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