0
|
1 /* The portable interface to event streams.
|
|
2 Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Board of Trustees, University of Illinois.
|
|
4 Copyright (C) 1995 Sun Microsystems, Inc.
|
|
5 Copyright (C) 1995, 1996 Ben Wing.
|
|
6
|
|
7 This file is part of XEmacs.
|
|
8
|
|
9 XEmacs is free software; you can redistribute it and/or modify it
|
|
10 under the terms of the GNU General Public License as published by the
|
|
11 Free Software Foundation; either version 2, or (at your option) any
|
|
12 later version.
|
|
13
|
|
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
17 for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with XEmacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 Boston, MA 02111-1307, USA. */
|
|
23
|
|
24 /* Synched up with: Not in FSF. */
|
|
25
|
|
26 /* This file has been Mule-ized. */
|
|
27
|
|
28 /*
|
|
29 * DANGER!!
|
|
30 *
|
|
31 * If you ever change ANYTHING in this file, you MUST run the
|
|
32 * testcases at the end to make sure that you haven't changed
|
|
33 * the semantics of recent-keys, last-input-char, or keyboard
|
|
34 * macros. You'd be surprised how easy it is to break this.
|
|
35 *
|
|
36 */
|
|
37
|
|
38 #include <config.h>
|
|
39 #include "lisp.h"
|
|
40
|
|
41 #include "buffer.h"
|
|
42 #include "commands.h"
|
|
43 #include "device.h"
|
|
44 #include "elhash.h"
|
|
45 #include "events.h"
|
|
46 #include "frame.h"
|
|
47 #include "insdel.h" /* for buffer_reset_changes */
|
|
48 #include "keymap.h"
|
|
49 #include "lstream.h"
|
|
50 #include "macros.h" /* for defining_keyboard_macro */
|
|
51 #include "opaque.h"
|
|
52 #include "process.h"
|
|
53 #include "window.h"
|
|
54
|
|
55 #include "sysdep.h" /* init_poll_for_quit() */
|
|
56 #include "syssignal.h" /* SIGCHLD, etc. */
|
|
57 #include "systime.h" /* to set Vlast_input_time */
|
|
58
|
100
|
59 #include "events-mod.h"
|
|
60
|
70
|
61 #ifdef MULE
|
|
62 #include "mule-coding.h"
|
|
63 #endif
|
|
64
|
0
|
65 #include <errno.h>
|
|
66
|
|
67 /* The number of keystrokes between auto-saves. */
|
|
68 static int auto_save_interval;
|
|
69
|
|
70 Lisp_Object Qundefined_keystroke_sequence;
|
|
71
|
|
72 Lisp_Object Qcommand_execute;
|
|
73
|
|
74 Lisp_Object Qcommand_event_p;
|
|
75
|
|
76 /* Hooks to run before and after each command. */
|
|
77 Lisp_Object Vpre_command_hook, Vpost_command_hook;
|
|
78 Lisp_Object Qpre_command_hook, Qpost_command_hook;
|
|
79
|
|
80 /* Hook run when XEmacs is about to be idle. */
|
|
81 Lisp_Object Qpre_idle_hook, Vpre_idle_hook;
|
|
82
|
72
|
83 /* Control gratuitous keyboard focus throwing. */
|
|
84 int focus_follows_mouse;
|
|
85
|
0
|
86 #ifdef ILL_CONCEIVED_HOOK
|
|
87 /* Hook run after a command if there's no more input soon. */
|
|
88 Lisp_Object Qpost_command_idle_hook, Vpost_command_idle_hook;
|
|
89
|
|
90 /* Delay time in microseconds before running post-command-idle-hook. */
|
|
91 int post_command_idle_delay;
|
|
92 #endif /* ILL_CONCEIVED_HOOK */
|
|
93
|
|
94 #ifdef DEFERRED_ACTION_CRAP
|
|
95 /* List of deferred actions to be performed at a later time.
|
|
96 The precise format isn't relevant here; we just check whether it is nil. */
|
|
97 Lisp_Object Vdeferred_action_list;
|
|
98
|
|
99 /* Function to call to handle deferred actions, when there are any. */
|
|
100 Lisp_Object Vdeferred_action_function;
|
|
101 Lisp_Object Qdeferred_action_function;
|
|
102 #endif /* DEFERRED_ACTION_CRAP */
|
|
103
|
|
104 /* Non-nil disable property on a command means
|
|
105 do not execute it; call disabled-command-hook's value instead. */
|
|
106 Lisp_Object Qdisabled, Vdisabled_command_hook;
|
|
107
|
|
108 static void pre_command_hook (void);
|
|
109 static void post_command_hook (void);
|
|
110
|
|
111 /* Last keyboard or mouse input event read as a command. */
|
|
112 Lisp_Object Vlast_command_event;
|
|
113
|
|
114 /* The nearest ASCII equivalent of the above. */
|
|
115 Lisp_Object Vlast_command_char;
|
|
116
|
|
117 /* Last keyboard or mouse event read for any purpose. */
|
|
118 Lisp_Object Vlast_input_event;
|
|
119
|
|
120 /* The nearest ASCII equivalent of the above. */
|
|
121 Lisp_Object Vlast_input_char;
|
|
122
|
|
123 Lisp_Object Vcurrent_mouse_event;
|
|
124
|
|
125 /* If not Qnil, event objects to be read as the next command input */
|
|
126 Lisp_Object Vunread_command_events;
|
|
127 Lisp_Object Vunread_command_event; /* obsoleteness support */
|
|
128
|
|
129 static Lisp_Object Qunread_command_events, Qunread_command_event;
|
|
130
|
|
131 /* Previous command, represented by a Lisp object.
|
|
132 Does not include prefix commands and arg setting commands */
|
|
133 Lisp_Object Vlast_command;
|
|
134
|
|
135 /* If a command sets this, the value goes into
|
|
136 previous-command for the next command. */
|
|
137 Lisp_Object Vthis_command;
|
|
138
|
|
139 /* The value of point when the last command was executed. */
|
|
140 Bufpos last_point_position;
|
|
141
|
|
142 /* The frame that was current when the last command was started. */
|
|
143 Lisp_Object Vlast_selected_frame;
|
|
144
|
|
145 /* The buffer that was current when the last command was started. */
|
|
146 Lisp_Object last_point_position_buffer;
|
|
147
|
|
148 /* A (16bit . 16bit) representation of the time of the last-command-event.
|
|
149 */
|
|
150 Lisp_Object Vlast_input_time;
|
|
151
|
|
152 /* Character to recognize as the help char. */
|
|
153 Lisp_Object Vhelp_char;
|
|
154
|
|
155 /* Form to execute when help char is typed. */
|
|
156 Lisp_Object Vhelp_form;
|
|
157
|
|
158 /* Flag to tell QUIT that some interesting occurrence (e.g. a keypress)
|
|
159 may have happened. */
|
|
160 volatile int something_happened;
|
|
161
|
|
162 /* Command to run when the help character follows a prefix key. */
|
|
163 Lisp_Object Vprefix_help_command;
|
|
164
|
|
165 /* Hash table to translate keysyms through */
|
|
166 Lisp_Object Vkeyboard_translate_table;
|
|
167
|
|
168 /* If control-meta-super-shift-X is undefined, try control-meta-super-x */
|
|
169 Lisp_Object Vretry_undefined_key_binding_unshifted;
|
|
170 Lisp_Object Qretry_undefined_key_binding_unshifted;
|
|
171
|
70
|
172 #ifdef HAVE_XIM
|
|
173 /* If composed input is undefined, use self-insert-char */
|
|
174 Lisp_Object Vcomposed_character_default_binding;
|
|
175 #endif /* HAVE_XIM */
|
|
176
|
0
|
177 /* Console that corresponds to our controlling terminal */
|
|
178 Lisp_Object Vcontrolling_terminal;
|
|
179
|
|
180 /* An event (actually an event chain linked through event_next) or Qnil.
|
|
181 */
|
|
182 Lisp_Object Vthis_command_keys;
|
|
183 Lisp_Object Vthis_command_keys_tail;
|
|
184
|
|
185 /* #### kludge! */
|
|
186 Lisp_Object Qauto_show_make_point_visible;
|
|
187
|
|
188 /* File in which we write all commands we read; an lstream */
|
|
189 static Lisp_Object Vdribble_file;
|
|
190
|
|
191 #ifdef DEBUG_XEMACS
|
|
192 int debug_emacs_events;
|
|
193 #endif
|
|
194
|
|
195
|
|
196 /* The callback routines for the window system or terminal driver */
|
|
197 struct event_stream *event_stream;
|
|
198
|
|
199 /* This structure is what we use to excapsulate the state of a command sequence
|
|
200 being composed; key events are executed by adding themselves to the command
|
|
201 builder; if the command builder is then complete (does not still represent
|
|
202 a prefix key sequence) it executes the corresponding command.
|
|
203 */
|
|
204 struct command_builder
|
|
205 {
|
|
206 struct lcrecord_header header;
|
|
207 Lisp_Object console; /* back pointer to the console this command
|
|
208 builder is for */
|
|
209 /* Qnil, or a Lisp_Event representing the first event read
|
|
210 * after the last command completed. Threaded. */
|
|
211 /* #### NYI */
|
|
212 Lisp_Object prefix_events;
|
|
213 /* Qnil, or a Lisp_Event representing event in the current
|
|
214 * keymap-lookup sequence. Subsequent events are threaded via
|
|
215 * the event's next slot */
|
|
216 Lisp_Object current_events;
|
|
217 /* Last elt of above */
|
|
218 Lisp_Object most_current_event;
|
|
219 /* Last elt before function map code took over.
|
|
220 What this means is: All prefixes up to (but not including)
|
|
221 this event have non-nil bindings, but the prefix including
|
|
222 this event has a nil binding. Any events in the chain after
|
|
223 this one were read solely because we're part of a possible
|
|
224 function key. If we end up with something that's not part
|
|
225 of a possible function key, we have to unread all of those
|
|
226 events. */
|
|
227 Lisp_Object last_non_munged_event;
|
|
228 /* One set of values for function-key-map, one for key-translation-map */
|
|
229 struct munging_key_translation
|
|
230 {
|
|
231 /* First event that can begin a possible function key sequence
|
|
232 (to be translated according to function-key-map). Normally
|
|
233 this is the first event in the chain. However, once we've
|
|
234 translated a sequence through function-key-map, this will
|
|
235 point to the first event after the translated sequence:
|
|
236 we don't ever want to translate any events twice through
|
|
237 function-key-map, or things could get really screwed up
|
|
238 (e.g. if the user created a translation loop). If this
|
|
239 is nil, then the next-read event is the first that can
|
|
240 begin a function key sequence. */
|
|
241 Lisp_Object first_mungeable_event;
|
|
242 } munge_me[2];
|
|
243
|
|
244 Bufbyte *echo_buf;
|
|
245 Bytecount echo_buf_length; /* size of echo_buf */
|
|
246 Bytecount echo_buf_index; /* index into echo_buf
|
|
247 * -1 before doing echoing for new cmd */
|
|
248 /* Self-insert-command is magic in that it doesn't always push an undo-
|
|
249 boundary: up to 20 consecutive self-inserts can happen before an undo-
|
|
250 boundary is pushed. This variable is that counter.
|
|
251 */
|
|
252 int self_insert_countdown;
|
|
253 };
|
|
254
|
|
255 static void echo_key_event (struct command_builder *, Lisp_Object event);
|
|
256 static void maybe_kbd_translate (Lisp_Object event);
|
|
257
|
|
258 /* This structure is basically a typeahead queue: things like
|
|
259 wait-reading-process-output will delay the execution of
|
|
260 keyboard and mouse events by pushing them here.
|
|
261
|
|
262 Chained through event_next()
|
|
263 command_event_queue_tail is a pointer to the last-added element.
|
|
264 */
|
|
265 static Lisp_Object command_event_queue;
|
|
266 static Lisp_Object command_event_queue_tail;
|
|
267
|
|
268 /* Nonzero means echo unfinished commands after this many seconds of pause. */
|
|
269 static int echo_keystrokes;
|
|
270
|
|
271 /* The number of keystrokes since the last auto-save. */
|
|
272 static int keystrokes_since_auto_save;
|
|
273
|
|
274 /* Used by the C-g signal handler so that it will never "hard quit"
|
|
275 when waiting for an event. Otherwise holding down C-g could
|
|
276 cause a suspension back to the shell, which is generally
|
|
277 undesirable. (#### This doesn't fully work.) */
|
|
278
|
|
279 int emacs_is_blocking;
|
|
280
|
108
|
281 /* Handlers which run during sit-for, sleep-for and accept-process-output
|
|
282 are not allowed to recursively call these routines. We record here
|
|
283 if we are in that situation. */
|
|
284
|
|
285 static Lisp_Object recursive_sit_for;
|
|
286
|
|
287
|
0
|
288
|
|
289 /**********************************************************************/
|
|
290 /* Command-builder object */
|
|
291 /**********************************************************************/
|
|
292
|
|
293 #define XCOMMAND_BUILDER(x) \
|
|
294 XRECORD (x, command_builder, struct command_builder)
|
|
295 #define XSETCOMMAND_BUILDER(x, p) XSETRECORD (x, p, command_builder)
|
|
296 #define COMMAND_BUILDERP(x) RECORDP (x, command_builder)
|
|
297 #define GC_COMMAND_BUILDERP(x) GC_RECORDP (x, command_builder)
|
|
298 #define CHECK_COMMAND_BUILDER(x) CHECK_RECORD (x, command_builder)
|
|
299
|
|
300 static Lisp_Object mark_command_builder (Lisp_Object obj,
|
|
301 void (*markobj) (Lisp_Object));
|
|
302 static void finalize_command_builder (void *header, int for_disksave);
|
|
303 DEFINE_LRECORD_IMPLEMENTATION ("command-builder", command_builder,
|
|
304 mark_command_builder, internal_object_printer,
|
|
305 finalize_command_builder, 0, 0,
|
|
306 struct command_builder);
|
|
307
|
|
308 static Lisp_Object
|
|
309 mark_command_builder (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
310 {
|
|
311 struct command_builder *builder = XCOMMAND_BUILDER (obj);
|
|
312 (markobj) (builder->prefix_events);
|
|
313 (markobj) (builder->current_events);
|
|
314 (markobj) (builder->most_current_event);
|
|
315 (markobj) (builder->last_non_munged_event);
|
|
316 (markobj) (builder->munge_me[0].first_mungeable_event);
|
|
317 (markobj) (builder->munge_me[1].first_mungeable_event);
|
|
318 return builder->console;
|
|
319 }
|
|
320
|
|
321 static void
|
|
322 finalize_command_builder (void *header, int for_disksave)
|
|
323 {
|
|
324 struct command_builder *c = (struct command_builder *) header;
|
|
325
|
|
326 if (!for_disksave)
|
|
327 {
|
|
328 xfree (c->echo_buf);
|
|
329 c->echo_buf = 0;
|
|
330 }
|
|
331 }
|
|
332
|
|
333 static void
|
|
334 reset_command_builder_event_chain (struct command_builder *builder)
|
|
335 {
|
|
336 builder->prefix_events = Qnil;
|
|
337 builder->current_events = Qnil;
|
|
338 builder->most_current_event = Qnil;
|
|
339 builder->last_non_munged_event = Qnil;
|
|
340 builder->munge_me[0].first_mungeable_event = Qnil;
|
|
341 builder->munge_me[1].first_mungeable_event = Qnil;
|
|
342 }
|
|
343
|
|
344 Lisp_Object
|
|
345 allocate_command_builder (Lisp_Object console)
|
|
346 {
|
|
347 Lisp_Object builder_obj = Qnil;
|
|
348 struct command_builder *builder =
|
|
349 alloc_lcrecord (sizeof (struct command_builder),
|
|
350 lrecord_command_builder);
|
|
351
|
|
352 builder->console = console;
|
|
353 reset_command_builder_event_chain (builder);
|
|
354 builder->echo_buf_length = 300; /* #### Kludge */
|
|
355 builder->echo_buf =
|
|
356 (Bufbyte *) xmalloc (builder->echo_buf_length);
|
|
357 builder->echo_buf[0] = 0;
|
|
358 builder->echo_buf_index = -1;
|
|
359 builder->echo_buf_index = -1;
|
|
360 builder->self_insert_countdown = 0;
|
|
361
|
|
362 XSETCOMMAND_BUILDER (builder_obj, builder);
|
|
363 return builder_obj;
|
|
364 }
|
|
365
|
|
366 static void
|
|
367 command_builder_append_event (struct command_builder *builder,
|
|
368 Lisp_Object event)
|
|
369 {
|
|
370 assert (EVENTP (event));
|
|
371
|
|
372 if (EVENTP (builder->most_current_event))
|
|
373 XSET_EVENT_NEXT (builder->most_current_event, event);
|
|
374 else
|
|
375 builder->current_events = event;
|
|
376
|
|
377 builder->most_current_event = event;
|
|
378 if (NILP (builder->munge_me[0].first_mungeable_event))
|
|
379 builder->munge_me[0].first_mungeable_event = event;
|
|
380 if (NILP (builder->munge_me[1].first_mungeable_event))
|
|
381 builder->munge_me[1].first_mungeable_event = event;
|
|
382 }
|
|
383
|
|
384
|
|
385 /**********************************************************************/
|
|
386 /* Low-level interfaces onto event methods */
|
|
387 /**********************************************************************/
|
|
388
|
|
389 enum event_stream_operation
|
|
390 {
|
|
391 EVENT_STREAM_PROCESS,
|
|
392 EVENT_STREAM_TIMEOUT,
|
|
393 EVENT_STREAM_CONSOLE,
|
|
394 EVENT_STREAM_READ
|
|
395 };
|
|
396
|
|
397 static void
|
|
398 check_event_stream_ok (enum event_stream_operation op)
|
|
399 {
|
|
400 if (!event_stream && noninteractive)
|
|
401 {
|
|
402 switch (op)
|
|
403 {
|
|
404 case EVENT_STREAM_PROCESS:
|
|
405 error ("Can't start subprocesses in -batch mode");
|
|
406 case EVENT_STREAM_TIMEOUT:
|
|
407 error ("Can't add timeouts in -batch mode");
|
|
408 case EVENT_STREAM_CONSOLE:
|
|
409 error ("Can't add consoles in -batch mode");
|
|
410 case EVENT_STREAM_READ:
|
|
411 error ("Can't read events in -batch mode");
|
|
412 default:
|
|
413 abort ();
|
|
414 }
|
|
415 }
|
|
416 else if (!event_stream)
|
|
417 {
|
|
418 error ("event-stream callbacks not initialized (internal error?)");
|
|
419 }
|
|
420 }
|
|
421
|
|
422 int
|
|
423 event_stream_event_pending_p (int user)
|
|
424 {
|
|
425 if (!event_stream)
|
|
426 return 0;
|
|
427 return event_stream->event_pending_p (user);
|
|
428 }
|
|
429
|
|
430 static int
|
|
431 maybe_read_quit_event (struct Lisp_Event *event)
|
|
432 {
|
|
433 /* A C-g that came from `sigint_happened' will always come from the
|
|
434 controlling terminal. If that doesn't exist, however, then the
|
|
435 user manually sent us a SIGINT, and we pretend the C-g came from
|
|
436 the selected console. */
|
|
437 struct console *con;
|
|
438
|
|
439 if (CONSOLEP (Vcontrolling_terminal) &&
|
|
440 CONSOLE_LIVE_P (XCONSOLE (Vcontrolling_terminal)))
|
|
441 con = XCONSOLE (Vcontrolling_terminal);
|
|
442 else
|
|
443 con = XCONSOLE (Fselected_console ());
|
|
444
|
|
445 if (sigint_happened)
|
|
446 {
|
|
447 int ch = CONSOLE_QUIT_CHAR (con);
|
|
448 sigint_happened = 0;
|
|
449 Vquit_flag = Qnil;
|
|
450 character_to_event (ch, event, con, 1);
|
|
451 event->channel = make_console (con);
|
|
452 return 1;
|
|
453 }
|
|
454 return 0;
|
|
455 }
|
|
456
|
|
457 void
|
|
458 event_stream_next_event (struct Lisp_Event *event)
|
|
459 {
|
|
460 Lisp_Object event_obj = Qnil;
|
|
461
|
|
462 check_event_stream_ok (EVENT_STREAM_READ);
|
|
463
|
|
464 XSETEVENT (event_obj, event);
|
|
465 zero_event (event);
|
|
466 /* If C-g was pressed, treat it as a character to be read.
|
|
467 Note that if C-g was pressed while we were blocking,
|
|
468 the SIGINT signal handler will be called. It will
|
|
469 set Vquit_flag and write a byte on our "fake pipe",
|
|
470 which will unblock us. */
|
|
471 if (maybe_read_quit_event (event))
|
|
472 {
|
|
473 #ifdef DEBUG_XEMACS
|
|
474 if (debug_emacs_events)
|
|
475 {
|
|
476 write_c_string ("(SIGINT) ",
|
|
477 Qexternal_debugging_output);
|
|
478 print_internal (event_obj, Qexternal_debugging_output, 1);
|
|
479 write_c_string ("\n", Qexternal_debugging_output);
|
|
480 }
|
|
481 #endif
|
|
482 return;
|
|
483 }
|
|
484
|
|
485 /* If a longjmp() happens in the callback, we're screwed.
|
|
486 Let's hope it doesn't. I think the code here is fairly
|
|
487 clean and doesn't do this. */
|
|
488 emacs_is_blocking = 1;
|
|
489 #if 0
|
|
490 /* Do this if the poll-for-quit timer seems to be taking too
|
|
491 much CPU time when idle ... */
|
|
492 reset_poll_for_quit ();
|
|
493 #endif
|
|
494 event_stream->next_event_cb (event);
|
|
495 #if 0
|
|
496 init_poll_for_quit ();
|
|
497 #endif
|
|
498 emacs_is_blocking = 0;
|
|
499
|
|
500 #ifdef DEBUG_XEMACS
|
|
501 if (debug_emacs_events)
|
|
502 {
|
|
503 write_c_string ("(real) ",
|
|
504 Qexternal_debugging_output);
|
|
505 /* timeout events have more info set later, so
|
|
506 print the event out in next_event_internal(). */
|
|
507 if (event->event_type != timeout_event)
|
|
508 {
|
|
509 print_internal (event_obj, Qexternal_debugging_output, 1);
|
|
510 write_c_string ("\n", Qexternal_debugging_output);
|
|
511 }
|
|
512 }
|
|
513 #endif
|
|
514 maybe_kbd_translate (event_obj);
|
|
515 }
|
|
516
|
|
517 void
|
|
518 event_stream_handle_magic_event (struct Lisp_Event *event)
|
|
519 {
|
|
520 check_event_stream_ok (EVENT_STREAM_READ);
|
|
521 event_stream->handle_magic_event_cb (event);
|
|
522 }
|
|
523
|
|
524 static int
|
|
525 event_stream_add_timeout (EMACS_TIME timeout)
|
|
526 {
|
|
527 check_event_stream_ok (EVENT_STREAM_TIMEOUT);
|
|
528 return event_stream->add_timeout_cb (timeout);
|
|
529 }
|
|
530
|
|
531 static void
|
|
532 event_stream_remove_timeout (int id)
|
|
533 {
|
|
534 check_event_stream_ok (EVENT_STREAM_TIMEOUT);
|
|
535 event_stream->remove_timeout_cb (id);
|
|
536 }
|
|
537
|
|
538 void
|
|
539 event_stream_select_console (struct console *con)
|
|
540 {
|
|
541 check_event_stream_ok (EVENT_STREAM_CONSOLE);
|
|
542 if (!con->input_enabled)
|
|
543 {
|
|
544 event_stream->select_console_cb (con);
|
|
545 con->input_enabled = 1;
|
|
546 }
|
|
547 }
|
|
548
|
|
549 void
|
|
550 event_stream_unselect_console (struct console *con)
|
|
551 {
|
|
552 check_event_stream_ok (EVENT_STREAM_CONSOLE);
|
|
553 if (con->input_enabled)
|
|
554 {
|
|
555 event_stream->unselect_console_cb (con);
|
|
556 con->input_enabled = 0;
|
|
557 }
|
|
558 }
|
|
559
|
|
560 void
|
|
561 event_stream_select_process (struct Lisp_Process *proc)
|
|
562 {
|
|
563 check_event_stream_ok (EVENT_STREAM_PROCESS);
|
|
564 if (!get_process_selected_p (proc))
|
|
565 {
|
|
566 event_stream->select_process_cb (proc);
|
|
567 set_process_selected_p (proc, 1);
|
|
568 }
|
|
569 }
|
|
570
|
|
571 void
|
|
572 event_stream_unselect_process (struct Lisp_Process *proc)
|
|
573 {
|
|
574 check_event_stream_ok (EVENT_STREAM_PROCESS);
|
|
575 if (get_process_selected_p (proc))
|
|
576 {
|
|
577 event_stream->unselect_process_cb (proc);
|
|
578 set_process_selected_p (proc, 0);
|
|
579 }
|
|
580 }
|
|
581
|
|
582 void
|
|
583 event_stream_quit_p (void)
|
|
584 {
|
|
585 if (event_stream)
|
|
586 event_stream->quit_p_cb ();
|
|
587 }
|
|
588
|
|
589
|
|
590
|
|
591 /**********************************************************************/
|
|
592 /* Character prompting */
|
|
593 /**********************************************************************/
|
|
594
|
|
595 static void
|
|
596 echo_key_event (struct command_builder *command_builder,
|
|
597 Lisp_Object event)
|
|
598 {
|
|
599 /* This function can GC */
|
|
600 char buf[255];
|
|
601 Bytecount buf_index = command_builder->echo_buf_index;
|
|
602 Bufbyte *e;
|
|
603 Bytecount len;
|
|
604
|
|
605 if (buf_index < 0)
|
|
606 {
|
|
607 buf_index = 0; /* We're echoing now */
|
|
608 clear_echo_area (selected_frame (), Qnil, 0);
|
|
609 }
|
|
610
|
|
611 format_event_object (buf, XEVENT (event), 1);
|
|
612 len = strlen (buf);
|
|
613
|
|
614 if (len + buf_index + 4 > command_builder->echo_buf_length)
|
|
615 return;
|
|
616 e = command_builder->echo_buf + buf_index;
|
|
617 memcpy (e, buf, len);
|
|
618 e += len;
|
|
619
|
|
620 e[0] = ' ';
|
|
621 e[1] = '-';
|
|
622 e[2] = ' ';
|
|
623 e[3] = 0;
|
|
624
|
|
625 command_builder->echo_buf_index = buf_index + len + 1;
|
|
626 }
|
|
627
|
|
628 static void
|
|
629 regenerate_echo_keys_from_this_command_keys (struct command_builder *
|
|
630 builder)
|
|
631 {
|
|
632 Lisp_Object event;
|
|
633
|
|
634 builder->echo_buf_index = 0;
|
|
635
|
|
636 EVENT_CHAIN_LOOP (event, Vthis_command_keys)
|
|
637 echo_key_event (builder, event);
|
|
638 }
|
|
639
|
|
640 static void
|
|
641 maybe_echo_keys (struct command_builder *command_builder, int no_snooze)
|
|
642 {
|
|
643 /* This function can GC */
|
|
644 struct frame *f = selected_frame ();
|
|
645 /* Message turns off echoing unless more keystrokes turn it on again. */
|
|
646 if (echo_area_active (f) && !EQ (Qcommand, echo_area_status (f)))
|
|
647 return;
|
|
648
|
|
649 if (minibuf_level == 0
|
|
650 && echo_keystrokes > 0)
|
|
651 {
|
|
652 if (!no_snooze)
|
|
653 {
|
|
654 /* #### C-g here will cause QUIT. Setting dont_check_for_quit
|
|
655 doesn't work. See check_quit. */
|
|
656 if (NILP (Fsit_for (make_int (echo_keystrokes), Qnil)))
|
|
657 /* input came in, so don't echo. */
|
|
658 return;
|
|
659 }
|
|
660
|
|
661 echo_area_message (f, command_builder->echo_buf, Qnil, 0,
|
|
662 /* not echo_buf_index. That doesn't include
|
|
663 the terminating " - ". */
|
|
664 strlen ((char *) command_builder->echo_buf),
|
|
665 Qcommand);
|
|
666 }
|
|
667 }
|
|
668
|
|
669 static void
|
|
670 reset_key_echo (struct command_builder *command_builder,
|
|
671 int remove_echo_area_echo)
|
|
672 {
|
|
673 /* This function can GC */
|
|
674 struct frame *f = selected_frame ();
|
|
675
|
|
676 command_builder->echo_buf_index = -1;
|
|
677
|
|
678 if (remove_echo_area_echo)
|
|
679 clear_echo_area (f, Qcommand, 0);
|
|
680 }
|
|
681
|
|
682
|
|
683 /**********************************************************************/
|
|
684 /* random junk */
|
|
685 /**********************************************************************/
|
|
686
|
|
687 static void
|
|
688 maybe_kbd_translate (Lisp_Object event)
|
|
689 {
|
|
690 Emchar c;
|
|
691 int did_translate = 0;
|
|
692
|
|
693 if (XEVENT_TYPE (event) != key_press_event)
|
|
694 return;
|
|
695 if (!HASHTABLEP (Vkeyboard_translate_table))
|
|
696 return;
|
|
697 if (EQ (Fhashtable_fullness (Vkeyboard_translate_table), Qzero))
|
|
698 return;
|
|
699
|
|
700 c = event_to_character (XEVENT (event), 0, 0, 0);
|
|
701 if (c != -1)
|
|
702 {
|
|
703 Lisp_Object traduit = Fgethash (make_char (c), Vkeyboard_translate_table,
|
|
704 Qnil);
|
|
705 if (!NILP (traduit) && SYMBOLP (traduit))
|
|
706 {
|
|
707 XEVENT (event)->event.key.keysym = traduit;
|
|
708 XEVENT (event)->event.key.modifiers = 0;
|
|
709 did_translate = 1;
|
|
710 }
|
|
711 else if (CHARP (traduit))
|
|
712 {
|
|
713 struct Lisp_Event ev2;
|
|
714
|
|
715 /* This used to call Fcharacter_to_event() directly into EVENT,
|
|
716 but that can eradicate timestamps and other such stuff.
|
|
717 This way is safer. */
|
|
718 zero_event (&ev2);
|
|
719 character_to_event (XCHAR (traduit), &ev2,
|
|
720 XCONSOLE (EVENT_CHANNEL (XEVENT (event))), 1);
|
|
721 XEVENT (event)->event.key.keysym = ev2.event.key.keysym;
|
|
722 XEVENT (event)->event.key.modifiers = ev2.event.key.modifiers;
|
|
723 did_translate = 1;
|
|
724 }
|
|
725 }
|
|
726
|
|
727 if (!did_translate)
|
|
728 {
|
|
729 Lisp_Object traduit = Fgethash (XEVENT (event)->event.key.keysym,
|
|
730 Vkeyboard_translate_table, Qnil);
|
|
731 if (!NILP (traduit) && SYMBOLP (traduit))
|
|
732 {
|
|
733 XEVENT (event)->event.key.keysym = traduit;
|
|
734 did_translate = 1;
|
|
735 }
|
|
736 }
|
|
737
|
|
738 #ifdef DEBUG_XEMACS
|
|
739 if (did_translate && debug_emacs_events)
|
|
740 {
|
|
741 write_c_string ("(->keyboard-translate-table) ",
|
|
742 Qexternal_debugging_output);
|
|
743 print_internal (event, Qexternal_debugging_output, 1);
|
|
744 write_c_string ("\n", Qexternal_debugging_output);
|
|
745 }
|
|
746 #endif
|
|
747 }
|
|
748
|
|
749 /* NB: The following auto-save stuff is in keyboard.c in FSFmacs, and
|
|
750 keystrokes_since_auto_save is equivalent to the difference between
|
|
751 num_nonmacro_input_chars and last_auto_save. */
|
|
752
|
|
753 /* When an auto-save happens, record the "time", and don't do again soon. */
|
|
754
|
|
755 void
|
|
756 record_auto_save (void)
|
|
757 {
|
|
758 keystrokes_since_auto_save = 0;
|
|
759 }
|
|
760
|
|
761 /* Make an auto save happen as soon as possible at command level. */
|
|
762
|
|
763 void
|
|
764 force_auto_save_soon (void)
|
|
765 {
|
|
766 keystrokes_since_auto_save = 1 + max (auto_save_interval, 20);
|
|
767
|
|
768 #if 0 /* FSFmacs */
|
|
769 record_asynch_buffer_change ();
|
|
770 #endif
|
|
771 }
|
|
772
|
|
773 static void
|
|
774 maybe_do_auto_save (void)
|
|
775 {
|
70
|
776 /* This function can GC */
|
0
|
777 keystrokes_since_auto_save++;
|
|
778 if (auto_save_interval > 0 &&
|
|
779 keystrokes_since_auto_save > max (auto_save_interval, 20) &&
|
|
780 !detect_input_pending ())
|
|
781 {
|
|
782 Fdo_auto_save (Qnil, Qnil);
|
|
783 record_auto_save ();
|
|
784 }
|
|
785 }
|
|
786
|
|
787 static Lisp_Object
|
|
788 print_help (Lisp_Object object)
|
|
789 {
|
|
790 Fprinc (object, Qnil);
|
|
791 return Qnil;
|
|
792 }
|
|
793
|
|
794 static void
|
|
795 execute_help_form (struct command_builder *command_builder,
|
|
796 Lisp_Object event)
|
|
797 {
|
|
798 /* This function can GC */
|
|
799 Lisp_Object help = Qnil;
|
|
800 int speccount = specpdl_depth ();
|
|
801 Bytecount buf_index = command_builder->echo_buf_index;
|
|
802 Lisp_Object echo = ((buf_index <= 0)
|
|
803 ? Qnil
|
|
804 : make_string (command_builder->echo_buf,
|
|
805 buf_index));
|
|
806 struct gcpro gcpro1, gcpro2;
|
|
807 GCPRO2 (echo, help);
|
|
808
|
|
809 record_unwind_protect (save_window_excursion_unwind,
|
|
810 Fcurrent_window_configuration (Qnil));
|
|
811 reset_key_echo (command_builder, 1);
|
|
812
|
|
813 help = Feval (Vhelp_form);
|
|
814 if (STRINGP (help))
|
|
815 internal_with_output_to_temp_buffer ("*Help*",
|
|
816 print_help, help, Qnil);
|
|
817 Fnext_command_event (event, Qnil);
|
|
818 /* Remove the help from the frame */
|
|
819 unbind_to (speccount, Qnil);
|
|
820 /* Hmmmm. Tricky. The unbind restores an old window configuration,
|
|
821 apparently bypassing any setting of windows_structure_changed.
|
|
822 So we need to set it so that things get redrawn properly. */
|
|
823 /* #### This is massive overkill. Look at doing it better once the
|
|
824 new redisplay is fully in place. */
|
|
825 {
|
|
826 Lisp_Object frmcons, devcons, concons;
|
|
827 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
|
|
828 {
|
|
829 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (XFRAME (XCAR (frmcons)));
|
|
830 }
|
|
831 }
|
|
832
|
|
833 redisplay ();
|
|
834 if (event_matches_key_specifier_p (XEVENT (event), make_char (' ')))
|
|
835 {
|
2
|
836 /* Discard next key if it is a space */
|
0
|
837 reset_key_echo (command_builder, 1);
|
|
838 Fnext_command_event (event, Qnil);
|
|
839 }
|
|
840
|
|
841 command_builder->echo_buf_index = buf_index;
|
|
842 if (buf_index > 0)
|
|
843 memcpy (command_builder->echo_buf,
|
14
|
844 XSTRING_DATA (echo), buf_index + 1); /* terminating 0 */
|
0
|
845 UNGCPRO;
|
|
846 }
|
|
847
|
|
848
|
|
849 /**********************************************************************/
|
|
850 /* input pending */
|
|
851 /**********************************************************************/
|
|
852
|
|
853 int
|
|
854 detect_input_pending (void)
|
|
855 {
|
|
856 /* Always call the event_pending_p hook even if there's an unread
|
|
857 character, because that might do some needed ^G detection (on
|
|
858 systems without SIGIO, for example).
|
|
859 */
|
|
860 if (event_stream_event_pending_p (1))
|
|
861 return 1;
|
|
862 if (!NILP (Vunread_command_events) || !NILP (Vunread_command_event))
|
|
863 return 1;
|
|
864 if (!NILP (command_event_queue))
|
|
865 {
|
|
866 Lisp_Object event;
|
|
867
|
|
868 EVENT_CHAIN_LOOP (event, command_event_queue)
|
|
869 {
|
|
870 if (XEVENT_TYPE (event) != eval_event
|
|
871 && XEVENT_TYPE (event) != magic_eval_event)
|
|
872 return (1);
|
|
873 }
|
|
874 }
|
|
875 return 0;
|
|
876 }
|
|
877
|
20
|
878 DEFUN ("input-pending-p", Finput_pending_p, 0, 0, 0, /*
|
0
|
879 T if command input is currently available with no waiting.
|
|
880 Actually, the value is nil only if we can be sure that no input is available.
|
20
|
881 */
|
70
|
882 ())
|
0
|
883 {
|
|
884 return ((detect_input_pending ()) ? Qt : Qnil);
|
|
885 }
|
|
886
|
|
887
|
|
888 /**********************************************************************/
|
|
889 /* timeouts */
|
|
890 /**********************************************************************/
|
|
891
|
|
892 /**** Low-level timeout functions. ****
|
|
893
|
|
894 These functions maintain a sorted list of one-shot timeouts (where
|
|
895 the timeouts are in absolute time). They are intended for use by
|
|
896 functions that need to convert a list of absolute timeouts into a
|
|
897 series of intervals to wait for. */
|
|
898
|
|
899 /* We ensure that 0 is never a valid ID, so that a value of 0 can be
|
|
900 used to indicate an absence of a timer. */
|
|
901 static int low_level_timeout_id_tick;
|
|
902
|
|
903 struct low_level_timeout_blocktype
|
|
904 {
|
|
905 Blocktype_declare (struct low_level_timeout);
|
|
906 } *the_low_level_timeout_blocktype;
|
|
907
|
|
908 /* Add a one-shot timeout at time TIME to TIMEOUT_LIST. Return
|
|
909 a unique ID identifying the timeout. */
|
|
910
|
|
911 int
|
|
912 add_low_level_timeout (struct low_level_timeout **timeout_list,
|
|
913 EMACS_TIME thyme)
|
|
914 {
|
|
915 struct low_level_timeout *tm;
|
|
916 struct low_level_timeout *t, **tt;
|
|
917
|
|
918 /* Allocate a new time struct. */
|
|
919
|
|
920 tm = Blocktype_alloc (the_low_level_timeout_blocktype);
|
|
921 tm->next = NULL;
|
|
922 if (low_level_timeout_id_tick == 0)
|
|
923 low_level_timeout_id_tick++;
|
|
924 tm->id = low_level_timeout_id_tick++;
|
|
925 tm->time = thyme;
|
|
926
|
|
927 /* Add it to the queue. */
|
|
928
|
|
929 tt = timeout_list;
|
|
930 t = *tt;
|
|
931 while (t && EMACS_TIME_EQUAL_OR_GREATER (tm->time, t->time))
|
|
932 {
|
|
933 tt = &t->next;
|
|
934 t = *tt;
|
|
935 }
|
|
936 tm->next = t;
|
|
937 *tt = tm;
|
|
938
|
|
939 return tm->id;
|
|
940 }
|
|
941
|
|
942 /* Remove the low-level timeout identified by ID from TIMEOUT_LIST.
|
|
943 If the timeout is not there, do nothing. */
|
|
944
|
|
945 void
|
|
946 remove_low_level_timeout (struct low_level_timeout **timeout_list, int id)
|
|
947 {
|
|
948 struct low_level_timeout *t, *prev;
|
|
949
|
|
950 /* find it */
|
|
951
|
|
952 for (t = *timeout_list, prev = NULL; t && t->id != id; t = t->next)
|
|
953 prev = t;
|
|
954
|
|
955 if (!t)
|
|
956 return; /* couldn't find it */
|
|
957
|
|
958 if (!prev)
|
|
959 *timeout_list = t->next;
|
|
960 else prev->next = t->next;
|
|
961
|
|
962 Blocktype_free (the_low_level_timeout_blocktype, t);
|
|
963 }
|
|
964
|
|
965 /* If there are timeouts on TIMEOUT_LIST, store the relative time
|
|
966 interval to the first timeout on the list into INTERVAL and
|
|
967 return 1. Otherwise, return 0. */
|
|
968
|
|
969 int
|
|
970 get_low_level_timeout_interval (struct low_level_timeout *timeout_list,
|
|
971 EMACS_TIME *interval)
|
|
972 {
|
|
973 if (!timeout_list) /* no timer events; block indefinitely */
|
|
974 return 0;
|
|
975 else
|
|
976 {
|
|
977 EMACS_TIME current_time;
|
|
978
|
|
979 /* The time to block is the difference between the first
|
|
980 (earliest) timer on the queue and the current time.
|
|
981 If that is negative, then the timer will fire immediately
|
|
982 but we still have to call select(), with a zero-valued
|
|
983 timeout: user events must have precedence over timer events. */
|
|
984 EMACS_GET_TIME (current_time);
|
|
985 if (EMACS_TIME_GREATER (timeout_list->time, current_time))
|
|
986 EMACS_SUB_TIME (*interval, timeout_list->time,
|
|
987 current_time);
|
|
988 else
|
|
989 EMACS_SET_SECS_USECS (*interval, 0, 0);
|
|
990 return 1;
|
|
991 }
|
|
992 }
|
|
993
|
|
994 /* Pop the first (i.e. soonest) timeout off of TIMEOUT_LIST and return
|
|
995 its ID. Also, if TIME_OUT is not 0, store the absolute time of the
|
|
996 timeout into TIME_OUT. */
|
|
997
|
|
998 int
|
|
999 pop_low_level_timeout (struct low_level_timeout **timeout_list,
|
|
1000 EMACS_TIME *time_out)
|
|
1001 {
|
|
1002 struct low_level_timeout *tm = *timeout_list;
|
|
1003 int id;
|
|
1004
|
|
1005 assert (tm);
|
|
1006 id = tm->id;
|
|
1007 if (time_out)
|
|
1008 *time_out = tm->time;
|
|
1009 *timeout_list = tm->next;
|
|
1010 Blocktype_free (the_low_level_timeout_blocktype, tm);
|
|
1011 return id;
|
|
1012 }
|
|
1013
|
|
1014
|
|
1015 /**** High-level timeout functions. ****/
|
|
1016
|
|
1017 static int timeout_id_tick;
|
|
1018
|
|
1019 /* Since timeout structures contain Lisp_Objects, they need to be GC'd
|
|
1020 properly. The opaque data type provides a convenient way of doing
|
|
1021 this without having to create a new Lisp object, since we can
|
|
1022 provide our own mark function. */
|
|
1023
|
|
1024 struct timeout
|
|
1025 {
|
|
1026 int id; /* Id we use to identify the timeout over its lifetime */
|
|
1027 int interval_id; /* Id for this particular interval; this may
|
|
1028 be different each time the timeout is
|
|
1029 signalled.*/
|
|
1030 Lisp_Object function, object; /* Function and object associated
|
|
1031 with timeout. */
|
|
1032 EMACS_TIME next_signal_time; /* Absolute time when the timeout
|
|
1033 is next going to be signalled. */
|
|
1034 unsigned int resignal_msecs; /* How far after the next timeout
|
|
1035 should the one after that
|
|
1036 occur? */
|
|
1037 };
|
|
1038
|
|
1039 static Lisp_Object pending_timeout_list, pending_async_timeout_list;
|
|
1040
|
|
1041 static Lisp_Object Vtimeout_free_list;
|
|
1042
|
|
1043 static Lisp_Object
|
|
1044 mark_timeout (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
1045 {
|
|
1046 struct timeout *tm = (struct timeout *) XOPAQUE_DATA (obj);
|
|
1047 (markobj) (tm->function);
|
|
1048 return tm->object;
|
|
1049 }
|
|
1050
|
|
1051 /* Generate a timeout and return its ID. */
|
|
1052
|
|
1053 int
|
|
1054 event_stream_generate_wakeup (unsigned int milliseconds,
|
|
1055 unsigned int vanilliseconds,
|
|
1056 Lisp_Object function, Lisp_Object object,
|
|
1057 int async_p)
|
|
1058 {
|
|
1059 Lisp_Object op = allocate_managed_opaque (Vtimeout_free_list, 0);
|
|
1060 struct timeout *timeout = (struct timeout *) XOPAQUE_DATA (op);
|
|
1061 EMACS_TIME current_time;
|
|
1062 EMACS_TIME interval;
|
|
1063
|
|
1064 timeout->id = timeout_id_tick++;
|
|
1065 timeout->resignal_msecs = vanilliseconds;
|
|
1066 timeout->function = function;
|
|
1067 timeout->object = object;
|
|
1068
|
|
1069 EMACS_GET_TIME (current_time);
|
|
1070 EMACS_SET_SECS_USECS (interval, milliseconds / 1000,
|
|
1071 1000 * (milliseconds % 1000));
|
|
1072 EMACS_ADD_TIME (timeout->next_signal_time, current_time, interval);
|
|
1073
|
|
1074 if (async_p)
|
|
1075 {
|
|
1076 timeout->interval_id =
|
|
1077 event_stream_add_async_timeout (timeout->next_signal_time);
|
|
1078 pending_async_timeout_list = noseeum_cons (op,
|
|
1079 pending_async_timeout_list);
|
|
1080 }
|
|
1081 else
|
|
1082 {
|
|
1083 timeout->interval_id =
|
|
1084 event_stream_add_timeout (timeout->next_signal_time);
|
|
1085 pending_timeout_list = noseeum_cons (op, pending_timeout_list);
|
|
1086 }
|
|
1087 return timeout->id;
|
|
1088 }
|
|
1089
|
|
1090 /* Given the INTERVAL-ID of a timeout just signalled, resignal the timeout
|
|
1091 as necessary and return the timeout's ID and function and object slots.
|
|
1092
|
|
1093 This should be called as a result of receiving notice that a timeout
|
|
1094 has fired. INTERVAL-ID is *not* the timeout's ID, but is the ID that
|
|
1095 identifies this particular firing of the timeout. INTERVAL-ID's and
|
|
1096 timeout ID's are in separate number spaces and bear no relation to
|
|
1097 each other. The INTERVAL-ID is all that the event callback routines
|
|
1098 work with: they work only with one-shot intervals, not with timeouts
|
|
1099 that may fire repeatedly.
|
|
1100
|
|
1101 NOTE: The returned FUNCTION and OBJECT are *not* GC-protected at all.
|
|
1102 */
|
|
1103
|
|
1104 static int
|
|
1105 event_stream_resignal_wakeup (int interval_id, int async_p,
|
|
1106 Lisp_Object *function, Lisp_Object *object)
|
|
1107 {
|
|
1108 Lisp_Object op = Qnil, rest;
|
|
1109 struct timeout *timeout;
|
|
1110 Lisp_Object *timeout_list;
|
|
1111 struct gcpro gcpro1;
|
|
1112 int id;
|
|
1113
|
|
1114 GCPRO1 (op); /* just in case ... because it's removed from the list
|
|
1115 for awhile. */
|
|
1116
|
|
1117 if (async_p)
|
|
1118 timeout_list = &pending_async_timeout_list;
|
|
1119 else
|
|
1120 timeout_list = &pending_timeout_list;
|
|
1121
|
|
1122 /* Find the timeout on the list of pending ones. */
|
|
1123 LIST_LOOP (rest, *timeout_list)
|
|
1124 {
|
|
1125 timeout = (struct timeout *) XOPAQUE_DATA (XCAR (rest));
|
|
1126 if (timeout->interval_id == interval_id)
|
|
1127 break;
|
|
1128 }
|
|
1129
|
|
1130 assert (!NILP (rest));
|
|
1131 op = XCAR (rest);
|
|
1132 timeout = (struct timeout *) XOPAQUE_DATA (op);
|
|
1133 /* We make sure to snarf the data out of the timeout object before
|
|
1134 we free it with free_managed_opaque(). */
|
|
1135 id = timeout->id;
|
|
1136 *function = timeout->function;
|
|
1137 *object = timeout->object;
|
|
1138
|
|
1139 /* Remove this one from the list of pending timeouts */
|
|
1140 *timeout_list = delq_no_quit_and_free_cons (op, *timeout_list);
|
|
1141
|
|
1142 /* If this timeout wants to be resignalled, do it now. */
|
|
1143 if (timeout->resignal_msecs)
|
|
1144 {
|
|
1145 EMACS_TIME current_time;
|
|
1146 EMACS_TIME interval;
|
|
1147
|
|
1148 /* Determine the time that the next resignalling should occur.
|
|
1149 We do that by adding the interval time to the last signalled
|
|
1150 time until we get a time that's current.
|
|
1151
|
|
1152 (This way, it doesn't matter if the timeout was signalled
|
|
1153 exactly when we asked for it, or at some time later.)
|
|
1154 */
|
|
1155 EMACS_GET_TIME (current_time);
|
|
1156 EMACS_SET_SECS_USECS (interval, timeout->resignal_msecs / 1000,
|
|
1157 1000 * (timeout->resignal_msecs % 1000));
|
|
1158 do
|
|
1159 {
|
|
1160 EMACS_ADD_TIME (timeout->next_signal_time, timeout->next_signal_time,
|
|
1161 interval);
|
|
1162 } while (EMACS_TIME_GREATER (current_time, timeout->next_signal_time));
|
|
1163
|
|
1164 if (async_p)
|
|
1165 timeout->interval_id =
|
|
1166 event_stream_add_async_timeout (timeout->next_signal_time);
|
|
1167 else
|
|
1168 timeout->interval_id =
|
|
1169 event_stream_add_timeout (timeout->next_signal_time);
|
|
1170 /* Add back onto the list. Note that the effect of this
|
|
1171 is to move frequently-hit timeouts to the front of the
|
|
1172 list, which is a good thing. */
|
|
1173 *timeout_list = noseeum_cons (op, *timeout_list);
|
|
1174 }
|
|
1175 else
|
|
1176 free_managed_opaque (Vtimeout_free_list, op);
|
|
1177
|
|
1178 UNGCPRO;
|
|
1179 return id;
|
|
1180 }
|
|
1181
|
|
1182 void
|
|
1183 event_stream_disable_wakeup (int id, int async_p)
|
|
1184 {
|
|
1185 struct timeout *timeout = 0;
|
|
1186 Lisp_Object rest = Qnil;
|
|
1187 Lisp_Object *timeout_list;
|
|
1188
|
|
1189 if (async_p)
|
|
1190 timeout_list = &pending_async_timeout_list;
|
|
1191 else
|
|
1192 timeout_list = &pending_timeout_list;
|
|
1193
|
|
1194 /* Find the timeout on the list of pending ones, if it's still there. */
|
|
1195 LIST_LOOP (rest, *timeout_list)
|
|
1196 {
|
|
1197 timeout = (struct timeout *) XOPAQUE_DATA (XCAR (rest));
|
|
1198 if (timeout->id == id)
|
|
1199 break;
|
|
1200 }
|
|
1201
|
|
1202 /* If we found it, remove it from the list and disable the pending
|
|
1203 one-shot. */
|
|
1204 if (!NILP (rest))
|
|
1205 {
|
|
1206 Lisp_Object op = XCAR (rest);
|
|
1207 *timeout_list =
|
|
1208 delq_no_quit_and_free_cons (op, *timeout_list);
|
|
1209 if (async_p)
|
|
1210 event_stream_remove_async_timeout (timeout->interval_id);
|
|
1211 else
|
|
1212 event_stream_remove_timeout (timeout->interval_id);
|
|
1213 free_managed_opaque (Vtimeout_free_list, op);
|
|
1214 }
|
|
1215 }
|
|
1216
|
74
|
1217 int
|
|
1218 event_stream_wakeup_pending_p (int id, int async_p)
|
|
1219 {
|
|
1220 struct timeout *timeout;
|
|
1221 Lisp_Object rest = Qnil;
|
|
1222 Lisp_Object timeout_list;
|
|
1223 int found = 0;
|
|
1224
|
|
1225
|
|
1226 if (async_p)
|
|
1227 timeout_list = pending_async_timeout_list;
|
|
1228 else
|
|
1229 timeout_list = pending_timeout_list;
|
|
1230
|
|
1231 /* Find the element on the list of pending ones, if it's still there. */
|
|
1232 LIST_LOOP (rest, timeout_list)
|
|
1233 {
|
|
1234 timeout = (struct timeout *) XOPAQUE_DATA (XCAR (rest));
|
|
1235 if (timeout->id == id)
|
|
1236 {
|
|
1237 found = 1;
|
|
1238 break;
|
|
1239 }
|
|
1240 }
|
|
1241
|
|
1242 return found;
|
|
1243 }
|
|
1244
|
0
|
1245
|
|
1246 /**** Asynch. timeout functions (see also signal.c) ****/
|
|
1247
|
|
1248 #if !defined (SIGIO) && !defined (DONT_POLL_FOR_QUIT)
|
|
1249 extern int poll_for_quit_id;
|
|
1250 #endif
|
|
1251
|
|
1252 #ifndef SIGCHLD
|
|
1253 extern int poll_for_sigchld_id;
|
|
1254 #endif
|
|
1255
|
|
1256 void
|
|
1257 event_stream_deal_with_async_timeout (int interval_id)
|
|
1258 {
|
|
1259 /* This function can GC */
|
|
1260 Lisp_Object humpty, dumpty;
|
|
1261 #if (!defined (SIGIO) && !defined (DONT_POLL_FOR_QUIT)) || !defined (SIGCHLD)
|
|
1262 int id =
|
|
1263 #endif
|
|
1264 event_stream_resignal_wakeup (interval_id, 1, &humpty, &dumpty);
|
|
1265
|
|
1266 #if !defined (SIGIO) && !defined (DONT_POLL_FOR_QUIT)
|
|
1267 if (id == poll_for_quit_id)
|
|
1268 {
|
|
1269 quit_check_signal_happened = 1;
|
|
1270 quit_check_signal_tick_count++;
|
|
1271 return;
|
|
1272 }
|
|
1273 #endif
|
|
1274
|
|
1275 #if !defined (SIGCHLD)
|
|
1276 if (id == poll_for_sigchld_id)
|
|
1277 {
|
|
1278 kick_status_notify ();
|
|
1279 return;
|
|
1280 }
|
|
1281 #endif
|
|
1282
|
|
1283 /* call1 GC-protects its arguments */
|
|
1284 call1_trapping_errors ("Error in asynchronous timeout callback",
|
|
1285 humpty, dumpty);
|
|
1286 }
|
|
1287
|
|
1288
|
|
1289 /**** Lisp-level timeout functions. ****/
|
|
1290
|
|
1291 static unsigned long
|
|
1292 lisp_number_to_milliseconds (Lisp_Object secs, int allow_0)
|
|
1293 {
|
|
1294 unsigned long msecs;
|
|
1295 #ifdef LISP_FLOAT_TYPE
|
|
1296 double fsecs;
|
|
1297 CHECK_INT_OR_FLOAT (secs);
|
|
1298 fsecs = XFLOATINT (secs);
|
|
1299 #else
|
|
1300 long fsecs;
|
|
1301 CHECK_INT_OR_FLOAT (secs);
|
|
1302 fsecs = XINT (secs);
|
|
1303 #endif
|
|
1304 msecs = 1000 * fsecs;
|
|
1305 if (fsecs < 0)
|
|
1306 signal_simple_error ("timeout is negative", secs);
|
|
1307 if (!allow_0 && fsecs == 0)
|
|
1308 signal_simple_error ("timeout is non-positive", secs);
|
|
1309 if (fsecs >= (((unsigned int) 0xFFFFFFFF) / 1000))
|
|
1310 signal_simple_error
|
|
1311 ("timeout would exceed 32 bits when represented in milliseconds", secs);
|
|
1312 return msecs;
|
|
1313 }
|
|
1314
|
20
|
1315 DEFUN ("add-timeout", Fadd_timeout, 3, 4, 0, /*
|
0
|
1316 Add a timeout, to be signaled after the timeout period has elapsed.
|
|
1317 SECS is a number of seconds, expressed as an integer or a float.
|
|
1318 FUNCTION will be called after that many seconds have elapsed, with one
|
|
1319 argument, the given OBJECT. If the optional RESIGNAL argument is provided,
|
|
1320 then after this timeout expires, `add-timeout' will automatically be called
|
|
1321 again with RESIGNAL as the first argument.
|
|
1322
|
|
1323 This function returns an object which is the id number of this particular
|
|
1324 timeout. You can pass that object to `disable-timeout' to turn off the
|
|
1325 timeout before it has been signalled.
|
|
1326
|
|
1327 NOTE: Id numbers as returned by this function are in a distinct namespace
|
|
1328 from those returned by `add-async-timeout'. This means that the same id
|
|
1329 number could refer to a pending synchronous timeout and a different pending
|
|
1330 asynchronous timeout, and that you cannot pass an id from `add-timeout'
|
|
1331 to `disable-async-timeout', or vice-versa.
|
|
1332
|
|
1333 The number of seconds may be expressed as a floating-point number, in which
|
|
1334 case some fractional part of a second will be used. Caveat: the usable
|
|
1335 timeout granularity will vary from system to system.
|
|
1336
|
|
1337 Adding a timeout causes a timeout event to be returned by `next-event', and
|
|
1338 the function will be invoked by `dispatch-event,' so if emacs is in a tight
|
|
1339 loop, the function will not be invoked until the next call to sit-for or
|
|
1340 until the return to top-level (the same is true of process filters).
|
|
1341
|
|
1342 If you need to have a timeout executed even when XEmacs is in the midst of
|
|
1343 running Lisp code, use `add-async-timeout'.
|
|
1344
|
|
1345 WARNING: if you are thinking of calling add-timeout from inside of a
|
|
1346 callback function as a way of resignalling a timeout, think again. There
|
|
1347 is a race condition. That's why the RESIGNAL argument exists.
|
20
|
1348 */
|
|
1349 (secs, function, object, resignal))
|
0
|
1350 {
|
|
1351 unsigned long msecs = lisp_number_to_milliseconds (secs, 0);
|
|
1352 unsigned long msecs2 = (NILP (resignal) ? 0 :
|
|
1353 lisp_number_to_milliseconds (resignal, 0));
|
|
1354 int id;
|
|
1355 Lisp_Object lid;
|
|
1356 id = event_stream_generate_wakeup (msecs, msecs2, function, object, 0);
|
|
1357 lid = make_int (id);
|
|
1358 if (id != XINT (lid)) abort ();
|
|
1359 return lid;
|
|
1360 }
|
|
1361
|
20
|
1362 DEFUN ("disable-timeout", Fdisable_timeout, 1, 1, 0, /*
|
0
|
1363 Disable a timeout from signalling any more.
|
|
1364 ID should be a timeout id number as returned by `add-timeout'. If ID
|
|
1365 corresponds to a one-shot timeout that has already signalled, nothing
|
|
1366 will happen.
|
|
1367
|
|
1368 It will not work to call this function on an id number returned by
|
|
1369 `add-async-timeout'. Use `disable-async-timeout' for that.
|
20
|
1370 */
|
|
1371 (id))
|
0
|
1372 {
|
|
1373 CHECK_INT (id);
|
|
1374 event_stream_disable_wakeup (XINT (id), 0);
|
|
1375 return Qnil;
|
|
1376 }
|
|
1377
|
20
|
1378 DEFUN ("add-async-timeout", Fadd_async_timeout, 3, 4, 0, /*
|
0
|
1379 Add an asynchronous timeout, to be signaled after an interval has elapsed.
|
|
1380 SECS is a number of seconds, expressed as an integer or a float.
|
|
1381 FUNCTION will be called after that many seconds have elapsed, with one
|
|
1382 argument, the given OBJECT. If the optional RESIGNAL argument is provided,
|
|
1383 then after this timeout expires, `add-async-timeout' will automatically be
|
|
1384 called again with RESIGNAL as the first argument.
|
|
1385
|
|
1386 This function returns an object which is the id number of this particular
|
|
1387 timeout. You can pass that object to `disable-async-timeout' to turn off
|
|
1388 the timeout before it has been signalled.
|
|
1389
|
|
1390 NOTE: Id numbers as returned by this function are in a distinct namespace
|
|
1391 from those returned by `add-timeout'. This means that the same id number
|
|
1392 could refer to a pending synchronous timeout and a different pending
|
|
1393 asynchronous timeout, and that you cannot pass an id from
|
|
1394 `add-async-timeout' to `disable-timeout', or vice-versa.
|
|
1395
|
|
1396 The number of seconds may be expressed as a floating-point number, in which
|
|
1397 case some fractional part of a second will be used. Caveat: the usable
|
|
1398 timeout granularity will vary from system to system.
|
|
1399
|
|
1400 Adding an asynchronous timeout causes the function to be invoked as soon
|
|
1401 as the timeout occurs, even if XEmacs is in the midst of executing some
|
|
1402 other code. (This is unlike the synchronous timeouts added with
|
|
1403 `add-timeout', where the timeout will only be signalled when XEmacs is
|
|
1404 waiting for events, i.e. the next return to top-level or invocation of
|
|
1405 `sit-for' or related functions.) This means that the function that is
|
|
1406 called *must* not signal an error or change any global state (e.g. switch
|
|
1407 buffers or windows) except when locking code is in place to make sure
|
|
1408 that race conditions don't occur in the interaction between the
|
|
1409 asynchronous timeout function and other code.
|
|
1410
|
|
1411 Under most circumstances, you should use `add-timeout' instead, as it is
|
|
1412 much safer. Asynchronous timeouts should only be used when such behavior
|
|
1413 is really necessary.
|
|
1414
|
|
1415 Asynchronous timeouts are blocked and will not occur when `inhibit-quit'
|
|
1416 is non-nil. As soon as `inhibit-quit' becomes nil again, any pending
|
|
1417 asynchronous timeouts will get called immediately. (Multiple occurrences
|
|
1418 of the same asynchronous timeout are not queued, however.) While the
|
|
1419 callback function of an asynchronous timeout is invoked, `inhibit-quit'
|
|
1420 is automatically bound to non-nil, and thus other asynchronous timeouts
|
|
1421 will be blocked unless the callback function explicitly sets `inhibit-quit'
|
|
1422 to nil.
|
|
1423
|
|
1424 WARNING: if you are thinking of calling `add-async-timeout' from inside of a
|
|
1425 callback function as a way of resignalling a timeout, think again. There
|
|
1426 is a race condition. That's why the RESIGNAL argument exists.
|
20
|
1427 */
|
70
|
1428 (secs, function, object, resignal))
|
0
|
1429 {
|
|
1430 unsigned long msecs = lisp_number_to_milliseconds (secs, 0);
|
|
1431 unsigned long msecs2 = (NILP (resignal) ? 0 :
|
|
1432 lisp_number_to_milliseconds (resignal, 0));
|
|
1433 int id;
|
|
1434 Lisp_Object lid;
|
|
1435 id = event_stream_generate_wakeup (msecs, msecs2, function, object, 1);
|
|
1436 lid = make_int (id);
|
|
1437 if (id != XINT (lid)) abort ();
|
|
1438 return lid;
|
|
1439 }
|
|
1440
|
20
|
1441 DEFUN ("disable-async-timeout", Fdisable_async_timeout, 1, 1, 0, /*
|
0
|
1442 Disable an asynchronous timeout from signalling any more.
|
|
1443 ID should be a timeout id number as returned by `add-async-timeout'. If ID
|
|
1444 corresponds to a one-shot timeout that has already signalled, nothing
|
|
1445 will happen.
|
|
1446
|
|
1447 It will not work to call this function on an id number returned by
|
|
1448 `add-timeout'. Use `disable-timeout' for that.
|
20
|
1449 */
|
|
1450 (id))
|
0
|
1451 {
|
|
1452 CHECK_INT (id);
|
|
1453 event_stream_disable_wakeup (XINT (id), 1);
|
|
1454 return Qnil;
|
|
1455 }
|
|
1456
|
|
1457
|
|
1458 /**********************************************************************/
|
|
1459 /* enqueuing and dequeuing events */
|
|
1460 /**********************************************************************/
|
|
1461
|
|
1462 /* Add an event to the back of the command-event queue: it will be the next
|
|
1463 event read after all pending events. This only works on keyboard,
|
|
1464 mouse-click, misc-user, and eval events.
|
|
1465 */
|
|
1466 void
|
|
1467 enqueue_command_event (Lisp_Object event)
|
|
1468 {
|
|
1469 enqueue_event (event, &command_event_queue, &command_event_queue_tail);
|
|
1470 }
|
|
1471
|
|
1472 Lisp_Object
|
|
1473 dequeue_command_event (void)
|
|
1474 {
|
|
1475 return dequeue_event (&command_event_queue, &command_event_queue_tail);
|
|
1476 }
|
|
1477
|
|
1478 /* put the event on the typeahead queue, unless
|
|
1479 the event is the quit char, in which case the `QUIT'
|
|
1480 which will occur on the next trip through this loop is
|
|
1481 all the processing we should do - leaving it on the queue
|
|
1482 would cause the quit to be processed twice.
|
|
1483 */
|
|
1484 static void
|
|
1485 enqueue_command_event_1 (Lisp_Object event_to_copy)
|
|
1486 {
|
|
1487 /* do not call check_quit() here. Vquit_flag was set in
|
|
1488 next_event_internal. */
|
|
1489 if (NILP (Vquit_flag))
|
|
1490 enqueue_command_event (Fcopy_event (event_to_copy, Qnil));
|
|
1491 }
|
|
1492
|
|
1493 void
|
|
1494 enqueue_magic_eval_event (void (*fun) (Lisp_Object), Lisp_Object object)
|
|
1495 {
|
|
1496 Lisp_Object event;
|
|
1497
|
|
1498 event = Fmake_event ();
|
|
1499
|
|
1500 XEVENT (event)->event_type = magic_eval_event;
|
|
1501 /* channel for magic_eval events is nil */
|
|
1502 XEVENT (event)->event.magic_eval.internal_function = fun;
|
|
1503 XEVENT (event)->event.magic_eval.object = object;
|
|
1504 enqueue_command_event (event);
|
|
1505 }
|
|
1506
|
20
|
1507 DEFUN ("enqueue-eval-event", Fenqueue_eval_event, 2, 2, 0, /*
|
0
|
1508 Add an eval event to the back of the eval event queue.
|
|
1509 When this event is dispatched, FUNCTION (which should be a function
|
|
1510 of one argument) will be called with OBJECT as its argument.
|
|
1511 See `next-event' for a description of event types and how events
|
|
1512 are received.
|
20
|
1513 */
|
|
1514 (function, object))
|
0
|
1515 {
|
|
1516 Lisp_Object event;
|
|
1517
|
|
1518 event = Fmake_event ();
|
|
1519
|
|
1520 XEVENT (event)->event_type = eval_event;
|
|
1521 /* channel for eval events is nil */
|
|
1522 XEVENT (event)->event.eval.function = function;
|
|
1523 XEVENT (event)->event.eval.object = object;
|
|
1524 enqueue_command_event (event);
|
|
1525
|
|
1526 return event;
|
|
1527 }
|
|
1528
|
|
1529 Lisp_Object
|
|
1530 enqueue_misc_user_event (Lisp_Object channel, Lisp_Object function,
|
|
1531 Lisp_Object object)
|
|
1532 {
|
|
1533 Lisp_Object event;
|
|
1534
|
|
1535 event = Fmake_event ();
|
|
1536
|
|
1537 XEVENT (event)->event_type = misc_user_event;
|
|
1538 XEVENT (event)->channel = channel;
|
|
1539 XEVENT (event)->event.eval.function = function;
|
|
1540 XEVENT (event)->event.eval.object = object;
|
|
1541 enqueue_command_event (event);
|
|
1542
|
|
1543 return event;
|
|
1544 }
|
|
1545
|
|
1546
|
|
1547 /**********************************************************************/
|
|
1548 /* focus-event handling */
|
|
1549 /**********************************************************************/
|
|
1550
|
|
1551 /*
|
|
1552
|
|
1553 Ben's capsule lecture on focus:
|
|
1554
|
|
1555 In FSFmacs `select-frame' never changes the window-manager frame
|
|
1556 focus. All it does is change the "selected frame". This is similar
|
|
1557 to what happens when we call `select-device' or `select-console'.
|
|
1558 Whenever an event comes in (including a keyboard event), its frame is
|
|
1559 selected; therefore, evaluating `select-frame' in *scratch* won't
|
|
1560 cause any effects because the next received event (in the same frame)
|
|
1561 will cause a switch back to the frame displaying *scratch*.
|
|
1562
|
|
1563 Whenever a focus-change event is received from the window manager, it
|
|
1564 generates a `switch-frame' event, which causes the Lisp function
|
|
1565 `handle-switch-frame' to get run. This basically just runs
|
|
1566 `select-frame' (see below, however).
|
|
1567
|
|
1568 In FSFmacs, if you want to have an operation run when a frame is
|
|
1569 selected, you supply an event binding for `switch-frame' (and then
|
|
1570 maybe call `handle-switch-frame', or something ...).
|
|
1571
|
|
1572 In XEmacs, we *do* change the window-manager frame focus as a result
|
|
1573 of `select-frame', but not until the next time an event is received,
|
|
1574 so that a function that momentarily changes the selected frame won't
|
|
1575 cause WM focus flashing. (#### There's something not quite right here;
|
|
1576 this is causing the wrong-cursor-focus problems that you occasionally
|
|
1577 see. But the general idea is correct.) This approach is winning for
|
|
1578 people who use the explicit-focus model, but is trickier to implement.
|
|
1579
|
|
1580 We also don't make the `switch-frame' event visible but instead have
|
|
1581 `select-frame-hook', which is a better approach.
|
|
1582
|
|
1583 There is the problem of surrogate minibuffers, where when we enter the
|
|
1584 minibuffer, you essentially want to temporarily switch the WM focus to
|
|
1585 the frame with the minibuffer, and switch it back when you exit the
|
|
1586 minibuffer.
|
|
1587
|
|
1588 FSFmacs solves this with the crockish `redirect-frame-focus', which
|
|
1589 says "for keyboard events received from FRAME, act like they're
|
|
1590 coming from FOCUS-FRAME". I think what this means is that, when
|
|
1591 a keyboard event comes in and the event manager is about to select the
|
|
1592 event's frame, if that frame has its focus redirected, the redirected-to
|
|
1593 frame is selected instead. That way, if you're in a minibufferless
|
|
1594 frame and enter the minibuffer, then all Lisp functions that run see
|
|
1595 the selected frame as the minibuffer's frame rather than the minibufferless
|
|
1596 frame you came from, so that (e.g.) your typing actually appears in
|
|
1597 the minibuffer's frame and things behave sanely.
|
|
1598
|
|
1599 There's also some weird logic that switches the redirected frame focus
|
|
1600 from one frame to another if Lisp code explicitly calls `select-frame'
|
|
1601 \(but not if `handle-switch-frame' is called), and saves and restores
|
|
1602 the frame focus in window configurations, etc. etc. All of this logic
|
|
1603 is heavily #if 0'd, with lots of comments saying "No, this approach
|
|
1604 doesn't seem to work, so I'm trying this ... is it reasonable?
|
|
1605 Well, I'm not sure ..." that are a red flag indicating crockishness.
|
|
1606
|
|
1607 Because of our way of doing things, we can avoid all this crock.
|
|
1608 Keyboard events never cause a select-frame (who cares what frame
|
|
1609 they're associated with? They come from a console, only). We change
|
|
1610 the actual WM focus to a surrogate minibuffer frame, so we don't have
|
|
1611 to do any internal redirection. In order to get the focus back,
|
|
1612 I took the approach in minibuf.el of just checking to see if the
|
|
1613 frame we moved to is still the selected frame, and move back to the
|
|
1614 old one if so. Conceivably we might have to do the weird "tracking"
|
|
1615 that FSFmacs does when `select-frame' is called, but I don't think
|
|
1616 so. If the selected frame moved from the minibuffer frame, then
|
|
1617 we just leave it there, figuring that someone knows what they're
|
|
1618 doing. Because we don't have any redirection recorded anywhere,
|
|
1619 it's safe to do this, and we don't end up with unwanted redirection.
|
|
1620
|
|
1621 */
|
|
1622
|
|
1623 static void
|
|
1624 run_select_frame_hook (void)
|
|
1625 {
|
|
1626 run_hook (Qselect_frame_hook);
|
|
1627 }
|
|
1628
|
|
1629 static void
|
|
1630 run_deselect_frame_hook (void)
|
|
1631 {
|
|
1632 #if 0 /* unclean! FSF calls this at all sorts of random places,
|
|
1633 including a bunch of places in their mouse.el. If this
|
|
1634 is implemented, it has to be done cleanly. */
|
|
1635 run_hook (Qmouse_leave_buffer_hook); /* #### Correct? It's also
|
|
1636 called in `call-interactively'.
|
|
1637 Does this mean it will be
|
|
1638 called twice? Oh well, FSF
|
|
1639 bug -- FSF calls it in
|
|
1640 `handle-switch-frame',
|
|
1641 which is approximately the
|
|
1642 same as the caller of this
|
|
1643 function. */
|
|
1644 #endif
|
|
1645 run_hook (Qdeselect_frame_hook);
|
|
1646 }
|
|
1647
|
|
1648 /* When select-frame is called, we want to tell the window system that
|
|
1649 the focus should be changed to point to the new frame. However,
|
|
1650 sometimes Lisp functions will temporarily change the selected frame
|
|
1651 (e.g. to call a function that operates on the selected frame),
|
|
1652 and it's annoying if this focus-change happens exactly when
|
|
1653 select-frame is called, because then you get some flickering of the
|
|
1654 window-manager border and perhaps other undesirable results. We
|
|
1655 really only want to change the focus when we're about to retrieve
|
|
1656 an event from the user. To do this, we keep track of the frame
|
|
1657 where the window-manager focus lies on, and just before waiting
|
|
1658 for user events, check the currently selected frame and change
|
|
1659 the focus as necessary. */
|
|
1660
|
|
1661 static void
|
|
1662 investigate_frame_change (void)
|
|
1663 {
|
|
1664 Lisp_Object devcons, concons;
|
|
1665
|
|
1666 /* if the selected frame was changed, change the window-system
|
|
1667 focus to the new frame. We don't do it when select-frame was
|
|
1668 called, to avoid flickering and other unwanted side effects when
|
|
1669 the frame is just changed temporarily. */
|
|
1670 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
1671 {
|
|
1672 struct device *d = XDEVICE (XCAR (devcons));
|
|
1673 Lisp_Object sel_frame = DEVICE_SELECTED_FRAME (d);
|
|
1674
|
|
1675 /* You'd think that maybe we should use FRAME_WITH_FOCUS_REAL,
|
98
|
1676 but that can cause us to end up in an infinite loop focusing
|
0
|
1677 between two frames. It seems that since the call to `select-frame'
|
|
1678 in emacs_handle_focus_change_final() is based on the _FOR_HOOKS
|
|
1679 value, we need to do so too. */
|
|
1680 if (!NILP (sel_frame) &&
|
72
|
1681 !focus_follows_mouse &&
|
0
|
1682 !EQ (DEVICE_FRAME_THAT_OUGHT_TO_HAVE_FOCUS (d), sel_frame) &&
|
|
1683 !NILP (DEVICE_FRAME_WITH_FOCUS_FOR_HOOKS (d)) &&
|
|
1684 !EQ (DEVICE_FRAME_WITH_FOCUS_FOR_HOOKS (d), sel_frame))
|
|
1685 {
|
|
1686 /* prevent us from issuing the same request more than once */
|
|
1687 DEVICE_FRAME_THAT_OUGHT_TO_HAVE_FOCUS (d) = sel_frame;
|
|
1688 MAYBE_DEVMETH (d, focus_on_frame, (XFRAME (sel_frame)));
|
|
1689 }
|
|
1690 }
|
|
1691 }
|
|
1692
|
|
1693 static Lisp_Object
|
|
1694 cleanup_after_missed_defocusing (Lisp_Object frame)
|
|
1695 {
|
|
1696 if (FRAMEP (frame) && FRAME_LIVE_P (XFRAME (frame)))
|
|
1697 Fselect_frame (frame);
|
|
1698 return Qnil;
|
|
1699 }
|
|
1700
|
|
1701 void
|
|
1702 emacs_handle_focus_change_preliminary (Lisp_Object frame_inp_and_dev)
|
|
1703 {
|
|
1704 Lisp_Object frame = Fcar (frame_inp_and_dev);
|
|
1705 Lisp_Object device = Fcar (Fcdr (frame_inp_and_dev));
|
|
1706 int in_p = !NILP (Fcdr (Fcdr (frame_inp_and_dev)));
|
|
1707 struct device *d;
|
|
1708
|
|
1709 if (!DEVICE_LIVE_P (XDEVICE (device)))
|
|
1710 return;
|
|
1711 else
|
|
1712 d = XDEVICE (device);
|
|
1713
|
|
1714 /* Any received focus-change notifications render invalid any
|
|
1715 pending focus-change requests. */
|
|
1716 DEVICE_FRAME_THAT_OUGHT_TO_HAVE_FOCUS (d) = Qnil;
|
|
1717 if (in_p)
|
|
1718 {
|
|
1719 Lisp_Object focus_frame;
|
|
1720
|
|
1721 if (!FRAME_LIVE_P (XFRAME (frame)))
|
|
1722 return;
|
|
1723 else
|
|
1724 focus_frame = DEVICE_FRAME_WITH_FOCUS_REAL (d);
|
|
1725
|
|
1726 /* Mark the minibuffer as changed to make sure it gets updated
|
|
1727 properly if the echo area is active. */
|
|
1728 MARK_WINDOWS_CHANGED (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame))));
|
|
1729
|
|
1730 if (FRAMEP (focus_frame) && !EQ (frame, focus_frame))
|
|
1731 {
|
|
1732 /* Oops, we missed a focus-out event. */
|
|
1733 DEVICE_FRAME_WITH_FOCUS_REAL (d) = Qnil;
|
|
1734 redisplay_redraw_cursor (XFRAME (focus_frame), 1);
|
|
1735 }
|
|
1736 DEVICE_FRAME_WITH_FOCUS_REAL (d) = frame;
|
|
1737 if (!EQ (frame, focus_frame))
|
|
1738 {
|
|
1739 redisplay_redraw_cursor (XFRAME (frame), 1);
|
|
1740 }
|
|
1741 }
|
|
1742 else
|
|
1743 {
|
|
1744 /* We ignore the frame reported in the event. If it's different
|
|
1745 from where we think the focus was, oh well -- we messed up.
|
|
1746 Nonetheless, we pretend we were right, for sensible behavior. */
|
|
1747 frame = DEVICE_FRAME_WITH_FOCUS_REAL (d);
|
|
1748 if (!NILP (frame))
|
|
1749 {
|
|
1750 DEVICE_FRAME_WITH_FOCUS_REAL (d) = Qnil;
|
|
1751
|
|
1752 if (FRAME_LIVE_P (XFRAME (frame)))
|
|
1753 redisplay_redraw_cursor (XFRAME (frame), 1);
|
|
1754 }
|
|
1755 }
|
|
1756 }
|
|
1757
|
|
1758 /* Called from the window-system-specific code when we receive a
|
|
1759 notification that the focus lies on a particular frame.
|
|
1760 Argument is a cons: (frame . (device . in-p)) where in-p is non-nil
|
|
1761 for focus-in.
|
|
1762 */
|
|
1763 void
|
|
1764 emacs_handle_focus_change_final (Lisp_Object frame_inp_and_dev)
|
|
1765 {
|
|
1766 Lisp_Object frame = Fcar (frame_inp_and_dev);
|
|
1767 Lisp_Object device = Fcar (Fcdr (frame_inp_and_dev));
|
|
1768 int in_p = !NILP (Fcdr (Fcdr (frame_inp_and_dev)));
|
|
1769 struct device *d;
|
|
1770 int count;
|
|
1771
|
|
1772 if (!DEVICE_LIVE_P (XDEVICE (device)))
|
|
1773 return;
|
|
1774 else
|
|
1775 d = XDEVICE (device);
|
|
1776
|
|
1777 if (in_p)
|
|
1778 {
|
|
1779 Lisp_Object focus_frame;
|
|
1780
|
|
1781 if (!FRAME_LIVE_P (XFRAME (frame)))
|
|
1782 return;
|
|
1783 else
|
|
1784 focus_frame = DEVICE_FRAME_WITH_FOCUS_FOR_HOOKS (d);
|
|
1785
|
|
1786 DEVICE_FRAME_WITH_FOCUS_FOR_HOOKS (d) = frame;
|
|
1787 if (FRAMEP (focus_frame) && !EQ (frame, focus_frame))
|
|
1788 {
|
|
1789 /* Oops, we missed a focus-out event. */
|
|
1790 Fselect_frame (focus_frame);
|
|
1791 /* Do an unwind-protect in case an error occurs in
|
|
1792 the deselect-frame-hook */
|
|
1793 count = specpdl_depth ();
|
|
1794 record_unwind_protect (cleanup_after_missed_defocusing, frame);
|
|
1795 run_deselect_frame_hook ();
|
|
1796 unbind_to (count, Qnil);
|
|
1797 /* the cleanup method changed the focus frame to nil, so
|
|
1798 we need to reflect this */
|
|
1799 focus_frame = Qnil;
|
|
1800 }
|
|
1801 else
|
|
1802 Fselect_frame (frame);
|
|
1803 if (!EQ (frame, focus_frame))
|
|
1804 run_select_frame_hook ();
|
|
1805 }
|
|
1806 else
|
|
1807 {
|
|
1808 /* We ignore the frame reported in the event. If it's different
|
|
1809 from where we think the focus was, oh well -- we messed up.
|
|
1810 Nonetheless, we pretend we were right, for sensible behavior. */
|
|
1811 frame = DEVICE_FRAME_WITH_FOCUS_FOR_HOOKS (d);
|
|
1812 if (!NILP (frame))
|
|
1813 {
|
|
1814 DEVICE_FRAME_WITH_FOCUS_FOR_HOOKS (d) = Qnil;
|
|
1815 run_deselect_frame_hook ();
|
|
1816 }
|
|
1817 }
|
|
1818 }
|
|
1819
|
|
1820
|
|
1821 /**********************************************************************/
|
|
1822 /* retrieving the next event */
|
|
1823 /**********************************************************************/
|
|
1824
|
|
1825 static int in_single_console;
|
|
1826
|
|
1827 /* #### These functions don't currently do anything. */
|
|
1828 void
|
|
1829 single_console_state (void)
|
|
1830 {
|
|
1831 in_single_console = 1;
|
|
1832 }
|
|
1833
|
|
1834 void
|
|
1835 any_console_state (void)
|
|
1836 {
|
|
1837 in_single_console = 0;
|
|
1838 }
|
|
1839
|
|
1840 int
|
|
1841 in_single_console_state (void)
|
|
1842 {
|
|
1843 return in_single_console;
|
|
1844 }
|
|
1845
|
|
1846 /* the number of keyboard characters read. callint.c wants this.
|
|
1847 */
|
|
1848 Charcount num_input_chars;
|
|
1849
|
|
1850 static void
|
108
|
1851 next_event_internal (Lisp_Object target_event, int allow_queued)
|
0
|
1852 {
|
|
1853 struct gcpro gcpro1;
|
|
1854 /* QUIT; This is incorrect - the caller must do this because some
|
|
1855 callers (ie, Fnext_event()) do not want to QUIT. */
|
|
1856
|
|
1857 assert (NILP (XEVENT_NEXT (target_event)));
|
|
1858
|
|
1859 GCPRO1 (target_event);
|
|
1860 investigate_frame_change ();
|
|
1861
|
|
1862 if (allow_queued && !NILP (command_event_queue))
|
|
1863 {
|
|
1864 Lisp_Object event = dequeue_command_event ();
|
|
1865 Fcopy_event (event, target_event);
|
|
1866 Fdeallocate_event (event);
|
|
1867 #ifdef DEBUG_XEMACS
|
|
1868 if (debug_emacs_events)
|
|
1869 {
|
|
1870 write_c_string ("(command event queue) ",
|
|
1871 Qexternal_debugging_output);
|
|
1872 print_internal (target_event, Qexternal_debugging_output, 1);
|
|
1873 write_c_string ("\n", Qexternal_debugging_output);
|
|
1874 }
|
|
1875 #endif
|
|
1876 }
|
|
1877 else
|
|
1878 {
|
|
1879 struct Lisp_Event *e = XEVENT (target_event);
|
|
1880
|
|
1881 /* The command_event_queue was empty. Wait for an event. */
|
|
1882 event_stream_next_event (e);
|
|
1883 /* If this was a timeout, then we need to extract some data
|
|
1884 out of the returned closure and might need to resignal
|
|
1885 it. */
|
|
1886 if (e->event_type == timeout_event)
|
|
1887 {
|
|
1888 Lisp_Object tristan, isolde;
|
|
1889
|
|
1890 e->event.timeout.id_number =
|
|
1891 event_stream_resignal_wakeup (e->event.timeout.interval_id, 0,
|
|
1892 &tristan, &isolde);
|
|
1893
|
|
1894 e->event.timeout.function = tristan;
|
|
1895 e->event.timeout.object = isolde;
|
|
1896 #ifdef DEBUG_XEMACS
|
|
1897 /* next_event_internal() doesn't print out timeout events
|
|
1898 because of the extra info we just set. */
|
|
1899 if (debug_emacs_events)
|
|
1900 {
|
|
1901 print_internal (target_event, Qexternal_debugging_output, 1);
|
|
1902 write_c_string ("\n", Qexternal_debugging_output);
|
|
1903 }
|
|
1904 #endif
|
|
1905 }
|
|
1906
|
|
1907 /* If we read a ^G, then set quit-flag but do not discard the ^G.
|
|
1908 The callers of next_event_internal() will do one of two things:
|
|
1909
|
|
1910 -- set Vquit_flag to Qnil. (next-event does this.) This will
|
|
1911 cause the ^G to be treated as a normal keystroke.
|
|
1912 -- not change Vquit_flag but attempt to enqueue the ^G, at
|
|
1913 which point it will be discarded. The next time QUIT is
|
|
1914 called, it will notice that Vquit_flag was set.
|
|
1915
|
|
1916 */
|
|
1917 if (e->event_type == key_press_event &&
|
|
1918 event_matches_key_specifier_p
|
|
1919 (e, make_char (CONSOLE_QUIT_CHAR (XCONSOLE (EVENT_CHANNEL (e))))))
|
|
1920 {
|
|
1921 Vquit_flag = Qt;
|
|
1922 }
|
|
1923 }
|
|
1924
|
|
1925 UNGCPRO;
|
|
1926 }
|
|
1927
|
|
1928 static void
|
|
1929 run_pre_idle_hook (void)
|
|
1930 {
|
|
1931 if (!NILP (Vpre_idle_hook)
|
|
1932 && !detect_input_pending ())
|
|
1933 safe_run_hook_trapping_errors
|
|
1934 ("Error in `pre-idle-hook' (setting hook to nil)",
|
|
1935 Qpre_idle_hook, 1);
|
|
1936 }
|
|
1937
|
|
1938 static void push_this_command_keys (Lisp_Object event);
|
|
1939 static void push_recent_keys (Lisp_Object event);
|
|
1940 static void dribble_out_event (Lisp_Object event);
|
|
1941 static void execute_internal_event (Lisp_Object event);
|
|
1942
|
20
|
1943 DEFUN ("next-event", Fnext_event, 0, 2, 0, /*
|
0
|
1944 Return the next available event.
|
|
1945 Pass this object to `dispatch-event' to handle it.
|
|
1946 In most cases, you will want to use `next-command-event', which returns
|
|
1947 the next available \"user\" event (i.e. keypress, button-press,
|
|
1948 button-release, or menu selection) instead of this function.
|
|
1949
|
|
1950 If EVENT is non-nil, it should be an event object and will be filled in
|
|
1951 and returned; otherwise a new event object will be created and returned.
|
|
1952 If PROMPT is non-nil, it should be a string and will be displayed in the
|
|
1953 echo area while this function is waiting for an event.
|
|
1954
|
|
1955 The next available event will be
|
|
1956
|
|
1957 -- any events in `unread-command-events' or `unread-command-event'; else
|
|
1958 -- the next event in the currently executing keyboard macro, if any; else
|
|
1959 -- an event queued by `enqueue-eval-event', if any; else
|
|
1960 -- the next available event from the window system or terminal driver.
|
|
1961
|
|
1962 In the last case, this function will block until an event is available.
|
|
1963
|
|
1964 The returned event will be one of the following types:
|
|
1965
|
|
1966 -- a key-press event.
|
|
1967 -- a button-press or button-release event.
|
|
1968 -- a misc-user-event, meaning the user selected an item on a menu or used
|
|
1969 the scrollbar.
|
|
1970 -- a process event, meaning that output from a subprocess is available.
|
|
1971 -- a timeout event, meaning that a timeout has elapsed.
|
|
1972 -- an eval event, which simply causes a function to be executed when the
|
|
1973 event is dispatched. Eval events are generated by `enqueue-eval-event'
|
|
1974 or by certain other conditions happening.
|
|
1975 -- a magic event, indicating that some window-system-specific event
|
|
1976 happened (such as an focus-change notification) that must be handled
|
|
1977 synchronously with other events. `dispatch-event' knows what to do with
|
|
1978 these events.
|
20
|
1979 */
|
|
1980 (event, prompt))
|
0
|
1981 {
|
70
|
1982 /* This function can GC */
|
0
|
1983 /* #### We start out using the selected console before an event
|
|
1984 is received, for echoing the partially completed command.
|
|
1985 This is most definitely wrong -- there needs to be a separate
|
|
1986 echo area for each console! */
|
|
1987 struct console *con = XCONSOLE (Vselected_console);
|
|
1988 struct command_builder *command_builder =
|
|
1989 XCOMMAND_BUILDER (con->command_builder);
|
|
1990 int store_this_key = 0;
|
|
1991 struct gcpro gcpro1;
|
|
1992 GCPRO1 (event);
|
70
|
1993
|
0
|
1994 /* DO NOT do QUIT anywhere within this function or the functions it calls.
|
|
1995 We want to read the ^G as an event. */
|
|
1996
|
|
1997 if (NILP (event))
|
|
1998 event = Fmake_event ();
|
|
1999 else
|
|
2000 CHECK_LIVE_EVENT (event);
|
|
2001
|
|
2002 if (!NILP (prompt))
|
|
2003 {
|
|
2004 Bytecount len;
|
|
2005 CHECK_STRING (prompt);
|
|
2006
|
14
|
2007 len = XSTRING_LENGTH (prompt);
|
0
|
2008 if (command_builder->echo_buf_length < len)
|
|
2009 len = command_builder->echo_buf_length - 1;
|
14
|
2010 memcpy (command_builder->echo_buf, XSTRING_DATA (prompt), len);
|
0
|
2011 command_builder->echo_buf[len] = 0;
|
|
2012 command_builder->echo_buf_index = len;
|
|
2013 echo_area_message (XFRAME (CONSOLE_SELECTED_FRAME (con)),
|
|
2014 command_builder->echo_buf,
|
|
2015 Qnil, 0,
|
|
2016 command_builder->echo_buf_index,
|
|
2017 Qcommand);
|
|
2018 }
|
|
2019
|
|
2020 start_over_and_avoid_hosage:
|
|
2021
|
|
2022 /* If there is something in unread-command-events, simply return it.
|
|
2023 But do some error checking to make sure the user hasn't put something
|
|
2024 in the unread-command-events that they shouldn't have.
|
|
2025 This does not update this-command-keys and recent-keys.
|
|
2026 */
|
|
2027 if (!NILP (Vunread_command_events))
|
|
2028 {
|
|
2029 if (!CONSP (Vunread_command_events))
|
|
2030 {
|
|
2031 Vunread_command_events = Qnil;
|
|
2032 signal_error (Qwrong_type_argument,
|
|
2033 list3 (Qconsp, Vunread_command_events,
|
|
2034 Qunread_command_events));
|
|
2035 }
|
|
2036 else
|
|
2037 {
|
|
2038 Lisp_Object e = XCAR (Vunread_command_events);
|
|
2039 Vunread_command_events = XCDR (Vunread_command_events);
|
|
2040 if (!EVENTP (e) || !command_event_p (e))
|
|
2041 signal_error (Qwrong_type_argument,
|
|
2042 list3 (Qcommand_event_p, e, Qunread_command_events));
|
|
2043 redisplay ();
|
|
2044 if (!EQ (e, event))
|
|
2045 Fcopy_event (e, event);
|
|
2046 #ifdef DEBUG_XEMACS
|
|
2047 if (debug_emacs_events)
|
|
2048 {
|
|
2049 write_c_string ("(unread-command-events) ",
|
|
2050 Qexternal_debugging_output);
|
|
2051 print_internal (event, Qexternal_debugging_output, 1);
|
|
2052 write_c_string ("\n", Qexternal_debugging_output);
|
|
2053 }
|
|
2054 #endif
|
|
2055 }
|
|
2056 }
|
|
2057
|
|
2058 /* Do similar for unread-command-event (obsoleteness support).
|
|
2059 */
|
|
2060 else if (!NILP (Vunread_command_event))
|
|
2061 {
|
|
2062 Lisp_Object e = Vunread_command_event;
|
|
2063 Vunread_command_event = Qnil;
|
|
2064
|
|
2065 if (!EVENTP (e) || !command_event_p (e))
|
|
2066 {
|
|
2067 signal_error (Qwrong_type_argument,
|
|
2068 list3 (Qeventp, e, Qunread_command_event));
|
|
2069 }
|
|
2070 if (!EQ (e, event))
|
|
2071 Fcopy_event (e, event);
|
|
2072 redisplay ();
|
|
2073 #ifdef DEBUG_XEMACS
|
|
2074 if (debug_emacs_events)
|
|
2075 {
|
|
2076 write_c_string ("(unread-command-event) ",
|
|
2077 Qexternal_debugging_output);
|
|
2078 print_internal (event, Qexternal_debugging_output, 1);
|
|
2079 write_c_string ("\n", Qexternal_debugging_output);
|
|
2080 }
|
|
2081 #endif
|
|
2082 }
|
|
2083
|
|
2084 /* If we're executing a keyboard macro, take the next event from that,
|
|
2085 and update this-command-keys and recent-keys.
|
|
2086 Note that the unread-command-events take precedence over kbd macros.
|
|
2087 */
|
|
2088 else
|
|
2089 {
|
|
2090 if (!NILP (Vexecuting_macro))
|
|
2091 {
|
|
2092 redisplay ();
|
|
2093 pop_kbd_macro_event (event); /* This throws past us at
|
|
2094 end-of-macro. */
|
|
2095 store_this_key = 1;
|
|
2096 #ifdef DEBUG_XEMACS
|
|
2097 if (debug_emacs_events)
|
|
2098 {
|
|
2099 write_c_string ("(keyboard macro) ",
|
|
2100 Qexternal_debugging_output);
|
|
2101 print_internal (event, Qexternal_debugging_output, 1);
|
|
2102 write_c_string ("\n", Qexternal_debugging_output);
|
|
2103 }
|
|
2104 #endif
|
|
2105 }
|
|
2106 /* Otherwise, read a real event, possibly from the
|
|
2107 command_event_queue, and update this-command-keys and
|
|
2108 recent-keys. */
|
|
2109 else
|
|
2110 {
|
|
2111 run_pre_idle_hook ();
|
|
2112 redisplay ();
|
108
|
2113 next_event_internal (event, 1);
|
0
|
2114 Vquit_flag = Qnil; /* Read C-g as an event. */
|
|
2115 store_this_key = 1;
|
|
2116 }
|
|
2117 }
|
|
2118
|
|
2119 status_notify (); /* Notice process change */
|
|
2120
|
|
2121 #ifdef C_ALLOCA
|
|
2122 alloca (0); /* Cause a garbage collection now */
|
|
2123 /* Since we can free the most stuff here
|
|
2124 * (since this is typically called from
|
|
2125 * the command-loop top-level). */
|
|
2126 #endif /* C_ALLOCA */
|
|
2127
|
|
2128 if (object_dead_p (XEVENT (event)->channel))
|
|
2129 /* event_console_or_selected may crash if the channel is dead.
|
|
2130 Best just to eat it and get the next event. */
|
|
2131 goto start_over_and_avoid_hosage;
|
|
2132
|
|
2133 /* OK, now we can stop the selected-console kludge and use the
|
|
2134 actual console from the event. */
|
|
2135 con = event_console_or_selected (event);
|
|
2136 command_builder = XCOMMAND_BUILDER (con->command_builder);
|
|
2137
|
|
2138 switch (XEVENT_TYPE (event))
|
|
2139 {
|
|
2140 default:
|
|
2141 goto RETURN;
|
|
2142 case button_release_event:
|
|
2143 case misc_user_event:
|
|
2144 goto EXECUTE_KEY;
|
|
2145 case button_press_event: /* key or mouse input can trigger prompting */
|
|
2146 goto STORE_AND_EXECUTE_KEY;
|
|
2147 case key_press_event: /* any key input can trigger autosave */
|
|
2148 break;
|
|
2149 }
|
|
2150
|
|
2151 maybe_do_auto_save ();
|
|
2152 num_input_chars++;
|
|
2153 STORE_AND_EXECUTE_KEY:
|
|
2154 if (store_this_key)
|
|
2155 {
|
|
2156 echo_key_event (command_builder, event);
|
|
2157 }
|
|
2158
|
|
2159 EXECUTE_KEY:
|
|
2160 /* Store the last-input-event. The semantics of this is that it is
|
|
2161 the thing most recently returned by next-command-event. It need
|
|
2162 not have come from the keyboard or a keyboard macro, it may have
|
|
2163 come from unread-command-events. It's always a command-event (a
|
|
2164 key, click, or menu selection), never a motion or process event.
|
|
2165 */
|
|
2166 if (!EVENTP (Vlast_input_event))
|
|
2167 Vlast_input_event = Fmake_event ();
|
|
2168 if (XEVENT_TYPE (Vlast_input_event) == dead_event)
|
|
2169 {
|
|
2170 Vlast_input_event = Fmake_event ();
|
|
2171 error ("Someone deallocated last-input-event!");
|
|
2172 }
|
|
2173 if (! EQ (event, Vlast_input_event))
|
|
2174 Fcopy_event (event, Vlast_input_event);
|
|
2175
|
|
2176 /* last-input-char and last-input-time are derived from
|
|
2177 last-input-event.
|
|
2178 Note that last-input-char will never have its high-bit set, in an
|
|
2179 effort to sidestep the ambiguity between M-x and oslash.
|
|
2180 */
|
|
2181 Vlast_input_char = Fevent_to_character (Vlast_input_event,
|
|
2182 Qnil, Qnil, Qnil);
|
|
2183 {
|
|
2184 EMACS_TIME t;
|
|
2185 EMACS_GET_TIME (t);
|
|
2186 if (!CONSP (Vlast_input_time))
|
|
2187 Vlast_input_time = Fcons (Qnil, Qnil);
|
|
2188 XCAR (Vlast_input_time)
|
|
2189 = make_int ((EMACS_SECS (t) >> 16) & 0xffff);
|
|
2190 XCDR (Vlast_input_time)
|
|
2191 = make_int ((EMACS_SECS (t) >> 0) & 0xffff);
|
|
2192 }
|
|
2193
|
|
2194 /* If this key came from the keyboard or from a keyboard macro, then
|
|
2195 it goes into the recent-keys and this-command-keys vectors.
|
|
2196 If this key came from the keyboard, and we're defining a keyboard
|
|
2197 macro, then it goes into the macro.
|
|
2198 */
|
|
2199 if (store_this_key)
|
|
2200 {
|
|
2201 push_this_command_keys (event);
|
|
2202 push_recent_keys (event);
|
|
2203 dribble_out_event (event);
|
|
2204 if (!NILP (con->defining_kbd_macro) && NILP (Vexecuting_macro))
|
|
2205 {
|
|
2206 if (!EVENTP (command_builder->current_events))
|
|
2207 finalize_kbd_macro_chars (con);
|
|
2208 store_kbd_macro_event (event);
|
|
2209 }
|
|
2210 }
|
|
2211 /* If this is the help char and there is a help form, then execute the
|
|
2212 help form and swallow this character. This is the only place where
|
|
2213 calling Fnext_event() can cause arbitrary lisp code to run. Note
|
|
2214 that execute_help_form() calls Fnext_command_event(), which calls
|
|
2215 this function, as well as Fdispatch_event.
|
|
2216 */
|
|
2217 if (!NILP (Vhelp_form) &&
|
|
2218 event_matches_key_specifier_p (XEVENT (event), Vhelp_char))
|
|
2219 execute_help_form (command_builder, event);
|
|
2220
|
|
2221 RETURN:
|
|
2222 UNGCPRO;
|
|
2223 return (event);
|
|
2224 }
|
|
2225
|
20
|
2226 DEFUN ("next-command-event", Fnext_command_event, 0, 2, 0, /*
|
0
|
2227 Return the next available \"user\" event.
|
|
2228 Pass this object to `dispatch-event' to handle it.
|
|
2229
|
|
2230 If EVENT is non-nil, it should be an event object and will be filled in
|
|
2231 and returned; otherwise a new event object will be created and returned.
|
|
2232 If PROMPT is non-nil, it should be a string and will be displayed in the
|
|
2233 echo area while this function is waiting for an event.
|
|
2234
|
|
2235 The event returned will be a keyboard, mouse press, or mouse release event.
|
|
2236 If there are non-command events available (mouse motion, sub-process output,
|
|
2237 etc) then these will be executed (with `dispatch-event') and discarded. This
|
|
2238 function is provided as a convenience; it is equivalent to the lisp code
|
|
2239
|
|
2240 (while (progn
|
|
2241 (next-event event prompt)
|
|
2242 (not (or (key-press-event-p event)
|
|
2243 (button-press-event-p event)
|
|
2244 (button-release-event-p event)
|
|
2245 (misc-user-event-p event))))
|
|
2246 (dispatch-event event))
|
|
2247
|
20
|
2248 */
|
|
2249 (event, prompt))
|
0
|
2250 {
|
|
2251 /* This function can GC */
|
|
2252 struct gcpro gcpro1;
|
|
2253 GCPRO1 (event);
|
|
2254 maybe_echo_keys (XCOMMAND_BUILDER
|
|
2255 (XCONSOLE (Vselected_console)->
|
|
2256 command_builder), 0); /* #### This sucks bigtime */
|
|
2257 for (;;)
|
|
2258 {
|
|
2259 event = Fnext_event (event, prompt);
|
|
2260 if (command_event_p (event))
|
|
2261 break;
|
|
2262 else
|
|
2263 execute_internal_event (event);
|
|
2264 }
|
|
2265 UNGCPRO;
|
|
2266 return (event);
|
|
2267 }
|
|
2268
|
|
2269 static void
|
|
2270 reset_current_events (struct command_builder *command_builder)
|
|
2271 {
|
|
2272 Lisp_Object event = command_builder->current_events;
|
|
2273 reset_command_builder_event_chain (command_builder);
|
|
2274 if (EVENTP (event))
|
|
2275 deallocate_event_chain (event);
|
|
2276 }
|
|
2277
|
20
|
2278 DEFUN ("discard-input", Fdiscard_input, 0, 0, 0, /*
|
0
|
2279 Discard any pending \"user\" events.
|
|
2280 Also cancel any kbd macro being defined.
|
|
2281 A user event is a key press, button press, button release, or
|
|
2282 \"other-user\" event (menu selection or scrollbar action).
|
20
|
2283 */
|
|
2284 ())
|
0
|
2285 {
|
|
2286 /* This throws away user-input on the queue, but doesn't process any
|
|
2287 events. Calling dispatch_event() here leads to a race condition.
|
|
2288 */
|
|
2289 Lisp_Object event = Fmake_event ();
|
|
2290 Lisp_Object head = Qnil, tail = Qnil;
|
|
2291 Lisp_Object oiq = Vinhibit_quit;
|
|
2292 struct gcpro gcpro1, gcpro2;
|
|
2293 /* #### not correct here with Vselected_console? Should
|
|
2294 discard-input take a console argument, or maybe map over
|
|
2295 all consoles? */
|
|
2296 struct console *con = XCONSOLE (Vselected_console);
|
|
2297
|
|
2298 /* next_event_internal() can cause arbitrary Lisp code to be evalled */
|
|
2299 GCPRO2 (event, oiq);
|
|
2300 Vinhibit_quit = Qt;
|
|
2301 /* If a macro was being defined then we have to mark the modeline
|
|
2302 has changed to ensure that it gets updated correctly. */
|
|
2303 if (!NILP (con->defining_kbd_macro))
|
|
2304 MARK_MODELINE_CHANGED;
|
|
2305 con->defining_kbd_macro = Qnil;
|
|
2306 reset_current_events (XCOMMAND_BUILDER (con->command_builder));
|
|
2307
|
|
2308 while (!NILP (command_event_queue)
|
|
2309 || event_stream_event_pending_p (1))
|
|
2310 {
|
|
2311 /* This will take stuff off the command_event_queue, or read it
|
|
2312 from the event_stream, but it will not block.
|
|
2313 */
|
108
|
2314 next_event_internal (event, 1);
|
0
|
2315 Vquit_flag = Qnil; /* Treat C-g as a user event (ignore it).
|
|
2316 It is vitally important that we reset
|
|
2317 Vquit_flag here. Otherwise, if we're
|
|
2318 reading from a TTY console,
|
|
2319 maybe_read_quit_event() will notice
|
|
2320 that C-g has been set and send us
|
|
2321 another C-g. That will cause us
|
|
2322 to get right back here, and read
|
|
2323 another C-g, ad infinitum ... */
|
|
2324
|
|
2325 /* If the event is a user event, ignore it. */
|
|
2326 if (!command_event_p (event))
|
|
2327 {
|
|
2328 /* Otherwise, chain the event onto our list of events not to ignore,
|
|
2329 and keep reading until the queue is empty. This does not mean
|
|
2330 that if a subprocess is generating an infinite amount of output,
|
|
2331 we will never terminate (*provided* that the behavior of
|
|
2332 next_event_cb() is correct -- see the comment in events.h),
|
|
2333 because this loop ends as soon as there are no more user events
|
|
2334 on the command_event_queue or event_stream.
|
|
2335 */
|
|
2336 enqueue_event (Fcopy_event (event, Qnil), &head, &tail);
|
|
2337 }
|
|
2338 }
|
|
2339
|
|
2340 if (!NILP (command_event_queue) || !NILP (command_event_queue_tail))
|
|
2341 abort ();
|
|
2342
|
|
2343 /* Now tack our chain of events back on to the front of the queue.
|
|
2344 Actually, since the queue is now drained, we can just replace it.
|
|
2345 The effect of this will be that we have deleted all user events
|
|
2346 from the input stream without changing the relative ordering of
|
|
2347 any other events. (Some events may have been taken from the
|
|
2348 event_stream and added to the command_event_queue, however.)
|
|
2349
|
|
2350 At this time, the command_event_queue will contain only eval_events.
|
|
2351 */
|
|
2352
|
|
2353 command_event_queue = head;
|
|
2354 command_event_queue_tail = tail;
|
|
2355
|
|
2356 Fdeallocate_event (event);
|
|
2357 UNGCPRO;
|
|
2358
|
|
2359 Vinhibit_quit = oiq;
|
|
2360 return Qnil;
|
|
2361 }
|
|
2362
|
|
2363
|
|
2364 /**********************************************************************/
|
|
2365 /* pausing until an action occurs */
|
|
2366 /**********************************************************************/
|
|
2367
|
108
|
2368 /* This is used in accept-process-output, sleep-for and sit-for.
|
|
2369 Before running any process_events in these routines, we set
|
|
2370 recursive_sit_for to Qt, and use this unwind protect to reset it to
|
|
2371 Qnil upon exit. When recursive_sit_for is Qt, calling any of these
|
|
2372 three routines will cause them to return immediately no matter what
|
|
2373 their arguments were.
|
|
2374
|
|
2375 All of these routines install timeouts, so we clear the installed
|
|
2376 timeout as well.
|
|
2377
|
|
2378 Note: It's very easy to break the desired behaviours of these
|
|
2379 3 routines. If you make any changes to anything in this area, run
|
|
2380 the regression tests at the bottom of the file. -- dmoore */
|
|
2381
|
|
2382
|
|
2383 static Lisp_Object
|
|
2384 sit_for_unwind (Lisp_Object timeout_id)
|
|
2385 {
|
|
2386 if (!NILP(timeout_id))
|
|
2387 Fdisable_timeout (timeout_id);
|
|
2388
|
|
2389 recursive_sit_for = Qnil;
|
|
2390 return Qnil;
|
|
2391 }
|
|
2392
|
0
|
2393 /* #### Is (accept-process-output nil 3) supposed to be like (sleep-for 3)?
|
|
2394 */
|
|
2395
|
20
|
2396 DEFUN ("accept-process-output", Faccept_process_output, 0, 3, 0, /*
|
0
|
2397 Allow any pending output from subprocesses to be read by Emacs.
|
|
2398 It is read into the process' buffers or given to their filter functions.
|
|
2399 Non-nil arg PROCESS means do not return until some output has been received
|
86
|
2400 from PROCESS. Nil arg PROCESS means do not return until some output has
|
|
2401 been received from any process.
|
0
|
2402 If the second arg is non-nil, it is the maximum number of seconds to wait:
|
|
2403 this function will return after that much time even if no input has arrived
|
|
2404 from PROCESS. This argument may be a float, meaning wait some fractional
|
|
2405 part of a second.
|
|
2406 If the third arg is non-nil, it is a number of milliseconds that is added
|
|
2407 to the second arg. (This exists only for compatibility.)
|
|
2408 Return non-nil iff we received any output before the timeout expired.
|
108
|
2409
|
|
2410 If a filter function or timeout handler (such as installed by `add-timeout')
|
|
2411 calls any of accept-process-output, sleep-for, or sit-for, those calls
|
|
2412 will return nil immediately (regardless of their arguments) in recursive
|
|
2413 situations. It is recommended that you never call accept-process-output
|
|
2414 from inside of a process filter function or timer event (either synchronous
|
|
2415 or asynchronous).
|
20
|
2416 */
|
|
2417 (process, timeout_secs, timeout_msecs))
|
0
|
2418 {
|
|
2419 /* This function can GC */
|
|
2420 struct gcpro gcpro1, gcpro2;
|
|
2421 Lisp_Object event = Qnil;
|
|
2422 Lisp_Object result = Qnil;
|
|
2423 int timeout_id;
|
|
2424 int timeout_enabled = 0;
|
86
|
2425 int done = 0;
|
0
|
2426 struct buffer *old_buffer = current_buffer;
|
108
|
2427 int count;
|
|
2428
|
|
2429 /* Recusive call from a filter function or timeout handler. */
|
|
2430 if (!NILP(recursive_sit_for))
|
|
2431 return Qnil;
|
30
|
2432
|
0
|
2433 /* We preserve the current buffer but nothing else. If a focus
|
|
2434 change alters the selected window then the top level event loop
|
|
2435 will eventually alter current_buffer to match. In the mean time
|
|
2436 we don't want to mess up whatever called this function. */
|
|
2437
|
|
2438 if (!NILP (process))
|
|
2439 CHECK_PROCESS (process);
|
|
2440
|
|
2441 GCPRO2 (event, process);
|
|
2442
|
86
|
2443 if (!NILP (timeout_secs) || !NILP (timeout_msecs))
|
0
|
2444 {
|
|
2445 unsigned long msecs = 0;
|
|
2446 if (!NILP (timeout_secs))
|
|
2447 msecs = lisp_number_to_milliseconds (timeout_secs, 1);
|
|
2448 if (!NILP (timeout_msecs))
|
|
2449 {
|
|
2450 CHECK_NATNUM (timeout_msecs);
|
|
2451 msecs += XINT (timeout_msecs);
|
|
2452 }
|
|
2453 if (msecs)
|
|
2454 {
|
|
2455 timeout_id = event_stream_generate_wakeup (msecs, 0, Qnil, Qnil, 0);
|
|
2456 timeout_enabled = 1;
|
|
2457 }
|
|
2458 }
|
|
2459
|
|
2460 event = Fmake_event ();
|
|
2461
|
108
|
2462 count = specpdl_depth ();
|
|
2463 record_unwind_protect (sit_for_unwind,
|
|
2464 timeout_enabled ? make_int (timeout_id) : Qnil);
|
|
2465 recursive_sit_for = Qt;
|
|
2466
|
86
|
2467 while (!done &&
|
|
2468 ((NILP (process) && timeout_enabled) ||
|
|
2469 (NILP (process) && event_stream_event_pending_p (0)) ||
|
|
2470 (!NILP (process))))
|
0
|
2471 /* Calling detect_input_pending() is the wrong thing here, because
|
|
2472 that considers the Vunread_command_events and command_event_queue.
|
|
2473 We don't need to look at the command_event_queue because we are
|
|
2474 only interested in process events, which don't go on that. In
|
|
2475 fact, we can't read from it anyway, because we put stuff on it.
|
|
2476
|
|
2477 Note that event_stream->event_pending_p must be called in such
|
|
2478 a way that it says whether any events *of any kind* are ready,
|
|
2479 not just user events, or (accept-process-output nil) will fail
|
|
2480 to dispatch any process events that may be on the queue. It is
|
|
2481 not clear to me that this is important, because the top-level
|
|
2482 loop will process it, and I don't think that there is ever a
|
|
2483 time when one calls accept-process-output with a nil argument
|
|
2484 and really need the processes to be handled. */
|
|
2485 {
|
74
|
2486 /* If our timeout has arrived, we move along. */
|
82
|
2487 if (timeout_enabled && !event_stream_wakeup_pending_p (timeout_id, 0))
|
74
|
2488 {
|
|
2489 timeout_enabled = 0;
|
86
|
2490 done = 1; /* We're done. */
|
|
2491 continue; /* Don't call next_event_internal */
|
74
|
2492 }
|
|
2493
|
0
|
2494 QUIT; /* next_event_internal() does not QUIT, so check for ^G
|
|
2495 before reading output from the process - this makes it
|
|
2496 less likely that the filter will actually be aborted.
|
|
2497 */
|
|
2498
|
108
|
2499 next_event_internal (event, 0);
|
0
|
2500 /* If C-g was pressed while we were waiting, Vquit_flag got
|
|
2501 set and next_event_internal() also returns C-g. When
|
|
2502 we enqueue the C-g below, it will get discarded. The
|
|
2503 next time through, QUIT will be called and will signal a quit. */
|
|
2504 switch (XEVENT_TYPE (event))
|
|
2505 {
|
|
2506 case process_event:
|
|
2507 {
|
86
|
2508 if (NILP (process) ||
|
|
2509 EQ (XEVENT (event)->event.process.process, process))
|
0
|
2510 {
|
86
|
2511 done = 1;
|
0
|
2512 /* RMS's version always returns nil when proc is nil,
|
|
2513 and only returns t if input ever arrived on proc. */
|
|
2514 result = Qt;
|
|
2515 }
|
|
2516
|
|
2517 execute_internal_event (event);
|
|
2518 break;
|
|
2519 }
|
|
2520 case timeout_event:
|
74
|
2521 /* We execute the event even if it's ours, and notice that it's
|
|
2522 happened above. */
|
0
|
2523 case pointer_motion_event:
|
|
2524 case magic_event:
|
|
2525 {
|
20
|
2526 EXECUTE_INTERNAL:
|
0
|
2527 execute_internal_event (event);
|
|
2528 break;
|
|
2529 }
|
|
2530 default:
|
|
2531 {
|
|
2532 enqueue_command_event_1 (event);
|
|
2533 break;
|
|
2534 }
|
|
2535 }
|
|
2536 }
|
|
2537
|
108
|
2538 unbind_to (count, timeout_enabled ? make_int (timeout_id) : Qnil);
|
0
|
2539
|
|
2540 Fdeallocate_event (event);
|
|
2541 UNGCPRO;
|
|
2542 current_buffer = old_buffer;
|
|
2543 return result;
|
|
2544 }
|
|
2545
|
20
|
2546 DEFUN ("sleep-for", Fsleep_for, 1, 1, 0, /*
|
0
|
2547 Pause, without updating display, for ARG seconds.
|
|
2548 ARG may be a float, meaning pause for some fractional part of a second.
|
108
|
2549
|
|
2550 If a filter function or timeout handler (such as installed by `add-timeout')
|
|
2551 calls any of accept-process-output, sleep-for, or sit-for, those calls
|
|
2552 will return nil immediately (regardless of their arguments) in recursive
|
|
2553 situations. It is recommended that you never call sleep-for from inside
|
|
2554 of a process filter function or timer event (either synchronous or
|
|
2555 asynchronous).
|
20
|
2556 */
|
|
2557 (seconds))
|
0
|
2558 {
|
|
2559 /* This function can GC */
|
|
2560 unsigned long msecs = lisp_number_to_milliseconds (seconds, 1);
|
|
2561 int id;
|
|
2562 Lisp_Object event = Qnil;
|
108
|
2563 int count;
|
0
|
2564 struct gcpro gcpro1;
|
|
2565
|
108
|
2566 /* Recusive call from a filter function or timeout handler. */
|
|
2567 if (!NILP(recursive_sit_for))
|
|
2568 return Qnil;
|
|
2569
|
0
|
2570 GCPRO1 (event);
|
|
2571
|
|
2572 id = event_stream_generate_wakeup (msecs, 0, Qnil, Qnil, 0);
|
|
2573 event = Fmake_event ();
|
108
|
2574
|
|
2575 count = specpdl_depth ();
|
|
2576 record_unwind_protect (sit_for_unwind, make_int (id));
|
|
2577 recursive_sit_for = Qt;
|
|
2578
|
0
|
2579 while (1)
|
|
2580 {
|
74
|
2581 /* If our timeout has arrived, we move along. */
|
|
2582 if (!event_stream_wakeup_pending_p (id, 0))
|
|
2583 goto DONE_LABEL;
|
|
2584
|
0
|
2585 QUIT; /* next_event_internal() does not QUIT, so check for ^G
|
|
2586 before reading output from the process - this makes it
|
|
2587 less likely that the filter will actually be aborted.
|
|
2588 */
|
|
2589 /* We're a generator of the command_event_queue, so we can't be a
|
|
2590 consumer as well. We don't care about command and eval-events
|
|
2591 anyway.
|
|
2592 */
|
108
|
2593 next_event_internal (event, 0); /* blocks */
|
0
|
2594 /* See the comment in accept-process-output about Vquit_flag */
|
|
2595 switch (XEVENT_TYPE (event))
|
|
2596 {
|
|
2597 case timeout_event:
|
74
|
2598 /* We execute the event even if it's ours, and notice that it's
|
|
2599 happened above. */
|
108
|
2600 case process_event:
|
0
|
2601 case pointer_motion_event:
|
|
2602 case magic_event:
|
|
2603 {
|
|
2604 EXECUTE_INTERNAL:
|
|
2605 execute_internal_event (event);
|
|
2606 break;
|
|
2607 }
|
|
2608 default:
|
|
2609 {
|
|
2610 enqueue_command_event_1 (event);
|
|
2611 break;
|
|
2612 }
|
|
2613 }
|
|
2614 }
|
|
2615 DONE_LABEL:
|
108
|
2616 unbind_to (count, make_int (id));
|
0
|
2617 Fdeallocate_event (event);
|
|
2618 UNGCPRO;
|
|
2619 return Qnil;
|
|
2620 }
|
|
2621
|
20
|
2622 DEFUN ("sit-for", Fsit_for, 1, 2, 0, /*
|
0
|
2623 Perform redisplay, then wait ARG seconds or until user input is available.
|
|
2624 ARG may be a float, meaning a fractional part of a second.
|
|
2625 Optional second arg non-nil means don't redisplay, just wait for input.
|
|
2626 Redisplay is preempted as always if user input arrives, and does not
|
108
|
2627 happen if input is available before it starts.
|
0
|
2628 Value is t if waited the full time with no input arriving.
|
108
|
2629
|
|
2630 If a filter function or timeout handler (such as installed by `add-timeout')
|
|
2631 calls any of accept-process-output, sleep-for, or sit-for, those calls
|
|
2632 will return nil immediately (regardless of their arguments) in recursive
|
|
2633 situations. It is recommended that you never call sit-for from inside
|
|
2634 of a process filter function or timer event (either synchronous or
|
|
2635 asynchronous) with an argument other than 0.
|
20
|
2636 */
|
|
2637 (seconds, nodisplay))
|
0
|
2638 {
|
|
2639 /* This function can GC */
|
|
2640 unsigned long msecs = lisp_number_to_milliseconds (seconds, 1);
|
|
2641 Lisp_Object event, result;
|
|
2642 struct gcpro gcpro1;
|
|
2643 int id;
|
108
|
2644 int count;
|
|
2645
|
|
2646 /* Recusive call from a filter function or timeout handler. */
|
|
2647 if (!NILP(recursive_sit_for))
|
|
2648 return Qnil;
|
30
|
2649
|
0
|
2650 /* The unread-command-events count as pending input */
|
|
2651 if (!NILP (Vunread_command_events) || !NILP (Vunread_command_event))
|
|
2652 return Qnil;
|
|
2653
|
|
2654 /* If the command-builder already has user-input on it (not eval events)
|
|
2655 then that means we're done too.
|
|
2656 */
|
|
2657 if (!NILP (command_event_queue))
|
|
2658 {
|
|
2659 EVENT_CHAIN_LOOP (event, command_event_queue)
|
|
2660 {
|
|
2661 if (command_event_p (event))
|
|
2662 return (Qnil);
|
|
2663 }
|
|
2664 }
|
|
2665
|
|
2666 /* If we're in a macro, or noninteractive, or early in temacs, then
|
|
2667 don't wait. */
|
|
2668 if (noninteractive || !NILP (Vexecuting_macro))
|
|
2669 return (Qnil);
|
|
2670
|
|
2671 /* Otherwise, start reading events from the event_stream.
|
|
2672 Do this loop at least once even if (sit-for 0) so that we
|
|
2673 redisplay when no input pending.
|
|
2674 */
|
108
|
2675 GCPRO1 (event);
|
70
|
2676 event = Fmake_event ();
|
0
|
2677
|
|
2678 /* Generate the wakeup even if MSECS is 0, so that existing timeout/etc.
|
|
2679 events get processed. The old (pre-19.12) code special-cased this
|
|
2680 and didn't generate a wakeup, but the resulting behavior was less than
|
|
2681 ideal; viz. the occurrence of (sit-for 0.001) scattered throughout
|
|
2682 the E-Lisp universe. */
|
|
2683
|
|
2684 id = event_stream_generate_wakeup (msecs, 0, Qnil, Qnil, 0);
|
|
2685
|
108
|
2686 count = specpdl_depth ();
|
|
2687 record_unwind_protect (sit_for_unwind, make_int (id));
|
|
2688 recursive_sit_for = Qt;
|
|
2689
|
0
|
2690 while (1)
|
|
2691 {
|
|
2692 /* If there is no user input pending, then redisplay.
|
|
2693 */
|
|
2694 if (!event_stream_event_pending_p (1) && NILP (nodisplay))
|
|
2695 {
|
|
2696 run_pre_idle_hook ();
|
|
2697 redisplay ();
|
|
2698 }
|
|
2699
|
74
|
2700 /* If our timeout has arrived, we move along. */
|
|
2701 if (!event_stream_wakeup_pending_p (id, 0))
|
0
|
2702 {
|
|
2703 result = Qt;
|
|
2704 goto DONE_LABEL;
|
|
2705 }
|
|
2706
|
|
2707 QUIT; /* next_event_internal() does not QUIT, so check for ^G
|
|
2708 before reading output from the process - this makes it
|
|
2709 less likely that the filter will actually be aborted.
|
|
2710 */
|
|
2711 /* We're a generator of the command_event_queue, so we can't be a
|
|
2712 consumer as well. In fact, we know there's nothing on the
|
|
2713 command_event_queue that we didn't just put there.
|
|
2714 */
|
108
|
2715 next_event_internal (event, 0); /* blocks */
|
0
|
2716 /* See the comment in accept-process-output about Vquit_flag */
|
|
2717
|
|
2718 if (command_event_p (event))
|
|
2719 {
|
108
|
2720 QUIT; /* If the command was C-g check it here
|
|
2721 so that we abort out of the sit-for,
|
|
2722 not the next command. sleep-for and
|
|
2723 accept-process-output continue looping
|
|
2724 so they check QUIT again implicitly.*/
|
0
|
2725 result = Qnil;
|
|
2726 goto DONE_LABEL;
|
|
2727 }
|
|
2728 switch (XEVENT_TYPE (event))
|
|
2729 {
|
|
2730 case eval_event:
|
|
2731 {
|
|
2732 /* eval-events get delayed until later. */
|
|
2733 enqueue_command_event (Fcopy_event (event, Qnil));
|
|
2734 break;
|
|
2735 }
|
86
|
2736
|
0
|
2737 case timeout_event:
|
74
|
2738 /* We execute the event even if it's ours, and notice that it's
|
|
2739 happened above. */
|
|
2740 default:
|
0
|
2741 {
|
|
2742 EXECUTE_INTERNAL:
|
|
2743 execute_internal_event (event);
|
|
2744 break;
|
|
2745 }
|
|
2746 }
|
|
2747 }
|
|
2748
|
|
2749 DONE_LABEL:
|
108
|
2750 unbind_to (count, make_int (id));
|
0
|
2751
|
|
2752 /* Put back the event (if any) that made Fsit_for() exit before the
|
|
2753 timeout. Note that it is being added to the back of the queue, which
|
|
2754 would be inappropriate if there were any user events on the queue
|
|
2755 already: we would be misordering them. But we know that there are
|
|
2756 no user-events on the queue, or else we would not have reached this
|
|
2757 point at all.
|
|
2758 */
|
|
2759 if (NILP (result))
|
|
2760 enqueue_command_event (event);
|
|
2761 else
|
|
2762 Fdeallocate_event (event);
|
|
2763
|
|
2764 UNGCPRO;
|
|
2765 return (result);
|
|
2766 }
|
|
2767
|
|
2768 /* This handy little function is used by xselect.c and energize.c to
|
|
2769 wait for replies from processes that aren't really processes (that is,
|
|
2770 the X server and the Energize server).
|
|
2771 */
|
|
2772 void
|
|
2773 wait_delaying_user_input (int (*predicate) (void *arg), void *predicate_arg)
|
|
2774 {
|
|
2775 /* This function can GC */
|
|
2776 Lisp_Object event = Fmake_event ();
|
|
2777 struct gcpro gcpro1;
|
|
2778 GCPRO1 (event);
|
|
2779
|
|
2780 while (!(*predicate) (predicate_arg))
|
|
2781 {
|
|
2782 QUIT; /* next_event_internal() does not QUIT. */
|
|
2783
|
|
2784 /* We're a generator of the command_event_queue, so we can't be a
|
|
2785 consumer as well. Also, we have no reason to consult the
|
|
2786 command_event_queue; there are only user and eval-events there,
|
|
2787 and we'd just have to put them back anyway.
|
|
2788 */
|
108
|
2789 next_event_internal (event, 0);
|
0
|
2790 /* See the comment in accept-process-output about Vquit_flag */
|
|
2791 if (command_event_p (event)
|
|
2792 || (XEVENT_TYPE (event) == eval_event)
|
|
2793 || (XEVENT_TYPE (event) == magic_eval_event))
|
|
2794 enqueue_command_event_1 (event);
|
|
2795 else
|
|
2796 execute_internal_event (event);
|
|
2797 }
|
|
2798 UNGCPRO;
|
|
2799 }
|
|
2800
|
|
2801
|
|
2802 /**********************************************************************/
|
|
2803 /* dispatching events; command builder */
|
|
2804 /**********************************************************************/
|
|
2805
|
|
2806 static void
|
|
2807 execute_internal_event (Lisp_Object event)
|
|
2808 {
|
|
2809 /* events on dead channels get silently eaten */
|
|
2810 if (object_dead_p (XEVENT (event)->channel))
|
|
2811 return;
|
|
2812
|
|
2813 /* This function can GC */
|
|
2814 switch (XEVENT_TYPE (event))
|
|
2815 {
|
|
2816 case empty_event:
|
|
2817 return;
|
|
2818
|
|
2819 case eval_event:
|
|
2820 {
|
|
2821 call1 (XEVENT (event)->event.eval.function,
|
|
2822 XEVENT (event)->event.eval.object);
|
|
2823 return;
|
|
2824 }
|
|
2825
|
|
2826 case magic_eval_event:
|
|
2827 {
|
|
2828 (XEVENT (event)->event.magic_eval.internal_function)
|
|
2829 (XEVENT (event)->event.magic_eval.object);
|
|
2830 return;
|
|
2831 }
|
|
2832
|
|
2833 case pointer_motion_event:
|
|
2834 {
|
|
2835 if (!NILP (Vmouse_motion_handler))
|
|
2836 call1 (Vmouse_motion_handler, event);
|
|
2837 return;
|
|
2838 }
|
|
2839
|
|
2840 case process_event:
|
|
2841 {
|
|
2842 Lisp_Object p = XEVENT (event)->event.process.process;
|
|
2843 Charcount readstatus;
|
|
2844
|
|
2845 assert (PROCESSP (p));
|
|
2846 while ((readstatus = read_process_output (p)) > 0)
|
|
2847 ;
|
|
2848 if (readstatus > 0)
|
|
2849 ; /* this clauses never gets executed but allows the #ifdefs
|
|
2850 to work cleanly. */
|
|
2851 #ifdef EWOULDBLOCK
|
|
2852 else if (readstatus == -1 && errno == EWOULDBLOCK)
|
|
2853 ;
|
|
2854 #endif /* EWOULDBLOCK */
|
|
2855 #ifdef EAGAIN
|
|
2856 else if (readstatus == -1 && errno == EAGAIN)
|
|
2857 ;
|
|
2858 #endif /* EAGAIN */
|
|
2859 else if ((readstatus == 0 &&
|
|
2860 /* Note that we cannot distinguish between no input
|
|
2861 available now and a closed pipe.
|
|
2862 With luck, a closed pipe will be accompanied by
|
|
2863 subprocess termination and SIGCHLD. */
|
|
2864 (!network_connection_p (p) ||
|
|
2865 /*
|
|
2866 When connected to ToolTalk (i.e.
|
|
2867 connected_via_filedesc_p()), it's not possible to
|
|
2868 reliably determine whether there is a message
|
|
2869 waiting for ToolTalk to receive. ToolTalk expects
|
|
2870 to have tt_message_receive() called exactly once
|
|
2871 every time the file descriptor becomes active, so
|
|
2872 the filter function forces this by returning 0.
|
|
2873 Emacs must not interpret this as a closed pipe. */
|
|
2874 connected_via_filedesc_p (XPROCESS (p))))
|
|
2875 #ifdef HAVE_PTYS
|
|
2876 /* On some OSs with ptys, when the process on one end of
|
|
2877 a pty exits, the other end gets an error reading with
|
|
2878 errno = EIO instead of getting an EOF (0 bytes read).
|
|
2879 Therefore, if we get an error reading and errno =
|
|
2880 EIO, just continue, because the child process has
|
|
2881 exited and should clean itself up soon (e.g. when we
|
|
2882 get a SIGCHLD). */
|
|
2883 || (readstatus == -1 && errno == EIO)
|
|
2884 #endif
|
|
2885 )
|
|
2886 {
|
80
|
2887 /* Currently, we rely on SIGCHLD to indicate that the
|
|
2888 process has terminated. Unfortunately, on some systems
|
|
2889 the SIGCHLD gets missed some of the time. So we put an
|
|
2890 additional check in status_notify() to see whether a
|
|
2891 process has terminated. We must tell status_notify()
|
|
2892 to enable that check, and we do so now. */
|
0
|
2893 kick_status_notify ();
|
|
2894 }
|
|
2895 else
|
|
2896 {
|
|
2897 /* Deactivate network connection */
|
|
2898 Lisp_Object status = Fprocess_status (p);
|
|
2899 if (EQ (status, Qopen)
|
|
2900 /* In case somebody changes the theory of whether to
|
|
2901 return open as opposed to run for network connection
|
|
2902 "processes"... */
|
|
2903 || EQ (status, Qrun))
|
|
2904 update_process_status (p, Qexit, 256, 0);
|
|
2905 deactivate_process (p);
|
|
2906 }
|
|
2907
|
|
2908 /* We must call status_notify here to allow the
|
|
2909 event_stream->unselect_process_cb to be run if appropriate.
|
|
2910 Otherwise, dead fds may be selected for, and we will get a
|
|
2911 continuous stream of process events for them. Since we don't
|
|
2912 return until all process events have been flushed, we would
|
|
2913 get stuck here, processing events on a process whose status
|
|
2914 was 'exit. Call this after dispatch-event, or the fds will
|
|
2915 have been closed before we read the last data from them.
|
|
2916 It's safe for the filter to signal an error because
|
|
2917 status_notify() will be called on return to top-level.
|
|
2918 */
|
|
2919 status_notify ();
|
|
2920 return;
|
|
2921 }
|
|
2922
|
|
2923 case timeout_event:
|
|
2924 {
|
|
2925 struct Lisp_Event *e = XEVENT (event);
|
|
2926 if (!NILP (e->event.timeout.function))
|
|
2927 call1 (e->event.timeout.function,
|
|
2928 e->event.timeout.object);
|
|
2929 return;
|
|
2930 }
|
|
2931 case magic_event:
|
|
2932 {
|
|
2933 event_stream_handle_magic_event (XEVENT (event));
|
|
2934 return;
|
|
2935 }
|
|
2936 default:
|
|
2937 abort ();
|
|
2938 }
|
|
2939 }
|
|
2940
|
|
2941
|
|
2942
|
|
2943 static void
|
|
2944 this_command_keys_replace_suffix (Lisp_Object suffix, Lisp_Object chain)
|
|
2945 {
|
|
2946 Lisp_Object first_before_suffix =
|
|
2947 event_chain_find_previous (Vthis_command_keys, suffix);
|
|
2948
|
|
2949 if (NILP (first_before_suffix))
|
|
2950 Vthis_command_keys = chain;
|
|
2951 else
|
|
2952 XSET_EVENT_NEXT (first_before_suffix, chain);
|
|
2953 deallocate_event_chain (suffix);
|
|
2954 Vthis_command_keys_tail = event_chain_tail (chain);
|
|
2955 }
|
|
2956
|
|
2957 static void
|
|
2958 command_builder_replace_suffix (struct command_builder *builder,
|
|
2959 Lisp_Object suffix, Lisp_Object chain)
|
|
2960 {
|
|
2961 Lisp_Object first_before_suffix =
|
|
2962 event_chain_find_previous (builder->current_events, suffix);
|
|
2963
|
|
2964 if (NILP (first_before_suffix))
|
|
2965 builder->current_events = chain;
|
|
2966 else
|
|
2967 XSET_EVENT_NEXT (first_before_suffix, chain);
|
|
2968 deallocate_event_chain (suffix);
|
|
2969 builder->most_current_event = event_chain_tail (chain);
|
|
2970 }
|
|
2971
|
|
2972 static Lisp_Object
|
|
2973 command_builder_find_leaf_1 (struct command_builder *builder)
|
|
2974 {
|
|
2975 Lisp_Object event0 = builder->current_events;
|
|
2976
|
|
2977 if (NILP (event0))
|
|
2978 return (Qnil);
|
|
2979
|
|
2980 return event_binding (event0, 1);
|
|
2981 }
|
|
2982
|
|
2983 /* See if we can do function-key-map or key-translation-map translation
|
|
2984 on the current events in the command builder. If so, do this, and
|
|
2985 return the resulting binding, if any. */
|
|
2986
|
|
2987 static Lisp_Object
|
|
2988 munge_keymap_translate (struct command_builder *builder,
|
|
2989 enum munge_me_out_the_door munge,
|
|
2990 int has_normal_binding_p)
|
|
2991 {
|
|
2992 Lisp_Object suffix;
|
|
2993
|
|
2994 EVENT_CHAIN_LOOP (suffix, builder->munge_me[munge].first_mungeable_event)
|
|
2995 {
|
|
2996 Lisp_Object result = munging_key_map_event_binding (suffix, munge);
|
|
2997
|
|
2998 if (!NILP (result))
|
|
2999 {
|
|
3000 if (KEYMAPP (result))
|
|
3001 {
|
|
3002 if (NILP (builder->last_non_munged_event)
|
|
3003 && !has_normal_binding_p)
|
|
3004 builder->last_non_munged_event =
|
|
3005 builder->most_current_event;
|
|
3006 }
|
|
3007 else
|
|
3008 builder->last_non_munged_event = Qnil;
|
|
3009
|
|
3010 if (!KEYMAPP (result) && !VECTORP (result)
|
|
3011 && !STRINGP (result))
|
|
3012 {
|
|
3013 struct gcpro gcpro1;
|
|
3014 GCPRO1 (suffix);
|
|
3015 result = call1 (result, Qnil);
|
|
3016 UNGCPRO;
|
|
3017 }
|
|
3018
|
|
3019 if (KEYMAPP (result))
|
|
3020 return result;
|
|
3021
|
|
3022 if (VECTORP (result) || STRINGP (result))
|
|
3023 {
|
|
3024 Lisp_Object new_chain =
|
|
3025 key_sequence_to_event_chain (result);
|
|
3026 Lisp_Object tempev;
|
|
3027 int n, tckn;
|
|
3028
|
|
3029 /* If the first_mungeable_event of the other munger
|
|
3030 is within the events we're munging, then it will
|
|
3031 point to deallocated events afterwards, which is
|
|
3032 bad -- so make it point at the beginning of the
|
|
3033 munged events. */
|
|
3034 EVENT_CHAIN_LOOP (tempev, suffix)
|
|
3035 {
|
|
3036 if (EQ (tempev, builder->munge_me[1 - munge].
|
|
3037 first_mungeable_event))
|
|
3038 {
|
|
3039 builder->munge_me[1 - munge].first_mungeable_event =
|
|
3040 new_chain;
|
|
3041 break;
|
|
3042 }
|
|
3043 }
|
|
3044
|
|
3045 n = event_chain_count (suffix);
|
|
3046 command_builder_replace_suffix (builder, suffix, new_chain);
|
|
3047 builder->munge_me[munge].first_mungeable_event = Qnil;
|
|
3048 /* Now hork this-command-keys as well. */
|
|
3049
|
|
3050 /* We just assume that the events we just replaced
|
|
3051 are sitting in copied form at the end of this-command-keys.
|
|
3052 If the user did weird things with `dispatch-event'
|
|
3053 this may not be the case, but at least we make
|
|
3054 sure we won't crash. */
|
|
3055 new_chain = copy_event_chain (new_chain);
|
|
3056 tckn = event_chain_count (Vthis_command_keys);
|
|
3057 if (tckn >= n)
|
|
3058 {
|
|
3059 this_command_keys_replace_suffix
|
|
3060 (event_chain_nth (Vthis_command_keys, tckn - n),
|
|
3061 new_chain);
|
|
3062 }
|
|
3063
|
|
3064 result = command_builder_find_leaf_1 (builder);
|
|
3065 return result;
|
|
3066 }
|
|
3067
|
|
3068 if (munge == MUNGE_ME_FUNCTION_KEY)
|
|
3069 signal_simple_error ("Invalid binding in function-key-map",
|
|
3070 result);
|
|
3071 else
|
|
3072 signal_simple_error ("Invalid binding in key-translation-map",
|
|
3073 result);
|
|
3074 }
|
|
3075 }
|
|
3076
|
|
3077 return Qnil;
|
|
3078 }
|
|
3079
|
|
3080 /* Compare the current state of the command builder against the local and
|
|
3081 global keymaps, and return the binding. If there is no match, try again,
|
2
|
3082 case-insensitively. The return value will be one of:
|
0
|
3083 -- nil (there is no binding)
|
|
3084 -- a keymap (part of a command has been specified)
|
|
3085 -- a command (anything that satisfies `commandp'; this includes
|
|
3086 some symbols, lists, subrs, strings, vectors, and
|
|
3087 compiled-function objects)
|
|
3088 */
|
|
3089 static Lisp_Object
|
|
3090 command_builder_find_leaf (struct command_builder *builder,
|
|
3091 int allow_misc_user_events_p)
|
|
3092 {
|
|
3093 /* This function can GC */
|
|
3094 Lisp_Object result;
|
|
3095 Lisp_Object evee = builder->current_events;
|
|
3096
|
|
3097 if (allow_misc_user_events_p
|
|
3098 && (NILP (XEVENT_NEXT (evee)))
|
|
3099 && (XEVENT_TYPE (evee) == misc_user_event))
|
|
3100 {
|
2
|
3101 Lisp_Object fn = XEVENT (evee)->event.eval.function;
|
0
|
3102 Lisp_Object arg = XEVENT (evee)->event.eval.object;
|
|
3103 return (list2 (fn, arg));
|
|
3104 }
|
|
3105
|
|
3106 else if (XEVENT_TYPE (evee) == misc_user_event)
|
|
3107 return Qnil;
|
|
3108
|
|
3109 result = command_builder_find_leaf_1 (builder);
|
|
3110
|
|
3111 /* Check to see if we have a potential function-key-map match. */
|
|
3112 if (NILP (result))
|
|
3113 {
|
|
3114 result = munge_keymap_translate (builder, MUNGE_ME_FUNCTION_KEY, 0);
|
|
3115 regenerate_echo_keys_from_this_command_keys (builder);
|
|
3116 }
|
|
3117 /* Check to see if we have a potential key-translation-map match. */
|
|
3118 {
|
|
3119 Lisp_Object key_translate_result =
|
|
3120 munge_keymap_translate (builder, MUNGE_ME_KEY_TRANSLATION,
|
|
3121 !NILP (result));
|
|
3122 if (!NILP (key_translate_result))
|
|
3123 {
|
|
3124 result = key_translate_result;
|
|
3125 regenerate_echo_keys_from_this_command_keys (builder);
|
|
3126 }
|
|
3127 }
|
|
3128
|
|
3129 if (!NILP (result))
|
|
3130 return result;
|
|
3131
|
|
3132 /* If key-sequence wasn't bound, we'll try some fallbacks. */
|
|
3133
|
|
3134 /* If we didn't find a binding, and the last event in the sequence is
|
|
3135 a shifted character, then try again with the lowercase version. */
|
|
3136
|
2
|
3137 if (XEVENT_TYPE (builder->most_current_event) == key_press_event
|
|
3138 && !NILP (Vretry_undefined_key_binding_unshifted))
|
|
3139 {
|
|
3140 Lisp_Object terminal = builder->most_current_event;
|
|
3141 struct key_data* key = & XEVENT (terminal)->event.key;
|
|
3142 Emchar c;
|
|
3143 if ((key->modifiers & MOD_SHIFT)
|
|
3144 || (CHAR_OR_CHAR_INTP (key->keysym)
|
|
3145 && ((c = XCHAR_OR_CHAR_INT (key->keysym)), c >= 'A' && c <= 'Z')))
|
|
3146 {
|
|
3147 struct Lisp_Event terminal_copy;
|
|
3148 terminal_copy = *XEVENT (terminal);
|
|
3149
|
|
3150 if (key->modifiers & MOD_SHIFT)
|
|
3151 key->modifiers &= (~ MOD_SHIFT);
|
|
3152 else
|
|
3153 key->keysym = make_char (c + 'a' - 'A');
|
|
3154
|
|
3155 result = command_builder_find_leaf (builder, allow_misc_user_events_p);
|
|
3156 if (!NILP (result))
|
|
3157 return (result);
|
|
3158 /* If there was no match with the lower-case version either,
|
|
3159 then put back the upper-case event for the error
|
|
3160 message. But make sure that function-key-map didn't
|
|
3161 change things out from under us. */
|
|
3162 if (EQ (terminal, builder->most_current_event))
|
|
3163 *XEVENT (terminal) = terminal_copy;
|
|
3164 }
|
|
3165 }
|
|
3166
|
|
3167 /* help-char is `auto-bound' in every keymap */
|
0
|
3168 if (!NILP (Vprefix_help_command) &&
|
|
3169 event_matches_key_specifier_p (XEVENT (builder->most_current_event),
|
|
3170 Vhelp_char))
|
|
3171 return (Vprefix_help_command);
|
|
3172
|
70
|
3173 #ifdef HAVE_XIM
|
|
3174 /* If keysym is a non-ASCII char, bind it to self-insert-char by default. */
|
|
3175 if (XEVENT_TYPE (builder->most_current_event) == key_press_event
|
|
3176 && !NILP (Vcomposed_character_default_binding))
|
|
3177 {
|
|
3178 Lisp_Object keysym = XEVENT (builder->most_current_event)->event.key.keysym;
|
|
3179 if (CHARP (keysym) && !CHAR_ASCII_P (XCHAR (keysym)))
|
|
3180 return Vcomposed_character_default_binding;
|
|
3181 }
|
|
3182 #endif /* HAVE_XIM */
|
|
3183
|
0
|
3184 /* If we read extra events attempting to match a function key but end
|
|
3185 up failing, then we release those events back to the command loop
|
|
3186 and fail on the original lookup. The released events will then be
|
|
3187 reprocessed in the context of the first part having failed. */
|
|
3188 if (!NILP (builder->last_non_munged_event))
|
|
3189 {
|
|
3190 Lisp_Object event0 = builder->last_non_munged_event;
|
|
3191
|
|
3192 /* Put the commands back on the event queue. */
|
|
3193 enqueue_event_chain (XEVENT_NEXT (event0),
|
|
3194 &command_event_queue,
|
|
3195 &command_event_queue_tail);
|
|
3196
|
|
3197 /* Then remove them from the command builder. */
|
|
3198 XSET_EVENT_NEXT (event0, Qnil);
|
|
3199 builder->most_current_event = event0;
|
|
3200 builder->last_non_munged_event = Qnil;
|
|
3201 }
|
|
3202
|
|
3203 return Qnil;
|
|
3204 }
|
|
3205
|
|
3206
|
|
3207 /* Every time a command-event (a key, button, or menu selection) is read by
|
|
3208 Fnext_event(), it is stored in the recent_keys_ring, in Vlast_input_event,
|
|
3209 and in Vthis_command_keys. (Eval-events are not stored there.)
|
|
3210
|
|
3211 Every time a command is invoked, Vlast_command_event is set to the last
|
|
3212 event in the sequence.
|
|
3213
|
|
3214 This means that Vthis_command_keys is really about "input read since the
|
|
3215 last command was executed" rather than about "what keys invoked this
|
|
3216 command." This is a little counterintuitive, but that's the way it
|
|
3217 has always worked.
|
|
3218
|
|
3219 As an extra kink, the function read-key-sequence resets/updates the
|
|
3220 last-command-event and this-command-keys. It doesn't append to the
|
|
3221 command-keys as read-char does. Such are the pitfalls of having to
|
|
3222 maintain compatibility with a program for which the only specification
|
|
3223 is the code itself.
|
|
3224
|
|
3225 (We could implement recent_keys_ring and Vthis_command_keys as the same
|
|
3226 data structure.)
|
|
3227 */
|
|
3228
|
|
3229 #define RECENT_KEYS_SIZE 100
|
|
3230 Lisp_Object recent_keys_ring;
|
|
3231 int recent_keys_ring_index;
|
|
3232
|
20
|
3233 DEFUN ("recent-keys", Frecent_keys, 0, 0, 0, /*
|
0
|
3234 Return vector of last 100 or so keyboard or mouse button events read.
|
|
3235 This copies the event objects into a new vector; it is safe to keep and
|
|
3236 modify them.
|
20
|
3237 */
|
|
3238 ())
|
0
|
3239 {
|
|
3240 struct gcpro gcpro1;
|
|
3241 Lisp_Object val = Qnil;
|
|
3242 int size = XVECTOR (recent_keys_ring)->size;
|
|
3243 int start, nkeys, i, j;
|
|
3244 GCPRO1 (val);
|
|
3245
|
|
3246 if (NILP (vector_data (XVECTOR (recent_keys_ring))[recent_keys_ring_index]))
|
|
3247 /* This means the vector has not yet wrapped */
|
|
3248 {
|
|
3249 nkeys = recent_keys_ring_index;
|
|
3250 start = 0;
|
|
3251 }
|
|
3252 else
|
|
3253 {
|
|
3254 nkeys = size;
|
|
3255 start = ((recent_keys_ring_index == size) ? 0 : recent_keys_ring_index);
|
|
3256 }
|
|
3257
|
|
3258 val = make_vector (nkeys, Qnil);
|
|
3259
|
|
3260 for (i = 0, j = start; i < nkeys; i++)
|
|
3261 {
|
|
3262 Lisp_Object e = vector_data (XVECTOR (recent_keys_ring))[j];
|
|
3263
|
|
3264 if (NILP (e))
|
|
3265 abort ();
|
|
3266 vector_data (XVECTOR (val))[i] = Fcopy_event (e, Qnil);
|
|
3267 if (++j >= size)
|
|
3268 j = 0;
|
|
3269 }
|
|
3270 UNGCPRO;
|
|
3271 return (val);
|
|
3272 }
|
|
3273
|
|
3274 /* Vthis_command_keys having value Qnil means that the next time
|
|
3275 push_this_command_keys is called, it should start over.
|
2
|
3276 The times at which the command-keys are reset
|
0
|
3277 (instead of merely being augmented) are pretty conterintuitive.
|
|
3278 (More specifically:
|
|
3279
|
|
3280 -- We do not reset this-command-keys when we finish reading a
|
|
3281 command. This is because some commands (e.g. C-u) act
|
|
3282 like command prefixes; they signal this by setting prefix-arg
|
|
3283 to non-nil.
|
|
3284 -- Therefore, we reset this-command-keys when we finish
|
70
|
3285 executing a comand, unless prefix-arg is set.
|
0
|
3286 -- However, if we ever do a non-local exit out of a command
|
|
3287 loop (e.g. an error in a command), we need to reset
|
|
3288 this-command-keys. We do this by calling reset_this_command_keys()
|
|
3289 from cmdloop.c, whenever an error causes an invocation of the
|
|
3290 default error handler, and whenever there's a throw to top-level.)
|
|
3291 */
|
|
3292
|
|
3293 void
|
|
3294 reset_this_command_keys (Lisp_Object console, int clear_echo_area_p)
|
|
3295 {
|
|
3296 struct command_builder *command_builder =
|
|
3297 XCOMMAND_BUILDER (XCONSOLE (console)->command_builder);
|
|
3298
|
|
3299 reset_key_echo (command_builder, clear_echo_area_p);
|
|
3300
|
|
3301 deallocate_event_chain (Vthis_command_keys);
|
|
3302 Vthis_command_keys = Qnil;
|
|
3303 Vthis_command_keys_tail = Qnil;
|
|
3304
|
|
3305 reset_current_events (command_builder);
|
|
3306 }
|
|
3307
|
|
3308 static void
|
|
3309 push_this_command_keys (Lisp_Object event)
|
|
3310 {
|
|
3311 Lisp_Object new = Fmake_event ();
|
|
3312
|
|
3313 Fcopy_event (event, new);
|
|
3314 enqueue_event (new, &Vthis_command_keys, &Vthis_command_keys_tail);
|
|
3315 }
|
|
3316
|
|
3317 /* The following two functions are used in call-interactively,
|
|
3318 for the @ and e specifications. We used to just use
|
70
|
3319 `current-mouse-event' (i.e. the last mouse event in this-comand-keys),
|
0
|
3320 but FSF does it more generally so we follow their lead. */
|
|
3321
|
|
3322 Lisp_Object
|
|
3323 extract_this_command_keys_nth_mouse_event (int n)
|
|
3324 {
|
|
3325 Lisp_Object event;
|
|
3326
|
|
3327 EVENT_CHAIN_LOOP (event, Vthis_command_keys)
|
|
3328 {
|
|
3329 if (EVENTP (event)
|
|
3330 && (XEVENT_TYPE (event) == button_press_event
|
|
3331 || XEVENT_TYPE (event) == button_release_event
|
|
3332 || XEVENT_TYPE (event) == misc_user_event))
|
|
3333 {
|
|
3334 if (!n)
|
|
3335 {
|
|
3336 /* must copy to avoid an abort() in next_event_internal() */
|
|
3337 if (!NILP (XEVENT_NEXT (event)))
|
|
3338 return Fcopy_event (event, Qnil);
|
|
3339 else
|
|
3340 return event;
|
|
3341 }
|
|
3342 n--;
|
|
3343 }
|
|
3344 }
|
|
3345
|
|
3346 return Qnil;
|
|
3347 }
|
|
3348
|
|
3349 Lisp_Object
|
|
3350 extract_vector_nth_mouse_event (Lisp_Object vector, int n)
|
|
3351 {
|
|
3352 int i;
|
|
3353
|
|
3354 for (i = 0; i < vector_length (XVECTOR (vector)); i++)
|
|
3355 {
|
|
3356 Lisp_Object event = vector_data (XVECTOR (vector))[i];
|
|
3357 if (EVENTP (event)
|
|
3358 && (XEVENT_TYPE (event) == button_press_event
|
|
3359 || XEVENT_TYPE (event) == button_release_event
|
|
3360 || XEVENT_TYPE (event) == misc_user_event))
|
|
3361 {
|
|
3362 if (!n)
|
|
3363 return event;
|
|
3364 n--;
|
|
3365 }
|
|
3366 }
|
|
3367
|
|
3368 return Qnil;
|
|
3369 }
|
|
3370
|
|
3371 static void
|
|
3372 push_recent_keys (Lisp_Object event)
|
|
3373 {
|
|
3374 Lisp_Object e
|
|
3375 = vector_data (XVECTOR (recent_keys_ring)) [recent_keys_ring_index];
|
|
3376
|
|
3377 if (NILP (e))
|
|
3378 {
|
|
3379 e = Fmake_event ();
|
|
3380 vector_data (XVECTOR (recent_keys_ring)) [recent_keys_ring_index] = e;
|
|
3381 }
|
|
3382 Fcopy_event (event, e);
|
|
3383 if (++recent_keys_ring_index == XVECTOR (recent_keys_ring)->size)
|
|
3384 recent_keys_ring_index = 0;
|
|
3385 }
|
|
3386
|
|
3387
|
|
3388 static Lisp_Object
|
|
3389 current_events_into_vector (struct command_builder *command_builder)
|
|
3390 {
|
|
3391 Lisp_Object vector;
|
|
3392 Lisp_Object event;
|
|
3393 int n = event_chain_count (command_builder->current_events);
|
|
3394
|
|
3395 /* Copy the vector and the events in it. */
|
|
3396 /* No need to copy the events, since they're already copies, and
|
|
3397 nobody other than the command-builder has pointers to them */
|
|
3398 vector = make_vector (n, Qnil);
|
|
3399 n = 0;
|
|
3400 EVENT_CHAIN_LOOP (event, command_builder->current_events)
|
|
3401 vector_data (XVECTOR (vector))[n++] = event;
|
|
3402 reset_command_builder_event_chain (command_builder);
|
|
3403 return (vector);
|
|
3404 }
|
|
3405
|
|
3406
|
|
3407 /*
|
|
3408 Given the current state of the command builder and a new command event
|
|
3409 that has just been dispatched:
|
|
3410
|
|
3411 -- add the event to the event chain forming the current command
|
|
3412 (doing meta-translation as necessary)
|
2
|
3413 -- return the binding of this event chain; this will be one of:
|
0
|
3414 -- nil (there is no binding)
|
|
3415 -- a keymap (part of a command has been specified)
|
|
3416 -- a command (anything that satisfies `commandp'; this includes
|
|
3417 some symbols, lists, subrs, strings, vectors, and
|
|
3418 compiled-function objects)
|
|
3419 */
|
|
3420 static Lisp_Object
|
|
3421 lookup_command_event (struct command_builder *command_builder,
|
|
3422 Lisp_Object event, int allow_misc_user_events_p)
|
|
3423 {
|
|
3424 /* This function can GC */
|
|
3425 struct frame *f = selected_frame ();
|
|
3426 /* Clear output from previous command execution */
|
|
3427 if (!EQ (Qcommand, echo_area_status (f))
|
|
3428 /* but don't let mouse-up clear what mouse-down just printed */
|
|
3429 && (XEVENT (event)->event_type != button_release_event))
|
|
3430 clear_echo_area (f, Qnil, 0);
|
|
3431
|
|
3432 /* Add the given event to the command builder.
|
|
3433 Extra hack: this also updates the recent_keys_ring and Vthis_command_keys
|
|
3434 vectors to translate "ESC x" to "M-x" (for any "x" of course).
|
|
3435 */
|
|
3436 {
|
|
3437 Lisp_Object recent = command_builder->most_current_event;
|
|
3438
|
|
3439 if (EVENTP (recent)
|
|
3440 && event_matches_key_specifier_p (XEVENT (recent), Vmeta_prefix_char))
|
|
3441 {
|
|
3442 struct Lisp_Event *e;
|
|
3443 /* When we see a sequence like "ESC x", pretend we really saw "M-x".
|
|
3444 DoubleThink the recent-keys and this-command-keys as well. */
|
|
3445
|
|
3446 /* Modify the previous most-recently-pushed event on the command
|
|
3447 builder to be a copy of this one with the meta-bit set instead of
|
|
3448 pushing a new event.
|
|
3449 */
|
|
3450 Fcopy_event (event, recent);
|
|
3451 e = XEVENT (recent);
|
|
3452 if (e->event_type == key_press_event)
|
|
3453 e->event.key.modifiers |= MOD_META;
|
|
3454 else if (e->event_type == button_press_event
|
|
3455 || e->event_type == button_release_event)
|
|
3456 e->event.button.modifiers |= MOD_META;
|
|
3457 else
|
|
3458 abort ();
|
|
3459
|
|
3460 {
|
|
3461 int tckn = event_chain_count (Vthis_command_keys);
|
|
3462 if (tckn >= 2)
|
|
3463 /* ??? very strange if it's < 2. */
|
|
3464 this_command_keys_replace_suffix
|
|
3465 (event_chain_nth (Vthis_command_keys, tckn - 2),
|
|
3466 Fcopy_event (recent, Qnil));
|
|
3467 }
|
|
3468
|
|
3469 regenerate_echo_keys_from_this_command_keys (command_builder);
|
|
3470 }
|
|
3471 else
|
|
3472 {
|
|
3473 event = Fcopy_event (event, Fmake_event ());
|
|
3474
|
|
3475 command_builder_append_event (command_builder, event);
|
|
3476 }
|
|
3477 }
|
|
3478
|
|
3479 {
|
|
3480 Lisp_Object leaf = command_builder_find_leaf (command_builder,
|
|
3481 allow_misc_user_events_p);
|
|
3482 struct gcpro gcpro1;
|
|
3483 GCPRO1 (leaf);
|
|
3484
|
|
3485 if (KEYMAPP (leaf))
|
|
3486 {
|
|
3487 Lisp_Object prompt = Fkeymap_prompt (leaf, Qt);
|
|
3488 if (STRINGP (prompt))
|
|
3489 {
|
|
3490 /* Append keymap prompt to key echo buffer */
|
|
3491 int buf_index = command_builder->echo_buf_index;
|
14
|
3492 Bytecount len = XSTRING_LENGTH (prompt);
|
0
|
3493
|
|
3494 if (len + buf_index + 1 <= command_builder->echo_buf_length)
|
|
3495 {
|
|
3496 Bufbyte *echo = command_builder->echo_buf + buf_index;
|
14
|
3497 memcpy (echo, XSTRING_DATA (prompt), len);
|
0
|
3498 echo[len] = 0;
|
|
3499 }
|
|
3500 maybe_echo_keys (command_builder, 1);
|
|
3501 }
|
|
3502 else
|
|
3503 maybe_echo_keys (command_builder, 0);
|
|
3504 }
|
|
3505 else if (!NILP (leaf))
|
|
3506 {
|
|
3507 if (EQ (Qcommand, echo_area_status (f))
|
|
3508 && command_builder->echo_buf_index > 0)
|
|
3509 {
|
|
3510 /* If we had been echoing keys, echo the last one (without
|
|
3511 the trailing dash) and redisplay before executing the
|
|
3512 command. */
|
|
3513 command_builder->echo_buf[command_builder->echo_buf_index] = 0;
|
|
3514 maybe_echo_keys (command_builder, 1);
|
|
3515 Fsit_for (Qzero, Qt);
|
|
3516 }
|
|
3517 }
|
|
3518 RETURN_UNGCPRO (leaf);
|
|
3519 }
|
|
3520 }
|
|
3521
|
|
3522 static void
|
|
3523 execute_command_event (struct command_builder *command_builder,
|
|
3524 Lisp_Object event)
|
|
3525 {
|
|
3526 /* This function can GC */
|
|
3527 struct console *con = XCONSOLE (command_builder->console);
|
|
3528 struct gcpro gcpro1;
|
|
3529
|
|
3530 GCPRO1 (event); /* event may be freshly created */
|
|
3531 reset_current_events (command_builder);
|
|
3532
|
|
3533 if (XEVENT (event)->event_type == key_press_event)
|
|
3534 Vcurrent_mouse_event = Qnil;
|
|
3535 else if (XEVENT (event)->event_type == button_press_event
|
|
3536 || XEVENT (event)->event_type == button_release_event
|
|
3537 || XEVENT (event)->event_type == misc_user_event)
|
|
3538 Vcurrent_mouse_event = Fcopy_event (event, Qnil);
|
|
3539
|
|
3540 /* Store the last-command-event. The semantics of this is that it is
|
|
3541 the last event most recently involved in command-lookup.
|
|
3542 */
|
|
3543 if (!EVENTP (Vlast_command_event))
|
|
3544 Vlast_command_event = Fmake_event ();
|
|
3545 if (XEVENT (Vlast_command_event)->event_type == dead_event)
|
|
3546 {
|
|
3547 Vlast_command_event = Fmake_event ();
|
|
3548 error ("Someone deallocated the last-command-event!");
|
|
3549 }
|
|
3550
|
|
3551 if (! EQ (event, Vlast_command_event))
|
|
3552 Fcopy_event (event, Vlast_command_event);
|
|
3553
|
|
3554 /* Note that last-command-char will never have its high-bit set, in
|
|
3555 an effort to sidestep the ambiguity between M-x and oslash.
|
|
3556 */
|
|
3557 Vlast_command_char = Fevent_to_character (Vlast_command_event,
|
|
3558 Qnil, Qnil, Qnil);
|
|
3559
|
|
3560 /* Actually call the command, with all sorts of hair to preserve or clear
|
|
3561 the echo-area and region as appropriate and call the pre- and post-
|
|
3562 command-hooks.
|
|
3563 */
|
|
3564 {
|
|
3565 int old_kbd_macro = con->kbd_macro_end;
|
|
3566 struct window *w;
|
|
3567
|
|
3568 w = XWINDOW (Fselected_window (Qnil));
|
|
3569
|
2
|
3570 /* We're executing a new command, so the old value is irrelevant. */
|
0
|
3571 zmacs_region_stays = 0;
|
|
3572
|
|
3573 /* If the previous command tried to force a specific window-start,
|
|
3574 reset the flag in case this command moves point far away from
|
|
3575 that position. Also, reset the window's buffer's change
|
|
3576 information so that we don't trigger an incremental update. */
|
|
3577 if (w->force_start)
|
|
3578 {
|
|
3579 w->force_start = 0;
|
|
3580 buffer_reset_changes (XBUFFER (w->buffer));
|
|
3581 }
|
|
3582
|
|
3583 pre_command_hook ();
|
|
3584
|
|
3585 if (XEVENT (event)->event_type == misc_user_event)
|
|
3586 {
|
|
3587 call1 (XEVENT (event)->event.eval.function,
|
|
3588 XEVENT (event)->event.eval.object);
|
|
3589 }
|
|
3590 else
|
|
3591 {
|
|
3592 #if 0
|
|
3593 call3 (Qcommand_execute, Vthis_command, Qnil, Qnil);
|
|
3594 #else
|
|
3595 Fcommand_execute (Vthis_command, Qnil, Qnil);
|
|
3596 #endif
|
|
3597 }
|
|
3598
|
|
3599 post_command_hook ();
|
|
3600
|
|
3601 if (!NILP (con->prefix_arg))
|
|
3602 {
|
|
3603 /* Commands that set the prefix arg don't update last-command, don't
|
|
3604 reset the echoing state, and don't go into keyboard macros unless
|
|
3605 followed by another command.
|
|
3606 */
|
|
3607 maybe_echo_keys (command_builder, 0);
|
|
3608
|
|
3609 /* If we're recording a keyboard macro, and the last command
|
|
3610 executed set a prefix argument, then decrement the pointer to
|
|
3611 the "last character really in the macro" to be just before this
|
|
3612 command. This is so that the ^U in "^U ^X )" doesn't go onto
|
|
3613 the end of macro.
|
|
3614 */
|
|
3615 if (!NILP (con->defining_kbd_macro))
|
|
3616 con->kbd_macro_end = old_kbd_macro;
|
|
3617 }
|
|
3618 else
|
|
3619 {
|
|
3620 /* Start a new command next time */
|
|
3621 Vlast_command = Vthis_command;
|
|
3622 /* Emacs 18 doesn't unconditionally clear the echoed keystrokes,
|
|
3623 so we don't either */
|
|
3624 reset_this_command_keys (make_console (con), 0);
|
|
3625 }
|
|
3626 }
|
|
3627
|
|
3628 UNGCPRO;
|
|
3629 }
|
|
3630
|
|
3631 /* Run the pre command hook. */
|
|
3632
|
|
3633 static void
|
|
3634 pre_command_hook (void)
|
|
3635 {
|
|
3636 last_point_position = BUF_PT (current_buffer);
|
|
3637 XSETBUFFER (last_point_position_buffer, current_buffer);
|
|
3638 /* This function can GC */
|
|
3639 safe_run_hook_trapping_errors
|
|
3640 ("Error in `pre-command-hook' (setting hook to nil)",
|
|
3641 Qpre_command_hook, 1);
|
|
3642 }
|
|
3643
|
|
3644 /* Run the post command hook. */
|
|
3645
|
|
3646 static void
|
|
3647 post_command_hook (void)
|
|
3648 {
|
|
3649 /* This function can GC */
|
|
3650 /* Turn off region highlighting unless this command requested that
|
|
3651 it be left on, or we're in the minibuffer. We don't turn it off
|
|
3652 when we're in the minibuffer so that things like M-x write-region
|
|
3653 still work!
|
|
3654
|
|
3655 This could be done via a function on the post-command-hook, but
|
|
3656 we don't want the user to accidentally remove it.
|
|
3657 */
|
2
|
3658
|
|
3659 Lisp_Object win = Fselected_window (Qnil);
|
|
3660
|
|
3661 #if 0
|
|
3662 /* If the last command deleted the frame, `win' might be nil.
|
|
3663 It seems safest to do nothing in this case. */
|
|
3664 /* ### This doesn't really fix the problem,
|
|
3665 if delete-frame is called by some hook */
|
|
3666 if (NILP (win))
|
|
3667 return;
|
|
3668 #endif
|
|
3669
|
0
|
3670 if (! zmacs_region_stays
|
2
|
3671 && (!MINI_WINDOW_P (XWINDOW (win))
|
|
3672 || EQ (zmacs_region_buffer (), WINDOW_BUFFER (XWINDOW (win)))))
|
0
|
3673 zmacs_deactivate_region ();
|
|
3674 else
|
|
3675 zmacs_update_region ();
|
|
3676
|
|
3677 safe_run_hook_trapping_errors
|
|
3678 ("Error in `post-command-hook' (setting hook to nil)",
|
|
3679 Qpost_command_hook, 1);
|
|
3680
|
|
3681 #ifdef DEFERRED_ACTION_CRAP
|
|
3682 if (!NILP (Vdeferred_action_list))
|
|
3683 call0 (Vdeferred_action_function);
|
|
3684 #endif
|
|
3685
|
|
3686 #ifdef ILL_CONCEIVED_HOOK
|
|
3687 if (NILP (Vunread_command_events)
|
|
3688 && NILP (Vexecuting_macro)
|
|
3689 && !NILP (Vpost_command_idle_hook)
|
|
3690 && !NILP (Fsit_for (make_float ((double) post_command_idle_delay
|
|
3691 / 1000000), Qnil)))
|
|
3692 safe_run_hook_trapping_errors
|
|
3693 ("Error in `post-command-idle-hook' (setting hook to nil)",
|
|
3694 Qpost_command_idle_hook, 1);
|
|
3695 #endif
|
|
3696
|
|
3697 #if 0 /* FSFmacs */
|
|
3698 if (!NILP (current_buffer->mark_active))
|
|
3699 {
|
|
3700 if (!NILP (Vdeactivate_mark) && !NILP (Vtransient_mark_mode))
|
|
3701 {
|
|
3702 current_buffer->mark_active = Qnil;
|
|
3703 run_hook (intern ("deactivate-mark-hook"));
|
|
3704 }
|
|
3705 else if (current_buffer != prev_buffer ||
|
|
3706 BUF_MODIFF (current_buffer) != prev_modiff)
|
|
3707 run_hook (intern ("activate-mark-hook"));
|
|
3708 }
|
|
3709 #endif /* FSFmacs */
|
|
3710
|
|
3711 /* #### Kludge!!! This is necessary to make sure that things
|
|
3712 are properly positioned even if post-command-hook moves point.
|
|
3713 #### There should be a cleaner way of handling this. */
|
|
3714 call0 (Qauto_show_make_point_visible);
|
|
3715 }
|
|
3716
|
|
3717
|
20
|
3718 DEFUN ("dispatch-event", Fdispatch_event, 1, 1, 0, /*
|
0
|
3719 Given an event object as returned by `next-event', execute it.
|
|
3720
|
|
3721 Key-press, button-press, and button-release events get accumulated
|
|
3722 until a complete key sequence (see `read-key-sequence') is reached,
|
|
3723 at which point the sequence is looked up in the current keymaps and
|
|
3724 acted upon.
|
|
3725
|
|
3726 Mouse motion events cause the low-level handling function stored in
|
|
3727 `mouse-motion-handler' to be called. (There are very few circumstances
|
|
3728 under which you should change this handler. Use `mode-motion-hook'
|
|
3729 instead.)
|
|
3730
|
|
3731 Menu, timeout, and eval events cause the associated function or handler
|
|
3732 to be called.
|
|
3733
|
|
3734 Process events cause the subprocess's output to be read and acted upon
|
|
3735 appropriately (see `start-process').
|
|
3736
|
|
3737 Magic events are handled as necessary.
|
20
|
3738 */
|
|
3739 (event))
|
0
|
3740 {
|
|
3741 /* This function can GC */
|
|
3742 struct command_builder *command_builder;
|
|
3743 struct Lisp_Event *ev;
|
|
3744 Lisp_Object console;
|
|
3745 Lisp_Object channel;
|
|
3746
|
|
3747 CHECK_LIVE_EVENT (event);
|
|
3748 ev = XEVENT (event);
|
|
3749
|
|
3750 /* events on dead channels get silently eaten */
|
|
3751 channel = EVENT_CHANNEL (ev);
|
|
3752 if (object_dead_p (channel))
|
|
3753 return Qnil;
|
|
3754
|
|
3755 /* Some events don't have channels (e.g. eval events). */
|
|
3756 console = CDFW_CONSOLE (channel);
|
|
3757 if (NILP (console))
|
|
3758 console = Vselected_console;
|
|
3759 else if (!EQ (console, Vselected_console))
|
|
3760 Fselect_console (console);
|
|
3761
|
|
3762 command_builder = XCOMMAND_BUILDER (XCONSOLE (console)->command_builder);
|
|
3763 switch (XEVENT (event)->event_type)
|
|
3764 {
|
|
3765 case button_press_event:
|
|
3766 case button_release_event:
|
|
3767 case key_press_event:
|
|
3768 {
|
|
3769 Lisp_Object leaf;
|
|
3770
|
|
3771 leaf = lookup_command_event (command_builder, event, 1);
|
|
3772 if (KEYMAPP (leaf))
|
|
3773 /* Incomplete key sequence */
|
|
3774 break;
|
|
3775 if (NILP (leaf))
|
|
3776 {
|
|
3777 /* At this point, we know that the sequence is not bound to a
|
|
3778 command. Normally, we beep and print a message informing the
|
|
3779 user of this. But we do not beep or print a message when:
|
|
3780
|
|
3781 o the last event in this sequence is a mouse-up event; or
|
|
3782 o the last event in this sequence is a mouse-down event and
|
|
3783 there is a binding for the mouse-up version.
|
|
3784
|
|
3785 That is, if the sequence ``C-x button1'' is typed, and is not
|
|
3786 bound to a command, but the sequence ``C-x button1up'' is bound
|
|
3787 to a command, we do not complain about the ``C-x button1''
|
|
3788 sequence. If neither ``C-x button1'' nor ``C-x button1up'' is
|
|
3789 bound to a command, then we complain about the ``C-x button1''
|
|
3790 sequence, but later will *not* complain about the
|
|
3791 ``C-x button1up'' sequence, which would be redundant.
|
|
3792
|
|
3793 This is pretty hairy, but I think it's the most intuitive
|
|
3794 behavior.
|
|
3795 */
|
|
3796 Lisp_Object terminal = command_builder->most_current_event;
|
|
3797
|
|
3798 if (XEVENT_TYPE (terminal) == button_press_event)
|
|
3799 {
|
|
3800 int no_bitching;
|
|
3801 /* Temporarily pretend the last event was an "up" instead of a
|
|
3802 "down", and look up its binding. */
|
|
3803 XEVENT_TYPE (terminal) = button_release_event;
|
|
3804 /* If the "up" version is bound, don't complain. */
|
|
3805 no_bitching
|
|
3806 = !NILP (command_builder_find_leaf
|
|
3807 (command_builder, 0));
|
|
3808 /* Undo the temporary changes we just made. */
|
|
3809 XEVENT_TYPE (terminal) = button_press_event;
|
|
3810 if (no_bitching)
|
|
3811 {
|
|
3812 /* Pretend this press was not seen (treat as a prefix) */
|
|
3813 if (EQ (command_builder->current_events, terminal))
|
|
3814 {
|
|
3815 reset_current_events (command_builder);
|
|
3816 }
|
|
3817 else
|
|
3818 {
|
|
3819 Lisp_Object eve;
|
|
3820
|
|
3821 EVENT_CHAIN_LOOP (eve, command_builder->current_events)
|
|
3822 if (EQ (XEVENT_NEXT (eve), terminal))
|
|
3823 break;
|
|
3824
|
|
3825 Fdeallocate_event (command_builder->
|
|
3826 most_current_event);
|
|
3827 XSET_EVENT_NEXT (eve, Qnil);
|
|
3828 command_builder->most_current_event = eve;
|
|
3829 }
|
|
3830 maybe_echo_keys (command_builder, 1);
|
|
3831 break;
|
|
3832 }
|
|
3833 }
|
|
3834
|
|
3835 /* Complain that the typed sequence is not defined, if this is the
|
|
3836 kind of sequence that warrants a complaint.
|
|
3837 */
|
|
3838 XCONSOLE (console)->defining_kbd_macro = Qnil;
|
|
3839 XCONSOLE (console)->prefix_arg = Qnil;
|
|
3840 /* Don't complain about undefined button-release events */
|
|
3841 if (XEVENT_TYPE (terminal) != button_release_event)
|
|
3842 {
|
|
3843 Lisp_Object keys =
|
|
3844 current_events_into_vector (command_builder);
|
|
3845 struct gcpro gcpro1;
|
|
3846
|
|
3847 /* Run the pre-command-hook before barfing about an undefined
|
|
3848 key. */
|
|
3849 Vthis_command = Qnil;
|
|
3850 GCPRO1 (keys);
|
|
3851 pre_command_hook ();
|
|
3852 UNGCPRO;
|
|
3853 /* The post-command-hook doesn't run. */
|
|
3854 Fsignal (Qundefined_keystroke_sequence, list1 (keys));
|
|
3855 }
|
|
3856 /* Reset the command builder for reading the next sequence. */
|
|
3857 reset_this_command_keys (console, 1);
|
|
3858 }
|
2
|
3859 else /* key sequence is bound to a command */
|
0
|
3860 {
|
|
3861 Vthis_command = leaf;
|
|
3862 /* Don't push an undo boundary if the command set the prefix arg,
|
|
3863 or if we are executing a keyboard macro, or if in the
|
|
3864 minibuffer. If the command we are about to execute is
|
|
3865 self-insert, it's tricky: up to 20 consecutive self-inserts may
|
|
3866 be done without an undo boundary. This counter is reset as
|
|
3867 soon as a command other than self-insert-command is executed.
|
|
3868 */
|
|
3869 if (! EQ (leaf, Qself_insert_command))
|
|
3870 command_builder->self_insert_countdown = 0;
|
|
3871 if (NILP (XCONSOLE (console)->prefix_arg)
|
|
3872 && NILP (Vexecuting_macro)
|
|
3873 #if 0
|
|
3874 /* This was done in the days when there was no undo
|
|
3875 in the minibuffer. If we don't disable this code,
|
|
3876 then each instance of "undo" undoes everything in
|
|
3877 the minibuffer. */
|
|
3878 && !EQ (minibuf_window, Fselected_window (Qnil))
|
|
3879 #endif
|
|
3880 && command_builder->self_insert_countdown == 0)
|
|
3881 Fundo_boundary ();
|
|
3882
|
|
3883 if (EQ (leaf, Qself_insert_command))
|
|
3884 {
|
|
3885 if (--command_builder->self_insert_countdown < 0)
|
|
3886 command_builder->self_insert_countdown = 20;
|
|
3887 }
|
2
|
3888 execute_command_event
|
|
3889 (command_builder,
|
|
3890 !NILP (Fequal (event, command_builder-> most_current_event))
|
|
3891 ? event
|
|
3892 /* Use the translated event that was most recently seen.
|
|
3893 This way, last-command-event becomes f1 instead of
|
|
3894 the P from ESC O P. But we must copy it, else we'll
|
|
3895 lose when the command-builder events are deallocated. */
|
|
3896 : Fcopy_event (command_builder-> most_current_event, Qnil));
|
0
|
3897 }
|
|
3898 break;
|
|
3899 }
|
|
3900 case misc_user_event:
|
|
3901 {
|
|
3902 /* Jamie said:
|
|
3903
|
|
3904 We could just always use the menu item entry, whatever it is, but
|
|
3905 this might break some Lisp code that expects `this-command' to
|
|
3906 always contain a symbol. So only store it if this is a simple
|
|
3907 `call-interactively' sort of menu item.
|
|
3908
|
|
3909 But this is bogus. `this-command' could be a string or vector
|
|
3910 anyway (for keyboard macros). There's even one instance
|
|
3911 (in pending-del.el) of `this-command' getting set to a cons
|
|
3912 (a lambda expression). So in the `eval' case I'll just
|
|
3913 convert it into a lambda expression.
|
|
3914 */
|
|
3915 if (EQ (XEVENT (event)->event.eval.function, Qcall_interactively)
|
|
3916 && SYMBOLP (XEVENT (event)->event.eval.object))
|
|
3917 Vthis_command = XEVENT (event)->event.eval.object;
|
|
3918 else if (EQ (XEVENT (event)->event.eval.function, Qeval))
|
|
3919 Vthis_command =
|
|
3920 Fcons (Qlambda, Fcons (Qnil, XEVENT (event)->event.eval.object));
|
|
3921 else if (SYMBOLP (XEVENT (event)->event.eval.function))
|
|
3922 /* A scrollbar command or the like. */
|
|
3923 Vthis_command = XEVENT (event)->event.eval.function;
|
|
3924 else
|
|
3925 /* Huh? */
|
|
3926 Vthis_command = Qnil;
|
|
3927
|
|
3928 command_builder->self_insert_countdown = 0;
|
|
3929 if (NILP (XCONSOLE (console)->prefix_arg)
|
|
3930 && NILP (Vexecuting_macro)
|
|
3931 && !EQ (minibuf_window, Fselected_window (Qnil)))
|
|
3932 Fundo_boundary ();
|
|
3933 execute_command_event (command_builder, event);
|
|
3934 break;
|
|
3935 }
|
|
3936 default:
|
|
3937 {
|
|
3938 execute_internal_event (event);
|
|
3939 break;
|
|
3940 }
|
|
3941 }
|
|
3942 return (Qnil);
|
|
3943 }
|
|
3944
|
20
|
3945 DEFUN ("read-key-sequence", Fread_key_sequence, 1, 3, 0, /*
|
0
|
3946 Read a sequence of keystrokes or mouse clicks.
|
|
3947 Returns a vector of the event objects read. The vector and the event
|
|
3948 objects it contains are freshly created (and will not be side-effected
|
|
3949 by subsequent calls to this function).
|
|
3950
|
|
3951 The sequence read is sufficient to specify a non-prefix command starting
|
|
3952 from the current local and global keymaps. A C-g typed while in this
|
|
3953 function is treated like any other character, and `quit-flag' is not set.
|
|
3954
|
|
3955 First arg PROMPT is a prompt string. If nil, do not prompt specially.
|
98
|
3956 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echoes
|
0
|
3957 as a continuation of the previous key.
|
|
3958
|
|
3959 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not
|
|
3960 convert the last event to lower case. (Normally any upper case event
|
|
3961 is converted to lower case if the original event is undefined and the lower
|
|
3962 case equivalent is defined.) This argument is provided mostly for
|
|
3963 FSF compatibility; the equivalent effect can be achieved more generally
|
|
3964 by binding `retry-undefined-key-binding-unshifted' to nil around the
|
|
3965 call to `read-key-sequence'.
|
|
3966
|
|
3967 A C-g typed while in this function is treated like any other character,
|
|
3968 and `quit-flag' is not set.
|
|
3969
|
|
3970 If the user selects a menu item while we are prompting for a key-sequence,
|
|
3971 the returned value will be a vector of a single menu-selection event.
|
|
3972 An error will be signalled if you pass this value to `lookup-key' or a
|
|
3973 related function.
|
|
3974
|
|
3975 `read-key-sequence' checks `function-key-map' for function key
|
|
3976 sequences, where they wouldn't conflict with ordinary bindings. See
|
|
3977 `function-key-map' for more details.
|
20
|
3978 */
|
|
3979 (prompt, continue_echo, dont_downcase_last))
|
0
|
3980 {
|
|
3981 /* This function can GC */
|
|
3982 struct console *con = XCONSOLE (Vselected_console); /* #### correct?
|
|
3983 Probably not -- see
|
|
3984 comment in
|
|
3985 next-event */
|
|
3986 struct command_builder *command_builder =
|
|
3987 XCOMMAND_BUILDER (con->command_builder);
|
|
3988 Lisp_Object result;
|
|
3989 Lisp_Object event = Fmake_event ();
|
|
3990 int speccount = specpdl_depth ();
|
|
3991 struct gcpro gcpro1;
|
|
3992 GCPRO1 (event);
|
|
3993
|
|
3994 if (!NILP (prompt))
|
|
3995 CHECK_STRING (prompt);
|
|
3996 /* else prompt = Fkeymap_prompt (current_buffer->keymap); may GC */
|
|
3997 QUIT;
|
|
3998
|
|
3999 if (NILP (continue_echo))
|
|
4000 reset_this_command_keys (make_console (con), 1);
|
|
4001
|
|
4002 specbind (Qinhibit_quit, Qt);
|
|
4003
|
|
4004 if (!NILP (dont_downcase_last))
|
|
4005 specbind (Qretry_undefined_key_binding_unshifted, Qnil);
|
|
4006
|
|
4007 for (;;)
|
|
4008 {
|
|
4009 Fnext_event (event, prompt);
|
|
4010 /* restore the selected-console damage */
|
|
4011 con = event_console_or_selected (event);
|
|
4012 command_builder = XCOMMAND_BUILDER (con->command_builder);
|
|
4013 if (! command_event_p (event))
|
|
4014 execute_internal_event (event);
|
|
4015 else
|
|
4016 {
|
|
4017 if (XEVENT (event)->event_type == misc_user_event)
|
|
4018 reset_current_events (command_builder);
|
|
4019 result = lookup_command_event (command_builder, event, 1);
|
|
4020 if (!KEYMAPP (result))
|
|
4021 {
|
|
4022 result = current_events_into_vector (command_builder);
|
|
4023 reset_key_echo (command_builder, 0);
|
|
4024 break;
|
|
4025 }
|
|
4026 prompt = Qnil;
|
|
4027 }
|
|
4028 }
|
|
4029
|
|
4030 Vquit_flag = Qnil; /* In case we read a ^G; do not call check_quit() here */
|
|
4031 Fdeallocate_event (event);
|
|
4032 RETURN_UNGCPRO (unbind_to (speccount, result));
|
|
4033 }
|
|
4034
|
20
|
4035 DEFUN ("this-command-keys", Fthis_command_keys, 0, 0, 0, /*
|
0
|
4036 Return a vector of the keyboard or mouse button events that were used
|
|
4037 to invoke this command. This copies the vector and the events; it is safe
|
|
4038 to keep and modify them.
|
20
|
4039 */
|
|
4040 ())
|
0
|
4041 {
|
|
4042 Lisp_Object event;
|
|
4043 Lisp_Object result;
|
|
4044 int len;
|
|
4045
|
|
4046 if (NILP (Vthis_command_keys))
|
|
4047 return (make_vector (0, Qnil));
|
|
4048
|
|
4049 len = event_chain_count (Vthis_command_keys);
|
|
4050
|
|
4051 result = make_vector (len, Qnil);
|
|
4052 len = 0;
|
|
4053 EVENT_CHAIN_LOOP (event, Vthis_command_keys)
|
|
4054 vector_data (XVECTOR (result))[len++] = Fcopy_event (event, Qnil);
|
|
4055 return (result);
|
|
4056 }
|
|
4057
|
20
|
4058 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths, 0, 0, 0, /*
|
0
|
4059 Used for complicated reasons in `universal-argument-other-key'.
|
|
4060
|
|
4061 `universal-argument-other-key' rereads the event just typed.
|
|
4062 It then gets translated through `function-key-map'.
|
|
4063 The translated event gets included in the echo area and in
|
|
4064 the value of `this-command-keys' in addition to the raw original event.
|
|
4065 That is not right.
|
|
4066
|
|
4067 Calling this function directs the translated event to replace
|
|
4068 the original event, so that only one version of the event actually
|
|
4069 appears in the echo area and in the value of `this-command-keys.'.
|
20
|
4070 */
|
|
4071 ())
|
0
|
4072 {
|
|
4073 /* #### I don't understand this at all, so currently it does nothing.
|
|
4074 If there is ever a problem, maybe someone should investigate. */
|
|
4075 return Qnil;
|
|
4076 }
|
|
4077
|
|
4078
|
|
4079 static void
|
|
4080 dribble_out_event (Lisp_Object event)
|
|
4081 {
|
|
4082 if (NILP (Vdribble_file))
|
|
4083 return;
|
|
4084
|
|
4085 if (XEVENT (event)->event_type == key_press_event &&
|
|
4086 !XEVENT (event)->event.key.modifiers)
|
|
4087 {
|
|
4088 Lisp_Object keysym = XEVENT (event)->event.key.keysym;
|
|
4089 if (CHARP (XEVENT (event)->event.key.keysym))
|
|
4090 {
|
|
4091 Emchar ch = XCHAR (keysym);
|
|
4092 Bufbyte str[MAX_EMCHAR_LEN];
|
|
4093 Bytecount len;
|
|
4094
|
|
4095 len = set_charptr_emchar (str, ch);
|
|
4096 Lstream_write (XLSTREAM (Vdribble_file), str, len);
|
|
4097 }
|
|
4098 else if (string_char_length (XSYMBOL (keysym)->name) == 1)
|
|
4099 /* one-char key events are printed with just the key name */
|
|
4100 Fprinc (keysym, Vdribble_file);
|
|
4101 else if (EQ (keysym, Qreturn))
|
|
4102 Lstream_putc (XLSTREAM (Vdribble_file), '\n');
|
|
4103 else if (EQ (keysym, Qspace))
|
|
4104 Lstream_putc (XLSTREAM (Vdribble_file), ' ');
|
|
4105 else
|
|
4106 Fprinc (event, Vdribble_file);
|
|
4107 }
|
|
4108 else
|
|
4109 Fprinc (event, Vdribble_file);
|
|
4110 Lstream_flush (XLSTREAM (Vdribble_file));
|
|
4111 }
|
|
4112
|
20
|
4113 DEFUN ("open-dribble-file", Fopen_dribble_file, 1, 1,
|
|
4114 "FOpen dribble file: ", /*
|
0
|
4115 Start writing all keyboard characters to a dribble file called FILE.
|
|
4116 If FILE is nil, close any open dribble file.
|
20
|
4117 */
|
|
4118 (file))
|
0
|
4119 {
|
|
4120 /* This function can GC */
|
|
4121 /* XEmacs change: always close existing dribble file. */
|
|
4122 /* FSFmacs uses FILE *'s here. With lstreams, that's unnecessary. */
|
|
4123 if (!NILP (Vdribble_file))
|
|
4124 {
|
|
4125 Lstream_close (XLSTREAM (Vdribble_file));
|
|
4126 Vdribble_file = Qnil;
|
|
4127 }
|
|
4128 if (!NILP (file))
|
|
4129 {
|
|
4130 int fd;
|
|
4131
|
|
4132 file = Fexpand_file_name (file, Qnil);
|
14
|
4133 fd = creat ((char *) XSTRING_DATA (file), 0666);
|
0
|
4134 if (fd < 0)
|
|
4135 error ("Unable to create dribble file");
|
|
4136 Vdribble_file = make_filedesc_output_stream (fd, 0, 0, LSTR_CLOSING);
|
70
|
4137 #ifdef MULE
|
|
4138 Vdribble_file =
|
|
4139 make_encoding_output_stream (XLSTREAM (Vdribble_file),
|
|
4140 Fget_coding_system (Qescape_quoted));
|
|
4141 #endif
|
0
|
4142 }
|
|
4143 return Qnil;
|
|
4144 }
|
|
4145
|
|
4146
|
|
4147 /************************************************************************/
|
|
4148 /* initialization */
|
|
4149 /************************************************************************/
|
|
4150
|
|
4151 void
|
|
4152 syms_of_event_stream (void)
|
|
4153 {
|
|
4154 defsymbol (&Qdisabled, "disabled");
|
|
4155 defsymbol (&Qcommand_event_p, "command-event-p");
|
|
4156
|
|
4157 deferror (&Qundefined_keystroke_sequence, "undefined-keystroke-sequence",
|
|
4158 "Undefined keystroke sequence", Qerror);
|
|
4159 defsymbol (&Qcommand_execute, "command-execute");
|
|
4160
|
20
|
4161 DEFSUBR (Frecent_keys);
|
|
4162 DEFSUBR (Finput_pending_p);
|
|
4163 DEFSUBR (Fenqueue_eval_event);
|
|
4164 DEFSUBR (Fnext_event);
|
|
4165 DEFSUBR (Fnext_command_event);
|
|
4166 DEFSUBR (Fdiscard_input);
|
|
4167 DEFSUBR (Fsit_for);
|
|
4168 DEFSUBR (Fsleep_for);
|
|
4169 DEFSUBR (Faccept_process_output);
|
|
4170 DEFSUBR (Fadd_timeout);
|
|
4171 DEFSUBR (Fdisable_timeout);
|
|
4172 DEFSUBR (Fadd_async_timeout);
|
|
4173 DEFSUBR (Fdisable_async_timeout);
|
|
4174 DEFSUBR (Fdispatch_event);
|
|
4175 DEFSUBR (Fread_key_sequence);
|
|
4176 DEFSUBR (Fthis_command_keys);
|
|
4177 DEFSUBR (Freset_this_command_lengths);
|
|
4178 DEFSUBR (Fopen_dribble_file);
|
0
|
4179
|
|
4180 defsymbol (&Qpre_command_hook, "pre-command-hook");
|
|
4181 defsymbol (&Qpost_command_hook, "post-command-hook");
|
|
4182 defsymbol (&Qunread_command_events, "unread-command-events");
|
|
4183 defsymbol (&Qunread_command_event, "unread-command-event");
|
|
4184 defsymbol (&Qpre_idle_hook, "pre-idle-hook");
|
|
4185 #ifdef ILL_CONCEIVED_HOOK
|
|
4186 defsymbol (&Qpost_command_idle_hook, "post-command-idle-hook");
|
|
4187 #endif
|
|
4188 #ifdef DEFERRED_ACTION_CRAP
|
|
4189 defsymbol (&Qdeferred_action_function, "deferred-action-function");
|
|
4190 #endif
|
|
4191 defsymbol (&Qretry_undefined_key_binding_unshifted,
|
|
4192 "retry-undefined-key-binding-unshifted");
|
|
4193 defsymbol (&Qauto_show_make_point_visible,
|
|
4194 "auto-show-make-point-visible");
|
|
4195 }
|
|
4196
|
|
4197 void
|
|
4198 vars_of_event_stream (void)
|
|
4199 {
|
|
4200 #ifdef HAVE_X_WINDOWS
|
|
4201 vars_of_event_Xt ();
|
|
4202 #endif
|
|
4203 #if defined (DEBUG_TTY_EVENT_STREAM) || !defined (HAVE_X_WINDOWS)
|
|
4204 vars_of_event_tty ();
|
|
4205 #endif
|
|
4206 #ifdef HAVE_NEXTSTEP
|
|
4207 vars_of_event_ns ();
|
|
4208 #endif
|
|
4209
|
|
4210
|
|
4211 recent_keys_ring_index = 0;
|
|
4212 recent_keys_ring = make_vector (RECENT_KEYS_SIZE, Qnil);
|
|
4213 staticpro (&recent_keys_ring);
|
|
4214
|
|
4215 Vthis_command_keys = Qnil;
|
|
4216 staticpro (&Vthis_command_keys);
|
|
4217 Vthis_command_keys_tail = Qnil;
|
|
4218
|
|
4219 num_input_chars = 0;
|
|
4220
|
|
4221 command_event_queue = Qnil;
|
|
4222 staticpro (&command_event_queue);
|
|
4223 command_event_queue_tail = Qnil;
|
|
4224
|
|
4225 Vlast_selected_frame = Qnil;
|
|
4226 staticpro (&Vlast_selected_frame);
|
|
4227
|
|
4228 pending_timeout_list = Qnil;
|
|
4229 staticpro (&pending_timeout_list);
|
|
4230
|
|
4231 pending_async_timeout_list = Qnil;
|
|
4232 staticpro (&pending_async_timeout_list);
|
|
4233
|
|
4234 Vtimeout_free_list = make_opaque_list (sizeof (struct timeout),
|
|
4235 mark_timeout);
|
|
4236 staticpro (&Vtimeout_free_list);
|
|
4237
|
|
4238 the_low_level_timeout_blocktype =
|
|
4239 Blocktype_new (struct low_level_timeout_blocktype);
|
|
4240
|
|
4241 something_happened = 0;
|
|
4242
|
|
4243 last_point_position_buffer = Qnil;
|
|
4244 staticpro (&last_point_position_buffer);
|
|
4245
|
108
|
4246 recursive_sit_for = Qnil;
|
|
4247
|
0
|
4248 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes /*
|
|
4249 *Nonzero means echo unfinished commands after this many seconds of pause.
|
|
4250 */ );
|
|
4251 echo_keystrokes = 1;
|
|
4252
|
|
4253 DEFVAR_INT ("auto-save-interval", &auto_save_interval /*
|
|
4254 *Number of keyboard input characters between auto-saves.
|
|
4255 Zero means disable autosaving due to number of characters typed.
|
|
4256 See also the variable `auto-save-timeout'.
|
|
4257 */ );
|
|
4258 auto_save_interval = 300;
|
|
4259
|
|
4260 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook /*
|
|
4261 Function or functions to run before every command.
|
|
4262 This may examine the `this-command' variable to find out what command
|
|
4263 is about to be run, or may change it to cause a different command to run.
|
|
4264 Function on this hook must be careful to avoid signalling errors!
|
|
4265 */ );
|
|
4266 Vpre_command_hook = Qnil;
|
|
4267
|
|
4268 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook /*
|
|
4269 Function or functions to run after every command.
|
|
4270 This may examine the `this-command' variable to find out what command
|
|
4271 was just executed.
|
|
4272 */ );
|
|
4273 Vpost_command_hook = Qnil;
|
|
4274
|
|
4275 DEFVAR_LISP ("pre-idle-hook", &Vpre_idle_hook /*
|
|
4276 Normal hook run when XEmacs it about to be idle.
|
|
4277 This occurs whenever it is going to block, waiting for an event.
|
|
4278 This generally happens as a result of a call to `next-event',
|
|
4279 `next-command-event', `sit-for', `sleep-for', `accept-process-output',
|
|
4280 `x-get-selection', or various Energize-specific commands.
|
|
4281 Errors running the hook are caught and ignored.
|
|
4282 */ );
|
|
4283 Vpre_idle_hook = Qnil;
|
|
4284
|
72
|
4285 DEFVAR_BOOL ("focus-follows-mouse", &focus_follows_mouse /*
|
|
4286 Variable to control XEmacs behavior with respect to focus changing.
|
|
4287 If this variable is set to t, then XEmacs will not gratuitously change
|
|
4288 the keyboard focus.
|
|
4289 */ );
|
|
4290 focus_follows_mouse = 0;
|
|
4291
|
0
|
4292 #ifdef ILL_CONCEIVED_HOOK
|
|
4293 /* Ill-conceived because it's not run in all sorts of cases
|
|
4294 where XEmacs is blocking. That's what `pre-idle-hook'
|
|
4295 is designed to solve. */
|
|
4296 xxDEFVAR_LISP ("post-command-idle-hook", &Vpost_command_idle_hook /*
|
|
4297 Normal hook run after each command is executed, if idle.
|
|
4298 `post-command-idle-delay' specifies a time in microseconds that XEmacs
|
|
4299 must be idle for in order for the functions on this hook to be called.
|
|
4300 Errors running the hook are caught and ignored.
|
|
4301 */ );
|
|
4302 Vpost_command_idle_hook = Qnil;
|
|
4303
|
|
4304 xxDEFVAR_INT ("post-command-idle-delay", &post_command_idle_delay /*
|
|
4305 Delay time before running `post-command-idle-hook'.
|
|
4306 This is measured in microseconds.
|
|
4307 */ );
|
|
4308 post_command_idle_delay = 5000;
|
|
4309 #endif /* ILL_CONCEIVED_HOOK */
|
|
4310
|
|
4311 #ifdef DEFERRED_ACTION_CRAP
|
|
4312 /* Random FSFmacs crap. There is absolutely nothing to gain,
|
|
4313 and a great deal to lose, in using this in place of just
|
|
4314 setting `post-command-hook'. */
|
|
4315 xxDEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list /*
|
|
4316 List of deferred actions to be performed at a later time.
|
|
4317 The precise format isn't relevant here; we just check whether it is nil.
|
|
4318 */ );
|
|
4319 Vdeferred_action_list = Qnil;
|
|
4320
|
|
4321 xxDEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function /*
|
|
4322 Function to call to handle deferred actions, after each command.
|
|
4323 This function is called with no arguments after each command
|
|
4324 whenever `deferred-action-list' is non-nil.
|
|
4325 */ );
|
|
4326 Vdeferred_action_function = Qnil;
|
|
4327 #endif /* DEFERRED_ACTION_CRAP */
|
|
4328
|
|
4329 DEFVAR_LISP ("last-command-event", &Vlast_command_event /*
|
|
4330 Last keyboard or mouse button event that was part of a command. This
|
|
4331 variable is off limits: you may not set its value or modify the event that
|
|
4332 is its value, as it is destructively modified by `read-key-sequence'. If
|
|
4333 you want to keep a pointer to this value, you must use `copy-event'.
|
|
4334 */ );
|
|
4335 Vlast_command_event = Qnil;
|
|
4336
|
|
4337 DEFVAR_LISP ("last-command-char", &Vlast_command_char /*
|
|
4338 If the value of `last-command-event' is a keyboard event, then
|
2
|
4339 this is the nearest ASCII equivalent to it. This is the value that
|
0
|
4340 `self-insert-command' will put in the buffer. Remember that there is
|
|
4341 NOT a 1:1 mapping between keyboard events and ASCII characters: the set
|
|
4342 of keyboard events is much larger, so writing code that examines this
|
|
4343 variable to determine what key has been typed is bad practice, unless
|
|
4344 you are certain that it will be one of a small set of characters.
|
|
4345 */ );
|
|
4346 Vlast_command_char = Qnil;
|
|
4347
|
|
4348 DEFVAR_LISP ("last-input-event", &Vlast_input_event /*
|
|
4349 Last keyboard or mouse button event received. This variable is off
|
|
4350 limits: you may not set its value or modify the event that is its value, as
|
|
4351 it is destructively modified by `next-event'. If you want to keep a pointer
|
|
4352 to this value, you must use `copy-event'.
|
|
4353 */ );
|
|
4354 Vlast_input_event = Qnil;
|
|
4355
|
|
4356 DEFVAR_LISP ("current-mouse-event", &Vcurrent_mouse_event /*
|
|
4357 The mouse-button event which invoked this command, or nil.
|
|
4358 This is usually what `(interactive \"e\")' returns.
|
|
4359 */ );
|
|
4360 Vcurrent_mouse_event = Qnil;
|
|
4361
|
|
4362 DEFVAR_LISP ("last-input-char", &Vlast_input_char /*
|
|
4363 If the value of `last-input-event' is a keyboard event, then
|
|
4364 this is the nearest ASCII equivalent to it. Remember that there is
|
|
4365 NOT a 1:1 mapping between keyboard events and ASCII characters: the set
|
|
4366 of keyboard events is much larger, so writing code that examines this
|
|
4367 variable to determine what key has been typed is bad practice, unless
|
|
4368 you are certain that it will be one of a small set of characters.
|
|
4369 */ );
|
|
4370 Vlast_input_char = Qnil;
|
|
4371
|
|
4372 DEFVAR_LISP ("last-input-time", &Vlast_input_time /*
|
|
4373 The time (in seconds since Jan 1, 1970) of the last-command-event,
|
|
4374 represented as a cons of two 16-bit integers. This is destructively
|
|
4375 modified, so copy it if you want to keep it.
|
|
4376 */ );
|
|
4377 Vlast_input_time = Qnil;
|
|
4378
|
|
4379 DEFVAR_LISP ("unread-command-events", &Vunread_command_events /*
|
|
4380 List of event objects to be read as next command input events.
|
|
4381 This can be used to simulate the receipt of events from the user.
|
|
4382 Normally this is nil.
|
|
4383 Events are removed from the front of this list.
|
|
4384 */ );
|
|
4385 Vunread_command_events = Qnil;
|
|
4386
|
|
4387 DEFVAR_LISP ("unread-command-event", &Vunread_command_event /*
|
|
4388 Obsolete. Use `unread-command-events' instead.
|
|
4389 */ );
|
|
4390 Vunread_command_event = Qnil;
|
|
4391
|
|
4392 DEFVAR_LISP ("last-command", &Vlast_command /*
|
|
4393 The last command executed. Normally a symbol with a function definition,
|
|
4394 but can be whatever was found in the keymap, or whatever the variable
|
|
4395 `this-command' was set to by that command.
|
|
4396 */ );
|
|
4397 Vlast_command = Qnil;
|
|
4398
|
|
4399 DEFVAR_LISP ("this-command", &Vthis_command /*
|
|
4400 The command now being executed.
|
|
4401 The command can set this variable; whatever is put here
|
|
4402 will be in `last-command' during the following command.
|
|
4403 */ );
|
|
4404 Vthis_command = Qnil;
|
|
4405
|
|
4406 DEFVAR_LISP ("help-char", &Vhelp_char /*
|
|
4407 Character to recognize as meaning Help.
|
|
4408 When it is read, do `(eval help-form)', and display result if it's a string.
|
|
4409 If the value of `help-form' is nil, this char can be read normally.
|
|
4410 This can be any form recognized as a single key specifier.
|
98
|
4411 The help-char cannot be a negative number in XEmacs.
|
0
|
4412 */ );
|
|
4413 Vhelp_char = make_char (8); /* C-h */
|
|
4414
|
|
4415 DEFVAR_LISP ("help-form", &Vhelp_form /*
|
|
4416 Form to execute when character help-char is read.
|
|
4417 If the form returns a string, that string is displayed.
|
|
4418 If `help-form' is nil, the help char is not recognized.
|
|
4419 */ );
|
|
4420 Vhelp_form = Qnil;
|
|
4421
|
|
4422 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command /*
|
|
4423 Command to run when `help-char' character follows a prefix key.
|
|
4424 This command is used only when there is no actual binding
|
|
4425 for that character after that prefix key.
|
|
4426 */ );
|
|
4427 Vprefix_help_command = Qnil;
|
|
4428
|
|
4429 DEFVAR_CONST_LISP ("keyboard-translate-table", &Vkeyboard_translate_table /*
|
|
4430 Hash table used as translate table for keyboard input.
|
|
4431 Use `keyboard-translate' to portably add entries to this table.
|
|
4432 Each key-press event is looked up in this table as follows:
|
|
4433
|
|
4434 -- If an entry maps a symbol to a symbol, then a key-press event whose
|
|
4435 keysym is the former symbol (with any modifiers at all) gets its
|
|
4436 keysym changed and its modifiers left alone. This is useful for
|
|
4437 dealing with non-standard X keyboards, such as the grievous damage
|
|
4438 that Sun has inflicted upon the world.
|
|
4439 -- If an entry maps a character to a character, then a key-press event
|
|
4440 matching the former character gets converted to a key-press event
|
|
4441 matching the latter character. This is useful on ASCII terminals
|
|
4442 for (e.g.) making C-\\ look like C-s, to get around flow-control
|
|
4443 problems.
|
|
4444 -- If an entry maps a character to a symbol, then a key-press event
|
|
4445 matching the character gets converted to a key-press event whose
|
|
4446 keysym is the given symbol and which has no modifiers.
|
|
4447 */ );
|
|
4448
|
|
4449 DEFVAR_LISP ("retry-undefined-key-binding-unshifted",
|
|
4450 &Vretry_undefined_key_binding_unshifted /*
|
|
4451 If a key-sequence which ends with a shifted keystroke is undefined
|
|
4452 and this variable is non-nil then the command lookup is retried again
|
|
4453 with the last key unshifted. (e.g. C-X C-F would be retried as C-X C-f.)
|
|
4454 If lookup still fails, a normal error is signalled. In general,
|
|
4455 you should *bind* this, not set it.
|
|
4456 */ );
|
|
4457 Vretry_undefined_key_binding_unshifted = Qt;
|
|
4458
|
70
|
4459 #ifdef HAVE_XIM
|
|
4460 DEFVAR_LISP ("Vcomposed_character_default_binding",
|
|
4461 &Vretry_undefined_key_binding_unshifted /*
|
|
4462 The default keybinding to use for key events from composed input.
|
|
4463 Window systems frequently have ways to allow the user to compose
|
|
4464 single characters in a language using multiple keystrokes.
|
|
4465 XEmacs sees these as single character keypress events.
|
|
4466 */ );
|
|
4467 Vcomposed_character_default_binding = Qself_insert_command;
|
|
4468 #endif /* HAVE_XIM */
|
|
4469
|
0
|
4470 Vcontrolling_terminal = Qnil;
|
|
4471 staticpro (&Vcontrolling_terminal);
|
|
4472
|
|
4473 Vdribble_file = Qnil;
|
|
4474 staticpro (&Vdribble_file);
|
|
4475
|
2
|
4476
|
0
|
4477 #ifdef DEBUG_XEMACS
|
|
4478 DEFVAR_INT ("debug-emacs-events", &debug_emacs_events /*
|
|
4479 If non-zero, display debug information about Emacs events that XEmacs sees.
|
|
4480 Information is displayed on stderr.
|
|
4481
|
|
4482 Before the event, the source of the event is displayed in parentheses,
|
|
4483 and is one of the following:
|
|
4484
|
|
4485 \(real) A real event from the window system or
|
|
4486 terminal driver, as far as XEmacs can tell.
|
|
4487
|
|
4488 \(keyboard macro) An event generated from a keyboard macro.
|
|
4489
|
|
4490 \(unread-command-events) An event taken from `unread-command-events'.
|
|
4491
|
|
4492 \(unread-command-event) An event taken from `unread-command-event'.
|
|
4493
|
|
4494 \(command event queue) An event taken from an internal queue.
|
|
4495 Events end up on this queue when
|
|
4496 `enqueue-eval-event' is called or when
|
|
4497 user or eval events are received while
|
|
4498 XEmacs is blocking (e.g. in `sit-for',
|
|
4499 `sleep-for', or `accept-process-output',
|
|
4500 or while waiting for the reply to an
|
|
4501 X selection).
|
|
4502
|
|
4503 \(->keyboard-translate-table) The result of an event translated through
|
|
4504 keyboard-translate-table. Note that in
|
|
4505 this case, two events are printed even
|
|
4506 though only one is really generated.
|
|
4507
|
|
4508 \(SIGINT) A faked C-g resulting when XEmacs receives
|
|
4509 a SIGINT (e.g. C-c was pressed in XEmacs'
|
|
4510 controlling terminal or the signal was
|
|
4511 explicitly sent to the XEmacs process).
|
|
4512 */ );
|
|
4513 debug_emacs_events = 0;
|
|
4514 #endif
|
|
4515 }
|
|
4516
|
|
4517 void
|
|
4518 complex_vars_of_event_stream (void)
|
|
4519 {
|
|
4520 Vkeyboard_translate_table = Fmake_hashtable (make_int (100), Qnil);
|
|
4521 }
|
|
4522
|
|
4523 void
|
|
4524 init_event_stream (void)
|
|
4525 {
|
|
4526 if (initialized)
|
|
4527 {
|
|
4528 #ifdef HAVE_UNIXOID_EVENT_LOOP
|
|
4529 init_event_unixoid ();
|
|
4530 #endif
|
|
4531
|
|
4532 #ifdef HAVE_X_WINDOWS
|
|
4533 if (!strcmp (display_use, "x"))
|
|
4534 init_event_Xt_late ();
|
|
4535 else
|
|
4536 #endif
|
|
4537 #ifdef HAVE_NEXTSTEP
|
|
4538 if (!strcmp (display_use, "ns"))
|
|
4539 init_event_ns_late ();
|
|
4540 else
|
|
4541 #endif
|
|
4542 {
|
|
4543 /* For TTY's, use the Xt event loop if we can; it allows
|
|
4544 us to later open an X connection. */
|
|
4545 #if defined (HAVE_X_WINDOWS) && !defined (DEBUG_TTY_EVENT_STREAM)
|
|
4546 init_event_Xt_late ();
|
|
4547 #else
|
|
4548 init_event_tty_late ();
|
|
4549 #endif
|
|
4550 }
|
|
4551 init_interrupts_late ();
|
|
4552 }
|
|
4553 }
|
|
4554
|
|
4555
|
|
4556 /*
|
|
4557 useful testcases for v18/v19 compatibility:
|
|
4558
|
|
4559 (defun foo ()
|
|
4560 (interactive)
|
|
4561 (setq unread-command-event (character-to-event ?A (allocate-event)))
|
|
4562 (setq x (list (read-char)
|
|
4563 ; (read-key-sequence "") ; try it with and without this
|
|
4564 last-command-char last-input-char
|
|
4565 (recent-keys) (this-command-keys))))
|
|
4566 (global-set-key "\^Q" 'foo)
|
|
4567
|
|
4568 without the read-key-sequence:
|
|
4569 ^Q ==> (65 17 65 [... ^Q] [^Q])
|
|
4570 ^U^U^Q ==> (65 17 65 [... ^U ^U ^Q] [^U ^U ^Q])
|
|
4571 ^U^U^U^G^Q ==> (65 17 65 [... ^U ^U ^U ^G ^Q] [^Q])
|
|
4572
|
|
4573 with the read-key-sequence:
|
|
4574 ^Qb ==> (65 [b] 17 98 [... ^Q b] [b])
|
|
4575 ^U^U^Qb ==> (65 [b] 17 98 [... ^U ^U ^Q b] [b])
|
|
4576 ^U^U^U^G^Qb ==> (65 [b] 17 98 [... ^U ^U ^U ^G ^Q b] [b])
|
|
4577
|
|
4578 ;the evi-mode command "4dlj.j.j.j.j.j." is also a good testcase (gag)
|
|
4579
|
|
4580 ;(setq x (list (read-char) quit-flag))^J^G
|
|
4581 ;(let ((inhibit-quit t)) (setq x (list (read-char) quit-flag)))^J^G
|
|
4582 ;for BOTH, x should get set to (7 t), but no result should be printed.
|
|
4583
|
|
4584 ;also do this: make two frames, one viewing "*scratch*", the other "foo".
|
|
4585 ;in *scratch*, type (sit-for 20)^J
|
|
4586 ;wait a couple of seconds, move cursor to foo, type "a"
|
|
4587 ;a should be inserted in foo. Cursor highlighting should not change in
|
|
4588 ;the meantime.
|
|
4589
|
|
4590 ;do it with sleep-for. move cursor into foo, then back into *scratch*
|
|
4591 ;before typing.
|
108
|
4592 ;repeat also with (accept-process-output nil 20)
|
|
4593
|
|
4594 ;make sure ^G aborts sit-for, sleep-for and accept-process-output:
|
0
|
4595
|
|
4596 (defun tst ()
|
|
4597 (list (condition-case c
|
|
4598 (sleep-for 20)
|
|
4599 (quit c))
|
|
4600 (read-char)))
|
|
4601
|
|
4602 (tst)^Ja^G ==> ((quit) 97) with no signal
|
|
4603 (tst)^J^Ga ==> ((quit) 97) with no signal
|
|
4604 (tst)^Jabc^G ==> ((quit) 97) with no signal, and "bc" inserted in buffer
|
|
4605
|
108
|
4606 ; with sit-for only do the 2nd test.
|
|
4607 ; Do all 3 tests with (accept-proccess-output nil 20)
|
|
4608
|
0
|
4609 Do this:
|
|
4610 (setq enable-recursive-minibuffers t
|
|
4611 minibuffer-max-depth nil)
|
|
4612 ESC ESC ESC ESC - there are now two minibuffers active
|
|
4613 C-g C-g C-g - there should be active 0, not 1
|
|
4614 Similarly:
|
|
4615 C-x C-f ~ / ? - wait for "Making completion list..." to display
|
|
4616 C-g - wait for "Quit" to display
|
|
4617 C-g - minibuffer should not be active
|
|
4618 however C-g before "Quit" is displayed should leave minibuffer active.
|
|
4619
|
|
4620 ;do it all in both v18 and v19 and make sure all results are the same.
|
|
4621 ;all of these cases matter a lot, but some in quite subtle ways.
|
|
4622 */
|
108
|
4623
|
|
4624 /*
|
|
4625 Additional test cases for accept-process-output, sleep-for, sit-for.
|
|
4626 Be sure you do all of the above checking for C-g and focus, too!
|
|
4627
|
|
4628 ; Make sure that timer handlers are run during, not after sit-for:
|
|
4629 (defun timer-check ()
|
|
4630 (add-timeout 2 '(lambda (ignore) (message "timer ran")) nil)
|
|
4631 (sit-for 5)
|
|
4632 (message "after sit-for"))
|
|
4633
|
|
4634 ; The first message should appear after 2 seconds, and the final message
|
|
4635 ; 3 seconds after that.
|
|
4636 ; repeat above test with (sleep-for 5) and (accept-process-output nil 5)
|
|
4637
|
|
4638
|
|
4639
|
|
4640 ; Make sure that process filters are run during, not after sit-for.
|
|
4641 (defun fubar ()
|
|
4642 (message "sit-for = %s" (sit-for 30)))
|
|
4643 (add-hook 'post-command-hook 'fubar)
|
|
4644
|
|
4645 ; Now type M-x shell RET
|
|
4646 ; wait for the shell prompt then send: ls RET
|
|
4647 ; the output of ls should fill immediately, and not wait 30 seconds.
|
|
4648
|
|
4649 ; repeat above test with (sleep-for 30) and (accept-process-output nil 30)
|
|
4650
|
|
4651
|
|
4652
|
|
4653 ; Make sure that recursive invocations return immediately:
|
|
4654 (defmacro test-diff-time (start end)
|
|
4655 `(+ (* (- (car ,end) (car ,start)) 65536.0)
|
|
4656 (- (cadr ,end) (cadr ,start))
|
|
4657 (/ (- (caddr ,end) (caddr ,start)) 1000000.0)))
|
|
4658
|
|
4659 (defun testee (ignore)
|
|
4660 ;; All three of these should return immediately.
|
|
4661 (sit-for 10)
|
|
4662 (sleep-for 10)
|
|
4663 (accept-process-output nil 10))
|
|
4664
|
|
4665 (defun test-them ()
|
|
4666 (let ((start (current-time))
|
|
4667 end)
|
|
4668 (add-timeout 2 'testee nil)
|
|
4669 (sit-for 5)
|
|
4670 (add-timeout 2 'testee nil)
|
|
4671 (sleep-for 5)
|
|
4672 (add-timeout 2 'testee nil)
|
|
4673 (accept-process-output nil 5)
|
|
4674 (setq end (current-time))
|
|
4675 (test-diff-time start end)))
|
|
4676
|
|
4677 (test-them) should sit for 15 seconds, not 105 or 96.
|
|
4678
|
|
4679
|
|
4680 */
|