From: Jens Schmidt via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 66032@debbugs.gnu.org
Cc: drew.adams@oracle.com, monnier@iro.umontreal.ca
Subject: bug#66032: [PATCH] Inline advice documentation into advised function's docstring, after all
Date: Sat, 16 Sep 2023 14:57:33 +0200 [thread overview]
Message-ID: <d7465ddf-5393-be30-f3fe-df168d40849e@vodafonemail.de> (raw)
[-- Attachment #1: Type: text/plain, Size: 1814 bytes --]
Severity: wishlist
X-Debbugs-CC: drew.adams@oracle.com, monnier@iro.umontreal.ca
I'm aware that I'm late to the party (got unstuck from Emacs 23
only recently) and that there have been some reports on that
already (bug#14734 and merged).
But at least on one occasion Stefan has asked for a patch, and I
haven't seen yet patches that got declined. So here is one, so
far the plain code patch only, without NEWS, tests, etc. It was
actually easier to implement than I thought, I hope I haven't
overseen any edge cases.
Here are two examples of how the generated documentation looks
like. The former shows documentation of a legacy-advised
function, the latter shows documentation of one of Stefan's
test advice to demonstrate that these cases are handled as well.
------------------------- snip -------------------------
ediff-quit is an interactive byte-compiled Lisp function in
‘ediff-util.el’.
(ediff-quit REVERSE-DEFAULT-KEEP-VARIANTS)
Finish an Ediff session and exit Ediff.
[...]
With prefix argument REVERSE-DEFAULT-KEEP-VARIANTS, temporarily
reverse the meaning of this variable.
<font-lock-warning-face>This function is advised.</f-l-w-f>
This function has :around advice: ‘ad-Advice-ediff-quit’
Does not ask any stupid questions.
Pops to buffer A.
[back]
------------------------- snip -------------------------
------------------------- snip -------------------------
sm-test1 is a Lisp macro.
(sm-test1 A)
<font-lock-warning-face>This function is advised.</f-l-w-f>
This macro has :override advice: No documentation
This is an :override advice, which means that ‘sm-test1’ isn’t
run at all, and the documentation below may be irrelevant.
This macro has :around advice: No documentation
[back]
------------------------- snip -------------------------
What do you think?
[-- Attachment #2: 0001-Improve-documentation-of-advised-macros-or-functions.patch --]
[-- Type: text/x-patch, Size: 3155 bytes --]
From 5b7c14242c1efad6d5ab05bf159ae0a5b7f41c32 Mon Sep 17 00:00:00 2001
From: Jens Schmidt <jschmidt4gnu@vodafonemail.de>
Date: Sat, 16 Sep 2023 14:53:18 +0200
Subject: [PATCH] Improve documentation of advised macros or functions
* lisp/emacs-lisp/nadvice.el (advice--make-single-doc): Inline advice
documentation where possible.
(advice--make-docstring): Add a prominent marker that the macro or
function is advised.
---
lisp/emacs-lisp/nadvice.el | 47 +++++++++++++++++++++++++++++---------
1 file changed, 36 insertions(+), 11 deletions(-)
diff --git a/lisp/emacs-lisp/nadvice.el b/lisp/emacs-lisp/nadvice.el
index cd80df2c41d..f04a584cf74 100644
--- a/lisp/emacs-lisp/nadvice.el
+++ b/lisp/emacs-lisp/nadvice.el
@@ -93,17 +93,30 @@ advice--make-single-doc
(format "This %s has %s advice: "
(if macrop "macro" "function")
how)
- (let ((fun (advice--car flist)))
- (if (symbolp fun) (format-message "`%S'." fun)
- (let* ((name (cdr (assq 'name (advice--props flist))))
- (doc (documentation fun t))
- (usage (help-split-fundoc doc function)))
- (if usage (setq doc (cdr usage)))
- (if name
- (if doc
- (format "%s\n%s" name doc)
- (format "%s" name))
- (or doc "No documentation")))))
+ (let* ((fun (advice--car flist))
+ (doc (documentation fun t))
+ (usage (help-split-fundoc doc function))
+ name)
+ (if usage (setq doc (cdr usage)))
+ (if (symbolp fun)
+ (if doc
+ (concat
+ (format-message "`%S'\n" fun)
+ ;; Remove first line possibly added by
+ ;; `ad-make-single-advice-docstring' for
+ ;; legacy advices.
+ (if (string-match
+ "^\\(?:Before\\|Around\\|After\\)-advice `.*?':\n"
+ doc)
+ (substring doc (match-end 0))
+ doc))
+ (format-message "`%S'." fun))
+ (setq name (cdr (assq 'name (advice--props flist))))
+ (if name
+ (if doc
+ (format "%s\n%s" name doc)
+ (format "%s" name))
+ (or doc "No documentation"))))
"\n"
(and
(eq how :override)
@@ -155,10 +168,22 @@ advice--make-docstring
(help-add-fundoc-usage
(with-temp-buffer
(when before
+ (insert
+ (propertize
+ (concat "This " (if macrop "macro" "function") " is advised.")
+ 'face 'font-lock-warning-face))
+ (ensure-empty-lines 1)
(insert before)
(ensure-empty-lines 1))
(when origdoc
(insert origdoc))
+ (when (not before)
+ (ensure-empty-lines 1)
+ (insert
+ (propertize
+ (concat "This " (if macrop "macro" "function") " is advised.")
+ 'face 'font-lock-warning-face))
+ (ensure-empty-lines 1))
(when after
(ensure-empty-lines 1)
(insert after))
--
2.30.2
next reply other threads:[~2023-09-16 12:57 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-16 12:57 Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-09-16 15:13 ` bug#66032: [PATCH] Inline advice documentation into advised function's docstring, after all Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-16 17:15 ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-17 20:13 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-18 21:03 ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-18 22:19 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-23 8:07 ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-23 16:03 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-23 19:09 ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-23 22:29 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
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=d7465ddf-5393-be30-f3fe-df168d40849e@vodafonemail.de \
--to=bug-gnu-emacs@gnu.org \
--cc=66032@debbugs.gnu.org \
--cc=drew.adams@oracle.com \
--cc=jschmidt4gnu@vodafonemail.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.