Sync with r21-2-28.
[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
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.
745
746      This function is a simplified interface to the
747      `read-from-minibuffer' function:
748
749           (read-string PROMPT INITIAL)
750           ==
751           (read-from-minibuffer PROMPT INITIAL nil nil nil)
752
753  - Variable: minibuffer-local-map
754      This is the default local keymap for reading from the minibuffer.
755      By default, it makes the following bindings:
756
757     `C-j'
758           `exit-minibuffer'
759
760     <RET>
761           `exit-minibuffer'
762
763     `C-g'
764           `abort-recursive-edit'
765
766     `M-n'
767           `next-history-element'
768
769     `M-p'
770           `previous-history-element'
771
772     `M-r'
773           `next-matching-history-element'
774
775     `M-s'
776           `previous-matching-history-element'
777
778 \1f
779 File: lispref.info,  Node: Object from Minibuffer,  Next: Minibuffer History,  Prev: Text from Minibuffer,  Up: Minibuffers
780
781 Reading Lisp Objects with the Minibuffer
782 ========================================
783
784    This section describes functions for reading Lisp objects with the
785 minibuffer.
786
787  - Function: read-minibuffer prompt &optional initial
788      This function reads a Lisp object using the minibuffer, and
789      returns it without evaluating it.  The arguments PROMPT and
790      INITIAL are used as in `read-from-minibuffer'.
791
792      This is a simplified interface to the `read-from-minibuffer'
793      function:
794
795           (read-minibuffer PROMPT INITIAL)
796           ==
797           (read-from-minibuffer PROMPT INITIAL nil t)
798
799      Here is an example in which we supply the string `"(testing)"' as
800      initial input:
801
802           (read-minibuffer
803            "Enter an expression: " (format "%s" '(testing)))
804           
805           ;; Here is how the minibuffer is displayed:
806           
807           ---------- Buffer: Minibuffer ----------
808           Enter an expression: (testing)-!-
809           ---------- Buffer: Minibuffer ----------
810
811      The user can type <RET> immediately to use the initial input as a
812      default, or can edit the input.
813
814  - Function: eval-minibuffer prompt &optional initial
815      This function reads a Lisp expression using the minibuffer,
816      evaluates it, then returns the result.  The arguments PROMPT and
817      INITIAL are used as in `read-from-minibuffer'.
818
819      This function simply evaluates the result of a call to
820      `read-minibuffer':
821
822           (eval-minibuffer PROMPT INITIAL)
823           ==
824           (eval (read-minibuffer PROMPT INITIAL))
825
826  - Function: edit-and-eval-command prompt form
827      This function reads a Lisp expression in the minibuffer, and then
828      evaluates it.  The difference between this command and
829      `eval-minibuffer' is that here the initial FORM is not optional
830      and it is treated as a Lisp object to be converted to printed
831      representation rather than as a string of text.  It is printed with
832      `prin1', so if it is a string, double-quote characters (`"')
833      appear in the initial text.  *Note Output Functions::.
834
835      The first thing `edit-and-eval-command' does is to activate the
836      minibuffer with PROMPT as the prompt.  Then it inserts the printed
837      representation of FORM in the minibuffer, and lets the user edit
838      it.  When the user exits the minibuffer, the edited text is read
839      with `read' and then evaluated.  The resulting value becomes the
840      value of `edit-and-eval-command'.
841
842      In the following example, we offer the user an expression with
843      initial text which is a valid form already:
844
845           (edit-and-eval-command "Please edit: " '(forward-word 1))
846           
847           ;; After evaluation of the preceding expression,
848           ;;   the following appears in the minibuffer:
849           
850           ---------- Buffer: Minibuffer ----------
851           Please edit: (forward-word 1)-!-
852           ---------- Buffer: Minibuffer ----------
853
854      Typing <RET> right away would exit the minibuffer and evaluate the
855      expression, thus moving point forward one word.
856      `edit-and-eval-command' returns `t' in this example.
857
858 \1f
859 File: lispref.info,  Node: Minibuffer History,  Next: Completion,  Prev: Object from Minibuffer,  Up: Minibuffers
860
861 Minibuffer History
862 ==================
863
864    A "minibuffer history list" records previous minibuffer inputs so
865 the user can reuse them conveniently.  A history list is actually a
866 symbol, not a list; it is a variable whose value is a list of strings
867 (previous inputs), most recent first.
868
869    There are many separate history lists, used for different kinds of
870 inputs.  It's the Lisp programmer's job to specify the right history
871 list for each use of the minibuffer.
872
873    The basic minibuffer input functions `read-from-minibuffer' and
874 `completing-read' both accept an optional argument named HIST which is
875 how you specify the history list.  Here are the possible values:
876
877 VARIABLE
878      Use VARIABLE (a symbol) as the history list.
879
880 (VARIABLE . STARTPOS)
881      Use VARIABLE (a symbol) as the history list, and assume that the
882      initial history position is STARTPOS (an integer, counting from
883      zero which specifies the most recent element of the history).
884
885      If you specify STARTPOS, then you should also specify that element
886      of the history as the initial minibuffer contents, for consistency.
887
888    If you don't specify HIST, then the default history list
889 `minibuffer-history' is used.  For other standard history lists, see
890 below.  You can also create your own history list variable; just
891 initialize it to `nil' before the first use.
892
893    Both `read-from-minibuffer' and `completing-read' add new elements
894 to the history list automatically, and provide commands to allow the
895 user to reuse items on the list.  The only thing your program needs to
896 do to use a history list is to initialize it and to pass its name to
897 the input functions when you wish.  But it is safe to modify the list
898 by hand when the minibuffer input functions are not using it.
899
900    Here are some of the standard minibuffer history list variables:
901
902  - Variable: minibuffer-history
903      The default history list for minibuffer history input.
904
905  - Variable: query-replace-history
906      A history list for arguments to `query-replace' (and similar
907      arguments to other commands).
908
909  - Variable: file-name-history
910      A history list for file name arguments.
911
912  - Variable: regexp-history
913      A history list for regular expression arguments.
914
915  - Variable: extended-command-history
916      A history list for arguments that are names of extended commands.
917
918  - Variable: shell-command-history
919      A history list for arguments that are shell commands.
920
921  - Variable: read-expression-history
922      A history list for arguments that are Lisp expressions to evaluate.
923
924  - Variable: Info-minibuffer-history
925      A history list for Info mode's minibuffer.
926
927  - Variable: Manual-page-minibuffer-history
928      A history list for `manual-entry'.
929
930    There are many other minibuffer history lists, defined by various
931 libraries.  An `M-x apropos' search for `history' should prove fruitful
932 in discovering them.
933
934 \1f
935 File: lispref.info,  Node: Completion,  Next: Yes-or-No Queries,  Prev: Minibuffer History,  Up: Minibuffers
936
937 Completion
938 ==========
939
940    "Completion" is a feature that fills in the rest of a name starting
941 from an abbreviation for it.  Completion works by comparing the user's
942 input against a list of valid names and determining how much of the
943 name is determined uniquely by what the user has typed.  For example,
944 when you type `C-x b' (`switch-to-buffer') and then type the first few
945 letters of the name of the buffer to which you wish to switch, and then
946 type <TAB> (`minibuffer-complete'), Emacs extends the name as far as it
947 can.
948
949    Standard XEmacs commands offer completion for names of symbols,
950 files, buffers, and processes; with the functions in this section, you
951 can implement completion for other kinds of names.
952
953    The `try-completion' function is the basic primitive for completion:
954 it returns the longest determined completion of a given initial string,
955 with a given set of strings to match against.
956
957    The function `completing-read' provides a higher-level interface for
958 completion.  A call to `completing-read' specifies how to determine the
959 list of valid names.  The function then activates the minibuffer with a
960 local keymap that binds a few keys to commands useful for completion.
961 Other functions provide convenient simple interfaces for reading
962 certain kinds of names with completion.
963
964 * Menu:
965
966 * Basic Completion::       Low-level functions for completing strings.
967                              (These are too low level to use the minibuffer.)
968 * Minibuffer Completion::  Invoking the minibuffer with completion.
969 * Completion Commands::    Minibuffer commands that do completion.
970 * High-Level Completion::  Convenient special cases of completion
971                              (reading buffer name, file name, etc.)
972 * Reading File Names::     Using completion to read file names.
973 * Programmed Completion::  Finding the completions for a given file name.
974
975 \1f
976 File: lispref.info,  Node: Basic Completion,  Next: Minibuffer Completion,  Up: Completion
977
978 Basic Completion Functions
979 --------------------------
980
981    The two functions `try-completion' and `all-completions' have
982 nothing in themselves to do with minibuffers.  We describe them in this
983 chapter so as to keep them near the higher-level completion features
984 that do use the minibuffer.
985
986  - Function: try-completion string collection &optional predicate
987      This function returns the longest common substring of all possible
988      completions of STRING in COLLECTION.  The value of COLLECTION must
989      be an alist, an obarray, or a function that implements a virtual
990      set of strings (see below).
991
992      Completion compares STRING against each of the permissible
993      completions specified by COLLECTION; if the beginning of the
994      permissible completion equals STRING, it matches.  If no
995      permissible completions match, `try-completion' returns `nil'.  If
996      only one permissible completion matches, and the match is exact,
997      then `try-completion' returns `t'.  Otherwise, the value is the
998      longest initial sequence common to all the permissible completions
999      that match.
1000
1001      If COLLECTION is an alist (*note Association Lists::), the CARs of
1002      the alist elements form the set of permissible completions.
1003
1004      If COLLECTION is an obarray (*note Creating Symbols::), the names
1005      of all symbols in the obarray form the set of permissible
1006      completions.  The global variable `obarray' holds an obarray
1007      containing the names of all interned Lisp symbols.
1008
1009      Note that the only valid way to make a new obarray is to create it
1010      empty and then add symbols to it one by one using `intern'.  Also,
1011      you cannot intern a given symbol in more than one obarray.
1012
1013      If the argument PREDICATE is non-`nil', then it must be a function
1014      of one argument.  It is used to test each possible match, and the
1015      match is accepted only if PREDICATE returns non-`nil'.  The
1016      argument given to PREDICATE is either a cons cell from the alist
1017      (the CAR of which is a string) or else it is a symbol (_not_ a
1018      symbol name) from the obarray.
1019
1020      You can also use a symbol that is a function as COLLECTION.  Then
1021      the function is solely responsible for performing completion;
1022      `try-completion' returns whatever this function returns.  The
1023      function is called with three arguments: STRING, PREDICATE and
1024      `nil'.  (The reason for the third argument is so that the same
1025      function can be used in `all-completions' and do the appropriate
1026      thing in either case.)  *Note Programmed Completion::.
1027
1028      In the first of the following examples, the string `foo' is
1029      matched by three of the alist CARs.  All of the matches begin with
1030      the characters `fooba', so that is the result.  In the second
1031      example, there is only one possible match, and it is exact, so the
1032      value is `t'.
1033
1034           (try-completion
1035            "foo"
1036            '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4)))
1037                => "fooba"
1038           
1039           (try-completion "foo" '(("barfoo" 2) ("foo" 3)))
1040                => t
1041
1042      In the following example, numerous symbols begin with the
1043      characters `forw', and all of them begin with the word `forward'.
1044      In most of the symbols, this is followed with a `-', but not in
1045      all, so no more than `forward' can be completed.
1046
1047           (try-completion "forw" obarray)
1048                => "forward"
1049
1050      Finally, in the following example, only two of the three possible
1051      matches pass the predicate `test' (the string `foobaz' is too
1052      short).  Both of those begin with the string `foobar'.
1053
1054           (defun test (s)
1055             (> (length (car s)) 6))
1056                => test
1057           (try-completion
1058            "foo"
1059            '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
1060            'test)
1061                => "foobar"
1062
1063  - Function: all-completions string collection &optional predicate
1064           nospace
1065      This function returns a list of all possible completions of
1066      STRING.  The arguments to this function are the same as those of
1067      `try-completion'.
1068
1069      If COLLECTION is a function, it is called with three arguments:
1070      STRING, PREDICATE and `t'; then `all-completions' returns whatever
1071      the function returns.  *Note Programmed Completion::.
1072
1073      If NOSPACE is non-`nil', completions that start with a space are
1074      ignored unless STRING also starts with a space.
1075
1076      Here is an example, using the function `test' shown in the example
1077      for `try-completion':
1078
1079           (defun test (s)
1080             (> (length (car s)) 6))
1081                => test
1082           
1083           (all-completions
1084            "foo"
1085            '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
1086            'test)
1087                => ("foobar1" "foobar2")
1088
1089  - Variable: completion-ignore-case
1090      If the value of this variable is non-`nil', XEmacs does not
1091      consider case significant in completion.
1092
1093 \1f
1094 File: lispref.info,  Node: Minibuffer Completion,  Next: Completion Commands,  Prev: Basic Completion,  Up: Completion
1095
1096 Completion and the Minibuffer
1097 -----------------------------
1098
1099    This section describes the basic interface for reading from the
1100 minibuffer with completion.
1101
1102  - Function: completing-read prompt collection &optional predicate
1103           require-match initial hist default
1104      This function reads a string in the minibuffer, assisting the user
1105      by providing completion.  It activates the minibuffer with prompt
1106      PROMPT, which must be a string.  If INITIAL is non-`nil',
1107      `completing-read' inserts it into the minibuffer as part of the
1108      input.  Then it allows the user to edit the input, providing
1109      several commands to attempt completion.
1110
1111      The actual completion is done by passing COLLECTION and PREDICATE
1112      to the function `try-completion'.  This happens in certain
1113      commands bound in the local keymaps used for completion.
1114
1115      If REQUIRE-MATCH is `t', the usual minibuffer exit commands won't
1116      exit unless the input completes to an element of COLLECTION.  If
1117      REQUIRE-MATCH is neither `nil' nor `t', then the exit commands
1118      won't exit unless the input typed is itself an element of
1119      COLLECTION.  If REQUIRE-MATCH is `nil', the exit commands work
1120      regardless of the input in the minibuffer.
1121
1122      However, empty input is always permitted, regardless of the value
1123      of REQUIRE-MATCH; in that case, `completing-read' returns DEFAULT.
1124      The value of DEFAULT (if non-`nil') is also available to the user
1125      through the history commands.
1126
1127      The user can exit with null input by typing <RET> with an empty
1128      minibuffer.  Then `completing-read' returns `""'.  This is how the
1129      user requests whatever default the command uses for the value being
1130      read.  The user can return using <RET> in this way regardless of
1131      the value of REQUIRE-MATCH, and regardless of whether the empty
1132      string is included in COLLECTION.
1133
1134      The function `completing-read' works by calling `read-minibuffer'.
1135      It uses `minibuffer-local-completion-map' as the keymap if
1136      REQUIRE-MATCH is `nil', and uses `minibuffer-local-must-match-map'
1137      if REQUIRE-MATCH is non-`nil'.  *Note Completion Commands::.
1138
1139      The argument HIST specifies which history list variable to use for
1140      saving the input and for minibuffer history commands.  It defaults
1141      to `minibuffer-history'.  *Note Minibuffer History::.
1142
1143      Completion ignores case when comparing the input against the
1144      possible matches, if the built-in variable
1145      `completion-ignore-case' is non-`nil'.  *Note Basic Completion::.
1146
1147      Here's an example of using `completing-read':
1148
1149           (completing-read
1150            "Complete a foo: "
1151            '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
1152            nil t "fo")
1153           
1154           ;; After evaluation of the preceding expression,
1155           ;;   the following appears in the minibuffer:
1156           
1157           ---------- Buffer: Minibuffer ----------
1158           Complete a foo: fo-!-
1159           ---------- Buffer: Minibuffer ----------
1160
1161      If the user then types `<DEL> <DEL> b <RET>', `completing-read'
1162      returns `barfoo'.
1163
1164      The `completing-read' function binds three variables to pass
1165      information to the commands that actually do completion.  These
1166      variables are `minibuffer-completion-table',
1167      `minibuffer-completion-predicate' and
1168      `minibuffer-completion-confirm'.  For more information about them,
1169      see *Note Completion Commands::.
1170
1171 \1f
1172 File: lispref.info,  Node: Completion Commands,  Next: High-Level Completion,  Prev: Minibuffer Completion,  Up: Completion
1173
1174 Minibuffer Commands That Do Completion
1175 --------------------------------------
1176
1177    This section describes the keymaps, commands and user options used in
1178 the minibuffer to do completion.
1179
1180  - Variable: minibuffer-local-completion-map
1181      `completing-read' uses this value as the local keymap when an
1182      exact match of one of the completions is not required.  By
1183      default, this keymap makes the following bindings:
1184
1185     `?'
1186           `minibuffer-completion-help'
1187
1188     <SPC>
1189           `minibuffer-complete-word'
1190
1191     <TAB>
1192           `minibuffer-complete'
1193
1194      with other characters bound as in `minibuffer-local-map' (*note
1195      Text from Minibuffer::).
1196
1197  - Variable: minibuffer-local-must-match-map
1198      `completing-read' uses this value as the local keymap when an
1199      exact match of one of the completions is required.  Therefore, no
1200      keys are bound to `exit-minibuffer', the command that exits the
1201      minibuffer unconditionally.  By default, this keymap makes the
1202      following bindings:
1203
1204     `?'
1205           `minibuffer-completion-help'
1206
1207     <SPC>
1208           `minibuffer-complete-word'
1209
1210     <TAB>
1211           `minibuffer-complete'
1212
1213     `C-j'
1214           `minibuffer-complete-and-exit'
1215
1216     <RET>
1217           `minibuffer-complete-and-exit'
1218
1219      with other characters bound as in `minibuffer-local-map'.
1220
1221  - Variable: minibuffer-completion-table
1222      The value of this variable is the alist or obarray used for
1223      completion in the minibuffer.  This is the global variable that
1224      contains what `completing-read' passes to `try-completion'.  It is
1225      used by minibuffer completion commands such as
1226      `minibuffer-complete-word'.
1227
1228  - Variable: minibuffer-completion-predicate
1229      This variable's value is the predicate that `completing-read'
1230      passes to `try-completion'.  The variable is also used by the other
1231      minibuffer completion functions.
1232
1233  - Command: minibuffer-complete-word
1234      This function completes the minibuffer contents by at most a single
1235      word.  Even if the minibuffer contents have only one completion,
1236      `minibuffer-complete-word' does not add any characters beyond the
1237      first character that is not a word constituent.  *Note Syntax
1238      Tables::.
1239
1240  - Command: minibuffer-complete
1241      This function completes the minibuffer contents as far as possible.
1242
1243  - Command: minibuffer-complete-and-exit
1244      This function completes the minibuffer contents, and exits if
1245      confirmation is not required, i.e., if
1246      `minibuffer-completion-confirm' is `nil'.  If confirmation _is_
1247      required, it is given by repeating this command immediately--the
1248      command is programmed to work without confirmation when run twice
1249      in succession.
1250
1251  - Variable: minibuffer-completion-confirm
1252      When the value of this variable is non-`nil', XEmacs asks for
1253      confirmation of a completion before exiting the minibuffer.  The
1254      function `minibuffer-complete-and-exit' checks the value of this
1255      variable before it exits.
1256
1257  - Command: minibuffer-completion-help
1258      This function creates a list of the possible completions of the
1259      current minibuffer contents.  It works by calling `all-completions'
1260      using the value of the variable `minibuffer-completion-table' as
1261      the COLLECTION argument, and the value of
1262      `minibuffer-completion-predicate' as the PREDICATE argument.  The
1263      list of completions is displayed as text in a buffer named
1264      `*Completions*'.
1265
1266  - Function: display-completion-list completions
1267      This function displays COMPLETIONS to the stream in
1268      `standard-output', usually a buffer.  (*Note Read and Print::, for
1269      more information about streams.)  The argument COMPLETIONS is
1270      normally a list of completions just returned by `all-completions',
1271      but it does not have to be.  Each element may be a symbol or a
1272      string, either of which is simply printed, or a list of two
1273      strings, which is printed as if the strings were concatenated.
1274
1275      This function is called by `minibuffer-completion-help'.  The most
1276      common way to use it is together with
1277      `with-output-to-temp-buffer', like this:
1278
1279           (with-output-to-temp-buffer "*Completions*"
1280             (display-completion-list
1281               (all-completions (buffer-string) my-alist)))
1282
1283  - User Option: completion-auto-help
1284      If this variable is non-`nil', the completion commands
1285      automatically display a list of possible completions whenever
1286      nothing can be completed because the next character is not
1287      uniquely determined.
1288