* Get key-binding for a command and print key binding in kbd syntax
@ 2023-02-09 8:33 Tassilo Horn
2023-02-09 10:28 ` Robert Pluim
0 siblings, 1 reply; 10+ messages in thread
From: Tassilo Horn @ 2023-02-09 8:33 UTC (permalink / raw)
To: help-gnu-emacs
Hi all,
someone asked on another list if mu4e could replace its main buffer's
content, parts of which looks like
Maildirs
* [ji] /Fastmail/GNU 0/1244
* [ja] /Fastmail/Archive 0/8976
* [jb] /Fastmail/Drafts 0/24
where j is the key bound to the mu4e-search-maildir command by default,
with the correct key bound in its mode's map. I.e., right now, j is
hard-coded and conforms to the standard binding but is wrong when you
define-key it otherwise.
So the question is: how do you get the key(s) for a command?
`where-is-internal' looks promising giving ([106] [menu-bar mu4e Search\
maildir]) where 106 is the char ?j. If that's the right way, is numeric
vector vs. vector of symbols the right way to distinguish key bindings
from menu items?
And the other question: how to I convert such a key binding vector to a
string in kbd syntax for display purposes?
Thanks,
Tassilo
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Get key-binding for a command and print key binding in kbd syntax
2023-02-09 8:33 Get key-binding for a command and print key binding in kbd syntax Tassilo Horn
@ 2023-02-09 10:28 ` Robert Pluim
2023-02-09 10:50 ` Tassilo Horn
0 siblings, 1 reply; 10+ messages in thread
From: Robert Pluim @ 2023-02-09 10:28 UTC (permalink / raw)
To: Tassilo Horn; +Cc: help-gnu-emacs
>>>>> On Thu, 09 Feb 2023 09:33:16 +0100, Tassilo Horn <tsdh@gnu.org> said:
Tassilo> Hi all,
Tassilo> someone asked on another list if mu4e could replace its main buffer's
Tassilo> content, parts of which looks like
Tassilo> Maildirs
Tassilo> * [ji] /Fastmail/GNU 0/1244
Tassilo> * [ja] /Fastmail/Archive 0/8976
Tassilo> * [jb] /Fastmail/Drafts 0/24
Tassilo> where j is the key bound to the mu4e-search-maildir command by default,
Tassilo> with the correct key bound in its mode's map. I.e., right now, j is
Tassilo> hard-coded and conforms to the standard binding but is wrong when you
Tassilo> define-key it otherwise.
Tassilo> So the question is: how do you get the key(s) for a command?
Tassilo> `where-is-internal' looks promising giving ([106] [menu-bar mu4e Search\
Tassilo> maildir]) where 106 is the char ?j. If that's the right way, is numeric
Tassilo> vector vs. vector of symbols the right way to distinguish key bindings
Tassilo> from menu items?
`substitute-command-keys'
Tassilo> And the other question: how to I convert such a key binding vector to a
Tassilo> string in kbd syntax for display purposes?
`key-description'
Robert
--
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Get key-binding for a command and print key binding in kbd syntax
2023-02-09 10:28 ` Robert Pluim
@ 2023-02-09 10:50 ` Tassilo Horn
2023-02-09 11:09 ` Tassilo Horn
0 siblings, 1 reply; 10+ messages in thread
From: Tassilo Horn @ 2023-02-09 10:50 UTC (permalink / raw)
To: Robert Pluim; +Cc: help-gnu-emacs
Robert Pluim <rpluim@gmail.com> writes:
Hi Robert,
> Tassilo> So the question is: how do you get the key(s) for a
> Tassilo> command? `where-is-internal' looks promising giving
> Tassilo> ([106] [menu-bar mu4e Search\ maildir]) where 106 is the
> Tassilo> char ?j. If that's the right way, is numeric vector
> Tassilo> vs. vector of symbols the right way to distinguish key
> Tassilo> bindings from menu items?
>
> `substitute-command-keys'
Oh, yeah, I've forgotten about that one. I think that will do
everything I need in one go.
Thanks a lot!
Bye,
Tassilo
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Get key-binding for a command and print key binding in kbd syntax
2023-02-09 10:50 ` Tassilo Horn
@ 2023-02-09 11:09 ` Tassilo Horn
2023-02-09 11:44 ` Robert Pluim
0 siblings, 1 reply; 10+ messages in thread
From: Tassilo Horn @ 2023-02-09 11:09 UTC (permalink / raw)
Cc: Robert Pluim, help-gnu-emacs
Tassilo Horn <tsdh@gnu.org> writes:
>> Tassilo> So the question is: how do you get the key(s) for a
>> Tassilo> command? `where-is-internal' looks promising giving
>> Tassilo> ([106] [menu-bar mu4e Search\ maildir]) where 106 is the
>> Tassilo> char ?j. If that's the right way, is numeric vector
>> Tassilo> vs. vector of symbols the right way to distinguish key
>> Tassilo> bindings from menu items?
>>
>> `substitute-command-keys'
>
> Oh, yeah, I've forgotten about that one. I think that will do
> everything I need in one go.
Oh, not quite. Right now, there's for example a "[C]ompose a new mail"
text where the C also has a keymap property which would invoke the
respective command on mouse-2 and RET. `substitute-command-keys'
doesn't allow doing that out of the box. So one would need to iterate
over occurrences of the help-key-binding face afterwards, translate back
to the command and add a keymap property.
How do I lookup a command for the printed key description?
(keymap-lookup nil "C-c C-c")
;=> message-send-and-exit
works but is too new to be used for packages supporting older emacsen.
Is
(lookup-key (current-local-map) (kbd "C-c C-c"))
the right incarnation?
Bye,
Tassilo
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Get key-binding for a command and print key binding in kbd syntax
2023-02-09 11:09 ` Tassilo Horn
@ 2023-02-09 11:44 ` Robert Pluim
2023-02-09 11:58 ` Tassilo Horn
0 siblings, 1 reply; 10+ messages in thread
From: Robert Pluim @ 2023-02-09 11:44 UTC (permalink / raw)
To: help-gnu-emacs
>>>>> On Thu, 09 Feb 2023 12:09:14 +0100, Tassilo Horn <tsdh@gnu.org> said:
Tassilo> Oh, not quite. Right now, there's for example a "[C]ompose a new mail"
Tassilo> text where the C also has a keymap property which would invoke the
Tassilo> respective command on mouse-2 and RET. `substitute-command-keys'
Tassilo> doesn't allow doing that out of the box. So one would need to iterate
Tassilo> over occurrences of the help-key-binding face afterwards, translate back
Tassilo> to the command and add a keymap property.
Tassilo> How do I lookup a command for the printed key description?
Tassilo> (keymap-lookup nil "C-c C-c")
Tassilo> ;=> message-send-and-exit
Tassilo> works but is too new to be used for packages supporting
Tassilo> older emacsen.
I think `keymap-lookup' will be in `compat' when emacs-29 comes out
Tassilo> Is
Tassilo> (lookup-key (current-local-map) (kbd "C-c C-c"))
Tassilo> the right incarnation?
For a 'keymap property? Probably
(get-char-property (point) 'keymap)
is needed to get the right map. `current-local-map' is for the buffer.
Robert
--
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Get key-binding for a command and print key binding in kbd syntax
2023-02-09 11:44 ` Robert Pluim
@ 2023-02-09 11:58 ` Tassilo Horn
2023-02-09 12:20 ` Robert Pluim
0 siblings, 1 reply; 10+ messages in thread
From: Tassilo Horn @ 2023-02-09 11:58 UTC (permalink / raw)
To: help-gnu-emacs
Robert Pluim <rpluim@gmail.com> writes:
> Tassilo> How do I lookup a command for the printed key description?
>
> Tassilo> (keymap-lookup nil "C-c C-c")
> Tassilo> ;=> message-send-and-exit
>
> Tassilo> works but is too new to be used for packages supporting
> Tassilo> older emacsen.
>
> I think `keymap-lookup' will be in `compat' when emacs-29 comes out
AFAIK, mu4e doesn't use the compat library (yet) since you cannot
install it from ELPA or some other archive anyhow given that it's
tightly coupled to mu mail indexer, i.e., the C++ and the elisp parts
must be compatible.
> Tassilo> Is
>
> Tassilo> (lookup-key (current-local-map) (kbd "C-c C-c"))
>
> Tassilo> the right incarnation?
>
> For a 'keymap property? Probably
>
> (get-char-property (point) 'keymap)
>
> is needed to get the right map. `current-local-map' is for the buffer.
No, no. I've meant that with substitute-command-keys I have the correct
key-descriptions in the buffer with help-key-binding face. However, I
would also like to have them clickable so I think I need to "parse" the
buffer and add keymap properties to the text having the help-key-binding
face.
So for example, there is the text "[j]ump to some maildir" where the j
is a key-description (recognizable by its help-key-binding face), I need
to translate back the j to the command mu4e-search-maildir in order to
add a keymap where RET and mouse-2 are bound to that command.
Bye,
Tassilo
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Get key-binding for a command and print key binding in kbd syntax
2023-02-09 11:58 ` Tassilo Horn
@ 2023-02-09 12:20 ` Robert Pluim
2023-02-09 12:22 ` Tassilo Horn
0 siblings, 1 reply; 10+ messages in thread
From: Robert Pluim @ 2023-02-09 12:20 UTC (permalink / raw)
To: Tassilo Horn; +Cc: help-gnu-emacs
>>>>> On Thu, 09 Feb 2023 12:58:37 +0100, Tassilo Horn <tsdh@gnu.org> said:
Tassilo> No, no. I've meant that with substitute-command-keys I have the correct
Tassilo> key-descriptions in the buffer with help-key-binding face. However, I
Tassilo> would also like to have them clickable so I think I need to "parse" the
Tassilo> buffer and add keymap properties to the text having the help-key-binding
Tassilo> face.
Tassilo> So for example, there is the text "[j]ump to some maildir" where the j
Tassilo> is a key-description (recognizable by its help-key-binding face), I need
Tassilo> to translate back the j to the command mu4e-search-maildir in order to
Tassilo> add a keymap where RET and mouse-2 are bound to that command.
Iʼm not sure Iʼm getting it.
- You insert (substitute-command-keys "\\[mu4e-search-maildir]")
- At that point you can add a 'keymap property to the text youʼve just
inserted, binding RET and mouse-2 to #'mu4e-search-maildir
Why do you need to lookup "j" in the local map at all?
(as an aside, clickable stuff is probably better done with buttons
than by inventing your own thing).
Robert
--
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Get key-binding for a command and print key binding in kbd syntax
2023-02-09 12:20 ` Robert Pluim
@ 2023-02-09 12:22 ` Tassilo Horn
2023-02-09 13:46 ` Robert Pluim
0 siblings, 1 reply; 10+ messages in thread
From: Tassilo Horn @ 2023-02-09 12:22 UTC (permalink / raw)
To: Robert Pluim; +Cc: help-gnu-emacs
Robert Pluim <rpluim@gmail.com> writes:
> Iʼm not sure Iʼm getting it.
>
> - You insert (substitute-command-keys "\\[mu4e-search-maildir]")
> - At that point you can add a 'keymap property to the text youʼve just
> inserted, binding RET and mouse-2 to #'mu4e-search-maildir
Ah, yes, you are right. I imagined I would compute a large string with
different \[foo] and \[bar] occurrences and then pass the whole thing
through substitute-command-keys. If I do it in small parts, it
obviously becomes much easier. Sometimes I don't see the forest for the
trees. :-)
> (as an aside, clickable stuff is probably better done with buttons
> than by inventing your own thing).
Well, maybe, but if possible I'd rather keep it the way it already is
UI-wise, just make it correct in the presence of non-default bindings.
Thanks again,
Tassilo
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Get key-binding for a command and print key binding in kbd syntax
2023-02-09 12:22 ` Tassilo Horn
@ 2023-02-09 13:46 ` Robert Pluim
2023-02-09 14:10 ` Tassilo Horn
0 siblings, 1 reply; 10+ messages in thread
From: Robert Pluim @ 2023-02-09 13:46 UTC (permalink / raw)
To: Tassilo Horn; +Cc: help-gnu-emacs
>>>>> On Thu, 09 Feb 2023 13:22:21 +0100, Tassilo Horn <tsdh@gnu.org> said:
Tassilo> Robert Pluim <rpluim@gmail.com> writes:
>> Iʼm not sure Iʼm getting it.
>>
>> - You insert (substitute-command-keys "\\[mu4e-search-maildir]")
>> - At that point you can add a 'keymap property to the text youʼve just
>> inserted, binding RET and mouse-2 to #'mu4e-search-maildir
Tassilo> Ah, yes, you are right. I imagined I would compute a large string with
Tassilo> different \[foo] and \[bar] occurrences and then pass the whole thing
Tassilo> through substitute-command-keys. If I do it in small parts, it
Tassilo> obviously becomes much easier. Sometimes I don't see the forest for the
Tassilo> trees. :-)
Breaking things into small parts is the essence of computer
programming :-)
Robert
--
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Get key-binding for a command and print key binding in kbd syntax
2023-02-09 13:46 ` Robert Pluim
@ 2023-02-09 14:10 ` Tassilo Horn
0 siblings, 0 replies; 10+ messages in thread
From: Tassilo Horn @ 2023-02-09 14:10 UTC (permalink / raw)
To: Robert Pluim; +Cc: help-gnu-emacs
Robert Pluim <rpluim@gmail.com> writes:
> Tassilo> Ah, yes, you are right. I imagined I would compute a
> Tassilo> large string with different \[foo] and \[bar] occurrences
> Tassilo> and then pass the whole thing through
> Tassilo> substitute-command-keys. If I do it in small parts, it
> Tassilo> obviously becomes much easier. Sometimes I don't see the
> Tassilo> forest for the trees. :-)
>
> Breaking things into small parts is the essence of computer
> programming :-)
Yes, generally in small *things*, not necessarily in small *strings*
although the latter fits the bill here. :-)
Bye,
Tassilo
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-02-09 14:10 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-09 8:33 Get key-binding for a command and print key binding in kbd syntax Tassilo Horn
2023-02-09 10:28 ` Robert Pluim
2023-02-09 10:50 ` Tassilo Horn
2023-02-09 11:09 ` Tassilo Horn
2023-02-09 11:44 ` Robert Pluim
2023-02-09 11:58 ` Tassilo Horn
2023-02-09 12:20 ` Robert Pluim
2023-02-09 12:22 ` Tassilo Horn
2023-02-09 13:46 ` Robert Pluim
2023-02-09 14:10 ` Tassilo Horn
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.