1 /* Call a Lisp function interactively.
2 Copyright (C) 1985-1986, 1993-1995, 1997, 2000-2015 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
10 (at 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"
31 static Lisp_Object preserved_fns
;
33 /* Marker used within call-interactively to refer to point. */
34 static Lisp_Object point_marker
;
36 /* String for the prompt text used in Fcall_interactively. */
37 static Lisp_Object callint_message
;
40 DEFUN ("interactive", Finteractive
, Sinteractive
, 0, UNEVALLED
, 0,
41 doc
: /* Specify a way of parsing arguments for interactive use of a function.
43 (defun foo (arg buf) "Doc string" (interactive "P\\nbbuffer: ") .... )
44 to make ARG be the raw prefix argument, and set BUF to an existing buffer,
45 when `foo' is called as a command.
46 The "call" to `interactive' is actually a declaration rather than a function;
47 it tells `call-interactively' how to read arguments
48 to pass to the function.
49 When actually called, `interactive' just returns nil.
51 Usually the argument of `interactive' is a string containing a code letter
52 followed optionally by a prompt. (Some code letters do not use I/O to get
53 the argument and do not use prompts.) To get several arguments, concatenate
54 the individual strings, separating them by newline characters.
55 Prompts are passed to format, and may use % escapes to print the
56 arguments that have already been read.
57 If the argument is not a string, it is evaluated to get a list of
58 arguments to pass to the function.
59 Just `(interactive)' means pass no args when calling interactively.
61 Code letters available are:
62 a -- Function name: symbol with a function definition.
63 b -- Name of existing buffer.
64 B -- Name of buffer, possibly nonexistent.
65 c -- Character (no input method is used).
66 C -- Command name: symbol with interactive function definition.
67 d -- Value of point as number. Does not do I/O.
69 e -- Parameterized event (i.e., one that's a list) that invoked this command.
70 If used more than once, the Nth `e' returns the Nth parameterized event.
71 This skips events that are integers or symbols.
72 f -- Existing file name.
73 F -- Possibly nonexistent file name.
74 G -- Possibly nonexistent file name, defaulting to just directory name.
75 i -- Ignored, i.e. always nil. Does not do I/O.
76 k -- Key sequence (downcase the last event if needed to get a definition).
77 K -- Key sequence to be redefined (do not downcase the last event).
78 m -- Value of mark as number. Does not do I/O.
79 M -- Any string. Inherits the current input method.
80 n -- Number read using minibuffer.
81 N -- Numeric prefix arg, or if none, do like code `n'.
82 p -- Prefix arg converted to number. Does not do I/O.
83 P -- Prefix arg in raw form. Does not do I/O.
84 r -- Region: point and mark as 2 numeric args, smallest first. Does no I/O.
85 s -- Any string. Does not inherit the current input method.
87 U -- Mouse up event discarded by a previous k or K argument.
88 v -- Variable name: symbol that is `custom-variable-p'.
89 x -- Lisp expression read but not evaluated.
90 X -- Lisp expression read and evaluated.
92 Z -- Coding system, nil if no prefix arg.
94 In addition, if the string begins with `*', an error is signaled if
95 the buffer is read-only.
96 If `@' appears at the beginning of the string, and if the key sequence
97 used to invoke the command includes any mouse events, then the window
98 associated with the first of those events is selected before the
100 If the string begins with `^' and `shift-select-mode' is non-nil,
101 Emacs first calls the function `handle-shift-selection'.
102 You may use `@', `*', and `^' together. They are processed in the
103 order that they appear, before reading any arguments.
104 usage: (interactive &optional ARGS) */
111 /* Quotify EXP: if EXP is constant, return it.
112 If EXP is not constant, return (quote EXP). */
114 quotify_arg (register Lisp_Object exp
)
118 && !NILP (exp
) && !EQ (exp
, Qt
)))
119 return list2 (Qquote
, exp
);
124 /* Modify EXP by quotifying each element (except the first). */
126 quotify_args (Lisp_Object exp
)
128 register Lisp_Object tail
;
130 for (tail
= exp
; CONSP (tail
); tail
= next
)
133 XSETCAR (tail
, quotify_arg (XCAR (tail
)));
138 static const char *callint_argfuns
[]
139 = {"", "point", "mark", "region-beginning", "region-end"};
142 check_mark (bool for_region
)
145 tem
= Fmarker_buffer (BVAR (current_buffer
, mark
));
146 if (NILP (tem
) || (XBUFFER (tem
) != current_buffer
))
147 error (for_region
? "The mark is not set now, so there is no region"
148 : "The mark is not set now");
149 if (!NILP (Vtransient_mark_mode
) && NILP (Vmark_even_if_inactive
)
150 && NILP (BVAR (current_buffer
, mark_active
)))
151 xsignal0 (Qmark_inactive
);
154 /* If the list of args INPUT was produced with an explicit call to
155 `list', look for elements that were computed with
156 (region-beginning) or (region-end), and put those expressions into
157 VALUES instead of the present values.
159 This function doesn't return a value because it modifies elements
160 of VALUES to do its job. */
163 fix_command (Lisp_Object input
, Lisp_Object values
)
165 /* FIXME: Instead of this ugly hack, we should provide a way for an
166 interactive spec to return an expression/function that will re-build the
167 args without user intervention. */
173 /* Skip through certain special forms. */
174 while (EQ (car
, Qlet
) || EQ (car
, Qletx
)
175 || EQ (car
, Qsave_excursion
)
178 while (CONSP (XCDR (input
)))
179 input
= XCDR (input
);
180 input
= XCAR (input
);
187 Lisp_Object intail
, valtail
;
188 for (intail
= Fcdr (input
), valtail
= values
;
190 intail
= Fcdr (intail
), valtail
= XCDR (valtail
))
196 Lisp_Object presflag
, carelt
;
198 /* If it is (if X Y), look at Y. */
200 && EQ (Fnthcdr (make_number (3), elt
), Qnil
))
201 elt
= Fnth (make_number (2), elt
);
202 /* If it is (when ... Y), look at Y. */
203 else if (EQ (carelt
, Qwhen
))
205 while (CONSP (XCDR (elt
)))
210 /* If the function call we're looking at
211 is a special preserved one, copy the
212 whole expression for this argument. */
215 presflag
= Fmemq (Fcar (elt
), preserved_fns
);
216 if (!NILP (presflag
))
217 Fsetcar (valtail
, Fcar (intail
));
225 /* Helper function to call `read-file-name' from C. */
228 read_file_name (Lisp_Object default_filename
, Lisp_Object mustmatch
,
229 Lisp_Object initial
, Lisp_Object predicate
)
234 GCPRO1 (default_filename
);
235 args
[0] = intern ("read-file-name");
236 args
[1] = callint_message
;
238 args
[3] = default_filename
;
242 RETURN_UNGCPRO (Ffuncall (7, args
));
245 /* BEWARE: Calling this directly from C would defeat the purpose! */
246 DEFUN ("funcall-interactively", Ffuncall_interactively
, Sfuncall_interactively
,
247 1, MANY
, 0, doc
: /* Like `funcall' but marks the call as interactive.
248 I.e. arrange that within the called function `called-interactively-p' will
250 usage: (funcall-interactively FUNCTION &rest ARGUMENTS) */)
251 (ptrdiff_t nargs
, Lisp_Object
*args
)
253 ptrdiff_t speccount
= SPECPDL_INDEX ();
254 temporarily_switch_to_single_kboard (NULL
);
256 /* Nothing special to do here, all the work is inside
257 `called-interactively-p'. Which will look for us as a marker in the
259 return unbind_to (speccount
, Ffuncall (nargs
, args
));
262 DEFUN ("call-interactively", Fcall_interactively
, Scall_interactively
, 1, 3, 0,
263 doc
: /* Call FUNCTION, providing args according to its interactive calling specs.
264 Return the value FUNCTION returns.
265 The function contains a specification of how to do the argument reading.
266 In the case of user-defined functions, this is specified by placing a call
267 to the function `interactive' at the top level of the function body.
270 Optional second arg RECORD-FLAG non-nil
271 means unconditionally put this command in the command-history.
272 Otherwise, this is done only if an arg is read using the minibuffer.
274 Optional third arg KEYS, if given, specifies the sequence of events to
275 supply, as a vector, if the command inquires which events were used to
276 invoke it. If KEYS is omitted or nil, the return value of
277 `this-command-keys-vector' is used. */)
278 (Lisp_Object function
, Lisp_Object record_flag
, Lisp_Object keys
)
280 /* `args' will contain the array of arguments to pass to the function.
281 `visargs' will contain the same list but in a nicer form, so that if we
282 pass it to `Fformat' it will be understandable to a human. */
283 Lisp_Object
*args
, *visargs
;
285 Lisp_Object filter_specs
;
287 Lisp_Object up_event
;
290 ptrdiff_t speccount
= SPECPDL_INDEX ();
292 /* The index of the next element of this_command_keys to examine for
293 the 'e' interactive code. */
294 ptrdiff_t next_event
;
296 Lisp_Object prefix_arg
;
300 /* If varies[i] > 0, the i'th argument shouldn't just have its value
301 in this call quoted in the command history. It should be
302 recorded as a call to the function named callint_argfuns[varies[i]]. */
307 bool arg_from_tty
= 0;
308 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
310 bool record_then_fail
= 0;
312 Lisp_Object save_this_command
, save_last_command
;
313 Lisp_Object save_this_original_command
, save_real_this_command
;
315 save_this_command
= Vthis_command
;
316 save_this_original_command
= Vthis_original_command
;
317 save_real_this_command
= Vreal_this_command
;
318 save_last_command
= KVAR (current_kboard
, Vlast_command
);
321 keys
= this_command_keys
, key_count
= this_command_key_count
;
325 key_count
= ASIZE (keys
);
328 /* Save this now, since use of minibuffer will clobber it. */
329 prefix_arg
= Vcurrent_prefix_arg
;
331 if (SYMBOLP (function
))
332 enable
= Fget (function
, Qenable_recursive_minibuffers
);
338 /* The idea of FILTER_SPECS is to provide a way to
339 specify how to represent the arguments in command history.
340 The feature is not fully implemented. */
343 /* If k or K discard an up-event, save it here so it can be retrieved with
347 /* Set SPECS to the interactive form, or barf if not interactive. */
350 GCPRO2 (function
, prefix_arg
);
351 form
= Finteractive_form (function
);
354 specs
= filter_specs
= Fcar (XCDR (form
));
356 wrong_type_argument (Qcommandp
, function
);
359 /* If SPECS is not a string, invent one. */
360 if (! STRINGP (specs
))
363 Lisp_Object funval
= Findirect_function (function
, Qt
);
364 uintmax_t events
= num_input_events
;
366 /* Compute the arg values using the user's expression. */
367 GCPRO2 (input
, filter_specs
);
368 specs
= Feval (specs
,
369 CONSP (funval
) && EQ (Qclosure
, XCAR (funval
))
370 ? CAR_SAFE (XCDR (funval
)) : Qnil
);
372 if (events
!= num_input_events
|| !NILP (record_flag
))
374 /* We should record this command on the command history. */
376 Lisp_Object this_cmd
;
377 /* Make a copy of the list of values, for the command history,
378 and turn them into things we can eval. */
379 values
= quotify_args (Fcopy_sequence (specs
));
380 fix_command (input
, values
);
381 this_cmd
= Fcons (function
, values
);
382 if (history_delete_duplicates
)
383 Vcommand_history
= Fdelete (this_cmd
, Vcommand_history
);
384 Vcommand_history
= Fcons (this_cmd
, Vcommand_history
);
386 /* Don't keep command history around forever. */
387 if (INTEGERP (Vhistory_length
) && XINT (Vhistory_length
) > 0)
389 teml
= Fnthcdr (Vhistory_length
, Vcommand_history
);
391 XSETCDR (teml
, Qnil
);
395 Vthis_command
= save_this_command
;
396 Vthis_original_command
= save_this_original_command
;
397 Vreal_this_command
= save_real_this_command
;
398 kset_last_command (current_kboard
, save_last_command
);
402 args
[0] = Qfuncall_interactively
;
405 Lisp_Object result
= unbind_to (speccount
, Fapply (3, args
));
411 /* SPECS is set to a string; use it as an interactive prompt.
412 Copy it so that STRING will be valid even if a GC relocates SPECS. */
413 SAFE_ALLOCA_STRING (string
, specs
);
415 /* Here if function specifies a string to control parsing the defaults. */
417 /* Set next_event to point to the first event with parameters. */
418 for (next_event
= 0; next_event
< key_count
; next_event
++)
419 if (EVENT_HAS_PARAMETERS (AREF (keys
, next_event
)))
422 /* Handle special starting chars `*' and `@'. Also `-'. */
423 /* Note that `+' is reserved for user extensions. */
427 error ("`+' is not used in `interactive' for ordinary commands");
428 else if (*string
== '*')
431 if (!NILP (BVAR (current_buffer
, read_only
)))
433 if (!NILP (record_flag
))
438 if (! (*p
== 'r' || *p
== 'p' || *p
== 'P'
440 Fbarf_if_buffer_read_only (Qnil
);
443 record_then_fail
= 1;
446 Fbarf_if_buffer_read_only (Qnil
);
449 /* Ignore this for semi-compatibility with Lucid. */
450 else if (*string
== '-')
452 else if (*string
== '@')
454 Lisp_Object event
, w
;
456 event
= (next_event
< key_count
457 ? AREF (keys
, next_event
)
459 if (EVENT_HAS_PARAMETERS (event
)
460 && (w
= XCDR (event
), CONSP (w
))
461 && (w
= XCAR (w
), CONSP (w
))
462 && (w
= XCAR (w
), WINDOWP (w
)))
464 if (MINI_WINDOW_P (XWINDOW (w
))
465 && ! (minibuf_level
> 0 && EQ (w
, minibuf_window
)))
466 error ("Attempt to select inactive minibuffer window");
468 /* If the current buffer wants to clean up, let it. */
469 run_hook (Qmouse_leave_buffer_hook
);
471 Fselect_window (w
, Qnil
);
475 else if (*string
== '^')
477 call0 (Qhandle_shift_selection
);
483 /* Count the number of arguments, which is two (the function itself and
484 `funcall-interactively') plus the number of arguments the interactive spec
485 would have us give to the function. */
487 for (nargs
= 2; *tem
; )
489 /* 'r' specifications ("point and mark as 2 numeric args")
490 produce *two* arguments. */
495 tem
= strchr (tem
, '\n');
502 if (MOST_POSITIVE_FIXNUM
< min (PTRDIFF_MAX
, SIZE_MAX
) / word_size
503 && MOST_POSITIVE_FIXNUM
< nargs
)
504 memory_full (SIZE_MAX
);
506 /* Allocate them all at one go. This wastes a bit of memory, but
507 it's OK to trade space for speed. */
508 SAFE_NALLOCA (args
, 3, nargs
);
509 visargs
= args
+ nargs
;
510 varies
= (signed char *) (visargs
+ nargs
);
512 for (i
= 0; i
< nargs
; i
++)
519 GCPRO5 (prefix_arg
, function
, *args
, *visargs
, up_event
);
520 gcpro3
.nvars
= nargs
;
521 gcpro4
.nvars
= nargs
;
524 specbind (Qenable_recursive_minibuffers
, Qt
);
527 for (i
= 2; *tem
; i
++)
529 visargs
[1] = make_string (tem
+ 1, strcspn (tem
+ 1, "\n"));
530 if (strchr (SSDATA (visargs
[1]), '%'))
531 callint_message
= Fformat (i
- 1, visargs
+ 1);
533 callint_message
= visargs
[1];
537 case 'a': /* Symbol defined as a function. */
538 visargs
[i
] = Fcompleting_read (callint_message
,
539 Vobarray
, Qfboundp
, Qt
,
540 Qnil
, Qnil
, Qnil
, Qnil
);
541 /* Passing args[i] directly stimulates compiler bug. */
543 args
[i
] = Fintern (teml
, Qnil
);
546 case 'b': /* Name of existing buffer. */
547 args
[i
] = Fcurrent_buffer ();
548 if (EQ (selected_window
, minibuf_window
))
549 args
[i
] = Fother_buffer (args
[i
], Qnil
, Qnil
);
550 args
[i
] = Fread_buffer (callint_message
, args
[i
], Qt
);
553 case 'B': /* Name of buffer, possibly nonexistent. */
554 args
[i
] = Fread_buffer (callint_message
,
555 Fother_buffer (Fcurrent_buffer (), Qnil
, Qnil
),
559 case 'c': /* Character. */
560 /* Prompt in `minibuffer-prompt' face. */
561 Fput_text_property (make_number (0),
562 make_number (SCHARS (callint_message
)),
563 Qface
, Qminibuffer_prompt
, callint_message
);
564 args
[i
] = Fread_char (callint_message
, Qnil
, Qnil
);
566 /* Passing args[i] directly stimulates compiler bug. */
569 if (! CHARACTERP (teml
)) error ("Non-character input-event");
570 visargs
[i
] = Fchar_to_string (teml
);
573 case 'C': /* Command: symbol with interactive function. */
574 visargs
[i
] = Fcompleting_read (callint_message
,
576 Qt
, Qnil
, Qnil
, Qnil
, Qnil
);
577 /* Passing args[i] directly stimulates compiler bug. */
579 args
[i
] = Fintern (teml
, Qnil
);
582 case 'd': /* Value of point. Does not do I/O. */
583 set_marker_both (point_marker
, Qnil
, PT
, PT_BYTE
);
584 args
[i
] = point_marker
;
585 /* visargs[i] = Qnil; */
589 case 'D': /* Directory name. */
590 args
[i
] = read_file_name (BVAR (current_buffer
, directory
), Qlambda
, Qnil
,
594 case 'f': /* Existing file name. */
595 args
[i
] = read_file_name (Qnil
, Qlambda
, Qnil
, Qnil
);
598 case 'F': /* Possibly nonexistent file name. */
599 args
[i
] = read_file_name (Qnil
, Qnil
, Qnil
, Qnil
);
602 case 'G': /* Possibly nonexistent file name,
603 default to directory alone. */
604 args
[i
] = read_file_name (Qnil
, Qnil
, empty_unibyte_string
, Qnil
);
607 case 'i': /* Ignore an argument -- Does not do I/O. */
611 case 'k': /* Key sequence. */
613 ptrdiff_t speccount1
= SPECPDL_INDEX ();
614 specbind (Qcursor_in_echo_area
, Qt
);
615 /* Prompt in `minibuffer-prompt' face. */
616 Fput_text_property (make_number (0),
617 make_number (SCHARS (callint_message
)),
618 Qface
, Qminibuffer_prompt
, callint_message
);
619 args
[i
] = Fread_key_sequence (callint_message
,
620 Qnil
, Qnil
, Qnil
, Qnil
);
621 unbind_to (speccount1
, Qnil
);
623 visargs
[i
] = Fkey_description (teml
, Qnil
);
625 /* If the key sequence ends with a down-event,
626 discard the following up-event. */
627 teml
= Faref (args
[i
], make_number (XINT (Flength (args
[i
])) - 1));
634 teml
= Fget (teml
, intern ("event-symbol-elements"));
635 /* Ignore first element, which is the base key. */
636 tem2
= Fmemq (intern ("down"), Fcdr (teml
));
638 up_event
= Fread_event (Qnil
, Qnil
, Qnil
);
643 case 'K': /* Key sequence to be defined. */
645 ptrdiff_t speccount1
= SPECPDL_INDEX ();
646 specbind (Qcursor_in_echo_area
, Qt
);
647 /* Prompt in `minibuffer-prompt' face. */
648 Fput_text_property (make_number (0),
649 make_number (SCHARS (callint_message
)),
650 Qface
, Qminibuffer_prompt
, callint_message
);
651 args
[i
] = Fread_key_sequence_vector (callint_message
,
652 Qnil
, Qt
, Qnil
, Qnil
);
654 visargs
[i
] = Fkey_description (teml
, Qnil
);
655 unbind_to (speccount1
, Qnil
);
657 /* If the key sequence ends with a down-event,
658 discard the following up-event. */
659 teml
= Faref (args
[i
], make_number (XINT (Flength (args
[i
])) - 1));
666 teml
= Fget (teml
, intern ("event-symbol-elements"));
667 /* Ignore first element, which is the base key. */
668 tem2
= Fmemq (intern ("down"), Fcdr (teml
));
670 up_event
= Fread_event (Qnil
, Qnil
, Qnil
);
675 case 'U': /* Up event from last k or K. */
676 if (!NILP (up_event
))
678 args
[i
] = Fmake_vector (make_number (1), up_event
);
681 visargs
[i
] = Fkey_description (teml
, Qnil
);
685 case 'e': /* The invoking event. */
686 if (next_event
>= key_count
)
687 error ("%s must be bound to an event with parameters",
689 ? SSDATA (SYMBOL_NAME (function
))
691 args
[i
] = AREF (keys
, next_event
);
695 /* Find the next parameterized event. */
696 while (next_event
< key_count
697 && !(EVENT_HAS_PARAMETERS (AREF (keys
, next_event
))))
702 case 'm': /* Value of mark. Does not do I/O. */
704 /* visargs[i] = Qnil; */
705 args
[i
] = BVAR (current_buffer
, mark
);
709 case 'M': /* String read via minibuffer with
710 inheriting the current input method. */
711 args
[i
] = Fread_string (callint_message
,
712 Qnil
, Qnil
, Qnil
, Qt
);
715 case 'N': /* Prefix arg as number, else number from minibuffer. */
716 if (!NILP (prefix_arg
))
717 goto have_prefix_arg
;
718 case 'n': /* Read number from minibuffer. */
719 args
[i
] = call1 (Qread_number
, callint_message
);
720 /* Passing args[i] directly stimulates compiler bug. */
722 visargs
[i
] = Fnumber_to_string (teml
);
725 case 'P': /* Prefix arg in raw form. Does no I/O. */
726 args
[i
] = prefix_arg
;
727 /* visargs[i] = Qnil; */
731 case 'p': /* Prefix arg converted to number. No I/O. */
733 args
[i
] = Fprefix_numeric_value (prefix_arg
);
734 /* visargs[i] = Qnil; */
738 case 'r': /* Region, point and mark as 2 args. */
740 set_marker_both (point_marker
, Qnil
, PT
, PT_BYTE
);
741 /* visargs[i+1] = Qnil; */
742 mark
= marker_position (BVAR (current_buffer
, mark
));
743 /* visargs[i] = Qnil; */
744 args
[i
] = PT
< mark
? point_marker
: BVAR (current_buffer
, mark
);
746 args
[++i
] = PT
> mark
? point_marker
: BVAR (current_buffer
, mark
);
750 case 's': /* String read via minibuffer without
751 inheriting the current input method. */
752 args
[i
] = Fread_string (callint_message
,
753 Qnil
, Qnil
, Qnil
, Qnil
);
756 case 'S': /* Any symbol. */
757 visargs
[i
] = Fread_string (callint_message
,
758 Qnil
, Qnil
, Qnil
, Qnil
);
759 /* Passing args[i] directly stimulates compiler bug. */
761 args
[i
] = Fintern (teml
, Qnil
);
764 case 'v': /* Variable name: symbol that is
765 custom-variable-p. */
766 args
[i
] = Fread_variable (callint_message
, Qnil
);
767 visargs
[i
] = last_minibuf_string
;
770 case 'x': /* Lisp expression read but not evaluated. */
771 args
[i
] = call1 (intern ("read-minibuffer"), callint_message
);
772 visargs
[i
] = last_minibuf_string
;
775 case 'X': /* Lisp expression read and evaluated. */
776 args
[i
] = call1 (intern ("eval-minibuffer"), callint_message
);
777 visargs
[i
] = last_minibuf_string
;
780 case 'Z': /* Coding-system symbol, or ignore the
781 argument if no prefix. */
782 if (NILP (prefix_arg
))
790 = Fread_non_nil_coding_system (callint_message
);
791 visargs
[i
] = last_minibuf_string
;
795 case 'z': /* Coding-system symbol or nil. */
796 args
[i
] = Fread_coding_system (callint_message
, Qnil
);
797 visargs
[i
] = last_minibuf_string
;
800 /* We have a case for `+' so we get an error
801 if anyone tries to define one here. */
804 error ("Invalid control letter `%c' (#o%03o, #x%04x) in interactive calling string",
805 STRING_CHAR ((unsigned char *) tem
),
806 (unsigned) STRING_CHAR ((unsigned char *) tem
),
807 (unsigned) STRING_CHAR ((unsigned char *) tem
));
813 if (NILP (visargs
[i
]) && STRINGP (args
[i
]))
814 visargs
[i
] = args
[i
];
816 tem
= strchr (tem
, '\n');
820 unbind_to (speccount
, Qnil
);
824 args
[0] = Qfuncall_interactively
;
827 if (arg_from_tty
|| !NILP (record_flag
))
829 /* We don't need `visargs' any more, so let's recycle it since we need
830 an array of just the same size. */
831 visargs
[1] = function
;
832 for (i
= 2; i
< nargs
; i
++)
835 visargs
[i
] = list1 (intern (callint_argfuns
[varies
[i
]]));
837 visargs
[i
] = quotify_arg (args
[i
]);
839 Vcommand_history
= Fcons (Flist (nargs
- 1, visargs
+ 1),
841 /* Don't keep command history around forever. */
842 if (INTEGERP (Vhistory_length
) && XINT (Vhistory_length
) > 0)
844 teml
= Fnthcdr (Vhistory_length
, Vcommand_history
);
846 XSETCDR (teml
, Qnil
);
850 /* If we used a marker to hold point, mark, or an end of the region,
851 temporarily, convert it to an integer now. */
852 for (i
= 2; i
< nargs
; i
++)
853 if (varies
[i
] >= 1 && varies
[i
] <= 4)
854 XSETINT (args
[i
], marker_position (args
[i
]));
856 if (record_then_fail
)
857 Fbarf_if_buffer_read_only (Qnil
);
859 Vthis_command
= save_this_command
;
860 Vthis_original_command
= save_this_original_command
;
861 Vreal_this_command
= save_real_this_command
;
862 kset_last_command (current_kboard
, save_last_command
);
865 Lisp_Object val
= Ffuncall (nargs
, args
);
867 val
= unbind_to (speccount
, val
);
873 DEFUN ("prefix-numeric-value", Fprefix_numeric_value
, Sprefix_numeric_value
,
875 doc
: /* Return numeric meaning of raw prefix argument RAW.
876 A raw prefix argument is what you get from `(interactive "P")'.
877 Its numeric meaning is what you would get from `(interactive "p")'. */)
883 XSETFASTINT (val
, 1);
884 else if (EQ (raw
, Qminus
))
886 else if (CONSP (raw
) && INTEGERP (XCAR (raw
)))
887 XSETINT (val
, XINT (XCAR (raw
)));
888 else if (INTEGERP (raw
))
891 XSETFASTINT (val
, 1);
897 syms_of_callint (void)
899 point_marker
= Fmake_marker ();
900 staticpro (&point_marker
);
902 callint_message
= Qnil
;
903 staticpro (&callint_message
);
905 preserved_fns
= listn (CONSTYPE_PURE
, 4,
906 intern_c_string ("region-beginning"),
907 intern_c_string ("region-end"),
908 intern_c_string ("point"),
909 intern_c_string ("mark"));
911 DEFSYM (Qlist
, "list");
912 DEFSYM (Qlet
, "let");
914 DEFSYM (Qwhen
, "when");
915 DEFSYM (Qletx
, "let*");
916 DEFSYM (Qsave_excursion
, "save-excursion");
917 DEFSYM (Qprogn
, "progn");
918 DEFSYM (Qminus
, "-");
920 DEFSYM (Qhandle_shift_selection
, "handle-shift-selection");
921 DEFSYM (Qread_number
, "read-number");
922 DEFSYM (Qfuncall_interactively
, "funcall-interactively");
923 DEFSYM (Qcommand_debug_status
, "command-debug-status");
924 DEFSYM (Qenable_recursive_minibuffers
, "enable-recursive-minibuffers");
925 DEFSYM (Qmouse_leave_buffer_hook
, "mouse-leave-buffer-hook");
927 DEFVAR_KBOARD ("prefix-arg", Vprefix_arg
,
928 doc
: /* The value of the prefix argument for the next editing command.
929 It may be a number, or the symbol `-' for just a minus sign as arg,
930 or a list whose car is a number for just one or more C-u's
931 or nil if no argument has been specified.
933 You cannot examine this variable to find the argument for this command
934 since it has been set to nil by the time you can look.
935 Instead, you should use the variable `current-prefix-arg', although
936 normally commands can get this prefix argument with (interactive "P"). */);
938 DEFVAR_KBOARD ("last-prefix-arg", Vlast_prefix_arg
,
939 doc
: /* The value of the prefix argument for the previous editing command.
940 See `prefix-arg' for the meaning of the value. */);
942 DEFVAR_LISP ("current-prefix-arg", Vcurrent_prefix_arg
,
943 doc
: /* The value of the prefix argument for this editing command.
944 It may be a number, or the symbol `-' for just a minus sign as arg,
945 or a list whose car is a number for just one or more C-u's
946 or nil if no argument has been specified.
947 This is what `(interactive \"P\")' returns. */);
948 Vcurrent_prefix_arg
= Qnil
;
950 DEFVAR_LISP ("command-history", Vcommand_history
,
951 doc
: /* List of recent commands that read arguments from terminal.
952 Each command is represented as a form to evaluate.
954 Maximum length of the history list is determined by the value
955 of `history-length', which see. */);
956 Vcommand_history
= Qnil
;
958 DEFVAR_LISP ("command-debug-status", Vcommand_debug_status
,
959 doc
: /* Debugging status of current interactive command.
960 Bound each time `call-interactively' is called;
961 may be set by the debugger as a reminder for itself. */);
962 Vcommand_debug_status
= Qnil
;
964 DEFVAR_LISP ("mark-even-if-inactive", Vmark_even_if_inactive
,
965 doc
: /* Non-nil means you can use the mark even when inactive.
966 This option makes a difference in Transient Mark mode.
967 When the option is non-nil, deactivation of the mark
968 turns off region highlighting, but commands that use the mark
969 behave as if the mark were still active. */);
970 Vmark_even_if_inactive
= Qt
;
972 DEFVAR_LISP ("mouse-leave-buffer-hook", Vmouse_leave_buffer_hook
,
973 doc
: /* Hook to run when about to switch windows with a mouse command.
974 Its purpose is to give temporary modes such as Isearch mode
975 a way to turn themselves off when a mouse command switches windows. */);
976 Vmouse_leave_buffer_hook
= Qnil
;
978 defsubr (&Sinteractive
);
979 defsubr (&Scall_interactively
);
980 defsubr (&Sfuncall_interactively
);
981 defsubr (&Sprefix_numeric_value
);