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