Mercurial > emacs
annotate src/callint.c @ 1425:2c156e9908ad
* callint.c (Fcall_interactively): Change handling of 'e' spec;
this_command_keys is now a vector.
| author | Jim Blandy <jimb@redhat.com> |
|---|---|
| date | Sat, 17 Oct 1992 22:11:23 +0000 |
| parents | 54028d2538a4 |
| children | 098464e977d6 |
| rev | line source |
|---|---|
| 407 | 1 /* Call a Lisp function interactively. |
| 617 | 2 Copyright (C) 1985, 1986, 1992 Free Software Foundation, Inc. |
| 407 | 3 |
| 4 This file is part of GNU Emacs. | |
| 5 | |
| 6 GNU Emacs is free software; you can redistribute it and/or modify | |
| 7 it under the terms of the GNU General Public License as published by | |
| 8 the Free Software Foundation; either version 1, or (at your option) | |
| 9 any later version. | |
| 10 | |
| 11 GNU Emacs is distributed in the hope that it will be useful, | |
| 12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 GNU General Public License for more details. | |
| 15 | |
| 16 You should have received a copy of the GNU General Public License | |
| 17 along with GNU Emacs; see the file COPYING. If not, write to | |
| 18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
| 19 | |
| 20 | |
| 21 #include "config.h" | |
| 22 #include "lisp.h" | |
| 23 #include "buffer.h" | |
| 24 #include "commands.h" | |
| 516 | 25 #include "keyboard.h" |
| 407 | 26 #include "window.h" |
| 27 #include "mocklisp.h" | |
| 28 | |
| 29 extern char *index (); | |
| 30 | |
| 31 Lisp_Object Vprefix_arg, Vcurrent_prefix_arg, Qminus; | |
| 32 Lisp_Object Qcall_interactively; | |
| 33 Lisp_Object Vcommand_history; | |
| 34 | |
| 35 Lisp_Object Vcommand_debug_status, Qcommand_debug_status; | |
| 873 | 36 Lisp_Object Qenable_recursive_minibuffers; |
| 407 | 37 |
| 38 /* This comment supplies the doc string for interactive, | |
| 39 for make-docfile to see. We cannot put this in the real DEFUN | |
| 40 due to limits in the Unix cpp. | |
| 41 | |
| 42 DEFUN ("interactive", Ffoo, Sfoo, 0, 0, 0, | |
| 43 "Specify a way of parsing arguments for interactive use of a function.\n\ | |
| 44 For example, write\n\ | |
| 45 (defun foo (arg) \"Doc string\" (interactive \"p\") ...use arg...)\n\ | |
| 46 to make ARG be the prefix argument when `foo' is called as a command.\n\ | |
| 47 The \"call\" to `interactive' is actually a declaration rather than a function;\n\ | |
| 48 it tells `call-interactively' how to read arguments\n\ | |
| 49 to pass to the function.\n\ | |
| 50 When actually called, `interactive' just returns nil.\n\ | |
| 51 \n\ | |
| 52 The argument of `interactive' is usually a string containing a code letter\n\ | |
| 53 followed by a prompt. (Some code letters do not use I/O to get\n\ | |
| 54 the argument and do not need prompts.) To prompt for multiple arguments,\n\ | |
| 55 give a code letter, its prompt, a newline, and another code letter, etc.\n\ | |
| 56 Prompts are passed to format, and may use % escapes to print the\n\ | |
| 57 arguments that have already been read.\n\ | |
| 58 If the argument is not a string, it is evaluated to get a list of\n\ | |
| 59 arguments to pass to the function.\n\ | |
| 60 Just `(interactive)' means pass no args when calling interactively.\n\ | |
| 61 \nCode letters available are:\n\ | |
| 62 a -- Function name: symbol with a function definition.\n\ | |
| 63 b -- Name of existing buffer.\n\ | |
| 64 B -- Name of buffer, possibly nonexistent.\n\ | |
| 65 c -- Character.\n\ | |
| 66 C -- Command name: symbol with interactive function definition.\n\ | |
| 67 d -- Value of point as number. Does not do I/O.\n\ | |
| 68 D -- Directory name.\n\ | |
|
1383
54028d2538a4
* callint.c (Fcall_interactively): Allow multiple 'e' specs.
Jim Blandy <jimb@redhat.com>
parents:
1347
diff
changeset
|
69 e -- Event that invoked this command (value of `last-nonmenu-event').\n\ |
|
54028d2538a4
* callint.c (Fcall_interactively): Allow multiple 'e' specs.
Jim Blandy <jimb@redhat.com>
parents:
1347
diff
changeset
|
70 This skips events without parameters.\n\ |
|
54028d2538a4
* callint.c (Fcall_interactively): Allow multiple 'e' specs.
Jim Blandy <jimb@redhat.com>
parents:
1347
diff
changeset
|
71 If used more than once, the Nth 'e' returns the Nth parameterized event.\n\ |
| 407 | 72 f -- Existing file name.\n\ |
| 73 F -- Possibly nonexistent file name.\n\ | |
| 74 k -- Key sequence (string).\n\ | |
| 75 m -- Value of mark as number. Does not do I/O.\n\ | |
| 76 n -- Number read using minibuffer.\n\ | |
| 77 N -- Prefix arg converted to number, or if none, do like code `n'.\n\ | |
| 78 p -- Prefix arg converted to number. Does not do I/O.\n\ | |
| 79 P -- Prefix arg in raw form. Does not do I/O.\n\ | |
| 80 r -- Region: point and mark as 2 numeric args, smallest first. Does no I/O.\n\ | |
| 81 s -- Any string.\n\ | |
| 82 S -- Any symbol.\n\ | |
| 83 v -- Variable name: symbol that is user-variable-p.\n\ | |
| 84 x -- Lisp expression read but not evaluated.\n\ | |
| 85 X -- Lisp expression read and evaluated.\n\ | |
| 86 In addition, if the string begins with `*'\n\ | |
| 87 then an error is signaled if the buffer is read-only.\n\ | |
| 88 This happens before reading any arguments.\n\ | |
| 89 If the string begins with `@', then the window the mouse is over is selected\n\ | |
| 90 before anything else is done. You may use both `@' and `*';\n\ | |
| 91 they are processed in the order that they appear." | |
| 92 */ | |
| 93 | |
| 94 /* ARGSUSED */ | |
| 95 DEFUN ("interactive", Finteractive, Sinteractive, 0, UNEVALLED, 0, | |
| 96 0 /* See immediately above */) | |
| 97 (args) | |
| 98 Lisp_Object args; | |
| 99 { | |
| 100 return Qnil; | |
| 101 } | |
| 102 | |
| 103 /* Quotify EXP: if EXP is constant, return it. | |
| 104 If EXP is not constant, return (quote EXP). */ | |
| 105 Lisp_Object | |
| 106 quotify_arg (exp) | |
| 107 register Lisp_Object exp; | |
| 108 { | |
| 109 if (XTYPE (exp) != Lisp_Int && XTYPE (exp) != Lisp_String | |
| 485 | 110 && !NILP (exp) && !EQ (exp, Qt)) |
| 407 | 111 return Fcons (Qquote, Fcons (exp, Qnil)); |
| 112 | |
| 113 return exp; | |
| 114 } | |
| 115 | |
| 116 /* Modify EXP by quotifying each element (except the first). */ | |
| 117 Lisp_Object | |
| 118 quotify_args (exp) | |
| 119 Lisp_Object exp; | |
| 120 { | |
| 121 register Lisp_Object tail; | |
| 122 register struct Lisp_Cons *ptr; | |
| 123 for (tail = exp; CONSP (tail); tail = ptr->cdr) | |
| 124 { | |
| 125 ptr = XCONS (tail); | |
| 126 ptr->car = quotify_arg (ptr->car); | |
| 127 } | |
| 128 return exp; | |
| 129 } | |
| 130 | |
| 131 char *callint_argfuns[] | |
| 132 = {"", "point", "mark", "region-beginning", "region-end"}; | |
| 133 | |
| 134 static void | |
| 135 check_mark () | |
| 136 { | |
| 137 Lisp_Object tem = Fmarker_buffer (current_buffer->mark); | |
| 485 | 138 if (NILP (tem) || (XBUFFER (tem) != current_buffer)) |
| 407 | 139 error ("The mark is not set now"); |
| 140 } | |
| 141 | |
| 142 | |
| 143 DEFUN ("call-interactively", Fcall_interactively, Scall_interactively, 1, 2, 0, | |
| 144 "Call FUNCTION, reading args according to its interactive calling specs.\n\ | |
| 145 The function contains a specification of how to do the argument reading.\n\ | |
| 146 In the case of user-defined functions, this is specified by placing a call\n\ | |
| 147 to the function `interactive' at the top level of the function body.\n\ | |
| 148 See `interactive'.\n\ | |
| 149 \n\ | |
| 150 Optional second arg RECORD-FLAG non-nil\n\ | |
| 151 means unconditionally put this command in the command-history.\n\ | |
| 152 Otherwise, this is done only if an arg is read using the minibuffer.") | |
| 153 (function, record) | |
| 154 Lisp_Object function, record; | |
| 155 { | |
| 156 Lisp_Object *args, *visargs; | |
| 157 unsigned char **argstrings; | |
| 158 Lisp_Object fun; | |
| 159 Lisp_Object funcar; | |
| 160 Lisp_Object specs; | |
| 161 Lisp_Object teml; | |
| 873 | 162 Lisp_Object enable; |
| 163 int speccount = specpdl_ptr - specpdl; | |
| 407 | 164 |
|
1383
54028d2538a4
* callint.c (Fcall_interactively): Allow multiple 'e' specs.
Jim Blandy <jimb@redhat.com>
parents:
1347
diff
changeset
|
165 /* The index of the next element of this_command_keys to examine for |
|
54028d2538a4
* callint.c (Fcall_interactively): Allow multiple 'e' specs.
Jim Blandy <jimb@redhat.com>
parents:
1347
diff
changeset
|
166 the 'e' interactive code. */ |
|
54028d2538a4
* callint.c (Fcall_interactively): Allow multiple 'e' specs.
Jim Blandy <jimb@redhat.com>
parents:
1347
diff
changeset
|
167 int next_event = 0; |
|
54028d2538a4
* callint.c (Fcall_interactively): Allow multiple 'e' specs.
Jim Blandy <jimb@redhat.com>
parents:
1347
diff
changeset
|
168 |
| 407 | 169 Lisp_Object prefix_arg; |
| 170 unsigned char *string; | |
| 171 unsigned char *tem; | |
| 438 | 172 |
| 173 /* If varies[i] > 0, the i'th argument shouldn't just have its value | |
| 174 in this call quoted in the command history. It should be | |
| 175 recorded as a call to the function named callint_argfuns[varies[i]]. */ | |
| 407 | 176 int *varies; |
| 438 | 177 |
| 407 | 178 register int i, j; |
| 179 int count, foo; | |
| 180 char prompt[100]; | |
| 181 char prompt1[100]; | |
| 182 char *tem1; | |
| 183 int arg_from_tty = 0; | |
| 184 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | |
| 185 | |
| 732 | 186 /* Save this now, since use of minibuffer will clobber it. */ |
| 407 | 187 prefix_arg = Vcurrent_prefix_arg; |
| 188 | |
| 617 | 189 retry: |
| 407 | 190 |
|
1115
eb7f1ab33a9d
* callint.c (Fcall_interactively): Remove the 'K' interactive
Jim Blandy <jimb@redhat.com>
parents:
1084
diff
changeset
|
191 if (XTYPE (function) == Lisp_Symbol) |
|
eb7f1ab33a9d
* callint.c (Fcall_interactively): Remove the 'K' interactive
Jim Blandy <jimb@redhat.com>
parents:
1084
diff
changeset
|
192 enable = Fget (function, Qenable_recursive_minibuffers); |
| 873 | 193 |
| 648 | 194 fun = indirect_function (function); |
| 407 | 195 |
| 196 specs = Qnil; | |
| 197 string = 0; | |
| 198 | |
| 199 /* Decode the kind of function. Either handle it and return, | |
| 200 or go to `lose' if not interactive, or go to `retry' | |
| 201 to specify a different function, or set either STRING or SPECS. */ | |
| 202 | |
| 203 if (XTYPE (fun) == Lisp_Subr) | |
| 204 { | |
| 205 string = (unsigned char *) XSUBR (fun)->prompt; | |
| 206 if (!string) | |
| 207 { | |
| 208 lose: | |
| 209 function = wrong_type_argument (Qcommandp, function, 0); | |
| 210 goto retry; | |
| 211 } | |
| 212 if ((int) string == 1) | |
| 213 /* Let SPECS (which is nil) be used as the args. */ | |
| 214 string = 0; | |
| 215 } | |
| 216 else if (XTYPE (fun) == Lisp_Compiled) | |
| 217 { | |
| 218 if (XVECTOR (fun)->size <= COMPILED_INTERACTIVE) | |
| 219 goto lose; | |
| 220 specs = XVECTOR (fun)->contents[COMPILED_INTERACTIVE]; | |
| 221 } | |
| 222 else if (!CONSP (fun)) | |
| 223 goto lose; | |
| 224 else if (funcar = Fcar (fun), EQ (funcar, Qautoload)) | |
| 225 { | |
| 226 GCPRO2 (function, prefix_arg); | |
| 227 do_autoload (fun, function); | |
| 228 UNGCPRO; | |
| 229 goto retry; | |
| 230 } | |
| 231 else if (EQ (funcar, Qlambda)) | |
| 232 { | |
| 233 specs = Fassq (Qinteractive, Fcdr (Fcdr (fun))); | |
| 485 | 234 if (NILP (specs)) |
| 407 | 235 goto lose; |
| 236 specs = Fcar (Fcdr (specs)); | |
| 237 } | |
| 238 else if (EQ (funcar, Qmocklisp)) | |
| 239 return ml_apply (fun, Qinteractive); | |
| 240 else | |
| 241 goto lose; | |
| 242 | |
| 617 | 243 /* If either specs or string is set to a string, use it. */ |
| 407 | 244 if (XTYPE (specs) == Lisp_String) |
| 617 | 245 { |
| 246 /* Make a copy of string so that if a GC relocates specs, | |
| 247 `string' will still be valid. */ | |
| 732 | 248 string = (unsigned char *) alloca (XSTRING (specs)->size + 1); |
| 617 | 249 bcopy (XSTRING (specs)->data, string, XSTRING (specs)->size + 1); |
| 250 } | |
| 407 | 251 else if (string == 0) |
| 252 { | |
| 253 i = num_input_chars; | |
| 254 specs = Feval (specs); | |
| 485 | 255 if (i != num_input_chars || !NILP (record)) |
| 407 | 256 Vcommand_history |
| 257 = Fcons (Fcons (function, quotify_args (Fcopy_sequence (specs))), | |
| 258 Vcommand_history); | |
| 259 return apply1 (function, specs); | |
| 260 } | |
| 261 | |
| 262 /* Here if function specifies a string to control parsing the defaults */ | |
| 263 | |
| 264 /* Handle special starting chars `*' and `@'. */ | |
| 265 while (1) | |
| 266 { | |
| 267 if (*string == '*') | |
| 268 { | |
| 269 string++; | |
| 485 | 270 if (!NILP (current_buffer->read_only)) |
| 407 | 271 Fbarf_if_buffer_read_only (); |
| 272 } | |
| 273 else if (*string == '@') | |
| 274 { | |
| 275 string++; | |
| 485 | 276 if (!NILP (Vmouse_window)) |
| 407 | 277 Fselect_window (Vmouse_window); |
| 278 } | |
| 279 else break; | |
| 280 } | |
| 281 | |
| 282 /* Count the number of arguments the interactive spec would have | |
| 283 us give to the function. */ | |
| 284 tem = string; | |
| 285 for (j = 0; *tem; j++) | |
| 286 { | |
| 287 /* 'r' specifications ("point and mark as 2 numeric args") | |
| 288 produce *two* arguments. */ | |
| 289 if (*tem == 'r') j++; | |
| 290 tem = (unsigned char *) index (tem, '\n'); | |
| 291 if (tem) | |
| 292 tem++; | |
| 293 else | |
| 294 tem = (unsigned char *) ""; | |
| 295 } | |
| 296 count = j; | |
| 297 | |
| 298 args = (Lisp_Object *) alloca ((count + 1) * sizeof (Lisp_Object)); | |
| 299 visargs = (Lisp_Object *) alloca ((count + 1) * sizeof (Lisp_Object)); | |
| 300 argstrings = (unsigned char **) alloca ((count + 1) * sizeof (char *)); | |
| 301 varies = (int *) alloca ((count + 1) * sizeof (int)); | |
| 302 | |
| 303 for (i = 0; i < (count + 1); i++) | |
| 304 { | |
| 305 args[i] = Qnil; | |
| 306 visargs[i] = Qnil; | |
| 307 varies[i] = 0; | |
| 308 } | |
| 309 | |
| 310 GCPRO4 (prefix_arg, function, *args, *visargs); | |
| 311 gcpro3.nvars = (count + 1); | |
| 312 gcpro4.nvars = (count + 1); | |
| 313 | |
| 873 | 314 if (!NILP (enable)) |
| 315 specbind (Qenable_recursive_minibuffers, Qt); | |
| 316 | |
| 407 | 317 tem = string; |
| 617 | 318 for (i = 1; *tem; i++) |
| 407 | 319 { |
| 320 strncpy (prompt1, tem + 1, sizeof prompt1 - 1); | |
| 321 prompt1[sizeof prompt1 - 1] = 0; | |
| 322 tem1 = index (prompt1, '\n'); | |
| 323 if (tem1) *tem1 = 0; | |
| 324 /* Fill argstrings with a vector of C strings | |
| 325 corresponding to the Lisp strings in visargs. */ | |
| 326 for (j = 1; j < i; j++) | |
| 327 argstrings[j] | |
| 328 = EQ (visargs[j], Qnil) | |
| 329 ? (unsigned char *) "" | |
| 617 | 330 : XSTRING (visargs[j])->data; |
| 407 | 331 |
| 332 doprnt (prompt, sizeof prompt, prompt1, 0, j - 1, argstrings + 1); | |
| 333 | |
| 334 switch (*tem) | |
| 335 { | |
| 336 case 'a': /* Symbol defined as a function */ | |
| 337 visargs[i] = Fcompleting_read (build_string (prompt), | |
| 338 Vobarray, Qfboundp, Qt, Qnil, Qnil); | |
| 339 /* Passing args[i] directly stimulates compiler bug */ | |
| 340 teml = visargs[i]; | |
| 341 args[i] = Fintern (teml, Qnil); | |
| 342 break; | |
| 343 | |
| 344 case 'b': /* Name of existing buffer */ | |
| 345 args[i] = Fcurrent_buffer (); | |
| 346 if (EQ (selected_window, minibuf_window)) | |
|
1347
ac3a893b9bb9
(Fcall_interactively): Pass 2nd arg to Fother_buffer.
Richard M. Stallman <rms@gnu.org>
parents:
1115
diff
changeset
|
347 args[i] = Fother_buffer (args[i], Qnil); |
| 407 | 348 args[i] = Fread_buffer (build_string (prompt), args[i], Qt); |
| 349 break; | |
| 350 | |
| 351 case 'B': /* Name of buffer, possibly nonexistent */ | |
| 352 args[i] = Fread_buffer (build_string (prompt), | |
|
1347
ac3a893b9bb9
(Fcall_interactively): Pass 2nd arg to Fother_buffer.
Richard M. Stallman <rms@gnu.org>
parents:
1115
diff
changeset
|
353 Fother_buffer (Fcurrent_buffer (), Qnil), |
|
ac3a893b9bb9
(Fcall_interactively): Pass 2nd arg to Fother_buffer.
Richard M. Stallman <rms@gnu.org>
parents:
1115
diff
changeset
|
354 Qnil); |
| 407 | 355 break; |
| 356 | |
| 357 case 'c': /* Character */ | |
| 358 message1 (prompt); | |
| 359 args[i] = Fread_char (); | |
| 360 /* Passing args[i] directly stimulates compiler bug */ | |
| 361 teml = args[i]; | |
| 362 visargs[i] = Fchar_to_string (teml); | |
| 363 break; | |
| 364 | |
| 365 case 'C': /* Command: symbol with interactive function */ | |
| 366 visargs[i] = Fcompleting_read (build_string (prompt), | |
| 367 Vobarray, Qcommandp, Qt, Qnil, Qnil); | |
| 368 /* Passing args[i] directly stimulates compiler bug */ | |
| 369 teml = visargs[i]; | |
| 370 args[i] = Fintern (teml, Qnil); | |
| 371 break; | |
| 372 | |
| 373 case 'd': /* Value of point. Does not do I/O. */ | |
| 374 XFASTINT (args[i]) = point; | |
| 375 /* visargs[i] = Qnil; */ | |
| 376 varies[i] = 1; | |
| 377 break; | |
| 378 | |
| 379 case 'D': /* Directory name. */ | |
| 380 args[i] = Fread_file_name (build_string (prompt), Qnil, | |
| 381 current_buffer->directory, Qlambda, Qnil); | |
| 382 break; | |
| 383 | |
| 384 case 'f': /* Existing file name. */ | |
| 385 args[i] = Fread_file_name (build_string (prompt), | |
| 386 Qnil, Qnil, Qlambda, Qnil); | |
| 387 break; | |
| 388 | |
| 389 case 'F': /* Possibly nonexistent file name. */ | |
| 390 args[i] = Fread_file_name (build_string (prompt), | |
| 391 Qnil, Qnil, Qnil, Qnil); | |
| 392 break; | |
| 393 | |
| 394 case 'k': /* Key sequence (string) */ | |
| 438 | 395 args[i] = Fread_key_sequence (build_string (prompt), Qnil); |
| 407 | 396 teml = args[i]; |
| 397 visargs[i] = Fkey_description (teml); | |
| 398 break; | |
| 399 | |
|
1383
54028d2538a4
* callint.c (Fcall_interactively): Allow multiple 'e' specs.
Jim Blandy <jimb@redhat.com>
parents:
1347
diff
changeset
|
400 case 'e': /* The invoking event. */ |
|
54028d2538a4
* callint.c (Fcall_interactively): Allow multiple 'e' specs.
Jim Blandy <jimb@redhat.com>
parents:
1347
diff
changeset
|
401 /* Find the next parameterized event. */ |
|
54028d2538a4
* callint.c (Fcall_interactively): Allow multiple 'e' specs.
Jim Blandy <jimb@redhat.com>
parents:
1347
diff
changeset
|
402 while (next_event < this_command_key_count |
|
1425
2c156e9908ad
* callint.c (Fcall_interactively): Change handling of 'e' spec;
Jim Blandy <jimb@redhat.com>
parents:
1383
diff
changeset
|
403 && ! (EVENT_HAS_PARAMETERS |
|
2c156e9908ad
* callint.c (Fcall_interactively): Change handling of 'e' spec;
Jim Blandy <jimb@redhat.com>
parents:
1383
diff
changeset
|
404 (XVECTOR (this_command_keys)->contents[next_event]))) |
|
1383
54028d2538a4
* callint.c (Fcall_interactively): Allow multiple 'e' specs.
Jim Blandy <jimb@redhat.com>
parents:
1347
diff
changeset
|
405 next_event++; |
|
54028d2538a4
* callint.c (Fcall_interactively): Allow multiple 'e' specs.
Jim Blandy <jimb@redhat.com>
parents:
1347
diff
changeset
|
406 if (next_event >= this_command_key_count) |
|
54028d2538a4
* callint.c (Fcall_interactively): Allow multiple 'e' specs.
Jim Blandy <jimb@redhat.com>
parents:
1347
diff
changeset
|
407 error ("%s must be bound to an event with parameters", |
| 438 | 408 (XTYPE (function) == Lisp_Symbol |
| 409 ? (char *) XSYMBOL (function)->name->data | |
|
1383
54028d2538a4
* callint.c (Fcall_interactively): Allow multiple 'e' specs.
Jim Blandy <jimb@redhat.com>
parents:
1347
diff
changeset
|
410 : "command")); |
|
1425
2c156e9908ad
* callint.c (Fcall_interactively): Change handling of 'e' spec;
Jim Blandy <jimb@redhat.com>
parents:
1383
diff
changeset
|
411 args[i] = XVECTOR (this_command_keys)->contents[next_event++]; |
| 732 | 412 varies[i] = -1; |
| 438 | 413 break; |
| 414 | |
| 407 | 415 case 'm': /* Value of mark. Does not do I/O. */ |
| 416 check_mark (); | |
| 417 /* visargs[i] = Qnil; */ | |
| 418 XFASTINT (args[i]) = marker_position (current_buffer->mark); | |
| 419 varies[i] = 2; | |
| 420 break; | |
| 421 | |
| 422 case 'N': /* Prefix arg, else number from minibuffer */ | |
| 485 | 423 if (!NILP (prefix_arg)) |
| 407 | 424 goto have_prefix_arg; |
| 425 case 'n': /* Read number from minibuffer. */ | |
| 426 do | |
| 427 args[i] = Fread_minibuffer (build_string (prompt), Qnil); | |
| 621 | 428 while (! NUMBERP (args[i])); |
| 407 | 429 visargs[i] = last_minibuf_string; |
| 430 break; | |
| 431 | |
| 432 case 'P': /* Prefix arg in raw form. Does no I/O. */ | |
| 433 have_prefix_arg: | |
| 434 args[i] = prefix_arg; | |
| 435 /* visargs[i] = Qnil; */ | |
| 436 varies[i] = -1; | |
| 437 break; | |
| 438 | |
| 439 case 'p': /* Prefix arg converted to number. No I/O. */ | |
| 440 args[i] = Fprefix_numeric_value (prefix_arg); | |
| 441 /* visargs[i] = Qnil; */ | |
| 442 varies[i] = -1; | |
| 443 break; | |
| 444 | |
| 445 case 'r': /* Region, point and mark as 2 args. */ | |
| 446 check_mark (); | |
| 447 /* visargs[i+1] = Qnil; */ | |
| 448 foo = marker_position (current_buffer->mark); | |
| 449 /* visargs[i] = Qnil; */ | |
| 450 XFASTINT (args[i]) = point < foo ? point : foo; | |
| 451 varies[i] = 3; | |
| 452 XFASTINT (args[++i]) = point > foo ? point : foo; | |
| 453 varies[i] = 4; | |
| 454 break; | |
| 455 | |
| 456 case 's': /* String read via minibuffer. */ | |
| 457 args[i] = Fread_string (build_string (prompt), Qnil); | |
| 458 break; | |
| 459 | |
| 460 case 'S': /* Any symbol. */ | |
|
863
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
819
diff
changeset
|
461 visargs[i] = Fread_no_blanks_input (build_string (prompt), Qnil); |
| 407 | 462 /* Passing args[i] directly stimulates compiler bug */ |
| 463 teml = visargs[i]; | |
| 464 args[i] = Fintern (teml, Qnil); | |
| 465 break; | |
| 466 | |
| 467 case 'v': /* Variable name: symbol that is | |
| 468 user-variable-p. */ | |
| 469 args[i] = Fread_variable (build_string (prompt)); | |
| 470 visargs[i] = last_minibuf_string; | |
| 471 break; | |
| 472 | |
| 473 case 'x': /* Lisp expression read but not evaluated */ | |
| 474 args[i] = Fread_minibuffer (build_string (prompt), Qnil); | |
| 475 visargs[i] = last_minibuf_string; | |
| 476 break; | |
| 477 | |
| 478 case 'X': /* Lisp expression read and evaluated */ | |
| 479 args[i] = Feval_minibuffer (build_string (prompt), Qnil); | |
| 480 visargs[i] = last_minibuf_string; | |
| 481 break; | |
| 482 | |
| 483 default: | |
| 484 error ("Invalid control letter \"%c\" (%03o) in interactive calling string", | |
| 485 *tem, *tem); | |
| 486 } | |
| 487 | |
| 488 if (varies[i] == 0) | |
| 489 arg_from_tty = 1; | |
| 490 | |
| 485 | 491 if (NILP (visargs[i]) && XTYPE (args[i]) == Lisp_String) |
| 407 | 492 visargs[i] = args[i]; |
| 493 | |
| 494 tem = (unsigned char *) index (tem, '\n'); | |
| 495 if (tem) tem++; | |
| 496 else tem = (unsigned char *) ""; | |
| 497 } | |
| 873 | 498 unbind_to (speccount, Qnil); |
| 407 | 499 |
| 500 QUIT; | |
| 501 | |
| 502 args[0] = function; | |
| 503 | |
| 485 | 504 if (arg_from_tty || !NILP (record)) |
| 407 | 505 { |
| 506 visargs[0] = function; | |
| 438 | 507 for (i = 1; i < count + 1; i++) |
| 508 if (varies[i] > 0) | |
| 407 | 509 visargs[i] = Fcons (intern (callint_argfuns[varies[i]]), Qnil); |
| 510 else | |
| 511 visargs[i] = quotify_arg (args[i]); | |
| 512 Vcommand_history = Fcons (Flist (count + 1, visargs), | |
| 513 Vcommand_history); | |
| 514 } | |
| 515 | |
| 516 { | |
| 517 Lisp_Object val; | |
| 518 specbind (Qcommand_debug_status, Qnil); | |
| 519 | |
| 520 val = Ffuncall (count + 1, args); | |
| 521 UNGCPRO; | |
| 522 return unbind_to (speccount, val); | |
| 523 } | |
| 524 } | |
| 525 | |
| 526 DEFUN ("prefix-numeric-value", Fprefix_numeric_value, Sprefix_numeric_value, | |
| 527 1, 1, 0, | |
| 528 "Return numeric meaning of raw prefix argument ARG.\n\ | |
| 529 A raw prefix argument is what you get from `(interactive \"P\")'.\n\ | |
| 530 Its numeric meaning is what you would get from `(interactive \"p\")'.") | |
| 531 (raw) | |
| 532 Lisp_Object raw; | |
| 533 { | |
| 534 Lisp_Object val; | |
| 535 | |
| 536 /* Tag val as an integer, so the rest of the assignments | |
| 537 may use XSETINT. */ | |
| 538 XFASTINT (val) = 0; | |
| 539 | |
| 485 | 540 if (NILP (raw)) |
| 407 | 541 XFASTINT (val) = 1; |
|
819
5bbabfcef929
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
732
diff
changeset
|
542 else if (EQ (raw, Qminus)) |
| 407 | 543 XSETINT (val, -1); |
| 544 else if (CONSP (raw)) | |
| 545 XSETINT (val, XINT (XCONS (raw)->car)); | |
| 546 else if (XTYPE (raw) == Lisp_Int) | |
| 547 val = raw; | |
| 548 else | |
| 549 XFASTINT (val) = 1; | |
| 550 | |
| 551 return val; | |
| 552 } | |
| 553 | |
| 554 syms_of_callint () | |
| 555 { | |
| 556 Qminus = intern ("-"); | |
| 557 staticpro (&Qminus); | |
| 558 | |
| 559 Qcall_interactively = intern ("call-interactively"); | |
| 560 staticpro (&Qcall_interactively); | |
| 561 | |
| 562 Qcommand_debug_status = intern ("command-debug-status"); | |
| 563 staticpro (&Qcommand_debug_status); | |
| 564 | |
| 873 | 565 Qenable_recursive_minibuffers = intern ("enable-recursive-minibuffers"); |
| 566 staticpro (&Qenable_recursive_minibuffers); | |
| 567 | |
| 407 | 568 DEFVAR_LISP ("prefix-arg", &Vprefix_arg, |
| 569 "The value of the prefix argument for the next editing command.\n\ | |
| 570 It may be a number, or the symbol `-' for just a minus sign as arg,\n\ | |
| 571 or a list whose car is a number for just one or more C-U's\n\ | |
| 572 or nil if no argument has been specified.\n\ | |
| 573 \n\ | |
| 574 You cannot examine this variable to find the argument for this command\n\ | |
| 575 since it has been set to nil by the time you can look.\n\ | |
| 576 Instead, you should use the variable `current-prefix-arg', although\n\ | |
| 577 normally commands can get this prefix argument with (interactive \"P\")."); | |
| 578 Vprefix_arg = Qnil; | |
| 579 | |
| 580 DEFVAR_LISP ("current-prefix-arg", &Vcurrent_prefix_arg, | |
| 581 "The value of the prefix argument for this editing command.\n\ | |
| 582 It may be a number, or the symbol `-' for just a minus sign as arg,\n\ | |
| 583 or a list whose car is a number for just one or more C-U's\n\ | |
| 584 or nil if no argument has been specified.\n\ | |
| 585 This is what `(interactive \"P\")' returns."); | |
| 586 Vcurrent_prefix_arg = Qnil; | |
| 587 | |
| 588 DEFVAR_LISP ("command-history", &Vcommand_history, | |
| 589 "List of recent commands that read arguments from terminal.\n\ | |
| 590 Each command is represented as a form to evaluate."); | |
| 591 Vcommand_history = Qnil; | |
| 592 | |
| 593 DEFVAR_LISP ("command-debug-status", &Vcommand_debug_status, | |
| 594 "Debugging status of current interactive command.\n\ | |
| 595 Bound each time `call-interactively' is called;\n\ | |
| 596 may be set by the debugger as a reminder for itself."); | |
| 597 Vcommand_debug_status = Qnil; | |
| 598 | |
| 599 defsubr (&Sinteractive); | |
| 600 defsubr (&Scall_interactively); | |
| 601 defsubr (&Sprefix_numeric_value); | |
| 602 } |
