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