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