unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
       [not found]         ` <87wnn7xbdg.fsf@gnus.org>
@ 2021-09-23 22:18           ` Arthur Miller
  0 siblings, 0 replies; 31+ messages in thread
From: Arthur Miller @ 2021-09-23 22:18 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: ndame, emacs-devel

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Arthur Miller <arthur.miller@live.com> writes:
>
>> You can see how it looks like. I have attached a small screenshot too,
>> so you don't need to apply it just to see how it looks like. The file
>> name at the end of the header is probably clear on it's own; the
>> symbol link is as clear/unclear as rest of the links in the buffer.
>
> (You're doing all these mails in a bug report that has been archived, so
> the only other people who's reading them are the ones in the CCs.  If
> you wish to discuss things publicly, either do so in emacs-devel or open
> a new bug report.)
I actually wondered why I was getting all those autmoated responses from bug
archive, but don't know how to fix that :). Sorry. Wasn't my intention. I have
removed debbugs from the CC, and atached emacs-devel, hopefully it's better now?
Should I remove the bug number too?

> I fixed up your patch so that it works more reliably, but then I
> remembered why I didn't add the link: We don't know at this point
> whether the symbol in question is documented in the manual.  Adding a
> link to something that fails is bad UI.  And we can't check whether the
> symbol exists in the manual when generating the *Help* buffer, because
> it's slow, and the trade-off (making the command slow versus an extra
> link) is not a good one.

Sure, it is ok. I don't think either it is very good idea to have failing
links. Same happens with 'i' command too, but that is not as visible.




^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
       [not found]                     ` <838rznusle.fsf@gnu.org>
@ 2021-09-24  7:16                       ` Arthur Miller
  2021-09-24 15:31                         ` Juri Linkov
  0 siblings, 1 reply; 31+ messages in thread
From: Arthur Miller @ 2021-09-24  7:16 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: larsi, emacs-devel, juri

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

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Arthur Miller <arthur.miller@live.com>
>> Cc: juri@linkov.net,  36767@debbugs.gnu.org,  larsi@gnus.org,
>>   emacsuser@freemail.hu
>> Date: Thu, 23 Sep 2021 18:05:29 +0200
>> 
>> Anyway that is one way; commands in help-mode.el need just a trivial hack to
>> make them usable from other buffers outside help-buffer. And than remap them to
>> global keys, or just remap entire map as I did in example in mail.
>
> Then by all means please submit a patch along these lines.

I came up with another idea last night and sent a patch, but I am not sure if it
got to right place, I don't see it myself. It was an answer longer in the thread
to Lars.

This one makes it possible to run any command in *Help* buffer, not just those
defined in help-mode.el, and those not need any patching or wrapping of existing
commands.

I don't know if it is correct place to put define-key for the global map, and I
am not sure if C-h M-h is the right, but that's just a detail.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Send-input-to-help-buffer-form-any-buffer.patch --]
[-- Type: text/x-patch, Size: 1262 bytes --]

From 77c404012dee603435b51b6a55be8700ce34a665 Mon Sep 17 00:00:00 2001
From: Arthur Miller <arthur.miller@live.com>
Date: Fri, 24 Sep 2021 02:09:42 +0200
Subject: [PATCH] Send input to help-buffer form any buffer

* help-mode.el (help-do-command): New command.
Install help-do-command in global-map on C-h M-h key.
---
 lisp/help-mode.el | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/lisp/help-mode.el b/lisp/help-mode.el
index 551cf7e1a3..a150cfa15b 100644
--- a/lisp/help-mode.el
+++ b/lisp/help-mode.el
@@ -875,6 +875,20 @@ help-insert-string
   (with-output-to-temp-buffer (help-buffer)
     (insert string)))
 
+(defun help-do-command ()
+  "Run a key-sequence in \"*Help*\" buffer from other buffers.
+
+If *Help* buffer is not visible, the HELP-DO-COMMAND will be aborterd."
+  (interactive)
+  (if (get-buffer-window (help-buffer))
+      (let ((__key (read-key-sequence "Run command in *Help* buffer: ")))
+        (with-current-buffer (help-buffer)
+          (call-interactively
+           (key-binding
+            (kbd (edmacro-format-keys (vector last-input-event)))))))
+    (call-interactively (global-key-binding "\C-g"))))
+
+(define-key global-map (kbd "C-h M-h") 'help-do-command)
 \f
 ;; Bookmark support
 
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
  2021-09-24  7:16                       ` Arthur Miller
@ 2021-09-24 15:31                         ` Juri Linkov
  2021-09-24 16:12                           ` Eli Zaretskii
                                             ` (4 more replies)
  0 siblings, 5 replies; 31+ messages in thread
From: Juri Linkov @ 2021-09-24 15:31 UTC (permalink / raw)
  To: Arthur Miller; +Cc: Eli Zaretskii, larsi, emacs-devel

> I came up with another idea last night and sent a patch, but I am not sure if it
> got to right place, I don't see it myself. It was an answer longer in the thread
> to Lars.
>
> This one makes it possible to run any command in *Help* buffer, not just those
> defined in help-mode.el, and those not need any patching or wrapping of existing
> commands.
>
> I don't know if it is correct place to put define-key for the global map, and I
> am not sure if C-h M-h is the right, but that's just a detail.

This would be a nice command.  But why it's limited only to help-window?
It could allow reading and running the key sequences in any next-window.

> +(defun help-do-command ()
> +  "Run a key-sequence in \"*Help*\" buffer from other buffers.
> +
> +If *Help* buffer is not visible, the HELP-DO-COMMAND will be aborterd."
> +  (interactive)
> +  (if (get-buffer-window (help-buffer))

I meant to replace '(get-buffer-window (help-buffer))' with '(next-window)'.

> +      (let ((__key (read-key-sequence "Run command in *Help* buffer: ")))
> +        (with-current-buffer (help-buffer)
> +          (call-interactively
> +           (key-binding
> +            (kbd (edmacro-format-keys (vector last-input-event)))))))
> +    (call-interactively (global-key-binding "\C-g"))))
> +
> +(define-key global-map (kbd "C-h M-h") 'help-do-command)



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
  2021-09-24 15:31                         ` Juri Linkov
