diff options
| author | Richard M. Stallman | 2003-08-13 17:21:57 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2003-08-13 17:21:57 +0000 |
| commit | 229644e7b176d89d4f1069d0821daa8ac798c6ac (patch) | |
| tree | b3e6e9158a0407d546e37730e99a61caaab32852 | |
| parent | 041b0e7bd7df98929d9bf3e035bc3a1da0916a30 (diff) | |
| download | emacs-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.texi | 154 |
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 | |||
| 124 | to enumerate all of them. A keymap that has a default binding | 125 | to enumerate all of them. A keymap that has a default binding |
| 125 | completely masks any lower-precedence keymap. | 126 | completely masks any lower-precedence keymap. |
| 126 | 127 | ||
| 127 | @item @var{vector} | 128 | @item @var{char-table} |
| 128 | If an element of a keymap is a vector, the vector counts as bindings for | 129 | If an element of a keymap is a char-table, it counts as holding |
| 129 | all the @sc{ascii} characters, codes 0 through 127; vector element | 130 | bindings 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 |
| 131 | compact way to record lots of bindings. A keymap with such a vector is | 132 | character with code @var{n}. This is a compact way to record lots of |
| 132 | called a @dfn{full keymap}. Other keymaps are called @dfn{sparse | 133 | bindings. A keymap with such a char-table is called a @dfn{full |
| 133 | keymaps}. | 134 | keymap}. Other keymaps are called @dfn{sparse keymaps}. |
| 134 | 135 | ||
| 135 | A @code{nil} binding is used to mean that a key is explicitly not bound. | 136 | When a keymap contains a char-table vector, it always defines a |
| 136 | Just like any other binding, it takes precedence over a default binding | 137 | binding for each character without modifiers. However, if the binding |
| 137 | or a binding in the parent keymap, but on the other hand, it does not | 138 | is @code{nil}, it doesn't constitute a definition. @code{nil} takes |
| 138 | take precedence over keymaps of lower priority. | 139 | precedence over a default binding or a binding in the parent keymap. |
| 139 | 140 | So in a full keymap, default bindings are not meaningful for | |
| 140 | When a keymap contains a vector, it always defines a binding for each | 141 | characters without modifiers. They can still apply to characters with |
| 141 | @sc{ascii} character, even if the vector contains @code{nil} for that | 142 | modifier bits and to non-character events. A binding of @code{nil} |
| 142 | character. Such a binding of @code{nil} overrides any default key | 143 | does @emph{not} override lower-precedence keymaps; thus, if the local |
| 143 | binding in the keymap, for @sc{ascii} characters. However, default | 144 | map gives a binding of @code{nil}, Emacs uses the binding from the |
| 144 | bindings are still meaningful for events other than @sc{ascii} | 145 | global map. |
| 145 | characters. A binding of @code{nil} does @emph{not} override | ||
| 146 | lower-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 |
| 532 | another local keymap that overrides the buffer's local map and all the | 530 | another local keymap that overrides the buffer's local map and all the |
| 533 | minor mode keymaps. | 531 | minor mode keymaps. Modes for emulation can specify additional |
| 532 | active 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 |
| 536 | execute when a key is entered. Emacs searches these maps one by one, in | 535 | execute 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 | |||
| 714 | event is run directly by @code{read-event}. @xref{Special Events}. | 713 | event is run directly by @code{read-event}. @xref{Special Events}. |
| 715 | @end defvar | 714 | @end defvar |
| 716 | 715 | ||
| 716 | @defvar emulation-mode-map-alists | ||
| 717 | This variable holds a list of keymap alists to use for emulations | ||
| 718 | modes. It is intended for modes or packages using multiple minor-mode | ||
| 719 | keymaps. Each element is a keymap alist which has the same format and | ||
| 720 | meaning as @code{minor-mode-map-alist}, or a symbol with a variable | ||
| 721 | binding which is such an alist. The ``active'' keymaps in each alist | ||
| 722 | are 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 | |||
| 918 | not cause an error. | 927 | not 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 |
| 922 | This function returns the binding for @var{key} in the current | 931 | This function returns the binding for @var{key} in the current |
| 923 | keymaps, trying all the active keymaps. The result is @code{nil} if | 932 | keymaps, 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 | |||
| 927 | The argument @var{accept-defaults} controls checking for default | 936 | The argument @var{accept-defaults} controls checking for default |
| 928 | bindings, as in @code{lookup-key} (above). | 937 | bindings, as in @code{lookup-key} (above). |
| 929 | 938 | ||
| 939 | When commands are remapped (@pxref{Remapping Commands}), | ||
| 940 | @code{key-binding} normally processes command remappings so as to | ||
| 941 | returns the remapped command that will actually be executed. However, | ||
| 942 | if @var{no-remap} is non-@code{nil}, @code{key-binding} ignores | ||
| 943 | remappings and returns the binding directly specified for @var{key}. | ||
| 944 | |||
| 930 | An error is signaled if @var{key} is not a string or a vector. | 945 | An 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 | |||
| 1150 | changing the bindings of both @kbd{C-p C-f} and @kbd{C-x C-f} in the | 1165 | changing the bindings of both @kbd{C-p C-f} and @kbd{C-x C-f} in the |
| 1151 | default global map. | 1166 | default global map. |
| 1152 | 1167 | ||
| 1168 | The function @code{substitute-key-definition} scans a keymap for | ||
| 1169 | keys that have a certain binding and rebind them with a different | ||
| 1170 | binding. Another feature you can use for similar effects, but which | ||
| 1171 | is 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 |
| 1155 | This function replaces @var{olddef} with @var{newdef} for any keys in | 1176 | This function replaces @var{olddef} with @var{newdef} for any keys in |
| @@ -1184,13 +1205,6 @@ bindings in another. For example, | |||
| 1184 | puts the special deletion command in @code{my-map} for whichever keys | 1205 | puts the special deletion command in @code{my-map} for whichever keys |
| 1185 | are globally bound to the standard deletion command. | 1206 | are globally bound to the standard deletion command. |
| 1186 | 1207 | ||
| 1187 | @ignore | ||
| 1188 | @c Emacs 18 only | ||
| 1189 | Prefix keymaps that appear within @var{keymap} are not checked | ||
| 1190 | recursively for keys bound to @var{olddef}; they are not changed at all. | ||
| 1191 | Perhaps it would be better to check nested keymaps recursively. | ||
| 1192 | @end ignore | ||
| 1193 | |||
| 1194 | Here is an example showing a keymap before and after substitution: | 1208 | Here 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'' | ||
| 1281 | which includes a command name, has the effect of @dfn{remapping} that | ||
| 1282 | command into another. Here's how it works. You make a key binding | ||
| 1283 | for a key sequence tha starts with the dummy event @code{remap}, | ||
| 1284 | followed by the command name you want to remap. Specify the remapped | ||
| 1285 | definition as the definition in this binding. The remapped definition | ||
| 1286 | is usually a command name, but it can be any valid definition for | ||
| 1287 | a 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 | ||
| 1291 | instead of @code{kill-line} and @code{kill-word}. It can establish | ||
| 1292 | this 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 | |||
| 1299 | Whenever @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}, | ||
| 1303 | so instead of running @code{kill-line}, Emacs runs | ||
| 1304 | @code{my-kill-line}. | ||
| 1305 | |||
| 1306 | Remapping 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 | ||
| 1314 | does 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}; | ||
| 1317 | if an ordinary binding specifies @code{my-kill-line}, this keymap will | ||
| 1318 | remap it to @code{my-other-kill-line}. | ||
| 1319 | |||
| 1320 | @defun command-remapping command | ||
| 1321 | This function returns the remapping for @var{command}, given the | ||
| 1322 | current active keymaps. If @var{command} is not remapped (which is | ||
| 1323 | the 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 | |||
| 1488 | in a keymap. | 1552 | in 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 |
| 1492 | This function is a subroutine used by the @code{where-is} command | 1556 | This 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 |
| 1494 | of key sequences (of any length) that are bound to @var{command} in a | 1558 | of 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 | |||
| 1519 | follow indirect keymap bindings. This makes it possible to search for | 1583 | follow indirect keymap bindings. This makes it possible to search for |
| 1520 | an indirect definition itself. | 1584 | an indirect definition itself. |
| 1521 | 1585 | ||
| 1586 | When command remapping is in effect (@pxref{Remapping Commands}), | ||
| 1587 | @code{where-is-internal} figures out when a command will be run due to | ||
| 1588 | remapping 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 | ||
| 1590 | other 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 |
| 2273 | This command is a convenience for defining tool bar items which are | 2344 | This function is a convenience for defining tool bar items which are |
| 2274 | consistent with existing menu bar bindings. The binding of | 2345 | consistent 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 |
| 2280 | to @code{[menu-bar]}. The remaining arguments @var{props} are | 2351 | items. |
| 2281 | additional 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 | ||
| 2355 | property 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 | ||
| 2359 | This function is used for making non-global tool bar items. Use it | ||
| 2360 | like @code{tool-bar-add-item-from-menu} except that @var{in-map} | ||
| 2361 | specifies 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 |