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