GNU bug report logs - #71117
30.0.50; output of describe-function

Previous Next

Package: emacs;

Reported by: Andreas Röhler <andreas.roehler <at> easy-emacs.de>

Date: Wed, 22 May 2024 13:54:01 UTC

Severity: normal

Found in version 30.0.50

Done: Andrea Corallo <acorallo <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Andrea Corallo <acorallo <at> gnu.org>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 71117 <at> debbugs.gnu.org, andreas.roehler <at> easy-emacs.de, Kévin Le Gouguec <kevin.legouguec <at> gmail.com>
Subject: bug#71117: 30.0.50; output of describe-function
Date: Tue, 28 May 2024 13:44:33 -0400
[Message part 1 (text/plain, inline)]
Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: Kévin Le Gouguec <kevin.legouguec <at> gmail.com>
>> Cc: andreas.roehler <at> easy-emacs.de,  71117 <at> debbugs.gnu.org
>> Date: Thu, 23 May 2024 00:22:10 +0200
>> 
>> Eli Zaretskii <eliz <at> gnu.org> writes:
>> 
>> > Which reminds me that we still don't have a "C-h SOMETHING" binding
>> > that would go to the source without the need to switch to the *Help*
>> > buffer.  At one time we discussed something like that, and I thought
>> > we actually installed it, but I guess I was dreaming, because I cannot
>> > find it...
>> 
>> Were you thinking of a command that specifically targets the symbol from
>> a displayed *Help* buffer, so the user would do e.g.
>> 
>> C-h v VAR RET   ; shows *Help* for VAR
>> C-h SOMETHING   ; finds source for VAR
>> 
>> where C-h SOMETHING's implementation would do (a smarter version of)
>> (with-current-buffer "*Help*"
>>   (help-view-source))
>> 
>> ?
>
> Yes, exactly.

Something like the attached?

It makes C-h z FUNCTION find the source for FUNCTION.

Not sure C-h z is the best (but there are not may other letter still
available).

Also ATM the patch is missing the NEWS entry (will do after).

Thanks

  Andrea

[0001-Add-help-function-source-C-h-z-to-visit-the-function.patch (text/x-diff, inline)]
From e1ab4f7fae70316ee07c19e3f34fdf5f5b6ac918 Mon Sep 17 00:00:00 2001
From: Andrea Corallo <acorallo <at> gnu.org>
Date: Tue, 28 May 2024 19:33:54 +0200
Subject: [PATCH] Add 'help-function-source' 'C-h z' to visit function's
 source (bug#71117)

* lisp/help.el (help-map): Bind 'help-function-source' to C-h z.
(help-for-help): Add 'help-function-source'.
* lisp/help-fns.el
(help-fns--describe-function-or-command-prompt): Extend arg
to support 'src-fun'.
(help-function-source): New function.
---
 lisp/help-fns.el | 17 ++++++++++++-----
 lisp/help.el     |  2 ++
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index a202c2d247e..66153f84b8f 100644
--- a/lisp/help-fns.el
+++ b/lisp/help-fns.el
@@ -224,14 +224,15 @@ describe-function-orig-buffer

 (defun help-fns--describe-function-or-command-prompt (&optional want-command)
   "Prompt for a function from `describe-function' or `describe-command'.
-If optional argument WANT-COMMAND is non-nil, prompt for an
-interactive command."
+If optional argument WANT-COMMAND is `is-command', prompt for an
+interactive command, if is `src-fun' prompt for go to function source."
   (let* ((fn (if want-command
                  (caar command-history)
                (function-called-at-point)))
-         (prompt (format-prompt (if want-command
-                                    "Describe command"
-                                  "Describe function")
+         (prompt (format-prompt (cl-case want-command
+                                  ('is-command "Describe command")
+                                  ('src-fun "Find source of function")
+                                  (t "Describe function"))
                                 fn))
          (enable-recursive-minibuffers t)
          (val (completing-read
@@ -298,6 +299,12 @@ describe-function
           ;; Return the text we displayed.
           (buffer-string))))))

+;;;###autoload
+(defun help-function-source (function)
+  "Switch to a buffer visiting the source of FUNCTION (a symbol)."
+  (interactive (help-fns--describe-function-or-command-prompt 'src-fun))
+  (xref-find-definitions (symbol-name function)))
+
 ;;;###autoload
 (defun describe-command (command)
   "Display the full documentation of COMMAND (a symbol).
diff --git a/lisp/help.el b/lisp/help.el
index 616a45328fd..a753a31a2e3 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -114,6 +114,7 @@ help-map
   "R"    #'info-display-manual
   "s"    #'describe-syntax
   "t"    #'help-with-tutorial
+  "z"    #'help-function-source
   "v"    #'describe-variable
   "w"    #'where-is
   "x"    #'describe-command
@@ -418,6 +419,7 @@ 'help
         "Search documentation of functions, variables, and other items")
        ("describe-command" "Show help for command")
        ("describe-function" "Show help for function")
+       ("help-function-source" "Show the source for function")
        ("describe-variable" "Show help for variable")
        ("describe-symbol" "Show help for function or variable"))
       ("Manuals"
--
2.34.1

This bug report was last modified 358 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.