aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman2006-05-25 17:03:30 +0000
committerRichard M. Stallman2006-05-25 17:03:30 +0000
commitb3540319ff29b94010974ef9572353248a1b9dbc (patch)
tree0f919dd2f405734b9e9f9fdd6cfd67cc42fdb10b
parentf195dc16c47781de49b353caa82aa3f1e6f17c18 (diff)
downloademacs-b3540319ff29b94010974ef9572353248a1b9dbc.tar.gz
emacs-b3540319ff29b94010974ef9572353248a1b9dbc.zip
(Keymap Basics): New node, split out of Key Sequences.
(Keymaps): Update menu.
-rw-r--r--lispref/keymaps.texi135
1 files changed, 74 insertions, 61 deletions
diff --git a/lispref/keymaps.texi b/lispref/keymaps.texi
index dd6a796805b..ed67a028446 100644
--- a/lispref/keymaps.texi
+++ b/lispref/keymaps.texi
@@ -16,7 +16,8 @@ to look up the next input event; this continues until a command is
16found. The whole process is called @dfn{key lookup}. 16found. The whole process is called @dfn{key lookup}.
17 17
18@menu 18@menu
19* Key Sequences:: What a key sequence looks like as a Lisp object. 19* Key Sequences:: Key sequences as Lisp objects.
20* Keymap Basics:: Basic concepts of keymaps.
20* Format of Keymaps:: What a keymap looks like as a Lisp object. 21* Format of Keymaps:: What a keymap looks like as a Lisp object.
21* Creating Keymaps:: Functions to create and copy keymaps. 22* Creating Keymaps:: Functions to create and copy keymaps.
22* Inheritance and Keymaps:: How one keymap can inherit the bindings 23* Inheritance and Keymaps:: How one keymap can inherit the bindings
@@ -41,22 +42,75 @@ found. The whole process is called @dfn{key lookup}.
41@section Key Sequences 42@section Key Sequences
42@cindex key 43@cindex key
43@cindex keystroke 44@cindex keystroke
45@cindex key sequence
46
47 A @dfn{key sequence}, or @dfn{key} for short, is a sequence of one
48or more input events that form a unit. The Emacs Lisp representation
49for a key sequence is a string or vector. Unless otherwise stated,
50any Emacs Lisp function that accepts a key sequence as an argument can
51handle both representations.
52
53 In the string representation, alphanumeric characters ordinarily
54stand for themselves; for example, @code{"a"} represents @kbd{a} and
55and @code{"2"} represents @kbd{2}. Control character events are
56prefixed by the substring @code{"\C-"}, and meta characters by
57@code{"\M-"}; for example, @code{"\C-x"} represents the key @kbd{C-x}.
58In addition, the @key{TAB}, @key{RET}, @key{ESC}, and @key{DEL} events
59are represented by @code{"\t"}, @code{"\r"}, @code{"\e"}, and
60@code{"\d"} respectively. The string representation of a complete key
61sequence is the concatenation of the string representations of the
62constituent events; thus, @code{"\C-xl"} represents the key sequence
63@kbd{C-x l}.
64
65 Key sequences containing function keys, mouse button events, or
66non-ASCII characters such as @kbd{C-=} or @kbd{H-a} cannot be
67represented as strings; they have to be represented as vectors.
68
69 In the vector representation, each element of the vector represents
70an input event, in its Lisp form. @xref{Input Events}. For example,
71the vector @code{[?\C-x ?l]} represents the key sequence @kbd{C-x l}.
72
73 For examples of key sequences written in string and vector
74representations, @ref{Init Rebinding,,, emacs, The GNU Emacs Manual}.
75
76@defmac kbd keyseq-text
77This macro converts the text @var{keyseq-text} (a string constant)
78into a key sequence (a string or vector constant). The contents of
79@var{keyseq-text} should describe the key sequence using almost the same
80syntax used in this manual. More precisely, it uses the same syntax
81that Edit Macro mode uses for editing keyboard macros (@pxref{Edit
82Keyboard Macro,,, emacs, The GNU Emacs Manual}); you must surround
83function key names with @samp{<@dots{}>}.
84
85@example
86(kbd "C-x") @result{} "\C-x"
87(kbd "C-x C-f") @result{} "\C-x\C-f"
88(kbd "C-x 4 C-f") @result{} "\C-x4\C-f"
89(kbd "X") @result{} "X"
90(kbd "RET") @result{} "\^M"
91(kbd "C-c SPC") @result{} "\C-c@ "
92(kbd "<f1> SPC") @result{} [f1 32]
93(kbd "C-M-<down>") @result{} [C-M-down]
94@end example
95@end defmac
96
97@node Keymap Basics
98@section Keymap Basics
44@cindex key binding 99@cindex key binding
45@cindex binding of a key 100@cindex binding of a key
46@cindex complete key 101@cindex complete key
47@cindex undefined key 102@cindex undefined key
48@cindex key sequence
49 103
50 A keymap determines a binding or definition for a set of @dfn{key 104 A keymap is a Lisp data structure that specifies @dfn{key bindings}
51sequences}, or @dfn{keys} for short. A key sequence is a sequence of 105for various key sequences.
52one or more input events that form a unit.
53 106
54 If a keymap binds a key sequence consisting of a single event, its 107 A single keymap directly specifies definitions for individual
55binding is the definition of that event. The binding of a key 108events. When a key sequence consists of a single event, its binding
56sequence of more than one event is found by an iterative process: the 109in a keymap is the keymap's definition for that event. The binding of
57binding of the first event is found, and must be a keymap; then the 110a longer key sequence is found by an iterative process: first find the
58second event's binding is found in that keymap, and so on until all 111definition of the first event (which must itself be a keymap); then
59the events in the key sequence are used up. 112find the second event's definition in that keymap, and so on until all
113the events in the key sequence have been processed.
60 114
61 If the binding of a key sequence is a keymap, we call the key sequence 115 If the binding of a key sequence is a keymap, we call the key sequence
62a @dfn{prefix key}. Otherwise, we call it a @dfn{complete key} (because 116a @dfn{prefix key}. Otherwise, we call it a @dfn{complete key} (because
@@ -82,56 +136,15 @@ and can change when bindings are changed. However, a one-event sequence
82is always a key sequence, because it does not depend on any prefix keys 136is always a key sequence, because it does not depend on any prefix keys
83for its well-formedness. 137for its well-formedness.
84 138
85 A key sequence can be represented in Emacs Lisp as either a string 139 At any time, several primary keymaps are @dfn{active}---that is, in
86or vector. Unless otherwise stated, any Emacs Lisp function that 140use for finding key bindings. These are the @dfn{global map}, which is
87accepts a key sequence as an argument can handle both representations. 141shared by all buffers; the @dfn{local keymap}, which is usually
88 142associated with a specific major mode; and zero or more @dfn{minor mode
89 In the string representation, alphanumeric characters ordinarily 143keymaps}, which belong to currently enabled minor modes. (Not all minor
90stand for themselves; for example, @code{"a"} represents @key{a} and 144modes have keymaps.) The local keymap bindings shadow (i.e., take
91and @code{"2"} represents @key{2}. Control character events are 145precedence over) the corresponding global bindings. The minor mode
92prefixed by the substring @code{"\C-"}, and meta characters by 146keymaps shadow both local and global keymaps. @xref{Active Keymaps},
93@code{"\M-"}; for example, @code{"\C-x"} represents the key @kbd{C-x}. 147for details.
94In addition, the @kbd{<TAB>}, @kbd{<RET>}, @kbd{<ESC>}, and
95@kbd{<DEL>} events are represented by @code{"\t"}, @code{"\r"},
96@code{"\e"}, and @code{"\d"} respectively. The string representation
97of a complete key sequence is then obtained by concatenating the
98string representations of each constituent event; thus, @code{"\C-xl"}
99represents the key sequence @kbd{C-x l}.
100
101 Key sequences containing function keys, mouse button events, or
102non-ASCII characters such as @kbd{C-=} or @kbd{H-a} cannot be
103represented by strings; they have to be represented by vectors.
104
105 In the vector representation, each element of the vector represents
106a consecutive input element, in its Lisp form. @xref{Input Events}.
107For example, the vector @code{[?\C-x ?l]} represents the key sequence
108@kbd{C-x l}.
109
110 For examples of key sequences written in string and vector
111representations, @ref{Init Rebinding,,, emacs, The GNU Emacs Manual}.
112
113 The @code{kbd} macro provides a convenient way to generate an Emacs
114Lisp key sequence:
115
116@defmac kbd keyseq-text
117This macro converts the text @var{keyseq-text} (a string constant)
118into a key sequence (a string or vector constant). The contents
119of @var{keyseq-text} should describe the key sequence using the syntax
120used in this manual. More precisely, it uses the same syntax that
121Edit Macro mode uses for editing keyboard macros (@pxref{Edit Keyboard
122Macro,,, emacs, The GNU Emacs Manual}).
123
124@example
125(kbd "C-x") @result{} "\C-x"
126(kbd "C-x C-f") @result{} "\C-x\C-f"
127(kbd "C-x 4 C-f") @result{} "\C-x4\C-f"
128(kbd "X") @result{} "X"
129(kbd "RET") @result{} "\^M"
130(kbd "C-c SPC") @result{} "\C-c@ "
131(kbd "<f1> SPC") @result{} [f1 32]
132(kbd "C-M-<down>") @result{} [C-M-down]
133@end example
134@end defmac
135 148
136@node Format of Keymaps 149@node Format of Keymaps
137@section Format of Keymaps 150@section Format of Keymaps