help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Supplying DOC string in a `defun' using `defvar'


From: Jean Louis
Subject: Re: Supplying DOC string in a `defun' using `defvar'
Date: Tue, 1 Jun 2021 04:07:18 +0300
User-agent: Mutt/2.0.7+183 (3d24855) (2021-05-28)

* Michael Heerdegen <michael_heerdegen@web.de> [2021-06-01 03:40]:
> Jean Louis <bugs@gnu.support> writes:
> 
> > (defvar my-doc "Hello there")
> >
> > (defmacro my-fun ()
> >   `(defun my-fun ()
> >      ,my-doc
> >      (ignore)))
> 
> Would you want the body to be stored in another defvar?  Then your code
> would be even smaller.
> 
> I'm only partially joking, actually, not at all - is the function's
> documentation for your code's readers really that much less important
> than its code?  Maybe it's even the other way round?

Yes, obviously it is not practical, but it works. And is not me who
defines those functions. I am generating 50+ function aliases by
Drew's suggestion:

(defun hyperscope-generate-add-functions-by-hyperdocument-types ()
  (let ((types (hyperscope-hyperdocument-types)))
    (while types
      (let* ((type (pop types))
             (id (nth 0 type))
             (type (nth 1 type))
             (type-name type)
             (type (downcase (string-replace " " "-" type)))
             (new-function-name (format "hyperscope-add-new-%s-hyperdocument" 
type)))
        (defalias (intern new-function-name)
          (lambda ()
            (interactive)
            (let* ((parent (hyperscope-select-set))
                   (prompt (format "New `%s' hyperdocument name: " type-name))
                   (name (read-from-minibuffer prompt)))
              (hlink-add-generic name "" id parent nil)))
          (format "Add new `%s' hyperdocument to Hyperscope." type-name))))))

(hyperscope-generate-add-functions-by-hyperdocument-types)

This technique is handy as then user can simply add new type in the
database, visually, interactively, and new function is generated as a
hook that helps to add the new type. Even new key binding could be
generated automatically.

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]