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