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