1 /* Call a Lisp function interactively.
2 Copyright (C) 1985-1986, 1993-1995, 1997, 2000-2017 Free Software
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or (at
10 your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
24 #include "character.h"
29 static Lisp_Object preserved_fns
;
31 /* Marker used within call-interactively to refer to point. */
32 static Lisp_Object point_marker
;
34 /* String for the prompt text used in Fcall_interactively. */
35 static Lisp_Object callint_message
;
38 DEFUN ("interactive", Finteractive
, Sinteractive
, 0, UNEVALLED
, 0,
39 doc
: /* Specify a way of parsing arguments for interactive use of a function.
41 (defun foo (arg buf) "Doc string" (interactive "P\\nbbuffer: ") .... )
42 to make ARG be the raw prefix argument, and set BUF to an existing buffer,
43 when `foo' is called as a command.
45 The "call" to `interactive' is actually a declaration rather than a
46 function; it tells `call-interactively' how to read arguments to pass
47 to the function. When actually called, `interactive' just returns
50 Usually the argument of `interactive' is a string containing a code
51 letter followed optionally by a prompt. (Some code letters do not
52 use I/O to get the argument and do not use prompts.) To pass several
53 arguments to the command, concatenate the individual strings,
54 separating them by newline characters.
56 Prompts are passed to `format', and may use % escapes to print the
57 arguments that have already been read.
58 If the argument is not a string, it is evaluated to get a list of
59 arguments to pass to the command.
60 Just `(interactive)' means pass no arguments to the command when
61 calling interactively.
63 Code letters available are:
64 a -- Function name: symbol with a function definition.
65 b -- Name of existing buffer.
66 B -- Name of buffer, possibly nonexistent.
67 c -- Character (no input method is used).
68 C -- Command name: symbol with interactive function definition.
69 d -- Value of point as number. Does not do I/O.
71 e -- Parameterized event (i.e., one that's a list) that invoked this command.
72 If used more than once, the Nth `e' returns the Nth parameterized event.
73 This skips events that are integers or symbols.
74 f -- Existing file name.
75 F -- Possibly nonexistent file name.
76 G -- Possibly nonexistent file name, defaulting to just directory name.
77 i -- Ignored, i.e. always nil. Does not do I/O.
78 k -- Key sequence (downcase the last event if needed to get a definition).
79 K -- Key sequence to be redefined (do not downcase the last event).
80 m -- Value of mark as number. Does not do I/O.
81 M -- Any string. Inherits the current input method.
82 n -- Number read using minibuffer.
83 N -- Numeric prefix arg, or if none, do like code `n'.
84 p -- Prefix arg converted to number. Does not do I/O.
85 P -- Prefix arg in raw form. Does not do I/O.
86 r -- Region: point and mark as 2 numeric args, smallest first. Does no I/O.
87 s -- Any string. Does not inherit the current input method.
89 U -- Mouse up event discarded by a previous k or K argument.
90 v -- Variable name: symbol that is `custom-variable-p'.
91 x -- Lisp expression read but not evaluated.
92 X -- Lisp expression read and evaluated.
94 Z -- Coding system, nil if no prefix arg.
96 In addition, if the string begins with `*', an error is signaled if
97 the buffer is read-only.
98 If `@' appears at the beginning of the string, and if the key sequence
99 used to invoke the command includes any mouse events, then the window
100 associated with the first of those events is selected before the
102 If the string begins with `^' and `shift-select-mode' is non-nil,
103 Emacs first calls the function `handle-shift-selection'.
104 You may use `@', `*', and `^' together. They are processed in the
105 order that they appear, before reading any arguments.
106 usage: (interactive &optional ARG-DESCRIPTOR) */
113 /* Quotify EXP: if EXP is constant, return it.
114 If EXP is not constant, return (quote EXP). */
116 quotify_arg (register Lisp_Object exp
)
120 && !NILP (exp
) && !EQ (exp
, Qt
)))
121 return list2 (Qquote
, exp
);
126 /* Modify EXP by quotifying each element (except the first). */
128 quotify_args (Lisp_Object exp
)
130 register Lisp_Object tail
;
132 for (tail
= exp
; CONSP (tail
); tail
= next
)
135 XSETCAR (tail
, quotify_arg (XCAR (tail
)));
140 static const char *callint_argfuns
[]
141 = {"", "point", "mark", "region-beginning", "region-end"};
144 check_mark (bool for_region
)
147 tem
= Fmarker_buffer (BVAR (current_buffer
, mark
));
148 if (NILP (tem
) || (XBUFFER (tem
) != current_buffer
))
149 error (for_region
? "The mark is not set now, so there is no region"
150 : "The mark is not set now");
151 if (!NILP (Vtransient_mark_mode
) && NILP (Vmark_even_if_inactive
)
152 && NILP (BVAR (current_buffer
, mark_active
)))
153 xsignal0 (Qmark_inactive
);
156 /* If the list of args INPUT was produced with an explicit call to
157 `list', look for elements that were computed with
158 (region-beginning) or (region-end), and put those expressions into
159 VALUES instead of the present values.
161 This function doesn't return a value because it modifies elements
162 of VALUES to do its job. */
165 fix_command (Lisp_Object input
, Lisp_Object values
)
167 /* FIXME: Instead of this ugly hack, we should provide a way for an
168 interactive spec to return an expression/function that will re-build the
169 args without user intervention. */
175 /* Skip through certain special forms. */
176 while (EQ (car
, Qlet
) || EQ (car
, Qletx
)
177 || EQ (car
, Qsave_excursion
)
180 while (CONSP (XCDR (input
)))
181 input
= XCDR (input
);
182 input
= XCAR (input
);
189 Lisp_Object intail
, valtail
;
190 for (intail
= Fcdr (input
), valtail
= values
;
192 intail
= Fcdr (intail
), valtail
= XCDR (valtail
))
198 Lisp_Object presflag
, carelt
;
200 /* If it is (if X Y), look at Y. */
202 && EQ (Fnthcdr (make_number (3), elt
), Qnil
))
203 elt
= Fnth (make_number (2), elt
);
204 /* If it is (when ... Y), look at Y. */
205 else if (EQ (carelt
, Qwhen
))
207 while (CONSP (XCDR (elt
)))
212 /* If the function call we're looking at
213 is a special preserved one, copy the
214 whole expression for this argument. */
217 presflag
= Fmemq (Fcar (elt
), preserved_fns
);
218 if (!NILP (presflag
))
219 Fsetcar (valtail
, Fcar (intail
));
227 /* Helper function to call `read-file-name' from C. */
230 read_file_name (Lisp_Object default_filename
, Lisp_Object mustmatch
,
231 Lisp_Object initial
, Lisp_Object predicate
)
233 return CALLN (Ffuncall
, intern ("read-file-name"),
234 callint_message
, Qnil
, default_filename
,
235 mustmatch
, initial
, predicate
);
238 /* BEWARE: Calling this directly from C would defeat the purpose! */
239 DEFUN ("funcall-interactively", Ffuncall_interactively
, Sfuncall_interactively
,
240 1, MANY
, 0, doc
: /* Like `funcall' but marks the call as interactive.
241 I.e. arrange that within the called function `called-interactively-p' will
243 usage: (funcall-interactively FUNCTION &rest ARGUMENTS) */)
244 (ptrdiff_t nargs
, Lisp_Object
*args
)
246 ptrdiff_t speccount
= SPECPDL_INDEX ();
247 temporarily_switch_to_single_kboard (NULL
);
249 /* Nothing special to do here, all the work is inside
250 `called-interactively-p'. Which will look for us as a marker in the
252 return unbind_to (speccount
, Ffuncall (nargs
, args
));
255 DEFUN ("call-interactively", Fcall_interactively
, Scall_interactively
, 1, 3, 0,
256 doc
: /* Call FUNCTION, providing args according to its interactive calling specs.
257 Return the value FUNCTION returns.
258 The function contains a specification of how to do the argument reading.
259 In the case of user-defined functions, this is specified by placing a call
260 to the function `interactive' at the top level of the function body.
263 Optional second arg RECORD-FLAG non-nil
264 means unconditionally put this command in the command-history.
265 Otherwise, this is done only if an arg is read using the minibuffer.
267 Optional third arg KEYS, if given, specifies the sequence of events to
268 supply, as a vector, if the command inquires which events were used to
269 invoke it. If KEYS is omitted or nil, the return value of
270 `this-command-keys-vector' is used. */)
271 (Lisp_Object function
, Lisp_Object record_flag
, Lisp_Object keys
)
273 /* `args' will contain the array of arguments to pass to the function.
274 `visargs' will contain the same list but in a nicer form, so that if we
275 pass it to Fformat_message it will be understandable to a human. */
276 Lisp_Object
*args
, *visargs
;
278 Lisp_Object filter_specs
;
280 Lisp_Object up_event
;
283 ptrdiff_t speccount
= SPECPDL_INDEX ();
285 /* The index of the next element of this_command_keys to examine for
286 the 'e' interactive code. */
287 ptrdiff_t next_event
;
289 Lisp_Object prefix_arg
;
293 /* If varies[i] > 0, the i'th argument shouldn't just have its value
294 in this call quoted in the command history. It should be
295 recorded as a call to the function named callint_argfuns[varies[i]]. */
300 bool arg_from_tty
= 0;
302 bool record_then_fail
= 0;
304 Lisp_Object save_this_command
, save_last_command
;
305 Lisp_Object save_this_original_command
, save_real_this_command
;
307 save_this_command
= Vthis_command
;
308 save_this_original_command
= Vthis_original_command
;
309 save_real_this_command
= Vreal_this_command
;
310 save_last_command
= KVAR (current_kboard
, Vlast_command
);
313 keys
= this_command_keys
, key_count
= this_command_key_count
;
317 key_count
= ASIZE (keys
);
320 /* Save this now, since use of minibuffer will clobber it. */
321 prefix_arg
= Vcurrent_prefix_arg
;
323 if (SYMBOLP (function
))
324 enable
= Fget (function
, Qenable_recursive_minibuffers
);
330 /* The idea of FILTER_SPECS is to provide a way to
331 specify how to represent the arguments in command history.
332 The feature is not fully implemented. */
335 /* If k or K discard an up-event, save it here so it can be retrieved with
339 /* Set SPECS to the interactive form, or barf if not interactive. */
342 form
= Finteractive_form (function
);
344 specs
= filter_specs
= Fcar (XCDR (form
));
346 wrong_type_argument (Qcommandp
, function
);
349 /* If SPECS is not a string, invent one. */
350 if (! STRINGP (specs
))
353 Lisp_Object funval
= Findirect_function (function
, Qt
);
354 uintmax_t events
= num_input_events
;
356 /* Compute the arg values using the user's expression. */
357 specs
= Feval (specs
,
358 CONSP (funval
) && EQ (Qclosure
, XCAR (funval
))
359 ? CAR_SAFE (XCDR (funval
)) : Qnil
);
360 if (events
!= num_input_events
|| !NILP (record_flag
))
362 /* We should record this command on the command history. */
364 Lisp_Object this_cmd
;
365 /* Make a copy of the list of values, for the command history,
366 and turn them into things we can eval. */
367 values
= quotify_args (Fcopy_sequence (specs
));
368 fix_command (input
, values
);
369 this_cmd
= Fcons (function
, values
);
370 if (history_delete_duplicates
)
371 Vcommand_history
= Fdelete (this_cmd
, Vcommand_history
);
372 Vcommand_history
= Fcons (this_cmd
, Vcommand_history
);
374 /* Don't keep command history around forever. */
375 if (INTEGERP (Vhistory_length
) && XINT (Vhistory_length
) > 0)
377 teml
= Fnthcdr (Vhistory_length
, Vcommand_history
);
379 XSETCDR (teml
, Qnil
);
383 Vthis_command
= save_this_command
;
384 Vthis_original_command
= save_this_original_command
;
385 Vreal_this_command
= save_real_this_command
;
386 kset_last_command (current_kboard
, save_last_command
);
389 = unbind_to (speccount
, CALLN (Fapply
, Qfuncall_interactively
,
395 /* SPECS is set to a string; use it as an interactive prompt.
396 Copy it so that STRING will be valid even if a GC relocates SPECS. */
397 SAFE_ALLOCA_STRING (string
, specs
);
399 /* Here if function specifies a string to control parsing the defaults. */
401 /* Set next_event to point to the first event with parameters. */
402 for (next_event
= 0; next_event
< key_count
; next_event
++)
403 if (EVENT_HAS_PARAMETERS (AREF (keys
, next_event
)))
406 /* Handle special starting chars `*' and `@'. Also `-'. */
407 /* Note that `+' is reserved for user extensions. */
411 error ("`+' is not used in `interactive' for ordinary commands");
412 else if (*string
== '*')
415 if (!NILP (BVAR (current_buffer
, read_only
)))
417 if (!NILP (record_flag
))
422 if (! (*p
== 'r' || *p
== 'p' || *p
== 'P'
424 Fbarf_if_buffer_read_only (Qnil
);
427 record_then_fail
= 1;
430 Fbarf_if_buffer_read_only (Qnil
);
433 /* Ignore this for semi-compatibility with Lucid. */
434 else if (*string
== '-')
436 else if (*string
== '@')
438 Lisp_Object event
, w
;
440 event
= (next_event
< key_count
441 ? AREF (keys
, next_event
)
443 if (EVENT_HAS_PARAMETERS (event
)
444 && (w
= XCDR (event
), CONSP (w
))
445 && (w
= XCAR (w
), CONSP (w
))
446 && (w
= XCAR (w
), WINDOWP (w
)))
448 if (MINI_WINDOW_P (XWINDOW (w
))
449 && ! (minibuf_level
> 0 && EQ (w
, minibuf_window
)))
450 error ("Attempt to select inactive minibuffer window");
452 /* If the current buffer wants to clean up, let it. */
453 run_hook (Qmouse_leave_buffer_hook
);
455 Fselect_window (w
, Qnil
);
459 else if (*string
== '^')
461 call0 (Qhandle_shift_selection
);
467 /* Count the number of arguments, which is two (the function itself and
468 `funcall-interactively') plus the number of arguments the interactive spec
469 would have us give to the function. */
471 for (nargs
= 2; *tem
; )
473 /* 'r' specifications ("point and mark as 2 numeric args")
474 produce *two* arguments. */
479 tem
= strchr (tem
, '\n');
486 if (MOST_POSITIVE_FIXNUM
< min (PTRDIFF_MAX
, SIZE_MAX
) / word_size
487 && MOST_POSITIVE_FIXNUM
< nargs
)
488 memory_full (SIZE_MAX
);
490 /* Allocate them all at one go. This wastes a bit of memory, but
491 it's OK to trade space for speed. */
492 SAFE_NALLOCA (args
, 3, nargs
);
493 visargs
= args
+ nargs
;
494 varies
= (signed char *) (visargs
+ nargs
);
496 memclear (args
, nargs
* (2 * word_size
+ 1));
499 specbind (Qenable_recursive_minibuffers
, Qt
);
502 for (i
= 2; *tem
; i
++)
504 visargs
[1] = make_string (tem
+ 1, strcspn (tem
+ 1, "\n"));
505 callint_message
= Fformat_message (i
- 1, visargs
+ 1);
509 case 'a': /* Symbol defined as a function. */
510 visargs
[i
] = Fcompleting_read (callint_message
,
511 Vobarray
, Qfboundp
, Qt
,
512 Qnil
, Qnil
, Qnil
, Qnil
);
513 /* Passing args[i] directly stimulates compiler bug. */
515 args
[i
] = Fintern (teml
, Qnil
);
518 case 'b': /* Name of existing buffer. */
519 args
[i
] = Fcurrent_buffer ();
520 if (EQ (selected_window
, minibuf_window
))
521 args
[i
] = Fother_buffer (args
[i
], Qnil
, Qnil
);
522 args
[i
] = Fread_buffer (callint_message
, args
[i
], Qt
, Qnil
);
525 case 'B': /* Name of buffer, possibly nonexistent. */
526 args
[i
] = Fread_buffer (callint_message
,
527 Fother_buffer (Fcurrent_buffer (), Qnil
, Qnil
),
531 case 'c': /* Character. */
532 /* Prompt in `minibuffer-prompt' face. */
533 Fput_text_property (make_number (0),
534 make_number (SCHARS (callint_message
)),
535 Qface
, Qminibuffer_prompt
, callint_message
);
536 args
[i
] = Fread_char (callint_message
, Qnil
, Qnil
);
538 /* Passing args[i] directly stimulates compiler bug. */
541 if (! CHARACTERP (teml
)) error ("Non-character input-event");
542 visargs
[i
] = Fchar_to_string (teml
);
545 case 'C': /* Command: symbol with interactive function. */
546 visargs
[i
] = Fcompleting_read (callint_message
,
548 Qt
, Qnil
, Qnil
, Qnil
, Qnil
);
549 /* Passing args[i] directly stimulates compiler bug. */
551 args
[i
] = Fintern (teml
, Qnil
);
554 case 'd': /* Value of point. Does not do I/O. */
555 set_marker_both (point_marker
, Qnil
, PT
, PT_BYTE
);
556 args
[i
] = point_marker
;
557 /* visargs[i] = Qnil; */
561 case 'D': /* Directory name. */
562 args
[i
] = read_file_name (BVAR (current_buffer
, directory
), Qlambda
, Qnil
,
566 case 'f': /* Existing file name. */
567 args
[i
] = read_file_name (Qnil
, Qlambda
, Qnil
, Qnil
);
570 case 'F': /* Possibly nonexistent file name. */
571 args
[i
] = read_file_name (Qnil
, Qnil
, Qnil
, Qnil
);
574 case 'G': /* Possibly nonexistent file name,
575 default to directory alone. */
576 args
[i
] = read_file_name (Qnil
, Qnil
, empty_unibyte_string
, Qnil
);
579 case 'i': /* Ignore an argument -- Does not do I/O. */
583 case 'k': /* Key sequence. */
585 ptrdiff_t speccount1
= SPECPDL_INDEX ();
586 specbind (Qcursor_in_echo_area
, Qt
);
587 /* Prompt in `minibuffer-prompt' face. */
588 Fput_text_property (make_number (0),
589 make_number (SCHARS (callint_message
)),
590 Qface
, Qminibuffer_prompt
, callint_message
);
591 args
[i
] = Fread_key_sequence (callint_message
,
592 Qnil
, Qnil
, Qnil
, Qnil
);
593 unbind_to (speccount1
, Qnil
);
595 visargs
[i
] = Fkey_description (teml
, Qnil
);
597 /* If the key sequence ends with a down-event,
598 discard the following up-event. */
599 teml
= Faref (args
[i
], make_number (XINT (Flength (args
[i
])) - 1));
606 teml
= Fget (teml
, Qevent_symbol_elements
);
607 /* Ignore first element, which is the base key. */
608 tem2
= Fmemq (Qdown
, Fcdr (teml
));
610 up_event
= Fread_event (Qnil
, Qnil
, Qnil
);
615 case 'K': /* Key sequence to be defined. */
617 ptrdiff_t speccount1
= SPECPDL_INDEX ();
618 specbind (Qcursor_in_echo_area
, Qt
);
619 /* Prompt in `minibuffer-prompt' face. */
620 Fput_text_property (make_number (0),
621 make_number (SCHARS (callint_message
)),
622 Qface
, Qminibuffer_prompt
, callint_message
);
623 args
[i
] = Fread_key_sequence_vector (callint_message
,
624 Qnil
, Qt
, Qnil
, Qnil
);
626 visargs
[i
] = Fkey_description (teml
, Qnil
);
627 unbind_to (speccount1
, Qnil
);
629 /* If the key sequence ends with a down-event,
630 discard the following up-event. */
631 teml
= Faref (args
[i
], make_number (XINT (Flength (args
[i
])) - 1));
638 teml
= Fget (teml
, Qevent_symbol_elements
);
639 /* Ignore first element, which is the base key. */
640 tem2
= Fmemq (Qdown
, Fcdr (teml
));
642 up_event
= Fread_event (Qnil
, Qnil
, Qnil
);
647 case 'U': /* Up event from last k or K. */
648 if (!NILP (up_event
))
650 args
[i
] = Fmake_vector (make_number (1), up_event
);
653 visargs
[i
] = Fkey_description (teml
, Qnil
);
657 case 'e': /* The invoking event. */
658 if (next_event
>= key_count
)
659 error ("%s must be bound to an event with parameters",
661 ? SSDATA (SYMBOL_NAME (function
))
663 args
[i
] = AREF (keys
, next_event
);
667 /* Find the next parameterized event. */
668 while (next_event
< key_count
669 && !(EVENT_HAS_PARAMETERS (AREF (keys
, next_event
))))
674 case 'm': /* Value of mark. Does not do I/O. */
676 /* visargs[i] = Qnil; */
677 args
[i
] = BVAR (current_buffer
, mark
);
681 case 'M': /* String read via minibuffer with
682 inheriting the current input method. */
683 args
[i
] = Fread_string (callint_message
,
684 Qnil
, Qnil
, Qnil
, Qt
);
687 case 'N': /* Prefix arg as number, else number from minibuffer. */
688 if (!NILP (prefix_arg
))
689 goto have_prefix_arg
;
691 case 'n': /* Read number from minibuffer. */
692 args
[i
] = call1 (Qread_number
, callint_message
);
693 /* Passing args[i] directly stimulates compiler bug. */
695 visargs
[i
] = Fnumber_to_string (teml
);
698 case 'P': /* Prefix arg in raw form. Does no I/O. */
699 args
[i
] = prefix_arg
;
700 /* visargs[i] = Qnil; */
704 case 'p': /* Prefix arg converted to number. No I/O. */
706 args
[i
] = Fprefix_numeric_value (prefix_arg
);
707 /* visargs[i] = Qnil; */
711 case 'r': /* Region, point and mark as 2 args. */
713 set_marker_both (point_marker
, Qnil
, PT
, PT_BYTE
);
714 /* visargs[i+1] = Qnil; */
715 mark
= marker_position (BVAR (current_buffer
, mark
));
716 /* visargs[i] = Qnil; */
717 args
[i
] = PT
< mark
? point_marker
: BVAR (current_buffer
, mark
);
719 args
[++i
] = PT
> mark
? point_marker
: BVAR (current_buffer
, mark
);
723 case 's': /* String read via minibuffer without
724 inheriting the current input method. */
725 args
[i
] = Fread_string (callint_message
,
726 Qnil
, Qnil
, Qnil
, Qnil
);
729 case 'S': /* Any symbol. */
730 visargs
[i
] = Fread_string (callint_message
,
731 Qnil
, Qnil
, Qnil
, Qnil
);
732 /* Passing args[i] directly stimulates compiler bug. */
734 args
[i
] = Fintern (teml
, Qnil
);
737 case 'v': /* Variable name: symbol that is
738 custom-variable-p. */
739 args
[i
] = Fread_variable (callint_message
, Qnil
);
740 visargs
[i
] = last_minibuf_string
;
743 case 'x': /* Lisp expression read but not evaluated. */
744 args
[i
] = call1 (intern ("read-minibuffer"), callint_message
);
745 visargs
[i
] = last_minibuf_string
;
748 case 'X': /* Lisp expression read and evaluated. */
749 args
[i
] = call1 (intern ("eval-minibuffer"), callint_message
);
750 visargs
[i
] = last_minibuf_string
;
753 case 'Z': /* Coding-system symbol, or ignore the
754 argument if no prefix. */
755 if (NILP (prefix_arg
))
757 /* args[i] = Qnil; */
763 = Fread_non_nil_coding_system (callint_message
);
764 visargs
[i
] = last_minibuf_string
;
768 case 'z': /* Coding-system symbol or nil. */
769 args
[i
] = Fread_coding_system (callint_message
, Qnil
);
770 visargs
[i
] = last_minibuf_string
;
773 /* We have a case for `+' so we get an error
774 if anyone tries to define one here. */
777 error ("Invalid control letter `%c' (#o%03o, #x%04x) in interactive calling string",
778 STRING_CHAR ((unsigned char *) tem
),
779 (unsigned) STRING_CHAR ((unsigned char *) tem
),
780 (unsigned) STRING_CHAR ((unsigned char *) tem
));
786 if (NILP (visargs
[i
]) && STRINGP (args
[i
]))
787 visargs
[i
] = args
[i
];
789 tem
= strchr (tem
, '\n');
793 unbind_to (speccount
, Qnil
);
797 args
[0] = Qfuncall_interactively
;
800 if (arg_from_tty
|| !NILP (record_flag
))
802 /* We don't need `visargs' any more, so let's recycle it since we need
803 an array of just the same size. */
804 visargs
[1] = function
;
805 for (i
= 2; i
< nargs
; i
++)
808 visargs
[i
] = list1 (intern (callint_argfuns
[varies
[i
]]));
810 visargs
[i
] = quotify_arg (args
[i
]);
812 Vcommand_history
= Fcons (Flist (nargs
- 1, visargs
+ 1),
814 /* Don't keep command history around forever. */
815 if (INTEGERP (Vhistory_length
) && XINT (Vhistory_length
) > 0)
817 teml
= Fnthcdr (Vhistory_length
, Vcommand_history
);
819 XSETCDR (teml
, Qnil
);
823 /* If we used a marker to hold point, mark, or an end of the region,
824 temporarily, convert it to an integer now. */
825 for (i
= 2; i
< nargs
; i
++)
826 if (varies
[i
] >= 1 && varies
[i
] <= 4)
827 XSETINT (args
[i
], marker_position (args
[i
]));
829 if (record_then_fail
)
830 Fbarf_if_buffer_read_only (Qnil
);
832 Vthis_command
= save_this_command
;
833 Vthis_original_command
= save_this_original_command
;
834 Vreal_this_command
= save_real_this_command
;
835 kset_last_command (current_kboard
, save_last_command
);
839 specbind (Qcommand_debug_status
, Qnil
);
841 val
= Ffuncall (nargs
, args
);
842 val
= unbind_to (speccount
, val
);
848 DEFUN ("prefix-numeric-value", Fprefix_numeric_value
, Sprefix_numeric_value
,
850 doc
: /* Return numeric meaning of raw prefix argument RAW.
851 A raw prefix argument is what you get from `(interactive "P")'.
852 Its numeric meaning is what you would get from `(interactive "p")'. */)
858 XSETFASTINT (val
, 1);
859 else if (EQ (raw
, Qminus
))
861 else if (CONSP (raw
) && INTEGERP (XCAR (raw
)))
862 XSETINT (val
, XINT (XCAR (raw
)));
863 else if (INTEGERP (raw
))
866 XSETFASTINT (val
, 1);
872 syms_of_callint (void)
874 point_marker
= Fmake_marker ();
875 staticpro (&point_marker
);
877 callint_message
= Qnil
;
878 staticpro (&callint_message
);
880 preserved_fns
= listn (CONSTYPE_PURE
, 4,
881 intern_c_string ("region-beginning"),
882 intern_c_string ("region-end"),
883 intern_c_string ("point"),
884 intern_c_string ("mark"));
886 DEFSYM (Qlist
, "list");
887 DEFSYM (Qlet
, "let");
889 DEFSYM (Qwhen
, "when");
890 DEFSYM (Qletx
, "let*");
891 DEFSYM (Qsave_excursion
, "save-excursion");
892 DEFSYM (Qprogn
, "progn");
893 DEFSYM (Qminus
, "-");
895 DEFSYM (Qhandle_shift_selection
, "handle-shift-selection");
896 DEFSYM (Qread_number
, "read-number");
897 DEFSYM (Qfuncall_interactively
, "funcall-interactively");
898 DEFSYM (Qcommand_debug_status
, "command-debug-status");
899 DEFSYM (Qenable_recursive_minibuffers
, "enable-recursive-minibuffers");
900 DEFSYM (Qmouse_leave_buffer_hook
, "mouse-leave-buffer-hook");
902 DEFVAR_KBOARD ("prefix-arg", Vprefix_arg
,
903 doc
: /* The value of the prefix argument for the next editing command.
904 It may be a number, or the symbol `-' for just a minus sign as arg,
905 or a list whose car is a number for just one or more C-u's
906 or nil if no argument has been specified.
908 You cannot examine this variable to find the argument for this command
909 since it has been set to nil by the time you can look.
910 Instead, you should use the variable `current-prefix-arg', although
911 normally commands can get this prefix argument with (interactive "P"). */);
913 DEFVAR_KBOARD ("last-prefix-arg", Vlast_prefix_arg
,
914 doc
: /* The value of the prefix argument for the previous editing command.
915 See `prefix-arg' for the meaning of the value. */);
917 DEFVAR_LISP ("current-prefix-arg", Vcurrent_prefix_arg
,
918 doc
: /* The value of the prefix argument for this editing command.
919 It may be a number, or the symbol `-' for just a minus sign as arg,
920 or a list whose car is a number for just one or more C-u's
921 or nil if no argument has been specified.
922 This is what `(interactive \"P\")' returns. */);
923 Vcurrent_prefix_arg
= Qnil
;
925 DEFVAR_LISP ("command-history", Vcommand_history
,
926 doc
: /* List of recent commands that read arguments from terminal.
927 Each command is represented as a form to evaluate.
929 Maximum length of the history list is determined by the value
930 of `history-length', which see. */);
931 Vcommand_history
= Qnil
;
933 DEFVAR_LISP ("command-debug-status", Vcommand_debug_status
,
934 doc
: /* Debugging status of current interactive command.
935 Bound each time `call-interactively' is called;
936 may be set by the debugger as a reminder for itself. */);
937 Vcommand_debug_status
= Qnil
;
939 DEFVAR_LISP ("mark-even-if-inactive", Vmark_even_if_inactive
,
940 doc
: /* Non-nil means you can use the mark even when inactive.
941 This option makes a difference in Transient Mark mode.
942 When the option is non-nil, deactivation of the mark
943 turns off region highlighting, but commands that use the mark
944 behave as if the mark were still active. */);
945 Vmark_even_if_inactive
= Qt
;
947 DEFVAR_LISP ("mouse-leave-buffer-hook", Vmouse_leave_buffer_hook
,
948 doc
: /* Hook to run when about to switch windows with a mouse command.
949 Its purpose is to give temporary modes such as Isearch mode
950 a way to turn themselves off when a mouse command switches windows. */);
951 Vmouse_leave_buffer_hook
= Qnil
;
953 defsubr (&Sinteractive
);
954 defsubr (&Scall_interactively
);
955 defsubr (&Sfuncall_interactively
);
956 defsubr (&Sprefix_numeric_value
);