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