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

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

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


From: Michael Heerdegen
Subject: Re: [External] : Supplying DOC string in a `defun' using `defvar'
Date: Tue, 01 Jun 2021 01:31:30 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Drew Adams <drew.adams@oracle.com> writes:

> (let ((toto "WHAT?!!!!"))
>   (put 'bar 'function-documentation toto))
>
> (describe-function 'bar)

Yes, the `function-documentation` property.  Its value can even be an
expression, and that will be evaluated whenever the documentation is
requested.  In one of the simplest cases, that expression is a variable
holding the documentation:

#+begin_src emacs-lisp
(defvar my-doc "A test function

And this is its documentation")

(defun test () 1)

(put 'test 'function-documentation 'my-doc)

;; Try C-h f test RET
#+end_src

When you change the value of `my-doc' the documentation of `test'
changes magically.

There are cases in Emacs where the expression is used to generate a
docstring dynamically - `pcase' is one example.


Michael.




reply via email to

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