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