Mercurial > hg > xemacs-beta
annotate src/callint.c @ 4701:684f0ed6cd4f
Behave better when #'variable-at-point gives nil, #'custom-variable-prompt.
lisp/ChangeLog addition:
2009-09-27 Aidan Kehoe <kehoea@parhasard.net>
* cus-edit.el (custom-variable-prompt):
nil is a symbol, check that variable-at-point is non-nil before
checking if it's a symbol when deciding on the prompt used in this
function.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sun, 27 Sep 2009 20:37:44 +0100 |
parents | 8f1ee2d15784 |
children | 17f7e9191c0b |
rev | line source |
---|---|
428 | 1 /* Call a Lisp function interactively. |
2 Copyright (C) 1985, 1986, 1992, 1993, 1994 Free Software Foundation, Inc. | |
793 | 3 Copyright (C) 1995, 1996, 2001, 2002 Ben Wing. |
428 | 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" | |
872 | 38 #include "window-impl.h" /* WINDOW_MINI_P */ |
428 | 39 |
1204 | 40 extern Charcount num_input_chars; |
428 | 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 */ | |
444 | 56 /* FSF calls Qmouse_leave_buffer_hook at all sorts of random places, |
57 including a bunch of places in their mouse.el. If this is | |
58 implemented, it has to be done cleanly. */ | |
428 | 59 Lisp_Object Vmouse_leave_buffer_hook, Qmouse_leave_buffer_hook; |
60 #endif | |
61 | |
442 | 62 Lisp_Object QletX, Qsave_excursion; |
428 | 63 |
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 | |
77 Lisp_Object Qread_coding_system; | |
78 Lisp_Object Qread_non_nil_coding_system; | |
79 | |
80 /* ARGSUSED */ | |
81 DEFUN ("interactive", Finteractive, 0, UNEVALLED, 0, /* | |
82 Specify a way of parsing arguments for interactive use of a function. | |
83 For example, write | |
84 (defun foo (arg) "Doc string" (interactive "p") ...use arg...) | |
85 to make ARG be the prefix argument when `foo' is called as a command. | |
86 The "call" to `interactive' is actually a declaration rather than a function; | |
87 it tells `call-interactively' how to read arguments | |
88 to pass to the function. | |
4644
b0ae008bf1a0
Documentment placement restriction. <87d490jb7v.fsf@uwakimon.sk.tsukuba.ac.jp>
Stephen J. Turnbull <stephen@xemacs.org>
parents:
2367
diff
changeset
|
89 The interactive form must appear at the top level of the function body. If |
b0ae008bf1a0
Documentment placement restriction. <87d490jb7v.fsf@uwakimon.sk.tsukuba.ac.jp>
Stephen J. Turnbull <stephen@xemacs.org>
parents:
2367
diff
changeset
|
90 it is wrapped in a `let' or `progn' or similar, Lisp will not even realize |
b0ae008bf1a0
Documentment placement restriction. <87d490jb7v.fsf@uwakimon.sk.tsukuba.ac.jp>
Stephen J. Turnbull <stephen@xemacs.org>
parents:
2367
diff
changeset
|
91 the function is an interactive command! |
428 | 92 When actually called, `interactive' just returns nil. |
93 | |
94 The argument of `interactive' is usually a string containing a code letter | |
95 followed by a prompt. (Some code letters do not use I/O to get | |
96 the argument and do not need prompts.) To prompt for multiple arguments, | |
97 give a code letter, its prompt, a newline, and another code letter, etc. | |
98 Prompts are passed to format, and may use % escapes to print the | |
99 arguments that have already been read. | |
100 If the argument is not a string, it is evaluated to get a list of | |
101 arguments to pass to the function. | |
102 Just `(interactive)' means pass no args when calling interactively. | |
103 | |
104 Code letters available are: | |
105 a -- Function name: symbol with a function definition. | |
106 b -- Name of existing buffer. | |
107 B -- Name of buffer, possibly nonexistent. | |
108 c -- Character. | |
109 C -- Command name: symbol with interactive function definition. | |
110 d -- Value of point as number. Does not do I/O. | |
111 D -- Directory name. | |
112 e -- Last mouse-button or misc-user event that invoked this command. | |
113 If used more than once, the Nth `e' returns the Nth such event. | |
114 Does not do I/O. | |
115 f -- Existing file name. | |
116 F -- Possibly nonexistent file name. | |
117 i -- Always nil, ignore. Use to skip arguments when interactive. | |
118 k -- Key sequence (a vector of events). | |
119 K -- Key sequence to be redefined (do not automatically down-case). | |
120 m -- Value of mark as number. Does not do I/O. | |
121 n -- Number read using minibuffer. | |
122 N -- Prefix arg converted to number, or if none, do like code `n'. | |
123 p -- Prefix arg converted to number. Does not do I/O. | |
124 P -- Prefix arg in raw form. Does not do I/O. | |
125 r -- Region: point and mark as 2 numeric args, smallest first. Does no I/O. | |
126 s -- Any string. | |
127 S -- Any symbol. | |
128 v -- Variable name: symbol that is user-variable-p. | |
129 x -- Lisp expression read but not evaluated. | |
130 X -- Lisp expression read and evaluated. | |
131 z -- Coding system. (Always nil if no Mule support.) | |
132 Z -- Coding system, nil if no prefix arg. (Always nil if no Mule support.) | |
133 In addition, if the string begins with `*' | |
134 then an error is signaled if the buffer is read-only. | |
135 This happens before reading any arguments. | |
136 If the string begins with `@', then the window the mouse is over is selected | |
137 before anything else is done. | |
138 If the string begins with `_', then this command will not cause the region | |
139 to be deactivated when it completes; that is, `zmacs-region-stays' will be | |
140 set to t when the command exits successfully. | |
141 You may use any of `@', `*' and `_' at the beginning of the string; | |
142 they are processed in the order that they appear. | |
502 | 143 |
144 | |
145 When writing your own interactive spec, it can be useful to know the | |
146 equivalent Lisp expressions for the various code letters. They are: | |
147 | |
148 a -- (read-function "PROMPT") | |
149 b -- (let ((def (current-buffer))) | |
150 (if (eq (selected-window) (active-minibuffer-window)) | |
151 (setq def (other-buffer def)) | |
152 (read-buffer "PROMPT" def t))) | |
153 B -- (read-buffer "PROMPT" (other-buffer (current-buffer))) | |
154 c -- (prog1 | |
155 (let ((cursor-in-echo-area t)) | |
156 (message "%s" "PROMPT") | |
157 (read-char)) | |
158 (message nil)) | |
159 C -- (read-command "PROMPT") | |
160 d -- (point) | |
161 D -- (read-directory-name "PROMPT" nil default-directory t) | |
162 e -- current-mouse-event ;; #### not quite right. needs access to the KEYS | |
163 ;; argument of `call-interactively', but that's | |
164 ;; currently impossible. | |
165 f -- (read-file-name "PROMPT" nil nil 0) | |
166 F -- (read-file-name "PROMPT") | |
167 i -- nil | |
168 k -- (read-key-sequence "PROMPT") | |
169 K -- (read-key-sequence "PROMPT" nil t) | |
170 m -- (mark) | |
171 n -- (read-number "PROMPT") | |
172 N -- (if current-prefix-arg | |
173 (prefix-numeric-value current-prefix-arg) | |
174 (read-number "PROMPT")) | |
175 p -- (prefix-numeric-value current-prefix-arg) | |
176 P -- current-prefix-arg | |
177 r -- (if (and zmacs-regions (not zmacs-region-active-p)) | |
178 (error "The region is not active now")) | |
179 (let ((tem (marker-buffer (mark-marker t)))) | |
180 (unless (and tem (eq tem (current-buffer))) | |
181 (error "The mark is now set now"))) | |
182 (region-beginning) + | |
183 (region-end) | |
184 s -- (read-string "PROMPT") | |
185 S -- (let (tem prev-tem) | |
186 (while (not tem) | |
187 (setq tem (completing-read "PROMPT" obarray nil nil prev-tem)) | |
188 (setq prev-tem tem) | |
189 (setq tem (intern tem)) | |
190 (if (= (length tem) 0) | |
191 (setq tem nil)))) | |
192 v -- (read-variable "PROMPT") | |
193 x -- (read-expression "PROMPT") | |
194 X -- (eval (read-expression "PROMPT")) | |
195 z -- (and (fboundp 'read-coding-system) (read-coding-system "PROMPT")) | |
196 Z -- (and current-prefix-arg (fboundp 'read-coding-system) | |
197 (read-coding-system "PROMPT")) | |
198 | |
199 `*' (barf-if-buffer-read-only) | |
200 `@' (let ((event current-mouse-event)) ;; #### not quite right; needs the | |
201 (when event ;; value from the `e' spec above. | |
202 (let ((window event-window event)) | |
203 (when window | |
204 (if (and (window-minibuffer-p window) | |
205 (not (and (> (minibuffer-depth) 0) | |
206 (eq window (active-minibuffer-window))))) | |
207 (error "Attempt to select inactive minibuffer window")) | |
208 (select window))))) | |
4652 | 209 `_' (setq zmacs-region-stays t) *//* FIXME: moving end of previous comment |
210 to a separate line causes docstring lossage! */ | |
2286 | 211 (UNUSED (args))) |
428 | 212 { |
213 return Qnil; | |
214 } | |
215 | |
216 /* Originally, this was just a function -- but `custom' used a | |
217 garden-variety version, so why not make it a subr? */ | |
218 /* #### Move it to another file! */ | |
219 DEFUN ("quote-maybe", Fquote_maybe, 1, 1, 0, /* | |
220 Quote EXPR if it is not self quoting. | |
221 */ | |
222 (expr)) | |
223 { | |
224 return ((NILP (expr) | |
225 || EQ (expr, Qt) | |
226 || INTP (expr) | |
227 || FLOATP (expr) | |
228 || CHARP (expr) | |
229 || STRINGP (expr) | |
230 || VECTORP (expr) | |
231 || KEYWORDP (expr) | |
232 || BIT_VECTORP (expr) | |
233 || (CONSP (expr) && EQ (XCAR (expr), Qlambda))) | |
234 ? expr : list2 (Qquote, expr)); | |
235 } | |
236 | |
237 /* Modify EXPR by quotifying each element (except the first). */ | |
238 static Lisp_Object | |
239 quotify_args (Lisp_Object expr) | |
240 { | |
2367 | 241 EXTERNAL_LIST_LOOP_3 (elt, expr, tail) |
242 XSETCAR (tail, Fquote_maybe (elt)); | |
428 | 243 return expr; |
244 } | |
245 | |
665 | 246 static Charbpos |
428 | 247 check_mark (void) |
248 { | |
249 Lisp_Object tem; | |
250 | |
251 if (zmacs_regions && !zmacs_region_active_p) | |
563 | 252 invalid_operation ("The region is not active now", Qunbound); |
428 | 253 |
254 tem = Fmarker_buffer (current_buffer->mark); | |
255 if (NILP (tem) || (XBUFFER (tem) != current_buffer)) | |
563 | 256 invalid_operation ("The mark is not set now", Qunbound); |
428 | 257 |
258 return marker_position (current_buffer->mark); | |
259 } | |
260 | |
261 static Lisp_Object | |
867 | 262 callint_prompt (const Ibyte *prompt_start, Bytecount prompt_length, |
442 | 263 const Lisp_Object *args, int nargs) |
428 | 264 { |
265 Lisp_Object s = make_string (prompt_start, prompt_length); | |
266 struct gcpro gcpro1; | |
267 | |
268 /* Fformat no longer smashes its arg vector, so no need to copy it. */ | |
269 | |
270 if (!strchr ((char *) XSTRING_DATA (s), '%')) | |
271 return s; | |
272 GCPRO1 (s); | |
771 | 273 RETURN_UNGCPRO (emacs_vsprintf_string_lisp (0, s, nargs, args)); |
428 | 274 } |
275 | |
276 /* `lambda' for RECORD-FLAG is an XEmacs addition. */ | |
277 | |
278 DEFUN ("call-interactively", Fcall_interactively, 1, 3, 0, /* | |
279 Call FUNCTION, reading args according to its interactive calling specs. | |
280 Return the value FUNCTION returns. | |
281 The function contains a specification of how to do the argument reading. | |
282 In the case of user-defined functions, this is specified by placing a call | |
283 to the function `interactive' at the top level of the function body. | |
284 See `interactive'. | |
285 | |
286 If optional second arg RECORD-FLAG is the symbol `lambda', the interactive | |
287 calling arguments for FUNCTION are read and returned as a list, | |
288 but the function is not called on them. | |
289 | |
290 If RECORD-FLAG is `t' then unconditionally put this command in the | |
291 command-history. Otherwise, this is done only if an arg is read using | |
292 the minibuffer. | |
293 | |
294 The argument KEYS specifies the value to use instead of (this-command-keys) | |
295 when reading the arguments. | |
296 */ | |
297 (function, record_flag, keys)) | |
298 { | |
299 /* This function can GC */ | |
300 int speccount = specpdl_depth (); | |
301 Lisp_Object prefix; | |
302 | |
303 Lisp_Object fun; | |
304 Lisp_Object specs = Qnil; | |
305 #ifdef IT_SEEMS_THAT_MLY_DOESNT_LIKE_THIS | |
306 Lisp_Object enable; | |
307 #endif | |
793 | 308 /* If SPECS is a string, we reset prompt_data to XSTRING_DATA (specs) |
309 every time a GC might have occurred */ | |
442 | 310 const char *prompt_data = 0; |
428 | 311 int prompt_index = 0; |
312 int argcount; | |
313 int set_zmacs_region_stays = 0; | |
314 int mouse_event_count = 0; | |
315 | |
316 if (!NILP (keys)) | |
317 { | |
318 int i, len; | |
319 | |
320 CHECK_VECTOR (keys); | |
321 len = XVECTOR_LENGTH (keys); | |
322 for (i = 0; i < len; i++) | |
323 CHECK_LIVE_EVENT (XVECTOR_DATA (keys)[i]); | |
324 } | |
325 | |
326 /* Save this now, since use of minibuffer will clobber it. */ | |
327 prefix = Vcurrent_prefix_arg; | |
328 | |
329 retry: | |
330 | |
331 #ifdef IT_SEEMS_THAT_MLY_DOESNT_LIKE_THIS | |
332 /* Marginal kludge. Use an evaluated interactive spec instead of this! */ | |
333 if (SYMBOLP (function)) | |
334 enable = Fget (function, Qenable_recursive_minibuffers, Qnil); | |
335 #endif | |
336 | |
337 fun = indirect_function (function, 1); | |
338 | |
339 /* Decode the kind of function. Either handle it and return, | |
340 or go to `lose' if not interactive, or go to `retry' | |
341 to specify a different function, or set either PROMPT_DATA or SPECS. */ | |
342 | |
343 if (SUBRP (fun)) | |
344 { | |
345 prompt_data = XSUBR (fun)->prompt; | |
346 if (!prompt_data) | |
347 { | |
348 lose: | |
349 function = wrong_type_argument (Qcommandp, function); | |
350 goto retry; | |
351 } | |
352 #if 0 /* FSFmacs */ /* Huh? Where is this used? */ | |
353 if ((EMACS_INT) prompt_data == 1) | |
354 /* Let SPECS (which is nil) be used as the args. */ | |
355 prompt_data = 0; | |
356 #endif | |
357 } | |
358 else if (COMPILED_FUNCTIONP (fun)) | |
359 { | |
360 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (fun); | |
361 if (! f->flags.interactivep) | |
362 goto lose; | |
363 specs = compiled_function_interactive (f); | |
364 } | |
365 else if (!CONSP (fun)) | |
366 goto lose; | |
367 else | |
368 { | |
369 Lisp_Object funcar = Fcar (fun); | |
370 | |
371 if (EQ (funcar, Qautoload)) | |
372 { | |
970 | 373 struct gcpro gcpro1; |
374 GCPRO1 (prefix); | |
375 /* do_autoload GCPROs both arguments */ | |
428 | 376 do_autoload (fun, function); |
377 UNGCPRO; | |
378 goto retry; | |
379 } | |
380 else if (EQ (funcar, Qlambda)) | |
381 { | |
382 specs = Fassq (Qinteractive, Fcdr (Fcdr (fun))); | |
383 if (NILP (specs)) | |
384 goto lose; | |
385 specs = Fcar (Fcdr (specs)); | |
386 } | |
387 else | |
388 goto lose; | |
389 } | |
390 | |
2367 | 391 /* FSFmacs makes an ALLOCA() copy of prompt_data here. |
428 | 392 We're more intelligent about this and just reset prompt_data |
393 as necessary. */ | |
394 /* If either specs or prompt_data is set to a string, use it. */ | |
395 if (!STRINGP (specs) && prompt_data == 0) | |
396 { | |
397 struct gcpro gcpro1, gcpro2, gcpro3; | |
398 int i = num_input_chars; | |
399 Lisp_Object input = specs; | |
400 | |
401 GCPRO3 (function, specs, input); | |
402 /* Compute the arg values using the user's expression. */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4654
diff
changeset
|
403 specs = IGNORE_MULTIPLE_VALUES (Feval (specs)); |
428 | 404 if (EQ (record_flag, Qlambda)) /* XEmacs addition */ |
405 { | |
406 UNGCPRO; | |
407 return specs; | |
408 } | |
409 if (!NILP (record_flag) || i != num_input_chars) | |
410 { | |
411 /* We should record this command on the command history. */ | |
412 /* #### The following is too specific; should have general | |
413 mechanism for doing this. */ | |
414 Lisp_Object values, car; | |
415 /* Make a copy of the list of values, for the command history, | |
416 and turn them into things we can eval. */ | |
417 values = quotify_args (Fcopy_sequence (specs)); | |
418 /* If the list of args was produced with an explicit call to `list', | |
419 look for elements that were computed with (region-beginning) | |
420 or (region-end), and put those expressions into VALUES | |
421 instead of the present values. */ | |
422 if (CONSP (input)) | |
423 { | |
424 car = XCAR (input); | |
425 /* Skip through certain special forms. */ | |
426 while (EQ (car, Qlet) || EQ (car, QletX) | |
427 || EQ (car, Qsave_excursion)) | |
428 { | |
429 while (CONSP (XCDR (input))) | |
430 input = XCDR (input); | |
431 input = XCAR (input); | |
432 if (!CONSP (input)) | |
433 break; | |
434 car = XCAR (input); | |
435 } | |
436 if (EQ (car, Qlist)) | |
437 { | |
438 Lisp_Object intail, valtail; | |
439 for (intail = Fcdr (input), valtail = values; | |
440 CONSP (valtail); | |
441 intail = Fcdr (intail), valtail = Fcdr (valtail)) | |
442 { | |
443 Lisp_Object elt; | |
444 elt = Fcar (intail); | |
445 if (CONSP (elt)) | |
446 { | |
447 Lisp_Object eltcar = Fcar (elt); | |
448 if (EQ (eltcar, Qpoint) || | |
449 EQ (eltcar, Qmark) || | |
450 EQ (eltcar, Qregion_beginning) || | |
451 EQ (eltcar, Qregion_end)) | |
452 Fsetcar (valtail, Fcar (intail)); | |
453 } | |
454 } | |
455 } | |
456 } | |
457 Vcommand_history | |
458 = Fcons (Fcons (function, values), Vcommand_history); | |
459 } | |
460 single_console_state (); | |
461 RETURN_UNGCPRO (apply1 (fun, specs)); | |
462 } | |
463 | |
464 /* Here if function specifies a string to control parsing the defaults */ | |
465 | |
466 #ifdef I18N3 | |
467 /* Translate interactive prompt. */ | |
468 if (STRINGP (specs)) | |
469 { | |
470 Lisp_Object domain = Qnil; | |
471 if (COMPILED_FUNCTIONP (fun)) | |
472 domain = compiled_function_domain (XCOMPILED_FUNCTION (fun)); | |
473 if (NILP (domain)) | |
474 specs = Fgettext (specs); | |
475 else | |
476 specs = Fdgettext (domain, specs); | |
477 } | |
478 else if (prompt_data) | |
479 /* We do not have to worry about domains in this case because | |
480 prompt_data is non-nil only for built-in functions, which | |
481 always use the default domain. */ | |
482 prompt_data = gettext (prompt_data); | |
483 #endif | |
484 | |
485 /* Handle special starting chars `*' and `@' and `_'. */ | |
486 /* Note that `+' is reserved for user extensions. */ | |
487 prompt_index = 0; | |
488 { | |
489 struct gcpro gcpro1, gcpro2; | |
490 GCPRO2 (function, specs); | |
491 | |
492 for (;;) | |
493 { | |
494 if (STRINGP (specs)) | |
442 | 495 prompt_data = (const char *) XSTRING_DATA (specs); |
428 | 496 |
497 if (prompt_data[prompt_index] == '+') | |
563 | 498 syntax_error ("`+' is not used in `interactive' for ordinary commands", Qunbound); |
428 | 499 else if (prompt_data[prompt_index] == '*') |
500 { | |
501 prompt_index++; | |
502 if (!NILP (current_buffer->read_only)) | |
503 barf_if_buffer_read_only (current_buffer, -1, -1); | |
504 } | |
505 else if (prompt_data[prompt_index] == '@') | |
506 { | |
507 Lisp_Object event; | |
508 prompt_index++; | |
509 | |
510 if (!NILP (keys)) | |
511 event = extract_vector_nth_mouse_event (keys, 0); | |
512 else | |
513 #if 0 | |
514 event = extract_this_command_keys_nth_mouse_event (0); | |
515 #else | |
516 /* Doesn't work; see below */ | |
517 event = Vcurrent_mouse_event; | |
518 #endif | |
519 if (! NILP (event)) | |
520 { | |
521 Lisp_Object window = Fevent_window (event); | |
522 if (!NILP (window)) | |
523 { | |
524 if (MINI_WINDOW_P (XWINDOW (window)) | |
525 && ! (minibuf_level > 0 && EQ (window, | |
526 minibuf_window))) | |
563 | 527 invalid_operation ("Attempt to select inactive minibuffer window", Qunbound); |
428 | 528 |
529 #if 0 /* unclean! see event-stream.c */ | |
530 /* If the current buffer wants to clean up, let it. */ | |
531 if (!NILP (Vmouse_leave_buffer_hook)) | |
532 run_hook (Qmouse_leave_buffer_hook); | |
533 #endif | |
534 | |
535 Fselect_window (window, Qnil); | |
536 } | |
537 } | |
538 } | |
539 else if (prompt_data[prompt_index] == '_') | |
540 { | |
541 prompt_index++; | |
542 set_zmacs_region_stays = 1; | |
543 } | |
544 else | |
545 { | |
546 UNGCPRO; | |
547 break; | |
548 } | |
549 } | |
550 } | |
551 | |
552 /* Count the number of arguments the interactive spec would have | |
553 us give to the function. */ | |
554 argcount = 0; | |
555 { | |
442 | 556 const char *tem; |
428 | 557 for (tem = prompt_data + prompt_index; *tem; ) |
558 { | |
559 /* 'r' specifications ("point and mark as 2 numeric args") | |
560 produce *two* arguments. */ | |
561 if (*tem == 'r') | |
562 argcount += 2; | |
563 else | |
564 argcount += 1; | |
442 | 565 tem = (const char *) strchr (tem + 1, '\n'); |
428 | 566 if (!tem) |
567 break; | |
568 tem++; | |
569 } | |
570 } | |
571 | |
572 #ifdef IT_SEEMS_THAT_MLY_DOESNT_LIKE_THIS | |
573 if (!NILP (enable)) | |
574 specbind (Qenable_recursive_minibuffers, Qt); | |
575 #endif | |
576 | |
577 if (argcount == 0) | |
578 { | |
579 /* Interactive function or no arguments; just call it */ | |
580 if (EQ (record_flag, Qlambda)) | |
581 return Qnil; | |
582 if (!NILP (record_flag)) | |
583 { | |
584 Vcommand_history = Fcons (list1 (function), Vcommand_history); | |
585 } | |
586 specbind (Qcommand_debug_status, Qnil); | |
587 /* XEmacs: was fun = call0 (fun), but that's backtraced wrong */ | |
588 { | |
589 struct gcpro gcpro1; | |
590 | |
591 GCPRO1 (fun); | |
592 fun = Ffuncall (1, &fun); | |
593 UNGCPRO; | |
594 } | |
595 if (set_zmacs_region_stays) | |
596 zmacs_region_stays = 1; | |
771 | 597 return unbind_to_1 (speccount, fun); |
428 | 598 } |
599 | |
600 /* Read interactive arguments */ | |
601 { | |
602 /* args[-1] is the function to call */ | |
603 /* args[n] is the n'th argument to the function */ | |
604 int alloca_size = (1 /* function to call */ | |
605 + argcount /* actual arguments */ | |
606 + argcount /* visargs */ | |
607 + argcount /* varies */ | |
608 ); | |
609 Lisp_Object *args = alloca_array (Lisp_Object, alloca_size) + 1; | |
610 /* visargs is an array of either Qnil or user-friendlier versions (often | |
611 * strings) of previous arguments, to use in prompts for successive | |
612 * arguments. ("Often strings" because emacs didn't used to have | |
613 * format %S and prin1-to-string.) */ | |
614 Lisp_Object *visargs = args + argcount; | |
615 /* If varies[i] is non-null, the i'th argument shouldn't just have | |
616 its value in this call quoted in the command history. It should be | |
617 recorded as a call to the function named varies[i]]. */ | |
618 Lisp_Object *varies = visargs + argcount; | |
619 int arg_from_tty = 0; | |
620 REGISTER int argnum; | |
621 struct gcpro gcpro1, gcpro2; | |
622 | |
623 args[-1] = function; | |
624 for (argnum = 0; argnum < alloca_size - 1; argnum++) | |
625 args[argnum] = Qnil; | |
626 | |
627 /* Must GC-protect args[-1] (ie function) because Ffuncall doesn't */ | |
628 /* `function' itself isn't GC-protected -- use args[-1] from here | |
629 (actually, doesn't matter since Emacs GC doesn't relocate, sigh) */ | |
630 GCPRO2 (prefix, args[-1]); | |
631 gcpro2.nvars = alloca_size; | |
632 | |
633 for (argnum = 0; ; argnum++) | |
634 { | |
442 | 635 const char *prompt_start = prompt_data + prompt_index + 1; |
636 const char *prompt_limit = (const char *) strchr (prompt_start, '\n'); | |
428 | 637 int prompt_length; |
638 prompt_length = ((prompt_limit) | |
639 ? (prompt_limit - prompt_start) | |
664 | 640 : (int) strlen (prompt_start)); |
428 | 641 if (prompt_limit && prompt_limit[1] == 0) |
642 { | |
643 prompt_limit = 0; /* "sfoo:\n" -- strip tailing return */ | |
644 prompt_length -= 1; | |
645 } | |
646 /* This uses `visargs' instead of `args' so that global-set-key | |
647 prompts with "Set key C-x C-f to command: "instead of printing | |
648 event objects in there. | |
649 */ | |
867 | 650 #define PROMPT() callint_prompt ((const Ibyte *) prompt_start, prompt_length, visargs, argnum) |
428 | 651 switch (prompt_data[prompt_index]) |
652 { | |
653 case 'a': /* Symbol defined as a function */ | |
654 { | |
655 Lisp_Object tem = call1 (Qread_function, PROMPT ()); | |
656 args[argnum] = tem; | |
657 arg_from_tty = 1; | |
658 break; | |
659 } | |
660 case 'b': /* Name of existing buffer */ | |
661 { | |
662 Lisp_Object def = Fcurrent_buffer (); | |
663 if (EQ (Fselected_window (Qnil), minibuf_window)) | |
664 def = Fother_buffer (def, Qnil, Qnil); | |
665 /* read-buffer returns a buffer name, not a buffer! */ | |
666 args[argnum] = call3 (Qread_buffer, PROMPT (), def, | |
667 Qt); | |
668 arg_from_tty = 1; | |
669 break; | |
670 } | |
671 case 'B': /* Name of buffer, possibly nonexistent */ | |
672 { | |
673 /* read-buffer returns a buffer name, not a buffer! */ | |
674 args[argnum] = call2 (Qread_buffer, PROMPT (), | |
675 Fother_buffer (Fcurrent_buffer (), Qnil, | |
676 Qnil)); | |
677 arg_from_tty = 1; | |
678 break; | |
679 } | |
680 case 'c': /* Character */ | |
681 { | |
682 Lisp_Object tem; | |
683 int shadowing_speccount = specpdl_depth (); | |
684 | |
685 specbind (Qcursor_in_echo_area, Qt); | |
686 message ("%s", XSTRING_DATA (PROMPT ())); | |
687 tem = (call0 (Qread_char)); | |
688 args[argnum] = tem; | |
689 /* visargs[argnum] = Fsingle_key_description (tem); */ | |
690 /* FSF has visargs[argnum] = Fchar_to_string (tem); */ | |
691 | |
771 | 692 unbind_to (shadowing_speccount); |
428 | 693 |
694 /* #### `C-x / a' should not leave the prompt in the minibuffer. | |
695 This isn't the right fix, because (message ...) (read-char) | |
696 shouldn't leave the message there either... */ | |
697 clear_message (); | |
698 | |
699 arg_from_tty = 1; | |
700 break; | |
701 } | |
702 case 'C': /* Command: symbol with interactive function */ | |
703 { | |
704 Lisp_Object tem = call1 (Qread_command, PROMPT ()); | |
705 args[argnum] = tem; | |
706 arg_from_tty = 1; | |
707 break; | |
708 } | |
709 case 'd': /* Value of point. Does not do I/O. */ | |
710 { | |
711 args[argnum] = Fcopy_marker (current_buffer->point_marker, Qt); | |
712 varies[argnum] = Qpoint; | |
713 break; | |
714 } | |
715 case 'e': | |
716 { | |
717 Lisp_Object event; | |
718 | |
719 if (!NILP (keys)) | |
720 event = extract_vector_nth_mouse_event (keys, | |
721 mouse_event_count); | |
722 else | |
723 #if 0 | |
724 /* This doesn't quite work because this-command-keys | |
725 behaves in utterly counterintuitive ways. Sometimes | |
726 it retrieves an event back in the future, e.g. when | |
727 one command invokes another command and both are | |
728 invoked with the mouse. */ | |
729 event = (extract_this_command_keys_nth_mouse_event | |
730 (mouse_event_count)); | |
731 #else | |
732 event = Vcurrent_mouse_event; | |
733 #endif | |
734 | |
735 if (NILP (event)) | |
563 | 736 signal_error (Qinvalid_operation, |
737 "function must be bound to a mouse or misc-user event", | |
738 function); | |
428 | 739 args[argnum] = event; |
740 mouse_event_count++; | |
741 break; | |
742 } | |
743 case 'D': /* Directory name. */ | |
744 { | |
745 args[argnum] = call4 (Qread_directory_name, PROMPT (), | |
746 Qnil, /* dir */ | |
747 current_buffer->directory, /* default */ | |
748 Qt /* must-match */ | |
749 ); | |
750 arg_from_tty = 1; | |
751 break; | |
752 } | |
753 case 'f': /* Existing file name. */ | |
754 { | |
755 Lisp_Object tem = call4 (Qread_file_name, PROMPT (), | |
756 Qnil, /* dir */ | |
757 Qnil, /* default */ | |
758 Qzero /* must-match */ | |
759 ); | |
760 args[argnum] = tem; | |
761 arg_from_tty = 1; | |
762 break; | |
763 } | |
764 case 'F': /* Possibly nonexistent file name. */ | |
765 { | |
766 args[argnum] = call4 (Qread_file_name, PROMPT (), | |
767 Qnil, /* dir */ | |
768 Qnil, /* default */ | |
769 Qnil /* must-match */ | |
770 ); | |
771 arg_from_tty = 1; | |
772 break; | |
773 } | |
774 case 'i': /* Ignore: always nil. Use to skip arguments. */ | |
775 { | |
776 args[argnum] = Qnil; | |
777 break; | |
778 } | |
779 case 'k': /* Key sequence (vector of events) */ | |
780 { | |
781 struct gcpro ngcpro1; | |
782 Lisp_Object tem; | |
783 Lisp_Object key_prompt = PROMPT (); | |
784 | |
785 NGCPRO1(key_prompt); | |
786 tem = Fread_key_sequence (key_prompt, Qnil, Qnil); | |
787 NUNGCPRO; | |
788 | |
789 visargs[argnum] = Fkey_description (tem); | |
790 /* The following makes `describe-key' not work with | |
791 extent-local keymaps and such; and anyway, it's | |
792 contrary to the documentation. */ | |
793 /* args[argnum] = call1 (Qevents_to_keys, tem); */ | |
794 args[argnum] = tem; | |
795 arg_from_tty = 1; | |
796 break; | |
797 } | |
798 case 'K': /* Key sequence (vector of events), | |
799 no automatic downcasing */ | |
800 { | |
801 struct gcpro ngcpro1; | |
802 Lisp_Object tem; | |
803 Lisp_Object key_prompt = PROMPT (); | |
804 | |
805 NGCPRO1(key_prompt); | |
806 tem = Fread_key_sequence (key_prompt, Qnil, Qt); | |
807 NUNGCPRO; | |
808 | |
809 visargs[argnum] = Fkey_description (tem); | |
810 /* The following makes `describe-key' not work with | |
811 extent-local keymaps and such; and anyway, it's | |
812 contrary to the documentation. */ | |
813 /* args[argnum] = call1 (Qevents_to_keys, tem); */ | |
814 args[argnum] = tem; | |
815 arg_from_tty = 1; | |
816 break; | |
817 } | |
818 | |
819 case 'm': /* Value of mark. Does not do I/O. */ | |
820 { | |
821 args[argnum] = current_buffer->mark; | |
822 varies[argnum] = Qmark; | |
823 break; | |
824 } | |
825 case 'n': /* Read number from minibuffer. */ | |
826 { | |
827 read_number: | |
828 args[argnum] = call2 (Qread_number, PROMPT (), Qnil); | |
829 /* numbers are too boring to go on command history */ | |
830 /* arg_from_tty = 1; */ | |
831 break; | |
832 } | |
833 case 'N': /* Prefix arg, else number from minibuffer */ | |
834 { | |
835 if (NILP (prefix)) | |
836 goto read_number; | |
837 else | |
838 goto prefix_value; | |
839 } | |
840 case 'P': /* Prefix arg in raw form. Does no I/O. */ | |
841 { | |
842 args[argnum] = prefix; | |
843 break; | |
844 } | |
845 case 'p': /* Prefix arg converted to number. No I/O. */ | |
846 { | |
847 prefix_value: | |
848 { | |
849 Lisp_Object tem = Fprefix_numeric_value (prefix); | |
850 args[argnum] = tem; | |
851 } | |
852 break; | |
853 } | |
854 case 'r': /* Region, point and mark as 2 args. */ | |
855 { | |
665 | 856 Charbpos tem = check_mark (); |
428 | 857 args[argnum] = (BUF_PT (current_buffer) < tem |
858 ? Fcopy_marker (current_buffer->point_marker, Qt) | |
859 : current_buffer->mark); | |
860 varies[argnum] = Qregion_beginning; | |
861 args[++argnum] = (BUF_PT (current_buffer) > tem | |
862 ? Fcopy_marker (current_buffer->point_marker, | |
863 Qt) | |
864 : current_buffer->mark); | |
865 varies[argnum] = Qregion_end; | |
866 break; | |
867 } | |
868 case 's': /* String read via minibuffer. */ | |
869 { | |
870 args[argnum] = call1 (Qread_string, PROMPT ()); | |
871 arg_from_tty = 1; | |
872 break; | |
873 } | |
874 case 'S': /* Any symbol. */ | |
875 { | |
876 visargs[argnum] = Qnil; | |
877 for (;;) | |
878 { | |
879 Lisp_Object tem = call5 (Qcompleting_read, | |
880 PROMPT (), | |
881 Vobarray, | |
882 Qnil, | |
883 Qnil, | |
884 /* nil, or prev attempt */ | |
885 visargs[argnum]); | |
886 visargs[argnum] = tem; | |
887 /* I could use condition-case with this loser, but why bother? | |
888 * tem = Fread (tem); check-symbol-p; | |
889 */ | |
890 tem = Fintern (tem, Qnil); | |
891 args[argnum] = tem; | |
793 | 892 if (XSTRING_LENGTH (XSYMBOL (tem)->name) > 0) |
428 | 893 /* Don't accept the empty-named symbol. If the loser |
894 really wants this s/he can call completing-read | |
895 directly */ | |
896 break; | |
897 } | |
898 arg_from_tty = 1; | |
899 break; | |
900 } | |
901 case 'v': /* Variable name: user-variable-p symbol */ | |
902 { | |
903 Lisp_Object tem = call1 (Qread_variable, PROMPT ()); | |
904 args[argnum] = tem; | |
905 arg_from_tty = 1; | |
906 break; | |
907 } | |
908 case 'x': /* Lisp expression read but not evaluated */ | |
909 { | |
910 args[argnum] = call1 (Qread_expression, PROMPT ()); | |
911 /* visargs[argnum] = Fprin1_to_string (args[argnum], Qnil); */ | |
912 arg_from_tty = 1; | |
913 break; | |
914 } | |
915 case 'X': /* Lisp expression read and evaluated */ | |
916 { | |
917 Lisp_Object tem = call1 (Qread_expression, PROMPT ()); | |
918 /* visargs[argnum] = Fprin1_to_string (tem, Qnil); */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4654
diff
changeset
|
919 args[argnum] = IGNORE_MULTIPLE_VALUES (Feval (tem)); |
428 | 920 arg_from_tty = 1; |
921 break; | |
922 } | |
923 case 'Z': /* Coding-system symbol or nil if no prefix */ | |
924 { | |
925 if (NILP (prefix)) | |
926 { | |
927 args[argnum] = Qnil; | |
928 } | |
929 else | |
930 { | |
931 args[argnum] = | |
932 call1 (Qread_non_nil_coding_system, PROMPT ()); | |
933 arg_from_tty = 1; | |
934 } | |
935 break; | |
936 } | |
937 case 'z': /* Coding-system symbol */ | |
938 { | |
939 args[argnum] = call1 (Qread_coding_system, PROMPT ()); | |
940 arg_from_tty = 1; | |
941 break; | |
942 } | |
943 | |
944 /* We have a case for `+' so we get an error | |
945 if anyone tries to define one here. */ | |
946 case '+': | |
947 default: | |
948 { | |
826 | 949 signal_ferror |
950 (Qsyntax_error, | |
951 "Invalid `interactive' control letter \"%c\" (#o%03o).", | |
952 prompt_data[prompt_index], prompt_data[prompt_index]); | |
428 | 953 } |
954 } | |
955 #undef PROMPT | |
956 if (NILP (visargs[argnum])) | |
957 visargs[argnum] = args[argnum]; | |
958 | |
959 if (!prompt_limit) | |
960 break; | |
961 if (STRINGP (specs)) | |
442 | 962 prompt_data = (const char *) XSTRING_DATA (specs); |
428 | 963 prompt_index += prompt_length + 1 + 1; /* +1 to skip spec, +1 for \n */ |
964 } | |
771 | 965 unbind_to (speccount); |
428 | 966 |
967 QUIT; | |
968 | |
969 if (EQ (record_flag, Qlambda)) | |
970 { | |
971 RETURN_UNGCPRO (Flist (argcount, args)); | |
972 } | |
973 | |
974 if (arg_from_tty || !NILP (record_flag)) | |
975 { | |
976 /* Reuse visargs as a temporary for constructing the command history */ | |
977 for (argnum = 0; argnum < argcount; argnum++) | |
978 { | |
979 if (!NILP (varies[argnum])) | |
980 visargs[argnum] = list1 (varies[argnum]); | |
981 else | |
982 visargs[argnum] = Fquote_maybe (args[argnum]); | |
983 } | |
984 Vcommand_history = Fcons (Fcons (args[-1], Flist (argcount, visargs)), | |
985 Vcommand_history); | |
986 } | |
987 | |
988 /* If we used a marker to hold point, mark, or an end of the region, | |
989 temporarily, convert it to an integer now. */ | |
990 for (argnum = 0; argnum < argcount; argnum++) | |
991 if (!NILP (varies[argnum])) | |
793 | 992 args[argnum] = make_int (marker_position (args[argnum])); |
428 | 993 |
994 single_console_state (); | |
995 specbind (Qcommand_debug_status, Qnil); | |
996 fun = Ffuncall (argcount + 1, args - 1); | |
997 UNGCPRO; | |
998 if (set_zmacs_region_stays) | |
999 zmacs_region_stays = 1; | |
771 | 1000 return unbind_to_1 (speccount, fun); |
428 | 1001 } |
1002 } | |
1003 | |
1004 DEFUN ("prefix-numeric-value", Fprefix_numeric_value, 1, 1, 0, /* | |
444 | 1005 Return numeric meaning of raw prefix argument RAW. |
428 | 1006 A raw prefix argument is what you get from `(interactive "P")'. |
1007 Its numeric meaning is what you would get from `(interactive "p")'. | |
1008 */ | |
1009 (raw)) | |
1010 { | |
1011 if (NILP (raw)) | |
1012 return make_int (1); | |
1013 if (EQ (raw, Qminus)) | |
1014 return make_int (-1); | |
1015 if (INTP (raw)) | |
1016 return raw; | |
1017 if (CONSP (raw) && INTP (XCAR (raw))) | |
1018 return XCAR (raw); | |
1019 | |
1020 return make_int (1); | |
1021 } | |
1022 | |
1023 void | |
1024 syms_of_callint (void) | |
1025 { | |
563 | 1026 DEFSYMBOL (Qcall_interactively); |
1027 DEFSYMBOL (Qread_from_minibuffer); | |
1028 DEFSYMBOL (Qcompleting_read); | |
1029 DEFSYMBOL (Qread_file_name); | |
1030 DEFSYMBOL (Qread_directory_name); | |
1031 DEFSYMBOL (Qread_string); | |
1032 DEFSYMBOL (Qread_buffer); | |
1033 DEFSYMBOL (Qread_variable); | |
1034 DEFSYMBOL (Qread_function); | |
1035 DEFSYMBOL (Qread_command); | |
1036 DEFSYMBOL (Qread_number); | |
1037 DEFSYMBOL (Qread_expression); | |
1038 DEFSYMBOL (Qread_coding_system); | |
1039 DEFSYMBOL (Qread_non_nil_coding_system); | |
1040 DEFSYMBOL (Qevents_to_keys); | |
1041 DEFSYMBOL (Qcommand_debug_status); | |
1042 DEFSYMBOL (Qenable_recursive_minibuffers); | |
428 | 1043 |
1044 defsymbol (&QletX, "let*"); | |
563 | 1045 DEFSYMBOL (Qsave_excursion); |
428 | 1046 #if 0 /* ill-conceived */ |
563 | 1047 DEFSYMBOL (Qmouse_leave_buffer_hook); |
428 | 1048 #endif |
1049 | |
1050 DEFSUBR (Finteractive); | |
1051 DEFSUBR (Fquote_maybe); | |
1052 DEFSUBR (Fcall_interactively); | |
1053 DEFSUBR (Fprefix_numeric_value); | |
1054 } | |
1055 | |
1056 void | |
1057 vars_of_callint (void) | |
1058 { | |
1059 DEFVAR_LISP ("current-prefix-arg", &Vcurrent_prefix_arg /* | |
1060 The value of the prefix argument for this editing command. | |
1061 It may be a number, or the symbol `-' for just a minus sign as arg, | |
1062 or a list whose car is a number for just one or more C-U's | |
1063 or nil if no argument has been specified. | |
1064 This is what `(interactive "P")' returns. | |
1065 */ ); | |
1066 Vcurrent_prefix_arg = Qnil; | |
1067 | |
1068 DEFVAR_LISP ("command-history", &Vcommand_history /* | |
1069 List of recent commands that read arguments from terminal. | |
1070 Each command is represented as a form to evaluate. | |
1071 */ ); | |
1072 Vcommand_history = Qnil; | |
1073 | |
1074 DEFVAR_LISP ("command-debug-status", &Vcommand_debug_status /* | |
1075 Debugging status of current interactive command. | |
1076 Bound each time `call-interactively' is called; | |
1077 may be set by the debugger as a reminder for itself. | |
1078 */ ); | |
1079 Vcommand_debug_status = Qnil; | |
1080 | |
1081 #if 0 /* FSFmacs */ | |
1082 xxDEFVAR_LISP ("mark-even-if-inactive", &Vmark_even_if_inactive /* | |
1083 *Non-nil means you can use the mark even when inactive. | |
1084 This option makes a difference in Transient Mark mode. | |
1085 When the option is non-nil, deactivation of the mark | |
1086 turns off region highlighting, but commands that use the mark | |
1087 behave as if the mark were still active. | |
1088 */ ); | |
1089 Vmark_even_if_inactive = Qnil; | |
1090 #endif | |
1091 | |
1092 #if 0 /* Doesn't work and is totally ill-conceived anyway. */ | |
1093 xxDEFVAR_LISP ("mouse-leave-buffer-hook", &Vmouse_leave_buffer_hook /* | |
1094 Hook to run when about to switch windows with a mouse command. | |
1095 Its purpose is to give temporary modes such as Isearch mode | |
1096 a way to turn themselves off when a mouse command switches windows. | |
1097 */ ); | |
1098 Vmouse_leave_buffer_hook = Qnil; | |
1099 #endif | |
1100 } |