-
Notifications
You must be signed in to change notification settings - Fork 87
custom string replacement: ambiguous example in README #338
Comments
I got stuck in a very similar place as you, and ultimately found the explanation here. I too wonder if the documentation could be amended to show an example where a description is provided and a key is bound to a non-trivial keymap. Suppose for example I have already constructed a keymap, and it is referred to by the symbol some-prefix-map. Then, if I understand correctly, the examples could read
and
|
At the same time, I still can't quite wrap my head around how this is working on a deep level. My understanding is that the correct usage is to pass a |
The elisp manual is not so clear about define-key, it only says
If it was so, as you say, we should find the cons under the "anything else" category, and it does not fit there. But if you look at the docstring of define-key, in the description of
We just use that and so for DEFN we have the choice between a command, a string treated as a keyboard macro, a keymap, a symbol which stands for its function definition. |
A keymap is a list with the symbol You also have to pay attention to what the Some examples might help This works, because the (define-key parent-map "k" '(keymap)) This doesn't work, because the (setq testmap '(keymap))
(define-key parent-map "k" 'testmap) This works again. Note the quotation. (setq testmap '(keymap))
(define-key parent-map "k" testmap) This doesn't work, because (define-key parent-map "k" '(testmap)) Now, adding the (define-key parent-map "k" '("name" . (keymap))) This will not (define-key parent-map "k" '("name" . '(keymap))) This will not work, because (setq testmap '(keymap))
(define-key parent-map "k" '("name" . testmap)) This will work again, because (setq testmap '(keymap))
(define-key parent-map "k" (cons "name" testmap)) |
Thank you Justin, the added example in 1692a1e will help to understand the syntax.
What is the meaning of
If it designates any keymap the parentheses are not relevant because the keymap is yet a cons, so the parentheses are included in the keymap.
The use of angle brackets to designate an arbitrary parameter is a posix convention, with an alternative of words separated by underlines, usually in italic. But the main thing is by writing This may be quite pernickety, and the added example should dispel any confusion |
In the examples that I gave in my initial post, I omitted
Such an example might be added in the README. |
I could not achieve custom string replacement as shown in the custom string replacement section
Consider the following keymap:
With this test which key gives for the top level "C-:" : "C-: -> +prefix", and for "C-:" itself
"a -> lambda".
Lets try to improve that:
Now on "C-:" which-key display "a -> a key".
Now for the keymap, if I follow the custom string replacement section I try:
I get when entering "C-:"
(wrong-type-argument commandp (testmap))
of course if I replace the cdr by testmap it is also wrong because testmap is a variable
whose value is not a command, but a keymap.
I have few ways of solving this either one of the following works as expected:
But the documentation seems as least ambiguous on what is meant by
(keymap)
The text was updated successfully, but these errors were encountered: