1 This is ../info/lispref.info, produced by makeinfo version 4.0 from
4 INFO-DIR-SECTION XEmacs Editor
6 * Lispref: (lispref). XEmacs Lisp Reference Manual.
11 GNU Emacs Lisp Reference Manual Second Edition (v2.01), May 1993 GNU
12 Emacs Lisp Reference Manual Further Revised (v2.02), August 1993 Lucid
13 Emacs Lisp Reference Manual (for 19.10) First Edition, March 1994
14 XEmacs Lisp Programmer's Manual (for 19.12) Second Edition, April 1995
15 GNU Emacs Lisp Reference Manual v2.4, June 1995 XEmacs Lisp
16 Programmer's Manual (for 19.13) Third Edition, July 1995 XEmacs Lisp
17 Reference Manual (for 19.14 and 20.0) v3.1, March 1996 XEmacs Lisp
18 Reference Manual (for 19.15 and 20.1, 20.2, 20.3) v3.2, April, May,
19 November 1997 XEmacs Lisp Reference Manual (for 21.0) v3.3, April 1998
21 Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Free Software
22 Foundation, Inc. Copyright (C) 1994, 1995 Sun Microsystems, Inc.
23 Copyright (C) 1995, 1996 Ben Wing.
25 Permission is granted to make and distribute verbatim copies of this
26 manual provided the copyright notice and this permission notice are
27 preserved on all copies.
29 Permission is granted to copy and distribute modified versions of
30 this manual under the conditions for verbatim copying, provided that the
31 entire resulting derived work is distributed under the terms of a
32 permission notice identical to this one.
34 Permission is granted to copy and distribute translations of this
35 manual into another language, under the above conditions for modified
36 versions, except that this permission notice may be stated in a
37 translation approved by the Foundation.
39 Permission is granted to copy and distribute modified versions of
40 this manual under the conditions for verbatim copying, provided also
41 that the section entitled "GNU General Public License" is included
42 exactly as in the original, and provided that the entire resulting
43 derived work is distributed under the terms of a permission notice
44 identical to this one.
46 Permission is granted to copy and distribute translations of this
47 manual into another language, under the above conditions for modified
48 versions, except that the section entitled "GNU General Public License"
49 may be included in a translation approved by the Free Software
50 Foundation instead of in the original English.
53 File: lispref.info, Node: Completion Commands, Next: High-Level Completion, Prev: Minibuffer Completion, Up: Completion
55 Minibuffer Commands That Do Completion
56 --------------------------------------
58 This section describes the keymaps, commands and user options used in
59 the minibuffer to do completion.
61 - Variable: minibuffer-local-completion-map
62 `completing-read' uses this value as the local keymap when an
63 exact match of one of the completions is not required. By
64 default, this keymap makes the following bindings:
67 `minibuffer-completion-help'
70 `minibuffer-complete-word'
75 with other characters bound as in `minibuffer-local-map' (*note
76 Text from Minibuffer::).
78 - Variable: minibuffer-local-must-match-map
79 `completing-read' uses this value as the local keymap when an
80 exact match of one of the completions is required. Therefore, no
81 keys are bound to `exit-minibuffer', the command that exits the
82 minibuffer unconditionally. By default, this keymap makes the
86 `minibuffer-completion-help'
89 `minibuffer-complete-word'
95 `minibuffer-complete-and-exit'
98 `minibuffer-complete-and-exit'
100 with other characters bound as in `minibuffer-local-map'.
102 - Variable: minibuffer-completion-table
103 The value of this variable is the alist or obarray used for
104 completion in the minibuffer. This is the global variable that
105 contains what `completing-read' passes to `try-completion'. It is
106 used by minibuffer completion commands such as
107 `minibuffer-complete-word'.
109 - Variable: minibuffer-completion-predicate
110 This variable's value is the predicate that `completing-read'
111 passes to `try-completion'. The variable is also used by the other
112 minibuffer completion functions.
114 - Command: minibuffer-complete-word
115 This function completes the minibuffer contents by at most a single
116 word. Even if the minibuffer contents have only one completion,
117 `minibuffer-complete-word' does not add any characters beyond the
118 first character that is not a word constituent. *Note Syntax
121 - Command: minibuffer-complete
122 This function completes the minibuffer contents as far as possible.
124 - Command: minibuffer-complete-and-exit
125 This function completes the minibuffer contents, and exits if
126 confirmation is not required, i.e., if
127 `minibuffer-completion-confirm' is `nil'. If confirmation _is_
128 required, it is given by repeating this command immediately--the
129 command is programmed to work without confirmation when run twice
132 - Variable: minibuffer-completion-confirm
133 When the value of this variable is non-`nil', XEmacs asks for
134 confirmation of a completion before exiting the minibuffer. The
135 function `minibuffer-complete-and-exit' checks the value of this
136 variable before it exits.
138 - Command: minibuffer-completion-help
139 This function creates a list of the possible completions of the
140 current minibuffer contents. It works by calling `all-completions'
141 using the value of the variable `minibuffer-completion-table' as
142 the COLLECTION argument, and the value of
143 `minibuffer-completion-predicate' as the PREDICATE argument. The
144 list of completions is displayed as text in a buffer named
147 - Function: display-completion-list completions &rest cl-keys
148 This function displays COMPLETIONS to the stream in
149 `standard-output', usually a buffer. (*Note Read and Print::, for
150 more information about streams.) The argument COMPLETIONS is
151 normally a list of completions just returned by `all-completions',
152 but it does not have to be. Each element may be a symbol or a
153 string, either of which is simply printed, or a list of two
154 strings, which is printed as if the strings were concatenated.
156 This function is called by `minibuffer-completion-help'. The most
157 common way to use it is together with
158 `with-output-to-temp-buffer', like this:
160 (with-output-to-temp-buffer "*Completions*"
161 (display-completion-list
162 (all-completions (buffer-string) my-alist)))
164 - User Option: completion-auto-help
165 If this variable is non-`nil', the completion commands
166 automatically display a list of possible completions whenever
167 nothing can be completed because the next character is not
171 File: lispref.info, Node: High-Level Completion, Next: Reading File Names, Prev: Completion Commands, Up: Completion
173 High-Level Completion Functions
174 --------------------------------
176 This section describes the higher-level convenient functions for
177 reading certain sorts of names with completion.
179 In most cases, you should not call these functions in the middle of a
180 Lisp function. When possible, do all minibuffer input as part of
181 reading the arguments for a command, in the `interactive' spec. *Note
184 - Function: read-buffer prompt &optional default existing
185 This function reads the name of a buffer and returns it as a
186 string. The argument DEFAULT is the default name to use, the
187 value to return if the user exits with an empty minibuffer. If
188 non-`nil', it should be a string or a buffer. It is mentioned in
189 the prompt, but is not inserted in the minibuffer as initial input.
191 If EXISTING is non-`nil', then the name specified must be that of
192 an existing buffer. The usual commands to exit the minibuffer do
193 not exit if the text is not valid, and <RET> does completion to
194 attempt to find a valid name. (However, DEFAULT is not checked
195 for validity; it is returned, whatever it is, if the user exits
196 with the minibuffer empty.)
198 In the following example, the user enters `minibuffer.t', and then
199 types <RET>. The argument EXISTING is `t', and the only buffer
200 name starting with the given input is `minibuffer.texi', so that
203 (read-buffer "Buffer name? " "foo" t)
204 ;; After evaluation of the preceding expression,
205 ;; the following prompt appears,
206 ;; with an empty minibuffer:
208 ---------- Buffer: Minibuffer ----------
209 Buffer name? (default foo) -!-
210 ---------- Buffer: Minibuffer ----------
212 ;; The user types `minibuffer.t <RET>'.
215 - Function: read-command prompt &optional default-value
216 This function reads the name of a command and returns it as a Lisp
217 symbol. The argument PROMPT is used as in `read-from-minibuffer'.
218 Recall that a command is anything for which `commandp' returns
219 `t', and a command name is a symbol for which `commandp' returns
220 `t'. *Note Interactive Call::.
222 The argument DEFAULT-VALUE specifies what to return if the user
223 enters null input. It can be a symbol or a string; if it is a
224 string, `read-command' interns it before returning it. If DEFAULT
225 is `nil', that means no default has been specified; then if the
226 user enters null input, the return value is `nil'.
228 (read-command "Command name? ")
230 ;; After evaluation of the preceding expression,
231 ;; the following prompt appears with an empty minibuffer:
233 ---------- Buffer: Minibuffer ----------
235 ---------- Buffer: Minibuffer ----------
237 If the user types `forward-c <RET>', then this function returns
240 The `read-command' function is a simplified interface to the
241 function `completing-read'. It uses the variable `obarray' so as
242 to complete in the set of extant Lisp symbols, and it uses the
243 `commandp' predicate so as to accept only command names:
245 (read-command PROMPT)
247 (intern (completing-read PROMPT obarray
250 - Function: read-variable prompt &optional default-value
251 This function reads the name of a user variable and returns it as a
254 The argument DEFAULT-VALUE specifies what to return if the user
255 enters null input. It can be a symbol or a string; if it is a
256 string, `read-variable' interns it before returning it. If DEFAULT
257 is `nil', that means no default has been specified; then if the
258 user enters null input, the return value is `nil'.
260 (read-variable "Variable name? ")
262 ;; After evaluation of the preceding expression,
263 ;; the following prompt appears,
264 ;; with an empty minibuffer:
266 ---------- Buffer: Minibuffer ----------
268 ---------- Buffer: Minibuffer ----------
270 If the user then types `fill-p <RET>', `read-variable' returns
273 This function is similar to `read-command', but uses the predicate
274 `user-variable-p' instead of `commandp':
276 (read-variable PROMPT)
279 (completing-read PROMPT obarray
280 'user-variable-p t nil))
283 File: lispref.info, Node: Reading File Names, Next: Programmed Completion, Prev: High-Level Completion, Up: Completion
288 Here is another high-level completion function, designed for reading
289 a file name. It provides special features including automatic insertion
290 of the default directory.
292 - Function: read-file-name prompt &optional directory default existing
294 This function reads a file name in the minibuffer, prompting with
295 PROMPT and providing completion. If DEFAULT is non-`nil', then
296 the function returns DEFAULT if the user just types <RET>.
297 DEFAULT is not checked for validity; it is returned, whatever it
298 is, if the user exits with the minibuffer empty.
300 If EXISTING is non-`nil', then the user must specify the name of
301 an existing file; <RET> performs completion to make the name valid
302 if possible, and then refuses to exit if it is not valid. If the
303 value of EXISTING is neither `nil' nor `t', then <RET> also
304 requires confirmation after completion. If EXISTING is `nil',
305 then the name of a nonexistent file is acceptable.
307 The argument DIRECTORY specifies the directory to use for
308 completion of relative file names. If `insert-default-directory'
309 is non-`nil', DIRECTORY is also inserted in the minibuffer as
310 initial input. It defaults to the current buffer's value of
313 If you specify INITIAL, that is an initial file name to insert in
314 the buffer (after DIRECTORY, if that is inserted). In this case,
315 point goes at the beginning of INITIAL. The default for INITIAL
316 is `nil'--don't insert any file name. To see what INITIAL does,
317 try the command `C-x C-v'.
321 (read-file-name "The file is ")
323 ;; After evaluation of the preceding expression,
324 ;; the following appears in the minibuffer:
326 ---------- Buffer: Minibuffer ----------
327 The file is /gp/gnu/elisp/-!-
328 ---------- Buffer: Minibuffer ----------
330 Typing `manual <TAB>' results in the following:
332 ---------- Buffer: Minibuffer ----------
333 The file is /gp/gnu/elisp/manual.texi-!-
334 ---------- Buffer: Minibuffer ----------
336 If the user types <RET>, `read-file-name' returns the file name as
337 the string `"/gp/gnu/elisp/manual.texi"'.
339 - User Option: insert-default-directory
340 This variable is used by `read-file-name'. Its value controls
341 whether `read-file-name' starts by placing the name of the default
342 directory in the minibuffer, plus the initial file name if any.
343 If the value of this variable is `nil', then `read-file-name' does
344 not place any initial input in the minibuffer (unless you specify
345 initial input with the INITIAL argument). In that case, the
346 default directory is still used for completion of relative file
347 names, but is not displayed.
351 ;; Here the minibuffer starts out with the default directory.
352 (let ((insert-default-directory t))
353 (read-file-name "The file is "))
355 ---------- Buffer: Minibuffer ----------
356 The file is ~lewis/manual/-!-
357 ---------- Buffer: Minibuffer ----------
359 ;; Here the minibuffer is empty and only the prompt
360 ;; appears on its line.
361 (let ((insert-default-directory nil))
362 (read-file-name "The file is "))
364 ---------- Buffer: Minibuffer ----------
366 ---------- Buffer: Minibuffer ----------
369 File: lispref.info, Node: Programmed Completion, Prev: Reading File Names, Up: Completion
371 Programmed Completion
372 ---------------------
374 Sometimes it is not possible to create an alist or an obarray
375 containing all the intended possible completions. In such a case, you
376 can supply your own function to compute the completion of a given
377 string. This is called "programmed completion".
379 To use this feature, pass a symbol with a function definition as the
380 COLLECTION argument to `completing-read'. The function
381 `completing-read' arranges to pass your completion function along to
382 `try-completion' and `all-completions', which will then let your
383 function do all the work.
385 The completion function should accept three arguments:
387 * The string to be completed.
389 * The predicate function to filter possible matches, or `nil' if
390 none. Your function should call the predicate for each possible
391 match, and ignore the possible match if the predicate returns
394 * A flag specifying the type of operation.
396 There are three flag values for three operations:
398 * `nil' specifies `try-completion'. The completion function should
399 return the completion of the specified string, or `t' if the
400 string is a unique and exact match already, or `nil' if the string
401 matches no possibility.
403 If the string is an exact match for one possibility, but also
404 matches other longer possibilities, the function should return the
407 * `t' specifies `all-completions'. The completion function should
408 return a list of all possible completions of the specified string.
410 * `lambda' specifies a test for an exact match. The completion
411 function should return `t' if the specified string is an exact
412 match for some possibility; `nil' otherwise.
414 It would be consistent and clean for completion functions to allow
415 lambda expressions (lists that are functions) as well as function
416 symbols as COLLECTION, but this is impossible. Lists as completion
417 tables are already assigned another meaning--as alists. It would be
418 unreliable to fail to handle an alist normally because it is also a
419 possible function. So you must arrange for any function you wish to
420 use for completion to be encapsulated in a symbol.
422 Emacs uses programmed completion when completing file names. *Note
423 File Name Completion::.
426 File: lispref.info, Node: Yes-or-No Queries, Next: Multiple Queries, Prev: Completion, Up: Minibuffers
431 This section describes functions used to ask the user a yes-or-no
432 question. The function `y-or-n-p' can be answered with a single
433 character; it is useful for questions where an inadvertent wrong answer
434 will not have serious consequences. `yes-or-no-p' is suitable for more
435 momentous questions, since it requires three or four characters to
436 answer. Variations of these functions can be used to ask a yes-or-no
437 question using a dialog box, or optionally using one.
439 If either of these functions is called in a command that was invoked
440 using the mouse, then it uses a dialog box or pop-up menu to ask the
441 question. Otherwise, it uses keyboard input.
443 Strictly speaking, `yes-or-no-p' uses the minibuffer and `y-or-n-p'
444 does not; but it seems best to describe them together.
446 - Function: y-or-n-p prompt
447 This function asks the user a question, expecting input in the echo
448 area. It returns `t' if the user types `y', `nil' if the user
449 types `n'. This function also accepts <SPC> to mean yes and <DEL>
450 to mean no. It accepts `C-]' to mean "quit", like `C-g', because
451 the question might look like a minibuffer and for that reason the
452 user might try to use `C-]' to get out. The answer is a single
453 character, with no <RET> needed to terminate it. Upper and lower
456 "Asking the question" means printing PROMPT in the echo area,
457 followed by the string `(y or n) '. If the input is not one of
458 the expected answers (`y', `n', `<SPC>', `<DEL>', or something
459 that quits), the function responds `Please answer y or n.', and
462 This function does not actually use the minibuffer, since it does
463 not allow editing of the answer. It actually uses the echo area
464 (*note The Echo Area::), which uses the same screen space as the
465 minibuffer. The cursor moves to the echo area while the question
468 The answers and their meanings, even `y' and `n', are not
469 hardwired. The keymap `query-replace-map' specifies them. *Note
470 Search and Replace::.
472 In the following example, the user first types `q', which is
473 invalid. At the next prompt the user types `y'.
475 (y-or-n-p "Do you need a lift? ")
477 ;; After evaluation of the preceding expression,
478 ;; the following prompt appears in the echo area:
480 ---------- Echo area ----------
481 Do you need a lift? (y or n)
482 ---------- Echo area ----------
484 ;; If the user then types `q', the following appears:
486 ---------- Echo area ----------
487 Please answer y or n. Do you need a lift? (y or n)
488 ---------- Echo area ----------
490 ;; When the user types a valid answer,
491 ;; it is displayed after the question:
493 ---------- Echo area ----------
494 Do you need a lift? (y or n) y
495 ---------- Echo area ----------
497 We show successive lines of echo area messages, but only one
498 actually appears on the screen at a time.
500 - Function: yes-or-no-p prompt
501 This function asks the user a question, expecting input in the
502 minibuffer. It returns `t' if the user enters `yes', `nil' if the
503 user types `no'. The user must type <RET> to finalize the
504 response. Upper and lower case are equivalent.
506 `yes-or-no-p' starts by displaying PROMPT in the echo area,
507 followed by `(yes or no) '. The user must type one of the
508 expected responses; otherwise, the function responds `Please answer
509 yes or no.', waits about two seconds and repeats the request.
511 `yes-or-no-p' requires more work from the user than `y-or-n-p' and
512 is appropriate for more crucial decisions.
516 (yes-or-no-p "Do you really want to remove everything? ")
518 ;; After evaluation of the preceding expression,
519 ;; the following prompt appears,
520 ;; with an empty minibuffer:
522 ---------- Buffer: minibuffer ----------
523 Do you really want to remove everything? (yes or no)
524 ---------- Buffer: minibuffer ----------
526 If the user first types `y <RET>', which is invalid because this
527 function demands the entire word `yes', it responds by displaying
528 these prompts, with a brief pause between them:
530 ---------- Buffer: minibuffer ----------
531 Please answer yes or no.
532 Do you really want to remove everything? (yes or no)
533 ---------- Buffer: minibuffer ----------
535 - Function: yes-or-no-p-dialog-box prompt
536 This function asks the user a "y or n" question with a popup dialog
537 box. It returns `t' if the answer is "yes". PROMPT is the string
538 to display to ask the question.
540 The following functions ask a question either in the minibuffer or a
541 dialog box, depending on whether the last user event (which presumably
542 invoked this command) was a keyboard or mouse event. When XEmacs is
543 running on a window system, the functions `y-or-n-p' and `yes-or-no-p'
544 are replaced with the following functions, so that menu items bring up
545 dialog boxes instead of minibuffer questions.
547 - Function: y-or-n-p-maybe-dialog-box prompt
548 This function asks user a "y or n" question, using either a dialog
549 box or the minibuffer, as appropriate.
551 - Function: yes-or-no-p-maybe-dialog-box prompt
552 This function asks user a "yes or no" question, using either a
553 dialog box or the minibuffer, as appropriate.
556 File: lispref.info, Node: Multiple Queries, Next: Reading a Password, Prev: Yes-or-No Queries, Up: Minibuffers
558 Asking Multiple Y-or-N Questions
559 ================================
561 When you have a series of similar questions to ask, such as "Do you
562 want to save this buffer" for each buffer in turn, you should use
563 `map-y-or-n-p' to ask the collection of questions, rather than asking
564 each question individually. This gives the user certain convenient
565 facilities such as the ability to answer the whole series at once.
567 - Function: map-y-or-n-p prompter actor list &optional help
569 This function, new in Emacs 19, asks the user a series of
570 questions, reading a single-character answer in the echo area for
573 The value of LIST specifies the objects to ask questions about.
574 It should be either a list of objects or a generator function. If
575 it is a function, it should expect no arguments, and should return
576 either the next object to ask about, or `nil' meaning stop asking
579 The argument PROMPTER specifies how to ask each question. If
580 PROMPTER is a string, the question text is computed like this:
582 (format PROMPTER OBJECT)
584 where OBJECT is the next object to ask about (as obtained from
587 If not a string, PROMPTER should be a function of one argument
588 (the next object to ask about) and should return the question
589 text. If the value is a string, that is the question to ask the
590 user. The function can also return `t' meaning do act on this
591 object (and don't ask the user), or `nil' meaning ignore this
592 object (and don't ask the user).
594 The argument ACTOR says how to act on the answers that the user
595 gives. It should be a function of one argument, and it is called
596 with each object that the user says yes for. Its argument is
597 always an object obtained from LIST.
599 If the argument HELP is given, it should be a list of this form:
601 (SINGULAR PLURAL ACTION)
603 where SINGULAR is a string containing a singular noun that
604 describes the objects conceptually being acted on, PLURAL is the
605 corresponding plural noun, and ACTION is a transitive verb
606 describing what ACTOR does.
608 If you don't specify HELP, the default is `("object" "objects"
611 Each time a question is asked, the user may enter `y', `Y', or
612 <SPC> to act on that object; `n', `N', or <DEL> to skip that
613 object; `!' to act on all following objects; <ESC> or `q' to exit
614 (skip all following objects); `.' (period) to act on the current
615 object and then exit; or `C-h' to get help. These are the same
616 answers that `query-replace' accepts. The keymap
617 `query-replace-map' defines their meaning for `map-y-or-n-p' as
618 well as for `query-replace'; see *Note Search and Replace::.
620 You can use ACTION-ALIST to specify additional possible answers
621 and what they mean. It is an alist of elements of the form `(CHAR
622 FUNCTION HELP)', each of which defines one additional answer. In
623 this element, CHAR is a character (the answer); FUNCTION is a
624 function of one argument (an object from LIST); HELP is a string.
626 When the user responds with CHAR, `map-y-or-n-p' calls FUNCTION.
627 If it returns non-`nil', the object is considered "acted upon",
628 and `map-y-or-n-p' advances to the next object in LIST. If it
629 returns `nil', the prompt is repeated for the same object.
631 If `map-y-or-n-p' is called in a command that was invoked using the
632 mouse--more precisely, if `last-nonmenu-event' (*note Command Loop
633 Info::) is either `nil' or a list--then it uses a dialog box or
634 pop-up menu to ask the question. In this case, it does not use
635 keyboard input or the echo area. You can force use of the mouse
636 or use of keyboard input by binding `last-nonmenu-event' to a
637 suitable value around the call.
639 The return value of `map-y-or-n-p' is the number of objects acted
643 File: lispref.info, Node: Reading a Password, Next: Minibuffer Misc, Prev: Multiple Queries, Up: Minibuffers
648 To read a password to pass to another program, you can use the
649 function `read-passwd'.
651 - Function: read-passwd prompt &optional confirm default
652 This function reads a password, prompting with PROMPT. It does
653 not echo the password as the user types it; instead, it echoes `.'
654 for each character in the password.
656 The optional argument CONFIRM, if non-`nil', says to read the
657 password twice and insist it must be the same both times. If it
658 isn't the same, the user has to type it over and over until the
659 last two times match.
661 The optional argument DEFAULT specifies the default password to
662 return if the user enters empty input. It is translated to `.'
663 and inserted in the minibuffer. If DEFAULT is `nil', then
664 `read-passwd' returns the null string in that case.
666 - User Option: passwd-invert-frame-when-keyboard-grabbed
667 If non-nil swap the foreground and background colors of all faces
668 while reading a password. Default values is `t' unless feature
669 `infodock' is provided.
671 - User Option: passwd-echo
672 This specifies the character echoed when typing a password. When
673 nil, nothing is echoed.
676 File: lispref.info, Node: Minibuffer Misc, Prev: Reading a Password, Up: Minibuffers
678 Minibuffer Miscellany
679 =====================
681 This section describes some basic functions and variables related to
684 - Command: exit-minibuffer
685 This command exits the active minibuffer. It is normally bound to
686 keys in minibuffer local keymaps.
688 - Command: self-insert-and-exit
689 This command exits the active minibuffer after inserting the last
690 character typed on the keyboard (found in `last-command-char';
691 *note Command Loop Info::).
693 - Command: previous-history-element n
694 This command replaces the minibuffer contents with the value of the
695 Nth previous (older) history element.
697 - Command: next-history-element n
698 This command replaces the minibuffer contents with the value of the
699 Nth more recent history element.
701 - Command: previous-matching-history-element pattern
702 This command replaces the minibuffer contents with the value of the
703 previous (older) history element that matches PATTERN (a regular
706 - Command: next-matching-history-element pattern
707 This command replaces the minibuffer contents with the value of
708 the next (newer) history element that matches PATTERN (a regular
711 - Function: minibuffer-prompt
712 This function returns the prompt string of the currently active
713 minibuffer. If no minibuffer is active, it returns `nil'.
715 - Function: minibuffer-prompt-width
716 This function returns the display width of the prompt string of the
717 currently active minibuffer. If no minibuffer is active, it
720 - Variable: minibuffer-setup-hook
721 This is a normal hook that is run whenever the minibuffer is
722 entered. *Note Hooks::.
724 - Variable: minibuffer-exit-hook
725 This is a normal hook that is run whenever the minibuffer is
726 exited. *Note Hooks::.
728 - Variable: minibuffer-help-form
729 The current value of this variable is used to rebind `help-form'
730 locally inside the minibuffer (*note Help Functions::).
732 - Function: active-minibuffer-window
733 This function returns the currently active minibuffer window, or
734 `nil' if none is currently active.
736 - Function: minibuffer-window &optional frame
737 This function returns the minibuffer window used for frame FRAME.
738 If FRAME is `nil', that stands for the current frame. Note that
739 the minibuffer window used by a frame need not be part of that
740 frame--a frame that has no minibuffer of its own necessarily uses
741 some other frame's minibuffer window.
743 - Function: window-minibuffer-p window
744 This function returns non-`nil' if WINDOW is a minibuffer window.
746 It is not correct to determine whether a given window is a
747 minibuffer by comparing it with the result of `(minibuffer-window)',
748 because there can be more than one minibuffer window if there is more
751 - Function: minibuffer-window-active-p window
752 This function returns non-`nil' if WINDOW, assumed to be a
753 minibuffer window, is currently active.
755 - Variable: minibuffer-scroll-window
756 If the value of this variable is non-`nil', it should be a window
757 object. When the function `scroll-other-window' is called in the
758 minibuffer, it scrolls this window.
760 Finally, some functions and variables deal with recursive minibuffers
761 (*note Recursive Editing::):
763 - Function: minibuffer-depth
764 This function returns the current depth of activations of the
765 minibuffer, a nonnegative integer. If no minibuffers are active,
768 - User Option: enable-recursive-minibuffers
769 If this variable is non-`nil', you can invoke commands (such as
770 `find-file') that use minibuffers even while the minibuffer window
771 is active. Such invocation produces a recursive editing level for
772 a new minibuffer. The outer-level minibuffer is invisible while
773 you are editing the inner one.
775 This variable only affects invoking the minibuffer while the
776 minibuffer window is selected. If you switch windows while in the
777 minibuffer, you can always invoke minibuffer commands while some
778 other window is selected.
780 In FSF Emacs 19, if a command name has a property
781 `enable-recursive-minibuffers' that is non-`nil', then the command can
782 use the minibuffer to read arguments even if it is invoked from the
783 minibuffer. The minibuffer command `next-matching-history-element'
784 (normally `M-s' in the minibuffer) uses this feature.
786 This is not implemented in XEmacs because it is a kludge. If you
787 want to explicitly set the value of `enable-recursive-minibuffers' in
788 this fashion, just use an evaluated interactive spec and bind
789 `enable-recursive-minibuffers' while reading from the minibuffer. See
790 the definition of `next-matching-history-element' in `lisp/minibuf.el'.
793 File: lispref.info, Node: Command Loop, Next: Keymaps, Prev: Minibuffers, Up: Top
798 When you run XEmacs, it enters the "editor command loop" almost
799 immediately. This loop reads events, executes their definitions, and
800 displays the results. In this chapter, we describe how these things
801 are done, and the subroutines that allow Lisp programs to do them.
805 * Command Overview:: How the command loop reads commands.
806 * Defining Commands:: Specifying how a function should read arguments.
807 * Interactive Call:: Calling a command, so that it will read arguments.
808 * Command Loop Info:: Variables set by the command loop for you to examine.
809 * Events:: What input looks like when you read it.
810 * Reading Input:: How to read input events from the keyboard or mouse.
811 * Waiting:: Waiting for user input or elapsed time.
812 * Quitting:: How C-g works. How to catch or defer quitting.
813 * Prefix Command Arguments:: How the commands to set prefix args work.
814 * Recursive Editing:: Entering a recursive edit,
815 and why you usually shouldn't.
816 * Disabling Commands:: How the command loop handles disabled commands.
817 * Command History:: How the command history is set up, and how accessed.
818 * Keyboard Macros:: How keyboard macros are implemented.
821 File: lispref.info, Node: Command Overview, Next: Defining Commands, Up: Command Loop
823 Command Loop Overview
824 =====================
826 The command loop in XEmacs is a standard event loop, reading events
827 one at a time with `next-event' and handling them with
828 `dispatch-event'. An event is typically a single user action, such as
829 a keypress, mouse movement, or menu selection; but they can also be
830 notifications from the window system, informing XEmacs that (for
831 example) part of its window was just uncovered and needs to be redrawn.
832 *Note Events::. Pending events are held in a first-in, first-out list
833 called the "event queue": events are read from the head of the list,
834 and newly arriving events are added to the tail. In this way, events
835 are always processed in the order in which they arrive.
837 `dispatch-event' does most of the work of handling user actions.
838 The first thing it must do is put the events together into a key
839 sequence, which is a sequence of events that translates into a command.
840 It does this by consulting the active keymaps, which specify what the
841 valid key sequences are and how to translate them into commands. *Note
842 Key Lookup::, for information on how this is done. The result of the
843 translation should be a keyboard macro or an interactively callable
844 function. If the key is `M-x', then it reads the name of another
845 command, which it then calls. This is done by the command
846 `execute-extended-command' (*note Interactive Call::).
848 To execute a command requires first reading the arguments for it.
849 This is done by calling `command-execute' (*note Interactive Call::).
850 For commands written in Lisp, the `interactive' specification says how
851 to read the arguments. This may use the prefix argument (*note Prefix
852 Command Arguments::) or may read with prompting in the minibuffer
853 (*note Minibuffers::). For example, the command `find-file' has an
854 `interactive' specification which says to read a file name using the
855 minibuffer. The command's function body does not use the minibuffer;
856 if you call this command from Lisp code as a function, you must supply
857 the file name string as an ordinary Lisp function argument.
859 If the command is a string or vector (i.e., a keyboard macro) then
860 `execute-kbd-macro' is used to execute it. You can call this function
861 yourself (*note Keyboard Macros::).
863 To terminate the execution of a running command, type `C-g'. This
864 character causes "quitting" (*note Quitting::).
866 - Variable: pre-command-hook
867 The editor command loop runs this normal hook before each command.
868 At that time, `this-command' contains the command that is about to
869 run, and `last-command' describes the previous command. *Note
872 - Variable: post-command-hook
873 The editor command loop runs this normal hook after each command.
874 (In FSF Emacs, it is also run when the command loop is entered, or
875 reentered after an error or quit.) At that time, `this-command'
876 describes the command that just ran, and `last-command' describes
877 the command before that. *Note Hooks::.
879 Quitting is suppressed while running `pre-command-hook' and
880 `post-command-hook'. If an error happens while executing one of these
881 hooks, it terminates execution of the hook, but that is all it does.
884 File: lispref.info, Node: Defining Commands, Next: Interactive Call, Prev: Command Overview, Up: Command Loop
889 A Lisp function becomes a command when its body contains, at top
890 level, a form that calls the special form `interactive'. This form
891 does nothing when actually executed, but its presence serves as a flag
892 to indicate that interactive calling is permitted. Its argument
893 controls the reading of arguments for an interactive call.
897 * Using Interactive:: General rules for `interactive'.
898 * Interactive Codes:: The standard letter-codes for reading arguments
900 * Interactive Examples:: Examples of how to read interactive arguments.
903 File: lispref.info, Node: Using Interactive, Next: Interactive Codes, Up: Defining Commands
908 This section describes how to write the `interactive' form that
909 makes a Lisp function an interactively-callable command.
911 - Special Form: interactive arg-descriptor
912 This special form declares that the function in which it appears
913 is a command, and that it may therefore be called interactively
914 (via `M-x' or by entering a key sequence bound to it). The
915 argument ARG-DESCRIPTOR declares how to compute the arguments to
916 the command when the command is called interactively.
918 A command may be called from Lisp programs like any other
919 function, but then the caller supplies the arguments and
920 ARG-DESCRIPTOR has no effect.
922 The `interactive' form has its effect because the command loop
923 (actually, its subroutine `call-interactively') scans through the
924 function definition looking for it, before calling the function.
925 Once the function is called, all its body forms including the
926 `interactive' form are executed, but at this time `interactive'
927 simply returns `nil' without even evaluating its argument.
929 There are three possibilities for the argument ARG-DESCRIPTOR:
931 * It may be omitted or `nil'; then the command is called with no
932 arguments. This leads quickly to an error if the command requires
933 one or more arguments.
935 * It may be a Lisp expression that is not a string; then it should
936 be a form that is evaluated to get a list of arguments to pass to
939 If this expression reads keyboard input (this includes using the
940 minibuffer), keep in mind that the integer value of point or the
941 mark before reading input may be incorrect after reading input.
942 This is because the current buffer may be receiving subprocess
943 output; if subprocess output arrives while the command is waiting
944 for input, it could relocate point and the mark.
946 Here's an example of what _not_ to do:
949 (list (region-beginning) (region-end)
950 (read-string "Foo: " nil 'my-history)))
952 Here's how to avoid the problem, by examining point and the mark
953 only after reading the keyboard input:
956 (let ((string (read-string "Foo: " nil 'my-history)))
957 (list (region-beginning) (region-end) string)))
959 * It may be a string; then its contents should consist of a code
960 character followed by a prompt (which some code characters use and
961 some ignore). The prompt ends either with the end of the string
962 or with a newline. Here is a simple example:
964 (interactive "bFrobnicate buffer: ")
966 The code letter `b' says to read the name of an existing buffer,
967 with completion. The buffer name is the sole argument passed to
968 the command. The rest of the string is a prompt.
970 If there is a newline character in the string, it terminates the
971 prompt. If the string does not end there, then the rest of the
972 string should contain another code character and prompt,
973 specifying another argument. You can specify any number of
974 arguments in this way.
976 The prompt string can use `%' to include previous argument values
977 (starting with the first argument) in the prompt. This is done
978 using `format' (*note Formatting Strings::). For example, here is
979 how you could read the name of an existing buffer followed by a
980 new name to give to that buffer:
982 (interactive "bBuffer to rename: \nsRename buffer %s to: ")
984 If the first character in the string is `*', then an error is
985 signaled if the buffer is read-only.
987 If the first character in the string is `@', and if the key
988 sequence used to invoke the command includes any mouse events, then
989 the window associated with the first of those events is selected
990 before the command is run.
992 If the first character in the string is `_', then this command will
993 not cause the region to be deactivated when it completes; that is,
994 `zmacs-region-stays' will be set to `t' when the command exits
997 You can use `*', `@', and `_' together; the order does not matter.
998 Actual reading of arguments is controlled by the rest of the
999 prompt string (starting with the first character that is not `*',
1002 - Function: function-interactive function
1003 This function retrieves the interactive specification of FUNCTION,
1004 which may be any funcallable object. The specification will be
1005 returned as the list of the symbol `interactive' and the specs. If
1006 FUNCTION is not interactive, `nil' will be returned.
1009 File: lispref.info, Node: Interactive Codes, Next: Interactive Examples, Prev: Using Interactive, Up: Defining Commands
1011 Code Characters for `interactive'
1012 ---------------------------------
1014 The code character descriptions below contain a number of key words,
1015 defined here as follows:
1018 Provide completion. <TAB>, <SPC>, and <RET> perform name
1019 completion because the argument is read using `completing-read'
1020 (*note Completion::). `?' displays a list of possible completions.
1023 Require the name of an existing object. An invalid name is not
1024 accepted; the commands to exit the minibuffer do not exit if the
1025 current input is not valid.
1028 A default value of some sort is used if the user enters no text in
1029 the minibuffer. The default depends on the code character.
1032 This code letter computes an argument without reading any input.
1033 Therefore, it does not use a prompt string, and any prompt string
1034 you supply is ignored.
1036 Even though the code letter doesn't use a prompt string, you must
1037 follow it with a newline if it is not the last code character in
1041 A prompt immediately follows the code character. The prompt ends
1042 either with the end of the string or with a newline.
1045 This code character is meaningful only at the beginning of the
1046 interactive string, and it does not look for a prompt or a newline.
1047 It is a single, isolated character.
1049 Here are the code character descriptions for use with `interactive':
1052 Signal an error if the current buffer is read-only. Special.
1055 Select the window mentioned in the first mouse event in the key
1056 sequence that invoked this command. Special.
1059 Do not cause the region to be deactivated when this command
1063 A function name (i.e., a symbol satisfying `fboundp'). Existing,
1067 The name of an existing buffer. By default, uses the name of the
1068 current buffer (*note Buffers::). Existing, Completion, Default,
1072 A buffer name. The buffer need not exist. By default, uses the
1073 name of a recently used buffer other than the current buffer.
1074 Completion, Default, Prompt.
1077 A character. The cursor does not move into the echo area. Prompt.
1080 A command name (i.e., a symbol satisfying `commandp'). Existing,
1084 The position of point, as an integer (*note Point::). No I/O.
1087 A directory name. The default is the current default directory of
1088 the current buffer, `default-directory' (*note System
1089 Environment::). Existing, Completion, Default, Prompt.
1092 The last mouse-button or misc-user event in the key sequence that
1093 invoked the command. No I/O.
1095 You can use `e' more than once in a single command's interactive
1096 specification. If the key sequence that invoked the command has N
1097 mouse-button or misc-user events, the Nth `e' provides the Nth
1101 A file name of an existing file (*note File Names::). The default
1102 directory is `default-directory'. Existing, Completion, Default,
1106 A file name. The file need not exist. Completion, Default,
1110 A key sequence (*note Keymap Terminology::). This keeps reading
1111 events until a command (or undefined command) is found in the
1112 current key maps. The key sequence argument is represented as a
1113 vector of events. The cursor does not move into the echo area.
1116 This kind of input is used by commands such as `describe-key' and
1120 A key sequence, whose definition you intend to change. This works
1121 like `k', except that it suppresses, for the last input event in
1122 the key sequence, the conversions that are normally used (when
1123 necessary) to convert an undefined key into a defined one.
1126 The position of the mark, as an integer. No I/O.
1129 A number read with the minibuffer. If the input is not a number,
1130 the user is asked to try again. The prefix argument, if any, is
1134 The raw prefix argument. If the prefix argument is `nil', then
1135 read a number as with `n'. Requires a number. *Note Prefix
1136 Command Arguments::. Prompt.
1139 The numeric prefix argument. (Note that this `p' is lower case.)
1143 The raw prefix argument. (Note that this `P' is upper case.) No
1147 Point and the mark, as two numeric arguments, smallest first.
1148 This is the only code letter that specifies two successive
1149 arguments rather than one. No I/O.
1152 Arbitrary text, read in the minibuffer and returned as a string
1153 (*note Text from Minibuffer::). Terminate the input with either
1154 <LFD> or <RET>. (`C-q' may be used to include either of these
1155 characters in the input.) Prompt.
1158 An interned symbol whose name is read in the minibuffer. Any
1159 whitespace character terminates the input. (Use `C-q' to include
1160 whitespace in the string.) Other characters that normally
1161 terminate a symbol (e.g., parentheses and brackets) do not do so
1165 A variable declared to be a user option (i.e., satisfying the
1166 predicate `user-variable-p'). *Note High-Level Completion::.
1167 Existing, Completion, Prompt.
1170 A Lisp object, specified with its read syntax, terminated with a
1171 <LFD> or <RET>. The object is not evaluated. *Note Object from
1172 Minibuffer::. Prompt.
1175 A Lisp form is read as with `x', but then evaluated so that its
1176 value becomes the argument for the command. Prompt.
1179 File: lispref.info, Node: Interactive Examples, Prev: Interactive Codes, Up: Defining Commands
1181 Examples of Using `interactive'
1182 -------------------------------
1184 Here are some examples of `interactive':
1186 (defun foo1 () ; `foo1' takes no arguments,
1187 (interactive) ; just moves forward two words.
1191 (defun foo2 (n) ; `foo2' takes one argument,
1192 (interactive "p") ; which is the numeric prefix.
1193 (forward-word (* 2 n)))
1196 (defun foo3 (n) ; `foo3' takes one argument,
1197 (interactive "nCount:") ; which is read with the Minibuffer.
1198 (forward-word (* 2 n)))
1201 (defun three-b (b1 b2 b3)
1202 "Select three existing buffers.
1203 Put them into three windows, selecting the last one."
1204 (interactive "bBuffer1:\nbBuffer2:\nbBuffer3:")
1205 (delete-other-windows)
1206 (split-window (selected-window) 8)
1207 (switch-to-buffer b1)
1209 (split-window (selected-window) 8)
1210 (switch-to-buffer b2)
1212 (switch-to-buffer b3))
1214 (three-b "*scratch*" "declarations.texi" "*mail*")