Merge from emacs--rel--22
[bpt/emacs.git] / lispref / commands.texi
index 5d1f999..fabe38f 100644 (file)
@@ -1,7 +1,7 @@
 @c -*-texinfo-*-
 @c This is part of the GNU Emacs Lisp Reference Manual.
-@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999
-@c   Free Software Foundation, Inc.
+@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2001, 2002,
+@c   2003, 2004, 2005, 2006, 2007  Free Software Foundation, Inc.
 @c See the file elisp.texi for copying conditions.
 @setfilename ../info/commands
 @node Command Loop, Keymaps, Minibuffers, Top
@@ -74,15 +74,15 @@ character causes @dfn{quitting} (@pxref{Quitting}).
 The editor command loop runs this normal hook before each command.  At
 that time, @code{this-command} contains the command that is about to
 run, and @code{last-command} describes the previous command.
-@xref{Hooks}.
+@xref{Command Loop Info}.
 @end defvar
 
 @defvar post-command-hook
 The editor command loop runs this normal hook after each command
 (including commands terminated prematurely by quitting or by errors),
 and also when the command loop is first entered.  At that time,
-@code{this-command} describes the command that just ran, and
-@code{last-command} describes the command before that.  @xref{Hooks}.
+@code{this-command} refers to the command that just ran, and
+@code{last-command} refers to the command before that.
 @end defvar
 
   Quitting is suppressed while running @code{pre-command-hook} and
@@ -116,13 +116,13 @@ controls the reading of arguments for an interactive call.
 
 @node Using Interactive
 @subsection Using @code{interactive}
+@cindex arguments, interactive entry
 
   This section describes how to write the @code{interactive} form that
 makes a Lisp function an interactively-callable command, and how to
-examine a commands's @code{interactive} form.
+examine a command's @code{interactive} form.
 
 @defspec interactive arg-descriptor
-@cindex argument descriptors
 This special form declares that the function in which it appears is a
 command, and that it may therefore be called interactively (via
 @kbd{M-x} or by entering a key sequence bound to it).  The argument
@@ -151,38 +151,6 @@ arguments.  This leads quickly to an error if the command requires one
 or more arguments.
 
 @item
