]> git.eshelyaron.com Git - emacs.git/commitdiff
Add new convenience commands for *Help*
authorLars Ingebrigtsen <larsi@gnus.org>
Tue, 15 Jun 2021 18:51:00 +0000 (20:51 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Tue, 15 Jun 2021 18:51:00 +0000 (20:51 +0200)
* doc/emacs/help.texi (Help Mode): Document it (bug#36767).

* lisp/help-fns.el (help-fns-function-description-header)
(describe-variable, describe-face, describe-keymap)
(describe-mode): Add the required data.

* lisp/help-mode.el (help-mode-map): Add 'i' and 's'.
(help-mode--current-data): New variable.
(help-mode): Make it local.
(help-view-source, help-goto-info): New commands.

doc/emacs/help.texi
etc/NEWS
lisp/help-fns.el
lisp/help-mode.el

index 90a2ddc809a3d4b8f2b5d537209737cab3f4f8db..8c24a926af5fe8759d4ccc9743bb668338b2cbf1 100644 (file)
@@ -451,6 +451,11 @@ Go forward to the next help topic (@code{help-go-forward}).
 @item C-c C-b
 @itemx l
 Go back to the previous help topic (@code{help-go-back}).
+@item s
+View the source of the current help topic (if any)
+(@code{help-view-source}).
+@item i
+Look up the current topic in the manual(s) (@code{help-goto-info}).
 @end table
 
 @cindex hyperlink
index 85ef6e4ba38bbea9674128acd006fdf97e18cdf6..da1372baf4cb1658ae484fb1676a352524852f76 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1124,6 +1124,15 @@ This change is for better compatibility with old versions of non-GNU
 
 ** Help
 
++++
+*** New command 'help-view-source' ('s')
+This command will view the source file (if any) of the current help
+topic.
+
++++
+*** New command 'help-goto-info' ('i')
+This command will look up the current symbol (if any) in Info.
+
 ---
 *** The 'help-for-help' ('C-h C-h') screen has been redesigned.
 
index 133763add15cfa473c97fba43c3e0282622ee923..f9804c705b3213e7611dfd99cb9192e89fc1e3be 100644 (file)
@@ -887,7 +887,9 @@ Returns a list of the form (REAL-FUNCTION DEF ALIASED REAL-DEF)."
                                       nil t)
              (help-xref-button 1 'help-function real-def)))))
 
-      (when file-name
+      (if (not file-name)
+         (with-current-buffer standard-output
+            (setq help-mode--current-data (list :symbol function)))
        ;; We used to add .el to the file name,
        ;; but that's completely wrong when the user used load-file.
        (princ (format-message " in `%s'"
@@ -896,6 +898,8 @@ Returns a list of the form (REAL-FUNCTION DEF ALIASED REAL-DEF)."
                                  (help-fns-short-filename file-name))))
        ;; Make a hyperlink to the library.
        (with-current-buffer standard-output
+          (setq help-mode--current-data (list :symbol function
+                                              :file file-name))
          (save-excursion
            (re-search-backward (substitute-command-keys "`\\([^`']+\\)'")
                                 nil t)
@@ -1070,7 +1074,10 @@ it is displayed along with the global value."
                                        "C source code"
                                      (help-fns-short-filename file-name))))
                           (with-current-buffer standard-output
-                            (save-excursion
+                             (setq help-mode--current-data
+                                   (list :symbol variable
+                                         :file file-name))
+                             (save-excursion
                               (re-search-backward (substitute-command-keys
                                                     "`\\([^`']+\\)'")
                                                    nil t)
@@ -1079,6 +1086,8 @@ it is displayed along with the global value."
                           (if valvoid
                               "It is void as a variable."
                              "Its "))
+                      (with-current-buffer standard-output
+                         (setq help-mode--current-data (list :symbol variable)))
                        (if valvoid
                           " is void as a variable."
                          (substitute-command-keys "'s ")))))
@@ -1448,7 +1457,10 @@ If FRAME is omitted or nil, use the selected frame."
                   (concat "\\(" customize-label "\\)") nil t)
                  (help-xref-button 1 'help-customize-face f)))
              (setq file-name (find-lisp-object-file-name f 'defface))
-             (when file-name
+             (if (not file-name)
+                  (setq help-mode--current-data (list :symbol f))
+                (setq help-mode--current-data (list :symbol f
+                                                    :file file-name))
                (princ (substitute-command-keys "Defined in `"))
                (princ (help-fns-short-filename file-name))
                (princ (substitute-command-keys "'"))
@@ -1738,7 +1750,9 @@ keymap value."
           (unless used-gentemp
             (princ (format-message "%S is a keymap variable" keymap))
             (if (not file-name)
-                (princ ".\n\n")
+                (progn
+                  (setq help-mode--current-data (list :symbol keymap))
+                  (princ ".\n\n"))
               (princ (format-message
                       " defined in `%s'.\n\n"
                       (if (eq file-name 'C-source)
@@ -1748,6 +1762,8 @@ keymap value."
                 (re-search-backward (substitute-command-keys
                                      "`\\([^`']+\\)'")
                                     nil t)
+                (setq help-mode--current-data (list :symbol keymap
+                                                    :file file-name))
                 (help-xref-button 1 'help-variable-def
                                   keymap file-name))))
           (when (and (not (equal "" doc)) doc)
@@ -1855,7 +1871,8 @@ documentation for the major and minor modes of that buffer."
        (princ " mode")
        (let* ((mode major-mode)
               (file-name (find-lisp-object-file-name mode nil)))
-         (when file-name
+         (if (not file-name)
+              (setq help-mode--current-data (list :symbol mode))
            (princ (format-message " defined in `%s'"
                                    (help-fns-short-filename file-name)))
            ;; Make a hyperlink to the library.
@@ -1863,6 +1880,8 @@ documentation for the major and minor modes of that buffer."
              (save-excursion
                (re-search-backward (substitute-command-keys "`\\([^`']+\\)'")
                                     nil t)
+                (setq help-mode--current-data (list :symbol mode
+                                                    :file file-name))
                 (help-xref-button 1 'help-function-def mode file-name)))))
         (let ((fundoc (help-split-fundoc (documentation major-mode) nil 'doc)))
           (with-current-buffer standard-output
index c7eaae5feb497553f1f34ab98516dda18bea3f3a..7450d73332224be20d95dbfcbe970c3a97a16089 100644 (file)
@@ -44,6 +44,8 @@
     (define-key map [XF86Forward] 'help-go-forward)
     (define-key map "\C-c\C-c" 'help-follow-symbol)
     (define-key map "\r" 'help-follow)
+    (define-key map "s" 'help-view-source)
+    (define-key map "i" 'help-goto-info)
     map)
   "Keymap for Help mode.")
 
     ["Move to Previous Button" backward-button
      :help "Move to the Previous Button in the help buffer"]
     ["Move to Next Button" forward-button
-      :help "Move to the Next Button in the help buffer"]))
+      :help "Move to the Next Button in the help buffer"]
+    ["View Source" help-view-source
+     :help "Go to the source file for the current help item"]
+    ["Goto Info" help-goto-info
+     :help "Go to the info node for the current help item"]))
 
 (defvar help-mode-tool-bar-map
   (let ((map (make-sparse-keymap)))
@@ -323,6 +329,7 @@ The format is (FUNCTION ARGS...).")
   'help-echo (purecopy "mouse-2, RET: show corresponding NEWS announcement"))
 \f
 (defvar bookmark-make-record-function)
+(defvar help-mode--current-data nil)
 
 ;;;###autoload
 (define-derived-mode help-mode special-mode "Help"
@@ -334,6 +341,7 @@ Commands:
               #'help-mode-revert-buffer)
   (setq-local tool-bar-map
               help-mode-tool-bar-map)
+  (setq-local help-mode--current-data nil)
   (setq-local bookmark-make-record-function
               #'help-bookmark-make-record))
 
@@ -722,6 +730,22 @@ See `help-make-xrefs'."
       (help-xref-go-forward (current-buffer))
     (user-error "No next help buffer")))
 
+(defun help-view-source ()
+  "View the source of the current help item."
+  (interactive nil help-mode)
+  (unless help-mode--current-data
+    (error "Source file for the current help item is not defined"))
+  (help-function-def--button-function (plist-get help-mode--current-data :symbol)
+                                      (plist-get help-mode--current-data :file)))
+
+(defun help-goto-info ()
+  "View the *info* node of the current help item."
+  (interactive nil help-mode)
+  (unless help-mode--current-data
+    (error "No symbol to look up in the current buffer"))
+  (info-lookup-symbol (plist-get help-mode--current-data :symbol)
+                      'emacs-lisp-mode))
+
 (defun help-do-xref (_pos function args)
   "Call the help cross-reference function FUNCTION with args ARGS.
 Things are set up properly so that the resulting help-buffer has