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