1 |
@c -*-texinfo-*- |
@c -*-texinfo-*- |
2 |
@c This is part of the GNU Emacs Lisp Reference Manual. |
@c This is part of the GNU Emacs Lisp Reference Manual. |
3 |
@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1998, 1999, 2000 |
@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1998, 1999, 2000 |
4 |
@c Free Software Foundation, Inc. |
@c Free Software Foundation, Inc. |
5 |
@c See the file elisp.texi for copying conditions. |
@c See the file elisp.texi for copying conditions. |
6 |
@setfilename ../info/keymaps |
@setfilename ../info/keymaps |
7 |
@node Keymaps, Modes, Command Loop, Top |
@node Keymaps, Modes, Command Loop, Top |
103 |
|
|
104 |
A keymap is a list whose @sc{car} is the symbol @code{keymap}. The |
A keymap is a list whose @sc{car} is the symbol @code{keymap}. The |
105 |
remaining elements of the list define the key bindings of the keymap. |
remaining elements of the list define the key bindings of the keymap. |
106 |
Use the function @code{keymapp} (see below) to test whether an object is |
A symbol whose function definition is a keymap is also a keymap. Use |
107 |
a keymap. |
the function @code{keymapp} (see below) to test whether an object is a |
108 |
|
keymap. |
109 |
|
|
110 |
Several kinds of elements may appear in a keymap, after the symbol |
Several kinds of elements may appear in a keymap, after the symbol |
111 |
@code{keymap} that begins it: |
@code{keymap} that begins it: |
175 |
@example |
@example |
176 |
@group |
@group |
177 |
lisp-mode-map |
lisp-mode-map |
178 |
@result{} |
@result{} |
179 |
@end group |
@end group |
180 |
@group |
@group |
181 |
(keymap |
(keymap |
182 |
;; @key{TAB} |
;; @key{TAB} |
183 |
(9 . lisp-indent-line) |
(9 . lisp-indent-line) |
184 |
@end group |
@end group |
185 |
@group |
@group |
186 |
;; @key{DEL} |
;; @key{DEL} |
187 |
(127 . backward-delete-char-untabify) |
(127 . backward-delete-char-untabify) |
188 |
@end group |
@end group |
189 |
@group |
@group |
190 |
(3 keymap |
(3 keymap |
191 |
;; @kbd{C-c C-l} |
;; @kbd{C-c C-l} |
192 |
(12 . run-lisp)) |
(12 . run-lisp)) |
193 |
@end group |
@end group |
194 |
@group |
@group |
195 |
(27 keymap |
(27 keymap |
196 |
;; @r{@kbd{M-C-q}, treated as @kbd{@key{ESC} C-q}} |
;; @r{@kbd{M-C-q}, treated as @kbd{@key{ESC} C-q}} |
197 |
(17 . indent-sexp) |
(17 . indent-sexp) |
198 |
;; @r{@kbd{M-C-x}, treated as @kbd{@key{ESC} C-x}} |
;; @r{@kbd{M-C-x}, treated as @kbd{@key{ESC} C-x}} |
199 |
(24 . lisp-send-defun))) |
(24 . lisp-send-defun))) |
200 |
@end group |
@end group |
201 |
@end example |
@end example |
202 |
|
|
203 |
@defun keymapp object |
@defun keymapp object |
204 |
This function returns @code{t} if @var{object} is a keymap, @code{nil} |
This function returns @code{t} if @var{object} is a keymap, @code{nil} |
205 |
otherwise. More precisely, this function tests for a list whose |
otherwise. More precisely, this function tests for a list whose |
206 |
@sc{car} is @code{keymap}. |
@sc{car} is @code{keymap}, or for a symbol whose function definition |
207 |
|
satisfies @code{keymapp}. |
208 |
|
|
209 |
@example |
@example |
210 |
@group |
@group |
212 |
@result{} t |
@result{} t |
213 |
@end group |
@end group |
214 |
@group |
@group |
215 |
|
(fset 'foo '(keymap)) |
216 |
|
(keymapp 'foo) |
217 |
|
@result{} t |
218 |
|
@end group |
219 |
|
@group |
220 |
(keymapp (current-global-map)) |
(keymapp (current-global-map)) |
221 |
@result{} t |
@result{} t |
222 |
@end group |
@end group |
280 |
@end group |
@end group |
281 |
@group |
@group |
282 |
;; @r{(This implements meta characters.)} |
;; @r{(This implements meta characters.)} |
283 |
(27 keymap |
(27 keymap |
284 |
(83 . center-paragraph) |
(83 . center-paragraph) |
285 |
(115 . center-line)) |
(115 . center-line)) |
286 |
(9 . tab-to-tab-stop)) |
(9 . tab-to-tab-stop)) |
529 |
when the minor mode is enabled. |
when the minor mode is enabled. |
530 |
|
|
531 |
The variable @code{overriding-local-map}, if non-@code{nil}, specifies |
The variable @code{overriding-local-map}, if non-@code{nil}, specifies |
532 |
another local keymap that overrides the buffer's local map and all the |
another local keymap that overrides the buffer's local map and all the |
533 |
minor mode keymaps. |
minor mode keymaps. |
534 |
|
|
535 |
All the active keymaps are used together to determine what command to |
All the active keymaps are used together to determine what command to |
584 |
@example |
@example |
585 |
@group |
@group |
586 |
(current-global-map) |
(current-global-map) |
587 |
@result{} (keymap [set-mark-command beginning-of-line @dots{} |
@result{} (keymap [set-mark-command beginning-of-line @dots{} |
588 |
delete-backward-char]) |
delete-backward-char]) |
589 |
@end group |
@end group |
590 |
@end example |
@end example |
600 |
@example |
@example |
601 |
@group |
@group |
602 |
(current-local-map) |
(current-local-map) |
603 |
@result{} (keymap |
@result{} (keymap |
604 |
(10 . eval-print-last-sexp) |
(10 . eval-print-last-sexp) |
605 |
(9 . lisp-indent-line) |
(9 . lisp-indent-line) |
606 |
(127 . backward-delete-char-untabify) |
(127 . backward-delete-char-untabify) |
607 |
@end group |
@end group |
608 |
@group |
@group |
609 |
(27 keymap |
(27 keymap |
610 |
(24 . eval-defun) |
(24 . eval-defun) |
611 |
(17 . indent-sexp))) |
(17 . indent-sexp))) |
612 |
@end group |
@end group |
613 |
@end example |
@end example |
1004 |
@end group |
@end group |
1005 |
@group |
@group |
1006 |
(setq meta-prefix-char 24) |
(setq meta-prefix-char 24) |
1007 |
@result{} 24 |
@result{} 24 |
1008 |
@end group |
@end group |
1009 |
@group |
@group |
1010 |
(key-binding "\M-b") |
(key-binding "\M-b") |
1070 |
meaningful. (For a list of meaningful types, see @ref{Key Lookup}.) |
meaningful. (For a list of meaningful types, see @ref{Key Lookup}.) |
1071 |
The value returned by @code{define-key} is @var{binding}. |
The value returned by @code{define-key} is @var{binding}. |
1072 |
|
|
1073 |
|
If @var{key} is @code{[t]}, this sets the default binding in |
1074 |
|
@var{keymap}. When an event has no binding of its own, the Emacs |
1075 |
|
command loop uses the keymap's default binding, if there is one. |
1076 |
|
|
1077 |
@cindex invalid prefix key error |
@cindex invalid prefix key error |
1078 |
@cindex key sequence error |
@cindex key sequence error |
1079 |
Every prefix of @var{key} must be a prefix key (i.e., bound to a keymap) |
Every prefix of @var{key} must be a prefix key (i.e., bound to a keymap) |
1083 |
|
|
1084 |
If there was previously no binding for @var{key} in @var{keymap}, the |
If there was previously no binding for @var{key} in @var{keymap}, the |
1085 |
new binding is added at the beginning of @var{keymap}. The order of |
new binding is added at the beginning of @var{keymap}. The order of |
1086 |
bindings in a keymap makes no difference in most cases, but it does |
bindings in a keymap makes no difference for keyboard input, but it |
1087 |
matter for menu keymaps (@pxref{Menu Keymaps}). |
does matter for menu keymaps (@pxref{Menu Keymaps}). |
1088 |
@end defun |
@end defun |
1089 |
|
|
1090 |
Here is an example that creates a sparse keymap and makes a number of |
Here is an example that creates a sparse keymap and makes a number of |
1111 |
@end group |
@end group |
1112 |
@group |
@group |
1113 |
map |
map |
1114 |
@result{} (keymap |
@result{} (keymap |
1115 |
(24 keymap ; @kbd{C-x} |
(24 keymap ; @kbd{C-x} |
1116 |
(102 . forward-word)) ; @kbd{f} |
(102 . forward-word)) ; @kbd{f} |
1117 |
(6 . forward-char)) ; @kbd{C-f} |
(6 . forward-char)) ; @kbd{C-f} |
1121 |
;; @r{Bind @kbd{C-p} to the @code{ctl-x-map}.} |
;; @r{Bind @kbd{C-p} to the @code{ctl-x-map}.} |
1122 |
(define-key map "\C-p" ctl-x-map) |
(define-key map "\C-p" ctl-x-map) |
1123 |
;; @code{ctl-x-map} |
;; @code{ctl-x-map} |
1124 |
@result{} [nil @dots{} find-file @dots{} backward-kill-sentence] |
@result{} [nil @dots{} find-file @dots{} backward-kill-sentence] |
1125 |
@end group |
@end group |
1126 |
|
|
1127 |
@group |
@group |
1133 |
map |
map |
1134 |
@result{} (keymap ; @r{Note @code{foo} in @code{ctl-x-map}.} |
@result{} (keymap ; @r{Note @code{foo} in @code{ctl-x-map}.} |
1135 |
(16 keymap [nil @dots{} foo @dots{} backward-kill-sentence]) |
(16 keymap [nil @dots{} foo @dots{} backward-kill-sentence]) |
1136 |
(24 keymap |
(24 keymap |
1137 |
(102 . forward-word)) |
(102 . forward-word)) |
1138 |
(6 . forward-char)) |
(6 . forward-char)) |
1139 |
@end group |
@end group |
1157 |
|
|
1158 |
@smallexample |
@smallexample |
1159 |
@group |
@group |
1160 |
(substitute-key-definition |
(substitute-key-definition |
1161 |
'find-file 'find-file-read-only (current-global-map)) |
'find-file 'find-file-read-only (current-global-map)) |
1162 |
@end group |
@end group |
1163 |
@end smallexample |
@end smallexample |
1190 |
|
|
1191 |
@smallexample |
@smallexample |
1192 |
@group |
@group |
1193 |
(setq map '(keymap |
(setq map '(keymap |
1194 |
(?1 . olddef-1) |
(?1 . olddef-1) |
1195 |
(?2 . olddef-2) |
(?2 . olddef-2) |
1196 |
(?3 . olddef-1))) |
(?3 . olddef-1))) |
1197 |
@result{} (keymap (49 . olddef-1) (50 . olddef-2) (51 . olddef-1)) |
@result{} (keymap (49 . olddef-1) (50 . olddef-2) (51 . olddef-1)) |
1198 |
@end group |
@end group |
1220 |
@code{negative-argument}. Otherwise it makes them undefined like the |
@code{negative-argument}. Otherwise it makes them undefined like the |
1221 |
rest of the printing characters. |
rest of the printing characters. |
1222 |
|
|
1223 |
@cindex yank suppression |
@cindex yank suppression |
1224 |
@cindex @code{quoted-insert} suppression |
@cindex @code{quoted-insert} suppression |
1225 |
The @code{suppress-keymap} function does not make it impossible to |
The @code{suppress-keymap} function does not make it impossible to |
1226 |
modify a buffer, as it does not suppress commands such as @code{yank} |
modify a buffer, as it does not suppress commands such as @code{yank} |
1227 |
and @code{quoted-insert}. To prevent any modification of a buffer, make |
and @code{quoted-insert}. To prevent any modification of a buffer, make |
1423 |
@smallexample |
@smallexample |
1424 |
@group |
@group |
1425 |
(accessible-keymaps (current-local-map)) |
(accessible-keymaps (current-local-map)) |
1426 |
@result{}(("" keymap |
@result{}(("" keymap |
1427 |
(27 keymap ; @r{Note this keymap for @key{ESC} is repeated below.} |
(27 keymap ; @r{Note this keymap for @key{ESC} is repeated below.} |
1428 |
(83 . center-paragraph) |
(83 . center-paragraph) |
1429 |
(115 . center-line)) |
(115 . center-line)) |
1431 |
@end group |
@end group |
1432 |
|
|
1433 |
@group |
@group |
1434 |
("^[" keymap |
("^[" keymap |
1435 |
(83 . center-paragraph) |
(83 . center-paragraph) |
1436 |
(115 . foo))) |
(115 . foo))) |
1437 |
@end group |
@end group |
1438 |
@end smallexample |
@end smallexample |
1447 |
@smallexample |
@smallexample |
1448 |
@group |
@group |
1449 |
(accessible-keymaps (current-global-map)) |
(accessible-keymaps (current-global-map)) |
1450 |
@result{} (("" keymap [set-mark-command beginning-of-line @dots{} |
@result{} (("" keymap [set-mark-command beginning-of-line @dots{} |
1451 |
delete-backward-char]) |
delete-backward-char]) |
1452 |
@end group |
@end group |
1453 |
@group |
@group |
2240 |
To define items in some local map, bind @code{`tool-bar-map} with |
To define items in some local map, bind @code{`tool-bar-map} with |
2241 |
@code{let} around calls of this function: |
@code{let} around calls of this function: |
2242 |
@example |
@example |
2243 |
(defvar foo-tool-bar-map |
(defvar foo-tool-bar-map |
2244 |
(let ((tool-bar-map (make-sparse-keymap))) |
(let ((tool-bar-map (make-sparse-keymap))) |
2245 |
(tool-bar-add-item @dots{}) |
(tool-bar-add-item @dots{}) |
2246 |
@dots{} |
@dots{} |