0
|
1 /* Editor command loop.
|
|
2 Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995, 1996 Ben Wing.
|
|
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: Mule 2.0. Not synched with FSF.
|
|
23 This was renamed from keyboard.c. However, it only contains the
|
|
24 command-loop stuff from FSF's keyboard.c; all the rest is in
|
|
25 event*.c, console.c, or signal.c. */
|
|
26
|
|
27 /* #### This module purports to separate out the command-loop stuff
|
|
28 from event-stream.c, but it doesn't really. Perhaps this file
|
|
29 should just be merged into event-stream.c, given its shortness. */
|
|
30
|
|
31 #include <config.h>
|
|
32 #include "lisp.h"
|
|
33
|
|
34 #include "buffer.h"
|
|
35 #include "commands.h"
|
|
36 #include "frame.h"
|
|
37 #include "events.h"
|
|
38 #include "macros.h"
|
|
39 #include "window.h"
|
|
40
|
|
41 /* Current depth in recursive edits. */
|
|
42 int command_loop_level;
|
|
43
|
|
44 /* Total number of times command_loop has read a key sequence. */
|
|
45 int num_input_keys;
|
|
46
|
|
47 #ifndef LISP_COMMAND_LOOP
|
|
48 /* Form to evaluate (if non-nil) when Emacs is started. */
|
|
49 Lisp_Object Vtop_level;
|
|
50 #else
|
|
51 /* Function to call to evaluate to read and process events. */
|
|
52 Lisp_Object Vcommand_loop;
|
|
53 #endif /* LISP_COMMAND_LOOP */
|
|
54
|
|
55 Lisp_Object Venter_window_hook, Vleave_window_hook;
|
|
56
|
|
57 /* The error handler. */
|
|
58 Lisp_Object Qcommand_error;
|
|
59
|
|
60 /* The emergency error handler, before we're ready. */
|
|
61 Lisp_Object Qreally_early_error_handler;
|
|
62
|
219
|
63 /* Variable defined in Lisp. */
|
|
64 Lisp_Object Qerrors_deactivate_region;
|
|
65
|
0
|
66 static Lisp_Object command_loop_1 (Lisp_Object dummy);
|
|
67
|
|
68 /* There are two possible command loops -- one written entirely in
|
|
69 C and one written mostly in Lisp, except stuff written in C for
|
|
70 speed. The advantage of the Lisp command loop is that the user
|
|
71 can specify their own command loop to use by changing the variable
|
|
72 `command-loop'. Its disadvantage is that it's slow. */
|
|
73
|
|
74 static Lisp_Object
|
|
75 default_error_handler (Lisp_Object data)
|
|
76 {
|
|
77 int speccount = specpdl_depth ();
|
|
78
|
219
|
79 /* None of this is invoked, normally. This code is almost identical
|
|
80 to the `command-error' function, except `command-error' does cool
|
|
81 tricks with sounds. This function is a fallback, invoked if
|
|
82 command-error is unavailable. */
|
|
83
|
0
|
84 Fding (Qnil, Qnil, Qnil);
|
219
|
85
|
|
86 if (!NILP (Fboundp (Qerrors_deactivate_region))
|
|
87 && !NILP (Fsymbol_value (Qerrors_deactivate_region)))
|
|
88 zmacs_deactivate_region ();
|
0
|
89 Fdiscard_input ();
|
|
90 specbind (Qinhibit_quit, Qt);
|
|
91 Vstandard_output = Qt;
|
|
92 Vstandard_input = Qt;
|
|
93 Vexecuting_macro = Qnil;
|
219
|
94 Fset (intern ("last-error"), data);
|
0
|
95 clear_echo_area (selected_frame (), Qnil, 0);
|
219
|
96 Fdisplay_error (data, Qt);
|
0
|
97 check_quit (); /* make Vquit_flag accurate */
|
|
98 Vquit_flag = Qnil;
|
|
99 return (unbind_to (speccount, Qt));
|
|
100 }
|
|
101
|
20
|
102 DEFUN ("really-early-error-handler", Freally_early_error_handler, 1, 1, 0, /*
|
0
|
103 You should almost certainly not be using this.
|
20
|
104 */
|
|
105 (x))
|
0
|
106 {
|
|
107 /* This is an error handler used when we're running temacs and when
|
|
108 we're in the early stages of XEmacs. No errors ought to be
|
|
109 occurring in those cases (or they ought to be trapped and
|
|
110 dealt with elsewhere), but if an error slips through, we need
|
|
111 to deal with it. We could write this function in Lisp (and it
|
|
112 used to be this way, at the beginning of loadup.el), but we do
|
|
113 it this way in case an error occurs before we get to loading
|
|
114 loadup.el. Note that there is also an `early-error-handler',
|
|
115 used in startup.el to catch more reasonable errors that
|
|
116 might occur during startup if the sysadmin or whoever fucked
|
|
117 up. This function is more conservative in what it does
|
|
118 and is used only as a last resort, indicating that the
|
|
119 programmer himself fucked up somewhere. */
|
|
120 stderr_out ("*** Error in XEmacs initialization");
|
|
121 Fprint (x, Qexternal_debugging_output);
|
|
122 stderr_out ("*** Backtrace\n");
|
|
123 Fbacktrace (Qexternal_debugging_output, Qt);
|
|
124 stderr_out ("*** Killing XEmacs\n");
|
|
125 return Fkill_emacs (make_int (-1));
|
|
126 }
|
|
127
|
|
128
|
|
129 /**********************************************************************/
|
|
130 /* Command-loop (in C) */
|
|
131 /**********************************************************************/
|
|
132
|
|
133 #ifndef LISP_COMMAND_LOOP
|
|
134
|
|
135 /* The guts of the command loop are in command_loop_1(). This function
|
|
136 doesn't catch errors, though -- that's the job of command_loop_2(),
|
|
137 which is a condition-case wrapper around command_loop_1().
|
|
138 command_loop_1() never returns, but may get thrown out of.
|
|
139
|
|
140 When an error occurs, cmd_error() is called, which usually
|
|
141 invokes the Lisp error handler in `command-error'; however,
|
|
142 a default error handler is provided if `command-error' is nil
|
|
143 (e.g. during startup). The purpose of the error handler is
|
|
144 simply to display the error message and do associated cleanup;
|
|
145 it does not need to throw anywhere. When the error handler
|
|
146 finishes, the condition-case in command_loop_2() will finish and
|
|
147 command_loop_2() will reinvoke command_loop_1().
|
|
148
|
|
149 command_loop_2() is invoked from three places: from
|
|
150 initial_command_loop() (called from main() at the end of
|
|
151 internal initialization), from the Lisp function `recursive-edit',
|
|
152 and from call_command_loop().
|
|
153
|
|
154 call_command_loop() is called when a macro is started and when the
|
|
155 minibuffer is entered; normal termination of the macro or
|
|
156 minibuffer causes a throw out of the recursive command loop. (To
|
|
157 'execute-kbd-macro for macros and 'exit for minibuffers. Note also
|
|
158 that the low-level minibuffer-entering function,
|
|
159 `read-minibuffer-internal', provides its own error handling and
|
|
160 does not need command_loop_2()'s error encapsulation; so it tells
|
|
161 call_command_loop() to invoke command_loop_1() directly.)
|
|
162
|
|
163 Note that both read-minibuffer-internal and recursive-edit set
|
|
164 up a catch for 'exit; this is why `abort-recursive-edit', which
|
|
165 throws to this catch, exits out of either one.
|
|
166
|
|
167 initial_command_loop(), called from main(), sets up a catch
|
|
168 for 'top-level when invoking command_loop_2(), allowing functions
|
|
169 to throw all the way to the top level if they really need to.
|
|
170 Before invoking command_loop_2(), initial_command_loop() calls
|
|
171 top_level_1(), which handles all of the startup stuff (creating
|
|
172 the initial frame, handling the command-line options, loading
|
|
173 the user's .emacs file, etc.). The function that actually does this
|
|
174 is in Lisp and is pointed to by the variable `top-level';
|
|
175 normally this function is `normal-top-level'. top_level_1() is
|
|
176 just an error-handling wrapper similar to command_loop_2().
|
|
177 Note also that initial_command_loop() sets up a catch for 'top-level
|
|
178 when invoking top_level_1(), just like when it invokes
|
|
179 command_loop_2(). */
|
|
180
|
|
181
|
|
182 static Lisp_Object
|
|
183 cmd_error (Lisp_Object data, Lisp_Object dummy)
|
|
184 {
|
|
185 /* This function can GC */
|
|
186 check_quit (); /* make Vquit_flag accurate */
|
|
187 Vquit_flag = Qnil;
|
|
188
|
|
189 any_console_state ();
|
|
190
|
|
191 if (!NILP (Ffboundp (Qcommand_error)))
|
|
192 return call1 (Qcommand_error, data);
|
|
193
|
|
194 return default_error_handler (data);
|
|
195 }
|
|
196
|
|
197 static Lisp_Object
|
|
198 top_level_1 (Lisp_Object dummy)
|
|
199 {
|
|
200 /* This function can GC */
|
|
201 /* On entry to the outer level, run the startup file */
|
|
202 if (!NILP (Vtop_level))
|
|
203 condition_case_1 (Qerror, Feval, Vtop_level, cmd_error, Qnil);
|
|
204 #if 1
|
|
205 else
|
|
206 {
|
|
207 message ("\ntemacs can only be run in -batch mode.");
|
|
208 noninteractive = 1; /* prevent things under kill-emacs from blowing up */
|
|
209 Fkill_emacs (make_int (-1));
|
|
210 }
|
|
211 #else
|
|
212 else if (purify_flag)
|
|
213 message ("Bare impure Emacs (standard Lisp code not loaded)");
|
|
214 else
|
|
215 message ("Bare Emacs (standard Lisp code not loaded)");
|
|
216 #endif
|
|
217
|
|
218 return Qnil;
|
|
219 }
|
|
220
|
|
221 /* Here we catch errors in execution of commands within the
|
|
222 editing loop, and reenter the editing loop.
|
|
223 When there is an error, cmd_error runs and the call
|
|
224 to condition_case_1() returns. */
|
|
225
|
|
226 /* Avoid confusing the compiler. A helper function for command_loop_2 */
|
|
227 static DOESNT_RETURN
|
|
228 command_loop_3 (void)
|
|
229 {
|
138
|
230 #ifdef LWLIB_MENUBARS_LUCID
|
|
231 extern int in_menu_callback; /* defined in menubar-x.c */
|
|
232 #endif /* LWLIB_MENUBARS_LUCID */
|
|
233
|
|
234 #ifdef LWLIB_MENUBARS_LUCID
|
|
235 /*
|
|
236 * #### Fix the menu code so this isn't necessary.
|
|
237 *
|
|
238 * We cannot allow the lwmenu code to be reentered, because the
|
|
239 * code is not written to be reentrant and will crash. Therefore
|
|
240 * paths from the menu callbacks back into the menu code have to
|
|
241 * be blocked. Fnext_event is the normal path into the menu code,
|
|
242 * but waiting to signal an error there is too late in case where
|
|
243 * a new command loop has been started. The error will be caught
|
|
244 * and Fnext_event will be called again, looping forever. So we
|
|
245 * signal an error here to avoid the loop.
|
|
246 */
|
|
247 if (in_menu_callback)
|
|
248 error ("Attempt to enter command_loop_3 inside menu callback");
|
|
249 #endif /* LWLIB_MENUBARS_LUCID */
|
0
|
250 /* This function can GC */
|
|
251 for (;;)
|
|
252 {
|
|
253 condition_case_1 (Qerror, command_loop_1, Qnil, cmd_error, Qnil);
|
|
254 /* #### wrong with selected-console? */
|
|
255 /* See command in initial_command_loop about why this value
|
|
256 is 0. */
|
|
257 reset_this_command_keys (Vselected_console, 0);
|
|
258 }
|
|
259 }
|
|
260
|
|
261 static Lisp_Object
|
|
262 command_loop_2 (Lisp_Object dummy)
|
|
263 {
|
|
264 command_loop_3(); /* doesn't return */
|
|
265 return Qnil;
|
|
266 }
|
|
267
|
|
268 /* This is called from emacs.c when it's done with initialization. */
|
|
269
|
|
270 DOESNT_RETURN
|
|
271 initial_command_loop (Lisp_Object load_me)
|
|
272 {
|
|
273 /* This function can GC */
|
|
274 if (!NILP (load_me))
|
|
275 Vtop_level = list2 (Qload, load_me);
|
|
276
|
|
277 /* First deal with startup and command-line arguments. A throw
|
|
278 to 'top-level gets us back here directly (does this ever happen?).
|
|
279 Otherwise, this function will return normally when all command-
|
|
280 line arguments have been processed, the user's initialization
|
|
281 file has been read in, and the first frame has been created. */
|
|
282 internal_catch (Qtop_level, top_level_1, Qnil, 0);
|
|
283
|
|
284 /* If an error occurred during startup and the initial console
|
|
285 wasn't created, then die now (the error was already printed out
|
|
286 on the terminal device). */
|
|
287 if (!noninteractive &&
|
|
288 (!CONSOLEP (Vselected_console) ||
|
|
289 CONSOLE_STREAM_P (XCONSOLE (Vselected_console))))
|
|
290 Fkill_emacs (make_int (-1));
|
185
|
291
|
0
|
292 /* End of -batch run causes exit here. */
|
|
293 if (noninteractive)
|
|
294 Fkill_emacs (Qt);
|
|
295
|
|
296 for (;;)
|
|
297 {
|
|
298 command_loop_level = 0;
|
|
299 MARK_MODELINE_CHANGED;
|
|
300 /* Now invoke the command loop. It never returns; however, a
|
|
301 throw to 'top-level will place us at the end of this loop. */
|
|
302 internal_catch (Qtop_level, command_loop_2, Qnil, 0);
|
|
303 /* #### wrong with selected-console? */
|
|
304 /* We don't actually call clear_echo_area() here, partially
|
|
305 at least because that runs Lisp code and it may be unsafe
|
|
306 to do so -- we are outside of the normal catches for
|
|
307 errors and such. */
|
|
308 reset_this_command_keys (Vselected_console, 0);
|
|
309 }
|
|
310 }
|
|
311
|
|
312 /* This function is invoked when a macro or minibuffer starts up.
|
|
313 Normal termination of the macro or minibuffer causes a throw past us.
|
|
314 See the comment above.
|
|
315
|
|
316 Note that this function never returns (but may be thrown out of). */
|
|
317
|
|
318 Lisp_Object
|
|
319 call_command_loop (Lisp_Object catch_errors)
|
|
320 {
|
|
321 /* This function can GC */
|
|
322 if (NILP (catch_errors))
|
|
323 return (command_loop_1 (Qnil));
|
|
324 else
|
|
325 return (command_loop_2 (Qnil));
|
|
326 }
|
|
327
|
|
328 static Lisp_Object
|
|
329 recursive_edit_unwind (Lisp_Object buffer)
|
|
330 {
|
|
331 if (!NILP (buffer))
|
|
332 Fset_buffer (buffer);
|
|
333
|
|
334 command_loop_level--;
|
|
335 MARK_MODELINE_CHANGED;
|
|
336
|
|
337 return Qnil;
|
|
338 }
|
|
339
|
20
|
340 DEFUN ("recursive-edit", Frecursive_edit, 0, 0, "", /*
|
0
|
341 Invoke the editor command loop recursively.
|
|
342 To get out of the recursive edit, a command can do `(throw 'exit nil)';
|
|
343 that tells this function to return.
|
|
344 Alternately, `(throw 'exit t)' makes this function signal an error.
|
20
|
345 */
|
|
346 ())
|
0
|
347 {
|
|
348 /* This function can GC */
|
|
349 Lisp_Object val;
|
|
350 int speccount = specpdl_depth ();
|
|
351
|
|
352 command_loop_level++;
|
|
353 MARK_MODELINE_CHANGED;
|
|
354
|
|
355 record_unwind_protect (recursive_edit_unwind,
|
|
356 ((current_buffer
|
|
357 != XBUFFER (XWINDOW (Fselected_window
|
|
358 (Qnil))->buffer))
|
|
359 ? Fcurrent_buffer ()
|
|
360 : Qnil));
|
|
361
|
|
362 specbind (Qstandard_output, Qt);
|
|
363 specbind (Qstandard_input, Qt);
|
|
364
|
|
365 val = internal_catch (Qexit, command_loop_2, Qnil, 0);
|
|
366
|
|
367 if (EQ (val, Qt))
|
|
368 /* Turn abort-recursive-edit into a quit. */
|
|
369 Fsignal (Qquit, Qnil);
|
|
370
|
|
371 return unbind_to (speccount, Qnil);
|
|
372 }
|
|
373
|
|
374 #endif /* !LISP_COMMAND_LOOP */
|
|
375
|
|
376
|
|
377 /**********************************************************************/
|
|
378 /* Alternate command-loop (largely in Lisp) */
|
|
379 /**********************************************************************/
|
|
380
|
|
381 #ifdef LISP_COMMAND_LOOP
|
|
382
|
|
383 static Lisp_Object
|
|
384 load1 (Lisp_Object name)
|
|
385 {
|
|
386 /* This function can GC */
|
|
387 call4 (Qload, name, Qnil, Qt, Qnil);
|
|
388 return (Qnil);
|
|
389 }
|
|
390
|
|
391 /* emergency backups for cold-load-stream use */
|
|
392 static Lisp_Object
|
|
393 cold_load_command_error (Lisp_Object datum, Lisp_Object ignored)
|
|
394 {
|
|
395 /* This function can GC */
|
|
396 check_quit (); /* make Vquit_flag accurate */
|
|
397 Vquit_flag = Qnil;
|
|
398
|
|
399 return default_error_handler (datum);
|
|
400 }
|
|
401
|
|
402 static Lisp_Object
|
|
403 cold_load_command_loop (Lisp_Object dummy)
|
|
404 {
|
|
405 /* This function can GC */
|
|
406 return (condition_case_1 (Qt,
|
|
407 command_loop_1, Qnil,
|
|
408 cold_load_command_error, Qnil));
|
|
409 }
|
|
410
|
|
411 Lisp_Object
|
|
412 call_command_loop (Lisp_Object catch_errors)
|
|
413 {
|
|
414 /* This function can GC */
|
|
415 reset_this_command_keys (Vselected_console, Qnil); /* #### bleagh */
|
|
416
|
|
417 loop:
|
|
418 for (;;)
|
|
419 {
|
|
420 if (NILP (Vcommand_loop))
|
|
421 break;
|
|
422 call1 (Vcommand_loop, catch_errors);
|
|
423 }
|
|
424
|
|
425 /* This isn't a "correct" definition, but you're pretty hosed if
|
|
426 you broke "command-loop" anyway */
|
|
427 /* #### not correct with Vselected_console */
|
|
428 XCONSOLE (Vselected_console)->prefix_arg = Qnil;
|
|
429 if (NILP (catch_errors))
|
|
430 Fcommand_loop_1 ();
|
185
|
431 else
|
0
|
432 internal_catch (Qtop_level,
|
|
433 cold_load_command_loop, Qnil, 0);
|
|
434 goto loop;
|
|
435 return Qnil;
|
|
436 }
|
|
437
|
|
438 static Lisp_Object
|
|
439 initial_error_handler (Lisp_Object datum, Lisp_Object ignored)
|
|
440 {
|
|
441 /* This function can GC */
|
|
442 Vcommand_loop = Qnil;
|
|
443 Fding (Qnil, Qnil, Qnil);
|
|
444
|
|
445 if (CONSP (datum) && EQ (XCAR (datum), Qquit))
|
|
446 /* Don't bother with the message */
|
|
447 return (Qt);
|
185
|
448
|
0
|
449 message ("Error in command-loop!!");
|
|
450 Fset (intern ("last-error"), datum); /* #### Better/different name? */
|
|
451 Fsit_for (make_int (2), Qnil);
|
|
452 cold_load_command_error (datum, Qnil);
|
|
453 return (Qt);
|
|
454 }
|
|
455
|
|
456 DOESNT_RETURN
|
|
457 initial_command_loop (Lisp_Object load_me)
|
|
458 {
|
|
459 /* This function can GC */
|
|
460 if (!NILP (load_me))
|
|
461 {
|
|
462 if (!NILP (condition_case_1 (Qt, load1, load_me,
|
|
463 initial_error_handler, Qnil)))
|
|
464 Fkill_emacs (make_int (-1));
|
|
465 }
|
|
466
|
|
467 for (;;)
|
|
468 {
|
|
469 command_loop_level = 0;
|
|
470 MARK_MODELINE_CHANGED;
|
|
471
|
|
472 condition_case_1 (Qt,
|
|
473 call_command_loop, Qtop_level,
|
|
474 initial_error_handler, Qnil);
|
|
475 }
|
|
476 }
|
|
477
|
|
478 #endif /* LISP_COMMAND_LOOP */
|
|
479
|
|
480
|
|
481 /**********************************************************************/
|
|
482 /* Guts of command loop */
|
|
483 /**********************************************************************/
|
|
484
|
|
485 static Lisp_Object
|
|
486 command_loop_1 (Lisp_Object dummy)
|
|
487 {
|
|
488 /* This function can GC */
|
|
489 /* #### not correct with Vselected_console */
|
|
490 XCONSOLE (Vselected_console)->prefix_arg = Qnil;
|
|
491 return (Fcommand_loop_1 ());
|
|
492 }
|
|
493
|
|
494 /* This is the actual command reading loop, sans error-handling
|
|
495 encapsulation. This is used for both the C and Lisp command
|
|
496 loops. Originally this function was written in Lisp when
|
|
497 the Lisp command loop was used, but it was too slow that way.
|
|
498
|
|
499 Under the C command loop, this function will never return
|
|
500 (although someone might throw past it). Under the Lisp
|
|
501 command loop, this will return only when the user specifies
|
|
502 a new command loop by changing the command-loop variable. */
|
|
503
|
20
|
504 DEFUN ("command-loop-1", Fcommand_loop_1, 0, 0, 0, /*
|
0
|
505 Invoke the internals of the canonical editor command loop.
|
|
506 Don't call this unless you know what you're doing.
|
20
|
507 */
|
|
508 ())
|
0
|
509 {
|
|
510 /* This function can GC */
|
189
|
511 Lisp_Object event = Fmake_event (Qnil, Qnil);
|
0
|
512 Lisp_Object old_loop = Qnil;
|
|
513 struct gcpro gcpro1, gcpro2;
|
|
514 int was_locked = in_single_console_state ();
|
|
515 GCPRO2 (event, old_loop);
|
|
516
|
|
517 /* cancel_echoing (); */
|
|
518 /* This magically makes single character keyboard macros work just
|
|
519 like the real thing. This is slightly bogus, but it's in here for
|
|
520 compatibility with Emacs 18. It's not even clear what the "right
|
|
521 thing" is. */
|
|
522 if (!(((STRINGP (Vexecuting_macro) || VECTORP (Vexecuting_macro))
|
|
523 && XINT (Flength (Vexecuting_macro)) == 1)))
|
|
524 Vlast_command = Qt;
|
|
525
|
|
526 #ifndef LISP_COMMAND_LOOP
|
|
527 while (1)
|
|
528 #else
|
|
529 old_loop = Vcommand_loop;
|
|
530 while (EQ (Vcommand_loop, old_loop))
|
|
531 #endif /* LISP_COMMAND_LOOP */
|
|
532 {
|
|
533 /* Make sure the current window's buffer is selected. */
|
|
534 {
|
|
535 Lisp_Object selected_window = Fselected_window (Qnil);
|
|
536
|
|
537 if (!NILP (selected_window) &&
|
|
538 (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer))
|
|
539 {
|
|
540 set_buffer_internal (XBUFFER (XWINDOW (selected_window)->buffer));
|
|
541 }
|
|
542 }
|
|
543
|
|
544 /* If ^G was typed before we got here (that is, before emacs was
|
|
545 idle and waiting for input) then we treat that as an interrupt. */
|
|
546 QUIT;
|
|
547
|
|
548 /* If minibuffer on and echo area in use, wait 2 sec and redraw
|
|
549 minibuffer. Treat a ^G here as a command, not an interrupt.
|
|
550 */
|
|
551 if (minibuf_level > 0 && echo_area_active (selected_frame ()))
|
|
552 {
|
|
553 /* Bind dont_check_for_quit to 1 so that C-g gets read in
|
|
554 rather than quitting back to the minibuffer. */
|
|
555 int count = specpdl_depth ();
|
|
556 begin_dont_check_for_quit ();
|
|
557 Fsit_for (make_int (2), Qnil);
|
|
558 clear_echo_area (selected_frame (), Qnil, 0);
|
|
559 unbind_to (count, Qnil);
|
|
560 }
|
|
561
|
|
562 Fnext_event (event, Qnil);
|
|
563 /* If ^G was typed while emacs was reading input from the user, then
|
|
564 Fnext_event() will have read it as a normal event and
|
|
565 next_event_internal() will have set Vquit_flag. We reset this
|
|
566 so that the ^G is treated as just another key. This is strange,
|
|
567 but it is what emacs 18 did.
|
|
568
|
|
569 Do not call check_quit() here. */
|
|
570 Vquit_flag = Qnil;
|
|
571 Fdispatch_event (event);
|
|
572
|
|
573 if (!was_locked)
|
|
574 any_console_state ();
|
185
|
575 #if defined (__SUNPRO_C) || defined (__SUNPRO_CC) || (defined (DEC_ALPHA) && defined (OSF1))
|
0
|
576 if (0) return Qnil; /* Shut up compiler */
|
|
577 #endif
|
|
578 }
|
|
579 #ifdef LISP_COMMAND_LOOP
|
|
580 UNGCPRO;
|
|
581 return Qnil;
|
|
582 #endif
|
|
583 }
|
|
584
|
|
585
|
|
586 /**********************************************************************/
|
|
587 /* Initialization */
|
|
588 /**********************************************************************/
|
|
589
|
|
590 void
|
|
591 syms_of_cmdloop (void)
|
|
592 {
|
|
593 defsymbol (&Qcommand_error, "command-error");
|
|
594 defsymbol (&Qreally_early_error_handler, "really-early-error-handler");
|
|
595 defsymbol (&Qtop_level, "top-level");
|
219
|
596 defsymbol (&Qerrors_deactivate_region, "errors-deactivate-region");
|
0
|
597
|
|
598 #ifndef LISP_COMMAND_LOOP
|
20
|
599 DEFSUBR (Frecursive_edit);
|
0
|
600 #endif
|
20
|
601 DEFSUBR (Freally_early_error_handler);
|
|
602 DEFSUBR (Fcommand_loop_1);
|
0
|
603 }
|
|
604
|
|
605 void
|
|
606 vars_of_cmdloop (void)
|
|
607 {
|
|
608 DEFVAR_INT ("command-loop-level", &command_loop_level /*
|
|
609 Number of recursive edits in progress.
|
|
610 */ );
|
|
611 command_loop_level = 0;
|
|
612
|
|
613 DEFVAR_LISP ("disabled-command-hook", &Vdisabled_command_hook /*
|
|
614 Value is called instead of any command that is disabled,
|
|
615 i.e. has a non-nil `disabled' property.
|
|
616 */ );
|
|
617 Vdisabled_command_hook = intern ("disabled-command-hook");
|
|
618
|
|
619 DEFVAR_LISP ("leave-window-hook", &Vleave_window_hook /*
|
|
620 Not yet implemented.
|
|
621 */ );
|
|
622 Vleave_window_hook = Qnil;
|
|
623
|
|
624 DEFVAR_LISP ("enter-window-hook", &Venter_window_hook /*
|
|
625 Not yet implemented.
|
|
626 */ );
|
|
627 Venter_window_hook = Qnil;
|
|
628
|
|
629 #ifndef LISP_COMMAND_LOOP
|
|
630 DEFVAR_LISP ("top-level", &Vtop_level /*
|
|
631 Form to evaluate when Emacs starts up.
|
|
632 Useful to set before you dump a modified Emacs.
|
|
633 */ );
|
|
634 Vtop_level = Qnil;
|
|
635 #else
|
|
636 DEFVAR_LISP ("command-loop", &Vcommand_loop /*
|
|
637 Function or one argument to call to read and process keyboard commands.
|
|
638 The passed argument specifies whether or not to handle errors.
|
|
639 */ );
|
|
640 Vcommand_loop = Qnil;
|
|
641 #endif /* LISP_COMMAND_LOOP */
|
|
642 }
|