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