]> code.delx.au - gnu-emacs/blobdiff - lispref/keymaps.texi
*** empty log message ***
[gnu-emacs] / lispref / keymaps.texi
index 826f90d5a0572dad31cd8854b7a8e3a48cf358de..089d29fc4ee1564060132ccf068a7dc3b6f9ff70 100644 (file)
@@ -1,6 +1,6 @@
 @c -*-texinfo-*-
 @c This is part of the GNU Emacs Lisp Reference Manual.
-@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1998, 1999, 2000
+@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1998, 1999, 2000, 2004
 @c   Free Software Foundation, Inc.
 @c See the file elisp.texi for copying conditions.
 @setfilename ../info/keymaps
@@ -95,6 +95,30 @@ precedence over) the corresponding global bindings.  The minor mode
 keymaps shadow both local and global keymaps.  @xref{Active Keymaps},
 for details.
 
+  The Emacs Lisp representation for a key sequence is a string or vector.
+You can enter key sequence constants using the ordinary string or vector
+representation; it is also convenient to use @code{kbd}:
+
+@defmac kbd keyseq-text
+This macro converts the text @var{keyseq-text} (a string constant)
+into a key sequence (a string or vector constant).  The contents
+of @var{keyseq-text} should describe the key sequence using the syntax
+used in this manual.  More precisely, it uses the same syntax that
+Edit Macro mode uses for editing keyboard macros (@pxref{Edit Keyboard
+Macro,,, emacs, The GNU Emacs Manual}).
+
+@example
+(kbd "C-x") @result{} "\C-x"
+(kbd "C-x C-f") @result{} "\C-x\C-f"
+(kbd "C-x 4 C-f") @result{} "\C-x4\C-f"
+(kbd "X") @result{} "X"
+(kbd "RET") @result{} "\^M"
+(kbd "C-c SPC") @result{} "\C-c@ "
+(kbd "<f1> SPC") @result{} [f1 32]
+(kbd "C-M-<down>") @result{} [C-M-down]
+@end example
+@end defmac
+
 @node Format of Keymaps
 @section Format of Keymaps
 @cindex format of keymaps
@@ -123,7 +147,8 @@ This specifies a @dfn{default key binding}; any event not bound by other
 elements of the keymap is given @var{binding} as its binding.  Default
 bindings allow a keymap to bind all possible event types without having
 to enumerate all of them.  A keymap that has a default binding
-completely masks any lower-precedence keymap.
+completely masks any lower-precedence keymap, except for events
+explicitly bound to @code{nil} (see below).
 
 @item @var{char-table}
 If an element of a keymap is a char-table, it counts as holding
@@ -230,17 +255,15 @@ satisfies @code{keymapp}.
 @c ??? This should come after make-sparse-keymap
 @defun make-keymap &optional prompt
 This function creates and returns a new full keymap.  That keymap
-contains a char-table (@pxref{Char-Tables}) with 384 slots: the first
-128 slots are for defining all the @sc{ascii} characters, the next 128
-slots are for 8-bit European characters, and each one of the final 128
-slots is for one character set of non-@sc{ascii} characters supported by
-Emacs.  The new keymap initially binds all these characters to
-@code{nil}, and does not bind any other kind of event.
+contains a char-table (@pxref{Char-Tables}) with slots for all
+characters without modifiers.  The new keymap initially binds all
+these characters to @code{nil}, and does not bind any other kind of
+event.
 
 @example
 @group
 (make-keymap)
