diff options
| author | Richard M. Stallman | 2006-05-25 17:03:30 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2006-05-25 17:03:30 +0000 |
| commit | b3540319ff29b94010974ef9572353248a1b9dbc (patch) | |
| tree | 0f919dd2f405734b9e9f9fdd6cfd67cc42fdb10b | |
| parent | f195dc16c47781de49b353caa82aa3f1e6f17c18 (diff) | |
| download | emacs-b3540319ff29b94010974ef9572353248a1b9dbc.tar.gz emacs-b3540319ff29b94010974ef9572353248a1b9dbc.zip | |
(Keymap Basics): New node, split out of Key Sequences.
(Keymaps): Update menu.
| -rw-r--r-- | lispref/keymaps.texi | 135 |
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 | |||
| 16 | found. The whole process is called @dfn{key lookup}. | 16 | found. 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 | ||
| 48 | or more input events that form a unit. The Emacs Lisp representation | ||
| 49 | for a key sequence is a string or vector. Unless otherwise stated, | ||
| 50 | any Emacs Lisp function that accepts a key sequence as an argument can | ||
| 51 | handle both representations. | ||
| 52 | |||
| 53 | In the string representation, alphanumeric characters ordinarily | ||
| 54 | stand for themselves; for example, @code{"a"} represents @kbd{a} and | ||
| 55 | and @code{"2"} represents @kbd{2}. Control character events are | ||
| 56 | prefixed by the substring @code{"\C-"}, and meta characters by | ||
| 57 | @code{"\M-"}; for example, @code{"\C-x"} represents the key @kbd{C-x}. | ||
| 58 | In addition, the @key{TAB}, @key{RET}, @key{ESC}, and @key{DEL} events | ||
| 59 | are represented by @code{"\t"}, @code{"\r"}, @code{"\e"}, and | ||
| 60 | @code{"\d"} respectively. The string representation of a complete key | ||
| 61 | sequence is the concatenation of the string representations of the | ||
| 62 | constituent 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 | ||
| 66 | non-ASCII characters such as @kbd{C-=} or @kbd{H-a} cannot be | ||
| 67 | represented as strings; they have to be represented as vectors. | ||
| 68 | |||
| 69 | In the vector representation, each element of the vector represents | ||
| 70 | an input event, in its Lisp form. @xref{Input Events}. For example, | ||
| 71 | the 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 | ||
| 74 | representations, @ref{Init Rebinding,,, emacs, The GNU Emacs Manual}. | ||
| 75 | |||
| 76 | @defmac kbd keyseq-text | ||
| 77 | This macro converts the text @var{keyseq-text} (a string constant) | ||
| 78 | into a key sequence (a string or vector constant). The contents of | ||
| 79 | @var{keyseq-text} should describe the key sequence using almost the same | ||
| 80 | syntax used in this manual. More precisely, it uses the same syntax | ||
| 81 | that Edit Macro mode uses for editing keyboard macros (@pxref{Edit | ||
| 82 | Keyboard Macro,,, emacs, The GNU Emacs Manual}); you must surround | ||
| 83 | function 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} |
| 51 | sequences}, or @dfn{keys} for short. A key sequence is a sequence of | 105 | for various key sequences. |
| 52 | one 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 |
| 55 | binding is the definition of that event. The binding of a key | 108 | events. When a key sequence consists of a single event, its binding |
| 56 | sequence of more than one event is found by an iterative process: the | 109 | in a keymap is the keymap's definition for that event. The binding of |
| 57 | binding of the first event is found, and must be a keymap; then the | 110 | a longer key sequence is found by an iterative process: first find the |
| 58 | second event's binding is found in that keymap, and so on until all | 111 | definition of the first event (which must itself be a keymap); then |
| 59 | the events in the key sequence are used up. | 112 | find the second event's definition in that keymap, and so on until all |
| 113 | the 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 |
| 62 | a @dfn{prefix key}. Otherwise, we call it a @dfn{complete key} (because | 116 | a @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 | |||
| 82 | is always a key sequence, because it does not depend on any prefix keys | 136 | is always a key sequence, because it does not depend on any prefix keys |
| 83 | for its well-formedness. | 137 | for 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 |
| 86 | or vector. Unless otherwise stated, any Emacs Lisp function that | 140 | use for finding key bindings. These are the @dfn{global map}, which is |
| 87 | accepts a key sequence as an argument can handle both representations. | 141 | shared by all buffers; the @dfn{local keymap}, which is usually |
| 88 | 142 | associated with a specific major mode; and zero or more @dfn{minor mode | |
| 89 | In the string representation, alphanumeric characters ordinarily | 143 | keymaps}, which belong to currently enabled minor modes. (Not all minor |
| 90 | stand for themselves; for example, @code{"a"} represents @key{a} and | 144 | modes have keymaps.) The local keymap bindings shadow (i.e., take |
| 91 | and @code{"2"} represents @key{2}. Control character events are | 145 | precedence over) the corresponding global bindings. The minor mode |
| 92 | prefixed by the substring @code{"\C-"}, and meta characters by | 146 | keymaps shadow both local and global keymaps. @xref{Active Keymaps}, |
| 93 | @code{"\M-"}; for example, @code{"\C-x"} represents the key @kbd{C-x}. | 147 | for details. |
| 94 | In 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 | ||
| 97 | of a complete key sequence is then obtained by concatenating the | ||
| 98 | string representations of each constituent event; thus, @code{"\C-xl"} | ||
| 99 | represents the key sequence @kbd{C-x l}. | ||
| 100 | |||
| 101 | Key sequences containing function keys, mouse button events, or | ||
| 102 | non-ASCII characters such as @kbd{C-=} or @kbd{H-a} cannot be | ||
| 103 | represented by strings; they have to be represented by vectors. | ||
| 104 | |||
| 105 | In the vector representation, each element of the vector represents | ||
| 106 | a consecutive input element, in its Lisp form. @xref{Input Events}. | ||
| 107 | For 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 | ||
| 111 | representations, @ref{Init Rebinding,,, emacs, The GNU Emacs Manual}. | ||
| 112 | |||
| 113 | The @code{kbd} macro provides a convenient way to generate an Emacs | ||
| 114 | Lisp key sequence: | ||
| 115 | |||
| 116 | @defmac kbd keyseq-text | ||
| 117 | This macro converts the text @var{keyseq-text} (a string constant) | ||
| 118 | into a key sequence (a string or vector constant). The contents | ||
| 119 | of @var{keyseq-text} should describe the key sequence using the syntax | ||
| 120 | used in this manual. More precisely, it uses the same syntax that | ||
| 121 | Edit Macro mode uses for editing keyboard macros (@pxref{Edit Keyboard | ||
| 122 | Macro,,, 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 |