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