all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Arthur Miller <arthur.miller@live.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: martin rudalics <rudalics@gmx.at>,
	larsi@gnus.org, juri@linkov.net,
	Drew Adams <drew.adams@oracle.com>,
	emacs-devel@gnu.org
Subject: Re: Exec help commands from other buffer (was bug#36767: 26.1; request: add more quick keys to the *Help* buffer)
Date: Mon, 27 Sep 2021 21:59:34 +0200	[thread overview]
Message-ID: <AM9PR09MB497782748CC7F11996A6E4DB96A79@AM9PR09MB4977.eurprd09.prod.outlook.com> (raw)
In-Reply-To: <AM9PR09MB4977D5AB8F47D54363EE9A7B96A79@AM9PR09MB4977.eurprd09.prod.outlook.com> (Arthur Miller's message of "Mon, 27 Sep 2021 13:07:51 +0200")

[-- Attachment #1: Type: text/plain, Size: 1455 bytes --]

Arthur Miller <arthur.miller@live.com> writes:

> Eli Zaretskii <eliz@gnu.org> writes:
>
>>> From: Arthur Miller <arthur.miller@live.com>
>>> Cc: Juri Linkov <juri@linkov.net>,  larsi@gnus.org,  emacs-devel@gnu.org
>>> Date: Fri, 24 Sep 2021 21:57:13 +0200
>>> 
>>> > Please, no unnecessary generalizations of this kind.  Or at least not
>>> > to cater to this particular request.  I want a _help_ command, not
>>> > just a prefix that runs any command in the other window.  because, for
>>> > starters, what if the *Help* buffer is not currently on display at
>>> > all?
>>> 
>>> Here is one updated without the unnecessary let statement.
>>
>> Thanks, but I'd prefer a prefix command, so that you wouldn't need to
>> prompt for the key sequence, but expect the user to provide it
>> already.  For example, "C-h M-h s" would show the definition of the
>> function or variable.
>>
>> Also, the *Help* window should stay displayed, so any additional
>> buffers the command needs to pop (for example, to show the definition)
>> should not replace the *Help* buffer, it should pop in another window,
>> exactly like when I invoke the command from the *Help* buffer.
>
> Ok, with iput from Martin, and wish to have this as a command prefix, after some
> doc reading and test and trys, here is another patch.
>
> When help is not displayed, it silently does nothing, should some message  be
> emitted in minibuffer?

This one goes to correct group and map :)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Run-help-mode-commands-form-any-buffer.patch --]
[-- Type: text/x-patch, Size: 6819 bytes --]

From 1841a5d32370e8fe0b493dcbe588b89b8051f12e Mon Sep 17 00:00:00 2001
From: Arthur Miller <arthur.miller@live.com>
Date: Mon, 27 Sep 2021 21:55:42 +0200
Subject: [PATCH] Run help-mode commands form any buffer

* help-mode.el (help-go-back): Addapted to call form any buufer.
(help-window): New function.
(with-help-buffer): New macro.
(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-command-prefix map in global-map on C-h M-h key.
---
 lisp/help-mode.el | 100 +++++++++++++++++++++++++++++++++++-----------
 1 file changed, 76 insertions(+), 24 deletions(-)

diff --git a/lisp/help-mode.el b/lisp/help-mode.el
index 0b404fe89f..932af304a7 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,20 @@ 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 '(choice (string :tag "Key") (const :tag "no binding"))
+  :set (lambda (var key)
+         (when (and (boundp var) (symbol-value var))
+           (define-key (current-global-map)
+             (read-kbd-macro (symbol-value var)) nil))
+         (when key
+           (define-key (current-global-map)
+             (read-kbd-macro key) 'help-command-prefix))
+         (set var key))
+  :group 'help
+  :version "28.1")
 \f
 ;; Button types used by help
 
@@ -402,7 +433,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)))
 \f
 ;; Grokking cross-reference information in doc strings and
 ;; hyperlinking it.
@@ -741,6 +773,21 @@ 'help-xref-interned
 \f
 ;; Navigation/hyperlinking with xrefs
 