@ 2021-09-24 16:12                           ` Eli Zaretskii
  2021-09-24 19:36                             ` Arthur Miller
                                               ` (2 more replies)
  2021-09-24 18:34                           ` [External] : Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer Drew Adams
                                             ` (3 subsequent siblings)
  4 siblings, 3 replies; 31+ messages in thread
From: Eli Zaretskii @ 2021-09-24 16:12 UTC (permalink / raw)
  To: Juri Linkov; +Cc: larsi, arthur.miller, emacs-devel

> From: Juri Linkov <juri@linkov.net>
> Date: Fri, 24 Sep 2021 18:31:59 +0300
> Cc: Eli Zaretskii <eliz@gnu.org>, larsi@gnus.org, emacs-devel@gnu.org
> 
> > am not sure if C-h M-h is the right, but that's just a detail.
> 
> This would be a nice command.  But why it's limited only to help-window?
> It could allow reading and running the key sequences in any next-window.

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?



^ permalink raw reply	[flat|nested] 31+ messages in thread

* RE: [External] : Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
  2021-09-24 15:31                         ` Juri Linkov
  2021-09-24 16:12                           ` Eli Zaretskii
@ 2021-09-24 18:34                           ` Drew Adams
  2021-09-24 19:34                           ` Arthur Miller
                                             ` (2 subsequent siblings)
  4 siblings, 0 replies; 31+ messages in thread
From: Drew Adams @ 2021-09-24 18:34 UTC (permalink / raw)
  To: Juri Linkov, Arthur Miller
  Cc: Eli Zaretskii, larsi@gnus.org, emacs-devel@gnu.org

Should the Subject here be a bug thread Subject?
Is this about bug #36767?




^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
  2021-09-24 15:31                         ` Juri Linkov
  2021-09-24 16:12                           ` Eli Zaretskii
  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
  4 siblings, 0 replies; 31+ messages in thread
From: Arthur Miller @ 2021-09-24 19:34 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Eli Zaretskii, larsi, emacs-devel

Juri Linkov <juri@linkov.net> writes:

>> I came up with another idea last night and sent a patch, but I am not sure if it
>> got to right place, I don't see it myself. It was an answer longer in the thread
>> to Lars.
>>
>> This one makes it possible to run any command in *Help* buffer, not just those
>> defined in help-mode.el, and those not need any patching or wrapping of existing
>> commands.
>>
>> I don't know if it is correct place to put define-key for the global map, and I
>> am not sure if C-h M-h is the right, but that's just a detail.
>
> This would be a nice command.  But why it's limited only to help-window?
> It could allow reading and running the key sequences in any next-window.

Yeah, sure, you could have it for next, previous or one found via
compleating-read, ot any buffer you can make current. 

This was meant as a quick fix to control help buffer so we don't need
to switch back and forth.

>> +(defun help-do-command ()
>> +  "Run a key-sequence in \"*Help*\" buffer from other buffers.
>> +
>> +If *Help* buffer is not visible, the HELP-DO-COMMAND will be aborterd."
>> +  (interactive)
>> +  (if (get-buffer-window (help-buffer))
>
> I meant to replace '(get-buffer-window (help-buffer))' with '(next-window)'.

Next-window could be anything, it could be just as annoying as switching
forth-and back, so I think it is better to have a specialized function that
works only on this buffer.
>
>> +      (let ((__key (read-key-sequence "Run command in *Help* buffer: ")))
>> +        (with-current-buffer (help-buffer)
>> +          (call-interactively
>> +           (key-binding
>> +            (kbd (edmacro-format-keys (vector last-input-event)))))))
>> +    (call-interactively (global-key-binding "\C-g"))))
>> +
>> +(define-key global-map (kbd "C-h M-h") 'help-do-command)

This was a quick fix, I just came up with that idea based on what I suggested
earlier, but sure it can be generalized. I think personally it is better that
every mode exports a named function, like foo-do-command or something, but one
where user chooses a buffer and one 'dwim' style one there are only two buffers
would be good to have too.

By the way, this let statement is unnecessary too, it is a leftover from refactoring.



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
  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
  2 siblings, 0 replies; 31+ messages in thread
From: Arthur Miller @ 2021-09-24 19:36 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: larsi, emacs-devel, Juri Linkov

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Juri Linkov <juri@linkov.net>
>> Date: Fri, 24 Sep 2021 18:31:59 +0300
>> Cc: Eli Zaretskii <eliz@gnu.org>, larsi@gnus.org, emacs-devel@gnu.org
>> 
>> > am not sure if C-h M-h is the right, but that's just a detail.
>> 
>> This would be a nice command.  But why it's limited only to help-window?
>> It could allow reading and running the key sequences in any next-window.
>
> 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?
The suggested patch will send C-g (abort the original request), so nothing will
happen. I think it would be confusing to work on a non-visible buffer, so that
is why call get-buffer-window.



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
  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
  2 siblings, 0 replies; 31+ messages in thread
From: Arthur Miller @ 2021-09-24 19:39 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: larsi, emacs-devel, Juri Linkov

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Juri Linkov <juri@linkov.net>
>> Date: Fri, 24 Sep 2021 18:31:59 +0300
>> Cc: Eli Zaretskii <eliz@gnu.org>, larsi@gnus.org, emacs-devel@gnu.org
>> 
>> > am not sure if C-h M-h is the right, but that's just a detail.
>> 
>> This would be a nice command.  But why it's limited only to help-window?
>> It could allow reading and running the key sequences in any next-window.
>
> 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?

By the way, help commands are of course avialable, same way as the example I
show you yesterday where I installed help-mode-map on C-h M-h. But this one is
better because no patching to existing commands in help-mode.el is needed, no
wrappers are needed, and if future commands are added it will work ootb. And you
cann send any other command if you prefer so too.



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
  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
  2 siblings, 1 reply; 31+ messages in thread
From: Arthur Miller @ 2021-09-24 19:57 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: larsi, emacs-devel, Juri Linkov

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

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Juri Linkov <juri@linkov.net>
>> Date: Fri, 24 Sep 2021 18:31:59 +0300
>> Cc: Eli Zaretskii <eliz@gnu.org>, larsi@gnus.org, emacs-devel@gnu.org
>> 
>> > am not sure if C-h M-h is the right, but that's just a detail.
>> 
>> This would be a nice command.  But why it's limited only to help-window?
>> It could allow reading and running the key sequences in any next-window.
>
> 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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Send-input-to-help-buffer-form-any-buffer.patch --]
[-- Type: text/x-patch, Size: 1273 bytes --]

