annotate man/lispref/minibuf.texi @ 5908:6174848f3e6c

Use parse_integer() in read_atom(); support bases with ratios like integers src/ChangeLog addition: 2015-05-08 Aidan Kehoe <kehoea@parhasard.net> * data.c (init_errors_once_early): Move the Qunsupported_type here from numbers.c, so it's available when the majority of our types are not supported. * general-slots.h: Add it here, too. * number.c: Remove the definition of Qunsupported_type from here. * lread.c (read_atom): Check if the first character could reflect a rational, if so, call parse_integer(), don't check the syntax of the other characters. This allows us to accept the non-ASCII digit characters too. If that worked partially, but not completely, and the next char is a slash, try to parse as a ratio. If that fails, try isfloat_string(), but only if the first character could plausibly be part of a float. Otherwise, treat as a symbol. * lread.c (read_rational): Rename from read_integer. Handle ratios with the same radix specification as was used for integers. * lread.c (read1): Rename read_integer in this function. Support the Common Lisp #NNNrMMM syntax for parsing a number MMM of arbitrary radix NNN. man/ChangeLog addition: 2015-05-08 Aidan Kehoe <kehoea@parhasard.net> * lispref/numbers.texi (Numbers): Describe the newly-supported arbitrary-base syntax for rationals (integers and ratios). Describe that ratios can take the same base specification as integers, something also new. tests/ChangeLog addition: 2015-05-08 Aidan Kehoe <kehoea@parhasard.net> * automated/lisp-reader-tests.el: Check the arbitrary-base integer reader syntax support, just added. Check the reader base support for ratios, just added. Check the non-ASCII-digit support in the reader, just added.
author Aidan Kehoe <kehoea@parhasard.net>
date Sat, 09 May 2015 00:40:57 +0100
parents 9fae6227ede5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 @c -*-texinfo-*-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 @c This is part of the XEmacs Lisp Reference Manual.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1997 Free Software Foundation, Inc.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 @c See the file lispref.texi for copying conditions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 @setfilename ../../info/minibuf.info
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 @node Minibuffers, Command Loop, Read and Print, Top
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 @chapter Minibuffers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 @cindex arguments, reading
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 @cindex complex arguments
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 @cindex minibuffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 A @dfn{minibuffer} is a special buffer that XEmacs commands use to read
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 arguments more complicated than the single numeric prefix argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 These arguments include file names, buffer names, and command names (as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 in @kbd{M-x}). The minibuffer is displayed on the bottom line of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 frame, in the same place as the echo area, but only while it is in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 use for reading an argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 @menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 * Intro to Minibuffers:: Basic information about minibuffers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 * Text from Minibuffer:: How to read a straight text string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 * Object from Minibuffer:: How to read a Lisp object or expression.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 * Minibuffer History:: Recording previous minibuffer inputs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 so the user can reuse them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 * Completion:: How to invoke and customize completion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 * Yes-or-No Queries:: Asking a question with a simple answer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 * Multiple Queries:: Asking a series of similar questions.
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
28 * Reading a Password:: Reading a password from the terminal.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 * Minibuffer Misc:: Various customization hooks and variables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 @end menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 444
diff changeset
32 @node Intro to Minibuffers, Text from Minibuffer, Minibuffers, Minibuffers
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 @section Introduction to Minibuffers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 In most ways, a minibuffer is a normal XEmacs buffer. Most operations
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 @emph{within} a buffer, such as editing commands, work normally in a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 minibuffer. However, many operations for managing buffers do not apply
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 to minibuffers. The name of a minibuffer always has the form @w{@samp{
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 *Minibuf-@var{number}}}, and it cannot be changed. Minibuffers are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 displayed only in special windows used only for minibuffers; these
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
41 windows always appear at the bottom of a frame. (Sometimes frames have
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 no minibuffer window, and sometimes a special kind of frame contains
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 nothing but a minibuffer window; see @ref{Minibuffers and Frames}.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 The minibuffer's window is normally a single line. You can resize it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 temporarily with the window sizing commands; it reverts to its normal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 size when the minibuffer is exited. You can resize it permanently by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 using the window sizing commands in the frame's other window, when the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 minibuffer is not active. If the frame contains just a minibuffer, you
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 can change the minibuffer's size by changing the frame's size.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 If a command uses a minibuffer while there is an active minibuffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 this is called a @dfn{recursive minibuffer}. The first minibuffer is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 named @w{@samp{ *Minibuf-0*}}. Recursive minibuffers are named by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 incrementing the number at the end of the name. (The names begin with a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 space so that they won't show up in normal buffer lists.) Of several
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 recursive minibuffers, the innermost (or most recently entered) is the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 active minibuffer. We usually call this ``the'' minibuffer. You can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 permit or forbid recursive minibuffers by setting the variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 @code{enable-recursive-minibuffers}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 Like other buffers, a minibuffer may use any of several local keymaps
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 (@pxref{Keymaps}); these contain various exit commands and in some cases
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 completion commands (@pxref{Completion}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 @itemize @bullet
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 @code{minibuffer-local-map} is for ordinary input (no completion).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 @code{minibuffer-local-completion-map} is for permissive completion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 @code{minibuffer-local-must-match-map} is for strict completion and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 for cautious completion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 @end itemize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 444
diff changeset
78 @node Text from Minibuffer, Object from Minibuffer, Intro to Minibuffers, Minibuffers
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 @section Reading Text Strings with the Minibuffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 Most often, the minibuffer is used to read text as a string. It can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 also be used to read a Lisp object in textual form. The most basic
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 primitive for minibuffer input is @code{read-from-minibuffer}; it can do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 either one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 In most cases, you should not call minibuffer input functions in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 middle of a Lisp function. Instead, do all minibuffer input as part of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 reading the arguments for a command, in the @code{interactive} spec.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 @xref{Defining Commands}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
91 @defun read-from-minibuffer prompt-string &optional initial-contents keymap read hist abbrev-table default
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 This function is the most general way to get input through the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 minibuffer. By default, it accepts arbitrary text and returns it as a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 string; however, if @var{read} is non-@code{nil}, then it uses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 @code{read} to convert the text into a Lisp object (@pxref{Input
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 Functions}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
98 The first thing this function does is to activate a minibuffer and
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 display it with @var{prompt-string} as the prompt. This value must be a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 Then, if @var{initial-contents} is a string, @code{read-from-minibuffer}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 inserts it into the minibuffer, leaving point at the end. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 minibuffer appears with this text as its contents.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 @c Emacs 19 feature
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 The value of @var{initial-contents} may also be a cons cell of the form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 @code{(@var{string} . @var{position})}. This means to insert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 @var{string} in the minibuffer but put point @var{position} characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 from the beginning, rather than at the end.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
112 When the user types a command to exit the minibuffer,
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
113 @code{read-from-minibuffer} constructs the return value from the text in
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
114 the minibuffer. Normally it returns a string containing that text.
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
115 However, if @var{read} is non-@code{nil}, @code{read-from-minibuffer}
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
116 reads the text and returns the resulting Lisp object, unevaluated.
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
117 (@xref{Input Functions}, for information about reading.)
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
118
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
119 The argument @var{default} specifies a default value to make available
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
120 through the history commands. It should be a string, or @code{nil}.
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
121
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 If @var{keymap} is non-@code{nil}, that keymap is the local keymap to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 use in the minibuffer. If @var{keymap} is omitted or @code{nil}, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 value of @code{minibuffer-local-map} is used as the keymap. Specifying
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 a keymap is the most important way to customize the minibuffer for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 various applications such as completion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
128 The argument @var{abbrev-table} specifies @code{local-abbrev-table} in
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
129 the minibuffer (@pxref{Standard Abbrev Tables}).
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
130
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 The argument @var{hist} specifies which history list variable to use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 for saving the input and for history commands used in the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 It defaults to @code{minibuffer-history}. @xref{Minibuffer History}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 When the user types a command to exit the minibuffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 @code{read-from-minibuffer} uses the text in the minibuffer to produce
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 its return value. Normally it simply makes a string containing that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 text. However, if @var{read} is non-@code{nil},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 @code{read-from-minibuffer} reads the text and returns the resulting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 Lisp object, unevaluated. (@xref{Input Functions}, for information
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 about reading.)
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
142
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
143 @strong{Usage note:} The @var{initial-contents} argument and the
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
144 @var{default} argument are two alternative features for more or less the
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
145 same job. It does not make sense to use both features in a single call
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
146 to @code{read-from-minibuffer}. In general, we recommend using
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
147 @var{default}, since this permits the user to insert the default value
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
148 when it is wanted, but does not burden the user with deleting it from
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
149 the minibuffer on other occasions. However, if user is supposed to edit
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
150 default value, @var{initial-contents} may be preferred.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
153 @defun read-string prompt &optional initial history default-value
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 This function reads a string from the minibuffer and returns it. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 arguments @var{prompt} and @var{initial} are used as in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 @code{read-from-minibuffer}. The keymap used is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 @code{minibuffer-local-map}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
159 The optional argument @var{history}, if non-@code{nil}, specifies a history
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
160 list and optionally the initial position in the list. The optional
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
161 argument @var{default-value} specifies a default value to return if the user
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
162 enters null input; it should be a string.
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
163
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
164 This function is a simplified interface to the
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 @code{read-from-minibuffer} function:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 @group
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
169 (read-string @var{prompt} @var{initial} @var{history} @var{default})
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 @equiv{}
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
171 (read-from-minibuffer @var{prompt} @var{initial} nil nil
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
172 @var{history} nil @var{default})))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 @defvar minibuffer-local-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 This is the default local keymap for reading from the minibuffer. By
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 default, it makes the following bindings:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 @table @asis
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
182 @item @kbd{C-j}
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 @code{exit-minibuffer}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 @item @key{RET}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 @code{exit-minibuffer}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 @item @kbd{C-g}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 @code{abort-recursive-edit}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 @item @kbd{M-n}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 @code{next-history-element}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 @item @kbd{M-p}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 @code{previous-history-element}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 @item @kbd{M-r}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 @code{next-matching-history-element}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 @item @kbd{M-s}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 @code{previous-matching-history-element}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 444
diff changeset
205 @node Object from Minibuffer, Minibuffer History, Text from Minibuffer, Minibuffers
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 @section Reading Lisp Objects with the Minibuffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 This section describes functions for reading Lisp objects with the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
211 @defun read-expression prompt &optional initial history default-value
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
212 This function reads a Lisp object using the minibuffer, and returns it
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 without evaluating it. The arguments @var{prompt} and @var{initial} are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 used as in @code{read-from-minibuffer}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
216 The optional argument @var{history}, if non-@code{nil}, specifies a history
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
217 list and optionally the initial position in the list. The optional
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
218 argument @var{default-value} specifies a default value to return if the
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
219 user enters null input; it should be a string.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
220
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 This is a simplified interface to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 @code{read-from-minibuffer} function:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 @group
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
226 (read-expression @var{prompt} @var{initial} @var{history} @var{default-value})
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 @equiv{}
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
228 (read-from-minibuffer @var{prompt} @var{initial} nil t
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
229 @var{history} nil @var{default-value})
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 Here is an example in which we supply the string @code{"(testing)"} as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 initial input:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 @group
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
238 (read-expression
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 "Enter an expression: " (format "%s" '(testing)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 ;; @r{Here is how the minibuffer is displayed:}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 ---------- Buffer: Minibuffer ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 Enter an expression: (testing)@point{}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 ---------- Buffer: Minibuffer ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 The user can type @key{RET} immediately to use the initial input as a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 default, or can edit the input.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
256 @defun read-minibuffer prompt &optional initial history default-value
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
257
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
258 This is a FSF Emacs compatible function. Use @code{read-expression}
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
259 instead.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
260 @end defun
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
261
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
262 @defun eval-minibuffer prompt &optional initial history default-value
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
263 This function reads a Lisp expression using the minibuffer, evaluates
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
264 it, then returns the result. The arguments @var{prompt} and
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
265 @var{initial} are used as in @code{read-from-minibuffer}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
267 The optional argument @var{history}, if non-@code{nil}, specifies a history
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
268 list and optionally the initial position in the list. The optional
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
269 argument @var{default-value} specifies a default value to return if the
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
270 user enters null input; it should be a string.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
271
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 This function simply evaluates the result of a call to
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
273 @code{read-expression}:
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 (eval-minibuffer @var{prompt} @var{initial})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 @equiv{}
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
279 (eval (read-expression @var{prompt} @var{initial}))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
284 @defun edit-and-eval-command prompt form &optional history
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 This function reads a Lisp expression in the minibuffer, and then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 evaluates it. The difference between this command and
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
287 @code{eval-minibuffer} is that here the initial @var{form} is not
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 optional and it is treated as a Lisp object to be converted to printed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 representation rather than as a string of text. It is printed with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 @code{prin1}, so if it is a string, double-quote characters (@samp{"})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 appear in the initial text. @xref{Output Functions}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 The first thing @code{edit-and-eval-command} does is to activate the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 minibuffer with @var{prompt} as the prompt. Then it inserts the printed
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
295 representation of @var{form} in the minibuffer, and lets the user edit it.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 When the user exits the minibuffer, the edited text is read with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 @code{read} and then evaluated. The resulting value becomes the value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 of @code{edit-and-eval-command}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 In the following example, we offer the user an expression with initial
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 text which is a valid form already:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 (edit-and-eval-command "Please edit: " '(forward-word 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
307 ;; @r{After evaluation of the preceding expression,}
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 ;; @r{the following appears in the minibuffer:}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 ---------- Buffer: Minibuffer ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 Please edit: (forward-word 1)@point{}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 ---------- Buffer: Minibuffer ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 Typing @key{RET} right away would exit the minibuffer and evaluate the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 expression, thus moving point forward one word.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 @code{edit-and-eval-command} returns @code{t} in this example.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 444
diff changeset
324 @node Minibuffer History, Completion, Object from Minibuffer, Minibuffers
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 @section Minibuffer History
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 @cindex minibuffer history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 @cindex history list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 A @dfn{minibuffer history list} records previous minibuffer inputs so
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 the user can reuse them conveniently. A history list is actually a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 symbol, not a list; it is a variable whose value is a list of strings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 (previous inputs), most recent first.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 There are many separate history lists, used for different kinds of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 inputs. It's the Lisp programmer's job to specify the right history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 list for each use of the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 The basic minibuffer input functions @code{read-from-minibuffer} and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 @code{completing-read} both accept an optional argument named @var{hist}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 which is how you specify the history list. Here are the possible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 values:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 @table @asis
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 @item @var{variable}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 Use @var{variable} (a symbol) as the history list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 @item (@var{variable} . @var{startpos})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 Use @var{variable} (a symbol) as the history list, and assume that the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 initial history position is @var{startpos} (an integer, counting from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 zero which specifies the most recent element of the history).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 If you specify @var{startpos}, then you should also specify that element
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 of the history as the initial minibuffer contents, for consistency.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 If you don't specify @var{hist}, then the default history list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 @code{minibuffer-history} is used. For other standard history lists,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 see below. You can also create your own history list variable; just
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 initialize it to @code{nil} before the first use.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 Both @code{read-from-minibuffer} and @code{completing-read} add new
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 elements to the history list automatically, and provide commands to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 allow the user to reuse items on the list. The only thing your program
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 needs to do to use a history list is to initialize it and to pass its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 name to the input functions when you wish. But it is safe to modify the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 list by hand when the minibuffer input functions are not using it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
368 Here are some of the standard minibuffer history list variables:
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
369
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 @defvar minibuffer-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 The default history list for minibuffer history input.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 @defvar query-replace-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 A history list for arguments to @code{query-replace} (and similar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 arguments to other commands).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 @defvar file-name-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 A history list for file name arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 @defvar regexp-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 A history list for regular expression arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 @defvar extended-command-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 A history list for arguments that are names of extended commands.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 @defvar shell-command-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 A history list for arguments that are shell commands.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 @defvar read-expression-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 A history list for arguments that are Lisp expressions to evaluate.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 @defvar Info-minibuffer-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 A history list for Info mode's minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 @defvar Manual-page-minibuffer-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 A history list for @code{manual-entry}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 There are many other minibuffer history lists, defined by various
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 libraries. An @kbd{M-x apropos} search for @samp{history} should prove
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 fruitful in discovering them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 444
diff changeset
411 @node Completion, Yes-or-No Queries, Minibuffer History, Minibuffers
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 @section Completion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 @cindex completion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 @dfn{Completion} is a feature that fills in the rest of a name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 starting from an abbreviation for it. Completion works by comparing the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 user's input against a list of valid names and determining how much of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 the name is determined uniquely by what the user has typed. For
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 example, when you type @kbd{C-x b} (@code{switch-to-buffer}) and then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 type the first few letters of the name of the buffer to which you wish
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 to switch, and then type @key{TAB} (@code{minibuffer-complete}), Emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 extends the name as far as it can.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 Standard XEmacs commands offer completion for names of symbols, files,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 buffers, and processes; with the functions in this section, you can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 implement completion for other kinds of names.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 The @code{try-completion} function is the basic primitive for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 completion: it returns the longest determined completion of a given
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 initial string, with a given set of strings to match against.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 The function @code{completing-read} provides a higher-level interface
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 for completion. A call to @code{completing-read} specifies how to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 determine the list of valid names. The function then activates the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 minibuffer with a local keymap that binds a few keys to commands useful
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 for completion. Other functions provide convenient simple interfaces
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 for reading certain kinds of names with completion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 @menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 * Basic Completion:: Low-level functions for completing strings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 (These are too low level to use the minibuffer.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 * Minibuffer Completion:: Invoking the minibuffer with completion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 * Completion Commands:: Minibuffer commands that do completion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 * High-Level Completion:: Convenient special cases of completion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 (reading buffer name, file name, etc.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 * Reading File Names:: Using completion to read file names.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 * Programmed Completion:: Finding the completions for a given file name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 @end menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 444
diff changeset
450 @node Basic Completion, Minibuffer Completion, Completion, Completion
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 @subsection Basic Completion Functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 The two functions @code{try-completion} and @code{all-completions}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 have nothing in themselves to do with minibuffers. We describe them in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 this chapter so as to keep them near the higher-level completion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 features that do use the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 @defun try-completion string collection &optional predicate
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
459 This function returns the longest common prefix of all possible
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 completions of @var{string} in @var{collection}. The value of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 @var{collection} must be an alist, an obarray, or a function that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 implements a virtual set of strings (see below).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 Completion compares @var{string} against each of the permissible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 completions specified by @var{collection}; if the beginning of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 permissible completion equals @var{string}, it matches. If no permissible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 completions match, @code{try-completion} returns @code{nil}. If only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 one permissible completion matches, and the match is exact, then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 @code{try-completion} returns @code{t}. Otherwise, the value is the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 longest initial sequence common to all the permissible completions that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 match.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 If @var{collection} is an alist (@pxref{Association Lists}), the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 @sc{car}s of the alist elements form the set of permissible completions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 @cindex obarray in completion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 If @var{collection} is an obarray (@pxref{Creating Symbols}), the names
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 of all symbols in the obarray form the set of permissible completions. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 global variable @code{obarray} holds an obarray containing the names of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 all interned Lisp symbols.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 Note that the only valid way to make a new obarray is to create it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 empty and then add symbols to it one by one using @code{intern}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 Also, you cannot intern a given symbol in more than one obarray.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 If the argument @var{predicate} is non-@code{nil}, then it must be a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 function of one argument. It is used to test each possible match, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 the match is accepted only if @var{predicate} returns non-@code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 The argument given to @var{predicate} is either a cons cell from the alist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 (the @sc{car} of which is a string) or else it is a symbol (@emph{not} a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 symbol name) from the obarray.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 You can also use a symbol that is a function as @var{collection}. Then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 the function is solely responsible for performing completion;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 @code{try-completion} returns whatever this function returns. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 function is called with three arguments: @var{string}, @var{predicate}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 and @code{nil}. (The reason for the third argument is so that the same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 function can be used in @code{all-completions} and do the appropriate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 thing in either case.) @xref{Programmed Completion}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 In the first of the following examples, the string @samp{foo} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 matched by three of the alist @sc{car}s. All of the matches begin with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 the characters @samp{fooba}, so that is the result. In the second
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 example, there is only one possible match, and it is exact, so the value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 is @code{t}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 @group
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
509 (try-completion
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 "foo"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 @result{} "fooba"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 (try-completion "foo" '(("barfoo" 2) ("foo" 3)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 @result{} t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 In the following example, numerous symbols begin with the characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 @samp{forw}, and all of them begin with the word @samp{forward}. In
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 most of the symbols, this is followed with a @samp{-}, but not in all,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 so no more than @samp{forward} can be completed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 (try-completion "forw" obarray)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 @result{} "forward"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 Finally, in the following example, only two of the three possible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 matches pass the predicate @code{test} (the string @samp{foobaz} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 too short). Both of those begin with the string @samp{foobar}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 @group
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
539 (defun test (s)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 (> (length (car s)) 6))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 @result{} test
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 @group
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
544 (try-completion
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 "foo"
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
546 '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 'test)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 @result{} "foobar"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
553 @defun all-completions string collection &optional predicate
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
554 This function returns a list of all possible completions of @var{string}.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
555 The arguments to this function are the same as those of @code{try-completion}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 If @var{collection} is a function, it is called with three arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 @var{string}, @var{predicate} and @code{t}; then @code{all-completions}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 returns whatever the function returns. @xref{Programmed Completion}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 Here is an example, using the function @code{test} shown in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 example for @code{try-completion}:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 @group
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
566 (defun test (s)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 (> (length (car s)) 6))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 @result{} test
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 @group
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
572 (all-completions
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 "foo"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 'test)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 @result{} ("foobar1" "foobar2")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 @defvar completion-ignore-case
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
582 If the value of this variable is
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 non-@code{nil}, XEmacs does not consider case significant in completion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 444
diff changeset
586 @node Minibuffer Completion, Completion Commands, Basic Completion, Completion
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 @subsection Completion and the Minibuffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 This section describes the basic interface for reading from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 minibuffer with completion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
592 @defun completing-read prompt collection &optional predicate require-match initial hist default
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 This function reads a string in the minibuffer, assisting the user by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 providing completion. It activates the minibuffer with prompt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 @var{prompt}, which must be a string. If @var{initial} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 non-@code{nil}, @code{completing-read} inserts it into the minibuffer as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 part of the input. Then it allows the user to edit the input, providing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 several commands to attempt completion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 The actual completion is done by passing @var{collection} and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 @var{predicate} to the function @code{try-completion}. This happens in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 certain commands bound in the local keymaps used for completion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 If @var{require-match} is @code{t}, the usual minibuffer exit commands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 won't exit unless the input completes to an element of @var{collection}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 If @var{require-match} is neither @code{nil} nor @code{t}, then the exit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 commands won't exit unless the input typed is itself an element of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 @var{collection}. If @var{require-match} is @code{nil}, the exit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 commands work regardless of the input in the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
611 However, empty input is always permitted, regardless of the value of
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
612 @var{require-match}; in that case, @code{completing-read} returns
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
613 @var{default}. The value of @var{default} (if non-@code{nil}) is also
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
614 available to the user through the history commands.
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
615
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 The user can exit with null input by typing @key{RET} with an empty
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
617 minibuffer. Then @code{completing-read} returns @code{""}. This is how
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
618 the user requests whatever default the command uses for the value being
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
619 read. The user can return using @key{RET} in this way regardless of the
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
620 value of @var{require-match}, and regardless of whether the empty string
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
621 is included in @var{collection}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 The function @code{completing-read} works by calling
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
624 @code{read-expression}. It uses @code{minibuffer-local-completion-map}
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 as the keymap if @var{require-match} is @code{nil}, and uses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 @code{minibuffer-local-must-match-map} if @var{require-match} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 non-@code{nil}. @xref{Completion Commands}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 The argument @var{hist} specifies which history list variable to use for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 saving the input and for minibuffer history commands. It defaults to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 @code{minibuffer-history}. @xref{Minibuffer History}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 Completion ignores case when comparing the input against the possible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 matches, if the built-in variable @code{completion-ignore-case} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 non-@code{nil}. @xref{Basic Completion}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 Here's an example of using @code{completing-read}:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 (completing-read
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 "Complete a foo: "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 nil t "fo")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 @group
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
648 ;; @r{After evaluation of the preceding expression,}
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 ;; @r{the following appears in the minibuffer:}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 ---------- Buffer: Minibuffer ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 Complete a foo: fo@point{}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 ---------- Buffer: Minibuffer ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 If the user then types @kbd{@key{DEL} @key{DEL} b @key{RET}},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 @code{completing-read} returns @code{barfoo}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 The @code{completing-read} function binds three variables to pass
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 information to the commands that actually do completion. These
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 variables are @code{minibuffer-completion-table},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 @code{minibuffer-completion-predicate} and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 @code{minibuffer-completion-confirm}. For more information about them,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 see @ref{Completion Commands}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 444
diff changeset
669 @node Completion Commands, High-Level Completion, Minibuffer Completion, Completion
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 @subsection Minibuffer Commands That Do Completion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 This section describes the keymaps, commands and user options used in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 the minibuffer to do completion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 @defvar minibuffer-local-completion-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 @code{completing-read} uses this value as the local keymap when an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 exact match of one of the completions is not required. By default, this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 keymap makes the following bindings:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 @table @asis
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 @item @kbd{?}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 @code{minibuffer-completion-help}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 @item @key{SPC}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 @code{minibuffer-complete-word}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 @item @key{TAB}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 @code{minibuffer-complete}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 with other characters bound as in @code{minibuffer-local-map}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 (@pxref{Text from Minibuffer}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 @defvar minibuffer-local-must-match-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 @code{completing-read} uses this value as the local keymap when an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 exact match of one of the completions is required. Therefore, no keys
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 are bound to @code{exit-minibuffer}, the command that exits the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 minibuffer unconditionally. By default, this keymap makes the following
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 bindings:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 @table @asis
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 @item @kbd{?}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 @code{minibuffer-completion-help}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 @item @key{SPC}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 @code{minibuffer-complete-word}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 @item @key{TAB}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 @code{minibuffer-complete}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
713 @item @kbd{C-j}
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 @code{minibuffer-complete-and-exit}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 @item @key{RET}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 @code{minibuffer-complete-and-exit}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 with other characters bound as in @code{minibuffer-local-map}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 @defvar minibuffer-completion-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 The value of this variable is the alist or obarray used for completion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 in the minibuffer. This is the global variable that contains what
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 @code{completing-read} passes to @code{try-completion}. It is used by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 minibuffer completion commands such as @code{minibuffer-complete-word}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 @defvar minibuffer-completion-predicate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 This variable's value is the predicate that @code{completing-read}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 passes to @code{try-completion}. The variable is also used by the other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 minibuffer completion functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 @deffn Command minibuffer-complete-word
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 This function completes the minibuffer contents by at most a single
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 word. Even if the minibuffer contents have only one completion,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 @code{minibuffer-complete-word} does not add any characters beyond the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 first character that is not a word constituent. @xref{Syntax Tables}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 @deffn Command minibuffer-complete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 This function completes the minibuffer contents as far as possible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 @deffn Command minibuffer-complete-and-exit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 This function completes the minibuffer contents, and exits if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 confirmation is not required, i.e., if
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
751 @code{minibuffer-completion-confirm} is @code{nil}. If confirmation
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 @emph{is} required, it is given by repeating this command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 immediately---the command is programmed to work without confirmation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 when run twice in succession.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 @defvar minibuffer-completion-confirm
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 When the value of this variable is non-@code{nil}, XEmacs asks for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 confirmation of a completion before exiting the minibuffer. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 function @code{minibuffer-complete-and-exit} checks the value of this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 variable before it exits.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 @deffn Command minibuffer-completion-help
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 This function creates a list of the possible completions of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 current minibuffer contents. It works by calling @code{all-completions}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 using the value of the variable @code{minibuffer-completion-table} as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 the @var{collection} argument, and the value of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 @code{minibuffer-completion-predicate} as the @var{predicate} argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 The list of completions is displayed as text in a buffer named
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 @samp{*Completions*}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
774 @defun display-completion-list completions &rest cl-keys
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 This function displays @var{completions} to the stream in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 @code{standard-output}, usually a buffer. (@xref{Read and Print}, for more
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 information about streams.) The argument @var{completions} is normally
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 a list of completions just returned by @code{all-completions}, but it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 does not have to be. Each element may be a symbol or a string, either
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 of which is simply printed, or a list of two strings, which is printed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 as if the strings were concatenated.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 This function is called by @code{minibuffer-completion-help}. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 most common way to use it is together with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 @code{with-output-to-temp-buffer}, like this:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 (with-output-to-temp-buffer "*Completions*"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 (display-completion-list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 (all-completions (buffer-string) my-alist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 @defopt completion-auto-help
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 If this variable is non-@code{nil}, the completion commands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 automatically display a list of possible completions whenever nothing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 can be completed because the next character is not uniquely determined.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 @end defopt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 444
diff changeset
800 @node High-Level Completion, Reading File Names, Completion Commands, Completion
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 @subsection High-Level Completion Functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 This section describes the higher-level convenient functions for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 reading certain sorts of names with completion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 In most cases, you should not call these functions in the middle of a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 Lisp function. When possible, do all minibuffer input as part of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 reading the arguments for a command, in the @code{interactive} spec.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 @xref{Defining Commands}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 @defun read-buffer prompt &optional default existing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 This function reads the name of a buffer and returns it as a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 The argument @var{default} is the default name to use, the value to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 return if the user exits with an empty minibuffer. If non-@code{nil},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 it should be a string or a buffer. It is mentioned in the prompt, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 is not inserted in the minibuffer as initial input.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 If @var{existing} is non-@code{nil}, then the name specified must be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 that of an existing buffer. The usual commands to exit the minibuffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 do not exit if the text is not valid, and @key{RET} does completion to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 attempt to find a valid name. (However, @var{default} is not checked
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 for validity; it is returned, whatever it is, if the user exits with the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 minibuffer empty.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 In the following example, the user enters @samp{minibuffer.t}, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 then types @key{RET}. The argument @var{existing} is @code{t}, and the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 only buffer name starting with the given input is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 @samp{minibuffer.texi}, so that name is the value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 (read-buffer "Buffer name? " "foo" t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 @group
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
833 ;; @r{After evaluation of the preceding expression,}
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 ;; @r{the following prompt appears,}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 ;; @r{with an empty minibuffer:}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 ---------- Buffer: Minibuffer ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 Buffer name? (default foo) @point{}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 ---------- Buffer: Minibuffer ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 ;; @r{The user types @kbd{minibuffer.t @key{RET}}.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 @result{} "minibuffer.texi"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
851 @defun read-command prompt &optional default-value
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 This function reads the name of a command and returns it as a Lisp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 symbol. The argument @var{prompt} is used as in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 @code{read-from-minibuffer}. Recall that a command is anything for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 which @code{commandp} returns @code{t}, and a command name is a symbol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 for which @code{commandp} returns @code{t}. @xref{Interactive Call}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
858 The argument @var{default-value} specifies what to return if the user
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
859 enters null input. It can be a symbol or a string; if it is a string,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
860 @code{read-command} interns it before returning it. If @var{default} is
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
861 @code{nil}, that means no default has been specified; then if the user
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
862 enters null input, the return value is @code{nil}.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
863
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 (read-command "Command name? ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 @group
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
868 ;; @r{After evaluation of the preceding expression,}
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 ;; @r{the following prompt appears with an empty minibuffer:}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 @group
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
873 ---------- Buffer: Minibuffer ----------
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
874 Command name?
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 ---------- Buffer: Minibuffer ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 If the user types @kbd{forward-c @key{RET}}, then this function returns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 @code{forward-char}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 The @code{read-command} function is a simplified interface to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 function @code{completing-read}. It uses the variable @code{obarray} so
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 as to complete in the set of extant Lisp symbols, and it uses the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 @code{commandp} predicate so as to accept only command names:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 @cindex @code{commandp} example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 (read-command @var{prompt})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 @equiv{}
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
893 (intern (completing-read @var{prompt} obarray
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 'commandp t nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
899 @defun read-variable prompt &optional default-value
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 This function reads the name of a user variable and returns it as a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 symbol.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
903 The argument @var{default-value} specifies what to return if the user
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
904 enters null input. It can be a symbol or a string; if it is a string,
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
905 @code{read-variable} interns it before returning it. If @var{default-value}
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
906 is @code{nil}, that means no default has been specified; then if the
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
907 user enters null input, the return value is @code{nil}.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
908
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 (read-variable "Variable name? ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
913 ;; @r{After evaluation of the preceding expression,}
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
914 ;; @r{the following prompt appears,}
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 ;; @r{with an empty minibuffer:}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 ---------- Buffer: Minibuffer ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 Variable name? @point{}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 ---------- Buffer: Minibuffer ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 If the user then types @kbd{fill-p @key{RET}}, @code{read-variable}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 returns @code{fill-prefix}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 This function is similar to @code{read-command}, but uses the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 predicate @code{user-variable-p} instead of @code{commandp}:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 @cindex @code{user-variable-p} example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 (read-variable @var{prompt})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 @equiv{}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 (intern
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 (completing-read @var{prompt} obarray
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 'user-variable-p t nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 444
diff changeset
944 @node Reading File Names, Programmed Completion, High-Level Completion, Completion
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 @subsection Reading File Names
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 Here is another high-level completion function, designed for reading a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 file name. It provides special features including automatic insertion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 of the default directory.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
951 @defun read-file-name prompt &optional directory default existing initial history
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 This function reads a file name in the minibuffer, prompting with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 @var{prompt} and providing completion. If @var{default} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 non-@code{nil}, then the function returns @var{default} if the user just
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 types @key{RET}. @var{default} is not checked for validity; it is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 returned, whatever it is, if the user exits with the minibuffer empty.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 If @var{existing} is non-@code{nil}, then the user must specify the name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 of an existing file; @key{RET} performs completion to make the name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 valid if possible, and then refuses to exit if it is not valid. If the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 value of @var{existing} is neither @code{nil} nor @code{t}, then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 @key{RET} also requires confirmation after completion. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 @var{existing} is @code{nil}, then the name of a nonexistent file is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 acceptable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 The argument @var{directory} specifies the directory to use for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 completion of relative file names. If @code{insert-default-directory}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 is non-@code{nil}, @var{directory} is also inserted in the minibuffer as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 initial input. It defaults to the current buffer's value of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 @code{default-directory}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 @c Emacs 19 feature
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 If you specify @var{initial}, that is an initial file name to insert in
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
974 the buffer (after @var{directory}, if that is inserted). In this
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 case, point goes at the beginning of @var{initial}. The default for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 @var{initial} is @code{nil}---don't insert any file name. To see what
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 @var{initial} does, try the command @kbd{C-x C-v}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
979 Here is an example:
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 (read-file-name "The file is ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
985 ;; @r{After evaluation of the preceding expression,}
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 ;; @r{the following appears in the minibuffer:}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 ---------- Buffer: Minibuffer ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 The file is /gp/gnu/elisp/@point{}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 ---------- Buffer: Minibuffer ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 Typing @kbd{manual @key{TAB}} results in the following:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 ---------- Buffer: Minibuffer ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 The file is /gp/gnu/elisp/manual.texi@point{}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 ---------- Buffer: Minibuffer ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 @c Wordy to avoid overfull hbox in smallbook mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 If the user types @key{RET}, @code{read-file-name} returns the file name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 as the string @code{"/gp/gnu/elisp/manual.texi"}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 @defopt insert-default-directory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 This variable is used by @code{read-file-name}. Its value controls
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 whether @code{read-file-name} starts by placing the name of the default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 directory in the minibuffer, plus the initial file name if any. If the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 value of this variable is @code{nil}, then @code{read-file-name} does
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 not place any initial input in the minibuffer (unless you specify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 initial input with the @var{initial} argument). In that case, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 default directory is still used for completion of relative file names,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 but is not displayed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 For example:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 ;; @r{Here the minibuffer starts out with the default directory.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 (let ((insert-default-directory t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 (read-file-name "The file is "))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 ---------- Buffer: Minibuffer ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 The file is ~lewis/manual/@point{}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 ---------- Buffer: Minibuffer ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 ;; @r{Here the minibuffer is empty and only the prompt}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 ;; @r{appears on its line.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 (let ((insert-default-directory nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 (read-file-name "The file is "))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 ---------- Buffer: Minibuffer ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 The file is @point{}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 ---------- Buffer: Minibuffer ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 @end defopt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 444
diff changeset
1053 @node Programmed Completion, , Reading File Names, Completion
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 @subsection Programmed Completion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 @cindex programmed completion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 Sometimes it is not possible to create an alist or an obarray
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 containing all the intended possible completions. In such a case, you
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 can supply your own function to compute the completion of a given string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060 This is called @dfn{programmed completion}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 To use this feature, pass a symbol with a function definition as the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 @var{collection} argument to @code{completing-read}. The function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064 @code{completing-read} arranges to pass your completion function along
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 to @code{try-completion} and @code{all-completions}, which will then let
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 your function do all the work.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068 The completion function should accept three arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 @itemize @bullet
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 The string to be completed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 The predicate function to filter possible matches, or @code{nil} if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076 none. Your function should call the predicate for each possible match,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077 and ignore the possible match if the predicate returns @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 A flag specifying the type of operation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081 @end itemize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 There are three flag values for three operations:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 @itemize @bullet
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 @code{nil} specifies @code{try-completion}. The completion function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 should return the completion of the specified string, or @code{t} if the
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1089 string is a unique and exact match already, or @code{nil} if the string
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1090 matches no possibility.
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1091
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1092 If the string is an exact match for one possibility, but also matches
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1093 other longer possibilities, the function should return the string, not
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1094 @code{t}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 @code{t} specifies @code{all-completions}. The completion function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 should return a list of all possible completions of the specified
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 @code{lambda} specifies a test for an exact match. The completion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 function should return @code{t} if the specified string is an exact
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104 match for some possibility; @code{nil} otherwise.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 @end itemize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107 It would be consistent and clean for completion functions to allow
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108 lambda expressions (lists that are functions) as well as function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 symbols as @var{collection}, but this is impossible. Lists as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 completion tables are already assigned another meaning---as alists. It
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111 would be unreliable to fail to handle an alist normally because it is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 also a possible function. So you must arrange for any function you wish
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113 to use for completion to be encapsulated in a symbol.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 Emacs uses programmed completion when completing file names.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 @xref{File Name Completion}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 444
diff changeset
1118 @node Yes-or-No Queries, Multiple Queries, Completion, Minibuffers
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 @section Yes-or-No Queries
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 @cindex asking the user questions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 @cindex querying the user
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 @cindex yes-or-no questions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124 This section describes functions used to ask the user a yes-or-no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125 question. The function @code{y-or-n-p} can be answered with a single
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126 character; it is useful for questions where an inadvertent wrong answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127 will not have serious consequences. @code{yes-or-no-p} is suitable for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128 more momentous questions, since it requires three or four characters to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129 answer. Variations of these functions can be used to ask a yes-or-no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130 question using a dialog box, or optionally using one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132 If either of these functions is called in a command that was invoked
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133 using the mouse, then it uses a dialog box or pop-up menu to ask the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 question. Otherwise, it uses keyboard input.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 Strictly speaking, @code{yes-or-no-p} uses the minibuffer and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137 @code{y-or-n-p} does not; but it seems best to describe them together.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139 @defun y-or-n-p prompt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 This function asks the user a question, expecting input in the echo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141 area. It returns @code{t} if the user types @kbd{y}, @code{nil} if the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 user types @kbd{n}. This function also accepts @key{SPC} to mean yes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143 and @key{DEL} to mean no. It accepts @kbd{C-]} to mean ``quit'', like
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 @kbd{C-g}, because the question might look like a minibuffer and for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 that reason the user might try to use @kbd{C-]} to get out. The answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146 is a single character, with no @key{RET} needed to terminate it. Upper
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147 and lower case are equivalent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149 ``Asking the question'' means printing @var{prompt} in the echo area,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 followed by the string @w{@samp{(y or n) }}. If the input is not one of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151 the expected answers (@kbd{y}, @kbd{n}, @kbd{@key{SPC}},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 @kbd{@key{DEL}}, or something that quits), the function responds
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 @samp{Please answer y or n.}, and repeats the request.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 This function does not actually use the minibuffer, since it does not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 allow editing of the answer. It actually uses the echo area (@pxref{The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 Echo Area}), which uses the same screen space as the minibuffer. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158 cursor moves to the echo area while the question is being asked.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 The answers and their meanings, even @samp{y} and @samp{n}, are not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 hardwired. The keymap @code{query-replace-map} specifies them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 @xref{Search and Replace}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164 In the following example, the user first types @kbd{q}, which is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 invalid. At the next prompt the user types @kbd{y}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 (y-or-n-p "Do you need a lift? ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1171 ;; @r{After evaluation of the preceding expression,}
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 ;; @r{the following prompt appears in the echo area:}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 ---------- Echo area ----------
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1177 Do you need a lift? (y or n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 ---------- Echo area ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181 ;; @r{If the user then types @kbd{q}, the following appears:}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184 ---------- Echo area ----------
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1185 Please answer y or n. Do you need a lift? (y or n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 ---------- Echo area ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189 ;; @r{When the user types a valid answer,}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 ;; @r{it is displayed after the question:}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 ---------- Echo area ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194 Do you need a lift? (y or n) y
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195 ---------- Echo area ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 We show successive lines of echo area messages, but only one actually
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201 appears on the screen at a time.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204 @defun yes-or-no-p prompt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205 This function asks the user a question, expecting input in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 minibuffer. It returns @code{t} if the user enters @samp{yes},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207 @code{nil} if the user types @samp{no}. The user must type @key{RET} to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208 finalize the response. Upper and lower case are equivalent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210 @code{yes-or-no-p} starts by displaying @var{prompt} in the echo area,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 followed by @w{@samp{(yes or no) }}. The user must type one of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 expected responses; otherwise, the function responds @samp{Please answer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213 yes or no.}, waits about two seconds and repeats the request.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 @code{yes-or-no-p} requires more work from the user than
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216 @code{y-or-n-p} and is appropriate for more crucial decisions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218 Here is an example:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222 (yes-or-no-p "Do you really want to remove everything? ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1224 ;; @r{After evaluation of the preceding expression,}
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1225 ;; @r{the following prompt appears,}
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226 ;; @r{with an empty minibuffer:}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230 ---------- Buffer: minibuffer ----------
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1231 Do you really want to remove everything? (yes or no)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1232 ---------- Buffer: minibuffer ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1235
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1237 If the user first types @kbd{y @key{RET}}, which is invalid because this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238 function demands the entire word @samp{yes}, it responds by displaying
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 these prompts, with a brief pause between them:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243 ---------- Buffer: minibuffer ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244 Please answer yes or no.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 Do you really want to remove everything? (yes or no)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246 ---------- Buffer: minibuffer ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251 @c The rest is XEmacs stuff
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 @defun yes-or-no-p-dialog-box prompt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 This function asks the user a ``y or n'' question with a popup dialog
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 box. It returns @code{t} if the answer is ``yes''. @var{prompt} is the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255 string to display to ask the question.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258 The following functions ask a question either in the minibuffer or a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259 dialog box, depending on whether the last user event (which presumably
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260 invoked this command) was a keyboard or mouse event. When XEmacs is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261 running on a window system, the functions @code{y-or-n-p} and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1262 @code{yes-or-no-p} are replaced with the following functions, so that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263 menu items bring up dialog boxes instead of minibuffer questions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1264
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265 @defun y-or-n-p-maybe-dialog-box prompt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266 This function asks user a ``y or n'' question, using either a dialog box
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267 or the minibuffer, as appropriate.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1268 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270 @defun yes-or-no-p-maybe-dialog-box prompt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271 This function asks user a ``yes or no'' question, using either a dialog
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272 box or the minibuffer, as appropriate.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 444
diff changeset
1275 @node Multiple Queries, Reading a Password, Yes-or-No Queries, Minibuffers
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276 @section Asking Multiple Y-or-N Questions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278 When you have a series of similar questions to ask, such as ``Do you
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279 want to save this buffer'' for each buffer in turn, you should use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280 @code{map-y-or-n-p} to ask the collection of questions, rather than
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281 asking each question individually. This gives the user certain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282 convenient facilities such as the ability to answer the whole series at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283 once.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285 @defun map-y-or-n-p prompter actor list &optional help action-alist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1286 This function, new in Emacs 19, asks the user a series of questions,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1287 reading a single-character answer in the echo area for each one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1288
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289 The value of @var{list} specifies the objects to ask questions about.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1290 It should be either a list of objects or a generator function. If it is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291 a function, it should expect no arguments, and should return either the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1292 next object to ask about, or @code{nil} meaning stop asking questions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1293
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1294 The argument @var{prompter} specifies how to ask each question. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1295 @var{prompter} is a string, the question text is computed like this:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1296
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1297 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1298 (format @var{prompter} @var{object})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1299 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1300
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1301 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1302 where @var{object} is the next object to ask about (as obtained from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1303 @var{list}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1305 If not a string, @var{prompter} should be a function of one argument
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1306 (the next object to ask about) and should return the question text. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1307 the value is a string, that is the question to ask the user. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1308 function can also return @code{t} meaning do act on this object (and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1309 don't ask the user), or @code{nil} meaning ignore this object (and don't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310 ask the user).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312 The argument @var{actor} says how to act on the answers that the user
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1313 gives. It should be a function of one argument, and it is called with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1314 each object that the user says yes for. Its argument is always an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 object obtained from @var{list}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317 If the argument @var{help} is given, it should be a list of this form:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1319 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1320 (@var{singular} @var{plural} @var{action})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1321 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1324 where @var{singular} is a string containing a singular noun that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1325 describes the objects conceptually being acted on, @var{plural} is the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326 corresponding plural noun, and @var{action} is a transitive verb
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327 describing what @var{actor} does.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1328
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1329 If you don't specify @var{help}, the default is @code{("object"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1330 "objects" "act on")}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1331
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1332 Each time a question is asked, the user may enter @kbd{y}, @kbd{Y}, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1333 @key{SPC} to act on that object; @kbd{n}, @kbd{N}, or @key{DEL} to skip
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1334 that object; @kbd{!} to act on all following objects; @key{ESC} or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1335 @kbd{q} to exit (skip all following objects); @kbd{.} (period) to act on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336 the current object and then exit; or @kbd{C-h} to get help. These are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337 the same answers that @code{query-replace} accepts. The keymap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338 @code{query-replace-map} defines their meaning for @code{map-y-or-n-p}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339 as well as for @code{query-replace}; see @ref{Search and Replace}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1340
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1341 You can use @var{action-alist} to specify additional possible answers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1342 and what they mean. It is an alist of elements of the form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1343 @code{(@var{char} @var{function} @var{help})}, each of which defines one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344 additional answer. In this element, @var{char} is a character (the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1345 answer); @var{function} is a function of one argument (an object from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346 @var{list}); @var{help} is a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348 When the user responds with @var{char}, @code{map-y-or-n-p} calls
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349 @var{function}. If it returns non-@code{nil}, the object is considered
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350 ``acted upon'', and @code{map-y-or-n-p} advances to the next object in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1351 @var{list}. If it returns @code{nil}, the prompt is repeated for the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352 same object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354 If @code{map-y-or-n-p} is called in a command that was invoked using the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1355 mouse---more precisely, if @code{last-nonmenu-event} (@pxref{Command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356 Loop Info}) is either @code{nil} or a list---then it uses a dialog box
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 or pop-up menu to ask the question. In this case, it does not use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358 keyboard input or the echo area. You can force use of the mouse or use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359 of keyboard input by binding @code{last-nonmenu-event} to a suitable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 value around the call.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1361
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1362 The return value of @code{map-y-or-n-p} is the number of objects acted on.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1363 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1364
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 444
diff changeset
1365 @node Reading a Password, Minibuffer Misc, Multiple Queries, Minibuffers
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1366 @section Reading a Password
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1367 @cindex passwords, reading
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1368
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1369 To read a password to pass to another program, you can use the
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1370 function @code{read-passwd}.
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1371
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1372 @defun read-passwd prompt &optional confirm default
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1373 This function reads a password, prompting with @var{prompt}. It does
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1374 not echo the password as the user types it; instead, it echoes @samp{.}
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1375 for each character in the password.
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1376
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1377 The optional argument @var{confirm}, if non-@code{nil}, says to read the
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1378 password twice and insist it must be the same both times. If it isn't
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1379 the same, the user has to type it over and over until the last two
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1380 times match.
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1381
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1382 The optional argument @var{default} specifies the default password to
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1383 return if the user enters empty input. It is translated to @samp{.}
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1384 and inserted in the minibuffer. If @var{default} is @code{nil}, then
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1385 @code{read-passwd} returns the null string in that case.
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1386 @end defun
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1387
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1388 @defopt passwd-invert-frame-when-keyboard-grabbed
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1389 If non-@code{nil}, swap the foreground and background colors of all faces while
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1390 reading a password. Default values is @code{t}, unless feature
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1391 @code{infodock} is provided.
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1392 @end defopt
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1393
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1394 @defopt passwd-echo
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1395 This specifies the character echoed when typing a password. When @code{nil},
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1396 nothing is echoed.
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1397 @end defopt
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1398
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 444
diff changeset
1399 @node Minibuffer Misc, , Reading a Password, Minibuffers
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1400 @section Minibuffer Miscellany
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1401
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1402 This section describes some basic functions and variables related to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1403 minibuffers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1404
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1405 @deffn Command exit-minibuffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1406 This command exits the active minibuffer. It is normally bound to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1407 keys in minibuffer local keymaps.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1408 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1409
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1410 @deffn Command self-insert-and-exit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1411 This command exits the active minibuffer after inserting the last
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1412 character typed on the keyboard (found in @code{last-command-char};
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1413 @pxref{Command Loop Info}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1414 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1415
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1416 @deffn Command previous-history-element n
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1417 This command replaces the minibuffer contents with the value of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1418 @var{n}th previous (older) history element.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1419 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1420
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421 @deffn Command next-history-element n
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1422 This command replaces the minibuffer contents with the value of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423 @var{n}th more recent history element.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1424 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1425
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1426 @deffn Command previous-matching-history-element pattern
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1427 This command replaces the minibuffer contents with the value of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1428 previous (older) history element that matches @var{pattern} (a regular
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 expression).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1430 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 @deffn Command next-matching-history-element pattern
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433 This command replaces the minibuffer contents with the value of the next
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434 (newer) history element that matches @var{pattern} (a regular
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1435 expression).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1437
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1438 @defun minibuffer-prompt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1439 This function returns the prompt string of the currently active
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1440 minibuffer. If no minibuffer is active, it returns @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1442
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1443 @defun minibuffer-prompt-width
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1444 This function returns the display width of the prompt string of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1445 currently active minibuffer. If no minibuffer is active, it returns 0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1446 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1447
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1448 @defvar minibuffer-setup-hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1449 This is a normal hook that is run whenever the minibuffer is entered.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1450 @xref{Hooks}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1451 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1452
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1453 @defvar minibuffer-exit-hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1454 This is a normal hook that is run whenever the minibuffer is exited.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1455 @xref{Hooks}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1456 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1457
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1458 @defvar minibuffer-help-form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1459 The current value of this variable is used to rebind @code{help-form}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1460 locally inside the minibuffer (@pxref{Help Functions}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1461 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1462
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1463 @defun active-minibuffer-window
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1464 This function returns the currently active minibuffer window, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1465 @code{nil} if none is currently active.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1466 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1467
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1468 @defun minibuffer-window &optional frame
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1469 This function returns the minibuffer window used for frame @var{frame}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1470 If @var{frame} is @code{nil}, that stands for the current frame. Note
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1471 that the minibuffer window used by a frame need not be part of that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1472 frame---a frame that has no minibuffer of its own necessarily uses some
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1473 other frame's minibuffer window.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1474 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1475
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1476 @c Emacs 19 feature
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1477 @defun window-minibuffer-p &optional window
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1478 This function returns non-@code{nil} if @var{window} is a minibuffer window.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1479 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1481 It is not correct to determine whether a given window is a minibuffer by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1482 comparing it with the result of @code{(minibuffer-window)}, because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483 there can be more than one minibuffer window if there is more than one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1484 frame.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1486 @defun minibuffer-window-active-p window
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1487 This function returns non-@code{nil} if @var{window}, assumed to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488 a minibuffer window, is currently active.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1490
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1491 @defvar minibuffer-scroll-window
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492 If the value of this variable is non-@code{nil}, it should be a window
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1493 object. When the function @code{scroll-other-window} is called in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1494 minibuffer, it scrolls this window.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1495 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1496
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1497 Finally, some functions and variables deal with recursive minibuffers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1498 (@pxref{Recursive Editing}):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1499
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1500 @defun minibuffer-depth
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1501 This function returns the current depth of activations of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1502 minibuffer, a nonnegative integer. If no minibuffers are active, it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1503 returns zero.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1505
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506 @defopt enable-recursive-minibuffers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1507 If this variable is non-@code{nil}, you can invoke commands (such as
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1508 @code{find-file}) that use minibuffers even while the minibuffer window
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1509 is active. Such invocation produces a recursive editing level for a new
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1510 minibuffer. The outer-level minibuffer is invisible while you are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1511 editing the inner one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513 This variable only affects invoking the minibuffer while the
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1514 minibuffer window is selected. If you switch windows while in the
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1515 minibuffer, you can always invoke minibuffer commands while some other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516 window is selected.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1517 @end defopt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1519 @c Emacs 19 feature
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1520 In FSF Emacs 19, if a command name has a property
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1521 @code{enable-recursive-minibuffers} that is non-@code{nil}, then the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1522 command can use the minibuffer to read arguments even if it is invoked
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1523 from the minibuffer. The minibuffer command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1524 @code{next-matching-history-element} (normally @kbd{M-s} in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1525 minibuffer) uses this feature.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1526
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1527 This is not implemented in XEmacs because it is a kludge. If you
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1528 want to explicitly set the value of @code{enable-recursive-minibuffers}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1529 in this fashion, just use an evaluated interactive spec and bind
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1530 @code{enable-recursive-minibuffers} while reading from the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1531 See the definition of @code{next-matching-history-element} in
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1532 @file{lisp/minibuf.el}.