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 <http://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 if (strchr (SSDATA (visargs
[1]), '%'))
506 callint_message
= Fformat_message (i
- 1, visargs
+ 1);
508 callint_message
= visargs
[1];
512 case 'a': /* Symbol defined as a function. */
513 visargs
[i
] = Fcompleting_read (callint_message
,
514 Vobarray
, Qfboundp
, Qt
,
515 Qnil
, Qnil
, Qnil
, Qnil
);
516 /* Passing args[i] directly stimulates compiler bug. */
518 args
[i
] = Fintern (teml
, Qnil
);
521 case 'b': /* Name of existing buffer. */
522 args
[i
] = Fcurrent_buffer ();
523 if (EQ (selected_window
, minibuf_window
))
524 args
[i
] = Fother_buffer (args
[i
], Qnil
, Qnil
);
525 args
[i
] = Fread_buffer (callint_message
, args
[i
], Qt
, Qnil
);
528 case 'B': /* Name of buffer, possibly nonexistent. */
529 args
[i
] = Fread_buffer (callint_message
,
530 Fother_buffer (Fcurrent_buffer (), Qnil
, Qnil
),
534 case 'c': /* Character. */
535 /* Prompt in `minibuffer-prompt' face. */
536 Fput_text_property (make_number (0),
537 make_number (SCHARS (callint_message
)),
538 Qface
, Qminibuffer_prompt
, callint_message
);
539 args
[i
] = Fread_char (callint_message
, Qnil
, Qnil
);
541 /* Passing args[i] directly stimulates compiler bug. */
544 if (! CHARACTERP (teml
)) error ("Non-character input-event");
545 visargs
[i
] = Fchar_to_string (teml
);
548 case 'C': /* Command: symbol with interactive function. */
549 visargs
[i
] = Fcompleting_read (callint_message
,
551 Qt
, Qnil
, Qnil
, Qnil
, Qnil
);
552 /* Passing args[i] directly stimulates compiler bug. */
554 args
[i
] = Fintern (teml
, Qnil
);
557 case 'd': /* Value of point. Does not do I/O. */
558 set_marker_both (point_marker
, Qnil
, PT
, PT_BYTE
);
559 args
[i
] = point_marker
;
560 /* visargs[i] = Qnil; */
564 case 'D': /* Directory name. */
565 args
[i
] = read_file_name (BVAR (current_buffer
, directory
), Qlambda
, Qnil
,
569 case 'f': /* Existing file name. */
570 args
[i
] = read_file_name (Qnil
, Qlambda
, Qnil
, Qnil
);
573 case 'F': /* Possibly nonexistent file name. */
574 args
[i
] = read_file_name (Qnil
, Qnil
, Qnil
, Qnil
);
577 case 'G': /* Possibly nonexistent file name,
578 default to directory alone. */
579 args
[i
] = read_file_name (Qnil
, Qnil
, empty_unibyte_string
, Qnil
);
582 case 'i': /* Ignore an argument -- Does not do I/O. */
586 case 'k': /* Key sequence. */
588 ptrdiff_t speccount1
= SPECPDL_INDEX ();
589 specbind (Qcursor_in_echo_area
, Qt
);
590 /* Prompt in `minibuffer-prompt' face. */
591 Fput_text_property (make_number (0),
592 make_number (SCHARS (callint_message
)),
593 Qface
, Qminibuffer_prompt
, callint_message
);
594 args
[i
] = Fread_key_sequence (callint_message
,
595 Qnil
, Qnil
, Qnil
, Qnil
);
596 unbind_to (speccount1
, Qnil
);
598 visargs
[i
] = Fkey_description (teml
, Qnil
);
600 /* If the key sequence ends with a down-event,
601 discard the following up-event. */
602 teml
= Faref (args
[i
], make_number (XINT (Flength (args
[i
])) - 1));
609 teml
= Fget (teml
, Qevent_symbol_elements
);
610 /* Ignore first element, which is the base key. */
611 tem2
= Fmemq (Qdown
, Fcdr (teml
));
613 up_event
= Fread_event (Qnil
, Qnil
, Qnil
);
618 case 'K': /* Key sequence to be defined. */
620 ptrdiff_t speccount1
= SPECPDL_INDEX ();
621 specbind (Qcursor_in_echo_area
, Qt
);
622 /* Prompt in `minibuffer-prompt' face. */
623 Fput_text_property (make_number (0),
624 make_number (SCHARS (callint_message
)),
625 Qface
, Qminibuffer_prompt
, callint_message
);
626 args
[i
] = Fread_key_sequence_vector (callint_message
,
627 Qnil
, Qt
, Qnil
, Qnil
);
629 visargs
[i
] = Fkey_description (teml
, Qnil
);
630 unbind_to (speccount1
, Qnil
);
632 /* If the key sequence ends with a down-event,
633 discard the following up-event. */
634 teml
= Faref (args
[i
], make_number (XINT (Flength (args
[i
])) - 1));
641 teml
= Fget (teml
, Qevent_symbol_elements
);
642 /* Ignore first element, which is the base key. */
643 tem2
= Fmemq (Qdown
, Fcdr (teml
));
645 up_event
= Fread_event (Qnil
, Qnil
, Qnil
);
650 case 'U': /* Up event from last k or K. */
651 if (!NILP (up_event
))
653 args
[i
] = Fmake_vector (make_number (1), up_event
);
656 visargs
[i
] = Fkey_description (teml
, Qnil
);
660 case 'e': /* The invoking event. */
661 if (next_event
>= key_count
)
662 error ("%s must be bound to an event with parameters",
664 ? SSDATA (SYMBOL_NAME (function
))
666 args
[i
] = AREF (keys
, next_event
);
670 /* Find the next parameterized event. */
671 while (next_event
< key_count
672 && !(EVENT_HAS_PARAMETERS (AREF (keys
, next_event
))))
677 case 'm': /* Value of mark. Does not do I/O. */
679 /* visargs[i] = Qnil; */
680 args
[i
] = BVAR (current_buffer
, mark
);
684 case 'M': /* String read via minibuffer with
685 inheriting the current input method. */
686 args
[i
] = Fread_string (callint_message
,
687 Qnil
, Qnil
, Qnil
, Qt
);
690 case 'N': /* Prefix arg as number, else number from minibuffer. */
691 if (!NILP (prefix_arg
))
692 goto have_prefix_arg
;
694 case 'n': /* Read number from minibuffer. */
695 args
[i
] = call1 (Qread_number
, callint_message
);
696 /* Passing args[i] directly stimulates compiler bug. */
698 visargs
[i
] = Fnumber_to_string (teml
);
701 case 'P': /* Prefix arg in raw form. Does no I/O. */
702 args
[i
] = prefix_arg
;
703 /* visargs[i] = Qnil; */
707 case 'p': /* Prefix arg converted to number. No I/O. */
709 args
[i
] = Fprefix_numeric_value (prefix_arg
);
710 /* visargs[i] = Qnil; */
714 case 'r': /* Region, point and mark as 2 args. */
716 set_marker_both (point_marker
, Qnil
, PT
, PT_BYTE
);
717 /* visargs[i+1] = Qnil; */
718 mark
= marker_position (BVAR (current_buffer
, mark
));
719 /* visargs[i] = Qnil; */
720 args
[i
] = PT
< mark
? point_marker
: BVAR (current_buffer
, mark
);
722 args
[++i
] = PT
> mark
? point_marker
: BVAR (current_buffer
, mark
);
726 case 's': /* String read via minibuffer without
727 inheriting the current input method. */
728 args
[i
] = Fread_string (callint_message
,
729 Qnil
, Qnil
, Qnil
, Qnil
);
732 case 'S': /* Any symbol. */
733 visargs
[i
] = Fread_string (callint_message
,
734 Qnil
, Qnil
, Qnil
, Qnil
);
735 /* Passing args[i] directly stimulates compiler bug. */
737 args
[i
] = Fintern (teml
, Qnil
);
740 case 'v': /* Variable name: symbol that is
741 custom-variable-p. */
742 args
[i
] = Fread_variable (callint_message
, Qnil
);
743 visargs
[i
] = last_minibuf_string
;
746 case 'x': /* Lisp expression read but not evaluated. */
747 args
[i
] = call1 (intern ("read-minibuffer"), callint_message
);
748 visargs
[i
] = last_minibuf_string
;
751 case 'X': /* Lisp expression read and evaluated. */
752 args
[i
] = call1 (intern ("eval-minibuffer"), callint_message
);
753 visargs
[i
] = last_minibuf_string
;
756 case 'Z': /* Coding-system symbol, or ignore the
757 argument if no prefix. */
758 if (NILP (prefix_arg
))
760 /* args[i] = Qnil; */
766 = Fread_non_nil_coding_system (callint_message
);
767 visargs
[i
] = last_minibuf_string
;
771 case 'z': /* Coding-system symbol or nil. */
772 args
[i
] = Fread_coding_system (callint_message
, Qnil
);
773 visargs
[i
] = last_minibuf_string
;
776 /* We have a case for `+' so we get an error
777 if anyone tries to define one here. */
780 error ("Invalid control letter `%c' (#o%03o, #x%04x) in interactive calling string",
781 STRING_CHAR ((unsigned char *) tem
),
782 (unsigned) STRING_CHAR ((unsigned char *) tem
),
783 (unsigned) STRING_CHAR ((unsigned char *) tem
));
789 if (NILP (visargs
[i
]) && STRINGP (args
[i
]))
790 visargs
[i
] = args
[i
];
792 tem
= strchr (tem
, '\n');
796 unbind_to (speccount
, Qnil
);
800 args
[0] = Qfuncall_interactively
;
803 if (arg_from_tty
|| !NILP (record_flag
))
805 /* We don't need `visargs' any more, so let's recycle it since we need
806 an array of just the same size. */
807 visargs
[1] = function
;
808 for (i
= 2; i
< nargs
; i
++)
811 visargs
[i
] = list1 (intern (callint_argfuns
[varies
[i
]]));
813 visargs
[i
] = quotify_arg (args
[i
]);
815 Vcommand_history
= Fcons (Flist (nargs
- 1, visargs
+ 1),
817 /* Don't keep command history around forever. */
818 if (INTEGERP (Vhistory_length
) && XINT (Vhistory_length
) > 0)
820 teml
= Fnthcdr (Vhistory_length
, Vcommand_history
);
822 XSETCDR (teml
, Qnil
);
826 /* If we used a marker to hold point, mark, or an end of the region,
827 temporarily, convert it to an integer now. */
828 for (i
= 2; i
< nargs
; i
++)
829 if (varies
[i
] >= 1 && varies
[i
] <= 4)
830 XSETINT (args
[i
], marker_position (args
[i
]));
832 if (record_then_fail
)
833 Fbarf_if_buffer_read_only (Qnil
);
835 Vthis_command
= save_this_command
;
836 Vthis_original_command
= save_this_original_command
;
837 Vreal_this_command
= save_real_this_command
;
838 kset_last_command (current_kboard
, save_last_command
);
842 specbind (Qcommand_debug_status
, Qnil
);
844 val
= Ffuncall (nargs
, args
);
845 val
= unbind_to (speccount
, val
);
851 DEFUN ("prefix-numeric-value", Fprefix_numeric_value
, Sprefix_numeric_value
,
853 doc
: /* Return numeric meaning of raw prefix argument RAW.
854 A raw prefix argument is what you get from `(interactive "P")'.
855 Its numeric meaning is what you would get from `(interactive "p")'. */)
861 XSETFASTINT (val
, 1);
862 else if (EQ (raw
, Qminus
))
864 else if (CONSP (raw
) && INTEGERP (XCAR (raw
)))
865 XSETINT (val
, XINT (XCAR (raw
)));
866 else if (INTEGERP (raw
))
869 XSETFASTINT (val
, 1);
875 syms_of_callint (void)
877 point_marker
= Fmake_marker ();
878 staticpro (&point_marker
);
880 callint_message
= Qnil
;
881 staticpro (&callint_message
);
883 preserved_fns
= listn (CONSTYPE_PURE
, 4,
884 intern_c_string ("region-beginning"),
885 intern_c_string ("region-end"),
886 intern_c_string ("point"),
887 intern_c_string ("mark"));
889 DEFSYM (Qlist
, "list");
890 DEFSYM (Qlet
, "let");
892 DEFSYM (Qwhen
, "when");
893 DEFSYM (Qletx
, "let*");
894 DEFSYM (Qsave_excursion
, "save-excursion");
895 DEFSYM (Qprogn
, "progn");
896 DEFSYM (Qminus
, "-");
898 DEFSYM (Qhandle_shift_selection
, "handle-shift-selection");
899 DEFSYM (Qread_number
, "read-number");
900 DEFSYM (Qfuncall_interactively
, "funcall-interactively");
901 DEFSYM (Qcommand_debug_status
, "command-debug-status");
902 DEFSYM (Qenable_recursive_minibuffers
, "enable-recursive-minibuffers");
903 DEFSYM (Qmouse_leave_buffer_hook
, "mouse-leave-buffer-hook");
905 DEFVAR_KBOARD ("prefix-arg", Vprefix_arg
,
906 doc
: /* The value of the prefix argument for the next editing command.
907 It may be a number, or the symbol `-' for just a minus sign as arg,
908 or a list whose car is a number for just one or more C-u's
909 or nil if no argument has been specified.
911 You cannot examine this variable to find the argument for this command
912 since it has been set to nil by the time you can look.
913 Instead, you should use the variable `current-prefix-arg', although
914 normally commands can get this prefix argument with (interactive "P"). */);
916 DEFVAR_KBOARD ("last-prefix-arg", Vlast_prefix_arg
,
917 doc
: /* The value of the prefix argument for the previous editing command.
918 See `prefix-arg' for the meaning of the value. */);
920 DEFVAR_LISP ("current-prefix-arg", Vcurrent_prefix_arg
,
921 doc
: /* The value of the prefix argument for this editing command.
922 It may be a number, or the symbol `-' for just a minus sign as arg,
923 or a list whose car is a number for just one or more C-u's
924 or nil if no argument has been specified.
925 This is what `(interactive \"P\")' returns. */);
926 Vcurrent_prefix_arg
= Qnil
;
928 DEFVAR_LISP ("command-history", Vcommand_history
,
929 doc
: /* List of recent commands that read arguments from terminal.
930 Each command is represented as a form to evaluate.
932 Maximum length of the history list is determined by the value
933 of `history-length', which see. */);
934 Vcommand_history
= Qnil
;
936 DEFVAR_LISP ("command-debug-status", Vcommand_debug_status
,
937 doc
: /* Debugging status of current interactive command.
938 Bound each time `call-interactively' is called;
939 may be set by the debugger as a reminder for itself. */);
940 Vcommand_debug_status
= Qnil
;
942 DEFVAR_LISP ("mark-even-if-inactive", Vmark_even_if_inactive
,
943 doc
: /* Non-nil means you can use the mark even when inactive.
944 This option makes a difference in Transient Mark mode.
945 When the option is non-nil, deactivation of the mark
946 turns off region highlighting, but commands that use the mark
947 behave as if the mark were still active. */);
948 Vmark_even_if_inactive
= Qt
;
950 DEFVAR_LISP ("mouse-leave-buffer-hook", Vmouse_leave_buffer_hook
,
951 doc
: /* Hook to run when about to switch windows with a mouse command.
952 Its purpose is to give temporary modes such as Isearch mode
953 a way to turn themselves off when a mouse command switches windows. */);
954 Vmouse_leave_buffer_hook
= Qnil
;
956 defsubr (&Sinteractive
);
957 defsubr (&Scall_interactively
);
958 defsubr (&Sfuncall_interactively
);
959 defsubr (&Sprefix_numeric_value
);