>From c70e38e9ff9678a7105f39a5efff7596d3452e2f Mon Sep 17 00:00:00 2001 From: Arthur Miller Date: Sat, 25 Sep 2021 22:06:53 +0200 Subject: [PATCH] Run help-mode commands form any buffer * help-mode.el (help-go-back): Addapted to call form any buufer. (help-go-forward): Addapted to call form any buufer. (help-view-source): Addapted to call form any buufer. (help-goto-info): Addapted to call form any buufer. (help-command-prefix): New map. (help-command-prefix-key): New customize option. Install help-do-command in global-map on C-h M-h key. --- lisp/help-mode.el | 80 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 57 insertions(+), 23 deletions(-) diff --git a/lisp/help-mode.el b/lisp/help-mode.el index 0b404fe89f..0d5a709d49 100644 --- a/lisp/help-mode.el +++ b/lisp/help-mode.el @@ -48,6 +48,23 @@ help-mode-map map) "Keymap for Help mode.") +(defvar help-command-prefix + (let ((map (define-prefix-command 'help-command-prefix))) + (define-key map "l" #'help-go-back) + (define-key map "r" #'help-go-forward) + (define-key map "\C-c\C-b" #'help-go-back) + (define-key map "\C-c\C-f" #'help-go-forward) + (define-key map [XF86Back] #'help-go-back) + (define-key map [XF86Forward] #'help-go-forward) + (define-key map "\C-c\C-c" #'help-follow-symbol) + (define-key map "s" #'help-view-source) + (define-key map "i" #'help-goto-info) + (define-key map "c" #'help-customize) + (fset 'help-command-prefix help-command-prefix) + (setq help-command-prefix help-command-prefix) + map) + "Keymap for Help command prefix.") + (easy-menu-define help-mode-menu help-mode-map "Menu for Help mode." '("Help-Mode" @@ -149,6 +166,12 @@ help-mode-hook "Hook run by `help-mode'." :type 'hook :group 'help) + +(defcustom help-command-prefix-key "C-h M-h" + "The key HELP-COMMAND-PREFIX is bound to in the global map." + :type 'string + :group 'help + :version "28.1") ;; Button types used by help @@ -402,7 +425,8 @@ help-mode-finish "Finalize Help mode setup in current buffer." (when (derived-mode-p 'help-mode) (setq buffer-read-only t) - (help-make-xrefs (current-buffer)))) + (help-make-xrefs (current-buffer)) + (set-window-dedicated-p (get-buffer-window (help-buffer)) t))) ;; Grokking cross-reference information in doc strings and ;; hyperlinking it. @@ -784,44 +808,54 @@ help-xref-go-forward (defun help-go-back () "Go back to previous topic in this help buffer." (interactive) - (if help-xref-stack - (help-xref-go-back (current-buffer)) - (user-error "No previous help buffer"))) + (when (get-buffer-window (help-buffer)) + (with-current-buffer (help-buffer) + (if help-xref-stack + (help-xref-go-back (current-buffer)) + (user-error "No previous help buffer"))))) (defun help-go-forward () "Go to the next topic in this help buffer." (interactive) - (if help-xref-forward-stack - (help-xref-go-forward (current-buffer)) - (user-error "No next help buffer"))) + (when (get-buffer-window (help-buffer)) + (with-current-buffer (help-buffer) + (if help-xref-forward-stack + (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 (plist-get help-mode--current-data :file) - (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) - (plist-get help-mode--current-data :type))) + (when (get-buffer-window (help-buffer)) + (with-current-buffer (help-buffer) + (unless (plist-get help-mode--current-data :file) + (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) + (plist-get help-mode--current-data :type))))) (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)) + (when (get-buffer-window (help-buffer)) + (with-current-buffer (help-buffer) + (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-customize () "Customize variable or face whose doc string is shown in the current buffer." (interactive nil help-mode) - (let ((sym (plist-get help-mode--current-data :symbol))) - (unless (or (boundp sym) (facep sym)) - (user-error "No variable or face to customize")) - (cond - ((boundp sym) (customize-variable sym)) - ((facep sym) (customize-face sym))))) + (when (get-buffer-window (help-buffer)) + (with-current-buffer (help-buffer) + (let ((sym (plist-get help-mode--current-data :symbol))) + (unless (or (boundp sym) (facep sym)) + (user-error "No variable or face to customize")) + (cond + ((boundp sym) (customize-variable sym)) + ((facep sym) (customize-face sym))))))) (defun help-do-xref (_pos function args) "Call the help cross-reference function FUNCTION with args ARGS. -- 2.33.0