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