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