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;
|
|
1981 GCPRO1 (event);
|
|
1982
|
|
1983 /* DO NOT do QUIT anywhere within this function or the functions it calls.
|
|
1984 We want to read the ^G as an event. */
|
|
1985
|
|
1986 if (NILP (event))
|
|
1987 event = Fmake_event ();
|
|
1988 else
|
|
1989 CHECK_LIVE_EVENT (event);
|
|
1990
|
|
1991 if (!NILP (prompt))
|
|
1992 {
|
|
1993 Bytecount len;
|
|
1994 CHECK_STRING (prompt);
|
|
1995
|
14
|
1996 len = XSTRING_LENGTH (prompt);
|
0
|
1997 if (command_builder->echo_buf_length < len)
|
|
1998 len = command_builder->echo_buf_length - 1;
|
14
|
1999 memcpy (command_builder->echo_buf, XSTRING_DATA (prompt), len);
|
0
|
2000 command_builder->echo_buf[len] = 0;
|
|
2001 command_builder->echo_buf_index = len;
|
|
2002 echo_area_message (XFRAME (CONSOLE_SELECTED_FRAME (con)),
|
|
2003 command_builder->echo_buf,
|
|
2004 Qnil, 0,
|
|
2005 command_builder->echo_buf_index,
|
|
2006 Qcommand);
|
|
2007 }
|
|
2008
|
|
2009 start_over_and_avoid_hosage:
|
|
2010
|
|
2011 /* If there is something in unread-command-events, simply return it.
|
|
2012 But do some error checking to make sure the user hasn't put something
|
|
2013 in the unread-command-events that they shouldn't have.
|
|
2014 This does not update this-command-keys and recent-keys.
|
|
2015 */
|
|
2016 if (!NILP (Vunread_command_events))
|
|
2017 {
|
|
2018 if (!CONSP (Vunread_command_events))
|
|
2019 {
|
|
2020 Vunread_command_events = Qnil;
|
|
2021 signal_error (Qwrong_type_argument,
|
|
2022 list3 (Qconsp, Vunread_command_events,
|
|
2023 Qunread_command_events));
|
|
2024 }
|
|
2025 else
|
|
2026 {
|
|
2027 Lisp_Object e = XCAR (Vunread_command_events);
|
|
2028 Vunread_command_events = XCDR (Vunread_command_events);
|
|
2029 if (!EVENTP (e) || !command_event_p (e))
|
|
2030 signal_error (Qwrong_type_argument,
|
|
2031 list3 (Qcommand_event_p, e, Qunread_command_events));
|
|
2032 redisplay ();
|
|
2033 if (!EQ (e, event))
|
|
2034 Fcopy_event (e, event);
|
|
2035 #ifdef DEBUG_XEMACS
|
|
2036 if (debug_emacs_events)
|
|
2037 {
|
|
2038 write_c_string ("(unread-command-events) ",
|
|
2039 Qexternal_debugging_output);
|
|
2040 print_internal (event, Qexternal_debugging_output, 1);
|
|
2041 write_c_string ("\n", Qexternal_debugging_output);
|
|
2042 }
|
|
2043 #endif
|
|
2044 }
|
|
2045 }
|
|
2046
|
|
2047 /* Do similar for unread-command-event (obsoleteness support).
|
|
2048 */
|
|
2049 else if (!NILP (Vunread_command_event))
|
|
2050 {
|
|
2051 Lisp_Object e = Vunread_command_event;
|
|
2052 Vunread_command_event = Qnil;
|
|
2053
|
|
2054 if (!EVENTP (e) || !command_event_p (e))
|
|
2055 {
|
|
2056 signal_error (Qwrong_type_argument,
|
|
2057 list3 (Qeventp, e, Qunread_command_event));
|
|
2058 }
|
|
2059 if (!EQ (e, event))
|
|
2060 Fcopy_event (e, event);
|
|
2061 redisplay ();
|
|
2062 #ifdef DEBUG_XEMACS
|
|
2063 if (debug_emacs_events)
|
|
2064 {
|
|
2065 write_c_string ("(unread-command-event) ",
|
|
2066 Qexternal_debugging_output);
|
|
2067 print_internal (event, Qexternal_debugging_output, 1);
|
|
2068 write_c_string ("\n", Qexternal_debugging_output);
|
|
2069 }
|
|
2070 #endif
|
|
2071 }
|
|
2072
|
|
2073 /* If we're executing a keyboard macro, take the next event from that,
|
|
2074 and update this-command-keys and recent-keys.
|
|
2075 Note that the unread-command-events take precedence over kbd macros.
|
|
2076 */
|
|
2077 else
|
|
2078 {
|
|
2079 if (!NILP (Vexecuting_macro))
|
|
2080 {
|
|
2081 redisplay ();
|
|
2082 pop_kbd_macro_event (event); /* This throws past us at
|
|
2083 end-of-macro. */
|
|
2084 store_this_key = 1;
|
|
2085 #ifdef DEBUG_XEMACS
|
|
2086 if (debug_emacs_events)
|
|
2087 {
|
|
2088 write_c_string ("(keyboard macro) ",
|
|
2089 Qexternal_debugging_output);
|
|
2090 print_internal (event, Qexternal_debugging_output, 1);
|
|
2091 write_c_string ("\n", Qexternal_debugging_output);
|
|
2092 }
|
|
2093 #endif
|
|
2094 }
|
|
2095 /* Otherwise, read a real event, possibly from the
|
|
2096 command_event_queue, and update this-command-keys and
|
|
2097 recent-keys. */
|
|
2098 else
|
|
2099 {
|
|
2100 run_pre_idle_hook ();
|
|
2101 redisplay ();
|
30
|
2102 next_event_internal (event, 1);
|
0
|
2103 Vquit_flag = Qnil; /* Read C-g as an event. */
|
|
2104 store_this_key = 1;
|
|
2105 }
|
|
2106 }
|
|
2107
|
|
2108 status_notify (); /* Notice process change */
|
|
2109
|
|
2110 #ifdef C_ALLOCA
|
|
2111 alloca (0); /* Cause a garbage collection now */
|
|
2112 /* Since we can free the most stuff here
|
|
2113 * (since this is typically called from
|
|
2114 * the command-loop top-level). */
|
|
2115 #endif /* C_ALLOCA */
|
|
2116
|
|
2117 if (object_dead_p (XEVENT (event)->channel))
|
|
2118 /* event_console_or_selected may crash if the channel is dead.
|
|
2119 Best just to eat it and get the next event. */
|
|
2120 goto start_over_and_avoid_hosage;
|
|
2121
|
|
2122 /* OK, now we can stop the selected-console kludge and use the
|
|
2123 actual console from the event. */
|
|
2124 con = event_console_or_selected (event);
|
|
2125 command_builder = XCOMMAND_BUILDER (con->command_builder);
|
|
2126
|
|
2127 switch (XEVENT_TYPE (event))
|
|
2128 {
|
|
2129 default:
|
|
2130 goto RETURN;
|
|
2131 case button_release_event:
|
|
2132 case misc_user_event:
|
|
2133 goto EXECUTE_KEY;
|
|
2134 case button_press_event: /* key or mouse input can trigger prompting */
|
|
2135 goto STORE_AND_EXECUTE_KEY;
|
|
2136 case key_press_event: /* any key input can trigger autosave */
|
|
2137 break;
|
|
2138 }
|
|
2139
|
|
2140 maybe_do_auto_save ();
|
|
2141 num_input_chars++;
|
|
2142 STORE_AND_EXECUTE_KEY:
|
|
2143 if (store_this_key)
|
|
2144 {
|
|
2145 echo_key_event (command_builder, event);
|
|
2146 }
|
|
2147
|
|
2148 EXECUTE_KEY:
|
|
2149 /* Store the last-input-event. The semantics of this is that it is
|
|
2150 the thing most recently returned by next-command-event. It need
|
|
2151 not have come from the keyboard or a keyboard macro, it may have
|
|
2152 come from unread-command-events. It's always a command-event (a
|
|
2153 key, click, or menu selection), never a motion or process event.
|
|
2154 */
|
|
2155 if (!EVENTP (Vlast_input_event))
|
|
2156 Vlast_input_event = Fmake_event ();
|
|
2157 if (XEVENT_TYPE (Vlast_input_event) == dead_event)
|
|
2158 {
|
|
2159 Vlast_input_event = Fmake_event ();
|
|
2160 error ("Someone deallocated last-input-event!");
|
|
2161 }
|
|
2162 if (! EQ (event, Vlast_input_event))
|
|
2163 Fcopy_event (event, Vlast_input_event);
|
|
2164
|
|
2165 /* last-input-char and last-input-time are derived from
|
|
2166 last-input-event.
|
|
2167 Note that last-input-char will never have its high-bit set, in an
|
|
2168 effort to sidestep the ambiguity between M-x and oslash.
|
|
2169 */
|
|
2170 Vlast_input_char = Fevent_to_character (Vlast_input_event,
|
|
2171 Qnil, Qnil, Qnil);
|
|
2172 {
|
|
2173 EMACS_TIME t;
|
|
2174 EMACS_GET_TIME (t);
|
|
2175 if (!CONSP (Vlast_input_time))
|
|
2176 Vlast_input_time = Fcons (Qnil, Qnil);
|
|
2177 XCAR (Vlast_input_time)
|
|
2178 = make_int ((EMACS_SECS (t) >> 16) & 0xffff);
|
|
2179 XCDR (Vlast_input_time)
|
|
2180 = make_int ((EMACS_SECS (t) >> 0) & 0xffff);
|
|
2181 }
|
|
2182
|
|
2183 /* If this key came from the keyboard or from a keyboard macro, then
|
|
2184 it goes into the recent-keys and this-command-keys vectors.
|
|
2185 If this key came from the keyboard, and we're defining a keyboard
|
|
2186 macro, then it goes into the macro.
|
|
2187 */
|
|
2188 if (store_this_key)
|
|
2189 {
|
|
2190 push_this_command_keys (event);
|
|
2191 push_recent_keys (event);
|
|
2192 dribble_out_event (event);
|
|
2193 if (!NILP (con->defining_kbd_macro) && NILP (Vexecuting_macro))
|
|
2194 {
|
|
2195 if (!EVENTP (command_builder->current_events))
|
|
2196 finalize_kbd_macro_chars (con);
|
|
2197 store_kbd_macro_event (event);
|
|
2198 }
|
|
2199 }
|
|
2200 /* If this is the help char and there is a help form, then execute the
|
|
2201 help form and swallow this character. This is the only place where
|
|
2202 calling Fnext_event() can cause arbitrary lisp code to run. Note
|
|
2203 that execute_help_form() calls Fnext_command_event(), which calls
|
|
2204 this function, as well as Fdispatch_event.
|
|
2205 */
|
|
2206 if (!NILP (Vhelp_form) &&
|
|
2207 event_matches_key_specifier_p (XEVENT (event), Vhelp_char))
|
|
2208 execute_help_form (command_builder, event);
|
|
2209
|
|
2210 RETURN:
|
|
2211 UNGCPRO;
|
|
2212 return (event);
|
|
2213 }
|
|
2214
|
20
|
2215 DEFUN ("next-command-event", Fnext_command_event, 0, 2, 0, /*
|
0
|
2216 Return the next available \"user\" event.
|
|
2217 Pass this object to `dispatch-event' to handle it.
|
|
2218
|
|
2219 If EVENT is non-nil, it should be an event object and will be filled in
|
|
2220 and returned; otherwise a new event object will be created and returned.
|
|
2221 If PROMPT is non-nil, it should be a string and will be displayed in the
|
|
2222 echo area while this function is waiting for an event.
|
|
2223
|
|
2224 The event returned will be a keyboard, mouse press, or mouse release event.
|
|
2225 If there are non-command events available (mouse motion, sub-process output,
|
|
2226 etc) then these will be executed (with `dispatch-event') and discarded. This
|
|
2227 function is provided as a convenience; it is equivalent to the lisp code
|
|
2228
|
|
2229 (while (progn
|
|
2230 (next-event event prompt)
|
|
2231 (not (or (key-press-event-p event)
|
|
2232 (button-press-event-p event)
|
|
2233 (button-release-event-p event)
|
|
2234 (misc-user-event-p event))))
|
|
2235 (dispatch-event event))
|
|
2236
|
20
|
2237 */
|
|
2238 (event, prompt))
|
0
|
2239 {
|
|
2240 /* This function can GC */
|
|
2241 struct gcpro gcpro1;
|
|
2242 GCPRO1 (event);
|
|
2243 maybe_echo_keys (XCOMMAND_BUILDER
|
|
2244 (XCONSOLE (Vselected_console)->
|
|
2245 command_builder), 0); /* #### This sucks bigtime */
|
|
2246 for (;;)
|
|
2247 {
|
|
2248 event = Fnext_event (event, prompt);
|
|
2249 if (command_event_p (event))
|
|
2250 break;
|
|
2251 else
|
|
2252 execute_internal_event (event);
|
|
2253 }
|
|
2254 UNGCPRO;
|
|
2255 return (event);
|
|
2256 }
|
|
2257
|
|
2258 static void
|
|
2259 reset_current_events (struct command_builder *command_builder)
|
|
2260 {
|
|
2261 Lisp_Object event = command_builder->current_events;
|
|
2262 reset_command_builder_event_chain (command_builder);
|
|
2263 if (EVENTP (event))
|
|
2264 deallocate_event_chain (event);
|
|
2265 }
|
|
2266
|
20
|
2267 DEFUN ("discard-input", Fdiscard_input, 0, 0, 0, /*
|
0
|
2268 Discard any pending \"user\" events.
|
|
2269 Also cancel any kbd macro being defined.
|
|
2270 A user event is a key press, button press, button release, or
|
|
2271 \"other-user\" event (menu selection or scrollbar action).
|
20
|
2272 */
|
|
2273 ())
|
0
|
2274 {
|
|
2275 /* This throws away user-input on the queue, but doesn't process any
|
|
2276 events. Calling dispatch_event() here leads to a race condition.
|
|
2277 */
|
|
2278 Lisp_Object event = Fmake_event ();
|
|
2279 Lisp_Object head = Qnil, tail = Qnil;
|
|
2280 Lisp_Object oiq = Vinhibit_quit;
|
|
2281 struct gcpro gcpro1, gcpro2;
|
|
2282 /* #### not correct here with Vselected_console? Should
|
|
2283 discard-input take a console argument, or maybe map over
|
|
2284 all consoles? */
|
|
2285 struct console *con = XCONSOLE (Vselected_console);
|
|
2286
|
|
2287 /* next_event_internal() can cause arbitrary Lisp code to be evalled */
|
|
2288 GCPRO2 (event, oiq);
|
|
2289 Vinhibit_quit = Qt;
|
|
2290 /* If a macro was being defined then we have to mark the modeline
|
|
2291 has changed to ensure that it gets updated correctly. */
|
|
2292 if (!NILP (con->defining_kbd_macro))
|
|
2293 MARK_MODELINE_CHANGED;
|
|
2294 con->defining_kbd_macro = Qnil;
|
|
2295 reset_current_events (XCOMMAND_BUILDER (con->command_builder));
|
|
2296
|
|
2297 while (!NILP (command_event_queue)
|
|
2298 || event_stream_event_pending_p (1))
|
|
2299 {
|
|
2300 /* This will take stuff off the command_event_queue, or read it
|
|
2301 from the event_stream, but it will not block.
|
|
2302 */
|
30
|
2303 next_event_internal (event, 1);
|
0
|
2304 Vquit_flag = Qnil; /* Treat C-g as a user event (ignore it).
|
|
2305 It is vitally important that we reset
|
|
2306 Vquit_flag here. Otherwise, if we're
|
|
2307 reading from a TTY console,
|
|
2308 maybe_read_quit_event() will notice
|
|
2309 that C-g has been set and send us
|
|
2310 another C-g. That will cause us
|
|
2311 to get right back here, and read
|
|
2312 another C-g, ad infinitum ... */
|
|
2313
|
|
2314 /* If the event is a user event, ignore it. */
|
|
2315 if (!command_event_p (event))
|
|
2316 {
|
|
2317 /* Otherwise, chain the event onto our list of events not to ignore,
|
|
2318 and keep reading until the queue is empty. This does not mean
|
|
2319 that if a subprocess is generating an infinite amount of output,
|
|
2320 we will never terminate (*provided* that the behavior of
|
|
2321 next_event_cb() is correct -- see the comment in events.h),
|
|
2322 because this loop ends as soon as there are no more user events
|
|
2323 on the command_event_queue or event_stream.
|
|
2324 */
|
|
2325 enqueue_event (Fcopy_event (event, Qnil), &head, &tail);
|
|
2326 }
|
|
2327 }
|
|
2328
|
|
2329 if (!NILP (command_event_queue) || !NILP (command_event_queue_tail))
|
|
2330 abort ();
|
|
2331
|
|
2332 /* Now tack our chain of events back on to the front of the queue.
|
|
2333 Actually, since the queue is now drained, we can just replace it.
|
|
2334 The effect of this will be that we have deleted all user events
|
|
2335 from the input stream without changing the relative ordering of
|
|
2336 any other events. (Some events may have been taken from the
|
|
2337 event_stream and added to the command_event_queue, however.)
|
|
2338
|
|
2339 At this time, the command_event_queue will contain only eval_events.
|
|
2340 */
|
|
2341
|
|
2342 command_event_queue = head;
|
|
2343 command_event_queue_tail = tail;
|
|
2344
|
|
2345 Fdeallocate_event (event);
|
|
2346 UNGCPRO;
|
|
2347
|
|
2348 Vinhibit_quit = oiq;
|
|
2349 return Qnil;
|
|
2350 }
|
|
2351
|
|
2352
|
|
2353 /**********************************************************************/
|
|
2354 /* pausing until an action occurs */
|
|
2355 /**********************************************************************/
|
|
2356
|
30
|
2357 /* This is used in accept-process-output, sleep-for and sit-for.
|
|
2358 Before running any process_events in these routines, we set
|
|
2359 recursive_sit_for to Qt, and use this unwind protect to reset it to
|
32
|
2360 Qnil upon exit. When recursive_sit_for is Qt, calling sit-for will
|
|
2361 cause it to return immediately.
|
30
|
2362
|
|
2363 All of these routines install timeouts, so we clear the installed
|
|
2364 timeout as well.
|
|
2365
|
|
2366 Note: It's very easy to break the desired behaviours of these
|
|
2367 3 routines. If you make any changes to anything in this area, run
|
|
2368 the regression tests at the bottom of the file. -- dmoore */
|
|
2369
|
|
2370
|
|
2371 static Lisp_Object
|
|
2372 sit_for_unwind (Lisp_Object timeout_id)
|
|
2373 {
|
|
2374 if (!NILP(timeout_id))
|
|
2375 Fdisable_timeout (timeout_id);
|
|
2376
|
|
2377 recursive_sit_for = Qnil;
|
|
2378 return Qnil;
|
|
2379 }
|
|
2380
|
0
|
2381 /* #### Is (accept-process-output nil 3) supposed to be like (sleep-for 3)?
|
|
2382 */
|
|
2383
|
20
|
2384 DEFUN ("accept-process-output", Faccept_process_output, 0, 3, 0, /*
|
0
|
2385 Allow any pending output from subprocesses to be read by Emacs.
|
|
2386 It is read into the process' buffers or given to their filter functions.
|
|
2387 Non-nil arg PROCESS means do not return until some output has been received
|
20
|
2388 from PROCESS. Nil arg PROCESS means do not return until some output has
|
|
2389 been received from any process.
|
0
|
2390 If the second arg is non-nil, it is the maximum number of seconds to wait:
|
|
2391 this function will return after that much time even if no input has arrived
|
|
2392 from PROCESS. This argument may be a float, meaning wait some fractional
|
|
2393 part of a second.
|
|
2394 If the third arg is non-nil, it is a number of milliseconds that is added
|
|
2395 to the second arg. (This exists only for compatibility.)
|
|
2396 Return non-nil iff we received any output before the timeout expired.
|
20
|
2397 */
|
|
2398 (process, timeout_secs, timeout_msecs))
|
0
|
2399 {
|
|
2400 /* This function can GC */
|
|
2401 struct gcpro gcpro1, gcpro2;
|
|
2402 Lisp_Object event = Qnil;
|
|
2403 Lisp_Object result = Qnil;
|
|
2404 int timeout_id;
|
|
2405 int timeout_enabled = 0;
|
20
|
2406 int done = 0;
|
0
|
2407 struct buffer *old_buffer = current_buffer;
|
30
|
2408 int count;
|
|
2409
|
0
|
2410 /* We preserve the current buffer but nothing else. If a focus
|
|
2411 change alters the selected window then the top level event loop
|
|
2412 will eventually alter current_buffer to match. In the mean time
|
|
2413 we don't want to mess up whatever called this function. */
|
|
2414
|
|
2415 if (!NILP (process))
|
|
2416 CHECK_PROCESS (process);
|
|
2417
|
|
2418 GCPRO2 (event, process);
|
|
2419
|
20
|
2420 if (!NILP (timeout_secs) || !NILP (timeout_msecs))
|
0
|
2421 {
|
|
2422 unsigned long msecs = 0;
|
|
2423 if (!NILP (timeout_secs))
|
|
2424 msecs = lisp_number_to_milliseconds (timeout_secs, 1);
|
|
2425 if (!NILP (timeout_msecs))
|
|
2426 {
|
|
2427 CHECK_NATNUM (timeout_msecs);
|
|
2428 msecs += XINT (timeout_msecs);
|
|
2429 }
|
|
2430 if (msecs)
|
|
2431 {
|
|
2432 timeout_id = event_stream_generate_wakeup (msecs, 0, Qnil, Qnil, 0);
|
|
2433 timeout_enabled = 1;
|
|
2434 }
|
|
2435 }
|
|
2436
|
|
2437 event = Fmake_event ();
|
|
2438
|
30
|
2439 count = specpdl_depth ();
|
|
2440 record_unwind_protect (sit_for_unwind,
|
|
2441 timeout_enabled ? make_int (timeout_id) : Qnil);
|
|
2442 recursive_sit_for = Qt;
|
|
2443
|
20
|
2444 while (!done &&
|
|
2445 ((NILP (process) && timeout_enabled) ||
|
|
2446 (NILP (process) && event_stream_event_pending_p (0)) ||
|
|
2447 (!NILP (process))))
|
0
|
2448 /* Calling detect_input_pending() is the wrong thing here, because
|
|
2449 that considers the Vunread_command_events and command_event_queue.
|
|
2450 We don't need to look at the command_event_queue because we are
|
|
2451 only interested in process events, which don't go on that. In
|
|
2452 fact, we can't read from it anyway, because we put stuff on it.
|
|
2453
|
|
2454 Note that event_stream->event_pending_p must be called in such
|
|
2455 a way that it says whether any events *of any kind* are ready,
|
|
2456 not just user events, or (accept-process-output nil) will fail
|
|
2457 to dispatch any process events that may be on the queue. It is
|
|
2458 not clear to me that this is important, because the top-level
|
|
2459 loop will process it, and I don't think that there is ever a
|
|
2460 time when one calls accept-process-output with a nil argument
|
|
2461 and really need the processes to be handled. */
|
|
2462 {
|
8
|
2463 /* If our timeout has arrived, we move along. */
|
16
|
2464 if (timeout_enabled && !event_stream_wakeup_pending_p (timeout_id, 0))
|
8
|
2465 {
|
|
2466 timeout_enabled = 0;
|
20
|
2467 done = 1; /* We're done. */
|
|
2468 continue; /* Don't call next_event_internal */
|
8
|
2469 }
|
|
2470
|
0
|
2471 QUIT; /* next_event_internal() does not QUIT, so check for ^G
|
|
2472 before reading output from the process - this makes it
|
|
2473 less likely that the filter will actually be aborted.
|
|
2474 */
|
|
2475
|
30
|
2476 next_event_internal (event, 0);
|
0
|
2477 /* If C-g was pressed while we were waiting, Vquit_flag got
|
|
2478 set and next_event_internal() also returns C-g. When
|
|
2479 we enqueue the C-g below, it will get discarded. The
|
|
2480 next time through, QUIT will be called and will signal a quit. */
|
|
2481 switch (XEVENT_TYPE (event))
|
|
2482 {
|
|
2483 case process_event:
|
|
2484 {
|
20
|
2485 if (NILP (process) ||
|
|
2486 EQ (XEVENT (event)->event.process.process, process))
|
0
|
2487 {
|
20
|
2488 done = 1;
|
0
|
2489 /* RMS's version always returns nil when proc is nil,
|
|
2490 and only returns t if input ever arrived on proc. */
|
|
2491 result = Qt;
|
|
2492 }
|
|
2493
|
|
2494 execute_internal_event (event);
|
|
2495 break;
|
|
2496 }
|
|
2497 case timeout_event:
|
8
|
2498 /* We execute the event even if it's ours, and notice that it's
|
|
2499 happened above. */
|
0
|
2500 case pointer_motion_event:
|
|
2501 case magic_event:
|
|
2502 {
|
20
|
2503 EXECUTE_INTERNAL:
|
0
|
2504 execute_internal_event (event);
|
|
2505 break;
|
|
2506 }
|
|
2507 default:
|
|
2508 {
|
|
2509 enqueue_command_event_1 (event);
|
|
2510 break;
|
|
2511 }
|
|
2512 }
|
|
2513 }
|
|
2514
|
30
|
2515 unbind_to (count, timeout_enabled ? make_int (timeout_id) : Qnil);
|
0
|
2516
|
|
2517 Fdeallocate_event (event);
|
|
2518 UNGCPRO;
|
|
2519 current_buffer = old_buffer;
|
|
2520 return result;
|
|
2521 }
|
|
2522
|
20
|
2523 DEFUN ("sleep-for", Fsleep_for, 1, 1, 0, /*
|
0
|
2524 Pause, without updating display, for ARG seconds.
|
|
2525 ARG may be a float, meaning pause for some fractional part of a second.
|
30
|
2526
|
32
|
2527 It is recommended that you never call sleep-for from inside of a process
|
|
2528 filter function or timer event (either synchronous or asynchronous).
|
20
|
2529 */
|
|
2530 (seconds))
|
0
|
2531 {
|
|
2532 /* This function can GC */
|
|
2533 unsigned long msecs = lisp_number_to_milliseconds (seconds, 1);
|
|
2534 int id;
|
|
2535 Lisp_Object event = Qnil;
|
30
|
2536 int count;
|
0
|
2537 struct gcpro gcpro1;
|
|
2538
|
|
2539 GCPRO1 (event);
|
|
2540
|
|
2541 id = event_stream_generate_wakeup (msecs, 0, Qnil, Qnil, 0);
|
|
2542 event = Fmake_event ();
|
30
|
2543
|
|
2544 count = specpdl_depth ();
|
|
2545 record_unwind_protect (sit_for_unwind, make_int (id));
|
|
2546 recursive_sit_for = Qt;
|
|
2547
|
0
|
2548 while (1)
|
|
2549 {
|
8
|
2550 /* If our timeout has arrived, we move along. */
|
|
2551 if (!event_stream_wakeup_pending_p (id, 0))
|
|
2552 goto DONE_LABEL;
|
|
2553
|
0
|
2554 QUIT; /* next_event_internal() does not QUIT, so check for ^G
|
|
2555 before reading output from the process - this makes it
|
|
2556 less likely that the filter will actually be aborted.
|
|
2557 */
|
|
2558 /* We're a generator of the command_event_queue, so we can't be a
|
|
2559 consumer as well. We don't care about command and eval-events
|
|
2560 anyway.
|
|
2561 */
|
30
|
2562 next_event_internal (event, 0); /* blocks */
|
0
|
2563 /* See the comment in accept-process-output about Vquit_flag */
|
|
2564 switch (XEVENT_TYPE (event))
|
|
2565 {
|
|
2566 case timeout_event:
|
8
|
2567 /* We execute the event even if it's ours, and notice that it's
|
|
2568 happened above. */
|
30
|
2569 case process_event:
|
0
|
2570 case pointer_motion_event:
|
|
2571 case magic_event:
|
|
2572 {
|
|
2573 EXECUTE_INTERNAL:
|
|
2574 execute_internal_event (event);
|
|
2575 break;
|
|
2576 }
|
|
2577 default:
|
|
2578 {
|
|
2579 enqueue_command_event_1 (event);
|
|
2580 break;
|
|
2581 }
|
|
2582 }
|
|
2583 }
|
|
2584 DONE_LABEL:
|
30
|
2585 unbind_to (count, make_int (id));
|
0
|
2586 Fdeallocate_event (event);
|
|
2587 UNGCPRO;
|
|
2588 return Qnil;
|
|
2589 }
|
|
2590
|
20
|
2591 DEFUN ("sit-for", Fsit_for, 1, 2, 0, /*
|
0
|
2592 Perform redisplay, then wait ARG seconds or until user input is available.
|
|
2593 ARG may be a float, meaning a fractional part of a second.
|
|
2594 Optional second arg non-nil means don't redisplay, just wait for input.
|
|
2595 Redisplay is preempted as always if user input arrives, and does not
|
30
|
2596 happen if input is available before it starts.
|
0
|
2597 Value is t if waited the full time with no input arriving.
|
30
|
2598
|
32
|
2599 If sit-for is called from within a process filter function or timer
|
|
2600 event (either synchronous or asynchronous) it will return immediately.
|
20
|
2601 */
|
|
2602 (seconds, nodisplay))
|
0
|
2603 {
|
|
2604 /* This function can GC */
|
|
2605 unsigned long msecs = lisp_number_to_milliseconds (seconds, 1);
|
|
2606 Lisp_Object event, result;
|
|
2607 struct gcpro gcpro1;
|
|
2608 int id;
|
30
|
2609 int count;
|
|
2610
|
0
|
2611 /* The unread-command-events count as pending input */
|
|
2612 if (!NILP (Vunread_command_events) || !NILP (Vunread_command_event))
|
|
2613 return Qnil;
|
|
2614
|
|
2615 /* If the command-builder already has user-input on it (not eval events)
|
|
2616 then that means we're done too.
|
|
2617 */
|
|
2618 if (!NILP (command_event_queue))
|
|
2619 {
|
|
2620 EVENT_CHAIN_LOOP (event, command_event_queue)
|
|
2621 {
|
|
2622 if (command_event_p (event))
|
|
2623 return (Qnil);
|
|
2624 }
|
|
2625 }
|
|
2626
|
|
2627 /* If we're in a macro, or noninteractive, or early in temacs, then
|
|
2628 don't wait. */
|
|
2629 if (noninteractive || !NILP (Vexecuting_macro))
|
|
2630 return (Qnil);
|
|
2631
|
32
|
2632 /* Recusive call from a filter function or timeout handler. */
|
|
2633 if (!NILP(recursive_sit_for))
|
|
2634 {
|
|
2635 if (!event_stream_event_pending_p (1) && NILP (nodisplay))
|
|
2636 {
|
|
2637 run_pre_idle_hook ();
|
|
2638 redisplay ();
|
|
2639 }
|
|
2640 return Qnil;
|
|
2641 }
|
|
2642
|
|
2643
|
0
|
2644 /* Otherwise, start reading events from the event_stream.
|
|
2645 Do this loop at least once even if (sit-for 0) so that we
|
|
2646 redisplay when no input pending.
|
|
2647 */
|
30
|
2648 GCPRO1 (event);
|
0
|
2649 event = Fmake_event ();
|
|
2650
|
|
2651 /* Generate the wakeup even if MSECS is 0, so that existing timeout/etc.
|
|
2652 events get processed. The old (pre-19.12) code special-cased this
|
|
2653 and didn't generate a wakeup, but the resulting behavior was less than
|
|
2654 ideal; viz. the occurrence of (sit-for 0.001) scattered throughout
|
|
2655 the E-Lisp universe. */
|
|
2656
|
|
2657 id = event_stream_generate_wakeup (msecs, 0, Qnil, Qnil, 0);
|
|
2658
|
30
|
2659 count = specpdl_depth ();
|
|
2660 record_unwind_protect (sit_for_unwind, make_int (id));
|
|
2661 recursive_sit_for = Qt;
|
|
2662
|
0
|
2663 while (1)
|
|
2664 {
|
|
2665 /* If there is no user input pending, then redisplay.
|
|
2666 */
|
|
2667 if (!event_stream_event_pending_p (1) && NILP (nodisplay))
|
|
2668 {
|
|
2669 run_pre_idle_hook ();
|
|
2670 redisplay ();
|
|
2671 }
|
|
2672
|
8
|
2673 /* If our timeout has arrived, we move along. */
|
|
2674 if (!event_stream_wakeup_pending_p (id, 0))
|
0
|
2675 {
|
|
2676 result = Qt;
|
|
2677 goto DONE_LABEL;
|
|
2678 }
|
|
2679
|
|
2680 QUIT; /* next_event_internal() does not QUIT, so check for ^G
|
|
2681 before reading output from the process - this makes it
|
|
2682 less likely that the filter will actually be aborted.
|
|
2683 */
|
|
2684 /* We're a generator of the command_event_queue, so we can't be a
|
|
2685 consumer as well. In fact, we know there's nothing on the
|
|
2686 command_event_queue that we didn't just put there.
|
|
2687 */
|
30
|
2688 next_event_internal (event, 0); /* blocks */
|
0
|
2689 /* See the comment in accept-process-output about Vquit_flag */
|
|
2690
|
|
2691 if (command_event_p (event))
|
|
2692 {
|
30
|
2693 QUIT; /* If the command was C-g check it here
|
|
2694 so that we abort out of the sit-for,
|
|
2695 not the next command. sleep-for and
|
|
2696 accept-process-output continue looping
|
|
2697 so they check QUIT again implicitly.*/
|
0
|
2698 result = Qnil;
|
|
2699 goto DONE_LABEL;
|
|
2700 }
|
|
2701 switch (XEVENT_TYPE (event))
|
|
2702 {
|
|
2703 case eval_event:
|
|
2704 {
|
|
2705 /* eval-events get delayed until later. */
|
|
2706 enqueue_command_event (Fcopy_event (event, Qnil));
|
|
2707 break;
|
|
2708 }
|
20
|
2709
|
0
|
2710 case timeout_event:
|
8
|
2711 /* We execute the event even if it's ours, and notice that it's
|
|
2712 happened above. */
|
|
2713 default:
|
0
|
2714 {
|
|
2715 EXECUTE_INTERNAL:
|
|
2716 execute_internal_event (event);
|
|
2717 break;
|
|
2718 }
|
|
2719 }
|
|
2720 }
|
|
2721
|
|
2722 DONE_LABEL:
|
30
|
2723 unbind_to (count, make_int (id));
|
0
|
2724
|
|
2725 /* Put back the event (if any) that made Fsit_for() exit before the
|
|
2726 timeout. Note that it is being added to the back of the queue, which
|
|
2727 would be inappropriate if there were any user events on the queue
|
|
2728 already: we would be misordering them. But we know that there are
|
|
2729 no user-events on the queue, or else we would not have reached this
|
|
2730 point at all.
|
|
2731 */
|
|
2732 if (NILP (result))
|
|
2733 enqueue_command_event (event);
|
|
2734 else
|
|
2735 Fdeallocate_event (event);
|
|
2736
|
|
2737 UNGCPRO;
|
|
2738 return (result);
|
|
2739 }
|
|
2740
|
|
2741 /* This handy little function is used by xselect.c and energize.c to
|
|
2742 wait for replies from processes that aren't really processes (that is,
|
|
2743 the X server and the Energize server).
|
|
2744 */
|
|
2745 void
|
|
2746 wait_delaying_user_input (int (*predicate) (void *arg), void *predicate_arg)
|
|
2747 {
|
|
2748 /* This function can GC */
|
|
2749 Lisp_Object event = Fmake_event ();
|
|
2750 struct gcpro gcpro1;
|
|
2751 GCPRO1 (event);
|
|
2752
|
|
2753 while (!(*predicate) (predicate_arg))
|
|
2754 {
|
|
2755 QUIT; /* next_event_internal() does not QUIT. */
|
|
2756
|
|
2757 /* We're a generator of the command_event_queue, so we can't be a
|
|
2758 consumer as well. Also, we have no reason to consult the
|
|
2759 command_event_queue; there are only user and eval-events there,
|
|
2760 and we'd just have to put them back anyway.
|
|
2761 */
|
30
|
2762 next_event_internal (event, 0);
|
0
|
2763 /* See the comment in accept-process-output about Vquit_flag */
|
|
2764 if (command_event_p (event)
|
|
2765 || (XEVENT_TYPE (event) == eval_event)
|
|
2766 || (XEVENT_TYPE (event) == magic_eval_event))
|
|
2767 enqueue_command_event_1 (event);
|
|
2768 else
|
|
2769 execute_internal_event (event);
|
|
2770 }
|
|
2771 UNGCPRO;
|
|
2772 }
|
|
2773
|
|
2774
|
|
2775 /**********************************************************************/
|
|
2776 /* dispatching events; command builder */
|
|
2777 /**********************************************************************/
|
|
2778
|
|
2779 static void
|
|
2780 execute_internal_event (Lisp_Object event)
|
|
2781 {
|
|
2782 /* events on dead channels get silently eaten */
|
|
2783 if (object_dead_p (XEVENT (event)->channel))
|
|
2784 return;
|
|
2785
|
|
2786 /* This function can GC */
|
|
2787 switch (XEVENT_TYPE (event))
|
|
2788 {
|
|
2789 case empty_event:
|
|
2790 return;
|
|
2791
|
|
2792 case eval_event:
|
|
2793 {
|
|
2794 call1 (XEVENT (event)->event.eval.function,
|
|
2795 XEVENT (event)->event.eval.object);
|
|
2796 return;
|
|
2797 }
|
|
2798
|
|
2799 case magic_eval_event:
|
|
2800 {
|
|
2801 (XEVENT (event)->event.magic_eval.internal_function)
|
|
2802 (XEVENT (event)->event.magic_eval.object);
|
|
2803 return;
|
|
2804 }
|
|
2805
|
|
2806 case pointer_motion_event:
|
|
2807 {
|
|
2808 if (!NILP (Vmouse_motion_handler))
|
|
2809 call1 (Vmouse_motion_handler, event);
|
|
2810 return;
|
|
2811 }
|
|
2812
|
|
2813 case process_event:
|
|
2814 {
|
|
2815 Lisp_Object p = XEVENT (event)->event.process.process;
|
|
2816 Charcount readstatus;
|
|
2817
|
|
2818 assert (PROCESSP (p));
|
|
2819 while ((readstatus = read_process_output (p)) > 0)
|
|
2820 ;
|
|
2821 if (readstatus > 0)
|
|
2822 ; /* this clauses never gets executed but allows the #ifdefs
|
|
2823 to work cleanly. */
|
|
2824 #ifdef EWOULDBLOCK
|
|
2825 else if (readstatus == -1 && errno == EWOULDBLOCK)
|
|
2826 ;
|
|
2827 #endif /* EWOULDBLOCK */
|
|
2828 #ifdef EAGAIN
|
|
2829 else if (readstatus == -1 && errno == EAGAIN)
|
|
2830 ;
|
|
2831 #endif /* EAGAIN */
|
|
2832 else if ((readstatus == 0 &&
|
|
2833 /* Note that we cannot distinguish between no input
|
|
2834 available now and a closed pipe.
|
|
2835 With luck, a closed pipe will be accompanied by
|
|
2836 subprocess termination and SIGCHLD. */
|
|
2837 (!network_connection_p (p) ||
|
|
2838 /*
|
|
2839 When connected to ToolTalk (i.e.
|
|
2840 connected_via_filedesc_p()), it's not possible to
|
|
2841 reliably determine whether there is a message
|
|
2842 waiting for ToolTalk to receive. ToolTalk expects
|
|
2843 to have tt_message_receive() called exactly once
|
|
2844 every time the file descriptor becomes active, so
|
|
2845 the filter function forces this by returning 0.
|
|
2846 Emacs must not interpret this as a closed pipe. */
|
|
2847 connected_via_filedesc_p (XPROCESS (p))))
|
|
2848 #ifdef HAVE_PTYS
|
|
2849 /* On some OSs with ptys, when the process on one end of
|
|
2850 a pty exits, the other end gets an error reading with
|
|
2851 errno = EIO instead of getting an EOF (0 bytes read).
|
|
2852 Therefore, if we get an error reading and errno =
|
|
2853 EIO, just continue, because the child process has
|
|
2854 exited and should clean itself up soon (e.g. when we
|
|
2855 get a SIGCHLD). */
|
|
2856 || (readstatus == -1 && errno == EIO)
|
|
2857 #endif
|
|
2858 )
|
|
2859 {
|
20
|
2860 /* Currently, we rely on SIGCHLD to indicate that the
|
|
2861 process has terminated. Unfortunately, on some systems
|
|
2862 the SIGCHLD gets missed some of the time. So we put an
|
|
2863 additional check in status_notify() to see whether a
|
|
2864 process has terminated. We must tell status_notify()
|
|
2865 to enable that check, and we do so now. */
|
0
|
2866 kick_status_notify ();
|
|
2867 }
|
|
2868 else
|
|
2869 {
|
|
2870 /* Deactivate network connection */
|
|
2871 Lisp_Object status = Fprocess_status (p);
|
|
2872 if (EQ (status, Qopen)
|
|
2873 /* In case somebody changes the theory of whether to
|
|
2874 return open as opposed to run for network connection
|
|
2875 "processes"... */
|
|
2876 || EQ (status, Qrun))
|
|
2877 update_process_status (p, Qexit, 256, 0);
|
|
2878 deactivate_process (p);
|
|
2879 }
|
|
2880
|
|
2881 /* We must call status_notify here to allow the
|
|
2882 event_stream->unselect_process_cb to be run if appropriate.
|
|
2883 Otherwise, dead fds may be selected for, and we will get a
|
|
2884 continuous stream of process events for them. Since we don't
|
|
2885 return until all process events have been flushed, we would
|
|
2886 get stuck here, processing events on a process whose status
|
|
2887 was 'exit. Call this after dispatch-event, or the fds will
|
|
2888 have been closed before we read the last data from them.
|
|
2889 It's safe for the filter to signal an error because
|
|
2890 status_notify() will be called on return to top-level.
|
|
2891 */
|
|
2892 status_notify ();
|
|
2893 return;
|
|
2894 }
|
|
2895
|
|
2896 case timeout_event:
|
|
2897 {
|
|
2898 struct Lisp_Event *e = XEVENT (event);
|
|
2899 if (!NILP (e->event.timeout.function))
|
|
2900 call1 (e->event.timeout.function,
|
|
2901 e->event.timeout.object);
|
|
2902 return;
|
|
2903 }
|
|
2904 case magic_event:
|
|
2905 {
|
|
2906 event_stream_handle_magic_event (XEVENT (event));
|
|
2907 return;
|
|
2908 }
|
|
2909 default:
|
|
2910 abort ();
|
|
2911 }
|
|
2912 }
|
|
2913
|
|
2914
|
|
2915
|
|
2916 static void
|
|
2917 this_command_keys_replace_suffix (Lisp_Object suffix, Lisp_Object chain)
|
|
2918 {
|
|
2919 Lisp_Object first_before_suffix =
|
|
2920 event_chain_find_previous (Vthis_command_keys, suffix);
|
|
2921
|
|
2922 if (NILP (first_before_suffix))
|
|
2923 Vthis_command_keys = chain;
|
|
2924 else
|
|
2925 XSET_EVENT_NEXT (first_before_suffix, chain);
|
|
2926 deallocate_event_chain (suffix);
|
|
2927 Vthis_command_keys_tail = event_chain_tail (chain);
|
|
2928 }
|
|
2929
|
|
2930 static void
|
|
2931 command_builder_replace_suffix (struct command_builder *builder,
|
|
2932 Lisp_Object suffix, Lisp_Object chain)
|
|
2933 {
|
|
2934 Lisp_Object first_before_suffix =
|
|
2935 event_chain_find_previous (builder->current_events, suffix);
|
|
2936
|
|
2937 if (NILP (first_before_suffix))
|
|
2938 builder->current_events = chain;
|
|
2939 else
|
|
2940 XSET_EVENT_NEXT (first_before_suffix, chain);
|
|
2941 deallocate_event_chain (suffix);
|
|
2942 builder->most_current_event = event_chain_tail (chain);
|
|
2943 }
|
|
2944
|
|
2945 static Lisp_Object
|
|
2946 command_builder_find_leaf_1 (struct command_builder *builder)
|
|
2947 {
|
|
2948 Lisp_Object event0 = builder->current_events;
|
|
2949
|
|
2950 if (NILP (event0))
|
|
2951 return (Qnil);
|
|
2952
|
|
2953 return event_binding (event0, 1);
|
|
2954 }
|
|
2955
|
|
2956 /* See if we can do function-key-map or key-translation-map translation
|
|
2957 on the current events in the command builder. If so, do this, and
|
|
2958 return the resulting binding, if any. */
|
|
2959
|
|
2960 static Lisp_Object
|
|
2961 munge_keymap_translate (struct command_builder *builder,
|
|
2962 enum munge_me_out_the_door munge,
|
|
2963 int has_normal_binding_p)
|
|
2964 {
|
|
2965 Lisp_Object suffix;
|
|
2966
|
|
2967 EVENT_CHAIN_LOOP (suffix, builder->munge_me[munge].first_mungeable_event)
|
|
2968 {
|
|
2969 Lisp_Object result = munging_key_map_event_binding (suffix, munge);
|
|
2970
|
|
2971 if (!NILP (result))
|
|
2972 {
|
|
2973 if (KEYMAPP (result))
|
|
2974 {
|
|
2975 if (NILP (builder->last_non_munged_event)
|
|
2976 && !has_normal_binding_p)
|
|
2977 builder->last_non_munged_event =
|
|
2978 builder->most_current_event;
|
|
2979 }
|
|
2980 else
|
|
2981 builder->last_non_munged_event = Qnil;
|
|
2982
|
|
2983 if (!KEYMAPP (result) && !VECTORP (result)
|
|
2984 && !STRINGP (result))
|
|
2985 {
|
|
2986 struct gcpro gcpro1;
|
|
2987 GCPRO1 (suffix);
|
|
2988 result = call1 (result, Qnil);
|
|
2989 UNGCPRO;
|
|
2990 }
|
|
2991
|
|
2992 if (KEYMAPP (result))
|
|
2993 return result;
|
|
2994
|
|
2995 if (VECTORP (result) || STRINGP (result))
|
|
2996 {
|
|
2997 Lisp_Object new_chain =
|
|
2998 key_sequence_to_event_chain (result);
|
|
2999 Lisp_Object tempev;
|
|
3000 int n, tckn;
|
|
3001
|
|
3002 /* If the first_mungeable_event of the other munger
|
|
3003 is within the events we're munging, then it will
|
|
3004 point to deallocated events afterwards, which is
|
|
3005 bad -- so make it point at the beginning of the
|
|
3006 munged events. */
|
|
3007 EVENT_CHAIN_LOOP (tempev, suffix)
|
|
3008 {
|
|
3009 if (EQ (tempev, builder->munge_me[1 - munge].
|
|
3010 first_mungeable_event))
|
|
3011 {
|
|
3012 builder->munge_me[1 - munge].first_mungeable_event =
|
|
3013 new_chain;
|
|
3014 break;
|
|
3015 }
|
|
3016 }
|
|
3017
|
|
3018 n = event_chain_count (suffix);
|
|
3019 command_builder_replace_suffix (builder, suffix, new_chain);
|
|
3020 builder->munge_me[munge].first_mungeable_event = Qnil;
|
|
3021 /* Now hork this-command-keys as well. */
|
|
3022
|
|
3023 /* We just assume that the events we just replaced
|
|
3024 are sitting in copied form at the end of this-command-keys.
|
|
3025 If the user did weird things with `dispatch-event'
|
|
3026 this may not be the case, but at least we make
|
|
3027 sure we won't crash. */
|
|
3028 new_chain = copy_event_chain (new_chain);
|
|
3029 tckn = event_chain_count (Vthis_command_keys);
|
|
3030 if (tckn >= n)
|
|
3031 {
|
|
3032 this_command_keys_replace_suffix
|
|
3033 (event_chain_nth (Vthis_command_keys, tckn - n),
|
|
3034 new_chain);
|
|
3035 }
|
|
3036
|
|
3037 result = command_builder_find_leaf_1 (builder);
|
|
3038 return result;
|
|
3039 }
|
|
3040
|
|
3041 if (munge == MUNGE_ME_FUNCTION_KEY)
|
|
3042 signal_simple_error ("Invalid binding in function-key-map",
|
|
3043 result);
|
|
3044 else
|
|
3045 signal_simple_error ("Invalid binding in key-translation-map",
|
|
3046 result);
|
|
3047 }
|
|
3048 }
|
|
3049
|
|
3050 return Qnil;
|
|
3051 }
|
|
3052
|
|
3053 /* Compare the current state of the command builder against the local and
|
|
3054 global keymaps, and return the binding. If there is no match, try again,
|
2
|
3055 case-insensitively. The return value will be one of:
|
0
|
3056 -- nil (there is no binding)
|
|
3057 -- a keymap (part of a command has been specified)
|
|
3058 -- a command (anything that satisfies `commandp'; this includes
|
|
3059 some symbols, lists, subrs, strings, vectors, and
|
|
3060 compiled-function objects)
|
|
3061 */
|
|
3062 static Lisp_Object
|
|
3063 command_builder_find_leaf (struct command_builder *builder,
|
|
3064 int allow_misc_user_events_p)
|
|
3065 {
|
|
3066 /* This function can GC */
|
|
3067 Lisp_Object result;
|
|
3068 Lisp_Object evee = builder->current_events;
|
|
3069
|
|
3070 if (allow_misc_user_events_p
|
|
3071 && (NILP (XEVENT_NEXT (evee)))
|
|
3072 && (XEVENT_TYPE (evee) == misc_user_event))
|
|
3073 {
|
2
|
3074 Lisp_Object fn = XEVENT (evee)->event.eval.function;
|
0
|
3075 Lisp_Object arg = XEVENT (evee)->event.eval.object;
|
|
3076 return (list2 (fn, arg));
|
|
3077 }
|
|
3078
|
|
3079 else if (XEVENT_TYPE (evee) == misc_user_event)
|
|
3080 return Qnil;
|
|
3081
|
|
3082 result = command_builder_find_leaf_1 (builder);
|
|
3083
|
|
3084 /* Check to see if we have a potential function-key-map match. */
|
|
3085 if (NILP (result))
|
|
3086 {
|
|
3087 result = munge_keymap_translate (builder, MUNGE_ME_FUNCTION_KEY, 0);
|
|
3088 regenerate_echo_keys_from_this_command_keys (builder);
|
|
3089 }
|
|
3090 /* Check to see if we have a potential key-translation-map match. */
|
|
3091 {
|
|
3092 Lisp_Object key_translate_result =
|
|
3093 munge_keymap_translate (builder, MUNGE_ME_KEY_TRANSLATION,
|
|
3094 !NILP (result));
|
|
3095 if (!NILP (key_translate_result))
|
|
3096 {
|
|
3097 result = key_translate_result;
|
|
3098 regenerate_echo_keys_from_this_command_keys (builder);
|
|
3099 }
|
|
3100 }
|
|
3101
|
|
3102 if (!NILP (result))
|
|
3103 return result;
|
|
3104
|
|
3105 /* If key-sequence wasn't bound, we'll try some fallbacks. */
|
|
3106
|
|
3107 /* If we didn't find a binding, and the last event in the sequence is
|
|
3108 a shifted character, then try again with the lowercase version. */
|
|
3109
|
2
|
3110 if (XEVENT_TYPE (builder->most_current_event) == key_press_event
|
|
3111 && !NILP (Vretry_undefined_key_binding_unshifted))
|
|
3112 {
|
|
3113 Lisp_Object terminal = builder->most_current_event;
|
|
3114 struct key_data* key = & XEVENT (terminal)->event.key;
|
|
3115 Emchar c;
|
|
3116 if ((key->modifiers & MOD_SHIFT)
|
|
3117 || (CHAR_OR_CHAR_INTP (key->keysym)
|
|
3118 && ((c = XCHAR_OR_CHAR_INT (key->keysym)), c >= 'A' && c <= 'Z')))
|
|
3119 {
|
|
3120 struct Lisp_Event terminal_copy;
|
|
3121 terminal_copy = *XEVENT (terminal);
|
|
3122
|
|
3123 if (key->modifiers & MOD_SHIFT)
|
|
3124 key->modifiers &= (~ MOD_SHIFT);
|
|
3125 else
|
|
3126 key->keysym = make_char (c + 'a' - 'A');
|
|
3127
|
|
3128 result = command_builder_find_leaf (builder, allow_misc_user_events_p);
|
|
3129 if (!NILP (result))
|
|
3130 return (result);
|
|
3131 /* If there was no match with the lower-case version either,
|
|
3132 then put back the upper-case event for the error
|
|
3133 message. But make sure that function-key-map didn't
|
|
3134 change things out from under us. */
|
|
3135 if (EQ (terminal, builder->most_current_event))
|
|
3136 *XEVENT (terminal) = terminal_copy;
|
|
3137 }
|
|
3138 }
|
|
3139
|
|
3140 /* help-char is `auto-bound' in every keymap */
|
0
|
3141 if (!NILP (Vprefix_help_command) &&
|
|
3142 event_matches_key_specifier_p (XEVENT (builder->most_current_event),
|
|
3143 Vhelp_char))
|
|
3144 return (Vprefix_help_command);
|
|
3145
|
|
3146 /* If we read extra events attempting to match a function key but end
|
|
3147 up failing, then we release those events back to the command loop
|
|
3148 and fail on the original lookup. The released events will then be
|
|
3149 reprocessed in the context of the first part having failed. */
|
|
3150 if (!NILP (builder->last_non_munged_event))
|
|
3151 {
|
|
3152 Lisp_Object event0 = builder->last_non_munged_event;
|
|
3153
|
|
3154 /* Put the commands back on the event queue. */
|
|
3155 enqueue_event_chain (XEVENT_NEXT (event0),
|
|
3156 &command_event_queue,
|
|
3157 &command_event_queue_tail);
|
|
3158
|
|
3159 /* Then remove them from the command builder. */
|
|
3160 XSET_EVENT_NEXT (event0, Qnil);
|
|
3161 builder->most_current_event = event0;
|
|
3162 builder->last_non_munged_event = Qnil;
|
|
3163 }
|
|
3164
|
|
3165 return Qnil;
|
|
3166 }
|
|
3167
|
|
3168
|
|
3169 /* Every time a command-event (a key, button, or menu selection) is read by
|
|
3170 Fnext_event(), it is stored in the recent_keys_ring, in Vlast_input_event,
|
|
3171 and in Vthis_command_keys. (Eval-events are not stored there.)
|
|
3172
|
|
3173 Every time a command is invoked, Vlast_command_event is set to the last
|
|
3174 event in the sequence.
|
|
3175
|
|
3176 This means that Vthis_command_keys is really about "input read since the
|
|
3177 last command was executed" rather than about "what keys invoked this
|
|
3178 command." This is a little counterintuitive, but that's the way it
|
|
3179 has always worked.
|
|
3180
|
|
3181 As an extra kink, the function read-key-sequence resets/updates the
|
|
3182 last-command-event and this-command-keys. It doesn't append to the
|
|
3183 command-keys as read-char does. Such are the pitfalls of having to
|
|
3184 maintain compatibility with a program for which the only specification
|
|
3185 is the code itself.
|
|
3186
|
|
3187 (We could implement recent_keys_ring and Vthis_command_keys as the same
|
|
3188 data structure.)
|
|
3189 */
|
|
3190
|
|
3191 #define RECENT_KEYS_SIZE 100
|
|
3192 Lisp_Object recent_keys_ring;
|
|
3193 int recent_keys_ring_index;
|
|
3194
|
20
|
3195 DEFUN ("recent-keys", Frecent_keys, 0, 0, 0, /*
|
0
|
3196 Return vector of last 100 or so keyboard or mouse button events read.
|
|
3197 This copies the event objects into a new vector; it is safe to keep and
|
|
3198 modify them.
|
20
|
3199 */
|
|
3200 ())
|
0
|
3201 {
|
|
3202 struct gcpro gcpro1;
|
|
3203 Lisp_Object val = Qnil;
|
|
3204 int size = XVECTOR (recent_keys_ring)->size;
|
|
3205 int start, nkeys, i, j;
|
|
3206 GCPRO1 (val);
|
|
3207
|
|
3208 if (NILP (vector_data (XVECTOR (recent_keys_ring))[recent_keys_ring_index]))
|
|
3209 /* This means the vector has not yet wrapped */
|
|
3210 {
|
|
3211 nkeys = recent_keys_ring_index;
|
|
3212 start = 0;
|
|
3213 }
|
|
3214 else
|
|
3215 {
|
|
3216 nkeys = size;
|
|
3217 start = ((recent_keys_ring_index == size) ? 0 : recent_keys_ring_index);
|
|
3218 }
|
|
3219
|
|
3220 val = make_vector (nkeys, Qnil);
|
|
3221
|
|
3222 for (i = 0, j = start; i < nkeys; i++)
|
|
3223 {
|
|
3224 Lisp_Object e = vector_data (XVECTOR (recent_keys_ring))[j];
|
|
3225
|
|
3226 if (NILP (e))
|
|
3227 abort ();
|
|
3228 vector_data (XVECTOR (val))[i] = Fcopy_event (e, Qnil);
|
|
3229 if (++j >= size)
|
|
3230 j = 0;
|
|
3231 }
|
|
3232 UNGCPRO;
|
|
3233 return (val);
|
|
3234 }
|
|
3235
|
|
3236 /* Vthis_command_keys having value Qnil means that the next time
|
|
3237 push_this_command_keys is called, it should start over.
|
2
|
3238 The times at which the command-keys are reset
|
0
|
3239 (instead of merely being augmented) are pretty conterintuitive.
|
|
3240 (More specifically:
|
|
3241
|
|
3242 -- We do not reset this-command-keys when we finish reading a
|
|
3243 command. This is because some commands (e.g. C-u) act
|
|
3244 like command prefixes; they signal this by setting prefix-arg
|
|
3245 to non-nil.
|
|
3246 -- Therefore, we reset this-command-keys when we finish
|
32
|
3247 executing a command, unless prefix-arg is set.
|
0
|
3248 -- However, if we ever do a non-local exit out of a command
|
|
3249 loop (e.g. an error in a command), we need to reset
|
|
3250 this-command-keys. We do this by calling reset_this_command_keys()
|
|
3251 from cmdloop.c, whenever an error causes an invocation of the
|
|
3252 default error handler, and whenever there's a throw to top-level.)
|
|
3253 */
|
|
3254
|
|
3255 void
|
|
3256 reset_this_command_keys (Lisp_Object console, int clear_echo_area_p)
|
|
3257 {
|
|
3258 struct command_builder *command_builder =
|
|
3259 XCOMMAND_BUILDER (XCONSOLE (console)->command_builder);
|
|
3260
|
|
3261 reset_key_echo (command_builder, clear_echo_area_p);
|
|
3262
|
|
3263 deallocate_event_chain (Vthis_command_keys);
|
|
3264 Vthis_command_keys = Qnil;
|
|
3265 Vthis_command_keys_tail = Qnil;
|
|
3266
|
|
3267 reset_current_events (command_builder);
|
|
3268 }
|
|
3269
|
|
3270 static void
|
|
3271 push_this_command_keys (Lisp_Object event)
|
|
3272 {
|
|
3273 Lisp_Object new = Fmake_event ();
|
|
3274
|
|
3275 Fcopy_event (event, new);
|
|
3276 enqueue_event (new, &Vthis_command_keys, &Vthis_command_keys_tail);
|
|
3277 }
|
|
3278
|
|
3279 /* The following two functions are used in call-interactively,
|
|
3280 for the @ and e specifications. We used to just use
|
32
|
3281 `current-mouse-event' (i.e. the last mouse event in this-command-keys),
|
0
|
3282 but FSF does it more generally so we follow their lead. */
|
|
3283
|
|
3284 Lisp_Object
|
|
3285 extract_this_command_keys_nth_mouse_event (int n)
|
|
3286 {
|
|
3287 Lisp_Object event;
|
|
3288
|
|
3289 EVENT_CHAIN_LOOP (event, Vthis_command_keys)
|
|
3290 {
|
|
3291 if (EVENTP (event)
|
|
3292 && (XEVENT_TYPE (event) == button_press_event
|
|
3293 || XEVENT_TYPE (event) == button_release_event
|
|
3294 || XEVENT_TYPE (event) == misc_user_event))
|
|
3295 {
|
|
3296 if (!n)
|
|
3297 {
|
|
3298 /* must copy to avoid an abort() in next_event_internal() */
|
|
3299 if (!NILP (XEVENT_NEXT (event)))
|
|
3300 return Fcopy_event (event, Qnil);
|
|
3301 else
|
|
3302 return event;
|
|
3303 }
|
|
3304 n--;
|
|
3305 }
|
|
3306 }
|
|
3307
|
|
3308 return Qnil;
|
|
3309 }
|
|
3310
|
|
3311 Lisp_Object
|
|
3312 extract_vector_nth_mouse_event (Lisp_Object vector, int n)
|
|
3313 {
|
|
3314 int i;
|
|
3315
|
|
3316 for (i = 0; i < vector_length (XVECTOR (vector)); i++)
|
|
3317 {
|
|
3318 Lisp_Object event = vector_data (XVECTOR (vector))[i];
|
|
3319 if (EVENTP (event)
|
|
3320 && (XEVENT_TYPE (event) == button_press_event
|
|
3321 || XEVENT_TYPE (event) == button_release_event
|
|
3322 || XEVENT_TYPE (event) == misc_user_event))
|
|
3323 {
|
|
3324 if (!n)
|
|
3325 return event;
|
|
3326 n--;
|
|
3327 }
|
|
3328 }
|
|
3329
|
|
3330 return Qnil;
|
|
3331 }
|
|
3332
|
|
3333 static void
|
|
3334 push_recent_keys (Lisp_Object event)
|
|
3335 {
|
|
3336 Lisp_Object e
|
|
3337 = vector_data (XVECTOR (recent_keys_ring)) [recent_keys_ring_index];
|
|
3338
|
|
3339 if (NILP (e))
|
|
3340 {
|
|
3341 e = Fmake_event ();
|
|
3342 vector_data (XVECTOR (recent_keys_ring)) [recent_keys_ring_index] = e;
|
|
3343 }
|
|
3344 Fcopy_event (event, e);
|
|
3345 if (++recent_keys_ring_index == XVECTOR (recent_keys_ring)->size)
|
|
3346 recent_keys_ring_index = 0;
|
|
3347 }
|
|
3348
|
|
3349
|
|
3350 static Lisp_Object
|
|
3351 current_events_into_vector (struct command_builder *command_builder)
|
|
3352 {
|
|
3353 Lisp_Object vector;
|
|
3354 Lisp_Object event;
|
|
3355 int n = event_chain_count (command_builder->current_events);
|
|
3356
|
|
3357 /* Copy the vector and the events in it. */
|
|
3358 /* No need to copy the events, since they're already copies, and
|
|
3359 nobody other than the command-builder has pointers to them */
|
|
3360 vector = make_vector (n, Qnil);
|
|
3361 n = 0;
|
|
3362 EVENT_CHAIN_LOOP (event, command_builder->current_events)
|
|
3363 vector_data (XVECTOR (vector))[n++] = event;
|
|
3364 reset_command_builder_event_chain (command_builder);
|
|
3365 return (vector);
|
|
3366 }
|
|
3367
|
|
3368
|
|
3369 /*
|
|
3370 Given the current state of the command builder and a new command event
|
|
3371 that has just been dispatched:
|
|
3372
|
|
3373 -- add the event to the event chain forming the current command
|
|
3374 (doing meta-translation as necessary)
|
2
|
3375 -- return the binding of this event chain; this will be one of:
|
0
|
3376 -- nil (there is no binding)
|
|
3377 -- a keymap (part of a command has been specified)
|
|
3378 -- a command (anything that satisfies `commandp'; this includes
|
|
3379 some symbols, lists, subrs, strings, vectors, and
|
|
3380 compiled-function objects)
|
|
3381 */
|
|
3382 static Lisp_Object
|
|
3383 lookup_command_event (struct command_builder *command_builder,
|
|
3384 Lisp_Object event, int allow_misc_user_events_p)
|
|
3385 {
|
|
3386 /* This function can GC */
|
|
3387 struct frame *f = selected_frame ();
|
|
3388 /* Clear output from previous command execution */
|
|
3389 if (!EQ (Qcommand, echo_area_status (f))
|
|
3390 /* but don't let mouse-up clear what mouse-down just printed */
|
|
3391 && (XEVENT (event)->event_type != button_release_event))
|
|
3392 clear_echo_area (f, Qnil, 0);
|
|
3393
|
|
3394 /* Add the given event to the command builder.
|
|
3395 Extra hack: this also updates the recent_keys_ring and Vthis_command_keys
|
|
3396 vectors to translate "ESC x" to "M-x" (for any "x" of course).
|
|
3397 */
|
|
3398 {
|
|
3399 Lisp_Object recent = command_builder->most_current_event;
|
|
3400
|
|
3401 if (EVENTP (recent)
|
|
3402 && event_matches_key_specifier_p (XEVENT (recent), Vmeta_prefix_char))
|
|
3403 {
|
|
3404 struct Lisp_Event *e;
|
|
3405 /* When we see a sequence like "ESC x", pretend we really saw "M-x".
|
|
3406 DoubleThink the recent-keys and this-command-keys as well. */
|
|
3407
|
|
3408 /* Modify the previous most-recently-pushed event on the command
|
|
3409 builder to be a copy of this one with the meta-bit set instead of
|
|
3410 pushing a new event.
|
|
3411 */
|
|
3412 Fcopy_event (event, recent);
|
|
3413 e = XEVENT (recent);
|
|
3414 if (e->event_type == key_press_event)
|
|
3415 e->event.key.modifiers |= MOD_META;
|
|
3416 else if (e->event_type == button_press_event
|
|
3417 || e->event_type == button_release_event)
|
|
3418 e->event.button.modifiers |= MOD_META;
|
|
3419 else
|
|
3420 abort ();
|
|
3421
|
|
3422 {
|
|
3423 int tckn = event_chain_count (Vthis_command_keys);
|
|
3424 if (tckn >= 2)
|
|
3425 /* ??? very strange if it's < 2. */
|
|
3426 this_command_keys_replace_suffix
|
|
3427 (event_chain_nth (Vthis_command_keys, tckn - 2),
|
|
3428 Fcopy_event (recent, Qnil));
|
|
3429 }
|
|
3430
|
|
3431 regenerate_echo_keys_from_this_command_keys (command_builder);
|
|
3432 }
|
|
3433 else
|
|
3434 {
|
|
3435 event = Fcopy_event (event, Fmake_event ());
|
|
3436
|
|
3437 command_builder_append_event (command_builder, event);
|
|
3438 }
|
|
3439 }
|
|
3440
|
|
3441 {
|
|
3442 Lisp_Object leaf = command_builder_find_leaf (command_builder,
|
|
3443 allow_misc_user_events_p);
|
|
3444 struct gcpro gcpro1;
|
|
3445 GCPRO1 (leaf);
|
|
3446
|
|
3447 if (KEYMAPP (leaf))
|
|
3448 {
|
|
3449 Lisp_Object prompt = Fkeymap_prompt (leaf, Qt);
|
|
3450 if (STRINGP (prompt))
|
|
3451 {
|
|
3452 /* Append keymap prompt to key echo buffer */
|
|
3453 int buf_index = command_builder->echo_buf_index;
|
14
|
3454 Bytecount len = XSTRING_LENGTH (prompt);
|
0
|
3455
|
|
3456 if (len + buf_index + 1 <= command_builder->echo_buf_length)
|
|
3457 {
|
|
3458 Bufbyte *echo = command_builder->echo_buf + buf_index;
|
14
|
3459 memcpy (echo, XSTRING_DATA (prompt), len);
|
0
|
3460 echo[len] = 0;
|
|
3461 }
|
|
3462 maybe_echo_keys (command_builder, 1);
|
|
3463 }
|
|
3464 else
|
|
3465 maybe_echo_keys (command_builder, 0);
|
|
3466 }
|
|
3467 else if (!NILP (leaf))
|
|
3468 {
|
|
3469 if (EQ (Qcommand, echo_area_status (f))
|
|
3470 && command_builder->echo_buf_index > 0)
|
|
3471 {
|
|
3472 /* If we had been echoing keys, echo the last one (without
|
|
3473 the trailing dash) and redisplay before executing the
|
|
3474 command. */
|
|
3475 command_builder->echo_buf[command_builder->echo_buf_index] = 0;
|
|
3476 maybe_echo_keys (command_builder, 1);
|
|
3477 Fsit_for (Qzero, Qt);
|
|
3478 }
|
|
3479 }
|
|
3480 RETURN_UNGCPRO (leaf);
|
|
3481 }
|
|
3482 }
|
|
3483
|
|
3484 static void
|
|
3485 execute_command_event (struct command_builder *command_builder,
|
|
3486 Lisp_Object event)
|
|
3487 {
|
|
3488 /* This function can GC */
|
|
3489 struct console *con = XCONSOLE (command_builder->console);
|
|
3490 struct gcpro gcpro1;
|
|
3491
|
|
3492 GCPRO1 (event); /* event may be freshly created */
|
|
3493 reset_current_events (command_builder);
|
|
3494
|
|
3495 if (XEVENT (event)->event_type == key_press_event)
|
|
3496 Vcurrent_mouse_event = Qnil;
|
|
3497 else if (XEVENT (event)->event_type == button_press_event
|
|
3498 || XEVENT (event)->event_type == button_release_event
|
|
3499 || XEVENT (event)->event_type == misc_user_event)
|
|
3500 Vcurrent_mouse_event = Fcopy_event (event, Qnil);
|
|
3501
|
|
3502 /* Store the last-command-event. The semantics of this is that it is
|
|
3503 the last event most recently involved in command-lookup.
|
|
3504 */
|
|
3505 if (!EVENTP (Vlast_command_event))
|
|
3506 Vlast_command_event = Fmake_event ();
|
|
3507 if (XEVENT (Vlast_command_event)->event_type == dead_event)
|
|
3508 {
|
|
3509 Vlast_command_event = Fmake_event ();
|
|
3510 error ("Someone deallocated the last-command-event!");
|
|
3511 }
|
|
3512
|
|
3513 if (! EQ (event, Vlast_command_event))
|
|
3514 Fcopy_event (event, Vlast_command_event);
|
|
3515
|
|
3516 /* Note that last-command-char will never have its high-bit set, in
|
|
3517 an effort to sidestep the ambiguity between M-x and oslash.
|
|
3518 */
|
|
3519 Vlast_command_char = Fevent_to_character (Vlast_command_event,
|
|
3520 Qnil, Qnil, Qnil);
|
|
3521
|
|
3522 /* Actually call the command, with all sorts of hair to preserve or clear
|
|
3523 the echo-area and region as appropriate and call the pre- and post-
|
|
3524 command-hooks.
|
|
3525 */
|
|
3526 {
|
|
3527 int old_kbd_macro = con->kbd_macro_end;
|
|
3528 struct window *w;
|
|
3529
|
|
3530 w = XWINDOW (Fselected_window (Qnil));
|
|
3531
|
2
|
3532 /* We're executing a new command, so the old value is irrelevant. */
|
0
|
3533 zmacs_region_stays = 0;
|
|
3534
|
|
3535 /* If the previous command tried to force a specific window-start,
|
|
3536 reset the flag in case this command moves point far away from
|
|
3537 that position. Also, reset the window's buffer's change
|
|
3538 information so that we don't trigger an incremental update. */
|
|
3539 if (w->force_start)
|
|
3540 {
|
|
3541 w->force_start = 0;
|
|
3542 buffer_reset_changes (XBUFFER (w->buffer));
|
|
3543 }
|
|
3544
|
|
3545 pre_command_hook ();
|
|
3546
|
|
3547 if (XEVENT (event)->event_type == misc_user_event)
|
|
3548 {
|
|
3549 call1 (XEVENT (event)->event.eval.function,
|
|
3550 XEVENT (event)->event.eval.object);
|
|
3551 }
|
|
3552 else
|
|
3553 {
|
|
3554 #if 0
|
|
3555 call3 (Qcommand_execute, Vthis_command, Qnil, Qnil);
|
|
3556 #else
|
|
3557 Fcommand_execute (Vthis_command, Qnil, Qnil);
|
|
3558 #endif
|
|
3559 }
|
|
3560
|
|
3561 post_command_hook ();
|
|
3562
|
|
3563 if (!NILP (con->prefix_arg))
|
|
3564 {
|
|
3565 /* Commands that set the prefix arg don't update last-command, don't
|
|
3566 reset the echoing state, and don't go into keyboard macros unless
|
|
3567 followed by another command.
|
|
3568 */
|
|
3569 maybe_echo_keys (command_builder, 0);
|
|
3570
|
|
3571 /* If we're recording a keyboard macro, and the last command
|
|
3572 executed set a prefix argument, then decrement the pointer to
|
|
3573 the "last character really in the macro" to be just before this
|
|
3574 command. This is so that the ^U in "^U ^X )" doesn't go onto
|
|
3575 the end of macro.
|
|
3576 */
|
|
3577 if (!NILP (con->defining_kbd_macro))
|
|
3578 con->kbd_macro_end = old_kbd_macro;
|
|
3579 }
|
|
3580 else
|
|
3581 {
|
|
3582 /* Start a new command next time */
|
|
3583 Vlast_command = Vthis_command;
|
|
3584 /* Emacs 18 doesn't unconditionally clear the echoed keystrokes,
|
|
3585 so we don't either */
|
|
3586 reset_this_command_keys (make_console (con), 0);
|
|
3587 }
|
|
3588 }
|
|
3589
|
|
3590 UNGCPRO;
|
|
3591 }
|
|
3592
|
|
3593 /* Run the pre command hook. */
|
|
3594
|
|
3595 static void
|
|
3596 pre_command_hook (void)
|
|
3597 {
|
|
3598 last_point_position = BUF_PT (current_buffer);
|
|
3599 XSETBUFFER (last_point_position_buffer, current_buffer);
|
|
3600 /* This function can GC */
|
|
3601 safe_run_hook_trapping_errors
|
|
3602 ("Error in `pre-command-hook' (setting hook to nil)",
|
|
3603 Qpre_command_hook, 1);
|
|
3604 }
|
|
3605
|
|
3606 /* Run the post command hook. */
|
|
3607
|
|
3608 static void
|
|
3609 post_command_hook (void)
|
|
3610 {
|
|
3611 /* This function can GC */
|
|
3612 /* Turn off region highlighting unless this command requested that
|
|
3613 it be left on, or we're in the minibuffer. We don't turn it off
|
|
3614 when we're in the minibuffer so that things like M-x write-region
|
|
3615 still work!
|
|
3616
|
|
3617 This could be done via a function on the post-command-hook, but
|
|
3618 we don't want the user to accidentally remove it.
|
|
3619 */
|
2
|
3620
|
|
3621 Lisp_Object win = Fselected_window (Qnil);
|
|
3622
|
|
3623 #if 0
|
|
3624 /* If the last command deleted the frame, `win' might be nil.
|
|
3625 It seems safest to do nothing in this case. */
|
|
3626 /* ### This doesn't really fix the problem,
|
|
3627 if delete-frame is called by some hook */
|
|
3628 if (NILP (win))
|
|
3629 return;
|
|
3630 #endif
|
|
3631
|
0
|
3632 if (! zmacs_region_stays
|
2
|
3633 && (!MINI_WINDOW_P (XWINDOW (win))
|
|
3634 || EQ (zmacs_region_buffer (), WINDOW_BUFFER (XWINDOW (win)))))
|
0
|
3635 zmacs_deactivate_region ();
|
|
3636 else
|
|
3637 zmacs_update_region ();
|
|
3638
|
|
3639 safe_run_hook_trapping_errors
|
|
3640 ("Error in `post-command-hook' (setting hook to nil)",
|
|
3641 Qpost_command_hook, 1);
|
|
3642
|
|
3643 #ifdef DEFERRED_ACTION_CRAP
|
|
3644 if (!NILP (Vdeferred_action_list))
|
|
3645 call0 (Vdeferred_action_function);
|
|
3646 #endif
|
|
3647
|
|
3648 #ifdef ILL_CONCEIVED_HOOK
|
|
3649 if (NILP (Vunread_command_events)
|
|
3650 && NILP (Vexecuting_macro)
|
|
3651 && !NILP (Vpost_command_idle_hook)
|
|
3652 && !NILP (Fsit_for (make_float ((double) post_command_idle_delay
|
|
3653 / 1000000), Qnil)))
|
|
3654 safe_run_hook_trapping_errors
|
|
3655 ("Error in `post-command-idle-hook' (setting hook to nil)",
|
|
3656 Qpost_command_idle_hook, 1);
|
|
3657 #endif
|
|
3658
|
|
3659 #if 0 /* FSFmacs */
|
|
3660 if (!NILP (current_buffer->mark_active))
|
|
3661 {
|
|
3662 if (!NILP (Vdeactivate_mark) && !NILP (Vtransient_mark_mode))
|
|
3663 {
|
|
3664 current_buffer->mark_active = Qnil;
|
|
3665 run_hook (intern ("deactivate-mark-hook"));
|
|
3666 }
|
|
3667 else if (current_buffer != prev_buffer ||
|
|
3668 BUF_MODIFF (current_buffer) != prev_modiff)
|
|
3669 run_hook (intern ("activate-mark-hook"));
|
|
3670 }
|
|
3671 #endif /* FSFmacs */
|
|
3672
|
|
3673 /* #### Kludge!!! This is necessary to make sure that things
|
|
3674 are properly positioned even if post-command-hook moves point.
|
|
3675 #### There should be a cleaner way of handling this. */
|
|
3676 call0 (Qauto_show_make_point_visible);
|
|
3677 }
|
|
3678
|
|
3679
|
20
|
3680 DEFUN ("dispatch-event", Fdispatch_event, 1, 1, 0, /*
|
0
|
3681 Given an event object as returned by `next-event', execute it.
|
|
3682
|
|
3683 Key-press, button-press, and button-release events get accumulated
|
|
3684 until a complete key sequence (see `read-key-sequence') is reached,
|
|
3685 at which point the sequence is looked up in the current keymaps and
|
|
3686 acted upon.
|
|
3687
|
|
3688 Mouse motion events cause the low-level handling function stored in
|
|
3689 `mouse-motion-handler' to be called. (There are very few circumstances
|
|
3690 under which you should change this handler. Use `mode-motion-hook'
|
|
3691 instead.)
|
|
3692
|
|
3693 Menu, timeout, and eval events cause the associated function or handler
|
|
3694 to be called.
|
|
3695
|
|
3696 Process events cause the subprocess's output to be read and acted upon
|
|
3697 appropriately (see `start-process').
|
|
3698
|
|
3699 Magic events are handled as necessary.
|
20
|
3700 */
|
|
3701 (event))
|
0
|
3702 {
|
|
3703 /* This function can GC */
|
|
3704 struct command_builder *command_builder;
|
|
3705 struct Lisp_Event *ev;
|
|
3706 Lisp_Object console;
|
|
3707 Lisp_Object channel;
|
|
3708
|
|
3709 CHECK_LIVE_EVENT (event);
|
|
3710 ev = XEVENT (event);
|
|
3711
|
|
3712 /* events on dead channels get silently eaten */
|
|
3713 channel = EVENT_CHANNEL (ev);
|
|
3714 if (object_dead_p (channel))
|
|
3715 return Qnil;
|
|
3716
|
|
3717 /* Some events don't have channels (e.g. eval events). */
|
|
3718 console = CDFW_CONSOLE (channel);
|
|
3719 if (NILP (console))
|
|
3720 console = Vselected_console;
|
|
3721 else if (!EQ (console, Vselected_console))
|
|
3722 Fselect_console (console);
|
|
3723
|
|
3724 command_builder = XCOMMAND_BUILDER (XCONSOLE (console)->command_builder);
|
|
3725 switch (XEVENT (event)->event_type)
|
|
3726 {
|
|
3727 case button_press_event:
|
|
3728 case button_release_event:
|
|
3729 case key_press_event:
|
|
3730 {
|
|
3731 Lisp_Object leaf;
|
|
3732
|
|
3733 leaf = lookup_command_event (command_builder, event, 1);
|
|
3734 if (KEYMAPP (leaf))
|
|
3735 /* Incomplete key sequence */
|
|
3736 break;
|
|
3737 if (NILP (leaf))
|
|
3738 {
|
|
3739 /* At this point, we know that the sequence is not bound to a
|
|
3740 command. Normally, we beep and print a message informing the
|
|
3741 user of this. But we do not beep or print a message when:
|
|
3742
|
|
3743 o the last event in this sequence is a mouse-up event; or
|
|
3744 o the last event in this sequence is a mouse-down event and
|
|
3745 there is a binding for the mouse-up version.
|
|
3746
|
|
3747 That is, if the sequence ``C-x button1'' is typed, and is not
|
|
3748 bound to a command, but the sequence ``C-x button1up'' is bound
|
|
3749 to a command, we do not complain about the ``C-x button1''
|
|
3750 sequence. If neither ``C-x button1'' nor ``C-x button1up'' is
|
|
3751 bound to a command, then we complain about the ``C-x button1''
|
|
3752 sequence, but later will *not* complain about the
|
|
3753 ``C-x button1up'' sequence, which would be redundant.
|
|
3754
|
|
3755 This is pretty hairy, but I think it's the most intuitive
|
|
3756 behavior.
|
|
3757 */
|
|
3758 Lisp_Object terminal = command_builder->most_current_event;
|
|
3759
|
|
3760 if (XEVENT_TYPE (terminal) == button_press_event)
|
|
3761 {
|
|
3762 int no_bitching;
|
|
3763 /* Temporarily pretend the last event was an "up" instead of a
|
|
3764 "down", and look up its binding. */
|
|
3765 XEVENT_TYPE (terminal) = button_release_event;
|
|
3766 /* If the "up" version is bound, don't complain. */
|
|
3767 no_bitching
|
|
3768 = !NILP (command_builder_find_leaf
|
|
3769 (command_builder, 0));
|
|
3770 /* Undo the temporary changes we just made. */
|
|
3771 XEVENT_TYPE (terminal) = button_press_event;
|
|
3772 if (no_bitching)
|
|
3773 {
|
|
3774 /* Pretend this press was not seen (treat as a prefix) */
|
|
3775 if (EQ (command_builder->current_events, terminal))
|
|
3776 {
|
|
3777 reset_current_events (command_builder);
|
|
3778 }
|
|
3779 else
|
|
3780 {
|
|
3781 Lisp_Object eve;
|
|
3782
|
|
3783 EVENT_CHAIN_LOOP (eve, command_builder->current_events)
|
|
3784 if (EQ (XEVENT_NEXT (eve), terminal))
|
|
3785 break;
|
|
3786
|
|
3787 Fdeallocate_event (command_builder->
|
|
3788 most_current_event);
|
|
3789 XSET_EVENT_NEXT (eve, Qnil);
|
|
3790 command_builder->most_current_event = eve;
|
|
3791 }
|
|
3792 maybe_echo_keys (command_builder, 1);
|
|
3793 break;
|
|
3794 }
|
|
3795 }
|
|
3796
|
|
3797 /* Complain that the typed sequence is not defined, if this is the
|
|
3798 kind of sequence that warrants a complaint.
|
|
3799 */
|
|
3800 XCONSOLE (console)->defining_kbd_macro = Qnil;
|
|
3801 XCONSOLE (console)->prefix_arg = Qnil;
|
|
3802 /* Don't complain about undefined button-release events */
|
|
3803 if (XEVENT_TYPE (terminal) != button_release_event)
|
|
3804 {
|
|
3805 Lisp_Object keys =
|
|
3806 current_events_into_vector (command_builder);
|
|
3807 struct gcpro gcpro1;
|
|
3808
|
|
3809 /* Run the pre-command-hook before barfing about an undefined
|
|
3810 key. */
|
|
3811 Vthis_command = Qnil;
|
|
3812 GCPRO1 (keys);
|
|
3813 pre_command_hook ();
|
|
3814 UNGCPRO;
|
|
3815 /* The post-command-hook doesn't run. */
|
|
3816 Fsignal (Qundefined_keystroke_sequence, list1 (keys));
|
|
3817 }
|
|
3818 /* Reset the command builder for reading the next sequence. */
|
|
3819 reset_this_command_keys (console, 1);
|
|
3820 }
|
2
|
3821 else /* key sequence is bound to a command */
|
0
|
3822 {
|
|
3823 Vthis_command = leaf;
|
|
3824 /* Don't push an undo boundary if the command set the prefix arg,
|
|
3825 or if we are executing a keyboard macro, or if in the
|
|
3826 minibuffer. If the command we are about to execute is
|
|
3827 self-insert, it's tricky: up to 20 consecutive self-inserts may
|
|
3828 be done without an undo boundary. This counter is reset as
|
|
3829 soon as a command other than self-insert-command is executed.
|
|
3830 */
|
|
3831 if (! EQ (leaf, Qself_insert_command))
|
|
3832 command_builder->self_insert_countdown = 0;
|
|
3833 if (NILP (XCONSOLE (console)->prefix_arg)
|
|
3834 && NILP (Vexecuting_macro)
|
|
3835 #if 0
|
|
3836 /* This was done in the days when there was no undo
|
|
3837 in the minibuffer. If we don't disable this code,
|
|
3838 then each instance of "undo" undoes everything in
|
|
3839 the minibuffer. */
|
|
3840 && !EQ (minibuf_window, Fselected_window (Qnil))
|
|
3841 #endif
|
|
3842 && command_builder->self_insert_countdown == 0)
|
|
3843 Fundo_boundary ();
|
|
3844
|
|
3845 if (EQ (leaf, Qself_insert_command))
|
|
3846 {
|
|
3847 if (--command_builder->self_insert_countdown < 0)
|
|
3848 command_builder->self_insert_countdown = 20;
|
|
3849 }
|
2
|
3850 execute_command_event
|
|
3851 (command_builder,
|
|
3852 !NILP (Fequal (event, command_builder-> most_current_event))
|
|
3853 ? event
|
|
3854 /* Use the translated event that was most recently seen.
|
|
3855 This way, last-command-event becomes f1 instead of
|
|
3856 the P from ESC O P. But we must copy it, else we'll
|
|
3857 lose when the command-builder events are deallocated. */
|
|
3858 : Fcopy_event (command_builder-> most_current_event, Qnil));
|
0
|
3859 }
|
|
3860 break;
|
|
3861 }
|
|
3862 case misc_user_event:
|
|
3863 {
|
|
3864 /* Jamie said:
|
|
3865
|
|
3866 We could just always use the menu item entry, whatever it is, but
|
|
3867 this might break some Lisp code that expects `this-command' to
|
|
3868 always contain a symbol. So only store it if this is a simple
|
|
3869 `call-interactively' sort of menu item.
|
|
3870
|
|
3871 But this is bogus. `this-command' could be a string or vector
|
|
3872 anyway (for keyboard macros). There's even one instance
|
|
3873 (in pending-del.el) of `this-command' getting set to a cons
|
|
3874 (a lambda expression). So in the `eval' case I'll just
|
|
3875 convert it into a lambda expression.
|
|
3876 */
|
|
3877 if (EQ (XEVENT (event)->event.eval.function, Qcall_interactively)
|
|
3878 && SYMBOLP (XEVENT (event)->event.eval.object))
|
|
3879 Vthis_command = XEVENT (event)->event.eval.object;
|
|
3880 else if (EQ (XEVENT (event)->event.eval.function, Qeval))
|
|
3881 Vthis_command =
|
|
3882 Fcons (Qlambda, Fcons (Qnil, XEVENT (event)->event.eval.object));
|
|
3883 else if (SYMBOLP (XEVENT (event)->event.eval.function))
|
|
3884 /* A scrollbar command or the like. */
|
|
3885 Vthis_command = XEVENT (event)->event.eval.function;
|
|
3886 else
|
|
3887 /* Huh? */
|
|
3888 Vthis_command = Qnil;
|
|
3889
|
|
3890 command_builder->self_insert_countdown = 0;
|
|
3891 if (NILP (XCONSOLE (console)->prefix_arg)
|
|
3892 && NILP (Vexecuting_macro)
|
|
3893 && !EQ (minibuf_window, Fselected_window (Qnil)))
|
|
3894 Fundo_boundary ();
|
|
3895 execute_command_event (command_builder, event);
|
|
3896 break;
|
|
3897 }
|
|
3898 default:
|
|
3899 {
|
|
3900 execute_internal_event (event);
|
|
3901 break;
|
|
3902 }
|
|
3903 }
|
|
3904 return (Qnil);
|
|
3905 }
|
|
3906
|
20
|
3907 DEFUN ("read-key-sequence", Fread_key_sequence, 1, 3, 0, /*
|
0
|
3908 Read a sequence of keystrokes or mouse clicks.
|
|
3909 Returns a vector of the event objects read. The vector and the event
|
|
3910 objects it contains are freshly created (and will not be side-effected
|
|
3911 by subsequent calls to this function).
|
|
3912
|
|
3913 The sequence read is sufficient to specify a non-prefix command starting
|
|
3914 from the current local and global keymaps. A C-g typed while in this
|
|
3915 function is treated like any other character, and `quit-flag' is not set.
|
|
3916
|
|
3917 First arg PROMPT is a prompt string. If nil, do not prompt specially.
|
|
3918 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos
|
|
3919 as a continuation of the previous key.
|
|
3920
|
|
3921 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not
|
|
3922 convert the last event to lower case. (Normally any upper case event
|
|
3923 is converted to lower case if the original event is undefined and the lower
|
|
3924 case equivalent is defined.) This argument is provided mostly for
|
|
3925 FSF compatibility; the equivalent effect can be achieved more generally
|
|
3926 by binding `retry-undefined-key-binding-unshifted' to nil around the
|
|
3927 call to `read-key-sequence'.
|
|
3928
|
|
3929 A C-g typed while in this function is treated like any other character,
|
|
3930 and `quit-flag' is not set.
|
|
3931
|
|
3932 If the user selects a menu item while we are prompting for a key-sequence,
|
|
3933 the returned value will be a vector of a single menu-selection event.
|
|
3934 An error will be signalled if you pass this value to `lookup-key' or a
|
|
3935 related function.
|
|
3936
|
|
3937 `read-key-sequence' checks `function-key-map' for function key
|
|
3938 sequences, where they wouldn't conflict with ordinary bindings. See
|
|
3939 `function-key-map' for more details.
|
20
|
3940 */
|
|
3941 (prompt, continue_echo, dont_downcase_last))
|
0
|
3942 {
|
|
3943 /* This function can GC */
|
|
3944 struct console *con = XCONSOLE (Vselected_console); /* #### correct?
|
|
3945 Probably not -- see
|
|
3946 comment in
|
|
3947 next-event */
|
|
3948 struct command_builder *command_builder =
|
|
3949 XCOMMAND_BUILDER (con->command_builder);
|
|
3950 Lisp_Object result;
|
|
3951 Lisp_Object event = Fmake_event ();
|
|
3952 int speccount = specpdl_depth ();
|
|
3953 struct gcpro gcpro1;
|
|
3954 GCPRO1 (event);
|
|
3955
|
|
3956 if (!NILP (prompt))
|
|
3957 CHECK_STRING (prompt);
|
|
3958 /* else prompt = Fkeymap_prompt (current_buffer->keymap); may GC */
|
|
3959 QUIT;
|
|
3960
|
|
3961 if (NILP (continue_echo))
|
|
3962 reset_this_command_keys (make_console (con), 1);
|
|
3963
|
|
3964 specbind (Qinhibit_quit, Qt);
|
|
3965
|
|
3966 if (!NILP (dont_downcase_last))
|
|
3967 specbind (Qretry_undefined_key_binding_unshifted, Qnil);
|
|
3968
|
|
3969 for (;;)
|
|
3970 {
|
|
3971 Fnext_event (event, prompt);
|
|
3972 /* restore the selected-console damage */
|
|
3973 con = event_console_or_selected (event);
|
|
3974 command_builder = XCOMMAND_BUILDER (con->command_builder);
|
|
3975 if (! command_event_p (event))
|
|
3976 execute_internal_event (event);
|
|
3977 else
|
|
3978 {
|
|
3979 if (XEVENT (event)->event_type == misc_user_event)
|
|
3980 reset_current_events (command_builder);
|
|
3981 result = lookup_command_event (command_builder, event, 1);
|
|
3982 if (!KEYMAPP (result))
|
|
3983 {
|
|
3984 result = current_events_into_vector (command_builder);
|
|
3985 reset_key_echo (command_builder, 0);
|
|
3986 break;
|
|
3987 }
|
|
3988 prompt = Qnil;
|
|
3989 }
|
|
3990 }
|
|
3991
|
|
3992 Vquit_flag = Qnil; /* In case we read a ^G; do not call check_quit() here */
|
|
3993 Fdeallocate_event (event);
|
|
3994 RETURN_UNGCPRO (unbind_to (speccount, result));
|
|
3995 }
|
|
3996
|
20
|
3997 DEFUN ("this-command-keys", Fthis_command_keys, 0, 0, 0, /*
|
0
|
3998 Return a vector of the keyboard or mouse button events that were used
|
|
3999 to invoke this command. This copies the vector and the events; it is safe
|
|
4000 to keep and modify them.
|
20
|
4001 */
|
|
4002 ())
|
0
|
4003 {
|
|
4004 Lisp_Object event;
|
|
4005 Lisp_Object result;
|
|
4006 int len;
|
|
4007
|
|
4008 if (NILP (Vthis_command_keys))
|
|
4009 return (make_vector (0, Qnil));
|
|
4010
|
|
4011 len = event_chain_count (Vthis_command_keys);
|
|
4012
|
|
4013 result = make_vector (len, Qnil);
|
|
4014 len = 0;
|
|
4015 EVENT_CHAIN_LOOP (event, Vthis_command_keys)
|
|
4016 vector_data (XVECTOR (result))[len++] = Fcopy_event (event, Qnil);
|
|
4017 return (result);
|
|
4018 }
|
|
4019
|
20
|
4020 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths, 0, 0, 0, /*
|
0
|
4021 Used for complicated reasons in `universal-argument-other-key'.
|
|
4022
|
|
4023 `universal-argument-other-key' rereads the event just typed.
|
|
4024 It then gets translated through `function-key-map'.
|
|
4025 The translated event gets included in the echo area and in
|
|
4026 the value of `this-command-keys' in addition to the raw original event.
|
|
4027 That is not right.
|
|
4028
|
|
4029 Calling this function directs the translated event to replace
|
|
4030 the original event, so that only one version of the event actually
|
|
4031 appears in the echo area and in the value of `this-command-keys.'.
|
20
|
4032 */
|
|
4033 ())
|
0
|
4034 {
|
|
4035 /* #### I don't understand this at all, so currently it does nothing.
|
|
4036 If there is ever a problem, maybe someone should investigate. */
|
|
4037 return Qnil;
|
|
4038 }
|
|
4039
|
|
4040
|
|
4041 static void
|
|
4042 dribble_out_event (Lisp_Object event)
|
|
4043 {
|
|
4044 if (NILP (Vdribble_file))
|
|
4045 return;
|
|
4046
|
|
4047 if (XEVENT (event)->event_type == key_press_event &&
|
|
4048 !XEVENT (event)->event.key.modifiers)
|
|
4049 {
|
|
4050 Lisp_Object keysym = XEVENT (event)->event.key.keysym;
|
|
4051 if (CHARP (XEVENT (event)->event.key.keysym))
|
|
4052 {
|
|
4053 Emchar ch = XCHAR (keysym);
|
|
4054 Bufbyte str[MAX_EMCHAR_LEN];
|
|
4055 Bytecount len;
|
|
4056
|
|
4057 len = set_charptr_emchar (str, ch);
|
|
4058 Lstream_write (XLSTREAM (Vdribble_file), str, len);
|
|
4059 }
|
|
4060 else if (string_char_length (XSYMBOL (keysym)->name) == 1)
|
|
4061 /* one-char key events are printed with just the key name */
|
|
4062 Fprinc (keysym, Vdribble_file);
|
|
4063 else if (EQ (keysym, Qreturn))
|
|
4064 Lstream_putc (XLSTREAM (Vdribble_file), '\n');
|
|
4065 else if (EQ (keysym, Qspace))
|
|
4066 Lstream_putc (XLSTREAM (Vdribble_file), ' ');
|
|
4067 else
|
|
4068 Fprinc (event, Vdribble_file);
|
|
4069 }
|
|
4070 else
|
|
4071 Fprinc (event, Vdribble_file);
|
|
4072 Lstream_flush (XLSTREAM (Vdribble_file));
|
|
4073 }
|
|
4074
|
20
|
4075 DEFUN ("open-dribble-file", Fopen_dribble_file, 1, 1,
|
|
4076 "FOpen dribble file: ", /*
|
0
|
4077 Start writing all keyboard characters to a dribble file called FILE.
|
|
4078 If FILE is nil, close any open dribble file.
|
20
|
4079 */
|
|
4080 (file))
|
0
|
4081 {
|
|
4082 /* This function can GC */
|
|
4083 /* XEmacs change: always close existing dribble file. */
|
|
4084 /* FSFmacs uses FILE *'s here. With lstreams, that's unnecessary. */
|
|
4085 if (!NILP (Vdribble_file))
|
|
4086 {
|
|
4087 Lstream_close (XLSTREAM (Vdribble_file));
|
|
4088 Vdribble_file = Qnil;
|
|
4089 }
|
|
4090 if (!NILP (file))
|
|
4091 {
|
|
4092 int fd;
|
|
4093
|
|
4094 file = Fexpand_file_name (file, Qnil);
|
14
|
4095 fd = creat ((char *) XSTRING_DATA (file), 0666);
|
0
|
4096 if (fd < 0)
|
|
4097 error ("Unable to create dribble file");
|
|
4098 Vdribble_file = make_filedesc_output_stream (fd, 0, 0, LSTR_CLOSING);
|
|
4099 }
|
|
4100 return Qnil;
|
|
4101 }
|
|
4102
|
|
4103
|
|
4104 /************************************************************************/
|
|
4105 /* initialization */
|
|
4106 /************************************************************************/
|
|
4107
|
|
4108 void
|
|
4109 syms_of_event_stream (void)
|
|
4110 {
|
|
4111 defsymbol (&Qdisabled, "disabled");
|
|
4112 defsymbol (&Qcommand_event_p, "command-event-p");
|
|
4113
|
|
4114 deferror (&Qundefined_keystroke_sequence, "undefined-keystroke-sequence",
|
|
4115 "Undefined keystroke sequence", Qerror);
|
|
4116 defsymbol (&Qcommand_execute, "command-execute");
|
|
4117
|
20
|
4118 DEFSUBR (Frecent_keys);
|
|
4119 DEFSUBR (Finput_pending_p);
|
|
4120 DEFSUBR (Fenqueue_eval_event);
|
|
4121 DEFSUBR (Fnext_event);
|
|
4122 DEFSUBR (Fnext_command_event);
|
|
4123 DEFSUBR (Fdiscard_input);
|
|
4124 DEFSUBR (Fsit_for);
|
|
4125 DEFSUBR (Fsleep_for);
|
|
4126 DEFSUBR (Faccept_process_output);
|
|
4127 DEFSUBR (Fadd_timeout);
|
|
4128 DEFSUBR (Fdisable_timeout);
|
|
4129 DEFSUBR (Fadd_async_timeout);
|
|
4130 DEFSUBR (Fdisable_async_timeout);
|
|
4131 DEFSUBR (Fdispatch_event);
|
|
4132 DEFSUBR (Fread_key_sequence);
|
|
4133 DEFSUBR (Fthis_command_keys);
|
|
4134 DEFSUBR (Freset_this_command_lengths);
|
|
4135 DEFSUBR (Fopen_dribble_file);
|
0
|
4136
|
|
4137 defsymbol (&Qpre_command_hook, "pre-command-hook");
|
|
4138 defsymbol (&Qpost_command_hook, "post-command-hook");
|
|
4139 defsymbol (&Qunread_command_events, "unread-command-events");
|
|
4140 defsymbol (&Qunread_command_event, "unread-command-event");
|
|
4141 defsymbol (&Qpre_idle_hook, "pre-idle-hook");
|
|
4142 #ifdef ILL_CONCEIVED_HOOK
|
|
4143 defsymbol (&Qpost_command_idle_hook, "post-command-idle-hook");
|
|
4144 #endif
|
|
4145 #ifdef DEFERRED_ACTION_CRAP
|
|
4146 defsymbol (&Qdeferred_action_function, "deferred-action-function");
|
|
4147 #endif
|
|
4148 defsymbol (&Qretry_undefined_key_binding_unshifted,
|
|
4149 "retry-undefined-key-binding-unshifted");
|
|
4150 defsymbol (&Qauto_show_make_point_visible,
|
|
4151 "auto-show-make-point-visible");
|
|
4152 }
|
|
4153
|
|
4154 void
|
|
4155 vars_of_event_stream (void)
|
|
4156 {
|
|
4157 #ifdef HAVE_X_WINDOWS
|
|
4158 vars_of_event_Xt ();
|
|
4159 #endif
|
|
4160 #if defined (DEBUG_TTY_EVENT_STREAM) || !defined (HAVE_X_WINDOWS)
|
|
4161 vars_of_event_tty ();
|
|
4162 #endif
|
|
4163 #ifdef HAVE_NEXTSTEP
|
|
4164 vars_of_event_ns ();
|
|
4165 #endif
|
|
4166
|
|
4167
|
|
4168 recent_keys_ring_index = 0;
|
|
4169 recent_keys_ring = make_vector (RECENT_KEYS_SIZE, Qnil);
|
|
4170 staticpro (&recent_keys_ring);
|
|
4171
|
|
4172 Vthis_command_keys = Qnil;
|
|
4173 staticpro (&Vthis_command_keys);
|
|
4174 Vthis_command_keys_tail = Qnil;
|
|
4175
|
|
4176 num_input_chars = 0;
|
|
4177
|
|
4178 command_event_queue = Qnil;
|
|
4179 staticpro (&command_event_queue);
|
|
4180 command_event_queue_tail = Qnil;
|
|
4181
|
|
4182 Vlast_selected_frame = Qnil;
|
|
4183 staticpro (&Vlast_selected_frame);
|
|
4184
|
|
4185 pending_timeout_list = Qnil;
|
|
4186 staticpro (&pending_timeout_list);
|
|
4187
|
|
4188 pending_async_timeout_list = Qnil;
|
|
4189 staticpro (&pending_async_timeout_list);
|
|
4190
|
|
4191 Vtimeout_free_list = make_opaque_list (sizeof (struct timeout),
|
|
4192 mark_timeout);
|
|
4193 staticpro (&Vtimeout_free_list);
|
|
4194
|
|
4195 the_low_level_timeout_blocktype =
|
|
4196 Blocktype_new (struct low_level_timeout_blocktype);
|
|
4197
|
|
4198 something_happened = 0;
|
|
4199
|
|
4200 last_point_position_buffer = Qnil;
|
|
4201 staticpro (&last_point_position_buffer);
|
|
4202
|
30
|
4203 recursive_sit_for = Qnil;
|
|
4204
|
0
|
4205 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes /*
|
|
4206 *Nonzero means echo unfinished commands after this many seconds of pause.
|
|
4207 */ );
|
|
4208 echo_keystrokes = 1;
|
|
4209
|
|
4210 DEFVAR_INT ("auto-save-interval", &auto_save_interval /*
|
|
4211 *Number of keyboard input characters between auto-saves.
|
|
4212 Zero means disable autosaving due to number of characters typed.
|
|
4213 See also the variable `auto-save-timeout'.
|
|
4214 */ );
|
|
4215 auto_save_interval = 300;
|
|
4216
|
|
4217 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook /*
|
|
4218 Function or functions to run before every command.
|
|
4219 This may examine the `this-command' variable to find out what command
|
|
4220 is about to be run, or may change it to cause a different command to run.
|
|
4221 Function on this hook must be careful to avoid signalling errors!
|
|
4222 */ );
|
|
4223 Vpre_command_hook = Qnil;
|
|
4224
|
|
4225 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook /*
|
|
4226 Function or functions to run after every command.
|
|
4227 This may examine the `this-command' variable to find out what command
|
|
4228 was just executed.
|
|
4229 */ );
|
|
4230 Vpost_command_hook = Qnil;
|
|
4231
|
|
4232 DEFVAR_LISP ("pre-idle-hook", &Vpre_idle_hook /*
|
|
4233 Normal hook run when XEmacs it about to be idle.
|
|
4234 This occurs whenever it is going to block, waiting for an event.
|
|
4235 This generally happens as a result of a call to `next-event',
|
|
4236 `next-command-event', `sit-for', `sleep-for', `accept-process-output',
|
|
4237 `x-get-selection', or various Energize-specific commands.
|
|
4238 Errors running the hook are caught and ignored.
|
|
4239 */ );
|
|
4240 Vpre_idle_hook = Qnil;
|
|
4241
|
4
|
4242 DEFVAR_BOOL ("focus-follows-mouse", &focus_follows_mouse /*
|
|
4243 Variable to control XEmacs behavior with respect to focus changing.
|
|
4244 If this variable is set to t, then XEmacs will not gratuitously change
|
|
4245 the keyboard focus.
|
|
4246 */ );
|
|
4247 focus_follows_mouse = 0;
|
|
4248
|
0
|
4249 #ifdef ILL_CONCEIVED_HOOK
|
|
4250 /* Ill-conceived because it's not run in all sorts of cases
|
|
4251 where XEmacs is blocking. That's what `pre-idle-hook'
|
|
4252 is designed to solve. */
|
|
4253 xxDEFVAR_LISP ("post-command-idle-hook", &Vpost_command_idle_hook /*
|
|
4254 Normal hook run after each command is executed, if idle.
|
|
4255 `post-command-idle-delay' specifies a time in microseconds that XEmacs
|
|
4256 must be idle for in order for the functions on this hook to be called.
|
|
4257 Errors running the hook are caught and ignored.
|
|
4258 */ );
|
|
4259 Vpost_command_idle_hook = Qnil;
|
|
4260
|
|
4261 xxDEFVAR_INT ("post-command-idle-delay", &post_command_idle_delay /*
|
|
4262 Delay time before running `post-command-idle-hook'.
|
|
4263 This is measured in microseconds.
|
|
4264 */ );
|
|
4265 post_command_idle_delay = 5000;
|
|
4266 #endif /* ILL_CONCEIVED_HOOK */
|
|
4267
|
|
4268 #ifdef DEFERRED_ACTION_CRAP
|
|
4269 /* Random FSFmacs crap. There is absolutely nothing to gain,
|
|
4270 and a great deal to lose, in using this in place of just
|
|
4271 setting `post-command-hook'. */
|
|
4272 xxDEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list /*
|
|
4273 List of deferred actions to be performed at a later time.
|
|
4274 The precise format isn't relevant here; we just check whether it is nil.
|
|
4275 */ );
|
|
4276 Vdeferred_action_list = Qnil;
|
|
4277
|
|
4278 xxDEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function /*
|
|
4279 Function to call to handle deferred actions, after each command.
|
|
4280 This function is called with no arguments after each command
|
|
4281 whenever `deferred-action-list' is non-nil.
|
|
4282 */ );
|
|
4283 Vdeferred_action_function = Qnil;
|
|
4284 #endif /* DEFERRED_ACTION_CRAP */
|
|
4285
|
|
4286 DEFVAR_LISP ("last-command-event", &Vlast_command_event /*
|
|
4287 Last keyboard or mouse button event that was part of a command. This
|
|
4288 variable is off limits: you may not set its value or modify the event that
|
|
4289 is its value, as it is destructively modified by `read-key-sequence'. If
|
|
4290 you want to keep a pointer to this value, you must use `copy-event'.
|
|
4291 */ );
|
|
4292 Vlast_command_event = Qnil;
|
|
4293
|
|
4294 DEFVAR_LISP ("last-command-char", &Vlast_command_char /*
|
|
4295 If the value of `last-command-event' is a keyboard event, then
|
2
|
4296 this is the nearest ASCII equivalent to it. This is the value that
|
0
|
4297 `self-insert-command' will put in the buffer. Remember that there is
|
|
4298 NOT a 1:1 mapping between keyboard events and ASCII characters: the set
|
|
4299 of keyboard events is much larger, so writing code that examines this
|
|
4300 variable to determine what key has been typed is bad practice, unless
|
|
4301 you are certain that it will be one of a small set of characters.
|
|
4302 */ );
|
|
4303 Vlast_command_char = Qnil;
|
|
4304
|
|
4305 DEFVAR_LISP ("last-input-event", &Vlast_input_event /*
|
|
4306 Last keyboard or mouse button event received. This variable is off
|
|
4307 limits: you may not set its value or modify the event that is its value, as
|
|
4308 it is destructively modified by `next-event'. If you want to keep a pointer
|
|
4309 to this value, you must use `copy-event'.
|
|
4310 */ );
|
|
4311 Vlast_input_event = Qnil;
|
|
4312
|
|
4313 DEFVAR_LISP ("current-mouse-event", &Vcurrent_mouse_event /*
|
|
4314 The mouse-button event which invoked this command, or nil.
|
|
4315 This is usually what `(interactive \"e\")' returns.
|
|
4316 */ );
|
|
4317 Vcurrent_mouse_event = Qnil;
|
|
4318
|
|
4319 DEFVAR_LISP ("last-input-char", &Vlast_input_char /*
|
|
4320 If the value of `last-input-event' is a keyboard event, then
|
|
4321 this is the nearest ASCII equivalent to it. Remember that there is
|
|
4322 NOT a 1:1 mapping between keyboard events and ASCII characters: the set
|
|
4323 of keyboard events is much larger, so writing code that examines this
|
|
4324 variable to determine what key has been typed is bad practice, unless
|
|
4325 you are certain that it will be one of a small set of characters.
|
|
4326 */ );
|
|
4327 Vlast_input_char = Qnil;
|
|
4328
|
|
4329 DEFVAR_LISP ("last-input-time", &Vlast_input_time /*
|
|
4330 The time (in seconds since Jan 1, 1970) of the last-command-event,
|
|
4331 represented as a cons of two 16-bit integers. This is destructively
|
|
4332 modified, so copy it if you want to keep it.
|
|
4333 */ );
|
|
4334 Vlast_input_time = Qnil;
|
|
4335
|
|
4336 DEFVAR_LISP ("unread-command-events", &Vunread_command_events /*
|
|
4337 List of event objects to be read as next command input events.
|
|
4338 This can be used to simulate the receipt of events from the user.
|
|
4339 Normally this is nil.
|
|
4340 Events are removed from the front of this list.
|
|
4341 */ );
|
|
4342 Vunread_command_events = Qnil;
|
|
4343
|
|
4344 DEFVAR_LISP ("unread-command-event", &Vunread_command_event /*
|
|
4345 Obsolete. Use `unread-command-events' instead.
|
|
4346 */ );
|
|
4347 Vunread_command_event = Qnil;
|
|
4348
|
|
4349 DEFVAR_LISP ("last-command", &Vlast_command /*
|
|
4350 The last command executed. Normally a symbol with a function definition,
|
|
4351 but can be whatever was found in the keymap, or whatever the variable
|
|
4352 `this-command' was set to by that command.
|
|
4353 */ );
|
|
4354 Vlast_command = Qnil;
|
|
4355
|
|
4356 DEFVAR_LISP ("this-command", &Vthis_command /*
|
|
4357 The command now being executed.
|
|
4358 The command can set this variable; whatever is put here
|
|
4359 will be in `last-command' during the following command.
|
|
4360 */ );
|
|
4361 Vthis_command = Qnil;
|
|
4362
|
|
4363 DEFVAR_LISP ("help-char", &Vhelp_char /*
|
|
4364 Character to recognize as meaning Help.
|
|
4365 When it is read, do `(eval help-form)', and display result if it's a string.
|
|
4366 If the value of `help-form' is nil, this char can be read normally.
|
|
4367 This can be any form recognized as a single key specifier.
|
|
4368 To disable the help-char, set it to a negative number.
|
|
4369 */ );
|
|
4370 Vhelp_char = make_char (8); /* C-h */
|
|
4371
|
|
4372 DEFVAR_LISP ("help-form", &Vhelp_form /*
|
|
4373 Form to execute when character help-char is read.
|
|
4374 If the form returns a string, that string is displayed.
|
|
4375 If `help-form' is nil, the help char is not recognized.
|
|
4376 */ );
|
|
4377 Vhelp_form = Qnil;
|
|
4378
|
|
4379 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command /*
|
|
4380 Command to run when `help-char' character follows a prefix key.
|
|
4381 This command is used only when there is no actual binding
|
|
4382 for that character after that prefix key.
|
|
4383 */ );
|
|
4384 Vprefix_help_command = Qnil;
|
|
4385
|
|
4386 DEFVAR_CONST_LISP ("keyboard-translate-table", &Vkeyboard_translate_table /*
|
|
4387 Hash table used as translate table for keyboard input.
|
|
4388 Use `keyboard-translate' to portably add entries to this table.
|
|
4389 Each key-press event is looked up in this table as follows:
|
|
4390
|
|
4391 -- If an entry maps a symbol to a symbol, then a key-press event whose
|
|
4392 keysym is the former symbol (with any modifiers at all) gets its
|
|
4393 keysym changed and its modifiers left alone. This is useful for
|
|
4394 dealing with non-standard X keyboards, such as the grievous damage
|
|
4395 that Sun has inflicted upon the world.
|
|
4396 -- If an entry maps a character to a character, then a key-press event
|
|
4397 matching the former character gets converted to a key-press event
|
|
4398 matching the latter character. This is useful on ASCII terminals
|
|
4399 for (e.g.) making C-\\ look like C-s, to get around flow-control
|
|
4400 problems.
|
|
4401 -- If an entry maps a character to a symbol, then a key-press event
|
|
4402 matching the character gets converted to a key-press event whose
|
|
4403 keysym is the given symbol and which has no modifiers.
|
|
4404 */ );
|
|
4405
|
|
4406 DEFVAR_LISP ("retry-undefined-key-binding-unshifted",
|
|
4407 &Vretry_undefined_key_binding_unshifted /*
|
|
4408 If a key-sequence which ends with a shifted keystroke is undefined
|
|
4409 and this variable is non-nil then the command lookup is retried again
|
|
4410 with the last key unshifted. (e.g. C-X C-F would be retried as C-X C-f.)
|
|
4411 If lookup still fails, a normal error is signalled. In general,
|
|
4412 you should *bind* this, not set it.
|
|
4413 */ );
|
|
4414 Vretry_undefined_key_binding_unshifted = Qt;
|
|
4415
|
|
4416 Vcontrolling_terminal = Qnil;
|
|
4417 staticpro (&Vcontrolling_terminal);
|
|
4418
|
|
4419 Vdribble_file = Qnil;
|
|
4420 staticpro (&Vdribble_file);
|
|
4421
|
2
|
4422
|
0
|
4423 #ifdef DEBUG_XEMACS
|
|
4424 DEFVAR_INT ("debug-emacs-events", &debug_emacs_events /*
|
|
4425 If non-zero, display debug information about Emacs events that XEmacs sees.
|
|
4426 Information is displayed on stderr.
|
|
4427
|
|
4428 Before the event, the source of the event is displayed in parentheses,
|
|
4429 and is one of the following:
|
|
4430
|
|
4431 \(real) A real event from the window system or
|
|
4432 terminal driver, as far as XEmacs can tell.
|
|
4433
|
|
4434 \(keyboard macro) An event generated from a keyboard macro.
|
|
4435
|
|
4436 \(unread-command-events) An event taken from `unread-command-events'.
|
|
4437
|
|
4438 \(unread-command-event) An event taken from `unread-command-event'.
|
|
4439
|
|
4440 \(command event queue) An event taken from an internal queue.
|
|
4441 Events end up on this queue when
|
|
4442 `enqueue-eval-event' is called or when
|
|
4443 user or eval events are received while
|
|
4444 XEmacs is blocking (e.g. in `sit-for',
|
|
4445 `sleep-for', or `accept-process-output',
|
|
4446 or while waiting for the reply to an
|
|
4447 X selection).
|
|
4448
|
|
4449 \(->keyboard-translate-table) The result of an event translated through
|
|
4450 keyboard-translate-table. Note that in
|
|
4451 this case, two events are printed even
|
|
4452 though only one is really generated.
|
|
4453
|
|
4454 \(SIGINT) A faked C-g resulting when XEmacs receives
|
|
4455 a SIGINT (e.g. C-c was pressed in XEmacs'
|
|
4456 controlling terminal or the signal was
|
|
4457 explicitly sent to the XEmacs process).
|
|
4458 */ );
|
|
4459 debug_emacs_events = 0;
|
|
4460 #endif
|
|
4461 }
|
|
4462
|
|
4463 void
|
|
4464 complex_vars_of_event_stream (void)
|
|
4465 {
|
|
4466 Vkeyboard_translate_table = Fmake_hashtable (make_int (100), Qnil);
|
|
4467 }
|
|
4468
|
|
4469 void
|
|
4470 init_event_stream (void)
|
|
4471 {
|
|
4472 if (initialized)
|
|
4473 {
|
|
4474 #ifdef HAVE_UNIXOID_EVENT_LOOP
|
|
4475 init_event_unixoid ();
|
|
4476 #endif
|
|
4477
|
|
4478 #ifdef HAVE_X_WINDOWS
|
|
4479 if (!strcmp (display_use, "x"))
|
|
4480 init_event_Xt_late ();
|
|
4481 else
|
|
4482 #endif
|
|
4483 #ifdef HAVE_NEXTSTEP
|
|
4484 if (!strcmp (display_use, "ns"))
|
|
4485 init_event_ns_late ();
|
|
4486 else
|
|
4487 #endif
|
|
4488 {
|
|
4489 /* For TTY's, use the Xt event loop if we can; it allows
|
|
4490 us to later open an X connection. */
|
|
4491 #if defined (HAVE_X_WINDOWS) && !defined (DEBUG_TTY_EVENT_STREAM)
|
|
4492 init_event_Xt_late ();
|
|
4493 #else
|
|
4494 init_event_tty_late ();
|
|
4495 #endif
|
|
4496 }
|
|
4497 init_interrupts_late ();
|
|
4498 }
|
|
4499 }
|
|
4500
|
|
4501
|
|
4502 /*
|
|
4503 useful testcases for v18/v19 compatibility:
|
|
4504
|
|
4505 (defun foo ()
|
|
4506 (interactive)
|
|
4507 (setq unread-command-event (character-to-event ?A (allocate-event)))
|
|
4508 (setq x (list (read-char)
|
|
4509 ; (read-key-sequence "") ; try it with and without this
|
|
4510 last-command-char last-input-char
|
|
4511 (recent-keys) (this-command-keys))))
|
|
4512 (global-set-key "\^Q" 'foo)
|
|
4513
|
|
4514 without the read-key-sequence:
|
|
4515 ^Q ==> (65 17 65 [... ^Q] [^Q])
|
|
4516 ^U^U^Q ==> (65 17 65 [... ^U ^U ^Q] [^U ^U ^Q])
|
|
4517 ^U^U^U^G^Q ==> (65 17 65 [... ^U ^U ^U ^G ^Q] [^Q])
|
|
4518
|
|
4519 with the read-key-sequence:
|
|
4520 ^Qb ==> (65 [b] 17 98 [... ^Q b] [b])
|
|
4521 ^U^U^Qb ==> (65 [b] 17 98 [... ^U ^U ^Q b] [b])
|
|
4522 ^U^U^U^G^Qb ==> (65 [b] 17 98 [... ^U ^U ^U ^G ^Q b] [b])
|
|
4523
|
|
4524 ;the evi-mode command "4dlj.j.j.j.j.j." is also a good testcase (gag)
|
|
4525
|
|
4526 ;(setq x (list (read-char) quit-flag))^J^G
|
|
4527 ;(let ((inhibit-quit t)) (setq x (list (read-char) quit-flag)))^J^G
|
|
4528 ;for BOTH, x should get set to (7 t), but no result should be printed.
|
|
4529
|
|
4530 ;also do this: make two frames, one viewing "*scratch*", the other "foo".
|
|
4531 ;in *scratch*, type (sit-for 20)^J
|
|
4532 ;wait a couple of seconds, move cursor to foo, type "a"
|
|
4533 ;a should be inserted in foo. Cursor highlighting should not change in
|
|
4534 ;the meantime.
|
|
4535
|
|
4536 ;do it with sleep-for. move cursor into foo, then back into *scratch*
|
|
4537 ;before typing.
|
30
|
4538 ;repeat also with (accept-process-output nil 20)
|
|
4539
|
|
4540 ;make sure ^G aborts sit-for, sleep-for and accept-process-output:
|
0
|
4541
|
|
4542 (defun tst ()
|
|
4543 (list (condition-case c
|
|
4544 (sleep-for 20)
|
|
4545 (quit c))
|
|
4546 (read-char)))
|
|
4547
|
|
4548 (tst)^Ja^G ==> ((quit) 97) with no signal
|
|
4549 (tst)^J^Ga ==> ((quit) 97) with no signal
|
|
4550 (tst)^Jabc^G ==> ((quit) 97) with no signal, and "bc" inserted in buffer
|
|
4551
|
30
|
4552 ; with sit-for only do the 2nd test.
|
|
4553 ; Do all 3 tests with (accept-proccess-output nil 20)
|
|
4554
|
0
|
4555 Do this:
|
|
4556 (setq enable-recursive-minibuffers t
|
|
4557 minibuffer-max-depth nil)
|
|
4558 ESC ESC ESC ESC - there are now two minibuffers active
|
|
4559 C-g C-g C-g - there should be active 0, not 1
|
|
4560 Similarly:
|
|
4561 C-x C-f ~ / ? - wait for "Making completion list..." to display
|
|
4562 C-g - wait for "Quit" to display
|
|
4563 C-g - minibuffer should not be active
|
|
4564 however C-g before "Quit" is displayed should leave minibuffer active.
|
|
4565
|
|
4566 ;do it all in both v18 and v19 and make sure all results are the same.
|
|
4567 ;all of these cases matter a lot, but some in quite subtle ways.
|
|
4568 */
|
30
|
4569
|
|
4570 /*
|
|
4571 Additional test cases for accept-process-output, sleep-for, sit-for.
|
|
4572 Be sure you do all of the above checking for C-g and focus, too!
|
|
4573
|
|
4574 ; Make sure that timer handlers are run during, not after sit-for:
|
|
4575 (defun timer-check ()
|
|
4576 (add-timeout 2 '(lambda (ignore) (message "timer ran")) nil)
|
|
4577 (sit-for 5)
|
|
4578 (message "after sit-for"))
|
|
4579
|
|
4580 ; The first message should appear after 2 seconds, and the final message
|
|
4581 ; 3 seconds after that.
|
|
4582 ; repeat above test with (sleep-for 5) and (accept-process-output nil 5)
|
|
4583
|
|
4584
|
|
4585
|
|
4586 ; Make sure that process filters are run during, not after sit-for.
|
|
4587 (defun fubar ()
|
|
4588 (message "sit-for = %s" (sit-for 30)))
|
|
4589 (add-hook 'post-command-hook 'fubar)
|
|
4590
|
|
4591 ; Now type M-x shell RET
|
|
4592 ; wait for the shell prompt then send: ls RET
|
|
4593 ; the output of ls should fill immediately, and not wait 30 seconds.
|
|
4594
|
|
4595 ; repeat above test with (sleep-for 30) and (accept-process-output nil 30)
|
|
4596
|
|
4597
|
|
4598
|
|
4599 ; Make sure that recursive invocations return immediately:
|
|
4600 (defmacro test-diff-time (start end)
|
|
4601 `(+ (* (- (car ,end) (car ,start)) 65536.0)
|
|
4602 (- (cadr ,end) (cadr ,start))
|
|
4603 (/ (- (caddr ,end) (caddr ,start)) 1000000.0)))
|
|
4604
|
|
4605 (defun testee (ignore)
|
32
|
4606 (sit-for 10))
|
30
|
4607
|
|
4608 (defun test-them ()
|
|
4609 (let ((start (current-time))
|
|
4610 end)
|
|
4611 (add-timeout 2 'testee nil)
|
|
4612 (sit-for 5)
|
|
4613 (add-timeout 2 'testee nil)
|
|
4614 (sleep-for 5)
|
|
4615 (add-timeout 2 'testee nil)
|
|
4616 (accept-process-output nil 5)
|
|
4617 (setq end (current-time))
|
|
4618 (test-diff-time start end)))
|
|
4619
|
32
|
4620 (test-them) should sit for 15 seconds.
|
|
4621 Repeat with testee set to sleep-for and accept-process-output.
|
|
4622 These should each delay 36 seconds.
|
30
|
4623
|
|
4624 */
|