Sync with r21_2_36.
[chise/xemacs-chise.git-] / info / lispref.info-16
1 This is ../info/lispref.info, produced by makeinfo version 4.0 from
2 lispref/lispref.texi.
3
4 INFO-DIR-SECTION XEmacs Editor
5 START-INFO-DIR-ENTRY
6 * Lispref: (lispref).           XEmacs Lisp Reference Manual.
7 END-INFO-DIR-ENTRY
8
9    Edition History:
10
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
20
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.
24
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.
28
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.
33
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.
38
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.
45
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.
51
52 \1f
53 File: lispref.info,  Node: Completion Commands,  Next: High-Level Completion,  Prev: Minibuffer Completion,  Up: Completion
54
55 Minibuffer Commands That Do Completion
56 --------------------------------------
57
58    This section describes the keymaps, commands and user options used in
59 the minibuffer to do completion.
60
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:
65
66     `?'
67           `minibuffer-completion-help'
68
69     <SPC>
70           `minibuffer-complete-word'
71
72     <TAB>
73           `minibuffer-complete'
74
75      with other characters bound as in `minibuffer-local-map' (*note
76      Text from Minibuffer::).
77
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
83      following bindings:
84
85     `?'
86           `minibuffer-completion-help'
87
88     <SPC>
89           `minibuffer-complete-word'
90
91     <TAB>
92           `minibuffer-complete'
93
94     `C-j'
95           `minibuffer-complete-and-exit'
96
97     <RET>
98           `minibuffer-complete-and-exit'
99
100      with other characters bound as in `minibuffer-local-map'.
101
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'.
108
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.
113
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
119      Tables::.
120
121  - Command: minibuffer-complete
122      This function completes the minibuffer contents as far as possible.
123
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
130      in succession.
131
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.
137
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
145      `*Completions*'.
146
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.
155
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:
159
160           (with-output-to-temp-buffer "*Completions*"
161             (display-completion-list
162               (all-completions (buffer-string) my-alist)))
163
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
168      uniquely determined.
169
170 \1f
171 File: lispref.info,  Node: High-Level Completion,  Next: Reading File Names,  Prev: Completion Commands,  Up: Completion
172
173 High-Level Completion  Functions
174 --------------------------------
175
176    This section describes the higher-level convenient functions for
177 reading certain sorts of names with completion.
178
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
182 Defining Commands::.
183
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.
190
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.)
197
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
201      name is the value.
202
203           (read-buffer "Buffer name? " "foo" t)
204           ;; After evaluation of the preceding expression,
205           ;;   the following prompt appears,
206           ;;   with an empty minibuffer:
207           
208           ---------- Buffer: Minibuffer ----------
209           Buffer name? (default foo) -!-
210           ---------- Buffer: Minibuffer ----------
211           
212           ;; The user types `minibuffer.t <RET>'.
213                => "minibuffer.texi"
214
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::.
221
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'.
227
228           (read-command "Command name? ")
229           
230           ;; After evaluation of the preceding expression,
231           ;;   the following prompt appears with an empty minibuffer:
232           
233           ---------- Buffer: Minibuffer ----------
234           Command name?
235           ---------- Buffer: Minibuffer ----------
236
237      If the user types `forward-c <RET>', then this function returns
238      `forward-char'.
239
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:
244
245           (read-command PROMPT)
246           ==
247           (intern (completing-read PROMPT obarray
248                                    'commandp t nil))
249
250  - Function: read-variable prompt &optional default-value
251      This function reads the name of a user variable and returns it as a
252      symbol.
253
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'.
259
260           (read-variable "Variable name? ")
261           
262           ;; After evaluation of the preceding expression,
263           ;;   the following prompt appears,
264           ;;   with an empty minibuffer:
265           
266           ---------- Buffer: Minibuffer ----------
267           Variable name? -!-
268           ---------- Buffer: Minibuffer ----------
269
270      If the user then types `fill-p <RET>', `read-variable' returns
271      `fill-prefix'.
272
273      This function is similar to `read-command', but uses the predicate
274      `user-variable-p' instead of `commandp':
275
276           (read-variable PROMPT)
277           ==
278           (intern
279            (completing-read PROMPT obarray
280                             'user-variable-p t nil))
281
282 \1f
283 File: lispref.info,  Node: Reading File Names,  Next: Programmed Completion,  Prev: High-Level Completion,  Up: Completion
284
285 Reading File Names
286 ------------------
287
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.
291
292  - Function: read-file-name prompt &optional directory default existing
293           initial history
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.
299
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.
306
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
311      `default-directory'.
312
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'.
318
319      Here is an example:
320
321           (read-file-name "The file is ")
322           
323           ;; After evaluation of the preceding expression,
324           ;;   the following appears in the minibuffer:
325           
326           ---------- Buffer: Minibuffer ----------
327           The file is /gp/gnu/elisp/-!-
328           ---------- Buffer: Minibuffer ----------
329
330      Typing `manual <TAB>' results in the following:
331
332           ---------- Buffer: Minibuffer ----------
333           The file is /gp/gnu/elisp/manual.texi-!-
334           ---------- Buffer: Minibuffer ----------
335
336      If the user types <RET>, `read-file-name' returns the file name as
337      the string `"/gp/gnu/elisp/manual.texi"'.
338
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.
348
349      For example:
350
351           ;; Here the minibuffer starts out with the default directory.
352           (let ((insert-default-directory t))
353             (read-file-name "The file is "))
354           
355           ---------- Buffer: Minibuffer ----------
356           The file is ~lewis/manual/-!-
357           ---------- Buffer: Minibuffer ----------
358           
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 "))
363           
364           ---------- Buffer: Minibuffer ----------
365           The file is -!-
366           ---------- Buffer: Minibuffer ----------
367
368 \1f
369 File: lispref.info,  Node: Programmed Completion,  Prev: Reading File Names,  Up: Completion
370
371 Programmed Completion
372 ---------------------
373
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".
378
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.
384
385    The completion function should accept three arguments:
386
387    * The string to be completed.
388
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
392      `nil'.
393
394    * A flag specifying the type of operation.
395
396    There are three flag values for three operations:
397
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.
402
403      If the string is an exact match for one possibility, but also
404      matches other longer possibilities, the function should return the
405      string, not `t'.
406
407    * `t' specifies `all-completions'.  The completion function should
408      return a list of all possible completions of the specified string.
409
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.
413
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.
421
422    Emacs uses programmed completion when completing file names.  *Note
423 File Name Completion::.
424
425 \1f
426 File: lispref.info,  Node: Yes-or-No Queries,  Next: Multiple Queries,  Prev: Completion,  Up: Minibuffers
427
428 Yes-or-No Queries
429 =================
430
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.
438
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.
442
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.
445
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
454      case are equivalent.
455
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
460      repeats the request.
461
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
466      is being asked.
467
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::.
471
472      In the following example, the user first types `q', which is
473      invalid.  At the next prompt the user types `y'.
474
475           (y-or-n-p "Do you need a lift? ")
476           
477           ;; After evaluation of the preceding expression,
478           ;;   the following prompt appears in the echo area:
479           
480           ---------- Echo area ----------
481           Do you need a lift? (y or n)
482           ---------- Echo area ----------
483           
484           ;; If the user then types `q', the following appears:
485           
486           ---------- Echo area ----------
487           Please answer y or n.  Do you need a lift? (y or n)
488           ---------- Echo area ----------
489           
490           ;; When the user types a valid answer,
491           ;;   it is displayed after the question:
492           
493           ---------- Echo area ----------
494           Do you need a lift? (y or n) y
495           ---------- Echo area ----------
496
497      We show successive lines of echo area messages, but only one
498      actually appears on the screen at a time.
499
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.
505
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.
510
511      `yes-or-no-p' requires more work from the user than `y-or-n-p' and
512      is appropriate for more crucial decisions.
513
514      Here is an example:
515
516           (yes-or-no-p "Do you really want to remove everything? ")
517           
518           ;; After evaluation of the preceding expression,
519           ;;   the following prompt appears,
520           ;;   with an empty minibuffer:
521           
522           ---------- Buffer: minibuffer ----------
523           Do you really want to remove everything? (yes or no)
524           ---------- Buffer: minibuffer ----------
525
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:
529
530           ---------- Buffer: minibuffer ----------
531           Please answer yes or no.
532           Do you really want to remove everything? (yes or no)
533           ---------- Buffer: minibuffer ----------
534
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.
539
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.
546
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.
550
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.
554
555 \1f
556 File: lispref.info,  Node: Multiple Queries,  Next: Reading a Password,  Prev: Yes-or-No Queries,  Up: Minibuffers
557
558 Asking Multiple Y-or-N Questions
559 ================================
560
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.
566
567  - Function: map-y-or-n-p prompter actor list &optional help
568           action-alist
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
571      each one.
572
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
577      questions.
578
579      The argument PROMPTER specifies how to ask each question.  If
580      PROMPTER is a string, the question text is computed like this:
581
582           (format PROMPTER OBJECT)
583
584      where OBJECT is the next object to ask about (as obtained from
585      LIST).
586
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).
593
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.
598
599      If the argument HELP is given, it should be a list of this form:
600
601           (SINGULAR PLURAL ACTION)
602
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.
607
608      If you don't specify HELP, the default is `("object" "objects"
609      "act on")'.
610
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::.
619
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.
625
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.
630
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.
638
639      The return value of `map-y-or-n-p' is the number of objects acted
640      on.
641
642 \1f
643 File: lispref.info,  Node: Reading a Password,  Next: Minibuffer Misc,  Prev: Multiple Queries,  Up: Minibuffers
644
645 Reading a Password
646 ==================
647
648    To read a password to pass to another program, you can use the
649 function `read-passwd'.
650
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.
655
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.
660
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.
665
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.
670
671  - User Option: passwd-echo
672      This specifies the character echoed when typing a password.  When
673      nil, nothing is echoed.
674
675 \1f
676 File: lispref.info,  Node: Minibuffer Misc,  Prev: Reading a Password,  Up: Minibuffers
677
678 Minibuffer Miscellany
679 =====================
680
681    This section describes some basic functions and variables related to
682 minibuffers.
683
684  - Command: exit-minibuffer
685      This command exits the active minibuffer.  It is normally bound to
686      keys in minibuffer local keymaps.
687
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::).
692
693  - Command: previous-history-element n
694      This command replaces the minibuffer contents with the value of the
695      Nth previous (older) history element.
696
697  - Command: next-history-element n
698      This command replaces the minibuffer contents with the value of the
699      Nth more recent history element.
700
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
704      expression).
705
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
709      expression).
710
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'.
714
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
718      returns 0.
719
720  - Variable: minibuffer-setup-hook
721      This is a normal hook that is run whenever the minibuffer is
722      entered.  *Note Hooks::.
723
724  - Variable: minibuffer-exit-hook
725      This is a normal hook that is run whenever the minibuffer is
726      exited.  *Note Hooks::.
727
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::).
731
732  - Function: active-minibuffer-window
733      This function returns the currently active minibuffer window, or
734      `nil' if none is currently active.
735
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.
742
743  - Function: window-minibuffer-p window
744      This function returns non-`nil' if WINDOW is a minibuffer window.
745
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
749 than one frame.
750
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.
754
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.
759
760    Finally, some functions and variables deal with recursive minibuffers
761 (*note Recursive Editing::):
762
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,
766      it returns zero.
767
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.
774
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.
779
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.
785
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'.
791
792 \1f
793 File: lispref.info,  Node: Command Loop,  Next: Keymaps,  Prev: Minibuffers,  Up: Top
794
795 Command Loop
796 ************
797
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.
802
803 * Menu:
804
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.
819
820 \1f
821 File: lispref.info,  Node: Command Overview,  Next: Defining Commands,  Up: Command Loop
822
823 Command Loop Overview
824 =====================
825
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.
836
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::).
847
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.
858
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::).
862
863    To terminate the execution of a running command, type `C-g'.  This
864 character causes "quitting" (*note Quitting::).
865
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
870      Hooks::.
871
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::.
878
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.
882
883 \1f
884 File: lispref.info,  Node: Defining Commands,  Next: Interactive Call,  Prev: Command Overview,  Up: Command Loop
885
886 Defining Commands
887 =================
888
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.
894
895 * Menu:
896
897 * Using Interactive::     General rules for `interactive'.
898 * Interactive Codes::     The standard letter-codes for reading arguments
899                              in various ways.
900 * Interactive Examples::  Examples of how to read interactive arguments.
901
902 \1f
903 File: lispref.info,  Node: Using Interactive,  Next: Interactive Codes,  Up: Defining Commands
904
905 Using `interactive'
906 -------------------
907
908    This section describes how to write the `interactive' form that
909 makes a Lisp function an interactively-callable command.
910
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.
917
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.
921
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.
928
929    There are three possibilities for the argument ARG-DESCRIPTOR:
930
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.
934
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
937      the command.
938
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.
945
946      Here's an example of what _not_ to do:
947
948           (interactive
949            (list (region-beginning) (region-end)
950                  (read-string "Foo: " nil 'my-history)))
951
952      Here's how to avoid the problem, by examining point and the mark
953      only after reading the keyboard input:
954
955           (interactive
956            (let ((string (read-string "Foo: " nil 'my-history)))
957              (list (region-beginning) (region-end) string)))
958
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:
963
964           (interactive "bFrobnicate buffer: ")
965
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.
969
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.
975
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:
981
982           (interactive "bBuffer to rename: \nsRename buffer %s to: ")
983
984      If the first character in the string is `*', then an error is
985      signaled if the buffer is read-only.
986
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.
991
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
995      successfully.
996
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 `*',
1000      `@', or `_').
1001
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.
1007
1008 \1f
1009 File: lispref.info,  Node: Interactive Codes,  Next: Interactive Examples,  Prev: Using Interactive,  Up: Defining Commands
1010
1011 Code Characters for `interactive'
1012 ---------------------------------
1013
1014    The code character descriptions below contain a number of key words,
1015 defined here as follows:
1016
1017 Completion
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.
1021
1022 Existing
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.
1026
1027 Default
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.
1030
1031 No I/O
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.
1035
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
1038      the string.
1039
1040 Prompt
1041      A prompt immediately follows the code character.  The prompt ends
1042      either with the end of the string or with a newline.
1043
1044 Special
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.
1048
1049    Here are the code character descriptions for use with `interactive':
1050
1051 `*'
1052      Signal an error if the current buffer is read-only.  Special.
1053
1054 `@'
1055      Select the window mentioned in the first mouse event in the key
1056      sequence that invoked this command.  Special.
1057
1058 `_'
1059      Do not cause the region to be deactivated when this command
1060      completes.  Special.
1061
1062 `a'
1063      A function name (i.e., a symbol satisfying `fboundp').  Existing,
1064      Completion, Prompt.
1065
1066 `b'
1067      The name of an existing buffer.  By default, uses the name of the
1068      current buffer (*note Buffers::).  Existing, Completion, Default,
1069      Prompt.
1070
1071 `B'
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.
1075
1076 `c'
1077      A character.  The cursor does not move into the echo area.  Prompt.
1078
1079 `C'
1080      A command name (i.e., a symbol satisfying `commandp').  Existing,
1081      Completion, Prompt.
1082
1083 `d'
1084      The position of point, as an integer (*note Point::).  No I/O.
1085
1086 `D'
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.
1090
1091 `e'
1092      The last mouse-button or misc-user event in the key sequence that
1093      invoked the command.  No I/O.
1094
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
1098      such event.
1099
1100 `f'
1101      A file name of an existing file (*note File Names::).  The default
1102      directory is `default-directory'.  Existing, Completion, Default,
1103      Prompt.
1104
1105 `F'
1106      A file name.  The file need not exist.  Completion, Default,
1107      Prompt.
1108
1109 `k'
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.
1114      Prompt.
1115
1116      This kind of input is used by commands such as `describe-key' and
1117      `global-set-key'.
1118
1119 `K'
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.
1124
1125 `m'
1126      The position of the mark, as an integer.  No I/O.
1127
1128 `n'
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
1131      not used.  Prompt.
1132
1133 `N'
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.
1137
1138 `p'
1139      The numeric prefix argument.  (Note that this `p' is lower case.)
1140      No I/O.
1141
1142 `P'
1143      The raw prefix argument.  (Note that this `P' is upper case.)  No
1144      I/O.
1145
1146 `r'
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.
1150
1151 `s'
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.
1156
1157 `S'
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
1162      here.  Prompt.
1163
1164 `v'
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.
1168
1169 `x'
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.
1173
1174 `X'
1175      A Lisp form is read as with `x', but then evaluated so that its
1176      value becomes the argument for the command.  Prompt.
1177
1178 \1f
1179 File: lispref.info,  Node: Interactive Examples,  Prev: Interactive Codes,  Up: Defining Commands
1180
1181 Examples of Using `interactive'
1182 -------------------------------
1183
1184    Here are some examples of `interactive':
1185
1186      (defun foo1 ()              ; `foo1' takes no arguments,
1187          (interactive)           ;   just moves forward two words.
1188          (forward-word 2))
1189           => foo1
1190      
1191      (defun foo2 (n)             ; `foo2' takes one argument,
1192          (interactive "p")       ;   which is the numeric prefix.
1193          (forward-word (* 2 n)))
1194           => foo2
1195      
1196      (defun foo3 (n)             ; `foo3' takes one argument,
1197          (interactive "nCount:") ;   which is read with the Minibuffer.
1198          (forward-word (* 2 n)))
1199           => foo3
1200      
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)
1208          (other-window 1)
1209          (split-window (selected-window) 8)
1210          (switch-to-buffer b2)
1211          (other-window 1)
1212          (switch-to-buffer b3))
1213           => three-b
1214      (three-b "*scratch*" "declarations.texi" "*mail*")
1215           => nil
1216