aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman2005-02-27 00:00:41 +0000
committerRichard M. Stallman2005-02-27 00:00:41 +0000
commit8a36c244a57d8f6f8f7828552ef6a4226667d203 (patch)
tree609e7adb27a365a794f5cf5592d2590ae63e7902
parent1e04ba2c9054fb1645226a3448cc6c5325d72591 (diff)
downloademacs-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.texi146
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
12structures called @dfn{keymaps}. Each binding in a keymap associates 12structures 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
14a command. When an event type is bound to a keymap, that keymap is used 14a command. When an event type is bound to a keymap, that keymap is used
15to look up the next input event; this continues until a command is 15to look up the next input event; this continues until a command is
16found. The whole process is called @dfn{key lookup}. 16found. 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
565text or overlay property. If that is non-@code{nil}, it is the first 570text or overlay property. If that is non-@code{nil}, it is the first
566keymap to be processed, in normal circumstances. 571keymap 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
569substitute other keymaps for some of those. The variable 574other 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
571that replaces all the usual active keymaps except the global keymap. 576that replaces all the usual active keymaps except the global keymap.
572Another way to do this is with @code{overriding-terminal-local-map}; 577Another 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
679not do. The @sc{cdr} can be either a keymap (a list) or a symbol whose 684not do. The @sc{cdr} can be either a keymap (a list) or a symbol whose
680function definition is a keymap. 685function definition is a keymap.
681 686
682When more than one minor mode keymap is active, their order of priority 687When more than one minor mode keymap is active, the earlier one in
683is the order of @code{minor-mode-map-alist}. But you should design 688@code{minor-mode-map-alist} takes priority. But you should design
684minor modes so that they don't interfere with each other. If you do 689minor modes so that they don't interfere with each other. If you do
685this properly, the order will not matter. 690this 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;
765the rest of the event is ignored. In fact, a key sequence used for key 770the rest of the event is ignored. In fact, a key sequence used for key
766lookup may designate mouse events with just their types (symbols) 771lookup may designate a mouse event with just its types (a symbol)
767instead of with entire mouse events (lists). @xref{Input Events}. Such 772instead of the entire event (a list). @xref{Input Events}. Such
768a ``key-sequence'' is insufficient for @code{command-execute} to run, 773a ``key-sequence'' is insufficient for @code{command-execute} to run,
769but it is sufficient for looking up or rebinding a key. 774but 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
1114numeric codes for the modifier bits don't appear in compiled files. 1119numeric 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
1117keymap or if @var{key} is not a string or vector representing a key 1122a keymap or if @var{key} is not a string or vector representing a key
1118sequence. You can use event types (symbols) as shorthand for events 1123sequence. You can use event types (symbols) as shorthand for events
1119that are lists. 1124that are lists. The @code{kbd} macro (@pxref{Keymap Terminology}) is
1125a convenient way to specify the key sequence.
1120 1126
1121@defun define-key keymap key binding 1127@defun define-key keymap key binding
1122This function sets the binding for @var{key} in @var{keymap}. (If 1128This 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
1399redefines the first (leftmost) mouse button, typed with the Meta key, to 1405redefines the first (leftmost) mouse button, entered with the Meta key, to
1400set point where you click. 1406set 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
1743describe the action of the command it corresponds to. Note that it is 1749describe the action of the command it corresponds to. Note that it is
1744not generally possible to display non-@acronym{ASCII} text in menus. It will 1750not generally possible to display non-@acronym{ASCII} text in menus. It will
1745work for keyboard menus and will work to a large extent when Emacs is 1751work for keyboard menus and will work to a large extent when Emacs is
1746built with Gtk+ support.@footnote{In this case, the text is first 1752built with the Gtk+ toolkit.@footnote{In this case, the text is first
1747encoded using the @code{utf-8} coding system and then rendered by the 1753encoded using the @code{utf-8} coding system and then rendered by the
1748toolkit as it sees fit.} 1754toolkit as it sees fit.}
1749 1755
@@ -2044,13 +2050,8 @@ with @samp{@@} or not. In a toolkit version of Emacs, the only thing
2044special about @samp{@@} at the beginning of an item string is that the 2050special 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
2048The full definition of a prefix key always comes from merging the 2054separate panes or separate submenus.
2049definitions supplied by the various active keymaps (minor mode, local,
2050and global). When more than one of these keymaps is a menu, each of
2051them makes a separate pane or panes (when Emacs does not use an
2052X-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
2097definition of the @samp{Print} submenu in the @samp{Tools} menu in the 2098definition of the @samp{Replace} submenu in the @samp{Edit} menu in
2098menu bar, and it uses the simple menu item format (@pxref{Simple Menu 2099the menu bar, and it uses the extended menu item format
2099Items}). First we create the keymap, and give it a name: 2100(@pxref{Extended Menu Items}). First we create the keymap, and give
2101it 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
2106Next we define the menu items: 2108Next 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
2122Note the symbols which the bindings are ``made for''; these appear 2123Note 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.
2138Like a real menu item, the separator has a key symbol, in this case 2139Like 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
2140have two different key symbols. 2141must have two different key symbols.
2141
2142 Here is code to define enable conditions for two of the commands in
2143the 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
2158Note that this incorporates the submenu keymap, which is the value of 2151Note that this incorporates the submenu keymap, which is the value of
2159the variable @code{menu-bar-print-menu}, rather than the symbol 2152the 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
2161item would be meaningless because @code{menu-bar-print-menu} is not a 2154menu item would be meaningless because @code{menu-bar-replace-menu} is
2162command. 2155not 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
2165can do it this way: 2158can 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
2173Items}) 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
2182With the extended menu item, the enable condition is specified
2183inside the menu item itself. If we wanted to make this
2184item disappear from the menu entirely when the mark is inactive,
2185we 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
2198permanently displayed menu stretching horizontally across the top of the 2170permanently displayed menu stretching horizontally across the top of the
2199frame. The items of the menu bar are the subcommands of the fake 2171frame. 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
2203own (let's call it @var{key}), and make a binding for the key sequence 2175own (let's call it @var{key}), and make a binding for the key sequence