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