diff options
| author | Richard M. Stallman | 2005-02-27 00:00:41 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2005-02-27 00:00:41 +0000 |
| commit | 8a36c244a57d8f6f8f7828552ef6a4226667d203 (patch) | |
| tree | 609e7adb27a365a794f5cf5592d2590ae63e7902 | |
| parent | 1e04ba2c9054fb1645226a3448cc6c5325d72591 (diff) | |
| download | emacs-8a36c244a57d8f6f8f7828552ef6a4226667d203.tar.gz emacs-8a36c244a57d8f6f8f7828552ef6a4226667d203.zip | |
(Keymaps): Clarify.
(Format of Keymaps): Update lisp-mode-map example.
(Active Keymaps, Key Lookup): Clarify.
(Changing Key Bindings): Add xref to `kbd'.
(Key Binding Commands, Simple Menu Items): Clarify.
(Mouse Menus, Menu Bar): Clarify.
(Menu Example): Replace print example with menu-bar-replace-menu.
| -rw-r--r-- | lispref/keymaps.texi | 146 |
1 files changed, 59 insertions, 87 deletions
diff --git a/lispref/keymaps.texi b/lispref/keymaps.texi index 8b2644c4fbb..9cf73053291 100644 --- a/lispref/keymaps.texi +++ b/lispref/keymaps.texi | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | 10 | ||
| 11 | The bindings between input events and commands are recorded in data | 11 | The bindings between input events and commands are recorded in data |
| 12 | structures called @dfn{keymaps}. Each binding in a keymap associates | 12 | structures called @dfn{keymaps}. Each binding in a keymap associates |
| 13 | (or @dfn{binds}) an individual event type either to another keymap or to | 13 | (or @dfn{binds}) an individual event type, either to another keymap or to |
| 14 | a command. When an event type is bound to a keymap, that keymap is used | 14 | a command. When an event type is bound to a keymap, that keymap is used |
| 15 | to look up the next input event; this continues until a command is | 15 | 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}. |
| @@ -202,24 +202,29 @@ lisp-mode-map | |||
| 202 | @end group | 202 | @end group |
| 203 | @group | 203 | @group |
| 204 | (keymap | 204 | (keymap |
| 205 | ;; @key{TAB} | 205 | (3 keymap |
| 206 | (9 . lisp-indent-line) | 206 | ;; @kbd{C-c C-z} |
| 207 | (26 . run-lisp)) | ||
| 207 | @end group | 208 | @end group |
| 208 | @group | 209 | @group |
| 209 | ;; @key{DEL} | 210 | (27 keymap |
| 210 | (127 . backward-delete-char-untabify) | 211 | ;; @r{@kbd{M-C-x}, treated as @kbd{@key{ESC} C-x}} |
| 212 | (24 . lisp-send-defun) | ||
| 213 | keymap | ||
| 214 | ;; @r{@kbd{M-C-q}, treated as @kbd{@key{ESC} C-q}} | ||
| 215 | (17 . indent-sexp))) | ||
| 211 | @end group | 216 | @end group |
| 212 | @group | 217 | @group |
| 213 | (3 keymap | 218 | ;; @r{This part is inherited from @code{lisp-mode-shared-map}.} |
| 214 | ;; @kbd{C-c C-l} | 219 | keymap |
| 215 | (12 . run-lisp)) | 220 | ;; @key{DEL} |
| 221 | (127 . backward-delete-char-untabify) | ||
| 216 | @end group | 222 | @end group |
| 217 | @group | 223 | @group |
| 218 | (27 keymap | 224 | (27 keymap |
| 219 | ;; @r{@kbd{M-C-q}, treated as @kbd{@key{ESC} C-q}} | 225 | ;; @r{@kbd{M-C-q}, treated as @kbd{@key{ESC} C-q}} |
| 220 | (17 . indent-sexp) | 226 | (17 . indent-sexp)) |
| 221 | ;; @r{@kbd{M-C-x}, treated as @kbd{@key{ESC} C-x}} | 227 | (9 . lisp-indent-line)) |
| 222 | (24 . lisp-send-defun))) | ||
| 223 | @end group | 228 | @end group |
| 224 | @end example | 229 | @end example |
| 225 | 230 | ||
| @@ -565,8 +570,8 @@ additional active keymaps through the variable | |||
| 565 | text or overlay property. If that is non-@code{nil}, it is the first | 570 | text or overlay property. If that is non-@code{nil}, it is the first |
| 566 | keymap to be processed, in normal circumstances. | 571 | keymap to be processed, in normal circumstances. |
| 567 | 572 | ||
| 568 | However, there are also special circumstances, ways programs can | 573 | However, there are also special ways for program can to substitute |
| 569 | substitute other keymaps for some of those. The variable | 574 | other keymaps for some of those. The variable |
| 570 | @code{overriding-local-map}, if non-@code{nil}, specifies a keymap | 575 | @code{overriding-local-map}, if non-@code{nil}, specifies a keymap |
| 571 | that replaces all the usual active keymaps except the global keymap. | 576 | that replaces all the usual active keymaps except the global keymap. |
| 572 | Another way to do this is with @code{overriding-terminal-local-map}; | 577 | Another way to do this is with @code{overriding-terminal-local-map}; |
| @@ -679,8 +684,8 @@ structure as elements of @code{minor-mode-alist}. The map must be the | |||
| 679 | not do. The @sc{cdr} can be either a keymap (a list) or a symbol whose | 684 | not do. The @sc{cdr} can be either a keymap (a list) or a symbol whose |
| 680 | function definition is a keymap. | 685 | function definition is a keymap. |
| 681 | 686 | ||
| 682 | When more than one minor mode keymap is active, their order of priority | 687 | When more than one minor mode keymap is active, the earlier one in |
| 683 | is the order of @code{minor-mode-map-alist}. But you should design | 688 | @code{minor-mode-map-alist} takes priority. But you should design |
| 684 | minor modes so that they don't interfere with each other. If you do | 689 | minor modes so that they don't interfere with each other. If you do |
| 685 | this properly, the order will not matter. | 690 | this properly, the order will not matter. |
| 686 | 691 | ||
| @@ -763,8 +768,8 @@ part of key lookup. | |||
| 763 | 768 | ||
| 764 | Key lookup uses just the event type of each event in the key sequence; | 769 | Key lookup uses just the event type of each event in the key sequence; |
| 765 | the rest of the event is ignored. In fact, a key sequence used for key | 770 | the rest of the event is ignored. In fact, a key sequence used for key |
| 766 | lookup may designate mouse events with just their types (symbols) | 771 | lookup may designate a mouse event with just its types (a symbol) |
| 767 | instead of with entire mouse events (lists). @xref{Input Events}. Such | 772 | instead of the entire event (a list). @xref{Input Events}. Such |
| 768 | a ``key-sequence'' is insufficient for @code{command-execute} to run, | 773 | a ``key-sequence'' is insufficient for @code{command-execute} to run, |
| 769 | but it is sufficient for looking up or rebinding a key. | 774 | but it is sufficient for looking up or rebinding a key. |
| 770 | 775 | ||
| @@ -1113,10 +1118,11 @@ key name). For example, @code{(control ?a)} is equivalent to | |||
| 1113 | @code{C-H-left}. One advantage of such lists is that the precise | 1118 | @code{C-H-left}. One advantage of such lists is that the precise |
| 1114 | numeric codes for the modifier bits don't appear in compiled files. | 1119 | numeric codes for the modifier bits don't appear in compiled files. |
| 1115 | 1120 | ||
| 1116 | For the functions below, an error is signaled if @var{keymap} is not a | 1121 | For the functions below, an error is signaled if @var{keymap} is not |
| 1117 | keymap or if @var{key} is not a string or vector representing a key | 1122 | a keymap or if @var{key} is not a string or vector representing a key |
| 1118 | sequence. You can use event types (symbols) as shorthand for events | 1123 | sequence. You can use event types (symbols) as shorthand for events |
| 1119 | that are lists. | 1124 | that are lists. The @code{kbd} macro (@pxref{Keymap Terminology}) is |
| 1125 | a convenient way to specify the key sequence. | ||
| 1120 | 1126 | ||
| 1121 | @defun define-key keymap key binding | 1127 | @defun define-key keymap key binding |
| 1122 | This function sets the binding for @var{key} in @var{keymap}. (If | 1128 | This function sets the binding for @var{key} in @var{keymap}. (If |
| @@ -1396,7 +1402,7 @@ redefines @kbd{C-x C-\} to move down a line. | |||
| 1396 | @end smallexample | 1402 | @end smallexample |
| 1397 | 1403 | ||
| 1398 | @noindent | 1404 | @noindent |
| 1399 | redefines the first (leftmost) mouse button, typed with the Meta key, to | 1405 | redefines the first (leftmost) mouse button, entered with the Meta key, to |
| 1400 | set point where you click. | 1406 | set point where you click. |
| 1401 | 1407 | ||
| 1402 | @cindex non-@acronym{ASCII} text in keybindings | 1408 | @cindex non-@acronym{ASCII} text in keybindings |
| @@ -1743,7 +1749,7 @@ menu. It should be short---preferably one to three words. It should | |||
| 1743 | describe the action of the command it corresponds to. Note that it is | 1749 | describe the action of the command it corresponds to. Note that it is |
| 1744 | not generally possible to display non-@acronym{ASCII} text in menus. It will | 1750 | not generally possible to display non-@acronym{ASCII} text in menus. It will |
| 1745 | work for keyboard menus and will work to a large extent when Emacs is | 1751 | work for keyboard menus and will work to a large extent when Emacs is |
| 1746 | built with Gtk+ support.@footnote{In this case, the text is first | 1752 | built with the Gtk+ toolkit.@footnote{In this case, the text is first |
| 1747 | encoded using the @code{utf-8} coding system and then rendered by the | 1753 | encoded using the @code{utf-8} coding system and then rendered by the |
| 1748 | toolkit as it sees fit.} | 1754 | toolkit as it sees fit.} |
| 1749 | 1755 | ||
| @@ -2044,13 +2050,8 @@ with @samp{@@} or not. In a toolkit version of Emacs, the only thing | |||
| 2044 | special about @samp{@@} at the beginning of an item string is that the | 2050 | special about @samp{@@} at the beginning of an item string is that the |
| 2045 | @samp{@@} doesn't appear in the menu item. | 2051 | @samp{@@} doesn't appear in the menu item. |
| 2046 | 2052 | ||
| 2047 | You can also produce multiple panes or submenus from separate keymaps. | 2053 | Multiple keymaps that define the same menu prefix key produce |
| 2048 | The full definition of a prefix key always comes from merging the | 2054 | separate panes or separate submenus. |
| 2049 | definitions supplied by the various active keymaps (minor mode, local, | ||
| 2050 | and global). When more than one of these keymaps is a menu, each of | ||
| 2051 | them makes a separate pane or panes (when Emacs does not use an | ||
| 2052 | X-toolkit) or a separate submenu (when using an X-toolkit). | ||
| 2053 | @xref{Active Keymaps}. | ||
| 2054 | 2055 | ||
| 2055 | @node Keyboard Menus | 2056 | @node Keyboard Menus |
| 2056 | @subsection Menus and the Keyboard | 2057 | @subsection Menus and the Keyboard |
| @@ -2094,29 +2095,29 @@ for @key{SPC}. | |||
| 2094 | @cindex menu definition example | 2095 | @cindex menu definition example |
| 2095 | 2096 | ||
| 2096 | Here is a complete example of defining a menu keymap. It is the | 2097 | Here is a complete example of defining a menu keymap. It is the |
| 2097 | definition of the @samp{Print} submenu in the @samp{Tools} menu in the | 2098 | definition of the @samp{Replace} submenu in the @samp{Edit} menu in |
| 2098 | menu bar, and it uses the simple menu item format (@pxref{Simple Menu | 2099 | the menu bar, and it uses the extended menu item format |
| 2099 | Items}). First we create the keymap, and give it a name: | 2100 | (@pxref{Extended Menu Items}). First we create the keymap, and give |
| 2101 | it a name: | ||
| 2100 | 2102 | ||
| 2101 | @example | 2103 | @smallexample |
| 2102 | (defvar menu-bar-print-menu (make-sparse-keymap "Print")) | 2104 | (defvar menu-bar-replace-menu (make-sparse-keymap "Replace")) |
| 2103 | @end example | 2105 | @end smallexample |
| 2104 | 2106 | ||
| 2105 | @noindent | 2107 | @noindent |
| 2106 | Next we define the menu items: | 2108 | Next we define the menu items: |
| 2107 | 2109 | ||
| 2108 | @example | 2110 | @smallexample |
| 2109 | (define-key menu-bar-print-menu [ps-print-region] | 2111 | (define-key menu-bar-replace-menu [tags-repl-continue] |
| 2110 | '("Postscript Print Region" . ps-print-region-with-faces)) | 2112 | '(menu-item "Continue Replace" tags-loop-continue |
| 2111 | (define-key menu-bar-print-menu [ps-print-buffer] | 2113 | :help "Continue last tags replace operation")) |
| 2112 | '("Postscript Print Buffer" . ps-print-buffer-with-faces)) | 2114 | (define-key menu-bar-replace-menu [tags-repl] |
| 2113 | (define-key menu-bar-print-menu [separator-ps-print] | 2115 | '(menu-item "Replace in tagged files" tags-query-replace |
| 2114 | '("--")) | 2116 | :help "Interactively replace a regexp in all tagged files")) |
| 2115 | (define-key menu-bar-print-menu [print-region] | 2117 | (define-key menu-bar-replace-menu [separator-replace-tags] |
| 2116 | '("Print Region" . print-region)) | 2118 | '(menu-item "--")) |
| 2117 | (define-key menu-bar-print-menu [print-buffer] | 2119 | ;; @r{@dots{}} |
| 2118 | '("Print Buffer" . print-buffer)) | 2120 | @end smallexample |
| 2119 | @end example | ||
| 2120 | 2121 | ||
| 2121 | @noindent | 2122 | @noindent |
| 2122 | Note the symbols which the bindings are ``made for''; these appear | 2123 | Note the symbols which the bindings are ``made for''; these appear |
| @@ -2136,58 +2137,29 @@ typed with the keyboard. | |||
| 2136 | 2137 | ||
| 2137 | The binding whose definition is @code{("--")} is a separator line. | 2138 | The binding whose definition is @code{("--")} is a separator line. |
| 2138 | Like a real menu item, the separator has a key symbol, in this case | 2139 | Like a real menu item, the separator has a key symbol, in this case |
| 2139 | @code{separator-ps-print}. If one menu has two separators, they must | 2140 | @code{separator-replace-tags}. If one menu has two separators, they |
| 2140 | have two different key symbols. | 2141 | must have two different key symbols. |
| 2141 | |||
| 2142 | Here is code to define enable conditions for two of the commands in | ||
| 2143 | the menu: | ||
| 2144 | |||
| 2145 | @example | ||
| 2146 | (put 'print-region 'menu-enable 'mark-active) | ||
| 2147 | (put 'ps-print-region-with-faces 'menu-enable 'mark-active) | ||
| 2148 | @end example | ||
| 2149 | 2142 | ||
| 2150 | Here is how we make this menu appear as an item in the parent menu: | 2143 | Here is how we make this menu appear as an item in the parent menu: |
| 2151 | 2144 | ||
| 2152 | @example | 2145 | @example |
| 2153 | (define-key menu-bar-tools-menu [print] | 2146 | (define-key menu-bar-edit-menu [replace] |
| 2154 | (cons "Print" menu-bar-print-menu)) | 2147 | (list 'menu-item "Replace" menu-bar-replace-menu)) |
| 2155 | @end example | 2148 | @end example |
| 2156 | 2149 | ||
| 2157 | @noindent | 2150 | @noindent |
| 2158 | Note that this incorporates the submenu keymap, which is the value of | 2151 | Note that this incorporates the submenu keymap, which is the value of |
| 2159 | the variable @code{menu-bar-print-menu}, rather than the symbol | 2152 | the variable @code{menu-bar-replace-menu}, rather than the symbol |
| 2160 | @code{menu-bar-print-menu} itself. Using that symbol in the parent menu | 2153 | @code{menu-bar-replace-menu} itself. Using that symbol in the parent |
| 2161 | item would be meaningless because @code{menu-bar-print-menu} is not a | 2154 | menu item would be meaningless because @code{menu-bar-replace-menu} is |
| 2162 | command. | 2155 | not a command. |
| 2163 | 2156 | ||
| 2164 | If you wanted to attach the same print menu to a mouse click, you | 2157 | If you wanted to attach the same replace menu to a mouse click, you |
| 2165 | can do it this way: | 2158 | can do it this way: |
| 2166 | 2159 | ||
| 2167 | @example | 2160 | @example |
| 2168 | (define-key global-map [C-S-down-mouse-1] | 2161 | (define-key global-map [C-S-down-mouse-1] |
| 2169 | menu-bar-print-menu) | 2162 | menu-bar-replace-menu) |
| 2170 | @end example | ||
| 2171 | |||
| 2172 | We could equally well use an extended menu item (@pxref{Extended Menu | ||
| 2173 | Items}) for @code{print-region}, like this: | ||
| 2174 | |||
| 2175 | @example | ||
| 2176 | (define-key menu-bar-print-menu [print-region] | ||
| 2177 | '(menu-item "Print Region" print-region | ||
| 2178 | :enable mark-active)) | ||
| 2179 | @end example | ||
| 2180 | |||
| 2181 | @noindent | ||
| 2182 | With the extended menu item, the enable condition is specified | ||
| 2183 | inside the menu item itself. If we wanted to make this | ||
| 2184 | item disappear from the menu entirely when the mark is inactive, | ||
| 2185 | we could do it this way: | ||
| 2186 | |||
| 2187 | @example | ||
| 2188 | (define-key menu-bar-print-menu [print-region] | ||
| 2189 | '(menu-item "Print Region" print-region | ||
| 2190 | :visible mark-active)) | ||
| 2191 | @end example | 2163 | @end example |
| 2192 | 2164 | ||
| 2193 | @node Menu Bar | 2165 | @node Menu Bar |
| @@ -2197,7 +2169,7 @@ we could do it this way: | |||
| 2197 | Most window systems allow each frame to have a @dfn{menu bar}---a | 2169 | Most window systems allow each frame to have a @dfn{menu bar}---a |
| 2198 | permanently displayed menu stretching horizontally across the top of the | 2170 | permanently displayed menu stretching horizontally across the top of the |
| 2199 | frame. The items of the menu bar are the subcommands of the fake | 2171 | frame. The items of the menu bar are the subcommands of the fake |
| 2200 | ``function key'' @code{menu-bar}, as defined by all the active keymaps. | 2172 | ``function key'' @code{menu-bar}, as defined in the active keymaps. |
| 2201 | 2173 | ||
| 2202 | To add an item to the menu bar, invent a fake ``function key'' of your | 2174 | To add an item to the menu bar, invent a fake ``function key'' of your |
| 2203 | own (let's call it @var{key}), and make a binding for the key sequence | 2175 | own (let's call it @var{key}), and make a binding for the key sequence |