Subject: Re: bug#71117: 30.0.50; output of describe-function

From: Andrea Corallo <[email-masked]>
Date: Tue, 28 May 2024 15:42:30 -0400

Eli Zaretskii <[email-masked]> writes:

>> From: Andrea Corallo <[email-masked]>
>> Cc: Kévin Le Gouguec <[email-masked]>,
>>   [email-masked],
>>   [email-masked]
>> Date: Tue, 28 May 2024 13:44:33 -0400
>> 
>> >> 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.
>
> I might be mistaken, but I don't think this is what I had in mind.

You are not.

> My use case is exactly like described above: I type "C-h v" or "C-h
> f", which displays the *Help* buffer in the other window.  Then I want
> to go to the source where the variable or function are defined, but
> without the need to switch to the window showing *Help*.

The attached is my understanding of what we want (still using C-h z).
Kévin's mail make me suspect I've been too naive but anyway 😅...

Thanks

  Andrea

>From 569eb50994cd0841dcfbc970d574d945aa43b064 Mon Sep 17 00:00:00 2001
From: Andrea Corallo <[email-masked]>
Date: Tue, 28 May 2024 21:06:21 +0200
Subject: [PATCH] Add 'help-find-source' and bind it to C-h z

* lisp/help-fns.el (help-find-source): New function.
* lisp/help.el (help-map): Bind 'help-find-source' to C-h z.
(help-for-help): Add 'help-find-source'.
---
 lisp/help-fns.el | 9 +++++++++
 lisp/help.el     | 2 ++
 2 files changed, 11 insertions(+)

diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index a202c2d247e..74760197c8b 100644
--- a/lisp/help-fns.el
+++ b/lisp/help-fns.el
@@ -298,6 +298,15 @@ describe-function
           ;; Return the text we displayed.
           (buffer-string))))))
 
+;;;###autoload
+(defun help-find-source ()
+  "Switch to a buffer visiting the source of what is being described in *Help*."
+  (interactive)
+  (if-let ((help-buffer (get-buffer "*Help*")))
+      (with-current-buffer help-buffer
+          (help-view-source))
+    (error "No *Help* buffer found")))
+
 ;;;###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..aa835008358 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-find-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-find-source" "Show the source for what's being described in *Help*")
        ("describe-variable" "Show help for variable")
        ("describe-symbol" "Show help for function or variable"))
       ("Manuals"
-- 
2.34.1