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:
|
|
2168 case misc_user_event:
|
175
|
2169 /* don't echo menu accelerator keys */
|
|
2170 reset_key_echo (command_builder, 1);
|
0
|
2171 goto EXECUTE_KEY;
|
|
2172 case button_press_event: /* key or mouse input can trigger prompting */
|
|
2173 goto STORE_AND_EXECUTE_KEY;
|
|
2174 case key_press_event: /* any key input can trigger autosave */
|
|
2175 break;
|
|
2176 }
|
|
2177
|
|
2178 maybe_do_auto_save ();
|
|
2179 num_input_chars++;
|
|
2180 STORE_AND_EXECUTE_KEY:
|
|
2181 if (store_this_key)
|
|
2182 {
|
|
2183 echo_key_event (command_builder, event);
|
|
2184 }
|
|
2185
|
|
2186 EXECUTE_KEY:
|
|
2187 /* Store the last-input-event. The semantics of this is that it is
|
|
2188 the thing most recently returned by next-command-event. It need
|
|
2189 not have come from the keyboard or a keyboard macro, it may have
|
|
2190 come from unread-command-events. It's always a command-event (a
|
|
2191 key, click, or menu selection), never a motion or process event.
|
|
2192 */
|
|
2193 if (!EVENTP (Vlast_input_event))
|
189
|
2194 Vlast_input_event = Fmake_event (Qnil, Qnil);
|
0
|
2195 if (XEVENT_TYPE (Vlast_input_event) == dead_event)
|
|
2196 {
|
189
|
2197 Vlast_input_event = Fmake_event (Qnil, Qnil);
|
0
|
2198 error ("Someone deallocated last-input-event!");
|
|
2199 }
|
|
2200 if (! EQ (event, Vlast_input_event))
|
|
2201 Fcopy_event (event, Vlast_input_event);
|
173
|
2202
|
0
|
2203 /* last-input-char and last-input-time are derived from
|
|
2204 last-input-event.
|
|
2205 Note that last-input-char will never have its high-bit set, in an
|
|
2206 effort to sidestep the ambiguity between M-x and oslash.
|
|
2207 */
|
|
2208 Vlast_input_char = Fevent_to_character (Vlast_input_event,
|
|
2209 Qnil, Qnil, Qnil);
|
|
2210 {
|
|
2211 EMACS_TIME t;
|
|
2212 EMACS_GET_TIME (t);
|
|
2213 if (!CONSP (Vlast_input_time))
|
|
2214 Vlast_input_time = Fcons (Qnil, Qnil);
|
185
|
2215 XCAR (Vlast_input_time) = make_int ((EMACS_SECS (t) >> 16) & 0xffff);
|
|
2216 XCDR (Vlast_input_time) = make_int ((EMACS_SECS (t) >> 0) & 0xffff);
|
0
|
2217 }
|
|
2218
|
|
2219 /* If this key came from the keyboard or from a keyboard macro, then
|
|
2220 it goes into the recent-keys and this-command-keys vectors.
|
|
2221 If this key came from the keyboard, and we're defining a keyboard
|
|
2222 macro, then it goes into the macro.
|
|
2223 */
|
|
2224 if (store_this_key)
|
|
2225 {
|
|
2226 push_this_command_keys (event);
|
187
|
2227 if (!inhibit_input_event_recording)
|
|
2228 push_recent_keys (event);
|
0
|
2229 dribble_out_event (event);
|
|
2230 if (!NILP (con->defining_kbd_macro) && NILP (Vexecuting_macro))
|
|
2231 {
|
|
2232 if (!EVENTP (command_builder->current_events))
|
|
2233 finalize_kbd_macro_chars (con);
|
|
2234 store_kbd_macro_event (event);
|
|
2235 }
|
|
2236 }
|
|
2237 /* If this is the help char and there is a help form, then execute the
|
|
2238 help form and swallow this character. This is the only place where
|
|
2239 calling Fnext_event() can cause arbitrary lisp code to run. Note
|
|
2240 that execute_help_form() calls Fnext_command_event(), which calls
|
|
2241 this function, as well as Fdispatch_event.
|
|
2242 */
|
|
2243 if (!NILP (Vhelp_form) &&
|
|
2244 event_matches_key_specifier_p (XEVENT (event), Vhelp_char))
|
|
2245 execute_help_form (command_builder, event);
|
|
2246
|
|
2247 RETURN:
|
|
2248 UNGCPRO;
|
173
|
2249 return event;
|
0
|
2250 }
|
|
2251
|
20
|
2252 DEFUN ("next-command-event", Fnext_command_event, 0, 2, 0, /*
|
185
|
2253 Return the next available "user" event.
|
0
|
2254 Pass this object to `dispatch-event' to handle it.
|
|
2255
|
|
2256 If EVENT is non-nil, it should be an event object and will be filled in
|
|
2257 and returned; otherwise a new event object will be created and returned.
|
|
2258 If PROMPT is non-nil, it should be a string and will be displayed in the
|
|
2259 echo area while this function is waiting for an event.
|
|
2260
|
|
2261 The event returned will be a keyboard, mouse press, or mouse release event.
|
|
2262 If there are non-command events available (mouse motion, sub-process output,
|
|
2263 etc) then these will be executed (with `dispatch-event') and discarded. This
|
|
2264 function is provided as a convenience; it is equivalent to the lisp code
|
|
2265
|
|
2266 (while (progn
|
|
2267 (next-event event prompt)
|
|
2268 (not (or (key-press-event-p event)
|
|
2269 (button-press-event-p event)
|
|
2270 (button-release-event-p event)
|
|
2271 (misc-user-event-p event))))
|
|
2272 (dispatch-event event))
|
|
2273
|
20
|
2274 */
|
|
2275 (event, prompt))
|
0
|
2276 {
|
|
2277 /* This function can GC */
|
|
2278 struct gcpro gcpro1;
|
|
2279 GCPRO1 (event);
|
|
2280 maybe_echo_keys (XCOMMAND_BUILDER
|
|
2281 (XCONSOLE (Vselected_console)->
|
|
2282 command_builder), 0); /* #### This sucks bigtime */
|
|
2283 for (;;)
|
|
2284 {
|
|
2285 event = Fnext_event (event, prompt);
|
|
2286 if (command_event_p (event))
|
|
2287 break;
|
|
2288 else
|
|
2289 execute_internal_event (event);
|
|
2290 }
|
|
2291 UNGCPRO;
|
173
|
2292 return event;
|
0
|
2293 }
|
|
2294
|
|
2295 static void
|
|
2296 reset_current_events (struct command_builder *command_builder)
|
|
2297 {
|
|
2298 Lisp_Object event = command_builder->current_events;
|
|
2299 reset_command_builder_event_chain (command_builder);
|
|
2300 if (EVENTP (event))
|
|
2301 deallocate_event_chain (event);
|
|
2302 }
|
|
2303
|
20
|
2304 DEFUN ("discard-input", Fdiscard_input, 0, 0, 0, /*
|
185
|
2305 Discard any pending "user" events.
|
0
|
2306 Also cancel any kbd macro being defined.
|
|
2307 A user event is a key press, button press, button release, or
|
185
|
2308 "misc-user" event (menu selection or scrollbar action).
|
20
|
2309 */
|
|
2310 ())
|
0
|
2311 {
|
|
2312 /* This throws away user-input on the queue, but doesn't process any
|
|
2313 events. Calling dispatch_event() here leads to a race condition.
|
|
2314 */
|
189
|
2315 Lisp_Object event = Fmake_event (Qnil, Qnil);
|
0
|
2316 Lisp_Object head = Qnil, tail = Qnil;
|
|
2317 Lisp_Object oiq = Vinhibit_quit;
|
|
2318 struct gcpro gcpro1, gcpro2;
|
|
2319 /* #### not correct here with Vselected_console? Should
|
|
2320 discard-input take a console argument, or maybe map over
|
|
2321 all consoles? */
|
|
2322 struct console *con = XCONSOLE (Vselected_console);
|
|
2323
|
|
2324 /* next_event_internal() can cause arbitrary Lisp code to be evalled */
|
|
2325 GCPRO2 (event, oiq);
|
|
2326 Vinhibit_quit = Qt;
|
|
2327 /* If a macro was being defined then we have to mark the modeline
|
|
2328 has changed to ensure that it gets updated correctly. */
|
|
2329 if (!NILP (con->defining_kbd_macro))
|
|
2330 MARK_MODELINE_CHANGED;
|
|
2331 con->defining_kbd_macro = Qnil;
|
|
2332 reset_current_events (XCOMMAND_BUILDER (con->command_builder));
|
|
2333
|
|
2334 while (!NILP (command_event_queue)
|
|
2335 || event_stream_event_pending_p (1))
|
|
2336 {
|
|
2337 /* This will take stuff off the command_event_queue, or read it
|
|
2338 from the event_stream, but it will not block.
|
|
2339 */
|
108
|
2340 next_event_internal (event, 1);
|
0
|
2341 Vquit_flag = Qnil; /* Treat C-g as a user event (ignore it).
|
|
2342 It is vitally important that we reset
|
|
2343 Vquit_flag here. Otherwise, if we're
|
|
2344 reading from a TTY console,
|
|
2345 maybe_read_quit_event() will notice
|
|
2346 that C-g has been set and send us
|
|
2347 another C-g. That will cause us
|
|
2348 to get right back here, and read
|
|
2349 another C-g, ad infinitum ... */
|
|
2350
|
|
2351 /* If the event is a user event, ignore it. */
|
|
2352 if (!command_event_p (event))
|
|
2353 {
|
|
2354 /* Otherwise, chain the event onto our list of events not to ignore,
|
|
2355 and keep reading until the queue is empty. This does not mean
|
|
2356 that if a subprocess is generating an infinite amount of output,
|
|
2357 we will never terminate (*provided* that the behavior of
|
|
2358 next_event_cb() is correct -- see the comment in events.h),
|
|
2359 because this loop ends as soon as there are no more user events
|
|
2360 on the command_event_queue or event_stream.
|
|
2361 */
|
|
2362 enqueue_event (Fcopy_event (event, Qnil), &head, &tail);
|
|
2363 }
|
|
2364 }
|
|
2365
|
|
2366 if (!NILP (command_event_queue) || !NILP (command_event_queue_tail))
|
|
2367 abort ();
|
|
2368
|
|
2369 /* Now tack our chain of events back on to the front of the queue.
|
|
2370 Actually, since the queue is now drained, we can just replace it.
|
|
2371 The effect of this will be that we have deleted all user events
|
|
2372 from the input stream without changing the relative ordering of
|
|
2373 any other events. (Some events may have been taken from the
|
|
2374 event_stream and added to the command_event_queue, however.)
|
|
2375
|
|
2376 At this time, the command_event_queue will contain only eval_events.
|
|
2377 */
|
|
2378
|
|
2379 command_event_queue = head;
|
|
2380 command_event_queue_tail = tail;
|
|
2381
|
|
2382 Fdeallocate_event (event);
|
|
2383 UNGCPRO;
|
|
2384
|
|
2385 Vinhibit_quit = oiq;
|
|
2386 return Qnil;
|
|
2387 }
|
|
2388
|
|
2389
|
|
2390 /**********************************************************************/
|
|
2391 /* pausing until an action occurs */
|
|
2392 /**********************************************************************/
|
|
2393
|
108
|
2394 /* This is used in accept-process-output, sleep-for and sit-for.
|
|
2395 Before running any process_events in these routines, we set
|
|
2396 recursive_sit_for to Qt, and use this unwind protect to reset it to
|
110
|
2397 Qnil upon exit. When recursive_sit_for is Qt, calling sit-for will
|
|
2398 cause it to return immediately.
|
173
|
2399
|
108
|
2400 All of these routines install timeouts, so we clear the installed
|
|
2401 timeout as well.
|
|
2402
|
|
2403 Note: It's very easy to break the desired behaviours of these
|
|
2404 3 routines. If you make any changes to anything in this area, run
|
|
2405 the regression tests at the bottom of the file. -- dmoore */
|
173
|
2406
|
108
|
2407
|
|
2408 static Lisp_Object
|
|
2409 sit_for_unwind (Lisp_Object timeout_id)
|
|
2410 {
|
|
2411 if (!NILP(timeout_id))
|
|
2412 Fdisable_timeout (timeout_id);
|
|
2413
|
|
2414 recursive_sit_for = Qnil;
|
|
2415 return Qnil;
|
|
2416 }
|
|
2417
|
0
|
2418 /* #### Is (accept-process-output nil 3) supposed to be like (sleep-for 3)?
|
|
2419 */
|
|
2420
|
20
|
2421 DEFUN ("accept-process-output", Faccept_process_output, 0, 3, 0, /*
|
0
|
2422 Allow any pending output from subprocesses to be read by Emacs.
|
|
2423 It is read into the process' buffers or given to their filter functions.
|
|
2424 Non-nil arg PROCESS means do not return until some output has been received
|
86
|
2425 from PROCESS. Nil arg PROCESS means do not return until some output has
|
|
2426 been received from any process.
|
0
|
2427 If the second arg is non-nil, it is the maximum number of seconds to wait:
|
|
2428 this function will return after that much time even if no input has arrived
|
|
2429 from PROCESS. This argument may be a float, meaning wait some fractional
|
|
2430 part of a second.
|
|
2431 If the third arg is non-nil, it is a number of milliseconds that is added
|
|
2432 to the second arg. (This exists only for compatibility.)
|
|
2433 Return non-nil iff we received any output before the timeout expired.
|
20
|
2434 */
|
|
2435 (process, timeout_secs, timeout_msecs))
|
0
|
2436 {
|
|
2437 /* This function can GC */
|
|
2438 struct gcpro gcpro1, gcpro2;
|
|
2439 Lisp_Object event = Qnil;
|
|
2440 Lisp_Object result = Qnil;
|
173
|
2441 int timeout_id = -1;
|
0
|
2442 int timeout_enabled = 0;
|
86
|
2443 int done = 0;
|
0
|
2444 struct buffer *old_buffer = current_buffer;
|
108
|
2445 int count;
|
|
2446
|
0
|
2447 /* We preserve the current buffer but nothing else. If a focus
|
|
2448 change alters the selected window then the top level event loop
|
|
2449 will eventually alter current_buffer to match. In the mean time
|
|
2450 we don't want to mess up whatever called this function. */
|
|
2451
|
|
2452 if (!NILP (process))
|
|
2453 CHECK_PROCESS (process);
|
|
2454
|
|
2455 GCPRO2 (event, process);
|
|
2456
|
86
|
2457 if (!NILP (timeout_secs) || !NILP (timeout_msecs))
|
0
|
2458 {
|
|
2459 unsigned long msecs = 0;
|
|
2460 if (!NILP (timeout_secs))
|
|
2461 msecs = lisp_number_to_milliseconds (timeout_secs, 1);
|
|
2462 if (!NILP (timeout_msecs))
|
|
2463 {
|
|
2464 CHECK_NATNUM (timeout_msecs);
|
|
2465 msecs += XINT (timeout_msecs);
|
|
2466 }
|
|
2467 if (msecs)
|
|
2468 {
|
|
2469 timeout_id = event_stream_generate_wakeup (msecs, 0, Qnil, Qnil, 0);
|
|
2470 timeout_enabled = 1;
|
|
2471 }
|
|
2472 }
|
|
2473
|
189
|
2474 event = Fmake_event (Qnil, Qnil);
|
0
|
2475
|
108
|
2476 count = specpdl_depth ();
|
|
2477 record_unwind_protect (sit_for_unwind,
|
|
2478 timeout_enabled ? make_int (timeout_id) : Qnil);
|
|
2479 recursive_sit_for = Qt;
|
|
2480
|
86
|
2481 while (!done &&
|
|
2482 ((NILP (process) && timeout_enabled) ||
|
|
2483 (NILP (process) && event_stream_event_pending_p (0)) ||
|
|
2484 (!NILP (process))))
|
0
|
2485 /* Calling detect_input_pending() is the wrong thing here, because
|
|
2486 that considers the Vunread_command_events and command_event_queue.
|
|
2487 We don't need to look at the command_event_queue because we are
|
|
2488 only interested in process events, which don't go on that. In
|
|
2489 fact, we can't read from it anyway, because we put stuff on it.
|
|
2490
|
|
2491 Note that event_stream->event_pending_p must be called in such
|
|
2492 a way that it says whether any events *of any kind* are ready,
|
|
2493 not just user events, or (accept-process-output nil) will fail
|
|
2494 to dispatch any process events that may be on the queue. It is
|
|
2495 not clear to me that this is important, because the top-level
|
|
2496 loop will process it, and I don't think that there is ever a
|
|
2497 time when one calls accept-process-output with a nil argument
|
|
2498 and really need the processes to be handled. */
|
|
2499 {
|
74
|
2500 /* If our timeout has arrived, we move along. */
|
82
|
2501 if (timeout_enabled && !event_stream_wakeup_pending_p (timeout_id, 0))
|
74
|
2502 {
|
|
2503 timeout_enabled = 0;
|
86
|
2504 done = 1; /* We're done. */
|
|
2505 continue; /* Don't call next_event_internal */
|
74
|
2506 }
|
|
2507
|
0
|
2508 QUIT; /* next_event_internal() does not QUIT, so check for ^G
|
|
2509 before reading output from the process - this makes it
|
|
2510 less likely that the filter will actually be aborted.
|
|
2511 */
|
|
2512
|
108
|
2513 next_event_internal (event, 0);
|
0
|
2514 /* If C-g was pressed while we were waiting, Vquit_flag got
|
|
2515 set and next_event_internal() also returns C-g. When
|
|
2516 we enqueue the C-g below, it will get discarded. The
|
|
2517 next time through, QUIT will be called and will signal a quit. */
|
|
2518 switch (XEVENT_TYPE (event))
|
|
2519 {
|
|
2520 case process_event:
|
|
2521 {
|
86
|
2522 if (NILP (process) ||
|
|
2523 EQ (XEVENT (event)->event.process.process, process))
|
0
|
2524 {
|
86
|
2525 done = 1;
|
0
|
2526 /* RMS's version always returns nil when proc is nil,
|
|
2527 and only returns t if input ever arrived on proc. */
|
|
2528 result = Qt;
|
|
2529 }
|
|
2530
|
|
2531 execute_internal_event (event);
|
|
2532 break;
|
|
2533 }
|
|
2534 case timeout_event:
|
74
|
2535 /* We execute the event even if it's ours, and notice that it's
|
|
2536 happened above. */
|
0
|
2537 case pointer_motion_event:
|
|
2538 case magic_event:
|
|
2539 {
|
|
2540 execute_internal_event (event);
|
|
2541 break;
|
|
2542 }
|
|
2543 default:
|
|
2544 {
|
|
2545 enqueue_command_event_1 (event);
|
|
2546 break;
|
|
2547 }
|
|
2548 }
|
|
2549 }
|
|
2550
|
108
|
2551 unbind_to (count, timeout_enabled ? make_int (timeout_id) : Qnil);
|
0
|
2552
|
|
2553 Fdeallocate_event (event);
|
|
2554 UNGCPRO;
|
|
2555 current_buffer = old_buffer;
|
|
2556 return result;
|
|
2557 }
|
|
2558
|
20
|
2559 DEFUN ("sleep-for", Fsleep_for, 1, 1, 0, /*
|
0
|
2560 Pause, without updating display, for ARG seconds.
|
|
2561 ARG may be a float, meaning pause for some fractional part of a second.
|
108
|
2562
|
110
|
2563 It is recommended that you never call sleep-for from inside of a process
|
|
2564 filter function or timer event (either synchronous or asynchronous).
|
20
|
2565 */
|
|
2566 (seconds))
|
0
|
2567 {
|
|
2568 /* This function can GC */
|
|
2569 unsigned long msecs = lisp_number_to_milliseconds (seconds, 1);
|
|
2570 int id;
|
|
2571 Lisp_Object event = Qnil;
|
108
|
2572 int count;
|
0
|
2573 struct gcpro gcpro1;
|
|
2574
|
|
2575 GCPRO1 (event);
|
|
2576
|
|
2577 id = event_stream_generate_wakeup (msecs, 0, Qnil, Qnil, 0);
|
189
|
2578 event = Fmake_event (Qnil, Qnil);
|
108
|
2579
|
|
2580 count = specpdl_depth ();
|
|
2581 record_unwind_protect (sit_for_unwind, make_int (id));
|
|
2582 recursive_sit_for = Qt;
|
|
2583
|
0
|
2584 while (1)
|
|
2585 {
|
74
|
2586 /* If our timeout has arrived, we move along. */
|
|
2587 if (!event_stream_wakeup_pending_p (id, 0))
|
|
2588 goto DONE_LABEL;
|
|
2589
|
0
|
2590 QUIT; /* next_event_internal() does not QUIT, so check for ^G
|
|
2591 before reading output from the process - this makes it
|
|
2592 less likely that the filter will actually be aborted.
|
|
2593 */
|
|
2594 /* We're a generator of the command_event_queue, so we can't be a
|
|
2595 consumer as well. We don't care about command and eval-events
|
|
2596 anyway.
|
|
2597 */
|
108
|
2598 next_event_internal (event, 0); /* blocks */
|
0
|
2599 /* See the comment in accept-process-output about Vquit_flag */
|
|
2600 switch (XEVENT_TYPE (event))
|
|
2601 {
|
|
2602 case timeout_event:
|
74
|
2603 /* We execute the event even if it's ours, and notice that it's
|
|
2604 happened above. */
|
108
|
2605 case process_event:
|
0
|
2606 case pointer_motion_event:
|
|
2607 case magic_event:
|
|
2608 {
|
|
2609 execute_internal_event (event);
|
|
2610 break;
|
|
2611 }
|
|
2612 default:
|
|
2613 {
|
|
2614 enqueue_command_event_1 (event);
|
|
2615 break;
|
|
2616 }
|
|
2617 }
|
|
2618 }
|
|
2619 DONE_LABEL:
|
108
|
2620 unbind_to (count, make_int (id));
|
0
|
2621 Fdeallocate_event (event);
|
|
2622 UNGCPRO;
|
|
2623 return Qnil;
|
|
2624 }
|
|
2625
|
20
|
2626 DEFUN ("sit-for", Fsit_for, 1, 2, 0, /*
|
0
|
2627 Perform redisplay, then wait ARG seconds or until user input is available.
|
|
2628 ARG may be a float, meaning a fractional part of a second.
|
|
2629 Optional second arg non-nil means don't redisplay, just wait for input.
|
|
2630 Redisplay is preempted as always if user input arrives, and does not
|
108
|
2631 happen if input is available before it starts.
|
0
|
2632 Value is t if waited the full time with no input arriving.
|
108
|
2633
|
110
|
2634 If sit-for is called from within a process filter function or timer
|
|
2635 event (either synchronous or asynchronous) it will return immediately.
|
20
|
2636 */
|
|
2637 (seconds, nodisplay))
|
0
|
2638 {
|
|
2639 /* This function can GC */
|
|
2640 unsigned long msecs = lisp_number_to_milliseconds (seconds, 1);
|
|
2641 Lisp_Object event, result;
|
|
2642 struct gcpro gcpro1;
|
|
2643 int id;
|
108
|
2644 int count;
|
|
2645
|
0
|
2646 /* The unread-command-events count as pending input */
|
|
2647 if (!NILP (Vunread_command_events) || !NILP (Vunread_command_event))
|
|
2648 return Qnil;
|
|
2649
|
|
2650 /* If the command-builder already has user-input on it (not eval events)
|
|
2651 then that means we're done too.
|
|
2652 */
|
|
2653 if (!NILP (command_event_queue))
|
|
2654 {
|
|
2655 EVENT_CHAIN_LOOP (event, command_event_queue)
|
|
2656 {
|
|
2657 if (command_event_p (event))
|
173
|
2658 return Qnil;
|
0
|
2659 }
|
|
2660 }
|
|
2661
|
|
2662 /* If we're in a macro, or noninteractive, or early in temacs, then
|
|
2663 don't wait. */
|
|
2664 if (noninteractive || !NILP (Vexecuting_macro))
|
173
|
2665 return Qnil;
|
0
|
2666
|
110
|
2667 /* Recusive call from a filter function or timeout handler. */
|
|
2668 if (!NILP(recursive_sit_for))
|
|
2669 {
|
|
2670 if (!event_stream_event_pending_p (1) && NILP (nodisplay))
|
|
2671 {
|
|
2672 run_pre_idle_hook ();
|
|
2673 redisplay ();
|
|
2674 }
|
|
2675 return Qnil;
|
|
2676 }
|
|
2677
|
|
2678
|
0
|
2679 /* Otherwise, start reading events from the event_stream.
|
|
2680 Do this loop at least once even if (sit-for 0) so that we
|
|
2681 redisplay when no input pending.
|
|
2682 */
|
108
|
2683 GCPRO1 (event);
|
189
|
2684 event = Fmake_event (Qnil, Qnil);
|
0
|
2685
|
|
2686 /* Generate the wakeup even if MSECS is 0, so that existing timeout/etc.
|
|
2687 events get processed. The old (pre-19.12) code special-cased this
|
|
2688 and didn't generate a wakeup, but the resulting behavior was less than
|
|
2689 ideal; viz. the occurrence of (sit-for 0.001) scattered throughout
|
|
2690 the E-Lisp universe. */
|
|
2691
|
|
2692 id = event_stream_generate_wakeup (msecs, 0, Qnil, Qnil, 0);
|
|
2693
|
108
|
2694 count = specpdl_depth ();
|
|
2695 record_unwind_protect (sit_for_unwind, make_int (id));
|
|
2696 recursive_sit_for = Qt;
|
|
2697
|
0
|
2698 while (1)
|
|
2699 {
|
|
2700 /* If there is no user input pending, then redisplay.
|
|
2701 */
|
|
2702 if (!event_stream_event_pending_p (1) && NILP (nodisplay))
|
|
2703 {
|
|
2704 run_pre_idle_hook ();
|
|
2705 redisplay ();
|
|
2706 }
|
|
2707
|
74
|
2708 /* If our timeout has arrived, we move along. */
|
|
2709 if (!event_stream_wakeup_pending_p (id, 0))
|
0
|
2710 {
|
|
2711 result = Qt;
|
|
2712 goto DONE_LABEL;
|
|
2713 }
|
|
2714
|
|
2715 QUIT; /* next_event_internal() does not QUIT, so check for ^G
|
|
2716 before reading output from the process - this makes it
|
|
2717 less likely that the filter will actually be aborted.
|
|
2718 */
|
|
2719 /* We're a generator of the command_event_queue, so we can't be a
|
|
2720 consumer as well. In fact, we know there's nothing on the
|
|
2721 command_event_queue that we didn't just put there.
|
|
2722 */
|
108
|
2723 next_event_internal (event, 0); /* blocks */
|
0
|
2724 /* See the comment in accept-process-output about Vquit_flag */
|
|
2725
|
|
2726 if (command_event_p (event))
|
|
2727 {
|
108
|
2728 QUIT; /* If the command was C-g check it here
|
|
2729 so that we abort out of the sit-for,
|
|
2730 not the next command. sleep-for and
|
|
2731 accept-process-output continue looping
|
|
2732 so they check QUIT again implicitly.*/
|
0
|
2733 result = Qnil;
|
|
2734 goto DONE_LABEL;
|
|
2735 }
|
|
2736 switch (XEVENT_TYPE (event))
|
|
2737 {
|
|
2738 case eval_event:
|
|
2739 {
|
|
2740 /* eval-events get delayed until later. */
|
|
2741 enqueue_command_event (Fcopy_event (event, Qnil));
|
|
2742 break;
|
|
2743 }
|
173
|
2744
|
0
|
2745 case timeout_event:
|
74
|
2746 /* We execute the event even if it's ours, and notice that it's
|
|
2747 happened above. */
|
|
2748 default:
|
0
|
2749 {
|
|
2750 execute_internal_event (event);
|
|
2751 break;
|
|
2752 }
|
|
2753 }
|
|
2754 }
|
|
2755
|
|
2756 DONE_LABEL:
|
108
|
2757 unbind_to (count, make_int (id));
|
0
|
2758
|
|
2759 /* Put back the event (if any) that made Fsit_for() exit before the
|
|
2760 timeout. Note that it is being added to the back of the queue, which
|
|
2761 would be inappropriate if there were any user events on the queue
|
|
2762 already: we would be misordering them. But we know that there are
|
|
2763 no user-events on the queue, or else we would not have reached this
|
|
2764 point at all.
|
|
2765 */
|
|
2766 if (NILP (result))
|
|
2767 enqueue_command_event (event);
|
|
2768 else
|
|
2769 Fdeallocate_event (event);
|
|
2770
|
|
2771 UNGCPRO;
|
173
|
2772 return result;
|
0
|
2773 }
|
|
2774
|
|
2775 /* This handy little function is used by xselect.c and energize.c to
|
|
2776 wait for replies from processes that aren't really processes (that is,
|
|
2777 the X server and the Energize server).
|
|
2778 */
|
|
2779 void
|
|
2780 wait_delaying_user_input (int (*predicate) (void *arg), void *predicate_arg)
|
|
2781 {
|
|
2782 /* This function can GC */
|
189
|
2783 Lisp_Object event = Fmake_event (Qnil, Qnil);
|
0
|
2784 struct gcpro gcpro1;
|
|
2785 GCPRO1 (event);
|
|
2786
|
|
2787 while (!(*predicate) (predicate_arg))
|
|
2788 {
|
|
2789 QUIT; /* next_event_internal() does not QUIT. */
|
|
2790
|
|
2791 /* We're a generator of the command_event_queue, so we can't be a
|
|
2792 consumer as well. Also, we have no reason to consult the
|
|
2793 command_event_queue; there are only user and eval-events there,
|
|
2794 and we'd just have to put them back anyway.
|
|
2795 */
|
108
|
2796 next_event_internal (event, 0);
|
0
|
2797 /* See the comment in accept-process-output about Vquit_flag */
|
|
2798 if (command_event_p (event)
|
|
2799 || (XEVENT_TYPE (event) == eval_event)
|
|
2800 || (XEVENT_TYPE (event) == magic_eval_event))
|
|
2801 enqueue_command_event_1 (event);
|
|
2802 else
|
|
2803 execute_internal_event (event);
|
|
2804 }
|
|
2805 UNGCPRO;
|
|
2806 }
|
|
2807
|
|
2808
|
|
2809 /**********************************************************************/
|
|
2810 /* dispatching events; command builder */
|
|
2811 /**********************************************************************/
|
|
2812
|
|
2813 static void
|
|
2814 execute_internal_event (Lisp_Object event)
|
|
2815 {
|
|
2816 /* events on dead channels get silently eaten */
|
|
2817 if (object_dead_p (XEVENT (event)->channel))
|
|
2818 return;
|
|
2819
|
|
2820 /* This function can GC */
|
173
|
2821 switch (XEVENT_TYPE (event))
|
0
|
2822 {
|
|
2823 case empty_event:
|
|
2824 return;
|
|
2825
|
|
2826 case eval_event:
|
|
2827 {
|
173
|
2828 call1 (XEVENT (event)->event.eval.function,
|
0
|
2829 XEVENT (event)->event.eval.object);
|
|
2830 return;
|
|
2831 }
|
|
2832
|
|
2833 case magic_eval_event:
|
|
2834 {
|
|
2835 (XEVENT (event)->event.magic_eval.internal_function)
|
|
2836 (XEVENT (event)->event.magic_eval.object);
|
|
2837 return;
|
|
2838 }
|
|
2839
|
|
2840 case pointer_motion_event:
|
|
2841 {
|
|
2842 if (!NILP (Vmouse_motion_handler))
|
|
2843 call1 (Vmouse_motion_handler, event);
|
|
2844 return;
|
|
2845 }
|
|
2846
|
|
2847 case process_event:
|
|
2848 {
|
|
2849 Lisp_Object p = XEVENT (event)->event.process.process;
|
|
2850 Charcount readstatus;
|
|
2851
|
|
2852 assert (PROCESSP (p));
|
|
2853 while ((readstatus = read_process_output (p)) > 0)
|
|
2854 ;
|
|
2855 if (readstatus > 0)
|
|
2856 ; /* this clauses never gets executed but allows the #ifdefs
|
|
2857 to work cleanly. */
|
|
2858 #ifdef EWOULDBLOCK
|
|
2859 else if (readstatus == -1 && errno == EWOULDBLOCK)
|
|
2860 ;
|
|
2861 #endif /* EWOULDBLOCK */
|
|
2862 #ifdef EAGAIN
|
|
2863 else if (readstatus == -1 && errno == EAGAIN)
|
|
2864 ;
|
|
2865 #endif /* EAGAIN */
|
173
|
2866 else if ((readstatus == 0 &&
|
0
|
2867 /* Note that we cannot distinguish between no input
|
|
2868 available now and a closed pipe.
|
|
2869 With luck, a closed pipe will be accompanied by
|
|
2870 subprocess termination and SIGCHLD. */
|
|
2871 (!network_connection_p (p) ||
|
|
2872 /*
|
|
2873 When connected to ToolTalk (i.e.
|
|
2874 connected_via_filedesc_p()), it's not possible to
|
|
2875 reliably determine whether there is a message
|
|
2876 waiting for ToolTalk to receive. ToolTalk expects
|
|
2877 to have tt_message_receive() called exactly once
|
|
2878 every time the file descriptor becomes active, so
|
|
2879 the filter function forces this by returning 0.
|
|
2880 Emacs must not interpret this as a closed pipe. */
|
|
2881 connected_via_filedesc_p (XPROCESS (p))))
|
|
2882 #ifdef HAVE_PTYS
|
|
2883 /* On some OSs with ptys, when the process on one end of
|
|
2884 a pty exits, the other end gets an error reading with
|
|
2885 errno = EIO instead of getting an EOF (0 bytes read).
|
|
2886 Therefore, if we get an error reading and errno =
|
|
2887 EIO, just continue, because the child process has
|
|
2888 exited and should clean itself up soon (e.g. when we
|
|
2889 get a SIGCHLD). */
|
|
2890 || (readstatus == -1 && errno == EIO)
|
|
2891 #endif
|
|
2892 )
|
|
2893 {
|
80
|
2894 /* Currently, we rely on SIGCHLD to indicate that the
|
|
2895 process has terminated. Unfortunately, on some systems
|
|
2896 the SIGCHLD gets missed some of the time. So we put an
|
|
2897 additional check in status_notify() to see whether a
|
|
2898 process has terminated. We must tell status_notify()
|
|
2899 to enable that check, and we do so now. */
|
0
|
2900 kick_status_notify ();
|
|
2901 }
|
|
2902 else
|
|
2903 {
|
|
2904 /* Deactivate network connection */
|
|
2905 Lisp_Object status = Fprocess_status (p);
|
|
2906 if (EQ (status, Qopen)
|
|
2907 /* In case somebody changes the theory of whether to
|
|
2908 return open as opposed to run for network connection
|
|
2909 "processes"... */
|
|
2910 || EQ (status, Qrun))
|
|
2911 update_process_status (p, Qexit, 256, 0);
|
|
2912 deactivate_process (p);
|
|
2913 }
|
|
2914
|
|
2915 /* We must call status_notify here to allow the
|
|
2916 event_stream->unselect_process_cb to be run if appropriate.
|
|
2917 Otherwise, dead fds may be selected for, and we will get a
|
|
2918 continuous stream of process events for them. Since we don't
|
|
2919 return until all process events have been flushed, we would
|
|
2920 get stuck here, processing events on a process whose status
|
|
2921 was 'exit. Call this after dispatch-event, or the fds will
|
|
2922 have been closed before we read the last data from them.
|
|
2923 It's safe for the filter to signal an error because
|
|
2924 status_notify() will be called on return to top-level.
|
|
2925 */
|
|
2926 status_notify ();
|
|
2927 return;
|
|
2928 }
|
|
2929
|
|
2930 case timeout_event:
|
|
2931 {
|
|
2932 struct Lisp_Event *e = XEVENT (event);
|
|
2933 if (!NILP (e->event.timeout.function))
|
|
2934 call1 (e->event.timeout.function,
|
|
2935 e->event.timeout.object);
|
|
2936 return;
|
|
2937 }
|
|
2938 case magic_event:
|
|
2939 {
|
|
2940 event_stream_handle_magic_event (XEVENT (event));
|
|
2941 return;
|
|
2942 }
|
|
2943 default:
|
|
2944 abort ();
|
|
2945 }
|
|
2946 }
|
|
2947
|
|
2948
|
|
2949
|
|
2950 static void
|
|
2951 this_command_keys_replace_suffix (Lisp_Object suffix, Lisp_Object chain)
|
|
2952 {
|
|
2953 Lisp_Object first_before_suffix =
|
|
2954 event_chain_find_previous (Vthis_command_keys, suffix);
|
|
2955
|
|
2956 if (NILP (first_before_suffix))
|
|
2957 Vthis_command_keys = chain;
|
|
2958 else
|
|
2959 XSET_EVENT_NEXT (first_before_suffix, chain);
|
|
2960 deallocate_event_chain (suffix);
|
|
2961 Vthis_command_keys_tail = event_chain_tail (chain);
|
|
2962 }
|
|
2963
|
|
2964 static void
|
|
2965 command_builder_replace_suffix (struct command_builder *builder,
|
|
2966 Lisp_Object suffix, Lisp_Object chain)
|
|
2967 {
|
|
2968 Lisp_Object first_before_suffix =
|
|
2969 event_chain_find_previous (builder->current_events, suffix);
|
|
2970
|
|
2971 if (NILP (first_before_suffix))
|
|
2972 builder->current_events = chain;
|
|
2973 else
|
|
2974 XSET_EVENT_NEXT (first_before_suffix, chain);
|
|
2975 deallocate_event_chain (suffix);
|
|
2976 builder->most_current_event = event_chain_tail (chain);
|
|
2977 }
|
|
2978
|
|
2979 static Lisp_Object
|
|
2980 command_builder_find_leaf_1 (struct command_builder *builder)
|
|
2981 {
|
|
2982 Lisp_Object event0 = builder->current_events;
|
|
2983
|
|
2984 if (NILP (event0))
|
173
|
2985 return Qnil;
|
0
|
2986
|
|
2987 return event_binding (event0, 1);
|
|
2988 }
|
|
2989
|
177
|
2990 #if defined(HAVE_X_WINDOWS) && defined(HAVE_MENUBARS)
|
175
|
2991 static void
|
|
2992 menu_move_up (void)
|
|
2993 {
|
|
2994 widget_value *current, *prev;
|
|
2995 widget_value *entries;
|
185
|
2996
|
175
|
2997 current = lw_get_entries (False);
|
|
2998 entries = lw_get_entries (True);
|
|
2999 prev = NULL;
|
|
3000 if (current != entries)
|
|
3001 {
|
|
3002 while (entries != current)
|
|
3003 {
|
|
3004 if (entries->name /*&& entries->enabled*/) prev = entries;
|
|
3005 entries = entries->next;
|
|
3006 assert (entries);
|
|
3007 }
|
|
3008 }
|
|
3009
|
|
3010 if (!prev)
|
|
3011 /* move to last item */
|
|
3012 {
|
|
3013 while (entries->next)
|
|
3014 {
|
|
3015 if (entries->name /*&& entries->enabled*/) prev = entries;
|
|
3016 entries = entries->next;
|
|
3017 }
|
|
3018 if (prev)
|
|
3019 {
|
|
3020 if (entries->name /*&& entries->enabled*/)
|
|
3021 prev = entries;
|
|
3022 }
|
|
3023 else
|
|
3024 {
|
|
3025 /* no selectable items in this menu, pop up to previous level */
|
|
3026 lw_pop_menu ();
|
|
3027 return;
|
|
3028 }
|
|
3029 }
|
|
3030 lw_set_item (prev);
|
|
3031 }
|
|
3032
|
|
3033 static void
|
|
3034 menu_move_down (void)
|
|
3035 {
|
|
3036 widget_value *current;
|
|
3037 widget_value *new;
|
185
|
3038
|
175
|
3039 current = lw_get_entries (False);
|
|
3040 new = current;
|
185
|
3041
|
175
|
3042 while (new->next)
|
|
3043 {
|
|
3044 new = new->next;
|
|
3045 if (new->name /*&& new->enabled*/) break;
|
|
3046 }
|
185
|
3047
|
175
|
3048 if (new==current||!(new->name/*||new->enabled*/))
|
|
3049 {
|
|
3050 new = lw_get_entries (True);
|
|
3051 while (new!=current)
|
|
3052 {
|
|
3053 if (new->name /*&& new->enabled*/) break;
|
|
3054 new = new->next;
|
|
3055 }
|
|
3056 if (new==current&&!(new->name /*|| new->enabled*/))
|
|
3057 {
|
|
3058 lw_pop_menu ();
|
|
3059 return;
|
|
3060 }
|
|
3061 }
|
185
|
3062
|
175
|
3063 lw_set_item (new);
|
|
3064 }
|
|
3065
|
|
3066 static void
|
|
3067 menu_move_left (void)
|
|
3068 {
|
|
3069 int level = lw_menu_level ();
|
|
3070 int l = level;
|
|
3071 widget_value *current;
|
185
|
3072
|
175
|
3073 while (level >= 3)
|
|
3074 {
|
|
3075 --level;
|
|
3076 lw_pop_menu ();
|
|
3077 }
|
|
3078 menu_move_up ();
|
|
3079 current = lw_get_entries (False);
|
|
3080 if (l > 2 && current->contents)
|
|
3081 lw_push_menu (current->contents);
|
|
3082 }
|
|
3083
|
|
3084 static void
|
|
3085 menu_move_right (void)
|
|
3086 {
|
|
3087 int level = lw_menu_level ();
|
|
3088 int l = level;
|
|
3089 widget_value *current;
|
185
|
3090
|
175
|
3091 while (level >= 3)
|
|
3092 {
|
|
3093 --level;
|
|
3094 lw_pop_menu ();
|
|
3095 }
|
|
3096 menu_move_down ();
|
|
3097 current = lw_get_entries (False);
|
|
3098 if (l > 2 && current->contents)
|
|
3099 lw_push_menu (current->contents);
|
|
3100 }
|
|
3101
|
|
3102 static void
|
|
3103 menu_select_item (widget_value *val)
|
|
3104 {
|
|
3105 if (val == NULL)
|
|
3106 val = lw_get_entries (False);
|
185
|
3107
|
175
|
3108 /* is match a submenu? */
|
185
|
3109
|
175
|
3110 if (val->contents)
|
|
3111 {
|
|
3112 /* enter the submenu */
|
185
|
3113
|
175
|
3114 lw_set_item (val);
|
|
3115 lw_push_menu (val->contents);
|
|
3116 }
|
|
3117 else
|
|
3118 {
|
|
3119 /* Execute the menu entry by calling the menu's `select'
|
|
3120 callback function
|
|
3121 */
|
|
3122 lw_kill_menus (val);
|
|
3123 }
|
|
3124 }
|
|
3125
|
|
3126 static Lisp_Object
|
|
3127 command_builder_operate_menu_accelerator (struct command_builder *builder)
|
|
3128 {
|
|
3129 /* this function can GC */
|
185
|
3130
|
175
|
3131 struct console *con = XCONSOLE (Vselected_console);
|
|
3132 Lisp_Object evee = builder->most_current_event;
|
|
3133 Lisp_Object binding;
|
|
3134 widget_value *entries;
|
185
|
3135
|
175
|
3136 extern int lw_menu_accelerate; /* lwlib.c */
|
|
3137
|
|
3138 #if 0
|
|
3139 {
|
|
3140 int i;
|
|
3141 Lisp_Object t;
|
|
3142 char buf[50];
|
185
|
3143
|
175
|
3144 t = builder->current_events;
|
|
3145 i = 0;
|
|
3146 while (!NILP (t))
|
|
3147 {
|
|
3148 i++;
|
|
3149 sprintf(buf,"OPERATE (%d): ",i);
|
|
3150 write_c_string (buf,Qexternal_debugging_output);
|
|
3151 print_internal (t, Qexternal_debugging_output, 1);
|
|
3152 write_c_string ("\n", Qexternal_debugging_output);
|
|
3153 t = XEVENT_NEXT (t);
|
|
3154 }
|
|
3155 }
|
|
3156 #endif
|
185
|
3157
|
175
|
3158 /* menu accelerator keys don't go into keyboard macros */
|
|
3159 if (!NILP (con->defining_kbd_macro) && NILP (Vexecuting_macro))
|
|
3160 con->kbd_macro_ptr = con->kbd_macro_end;
|
185
|
3161
|
175
|
3162 /* don't echo menu accelerator keys */
|
|
3163 /*reset_key_echo (builder, 1);*/
|
185
|
3164
|
175
|
3165 if (!lw_menu_accelerate)
|
|
3166 {
|
|
3167 /* `convert' mouse display to keyboard display
|
|
3168 by entering the open submenu
|
|
3169 */
|
|
3170 entries = lw_get_entries (False);
|
|
3171 if (entries->contents)
|
|
3172 {
|
|
3173 lw_push_menu (entries->contents);
|
|
3174 lw_display_menu (CurrentTime);
|
|
3175 }
|
|
3176 }
|
185
|
3177
|
175
|
3178 /* compare event to the current menu accelerators */
|
185
|
3179
|
175
|
3180 entries=lw_get_entries (True);
|
185
|
3181
|
175
|
3182 while (entries)
|
|
3183 {
|
|
3184 Lisp_Object accel;
|
|
3185 VOID_TO_LISP (accel, entries->accel);
|
|
3186 if (entries->name && !NILP (accel))
|
|
3187 {
|
|
3188 if (event_matches_key_specifier_p (XEVENT (evee), accel))
|
|
3189 {
|
|
3190 /* a match! */
|
185
|
3191
|
175
|
3192 menu_select_item (entries);
|
185
|
3193
|
175
|
3194 if (lw_menu_active) lw_display_menu (CurrentTime);
|
185
|
3195
|
175
|
3196 reset_this_command_keys (Vselected_console, 1);
|
|
3197 /*reset_command_builder_event_chain (builder);*/
|
|
3198 return Vmenu_accelerator_map;
|
|
3199 }
|
|
3200 }
|
|
3201 entries = entries->next;
|
|
3202 }
|
185
|
3203
|
175
|
3204 /* try to look up event in menu-accelerator-map */
|
185
|
3205
|
175
|
3206 binding = event_binding_in (evee, Vmenu_accelerator_map, 1);
|
185
|
3207
|
175
|
3208 if (NILP (binding))
|
|
3209 {
|
|
3210 /* beep at user for undefined key */
|
|
3211 return Qnil;
|
|
3212 }
|
|
3213 else
|
|
3214 {
|
|
3215 if (EQ (binding, Qmenu_quit))
|
|
3216 {
|
|
3217 /* turn off menus and set quit flag */
|
|
3218 lw_kill_menus (NULL);
|
|
3219 Vquit_flag = Qt;
|
|
3220 }
|
|
3221 else if (EQ (binding, Qmenu_up))
|
|
3222 {
|
|
3223 int level = lw_menu_level ();
|
|
3224 if (level > 2)
|
|
3225 menu_move_up ();
|
|
3226 }
|
|
3227 else if (EQ (binding, Qmenu_down))
|
|
3228 {
|
|
3229 int level = lw_menu_level ();
|
|
3230 if (level > 2)
|
|
3231 menu_move_down ();
|
|
3232 else
|
|
3233 menu_select_item (NULL);
|
|
3234 }
|
|
3235 else if (EQ (binding, Qmenu_left))
|
|
3236 {
|
|
3237 int level = lw_menu_level ();
|
|
3238 if (level > 3)
|
|
3239 {
|
|
3240 lw_pop_menu ();
|
|
3241 lw_display_menu (CurrentTime);
|
|
3242 }
|
|
3243 else
|
|
3244 menu_move_left ();
|
|
3245 }
|
|
3246 else if (EQ (binding, Qmenu_right))
|
|
3247 {
|
|
3248 int level = lw_menu_level ();
|
|
3249 if (level > 2 &&
|
|
3250 lw_get_entries (False)->contents)
|
|
3251 {
|
|
3252 widget_value *current = lw_get_entries (False);
|
|
3253 if (current->contents)
|
|
3254 menu_select_item (NULL);
|
|
3255 }
|
|
3256 else
|
|
3257 menu_move_right ();
|
|
3258 }
|
|
3259 else if (EQ (binding, Qmenu_select))
|
|
3260 menu_select_item (NULL);
|
|
3261 else if (EQ (binding, Qmenu_escape))
|
|
3262 {
|
|
3263 int level = lw_menu_level ();
|
185
|
3264
|
175
|
3265 if (level > 2)
|
|
3266 {
|
|
3267 lw_pop_menu ();
|
|
3268 lw_display_menu (CurrentTime);
|
|
3269 }
|
|
3270 else
|
|
3271 {
|
|
3272 /* turn off menus quietly */
|
|
3273 lw_kill_menus (NULL);
|
|
3274 }
|
|
3275 }
|
|
3276 else if (KEYMAPP (binding))
|
|
3277 {
|
|
3278 /* prefix key */
|
|
3279 reset_this_command_keys (Vselected_console, 1);
|
|
3280 /*reset_command_builder_event_chain (builder);*/
|
|
3281 return binding;
|
|
3282 }
|
|
3283 else
|
|
3284 {
|
|
3285 /* turn off menus and execute binding */
|
|
3286 lw_kill_menus (NULL);
|
|
3287 reset_this_command_keys (Vselected_console, 1);
|
|
3288 /*reset_command_builder_event_chain (builder);*/
|
|
3289 return binding;
|
|
3290 }
|
|
3291 }
|
185
|
3292
|
175
|
3293 if (lw_menu_active) lw_display_menu (CurrentTime);
|
185
|
3294
|
175
|
3295 reset_this_command_keys (Vselected_console, 1);
|
|
3296 /*reset_command_builder_event_chain (builder);*/
|
185
|
3297
|
175
|
3298 return Vmenu_accelerator_map;
|
|
3299 }
|
|
3300
|
|
3301 static Lisp_Object
|
|
3302 menu_accelerator_junk_on_error (Lisp_Object errordata, Lisp_Object ignored)
|
|
3303 {
|
185
|
3304 Vmenu_accelerator_prefix = Qnil;
|
175
|
3305 Vmenu_accelerator_modifiers = Qnil;
|
185
|
3306 Vmenu_accelerator_enabled = Qnil;
|
175
|
3307 if (!NILP (errordata))
|
|
3308 {
|
|
3309 Lisp_Object args[2];
|
185
|
3310
|
175
|
3311 args[0] = build_string ("Error in menu accelerators (setting to nil)");
|
|
3312 /* #### This should call
|
|
3313 (with-output-to-string (display-error errordata))
|
|
3314 but that stuff is all in Lisp currently. */
|
|
3315 args[1] = errordata;
|
|
3316 warn_when_safe_lispobj
|
|
3317 (Qerror, Qwarning,
|
|
3318 emacs_doprnt_string_lisp ((CONST Bufbyte *) "%s: %s",
|
|
3319 Qnil, -1, 2, args));
|
|
3320 }
|
185
|
3321
|
175
|
3322 return Qnil;
|
|
3323 }
|
|
3324
|
|
3325 static Lisp_Object
|
|
3326 menu_accelerator_safe_compare (Lisp_Object event0)
|
|
3327 {
|
|
3328 if (CONSP (Vmenu_accelerator_prefix))
|
|
3329 {
|
|
3330 Lisp_Object t;
|
|
3331 t=Vmenu_accelerator_prefix;
|
|
3332 while (!NILP (t)
|
|
3333 && !NILP (event0)
|
|
3334 && event_matches_key_specifier_p (XEVENT (event0), Fcar (t)))
|
|
3335 {
|
|
3336 t = Fcdr (t);
|
|
3337 event0 = XEVENT_NEXT (event0);
|
|
3338 }
|
|
3339 if (!NILP (t))
|
|
3340 return Qnil;
|
|
3341 }
|
|
3342 else if (NILP (event0))
|
|
3343 return Qnil;
|
|
3344 else if (event_matches_key_specifier_p (XEVENT (event0), Vmenu_accelerator_prefix))
|
|
3345 event0 = XEVENT_NEXT (event0);
|
|
3346 else
|
|
3347 return Qnil;
|
|
3348 return event0;
|
|
3349 }
|
|
3350
|
|
3351 static Lisp_Object
|
|
3352 menu_accelerator_safe_mod_compare (Lisp_Object cons)
|
|
3353 {
|
|
3354 return (event_matches_key_specifier_p (XEVENT (XCAR (cons)), XCDR (cons))
|
|
3355 ? Qt
|
|
3356 : Qnil);
|
|
3357 }
|
|
3358
|
|
3359 static Lisp_Object
|
|
3360 command_builder_find_menu_accelerator (struct command_builder *builder)
|
|
3361 {
|
|
3362 /* this function can GC */
|
|
3363 Lisp_Object event0 = builder->current_events;
|
|
3364 struct console *con = XCONSOLE (Vselected_console);
|
|
3365 struct frame *f = XFRAME (CONSOLE_SELECTED_FRAME (con));
|
|
3366 Widget menubar_widget;
|
185
|
3367
|
175
|
3368 /* compare entries in event0 against the menu prefix */
|
185
|
3369
|
175
|
3370 if ((!CONSOLE_X_P (XCONSOLE (builder->console))) || NILP (event0) ||
|
|
3371 XEVENT (event0)->event_type != key_press_event)
|
|
3372 return Qnil;
|
185
|
3373
|
175
|
3374 if (!NILP (Vmenu_accelerator_prefix))
|
|
3375 {
|
|
3376 event0 = condition_case_1 (Qerror,
|
|
3377 menu_accelerator_safe_compare,
|
|
3378 event0,
|
|
3379 menu_accelerator_junk_on_error,
|
|
3380 Qnil);
|
|
3381 }
|
185
|
3382
|
175
|
3383 if (NILP (event0))
|
|
3384 return Qnil;
|
185
|
3385
|
175
|
3386 menubar_widget = FRAME_X_MENUBAR_WIDGET (f);
|
|
3387 if (menubar_widget
|
|
3388 && CONSP (Vmenu_accelerator_modifiers))
|
|
3389 {
|
|
3390 Lisp_Object fake;
|
185
|
3391 Lisp_Object last = Qnil;
|
175
|
3392 struct gcpro gcpro1;
|
|
3393 Lisp_Object matchp;
|
185
|
3394
|
175
|
3395 widget_value *val;
|
|
3396 LWLIB_ID id = XPOPUP_DATA (f->menubar_data)->id;
|
185
|
3397
|
175
|
3398 val = lw_get_all_values (id);
|
|
3399 if (val)
|
|
3400 {
|
|
3401 val = val->contents;
|
185
|
3402
|
175
|
3403 fake = Fcopy_sequence (Vmenu_accelerator_modifiers);
|
|
3404 last = fake;
|
185
|
3405
|
175
|
3406 while (!NILP (Fcdr (last)))
|
|
3407 last = Fcdr (last);
|
185
|
3408
|
175
|
3409 Fsetcdr (last, Fcons (Qnil, Qnil));
|
|
3410 last = Fcdr (last);
|
|
3411 }
|
185
|
3412
|
175
|
3413 fake = Fcons (Qnil, fake);
|
185
|
3414
|
175
|
3415 GCPRO1 (fake);
|
|
3416
|
|
3417 while (val)
|
|
3418 {
|
|
3419 Lisp_Object accel;
|
|
3420 VOID_TO_LISP (accel, val->accel);
|
|
3421 if (val->name && !NILP (accel))
|
|
3422 {
|
|
3423 Fsetcar (last, accel);
|
|
3424 Fsetcar (fake, event0);
|
|
3425 matchp = condition_case_1 (Qerror,
|
|
3426 menu_accelerator_safe_mod_compare,
|
|
3427 fake,
|
|
3428 menu_accelerator_junk_on_error,
|
|
3429 Qnil);
|
|
3430 if (!NILP (matchp))
|
|
3431 {
|
|
3432 /* we found one! */
|
185
|
3433
|
175
|
3434 lw_set_menu (menubar_widget, val);
|
|
3435 /* yah - yet another hack.
|
|
3436 pretend emacs timestamp is the same as an X timestamp,
|
|
3437 which for the moment it is. (read events.h)
|
|
3438 */
|
|
3439 lw_map_menu (XEVENT (event0)->timestamp);
|
185
|
3440
|
175
|
3441 if (val->contents)
|
|
3442 lw_push_menu (val->contents);
|
185
|
3443
|
175
|
3444 lw_display_menu (CurrentTime);
|
185
|
3445
|
175
|
3446 /* menu accelerator keys don't go into keyboard macros */
|
|
3447 if (!NILP (con->defining_kbd_macro) && NILP (Vexecuting_macro))
|
|
3448 con->kbd_macro_ptr = con->kbd_macro_end;
|
185
|
3449
|
175
|
3450 /* don't echo menu accelerator keys */
|
|
3451 /*reset_key_echo (builder, 1);*/
|
|
3452 reset_this_command_keys (Vselected_console, 1);
|
|
3453 UNGCPRO;
|
185
|
3454
|
175
|
3455 return Vmenu_accelerator_map;
|
|
3456 }
|
|
3457 }
|
185
|
3458
|
175
|
3459 val = val->next;
|
|
3460 }
|
185
|
3461
|
175
|
3462 UNGCPRO;
|
|
3463 }
|
|
3464 return Qnil;
|
|
3465 }
|
|
3466
|
177
|
3467
|
|
3468 DEFUN ("accelerate-menu", Faccelerate_menu, 0, 0, "_", /*
|
|
3469 Make the menubar active. Menu items can be selected using menu accelerators
|
|
3470 or by actions defined in menu-accelerator-map.
|
|
3471 */
|
|
3472 ())
|
175
|
3473 {
|
|
3474 struct console *con = XCONSOLE (Vselected_console);
|
|
3475 struct frame *f = XFRAME (CONSOLE_SELECTED_FRAME (con));
|
|
3476 LWLIB_ID id = XPOPUP_DATA (f->menubar_data)->id;
|
|
3477 widget_value *val = lw_get_all_values (id);
|
185
|
3478
|
175
|
3479 val = val->contents;
|
|
3480 lw_set_menu (FRAME_X_MENUBAR_WIDGET (f), val);
|
|
3481 lw_map_menu (CurrentTime);
|
185
|
3482
|
175
|
3483 lw_display_menu (CurrentTime);
|
185
|
3484
|
175
|
3485 /* menu accelerator keys don't go into keyboard macros */
|
|
3486 if (!NILP (con->defining_kbd_macro) && NILP (Vexecuting_macro))
|
|
3487 con->kbd_macro_ptr = con->kbd_macro_end;
|
185
|
3488
|
177
|
3489 return Qnil;
|
175
|
3490 }
|
177
|
3491 #endif /* HAVE_X_WINDOWS && HAVE_MENUBARS */
|
175
|
3492
|
0
|
3493 /* See if we can do function-key-map or key-translation-map translation
|
|
3494 on the current events in the command builder. If so, do this, and
|
|
3495 return the resulting binding, if any. */
|
|
3496
|
|
3497 static Lisp_Object
|
|
3498 munge_keymap_translate (struct command_builder *builder,
|
|
3499 enum munge_me_out_the_door munge,
|
|
3500 int has_normal_binding_p)
|
|
3501 {
|
|
3502 Lisp_Object suffix;
|
173
|
3503
|
0
|
3504 EVENT_CHAIN_LOOP (suffix, builder->munge_me[munge].first_mungeable_event)
|
|
3505 {
|
|
3506 Lisp_Object result = munging_key_map_event_binding (suffix, munge);
|
173
|
3507
|
185
|
3508 if (NILP (result))
|
|
3509 continue;
|
|
3510
|
|
3511 if (KEYMAPP (result))
|
|
3512 {
|
|
3513 if (NILP (builder->last_non_munged_event)
|
|
3514 && !has_normal_binding_p)
|
|
3515 builder->last_non_munged_event = builder->most_current_event;
|
|
3516 }
|
|
3517 else
|
|
3518 builder->last_non_munged_event = Qnil;
|
|
3519
|
|
3520 if (!KEYMAPP (result) &&
|
|
3521 !VECTORP (result) &&
|
|
3522 !STRINGP (result))
|
0
|
3523 {
|
185
|
3524 struct gcpro gcpro1;
|
|
3525 GCPRO1 (suffix);
|
|
3526 result = call1 (result, Qnil);
|
|
3527 UNGCPRO;
|
|
3528 if (NILP (result))
|
|
3529 return Qnil;
|
|
3530 }
|
|
3531
|
|
3532 if (KEYMAPP (result))
|
|
3533 return result;
|
|
3534
|
|
3535 if (VECTORP (result) || STRINGP (result))
|
|
3536 {
|
|
3537 Lisp_Object new_chain = key_sequence_to_event_chain (result);
|
|
3538 Lisp_Object tempev;
|
|
3539 int n, tckn;
|
|
3540
|
|
3541 /* If the first_mungeable_event of the other munger is
|
|
3542 within the events we're munging, then it will point to
|
|
3543 deallocated events afterwards, which is bad -- so make it
|
|
3544 point at the beginning of the munged events. */
|
|
3545 EVENT_CHAIN_LOOP (tempev, suffix)
|
0
|
3546 {
|
185
|
3547 Lisp_Object *mungeable_event =
|
|
3548 &builder->munge_me[1 - munge].first_mungeable_event;
|
|
3549 if (EQ (tempev, *mungeable_event))
|
0
|
3550 {
|
185
|
3551 *mungeable_event = new_chain;
|
|
3552 break;
|
0
|
3553 }
|
|
3554 }
|
|
3555
|
185
|
3556 n = event_chain_count (suffix);
|
|
3557 command_builder_replace_suffix (builder, suffix, new_chain);
|
|
3558 builder->munge_me[munge].first_mungeable_event = Qnil;
|
|
3559 /* Now hork this-command-keys as well. */
|
|
3560
|
|
3561 /* We just assume that the events we just replaced are
|
|
3562 sitting in copied form at the end of this-command-keys.
|
|
3563 If the user did weird things with `dispatch-event' this
|
|
3564 may not be the case, but at least we make sure we won't
|
|
3565 crash. */
|
|
3566 new_chain = copy_event_chain (new_chain);
|
|
3567 tckn = event_chain_count (Vthis_command_keys);
|
|
3568 if (tckn >= n)
|
|
3569 {
|
|
3570 this_command_keys_replace_suffix
|
|
3571 (event_chain_nth (Vthis_command_keys, tckn - n),
|
|
3572 new_chain);
|
|
3573 }
|
|
3574
|
|
3575 result = command_builder_find_leaf_1 (builder);
|
|
3576 return result;
|
0
|
3577 }
|
185
|
3578
|
|
3579 signal_simple_error ((munge == MUNGE_ME_FUNCTION_KEY ?
|
|
3580 "Invalid binding in function-key-map" :
|
|
3581 "Invalid binding in key-translation-map"),
|
|
3582 result);
|
0
|
3583 }
|
|
3584
|
|
3585 return Qnil;
|
|
3586 }
|
|
3587
|
|
3588 /* Compare the current state of the command builder against the local and
|
|
3589 global keymaps, and return the binding. If there is no match, try again,
|
2
|
3590 case-insensitively. The return value will be one of:
|
0
|
3591 -- nil (there is no binding)
|
|
3592 -- a keymap (part of a command has been specified)
|
|
3593 -- a command (anything that satisfies `commandp'; this includes
|
|
3594 some symbols, lists, subrs, strings, vectors, and
|
|
3595 compiled-function objects)
|
|
3596 */
|
|
3597 static Lisp_Object
|
|
3598 command_builder_find_leaf (struct command_builder *builder,
|
|
3599 int allow_misc_user_events_p)
|
|
3600 {
|
|
3601 /* This function can GC */
|
|
3602 Lisp_Object result;
|
|
3603 Lisp_Object evee = builder->current_events;
|
|
3604
|
185
|
3605 if (XEVENT_TYPE (evee) == misc_user_event)
|
0
|
3606 {
|
185
|
3607 if (allow_misc_user_events_p && (NILP (XEVENT_NEXT (evee))))
|
|
3608 return list2 (XEVENT (evee)->event.eval.function,
|
|
3609 XEVENT (evee)->event.eval.object);
|
|
3610 else
|
|
3611 return Qnil;
|
0
|
3612 }
|
|
3613
|
175
|
3614 /* if we're currently in a menu accelerator, check there for further events */
|
179
|
3615 #if defined(HAVE_X_WINDOWS) && defined(HAVE_MENUBARS)
|
175
|
3616 if (lw_menu_active)
|
|
3617 {
|
185
|
3618 return command_builder_operate_menu_accelerator (builder);
|
175
|
3619 }
|
|
3620 else
|
|
3621 {
|
185
|
3622 result = Qnil;
|
175
|
3623 if (EQ (Vmenu_accelerator_enabled, Qmenu_force))
|
|
3624 result = command_builder_find_menu_accelerator (builder);
|
|
3625 if (NILP (result))
|
|
3626 #endif
|
|
3627 result = command_builder_find_leaf_1 (builder);
|
179
|
3628 #if defined(HAVE_X_WINDOWS) && defined(HAVE_MENUBARS)
|
175
|
3629 if (NILP (result)
|
|
3630 && EQ (Vmenu_accelerator_enabled, Qmenu_fallback))
|
|
3631 result = command_builder_find_menu_accelerator (builder);
|
|
3632 }
|
|
3633 #endif
|
0
|
3634
|
|
3635 /* Check to see if we have a potential function-key-map match. */
|
|
3636 if (NILP (result))
|
|
3637 {
|
|
3638 result = munge_keymap_translate (builder, MUNGE_ME_FUNCTION_KEY, 0);
|
|
3639 regenerate_echo_keys_from_this_command_keys (builder);
|
|
3640 }
|
|
3641 /* Check to see if we have a potential key-translation-map match. */
|
|
3642 {
|
|
3643 Lisp_Object key_translate_result =
|
|
3644 munge_keymap_translate (builder, MUNGE_ME_KEY_TRANSLATION,
|
|
3645 !NILP (result));
|
|
3646 if (!NILP (key_translate_result))
|
|
3647 {
|
|
3648 result = key_translate_result;
|
|
3649 regenerate_echo_keys_from_this_command_keys (builder);
|
|
3650 }
|
|
3651 }
|
|
3652
|
|
3653 if (!NILP (result))
|
|
3654 return result;
|
|
3655
|
|
3656 /* If key-sequence wasn't bound, we'll try some fallbacks. */
|
|
3657
|
|
3658 /* If we didn't find a binding, and the last event in the sequence is
|
|
3659 a shifted character, then try again with the lowercase version. */
|
|
3660
|
2
|
3661 if (XEVENT_TYPE (builder->most_current_event) == key_press_event
|
|
3662 && !NILP (Vretry_undefined_key_binding_unshifted))
|
|
3663 {
|
|
3664 Lisp_Object terminal = builder->most_current_event;
|
|
3665 struct key_data* key = & XEVENT (terminal)->event.key;
|
173
|
3666 Emchar c = 0;
|
2
|
3667 if ((key->modifiers & MOD_SHIFT)
|
|
3668 || (CHAR_OR_CHAR_INTP (key->keysym)
|
|
3669 && ((c = XCHAR_OR_CHAR_INT (key->keysym)), c >= 'A' && c <= 'Z')))
|
|
3670 {
|
169
|
3671 struct Lisp_Event terminal_copy = *XEVENT (terminal);
|
173
|
3672
|
2
|
3673 if (key->modifiers & MOD_SHIFT)
|
|
3674 key->modifiers &= (~ MOD_SHIFT);
|
|
3675 else
|
|
3676 key->keysym = make_char (c + 'a' - 'A');
|
|
3677
|
|
3678 result = command_builder_find_leaf (builder, allow_misc_user_events_p);
|
|
3679 if (!NILP (result))
|
169
|
3680 return result;
|
2
|
3681 /* If there was no match with the lower-case version either,
|
|
3682 then put back the upper-case event for the error
|
|
3683 message. But make sure that function-key-map didn't
|
|
3684 change things out from under us. */
|
|
3685 if (EQ (terminal, builder->most_current_event))
|
|
3686 *XEVENT (terminal) = terminal_copy;
|
|
3687 }
|
|
3688 }
|
|
3689
|
|
3690 /* help-char is `auto-bound' in every keymap */
|
0
|
3691 if (!NILP (Vprefix_help_command) &&
|
|
3692 event_matches_key_specifier_p (XEVENT (builder->most_current_event),
|
|
3693 Vhelp_char))
|
173
|
3694 return Vprefix_help_command;
|
0
|
3695
|
70
|
3696 #ifdef HAVE_XIM
|
|
3697 /* If keysym is a non-ASCII char, bind it to self-insert-char by default. */
|
|
3698 if (XEVENT_TYPE (builder->most_current_event) == key_press_event
|
|
3699 && !NILP (Vcomposed_character_default_binding))
|
|
3700 {
|
|
3701 Lisp_Object keysym = XEVENT (builder->most_current_event)->event.key.keysym;
|
|
3702 if (CHARP (keysym) && !CHAR_ASCII_P (XCHAR (keysym)))
|
|
3703 return Vcomposed_character_default_binding;
|
|
3704 }
|
|
3705 #endif /* HAVE_XIM */
|
173
|
3706
|
0
|
3707 /* If we read extra events attempting to match a function key but end
|
|
3708 up failing, then we release those events back to the command loop
|
|
3709 and fail on the original lookup. The released events will then be
|
|
3710 reprocessed in the context of the first part having failed. */
|
|
3711 if (!NILP (builder->last_non_munged_event))
|
|
3712 {
|
|
3713 Lisp_Object event0 = builder->last_non_munged_event;
|
173
|
3714
|
0
|
3715 /* Put the commands back on the event queue. */
|
|
3716 enqueue_event_chain (XEVENT_NEXT (event0),
|
|
3717 &command_event_queue,
|
|
3718 &command_event_queue_tail);
|
173
|
3719
|
0
|
3720 /* Then remove them from the command builder. */
|
|
3721 XSET_EVENT_NEXT (event0, Qnil);
|
|
3722 builder->most_current_event = event0;
|
|
3723 builder->last_non_munged_event = Qnil;
|
|
3724 }
|
|
3725
|
|
3726 return Qnil;
|
|
3727 }
|
|
3728
|
|
3729
|
|
3730 /* Every time a command-event (a key, button, or menu selection) is read by
|
|
3731 Fnext_event(), it is stored in the recent_keys_ring, in Vlast_input_event,
|
|
3732 and in Vthis_command_keys. (Eval-events are not stored there.)
|
|
3733
|
|
3734 Every time a command is invoked, Vlast_command_event is set to the last
|
|
3735 event in the sequence.
|
|
3736
|
|
3737 This means that Vthis_command_keys is really about "input read since the
|
|
3738 last command was executed" rather than about "what keys invoked this
|
173
|
3739 command." This is a little counterintuitive, but that's the way it
|
0
|
3740 has always worked.
|
|
3741
|
|
3742 As an extra kink, the function read-key-sequence resets/updates the
|
|
3743 last-command-event and this-command-keys. It doesn't append to the
|
|
3744 command-keys as read-char does. Such are the pitfalls of having to
|
|
3745 maintain compatibility with a program for which the only specification
|
|
3746 is the code itself.
|
|
3747
|
|
3748 (We could implement recent_keys_ring and Vthis_command_keys as the same
|
|
3749 data structure.)
|
|
3750 */
|
|
3751
|
153
|
3752 DEFUN ("recent-keys", Frecent_keys, 0, 1, 0, /*
|
|
3753 Return a vector of recent keyboard or mouse button events read.
|
|
3754 If NUMBER is non-nil, not more than NUMBER events will be returned.
|
|
3755 Change number of events stored using `set-recent-keys-size'.
|
|
3756
|
0
|
3757 This copies the event objects into a new vector; it is safe to keep and
|
|
3758 modify them.
|
20
|
3759 */
|
153
|
3760 (number))
|
0
|
3761 {
|
|
3762 struct gcpro gcpro1;
|
|
3763 Lisp_Object val = Qnil;
|
153
|
3764 int nwanted;
|
0
|
3765 int start, nkeys, i, j;
|
|
3766 GCPRO1 (val);
|
|
3767
|
153
|
3768 if (NILP (number))
|
|
3769 nwanted = recent_keys_ring_size;
|
|
3770 else
|
|
3771 {
|
|
3772 CHECK_NATNUM (number);
|
|
3773 nwanted = XINT (number);
|
|
3774 }
|
|
3775
|
|
3776 /* Create the keys ring vector, if none present. */
|
|
3777 if (NILP (Vrecent_keys_ring))
|
|
3778 {
|
|
3779 Vrecent_keys_ring = make_vector (recent_keys_ring_size, Qnil);
|
|
3780 /* And return nothing in particular. */
|
|
3781 return make_vector (0, Qnil);
|
|
3782 }
|
|
3783
|
173
|
3784 if (NILP (XVECTOR_DATA (Vrecent_keys_ring)[recent_keys_ring_index]))
|
0
|
3785 /* This means the vector has not yet wrapped */
|
|
3786 {
|
|
3787 nkeys = recent_keys_ring_index;
|
|
3788 start = 0;
|
|
3789 }
|
|
3790 else
|
|
3791 {
|
153
|
3792 nkeys = recent_keys_ring_size;
|
|
3793 start = ((recent_keys_ring_index == nkeys) ? 0 : recent_keys_ring_index);
|
0
|
3794 }
|
|
3795
|
153
|
3796 if (nwanted < nkeys)
|
|
3797 {
|
|
3798 start += nkeys - nwanted;
|
|
3799 if (start >= recent_keys_ring_size)
|
|
3800 start -= recent_keys_ring_size;
|
|
3801 nkeys = nwanted;
|
|
3802 }
|
|
3803 else
|
|
3804 nwanted = nkeys;
|
|
3805
|
|
3806 val = make_vector (nwanted, Qnil);
|
0
|
3807
|
|
3808 for (i = 0, j = start; i < nkeys; i++)
|
|
3809 {
|
173
|
3810 Lisp_Object e = XVECTOR_DATA (Vrecent_keys_ring)[j];
|
0
|
3811
|
|
3812 if (NILP (e))
|
|
3813 abort ();
|
173
|
3814 XVECTOR_DATA (val)[i] = Fcopy_event (e, Qnil);
|
153
|
3815 if (++j >= recent_keys_ring_size)
|
0
|
3816 j = 0;
|
|
3817 }
|
|
3818 UNGCPRO;
|
173
|
3819 return val;
|
0
|
3820 }
|
|
3821
|
153
|
3822
|
|
3823 DEFUN ("recent-keys-ring-size", Frecent_keys_ring_size, 0, 0, 0, /*
|
|
3824 The maximum number of events `recent-keys' can return.
|
|
3825 */
|
|
3826 ())
|
|
3827 {
|
|
3828 return make_int (recent_keys_ring_size);
|
|
3829 }
|
|
3830
|
|
3831 DEFUN ("set-recent-keys-ring-size", Fset_recent_keys_ring_size, 1, 1, 0, /*
|
|
3832 Set the maximum number of events to be stored internally.
|
|
3833 */
|
|
3834 (size))
|
|
3835 {
|
|
3836 Lisp_Object new_vector = Qnil;
|
|
3837 int i, j, nkeys, start, min;
|
|
3838 struct gcpro gcpro1;
|
|
3839 GCPRO1 (new_vector);
|
|
3840
|
|
3841 CHECK_INT (size);
|
|
3842 if (XINT (size) <= 0)
|
|
3843 error ("Recent keys ring size must be positive");
|
|
3844 if (XINT (size) == recent_keys_ring_size)
|
|
3845 return size;
|
|
3846
|
|
3847 new_vector = make_vector (XINT (size), Qnil);
|
|
3848
|
|
3849 if (NILP (Vrecent_keys_ring))
|
|
3850 {
|
|
3851 Vrecent_keys_ring = new_vector;
|
|
3852 return size;
|
|
3853 }
|
|
3854
|
173
|
3855 if (NILP (XVECTOR_DATA (Vrecent_keys_ring)[recent_keys_ring_index]))
|
153
|
3856 /* This means the vector has not yet wrapped */
|
|
3857 {
|
|
3858 nkeys = recent_keys_ring_index;
|
|
3859 start = 0;
|
|
3860 }
|
|
3861 else
|
|
3862 {
|
|
3863 nkeys = recent_keys_ring_size;
|
|
3864 start = ((recent_keys_ring_index == nkeys) ? 0 : recent_keys_ring_index);
|
|
3865 }
|
|
3866
|
|
3867 if (XINT (size) > nkeys)
|
|
3868 min = nkeys;
|
|
3869 else
|
|
3870 min = XINT (size);
|
|
3871
|
|
3872 for (i = 0, j = start; i < min; i++)
|
|
3873 {
|
173
|
3874 XVECTOR_DATA (new_vector)[i] = XVECTOR_DATA (Vrecent_keys_ring)[j];
|
153
|
3875 if (++j >= recent_keys_ring_size)
|
|
3876 j = 0;
|
|
3877 }
|
|
3878 recent_keys_ring_size = XINT (size);
|
|
3879 recent_keys_ring_index = (i < recent_keys_ring_size) ? i : 0;
|
|
3880
|
|
3881 Vrecent_keys_ring = new_vector;
|
|
3882
|
|
3883 UNGCPRO;
|
|
3884 return size;
|
|
3885 }
|
|
3886
|
0
|
3887 /* Vthis_command_keys having value Qnil means that the next time
|
|
3888 push_this_command_keys is called, it should start over.
|
2
|
3889 The times at which the command-keys are reset
|
0
|
3890 (instead of merely being augmented) are pretty conterintuitive.
|
|
3891 (More specifically:
|
|
3892
|
|
3893 -- We do not reset this-command-keys when we finish reading a
|
|
3894 command. This is because some commands (e.g. C-u) act
|
|
3895 like command prefixes; they signal this by setting prefix-arg
|
|
3896 to non-nil.
|
|
3897 -- Therefore, we reset this-command-keys when we finish
|
110
|
3898 executing a command, unless prefix-arg is set.
|
0
|
3899 -- However, if we ever do a non-local exit out of a command
|
|
3900 loop (e.g. an error in a command), we need to reset
|
|
3901 this-command-keys. We do this by calling reset_this_command_keys()
|
|
3902 from cmdloop.c, whenever an error causes an invocation of the
|
|
3903 default error handler, and whenever there's a throw to top-level.)
|
|
3904 */
|
|
3905
|
|
3906 void
|
|
3907 reset_this_command_keys (Lisp_Object console, int clear_echo_area_p)
|
|
3908 {
|
|
3909 struct command_builder *command_builder =
|
|
3910 XCOMMAND_BUILDER (XCONSOLE (console)->command_builder);
|
|
3911
|
|
3912 reset_key_echo (command_builder, clear_echo_area_p);
|
|
3913
|
|
3914 deallocate_event_chain (Vthis_command_keys);
|
|
3915 Vthis_command_keys = Qnil;
|
|
3916 Vthis_command_keys_tail = Qnil;
|
|
3917
|
|
3918 reset_current_events (command_builder);
|
|
3919 }
|
|
3920
|
|
3921 static void
|
|
3922 push_this_command_keys (Lisp_Object event)
|
|
3923 {
|
189
|
3924 Lisp_Object new = Fmake_event (Qnil, Qnil);
|
0
|
3925
|
|
3926 Fcopy_event (event, new);
|
|
3927 enqueue_event (new, &Vthis_command_keys, &Vthis_command_keys_tail);
|
|
3928 }
|
|
3929
|
|
3930 /* The following two functions are used in call-interactively,
|
|
3931 for the @ and e specifications. We used to just use
|
110
|
3932 `current-mouse-event' (i.e. the last mouse event in this-command-keys),
|
0
|
3933 but FSF does it more generally so we follow their lead. */
|
|
3934
|
|
3935 Lisp_Object
|
|
3936 extract_this_command_keys_nth_mouse_event (int n)
|
|
3937 {
|
|
3938 Lisp_Object event;
|
|
3939
|
|
3940 EVENT_CHAIN_LOOP (event, Vthis_command_keys)
|
|
3941 {
|
|
3942 if (EVENTP (event)
|
|
3943 && (XEVENT_TYPE (event) == button_press_event
|
|
3944 || XEVENT_TYPE (event) == button_release_event
|
|
3945 || XEVENT_TYPE (event) == misc_user_event))
|
|
3946 {
|
|
3947 if (!n)
|
|
3948 {
|
|
3949 /* must copy to avoid an abort() in next_event_internal() */
|
|
3950 if (!NILP (XEVENT_NEXT (event)))
|
|
3951 return Fcopy_event (event, Qnil);
|
|
3952 else
|
|
3953 return event;
|
|
3954 }
|
|
3955 n--;
|
|
3956 }
|
|
3957 }
|
|
3958
|
|
3959 return Qnil;
|
|
3960 }
|
|
3961
|
|
3962 Lisp_Object
|
|
3963 extract_vector_nth_mouse_event (Lisp_Object vector, int n)
|
|
3964 {
|
|
3965 int i;
|
173
|
3966 int len = XVECTOR_LENGTH (vector);
|
|
3967
|
|
3968 for (i = 0; i < len; i++)
|
0
|
3969 {
|
173
|
3970 Lisp_Object event = XVECTOR_DATA (vector)[i];
|
|
3971 if (EVENTP (event))
|
|
3972 switch (XEVENT_TYPE (event))
|
|
3973 {
|
|
3974 case button_press_event :
|
|
3975 case button_release_event :
|
|
3976 case misc_user_event :
|
|
3977 if (n == 0)
|
|
3978 return event;
|
|
3979 n--;
|
|
3980 break;
|
|
3981 default:
|
|
3982 continue;
|
|
3983 }
|
0
|
3984 }
|
|
3985
|
|
3986 return Qnil;
|
|
3987 }
|
|
3988
|
|
3989 static void
|
|
3990 push_recent_keys (Lisp_Object event)
|
|
3991 {
|
153
|
3992 Lisp_Object e;
|
|
3993
|
|
3994 if (NILP (Vrecent_keys_ring))
|
|
3995 Vrecent_keys_ring = make_vector (recent_keys_ring_size, Qnil);
|
|
3996
|
173
|
3997 e = XVECTOR_DATA (Vrecent_keys_ring) [recent_keys_ring_index];
|
0
|
3998
|
|
3999 if (NILP (e))
|
|
4000 {
|
189
|
4001 e = Fmake_event (Qnil, Qnil);
|
173
|
4002 XVECTOR_DATA (Vrecent_keys_ring) [recent_keys_ring_index] = e;
|
0
|
4003 }
|
|
4004 Fcopy_event (event, e);
|
153
|
4005 if (++recent_keys_ring_index == recent_keys_ring_size)
|
0
|
4006 recent_keys_ring_index = 0;
|
|
4007 }
|
|
4008
|
|
4009
|
|
4010 static Lisp_Object
|
|
4011 current_events_into_vector (struct command_builder *command_builder)
|
|
4012 {
|
|
4013 Lisp_Object vector;
|
|
4014 Lisp_Object event;
|
|
4015 int n = event_chain_count (command_builder->current_events);
|
|
4016
|
|
4017 /* Copy the vector and the events in it. */
|
|
4018 /* No need to copy the events, since they're already copies, and
|
|
4019 nobody other than the command-builder has pointers to them */
|
|
4020 vector = make_vector (n, Qnil);
|
|
4021 n = 0;
|
|
4022 EVENT_CHAIN_LOOP (event, command_builder->current_events)
|
173
|
4023 XVECTOR_DATA (vector)[n++] = event;
|
0
|
4024 reset_command_builder_event_chain (command_builder);
|
173
|
4025 return vector;
|
0
|
4026 }
|
|
4027
|
|
4028
|
|
4029 /*
|
|
4030 Given the current state of the command builder and a new command event
|
|
4031 that has just been dispatched:
|
|
4032
|
|
4033 -- add the event to the event chain forming the current command
|
|
4034 (doing meta-translation as necessary)
|
2
|
4035 -- return the binding of this event chain; this will be one of:
|
0
|
4036 -- nil (there is no binding)
|
|
4037 -- a keymap (part of a command has been specified)
|
|
4038 -- a command (anything that satisfies `commandp'; this includes
|
|
4039 some symbols, lists, subrs, strings, vectors, and
|
|
4040 compiled-function objects)
|
|
4041 */
|
|
4042 static Lisp_Object
|
|
4043 lookup_command_event (struct command_builder *command_builder,
|
|
4044 Lisp_Object event, int allow_misc_user_events_p)
|
|
4045 {
|
|
4046 /* This function can GC */
|
|
4047 struct frame *f = selected_frame ();
|
|
4048 /* Clear output from previous command execution */
|
|
4049 if (!EQ (Qcommand, echo_area_status (f))
|
|
4050 /* but don't let mouse-up clear what mouse-down just printed */
|
|
4051 && (XEVENT (event)->event_type != button_release_event))
|
|
4052 clear_echo_area (f, Qnil, 0);
|
|
4053
|
|
4054 /* Add the given event to the command builder.
|
|
4055 Extra hack: this also updates the recent_keys_ring and Vthis_command_keys
|
|
4056 vectors to translate "ESC x" to "M-x" (for any "x" of course).
|
|
4057 */
|
|
4058 {
|
|
4059 Lisp_Object recent = command_builder->most_current_event;
|
|
4060
|
|
4061 if (EVENTP (recent)
|
|
4062 && event_matches_key_specifier_p (XEVENT (recent), Vmeta_prefix_char))
|
|
4063 {
|
|
4064 struct Lisp_Event *e;
|
|
4065 /* When we see a sequence like "ESC x", pretend we really saw "M-x".
|
|
4066 DoubleThink the recent-keys and this-command-keys as well. */
|
|
4067
|
|
4068 /* Modify the previous most-recently-pushed event on the command
|
|
4069 builder to be a copy of this one with the meta-bit set instead of
|
|
4070 pushing a new event.
|
|
4071 */
|
|
4072 Fcopy_event (event, recent);
|
|
4073 e = XEVENT (recent);
|
|
4074 if (e->event_type == key_press_event)
|
|
4075 e->event.key.modifiers |= MOD_META;
|
173
|
4076 else if (e->event_type == button_press_event
|
0
|
4077 || e->event_type == button_release_event)
|
|
4078 e->event.button.modifiers |= MOD_META;
|
|
4079 else
|
|
4080 abort ();
|
|
4081
|
|
4082 {
|
|
4083 int tckn = event_chain_count (Vthis_command_keys);
|
|
4084 if (tckn >= 2)
|
|
4085 /* ??? very strange if it's < 2. */
|
|
4086 this_command_keys_replace_suffix
|
|
4087 (event_chain_nth (Vthis_command_keys, tckn - 2),
|
|
4088 Fcopy_event (recent, Qnil));
|
|
4089 }
|
|
4090
|
|
4091 regenerate_echo_keys_from_this_command_keys (command_builder);
|
|
4092 }
|
|
4093 else
|
|
4094 {
|
189
|
4095 event = Fcopy_event (event, Fmake_event (Qnil, Qnil));
|
0
|
4096
|
|
4097 command_builder_append_event (command_builder, event);
|
|
4098 }
|
|
4099 }
|
|
4100
|
|
4101 {
|
|
4102 Lisp_Object leaf = command_builder_find_leaf (command_builder,
|
|
4103 allow_misc_user_events_p);
|
|
4104 struct gcpro gcpro1;
|
|
4105 GCPRO1 (leaf);
|
|
4106
|
|
4107 if (KEYMAPP (leaf))
|
|
4108 {
|
175
|
4109 if (!lw_menu_active)
|
0
|
4110 {
|
175
|
4111 Lisp_Object prompt = Fkeymap_prompt (leaf, Qt);
|
|
4112 if (STRINGP (prompt))
|
0
|
4113 {
|
175
|
4114 /* Append keymap prompt to key echo buffer */
|
|
4115 int buf_index = command_builder->echo_buf_index;
|
|
4116 Bytecount len = XSTRING_LENGTH (prompt);
|
|
4117
|
|
4118 if (len + buf_index + 1 <= command_builder->echo_buf_length)
|
|
4119 {
|
|
4120 Bufbyte *echo = command_builder->echo_buf + buf_index;
|
|
4121 memcpy (echo, XSTRING_DATA (prompt), len);
|
|
4122 echo[len] = 0;
|
|
4123 }
|
|
4124 maybe_echo_keys (command_builder, 1);
|
0
|
4125 }
|
175
|
4126 else
|
|
4127 maybe_echo_keys (command_builder, 0);
|
0
|
4128 }
|
175
|
4129 else if (!NILP (Vquit_flag)) {
|
189
|
4130 Lisp_Object quit_event = Fmake_event(Qnil, Qnil);
|
185
|
4131 struct Lisp_Event *e = XEVENT (quit_event);
|
175
|
4132 /* if quit happened during menu acceleration, pretend we read it */
|
185
|
4133 struct console *con = XCONSOLE (Fselected_console ());
|
|
4134 int ch = CONSOLE_QUIT_CHAR (con);
|
|
4135
|
175
|
4136 character_to_event (ch, e, con, 1);
|
|
4137 e->channel = make_console (con);
|
185
|
4138
|
|
4139 enqueue_command_event (quit_event);
|
175
|
4140 Vquit_flag = Qnil;
|
|
4141 }
|
0
|
4142 }
|
|
4143 else if (!NILP (leaf))
|
|
4144 {
|
|
4145 if (EQ (Qcommand, echo_area_status (f))
|
|
4146 && command_builder->echo_buf_index > 0)
|
|
4147 {
|
|
4148 /* If we had been echoing keys, echo the last one (without
|
|
4149 the trailing dash) and redisplay before executing the
|
|
4150 command. */
|
|
4151 command_builder->echo_buf[command_builder->echo_buf_index] = 0;
|
|
4152 maybe_echo_keys (command_builder, 1);
|
|
4153 Fsit_for (Qzero, Qt);
|
|
4154 }
|
|
4155 }
|
|
4156 RETURN_UNGCPRO (leaf);
|
|
4157 }
|
|
4158 }
|
|
4159
|
|
4160 static void
|
|
4161 execute_command_event (struct command_builder *command_builder,
|
|
4162 Lisp_Object event)
|
|
4163 {
|
|
4164 /* This function can GC */
|
|
4165 struct console *con = XCONSOLE (command_builder->console);
|
|
4166 struct gcpro gcpro1;
|
|
4167
|
|
4168 GCPRO1 (event); /* event may be freshly created */
|
|
4169 reset_current_events (command_builder);
|
|
4170
|
185
|
4171 switch (XEVENT (event)->event_type)
|
|
4172 {
|
|
4173 case key_press_event:
|
|
4174 Vcurrent_mouse_event = Qnil;
|
|
4175 break;
|
|
4176 case button_press_event:
|
|
4177 case button_release_event:
|
|
4178 case misc_user_event:
|
|
4179 Vcurrent_mouse_event = Fcopy_event (event, Qnil);
|
|
4180 break;
|
|
4181 default: break;
|
|
4182 }
|
|
4183
|
|
4184 /* Store the last-command-event. The semantics of this is that it
|
|
4185 is the last event most recently involved in command-lookup. */
|
0
|
4186 if (!EVENTP (Vlast_command_event))
|
189
|
4187 Vlast_command_event = Fmake_event (Qnil, Qnil);
|
0
|
4188 if (XEVENT (Vlast_command_event)->event_type == dead_event)
|
|
4189 {
|
189
|
4190 Vlast_command_event = Fmake_event (Qnil, Qnil);
|
0
|
4191 error ("Someone deallocated the last-command-event!");
|
|
4192 }
|
173
|
4193
|
0
|
4194 if (! EQ (event, Vlast_command_event))
|
|
4195 Fcopy_event (event, Vlast_command_event);
|
|
4196
|
|
4197 /* Note that last-command-char will never have its high-bit set, in
|
185
|
4198 an effort to sidestep the ambiguity between M-x and oslash. */
|
0
|
4199 Vlast_command_char = Fevent_to_character (Vlast_command_event,
|
|
4200 Qnil, Qnil, Qnil);
|
|
4201
|
|
4202 /* Actually call the command, with all sorts of hair to preserve or clear
|
|
4203 the echo-area and region as appropriate and call the pre- and post-
|
185
|
4204 command-hooks. */
|
0
|
4205 {
|
|
4206 int old_kbd_macro = con->kbd_macro_end;
|
185
|
4207 struct window *w = XWINDOW (Fselected_window (Qnil));
|
0
|
4208
|
2
|
4209 /* We're executing a new command, so the old value is irrelevant. */
|
0
|
4210 zmacs_region_stays = 0;
|
|
4211
|
|
4212 /* If the previous command tried to force a specific window-start,
|
|
4213 reset the flag in case this command moves point far away from
|
|
4214 that position. Also, reset the window's buffer's change
|
|
4215 information so that we don't trigger an incremental update. */
|
|
4216 if (w->force_start)
|
|
4217 {
|
|
4218 w->force_start = 0;
|
|
4219 buffer_reset_changes (XBUFFER (w->buffer));
|
|
4220 }
|
|
4221
|
|
4222 pre_command_hook ();
|
|
4223
|
|
4224 if (XEVENT (event)->event_type == misc_user_event)
|
|
4225 {
|
173
|
4226 call1 (XEVENT (event)->event.eval.function,
|
0
|
4227 XEVENT (event)->event.eval.object);
|
|
4228 }
|
|
4229 else
|
|
4230 {
|
|
4231 Fcommand_execute (Vthis_command, Qnil, Qnil);
|
|
4232 }
|
|
4233
|
|
4234 post_command_hook ();
|
|
4235
|
185
|
4236 #if 0 /* #### here was an attempted fix that didn't work */
|
|
4237 if (XEVENT (event)->event_type == misc_user_event)
|
|
4238 ;
|
|
4239 else
|
|
4240 #endif
|
|
4241 if (!NILP (con->prefix_arg))
|
0
|
4242 {
|
|
4243 /* Commands that set the prefix arg don't update last-command, don't
|
|
4244 reset the echoing state, and don't go into keyboard macros unless
|
185
|
4245 followed by another command. */
|
0
|
4246 maybe_echo_keys (command_builder, 0);
|
|
4247
|
|
4248 /* If we're recording a keyboard macro, and the last command
|
|
4249 executed set a prefix argument, then decrement the pointer to
|
|
4250 the "last character really in the macro" to be just before this
|
|
4251 command. This is so that the ^U in "^U ^X )" doesn't go onto
|
185
|
4252 the end of macro. */
|
0
|
4253 if (!NILP (con->defining_kbd_macro))
|
|
4254 con->kbd_macro_end = old_kbd_macro;
|
|
4255 }
|
|
4256 else
|
|
4257 {
|
|
4258 /* Start a new command next time */
|
|
4259 Vlast_command = Vthis_command;
|
|
4260 /* Emacs 18 doesn't unconditionally clear the echoed keystrokes,
|
|
4261 so we don't either */
|
|
4262 reset_this_command_keys (make_console (con), 0);
|
|
4263 }
|
|
4264 }
|
|
4265
|
|
4266 UNGCPRO;
|
|
4267 }
|
|
4268
|
|
4269 /* Run the pre command hook. */
|
|
4270
|
|
4271 static void
|
|
4272 pre_command_hook (void)
|
|
4273 {
|
|
4274 last_point_position = BUF_PT (current_buffer);
|
|
4275 XSETBUFFER (last_point_position_buffer, current_buffer);
|
|
4276 /* This function can GC */
|
|
4277 safe_run_hook_trapping_errors
|
|
4278 ("Error in `pre-command-hook' (setting hook to nil)",
|
|
4279 Qpre_command_hook, 1);
|
|
4280 }
|
|
4281
|
|
4282 /* Run the post command hook. */
|
|
4283
|
|
4284 static void
|
|
4285 post_command_hook (void)
|
|
4286 {
|
|
4287 /* This function can GC */
|
|
4288 /* Turn off region highlighting unless this command requested that
|
|
4289 it be left on, or we're in the minibuffer. We don't turn it off
|
|
4290 when we're in the minibuffer so that things like M-x write-region
|
|
4291 still work!
|
|
4292
|
|
4293 This could be done via a function on the post-command-hook, but
|
|
4294 we don't want the user to accidentally remove it.
|
|
4295 */
|
2
|
4296
|
|
4297 Lisp_Object win = Fselected_window (Qnil);
|
|
4298
|
|
4299 #if 0
|
|
4300 /* If the last command deleted the frame, `win' might be nil.
|
|
4301 It seems safest to do nothing in this case. */
|
|
4302 /* ### This doesn't really fix the problem,
|
|
4303 if delete-frame is called by some hook */
|
|
4304 if (NILP (win))
|
|
4305 return;
|
|
4306 #endif
|
173
|
4307
|
0
|
4308 if (! zmacs_region_stays
|
2
|
4309 && (!MINI_WINDOW_P (XWINDOW (win))
|
|
4310 || EQ (zmacs_region_buffer (), WINDOW_BUFFER (XWINDOW (win)))))
|
0
|
4311 zmacs_deactivate_region ();
|
|
4312 else
|
|
4313 zmacs_update_region ();
|
|
4314
|
|
4315 safe_run_hook_trapping_errors
|
|
4316 ("Error in `post-command-hook' (setting hook to nil)",
|
|
4317 Qpost_command_hook, 1);
|
|
4318
|
|
4319 #ifdef DEFERRED_ACTION_CRAP
|
|
4320 if (!NILP (Vdeferred_action_list))
|
|
4321 call0 (Vdeferred_action_function);
|
|
4322 #endif
|
|
4323
|
|
4324 #ifdef ILL_CONCEIVED_HOOK
|
|
4325 if (NILP (Vunread_command_events)
|
|
4326 && NILP (Vexecuting_macro)
|
|
4327 && !NILP (Vpost_command_idle_hook)
|
|
4328 && !NILP (Fsit_for (make_float ((double) post_command_idle_delay
|
|
4329 / 1000000), Qnil)))
|
|
4330 safe_run_hook_trapping_errors
|
|
4331 ("Error in `post-command-idle-hook' (setting hook to nil)",
|
|
4332 Qpost_command_idle_hook, 1);
|
|
4333 #endif
|
|
4334
|
|
4335 #if 0 /* FSFmacs */
|
|
4336 if (!NILP (current_buffer->mark_active))
|
|
4337 {
|
|
4338 if (!NILP (Vdeactivate_mark) && !NILP (Vtransient_mark_mode))
|
|
4339 {
|
|
4340 current_buffer->mark_active = Qnil;
|
|
4341 run_hook (intern ("deactivate-mark-hook"));
|
|
4342 }
|
|
4343 else if (current_buffer != prev_buffer ||
|
|
4344 BUF_MODIFF (current_buffer) != prev_modiff)
|
|
4345 run_hook (intern ("activate-mark-hook"));
|
|
4346 }
|
|
4347 #endif /* FSFmacs */
|
|
4348
|
|
4349 /* #### Kludge!!! This is necessary to make sure that things
|
|
4350 are properly positioned even if post-command-hook moves point.
|
|
4351 #### There should be a cleaner way of handling this. */
|
|
4352 call0 (Qauto_show_make_point_visible);
|
|
4353 }
|
|
4354
|
|
4355
|
20
|
4356 DEFUN ("dispatch-event", Fdispatch_event, 1, 1, 0, /*
|
0
|
4357 Given an event object as returned by `next-event', execute it.
|
|
4358
|
|
4359 Key-press, button-press, and button-release events get accumulated
|
|
4360 until a complete key sequence (see `read-key-sequence') is reached,
|
|
4361 at which point the sequence is looked up in the current keymaps and
|
|
4362 acted upon.
|
|
4363
|
|
4364 Mouse motion events cause the low-level handling function stored in
|
|
4365 `mouse-motion-handler' to be called. (There are very few circumstances
|
|
4366 under which you should change this handler. Use `mode-motion-hook'
|
|
4367 instead.)
|
|
4368
|
|
4369 Menu, timeout, and eval events cause the associated function or handler
|
|
4370 to be called.
|
|
4371
|
|
4372 Process events cause the subprocess's output to be read and acted upon
|
|
4373 appropriately (see `start-process').
|
|
4374
|
|
4375 Magic events are handled as necessary.
|
20
|
4376 */
|
|
4377 (event))
|
0
|
4378 {
|
|
4379 /* This function can GC */
|
|
4380 struct command_builder *command_builder;
|
|
4381 struct Lisp_Event *ev;
|
|
4382 Lisp_Object console;
|
|
4383 Lisp_Object channel;
|
|
4384
|
|
4385 CHECK_LIVE_EVENT (event);
|
|
4386 ev = XEVENT (event);
|
|
4387
|
|
4388 /* events on dead channels get silently eaten */
|
|
4389 channel = EVENT_CHANNEL (ev);
|
|
4390 if (object_dead_p (channel))
|
|
4391 return Qnil;
|
|
4392
|
|
4393 /* Some events don't have channels (e.g. eval events). */
|
|
4394 console = CDFW_CONSOLE (channel);
|
|
4395 if (NILP (console))
|
|
4396 console = Vselected_console;
|
|
4397 else if (!EQ (console, Vselected_console))
|
|
4398 Fselect_console (console);
|
|
4399
|
|
4400 command_builder = XCOMMAND_BUILDER (XCONSOLE (console)->command_builder);
|
173
|
4401 switch (XEVENT (event)->event_type)
|
0
|
4402 {
|
|
4403 case button_press_event:
|
|
4404 case button_release_event:
|
|
4405 case key_press_event:
|
|
4406 {
|
185
|
4407 Lisp_Object leaf = lookup_command_event (command_builder, event, 1);
|
|
4408
|
0
|
4409 if (KEYMAPP (leaf))
|
|
4410 /* Incomplete key sequence */
|
|
4411 break;
|
|
4412 if (NILP (leaf))
|
|
4413 {
|
|
4414 /* At this point, we know that the sequence is not bound to a
|
|
4415 command. Normally, we beep and print a message informing the
|
|
4416 user of this. But we do not beep or print a message when:
|
|
4417
|
|
4418 o the last event in this sequence is a mouse-up event; or
|
|
4419 o the last event in this sequence is a mouse-down event and
|
|
4420 there is a binding for the mouse-up version.
|
|
4421
|
|
4422 That is, if the sequence ``C-x button1'' is typed, and is not
|
|
4423 bound to a command, but the sequence ``C-x button1up'' is bound
|
|
4424 to a command, we do not complain about the ``C-x button1''
|
|
4425 sequence. If neither ``C-x button1'' nor ``C-x button1up'' is
|
|
4426 bound to a command, then we complain about the ``C-x button1''
|
|
4427 sequence, but later will *not* complain about the
|
|
4428 ``C-x button1up'' sequence, which would be redundant.
|
|
4429
|
|
4430 This is pretty hairy, but I think it's the most intuitive
|
|
4431 behavior.
|
|
4432 */
|
|
4433 Lisp_Object terminal = command_builder->most_current_event;
|
|
4434
|
|
4435 if (XEVENT_TYPE (terminal) == button_press_event)
|
|
4436 {
|
|
4437 int no_bitching;
|
|
4438 /* Temporarily pretend the last event was an "up" instead of a
|
|
4439 "down", and look up its binding. */
|
|
4440 XEVENT_TYPE (terminal) = button_release_event;
|
|
4441 /* If the "up" version is bound, don't complain. */
|
|
4442 no_bitching
|
185
|
4443 = !NILP (command_builder_find_leaf (command_builder, 0));
|
0
|
4444 /* Undo the temporary changes we just made. */
|
|
4445 XEVENT_TYPE (terminal) = button_press_event;
|
|
4446 if (no_bitching)
|
|
4447 {
|
|
4448 /* Pretend this press was not seen (treat as a prefix) */
|
|
4449 if (EQ (command_builder->current_events, terminal))
|
|
4450 {
|
|
4451 reset_current_events (command_builder);
|
|
4452 }
|
|
4453 else
|
|
4454 {
|
|
4455 Lisp_Object eve;
|
|
4456
|
|
4457 EVENT_CHAIN_LOOP (eve, command_builder->current_events)
|
|
4458 if (EQ (XEVENT_NEXT (eve), terminal))
|
|
4459 break;
|
|
4460
|
|
4461 Fdeallocate_event (command_builder->
|
|
4462 most_current_event);
|
|
4463 XSET_EVENT_NEXT (eve, Qnil);
|
|
4464 command_builder->most_current_event = eve;
|
|
4465 }
|
|
4466 maybe_echo_keys (command_builder, 1);
|
|
4467 break;
|
|
4468 }
|
|
4469 }
|
|
4470
|
|
4471 /* Complain that the typed sequence is not defined, if this is the
|
185
|
4472 kind of sequence that warrants a complaint. */
|
0
|
4473 XCONSOLE (console)->defining_kbd_macro = Qnil;
|
|
4474 XCONSOLE (console)->prefix_arg = Qnil;
|
|
4475 /* Don't complain about undefined button-release events */
|
173
|
4476 if (XEVENT_TYPE (terminal) != button_release_event)
|
0
|
4477 {
|
185
|
4478 Lisp_Object keys = current_events_into_vector (command_builder);
|
0
|
4479 struct gcpro gcpro1;
|
|
4480
|
|
4481 /* Run the pre-command-hook before barfing about an undefined
|
|
4482 key. */
|
|
4483 Vthis_command = Qnil;
|
|
4484 GCPRO1 (keys);
|
|
4485 pre_command_hook ();
|
|
4486 UNGCPRO;
|
|
4487 /* The post-command-hook doesn't run. */
|
|
4488 Fsignal (Qundefined_keystroke_sequence, list1 (keys));
|
|
4489 }
|
|
4490 /* Reset the command builder for reading the next sequence. */
|
|
4491 reset_this_command_keys (console, 1);
|
|
4492 }
|
2
|
4493 else /* key sequence is bound to a command */
|
0
|
4494 {
|
|
4495 Vthis_command = leaf;
|
|
4496 /* Don't push an undo boundary if the command set the prefix arg,
|
|
4497 or if we are executing a keyboard macro, or if in the
|
|
4498 minibuffer. If the command we are about to execute is
|
|
4499 self-insert, it's tricky: up to 20 consecutive self-inserts may
|
|
4500 be done without an undo boundary. This counter is reset as
|
|
4501 soon as a command other than self-insert-command is executed.
|
|
4502 */
|
|
4503 if (! EQ (leaf, Qself_insert_command))
|
|
4504 command_builder->self_insert_countdown = 0;
|
|
4505 if (NILP (XCONSOLE (console)->prefix_arg)
|
|
4506 && NILP (Vexecuting_macro)
|
|
4507 #if 0
|
|
4508 /* This was done in the days when there was no undo
|
|
4509 in the minibuffer. If we don't disable this code,
|
|
4510 then each instance of "undo" undoes everything in
|
|
4511 the minibuffer. */
|
|
4512 && !EQ (minibuf_window, Fselected_window (Qnil))
|
|
4513 #endif
|
|
4514 && command_builder->self_insert_countdown == 0)
|
|
4515 Fundo_boundary ();
|
|
4516
|
|
4517 if (EQ (leaf, Qself_insert_command))
|
|
4518 {
|
|
4519 if (--command_builder->self_insert_countdown < 0)
|
|
4520 command_builder->self_insert_countdown = 20;
|
|
4521 }
|
2
|
4522 execute_command_event
|
|
4523 (command_builder,
|
195
|
4524 internal_equal (event, command_builder-> most_current_event, 0)
|
2
|
4525 ? event
|
|
4526 /* Use the translated event that was most recently seen.
|
|
4527 This way, last-command-event becomes f1 instead of
|
|
4528 the P from ESC O P. But we must copy it, else we'll
|
|
4529 lose when the command-builder events are deallocated. */
|
|
4530 : Fcopy_event (command_builder-> most_current_event, Qnil));
|
0
|
4531 }
|
|
4532 break;
|
|
4533 }
|
|
4534 case misc_user_event:
|
|
4535 {
|
|
4536 /* Jamie said:
|
|
4537
|
|
4538 We could just always use the menu item entry, whatever it is, but
|
|
4539 this might break some Lisp code that expects `this-command' to
|
|
4540 always contain a symbol. So only store it if this is a simple
|
|
4541 `call-interactively' sort of menu item.
|
|
4542
|
|
4543 But this is bogus. `this-command' could be a string or vector
|
|
4544 anyway (for keyboard macros). There's even one instance
|
|
4545 (in pending-del.el) of `this-command' getting set to a cons
|
|
4546 (a lambda expression). So in the `eval' case I'll just
|
|
4547 convert it into a lambda expression.
|
|
4548 */
|
|
4549 if (EQ (XEVENT (event)->event.eval.function, Qcall_interactively)
|
|
4550 && SYMBOLP (XEVENT (event)->event.eval.object))
|
|
4551 Vthis_command = XEVENT (event)->event.eval.object;
|
|
4552 else if (EQ (XEVENT (event)->event.eval.function, Qeval))
|
|
4553 Vthis_command =
|
|
4554 Fcons (Qlambda, Fcons (Qnil, XEVENT (event)->event.eval.object));
|
|
4555 else if (SYMBOLP (XEVENT (event)->event.eval.function))
|
|
4556 /* A scrollbar command or the like. */
|
|
4557 Vthis_command = XEVENT (event)->event.eval.function;
|
|
4558 else
|
|
4559 /* Huh? */
|
|
4560 Vthis_command = Qnil;
|
|
4561
|
175
|
4562 /* clear the echo area */
|
|
4563 reset_key_echo (command_builder, 1);
|
185
|
4564
|
0
|
4565 command_builder->self_insert_countdown = 0;
|
|
4566 if (NILP (XCONSOLE (console)->prefix_arg)
|
|
4567 && NILP (Vexecuting_macro)
|
|
4568 && !EQ (minibuf_window, Fselected_window (Qnil)))
|
|
4569 Fundo_boundary ();
|
|
4570 execute_command_event (command_builder, event);
|
|
4571 break;
|
|
4572 }
|
|
4573 default:
|
|
4574 {
|
|
4575 execute_internal_event (event);
|
|
4576 break;
|
|
4577 }
|
|
4578 }
|
173
|
4579 return Qnil;
|
0
|
4580 }
|
|
4581
|
20
|
4582 DEFUN ("read-key-sequence", Fread_key_sequence, 1, 3, 0, /*
|
0
|
4583 Read a sequence of keystrokes or mouse clicks.
|
|
4584 Returns a vector of the event objects read. The vector and the event
|
|
4585 objects it contains are freshly created (and will not be side-effected
|
|
4586 by subsequent calls to this function).
|
|
4587
|
|
4588 The sequence read is sufficient to specify a non-prefix command starting
|
|
4589 from the current local and global keymaps. A C-g typed while in this
|
|
4590 function is treated like any other character, and `quit-flag' is not set.
|
|
4591
|
|
4592 First arg PROMPT is a prompt string. If nil, do not prompt specially.
|
98
|
4593 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echoes
|
0
|
4594 as a continuation of the previous key.
|
|
4595
|
|
4596 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not
|
|
4597 convert the last event to lower case. (Normally any upper case event
|
|
4598 is converted to lower case if the original event is undefined and the lower
|
|
4599 case equivalent is defined.) This argument is provided mostly for
|
|
4600 FSF compatibility; the equivalent effect can be achieved more generally
|
|
4601 by binding `retry-undefined-key-binding-unshifted' to nil around the
|
|
4602 call to `read-key-sequence'.
|
|
4603
|
|
4604 A C-g typed while in this function is treated like any other character,
|
|
4605 and `quit-flag' is not set.
|
|
4606
|
|
4607 If the user selects a menu item while we are prompting for a key-sequence,
|
|
4608 the returned value will be a vector of a single menu-selection event.
|
|
4609 An error will be signalled if you pass this value to `lookup-key' or a
|
|
4610 related function.
|
|
4611
|
|
4612 `read-key-sequence' checks `function-key-map' for function key
|
|
4613 sequences, where they wouldn't conflict with ordinary bindings. See
|
|
4614 `function-key-map' for more details.
|
20
|
4615 */
|
|
4616 (prompt, continue_echo, dont_downcase_last))
|
0
|
4617 {
|
|
4618 /* This function can GC */
|
|
4619 struct console *con = XCONSOLE (Vselected_console); /* #### correct?
|
|
4620 Probably not -- see
|
|
4621 comment in
|
|
4622 next-event */
|
|
4623 struct command_builder *command_builder =
|
|
4624 XCOMMAND_BUILDER (con->command_builder);
|
|
4625 Lisp_Object result;
|
189
|
4626 Lisp_Object event = Fmake_event (Qnil, Qnil);
|
0
|
4627 int speccount = specpdl_depth ();
|
|
4628 struct gcpro gcpro1;
|
|
4629 GCPRO1 (event);
|
|
4630
|
|
4631 if (!NILP (prompt))
|
|
4632 CHECK_STRING (prompt);
|
|
4633 /* else prompt = Fkeymap_prompt (current_buffer->keymap); may GC */
|
|
4634 QUIT;
|
|
4635
|
|
4636 if (NILP (continue_echo))
|
|
4637 reset_this_command_keys (make_console (con), 1);
|
|
4638
|
|
4639 specbind (Qinhibit_quit, Qt);
|
|
4640
|
|
4641 if (!NILP (dont_downcase_last))
|
|
4642 specbind (Qretry_undefined_key_binding_unshifted, Qnil);
|
|
4643
|
|
4644 for (;;)
|
|
4645 {
|
|
4646 Fnext_event (event, prompt);
|
|
4647 /* restore the selected-console damage */
|
|
4648 con = event_console_or_selected (event);
|
|
4649 command_builder = XCOMMAND_BUILDER (con->command_builder);
|
|
4650 if (! command_event_p (event))
|
|
4651 execute_internal_event (event);
|
|
4652 else
|
|
4653 {
|
|
4654 if (XEVENT (event)->event_type == misc_user_event)
|
|
4655 reset_current_events (command_builder);
|
|
4656 result = lookup_command_event (command_builder, event, 1);
|
|
4657 if (!KEYMAPP (result))
|
|
4658 {
|
|
4659 result = current_events_into_vector (command_builder);
|
|
4660 reset_key_echo (command_builder, 0);
|
|
4661 break;
|
|
4662 }
|
|
4663 prompt = Qnil;
|
|
4664 }
|
|
4665 }
|
|
4666
|
|
4667 Vquit_flag = Qnil; /* In case we read a ^G; do not call check_quit() here */
|
|
4668 Fdeallocate_event (event);
|
|
4669 RETURN_UNGCPRO (unbind_to (speccount, result));
|
|
4670 }
|
|
4671
|
20
|
4672 DEFUN ("this-command-keys", Fthis_command_keys, 0, 0, 0, /*
|
0
|
4673 Return a vector of the keyboard or mouse button events that were used
|
|
4674 to invoke this command. This copies the vector and the events; it is safe
|
|
4675 to keep and modify them.
|
20
|
4676 */
|
|
4677 ())
|
0
|
4678 {
|
|
4679 Lisp_Object event;
|
|
4680 Lisp_Object result;
|
|
4681 int len;
|
|
4682
|
|
4683 if (NILP (Vthis_command_keys))
|
173
|
4684 return make_vector (0, Qnil);
|
0
|
4685
|
|
4686 len = event_chain_count (Vthis_command_keys);
|
|
4687
|
|
4688 result = make_vector (len, Qnil);
|
|
4689 len = 0;
|
|
4690 EVENT_CHAIN_LOOP (event, Vthis_command_keys)
|
173
|
4691 XVECTOR_DATA (result)[len++] = Fcopy_event (event, Qnil);
|
|
4692 return result;
|
0
|
4693 }
|
|
4694
|
20
|
4695 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths, 0, 0, 0, /*
|
0
|
4696 Used for complicated reasons in `universal-argument-other-key'.
|
|
4697
|
|
4698 `universal-argument-other-key' rereads the event just typed.
|
|
4699 It then gets translated through `function-key-map'.
|
|
4700 The translated event gets included in the echo area and in
|
|
4701 the value of `this-command-keys' in addition to the raw original event.
|
|
4702 That is not right.
|
|
4703
|
|
4704 Calling this function directs the translated event to replace
|
|
4705 the original event, so that only one version of the event actually
|
|
4706 appears in the echo area and in the value of `this-command-keys.'.
|
20
|
4707 */
|
|
4708 ())
|
0
|
4709 {
|
|
4710 /* #### I don't understand this at all, so currently it does nothing.
|
|
4711 If there is ever a problem, maybe someone should investigate. */
|
|
4712 return Qnil;
|
|
4713 }
|
|
4714
|
|
4715
|
|
4716 static void
|
|
4717 dribble_out_event (Lisp_Object event)
|
|
4718 {
|
|
4719 if (NILP (Vdribble_file))
|
|
4720 return;
|
|
4721
|
|
4722 if (XEVENT (event)->event_type == key_press_event &&
|
|
4723 !XEVENT (event)->event.key.modifiers)
|
|
4724 {
|
|
4725 Lisp_Object keysym = XEVENT (event)->event.key.keysym;
|
|
4726 if (CHARP (XEVENT (event)->event.key.keysym))
|
|
4727 {
|
|
4728 Emchar ch = XCHAR (keysym);
|
|
4729 Bufbyte str[MAX_EMCHAR_LEN];
|
|
4730 Bytecount len;
|
173
|
4731
|
0
|
4732 len = set_charptr_emchar (str, ch);
|
|
4733 Lstream_write (XLSTREAM (Vdribble_file), str, len);
|
|
4734 }
|
|
4735 else if (string_char_length (XSYMBOL (keysym)->name) == 1)
|
|
4736 /* one-char key events are printed with just the key name */
|
|
4737 Fprinc (keysym, Vdribble_file);
|
|
4738 else if (EQ (keysym, Qreturn))
|
|
4739 Lstream_putc (XLSTREAM (Vdribble_file), '\n');
|
|
4740 else if (EQ (keysym, Qspace))
|
|
4741 Lstream_putc (XLSTREAM (Vdribble_file), ' ');
|
|
4742 else
|
|
4743 Fprinc (event, Vdribble_file);
|
|
4744 }
|
|
4745 else
|
|
4746 Fprinc (event, Vdribble_file);
|
|
4747 Lstream_flush (XLSTREAM (Vdribble_file));
|
|
4748 }
|
|
4749
|
20
|
4750 DEFUN ("open-dribble-file", Fopen_dribble_file, 1, 1,
|
|
4751 "FOpen dribble file: ", /*
|
0
|
4752 Start writing all keyboard characters to a dribble file called FILE.
|
|
4753 If FILE is nil, close any open dribble file.
|
20
|
4754 */
|
|
4755 (file))
|
0
|
4756 {
|
|
4757 /* This function can GC */
|
|
4758 /* XEmacs change: always close existing dribble file. */
|
|
4759 /* FSFmacs uses FILE *'s here. With lstreams, that's unnecessary. */
|
|
4760 if (!NILP (Vdribble_file))
|
|
4761 {
|
|
4762 Lstream_close (XLSTREAM (Vdribble_file));
|
|
4763 Vdribble_file = Qnil;
|
|
4764 }
|
|
4765 if (!NILP (file))
|
|
4766 {
|
|
4767 int fd;
|
|
4768
|
|
4769 file = Fexpand_file_name (file, Qnil);
|
14
|
4770 fd = creat ((char *) XSTRING_DATA (file), 0666);
|
0
|
4771 if (fd < 0)
|
|
4772 error ("Unable to create dribble file");
|
|
4773 Vdribble_file = make_filedesc_output_stream (fd, 0, 0, LSTR_CLOSING);
|
70
|
4774 #ifdef MULE
|
|
4775 Vdribble_file =
|
|
4776 make_encoding_output_stream (XLSTREAM (Vdribble_file),
|
|
4777 Fget_coding_system (Qescape_quoted));
|
|
4778 #endif
|
0
|
4779 }
|
|
4780 return Qnil;
|
|
4781 }
|
|
4782
|
|
4783
|
|
4784 /************************************************************************/
|
|
4785 /* initialization */
|
|
4786 /************************************************************************/
|
|
4787
|
|
4788 void
|
|
4789 syms_of_event_stream (void)
|
|
4790 {
|
|
4791 defsymbol (&Qdisabled, "disabled");
|
|
4792 defsymbol (&Qcommand_event_p, "command-event-p");
|
|
4793
|
|
4794 deferror (&Qundefined_keystroke_sequence, "undefined-keystroke-sequence",
|
|
4795 "Undefined keystroke sequence", Qerror);
|
|
4796 defsymbol (&Qcommand_execute, "command-execute");
|
|
4797
|
20
|
4798 DEFSUBR (Frecent_keys);
|
153
|
4799 DEFSUBR (Frecent_keys_ring_size);
|
|
4800 DEFSUBR (Fset_recent_keys_ring_size);
|
20
|
4801 DEFSUBR (Finput_pending_p);
|
|
4802 DEFSUBR (Fenqueue_eval_event);
|
|
4803 DEFSUBR (Fnext_event);
|
|
4804 DEFSUBR (Fnext_command_event);
|
|
4805 DEFSUBR (Fdiscard_input);
|
|
4806 DEFSUBR (Fsit_for);
|
|
4807 DEFSUBR (Fsleep_for);
|
|
4808 DEFSUBR (Faccept_process_output);
|
|
4809 DEFSUBR (Fadd_timeout);
|
|
4810 DEFSUBR (Fdisable_timeout);
|
|
4811 DEFSUBR (Fadd_async_timeout);
|
|
4812 DEFSUBR (Fdisable_async_timeout);
|
|
4813 DEFSUBR (Fdispatch_event);
|
|
4814 DEFSUBR (Fread_key_sequence);
|
|
4815 DEFSUBR (Fthis_command_keys);
|
|
4816 DEFSUBR (Freset_this_command_lengths);
|
|
4817 DEFSUBR (Fopen_dribble_file);
|
181
|
4818 #if defined(HAVE_X_WINDOWS) && defined(HAVE_MENUBARS)
|
177
|
4819 DEFSUBR (Faccelerate_menu);
|
179
|
4820 #endif
|
0
|
4821
|
|
4822 defsymbol (&Qpre_command_hook, "pre-command-hook");
|
|
4823 defsymbol (&Qpost_command_hook, "post-command-hook");
|
|
4824 defsymbol (&Qunread_command_events, "unread-command-events");
|
|
4825 defsymbol (&Qunread_command_event, "unread-command-event");
|
|
4826 defsymbol (&Qpre_idle_hook, "pre-idle-hook");
|
|
4827 #ifdef ILL_CONCEIVED_HOOK
|
|
4828 defsymbol (&Qpost_command_idle_hook, "post-command-idle-hook");
|
|
4829 #endif
|
|
4830 #ifdef DEFERRED_ACTION_CRAP
|
|
4831 defsymbol (&Qdeferred_action_function, "deferred-action-function");
|
|
4832 #endif
|
|
4833 defsymbol (&Qretry_undefined_key_binding_unshifted,
|
|
4834 "retry-undefined-key-binding-unshifted");
|
|
4835 defsymbol (&Qauto_show_make_point_visible,
|
|
4836 "auto-show-make-point-visible");
|
175
|
4837
|
|
4838 defsymbol (&Qmenu_force, "menu-force");
|
|
4839 defsymbol (&Qmenu_fallback, "menu-fallback");
|
185
|
4840
|
175
|
4841 defsymbol (&Qmenu_quit, "menu-quit");
|
|
4842 defsymbol (&Qmenu_up, "menu-up");
|
|
4843 defsymbol (&Qmenu_down, "menu-down");
|
|
4844 defsymbol (&Qmenu_left, "menu-left");
|
|
4845 defsymbol (&Qmenu_right, "menu-right");
|
|
4846 defsymbol (&Qmenu_select, "menu-select");
|
|
4847 defsymbol (&Qmenu_escape, "menu-escape");
|
0
|
4848 }
|
|
4849
|
|
4850 void
|
|
4851 vars_of_event_stream (void)
|
|
4852 {
|
|
4853 #ifdef HAVE_X_WINDOWS
|
|
4854 vars_of_event_Xt ();
|
|
4855 #endif
|
|
4856 #if defined (DEBUG_TTY_EVENT_STREAM) || !defined (HAVE_X_WINDOWS)
|
|
4857 vars_of_event_tty ();
|
|
4858 #endif
|
|
4859
|
|
4860
|
|
4861 recent_keys_ring_index = 0;
|
153
|
4862 recent_keys_ring_size = 100;
|
|
4863 Vrecent_keys_ring = Qnil;
|
|
4864 staticpro (&Vrecent_keys_ring);
|
0
|
4865
|
|
4866 Vthis_command_keys = Qnil;
|
|
4867 staticpro (&Vthis_command_keys);
|
|
4868 Vthis_command_keys_tail = Qnil;
|
|
4869
|
|
4870 num_input_chars = 0;
|
173
|
4871
|
0
|
4872 command_event_queue = Qnil;
|
|
4873 staticpro (&command_event_queue);
|
|
4874 command_event_queue_tail = Qnil;
|
|
4875
|
|
4876 Vlast_selected_frame = Qnil;
|
|
4877 staticpro (&Vlast_selected_frame);
|
|
4878
|
|
4879 pending_timeout_list = Qnil;
|
|
4880 staticpro (&pending_timeout_list);
|
|
4881
|
|
4882 pending_async_timeout_list = Qnil;
|
|
4883 staticpro (&pending_async_timeout_list);
|
|
4884
|
|
4885 Vtimeout_free_list = make_opaque_list (sizeof (struct timeout),
|
|
4886 mark_timeout);
|
|
4887 staticpro (&Vtimeout_free_list);
|
|
4888
|
|
4889 the_low_level_timeout_blocktype =
|
|
4890 Blocktype_new (struct low_level_timeout_blocktype);
|
|
4891
|
|
4892 something_happened = 0;
|
|
4893
|
|
4894 last_point_position_buffer = Qnil;
|
|
4895 staticpro (&last_point_position_buffer);
|
|
4896
|
108
|
4897 recursive_sit_for = Qnil;
|
|
4898
|
0
|
4899 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes /*
|
|
4900 *Nonzero means echo unfinished commands after this many seconds of pause.
|
|
4901 */ );
|
|
4902 echo_keystrokes = 1;
|
|
4903
|
|
4904 DEFVAR_INT ("auto-save-interval", &auto_save_interval /*
|
|
4905 *Number of keyboard input characters between auto-saves.
|
|
4906 Zero means disable autosaving due to number of characters typed.
|
|
4907 See also the variable `auto-save-timeout'.
|
|
4908 */ );
|
|
4909 auto_save_interval = 300;
|
|
4910
|
|
4911 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook /*
|
|
4912 Function or functions to run before every command.
|
|
4913 This may examine the `this-command' variable to find out what command
|
|
4914 is about to be run, or may change it to cause a different command to run.
|
|
4915 Function on this hook must be careful to avoid signalling errors!
|
|
4916 */ );
|
|
4917 Vpre_command_hook = Qnil;
|
|
4918
|
|
4919 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook /*
|
|
4920 Function or functions to run after every command.
|
|
4921 This may examine the `this-command' variable to find out what command
|
|
4922 was just executed.
|
|
4923 */ );
|
|
4924 Vpost_command_hook = Qnil;
|
|
4925
|
|
4926 DEFVAR_LISP ("pre-idle-hook", &Vpre_idle_hook /*
|
|
4927 Normal hook run when XEmacs it about to be idle.
|
|
4928 This occurs whenever it is going to block, waiting for an event.
|
|
4929 This generally happens as a result of a call to `next-event',
|
|
4930 `next-command-event', `sit-for', `sleep-for', `accept-process-output',
|
|
4931 `x-get-selection', or various Energize-specific commands.
|
|
4932 Errors running the hook are caught and ignored.
|
|
4933 */ );
|
|
4934 Vpre_idle_hook = Qnil;
|
|
4935
|
72
|
4936 DEFVAR_BOOL ("focus-follows-mouse", &focus_follows_mouse /*
|
142
|
4937 *Variable to control XEmacs behavior with respect to focus changing.
|
72
|
4938 If this variable is set to t, then XEmacs will not gratuitously change
|
142
|
4939 the keyboard focus. XEmacs cannot in general detect when this mode is
|
|
4940 use by the window manager, so it is up to the user to set it.
|
72
|
4941 */ );
|
|
4942 focus_follows_mouse = 0;
|
|
4943
|
0
|
4944 #ifdef ILL_CONCEIVED_HOOK
|
|
4945 /* Ill-conceived because it's not run in all sorts of cases
|
|
4946 where XEmacs is blocking. That's what `pre-idle-hook'
|
|
4947 is designed to solve. */
|
|
4948 xxDEFVAR_LISP ("post-command-idle-hook", &Vpost_command_idle_hook /*
|
|
4949 Normal hook run after each command is executed, if idle.
|
|
4950 `post-command-idle-delay' specifies a time in microseconds that XEmacs
|
|
4951 must be idle for in order for the functions on this hook to be called.
|
|
4952 Errors running the hook are caught and ignored.
|
|
4953 */ );
|
|
4954 Vpost_command_idle_hook = Qnil;
|
|
4955
|
|
4956 xxDEFVAR_INT ("post-command-idle-delay", &post_command_idle_delay /*
|
|
4957 Delay time before running `post-command-idle-hook'.
|
|
4958 This is measured in microseconds.
|
|
4959 */ );
|
|
4960 post_command_idle_delay = 5000;
|
|
4961 #endif /* ILL_CONCEIVED_HOOK */
|
|
4962
|
|
4963 #ifdef DEFERRED_ACTION_CRAP
|
|
4964 /* Random FSFmacs crap. There is absolutely nothing to gain,
|
|
4965 and a great deal to lose, in using this in place of just
|
|
4966 setting `post-command-hook'. */
|
|
4967 xxDEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list /*
|
|
4968 List of deferred actions to be performed at a later time.
|
|
4969 The precise format isn't relevant here; we just check whether it is nil.
|
|
4970 */ );
|
|
4971 Vdeferred_action_list = Qnil;
|
|
4972
|
|
4973 xxDEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function /*
|
|
4974 Function to call to handle deferred actions, after each command.
|
|
4975 This function is called with no arguments after each command
|
|
4976 whenever `deferred-action-list' is non-nil.
|
|
4977 */ );
|
|
4978 Vdeferred_action_function = Qnil;
|
|
4979 #endif /* DEFERRED_ACTION_CRAP */
|
|
4980
|
|
4981 DEFVAR_LISP ("last-command-event", &Vlast_command_event /*
|
|
4982 Last keyboard or mouse button event that was part of a command. This
|
|
4983 variable is off limits: you may not set its value or modify the event that
|
|
4984 is its value, as it is destructively modified by `read-key-sequence'. If
|
|
4985 you want to keep a pointer to this value, you must use `copy-event'.
|
|
4986 */ );
|
|
4987 Vlast_command_event = Qnil;
|
|
4988
|
|
4989 DEFVAR_LISP ("last-command-char", &Vlast_command_char /*
|
|
4990 If the value of `last-command-event' is a keyboard event, then
|
2
|
4991 this is the nearest ASCII equivalent to it. This is the value that
|
0
|
4992 `self-insert-command' will put in the buffer. Remember that there is
|
|
4993 NOT a 1:1 mapping between keyboard events and ASCII characters: the set
|
|
4994 of keyboard events is much larger, so writing code that examines this
|
|
4995 variable to determine what key has been typed is bad practice, unless
|
|
4996 you are certain that it will be one of a small set of characters.
|
|
4997 */ );
|
|
4998 Vlast_command_char = Qnil;
|
|
4999
|
|
5000 DEFVAR_LISP ("last-input-event", &Vlast_input_event /*
|
|
5001 Last keyboard or mouse button event received. This variable is off
|
|
5002 limits: you may not set its value or modify the event that is its value, as
|
|
5003 it is destructively modified by `next-event'. If you want to keep a pointer
|
|
5004 to this value, you must use `copy-event'.
|
|
5005 */ );
|
|
5006 Vlast_input_event = Qnil;
|
|
5007
|
|
5008 DEFVAR_LISP ("current-mouse-event", &Vcurrent_mouse_event /*
|
|
5009 The mouse-button event which invoked this command, or nil.
|
185
|
5010 This is usually what `(interactive "e")' returns.
|
0
|
5011 */ );
|
|
5012 Vcurrent_mouse_event = Qnil;
|
|
5013
|
|
5014 DEFVAR_LISP ("last-input-char", &Vlast_input_char /*
|
|
5015 If the value of `last-input-event' is a keyboard event, then
|
|
5016 this is the nearest ASCII equivalent to it. Remember that there is
|
|
5017 NOT a 1:1 mapping between keyboard events and ASCII characters: the set
|
|
5018 of keyboard events is much larger, so writing code that examines this
|
|
5019 variable to determine what key has been typed is bad practice, unless
|
|
5020 you are certain that it will be one of a small set of characters.
|
|
5021 */ );
|
|
5022 Vlast_input_char = Qnil;
|
|
5023
|
|
5024 DEFVAR_LISP ("last-input-time", &Vlast_input_time /*
|
|
5025 The time (in seconds since Jan 1, 1970) of the last-command-event,
|
|
5026 represented as a cons of two 16-bit integers. This is destructively
|
|
5027 modified, so copy it if you want to keep it.
|
|
5028 */ );
|
|
5029 Vlast_input_time = Qnil;
|
|
5030
|
|
5031 DEFVAR_LISP ("unread-command-events", &Vunread_command_events /*
|
|
5032 List of event objects to be read as next command input events.
|
|
5033 This can be used to simulate the receipt of events from the user.
|
|
5034 Normally this is nil.
|
|
5035 Events are removed from the front of this list.
|
|
5036 */ );
|
|
5037 Vunread_command_events = Qnil;
|
|
5038
|
|
5039 DEFVAR_LISP ("unread-command-event", &Vunread_command_event /*
|
|
5040 Obsolete. Use `unread-command-events' instead.
|
|
5041 */ );
|
|
5042 Vunread_command_event = Qnil;
|
|
5043
|
|
5044 DEFVAR_LISP ("last-command", &Vlast_command /*
|
|
5045 The last command executed. Normally a symbol with a function definition,
|
|
5046 but can be whatever was found in the keymap, or whatever the variable
|
|
5047 `this-command' was set to by that command.
|
|
5048 */ );
|
|
5049 Vlast_command = Qnil;
|
|
5050
|
|
5051 DEFVAR_LISP ("this-command", &Vthis_command /*
|
|
5052 The command now being executed.
|
|
5053 The command can set this variable; whatever is put here
|
|
5054 will be in `last-command' during the following command.
|
|
5055 */ );
|
|
5056 Vthis_command = Qnil;
|
|
5057
|
|
5058 DEFVAR_LISP ("help-char", &Vhelp_char /*
|
|
5059 Character to recognize as meaning Help.
|
|
5060 When it is read, do `(eval help-form)', and display result if it's a string.
|
|
5061 If the value of `help-form' is nil, this char can be read normally.
|
|
5062 This can be any form recognized as a single key specifier.
|
98
|
5063 The help-char cannot be a negative number in XEmacs.
|
0
|
5064 */ );
|
|
5065 Vhelp_char = make_char (8); /* C-h */
|
|
5066
|
|
5067 DEFVAR_LISP ("help-form", &Vhelp_form /*
|
|
5068 Form to execute when character help-char is read.
|
|
5069 If the form returns a string, that string is displayed.
|
|
5070 If `help-form' is nil, the help char is not recognized.
|
|
5071 */ );
|
|
5072 Vhelp_form = Qnil;
|
|
5073
|
|
5074 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command /*
|
|
5075 Command to run when `help-char' character follows a prefix key.
|
|
5076 This command is used only when there is no actual binding
|
|
5077 for that character after that prefix key.
|
|
5078 */ );
|
|
5079 Vprefix_help_command = Qnil;
|
|
5080
|
|
5081 DEFVAR_CONST_LISP ("keyboard-translate-table", &Vkeyboard_translate_table /*
|
|
5082 Hash table used as translate table for keyboard input.
|
|
5083 Use `keyboard-translate' to portably add entries to this table.
|
|
5084 Each key-press event is looked up in this table as follows:
|
|
5085
|
|
5086 -- If an entry maps a symbol to a symbol, then a key-press event whose
|
|
5087 keysym is the former symbol (with any modifiers at all) gets its
|
|
5088 keysym changed and its modifiers left alone. This is useful for
|
|
5089 dealing with non-standard X keyboards, such as the grievous damage
|
|
5090 that Sun has inflicted upon the world.
|
|
5091 -- If an entry maps a character to a character, then a key-press event
|
|
5092 matching the former character gets converted to a key-press event
|
|
5093 matching the latter character. This is useful on ASCII terminals
|
|
5094 for (e.g.) making C-\\ look like C-s, to get around flow-control
|
|
5095 problems.
|
|
5096 -- If an entry maps a character to a symbol, then a key-press event
|
|
5097 matching the character gets converted to a key-press event whose
|
|
5098 keysym is the given symbol and which has no modifiers.
|
|
5099 */ );
|
|
5100
|
|
5101 DEFVAR_LISP ("retry-undefined-key-binding-unshifted",
|
|
5102 &Vretry_undefined_key_binding_unshifted /*
|
|
5103 If a key-sequence which ends with a shifted keystroke is undefined
|
|
5104 and this variable is non-nil then the command lookup is retried again
|
|
5105 with the last key unshifted. (e.g. C-X C-F would be retried as C-X C-f.)
|
|
5106 If lookup still fails, a normal error is signalled. In general,
|
|
5107 you should *bind* this, not set it.
|
|
5108 */ );
|
|
5109 Vretry_undefined_key_binding_unshifted = Qt;
|
|
5110
|
70
|
5111 #ifdef HAVE_XIM
|
|
5112 DEFVAR_LISP ("Vcomposed_character_default_binding",
|
173
|
5113 &Vretry_undefined_key_binding_unshifted /*
|
70
|
5114 The default keybinding to use for key events from composed input.
|
|
5115 Window systems frequently have ways to allow the user to compose
|
|
5116 single characters in a language using multiple keystrokes.
|
|
5117 XEmacs sees these as single character keypress events.
|
|
5118 */ );
|
|
5119 Vcomposed_character_default_binding = Qself_insert_command;
|
|
5120 #endif /* HAVE_XIM */
|
|
5121
|
0
|
5122 Vcontrolling_terminal = Qnil;
|
|
5123 staticpro (&Vcontrolling_terminal);
|
|
5124
|
|
5125 Vdribble_file = Qnil;
|
|
5126 staticpro (&Vdribble_file);
|
|
5127
|
|
5128 #ifdef DEBUG_XEMACS
|
|
5129 DEFVAR_INT ("debug-emacs-events", &debug_emacs_events /*
|
|
5130 If non-zero, display debug information about Emacs events that XEmacs sees.
|
|
5131 Information is displayed on stderr.
|
|
5132
|
|
5133 Before the event, the source of the event is displayed in parentheses,
|
|
5134 and is one of the following:
|
|
5135
|
|
5136 \(real) A real event from the window system or
|
|
5137 terminal driver, as far as XEmacs can tell.
|
|
5138
|
|
5139 \(keyboard macro) An event generated from a keyboard macro.
|
|
5140
|
|
5141 \(unread-command-events) An event taken from `unread-command-events'.
|
|
5142
|
|
5143 \(unread-command-event) An event taken from `unread-command-event'.
|
|
5144
|
|
5145 \(command event queue) An event taken from an internal queue.
|
|
5146 Events end up on this queue when
|
|
5147 `enqueue-eval-event' is called or when
|
|
5148 user or eval events are received while
|
|
5149 XEmacs is blocking (e.g. in `sit-for',
|
|
5150 `sleep-for', or `accept-process-output',
|
|
5151 or while waiting for the reply to an
|
|
5152 X selection).
|
|
5153
|
|
5154 \(->keyboard-translate-table) The result of an event translated through
|
|
5155 keyboard-translate-table. Note that in
|
|
5156 this case, two events are printed even
|
|
5157 though only one is really generated.
|
|
5158
|
|
5159 \(SIGINT) A faked C-g resulting when XEmacs receives
|
|
5160 a SIGINT (e.g. C-c was pressed in XEmacs'
|
|
5161 controlling terminal or the signal was
|
|
5162 explicitly sent to the XEmacs process).
|
|
5163 */ );
|
|
5164 debug_emacs_events = 0;
|
|
5165 #endif
|
175
|
5166
|
187
|
5167 DEFVAR_BOOL ("inhibit-input-event-recording", &inhibit_input_event_recording /*
|
|
5168 Non-nil inhibits recording of input-events to recent-keys ring.
|
|
5169 */ );
|
|
5170 inhibit_input_event_recording = 0;
|
|
5171
|
175
|
5172 DEFVAR_LISP("menu-accelerator-prefix", &Vmenu_accelerator_prefix /*
|
|
5173 Prefix key(s) that must be typed before menu accelerators will be activated.
|
|
5174 Set this to a value acceptable by define-key.
|
|
5175 */ );
|
|
5176 Vmenu_accelerator_prefix = Qnil;
|
|
5177
|
|
5178 DEFVAR_LISP ("menu-accelerator-modifiers", &Vmenu_accelerator_modifiers /*
|
|
5179 Modifier keys which must be pressed to get to the top level menu accelerators.
|
|
5180 This is a list of modifier key symbols. All modifier keys must be held down
|
|
5181 while a valid menu accelerator key is pressed in order for the top level
|
|
5182 menu to become active.
|
|
5183
|
|
5184 See also menu-accelerator-enabled and menu-accelerator-prefix.
|
|
5185 */ );
|
|
5186 Vmenu_accelerator_modifiers = list1 (Qmeta);
|
185
|
5187
|
175
|
5188 DEFVAR_LISP ("menu-accelerator-enabled", &Vmenu_accelerator_enabled /*
|
|
5189 Whether menu accelerator keys can cause the menubar to become active.
|
|
5190 If 'menu-force or 'menu-fallback, then menu accelerator keys can
|
|
5191 be used to activate the top level menu. Once the menubar becomes active, the
|
|
5192 accelerator keys can be used regardless of the value of this variable.
|
|
5193
|
|
5194 menu-force is used to indicate that the menu accelerator key takes
|
|
5195 precedence over bindings in the current keymap(s). menu-fallback means
|
|
5196 that bindings in the current keymap take precedence over menu accelerator keys.
|
185
|
5197 Thus a top level menu with an accelerator of "T" would be activated on a
|
175
|
5198 keypress of Meta-t if menu-accelerator-enabled is menu-force.
|
|
5199 However, if menu-accelerator-enabled is menu-fallback, then
|
|
5200 Meta-t will not activate the menubar and will instead run the function
|
|
5201 transpose-words, to which it is normally bound.
|
|
5202
|
|
5203 See also menu-accelerator-modifiers and menu-accelerator-prefix.
|
|
5204 */ );
|
|
5205 Vmenu_accelerator_enabled = Qnil;
|
0
|
5206 }
|
|
5207
|
|
5208 void
|
|
5209 complex_vars_of_event_stream (void)
|
|
5210 {
|
|
5211 Vkeyboard_translate_table = Fmake_hashtable (make_int (100), Qnil);
|
175
|
5212
|
|
5213 DEFVAR_LISP ("menu-accelerator-map", &Vmenu_accelerator_map /*
|
|
5214 Keymap for use when the menubar is active.
|
|
5215 The actions menu-quit, menu-up, menu-down, menu-left, menu-right,
|
|
5216 menu-select and menu-escape can be mapped to keys in this map.
|
|
5217
|
|
5218 menu-quit Immediately deactivate the menubar and any open submenus without
|
|
5219 selecting an item.
|
|
5220 menu-up Move the menu cursor up one row in the current menu. If the
|
|
5221 move extends past the top of the menu, wrap around to the bottom.
|
|
5222 menu-down Move the menu cursor down one row in the current menu. If the
|
|
5223 move extends past the bottom of the menu, wrap around to the top.
|
|
5224 If executed while the cursor is in the top level menu, move down
|
|
5225 into the selected menu.
|
|
5226 menu-left Move the cursor from a submenu into the parent menu. If executed
|
|
5227 while the cursor is in the top level menu, move the cursor to the
|
|
5228 left. If the move extends past the left edge of the menu, wrap
|
|
5229 around to the right edge.
|
|
5230 menu-right Move the cursor into a submenu. If the cursor is located in the
|
|
5231 top level menu or is not currently on a submenu heading, then move
|
|
5232 the cursor to the next top level menu entry. If the move extends
|
|
5233 past the right edge of the menu, wrap around to the left edge.
|
|
5234 menu-select Activate the item under the cursor. If the cursor is located on
|
|
5235 a submenu heading, then move the cursor into the submenu.
|
|
5236 menu-escape Pop up to the next level of menus. Moves from a submenu into its
|
|
5237 parent menu. From the top level menu, this deactivates the
|
|
5238 menubar.
|
|
5239
|
|
5240 This keymap can also contain normal key-command bindings, in which case the
|
|
5241 menubar is deactivated and the corresponding command is executed.
|
|
5242
|
|
5243 The action bindings used by the menu accelerator code are designed to mimic
|
|
5244 the actions of menu traversal keys in a commonly used PC operating system.
|
|
5245 */ );
|
|
5246 Vmenu_accelerator_map = Fmake_keymap(Qnil);
|
0
|
5247 }
|
|
5248
|
|
5249 void
|
|
5250 init_event_stream (void)
|
|
5251 {
|
|
5252 if (initialized)
|
|
5253 {
|
|
5254 #ifdef HAVE_UNIXOID_EVENT_LOOP
|
|
5255 init_event_unixoid ();
|
|
5256 #endif
|
|
5257
|
|
5258 #ifdef HAVE_X_WINDOWS
|
|
5259 if (!strcmp (display_use, "x"))
|
|
5260 init_event_Xt_late ();
|
|
5261 else
|
|
5262 #endif
|
|
5263 {
|
|
5264 /* For TTY's, use the Xt event loop if we can; it allows
|
|
5265 us to later open an X connection. */
|
|
5266 #if defined (HAVE_X_WINDOWS) && !defined (DEBUG_TTY_EVENT_STREAM)
|
|
5267 init_event_Xt_late ();
|
|
5268 #else
|
|
5269 init_event_tty_late ();
|
|
5270 #endif
|
|
5271 }
|
|
5272 init_interrupts_late ();
|
|
5273 }
|
|
5274 }
|
|
5275
|
|
5276
|
|
5277 /*
|
|
5278 useful testcases for v18/v19 compatibility:
|
|
5279
|
|
5280 (defun foo ()
|
|
5281 (interactive)
|
|
5282 (setq unread-command-event (character-to-event ?A (allocate-event)))
|
|
5283 (setq x (list (read-char)
|
|
5284 ; (read-key-sequence "") ; try it with and without this
|
|
5285 last-command-char last-input-char
|
|
5286 (recent-keys) (this-command-keys))))
|
|
5287 (global-set-key "\^Q" 'foo)
|
|
5288
|
|
5289 without the read-key-sequence:
|
|
5290 ^Q ==> (65 17 65 [... ^Q] [^Q])
|
|
5291 ^U^U^Q ==> (65 17 65 [... ^U ^U ^Q] [^U ^U ^Q])
|
|
5292 ^U^U^U^G^Q ==> (65 17 65 [... ^U ^U ^U ^G ^Q] [^Q])
|
|
5293
|
|
5294 with the read-key-sequence:
|
|
5295 ^Qb ==> (65 [b] 17 98 [... ^Q b] [b])
|
|
5296 ^U^U^Qb ==> (65 [b] 17 98 [... ^U ^U ^Q b] [b])
|
|
5297 ^U^U^U^G^Qb ==> (65 [b] 17 98 [... ^U ^U ^U ^G ^Q b] [b])
|
|
5298
|
|
5299 ;the evi-mode command "4dlj.j.j.j.j.j." is also a good testcase (gag)
|
|
5300
|
|
5301 ;(setq x (list (read-char) quit-flag))^J^G
|
|
5302 ;(let ((inhibit-quit t)) (setq x (list (read-char) quit-flag)))^J^G
|
|
5303 ;for BOTH, x should get set to (7 t), but no result should be printed.
|
|
5304
|
|
5305 ;also do this: make two frames, one viewing "*scratch*", the other "foo".
|
|
5306 ;in *scratch*, type (sit-for 20)^J
|
|
5307 ;wait a couple of seconds, move cursor to foo, type "a"
|
|
5308 ;a should be inserted in foo. Cursor highlighting should not change in
|
|
5309 ;the meantime.
|
|
5310
|
|
5311 ;do it with sleep-for. move cursor into foo, then back into *scratch*
|
|
5312 ;before typing.
|
108
|
5313 ;repeat also with (accept-process-output nil 20)
|
|
5314
|
|
5315 ;make sure ^G aborts sit-for, sleep-for and accept-process-output:
|
0
|
5316
|
|
5317 (defun tst ()
|
|
5318 (list (condition-case c
|
|
5319 (sleep-for 20)
|
|
5320 (quit c))
|
|
5321 (read-char)))
|
|
5322
|
|
5323 (tst)^Ja^G ==> ((quit) 97) with no signal
|
|
5324 (tst)^J^Ga ==> ((quit) 97) with no signal
|
|
5325 (tst)^Jabc^G ==> ((quit) 97) with no signal, and "bc" inserted in buffer
|
|
5326
|
108
|
5327 ; with sit-for only do the 2nd test.
|
|
5328 ; Do all 3 tests with (accept-proccess-output nil 20)
|
|
5329
|
0
|
5330 Do this:
|
|
5331 (setq enable-recursive-minibuffers t
|
|
5332 minibuffer-max-depth nil)
|
|
5333 ESC ESC ESC ESC - there are now two minibuffers active
|
|
5334 C-g C-g C-g - there should be active 0, not 1
|
|
5335 Similarly:
|
|
5336 C-x C-f ~ / ? - wait for "Making completion list..." to display
|
|
5337 C-g - wait for "Quit" to display
|
|
5338 C-g - minibuffer should not be active
|
|
5339 however C-g before "Quit" is displayed should leave minibuffer active.
|
|
5340
|
|
5341 ;do it all in both v18 and v19 and make sure all results are the same.
|
|
5342 ;all of these cases matter a lot, but some in quite subtle ways.
|
|
5343 */
|
108
|
5344
|
|
5345 /*
|
|
5346 Additional test cases for accept-process-output, sleep-for, sit-for.
|
|
5347 Be sure you do all of the above checking for C-g and focus, too!
|
|
5348
|
|
5349 ; Make sure that timer handlers are run during, not after sit-for:
|
|
5350 (defun timer-check ()
|
|
5351 (add-timeout 2 '(lambda (ignore) (message "timer ran")) nil)
|
|
5352 (sit-for 5)
|
|
5353 (message "after sit-for"))
|
|
5354
|
|
5355 ; The first message should appear after 2 seconds, and the final message
|
|
5356 ; 3 seconds after that.
|
|
5357 ; repeat above test with (sleep-for 5) and (accept-process-output nil 5)
|
|
5358
|
|
5359
|
|
5360
|
|
5361 ; Make sure that process filters are run during, not after sit-for.
|
|
5362 (defun fubar ()
|
|
5363 (message "sit-for = %s" (sit-for 30)))
|
|
5364 (add-hook 'post-command-hook 'fubar)
|
|
5365
|
|
5366 ; Now type M-x shell RET
|
|
5367 ; wait for the shell prompt then send: ls RET
|
|
5368 ; the output of ls should fill immediately, and not wait 30 seconds.
|
|
5369
|
|
5370 ; repeat above test with (sleep-for 30) and (accept-process-output nil 30)
|
|
5371
|
|
5372
|
|
5373
|
|
5374 ; Make sure that recursive invocations return immediately:
|
|
5375 (defmacro test-diff-time (start end)
|
|
5376 `(+ (* (- (car ,end) (car ,start)) 65536.0)
|
|
5377 (- (cadr ,end) (cadr ,start))
|
|
5378 (/ (- (caddr ,end) (caddr ,start)) 1000000.0)))
|
|
5379
|
|
5380 (defun testee (ignore)
|
110
|
5381 (sit-for 10))
|
108
|
5382
|
|
5383 (defun test-them ()
|
|
5384 (let ((start (current-time))
|
|
5385 end)
|
|
5386 (add-timeout 2 'testee nil)
|
|
5387 (sit-for 5)
|
|
5388 (add-timeout 2 'testee nil)
|
|
5389 (sleep-for 5)
|
|
5390 (add-timeout 2 'testee nil)
|
|
5391 (accept-process-output nil 5)
|
|
5392 (setq end (current-time))
|
|
5393 (test-diff-time start end)))
|
|
5394
|
110
|
5395 (test-them) should sit for 15 seconds.
|
|
5396 Repeat with testee set to sleep-for and accept-process-output.
|
|
5397 These should each delay 36 seconds.
|
108
|
5398
|
|
5399 */
|