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