+(defun help-window ()
+  "Return help-buffer window or nil help-buffer is not currently displayed."
+  (when (get-buffer "*Help*")
+    (get-buffer-window (get-buffer "*Help*"))))
+
+(defmacro with-help-buffer (&rest body)
+  "Execute the forms in BODY with HELP-BUFFER temporarily current.
+
+BODY will be executed onlu if HELP-BUFFER is displayed in a live
+window on the screen."
+  (declare (indent 1) (debug t))
+  `(when (help-window)
+    (with-current-buffer (help-buffer)
+      ,@body)))
+
 (defun help-xref-go-back (buffer)
   "From BUFFER, go back to previous help buffer text using `help-xref-stack'."
   (let (item position method args)
@@ -784,44 +831,49 @@ 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")))
+  (with-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")))
+  (with-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)))
+  (with-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))
+    (with-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)))))
+    (with-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.
@@ -844,7 +896,7 @@ help-follow-mouse
 (defun help-follow ()
   "Follow cross-reference at point.
 
-For the cross-reference format, see `help-make-xrefs'."
+For the cross-reference format, see `help-make-xrsefs'."
   (declare (obsolete nil "28.1"))
   (interactive)
   (user-error "No cross-reference here"))
-- 
2.33.0


  reply	other threads:[~2021-09-27 19:59 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-22 19:53 bug#36767: 26.1; request: add more quick keys to the *Help* buffer ndame
2019-07-22 20:49 ` Drew Adams
2019-07-28  0:10   ` Basil L. Contovounesios
2021-06-15 18:52 ` Lars Ingebrigtsen
2021-06-17 20:34   ` Juri Linkov
2021-06-18  6:02     ` Eli Zaretskii
2021-06-18  7:20       ` Robert Pluim
2021-06-18 10:58         ` Eli Zaretskii
2021-06-18 14:21           ` bug#36767: [External] : " Drew Adams
2021-06-18 14:32           ` Stephen Berman
2021-06-18 14:45             ` Eli Zaretskii
2021-06-18 16:02               ` Stephen Berman
2021-06-18 18:25                 ` Eli Zaretskii
2021-06-19  9:08               ` martin rudalics
2021-06-19  9:27                 ` Eli Zaretskii
2021-06-20  9:21                   ` martin rudalics
2021-06-18 16:21             ` bug#36767: [External] : " Drew Adams
2021-06-18 14:12         ` Drew Adams
2021-06-18 19:14       ` Juri Linkov
2021-06-18 19:21         ` Eli Zaretskii
2021-06-19 23:15           ` Juri Linkov
     [not found]       ` <AM9PR09MB49779C8B93EFFB329EB8E5A596A29@AM9PR09MB4977.eurprd09.prod.outlook.com>
     [not found]         ` <83y27nvnb4.fsf@gnu.org>
     [not found]           ` <AM9PR09MB497767EDF180DE0C3EE15F4396A39@AM9PR09MB4977.eurprd09.prod.outlook.com>
     [not found]             ` <83ilyrvgda.fsf@gnu.org>
     [not found]               ` <AM9PR09MB497720FA603D3B7FC4D4739196A39@AM9PR09MB4977.eurprd09.prod.outlook.com>
2021-09-23 20:54                 ` Lars Ingebrigtsen
     [not found]                 ` <83h7ebv39d.fsf@gnu.org>
     [not found]                   ` <AM9PR09MB49771D1ECD11701DEFB77C7A96A39@AM9PR09MB4977.eurprd09.prod.outlook.com>
     [not found]                     ` <838rznusle.fsf@gnu.org>
2021-09-24  7:16                       ` Arthur Miller
2021-09-24 15:31                         ` Juri Linkov
2021-09-24 16:12                           ` Eli Zaretskii
2021-09-24 19:36                             ` Arthur Miller
2021-09-24 19:39                             ` Arthur Miller
2021-09-24 19:57                             ` Arthur Miller
2021-09-25  6:09                               ` Eli Zaretskii
2021-09-25 14:41                                 ` Arthur Miller
2021-09-25 14:59                                   ` Eli Zaretskii
2021-09-25 16:22                                     ` Arthur Miller
2021-09-25 16:26                                       ` Eli Zaretskii
2021-09-25 17:08                                         ` Arthur Miller
2021-09-25 17:20                                           ` Eli Zaretskii
2021-09-25 20:15                                             ` Arthur Miller
2021-09-26 21:52                                               ` Arthur Miller
2021-09-26  9:11                                           ` martin rudalics
2021-09-26 16:11                                             ` Arthur Miller
2021-09-26 16:54                                               ` [External] : " Drew Adams
2021-09-26 21:51                                                 ` Arthur Miller
2021-09-26 22:38                                                   ` Drew Adams
2021-09-26 22:46                                                     ` Arthur Miller
2021-09-26 17:51                                               ` martin rudalics
2021-09-26 21:48                                                 ` Arthur Miller
2021-09-27 11:07                                 ` Exec help commands from other buffer (was bug#36767: 26.1; request: add more quick keys to the *Help* buffer) Arthur Miller
2021-09-27 19:59                                   ` Arthur Miller [this message]
2021-09-24 18:34                           ` [External] : Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer Drew Adams
2021-09-24 19:34                           ` Arthur Miller
2021-09-24 20:20                           ` Arthur Miller
2021-09-24 20:33                           ` Arthur Miller
2021-09-25 18:46                             ` Juri Linkov
2021-06-19 11:58     ` Lars Ingebrigtsen
2021-06-19 12:22       ` Eli Zaretskii
2021-06-19 23:15       ` Juri Linkov
     [not found]   ` <AM9PR09MB4977DAFB86D88A4714C1C64196A29@AM9PR09MB4977.eurprd09.prod.outlook.com>
     [not found]     ` <87pmt0qomh.fsf@gnus.org>
     [not found]       ` <AM9PR09MB4977CCFA194C77F1ADF0015C96A29@AM9PR09MB4977.eurprd09.prod.outlook.com>
2021-09-23 20:42         ` Lars Ingebrigtsen
2021-09-23 23:09           ` bug#36767: [External] : " Drew Adams
     [not found]       ` <AM9PR09MB49770845B0C1B7CBB331E68A96A39@AM9PR09MB4977.eurprd09.prod.outlook.com>
2021-09-23 20:52         ` Lars Ingebrigtsen
2021-09-23 22:18           ` Arthur Miller
2021-09-26  9:11           ` martin rudalics
2021-09-26  9:40             ` Lars Ingebrigtsen
2021-09-26  9:55             ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AM9PR09MB497782748CC7F11996A6E4DB96A79@AM9PR09MB4977.eurprd09.prod.outlook.com \
    --to=arthur.miller@live.com \
    --cc=drew.adams@oracle.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=juri@linkov.net \
    --cc=larsi@gnus.org \
    --cc=rudalics@gmx.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.