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