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