0
|
1 /* Call a Lisp function interactively.
|
|
2 Copyright (C) 1985, 1986, 1992, 1993, 1994 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995, 1996 Ben Wing.
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: FSF 19.30, Mule 2.0. */
|
|
23
|
|
24 /* Authorship:
|
|
25
|
|
26 FSF: long ago.
|
|
27 Mly or JWZ: various changes.
|
|
28 */
|
|
29
|
|
30 #include <config.h>
|
|
31 #include "lisp.h"
|
|
32
|
|
33 #include "buffer.h"
|
|
34 #include "bytecode.h"
|
|
35 #include "commands.h"
|
|
36 #include "events.h"
|
|
37 #include "insdel.h"
|
|
38 #include "window.h"
|
|
39
|
|
40 extern int num_input_chars;
|
|
41
|
|
42 Lisp_Object Vcurrent_prefix_arg;
|
|
43 Lisp_Object Qcall_interactively;
|
|
44 Lisp_Object Vcommand_history;
|
|
45
|
|
46 Lisp_Object Vcommand_debug_status, Qcommand_debug_status;
|
|
47 Lisp_Object Qenable_recursive_minibuffers;
|
|
48
|
|
49 #if 0 /* FSFmacs */
|
|
50 /* Non-nil means treat the mark as active
|
|
51 even if mark_active is 0. */
|
|
52 Lisp_Object Vmark_even_if_inactive;
|
|
53 #endif
|
|
54
|
|
55 #if 0 /* ill-conceived */
|
|
56 Lisp_Object Vmouse_leave_buffer_hook, Qmouse_leave_buffer_hook;
|
|
57 #endif
|
|
58
|
|
59 Lisp_Object Qlet, QletX, Qsave_excursion;
|
|
60
|
|
61 Lisp_Object Qcurrent_prefix_arg;
|
|
62
|
|
63 Lisp_Object Quser_variable_p;
|
|
64 Lisp_Object Qread_from_minibuffer;
|
|
65 Lisp_Object Qread_file_name;
|
|
66 Lisp_Object Qread_directory_name;
|
|
67 Lisp_Object Qcompleting_read;
|
|
68 Lisp_Object Qread_buffer;
|
|
69 Lisp_Object Qread_function;
|
|
70 Lisp_Object Qread_variable;
|
|
71 Lisp_Object Qread_expression;
|
|
72 Lisp_Object Qread_command;
|
|
73 Lisp_Object Qread_number;
|
|
74 Lisp_Object Qread_string;
|
|
75 Lisp_Object Qevents_to_keys;
|
|
76
|
|
77 /* ARGSUSED */
|
20
|
78 DEFUN ("interactive", Finteractive, 0, UNEVALLED, 0, /*
|
0
|
79 Specify a way of parsing arguments for interactive use of a function.
|
|
80 For example, write
|
|
81 (defun foo (arg) \"Doc string\" (interactive \"p\") ...use arg...)
|
|
82 to make ARG be the prefix argument when `foo' is called as a command.
|
|
83 The \"call\" to `interactive' is actually a declaration rather than a function;
|
|
84 it tells `call-interactively' how to read arguments
|
|
85 to pass to the function.
|
|
86 When actually called, `interactive' just returns nil.
|
|
87
|
|
88 The argument of `interactive' is usually a string containing a code letter
|
|
89 followed by a prompt. (Some code letters do not use I/O to get
|
|
90 the argument and do not need prompts.) To prompt for multiple arguments,
|
|
91 give a code letter, its prompt, a newline, and another code letter, etc.
|
|
92 Prompts are passed to format, and may use % escapes to print the
|
|
93 arguments that have already been read.
|
|
94 If the argument is not a string, it is evaluated to get a list of
|
|
95 arguments to pass to the function.
|
|
96 Just `(interactive)' means pass no args when calling interactively.
|
|
97
|
|
98 Code letters available are:
|
|
99 a -- Function name: symbol with a function definition.
|
|
100 b -- Name of existing buffer.
|
|
101 B -- Name of buffer, possibly nonexistent.
|
|
102 c -- Character.
|
|
103 C -- Command name: symbol with interactive function definition.
|
|
104 d -- Value of point as number. Does not do I/O.
|
|
105 D -- Directory name.
|
|
106 e -- Last mouse-button or misc-user event that invoked this command.
|
|
107 If used more than once, the Nth `e' returns the Nth such event.
|
|
108 Does not do I/O.
|
|
109 f -- Existing file name.
|
|
110 F -- Possibly nonexistent file name.
|
2
|
111 i -- Always nil, ignore. Use to skip arguments when interactive.
|
0
|
112 k -- Key sequence (a vector of events).
|
|
113 K -- Key sequence to be redefined (do not automatically down-case).
|
|
114 m -- Value of mark as number. Does not do I/O.
|
|
115 n -- Number read using minibuffer.
|
|
116 N -- Prefix arg converted to number, or if none, do like code `n'.
|
|
117 p -- Prefix arg converted to number. Does not do I/O.
|
|
118 P -- Prefix arg in raw form. Does not do I/O.
|
|
119 r -- Region: point and mark as 2 numeric args, smallest first. Does no I/O.
|
|
120 s -- Any string.
|
|
121 S -- Any symbol.
|
|
122 v -- Variable name: symbol that is user-variable-p.
|
|
123 x -- Lisp expression read but not evaluated.
|
|
124 X -- Lisp expression read and evaluated.
|
|
125 In addition, if the string begins with `*'
|
|
126 then an error is signaled if the buffer is read-only.
|
|
127 This happens before reading any arguments.
|
|
128 If the string begins with `@', then the window the mouse is over is selected
|
|
129 before anything else is done.
|
|
130 If the string begins with `_', then this command will not cause the region
|
|
131 to be deactivated when it completes; that is, `zmacs-region-stays' will be
|
|
132 set to t when the command exits successfully.
|
|
133 You may use any of `@', `*' and `_' at the beginning of the string;
|
|
134 they are processed in the order that they appear.
|
20
|
135 */
|
|
136 (args))
|
0
|
137 {
|
|
138 return Qnil;
|
|
139 }
|
|
140
|
|
141 /* Quotify EXP: if EXP is constant, return it.
|
|
142 If EXP is not constant, return (quote EXP). */
|
|
143 static Lisp_Object
|
|
144 quotify_arg (Lisp_Object exp)
|
|
145 {
|
|
146 if (!INTP (exp) && !CHARP (exp) && !STRINGP (exp)
|
|
147 && !NILP (exp) && !EQ (exp, Qt))
|
|
148 return Fcons (Qquote, Fcons (exp, Qnil));
|
|
149
|
|
150 return exp;
|
|
151 }
|
|
152
|
|
153 /* Modify EXP by quotifying each element (except the first). */
|
|
154 static Lisp_Object
|
|
155 quotify_args (Lisp_Object exp)
|
|
156 {
|
|
157 REGISTER Lisp_Object tail;
|
|
158 REGISTER struct Lisp_Cons *ptr;
|
|
159 for (tail = exp; CONSP (tail); tail = ptr->cdr)
|
|
160 {
|
|
161 ptr = XCONS (tail);
|
|
162 ptr->car = quotify_arg (ptr->car);
|
|
163 }
|
|
164 return exp;
|
|
165 }
|
|
166
|
|
167 static Bufpos
|
|
168 check_mark (void)
|
|
169 {
|
|
170 Lisp_Object tem;
|
|
171
|
|
172 if (zmacs_regions && !zmacs_region_active_p)
|
|
173 error ("The region is not active now");
|
|
174
|
|
175 tem = Fmarker_buffer (current_buffer->mark);
|
|
176 if (NILP (tem) || (XBUFFER (tem) != current_buffer))
|
|
177 error ("The mark is not set now");
|
|
178
|
|
179 return (marker_position (current_buffer->mark));
|
|
180 }
|
|
181
|
|
182 static Lisp_Object
|
|
183 callint_prompt (CONST Bufbyte *prompt_start, Bytecount prompt_length,
|
|
184 CONST Lisp_Object *args, int nargs)
|
|
185 {
|
|
186 Lisp_Object s = make_string (prompt_start, prompt_length);
|
|
187 struct gcpro gcpro1;
|
|
188
|
|
189 /* Fformat no longer smashes its arg vector, so no need to copy it. */
|
|
190
|
14
|
191 if (!strchr ((char *) XSTRING_DATA (s), '%'))
|
0
|
192 return (s);
|
|
193 GCPRO1 (s);
|
|
194 RETURN_UNGCPRO (emacs_doprnt_string_lisp (0, s, 0, nargs, args));
|
|
195 }
|
|
196
|
|
197 /* `lambda' for RECORD-FLAG is an XEmacs addition. */
|
|
198
|
20
|
199 DEFUN ("call-interactively", Fcall_interactively, 1, 3, 0, /*
|
0
|
200 Call FUNCTION, reading args according to its interactive calling specs.
|
|
201 Return the value FUNCTION returns.
|
|
202 The function contains a specification of how to do the argument reading.
|
|
203 In the case of user-defined functions, this is specified by placing a call
|
|
204 to the function `interactive' at the top level of the function body.
|
|
205 See `interactive'.
|
|
206
|
|
207 If optional second arg RECORD-FLAG is the symbol `lambda', the interactive
|
|
208 calling arguments for FUNCTION are read and returned as a list,
|
|
209 but the function is not called on them.
|
|
210
|
|
211 If RECORD-FLAG is `t' then unconditionally put this command in the
|
|
212 command-history. Otherwise, this is done only if an arg is read using
|
|
213 the minibuffer.
|
|
214
|
|
215 The argument KEYS specifies the value to use instead of (this-command-keys)
|
|
216 when reading the arguments.
|
20
|
217 */
|
|
218 (function, record_flag, keys))
|
0
|
219 {
|
|
220 /* This function can GC */
|
|
221 int speccount = specpdl_depth ();
|
|
222 Lisp_Object prefix;
|
|
223
|
|
224 Lisp_Object fun;
|
|
225 Lisp_Object specs = Qnil;
|
|
226 #ifdef IT_SEEMS_THAT_MLY_DOESNT_LIKE_THIS
|
|
227 Lisp_Object enable;
|
|
228 #endif
|
|
229 /* If SPECS is a string, we reset prompt_data to string_data
|
|
230 * (XSTRING (specs)) every time a GC might have occurred */
|
|
231 CONST char *prompt_data = 0;
|
|
232 int prompt_index = 0;
|
|
233 int argcount;
|
|
234 int set_zmacs_region_stays = 0;
|
|
235 int mouse_event_count = 0;
|
|
236
|
|
237 if (!NILP (keys))
|
|
238 {
|
|
239 int i;
|
|
240
|
|
241 CHECK_VECTOR (keys);
|
|
242 for (i = 0; i < vector_length (XVECTOR (keys)); i++)
|
|
243 CHECK_LIVE_EVENT (vector_data (XVECTOR (keys))[i]);
|
|
244 }
|
|
245
|
|
246 /* Save this now, since use of minibuffer will clobber it. */
|
|
247 prefix = Vcurrent_prefix_arg;
|
|
248
|
|
249 retry:
|
|
250
|
|
251 #ifdef IT_SEEMS_THAT_MLY_DOESNT_LIKE_THIS
|
|
252 /* Marginal kludge. Use an evaluated interactive spec instead of this! */
|
|
253 if (SYMBOLP (function))
|
|
254 enable = Fget (function, Qenable_recursive_minibuffers, Qnil);
|
|
255 #endif
|
|
256
|
|
257 fun = indirect_function (function, 1);
|
|
258
|
|
259 /* Decode the kind of function. Either handle it and return,
|
|
260 or go to `lose' if not interactive, or go to `retry'
|
|
261 to specify a different function, or set either PROMPT_DATA or SPECS. */
|
|
262
|
|
263 if (SUBRP (fun))
|
|
264 {
|
|
265 prompt_data = XSUBR (fun)->prompt;
|
|
266 if (!prompt_data)
|
|
267 {
|
|
268 lose:
|
|
269 function = wrong_type_argument (Qcommandp, function);
|
|
270 goto retry;
|
|
271 }
|
|
272 #if 0 /* FSFmacs */ /* Huh? Where is this used? */
|
|
273 if ((EMACS_INT) prompt_data == 1)
|
|
274 /* Let SPECS (which is nil) be used as the args. */
|
|
275 prompt_data = 0;
|
|
276 #endif
|
|
277 }
|
|
278 else if (COMPILED_FUNCTIONP (fun))
|
|
279 {
|
|
280 struct Lisp_Compiled_Function *b = XCOMPILED_FUNCTION (fun);
|
|
281 if (!(b->flags.interactivep))
|
|
282 goto lose;
|
|
283 specs = compiled_function_interactive (b);
|
|
284 }
|
|
285 else if (!CONSP (fun))
|
|
286 goto lose;
|
|
287 else
|
|
288 {
|
|
289 Lisp_Object funcar = Fcar (fun);
|
|
290
|
|
291 if (EQ (funcar, Qautoload))
|
|
292 {
|
|
293 struct gcpro gcpro1, gcpro2;
|
|
294 GCPRO2 (function, prefix);
|
|
295 do_autoload (fun, function);
|
|
296 UNGCPRO;
|
|
297 goto retry;
|
|
298 }
|
|
299 else if (EQ (funcar, Qlambda))
|
|
300 {
|
|
301 specs = Fassq (Qinteractive, Fcdr (Fcdr (fun)));
|
|
302 if (NILP (specs))
|
|
303 goto lose;
|
|
304 specs = Fcar (Fcdr (specs));
|
|
305 }
|
|
306 #ifdef MOCKLISP_SUPPORT
|
|
307 else if (EQ (funcar, Qmocklisp))
|
|
308 {
|
|
309 single_console_state ();
|
|
310 return ml_apply (fun, Qinteractive);
|
|
311 }
|
|
312 #endif
|
|
313 else
|
|
314 goto lose;
|
|
315 }
|
|
316
|
|
317 /* FSFmacs makes an alloca() copy of prompt_data here.
|
|
318 We're more intelligent about this and just reset prompt_data
|
|
319 as necessary. */
|
|
320 /* If either specs or prompt_data is set to a string, use it. */
|
|
321 if (!STRINGP (specs) && prompt_data == 0)
|
|
322 {
|
|
323 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
324 int i = num_input_chars;
|
|
325 Lisp_Object input = specs;
|
|
326
|
|
327 GCPRO3 (function, specs, input);
|
|
328 /* Compute the arg values using the user's expression. */
|
|
329 specs = Feval (specs);
|
|
330 if (EQ (record_flag, Qlambda)) /* XEmacs addition */
|
|
331 {
|
|
332 UNGCPRO;
|
|
333 return (specs);
|
|
334 }
|
|
335 if (!NILP (record_flag) || i != num_input_chars)
|
|
336 {
|
|
337 /* We should record this command on the command history. */
|
|
338 /* #### The following is too specific; should have general
|
|
339 mechanism for doing this. */
|
|
340 Lisp_Object values, car;
|
|
341 /* Make a copy of the list of values, for the command history,
|
|
342 and turn them into things we can eval. */
|
|
343 values = quotify_args (Fcopy_sequence (specs));
|
|
344 /* If the list of args was produced with an explicit call to `list',
|
|
345 look for elements that were computed with (region-beginning)
|
|
346 or (region-end), and put those expressions into VALUES
|
|
347 instead of the present values. */
|
|
348 if (CONSP (input))
|
|
349 {
|
|
350 car = XCAR (input);
|
|
351 /* Skip through certain special forms. */
|
|
352 while (EQ (car, Qlet) || EQ (car, QletX)
|
|
353 || EQ (car, Qsave_excursion))
|
|
354 {
|
|
355 while (CONSP (XCDR (input)))
|
|
356 input = XCDR (input);
|
|
357 input = XCAR (input);
|
|
358 if (!CONSP (input))
|
|
359 break;
|
|
360 car = XCAR (input);
|
|
361 }
|
|
362 if (EQ (car, Qlist))
|
|
363 {
|
|
364 Lisp_Object intail, valtail;
|
|
365 for (intail = Fcdr (input), valtail = values;
|
|
366 CONSP (valtail);
|
|
367 intail = Fcdr (intail), valtail = Fcdr (valtail))
|
|
368 {
|
|
369 Lisp_Object elt;
|
|
370 elt = Fcar (intail);
|
|
371 if (CONSP (elt))
|
|
372 {
|
|
373 Lisp_Object eltcar = Fcar (elt);
|
|
374 if (EQ (eltcar, Qpoint)
|
|
375 || EQ (eltcar, Qmark)
|
|
376 || EQ (eltcar, Qregion_beginning)
|
|
377 || EQ (eltcar, Qregion_end))
|
|
378 Fsetcar (valtail, Fcar (intail));
|
|
379 }
|
|
380 }
|
|
381 }
|
|
382 }
|
|
383 Vcommand_history
|
|
384 = Fcons (Fcons (function, values), Vcommand_history);
|
|
385 }
|
|
386 single_console_state ();
|
|
387 RETURN_UNGCPRO (apply1 (fun, specs));
|
|
388 }
|
|
389
|
|
390 /* Here if function specifies a string to control parsing the defaults */
|
|
391
|
|
392 #ifdef I18N3
|
|
393 /* Translate interactive prompt. */
|
|
394 if (STRINGP (specs))
|
|
395 {
|
|
396 Lisp_Object domain = Qnil;
|
|
397 if (COMPILED_FUNCTIONP (fun))
|
|
398 domain = Fcompiled_function_domain (fun);
|
|
399 if (NILP (domain))
|
|
400 specs = Fgettext (specs);
|
|
401 else
|
|
402 specs = Fdgettext (domain, specs);
|
|
403 }
|
|
404 else if (prompt_data)
|
|
405 /* We do not have to worry about domains in this case because
|
|
406 prompt_data is non-nil only for built-in functions, which
|
|
407 always use the default domain. */
|
|
408 prompt_data = gettext (prompt_data);
|
|
409 #endif
|
|
410
|
|
411 /* Handle special starting chars `*' and `@' and `_'. */
|
|
412 /* Note that `+' is reserved for user extensions. */
|
|
413 prompt_index = 0;
|
|
414 {
|
|
415 struct gcpro gcpro1, gcpro2;
|
|
416 GCPRO2 (function, specs);
|
|
417
|
|
418 for (;;)
|
|
419 {
|
|
420 if (STRINGP (specs))
|
14
|
421 prompt_data = (CONST char *) XSTRING_DATA (specs);
|
0
|
422
|
|
423 if (prompt_data[prompt_index] == '+')
|
|
424 error ("`+' is not used in `interactive' for ordinary commands");
|
|
425 else if (prompt_data[prompt_index] == '*')
|
|
426 {
|
|
427 prompt_index++;
|
|
428 if (!NILP (current_buffer->read_only))
|
|
429 barf_if_buffer_read_only (current_buffer, -1, -1);
|
|
430 }
|
|
431 else if (prompt_data[prompt_index] == '@')
|
|
432 {
|
|
433 Lisp_Object event;
|
|
434 prompt_index++;
|
|
435
|
|
436 if (!NILP (keys))
|
|
437 event = extract_vector_nth_mouse_event (keys, 0);
|
|
438 else
|
|
439 #if 0
|
|
440 event = extract_this_command_keys_nth_mouse_event (0);
|
|
441 #else
|
|
442 /* Doesn't work; see below */
|
|
443 event = Vcurrent_mouse_event;
|
|
444 #endif
|
|
445 if (! NILP (event))
|
|
446 {
|
|
447 Lisp_Object window = Fevent_window (event);
|
|
448 if (!NILP (window))
|
|
449 {
|
|
450 if (MINI_WINDOW_P (XWINDOW (window))
|
|
451 && ! (minibuf_level > 0 && EQ (window,
|
|
452 minibuf_window)))
|
|
453 error ("Attempt to select inactive minibuffer window");
|
|
454
|
|
455 #if 0 /* unclean! see event-stream.c */
|
|
456 /* If the current buffer wants to clean up, let it. */
|
|
457 if (!NILP (Vmouse_leave_buffer_hook))
|
|
458 run_hook (Qmouse_leave_buffer_hook);
|
|
459 #endif
|
|
460
|
|
461 Fselect_window (window);
|
|
462 }
|
|
463 }
|
|
464 }
|
|
465 else if (prompt_data[prompt_index] == '_')
|
|
466 {
|
|
467 prompt_index++;
|
|
468 set_zmacs_region_stays = 1;
|
|
469 }
|
|
470 else
|
|
471 {
|
|
472 UNGCPRO;
|
|
473 break;
|
|
474 }
|
|
475 }
|
|
476 }
|
|
477
|
|
478 /* Count the number of arguments the interactive spec would have
|
|
479 us give to the function. */
|
|
480 argcount = 0;
|
|
481 {
|
|
482 CONST char *tem;
|
|
483 for (tem = prompt_data + prompt_index; *tem; )
|
|
484 {
|
|
485 /* 'r' specifications ("point and mark as 2 numeric args")
|
|
486 produce *two* arguments. */
|
|
487 if (*tem == 'r')
|
|
488 argcount += 2;
|
|
489 else
|
|
490 argcount += 1;
|
|
491 tem = (CONST char *) strchr (tem + 1, '\n');
|
|
492 if (!tem)
|
|
493 break;
|
|
494 tem++;
|
|
495 }
|
|
496 }
|
|
497
|
|
498 #ifdef IT_SEEMS_THAT_MLY_DOESNT_LIKE_THIS
|
|
499 if (!NILP (enable))
|
|
500 specbind (Qenable_recursive_minibuffers, Qt);
|
|
501 #endif
|
|
502
|
|
503 if (argcount == 0)
|
|
504 {
|
|
505 /* Interactive function or no arguments; just call it */
|
|
506 if (EQ (record_flag, Qlambda))
|
|
507 return (Qnil);
|
|
508 if (!NILP (record_flag))
|
|
509 {
|
|
510 Vcommand_history = Fcons (list1 (function), Vcommand_history);
|
|
511 }
|
|
512 specbind (Qcommand_debug_status, Qnil);
|
|
513 /* XEmacs: was fun = call0 (fun), but that's backtraced wrong */
|
|
514 {
|
|
515 struct gcpro gcpro1;
|
|
516
|
|
517 GCPRO1 (fun);
|
|
518 fun = funcall_recording_as (function, 1, &fun);
|
|
519 UNGCPRO;
|
|
520 }
|
|
521 if (set_zmacs_region_stays)
|
|
522 zmacs_region_stays = 1;
|
|
523 return (unbind_to (speccount, fun));
|
|
524 }
|
|
525
|
|
526 /* Read interactive arguments */
|
|
527 {
|
|
528 /* args[-1] is the function to call */
|
|
529 /* args[n] is the n'th argument to the function */
|
|
530 int alloca_size = (1 /* function to call */
|
|
531 + argcount /* actual arguments */
|
|
532 + argcount /* visargs */
|
|
533 + argcount /* varies */
|
|
534 );
|
|
535 Lisp_Object *args
|
|
536 = (((Lisp_Object *) alloca (sizeof (Lisp_Object) * alloca_size))
|
|
537 + 1);
|
|
538 /* visargs is an array of either Qnil or user-friendlier versions (often
|
|
539 * strings) of previous arguments, to use in prompts for succesive
|
|
540 * arguments. ("Often strings" because emacs didn't used to have
|
|
541 * format %S and prin1-to-string.) */
|
|
542 Lisp_Object *visargs = args + argcount;
|
|
543 /* If varies[i] is non-null, the i'th argument shouldn't just have
|
|
544 its value in this call quoted in the command history. It should be
|
|
545 recorded as a call to the function named varies[i]]. */
|
|
546 Lisp_Object *varies = visargs + argcount;
|
|
547 int arg_from_tty = 0;
|
|
548 REGISTER int argnum;
|
|
549 struct gcpro gcpro1, gcpro2;
|
|
550
|
|
551 args[-1] = function;
|
|
552 for (argnum = 0; argnum < alloca_size - 1; argnum++)
|
|
553 args[argnum] = Qnil;
|
|
554
|
|
555 /* Must GC-protect args[-1] (ie function) because Ffuncall doesn't */
|
|
556 /* `function' itself isn't GC-protected -- use args[-1] from here
|
|
557 (actually, doesn't matter since Emacs GC doesn't relocate, sigh) */
|
|
558 GCPRO2 (prefix, args[-1]);
|
|
559 gcpro2.nvars = alloca_size;
|
|
560
|
|
561 for (argnum = 0; ; argnum++)
|
|
562 {
|
|
563 CONST char *prompt_start = prompt_data + prompt_index + 1;
|
|
564 CONST char *prompt_limit = (CONST char *) strchr (prompt_start, '\n');
|
|
565 int prompt_length;
|
|
566 prompt_length = ((prompt_limit)
|
|
567 ? (prompt_limit - prompt_start)
|
|
568 : strlen (prompt_start));
|
|
569 if (prompt_limit && prompt_limit[1] == 0)
|
|
570 {
|
|
571 prompt_limit = 0; /* "sfoo:\n" -- strip tailing return */
|
|
572 prompt_length -= 1;
|
|
573 }
|
|
574 /* This uses `visargs' instead of `args' so that global-set-key
|
|
575 prompts with "Set key C-x C-f to command: "instead of printing
|
|
576 event objects in there.
|
|
577 */
|
|
578 #define PROMPT() callint_prompt ((CONST Bufbyte *) prompt_start, prompt_length, visargs, argnum)
|
|
579 switch (prompt_data[prompt_index])
|
|
580 {
|
|
581 case 'a': /* Symbol defined as a function */
|
|
582 {
|
|
583 Lisp_Object tem = call1 (Qread_function, PROMPT ());
|
|
584 args[argnum] = tem;
|
|
585 arg_from_tty = 1;
|
|
586 break;
|
|
587 }
|
|
588 case 'b': /* Name of existing buffer */
|
|
589 {
|
|
590 Lisp_Object def = Fcurrent_buffer ();
|
|
591 if (EQ (Fselected_window (Qnil), minibuf_window))
|
|
592 def = Fother_buffer (def, Qnil, Qnil);
|
|
593 /* read-buffer returns a buffer name, not a buffer! */
|
|
594 args[argnum] = call3 (Qread_buffer, PROMPT (), def,
|
|
595 Qt);
|
|
596 arg_from_tty = 1;
|
|
597 break;
|
|
598 }
|
|
599 case 'B': /* Name of buffer, possibly nonexistent */
|
|
600 {
|
|
601 /* read-buffer returns a buffer name, not a buffer! */
|
|
602 args[argnum] = call2 (Qread_buffer, PROMPT (),
|
|
603 Fother_buffer (Fcurrent_buffer (), Qnil,
|
|
604 Qnil));
|
|
605 arg_from_tty = 1;
|
|
606 break;
|
|
607 }
|
|
608 case 'c': /* Character */
|
|
609 {
|
|
610 Lisp_Object tem;
|
|
611 int shadowing_speccount = specpdl_depth ();
|
|
612
|
|
613 specbind (Qcursor_in_echo_area, Qt);
|
14
|
614 message ("%s", XSTRING_DATA (PROMPT ()));
|
0
|
615 tem = (call0 (Qread_char));
|
|
616 args[argnum] = tem;
|
|
617 /* visargs[argnum] = Fsingle_key_description (tem); */
|
|
618 /* FSF has visargs[argnum] = Fchar_to_string (tem); */
|
|
619
|
|
620 unbind_to (shadowing_speccount, Qnil);
|
|
621
|
|
622 /* #### `C-x / a' should not leave the prompt in the minibuffer.
|
|
623 This isn't the right fix, because (message ...) (read-char)
|
|
624 shouldn't leave the message there either... */
|
|
625 clear_message ();
|
|
626
|
|
627 arg_from_tty = 1;
|
|
628 break;
|
|
629 }
|
|
630 case 'C': /* Command: symbol with interactive function */
|
|
631 {
|
|
632 Lisp_Object tem = call1 (Qread_command, PROMPT ());
|
|
633 args[argnum] = tem;
|
|
634 arg_from_tty = 1;
|
|
635 break;
|
|
636 }
|
|
637 case 'd': /* Value of point. Does not do I/O. */
|
|
638 {
|
|
639 args[argnum] = Fcopy_marker (current_buffer->point_marker, Qt);
|
|
640 varies[argnum] = Qpoint;
|
|
641 break;
|
|
642 }
|
|
643 case 'e':
|
|
644 {
|
|
645 Lisp_Object event;
|
|
646
|
|
647 if (!NILP (keys))
|
|
648 event = extract_vector_nth_mouse_event (keys,
|
|
649 mouse_event_count);
|
|
650 else
|
|
651 #if 0
|
|
652 /* This doesn't quite work because this-command-keys
|
|
653 behaves in utterly counterintuitive ways. Sometimes
|
|
654 it retrieves an event back in the future, e.g. when
|
|
655 one command invokes another command and both are
|
|
656 invoked with the mouse. */
|
|
657 event = (extract_this_command_keys_nth_mouse_event
|
|
658 (mouse_event_count));
|
|
659 #else
|
|
660 event = Vcurrent_mouse_event;
|
|
661 #endif
|
|
662
|
|
663 if (NILP (event))
|
|
664 error ("%s must be bound to a mouse or misc-user event",
|
|
665 (SYMBOLP (function)
|
|
666 ? (char *) string_data (XSYMBOL (function)->name)
|
|
667 : "command"));
|
|
668 args[argnum] = event;
|
|
669 mouse_event_count++;
|
|
670 break;
|
|
671 }
|
|
672 case 'D': /* Directory name. */
|
|
673 {
|
|
674 args[argnum] = call4 (Qread_directory_name, PROMPT (),
|
|
675 Qnil, /* dir */
|
|
676 current_buffer->directory, /* default */
|
|
677 Qt /* must-match */
|
|
678 );
|
|
679 arg_from_tty = 1;
|
|
680 break;
|
|
681 }
|
|
682 case 'f': /* Existing file name. */
|
|
683 {
|
|
684 Lisp_Object tem = call4 (Qread_file_name, PROMPT (),
|
|
685 Qnil, /* dir */
|
|
686 Qnil, /* default */
|
|
687 make_int (0) /* must-match */
|
|
688 );
|
|
689 args[argnum] = tem;
|
|
690 arg_from_tty = 1;
|
|
691 break;
|
|
692 }
|
|
693 case 'F': /* Possibly nonexistent file name. */
|
|
694 {
|
|
695 args[argnum] = call4 (Qread_file_name, PROMPT (),
|
|
696 Qnil, /* dir */
|
|
697 Qnil, /* default */
|
|
698 Qnil /* must-match */
|
|
699 );
|
|
700 arg_from_tty = 1;
|
|
701 break;
|
|
702 }
|
2
|
703 case 'i': /* Ignore: always nil. Use to skip arguments. */
|
|
704 {
|
|
705 args[argnum] = Qnil;
|
|
706 break;
|
|
707 }
|
0
|
708 case 'k': /* Key sequence (vector of events) */
|
|
709 {
|
|
710 Lisp_Object tem = Fread_key_sequence (PROMPT (), Qnil, Qnil);
|
|
711 visargs[argnum] = Fkey_description (tem);
|
|
712 /* The following makes `describe-key' not work with
|
|
713 extent-local keymaps and such; and anyway, it's
|
|
714 contrary to the documentation. */
|
|
715 /* args[argnum] = call1 (Qevents_to_keys, tem); */
|
|
716 args[argnum] = tem;
|
|
717 arg_from_tty = 1;
|
|
718 break;
|
|
719 }
|
|
720 case 'K': /* Key sequence (vector of events),
|
|
721 no automatic downcasing */
|
|
722 {
|
|
723 Lisp_Object tem = Fread_key_sequence (PROMPT (), Qnil, Qt);
|
|
724 visargs[argnum] = Fkey_description (tem);
|
|
725 /* The following makes `describe-key' not work with
|
|
726 extent-local keymaps and such; and anyway, it's
|
|
727 contrary to the documentation. */
|
|
728 /* args[argnum] = call1 (Qevents_to_keys, tem); */
|
|
729 args[argnum] = tem;
|
|
730 arg_from_tty = 1;
|
|
731 break;
|
|
732 }
|
|
733
|
|
734 case 'm': /* Value of mark. Does not do I/O. */
|
|
735 {
|
|
736 args[argnum] = current_buffer->mark;
|
|
737 varies[argnum] = Qmark;
|
|
738 break;
|
|
739 }
|
|
740 case 'n': /* Read number from minibuffer. */
|
|
741 {
|
|
742 read_number:
|
|
743 args[argnum] = call2 (Qread_number, PROMPT (), Qt);
|
|
744 /* numbers are too boring to go on command history */
|
|
745 /* arg_from_tty = 1; */
|
|
746 break;
|
|
747 }
|
|
748 case 'N': /* Prefix arg, else number from minibuffer */
|
|
749 {
|
|
750 if (NILP (prefix))
|
|
751 goto read_number;
|
|
752 else
|
|
753 goto prefix_value;
|
|
754 }
|
|
755 case 'P': /* Prefix arg in raw form. Does no I/O. */
|
|
756 {
|
|
757 args[argnum] = prefix;
|
|
758 break;
|
|
759 }
|
|
760 case 'p': /* Prefix arg converted to number. No I/O. */
|
|
761 {
|
|
762 prefix_value:
|
|
763 {
|
|
764 Lisp_Object tem = Fprefix_numeric_value (prefix);
|
|
765 args[argnum] = tem;
|
|
766 }
|
|
767 break;
|
|
768 }
|
|
769 case 'r': /* Region, point and mark as 2 args. */
|
|
770 {
|
|
771 Bufpos tem = check_mark ();
|
|
772 args[argnum] = (BUF_PT (current_buffer) < tem
|
|
773 ? Fcopy_marker (current_buffer->point_marker, Qt)
|
|
774 : current_buffer->mark);
|
|
775 varies[argnum] = Qregion_beginning;
|
|
776 args[++argnum] = (BUF_PT (current_buffer) > tem
|
|
777 ? Fcopy_marker (current_buffer->point_marker,
|
|
778 Qt)
|
|
779 : current_buffer->mark);
|
|
780 varies[argnum] = Qregion_end;
|
|
781 break;
|
|
782 }
|
|
783 case 's': /* String read via minibuffer. */
|
|
784 {
|
|
785 args[argnum] = call1 (Qread_string, PROMPT ());
|
|
786 arg_from_tty = 1;
|
|
787 break;
|
|
788 }
|
|
789 case 'S': /* Any symbol. */
|
|
790 {
|
|
791 #if 0 /* Historical crock */
|
|
792 Lisp_Object tem = intern ("minibuffer-local-ns-map");
|
|
793 tem = find_symbol_value (tem);
|
|
794 if (UNBOUNDP (tem)) tem = Qnil;
|
|
795 tem = call3 (Qread_from_minibuffer, PROMPT (), Qnil,
|
|
796 tem);
|
|
797 args[argnum] = Fintern (tem, Qnil);
|
|
798 #else /* 1 */
|
|
799 visargs[argnum] = Qnil;
|
|
800 for (;;)
|
|
801 {
|
|
802 Lisp_Object tem = call5 (Qcompleting_read,
|
|
803 PROMPT (),
|
|
804 Vobarray,
|
|
805 Qnil,
|
|
806 Qnil,
|
|
807 /* nil, or prev attempt */
|
|
808 visargs[argnum]);
|
|
809 visargs[argnum] = tem;
|
|
810 /* I could use condition-case with this loser, but why bother?
|
|
811 * tem = Fread (tem); check-symbol-p;
|
|
812 */
|
|
813 tem = Fintern (tem, Qnil);
|
|
814 args[argnum] = tem;
|
|
815 if (string_length (XSYMBOL (tem)->name) > 0)
|
|
816 /* Don't accept the empty-named symbol. If the loser
|
|
817 really wants this s/he can call completing-read
|
|
818 directly */
|
|
819 break;
|
|
820 }
|
|
821 #endif /* 1 */
|
|
822 arg_from_tty = 1;
|
|
823 break;
|
|
824 }
|
|
825 case 'v': /* Variable name: user-variable-p symbol */
|
|
826 {
|
|
827 Lisp_Object tem = call1 (Qread_variable, PROMPT ());
|
|
828 args[argnum] = tem;
|
|
829 arg_from_tty = 1;
|
|
830 break;
|
|
831 }
|
|
832 case 'x': /* Lisp expression read but not evaluated */
|
|
833 {
|
|
834 args[argnum] = call1 (Qread_expression, PROMPT ());
|
|
835 /* visargs[argnum] = Fprin1_to_string (args[argnum], Qnil); */
|
|
836 arg_from_tty = 1;
|
|
837 break;
|
|
838 }
|
|
839 case 'X': /* Lisp expression read and evaluated */
|
|
840 {
|
|
841 Lisp_Object tem = call1 (Qread_expression, PROMPT ());
|
|
842 /* visargs[argnum] = Fprin1_to_string (tem, Qnil); */
|
|
843 args[argnum] = Feval (tem);
|
|
844 arg_from_tty = 1;
|
|
845 break;
|
|
846 }
|
|
847
|
|
848 /* We have a case for `+' so we get an error
|
|
849 if anyone tries to define one here. */
|
|
850 case '+':
|
|
851 default:
|
|
852 {
|
|
853 error ("Invalid `interactive' control letter \"%c\" (#o%03o).",
|
|
854 prompt_data[prompt_index],
|
|
855 prompt_data[prompt_index]);
|
|
856 }
|
|
857 }
|
|
858 #undef PROMPT
|
|
859 if (NILP (visargs[argnum]))
|
|
860 visargs[argnum] = args[argnum];
|
|
861
|
|
862 if (!prompt_limit)
|
|
863 break;
|
|
864 if (STRINGP (specs))
|
14
|
865 prompt_data = (CONST char *) XSTRING_DATA (specs);
|
0
|
866 prompt_index += prompt_length + 1 + 1; /* +1 to skip spec, +1 for \n */
|
|
867 }
|
|
868 unbind_to (speccount, Qnil);
|
|
869
|
|
870 QUIT;
|
|
871
|
|
872 if (EQ (record_flag, Qlambda))
|
|
873 {
|
|
874 RETURN_UNGCPRO (Flist (argcount, args));
|
|
875 }
|
|
876
|
|
877 if (arg_from_tty || !NILP (record_flag))
|
|
878 {
|
|
879 /* Reuse visargs as a temporary for constructing the command history */
|
|
880 for (argnum = 0; argnum < argcount; argnum++)
|
|
881 {
|
|
882 if (!NILP (varies[argnum]))
|
|
883 visargs[argnum] = list1 (varies[argnum]);
|
|
884 else
|
|
885 visargs[argnum] = quotify_arg (args[argnum]);
|
|
886 }
|
|
887 Vcommand_history = Fcons (Fcons (args[-1], Flist (argcount, visargs)),
|
|
888 Vcommand_history);
|
|
889 }
|
|
890
|
|
891 /* If we used a marker to hold point, mark, or an end of the region,
|
|
892 temporarily, convert it to an integer now. */
|
|
893 for (argnum = 0; argnum < argcount; argnum++)
|
|
894 if (!NILP (varies[argnum]))
|
|
895 XSETINT (args[argnum], marker_position (args[argnum]));
|
|
896
|
|
897 single_console_state ();
|
|
898 specbind (Qcommand_debug_status, Qnil);
|
|
899 fun = Ffuncall (argcount + 1, args - 1);
|
|
900 UNGCPRO;
|
|
901 if (set_zmacs_region_stays)
|
|
902 zmacs_region_stays = 1;
|
|
903 return (unbind_to (speccount, fun));
|
|
904 }
|
|
905 }
|
|
906
|
20
|
907 DEFUN ("prefix-numeric-value", Fprefix_numeric_value, 1, 1, 0, /*
|
0
|
908 Return numeric meaning of raw prefix argument ARG.
|
|
909 A raw prefix argument is what you get from `(interactive \"P\")'.
|
|
910 Its numeric meaning is what you would get from `(interactive \"p\")'.
|
20
|
911 */
|
|
912 (raw))
|
0
|
913 {
|
|
914 int val;
|
|
915
|
|
916 if (NILP (raw))
|
|
917 val = 1;
|
|
918 else if (EQ (raw, Qminus))
|
|
919 val = -1;
|
|
920 else if (INTP (raw))
|
|
921 val = XINT (raw);
|
|
922 else if (CONSP (raw) && INTP (XCAR (raw)))
|
|
923 val = XINT (XCAR (raw));
|
|
924 else
|
|
925 val = 1;
|
|
926
|
|
927 return (make_int (val));
|
|
928
|
|
929 }
|
|
930
|
|
931 void
|
|
932 syms_of_callint (void)
|
|
933 {
|
|
934 defsymbol (&Qcall_interactively, "call-interactively");
|
|
935 defsymbol (&Qread_from_minibuffer, "read-from-minibuffer");
|
|
936 defsymbol (&Qcompleting_read, "completing-read");
|
|
937 defsymbol (&Qread_file_name, "read-file-name");
|
|
938 defsymbol (&Qread_directory_name, "read-directory-name");
|
|
939 defsymbol (&Qread_string, "read-string");
|
|
940 defsymbol (&Qread_buffer, "read-buffer");
|
|
941 defsymbol (&Qread_variable, "read-variable");
|
|
942 defsymbol (&Qread_function, "read-function");
|
|
943 defsymbol (&Qread_command, "read-command");
|
|
944 defsymbol (&Qread_number, "read-number");
|
|
945 defsymbol (&Qread_expression, "read-expression");
|
|
946 defsymbol (&Qevents_to_keys, "events-to-keys");
|
|
947 defsymbol (&Qcommand_debug_status, "command-debug-status");
|
|
948 defsymbol (&Qenable_recursive_minibuffers, "enable-recursive-minibuffers");
|
|
949 defsymbol (&Qcommand_debug_status, "command-debug-status");
|
|
950 defsymbol (&Quser_variable_p, "user-variable-p");
|
|
951 defsymbol (&Qcurrent_prefix_arg, "current-prefix-arg");
|
|
952
|
|
953 defsymbol (&Qlet, "let");
|
|
954 defsymbol (&QletX, "let*");
|
|
955 defsymbol (&Qsave_excursion, "save-excursion");
|
|
956 #if 0 /* ill-conceived */
|
|
957 defsymbol (&Qmouse_leave_buffer_hook, "mouse-leave-buffer-hook");
|
|
958 #endif
|
|
959
|
20
|
960 DEFSUBR (Finteractive);
|
|
961 DEFSUBR (Fcall_interactively);
|
|
962 DEFSUBR (Fprefix_numeric_value);
|
0
|
963 }
|
|
964
|
|
965 void
|
|
966 vars_of_callint (void)
|
|
967 {
|
|
968 DEFVAR_LISP ("current-prefix-arg", &Vcurrent_prefix_arg /*
|
|
969 The value of the prefix argument for this editing command.
|
|
970 It may be a number, or the symbol `-' for just a minus sign as arg,
|
|
971 or a list whose car is a number for just one or more C-U's
|
|
972 or nil if no argument has been specified.
|
|
973 This is what `(interactive \"P\")' returns.
|
|
974 */ );
|
|
975 Vcurrent_prefix_arg = Qnil;
|
|
976
|
|
977 DEFVAR_LISP ("command-history", &Vcommand_history /*
|
|
978 List of recent commands that read arguments from terminal.
|
|
979 Each command is represented as a form to evaluate.
|
|
980 */ );
|
|
981 Vcommand_history = Qnil;
|
|
982
|
|
983 DEFVAR_LISP ("command-debug-status", &Vcommand_debug_status /*
|
|
984 Debugging status of current interactive command.
|
|
985 Bound each time `call-interactively' is called;
|
|
986 may be set by the debugger as a reminder for itself.
|
|
987 */ );
|
|
988 Vcommand_debug_status = Qnil;
|
|
989
|
|
990 #if 0 /* FSFmacs */
|
|
991 xxDEFVAR_LISP ("mark-even-if-inactive", &Vmark_even_if_inactive /*
|
|
992 *Non-nil means you can use the mark even when inactive.
|
|
993 This option makes a difference in Transient Mark mode.
|
|
994 When the option is non-nil, deactivation of the mark
|
|
995 turns off region highlighting, but commands that use the mark
|
|
996 behave as if the mark were still active.
|
|
997 */ );
|
|
998 Vmark_even_if_inactive = Qnil;
|
|
999 #endif
|
|
1000
|
|
1001 #if 0 /* Doesn't work and is totally ill-conceived anyway. */
|
|
1002 xxDEFVAR_LISP ("mouse-leave-buffer-hook", &Vmouse_leave_buffer_hook /*
|
|
1003 Hook to run when about to switch windows with a mouse command.
|
|
1004 Its purpose is to give temporary modes such as Isearch mode
|
|
1005 a way to turn themselves off when a mouse command switches windows.
|
|
1006 */ );
|
|
1007 Vmouse_leave_buffer_hook = Qnil;
|
|
1008 #endif
|
|
1009 }
|