From 58f8a59c9e93f081f76f8cf773d78be3b7d3740b Mon Sep 17 00:00:00 2001
From: Arthur Miller <arthur.miller@live.com>
Date: Fri, 24 Sep 2021 21:54:31 +0200
Subject: [PATCH] Send input to help-buffer form any buffer

* help-mode.el (help-do-command): New command.
Install help-do-command in global-map on C-h M-h key.
---
 lisp/help-mode.el | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/lisp/help-mode.el b/lisp/help-mode.el
index 551cf7e1a3..94fce1e8ec 100644
--- a/lisp/help-mode.el
+++ b/lisp/help-mode.el
@@ -875,6 +875,21 @@ help-insert-string
   (with-output-to-temp-buffer (help-buffer)
     (insert string)))
 
+(defun help-do-command ()
+  "Execute a command in \"*Help*\" buffer while working in other buffer.
+
+If *Help* buffer is not visible, the HELP-DO-COMMAND will be aborted."
+  (interactive)
+  (if (get-buffer-window (help-buffer))
+      (progn
+        (read-key-sequence "Run command in *Help* buffer: ")
+        (with-current-buffer (help-buffer)
+          (call-interactively
+           (key-binding
+            (kbd (edmacro-format-keys (vector last-input-event)))))))
+    (call-interactively (global-key-binding "\C-g"))))
+
+(define-key global-map (kbd "C-h M-h") 'help-do-command)
 \f
 ;; Bookmark support
 
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
  2021-09-24 15:31                         ` Juri Linkov
                                             ` (2 preceding siblings ...)
  2021-09-24 19:34                           ` Arthur Miller
@ 2021-09-24 20:20                           ` Arthur Miller
  2021-09-24 20:33                           ` Arthur Miller
  4 siblings, 0 replies; 31+ messages in thread
From: Arthur Miller @ 2021-09-24 20:20 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Eli Zaretskii, larsi, emacs-devel

Juri Linkov <juri@linkov.net> writes:

>> I came up with another idea last night and sent a patch, but I am not sure if it
>> got to right place, I don't see it myself. It was an answer longer in the thread
>> to Lars.
>>
>> This one makes it possible to run any command in *Help* buffer, not just those
>> defined in help-mode.el, and those not need any patching or wrapping of existing
>> commands.
>>
>> I don't know if it is correct place to put define-key for the global map, and I
>> am not sure if C-h M-h is the right, but that's just a detail.
>
> This would be a nice command.  But why it's limited only to help-window?
> It could allow reading and running the key sequences in any next-window.
>
>> +(defun help-do-command ()
>> +  "Run a key-sequence in \"*Help*\" buffer from other buffers.
>> +
>> +If *Help* buffer is not visible, the HELP-DO-COMMAND will be aborterd."
>> +  (interactive)
>> +  (if (get-buffer-window (help-buffer))
>
> I meant to replace '(get-buffer-window (help-buffer))' with '(next-window)'.
>
>> +      (let ((__key (read-key-sequence "Run command in *Help* buffer: ")))
>> +        (with-current-buffer (help-buffer)
>> +          (call-interactively
>> +           (key-binding
>> +            (kbd (edmacro-format-keys (vector last-input-event)))))))
>> +    (call-interactively (global-key-binding "\C-g"))))
>> +
>> +(define-key global-map (kbd "C-h M-h") 'help-do-command)

What I meant in last mail was something like this:

#+begin_src emacs-lisp
(defun remote-control (buffer-or-buffer-name)
  (let ((buffer (if (stringp buffer-or-buffer-name)
                  (get-buffer buffer-or-buffer-name))))
    (if (and buffer (get-buffer-window buffer))
          (progn
            (read-key-sequence (format "Run command in %s buffer: "
                                       (buffer-name buffer)))
            (with-current-buffer buffer
              (call-interactively
               (key-binding
                (kbd (edmacro-format-keys (vector last-input-event)))))))
      (keyboard-quit))))

(defun help-remote-me ()
  (interactive)
  (remote-control (help-buffer)))
#+end_src

'remote-control' is one that does all the work. There could be
remote-control-other-window-dwim similar as for dired. It is limited to
visible windows, I think it would be easy to make misstakes if operatin on
unvisible windows. Also note while this has utility, it can be a bit confusing.
Anything that moves cursor around will be confusing since cursor is not moving
in remote window, so visual feedback is not always there.

If it would be interesting to develop furhter, where would it belong?
Windmove.el or elswehere?




^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
  2021-09-24 15:31                         ` Juri Linkov
                                             ` (3 preceding siblings ...)
  2021-09-24 20:20                           ` Arthur Miller
@ 2021-09-24 20:33                           ` Arthur Miller
  2021-09-25 18:46                             ` Juri Linkov
  4 siblings, 1 reply; 31+ messages in thread
From: Arthur Miller @ 2021-09-24 20:33 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Eli Zaretskii, larsi, emacs-devel

Juri Linkov <juri@linkov.net> writes:

>> I came up with another idea last night and sent a patch, but I am not sure if it
>> got to right place, I don't see it myself. It was an answer longer in the thread
>> to Lars.
>>
>> This one makes it possible to run any command in *Help* buffer, not just those
>> defined in help-mode.el, and those not need any patching or wrapping of existing
>> commands.
>>
>> I don't know if it is correct place to put define-key for the global map, and I
>> am not sure if C-h M-h is the right, but that's just a detail.
>
> This would be a nice command.  But why it's limited only to help-window?
> It could allow reading and running the key sequences in any next-window.
>
>> +(defun help-do-command ()
>> +  "Run a key-sequence in \"*Help*\" buffer from other buffers.
>> +
>> +If *Help* buffer is not visible, the HELP-DO-COMMAND will be aborterd."
>> +  (interactive)
>> +  (if (get-buffer-window (help-buffer))
>
> I meant to replace '(get-buffer-window (help-buffer))' with '(next-window)'.
>
>> +      (let ((__key (read-key-sequence "Run command in *Help* buffer: ")))
>> +        (with-current-buffer (help-buffer)
>> +          (call-interactively
>> +           (key-binding
>> +            (kbd (edmacro-format-keys (vector last-input-event)))))))
>> +    (call-interactively (global-key-binding "\C-g"))))
>> +
>> +(define-key global-map (kbd "C-h M-h") 'help-do-command)

I tried with next-window, but does it give me current-buffers window when there
are no other windows? When there are two windows, it works fine.

#+begin_src emacs-lisp
(defun remote-control-other-window ()
  (interactive)
  (let ((buffer (window-buffer (next-window))))
    (if (and buffer (get-buffer-window buffer))
        (progn
          (read-key-sequence (format "Run command in %s buffer: "
                                     (buffer-name buffer)))
          (with-current-buffer buffer
            (call-interactively
             (key-binding
              (kbd (edmacro-format-keys (vector last-input-event)))))))
      (keyboard-quit))))
#+end_src



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
  2021-09-24 19:57                             ` Arthur Miller
@ 2021-09-25  6:09                               ` Eli Zaretskii
  2021-09-25 14:41                                 ` 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
  0 siblings, 2 replies; 31+ messages in thread
From: Eli Zaretskii @ 2021-09-25  6:09 UTC (permalink / raw)
  To: Arthur Miller; +Cc: larsi, emacs-devel, juri

> 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.



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
  2021-09-25  6:09                               ` Eli Zaretskii
@ 2021-09-25 14:41                                 ` Arthur Miller
  2021-09-25 14:59                                   ` Eli Zaretskii
  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
  1 sibling, 1 reply; 31+ messages in thread
From: Arthur Miller @ 2021-09-25 14:41 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: larsi, emacs-devel, juri

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

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.

I am sorry, but I don't really understand what you mean here. You would like to
be able to type: C-u C-h M-h s, intead of C-h M-h s? Or  you mean C-h M-h C-u s?

C-h M-h is needed to switch control to the help buffer from the current buffer,
then you are just typing commands as if the cursor was in the help buffer. I
don't know, I don't really understand what you mean there, and I am not sure I
would know how to implement that, so maybe someone else can help with that one?

The obivous alternative I see is to globally define help-mode commands, as
originally suggested and put them on global shortcuts or make help-mode-map
globally accessible, but I think in practice remotely executing commands is
better since the keyboard shortcuts involved are same but all interactive
commands defined in help-mode become automatically avialable without any extra
work. If prompt bothers you, we can pass empty string as prompt in cal to
'read-key-sequence'. I put a descriptive prompt just to make it more clear, but
it is just cosmetics.

Maybe there is other way; but I am not aware of it.

> 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.

Yes, I noticed myself. Since the current buffer is no longer help buffer, Emacs
chooses a bit differently in which window to display source code/info
buffer. Easy hack is to make help window dedicated to help buffer, as in the
attched patch. I have put into the patch so it is done automatic; but maybe it
is better to let users decide on that one by modifying buffer-display-alist?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Send-input-to-help-buffer-form-any-buffer.patch --]
[-- Type: text/x-patch, Size: 1391 bytes --]

From 7e750943df9bb2acaff6d6fa9153636424ec59b2 Mon Sep 17 00:00:00 2001
From: Arthur Miller <arthur.miller@live.com>
Date: Sat, 25 Sep 2021 16:21:07 +0200
Subject: [PATCH] Send input to help-buffer form any buffer

* help-mode.el (help-do-command): New command.
Install help-do-command in global-map on C-h M-h key.
---
 lisp/help-mode.el | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/lisp/help-mode.el b/lisp/help-mode.el
index 551cf7e1a3..6ab6c7e482 100644
--- a/lisp/help-mode.el
+++ b/lisp/help-mode.el
@@ -875,6 +875,23 @@ help-insert-string
   (with-output-to-temp-buffer (help-buffer)
     (insert string)))
 
