Reformatted.
[chise/xemacs-chise.git] / info / lispref.info-15
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: Input Streams,  Next: Input Functions,  Prev: Streams Intro,  Up: Read and Print
54
55 Input Streams
56 =============
57
58    Most of the Lisp functions for reading text take an "input stream"
59 as an argument.  The input stream specifies where or how to get the
60 characters of the text to be read.  Here are the possible types of input
61 stream:
62
63 BUFFER
64      The input characters are read from BUFFER, starting with the
65      character directly after point.  Point advances as characters are
66      read.
67
68 MARKER
69      The input characters are read from the buffer that MARKER is in,
70      starting with the character directly after the marker.  The marker
71      position advances as characters are read.  The value of point in
72      the buffer has no effect when the stream is a marker.
73
74 STRING
75      The input characters are taken from STRING, starting at the first
76      character in the string and using as many characters as required.
77
78 FUNCTION
79      The input characters are generated by FUNCTION, one character per
80      call.  Normally FUNCTION is called with no arguments, and should
81      return a character.
82
83      Occasionally FUNCTION is called with one argument (always a
84      character).  When that happens, FUNCTION should save the argument
85      and arrange to return it on the next call.  This is called
86      "unreading" the character; it happens when the Lisp reader reads
87      one character too many and wants to "put it back where it came
88      from".
89
90 `t'
91      `t' used as a stream means that the input is read from the
92      minibuffer.  In fact, the minibuffer is invoked once and the text
93      given by the user is made into a string that is then used as the
94      input stream.
95
96 `nil'
97      `nil' supplied as an input stream means to use the value of
98      `standard-input' instead; that value is the "default input
99      stream", and must be a non-`nil' input stream.
100
101 SYMBOL
102      A symbol as input stream is equivalent to the symbol's function
103      definition (if any).
104
105    Here is an example of reading from a stream that is a buffer, showing
106 where point is located before and after:
107
108      ---------- Buffer: foo ----------
109      This-!- is the contents of foo.
110      ---------- Buffer: foo ----------
111      
112      (read (get-buffer "foo"))
113           => is
114      (read (get-buffer "foo"))
115           => the
116      
117      ---------- Buffer: foo ----------
118      This is the-!- contents of foo.
119      ---------- Buffer: foo ----------
120
121 Note that the first read skips a space.  Reading skips any amount of
122 whitespace preceding the significant text.
123
124    In Emacs 18, reading a symbol discarded the delimiter terminating the
125 symbol.  Thus, point would end up at the beginning of `contents' rather
126 than after `the'.  The Emacs 19 behavior is superior because it
127 correctly handles input such as `bar(foo)', where the open-parenthesis
128 that ends one object is needed as the beginning of another object.
129
130    Here is an example of reading from a stream that is a marker,
131 initially positioned at the beginning of the buffer shown.  The value
132 read is the symbol `This'.
133
134
135      ---------- Buffer: foo ----------
136      This is the contents of foo.
137      ---------- Buffer: foo ----------
138      
139      (setq m (set-marker (make-marker) 1 (get-buffer "foo")))
140           => #<marker at 1 in foo>
141      (read m)
142           => This
143      m
144           => #<marker at 5 in foo>   ;; Before the first space.
145
146    Here we read from the contents of a string:
147
148      (read "(When in) the course")
149           => (When in)
150
151    The following example reads from the minibuffer.  The prompt is:
152 `Lisp expression: '.  (That is always the prompt used when you read
153 from the stream `t'.)  The user's input is shown following the prompt.
154
155      (read t)
156           => 23
157      ---------- Buffer: Minibuffer ----------
158      Lisp expression: 23 <RET>
159      ---------- Buffer: Minibuffer ----------
160
161    Finally, here is an example of a stream that is a function, named
162 `useless-stream'.  Before we use the stream, we initialize the variable
163 `useless-list' to a list of characters.  Then each call to the function
164 `useless-stream' obtains the next character in the list or unreads a
165 character by adding it to the front of the list.
166
167      (setq useless-list (append "XY()" nil))
168           => (88 89 40 41)
169      
170      (defun useless-stream (&optional unread)
171        (if unread
172            (setq useless-list (cons unread useless-list))
173          (prog1 (car useless-list)
174                 (setq useless-list (cdr useless-list)))))
175           => useless-stream
176
177 Now we read using the stream thus constructed:
178
179      (read 'useless-stream)
180           => XY
181      
182      useless-list
183           => (40 41)
184
185 Note that the open and close parentheses remains in the list.  The Lisp
186 reader encountered the open parenthesis, decided that it ended the
187 input, and unread it.  Another attempt to read from the stream at this
188 point would read `()' and return `nil'.
189
190 \1f
191 File: lispref.info,  Node: Input Functions,  Next: Output Streams,  Prev: Input Streams,  Up: Read and Print
192
193 Input Functions
194 ===============
195
196    This section describes the Lisp functions and variables that pertain
197 to reading.
198
199    In the functions below, STREAM stands for an input stream (see the
200 previous section).  If STREAM is `nil' or omitted, it defaults to the
201 value of `standard-input'.
202
203    An `end-of-file' error is signaled if reading encounters an
204 unterminated list, vector, or string.
205
206  - Function: read &optional stream
207      This function reads one textual Lisp expression from STREAM,
208      returning it as a Lisp object.  This is the basic Lisp input
209      function.
210
211  - Function: read-from-string string &optional start end
212      This function reads the first textual Lisp expression from the
213      text in STRING.  It returns a cons cell whose CAR is that
214      expression, and whose CDR is an integer giving the position of the
215      next remaining character in the string (i.e., the first one not
216      read).
217
218      If START is supplied, then reading begins at index START in the
219      string (where the first character is at index 0).  If END is also
220      supplied, then reading stops just before that index, as if the rest
221      of the string were not there.
222
223      For example:
224
225           (read-from-string "(setq x 55) (setq y 5)")
226                => ((setq x 55) . 11)
227           (read-from-string "\"A short string\"")
228                => ("A short string" . 16)
229           
230           ;; Read starting at the first character.
231           (read-from-string "(list 112)" 0)
232                => ((list 112) . 10)
233           ;; Read starting at the second character.
234           (read-from-string "(list 112)" 1)
235                => (list . 5)
236           ;; Read starting at the seventh character,
237           ;;   and stopping at the ninth.
238           (read-from-string "(list 112)" 6 8)
239                => (11 . 8)
240
241  - Variable: standard-input
242      This variable holds the default input stream--the stream that
243      `read' uses when the STREAM argument is `nil'.
244
245 \1f
246 File: lispref.info,  Node: Output Streams,  Next: Output Functions,  Prev: Input Functions,  Up: Read and Print
247
248 Output Streams
249 ==============
250
251    An output stream specifies what to do with the characters produced
252 by printing.  Most print functions accept an output stream as an
253 optional argument.  Here are the possible types of output stream:
254
255 BUFFER
256      The output characters are inserted into BUFFER at point.  Point
257      advances as characters are inserted.
258
259 MARKER
260      The output characters are inserted into the buffer that MARKER
261      points into, at the marker position.  The marker position advances
262      as characters are inserted.  The value of point in the buffer has
263      no effect on printing when the stream is a marker.
264
265 FUNCTION
266      The output characters are passed to FUNCTION, which is responsible
267      for storing them away.  It is called with a single character as
268      argument, as many times as there are characters to be output, and
269      is free to do anything at all with the characters it receives.
270
271 `t'
272      The output characters are displayed in the echo area.
273
274 `nil'
275      `nil' specified as an output stream means to the value of
276      `standard-output' instead; that value is the "default output
277      stream", and must be a non-`nil' output stream.
278
279 SYMBOL
280      A symbol as output stream is equivalent to the symbol's function
281      definition (if any).
282
283    Many of the valid output streams are also valid as input streams.
284 The difference between input and output streams is therefore mostly one
285 of how you use a Lisp object, not a distinction of types of object.
286
287    Here is an example of a buffer used as an output stream.  Point is
288 initially located as shown immediately before the `h' in `the'.  At the
289 end, point is located directly before that same `h'.
290
291      ---------- Buffer: foo ----------
292      This is t-!-he contents of foo.
293      ---------- Buffer: foo ----------
294      
295      (print "This is the output" (get-buffer "foo"))
296           => "This is the output"
297      
298      ---------- Buffer: foo ----------
299      This is t
300      "This is the output"
301      -!-he contents of foo.
302      ---------- Buffer: foo ----------
303
304    Now we show a use of a marker as an output stream.  Initially, the
305 marker is in buffer `foo', between the `t' and the `h' in the word
306 `the'.  At the end, the marker has advanced over the inserted text so
307 that it remains positioned before the same `h'.  Note that the location
308 of point, shown in the usual fashion, has no effect.
309
310      ---------- Buffer: foo ----------
311      "This is the -!-output"
312      ---------- Buffer: foo ----------
313      
314      m
315           => #<marker at 11 in foo>
316      
317      (print "More output for foo." m)
318           => "More output for foo."
319      
320      ---------- Buffer: foo ----------
321      "This is t
322      "More output for foo."
323      he -!-output"
324      ---------- Buffer: foo ----------
325      
326      m
327           => #<marker at 35 in foo>
328
329    The following example shows output to the echo area:
330
331      (print "Echo Area output" t)
332           => "Echo Area output"
333      ---------- Echo Area ----------
334      "Echo Area output"
335      ---------- Echo Area ----------
336
337    Finally, we show the use of a function as an output stream.  The
338 function `eat-output' takes each character that it is given and conses
339 it onto the front of the list `last-output' (*note Building Lists::).
340 At the end, the list contains all the characters output, but in reverse
341 order.
342
343      (setq last-output nil)
344           => nil
345      
346      (defun eat-output (c)
347        (setq last-output (cons c last-output)))
348           => eat-output
349      
350      (print "This is the output" 'eat-output)
351           => "This is the output"
352      
353      last-output
354           => (?\n ?\" ?t ?u ?p ?t ?u ?o ?\  ?e ?h ?t
355                      ?\  ?s ?i ?\  ?s ?i ?h ?T ?\" ?\n)
356
357 Now we can put the output in the proper order by reversing the list:
358
359      (concat (nreverse last-output))
360           => "
361      \"This is the output\"
362      "
363
364 Calling `concat' converts the list to a string so you can see its
365 contents more clearly.
366
367 \1f
368 File: lispref.info,  Node: Output Functions,  Next: Output Variables,  Prev: Output Streams,  Up: Read and Print
369
370 Output Functions
371 ================
372
373    This section describes the Lisp functions for printing Lisp objects.
374
375    Some of the XEmacs printing functions add quoting characters to the
376 output when necessary so that it can be read properly.  The quoting
377 characters used are `"' and `\'; they distinguish strings from symbols,
378 and prevent punctuation characters in strings and symbols from being
379 taken as delimiters when reading.  *Note Printed Representation::, for
380 full details.  You specify quoting or no quoting by the choice of
381 printing function.
382
383    If the text is to be read back into Lisp, then it is best to print
384 with quoting characters to avoid ambiguity.  Likewise, if the purpose is
385 to describe a Lisp object clearly for a Lisp programmer.  However, if
386 the purpose of the output is to look nice for humans, then it is better
387 to print without quoting.
388
389    Printing a self-referent Lisp object requires an infinite amount of
390 text.  In certain cases, trying to produce this text leads to a stack
391 overflow.  XEmacs detects such recursion and prints `#LEVEL' instead of
392 recursively printing an object already being printed.  For example,
393 here `#0' indicates a recursive reference to the object at level 0 of
394 the current print operation:
395
396      (setq foo (list nil))
397           => (nil)
398      (setcar foo foo)
399           => (#0)
400
401    In the functions below, STREAM stands for an output stream.  (See
402 the previous section for a description of output streams.)  If STREAM
403 is `nil' or omitted, it defaults to the value of `standard-output'.
404
405  - Function: print object &optional stream
406      The `print' function is a convenient way of printing.  It outputs
407      the printed representation of OBJECT to STREAM, printing in
408      addition one newline before OBJECT and another after it.  Quoting
409      characters are used.  `print' returns OBJECT.  For example:
410
411           (progn (print 'The\ cat\ in)
412                  (print "the hat")
413                  (print " came back"))
414                -|
415                -| The\ cat\ in
416                -|
417                -| "the hat"
418                -|
419                -| " came back"
420                -|
421                => " came back"
422
423  - Function: prin1 object &optional stream
424      This function outputs the printed representation of OBJECT to
425      STREAM.  It does not print newlines to separate output as `print'
426      does, but it does use quoting characters just like `print'.  It
427      returns OBJECT.
428
429           (progn (prin1 'The\ cat\ in)
430                  (prin1 "the hat")
431                  (prin1 " came back"))
432                -| The\ cat\ in"the hat"" came back"
433                => " came back"
434
435  - Function: princ object &optional stream
436      This function outputs the printed representation of OBJECT to
437      STREAM.  It returns OBJECT.
438
439      This function is intended to produce output that is readable by
440      people, not by `read', so it doesn't insert quoting characters and
441      doesn't put double-quotes around the contents of strings.  It does
442      not add any spacing between calls.
443
444           (progn
445             (princ 'The\ cat)
446             (princ " in the \"hat\""))
447                -| The cat in the "hat"
448                => " in the \"hat\""
449
450  - Function: terpri &optional stream
451      This function outputs a newline to STREAM.  The name stands for
452      "terminate print".
453
454  - Function: write-char character &optional stream
455      This function outputs CHARACTER to STREAM.  It returns CHARACTER.
456
457  - Function: prin1-to-string object &optional noescape
458      This function returns a string containing the text that `prin1'
459      would have printed for the same argument.
460
461           (prin1-to-string 'foo)
462                => "foo"
463           (prin1-to-string (mark-marker))
464                => "#<marker at 2773 in strings.texi>"
465
466      If NOESCAPE is non-`nil', that inhibits use of quoting characters
467      in the output.  (This argument is supported in Emacs versions 19
468      and later.)
469
470           (prin1-to-string "foo")
471                => "\"foo\""
472           (prin1-to-string "foo" t)
473                => "foo"
474
475      See `format', in *Note String Conversion::, for other ways to
476      obtain the printed representation of a Lisp object as a string.
477
478 \1f
479 File: lispref.info,  Node: Output Variables,  Prev: Output Functions,  Up: Read and Print
480
481 Variables Affecting Output
482 ==========================
483
484  - Variable: standard-output
485      The value of this variable is the default output stream--the stream
486      that print functions use when the STREAM argument is `nil'.
487
488  - Variable: print-escape-newlines
489      If this variable is non-`nil', then newline characters in strings
490      are printed as `\n' and formfeeds are printed as `\f'.  Normally
491      these characters are printed as actual newlines and formfeeds.
492
493      This variable affects the print functions `prin1' and `print', as
494      well as everything that uses them.  It does not affect `princ'.
495      Here is an example using `prin1':
496
497           (prin1 "a\nb")
498                -| "a
499                -| b"
500                => "a
501           b"
502           
503           (let ((print-escape-newlines t))
504             (prin1 "a\nb"))
505                -| "a\nb"
506                => "a
507           b"
508
509      In the second expression, the local binding of
510      `print-escape-newlines' is in effect during the call to `prin1',
511      but not during the printing of the result.
512
513  - Variable: print-readably
514      If non-`nil', then all objects will be printed in a readable form.
515      If an object has no readable representation, then an error is
516      signalled.  When `print-readably' is true, compiled-function
517      objects will be written in `#[...]' form instead of in
518      `#<compiled-function [...]>' form, and two-element lists of the
519      form `(quote object)' will be written as the equivalent `'object'.
520      Do not _set_ this variable; bind it instead.
521
522  - Variable: print-length
523      The value of this variable is the maximum number of elements of a
524      list that will be printed.  If a list being printed has more than
525      this many elements, it is abbreviated with an ellipsis.
526
527      If the value is `nil' (the default), then there is no limit.
528
529           (setq print-length 2)
530                => 2
531           (print '(1 2 3 4 5))
532                -| (1 2 ...)
533                => (1 2 ...)
534
535  - Variable: print-level
536      The value of this variable is the maximum depth of nesting of
537      parentheses and brackets when printed.  Any list or vector at a
538      depth exceeding this limit is abbreviated with an ellipsis.  A
539      value of `nil' (which is the default) means no limit.
540
541      This variable exists in version 19 and later versions.
542
543  - Variable: print-string-length
544      The value of this variable is the maximum number of characters of
545      a string that will be printed.  If a string being printed has more
546      than this many characters, it is abbreviated with an ellipsis.
547
548  - Variable: print-gensym
549      If non-`nil', then uninterned symbols will be printed specially.
550      Uninterned symbols are those which are not present in `obarray',
551      that is, those which were made with `make-symbol' or by calling
552      `intern' with a second argument.
553
554      When `print-gensym' is true, such symbols will be preceded by
555      `#:', which causes the reader to create a new symbol instead of
556      interning and returning an existing one.  Beware: The `#:' syntax
557      creates a new symbol each time it is seen, so if you print an
558      object which contains two pointers to the same uninterned symbol,
559      `read' will not duplicate that structure.
560
561      Also, since XEmacs has no real notion of packages, there is no way
562      for the printer to distinguish between symbols interned in no
563      obarray, and symbols interned in an alternate obarray.
564
565  - Variable: float-output-format
566      This variable holds the format descriptor string that Lisp uses to
567      print floats.  This is a `%'-spec like those accepted by `printf'
568      in C, but with some restrictions.  It must start with the two
569      characters `%.'.  After that comes an integer precision
570      specification, and then a letter which controls the format.  The
571      letters allowed are `e', `f' and `g'.
572
573         * Use `e' for exponential notation `DIG.DIGITSeEXPT'.
574
575         * Use `f' for decimal point notation `DIGITS.DIGITS'.
576
577         * Use `g' to choose the shorter of those two formats for the
578           number at hand.
579
580      The precision in any of these cases is the number of digits
581      following the decimal point.  With `f', a precision of 0 means to
582      omit the decimal point.  0 is not allowed with `f' or `g'.
583
584      A value of nil means to use `%.16g'.
585
586      Regardless of the value of `float-output-format', a floating point
587      number will never be printed in such a way that it is ambiguous
588      with an integer; that is, a floating-point number will always be
589      printed with a decimal point and/or an exponent, even if the
590      digits following the decimal point are all zero.  This is to
591      preserve read-equivalence.
592
593 \1f
594 File: lispref.info,  Node: Minibuffers,  Next: Command Loop,  Prev: Read and Print,  Up: Top
595
596 Minibuffers
597 ***********
598
599    A "minibuffer" is a special buffer that XEmacs commands use to read
600 arguments more complicated than the single numeric prefix argument.
601 These arguments include file names, buffer names, and command names (as
602 in `M-x').  The minibuffer is displayed on the bottom line of the
603 frame, in the same place as the echo area, but only while it is in use
604 for reading an argument.
605
606 * Menu:
607
608 * Intro to Minibuffers::      Basic information about minibuffers.
609 * Text from Minibuffer::      How to read a straight text string.
610 * Object from Minibuffer::    How to read a Lisp object or expression.
611 * Minibuffer History::        Recording previous minibuffer inputs
612                                 so the user can reuse them.
613 * Completion::                How to invoke and customize completion.
614 * Yes-or-No Queries::         Asking a question with a simple answer.
615 * Multiple Queries::          Asking a series of similar questions.
616 * Reading a Password::        Reading a password from the terminal.
617 * Minibuffer Misc::           Various customization hooks and variables.
618
619 \1f
620 File: lispref.info,  Node: Intro to Minibuffers,  Next: Text from Minibuffer,  Up: Minibuffers
621
622 Introduction to Minibuffers
623 ===========================
624
625    In most ways, a minibuffer is a normal XEmacs buffer.  Most
626 operations _within_ a buffer, such as editing commands, work normally
627 in a minibuffer.  However, many operations for managing buffers do not
628 apply to minibuffers.  The name of a minibuffer always has the form
629 ` *Minibuf-NUMBER', and it cannot be changed.  Minibuffers are
630 displayed only in special windows used only for minibuffers; these
631 windows always appear at the bottom of a frame.  (Sometimes frames have
632 no minibuffer window, and sometimes a special kind of frame contains
633 nothing but a minibuffer window; see *Note Minibuffers and Frames::.)
634
635    The minibuffer's window is normally a single line.  You can resize it
636 temporarily with the window sizing commands; it reverts to its normal
637 size when the minibuffer is exited.  You can resize it permanently by
638 using the window sizing commands in the frame's other window, when the
639 minibuffer is not active.  If the frame contains just a minibuffer, you
640 can change the minibuffer's size by changing the frame's size.
641
642    If a command uses a minibuffer while there is an active minibuffer,
643 this is called a "recursive minibuffer".  The first minibuffer is named
644 ` *Minibuf-0*'.  Recursive minibuffers are named by incrementing the
645 number at the end of the name.  (The names begin with a space so that
646 they won't show up in normal buffer lists.)  Of several recursive
647 minibuffers, the innermost (or most recently entered) is the active
648 minibuffer.  We usually call this "the" minibuffer.  You can permit or
649 forbid recursive minibuffers by setting the variable
650 `enable-recursive-minibuffers'.
651
652    Like other buffers, a minibuffer may use any of several local keymaps
653 (*note Keymaps::); these contain various exit commands and in some cases
654 completion commands (*note Completion::).
655
656    * `minibuffer-local-map' is for ordinary input (no completion).
657
658    * `minibuffer-local-completion-map' is for permissive completion.
659
660    * `minibuffer-local-must-match-map' is for strict completion and for
661      cautious completion.
662
663 \1f
664 File: lispref.info,  Node: Text from Minibuffer,  Next: Object from Minibuffer,  Prev: Intro to Minibuffers,  Up: Minibuffers
665
666 Reading Text Strings with the Minibuffer
667 ========================================
668
669    Most often, the minibuffer is used to read text as a string.  It can
670 also be used to read a Lisp object in textual form.  The most basic
671 primitive for minibuffer input is `read-from-minibuffer'; it can do
672 either one.
673
674    In most cases, you should not call minibuffer input functions in the
675 middle of a Lisp function.  Instead, do all minibuffer input as part of
676 reading the arguments for a command, in the `interactive' spec.  *Note
677 Defining Commands::.
678
679  - Function: read-from-minibuffer prompt-string &optional
680           initial-contents keymap read hist abbrev-table default
681      This function is the most general way to get input through the
682      minibuffer.  By default, it accepts arbitrary text and returns it
683      as a string; however, if READ is non-`nil', then it uses `read' to
684      convert the text into a Lisp object (*note Input Functions::).
685
686      The first thing this function does is to activate a minibuffer and
687      display it with PROMPT-STRING as the prompt.  This value must be a
688      string.
689
690      Then, if INITIAL-CONTENTS is a string, `read-from-minibuffer'
691      inserts it into the minibuffer, leaving point at the end.  The
692      minibuffer appears with this text as its contents.
693
694      The value of INITIAL-CONTENTS may also be a cons cell of the form
695      `(STRING . POSITION)'.  This means to insert STRING in the
696      minibuffer but put point POSITION characters from the beginning,
697      rather than at the end.
698
699      When the user types a command to exit the minibuffer,
700      `read-from-minibuffer' constructs the return value from the text in
701      the minibuffer.  Normally it returns a string containing that text.
702      However, if READ is non-`nil', `read-from-minibuffer' reads the
703      text and returns the resulting Lisp object, unevaluated.  (*Note
704      Input Functions::, for information about reading.)
705
706      The argument DEFAULT specifies a default value to make available
707      through the history commands.  It should be a string, or `nil'.
708
709      If KEYMAP is non-`nil', that keymap is the local keymap to use in
710      the minibuffer.  If KEYMAP is omitted or `nil', the value of
711      `minibuffer-local-map' is used as the keymap.  Specifying a keymap
712      is the most important way to customize the minibuffer for various
713      applications such as completion.
714
715      The argument ABBREV-TABLE specifies `local-abbrev-table' in the
716      minibuffer (*note Standard Abbrev Tables::).
717
718      The argument HIST specifies which history list variable to use for
719      saving the input and for history commands used in the minibuffer.
720      It defaults to `minibuffer-history'.  *Note Minibuffer History::.
721
722      When the user types a command to exit the minibuffer,
723      `read-from-minibuffer' uses the text in the minibuffer to produce
724      its return value.  Normally it simply makes a string containing
725      that text.  However, if READ is non-`nil', `read-from-minibuffer'
726      reads the text and returns the resulting Lisp object, unevaluated.
727      (*Note Input Functions::, for information about reading.)
728
729      *Usage note:* The INITIAL-CONTENTS argument and the DEFAULT
730      argument are two alternative features for more or less the same
731      job.  It does not make sense to use both features in a single call
732      to `read-from-minibuffer'.  In general, we recommend using
733      DEFAULT, since this permits the user to insert the default value
734      when it is wanted, but does not burden the user with deleting it
735      from the minibuffer on other occasions.  However, if user is
736      supposed to edit default value, INITIAL-CONTENTS may be preferred.
737
738  - Function: read-string prompt &optional initial history default-value
739      This function reads a string from the minibuffer and returns it.
740      The arguments PROMPT and INITIAL are used as in
741      `read-from-minibuffer'.  The keymap used is `minibuffer-local-map'.
742
743      The optional argument HISTORY, if non-nil, specifies a history
744      list and optionally the initial position in the list.  The optional
745      argument DEFAULT specifies a default value to return if the user
746      enters null input; it should be a string.
747
748      This function is a simplified interface to the
749      `read-from-minibuffer' function:
750
751           (read-string PROMPT INITIAL HISTORY DEFAULT)
752           ==
753           (read-from-minibuffer PROMPT INITIAL nil nil
754                                 HISTORY nil DEFAULT)))
755
756  - Variable: minibuffer-local-map
757      This is the default local keymap for reading from the minibuffer.
758      By default, it makes the following bindings:
759
760     `C-j'
761           `exit-minibuffer'
762
763     <RET>
764           `exit-minibuffer'
765
766     `C-g'
767           `abort-recursive-edit'
768
769     `M-n'
770           `next-history-element'
771
772     `M-p'
773           `previous-history-element'
774
775     `M-r'
776           `next-matching-history-element'
777
778     `M-s'
779           `previous-matching-history-element'
780
781 \1f
782 File: lispref.info,  Node: Object from Minibuffer,  Next: Minibuffer History,  Prev: Text from Minibuffer,  Up: Minibuffers
783
784 Reading Lisp Objects with the Minibuffer
785 ========================================
786
787    This section describes functions for reading Lisp objects with the
788 minibuffer.
789
790  - Function: read-expression prompt &optional initial history
791           default-value
792      This function reads a Lisp object using the minibuffer, and
793      returns it without evaluating it.  The arguments PROMPT and
794      INITIAL are used as in `read-from-minibuffer'.
795
796      The optional argument HISTORY, if non-nil, specifies a history
797      list and optionally the initial position in the list.  The optional
798      argument DEFAULT-VALUE specifies a default value to return if the
799      user enters null input; it should be a string.
800
801      This is a simplified interface to the `read-from-minibuffer'
802      function:
803
804           (read-expression PROMPT INITIAL HISTORY DEFAULT-VALUE)
805           ==
806           (read-from-minibuffer PROMPT INITIAL nil t
807                                 HISTORY nil DEFAULT-VALUE)
808
809      Here is an example in which we supply the string `"(testing)"' as
810      initial input:
811
812           (read-expression
813            "Enter an expression: " (format "%s" '(testing)))
814           
815           ;; Here is how the minibuffer is displayed:
816           
817           ---------- Buffer: Minibuffer ----------
818           Enter an expression: (testing)-!-
819           ---------- Buffer: Minibuffer ----------
820
821      The user can type <RET> immediately to use the initial input as a
822      default, or can edit the input.
823
824  - Function: read-minibuffer prompt &optional initial history
825           default-value
826      This is a FSF Emacs compatible function.  Use `read-expression'
827      instead.
828
829  - Function: eval-minibuffer prompt &optional initial history
830           default-value
831      This function reads a Lisp expression using the minibuffer,
832      evaluates it, then returns the result.  The arguments PROMPT and
833      INITIAL are used as in `read-from-minibuffer'.
834
835      The optional argument HISTORY, if non-nil, specifies a history
836      list and optionally the initial position in the list.  The optional
837      argument DEFAULT-VALUE specifies a default value to return if the
838      user enters null input; it should be a string.
839
840      This function simply evaluates the result of a call to
841      `read-expression':
842
843           (eval-minibuffer PROMPT INITIAL)
844           ==
845           (eval (read-expression PROMPT INITIAL))
846
847  - Function: edit-and-eval-command prompt command &optional history
848      This function reads a Lisp expression in the minibuffer, and then
849      evaluates it.  The difference between this command and
850      `eval-minibuffer' is that here the initial COMMAND is not optional
851      and it is treated as a Lisp object to be converted to printed
852      representation rather than as a string of text.  It is printed with
853      `prin1', so if it is a string, double-quote characters (`"')
854      appear in the initial text.  *Note Output Functions::.
855
856      The first thing `edit-and-eval-command' does is to activate the
857      minibuffer with PROMPT as the prompt.  Then it inserts the printed
858      representation of FORM in the minibuffer, and lets the user edit
859      it.  When the user exits the minibuffer, the edited text is read
860      with `read' and then evaluated.  The resulting value becomes the
861      value of `edit-and-eval-command'.
862
863      In the following example, we offer the user an expression with
864      initial text which is a valid form already:
865
866           (edit-and-eval-command "Please edit: " '(forward-word 1))
867           
868           ;; After evaluation of the preceding expression,
869           ;;   the following appears in the minibuffer:
870           
871           ---------- Buffer: Minibuffer ----------
872           Please edit: (forward-word 1)-!-
873           ---------- Buffer: Minibuffer ----------
874
875      Typing <RET> right away would exit the minibuffer and evaluate the
876      expression, thus moving point forward one word.
877      `edit-and-eval-command' returns `t' in this example.
878
879 \1f
880 File: lispref.info,  Node: Minibuffer History,  Next: Completion,  Prev: Object from Minibuffer,  Up: Minibuffers
881
882 Minibuffer History
883 ==================
884
885    A "minibuffer history list" records previous minibuffer inputs so
886 the user can reuse them conveniently.  A history list is actually a
887 symbol, not a list; it is a variable whose value is a list of strings
888 (previous inputs), most recent first.
889
890    There are many separate history lists, used for different kinds of
891 inputs.  It's the Lisp programmer's job to specify the right history
892 list for each use of the minibuffer.
893
894    The basic minibuffer input functions `read-from-minibuffer' and
895 `completing-read' both accept an optional argument named HIST which is
896 how you specify the history list.  Here are the possible values:
897
898 VARIABLE
899      Use VARIABLE (a symbol) as the history list.
900
901 (VARIABLE . STARTPOS)
902      Use VARIABLE (a symbol) as the history list, and assume that the
903      initial history position is STARTPOS (an integer, counting from
904      zero which specifies the most recent element of the history).
905
906      If you specify STARTPOS, then you should also specify that element
907      of the history as the initial minibuffer contents, for consistency.
908
909    If you don't specify HIST, then the default history list
910 `minibuffer-history' is used.  For other standard history lists, see
911 below.  You can also create your own history list variable; just
912 initialize it to `nil' before the first use.
913
914    Both `read-from-minibuffer' and `completing-read' add new elements
915 to the history list automatically, and provide commands to allow the
916 user to reuse items on the list.  The only thing your program needs to
917 do to use a history list is to initialize it and to pass its name to
918 the input functions when you wish.  But it is safe to modify the list
919 by hand when the minibuffer input functions are not using it.
920
921    Here are some of the standard minibuffer history list variables:
922
923  - Variable: minibuffer-history
924      The default history list for minibuffer history input.
925
926  - Variable: query-replace-history
927      A history list for arguments to `query-replace' (and similar
928      arguments to other commands).
929
930  - Variable: file-name-history
931      A history list for file name arguments.
932
933  - Variable: regexp-history
934      A history list for regular expression arguments.
935
936  - Variable: extended-command-history
937      A history list for arguments that are names of extended commands.
938
939  - Variable: shell-command-history
940      A history list for arguments that are shell commands.
941
942  - Variable: read-expression-history
943      A history list for arguments that are Lisp expressions to evaluate.
944
945  - Variable: Info-minibuffer-history
946      A history list for Info mode's minibuffer.
947
948  - Variable: Manual-page-minibuffer-history
949      A history list for `manual-entry'.
950
951    There are many other minibuffer history lists, defined by various
952 libraries.  An `M-x apropos' search for `history' should prove fruitful
953 in discovering them.
954
955 \1f
956 File: lispref.info,  Node: Completion,  Next: Yes-or-No Queries,  Prev: Minibuffer History,  Up: Minibuffers
957
958 Completion
959 ==========
960
961    "Completion" is a feature that fills in the rest of a name starting
962 from an abbreviation for it.  Completion works by comparing the user's
963 input against a list of valid names and determining how much of the
964 name is determined uniquely by what the user has typed.  For example,
965 when you type `C-x b' (`switch-to-buffer') and then type the first few
966 letters of the name of the buffer to which you wish to switch, and then
967 type <TAB> (`minibuffer-complete'), Emacs extends the name as far as it
968 can.
969
970    Standard XEmacs commands offer completion for names of symbols,
971 files, buffers, and processes; with the functions in this section, you
972 can implement completion for other kinds of names.
973
974    The `try-completion' function is the basic primitive for completion:
975 it returns the longest determined completion of a given initial string,
976 with a given set of strings to match against.
977
978    The function `completing-read' provides a higher-level interface for
979 completion.  A call to `completing-read' specifies how to determine the
980 list of valid names.  The function then activates the minibuffer with a
981 local keymap that binds a few keys to commands useful for completion.
982 Other functions provide convenient simple interfaces for reading
983 certain kinds of names with completion.
984
985 * Menu:
986
987 * Basic Completion::       Low-level functions for completing strings.
988                              (These are too low level to use the minibuffer.)
989 * Minibuffer Completion::  Invoking the minibuffer with completion.
990 * Completion Commands::    Minibuffer commands that do completion.
991 * High-Level Completion::  Convenient special cases of completion
992                              (reading buffer name, file name, etc.)
993 * Reading File Names::     Using completion to read file names.
994 * Programmed Completion::  Finding the completions for a given file name.
995
996 \1f
997 File: lispref.info,  Node: Basic Completion,  Next: Minibuffer Completion,  Up: Completion
998
999 Basic Completion Functions
1000 --------------------------
1001
1002    The two functions `try-completion' and `all-completions' have
1003 nothing in themselves to do with minibuffers.  We describe them in this
1004 chapter so as to keep them near the higher-level completion features
1005 that do use the minibuffer.
1006
1007  - Function: try-completion string collection &optional predicate
1008      This function returns the longest common substring of all possible
1009      completions of STRING in COLLECTION.  The value of COLLECTION must
1010      be an alist, an obarray, or a function that implements a virtual
1011      set of strings (see below).
1012
1013      Completion compares STRING against each of the permissible
1014      completions specified by COLLECTION; if the beginning of the
1015      permissible completion equals STRING, it matches.  If no
1016      permissible completions match, `try-completion' returns `nil'.  If
1017      only one permissible completion matches, and the match is exact,
1018      then `try-completion' returns `t'.  Otherwise, the value is the
1019      longest initial sequence common to all the permissible completions
1020      that match.
1021
1022      If COLLECTION is an alist (*note Association Lists::), the CARs of
1023      the alist elements form the set of permissible completions.
1024
1025      If COLLECTION is an obarray (*note Creating Symbols::), the names
1026      of all symbols in the obarray form the set of permissible
1027      completions.  The global variable `obarray' holds an obarray
1028      containing the names of all interned Lisp symbols.
1029
1030      Note that the only valid way to make a new obarray is to create it
1031      empty and then add symbols to it one by one using `intern'.  Also,
1032      you cannot intern a given symbol in more than one obarray.
1033
1034      If the argument PREDICATE is non-`nil', then it must be a function
1035      of one argument.  It is used to test each possible match, and the
1036      match is accepted only if PREDICATE returns non-`nil'.  The
1037      argument given to PREDICATE is either a cons cell from the alist
1038      (the CAR of which is a string) or else it is a symbol (_not_ a
1039      symbol name) from the obarray.
1040
1041      You can also use a symbol that is a function as COLLECTION.  Then
1042      the function is solely responsible for performing completion;
1043      `try-completion' returns whatever this function returns.  The
1044      function is called with three arguments: STRING, PREDICATE and
1045      `nil'.  (The reason for the third argument is so that the same
1046      function can be used in `all-completions' and do the appropriate
1047      thing in either case.)  *Note Programmed Completion::.
1048
1049      In the first of the following examples, the string `foo' is
1050      matched by three of the alist CARs.  All of the matches begin with
1051      the characters `fooba', so that is the result.  In the second
1052      example, there is only one possible match, and it is exact, so the
1053      value is `t'.
1054
1055           (try-completion
1056            "foo"
1057            '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4)))
1058                => "fooba"
1059           
1060           (try-completion "foo" '(("barfoo" 2) ("foo" 3)))
1061                => t
1062
1063      In the following example, numerous symbols begin with the
1064      characters `forw', and all of them begin with the word `forward'.
1065      In most of the symbols, this is followed with a `-', but not in
1066      all, so no more than `forward' can be completed.
1067
1068           (try-completion "forw" obarray)
1069                => "forward"
1070
1071      Finally, in the following example, only two of the three possible
1072      matches pass the predicate `test' (the string `foobaz' is too
1073      short).  Both of those begin with the string `foobar'.
1074
1075           (defun test (s)
1076             (> (length (car s)) 6))
1077                => test
1078           (try-completion
1079            "foo"
1080            '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
1081            'test)
1082                => "foobar"
1083
1084  - Function: all-completions string collection &optional predicate
1085           nospace
1086      This function returns a list of all possible completions of
1087      STRING.  The arguments to this function are the same as those of
1088      `try-completion'.
1089
1090      If COLLECTION is a function, it is called with three arguments:
1091      STRING, PREDICATE and `t'; then `all-completions' returns whatever
1092      the function returns.  *Note Programmed Completion::.
1093
1094      If NOSPACE is non-`nil', completions that start with a space are
1095      ignored unless STRING also starts with a space.
1096
1097      Here is an example, using the function `test' shown in the example
1098      for `try-completion':
1099
1100           (defun test (s)
1101             (> (length (car s)) 6))
1102                => test
1103           
1104           (all-completions
1105            "foo"
1106            '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
1107            'test)
1108                => ("foobar1" "foobar2")
1109
1110  - Variable: completion-ignore-case
1111      If the value of this variable is non-`nil', XEmacs does not
1112      consider case significant in completion.
1113
1114 \1f
1115 File: lispref.info,  Node: Minibuffer Completion,  Next: Completion Commands,  Prev: Basic Completion,  Up: Completion
1116
1117 Completion and the Minibuffer
1118 -----------------------------
1119
1120    This section describes the basic interface for reading from the
1121 minibuffer with completion.
1122
1123  - Function: completing-read prompt collection &optional predicate
1124           require-match initial hist default
1125      This function reads a string in the minibuffer, assisting the user
1126      by providing completion.  It activates the minibuffer with prompt
1127      PROMPT, which must be a string.  If INITIAL is non-`nil',
1128      `completing-read' inserts it into the minibuffer as part of the
1129      input.  Then it allows the user to edit the input, providing
1130      several commands to attempt completion.
1131
1132      The actual completion is done by passing COLLECTION and PREDICATE
1133      to the function `try-completion'.  This happens in certain
1134      commands bound in the local keymaps used for completion.
1135
1136      If REQUIRE-MATCH is `t', the usual minibuffer exit commands won't
1137      exit unless the input completes to an element of COLLECTION.  If
1138      REQUIRE-MATCH is neither `nil' nor `t', then the exit commands
1139      won't exit unless the input typed is itself an element of
1140      COLLECTION.  If REQUIRE-MATCH is `nil', the exit commands work
1141      regardless of the input in the minibuffer.
1142
1143      However, empty input is always permitted, regardless of the value
1144      of REQUIRE-MATCH; in that case, `completing-read' returns DEFAULT.
1145      The value of DEFAULT (if non-`nil') is also available to the user
1146      through the history commands.
1147
1148      The user can exit with null input by typing <RET> with an empty
1149      minibuffer.  Then `completing-read' returns `""'.  This is how the
1150      user requests whatever default the command uses for the value being
1151      read.  The user can return using <RET> in this way regardless of
1152      the value of REQUIRE-MATCH, and regardless of whether the empty
1153      string is included in COLLECTION.
1154
1155      The function `completing-read' works by calling `read-expression'.
1156      It uses `minibuffer-local-completion-map' as the keymap if
1157      REQUIRE-MATCH is `nil', and uses `minibuffer-local-must-match-map'
1158      if REQUIRE-MATCH is non-`nil'.  *Note Completion Commands::.
1159
1160      The argument HIST specifies which history list variable to use for
1161      saving the input and for minibuffer history commands.  It defaults
1162      to `minibuffer-history'.  *Note Minibuffer History::.
1163
1164      Completion ignores case when comparing the input against the
1165      possible matches, if the built-in variable
1166      `completion-ignore-case' is non-`nil'.  *Note Basic Completion::.
1167
1168      Here's an example of using `completing-read':
1169
1170           (completing-read
1171            "Complete a foo: "
1172            '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
1173            nil t "fo")
1174           
1175           ;; After evaluation of the preceding expression,
1176           ;;   the following appears in the minibuffer:
1177           
1178           ---------- Buffer: Minibuffer ----------
1179           Complete a foo: fo-!-
1180           ---------- Buffer: Minibuffer ----------
1181
1182      If the user then types `<DEL> <DEL> b <RET>', `completing-read'
1183      returns `barfoo'.
1184
1185      The `completing-read' function binds three variables to pass
1186      information to the commands that actually do completion.  These
1187      variables are `minibuffer-completion-table',
1188      `minibuffer-completion-predicate' and
1189      `minibuffer-completion-confirm'.  For more information about them,
1190      see *Note Completion Commands::.
1191