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