+(defun help-do-command ()
+  "Execute a command in \"*Help*\" buffer while working in other buffer.
+
+If *Help* buffer is not visible, the HELP-DO-COMMAND will be aborted."
+  (interactive)
+  (if (get-buffer-window (help-buffer))
+      (let ((help-window (get-buffer-window (help-buffer))))
+        (unless (window-dedicated-p help-window)
+          (set-window-dedicated-p help-window t))
+        (read-key-sequence "Run command in *Help* buffer: ")
+        (with-current-buffer (help-buffer)
+          (call-interactively
+           (key-binding
+            (kbd (edmacro-format-keys (vector last-input-event)))))))
+    (keyboard-quit)))
+
+(define-key global-map (kbd "C-h M-h") 'help-do-command)
 \f
 ;; Bookmark support
 
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
  2021-09-25 14:41                                 ` Arthur Miller
@ 2021-09-25 14:59                                   ` Eli Zaretskii
  2021-09-25 16:22                                     ` Arthur Miller
  0 siblings, 1 reply; 31+ messages in thread
From: Eli Zaretskii @ 2021-09-25 14:59 UTC (permalink / raw)
  To: Arthur Miller; +Cc: larsi, emacs-devel, juri

> From: Arthur Miller <arthur.miller@live.com>
> Cc: juri@linkov.net,  larsi@gnus.org,  emacs-devel@gnu.org
> Date: Sat, 25 Sep 2021 16:41:34 +0200
> 
> > 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.
> 
> I am sorry, but I don't really understand what you mean here. You would like to
> be able to type: C-u C-h M-h s, intead of C-h M-h s?

No, I'd prefer not to be shown a prompt for another key.

> The obivous alternative I see is to globally define help-mode commands

Some of them, yes.

> Maybe there is other way; but I am not aware of it.

The other way is to have a prefix key "C-h M-h".



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
  2021-09-25 14:59                                   ` Eli Zaretskii
@ 2021-09-25 16:22                                     ` Arthur Miller
  2021-09-25 16:26                                       ` Eli Zaretskii
  0 siblings, 1 reply; 31+ messages in thread
From: Arthur Miller @ 2021-09-25 16:22 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: larsi, juri, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Arthur Miller <arthur.miller@live.com>
>> Cc: juri@linkov.net,  larsi@gnus.org,  emacs-devel@gnu.org
>> Date: Sat, 25 Sep 2021 16:41:34 +0200
>> 
>> > 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.
>> 
>> I am sorry, but I don't really understand what you mean here. You would like to
>> be able to type: C-u C-h M-h s, intead of C-h M-h s?
>
> No, I'd prefer not to be shown a prompt for another key.

Try the attached patch. It shows no prompt, so you can just type C-h M-h s and
it will pop source in another window. I don't have any feel of being "prompted".

>> The obivous alternative I see is to globally define help-mode commands
>
> Some of them, yes.
But that is extra work; this solution does it for free, and will work with
future commands in help-mode, if they get defined, no?

>> Maybe there is other way; but I am not aware of it.
>
> The other way is to have a prefix key "C-h M-h".

What is the difference and extra benefit? It is still "same typing"? It
effectively acts like a prefix key since it is executed in help-mode buffer; it
is same effect as putting help-mode-map on a prefix key. And one can rebind the
function to any key; maybe someone can find some easier to type shortcut than
C-h M-h? I am sorry but I probably just don't understand what you are asking for.




^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
  2021-09-25 16:22                                     ` Arthur Miller
@ 2021-09-25 16:26                                       ` Eli Zaretskii
  2021-09-25 17:08                                         ` Arthur Miller
  0 siblings, 1 reply; 31+ messages in thread
From: Eli Zaretskii @ 2021-09-25 16:26 UTC (permalink / raw)
  To: Arthur Miller; +Cc: larsi, emacs-devel, juri

> From: Arthur Miller <arthur.miller@live.com>
> Date: Sat, 25 Sep 2021 18:22:42 +0200
> Cc: larsi@gnus.org, juri@linkov.net, emacs-devel@gnu.org
> 
> > No, I'd prefer not to be shown a prompt for another key.
> 
> Try the attached patch.

ENOPATCH

> > The other way is to have a prefix key "C-h M-h".
> 
> What is the difference and extra benefit?

It's cleaner, IMO.



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
  2021-09-25 16:26                                       ` Eli Zaretskii
@ 2021-09-25 17:08                                         ` Arthur Miller
  2021-09-25 17:20                                           ` Eli Zaretskii
  2021-09-26  9:11                                           ` martin rudalics
  0 siblings, 2 replies; 31+ messages in thread
From: Arthur Miller @ 2021-09-25 17:08 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: larsi, juri, emacs-devel

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

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Arthur Miller <arthur.miller@live.com>
>> Date: Sat, 25 Sep 2021 18:22:42 +0200
>> Cc: larsi@gnus.org, juri@linkov.net, emacs-devel@gnu.org
>> 
>> > No, I'd prefer not to be shown a prompt for another key.
>> 
>> Try the attached patch.
>
> ENOPATCH

Oh, I am sorry :-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Send-input-to-help-buffer-form-any-buffer.patch --]
[-- Type: text/x-patch, Size: 1361 bytes --]

From a918b47feaa307808c5b2a3c913802b502ff61aa Mon Sep 17 00:00:00 2001
From: Arthur Miller <arthur.miller@live.com>
Date: Sat, 25 Sep 2021 18:11:13 +0200
Subject: [PATCH] Send input to help-buffer form any buffer

* help-mode.el (help-do-command): New command.
Install help-do-command in global-map on C-h M-h key.
---
 lisp/help-mode.el | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/lisp/help-mode.el b/lisp/help-mode.el
index 551cf7e1a3..1a810e4379 100644
--- a/lisp/help-mode.el
+++ b/lisp/help-mode.el
@@ -875,6 +875,23 @@ help-insert-string
   (with-output-to-temp-buffer (help-buffer)
     (insert string)))
 
+(defun help-do-command ()
+  "Execute a command in \"*Help*\" buffer while working in other buffer.
+
+If *Help* buffer is not visible, the HELP-DO-COMMAND will be aborted."
+  (interactive)
+  (if (get-buffer-window (help-buffer))
+      (let ((help-window (get-buffer-window (help-buffer))))
+        (unless (window-dedicated-p help-window)
+          (set-window-dedicated-p help-window t))
+        (read-key-sequence "")
+        (with-current-buffer (help-buffer)
+          (call-interactively
+           (key-binding
+            (kbd (edmacro-format-keys (vector last-input-event)))))))
+    (keyboard-quit)))
+
+(define-key global-map (kbd "C-h M-h") 'help-do-command)
 \f
 ;; Bookmark support
 
-- 
2.33.0


[-- Attachment #3: Type: text/plain, Size: 132 bytes --]


>> > The other way is to have a prefix key "C-h M-h".
>> 
>> What is the difference and extra benefit?
>
> It's cleaner, IMO.

Ok.

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
  2021-09-25 17:08                                         ` Arthur Miller
@ 2021-09-25 17:20                                           ` Eli Zaretskii
  2021-09-25 20:15                                             ` Arthur Miller
  2021-09-26  9:11                                           ` martin rudalics
  1 sibling, 1 reply; 31+ messages in thread
From: Eli Zaretskii @ 2021-09-25 17:20 UTC (permalink / raw)
  To: Arthur Miller; +Cc: larsi, juri, emacs-devel

> From: Arthur Miller <arthur.miller@live.com>
> Cc: larsi@gnus.org,  emacs-devel@gnu.org,  juri@linkov.net
> Date: Sat, 25 Sep 2021 19:08:05 +0200
> 
> >> > No, I'd prefer not to be shown a prompt for another key.
> >> 
> >> Try the attached patch.
> >
> > ENOPATCH
> 
> Oh, I am sorry :-)

Thanks, but this still prompts for a key, just silently so.



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
  2021-09-24 20:33                           ` Arthur Miller
@ 2021-09-25 18:46                             ` Juri Linkov
  0 siblings, 0 replies; 31+ messages in thread
From: Juri Linkov @ 2021-09-25 18:46 UTC (permalink / raw)
  To: Arthur Miller; +Cc: Eli Zaretskii, larsi, emacs-devel

> #+begin_src emacs-lisp
> (defun remote-control-other-window ()
>   (interactive)
>   (let ((buffer (window-buffer (next-window))))
>     (if (and buffer (get-buffer-window buffer))
>         (progn
>           (read-key-sequence (format "Run command in %s buffer: "
>                                      (buffer-name buffer)))
>           (with-current-buffer buffer
>             (call-interactively
>              (key-binding
>               (kbd (edmacro-format-keys (vector last-input-event)))))))
>       (keyboard-quit))))
> #+end_src

Thanks, I missed such a command for a long time.
And 'remote-control-other-window' is an exact name.

> I tried with next-window, but does it give me current-buffers window
> when there are no other windows? When there are two windows, it works fine.

It does no harm when the command is redirected to the same single window.

> If it would be interesting to develop furhter, where would it belong?
> Windmove.el or elswehere?

Windmove.el looks like the most suitable place since it also
provides quick keys for customization.  The same way you can choose
a key to use another window, like there are already similar keys
to scroll another window with M-<next>/C-M-v and M-<prior>/C-M-S-v,
etc.



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
  2021-09-25 17:20                                           ` Eli Zaretskii
@ 2021-09-25 20:15                                             ` Arthur Miller
  2021-09-26 21:52                                               ` Arthur Miller
  0 siblings, 1 reply; 31+ messages in thread
From: Arthur Miller @ 2021-09-25 20:15 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: larsi, emacs-devel, juri

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

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Arthur Miller <arthur.miller@live.com>
>> Cc: larsi@gnus.org,  emacs-devel@gnu.org,  juri@linkov.net
>> Date: Sat, 25 Sep 2021 19:08:05 +0200
>> 
>> >> > No, I'd prefer not to be shown a prompt for another key.
>> >> 
>> >> Try the attached patch.
>> >
>> > ENOPATCH
>> 
>> Oh, I am sorry :-)
>
> Thanks, but this still prompts for a key, just silently so.

