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