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