* bug#74903: [PATCH] Add function to show table of keys when describing keymap variable
@ 2024-12-15 23:14 Mekeor Melire
2024-12-16 15:57 ` Eli Zaretskii
0 siblings, 1 reply; 13+ messages in thread
From: Mekeor Melire @ 2024-12-15 23:14 UTC (permalink / raw)
To: 74903
[-- Attachment #1: Type: text/plain, Size: 428 bytes --]
Tags: patch
It'd be nice if users could opt in to have C-h v some-map RET show a
nice table of key bindings for that keymap. I wrote a function that can
be added to help-fns-describe-variable-functions so that this happens.
What do you think?
Alternatively, we can also add a key binding to help-mode so that users
can easily "switch" from describe-variable to describe-keymap, e.g. per
"K":
C-h v message-mode-map RET K
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-function-to-show-table-of-keys-when-describing-k.patch --]
[-- Type: text/patch, Size: 2193 bytes --]
From df0fbd4d61a0d0bebcb050f4f22a5ae4c67d0f65 Mon Sep 17 00:00:00 2001
From: Mekeor Melire <mekeor@posteo.de>
Date: Sun, 15 Dec 2024 23:21:00 +0100
Subject: [PATCH] Add function to show table of keys when describing keymap
variable
* lisp/help-fns.el (help-fns-keymap-key-bindings): New function possible
member of 'help-fns-describe-variable-functions' that shows a table of
key bindings.
* etc/NEWS: Advertise it.
---
etc/NEWS | 12 ++++++++++++
lisp/help-fns.el | 10 ++++++++++
2 files changed, 22 insertions(+)
diff --git a/etc/NEWS b/etc/NEWS
index 48546a2d916..9ae50ddb923 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -220,6 +220,18 @@ on the header lines are now these two: the selected window uses
** In 'customize-face', the "Font family" attribute now supports completion.
+** Help
+
++++
+*** New function 'help-fns-keymap-key-bindings'.
+This function inserts into the current buffer a table of key bindings if
+the given argument is a variable with a keymap as value. If you want
+'describe-variable' ('C-h v') to insert a table of key bindings into
+regular "*Help*" buffers, add the following to your init file:
+
+ (add-hook 'help-fns-describe-function-functions
+ #'help-fns-keymap-key-bindings)
+
\f
* Editing Changes in Emacs 31.1
diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index 157ec6b8d61..4ed4c64f3ea 100644
--- a/lisp/help-fns.el
+++ b/lisp/help-fns.el
@@ -563,6 +563,16 @@ find-lisp-object-file-name
(src-file (locate-library file-name t nil 'readable)))
(and src-file (file-readable-p src-file) src-file))))))
+(defun help-fns-keymap-key-bindings (variable)
+ "Insert table of key bindings of keymap VARIABLE into the current buffer.
+You can add this function to the `help-fns-describe-function-functions'
+hook to show examples of using FUNCTION in *Help* buffers produced by
+\\[describe-function]."
+ (when-let* ((value (symbol-value variable))
+ ((keymapp value)))
+ (with-current-buffer standard-output
+ (help--describe-map-tree value))))
+
(defun help-fns--key-bindings (function)
(when (commandp function)
(let ((pt2 (with-current-buffer standard-output (point)))
--
2.47.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* bug#74903: [PATCH] Add function to show table of keys when describing keymap variable
2024-12-15 23:14 bug#74903: [PATCH] Add function to show table of keys when describing keymap variable Mekeor Melire
@ 2024-12-16 15:57 ` Eli Zaretskii
2024-12-16 17:28 ` Robert Pluim
2024-12-17 2:56 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 2 replies; 13+ messages in thread
From: Eli Zaretskii @ 2024-12-16 15:57 UTC (permalink / raw)
To: Mekeor Melire, Stefan Kangas, Andrea Corallo, Stefan Monnier; +Cc: 74903
> From: Mekeor Melire <mekeor@posteo.de>
> Date: Sun, 15 Dec 2024 23:14:15 +0000
>
> It'd be nice if users could opt in to have C-h v some-map RET show a
> nice table of key bindings for that keymap. I wrote a function that can
> be added to help-fns-describe-variable-functions so that this happens.
>
> What do you think?
>
> Alternatively, we can also add a key binding to help-mode so that users
> can easily "switch" from describe-variable to describe-keymap, e.g. per
> "K":
>
> C-h v message-mode-map RET K
We have "C-h b" and "C-h m" which show the bindings, albeit not by
keymap. Is that not enough for some reason?
Adding yet another help command related to key bindings needs to be
justified, since we already have at least two with overlapping
functionalities.
What do others think about this?
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#74903: [PATCH] Add function to show table of keys when describing keymap variable
2024-12-16 15:57 ` Eli Zaretskii
@ 2024-12-16 17:28 ` Robert Pluim
2024-12-16 18:41 ` Mekeor Melire
2024-12-17 2:56 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
1 sibling, 1 reply; 13+ messages in thread
From: Robert Pluim @ 2024-12-16 17:28 UTC (permalink / raw)
To: Eli Zaretskii
Cc: Mekeor Melire, Andrea Corallo, Stefan Kangas, 74903,
Stefan Monnier
>>>>> On Mon, 16 Dec 2024 17:57:14 +0200, Eli Zaretskii <eliz@gnu.org> said:
>> From: Mekeor Melire <mekeor@posteo.de>
>> Date: Sun, 15 Dec 2024 23:14:15 +0000
>>
>> It'd be nice if users could opt in to have C-h v some-map RET show a
>> nice table of key bindings for that keymap. I wrote a function that can
>> be added to help-fns-describe-variable-functions so that this happens.
>>
>> What do you think?
>>
>> Alternatively, we can also add a key binding to help-mode so that users
>> can easily "switch" from describe-variable to describe-keymap, e.g. per
>> "K":
>>
>> C-h v message-mode-map RET K
Eli> We have "C-h b" and "C-h m" which show the bindings, albeit not by
Eli> keymap. Is that not enough for some reason?
"C-h b" shows all the bindings split out by major and minor mode
already. I guess we could add the name of the relevant keymap as well,
but the people who need to know the name of the keymap generally know
enough about Emacs to figure it out (eg via "C-h k").
Eli> Adding yet another help command related to key bindings needs to be
Eli> justified, since we already have at least two with overlapping
Eli> functionalities.
Eli> What do others think about this?
I really donʼt see the need for more functionality here.
Robert
--
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#74903: [PATCH] Add function to show table of keys when describing keymap variable
2024-12-16 17:28 ` Robert Pluim
@ 2024-12-16 18:41 ` Mekeor Melire
2024-12-17 3:03 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-17 7:49 ` Robert Pluim
0 siblings, 2 replies; 13+ messages in thread
From: Mekeor Melire @ 2024-12-16 18:41 UTC (permalink / raw)
To: Robert Pluim, Eli Zaretskii
Cc: Andrea Corallo, Stefan Kangas, 74903, Stefan Monnier
[-- Attachment #1: Type: text/plain, Size: 2209 bytes --]
On December 16, 2024 6:28:58 PM GMT+01:00, Robert Pluim <rpluim@gmail.com> wrote:
>>>>>> On Mon, 16 Dec 2024 17:57:14 +0200, Eli Zaretskii <eliz@gnu.org> said:
>
> >> From: Mekeor Melire <mekeor@posteo.de>
> >> Date: Sun, 15 Dec 2024 23:14:15 +0000
> >>
> >> It'd be nice if users could opt in to have C-h v some-map RET show a
> >> nice table of key bindings for that keymap. I wrote a function that can
> >> be added to help-fns-describe-variable-functions so that this happens.
> >>
> >> What do you think?
> >>
> >> Alternatively, we can also add a key binding to help-mode so that users
> >> can easily "switch" from describe-variable to describe-keymap, e.g. per
> >> "K":
> >>
> >> C-h v message-mode-map RET K
>
> Eli> We have "C-h b" and "C-h m" which show the bindings, albeit not by
> Eli> keymap. Is that not enough for some reason?
>
>"C-h b" shows all the bindings split out by major and minor mode
>already. I guess we could add the name of the relevant keymap as well,
>but the people who need to know the name of the keymap generally know
>enough about Emacs to figure it out (eg via "C-h k").
>
> Eli> Adding yet another help command related to key bindings needs to be
> Eli> justified, since we already have at least two with overlapping
> Eli> functionalities.
>
> Eli> What do others think about this?
>
>I really donʼt see the need for more functionality here.
>
>Robert
>--
I get the impression that you talk about M-x describe-keymap RET which does already exist.
That is not what I proposed. What I proposed is two things:
1. Allow users to opt-in to have C-h v foo-keymap RET show a table of key bindings in addition to the formatting as S-expression. This fits well into the existing help-fns mechanism. The patch I submitted implements a prototype.
2. In help-mode, bind a single-char-key like "K" to a command that will allow users to easily switch from describing a variable as variable to describing it as keymap a la describe-keymap.
I proposed (2.) as an alternative to (1.) but my main proposal is (1.). Both approaches have a similar objection though.
[-- Attachment #2: Type: text/html, Size: 3490 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#74903: [PATCH] Add function to show table of keys when describing keymap variable
2024-12-16 15:57 ` Eli Zaretskii
2024-12-16 17:28 ` Robert Pluim
@ 2024-12-17 2:56 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-18 0:21 ` Mekeor Melire
1 sibling, 1 reply; 13+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-12-17 2:56 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: Mekeor Melire, Andrea Corallo, Stefan Kangas, 74903
>> It'd be nice if users could opt in to have C-h v some-map RET show a
>> nice table of key bindings for that keymap. I wrote a function that can
>> be added to help-fns-describe-variable-functions so that this happens.
>>
>> What do you think?
>>
>> Alternatively, we can also add a key binding to help-mode so that users
>> can easily "switch" from describe-variable to describe-keymap, e.g. per
>> "K":
>>
>> C-h v message-mode-map RET K
>
> We have "C-h b" and "C-h m" which show the bindings, albeit not by
> keymap. Is that not enough for some reason?
It's quite different, since his proposal is about displaying keymap
values held in variables (i.e. not necessarily currently active).
> Adding yet another help command related to key bindings needs to be
> justified, since we already have at least two with overlapping
> functionalities.
AFAICT his proposal does not add any new command (help or other).
What am I missing?
Stefan
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#74903: [PATCH] Add function to show table of keys when describing keymap variable
2024-12-16 18:41 ` Mekeor Melire
@ 2024-12-17 3:03 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-17 7:49 ` Robert Pluim
1 sibling, 0 replies; 13+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-12-17 3:03 UTC (permalink / raw)
To: Mekeor Melire
Cc: Robert Pluim, Andrea Corallo, Eli Zaretskii, 74903, Stefan Kangas
> 1. Allow users to opt-in to have C-h v foo-keymap RET show a table of key
> bindings in addition to the formatting as S-expression. This fits well into
> the existing help-fns mechanism. The patch I submitted implements
> a prototype.
>
> 2. In help-mode, bind a single-char-key like "K" to a command that will
> allow users to easily switch from describing a variable as variable to
> describing it as keymap a la describe-keymap.
The table is a bit redundant with the s-exp representation and I'm not
sure we want to spend all this time&space printing out a large keymap,
but maybe we could use the `help-fns-describe-variable-functions`
mechanism to add a one-liner that can be clicked to get to the
keymap-specific description, a bit like Custom vars have a "You can
customize this variable" link.
WDYT?
[ There is also something to be said to spice up `describe-keymap` so it
can be used to *modify* a keymap. But that comes with many more
difficulties (the main one being how to save those modifications so
they survive a restart). ]
Stefan
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#74903: [PATCH] Add function to show table of keys when describing keymap variable
2024-12-16 18:41 ` Mekeor Melire
2024-12-17 3:03 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-12-17 7:49 ` Robert Pluim
2024-12-17 7:59 ` Juri Linkov
1 sibling, 1 reply; 13+ messages in thread
From: Robert Pluim @ 2024-12-17 7:49 UTC (permalink / raw)
To: Mekeor Melire
Cc: Eli Zaretskii, Andrea Corallo, Stefan Kangas, 74903,
Stefan Monnier
>>>>> On Mon, 16 Dec 2024 18:41:19 +0000, Mekeor Melire <mekeor@posteo.de> said:
Mekeor> I get the impression that you talk about M-x describe-keymap RET which does already exist.
No, Iʼm talking about `describe-bindings'.
Mekeor> That is not what I proposed. What I proposed is two things:
Mekeor> 1. Allow users to opt-in to have C-h v foo-keymap RET show a table of
Mekeor> key bindings in addition to the formatting as S-expression. This fits
Mekeor> well into the existing help-fns mechanism. The patch I submitted
Mekeor> implements a prototype.
Again, I donʼt see a need for it. A user trying to figure out
keybindings is not going to be inspecting keymap variables, and
`describe-bindings' or `describe-mode' tells them what they need to
know. A developer writing code presumably knows about keymaps, and
doesnʼt need a different visual representation of them to get stuff
done.
Mekeor> 2. In help-mode, bind a single-char-key like "K" to a
Mekeor> command that will allow users to easily switch from
Mekeor> describing a variable as variable to describing it as
Mekeor> keymap a la describe-keymap.
See my previous paragraph.
Robert
--
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#74903: [PATCH] Add function to show table of keys when describing keymap variable
2024-12-17 7:49 ` Robert Pluim
@ 2024-12-17 7:59 ` Juri Linkov
2024-12-17 8:32 ` Robert Pluim
0 siblings, 1 reply; 13+ messages in thread
From: Juri Linkov @ 2024-12-17 7:59 UTC (permalink / raw)
To: Robert Pluim
Cc: 74903, Mekeor Melire, Stefan Kangas, Eli Zaretskii,
Andrea Corallo, Stefan Monnier
> Mekeor> 1. Allow users to opt-in to have C-h v foo-keymap RET show a table of
> Mekeor> key bindings in addition to the formatting as S-expression. This fits
> Mekeor> well into the existing help-fns mechanism. The patch I submitted
> Mekeor> implements a prototype.
>
> Again, I donʼt see a need for it. A user trying to figure out
> keybindings is not going to be inspecting keymap variables, and
> `describe-bindings' or `describe-mode' tells them what they need to
> know. A developer writing code presumably knows about keymaps, and
> doesnʼt need a different visual representation of them to get stuff
> done.
It would be nice if users will be able first to see keymap tables
in the output of `describe-repeat-maps', then click on a map
variable, and see the same keymap table individually.
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#74903: [PATCH] Add function to show table of keys when describing keymap variable
2024-12-17 7:59 ` Juri Linkov
@ 2024-12-17 8:32 ` Robert Pluim
2024-12-17 19:00 ` Juri Linkov
0 siblings, 1 reply; 13+ messages in thread
From: Robert Pluim @ 2024-12-17 8:32 UTC (permalink / raw)
To: Juri Linkov
Cc: 74903, Mekeor Melire, Stefan Kangas, Eli Zaretskii,
Andrea Corallo, Stefan Monnier
>>>>> On Tue, 17 Dec 2024 09:59:57 +0200, Juri Linkov <juri@linkov.net> said:
Mekeor> 1. Allow users to opt-in to have C-h v foo-keymap RET show a table of
Mekeor> key bindings in addition to the formatting as S-expression. This fits
Mekeor> well into the existing help-fns mechanism. The patch I submitted
Mekeor> implements a prototype.
>>
>> Again, I donʼt see a need for it. A user trying to figure out
>> keybindings is not going to be inspecting keymap variables, and
>> `describe-bindings' or `describe-mode' tells them what they need to
>> know. A developer writing code presumably knows about keymaps, and
>> doesnʼt need a different visual representation of them to get stuff
>> done.
Juri> It would be nice if users will be able first to see keymap tables
Juri> in the output of `describe-repeat-maps', then click on a map
Juri> variable, and see the same keymap table individually.
? I must be misunderstanding, because thatʼs already how
`describe-repeat-maps' works.
Robert
--
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#74903: [PATCH] Add function to show table of keys when describing keymap variable
2024-12-17 8:32 ` Robert Pluim
@ 2024-12-17 19:00 ` Juri Linkov
2024-12-18 12:04 ` Robert Pluim
0 siblings, 1 reply; 13+ messages in thread
From: Juri Linkov @ 2024-12-17 19:00 UTC (permalink / raw)
To: Robert Pluim
Cc: 74903, Mekeor Melire, Stefan Kangas, Eli Zaretskii,
Andrea Corallo, Stefan Monnier
>> It would be nice if users will be able first to see keymap tables
>> in the output of `describe-repeat-maps', then click on a map
>> variable, and see the same keymap table individually.
>
> ? I must be misunderstanding, because thatʼs already how
> `describe-repeat-maps' works.
I meant that after clicking on the map variable in the heading
it could show the same keymap.
BTW, I just finally fixed `describe-repeat-maps' to use the very
useful function 'cl--map-keymap-recursively' instead of 'map-keymap'.
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#74903: [PATCH] Add function to show table of keys when describing keymap variable
2024-12-17 2:56 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-12-18 0:21 ` Mekeor Melire
0 siblings, 0 replies; 13+ messages in thread
From: Mekeor Melire @ 2024-12-18 0:21 UTC (permalink / raw)
To: Stefan Monnier
Cc: Mekeor Melire, Eli Zaretskii, Andrea Corallo, Stefan Kangas,
74903
Monnier> AFAICT his proposal does not add any new command
(help or Monnier> other). What am I missing?
I think the confusion originates in a misunderstanding between my
initial mail and Eli's initial response where Eli said:
Eli> We have "C-h b" and "C-h m" which show the bindings,
albeit not Eli> by keymap.
Most further responses seem to assume that I want to reimplement
`describe-bindings' (C-h b).
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#74903: [PATCH] Add function to show table of keys when describing keymap variable
2024-12-17 19:00 ` Juri Linkov
@ 2024-12-18 12:04 ` Robert Pluim
2024-12-18 17:28 ` Juri Linkov
0 siblings, 1 reply; 13+ messages in thread
From: Robert Pluim @ 2024-12-18 12:04 UTC (permalink / raw)
To: Juri Linkov
Cc: 74903, Mekeor Melire, Stefan Kangas, Eli Zaretskii,
Andrea Corallo, Stefan Monnier
>>>>> On Tue, 17 Dec 2024 21:00:11 +0200, Juri Linkov <juri@linkov.net> said:
>>> It would be nice if users will be able first to see keymap tables
>>> in the output of `describe-repeat-maps', then click on a map
>>> variable, and see the same keymap table individually.
>>
>> ? I must be misunderstanding, because thatʼs already how
>> `describe-repeat-maps' works.
Juri> I meant that after clicking on the map variable in the heading
Juri> it could show the same keymap.
Thatʼs just narrowing the buffer, no? 😉
Robert
--
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#74903: [PATCH] Add function to show table of keys when describing keymap variable
2024-12-18 12:04 ` Robert Pluim
@ 2024-12-18 17:28 ` Juri Linkov
0 siblings, 0 replies; 13+ messages in thread
From: Juri Linkov @ 2024-12-18 17:28 UTC (permalink / raw)
To: Robert Pluim
Cc: 74903, Mekeor Melire, Stefan Kangas, Eli Zaretskii,
Andrea Corallo, Stefan Monnier
> >>> It would be nice if users will be able first to see keymap tables
> >>> in the output of `describe-repeat-maps', then click on a map
> >>> variable, and see the same keymap table individually.
> >>
> >> ? I must be misunderstanding, because thatʼs already how
> >> `describe-repeat-maps' works.
>
> Juri> I meant that after clicking on the map variable in the heading
> Juri> it could show the same keymap.
>
> Thatʼs just narrowing the buffer, no? 😉
Except that it also shows a docstring and a link to source code.
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2024-12-18 17:28 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-15 23:14 bug#74903: [PATCH] Add function to show table of keys when describing keymap variable Mekeor Melire
2024-12-16 15:57 ` Eli Zaretskii
2024-12-16 17:28 ` Robert Pluim
2024-12-16 18:41 ` Mekeor Melire
2024-12-17 3:03 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-17 7:49 ` Robert Pluim
2024-12-17 7:59 ` Juri Linkov
2024-12-17 8:32 ` Robert Pluim
2024-12-17 19:00 ` Juri Linkov
2024-12-18 12:04 ` Robert Pluim
2024-12-18 17:28 ` Juri Linkov
2024-12-17 2:56 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-18 0:21 ` Mekeor Melire
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.