comparison lispref/minibuf.texi @ 21682:90da2489c498

*** empty log message ***
author Richard M. Stallman <rms@gnu.org>
date Mon, 20 Apr 1998 17:43:57 +0000
parents 66d807bdc5b4
children d4ac295a98b3
comparison
equal deleted inserted replaced
21681:11eafe90b842 21682:90da2489c498
11 11
12 A @dfn{minibuffer} is a special buffer that Emacs commands use to read 12 A @dfn{minibuffer} is a special buffer that Emacs commands use to read
13 arguments more complicated than the single numeric prefix argument. 13 arguments more complicated than the single numeric prefix argument.
14 These arguments include file names, buffer names, and command names (as 14 These arguments include file names, buffer names, and command names (as
15 in @kbd{M-x}). The minibuffer is displayed on the bottom line of the 15 in @kbd{M-x}). The minibuffer is displayed on the bottom line of the
16 screen, in the same place as the echo area, but only while it is in 16 frame, in the same place as the echo area, but only while it is in use
17 use for reading an argument. 17 for reading an argument.
18 18
19 @menu 19 @menu
20 * Intro to Minibuffers:: Basic information about minibuffers. 20 * Intro to Minibuffers:: Basic information about minibuffers.
21 * Text from Minibuffer:: How to read a straight text string. 21 * Text from Minibuffer:: How to read a straight text string.
22 * Object from Minibuffer:: How to read a Lisp object or expression. 22 * Object from Minibuffer:: How to read a Lisp object or expression.
98 minibuffer. By default, it accepts arbitrary text and returns it as a 98 minibuffer. By default, it accepts arbitrary text and returns it as a
99 string; however, if @var{read} is non-@code{nil}, then it uses 99 string; however, if @var{read} is non-@code{nil}, then it uses
100 @code{read} to convert the text into a Lisp object (@pxref{Input 100 @code{read} to convert the text into a Lisp object (@pxref{Input
101 Functions}). 101 Functions}).
102 102
103 The first thing this function does is to activate a minibuffer and 103 The first thing this function does is to activate a minibuffer and
104 display it with @var{prompt-string} as the prompt. This value must be a 104 display it with @var{prompt-string} as the prompt. This value must be a
105 string. 105 string. Then the user can edit text in the minibuffer.
106 106
107 Then, if @var{initial-contents} is a string, @code{read-from-minibuffer} 107 When the user types a command to exit the minibuffer,
108 inserts it into the minibuffer, leaving point at the end. The 108 @code{read-from-minibuffer} constructs the return value from the text in
109 minibuffer appears with this text as its contents. 109 the minibuffer. Normally it returns a string containing that text.
110 110 However, if @var{read} is non-@code{nil}, @code{read-from-minibuffer}
111 @strong{Usage note:} The @var{initial-contents} argument and the 111 reads the text and returns the resulting Lisp object, unevaluated.
112 @var{default} argument are two alternative features for the same job. 112 (@xref{Input Functions}, for information about reading.)
113 It usually does not make sense to use both at once. In most cases, you 113
114 should use @var{default}, since this permits the user to insert the 114 The argument @var{default} specifies a default value to make available
115 default value but does not burden the user with deleting it from the 115 through the history commands. It should be a string, or @code{nil}. If
116 minibuffer. 116 @var{read} is non-@code{nil}, then @var{default} is also used as the
117 117 input to @code{read}, if the user enters empty input. However, in the
118 @c Emacs 19 feature 118 usual case (where @var{read} is @code{nil}, @code{read-from-minibuffer}
119 The value of @var{initial-contents} may also be a cons cell of the form 119 does not return @var{default} when the user enters empty input; it
120 @code{(@var{string} . @var{position})}. This means to insert 120 returns an empty string, @code{""}. In this respect, it is different
121 @var{string} in the minibuffer but put point @var{position} characters 121 from all the other minibuffer input functions in this chapter.
122 from the beginning, rather than at the end.
123 122
124 If @var{keymap} is non-@code{nil}, that keymap is the local keymap to 123 If @var{keymap} is non-@code{nil}, that keymap is the local keymap to
125 use in the minibuffer. If @var{keymap} is omitted or @code{nil}, the 124 use in the minibuffer. If @var{keymap} is omitted or @code{nil}, the
126 value of @code{minibuffer-local-map} is used as the keymap. Specifying 125 value of @code{minibuffer-local-map} is used as the keymap. Specifying
127 a keymap is the most important way to customize the minibuffer for 126 a keymap is the most important way to customize the minibuffer for
129 128
130 The argument @var{hist} specifies which history list variable to use 129 The argument @var{hist} specifies which history list variable to use
131 for saving the input and for history commands used in the minibuffer. 130 for saving the input and for history commands used in the minibuffer.
132 It defaults to @code{minibuffer-history}. @xref{Minibuffer History}. 131 It defaults to @code{minibuffer-history}. @xref{Minibuffer History}.
133 132
134 When the user types a command to exit the minibuffer,
135 @code{read-from-minibuffer} uses the text in the minibuffer to produce
136 its return value. Normally it simply makes a string containing that
137 text. However, if @var{read} is non-@code{nil},
138 @code{read-from-minibuffer} reads the text and returns the resulting
139 Lisp object, unevaluated. (@xref{Input Functions}, for information
140 about reading.)
141
142 If the variable @code{minibuffer-allow-text-properties} is 133 If the variable @code{minibuffer-allow-text-properties} is
143 non-@code{nil}, then the string which is returned includes whatever text 134 non-@code{nil}, then the string which is returned includes whatever text
144 properties were present in the minibuffer. Otherwise all the text 135 properties were present in the minibuffer. Otherwise all the text
145 properties are stripped when the value is returned. 136 properties are stripped when the value is returned.
146 137
147 The argument @var{default} specifies a default value to make available
148 through the history list. It should be a string, or @code{nil}. If
149 @var{read} is non-@code{nil}, then @var{default} is passed through
150 @code{read}, just as ordinary user input would be. Unlike many other
151 minibuffer functions, this function does @emph{not} return @var{default}
152 if the user enters empty input. It returns @code{""} in that case.
153
154 If the argument @var{inherit-input-method} is non-@code{nil}, then the 138 If the argument @var{inherit-input-method} is non-@code{nil}, then the
155 minibuffer inherits the current input method and the setting of 139 minibuffer inherits the current input method and the setting of
156 @code{enable-multibyte-characters} from whichever buffer was current 140 @code{enable-multibyte-characters} from whichever buffer was current
157 before entering the minibuffer. 141 before entering the minibuffer.
142
143 If @var{initial-contents} is a string, @code{read-from-minibuffer}
144 inserts it into the minibuffer, leaving point at the end, before the
145 user starts to edit the text. The minibuffer appears with this text as
146 its initial contents.
147
148 Alternatively, @var{initial-contents} can be a cons cell of the form
149 @code{(@var{string} . @var{position})}. This means to insert
150 @var{string} in the minibuffer but put point @var{position} characters
151 from the beginning, rather than at the end.
152
153 @strong{Usage note:} The @var{initial-contents} argument and the
154 @var{default} argument are two alternative features for more or less the
155 same job. It does not make sense to use both features in a single call
156 to @code{read-from-minibuffer}. In general, we recommend using
157 @var{default}, since this permits the user to insert the default value
158 when it is wanted, but does not burden the user with deleting it from
159 the minibuffer on other occasions.
158 @end defun 160 @end defun
159 161
160 @defun read-string prompt &optional initial history default inherit-input-method 162 @defun read-string prompt &optional initial history default inherit-input-method
161 This function reads a string from the minibuffer and returns it. The 163 This function reads a string from the minibuffer and returns it. The
162 arguments @var{prompt} and @var{initial} are used as in 164 arguments @var{prompt} and @var{initial} are used as in
175 177
176 @smallexample 178 @smallexample
177 @group 179 @group
178 (read-string @var{prompt} @var{initial} @var{history} @var{default} @var{inherit}) 180 (read-string @var{prompt} @var{initial} @var{history} @var{default} @var{inherit})
179 @equiv{} 181 @equiv{}
180 (read-from-minibuffer @var{prompt} @var{initial} nil nil 182 (let ((value
181 @var{history} @var{default} @var{inherit}) 183 (read-from-minibuffer @var{prompt} @var{initial} nil nil
184 @var{history} @var{default} @var{inherit})))
185 (if (equal value "")
186 @var{default}
187 value))
182 @end group 188 @end group
183 @end smallexample 189 @end smallexample
184 @end defun 190 @end defun
185 191
186 @defvar minibuffer-allow-text-properties 192 @defvar minibuffer-allow-text-properties
193 @defvar minibuffer-local-map 199 @defvar minibuffer-local-map
194 This is the default local keymap for reading from the minibuffer. By 200 This is the default local keymap for reading from the minibuffer. By
195 default, it makes the following bindings: 201 default, it makes the following bindings:
196 202
197 @table @asis 203 @table @asis
198 @item @key{LFD} 204 @item @kbd{C-j}
199 @code{exit-minibuffer} 205 @code{exit-minibuffer}
200 206
201 @item @key{RET} 207 @item @key{RET}
202 @code{exit-minibuffer} 208 @code{exit-minibuffer}
203 209
366 @node Minibuffer History 372 @node Minibuffer History
367 @section Minibuffer History 373 @section Minibuffer History
368 @cindex minibuffer history 374 @cindex minibuffer history
369 @cindex history list 375 @cindex history list
370 376
371 A @dfn{minibuffer history list} records previous minibuffer inputs so 377 A @dfn{minibuffer history list} records previous minibuffer inputs so
372 the user can reuse them conveniently. A history list is actually a 378 the user can reuse them conveniently. A history list is actually a
373 symbol, not a list; it is a variable whose value is a list of strings 379 symbol, not a list; it is a variable whose value is a list of strings
374 (previous inputs), most recent first. 380 (previous inputs), most recent first.
375 381
376 There are many separate history lists, used for different kinds of 382 There are many separate history lists, used for different kinds of
377 inputs. It's the Lisp programmer's job to specify the right history 383 inputs. It's the Lisp programmer's job to specify the right history
378 list for each use of the minibuffer. 384 list for each use of the minibuffer.
379 385
380 The basic minibuffer input functions @code{read-from-minibuffer} and 386 The basic minibuffer input functions @code{read-from-minibuffer} and
381 @code{completing-read} both accept an optional argument named @var{hist} 387 @code{completing-read} both accept an optional argument named @var{hist}
382 which is how you specify the history list. Here are the possible 388 which is how you specify the history list. Here are the possible
383 values: 389 values:
384 390
385 @table @asis 391 @table @asis
393 399
394 If you specify @var{startpos}, then you should also specify that element 400 If you specify @var{startpos}, then you should also specify that element
395 of the history as the initial minibuffer contents, for consistency. 401 of the history as the initial minibuffer contents, for consistency.
396 @end table 402 @end table
397 403
398 If you don't specify @var{hist}, then the default history list 404 If you don't specify @var{hist}, then the default history list
399 @code{minibuffer-history} is used. For other standard history lists, 405 @code{minibuffer-history} is used. For other standard history lists,
400 see below. You can also create your own history list variable; just 406 see below. You can also create your own history list variable; just
401 initialize it to @code{nil} before the first use. 407 initialize it to @code{nil} before the first use.
402 408
403 Both @code{read-from-minibuffer} and @code{completing-read} add new 409 Both @code{read-from-minibuffer} and @code{completing-read} add new
404 elements to the history list automatically, and provide commands to 410 elements to the history list automatically, and provide commands to
405 allow the user to reuse items on the list. The only thing your program 411 allow the user to reuse items on the list. The only thing your program
406 needs to do to use a history list is to initialize it and to pass its 412 needs to do to use a history list is to initialize it and to pass its
407 name to the input functions when you wish. But it is safe to modify the 413 name to the input functions when you wish. But it is safe to modify the
408 list by hand when the minibuffer input functions are not using it. 414 list by hand when the minibuffer input functions are not using it.
415
416 Here are some of the standard minibuffer history list variables:
409 417
410 @defvar minibuffer-history 418 @defvar minibuffer-history
411 The default history list for minibuffer history input. 419 The default history list for minibuffer history input.
412 @end defvar 420 @end defvar
413 421
578 @end smallexample 586 @end smallexample
579 @end defun 587 @end defun
580 588
581 @defun all-completions string collection &optional predicate nospace 589 @defun all-completions string collection &optional predicate nospace
582 This function returns a list of all possible completions of 590 This function returns a list of all possible completions of
583 @var{string}. The parameters to this function are the same as to 591 @var{string}. The arguments to this function are the same as those of
584 @code{try-completion}. 592 @code{try-completion}.
585 593
586 If @var{collection} is a function, it is called with three arguments: 594 If @var{collection} is a function, it is called with three arguments:
587 @var{string}, @var{predicate} and @code{t}; then @code{all-completions} 595 @var{string}, @var{predicate} and @code{t}; then @code{all-completions}
588 returns whatever the function returns. @xref{Programmed Completion}. 596 returns whatever the function returns. @xref{Programmed Completion}.
622 minibuffer with completion. 630 minibuffer with completion.
623 631
624 @defun completing-read prompt collection &optional predicate require-match initial hist default inherit-input-method 632 @defun completing-read prompt collection &optional predicate require-match initial hist default inherit-input-method
625 This function reads a string in the minibuffer, assisting the user by 633 This function reads a string in the minibuffer, assisting the user by
626 providing completion. It activates the minibuffer with prompt 634 providing completion. It activates the minibuffer with prompt
627 @var{prompt}, which must be a string. If @var{initial} is 635 @var{prompt}, which must be a string.
628 non-@code{nil}, @code{completing-read} inserts it into the minibuffer as
629 part of the input. Then it allows the user to edit the input, providing
630 several commands to attempt completion.
631 636
632 The actual completion is done by passing @var{collection} and 637 The actual completion is done by passing @var{collection} and
633 @var{predicate} to the function @code{try-completion}. This happens in 638 @var{predicate} to the function @code{try-completion}. This happens in
634 certain commands bound in the local keymaps used for completion. 639 certain commands bound in the local keymaps used for completion.
635 640
640 @code{nil} nor @code{t}, then the exit commands won't exit unless the 645 @code{nil} nor @code{t}, then the exit commands won't exit unless the
641 input already in the buffer matches an element of @var{collection}. 646 input already in the buffer matches an element of @var{collection}.
642 647
643 However, empty input is always permitted, regardless of the value of 648 However, empty input is always permitted, regardless of the value of
644 @var{require-match}; in that case, @code{completing-read} returns 649 @var{require-match}; in that case, @code{completing-read} returns
645 @var{default}. 650 @var{default}. The value of @var{default} (if non-@code{nil}) is also
651 available to the user through the history commands.
646 652
647 The user can exit with null input by typing @key{RET} with an empty 653 The user can exit with null input by typing @key{RET} with an empty
648 minibuffer. Then @code{completing-read} returns @code{""}. This is how 654 minibuffer. Then @code{completing-read} returns @code{""}. This is how
649 the user requests whatever default the command uses for the value being 655 the user requests whatever default the command uses for the value being
650 read. The user can return using @key{RET} in this way regardless of the 656 read. The user can return using @key{RET} in this way regardless of the
659 665
660 The argument @var{hist} specifies which history list variable to use for 666 The argument @var{hist} specifies which history list variable to use for
661 saving the input and for minibuffer history commands. It defaults to 667 saving the input and for minibuffer history commands. It defaults to
662 @code{minibuffer-history}. @xref{Minibuffer History}. 668 @code{minibuffer-history}. @xref{Minibuffer History}.
663 669
664 The optional argument @var{default} specifies a default value to return 670 If @var{initial} is non-@code{nil}, @code{completing-read} inserts it
665 if the user enters null input; it should be a string. 671 into the minibuffer as part of the input. Then it allows the user to
672 edit the input, providing several commands to attempt completion.
673 In most cases, we recommend using @var{default}, and not @var{initial}.
666 674
667 If the argument @var{inherit-input-method} is non-@code{nil}, then the 675 If the argument @var{inherit-input-method} is non-@code{nil}, then the
668 minibuffer inherits the current input method and the setting of 676 minibuffer inherits the current input method and the setting of
669 @code{enable-multibyte-characters} from whichever buffer was current 677 @code{enable-multibyte-characters} from whichever buffer was current
670 before entering the minibuffer. @xref{Input Methods,,, emacs, The GNU 678 before entering the minibuffer. @xref{Input Methods,,, emacs, The GNU
748 @code{minibuffer-complete-word} 756 @code{minibuffer-complete-word}
749 757
750 @item @key{TAB} 758 @item @key{TAB}
751 @code{minibuffer-complete} 759 @code{minibuffer-complete}
752 760
753 @item @key{LFD} 761 @item @kbd{C-j}
754 @code{minibuffer-complete-and-exit} 762 @code{minibuffer-complete-and-exit}
755 763
756 @item @key{RET} 764 @item @key{RET}
757 @code{minibuffer-complete-and-exit} 765 @code{minibuffer-complete-and-exit}
758 @end table 766 @end table
901 @code{read-from-minibuffer}. Recall that a command is anything for 909 @code{read-from-minibuffer}. Recall that a command is anything for
902 which @code{commandp} returns @code{t}, and a command name is a symbol 910 which @code{commandp} returns @code{t}, and a command name is a symbol
903 for which @code{commandp} returns @code{t}. @xref{Interactive Call}. 911 for which @code{commandp} returns @code{t}. @xref{Interactive Call}.
904 912
905 The argument @var{default} specifies what to return if the user enters 913 The argument @var{default} specifies what to return if the user enters
906 null input. It can be a symbol or a string, but the value returned by 914 null input. It can be a symbol or a string; if it is a string,
907 @code{read-command} is always a symbol. If @var{default} is @code{nil}, 915 @code{read-command} interns it before returning it. If @var{default} is
908 that means no default has been specified; then if the user enters null 916 @code{nil}, that means no default has been specified; then if the user
909 input, the return value is @code{nil}. 917 enters null input, the return value is @code{nil}.
910 918
911 @example 919 @example
912 (read-command "Command name? ") 920 (read-command "Command name? ")
913 921
914 @group 922 @group
946 @defun read-variable prompt &optional default 954 @defun read-variable prompt &optional default
947 This function reads the name of a user variable and returns it as a 955 This function reads the name of a user variable and returns it as a
948 symbol. 956 symbol.
949 957
950 The argument @var{default} specifies what to return if the user enters 958 The argument @var{default} specifies what to return if the user enters
951 null input. It can be a symbol or a string, but the value returned by 959 null input. It can be a symbol or a string; if it is a string,
952 @code{read-variable} is always a symbol. If @var{default} is 960 @code{read-variable} interns it before returning it. If @var{default}
953 @code{nil}, that means no default has been specified; then if the user 961 is @code{nil}, that means no default has been specified; then if the
954 enters null input, the return value is @code{nil}. 962 user enters null input, the return value is @code{nil}.
955 963
956 @example 964 @example
957 @group 965 @group
958 (read-variable "Variable name? ") 966 (read-variable "Variable name? ")
959 967
986 'user-variable-p t nil)) 994 'user-variable-p t nil))
987 @end group 995 @end group
988 @end example 996 @end example
989 @end defun 997 @end defun
990 998
991 @tindex read-coding-system 999 See also the functions @code{read-coding-system} and
992 @defun read-coding-system prompt default 1000 @code{read-non-nil-coding-system}, in @ref{Lisp and Coding Systems}.
993 This function reads a coding system using the minibuffer, prompting with
994 string @var{prompt}, and returns the coding system name as a symbol. If
995 the user tries to enter null input, it asks the user to try again.
996 @xref{Coding Systems}.
997 @end defun
998
999 @tindex read-non-nil-coding-system
1000 @defun read-non-nil-coding-system prompt
1001 This function reads a coding system using the minibuffer, prompting with
1002 string @var{prompt},and returns the coding system name as a symbol. If
1003 the user enters null input, it returns @var{default-coding-system}.
1004 which should be a symbol or a string. @xref{Coding Systems}.
1005 @end defun
1006 1001
1007 @node Reading File Names 1002 @node Reading File Names
1008 @subsection Reading File Names 1003 @subsection Reading File Names
1009 1004
1010 Here is another high-level completion function, designed for reading a 1005 Here is another high-level completion function, designed for reading a
1035 @c Emacs 19 feature 1030 @c Emacs 19 feature
1036 If you specify @var{initial}, that is an initial file name to insert in 1031 If you specify @var{initial}, that is an initial file name to insert in
1037 the buffer (after with @var{directory}, if that is inserted). In this 1032 the buffer (after with @var{directory}, if that is inserted). In this
1038 case, point goes at the beginning of @var{initial}. The default for 1033 case, point goes at the beginning of @var{initial}. The default for
1039 @var{initial} is @code{nil}---don't insert any file name. To see what 1034 @var{initial} is @code{nil}---don't insert any file name. To see what
1040 @var{initial} does, try the command @kbd{C-x C-v}. 1035 @var{initial} does, try the command @kbd{C-x C-v}. @strong{Note:} we
1036 recommend using @var{default} rather than @var{initial} in most cases.
1041 1037
1042 Here is an example: 1038 Here is an example:
1043 1039
1044 @example 1040 @example
1045 @group 1041 @group
1151 should return the completion of the specified string, or @code{t} if the 1147 should return the completion of the specified string, or @code{t} if the
1152 string is a unique and exact match already, or @code{nil} if the string 1148 string is a unique and exact match already, or @code{nil} if the string
1153 matches no possibility. 1149 matches no possibility.
1154 1150
1155 If the string is an exact match for one possibility, but also matches 1151 If the string is an exact match for one possibility, but also matches
1156 other longer possibilities, the function shuold return the string, not 1152 other longer possibilities, the function should return the string, not
1157 @code{t}. 1153 @code{t}.
1158 1154
1159 @item 1155 @item
1160 @code{t} specifies @code{all-completions}. The completion function 1156 @code{t} specifies @code{all-completions}. The completion function
1161 should return a list of all possible completions of the specified 1157 should return a list of all possible completions of the specified
1531 returns zero. 1527 returns zero.
1532 @end defun 1528 @end defun
1533 1529
1534 @defopt enable-recursive-minibuffers 1530 @defopt enable-recursive-minibuffers
1535 If this variable is non-@code{nil}, you can invoke commands (such as 1531 If this variable is non-@code{nil}, you can invoke commands (such as
1536 @code{find-file}) that use minibuffers even while in the minibuffer 1532 @code{find-file}) that use minibuffers even while the minibuffer window
1537 window. Such invocation produces a recursive editing level for a new 1533 is active. Such invocation produces a recursive editing level for a new
1538 minibuffer. The outer-level minibuffer is invisible while you are 1534 minibuffer. The outer-level minibuffer is invisible while you are
1539 editing the inner one. 1535 editing the inner one.
1540 1536
1541 This variable only affects invoking the minibuffer while the 1537 If this variable is @code{nil}, you cannot invoke minibuffer
1542 minibuffer window is selected. If you switch windows while in the 1538 commands when the minibuffer window is active, not even if you switch to
1543 minibuffer, you can always invoke minibuffer commands while some other 1539 another window to do it.
1544 window is selected.
1545 @end defopt 1540 @end defopt
1546 1541
1547 @c Emacs 19 feature 1542 @c Emacs 19 feature
1548 If a command name has a property @code{enable-recursive-minibuffers} 1543 If a command name has a property @code{enable-recursive-minibuffers}
1549 that is non-@code{nil}, then the command can use the minibuffer to read 1544 that is non-@code{nil}, then the command can use the minibuffer to read