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