aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman2003-08-13 17:21:57 +0000
committerRichard M. Stallman2003-08-13 17:21:57 +0000
commit229644e7b176d89d4f1069d0821daa8ac798c6ac (patch)
treeb3e6e9158a0407d546e37730e99a61caaab32852
parent041b0e7bd7df98929d9bf3e035bc3a1da0916a30 (diff)
downloademacs-229644e7b176d89d4f1069d0821daa8ac798c6ac.tar.gz
emacs-229644e7b176d89d4f1069d0821daa8ac798c6ac.zip
(Format of Keymaps): Keymaps contain char tables, not vectors.
(Active Keymaps): Add emulation-mode-map-alists. (Functions for Key Lookup): key-binding has new arg no-remap. (Remapping Commands): New node. (Scanning Keymaps): where-is-internal has new arg no-remap. (Tool Bar): Add tool-bar-local-item-from-menu. Clarify when to use tool-bar-add-item-from-menu.
-rw-r--r--lispref/keymaps.texi154
1 files changed, 118 insertions, 36 deletions
diff --git a/lispref/keymaps.texi b/lispref/keymaps.texi
index b6170b3a8f0..fd5c398fec6 100644
--- a/lispref/keymaps.texi
+++ b/lispref/keymaps.texi
@@ -28,6 +28,7 @@ found. The whole process is called @dfn{key lookup}.
28* Key Lookup:: How extracting elements from keymaps works. 28* Key Lookup:: How extracting elements from keymaps works.
29* Functions for Key Lookup:: How to request key lookup. 29* Functions for Key Lookup:: How to request key lookup.
30* Changing Key Bindings:: Redefining a key in a keymap. 30* Changing Key Bindings:: Redefining a key in a keymap.
31* Remapping Commands:: Bindings that translate one command to another.
31* Key Binding Commands:: Interactive interfaces for redefining keys. 32* Key Binding Commands:: Interactive interfaces for redefining keys.
32* Scanning Keymaps:: Looking through all keymaps, for printing help. 33* Scanning Keymaps:: Looking through all keymaps, for printing help.
33* Menu Keymaps:: Defining a menu as a keymap. 34* Menu Keymaps:: Defining a menu as a keymap.
@@ -124,27 +125,24 @@ bindings allow a keymap to bind all possible event types without having
124to enumerate all of them. A keymap that has a default binding 125to enumerate all of them. A keymap that has a default binding
125completely masks any lower-precedence keymap. 126completely masks any lower-precedence keymap.
126 127
127@item @var{vector} 128@item @var{char-table}
128If an element of a keymap is a vector, the vector counts as bindings for 129If an element of a keymap is a char-table, it counts as holding
129all the @sc{ascii} characters, codes 0 through 127; vector element 130bindings for all character events with no modifier bits
130@var{n} is the binding for the character with code @var{n}. This is a 131(@pxref{modifier bits}): element @var{n} is the binding for the
131compact way to record lots of bindings. A keymap with such a vector is 132character with code @var{n}. This is a compact way to record lots of
132called a @dfn{full keymap}. Other keymaps are called @dfn{sparse 133bindings. A keymap with such a char-table is called a @dfn{full
133keymaps}. 134keymap}. Other keymaps are called @dfn{sparse keymaps}.
134 135
135A @code{nil} binding is used to mean that a key is explicitly not bound. 136When a keymap contains a char-table vector, it always defines a
136Just like any other binding, it takes precedence over a default binding 137binding for each character without modifiers. However, if the binding
137or a binding in the parent keymap, but on the other hand, it does not 138is @code{nil}, it doesn't constitute a definition. @code{nil} takes
138take precedence over keymaps of lower priority. 139precedence over a default binding or a binding in the parent keymap.
139 140So in a full keymap, default bindings are not meaningful for
140When a keymap contains a vector, it always defines a binding for each 141characters without modifiers. They can still apply to characters with
141@sc{ascii} character, even if the vector contains @code{nil} for that 142modifier bits and to non-character events. A binding of @code{nil}
142character. Such a binding of @code{nil} overrides any default key 143does @emph{not} override lower-precedence keymaps; thus, if the local
143binding in the keymap, for @sc{ascii} characters. However, default 144map gives a binding of @code{nil}, Emacs uses the binding from the
144bindings are still meaningful for events other than @sc{ascii} 145global map.
145characters. A binding of @code{nil} does @emph{not} override
146lower-precedence keymaps; thus, if the local map gives a binding of
147@code{nil}, Emacs uses the binding from the global map.
148 146
149@item @var{string} 147@item @var{string}
150@cindex keymap prompt string 148@cindex keymap prompt string
@@ -530,7 +528,8 @@ when the minor mode is enabled.
530 528
531 The variable @code{overriding-local-map}, if non-@code{nil}, specifies 529 The variable @code{overriding-local-map}, if non-@code{nil}, specifies
532another local keymap that overrides the buffer's local map and all the 530another local keymap that overrides the buffer's local map and all the
533minor mode keymaps. 531minor mode keymaps. Modes for emulation can specify additional
532active keymaps through the variable @code{emulation-mode-map-alists}.
534 533
535 All the active keymaps are used together to determine what command to 534 All the active keymaps are used together to determine what command to
536execute when a key is entered. Emacs searches these maps one by one, in 535execute when a key is entered. Emacs searches these maps one by one, in
@@ -714,6 +713,16 @@ binding in this keymap, then it is special, and the binding for the
714event is run directly by @code{read-event}. @xref{Special Events}. 713event is run directly by @code{read-event}. @xref{Special Events}.
715@end defvar 714@end defvar
716 715
716@defvar emulation-mode-map-alists
717This variable holds a list of keymap alists to use for emulations
718modes. It is intended for modes or packages using multiple minor-mode
719keymaps. Each element is a keymap alist which has the same format and
720meaning as @code{minor-mode-map-alist}, or a symbol with a variable
721binding which is such an alist. The ``active'' keymaps in each alist
722are used before @code{minor-mode-map-alist} and
723@code{minor-mode-overriding-map-alist}.
724@end defvar
725
717@node Key Lookup 726@node Key Lookup
718@section Key Lookup 727@section Key Lookup
719@cindex key lookup 728@cindex key lookup
@@ -918,7 +927,7 @@ Used in keymaps to undefine keys. It calls @code{ding}, but does
918not cause an error. 927not cause an error.
919@end deffn 928@end deffn
920 929
921@defun key-binding key &optional accept-defaults 930@defun key-binding key &optional accept-defaults no-remap
922This function returns the binding for @var{key} in the current 931This function returns the binding for @var{key} in the current
923keymaps, trying all the active keymaps. The result is @code{nil} if 932keymaps, trying all the active keymaps. The result is @code{nil} if
924@var{key} is undefined in the keymaps. 933@var{key} is undefined in the keymaps.
@@ -927,6 +936,12 @@ keymaps, trying all the active keymaps. The result is @code{nil} if
927The argument @var{accept-defaults} controls checking for default 936The argument @var{accept-defaults} controls checking for default
928bindings, as in @code{lookup-key} (above). 937bindings, as in @code{lookup-key} (above).
929 938
939When commands are remapped (@pxref{Remapping Commands}),
940@code{key-binding} normally processes command remappings so as to
941returns the remapped command that will actually be executed. However,
942if @var{no-remap} is non-@code{nil}, @code{key-binding} ignores
943remappings and returns the binding directly specified for @var{key}.
944
930An error is signaled if @var{key} is not a string or a vector. 945An error is signaled if @var{key} is not a string or a vector.
931 946
932@example 947@example
@@ -1150,6 +1165,12 @@ changing an entry in @code{ctl-x-map}, and this has the effect of
1150changing the bindings of both @kbd{C-p C-f} and @kbd{C-x C-f} in the 1165changing the bindings of both @kbd{C-p C-f} and @kbd{C-x C-f} in the
1151default global map. 1166default global map.
1152 1167
1168 The function @code{substitute-key-definition} scans a keymap for
1169keys that have a certain binding and rebind them with a different
1170binding. Another feature you can use for similar effects, but which
1171is often cleaner, is to add a binding that remaps a command
1172(@pxref{Remapping Commands}).
1173
1153@defun substitute-key-definition olddef newdef keymap &optional oldmap 1174@defun substitute-key-definition olddef newdef keymap &optional oldmap
1154@cindex replace bindings 1175@cindex replace bindings
1155This function replaces @var{olddef} with @var{newdef} for any keys in 1176This function replaces @var{olddef} with @var{newdef} for any keys in
@@ -1184,13 +1205,6 @@ bindings in another. For example,
1184puts the special deletion command in @code{my-map} for whichever keys 1205puts the special deletion command in @code{my-map} for whichever keys
1185are globally bound to the standard deletion command. 1206are globally bound to the standard deletion command.
1186 1207
1187@ignore
1188@c Emacs 18 only
1189Prefix keymaps that appear within @var{keymap} are not checked
1190recursively for keys bound to @var{olddef}; they are not changed at all.
1191Perhaps it would be better to check nested keymaps recursively.
1192@end ignore
1193
1194Here is an example showing a keymap before and after substitution: 1208Here is an example showing a keymap before and after substitution:
1195 1209
1196@smallexample 1210@smallexample
@@ -1259,6 +1273,56 @@ Dired mode is set up:
1259@end smallexample 1273@end smallexample
1260@end defun 1274@end defun
1261 1275
1276@node Remapping Commands
1277@section Remapping Commands
1278@cindex remapping commands
1279
1280 A special kind of key binding, using a special ``key sequence''
1281which includes a command name, has the effect of @dfn{remapping} that
1282command into another. Here's how it works. You make a key binding
1283for a key sequence tha starts with the dummy event @code{remap},
1284followed by the command name you want to remap. Specify the remapped
1285definition as the definition in this binding. The remapped definition
1286is usually a command name, but it can be any valid definition for
1287a key binding.
1288
1289 Here's an example. Suppose that My mode uses special commands
1290@code{my-kill-line} and @code{my-kill-word}, which should be invoked
1291instead of @code{kill-line} and @code{kill-word}. It can establish
1292this by making these two command-remapping bindings in its keymap:
1293
1294@example
1295(define-key my-mode-map [remap kill-line] 'my-kill-line)
1296(define-key my-mode-map [remap kill-word] 'my-kill-word)
1297@end example
1298
1299Whenever @code{my-mode-map} is an active keymap, if the user types
1300@kbd{C-k}, Emacs will find the standard global binding of
1301@code{kill-line} (assuming nobody has changed it). But
1302@code{my-mode-map} remaps @code{kill-line} to @code{my-mode-map},
1303so instead of running @code{kill-line}, Emacs runs
1304@code{my-kill-line}.
1305
1306Remapping only works through a single level. In other words,
1307
1308@example
1309(define-key my-mode-map [remap kill-line] 'my-kill-line)
1310(define-key my-mode-map [remap my-kill-line] 'my-other-kill-line)
1311@end example
1312
1313@noindent
1314does not have the effect of remapping @code{kill-line} into
1315@code{my-other-kill-line}. If an ordinary key binding specifies
1316@code{kill-line}, this keymap will remap it to @code{my-kill-line};
1317if an ordinary binding specifies @code{my-kill-line}, this keymap will
1318remap it to @code{my-other-kill-line}.
1319
1320@defun command-remapping command
1321This function returns the remapping for @var{command}, given the
1322current active keymaps. If @var{command} is not remapped (which is
1323the usual situation), the function returns @code{nil}.
1324@end defun
1325
1262@node Key Binding Commands 1326@node Key Binding Commands
1263@section Commands for Binding Keys 1327@section Commands for Binding Keys
1264 1328
@@ -1488,7 +1552,7 @@ This function is the cleanest way to examine all the bindings
1488in a keymap. 1552in a keymap.
1489@end defun 1553@end defun
1490 1554
1491@defun where-is-internal command &optional keymap firstonly noindirect 1555@defun where-is-internal command &optional keymap firstonly noindirect no-remap
1492This function is a subroutine used by the @code{where-is} command 1556This function is a subroutine used by the @code{where-is} command
1493(@pxref{Help, , Help, emacs,The GNU Emacs Manual}). It returns a list 1557(@pxref{Help, , Help, emacs,The GNU Emacs Manual}). It returns a list
1494of key sequences (of any length) that are bound to @var{command} in a 1558of key sequences (of any length) that are bound to @var{command} in a
@@ -1519,6 +1583,13 @@ If @var{noindirect} is non-@code{nil}, @code{where-is-internal} doesn't
1519follow indirect keymap bindings. This makes it possible to search for 1583follow indirect keymap bindings. This makes it possible to search for
1520an indirect definition itself. 1584an indirect definition itself.
1521 1585
1586When command remapping is in effect (@pxref{Remapping Commands}),
1587@code{where-is-internal} figures out when a command will be run due to
1588remapping and reports keys accordingly. It also returns @code{nil} if
1589@var{command} won't really be run because it has been remapped to some
1590other command. However, if @var{no-remap} is non-@code{nil}.
1591@code{where-is-internal} ignores remappings.
1592
1522@smallexample 1593@smallexample
1523@group 1594@group
1524(where-is-internal 'describe-function) 1595(where-is-internal 'describe-function)
@@ -2270,15 +2341,26 @@ To define items in some local map, bind @code{`tool-bar-map} with
2270 2341
2271@defun tool-bar-add-item-from-menu command icon &optional map &rest props 2342@defun tool-bar-add-item-from-menu command icon &optional map &rest props
2272@tindex tool-bar-add-item-from-menu 2343@tindex tool-bar-add-item-from-menu
2273This command is a convenience for defining tool bar items which are 2344This function is a convenience for defining tool bar items which are
2274consistent with existing menu bar bindings. The binding of 2345consistent with existing menu bar bindings. The binding of
2275@var{command} is looked up in the menu bar in @var{map} (default 2346@var{command} is looked up in the menu bar in @var{map} (default
2276@code{global-map}) and modified to add an image specification for 2347@code{global-map}) and modified to add an image specification for
2277@var{icon}, which is looked for in the same way as by 2348@var{icon}, which is found in the same way as by
2278@code{tool-bar-add-item}. The resulting binding is then placed in 2349@code{tool-bar-add-item}. The resulting binding is then placed in
2279@code{tool-bar-map}. @var{map} must contain an appropriate keymap bound 2350@code{tool-bar-map}, so use this function only for global tool bar
2280to @code{[menu-bar]}. The remaining arguments @var{props} are 2351items.
2281additional property list elements to add to the menu item specification. 2352
2353@var{map} must contain an appropriate keymap bound to
2354@code{[menu-bar]}. The remaining arguments @var{props} are additional
2355property list elements to add to the menu item specification.
2356@end defun
2357
2358@defun tool-bar-local-item-from-menu command icon in-map &optional from-map &rest props
2359This function is used for making non-global tool bar items. Use it
2360like @code{tool-bar-add-item-from-menu} except that @var{in-map}
2361specifies the local map to make the definition in. The argument
2362@var{from-map} si like the @var{map} argument of
2363@code{tool-bar-add-item-from-menu}.
2282@end defun 2364@end defun
2283 2365
2284@tindex auto-resize-tool-bar 2366@tindex auto-resize-tool-bar