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