Yes, exactly, you said you were bothered by the prompt :-). Without seing the
prompt it feels like you are just ordinary shortcut. At least for me.

Anyway, I have tested with the prefix key, it does make for one difference:
it shows me the panel for which-key which shows all completions, which
read-key-sequence does not.

In this case I had to hack those commands exported by help-mode as described
before. Lars didn't like that, so you will have to agree on how to solve what is
preferred here.

For the note: is it acceptable to have this simplified customize? It works for
me, but there is no checks for validity etc. I don't know how to write it so it
take a valid prefix and so on.


[-- 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: 5621 bytes --]

From c70e38e9ff9678a7105f39a5efff7596d3452e2f Mon Sep 17 00:00:00 2001
From: Arthur Miller <arthur.miller@live.com>
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")
 \f
 ;; 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)))
 \f
 ;; 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


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
  2021-09-25 17:08                                         ` Arthur Miller
  2021-09-25 17:20                                           ` Eli Zaretskii
@ 2021-09-26  9:11                                           ` martin rudalics
  2021-09-26 16:11                                             ` Arthur Miller
  1 sibling, 1 reply; 31+ messages in thread
From: martin rudalics @ 2021-09-26  9:11 UTC (permalink / raw)
  To: Arthur Miller, Eli Zaretskii; +Cc: larsi, emacs-devel, juri

