Here are examples of key bindings culled from the Emacs FAQ and emacswiki. Each one seems to use a slightly different notation to identify the keystroke.
> Trying to bind the Lisp comment character ";" to anything can become tricky…
> In my Emacsen (23.4, 24.2.50) this works:
> (global-set-key [67108923] 'comment-indent)
Now that's very intuitive. A better choice (maybe still not totally
obvious to come across, but at least a bit more obvious to understand
when you read it):
(global-set-key [?\C-\;] 'comment-indent)
> The number value can be found by typing, for example in *scratch* buffer,
> C-q C-;. This produces a record in the *Messages* buffer you can use.
If you type C-x C-e twice in a row, with point right after the magical
number, you'll see alternative ways to write this number, one of them
being the one I used above.
When you meet a master swordsman,
show him your sword.
When you meet a man who is not a poet,
do not show him your poem.
– Rinzai, ninth century Zen master
I don't know elisp. Is there an exhaustive list of how to express all of the key chords using vector notation? For instance, I wouldn't have guessed that the 'return' key was denoted by 'return' - I usually see it written RET.
As to my problem with C-; I strongly suspect my binding is getting stomped by C++ mode. So I'd also appreciate some guidelines on what keys to use or avoid.
>>> I think the vector notation is a good choice:
>>> (global-set-key [C-∫] 'backward-sexp) ; A-C-b
>> This likely won't work. You need
>> (global-set-key [?\C-∫] 'backward-sexp) ; A-C-b
>> instead. Yes, it's an annoyance. You have to understand the
>> distinction between keys that emit characters and other keys (that emit
>> symbols).
> Yes, it stopped working.
AFAIK they're all characters (my use of `symbol' was in the Lisp sense
of symbol as opposed to integer, string, cons, float, ...).
> What makes the distinction?
The code that turns GUI events into Lisp events, mostly. The general
rule is that keys which should self-insert get turned into
character-events, while other (special) keys get turned into symbol-events.
>>>> I think the vector notation is a good choice:
>>>> (global-set-key [C-∫] 'backward-sexp) ; A-C-b
>>> This likely won't work. You need
>>> (global-set-key [?\C-∫] 'backward-sexp) ; A-C-b
>>> instead. Yes, it's an annoyance. You have to understand the
>>> distinction between keys that emit characters and other keys (that emit
>>> symbols).
>> Yes, it stopped working.
> When did it work?
I think it was in GNU Emacs 22 based "Carbon Emacs".
> AFAIK they're all characters (my use of `symbol' was in the Lisp sense
> of symbol as opposed to integer, string, cons, float, ...).
>> What makes the distinction?
> The code that turns GUI events into Lisp events, mostly. The general
> rule is that keys which should self-insert get turned into
> character-events, while other (special) keys get turned into symbol-events.
∫ is a self-insert command:
∫ runs the command self-insert-command, which is an interactive
built-in function in `C source code'.
It is bound to many ordinary text characters.
--
Greetings
Pete
The wise man said: "Never argue with an idiot. They bring you down to their level and beat you with experience."
Chap Harrison <chap.harri...@me.com> writes:
> Here are examples of key bindings culled from the Emacs FAQ and
> emacswiki. Each one seems to use a slightly different notation to
> identify the keystroke.
Will above representation work across different platforms or different
invocations of Emacs (terminal/gui/remote). I don't know and I would
like to know.
I can assure you that it will get the job done.
Likewise for local-set-key.
That said, in the long-run, it is better to not meddle with
Emacs-provided bindings.
> I don't know elisp. Is there an exhaustive list of how to express all of the key
> chords using vector notation? For instance, I wouldn't have guessed that the
> 'return' key was denoted by 'return' - I usually see it written RET.
They are different, see the "(emacs)Named ASCII Chars" info node.
> As to my problem with C-; I strongly suspect my binding is getting stomped by
> C++ mode. So I'd also appreciate some guidelines on what keys to use or avoid.
See the "(elisp)Key Binding Conventions" info node.