Mercurial > emacs
comparison lispref/commands.texi @ 69014:d356f128459f
(Using Interactive): Put string case before list case.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 19 Feb 2006 23:38:11 +0000 |
parents | 727fe5204470 |
children | 069e0539c37d |
comparison
equal
deleted
inserted
replaced
69013:727fe5204470 | 69014:d356f128459f |
---|---|
148 @item | 148 @item |
149 It may be omitted or @code{nil}; then the command is called with no | 149 It may be omitted or @code{nil}; then the command is called with no |
150 arguments. This leads quickly to an error if the command requires one | 150 arguments. This leads quickly to an error if the command requires one |
151 or more arguments. | 151 or more arguments. |
152 | 152 |
153 @item | |
154 @cindex argument prompt | |
155 It may be a string; then its contents should consist of a code character | |
156 followed by a prompt (which some code characters use and some ignore). | |
157 The prompt ends either with the end of the string or with a newline. | |
158 Here is a simple example: | |
159 | |
160 @smallexample | |
161 (interactive "bFrobnicate buffer: ") | |
162 @end smallexample | |
163 | |
164 @noindent | |
165 The code letter @samp{b} says to read the name of an existing buffer, | |
166 with completion. The buffer name is the sole argument passed to the | |
167 command. The rest of the string is a prompt. | |
168 | |
169 If there is a newline character in the string, it terminates the prompt. | |
170 If the string does not end there, then the rest of the string should | |
171 contain another code character and prompt, specifying another argument. | |
172 You can specify any number of arguments in this way. | |
173 | |
174 @c Emacs 19 feature | |
175 The prompt string can use @samp{%} to include previous argument values | |
176 (starting with the first argument) in the prompt. This is done using | |
177 @code{format} (@pxref{Formatting Strings}). For example, here is how | |
178 you could read the name of an existing buffer followed by a new name to | |
179 give to that buffer: | |
180 | |
181 @smallexample | |
182 @group | |
183 (interactive "bBuffer to rename: \nsRename buffer %s to: ") | |
184 @end group | |
185 @end smallexample | |
186 | |
187 @cindex @samp{*} in @code{interactive} | |
188 @cindex read-only buffers in interactive | |
189 If the first character in the string is @samp{*}, then an error is | |
190 signaled if the buffer is read-only. | |
191 | |
192 @cindex @samp{@@} in @code{interactive} | |
193 @c Emacs 19 feature | |
194 If the first character in the string is @samp{@@}, and if the key | |
195 sequence used to invoke the command includes any mouse events, then | |
196 the window associated with the first of those events is selected | |
197 before the command is run. | |
198 | |
199 You can use @samp{*} and @samp{@@} together; the order does not matter. | |
200 Actual reading of arguments is controlled by the rest of the prompt | |
201 string (starting with the first character that is not @samp{*} or | |
202 @samp{@@}). | |
153 | 203 |
154 @item | 204 @item |
155 It may be a Lisp expression that is not a string; then it should be a | 205 It may be a Lisp expression that is not a string; then it should be a |
156 form that is evaluated to get a list of arguments to pass to the | 206 form that is evaluated to get a list of arguments to pass to the |
157 command. Usually this form will call various functions to read input | 207 command. Usually this form will call various functions to read input |
181 @smallexample | 231 @smallexample |
182 (interactive | 232 (interactive |
183 (let ((string (read-string "Foo: " nil 'my-history))) | 233 (let ((string (read-string "Foo: " nil 'my-history))) |
184 (list (region-beginning) (region-end) string))) | 234 (list (region-beginning) (region-end) string))) |
185 @end smallexample | 235 @end smallexample |
186 | |
187 @item | |
188 @cindex argument prompt | |
189 It may be a string; then its contents should consist of a code character | |
190 followed by a prompt (which some code characters use and some ignore). | |
191 The prompt ends either with the end of the string or with a newline. | |
192 Here is a simple example: | |
193 | |
194 @smallexample | |
195 (interactive "bFrobnicate buffer: ") | |
196 @end smallexample | |
197 | |
198 @noindent | |
199 The code letter @samp{b} says to read the name of an existing buffer, | |
200 with completion. The buffer name is the sole argument passed to the | |
201 command. The rest of the string is a prompt. | |
202 | |
203 If there is a newline character in the string, it terminates the prompt. | |
204 If the string does not end there, then the rest of the string should | |
205 contain another code character and prompt, specifying another argument. | |
206 You can specify any number of arguments in this way. | |
207 | |
208 @c Emacs 19 feature | |
209 The prompt string can use @samp{%} to include previous argument values | |
210 (starting with the first argument) in the prompt. This is done using | |
211 @code{format} (@pxref{Formatting Strings}). For example, here is how | |
212 you could read the name of an existing buffer followed by a new name to | |
213 give to that buffer: | |
214 | |
215 @smallexample | |
216 @group | |
217 (interactive "bBuffer to rename: \nsRename buffer %s to: ") | |
218 @end group | |
219 @end smallexample | |
220 | |
221 @cindex @samp{*} in @code{interactive} | |
222 @cindex read-only buffers in interactive | |
223 If the first character in the string is @samp{*}, then an error is | |
224 signaled if the buffer is read-only. | |
225 | |
226 @cindex @samp{@@} in @code{interactive} | |
227 @c Emacs 19 feature | |
228 If the first character in the string is @samp{@@}, and if the key | |
229 sequence used to invoke the command includes any mouse events, then | |
230 the window associated with the first of those events is selected | |
231 before the command is run. | |
232 | |
233 You can use @samp{*} and @samp{@@} together; the order does not matter. | |
234 Actual reading of arguments is controlled by the rest of the prompt | |
235 string (starting with the first character that is not @samp{*} or | |
236 @samp{@@}). | |
237 @end itemize | 236 @end itemize |
238 | 237 |
239 @cindex examining the @code{interactive} form | 238 @cindex examining the @code{interactive} form |
240 @defun interactive-form function | 239 @defun interactive-form function |
241 This function returns the @code{interactive} form of @var{function}. | 240 This function returns the @code{interactive} form of @var{function}. |