1 /* Keyboard and mouse input; editor command loop.
2 Copyright (C) 1985, 1986, 1987, 1988, 1989, 1993, 1994, 1995,
3 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004,
4 2005 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
30 #include "termhooks.h"
38 #include "dispextern.h"
40 #include "intervals.h"
42 #include "blockinput.h"
49 #ifdef HAVE_GTK_AND_PTHREAD
57 #include <sys/ioctl.h>
59 #endif /* not MSDOS */
61 #include "syssignal.h"
63 #include <sys/types.h>
72 /* This is to get the definitions of the XK_ symbols. */
79 #endif /* HAVE_NTGUI */
89 /* Variables for blockinput.h: */
91 /* Non-zero if interrupt input is blocked right now. */
92 int interrupt_input_blocked
;
94 /* Nonzero means an input interrupt has arrived
95 during the current critical section. */
96 int interrupt_input_pending
;
99 #ifdef HAVE_WINDOW_SYSTEM
100 /* Make all keyboard buffers much bigger when using X windows. */
102 /* But not too big (local data > 32K error) if on Mac OS Classic. */
103 #define KBD_BUFFER_SIZE 512
105 #define KBD_BUFFER_SIZE 4096
107 #else /* No X-windows, character input */
108 #define KBD_BUFFER_SIZE 4096
109 #endif /* No X-windows */
111 #define abs(x) ((x) >= 0 ? (x) : -(x))
113 /* Following definition copied from eval.c */
117 struct backtrace
*next
;
118 Lisp_Object
*function
;
119 Lisp_Object
*args
; /* Points to vector of args. */
120 int nargs
; /* length of vector. If nargs is UNEVALLED,
121 args points to slot holding list of
124 /* Nonzero means call value of debugger when done with this operation. */
129 KBOARD
*initial_kboard
;
130 KBOARD
*current_kboard
;
134 KBOARD the_only_kboard
;
137 /* Non-nil disable property on a command means
138 do not execute it; call disabled-command-function's value instead. */
139 Lisp_Object Qdisabled
, Qdisabled_command_function
;
141 #define NUM_RECENT_KEYS (100)
142 int recent_keys_index
; /* Index for storing next element into recent_keys */
143 int total_keys
; /* Total number of elements stored into recent_keys */
144 Lisp_Object recent_keys
; /* A vector, holding the last 100 keystrokes */
146 /* Vector holding the key sequence that invoked the current command.
147 It is reused for each command, and it may be longer than the current
148 sequence; this_command_key_count indicates how many elements
149 actually mean something.
150 It's easier to staticpro a single Lisp_Object than an array. */
151 Lisp_Object this_command_keys
;
152 int this_command_key_count
;
154 /* 1 after calling Freset_this_command_lengths.
156 int this_command_key_count_reset
;
158 /* This vector is used as a buffer to record the events that were actually read
159 by read_key_sequence. */
160 Lisp_Object raw_keybuf
;
161 int raw_keybuf_count
;
163 #define GROW_RAW_KEYBUF \
164 if (raw_keybuf_count == XVECTOR (raw_keybuf)->size) \
166 int newsize = 2 * XVECTOR (raw_keybuf)->size; \
168 new = Fmake_vector (make_number (newsize), Qnil); \
169 bcopy (XVECTOR (raw_keybuf)->contents, XVECTOR (new)->contents, \
170 raw_keybuf_count * sizeof (Lisp_Object)); \
174 /* Number of elements of this_command_keys
175 that precede this key sequence. */
176 int this_single_command_key_start
;
178 /* Record values of this_command_key_count and echo_length ()
179 before this command was read. */
180 static int before_command_key_count
;
181 static int before_command_echo_length
;
183 extern int minbuf_level
;
185 extern int message_enable_multibyte
;
187 extern struct backtrace
*backtrace_list
;
189 /* If non-nil, the function that implements the display of help.
190 It's called with one argument, the help string to display. */
192 Lisp_Object Vshow_help_function
;
194 /* If a string, the message displayed before displaying a help-echo
197 Lisp_Object Vpre_help_message
;
199 /* Nonzero means do menu prompting. */
201 static int menu_prompting
;
203 /* Character to see next line of menu prompt. */
205 static Lisp_Object menu_prompt_more_char
;
207 /* For longjmp to where kbd input is being done. */
209 static jmp_buf getcjmp
;
211 /* True while doing kbd input. */
212 int waiting_for_input
;
214 /* True while displaying for echoing. Delays C-g throwing. */
218 /* Non-null means we can start echoing at the next input pause even
219 though there is something in the echo area. */
221 static struct kboard
*ok_to_echo_at_next_pause
;
223 /* The kboard last echoing, or null for none. Reset to 0 in
224 cancel_echoing. If non-null, and a current echo area message
225 exists, and echo_message_buffer is eq to the current message
226 buffer, we know that the message comes from echo_kboard. */
228 struct kboard
*echo_kboard
;
230 /* The buffer used for echoing. Set in echo_now, reset in
233 Lisp_Object echo_message_buffer
;
235 /* Nonzero means disregard local maps for the menu bar. */
236 static int inhibit_local_menu_bar_menus
;
238 /* Nonzero means C-g should cause immediate error-signal. */
241 /* The user's ERASE setting. */
242 Lisp_Object Vtty_erase_char
;
244 /* Character to recognize as the help char. */
245 Lisp_Object Vhelp_char
;
247 /* List of other event types to recognize as meaning "help". */
248 Lisp_Object Vhelp_event_list
;
250 /* Form to execute when help char is typed. */
251 Lisp_Object Vhelp_form
;
253 /* Command to run when the help character follows a prefix key. */
254 Lisp_Object Vprefix_help_command
;
256 /* List of items that should move to the end of the menu bar. */
257 Lisp_Object Vmenu_bar_final_items
;
259 /* Non-nil means show the equivalent key-binding for
260 any M-x command that has one.
261 The value can be a length of time to show the message for.
262 If the value is non-nil and not a number, we wait 2 seconds. */
263 Lisp_Object Vsuggest_key_bindings
;
265 /* How long to display an echo-area message when the minibuffer is active.
266 If the value is not a number, such messages don't time out. */
267 Lisp_Object Vminibuffer_message_timeout
;
269 /* Character that causes a quit. Normally C-g.
271 If we are running on an ordinary terminal, this must be an ordinary
272 ASCII char, since we want to make it our interrupt character.
274 If we are not running on an ordinary terminal, it still needs to be
275 an ordinary ASCII char. This character needs to be recognized in
276 the input interrupt handler. At this point, the keystroke is
277 represented as a struct input_event, while the desired quit
278 character is specified as a lispy event. The mapping from struct
279 input_events to lispy events cannot run in an interrupt handler,
280 and the reverse mapping is difficult for anything but ASCII
283 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
287 extern Lisp_Object current_global_map
;
288 extern int minibuf_level
;
290 /* If non-nil, this is a map that overrides all other local maps. */
291 Lisp_Object Voverriding_local_map
;
293 /* If non-nil, Voverriding_local_map applies to the menu bar. */
294 Lisp_Object Voverriding_local_map_menu_flag
;
296 /* Keymap that defines special misc events that should
297 be processed immediately at a low level. */
298 Lisp_Object Vspecial_event_map
;
300 /* Current depth in recursive edits. */
301 int command_loop_level
;
303 /* Total number of times command_loop has read a key sequence. */
304 EMACS_INT num_input_keys
;
306 /* Last input character read as a command. */
307 Lisp_Object last_command_char
;
309 /* Last input character read as a command, not counting menus
310 reached by the mouse. */
311 Lisp_Object last_nonmenu_event
;
313 /* Last input character read for any purpose. */
314 Lisp_Object last_input_char
;
316 /* If not Qnil, a list of objects to be read as subsequent command input. */
317 Lisp_Object Vunread_command_events
;
319 /* If not Qnil, a list of objects to be read as subsequent command input
320 including input method processing. */
321 Lisp_Object Vunread_input_method_events
;
323 /* If not Qnil, a list of objects to be read as subsequent command input
324 but NOT including input method processing. */
325 Lisp_Object Vunread_post_input_method_events
;
327 /* If not -1, an event to be read as subsequent command input. */
328 EMACS_INT unread_command_char
;
330 /* If not Qnil, this is a switch-frame event which we decided to put
331 off until the end of a key sequence. This should be read as the
332 next command input, after any unread_command_events.
334 read_key_sequence uses this to delay switch-frame events until the
335 end of the key sequence; Fread_char uses it to put off switch-frame
336 events until a non-ASCII event is acceptable as input. */
337 Lisp_Object unread_switch_frame
;
339 /* A mask of extra modifier bits to put into every keyboard char. */
340 EMACS_INT extra_keyboard_modifiers
;
342 /* Char to use as prefix when a meta character is typed in.
343 This is bound on entry to minibuffer in case ESC is changed there. */
345 Lisp_Object meta_prefix_char
;
347 /* Last size recorded for a current buffer which is not a minibuffer. */
348 static int last_non_minibuf_size
;
350 /* Number of idle seconds before an auto-save and garbage collection. */
351 static Lisp_Object Vauto_save_timeout
;
353 /* Total number of times read_char has returned. */
354 int num_input_events
;
356 /* Total number of times read_char has returned, outside of macros. */
357 EMACS_INT num_nonmacro_input_events
;
359 /* Auto-save automatically when this many characters have been typed
360 since the last time. */
362 static EMACS_INT auto_save_interval
;
364 /* Value of num_nonmacro_input_events as of last auto save. */
368 /* The command being executed by the command loop.
369 Commands may set this, and the value set will be copied into
370 current_kboard->Vlast_command instead of the actual command. */
371 Lisp_Object Vthis_command
;
373 /* This is like Vthis_command, except that commands never set it. */
374 Lisp_Object real_this_command
;
376 /* If the lookup of the command returns a binding, the original
377 command is stored in this-original-command. It is nil otherwise. */
378 Lisp_Object Vthis_original_command
;
380 /* The value of point when the last command was started. */
381 int last_point_position
;
383 /* The buffer that was current when the last command was started. */
384 Lisp_Object last_point_position_buffer
;
386 /* The window that was selected when the last command was started. */
387 Lisp_Object last_point_position_window
;
389 /* The frame in which the last input event occurred, or Qmacro if the
390 last event came from a macro. We use this to determine when to
391 generate switch-frame events. This may be cleared by functions
392 like Fselect_frame, to make sure that a switch-frame event is
393 generated by the next character. */
394 Lisp_Object internal_last_event_frame
;
396 /* A user-visible version of the above, intended to allow users to
397 figure out where the last event came from, if the event doesn't
398 carry that information itself (i.e. if it was a character). */
399 Lisp_Object Vlast_event_frame
;
401 /* The timestamp of the last input event we received from the X server.
402 X Windows wants this for selection ownership. */
403 unsigned long last_event_timestamp
;
405 Lisp_Object Qself_insert_command
;
406 Lisp_Object Qforward_char
;
407 Lisp_Object Qbackward_char
;
408 Lisp_Object Qundefined
;
409 Lisp_Object Qtimer_event_handler
;
411 /* read_key_sequence stores here the command definition of the
412 key sequence that it reads. */
413 Lisp_Object read_key_sequence_cmd
;
415 /* Echo unfinished commands after this many seconds of pause. */
416 Lisp_Object Vecho_keystrokes
;
418 /* Form to evaluate (if non-nil) when Emacs is started. */
419 Lisp_Object Vtop_level
;
421 /* If non-nil, this implements the current input method. */
422 Lisp_Object Vinput_method_function
;
423 Lisp_Object Qinput_method_function
;
425 /* When we call Vinput_method_function,
426 this holds the echo area message that was just erased. */
427 Lisp_Object Vinput_method_previous_message
;
429 /* Non-nil means deactivate the mark at end of this command. */
430 Lisp_Object Vdeactivate_mark
;
432 /* Menu bar specified in Lucid Emacs fashion. */
434 Lisp_Object Vlucid_menu_bar_dirty_flag
;
435 Lisp_Object Qrecompute_lucid_menubar
, Qactivate_menubar_hook
;
437 Lisp_Object Qecho_area_clear_hook
;
439 /* Hooks to run before and after each command. */
440 Lisp_Object Qpre_command_hook
, Vpre_command_hook
;
441 Lisp_Object Qpost_command_hook
, Vpost_command_hook
;
442 Lisp_Object Qcommand_hook_internal
, Vcommand_hook_internal
;
444 /* Parent keymap of terminal-local function-key-map instances. */
445 Lisp_Object Vfunction_key_map
;
447 /* Parent keymap of terminal-local key-translation-map instances. */
448 Lisp_Object Vkey_translation_map
;
450 /* List of deferred actions to be performed at a later time.
451 The precise format isn't relevant here; we just check whether it is nil. */
452 Lisp_Object Vdeferred_action_list
;
454 /* Function to call to handle deferred actions, when there are any. */
455 Lisp_Object Vdeferred_action_function
;
456 Lisp_Object Qdeferred_action_function
;
458 Lisp_Object Qinput_method_exit_on_first_char
;
459 Lisp_Object Qinput_method_use_echo_area
;
461 /* File in which we write all commands we read. */
464 /* Nonzero if input is available. */
467 extern char *pending_malloc_warning
;
469 /* Circular buffer for pre-read keyboard input. */
471 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
473 /* Pointer to next available character in kbd_buffer.
474 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
475 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the
476 next available char is in kbd_buffer[0]. */
477 static struct input_event
*kbd_fetch_ptr
;
479 /* Pointer to next place to store character in kbd_buffer. This
480 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
481 character should go in kbd_buffer[0]. */
482 static struct input_event
* volatile kbd_store_ptr
;
484 /* The above pair of variables forms a "queue empty" flag. When we
485 enqueue a non-hook event, we increment kbd_store_ptr. When we
486 dequeue a non-hook event, we increment kbd_fetch_ptr. We say that
487 there is input available iff the two pointers are not equal.
489 Why not just have a flag set and cleared by the enqueuing and
490 dequeuing functions? Such a flag could be screwed up by interrupts
491 at inopportune times. */
493 /* If this flag is non-nil, we check mouse_moved to see when the
494 mouse moves, and motion events will appear in the input stream.
495 Otherwise, mouse motion is ignored. */
496 Lisp_Object do_mouse_tracking
;
498 /* Symbols to head events. */
499 Lisp_Object Qmouse_movement
;
500 Lisp_Object Qscroll_bar_movement
;
501 Lisp_Object Qswitch_frame
;
502 Lisp_Object Qdelete_frame
;
503 Lisp_Object Qiconify_frame
;
504 Lisp_Object Qmake_frame_visible
;
505 Lisp_Object Qselect_window
;
506 Lisp_Object Qhelp_echo
;
509 Lisp_Object Qmouse_fixup_help_message
;
512 /* Symbols to denote kinds of events. */
513 Lisp_Object Qfunction_key
;
514 Lisp_Object Qmouse_click
;
515 #if defined (WINDOWSNT) || defined (MAC_OS)
516 Lisp_Object Qlanguage_change
;
518 Lisp_Object Qdrag_n_drop
;
519 Lisp_Object Qsave_session
;
521 Lisp_Object Qmac_apple_event
;
524 /* Lisp_Object Qmouse_movement; - also an event header */
526 /* Properties of event headers. */
527 Lisp_Object Qevent_kind
;
528 Lisp_Object Qevent_symbol_elements
;
530 /* menu item parts */
531 Lisp_Object Qmenu_alias
;
532 Lisp_Object Qmenu_enable
;
533 Lisp_Object QCenable
, QCvisible
, QChelp
, QCfilter
, QCkeys
, QCkey_sequence
;
534 Lisp_Object QCbutton
, QCtoggle
, QCradio
;
535 extern Lisp_Object Vdefine_key_rebound_commands
;
536 extern Lisp_Object Qmenu_item
;
538 /* An event header symbol HEAD may have a property named
539 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
540 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
541 mask of modifiers applied to it. If present, this is used to help
542 speed up parse_modifiers. */
543 Lisp_Object Qevent_symbol_element_mask
;
545 /* An unmodified event header BASE may have a property named
546 Qmodifier_cache, which is an alist mapping modifier masks onto
547 modified versions of BASE. If present, this helps speed up
549 Lisp_Object Qmodifier_cache
;
551 /* Symbols to use for parts of windows. */
552 Lisp_Object Qmode_line
;
553 Lisp_Object Qvertical_line
;
554 Lisp_Object Qvertical_scroll_bar
;
555 Lisp_Object Qmenu_bar
;
556 extern Lisp_Object Qleft_margin
, Qright_margin
;
557 extern Lisp_Object Qleft_fringe
, Qright_fringe
;
558 extern Lisp_Object QCmap
;
560 Lisp_Object
recursive_edit_unwind (), command_loop ();
561 Lisp_Object
Fthis_command_keys ();
562 Lisp_Object Qextended_command_history
;
563 EMACS_TIME
timer_check ();
565 extern Lisp_Object Vhistory_length
, Vtranslation_table_for_input
;
567 extern char *x_get_keysym_name ();
569 static void record_menu_key ();
570 static int echo_length ();
572 Lisp_Object Qpolling_period
;
574 /* List of absolute timers. Appears in order of next scheduled event. */
575 Lisp_Object Vtimer_list
;
577 /* List of idle time timers. Appears in order of next scheduled event. */
578 Lisp_Object Vtimer_idle_list
;
580 /* Incremented whenever a timer is run. */
583 extern Lisp_Object Vprint_level
, Vprint_length
;
585 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
587 EMACS_TIME
*input_available_clear_time
;
589 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
590 Default is 1 if INTERRUPT_INPUT is defined. */
593 /* Nonzero while interrupts are temporarily deferred during redisplay. */
594 int interrupts_deferred
;
596 /* Allow m- file to inhibit use of FIONREAD. */
597 #ifdef BROKEN_FIONREAD
601 /* We are unable to use interrupts if FIONREAD is not available,
602 so flush SIGIO so we won't try. */
603 #if !defined (FIONREAD)
609 /* If we support a window system, turn on the code to poll periodically
610 to detect C-g. It isn't actually used when doing interrupt input. */
611 #if defined(HAVE_WINDOW_SYSTEM) && !defined(USE_ASYNC_EVENTS)
612 #define POLL_FOR_INPUT
615 /* After a command is executed, if point is moved into a region that
616 has specific properties (e.g. composition, display), we adjust
617 point to the boundary of the region. But, if a command sets this
618 variable to non-nil, we suppress this point adjustment. This
619 variable is set to nil before reading a command. */
621 Lisp_Object Vdisable_point_adjustment
;
623 /* If non-nil, always disable point adjustment. */
625 Lisp_Object Vglobal_disable_point_adjustment
;
627 /* The time when Emacs started being idle. */
629 static EMACS_TIME timer_idleness_start_time
;
631 /* After Emacs stops being idle, this saves the last value
632 of timer_idleness_start_time from when it was idle. */
634 static EMACS_TIME timer_last_idleness_start_time
;
637 /* Global variable declarations. */
639 /* Flags for readable_events. */
640 #define READABLE_EVENTS_DO_TIMERS_NOW (1 << 0)
641 #define READABLE_EVENTS_FILTER_EVENTS (1 << 1)
642 #define READABLE_EVENTS_IGNORE_SQUEEZABLES (1 << 2)
644 /* Function for init_keyboard to call with no args (if nonzero). */
645 void (*keyboard_init_hook
) ();
647 static int read_avail_input
P_ ((int));
648 static void get_input_pending
P_ ((int *, int));
649 static int readable_events
P_ ((int));
650 static Lisp_Object read_char_x_menu_prompt
P_ ((int, Lisp_Object
*,
651 Lisp_Object
, int *));
652 static Lisp_Object
read_char_x_menu_prompt ();
653 static Lisp_Object read_char_minibuf_menu_prompt
P_ ((int, int,
655 static Lisp_Object make_lispy_event
P_ ((struct input_event
*));
657 static Lisp_Object make_lispy_movement
P_ ((struct frame
*, Lisp_Object
,
658 enum scroll_bar_part
,
659 Lisp_Object
, Lisp_Object
,
662 static Lisp_Object modify_event_symbol
P_ ((int, unsigned, Lisp_Object
,
663 Lisp_Object
, char **,
664 Lisp_Object
*, unsigned));
665 static Lisp_Object make_lispy_switch_frame
P_ ((Lisp_Object
));
666 static int parse_solitary_modifier
P_ ((Lisp_Object
));
667 static int parse_solitary_modifier ();
668 static void save_getcjmp
P_ ((jmp_buf));
669 static void save_getcjmp ();
670 static void restore_getcjmp
P_ ((jmp_buf));
671 static Lisp_Object apply_modifiers
P_ ((int, Lisp_Object
));
672 static void clear_event
P_ ((struct input_event
*));
673 static Lisp_Object restore_kboard_configuration
P_ ((Lisp_Object
));
674 static SIGTYPE interrupt_signal
P_ ((int signalnum
));
675 static void handle_interrupt
P_ ((void));
676 static void timer_start_idle
P_ ((void));
677 static void timer_stop_idle
P_ ((void));
678 static void timer_resume_idle
P_ ((void));
680 /* Nonzero means don't try to suspend even if the operating system seems
682 static int cannot_suspend
;
684 extern Lisp_Object Qidentity
, Qonly
;
686 /* Install the string STR as the beginning of the string of echoing,
687 so that it serves as a prompt for the next character.
688 Also start echoing. */
694 current_kboard
->echo_string
= str
;
695 current_kboard
->echo_after_prompt
= SCHARS (str
);
699 /* Add C to the echo string, if echoing is going on.
700 C can be a character, which is printed prettily ("M-C-x" and all that
701 jazz), or a symbol, whose name is printed. */
707 if (current_kboard
->immediate_echo
)
709 int size
= KEY_DESCRIPTION_SIZE
+ 100;
710 char *buffer
= (char *) alloca (size
);
712 Lisp_Object echo_string
;
714 echo_string
= current_kboard
->echo_string
;
716 /* If someone has passed us a composite event, use its head symbol. */
721 ptr
= push_key_description (XINT (c
), ptr
, 1);
723 else if (SYMBOLP (c
))
725 Lisp_Object name
= SYMBOL_NAME (c
);
726 int nbytes
= SBYTES (name
);
728 if (size
- (ptr
- buffer
) < nbytes
)
730 int offset
= ptr
- buffer
;
731 size
= max (2 * size
, size
+ nbytes
);
732 buffer
= (char *) alloca (size
);
733 ptr
= buffer
+ offset
;
736 ptr
+= copy_text (SDATA (name
), ptr
, nbytes
,
737 STRING_MULTIBYTE (name
), 1);
740 if ((NILP (echo_string
) || SCHARS (echo_string
) == 0)
743 const char *text
= " (Type ? for further options)";
744 int len
= strlen (text
);
746 if (size
- (ptr
- buffer
) < len
)
748 int offset
= ptr
- buffer
;
750 buffer
= (char *) alloca (size
);
751 ptr
= buffer
+ offset
;
754 bcopy (text
, ptr
, len
);
758 /* Replace a dash from echo_dash with a space, otherwise
759 add a space at the end as a separator between keys. */
760 if (STRINGP (echo_string
)
761 && SCHARS (echo_string
) > 1)
763 Lisp_Object last_char
, prev_char
, idx
;
765 idx
= make_number (SCHARS (echo_string
) - 2);
766 prev_char
= Faref (echo_string
, idx
);
768 idx
= make_number (SCHARS (echo_string
) - 1);
769 last_char
= Faref (echo_string
, idx
);
771 /* We test PREV_CHAR to make sure this isn't the echoing
773 if (XINT (last_char
) == '-' && XINT (prev_char
) != ' ')
774 Faset (echo_string
, idx
, make_number (' '));
776 echo_string
= concat2 (echo_string
, build_string (" "));
779 current_kboard
->echo_string
780 = concat2 (echo_string
, make_string (buffer
, ptr
- buffer
));
786 /* Temporarily add a dash to the end of the echo string if it's not
787 empty, so that it serves as a mini-prompt for the very next character. */
792 /* Do nothing if not echoing at all. */
793 if (NILP (current_kboard
->echo_string
))
796 if (!current_kboard
->immediate_echo
797 && SCHARS (current_kboard
->echo_string
) == 0)
800 /* Do nothing if we just printed a prompt. */
801 if (current_kboard
->echo_after_prompt
802 == SCHARS (current_kboard
->echo_string
))
805 /* Do nothing if we have already put a dash at the end. */
806 if (SCHARS (current_kboard
->echo_string
) > 1)
808 Lisp_Object last_char
, prev_char
, idx
;
810 idx
= make_number (SCHARS (current_kboard
->echo_string
) - 2);
811 prev_char
= Faref (current_kboard
->echo_string
, idx
);
813 idx
= make_number (SCHARS (current_kboard
->echo_string
) - 1);
814 last_char
= Faref (current_kboard
->echo_string
, idx
);
816 if (XINT (last_char
) == '-' && XINT (prev_char
) != ' ')
820 /* Put a dash at the end of the buffer temporarily,
821 but make it go away when the next character is added. */
822 current_kboard
->echo_string
= concat2 (current_kboard
->echo_string
,
827 /* Display the current echo string, and begin echoing if not already
833 if (!current_kboard
->immediate_echo
)
836 current_kboard
->immediate_echo
= 1;
838 for (i
= 0; i
< this_command_key_count
; i
++)
842 /* Set before_command_echo_length to the value that would
843 have been saved before the start of this subcommand in
844 command_loop_1, if we had already been echoing then. */
845 if (i
== this_single_command_key_start
)
846 before_command_echo_length
= echo_length ();
848 c
= XVECTOR (this_command_keys
)->contents
[i
];
849 if (! (EVENT_HAS_PARAMETERS (c
)
850 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
854 /* Set before_command_echo_length to the value that would
855 have been saved before the start of this subcommand in
856 command_loop_1, if we had already been echoing then. */
857 if (this_command_key_count
== this_single_command_key_start
)
858 before_command_echo_length
= echo_length ();
860 /* Put a dash at the end to invite the user to type more. */
865 message3_nolog (current_kboard
->echo_string
,
866 SBYTES (current_kboard
->echo_string
),
867 STRING_MULTIBYTE (current_kboard
->echo_string
));
870 /* Record in what buffer we echoed, and from which kboard. */
871 echo_message_buffer
= echo_area_buffer
[0];
872 echo_kboard
= current_kboard
;
874 if (waiting_for_input
&& !NILP (Vquit_flag
))
875 quit_throw_to_read_char ();
878 /* Turn off echoing, for the start of a new command. */
883 current_kboard
->immediate_echo
= 0;
884 current_kboard
->echo_after_prompt
= -1;
885 current_kboard
->echo_string
= Qnil
;
886 ok_to_echo_at_next_pause
= NULL
;
888 echo_message_buffer
= Qnil
;
891 /* Return the length of the current echo string. */
896 return (STRINGP (current_kboard
->echo_string
)
897 ? SCHARS (current_kboard
->echo_string
)
901 /* Truncate the current echo message to its first LEN chars.
902 This and echo_char get used by read_key_sequence when the user
903 switches frames while entering a key sequence. */
906 echo_truncate (nchars
)
909 if (STRINGP (current_kboard
->echo_string
))
910 current_kboard
->echo_string
911 = Fsubstring (current_kboard
->echo_string
,
912 make_number (0), make_number (nchars
));
913 truncate_echo_area (nchars
);
917 /* Functions for manipulating this_command_keys. */
919 add_command_key (key
)
922 #if 0 /* Not needed after we made Freset_this_command_lengths
923 do the job immediately. */
924 /* If reset-this-command-length was called recently, obey it now.
925 See the doc string of that function for an explanation of why. */
926 if (before_command_restore_flag
)
928 this_command_key_count
= before_command_key_count_1
;
929 if (this_command_key_count
< this_single_command_key_start
)
930 this_single_command_key_start
= this_command_key_count
;
931 echo_truncate (before_command_echo_length_1
);
932 before_command_restore_flag
= 0;
936 if (this_command_key_count
>= ASIZE (this_command_keys
))
937 this_command_keys
= larger_vector (this_command_keys
,
938 2 * ASIZE (this_command_keys
),
941 AREF (this_command_keys
, this_command_key_count
) = key
;
942 ++this_command_key_count
;
949 int count
= SPECPDL_INDEX ();
952 if (command_loop_level
> 0)
954 specbind (Qstandard_output
, Qt
);
955 specbind (Qstandard_input
, Qt
);
958 #ifdef HAVE_X_WINDOWS
959 /* The command loop has started an hourglass timer, so we have to
960 cancel it here, otherwise it will fire because the recursive edit
961 can take some time. Do not check for display_hourglass_p here,
962 because it could already be nil. */
966 /* This function may have been called from a debugger called from
967 within redisplay, for instance by Edebugging a function called
968 from fontification-functions. We want to allow redisplay in
969 the debugging session.
971 The recursive edit is left with a `(throw exit ...)'. The `exit'
972 tag is not caught anywhere in redisplay, i.e. when we leave the
973 recursive edit, the original redisplay leading to the recursive
974 edit will be unwound. The outcome should therefore be safe. */
975 specbind (Qinhibit_redisplay
, Qnil
);
978 val
= command_loop ();
980 Fsignal (Qquit
, Qnil
);
981 /* Handle throw from read_minibuf when using minibuffer
982 while it's active but we're in another window. */
984 Fsignal (Qerror
, Fcons (val
, Qnil
));
986 return unbind_to (count
, Qnil
);
989 /* When an auto-save happens, record the "time", and don't do again soon. */
994 last_auto_save
= num_nonmacro_input_events
;
997 /* Make an auto save happen as soon as possible at command level. */
1000 force_auto_save_soon ()
1002 last_auto_save
= - auto_save_interval
- 1;
1004 record_asynch_buffer_change ();
1007 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
1008 doc
: /* Invoke the editor command loop recursively.
1009 To get out of the recursive edit, a command can do `(throw 'exit nil)';
1010 that tells this function to return.
1011 Alternatively, `(throw 'exit t)' makes this function signal an error.
1012 This function is called by the editor initialization to begin editing. */)
1015 int count
= SPECPDL_INDEX ();
1018 /* If we enter while input is blocked, don't lock up here.
1019 This may happen through the debugger during redisplay. */
1020 if (INPUT_BLOCKED_P
)
1023 command_loop_level
++;
1024 update_mode_lines
= 1;
1026 if (command_loop_level
1027 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
1028 buffer
= Fcurrent_buffer ();
1032 /* If we leave recursive_edit_1 below with a `throw' for instance,
1033 like it is done in the splash screen display, we have to
1034 make sure that we restore single_kboard as command_loop_1
1035 would have done if it were left normally. */
1036 if (command_loop_level
> 0)
1037 temporarily_switch_to_single_kboard (SELECTED_FRAME ());
1038 record_unwind_protect (recursive_edit_unwind
, buffer
);
1040 recursive_edit_1 ();
1041 return unbind_to (count
, Qnil
);
1045 recursive_edit_unwind (buffer
)
1048 if (BUFFERP (buffer
))
1049 Fset_buffer (buffer
);
1051 command_loop_level
--;
1052 update_mode_lines
= 1;
1057 #if 0 /* These two functions are now replaced with
1058 temporarily_switch_to_single_kboard. */
1063 #if 0 /* Theory: if there's anything in Vunread_command_events,
1064 it will right away be read by read_key_sequence,
1065 and then if we do switch KBOARDS, it will go into the side
1066 queue then. So we don't need to do anything special here -- rms. */
1067 if (CONSP (Vunread_command_events
))
1069 current_kboard
->kbd_queue
1070 = nconc2 (Vunread_command_events
, current_kboard
->kbd_queue
);
1071 current_kboard
->kbd_queue_has_data
= 1;
1073 Vunread_command_events
= Qnil
;
1079 /* Switch to the single-kboard state, making current_kboard
1080 the only KBOARD from which further input is accepted. */
1083 single_kboard_state ()
1091 /* If we're in single_kboard state for kboard KBOARD,
1095 not_single_kboard_state (kboard
)
1099 if (kboard
== current_kboard
)
1104 /* Maintain a stack of kboards, so other parts of Emacs
1105 can switch temporarily to the kboard of a given frame
1106 and then revert to the previous status. */
1111 struct kboard_stack
*next
;
1114 static struct kboard_stack
*kboard_stack
;
1121 struct kboard_stack
*p
1122 = (struct kboard_stack
*) xmalloc (sizeof (struct kboard_stack
));
1124 p
->next
= kboard_stack
;
1125 p
->kboard
= current_kboard
;
1137 struct kboard_stack
*p
= kboard_stack
;
1139 for (t
= terminal_list
; t
; t
= t
->next_terminal
)
1141 if (t
->kboard
== p
->kboard
)
1143 current_kboard
= p
->kboard
;
1150 /* The terminal we remembered has been deleted. */
1151 current_kboard
= FRAME_KBOARD (SELECTED_FRAME ());
1154 kboard_stack
= p
->next
;
1159 /* Switch to single_kboard mode, making current_kboard the only KBOARD
1160 from which further input is accepted. If F is non-nil, set its
1161 KBOARD as the current keyboard.
1163 This function uses record_unwind_protect to return to the previous
1166 If Emacs is already in single_kboard mode, and F's keyboard is
1167 locked, then this function will throw an errow. */
1170 temporarily_switch_to_single_kboard (f
)
1174 int was_locked
= single_kboard
;
1177 if (f
!= NULL
&& FRAME_KBOARD (f
) != current_kboard
)
1178 /* We can not switch keyboards while in single_kboard mode.
1179 This can legally happen when Lisp code calls
1180 `recursive-edit' (or `read-minibuffer' or `y-or-n-p') after
1181 it switched to a locked frame. This kind of situation is
1182 likely to happen when server.el connects to a new
1184 error ("Terminal %d is locked, cannot read from it",
1185 FRAME_TERMINAL (f
)->id
);
1187 /* This call is unnecessary, but helps
1188 `restore_kboard_configuration' discover if somebody changed
1189 `current_kboard' behind our back. */
1190 push_kboard (current_kboard
);
1193 current_kboard
= FRAME_KBOARD (f
);
1195 record_unwind_protect (restore_kboard_configuration
,
1196 (was_locked
? Qt
: Qnil
));
1200 #if 0 /* This function is not needed anymore. */
1202 record_single_kboard_state ()
1205 push_kboard (current_kboard
);
1206 record_unwind_protect (restore_kboard_configuration
,
1207 (single_kboard
? Qt
: Qnil
));
1212 restore_kboard_configuration (was_locked
)
1213 Lisp_Object was_locked
;
1215 if (NILP (was_locked
))
1219 struct kboard
*prev
= current_kboard
;
1222 /* The pop should not change the kboard. */
1223 if (single_kboard
&& current_kboard
!= prev
)
1229 /* Handle errors that are not handled at inner levels
1230 by printing an error message and returning to the editor command loop. */
1236 Lisp_Object old_level
, old_length
;
1237 char macroerror
[50];
1239 #ifdef HAVE_X_WINDOWS
1240 if (display_hourglass_p
)
1241 cancel_hourglass ();
1244 if (!NILP (executing_kbd_macro
))
1246 if (executing_kbd_macro_iterations
== 1)
1247 sprintf (macroerror
, "After 1 kbd macro iteration: ");
1249 sprintf (macroerror
, "After %d kbd macro iterations: ",
1250 executing_kbd_macro_iterations
);
1255 Vstandard_output
= Qt
;
1256 Vstandard_input
= Qt
;
1257 Vexecuting_kbd_macro
= Qnil
;
1258 executing_kbd_macro
= Qnil
;
1259 current_kboard
->Vprefix_arg
= Qnil
;
1260 current_kboard
->Vlast_prefix_arg
= Qnil
;
1263 /* Avoid unquittable loop if data contains a circular list. */
1264 old_level
= Vprint_level
;
1265 old_length
= Vprint_length
;
1266 XSETFASTINT (Vprint_level
, 10);
1267 XSETFASTINT (Vprint_length
, 10);
1268 cmd_error_internal (data
, macroerror
);
1269 Vprint_level
= old_level
;
1270 Vprint_length
= old_length
;
1274 Vinhibit_quit
= Qnil
;
1275 #if 0 /* This shouldn't be necessary anymore. --lorentey */
1277 if (command_loop_level
== 0 && minibuf_level
== 0)
1278 any_kboard_state ();
1282 return make_number (0);
1285 /* Take actions on handling an error. DATA is the data that describes
1288 CONTEXT is a C-string containing ASCII characters only which
1289 describes the context in which the error happened. If we need to
1290 generalize CONTEXT to allow multibyte characters, make it a Lisp
1294 cmd_error_internal (data
, context
)
1299 int kill_emacs_p
= 0;
1300 struct frame
*sf
= SELECTED_FRAME ();
1304 clear_message (1, 0);
1306 /* If the window system or terminal frame hasn't been initialized
1307 yet, or we're not interactive, it's best to dump this message out
1308 to stderr and exit. */
1309 if (!sf
->glyphs_initialized_p
1310 || FRAME_INITIAL_P (sf
)
1313 stream
= Qexternal_debugging_output
;
1319 message_log_maybe_newline ();
1324 /* The immediate context is not interesting for Quits,
1325 since they are asyncronous. */
1326 if (EQ (XCAR (data
), Qquit
))
1327 Vsignaling_function
= Qnil
;
1329 print_error_message (data
, stream
, context
, Vsignaling_function
);
1331 Vsignaling_function
= Qnil
;
1333 /* If the window system or terminal frame hasn't been initialized
1334 yet, or we're in -batch mode, this error should cause Emacs to exit. */
1338 Fkill_emacs (make_number (-1));
1342 Lisp_Object
command_loop_1 ();
1343 Lisp_Object
command_loop_2 ();
1344 Lisp_Object
top_level_1 ();
1346 /* Entry to editor-command-loop.
1347 This level has the catches for exiting/returning to editor command loop.
1348 It returns nil to exit recursive edit, t to abort it. */
1353 if (command_loop_level
> 0 || minibuf_level
> 0)
1356 val
= internal_catch (Qexit
, command_loop_2
, Qnil
);
1357 executing_kbd_macro
= Qnil
;
1363 internal_catch (Qtop_level
, top_level_1
, Qnil
);
1364 #if 0 /* This shouldn't be necessary anymore. --lorentey */
1365 /* Reset single_kboard in case top-level set it while
1366 evaluating an -f option, or we are stuck there for some
1368 any_kboard_state ();
1370 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
1371 executing_kbd_macro
= Qnil
;
1373 /* End of file in -batch run causes exit here. */
1379 /* Here we catch errors in execution of commands within the
1380 editing loop, and reenter the editing loop.
1381 When there is an error, cmd_error runs and returns a non-nil
1382 value to us. A value of nil means that command_loop_1 itself
1383 returned due to end of file (or end of kbd macro). */
1388 register Lisp_Object val
;
1391 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
1392 while (!NILP (val
));
1400 return Feval (Vtop_level
);
1406 /* On entry to the outer level, run the startup file */
1407 if (!NILP (Vtop_level
))
1408 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
1409 else if (!NILP (Vpurify_flag
))
1410 message ("Bare impure Emacs (standard Lisp code not loaded)");
1412 message ("Bare Emacs (standard Lisp code not loaded)");
1416 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
1417 doc
: /* Exit all recursive editing levels. */)
1420 #ifdef HAVE_X_WINDOWS
1421 if (display_hourglass_p
)
1422 cancel_hourglass ();
1425 /* Unblock input if we enter with input blocked. This may happen if
1426 redisplay traps e.g. during tool-bar update with input blocked. */
1427 while (INPUT_BLOCKED_P
)
1430 return Fthrow (Qtop_level
, Qnil
);
1433 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
1434 doc
: /* Exit from the innermost recursive edit or minibuffer. */)
1437 if (command_loop_level
> 0 || minibuf_level
> 0)
1438 Fthrow (Qexit
, Qnil
);
1440 error ("No recursive edit is in progress");
1444 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
1445 doc
: /* Abort the command that requested this recursive edit or minibuffer input. */)
1448 if (command_loop_level
> 0 || minibuf_level
> 0)
1451 error ("No recursive edit is in progress");
1455 /* This is the actual command reading loop,
1456 sans error-handling encapsulation. */
1458 static int read_key_sequence
P_ ((Lisp_Object
*, int, Lisp_Object
,
1460 void safe_run_hooks
P_ ((Lisp_Object
));
1461 static void adjust_point_for_property
P_ ((int, int));
1463 /* Cancel hourglass from protect_unwind.
1465 #ifdef HAVE_X_WINDOWS
1467 cancel_hourglass_unwind (arg
)
1470 cancel_hourglass ();
1481 Lisp_Object keybuf
[30];
1484 int prev_modiff
= 0;
1485 struct buffer
*prev_buffer
= NULL
;
1486 #if 0 /* This shouldn't be necessary anymore. --lorentey */
1488 int was_locked
= single_kboard
;
1491 int already_adjusted
= 0;
1493 current_kboard
->Vprefix_arg
= Qnil
;
1494 current_kboard
->Vlast_prefix_arg
= Qnil
;
1495 Vdeactivate_mark
= Qnil
;
1496 waiting_for_input
= 0;
1500 this_command_key_count
= 0;
1501 this_command_key_count_reset
= 0;
1502 this_single_command_key_start
= 0;
1504 if (NILP (Vmemory_full
))
1506 /* Make sure this hook runs after commands that get errors and
1507 throw to top level. */
1508 /* Note that the value cell will never directly contain nil
1509 if the symbol is a local variable. */
1510 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1511 safe_run_hooks (Qpost_command_hook
);
1513 /* If displaying a message, resize the echo area window to fit
1514 that message's size exactly. */
1515 if (!NILP (echo_area_buffer
[0]))
1516 resize_echo_area_exactly ();
1518 if (!NILP (Vdeferred_action_list
))
1519 safe_run_hooks (Qdeferred_action_function
);
1522 /* Do this after running Vpost_command_hook, for consistency. */
1523 current_kboard
->Vlast_command
= Vthis_command
;
1524 current_kboard
->Vreal_last_command
= real_this_command
;
1528 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
1531 /* Make sure the current window's buffer is selected. */
1532 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1533 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1535 /* Display any malloc warning that just came out. Use while because
1536 displaying one warning can cause another. */
1538 while (pending_malloc_warning
)
1539 display_malloc_warning ();
1543 Vdeactivate_mark
= Qnil
;
1545 /* If minibuffer on and echo area in use,
1546 wait a short time and redraw minibuffer. */
1549 && !NILP (echo_area_buffer
[0])
1550 && EQ (minibuf_window
, echo_area_window
)
1551 && NUMBERP (Vminibuffer_message_timeout
))
1553 /* Bind inhibit-quit to t so that C-g gets read in
1554 rather than quitting back to the minibuffer. */
1555 int count
= SPECPDL_INDEX ();
1556 specbind (Qinhibit_quit
, Qt
);
1558 Fsit_for (Vminibuffer_message_timeout
, Qnil
, Qnil
);
1559 /* Clear the echo area. */
1561 safe_run_hooks (Qecho_area_clear_hook
);
1563 unbind_to (count
, Qnil
);
1565 /* If a C-g came in before, treat it as input now. */
1566 if (!NILP (Vquit_flag
))
1569 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1574 alloca (0); /* Cause a garbage collection now */
1575 /* Since we can free the most stuff here. */
1576 #endif /* C_ALLOCA */
1579 /* Select the frame that the last event came from. Usually,
1580 switch-frame events will take care of this, but if some lisp
1581 code swallows a switch-frame event, we'll fix things up here.
1582 Is this a good idea? */
1583 if (FRAMEP (internal_last_event_frame
)
1584 && !EQ (internal_last_event_frame
, selected_frame
))
1585 Fselect_frame (internal_last_event_frame
);
1587 /* If it has changed current-menubar from previous value,
1588 really recompute the menubar from the value. */
1589 if (! NILP (Vlucid_menu_bar_dirty_flag
)
1590 && !NILP (Ffboundp (Qrecompute_lucid_menubar
)))
1591 call0 (Qrecompute_lucid_menubar
);
1593 before_command_key_count
= this_command_key_count
;
1594 before_command_echo_length
= echo_length ();
1596 Vthis_command
= Qnil
;
1597 real_this_command
= Qnil
;
1598 Vthis_original_command
= Qnil
;
1600 /* Read next key sequence; i gets its length. */
1601 i
= read_key_sequence (keybuf
, sizeof keybuf
/ sizeof keybuf
[0],
1604 /* A filter may have run while we were reading the input. */
1605 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
1607 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1608 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1612 /* Now we have read a key sequence of length I,
1613 or else I is 0 and we found end of file. */
1615 if (i
== 0) /* End of file -- happens only in */
1616 return Qnil
; /* a kbd macro, at the end. */
1617 /* -1 means read_key_sequence got a menu that was rejected.
1618 Just loop around and read another command. */
1622 this_command_key_count
= 0;
1623 this_command_key_count_reset
= 0;
1624 this_single_command_key_start
= 0;
1628 last_command_char
= keybuf
[i
- 1];
1630 /* If the previous command tried to force a specific window-start,
1631 forget about that, in case this command moves point far away
1632 from that position. But also throw away beg_unchanged and
1633 end_unchanged information in that case, so that redisplay will
1634 update the whole window properly. */
1635 if (!NILP (XWINDOW (selected_window
)->force_start
))
1638 XWINDOW (selected_window
)->force_start
= Qnil
;
1639 b
= XBUFFER (XWINDOW (selected_window
)->buffer
);
1640 BUF_BEG_UNCHANGED (b
) = BUF_END_UNCHANGED (b
) = 0;
1643 cmd
= read_key_sequence_cmd
;
1644 if (!NILP (Vexecuting_kbd_macro
))
1646 if (!NILP (Vquit_flag
))
1648 Vexecuting_kbd_macro
= Qt
;
1649 QUIT
; /* Make some noise. */
1650 /* Will return since macro now empty. */
1654 /* Do redisplay processing after this command except in special
1655 cases identified below. */
1656 prev_buffer
= current_buffer
;
1657 prev_modiff
= MODIFF
;
1658 last_point_position
= PT
;
1659 last_point_position_window
= selected_window
;
1660 XSETBUFFER (last_point_position_buffer
, prev_buffer
);
1662 /* By default, we adjust point to a boundary of a region that
1663 has such a property that should be treated intangible
1664 (e.g. composition, display). But, some commands will set
1665 this variable differently. */
1666 Vdisable_point_adjustment
= Qnil
;
1668 /* Process filters and timers may have messed with deactivate-mark.
1669 reset it before we execute the command. */
1670 Vdeactivate_mark
= Qnil
;
1672 /* Remap command through active keymaps */
1673 Vthis_original_command
= cmd
;
1677 if (cmd1
= Fcommand_remapping (cmd
), !NILP (cmd1
))
1681 /* Execute the command. */
1683 Vthis_command
= cmd
;
1684 real_this_command
= cmd
;
1685 /* Note that the value cell will never directly contain nil
1686 if the symbol is a local variable. */
1687 if (!NILP (Vpre_command_hook
) && !NILP (Vrun_hooks
))
1688 safe_run_hooks (Qpre_command_hook
);
1690 already_adjusted
= 0;
1692 if (NILP (Vthis_command
))
1694 /* nil means key is undefined. */
1695 Lisp_Object keys
= Fvector (i
, keybuf
);
1696 keys
= Fkey_description (keys
, Qnil
);
1698 message_with_string ("%s is undefined", keys
, 0);
1699 current_kboard
->defining_kbd_macro
= Qnil
;
1700 update_mode_lines
= 1;
1701 current_kboard
->Vprefix_arg
= Qnil
;
1705 if (NILP (current_kboard
->Vprefix_arg
) && ! no_direct
)
1707 /* In case we jump to directly_done. */
1708 Vcurrent_prefix_arg
= current_kboard
->Vprefix_arg
;
1710 /* Recognize some common commands in common situations and
1711 do them directly. */
1712 if (EQ (Vthis_command
, Qforward_char
) && PT
< ZV
)
1714 struct Lisp_Char_Table
*dp
1715 = window_display_table (XWINDOW (selected_window
));
1716 lose
= FETCH_CHAR (PT_BYTE
);
1718 if (! NILP (Vpost_command_hook
))
1719 /* Put this before calling adjust_point_for_property
1720 so it will only get called once in any case. */
1722 if (current_buffer
== prev_buffer
1723 && last_point_position
!= PT
1724 && NILP (Vdisable_point_adjustment
)
1725 && NILP (Vglobal_disable_point_adjustment
))
1726 adjust_point_for_property (last_point_position
, 0);
1727 already_adjusted
= 1;
1728 if (PT
== last_point_position
+ 1
1730 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1731 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1732 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1733 && (lose
>= 0x20 && lose
< 0x7f)))
1734 : (lose
>= 0x20 && lose
< 0x7f))
1735 /* To extract the case of continuation on
1736 wide-column characters. */
1737 && (WIDTH_BY_CHAR_HEAD (FETCH_BYTE (PT_BYTE
)) == 1)
1738 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1740 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1742 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1744 && !windows_or_buffers_changed
1745 && EQ (current_buffer
->selective_display
, Qnil
)
1746 && !detect_input_pending ()
1747 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1748 && NILP (Vexecuting_kbd_macro
))
1749 direct_output_forward_char (1);
1752 else if (EQ (Vthis_command
, Qbackward_char
) && PT
> BEGV
)
1754 struct Lisp_Char_Table
*dp
1755 = window_display_table (XWINDOW (selected_window
));
1757 lose
= FETCH_CHAR (PT_BYTE
);
1758 if (! NILP (Vpost_command_hook
))
1760 if (current_buffer
== prev_buffer
1761 && last_point_position
!= PT
1762 && NILP (Vdisable_point_adjustment
)
1763 && NILP (Vglobal_disable_point_adjustment
))
1764 adjust_point_for_property (last_point_position
, 0);
1765 already_adjusted
= 1;
1766 if (PT
== last_point_position
- 1
1768 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1769 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1770 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1771 && (lose
>= 0x20 && lose
< 0x7f)))
1772 : (lose
>= 0x20 && lose
< 0x7f))
1773 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1775 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1777 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1779 && !windows_or_buffers_changed
1780 && EQ (current_buffer
->selective_display
, Qnil
)
1781 && !detect_input_pending ()
1782 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1783 && NILP (Vexecuting_kbd_macro
))
1784 direct_output_forward_char (-1);
1787 else if (EQ (Vthis_command
, Qself_insert_command
)
1788 /* Try this optimization only on char keystrokes. */
1789 && NATNUMP (last_command_char
)
1790 && CHAR_VALID_P (XFASTINT (last_command_char
), 0))
1793 = translate_char (Vtranslation_table_for_input
,
1794 XFASTINT (last_command_char
), 0, 0, 0);
1796 if (NILP (Vexecuting_kbd_macro
)
1797 && !EQ (minibuf_window
, selected_window
))
1799 if (!nonundocount
|| nonundocount
>= 20)
1807 lose
= ((XFASTINT (XWINDOW (selected_window
)->last_modified
)
1809 || (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1811 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1813 || MODIFF
<= SAVE_MODIFF
1814 || windows_or_buffers_changed
1815 || !EQ (current_buffer
->selective_display
, Qnil
)
1816 || detect_input_pending ()
1817 || !NILP (XWINDOW (selected_window
)->column_number_displayed
)
1818 || !NILP (Vexecuting_kbd_macro
));
1820 value
= internal_self_insert (c
, 0);
1825 if (! NILP (Vpost_command_hook
))
1826 /* Put this before calling adjust_point_for_property
1827 so it will only get called once in any case. */
1830 /* VALUE == 1 when AFTER-CHANGE functions are
1831 installed which is the case most of the time
1832 because FONT-LOCK installs one. */
1833 if (!lose
&& !value
)
1834 direct_output_for_insert (c
);
1839 /* Here for a command that isn't executed directly */
1842 #ifdef HAVE_X_WINDOWS
1843 int scount
= SPECPDL_INDEX ();
1845 if (display_hourglass_p
1846 && NILP (Vexecuting_kbd_macro
))
1848 record_unwind_protect (cancel_hourglass_unwind
, Qnil
);
1854 if (NILP (current_kboard
->Vprefix_arg
))
1856 Fcommand_execute (Vthis_command
, Qnil
, Qnil
, Qnil
);
1858 #ifdef HAVE_X_WINDOWS
1859 /* Do not check display_hourglass_p here, because
1860 Fcommand_execute could change it, but we should cancel
1861 hourglass cursor anyway.
1862 But don't cancel the hourglass within a macro
1863 just because a command in the macro finishes. */
1864 if (NILP (Vexecuting_kbd_macro
))
1865 unbind_to (scount
, Qnil
);
1870 current_kboard
->Vlast_prefix_arg
= Vcurrent_prefix_arg
;
1872 /* Note that the value cell will never directly contain nil
1873 if the symbol is a local variable. */
1874 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1875 safe_run_hooks (Qpost_command_hook
);
1877 /* If displaying a message, resize the echo area window to fit
1878 that message's size exactly. */
1879 if (!NILP (echo_area_buffer
[0]))
1880 resize_echo_area_exactly ();
1882 if (!NILP (Vdeferred_action_list
))
1883 safe_run_hooks (Qdeferred_action_function
);
1885 /* If there is a prefix argument,
1886 1) We don't want Vlast_command to be ``universal-argument''
1887 (that would be dumb), so don't set Vlast_command,
1888 2) we want to leave echoing on so that the prefix will be
1889 echoed as part of this key sequence, so don't call
1891 3) we want to leave this_command_key_count non-zero, so that
1892 read_char will realize that it is re-reading a character, and
1893 not echo it a second time.
1895 If the command didn't actually create a prefix arg,
1896 but is merely a frame event that is transparent to prefix args,
1897 then the above doesn't apply. */
1898 if (NILP (current_kboard
->Vprefix_arg
) || CONSP (last_command_char
))
1900 current_kboard
->Vlast_command
= Vthis_command
;
1901 current_kboard
->Vreal_last_command
= real_this_command
;
1903 this_command_key_count
= 0;
1904 this_command_key_count_reset
= 0;
1905 this_single_command_key_start
= 0;
1908 if (!NILP (current_buffer
->mark_active
) && !NILP (Vrun_hooks
))
1910 /* Setting transient-mark-mode to `only' is a way of
1911 turning it on for just one command. */
1913 if (EQ (Vtransient_mark_mode
, Qidentity
))
1914 Vtransient_mark_mode
= Qnil
;
1915 if (EQ (Vtransient_mark_mode
, Qonly
))
1916 Vtransient_mark_mode
= Qidentity
;
1918 if (!NILP (Vdeactivate_mark
) && !NILP (Vtransient_mark_mode
))
1920 /* We could also call `deactivate'mark'. */
1921 if (EQ (Vtransient_mark_mode
, Qlambda
))
1922 Vtransient_mark_mode
= Qnil
;
1925 current_buffer
->mark_active
= Qnil
;
1926 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
1929 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
1930 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
1935 if (current_buffer
== prev_buffer
1936 && last_point_position
!= PT
1937 && NILP (Vdisable_point_adjustment
)
1938 && NILP (Vglobal_disable_point_adjustment
)
1939 && !already_adjusted
)
1940 adjust_point_for_property (last_point_position
, MODIFF
!= prev_modiff
);
1942 /* Install chars successfully executed in kbd macro. */
1944 if (!NILP (current_kboard
->defining_kbd_macro
)
1945 && NILP (current_kboard
->Vprefix_arg
))
1946 finalize_kbd_macro_chars ();
1947 #if 0 /* This shouldn't be necessary anymore. --lorentey */
1950 any_kboard_state ();
1956 extern Lisp_Object Qcomposition
, Qdisplay
;
1958 /* Adjust point to a boundary of a region that has such a property
1959 that should be treated intangible. For the moment, we check
1960 `composition', `display' and `invisible' properties.
1961 LAST_PT is the last position of point. */
1963 extern Lisp_Object Qafter_string
, Qbefore_string
;
1964 extern Lisp_Object get_pos_property
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
));
1967 adjust_point_for_property (last_pt
, modified
)
1972 Lisp_Object val
, overlay
, tmp
;
1973 int check_composition
= 1, check_display
= 1, check_invisible
= 1;
1976 /* FIXME: cycling is probably not necessary because these properties
1977 can't be usefully combined anyway. */
1978 while (check_composition
|| check_display
|| check_invisible
)
1980 if (check_composition
1981 && PT
> BEGV
&& PT
< ZV
1982 && get_property_and_range (PT
, Qcomposition
, &val
, &beg
, &end
, Qnil
)
1983 && COMPOSITION_VALID_P (beg
, end
, val
)
1984 && beg
< PT
/* && end > PT <- It's always the case. */
1985 && (last_pt
<= beg
|| last_pt
>= end
))
1988 SET_PT (PT
< last_pt
? beg
: end
);
1989 check_display
= check_invisible
= 1;
1991 check_composition
= 0;
1993 && PT
> BEGV
&& PT
< ZV
1994 && !NILP (val
= get_char_property_and_overlay
1995 (make_number (PT
), Qdisplay
, Qnil
, &overlay
))
1996 && display_prop_intangible_p (val
)
1997 && (!OVERLAYP (overlay
)
1998 ? get_property_and_range (PT
, Qdisplay
, &val
, &beg
, &end
, Qnil
)
1999 : (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)),
2000 end
= OVERLAY_POSITION (OVERLAY_END (overlay
))))
2001 && (beg
< PT
/* && end > PT <- It's always the case. */
2002 || (beg
<= PT
&& STRINGP (val
) && SCHARS (val
) == 0)))
2005 SET_PT (PT
< last_pt
2006 ? (STRINGP (val
) && SCHARS (val
) == 0 ? beg
- 1 : beg
)
2008 check_composition
= check_invisible
= 1;
2011 if (check_invisible
&& PT
> BEGV
&& PT
< ZV
)
2013 int inv
, ellipsis
= 0;
2016 /* Find boundaries `beg' and `end' of the invisible area, if any. */
2018 && !NILP (val
= get_char_property_and_overlay
2019 (make_number (end
), Qinvisible
, Qnil
, &overlay
))
2020 && (inv
= TEXT_PROP_MEANS_INVISIBLE (val
)))
2022 ellipsis
= ellipsis
|| inv
> 1
2023 || (OVERLAYP (overlay
)
2024 && (!NILP (Foverlay_get (overlay
, Qafter_string
))
2025 || !NILP (Foverlay_get (overlay
, Qbefore_string
))));
2026 tmp
= Fnext_single_char_property_change
2027 (make_number (end
), Qinvisible
, Qnil
, Qnil
);
2028 end
= NATNUMP (tmp
) ? XFASTINT (tmp
) : ZV
;
2031 && !NILP (val
= get_char_property_and_overlay
2032 (make_number (beg
- 1), Qinvisible
, Qnil
, &overlay
))
2033 && (inv
= TEXT_PROP_MEANS_INVISIBLE (val
)))
2035 ellipsis
= ellipsis
|| inv
> 1
2036 || (OVERLAYP (overlay
)
2037 && (!NILP (Foverlay_get (overlay
, Qafter_string
))
2038 || !NILP (Foverlay_get (overlay
, Qbefore_string
))));
2039 tmp
= Fprevious_single_char_property_change
2040 (make_number (beg
), Qinvisible
, Qnil
, Qnil
);
2041 beg
= NATNUMP (tmp
) ? XFASTINT (tmp
) : BEGV
;
2044 /* Move away from the inside area. */
2045 if (beg
< PT
&& end
> PT
)
2047 SET_PT ((orig_pt
== PT
&& (last_pt
< beg
|| last_pt
> end
))
2048 /* We haven't moved yet (so we don't need to fear
2049 infinite-looping) and we were outside the range
2050 before (so either end of the range still corresponds
2051 to a move in the right direction): pretend we moved
2052 less than we actually did, so that we still have
2053 more freedom below in choosing which end of the range
2055 ? (orig_pt
= -1, PT
< last_pt
? end
: beg
)
2056 /* We either have moved already or the last point
2057 was already in the range: we don't get to choose
2058 which end of the range we have to go to. */
2059 : (PT
< last_pt
? beg
: end
));
2060 check_composition
= check_display
= 1;
2062 #if 0 /* This assertion isn't correct, because SET_PT may end up setting
2063 the point to something other than its argument, due to
2064 point-motion hooks, intangibility, etc. */
2065 xassert (PT
== beg
|| PT
== end
);
2068 /* Pretend the area doesn't exist if the buffer is not
2070 if (!modified
&& !ellipsis
&& beg
< end
)
2072 if (last_pt
== beg
&& PT
== end
&& end
< ZV
)
2073 (check_composition
= check_display
= 1, SET_PT (end
+ 1));
2074 else if (last_pt
== end
&& PT
== beg
&& beg
> BEGV
)
2075 (check_composition
= check_display
= 1, SET_PT (beg
- 1));
2076 else if (PT
== ((PT
< last_pt
) ? beg
: end
))
2077 /* We've already moved as far as we can. Trying to go
2078 to the other end would mean moving backwards and thus
2079 could lead to an infinite loop. */
2081 else if (val
= get_pos_property (make_number (PT
),
2083 TEXT_PROP_MEANS_INVISIBLE (val
)
2084 && (val
= get_pos_property
2085 (make_number (PT
== beg
? end
: beg
),
2087 !TEXT_PROP_MEANS_INVISIBLE (val
)))
2088 (check_composition
= check_display
= 1,
2089 SET_PT (PT
== beg
? end
: beg
));
2092 check_invisible
= 0;
2096 /* Subroutine for safe_run_hooks: run the hook HOOK. */
2099 safe_run_hooks_1 (hook
)
2102 return call1 (Vrun_hooks
, Vinhibit_quit
);
2105 /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */
2108 safe_run_hooks_error (data
)
2111 Lisp_Object args
[3];
2112 args
[0] = build_string ("Error in %s: %s");
2113 args
[1] = Vinhibit_quit
;
2116 return Fset (Vinhibit_quit
, Qnil
);
2119 /* If we get an error while running the hook, cause the hook variable
2120 to be nil. Also inhibit quits, so that C-g won't cause the hook
2121 to mysteriously evaporate. */
2124 safe_run_hooks (hook
)
2127 int count
= SPECPDL_INDEX ();
2128 specbind (Qinhibit_quit
, hook
);
2130 internal_condition_case (safe_run_hooks_1
, Qt
, safe_run_hooks_error
);
2132 unbind_to (count
, Qnil
);
2136 /* Number of seconds between polling for input. This is a Lisp
2137 variable that can be bound. */
2139 EMACS_INT polling_period
;
2141 /* Nonzero means polling for input is temporarily suppressed. */
2143 int poll_suppress_count
;
2145 /* Asynchronous timer for polling. */
2147 struct atimer
*poll_timer
;
2150 #ifdef POLL_FOR_INPUT
2152 /* Poll for input, so what we catch a C-g if it comes in. This
2153 function is called from x_make_frame_visible, see comment
2159 if (interrupt_input_blocked
== 0
2160 && !waiting_for_input
)
2161 read_avail_input (0);
2164 /* Timer callback function for poll_timer. TIMER is equal to
2168 poll_for_input (timer
)
2169 struct atimer
*timer
;
2171 if (poll_suppress_count
== 0)
2173 interrupt_input_pending
= 1;
2175 poll_for_input_1 ();
2179 #endif /* POLL_FOR_INPUT */
2181 /* Begin signals to poll for input, if they are appropriate.
2182 This function is called unconditionally from various places. */
2187 #ifdef POLL_FOR_INPUT
2188 /* XXX This condition was (read_socket_hook && !interrupt_input),
2189 but read_socket_hook is not global anymore. Let's pretend that
2191 if (!interrupt_input
)
2193 /* Turn alarm handling on unconditionally. It might have
2194 been turned off in process.c. */
2195 turn_on_atimers (1);
2197 /* If poll timer doesn't exist, are we need one with
2198 a different interval, start a new one. */
2199 if (poll_timer
== NULL
2200 || EMACS_SECS (poll_timer
->interval
) != polling_period
)
2202 EMACS_TIME interval
;
2205 cancel_atimer (poll_timer
);
2207 EMACS_SET_SECS_USECS (interval
, polling_period
, 0);
2208 poll_timer
= start_atimer (ATIMER_CONTINUOUS
, interval
,
2209 poll_for_input
, NULL
);
2212 /* Let the timer's callback function poll for input
2213 if this becomes zero. */
2214 --poll_suppress_count
;
2219 /* Nonzero if we are using polling to handle input asynchronously. */
2222 input_polling_used ()
2224 #ifdef POLL_FOR_INPUT
2225 /* XXX This condition was (read_socket_hook && !interrupt_input),
2226 but read_socket_hook is not global anymore. Let's pretend that
2228 return !interrupt_input
;
2234 /* Turn off polling. */
2239 #ifdef POLL_FOR_INPUT
2240 /* XXX This condition was (read_socket_hook && !interrupt_input),
2241 but read_socket_hook is not global anymore. Let's pretend that
2243 if (!interrupt_input
)
2244 ++poll_suppress_count
;
2248 /* Set the value of poll_suppress_count to COUNT
2249 and start or stop polling accordingly. */
2252 set_poll_suppress_count (count
)
2255 #ifdef POLL_FOR_INPUT
2256 if (count
== 0 && poll_suppress_count
!= 0)
2258 poll_suppress_count
= 1;
2261 else if (count
!= 0 && poll_suppress_count
== 0)
2265 poll_suppress_count
= count
;
2269 /* Bind polling_period to a value at least N.
2270 But don't decrease it. */
2273 bind_polling_period (n
)
2276 #ifdef POLL_FOR_INPUT
2277 int new = polling_period
;
2282 stop_other_atimers (poll_timer
);
2284 specbind (Qpolling_period
, make_number (new));
2285 /* Start a new alarm with the new period. */
2290 /* Apply the control modifier to CHARACTER. */
2296 /* Save the upper bits here. */
2297 int upper
= c
& ~0177;
2301 /* Everything in the columns containing the upper-case letters
2302 denotes a control character. */
2303 if (c
>= 0100 && c
< 0140)
2307 /* Set the shift modifier for a control char
2308 made from a shifted letter. But only for letters! */
2309 if (oc
>= 'A' && oc
<= 'Z')
2310 c
|= shift_modifier
;
2313 /* The lower-case letters denote control characters too. */
2314 else if (c
>= 'a' && c
<= 'z')
2317 /* Include the bits for control and shift
2318 only if the basic ASCII code can't indicate them. */
2322 /* Replace the high bits. */
2323 c
|= (upper
& ~ctrl_modifier
);
2328 /* Display the help-echo property of the character after the mouse pointer.
2329 Either show it in the echo area, or call show-help-function to display
2330 it by other means (maybe in a tooltip).
2332 If HELP is nil, that means clear the previous help echo.
2334 If HELP is a string, display that string. If HELP is a function,
2335 call it with OBJECT and POS as arguments; the function should
2336 return a help string or nil for none. For all other types of HELP,
2337 evaluate it to obtain a string.
2339 WINDOW is the window in which the help was generated, if any.
2340 It is nil if not in a window.
2342 If OBJECT is a buffer, POS is the position in the buffer where the
2343 `help-echo' text property was found.
2345 If OBJECT is an overlay, that overlay has a `help-echo' property,
2346 and POS is the position in the overlay's buffer under the mouse.
2348 If OBJECT is a string (an overlay string or a string displayed with
2349 the `display' property). POS is the position in that string under
2352 OK_TO_OVERWRITE_KEYSTROKE_ECHO non-zero means it's okay if the help
2353 echo overwrites a keystroke echo currently displayed in the echo
2356 Note: this function may only be called with HELP nil or a string
2357 from X code running asynchronously. */
2360 show_help_echo (help
, window
, object
, pos
, ok_to_overwrite_keystroke_echo
)
2361 Lisp_Object help
, window
, object
, pos
;
2362 int ok_to_overwrite_keystroke_echo
;
2364 if (!NILP (help
) && !STRINGP (help
))
2366 if (FUNCTIONP (help
))
2368 Lisp_Object args
[4];
2373 help
= safe_call (4, args
);
2376 help
= safe_eval (help
);
2378 if (!STRINGP (help
))
2383 if (!noninteractive
&& STRINGP (help
))
2384 help
= call1 (Qmouse_fixup_help_message
, help
);
2387 if (STRINGP (help
) || NILP (help
))
2389 if (!NILP (Vshow_help_function
))
2390 call1 (Vshow_help_function
, help
);
2391 else if (/* Don't overwrite minibuffer contents. */
2392 !MINI_WINDOW_P (XWINDOW (selected_window
))
2393 /* Don't overwrite a keystroke echo. */
2394 && (NILP (echo_message_buffer
)
2395 || ok_to_overwrite_keystroke_echo
)
2396 /* Don't overwrite a prompt. */
2397 && !cursor_in_echo_area
)
2401 int count
= SPECPDL_INDEX ();
2403 if (!help_echo_showing_p
)
2404 Vpre_help_message
= current_message ();
2406 specbind (Qmessage_truncate_lines
, Qt
);
2407 message3_nolog (help
, SBYTES (help
),
2408 STRING_MULTIBYTE (help
));
2409 unbind_to (count
, Qnil
);
2411 else if (STRINGP (Vpre_help_message
))
2413 message3_nolog (Vpre_help_message
,
2414 SBYTES (Vpre_help_message
),
2415 STRING_MULTIBYTE (Vpre_help_message
));
2416 Vpre_help_message
= Qnil
;
2422 help_echo_showing_p
= STRINGP (help
);
2428 /* Input of single characters from keyboard */
2430 Lisp_Object
print_help ();
2431 static Lisp_Object
kbd_buffer_get_event ();
2432 static void record_char ();
2434 #define STOP_POLLING \
2435 do { if (! polling_stopped_here) stop_polling (); \
2436 polling_stopped_here = 1; } while (0)
2438 #define RESUME_POLLING \
2439 do { if (polling_stopped_here) start_polling (); \
2440 polling_stopped_here = 0; } while (0)
2442 /* read a character from the keyboard; call the redisplay if needed */
2443 /* commandflag 0 means do not do auto-saving, but do do redisplay.
2444 -1 means do not do redisplay, but do do autosaving.
2447 /* The arguments MAPS and NMAPS are for menu prompting.
2448 MAPS is an array of keymaps; NMAPS is the length of MAPS.
2450 PREV_EVENT is the previous input event, or nil if we are reading
2451 the first event of a key sequence (or not reading a key sequence).
2452 If PREV_EVENT is t, that is a "magic" value that says
2453 not to run input methods, but in other respects to act as if
2454 not reading a key sequence.
2456 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
2457 if we used a mouse menu to read the input, or zero otherwise. If
2458 USED_MOUSE_MENU is null, we don't dereference it.
2460 WRONG_KBOARD_JMPBUF should be a stack context to longjmp to in case
2461 we find input on another keyboard.
2463 Value is t if we showed a menu and the user rejected it. */
2466 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
, wrong_kboard_jmpbuf
)
2470 Lisp_Object prev_event
;
2471 int *used_mouse_menu
;
2472 jmp_buf *wrong_kboard_jmpbuf
;
2474 volatile Lisp_Object c
;
2476 jmp_buf local_getcjmp
;
2478 volatile int key_already_recorded
= 0;
2479 Lisp_Object tem
, save
;
2480 volatile Lisp_Object previous_echo_area_message
;
2481 volatile Lisp_Object also_record
;
2482 volatile int reread
;
2483 struct gcpro gcpro1
, gcpro2
;
2484 int polling_stopped_here
= 0;
2485 struct kboard
*orig_kboard
= current_kboard
;
2489 #if 0 /* This was commented out as part of fixing echo for C-u left. */
2490 before_command_key_count
= this_command_key_count
;
2491 before_command_echo_length
= echo_length ();
2494 previous_echo_area_message
= Qnil
;
2496 GCPRO2 (c
, previous_echo_area_message
);
2501 if (CONSP (Vunread_post_input_method_events
))
2503 c
= XCAR (Vunread_post_input_method_events
);
2504 Vunread_post_input_method_events
2505 = XCDR (Vunread_post_input_method_events
);
2507 /* Undo what read_char_x_menu_prompt did when it unread
2508 additional keys returned by Fx_popup_menu. */
2510 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
)))
2518 if (unread_command_char
!= -1)
2520 XSETINT (c
, unread_command_char
);
2521 unread_command_char
= -1;
2527 if (CONSP (Vunread_command_events
))
2529 c
= XCAR (Vunread_command_events
);
2530 Vunread_command_events
= XCDR (Vunread_command_events
);
2532 /* Undo what read_char_x_menu_prompt did when it unread
2533 additional keys returned by Fx_popup_menu. */
2535 && EQ (XCDR (c
), Qdisabled
)
2536 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
))))
2539 /* If the queued event is something that used the mouse,
2540 set used_mouse_menu accordingly. */
2542 && (EQ (c
, Qtool_bar
) || EQ (c
, Qmenu_bar
)))
2543 *used_mouse_menu
= 1;
2546 goto reread_for_input_method
;
2549 if (CONSP (Vunread_input_method_events
))
2551 c
= XCAR (Vunread_input_method_events
);
2552 Vunread_input_method_events
= XCDR (Vunread_input_method_events
);
2554 /* Undo what read_char_x_menu_prompt did when it unread
2555 additional keys returned by Fx_popup_menu. */
2557 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
)))
2561 goto reread_for_input_method
;
2564 this_command_key_count_reset
= 0;
2566 if (!NILP (Vexecuting_kbd_macro
))
2568 /* We set this to Qmacro; since that's not a frame, nobody will
2569 try to switch frames on us, and the selected window will
2572 Since this event came from a macro, it would be misleading to
2573 leave internal_last_event_frame set to wherever the last
2574 real event came from. Normally, a switch-frame event selects
2575 internal_last_event_frame after each command is read, but
2576 events read from a macro should never cause a new frame to be
2578 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
2580 /* Exit the macro if we are at the end.
2581 Also, some things replace the macro with t
2582 to force an early exit. */
2583 if (EQ (Vexecuting_kbd_macro
, Qt
)
2584 || executing_kbd_macro_index
>= XFASTINT (Flength (Vexecuting_kbd_macro
)))
2590 c
= Faref (Vexecuting_kbd_macro
, make_number (executing_kbd_macro_index
));
2591 if (STRINGP (Vexecuting_kbd_macro
)
2592 && (XINT (c
) & 0x80) && (XUINT (c
) <= 0xff))
2593 XSETFASTINT (c
, CHAR_META
| (XINT (c
) & ~0x80));
2595 executing_kbd_macro_index
++;
2600 if (!NILP (unread_switch_frame
))
2602 c
= unread_switch_frame
;
2603 unread_switch_frame
= Qnil
;
2605 /* This event should make it into this_command_keys, and get echoed
2606 again, so we do not set `reread'. */
2610 /* if redisplay was requested */
2611 if (commandflag
>= 0)
2613 /* If there is pending input, process any events which are not
2614 user-visible, such as X selection_request events. */
2616 || detect_input_pending_run_timers (0))
2617 swallow_events (0); /* may clear input_pending */
2619 /* Redisplay if no pending input. */
2620 while (!input_pending
)
2622 if (help_echo_showing_p
&& !EQ (selected_window
, minibuf_window
))
2623 redisplay_preserve_echo_area (5);
2628 /* Normal case: no input arrived during redisplay. */
2631 /* Input arrived and pre-empted redisplay.
2632 Process any events which are not user-visible. */
2634 /* If that cleared input_pending, try again to redisplay. */
2638 /* Message turns off echoing unless more keystrokes turn it on again.
2640 The code in 20.x for the condition was
2642 1. echo_area_glyphs && *echo_area_glyphs
2643 2. && echo_area_glyphs != current_kboard->echobuf
2644 3. && ok_to_echo_at_next_pause != echo_area_glyphs
2646 (1) means there's a current message displayed
2648 (2) means it's not the message from echoing from the current
2651 (3) There's only one place in 20.x where ok_to_echo_at_next_pause
2652 is set to a non-null value. This is done in read_char and it is
2653 set to echo_area_glyphs after a call to echo_char. That means
2654 ok_to_echo_at_next_pause is either null or
2655 current_kboard->echobuf with the appropriate current_kboard at
2658 So, condition (3) means in clear text ok_to_echo_at_next_pause
2659 must be either null, or the current message isn't from echoing at
2660 all, or it's from echoing from a different kboard than the
2663 if (/* There currently is something in the echo area. */
2664 !NILP (echo_area_buffer
[0])
2665 && (/* And it's either not from echoing. */
2666 !EQ (echo_area_buffer
[0], echo_message_buffer
)
2667 /* Or it's an echo from a different kboard. */
2668 || echo_kboard
!= current_kboard
2669 /* Or we explicitly allow overwriting whatever there is. */
2670 || ok_to_echo_at_next_pause
== NULL
))
2675 /* Try reading a character via menu prompting in the minibuf.
2676 Try this before the sit-for, because the sit-for
2677 would do the wrong thing if we are supposed to do
2678 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
2679 after a mouse event so don't try a minibuf menu. */
2681 if (nmaps
> 0 && INTERACTIVE
2682 && !NILP (prev_event
) && ! EVENT_HAS_PARAMETERS (prev_event
)
2683 /* Don't bring up a menu if we already have another event. */
2684 && NILP (Vunread_command_events
)
2685 && unread_command_char
< 0
2686 && !detect_input_pending_run_timers (0))
2688 c
= read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
);
2691 key_already_recorded
= 1;
2696 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet.
2697 We will do that below, temporarily for short sections of code,
2698 when appropriate. local_getcjmp must be in effect
2699 around any call to sit_for or kbd_buffer_get_event;
2700 it *must not* be in effect when we call redisplay. */
2702 if (_setjmp (local_getcjmp
))
2704 /* Handle quits while reading the keyboard. */
2705 /* We must have saved the outer value of getcjmp here,
2706 so restore it now. */
2707 restore_getcjmp (save_jump
);
2708 XSETINT (c
, quit_char
);
2709 internal_last_event_frame
= selected_frame
;
2710 Vlast_event_frame
= internal_last_event_frame
;
2711 /* If we report the quit char as an event,
2712 don't do so more than once. */
2713 if (!NILP (Vinhibit_quit
))
2718 KBOARD
*kb
= FRAME_KBOARD (XFRAME (selected_frame
));
2719 if (kb
!= current_kboard
)
2721 Lisp_Object link
= kb
->kbd_queue
;
2722 /* We shouldn't get here if we were in single-kboard mode! */
2727 while (CONSP (XCDR (link
)))
2729 if (!NILP (XCDR (link
)))
2733 kb
->kbd_queue
= Fcons (c
, Qnil
);
2735 XSETCDR (link
, Fcons (c
, Qnil
));
2736 kb
->kbd_queue_has_data
= 1;
2737 current_kboard
= kb
;
2738 /* This is going to exit from read_char
2739 so we had better get rid of this frame's stuff. */
2741 if (wrong_kboard_jmpbuf
== NULL
)
2743 longjmp (*wrong_kboard_jmpbuf
, 1);
2750 timer_start_idle ();
2752 /* If in middle of key sequence and minibuffer not active,
2753 start echoing if enough time elapses. */
2755 if (minibuf_level
== 0
2756 && !current_kboard
->immediate_echo
2757 && this_command_key_count
> 0
2759 && (FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
2760 && NILP (Fzerop (Vecho_keystrokes
))
2761 && (/* No message. */
2762 NILP (echo_area_buffer
[0])
2763 /* Or empty message. */
2764 || (BUF_BEG (XBUFFER (echo_area_buffer
[0]))
2765 == BUF_Z (XBUFFER (echo_area_buffer
[0])))
2766 /* Or already echoing from same kboard. */
2767 || (echo_kboard
&& ok_to_echo_at_next_pause
== echo_kboard
)
2768 /* Or not echoing before and echoing allowed. */
2769 || (!echo_kboard
&& ok_to_echo_at_next_pause
)))
2773 /* After a mouse event, start echoing right away.
2774 This is because we are probably about to display a menu,
2775 and we don't want to delay before doing so. */
2776 if (EVENT_HAS_PARAMETERS (prev_event
))
2781 double duration
= extract_float (Vecho_keystrokes
);
2782 sec
= (int) duration
;
2783 usec
= (duration
- sec
) * 1000000;
2784 save_getcjmp (save_jump
);
2785 restore_getcjmp (local_getcjmp
);
2786 tem0
= sit_for (sec
, usec
, 1, 1, 0);
2787 restore_getcjmp (save_jump
);
2789 && ! CONSP (Vunread_command_events
))
2794 /* Maybe auto save due to number of keystrokes. */
2796 if (commandflag
!= 0
2797 && auto_save_interval
> 0
2798 && num_nonmacro_input_events
- last_auto_save
> max (auto_save_interval
, 20)
2799 && !detect_input_pending_run_timers (0))
2801 Fdo_auto_save (Qnil
, Qnil
);
2802 /* Hooks can actually change some buffers in auto save. */
2806 /* Try reading using an X menu.
2807 This is never confused with reading using the minibuf
2808 because the recursive call of read_char in read_char_minibuf_menu_prompt
2809 does not pass on any keymaps. */
2811 if (nmaps
> 0 && INTERACTIVE
2812 && !NILP (prev_event
)
2813 && EVENT_HAS_PARAMETERS (prev_event
)
2814 && !EQ (XCAR (prev_event
), Qmenu_bar
)
2815 && !EQ (XCAR (prev_event
), Qtool_bar
)
2816 /* Don't bring up a menu if we already have another event. */
2817 && NILP (Vunread_command_events
)
2818 && unread_command_char
< 0)
2820 c
= read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
2822 /* Now that we have read an event, Emacs is not idle. */
2828 /* Maybe autosave and/or garbage collect due to idleness. */
2830 if (INTERACTIVE
&& NILP (c
))
2832 int delay_level
, buffer_size
;
2834 /* Slow down auto saves logarithmically in size of current buffer,
2835 and garbage collect while we're at it. */
2836 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
2837 last_non_minibuf_size
= Z
- BEG
;
2838 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
2840 while (buffer_size
> 64)
2841 delay_level
++, buffer_size
-= buffer_size
>> 2;
2842 if (delay_level
< 4) delay_level
= 4;
2843 /* delay_level is 4 for files under around 50k, 7 at 100k,
2844 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
2846 /* Auto save if enough time goes by without input. */
2847 if (commandflag
!= 0
2848 && num_nonmacro_input_events
> last_auto_save
2849 && INTEGERP (Vauto_save_timeout
)
2850 && XINT (Vauto_save_timeout
) > 0)
2854 save_getcjmp (save_jump
);
2855 restore_getcjmp (local_getcjmp
);
2856 tem0
= sit_for (delay_level
* XFASTINT (Vauto_save_timeout
) / 4,
2858 restore_getcjmp (save_jump
);
2861 && ! CONSP (Vunread_command_events
))
2863 Fdo_auto_save (Qnil
, Qnil
);
2865 /* If we have auto-saved and there is still no input
2866 available, garbage collect if there has been enough
2867 consing going on to make it worthwhile. */
2868 if (!detect_input_pending_run_timers (0)
2869 && consing_since_gc
> gc_cons_threshold
/ 2)
2870 Fgarbage_collect ();
2877 /* Notify the caller if a timer or sentinel or filter in the sit_for
2878 calls above have changed the current kboard. This could happen
2879 if they start a recursive edit, like the fancy splash screen in
2880 server.el's filter. If this longjmp wasn't here,
2881 read_key_sequence would interpret the next key sequence using the
2882 wrong translation tables and function keymaps. */
2883 if (NILP (c
) && current_kboard
!= orig_kboard
)
2886 if (wrong_kboard_jmpbuf
== NULL
)
2888 longjmp (*wrong_kboard_jmpbuf
, 1);
2891 /* If this has become non-nil here, it has been set by a timer
2892 or sentinel or filter. */
2893 if (CONSP (Vunread_command_events
))
2895 c
= XCAR (Vunread_command_events
);
2896 Vunread_command_events
= XCDR (Vunread_command_events
);
2899 /* Read something from current KBOARD's side queue, if possible. */
2903 if (current_kboard
->kbd_queue_has_data
)
2905 if (!CONSP (current_kboard
->kbd_queue
))
2907 c
= XCAR (current_kboard
->kbd_queue
);
2908 current_kboard
->kbd_queue
2909 = XCDR (current_kboard
->kbd_queue
);
2910 if (NILP (current_kboard
->kbd_queue
))
2911 current_kboard
->kbd_queue_has_data
= 0;
2912 input_pending
= readable_events (0);
2913 if (EVENT_HAS_PARAMETERS (c
)
2914 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qswitch_frame
))
2915 internal_last_event_frame
= XCAR (XCDR (c
));
2916 Vlast_event_frame
= internal_last_event_frame
;
2921 /* If current_kboard's side queue is empty check the other kboards.
2922 If one of them has data that we have not yet seen here,
2923 switch to it and process the data waiting for it.
2925 Note: if the events queued up for another kboard
2926 have already been seen here, and therefore are not a complete command,
2927 the kbd_queue_has_data field is 0, so we skip that kboard here.
2928 That's to avoid an infinite loop switching between kboards here. */
2929 if (NILP (c
) && !single_kboard
)
2932 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2933 if (kb
->kbd_queue_has_data
)
2935 current_kboard
= kb
;
2936 /* This is going to exit from read_char
2937 so we had better get rid of this frame's stuff. */
2939 if (wrong_kboard_jmpbuf
== NULL
)
2941 longjmp (*wrong_kboard_jmpbuf
, 1);
2950 /* Finally, we read from the main queue,
2951 and if that gives us something we can't use yet, we put it on the
2952 appropriate side queue and try again. */
2958 /* Actually read a character, waiting if necessary. */
2959 save_getcjmp (save_jump
);
2960 restore_getcjmp (local_getcjmp
);
2961 timer_start_idle ();
2962 c
= kbd_buffer_get_event (&kb
, used_mouse_menu
);
2963 restore_getcjmp (save_jump
);
2966 if (! NILP (c
) && (kb
!= current_kboard
))
2968 Lisp_Object link
= kb
->kbd_queue
;
2971 while (CONSP (XCDR (link
)))
2973 if (!NILP (XCDR (link
)))
2977 kb
->kbd_queue
= Fcons (c
, Qnil
);
2979 XSETCDR (link
, Fcons (c
, Qnil
));
2980 kb
->kbd_queue_has_data
= 1;
2984 current_kboard
= kb
;
2985 /* This is going to exit from read_char
2986 so we had better get rid of this frame's stuff. */
2988 if (wrong_kboard_jmpbuf
== NULL
)
2990 longjmp (*wrong_kboard_jmpbuf
, 1);
2995 /* Terminate Emacs in batch mode if at eof. */
2996 if (noninteractive
&& INTEGERP (c
) && XINT (c
) < 0)
2997 Fkill_emacs (make_number (1));
3001 /* Add in any extra modifiers, where appropriate. */
3002 if ((extra_keyboard_modifiers
& CHAR_CTL
)
3003 || ((extra_keyboard_modifiers
& 0177) < ' '
3004 && (extra_keyboard_modifiers
& 0177) != 0))
3005 XSETINT (c
, make_ctrl_char (XINT (c
)));
3007 /* Transfer any other modifier bits directly from
3008 extra_keyboard_modifiers to c. Ignore the actual character code
3009 in the low 16 bits of extra_keyboard_modifiers. */
3010 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
3020 if (commandflag
>= 0
3021 && !input_pending
&& !detect_input_pending_run_timers (0))
3029 /* Buffer switch events are only for internal wakeups
3030 so don't show them to the user.
3031 Also, don't record a key if we already did. */
3032 if (BUFFERP (c
) || key_already_recorded
)
3035 /* Process special events within read_char
3036 and loop around to read another event. */
3039 tem
= access_keymap (get_keymap (Vspecial_event_map
, 0, 1), c
, 0, 0, 1);
3044 #if 0 /* This shouldn't be necessary anymore. --lorentey */
3045 int was_locked
= single_kboard
;
3046 int count
= SPECPDL_INDEX ();
3047 record_single_kboard_state ();
3050 last_input_char
= c
;
3051 Fcommand_execute (tem
, Qnil
, Fvector (1, &last_input_char
), Qt
);
3053 if (CONSP (c
) && EQ (XCAR (c
), Qselect_window
))
3054 /* We stopped being idle for this event; undo that. This
3055 prevents automatic window selection (under
3056 mouse_autoselect_window from acting as a real input event, for
3057 example banishing the mouse under mouse-avoidance-mode. */
3058 timer_resume_idle ();
3060 #if 0 /* This shouldn't be necessary anymore. --lorentey */
3061 /* Resume allowing input from any kboard, if that was true before. */
3063 any_kboard_state ();
3064 unbind_to (count
, Qnil
);
3070 /* Handle things that only apply to characters. */
3073 /* If kbd_buffer_get_event gave us an EOF, return that. */
3077 if ((STRINGP (current_kboard
->Vkeyboard_translate_table
)
3078 && SCHARS (current_kboard
->Vkeyboard_translate_table
) > (unsigned) XFASTINT (c
))
3079 || (VECTORP (current_kboard
->Vkeyboard_translate_table
)
3080 && XVECTOR (current_kboard
->Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
3081 || (CHAR_TABLE_P (current_kboard
->Vkeyboard_translate_table
)
3082 && CHAR_VALID_P (XINT (c
), 0)))
3085 d
= Faref (current_kboard
->Vkeyboard_translate_table
, c
);
3086 /* nil in keyboard-translate-table means no translation. */
3092 /* If this event is a mouse click in the menu bar,
3093 return just menu-bar for now. Modify the mouse click event
3094 so we won't do this twice, then queue it up. */
3095 if (EVENT_HAS_PARAMETERS (c
)
3097 && CONSP (EVENT_START (c
))
3098 && CONSP (XCDR (EVENT_START (c
))))
3102 posn
= POSN_POSN (EVENT_START (c
));
3103 /* Handle menu-bar events:
3104 insert the dummy prefix event `menu-bar'. */
3105 if (EQ (posn
, Qmenu_bar
) || EQ (posn
, Qtool_bar
))
3107 /* Change menu-bar to (menu-bar) as the event "position". */
3108 POSN_SET_POSN (EVENT_START (c
), Fcons (posn
, Qnil
));
3111 Vunread_command_events
= Fcons (c
, Vunread_command_events
);
3116 /* Store these characters into recent_keys, the dribble file if any,
3117 and the keyboard macro being defined, if any. */
3119 if (! NILP (also_record
))
3120 record_char (also_record
);
3122 /* Wipe the echo area.
3123 But first, if we are about to use an input method,
3124 save the echo area contents for it to refer to. */
3126 && ! NILP (Vinput_method_function
)
3127 && (unsigned) XINT (c
) >= ' '
3128 && (unsigned) XINT (c
) != 127
3129 && (unsigned) XINT (c
) < 256)
3131 previous_echo_area_message
= Fcurrent_message ();
3132 Vinput_method_previous_message
= previous_echo_area_message
;
3135 /* Now wipe the echo area, except for help events which do their
3136 own stuff with the echo area. */
3138 || (!(EQ (Qhelp_echo
, XCAR (c
)))
3139 && !(EQ (Qswitch_frame
, XCAR (c
)))))
3141 if (!NILP (echo_area_buffer
[0]))
3142 safe_run_hooks (Qecho_area_clear_hook
);
3143 clear_message (1, 0);
3146 reread_for_input_method
:
3148 /* Pass this to the input method, if appropriate. */
3150 && ! NILP (Vinput_method_function
)
3151 /* Don't run the input method within a key sequence,
3152 after the first event of the key sequence. */
3153 && NILP (prev_event
)
3154 && (unsigned) XINT (c
) >= ' '
3155 && (unsigned) XINT (c
) != 127
3156 && (unsigned) XINT (c
) < 256)
3159 int key_count
, key_count_reset
;
3160 struct gcpro gcpro1
;
3161 int count
= SPECPDL_INDEX ();
3163 /* Save the echo status. */
3164 int saved_immediate_echo
= current_kboard
->immediate_echo
;
3165 struct kboard
*saved_ok_to_echo
= ok_to_echo_at_next_pause
;
3166 Lisp_Object saved_echo_string
= current_kboard
->echo_string
;
3167 int saved_echo_after_prompt
= current_kboard
->echo_after_prompt
;
3170 if (before_command_restore_flag
)
3172 this_command_key_count
= before_command_key_count_1
;
3173 if (this_command_key_count
< this_single_command_key_start
)
3174 this_single_command_key_start
= this_command_key_count
;
3175 echo_truncate (before_command_echo_length_1
);
3176 before_command_restore_flag
= 0;
3180 /* Save the this_command_keys status. */
3181 key_count
= this_command_key_count
;
3182 key_count_reset
= this_command_key_count_reset
;
3185 keys
= Fcopy_sequence (this_command_keys
);
3190 /* Clear out this_command_keys. */
3191 this_command_key_count
= 0;
3192 this_command_key_count_reset
= 0;
3194 /* Now wipe the echo area. */
3195 if (!NILP (echo_area_buffer
[0]))
3196 safe_run_hooks (Qecho_area_clear_hook
);
3197 clear_message (1, 0);
3200 /* If we are not reading a key sequence,
3201 never use the echo area. */
3204 specbind (Qinput_method_use_echo_area
, Qt
);
3207 /* Call the input method. */
3208 tem
= call1 (Vinput_method_function
, c
);
3210 tem
= unbind_to (count
, tem
);
3212 /* Restore the saved echoing state
3213 and this_command_keys state. */
3214 this_command_key_count
= key_count
;
3215 this_command_key_count_reset
= key_count_reset
;
3217 this_command_keys
= keys
;
3220 ok_to_echo_at_next_pause
= saved_ok_to_echo
;
3221 current_kboard
->echo_string
= saved_echo_string
;
3222 current_kboard
->echo_after_prompt
= saved_echo_after_prompt
;
3223 if (saved_immediate_echo
)
3228 /* The input method can return no events. */
3231 /* Bring back the previous message, if any. */
3232 if (! NILP (previous_echo_area_message
))
3233 message_with_string ("%s", previous_echo_area_message
, 0);
3236 /* It returned one event or more. */
3238 Vunread_post_input_method_events
3239 = nconc2 (XCDR (tem
), Vunread_post_input_method_events
);
3244 /* Display help if not echoing. */
3245 if (CONSP (c
) && EQ (XCAR (c
), Qhelp_echo
))
3247 /* (help-echo FRAME HELP WINDOW OBJECT POS). */
3248 Lisp_Object help
, object
, position
, window
, tem
;
3250 tem
= Fcdr (XCDR (c
));
3253 window
= Fcar (tem
);
3255 object
= Fcar (tem
);
3257 position
= Fcar (tem
);
3259 show_help_echo (help
, window
, object
, position
, 0);
3261 /* We stopped being idle for this event; undo that. */
3262 timer_resume_idle ();
3266 if (! reread
|| this_command_key_count
== 0
3267 || this_command_key_count_reset
)
3270 /* Don't echo mouse motion events. */
3271 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
3272 && NILP (Fzerop (Vecho_keystrokes
))
3273 && ! (EVENT_HAS_PARAMETERS (c
)
3274 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
3277 if (! NILP (also_record
))
3278 echo_char (also_record
);
3279 /* Once we reread a character, echoing can happen
3280 the next time we pause to read a new one. */
3281 ok_to_echo_at_next_pause
= current_kboard
;
3284 /* Record this character as part of the current key. */
3285 add_command_key (c
);
3286 if (! NILP (also_record
))
3287 add_command_key (also_record
);
3290 last_input_char
= c
;
3293 /* Process the help character specially if enabled */
3294 if (!NILP (Vhelp_form
) && help_char_p (c
))
3297 count
= SPECPDL_INDEX ();
3299 record_unwind_protect (Fset_window_configuration
,
3300 Fcurrent_window_configuration (Qnil
));
3302 tem0
= Feval (Vhelp_form
);
3304 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
3308 c
= read_char (0, 0, 0, Qnil
, 0, &wrong_kboard_jmpbuf
);
3309 while (BUFFERP (c
));
3310 /* Remove the help from the frame */
3311 unbind_to (count
, Qnil
);
3314 if (EQ (c
, make_number (040)))
3318 c
= read_char (0, 0, 0, Qnil
, 0, &wrong_kboard_jmpbuf
);
3319 while (BUFFERP (c
));
3328 /* Record a key that came from a mouse menu.
3329 Record it for echoing, for this-command-keys, and so on. */
3335 /* Wipe the echo area. */
3336 clear_message (1, 0);
3341 before_command_key_count
= this_command_key_count
;
3342 before_command_echo_length
= echo_length ();
3345 /* Don't echo mouse motion events. */
3346 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
3347 && NILP (Fzerop (Vecho_keystrokes
)))
3351 /* Once we reread a character, echoing can happen
3352 the next time we pause to read a new one. */
3353 ok_to_echo_at_next_pause
= 0;
3356 /* Record this character as part of the current key. */
3357 add_command_key (c
);
3359 /* Re-reading in the middle of a command */
3360 last_input_char
= c
;
3364 /* Return 1 if should recognize C as "the help character". */
3372 if (EQ (c
, Vhelp_char
))
3374 for (tail
= Vhelp_event_list
; CONSP (tail
); tail
= XCDR (tail
))
3375 if (EQ (c
, XCAR (tail
)))
3380 /* Record the input event C in various ways. */
3388 if (CONSP (c
) && (EQ (XCAR (c
), Qhelp_echo
) || EQ (XCAR (c
), Qmouse_movement
)))
3390 /* To avoid filling recent_keys with help-echo and mouse-movement
3391 events, we filter out repeated help-echo events, only store the
3392 first and last in a series of mouse-movement events, and don't
3393 store repeated help-echo events which are only separated by
3394 mouse-movement events. */
3396 Lisp_Object ev1
, ev2
, ev3
;
3399 if ((ix1
= recent_keys_index
- 1) < 0)
3400 ix1
= NUM_RECENT_KEYS
- 1;
3401 ev1
= AREF (recent_keys
, ix1
);
3403 if ((ix2
= ix1
- 1) < 0)
3404 ix2
= NUM_RECENT_KEYS
- 1;
3405 ev2
= AREF (recent_keys
, ix2
);
3407 if ((ix3
= ix2
- 1) < 0)
3408 ix3
= NUM_RECENT_KEYS
- 1;
3409 ev3
= AREF (recent_keys
, ix3
);
3411 if (EQ (XCAR (c
), Qhelp_echo
))
3413 /* Don't record `help-echo' in recent_keys unless it shows some help
3414 message, and a different help than the previously recorded
3416 Lisp_Object help
, last_help
;
3418 help
= Fcar_safe (Fcdr_safe (XCDR (c
)));
3419 if (!STRINGP (help
))
3421 else if (CONSP (ev1
) && EQ (XCAR (ev1
), Qhelp_echo
)
3422 && (last_help
= Fcar_safe (Fcdr_safe (XCDR (ev1
))), EQ (last_help
, help
)))
3424 else if (CONSP (ev1
) && EQ (XCAR (ev1
), Qmouse_movement
)
3425 && CONSP (ev2
) && EQ (XCAR (ev2
), Qhelp_echo
)
3426 && (last_help
= Fcar_safe (Fcdr_safe (XCDR (ev2
))), EQ (last_help
, help
)))
3428 else if (CONSP (ev1
) && EQ (XCAR (ev1
), Qmouse_movement
)
3429 && CONSP (ev2
) && EQ (XCAR (ev2
), Qmouse_movement
)
3430 && CONSP (ev3
) && EQ (XCAR (ev3
), Qhelp_echo
)
3431 && (last_help
= Fcar_safe (Fcdr_safe (XCDR (ev3
))), EQ (last_help
, help
)))
3434 else if (EQ (XCAR (c
), Qmouse_movement
))
3436 /* Only record one pair of `mouse-movement' on a window in recent_keys.
3437 So additional mouse movement events replace the last element. */
3438 Lisp_Object last_window
, window
;
3440 window
= Fcar_safe (Fcar_safe (XCDR (c
)));
3441 if (CONSP (ev1
) && EQ (XCAR (ev1
), Qmouse_movement
)
3442 && (last_window
= Fcar_safe (Fcar_safe (XCDR (ev1
))), EQ (last_window
, window
))
3443 && CONSP (ev2
) && EQ (XCAR (ev2
), Qmouse_movement
)
3444 && (last_window
= Fcar_safe (Fcar_safe (XCDR (ev2
))), EQ (last_window
, window
)))
3446 ASET (recent_keys
, ix1
, c
);
3452 store_kbd_macro_char (c
);
3457 ASET (recent_keys
, recent_keys_index
, c
);
3458 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
3459 recent_keys_index
= 0;
3461 else if (recorded
< 0)
3463 /* We need to remove one or two events from recent_keys.
3464 To do this, we simply put nil at those events and move the
3465 recent_keys_index backwards over those events. Usually,
3466 users will never see those nil events, as they will be
3467 overwritten by the command keys entered to see recent_keys
3470 while (recorded
++ < 0 && total_keys
> 0)
3472 if (total_keys
< NUM_RECENT_KEYS
)
3474 if (--recent_keys_index
< 0)
3475 recent_keys_index
= NUM_RECENT_KEYS
- 1;
3476 ASET (recent_keys
, recent_keys_index
, Qnil
);
3480 num_nonmacro_input_events
++;
3482 /* Write c to the dribble file. If c is a lispy event, write
3483 the event's symbol to the dribble file, in <brackets>. Bleaugh.
3484 If you, dear reader, have a better idea, you've got the source. :-) */
3489 if (XUINT (c
) < 0x100)
3490 putc (XINT (c
), dribble
);
3492 fprintf (dribble
, " 0x%x", (int) XUINT (c
));
3496 Lisp_Object dribblee
;
3498 /* If it's a structured event, take the event header. */
3499 dribblee
= EVENT_HEAD (c
);
3501 if (SYMBOLP (dribblee
))
3503 putc ('<', dribble
);
3504 fwrite (SDATA (SYMBOL_NAME (dribblee
)), sizeof (char),
3505 SBYTES (SYMBOL_NAME (dribblee
)),
3507 putc ('>', dribble
);
3519 struct buffer
*old
= current_buffer
;
3520 Fprinc (object
, Qnil
);
3521 set_buffer_internal (XBUFFER (Vstandard_output
));
3522 call0 (intern ("help-mode"));
3523 set_buffer_internal (old
);
3527 /* Copy out or in the info on where C-g should throw to.
3528 This is used when running Lisp code from within get_char,
3529 in case get_char is called recursively.
3530 See read_process_output. */
3536 bcopy (getcjmp
, temp
, sizeof getcjmp
);
3540 restore_getcjmp (temp
)
3543 bcopy (temp
, getcjmp
, sizeof getcjmp
);
3548 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
3549 of this function. */
3552 tracking_off (old_value
)
3553 Lisp_Object old_value
;
3555 do_mouse_tracking
= old_value
;
3556 if (NILP (old_value
))
3558 /* Redisplay may have been preempted because there was input
3559 available, and it assumes it will be called again after the
3560 input has been processed. If the only input available was
3561 the sort that we have just disabled, then we need to call
3563 if (!readable_events (READABLE_EVENTS_DO_TIMERS_NOW
))
3565 redisplay_preserve_echo_area (6);
3566 get_input_pending (&input_pending
,
3567 READABLE_EVENTS_DO_TIMERS_NOW
);
3573 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
3574 doc
: /* Evaluate BODY with mouse movement events enabled.
3575 Within a `track-mouse' form, mouse motion generates input events that
3576 you can read with `read-event'.
3577 Normally, mouse motion is ignored.
3578 usage: (track-mouse BODY ...) */)
3582 int count
= SPECPDL_INDEX ();
3585 record_unwind_protect (tracking_off
, do_mouse_tracking
);
3587 do_mouse_tracking
= Qt
;
3589 val
= Fprogn (args
);
3590 return unbind_to (count
, val
);
3593 /* If mouse has moved on some frame, return one of those frames.
3594 Return 0 otherwise. */
3599 Lisp_Object tail
, frame
;
3601 FOR_EACH_FRAME (tail
, frame
)
3603 if (XFRAME (frame
)->mouse_moved
)
3604 return XFRAME (frame
);
3610 #endif /* HAVE_MOUSE */
3612 /* Low level keyboard/mouse input.
3613 kbd_buffer_store_event places events in kbd_buffer, and
3614 kbd_buffer_get_event retrieves them. */
3616 /* Return true iff there are any events in the queue that read-char
3617 would return. If this returns false, a read-char would block. */
3619 readable_events (flags
)
3622 if (flags
& READABLE_EVENTS_DO_TIMERS_NOW
)
3625 /* If the buffer contains only FOCUS_IN_EVENT events, and
3626 READABLE_EVENTS_FILTER_EVENTS is set, report it as empty. */
3627 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3629 if (flags
& (READABLE_EVENTS_FILTER_EVENTS
3630 #ifdef USE_TOOLKIT_SCROLL_BARS
3631 | READABLE_EVENTS_IGNORE_SQUEEZABLES
3635 struct input_event
*event
;
3637 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
3644 #ifdef USE_TOOLKIT_SCROLL_BARS
3645 (flags
& READABLE_EVENTS_FILTER_EVENTS
) &&
3647 event
->kind
== FOCUS_IN_EVENT
)
3648 #ifdef USE_TOOLKIT_SCROLL_BARS
3649 && !((flags
& READABLE_EVENTS_IGNORE_SQUEEZABLES
)
3650 && event
->kind
== SCROLL_BAR_CLICK_EVENT
3651 && event
->part
== scroll_bar_handle
3652 && event
->modifiers
== 0)
3657 if (event
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3660 while (event
!= kbd_store_ptr
);
3667 if (!(flags
& READABLE_EVENTS_IGNORE_SQUEEZABLES
)
3668 && !NILP (do_mouse_tracking
) && some_mouse_moved ())
3673 if (current_kboard
->kbd_queue_has_data
)
3679 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
3680 if (kb
->kbd_queue_has_data
)
3686 /* Set this for debugging, to have a way to get out */
3691 event_to_kboard (event
)
3692 struct input_event
*event
;
3695 frame
= event
->frame_or_window
;
3697 frame
= XCAR (frame
);
3698 else if (WINDOWP (frame
))
3699 frame
= WINDOW_FRAME (XWINDOW (frame
));
3701 /* There are still some events that don't set this field.
3702 For now, just ignore the problem.
3703 Also ignore dead frames here. */
3704 if (!FRAMEP (frame
) || !FRAME_LIVE_P (XFRAME (frame
)))
3707 return FRAME_KBOARD (XFRAME (frame
));
3712 Lisp_Object Vthrow_on_input
;
3714 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
3717 kbd_buffer_store_event (event
)
3718 register struct input_event
*event
;
3720 kbd_buffer_store_event_hold (event
, 0);
3723 /* Store EVENT obtained at interrupt level into kbd_buffer, fifo.
3725 If HOLD_QUIT is 0, just stuff EVENT into the fifo.
3726 Else, if HOLD_QUIT.kind != NO_EVENT, discard EVENT.
3727 Else, if EVENT is a quit event, store the quit event
3728 in HOLD_QUIT, and return (thus ignoring further events).
3730 This is used in read_avail_input to postpone the processing
3731 of the quit event until all subsequent input events have been
3732 parsed (and discarded).
3736 kbd_buffer_store_event_hold (event
, hold_quit
)
3737 register struct input_event
*event
;
3738 struct input_event
*hold_quit
;
3740 if (event
->kind
== NO_EVENT
)
3743 if (hold_quit
&& hold_quit
->kind
!= NO_EVENT
)
3746 if (event
->kind
== ASCII_KEYSTROKE_EVENT
)
3748 register int c
= event
->code
& 0377;
3750 if (event
->modifiers
& ctrl_modifier
)
3751 c
= make_ctrl_char (c
);
3753 c
|= (event
->modifiers
3754 & (meta_modifier
| alt_modifier
3755 | hyper_modifier
| super_modifier
));
3760 KBOARD
*kb
= FRAME_KBOARD (XFRAME (event
->frame_or_window
));
3761 struct input_event
*sp
;
3763 if (single_kboard
&& kb
!= current_kboard
)
3766 = Fcons (make_lispy_switch_frame (event
->frame_or_window
),
3767 Fcons (make_number (c
), Qnil
));
3768 kb
->kbd_queue_has_data
= 1;
3769 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
3771 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3774 if (event_to_kboard (sp
) == kb
)
3776 sp
->kind
= NO_EVENT
;
3777 sp
->frame_or_window
= Qnil
;
3787 bcopy (event
, (char *) hold_quit
, sizeof (*event
));
3791 /* If this results in a quit_char being returned to Emacs as
3792 input, set Vlast_event_frame properly. If this doesn't
3793 get returned to Emacs as an event, the next event read
3794 will set Vlast_event_frame again, so this is safe to do. */
3798 focus
= FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
3800 focus
= event
->frame_or_window
;
3801 internal_last_event_frame
= focus
;
3802 Vlast_event_frame
= focus
;
3805 last_event_timestamp
= event
->timestamp
;
3806 handle_interrupt ();
3810 if (c
&& c
== stop_character
)
3816 /* Don't insert two BUFFER_SWITCH_EVENT's in a row.
3817 Just ignore the second one. */
3818 else if (event
->kind
== BUFFER_SWITCH_EVENT
3819 && kbd_fetch_ptr
!= kbd_store_ptr
3820 && ((kbd_store_ptr
== kbd_buffer
3821 ? kbd_buffer
+ KBD_BUFFER_SIZE
- 1
3822 : kbd_store_ptr
- 1)->kind
) == BUFFER_SWITCH_EVENT
)
3825 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
3826 kbd_store_ptr
= kbd_buffer
;
3828 /* Don't let the very last slot in the buffer become full,
3829 since that would make the two pointers equal,
3830 and that is indistinguishable from an empty buffer.
3831 Discard the event if it would fill the last slot. */
3832 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
3834 *kbd_store_ptr
= *event
;
3838 /* If we're inside while-no-input, and this event qualifies
3839 as input, set quit-flag to cause an interrupt. */
3840 if (!NILP (Vthrow_on_input
)
3841 && event
->kind
!= FOCUS_IN_EVENT
3842 && event
->kind
!= HELP_EVENT
3843 && event
->kind
!= DEICONIFY_EVENT
)
3845 Vquit_flag
= Vthrow_on_input
;
3846 /* If we're inside a function that wants immediate quits,
3848 if (immediate_quit
&& NILP (Vinhibit_quit
))
3858 /* Put an input event back in the head of the event queue. */
3861 kbd_buffer_unget_event (event
)
3862 register struct input_event
*event
;
3864 if (kbd_fetch_ptr
== kbd_buffer
)
3865 kbd_fetch_ptr
= kbd_buffer
+ KBD_BUFFER_SIZE
;
3867 /* Don't let the very last slot in the buffer become full, */
3868 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
3871 *kbd_fetch_ptr
= *event
;
3876 /* Generate HELP_EVENT input_events in BUFP which has room for
3877 SIZE events. If there's not enough room in BUFP, ignore this
3880 HELP is the help form.
3882 FRAME is the frame on which the help is generated. OBJECT is the
3883 Lisp object where the help was found (a buffer, a string, an
3884 overlay, or nil if neither from a string nor from a buffer. POS is
3885 the position within OBJECT where the help was found.
3887 Value is the number of input_events generated. */
3890 gen_help_event (help
, frame
, window
, object
, pos
)
3891 Lisp_Object help
, frame
, object
, window
;
3894 struct input_event event
;
3898 event
.kind
= HELP_EVENT
;
3899 event
.frame_or_window
= frame
;
3901 event
.x
= WINDOWP (window
) ? window
: frame
;
3904 kbd_buffer_store_event (&event
);
3908 /* Store HELP_EVENTs for HELP on FRAME in the input queue. */
3911 kbd_buffer_store_help_event (frame
, help
)
3912 Lisp_Object frame
, help
;
3914 struct input_event event
;
3916 event
.kind
= HELP_EVENT
;
3917 event
.frame_or_window
= frame
;
3922 kbd_buffer_store_event (&event
);
3926 /* Discard any mouse events in the event buffer by setting them to
3929 discard_mouse_events ()
3931 struct input_event
*sp
;
3932 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
3934 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3937 if (sp
->kind
== MOUSE_CLICK_EVENT
3938 || sp
->kind
== WHEEL_EVENT
3940 || sp
->kind
== W32_SCROLL_BAR_CLICK_EVENT
3942 || sp
->kind
== SCROLL_BAR_CLICK_EVENT
)
3944 sp
->kind
= NO_EVENT
;
3950 /* Return non-zero if there are any real events waiting in the event
3951 buffer, not counting `NO_EVENT's.
3953 If DISCARD is non-zero, discard NO_EVENT events at the front of
3954 the input queue, possibly leaving the input queue empty if there
3955 are no real input events. */
3958 kbd_buffer_events_waiting (discard
)
3961 struct input_event
*sp
;
3963 for (sp
= kbd_fetch_ptr
;
3964 sp
!= kbd_store_ptr
&& sp
->kind
== NO_EVENT
;
3967 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3974 return sp
!= kbd_store_ptr
&& sp
->kind
!= NO_EVENT
;
3978 /* Clear input event EVENT. */
3982 struct input_event
*event
;
3984 event
->kind
= NO_EVENT
;
3988 /* Read one event from the event buffer, waiting if necessary.
3989 The value is a Lisp object representing the event.
3990 The value is nil for an event that should be ignored,
3991 or that was handled here.
3992 We always read and discard one event. */
3995 kbd_buffer_get_event (kbp
, used_mouse_menu
)
3997 int *used_mouse_menu
;
4006 *kbp
= current_kboard
;
4010 /* Wait until there is input available. */
4013 if (kbd_fetch_ptr
!= kbd_store_ptr
)
4016 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
4020 /* If the quit flag is set, then read_char will return
4021 quit_char, so that counts as "available input." */
4022 if (!NILP (Vquit_flag
))
4023 quit_throw_to_read_char ();
4025 /* One way or another, wait until input is available; then, if
4026 interrupt handlers have not read it, read it now. */
4029 wait_for_kbd_input ();
4031 /* Note SIGIO has been undef'd if FIONREAD is missing. */
4035 if (kbd_fetch_ptr
!= kbd_store_ptr
)
4038 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
4042 wait_reading_process_output (0, 0, -1, 1, Qnil
, NULL
, 0);
4044 if (!interrupt_input
&& kbd_fetch_ptr
== kbd_store_ptr
)
4045 /* Pass 1 for EXPECT since we just waited to have input. */
4046 read_avail_input (1);
4048 #endif /* not VMS */
4051 if (CONSP (Vunread_command_events
))
4054 first
= XCAR (Vunread_command_events
);
4055 Vunread_command_events
= XCDR (Vunread_command_events
);
4056 *kbp
= current_kboard
;
4060 /* At this point, we know that there is a readable event available
4061 somewhere. If the event queue is empty, then there must be a
4062 mouse movement enabled and available. */
4063 if (kbd_fetch_ptr
!= kbd_store_ptr
)
4065 struct input_event
*event
;
4067 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
4071 last_event_timestamp
= event
->timestamp
;
4074 *kbp
= event_to_kboard (event
);
4076 *kbp
= current_kboard
; /* Better than returning null ptr? */
4078 *kbp
= &the_only_kboard
;
4083 /* These two kinds of events get special handling
4084 and don't actually appear to the command loop.
4085 We return nil for them. */
4086 if (event
->kind
== SELECTION_REQUEST_EVENT
4087 || event
->kind
== SELECTION_CLEAR_EVENT
)
4090 struct input_event copy
;
4092 /* Remove it from the buffer before processing it,
4093 since otherwise swallow_events will see it
4094 and process it again. */
4096 kbd_fetch_ptr
= event
+ 1;
4097 input_pending
= readable_events (0);
4098 x_handle_selection_event (©
);
4100 /* We're getting selection request events, but we don't have
4106 #if defined (HAVE_X11) || defined (HAVE_NTGUI) || defined (MAC_OS)
4107 else if (event
->kind
== DELETE_WINDOW_EVENT
)
4109 /* Make an event (delete-frame (FRAME)). */
4110 obj
= Fcons (event
->frame_or_window
, Qnil
);
4111 obj
= Fcons (Qdelete_frame
, Fcons (obj
, Qnil
));
4112 kbd_fetch_ptr
= event
+ 1;
4115 #if defined (HAVE_X11) || defined (HAVE_NTGUI) || defined (MAC_OS)
4116 else if (event
->kind
== ICONIFY_EVENT
)
4118 /* Make an event (iconify-frame (FRAME)). */
4119 obj
= Fcons (event
->frame_or_window
, Qnil
);
4120 obj
= Fcons (Qiconify_frame
, Fcons (obj
, Qnil
));
4121 kbd_fetch_ptr
= event
+ 1;
4123 else if (event
->kind
== DEICONIFY_EVENT
)
4125 /* Make an event (make-frame-visible (FRAME)). */
4126 obj
= Fcons (event
->frame_or_window
, Qnil
);
4127 obj
= Fcons (Qmake_frame_visible
, Fcons (obj
, Qnil
));
4128 kbd_fetch_ptr
= event
+ 1;
4131 else if (event
->kind
== BUFFER_SWITCH_EVENT
)
4133 /* The value doesn't matter here; only the type is tested. */
4134 XSETBUFFER (obj
, current_buffer
);
4135 kbd_fetch_ptr
= event
+ 1;
4137 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
4138 || defined (USE_GTK)
4139 else if (event
->kind
== MENU_BAR_ACTIVATE_EVENT
)
4141 kbd_fetch_ptr
= event
+ 1;
4142 input_pending
= readable_events (0);
4143 if (FRAME_LIVE_P (XFRAME (event
->frame_or_window
)))
4144 x_activate_menubar (XFRAME (event
->frame_or_window
));
4147 #if defined (WINDOWSNT) || defined (MAC_OS)
4148 else if (event
->kind
== LANGUAGE_CHANGE_EVENT
)
4151 /* Make an event (language-change (KEY_SCRIPT)). */
4152 obj
= Fcons (make_number (event
->code
), Qnil
);
4154 /* Make an event (language-change (FRAME CHARSET LCID)). */
4155 obj
= Fcons (event
->frame_or_window
, Qnil
);
4157 obj
= Fcons (Qlanguage_change
, Fcons (obj
, Qnil
));
4158 kbd_fetch_ptr
= event
+ 1;
4161 else if (event
->kind
== SAVE_SESSION_EVENT
)
4163 obj
= Fcons (Qsave_session
, Qnil
);
4164 kbd_fetch_ptr
= event
+ 1;
4166 /* Just discard these, by returning nil.
4167 With MULTI_KBOARD, these events are used as placeholders
4168 when we need to randomly delete events from the queue.
4169 (They shouldn't otherwise be found in the buffer,
4170 but on some machines it appears they do show up
4171 even without MULTI_KBOARD.) */
4172 /* On Windows NT/9X, NO_EVENT is used to delete extraneous
4173 mouse events during a popup-menu call. */
4174 else if (event
->kind
== NO_EVENT
)
4175 kbd_fetch_ptr
= event
+ 1;
4176 else if (event
->kind
== HELP_EVENT
)
4178 Lisp_Object object
, position
, help
, frame
, window
;
4180 frame
= event
->frame_or_window
;
4181 object
= event
->arg
;
4182 position
= make_number (event
->code
);
4185 clear_event (event
);
4187 kbd_fetch_ptr
= event
+ 1;
4188 if (!WINDOWP (window
))
4190 obj
= Fcons (Qhelp_echo
,
4191 list5 (frame
, help
, window
, object
, position
));
4193 else if (event
->kind
== FOCUS_IN_EVENT
)
4195 /* Notification of a FocusIn event. The frame receiving the
4196 focus is in event->frame_or_window. Generate a
4197 switch-frame event if necessary. */
4198 Lisp_Object frame
, focus
;
4200 frame
= event
->frame_or_window
;
4201 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
4205 if (!EQ (frame
, internal_last_event_frame
)
4206 && !EQ (frame
, selected_frame
))
4207 obj
= make_lispy_switch_frame (frame
);
4208 internal_last_event_frame
= frame
;
4209 kbd_fetch_ptr
= event
+ 1;
4213 /* If this event is on a different frame, return a switch-frame this
4214 time, and leave the event in the queue for next time. */
4218 frame
= event
->frame_or_window
;
4220 frame
= XCAR (frame
);
4221 else if (WINDOWP (frame
))
4222 frame
= WINDOW_FRAME (XWINDOW (frame
));
4224 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
4228 if (! EQ (frame
, internal_last_event_frame
)
4229 && !EQ (frame
, selected_frame
))
4230 obj
= make_lispy_switch_frame (frame
);
4231 internal_last_event_frame
= frame
;
4233 /* If we didn't decide to make a switch-frame event, go ahead
4234 and build a real event from the queue entry. */
4238 obj
= make_lispy_event (event
);
4240 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined(MAC_OS) \
4241 || defined (USE_GTK)
4242 /* If this was a menu selection, then set the flag to inhibit
4243 writing to last_nonmenu_event. Don't do this if the event
4244 we're returning is (menu-bar), though; that indicates the
4245 beginning of the menu sequence, and we might as well leave
4246 that as the `event with parameters' for this selection. */
4248 && !EQ (event
->frame_or_window
, event
->arg
)
4249 && (event
->kind
== MENU_BAR_EVENT
4250 || event
->kind
== TOOL_BAR_EVENT
))
4251 *used_mouse_menu
= 1;
4254 /* Wipe out this event, to catch bugs. */
4255 clear_event (event
);
4256 kbd_fetch_ptr
= event
+ 1;
4261 /* Try generating a mouse motion event. */
4262 else if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
4264 FRAME_PTR f
= some_mouse_moved ();
4265 Lisp_Object bar_window
;
4266 enum scroll_bar_part part
;
4270 *kbp
= current_kboard
;
4271 /* Note that this uses F to determine which terminal to look at.
4272 If there is no valid info, it does not store anything
4273 so x remains nil. */
4276 /* XXX Can f or mouse_position_hook be NULL here? */
4277 if (f
&& FRAME_TERMINAL (f
)->mouse_position_hook
)
4278 (*FRAME_TERMINAL (f
)->mouse_position_hook
) (&f
, 0, &bar_window
,
4279 &part
, &x
, &y
, &time
);
4283 /* Decide if we should generate a switch-frame event. Don't
4284 generate switch-frame events for motion outside of all Emacs
4290 frame
= FRAME_FOCUS_FRAME (f
);
4292 XSETFRAME (frame
, f
);
4294 if (! EQ (frame
, internal_last_event_frame
)
4295 && !EQ (frame
, selected_frame
))
4296 obj
= make_lispy_switch_frame (frame
);
4297 internal_last_event_frame
= frame
;
4300 /* If we didn't decide to make a switch-frame event, go ahead and
4301 return a mouse-motion event. */
4302 if (!NILP (x
) && NILP (obj
))
4303 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
4305 #endif /* HAVE_MOUSE */
4307 /* We were promised by the above while loop that there was
4308 something for us to read! */
4311 input_pending
= readable_events (0);
4313 Vlast_event_frame
= internal_last_event_frame
;
4318 /* Process any events that are not user-visible,
4319 then return, without reading any user-visible events. */
4322 swallow_events (do_display
)
4327 while (kbd_fetch_ptr
!= kbd_store_ptr
)
4329 struct input_event
*event
;
4331 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
4335 last_event_timestamp
= event
->timestamp
;
4337 /* These two kinds of events get special handling
4338 and don't actually appear to the command loop. */
4339 if (event
->kind
== SELECTION_REQUEST_EVENT
4340 || event
->kind
== SELECTION_CLEAR_EVENT
)
4343 struct input_event copy
;
4345 /* Remove it from the buffer before processing it,
4346 since otherwise swallow_events called recursively could see it
4347 and process it again. */
4349 kbd_fetch_ptr
= event
+ 1;
4350 input_pending
= readable_events (0);
4351 x_handle_selection_event (©
);
4353 /* We're getting selection request events, but we don't have
4362 old_timers_run
= timers_run
;
4363 get_input_pending (&input_pending
, READABLE_EVENTS_DO_TIMERS_NOW
);
4365 if (timers_run
!= old_timers_run
&& do_display
)
4366 redisplay_preserve_echo_area (7);
4369 /* Record the start of when Emacs is idle,
4370 for the sake of running idle-time timers. */
4377 /* If we are already in the idle state, do nothing. */
4378 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
4381 EMACS_GET_TIME (timer_idleness_start_time
);
4383 timer_last_idleness_start_time
= timer_idleness_start_time
;
4385 /* Mark all idle-time timers as once again candidates for running. */
4386 for (timers
= Vtimer_idle_list
; CONSP (timers
); timers
= XCDR (timers
))
4390 timer
= XCAR (timers
);
4392 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
4394 XVECTOR (timer
)->contents
[0] = Qnil
;
4398 /* Record that Emacs is no longer idle, so stop running idle-time timers. */
4403 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
4406 /* Resume idle timer from last idle start time. */
4409 timer_resume_idle ()
4411 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
4414 timer_idleness_start_time
= timer_last_idleness_start_time
;
4417 /* This is only for debugging. */
4418 struct input_event last_timer_event
;
4420 /* Check whether a timer has fired. To prevent larger problems we simply
4421 disregard elements that are not proper timers. Do not make a circular
4422 timer list for the time being.
4424 Returns the number of seconds to wait until the next timer fires. If a
4425 timer is triggering now, return zero seconds.
4426 If no timer is active, return -1 seconds.
4428 If a timer is ripe, we run it, with quitting turned off.
4430 DO_IT_NOW is now ignored. It used to mean that we should
4431 run the timer directly instead of queueing a timer-event.
4432 Now we always run timers directly. */
4435 timer_check (do_it_now
)
4438 EMACS_TIME nexttime
;
4439 EMACS_TIME now
, idleness_now
;
4440 Lisp_Object timers
, idle_timers
, chosen_timer
;
4441 struct gcpro gcpro1
, gcpro2
, gcpro3
;
4443 EMACS_SET_SECS (nexttime
, -1);
4444 EMACS_SET_USECS (nexttime
, -1);
4446 /* Always consider the ordinary timers. */
4447 timers
= Vtimer_list
;
4448 /* Consider the idle timers only if Emacs is idle. */
4449 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
4450 idle_timers
= Vtimer_idle_list
;
4453 chosen_timer
= Qnil
;
4454 GCPRO3 (timers
, idle_timers
, chosen_timer
);
4456 if (CONSP (timers
) || CONSP (idle_timers
))
4458 EMACS_GET_TIME (now
);
4459 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
4460 EMACS_SUB_TIME (idleness_now
, now
, timer_idleness_start_time
);
4463 while (CONSP (timers
) || CONSP (idle_timers
))
4465 Lisp_Object
*vector
;
4466 Lisp_Object timer
= Qnil
, idle_timer
= Qnil
;
4467 EMACS_TIME timer_time
, idle_timer_time
;
4468 EMACS_TIME difference
, timer_difference
, idle_timer_difference
;
4470 /* Skip past invalid timers and timers already handled. */
4473 timer
= XCAR (timers
);
4474 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
4476 timers
= XCDR (timers
);
4479 vector
= XVECTOR (timer
)->contents
;
4481 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
4482 || !INTEGERP (vector
[3])
4483 || ! NILP (vector
[0]))
4485 timers
= XCDR (timers
);
4489 if (!NILP (idle_timers
))
4491 timer
= XCAR (idle_timers
);
4492 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
4494 idle_timers
= XCDR (idle_timers
);
4497 vector
= XVECTOR (timer
)->contents
;
4499 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
4500 || !INTEGERP (vector
[3])
4501 || ! NILP (vector
[0]))
4503 idle_timers
= XCDR (idle_timers
);
4508 /* Set TIMER, TIMER_TIME and TIMER_DIFFERENCE
4509 based on the next ordinary timer.
4510 TIMER_DIFFERENCE is the distance in time from NOW to when
4511 this timer becomes ripe (negative if it's already ripe). */
4514 timer
= XCAR (timers
);
4515 vector
= XVECTOR (timer
)->contents
;
4516 EMACS_SET_SECS (timer_time
,
4517 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
4518 EMACS_SET_USECS (timer_time
, XINT (vector
[3]));
4519 EMACS_SUB_TIME (timer_difference
, timer_time
, now
);
4522 /* Set IDLE_TIMER, IDLE_TIMER_TIME and IDLE_TIMER_DIFFERENCE
4523 based on the next idle timer. */
4524 if (!NILP (idle_timers
))
4526 idle_timer
= XCAR (idle_timers
);
4527 vector
= XVECTOR (idle_timer
)->contents
;
4528 EMACS_SET_SECS (idle_timer_time
,
4529 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
4530 EMACS_SET_USECS (idle_timer_time
, XINT (vector
[3]));
4531 EMACS_SUB_TIME (idle_timer_difference
, idle_timer_time
, idleness_now
);
4534 /* Decide which timer is the next timer,
4535 and set CHOSEN_TIMER, VECTOR and DIFFERENCE accordingly.
4536 Also step down the list where we found that timer. */
4538 if (! NILP (timers
) && ! NILP (idle_timers
))
4541 EMACS_SUB_TIME (temp
, timer_difference
, idle_timer_difference
);
4542 if (EMACS_TIME_NEG_P (temp
))
4544 chosen_timer
= timer
;
4545 timers
= XCDR (timers
);
4546 difference
= timer_difference
;
4550 chosen_timer
= idle_timer
;
4551 idle_timers
= XCDR (idle_timers
);
4552 difference
= idle_timer_difference
;
4555 else if (! NILP (timers
))
4557 chosen_timer
= timer
;
4558 timers
= XCDR (timers
);
4559 difference
= timer_difference
;
4563 chosen_timer
= idle_timer
;
4564 idle_timers
= XCDR (idle_timers
);
4565 difference
= idle_timer_difference
;
4567 vector
= XVECTOR (chosen_timer
)->contents
;
4569 /* If timer is ripe, run it if it hasn't been run. */
4570 if (EMACS_TIME_NEG_P (difference
)
4571 || (EMACS_SECS (difference
) == 0
4572 && EMACS_USECS (difference
) == 0))
4574 if (NILP (vector
[0]))
4576 int count
= SPECPDL_INDEX ();
4577 Lisp_Object old_deactivate_mark
= Vdeactivate_mark
;
4579 #if 0 /* This shouldn't be necessary anymore. --lorentey */
4580 /* On unbind_to, resume allowing input from any kboard, if that
4582 record_single_kboard_state ();
4584 /* Mark the timer as triggered to prevent problems if the lisp
4585 code fails to reschedule it right. */
4588 specbind (Qinhibit_quit
, Qt
);
4590 call1 (Qtimer_event_handler
, chosen_timer
);
4591 Vdeactivate_mark
= old_deactivate_mark
;
4593 unbind_to (count
, Qnil
);
4595 /* Since we have handled the event,
4596 we don't need to tell the caller to wake up and do it. */
4600 /* When we encounter a timer that is still waiting,
4601 return the amount of time to wait before it is ripe. */
4608 /* No timers are pending in the future. */
4609 /* Return 0 if we generated an event, and -1 if not. */
4614 /* Caches for modify_event_symbol. */
4615 static Lisp_Object accent_key_syms
;
4616 static Lisp_Object func_key_syms
;
4617 static Lisp_Object mouse_syms
;
4618 static Lisp_Object wheel_syms
;
4619 static Lisp_Object drag_n_drop_syms
;
4621 /* This is a list of keysym codes for special "accent" characters.
4622 It parallels lispy_accent_keys. */
4624 static int lispy_accent_codes
[] =
4626 #ifdef XK_dead_circumflex
4631 #ifdef XK_dead_grave
4636 #ifdef XK_dead_tilde
4641 #ifdef XK_dead_diaeresis
4646 #ifdef XK_dead_macron
4651 #ifdef XK_dead_degree
4656 #ifdef XK_dead_acute
4661 #ifdef XK_dead_cedilla
4666 #ifdef XK_dead_breve
4671 #ifdef XK_dead_ogonek
4676 #ifdef XK_dead_caron
4681 #ifdef XK_dead_doubleacute
4682 XK_dead_doubleacute
,
4686 #ifdef XK_dead_abovedot
4691 #ifdef XK_dead_abovering
4701 #ifdef XK_dead_belowdot
4706 #ifdef XK_dead_voiced_sound
4707 XK_dead_voiced_sound
,
4711 #ifdef XK_dead_semivoiced_sound
4712 XK_dead_semivoiced_sound
,
4728 /* This is a list of Lisp names for special "accent" characters.
4729 It parallels lispy_accent_codes. */
4731 static char *lispy_accent_keys
[] =
4749 "dead-voiced-sound",
4750 "dead-semivoiced-sound",
4756 #define FUNCTION_KEY_OFFSET 0x0
4758 char *lispy_function_keys
[] =
4762 0, /* VK_LBUTTON 0x01 */
4763 0, /* VK_RBUTTON 0x02 */
4764 "cancel", /* VK_CANCEL 0x03 */
4765 0, /* VK_MBUTTON 0x04 */
4767 0, 0, 0, /* 0x05 .. 0x07 */
4769 "backspace", /* VK_BACK 0x08 */
4770 "tab", /* VK_TAB 0x09 */
4772 0, 0, /* 0x0A .. 0x0B */
4774 "clear", /* VK_CLEAR 0x0C */
4775 "return", /* VK_RETURN 0x0D */
4777 0, 0, /* 0x0E .. 0x0F */
4779 0, /* VK_SHIFT 0x10 */
4780 0, /* VK_CONTROL 0x11 */
4781 0, /* VK_MENU 0x12 */
4782 "pause", /* VK_PAUSE 0x13 */
4783 "capslock", /* VK_CAPITAL 0x14 */
4785 0, 0, 0, 0, 0, 0, /* 0x15 .. 0x1A */
4787 "escape", /* VK_ESCAPE 0x1B */
4789 0, 0, 0, 0, /* 0x1C .. 0x1F */
4791 0, /* VK_SPACE 0x20 */
4792 "prior", /* VK_PRIOR 0x21 */
4793 "next", /* VK_NEXT 0x22 */
4794 "end", /* VK_END 0x23 */
4795 "home", /* VK_HOME 0x24 */
4796 "left", /* VK_LEFT 0x25 */
4797 "up", /* VK_UP 0x26 */
4798 "right", /* VK_RIGHT 0x27 */
4799 "down", /* VK_DOWN 0x28 */
4800 "select", /* VK_SELECT 0x29 */
4801 "print", /* VK_PRINT 0x2A */
4802 "execute", /* VK_EXECUTE 0x2B */
4803 "snapshot", /* VK_SNAPSHOT 0x2C */
4804 "insert", /* VK_INSERT 0x2D */
4805 "delete", /* VK_DELETE 0x2E */
4806 "help", /* VK_HELP 0x2F */
4808 /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
4810 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4812 0, 0, 0, 0, 0, 0, 0, /* 0x3A .. 0x40 */
4814 /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
4816 0, 0, 0, 0, 0, 0, 0, 0, 0,
4817 0, 0, 0, 0, 0, 0, 0, 0, 0,
4818 0, 0, 0, 0, 0, 0, 0, 0,
4820 "lwindow", /* VK_LWIN 0x5B */
4821 "rwindow", /* VK_RWIN 0x5C */
4822 "apps", /* VK_APPS 0x5D */
4824 0, 0, /* 0x5E .. 0x5F */
4826 "kp-0", /* VK_NUMPAD0 0x60 */
4827 "kp-1", /* VK_NUMPAD1 0x61 */
4828 "kp-2", /* VK_NUMPAD2 0x62 */
4829 "kp-3", /* VK_NUMPAD3 0x63 */
4830 "kp-4", /* VK_NUMPAD4 0x64 */
4831 "kp-5", /* VK_NUMPAD5 0x65 */
4832 "kp-6", /* VK_NUMPAD6 0x66 */
4833 "kp-7", /* VK_NUMPAD7 0x67 */
4834 "kp-8", /* VK_NUMPAD8 0x68 */
4835 "kp-9", /* VK_NUMPAD9 0x69 */
4836 "kp-multiply", /* VK_MULTIPLY 0x6A */
4837 "kp-add", /* VK_ADD 0x6B */
4838 "kp-separator", /* VK_SEPARATOR 0x6C */
4839 "kp-subtract", /* VK_SUBTRACT 0x6D */
4840 "kp-decimal", /* VK_DECIMAL 0x6E */
4841 "kp-divide", /* VK_DIVIDE 0x6F */
4842 "f1", /* VK_F1 0x70 */
4843 "f2", /* VK_F2 0x71 */
4844 "f3", /* VK_F3 0x72 */
4845 "f4", /* VK_F4 0x73 */
4846 "f5", /* VK_F5 0x74 */
4847 "f6", /* VK_F6 0x75 */
4848 "f7", /* VK_F7 0x76 */
4849 "f8", /* VK_F8 0x77 */
4850 "f9", /* VK_F9 0x78 */
4851 "f10", /* VK_F10 0x79 */
4852 "f11", /* VK_F11 0x7A */
4853 "f12", /* VK_F12 0x7B */
4854 "f13", /* VK_F13 0x7C */
4855 "f14", /* VK_F14 0x7D */
4856 "f15", /* VK_F15 0x7E */
4857 "f16", /* VK_F16 0x7F */
4858 "f17", /* VK_F17 0x80 */
4859 "f18", /* VK_F18 0x81 */
4860 "f19", /* VK_F19 0x82 */
4861 "f20", /* VK_F20 0x83 */
4862 "f21", /* VK_F21 0x84 */
4863 "f22", /* VK_F22 0x85 */
4864 "f23", /* VK_F23 0x86 */
4865 "f24", /* VK_F24 0x87 */
4867 0, 0, 0, 0, /* 0x88 .. 0x8B */
4868 0, 0, 0, 0, /* 0x8C .. 0x8F */
4870 "kp-numlock", /* VK_NUMLOCK 0x90 */
4871 "scroll", /* VK_SCROLL 0x91 */
4873 "kp-space", /* VK_NUMPAD_CLEAR 0x92 */
4874 "kp-enter", /* VK_NUMPAD_ENTER 0x93 */
4875 "kp-prior", /* VK_NUMPAD_PRIOR 0x94 */
4876 "kp-next", /* VK_NUMPAD_NEXT 0x95 */
4877 "kp-end", /* VK_NUMPAD_END 0x96 */
4878 "kp-home", /* VK_NUMPAD_HOME 0x97 */
4879 "kp-left", /* VK_NUMPAD_LEFT 0x98 */
4880 "kp-up", /* VK_NUMPAD_UP 0x99 */
4881 "kp-right", /* VK_NUMPAD_RIGHT 0x9A */
4882 "kp-down", /* VK_NUMPAD_DOWN 0x9B */
4883 "kp-insert", /* VK_NUMPAD_INSERT 0x9C */
4884 "kp-delete", /* VK_NUMPAD_DELETE 0x9D */
4886 0, 0, /* 0x9E .. 0x9F */
4889 * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
4890 * Used only as parameters to GetAsyncKeyState and GetKeyState.
4891 * No other API or message will distinguish left and right keys this way.
4895 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4896 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4897 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4898 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4899 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4905 "attn", /* VK_ATTN 0xF6 */
4906 "crsel", /* VK_CRSEL 0xF7 */
4907 "exsel", /* VK_EXSEL 0xF8 */
4908 "ereof", /* VK_EREOF 0xF9 */
4909 "play", /* VK_PLAY 0xFA */
4910 "zoom", /* VK_ZOOM 0xFB */
4911 "noname", /* VK_NONAME 0xFC */
4912 "pa1", /* VK_PA1 0xFD */
4913 "oem_clear", /* VK_OEM_CLEAR 0xFE */
4917 #else /* not HAVE_NTGUI */
4919 /* This should be dealt with in XTread_socket now, and that doesn't
4920 depend on the client system having the Kana syms defined. See also
4921 the XK_kana_A case below. */
4924 static char *lispy_kana_keys
[] =
4926 /* X Keysym value */
4927 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x400 .. 0x40f */
4928 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x410 .. 0x41f */
4929 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x420 .. 0x42f */
4930 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x430 .. 0x43f */
4931 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x440 .. 0x44f */
4932 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x450 .. 0x45f */
4933 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x460 .. 0x46f */
4934 0,0,0,0,0,0,0,0,0,0,0,0,0,0,"overline",0,
4935 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x480 .. 0x48f */
4936 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x490 .. 0x49f */
4937 0, "kana-fullstop", "kana-openingbracket", "kana-closingbracket",
4938 "kana-comma", "kana-conjunctive", "kana-WO", "kana-a",
4939 "kana-i", "kana-u", "kana-e", "kana-o",
4940 "kana-ya", "kana-yu", "kana-yo", "kana-tsu",
4941 "prolongedsound", "kana-A", "kana-I", "kana-U",
4942 "kana-E", "kana-O", "kana-KA", "kana-KI",
4943 "kana-KU", "kana-KE", "kana-KO", "kana-SA",
4944 "kana-SHI", "kana-SU", "kana-SE", "kana-SO",
4945 "kana-TA", "kana-CHI", "kana-TSU", "kana-TE",
4946 "kana-TO", "kana-NA", "kana-NI", "kana-NU",
4947 "kana-NE", "kana-NO", "kana-HA", "kana-HI",
4948 "kana-FU", "kana-HE", "kana-HO", "kana-MA",
4949 "kana-MI", "kana-MU", "kana-ME", "kana-MO",
4950 "kana-YA", "kana-YU", "kana-YO", "kana-RA",
4951 "kana-RI", "kana-RU", "kana-RE", "kana-RO",
4952 "kana-WA", "kana-N", "voicedsound", "semivoicedsound",
4953 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4e0 .. 0x4ef */
4954 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4f0 .. 0x4ff */
4956 #endif /* XK_kana_A */
4959 #define FUNCTION_KEY_OFFSET 0xff00
4961 /* You'll notice that this table is arranged to be conveniently
4962 indexed by X Windows keysym values. */
4963 static char *lispy_function_keys
[] =
4965 /* X Keysym value */
4967 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00...0f */
4968 "backspace", "tab", "linefeed", "clear",
4970 0, 0, 0, "pause", /* 0xff10...1f */
4971 0, 0, 0, 0, 0, 0, 0, "escape",
4973 0, "kanji", "muhenkan", "henkan", /* 0xff20...2f */
4974 "romaji", "hiragana", "katakana", "hiragana-katakana",
4975 "zenkaku", "hankaku", "zenkaku-hankaku", "touroku",
4976 "massyo", "kana-lock", "kana-shift", "eisu-shift",
4977 "eisu-toggle", /* 0xff30...3f */
4978 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4979 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
4981 "home", "left", "up", "right", /* 0xff50 */ /* IsCursorKey */
4982 "down", "prior", "next", "end",
4983 "begin", 0, 0, 0, 0, 0, 0, 0,
4984 "select", /* 0xff60 */ /* IsMiscFunctionKey */
4995 "break", /* 0xff6b */
4998 0, 0, 0, 0, "backtab", 0, 0, 0, /* 0xff70... */
4999 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff78... */
5000 "kp-space", /* 0xff80 */ /* IsKeypadKey */
5001 0, 0, 0, 0, 0, 0, 0, 0,
5002 "kp-tab", /* 0xff89 */
5004 "kp-enter", /* 0xff8d */
5006 "kp-f1", /* 0xff91 */
5010 "kp-home", /* 0xff95 */
5015 "kp-prior", /* kp-page-up */
5016 "kp-next", /* kp-page-down */
5022 0, 0, 0, 0, 0, 0, 0, 0, 0,
5023 "kp-multiply", /* 0xffaa */
5028 "kp-divide", /* 0xffaf */
5029 "kp-0", /* 0xffb0 */
5030 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
5033 "kp-equal", /* 0xffbd */
5034 "f1", /* 0xffbe */ /* IsFunctionKey */
5036 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
5037 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
5038 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
5039 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
5040 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
5041 0, 0, 0, 0, 0, 0, 0, 0,
5042 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
5043 0, 0, 0, 0, 0, 0, 0, "delete"
5046 /* ISO 9995 Function and Modifier Keys; the first byte is 0xFE. */
5047 #define ISO_FUNCTION_KEY_OFFSET 0xfe00
5049 static char *iso_lispy_function_keys
[] =
5051 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe00 */
5052 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe08 */
5053 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe10 */
5054 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe18 */
5055 "iso-lefttab", /* 0xfe20 */
5056 "iso-move-line-up", "iso-move-line-down",
5057 "iso-partial-line-up", "iso-partial-line-down",
5058 "iso-partial-space-left", "iso-partial-space-right",
5059 "iso-set-margin-left", "iso-set-margin-right", /* 0xffe27, 28 */
5060 "iso-release-margin-left", "iso-release-margin-right",
5061 "iso-release-both-margins",
5062 "iso-fast-cursor-left", "iso-fast-cursor-right",
5063 "iso-fast-cursor-up", "iso-fast-cursor-down",
5064 "iso-continuous-underline", "iso-discontinuous-underline", /* 0xfe30, 31 */
5065 "iso-emphasize", "iso-center-object", "iso-enter", /* ... 0xfe34 */
5068 #endif /* not HAVE_NTGUI */
5070 Lisp_Object Vlispy_mouse_stem
;
5072 static char *lispy_wheel_names
[] =
5074 "wheel-up", "wheel-down"
5077 /* drag-n-drop events are generated when a set of selected files are
5078 dragged from another application and dropped onto an Emacs window. */
5079 static char *lispy_drag_n_drop_names
[] =
5084 /* Scroll bar parts. */
5085 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
5086 Lisp_Object Qup
, Qdown
, Qbottom
, Qend_scroll
;
5087 Lisp_Object Qtop
, Qratio
;
5089 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
5090 Lisp_Object
*scroll_bar_parts
[] = {
5091 &Qabove_handle
, &Qhandle
, &Qbelow_handle
,
5092 &Qup
, &Qdown
, &Qtop
, &Qbottom
, &Qend_scroll
, &Qratio
5095 /* User signal events. */
5096 Lisp_Object Qusr1_signal
, Qusr2_signal
;
5098 Lisp_Object
*lispy_user_signals
[] =
5100 &Qusr1_signal
, &Qusr2_signal
5104 /* A vector, indexed by button number, giving the down-going location
5105 of currently depressed buttons, both scroll bar and non-scroll bar.
5107 The elements have the form
5108 (BUTTON-NUMBER MODIFIER-MASK . REST)
5109 where REST is the cdr of a position as it would be reported in the event.
5111 The make_lispy_event function stores positions here to tell the
5112 difference between click and drag events, and to store the starting
5113 location to be included in drag events. */
5115 static Lisp_Object button_down_location
;
5117 /* Information about the most recent up-going button event: Which
5118 button, what location, and what time. */
5120 static int last_mouse_button
;
5121 static int last_mouse_x
;
5122 static int last_mouse_y
;
5123 static unsigned long button_down_time
;
5125 /* The maximum time between clicks to make a double-click, or Qnil to
5126 disable double-click detection, or Qt for no time limit. */
5128 Lisp_Object Vdouble_click_time
;
5130 /* Maximum number of pixels the mouse may be moved between clicks
5131 to make a double-click. */
5133 EMACS_INT double_click_fuzz
;
5135 /* The number of clicks in this multiple-click. */
5137 int double_click_count
;
5139 /* Return position of a mouse click or wheel event */
5142 make_lispy_position (f
, x
, y
, time
)
5148 enum window_part part
;
5149 Lisp_Object posn
= Qnil
;
5150 Lisp_Object extra_info
= Qnil
;
5153 /* Set `window' to the window under frame pixel coordinates (x,y) */
5155 window
= window_from_coordinates (f
, XINT (*x
), XINT (*y
),
5156 &part
, &wx
, &wy
, 0);
5160 if (WINDOWP (window
))
5162 /* It's a click in window window at frame coordinates (x,y) */
5163 struct window
*w
= XWINDOW (window
);
5164 Lisp_Object string_info
= Qnil
;
5165 int textpos
= -1, rx
= -1, ry
= -1;
5166 int dx
= -1, dy
= -1;
5167 int width
= -1, height
= -1;
5168 Lisp_Object object
= Qnil
;
5170 /* Set event coordinates to window-relative coordinates
5171 for constructing the Lisp event below. */
5175 if (part
== ON_TEXT
)
5177 wx
+= WINDOW_LEFT_MARGIN_WIDTH (w
);
5179 else if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
)
5181 /* Mode line or header line. Look for a string under
5182 the mouse that may have a `local-map' property. */
5186 posn
= part
== ON_MODE_LINE
? Qmode_line
: Qheader_line
;
5188 string
= mode_line_string (w
, part
, &rx
, &ry
, &charpos
,
5189 &object
, &dx
, &dy
, &width
, &height
);
5190 if (STRINGP (string
))
5191 string_info
= Fcons (string
, make_number (charpos
));
5192 if (w
== XWINDOW (selected_window
))
5195 textpos
= XMARKER (w
->pointm
)->charpos
;
5197 else if (part
== ON_VERTICAL_BORDER
)
5199 posn
= Qvertical_line
;
5204 else if (part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
5209 posn
= (part
== ON_LEFT_MARGIN
) ? Qleft_margin
: Qright_margin
;
5211 string
= marginal_area_string (w
, part
, &rx
, &ry
, &charpos
,
5212 &object
, &dx
, &dy
, &width
, &height
);
5213 if (STRINGP (string
))
5214 string_info
= Fcons (string
, make_number (charpos
));
5215 if (part
== ON_LEFT_MARGIN
)
5218 wx
= window_box_right_offset (w
, TEXT_AREA
) - 1;
5220 else if (part
== ON_LEFT_FRINGE
)
5222 posn
= Qleft_fringe
;
5225 wx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5227 : window_box_width (w
, LEFT_MARGIN_AREA
));
5230 else if (part
== ON_RIGHT_FRINGE
)
5232 posn
= Qright_fringe
;
5235 wx
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5236 + window_box_width (w
, TEXT_AREA
)
5237 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5238 ? window_box_width (w
, RIGHT_MARGIN_AREA
)
5244 /* Note: We have no special posn for part == ON_SCROLL_BAR. */
5245 wx
= max (WINDOW_LEFT_MARGIN_WIDTH (w
), wx
);
5250 Lisp_Object string2
, object2
= Qnil
;
5251 struct display_pos p
;
5253 int width2
, height2
;
5254 string2
= buffer_posn_from_coords (w
, &wx
, &wy
, &p
,
5255 &object2
, &dx2
, &dy2
,
5257 textpos
= CHARPOS (p
.pos
);
5258 if (rx
< 0) rx
= wx
;
5259 if (ry
< 0) ry
= wy
;
5260 if (dx
< 0) dx
= dx2
;
5261 if (dy
< 0) dy
= dy2
;
5262 if (width
< 0) width
= width2
;
5263 if (height
< 0) height
= height2
;
5267 posn
= make_number (textpos
);
5268 if (STRINGP (string2
))
5269 string_info
= Fcons (string2
,
5270 make_number (CHARPOS (p
.string_pos
)));
5276 #ifdef HAVE_WINDOW_SYSTEM
5277 if (IMAGEP (object
))
5279 Lisp_Object image_map
, hotspot
;
5280 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
5282 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
5284 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
5285 posn
= XCAR (hotspot
);
5290 extra_info
= Fcons (object
,
5291 Fcons (Fcons (make_number (dx
),
5293 Fcons (Fcons (make_number (width
),
5294 make_number (height
)),
5298 extra_info
= Fcons (string_info
,
5299 Fcons (make_number (textpos
),
5300 Fcons (Fcons (make_number (rx
),
5306 XSETFRAME (window
, f
);
5311 XSETFASTINT (*x
, 0);
5312 XSETFASTINT (*y
, 0);
5315 return Fcons (window
,
5317 Fcons (Fcons (*x
, *y
),
5318 Fcons (make_number (time
),
5322 /* Given a struct input_event, build the lisp event which represents
5323 it. If EVENT is 0, build a mouse movement event from the mouse
5324 movement buffer, which should have a movement event in it.
5326 Note that events must be passed to this function in the order they
5327 are received; this function stores the location of button presses
5328 in order to build drag events when the button is released. */
5331 make_lispy_event (event
)
5332 struct input_event
*event
;
5336 switch (SWITCH_ENUM_CAST (event
->kind
))
5338 /* A simple keystroke. */
5339 case ASCII_KEYSTROKE_EVENT
:
5341 Lisp_Object lispy_c
;
5342 int c
= event
->code
& 0377;
5343 /* Turn ASCII characters into control characters
5345 if (event
->modifiers
& ctrl_modifier
)
5346 c
= make_ctrl_char (c
);
5348 /* Add in the other modifier bits. We took care of ctrl_modifier
5349 just above, and the shift key was taken care of by the X code,
5350 and applied to control characters by make_ctrl_char. */
5351 c
|= (event
->modifiers
5352 & (meta_modifier
| alt_modifier
5353 | hyper_modifier
| super_modifier
));
5354 /* Distinguish Shift-SPC from SPC. */
5355 if ((event
->code
& 0377) == 040
5356 && event
->modifiers
& shift_modifier
)
5357 c
|= shift_modifier
;
5358 button_down_time
= 0;
5359 XSETFASTINT (lispy_c
, c
);
5363 case MULTIBYTE_CHAR_KEYSTROKE_EVENT
:
5365 Lisp_Object lispy_c
;
5366 int c
= event
->code
;
5368 /* Add in the other modifier bits. We took care of ctrl_modifier
5369 just above, and the shift key was taken care of by the X code,
5370 and applied to control characters by make_ctrl_char. */
5371 c
|= (event
->modifiers
5372 & (meta_modifier
| alt_modifier
5373 | hyper_modifier
| super_modifier
| ctrl_modifier
));
5374 /* What about the `shift' modifier ? */
5375 button_down_time
= 0;
5376 XSETFASTINT (lispy_c
, c
);
5380 /* A function key. The symbol may need to have modifier prefixes
5382 case NON_ASCII_KEYSTROKE_EVENT
:
5383 button_down_time
= 0;
5385 for (i
= 0; i
< sizeof (lispy_accent_codes
) / sizeof (int); i
++)
5386 if (event
->code
== lispy_accent_codes
[i
])
5387 return modify_event_symbol (i
,
5389 Qfunction_key
, Qnil
,
5390 lispy_accent_keys
, &accent_key_syms
,
5391 (sizeof (lispy_accent_keys
)
5392 / sizeof (lispy_accent_keys
[0])));
5396 if (event
->code
>= 0x400 && event
->code
< 0x500)
5397 return modify_event_symbol (event
->code
- 0x400,
5398 event
->modifiers
& ~shift_modifier
,
5399 Qfunction_key
, Qnil
,
5400 lispy_kana_keys
, &func_key_syms
,
5401 (sizeof (lispy_kana_keys
)
5402 / sizeof (lispy_kana_keys
[0])));
5403 #endif /* XK_kana_A */
5406 #ifdef ISO_FUNCTION_KEY_OFFSET
5407 if (event
->code
< FUNCTION_KEY_OFFSET
5408 && event
->code
>= ISO_FUNCTION_KEY_OFFSET
)
5409 return modify_event_symbol (event
->code
- ISO_FUNCTION_KEY_OFFSET
,
5411 Qfunction_key
, Qnil
,
5412 iso_lispy_function_keys
, &func_key_syms
,
5413 (sizeof (iso_lispy_function_keys
)
5414 / sizeof (iso_lispy_function_keys
[0])));
5417 /* Handle system-specific or unknown keysyms. */
5418 if (event
->code
& (1 << 28)
5419 || event
->code
- FUNCTION_KEY_OFFSET
< 0
5420 || (event
->code
- FUNCTION_KEY_OFFSET
5421 >= sizeof lispy_function_keys
/ sizeof *lispy_function_keys
)
5422 || !lispy_function_keys
[event
->code
- FUNCTION_KEY_OFFSET
])
5424 /* We need to use an alist rather than a vector as the cache
5425 since we can't make a vector long enuf. */
5426 if (NILP (current_kboard
->system_key_syms
))
5427 current_kboard
->system_key_syms
= Fcons (Qnil
, Qnil
);
5428 return modify_event_symbol (event
->code
,
5431 current_kboard
->Vsystem_key_alist
,
5432 0, ¤t_kboard
->system_key_syms
,
5436 return modify_event_symbol (event
->code
- FUNCTION_KEY_OFFSET
,
5438 Qfunction_key
, Qnil
,
5439 lispy_function_keys
, &func_key_syms
,
5440 (sizeof (lispy_function_keys
)
5441 / sizeof (lispy_function_keys
[0])));
5444 /* A mouse click. Figure out where it is, decide whether it's
5445 a press, click or drag, and build the appropriate structure. */
5446 case MOUSE_CLICK_EVENT
:
5447 #ifndef USE_TOOLKIT_SCROLL_BARS
5448 case SCROLL_BAR_CLICK_EVENT
:
5451 int button
= event
->code
;
5453 Lisp_Object position
;
5454 Lisp_Object
*start_pos_ptr
;
5455 Lisp_Object start_pos
;
5459 /* Build the position as appropriate for this mouse click. */
5460 if (event
->kind
== MOUSE_CLICK_EVENT
)
5462 struct frame
*f
= XFRAME (event
->frame_or_window
);
5463 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
5467 /* Ignore mouse events that were made on frame that
5468 have been deleted. */
5469 if (! FRAME_LIVE_P (f
))
5472 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
5473 /* EVENT->x and EVENT->y are frame-relative pixel
5474 coordinates at this place. Under old redisplay, COLUMN
5475 and ROW are set to frame relative glyph coordinates
5476 which are then used to determine whether this click is
5477 in a menu (non-toolkit version). */
5478 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
5479 &column
, &row
, NULL
, 1);
5481 /* In the non-toolkit version, clicks on the menu bar
5482 are ordinary button events in the event buffer.
5483 Distinguish them, and invoke the menu.
5485 (In the toolkit version, the toolkit handles the menu bar
5486 and Emacs doesn't know about it until after the user
5487 makes a selection.) */
5488 if (row
>= 0 && row
< FRAME_MENU_BAR_LINES (f
)
5489 && (event
->modifiers
& down_modifier
))
5491 Lisp_Object items
, item
;
5496 /* Activate the menu bar on the down event. If the
5497 up event comes in before the menu code can deal with it,
5499 if (! (event
->modifiers
& down_modifier
))
5503 /* Find the menu bar item under `column'. */
5505 items
= FRAME_MENU_BAR_ITEMS (f
);
5506 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
5508 Lisp_Object pos
, string
;
5509 string
= AREF (items
, i
+ 1);
5510 pos
= AREF (items
, i
+ 3);
5513 if (column
>= XINT (pos
)
5514 && column
< XINT (pos
) + SCHARS (string
))
5516 item
= AREF (items
, i
);
5521 /* ELisp manual 2.4b says (x y) are window relative but
5522 code says they are frame-relative. */
5524 = Fcons (event
->frame_or_window
,
5526 Fcons (Fcons (event
->x
, event
->y
),
5527 Fcons (make_number (event
->timestamp
),
5530 return Fcons (item
, Fcons (position
, Qnil
));
5532 #endif /* not USE_X_TOOLKIT && not USE_GTK */
5534 position
= make_lispy_position (f
, &event
->x
, &event
->y
,
5537 #ifndef USE_TOOLKIT_SCROLL_BARS
5540 /* It's a scrollbar click. */
5542 Lisp_Object portion_whole
;
5545 window
= event
->frame_or_window
;
5546 portion_whole
= Fcons (event
->x
, event
->y
);
5547 part
= *scroll_bar_parts
[(int) event
->part
];
5551 Fcons (Qvertical_scroll_bar
,
5552 Fcons (portion_whole
,
5553 Fcons (make_number (event
->timestamp
),
5554 Fcons (part
, Qnil
)))));
5556 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5558 if (button
>= ASIZE (button_down_location
))
5560 button_down_location
= larger_vector (button_down_location
,
5562 mouse_syms
= larger_vector (mouse_syms
, button
+ 1, Qnil
);
5565 start_pos_ptr
= &AREF (button_down_location
, button
);
5566 start_pos
= *start_pos_ptr
;
5567 *start_pos_ptr
= Qnil
;
5570 /* On window-system frames, use the value of
5571 double-click-fuzz as is. On other frames, interpret it
5572 as a multiple of 1/8 characters. */
5576 if (WINDOWP (event
->frame_or_window
))
5577 f
= XFRAME (XWINDOW (event
->frame_or_window
)->frame
);
5578 else if (FRAMEP (event
->frame_or_window
))
5579 f
= XFRAME (event
->frame_or_window
);
5583 if (FRAME_WINDOW_P (f
))
5584 fuzz
= double_click_fuzz
;
5586 fuzz
= double_click_fuzz
/ 8;
5588 is_double
= (button
== last_mouse_button
5589 && (abs (XINT (event
->x
) - last_mouse_x
) <= fuzz
)
5590 && (abs (XINT (event
->y
) - last_mouse_y
) <= fuzz
)
5591 && button_down_time
!= 0
5592 && (EQ (Vdouble_click_time
, Qt
)
5593 || (INTEGERP (Vdouble_click_time
)
5594 && ((int)(event
->timestamp
- button_down_time
)
5595 < XINT (Vdouble_click_time
)))));
5598 last_mouse_button
= button
;
5599 last_mouse_x
= XINT (event
->x
);
5600 last_mouse_y
= XINT (event
->y
);
5602 /* If this is a button press, squirrel away the location, so
5603 we can decide later whether it was a click or a drag. */
5604 if (event
->modifiers
& down_modifier
)
5608 double_click_count
++;
5609 event
->modifiers
|= ((double_click_count
> 2)
5614 double_click_count
= 1;
5615 button_down_time
= event
->timestamp
;
5616 *start_pos_ptr
= Fcopy_alist (position
);
5619 /* Now we're releasing a button - check the co-ordinates to
5620 see if this was a click or a drag. */
5621 else if (event
->modifiers
& up_modifier
)
5623 /* If we did not see a down before this up, ignore the up.
5624 Probably this happened because the down event chose a
5625 menu item. It would be an annoyance to treat the
5626 release of the button that chose the menu item as a
5629 if (!CONSP (start_pos
))
5632 event
->modifiers
&= ~up_modifier
;
5633 #if 0 /* Formerly we treated an up with no down as a click event. */
5634 if (!CONSP (start_pos
))
5635 event
->modifiers
|= click_modifier
;
5640 EMACS_INT xdiff
= double_click_fuzz
, ydiff
= double_click_fuzz
;
5642 /* The third element of every position
5643 should be the (x,y) pair. */
5644 down
= Fcar (Fcdr (Fcdr (start_pos
)));
5646 && INTEGERP (XCAR (down
)) && INTEGERP (XCDR (down
)))
5648 xdiff
= XINT (event
->x
) - XINT (XCAR (down
));
5649 ydiff
= XINT (event
->y
) - XINT (XCDR (down
));
5652 if (xdiff
< double_click_fuzz
&& xdiff
> - double_click_fuzz
5653 && ydiff
< double_click_fuzz
&& ydiff
> - double_click_fuzz
5654 /* Maybe the mouse has moved a lot, caused scrolling, and
5655 eventually ended up at the same screen position (but
5656 not buffer position) in which case it is a drag, not
5658 /* FIXME: OTOH if the buffer position has changed
5659 because of a timer or process filter rather than
5660 because of mouse movement, it should be considered as
5661 a click. But mouse-drag-region completely ignores
5662 this case and it hasn't caused any real problem, so
5663 it's probably OK to ignore it as well. */
5664 && EQ (Fcar (Fcdr (start_pos
)), Fcar (Fcdr (position
))))
5665 /* Mouse hasn't moved (much). */
5666 event
->modifiers
|= click_modifier
;
5669 button_down_time
= 0;
5670 event
->modifiers
|= drag_modifier
;
5673 /* Don't check is_double; treat this as multiple
5674 if the down-event was multiple. */
5675 if (double_click_count
> 1)
5676 event
->modifiers
|= ((double_click_count
> 2)
5682 /* Every mouse event should either have the down_modifier or
5683 the up_modifier set. */
5687 /* Get the symbol we should use for the mouse click. */
5690 head
= modify_event_symbol (button
,
5692 Qmouse_click
, Vlispy_mouse_stem
,
5695 XVECTOR (mouse_syms
)->size
);
5696 if (event
->modifiers
& drag_modifier
)
5701 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
5704 Fcons (make_number (double_click_count
),
5715 Lisp_Object position
;
5718 /* Build the position as appropriate for this mouse click. */
5719 struct frame
*f
= XFRAME (event
->frame_or_window
);
5721 /* Ignore wheel events that were made on frame that have been
5723 if (! FRAME_LIVE_P (f
))
5726 position
= make_lispy_position (f
, &event
->x
, &event
->y
,
5729 /* Set double or triple modifiers to indicate the wheel speed. */
5731 /* On window-system frames, use the value of
5732 double-click-fuzz as is. On other frames, interpret it
5733 as a multiple of 1/8 characters. */
5738 if (WINDOWP (event
->frame_or_window
))
5739 f
= XFRAME (XWINDOW (event
->frame_or_window
)->frame
);
5740 else if (FRAMEP (event
->frame_or_window
))
5741 f
= XFRAME (event
->frame_or_window
);
5745 if (FRAME_WINDOW_P (f
))
5746 fuzz
= double_click_fuzz
;
5748 fuzz
= double_click_fuzz
/ 8;
5750 is_double
= (last_mouse_button
< 0
5751 && (abs (XINT (event
->x
) - last_mouse_x
) <= fuzz
)
5752 && (abs (XINT (event
->y
) - last_mouse_y
) <= fuzz
)
5753 && button_down_time
!= 0
5754 && (EQ (Vdouble_click_time
, Qt
)
5755 || (INTEGERP (Vdouble_click_time
)
5756 && ((int)(event
->timestamp
- button_down_time
)
5757 < XINT (Vdouble_click_time
)))));
5760 double_click_count
++;
5761 event
->modifiers
|= ((double_click_count
> 2)
5767 double_click_count
= 1;
5768 event
->modifiers
|= click_modifier
;
5771 button_down_time
= event
->timestamp
;
5772 /* Use a negative value to distinguish wheel from mouse button. */
5773 last_mouse_button
= -1;
5774 last_mouse_x
= XINT (event
->x
);
5775 last_mouse_y
= XINT (event
->y
);
5781 if (event
->modifiers
& up_modifier
)
5783 /* Emit a wheel-up event. */
5784 event
->modifiers
&= ~up_modifier
;
5787 else if (event
->modifiers
& down_modifier
)
5789 /* Emit a wheel-down event. */
5790 event
->modifiers
&= ~down_modifier
;
5794 /* Every wheel event should either have the down_modifier or
5795 the up_modifier set. */
5798 /* Get the symbol we should use for the wheel event. */
5799 head
= modify_event_symbol (symbol_num
,
5805 ASIZE (wheel_syms
));
5808 if (event
->modifiers
& (double_modifier
| triple_modifier
))
5811 Fcons (make_number (double_click_count
),
5820 #ifdef USE_TOOLKIT_SCROLL_BARS
5822 /* We don't have down and up events if using toolkit scroll bars,
5823 so make this always a click event. Store in the `part' of
5824 the Lisp event a symbol which maps to the following actions:
5826 `above_handle' page up
5827 `below_handle' page down
5831 `bottom' bottom of buffer
5832 `handle' thumb has been dragged.
5833 `end-scroll' end of interaction with scroll bar
5835 The incoming input_event contains in its `part' member an
5836 index of type `enum scroll_bar_part' which we can use as an
5837 index in scroll_bar_parts to get the appropriate symbol. */
5839 case SCROLL_BAR_CLICK_EVENT
:
5841 Lisp_Object position
, head
, window
, portion_whole
, part
;
5843 window
= event
->frame_or_window
;
5844 portion_whole
= Fcons (event
->x
, event
->y
);
5845 part
= *scroll_bar_parts
[(int) event
->part
];
5849 Fcons (Qvertical_scroll_bar
,
5850 Fcons (portion_whole
,
5851 Fcons (make_number (event
->timestamp
),
5852 Fcons (part
, Qnil
)))));
5854 /* Always treat scroll bar events as clicks. */
5855 event
->modifiers
|= click_modifier
;
5856 event
->modifiers
&= ~up_modifier
;
5858 if (event
->code
>= ASIZE (mouse_syms
))
5859 mouse_syms
= larger_vector (mouse_syms
, event
->code
+ 1, Qnil
);
5861 /* Get the symbol we should use for the mouse click. */
5862 head
= modify_event_symbol (event
->code
,
5867 XVECTOR (mouse_syms
)->size
);
5868 return Fcons (head
, Fcons (position
, Qnil
));
5871 #endif /* USE_TOOLKIT_SCROLL_BARS */
5874 case W32_SCROLL_BAR_CLICK_EVENT
:
5876 int button
= event
->code
;
5878 Lisp_Object position
;
5879 Lisp_Object
*start_pos_ptr
;
5880 Lisp_Object start_pos
;
5884 Lisp_Object portion_whole
;
5887 window
= event
->frame_or_window
;
5888 portion_whole
= Fcons (event
->x
, event
->y
);
5889 part
= *scroll_bar_parts
[(int) event
->part
];
5893 Fcons (Qvertical_scroll_bar
,
5894 Fcons (portion_whole
,
5895 Fcons (make_number (event
->timestamp
),
5896 Fcons (part
, Qnil
)))));
5899 /* Always treat W32 scroll bar events as clicks. */
5900 event
->modifiers
|= click_modifier
;
5903 /* Get the symbol we should use for the mouse click. */
5906 head
= modify_event_symbol (button
,
5911 XVECTOR (mouse_syms
)->size
);
5917 #endif /* WINDOWSNT */
5919 case DRAG_N_DROP_EVENT
:
5922 Lisp_Object head
, position
;
5925 f
= XFRAME (event
->frame_or_window
);
5928 /* Ignore mouse events that were made on frames that
5929 have been deleted. */
5930 if (! FRAME_LIVE_P (f
))
5933 position
= make_lispy_position (f
, &event
->x
, &event
->y
,
5936 head
= modify_event_symbol (0, event
->modifiers
,
5938 lispy_drag_n_drop_names
,
5939 &drag_n_drop_syms
, 1);
5945 #endif /* HAVE_MOUSE */
5947 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
5948 || defined (USE_GTK)
5949 case MENU_BAR_EVENT
:
5950 if (EQ (event
->arg
, event
->frame_or_window
))
5951 /* This is the prefix key. We translate this to
5952 `(menu_bar)' because the code in keyboard.c for menu
5953 events, which we use, relies on this. */
5954 return Fcons (Qmenu_bar
, Qnil
);
5958 case SELECT_WINDOW_EVENT
:
5959 /* Make an event (select-window (WINDOW)). */
5960 return Fcons (Qselect_window
,
5961 Fcons (Fcons (event
->frame_or_window
, Qnil
),
5964 case TOOL_BAR_EVENT
:
5965 if (EQ (event
->arg
, event
->frame_or_window
))
5966 /* This is the prefix key. We translate this to
5967 `(tool_bar)' because the code in keyboard.c for tool bar
5968 events, which we use, relies on this. */
5969 return Fcons (Qtool_bar
, Qnil
);
5970 else if (SYMBOLP (event
->arg
))
5971 return apply_modifiers (event
->modifiers
, event
->arg
);
5974 case USER_SIGNAL_EVENT
:
5975 /* A user signal. */
5976 return *lispy_user_signals
[event
->code
];
5978 case SAVE_SESSION_EVENT
:
5979 return Qsave_session
;
5982 case MAC_APPLE_EVENT
:
5984 Lisp_Object spec
[2];
5988 return Fcons (Qmac_apple_event
,
5989 Fcons (Fvector (2, spec
),
5990 Fcons (mac_make_lispy_event_code (event
->code
),
5995 /* The 'kind' field of the event is something we don't recognize. */
6004 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
6006 Lisp_Object bar_window
;
6007 enum scroll_bar_part part
;
6011 /* Is it a scroll bar movement? */
6012 if (frame
&& ! NILP (bar_window
))
6014 Lisp_Object part_sym
;
6016 part_sym
= *scroll_bar_parts
[(int) part
];
6017 return Fcons (Qscroll_bar_movement
,
6018 (Fcons (Fcons (bar_window
,
6019 Fcons (Qvertical_scroll_bar
,
6020 Fcons (Fcons (x
, y
),
6021 Fcons (make_number (time
),
6027 /* Or is it an ordinary mouse movement? */
6030 Lisp_Object position
;
6032 position
= make_lispy_position (frame
, &x
, &y
, time
);
6034 return Fcons (Qmouse_movement
,
6040 #endif /* HAVE_MOUSE */
6042 /* Construct a switch frame event. */
6044 make_lispy_switch_frame (frame
)
6047 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
6050 /* Manipulating modifiers. */
6052 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
6054 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
6055 SYMBOL's name of the end of the modifiers; the string from this
6056 position is the unmodified symbol name.
6058 This doesn't use any caches. */
6061 parse_modifiers_uncached (symbol
, modifier_end
)
6069 CHECK_SYMBOL (symbol
);
6072 name
= SYMBOL_NAME (symbol
);
6074 for (i
= 0; i
+2 <= SBYTES (name
); )
6076 int this_mod_end
= 0;
6079 /* See if the name continues with a modifier word.
6080 Check that the word appears, but don't check what follows it.
6081 Set this_mod and this_mod_end to record what we find. */
6083 switch (SREF (name
, i
))
6085 #define SINGLE_LETTER_MOD(BIT) \
6086 (this_mod_end = i + 1, this_mod = BIT)
6089 SINGLE_LETTER_MOD (alt_modifier
);
6093 SINGLE_LETTER_MOD (ctrl_modifier
);
6097 SINGLE_LETTER_MOD (hyper_modifier
);
6101 SINGLE_LETTER_MOD (meta_modifier
);
6105 SINGLE_LETTER_MOD (shift_modifier
);
6109 SINGLE_LETTER_MOD (super_modifier
);
6112 #undef SINGLE_LETTER_MOD
6114 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
6115 if (i + LEN + 1 <= SBYTES (name) \
6116 && ! strncmp (SDATA (name) + i, NAME, LEN)) \
6118 this_mod_end = i + LEN; \
6123 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
6124 MULTI_LETTER_MOD (down_modifier
, "down", 4);
6125 MULTI_LETTER_MOD (double_modifier
, "double", 6);
6129 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
6131 #undef MULTI_LETTER_MOD
6135 /* If we found no modifier, stop looking for them. */
6136 if (this_mod_end
== 0)
6139 /* Check there is a dash after the modifier, so that it
6140 really is a modifier. */
6141 if (this_mod_end
>= SBYTES (name
)
6142 || SREF (name
, this_mod_end
) != '-')
6145 /* This modifier is real; look for another. */
6146 modifiers
|= this_mod
;
6147 i
= this_mod_end
+ 1;
6150 /* Should we include the `click' modifier? */
6151 if (! (modifiers
& (down_modifier
| drag_modifier
6152 | double_modifier
| triple_modifier
))
6153 && i
+ 7 == SBYTES (name
)
6154 && strncmp (SDATA (name
) + i
, "mouse-", 6) == 0
6155 && ('0' <= SREF (name
, i
+ 6) && SREF (name
, i
+ 6) <= '9'))
6156 modifiers
|= click_modifier
;
6164 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
6165 prepended to the string BASE[0..BASE_LEN-1].
6166 This doesn't use any caches. */
6168 apply_modifiers_uncached (modifiers
, base
, base_len
, base_len_byte
)
6171 int base_len
, base_len_byte
;
6173 /* Since BASE could contain nulls, we can't use intern here; we have
6174 to use Fintern, which expects a genuine Lisp_String, and keeps a
6177 = (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
6183 /* Only the event queue may use the `up' modifier; it should always
6184 be turned into a click or drag event before presented to lisp code. */
6185 if (modifiers
& up_modifier
)
6188 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
6189 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
6190 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
6191 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
6192 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
6193 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
6194 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
6195 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
6196 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
6197 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
6198 /* The click modifier is denoted by the absence of other modifiers. */
6202 mod_len
= p
- new_mods
;
6206 Lisp_Object new_name
;
6208 new_name
= make_uninit_multibyte_string (mod_len
+ base_len
,
6209 mod_len
+ base_len_byte
);
6210 bcopy (new_mods
, SDATA (new_name
), mod_len
);
6211 bcopy (base
, SDATA (new_name
) + mod_len
, base_len_byte
);
6213 return Fintern (new_name
, Qnil
);
6218 static char *modifier_names
[] =
6220 "up", "down", "drag", "click", "double", "triple", 0, 0,
6221 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6222 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
6224 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
6226 static Lisp_Object modifier_symbols
;
6228 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
6230 lispy_modifier_list (modifiers
)
6233 Lisp_Object modifier_list
;
6236 modifier_list
= Qnil
;
6237 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
6238 if (modifiers
& (1<<i
))
6239 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
6242 return modifier_list
;
6246 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
6247 where UNMODIFIED is the unmodified form of SYMBOL,
6248 MASK is the set of modifiers present in SYMBOL's name.
6249 This is similar to parse_modifiers_uncached, but uses the cache in
6250 SYMBOL's Qevent_symbol_element_mask property, and maintains the
6251 Qevent_symbol_elements property. */
6254 parse_modifiers (symbol
)
6257 Lisp_Object elements
;
6259 elements
= Fget (symbol
, Qevent_symbol_element_mask
);
6260 if (CONSP (elements
))
6265 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
6266 Lisp_Object unmodified
;
6269 unmodified
= Fintern (make_string (SDATA (SYMBOL_NAME (symbol
)) + end
,
6270 SBYTES (SYMBOL_NAME (symbol
)) - end
),
6273 if (modifiers
& ~INTMASK
)
6275 XSETFASTINT (mask
, modifiers
);
6276 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
6278 /* Cache the parsing results on SYMBOL. */
6279 Fput (symbol
, Qevent_symbol_element_mask
,
6281 Fput (symbol
, Qevent_symbol_elements
,
6282 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
6284 /* Since we know that SYMBOL is modifiers applied to unmodified,
6285 it would be nice to put that in unmodified's cache.
6286 But we can't, since we're not sure that parse_modifiers is
6293 /* Apply the modifiers MODIFIERS to the symbol BASE.
6294 BASE must be unmodified.
6296 This is like apply_modifiers_uncached, but uses BASE's
6297 Qmodifier_cache property, if present. It also builds
6298 Qevent_symbol_elements properties, since it has that info anyway.
6300 apply_modifiers copies the value of BASE's Qevent_kind property to
6301 the modified symbol. */
6303 apply_modifiers (modifiers
, base
)
6307 Lisp_Object cache
, index
, entry
, new_symbol
;
6309 /* Mask out upper bits. We don't know where this value's been. */
6310 modifiers
&= INTMASK
;
6312 /* The click modifier never figures into cache indices. */
6313 cache
= Fget (base
, Qmodifier_cache
);
6314 XSETFASTINT (index
, (modifiers
& ~click_modifier
));
6315 entry
= assq_no_quit (index
, cache
);
6318 new_symbol
= XCDR (entry
);
6321 /* We have to create the symbol ourselves. */
6322 new_symbol
= apply_modifiers_uncached (modifiers
,
6323 SDATA (SYMBOL_NAME (base
)),
6324 SCHARS (SYMBOL_NAME (base
)),
6325 SBYTES (SYMBOL_NAME (base
)));
6327 /* Add the new symbol to the base's cache. */
6328 entry
= Fcons (index
, new_symbol
);
6329 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
6331 /* We have the parsing info now for free, so we could add it to
6333 XSETFASTINT (index, modifiers);
6334 Fput (new_symbol, Qevent_symbol_element_mask,
6335 Fcons (base, Fcons (index, Qnil)));
6336 Fput (new_symbol, Qevent_symbol_elements,
6337 Fcons (base, lispy_modifier_list (modifiers)));
6338 Sadly, this is only correct if `base' is indeed a base event,
6339 which is not necessarily the case. -stef */
6342 /* Make sure this symbol is of the same kind as BASE.
6344 You'd think we could just set this once and for all when we
6345 intern the symbol above, but reorder_modifiers may call us when
6346 BASE's property isn't set right; we can't assume that just
6347 because it has a Qmodifier_cache property it must have its
6348 Qevent_kind set right as well. */
6349 if (NILP (Fget (new_symbol
, Qevent_kind
)))
6353 kind
= Fget (base
, Qevent_kind
);
6355 Fput (new_symbol
, Qevent_kind
, kind
);
6362 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
6363 return a symbol with the modifiers placed in the canonical order.
6364 Canonical order is alphabetical, except for down and drag, which
6365 always come last. The 'click' modifier is never written out.
6367 Fdefine_key calls this to make sure that (for example) C-M-foo
6368 and M-C-foo end up being equivalent in the keymap. */
6371 reorder_modifiers (symbol
)
6374 /* It's hopefully okay to write the code this way, since everything
6375 will soon be in caches, and no consing will be done at all. */
6378 parsed
= parse_modifiers (symbol
);
6379 return apply_modifiers ((int) XINT (XCAR (XCDR (parsed
))),
6384 /* For handling events, we often want to produce a symbol whose name
6385 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
6386 to some base, like the name of a function key or mouse button.
6387 modify_event_symbol produces symbols of this sort.
6389 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
6390 is the name of the i'th symbol. TABLE_SIZE is the number of elements
6393 Alternatively, NAME_ALIST_OR_STEM is either an alist mapping codes
6394 into symbol names, or a string specifying a name stem used to
6395 construct a symbol name or the form `STEM-N', where N is the decimal
6396 representation of SYMBOL_NUM. NAME_ALIST_OR_STEM is used if it is
6397 non-nil; otherwise NAME_TABLE is used.
6399 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
6400 persist between calls to modify_event_symbol that it can use to
6401 store a cache of the symbols it's generated for this NAME_TABLE
6402 before. The object stored there may be a vector or an alist.
6404 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
6406 MODIFIERS is a set of modifier bits (as given in struct input_events)
6407 whose prefixes should be applied to the symbol name.
6409 SYMBOL_KIND is the value to be placed in the event_kind property of
6410 the returned symbol.
6412 The symbols we create are supposed to have an
6413 `event-symbol-elements' property, which lists the modifiers present
6414 in the symbol's name. */
6417 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_alist_or_stem
,
6418 name_table
, symbol_table
, table_size
)
6421 Lisp_Object symbol_kind
;
6422 Lisp_Object name_alist_or_stem
;
6424 Lisp_Object
*symbol_table
;
6425 unsigned int table_size
;
6428 Lisp_Object symbol_int
;
6430 /* Get rid of the "vendor-specific" bit here. */
6431 XSETINT (symbol_int
, symbol_num
& 0xffffff);
6433 /* Is this a request for a valid symbol? */
6434 if (symbol_num
< 0 || symbol_num
>= table_size
)
6437 if (CONSP (*symbol_table
))
6438 value
= Fcdr (assq_no_quit (symbol_int
, *symbol_table
));
6440 /* If *symbol_table doesn't seem to be initialized properly, fix that.
6441 *symbol_table should be a lisp vector TABLE_SIZE elements long,
6442 where the Nth element is the symbol for NAME_TABLE[N], or nil if
6443 we've never used that symbol before. */
6446 if (! VECTORP (*symbol_table
)
6447 || XVECTOR (*symbol_table
)->size
!= table_size
)
6451 XSETFASTINT (size
, table_size
);
6452 *symbol_table
= Fmake_vector (size
, Qnil
);
6455 value
= XVECTOR (*symbol_table
)->contents
[symbol_num
];
6458 /* Have we already used this symbol before? */
6461 /* No; let's create it. */
6462 if (CONSP (name_alist_or_stem
))
6463 value
= Fcdr_safe (Fassq (symbol_int
, name_alist_or_stem
));
6464 else if (STRINGP (name_alist_or_stem
))
6466 int len
= SBYTES (name_alist_or_stem
);
6467 char *buf
= (char *) alloca (len
+ 50);
6468 sprintf (buf
, "%s-%ld", SDATA (name_alist_or_stem
),
6469 (long) XINT (symbol_int
) + 1);
6470 value
= intern (buf
);
6472 else if (name_table
!= 0 && name_table
[symbol_num
])
6473 value
= intern (name_table
[symbol_num
]);
6475 #ifdef HAVE_WINDOW_SYSTEM
6478 char *name
= x_get_keysym_name (symbol_num
);
6480 value
= intern (name
);
6487 sprintf (buf
, "key-%d", symbol_num
);
6488 value
= intern (buf
);
6491 if (CONSP (*symbol_table
))
6492 *symbol_table
= Fcons (Fcons (symbol_int
, value
), *symbol_table
);
6494 XVECTOR (*symbol_table
)->contents
[symbol_num
] = value
;
6496 /* Fill in the cache entries for this symbol; this also
6497 builds the Qevent_symbol_elements property, which the user
6499 apply_modifiers (modifiers
& click_modifier
, value
);
6500 Fput (value
, Qevent_kind
, symbol_kind
);
6503 /* Apply modifiers to that symbol. */
6504 return apply_modifiers (modifiers
, value
);
6507 /* Convert a list that represents an event type,
6508 such as (ctrl meta backspace), into the usual representation of that
6509 event type as a number or a symbol. */
6511 DEFUN ("event-convert-list", Fevent_convert_list
, Sevent_convert_list
, 1, 1, 0,
6512 doc
: /* Convert the event description list EVENT-DESC to an event type.
6513 EVENT-DESC should contain one base event type (a character or symbol)
6514 and zero or more modifier names (control, meta, hyper, super, shift, alt,
6515 drag, down, double or triple). The base must be last.
6516 The return value is an event type (a character or symbol) which
6517 has the same base event type and all the specified modifiers. */)
6519 Lisp_Object event_desc
;
6527 while (CONSP (rest
))
6535 /* Given a symbol, see if it is a modifier name. */
6536 if (SYMBOLP (elt
) && CONSP (rest
))
6537 this = parse_solitary_modifier (elt
);
6541 else if (!NILP (base
))
6542 error ("Two bases given in one event");
6548 /* Let the symbol A refer to the character A. */
6549 if (SYMBOLP (base
) && SCHARS (SYMBOL_NAME (base
)) == 1)
6550 XSETINT (base
, SREF (SYMBOL_NAME (base
), 0));
6552 if (INTEGERP (base
))
6554 /* Turn (shift a) into A. */
6555 if ((modifiers
& shift_modifier
) != 0
6556 && (XINT (base
) >= 'a' && XINT (base
) <= 'z'))
6558 XSETINT (base
, XINT (base
) - ('a' - 'A'));
6559 modifiers
&= ~shift_modifier
;
6562 /* Turn (control a) into C-a. */
6563 if (modifiers
& ctrl_modifier
)
6564 return make_number ((modifiers
& ~ctrl_modifier
)
6565 | make_ctrl_char (XINT (base
)));
6567 return make_number (modifiers
| XINT (base
));
6569 else if (SYMBOLP (base
))
6570 return apply_modifiers (modifiers
, base
);
6573 error ("Invalid base event");
6578 /* Try to recognize SYMBOL as a modifier name.
6579 Return the modifier flag bit, or 0 if not recognized. */
6582 parse_solitary_modifier (symbol
)
6585 Lisp_Object name
= SYMBOL_NAME (symbol
);
6587 switch (SREF (name
, 0))
6589 #define SINGLE_LETTER_MOD(BIT) \
6590 if (SBYTES (name) == 1) \
6593 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
6594 if (LEN == SBYTES (name) \
6595 && ! strncmp (SDATA (name), NAME, LEN)) \
6599 SINGLE_LETTER_MOD (alt_modifier
);
6603 MULTI_LETTER_MOD (alt_modifier
, "alt", 3);
6607 SINGLE_LETTER_MOD (ctrl_modifier
);
6611 MULTI_LETTER_MOD (ctrl_modifier
, "ctrl", 4);
6612 MULTI_LETTER_MOD (ctrl_modifier
, "control", 7);
6616 SINGLE_LETTER_MOD (hyper_modifier
);
6620 MULTI_LETTER_MOD (hyper_modifier
, "hyper", 5);
6624 SINGLE_LETTER_MOD (meta_modifier
);
6628 MULTI_LETTER_MOD (meta_modifier
, "meta", 4);
6632 SINGLE_LETTER_MOD (shift_modifier
);
6636 MULTI_LETTER_MOD (shift_modifier
, "shift", 5);
6637 MULTI_LETTER_MOD (super_modifier
, "super", 5);
6638 SINGLE_LETTER_MOD (super_modifier
);
6642 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
6643 MULTI_LETTER_MOD (down_modifier
, "down", 4);
6644 MULTI_LETTER_MOD (double_modifier
, "double", 6);
6648 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
6651 #undef SINGLE_LETTER_MOD
6652 #undef MULTI_LETTER_MOD
6658 /* Return 1 if EVENT is a list whose elements are all integers or symbols.
6659 Such a list is not valid as an event,
6660 but it can be a Lucid-style event type list. */
6663 lucid_event_type_list_p (object
)
6668 if (! CONSP (object
))
6671 if (EQ (XCAR (object
), Qhelp_echo
)
6672 || EQ (XCAR (object
), Qvertical_line
)
6673 || EQ (XCAR (object
), Qmode_line
)
6674 || EQ (XCAR (object
), Qheader_line
))
6677 for (tail
= object
; CONSP (tail
); tail
= XCDR (tail
))
6681 if (! (INTEGERP (elt
) || SYMBOLP (elt
)))
6688 /* Store into *addr a value nonzero if terminal input chars are available.
6689 Serves the purpose of ioctl (0, FIONREAD, addr)
6690 but works even if FIONREAD does not exist.
6691 (In fact, this may actually read some input.)
6693 If READABLE_EVENTS_DO_TIMERS_NOW is set in FLAGS, actually run
6694 timer events that are ripe.
6695 If READABLE_EVENTS_FILTER_EVENTS is set in FLAGS, ignore internal
6696 events (FOCUS_IN_EVENT).
6697 If READABLE_EVENTS_IGNORE_SQUEEZABLES is set in FLAGS, ignore mouse
6698 movements and toolkit scroll bar thumb drags. */
6701 get_input_pending (addr
, flags
)
6705 /* First of all, have we already counted some input? */
6706 *addr
= (!NILP (Vquit_flag
) || readable_events (flags
));
6708 /* If input is being read as it arrives, and we have none, there is none. */
6709 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
6712 /* Try to read some input and see how much we get. */
6714 *addr
= (!NILP (Vquit_flag
) || readable_events (flags
));
6717 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
6720 gobble_input (expected
)
6725 if (interrupt_input
)
6728 mask
= sigblock (sigmask (SIGIO
));
6729 read_avail_input (expected
);
6733 #ifdef POLL_FOR_INPUT
6734 /* XXX This condition was (read_socket_hook && !interrupt_input),
6735 but read_socket_hook is not global anymore. Let's pretend that
6737 if (!interrupt_input
&& poll_suppress_count
== 0)
6740 mask
= sigblock (sigmask (SIGALRM
));
6741 read_avail_input (expected
);
6747 read_avail_input (expected
);
6751 /* Put a BUFFER_SWITCH_EVENT in the buffer
6752 so that read_key_sequence will notice the new current buffer. */
6755 record_asynch_buffer_change ()
6757 struct input_event event
;
6761 event
.kind
= BUFFER_SWITCH_EVENT
;
6762 event
.frame_or_window
= Qnil
;
6766 /* We don't need a buffer-switch event unless Emacs is waiting for input.
6767 The purpose of the event is to make read_key_sequence look up the
6768 keymaps again. If we aren't in read_key_sequence, we don't need one,
6769 and the event could cause trouble by messing up (input-pending-p). */
6770 tem
= Fwaiting_for_user_input_p ();
6774 /* We never need these events if we have no asynchronous subprocesses. */
6778 /* Make sure no interrupt happens while storing the event. */
6780 if (interrupt_input
)
6783 mask
= sigblock (sigmask (SIGIO
));
6784 kbd_buffer_store_event (&event
);
6791 kbd_buffer_store_event (&event
);
6798 /* Read any terminal input already buffered up by the system
6799 into the kbd_buffer, but do not wait.
6801 EXPECTED should be nonzero if the caller knows there is some input.
6803 Except on VMS, all input is read by this function.
6804 If interrupt_input is nonzero, this function MUST be called
6805 only when SIGIO is blocked.
6807 Returns the number of keyboard chars read, or -1 meaning
6808 this is a bad time to try to read input. */
6811 read_avail_input (expected
)
6818 /* Loop through the available terminals, and call their input hooks. */
6822 struct terminal
*next
= t
->next_terminal
;
6824 if (t
->read_socket_hook
)
6827 struct input_event hold_quit
;
6829 EVENT_INIT (hold_quit
);
6830 hold_quit
.kind
= NO_EVENT
;
6832 /* No need for FIONREAD or fcntl; just say don't wait. */
6833 while (nr
= (*t
->read_socket_hook
) (t
, expected
, &hold_quit
), nr
> 0)
6839 if (nr
== -1) /* Not OK to read input now. */
6843 else if (nr
== -2) /* Non-transient error. */
6845 /* The terminal device terminated; it should be closed. */
6847 /* Kill Emacs if this was our last terminal. */
6848 if (!terminal_list
->next_terminal
)
6849 /* Formerly simply reported no input, but that
6850 sometimes led to a failure of Emacs to terminate.
6851 SIGHUP seems appropriate if we can't reach the
6853 /* ??? Is it really right to send the signal just to
6854 this process rather than to the whole process
6855 group? Perhaps on systems with FIONREAD Emacs is
6856 alone in its group. */
6857 kill (getpid (), SIGHUP
);
6859 /* XXX Is calling delete_terminal safe here? It calls Fdelete_frame. */
6860 if (t
->delete_terminal_hook
)
6861 (*t
->delete_terminal_hook
) (t
);
6863 delete_terminal (t
);
6866 if (hold_quit
.kind
!= NO_EVENT
)
6867 kbd_buffer_store_event (&hold_quit
);
6879 /* This is the tty way of reading available input.
6881 Note that each terminal device has its own `struct terminal' object,
6882 and so this function is called once for each individual termcap
6883 terminal. The first parameter indicates which terminal to read from. */
6886 tty_read_avail_input (struct terminal
*terminal
,
6888 struct input_event
*hold_quit
)
6890 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
6891 the kbd_buffer can really hold. That may prevent loss
6892 of characters on some systems when input is stuffed at us. */
6893 unsigned char cbuf
[KBD_BUFFER_SIZE
- 1];
6895 struct tty_display_info
*tty
= terminal
->display_info
.tty
;
6898 if (terminal
->type
!= output_termcap
)
6901 /* XXX I think the following code should be moved to separate hook
6902 functions in system-dependent files. */
6905 #else /* not WINDOWSNT */
6907 n_to_read
= dos_keysns ();
6911 cbuf
[0] = dos_keyread ();
6914 #else /* not MSDOS */
6916 if (! tty
->term_initted
) /* In case we get called during bootstrap. */
6920 return 0; /* The terminal is suspended. */
6922 /* Determine how many characters we should *try* to read. */
6924 /* Find out how much input is available. */
6925 if (ioctl (fileno (tty
->input
), FIONREAD
, &n_to_read
) < 0)
6927 if (! noninteractive
)
6928 return -2; /* Close this terminal. */
6934 if (n_to_read
> sizeof cbuf
)
6935 n_to_read
= sizeof cbuf
;
6936 #else /* no FIONREAD */
6937 #if defined (USG) || defined (DGUX) || defined(CYGWIN)
6938 /* Read some input if available, but don't wait. */
6939 n_to_read
= sizeof cbuf
;
6940 fcntl (fileno (tty
->input
), F_SETFL
, O_NDELAY
);
6946 /* Now read; for one reason or another, this will not block.
6947 NREAD is set to the number of chars read. */
6950 nread
= emacs_read (fileno (tty
->input
), cbuf
, n_to_read
);
6951 /* POSIX infers that processes which are not in the session leader's
6952 process group won't get SIGHUP's at logout time. BSDI adheres to
6953 this part standard and returns -1 from read (0) with errno==EIO
6954 when the control tty is taken away.
6955 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
6956 if (nread
== -1 && errno
== EIO
)
6957 return -2; /* Close this terminal. */
6958 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
6959 /* The kernel sometimes fails to deliver SIGHUP for ptys.
6960 This looks incorrect, but it isn't, because _BSD causes
6961 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
6962 and that causes a value other than 0 when there is no input. */
6964 return -2; /* Close this terminal. */
6968 /* We used to retry the read if it was interrupted.
6969 But this does the wrong thing when O_NDELAY causes
6970 an EAGAIN error. Does anybody know of a situation
6971 where a retry is actually needed? */
6973 nread
< 0 && (errno
== EAGAIN
6987 #if defined (USG) || defined (DGUX) || defined (CYGWIN)
6988 fcntl (fileno (tty
->input
), F_SETFL
, 0);
6989 #endif /* USG or DGUX or CYGWIN */
6990 #endif /* no FIONREAD */
6995 #endif /* not MSDOS */
6996 #endif /* not WINDOWSNT */
6998 for (i
= 0; i
< nread
; i
++)
7000 struct input_event buf
;
7002 buf
.kind
= ASCII_KEYSTROKE_EVENT
;
7004 if (tty
->meta_key
== 1 && (cbuf
[i
] & 0x80))
7005 buf
.modifiers
= meta_modifier
;
7006 if (tty
->meta_key
!= 2)
7010 /* Set the frame corresponding to the active tty. Note that the
7011 value of selected_frame is not reliable here, redisplay tends
7012 to temporarily change it. */
7013 buf
.frame_or_window
= tty
->top_frame
;
7016 kbd_buffer_store_event (&buf
);
7017 /* Don't look at input that follows a C-g too closely.
7018 This reduces lossage due to autorepeat on C-g. */
7019 if (buf
.kind
== ASCII_KEYSTROKE_EVENT
7020 && buf
.code
== quit_char
)
7026 #endif /* not VMS */
7029 handle_async_input ()
7032 extern int select_alarmed
;
7035 interrupt_input_pending
= 0;
7040 nread
= read_avail_input (1);
7041 /* -1 means it's not ok to read the input now.
7042 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
7043 0 means there was no keyboard input available. */
7048 select_alarmed
= 1; /* Force the select emulator back to life */
7053 #ifdef SIGIO /* for entire page */
7054 /* Note SIGIO has been undef'd if FIONREAD is missing. */
7057 input_available_signal (signo
)
7060 /* Must preserve main program's value of errno. */
7061 int old_errno
= errno
;
7062 #if defined (USG) && !defined (POSIX_SIGNALS)
7063 /* USG systems forget handlers when they are used;
7064 must reestablish each time */
7065 signal (signo
, input_available_signal
);
7073 interrupt_input_pending
= 1;
7075 SIGNAL_THREAD_CHECK (signo
);
7078 if (input_available_clear_time
)
7079 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
7082 handle_async_input ();
7092 /* Send ourselves a SIGIO.
7094 This function exists so that the UNBLOCK_INPUT macro in
7095 blockinput.h can have some way to take care of input we put off
7096 dealing with, without assuming that every file which uses
7097 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
7099 reinvoke_input_signal ()
7102 handle_async_input ();
7108 static void menu_bar_item
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
, void*));
7109 static Lisp_Object menu_bar_one_keymap_changed_items
;
7111 /* These variables hold the vector under construction within
7112 menu_bar_items and its subroutines, and the current index
7113 for storing into that vector. */
7114 static Lisp_Object menu_bar_items_vector
;
7115 static int menu_bar_items_index
;
7117 /* Return a vector of menu items for a menu bar, appropriate
7118 to the current buffer. Each item has three elements in the vector:
7121 OLD is an old vector we can optionally reuse, or nil. */
7124 menu_bar_items (old
)
7127 /* The number of keymaps we're scanning right now, and the number of
7128 keymaps we have allocated space for. */
7131 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
7132 in the current keymaps, or nil where it is not a prefix. */
7135 Lisp_Object def
, tail
;
7144 /* In order to build the menus, we need to call the keymap
7145 accessors. They all call QUIT. But this function is called
7146 during redisplay, during which a quit is fatal. So inhibit
7147 quitting while building the menus.
7148 We do this instead of specbind because (1) errors will clear it anyway
7149 and (2) this avoids risk of specpdl overflow. */
7150 oquit
= Vinhibit_quit
;
7154 menu_bar_items_vector
= old
;
7156 menu_bar_items_vector
= Fmake_vector (make_number (24), Qnil
);
7157 menu_bar_items_index
= 0;
7159 /* Build our list of keymaps.
7160 If we recognize a function key and replace its escape sequence in
7161 keybuf with its symbol, or if the sequence starts with a mouse
7162 click and we need to switch buffers, we jump back here to rebuild
7163 the initial keymaps from the current buffer. */
7167 /* Should overriding-terminal-local-map and overriding-local-map apply? */
7168 if (!NILP (Voverriding_local_map_menu_flag
))
7170 /* Yes, use them (if non-nil) as well as the global map. */
7171 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
7173 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
7174 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
7175 if (!NILP (Voverriding_local_map
))
7176 maps
[nmaps
++] = Voverriding_local_map
;
7180 /* No, so use major and minor mode keymaps and keymap property.
7181 Note that menu-bar bindings in the local-map and keymap
7182 properties may not work reliable, as they are only
7183 recognized when the menu-bar (or mode-line) is updated,
7184 which does not normally happen after every command. */
7187 nminor
= current_minor_maps (NULL
, &tmaps
);
7188 maps
= (Lisp_Object
*) alloca ((nminor
+ 3) * sizeof (maps
[0]));
7190 if (tem
= get_local_map (PT
, current_buffer
, Qkeymap
), !NILP (tem
))
7191 maps
[nmaps
++] = tem
;
7192 bcopy (tmaps
, (void *) (maps
+ nmaps
), nminor
* sizeof (maps
[0]));
7194 maps
[nmaps
++] = get_local_map (PT
, current_buffer
, Qlocal_map
);
7196 maps
[nmaps
++] = current_global_map
;
7199 /* Look up in each map the dummy prefix key `menu-bar'. */
7203 for (mapno
= nmaps
- 1; mapno
>= 0; mapno
--)
7204 if (!NILP (maps
[mapno
]))
7206 def
= get_keymap (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0, 1),
7210 menu_bar_one_keymap_changed_items
= Qnil
;
7211 map_keymap (def
, menu_bar_item
, Qnil
, NULL
, 1);
7215 /* Move to the end those items that should be at the end. */
7217 for (tail
= Vmenu_bar_final_items
; CONSP (tail
); tail
= XCDR (tail
))
7220 int end
= menu_bar_items_index
;
7222 for (i
= 0; i
< end
; i
+= 4)
7223 if (EQ (XCAR (tail
), XVECTOR (menu_bar_items_vector
)->contents
[i
]))
7225 Lisp_Object tem0
, tem1
, tem2
, tem3
;
7226 /* Move the item at index I to the end,
7227 shifting all the others forward. */
7228 tem0
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 0];
7229 tem1
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 1];
7230 tem2
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
7231 tem3
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3];
7233 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
7234 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
7235 (end
- i
- 4) * sizeof (Lisp_Object
));
7236 XVECTOR (menu_bar_items_vector
)->contents
[end
- 4] = tem0
;
7237 XVECTOR (menu_bar_items_vector
)->contents
[end
- 3] = tem1
;
7238 XVECTOR (menu_bar_items_vector
)->contents
[end
- 2] = tem2
;
7239 XVECTOR (menu_bar_items_vector
)->contents
[end
- 1] = tem3
;
7244 /* Add nil, nil, nil, nil at the end. */
7245 i
= menu_bar_items_index
;
7246 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
7249 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
7250 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
7251 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
7252 menu_bar_items_vector
= tem
;
7254 /* Add this item. */
7255 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
7256 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
7257 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
7258 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
7259 menu_bar_items_index
= i
;
7261 Vinhibit_quit
= oquit
;
7262 return menu_bar_items_vector
;
7265 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
7266 If there's already an item for KEY, add this DEF to it. */
7268 Lisp_Object item_properties
;
7271 menu_bar_item (key
, item
, dummy1
, dummy2
)
7272 Lisp_Object key
, item
, dummy1
;
7275 struct gcpro gcpro1
;
7279 if (EQ (item
, Qundefined
))
7281 /* If a map has an explicit `undefined' as definition,
7282 discard any previously made menu bar item. */
7284 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
7285 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
7287 if (menu_bar_items_index
> i
+ 4)
7288 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
7289 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
7290 (menu_bar_items_index
- i
- 4) * sizeof (Lisp_Object
));
7291 menu_bar_items_index
-= 4;
7295 /* If this keymap has already contributed to this KEY,
7296 don't contribute to it a second time. */
7297 tem
= Fmemq (key
, menu_bar_one_keymap_changed_items
);
7298 if (!NILP (tem
) || NILP (item
))
7301 menu_bar_one_keymap_changed_items
7302 = Fcons (key
, menu_bar_one_keymap_changed_items
);
7304 /* We add to menu_bar_one_keymap_changed_items before doing the
7305 parse_menu_item, so that if it turns out it wasn't a menu item,
7306 it still correctly hides any further menu item. */
7308 i
= parse_menu_item (item
, 0, 1);
7313 item
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
7315 /* Find any existing item for this KEY. */
7316 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
7317 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
7320 /* If we did not find this KEY, add it at the end. */
7321 if (i
== menu_bar_items_index
)
7323 /* If vector is too small, get a bigger one. */
7324 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
7327 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
7328 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
7329 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
7330 menu_bar_items_vector
= tem
;
7333 /* Add this item. */
7334 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = key
;
7335 XVECTOR (menu_bar_items_vector
)->contents
[i
++]
7336 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
7337 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Fcons (item
, Qnil
);
7338 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = make_number (0);
7339 menu_bar_items_index
= i
;
7341 /* We did find an item for this KEY. Add ITEM to its list of maps. */
7345 old
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
7346 /* If the new and the old items are not both keymaps,
7347 the lookup will only find `item'. */
7348 item
= Fcons (item
, KEYMAPP (item
) && KEYMAPP (XCAR (old
)) ? old
: Qnil
);
7349 XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2] = item
;
7353 /* This is used as the handler when calling menu_item_eval_property. */
7355 menu_item_eval_property_1 (arg
)
7358 /* If we got a quit from within the menu computation,
7359 quit all the way out of it. This takes care of C-] in the debugger. */
7360 if (CONSP (arg
) && EQ (XCAR (arg
), Qquit
))
7361 Fsignal (Qquit
, Qnil
);
7366 /* Evaluate an expression and return the result (or nil if something
7367 went wrong). Used to evaluate dynamic parts of menu items. */
7369 menu_item_eval_property (sexpr
)
7372 int count
= SPECPDL_INDEX ();
7374 specbind (Qinhibit_redisplay
, Qt
);
7375 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
,
7376 menu_item_eval_property_1
);
7377 return unbind_to (count
, val
);
7380 /* This function parses a menu item and leaves the result in the
7381 vector item_properties.
7382 ITEM is a key binding, a possible menu item.
7383 If NOTREAL is nonzero, only check for equivalent key bindings, don't
7384 evaluate dynamic expressions in the menu item.
7385 INMENUBAR is > 0 when this is considered for an entry in a menu bar
7387 INMENUBAR is < 0 when this is considered for an entry in a keyboard menu.
7388 parse_menu_item returns true if the item is a menu item and false
7392 parse_menu_item (item
, notreal
, inmenubar
)
7394 int notreal
, inmenubar
;
7396 Lisp_Object def
, tem
, item_string
, start
;
7397 Lisp_Object cachelist
;
7399 Lisp_Object keyhint
;
7410 /* Create item_properties vector if necessary. */
7411 if (NILP (item_properties
))
7413 = Fmake_vector (make_number (ITEM_PROPERTY_ENABLE
+ 1), Qnil
);
7415 /* Initialize optional entries. */
7416 for (i
= ITEM_PROPERTY_DEF
; i
< ITEM_PROPERTY_ENABLE
; i
++)
7417 AREF (item_properties
, i
) = Qnil
;
7418 AREF (item_properties
, ITEM_PROPERTY_ENABLE
) = Qt
;
7420 /* Save the item here to protect it from GC. */
7421 AREF (item_properties
, ITEM_PROPERTY_ITEM
) = item
;
7423 item_string
= XCAR (item
);
7427 if (STRINGP (item_string
))
7429 /* Old format menu item. */
7430 AREF (item_properties
, ITEM_PROPERTY_NAME
) = item_string
;
7432 /* Maybe help string. */
7433 if (CONSP (item
) && STRINGP (XCAR (item
)))
7435 AREF (item_properties
, ITEM_PROPERTY_HELP
) = XCAR (item
);
7440 /* Maybe key binding cache. */
7441 if (CONSP (item
) && CONSP (XCAR (item
))
7442 && (NILP (XCAR (XCAR (item
)))
7443 || VECTORP (XCAR (XCAR (item
)))))
7445 cachelist
= XCAR (item
);
7449 /* This is the real definition--the function to run. */
7450 AREF (item_properties
, ITEM_PROPERTY_DEF
) = item
;
7452 /* Get enable property, if any. */
7455 tem
= Fget (item
, Qmenu_enable
);
7457 AREF (item_properties
, ITEM_PROPERTY_ENABLE
) = tem
;
7460 else if (EQ (item_string
, Qmenu_item
) && CONSP (item
))
7462 /* New format menu item. */
7463 AREF (item_properties
, ITEM_PROPERTY_NAME
) = XCAR (item
);
7464 start
= XCDR (item
);
7467 /* We have a real binding. */
7468 AREF (item_properties
, ITEM_PROPERTY_DEF
) = XCAR (start
);
7470 item
= XCDR (start
);
7471 /* Is there a cache list with key equivalences. */
7472 if (CONSP (item
) && CONSP (XCAR (item
)))
7474 cachelist
= XCAR (item
);
7478 /* Parse properties. */
7479 while (CONSP (item
) && CONSP (XCDR (item
)))
7484 if (EQ (tem
, QCenable
))
7485 AREF (item_properties
, ITEM_PROPERTY_ENABLE
) = XCAR (item
);
7486 else if (EQ (tem
, QCvisible
) && !notreal
)
7488 /* If got a visible property and that evaluates to nil
7489 then ignore this item. */
7490 tem
= menu_item_eval_property (XCAR (item
));
7494 else if (EQ (tem
, QChelp
))
7495 AREF (item_properties
, ITEM_PROPERTY_HELP
) = XCAR (item
);
7496 else if (EQ (tem
, QCfilter
))
7498 else if (EQ (tem
, QCkey_sequence
))
7501 if (NILP (cachelist
)
7502 && (SYMBOLP (tem
) || STRINGP (tem
) || VECTORP (tem
)))
7503 /* Be GC protected. Set keyhint to item instead of tem. */
7506 else if (EQ (tem
, QCkeys
))
7509 if (CONSP (tem
) || (STRINGP (tem
) && NILP (cachelist
)))
7510 AREF (item_properties
, ITEM_PROPERTY_KEYEQ
) = tem
;
7512 else if (EQ (tem
, QCbutton
) && CONSP (XCAR (item
)))
7517 if (EQ (type
, QCtoggle
) || EQ (type
, QCradio
))
7519 AREF (item_properties
, ITEM_PROPERTY_SELECTED
)
7521 AREF (item_properties
, ITEM_PROPERTY_TYPE
)
7528 else if (inmenubar
|| !NILP (start
))
7532 return 0; /* not a menu item */
7534 /* If item string is not a string, evaluate it to get string.
7535 If we don't get a string, skip this item. */
7536 item_string
= AREF (item_properties
, ITEM_PROPERTY_NAME
);
7537 if (!(STRINGP (item_string
) || notreal
))
7539 item_string
= menu_item_eval_property (item_string
);
7540 if (!STRINGP (item_string
))
7542 AREF (item_properties
, ITEM_PROPERTY_NAME
) = item_string
;
7545 /* If got a filter apply it on definition. */
7546 def
= AREF (item_properties
, ITEM_PROPERTY_DEF
);
7549 def
= menu_item_eval_property (list2 (XCAR (filter
),
7550 list2 (Qquote
, def
)));
7552 AREF (item_properties
, ITEM_PROPERTY_DEF
) = def
;
7555 /* Enable or disable selection of item. */
7556 tem
= AREF (item_properties
, ITEM_PROPERTY_ENABLE
);
7562 tem
= menu_item_eval_property (tem
);
7563 if (inmenubar
&& NILP (tem
))
7564 return 0; /* Ignore disabled items in menu bar. */
7565 AREF (item_properties
, ITEM_PROPERTY_ENABLE
) = tem
;
7568 /* If we got no definition, this item is just unselectable text which
7569 is OK in a submenu but not in the menubar. */
7571 return (inmenubar
? 0 : 1);
7573 /* See if this is a separate pane or a submenu. */
7574 def
= AREF (item_properties
, ITEM_PROPERTY_DEF
);
7575 tem
= get_keymap (def
, 0, 1);
7576 /* For a subkeymap, just record its details and exit. */
7579 AREF (item_properties
, ITEM_PROPERTY_MAP
) = tem
;
7580 AREF (item_properties
, ITEM_PROPERTY_DEF
) = tem
;
7584 /* At the top level in the menu bar, do likewise for commands also.
7585 The menu bar does not display equivalent key bindings anyway.
7586 ITEM_PROPERTY_DEF is already set up properly. */
7590 /* This is a command. See if there is an equivalent key binding. */
7591 if (NILP (cachelist
))
7593 /* We have to create a cachelist. */
7594 CHECK_IMPURE (start
);
7595 XSETCDR (start
, Fcons (Fcons (Qnil
, Qnil
), XCDR (start
)));
7596 cachelist
= XCAR (XCDR (start
));
7598 tem
= AREF (item_properties
, ITEM_PROPERTY_KEYEQ
);
7599 if (!NILP (keyhint
))
7601 XSETCAR (cachelist
, XCAR (keyhint
));
7604 else if (STRINGP (tem
))
7606 XSETCDR (cachelist
, Fsubstitute_command_keys (tem
));
7607 XSETCAR (cachelist
, Qt
);
7611 tem
= XCAR (cachelist
);
7618 tem
= Fkey_binding (tem
, Qnil
, Qnil
);
7620 prefix
= AREF (item_properties
, ITEM_PROPERTY_KEYEQ
);
7623 def
= XCAR (prefix
);
7624 prefix
= XCDR (prefix
);
7627 def
= AREF (item_properties
, ITEM_PROPERTY_DEF
);
7629 if (NILP (XCAR (cachelist
))) /* Have no saved key. */
7631 if (newcache
/* Always check first time. */
7632 /* Should we check everything when precomputing key
7634 /* If something had no key binding before, don't recheck it
7635 because that is too slow--except if we have a list of
7636 rebound commands in Vdefine_key_rebound_commands, do
7637 recheck any command that appears in that list. */
7638 || (CONSP (Vdefine_key_rebound_commands
)
7639 && !NILP (Fmemq (def
, Vdefine_key_rebound_commands
))))
7642 /* We had a saved key. Is it still bound to the command? */
7645 /* If the command is an alias for another
7646 (such as lmenu.el set it up), check if the
7647 original command matches the cached command. */
7648 && !(SYMBOLP (def
) && EQ (tem
, XSYMBOL (def
)->function
))))
7649 chkcache
= 1; /* Need to recompute key binding. */
7653 /* Recompute equivalent key binding. If the command is an alias
7654 for another (such as lmenu.el set it up), see if the original
7655 command name has equivalent keys. Otherwise look up the
7656 specified command itself. We don't try both, because that
7657 makes lmenu menus slow. */
7659 && SYMBOLP (XSYMBOL (def
)->function
)
7660 && ! NILP (Fget (def
, Qmenu_alias
)))
7661 def
= XSYMBOL (def
)->function
;
7662 tem
= Fwhere_is_internal (def
, Qnil
, Qt
, Qnil
, Qt
);
7663 XSETCAR (cachelist
, tem
);
7666 XSETCDR (cachelist
, Qnil
);
7670 else if (!NILP (keyhint
) && !NILP (XCAR (cachelist
)))
7672 tem
= XCAR (cachelist
);
7676 newcache
= chkcache
;
7679 tem
= Fkey_description (tem
, Qnil
);
7682 if (STRINGP (XCAR (prefix
)))
7683 tem
= concat2 (XCAR (prefix
), tem
);
7684 if (STRINGP (XCDR (prefix
)))
7685 tem
= concat2 (tem
, XCDR (prefix
));
7687 XSETCDR (cachelist
, tem
);
7691 tem
= XCDR (cachelist
);
7692 if (newcache
&& !NILP (tem
))
7694 tem
= concat3 (build_string (" ("), tem
, build_string (")"));
7695 XSETCDR (cachelist
, tem
);
7698 /* If we only want to precompute equivalent key bindings, stop here. */
7702 /* If we have an equivalent key binding, use that. */
7703 AREF (item_properties
, ITEM_PROPERTY_KEYEQ
) = tem
;
7705 /* Include this when menu help is implemented.
7706 tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP];
7707 if (!(NILP (tem) || STRINGP (tem)))
7709 tem = menu_item_eval_property (tem);
7712 XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP] = tem;
7716 /* Handle radio buttons or toggle boxes. */
7717 tem
= AREF (item_properties
, ITEM_PROPERTY_SELECTED
);
7719 AREF (item_properties
, ITEM_PROPERTY_SELECTED
)
7720 = menu_item_eval_property (tem
);
7727 /***********************************************************************
7729 ***********************************************************************/
7731 /* A vector holding tool bar items while they are parsed in function
7732 tool_bar_items. Each item occupies TOOL_BAR_ITEM_NSCLOTS elements
7735 static Lisp_Object tool_bar_items_vector
;
7737 /* A vector holding the result of parse_tool_bar_item. Layout is like
7738 the one for a single item in tool_bar_items_vector. */
7740 static Lisp_Object tool_bar_item_properties
;
7742 /* Next free index in tool_bar_items_vector. */
7744 static int ntool_bar_items
;
7746 /* The symbols `tool-bar', and `:image'. */
7748 extern Lisp_Object Qtool_bar
;
7749 Lisp_Object QCimage
;
7751 /* Function prototypes. */
7753 static void init_tool_bar_items
P_ ((Lisp_Object
));
7754 static void process_tool_bar_item
P_ ((Lisp_Object
, Lisp_Object
));
7755 static int parse_tool_bar_item
P_ ((Lisp_Object
, Lisp_Object
));
7756 static void append_tool_bar_item
P_ ((void));
7759 /* Return a vector of tool bar items for keymaps currently in effect.
7760 Reuse vector REUSE if non-nil. Return in *NITEMS the number of
7761 tool bar items found. */
7764 tool_bar_items (reuse
, nitems
)
7775 /* In order to build the menus, we need to call the keymap
7776 accessors. They all call QUIT. But this function is called
7777 during redisplay, during which a quit is fatal. So inhibit
7778 quitting while building the menus. We do this instead of
7779 specbind because (1) errors will clear it anyway and (2) this
7780 avoids risk of specpdl overflow. */
7781 oquit
= Vinhibit_quit
;
7784 /* Initialize tool_bar_items_vector and protect it from GC. */
7785 init_tool_bar_items (reuse
);
7787 /* Build list of keymaps in maps. Set nmaps to the number of maps
7790 /* Should overriding-terminal-local-map and overriding-local-map apply? */
7791 if (!NILP (Voverriding_local_map_menu_flag
))
7793 /* Yes, use them (if non-nil) as well as the global map. */
7794 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
7796 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
7797 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
7798 if (!NILP (Voverriding_local_map
))
7799 maps
[nmaps
++] = Voverriding_local_map
;
7803 /* No, so use major and minor mode keymaps and keymap property.
7804 Note that tool-bar bindings in the local-map and keymap
7805 properties may not work reliable, as they are only
7806 recognized when the tool-bar (or mode-line) is updated,
7807 which does not normally happen after every command. */
7810 nminor
= current_minor_maps (NULL
, &tmaps
);
7811 maps
= (Lisp_Object
*) alloca ((nminor
+ 3) * sizeof (maps
[0]));
7813 if (tem
= get_local_map (PT
, current_buffer
, Qkeymap
), !NILP (tem
))
7814 maps
[nmaps
++] = tem
;
7815 bcopy (tmaps
, (void *) (maps
+ nmaps
), nminor
* sizeof (maps
[0]));
7817 maps
[nmaps
++] = get_local_map (PT
, current_buffer
, Qlocal_map
);
7820 /* Add global keymap at the end. */
7821 maps
[nmaps
++] = current_global_map
;
7823 /* Process maps in reverse order and look up in each map the prefix
7825 for (i
= nmaps
- 1; i
>= 0; --i
)
7826 if (!NILP (maps
[i
]))
7830 keymap
= get_keymap (access_keymap (maps
[i
], Qtool_bar
, 1, 0, 1), 0, 1);
7835 /* KEYMAP is a list `(keymap (KEY . BINDING) ...)'. */
7836 for (tail
= keymap
; CONSP (tail
); tail
= XCDR (tail
))
7838 Lisp_Object keydef
= XCAR (tail
);
7840 process_tool_bar_item (XCAR (keydef
), XCDR (keydef
));
7845 Vinhibit_quit
= oquit
;
7846 *nitems
= ntool_bar_items
/ TOOL_BAR_ITEM_NSLOTS
;
7847 return tool_bar_items_vector
;
7851 /* Process the definition of KEY which is DEF. */
7854 process_tool_bar_item (key
, def
)
7855 Lisp_Object key
, def
;
7858 extern Lisp_Object Qundefined
;
7859 struct gcpro gcpro1
, gcpro2
;
7861 /* Protect KEY and DEF from GC because parse_tool_bar_item may call
7865 if (EQ (def
, Qundefined
))
7867 /* If a map has an explicit `undefined' as definition,
7868 discard any previously made item. */
7869 for (i
= 0; i
< ntool_bar_items
; i
+= TOOL_BAR_ITEM_NSLOTS
)
7871 Lisp_Object
*v
= XVECTOR (tool_bar_items_vector
)->contents
+ i
;
7873 if (EQ (key
, v
[TOOL_BAR_ITEM_KEY
]))
7875 if (ntool_bar_items
> i
+ TOOL_BAR_ITEM_NSLOTS
)
7876 bcopy (v
+ TOOL_BAR_ITEM_NSLOTS
, v
,
7877 ((ntool_bar_items
- i
- TOOL_BAR_ITEM_NSLOTS
)
7878 * sizeof (Lisp_Object
)));
7879 ntool_bar_items
-= TOOL_BAR_ITEM_NSLOTS
;
7884 else if (parse_tool_bar_item (key
, def
))
7885 /* Append a new tool bar item to tool_bar_items_vector. Accept
7886 more than one definition for the same key. */
7887 append_tool_bar_item ();
7893 /* Parse a tool bar item specification ITEM for key KEY and return the
7894 result in tool_bar_item_properties. Value is zero if ITEM is
7897 ITEM is a list `(menu-item CAPTION BINDING PROPS...)'.
7899 CAPTION is the caption of the item, If it's not a string, it is
7900 evaluated to get a string.
7902 BINDING is the tool bar item's binding. Tool-bar items with keymaps
7903 as binding are currently ignored.
7905 The following properties are recognized:
7909 FORM is evaluated and specifies whether the tool bar item is
7910 enabled or disabled.
7914 FORM is evaluated and specifies whether the tool bar item is visible.
7916 - `:filter FUNCTION'
7918 FUNCTION is invoked with one parameter `(quote BINDING)'. Its
7919 result is stored as the new binding.
7921 - `:button (TYPE SELECTED)'
7923 TYPE must be one of `:radio' or `:toggle'. SELECTED is evaluated
7924 and specifies whether the button is selected (pressed) or not.
7928 IMAGES is either a single image specification or a vector of four
7929 image specifications. See enum tool_bar_item_images.
7931 - `:help HELP-STRING'.
7933 Gives a help string to display for the tool bar item. */
7936 parse_tool_bar_item (key
, item
)
7937 Lisp_Object key
, item
;
7939 /* Access slot with index IDX of vector tool_bar_item_properties. */
7940 #define PROP(IDX) XVECTOR (tool_bar_item_properties)->contents[IDX]
7942 Lisp_Object filter
= Qnil
;
7943 Lisp_Object caption
;
7946 /* Defininition looks like `(menu-item CAPTION BINDING PROPS...)'.
7947 Rule out items that aren't lists, don't start with
7948 `menu-item' or whose rest following `tool-bar-item' is not a
7951 || !EQ (XCAR (item
), Qmenu_item
)
7952 || (item
= XCDR (item
),
7956 /* Create tool_bar_item_properties vector if necessary. Reset it to
7958 if (VECTORP (tool_bar_item_properties
))
7960 for (i
= 0; i
< TOOL_BAR_ITEM_NSLOTS
; ++i
)
7964 tool_bar_item_properties
7965 = Fmake_vector (make_number (TOOL_BAR_ITEM_NSLOTS
), Qnil
);
7968 PROP (TOOL_BAR_ITEM_KEY
) = key
;
7969 PROP (TOOL_BAR_ITEM_ENABLED_P
) = Qt
;
7971 /* Get the caption of the item. If the caption is not a string,
7972 evaluate it to get a string. If we don't get a string, skip this
7974 caption
= XCAR (item
);
7975 if (!STRINGP (caption
))
7977 caption
= menu_item_eval_property (caption
);
7978 if (!STRINGP (caption
))
7981 PROP (TOOL_BAR_ITEM_CAPTION
) = caption
;
7983 /* Give up if rest following the caption is not a list. */
7988 /* Store the binding. */
7989 PROP (TOOL_BAR_ITEM_BINDING
) = XCAR (item
);
7992 /* Ignore cached key binding, if any. */
7993 if (CONSP (item
) && CONSP (XCAR (item
)))
7996 /* Process the rest of the properties. */
7997 for (; CONSP (item
) && CONSP (XCDR (item
)); item
= XCDR (XCDR (item
)))
7999 Lisp_Object key
, value
;
8002 value
= XCAR (XCDR (item
));
8004 if (EQ (key
, QCenable
))
8005 /* `:enable FORM'. */
8006 PROP (TOOL_BAR_ITEM_ENABLED_P
) = value
;
8007 else if (EQ (key
, QCvisible
))
8009 /* `:visible FORM'. If got a visible property and that
8010 evaluates to nil then ignore this item. */
8011 if (NILP (menu_item_eval_property (value
)))
8014 else if (EQ (key
, QChelp
))
8015 /* `:help HELP-STRING'. */
8016 PROP (TOOL_BAR_ITEM_HELP
) = value
;
8017 else if (EQ (key
, QCfilter
))
8018 /* ':filter FORM'. */
8020 else if (EQ (key
, QCbutton
) && CONSP (value
))
8022 /* `:button (TYPE . SELECTED)'. */
8023 Lisp_Object type
, selected
;
8025 type
= XCAR (value
);
8026 selected
= XCDR (value
);
8027 if (EQ (type
, QCtoggle
) || EQ (type
, QCradio
))
8029 PROP (TOOL_BAR_ITEM_SELECTED_P
) = selected
;
8030 PROP (TOOL_BAR_ITEM_TYPE
) = type
;
8033 else if (EQ (key
, QCimage
)
8035 || (VECTORP (value
) && XVECTOR (value
)->size
== 4)))
8036 /* Value is either a single image specification or a vector
8037 of 4 such specifications for the different button states. */
8038 PROP (TOOL_BAR_ITEM_IMAGES
) = value
;
8041 /* If got a filter apply it on binding. */
8043 PROP (TOOL_BAR_ITEM_BINDING
)
8044 = menu_item_eval_property (list2 (filter
,
8046 PROP (TOOL_BAR_ITEM_BINDING
))));
8048 /* See if the binding is a keymap. Give up if it is. */
8049 if (CONSP (get_keymap (PROP (TOOL_BAR_ITEM_BINDING
), 0, 1)))
8052 /* Enable or disable selection of item. */
8053 if (!EQ (PROP (TOOL_BAR_ITEM_ENABLED_P
), Qt
))
8054 PROP (TOOL_BAR_ITEM_ENABLED_P
)
8055 = menu_item_eval_property (PROP (TOOL_BAR_ITEM_ENABLED_P
));
8057 /* Handle radio buttons or toggle boxes. */
8058 if (!NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
)))
8059 PROP (TOOL_BAR_ITEM_SELECTED_P
)
8060 = menu_item_eval_property (PROP (TOOL_BAR_ITEM_SELECTED_P
));
8068 /* Initialize tool_bar_items_vector. REUSE, if non-nil, is a vector
8069 that can be reused. */
8072 init_tool_bar_items (reuse
)
8075 if (VECTORP (reuse
))
8076 tool_bar_items_vector
= reuse
;
8078 tool_bar_items_vector
= Fmake_vector (make_number (64), Qnil
);
8079 ntool_bar_items
= 0;
8083 /* Append parsed tool bar item properties from
8084 tool_bar_item_properties */
8087 append_tool_bar_item ()
8089 Lisp_Object
*to
, *from
;
8091 /* Enlarge tool_bar_items_vector if necessary. */
8092 if (ntool_bar_items
+ TOOL_BAR_ITEM_NSLOTS
8093 >= XVECTOR (tool_bar_items_vector
)->size
)
8095 Lisp_Object new_vector
;
8096 int old_size
= XVECTOR (tool_bar_items_vector
)->size
;
8098 new_vector
= Fmake_vector (make_number (2 * old_size
), Qnil
);
8099 bcopy (XVECTOR (tool_bar_items_vector
)->contents
,
8100 XVECTOR (new_vector
)->contents
,
8101 old_size
* sizeof (Lisp_Object
));
8102 tool_bar_items_vector
= new_vector
;
8105 /* Append entries from tool_bar_item_properties to the end of
8106 tool_bar_items_vector. */
8107 to
= XVECTOR (tool_bar_items_vector
)->contents
+ ntool_bar_items
;
8108 from
= XVECTOR (tool_bar_item_properties
)->contents
;
8109 bcopy (from
, to
, TOOL_BAR_ITEM_NSLOTS
* sizeof *to
);
8110 ntool_bar_items
+= TOOL_BAR_ITEM_NSLOTS
;
8117 /* Read a character using menus based on maps in the array MAPS.
8118 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
8119 Return t if we displayed a menu but the user rejected it.
8121 PREV_EVENT is the previous input event, or nil if we are reading
8122 the first event of a key sequence.
8124 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
8125 if we used a mouse menu to read the input, or zero otherwise. If
8126 USED_MOUSE_MENU is null, we don't dereference it.
8128 The prompting is done based on the prompt-string of the map
8129 and the strings associated with various map elements.
8131 This can be done with X menus or with menus put in the minibuf.
8132 These are done in different ways, depending on how the input will be read.
8133 Menus using X are done after auto-saving in read-char, getting the input
8134 event from Fx_popup_menu; menus using the minibuf use read_char recursively
8135 and do auto-saving in the inner call of read_char. */
8138 read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
8141 Lisp_Object prev_event
;
8142 int *used_mouse_menu
;
8145 register Lisp_Object name
= Qnil
;
8147 if (used_mouse_menu
)
8148 *used_mouse_menu
= 0;
8150 /* Use local over global Menu maps */
8152 if (! menu_prompting
)
8155 /* Optionally disregard all but the global map. */
8156 if (inhibit_local_menu_bar_menus
)
8158 maps
+= (nmaps
- 1);
8162 /* Get the menu name from the first map that has one (a prompt string). */
8163 for (mapno
= 0; mapno
< nmaps
; mapno
++)
8165 name
= Fkeymap_prompt (maps
[mapno
]);
8170 /* If we don't have any menus, just read a character normally. */
8171 if (!STRINGP (name
))
8175 /* If we got to this point via a mouse click,
8176 use a real menu for mouse selection. */
8177 if (EVENT_HAS_PARAMETERS (prev_event
)
8178 && !EQ (XCAR (prev_event
), Qmenu_bar
)
8179 && !EQ (XCAR (prev_event
), Qtool_bar
))
8181 /* Display the menu and get the selection. */
8182 Lisp_Object
*realmaps
8183 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
8187 /* Use the maps that are not nil. */
8188 for (mapno
= 0; mapno
< nmaps
; mapno
++)
8189 if (!NILP (maps
[mapno
]))
8190 realmaps
[nmaps1
++] = maps
[mapno
];
8192 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
8197 record_menu_key (XCAR (value
));
8199 /* If we got multiple events, unread all but
8201 There is no way to prevent those unread events
8202 from showing up later in last_nonmenu_event.
8203 So turn symbol and integer events into lists,
8204 to indicate that they came from a mouse menu,
8205 so that when present in last_nonmenu_event
8206 they won't confuse things. */
8207 for (tem
= XCDR (value
); !NILP (tem
); tem
= XCDR (tem
))
8209 record_menu_key (XCAR (tem
));
8210 if (SYMBOLP (XCAR (tem
))
8211 || INTEGERP (XCAR (tem
)))
8212 XSETCAR (tem
, Fcons (XCAR (tem
), Qdisabled
));
8215 /* If we got more than one event, put all but the first
8216 onto this list to be read later.
8217 Return just the first event now. */
8218 Vunread_command_events
8219 = nconc2 (XCDR (value
), Vunread_command_events
);
8220 value
= XCAR (value
);
8222 else if (NILP (value
))
8224 if (used_mouse_menu
)
8225 *used_mouse_menu
= 1;
8228 #endif /* HAVE_MENUS */
8232 /* Buffer in use so far for the minibuf prompts for menu keymaps.
8233 We make this bigger when necessary, and never free it. */
8234 static char *read_char_minibuf_menu_text
;
8235 /* Size of that buffer. */
8236 static int read_char_minibuf_menu_width
;
8239 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
8245 register Lisp_Object name
;
8247 /* FIXME: Use the minibuffer's frame width. */
8248 int width
= FRAME_COLS (SELECTED_FRAME ()) - 4;
8251 Lisp_Object rest
, vector
;
8257 if (! menu_prompting
)
8260 /* Make sure we have a big enough buffer for the menu text. */
8261 if (read_char_minibuf_menu_text
== 0)
8263 read_char_minibuf_menu_width
= width
+ 4;
8264 read_char_minibuf_menu_text
= (char *) xmalloc (width
+ 4);
8266 else if (width
+ 4 > read_char_minibuf_menu_width
)
8268 read_char_minibuf_menu_width
= width
+ 4;
8269 read_char_minibuf_menu_text
8270 = (char *) xrealloc (read_char_minibuf_menu_text
, width
+ 4);
8272 menu
= read_char_minibuf_menu_text
;
8274 /* Get the menu name from the first map that has one (a prompt string). */
8275 for (mapno
= 0; mapno
< nmaps
; mapno
++)
8277 name
= Fkeymap_prompt (maps
[mapno
]);
8282 /* If we don't have any menus, just read a character normally. */
8283 if (!STRINGP (name
))
8286 /* Prompt string always starts with map's prompt, and a space. */
8287 strcpy (menu
, SDATA (name
));
8288 nlength
= SBYTES (name
);
8289 menu
[nlength
++] = ':';
8290 menu
[nlength
++] = ' ';
8293 /* Start prompting at start of first map. */
8297 /* Present the documented bindings, a line at a time. */
8304 Lisp_Object orig_defn_macro
;
8306 /* Loop over elements of map. */
8311 /* If reached end of map, start at beginning of next map. */
8315 /* At end of last map, wrap around to first map if just starting,
8316 or end this line if already have something on it. */
8320 if (notfirst
|| nobindings
) break;
8325 /* Look at the next element of the map. */
8327 elt
= XVECTOR (vector
)->contents
[idx
];
8329 elt
= Fcar_safe (rest
);
8331 if (idx
< 0 && VECTORP (elt
))
8333 /* If we found a dense table in the keymap,
8334 advanced past it, but start scanning its contents. */
8335 rest
= Fcdr_safe (rest
);
8341 /* An ordinary element. */
8342 Lisp_Object event
, tem
;
8346 event
= Fcar_safe (elt
); /* alist */
8347 elt
= Fcdr_safe (elt
);
8351 XSETINT (event
, idx
); /* vector */
8354 /* Ignore the element if it has no prompt string. */
8355 if (INTEGERP (event
) && parse_menu_item (elt
, 0, -1))
8357 /* 1 if the char to type matches the string. */
8359 Lisp_Object upcased_event
, downcased_event
;
8360 Lisp_Object desc
= Qnil
;
8362 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
8364 upcased_event
= Fupcase (event
);
8365 downcased_event
= Fdowncase (event
);
8366 char_matches
= (XINT (upcased_event
) == SREF (s
, 0)
8367 || XINT (downcased_event
) == SREF (s
, 0));
8369 desc
= Fsingle_key_description (event
, Qnil
);
8371 #if 0 /* It is redundant to list the equivalent key bindings because
8372 the prefix is what the user has already typed. */
8374 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
8376 /* Insert equivalent keybinding. */
8377 s
= concat2 (s
, tem
);
8380 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_TYPE
];
8381 if (EQ (tem
, QCradio
) || EQ (tem
, QCtoggle
))
8383 /* Insert button prefix. */
8384 Lisp_Object selected
8385 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
];
8386 if (EQ (tem
, QCradio
))
8387 tem
= build_string (NILP (selected
) ? "(*) " : "( ) ");
8389 tem
= build_string (NILP (selected
) ? "[X] " : "[ ] ");
8390 s
= concat2 (tem
, s
);
8394 /* If we have room for the prompt string, add it to this line.
8395 If this is the first on the line, always add it. */
8396 if ((SCHARS (s
) + i
+ 2
8397 + (char_matches
? 0 : SCHARS (desc
) + 3))
8403 /* Punctuate between strings. */
8406 strcpy (menu
+ i
, ", ");
8412 /* If the char to type doesn't match the string's
8413 first char, explicitly show what char to type. */
8416 /* Add as much of string as fits. */
8417 thiswidth
= SCHARS (desc
);
8418 if (thiswidth
+ i
> width
)
8419 thiswidth
= width
- i
;
8420 bcopy (SDATA (desc
), menu
+ i
, thiswidth
);
8422 strcpy (menu
+ i
, " = ");
8426 /* Add as much of string as fits. */
8427 thiswidth
= SCHARS (s
);
8428 if (thiswidth
+ i
> width
)
8429 thiswidth
= width
- i
;
8430 bcopy (SDATA (s
), menu
+ i
, thiswidth
);
8436 /* If this element does not fit, end the line now,
8437 and save the element for the next line. */
8438 strcpy (menu
+ i
, "...");
8443 /* Move past this element. */
8444 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
8445 /* Handle reaching end of dense table. */
8450 rest
= Fcdr_safe (rest
);
8454 /* Prompt with that and read response. */
8455 message2_nolog (menu
, strlen (menu
),
8456 ! NILP (current_buffer
->enable_multibyte_characters
));
8458 /* Make believe its not a keyboard macro in case the help char
8459 is pressed. Help characters are not recorded because menu prompting
8460 is not used on replay.
8462 orig_defn_macro
= current_kboard
->defining_kbd_macro
;
8463 current_kboard
->defining_kbd_macro
= Qnil
;
8465 obj
= read_char (commandflag
, 0, 0, Qt
, 0);
8466 while (BUFFERP (obj
));
8467 current_kboard
->defining_kbd_macro
= orig_defn_macro
;
8469 if (!INTEGERP (obj
))
8474 if (! EQ (obj
, menu_prompt_more_char
)
8475 && (!INTEGERP (menu_prompt_more_char
)
8476 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
8478 if (!NILP (current_kboard
->defining_kbd_macro
))
8479 store_kbd_macro_char (obj
);
8482 /* Help char - go round again */
8486 /* Reading key sequences. */
8488 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
8489 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
8490 keymap, or nil otherwise. Return the index of the first keymap in
8491 which KEY has any binding, or NMAPS if no map has a binding.
8493 If KEY is a meta ASCII character, treat it like meta-prefix-char
8494 followed by the corresponding non-meta character. Keymaps in
8495 CURRENT with non-prefix bindings for meta-prefix-char become nil in
8498 If KEY has no bindings in any of the CURRENT maps, NEXT is left
8501 NEXT may be the same array as CURRENT. */
8504 follow_key (key
, nmaps
, current
, defs
, next
)
8506 Lisp_Object
*current
, *defs
, *next
;
8509 int i
, first_binding
;
8511 first_binding
= nmaps
;
8512 for (i
= nmaps
- 1; i
>= 0; i
--)
8514 if (! NILP (current
[i
]))
8516 defs
[i
] = access_keymap (current
[i
], key
, 1, 0, 1);
8517 if (! NILP (defs
[i
]))
8524 /* Given the set of bindings we've found, produce the next set of maps. */
8525 if (first_binding
< nmaps
)
8526 for (i
= 0; i
< nmaps
; i
++)
8527 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap (defs
[i
], 0, 1);
8529 return first_binding
;
8532 /* Structure used to keep track of partial application of key remapping
8533 such as Vfunction_key_map and Vkey_translation_map. */
8534 typedef struct keyremap
8536 Lisp_Object map
, parent
;
8540 /* Lookup KEY in MAP.
8541 MAP is a keymap mapping keys to key vectors or functions.
8542 If the mapping is a function and DO_FUNCTION is non-zero, then
8543 the function is called with PROMPT as parameter and its return
8544 value is used as the return value of this function (after checking
8545 that it is indeed a vector). */
8548 access_keymap_keyremap (map
, key
, prompt
, do_funcall
)
8549 Lisp_Object map
, key
, prompt
;
8554 next
= access_keymap (map
, key
, 1, 0, 1);
8556 /* Handle symbol with autoload definition. */
8557 if (SYMBOLP (next
) && !NILP (Ffboundp (next
))
8558 && CONSP (XSYMBOL (next
)->function
)
8559 && EQ (XCAR (XSYMBOL (next
)->function
), Qautoload
))
8560 do_autoload (XSYMBOL (next
)->function
, next
);
8562 /* Handle a symbol whose function definition is a keymap
8564 if (SYMBOLP (next
) && !NILP (Ffboundp (next
))
8565 && (!NILP (Farrayp (XSYMBOL (next
)->function
))
8566 || KEYMAPP (XSYMBOL (next
)->function
)))
8567 next
= XSYMBOL (next
)->function
;
8569 /* If the keymap gives a function, not an
8570 array, then call the function with one arg and use
8571 its value instead. */
8572 if (SYMBOLP (next
) && !NILP (Ffboundp (next
)) && do_funcall
)
8577 next
= call1 (next
, prompt
);
8578 /* If the function returned something invalid,
8579 barf--don't ignore it.
8580 (To ignore it safely, we would need to gcpro a bunch of
8581 other variables.) */
8582 if (! (VECTORP (next
) || STRINGP (next
)))
8583 error ("Function %s returns invalid key sequence", tem
);
8588 /* Do one step of the key remapping used for function-key-map and
8589 key-translation-map:
8590 KEYBUF is the buffer holding the input events.
8591 BUFSIZE is its maximum size.
8592 FKEY is a pointer to the keyremap structure to use.
8593 INPUT is the index of the last element in KEYBUF.
8594 DOIT if non-zero says that the remapping can actually take place.
8595 DIFF is used to return the number of keys added/removed by the remapping.
8596 PARENT is the root of the keymap.
8597 PROMPT is the prompt to use if the remapping happens through a function.
8598 The return value is non-zero if the remapping actually took place. */
8601 keyremap_step (keybuf
, bufsize
, fkey
, input
, doit
, diff
, prompt
)
8602 Lisp_Object
*keybuf
, prompt
;
8604 int input
, doit
, *diff
, bufsize
;
8606 Lisp_Object next
, key
;
8608 key
= keybuf
[fkey
->end
++];
8609 next
= access_keymap_keyremap (fkey
->map
, key
, prompt
, doit
);
8611 /* If keybuf[fkey->start..fkey->end] is bound in the
8612 map and we're in a position to do the key remapping, replace it with
8613 the binding and restart with fkey->start at the end. */
8614 if ((VECTORP (next
) || STRINGP (next
)) && doit
)
8616 int len
= XFASTINT (Flength (next
));
8619 *diff
= len
- (fkey
->end
- fkey
->start
);
8621 if (input
+ *diff
>= bufsize
)
8622 error ("Key sequence too long");
8624 /* Shift the keys that follow fkey->end. */
8626 for (i
= fkey
->end
; i
< input
; i
++)
8627 keybuf
[i
+ *diff
] = keybuf
[i
];
8629 for (i
= input
- 1; i
>= fkey
->end
; i
--)
8630 keybuf
[i
+ *diff
] = keybuf
[i
];
8631 /* Overwrite the old keys with the new ones. */
8632 for (i
= 0; i
< len
; i
++)
8633 keybuf
[fkey
->start
+ i
]
8634 = Faref (next
, make_number (i
));
8636 fkey
->start
= fkey
->end
+= *diff
;
8637 fkey
->map
= fkey
->parent
;
8642 fkey
->map
= get_keymap (next
, 0, 1);
8644 /* If we no longer have a bound suffix, try a new position for
8646 if (!CONSP (fkey
->map
))
8648 fkey
->end
= ++fkey
->start
;
8649 fkey
->map
= fkey
->parent
;
8654 /* Read a sequence of keys that ends with a non prefix character,
8655 storing it in KEYBUF, a buffer of size BUFSIZE.
8657 Return the length of the key sequence stored.
8658 Return -1 if the user rejected a command menu.
8660 Echo starting immediately unless `prompt' is 0.
8662 Where a key sequence ends depends on the currently active keymaps.
8663 These include any minor mode keymaps active in the current buffer,
8664 the current buffer's local map, and the global map.
8666 If a key sequence has no other bindings, we check Vfunction_key_map
8667 to see if some trailing subsequence might be the beginning of a
8668 function key's sequence. If so, we try to read the whole function
8669 key, and substitute its symbolic name into the key sequence.
8671 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
8672 `double-' events into similar click events, if that would make them
8673 bound. We try to turn `triple-' events first into `double-' events,
8676 If we get a mouse click in a mode line, vertical divider, or other
8677 non-text area, we treat the click as if it were prefixed by the
8678 symbol denoting that area - `mode-line', `vertical-line', or
8681 If the sequence starts with a mouse click, we read the key sequence
8682 with respect to the buffer clicked on, not the current buffer.
8684 If the user switches frames in the midst of a key sequence, we put
8685 off the switch-frame event until later; the next call to
8686 read_char will return it.
8688 If FIX_CURRENT_BUFFER is nonzero, we restore current_buffer
8689 from the selected window's buffer. */
8692 read_key_sequence (keybuf
, bufsize
, prompt
, dont_downcase_last
,
8693 can_return_switch_frame
, fix_current_buffer
)
8694 Lisp_Object
*keybuf
;
8697 int dont_downcase_last
;
8698 int can_return_switch_frame
;
8699 int fix_current_buffer
;
8701 volatile Lisp_Object from_string
;
8702 volatile int count
= SPECPDL_INDEX ();
8704 /* How many keys there are in the current key sequence. */
8707 /* The length of the echo buffer when we started reading, and
8708 the length of this_command_keys when we started reading. */
8709 volatile int echo_start
;
8710 volatile int keys_start
;
8712 /* The number of keymaps we're scanning right now, and the number of
8713 keymaps we have allocated space for. */
8715 volatile int nmaps_allocated
= 0;
8717 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
8718 the current keymaps. */
8719 Lisp_Object
*volatile defs
= NULL
;
8721 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
8722 in the current keymaps, or nil where it is not a prefix. */
8723 Lisp_Object
*volatile submaps
= NULL
;
8725 /* The local map to start out with at start of key sequence. */
8726 volatile Lisp_Object orig_local_map
;
8728 /* The map from the `keymap' property to start out with at start of
8730 volatile Lisp_Object orig_keymap
;
8732 /* 1 if we have already considered switching to the local-map property
8733 of the place where a mouse click occurred. */
8734 volatile int localized_local_map
= 0;
8736 /* The index in defs[] of the first keymap that has a binding for
8737 this key sequence. In other words, the lowest i such that
8738 defs[i] is non-nil. */
8739 volatile int first_binding
;
8740 /* Index of the first key that has no binding.
8741 It is useless to try fkey.start larger than that. */
8742 volatile int first_unbound
;
8744 /* If t < mock_input, then KEYBUF[t] should be read as the next
8747 We use this to recover after recognizing a function key. Once we
8748 realize that a suffix of the current key sequence is actually a
8749 function key's escape sequence, we replace the suffix with the
8750 function key's binding from Vfunction_key_map. Now keybuf
8751 contains a new and different key sequence, so the echo area,
8752 this_command_keys, and the submaps and defs arrays are wrong. In
8753 this situation, we set mock_input to t, set t to 0, and jump to
8754 restart_sequence; the loop will read keys from keybuf up until
8755 mock_input, thus rebuilding the state; and then it will resume
8756 reading characters from the keyboard. */
8757 volatile int mock_input
= 0;
8759 /* If the sequence is unbound in submaps[], then
8760 keybuf[fkey.start..fkey.end-1] is a prefix in Vfunction_key_map,
8761 and fkey.map is its binding.
8763 These might be > t, indicating that all function key scanning
8764 should hold off until t reaches them. We do this when we've just
8765 recognized a function key, to avoid searching for the function
8766 key's again in Vfunction_key_map. */
8767 volatile keyremap fkey
;
8769 /* Likewise, for key_translation_map. */
8770 volatile keyremap keytran
;
8772 /* If we receive a `switch-frame' or `select-window' event in the middle of
8773 a key sequence, we put it off for later.
8774 While we're reading, we keep the event here. */
8775 volatile Lisp_Object delayed_switch_frame
;
8777 /* See the comment below... */
8778 #if defined (GOBBLE_FIRST_EVENT)
8779 Lisp_Object first_event
;
8782 volatile Lisp_Object original_uppercase
;
8783 volatile int original_uppercase_position
= -1;
8785 /* Gets around Microsoft compiler limitations. */
8788 struct buffer
*starting_buffer
;
8790 /* List of events for which a fake prefix key has been generated. */
8791 volatile Lisp_Object fake_prefixed_keys
= Qnil
;
8793 #if defined (GOBBLE_FIRST_EVENT)
8797 jmp_buf *volatile wrong_kboard_jmpbuf
= alloca (sizeof (jmp_buf));
8799 struct gcpro gcpro1
;
8801 GCPRO1 (fake_prefixed_keys
);
8802 raw_keybuf_count
= 0;
8804 last_nonmenu_event
= Qnil
;
8806 delayed_switch_frame
= Qnil
;
8811 echo_prompt (prompt
);
8812 else if (cursor_in_echo_area
8813 && (FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
8814 && NILP (Fzerop (Vecho_keystrokes
)))
8815 /* This doesn't put in a dash if the echo buffer is empty, so
8816 you don't always see a dash hanging out in the minibuffer. */
8820 /* Record the initial state of the echo area and this_command_keys;
8821 we will need to restore them if we replay a key sequence. */
8823 echo_start
= echo_length ();
8824 keys_start
= this_command_key_count
;
8825 this_single_command_key_start
= keys_start
;
8827 #if defined (GOBBLE_FIRST_EVENT)
8828 /* This doesn't quite work, because some of the things that read_char
8829 does cannot safely be bypassed. It seems too risky to try to make
8832 /* Read the first char of the sequence specially, before setting
8833 up any keymaps, in case a filter runs and switches buffers on us. */
8834 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
8836 #endif /* GOBBLE_FIRST_EVENT */
8838 orig_local_map
= get_local_map (PT
, current_buffer
, Qlocal_map
);
8839 orig_keymap
= get_local_map (PT
, current_buffer
, Qkeymap
);
8842 /* We jump here when the key sequence has been thoroughly changed, and
8843 we need to rescan it starting from the beginning. When we jump here,
8844 keybuf[0..mock_input] holds the sequence we should reread. */
8847 /* We may switch keyboards between rescans, so we need to
8848 reinitialize fkey and keytran before each replay. */
8849 fkey
.map
= fkey
.parent
= current_kboard
->Vlocal_function_key_map
;
8850 keytran
.map
= keytran
.parent
= current_kboard
->Vlocal_key_translation_map
;
8851 /* If there is no translation map, turn off scanning. */
8852 fkey
.start
= fkey
.end
= KEYMAPP (fkey
.map
) ? 0 : bufsize
+ 1;
8853 keytran
.start
= keytran
.end
= KEYMAPP (keytran
.map
) ? 0 : bufsize
+ 1;
8855 starting_buffer
= current_buffer
;
8856 first_unbound
= bufsize
+ 1;
8858 /* Build our list of keymaps.
8859 If we recognize a function key and replace its escape sequence in
8860 keybuf with its symbol, or if the sequence starts with a mouse
8861 click and we need to switch buffers, we jump back here to rebuild
8862 the initial keymaps from the current buffer. */
8865 if (!NILP (current_kboard
->Voverriding_terminal_local_map
)
8866 || !NILP (Voverriding_local_map
))
8868 if (3 > nmaps_allocated
)
8870 submaps
= (Lisp_Object
*) alloca (3 * sizeof (submaps
[0]));
8871 defs
= (Lisp_Object
*) alloca (3 * sizeof (defs
[0]));
8872 nmaps_allocated
= 3;
8874 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
8875 submaps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
8876 if (!NILP (Voverriding_local_map
))
8877 submaps
[nmaps
++] = Voverriding_local_map
;
8885 nminor
= current_minor_maps (0, &maps
);
8886 total
= nminor
+ (!NILP (orig_keymap
) ? 3 : 2);
8888 if (total
> nmaps_allocated
)
8890 submaps
= (Lisp_Object
*) alloca (total
* sizeof (submaps
[0]));
8891 defs
= (Lisp_Object
*) alloca (total
* sizeof (defs
[0]));
8892 nmaps_allocated
= total
;
8895 if (!NILP (orig_keymap
))
8896 submaps
[nmaps
++] = orig_keymap
;
8898 bcopy (maps
, (void *) (submaps
+ nmaps
),
8899 nminor
* sizeof (submaps
[0]));
8903 submaps
[nmaps
++] = orig_local_map
;
8905 submaps
[nmaps
++] = current_global_map
;
8907 /* Find an accurate initial value for first_binding. */
8908 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
8909 if (! NILP (submaps
[first_binding
]))
8912 /* Start from the beginning in keybuf. */
8915 /* These are no-ops the first time through, but if we restart, they
8916 revert the echo area and this_command_keys to their original state. */
8917 this_command_key_count
= keys_start
;
8918 if (INTERACTIVE
&& t
< mock_input
)
8919 echo_truncate (echo_start
);
8921 /* If the best binding for the current key sequence is a keymap, or
8922 we may be looking at a function key's escape sequence, keep on
8924 while (first_binding
< nmaps
8925 /* Keep reading as long as there's a prefix binding. */
8926 ? !NILP (submaps
[first_binding
])
8927 /* Don't return in the middle of a possible function key sequence,
8928 if the only bindings we found were via case conversion.
8929 Thus, if ESC O a has a function-key-map translation
8930 and ESC o has a binding, don't return after ESC O,
8931 so that we can translate ESC O plus the next character. */
8932 : (fkey
.start
< t
|| keytran
.start
< t
))
8935 int used_mouse_menu
= 0;
8937 /* Where the last real key started. If we need to throw away a
8938 key that has expanded into more than one element of keybuf
8939 (say, a mouse click on the mode line which is being treated
8940 as [mode-line (mouse-...)], then we backtrack to this point
8942 volatile int last_real_key_start
;
8944 /* These variables are analogous to echo_start and keys_start;
8945 while those allow us to restart the entire key sequence,
8946 echo_local_start and keys_local_start allow us to throw away
8948 volatile int echo_local_start
, keys_local_start
, local_first_binding
;
8950 eassert (fkey
.end
== t
|| (fkey
.end
> t
&& fkey
.end
<= mock_input
));
8951 eassert (fkey
.start
<= fkey
.end
);
8952 eassert (keytran
.start
<= keytran
.end
);
8953 /* key-translation-map is applied *after* function-key-map. */
8954 eassert (keytran
.end
<= fkey
.start
);
8956 if (first_unbound
< fkey
.start
&& first_unbound
< keytran
.start
)
8957 { /* The prefix upto first_unbound has no binding and has
8958 no translation left to do either, so we know it's unbound.
8959 If we don't stop now, we risk staying here indefinitely
8960 (if the user keeps entering fkey or keytran prefixes
8961 like C-c ESC ESC ESC ESC ...) */
8963 for (i
= first_unbound
+ 1; i
< t
; i
++)
8964 keybuf
[i
- first_unbound
- 1] = keybuf
[i
];
8965 mock_input
= t
- first_unbound
- 1;
8966 fkey
.end
= fkey
.start
-= first_unbound
+ 1;
8967 fkey
.map
= fkey
.parent
;
8968 keytran
.end
= keytran
.start
-= first_unbound
+ 1;
8969 keytran
.map
= keytran
.parent
;
8970 goto replay_sequence
;
8974 error ("Key sequence too long");
8977 echo_local_start
= echo_length ();
8978 keys_local_start
= this_command_key_count
;
8979 local_first_binding
= first_binding
;
8982 /* These are no-ops, unless we throw away a keystroke below and
8983 jumped back up to replay_key; in that case, these restore the
8984 variables to their original state, allowing us to replay the
8986 if (INTERACTIVE
&& t
< mock_input
)
8987 echo_truncate (echo_local_start
);
8988 this_command_key_count
= keys_local_start
;
8989 first_binding
= local_first_binding
;
8991 /* By default, assume each event is "real". */
8992 last_real_key_start
= t
;
8994 /* Does mock_input indicate that we are re-reading a key sequence? */
8998 add_command_key (key
);
8999 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
9000 && NILP (Fzerop (Vecho_keystrokes
)))
9004 /* If not, we should actually read a character. */
9009 KBOARD
*interrupted_kboard
= current_kboard
;
9010 struct frame
*interrupted_frame
= SELECTED_FRAME ();
9011 if (setjmp (*wrong_kboard_jmpbuf
))
9016 for (k
= all_kboards
; k
; k
= k
->next_kboard
)
9017 if (k
== interrupted_kboard
)
9022 if (!NILP (delayed_switch_frame
))
9024 interrupted_kboard
->kbd_queue
9025 = Fcons (delayed_switch_frame
,
9026 interrupted_kboard
->kbd_queue
);
9027 delayed_switch_frame
= Qnil
;
9030 interrupted_kboard
->kbd_queue
9031 = Fcons (keybuf
[--t
], interrupted_kboard
->kbd_queue
);
9033 /* If the side queue is non-empty, ensure it begins with a
9034 switch-frame, so we'll replay it in the right context. */
9035 if (CONSP (interrupted_kboard
->kbd_queue
)
9036 && (key
= XCAR (interrupted_kboard
->kbd_queue
),
9037 !(EVENT_HAS_PARAMETERS (key
)
9038 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)),
9042 XSETFRAME (frame
, interrupted_frame
);
9043 interrupted_kboard
->kbd_queue
9044 = Fcons (make_lispy_switch_frame (frame
),
9045 interrupted_kboard
->kbd_queue
);
9048 orig_local_map
= get_local_map (PT
, current_buffer
, Qlocal_map
);
9049 orig_keymap
= get_local_map (PT
, current_buffer
, Qkeymap
);
9050 goto replay_sequence
;
9053 key
= read_char (NILP (prompt
), nmaps
,
9054 (Lisp_Object
*) submaps
, last_nonmenu_event
,
9055 &used_mouse_menu
, wrong_kboard_jmpbuf
);
9058 /* read_char returns t when it shows a menu and the user rejects it.
9062 unbind_to (count
, Qnil
);
9067 /* read_char returns -1 at the end of a macro.
9068 Emacs 18 handles this by returning immediately with a
9069 zero, so that's what we'll do. */
9070 if (INTEGERP (key
) && XINT (key
) == -1)
9073 /* The Microsoft C compiler can't handle the goto that
9079 /* If the current buffer has been changed from under us, the
9080 keymap may have changed, so replay the sequence. */
9083 timer_resume_idle ();
9086 /* Reset the current buffer from the selected window
9087 in case something changed the former and not the latter.
9088 This is to be more consistent with the behavior
9089 of the command_loop_1. */
9090 if (fix_current_buffer
)
9092 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
9094 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
9095 Fset_buffer (XWINDOW (selected_window
)->buffer
);
9098 orig_local_map
= get_local_map (PT
, current_buffer
, Qlocal_map
);
9099 orig_keymap
= get_local_map (PT
, current_buffer
, Qkeymap
);
9100 goto replay_sequence
;
9103 /* If we have a quit that was typed in another frame, and
9104 quit_throw_to_read_char switched buffers,
9105 replay to get the right keymap. */
9107 && XINT (key
) == quit_char
9108 && current_buffer
!= starting_buffer
)
9111 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
9115 orig_local_map
= get_local_map (PT
, current_buffer
, Qlocal_map
);
9116 orig_keymap
= get_local_map (PT
, current_buffer
, Qkeymap
);
9117 goto replay_sequence
;
9122 if (EVENT_HAS_PARAMETERS (key
)
9123 /* Either a `switch-frame' or a `select-window' event. */
9124 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)), Qswitch_frame
))
9126 /* If we're at the beginning of a key sequence, and the caller
9127 says it's okay, go ahead and return this event. If we're
9128 in the midst of a key sequence, delay it until the end. */
9129 if (t
> 0 || !can_return_switch_frame
)
9131 delayed_switch_frame
= key
;
9137 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
9140 /* Clicks in non-text areas get prefixed by the symbol
9141 in their CHAR-ADDRESS field. For example, a click on
9142 the mode line is prefixed by the symbol `mode-line'.
9144 Furthermore, key sequences beginning with mouse clicks
9145 are read using the keymaps of the buffer clicked on, not
9146 the current buffer. So we may have to switch the buffer
9149 When we turn one event into two events, we must make sure
9150 that neither of the two looks like the original--so that,
9151 if we replay the events, they won't be expanded again.
9152 If not for this, such reexpansion could happen either here
9153 or when user programs play with this-command-keys. */
9154 if (EVENT_HAS_PARAMETERS (key
))
9159 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
9160 if (EQ (kind
, Qmouse_click
))
9162 Lisp_Object window
, posn
;
9164 window
= POSN_WINDOW (EVENT_START (key
));
9165 posn
= POSN_POSN (EVENT_START (key
));
9168 || (!NILP (fake_prefixed_keys
)
9169 && !NILP (Fmemq (key
, fake_prefixed_keys
))))
9171 /* We're looking a second time at an event for which
9172 we generated a fake prefix key. Set
9173 last_real_key_start appropriately. */
9175 last_real_key_start
= t
- 1;
9178 /* Key sequences beginning with mouse clicks are
9179 read using the keymaps in the buffer clicked on,
9180 not the current buffer. If we're at the
9181 beginning of a key sequence, switch buffers. */
9182 if (last_real_key_start
== 0
9184 && BUFFERP (XWINDOW (window
)->buffer
)
9185 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
9187 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
9191 /* Arrange to go back to the original buffer once we're
9192 done reading the key sequence. Note that we can't
9193 use save_excursion_{save,restore} here, because they
9194 save point as well as the current buffer; we don't
9195 want to save point, because redisplay may change it,
9196 to accommodate a Fset_window_start or something. We
9197 don't want to do this at the top of the function,
9198 because we may get input from a subprocess which
9199 wants to change the selected window and stuff (say,
9201 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
9203 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
9205 set_buffer_internal (XBUFFER (XWINDOW (window
)->buffer
));
9206 orig_local_map
= get_local_map (PT
, current_buffer
,
9208 orig_keymap
= get_local_map (PT
, current_buffer
, Qkeymap
);
9209 goto replay_sequence
;
9212 /* For a mouse click, get the local text-property keymap
9213 of the place clicked on, rather than point. */
9214 if (last_real_key_start
== 0
9215 && CONSP (XCDR (key
))
9216 && ! localized_local_map
)
9218 Lisp_Object map_here
, start
, pos
;
9220 localized_local_map
= 1;
9221 start
= EVENT_START (key
);
9223 if (CONSP (start
) && POSN_INBUFFER_P (start
))
9225 pos
= POSN_BUFFER_POSN (start
);
9227 && XINT (pos
) >= BEG
&& XINT (pos
) <= Z
)
9229 map_here
= get_local_map (XINT (pos
),
9230 current_buffer
, Qlocal_map
);
9231 if (!EQ (map_here
, orig_local_map
))
9233 orig_local_map
= map_here
;
9237 goto replay_sequence
;
9239 map_here
= get_local_map (XINT (pos
),
9240 current_buffer
, Qkeymap
);
9241 if (!EQ (map_here
, orig_keymap
))
9243 orig_keymap
= map_here
;
9247 goto replay_sequence
;
9253 /* Expand mode-line and scroll-bar events into two events:
9254 use posn as a fake prefix key. */
9256 && (NILP (fake_prefixed_keys
)
9257 || NILP (Fmemq (key
, fake_prefixed_keys
))))
9259 if (t
+ 1 >= bufsize
)
9260 error ("Key sequence too long");
9263 keybuf
[t
+ 1] = key
;
9266 /* Record that a fake prefix key has been generated
9267 for KEY. Don't modify the event; this would
9268 prevent proper action when the event is pushed
9269 back into unread-command-events. */
9270 fake_prefixed_keys
= Fcons (key
, fake_prefixed_keys
);
9272 /* If on a mode line string with a local keymap,
9273 reconsider the key sequence with that keymap. */
9274 if (string
= POSN_STRING (EVENT_START (key
)),
9275 (CONSP (string
) && STRINGP (XCAR (string
))))
9277 Lisp_Object pos
, map
, map2
;
9279 pos
= XCDR (string
);
9280 string
= XCAR (string
);
9282 && XINT (pos
) < SCHARS (string
))
9284 map
= Fget_text_property (pos
, Qlocal_map
, string
);
9286 orig_local_map
= map
;
9287 map2
= Fget_text_property (pos
, Qkeymap
, string
);
9290 if (!NILP (map
) || !NILP (map2
))
9291 goto replay_sequence
;
9297 else if (NILP (from_string
)
9298 && (string
= POSN_STRING (EVENT_START (key
)),
9299 (CONSP (string
) && STRINGP (XCAR (string
)))))
9301 /* For a click on a string, i.e. overlay string or a
9302 string displayed via the `display' property,
9303 consider `local-map' and `keymap' properties of
9305 Lisp_Object pos
, map
, map2
;
9307 pos
= XCDR (string
);
9308 string
= XCAR (string
);
9310 && XINT (pos
) < SCHARS (string
))
9312 map
= Fget_text_property (pos
, Qlocal_map
, string
);
9314 orig_local_map
= map
;
9315 map2
= Fget_text_property (pos
, Qkeymap
, string
);
9319 if (!NILP (map
) || !NILP (map2
))
9321 from_string
= string
;
9322 goto replay_sequence
;
9327 else if (CONSP (XCDR (key
))
9328 && CONSP (EVENT_START (key
))
9329 && CONSP (XCDR (EVENT_START (key
))))
9333 posn
= POSN_POSN (EVENT_START (key
));
9334 /* Handle menu-bar events:
9335 insert the dummy prefix event `menu-bar'. */
9336 if (EQ (posn
, Qmenu_bar
) || EQ (posn
, Qtool_bar
))
9338 if (t
+ 1 >= bufsize
)
9339 error ("Key sequence too long");
9343 /* Zap the position in key, so we know that we've
9344 expanded it, and don't try to do so again. */
9345 POSN_SET_POSN (EVENT_START (key
),
9346 Fcons (posn
, Qnil
));
9349 goto replay_sequence
;
9351 else if (CONSP (posn
))
9353 /* We're looking at the second event of a
9354 sequence which we expanded before. Set
9355 last_real_key_start appropriately. */
9356 if (last_real_key_start
== t
&& t
> 0)
9357 last_real_key_start
= t
- 1;
9362 /* We have finally decided that KEY is something we might want
9364 first_binding
= (follow_key (key
,
9365 nmaps
- first_binding
,
9366 submaps
+ first_binding
,
9367 defs
+ first_binding
,
9368 submaps
+ first_binding
)
9371 /* If KEY wasn't bound, we'll try some fallbacks. */
9372 if (first_binding
< nmaps
)
9373 /* This is needed for the following scenario:
9374 event 0: a down-event that gets dropped by calling replay_key.
9375 event 1: some normal prefix like C-h.
9376 After event 0, first_unbound is 0, after event 1 fkey.start
9377 and keytran.start are both 1, so when we see that C-h is bound,
9378 we need to update first_unbound. */
9379 first_unbound
= max (t
+ 1, first_unbound
);
9384 /* Remember the position to put an upper bound on fkey.start. */
9385 first_unbound
= min (t
, first_unbound
);
9387 head
= EVENT_HEAD (key
);
9388 if (help_char_p (head
) && t
> 0)
9390 read_key_sequence_cmd
= Vprefix_help_command
;
9392 last_nonmenu_event
= key
;
9393 /* The Microsoft C compiler can't handle the goto that
9401 Lisp_Object breakdown
;
9404 breakdown
= parse_modifiers (head
);
9405 modifiers
= XINT (XCAR (XCDR (breakdown
)));
9406 /* Attempt to reduce an unbound mouse event to a simpler
9407 event that is bound:
9408 Drags reduce to clicks.
9409 Double-clicks reduce to clicks.
9410 Triple-clicks reduce to double-clicks, then to clicks.
9411 Down-clicks are eliminated.
9412 Double-downs reduce to downs, then are eliminated.
9413 Triple-downs reduce to double-downs, then to downs,
9414 then are eliminated. */
9415 if (modifiers
& (down_modifier
| drag_modifier
9416 | double_modifier
| triple_modifier
))
9418 while (modifiers
& (down_modifier
| drag_modifier
9419 | double_modifier
| triple_modifier
))
9421 Lisp_Object new_head
, new_click
;
9422 if (modifiers
& triple_modifier
)
9423 modifiers
^= (double_modifier
| triple_modifier
);
9424 else if (modifiers
& double_modifier
)
9425 modifiers
&= ~double_modifier
;
9426 else if (modifiers
& drag_modifier
)
9427 modifiers
&= ~drag_modifier
;
9430 /* Dispose of this `down' event by simply jumping
9431 back to replay_key, to get another event.
9433 Note that if this event came from mock input,
9434 then just jumping back to replay_key will just
9435 hand it to us again. So we have to wipe out any
9438 We could delete keybuf[t] and shift everything
9439 after that to the left by one spot, but we'd also
9440 have to fix up any variable that points into
9441 keybuf, and shifting isn't really necessary
9444 Adding prefixes for non-textual mouse clicks
9445 creates two characters of mock input, and both
9446 must be thrown away. If we're only looking at
9447 the prefix now, we can just jump back to
9448 replay_key. On the other hand, if we've already
9449 processed the prefix, and now the actual click
9450 itself is giving us trouble, then we've lost the
9451 state of the keymaps we want to backtrack to, and
9452 we need to replay the whole sequence to rebuild
9455 Beyond that, only function key expansion could
9456 create more than two keys, but that should never
9457 generate mouse events, so it's okay to zero
9458 mock_input in that case too.
9460 FIXME: The above paragraph seems just plain
9461 wrong, if you consider things like
9462 xterm-mouse-mode. -stef
9464 Isn't this just the most wonderful code ever? */
9466 /* If mock_input > t + 1, the above simplification
9467 will actually end up dropping keys on the floor.
9468 This is probably OK for now, but even
9469 if mock_input <= t + 1, we need to adjust fkey
9471 Typical case [header-line down-mouse-N]:
9472 mock_input = 2, t = 1, fkey.end = 1,
9473 last_real_key_start = 0. */
9474 if (fkey
.end
> last_real_key_start
)
9476 fkey
.end
= fkey
.start
9477 = min (last_real_key_start
, fkey
.start
);
9478 fkey
.map
= fkey
.parent
;
9479 if (keytran
.end
> last_real_key_start
)
9481 keytran
.end
= keytran
.start
9482 = min (last_real_key_start
, keytran
.start
);
9483 keytran
.map
= keytran
.parent
;
9486 if (t
== last_real_key_start
)
9493 mock_input
= last_real_key_start
;
9494 goto replay_sequence
;
9499 = apply_modifiers (modifiers
, XCAR (breakdown
));
9501 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
9503 /* Look for a binding for this new key. follow_key
9504 promises that it didn't munge submaps the
9505 last time we called it, since key was unbound. */
9507 = (follow_key (new_click
,
9508 nmaps
- local_first_binding
,
9509 submaps
+ local_first_binding
,
9510 defs
+ local_first_binding
,
9511 submaps
+ local_first_binding
)
9512 + local_first_binding
);
9514 /* If that click is bound, go for it. */
9515 if (first_binding
< nmaps
)
9520 /* Otherwise, we'll leave key set to the drag event. */
9527 /* Normally, last_nonmenu_event gets the previous key we read.
9528 But when a mouse popup menu is being used,
9529 we don't update last_nonmenu_event; it continues to hold the mouse
9530 event that preceded the first level of menu. */
9531 if (!used_mouse_menu
)
9532 last_nonmenu_event
= key
;
9534 /* Record what part of this_command_keys is the current key sequence. */
9535 this_single_command_key_start
= this_command_key_count
- t
;
9537 if (first_binding
< nmaps
&& NILP (submaps
[first_binding
]))
9538 /* There is a binding and it's not a prefix.
9539 There is thus no function-key in this sequence.
9540 Moving fkey.start is important in this case to allow keytran.start
9541 to go over the sequence before we return (since we keep the
9542 invariant that keytran.end <= fkey.start). */
9545 (fkey
.start
= fkey
.end
= t
, fkey
.map
= fkey
.parent
);
9548 /* If the sequence is unbound, see if we can hang a function key
9549 off the end of it. */
9550 /* Continue scan from fkey.end until we find a bound suffix. */
9551 while (fkey
.end
< t
)
9553 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9556 GCPRO3 (fkey
.map
, keytran
.map
, delayed_switch_frame
);
9557 done
= keyremap_step (keybuf
, bufsize
, &fkey
,
9558 max (t
, mock_input
),
9559 /* If there's a binding (i.e.
9560 first_binding >= nmaps) we don't want
9561 to apply this function-key-mapping. */
9562 fkey
.end
+ 1 == t
&& first_binding
>= nmaps
,
9567 mock_input
= diff
+ max (t
, mock_input
);
9568 goto replay_sequence
;
9572 /* Look for this sequence in key-translation-map.
9573 Scan from keytran.end until we find a bound suffix. */
9574 while (keytran
.end
< fkey
.start
)
9576 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9579 GCPRO3 (fkey
.map
, keytran
.map
, delayed_switch_frame
);
9580 done
= keyremap_step (keybuf
, bufsize
, &keytran
, max (t
, mock_input
),
9585 mock_input
= diff
+ max (t
, mock_input
);
9586 /* Adjust the function-key-map counters. */
9590 goto replay_sequence
;
9594 /* If KEY is not defined in any of the keymaps,
9595 and cannot be part of a function key or translation,
9596 and is an upper case letter
9597 use the corresponding lower-case letter instead. */
9598 if (first_binding
>= nmaps
9599 && fkey
.start
>= t
&& keytran
.start
>= t
9601 && ((((XINT (key
) & 0x3ffff)
9602 < XCHAR_TABLE (current_buffer
->downcase_table
)->size
)
9603 && UPPERCASEP (XINT (key
) & 0x3ffff))
9604 || (XINT (key
) & shift_modifier
)))
9606 Lisp_Object new_key
;
9608 original_uppercase
= key
;
9609 original_uppercase_position
= t
- 1;
9611 if (XINT (key
) & shift_modifier
)
9612 XSETINT (new_key
, XINT (key
) & ~shift_modifier
);
9614 XSETINT (new_key
, (DOWNCASE (XINT (key
) & 0x3ffff)
9615 | (XINT (key
) & ~0x3ffff)));
9617 /* We have to do this unconditionally, regardless of whether
9618 the lower-case char is defined in the keymaps, because they
9619 might get translated through function-key-map. */
9620 keybuf
[t
- 1] = new_key
;
9621 mock_input
= max (t
, mock_input
);
9623 goto replay_sequence
;
9625 /* If KEY is not defined in any of the keymaps,
9626 and cannot be part of a function key or translation,
9627 and is a shifted function key,
9628 use the corresponding unshifted function key instead. */
9629 if (first_binding
>= nmaps
9630 && fkey
.start
>= t
&& keytran
.start
>= t
9633 Lisp_Object breakdown
;
9636 breakdown
= parse_modifiers (key
);
9637 modifiers
= XINT (XCAR (XCDR (breakdown
)));
9638 if (modifiers
& shift_modifier
)
9640 Lisp_Object new_key
;
9642 original_uppercase
= key
;
9643 original_uppercase_position
= t
- 1;
9645 modifiers
&= ~shift_modifier
;
9646 new_key
= apply_modifiers (modifiers
,
9649 keybuf
[t
- 1] = new_key
;
9650 mock_input
= max (t
, mock_input
);
9651 fkey
.start
= fkey
.end
= KEYMAPP (fkey
.map
) ? 0 : bufsize
+ 1;
9652 keytran
.start
= keytran
.end
= KEYMAPP (keytran
.map
) ? 0 : bufsize
+ 1;
9654 goto replay_sequence
;
9660 read_key_sequence_cmd
= (first_binding
< nmaps
9661 ? defs
[first_binding
]
9664 unread_switch_frame
= delayed_switch_frame
;
9665 unbind_to (count
, Qnil
);
9667 /* Don't downcase the last character if the caller says don't.
9668 Don't downcase it if the result is undefined, either. */
9669 if ((dont_downcase_last
|| first_binding
>= nmaps
)
9670 && t
- 1 == original_uppercase_position
)
9671 keybuf
[t
- 1] = original_uppercase
;
9673 /* Occasionally we fabricate events, perhaps by expanding something
9674 according to function-key-map, or by adding a prefix symbol to a
9675 mouse click in the scroll bar or modeline. In this cases, return
9676 the entire generated key sequence, even if we hit an unbound
9677 prefix or a definition before the end. This means that you will
9678 be able to push back the event properly, and also means that
9679 read-key-sequence will always return a logical unit.
9682 for (; t
< mock_input
; t
++)
9684 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
9685 && NILP (Fzerop (Vecho_keystrokes
)))
9686 echo_char (keybuf
[t
]);
9687 add_command_key (keybuf
[t
]);
9696 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 5, 0,
9697 doc
: /* Read a sequence of keystrokes and return as a string or vector.
9698 The sequence is sufficient to specify a non-prefix command in the
9699 current local and global maps.
9701 First arg PROMPT is a prompt string. If nil, do not prompt specially.
9702 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos
9703 as a continuation of the previous key.
9705 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not
9706 convert the last event to lower case. (Normally any upper case event
9707 is converted to lower case if the original event is undefined and the lower
9708 case equivalent is defined.) A non-nil value is appropriate for reading
9709 a key sequence to be defined.
9711 A C-g typed while in this function is treated like any other character,
9712 and `quit-flag' is not set.
9714 If the key sequence starts with a mouse click, then the sequence is read
9715 using the keymaps of the buffer of the window clicked in, not the buffer
9716 of the selected window as normal.
9718 `read-key-sequence' drops unbound button-down events, since you normally
9719 only care about the click or drag events which follow them. If a drag
9720 or multi-click event is unbound, but the corresponding click event would
9721 be bound, `read-key-sequence' turns the event into a click event at the
9722 drag's starting position. This means that you don't have to distinguish
9723 between click and drag, double, or triple events unless you want to.
9725 `read-key-sequence' prefixes mouse events on mode lines, the vertical
9726 lines separating windows, and scroll bars with imaginary keys
9727 `mode-line', `vertical-line', and `vertical-scroll-bar'.
9729 Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this
9730 function will process a switch-frame event if the user switches frames
9731 before typing anything. If the user switches frames in the middle of a
9732 key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME
9733 is nil, then the event will be put off until after the current key sequence.
9735 `read-key-sequence' checks `function-key-map' for function key
9736 sequences, where they wouldn't conflict with ordinary bindings. See
9737 `function-key-map' for more details.
9739 The optional fifth argument COMMAND-LOOP, if non-nil, means
9740 that this key sequence is being read by something that will
9741 read commands one after another. It should be nil if the caller
9742 will read just one key sequence. */)
9743 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
9745 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
9746 Lisp_Object can_return_switch_frame
, command_loop
;
9748 Lisp_Object keybuf
[30];
9750 struct gcpro gcpro1
;
9751 int count
= SPECPDL_INDEX ();
9754 CHECK_STRING (prompt
);
9757 specbind (Qinput_method_exit_on_first_char
,
9758 (NILP (command_loop
) ? Qt
: Qnil
));
9759 specbind (Qinput_method_use_echo_area
,
9760 (NILP (command_loop
) ? Qt
: Qnil
));
9762 bzero (keybuf
, sizeof keybuf
);
9764 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
9766 if (NILP (continue_echo
))
9768 this_command_key_count
= 0;
9769 this_command_key_count_reset
= 0;
9770 this_single_command_key_start
= 0;
9773 #ifdef HAVE_X_WINDOWS
9774 if (display_hourglass_p
)
9775 cancel_hourglass ();
9778 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
9779 prompt
, ! NILP (dont_downcase_last
),
9780 ! NILP (can_return_switch_frame
), 0);
9782 #if 0 /* The following is fine for code reading a key sequence and
9783 then proceeding with a lenghty computation, but it's not good
9784 for code reading keys in a loop, like an input method. */
9785 #ifdef HAVE_X_WINDOWS
9786 if (display_hourglass_p
)
9797 return unbind_to (count
, make_event_array (i
, keybuf
));
9800 DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector
,
9801 Sread_key_sequence_vector
, 1, 5, 0,
9802 doc
: /* Like `read-key-sequence' but always return a vector. */)
9803 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
9805 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
9806 Lisp_Object can_return_switch_frame
, command_loop
;
9808 Lisp_Object keybuf
[30];
9810 struct gcpro gcpro1
;
9811 int count
= SPECPDL_INDEX ();
9814 CHECK_STRING (prompt
);
9817 specbind (Qinput_method_exit_on_first_char
,
9818 (NILP (command_loop
) ? Qt
: Qnil
));
9819 specbind (Qinput_method_use_echo_area
,
9820 (NILP (command_loop
) ? Qt
: Qnil
));
9822 bzero (keybuf
, sizeof keybuf
);
9824 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
9826 if (NILP (continue_echo
))
9828 this_command_key_count
= 0;
9829 this_command_key_count_reset
= 0;
9830 this_single_command_key_start
= 0;
9833 #ifdef HAVE_X_WINDOWS
9834 if (display_hourglass_p
)
9835 cancel_hourglass ();
9838 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
9839 prompt
, ! NILP (dont_downcase_last
),
9840 ! NILP (can_return_switch_frame
), 0);
9842 #ifdef HAVE_X_WINDOWS
9843 if (display_hourglass_p
)
9853 return unbind_to (count
, Fvector (i
, keybuf
));
9856 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 4, 0,
9857 doc
: /* Execute CMD as an editor command.
9858 CMD must be a symbol that satisfies the `commandp' predicate.
9859 Optional second arg RECORD-FLAG non-nil
9860 means unconditionally put this command in `command-history'.
9861 Otherwise, that is done only if an arg is read using the minibuffer.
9862 The argument KEYS specifies the value to use instead of (this-command-keys)
9863 when reading the arguments; if it is nil, (this-command-keys) is used.
9864 The argument SPECIAL, if non-nil, means that this command is executing
9865 a special event, so ignore the prefix argument and don't clear it. */)
9866 (cmd
, record_flag
, keys
, special
)
9867 Lisp_Object cmd
, record_flag
, keys
, special
;
9869 register Lisp_Object final
;
9870 register Lisp_Object tem
;
9871 Lisp_Object prefixarg
;
9872 struct backtrace backtrace
;
9873 extern int debug_on_next_call
;
9875 debug_on_next_call
= 0;
9879 prefixarg
= current_kboard
->Vprefix_arg
;
9880 Vcurrent_prefix_arg
= prefixarg
;
9881 current_kboard
->Vprefix_arg
= Qnil
;
9888 tem
= Fget (cmd
, Qdisabled
);
9889 if (!NILP (tem
) && !NILP (Vrun_hooks
))
9891 tem
= Fsymbol_value (Qdisabled_command_function
);
9893 return call1 (Vrun_hooks
, Qdisabled_command_function
);
9899 final
= Findirect_function (cmd
);
9901 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
9903 struct gcpro gcpro1
, gcpro2
;
9905 GCPRO2 (cmd
, prefixarg
);
9906 do_autoload (final
, cmd
);
9913 if (STRINGP (final
) || VECTORP (final
))
9915 /* If requested, place the macro in the command history. For
9916 other sorts of commands, call-interactively takes care of
9918 if (!NILP (record_flag
))
9921 = Fcons (Fcons (Qexecute_kbd_macro
,
9922 Fcons (final
, Fcons (prefixarg
, Qnil
))),
9925 /* Don't keep command history around forever. */
9926 if (NUMBERP (Vhistory_length
) && XINT (Vhistory_length
) > 0)
9928 tem
= Fnthcdr (Vhistory_length
, Vcommand_history
);
9930 XSETCDR (tem
, Qnil
);
9934 return Fexecute_kbd_macro (final
, prefixarg
, Qnil
);
9937 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
9939 backtrace
.next
= backtrace_list
;
9940 backtrace_list
= &backtrace
;
9941 backtrace
.function
= &Qcall_interactively
;
9942 backtrace
.args
= &cmd
;
9943 backtrace
.nargs
= 1;
9944 backtrace
.evalargs
= 0;
9945 backtrace
.debug_on_exit
= 0;
9947 tem
= Fcall_interactively (cmd
, record_flag
, keys
);
9949 backtrace_list
= backtrace
.next
;
9957 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
9959 doc
: /* Read function name, then read its arguments and call it. */)
9961 Lisp_Object prefixarg
;
9963 Lisp_Object function
;
9965 int saved_last_point_position
;
9966 Lisp_Object saved_keys
, saved_last_point_position_buffer
;
9967 Lisp_Object bindings
, value
;
9968 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9969 #ifdef HAVE_X_WINDOWS
9970 /* The call to Fcompleting_read wil start and cancel the hourglass,
9971 but if the hourglass was already scheduled, this means that no
9972 hourglass will be shown for the actual M-x command itself.
9973 So we restart it if it is already scheduled. Note that checking
9974 hourglass_shown_p is not enough, normally the hourglass is not shown,
9975 just scheduled to be shown. */
9976 int hstarted
= hourglass_started ();
9979 saved_keys
= Fvector (this_command_key_count
,
9980 XVECTOR (this_command_keys
)->contents
);
9981 saved_last_point_position_buffer
= last_point_position_buffer
;
9982 saved_last_point_position
= last_point_position
;
9984 GCPRO3 (saved_keys
, prefixarg
, saved_last_point_position_buffer
);
9986 if (EQ (prefixarg
, Qminus
))
9988 else if (CONSP (prefixarg
) && XINT (XCAR (prefixarg
)) == 4)
9989 strcpy (buf
, "C-u ");
9990 else if (CONSP (prefixarg
) && INTEGERP (XCAR (prefixarg
)))
9991 sprintf (buf
, "%ld ", (long) XINT (XCAR (prefixarg
)));
9992 else if (INTEGERP (prefixarg
))
9993 sprintf (buf
, "%ld ", (long) XINT (prefixarg
));
9995 /* This isn't strictly correct if execute-extended-command
9996 is bound to anything else. Perhaps it should use
9997 this_command_keys? */
9998 strcat (buf
, "M-x ");
10000 /* Prompt with buf, and then read a string, completing from and
10001 restricting to the set of all defined commands. Don't provide
10002 any initial input. Save the command read on the extended-command
10004 function
= Fcompleting_read (build_string (buf
),
10005 Vobarray
, Qcommandp
,
10006 Qt
, Qnil
, Qextended_command_history
, Qnil
,
10009 #ifdef HAVE_X_WINDOWS
10010 if (hstarted
) start_hourglass ();
10013 if (STRINGP (function
) && SCHARS (function
) == 0)
10014 error ("No command name given");
10016 /* Set this_command_keys to the concatenation of saved_keys and
10017 function, followed by a RET. */
10022 this_command_key_count
= 0;
10023 this_command_key_count_reset
= 0;
10024 this_single_command_key_start
= 0;
10026 keys
= XVECTOR (saved_keys
)->contents
;
10027 for (i
= 0; i
< XVECTOR (saved_keys
)->size
; i
++)
10028 add_command_key (keys
[i
]);
10030 for (i
= 0; i
< SCHARS (function
); i
++)
10031 add_command_key (Faref (function
, make_number (i
)));
10033 add_command_key (make_number ('\015'));
10036 last_point_position
= saved_last_point_position
;
10037 last_point_position_buffer
= saved_last_point_position_buffer
;
10041 function
= Fintern (function
, Qnil
);
10042 current_kboard
->Vprefix_arg
= prefixarg
;
10043 Vthis_command
= function
;
10044 real_this_command
= function
;
10046 /* If enabled, show which key runs this command. */
10047 if (!NILP (Vsuggest_key_bindings
)
10048 && NILP (Vexecuting_kbd_macro
)
10049 && SYMBOLP (function
))
10050 bindings
= Fwhere_is_internal (function
, Voverriding_local_map
,
10056 GCPRO2 (bindings
, value
);
10057 value
= Fcommand_execute (function
, Qt
, Qnil
, Qnil
);
10059 /* If the command has a key binding, print it now. */
10060 if (!NILP (bindings
)
10061 && ! (VECTORP (bindings
) && EQ (Faref (bindings
, make_number (0)),
10064 /* But first wait, and skip the message if there is input. */
10066 if (!NILP (echo_area_buffer
[0]))
10067 /* This command displayed something in the echo area;
10068 so wait a few seconds, then display our suggestion message. */
10069 delay_time
= (NUMBERP (Vsuggest_key_bindings
)
10070 ? XINT (Vsuggest_key_bindings
) : 2);
10072 /* This command left the echo area empty,
10073 so display our message immediately. */
10076 if (!NILP (Fsit_for (make_number (delay_time
), Qnil
, Qnil
))
10077 && ! CONSP (Vunread_command_events
))
10079 Lisp_Object binding
;
10081 int message_p
= push_message ();
10082 int count
= SPECPDL_INDEX ();
10084 record_unwind_protect (pop_message_unwind
, Qnil
);
10085 binding
= Fkey_description (bindings
, Qnil
);
10088 = (char *) alloca (SCHARS (SYMBOL_NAME (function
))
10091 sprintf (newmessage
, "You can run the command `%s' with %s",
10092 SDATA (SYMBOL_NAME (function
)),
10094 message2_nolog (newmessage
,
10095 strlen (newmessage
),
10096 STRING_MULTIBYTE (binding
));
10097 if (!NILP (Fsit_for ((NUMBERP (Vsuggest_key_bindings
)
10098 ? Vsuggest_key_bindings
: make_number (2)),
10101 restore_message ();
10103 unbind_to (count
, Qnil
);
10107 RETURN_UNGCPRO (value
);
10111 /* Return nonzero if input events are pending. */
10114 detect_input_pending ()
10116 if (!input_pending
)
10117 get_input_pending (&input_pending
, 0);
10119 return input_pending
;
10122 /* Return nonzero if input events other than mouse movements are
10126 detect_input_pending_ignore_squeezables ()
10128 if (!input_pending
)
10129 get_input_pending (&input_pending
, READABLE_EVENTS_IGNORE_SQUEEZABLES
);
10131 return input_pending
;
10134 /* Return nonzero if input events are pending, and run any pending timers. */
10137 detect_input_pending_run_timers (do_display
)
10140 int old_timers_run
= timers_run
;
10142 if (!input_pending
)
10143 get_input_pending (&input_pending
, READABLE_EVENTS_DO_TIMERS_NOW
);
10145 if (old_timers_run
!= timers_run
&& do_display
)
10147 redisplay_preserve_echo_area (8);
10148 /* The following fixes a bug when using lazy-lock with
10149 lazy-lock-defer-on-the-fly set to t, i.e. when fontifying
10150 from an idle timer function. The symptom of the bug is that
10151 the cursor sometimes doesn't become visible until the next X
10152 event is processed. --gerd. */
10154 Lisp_Object tail
, frame
;
10155 FOR_EACH_FRAME (tail
, frame
)
10156 if (FRAME_RIF (XFRAME (frame
)))
10157 FRAME_RIF (XFRAME (frame
))->flush_display (XFRAME (frame
));
10161 return input_pending
;
10164 /* This is called in some cases before a possible quit.
10165 It cases the next call to detect_input_pending to recompute input_pending.
10166 So calling this function unnecessarily can't do any harm. */
10169 clear_input_pending ()
10174 /* Return nonzero if there are pending requeued events.
10175 This isn't used yet. The hope is to make wait_reading_process_output
10176 call it, and return if it runs Lisp code that unreads something.
10177 The problem is, kbd_buffer_get_event needs to be fixed to know what
10178 to do in that case. It isn't trivial. */
10181 requeued_events_pending_p ()
10183 return (!NILP (Vunread_command_events
) || unread_command_char
!= -1);
10187 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
10188 doc
: /* Return t if command input is currently available with no wait.
10189 Actually, the value is nil only if we can be sure that no input is available;
10190 if there is a doubt, the value is t. */)
10193 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1)
10196 get_input_pending (&input_pending
,
10197 READABLE_EVENTS_DO_TIMERS_NOW
10198 | READABLE_EVENTS_FILTER_EVENTS
);
10199 return input_pending
> 0 ? Qt
: Qnil
;
10202 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
10203 doc
: /* Return vector of last 100 events, not counting those from keyboard macros. */)
10206 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
10209 if (total_keys
< NUM_RECENT_KEYS
)
10210 return Fvector (total_keys
, keys
);
10213 val
= Fvector (NUM_RECENT_KEYS
, keys
);
10214 bcopy (keys
+ recent_keys_index
,
10215 XVECTOR (val
)->contents
,
10216 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
10218 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
10219 recent_keys_index
* sizeof (Lisp_Object
));
10224 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
10225 doc
: /* Return the key sequence that invoked this command.
10226 However, if the command has called `read-key-sequence', it returns
10227 the last key sequence that has been read.
10228 The value is a string or a vector. */)
10231 return make_event_array (this_command_key_count
,
10232 XVECTOR (this_command_keys
)->contents
);
10235 DEFUN ("this-command-keys-vector", Fthis_command_keys_vector
, Sthis_command_keys_vector
, 0, 0, 0,
10236 doc
: /* Return the key sequence that invoked this command, as a vector.
10237 However, if the command has called `read-key-sequence', it returns
10238 the last key sequence that has been read. */)
10241 return Fvector (this_command_key_count
,
10242 XVECTOR (this_command_keys
)->contents
);
10245 DEFUN ("this-single-command-keys", Fthis_single_command_keys
,
10246 Sthis_single_command_keys
, 0, 0, 0,
10247 doc
: /* Return the key sequence that invoked this command.
10248 More generally, it returns the last key sequence read, either by
10249 the command loop or by `read-key-sequence'.
10250 Unlike `this-command-keys', this function's value
10251 does not include prefix arguments.
10252 The value is always a vector. */)
10255 return Fvector (this_command_key_count
10256 - this_single_command_key_start
,
10257 (XVECTOR (this_command_keys
)->contents
10258 + this_single_command_key_start
));
10261 DEFUN ("this-single-command-raw-keys", Fthis_single_command_raw_keys
,
10262 Sthis_single_command_raw_keys
, 0, 0, 0,
10263 doc
: /* Return the raw events that were read for this command.
10264 More generally, it returns the last key sequence read, either by
10265 the command loop or by `read-key-sequence'.
10266 Unlike `this-single-command-keys', this function's value
10267 shows the events before all translations (except for input methods).
10268 The value is always a vector. */)
10271 return Fvector (raw_keybuf_count
,
10272 (XVECTOR (raw_keybuf
)->contents
));
10275 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths
,
10276 Sreset_this_command_lengths
, 0, 0, 0,
10277 doc
: /* Make the unread events replace the last command and echo.
10278 Used in `universal-argument-other-key'.
10280 `universal-argument-other-key' rereads the event just typed.
10281 It then gets translated through `function-key-map'.
10282 The translated event has to replace the real events,
10283 both in the value of (this-command-keys) and in echoing.
10284 To achieve this, `universal-argument-other-key' calls
10285 `reset-this-command-lengths', which discards the record of reading
10286 these events the first time. */)
10289 this_command_key_count
= before_command_key_count
;
10290 if (this_command_key_count
< this_single_command_key_start
)
10291 this_single_command_key_start
= this_command_key_count
;
10293 echo_truncate (before_command_echo_length
);
10295 /* Cause whatever we put into unread-command-events
10296 to echo as if it were being freshly read from the keyboard. */
10297 this_command_key_count_reset
= 1;
10302 DEFUN ("clear-this-command-keys", Fclear_this_command_keys
,
10303 Sclear_this_command_keys
, 0, 1, 0,
10304 doc
: /* Clear out the vector that `this-command-keys' returns.
10305 Also clear the record of the last 100 events, unless optional arg
10306 KEEP-RECORD is non-nil. */)
10308 Lisp_Object keep_record
;
10312 this_command_key_count
= 0;
10313 this_command_key_count_reset
= 0;
10315 if (NILP (keep_record
))
10317 for (i
= 0; i
< XVECTOR (recent_keys
)->size
; ++i
)
10318 XVECTOR (recent_keys
)->contents
[i
] = Qnil
;
10320 recent_keys_index
= 0;
10325 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
10326 doc
: /* Return the current depth in recursive edits. */)
10330 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
10334 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
10335 "FOpen dribble file: ",
10336 doc
: /* Start writing all keyboard characters to a dribble file called FILE.
10337 If FILE is nil, close any open dribble file. */)
10348 file
= Fexpand_file_name (file
, Qnil
);
10349 dribble
= fopen (SDATA (file
), "w");
10351 report_file_error ("Opening dribble", Fcons (file
, Qnil
));
10356 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
10357 doc
: /* Discard the contents of the terminal input buffer.
10358 Also end any kbd macro being defined. */)
10361 if (!NILP (current_kboard
->defining_kbd_macro
))
10363 /* Discard the last command from the macro. */
10364 Fcancel_kbd_macro_events ();
10368 update_mode_lines
++;
10370 Vunread_command_events
= Qnil
;
10371 unread_command_char
= -1;
10373 discard_tty_input ();
10375 kbd_fetch_ptr
= kbd_store_ptr
;
10381 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
10382 doc
: /* Stop Emacs and return to superior process. You can resume later.
10383 If `cannot-suspend' is non-nil, or if the system doesn't support job
10384 control, run a subshell instead.
10386 If optional arg STUFFSTRING is non-nil, its characters are stuffed
10387 to be read as terminal input by Emacs's parent, after suspension.
10389 Before suspending, run the normal hook `suspend-hook'.
10390 After resumption run the normal hook `suspend-resume-hook'.
10392 Some operating systems cannot stop the Emacs process and resume it later.
10393 On such systems, Emacs starts a subshell instead of suspending. */)
10395 Lisp_Object stuffstring
;
10397 int count
= SPECPDL_INDEX ();
10398 int old_height
, old_width
;
10400 struct gcpro gcpro1
;
10402 if (tty_list
&& tty_list
->next
)
10403 error ("There are other tty frames open; close them before suspending Emacs");
10405 if (!NILP (stuffstring
))
10406 CHECK_STRING (stuffstring
);
10408 /* Run the functions in suspend-hook. */
10409 if (!NILP (Vrun_hooks
))
10410 call1 (Vrun_hooks
, intern ("suspend-hook"));
10412 GCPRO1 (stuffstring
);
10413 get_tty_size (fileno (CURTTY ()->input
), &old_width
, &old_height
);
10414 reset_all_sys_modes ();
10415 /* sys_suspend can get an error if it tries to fork a subshell
10416 and the system resources aren't available for that. */
10417 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object
))) init_all_sys_modes
,
10419 stuff_buffered_input (stuffstring
);
10420 if (cannot_suspend
)
10424 unbind_to (count
, Qnil
);
10426 /* Check if terminal/window size has changed.
10427 Note that this is not useful when we are running directly
10428 with a window system; but suspend should be disabled in that case. */
10429 get_tty_size (fileno (CURTTY ()->input
), &width
, &height
);
10430 if (width
!= old_width
|| height
!= old_height
)
10431 change_frame_size (SELECTED_FRAME (), height
, width
, 0, 0, 0);
10433 /* Run suspend-resume-hook. */
10434 if (!NILP (Vrun_hooks
))
10435 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
10441 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
10442 Then in any case stuff anything Emacs has read ahead and not used. */
10445 stuff_buffered_input (stuffstring
)
10446 Lisp_Object stuffstring
;
10448 #ifdef SIGTSTP /* stuff_char is defined if SIGTSTP. */
10449 register unsigned char *p
;
10451 if (STRINGP (stuffstring
))
10453 register int count
;
10455 p
= SDATA (stuffstring
);
10456 count
= SBYTES (stuffstring
);
10457 while (count
-- > 0)
10462 /* Anything we have read ahead, put back for the shell to read. */
10463 /* ?? What should this do when we have multiple keyboards??
10464 Should we ignore anything that was typed in at the "wrong" kboard?
10466 rms: we should stuff everything back into the kboard
10468 for (; kbd_fetch_ptr
!= kbd_store_ptr
; kbd_fetch_ptr
++)
10471 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
10472 kbd_fetch_ptr
= kbd_buffer
;
10473 if (kbd_fetch_ptr
->kind
== ASCII_KEYSTROKE_EVENT
)
10474 stuff_char (kbd_fetch_ptr
->code
);
10476 clear_event (kbd_fetch_ptr
);
10480 #endif /* SIGTSTP */
10484 set_waiting_for_input (time_to_clear
)
10485 EMACS_TIME
*time_to_clear
;
10487 input_available_clear_time
= time_to_clear
;
10489 /* Tell handle_interrupt to throw back to read_char, */
10490 waiting_for_input
= 1;
10492 /* If handle_interrupt was called before and buffered a C-g,
10493 make it run again now, to avoid timing error. */
10494 if (!NILP (Vquit_flag
))
10495 quit_throw_to_read_char ();
10499 clear_waiting_for_input ()
10501 /* Tell handle_interrupt not to throw back to read_char, */
10502 waiting_for_input
= 0;
10503 input_available_clear_time
= 0;
10506 /* The SIGINT handler.
10508 If we have a frame on the controlling tty, we assume that the
10509 SIGINT was generated by C-g, so we call handle_interrupt.
10510 Otherwise, the handler kills Emacs. */
10513 interrupt_signal (signalnum
) /* If we don't have an argument, */
10514 int signalnum
; /* some compilers complain in signal calls. */
10516 /* Must preserve main program's value of errno. */
10517 int old_errno
= errno
;
10518 struct terminal
*terminal
;
10520 #if defined (USG) && !defined (POSIX_SIGNALS)
10521 /* USG systems forget handlers when they are used;
10522 must reestablish each time */
10523 signal (SIGINT
, interrupt_signal
);
10524 signal (SIGQUIT
, interrupt_signal
);
10527 SIGNAL_THREAD_CHECK (signalnum
);
10529 /* See if we have an active terminal on our controlling tty. */
10530 terminal
= get_named_tty (NULL
);
10533 /* If there are no frames there, let's pretend that we are a
10534 well-behaving UN*X program and quit. */
10535 Fkill_emacs (Qnil
);
10539 /* Otherwise, the SIGINT was probably generated by C-g. */
10541 /* Set internal_last_event_frame to the top frame of the
10542 controlling tty, if we have a frame there. We disable the
10543 interrupt key on secondary ttys, so the SIGINT must have come
10544 from the controlling tty. */
10545 internal_last_event_frame
= terminal
->display_info
.tty
->top_frame
;
10547 handle_interrupt ();
10553 /* This routine is called at interrupt level in response to C-g.
10555 It is called from the SIGINT handler or kbd_buffer_store_event.
10557 If `waiting_for_input' is non zero, then unless `echoing' is
10558 nonzero, immediately throw back to read_char.
10560 Otherwise it sets the Lisp variable quit-flag not-nil. This causes
10561 eval to throw, when it gets a chance. If quit-flag is already
10562 non-nil, it stops the job right away. */
10565 handle_interrupt ()
10571 /* XXX This code needs to be revised for multi-tty support. */
10572 if (!NILP (Vquit_flag
)
10574 && get_named_tty (NULL
)
10578 /* If SIGINT isn't blocked, don't let us be interrupted by
10579 another SIGINT, it might be harmful due to non-reentrancy
10580 in I/O functions. */
10581 sigblock (sigmask (SIGINT
));
10584 reset_all_sys_modes ();
10586 #ifdef SIGTSTP /* Support possible in later USG versions */
10588 * On systems which can suspend the current process and return to the original
10589 * shell, this command causes the user to end up back at the shell.
10590 * The "Auto-save" and "Abort" questions are not asked until
10591 * the user elects to return to emacs, at which point he can save the current
10592 * job and either dump core or continue.
10597 if (sys_suspend () == -1)
10599 printf ("Not running as a subprocess;\n");
10600 printf ("you can continue or abort.\n");
10602 #else /* not VMS */
10603 /* Perhaps should really fork an inferior shell?
10604 But that would not provide any way to get back
10605 to the original shell, ever. */
10606 printf ("No support for stopping a process on this operating system;\n");
10607 printf ("you can continue or abort.\n");
10608 #endif /* not VMS */
10609 #endif /* not SIGTSTP */
10611 /* We must remain inside the screen area when the internal terminal
10612 is used. Note that [Enter] is not echoed by dos. */
10615 /* It doesn't work to autosave while GC is in progress;
10616 the code used for auto-saving doesn't cope with the mark bit. */
10617 if (!gc_in_progress
)
10619 printf ("Auto-save? (y or n) ");
10621 if (((c
= getchar ()) & ~040) == 'Y')
10623 Fdo_auto_save (Qt
, Qnil
);
10625 printf ("\r\nAuto-save done");
10626 #else /* not MSDOS */
10627 printf ("Auto-save done\n");
10628 #endif /* not MSDOS */
10630 while (c
!= '\n') c
= getchar ();
10634 /* During GC, it must be safe to reenable quitting again. */
10635 Vinhibit_quit
= Qnil
;
10638 #endif /* not MSDOS */
10639 printf ("Garbage collection in progress; cannot auto-save now\r\n");
10640 printf ("but will instead do a real quit after garbage collection ends\r\n");
10645 printf ("\r\nAbort? (y or n) ");
10646 #else /* not MSDOS */
10648 printf ("Abort (and enter debugger)? (y or n) ");
10649 #else /* not VMS */
10650 printf ("Abort (and dump core)? (y or n) ");
10651 #endif /* not VMS */
10652 #endif /* not MSDOS */
10654 if (((c
= getchar ()) & ~040) == 'Y')
10656 while (c
!= '\n') c
= getchar ();
10658 printf ("\r\nContinuing...\r\n");
10659 #else /* not MSDOS */
10660 printf ("Continuing...\n");
10661 #endif /* not MSDOS */
10663 init_all_sys_modes ();
10668 /* If executing a function that wants to be interrupted out of
10669 and the user has not deferred quitting by binding `inhibit-quit'
10670 then quit right away. */
10671 if (immediate_quit
&& NILP (Vinhibit_quit
))
10673 struct gl_state_s saved
;
10674 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
10676 immediate_quit
= 0;
10679 GCPRO4 (saved
.object
, saved
.global_code
,
10680 saved
.current_syntax_table
, saved
.old_prop
);
10681 Fsignal (Qquit
, Qnil
);
10686 /* Else request quit when it's safe */
10690 if (waiting_for_input
&& !echoing
)
10691 quit_throw_to_read_char ();
10694 /* Handle a C-g by making read_char return C-g. */
10697 quit_throw_to_read_char ()
10700 /* Prevent another signal from doing this before we finish. */
10701 clear_waiting_for_input ();
10704 Vunread_command_events
= Qnil
;
10705 unread_command_char
= -1;
10707 #if 0 /* Currently, sit_for is called from read_char without turning
10708 off polling. And that can call set_waiting_for_input.
10709 It seems to be harmless. */
10710 #ifdef POLL_FOR_INPUT
10711 /* May be > 1 if in recursive minibuffer. */
10712 if (poll_suppress_count
== 0)
10716 if (FRAMEP (internal_last_event_frame
)
10717 && !EQ (internal_last_event_frame
, selected_frame
))
10718 do_switch_frame (make_lispy_switch_frame (internal_last_event_frame
),
10721 _longjmp (getcjmp
, 1);
10724 DEFUN ("set-input-interrupt-mode", Fset_input_interrupt_mode
, Sset_input_interrupt_mode
, 1, 1, 0,
10725 doc
: /* Set interrupt mode of reading keyboard input.
10726 If INTERRUPT is non-nil, Emacs will use input interrupts;
10727 otherwise Emacs uses CBREAK mode.
10729 See also `current-input-mode'. */)
10731 Lisp_Object interrupt
;
10733 int new_interrupt_input
;
10735 /* Note SIGIO has been undef'd if FIONREAD is missing. */
10737 #ifdef HAVE_X_WINDOWS
10738 || x_display_list
!= NULL
10742 /* When using X, don't give the user a real choice,
10743 because we haven't implemented the mechanisms to support it. */
10744 #ifdef NO_SOCK_SIGIO
10745 new_interrupt_input
= 0;
10746 #else /* not NO_SOCK_SIGIO */
10747 new_interrupt_input
= 1;
10748 #endif /* NO_SOCK_SIGIO */
10751 new_interrupt_input
= !NILP (interrupt
);
10752 #else /* not SIGIO */
10753 new_interrupt_input
= 0;
10754 #endif /* not SIGIO */
10756 /* Our VMS input only works by interrupts, as of now. */
10758 new_interrupt_input
= 1;
10761 if (new_interrupt_input
!= interrupt_input
)
10763 #ifdef POLL_FOR_INPUT
10767 /* this causes startup screen to be restored and messes with the mouse */
10768 reset_all_sys_modes ();
10770 interrupt_input
= new_interrupt_input
;
10772 init_all_sys_modes ();
10775 #ifdef POLL_FOR_INPUT
10776 poll_suppress_count
= 1;
10783 DEFUN ("set-output-flow-control", Fset_output_flow_control
, Sset_output_flow_control
, 1, 2, 0,
10784 doc
: /* Enable or disable ^S/^Q flow control for output to TERMINAL.
10785 If FLOW is non-nil, flow control is enabled and you cannot use C-s or
10786 C-q in key sequences.
10788 This setting only has an effect on tty terminals and only when
10789 Emacs reads input in CBREAK mode; see `set-input-interrupt-mode'.
10791 See also `current-input-mode'. */)
10793 Lisp_Object flow
, terminal
;
10795 struct terminal
*t
= get_terminal (terminal
, 1);
10796 struct tty_display_info
*tty
;
10797 if (t
== NULL
|| t
->type
!= output_termcap
)
10799 tty
= t
->display_info
.tty
;
10801 if (tty
->flow_control
!= !NILP (flow
))
10804 /* this causes startup screen to be restored and messes with the mouse */
10805 reset_sys_modes (tty
);
10808 tty
->flow_control
= !NILP (flow
);
10811 init_sys_modes (tty
);
10817 DEFUN ("set-input-meta-mode", Fset_input_meta_mode
, Sset_input_meta_mode
, 1, 2, 0,
10818 doc
: /* Enable or disable 8-bit input on TERMINAL.
10819 If META is t, Emacs will accept 8-bit input, and interpret the 8th
10820 bit as the Meta modifier.
10822 If META is nil, Emacs will ignore the top bit, on the assumption it is
10825 Otherwise, Emacs will accept and pass through 8-bit input without
10826 specially interpreting the top bit.
10828 This setting only has an effect on tty terminal devices.
10830 Optional parameter TERMINAL specifies the tty terminal device to use.
10831 It may be a terminal id, a frame, or nil for the terminal used by the
10832 currently selected frame.
10834 See also `current-input-mode'. */)
10836 Lisp_Object meta
, terminal
;
10838 struct terminal
*t
= get_terminal (terminal
, 1);
10839 struct tty_display_info
*tty
;
10842 if (t
== NULL
|| t
->type
!= output_termcap
)
10844 tty
= t
->display_info
.tty
;
10848 else if (EQ (meta
, Qt
))
10853 if (tty
->meta_key
!= new_meta
)
10856 /* this causes startup screen to be restored and messes with the mouse */
10857 reset_sys_modes (tty
);
10860 tty
->meta_key
= new_meta
;
10863 init_sys_modes (tty
);
10869 DEFUN ("set-quit-char", Fset_quit_char
, Sset_quit_char
, 1, 1, 0,
10870 doc
: /* Specify character used for quitting.
10871 QUIT must be an ASCII character.
10873 This function only has an effect on the terminal on the controlling
10874 tty of the Emacs process.
10876 See also `current-input-mode'. */)
10880 struct terminal
*t
= get_named_tty (NULL
);
10881 struct tty_display_info
*tty
;
10882 if (t
== NULL
|| t
->type
!= output_termcap
)
10884 tty
= t
->display_info
.tty
;
10887 /* this causes startup screen to be restored and messes with the mouse */
10888 reset_sys_modes (tty
);
10891 if (NILP (quit
) || !INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400)
10892 error ("QUIT must be an ASCII character");
10894 /* Don't let this value be out of range. */
10895 quit_char
= XINT (quit
) & (tty
->meta_key
== 0 ? 0177 : 0377);
10898 init_sys_modes (tty
);
10904 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
10905 doc
: /* Set mode of reading keyboard input.
10906 First arg INTERRUPT non-nil means use input interrupts;
10907 nil means use CBREAK mode.
10908 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal
10909 (no effect except in CBREAK mode).
10910 Third arg META t means accept 8-bit input (for a Meta key).
10911 META nil means ignore the top bit, on the assumption it is parity.
10912 Otherwise, accept 8-bit input and don't use the top bit for Meta.
10913 Optional fourth arg QUIT if non-nil specifies character to use for quitting.
10914 See also `current-input-mode'. */)
10915 (interrupt
, flow
, meta
, quit
)
10916 Lisp_Object interrupt
, flow
, meta
, quit
;
10918 Fset_input_interrupt_mode (interrupt
);
10919 Fset_output_flow_control (flow
, Qnil
);
10920 Fset_input_meta_mode (meta
, Qnil
);
10921 Fset_quit_char (quit
);
10925 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
10926 doc
: /* Return information about the way Emacs currently reads keyboard input.
10927 The value is a list of the form (INTERRUPT FLOW META QUIT), where
10928 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if
10929 nil, Emacs is using CBREAK mode.
10930 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the
10931 terminal; this does not apply if Emacs uses interrupt-driven input.
10932 META is t if accepting 8-bit input with 8th bit as Meta flag.
10933 META nil means ignoring the top bit, on the assumption it is parity.
10934 META is neither t nor nil if accepting 8-bit input and using
10935 all 8 bits as the character code.
10936 QUIT is the character Emacs currently uses to quit.
10937 The elements of this list correspond to the arguments of
10938 `set-input-mode'. */)
10941 Lisp_Object val
[4];
10942 struct frame
*sf
= XFRAME (selected_frame
);
10944 val
[0] = interrupt_input
? Qt
: Qnil
;
10945 if (FRAME_TERMCAP_P (sf
))
10947 val
[1] = FRAME_TTY (sf
)->flow_control
? Qt
: Qnil
;
10948 val
[2] = (FRAME_TTY (sf
)->meta_key
== 2
10950 : (CURTTY ()->meta_key
== 1 ? Qt
: Qnil
));
10957 XSETFASTINT (val
[3], quit_char
);
10959 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
10962 DEFUN ("posn-at-x-y", Fposn_at_x_y
, Sposn_at_x_y
, 2, 4, 0,
10963 doc
: /* Return position information for pixel coordinates X and Y.
10964 By default, X and Y are relative to text area of the selected window.
10965 Optional third arg FRAME-OR-WINDOW non-nil specifies frame or window.
10966 If optional fourth arg WHOLE is non-nil, X is relative to the left
10967 edge of the window.
10969 The return value is similar to a mouse click position:
10970 (WINDOW AREA-OR-POS (X . Y) TIMESTAMP OBJECT POS (COL . ROW)
10971 IMAGE (DX . DY) (WIDTH . HEIGHT))
10972 The `posn-' functions access elements of such lists. */)
10973 (x
, y
, frame_or_window
, whole
)
10974 Lisp_Object x
, y
, frame_or_window
, whole
;
10979 if (NILP (frame_or_window
))
10980 frame_or_window
= selected_window
;
10982 if (WINDOWP (frame_or_window
))
10986 CHECK_LIVE_WINDOW (frame_or_window
);
10988 w
= XWINDOW (frame_or_window
);
10989 XSETINT (x
, (XINT (x
)
10990 + WINDOW_LEFT_EDGE_X (w
)
10992 ? window_box_left_offset (w
, TEXT_AREA
)
10994 XSETINT (y
, WINDOW_TO_FRAME_PIXEL_Y (w
, XINT (y
)));
10995 frame_or_window
= w
->frame
;
10998 CHECK_LIVE_FRAME (frame_or_window
);
11000 return make_lispy_position (XFRAME (frame_or_window
), &x
, &y
, 0);
11003 DEFUN ("posn-at-point", Fposn_at_point
, Sposn_at_point
, 0, 2, 0,
11004 doc
: /* Return position information for buffer POS in WINDOW.
11005 POS defaults to point in WINDOW; WINDOW defaults to the selected window.
11007 Return nil if position is not visible in window. Otherwise,
11008 the return value is similar to that returned by `event-start' for
11009 a mouse click at the upper left corner of the glyph corresponding
11010 to the given buffer position:
11011 (WINDOW AREA-OR-POS (X . Y) TIMESTAMP OBJECT POS (COL . ROW)
11012 IMAGE (DX . DY) (WIDTH . HEIGHT))
11013 The `posn-' functions access elements of such lists. */)
11015 Lisp_Object pos
, window
;
11020 window
= selected_window
;
11022 tem
= Fpos_visible_in_window_p (pos
, window
, Qt
);
11025 Lisp_Object x
= XCAR (tem
);
11026 Lisp_Object y
= XCAR (XCDR (tem
));
11028 /* Point invisible due to hscrolling? */
11031 tem
= Fposn_at_x_y (x
, y
, window
, Qnil
);
11039 * Set up a new kboard object with reasonable initial values.
11045 kb
->Voverriding_terminal_local_map
= Qnil
;
11046 kb
->Vlast_command
= Qnil
;
11047 kb
->Vreal_last_command
= Qnil
;
11048 kb
->Vkeyboard_translate_table
= Qnil
;
11049 kb
->Vprefix_arg
= Qnil
;
11050 kb
->Vlast_prefix_arg
= Qnil
;
11051 kb
->kbd_queue
= Qnil
;
11052 kb
->kbd_queue_has_data
= 0;
11053 kb
->immediate_echo
= 0;
11054 kb
->echo_string
= Qnil
;
11055 kb
->echo_after_prompt
= -1;
11056 kb
->kbd_macro_buffer
= 0;
11057 kb
->kbd_macro_bufsize
= 0;
11058 kb
->defining_kbd_macro
= Qnil
;
11059 kb
->Vlast_kbd_macro
= Qnil
;
11060 kb
->reference_count
= 0;
11061 kb
->Vsystem_key_alist
= Qnil
;
11062 kb
->system_key_syms
= Qnil
;
11063 kb
->Vlocal_function_key_map
= Fmake_sparse_keymap (Qnil
);
11064 Fset_keymap_parent (kb
->Vlocal_function_key_map
, Vfunction_key_map
);
11065 kb
->Vlocal_key_translation_map
= Fmake_sparse_keymap (Qnil
);
11066 Fset_keymap_parent (kb
->Vlocal_key_translation_map
, Vkey_translation_map
);
11067 kb
->Vdefault_minibuffer_frame
= Qnil
;
11071 * Destroy the contents of a kboard object, but not the object itself.
11072 * We use this just before deleting it, or if we're going to initialize
11073 * it a second time.
11079 if (kb
->kbd_macro_buffer
)
11080 xfree (kb
->kbd_macro_buffer
);
11083 #ifdef MULTI_KBOARD
11085 /* Free KB and memory referenced from it. */
11093 for (kbp
= &all_kboards
; *kbp
!= kb
; kbp
= &(*kbp
)->next_kboard
)
11096 *kbp
= kb
->next_kboard
;
11098 /* Prevent a dangling reference to KB. */
11099 if (kb
== current_kboard
11100 && FRAMEP (selected_frame
)
11101 && FRAME_LIVE_P (XFRAME (selected_frame
)))
11103 current_kboard
= FRAME_KBOARD (XFRAME (selected_frame
));
11105 if (current_kboard
== kb
)
11113 #endif /* MULTI_KBOARD */
11118 /* This is correct before outermost invocation of the editor loop */
11119 command_loop_level
= -1;
11120 immediate_quit
= 0;
11121 quit_char
= Ctl ('g');
11122 Vunread_command_events
= Qnil
;
11123 unread_command_char
= -1;
11124 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
11126 recent_keys_index
= 0;
11127 kbd_fetch_ptr
= kbd_buffer
;
11128 kbd_store_ptr
= kbd_buffer
;
11130 do_mouse_tracking
= Qnil
;
11134 /* This means that command_loop_1 won't try to select anything the first
11136 internal_last_event_frame
= Qnil
;
11137 Vlast_event_frame
= internal_last_event_frame
;
11139 #ifdef MULTI_KBOARD
11140 current_kboard
= initial_kboard
;
11142 wipe_kboard (current_kboard
);
11143 init_kboard (current_kboard
);
11145 if (!noninteractive
)
11147 /* Before multi-tty support, these handlers used to be installed
11148 only if the current session was a tty session. Now an Emacs
11149 session may have multiple display types, so we always handle
11150 SIGINT. There is special code in interrupt_signal to exit
11151 Emacs on SIGINT when there are no termcap frames on the
11152 controlling terminal. */
11153 signal (SIGINT
, interrupt_signal
);
11154 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
11155 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
11156 SIGQUIT and we can't tell which one it will give us. */
11157 signal (SIGQUIT
, interrupt_signal
);
11158 #endif /* HAVE_TERMIO */
11160 /* Note SIGIO has been undef'd if FIONREAD is missing. */
11162 if (!noninteractive
)
11163 signal (SIGIO
, input_available_signal
);
11166 /* Use interrupt input by default, if it works and noninterrupt input
11167 has deficiencies. */
11169 #ifdef INTERRUPT_INPUT
11170 interrupt_input
= 1;
11172 interrupt_input
= 0;
11175 /* Our VMS input only works by interrupts, as of now. */
11177 interrupt_input
= 1;
11183 if (keyboard_init_hook
)
11184 (*keyboard_init_hook
) ();
11186 #ifdef POLL_FOR_INPUT
11187 poll_suppress_count
= 1;
11192 /* This type's only use is in syms_of_keyboard, to initialize the
11193 event header symbols and put properties on them. */
11194 struct event_head
{
11200 struct event_head head_table
[] = {
11201 {&Qmouse_movement
, "mouse-movement", &Qmouse_movement
},
11202 {&Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
},
11203 {&Qswitch_frame
, "switch-frame", &Qswitch_frame
},
11204 {&Qdelete_frame
, "delete-frame", &Qdelete_frame
},
11205 {&Qiconify_frame
, "iconify-frame", &Qiconify_frame
},
11206 {&Qmake_frame_visible
, "make-frame-visible", &Qmake_frame_visible
},
11207 /* `select-window' should be handled just like `switch-frame'
11208 in read_key_sequence. */
11209 {&Qselect_window
, "select-window", &Qswitch_frame
}
11213 syms_of_keyboard ()
11215 Vpre_help_message
= Qnil
;
11216 staticpro (&Vpre_help_message
);
11218 Vlispy_mouse_stem
= build_string ("mouse");
11219 staticpro (&Vlispy_mouse_stem
);
11222 QCimage
= intern (":image");
11223 staticpro (&QCimage
);
11225 staticpro (&Qhelp_echo
);
11226 Qhelp_echo
= intern ("help-echo");
11228 staticpro (&item_properties
);
11229 item_properties
= Qnil
;
11231 staticpro (&tool_bar_item_properties
);
11232 tool_bar_item_properties
= Qnil
;
11233 staticpro (&tool_bar_items_vector
);
11234 tool_bar_items_vector
= Qnil
;
11236 staticpro (&real_this_command
);
11237 real_this_command
= Qnil
;
11239 Qtimer_event_handler
= intern ("timer-event-handler");
11240 staticpro (&Qtimer_event_handler
);
11242 Qdisabled_command_function
= intern ("disabled-command-function");
11243 staticpro (&Qdisabled_command_function
);
11245 Qself_insert_command
= intern ("self-insert-command");
11246 staticpro (&Qself_insert_command
);
11248 Qforward_char
= intern ("forward-char");
11249 staticpro (&Qforward_char
);
11251 Qbackward_char
= intern ("backward-char");
11252 staticpro (&Qbackward_char
);
11254 Qdisabled
= intern ("disabled");
11255 staticpro (&Qdisabled
);
11257 Qundefined
= intern ("undefined");
11258 staticpro (&Qundefined
);
11260 Qpre_command_hook
= intern ("pre-command-hook");
11261 staticpro (&Qpre_command_hook
);
11263 Qpost_command_hook
= intern ("post-command-hook");
11264 staticpro (&Qpost_command_hook
);
11266 Qdeferred_action_function
= intern ("deferred-action-function");
11267 staticpro (&Qdeferred_action_function
);
11269 Qcommand_hook_internal
= intern ("command-hook-internal");
11270 staticpro (&Qcommand_hook_internal
);
11272 Qfunction_key
= intern ("function-key");
11273 staticpro (&Qfunction_key
);
11274 Qmouse_click
= intern ("mouse-click");
11275 staticpro (&Qmouse_click
);
11276 #if defined (WINDOWSNT) || defined (MAC_OS)
11277 Qlanguage_change
= intern ("language-change");
11278 staticpro (&Qlanguage_change
);
11280 Qdrag_n_drop
= intern ("drag-n-drop");
11281 staticpro (&Qdrag_n_drop
);
11283 Qsave_session
= intern ("save-session");
11284 staticpro (&Qsave_session
);
11287 Qmac_apple_event
= intern ("mac-apple-event");
11288 staticpro (&Qmac_apple_event
);
11291 Qusr1_signal
= intern ("usr1-signal");
11292 staticpro (&Qusr1_signal
);
11293 Qusr2_signal
= intern ("usr2-signal");
11294 staticpro (&Qusr2_signal
);
11296 Qmenu_enable
= intern ("menu-enable");
11297 staticpro (&Qmenu_enable
);
11298 Qmenu_alias
= intern ("menu-alias");
11299 staticpro (&Qmenu_alias
);
11300 QCenable
= intern (":enable");
11301 staticpro (&QCenable
);
11302 QCvisible
= intern (":visible");
11303 staticpro (&QCvisible
);
11304 QChelp
= intern (":help");
11305 staticpro (&QChelp
);
11306 QCfilter
= intern (":filter");
11307 staticpro (&QCfilter
);
11308 QCbutton
= intern (":button");
11309 staticpro (&QCbutton
);
11310 QCkeys
= intern (":keys");
11311 staticpro (&QCkeys
);
11312 QCkey_sequence
= intern (":key-sequence");
11313 staticpro (&QCkey_sequence
);
11314 QCtoggle
= intern (":toggle");
11315 staticpro (&QCtoggle
);
11316 QCradio
= intern (":radio");
11317 staticpro (&QCradio
);
11319 Qmode_line
= intern ("mode-line");
11320 staticpro (&Qmode_line
);
11321 Qvertical_line
= intern ("vertical-line");
11322 staticpro (&Qvertical_line
);
11323 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
11324 staticpro (&Qvertical_scroll_bar
);
11325 Qmenu_bar
= intern ("menu-bar");
11326 staticpro (&Qmenu_bar
);
11329 Qmouse_fixup_help_message
= intern ("mouse-fixup-help-message");
11330 staticpro (&Qmouse_fixup_help_message
);
11333 Qabove_handle
= intern ("above-handle");
11334 staticpro (&Qabove_handle
);
11335 Qhandle
= intern ("handle");
11336 staticpro (&Qhandle
);
11337 Qbelow_handle
= intern ("below-handle");
11338 staticpro (&Qbelow_handle
);
11339 Qup
= intern ("up");
11341 Qdown
= intern ("down");
11342 staticpro (&Qdown
);
11343 Qtop
= intern ("top");
11345 Qbottom
= intern ("bottom");
11346 staticpro (&Qbottom
);
11347 Qend_scroll
= intern ("end-scroll");
11348 staticpro (&Qend_scroll
);
11349 Qratio
= intern ("ratio");
11350 staticpro (&Qratio
);
11352 Qevent_kind
= intern ("event-kind");
11353 staticpro (&Qevent_kind
);
11354 Qevent_symbol_elements
= intern ("event-symbol-elements");
11355 staticpro (&Qevent_symbol_elements
);
11356 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
11357 staticpro (&Qevent_symbol_element_mask
);
11358 Qmodifier_cache
= intern ("modifier-cache");
11359 staticpro (&Qmodifier_cache
);
11361 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
11362 staticpro (&Qrecompute_lucid_menubar
);
11363 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
11364 staticpro (&Qactivate_menubar_hook
);
11366 Qpolling_period
= intern ("polling-period");
11367 staticpro (&Qpolling_period
);
11369 Qinput_method_function
= intern ("input-method-function");
11370 staticpro (&Qinput_method_function
);
11372 Qinput_method_exit_on_first_char
= intern ("input-method-exit-on-first-char");
11373 staticpro (&Qinput_method_exit_on_first_char
);
11374 Qinput_method_use_echo_area
= intern ("input-method-use-echo-area");
11375 staticpro (&Qinput_method_use_echo_area
);
11377 Fset (Qinput_method_exit_on_first_char
, Qnil
);
11378 Fset (Qinput_method_use_echo_area
, Qnil
);
11380 last_point_position_buffer
= Qnil
;
11381 last_point_position_window
= Qnil
;
11384 struct event_head
*p
;
11386 for (p
= head_table
;
11387 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
11390 *p
->var
= intern (p
->name
);
11391 staticpro (p
->var
);
11392 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
11393 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
11397 button_down_location
= Fmake_vector (make_number (1), Qnil
);
11398 staticpro (&button_down_location
);
11399 mouse_syms
= Fmake_vector (make_number (1), Qnil
);
11400 staticpro (&mouse_syms
);
11401 wheel_syms
= Fmake_vector (make_number (2), Qnil
);
11402 staticpro (&wheel_syms
);
11406 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
11408 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
11409 for (i
= 0; i
< len
; i
++)
11410 if (modifier_names
[i
])
11411 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
11412 staticpro (&modifier_symbols
);
11415 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
11416 staticpro (&recent_keys
);
11418 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
11419 staticpro (&this_command_keys
);
11421 raw_keybuf
= Fmake_vector (make_number (30), Qnil
);
11422 staticpro (&raw_keybuf
);
11424 Qextended_command_history
= intern ("extended-command-history");
11425 Fset (Qextended_command_history
, Qnil
);
11426 staticpro (&Qextended_command_history
);
11428 accent_key_syms
= Qnil
;
11429 staticpro (&accent_key_syms
);
11431 func_key_syms
= Qnil
;
11432 staticpro (&func_key_syms
);
11434 drag_n_drop_syms
= Qnil
;
11435 staticpro (&drag_n_drop_syms
);
11437 unread_switch_frame
= Qnil
;
11438 staticpro (&unread_switch_frame
);
11440 internal_last_event_frame
= Qnil
;
11441 staticpro (&internal_last_event_frame
);
11443 read_key_sequence_cmd
= Qnil
;
11444 staticpro (&read_key_sequence_cmd
);
11446 menu_bar_one_keymap_changed_items
= Qnil
;
11447 staticpro (&menu_bar_one_keymap_changed_items
);
11449 menu_bar_items_vector
= Qnil
;
11450 staticpro (&menu_bar_items_vector
);
11452 defsubr (&Sevent_convert_list
);
11453 defsubr (&Sread_key_sequence
);
11454 defsubr (&Sread_key_sequence_vector
);
11455 defsubr (&Srecursive_edit
);
11457 defsubr (&Strack_mouse
);
11459 defsubr (&Sinput_pending_p
);
11460 defsubr (&Scommand_execute
);
11461 defsubr (&Srecent_keys
);
11462 defsubr (&Sthis_command_keys
);
11463 defsubr (&Sthis_command_keys_vector
);
11464 defsubr (&Sthis_single_command_keys
);
11465 defsubr (&Sthis_single_command_raw_keys
);
11466 defsubr (&Sreset_this_command_lengths
);
11467 defsubr (&Sclear_this_command_keys
);
11468 defsubr (&Ssuspend_emacs
);
11469 defsubr (&Sabort_recursive_edit
);
11470 defsubr (&Sexit_recursive_edit
);
11471 defsubr (&Srecursion_depth
);
11472 defsubr (&Stop_level
);
11473 defsubr (&Sdiscard_input
);
11474 defsubr (&Sopen_dribble_file
);
11475 defsubr (&Sset_input_interrupt_mode
);
11476 defsubr (&Sset_output_flow_control
);
11477 defsubr (&Sset_input_meta_mode
);
11478 defsubr (&Sset_quit_char
);
11479 defsubr (&Sset_input_mode
);
11480 defsubr (&Scurrent_input_mode
);
11481 defsubr (&Sexecute_extended_command
);
11482 defsubr (&Sposn_at_point
);
11483 defsubr (&Sposn_at_x_y
);
11485 DEFVAR_LISP ("last-command-char", &last_command_char
,
11486 doc
: /* Last input event that was part of a command. */);
11488 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char
,
11489 doc
: /* Last input event that was part of a command. */);
11491 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
11492 doc
: /* Last input event in a command, except for mouse menu events.
11493 Mouse menus give back keys that don't look like mouse events;
11494 this variable holds the actual mouse event that led to the menu,
11495 so that you can determine whether the command was run by mouse or not. */);
11497 DEFVAR_LISP ("last-input-char", &last_input_char
,
11498 doc
: /* Last input event. */);
11500 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char
,
11501 doc
: /* Last input event. */);
11503 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
11504 doc
: /* List of events to be read as the command input.
11505 These events are processed first, before actual keyboard input. */);
11506 Vunread_command_events
= Qnil
;
11508 DEFVAR_INT ("unread-command-char", &unread_command_char
,
11509 doc
: /* If not -1, an object to be read as next command input event. */);
11511 DEFVAR_LISP ("unread-post-input-method-events", &Vunread_post_input_method_events
,
11512 doc
: /* List of events to be processed as input by input methods.
11513 These events are processed after `unread-command-events', but
11514 before actual keyboard input. */);
11515 Vunread_post_input_method_events
= Qnil
;
11517 DEFVAR_LISP ("unread-input-method-events", &Vunread_input_method_events
,
11518 doc
: /* List of events to be processed as input by input methods.
11519 These events are processed after `unread-command-events', but
11520 before actual keyboard input. */);
11521 Vunread_input_method_events
= Qnil
;
11523 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
11524 doc
: /* Meta-prefix character code.
11525 Meta-foo as command input turns into this character followed by foo. */);
11526 XSETINT (meta_prefix_char
, 033);
11528 DEFVAR_KBOARD ("last-command", Vlast_command
,
11529 doc
: /* The last command executed.
11530 Normally a symbol with a function definition, but can be whatever was found
11531 in the keymap, or whatever the variable `this-command' was set to by that
11534 The value `mode-exit' is special; it means that the previous command
11535 read an event that told it to exit, and it did so and unread that event.
11536 In other words, the present command is the event that made the previous
11539 The value `kill-region' is special; it means that the previous command
11540 was a kill command.
11542 `last-command' has a separate binding for each terminal device.
11543 See Info node `(elisp)Multiple displays'. */);
11545 DEFVAR_KBOARD ("real-last-command", Vreal_last_command
,
11546 doc
: /* Same as `last-command', but never altered by Lisp code. */);
11548 DEFVAR_LISP ("this-command", &Vthis_command
,
11549 doc
: /* The command now being executed.
11550 The command can set this variable; whatever is put here
11551 will be in `last-command' during the following command. */);
11552 Vthis_command
= Qnil
;
11554 DEFVAR_LISP ("this-original-command", &Vthis_original_command
,
11555 doc
: /* The command bound to the current key sequence before remapping.
11556 It equals `this-command' if the original command was not remapped through
11557 any of the active keymaps. Otherwise, the value of `this-command' is the
11558 result of looking up the original command in the active keymaps. */);
11559 Vthis_original_command
= Qnil
;
11561 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
11562 doc
: /* *Number of input events between auto-saves.
11563 Zero means disable autosaving due to number of characters typed. */);
11564 auto_save_interval
= 300;
11566 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
11567 doc
: /* *Number of seconds idle time before auto-save.
11568 Zero or nil means disable auto-saving due to idleness.
11569 After auto-saving due to this many seconds of idle time,
11570 Emacs also does a garbage collection if that seems to be warranted. */);
11571 XSETFASTINT (Vauto_save_timeout
, 30);
11573 DEFVAR_LISP ("echo-keystrokes", &Vecho_keystrokes
,
11574 doc
: /* *Nonzero means echo unfinished commands after this many seconds of pause.
11575 The value may be integer or floating point. */);
11576 Vecho_keystrokes
= make_number (1);
11578 DEFVAR_INT ("polling-period", &polling_period
,
11579 doc
: /* *Interval between polling for input during Lisp execution.
11580 The reason for polling is to make C-g work to stop a running program.
11581 Polling is needed only when using X windows and SIGIO does not work.
11582 Polling is automatically disabled in all other cases. */);
11583 polling_period
= 2;
11585 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
11586 doc
: /* *Maximum time between mouse clicks to make a double-click.
11587 Measured in milliseconds. nil means disable double-click recognition;
11588 t means double-clicks have no time limit and are detected
11589 by position only. */);
11590 Vdouble_click_time
= make_number (500);
11592 DEFVAR_INT ("double-click-fuzz", &double_click_fuzz
,
11593 doc
: /* *Maximum mouse movement between clicks to make a double-click.
11594 On window-system frames, value is the number of pixels the mouse may have
11595 moved horizontally or vertically between two clicks to make a double-click.
11596 On non window-system frames, value is interpreted in units of 1/8 characters
11599 This variable is also the threshold for motion of the mouse
11600 to count as a drag. */);
11601 double_click_fuzz
= 3;
11603 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
11604 doc
: /* *Non-nil means inhibit local map menu bar menus. */);
11605 inhibit_local_menu_bar_menus
= 0;
11607 DEFVAR_INT ("num-input-keys", &num_input_keys
,
11608 doc
: /* Number of complete key sequences read as input so far.
11609 This includes key sequences read from keyboard macros.
11610 The number is effectively the number of interactive command invocations. */);
11611 num_input_keys
= 0;
11613 DEFVAR_INT ("num-nonmacro-input-events", &num_nonmacro_input_events
,
11614 doc
: /* Number of input events read from the keyboard so far.
11615 This does not include events generated by keyboard macros. */);
11616 num_nonmacro_input_events
= 0;
11618 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
11619 doc
: /* The frame in which the most recently read event occurred.
11620 If the last event came from a keyboard macro, this is set to `macro'. */);
11621 Vlast_event_frame
= Qnil
;
11623 /* This variable is set up in sysdep.c. */
11624 DEFVAR_LISP ("tty-erase-char", &Vtty_erase_char
,
11625 doc
: /* The ERASE character as set by the user with stty. */);
11627 DEFVAR_LISP ("help-char", &Vhelp_char
,
11628 doc
: /* Character to recognize as meaning Help.
11629 When it is read, do `(eval help-form)', and display result if it's a string.
11630 If the value of `help-form' is nil, this char can be read normally. */);
11631 XSETINT (Vhelp_char
, Ctl ('H'));
11633 DEFVAR_LISP ("help-event-list", &Vhelp_event_list
,
11634 doc
: /* List of input events to recognize as meaning Help.
11635 These work just like the value of `help-char' (see that). */);
11636 Vhelp_event_list
= Qnil
;
11638 DEFVAR_LISP ("help-form", &Vhelp_form
,
11639 doc
: /* Form to execute when character `help-char' is read.
11640 If the form returns a string, that string is displayed.
11641 If `help-form' is nil, the help char is not recognized. */);
11644 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
11645 doc
: /* Command to run when `help-char' character follows a prefix key.
11646 This command is used only when there is no actual binding
11647 for that character after that prefix key. */);
11648 Vprefix_help_command
= Qnil
;
11650 DEFVAR_LISP ("top-level", &Vtop_level
,
11651 doc
: /* Form to evaluate when Emacs starts up.
11652 Useful to set before you dump a modified Emacs. */);
11655 DEFVAR_KBOARD ("keyboard-translate-table", Vkeyboard_translate_table
,
11656 doc
: /* Translate table for local keyboard input, or nil.
11657 If non-nil, the value should be a char-table. Each character read
11658 from the keyboard is looked up in this char-table. If the value found
11659 there is non-nil, then it is used instead of the actual input character.
11661 The value can also be a string or vector, but this is considered obsolete.
11662 If it is a string or vector of length N, character codes N and up are left
11663 untranslated. In a vector, an element which is nil means "no translation".
11665 This is applied to the characters supplied to input methods, not their
11666 output. See also `translation-table-for-input'.
11668 This variable has a separate binding for each terminal. See Info node
11669 `(elisp)Multiple displays'. */);
11671 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
11672 doc
: /* Non-nil means to always spawn a subshell instead of suspending.
11673 \(Even if the operating system has support for stopping a process.\) */);
11674 cannot_suspend
= 0;
11676 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
11677 doc
: /* Non-nil means prompt with menus when appropriate.
11678 This is done when reading from a keymap that has a prompt string,
11679 for elements that have prompt strings.
11680 The menu is displayed on the screen
11681 if X menus were enabled at configuration
11682 time and the previous event was a mouse click prefix key.
11683 Otherwise, menu prompting uses the echo area. */);
11684 menu_prompting
= 1;
11686 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
11687 doc
: /* Character to see next line of menu prompt.
11688 Type this character while in a menu prompt to rotate around the lines of it. */);
11689 XSETINT (menu_prompt_more_char
, ' ');
11691 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
11692 doc
: /* A mask of additional modifier keys to use with every keyboard character.
11693 Emacs applies the modifiers of the character stored here to each keyboard
11694 character it reads. For example, after evaluating the expression
11695 (setq extra-keyboard-modifiers ?\\C-x)
11696 all input characters will have the control modifier applied to them.
11698 Note that the character ?\\C-@, equivalent to the integer zero, does
11699 not count as a control character; rather, it counts as a character
11700 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero
11701 cancels any modification. */);
11702 extra_keyboard_modifiers
= 0;
11704 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
11705 doc
: /* If an editing command sets this to t, deactivate the mark afterward.
11706 The command loop sets this to nil before each command,
11707 and tests the value when the command returns.
11708 Buffer modification stores t in this variable. */);
11709 Vdeactivate_mark
= Qnil
;
11711 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
11712 doc
: /* Temporary storage of pre-command-hook or post-command-hook. */);
11713 Vcommand_hook_internal
= Qnil
;
11715 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
11716 doc
: /* Normal hook run before each command is executed.
11717 If an unhandled error happens in running this hook,
11718 the hook value is set to nil, since otherwise the error
11719 might happen repeatedly and make Emacs nonfunctional. */);
11720 Vpre_command_hook
= Qnil
;
11722 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
11723 doc
: /* Normal hook run after each command is executed.
11724 If an unhandled error happens in running this hook,
11725 the hook value is set to nil, since otherwise the error
11726 might happen repeatedly and make Emacs nonfunctional. */);
11727 Vpost_command_hook
= Qnil
;
11730 DEFVAR_LISP ("echo-area-clear-hook", ...,
11731 doc
: /* Normal hook run when clearing the echo area. */);
11733 Qecho_area_clear_hook
= intern ("echo-area-clear-hook");
11734 staticpro (&Qecho_area_clear_hook
);
11735 SET_SYMBOL_VALUE (Qecho_area_clear_hook
, Qnil
);
11737 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
11738 doc
: /* Non-nil means menu bar, specified Lucid style, needs to be recomputed. */);
11739 Vlucid_menu_bar_dirty_flag
= Qnil
;
11741 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
11742 doc
: /* List of menu bar items to move to the end of the menu bar.
11743 The elements of the list are event types that may have menu bar bindings. */);
11744 Vmenu_bar_final_items
= Qnil
;
11746 DEFVAR_KBOARD ("overriding-terminal-local-map",
11747 Voverriding_terminal_local_map
,
11748 doc
: /* Per-terminal keymap that overrides all other local keymaps.
11749 If this variable is non-nil, it is used as a keymap instead of the
11750 buffer's local map, and the minor mode keymaps and text property keymaps.
11751 It also replaces `overriding-local-map'.
11753 This variable is intended to let commands such as `universal-argument'
11754 set up a different keymap for reading the next command.
11756 `overriding-terminal-local-map' has a separate binding for each
11758 See Info node `(elisp)Multiple displays'. */);
11760 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
11761 doc
: /* Keymap that overrides all other local keymaps.
11762 If this variable is non-nil, it is used as a keymap--replacing the
11763 buffer's local map, the minor mode keymaps, and char property keymaps. */);
11764 Voverriding_local_map
= Qnil
;
11766 DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag
,
11767 doc
: /* Non-nil means `overriding-local-map' applies to the menu bar.
11768 Otherwise, the menu bar continues to reflect the buffer's local map
11769 and the minor mode maps regardless of `overriding-local-map'. */);
11770 Voverriding_local_map_menu_flag
= Qnil
;
11772 DEFVAR_LISP ("special-event-map", &Vspecial_event_map
,
11773 doc
: /* Keymap defining bindings for special events to execute at low level. */);
11774 Vspecial_event_map
= Fcons (intern ("keymap"), Qnil
);
11776 DEFVAR_LISP ("track-mouse", &do_mouse_tracking
,
11777 doc
: /* *Non-nil means generate motion events for mouse motion. */);
11779 DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist
,
11780 doc
: /* Alist of system-specific X windows key symbols.
11781 Each element should have the form (N . SYMBOL) where N is the
11782 numeric keysym code (sans the \"system-specific\" bit 1<<28)
11783 and SYMBOL is its name.
11785 `system-key-alist' has a separate binding for each terminal device.
11786 See Info node `(elisp)Multiple displays'. */);
11788 DEFVAR_KBOARD ("local-function-key-map", Vlocal_function_key_map
,
11789 doc
: /* Keymap that translates key sequences to key sequences during input.
11790 This is used mainly for mapping ASCII function key sequences into
11791 real Emacs function key events (symbols).
11793 The `read-key-sequence' function replaces any subsequence bound by
11794 `local-function-key-map' with its binding. More precisely, when the
11795 active keymaps have no binding for the current key sequence but
11796 `local-function-key-map' binds a suffix of the sequence to a vector or
11797 string, `read-key-sequence' replaces the matching suffix with its
11798 binding, and continues with the new sequence.
11800 If the binding is a function, it is called with one argument (the prompt)
11801 and its return value (a key sequence) is used.
11803 The events that come from bindings in `local-function-key-map' are not
11804 themselves looked up in `local-function-key-map'.
11806 For example, suppose `local-function-key-map' binds `ESC O P' to [f1].
11807 Typing `ESC O P' to `read-key-sequence' would return [f1]. Typing
11808 `C-x ESC O P' would return [?\\C-x f1]. If [f1] were a prefix key,
11809 typing `ESC O P x' would return [f1 x].
11811 `local-function-key-map' has a separate binding for each terminal
11812 device. See Info node `(elisp)Multiple displays'. If you need to
11813 define a binding on all terminals, change `function-key-map'
11814 instead. Initially, `local-function-key-map' is an empty keymap that
11815 has `function-key-map' as its parent on all terminal devices. */);
11817 DEFVAR_LISP ("function-key-map", &Vfunction_key_map
,
11818 doc
: /* The parent keymap of all `local-function-key-map' instances.
11819 Function key definitions that apply to all terminal devices should go
11820 here. If a mapping is defined in both the current
11821 `local-function-key-map' binding and this variable, then the local
11822 definition will take precendence. */);
11823 Vfunction_key_map
= Fmake_sparse_keymap (Qnil
);
11825 DEFVAR_KBOARD ("local-key-translation-map", Vlocal_key_translation_map
,
11826 doc
: /* Keymap of key translations that can override keymaps.
11827 This keymap works like `function-key-map', but comes after that,
11828 and its non-prefix bindings override ordinary bindings.
11830 `key-translation-map' has a separate binding for each terminal device.
11831 (See Info node `(elisp)Multiple displays'.) If you need to set a key
11832 translation on all terminals, change `global-key-translation-map' instead. */);
11834 DEFVAR_LISP ("key-translation-map", &Vkey_translation_map
,
11835 doc
: /* The parent keymap of all `local-key-translation-map' instances.
11836 Key translations that apply to all terminal devices should go here. */);
11837 Vkey_translation_map
= Fmake_sparse_keymap (Qnil
);
11839 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
11840 doc
: /* List of deferred actions to be performed at a later time.
11841 The precise format isn't relevant here; we just check whether it is nil. */);
11842 Vdeferred_action_list
= Qnil
;
11844 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
11845 doc
: /* Function to call to handle deferred actions, after each command.
11846 This function is called with no arguments after each command
11847 whenever `deferred-action-list' is non-nil. */);
11848 Vdeferred_action_function
= Qnil
;
11850 DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings
,
11851 doc
: /* *Non-nil means show the equivalent key-binding when M-x command has one.
11852 The value can be a length of time to show the message for.
11853 If the value is non-nil and not a number, we wait 2 seconds. */);
11854 Vsuggest_key_bindings
= Qt
;
11856 DEFVAR_LISP ("timer-list", &Vtimer_list
,
11857 doc
: /* List of active absolute time timers in order of increasing time. */);
11858 Vtimer_list
= Qnil
;
11860 DEFVAR_LISP ("timer-idle-list", &Vtimer_idle_list
,
11861 doc
: /* List of active idle-time timers in order of increasing time. */);
11862 Vtimer_idle_list
= Qnil
;
11864 DEFVAR_LISP ("input-method-function", &Vinput_method_function
,
11865 doc
: /* If non-nil, the function that implements the current input method.
11866 It's called with one argument, a printing character that was just read.
11867 \(That means a character with code 040...0176.)
11868 Typically this function uses `read-event' to read additional events.
11869 When it does so, it should first bind `input-method-function' to nil
11870 so it will not be called recursively.
11872 The function should return a list of zero or more events
11873 to be used as input. If it wants to put back some events
11874 to be reconsidered, separately, by the input method,
11875 it can add them to the beginning of `unread-command-events'.
11877 The input method function can find in `input-method-previous-method'
11878 the previous echo area message.
11880 The input method function should refer to the variables
11881 `input-method-use-echo-area' and `input-method-exit-on-first-char'
11882 for guidance on what to do. */);
11883 Vinput_method_function
= Qnil
;
11885 DEFVAR_LISP ("input-method-previous-message",
11886 &Vinput_method_previous_message
,
11887 doc
: /* When `input-method-function' is called, hold the previous echo area message.
11888 This variable exists because `read-event' clears the echo area
11889 before running the input method. It is nil if there was no message. */);
11890 Vinput_method_previous_message
= Qnil
;
11892 DEFVAR_LISP ("show-help-function", &Vshow_help_function
,
11893 doc
: /* If non-nil, the function that implements the display of help.
11894 It's called with one argument, the help string to display. */);
11895 Vshow_help_function
= Qnil
;
11897 DEFVAR_LISP ("disable-point-adjustment", &Vdisable_point_adjustment
,
11898 doc
: /* If non-nil, suppress point adjustment after executing a command.
11900 After a command is executed, if point is moved into a region that has
11901 special properties (e.g. composition, display), we adjust point to
11902 the boundary of the region. But, when a command sets this variable to
11903 non-nil, we suppress the point adjustment.
11905 This variable is set to nil before reading a command, and is checked
11906 just after executing the command. */);
11907 Vdisable_point_adjustment
= Qnil
;
11909 DEFVAR_LISP ("global-disable-point-adjustment",
11910 &Vglobal_disable_point_adjustment
,
11911 doc
: /* *If non-nil, always suppress point adjustment.
11913 The default value is nil, in which case, point adjustment are
11914 suppressed only after special commands that set
11915 `disable-point-adjustment' (which see) to non-nil. */);
11916 Vglobal_disable_point_adjustment
= Qnil
;
11918 DEFVAR_LISP ("minibuffer-message-timeout", &Vminibuffer_message_timeout
,
11919 doc
: /* *How long to display an echo-area message when the minibuffer is active.
11920 If the value is not a number, such messages don't time out. */);
11921 Vminibuffer_message_timeout
= make_number (2);
11923 DEFVAR_LISP ("throw-on-input", &Vthrow_on_input
,
11924 doc
: /* If non-nil, any keyboard input throws to this symbol.
11925 The value of that variable is passed to `quit-flag' and later causes a
11926 peculiar kind of quitting. */);
11927 Vthrow_on_input
= Qnil
;
11931 keys_of_keyboard ()
11933 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
11934 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
11935 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
11936 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
11937 initial_define_key (meta_map
, 'x', "execute-extended-command");
11939 initial_define_lispy_key (Vspecial_event_map
, "delete-frame",
11940 "handle-delete-frame");
11941 /* Here we used to use `ignore-event' which would simple set prefix-arg to
11942 current-prefix-arg, as is done in `handle-switch-frame'.
11943 But `handle-switch-frame is not run from the special-map.
11944 Commands from that map are run in a special way that automatically
11945 preserves the prefix-arg. Restoring the prefix arg here is not just
11946 redundant but harmful:
11948 - current-prefix-arg is set to non-nil, prefix-arg is set to nil.
11949 - after the first prompt, the exit-minibuffer-hook is run which may
11950 iconify a frame and thus push a `iconify-frame' event.
11951 - after running exit-minibuffer-hook, current-prefix-arg is
11952 restored to the non-nil value it had before the prompt.
11953 - we enter the second prompt.
11954 current-prefix-arg is non-nil, prefix-arg is nil.
11955 - before running the first real event, we run the special iconify-frame
11956 event, but we pass the `special' arg to execute-command so
11957 current-prefix-arg and prefix-arg are left untouched.
11958 - here we foolishly copy the non-nil current-prefix-arg to prefix-arg.
11959 - the next key event will have a spuriously non-nil current-prefix-arg. */
11960 initial_define_lispy_key (Vspecial_event_map
, "iconify-frame",
11962 initial_define_lispy_key (Vspecial_event_map
, "make-frame-visible",
11964 /* Handling it at such a low-level causes read_key_sequence to get
11965 * confused because it doesn't realize that the current_buffer was
11966 * changed by read_char.
11968 * initial_define_lispy_key (Vspecial_event_map, "select-window",
11969 * "handle-select-window"); */
11970 initial_define_lispy_key (Vspecial_event_map
, "save-session",
11971 "handle-save-session");
11974 /* Mark the pointers in the kboard objects.
11975 Called by the Fgarbage_collector. */
11981 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
11983 if (kb
->kbd_macro_buffer
)
11984 for (p
= kb
->kbd_macro_buffer
; p
< kb
->kbd_macro_ptr
; p
++)
11986 mark_object (kb
->Voverriding_terminal_local_map
);
11987 mark_object (kb
->Vlast_command
);
11988 mark_object (kb
->Vreal_last_command
);
11989 mark_object (kb
->Vkeyboard_translate_table
);
11990 mark_object (kb
->Vprefix_arg
);
11991 mark_object (kb
->Vlast_prefix_arg
);
11992 mark_object (kb
->kbd_queue
);
11993 mark_object (kb
->defining_kbd_macro
);
11994 mark_object (kb
->Vlast_kbd_macro
);
11995 mark_object (kb
->Vsystem_key_alist
);
11996 mark_object (kb
->system_key_syms
);
11997 mark_object (kb
->Vlocal_function_key_map
);
11998 mark_object (kb
->Vlocal_key_translation_map
);
11999 mark_object (kb
->Vdefault_minibuffer_frame
);
12000 mark_object (kb
->echo_string
);
12003 struct input_event
*event
;
12004 for (event
= kbd_fetch_ptr
; event
!= kbd_store_ptr
; event
++)
12006 if (event
== kbd_buffer
+ KBD_BUFFER_SIZE
)
12007 event
= kbd_buffer
;
12008 if (event
->kind
!= SELECTION_REQUEST_EVENT
12009 && event
->kind
!= SELECTION_CLEAR_EVENT
)
12011 mark_object (event
->x
);
12012 mark_object (event
->y
);
12014 mark_object (event
->frame_or_window
);
12015 mark_object (event
->arg
);
12020 /* arch-tag: 774e34d7-6d31-42f3-8397-e079a4e4c9ca
12021 (do not change this comment) */