-It may be a Lisp expression that is not a string; then it should be a
-form that is evaluated to get a list of arguments to pass to the
-command.
-@cindex argument evaluation form
-
-If this expression reads keyboard input (this includes using the
-minibuffer), keep in mind that the integer value of point or the mark
-before reading input may be incorrect after reading input.  This is
-because the current buffer may be receiving subprocess output;
-if subprocess output arrives while the command is waiting for input,
-it could relocate point and the mark.
-
-Here's an example of what @emph{not} to do:
-
-@smallexample
-(interactive
- (list (region-beginning) (region-end)
-       (read-string "Foo: " nil 'my-history)))
-@end smallexample
-
-@noindent
-Here's how to avoid the problem, by examining point and the mark only
-after reading the keyboard input:
-
-@smallexample
-(interactive
- (let ((string (read-string "Foo: " nil 'my-history)))
-   (list (region-beginning) (region-end) string)))
-@end smallexample
-
-@item
-@cindex argument prompt
 It may be a string; then its contents should consist of a code character
 followed by a prompt (which some code characters use and some ignore).
 The prompt ends either with the end of the string or with a newline.
@@ -231,17 +199,63 @@ You can use @samp{*} and @samp{@@} together; the order does not matter.
 Actual reading of arguments is controlled by the rest of the prompt
 string (starting with the first character that is not @samp{*} or
 @samp{@@}).
+
+@item
+It may be a Lisp expression that is not a string; then it should be a
+form that is evaluated to get a list of arguments to pass to the
+command.  Usually this form will call various functions to read input
+from the user, most often through the minibuffer (@pxref{Minibuffers})
+or directly from the keyboard (@pxref{Reading Input}).
+
+Providing point or the mark as an argument value is also common, but
+if you do this @emph{and} read input (whether using the minibuffer or
+not), be sure to get the integer values of point or the mark after
+reading.  The current buffer may be receiving subprocess output; if
+subprocess output arrives while the command is waiting for input, it
+could relocate point and the mark.
+
+Here's an example of what @emph{not} to do:
+
+@smallexample
+(interactive
+ (list (region-beginning) (region-end)
+       (read-string "Foo: " nil 'my-history)))
+@end smallexample
+
+@noindent
+Here's how to avoid the problem, by examining point and the mark after
+reading the keyboard input:
+
+@smallexample
+(interactive
+ (let ((string (read-string "Foo: " nil 'my-history)))
+   (list (region-beginning) (region-end) string)))
+@end smallexample
+
+@strong{Warning:} the argument values should not include any data
+types that can't be printed and then read.  Some facilities save
+@code{command-history} in a file to be read in the subsequent
+sessions; if a command's arguments contain a data type that prints
+using @samp{#<@dots{}>} syntax, those facilities won't work.
+
+There are, however, a few exceptions: it is ok to use a limited set of
+expressions such as @code{(point)}, @code{(mark)},
+@code{(region-beginning)}, and @code{(region-end)}, because Emacs
+recognizes them specially and puts the expression (rather than its
+value) into the command history.  To see whether the expression you
+wrote is one of these exceptions, run the command, then examine
+@code{(car command-history)}.
 @end itemize
 
 @cindex examining the @code{interactive} form
 @defun interactive-form function
-This function returns the @code{interactive} form of @var{function}.  If
-@var{function} is a command (@pxref{Interactive Call}), the value is a
-list of the form @code{(interactive @var{spec})}, where @var{spec} is
-the descriptor specification used by the command's @code{interactive}
-form to compute the function's arguments (@pxref{Using Interactive}).
-If @var{function} is not a command, @code{interactive-form} returns
-@code{nil}.
+This function returns the @code{interactive} form of @var{function}.
+If @var{function} is an interactively callable function
+(@pxref{Interactive Call}), the value is the command's
+@code{interactive} form @code{(interactive @var{spec})}, which
+specifies how to compute its arguments.  Otherwise, the value is
+@code{nil}.  If @var{function} is a symbol, its function definition is
+used.
 @end defun
 
 @node Interactive Codes
@@ -328,7 +342,7 @@ The position of point, as an integer (@pxref{Point}).  No I/O.
 
 @item D
 A directory name.  The default is the current default directory of the
-current buffer, @code{default-directory} (@pxref{System Environment}).
+current buffer, @code{default-directory} (@pxref{File Name Expansion}).
 Existing, Completion, Default, Prompt.
 
 @item e
@@ -350,16 +364,25 @@ Prompt.
 @item F
 A file name.  The file need not exist.  Completion, Default, Prompt.
 
+@item G
+A file name.  The file need not exist.  If the user enters just a
+directory name, then the value is just that directory name, with no
+file name within the directory added.  Completion, Default, Prompt.
+
 @item i
 An irrelevant argument.  This code always supplies @code{nil} as
 the argument's value.  No I/O.
 
 @item k
-A key sequence (@pxref{Keymap Terminology}).  This keeps reading events
+A key sequence (@pxref{Key Sequences}).  This keeps reading events
 until a command (or undefined command) is found in the current key
 maps.  The key sequence argument is represented as a string or vector.
 The cursor does not move into the echo area.  Prompt.
 
+If @samp{k} reads a key sequence that ends with a down-event, it also
+reads and discards the following up-event.  You can get access to that
+up-event with the @samp{U} code character.
+
 This kind of input is used by commands such as @code{describe-key} and
 @code{global-set-key}.
 
@@ -379,15 +402,14 @@ method, and returned as a string (@pxref{Input Methods,,, emacs, The GNU
 Emacs Manual}).  Prompt.
 
 @item n
-A number read with the minibuffer.  If the input is not a number, the
-user is asked to try again.  The prefix argument, if any, is not used.
+A number, read with the minibuffer.  If the input is not a number, the
+user has to try again.  @samp{n} never uses the prefix argument.
 Prompt.
 
 @item N
-@cindex raw prefix argument usage
-The numeric prefix argument; but if there is no prefix argument, read a
-number as with @kbd{n}.  Requires a number.  @xref{Prefix Command
-Arguments}.  Prompt.
+The numeric prefix argument; but if there is no prefix argument, read
+a number as with @kbd{n}.  The value is always a number.  @xref{Prefix
+Command Arguments}.  Prompt.
 
 @item p
 @cindex numeric prefix argument usage
@@ -395,6 +417,7 @@ The numeric prefix argument.  (Note that this @samp{p} is lower case.)
 No I/O.
 
 @item P
+@cindex raw prefix argument usage
 The raw prefix argument.  (Note that this @samp{P} is upper case.)  No
 I/O.
 
@@ -416,9 +439,16 @@ character terminates the input.  (Use @kbd{C-q} to include whitespace in
 the string.)  Other characters that normally terminate a symbol (e.g.,
 parentheses and brackets) do not do so here.  Prompt.
 
+@item U
+A key sequence or @code{nil}.  Can be used after a @samp{k} or
+@samp{K} argument to get the up-event that was discarded (if any)
+after @samp{k} or @samp{K} read a down-event.  If no up-event has been
+discarded, @samp{U} provides @code{nil} as the argument.  No I/O.
+
 @item v
-A variable declared to be a user option (i.e., satisfying the predicate
-@code{user-variable-p}).  @xref{High-Level Completion}.  Existing,
+A variable declared to be a user option (i.e., satisfying the
+predicate @code{user-variable-p}).  This reads the variable using
+@code{read-variable}.  @xref{Definition of read-variable}.  Existing,
 Completion, Prompt.
 
 @item x
@@ -428,8 +458,9 @@ Minibuffer}.  Prompt.
 
 @item X
 @cindex evaluated expression argument
-A Lisp form is read as with @kbd{x}, but then evaluated so that its
-value becomes the argument for the command.  Prompt.
+A Lisp form's value.  @samp{X} reads as @samp{x} does, then evaluates
+the form so that its value becomes the argument for the command.
+Prompt.
 
 @item z
 A coding system name (a symbol).  If the user enters null input, the
@@ -529,10 +560,12 @@ realistic example of using @code{commandp}.
 @defun call-interactively command &optional record-flag keys
 This function calls the interactively callable function @var{command},
 reading arguments according to its interactive calling specifications.
-An error is signaled if @var{command} is not a function or if it cannot
-be called interactively (i.e., is not a command).  Note that keyboard
-macros (strings and vectors) are not accepted, even though they are
-considered commands, because they are not functions.
+It returns whatever @var{command} returns.  An error is signaled if
+@var{command} is not a function or if it cannot be called
+interactively (i.e., is not a command).  Note that keyboard macros
+(strings and vectors) are not accepted, even though they are
+considered commands, because they are not functions.  If @var{command}
+is a symbol, then @code{call-interactively} uses its function definition.
 
 @cindex record command history
 If @var{record-flag} is non-@code{nil}, then this command and its
@@ -540,8 +573,11 @@ arguments are unconditionally added to the list @code{command-history}.
 Otherwise, the command is added only if it uses the minibuffer to read
 an argument.  @xref{Command History}.
 
-The argument @var{keys}, if given, specifies the sequence of events to
-supply if the command inquires which events were used to invoke it.
+The argument @var{keys}, if given, should be a vector which specifies
+the sequence of events to supply if the command inquires which events
+were used to invoke it.  If @var{keys} is omitted or @code{nil}, the
+default is the return value of @code{this-command-keys-vector}.
+@xref{Definition of this-command-keys-vector}.
 @end defun
 
 @defun command-execute command &optional record-flag keys special
@@ -552,7 +588,8 @@ callable function or a keyboard macro.
 
 A string or vector as @var{command} is executed with
 @code{execute-kbd-macro}.  A function is passed to
-@code{call-interactively}, along with the optional @var{record-flag}.
+@code{call-interactively}, along with the optional @var{record-flag}
+and @var{keys}.
 
 A symbol is handled by using its function definition in its place.  A
 symbol with an @code{autoload} definition counts as a command if it was
@@ -560,9 +597,6 @@ declared to stand for an interactively callable function.  Such a
 definition is handled by loading the specified library and then
 rechecking the definition of the symbol.
 
-The argument @var{keys}, if given, specifies the sequence of events to
-supply if the command inquires which events were used to invoke it.
-
 The argument @var{special}, if given, means to ignore the prefix
 argument and not clear it.  This is used for executing special events
 (@pxref{Special Events}).
@@ -592,9 +626,9 @@ part of the prompt.
 
 @example
 @group
-(execute-extended-command 1)
+(execute-extended-command 3)
 ---------- Buffer: Minibuffer ----------
-1 M-x forward-word RET
+3 M-x forward-word RET
 ---------- Buffer: Minibuffer ----------
      @result{} t
 @end group
@@ -602,25 +636,23 @@ part of the prompt.
 @end deffn
 
 @defun interactive-p
-This function returns @code{t} if the containing function (the one whose
-code includes the call to @code{interactive-p}) was called
-interactively, with the function @code{call-interactively}.  (It makes
-no difference whether @code{call-interactively} was called from Lisp or
-directly from the editor command loop.)  If the containing function was
-called by Lisp evaluation (or with @code{apply} or @code{funcall}), then
-it was not called interactively.
+This function returns @code{t} if the containing function (the one
+whose code includes the call to @code{interactive-p}) was called in
+direct response to user input.  This means that it was called with the
+function @code{call-interactively}, and that a keyboard macro is
+not running, and that Emacs is not running in batch mode.
+
+If the containing function was called by Lisp evaluation (or with
+@code{apply} or @code{funcall}), then it was not called interactively.
 @end defun
 
-  The most common use of @code{interactive-p} is for deciding whether to
-print an informative message.  As a special exception,
-@code{interactive-p} returns @code{nil} whenever a keyboard macro is
-being run.  This is to suppress the informative messages and speed
-execution of the macro.
-
-  For example:
+  The most common use of @code{interactive-p} is for deciding whether
+to give the user additional visual feedback (such as by printing an
+informative message).  For example:
 
 @example
 @group
+;; @r{Here's the usual way to use @code{interactive-p}.}
 (defun foo ()
   (interactive)
   (when (interactive-p)
@@ -629,6 +661,7 @@ execution of the macro.
 @end group
 
 @group
+;; @r{This function is just to illustrate the behavior.}
 (defun bar ()
   (interactive)
   (setq foobar (list (foo) (interactive-p))))
@@ -642,7 +675,7 @@ execution of the macro.
 
 @group
 ;; @r{Type @kbd{M-x bar}.}
-;; @r{This does not print anything.}
+;; @r{This does not display a message.}
 @end group
 
 @group
@@ -651,10 +684,11 @@ foobar
 @end group
 @end example
 
-  The other way to do this sort of job is to make the command take an
-argument @code{print-message} which should be non-@code{nil} in an
-interactive call, and use the @code{interactive} spec to make sure it is
-non-@code{nil}.  Here's how:
+  If you want to test @emph{only} whether the function was called
+using @code{call-interactively}, add an optional argument
+@code{print-message} which should be non-@code{nil} in an interactive
+call, and use the @code{interactive} spec to make sure it is
+non-@code{nil}.  Here's an example:
 
 @example
 (defun foo (&optional print-message)
@@ -664,10 +698,18 @@ non-@code{nil}.  Here's how:
 @end example
 
 @noindent
-Defined in this way, the function does display the message when
-called from a keyboard macro.
+Defined in this way, the function does display the message when called
+from a keyboard macro.  We use @code{"p"} because the numeric prefix
+argument is never @code{nil}.
 
-  The numeric prefix argument, provided by @samp{p}, is never @code{nil}.
+@defun called-interactively-p
+This function returns @code{t} when the calling function was called
+using @code{call-interactively}.
+
+When possible, instead of using this function, you should use the
+method in the example above; that method makes it possible for a
+caller to ``pretend'' that the function was called interactively.
+@end defun
 
 @node Command Loop Info
 @comment  node-name,  next,  previous,  up
@@ -744,8 +786,13 @@ was specified to run but remapped into another command.
 @defun this-command-keys
 This function returns a string or vector containing the key sequence
 that invoked the present command, plus any previous commands that
-generated the prefix argument for this command.  The value is a string
-if all those events were characters.  @xref{Input Events}.
+generated the prefix argument for this command.  Any events read by the
+command using @code{read-event} without a timeout get tacked on to the end.
+
+However, if the command has called @code{read-key-sequence}, it
+returns the last read key sequence.  @xref{Key Sequence Input}.  The
+value is a string if all events in the sequence were characters that
+fit in a string.  @xref{Input Events}.
 
 @example
 @group
@@ -757,19 +804,19 @@ if all those events were characters.  @xref{Input Events}.
 @end defun
 
 @defun this-command-keys-vector
+@anchor{Definition of this-command-keys-vector}
 Like @code{this-command-keys}, except that it always returns the events
 in a vector, so you don't need to deal with the complexities of storing
 input events in a string (@pxref{Strings of Events}).
 @end defun
 
-@tindex clear-this-command-keys
-@defun clear-this-command-keys
+@defun clear-this-command-keys &optional keep-record
 This function empties out the table of events for
-@code{this-command-keys} to return, and also empties the records that
-the function @code{recent-keys} (@pxref{Recording Input}) will
-subsequently return.  This is useful after reading a password, to
-prevent the password from echoing inadvertently as part of the next
-command in certain cases.
+@code{this-command-keys} to return.  Unless @var{keep-record} is
+non-@code{nil}, it also empties the records that the function
+@code{recent-keys} (@pxref{Recording Input}) will subsequently return.
+This is useful after reading a password, to prevent the password from
+echoing inadvertently as part of the next command in certain cases.
 @end defun
 
 @defvar last-nonmenu-event
@@ -810,33 +857,37 @@ Usually this is the frame that was selected when the event was
 generated, but if that frame has redirected input focus to another
 frame, the value is the frame to which the event was redirected.
 @xref{Input Focus}.
+
+If the last event came from a keyboard macro, the value is @code{macro}.
 @end defvar
 
 @node Adjusting Point
 @section Adjusting Point After Commands
-
-  It is not easy to display a value of point in the middle of a sequence
-of text that has the @code{display} or @code{composition} property.  So
-after a command finishes and returns to the command loop, if point is
-within such a sequence, the command loop normally moves point to the
-edge of the sequence.
+@cindex adjusting point
+@cindex invisible/intangible text, and point
+@cindex @code{display} property, and point display
+@cindex @code{composition} property, and point display
+
+  It is not easy to display a value of point in the middle of a
+sequence of text that has the @code{display}, @code{composition} or
+@code{intangible} property, or is invisible.  Therefore, after a
+command finishes and returns to the command loop, if point is within
+such a sequence, the command loop normally moves point to the edge of
+the sequence.
 
   A command can inhibit this feature by setting the variable
 @code{disable-point-adjustment}:
 
 @defvar disable-point-adjustment
-@tindex disable-point-adjustment
-If this variable is non-@code{nil} when a command returns to the command
-loop, then the command loop does not check for text properties such as
-@code{display} and @code{composition}, and does not move point out of
-sequences that have these properties.
+If this variable is non-@code{nil} when a command returns to the
+command loop, then the command loop does not check for those text
+properties, and does not move point out of sequences that have them.
 
 The command loop sets this variable to @code{nil} before each command,
 so if a command sets it, the effect applies only to that command.
 @end defvar
 
 @defvar global-disable-point-adjustment
-@tindex global-disable-point-adjustment
 If you set this variable to a non-@code{nil} value, the feature of
 moving point out of these sequences is completely turned off.
 @end defvar
@@ -873,7 +924,7 @@ the current Emacs session.  If a symbol has not yet been so used,
 * Repeat Events::               Double and triple click (or drag, or down).
 * Motion Events::              Just moving the mouse, not pushing a button.
 * Focus Events::               Moving the mouse between frames.
-* Misc Events::                 Other events window systems can generate.
+* Misc Events::                 Other events the system can generate.
 * Event Examples::             Examples of the lists for mouse events.
 * Classifying Events::         Finding the modifier keys in an event symbol.
                                Event types.
@@ -884,6 +935,7 @@ the current Emacs session.  If a symbol has not yet been so used,
 
 @node Keyboard Events
 @subsection Keyboard Events
+@cindex keyboard events
 
 There are two kinds of input you can get from the keyboard: ordinary
 keys, and function keys.  Ordinary keys correspond to characters; the
@@ -1041,7 +1093,7 @@ Lisp programs by representing the former as the integer 9, and the
 latter as the symbol @code{tab}.
 
 Most of the time, it's not useful to distinguish the two.  So normally
-@code{function-key-map} (@pxref{Translating Input}) is set up to map
+@code{function-key-map} (@pxref{Translation Keymaps}) is set up to map
 @code{tab} into 9.  Thus, a key binding for character code 9 (the
 character @kbd{C-i}) also applies to @code{tab}.  Likewise for the other
 symbols in this group.  The function @code{read-char} likewise converts
@@ -1096,7 +1148,7 @@ arguments to the key-binding lookup and modification functions.
 
 Emacs supports four kinds of mouse events: click events, drag events,
 button-down events, and motion events.  All mouse events are represented
-as lists.  The @acronym{CAR} of the list is the event type; this says which
+as lists.  The @sc{car} of the list is the event type; this says which
 mouse button was involved, and which modifier keys were used with it.
 The event type can also distinguish double or triple button presses
 (@pxref{Repeat Events}).  The rest of the list elements give position
@@ -1144,18 +1196,15 @@ describe events by their types; thus, if there is a key binding for
 @item @var{position}
 This is the position where the mouse click occurred.  The actual
 format of @var{position} depends on what part of a window was clicked
-on.  The various formats are described below.
-
-@item @var{click-count}
-This is the number of rapid repeated presses so far of the same mouse
-button.  @xref{Repeat Events}.
-@end table
+on.
 
 For mouse click events in the text area, mode line, header line, or in
 the marginal areas, @var{position} has this form:
 
 @example
-(@var{window} @var{pos-or-area} (@var{x} . @var{y}) @var{timestamp} @var{object} @var{text-pos} (@var{col} . @var{row}))
+(@var{window} @var{pos-or-area} (@var{x} . @var{y}) @var{timestamp}
+ @var{object} @var{text-pos} (@var{col} . @var{row})
+ @var{image} (@var{dx} . @var{dy}) (@var{width} . @var{height}))
 @end example
 
 @table @asis
@@ -1169,9 +1218,15 @@ which the click occurred.  It is one of the symbols @code{mode-line},
 @code{header-line}, @code{vertical-line}, @code{left-margin},
 @code{right-margin}, @code{left-fringe}, or @code{right-fringe}.
 
+In one special case, @var{pos-or-area} is a list containing a symbol (one
+of the symbols listed above) instead of just the symbol.  This happens
+after the imaginary prefix keys for the event are inserted into the
+input stream.  @xref{Key Sequence Input}.
+
+
 @item @var{x}, @var{y}
-These are the pixel-denominated coordinates of the click, relative to
-the top left corner of @var{window}, which is @code{(0 . 0)}.  
+These are the pixel coordinates of the click, relative to
+the top left corner of @var{window}, which is @code{(0 . 0)}.
 For the mode or header line, @var{y} does not have meaningful data.
 For the vertical line, @var{x} does not have meaningful data.
 
@@ -1179,17 +1234,20 @@ For the vertical line, @var{x} does not have meaningful data.
 This is the time at which the event occurred, in milliseconds.
 
 @item @var{object}
-This is the object on which the click occurred.  It is either nil (for
-a click in a marginal area with no associated object, or it has the
-form (@var{string} . @var{string-pos}).
+This is the object on which the click occurred.  It is either
+@code{nil} if there is no string property, or it has the form
+(@var{string} . @var{string-pos}) when there is a string-type text
+property at the click position.
 
+@table @asis
 @item @var{string}
 This is the string on which the click occurred, including any
-properties.  
+properties.
 
 @item @var{string-pos}
 This is the position in the string on which the click occurred,
 relevant if properties at the click need to be looked up.
+@end table
 
 @item @var{text-pos}
 For clicks on a marginal area or on a fringe, this is the buffer
@@ -1201,8 +1259,24 @@ the window.
 These are the actual coordinates of the glyph under the @var{x},
 @var{y} position, possibly padded with default character width
 glyphs if @var{x} is beyond the last glyph on the line.
-@end table
 
+@item @var{image}
+This is the image object on which the click occurred.  It is either
+@code{nil} if there is no image at the position clicked on, or it is
+an image object as returned by @code{find-image} if click was in an image.
+
+@item @var{dx}, @var{dy}
+These are the pixel coordinates of the click, relative to
+the top left corner of @var{object}, which is @code{(0 . 0)}.  If
+@var{object} is @code{nil}, the coordinates are relative to the top
+left corner of the character glyph clicked on.
+
+@item @var{width}, @var{height}
+These are the pixel width and height of @var{object} or, if this is
+@code{nil}, those of the character glyph clicked on.
+@end table
+@sp 1
 For mouse clicks on a scroll-bar, @var{position} has this form:
 
 @example
@@ -1233,10 +1307,10 @@ of the symbols @code{above-handle}, @code{handle}, @code{below-handle},
 @code{up}, @code{down}, @code{top}, @code{bottom}, and @code{end-scroll}.
 @end table
 
-In one special case, @var{buffer-pos} is a list containing a symbol (one
-of the symbols listed above) instead of just the symbol.  This happens
-after the imaginary prefix keys for the event are inserted into the
-input stream.  @xref{Key Sequence Input}.
+@item @var{click-count}
+This is the number of rapid repeated presses so far of the same mouse
+button.  @xref{Repeat Events}.
+@end table
 
 @node Drag Events
 @subsection Drag Events
@@ -1252,19 +1326,18 @@ position and the final position, like this:
 
 @example
 (@var{event-type}
- (@var{window1} @var{buffer-pos1} (@var{x1} . @var{y1}) @var{timestamp1})
- (@var{window2} @var{buffer-pos2} (@var{x2} . @var{y2}) @var{timestamp2})
- @var{click-count})
+ (@var{window1} START-POSITION)
+ (@var{window2} END-POSITION))
 @end example
 
 For a drag event, the name of the symbol @var{event-type} contains the
-prefix @samp{drag-}.  For example, dragging the mouse with button 2 held
-down generates a @code{drag-mouse-2} event.  The second and third
-elements of the event give the starting and ending position of the drag.
-Aside from that, the data have the same meanings as in a click event
-(@pxref{Click Events}).  You can access the second element of any mouse
-event in the same way, with no need to distinguish drag events from
-others.
+prefix @samp{drag-}.  For example, dragging the mouse with button 2
+held down generates a @code{drag-mouse-2} event.  The second and third
+elements of the event give the starting and ending position of the
+drag.  They have the same form as @var{position} in a click event
+(@pxref{Click Events}) that is not on the scroll bar part of the
+window.  You can access the second element of any mouse event in the
+same way, with no need to distinguish drag events from others.
 
 The @samp{drag-} prefix follows the modifier key prefixes such as
 @samp{C-} and @samp{M-}.
@@ -1374,22 +1447,25 @@ the value is 3 or greater.  If @var{event} is an ordinary mouse event
 (not a repeat event), the value is 1.
 @end defun
 
-@defvar double-click-fuzz
+@defopt double-click-fuzz
 To generate repeat events, successive mouse button presses must be at
 approximately the same screen position.  The value of
 @code{double-click-fuzz} specifies the maximum number of pixels the
-mouse may be moved between two successive clicks to make a
-double-click.
-@end defvar
+mouse may be moved (horizontally or vertically) between two successive
+clicks to make a double-click.
+
+This variable is also the threshold for motion of the mouse to count
+as a drag.
+@end defopt
 
-@defvar double-click-time
+@defopt double-click-time
 To generate repeat events, the number of milliseconds between
 successive button presses must be less than the value of
 @code{double-click-time}.  Setting @code{double-click-time} to
 @code{nil} disables multi-click detection entirely.  Setting it to
 @code{t} removes the time limit; Emacs then detects multi-clicks by
 position only.
-@end defvar
+@end defopt
 
 @node Motion Events
 @subsection Motion Events
@@ -1401,7 +1477,7 @@ of the mouse without any button activity.  Mouse motion events are
 represented by lists that look like this:
 
 @example
-(mouse-movement (@var{window} @var{buffer-pos} (@var{x} . @var{y}) @var{timestamp}))
+(mouse-movement (POSITION))
 @end example
 
 The second element of the list describes the current position of the
@@ -1449,9 +1525,9 @@ so that the focus event comes either before or after the multi-event key
 sequence, and not within it.
 
 @node Misc Events
-@subsection Miscellaneous Window System Events
+@subsection Miscellaneous System Events
 
-A few other event types represent occurrences within the window system.
+A few other event types represent occurrences within the system.
 
 @table @code
 @cindex @code{delete-frame} event
@@ -1475,21 +1551,21 @@ This kind of event indicates that the user deiconified @var{frame} using
 the window manager.  Its standard definition is @code{ignore}; since the
 frame has already been made visible, Emacs has no work to do.
 
-@cindex @code{mouse-wheel} event
-@item (mouse-wheel @var{position} @var{delta})
-This kind of event is generated by moving a wheel on a mouse (such as
-the MS Intellimouse).  Its effect is typically a kind of scroll or zoom.
-
-The element @var{delta} describes the amount and direction of the wheel
-rotation.  Its absolute value is the number of increments by which the
-wheel was rotated.  A negative @var{delta} indicates that the wheel was
-rotated backwards, towards the user, and a positive @var{delta}
-indicates that the wheel was rotated forward, away from the user.
+@cindex @code{wheel-up} event
+@cindex @code{wheel-down} event
+@item (wheel-up @var{position})
+@item (wheel-down @var{position})
+These kinds of event are generated by moving a mouse wheel.  Their
+usual meaning is a kind of scroll or zoom.
 
 The element @var{position} is a list describing the position of the
 event, in the same format as used in a mouse-click event.
 
-This kind of event is generated only on some kinds of systems.
+This kind of event is generated only on some kinds of systems. On some
+systems, @code{mouse-4} and @code{mouse-5} are used instead.  For
+portable code, use the variables @code{mouse-wheel-up-event} and
+@code{mouse-wheel-down-event} defined in @file{mwheel.el} to determine
+what event types to expect for the mouse wheel.
 
 @cindex @code{drag-n-drop} event
 @item (drag-n-drop @var{position} @var{files})
@@ -1504,6 +1580,49 @@ The usual way to handle this event is by visiting these files.
 
 This kind of event is generated, at present, only on some kinds of
 systems.
+
+@cindex @code{help-echo} event
+@item help-echo
+This kind of event is generated when a mouse pointer moves onto a
+portion of buffer text which has a @code{help-echo} text property.
+The generated event has this form:
+
+@example
+(help-echo @var{frame} @var{help} @var{window} @var{object} @var{pos})
+@end example
+
+@noindent
+The precise meaning of the event parameters and the way these
+parameters are used to display the help-echo text are described in
+@ref{Text help-echo}.
+
+@cindex @code{sigusr1} event
+@cindex @code{sigusr2} event
+@cindex user signals
+@item sigusr1
+@itemx sigusr2
+These events are generated when the Emacs process receives
+the signals @code{SIGUSR1} and @code{SIGUSR2}.  They contain no
+additional data because signals do not carry additional information.
+
+To catch a user signal, bind the corresponding event to an interactive
+command in the @code{special-event-map} (@pxref{Active Keymaps}).
+The command is called with no arguments, and the specific signal event is
+available in @code{last-input-event}.  For example:
+
+@smallexample
+(defun sigusr-handler ()
+  (interactive)
+  (message "Caught signal %S" last-input-event))
+
+(define-key special-event-map [sigusr1] 'sigusr-handler)
+@end smallexample
+
+To test the signal handler, you can make Emacs send a signal to itself:
+
+@smallexample
+(signal-process (emacs-pid) 'sigusr1)
+@end smallexample
 @end table
 
   If one of these events arrives in the middle of a key sequence---that
@@ -1543,6 +1662,16 @@ into another window.  That produces a pair of events like these:
                    -453816))
 @end smallexample
 
+To handle a SIGUSR1 signal, define an interactive function, and
+bind it to the @code{signal usr1} event sequence:
+
+@smallexample
+(defun usr1-handler ()
+  (interactive)
+  (message "Got USR1 signal"))
+(global-set-key [signal usr1] 'usr1-handler)
+@end smallexample
+
 @node Classifying Events
 @subsection Classifying Events
 @cindex event type
@@ -1551,7 +1680,7 @@ into another window.  That produces a pair of events like these:
 key binding purposes.  For a keyboard event, the event type equals the
 event value; thus, the event type for a character is the character, and
 the event type for a function key symbol is the symbol itself.  For
-events that are lists, the event type is the symbol in the @acronym{CAR} of
+events that are lists, the event type is the symbol in the @sc{car} of
 the list.  Thus, the event type is always a symbol or a character.
 
   Two events of the same type are equivalent where key bindings are
@@ -1572,16 +1701,22 @@ This function returns a list of the modifiers that @var{event} has.  The
 modifiers are symbols; they include @code{shift}, @code{control},
 @code{meta}, @code{alt}, @code{hyper} and @code{super}.  In addition,
 the modifiers list of a mouse event symbol always contains one of
-@code{click}, @code{drag}, and @code{down}.
+@code{click}, @code{drag}, and @code{down}.  For double or triple
+events, it also contains @code{double} or @code{triple}.
 
-The argument @var{event} may be an entire event object, or just an event
-type.
+The argument @var{event} may be an entire event object, or just an
+event type.  If @var{event} is a symbol that has never been used in an
+event that has been read as input in the current Emacs session, then
+@code{event-modifiers} can return @code{nil}, even when @var{event}
+actually has modifiers.
 
 Here are some examples:
 
 @example
 (event-modifiers ?a)
      @result{} nil
+(event-modifiers ?A)
+     @result{} (shift)
 (event-modifiers ?\C-a)
      @result{} (control)
 (event-modifiers ?\C-%)
@@ -1606,7 +1741,8 @@ but the event symbol name itself does not contain @samp{click}.
 
 @defun event-basic-type event
 This function returns the key or mouse button that @var{event}
-describes, with all modifiers removed.  For example:
+describes, with all modifiers removed.  The @var{event} argument is as
+in @code{event-modifiers}.  For example:
 
 @example
 (event-basic-type ?a)
@@ -1635,7 +1771,8 @@ event.
 
 @defun event-convert-list list
 This function converts a list of modifier names and a basic event type
-to an event type which specifies all of them.  For example,
+to an event type which specifies all of them.  The basic event type
+must be the last element of the list.  For example,
 
 @example
 (event-convert-list '(control ?a))
@@ -1649,8 +1786,7 @@ to an event type which specifies all of them.  For example,
 
 @node Accessing Events
 @subsection Accessing Events
-@cindex mouse events, accessing the data
-@cindex accessing data of mouse events
+@cindex mouse events, data in
 
   This section describes convenient functions for accessing the data in
 a mouse button or motion event.
@@ -1659,7 +1795,9 @@ a mouse button or motion event.
 mouse-button event, as a list of this form:
 
 @example
-(@var{window} @var{pos-or-area} (@var{x} . @var{y}) @var{timestamp} @var{object} @var{text-pos} (@var{col} . @var{row}))
+(@var{window} @var{pos-or-area} (@var{x} . @var{y}) @var{timestamp}
+ @var{object} @var{text-pos} (@var{col} . @var{row})
+ @var{image} (@var{dx} . @var{dy}) (@var{width} . @var{height}))
 @end example
 
 @defun event-start event
@@ -1680,7 +1818,7 @@ position such events have.
 @end defun
 
 @cindex mouse position list, accessing
-  These seven functions take a position list as described above, and
+  These functions take a position list as described above, and
 return various parts of it.
 
 @defun posn-window position
@@ -1688,9 +1826,9 @@ Return the window that @var{position} is in.
 @end defun
 
 @defun posn-area position
-Return the window area recorded in @var{position}.  It returns nil
+Return the window area recorded in @var{position}.  It returns @code{nil}
 when the event occurred in the text area of the window; otherwise, it
-is a symbol identifying the area in which the the event occurred.
+is a symbol identifying the area in which the event occurred.
 @end defun
 
 @defun posn-point position
@@ -1700,35 +1838,97 @@ this is an integer specifying a buffer position.  Otherwise, the value
 is undefined.
 @end defun
 
-@defun posn-timestamp
-Return the timestamp in @var{position}.  This is the time at which the
-event occurred, in milliseconds.
-@end defun
-
 @defun posn-x-y position
-Return the pixel-based x and y coordinates in @var{position}, as a cons
-cell @code{(@var{x} . @var{y})}.
+Return the pixel-based x and y coordinates in @var{position}, as a
+cons cell @code{(@var{x} . @var{y})}.  These coordinates are relative
+to the window given by @code{posn-window}.
+
+This example shows how to convert these window-relative coordinates
+into frame-relative coordinates:
+
+@example
+(defun frame-relative-coordinates (position)
+  "Return frame-relative coordinates from POSITION."
+  (let* ((x-y (posn-x-y position))
+         (window (posn-window position))
+         (edges (window-inside-pixel-edges window)))
+    (cons (+ (car x-y) (car edges))
+          (+ (cdr x-y) (cadr edges)))))
+@end example
 @end defun
 
 @defun posn-col-row position
-Return the row and column (in units of frame default characters) of
-@var{position}, as a cons cell @code{(@var{col} . @var{row})}.  These
-are computed from the @var{x} and @var{y} values actually found in
-@var{position}.
+Return the row and column (in units of the frame's default character
+height and width) of @var{position}, as a cons cell @code{(@var{col} .
+@var{row})}.  These are computed from the @var{x} and @var{y} values
+actually found in @var{position}.
 @end defun
 
 @defun posn-actual-col-row position
 Return the actual row and column in @var{position}, as a cons cell
 @code{(@var{col} . @var{row})}.  The values are the actual row number
-in the window, and the actual character number in that row.  Return
-nil if @var{position} does not include the actual positions; in that
-case, @code{posn-col-row} can be used to get approximate values.
+in the window, and the actual character number in that row.  It returns
+@code{nil} if @var{position} does not include actual positions values.
+You can use @code{posn-col-row} to get approximate values.
+@end defun
+
+@defun posn-string position
+Return the string object in @var{position}, either @code{nil}, or a
+cons cell @code{(@var{string} . @var{string-pos})}.
+@end defun
+
+@defun posn-image position
+Return the image object in @var{position}, either @code{nil}, or an
+image @code{(image ...)}.
+@end defun
+
+@defun posn-object position
+Return the image or string object in @var{position}, either
+@code{nil}, an image @code{(image ...)}, or a cons cell
+@code{(@var{string} . @var{string-pos})}.
+@end defun
+
+@defun posn-object-x-y position
+Return the pixel-based x and y coordinates relative to the upper left
+corner of the object in @var{position} as a cons cell @code{(@var{dx}
+. @var{dy})}.  If the @var{position} is a buffer position, return the
+relative position in the character at that position.
+@end defun
+
+@defun posn-object-width-height position
+Return the pixel width and height of the object in @var{position} as a
+cons cell @code{(@var{width} . @var{height})}.  If the @var{position}
+is a buffer position, return the size of the character at that position.
 @end defun
 
-@cindex mouse event, timestamp
 @cindex timestamp of a mouse event
 @defun posn-timestamp position
-Return the timestamp in @var{position}.
+Return the timestamp in @var{position}.  This is the time at which the
+event occurred, in milliseconds.
+@end defun
+
+  These functions compute a position list given particular buffer
+position or screen position.  You can access the data in this position
+list with the functions described above.
+
+@defun posn-at-point &optional pos window
+This function returns a position list for position @var{pos} in
+@var{window}.  @var{pos} defaults to point in @var{window};
+@var{window} defaults to the selected window.
+
+@code{posn-at-point} returns @code{nil} if @var{pos} is not visible in
+@var{window}.
+@end defun
+
+@defun posn-at-x-y x y &optional frame-or-window whole
+This function returns position information corresponding to pixel
+coordinates @var{x} and @var{y} in a specified frame or window,
+@var{frame-or-window}, which defaults to the selected window.
+The coordinates @var{x} and @var{y} are relative to the
+frame or window used.
+If @var{whole} is @code{nil}, the coordinates are relative
+to the window text area, otherwise they are relative to
+the entire window area including scroll bars, margins and fringes.
 @end defun
 
   These functions are useful for decoding scroll bar events.
@@ -1885,6 +2085,8 @@ following the recommendations at the beginning of this section.
 
 @node Reading Input
 @section Reading Input
+@cindex read input
+@cindex keyboard input
 
   The editor command loop reads key sequences using the function
 @code{read-key-sequence}, which uses @code{read-event}.  These and other
@@ -1892,14 +2094,14 @@ functions for event input are also available for use in Lisp programs.
 See also @code{momentary-string-display} in @ref{Temporary Displays},
 and @code{sit-for} in @ref{Waiting}.  @xref{Terminal Input}, for
 functions and variables for controlling terminal input modes and
-debugging terminal input.  @xref{Translating Input}, for features you
-can use for translating or modifying input events while reading them.
+debugging terminal input.
 
   For higher-level input facilities, see @ref{Minibuffers}.
 
 @menu
 * Key Sequence Input::         How to read one key sequence.
 * Reading One Event::          How to read just one event.
+* Event Mod::                   How Emacs modifies events as they are read.
 * Invoking the Input Method::   How reading an event uses the input method.
 * Quoted Character Input::     Asking the user to specify a character.
 * Event Input Misc::           How to reread or throw away input events.
@@ -1913,12 +2115,13 @@ can use for translating or modifying input events while reading them.
 @code{read-key-sequence}.  Lisp programs can also call this function;
 for example, @code{describe-key} uses it to read the key to describe.
 
-@defun read-key-sequence prompt
-@cindex key sequence
+@defun read-key-sequence prompt &optional continue-echo dont-downcase-last switch-frame-ok command-loop
 This function reads a key sequence and returns it as a string or
 vector.  It keeps reading events until it has accumulated a complete key
 sequence; that is, enough to specify a non-prefix command using the
-currently active keymaps.
+currently active keymaps.  (Remember that a key sequence that starts
+with a mouse event is read using the keymaps of the buffer in the
+window that the mouse was in, not the current buffer.)
 
 If the events are all characters and all can fit in a string, then
 @code{read-key-sequence} returns a string (@pxref{Strings of Events}).
@@ -1926,11 +2129,34 @@ Otherwise, it returns a vector, since a vector can hold all kinds of
 events---characters, symbols, and lists.  The elements of the string or
 vector are the events in the key sequence.
 
-The argument @var{prompt} is either a string to be displayed in the echo
-area as a prompt, or @code{nil}, meaning not to display a prompt.
+Reading a key sequence includes translating the events in various
+ways.  @xref{Translation Keymaps}.
 
-In the example below, the prompt @samp{?} is displayed in the echo area,
-and the user types @kbd{C-x C-f}.
+The argument @var{prompt} is either a string to be displayed in the
+echo area as a prompt, or @code{nil}, meaning not to display a prompt.
+The argument @var{continue-echo}, if non-@code{nil}, means to echo
+this key as a continuation of the previous key.
+
+Normally any upper case event is converted to lower case if the
+original event is undefined and the lower case equivalent is defined.
+The argument @var{dont-downcase-last}, if non-@code{nil}, means do not
+convert the last event to lower case.  This is appropriate for reading
+a key sequence to be defined.
+
+The argument @var{switch-frame-ok}, if non-@code{nil}, means that this
+function should process a @code{switch-frame} event if the user
+switches frames before typing anything.  If the user switches frames
+in the middle of a key sequence, or at the start of the sequence but
+@var{switch-frame-ok} is @code{nil}, then the event will be put off
+until after the current key sequence.
+
+The argument @var{command-loop}, if non-@code{nil}, means that this
+key sequence is being read by something that will read commands one
+after another.  It should be @code{nil} if the caller will read just
+one key sequence.
+
+In the following example, Emacs displays the prompt @samp{?} in the
+echo area, and then the user types @kbd{C-x C-f}.
 
 @example
 (read-key-sequence "?")
@@ -1949,7 +2175,7 @@ typed while reading with this function works like any other character,
 and does not set @code{quit-flag}.  @xref{Quitting}.
 @end defun
 
-@defun read-key-sequence-vector prompt
+@defun read-key-sequence-vector prompt &optional continue-echo dont-downcase-last switch-frame-ok command-loop
 This is like @code{read-key-sequence} except that it always
 returns the key sequence as a vector, never as a string.
 @xref{Strings of Events}.
@@ -1957,10 +2183,10 @@ returns the key sequence as a vector, never as a string.
 
 @cindex upper case key sequence
 @cindex downcasing in @code{lookup-key}
-If an input character is an upper-case letter and has no key binding,
-but its lower-case equivalent has one, then @code{read-key-sequence}
-converts the character to lower case.  Note that @code{lookup-key} does
-not perform case conversion in this way.
+If an input character is upper-case (or has the shift modifier) and
+has no key binding, but its lower-case equivalent has one, then
+@code{read-key-sequence} converts the character to lower case.  Note
+that @code{lookup-key} does not perform case conversion in this way.
 
 The function @code{read-key-sequence} also transforms some mouse events.
 It converts unbound drag events into click events, and discards unbound
@@ -1981,7 +2207,7 @@ same symbol that would normally represent that combination of mouse
 button and modifier keys.  The information about the window part is kept
 elsewhere in the event---in the coordinates.  But
 @code{read-key-sequence} translates this information into imaginary
-``prefix keys'', all of which are symbols: @code{header-line},
+``prefix keys,'' all of which are symbols: @code{header-line},
 @code{horizontal-scroll-bar}, @code{menu-bar}, @code{mode-line},
 @code{vertical-line}, and @code{vertical-scroll-bar}.  You can define
 meanings for mouse clicks in special window parts by defining key
@@ -2005,11 +2231,6 @@ this Emacs session.  This includes key sequences read from the terminal
 and key sequences read from keyboard macros being executed.
 @end defvar
 
-@defvar num-nonmacro-input-events
-This variable holds the total number of input events received so far
-from the terminal---not counting those generated by keyboard macros.
-@end defvar
-
 @node Reading One Event
 @subsection Reading One Event
 @cindex reading a single event
@@ -2018,7 +2239,9 @@ from the terminal---not counting those generated by keyboard macros.
   The lowest level functions for command input are those that read a
 single event.
 
-@defun read-event &optional prompt inherit-input-method
+None of the three functions below suppresses quitting.
+
+@defun read-event &optional prompt inherit-input-method seconds
 This function reads and returns the next event of command input, waiting
 if necessary until an event is available.  Events can come directly from
 the user or from a keyboard macro.
@@ -2039,8 +2262,26 @@ If @code{cursor-in-echo-area} is non-@code{nil}, then @code{read-event}
 moves the cursor temporarily to the echo area, to the end of any message
 displayed there.  Otherwise @code{read-event} does not move the cursor.
 
-If @code{read-event} gets an event that is defined as a help character, in
-some cases @code{read-event} processes the event directly without
+If @var{seconds} is non-@code{nil}, it should be a number specifying
+the maximum time to wait for input, in seconds.  If no input arrives
+within that time, @code{read-event} stops waiting and returns
+@code{nil}.  A floating-point value for @var{seconds} means to wait
+for a fractional number of seconds.  Some systems support only a whole
+number of seconds; on these systems, @var{seconds} is rounded down.
+If @var{seconds} is @code{nil}, @code{read-event} waits as long as
+necessary for input to arrive.
+
+If @var{seconds} is @code{nil}, Emacs is considered idle while waiting
+for user input to arrive.  Idle timers---those created with
+@code{run-with-idle-timer} (@pxref{Idle Timers})---can run during this
+period.  However, if @var{seconds} is non-@code{nil}, the state of
+idleness remains unchanged.  If Emacs is non-idle when
+@code{read-event} is called, it remains non-idle throughout the
+operation of @code{read-event}; if Emacs is idle (which can happen if
+the call happens inside an idle timer), it remains idle.
+
+If @code{read-event} gets an event that is defined as a help character,
+then in some cases @code{read-event} processes the event directly without
 returning.  @xref{Help Functions}.  Certain other events, called
 @dfn{special events}, are also processed directly within
 @code{read-event} (@pxref{Special Events}).
@@ -2056,7 +2297,7 @@ right-arrow function key:
 @end example
 @end defun
 
-@defun read-char &optional prompt inherit-input-method
+@defun read-char &optional prompt inherit-input-method seconds
 This function reads and returns a character of command input.  If the
 user generates an event which is not a character (i.e. a mouse click or
 function key event), @code{read-char} signals an error.  The arguments
@@ -2088,13 +2329,99 @@ the echo area.
 @end example
 @end defun
 
-@defun read-char-exclusive &optional prompt inherit-input-method
+@defun read-char-exclusive &optional prompt inherit-input-method seconds
 This function reads and returns a character of command input.  If the
 user generates an event which is not a character,
 @code{read-char-exclusive} ignores it and reads another event, until it
 gets a character.  The arguments work as in @code{read-event}.
 @end defun
 
+@defvar num-nonmacro-input-events
+This variable holds the total number of input events received so far
+from the terminal---not counting those generated by keyboard macros.
+@end defvar
+
+@node Event Mod
+@subsection Modifying and Translating Input Events
+
+  Emacs modifies every event it reads according to
+@code{extra-keyboard-modifiers}, then translates it through
+@code{keyboard-translate-table} (if applicable), before returning it
+from @code{read-event}.
+
+@c Emacs 19 feature
+@defvar extra-keyboard-modifiers
+This variable lets Lisp programs ``press'' the modifier keys on the
+keyboard.  The value is a character.  Only the modifiers of the
+character matter.  Each time the user types a keyboard key, it is
+altered as if those modifier keys were held down.  For instance, if
+you bind @code{extra-keyboard-modifiers} to @code{?\C-\M-a}, then all
+keyboard input characters typed during the scope of the binding will
+have the control and meta modifiers applied to them.  The character
+@code{?\C-@@}, equivalent to the integer 0, does not count as a control
+character for this purpose, but as a character with no modifiers.
+Thus, setting @code{extra-keyboard-modifiers} to zero cancels any
+modification.
+
+When using a window system, the program can ``press'' any of the
+modifier keys in this way.  Otherwise, only the @key{CTL} and @key{META}
+keys can be virtually pressed.
+
+Note that this variable applies only to events that really come from
+the keyboard, and has no effect on mouse events or any other events.
+@end defvar
+
+@defvar keyboard-translate-table
+This variable is the translate table for keyboard characters.  It lets
+you reshuffle the keys on the keyboard without changing any command
+bindings.  Its value is normally a char-table, or else @code{nil}.
+(It can also be a string or vector, but this is considered obsolete.)
+
+If @code{keyboard-translate-table} is a char-table
+(@pxref{Char-Tables}), then each character read from the keyboard is
+looked up in this char-table.  If the value found there is
+non-@code{nil}, then it is used instead of the actual input character.
+
+Note that this translation is the first thing that happens to a
+character after it is read from the terminal.  Record-keeping features
+such as @code{recent-keys} and dribble files record the characters after
+translation.
+
+Note also that this translation is done before the characters are
+supplied to input methods (@pxref{Input Methods}).  Use
+@code{translation-table-for-input} (@pxref{Translation of Characters}),
+if you want to translate characters after input methods operate.
+@end defvar
+
+@defun keyboard-translate from to
+This function modifies @code{keyboard-translate-table} to translate
+character code @var{from} into character code @var{to}.  It creates
+the keyboard translate table if necessary.
+@end defun
+
+  Here's an example of using the @code{keyboard-translate-table} to
+make @kbd{C-x}, @kbd{C-c} and @kbd{C-v} perform the cut, copy and paste
+operations:
+
+@example
+(keyboard-translate ?\C-x 'control-x)
+(keyboard-translate ?\C-c 'control-c)
+(keyboard-translate ?\C-v 'control-v)
+(global-set-key [control-x] 'kill-region)
+(global-set-key [control-c] 'kill-ring-save)
+(global-set-key [control-v] 'yank)
+@end example
+
+@noindent
+On a graphical terminal that supports extended @acronym{ASCII} input,
+you can still get the standard Emacs meanings of one of those
+characters by typing it with the shift key.  That makes it a different
+character as far as keyboard translation is concerned, but it has the
+same usual meaning.
+
+  @xref{Translation Keymaps}, for mechanisms that translate event sequences
+at the level of @code{read-key-sequence}.
+
 @node Invoking the Input Method
 @subsection Invoking the Input Method
 
@@ -2152,7 +2479,10 @@ The command @code{quoted-insert} uses this function.
 This function is like @code{read-char}, except that if the first
 character read is an octal digit (0-7), it reads any number of octal
 digits (but stopping if a non-octal digit is found), and returns the
-character represented by that numeric character code.
+character represented by that numeric character code.  If the
+character that terminates the sequence of octal digits is @key{RET},
+it is discarded.  Any other terminating character is used as input
+after this function returns.
 
 Quitting is suppressed when the first character is read, so that the
 user can enter a @kbd{C-g}.  @xref{Quitting}.
@@ -2169,7 +2499,7 @@ is 127 in decimal).
 
 @group
 ---------- Echo Area ----------
-What character-@kbd{177}
+What character @kbd{1 7 7}-
 ---------- Echo Area ----------
 
      @result{} 127
@@ -2212,6 +2542,12 @@ put them in @code{unread-command-events} is to use
 
 Normally you add events to the front of this list, so that the events
 most recently unread will be reread first.
+
+Events read from this list are not normally added to the current
+command's key sequence (as returned by e.g. @code{this-command-keys}),
+as the events will already have been added once as they were read for
+the first time.  An element of the form @code{(@code{t} . @var{event})}
+forces @var{event} to be added to the current command's key sequence.
 @end defvar
 
 @defun listify-key-sequence key
@@ -2221,7 +2557,7 @@ individual events, which you can put in @code{unread-command-events}.
 
 @defvar unread-command-char
 This variable holds a character to be read as command input.
-A value of -1 means ``empty''.
+A value of -1 means ``empty.''
 
 This variable is mostly obsolete now that you can use
 @code{unread-command-events} instead; it exists only to support programs
@@ -2261,10 +2597,33 @@ The alias @code{last-input-char} exists for compatibility with
 Emacs version 18.
 @end defvar
 
+@defmac while-no-input body@dots{}
+This construct runs the @var{body} forms and returns the value of the
+last one---but only if no input arrives.  If any input arrives during
+the execution of the @var{body} forms, it aborts them (working much
+like a quit).  The @code{while-no-input} form returns @code{nil} if
+aborted by a real quit, and returns @code{t} if aborted by arrival of
+other input.
+
+If a part of @var{body} binds @code{inhibit-quit} to non-@code{nil},
+arrival of input during those parts won't cause an abort until
+the end of that part.
+
+If you want to be able to distinguish all possible values computed
+by @var{body} from both kinds of abort conditions, write the code
+like this:
+
+@example
+(while-no-input
+  (list
+    (progn . @var{body})))
+@end example
+@end defmac
+
 @defun discard-input
-@cindex flush input
-@cindex discard input
-@cindex terminate keyboard macro
+@cindex flushing input
+@cindex discarding input
+@cindex keyboard macro, terminating
 This function discards the contents of the terminal input buffer and
 cancels any keyboard macro that might be in the process of definition.
 It returns @code{nil}.
@@ -2287,7 +2646,8 @@ during the sleep.
 @cindex special events
 Special events are handled at a very low level---as soon as they are
 read.  The @code{read-event} function processes these events itself, and
-never returns them.
+never returns them.  Instead, it keeps waiting for the first event
+that is not special and returns that one.
 
 Events that are handled in this way do not echo, they are never grouped
 into key sequences, and they never appear in the value of
@@ -2301,14 +2661,14 @@ These events do, however, appear in @code{last-input-event} immediately
 after they are read, and this is the way for the event's definition to
 find the actual event.
 
-The events types @code{iconify-frame}, @code{make-frame-visible} and
-@code{delete-frame} are normally handled in this way.  The keymap which
+The events types @code{iconify-frame}, @code{make-frame-visible},
+@code{delete-frame}, @code{drag-n-drop}, and user signals like
+@code{sigusr1} are normally handled in this way.  The keymap which
 defines how to handle special events---and which events are special---is
 in the variable @code{special-event-map} (@pxref{Active Keymaps}).
 
 @node Waiting
 @section Waiting for Elapsed Time or Input
-@cindex pausing
 @cindex waiting
 
   The wait functions are designed to wait for a certain amount of time
@@ -2321,27 +2681,27 @@ screen.
 @defun sit-for seconds &optional nodisp
 This function performs redisplay (provided there is no pending input
 from the user), then waits @var{seconds} seconds, or until input is
-available.  The value is @code{t} if @code{sit-for} waited the full
-time with no input arriving (see @code{input-pending-p} in @ref{Event
-Input Misc}).  Otherwise, the value is @code{nil}.
+available.  The usual purpose of @code{sit-for} is to give the user
+time to read text that you display.  The value is @code{t} if
+@code{sit-for} waited the full time with no input arriving
+(@pxref{Event Input Misc}).  Otherwise, the value is @code{nil}.
 
 The argument @var{seconds} need not be an integer.  If it is a floating
 point number, @code{sit-for} waits for a fractional number of seconds.
 Some systems support only a whole number of seconds; on these systems,
 @var{seconds} is rounded down.
 
-The expression @code{(sit-for 0)} is a convenient way to request a
-redisplay, without any delay.  @xref{Forcing Redisplay}.
+The expression @code{(sit-for 0)} is equivalent to @code{(redisplay)},
+i.e. it requests a redisplay, without any delay, if there is no pending input.
+@xref{Forcing Redisplay}.
 
 If @var{nodisp} is non-@code{nil}, then @code{sit-for} does not
 redisplay, but it still returns as soon as input is available (or when
 the timeout elapses).
 
-Iconifying or deiconifying a frame makes @code{sit-for} return, because
-that generates an event.  @xref{Misc Events}.
-
-The usual purpose of @code{sit-for} is to give the user time to read
-text that you display.
+In batch mode (@pxref{Batch Mode}), @code{sit-for} cannot be
+interrupted, even by input from the standard input descriptor.  It is
+thus equivalent to @code{sleep-for}, which is described below.
 
 It is also possible to call @code{sit-for} with three arguments,
 as @code{(sit-for @var{seconds} @var{millisec} @var{nodisp})},
@@ -2415,7 +2775,7 @@ about the special behavior of @kbd{C-g} in the command loop.  In the
 case of @code{read-quoted-char}, this is so that @kbd{C-q} can be used
 to quote a @kbd{C-g}.
 
-@cindex prevent quitting
+@cindex preventing quitting
   You can prevent quitting for a portion of a Lisp function by binding
 the variable @code{inhibit-quit} to a non-@code{nil} value.  Then,
 although @kbd{C-g} still sets @code{quit-flag} to @code{t} as usual, the
@@ -2461,6 +2821,30 @@ is set to a value other than @code{nil}.  If @code{inhibit-quit} is
 non-@code{nil}, then @code{quit-flag} has no special effect.
 @end defvar
 
+@defmac with-local-quit body@dots{}
+This macro executes @var{body} forms in sequence, but allows quitting, at
+least locally, within @var{body} even if @code{inhibit-quit} was
+non-@code{nil} outside this construct.  It returns the value of the
+last form in @var{body}, unless exited by quitting, in which case
+it returns @code{nil}.
+
+If @code{inhibit-quit} is @code{nil} on entry to @code{with-local-quit},
+it only executes the @var{body}, and setting @code{quit-flag} causes
+a normal quit.  However, if @code{inhibit-quit} is non-@code{nil} so
+that ordinary quitting is delayed, a non-@code{nil} @code{quit-flag}
+triggers a special kind of local quit.  This ends the execution of
+@var{body} and exits the @code{with-local-quit} body with
+@code{quit-flag} still non-@code{nil}, so that another (ordinary) quit
+will happen as soon as that is allowed.  If @code{quit-flag} is
+already non-@code{nil} at the beginning of @var{body}, the local quit
+happens immediately and the body doesn't execute at all.
+
+This macro is mainly useful in functions that can be called from
+timers, process filters, process sentinels, @code{pre-command-hook},
+@code{post-command-hook}, and other places where @code{inhibit-quit} is
+normally bound to @code{t}.
+@end defmac
+
 @deffn Command keyboard-quit
 This function signals the @code{quit} condition with @code{(signal 'quit
 nil)}.  This is the same thing that quitting does.  (See @code{signal}
@@ -2556,7 +2940,7 @@ command, so setting it has no effect on the prefix arguments for future
 commands.
 
   Normally, commands specify which representation to use for the prefix
-argument, either numeric or raw, in the @code{interactive} declaration.
+argument, either numeric or raw, in the @code{interactive} specification.
 (@xref{Using Interactive}.)  Alternatively, functions may look at the
 value of the prefix argument directly in the variable
 @code{current-prefix-arg}, but this is less clean.
@@ -2566,7 +2950,7 @@ This function returns the numeric meaning of a valid raw prefix argument
 value, @var{arg}.  The argument may be a symbol, a number, or a list.
 If it is @code{nil}, the value 1 is returned; if it is @code{-}, the
 value @minus{}1 is returned; if it is a number, that number is returned;
-if it is a list, the @acronym{CAR} of that list (which should be a number) is
+if it is a list, the @sc{car} of that list (which should be a number) is
 returned.
 @end defun
 
@@ -2663,7 +3047,7 @@ using the minibuffer.  Usually it is more convenient for the user if you
 change the major mode of the current buffer temporarily to a special
 major mode, which should have a command to go back to the previous mode.
 (The @kbd{e} command in Rmail uses this technique.)  Or, if you wish to
-give the user different text to edit ``recursively'', create and select
+give the user different text to edit ``recursively,'' create and select
 a new buffer in a special mode.  In this mode, define a command to
 complete the processing and go back to the previous buffer.  (The
 @kbd{m} command in Rmail does this.)
@@ -2683,7 +3067,12 @@ automatically by the initialization of Emacs, to let the user begin
 editing.  When called from a Lisp program, it enters a recursive editing
 level.
 
-  In the following example, the function @code{simple-rec} first
+If the current buffer is not the same as the selected window's buffer,
+@code{recursive-edit} saves and restores the current buffer.  Otherwise,
+if you switch buffers, the buffer you switched to is current after
+@code{recursive-edit} returns.
+
+In the following example, the function @code{simple-rec} first
 advances point one word, then enters a recursive edit, printing out a
 message in the echo area.  The user can then do any editing desired, and
 then type @kbd{C-M-c} to exit and continue executing @code{simple-rec}.
@@ -2761,25 +3150,28 @@ Disabling a command has no effect on calling it as a function from Lisp
 programs.
 
 @deffn Command enable-command command
-Allow @var{command} to be executed without special confirmation from now
-on, and (if the user confirms) alter the user's init file (@pxref{Init
+Allow @var{command} (a symbol) to be executed without special
+confirmation from now on, and alter the user's init file (@pxref{Init
 File}) so that this will apply to future sessions.
 @end deffn
 
 @deffn Command disable-command command
 Require special confirmation to execute @var{command} from now on, and
-(if the user confirms) alter the user's init file so that this
-will apply to future sessions.
+alter the user's init file so that this will apply to future sessions.
 @end deffn
 
-@defvar disabled-command-hook
-When the user invokes a disabled command interactively, this normal hook
-is run instead of the disabled command.  The hook functions can use
-@code{this-command-keys} to determine what the user typed to run the
-command, and thus find the command itself.  @xref{Hooks}.
+@defvar disabled-command-function
+The value of this variable should be a function.  When the user
+invokes a disabled command interactively, this function is called
+instead of the disabled command.  It can use @code{this-command-keys}
+to determine what the user typed to run the command, and thus find the
+command itself.
 
-By default, @code{disabled-command-hook} contains a function that asks
-the user whether to proceed.
+The value may also be @code{nil}.  Then all commands work normally,
+even disabled ones.
+
+By default, the value is a function that asks the user whether to
+proceed.
 @end defvar
 
 @node Command History
@@ -2835,7 +3227,7 @@ representation of a keyboard macro is a string or vector containing the
 events.  Don't confuse keyboard macros with Lisp macros
 (@pxref{Macros}).
 
-@defun execute-kbd-macro kbdmacro &optional count
+@defun execute-kbd-macro kbdmacro &optional count loopfunc
 This function executes @var{kbdmacro} as a sequence of events.  If
 @var{kbdmacro} is a string or vector, then the events in it are executed
 exactly as if they had been input by the user.  The sequence is
@@ -2852,10 +3244,14 @@ many times.  If @var{count} is omitted or @code{nil}, @var{kbdmacro} is
 executed once.  If it is 0, @var{kbdmacro} is executed over and over until it
 encounters an error or a failing search.
 
+If @var{loopfunc} is non-@code{nil}, it is a function that is called,
+without arguments, prior to each iteration of the macro.  If
+@var{loopfunc} returns @code{nil}, then this stops execution of the macro.
+
 @xref{Reading One Event}, for an example of using @code{execute-kbd-macro}.
 @end defun
 
-@defvar executing-macro
+@defvar executing-kbd-macro
 This variable contains the string or vector that defines the keyboard
 macro that is currently executing.  It is @code{nil} if no macro is
 currently executing.  A command can test this variable so as to behave
@@ -2864,9 +3260,11 @@ yourself.
 @end defvar
 
 @defvar defining-kbd-macro
-This variable indicates whether a keyboard macro is being defined.  A
-command can test this variable so as to behave differently while a macro
-is being defined.  The commands @code{start-kbd-macro} and
+This variable is non-@code{nil} if and only if a keyboard macro is
+being defined.  A command can test this variable so as to behave
+differently while a macro is being defined.  The value is
+@code{append} while appending to the definition of an existing macro.
+The commands @code{start-kbd-macro}, @code{kmacro-start-macro} and
 @code{end-kbd-macro} set this variable---do not set it yourself.
 
 The variable is always local to the current terminal and cannot be