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