Last major edit (later minor edits)
Changed:
< * Use [[macro]] `naked' instead of macro `kbd'. The former expects its argument key-sequence description to use naked keys, not clothed in angle brackets. E.g., ##(naked "C-M-delete")## has the same effect as ##(kbd "C-M-<delete>")##.
to
> * Use [[macro]] `naked' instead of macro `kbd'. The former accepts its argument key-sequence description whether it uses angle bracket or naked key notation. E.g., ##(naked "C-M-delete")## has the same effect as ##(naked "C-M-<delete>")##, which is the same as the effect of ##(kbd "C-M-<delete>")##.
Changed:
< But you can also have it both ways if or when you might need to: All of these accept an optional argument ##ANGLES## which, if non-`nil', returns the behavior to the brain-dead vanilla one, expecting function keys to be fully clothed in angle brackets. Example:
< ##(naked "C-M-<delete>" t)##
to
> All of these also accept an optional argument ##ANGLES## which, if non-`nil', returns the behavior to the brain-dead vanilla one, expecting function keys to be fully clothed in angle brackets. Example: ##(naked "C-M-<delete>" t)##.
> In fact, when you use non-`nil' argument ##ANGLES## they even respect the vanilla behavior when it is bugged -- E.g. [[http://debbugs.gnu.org/cgi/bugreport.cgi?bug=12535|bug #12535]]. For an argument of "##M-<TAB>##" they return ##[M-TAB]## instead of [134217737] (which is what `kbd' returns for argument "M-TAB").
Changed:
< Thx. Feel free to follow with anything else (e.g., your functions). -- DrewAdams
to
> Thx. Feel free to follow up with anything else (e.g., your functions). -- DrewAdams
This page is about library NaKeD, naked.el, which provides for no-angles key descriptions. It lets you use key-sequence descriptions that do not bother with angle brackets: `<’ and `>’.
Prior to Emacs 21, vanilla GnuEmacs did not bother with angle brackets either, but someone around the turn of the century had the bright idea that Emacs could not do without them. So instead of the ‘delete’ key we now have the `<delete>’ key. And instead of ‘C-x M-delete’ we now have `C-x M-<delete>’. On n’arrete pas le progres !
If you think that’s silly, well, now there are two of us…
All I can think of is that some misguided soul forgot that we already use spaces to separate keys in a key-sequence description (we use ‘SPC’ to indicate the SPACE key). So we don’t need no stinkin’ brackets to separate keys. Perhaps someone thought we could not distinguish ‘C-d elete’ from ‘C-delete’ (the former being the two-key sequence ‘C-d’ followed by the yet-to-be-defined function key ‘elete’).
Well, we can distinguish them, and no, we do not need angle brackets, because we already have spaces to separate keys in a sequence.
To be fair, it is true that sometimes people have taken the shortcut when writing about user input of writing, e.g., ‘M-x forward-char RET’ instead of writing ‘M-x f o r w a r d - c h a r’. And if you write ‘forward’ that way to stand for an input sequence of seven chars, then you cannot also expect ‘forward’ to stand for a function key named “forward”, can you?
Well, yes you can, if the context makes things clear enough. And I for one (maybe the only one), find `C-M-<insert>’ butt-ugly (likewise `<C-M-insert>’) – and, more importantly, insulting to Occam.
So go ahead and go NaKeD – shed your angles.
Here’s what you need. It won’t completely purge Emacs from insulting you with the occasional pair of angle brackets, but it at least lets you DTRT in code you write:
‘naked-key-description’ instead of ‘key-description’. The former outputs naked key descriptions: no angle brackets around function keys. E.g., if KEY is the sequence of events produced by holding the Shift key while hitting the Insert key, then (naked-key-description KEY) returns "S-insert" (and not "S-<insert>"). (Internally, this sequence of events is the vector [S-insert].)‘naked’ instead of ‘kbd’ (which is a function starting with Emacs 24.3 and a macro before then). The former accepts its argument key-sequence description whether it uses angle bracket or naked key notation. E.g., (naked "C-M-delete") has the same effect as (naked "C-M-<delete>"), which is the same as the effect of (kbd "C-M-<delete>").‘naked-read-kbd-macro’ instead of ‘read-kbd-macro’.‘naked-edmacro-parse-keys’ instead of ‘edmacro-parse-keys’ (if you happen to use that lower-level function).All of these also accept an optional argument ANGLES which, if non-‘nil’, returns the behavior to the brain-dead vanilla one, expecting function keys to be fully clothed in angle brackets. Example: (naked "C-M-<delete>" t).
In fact, when you use non-‘nil’ argument ANGLES they even respect the vanilla behavior when it is bugged – E.g. bug #12535. For an argument of “M-<TAB>” they return [M-TAB] instead of [134217737] (which is what ‘kbd’ returns for argument “M-TAB”).
Enjoy!
I will contact you by mail once I have looked into this a bit more. – JonasBernoulli
Please try the latest. I uploaded a fix for the ‘M-TAB’ case, which was indeed a bug. The code was not handling ‘M-TAB’ differently from ‘M-tab’. This is fixed in naked.el, and I submitted vanilla Emacs bug #12535 about this, with a patch. I also made ‘naked’ handle angle-bracketed key descriptions even without non-‘nil’ arg ANGLES. In that case, #12535 is fixed, but I left it unfixed for the non-‘nil’ ANGLES case, to be consistent with vanilla Emacs.
Thx. Feel free to follow up with anything else (e.g., your functions). – DrewAdams