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