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