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