-    @result{} (keymap [nil nil nil @dots{} nil nil])
+    @result{} (keymap #^[t nil nil nil @dots{} nil nil keymap])
 @end group
 @end example
 
@@ -488,6 +511,7 @@ active keymap.
 
 @defun define-prefix-command symbol &optional mapvar prompt
 @cindex prefix command
+@anchor{Definition of define-prefix-command}
 This function prepares @var{symbol} for use as a prefix key's binding:
 it creates a sparse keymap and stores it as @var{symbol}'s function
 definition.  Subsequently binding a key sequence to @var{symbol} will
@@ -593,7 +617,7 @@ other.
 This function returns the current buffer's local keymap, or @code{nil}
 if it has none.  In the following example, the keymap for the
 @samp{*scratch*} buffer (using Lisp Interaction mode) is a sparse keymap
-in which the entry for @key{ESC}, @sc{ascii} code 27, is another sparse
+in which the entry for @key{ESC}, @acronym{ASCII} code 27, is another sparse
 keymap.
 
 @example
@@ -677,15 +701,16 @@ all buffers.
 
 @defvar overriding-local-map
 If non-@code{nil}, this variable holds a keymap to use instead of the
-buffer's local keymap and instead of all the minor mode keymaps.  This
-keymap, if any, overrides all other maps that would have been active,
-except for the current global map.
+buffer's local keymap, text property or overlay keymaps, and instead
+of all the minor mode keymaps.  This keymap, if any, overrides all
+other maps that would have been active, except for the current global
+map.
 @end defvar
 
 @defvar overriding-terminal-local-map
 If non-@code{nil}, this variable holds a keymap to use instead of
-@code{overriding-local-map}, the buffer's local keymap and all the minor
-mode keymaps.
+@code{overriding-local-map}, the buffer's local keymap, text property
+or overlay keymaps, and all the minor mode keymaps.
 
 This variable is always local to the current terminal and cannot be
 buffer-local.  @xref{Multiple Displays}.  It is used to implement
@@ -880,6 +905,10 @@ the other functions described in this chapter that look up keys use
     @result{} find-file
 @end group
 @group
+(lookup-key (current-global-map) (kbd "C-x C-f"))
+    @result{} find-file
+@end group
+@group
 (lookup-key (current-global-map) "\C-x\C-f12345")
     @result{} 2
 @end group
@@ -952,9 +981,12 @@ An error is signaled if @var{key} is not a string or a vector.
 @end example
 @end defun
 
-@defun current-active-maps
+@defun current-active-maps &optional olp
 This returns the list of keymaps that would be used by the command
-loop in the current circumstances to look up a key sequence.
+loop in the current circumstances to look up a key sequence.  Normally
+it ignores @code{overriding-local-map} and
+@code{overriding-terminal-local-map}, but if @var{olp} is
+non-@code{nil} then it pays attention to them.
 @end defun
 
 @defun local-key-binding key &optional accept-defaults
@@ -999,7 +1031,7 @@ This variable is the meta-prefix character code.  It is used when
 translating a meta character to a two-character sequence so it can be
 looked up in a keymap.  For useful results, the value should be a prefix
 event (@pxref{Prefix Keys}).  The default value is 27, which is the
-@sc{ascii} code for @key{ESC}.
+@acronym{ASCII} code for @key{ESC}.
 
 As long as the value of @code{meta-prefix-char} remains 27, key lookup
 translates @kbd{M-b} into @kbd{@key{ESC} b}, which is normally defined
@@ -1126,7 +1158,7 @@ map
 
 @group
 ;; @r{Build sparse submap for @kbd{C-x} and bind @kbd{f} in that.}
-(define-key map "\C-xf" 'forward-word)
+(define-key map (kbd "C-x f") 'forward-word)
     @result{} forward-word
 @end group
 @group
@@ -1139,14 +1171,14 @@ map
 
 @group
 ;; @r{Bind @kbd{C-p} to the @code{ctl-x-map}.}
-(define-key map "\C-p" ctl-x-map)
+(define-key map (kbd "C-p") ctl-x-map)
 ;; @code{ctl-x-map}
 @result{} [nil @dots{} find-file @dots{} backward-kill-sentence]
 @end group
 
 @group
 ;; @r{Bind @kbd{C-f} to @code{foo} in the @code{ctl-x-map}.}
-(define-key map "\C-p\C-f" 'foo)
+(define-key map (kbd "C-p C-f") 'foo)
 @result{} 'foo
 @end group
 @group
@@ -1166,7 +1198,7 @@ changing the bindings of both @kbd{C-p C-f} and @kbd{C-x C-f} in the
 default global map.
 
   The function @code{substitute-key-definition} scans a keymap for
-keys that have a certain binding and rebind them with a different
+keys that have a certain binding and rebinds them with a different
 binding.  Another feature you can use for similar effects, but which
 is often cleaner, is to add a binding that remaps a command
 (@pxref{Remapping Commands}).
@@ -1280,7 +1312,7 @@ Dired mode is set up:
   A special kind of key binding, using a special ``key sequence''
 which includes a command name, has the effect of @dfn{remapping} that
 command into another.  Here's how it works.  You make a key binding
-for a key sequence tha starts with the dummy event @code{remap},
+for a key sequence that starts with the dummy event @code{remap},
 followed by the command name you want to remap.  Specify the remapped
 definition as the definition in this binding.  The remapped definition
 is usually a command name, but it can be any valid definition for
@@ -1299,7 +1331,7 @@ this by making these two command-remapping bindings in its keymap:
 Whenever @code{my-mode-map} is an active keymap, if the user types
 @kbd{C-k}, Emacs will find the standard global binding of
 @code{kill-line} (assuming nobody has changed it).  But
-@code{my-mode-map} remaps @code{kill-line} to @code{my-mode-map},
+@code{my-mode-map} remaps @code{kill-line} to @code{my-kill-line},
 so instead of running @code{kill-line}, Emacs runs
 @code{my-kill-line}.
 
@@ -1312,15 +1344,16 @@ Remapping only works through a single level.  In other words,
 
 @noindent
 does not have the effect of remapping @code{kill-line} into
-@code{my-other-kill-line}.  If an ordinary key binding specifies 
+@code{my-other-kill-line}.  If an ordinary key binding specifies
 @code{kill-line}, this keymap will remap it to @code{my-kill-line};
 if an ordinary binding specifies @code{my-kill-line}, this keymap will
 remap it to @code{my-other-kill-line}.
 
 @defun command-remapping command
-This function returns the remapping for @var{command}, given the
-current active keymaps.  If @var{command} is not remapped (which is
-the usual situation), the function returns @code{nil}.
+This function returns the remapping for @var{command} (a symbol),
+given the current active keymaps.  If @var{command} is not remapped
+(which is the usual situation), or not a symbol, the function returns
+@code{nil}.
 @end defun
 
 @node Key Binding Commands
@@ -1333,7 +1366,7 @@ changing key bindings.  They work by calling @code{define-key}.
 (@pxref{Init File}) for simple customization.  For example,
 
 @smallexample
-(global-set-key "\C-x\C-\\" 'next-line)
+(global-set-key (kbd "C-x C-\\") 'next-line)
 @end smallexample
 
 @noindent
@@ -1361,8 +1394,8 @@ redefines @kbd{C-x C-\} to move down a line.
 redefines the first (leftmost) mouse button, typed with the Meta key, to
 set point where you click.
 
-@cindex non-@sc{ascii} text in keybindings
-  Be careful when using non-@sc{ascii} text characters in Lisp
+@cindex non-@acronym{ASCII} text in keybindings
+  Be careful when using non-@acronym{ASCII} text characters in Lisp
 specifications of keys to bind.  If these are read as multibyte text, as
 they usually will be in a Lisp file (@pxref{Loading Non-ASCII}), you
 must type the keys as multibyte too.  For instance, if you use this:
@@ -1384,7 +1417,7 @@ actually bind the multibyte character with code 2294, not the unibyte
 Latin-1 character with code 246 (@kbd{M-v}).  In order to use this
 binding, you need to enter the multibyte Latin-1 character as keyboard
 input.  One way to do this is by using an appropriate input method
-(@pxref{Input Methods, , Input Methods, emacs,The GNU Emacs Manual}).
+(@pxref{Input Methods, , Input Methods, emacs, The GNU Emacs Manual}).
 
   If you want to use a unibyte character in the key binding, you can
 construct the key sequence string using @code{multibyte-char-to-unibyte}
@@ -1474,7 +1507,7 @@ association list with elements of the form @code{(@var{key} .@:
 @var{keymap} is @var{map}.
 
 The elements of the alist are ordered so that the @var{key} increases
-in length.  The first element is always @code{("" .@: @var{keymap})},
+in length.  The first element is always @code{([] .@: @var{keymap})},
 because the specified keymap is accessible from itself with a prefix of
 no events.
 
@@ -1492,7 +1525,7 @@ definition is the sparse keymap @code{(keymap (83 .@: center-paragraph)
 @smallexample
 @group
 (accessible-keymaps (current-local-map))
-@result{}(("" keymap
+@result{}(([] keymap
       (27 keymap   ; @r{Note this keymap for @key{ESC} is repeated below.}
           (83 . center-paragraph)
           (115 . center-line))
@@ -1516,7 +1549,7 @@ of a window.
 @smallexample
 @group
 (accessible-keymaps (current-global-map))
-@result{} (("" keymap [set-mark-command beginning-of-line @dots{}
+@result{} (([] keymap [set-mark-command beginning-of-line @dots{}
                    delete-backward-char])
 @end group
 @group
@@ -1547,6 +1580,8 @@ The function @code{map-keymap} calls @var{function} once
 for each binding in @var{keymap}.  It passes two arguments,
 the event type and the value of the binding.  If @var{keymap}
 has a parent, the parent's bindings are included as well.
+This works recursively: if the parent has itself a parent, then the
+grandparent's bindings are also included and so on.
 
 This function is the cleanest way to examine all the bindings
 in a keymap.
@@ -1555,7 +1590,7 @@ in a keymap.
 @defun where-is-internal command &optional keymap firstonly noindirect no-remap
 This function is a subroutine used by the @code{where-is} command
 (@pxref{Help, , Help, emacs,The GNU Emacs Manual}).  It returns a list
-of key sequences (of any length) that are bound to @var{command} in a
+of all key sequences (of any length) that are bound to @var{command} in a
 set of keymaps.
 
 The argument @var{command} can be any object; it is compared with all
@@ -1563,7 +1598,7 @@ keymap entries using @code{eq}.
 
 If @var{keymap} is @code{nil}, then the maps used are the current active
 keymaps, disregarding @code{overriding-local-map} (that is, pretending
-its value is @code{nil}).  If @var{keymap} is non-@code{nil}, then the
+its value is @code{nil}).  If @var{keymap} is a keymap, then the
 maps searched are @var{keymap} and the global keymap.  If @var{keymap}
 is a list of keymaps, only those keymaps are searched.
 
@@ -1573,11 +1608,12 @@ keymaps that are active.  To search only the global map, pass
 @code{(keymap)} (an empty keymap) as @var{keymap}.
 
 If @var{firstonly} is @code{non-ascii}, then the value is a single
-string representing the first key sequence found, rather than a list of
+vector representing the first key sequence found, rather than a list of
 all possible key sequences.  If @var{firstonly} is @code{t}, then the
 value is the first key sequence, except that key sequences consisting
-entirely of @sc{ascii} characters (or meta variants of @sc{ascii}
-characters) are preferred to all other key sequences.
+entirely of @acronym{ASCII} characters (or meta variants of @acronym{ASCII}
+characters) are preferred to all other key sequences and that the
+return value can never be a menu binding.
 
 If @var{noindirect} is non-@code{nil}, @code{where-is-internal} doesn't
 follow indirect keymap bindings.  This makes it possible to search for
@@ -1598,7 +1634,7 @@ other command.  However, if @var{no-remap} is non-@code{nil}.
 @end smallexample
 @end defun
 
-@deffn Command describe-bindings &optional prefix
+@deffn Command describe-bindings &optional prefix buffer-or-name
 This function creates a listing of all current key bindings, and
 displays it in a buffer named @samp{*Help*}.  The text is grouped by
 modes---minor modes first, then the major mode, then global bindings.
@@ -1609,15 +1645,19 @@ listing includes only keys that start with @var{prefix}.
 The listing describes meta characters as @key{ESC} followed by the
 corresponding non-meta character.
 
-When several characters with consecutive @sc{ascii} codes have the
+When several characters with consecutive @acronym{ASCII} codes have the
 same definition, they are shown together, as
 @samp{@var{firstchar}..@var{lastchar}}.  In this instance, you need to
-know the @sc{ascii} codes to understand which characters this means.
+know the @acronym{ASCII} codes to understand which characters this means.
 For example, in the default global map, the characters @samp{@key{SPC}
-..@: ~} are described by a single line.  @key{SPC} is @sc{ascii} 32,
-@kbd{~} is @sc{ascii} 126, and the characters between them include all
+..@: ~} are described by a single line.  @key{SPC} is @acronym{ASCII} 32,
+@kbd{~} is @acronym{ASCII} 126, and the characters between them include all
 the normal printing characters, (e.g., letters, digits, punctuation,
 etc.@:); all these characters are bound to @code{self-insert-command}.
+
+If @var{buffer-or-name} is non-@code{nil}, it should be a buffer or a
+buffer name.  Then @code{describe-bindings} lists that buffer's bindings,
+instead of the current buffer's.
 @end deffn
 
 @node Menu Keymaps
@@ -1656,8 +1696,9 @@ prompt string.
 
 The easiest way to construct a keymap with a prompt string is to specify
 the string as an argument when you call @code{make-keymap},
-@code{make-sparse-keymap} or @code{define-prefix-command}
-(@pxref{Creating Keymaps}).
+@code{make-sparse-keymap} (@pxref{Creating Keymaps}), or
+@code{define-prefix-command} (@pxref{Definition of define-prefix-command}).
+
 
 @defun keymap-prompt keymap
 This function returns the overall prompt string of @var{keymap},
@@ -1694,7 +1735,12 @@ looks like this:
 @noindent
 The @sc{car}, @var{item-string}, is the string to be displayed in the
 menu.  It should be short---preferably one to three words.  It should
-describe the action of the command it corresponds to.
+describe the action of the command it corresponds to.  Note that it is
+not generally possible to display non-@acronym{ASCII} text in menus.  It will
+work for keyboard menus and will work to a large extent when Emacs is
+built with Gtk+ support.@footnote{In this case, the text is first
+encoded using the @code{utf-8} coding system and then rendered by the
+toolkit as it sees fit.}
 
 You can also supply a second string, called the help string, as follows:
 
@@ -1859,7 +1905,7 @@ function should return the binding to use instead.
 @cindex menu separators
 
   A menu separator is a kind of menu item that doesn't display any
-text--instead, it divides the menu into subparts with a horizontal line.
+text---instead, it divides the menu into subparts with a horizontal line.
 A separator looks like this in the menu keymap:
 
 @example
@@ -2077,6 +2123,12 @@ functioning of the menu itself, but they are ``echoed'' in the echo area
 when the user selects from the menu, and they appear in the output of
 @code{where-is} and @code{apropos}.
 
+  The menu in this example is intended for use with the mouse.  If a
+menu is intended for use with the keyboard, that is, if it is bound to
+a key sequence ending with a keyboard event, then the menu items
+should be bound to characters or ``real'' function keys, that can be
+typed with the keyboard.
+
   The binding whose definition is @code{("--")} is a separator line.
 Like a real menu item, the separator has a key symbol, in this case
 @code{separator-ps-print}.  If one menu has two separators, they must
@@ -2319,7 +2371,7 @@ follows.
 @tindex tool-bar-add-item
 This function adds an item to the tool bar by modifying
 @code{tool-bar-map}.  The image to use is defined by @var{icon}, which
-is the base name of an XPM, XBM or PBM image file to located by
+is the base name of an XPM, XBM or PBM image file to be located by
 @code{find-image}.  Given a value @samp{"exit"}, say, @file{exit.xpm},
 @file{exit.pbm} and @file{exit.xbm} would be searched for in that order
 on a color display.  On a monochrome display, the search order is
@@ -2328,7 +2380,7 @@ command @var{def}, and @var{key} is the fake function key symbol in the
 prefix keymap.  The remaining arguments @var{props} are additional
 property list elements to add to the menu item specification.
 
-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
 @code{let} around calls of this function:
 @example
 (defvar foo-tool-bar-map
@@ -2359,7 +2411,7 @@ property list elements to add to the menu item specification.
 This function is used for making non-global tool bar items.  Use it
 like @code{tool-bar-add-item-from-menu} except that @var{in-map}
 specifies the local map to make the definition in.  The argument
-@var{from-map} si like the @var{map} argument of
+@var{from-map} is like the @var{map} argument of
 @code{tool-bar-add-item-from-menu}.
 @end defun
 
@@ -2370,22 +2422,22 @@ show all defined tool bar items---but not larger than a quarter of the
 frame's height.
 @end defvar
 
-@tindex auto-raise-tool-bar-items
-@defvar auto-raise-tool-bar-items
+@tindex auto-raise-tool-bar-buttons
+@defvar auto-raise-tool-bar-buttons
 If this variable is non-@code{nil}, tool bar items display
 in raised form when the mouse moves over them.
 @end defvar
 
-@tindex tool-bar-item-margin
-@defvar tool-bar-item-margin
+@tindex tool-bar-button-margin
+@defvar tool-bar-button-margin
 This variable specifies an extra margin to add around tool bar items.
-The value is an integer, a number of pixels.  The default is 1.
+The value is an integer, a number of pixels.  The default is 4.
 @end defvar
 
-@tindex tool-bar-item-relief
-@defvar tool-bar-item-relief
+@tindex tool-bar-button-relief
+@defvar tool-bar-button-relief
 This variable specifies the shadow width for tool bar items.
-The value is an integer, a number of pixels.  The default is 3.
+The value is an integer, a number of pixels.  The default is 1.
 @end defvar
 
   You can define a special meaning for clicking on a tool bar item with