D.2 Key Binding Conventions
Many special major modes, like Dired, Info, Compilation, and Occur, are designed to handle read-only text that contains hyper-links. Such a major mode should redefine
mouse-2
andRET
to follow the links. It should also set up afollow-link
condition, so that the link obeysmouse-1-click-follows-link
. See Clickable Text. See Buttons, for an easy method of implementing such clickable links.Don’t define
C-c letter
as a key in Lisp programs. Sequences consisting ofC-c
and a letter (either upper or lower case) are reserved for users; they are the only sequences reserved for users, so do not block them.Changing all the Emacs major modes to respect this convention was a lot of work; abandoning this convention would make that work go to waste, and inconvenience users. Please comply with it.
Function keys
F5
throughF9
without modifier keys are also reserved for users to define.Sequences consisting of
C-c
followed by a control character or a digit are reserved for major modes.Sequences consisting of
C-c
followed by{
,}
,<
,>
,:
or;
are also reserved for major modes.Sequences consisting of
C-c
followed by any other ASCII punctuation or symbol character are allocated for minor modes. Using them in a major mode is not absolutely prohibited, but if you do that, the major mode binding may be shadowed from time to time by minor modes.Don’t bind
C-h
following any prefix character (includingC-c
). If you don’t bindC-h
, it is automatically available as a help character for listing the subcommands of the prefix character.Don’t bind a key sequence ending in
ESC
except following anotherESC
. (That is, it is OK to bind a sequence ending inESC ESC
.)The reason for this rule is that a non-prefix binding for
ESC
in any context prevents recognition of escape sequences as function keys in that context.Similarly, don’t bind a key sequence ending in
C-g
, since that is commonly used to cancel a key sequence.Anything that acts like a temporary mode or state that the user can enter and leave should define
ESC ESC
orESC ESC ESC
as a way to escape.For a state that accepts ordinary Emacs commands, or more generally any kind of state in which
ESC
followed by a function key or arrow key is potentially meaningful, then you must not defineESC ESC
, since that would preclude recognizing an escape sequence afterESC
. In these states, you should defineESC ESC ESC
as the way to escape. Otherwise, defineESC ESC
instead.