From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: 58602@debbugs.gnu.org
Subject: bug#58602: 29.0.50; Please document (:documentation FORM) spec for closures
Date: Tue, 18 Oct 2022 16:13:25 -0400 [thread overview]
Message-ID: <jwvilkghp5n.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <jwvtu419rzr.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Tue, 18 Oct 2022 09:34:29 -0400")
I pushed the text below.
Thanks to Eli and Drew for their review.
Stefan
PS: BTW, I noticed that `i :documentation RET` doesn't bring me to this
text, instead it just looks for "documentation" (which matches many
more index entries), disregarding the `:` and making this `@kindex` much
less useful.
PPS: Every time you use this `function-documentation` property, kitten
suffer atrocious pains.
diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi
index 8b858e0aa01..94c42ba260d 100644
--- a/doc/lispref/functions.texi
+++ b/doc/lispref/functions.texi
@@ -533,6 +533,46 @@ Function Documentation
compiler emit a warning message when it compiles Lisp programs which
use the deprecated calling convention.
+@cindex computed documentation string
+@kindex{:documentation}
+
+Documentation strings are usually static, but occasionally it can be
+necessary to generate them dynamically. In some cases you can do so
+by writing a macro which generates at compile time the code of the
+function, including the desired documentation string. But you can
+also generate the docstring dynamically by writing
+@code{(:documentation @var{form})} instead of the documentation
+string. This will evaluate @var{form} at run-time when the function
+is defined and use it as the documentation string@footnote{This only
+works in code using @code{lexical-binding}.}. You can also compute
+the documentation string on the fly when it is requested, by setting
+the @code{function-documentation} property of the function's symbol to
+a Lisp form that evaluates to a string.
+
+For example:
+@example
+@group
+(defun adder (x)
+ (lambda (y)
+ (:documentation (format "Add %S to the argument Y." x))
+ (+ x y)))
+(defalias 'adder5 (adder 5))
+(documentation 'adder5)
+ @result{} "Add 5 to the argument Y."
+@end group
+
+@group
+(put 'adder5 'function-documentation
+ '(concat (documentation (symbol-function 'adder5) 'raw)
+ " Consulted at " (format-time-string "%H:%M:%S")))
+(documentation 'adder5)
+ @result{} "Add 5 to the argument Y. Consulted at 15:52:13"
+(documentation 'adder5)
+ @result{} "Add 5 to the argument Y. Consulted at 15:52:18"
+@end group
+@end example
+
+
@node Function Names
@section Naming a Function
@cindex function definition
next prev parent reply other threads:[~2022-10-18 20:13 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-18 0:46 bug#58602: 29.0.50; Please document (:documentation FORM) spec for closures Michael Heerdegen
2022-10-18 2:05 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-18 2:20 ` Christopher Dimech
2022-10-18 3:16 ` Michael Heerdegen
2022-10-18 13:34 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-18 20:13 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-10-18 20:39 ` Drew Adams
2022-10-19 1:24 ` Michael Heerdegen
2022-10-19 23:23 ` Michael Heerdegen
2022-10-20 9:35 ` Michael Albinus
2022-10-20 16:50 ` Drew Adams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvilkghp5n.fsf-monnier+emacs@gnu.org \
--to=bug-gnu-emacs@gnu.org \
--cc=58602@debbugs.gnu.org \
--cc=michael_heerdegen@web.de \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.