here.+  (if (get-buffer-window (help-buffer))
+      (let ((help-window (get-buffer-window (help-buffer))))
+        (unless (window-dedicated-p help-window)

Please use an idiom like

(when (get-buffer "*Help*")
   (let ((help-window (get-buffer-window "*Help*")))
     (when help-window
       ...

instead.

Thanks, martin




^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
  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 17:51                                               ` martin rudalics
  0 siblings, 2 replies; 31+ messages in thread
From: Arthur Miller @ 2021-09-26 16:11 UTC (permalink / raw)
  To: martin rudalics; +Cc: Eli Zaretskii, emacs-devel, larsi, juri

martin rudalics <rudalics@gmx.at> writes:

> here.+  (if (get-buffer-window (help-buffer))
> +      (let ((help-window (get-buffer-window (help-buffer))))
> +        (unless (window-dedicated-p help-window)
>
> Please use an idiom like
>
> (when (get-buffer "*Help*")
>   (let ((help-window (get-buffer-window "*Help*")))
>     (when help-window
>       ...
>
> instead.

I agree, but I don't like to see hardcoded *Help* string all over the place. I
don't think it will change in near future, if ever, but since I have used this
in several places, and plan to suggest some other commands for help buffer, I
think we can abstract it even further into something like this:

#+begin_src emacs-lisp
(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)))
#+end_src

I see some problems with the latest patch I sent to Eli last night. I don't
understand why it worked last night, but does not work today :), but I have
probably had somewhere some state that I evaled, while I was tested.

I can add those two and rework patch to use them when I am done with it. It
loosk cleaner in those interactive commands.



^ permalink raw reply	[flat|nested] 31+ messages in thread

* RE: [External] : Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
  2021-09-26 16:11                                             ` Arthur Miller
@ 2021-09-26 16:54                                               ` Drew Adams
  2021-09-26 21:51                                                 ` Arthur Miller
  2021-09-26 17:51                                               ` martin rudalics
  1 sibling, 1 reply; 31+ messages in thread
From: Drew Adams @ 2021-09-26 16:54 UTC (permalink / raw)
  To: Arthur Miller, martin rudalics
  Cc: Eli Zaretskii, juri@linkov.net, larsi@gnus.org,
	emacs-devel@gnu.org

> I don't like to see hardcoded *Help* string all over the place.

We have function `help-buffer', which is generally
used instead of a hardcoded "*Help*" buffer name.

(I'm not following everything in this thread, so
sorry if not germain.)




^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
  2021-09-26 16:11                                             ` Arthur Miller
  2021-09-26 16:54                                               ` [External] : " Drew Adams
@ 2021-09-26 17:51                                               ` martin rudalics
  2021-09-26 21:48                                                 ` Arthur Miller
  1 sibling, 1 reply; 31+ messages in thread
From: martin rudalics @ 2021-09-26 17:51 UTC (permalink / raw)
  To: Arthur Miller; +Cc: Eli Zaretskii, juri, larsi, emacs-devel

 > I agree, but I don't like to see hardcoded *Help* string all over the place. I
 > don't think it will change in near future, if ever, but since I have used this
 > in several places, and plan to suggest some other commands for help buffer, I
 > think we can abstract it even further into something like this:

The help buffer is "*Help*" - look at the code of `help-buffer'.  The
problem with using `help-buffer' is that it creates *Help* if it didn't
exist before.  Do you really want your function to do that?

martin



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
  2021-09-26 17:51                                               ` martin rudalics
@ 2021-09-26 21:48                                                 ` Arthur Miller
  0 siblings, 0 replies; 31+ messages in thread
From: Arthur Miller @ 2021-09-26 21:48 UTC (permalink / raw)
  To: martin rudalics; +Cc: Eli Zaretskii, juri, larsi, emacs-devel

martin rudalics <rudalics@gmx.at> writes:

>> I agree, but I don't like to see hardcoded *Help* string all over the place. I
>> don't think it will change in near future, if ever, but since I have used this
>> in several places, and plan to suggest some other commands for help buffer, I
>> think we can abstract it even further into something like this:
>
> The help buffer is "*Help*" - look at the code of `help-buffer'.

Yes, I know, I have seen how (help-buffer) works :).

>                                                                   The
> problem with using `help-buffer' is that it creates *Help* if it didn't
> exist before.  Do you really want your function to do that?

Yes, the rationale was that for people who use built-in help, the buffer will be
created anyway. The new object will not be a waste, it will be used next time
buffer is created. I didn't thought that somone would see it as a problem.

I was also affraid that something somewhere, would throw me into
degubber. didn't want to accidentally end up in debugger which woudl be a
nuissance in this context. That felt like a punishment for a user who pressed a
button by accident :-).

But I have tested a bit with 'get-buffer' and it just returns silently nil, and
sent you a suggestion for better astraction anyway, the functions'help-window' and
macro 'with-help-buffer'. I haven't had time to code anything today though,
regarding the patch I'll see if I can sit a moment before I go to bed now.



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [External] : Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
  2021-09-26 16:54                                               ` [External] : " Drew Adams
@ 2021-09-26 21:51                                                 ` Arthur Miller
  2021-09-26 22:38                                                   ` Drew Adams
  0 siblings, 1 reply; 31+ messages in thread
From: Arthur Miller @ 2021-09-26 21:51 UTC (permalink / raw)
  To: Drew Adams
  Cc: martin rudalics, Eli Zaretskii, juri@linkov.net, larsi@gnus.org,
	emacs-devel@gnu.org

Drew Adams <drew.adams@oracle.com> writes:

>> I don't like to see hardcoded *Help* string all over the place.
>
> We have function `help-buffer', which is generally
> used instead of a hardcoded "*Help*" buffer name.
>
> (I'm not following everything in this thread, so
> sorry if not germain.)

Yes, I see; because what you suggest was exactly what I did, check the patch I
sent to Eli :).

I think the 'help-window' and 'with-help-buffer' are even better abstractions for
this particualr case. I have put them into my patch and it looks neater with
them. I have just to fix that with prefix which does not seem to work after I
started a fresh Emacs today :).



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
  2021-09-25 20:15                                             ` Arthur Miller
@ 2021-09-26 21:52                                               ` Arthur Miller
  0 siblings, 0 replies; 31+ messages in thread
From: Arthur Miller @ 2021-09-26 21:52 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: larsi, juri, emacs-devel

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

> Eli Zaretskii <eliz@gnu.org> writes:
>
>>> From: Arthur Miller <arthur.miller@live.com>
>>> Cc: larsi@gnus.org,  emacs-devel@gnu.org,  juri@linkov.net
>>> Date: Sat, 25 Sep 2021 19:08:05 +0200
>>> 
>>> >> > No, I'd prefer not to be shown a prompt for another key.
>>> >> 
>>> >> Try the attached patch.
>>> >
>>> > ENOPATCH
>>> 
>>> Oh, I am sorry :-)
>>
>> Thanks, but this still prompts for a key, just silently so.
>
> Yes, exactly, you said you were bothered by the prompt :-). Without seing the
> prompt it feels like you are just ordinary shortcut. At least for me.
>
> Anyway, I have tested with the prefix key, it does make for one difference:
> it shows me the panel for which-key which shows all completions, which
> read-key-sequence does not.
>
> In this case I had to hack those commands exported by help-mode as described
> before. Lars didn't like that, so you will have to agree on how to solve what is
> preferred here.
>
> For the note: is it acceptable to have this simplified customize? It works for
> me, but there is no checks for validity etc. I don't know how to write it so it
> take a valid prefix and so on.

I am sorry, for some reason the prefix key is unknown in a fresh Emacs
:). Worked for me so well yesterday when I teste, I must have some evaled
remains when I was tested and I didn't noticed. Thought I woudl have time to
send new one today, but I didn't. Will send one when I have solved that with
prefix command and key. 



