aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-03-28 20:02:03 +0000
committerRichard M. Stallman1994-03-28 20:02:03 +0000
commitf142f62a0ac4d515265edc4fcdda31f0b63a7311 (patch)
tree4b5ea2b63ea491d1831bee49dc6f35a474dd7a48
parent4d4cd289b45ae706b4f723c3a11955447020d43e (diff)
downloademacs-f142f62a0ac4d515265edc4fcdda31f0b63a7311.tar.gz
emacs-f142f62a0ac4d515265edc4fcdda31f0b63a7311.zip
*** empty log message ***
-rw-r--r--lispref/commands.texi690
1 files changed, 356 insertions, 334 deletions
diff --git a/lispref/commands.texi b/lispref/commands.texi
index 19eb0340df7..e2878eee00d 100644
--- a/lispref/commands.texi
+++ b/lispref/commands.texi
@@ -1,6 +1,6 @@
1@c -*-texinfo-*- 1@c -*-texinfo-*-
2@c This is part of the GNU Emacs Lisp Reference Manual. 2@c This is part of the GNU Emacs Lisp Reference Manual.
3@c Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc. 3@c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
4@c See the file elisp.texi for copying conditions. 4@c See the file elisp.texi for copying conditions.
5@setfilename ../info/commands 5@setfilename ../info/commands
6@node Command Loop, Keymaps, Minibuffers, Top 6@node Command Loop, Keymaps, Minibuffers, Top
@@ -39,42 +39,46 @@ calling the function @code{read-key-sequence}. Your Lisp code can also
39call this function (@pxref{Key Sequence Input}). Lisp programs can also 39call this function (@pxref{Key Sequence Input}). Lisp programs can also
40do input at a lower level with @code{read-event} (@pxref{Reading One 40do input at a lower level with @code{read-event} (@pxref{Reading One
41Event}) or discard pending input with @code{discard-input} 41Event}) or discard pending input with @code{discard-input}
42(@pxref{Peeking and Discarding}). 42(@pxref{Event Input Misc}).
43 43
44 The key sequence is translated into a command through the currently 44 The key sequence is translated into a command through the currently
45active keymaps. @xref{Key Lookup}, for information on how this is done. 45active keymaps. @xref{Key Lookup}, for information on how this is done.
46The result should be a keyboard macro or an interactively callable 46The result should be a keyboard macro or an interactively callable
47function. If the key is @kbd{M-x}, then it reads the name of another 47function. If the key is @kbd{M-x}, then it reads the name of another
48command, which is used instead. This is done by the command 48command, which it then calls. This is done by the command
49@code{execute-extended-command} (@pxref{Interactive Call}). 49@code{execute-extended-command} (@pxref{Interactive Call}).
50 50
51 Once the command is chosen, it must be executed, which includes 51 To execute a command requires first reading the arguments for it.
52reading arguments to be given to it. This is done by calling 52This is done by calling @code{command-execute} (@pxref{Interactive
53@code{command-execute} (@pxref{Interactive Call}). For commands written 53Call}). For commands written in Lisp, the @code{interactive}
54in Lisp, the @code{interactive} specification says how to read the 54specification says how to read the arguments. This may use the prefix
55arguments. This may use the prefix argument (@pxref{Prefix Command 55argument (@pxref{Prefix Command Arguments}) or may read with prompting
56Arguments}) or may read with prompting in the minibuffer 56in the minibuffer (@pxref{Minibuffers}). For example, the command
57(@pxref{Minibuffers}). For example, the command @code{find-file} has an 57@code{find-file} has an @code{interactive} specification which says to
58@code{interactive} specification which says to read a file name using 58read a file name using the minibuffer. The command's function body does
59the minibuffer. The command's function body does not use the 59not use the minibuffer; if you call this command from Lisp code as a
60minibuffer; if you call this command from Lisp code as a function, you 60function, you must supply the file name string as an ordinary Lisp
61must supply the file name string as an ordinary Lisp function argument. 61function argument.
62 62
63 If the command is a string or vector (i.e., a keyboard macro) then 63 If the command is a string or vector (i.e., a keyboard macro) then
64@code{execute-kbd-macro} is used to execute it. You can call this 64@code{execute-kbd-macro} is used to execute it. You can call this
65function yourself (@pxref{Keyboard Macros}). 65function yourself (@pxref{Keyboard Macros}).
66 66
67 If a command runs away, typing @kbd{C-g} terminates its execution 67 To terminate the execution of a running command, type @kbd{C-g}. This
68immediately. This is called @dfn{quitting} (@pxref{Quitting}). 68character causes @dfn{quitting} (@pxref{Quitting}).
69 69
70@defvar pre-command-hook 70@defvar pre-command-hook
71The editor command loop runs this normal hook before each command. 71The editor command loop runs this normal hook before each command. At
72that time, @code{this-command} contains the command that is about to
73run, and @code{last-command} describes the previous command.
72@end defvar 74@end defvar
73 75
74@defvar post-command-hook 76@defvar post-command-hook
75The editor command loop runs this normal hook after each command, 77The editor command loop runs this normal hook after each command
76and also when the command loop is entered, or reentered after 78(including commands terminated prematurely by quitting or by errors),
77an error or quit. 79and also when the command loop is first entered. At that time,
80@code{this-command} describes the command that just ran, and
81@code{last-command} describes the command before that.
78@end defvar 82@end defvar
79 83
80@node Defining Commands 84@node Defining Commands
@@ -108,12 +112,12 @@ makes a Lisp function an interactively-callable command.
108This special form declares that the function in which it appears is a 112This special form declares that the function in which it appears is a
109command, and that it may therefore be called interactively (via 113command, and that it may therefore be called interactively (via
110@kbd{M-x} or by entering a key sequence bound to it). The argument 114@kbd{M-x} or by entering a key sequence bound to it). The argument
111@var{arg-descriptor} declares the way the arguments to the command are 115@var{arg-descriptor} declares how to compute the arguments to the
112to be computed when the command is called interactively. 116command when the command is called interactively.
113 117
114A command may be called from Lisp programs like any other function, but 118A command may be called from Lisp programs like any other function, but
115then the arguments are supplied by the caller and @var{arg-descriptor} 119then the caller supplies the arguments and @var{arg-descriptor} has no
116has no effect. 120effect.
117 121
118The @code{interactive} form has its effect because the command loop 122The @code{interactive} form has its effect because the command loop
119(actually, its subroutine @code{call-interactively}) scans through the 123(actually, its subroutine @code{call-interactively}) scans through the
@@ -172,7 +176,7 @@ existing buffer followed by a new name to give to that buffer:
172@end smallexample 176@end smallexample
173 177
174@cindex @samp{*} in interactive 178@cindex @samp{*} in interactive
175@kindex buffer-read-only 179@cindex read-only buffers in interactive
176If the first character in the string is @samp{*}, then an error is 180If the first character in the string is @samp{*}, then an error is
177signaled if the buffer is read-only. 181signaled if the buffer is read-only.
178 182
@@ -222,6 +226,9 @@ This code letter computes an argument without reading any input.
222Therefore, it does not use a prompt string, and any prompt string you 226Therefore, it does not use a prompt string, and any prompt string you
223supply is ignored. 227supply is ignored.
224 228
229Even though the code letter doesn't use a prompt string, you must follow
230it with a newline if it is not the last code character in the string.
231
225@item Prompt 232@item Prompt
226A prompt immediately follows the code character. The prompt ends either 233A prompt immediately follows the code character. The prompt ends either
227with the end of the string or with a newline. 234with the end of the string or with a newline.
@@ -266,7 +273,7 @@ Completion, Prompt.
266 273
267@item d 274@item d
268@cindex position argument 275@cindex position argument
269The position of point as a number (@pxref{Point}). No I/O. 276The position of point, as an integer (@pxref{Point}). No I/O.
270 277
271@item D 278@item D
272A directory name. The default is the current default directory of the 279A directory name. The default is the current default directory of the
@@ -280,13 +287,10 @@ the data in the lists. @xref{Input Events}. No I/O.
280 287
281You can use @samp{e} more than once in a single command's interactive 288You can use @samp{e} more than once in a single command's interactive
282specification. If the key sequence which invoked the command has 289specification. If the key sequence which invoked the command has
283@var{n} events with parameters, the @var{n}th @samp{e} provides the 290@var{n} events that are lists, the @var{n}th @samp{e} provides the
284@var{n}th list event. Events which are not lists, such as function keys 291@var{n}th such event. Events which are not lists, such as function keys
285and @sc{ASCII} characters, do not count where @samp{e} is concerned. 292and @sc{ASCII} characters, do not count where @samp{e} is concerned.
286 293
287Even though @samp{e} does not use a prompt string, you must follow
288it with a newline if it is not the last code character.
289
290@item f 294@item f
291A file name of an existing file (@pxref{File Names}). The default 295A file name of an existing file (@pxref{File Names}). The default
292directory is @code{default-directory}. Existing, Completion, Default, 296directory is @code{default-directory}. Existing, Completion, Default,
@@ -306,7 +310,7 @@ This kind of input is used by commands such as @code{describe-key} and
306 310
307@item m 311@item m
308@cindex marker argument 312@cindex marker argument
309The position of the mark as a number. No I/O. 313The position of the mark, as an integer. No I/O.
310 314
311@item n 315@item n
312A number read with the minibuffer. If the input is not a number, the 316A number read with the minibuffer. If the input is not a number, the
@@ -315,8 +319,8 @@ Prompt.
315 319
316@item N 320@item N
317@cindex raw prefix argument usage 321@cindex raw prefix argument usage
318The raw prefix argument. If the prefix argument is @code{nil}, then a 322The raw prefix argument. If the prefix argument is @code{nil}, then
319number is read as with @kbd{n}. Requires a number. Prompt. 323read a number as with @kbd{n}. Requires a number. Prompt.
320 324
321@item p 325@item p
322@cindex numeric prefix argument usage 326@cindex numeric prefix argument usage
@@ -429,9 +433,10 @@ that is, if @var{object} is a command. Otherwise, returns @code{nil}.
429 433
430The interactively callable objects include strings and vectors (treated 434The interactively callable objects include strings and vectors (treated
431as keyboard macros), lambda expressions that contain a top-level call to 435as keyboard macros), lambda expressions that contain a top-level call to
432@code{interactive}, byte-code function objects, autoload objects that 436@code{interactive}, compiled function objects made from such lambda
433are declared as interactive (non-@code{nil} fourth argument to 437expressions, autoload objects that are declared as interactive
434@code{autoload}), and some of the primitive functions. 438(non-@code{nil} fourth argument to @code{autoload}), and some of the
439primitive functions.
435 440
436A symbol is @code{commandp} if its function definition is 441A symbol is @code{commandp} if its function definition is
437@code{commandp}. 442@code{commandp}.
@@ -461,7 +466,7 @@ an argument. @xref{Command History}.
461@cindex keyboard macro execution 466@cindex keyboard macro execution
462This function executes @var{command} as an editing command. The 467This function executes @var{command} as an editing command. The
463argument @var{command} must satisfy the @code{commandp} predicate; i.e., 468argument @var{command} must satisfy the @code{commandp} predicate; i.e.,
464it must be an interactively callable function or a string. 469it must be an interactively callable function or a keyboard macro.
465 470
466A string or vector as @var{command} is executed with 471A string or vector as @var{command} is executed with
467@code{execute-kbd-macro}. A function is passed to 472@code{execute-kbd-macro}. A function is passed to
@@ -482,9 +487,9 @@ This function reads a command name from the minibuffer using
482command returns becomes the value of @code{execute-extended-command}. 487command returns becomes the value of @code{execute-extended-command}.
483 488
484@cindex execute with prefix argument 489@cindex execute with prefix argument
485If the command asks for a prefix argument, the value 490If the command asks for a prefix argument, it receives the value
486@var{prefix-argument} is supplied. If @code{execute-extended-command} 491@var{prefix-argument}. If @code{execute-extended-command} is called
487is called interactively, the current raw prefix argument is used for 492interactively, the current raw prefix argument is used for
488@var{prefix-argument}, and thus passed on to whatever command is run. 493@var{prefix-argument}, and thus passed on to whatever command is run.
489 494
490@c !!! Should this be @kindex? 495@c !!! Should this be @kindex?
@@ -512,11 +517,11 @@ This function returns @code{t} if the containing function (the one that
512called @code{interactive-p}) was called interactively, with the function 517called @code{interactive-p}) was called interactively, with the function
513@code{call-interactively}. (It makes no difference whether 518@code{call-interactively}. (It makes no difference whether
514@code{call-interactively} was called from Lisp or directly from the 519@code{call-interactively} was called from Lisp or directly from the
515editor command loop.) Note that if the containing function was called 520editor command loop.) If the containing function was called by Lisp
516by Lisp evaluation (or with @code{apply} or @code{funcall}), then it was 521evaluation (or with @code{apply} or @code{funcall}), then it was not
517not called interactively. 522called interactively.
518 523
519The usual application of @code{interactive-p} is for deciding whether to 524The most common use of @code{interactive-p} is for deciding whether to
520print an informative message. As a special exception, 525print an informative message. As a special exception,
521@code{interactive-p} returns @code{nil} whenever a keyboard macro is 526@code{interactive-p} returns @code{nil} whenever a keyboard macro is
522being run. This is to suppress the informative messages and speed 527being run. This is to suppress the informative messages and speed
@@ -569,9 +574,9 @@ This variable records the name of the previous command executed by the
569command loop (the one before the current command). Normally the value 574command loop (the one before the current command). Normally the value
570is a symbol with a function definition, but this is not guaranteed. 575is a symbol with a function definition, but this is not guaranteed.
571 576
572The value is set by copying the value of @code{this-command} when a 577The value is copied from @code{this-command} when a command returns to
573command returns to the command loop, except when the command specifies a 578the command loop, except when the command specifies a prefix argument
574prefix argument for the following command. 579for the following command.
575@end defvar 580@end defvar
576 581
577@defvar this-command 582@defvar this-command
@@ -580,17 +585,17 @@ This variable records the name of the command now being executed by
580the editor command loop. Like @code{last-command}, it is normally a symbol 585the editor command loop. Like @code{last-command}, it is normally a symbol
581with a function definition. 586with a function definition.
582 587
583This variable is set by the command loop just before the command is run, 588The command loop sets this variable just before running a command, and
584and its value is copied into @code{last-command} when the command 589copies its value into @code{last-command} when the command finishes
585finishes (unless the command specifies a prefix argument for the 590(unless the command specifies a prefix argument for the following
586following command). 591command).
587 592
588@cindex kill command repetition 593@cindex kill command repetition
589Some commands change the value of this variable during their execution, 594Some commands set this variable during their execution, as a flag for
590simply as a flag for whatever command runs next. In particular, the 595whatever command runs next. In particular, the functions that kill text
591functions that kill text set @code{this-command} to @code{kill-region} 596set @code{this-command} to @code{kill-region} so that any kill commands
592so that any kill commands immediately following will know to append the 597immediately following will know to append the killed text to the
593killed text to the previous kill. 598previous kill.
594@end defvar 599@end defvar
595 600
596If you do not want a particular command to be recognized as the previous 601If you do not want a particular command to be recognized as the previous
@@ -625,7 +630,7 @@ if all those events were characters. @xref{Input Events}.
625 630
626@defvar last-nonmenu-event 631@defvar last-nonmenu-event
627This variable holds the last input event read as part of a key 632This variable holds the last input event read as part of a key
628sequence, aside from events resulting from mouse menus. 633sequence, not counting events resulting from mouse menus.
629 634
630One use of this variable is to figure out a good default location to 635One use of this variable is to figure out a good default location to
631pop up another menu. 636pop up another menu.
@@ -640,7 +645,7 @@ character to insert.
640 645
641@example 646@example
642@group 647@group
643last-command-char 648last-command-event
644;; @r{Now type @kbd{C-u C-x C-e}.} 649;; @r{Now type @kbd{C-u C-x C-e}.}
645 @result{} 5 650 @result{} 5
646@end group 651@end group
@@ -666,9 +671,9 @@ frame, the value is the frame to which the event was redirected.
666This variable determines how much time should elapse before command 671This variable determines how much time should elapse before command
667characters echo. Its value must be an integer, which specifies the 672characters echo. Its value must be an integer, which specifies the
668number of seconds to wait before echoing. If the user types a prefix 673number of seconds to wait before echoing. If the user types a prefix
669key (say @kbd{C-x}) and then delays this many seconds before continuing, 674key (such as @kbd{C-x}) and then delays this many seconds before
670the key @kbd{C-x} is echoed in the echo area. Any subsequent characters 675continuing, the prefix key is echoed in the echo area. Any subsequent
671in the same command will be echoed as well. 676characters in the same command will be echoed as well.
672 677
673If the value is zero, then command input is not echoed. 678If the value is zero, then command input is not echoed.
674@end defvar 679@end defvar
@@ -683,16 +688,6 @@ represent keyboard or mouse activity. The events for keyboard activity
683are characters or symbols; mouse events are always lists. This section 688are characters or symbols; mouse events are always lists. This section
684describes the representation and meaning of input events in detail. 689describes the representation and meaning of input events in detail.
685 690
686A command invoked using events that are lists can get the full values of
687these events using the @samp{e} interactive code. @xref{Interactive
688Codes}.
689
690A key sequence that starts with a mouse event is read using the keymaps
691of the buffer in the window that the mouse was in, not the current
692buffer. This does not imply that clicking in a window selects that
693window or its buffer---that is entirely under the control of the command
694binding of the key sequence.
695
696@defun eventp object 691@defun eventp object
697This function returns non-@code{nil} if @var{event} is an input event. 692This function returns non-@code{nil} if @var{event} is an input event.
698@end defun 693@end defun
@@ -700,6 +695,7 @@ This function returns non-@code{nil} if @var{event} is an input event.
700@menu 695@menu
701* Keyboard Events:: Ordinary characters--keys with symbols on them. 696* Keyboard Events:: Ordinary characters--keys with symbols on them.
702* Function Keys:: Function keys--keys with names, not symbols. 697* Function Keys:: Function keys--keys with names, not symbols.
698* Mouse Events:: Overview of mouse events.
703* Click Events:: Pushing and releasing a mouse button. 699* Click Events:: Pushing and releasing a mouse button.
704* Drag Events:: Moving the mouse before releasing the button. 700* Drag Events:: Moving the mouse before releasing the button.
705* Button-Down Events:: A button was pushed and not yet released. 701* Button-Down Events:: A button was pushed and not yet released.
@@ -720,7 +716,9 @@ This function returns non-@code{nil} if @var{event} is an input event.
720There are two kinds of input you can get from the keyboard: ordinary 716There are two kinds of input you can get from the keyboard: ordinary
721keys, and function keys. Ordinary keys correspond to characters; the 717keys, and function keys. Ordinary keys correspond to characters; the
722events they generate are represented in Lisp as characters. In Emacs 718events they generate are represented in Lisp as characters. In Emacs
723versions 18 and earlier, characters were the only events. 719versions 18 and earlier, characters were the only events. The event
720type of a character event is the character itself (an integer);
721see @ref{Classifying Events}.
724 722
725@cindex modifier bits (of input character) 723@cindex modifier bits (of input character)
726@cindex basic code (of input character) 724@cindex basic code (of input character)
@@ -756,7 +754,7 @@ the @sc{ASCII} character set whenever possible, Emacs avoids using
756the 2**21 bit for those characters. 754the 2**21 bit for those characters.
757 755
758However, @sc{ASCII} provides no way to distinguish @kbd{C-A} from 756However, @sc{ASCII} provides no way to distinguish @kbd{C-A} from
759@kbd{C-A}, so Emacs uses the 2**21 bit in @kbd{C-A} and not in 757@kbd{C-a}, so Emacs uses the 2**21 bit in @kbd{C-A} and not in
760@kbd{C-a}. 758@kbd{C-a}.
761 759
762@item hyper 760@item hyper
@@ -785,13 +783,12 @@ function @code{event-modifiers} (@pxref{Classifying Events}).
785@cindex function keys 783@cindex function keys
786Most keyboards also have @dfn{function keys}---keys which have names or 784Most keyboards also have @dfn{function keys}---keys which have names or
787symbols that are not characters. Function keys are represented in Lisp 785symbols that are not characters. Function keys are represented in Lisp
788as symbols; the symbol's name is the function key's label. For example, 786as symbols; the symbol's name is the function key's label, in lower
789pressing a key labeled @key{F1} places the symbol @code{f1} in the input 787case. For example, pressing a key labeled @key{F1} places the symbol
790stream. 788@code{f1} in the input stream.
791 789
792For all keyboard events, the event type (which classifies the event for 790The event type of a function key event is the event symbol itself.
793key lookup purposes) is identical to the event---it is the character or 791@xref{Classifying Events}.
794the symbol. @xref{Classifying Events}.
795 792
796Here are a few special cases in the symbol naming convention for 793Here are a few special cases in the symbol naming convention for
797function keys: 794function keys:
@@ -801,15 +798,16 @@ function keys:
801These keys correspond to common @sc{ASCII} control characters that have 798These keys correspond to common @sc{ASCII} control characters that have
802special keys on most keyboards. 799special keys on most keyboards.
803 800
804In @sc{ASCII}, @kbd{C-i} and @key{TAB} are the same character. Emacs 801In @sc{ASCII}, @kbd{C-i} and @key{TAB} are the same character. If the
805lets you distinguish them if you wish, by returning the former as the 802terminal can distinguish between them, Emacs conveys the distinction to
806integer 9, and the latter as the symbol @code{tab}. 803Lisp programs by representing the former as the integer 9, and the
804latter as the symbol @code{tab}.
807 805
808Most of the time, it's not useful to distinguish the two. So normally 806Most of the time, it's not useful to distinguish the two. So normally
809@code{function-key-map} is set up to map @code{tab} into 9. Thus, a 807@code{function-key-map} is set up to map @code{tab} into 9. Thus, a key
810key binding for character code 9 also applies to @code{tab}. Likewise 808binding for character code 9 (the character @kbd{C-i}) also applies to
811for the other symbols in this group. The function @code{read-char} 809@code{tab}. Likewise for the other symbols in this group. The function
812also converts these events into characters. 810@code{read-char} likewise converts these events into characters.
813 811
814In @sc{ASCII}, @key{BS} is really @kbd{C-h}. But @code{backspace} 812In @sc{ASCII}, @key{BS} is really @kbd{C-h}. But @code{backspace}
815converts into the character code 127 (@key{DEL}), not into code 8 813converts into the character code 127 (@key{DEL}), not into code 8
@@ -845,9 +843,31 @@ The super modifier.
845@end table 843@end table
846 844
847Thus, the symbol for the key @key{F3} with @key{META} held down is 845Thus, the symbol for the key @key{F3} with @key{META} held down is
848@kbd{M-@key{F3}}. When you use more than one prefix, we recommend you 846@kbd{M-@key{f3}}. When you use more than one prefix, we recommend you
849write them in alphabetical order (though the order does not matter in 847write them in alphabetical order; but the order does not matter in
850arguments to the key-binding lookup and modification functions). 848arguments to the key-binding lookup and modification functions.
849
850@node Mouse Events
851@subsection Mouse Events
852
853Emacs supports four kinds of mouse events: click events, drag events,
854button-down events, and motion events. All mouse events are represented
855as lists. The @sc{car} of the list is the event type; this says which
856mouse button was involved, and which modifier keys were used with it.
857The event type can also distinguish double or triple button presses
858(@pxref{Repeat Events}). The rest of the list elements give position
859and time information.
860
861For key lookup, only the event type matters: two events of the same type
862necessarily run the same command. The command can access the full
863values of these events using the @samp{e} interactive code.
864@xref{Interactive Codes}.
865
866A key sequence that starts with a mouse event is read using the keymaps
867of the buffer in the window that the mouse was in, not the current
868buffer. This does not imply that clicking in a window selects that
869window or its buffer---that is entirely under the control of the command
870binding of the key sequence.
851 871
852@node Click Events 872@node Click Events
853@subsection Click Events 873@subsection Click Events
@@ -860,18 +880,17 @@ this form:
860 880
861@example 881@example
862(@var{event-type} 882(@var{event-type}
863 (@var{window} @var{buffer-pos} 883 (@var{window} @var{buffer-pos} (@var{x} . @var{y}) @var{timestamp})
864 (@var{x} . @var{y}) @var{timestamp})
865 @var{click-count}) 884 @var{click-count})
866@end example 885@end example
867 886
868Here is what the elements normally mean: 887Here is what the elements normally mean:
869 888
870@table @var 889@table @asis
871@item event-type 890@item @var{event-type}
872This is a symbol that indicates which mouse button was used. It is 891This is a symbol that indicates which mouse button was used. It is
873one of the symbols @code{mouse-1}, @code{mouse-2}, @dots{}, where the 892one of the symbols @code{mouse-1}, @code{mouse-2}, @dots{}, where the
874buttons are numbered numbered left to right. 893buttons are numbered left to right.
875 894
876You can also use prefixes @samp{A-}, @samp{C-}, @samp{H-}, @samp{M-}, 895You can also use prefixes @samp{A-}, @samp{C-}, @samp{H-}, @samp{M-},
877@samp{S-} and @samp{s-} for modifiers alt, control, hyper, meta, shift 896@samp{S-} and @samp{s-} for modifiers alt, control, hyper, meta, shift
@@ -882,30 +901,29 @@ describe events by their types; thus, if there is a key binding for
882@code{mouse-1}, that binding would apply to all events whose 901@code{mouse-1}, that binding would apply to all events whose
883@var{event-type} is @code{mouse-1}. 902@var{event-type} is @code{mouse-1}.
884 903
885@item window 904@item @var{window}
886This is the window in which the click occurred. 905This is the window in which the click occurred.
887 906
888@item x 907@item @var{x}, @var{y}
889@itemx y
890These are the pixel-based coordinates of the click, relative to the top 908These are the pixel-based coordinates of the click, relative to the top
891left corner of @var{window}, which is @code{(0 . 0)}. 909left corner of @var{window}, which is @code{(0 . 0)}.
892 910
893@item buffer-pos 911@item @var{buffer-pos}
894This is the buffer position of the character clicked on. 912This is the buffer position of the character clicked on.
895 913
896@item timestamp 914@item @var{timestamp}
897This is the time at which the event occurred, in milliseconds. (Since 915This is the time at which the event occurred, in milliseconds. (Since
898this value wraps around the entire range of Emacs Lisp integers in about 916this value wraps around the entire range of Emacs Lisp integers in about
899five hours, it is useful only for relating the times of nearby events.) 917five hours, it is useful only for relating the times of nearby events.)
900 918
901@item click-count 919@item @var{click-count}
902This is the number of rapid repeated presses so far of the same mouse 920This is the number of rapid repeated presses so far of the same mouse
903button. @xref{Repeat Events}. 921button. @xref{Repeat Events}.
904@end table 922@end table
905 923
906The meanings of @var{buffer-pos}, @var{row} and @var{column} are 924The meanings of @var{buffer-pos}, @var{x} and @var{y} are somewhat
907somewhat different when the event location is in a special part of the 925different when the event location is in a special part of the screen,
908screen, such as the mode line or a scroll bar. 926such as the mode line or a scroll bar.
909 927
910If the location is in a scroll bar, then @var{buffer-pos} is the symbol 928If the location is in a scroll bar, then @var{buffer-pos} is the symbol
911@code{vertical-scroll-bar} or @code{horizontal-scroll-bar}, and the pair 929@code{vertical-scroll-bar} or @code{horizontal-scroll-bar}, and the pair
@@ -917,8 +935,8 @@ the entire scroll bar.
917If the position is on a mode line or the vertical line separating 935If the position is on a mode line or the vertical line separating
918@var{window} from its neighbor to the right, then @var{buffer-pos} is 936@var{window} from its neighbor to the right, then @var{buffer-pos} is
919the symbol @code{mode-line} or @code{vertical-line}. For the mode line, 937the symbol @code{mode-line} or @code{vertical-line}. For the mode line,
920@var{row} does not have meaningful data. For the vertical line, 938@var{y} does not have meaningful data. For the vertical line, @var{x}
921@var{column} does not have meaningful data. 939does not have meaningful data.
922 940
923@var{buffer-pos} may be a list containing a symbol (one of the symbols 941@var{buffer-pos} may be a list containing a symbol (one of the symbols
924listed above) instead of just the symbol. This is what happens after 942listed above) instead of just the symbol. This is what happens after
@@ -939,10 +957,8 @@ position and the final position, like this:
939 957
940@example 958@example
941(@var{event-type} 959(@var{event-type}
942 (@var{window1} @var{buffer-pos1} 960 (@var{window1} @var{buffer-pos1} (@var{x1} . @var{y1}) @var{timestamp1})
943 (@var{x1} . @var{y1}) @var{timestamp1}) 961 (@var{window2} @var{buffer-pos2} (@var{x2} . @var{y2}) @var{timestamp2})
944 (@var{window2} @var{buffer-pos2}
945 (@var{x2} . @var{y2}) @var{timestamp2})
946 @var{click-count}) 962 @var{click-count})
947@end example 963@end example
948 964
@@ -972,10 +988,10 @@ click from a drag until the button is released.
972 988
973If you want to take action as soon as a button is pressed, you need to 989If you want to take action as soon as a button is pressed, you need to
974handle @dfn{button-down} events.@footnote{Button-down is the 990handle @dfn{button-down} events.@footnote{Button-down is the
975conservative antithesis of drag.}. These occur as soon as a button is 991conservative antithesis of drag.} These occur as soon as a button is
976pressed. They are represented by lists which look exactly like click 992pressed. They are represented by lists which look exactly like click
977events (@pxref{Click Events}), except that the name of @var{event-type} 993events (@pxref{Click Events}), except that the @var{event-type} symbol
978contains the prefix @samp{down-}. The @samp{down-} prefix follows the 994name contains the prefix @samp{down-}. The @samp{down-} prefix follows
979modifier key prefixes such as @samp{C-} and @samp{M-}. 995modifier key prefixes such as @samp{C-} and @samp{M-}.
980 996
981The function @code{read-key-sequence}, and the Emacs command loop, 997The function @code{read-key-sequence}, and the Emacs command loop,
@@ -983,10 +999,7 @@ ignore any button-down events that don't have command bindings. This
983means that you need not worry about defining button-down events unless 999means that you need not worry about defining button-down events unless
984you want them to do something. The usual reason to define a button-down 1000you want them to do something. The usual reason to define a button-down
985event is so that you can track mouse motion (by reading motion events) 1001event is so that you can track mouse motion (by reading motion events)
986until the button is released. 1002until the button is released. @xref{Motion Events}.
987@ifinfo
988@xref{Motion Events}.
989@end ifinfo
990 1003
991@node Repeat Events 1004@node Repeat Events
992@subsection Repeat Events 1005@subsection Repeat Events
@@ -995,8 +1008,8 @@ until the button is released.
995@cindex triple-click events 1008@cindex triple-click events
996 1009
997If you press the same mouse button more than once in quick succession 1010If you press the same mouse button more than once in quick succession
998without moving the mouse, Emacs uses special @dfn{repeat} mouse events 1011without moving the mouse, Emacs generates special @dfn{repeat} mouse
999for the second and subsequent presses. 1012events for the second and subsequent presses.
1000 1013
1001The most common repeat events are @dfn{double-click} events. Emacs 1014The most common repeat events are @dfn{double-click} events. Emacs
1002generates a double-click event when you click a button twice; the event 1015generates a double-click event when you click a button twice; the event
@@ -1004,7 +1017,7 @@ happens when you release the button (as is normal for all click
1004events). 1017events).
1005 1018
1006The event type of a double-click event contains the prefix 1019The event type of a double-click event contains the prefix
1007@code{double}. Thus, a double click on the second mouse button with 1020@samp{double-}. Thus, a double click on the second mouse button with
1008@key{meta} held down comes to the Lisp program as 1021@key{meta} held down comes to the Lisp program as
1009@code{M-double-mouse-2}. If a double-click event has no binding, the 1022@code{M-double-mouse-2}. If a double-click event has no binding, the
1010binding of the corresponding ordinary click event is used to execute 1023binding of the corresponding ordinary click event is used to execute
@@ -1012,14 +1025,14 @@ it. Thus, you need not pay attention to the double click feature
1012unless you really want to. 1025unless you really want to.
1013 1026
1014When the user performs a double click, Emacs generates first an ordinary 1027When the user performs a double click, Emacs generates first an ordinary
1015click event, and then a double-click event. Therefore, the command 1028click event, and then a double-click event. Therefore, you must design
1016binding of the double click event must be written to assume that the 1029the command binding of the double click event to assume that the
1017single-click command has already run. It must produce the desired 1030single-click command has already run. It must produce the desired
1018results of a double click, starting from the results of a single click. 1031results of a double click, starting from the results of a single click.
1019 1032
1020This means that it is most convenient to give double clicks a meaning 1033This is convenient, if the meaning of a double click somehow ``builds
1021that somehow ``builds on'' the meaning of a single click. This is what 1034on'' the meaning of a single click---which is recommended user interface
1022user interface experts recommend that double clicks should do. 1035design practice for double clicks.
1023 1036
1024If you click a button, then press it down again and start moving the 1037If you click a button, then press it down again and start moving the
1025mouse with the button held down, then you get a @dfn{double-drag} event 1038mouse with the button held down, then you get a @dfn{double-drag} event
@@ -1029,11 +1042,12 @@ has no binding, Emacs looks for an alternate binding as if the event
1029were an ordinary click. 1042were an ordinary click.
1030 1043
1031Before the double-click or double-drag event, Emacs generates a 1044Before the double-click or double-drag event, Emacs generates a
1032@dfn{double-down} event when the button is pressed down for the second 1045@dfn{double-down} event when the user presses the button down for the
1033time. Its event type contains @samp{double-down} instead of just 1046second time. Its event type contains @samp{double-down} instead of just
1034@samp{down}. If a double-down event has no binding, Emacs looks for an 1047@samp{down}. If a double-down event has no binding, Emacs looks for an
1035alternate binding as if the event were an ordinary button-down event. 1048alternate binding as if the event were an ordinary button-down event.
1036If it finds no binding that way either, the double-down event is ignored. 1049If it finds no binding that way either, the double-down event is
1050ignored.
1037 1051
1038To summarize, when you click a button and then press it again right 1052To summarize, when you click a button and then press it again right
1039away, Emacs generates a double-down event, followed by either a 1053away, Emacs generates a double-down event, followed by either a
@@ -1046,11 +1060,11 @@ these events contain @samp{triple} instead of @samp{double}. If any
1046triple event has no binding, Emacs uses the binding that it would use 1060triple event has no binding, Emacs uses the binding that it would use
1047for the corresponding double event. 1061for the corresponding double event.
1048 1062
1049If you click a button three or more times and then press it again, 1063If you click a button three or more times and then press it again, the
1050the events for the presses beyond the third are all triple events. 1064events for the presses beyond the third are all triple events. Emacs
1051Emacs does not have quadruple, quintuple, etc. events as separate 1065does not have separate event types for quadruple, quintuple, etc.@:
1052event types. However, you can look at the event list to find out 1066events. However, you can look at the event list to find out precisely
1053precisely how many times the button was pressed. 1067how many times the button was pressed.
1054 1068
1055@defun event-click-count event 1069@defun event-click-count event
1056This function returns the number of consecutive button presses that led 1070This function returns the number of consecutive button presses that led
@@ -1061,9 +1075,9 @@ the value is 3 or greater. If @var{event} is an ordinary mouse event
1061@end defun 1075@end defun
1062 1076
1063@defvar double-click-time 1077@defvar double-click-time
1064To count as double- and triple-clicks, mouse clicks must be at the same 1078To generate repeat events, successive mouse button presses must be at
1065location as the first click, and the number of milliseconds between the 1079the same screen position, and the number of milliseconds between
1066first release and the second must be less than the value of 1080successive button presses must be less than the value of
1067@code{double-click-time}. Setting @code{double-click-time} to 1081@code{double-click-time}. Setting @code{double-click-time} to
1068@code{nil} disables multi-click detection entirely. Setting it to 1082@code{nil} disables multi-click detection entirely. Setting it to
1069@code{t} removes the time limit; Emacs then detects multi-clicks by 1083@code{t} removes the time limit; Emacs then detects multi-clicks by
@@ -1081,8 +1095,7 @@ represented by lists that look like this:
1081 1095
1082@example 1096@example
1083(mouse-movement 1097(mouse-movement
1084 (@var{window} @var{buffer-pos} 1098 (@var{window} @var{buffer-pos} (@var{x} . @var{y}) @var{timestamp}))
1085 (@var{x} . @var{y}) @var{timestamp}))
1086@end example 1099@end example
1087 1100
1088The second element of the list describes the current position of the 1101The second element of the list describes the current position of the
@@ -1099,8 +1112,8 @@ events enabled. Typically @var{body} would use @code{read-event}
1099to read the motion events and modify the display accordingly. 1112to read the motion events and modify the display accordingly.
1100 1113
1101When the user releases the button, that generates a click event. 1114When the user releases the button, that generates a click event.
1102Normally @var{body} should return when it sees the click event, and 1115Typically, @var{body} should return when it sees the click event, and
1103discard the event. 1116discard that event.
1104@end defspec 1117@end defspec
1105 1118
1106@node Focus Events 1119@node Focus Events
@@ -1123,14 +1136,14 @@ Focus events are represented in Lisp as lists that look like this:
1123@noindent 1136@noindent
1124where @var{new-frame} is the frame switched to. 1137where @var{new-frame} is the frame switched to.
1125 1138
1126In X windows, most window managers are set up so that just moving the 1139Most X window window managers are set up so that just moving the mouse
1127mouse into a window is enough to set the focus there. Emacs appears to 1140into a window is enough to set the focus there. Emacs appears to do
1128do this, because it changes the cursor to solid in the new frame. 1141this, because it changes the cursor to solid in the new frame. However,
1129However, there is no need for the Lisp program to know about the focus 1142there is no need for the Lisp program to know about the focus change
1130change until some other kind of input arrives. So Emacs generates the 1143until some other kind of input arrives. So Emacs generates a focus
1131focus event only when the user actually types a keyboard key or presses 1144event only when the user actually types a keyboard key or presses a
1132a mouse button in the new frame; just moving the mouse between frames 1145mouse button in the new frame; just moving the mouse between frames does
1133does not generate a focus event. 1146not generate a focus event.
1134 1147
1135A focus event in the middle of a key sequence would garble the 1148A focus event in the middle of a key sequence would garble the
1136sequence. So Emacs never generates a focus event in the middle of a key 1149sequence. So Emacs never generates a focus event in the middle of a key
@@ -1150,7 +1163,7 @@ location, that generates a sequence of events like this:
1150(mouse-1 (#<window 18 on NEWS> 2613 (0 . 38) -864180)) 1163(mouse-1 (#<window 18 on NEWS> 2613 (0 . 38) -864180))
1151@end smallexample 1164@end smallexample
1152 1165
1153Or, while holding the control key down, the user might hold down the 1166While holding the control key down, the user might hold down the
1154second mouse button, and drag the mouse from one line to the next. 1167second mouse button, and drag the mouse from one line to the next.
1155That produces two events, as shown here: 1168That produces two events, as shown here:
1156 1169
@@ -1160,9 +1173,9 @@ That produces two events, as shown here:
1160 (#<window 18 on NEWS> 3510 (0 . 28) -729648)) 1173 (#<window 18 on NEWS> 3510 (0 . 28) -729648))
1161@end smallexample 1174@end smallexample
1162 1175
1163Or, while holding down the meta and shift keys, the user might press the 1176While holding down the meta and shift keys, the user might press the
1164second mouse button on the window's mode line, and then drag the mouse 1177second mouse button on the window's mode line, and then drag the mouse
1165into another window. That produces the following pair of events: 1178into another window. That produces a pair of events like these:
1166 1179
1167@smallexample 1180@smallexample
1168(M-S-down-mouse-2 (#<window 18 on NEWS> mode-line (33 . 31) -457844)) 1181(M-S-down-mouse-2 (#<window 18 on NEWS> mode-line (33 . 31) -457844))
@@ -1186,7 +1199,7 @@ list. Thus, the event type is always a symbol or a character.
1186concerned; thus, they always run the same command. That does not 1199concerned; thus, they always run the same command. That does not
1187necessarily mean they do the same things, however, as some commands look 1200necessarily mean they do the same things, however, as some commands look
1188at the whole event to decide what to do. For example, some commands use 1201at the whole event to decide what to do. For example, some commands use
1189the location of a mouse event to decide what text to act on. 1202the location of a mouse event to decide where in the buffer to act.
1190 1203
1191 Sometimes broader classifications of events are useful. For example, 1204 Sometimes broader classifications of events are useful. For example,
1192you might want to ask whether an event involved the @key{META} key, 1205you might want to ask whether an event involved the @key{META} key,
@@ -1196,11 +1209,16 @@ regardless of which other key or mouse button was used.
1196provided to get such information conveniently. 1209provided to get such information conveniently.
1197 1210
1198@defun event-modifiers event 1211@defun event-modifiers event
1199This function returns a list of the modifiers that @var{event} has. 1212This function returns a list of the modifiers that @var{event} has. The
1200The modifiers are symbols; they include @code{shift}, @code{control}, 1213modifiers are symbols; they include @code{shift}, @code{control},
1201@code{meta}, @code{alt}, @code{hyper} and @code{super}. In addition, 1214@code{meta}, @code{alt}, @code{hyper} and @code{super}. In addition,
1202the property of a mouse event symbol always has one of @code{click}, 1215the modifiers list of a mouse event symbol always contains one of
1203@code{drag}, and @code{down} among the modifiers. For example: 1216@code{click}, @code{drag}, and @code{down}.
1217
1218The argument @var{event} may be an entire event object, or just an event
1219type.
1220
1221Here are some examples:
1204 1222
1205@example 1223@example
1206(event-modifiers ?a) 1224(event-modifiers ?a)
@@ -1260,14 +1278,14 @@ event.
1260@subsection Accessing Events 1278@subsection Accessing Events
1261 1279
1262 This section describes convenient functions for accessing the data in 1280 This section describes convenient functions for accessing the data in
1263an event which is a list. 1281a mouse button or motion event.
1264 1282
1265 The following functions return the starting or ending position of a 1283 These two functions return the starting or ending position of a
1266mouse-button event. The position is a list of this form: 1284mouse-button event. The position is a list of this form:
1267 1285
1268@smallexample 1286@example
1269(@var{window} @var{buffer-position} (@var{col} . @var{row}) @var{timestamp}) 1287(@var{window} @var{buffer-position} (@var{col} . @var{row}) @var{timestamp})
1270@end smallexample 1288@end example
1271 1289
1272@defun event-start event 1290@defun event-start event
1273This returns the starting position of @var{event}. 1291This returns the starting position of @var{event}.
@@ -1294,7 +1312,7 @@ Return the window that @var{position} is in.
1294@end defun 1312@end defun
1295 1313
1296@defun posn-point position 1314@defun posn-point position
1297Return the buffer location in @var{position}. 1315Return the buffer position in @var{position}. This is an integer.
1298@end defun 1316@end defun
1299 1317
1300@defun posn-x-y position 1318@defun posn-x-y position
@@ -1303,22 +1321,22 @@ a cons cell @code{(@var{x} . @var{y})}.
1303@end defun 1321@end defun
1304 1322
1305@defun posn-col-row position 1323@defun posn-col-row position
1306Return the row and column (in units of characters) in @var{position}, as 1324Return the row and column (in units of characters) of @var{position}, as
1307a cons cell @code{(@var{col} . @var{row})}. These are computed from the 1325a cons cell @code{(@var{col} . @var{row})}. These are computed from the
1308@var{x} and @var{y} values actually found in @var{position}. 1326@var{x} and @var{y} values actually found in @var{position}.
1309@end defun 1327@end defun
1310 1328
1311@defun posn-timestamp position 1329@defun posn-timestamp position
1312Return the timestamp of @var{position}. 1330Return the timestamp in @var{position}.
1313@end defun 1331@end defun
1314 1332
1315@defun scroll-bar-scale ratio total 1333@defun scroll-bar-scale ratio total
1316This function multiples (in effect) @var{ratio} by @var{total}, 1334This function multiples (in effect) @var{ratio} by @var{total}, rounding
1317rounding the result to an integer. @var{ratio} is not a number, 1335the result to an integer. The argument @var{ratio} is not a number, but
1318but rather a pair @code{(@var{num} . @var{denom})}. 1336rather a pair @code{(@var{num} . @var{denom})}.
1319 1337
1320This is handy for scaling a position on a scroll bar into a buffer 1338This function is handy for scaling a position on a scroll bar into a
1321position. Here's how to do that: 1339buffer position. Here's how to do that:
1322 1340
1323@example 1341@example
1324(+ (point-min) 1342(+ (point-min)
@@ -1348,20 +1366,20 @@ fit in a string, and many Lisp programs contain string constants that
1348use @samp{\M-} to express meta characters, especially as the argument to 1366use @samp{\M-} to express meta characters, especially as the argument to
1349@code{define-key} and similar functions. 1367@code{define-key} and similar functions.
1350 1368
1351 We provide backward compatibility to run those programs with special 1369 We provide backward compatibility to run those programs using special
1352rules for how to put a keyboard character event in a string. Here are 1370rules for how to put a keyboard character event in a string. Here are
1353the rules: 1371the rules:
1354 1372
1355@itemize @bullet 1373@itemize @bullet
1356@item 1374@item
1357If the keyboard event value is in the range of 0 to 127, it can go in the 1375If the keyboard character value is in the range of 0 to 127, it can go
1358string unchanged. 1376in the string unchanged.
1359 1377
1360@item 1378@item
1361The meta variants of those events, with codes in the range of 2**23 to 1379The meta variants of those characters, with codes in the range of 2**23
13622**23+127, can also go in the string, but you must change their numeric 1380to 2**23+127, can also go in the string, but you must change their
1363values. You must set the 2**7 bit instead of the 2**23 bit, resulting 1381numeric values. You must set the 2**7 bit instead of the 2**23 bit,
1364in a value between 128 and 255. 1382resulting in a value between 128 and 255.
1365 1383
1366@item 1384@item
1367Other keyboard character events cannot fit in a string. This includes 1385Other keyboard character events cannot fit in a string. This includes
@@ -1369,7 +1387,8 @@ keyboard events in the range of 128 to 255.
1369@end itemize 1387@end itemize
1370 1388
1371 Functions such as @code{read-key-sequence} that can construct strings 1389 Functions such as @code{read-key-sequence} that can construct strings
1372containing events follow these rules. 1390of keyboard input characters follow these rules. They construct vectors
1391instead of strings, when the events won't fit in a string.
1373 1392
1374 When you use the read syntax @samp{\M-} in a string, it produces a 1393 When you use the read syntax @samp{\M-} in a string, it produces a
1375code in the range of 128 to 255---the same code that you get if you 1394code in the range of 128 to 255---the same code that you get if you
@@ -1377,14 +1396,22 @@ modify the corresponding keyboard event to put it in the string. Thus,
1377meta events in strings work consistently regardless of how they get into 1396meta events in strings work consistently regardless of how they get into
1378the strings. 1397the strings.
1379 1398
1380 New programs can avoid dealing with these rules by using vectors
1381instead of strings for key sequences when there is any possibility that
1382these issues might arise.
1383
1384 The reason we changed the representation of meta characters as 1399 The reason we changed the representation of meta characters as
1385keyboard events is to make room for basic character codes beyond 127, 1400keyboard events is to make room for basic character codes beyond 127,
1386and support meta variants of such larger character codes. 1401and support meta variants of such larger character codes.
1387 1402
1403 New programs can avoid dealing with these special compatibility rules
1404by using vectors instead of strings for key sequences when there is any
1405possibility that they might contain meta characters, and by using
1406@code{listify-key-sequence} to access a string of events.
1407
1408@defun listify-key-sequence key
1409This function converts the string or vector @var{key} to a list of
1410events which you can put in @code{unread-command-events}. Converting a
1411vector is simple, but converting a string is tricky because of the
1412special representation used for meta characters in a string.
1413@end defun
1414
1388@node Reading Input 1415@node Reading Input
1389@section Reading Input 1416@section Reading Input
1390 1417
@@ -1402,7 +1429,7 @@ debugging terminal input.
1402* Key Sequence Input:: How to read one key sequence. 1429* Key Sequence Input:: How to read one key sequence.
1403* Reading One Event:: How to read just one event. 1430* Reading One Event:: How to read just one event.
1404* Quoted Character Input:: Asking the user to specify a character. 1431* Quoted Character Input:: Asking the user to specify a character.
1405* Peeking and Discarding:: How to reread or throw away input events. 1432* Event Input Misc:: How to reread or throw away input events.
1406@end menu 1433@end menu
1407 1434
1408@node Key Sequence Input 1435@node Key Sequence Input
@@ -1426,9 +1453,9 @@ Otherwise, it returns a vector, since a vector can hold all kinds of
1426events---characters, symbols, and lists. The elements of the string or 1453events---characters, symbols, and lists. The elements of the string or
1427vector are the events in the key sequence. 1454vector are the events in the key sequence.
1428 1455
1429Quitting is suppressed inside @code{read-key-sequence}. In other words, 1456The function @code{read-key-sequence} suppresses quitting: @kbd{C-g}
1430a @kbd{C-g} typed while reading with this function is treated like any 1457typed while reading with this function works like any other character,
1431other character, and does not set @code{quit-flag}. @xref{Quitting}. 1458and does not set @code{quit-flag}. @xref{Quitting}.
1432 1459
1433The argument @var{prompt} is either a string to be displayed in the echo 1460The argument @var{prompt} is either a string to be displayed in the echo
1434area as a prompt, or @code{nil}, meaning not to display a prompt. 1461area as a prompt, or @code{nil}, meaning not to display a prompt.
@@ -1459,7 +1486,7 @@ and key sequences read from keyboard macros being executed.
1459@cindex upper case key sequence 1486@cindex upper case key sequence
1460@cindex downcasing in @code{lookup-key} 1487@cindex downcasing in @code{lookup-key}
1461If an input character is an upper case letter and has no key binding, 1488If an input character is an upper case letter and has no key binding,
1462but the lower case equivalent has one, then @code{read-key-sequence} 1489but its lower case equivalent has one, then @code{read-key-sequence}
1463converts the character to lower case. Note that @code{lookup-key} does 1490converts the character to lower case. Note that @code{lookup-key} does
1464not perform case conversion in this way. 1491not perform case conversion in this way.
1465 1492
@@ -1469,27 +1496,28 @@ button-down events entirely. It also reshuffles focus events so that they
1469never appear in a key sequence with any other events. 1496never appear in a key sequence with any other events.
1470 1497
1471When mouse events occur in special parts of a window, such as a mode 1498When mouse events occur in special parts of a window, such as a mode
1472line or a scroll bar, the event itself shows nothing special---only the 1499line or a scroll bar, the event type shows nothing special---it is the
1473symbol that would normally represent that mouse button and modifier 1500same symbol that would normally represent that combination of mouse
1474keys. The information about the screen region is kept elsewhere in the 1501button and modifier keys. The information about the window part is
1475event---in the coordinates. But @code{read-key-sequence} translates 1502kept elsewhere in the event---in the coordinates. But
1476this information into imaginary prefix keys, all of which are symbols: 1503@code{read-key-sequence} translates this information into imaginary
1477@code{mode-line}, @code{vertical-line}, @code{horizontal-scroll-bar} and 1504prefix keys, all of which are symbols: @code{mode-line},
1505@code{vertical-line}, @code{horizontal-scroll-bar} and
1478@code{vertical-scroll-bar}. 1506@code{vertical-scroll-bar}.
1479 1507
1508You can define meanings for mouse clicks in special window parts by
1509defining key sequences using these imaginary prefix keys.
1510
1480For example, if you call @code{read-key-sequence} and then click the 1511For example, if you call @code{read-key-sequence} and then click the
1481mouse on the window's mode line, this is what happens: 1512mouse on the window's mode line, you get an event like this:
1482 1513
1483@smallexample 1514@example
1484(read-key-sequence "Click on the mode line: ") 1515(read-key-sequence "Click on the mode line: ")
1485 @result{} [mode-line 1516 @result{} [mode-line
1486 (mouse-1 1517 (mouse-1
1487 (#<window 6 on NEWS> mode-line 1518 (#<window 6 on NEWS> mode-line
1488 (40 . 63) 5959987))] 1519 (40 . 63) 5959987))]
1489@end smallexample 1520@end example
1490
1491You can define meanings for mouse clicks in special window regions by
1492defining key sequences using these imaginary prefix keys.
1493 1521
1494@node Reading One Event 1522@node Reading One Event
1495@subsection Reading One Event 1523@subsection Reading One Event
@@ -1505,13 +1533,12 @@ the user or from a keyboard macro.
1505The function @code{read-event} does not display any message to indicate 1533The function @code{read-event} does not display any message to indicate
1506it is waiting for input; use @code{message} first, if you wish to 1534it is waiting for input; use @code{message} first, if you wish to
1507display one. If you have not displayed a message, @code{read-event} 1535display one. If you have not displayed a message, @code{read-event}
1508does @dfn{prompting}: it displays descriptions of the events that led to 1536prompts by echoing: it displays descriptions of the events that led to
1509or were read by the current command. @xref{The Echo Area}. 1537or were read by the current command. @xref{The Echo Area}.
1510 1538
1511If @code{cursor-in-echo-area} is non-@code{nil}, then @code{read-event} 1539If @code{cursor-in-echo-area} is non-@code{nil}, then @code{read-event}
1512moves the cursor temporarily to the echo area, to the end of any message 1540moves the cursor temporarily to the echo area, to the end of any message
1513displayed there. Otherwise @code{read-event} does not move the cursor. 1541displayed there. Otherwise @code{read-event} does not move the cursor.
1514@end defun
1515 1542
1516Here is what happens if you call @code{read-event} and then press the 1543Here is what happens if you call @code{read-event} and then press the
1517right-arrow function key: 1544right-arrow function key:
@@ -1522,17 +1549,18 @@ right-arrow function key:
1522 @result{} right 1549 @result{} right
1523@end group 1550@end group
1524@end example 1551@end example
1552@end defun
1525 1553
1526@defun read-char 1554@defun read-char
1527This function reads and returns a character of command input. It 1555This function reads and returns a character of command input. It
1528discards any events that are not characters until it gets a character. 1556discards any events that are not characters, until it gets a character.
1529 1557
1530In the first example, the user types @kbd{1} (which is @sc{ASCII} code 1558In the first example, the user types the character @kbd{1} (@sc{ASCII}
153149). The second example shows a keyboard macro definition that calls 1559code 49). The second example shows a keyboard macro definition that
1532@code{read-char} from the minibuffer. @code{read-char} reads the 1560calls @code{read-char} from the minibuffer using @code{eval-expression}.
1533keyboard macro's very next character, which is @kbd{1}. The value of 1561@code{read-char} reads the keyboard macro's very next character, which
1534this function is displayed in the echo area by the command 1562is @kbd{1}. Then @code{eval-expression} displays its return value in
1535@code{eval-expression}. 1563the echo area.
1536 1564
1537@example 1565@example
1538@group 1566@group
@@ -1545,7 +1573,7 @@ this function is displayed in the echo area by the command
1545 @result{} "^[^[(read-char)^M1" 1573 @result{} "^[^[(read-char)^M1"
1546@end group 1574@end group
1547@group 1575@group
1548(execute-kbd-macro foo) 1576(execute-kbd-macro 'foo)
1549 @print{} 49 1577 @print{} 49
1550 @result{} nil 1578 @result{} nil
1551@end group 1579@end group
@@ -1556,10 +1584,10 @@ this function is displayed in the echo area by the command
1556@subsection Quoted Character Input 1584@subsection Quoted Character Input
1557@cindex quoted character input 1585@cindex quoted character input
1558 1586
1559 You can use the function @code{read-quoted-char} when you want the user 1587 You can use the function @code{read-quoted-char} when to ask the user
1560to specify a character, and allow the user to specify a control or meta 1588to specify a character, and allow the user to specify a control or meta
1561character conveniently with quoting or as an octal character code. The 1589character conveniently with quoting or as an octal character code. The
1562command @code{quoted-insert} calls this function. 1590command @code{quoted-insert} uses this function.
1563 1591
1564@defun read-quoted-char &optional prompt 1592@defun read-quoted-char &optional prompt
1565@cindex octal character input 1593@cindex octal character input
@@ -1568,13 +1596,13 @@ command @code{quoted-insert} calls this function.
1568This function is like @code{read-char}, except that if the first 1596This function is like @code{read-char}, except that if the first
1569character read is an octal digit (0-7), it reads up to two more octal digits 1597character read is an octal digit (0-7), it reads up to two more octal digits
1570(but stopping if a non-octal digit is found) and returns the 1598(but stopping if a non-octal digit is found) and returns the
1571character represented by those digits as an octal number. 1599character represented by those digits in octal.
1572 1600
1573Quitting is suppressed when the first character is read, so that the 1601Quitting is suppressed when the first character is read, so that the
1574user can enter a @kbd{C-g}. @xref{Quitting}. 1602user can enter a @kbd{C-g}. @xref{Quitting}.
1575 1603
1576If @var{prompt} is supplied, it specifies a string for prompting the 1604If @var{prompt} is supplied, it specifies a string for prompting the
1577user. The prompt string is always printed in the echo area and followed 1605user. The prompt string is always displayed in the echo area, followed
1578by a single @samp{-}. 1606by a single @samp{-}.
1579 1607
1580In the following example, the user types in the octal number 177 (which 1608In the following example, the user types in the octal number 177 (which
@@ -1595,74 +1623,76 @@ What character-@kbd{177}
1595 1623
1596@need 3000 1624@need 3000
1597 1625
1598@node Peeking and Discarding 1626@node Event Input Misc
1599@subsection Peeking and Discarding 1627@subsection Miscellaneous Event Input Features
1628
1629This section describes how to ``peek ahead'' at events without using
1630them up, how to check for pending input, and how to discard pending
1631input.
1600 1632
1601@defvar unread-command-events 1633@defvar unread-command-events
1602@cindex next input 1634@cindex next input
1603@cindex peeking at input 1635@cindex peeking at input
1604This variable holds a list of events waiting to be read as command 1636This variable holds a list of events waiting to be read as command
1605input. The events are used in the order they appear in the list. 1637input. The events are used in the order they appear in the list, and
1638removed one by one as they are used.
1606 1639
1607The variable is used because in some cases a function reads a event and 1640The variable is needed because in some cases a function reads a event
1608then decides not to use it. Storing the event in this variable causes 1641and then decides not to use it. Storing the event in this variable
1609it to be processed normally by the command loop or when the functions to 1642causes it to be processed normally, by the command loop or by the
1610read command input are called. 1643functions to read command input.
1611 1644
1612@cindex prefix argument unreading 1645@cindex prefix argument unreading
1613For example, the function that implements numeric prefix arguments reads 1646For example, the function that implements numeric prefix arguments reads
1614any number of digits. When it finds a non-digit event, it must unread 1647any number of digits. When it finds a non-digit event, it must unread
1615the event so that it can be read normally by the command loop. 1648the event so that it can be read normally by the command loop.
1616Likewise, incremental search uses this feature to unread events it does 1649Likewise, incremental search uses this feature to unread events with no
1617not recognize. 1650special meaning in a search, because these events should exit the search
1651and then execute normally.
1652
1653The reliable and easy way to extract events from a key sequence to put
1654them in @code{unread-command-events} is to use
1655@code{listify-key-sequence} (@pxref{Strings of Events}).
1618@end defvar 1656@end defvar
1619 1657
1620@defvar unread-command-char 1658@defvar unread-command-char
1621This variable holds a character to be read as command input. 1659This variable holds a character to be read as command input.
1622A value of -1 means ``empty''. 1660A value of -1 means ``empty''.
1623 1661
1624This variable is pretty much obsolete now that you can use 1662This variable is mostly obsolete now that you can use
1625@code{unread-command-events} instead; it exists only to support programs 1663@code{unread-command-events} instead; it exists only to support programs
1626written for Emacs versions 18 and earlier. 1664written for Emacs versions 18 and earlier.
1627@end defvar 1665@end defvar
1628 1666
1629@defun listify-key-sequence key
1630This function converts the string or vector @var{key} to a list of
1631events which you can put in @code{unread-command-events}. Converting a
1632vector is simple, but converting a string is tricky because of the
1633special representation used for meta characters in a string
1634(@pxref{Strings of Events}).
1635@end defun
1636
1637@defun input-pending-p 1667@defun input-pending-p
1638@cindex waiting for command key input 1668@cindex waiting for command key input
1639This function determines whether any command input is currently 1669This function determines whether any command input is currently
1640available to be read. It returns immediately, with value @code{t} if 1670available to be read. It returns immediately, with value @code{t} if
1641there is input, @code{nil} otherwise. On rare occasions it may return 1671there is available input, @code{nil} otherwise. On rare occasions it
1642@code{t} when no input is available. 1672may return @code{t} when no input is available.
1643@end defun 1673@end defun
1644 1674
1645@defvar last-input-event 1675@defvar last-input-event
1646@defvarx last-input-char 1676This variable records the last terminal input event read, whether
1647 This variable records the last terminal input event read, whether
1648as part of a command or explicitly by a Lisp program. 1677as part of a command or explicitly by a Lisp program.
1649 1678
1650 In the example below, a character is read (the character @kbd{1}, 1679In the example below, the Lisp program reads the character @kbd{1},
1651@sc{ASCII} code 49). It becomes the value of @code{last-input-char}, 1680@sc{ASCII} code 49. It becomes the value of @code{last-input-event},
1652while @kbd{C-e} (from the @kbd{C-x C-e} command used to evaluate this 1681while @kbd{C-e} (from the @kbd{C-x C-e} command used to evaluate this
1653expression) remains the value of @code{last-command-char}. 1682expression) remains the value of @code{last-command-event}.
1654 1683
1655@example 1684@example
1656@group 1685@group
1657(progn (print (read-char)) 1686(progn (print (read-char))
1658 (print last-command-char) 1687 (print last-command-event)
1659 last-input-char) 1688 last-input-event)
1660 @print{} 49 1689 @print{} 49
1661 @print{} 5 1690 @print{} 5
1662 @result{} 49 1691 @result{} 49
1663@end group 1692@end group
1664@end example 1693@end example
1665 1694
1695@vindex last-input-char
1666The alias @code{last-input-char} exists for compatibility with 1696The alias @code{last-input-char} exists for compatibility with
1667Emacs version 18. 1697Emacs version 18.
1668@end defvar 1698@end defvar
@@ -1677,11 +1707,12 @@ It returns @code{nil}.
1677 1707
1678In the following example, the user may type a number of characters right 1708In the following example, the user may type a number of characters right
1679after starting the evaluation of the form. After the @code{sleep-for} 1709after starting the evaluation of the form. After the @code{sleep-for}
1680finishes sleeping, any characters that have been typed are discarded. 1710finishes sleeping, @code{discard-input} discards any characters typed
1711during the sleep.
1681 1712
1682@example 1713@example
1683(progn (sleep-for 2) 1714(progn (sleep-for 2)
1684 (discard-input)) 1715 (discard-input))
1685 @result{} nil 1716 @result{} nil
1686@end example 1717@end example
1687@end defun 1718@end defun
@@ -1691,19 +1722,19 @@ finishes sleeping, any characters that have been typed are discarded.
1691@cindex pausing 1722@cindex pausing
1692@cindex waiting 1723@cindex waiting
1693 1724
1694 The waiting commands are designed to make Emacs wait for a certain 1725 The wait functions are designed to wait for a certain amount of time
1695amount of time to pass or until there is input. For example, you may 1726to pass or until there is input. For example, you may wish to pause in
1696wish to pause in the middle of a computation to allow the user time to 1727the middle of a computation to allow the user time to view the display.
1697view the display. @code{sit-for} pauses and updates the screen, and 1728@code{sit-for} pauses and updates the screen, and returns immediately if
1698returns immediately if input comes in, while @code{sleep-for} pauses 1729input comes in, while @code{sleep-for} pauses without updating the
1699without updating the screen. 1730screen.
1700 1731
1701@defun sit-for seconds &optional millisec nodisp 1732@defun sit-for seconds &optional millisec nodisp
1702This function performs redisplay (provided there is no pending input 1733This function performs redisplay (provided there is no pending input
1703from the user), then waits @var{seconds} seconds, or until input is 1734from the user), then waits @var{seconds} seconds, or until input is
1704available. The result is @code{t} if @code{sit-for} waited the full 1735available. The value is @code{t} if @code{sit-for} waited the full
1705time with no input arriving (see @code{input-pending-p} in @ref{Peeking 1736time with no input arriving (see @code{input-pending-p} in @ref{Event
1706and Discarding}). Otherwise, the value is @code{nil}. 1737Input Misc}). Otherwise, the value is @code{nil}.
1707 1738
1708@c Emacs 19 feature ??? maybe not working yet 1739@c Emacs 19 feature ??? maybe not working yet
1709The optional argument @var{millisec} specifies an additional waiting 1740The optional argument @var{millisec} specifies an additional waiting
@@ -1769,14 +1800,14 @@ directly when the command reader is reading input is so that its meaning
1769can be redefined in the minibuffer in this way. @kbd{C-g} following a 1800can be redefined in the minibuffer in this way. @kbd{C-g} following a
1770prefix key is not redefined in the minibuffer, and it has its normal 1801prefix key is not redefined in the minibuffer, and it has its normal
1771effect of canceling the prefix key and prefix argument. This too 1802effect of canceling the prefix key and prefix argument. This too
1772would not be possible if @kbd{C-g} quit directly. 1803would not be possible if @kbd{C-g} always quit directly.
1773 1804
1774 @kbd{C-g} causes a quit by setting the variable @code{quit-flag} to a 1805 When @kbd{C-g} does directly quit, it does so by the variable
1775non-@code{nil} value. Emacs checks this variable at appropriate times 1806@code{quit-flag} to @code{t}. Emacs checks this variable at appropriate
1776and quits if it is not @code{nil}. Setting @code{quit-flag} 1807times and quits if it is not @code{nil}. Setting @code{quit-flag}
1777non-@code{nil} in any way thus causes a quit. 1808non-@code{nil} in any way thus causes a quit.
1778 1809
1779 At the level of C code, quits cannot happen just anywhere; only at the 1810 At the level of C code, quitting cannot happen just anywhere; only at the
1780special places which check @code{quit-flag}. The reason for this is 1811special places which check @code{quit-flag}. The reason for this is
1781that quitting at other places might leave an inconsistency in Emacs's 1812that quitting at other places might leave an inconsistency in Emacs's
1782internal state. Because quitting is delayed until a safe place, quitting 1813internal state. Because quitting is delayed until a safe place, quitting
@@ -1804,7 +1835,7 @@ the program.
1804@cindex @code{read-quoted-char} quitting 1835@cindex @code{read-quoted-char} quitting
1805 In some functions (such as @code{read-quoted-char}), @kbd{C-g} is 1836 In some functions (such as @code{read-quoted-char}), @kbd{C-g} is
1806handled in a special way which does not involve quitting. This is done 1837handled in a special way which does not involve quitting. This is done
1807by reading the input with @code{inhibit-quit} bound to @code{t} and 1838by reading the input with @code{inhibit-quit} bound to @code{t}, and
1808setting @code{quit-flag} to @code{nil} before @code{inhibit-quit} 1839setting @code{quit-flag} to @code{nil} before @code{inhibit-quit}
1809becomes @code{nil} again. This excerpt from the definition of 1840becomes @code{nil} again. This excerpt from the definition of
1810@code{read-quoted-char} shows how this is done; it also shows that 1841@code{read-quoted-char} shows how this is done; it also shows that
@@ -1825,8 +1856,8 @@ normal quitting is permitted after the first character of input.
1825@end example 1856@end example
1826 1857
1827@defvar quit-flag 1858@defvar quit-flag
1828If this variable is non-@code{nil}, then Emacs quits immediately, 1859If this variable is non-@code{nil}, then Emacs quits immediately, unless
1829unless @code{inhibit-quit} is non-@code{nil}. Typing @kbd{C-g} sets 1860@code{inhibit-quit} is non-@code{nil}. Typing @kbd{C-g} ordinarily sets
1830@code{quit-flag} non-@code{nil}, regardless of @code{inhibit-quit}. 1861@code{quit-flag} non-@code{nil}, regardless of @code{inhibit-quit}.
1831@end defvar 1862@end defvar
1832 1863
@@ -1887,8 +1918,8 @@ typed, without following digits. The equivalent numeric value is
1887@minus{}1 and the symbol @code{-}. 1918@minus{}1 and the symbol @code{-}.
1888@end itemize 1919@end itemize
1889 1920
1890The various possibilities may be illustrated by calling the following 1921We illustrate these possibilities by calling the following function with
1891function with various prefixes: 1922various prefixes:
1892 1923
1893@example 1924@example
1894@group 1925@group
@@ -1916,11 +1947,11 @@ M-3 M-x display-prefix @print{} 3 ; @r{(Same as @code{C-u 3}.)}
1916 1947
1917C-u - M-x display-prefix @print{} - 1948C-u - M-x display-prefix @print{} -
1918 1949
1919M- - M-x display-prefix @print{} - ; @r{(Same as @code{C-u -}.)} 1950M-- M-x display-prefix @print{} - ; @r{(Same as @code{C-u -}.)}
1920 1951
1921C-u -7 M-x display-prefix @print{} -7 1952C-u - 7 M-x display-prefix @print{} -7
1922 1953
1923M- -7 M-x display-prefix @print{} -7 ; @r{(Same as @code{C-u -7}.)} 1954M-- 7 M-x display-prefix @print{} -7 ; @r{(Same as @code{C-u -7}.)}
1924@end example 1955@end example
1925 1956
1926 Emacs uses two variables to store the prefix argument: 1957 Emacs uses two variables to store the prefix argument:
@@ -1937,6 +1968,27 @@ argument, either numeric or raw, in the @code{interactive} declaration.
1937value of the prefix argument directly in the variable 1968value of the prefix argument directly in the variable
1938@code{current-prefix-arg}, but this is less clean. 1969@code{current-prefix-arg}, but this is less clean.
1939 1970
1971@defun prefix-numeric-value arg
1972This function returns the numeric meaning of a valid raw prefix argument
1973value, @var{arg}. The argument may be a symbol, a number, or a list.
1974If it is @code{nil}, the value 1 is returned; if it is any other symbol,
1975the value @minus{}1 is returned. If it is a number, that number is
1976returned; if it is a list, the @sc{car} of that list (which should be a
1977number) is returned.
1978@end defun
1979
1980@defvar current-prefix-arg
1981This variable holds the raw prefix argument for the @emph{current}
1982command. Commands may examine it directly, but the usual way to access
1983it is with @code{(interactive "P")}.
1984@end defvar
1985
1986@defvar prefix-arg
1987The value of this variable is the raw prefix argument for the
1988@emph{next} editing command. Commands that specify prefix arguments for
1989the following command work by setting this variable.
1990@end defvar
1991
1940 Do not call the functions @code{universal-argument}, 1992 Do not call the functions @code{universal-argument},
1941@code{digit-argument}, or @code{negative-argument} unless you intend to 1993@code{digit-argument}, or @code{negative-argument} unless you intend to
1942let the user enter the prefix argument for the @emph{next} command. 1994let the user enter the prefix argument for the @emph{next} command.
@@ -1961,47 +2013,26 @@ command; its value is negated to form the new prefix argument. Don't
1961call this command yourself unless you know what you are doing. 2013call this command yourself unless you know what you are doing.
1962@end deffn 2014@end deffn
1963 2015
1964@defun prefix-numeric-value arg
1965This function returns the numeric meaning of a valid raw prefix argument
1966value, @var{arg}. The argument may be a symbol, a number, or a list.
1967If it is @code{nil}, the value 1 is returned; if it is any other symbol,
1968the value @minus{}1 is returned. If it is a number, that number is
1969returned; if it is a list, the @sc{car} of that list (which should be a
1970number) is returned.
1971@end defun
1972
1973@defvar current-prefix-arg
1974This variable is the value of the raw prefix argument for the
1975@emph{current} command. Commands may examine it directly, but the usual
1976way to access it is with @code{(interactive "P")}.
1977@end defvar
1978
1979@defvar prefix-arg
1980The value of this variable is the raw prefix argument for the
1981@emph{next} editing command. Commands that specify prefix arguments for
1982the following command work by setting this variable.
1983@end defvar
1984
1985@node Recursive Editing 2016@node Recursive Editing
1986@section Recursive Editing 2017@section Recursive Editing
1987@cindex recursive command loop 2018@cindex recursive command loop
1988@cindex recursive editing level 2019@cindex recursive editing level
1989@cindex command loop, recursive 2020@cindex command loop, recursive
1990 2021
1991 The Emacs command loop is entered automatically when Emacs starts up. 2022 The Emacs command loop is entered automatically when Emacs starts up.
1992This top-level invocation of the command loop is never exited until the 2023This top-level invocation of the command loop never exits; it keeps
1993Emacs is killed. Lisp programs can also invoke the command loop. Since 2024running as long as Emacs does. Lisp programs can also invoke the
1994this makes more than one activation of the command loop, we call it 2025command loop. Since this makes more than one activation of the command
1995@dfn{recursive editing}. A recursive editing level has the effect of 2026loop, we call it @dfn{recursive editing}. A recursive editing level has
1996suspending whatever command invoked it and permitting the user to do 2027the effect of suspending whatever command invoked it and permitting the
1997arbitrary editing before resuming that command. 2028user to do arbitrary editing before resuming that command.
1998 2029
1999 The commands available during recursive editing are the same ones 2030 The commands available during recursive editing are the same ones
2000available in the top-level editing loop and defined in the keymaps. 2031available in the top-level editing loop and defined in the keymaps.
2001Only a few special commands exit the recursive editing level; the others 2032Only a few special commands exit the recursive editing level; the others
2002return to the recursive editing level when finished. (The special 2033return to the recursive editing level when they finish. (The special
2003commands for exiting are always available, but do nothing when recursive 2034commands for exiting are always available, but they do nothing when
2004editing is not in progress.) 2035recursive editing is not in progress.)
2005 2036
2006 All command loops, including recursive ones, set up all-purpose error 2037 All command loops, including recursive ones, set up all-purpose error
2007handlers so that an error in a command run from the command loop will 2038handlers so that an error in a command run from the command loop will
@@ -2033,12 +2064,12 @@ control returns to the command loop one level up. This is called
2033 Most applications should not use recursive editing, except as part of 2064 Most applications should not use recursive editing, except as part of
2034using the minibuffer. Usually it is more convenient for the user if you 2065using the minibuffer. Usually it is more convenient for the user if you
2035change the major mode of the current buffer temporarily to a special 2066change the major mode of the current buffer temporarily to a special
2036major mode, which has a command to go back to the previous mode. (This 2067major mode, which has a command to go back to the previous mode. (The
2037technique is used by the @kbd{w} command in Rmail.) Or, if you wish to 2068@kbd{e} command in Rmail uses this technique.) Or, if you wish to give
2038give the user different text to edit ``recursively'', create and select 2069the user different text to edit ``recursively'', create and select a new
2039a new buffer in a special mode. In this mode, define a command to 2070buffer in a special mode. In this mode, define a command to complete
2040complete the processing and go back to the previous buffer. (The 2071the processing and go back to the previous buffer. (The @kbd{m} command
2041@kbd{m} command in Rmail does this.) 2072in Rmail does this.)
2042 2073
2043 Recursive edits are useful in debugging. You can insert a call to 2074 Recursive edits are useful in debugging. You can insert a call to
2044@code{debug} into a function definition as a sort of breakpoint, so that 2075@code{debug} into a function definition as a sort of breakpoint, so that
@@ -2063,7 +2094,7 @@ then type @kbd{C-M-c} to exit and continue executing @code{simple-rec}.
2063@example 2094@example
2064(defun simple-rec () 2095(defun simple-rec ()
2065 (forward-word 1) 2096 (forward-word 1)
2066 (message "Recursive edit in progress.") 2097 (message "Recursive edit in progress")
2067 (recursive-edit) 2098 (recursive-edit)
2068 (forward-word 1)) 2099 (forward-word 1))
2069 @result{} simple-rec 2100 @result{} simple-rec
@@ -2119,8 +2150,8 @@ command. These properties are normally set up by the user's
2119For a few commands, these properties are present by default and may be 2150For a few commands, these properties are present by default and may be
2120removed by the @file{.emacs} file. 2151removed by the @file{.emacs} file.
2121 2152
2122 If the value of the @code{disabled} property is a string, that string 2153 If the value of the @code{disabled} property is a string, the message
2123is included in the message printed when the command is used: 2154saying the command is disabled includes that string. For example:
2124 2155
2125@example 2156@example
2126(put 'delete-region 'disabled 2157(put 'delete-region 'disabled
@@ -2134,21 +2165,21 @@ programs.
2134 2165
2135@deffn Command enable-command command 2166@deffn Command enable-command command
2136Allow @var{command} to be executed without special confirmation from now 2167Allow @var{command} to be executed without special confirmation from now
2137on. The user's @file{.emacs} file is optionally altered so that this 2168on, and optionally alter the user's @file{.emacs} file so that this will
2138will apply to future sessions. 2169apply to future sessions.
2139@end deffn 2170@end deffn
2140 2171
2141@deffn Command disable-command command 2172@deffn Command disable-command command
2142Require special confirmation to execute @var{command} from now on. The 2173Require special confirmation to execute @var{command} from now on, and
2143user's @file{.emacs} file is optionally altered so that this will apply 2174optionally alter the user's @file{.emacs} file so that this will apply
2144to future sessions. 2175to future sessions.
2145@end deffn 2176@end deffn
2146 2177
2147@defvar disabled-command-hook 2178@defvar disabled-command-hook
2148This variable is a normal hook that is run instead of a disabled command, 2179This normal hook is run instead of a disabled command, when the user
2149when the user runs the disabled command interactively. The hook functions 2180invokes the disabled command interactively. The hook functions can use
2150can use @code{this-command-keys} to determine what the user typed to run 2181@code{this-command-keys} to determine what the user typed to run the
2151the command, and thus find the command itself. 2182command, and thus find the command itself.
2152 2183
2153By default, @code{disabled-command-hook} contains a function that asks 2184By default, @code{disabled-command-hook} contains a function that asks
2154the user whether to proceed. 2185the user whether to proceed.
@@ -2203,8 +2234,10 @@ minibuffer.
2203@cindex keyboard macros 2234@cindex keyboard macros
2204 2235
2205 A @dfn{keyboard macro} is a canned sequence of input events that can 2236 A @dfn{keyboard macro} is a canned sequence of input events that can
2206be considered a command and made the definition of a key. Don't confuse 2237be considered a command and made the definition of a key. The Lisp
2207keyboard macros with Lisp macros (@pxref{Macros}). 2238representation of a keyboard macro is a string or vector containing the
2239events. Don't confuse keyboard macros with Lisp macros
2240(@pxref{Macros}).
2208 2241
2209@defun execute-kbd-macro macro &optional count 2242@defun execute-kbd-macro macro &optional count
2210This function executes @var{macro} as a sequence of events. If 2243This function executes @var{macro} as a sequence of events. If
@@ -2232,26 +2265,15 @@ macro. Its value is a string or vector, or @code{nil}.
2232@defvar executing-macro 2265@defvar executing-macro
2233This variable contains the string or vector that defines the keyboard 2266This variable contains the string or vector that defines the keyboard
2234macro that is currently executing. It is @code{nil} if no macro is 2267macro that is currently executing. It is @code{nil} if no macro is
2235currently executing. 2268currently executing. A command can test this variable to behave
2269differently when run from an executing macro. Do not set this variable
2270yourself.
2236@end defvar 2271@end defvar
2237 2272
2238@defvar defining-kbd-macro 2273@defvar defining-kbd-macro
2239This variable indicates whether a keyboard macro is being defined. It 2274This variable indicates whether a keyboard macro is being defined. A
2240is set to @code{t} by @code{start-kbd-macro}, and @code{nil} by 2275command can test this variable to behave differently while a macro is
2241@code{end-kbd-macro}. You can use this variable to make a command 2276being defined. The commands @code{start-kbd-macro} and
2242behave differently when run from a keyboard macro (perhaps indirectly by 2277@code{end-kbd-macro} set this variable---do not set it yourself.
2243calling @code{interactive-p}). However, do not set this variable
2244yourself.
2245@end defvar 2278@end defvar
2246 2279
2247@ignore @c It's hard to make this format ok.
2248 The user-level commands for defining, running and editing keyboard
2249macros include @code{call-last-kbd-macro}, @code{insert-kbd-macro},
2250@code{start-kbd-macro}, @code{end-kbd-macro}, @code{kbd-macro-query},
2251and @code{name-last-kbd-macro}.
2252@end ignore
2253
2254@c Broke paragraph to prevent overfull hbox. --rjc 15mar92
2255 The commands are described in the user's manual (@pxref{Keyboard
2256Macros,,, emacs, The GNU Emacs Manual}).
2257