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