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