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