mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-11-26 07:33:47 +00:00
Add new convenience commands for *Help*
* 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.
This commit is contained in:
parent
6ae5a59e52
commit
6fc48df5ae
@ -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
|
||||
|
9
etc/NEWS
9
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.
|
||||
|
||||
|
@ -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
|
||||
|
@ -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.")
|
||||
|
||||
@ -61,7 +63,11 @@
|
||||
["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"))
|
||||
|
||||
(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
|
||||
|
Loading…
Reference in New Issue
Block a user