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