^ permalink raw reply	[flat|nested] 31+ messages in thread

* RE: [External] : Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
  2021-09-26 21:51                                                 ` Arthur Miller
@ 2021-09-26 22:38                                                   ` Drew Adams
  2021-09-26 22:46                                                     ` Arthur Miller
  0 siblings, 1 reply; 31+ messages in thread
From: Drew Adams @ 2021-09-26 22:38 UTC (permalink / raw)
  To: Arthur Miller
  Cc: martin rudalics, Eli Zaretskii, juri@linkov.net, larsi@gnus.org,
	emacs-devel@gnu.org

> > (I'm not following everything in this thread,
> > so sorry if not germain.)

After I saw your reply msg I realized I wrote
"germain" instead of "germane".  St Germain
des Pres on the brain, no doubt...



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [External] : Re: bug#36767: 26.1; request: add more quick keys to the *Help* buffer
  2021-09-26 22:38                                                   ` Drew Adams
@ 2021-09-26 22:46                                                     ` Arthur Miller
  0 siblings, 0 replies; 31+ messages in thread
From: Arthur Miller @ 2021-09-26 22:46 UTC (permalink / raw)
  To: Drew Adams
  Cc: martin rudalics, Eli Zaretskii, juri@linkov.net, larsi@gnus.org,
	emacs-devel@gnu.org

Drew Adams <drew.adams@oracle.com> writes:

>> > (I'm not following everything in this thread,
>> > so sorry if not germain.)
>
> After I saw your reply msg I realized I wrote
> "germain" instead of "germane".  St Germain
> des Pres on the brain, no doubt...

St Germain So Flute ...

https://www.youtube.com/watch?v=BX5-i7BCenw&list=PLW0M5yptNMmrZcRoD2_m_D4zciEWXJCCw&index=3



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Exec help commands from other buffer (was bug#36767: 26.1; request: add more quick keys to the *Help* buffer)
  2021-09-25  6:09                               ` Eli Zaretskii
  2021-09-25 14:41                                 ` Arthur Miller
@ 2021-09-27 11:07                                 ` Arthur Miller
  2021-09-27 19:59                                   ` Arthur Miller
  1 sibling, 1 reply; 31+ messages in thread
From: Arthur Miller @ 2021-09-27 11:07 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: martin rudalics, larsi, emacs-devel, Drew Adams, juri

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

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?


[-- 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: 6771 bytes --]

From c3452b69bbedffa971d6ad8741e06b99a6cd72cb Mon Sep 17 00:00:00 2001
From: Arthur Miller <arthur.miller@live.com>
Date: Mon, 27 Sep 2021 13:06:58 +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..b46ab21d29 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 'helm-command-prefix helm-command-map)
+    (setq  helm-command-prefix helm-command-map)
+    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."
+  :group 'helm-config
+  :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


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* Re: Exec help commands from other buffer (was bug#36767: 26.1; request: add more quick keys to the *Help* buffer)
  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
  0 siblings, 0 replies; 31+ messages in thread
From: Arthur Miller @ 2021-09-27 19:59 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: martin rudalics, larsi, juri, Drew Adams, emacs-devel

[-- 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


^ permalink raw reply related	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2021-09-27 19:59 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <AxtnEw.onqlxb7Mkpry.ig9TynsmAb80jvlU3CY7@freemail.hu>
     [not found] ` <87mtrrq7t7.fsf@gnus.org>
     [not found]   ` <AM9PR09MB4977DAFB86D88A4714C1C64196A29@AM9PR09MB4977.eurprd09.prod.outlook.com>
     [not found]     ` <87pmt0qomh.fsf@gnus.org>
     [not found]       ` <AM9PR09MB49770845B0C1B7CBB331E68A96A39@AM9PR09MB4977.eurprd09.prod.outlook.com>
     [not found]         ` <87wnn7xbdg.fsf@gnus.org>
2021-09-23 22:18           ` bug#36767: 26.1; request: add more quick keys to the *Help* buffer Arthur Miller
     [not found]   ` <87eed0nsez.fsf@mail.linkov.net>
     [not found]     ` <83bl83zp5h.fsf@gnu.org>
     [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>
     [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
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

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).