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 executed. */
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 frame in which the last input event occurred, or Qmacro if the
387 last event came from a macro. We use this to determine when to
388 generate switch-frame events. This may be cleared by functions
389 like Fselect_frame, to make sure that a switch-frame event is
390 generated by the next character. */
391 Lisp_Object internal_last_event_frame
;
393 /* A user-visible version of the above, intended to allow users to
394 figure out where the last event came from, if the event doesn't
395 carry that information itself (i.e. if it was a character). */
396 Lisp_Object Vlast_event_frame
;
398 /* The timestamp of the last input event we received from the X server.
399 X Windows wants this for selection ownership. */
400 unsigned long last_event_timestamp
;
402 Lisp_Object Qself_insert_command
;
403 Lisp_Object Qforward_char
;
404 Lisp_Object Qbackward_char
;
405 Lisp_Object Qundefined
;
406 Lisp_Object Qtimer_event_handler
;
408 /* read_key_sequence stores here the command definition of the
409 key sequence that it reads. */
410 Lisp_Object read_key_sequence_cmd
;
412 /* Echo unfinished commands after this many seconds of pause. */
413 Lisp_Object Vecho_keystrokes
;
415 /* Form to evaluate (if non-nil) when Emacs is started. */
416 Lisp_Object Vtop_level
;
418 /* If non-nil, this implements the current input method. */
419 Lisp_Object Vinput_method_function
;
420 Lisp_Object Qinput_method_function
;
422 /* When we call Vinput_method_function,
423 this holds the echo area message that was just erased. */
424 Lisp_Object Vinput_method_previous_message
;
426 /* Non-nil means deactivate the mark at end of this command. */
427 Lisp_Object Vdeactivate_mark
;
429 /* Menu bar specified in Lucid Emacs fashion. */
431 Lisp_Object Vlucid_menu_bar_dirty_flag
;
432 Lisp_Object Qrecompute_lucid_menubar
, Qactivate_menubar_hook
;
434 Lisp_Object Qecho_area_clear_hook
;
436 /* Hooks to run before and after each command. */
437 Lisp_Object Qpre_command_hook
, Vpre_command_hook
;
438 Lisp_Object Qpost_command_hook
, Vpost_command_hook
;
439 Lisp_Object Qcommand_hook_internal
, Vcommand_hook_internal
;
441 /* Parent keymap of terminal-local function-key-map instances. */
442 Lisp_Object Vfunction_key_map
;
444 /* Parent keymap of terminal-local key-translation-map instances. */
445 Lisp_Object Vkey_translation_map
;
447 /* List of deferred actions to be performed at a later time.
448 The precise format isn't relevant here; we just check whether it is nil. */
449 Lisp_Object Vdeferred_action_list
;
451 /* Function to call to handle deferred actions, when there are any. */
452 Lisp_Object Vdeferred_action_function
;
453 Lisp_Object Qdeferred_action_function
;
455 Lisp_Object Qinput_method_exit_on_first_char
;
456 Lisp_Object Qinput_method_use_echo_area
;
458 /* File in which we write all commands we read. */
461 /* Nonzero if input is available. */
464 extern char *pending_malloc_warning
;
466 /* Circular buffer for pre-read keyboard input. */
468 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
470 /* Pointer to next available character in kbd_buffer.
471 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
472 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the
473 next available char is in kbd_buffer[0]. */
474 static struct input_event
*kbd_fetch_ptr
;
476 /* Pointer to next place to store character in kbd_buffer. This
477 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
478 character should go in kbd_buffer[0]. */
479 static struct input_event
* volatile kbd_store_ptr
;
481 /* The above pair of variables forms a "queue empty" flag. When we
482 enqueue a non-hook event, we increment kbd_store_ptr. When we
483 dequeue a non-hook event, we increment kbd_fetch_ptr. We say that
484 there is input available iff the two pointers are not equal.
486 Why not just have a flag set and cleared by the enqueuing and
487 dequeuing functions? Such a flag could be screwed up by interrupts
488 at inopportune times. */
490 /* If this flag is non-nil, we check mouse_moved to see when the
491 mouse moves, and motion events will appear in the input stream.
492 Otherwise, mouse motion is ignored. */
493 Lisp_Object do_mouse_tracking
;
495 /* Symbols to head events. */
496 Lisp_Object Qmouse_movement
;
497 Lisp_Object Qscroll_bar_movement
;
498 Lisp_Object Qswitch_frame
;
499 Lisp_Object Qdelete_frame
;
500 Lisp_Object Qiconify_frame
;
501 Lisp_Object Qmake_frame_visible
;
502 Lisp_Object Qselect_window
;
503 Lisp_Object Qhelp_echo
;
506 Lisp_Object Qmouse_fixup_help_message
;
509 /* Symbols to denote kinds of events. */
510 Lisp_Object Qfunction_key
;
511 Lisp_Object Qmouse_click
;
512 #if defined (WINDOWSNT) || defined (MAC_OS)
513 Lisp_Object Qlanguage_change
;
515 Lisp_Object Qdrag_n_drop
;
516 Lisp_Object Qsave_session
;
518 Lisp_Object Qmac_apple_event
;
521 /* Lisp_Object Qmouse_movement; - also an event header */
523 /* Properties of event headers. */
524 Lisp_Object Qevent_kind
;
525 Lisp_Object Qevent_symbol_elements
;
527 /* menu item parts */
528 Lisp_Object Qmenu_alias
;
529 Lisp_Object Qmenu_enable
;
530 Lisp_Object QCenable
, QCvisible
, QChelp
, QCfilter
, QCkeys
, QCkey_sequence
;
531 Lisp_Object QCbutton
, QCtoggle
, QCradio
;
532 extern Lisp_Object Vdefine_key_rebound_commands
;
533 extern Lisp_Object Qmenu_item
;
535 /* An event header symbol HEAD may have a property named
536 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
537 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
538 mask of modifiers applied to it. If present, this is used to help
539 speed up parse_modifiers. */
540 Lisp_Object Qevent_symbol_element_mask
;
542 /* An unmodified event header BASE may have a property named
543 Qmodifier_cache, which is an alist mapping modifier masks onto
544 modified versions of BASE. If present, this helps speed up
546 Lisp_Object Qmodifier_cache
;
548 /* Symbols to use for parts of windows. */
549 Lisp_Object Qmode_line
;
550 Lisp_Object Qvertical_line
;
551 Lisp_Object Qvertical_scroll_bar
;
552 Lisp_Object Qmenu_bar
;
553 extern Lisp_Object Qleft_margin
, Qright_margin
;
554 extern Lisp_Object Qleft_fringe
, Qright_fringe
;
555 extern Lisp_Object QCmap
;
557 Lisp_Object
recursive_edit_unwind (), command_loop ();
558 Lisp_Object
Fthis_command_keys ();
559 Lisp_Object Qextended_command_history
;
560 EMACS_TIME
timer_check ();
562 extern Lisp_Object Vhistory_length
, Vtranslation_table_for_input
;
564 extern char *x_get_keysym_name ();
566 static void record_menu_key ();
567 static int echo_length ();
569 Lisp_Object Qpolling_period
;
571 /* List of absolute timers. Appears in order of next scheduled event. */
572 Lisp_Object Vtimer_list
;
574 /* List of idle time timers. Appears in order of next scheduled event. */
575 Lisp_Object Vtimer_idle_list
;
577 /* Incremented whenever a timer is run. */
580 extern Lisp_Object Vprint_level
, Vprint_length
;
582 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
584 EMACS_TIME
*input_available_clear_time
;
586 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
587 Default is 1 if INTERRUPT_INPUT is defined. */
590 /* Nonzero while interrupts are temporarily deferred during redisplay. */
591 int interrupts_deferred
;
593 /* Allow m- file to inhibit use of FIONREAD. */
594 #ifdef BROKEN_FIONREAD
598 /* We are unable to use interrupts if FIONREAD is not available,
599 so flush SIGIO so we won't try. */
600 #if !defined (FIONREAD)
606 /* If we support a window system, turn on the code to poll periodically
607 to detect C-g. It isn't actually used when doing interrupt input. */
608 #if defined(HAVE_WINDOW_SYSTEM) && !defined(USE_ASYNC_EVENTS)
609 #define POLL_FOR_INPUT
612 /* After a command is executed, if point is moved into a region that
613 has specific properties (e.g. composition, display), we adjust
614 point to the boundary of the region. But, if a command sets this
615 variable to non-nil, we suppress this point adjustment. This
616 variable is set to nil before reading a command. */
618 Lisp_Object Vdisable_point_adjustment
;
620 /* If non-nil, always disable point adjustment. */
622 Lisp_Object Vglobal_disable_point_adjustment
;
624 /* The time when Emacs started being idle. */
626 static EMACS_TIME timer_idleness_start_time
;
628 /* After Emacs stops being idle, this saves the last value
629 of timer_idleness_start_time from when it was idle. */
631 static EMACS_TIME timer_last_idleness_start_time
;
634 /* Global variable declarations. */
636 /* Flags for readable_events. */
637 #define READABLE_EVENTS_DO_TIMERS_NOW (1 << 0)
638 #define READABLE_EVENTS_FILTER_EVENTS (1 << 1)
639 #define READABLE_EVENTS_IGNORE_SQUEEZABLES (1 << 2)
641 /* Function for init_keyboard to call with no args (if nonzero). */
642 void (*keyboard_init_hook
) ();
644 static int read_avail_input
P_ ((int));
645 static void get_input_pending
P_ ((int *, int));
646 static int readable_events
P_ ((int));
647 static Lisp_Object read_char_x_menu_prompt
P_ ((int, Lisp_Object
*,
648 Lisp_Object
, int *));
649 static Lisp_Object
read_char_x_menu_prompt ();
650 static Lisp_Object read_char_minibuf_menu_prompt
P_ ((int, int,
652 static Lisp_Object make_lispy_event
P_ ((struct input_event
*));
654 static Lisp_Object make_lispy_movement
P_ ((struct frame
*, Lisp_Object
,
655 enum scroll_bar_part
,
656 Lisp_Object
, Lisp_Object
,
659 static Lisp_Object modify_event_symbol
P_ ((int, unsigned, Lisp_Object
,
660 Lisp_Object
, char **,
661 Lisp_Object
*, unsigned));
662 static Lisp_Object make_lispy_switch_frame
P_ ((Lisp_Object
));
663 static int parse_solitary_modifier
P_ ((Lisp_Object
));
664 static int parse_solitary_modifier ();
665 static void save_getcjmp
P_ ((jmp_buf));
666 static void save_getcjmp ();
667 static void restore_getcjmp
P_ ((jmp_buf));
668 static Lisp_Object apply_modifiers
P_ ((int, Lisp_Object
));
669 static void clear_event
P_ ((struct input_event
*));
670 static void any_kboard_state
P_ ((void));
671 static Lisp_Object restore_kboard_configuration
P_ ((Lisp_Object
));
672 static SIGTYPE interrupt_signal
P_ ((int signalnum
));
673 static void handle_interrupt
P_ ((void));
674 static void timer_start_idle
P_ ((void));
675 static void timer_stop_idle
P_ ((void));
676 static void timer_resume_idle
P_ ((void));
678 /* Nonzero means don't try to suspend even if the operating system seems
680 static int cannot_suspend
;
682 extern Lisp_Object Qidentity
, Qonly
;
684 /* Install the string STR as the beginning of the string of echoing,
685 so that it serves as a prompt for the next character.
686 Also start echoing. */
692 current_kboard
->echo_string
= str
;
693 current_kboard
->echo_after_prompt
= SCHARS (str
);
697 /* Add C to the echo string, if echoing is going on.
698 C can be a character, which is printed prettily ("M-C-x" and all that
699 jazz), or a symbol, whose name is printed. */
705 if (current_kboard
->immediate_echo
)
707 int size
= KEY_DESCRIPTION_SIZE
+ 100;
708 char *buffer
= (char *) alloca (size
);
710 Lisp_Object echo_string
;
712 echo_string
= current_kboard
->echo_string
;
714 /* If someone has passed us a composite event, use its head symbol. */
719 ptr
= push_key_description (XINT (c
), ptr
, 1);
721 else if (SYMBOLP (c
))
723 Lisp_Object name
= SYMBOL_NAME (c
);
724 int nbytes
= SBYTES (name
);
726 if (size
- (ptr
- buffer
) < nbytes
)
728 int offset
= ptr
- buffer
;
729 size
= max (2 * size
, size
+ nbytes
);
730 buffer
= (char *) alloca (size
);
731 ptr
= buffer
+ offset
;
734 ptr
+= copy_text (SDATA (name
), ptr
, nbytes
,
735 STRING_MULTIBYTE (name
), 1);
738 if ((NILP (echo_string
) || SCHARS (echo_string
) == 0)
741 const char *text
= " (Type ? for further options)";
742 int len
= strlen (text
);
744 if (size
- (ptr
- buffer
) < len
)
746 int offset
= ptr
- buffer
;
748 buffer
= (char *) alloca (size
);
749 ptr
= buffer
+ offset
;
752 bcopy (text
, ptr
, len
);
756 /* Replace a dash from echo_dash with a space, otherwise
757 add a space at the end as a separator between keys. */
758 if (STRINGP (echo_string
)
759 && SCHARS (echo_string
) > 1)
761 Lisp_Object last_char
, prev_char
, idx
;
763 idx
= make_number (SCHARS (echo_string
) - 2);
764 prev_char
= Faref (echo_string
, idx
);
766 idx
= make_number (SCHARS (echo_string
) - 1);
767 last_char
= Faref (echo_string
, idx
);
769 /* We test PREV_CHAR to make sure this isn't the echoing
771 if (XINT (last_char
) == '-' && XINT (prev_char
) != ' ')
772 Faset (echo_string
, idx
, make_number (' '));
774 echo_string
= concat2 (echo_string
, build_string (" "));
777 current_kboard
->echo_string
778 = concat2 (echo_string
, make_string (buffer
, ptr
- buffer
));
784 /* Temporarily add a dash to the end of the echo string if it's not
785 empty, so that it serves as a mini-prompt for the very next character. */
790 /* Do nothing if not echoing at all. */
791 if (NILP (current_kboard
->echo_string
))
794 if (!current_kboard
->immediate_echo
795 && SCHARS (current_kboard
->echo_string
) == 0)
798 /* Do nothing if we just printed a prompt. */
799 if (current_kboard
->echo_after_prompt
800 == SCHARS (current_kboard
->echo_string
))
803 /* Do nothing if we have already put a dash at the end. */
804 if (SCHARS (current_kboard
->echo_string
) > 1)
806 Lisp_Object last_char
, prev_char
, idx
;
808 idx
= make_number (SCHARS (current_kboard
->echo_string
) - 2);
809 prev_char
= Faref (current_kboard
->echo_string
, idx
);
811 idx
= make_number (SCHARS (current_kboard
->echo_string
) - 1);
812 last_char
= Faref (current_kboard
->echo_string
, idx
);
814 if (XINT (last_char
) == '-' && XINT (prev_char
) != ' ')
818 /* Put a dash at the end of the buffer temporarily,
819 but make it go away when the next character is added. */
820 current_kboard
->echo_string
= concat2 (current_kboard
->echo_string
,
825 /* Display the current echo string, and begin echoing if not already
831 if (!current_kboard
->immediate_echo
)
834 current_kboard
->immediate_echo
= 1;
836 for (i
= 0; i
< this_command_key_count
; i
++)
840 /* Set before_command_echo_length to the value that would
841 have been saved before the start of this subcommand in
842 command_loop_1, if we had already been echoing then. */
843 if (i
== this_single_command_key_start
)
844 before_command_echo_length
= echo_length ();
846 c
= XVECTOR (this_command_keys
)->contents
[i
];
847 if (! (EVENT_HAS_PARAMETERS (c
)
848 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
852 /* Set before_command_echo_length to the value that would
853 have been saved before the start of this subcommand in
854 command_loop_1, if we had already been echoing then. */
855 if (this_command_key_count
== this_single_command_key_start
)
856 before_command_echo_length
= echo_length ();
858 /* Put a dash at the end to invite the user to type more. */
863 message3_nolog (current_kboard
->echo_string
,
864 SBYTES (current_kboard
->echo_string
),
865 STRING_MULTIBYTE (current_kboard
->echo_string
));
868 /* Record in what buffer we echoed, and from which kboard. */
869 echo_message_buffer
= echo_area_buffer
[0];
870 echo_kboard
= current_kboard
;
872 if (waiting_for_input
&& !NILP (Vquit_flag
))
873 quit_throw_to_read_char ();
876 /* Turn off echoing, for the start of a new command. */
881 current_kboard
->immediate_echo
= 0;
882 current_kboard
->echo_after_prompt
= -1;
883 current_kboard
->echo_string
= Qnil
;
884 ok_to_echo_at_next_pause
= NULL
;
886 echo_message_buffer
= Qnil
;
889 /* Return the length of the current echo string. */
894 return (STRINGP (current_kboard
->echo_string
)
895 ? SCHARS (current_kboard
->echo_string
)
899 /* Truncate the current echo message to its first LEN chars.
900 This and echo_char get used by read_key_sequence when the user
901 switches frames while entering a key sequence. */
904 echo_truncate (nchars
)
907 if (STRINGP (current_kboard
->echo_string
))
908 current_kboard
->echo_string
909 = Fsubstring (current_kboard
->echo_string
,
910 make_number (0), make_number (nchars
));
911 truncate_echo_area (nchars
);
915 /* Functions for manipulating this_command_keys. */
917 add_command_key (key
)
920 #if 0 /* Not needed after we made Freset_this_command_lengths
921 do the job immediately. */
922 /* If reset-this-command-length was called recently, obey it now.
923 See the doc string of that function for an explanation of why. */
924 if (before_command_restore_flag
)
926 this_command_key_count
= before_command_key_count_1
;
927 if (this_command_key_count
< this_single_command_key_start
)
928 this_single_command_key_start
= this_command_key_count
;
929 echo_truncate (before_command_echo_length_1
);
930 before_command_restore_flag
= 0;
934 if (this_command_key_count
>= ASIZE (this_command_keys
))
935 this_command_keys
= larger_vector (this_command_keys
,
936 2 * ASIZE (this_command_keys
),
939 AREF (this_command_keys
, this_command_key_count
) = key
;
940 ++this_command_key_count
;
947 int count
= SPECPDL_INDEX ();
950 if (command_loop_level
> 0)
952 specbind (Qstandard_output
, Qt
);
953 specbind (Qstandard_input
, Qt
);
956 #ifdef HAVE_X_WINDOWS
957 /* The command loop has started an hourglass timer, so we have to
958 cancel it here, otherwise it will fire because the recursive edit
959 can take some time. Do not check for display_hourglass_p here,
960 because it could already be nil. */
964 /* This function may have been called from a debugger called from
965 within redisplay, for instance by Edebugging a function called
966 from fontification-functions. We want to allow redisplay in
967 the debugging session.
969 The recursive edit is left with a `(throw exit ...)'. The `exit'
970 tag is not caught anywhere in redisplay, i.e. when we leave the
971 recursive edit, the original redisplay leading to the recursive
972 edit will be unwound. The outcome should therefore be safe. */
973 specbind (Qinhibit_redisplay
, Qnil
);
976 val
= command_loop ();
978 Fsignal (Qquit
, Qnil
);
979 /* Handle throw from read_minibuf when using minibuffer
980 while it's active but we're in another window. */
982 Fsignal (Qerror
, Fcons (val
, Qnil
));
984 return unbind_to (count
, Qnil
);
987 /* When an auto-save happens, record the "time", and don't do again soon. */
992 last_auto_save
= num_nonmacro_input_events
;
995 /* Make an auto save happen as soon as possible at command level. */
998 force_auto_save_soon ()
1000 last_auto_save
= - auto_save_interval
- 1;
1002 record_asynch_buffer_change ();
1005 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
1006 doc
: /* Invoke the editor command loop recursively.
1007 To get out of the recursive edit, a command can do `(throw 'exit nil)';
1008 that tells this function to return.
1009 Alternatively, `(throw 'exit t)' makes this function signal an error.
1010 This function is called by the editor initialization to begin editing. */)
1013 int count
= SPECPDL_INDEX ();
1016 /* If we enter while input is blocked, don't lock up here.
1017 This may happen through the debugger during redisplay. */
1018 if (INPUT_BLOCKED_P
)
1021 command_loop_level
++;
1022 update_mode_lines
= 1;
1024 if (command_loop_level
1025 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
1026 buffer
= Fcurrent_buffer ();
1030 /* If we leave recursive_edit_1 below with a `throw' for instance,
1031 like it is done in the splash screen display, we have to
1032 make sure that we restore single_kboard as command_loop_1
1033 would have done if it were left normally. */
1034 temporarily_switch_to_single_kboard (FRAME_KBOARD (SELECTED_FRAME ()));
1035 record_unwind_protect (recursive_edit_unwind
, buffer
);
1037 recursive_edit_1 ();
1038 return unbind_to (count
, Qnil
);
1042 recursive_edit_unwind (buffer
)
1045 if (BUFFERP (buffer
))
1046 Fset_buffer (buffer
);
1048 command_loop_level
--;
1049 update_mode_lines
= 1;
1058 #if 0 /* Theory: if there's anything in Vunread_command_events,
1059 it will right away be read by read_key_sequence,
1060 and then if we do switch KBOARDS, it will go into the side
1061 queue then. So we don't need to do anything special here -- rms. */
1062 if (CONSP (Vunread_command_events
))
1064 current_kboard
->kbd_queue
1065 = nconc2 (Vunread_command_events
, current_kboard
->kbd_queue
);
1066 current_kboard
->kbd_queue_has_data
= 1;
1068 Vunread_command_events
= Qnil
;
1074 /* Switch to the single-kboard state, making current_kboard
1075 the only KBOARD from which further input is accepted. */
1078 single_kboard_state ()
1085 /* If we're in single_kboard state for kboard KBOARD,
1089 not_single_kboard_state (kboard
)
1093 if (kboard
== current_kboard
)
1098 /* Maintain a stack of kboards, so other parts of Emacs
1099 can switch temporarily to the kboard of a given frame
1100 and then revert to the previous status. */
1105 struct kboard_stack
*next
;
1108 static struct kboard_stack
*kboard_stack
;
1115 struct kboard_stack
*p
1116 = (struct kboard_stack
*) xmalloc (sizeof (struct kboard_stack
));
1118 p
->next
= kboard_stack
;
1119 p
->kboard
= current_kboard
;
1127 push_frame_kboard (f
)
1130 push_kboard (f
->device
->kboard
);
1138 struct kboard_stack
*p
= kboard_stack
;
1140 current_kboard
= NULL
;
1141 for (d
= device_list
; d
; d
= d
->next_device
)
1143 if (d
->kboard
== p
->kboard
)
1145 current_kboard
= p
->kboard
;
1149 if (current_kboard
== NULL
)
1151 /* The display we remembered has been deleted. */
1152 current_kboard
= FRAME_KBOARD (SELECTED_FRAME ());
1154 kboard_stack
= p
->next
;
1159 /* Switch to single_kboard mode. If K is non-nil, set it as the
1160 current keyboard. Use record_unwind_protect to return to the
1161 previous state later. */
1164 temporarily_switch_to_single_kboard (k
)
1168 int was_locked
= single_kboard
;
1172 push_kboard (current_kboard
);
1173 single_kboard_state ();
1174 record_unwind_protect (restore_kboard_configuration
,
1175 (was_locked
? Qt
: Qnil
));
1180 record_single_kboard_state ()
1182 push_kboard (current_kboard
);
1183 record_unwind_protect (restore_kboard_configuration
,
1184 (single_kboard
? Qt
: Qnil
));
1188 restore_kboard_configuration (was_locked
)
1189 Lisp_Object was_locked
;
1191 if (NILP (was_locked
))
1192 any_kboard_state ();
1194 single_kboard_state ();
1199 /* Handle errors that are not handled at inner levels
1200 by printing an error message and returning to the editor command loop. */
1206 Lisp_Object old_level
, old_length
;
1207 char macroerror
[50];
1209 #ifdef HAVE_X_WINDOWS
1210 if (display_hourglass_p
)
1211 cancel_hourglass ();
1214 if (!NILP (executing_kbd_macro
))
1216 if (executing_kbd_macro_iterations
== 1)
1217 sprintf (macroerror
, "After 1 kbd macro iteration: ");
1219 sprintf (macroerror
, "After %d kbd macro iterations: ",
1220 executing_kbd_macro_iterations
);
1225 Vstandard_output
= Qt
;
1226 Vstandard_input
= Qt
;
1227 Vexecuting_kbd_macro
= Qnil
;
1228 executing_kbd_macro
= Qnil
;
1229 current_kboard
->Vprefix_arg
= Qnil
;
1230 current_kboard
->Vlast_prefix_arg
= Qnil
;
1233 /* Avoid unquittable loop if data contains a circular list. */
1234 old_level
= Vprint_level
;
1235 old_length
= Vprint_length
;
1236 XSETFASTINT (Vprint_level
, 10);
1237 XSETFASTINT (Vprint_length
, 10);
1238 cmd_error_internal (data
, macroerror
);
1239 Vprint_level
= old_level
;
1240 Vprint_length
= old_length
;
1244 Vinhibit_quit
= Qnil
;
1246 if (command_loop_level
== 0 && minibuf_level
== 0)
1247 any_kboard_state ();
1250 return make_number (0);
1253 /* Take actions on handling an error. DATA is the data that describes
1256 CONTEXT is a C-string containing ASCII characters only which
1257 describes the context in which the error happened. If we need to
1258 generalize CONTEXT to allow multibyte characters, make it a Lisp
1262 cmd_error_internal (data
, context
)
1267 int kill_emacs_p
= 0;
1268 struct frame
*sf
= SELECTED_FRAME ();
1272 clear_message (1, 0);
1274 /* If the window system or terminal frame hasn't been initialized
1275 yet, or we're not interactive, it's best to dump this message out
1276 to stderr and exit. */
1277 if (!sf
->glyphs_initialized_p
1278 || FRAME_INITIAL_P (sf
)
1281 stream
= Qexternal_debugging_output
;
1287 message_log_maybe_newline ();
1292 /* The immediate context is not interesting for Quits,
1293 since they are asyncronous. */
1294 if (EQ (XCAR (data
), Qquit
))
1295 Vsignaling_function
= Qnil
;
1297 print_error_message (data
, stream
, context
, Vsignaling_function
);
1299 Vsignaling_function
= Qnil
;
1301 /* If the window system or terminal frame hasn't been initialized
1302 yet, or we're in -batch mode, this error should cause Emacs to exit. */
1306 Fkill_emacs (make_number (-1));
1310 Lisp_Object
command_loop_1 ();
1311 Lisp_Object
command_loop_2 ();
1312 Lisp_Object
top_level_1 ();
1314 /* Entry to editor-command-loop.
1315 This level has the catches for exiting/returning to editor command loop.
1316 It returns nil to exit recursive edit, t to abort it. */
1321 if (command_loop_level
> 0 || minibuf_level
> 0)
1324 val
= internal_catch (Qexit
, command_loop_2
, Qnil
);
1325 executing_kbd_macro
= Qnil
;
1331 internal_catch (Qtop_level
, top_level_1
, Qnil
);
1332 /* Reset single_kboard in case top-level set it while
1333 evaluating an -f option, or we are stuck there for some
1335 any_kboard_state ();
1336 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
1337 executing_kbd_macro
= Qnil
;
1339 /* End of file in -batch run causes exit here. */
1345 /* Here we catch errors in execution of commands within the
1346 editing loop, and reenter the editing loop.
1347 When there is an error, cmd_error runs and returns a non-nil
1348 value to us. A value of nil means that command_loop_1 itself
1349 returned due to end of file (or end of kbd macro). */
1354 register Lisp_Object val
;
1357 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
1358 while (!NILP (val
));
1366 return Feval (Vtop_level
);
1372 /* On entry to the outer level, run the startup file */
1373 if (!NILP (Vtop_level
))
1374 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
1375 else if (!NILP (Vpurify_flag
))
1376 message ("Bare impure Emacs (standard Lisp code not loaded)");
1378 message ("Bare Emacs (standard Lisp code not loaded)");
1382 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
1383 doc
: /* Exit all recursive editing levels. */)
1386 #ifdef HAVE_X_WINDOWS
1387 if (display_hourglass_p
)
1388 cancel_hourglass ();
1391 /* Unblock input if we enter with input blocked. This may happen if
1392 redisplay traps e.g. during tool-bar update with input blocked. */
1393 while (INPUT_BLOCKED_P
)
1396 return Fthrow (Qtop_level
, Qnil
);
1399 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
1400 doc
: /* Exit from the innermost recursive edit or minibuffer. */)
1403 if (command_loop_level
> 0 || minibuf_level
> 0)
1404 Fthrow (Qexit
, Qnil
);
1406 error ("No recursive edit is in progress");
1410 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
1411 doc
: /* Abort the command that requested this recursive edit or minibuffer input. */)
1414 if (command_loop_level
> 0 || minibuf_level
> 0)
1417 error ("No recursive edit is in progress");
1421 /* This is the actual command reading loop,
1422 sans error-handling encapsulation. */
1424 static int read_key_sequence
P_ ((Lisp_Object
*, int, Lisp_Object
,
1426 void safe_run_hooks
P_ ((Lisp_Object
));
1427 static void adjust_point_for_property
P_ ((int, int));
1429 /* Cancel hourglass from protect_unwind.
1431 #ifdef HAVE_X_WINDOWS
1433 cancel_hourglass_unwind (arg
)
1436 cancel_hourglass ();
1447 Lisp_Object keybuf
[30];
1450 int prev_modiff
= 0;
1451 struct buffer
*prev_buffer
= NULL
;
1453 int was_locked
= single_kboard
;
1455 int already_adjusted
= 0;
1457 current_kboard
->Vprefix_arg
= Qnil
;
1458 current_kboard
->Vlast_prefix_arg
= Qnil
;
1459 Vdeactivate_mark
= Qnil
;
1460 waiting_for_input
= 0;
1464 this_command_key_count
= 0;
1465 this_command_key_count_reset
= 0;
1466 this_single_command_key_start
= 0;
1468 if (NILP (Vmemory_full
))
1470 /* Make sure this hook runs after commands that get errors and
1471 throw to top level. */
1472 /* Note that the value cell will never directly contain nil
1473 if the symbol is a local variable. */
1474 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1475 safe_run_hooks (Qpost_command_hook
);
1477 /* If displaying a message, resize the echo area window to fit
1478 that message's size exactly. */
1479 if (!NILP (echo_area_buffer
[0]))
1480 resize_echo_area_exactly ();
1482 if (!NILP (Vdeferred_action_list
))
1483 safe_run_hooks (Qdeferred_action_function
);
1486 /* Do this after running Vpost_command_hook, for consistency. */
1487 current_kboard
->Vlast_command
= Vthis_command
;
1488 current_kboard
->Vreal_last_command
= real_this_command
;
1492 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
1495 /* Make sure the current window's buffer is selected. */
1496 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1497 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1499 /* Display any malloc warning that just came out. Use while because
1500 displaying one warning can cause another. */
1502 while (pending_malloc_warning
)
1503 display_malloc_warning ();
1507 Vdeactivate_mark
= Qnil
;
1509 /* If minibuffer on and echo area in use,
1510 wait a short time and redraw minibuffer. */
1513 && !NILP (echo_area_buffer
[0])
1514 && EQ (minibuf_window
, echo_area_window
)
1515 && NUMBERP (Vminibuffer_message_timeout
))
1517 /* Bind inhibit-quit to t so that C-g gets read in
1518 rather than quitting back to the minibuffer. */
1519 int count
= SPECPDL_INDEX ();
1520 specbind (Qinhibit_quit
, Qt
);
1522 Fsit_for (Vminibuffer_message_timeout
, Qnil
, Qnil
);
1523 /* Clear the echo area. */
1525 safe_run_hooks (Qecho_area_clear_hook
);
1527 unbind_to (count
, Qnil
);
1529 /* If a C-g came in before, treat it as input now. */
1530 if (!NILP (Vquit_flag
))
1533 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1538 alloca (0); /* Cause a garbage collection now */
1539 /* Since we can free the most stuff here. */
1540 #endif /* C_ALLOCA */
1543 /* Select the frame that the last event came from. Usually,
1544 switch-frame events will take care of this, but if some lisp
1545 code swallows a switch-frame event, we'll fix things up here.
1546 Is this a good idea? */
1547 if (FRAMEP (internal_last_event_frame
)
1548 && !EQ (internal_last_event_frame
, selected_frame
))
1549 Fselect_frame (internal_last_event_frame
);
1551 /* If it has changed current-menubar from previous value,
1552 really recompute the menubar from the value. */
1553 if (! NILP (Vlucid_menu_bar_dirty_flag
)
1554 && !NILP (Ffboundp (Qrecompute_lucid_menubar
)))
1555 call0 (Qrecompute_lucid_menubar
);
1557 before_command_key_count
= this_command_key_count
;
1558 before_command_echo_length
= echo_length ();
1560 Vthis_command
= Qnil
;
1561 real_this_command
= Qnil
;
1562 Vthis_original_command
= Qnil
;
1564 /* Read next key sequence; i gets its length. */
1565 i
= read_key_sequence (keybuf
, sizeof keybuf
/ sizeof keybuf
[0],
1568 /* A filter may have run while we were reading the input. */
1569 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
1571 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1572 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1576 /* Now we have read a key sequence of length I,
1577 or else I is 0 and we found end of file. */
1579 if (i
== 0) /* End of file -- happens only in */
1580 return Qnil
; /* a kbd macro, at the end. */
1581 /* -1 means read_key_sequence got a menu that was rejected.
1582 Just loop around and read another command. */
1586 this_command_key_count
= 0;
1587 this_command_key_count_reset
= 0;
1588 this_single_command_key_start
= 0;
1592 last_command_char
= keybuf
[i
- 1];
1594 /* If the previous command tried to force a specific window-start,
1595 forget about that, in case this command moves point far away
1596 from that position. But also throw away beg_unchanged and
1597 end_unchanged information in that case, so that redisplay will
1598 update the whole window properly. */
1599 if (!NILP (XWINDOW (selected_window
)->force_start
))
1602 XWINDOW (selected_window
)->force_start
= Qnil
;
1603 b
= XBUFFER (XWINDOW (selected_window
)->buffer
);
1604 BUF_BEG_UNCHANGED (b
) = BUF_END_UNCHANGED (b
) = 0;
1607 cmd
= read_key_sequence_cmd
;
1608 if (!NILP (Vexecuting_kbd_macro
))
1610 if (!NILP (Vquit_flag
))
1612 Vexecuting_kbd_macro
= Qt
;
1613 QUIT
; /* Make some noise. */
1614 /* Will return since macro now empty. */
1618 /* Do redisplay processing after this command except in special
1619 cases identified below. */
1620 prev_buffer
= current_buffer
;
1621 prev_modiff
= MODIFF
;
1622 last_point_position
= PT
;
1623 XSETBUFFER (last_point_position_buffer
, prev_buffer
);
1625 /* By default, we adjust point to a boundary of a region that
1626 has such a property that should be treated intangible
1627 (e.g. composition, display). But, some commands will set
1628 this variable differently. */
1629 Vdisable_point_adjustment
= Qnil
;
1631 /* Process filters and timers may have messed with deactivate-mark.
1632 reset it before we execute the command. */
1633 Vdeactivate_mark
= Qnil
;
1635 /* Remap command through active keymaps */
1636 Vthis_original_command
= cmd
;
1640 if (cmd1
= Fcommand_remapping (cmd
), !NILP (cmd1
))
1644 /* Execute the command. */
1646 Vthis_command
= cmd
;
1647 real_this_command
= cmd
;
1648 /* Note that the value cell will never directly contain nil
1649 if the symbol is a local variable. */
1650 if (!NILP (Vpre_command_hook
) && !NILP (Vrun_hooks
))
1651 safe_run_hooks (Qpre_command_hook
);
1653 already_adjusted
= 0;
1655 if (NILP (Vthis_command
))
1657 /* nil means key is undefined. */
1658 Lisp_Object keys
= Fvector (i
, keybuf
);
1659 keys
= Fkey_description (keys
, Qnil
);
1661 message_with_string ("%s is undefined", keys
, 0);
1662 current_kboard
->defining_kbd_macro
= Qnil
;
1663 update_mode_lines
= 1;
1664 current_kboard
->Vprefix_arg
= Qnil
;
1668 if (NILP (current_kboard
->Vprefix_arg
) && ! no_direct
)
1670 /* In case we jump to directly_done. */
1671 Vcurrent_prefix_arg
= current_kboard
->Vprefix_arg
;
1673 /* Recognize some common commands in common situations and
1674 do them directly. */
1675 if (EQ (Vthis_command
, Qforward_char
) && PT
< ZV
)
1677 struct Lisp_Char_Table
*dp
1678 = window_display_table (XWINDOW (selected_window
));
1679 lose
= FETCH_CHAR (PT_BYTE
);
1681 if (! NILP (Vpost_command_hook
))
1682 /* Put this before calling adjust_point_for_property
1683 so it will only get called once in any case. */
1685 if (current_buffer
== prev_buffer
1686 && last_point_position
!= PT
1687 && NILP (Vdisable_point_adjustment
)
1688 && NILP (Vglobal_disable_point_adjustment
))
1689 adjust_point_for_property (last_point_position
, 0);
1690 already_adjusted
= 1;
1691 if (PT
== last_point_position
+ 1
1693 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1694 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1695 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1696 && (lose
>= 0x20 && lose
< 0x7f)))
1697 : (lose
>= 0x20 && lose
< 0x7f))
1698 /* To extract the case of continuation on
1699 wide-column characters. */
1700 && (WIDTH_BY_CHAR_HEAD (FETCH_BYTE (PT_BYTE
)) == 1)
1701 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1703 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1705 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1707 && !windows_or_buffers_changed
1708 && EQ (current_buffer
->selective_display
, Qnil
)
1709 && !detect_input_pending ()
1710 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1711 && NILP (Vexecuting_kbd_macro
))
1712 direct_output_forward_char (1);
1715 else if (EQ (Vthis_command
, Qbackward_char
) && PT
> BEGV
)
1717 struct Lisp_Char_Table
*dp
1718 = window_display_table (XWINDOW (selected_window
));
1720 lose
= FETCH_CHAR (PT_BYTE
);
1721 if (! NILP (Vpost_command_hook
))
1723 if (current_buffer
== prev_buffer
1724 && last_point_position
!= PT
1725 && NILP (Vdisable_point_adjustment
)
1726 && NILP (Vglobal_disable_point_adjustment
))
1727 adjust_point_for_property (last_point_position
, 0);
1728 already_adjusted
= 1;
1729 if (PT
== last_point_position
- 1
1731 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1732 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1733 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1734 && (lose
>= 0x20 && lose
< 0x7f)))
1735 : (lose
>= 0x20 && lose
< 0x7f))
1736 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1738 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1740 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1742 && !windows_or_buffers_changed
1743 && EQ (current_buffer
->selective_display
, Qnil
)
1744 && !detect_input_pending ()
1745 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1746 && NILP (Vexecuting_kbd_macro
))
1747 direct_output_forward_char (-1);
1750 else if (EQ (Vthis_command
, Qself_insert_command
)
1751 /* Try this optimization only on char keystrokes. */
1752 && NATNUMP (last_command_char
)
1753 && CHAR_VALID_P (XFASTINT (last_command_char
), 0))
1756 = translate_char (Vtranslation_table_for_input
,
1757 XFASTINT (last_command_char
), 0, 0, 0);
1759 if (NILP (Vexecuting_kbd_macro
)
1760 && !EQ (minibuf_window
, selected_window
))
1762 if (!nonundocount
|| nonundocount
>= 20)
1770 lose
= ((XFASTINT (XWINDOW (selected_window
)->last_modified
)
1772 || (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1774 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1776 || MODIFF
<= SAVE_MODIFF
1777 || windows_or_buffers_changed
1778 || !EQ (current_buffer
->selective_display
, Qnil
)
1779 || detect_input_pending ()
1780 || !NILP (XWINDOW (selected_window
)->column_number_displayed
)
1781 || !NILP (Vexecuting_kbd_macro
));
1783 value
= internal_self_insert (c
, 0);
1788 if (! NILP (Vpost_command_hook
))
1789 /* Put this before calling adjust_point_for_property
1790 so it will only get called once in any case. */
1793 /* VALUE == 1 when AFTER-CHANGE functions are
1794 installed which is the case most of the time
1795 because FONT-LOCK installs one. */
1796 if (!lose
&& !value
)
1797 direct_output_for_insert (c
);
1802 /* Here for a command that isn't executed directly */
1805 #ifdef HAVE_X_WINDOWS
1806 int scount
= SPECPDL_INDEX ();
1808 if (display_hourglass_p
1809 && NILP (Vexecuting_kbd_macro
))
1811 record_unwind_protect (cancel_hourglass_unwind
, Qnil
);
1817 if (NILP (current_kboard
->Vprefix_arg
))
1819 Fcommand_execute (Vthis_command
, Qnil
, Qnil
, Qnil
);
1821 #ifdef HAVE_X_WINDOWS
1822 /* Do not check display_hourglass_p here, because
1823 Fcommand_execute could change it, but we should cancel
1824 hourglass cursor anyway.
1825 But don't cancel the hourglass within a macro
1826 just because a command in the macro finishes. */
1827 if (NILP (Vexecuting_kbd_macro
))
1828 unbind_to (scount
, Qnil
);
1833 current_kboard
->Vlast_prefix_arg
= Vcurrent_prefix_arg
;
1835 /* Note that the value cell will never directly contain nil
1836 if the symbol is a local variable. */
1837 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1838 safe_run_hooks (Qpost_command_hook
);
1840 /* If displaying a message, resize the echo area window to fit
1841 that message's size exactly. */
1842 if (!NILP (echo_area_buffer
[0]))
1843 resize_echo_area_exactly ();
1845 if (!NILP (Vdeferred_action_list
))
1846 safe_run_hooks (Qdeferred_action_function
);
1848 /* If there is a prefix argument,
1849 1) We don't want Vlast_command to be ``universal-argument''
1850 (that would be dumb), so don't set Vlast_command,
1851 2) we want to leave echoing on so that the prefix will be
1852 echoed as part of this key sequence, so don't call
1854 3) we want to leave this_command_key_count non-zero, so that
1855 read_char will realize that it is re-reading a character, and
1856 not echo it a second time.
1858 If the command didn't actually create a prefix arg,
1859 but is merely a frame event that is transparent to prefix args,
1860 then the above doesn't apply. */
1861 if (NILP (current_kboard
->Vprefix_arg
) || CONSP (last_command_char
))
1863 current_kboard
->Vlast_command
= Vthis_command
;
1864 current_kboard
->Vreal_last_command
= real_this_command
;
1866 this_command_key_count
= 0;
1867 this_command_key_count_reset
= 0;
1868 this_single_command_key_start
= 0;
1871 if (!NILP (current_buffer
->mark_active
) && !NILP (Vrun_hooks
))
1873 /* Setting transient-mark-mode to `only' is a way of
1874 turning it on for just one command. */
1876 if (EQ (Vtransient_mark_mode
, Qidentity
))
1877 Vtransient_mark_mode
= Qnil
;
1878 if (EQ (Vtransient_mark_mode
, Qonly
))
1879 Vtransient_mark_mode
= Qidentity
;
1881 if (!NILP (Vdeactivate_mark
) && !NILP (Vtransient_mark_mode
))
1883 /* We could also call `deactivate'mark'. */
1884 if (EQ (Vtransient_mark_mode
, Qlambda
))
1885 Vtransient_mark_mode
= Qnil
;
1888 current_buffer
->mark_active
= Qnil
;
1889 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
1892 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
1893 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
1898 if (current_buffer
== prev_buffer
1899 && last_point_position
!= PT
1900 && NILP (Vdisable_point_adjustment
)
1901 && NILP (Vglobal_disable_point_adjustment
)
1902 && !already_adjusted
)
1903 adjust_point_for_property (last_point_position
, MODIFF
!= prev_modiff
);
1905 /* Install chars successfully executed in kbd macro. */
1907 if (!NILP (current_kboard
->defining_kbd_macro
)
1908 && NILP (current_kboard
->Vprefix_arg
))
1909 finalize_kbd_macro_chars ();
1913 any_kboard_state ();
1918 extern Lisp_Object Qcomposition
, Qdisplay
;
1920 /* Adjust point to a boundary of a region that has such a property
1921 that should be treated intangible. For the moment, we check
1922 `composition', `display' and `invisible' properties.
1923 LAST_PT is the last position of point. */
1925 extern Lisp_Object Qafter_string
, Qbefore_string
;
1926 extern Lisp_Object get_pos_property
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
));
1929 adjust_point_for_property (last_pt
, modified
)
1934 Lisp_Object val
, overlay
, tmp
;
1935 int check_composition
= 1, check_display
= 1, check_invisible
= 1;
1938 /* FIXME: cycling is probably not necessary because these properties
1939 can't be usefully combined anyway. */
1940 while (check_composition
|| check_display
|| check_invisible
)
1942 if (check_composition
1943 && PT
> BEGV
&& PT
< ZV
1944 && get_property_and_range (PT
, Qcomposition
, &val
, &beg
, &end
, Qnil
)
1945 && COMPOSITION_VALID_P (beg
, end
, val
)
1946 && beg
< PT
/* && end > PT <- It's always the case. */
1947 && (last_pt
<= beg
|| last_pt
>= end
))
1950 SET_PT (PT
< last_pt
? beg
: end
);
1951 check_display
= check_invisible
= 1;
1953 check_composition
= 0;
1955 && PT
> BEGV
&& PT
< ZV
1956 && !NILP (val
= get_char_property_and_overlay
1957 (make_number (PT
), Qdisplay
, Qnil
, &overlay
))
1958 && display_prop_intangible_p (val
)
1959 && (!OVERLAYP (overlay
)
1960 ? get_property_and_range (PT
, Qdisplay
, &val
, &beg
, &end
, Qnil
)
1961 : (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)),
1962 end
= OVERLAY_POSITION (OVERLAY_END (overlay
))))
1963 && (beg
< PT
/* && end > PT <- It's always the case. */
1964 || (beg
<= PT
&& STRINGP (val
) && SCHARS (val
) == 0)))
1967 SET_PT (PT
< last_pt
1968 ? (STRINGP (val
) && SCHARS (val
) == 0 ? beg
- 1 : beg
)
1970 check_composition
= check_invisible
= 1;
1973 if (check_invisible
&& PT
> BEGV
&& PT
< ZV
)
1975 int inv
, ellipsis
= 0;
1978 /* Find boundaries `beg' and `end' of the invisible area, if any. */
1980 && !NILP (val
= get_char_property_and_overlay
1981 (make_number (end
), Qinvisible
, Qnil
, &overlay
))
1982 && (inv
= TEXT_PROP_MEANS_INVISIBLE (val
)))
1984 ellipsis
= ellipsis
|| inv
> 1
1985 || (OVERLAYP (overlay
)
1986 && (!NILP (Foverlay_get (overlay
, Qafter_string
))
1987 || !NILP (Foverlay_get (overlay
, Qbefore_string
))));
1988 tmp
= Fnext_single_char_property_change
1989 (make_number (end
), Qinvisible
, Qnil
, Qnil
);
1990 end
= NATNUMP (tmp
) ? XFASTINT (tmp
) : ZV
;
1993 && !NILP (val
= get_char_property_and_overlay
1994 (make_number (beg
- 1), Qinvisible
, Qnil
, &overlay
))
1995 && (inv
= TEXT_PROP_MEANS_INVISIBLE (val
)))
1997 ellipsis
= ellipsis
|| inv
> 1
1998 || (OVERLAYP (overlay
)
1999 && (!NILP (Foverlay_get (overlay
, Qafter_string
))
2000 || !NILP (Foverlay_get (overlay
, Qbefore_string
))));
2001 tmp
= Fprevious_single_char_property_change
2002 (make_number (beg
), Qinvisible
, Qnil
, Qnil
);
2003 beg
= NATNUMP (tmp
) ? XFASTINT (tmp
) : BEGV
;
2006 /* Move away from the inside area. */
2007 if (beg
< PT
&& end
> PT
)
2009 SET_PT ((orig_pt
== PT
&& (last_pt
< beg
|| last_pt
> end
))
2010 /* We haven't moved yet (so we don't need to fear
2011 infinite-looping) and we were outside the range
2012 before (so either end of the range still corresponds
2013 to a move in the right direction): pretend we moved
2014 less than we actually did, so that we still have
2015 more freedom below in choosing which end of the range
2017 ? (orig_pt
= -1, PT
< last_pt
? end
: beg
)
2018 /* We either have moved already or the last point
2019 was already in the range: we don't get to choose
2020 which end of the range we have to go to. */
2021 : (PT
< last_pt
? beg
: end
));
2022 check_composition
= check_display
= 1;
2024 #if 0 /* This assertion isn't correct, because SET_PT may end up setting
2025 the point to something other than its argument, due to
2026 point-motion hooks, intangibility, etc. */
2027 xassert (PT
== beg
|| PT
== end
);
2030 /* Pretend the area doesn't exist if the buffer is not
2032 if (!modified
&& !ellipsis
&& beg
< end
)
2034 if (last_pt
== beg
&& PT
== end
&& end
< ZV
)
2035 (check_composition
= check_display
= 1, SET_PT (end
+ 1));
2036 else if (last_pt
== end
&& PT
== beg
&& beg
> BEGV
)
2037 (check_composition
= check_display
= 1, SET_PT (beg
- 1));
2038 else if (PT
== ((PT
< last_pt
) ? beg
: end
))
2039 /* We've already moved as far as we can. Trying to go
2040 to the other end would mean moving backwards and thus
2041 could lead to an infinite loop. */
2043 else if (val
= get_pos_property (make_number (PT
),
2045 TEXT_PROP_MEANS_INVISIBLE (val
)
2046 && (val
= get_pos_property
2047 (make_number (PT
== beg
? end
: beg
),
2049 !TEXT_PROP_MEANS_INVISIBLE (val
)))
2050 (check_composition
= check_display
= 1,
2051 SET_PT (PT
== beg
? end
: beg
));
2054 check_invisible
= 0;
2058 /* Subroutine for safe_run_hooks: run the hook HOOK. */
2061 safe_run_hooks_1 (hook
)
2064 return call1 (Vrun_hooks
, Vinhibit_quit
);
2067 /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */
2070 safe_run_hooks_error (data
)
2073 Lisp_Object args
[3];
2074 args
[0] = build_string ("Error in %s: %s");
2075 args
[1] = Vinhibit_quit
;
2078 return Fset (Vinhibit_quit
, Qnil
);
2081 /* If we get an error while running the hook, cause the hook variable
2082 to be nil. Also inhibit quits, so that C-g won't cause the hook
2083 to mysteriously evaporate. */
2086 safe_run_hooks (hook
)
2089 int count
= SPECPDL_INDEX ();
2090 specbind (Qinhibit_quit
, hook
);
2092 internal_condition_case (safe_run_hooks_1
, Qt
, safe_run_hooks_error
);
2094 unbind_to (count
, Qnil
);
2098 /* Number of seconds between polling for input. This is a Lisp
2099 variable that can be bound. */
2101 EMACS_INT polling_period
;
2103 /* Nonzero means polling for input is temporarily suppressed. */
2105 int poll_suppress_count
;
2107 /* Asynchronous timer for polling. */
2109 struct atimer
*poll_timer
;
2112 #ifdef POLL_FOR_INPUT
2114 /* Poll for input, so what we catch a C-g if it comes in. This
2115 function is called from x_make_frame_visible, see comment
2121 if (interrupt_input_blocked
== 0
2122 && !waiting_for_input
)
2123 read_avail_input (0);
2126 /* Timer callback function for poll_timer. TIMER is equal to
2130 poll_for_input (timer
)
2131 struct atimer
*timer
;
2133 if (poll_suppress_count
== 0)
2135 interrupt_input_pending
= 1;
2137 poll_for_input_1 ();
2141 #endif /* POLL_FOR_INPUT */
2143 /* Begin signals to poll for input, if they are appropriate.
2144 This function is called unconditionally from various places. */
2149 #ifdef POLL_FOR_INPUT
2150 /* XXX This condition was (read_socket_hook && !interrupt_input),
2151 but read_socket_hook is not global anymore. Let's pretend that
2153 if (!interrupt_input
)
2155 /* Turn alarm handling on unconditionally. It might have
2156 been turned off in process.c. */
2157 turn_on_atimers (1);
2159 /* If poll timer doesn't exist, are we need one with
2160 a different interval, start a new one. */
2161 if (poll_timer
== NULL
2162 || EMACS_SECS (poll_timer
->interval
) != polling_period
)
2164 EMACS_TIME interval
;
2167 cancel_atimer (poll_timer
);
2169 EMACS_SET_SECS_USECS (interval
, polling_period
, 0);
2170 poll_timer
= start_atimer (ATIMER_CONTINUOUS
, interval
,
2171 poll_for_input
, NULL
);
2174 /* Let the timer's callback function poll for input
2175 if this becomes zero. */
2176 --poll_suppress_count
;
2181 /* Nonzero if we are using polling to handle input asynchronously. */
2184 input_polling_used ()
2186 #ifdef POLL_FOR_INPUT
2187 /* XXX This condition was (read_socket_hook && !interrupt_input),
2188 but read_socket_hook is not global anymore. Let's pretend that
2190 return !interrupt_input
;
2196 /* Turn off polling. */
2201 #ifdef POLL_FOR_INPUT
2202 /* XXX This condition was (read_socket_hook && !interrupt_input),
2203 but read_socket_hook is not global anymore. Let's pretend that
2205 if (!interrupt_input
)
2206 ++poll_suppress_count
;
2210 /* Set the value of poll_suppress_count to COUNT
2211 and start or stop polling accordingly. */
2214 set_poll_suppress_count (count
)
2217 #ifdef POLL_FOR_INPUT
2218 if (count
== 0 && poll_suppress_count
!= 0)
2220 poll_suppress_count
= 1;
2223 else if (count
!= 0 && poll_suppress_count
== 0)
2227 poll_suppress_count
= count
;
2231 /* Bind polling_period to a value at least N.
2232 But don't decrease it. */
2235 bind_polling_period (n
)
2238 #ifdef POLL_FOR_INPUT
2239 int new = polling_period
;
2244 stop_other_atimers (poll_timer
);
2246 specbind (Qpolling_period
, make_number (new));
2247 /* Start a new alarm with the new period. */
2252 /* Apply the control modifier to CHARACTER. */
2258 /* Save the upper bits here. */
2259 int upper
= c
& ~0177;
2263 /* Everything in the columns containing the upper-case letters
2264 denotes a control character. */
2265 if (c
>= 0100 && c
< 0140)
2269 /* Set the shift modifier for a control char
2270 made from a shifted letter. But only for letters! */
2271 if (oc
>= 'A' && oc
<= 'Z')
2272 c
|= shift_modifier
;
2275 /* The lower-case letters denote control characters too. */
2276 else if (c
>= 'a' && c
<= 'z')
2279 /* Include the bits for control and shift
2280 only if the basic ASCII code can't indicate them. */
2284 /* Replace the high bits. */
2285 c
|= (upper
& ~ctrl_modifier
);
2290 /* Display the help-echo property of the character after the mouse pointer.
2291 Either show it in the echo area, or call show-help-function to display
2292 it by other means (maybe in a tooltip).
2294 If HELP is nil, that means clear the previous help echo.
2296 If HELP is a string, display that string. If HELP is a function,
2297 call it with OBJECT and POS as arguments; the function should
2298 return a help string or nil for none. For all other types of HELP,
2299 evaluate it to obtain a string.
2301 WINDOW is the window in which the help was generated, if any.
2302 It is nil if not in a window.
2304 If OBJECT is a buffer, POS is the position in the buffer where the
2305 `help-echo' text property was found.
2307 If OBJECT is an overlay, that overlay has a `help-echo' property,
2308 and POS is the position in the overlay's buffer under the mouse.
2310 If OBJECT is a string (an overlay string or a string displayed with
2311 the `display' property). POS is the position in that string under
2314 OK_TO_OVERWRITE_KEYSTROKE_ECHO non-zero means it's okay if the help
2315 echo overwrites a keystroke echo currently displayed in the echo
2318 Note: this function may only be called with HELP nil or a string
2319 from X code running asynchronously. */
2322 show_help_echo (help
, window
, object
, pos
, ok_to_overwrite_keystroke_echo
)
2323 Lisp_Object help
, window
, object
, pos
;
2324 int ok_to_overwrite_keystroke_echo
;
2326 if (!NILP (help
) && !STRINGP (help
))
2328 if (FUNCTIONP (help
))
2330 Lisp_Object args
[4];
2335 help
= safe_call (4, args
);
2338 help
= safe_eval (help
);
2340 if (!STRINGP (help
))
2345 if (!noninteractive
&& STRINGP (help
))
2346 help
= call1 (Qmouse_fixup_help_message
, help
);
2349 if (STRINGP (help
) || NILP (help
))
2351 if (!NILP (Vshow_help_function
))
2352 call1 (Vshow_help_function
, help
);
2353 else if (/* Don't overwrite minibuffer contents. */
2354 !MINI_WINDOW_P (XWINDOW (selected_window
))
2355 /* Don't overwrite a keystroke echo. */
2356 && (NILP (echo_message_buffer
)
2357 || ok_to_overwrite_keystroke_echo
)
2358 /* Don't overwrite a prompt. */
2359 && !cursor_in_echo_area
)
2363 int count
= SPECPDL_INDEX ();
2365 if (!help_echo_showing_p
)
2366 Vpre_help_message
= current_message ();
2368 specbind (Qmessage_truncate_lines
, Qt
);
2369 message3_nolog (help
, SBYTES (help
),
2370 STRING_MULTIBYTE (help
));
2371 unbind_to (count
, Qnil
);
2373 else if (STRINGP (Vpre_help_message
))
2375 message3_nolog (Vpre_help_message
,
2376 SBYTES (Vpre_help_message
),
2377 STRING_MULTIBYTE (Vpre_help_message
));
2378 Vpre_help_message
= Qnil
;
2384 help_echo_showing_p
= STRINGP (help
);
2390 /* Input of single characters from keyboard */
2392 Lisp_Object
print_help ();
2393 static Lisp_Object
kbd_buffer_get_event ();
2394 static void record_char ();
2397 static jmp_buf wrong_kboard_jmpbuf
;
2400 #define STOP_POLLING \
2401 do { if (! polling_stopped_here) stop_polling (); \
2402 polling_stopped_here = 1; } while (0)
2404 #define RESUME_POLLING \
2405 do { if (polling_stopped_here) start_polling (); \
2406 polling_stopped_here = 0; } while (0)
2408 /* read a character from the keyboard; call the redisplay if needed */
2409 /* commandflag 0 means do not do auto-saving, but do do redisplay.
2410 -1 means do not do redisplay, but do do autosaving.
2413 /* The arguments MAPS and NMAPS are for menu prompting.
2414 MAPS is an array of keymaps; NMAPS is the length of MAPS.
2416 PREV_EVENT is the previous input event, or nil if we are reading
2417 the first event of a key sequence (or not reading a key sequence).
2418 If PREV_EVENT is t, that is a "magic" value that says
2419 not to run input methods, but in other respects to act as if
2420 not reading a key sequence.
2422 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
2423 if we used a mouse menu to read the input, or zero otherwise. If
2424 USED_MOUSE_MENU is null, we don't dereference it.
2426 Value is t if we showed a menu and the user rejected it. */
2429 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
)
2433 Lisp_Object prev_event
;
2434 int *used_mouse_menu
;
2436 volatile Lisp_Object c
;
2438 jmp_buf local_getcjmp
;
2440 volatile int key_already_recorded
= 0;
2441 Lisp_Object tem
, save
;
2442 volatile Lisp_Object previous_echo_area_message
;
2443 volatile Lisp_Object also_record
;
2444 volatile int reread
;
2445 struct gcpro gcpro1
, gcpro2
;
2446 int polling_stopped_here
= 0;
2450 #if 0 /* This was commented out as part of fixing echo for C-u left. */
2451 before_command_key_count
= this_command_key_count
;
2452 before_command_echo_length
= echo_length ();
2455 previous_echo_area_message
= Qnil
;
2457 GCPRO2 (c
, previous_echo_area_message
);
2462 if (CONSP (Vunread_post_input_method_events
))
2464 c
= XCAR (Vunread_post_input_method_events
);
2465 Vunread_post_input_method_events
2466 = XCDR (Vunread_post_input_method_events
);
2468 /* Undo what read_char_x_menu_prompt did when it unread
2469 additional keys returned by Fx_popup_menu. */
2471 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
)))
2479 if (unread_command_char
!= -1)
2481 XSETINT (c
, unread_command_char
);
2482 unread_command_char
= -1;
2488 if (CONSP (Vunread_command_events
))
2490 c
= XCAR (Vunread_command_events
);
2491 Vunread_command_events
= XCDR (Vunread_command_events
);
2493 /* Undo what read_char_x_menu_prompt did when it unread
2494 additional keys returned by Fx_popup_menu. */
2496 && EQ (XCDR (c
), Qdisabled
)
2497 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
))))
2500 /* If the queued event is something that used the mouse,
2501 set used_mouse_menu accordingly. */
2503 && (EQ (c
, Qtool_bar
) || EQ (c
, Qmenu_bar
)))
2504 *used_mouse_menu
= 1;
2507 goto reread_for_input_method
;
2510 if (CONSP (Vunread_input_method_events
))
2512 c
= XCAR (Vunread_input_method_events
);
2513 Vunread_input_method_events
= XCDR (Vunread_input_method_events
);
2515 /* Undo what read_char_x_menu_prompt did when it unread
2516 additional keys returned by Fx_popup_menu. */
2518 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
)))
2522 goto reread_for_input_method
;
2525 this_command_key_count_reset
= 0;
2527 if (!NILP (Vexecuting_kbd_macro
))
2529 /* We set this to Qmacro; since that's not a frame, nobody will
2530 try to switch frames on us, and the selected window will
2533 Since this event came from a macro, it would be misleading to
2534 leave internal_last_event_frame set to wherever the last
2535 real event came from. Normally, a switch-frame event selects
2536 internal_last_event_frame after each command is read, but
2537 events read from a macro should never cause a new frame to be
2539 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
2541 /* Exit the macro if we are at the end.
2542 Also, some things replace the macro with t
2543 to force an early exit. */
2544 if (EQ (Vexecuting_kbd_macro
, Qt
)
2545 || executing_kbd_macro_index
>= XFASTINT (Flength (Vexecuting_kbd_macro
)))
2551 c
= Faref (Vexecuting_kbd_macro
, make_number (executing_kbd_macro_index
));
2552 if (STRINGP (Vexecuting_kbd_macro
)
2553 && (XINT (c
) & 0x80) && (XUINT (c
) <= 0xff))
2554 XSETFASTINT (c
, CHAR_META
| (XINT (c
) & ~0x80));
2556 executing_kbd_macro_index
++;
2561 if (!NILP (unread_switch_frame
))
2563 c
= unread_switch_frame
;
2564 unread_switch_frame
= Qnil
;
2566 /* This event should make it into this_command_keys, and get echoed
2567 again, so we do not set `reread'. */
2571 /* if redisplay was requested */
2572 if (commandflag
>= 0)
2574 /* If there is pending input, process any events which are not
2575 user-visible, such as X selection_request events. */
2577 || detect_input_pending_run_timers (0))
2578 swallow_events (0); /* may clear input_pending */
2580 /* Redisplay if no pending input. */
2581 while (!input_pending
)
2583 if (help_echo_showing_p
&& !EQ (selected_window
, minibuf_window
))
2584 redisplay_preserve_echo_area (5);
2589 /* Normal case: no input arrived during redisplay. */
2592 /* Input arrived and pre-empted redisplay.
2593 Process any events which are not user-visible. */
2595 /* If that cleared input_pending, try again to redisplay. */
2599 /* Message turns off echoing unless more keystrokes turn it on again.
2601 The code in 20.x for the condition was
2603 1. echo_area_glyphs && *echo_area_glyphs
2604 2. && echo_area_glyphs != current_kboard->echobuf
2605 3. && ok_to_echo_at_next_pause != echo_area_glyphs
2607 (1) means there's a current message displayed
2609 (2) means it's not the message from echoing from the current
2612 (3) There's only one place in 20.x where ok_to_echo_at_next_pause
2613 is set to a non-null value. This is done in read_char and it is
2614 set to echo_area_glyphs after a call to echo_char. That means
2615 ok_to_echo_at_next_pause is either null or
2616 current_kboard->echobuf with the appropriate current_kboard at
2619 So, condition (3) means in clear text ok_to_echo_at_next_pause
2620 must be either null, or the current message isn't from echoing at
2621 all, or it's from echoing from a different kboard than the
2624 if (/* There currently is something in the echo area. */
2625 !NILP (echo_area_buffer
[0])
2626 && (/* And it's either not from echoing. */
2627 !EQ (echo_area_buffer
[0], echo_message_buffer
)
2628 /* Or it's an echo from a different kboard. */
2629 || echo_kboard
!= current_kboard
2630 /* Or we explicitly allow overwriting whatever there is. */
2631 || ok_to_echo_at_next_pause
== NULL
))
2636 /* Try reading a character via menu prompting in the minibuf.
2637 Try this before the sit-for, because the sit-for
2638 would do the wrong thing if we are supposed to do
2639 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
2640 after a mouse event so don't try a minibuf menu. */
2642 if (nmaps
> 0 && INTERACTIVE
2643 && !NILP (prev_event
) && ! EVENT_HAS_PARAMETERS (prev_event
)
2644 /* Don't bring up a menu if we already have another event. */
2645 && NILP (Vunread_command_events
)
2646 && unread_command_char
< 0
2647 && !detect_input_pending_run_timers (0))
2649 c
= read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
);
2652 key_already_recorded
= 1;
2657 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet.
2658 We will do that below, temporarily for short sections of code,
2659 when appropriate. local_getcjmp must be in effect
2660 around any call to sit_for or kbd_buffer_get_event;
2661 it *must not* be in effect when we call redisplay. */
2663 if (_setjmp (local_getcjmp
))
2665 /* We must have saved the outer value of getcjmp here,
2666 so restore it now. */
2667 restore_getcjmp (save_jump
);
2668 XSETINT (c
, quit_char
);
2669 internal_last_event_frame
= selected_frame
;
2670 Vlast_event_frame
= internal_last_event_frame
;
2671 /* If we report the quit char as an event,
2672 don't do so more than once. */
2673 if (!NILP (Vinhibit_quit
))
2678 KBOARD
*kb
= FRAME_KBOARD (XFRAME (selected_frame
));
2679 if (kb
!= current_kboard
)
2681 Lisp_Object link
= kb
->kbd_queue
;
2682 /* We shouldn't get here if we were in single-kboard mode! */
2687 while (CONSP (XCDR (link
)))
2689 if (!NILP (XCDR (link
)))
2693 kb
->kbd_queue
= Fcons (c
, Qnil
);
2695 XSETCDR (link
, Fcons (c
, Qnil
));
2696 kb
->kbd_queue_has_data
= 1;
2697 current_kboard
= kb
;
2698 /* This is going to exit from read_char
2699 so we had better get rid of this frame's stuff. */
2701 longjmp (wrong_kboard_jmpbuf
, 1);
2708 timer_start_idle ();
2710 /* If in middle of key sequence and minibuffer not active,
2711 start echoing if enough time elapses. */
2713 if (minibuf_level
== 0
2714 && !current_kboard
->immediate_echo
2715 && this_command_key_count
> 0
2717 && (FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
2718 && NILP (Fzerop (Vecho_keystrokes
))
2719 && (/* No message. */
2720 NILP (echo_area_buffer
[0])
2721 /* Or empty message. */
2722 || (BUF_BEG (XBUFFER (echo_area_buffer
[0]))
2723 == BUF_Z (XBUFFER (echo_area_buffer
[0])))
2724 /* Or already echoing from same kboard. */
2725 || (echo_kboard
&& ok_to_echo_at_next_pause
== echo_kboard
)
2726 /* Or not echoing before and echoing allowed. */
2727 || (!echo_kboard
&& ok_to_echo_at_next_pause
)))
2731 /* After a mouse event, start echoing right away.
2732 This is because we are probably about to display a menu,
2733 and we don't want to delay before doing so. */
2734 if (EVENT_HAS_PARAMETERS (prev_event
))
2739 double duration
= extract_float (Vecho_keystrokes
);
2740 sec
= (int) duration
;
2741 usec
= (duration
- sec
) * 1000000;
2742 save_getcjmp (save_jump
);
2743 restore_getcjmp (local_getcjmp
);
2744 tem0
= sit_for (sec
, usec
, 1, 1, 0);
2745 restore_getcjmp (save_jump
);
2747 && ! CONSP (Vunread_command_events
))
2752 /* Maybe auto save due to number of keystrokes. */
2754 if (commandflag
!= 0
2755 && auto_save_interval
> 0
2756 && num_nonmacro_input_events
- last_auto_save
> max (auto_save_interval
, 20)
2757 && !detect_input_pending_run_timers (0))
2759 Fdo_auto_save (Qnil
, Qnil
);
2760 /* Hooks can actually change some buffers in auto save. */
2764 /* Try reading using an X menu.
2765 This is never confused with reading using the minibuf
2766 because the recursive call of read_char in read_char_minibuf_menu_prompt
2767 does not pass on any keymaps. */
2769 if (nmaps
> 0 && INTERACTIVE
2770 && !NILP (prev_event
)
2771 && EVENT_HAS_PARAMETERS (prev_event
)
2772 && !EQ (XCAR (prev_event
), Qmenu_bar
)
2773 && !EQ (XCAR (prev_event
), Qtool_bar
)
2774 /* Don't bring up a menu if we already have another event. */
2775 && NILP (Vunread_command_events
)
2776 && unread_command_char
< 0)
2778 c
= read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
2780 /* Now that we have read an event, Emacs is not idle. */
2786 /* Maybe autosave and/or garbage collect due to idleness. */
2788 if (INTERACTIVE
&& NILP (c
))
2790 int delay_level
, buffer_size
;
2792 /* Slow down auto saves logarithmically in size of current buffer,
2793 and garbage collect while we're at it. */
2794 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
2795 last_non_minibuf_size
= Z
- BEG
;
2796 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
2798 while (buffer_size
> 64)
2799 delay_level
++, buffer_size
-= buffer_size
>> 2;
2800 if (delay_level
< 4) delay_level
= 4;
2801 /* delay_level is 4 for files under around 50k, 7 at 100k,
2802 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
2804 /* Auto save if enough time goes by without input. */
2805 if (commandflag
!= 0
2806 && num_nonmacro_input_events
> last_auto_save
2807 && INTEGERP (Vauto_save_timeout
)
2808 && XINT (Vauto_save_timeout
) > 0)
2812 save_getcjmp (save_jump
);
2813 restore_getcjmp (local_getcjmp
);
2814 tem0
= sit_for (delay_level
* XFASTINT (Vauto_save_timeout
) / 4,
2816 restore_getcjmp (save_jump
);
2819 && ! CONSP (Vunread_command_events
))
2821 Fdo_auto_save (Qnil
, Qnil
);
2823 /* If we have auto-saved and there is still no input
2824 available, garbage collect if there has been enough
2825 consing going on to make it worthwhile. */
2826 if (!detect_input_pending_run_timers (0)
2827 && consing_since_gc
> gc_cons_threshold
/ 2)
2828 Fgarbage_collect ();
2835 /* If this has become non-nil here, it has been set by a timer
2836 or sentinel or filter. */
2837 if (CONSP (Vunread_command_events
))
2839 c
= XCAR (Vunread_command_events
);
2840 Vunread_command_events
= XCDR (Vunread_command_events
);
2843 /* Read something from current KBOARD's side queue, if possible. */
2847 if (current_kboard
->kbd_queue_has_data
)
2849 if (!CONSP (current_kboard
->kbd_queue
))
2851 c
= XCAR (current_kboard
->kbd_queue
);
2852 current_kboard
->kbd_queue
2853 = XCDR (current_kboard
->kbd_queue
);
2854 if (NILP (current_kboard
->kbd_queue
))
2855 current_kboard
->kbd_queue_has_data
= 0;
2856 input_pending
= readable_events (0);
2857 if (EVENT_HAS_PARAMETERS (c
)
2858 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qswitch_frame
))
2859 internal_last_event_frame
= XCAR (XCDR (c
));
2860 Vlast_event_frame
= internal_last_event_frame
;
2865 /* If current_kboard's side queue is empty check the other kboards.
2866 If one of them has data that we have not yet seen here,
2867 switch to it and process the data waiting for it.
2869 Note: if the events queued up for another kboard
2870 have already been seen here, and therefore are not a complete command,
2871 the kbd_queue_has_data field is 0, so we skip that kboard here.
2872 That's to avoid an infinite loop switching between kboards here. */
2873 if (NILP (c
) && !single_kboard
)
2876 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2877 if (kb
->kbd_queue_has_data
)
2879 current_kboard
= kb
;
2880 /* This is going to exit from read_char
2881 so we had better get rid of this frame's stuff. */
2883 longjmp (wrong_kboard_jmpbuf
, 1);
2892 /* Finally, we read from the main queue,
2893 and if that gives us something we can't use yet, we put it on the
2894 appropriate side queue and try again. */
2900 /* Actually read a character, waiting if necessary. */
2901 save_getcjmp (save_jump
);
2902 restore_getcjmp (local_getcjmp
);
2903 timer_start_idle ();
2904 c
= kbd_buffer_get_event (&kb
, used_mouse_menu
);
2905 restore_getcjmp (save_jump
);
2908 if (! NILP (c
) && (kb
!= current_kboard
))
2910 Lisp_Object link
= kb
->kbd_queue
;
2913 while (CONSP (XCDR (link
)))
2915 if (!NILP (XCDR (link
)))
2919 kb
->kbd_queue
= Fcons (c
, Qnil
);
2921 XSETCDR (link
, Fcons (c
, Qnil
));
2922 kb
->kbd_queue_has_data
= 1;
2926 current_kboard
= kb
;
2927 /* This is going to exit from read_char
2928 so we had better get rid of this frame's stuff. */
2930 longjmp (wrong_kboard_jmpbuf
, 1);
2935 /* Terminate Emacs in batch mode if at eof. */
2936 if (noninteractive
&& INTEGERP (c
) && XINT (c
) < 0)
2937 Fkill_emacs (make_number (1));
2941 /* Add in any extra modifiers, where appropriate. */
2942 if ((extra_keyboard_modifiers
& CHAR_CTL
)
2943 || ((extra_keyboard_modifiers
& 0177) < ' '
2944 && (extra_keyboard_modifiers
& 0177) != 0))
2945 XSETINT (c
, make_ctrl_char (XINT (c
)));
2947 /* Transfer any other modifier bits directly from
2948 extra_keyboard_modifiers to c. Ignore the actual character code
2949 in the low 16 bits of extra_keyboard_modifiers. */
2950 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
2960 if (commandflag
>= 0
2961 && !input_pending
&& !detect_input_pending_run_timers (0))
2969 /* Buffer switch events are only for internal wakeups
2970 so don't show them to the user.
2971 Also, don't record a key if we already did. */
2972 if (BUFFERP (c
) || key_already_recorded
)
2975 /* Process special events within read_char
2976 and loop around to read another event. */
2979 tem
= access_keymap (get_keymap (Vspecial_event_map
, 0, 1), c
, 0, 0, 1);
2984 int was_locked
= single_kboard
;
2986 last_input_char
= c
;
2987 Fcommand_execute (tem
, Qnil
, Fvector (1, &last_input_char
), Qt
);
2989 if (CONSP (c
) && EQ (XCAR (c
), Qselect_window
))
2990 /* We stopped being idle for this event; undo that. This
2991 prevents automatic window selection (under
2992 mouse_autoselect_window from acting as a real input event, for
2993 example banishing the mouse under mouse-avoidance-mode. */
2994 timer_resume_idle ();
2996 /* Resume allowing input from any kboard, if that was true before. */
2998 any_kboard_state ();
3003 /* Handle things that only apply to characters. */
3006 /* If kbd_buffer_get_event gave us an EOF, return that. */
3010 if ((STRINGP (current_kboard
->Vkeyboard_translate_table
)
3011 && SCHARS (current_kboard
->Vkeyboard_translate_table
) > (unsigned) XFASTINT (c
))
3012 || (VECTORP (current_kboard
->Vkeyboard_translate_table
)
3013 && XVECTOR (current_kboard
->Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
3014 || (CHAR_TABLE_P (current_kboard
->Vkeyboard_translate_table
)
3015 && CHAR_VALID_P (XINT (c
), 0)))
3018 d
= Faref (current_kboard
->Vkeyboard_translate_table
, c
);
3019 /* nil in keyboard-translate-table means no translation. */
3025 /* If this event is a mouse click in the menu bar,
3026 return just menu-bar for now. Modify the mouse click event
3027 so we won't do this twice, then queue it up. */
3028 if (EVENT_HAS_PARAMETERS (c
)
3030 && CONSP (EVENT_START (c
))
3031 && CONSP (XCDR (EVENT_START (c
))))
3035 posn
= POSN_POSN (EVENT_START (c
));
3036 /* Handle menu-bar events:
3037 insert the dummy prefix event `menu-bar'. */
3038 if (EQ (posn
, Qmenu_bar
) || EQ (posn
, Qtool_bar
))
3040 /* Change menu-bar to (menu-bar) as the event "position". */
3041 POSN_SET_POSN (EVENT_START (c
), Fcons (posn
, Qnil
));
3044 Vunread_command_events
= Fcons (c
, Vunread_command_events
);
3049 /* Store these characters into recent_keys, the dribble file if any,
3050 and the keyboard macro being defined, if any. */
3052 if (! NILP (also_record
))
3053 record_char (also_record
);
3055 /* Wipe the echo area.
3056 But first, if we are about to use an input method,
3057 save the echo area contents for it to refer to. */
3059 && ! NILP (Vinput_method_function
)
3060 && (unsigned) XINT (c
) >= ' '
3061 && (unsigned) XINT (c
) != 127
3062 && (unsigned) XINT (c
) < 256)
3064 previous_echo_area_message
= Fcurrent_message ();
3065 Vinput_method_previous_message
= previous_echo_area_message
;
3068 /* Now wipe the echo area, except for help events which do their
3069 own stuff with the echo area. */
3071 || (!(EQ (Qhelp_echo
, XCAR (c
)))
3072 && !(EQ (Qswitch_frame
, XCAR (c
)))))
3074 if (!NILP (echo_area_buffer
[0]))
3075 safe_run_hooks (Qecho_area_clear_hook
);
3076 clear_message (1, 0);
3079 reread_for_input_method
:
3081 /* Pass this to the input method, if appropriate. */
3083 && ! NILP (Vinput_method_function
)
3084 /* Don't run the input method within a key sequence,
3085 after the first event of the key sequence. */
3086 && NILP (prev_event
)
3087 && (unsigned) XINT (c
) >= ' '
3088 && (unsigned) XINT (c
) != 127
3089 && (unsigned) XINT (c
) < 256)
3092 int key_count
, key_count_reset
;
3093 struct gcpro gcpro1
;
3094 int count
= SPECPDL_INDEX ();
3096 /* Save the echo status. */
3097 int saved_immediate_echo
= current_kboard
->immediate_echo
;
3098 struct kboard
*saved_ok_to_echo
= ok_to_echo_at_next_pause
;
3099 Lisp_Object saved_echo_string
= current_kboard
->echo_string
;
3100 int saved_echo_after_prompt
= current_kboard
->echo_after_prompt
;
3103 if (before_command_restore_flag
)
3105 this_command_key_count
= before_command_key_count_1
;
3106 if (this_command_key_count
< this_single_command_key_start
)
3107 this_single_command_key_start
= this_command_key_count
;
3108 echo_truncate (before_command_echo_length_1
);
3109 before_command_restore_flag
= 0;
3113 /* Save the this_command_keys status. */
3114 key_count
= this_command_key_count
;
3115 key_count_reset
= this_command_key_count_reset
;
3118 keys
= Fcopy_sequence (this_command_keys
);
3123 /* Clear out this_command_keys. */
3124 this_command_key_count
= 0;
3125 this_command_key_count_reset
= 0;
3127 /* Now wipe the echo area. */
3128 if (!NILP (echo_area_buffer
[0]))
3129 safe_run_hooks (Qecho_area_clear_hook
);
3130 clear_message (1, 0);
3133 /* If we are not reading a key sequence,
3134 never use the echo area. */
3137 specbind (Qinput_method_use_echo_area
, Qt
);
3140 /* Call the input method. */
3141 tem
= call1 (Vinput_method_function
, c
);
3143 tem
= unbind_to (count
, tem
);
3145 /* Restore the saved echoing state
3146 and this_command_keys state. */
3147 this_command_key_count
= key_count
;
3148 this_command_key_count_reset
= key_count_reset
;
3150 this_command_keys
= keys
;
3153 ok_to_echo_at_next_pause
= saved_ok_to_echo
;
3154 current_kboard
->echo_string
= saved_echo_string
;
3155 current_kboard
->echo_after_prompt
= saved_echo_after_prompt
;
3156 if (saved_immediate_echo
)
3161 /* The input method can return no events. */
3164 /* Bring back the previous message, if any. */
3165 if (! NILP (previous_echo_area_message
))
3166 message_with_string ("%s", previous_echo_area_message
, 0);
3169 /* It returned one event or more. */
3171 Vunread_post_input_method_events
3172 = nconc2 (XCDR (tem
), Vunread_post_input_method_events
);
3177 /* Display help if not echoing. */
3178 if (CONSP (c
) && EQ (XCAR (c
), Qhelp_echo
))
3180 /* (help-echo FRAME HELP WINDOW OBJECT POS). */
3181 Lisp_Object help
, object
, position
, window
, tem
;
3183 tem
= Fcdr (XCDR (c
));
3186 window
= Fcar (tem
);
3188 object
= Fcar (tem
);
3190 position
= Fcar (tem
);
3192 show_help_echo (help
, window
, object
, position
, 0);
3194 /* We stopped being idle for this event; undo that. */
3195 timer_resume_idle ();
3199 if (! reread
|| this_command_key_count
== 0
3200 || this_command_key_count_reset
)
3203 /* Don't echo mouse motion events. */
3204 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
3205 && NILP (Fzerop (Vecho_keystrokes
))
3206 && ! (EVENT_HAS_PARAMETERS (c
)
3207 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
3210 if (! NILP (also_record
))
3211 echo_char (also_record
);
3212 /* Once we reread a character, echoing can happen
3213 the next time we pause to read a new one. */
3214 ok_to_echo_at_next_pause
= current_kboard
;
3217 /* Record this character as part of the current key. */
3218 add_command_key (c
);
3219 if (! NILP (also_record
))
3220 add_command_key (also_record
);
3223 last_input_char
= c
;
3226 /* Process the help character specially if enabled */
3227 if (!NILP (Vhelp_form
) && help_char_p (c
))
3230 count
= SPECPDL_INDEX ();
3232 record_unwind_protect (Fset_window_configuration
,
3233 Fcurrent_window_configuration (Qnil
));
3235 tem0
= Feval (Vhelp_form
);
3237 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
3241 c
= read_char (0, 0, 0, Qnil
, 0);
3242 while (BUFFERP (c
));
3243 /* Remove the help from the frame */
3244 unbind_to (count
, Qnil
);
3247 if (EQ (c
, make_number (040)))
3251 c
= read_char (0, 0, 0, Qnil
, 0);
3252 while (BUFFERP (c
));
3261 /* Record a key that came from a mouse menu.
3262 Record it for echoing, for this-command-keys, and so on. */
3268 /* Wipe the echo area. */
3269 clear_message (1, 0);
3274 before_command_key_count
= this_command_key_count
;
3275 before_command_echo_length
= echo_length ();
3278 /* Don't echo mouse motion events. */
3279 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
3280 && NILP (Fzerop (Vecho_keystrokes
)))
3284 /* Once we reread a character, echoing can happen
3285 the next time we pause to read a new one. */
3286 ok_to_echo_at_next_pause
= 0;
3289 /* Record this character as part of the current key. */
3290 add_command_key (c
);
3292 /* Re-reading in the middle of a command */
3293 last_input_char
= c
;
3297 /* Return 1 if should recognize C as "the help character". */
3305 if (EQ (c
, Vhelp_char
))
3307 for (tail
= Vhelp_event_list
; CONSP (tail
); tail
= XCDR (tail
))
3308 if (EQ (c
, XCAR (tail
)))
3313 /* Record the input event C in various ways. */
3321 if (CONSP (c
) && (EQ (XCAR (c
), Qhelp_echo
) || EQ (XCAR (c
), Qmouse_movement
)))
3323 /* To avoid filling recent_keys with help-echo and mouse-movement
3324 events, we filter out repeated help-echo events, only store the
3325 first and last in a series of mouse-movement events, and don't
3326 store repeated help-echo events which are only separated by
3327 mouse-movement events. */
3329 Lisp_Object ev1
, ev2
, ev3
;
3332 if ((ix1
= recent_keys_index
- 1) < 0)
3333 ix1
= NUM_RECENT_KEYS
- 1;
3334 ev1
= AREF (recent_keys
, ix1
);
3336 if ((ix2
= ix1
- 1) < 0)
3337 ix2
= NUM_RECENT_KEYS
- 1;
3338 ev2
= AREF (recent_keys
, ix2
);
3340 if ((ix3
= ix2
- 1) < 0)
3341 ix3
= NUM_RECENT_KEYS
- 1;
3342 ev3
= AREF (recent_keys
, ix3
);
3344 if (EQ (XCAR (c
), Qhelp_echo
))
3346 /* Don't record `help-echo' in recent_keys unless it shows some help
3347 message, and a different help than the previously recorded
3349 Lisp_Object help
, last_help
;
3351 help
= Fcar_safe (Fcdr_safe (XCDR (c
)));
3352 if (!STRINGP (help
))
3354 else if (CONSP (ev1
) && EQ (XCAR (ev1
), Qhelp_echo
)
3355 && (last_help
= Fcar_safe (Fcdr_safe (XCDR (ev1
))), EQ (last_help
, help
)))
3357 else if (CONSP (ev1
) && EQ (XCAR (ev1
), Qmouse_movement
)
3358 && CONSP (ev2
) && EQ (XCAR (ev2
), Qhelp_echo
)
3359 && (last_help
= Fcar_safe (Fcdr_safe (XCDR (ev2
))), EQ (last_help
, help
)))
3361 else if (CONSP (ev1
) && EQ (XCAR (ev1
), Qmouse_movement
)
3362 && CONSP (ev2
) && EQ (XCAR (ev2
), Qmouse_movement
)
3363 && CONSP (ev3
) && EQ (XCAR (ev3
), Qhelp_echo
)
3364 && (last_help
= Fcar_safe (Fcdr_safe (XCDR (ev3
))), EQ (last_help
, help
)))
3367 else if (EQ (XCAR (c
), Qmouse_movement
))
3369 /* Only record one pair of `mouse-movement' on a window in recent_keys.
3370 So additional mouse movement events replace the last element. */
3371 Lisp_Object last_window
, window
;
3373 window
= Fcar_safe (Fcar_safe (XCDR (c
)));
3374 if (CONSP (ev1
) && EQ (XCAR (ev1
), Qmouse_movement
)
3375 && (last_window
= Fcar_safe (Fcar_safe (XCDR (ev1
))), EQ (last_window
, window
))
3376 && CONSP (ev2
) && EQ (XCAR (ev2
), Qmouse_movement
)
3377 && (last_window
= Fcar_safe (Fcar_safe (XCDR (ev2
))), EQ (last_window
, window
)))
3379 ASET (recent_keys
, ix1
, c
);
3385 store_kbd_macro_char (c
);
3390 ASET (recent_keys
, recent_keys_index
, c
);
3391 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
3392 recent_keys_index
= 0;
3394 else if (recorded
< 0)
3396 /* We need to remove one or two events from recent_keys.
3397 To do this, we simply put nil at those events and move the
3398 recent_keys_index backwards over those events. Usually,
3399 users will never see those nil events, as they will be
3400 overwritten by the command keys entered to see recent_keys
3403 while (recorded
++ < 0 && total_keys
> 0)
3405 if (total_keys
< NUM_RECENT_KEYS
)
3407 if (--recent_keys_index
< 0)
3408 recent_keys_index
= NUM_RECENT_KEYS
- 1;
3409 ASET (recent_keys
, recent_keys_index
, Qnil
);
3413 num_nonmacro_input_events
++;
3415 /* Write c to the dribble file. If c is a lispy event, write
3416 the event's symbol to the dribble file, in <brackets>. Bleaugh.
3417 If you, dear reader, have a better idea, you've got the source. :-) */
3422 if (XUINT (c
) < 0x100)
3423 putc (XINT (c
), dribble
);
3425 fprintf (dribble
, " 0x%x", (int) XUINT (c
));
3429 Lisp_Object dribblee
;
3431 /* If it's a structured event, take the event header. */
3432 dribblee
= EVENT_HEAD (c
);
3434 if (SYMBOLP (dribblee
))
3436 putc ('<', dribble
);
3437 fwrite (SDATA (SYMBOL_NAME (dribblee
)), sizeof (char),
3438 SBYTES (SYMBOL_NAME (dribblee
)),
3440 putc ('>', dribble
);
3452 struct buffer
*old
= current_buffer
;
3453 Fprinc (object
, Qnil
);
3454 set_buffer_internal (XBUFFER (Vstandard_output
));
3455 call0 (intern ("help-mode"));
3456 set_buffer_internal (old
);
3460 /* Copy out or in the info on where C-g should throw to.
3461 This is used when running Lisp code from within get_char,
3462 in case get_char is called recursively.
3463 See read_process_output. */
3469 bcopy (getcjmp
, temp
, sizeof getcjmp
);
3473 restore_getcjmp (temp
)
3476 bcopy (temp
, getcjmp
, sizeof getcjmp
);
3481 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
3482 of this function. */
3485 tracking_off (old_value
)
3486 Lisp_Object old_value
;
3488 do_mouse_tracking
= old_value
;
3489 if (NILP (old_value
))
3491 /* Redisplay may have been preempted because there was input
3492 available, and it assumes it will be called again after the
3493 input has been processed. If the only input available was
3494 the sort that we have just disabled, then we need to call
3496 if (!readable_events (READABLE_EVENTS_DO_TIMERS_NOW
))
3498 redisplay_preserve_echo_area (6);
3499 get_input_pending (&input_pending
,
3500 READABLE_EVENTS_DO_TIMERS_NOW
);
3506 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
3507 doc
: /* Evaluate BODY with mouse movement events enabled.
3508 Within a `track-mouse' form, mouse motion generates input events that
3509 you can read with `read-event'.
3510 Normally, mouse motion is ignored.
3511 usage: (track-mouse BODY ...) */)
3515 int count
= SPECPDL_INDEX ();
3518 record_unwind_protect (tracking_off
, do_mouse_tracking
);
3520 do_mouse_tracking
= Qt
;
3522 val
= Fprogn (args
);
3523 return unbind_to (count
, val
);
3526 /* If mouse has moved on some frame, return one of those frames.
3527 Return 0 otherwise. */
3532 Lisp_Object tail
, frame
;
3534 FOR_EACH_FRAME (tail
, frame
)
3536 if (XFRAME (frame
)->mouse_moved
)
3537 return XFRAME (frame
);
3543 #endif /* HAVE_MOUSE */
3545 /* Low level keyboard/mouse input.
3546 kbd_buffer_store_event places events in kbd_buffer, and
3547 kbd_buffer_get_event retrieves them. */
3549 /* Return true iff there are any events in the queue that read-char
3550 would return. If this returns false, a read-char would block. */
3552 readable_events (flags
)
3555 if (flags
& READABLE_EVENTS_DO_TIMERS_NOW
)
3558 /* If the buffer contains only FOCUS_IN_EVENT events, and
3559 READABLE_EVENTS_FILTER_EVENTS is set, report it as empty. */
3560 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3562 if (flags
& (READABLE_EVENTS_FILTER_EVENTS
3563 #ifdef USE_TOOLKIT_SCROLL_BARS
3564 | READABLE_EVENTS_IGNORE_SQUEEZABLES
3568 struct input_event
*event
;
3570 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
3577 #ifdef USE_TOOLKIT_SCROLL_BARS
3578 (flags
& READABLE_EVENTS_FILTER_EVENTS
) &&
3580 event
->kind
== FOCUS_IN_EVENT
)
3581 #ifdef USE_TOOLKIT_SCROLL_BARS
3582 && !((flags
& READABLE_EVENTS_IGNORE_SQUEEZABLES
)
3583 && event
->kind
== SCROLL_BAR_CLICK_EVENT
3584 && event
->part
== scroll_bar_handle
3585 && event
->modifiers
== 0)
3590 if (event
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3593 while (event
!= kbd_store_ptr
);
3600 if (!(flags
& READABLE_EVENTS_IGNORE_SQUEEZABLES
)
3601 && !NILP (do_mouse_tracking
) && some_mouse_moved ())
3606 if (current_kboard
->kbd_queue_has_data
)
3612 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
3613 if (kb
->kbd_queue_has_data
)
3619 /* Set this for debugging, to have a way to get out */
3624 event_to_kboard (event
)
3625 struct input_event
*event
;
3628 frame
= event
->frame_or_window
;
3630 frame
= XCAR (frame
);
3631 else if (WINDOWP (frame
))
3632 frame
= WINDOW_FRAME (XWINDOW (frame
));
3634 /* There are still some events that don't set this field.
3635 For now, just ignore the problem.
3636 Also ignore dead frames here. */
3637 if (!FRAMEP (frame
) || !FRAME_LIVE_P (XFRAME (frame
)))
3640 return FRAME_KBOARD (XFRAME (frame
));
3645 Lisp_Object Vthrow_on_input
;
3647 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
3650 kbd_buffer_store_event (event
)
3651 register struct input_event
*event
;
3653 kbd_buffer_store_event_hold (event
, 0);
3656 /* Store EVENT obtained at interrupt level into kbd_buffer, fifo.
3658 If HOLD_QUIT is 0, just stuff EVENT into the fifo.
3659 Else, if HOLD_QUIT.kind != NO_EVENT, discard EVENT.
3660 Else, if EVENT is a quit event, store the quit event
3661 in HOLD_QUIT, and return (thus ignoring further events).
3663 This is used in read_avail_input to postpone the processing
3664 of the quit event until all subsequent input events have been
3665 parsed (and discarded).
3669 kbd_buffer_store_event_hold (event
, hold_quit
)
3670 register struct input_event
*event
;
3671 struct input_event
*hold_quit
;
3673 if (event
->kind
== NO_EVENT
)
3676 if (hold_quit
&& hold_quit
->kind
!= NO_EVENT
)
3679 if (event
->kind
== ASCII_KEYSTROKE_EVENT
)
3681 register int c
= event
->code
& 0377;
3683 if (event
->modifiers
& ctrl_modifier
)
3684 c
= make_ctrl_char (c
);
3686 c
|= (event
->modifiers
3687 & (meta_modifier
| alt_modifier
3688 | hyper_modifier
| super_modifier
));
3694 struct input_event
*sp
;
3697 && (kb
= FRAME_KBOARD (XFRAME (event
->frame_or_window
)),
3698 kb
!= current_kboard
))
3701 = Fcons (make_lispy_switch_frame (event
->frame_or_window
),
3702 Fcons (make_number (c
), Qnil
));
3703 kb
->kbd_queue_has_data
= 1;
3704 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
3706 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3709 if (event_to_kboard (sp
) == kb
)
3711 sp
->kind
= NO_EVENT
;
3712 sp
->frame_or_window
= Qnil
;
3722 bcopy (event
, (char *) hold_quit
, sizeof (*event
));
3726 /* If this results in a quit_char being returned to Emacs as
3727 input, set Vlast_event_frame properly. If this doesn't
3728 get returned to Emacs as an event, the next event read
3729 will set Vlast_event_frame again, so this is safe to do. */
3733 focus
= FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
3735 focus
= event
->frame_or_window
;
3736 internal_last_event_frame
= focus
;
3737 Vlast_event_frame
= focus
;
3740 last_event_timestamp
= event
->timestamp
;
3741 handle_interrupt ();
3745 if (c
&& c
== stop_character
)
3751 /* Don't insert two BUFFER_SWITCH_EVENT's in a row.
3752 Just ignore the second one. */
3753 else if (event
->kind
== BUFFER_SWITCH_EVENT
3754 && kbd_fetch_ptr
!= kbd_store_ptr
3755 && ((kbd_store_ptr
== kbd_buffer
3756 ? kbd_buffer
+ KBD_BUFFER_SIZE
- 1
3757 : kbd_store_ptr
- 1)->kind
) == BUFFER_SWITCH_EVENT
)
3760 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
3761 kbd_store_ptr
= kbd_buffer
;
3763 /* Don't let the very last slot in the buffer become full,
3764 since that would make the two pointers equal,
3765 and that is indistinguishable from an empty buffer.
3766 Discard the event if it would fill the last slot. */
3767 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
3769 *kbd_store_ptr
= *event
;
3773 /* If we're inside while-no-input, and this event qualifies
3774 as input, set quit-flag to cause an interrupt. */
3775 if (!NILP (Vthrow_on_input
)
3776 && event
->kind
!= FOCUS_IN_EVENT
3777 && event
->kind
!= HELP_EVENT
3778 && event
->kind
!= DEICONIFY_EVENT
)
3780 Vquit_flag
= Vthrow_on_input
;
3781 /* If we're inside a function that wants immediate quits,
3783 if (immediate_quit
&& NILP (Vinhibit_quit
))
3793 /* Put an input event back in the head of the event queue. */
3796 kbd_buffer_unget_event (event
)
3797 register struct input_event
*event
;
3799 if (kbd_fetch_ptr
== kbd_buffer
)
3800 kbd_fetch_ptr
= kbd_buffer
+ KBD_BUFFER_SIZE
;
3802 /* Don't let the very last slot in the buffer become full, */
3803 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
3806 *kbd_fetch_ptr
= *event
;
3811 /* Generate HELP_EVENT input_events in BUFP which has room for
3812 SIZE events. If there's not enough room in BUFP, ignore this
3815 HELP is the help form.
3817 FRAME is the frame on which the help is generated. OBJECT is the
3818 Lisp object where the help was found (a buffer, a string, an
3819 overlay, or nil if neither from a string nor from a buffer. POS is
3820 the position within OBJECT where the help was found.
3822 Value is the number of input_events generated. */
3825 gen_help_event (help
, frame
, window
, object
, pos
)
3826 Lisp_Object help
, frame
, object
, window
;
3829 struct input_event event
;
3833 event
.kind
= HELP_EVENT
;
3834 event
.frame_or_window
= frame
;
3836 event
.x
= WINDOWP (window
) ? window
: frame
;
3839 kbd_buffer_store_event (&event
);
3843 /* Store HELP_EVENTs for HELP on FRAME in the input queue. */
3846 kbd_buffer_store_help_event (frame
, help
)
3847 Lisp_Object frame
, help
;
3849 struct input_event event
;
3851 event
.kind
= HELP_EVENT
;
3852 event
.frame_or_window
= frame
;
3857 kbd_buffer_store_event (&event
);
3861 /* Discard any mouse events in the event buffer by setting them to
3864 discard_mouse_events ()
3866 struct input_event
*sp
;
3867 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
3869 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3872 if (sp
->kind
== MOUSE_CLICK_EVENT
3873 || sp
->kind
== WHEEL_EVENT
3875 || sp
->kind
== W32_SCROLL_BAR_CLICK_EVENT
3877 || sp
->kind
== SCROLL_BAR_CLICK_EVENT
)
3879 sp
->kind
= NO_EVENT
;
3885 /* Return non-zero if there are any real events waiting in the event
3886 buffer, not counting `NO_EVENT's.
3888 If DISCARD is non-zero, discard NO_EVENT events at the front of
3889 the input queue, possibly leaving the input queue empty if there
3890 are no real input events. */
3893 kbd_buffer_events_waiting (discard
)
3896 struct input_event
*sp
;
3898 for (sp
= kbd_fetch_ptr
;
3899 sp
!= kbd_store_ptr
&& sp
->kind
== NO_EVENT
;
3902 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3909 return sp
!= kbd_store_ptr
&& sp
->kind
!= NO_EVENT
;
3913 /* Clear input event EVENT. */
3917 struct input_event
*event
;
3919 event
->kind
= NO_EVENT
;
3923 /* Read one event from the event buffer, waiting if necessary.
3924 The value is a Lisp object representing the event.
3925 The value is nil for an event that should be ignored,
3926 or that was handled here.
3927 We always read and discard one event. */
3930 kbd_buffer_get_event (kbp
, used_mouse_menu
)
3932 int *used_mouse_menu
;
3941 *kbp
= current_kboard
;
3945 /* Wait until there is input available. */
3948 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3951 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
3955 /* If the quit flag is set, then read_char will return
3956 quit_char, so that counts as "available input." */
3957 if (!NILP (Vquit_flag
))
3958 quit_throw_to_read_char ();
3960 /* One way or another, wait until input is available; then, if
3961 interrupt handlers have not read it, read it now. */
3964 wait_for_kbd_input ();
3966 /* Note SIGIO has been undef'd if FIONREAD is missing. */
3970 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3973 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
3977 wait_reading_process_output (0, 0, -1, 1, Qnil
, NULL
, 0);
3979 if (!interrupt_input
&& kbd_fetch_ptr
== kbd_store_ptr
)
3980 /* Pass 1 for EXPECT since we just waited to have input. */
3981 read_avail_input (1);
3983 #endif /* not VMS */
3986 if (CONSP (Vunread_command_events
))
3989 first
= XCAR (Vunread_command_events
);
3990 Vunread_command_events
= XCDR (Vunread_command_events
);
3991 *kbp
= current_kboard
;
3995 /* At this point, we know that there is a readable event available
3996 somewhere. If the event queue is empty, then there must be a
3997 mouse movement enabled and available. */
3998 if (kbd_fetch_ptr
!= kbd_store_ptr
)
4000 struct input_event
*event
;
4002 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
4006 last_event_timestamp
= event
->timestamp
;
4009 *kbp
= event_to_kboard (event
);
4011 *kbp
= current_kboard
; /* Better than returning null ptr? */
4013 *kbp
= &the_only_kboard
;
4018 /* These two kinds of events get special handling
4019 and don't actually appear to the command loop.
4020 We return nil for them. */
4021 if (event
->kind
== SELECTION_REQUEST_EVENT
4022 || event
->kind
== SELECTION_CLEAR_EVENT
)
4025 struct input_event copy
;
4027 /* Remove it from the buffer before processing it,
4028 since otherwise swallow_events will see it
4029 and process it again. */
4031 kbd_fetch_ptr
= event
+ 1;
4032 input_pending
= readable_events (0);
4033 x_handle_selection_event (©
);
4035 /* We're getting selection request events, but we don't have
4041 #if defined (HAVE_X11) || defined (HAVE_NTGUI) || defined (MAC_OS)
4042 else if (event
->kind
== DELETE_WINDOW_EVENT
)
4044 /* Make an event (delete-frame (FRAME)). */
4045 obj
= Fcons (event
->frame_or_window
, Qnil
);
4046 obj
= Fcons (Qdelete_frame
, Fcons (obj
, Qnil
));
4047 kbd_fetch_ptr
= event
+ 1;
4050 #if defined (HAVE_X11) || defined (HAVE_NTGUI) || defined (MAC_OS)
4051 else if (event
->kind
== ICONIFY_EVENT
)
4053 /* Make an event (iconify-frame (FRAME)). */
4054 obj
= Fcons (event
->frame_or_window
, Qnil
);
4055 obj
= Fcons (Qiconify_frame
, Fcons (obj
, Qnil
));
4056 kbd_fetch_ptr
= event
+ 1;
4058 else if (event
->kind
== DEICONIFY_EVENT
)
4060 /* Make an event (make-frame-visible (FRAME)). */
4061 obj
= Fcons (event
->frame_or_window
, Qnil
);
4062 obj
= Fcons (Qmake_frame_visible
, Fcons (obj
, Qnil
));
4063 kbd_fetch_ptr
= event
+ 1;
4066 else if (event
->kind
== BUFFER_SWITCH_EVENT
)
4068 /* The value doesn't matter here; only the type is tested. */
4069 XSETBUFFER (obj
, current_buffer
);
4070 kbd_fetch_ptr
= event
+ 1;
4072 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
4073 || defined (USE_GTK)
4074 else if (event
->kind
== MENU_BAR_ACTIVATE_EVENT
)
4076 kbd_fetch_ptr
= event
+ 1;
4077 input_pending
= readable_events (0);
4078 if (FRAME_LIVE_P (XFRAME (event
->frame_or_window
)))
4079 x_activate_menubar (XFRAME (event
->frame_or_window
));
4082 #if defined (WINDOWSNT) || defined (MAC_OS)
4083 else if (event
->kind
== LANGUAGE_CHANGE_EVENT
)
4086 /* Make an event (language-change (KEY_SCRIPT)). */
4087 obj
= Fcons (make_number (event
->code
), Qnil
);
4089 /* Make an event (language-change (FRAME CHARSET LCID)). */
4090 obj
= Fcons (event
->frame_or_window
, Qnil
);
4092 obj
= Fcons (Qlanguage_change
, Fcons (obj
, Qnil
));
4093 kbd_fetch_ptr
= event
+ 1;
4096 else if (event
->kind
== SAVE_SESSION_EVENT
)
4098 obj
= Fcons (Qsave_session
, Qnil
);
4099 kbd_fetch_ptr
= event
+ 1;
4101 /* Just discard these, by returning nil.
4102 With MULTI_KBOARD, these events are used as placeholders
4103 when we need to randomly delete events from the queue.
4104 (They shouldn't otherwise be found in the buffer,
4105 but on some machines it appears they do show up
4106 even without MULTI_KBOARD.) */
4107 /* On Windows NT/9X, NO_EVENT is used to delete extraneous
4108 mouse events during a popup-menu call. */
4109 else if (event
->kind
== NO_EVENT
)
4110 kbd_fetch_ptr
= event
+ 1;
4111 else if (event
->kind
== HELP_EVENT
)
4113 Lisp_Object object
, position
, help
, frame
, window
;
4115 frame
= event
->frame_or_window
;
4116 object
= event
->arg
;
4117 position
= make_number (event
->code
);
4120 clear_event (event
);
4122 kbd_fetch_ptr
= event
+ 1;
4123 if (!WINDOWP (window
))
4125 obj
= Fcons (Qhelp_echo
,
4126 list5 (frame
, help
, window
, object
, position
));
4128 else if (event
->kind
== FOCUS_IN_EVENT
)
4130 /* Notification of a FocusIn event. The frame receiving the
4131 focus is in event->frame_or_window. Generate a
4132 switch-frame event if necessary. */
4133 Lisp_Object frame
, focus
;
4135 frame
= event
->frame_or_window
;
4136 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
4140 if (!EQ (frame
, internal_last_event_frame
)
4141 && !EQ (frame
, selected_frame
))
4142 obj
= make_lispy_switch_frame (frame
);
4143 internal_last_event_frame
= frame
;
4144 kbd_fetch_ptr
= event
+ 1;
4148 /* If this event is on a different frame, return a switch-frame this
4149 time, and leave the event in the queue for next time. */
4153 frame
= event
->frame_or_window
;
4155 frame
= XCAR (frame
);
4156 else if (WINDOWP (frame
))
4157 frame
= WINDOW_FRAME (XWINDOW (frame
));
4159 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
4163 if (! EQ (frame
, internal_last_event_frame
)
4164 && !EQ (frame
, selected_frame
))
4165 obj
= make_lispy_switch_frame (frame
);
4166 internal_last_event_frame
= frame
;
4168 /* If we didn't decide to make a switch-frame event, go ahead
4169 and build a real event from the queue entry. */
4173 obj
= make_lispy_event (event
);
4175 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined(MAC_OS) \
4176 || defined (USE_GTK)
4177 /* If this was a menu selection, then set the flag to inhibit
4178 writing to last_nonmenu_event. Don't do this if the event
4179 we're returning is (menu-bar), though; that indicates the
4180 beginning of the menu sequence, and we might as well leave
4181 that as the `event with parameters' for this selection. */
4183 && !EQ (event
->frame_or_window
, event
->arg
)
4184 && (event
->kind
== MENU_BAR_EVENT
4185 || event
->kind
== TOOL_BAR_EVENT
))
4186 *used_mouse_menu
= 1;
4189 /* Wipe out this event, to catch bugs. */
4190 clear_event (event
);
4191 kbd_fetch_ptr
= event
+ 1;
4196 /* Try generating a mouse motion event. */
4197 else if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
4199 FRAME_PTR f
= some_mouse_moved ();
4200 Lisp_Object bar_window
;
4201 enum scroll_bar_part part
;
4205 *kbp
= current_kboard
;
4206 /* Note that this uses F to determine which display to look at.
4207 If there is no valid info, it does not store anything
4208 so x remains nil. */
4211 /* XXX Can f or mouse_position_hook be NULL here? */
4212 if (f
&& FRAME_DEVICE (f
)->mouse_position_hook
)
4213 (*FRAME_DEVICE (f
)->mouse_position_hook
) (&f
, 0, &bar_window
,
4214 &part
, &x
, &y
, &time
);
4218 /* Decide if we should generate a switch-frame event. Don't
4219 generate switch-frame events for motion outside of all Emacs
4225 frame
= FRAME_FOCUS_FRAME (f
);
4227 XSETFRAME (frame
, f
);
4229 if (! EQ (frame
, internal_last_event_frame
)
4230 && !EQ (frame
, selected_frame
))
4231 obj
= make_lispy_switch_frame (frame
);
4232 internal_last_event_frame
= frame
;
4235 /* If we didn't decide to make a switch-frame event, go ahead and
4236 return a mouse-motion event. */
4237 if (!NILP (x
) && NILP (obj
))
4238 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
4240 #endif /* HAVE_MOUSE */
4242 /* We were promised by the above while loop that there was
4243 something for us to read! */
4246 input_pending
= readable_events (0);
4248 Vlast_event_frame
= internal_last_event_frame
;
4253 /* Process any events that are not user-visible,
4254 then return, without reading any user-visible events. */
4257 swallow_events (do_display
)
4262 while (kbd_fetch_ptr
!= kbd_store_ptr
)
4264 struct input_event
*event
;
4266 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
4270 last_event_timestamp
= event
->timestamp
;
4272 /* These two kinds of events get special handling
4273 and don't actually appear to the command loop. */
4274 if (event
->kind
== SELECTION_REQUEST_EVENT
4275 || event
->kind
== SELECTION_CLEAR_EVENT
)
4278 struct input_event copy
;
4280 /* Remove it from the buffer before processing it,
4281 since otherwise swallow_events called recursively could see it
4282 and process it again. */
4284 kbd_fetch_ptr
= event
+ 1;
4285 input_pending
= readable_events (0);
4286 x_handle_selection_event (©
);
4288 /* We're getting selection request events, but we don't have
4297 old_timers_run
= timers_run
;
4298 get_input_pending (&input_pending
, READABLE_EVENTS_DO_TIMERS_NOW
);
4300 if (timers_run
!= old_timers_run
&& do_display
)
4301 redisplay_preserve_echo_area (7);
4304 /* Record the start of when Emacs is idle,
4305 for the sake of running idle-time timers. */
4312 /* If we are already in the idle state, do nothing. */
4313 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
4316 EMACS_GET_TIME (timer_idleness_start_time
);
4318 timer_last_idleness_start_time
= timer_idleness_start_time
;
4320 /* Mark all idle-time timers as once again candidates for running. */
4321 for (timers
= Vtimer_idle_list
; CONSP (timers
); timers
= XCDR (timers
))
4325 timer
= XCAR (timers
);
4327 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
4329 XVECTOR (timer
)->contents
[0] = Qnil
;
4333 /* Record that Emacs is no longer idle, so stop running idle-time timers. */
4338 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
4341 /* Resume idle timer from last idle start time. */
4344 timer_resume_idle ()
4346 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
4349 timer_idleness_start_time
= timer_last_idleness_start_time
;
4352 /* This is only for debugging. */
4353 struct input_event last_timer_event
;
4355 /* Check whether a timer has fired. To prevent larger problems we simply
4356 disregard elements that are not proper timers. Do not make a circular
4357 timer list for the time being.
4359 Returns the number of seconds to wait until the next timer fires. If a
4360 timer is triggering now, return zero seconds.
4361 If no timer is active, return -1 seconds.
4363 If a timer is ripe, we run it, with quitting turned off.
4365 DO_IT_NOW is now ignored. It used to mean that we should
4366 run the timer directly instead of queueing a timer-event.
4367 Now we always run timers directly. */
4370 timer_check (do_it_now
)
4373 EMACS_TIME nexttime
;
4374 EMACS_TIME now
, idleness_now
;
4375 Lisp_Object timers
, idle_timers
, chosen_timer
;
4376 struct gcpro gcpro1
, gcpro2
, gcpro3
;
4378 EMACS_SET_SECS (nexttime
, -1);
4379 EMACS_SET_USECS (nexttime
, -1);
4381 /* Always consider the ordinary timers. */
4382 timers
= Vtimer_list
;
4383 /* Consider the idle timers only if Emacs is idle. */
4384 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
4385 idle_timers
= Vtimer_idle_list
;
4388 chosen_timer
= Qnil
;
4389 GCPRO3 (timers
, idle_timers
, chosen_timer
);
4391 if (CONSP (timers
) || CONSP (idle_timers
))
4393 EMACS_GET_TIME (now
);
4394 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
4395 EMACS_SUB_TIME (idleness_now
, now
, timer_idleness_start_time
);
4398 while (CONSP (timers
) || CONSP (idle_timers
))
4400 Lisp_Object
*vector
;
4401 Lisp_Object timer
= Qnil
, idle_timer
= Qnil
;
4402 EMACS_TIME timer_time
, idle_timer_time
;
4403 EMACS_TIME difference
, timer_difference
, idle_timer_difference
;
4405 /* Skip past invalid timers and timers already handled. */
4408 timer
= XCAR (timers
);
4409 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
4411 timers
= XCDR (timers
);
4414 vector
= XVECTOR (timer
)->contents
;
4416 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
4417 || !INTEGERP (vector
[3])
4418 || ! NILP (vector
[0]))
4420 timers
= XCDR (timers
);
4424 if (!NILP (idle_timers
))
4426 timer
= XCAR (idle_timers
);
4427 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
4429 idle_timers
= XCDR (idle_timers
);
4432 vector
= XVECTOR (timer
)->contents
;
4434 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
4435 || !INTEGERP (vector
[3])
4436 || ! NILP (vector
[0]))
4438 idle_timers
= XCDR (idle_timers
);
4443 /* Set TIMER, TIMER_TIME and TIMER_DIFFERENCE
4444 based on the next ordinary timer.
4445 TIMER_DIFFERENCE is the distance in time from NOW to when
4446 this timer becomes ripe (negative if it's already ripe). */
4449 timer
= XCAR (timers
);
4450 vector
= XVECTOR (timer
)->contents
;
4451 EMACS_SET_SECS (timer_time
,
4452 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
4453 EMACS_SET_USECS (timer_time
, XINT (vector
[3]));
4454 EMACS_SUB_TIME (timer_difference
, timer_time
, now
);
4457 /* Set IDLE_TIMER, IDLE_TIMER_TIME and IDLE_TIMER_DIFFERENCE
4458 based on the next idle timer. */
4459 if (!NILP (idle_timers
))
4461 idle_timer
= XCAR (idle_timers
);
4462 vector
= XVECTOR (idle_timer
)->contents
;
4463 EMACS_SET_SECS (idle_timer_time
,
4464 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
4465 EMACS_SET_USECS (idle_timer_time
, XINT (vector
[3]));
4466 EMACS_SUB_TIME (idle_timer_difference
, idle_timer_time
, idleness_now
);
4469 /* Decide which timer is the next timer,
4470 and set CHOSEN_TIMER, VECTOR and DIFFERENCE accordingly.
4471 Also step down the list where we found that timer. */
4473 if (! NILP (timers
) && ! NILP (idle_timers
))
4476 EMACS_SUB_TIME (temp
, timer_difference
, idle_timer_difference
);
4477 if (EMACS_TIME_NEG_P (temp
))
4479 chosen_timer
= timer
;
4480 timers
= XCDR (timers
);
4481 difference
= timer_difference
;
4485 chosen_timer
= idle_timer
;
4486 idle_timers
= XCDR (idle_timers
);
4487 difference
= idle_timer_difference
;
4490 else if (! NILP (timers
))
4492 chosen_timer
= timer
;
4493 timers
= XCDR (timers
);
4494 difference
= timer_difference
;
4498 chosen_timer
= idle_timer
;
4499 idle_timers
= XCDR (idle_timers
);
4500 difference
= idle_timer_difference
;
4502 vector
= XVECTOR (chosen_timer
)->contents
;
4504 /* If timer is ripe, run it if it hasn't been run. */
4505 if (EMACS_TIME_NEG_P (difference
)
4506 || (EMACS_SECS (difference
) == 0
4507 && EMACS_USECS (difference
) == 0))
4509 if (NILP (vector
[0]))
4511 int count
= SPECPDL_INDEX ();
4512 Lisp_Object old_deactivate_mark
= Vdeactivate_mark
;
4514 /* On unbind_to, resume allowing input from any kboard, if that
4516 record_single_kboard_state ();
4518 /* Mark the timer as triggered to prevent problems if the lisp
4519 code fails to reschedule it right. */
4522 specbind (Qinhibit_quit
, Qt
);
4524 call1 (Qtimer_event_handler
, chosen_timer
);
4525 Vdeactivate_mark
= old_deactivate_mark
;
4527 unbind_to (count
, Qnil
);
4529 /* Since we have handled the event,
4530 we don't need to tell the caller to wake up and do it. */
4534 /* When we encounter a timer that is still waiting,
4535 return the amount of time to wait before it is ripe. */
4542 /* No timers are pending in the future. */
4543 /* Return 0 if we generated an event, and -1 if not. */
4548 /* Caches for modify_event_symbol. */
4549 static Lisp_Object accent_key_syms
;
4550 static Lisp_Object func_key_syms
;
4551 static Lisp_Object mouse_syms
;
4552 static Lisp_Object wheel_syms
;
4553 static Lisp_Object drag_n_drop_syms
;
4555 /* This is a list of keysym codes for special "accent" characters.
4556 It parallels lispy_accent_keys. */
4558 static int lispy_accent_codes
[] =
4560 #ifdef XK_dead_circumflex
4565 #ifdef XK_dead_grave
4570 #ifdef XK_dead_tilde
4575 #ifdef XK_dead_diaeresis
4580 #ifdef XK_dead_macron
4585 #ifdef XK_dead_degree
4590 #ifdef XK_dead_acute
4595 #ifdef XK_dead_cedilla
4600 #ifdef XK_dead_breve
4605 #ifdef XK_dead_ogonek
4610 #ifdef XK_dead_caron
4615 #ifdef XK_dead_doubleacute
4616 XK_dead_doubleacute
,
4620 #ifdef XK_dead_abovedot
4625 #ifdef XK_dead_abovering
4635 #ifdef XK_dead_belowdot
4640 #ifdef XK_dead_voiced_sound
4641 XK_dead_voiced_sound
,
4645 #ifdef XK_dead_semivoiced_sound
4646 XK_dead_semivoiced_sound
,
4662 /* This is a list of Lisp names for special "accent" characters.
4663 It parallels lispy_accent_codes. */
4665 static char *lispy_accent_keys
[] =
4683 "dead-voiced-sound",
4684 "dead-semivoiced-sound",
4690 #define FUNCTION_KEY_OFFSET 0x0
4692 char *lispy_function_keys
[] =
4696 0, /* VK_LBUTTON 0x01 */
4697 0, /* VK_RBUTTON 0x02 */
4698 "cancel", /* VK_CANCEL 0x03 */
4699 0, /* VK_MBUTTON 0x04 */
4701 0, 0, 0, /* 0x05 .. 0x07 */
4703 "backspace", /* VK_BACK 0x08 */
4704 "tab", /* VK_TAB 0x09 */
4706 0, 0, /* 0x0A .. 0x0B */
4708 "clear", /* VK_CLEAR 0x0C */
4709 "return", /* VK_RETURN 0x0D */
4711 0, 0, /* 0x0E .. 0x0F */
4713 0, /* VK_SHIFT 0x10 */
4714 0, /* VK_CONTROL 0x11 */
4715 0, /* VK_MENU 0x12 */
4716 "pause", /* VK_PAUSE 0x13 */
4717 "capslock", /* VK_CAPITAL 0x14 */
4719 0, 0, 0, 0, 0, 0, /* 0x15 .. 0x1A */
4721 "escape", /* VK_ESCAPE 0x1B */
4723 0, 0, 0, 0, /* 0x1C .. 0x1F */
4725 0, /* VK_SPACE 0x20 */
4726 "prior", /* VK_PRIOR 0x21 */
4727 "next", /* VK_NEXT 0x22 */
4728 "end", /* VK_END 0x23 */
4729 "home", /* VK_HOME 0x24 */
4730 "left", /* VK_LEFT 0x25 */
4731 "up", /* VK_UP 0x26 */
4732 "right", /* VK_RIGHT 0x27 */
4733 "down", /* VK_DOWN 0x28 */
4734 "select", /* VK_SELECT 0x29 */
4735 "print", /* VK_PRINT 0x2A */
4736 "execute", /* VK_EXECUTE 0x2B */
4737 "snapshot", /* VK_SNAPSHOT 0x2C */
4738 "insert", /* VK_INSERT 0x2D */
4739 "delete", /* VK_DELETE 0x2E */
4740 "help", /* VK_HELP 0x2F */
4742 /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
4744 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4746 0, 0, 0, 0, 0, 0, 0, /* 0x3A .. 0x40 */
4748 /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
4750 0, 0, 0, 0, 0, 0, 0, 0, 0,
4751 0, 0, 0, 0, 0, 0, 0, 0, 0,
4752 0, 0, 0, 0, 0, 0, 0, 0,
4754 "lwindow", /* VK_LWIN 0x5B */
4755 "rwindow", /* VK_RWIN 0x5C */
4756 "apps", /* VK_APPS 0x5D */
4758 0, 0, /* 0x5E .. 0x5F */
4760 "kp-0", /* VK_NUMPAD0 0x60 */
4761 "kp-1", /* VK_NUMPAD1 0x61 */
4762 "kp-2", /* VK_NUMPAD2 0x62 */
4763 "kp-3", /* VK_NUMPAD3 0x63 */
4764 "kp-4", /* VK_NUMPAD4 0x64 */
4765 "kp-5", /* VK_NUMPAD5 0x65 */
4766 "kp-6", /* VK_NUMPAD6 0x66 */
4767 "kp-7", /* VK_NUMPAD7 0x67 */
4768 "kp-8", /* VK_NUMPAD8 0x68 */
4769 "kp-9", /* VK_NUMPAD9 0x69 */
4770 "kp-multiply", /* VK_MULTIPLY 0x6A */
4771 "kp-add", /* VK_ADD 0x6B */
4772 "kp-separator", /* VK_SEPARATOR 0x6C */
4773 "kp-subtract", /* VK_SUBTRACT 0x6D */
4774 "kp-decimal", /* VK_DECIMAL 0x6E */
4775 "kp-divide", /* VK_DIVIDE 0x6F */
4776 "f1", /* VK_F1 0x70 */
4777 "f2", /* VK_F2 0x71 */
4778 "f3", /* VK_F3 0x72 */
4779 "f4", /* VK_F4 0x73 */
4780 "f5", /* VK_F5 0x74 */
4781 "f6", /* VK_F6 0x75 */
4782 "f7", /* VK_F7 0x76 */
4783 "f8", /* VK_F8 0x77 */
4784 "f9", /* VK_F9 0x78 */
4785 "f10", /* VK_F10 0x79 */
4786 "f11", /* VK_F11 0x7A */
4787 "f12", /* VK_F12 0x7B */
4788 "f13", /* VK_F13 0x7C */
4789 "f14", /* VK_F14 0x7D */
4790 "f15", /* VK_F15 0x7E */
4791 "f16", /* VK_F16 0x7F */
4792 "f17", /* VK_F17 0x80 */
4793 "f18", /* VK_F18 0x81 */
4794 "f19", /* VK_F19 0x82 */
4795 "f20", /* VK_F20 0x83 */
4796 "f21", /* VK_F21 0x84 */
4797 "f22", /* VK_F22 0x85 */
4798 "f23", /* VK_F23 0x86 */
4799 "f24", /* VK_F24 0x87 */
4801 0, 0, 0, 0, /* 0x88 .. 0x8B */
4802 0, 0, 0, 0, /* 0x8C .. 0x8F */
4804 "kp-numlock", /* VK_NUMLOCK 0x90 */
4805 "scroll", /* VK_SCROLL 0x91 */
4807 "kp-space", /* VK_NUMPAD_CLEAR 0x92 */
4808 "kp-enter", /* VK_NUMPAD_ENTER 0x93 */
4809 "kp-prior", /* VK_NUMPAD_PRIOR 0x94 */
4810 "kp-next", /* VK_NUMPAD_NEXT 0x95 */
4811 "kp-end", /* VK_NUMPAD_END 0x96 */
4812 "kp-home", /* VK_NUMPAD_HOME 0x97 */
4813 "kp-left", /* VK_NUMPAD_LEFT 0x98 */
4814 "kp-up", /* VK_NUMPAD_UP 0x99 */
4815 "kp-right", /* VK_NUMPAD_RIGHT 0x9A */
4816 "kp-down", /* VK_NUMPAD_DOWN 0x9B */
4817 "kp-insert", /* VK_NUMPAD_INSERT 0x9C */
4818 "kp-delete", /* VK_NUMPAD_DELETE 0x9D */
4820 0, 0, /* 0x9E .. 0x9F */
4823 * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
4824 * Used only as parameters to GetAsyncKeyState and GetKeyState.
4825 * No other API or message will distinguish left and right keys this way.
4829 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4830 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4831 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4832 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4833 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4839 "attn", /* VK_ATTN 0xF6 */
4840 "crsel", /* VK_CRSEL 0xF7 */
4841 "exsel", /* VK_EXSEL 0xF8 */
4842 "ereof", /* VK_EREOF 0xF9 */
4843 "play", /* VK_PLAY 0xFA */
4844 "zoom", /* VK_ZOOM 0xFB */
4845 "noname", /* VK_NONAME 0xFC */
4846 "pa1", /* VK_PA1 0xFD */
4847 "oem_clear", /* VK_OEM_CLEAR 0xFE */
4851 #else /* not HAVE_NTGUI */
4853 /* This should be dealt with in XTread_socket now, and that doesn't
4854 depend on the client system having the Kana syms defined. See also
4855 the XK_kana_A case below. */
4858 static char *lispy_kana_keys
[] =
4860 /* X Keysym value */
4861 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x400 .. 0x40f */
4862 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x410 .. 0x41f */
4863 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x420 .. 0x42f */
4864 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x430 .. 0x43f */
4865 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x440 .. 0x44f */
4866 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x450 .. 0x45f */
4867 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x460 .. 0x46f */
4868 0,0,0,0,0,0,0,0,0,0,0,0,0,0,"overline",0,
4869 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x480 .. 0x48f */
4870 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x490 .. 0x49f */
4871 0, "kana-fullstop", "kana-openingbracket", "kana-closingbracket",
4872 "kana-comma", "kana-conjunctive", "kana-WO", "kana-a",
4873 "kana-i", "kana-u", "kana-e", "kana-o",
4874 "kana-ya", "kana-yu", "kana-yo", "kana-tsu",
4875 "prolongedsound", "kana-A", "kana-I", "kana-U",
4876 "kana-E", "kana-O", "kana-KA", "kana-KI",
4877 "kana-KU", "kana-KE", "kana-KO", "kana-SA",
4878 "kana-SHI", "kana-SU", "kana-SE", "kana-SO",
4879 "kana-TA", "kana-CHI", "kana-TSU", "kana-TE",
4880 "kana-TO", "kana-NA", "kana-NI", "kana-NU",
4881 "kana-NE", "kana-NO", "kana-HA", "kana-HI",
4882 "kana-FU", "kana-HE", "kana-HO", "kana-MA",
4883 "kana-MI", "kana-MU", "kana-ME", "kana-MO",
4884 "kana-YA", "kana-YU", "kana-YO", "kana-RA",
4885 "kana-RI", "kana-RU", "kana-RE", "kana-RO",
4886 "kana-WA", "kana-N", "voicedsound", "semivoicedsound",
4887 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4e0 .. 0x4ef */
4888 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4f0 .. 0x4ff */
4890 #endif /* XK_kana_A */
4893 #define FUNCTION_KEY_OFFSET 0xff00
4895 /* You'll notice that this table is arranged to be conveniently
4896 indexed by X Windows keysym values. */
4897 static char *lispy_function_keys
[] =
4899 /* X Keysym value */
4901 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00...0f */
4902 "backspace", "tab", "linefeed", "clear",
4904 0, 0, 0, "pause", /* 0xff10...1f */
4905 0, 0, 0, 0, 0, 0, 0, "escape",
4907 0, "kanji", "muhenkan", "henkan", /* 0xff20...2f */
4908 "romaji", "hiragana", "katakana", "hiragana-katakana",
4909 "zenkaku", "hankaku", "zenkaku-hankaku", "touroku",
4910 "massyo", "kana-lock", "kana-shift", "eisu-shift",
4911 "eisu-toggle", /* 0xff30...3f */
4912 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4913 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
4915 "home", "left", "up", "right", /* 0xff50 */ /* IsCursorKey */
4916 "down", "prior", "next", "end",
4917 "begin", 0, 0, 0, 0, 0, 0, 0,
4918 "select", /* 0xff60 */ /* IsMiscFunctionKey */
4929 "break", /* 0xff6b */
4932 0, 0, 0, 0, "backtab", 0, 0, 0, /* 0xff70... */
4933 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff78... */
4934 "kp-space", /* 0xff80 */ /* IsKeypadKey */
4935 0, 0, 0, 0, 0, 0, 0, 0,
4936 "kp-tab", /* 0xff89 */
4938 "kp-enter", /* 0xff8d */
4940 "kp-f1", /* 0xff91 */
4944 "kp-home", /* 0xff95 */
4949 "kp-prior", /* kp-page-up */
4950 "kp-next", /* kp-page-down */
4956 0, 0, 0, 0, 0, 0, 0, 0, 0,
4957 "kp-multiply", /* 0xffaa */
4962 "kp-divide", /* 0xffaf */
4963 "kp-0", /* 0xffb0 */
4964 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
4967 "kp-equal", /* 0xffbd */
4968 "f1", /* 0xffbe */ /* IsFunctionKey */
4970 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
4971 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
4972 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
4973 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
4974 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
4975 0, 0, 0, 0, 0, 0, 0, 0,
4976 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
4977 0, 0, 0, 0, 0, 0, 0, "delete"
4980 /* ISO 9995 Function and Modifier Keys; the first byte is 0xFE. */
4981 #define ISO_FUNCTION_KEY_OFFSET 0xfe00
4983 static char *iso_lispy_function_keys
[] =
4985 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe00 */
4986 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe08 */
4987 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe10 */
4988 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe18 */
4989 "iso-lefttab", /* 0xfe20 */
4990 "iso-move-line-up", "iso-move-line-down",
4991 "iso-partial-line-up", "iso-partial-line-down",
4992 "iso-partial-space-left", "iso-partial-space-right",
4993 "iso-set-margin-left", "iso-set-margin-right", /* 0xffe27, 28 */
4994 "iso-release-margin-left", "iso-release-margin-right",
4995 "iso-release-both-margins",
4996 "iso-fast-cursor-left", "iso-fast-cursor-right",
4997 "iso-fast-cursor-up", "iso-fast-cursor-down",
4998 "iso-continuous-underline", "iso-discontinuous-underline", /* 0xfe30, 31 */
4999 "iso-emphasize", "iso-center-object", "iso-enter", /* ... 0xfe34 */
5002 #endif /* not HAVE_NTGUI */
5004 Lisp_Object Vlispy_mouse_stem
;
5006 static char *lispy_wheel_names
[] =
5008 "wheel-up", "wheel-down"
5011 /* drag-n-drop events are generated when a set of selected files are
5012 dragged from another application and dropped onto an Emacs window. */
5013 static char *lispy_drag_n_drop_names
[] =
5018 /* Scroll bar parts. */
5019 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
5020 Lisp_Object Qup
, Qdown
, Qbottom
, Qend_scroll
;
5021 Lisp_Object Qtop
, Qratio
;
5023 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
5024 Lisp_Object
*scroll_bar_parts
[] = {
5025 &Qabove_handle
, &Qhandle
, &Qbelow_handle
,
5026 &Qup
, &Qdown
, &Qtop
, &Qbottom
, &Qend_scroll
, &Qratio
5029 /* User signal events. */
5030 Lisp_Object Qusr1_signal
, Qusr2_signal
;
5032 Lisp_Object
*lispy_user_signals
[] =
5034 &Qusr1_signal
, &Qusr2_signal
5038 /* A vector, indexed by button number, giving the down-going location
5039 of currently depressed buttons, both scroll bar and non-scroll bar.
5041 The elements have the form
5042 (BUTTON-NUMBER MODIFIER-MASK . REST)
5043 where REST is the cdr of a position as it would be reported in the event.
5045 The make_lispy_event function stores positions here to tell the
5046 difference between click and drag events, and to store the starting
5047 location to be included in drag events. */
5049 static Lisp_Object button_down_location
;
5051 /* Information about the most recent up-going button event: Which
5052 button, what location, and what time. */
5054 static int last_mouse_button
;
5055 static int last_mouse_x
;
5056 static int last_mouse_y
;
5057 static unsigned long button_down_time
;
5059 /* The maximum time between clicks to make a double-click, or Qnil to
5060 disable double-click detection, or Qt for no time limit. */
5062 Lisp_Object Vdouble_click_time
;
5064 /* Maximum number of pixels the mouse may be moved between clicks
5065 to make a double-click. */
5067 EMACS_INT double_click_fuzz
;
5069 /* The number of clicks in this multiple-click. */
5071 int double_click_count
;
5073 /* Return position of a mouse click or wheel event */
5076 make_lispy_position (f
, x
, y
, time
)
5082 enum window_part part
;
5083 Lisp_Object posn
= Qnil
;
5084 Lisp_Object extra_info
= Qnil
;
5087 /* Set `window' to the window under frame pixel coordinates (x,y) */
5089 window
= window_from_coordinates (f
, XINT (*x
), XINT (*y
),
5090 &part
, &wx
, &wy
, 0);
5094 if (WINDOWP (window
))
5096 /* It's a click in window window at frame coordinates (x,y) */
5097 struct window
*w
= XWINDOW (window
);
5098 Lisp_Object string_info
= Qnil
;
5099 int textpos
= -1, rx
= -1, ry
= -1;
5100 int dx
= -1, dy
= -1;
5101 int width
= -1, height
= -1;
5102 Lisp_Object object
= Qnil
;
5104 /* Set event coordinates to window-relative coordinates
5105 for constructing the Lisp event below. */
5109 if (part
== ON_TEXT
)
5111 wx
+= WINDOW_LEFT_MARGIN_WIDTH (w
);
5113 else if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
)
5115 /* Mode line or header line. Look for a string under
5116 the mouse that may have a `local-map' property. */
5120 posn
= part
== ON_MODE_LINE
? Qmode_line
: Qheader_line
;
5122 string
= mode_line_string (w
, part
, &rx
, &ry
, &charpos
,
5123 &object
, &dx
, &dy
, &width
, &height
);
5124 if (STRINGP (string
))
5125 string_info
= Fcons (string
, make_number (charpos
));
5126 if (w
== XWINDOW (selected_window
))
5129 textpos
= XMARKER (w
->pointm
)->charpos
;
5131 else if (part
== ON_VERTICAL_BORDER
)
5133 posn
= Qvertical_line
;
5138 else if (part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
5143 posn
= (part
== ON_LEFT_MARGIN
) ? Qleft_margin
: Qright_margin
;
5145 string
= marginal_area_string (w
, part
, &rx
, &ry
, &charpos
,
5146 &object
, &dx
, &dy
, &width
, &height
);
5147 if (STRINGP (string
))
5148 string_info
= Fcons (string
, make_number (charpos
));
5149 if (part
== ON_LEFT_MARGIN
)
5152 wx
= window_box_right_offset (w
, TEXT_AREA
) - 1;
5154 else if (part
== ON_LEFT_FRINGE
)
5156 posn
= Qleft_fringe
;
5159 wx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5161 : window_box_width (w
, LEFT_MARGIN_AREA
));
5164 else if (part
== ON_RIGHT_FRINGE
)
5166 posn
= Qright_fringe
;
5169 wx
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5170 + window_box_width (w
, TEXT_AREA
)
5171 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5172 ? window_box_width (w
, RIGHT_MARGIN_AREA
)
5178 /* Note: We have no special posn for part == ON_SCROLL_BAR. */
5179 wx
= max (WINDOW_LEFT_MARGIN_WIDTH (w
), wx
);
5184 Lisp_Object string2
, object2
= Qnil
;
5185 struct display_pos p
;
5187 int width2
, height2
;
5188 string2
= buffer_posn_from_coords (w
, &wx
, &wy
, &p
,
5189 &object2
, &dx2
, &dy2
,
5191 textpos
= CHARPOS (p
.pos
);
5192 if (rx
< 0) rx
= wx
;
5193 if (ry
< 0) ry
= wy
;
5194 if (dx
< 0) dx
= dx2
;
5195 if (dy
< 0) dy
= dy2
;
5196 if (width
< 0) width
= width2
;
5197 if (height
< 0) height
= height2
;
5201 posn
= make_number (textpos
);
5202 if (STRINGP (string2
))
5203 string_info
= Fcons (string2
,
5204 make_number (CHARPOS (p
.string_pos
)));
5210 #ifdef HAVE_WINDOW_SYSTEM
5211 if (IMAGEP (object
))
5213 Lisp_Object image_map
, hotspot
;
5214 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
5216 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
5218 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
5219 posn
= XCAR (hotspot
);
5224 extra_info
= Fcons (object
,
5225 Fcons (Fcons (make_number (dx
),
5227 Fcons (Fcons (make_number (width
),
5228 make_number (height
)),
5232 extra_info
= Fcons (string_info
,
5233 Fcons (make_number (textpos
),
5234 Fcons (Fcons (make_number (rx
),
5240 XSETFRAME (window
, f
);
5245 XSETFASTINT (*x
, 0);
5246 XSETFASTINT (*y
, 0);
5249 return Fcons (window
,
5251 Fcons (Fcons (*x
, *y
),
5252 Fcons (make_number (time
),
5256 /* Given a struct input_event, build the lisp event which represents
5257 it. If EVENT is 0, build a mouse movement event from the mouse
5258 movement buffer, which should have a movement event in it.
5260 Note that events must be passed to this function in the order they
5261 are received; this function stores the location of button presses
5262 in order to build drag events when the button is released. */
5265 make_lispy_event (event
)
5266 struct input_event
*event
;
5270 switch (SWITCH_ENUM_CAST (event
->kind
))
5272 /* A simple keystroke. */
5273 case ASCII_KEYSTROKE_EVENT
:
5275 Lisp_Object lispy_c
;
5276 int c
= event
->code
& 0377;
5277 /* Turn ASCII characters into control characters
5279 if (event
->modifiers
& ctrl_modifier
)
5280 c
= make_ctrl_char (c
);
5282 /* Add in the other modifier bits. We took care of ctrl_modifier
5283 just above, and the shift key was taken care of by the X code,
5284 and applied to control characters by make_ctrl_char. */
5285 c
|= (event
->modifiers
5286 & (meta_modifier
| alt_modifier
5287 | hyper_modifier
| super_modifier
));
5288 /* Distinguish Shift-SPC from SPC. */
5289 if ((event
->code
& 0377) == 040
5290 && event
->modifiers
& shift_modifier
)
5291 c
|= shift_modifier
;
5292 button_down_time
= 0;
5293 XSETFASTINT (lispy_c
, c
);
5297 case MULTIBYTE_CHAR_KEYSTROKE_EVENT
:
5299 Lisp_Object lispy_c
;
5300 int c
= event
->code
;
5302 /* Add in the other modifier bits. We took care of ctrl_modifier
5303 just above, and the shift key was taken care of by the X code,
5304 and applied to control characters by make_ctrl_char. */
5305 c
|= (event
->modifiers
5306 & (meta_modifier
| alt_modifier
5307 | hyper_modifier
| super_modifier
| ctrl_modifier
));
5308 /* What about the `shift' modifier ? */
5309 button_down_time
= 0;
5310 XSETFASTINT (lispy_c
, c
);
5314 /* A function key. The symbol may need to have modifier prefixes
5316 case NON_ASCII_KEYSTROKE_EVENT
:
5317 button_down_time
= 0;
5319 for (i
= 0; i
< sizeof (lispy_accent_codes
) / sizeof (int); i
++)
5320 if (event
->code
== lispy_accent_codes
[i
])
5321 return modify_event_symbol (i
,
5323 Qfunction_key
, Qnil
,
5324 lispy_accent_keys
, &accent_key_syms
,
5325 (sizeof (lispy_accent_keys
)
5326 / sizeof (lispy_accent_keys
[0])));
5330 if (event
->code
>= 0x400 && event
->code
< 0x500)
5331 return modify_event_symbol (event
->code
- 0x400,
5332 event
->modifiers
& ~shift_modifier
,
5333 Qfunction_key
, Qnil
,
5334 lispy_kana_keys
, &func_key_syms
,
5335 (sizeof (lispy_kana_keys
)
5336 / sizeof (lispy_kana_keys
[0])));
5337 #endif /* XK_kana_A */
5340 #ifdef ISO_FUNCTION_KEY_OFFSET
5341 if (event
->code
< FUNCTION_KEY_OFFSET
5342 && event
->code
>= ISO_FUNCTION_KEY_OFFSET
)
5343 return modify_event_symbol (event
->code
- ISO_FUNCTION_KEY_OFFSET
,
5345 Qfunction_key
, Qnil
,
5346 iso_lispy_function_keys
, &func_key_syms
,
5347 (sizeof (iso_lispy_function_keys
)
5348 / sizeof (iso_lispy_function_keys
[0])));
5351 /* Handle system-specific or unknown keysyms. */
5352 if (event
->code
& (1 << 28)
5353 || event
->code
- FUNCTION_KEY_OFFSET
< 0
5354 || (event
->code
- FUNCTION_KEY_OFFSET
5355 >= sizeof lispy_function_keys
/ sizeof *lispy_function_keys
)
5356 || !lispy_function_keys
[event
->code
- FUNCTION_KEY_OFFSET
])
5358 /* We need to use an alist rather than a vector as the cache
5359 since we can't make a vector long enuf. */
5360 if (NILP (current_kboard
->system_key_syms
))
5361 current_kboard
->system_key_syms
= Fcons (Qnil
, Qnil
);
5362 return modify_event_symbol (event
->code
,
5365 current_kboard
->Vsystem_key_alist
,
5366 0, ¤t_kboard
->system_key_syms
,
5370 return modify_event_symbol (event
->code
- FUNCTION_KEY_OFFSET
,
5372 Qfunction_key
, Qnil
,
5373 lispy_function_keys
, &func_key_syms
,
5374 (sizeof (lispy_function_keys
)
5375 / sizeof (lispy_function_keys
[0])));
5378 /* A mouse click. Figure out where it is, decide whether it's
5379 a press, click or drag, and build the appropriate structure. */
5380 case MOUSE_CLICK_EVENT
:
5381 #ifndef USE_TOOLKIT_SCROLL_BARS
5382 case SCROLL_BAR_CLICK_EVENT
:
5385 int button
= event
->code
;
5387 Lisp_Object position
;
5388 Lisp_Object
*start_pos_ptr
;
5389 Lisp_Object start_pos
;
5393 /* Build the position as appropriate for this mouse click. */
5394 if (event
->kind
== MOUSE_CLICK_EVENT
)
5396 struct frame
*f
= XFRAME (event
->frame_or_window
);
5397 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
5401 /* Ignore mouse events that were made on frame that
5402 have been deleted. */
5403 if (! FRAME_LIVE_P (f
))
5406 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
5407 /* EVENT->x and EVENT->y are frame-relative pixel
5408 coordinates at this place. Under old redisplay, COLUMN
5409 and ROW are set to frame relative glyph coordinates
5410 which are then used to determine whether this click is
5411 in a menu (non-toolkit version). */
5412 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
5413 &column
, &row
, NULL
, 1);
5415 /* In the non-toolkit version, clicks on the menu bar
5416 are ordinary button events in the event buffer.
5417 Distinguish them, and invoke the menu.
5419 (In the toolkit version, the toolkit handles the menu bar
5420 and Emacs doesn't know about it until after the user
5421 makes a selection.) */
5422 if (row
>= 0 && row
< FRAME_MENU_BAR_LINES (f
)
5423 && (event
->modifiers
& down_modifier
))
5425 Lisp_Object items
, item
;
5430 /* Activate the menu bar on the down event. If the
5431 up event comes in before the menu code can deal with it,
5433 if (! (event
->modifiers
& down_modifier
))
5437 /* Find the menu bar item under `column'. */
5439 items
= FRAME_MENU_BAR_ITEMS (f
);
5440 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
5442 Lisp_Object pos
, string
;
5443 string
= AREF (items
, i
+ 1);
5444 pos
= AREF (items
, i
+ 3);
5447 if (column
>= XINT (pos
)
5448 && column
< XINT (pos
) + SCHARS (string
))
5450 item
= AREF (items
, i
);
5455 /* ELisp manual 2.4b says (x y) are window relative but
5456 code says they are frame-relative. */
5458 = Fcons (event
->frame_or_window
,
5460 Fcons (Fcons (event
->x
, event
->y
),
5461 Fcons (make_number (event
->timestamp
),
5464 return Fcons (item
, Fcons (position
, Qnil
));
5466 #endif /* not USE_X_TOOLKIT && not USE_GTK */
5468 position
= make_lispy_position (f
, &event
->x
, &event
->y
,
5471 #ifndef USE_TOOLKIT_SCROLL_BARS
5474 /* It's a scrollbar click. */
5476 Lisp_Object portion_whole
;
5479 window
= event
->frame_or_window
;
5480 portion_whole
= Fcons (event
->x
, event
->y
);
5481 part
= *scroll_bar_parts
[(int) event
->part
];
5485 Fcons (Qvertical_scroll_bar
,
5486 Fcons (portion_whole
,
5487 Fcons (make_number (event
->timestamp
),
5488 Fcons (part
, Qnil
)))));
5490 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5492 if (button
>= ASIZE (button_down_location
))
5494 button_down_location
= larger_vector (button_down_location
,
5496 mouse_syms
= larger_vector (mouse_syms
, button
+ 1, Qnil
);
5499 start_pos_ptr
= &AREF (button_down_location
, button
);
5500 start_pos
= *start_pos_ptr
;
5501 *start_pos_ptr
= Qnil
;
5504 /* On window-system frames, use the value of
5505 double-click-fuzz as is. On other frames, interpret it
5506 as a multiple of 1/8 characters. */
5510 if (WINDOWP (event
->frame_or_window
))
5511 f
= XFRAME (XWINDOW (event
->frame_or_window
)->frame
);
5512 else if (FRAMEP (event
->frame_or_window
))
5513 f
= XFRAME (event
->frame_or_window
);
5517 if (FRAME_WINDOW_P (f
))
5518 fuzz
= double_click_fuzz
;
5520 fuzz
= double_click_fuzz
/ 8;
5522 is_double
= (button
== last_mouse_button
5523 && (abs (XINT (event
->x
) - last_mouse_x
) <= fuzz
)
5524 && (abs (XINT (event
->y
) - last_mouse_y
) <= fuzz
)
5525 && button_down_time
!= 0
5526 && (EQ (Vdouble_click_time
, Qt
)
5527 || (INTEGERP (Vdouble_click_time
)
5528 && ((int)(event
->timestamp
- button_down_time
)
5529 < XINT (Vdouble_click_time
)))));
5532 last_mouse_button
= button
;
5533 last_mouse_x
= XINT (event
->x
);
5534 last_mouse_y
= XINT (event
->y
);
5536 /* If this is a button press, squirrel away the location, so
5537 we can decide later whether it was a click or a drag. */
5538 if (event
->modifiers
& down_modifier
)
5542 double_click_count
++;
5543 event
->modifiers
|= ((double_click_count
> 2)
5548 double_click_count
= 1;
5549 button_down_time
= event
->timestamp
;
5550 *start_pos_ptr
= Fcopy_alist (position
);
5553 /* Now we're releasing a button - check the co-ordinates to
5554 see if this was a click or a drag. */
5555 else if (event
->modifiers
& up_modifier
)
5557 /* If we did not see a down before this up, ignore the up.
5558 Probably this happened because the down event chose a
5559 menu item. It would be an annoyance to treat the
5560 release of the button that chose the menu item as a
5563 if (!CONSP (start_pos
))
5566 event
->modifiers
&= ~up_modifier
;
5567 #if 0 /* Formerly we treated an up with no down as a click event. */
5568 if (!CONSP (start_pos
))
5569 event
->modifiers
|= click_modifier
;
5574 EMACS_INT xdiff
= double_click_fuzz
, ydiff
= double_click_fuzz
;
5576 /* The third element of every position
5577 should be the (x,y) pair. */
5578 down
= Fcar (Fcdr (Fcdr (start_pos
)));
5580 && INTEGERP (XCAR (down
)) && INTEGERP (XCDR (down
)))
5582 xdiff
= XINT (event
->x
) - XINT (XCAR (down
));
5583 ydiff
= XINT (event
->y
) - XINT (XCDR (down
));
5586 if (xdiff
< double_click_fuzz
&& xdiff
> - double_click_fuzz
5587 && ydiff
< double_click_fuzz
&& ydiff
> - double_click_fuzz
5588 /* Maybe the mouse has moved a lot, caused scrolling, and
5589 eventually ended up at the same screen position (but
5590 not buffer position) in which case it is a drag, not
5592 /* FIXME: OTOH if the buffer position has changed
5593 because of a timer or process filter rather than
5594 because of mouse movement, it should be considered as
5595 a click. But mouse-drag-region completely ignores
5596 this case and it hasn't caused any real problem, so
5597 it's probably OK to ignore it as well. */
5598 && EQ (Fcar (Fcdr (start_pos
)), Fcar (Fcdr (position
))))
5599 /* Mouse hasn't moved (much). */
5600 event
->modifiers
|= click_modifier
;
5603 button_down_time
= 0;
5604 event
->modifiers
|= drag_modifier
;
5607 /* Don't check is_double; treat this as multiple
5608 if the down-event was multiple. */
5609 if (double_click_count
> 1)
5610 event
->modifiers
|= ((double_click_count
> 2)
5616 /* Every mouse event should either have the down_modifier or
5617 the up_modifier set. */
5621 /* Get the symbol we should use for the mouse click. */
5624 head
= modify_event_symbol (button
,
5626 Qmouse_click
, Vlispy_mouse_stem
,
5629 XVECTOR (mouse_syms
)->size
);
5630 if (event
->modifiers
& drag_modifier
)
5635 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
5638 Fcons (make_number (double_click_count
),
5649 Lisp_Object position
;
5652 /* Build the position as appropriate for this mouse click. */
5653 struct frame
*f
= XFRAME (event
->frame_or_window
);
5655 /* Ignore wheel events that were made on frame that have been
5657 if (! FRAME_LIVE_P (f
))
5660 position
= make_lispy_position (f
, &event
->x
, &event
->y
,
5663 /* Set double or triple modifiers to indicate the wheel speed. */
5665 /* On window-system frames, use the value of
5666 double-click-fuzz as is. On other frames, interpret it
5667 as a multiple of 1/8 characters. */
5672 if (WINDOWP (event
->frame_or_window
))
5673 f
= XFRAME (XWINDOW (event
->frame_or_window
)->frame
);
5674 else if (FRAMEP (event
->frame_or_window
))
5675 f
= XFRAME (event
->frame_or_window
);
5679 if (FRAME_WINDOW_P (f
))
5680 fuzz
= double_click_fuzz
;
5682 fuzz
= double_click_fuzz
/ 8;
5684 is_double
= (last_mouse_button
< 0
5685 && (abs (XINT (event
->x
) - last_mouse_x
) <= fuzz
)
5686 && (abs (XINT (event
->y
) - last_mouse_y
) <= fuzz
)
5687 && button_down_time
!= 0
5688 && (EQ (Vdouble_click_time
, Qt
)
5689 || (INTEGERP (Vdouble_click_time
)
5690 && ((int)(event
->timestamp
- button_down_time
)
5691 < XINT (Vdouble_click_time
)))));
5694 double_click_count
++;
5695 event
->modifiers
|= ((double_click_count
> 2)
5701 double_click_count
= 1;
5702 event
->modifiers
|= click_modifier
;
5705 button_down_time
= event
->timestamp
;
5706 /* Use a negative value to distinguish wheel from mouse button. */
5707 last_mouse_button
= -1;
5708 last_mouse_x
= XINT (event
->x
);
5709 last_mouse_y
= XINT (event
->y
);
5715 if (event
->modifiers
& up_modifier
)
5717 /* Emit a wheel-up event. */
5718 event
->modifiers
&= ~up_modifier
;
5721 else if (event
->modifiers
& down_modifier
)
5723 /* Emit a wheel-down event. */
5724 event
->modifiers
&= ~down_modifier
;
5728 /* Every wheel event should either have the down_modifier or
5729 the up_modifier set. */
5732 /* Get the symbol we should use for the wheel event. */
5733 head
= modify_event_symbol (symbol_num
,
5739 ASIZE (wheel_syms
));
5742 if (event
->modifiers
& (double_modifier
| triple_modifier
))
5745 Fcons (make_number (double_click_count
),
5754 #ifdef USE_TOOLKIT_SCROLL_BARS
5756 /* We don't have down and up events if using toolkit scroll bars,
5757 so make this always a click event. Store in the `part' of
5758 the Lisp event a symbol which maps to the following actions:
5760 `above_handle' page up
5761 `below_handle' page down
5765 `bottom' bottom of buffer
5766 `handle' thumb has been dragged.
5767 `end-scroll' end of interaction with scroll bar
5769 The incoming input_event contains in its `part' member an
5770 index of type `enum scroll_bar_part' which we can use as an
5771 index in scroll_bar_parts to get the appropriate symbol. */
5773 case SCROLL_BAR_CLICK_EVENT
:
5775 Lisp_Object position
, head
, window
, portion_whole
, part
;
5777 window
= event
->frame_or_window
;
5778 portion_whole
= Fcons (event
->x
, event
->y
);
5779 part
= *scroll_bar_parts
[(int) event
->part
];
5783 Fcons (Qvertical_scroll_bar
,
5784 Fcons (portion_whole
,
5785 Fcons (make_number (event
->timestamp
),
5786 Fcons (part
, Qnil
)))));
5788 /* Always treat scroll bar events as clicks. */
5789 event
->modifiers
|= click_modifier
;
5790 event
->modifiers
&= ~up_modifier
;
5792 if (event
->code
>= ASIZE (mouse_syms
))
5793 mouse_syms
= larger_vector (mouse_syms
, event
->code
+ 1, Qnil
);
5795 /* Get the symbol we should use for the mouse click. */
5796 head
= modify_event_symbol (event
->code
,
5801 XVECTOR (mouse_syms
)->size
);
5802 return Fcons (head
, Fcons (position
, Qnil
));
5805 #endif /* USE_TOOLKIT_SCROLL_BARS */
5808 case W32_SCROLL_BAR_CLICK_EVENT
:
5810 int button
= event
->code
;
5812 Lisp_Object position
;
5813 Lisp_Object
*start_pos_ptr
;
5814 Lisp_Object start_pos
;
5818 Lisp_Object portion_whole
;
5821 window
= event
->frame_or_window
;
5822 portion_whole
= Fcons (event
->x
, event
->y
);
5823 part
= *scroll_bar_parts
[(int) event
->part
];
5827 Fcons (Qvertical_scroll_bar
,
5828 Fcons (portion_whole
,
5829 Fcons (make_number (event
->timestamp
),
5830 Fcons (part
, Qnil
)))));
5833 /* Always treat W32 scroll bar events as clicks. */
5834 event
->modifiers
|= click_modifier
;
5837 /* Get the symbol we should use for the mouse click. */
5840 head
= modify_event_symbol (button
,
5845 XVECTOR (mouse_syms
)->size
);
5851 #endif /* WINDOWSNT */
5853 case DRAG_N_DROP_EVENT
:
5856 Lisp_Object head
, position
;
5859 /* The frame_or_window field should be a cons of the frame in
5860 which the event occurred and a list of the filenames
5862 if (! CONSP (event
->frame_or_window
))
5865 f
= XFRAME (XCAR (event
->frame_or_window
));
5866 files
= XCDR (event
->frame_or_window
);
5868 /* Ignore mouse events that were made on frames that
5869 have been deleted. */
5870 if (! FRAME_LIVE_P (f
))
5873 position
= make_lispy_position (f
, &event
->x
, &event
->y
,
5876 head
= modify_event_symbol (0, event
->modifiers
,
5878 lispy_drag_n_drop_names
,
5879 &drag_n_drop_syms
, 1);
5885 #endif /* HAVE_MOUSE */
5887 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
5888 || defined (USE_GTK)
5889 case MENU_BAR_EVENT
:
5890 if (EQ (event
->arg
, event
->frame_or_window
))
5891 /* This is the prefix key. We translate this to
5892 `(menu_bar)' because the code in keyboard.c for menu
5893 events, which we use, relies on this. */
5894 return Fcons (Qmenu_bar
, Qnil
);
5898 case SELECT_WINDOW_EVENT
:
5899 /* Make an event (select-window (WINDOW)). */
5900 return Fcons (Qselect_window
,
5901 Fcons (Fcons (event
->frame_or_window
, Qnil
),
5904 case TOOL_BAR_EVENT
:
5905 if (EQ (event
->arg
, event
->frame_or_window
))
5906 /* This is the prefix key. We translate this to
5907 `(tool_bar)' because the code in keyboard.c for tool bar
5908 events, which we use, relies on this. */
5909 return Fcons (Qtool_bar
, Qnil
);
5910 else if (SYMBOLP (event
->arg
))
5911 return apply_modifiers (event
->modifiers
, event
->arg
);
5914 case USER_SIGNAL_EVENT
:
5915 /* A user signal. */
5916 return *lispy_user_signals
[event
->code
];
5918 case SAVE_SESSION_EVENT
:
5919 return Qsave_session
;
5922 case MAC_APPLE_EVENT
:
5924 Lisp_Object spec
[2];
5928 return Fcons (Qmac_apple_event
,
5929 Fcons (Fvector (2, spec
),
5930 Fcons (mac_make_lispy_event_code (event
->code
),
5935 /* The 'kind' field of the event is something we don't recognize. */
5944 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
5946 Lisp_Object bar_window
;
5947 enum scroll_bar_part part
;
5951 /* Is it a scroll bar movement? */
5952 if (frame
&& ! NILP (bar_window
))
5954 Lisp_Object part_sym
;
5956 part_sym
= *scroll_bar_parts
[(int) part
];
5957 return Fcons (Qscroll_bar_movement
,
5958 (Fcons (Fcons (bar_window
,
5959 Fcons (Qvertical_scroll_bar
,
5960 Fcons (Fcons (x
, y
),
5961 Fcons (make_number (time
),
5967 /* Or is it an ordinary mouse movement? */
5970 Lisp_Object position
;
5972 position
= make_lispy_position (frame
, &x
, &y
, time
);
5974 return Fcons (Qmouse_movement
,
5980 #endif /* HAVE_MOUSE */
5982 /* Construct a switch frame event. */
5984 make_lispy_switch_frame (frame
)
5987 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
5990 /* Manipulating modifiers. */
5992 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
5994 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
5995 SYMBOL's name of the end of the modifiers; the string from this
5996 position is the unmodified symbol name.
5998 This doesn't use any caches. */
6001 parse_modifiers_uncached (symbol
, modifier_end
)
6009 CHECK_SYMBOL (symbol
);
6012 name
= SYMBOL_NAME (symbol
);
6014 for (i
= 0; i
+2 <= SBYTES (name
); )
6016 int this_mod_end
= 0;
6019 /* See if the name continues with a modifier word.
6020 Check that the word appears, but don't check what follows it.
6021 Set this_mod and this_mod_end to record what we find. */
6023 switch (SREF (name
, i
))
6025 #define SINGLE_LETTER_MOD(BIT) \
6026 (this_mod_end = i + 1, this_mod = BIT)
6029 SINGLE_LETTER_MOD (alt_modifier
);
6033 SINGLE_LETTER_MOD (ctrl_modifier
);
6037 SINGLE_LETTER_MOD (hyper_modifier
);
6041 SINGLE_LETTER_MOD (meta_modifier
);
6045 SINGLE_LETTER_MOD (shift_modifier
);
6049 SINGLE_LETTER_MOD (super_modifier
);
6052 #undef SINGLE_LETTER_MOD
6054 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
6055 if (i + LEN + 1 <= SBYTES (name) \
6056 && ! strncmp (SDATA (name) + i, NAME, LEN)) \
6058 this_mod_end = i + LEN; \
6063 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
6064 MULTI_LETTER_MOD (down_modifier
, "down", 4);
6065 MULTI_LETTER_MOD (double_modifier
, "double", 6);
6069 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
6071 #undef MULTI_LETTER_MOD
6075 /* If we found no modifier, stop looking for them. */
6076 if (this_mod_end
== 0)
6079 /* Check there is a dash after the modifier, so that it
6080 really is a modifier. */
6081 if (this_mod_end
>= SBYTES (name
)
6082 || SREF (name
, this_mod_end
) != '-')
6085 /* This modifier is real; look for another. */
6086 modifiers
|= this_mod
;
6087 i
= this_mod_end
+ 1;
6090 /* Should we include the `click' modifier? */
6091 if (! (modifiers
& (down_modifier
| drag_modifier
6092 | double_modifier
| triple_modifier
))
6093 && i
+ 7 == SBYTES (name
)
6094 && strncmp (SDATA (name
) + i
, "mouse-", 6) == 0
6095 && ('0' <= SREF (name
, i
+ 6) && SREF (name
, i
+ 6) <= '9'))
6096 modifiers
|= click_modifier
;
6104 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
6105 prepended to the string BASE[0..BASE_LEN-1].
6106 This doesn't use any caches. */
6108 apply_modifiers_uncached (modifiers
, base
, base_len
, base_len_byte
)
6111 int base_len
, base_len_byte
;
6113 /* Since BASE could contain nulls, we can't use intern here; we have
6114 to use Fintern, which expects a genuine Lisp_String, and keeps a
6117 = (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
6123 /* Only the event queue may use the `up' modifier; it should always
6124 be turned into a click or drag event before presented to lisp code. */
6125 if (modifiers
& up_modifier
)
6128 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
6129 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
6130 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
6131 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
6132 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
6133 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
6134 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
6135 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
6136 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
6137 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
6138 /* The click modifier is denoted by the absence of other modifiers. */
6142 mod_len
= p
- new_mods
;
6146 Lisp_Object new_name
;
6148 new_name
= make_uninit_multibyte_string (mod_len
+ base_len
,
6149 mod_len
+ base_len_byte
);
6150 bcopy (new_mods
, SDATA (new_name
), mod_len
);
6151 bcopy (base
, SDATA (new_name
) + mod_len
, base_len_byte
);
6153 return Fintern (new_name
, Qnil
);
6158 static char *modifier_names
[] =
6160 "up", "down", "drag", "click", "double", "triple", 0, 0,
6161 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6162 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
6164 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
6166 static Lisp_Object modifier_symbols
;
6168 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
6170 lispy_modifier_list (modifiers
)
6173 Lisp_Object modifier_list
;
6176 modifier_list
= Qnil
;
6177 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
6178 if (modifiers
& (1<<i
))
6179 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
6182 return modifier_list
;
6186 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
6187 where UNMODIFIED is the unmodified form of SYMBOL,
6188 MASK is the set of modifiers present in SYMBOL's name.
6189 This is similar to parse_modifiers_uncached, but uses the cache in
6190 SYMBOL's Qevent_symbol_element_mask property, and maintains the
6191 Qevent_symbol_elements property. */
6194 parse_modifiers (symbol
)
6197 Lisp_Object elements
;
6199 elements
= Fget (symbol
, Qevent_symbol_element_mask
);
6200 if (CONSP (elements
))
6205 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
6206 Lisp_Object unmodified
;
6209 unmodified
= Fintern (make_string (SDATA (SYMBOL_NAME (symbol
)) + end
,
6210 SBYTES (SYMBOL_NAME (symbol
)) - end
),
6213 if (modifiers
& ~INTMASK
)
6215 XSETFASTINT (mask
, modifiers
);
6216 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
6218 /* Cache the parsing results on SYMBOL. */
6219 Fput (symbol
, Qevent_symbol_element_mask
,
6221 Fput (symbol
, Qevent_symbol_elements
,
6222 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
6224 /* Since we know that SYMBOL is modifiers applied to unmodified,
6225 it would be nice to put that in unmodified's cache.
6226 But we can't, since we're not sure that parse_modifiers is
6233 /* Apply the modifiers MODIFIERS to the symbol BASE.
6234 BASE must be unmodified.
6236 This is like apply_modifiers_uncached, but uses BASE's
6237 Qmodifier_cache property, if present. It also builds
6238 Qevent_symbol_elements properties, since it has that info anyway.
6240 apply_modifiers copies the value of BASE's Qevent_kind property to
6241 the modified symbol. */
6243 apply_modifiers (modifiers
, base
)
6247 Lisp_Object cache
, index
, entry
, new_symbol
;
6249 /* Mask out upper bits. We don't know where this value's been. */
6250 modifiers
&= INTMASK
;
6252 /* The click modifier never figures into cache indices. */
6253 cache
= Fget (base
, Qmodifier_cache
);
6254 XSETFASTINT (index
, (modifiers
& ~click_modifier
));
6255 entry
= assq_no_quit (index
, cache
);
6258 new_symbol
= XCDR (entry
);
6261 /* We have to create the symbol ourselves. */
6262 new_symbol
= apply_modifiers_uncached (modifiers
,
6263 SDATA (SYMBOL_NAME (base
)),
6264 SCHARS (SYMBOL_NAME (base
)),
6265 SBYTES (SYMBOL_NAME (base
)));
6267 /* Add the new symbol to the base's cache. */
6268 entry
= Fcons (index
, new_symbol
);
6269 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
6271 /* We have the parsing info now for free, so we could add it to
6273 XSETFASTINT (index, modifiers);
6274 Fput (new_symbol, Qevent_symbol_element_mask,
6275 Fcons (base, Fcons (index, Qnil)));
6276 Fput (new_symbol, Qevent_symbol_elements,
6277 Fcons (base, lispy_modifier_list (modifiers)));
6278 Sadly, this is only correct if `base' is indeed a base event,
6279 which is not necessarily the case. -stef */
6282 /* Make sure this symbol is of the same kind as BASE.
6284 You'd think we could just set this once and for all when we
6285 intern the symbol above, but reorder_modifiers may call us when
6286 BASE's property isn't set right; we can't assume that just
6287 because it has a Qmodifier_cache property it must have its
6288 Qevent_kind set right as well. */
6289 if (NILP (Fget (new_symbol
, Qevent_kind
)))
6293 kind
= Fget (base
, Qevent_kind
);
6295 Fput (new_symbol
, Qevent_kind
, kind
);
6302 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
6303 return a symbol with the modifiers placed in the canonical order.
6304 Canonical order is alphabetical, except for down and drag, which
6305 always come last. The 'click' modifier is never written out.
6307 Fdefine_key calls this to make sure that (for example) C-M-foo
6308 and M-C-foo end up being equivalent in the keymap. */
6311 reorder_modifiers (symbol
)
6314 /* It's hopefully okay to write the code this way, since everything
6315 will soon be in caches, and no consing will be done at all. */
6318 parsed
= parse_modifiers (symbol
);
6319 return apply_modifiers ((int) XINT (XCAR (XCDR (parsed
))),
6324 /* For handling events, we often want to produce a symbol whose name
6325 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
6326 to some base, like the name of a function key or mouse button.
6327 modify_event_symbol produces symbols of this sort.
6329 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
6330 is the name of the i'th symbol. TABLE_SIZE is the number of elements
6333 Alternatively, NAME_ALIST_OR_STEM is either an alist mapping codes
6334 into symbol names, or a string specifying a name stem used to
6335 construct a symbol name or the form `STEM-N', where N is the decimal
6336 representation of SYMBOL_NUM. NAME_ALIST_OR_STEM is used if it is
6337 non-nil; otherwise NAME_TABLE is used.
6339 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
6340 persist between calls to modify_event_symbol that it can use to
6341 store a cache of the symbols it's generated for this NAME_TABLE
6342 before. The object stored there may be a vector or an alist.
6344 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
6346 MODIFIERS is a set of modifier bits (as given in struct input_events)
6347 whose prefixes should be applied to the symbol name.
6349 SYMBOL_KIND is the value to be placed in the event_kind property of
6350 the returned symbol.
6352 The symbols we create are supposed to have an
6353 `event-symbol-elements' property, which lists the modifiers present
6354 in the symbol's name. */
6357 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_alist_or_stem
,
6358 name_table
, symbol_table
, table_size
)
6361 Lisp_Object symbol_kind
;
6362 Lisp_Object name_alist_or_stem
;
6364 Lisp_Object
*symbol_table
;
6365 unsigned int table_size
;
6368 Lisp_Object symbol_int
;
6370 /* Get rid of the "vendor-specific" bit here. */
6371 XSETINT (symbol_int
, symbol_num
& 0xffffff);
6373 /* Is this a request for a valid symbol? */
6374 if (symbol_num
< 0 || symbol_num
>= table_size
)
6377 if (CONSP (*symbol_table
))
6378 value
= Fcdr (assq_no_quit (symbol_int
, *symbol_table
));
6380 /* If *symbol_table doesn't seem to be initialized properly, fix that.
6381 *symbol_table should be a lisp vector TABLE_SIZE elements long,
6382 where the Nth element is the symbol for NAME_TABLE[N], or nil if
6383 we've never used that symbol before. */
6386 if (! VECTORP (*symbol_table
)
6387 || XVECTOR (*symbol_table
)->size
!= table_size
)
6391 XSETFASTINT (size
, table_size
);
6392 *symbol_table
= Fmake_vector (size
, Qnil
);
6395 value
= XVECTOR (*symbol_table
)->contents
[symbol_num
];
6398 /* Have we already used this symbol before? */
6401 /* No; let's create it. */
6402 if (CONSP (name_alist_or_stem
))
6403 value
= Fcdr_safe (Fassq (symbol_int
, name_alist_or_stem
));
6404 else if (STRINGP (name_alist_or_stem
))
6406 int len
= SBYTES (name_alist_or_stem
);
6407 char *buf
= (char *) alloca (len
+ 50);
6408 sprintf (buf
, "%s-%ld", SDATA (name_alist_or_stem
),
6409 (long) XINT (symbol_int
) + 1);
6410 value
= intern (buf
);
6412 else if (name_table
!= 0 && name_table
[symbol_num
])
6413 value
= intern (name_table
[symbol_num
]);
6415 #ifdef HAVE_WINDOW_SYSTEM
6418 char *name
= x_get_keysym_name (symbol_num
);
6420 value
= intern (name
);
6427 sprintf (buf
, "key-%d", symbol_num
);
6428 value
= intern (buf
);
6431 if (CONSP (*symbol_table
))
6432 *symbol_table
= Fcons (Fcons (symbol_int
, value
), *symbol_table
);
6434 XVECTOR (*symbol_table
)->contents
[symbol_num
] = value
;
6436 /* Fill in the cache entries for this symbol; this also
6437 builds the Qevent_symbol_elements property, which the user
6439 apply_modifiers (modifiers
& click_modifier
, value
);
6440 Fput (value
, Qevent_kind
, symbol_kind
);
6443 /* Apply modifiers to that symbol. */
6444 return apply_modifiers (modifiers
, value
);
6447 /* Convert a list that represents an event type,
6448 such as (ctrl meta backspace), into the usual representation of that
6449 event type as a number or a symbol. */
6451 DEFUN ("event-convert-list", Fevent_convert_list
, Sevent_convert_list
, 1, 1, 0,
6452 doc
: /* Convert the event description list EVENT-DESC to an event type.
6453 EVENT-DESC should contain one base event type (a character or symbol)
6454 and zero or more modifier names (control, meta, hyper, super, shift, alt,
6455 drag, down, double or triple). The base must be last.
6456 The return value is an event type (a character or symbol) which
6457 has the same base event type and all the specified modifiers. */)
6459 Lisp_Object event_desc
;
6467 while (CONSP (rest
))
6475 /* Given a symbol, see if it is a modifier name. */
6476 if (SYMBOLP (elt
) && CONSP (rest
))
6477 this = parse_solitary_modifier (elt
);
6481 else if (!NILP (base
))
6482 error ("Two bases given in one event");
6488 /* Let the symbol A refer to the character A. */
6489 if (SYMBOLP (base
) && SCHARS (SYMBOL_NAME (base
)) == 1)
6490 XSETINT (base
, SREF (SYMBOL_NAME (base
), 0));
6492 if (INTEGERP (base
))
6494 /* Turn (shift a) into A. */
6495 if ((modifiers
& shift_modifier
) != 0
6496 && (XINT (base
) >= 'a' && XINT (base
) <= 'z'))
6498 XSETINT (base
, XINT (base
) - ('a' - 'A'));
6499 modifiers
&= ~shift_modifier
;
6502 /* Turn (control a) into C-a. */
6503 if (modifiers
& ctrl_modifier
)
6504 return make_number ((modifiers
& ~ctrl_modifier
)
6505 | make_ctrl_char (XINT (base
)));
6507 return make_number (modifiers
| XINT (base
));
6509 else if (SYMBOLP (base
))
6510 return apply_modifiers (modifiers
, base
);
6513 error ("Invalid base event");
6518 /* Try to recognize SYMBOL as a modifier name.
6519 Return the modifier flag bit, or 0 if not recognized. */
6522 parse_solitary_modifier (symbol
)
6525 Lisp_Object name
= SYMBOL_NAME (symbol
);
6527 switch (SREF (name
, 0))
6529 #define SINGLE_LETTER_MOD(BIT) \
6530 if (SBYTES (name) == 1) \
6533 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
6534 if (LEN == SBYTES (name) \
6535 && ! strncmp (SDATA (name), NAME, LEN)) \
6539 SINGLE_LETTER_MOD (alt_modifier
);
6543 MULTI_LETTER_MOD (alt_modifier
, "alt", 3);
6547 SINGLE_LETTER_MOD (ctrl_modifier
);
6551 MULTI_LETTER_MOD (ctrl_modifier
, "ctrl", 4);
6552 MULTI_LETTER_MOD (ctrl_modifier
, "control", 7);
6556 SINGLE_LETTER_MOD (hyper_modifier
);
6560 MULTI_LETTER_MOD (hyper_modifier
, "hyper", 5);
6564 SINGLE_LETTER_MOD (meta_modifier
);
6568 MULTI_LETTER_MOD (meta_modifier
, "meta", 4);
6572 SINGLE_LETTER_MOD (shift_modifier
);
6576 MULTI_LETTER_MOD (shift_modifier
, "shift", 5);
6577 MULTI_LETTER_MOD (super_modifier
, "super", 5);
6578 SINGLE_LETTER_MOD (super_modifier
);
6582 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
6583 MULTI_LETTER_MOD (down_modifier
, "down", 4);
6584 MULTI_LETTER_MOD (double_modifier
, "double", 6);
6588 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
6591 #undef SINGLE_LETTER_MOD
6592 #undef MULTI_LETTER_MOD
6598 /* Return 1 if EVENT is a list whose elements are all integers or symbols.
6599 Such a list is not valid as an event,
6600 but it can be a Lucid-style event type list. */
6603 lucid_event_type_list_p (object
)
6608 if (! CONSP (object
))
6611 if (EQ (XCAR (object
), Qhelp_echo
)
6612 || EQ (XCAR (object
), Qvertical_line
)
6613 || EQ (XCAR (object
), Qmode_line
)
6614 || EQ (XCAR (object
), Qheader_line
))
6617 for (tail
= object
; CONSP (tail
); tail
= XCDR (tail
))
6621 if (! (INTEGERP (elt
) || SYMBOLP (elt
)))
6628 /* Store into *addr a value nonzero if terminal input chars are available.
6629 Serves the purpose of ioctl (0, FIONREAD, addr)
6630 but works even if FIONREAD does not exist.
6631 (In fact, this may actually read some input.)
6633 If READABLE_EVENTS_DO_TIMERS_NOW is set in FLAGS, actually run
6634 timer events that are ripe.
6635 If READABLE_EVENTS_FILTER_EVENTS is set in FLAGS, ignore internal
6636 events (FOCUS_IN_EVENT).
6637 If READABLE_EVENTS_IGNORE_SQUEEZABLES is set in FLAGS, ignore mouse
6638 movements and toolkit scroll bar thumb drags. */
6641 get_input_pending (addr
, flags
)
6645 /* First of all, have we already counted some input? */
6646 *addr
= (!NILP (Vquit_flag
) || readable_events (flags
));
6648 /* If input is being read as it arrives, and we have none, there is none. */
6649 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
6652 /* Try to read some input and see how much we get. */
6654 *addr
= (!NILP (Vquit_flag
) || readable_events (flags
));
6657 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
6660 gobble_input (expected
)
6665 if (interrupt_input
)
6668 mask
= sigblock (sigmask (SIGIO
));
6669 read_avail_input (expected
);
6673 #ifdef POLL_FOR_INPUT
6674 /* XXX This condition was (read_socket_hook && !interrupt_input),
6675 but read_socket_hook is not global anymore. Let's pretend that
6677 if (!interrupt_input
&& poll_suppress_count
== 0)
6680 mask
= sigblock (sigmask (SIGALRM
));
6681 read_avail_input (expected
);
6687 read_avail_input (expected
);
6691 /* Put a BUFFER_SWITCH_EVENT in the buffer
6692 so that read_key_sequence will notice the new current buffer. */
6695 record_asynch_buffer_change ()
6697 struct input_event event
;
6701 event
.kind
= BUFFER_SWITCH_EVENT
;
6702 event
.frame_or_window
= Qnil
;
6706 /* We don't need a buffer-switch event unless Emacs is waiting for input.
6707 The purpose of the event is to make read_key_sequence look up the
6708 keymaps again. If we aren't in read_key_sequence, we don't need one,
6709 and the event could cause trouble by messing up (input-pending-p). */
6710 tem
= Fwaiting_for_user_input_p ();
6714 /* We never need these events if we have no asynchronous subprocesses. */
6718 /* Make sure no interrupt happens while storing the event. */
6720 if (interrupt_input
)
6723 mask
= sigblock (sigmask (SIGIO
));
6724 kbd_buffer_store_event (&event
);
6731 kbd_buffer_store_event (&event
);
6738 /* Read any terminal input already buffered up by the system
6739 into the kbd_buffer, but do not wait.
6741 EXPECTED should be nonzero if the caller knows there is some input.
6743 Except on VMS, all input is read by this function.
6744 If interrupt_input is nonzero, this function MUST be called
6745 only when SIGIO is blocked.
6747 Returns the number of keyboard chars read, or -1 meaning
6748 this is a bad time to try to read input. */
6751 read_avail_input (expected
)
6758 /* Loop through the available devices, and call their input hooks. */
6762 struct device
*next
= d
->next_device
;
6764 if (d
->read_socket_hook
)
6767 struct input_event hold_quit
;
6769 EVENT_INIT (hold_quit
);
6770 hold_quit
.kind
= NO_EVENT
;
6772 /* No need for FIONREAD or fcntl; just say don't wait. */
6773 while (nr
= (*d
->read_socket_hook
) (d
, expected
, &hold_quit
), nr
> 0)
6779 if (nr
== -1) /* Not OK to read input now. */
6783 else if (nr
== -2) /* Non-transient error. */
6785 /* The display device terminated; it should be closed. */
6787 /* Kill Emacs if this was our last display. */
6788 if (! device_list
->next_device
)
6789 /* Formerly simply reported no input, but that
6790 sometimes led to a failure of Emacs to terminate.
6791 SIGHUP seems appropriate if we can't reach the
6793 /* ??? Is it really right to send the signal just to
6794 this process rather than to the whole process
6795 group? Perhaps on systems with FIONREAD Emacs is
6796 alone in its group. */
6797 kill (getpid (), SIGHUP
);
6799 /* XXX Is calling delete_device safe here? It calls Fdelete_frame. */
6800 if (d
->delete_device_hook
)
6801 (*d
->delete_device_hook
) (d
);
6806 if (hold_quit
.kind
!= NO_EVENT
)
6807 kbd_buffer_store_event (&hold_quit
);
6819 /* This is the tty way of reading available input.
6821 Note that each terminal device has its own `struct device' object,
6822 and so this function is called once for each individual termcap
6823 display. The first parameter indicates which device to read from. */
6826 tty_read_avail_input (struct device
*device
,
6828 struct input_event
*hold_quit
)
6830 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
6831 the kbd_buffer can really hold. That may prevent loss
6832 of characters on some systems when input is stuffed at us. */
6833 unsigned char cbuf
[KBD_BUFFER_SIZE
- 1];
6835 struct tty_display_info
*tty
= device
->display_info
.tty
;
6838 if (device
->type
!= output_termcap
)
6841 /* XXX I think the following code should be moved to separate hook
6842 functions in system-dependent files. */
6845 #else /* not WINDOWSNT */
6847 n_to_read
= dos_keysns ();
6851 cbuf
[0] = dos_keyread ();
6854 #else /* not MSDOS */
6856 if (! tty
->term_initted
) /* In case we get called during bootstrap. */
6860 return 0; /* The terminal is suspended. */
6862 /* Determine how many characters we should *try* to read. */
6864 /* Find out how much input is available. */
6865 if (ioctl (fileno (tty
->input
), FIONREAD
, &n_to_read
) < 0)
6867 if (! noninteractive
)
6868 return -2; /* Close this device. */
6874 if (n_to_read
> sizeof cbuf
)
6875 n_to_read
= sizeof cbuf
;
6876 #else /* no FIONREAD */
6877 #if defined (USG) || defined (DGUX) || defined(CYGWIN)
6878 /* Read some input if available, but don't wait. */
6879 n_to_read
= sizeof cbuf
;
6880 fcntl (fileno (tty
->input
), F_SETFL
, O_NDELAY
);
6886 /* Now read; for one reason or another, this will not block.
6887 NREAD is set to the number of chars read. */
6890 nread
= emacs_read (fileno (tty
->input
), cbuf
, n_to_read
);
6891 /* POSIX infers that processes which are not in the session leader's
6892 process group won't get SIGHUP's at logout time. BSDI adheres to
6893 this part standard and returns -1 from read (0) with errno==EIO
6894 when the control tty is taken away.
6895 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
6896 if (nread
== -1 && errno
== EIO
)
6897 return -2; /* Close this device. */
6898 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
6899 /* The kernel sometimes fails to deliver SIGHUP for ptys.
6900 This looks incorrect, but it isn't, because _BSD causes
6901 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
6902 and that causes a value other than 0 when there is no input. */
6904 return -2; /* Close this device. */
6908 /* We used to retry the read if it was interrupted.
6909 But this does the wrong thing when O_NDELAY causes
6910 an EAGAIN error. Does anybody know of a situation
6911 where a retry is actually needed? */
6913 nread
< 0 && (errno
== EAGAIN
6927 #if defined (USG) || defined (DGUX) || defined (CYGWIN)
6928 fcntl (fileno (tty
->input
), F_SETFL
, 0);
6929 #endif /* USG or DGUX or CYGWIN */
6930 #endif /* no FIONREAD */
6935 #endif /* not MSDOS */
6936 #endif /* not WINDOWSNT */
6938 for (i
= 0; i
< nread
; i
++)
6940 struct input_event buf
;
6942 buf
.kind
= ASCII_KEYSTROKE_EVENT
;
6944 if (tty
->meta_key
== 1 && (cbuf
[i
] & 0x80))
6945 buf
.modifiers
= meta_modifier
;
6946 if (tty
->meta_key
!= 2)
6950 /* Set the frame corresponding to the active tty. Note that the
6951 value of selected_frame is not reliable here, redisplay tends
6952 to temporarily change it. */
6953 buf
.frame_or_window
= tty
->top_frame
;
6956 kbd_buffer_store_event (&buf
);
6957 /* Don't look at input that follows a C-g too closely.
6958 This reduces lossage due to autorepeat on C-g. */
6959 if (buf
.kind
== ASCII_KEYSTROKE_EVENT
6960 && buf
.code
== quit_char
)
6966 #endif /* not VMS */
6969 handle_async_input ()
6972 extern int select_alarmed
;
6975 interrupt_input_pending
= 0;
6980 nread
= read_avail_input (1);
6981 /* -1 means it's not ok to read the input now.
6982 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
6983 0 means there was no keyboard input available. */
6988 select_alarmed
= 1; /* Force the select emulator back to life */
6993 #ifdef SIGIO /* for entire page */
6994 /* Note SIGIO has been undef'd if FIONREAD is missing. */
6997 input_available_signal (signo
)
7000 /* Must preserve main program's value of errno. */
7001 int old_errno
= errno
;
7002 #if defined (USG) && !defined (POSIX_SIGNALS)
7003 /* USG systems forget handlers when they are used;
7004 must reestablish each time */
7005 signal (signo
, input_available_signal
);
7013 interrupt_input_pending
= 1;
7015 SIGNAL_THREAD_CHECK (signo
);
7018 if (input_available_clear_time
)
7019 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
7022 handle_async_input ();
7032 /* Send ourselves a SIGIO.
7034 This function exists so that the UNBLOCK_INPUT macro in
7035 blockinput.h can have some way to take care of input we put off
7036 dealing with, without assuming that every file which uses
7037 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
7039 reinvoke_input_signal ()
7042 handle_async_input ();
7048 static void menu_bar_item
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
, void*));
7049 static Lisp_Object menu_bar_one_keymap_changed_items
;
7051 /* These variables hold the vector under construction within
7052 menu_bar_items and its subroutines, and the current index
7053 for storing into that vector. */
7054 static Lisp_Object menu_bar_items_vector
;
7055 static int menu_bar_items_index
;
7057 /* Return a vector of menu items for a menu bar, appropriate
7058 to the current buffer. Each item has three elements in the vector:
7061 OLD is an old vector we can optionally reuse, or nil. */
7064 menu_bar_items (old
)
7067 /* The number of keymaps we're scanning right now, and the number of
7068 keymaps we have allocated space for. */
7071 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
7072 in the current keymaps, or nil where it is not a prefix. */
7075 Lisp_Object def
, tail
;
7084 /* In order to build the menus, we need to call the keymap
7085 accessors. They all call QUIT. But this function is called
7086 during redisplay, during which a quit is fatal. So inhibit
7087 quitting while building the menus.
7088 We do this instead of specbind because (1) errors will clear it anyway
7089 and (2) this avoids risk of specpdl overflow. */
7090 oquit
= Vinhibit_quit
;
7094 menu_bar_items_vector
= old
;
7096 menu_bar_items_vector
= Fmake_vector (make_number (24), Qnil
);
7097 menu_bar_items_index
= 0;
7099 /* Build our list of keymaps.
7100 If we recognize a function key and replace its escape sequence in
7101 keybuf with its symbol, or if the sequence starts with a mouse
7102 click and we need to switch buffers, we jump back here to rebuild
7103 the initial keymaps from the current buffer. */
7107 /* Should overriding-terminal-local-map and overriding-local-map apply? */
7108 if (!NILP (Voverriding_local_map_menu_flag
))
7110 /* Yes, use them (if non-nil) as well as the global map. */
7111 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
7113 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
7114 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
7115 if (!NILP (Voverriding_local_map
))
7116 maps
[nmaps
++] = Voverriding_local_map
;
7120 /* No, so use major and minor mode keymaps and keymap property.
7121 Note that menu-bar bindings in the local-map and keymap
7122 properties may not work reliable, as they are only
7123 recognized when the menu-bar (or mode-line) is updated,
7124 which does not normally happen after every command. */
7127 nminor
= current_minor_maps (NULL
, &tmaps
);
7128 maps
= (Lisp_Object
*) alloca ((nminor
+ 3) * sizeof (maps
[0]));
7130 if (tem
= get_local_map (PT
, current_buffer
, Qkeymap
), !NILP (tem
))
7131 maps
[nmaps
++] = tem
;
7132 bcopy (tmaps
, (void *) (maps
+ nmaps
), nminor
* sizeof (maps
[0]));
7134 maps
[nmaps
++] = get_local_map (PT
, current_buffer
, Qlocal_map
);
7136 maps
[nmaps
++] = current_global_map
;
7139 /* Look up in each map the dummy prefix key `menu-bar'. */
7143 for (mapno
= nmaps
- 1; mapno
>= 0; mapno
--)
7144 if (!NILP (maps
[mapno
]))
7146 def
= get_keymap (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0, 1),
7150 menu_bar_one_keymap_changed_items
= Qnil
;
7151 map_keymap (def
, menu_bar_item
, Qnil
, NULL
, 1);
7155 /* Move to the end those items that should be at the end. */
7157 for (tail
= Vmenu_bar_final_items
; CONSP (tail
); tail
= XCDR (tail
))
7160 int end
= menu_bar_items_index
;
7162 for (i
= 0; i
< end
; i
+= 4)
7163 if (EQ (XCAR (tail
), XVECTOR (menu_bar_items_vector
)->contents
[i
]))
7165 Lisp_Object tem0
, tem1
, tem2
, tem3
;
7166 /* Move the item at index I to the end,
7167 shifting all the others forward. */
7168 tem0
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 0];
7169 tem1
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 1];
7170 tem2
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
7171 tem3
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3];
7173 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
7174 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
7175 (end
- i
- 4) * sizeof (Lisp_Object
));
7176 XVECTOR (menu_bar_items_vector
)->contents
[end
- 4] = tem0
;
7177 XVECTOR (menu_bar_items_vector
)->contents
[end
- 3] = tem1
;
7178 XVECTOR (menu_bar_items_vector
)->contents
[end
- 2] = tem2
;
7179 XVECTOR (menu_bar_items_vector
)->contents
[end
- 1] = tem3
;
7184 /* Add nil, nil, nil, nil at the end. */
7185 i
= menu_bar_items_index
;
7186 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
7189 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
7190 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
7191 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
7192 menu_bar_items_vector
= tem
;
7194 /* Add this item. */
7195 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
7196 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
7197 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
7198 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
7199 menu_bar_items_index
= i
;
7201 Vinhibit_quit
= oquit
;
7202 return menu_bar_items_vector
;
7205 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
7206 If there's already an item for KEY, add this DEF to it. */
7208 Lisp_Object item_properties
;
7211 menu_bar_item (key
, item
, dummy1
, dummy2
)
7212 Lisp_Object key
, item
, dummy1
;
7215 struct gcpro gcpro1
;
7219 if (EQ (item
, Qundefined
))
7221 /* If a map has an explicit `undefined' as definition,
7222 discard any previously made menu bar item. */
7224 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
7225 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
7227 if (menu_bar_items_index
> i
+ 4)
7228 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
7229 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
7230 (menu_bar_items_index
- i
- 4) * sizeof (Lisp_Object
));
7231 menu_bar_items_index
-= 4;
7235 /* If this keymap has already contributed to this KEY,
7236 don't contribute to it a second time. */
7237 tem
= Fmemq (key
, menu_bar_one_keymap_changed_items
);
7238 if (!NILP (tem
) || NILP (item
))
7241 menu_bar_one_keymap_changed_items
7242 = Fcons (key
, menu_bar_one_keymap_changed_items
);
7244 /* We add to menu_bar_one_keymap_changed_items before doing the
7245 parse_menu_item, so that if it turns out it wasn't a menu item,
7246 it still correctly hides any further menu item. */
7248 i
= parse_menu_item (item
, 0, 1);
7253 item
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
7255 /* Find any existing item for this KEY. */
7256 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
7257 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
7260 /* If we did not find this KEY, add it at the end. */
7261 if (i
== menu_bar_items_index
)
7263 /* If vector is too small, get a bigger one. */
7264 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
7267 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
7268 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
7269 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
7270 menu_bar_items_vector
= tem
;
7273 /* Add this item. */
7274 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = key
;
7275 XVECTOR (menu_bar_items_vector
)->contents
[i
++]
7276 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
7277 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Fcons (item
, Qnil
);
7278 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = make_number (0);
7279 menu_bar_items_index
= i
;
7281 /* We did find an item for this KEY. Add ITEM to its list of maps. */
7285 old
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
7286 /* If the new and the old items are not both keymaps,
7287 the lookup will only find `item'. */
7288 item
= Fcons (item
, KEYMAPP (item
) && KEYMAPP (XCAR (old
)) ? old
: Qnil
);
7289 XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2] = item
;
7293 /* This is used as the handler when calling menu_item_eval_property. */
7295 menu_item_eval_property_1 (arg
)
7298 /* If we got a quit from within the menu computation,
7299 quit all the way out of it. This takes care of C-] in the debugger. */
7300 if (CONSP (arg
) && EQ (XCAR (arg
), Qquit
))
7301 Fsignal (Qquit
, Qnil
);
7306 /* Evaluate an expression and return the result (or nil if something
7307 went wrong). Used to evaluate dynamic parts of menu items. */
7309 menu_item_eval_property (sexpr
)
7312 int count
= SPECPDL_INDEX ();
7314 specbind (Qinhibit_redisplay
, Qt
);
7315 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
,
7316 menu_item_eval_property_1
);
7317 return unbind_to (count
, val
);
7320 /* This function parses a menu item and leaves the result in the
7321 vector item_properties.
7322 ITEM is a key binding, a possible menu item.
7323 If NOTREAL is nonzero, only check for equivalent key bindings, don't
7324 evaluate dynamic expressions in the menu item.
7325 INMENUBAR is > 0 when this is considered for an entry in a menu bar
7327 INMENUBAR is < 0 when this is considered for an entry in a keyboard menu.
7328 parse_menu_item returns true if the item is a menu item and false
7332 parse_menu_item (item
, notreal
, inmenubar
)
7334 int notreal
, inmenubar
;
7336 Lisp_Object def
, tem
, item_string
, start
;
7337 Lisp_Object cachelist
;
7339 Lisp_Object keyhint
;
7350 /* Create item_properties vector if necessary. */
7351 if (NILP (item_properties
))
7353 = Fmake_vector (make_number (ITEM_PROPERTY_ENABLE
+ 1), Qnil
);
7355 /* Initialize optional entries. */
7356 for (i
= ITEM_PROPERTY_DEF
; i
< ITEM_PROPERTY_ENABLE
; i
++)
7357 AREF (item_properties
, i
) = Qnil
;
7358 AREF (item_properties
, ITEM_PROPERTY_ENABLE
) = Qt
;
7360 /* Save the item here to protect it from GC. */
7361 AREF (item_properties
, ITEM_PROPERTY_ITEM
) = item
;
7363 item_string
= XCAR (item
);
7367 if (STRINGP (item_string
))
7369 /* Old format menu item. */
7370 AREF (item_properties
, ITEM_PROPERTY_NAME
) = item_string
;
7372 /* Maybe help string. */
7373 if (CONSP (item
) && STRINGP (XCAR (item
)))
7375 AREF (item_properties
, ITEM_PROPERTY_HELP
) = XCAR (item
);
7380 /* Maybe key binding cache. */
7381 if (CONSP (item
) && CONSP (XCAR (item
))
7382 && (NILP (XCAR (XCAR (item
)))
7383 || VECTORP (XCAR (XCAR (item
)))))
7385 cachelist
= XCAR (item
);
7389 /* This is the real definition--the function to run. */
7390 AREF (item_properties
, ITEM_PROPERTY_DEF
) = item
;
7392 /* Get enable property, if any. */
7395 tem
= Fget (item
, Qmenu_enable
);
7397 AREF (item_properties
, ITEM_PROPERTY_ENABLE
) = tem
;
7400 else if (EQ (item_string
, Qmenu_item
) && CONSP (item
))
7402 /* New format menu item. */
7403 AREF (item_properties
, ITEM_PROPERTY_NAME
) = XCAR (item
);
7404 start
= XCDR (item
);
7407 /* We have a real binding. */
7408 AREF (item_properties
, ITEM_PROPERTY_DEF
) = XCAR (start
);
7410 item
= XCDR (start
);
7411 /* Is there a cache list with key equivalences. */
7412 if (CONSP (item
) && CONSP (XCAR (item
)))
7414 cachelist
= XCAR (item
);
7418 /* Parse properties. */
7419 while (CONSP (item
) && CONSP (XCDR (item
)))
7424 if (EQ (tem
, QCenable
))
7425 AREF (item_properties
, ITEM_PROPERTY_ENABLE
) = XCAR (item
);
7426 else if (EQ (tem
, QCvisible
) && !notreal
)
7428 /* If got a visible property and that evaluates to nil
7429 then ignore this item. */
7430 tem
= menu_item_eval_property (XCAR (item
));
7434 else if (EQ (tem
, QChelp
))
7435 AREF (item_properties
, ITEM_PROPERTY_HELP
) = XCAR (item
);
7436 else if (EQ (tem
, QCfilter
))
7438 else if (EQ (tem
, QCkey_sequence
))
7441 if (NILP (cachelist
)
7442 && (SYMBOLP (tem
) || STRINGP (tem
) || VECTORP (tem
)))
7443 /* Be GC protected. Set keyhint to item instead of tem. */
7446 else if (EQ (tem
, QCkeys
))
7449 if (CONSP (tem
) || (STRINGP (tem
) && NILP (cachelist
)))
7450 AREF (item_properties
, ITEM_PROPERTY_KEYEQ
) = tem
;
7452 else if (EQ (tem
, QCbutton
) && CONSP (XCAR (item
)))
7457 if (EQ (type
, QCtoggle
) || EQ (type
, QCradio
))
7459 AREF (item_properties
, ITEM_PROPERTY_SELECTED
)
7461 AREF (item_properties
, ITEM_PROPERTY_TYPE
)
7468 else if (inmenubar
|| !NILP (start
))
7472 return 0; /* not a menu item */
7474 /* If item string is not a string, evaluate it to get string.
7475 If we don't get a string, skip this item. */
7476 item_string
= AREF (item_properties
, ITEM_PROPERTY_NAME
);
7477 if (!(STRINGP (item_string
) || notreal
))
7479 item_string
= menu_item_eval_property (item_string
);
7480 if (!STRINGP (item_string
))
7482 AREF (item_properties
, ITEM_PROPERTY_NAME
) = item_string
;
7485 /* If got a filter apply it on definition. */
7486 def
= AREF (item_properties
, ITEM_PROPERTY_DEF
);
7489 def
= menu_item_eval_property (list2 (XCAR (filter
),
7490 list2 (Qquote
, def
)));
7492 AREF (item_properties
, ITEM_PROPERTY_DEF
) = def
;
7495 /* Enable or disable selection of item. */
7496 tem
= AREF (item_properties
, ITEM_PROPERTY_ENABLE
);
7502 tem
= menu_item_eval_property (tem
);
7503 if (inmenubar
&& NILP (tem
))
7504 return 0; /* Ignore disabled items in menu bar. */
7505 AREF (item_properties
, ITEM_PROPERTY_ENABLE
) = tem
;
7508 /* If we got no definition, this item is just unselectable text which
7509 is OK in a submenu but not in the menubar. */
7511 return (inmenubar
? 0 : 1);
7513 /* See if this is a separate pane or a submenu. */
7514 def
= AREF (item_properties
, ITEM_PROPERTY_DEF
);
7515 tem
= get_keymap (def
, 0, 1);
7516 /* For a subkeymap, just record its details and exit. */
7519 AREF (item_properties
, ITEM_PROPERTY_MAP
) = tem
;
7520 AREF (item_properties
, ITEM_PROPERTY_DEF
) = tem
;
7524 /* At the top level in the menu bar, do likewise for commands also.
7525 The menu bar does not display equivalent key bindings anyway.
7526 ITEM_PROPERTY_DEF is already set up properly. */
7530 /* This is a command. See if there is an equivalent key binding. */
7531 if (NILP (cachelist
))
7533 /* We have to create a cachelist. */
7534 CHECK_IMPURE (start
);
7535 XSETCDR (start
, Fcons (Fcons (Qnil
, Qnil
), XCDR (start
)));
7536 cachelist
= XCAR (XCDR (start
));
7538 tem
= AREF (item_properties
, ITEM_PROPERTY_KEYEQ
);
7539 if (!NILP (keyhint
))
7541 XSETCAR (cachelist
, XCAR (keyhint
));
7544 else if (STRINGP (tem
))
7546 XSETCDR (cachelist
, Fsubstitute_command_keys (tem
));
7547 XSETCAR (cachelist
, Qt
);
7551 tem
= XCAR (cachelist
);
7558 tem
= Fkey_binding (tem
, Qnil
, Qnil
);
7560 prefix
= AREF (item_properties
, ITEM_PROPERTY_KEYEQ
);
7563 def
= XCAR (prefix
);
7564 prefix
= XCDR (prefix
);
7567 def
= AREF (item_properties
, ITEM_PROPERTY_DEF
);
7569 if (NILP (XCAR (cachelist
))) /* Have no saved key. */
7571 if (newcache
/* Always check first time. */
7572 /* Should we check everything when precomputing key
7574 /* If something had no key binding before, don't recheck it
7575 because that is too slow--except if we have a list of
7576 rebound commands in Vdefine_key_rebound_commands, do
7577 recheck any command that appears in that list. */
7578 || (CONSP (Vdefine_key_rebound_commands
)
7579 && !NILP (Fmemq (def
, Vdefine_key_rebound_commands
))))
7582 /* We had a saved key. Is it still bound to the command? */
7585 /* If the command is an alias for another
7586 (such as lmenu.el set it up), check if the
7587 original command matches the cached command. */
7588 && !(SYMBOLP (def
) && EQ (tem
, XSYMBOL (def
)->function
))))
7589 chkcache
= 1; /* Need to recompute key binding. */
7593 /* Recompute equivalent key binding. If the command is an alias
7594 for another (such as lmenu.el set it up), see if the original
7595 command name has equivalent keys. Otherwise look up the
7596 specified command itself. We don't try both, because that
7597 makes lmenu menus slow. */
7599 && SYMBOLP (XSYMBOL (def
)->function
)
7600 && ! NILP (Fget (def
, Qmenu_alias
)))
7601 def
= XSYMBOL (def
)->function
;
7602 tem
= Fwhere_is_internal (def
, Qnil
, Qt
, Qnil
, Qt
);
7603 XSETCAR (cachelist
, tem
);
7606 XSETCDR (cachelist
, Qnil
);
7610 else if (!NILP (keyhint
) && !NILP (XCAR (cachelist
)))
7612 tem
= XCAR (cachelist
);
7616 newcache
= chkcache
;
7619 tem
= Fkey_description (tem
, Qnil
);
7622 if (STRINGP (XCAR (prefix
)))
7623 tem
= concat2 (XCAR (prefix
), tem
);
7624 if (STRINGP (XCDR (prefix
)))
7625 tem
= concat2 (tem
, XCDR (prefix
));
7627 XSETCDR (cachelist
, tem
);
7631 tem
= XCDR (cachelist
);
7632 if (newcache
&& !NILP (tem
))
7634 tem
= concat3 (build_string (" ("), tem
, build_string (")"));
7635 XSETCDR (cachelist
, tem
);
7638 /* If we only want to precompute equivalent key bindings, stop here. */
7642 /* If we have an equivalent key binding, use that. */
7643 AREF (item_properties
, ITEM_PROPERTY_KEYEQ
) = tem
;
7645 /* Include this when menu help is implemented.
7646 tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP];
7647 if (!(NILP (tem) || STRINGP (tem)))
7649 tem = menu_item_eval_property (tem);
7652 XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP] = tem;
7656 /* Handle radio buttons or toggle boxes. */
7657 tem
= AREF (item_properties
, ITEM_PROPERTY_SELECTED
);
7659 AREF (item_properties
, ITEM_PROPERTY_SELECTED
)
7660 = menu_item_eval_property (tem
);
7667 /***********************************************************************
7669 ***********************************************************************/
7671 /* A vector holding tool bar items while they are parsed in function
7672 tool_bar_items. Each item occupies TOOL_BAR_ITEM_NSCLOTS elements
7675 static Lisp_Object tool_bar_items_vector
;
7677 /* A vector holding the result of parse_tool_bar_item. Layout is like
7678 the one for a single item in tool_bar_items_vector. */
7680 static Lisp_Object tool_bar_item_properties
;
7682 /* Next free index in tool_bar_items_vector. */
7684 static int ntool_bar_items
;
7686 /* The symbols `tool-bar', and `:image'. */
7688 extern Lisp_Object Qtool_bar
;
7689 Lisp_Object QCimage
;
7691 /* Function prototypes. */
7693 static void init_tool_bar_items
P_ ((Lisp_Object
));
7694 static void process_tool_bar_item
P_ ((Lisp_Object
, Lisp_Object
));
7695 static int parse_tool_bar_item
P_ ((Lisp_Object
, Lisp_Object
));
7696 static void append_tool_bar_item
P_ ((void));
7699 /* Return a vector of tool bar items for keymaps currently in effect.
7700 Reuse vector REUSE if non-nil. Return in *NITEMS the number of
7701 tool bar items found. */
7704 tool_bar_items (reuse
, nitems
)
7715 /* In order to build the menus, we need to call the keymap
7716 accessors. They all call QUIT. But this function is called
7717 during redisplay, during which a quit is fatal. So inhibit
7718 quitting while building the menus. We do this instead of
7719 specbind because (1) errors will clear it anyway and (2) this
7720 avoids risk of specpdl overflow. */
7721 oquit
= Vinhibit_quit
;
7724 /* Initialize tool_bar_items_vector and protect it from GC. */
7725 init_tool_bar_items (reuse
);
7727 /* Build list of keymaps in maps. Set nmaps to the number of maps
7730 /* Should overriding-terminal-local-map and overriding-local-map apply? */
7731 if (!NILP (Voverriding_local_map_menu_flag
))
7733 /* Yes, use them (if non-nil) as well as the global map. */
7734 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
7736 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
7737 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
7738 if (!NILP (Voverriding_local_map
))
7739 maps
[nmaps
++] = Voverriding_local_map
;
7743 /* No, so use major and minor mode keymaps and keymap property.
7744 Note that tool-bar bindings in the local-map and keymap
7745 properties may not work reliable, as they are only
7746 recognized when the tool-bar (or mode-line) is updated,
7747 which does not normally happen after every command. */
7750 nminor
= current_minor_maps (NULL
, &tmaps
);
7751 maps
= (Lisp_Object
*) alloca ((nminor
+ 3) * sizeof (maps
[0]));
7753 if (tem
= get_local_map (PT
, current_buffer
, Qkeymap
), !NILP (tem
))
7754 maps
[nmaps
++] = tem
;
7755 bcopy (tmaps
, (void *) (maps
+ nmaps
), nminor
* sizeof (maps
[0]));
7757 maps
[nmaps
++] = get_local_map (PT
, current_buffer
, Qlocal_map
);
7760 /* Add global keymap at the end. */
7761 maps
[nmaps
++] = current_global_map
;
7763 /* Process maps in reverse order and look up in each map the prefix
7765 for (i
= nmaps
- 1; i
>= 0; --i
)
7766 if (!NILP (maps
[i
]))
7770 keymap
= get_keymap (access_keymap (maps
[i
], Qtool_bar
, 1, 0, 1), 0, 1);
7775 /* KEYMAP is a list `(keymap (KEY . BINDING) ...)'. */
7776 for (tail
= keymap
; CONSP (tail
); tail
= XCDR (tail
))
7778 Lisp_Object keydef
= XCAR (tail
);
7780 process_tool_bar_item (XCAR (keydef
), XCDR (keydef
));
7785 Vinhibit_quit
= oquit
;
7786 *nitems
= ntool_bar_items
/ TOOL_BAR_ITEM_NSLOTS
;
7787 return tool_bar_items_vector
;
7791 /* Process the definition of KEY which is DEF. */
7794 process_tool_bar_item (key
, def
)
7795 Lisp_Object key
, def
;
7798 extern Lisp_Object Qundefined
;
7799 struct gcpro gcpro1
, gcpro2
;
7801 /* Protect KEY and DEF from GC because parse_tool_bar_item may call
7805 if (EQ (def
, Qundefined
))
7807 /* If a map has an explicit `undefined' as definition,
7808 discard any previously made item. */
7809 for (i
= 0; i
< ntool_bar_items
; i
+= TOOL_BAR_ITEM_NSLOTS
)
7811 Lisp_Object
*v
= XVECTOR (tool_bar_items_vector
)->contents
+ i
;
7813 if (EQ (key
, v
[TOOL_BAR_ITEM_KEY
]))
7815 if (ntool_bar_items
> i
+ TOOL_BAR_ITEM_NSLOTS
)
7816 bcopy (v
+ TOOL_BAR_ITEM_NSLOTS
, v
,
7817 ((ntool_bar_items
- i
- TOOL_BAR_ITEM_NSLOTS
)
7818 * sizeof (Lisp_Object
)));
7819 ntool_bar_items
-= TOOL_BAR_ITEM_NSLOTS
;
7824 else if (parse_tool_bar_item (key
, def
))
7825 /* Append a new tool bar item to tool_bar_items_vector. Accept
7826 more than one definition for the same key. */
7827 append_tool_bar_item ();
7833 /* Parse a tool bar item specification ITEM for key KEY and return the
7834 result in tool_bar_item_properties. Value is zero if ITEM is
7837 ITEM is a list `(menu-item CAPTION BINDING PROPS...)'.
7839 CAPTION is the caption of the item, If it's not a string, it is
7840 evaluated to get a string.
7842 BINDING is the tool bar item's binding. Tool-bar items with keymaps
7843 as binding are currently ignored.
7845 The following properties are recognized:
7849 FORM is evaluated and specifies whether the tool bar item is
7850 enabled or disabled.
7854 FORM is evaluated and specifies whether the tool bar item is visible.
7856 - `:filter FUNCTION'
7858 FUNCTION is invoked with one parameter `(quote BINDING)'. Its
7859 result is stored as the new binding.
7861 - `:button (TYPE SELECTED)'
7863 TYPE must be one of `:radio' or `:toggle'. SELECTED is evaluated
7864 and specifies whether the button is selected (pressed) or not.
7868 IMAGES is either a single image specification or a vector of four
7869 image specifications. See enum tool_bar_item_images.
7871 - `:help HELP-STRING'.
7873 Gives a help string to display for the tool bar item. */
7876 parse_tool_bar_item (key
, item
)
7877 Lisp_Object key
, item
;
7879 /* Access slot with index IDX of vector tool_bar_item_properties. */
7880 #define PROP(IDX) XVECTOR (tool_bar_item_properties)->contents[IDX]
7882 Lisp_Object filter
= Qnil
;
7883 Lisp_Object caption
;
7886 /* Defininition looks like `(menu-item CAPTION BINDING PROPS...)'.
7887 Rule out items that aren't lists, don't start with
7888 `menu-item' or whose rest following `tool-bar-item' is not a
7891 || !EQ (XCAR (item
), Qmenu_item
)
7892 || (item
= XCDR (item
),
7896 /* Create tool_bar_item_properties vector if necessary. Reset it to
7898 if (VECTORP (tool_bar_item_properties
))
7900 for (i
= 0; i
< TOOL_BAR_ITEM_NSLOTS
; ++i
)
7904 tool_bar_item_properties
7905 = Fmake_vector (make_number (TOOL_BAR_ITEM_NSLOTS
), Qnil
);
7908 PROP (TOOL_BAR_ITEM_KEY
) = key
;
7909 PROP (TOOL_BAR_ITEM_ENABLED_P
) = Qt
;
7911 /* Get the caption of the item. If the caption is not a string,
7912 evaluate it to get a string. If we don't get a string, skip this
7914 caption
= XCAR (item
);
7915 if (!STRINGP (caption
))
7917 caption
= menu_item_eval_property (caption
);
7918 if (!STRINGP (caption
))
7921 PROP (TOOL_BAR_ITEM_CAPTION
) = caption
;
7923 /* Give up if rest following the caption is not a list. */
7928 /* Store the binding. */
7929 PROP (TOOL_BAR_ITEM_BINDING
) = XCAR (item
);
7932 /* Ignore cached key binding, if any. */
7933 if (CONSP (item
) && CONSP (XCAR (item
)))
7936 /* Process the rest of the properties. */
7937 for (; CONSP (item
) && CONSP (XCDR (item
)); item
= XCDR (XCDR (item
)))
7939 Lisp_Object key
, value
;
7942 value
= XCAR (XCDR (item
));
7944 if (EQ (key
, QCenable
))
7945 /* `:enable FORM'. */
7946 PROP (TOOL_BAR_ITEM_ENABLED_P
) = value
;
7947 else if (EQ (key
, QCvisible
))
7949 /* `:visible FORM'. If got a visible property and that
7950 evaluates to nil then ignore this item. */
7951 if (NILP (menu_item_eval_property (value
)))
7954 else if (EQ (key
, QChelp
))
7955 /* `:help HELP-STRING'. */
7956 PROP (TOOL_BAR_ITEM_HELP
) = value
;
7957 else if (EQ (key
, QCfilter
))
7958 /* ':filter FORM'. */
7960 else if (EQ (key
, QCbutton
) && CONSP (value
))
7962 /* `:button (TYPE . SELECTED)'. */
7963 Lisp_Object type
, selected
;
7965 type
= XCAR (value
);
7966 selected
= XCDR (value
);
7967 if (EQ (type
, QCtoggle
) || EQ (type
, QCradio
))
7969 PROP (TOOL_BAR_ITEM_SELECTED_P
) = selected
;
7970 PROP (TOOL_BAR_ITEM_TYPE
) = type
;
7973 else if (EQ (key
, QCimage
)
7975 || (VECTORP (value
) && XVECTOR (value
)->size
== 4)))
7976 /* Value is either a single image specification or a vector
7977 of 4 such specifications for the different button states. */
7978 PROP (TOOL_BAR_ITEM_IMAGES
) = value
;
7981 /* If got a filter apply it on binding. */
7983 PROP (TOOL_BAR_ITEM_BINDING
)
7984 = menu_item_eval_property (list2 (filter
,
7986 PROP (TOOL_BAR_ITEM_BINDING
))));
7988 /* See if the binding is a keymap. Give up if it is. */
7989 if (CONSP (get_keymap (PROP (TOOL_BAR_ITEM_BINDING
), 0, 1)))
7992 /* Enable or disable selection of item. */
7993 if (!EQ (PROP (TOOL_BAR_ITEM_ENABLED_P
), Qt
))
7994 PROP (TOOL_BAR_ITEM_ENABLED_P
)
7995 = menu_item_eval_property (PROP (TOOL_BAR_ITEM_ENABLED_P
));
7997 /* Handle radio buttons or toggle boxes. */
7998 if (!NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
)))
7999 PROP (TOOL_BAR_ITEM_SELECTED_P
)
8000 = menu_item_eval_property (PROP (TOOL_BAR_ITEM_SELECTED_P
));
8008 /* Initialize tool_bar_items_vector. REUSE, if non-nil, is a vector
8009 that can be reused. */
8012 init_tool_bar_items (reuse
)
8015 if (VECTORP (reuse
))
8016 tool_bar_items_vector
= reuse
;
8018 tool_bar_items_vector
= Fmake_vector (make_number (64), Qnil
);
8019 ntool_bar_items
= 0;
8023 /* Append parsed tool bar item properties from
8024 tool_bar_item_properties */
8027 append_tool_bar_item ()
8029 Lisp_Object
*to
, *from
;
8031 /* Enlarge tool_bar_items_vector if necessary. */
8032 if (ntool_bar_items
+ TOOL_BAR_ITEM_NSLOTS
8033 >= XVECTOR (tool_bar_items_vector
)->size
)
8035 Lisp_Object new_vector
;
8036 int old_size
= XVECTOR (tool_bar_items_vector
)->size
;
8038 new_vector
= Fmake_vector (make_number (2 * old_size
), Qnil
);
8039 bcopy (XVECTOR (tool_bar_items_vector
)->contents
,
8040 XVECTOR (new_vector
)->contents
,
8041 old_size
* sizeof (Lisp_Object
));
8042 tool_bar_items_vector
= new_vector
;
8045 /* Append entries from tool_bar_item_properties to the end of
8046 tool_bar_items_vector. */
8047 to
= XVECTOR (tool_bar_items_vector
)->contents
+ ntool_bar_items
;
8048 from
= XVECTOR (tool_bar_item_properties
)->contents
;
8049 bcopy (from
, to
, TOOL_BAR_ITEM_NSLOTS
* sizeof *to
);
8050 ntool_bar_items
+= TOOL_BAR_ITEM_NSLOTS
;
8057 /* Read a character using menus based on maps in the array MAPS.
8058 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
8059 Return t if we displayed a menu but the user rejected it.
8061 PREV_EVENT is the previous input event, or nil if we are reading
8062 the first event of a key sequence.
8064 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
8065 if we used a mouse menu to read the input, or zero otherwise. If
8066 USED_MOUSE_MENU is null, we don't dereference it.
8068 The prompting is done based on the prompt-string of the map
8069 and the strings associated with various map elements.
8071 This can be done with X menus or with menus put in the minibuf.
8072 These are done in different ways, depending on how the input will be read.
8073 Menus using X are done after auto-saving in read-char, getting the input
8074 event from Fx_popup_menu; menus using the minibuf use read_char recursively
8075 and do auto-saving in the inner call of read_char. */
8078 read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
8081 Lisp_Object prev_event
;
8082 int *used_mouse_menu
;
8085 register Lisp_Object name
= Qnil
;
8087 if (used_mouse_menu
)
8088 *used_mouse_menu
= 0;
8090 /* Use local over global Menu maps */
8092 if (! menu_prompting
)
8095 /* Optionally disregard all but the global map. */
8096 if (inhibit_local_menu_bar_menus
)
8098 maps
+= (nmaps
- 1);
8102 /* Get the menu name from the first map that has one (a prompt string). */
8103 for (mapno
= 0; mapno
< nmaps
; mapno
++)
8105 name
= Fkeymap_prompt (maps
[mapno
]);
8110 /* If we don't have any menus, just read a character normally. */
8111 if (!STRINGP (name
))
8115 /* If we got to this point via a mouse click,
8116 use a real menu for mouse selection. */
8117 if (EVENT_HAS_PARAMETERS (prev_event
)
8118 && !EQ (XCAR (prev_event
), Qmenu_bar
)
8119 && !EQ (XCAR (prev_event
), Qtool_bar
))
8121 /* Display the menu and get the selection. */
8122 Lisp_Object
*realmaps
8123 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
8127 /* Use the maps that are not nil. */
8128 for (mapno
= 0; mapno
< nmaps
; mapno
++)
8129 if (!NILP (maps
[mapno
]))
8130 realmaps
[nmaps1
++] = maps
[mapno
];
8132 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
8137 record_menu_key (XCAR (value
));
8139 /* If we got multiple events, unread all but
8141 There is no way to prevent those unread events
8142 from showing up later in last_nonmenu_event.
8143 So turn symbol and integer events into lists,
8144 to indicate that they came from a mouse menu,
8145 so that when present in last_nonmenu_event
8146 they won't confuse things. */
8147 for (tem
= XCDR (value
); !NILP (tem
); tem
= XCDR (tem
))
8149 record_menu_key (XCAR (tem
));
8150 if (SYMBOLP (XCAR (tem
))
8151 || INTEGERP (XCAR (tem
)))
8152 XSETCAR (tem
, Fcons (XCAR (tem
), Qdisabled
));
8155 /* If we got more than one event, put all but the first
8156 onto this list to be read later.
8157 Return just the first event now. */
8158 Vunread_command_events
8159 = nconc2 (XCDR (value
), Vunread_command_events
);
8160 value
= XCAR (value
);
8162 else if (NILP (value
))
8164 if (used_mouse_menu
)
8165 *used_mouse_menu
= 1;
8168 #endif /* HAVE_MENUS */
8172 /* Buffer in use so far for the minibuf prompts for menu keymaps.
8173 We make this bigger when necessary, and never free it. */
8174 static char *read_char_minibuf_menu_text
;
8175 /* Size of that buffer. */
8176 static int read_char_minibuf_menu_width
;
8179 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
8185 register Lisp_Object name
;
8187 /* FIXME: Use the minibuffer's frame width. */
8188 int width
= FRAME_COLS (SELECTED_FRAME ()) - 4;
8191 Lisp_Object rest
, vector
;
8197 if (! menu_prompting
)
8200 /* Make sure we have a big enough buffer for the menu text. */
8201 if (read_char_minibuf_menu_text
== 0)
8203 read_char_minibuf_menu_width
= width
+ 4;
8204 read_char_minibuf_menu_text
= (char *) xmalloc (width
+ 4);
8206 else if (width
+ 4 > read_char_minibuf_menu_width
)
8208 read_char_minibuf_menu_width
= width
+ 4;
8209 read_char_minibuf_menu_text
8210 = (char *) xrealloc (read_char_minibuf_menu_text
, width
+ 4);
8212 menu
= read_char_minibuf_menu_text
;
8214 /* Get the menu name from the first map that has one (a prompt string). */
8215 for (mapno
= 0; mapno
< nmaps
; mapno
++)
8217 name
= Fkeymap_prompt (maps
[mapno
]);
8222 /* If we don't have any menus, just read a character normally. */
8223 if (!STRINGP (name
))
8226 /* Prompt string always starts with map's prompt, and a space. */
8227 strcpy (menu
, SDATA (name
));
8228 nlength
= SBYTES (name
);
8229 menu
[nlength
++] = ':';
8230 menu
[nlength
++] = ' ';
8233 /* Start prompting at start of first map. */
8237 /* Present the documented bindings, a line at a time. */
8244 Lisp_Object orig_defn_macro
;
8246 /* Loop over elements of map. */
8251 /* If reached end of map, start at beginning of next map. */
8255 /* At end of last map, wrap around to first map if just starting,
8256 or end this line if already have something on it. */
8260 if (notfirst
|| nobindings
) break;
8265 /* Look at the next element of the map. */
8267 elt
= XVECTOR (vector
)->contents
[idx
];
8269 elt
= Fcar_safe (rest
);
8271 if (idx
< 0 && VECTORP (elt
))
8273 /* If we found a dense table in the keymap,
8274 advanced past it, but start scanning its contents. */
8275 rest
= Fcdr_safe (rest
);
8281 /* An ordinary element. */
8282 Lisp_Object event
, tem
;
8286 event
= Fcar_safe (elt
); /* alist */
8287 elt
= Fcdr_safe (elt
);
8291 XSETINT (event
, idx
); /* vector */
8294 /* Ignore the element if it has no prompt string. */
8295 if (INTEGERP (event
) && parse_menu_item (elt
, 0, -1))
8297 /* 1 if the char to type matches the string. */
8299 Lisp_Object upcased_event
, downcased_event
;
8300 Lisp_Object desc
= Qnil
;
8302 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
8304 upcased_event
= Fupcase (event
);
8305 downcased_event
= Fdowncase (event
);
8306 char_matches
= (XINT (upcased_event
) == SREF (s
, 0)
8307 || XINT (downcased_event
) == SREF (s
, 0));
8309 desc
= Fsingle_key_description (event
, Qnil
);
8311 #if 0 /* It is redundant to list the equivalent key bindings because
8312 the prefix is what the user has already typed. */
8314 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
8316 /* Insert equivalent keybinding. */
8317 s
= concat2 (s
, tem
);
8320 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_TYPE
];
8321 if (EQ (tem
, QCradio
) || EQ (tem
, QCtoggle
))
8323 /* Insert button prefix. */
8324 Lisp_Object selected
8325 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
];
8326 if (EQ (tem
, QCradio
))
8327 tem
= build_string (NILP (selected
) ? "(*) " : "( ) ");
8329 tem
= build_string (NILP (selected
) ? "[X] " : "[ ] ");
8330 s
= concat2 (tem
, s
);
8334 /* If we have room for the prompt string, add it to this line.
8335 If this is the first on the line, always add it. */
8336 if ((SCHARS (s
) + i
+ 2
8337 + (char_matches
? 0 : SCHARS (desc
) + 3))
8343 /* Punctuate between strings. */
8346 strcpy (menu
+ i
, ", ");
8352 /* If the char to type doesn't match the string's
8353 first char, explicitly show what char to type. */
8356 /* Add as much of string as fits. */
8357 thiswidth
= SCHARS (desc
);
8358 if (thiswidth
+ i
> width
)
8359 thiswidth
= width
- i
;
8360 bcopy (SDATA (desc
), menu
+ i
, thiswidth
);
8362 strcpy (menu
+ i
, " = ");
8366 /* Add as much of string as fits. */
8367 thiswidth
= SCHARS (s
);
8368 if (thiswidth
+ i
> width
)
8369 thiswidth
= width
- i
;
8370 bcopy (SDATA (s
), menu
+ i
, thiswidth
);
8376 /* If this element does not fit, end the line now,
8377 and save the element for the next line. */
8378 strcpy (menu
+ i
, "...");
8383 /* Move past this element. */
8384 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
8385 /* Handle reaching end of dense table. */
8390 rest
= Fcdr_safe (rest
);
8394 /* Prompt with that and read response. */
8395 message2_nolog (menu
, strlen (menu
),
8396 ! NILP (current_buffer
->enable_multibyte_characters
));
8398 /* Make believe its not a keyboard macro in case the help char
8399 is pressed. Help characters are not recorded because menu prompting
8400 is not used on replay.
8402 orig_defn_macro
= current_kboard
->defining_kbd_macro
;
8403 current_kboard
->defining_kbd_macro
= Qnil
;
8405 obj
= read_char (commandflag
, 0, 0, Qt
, 0);
8406 while (BUFFERP (obj
));
8407 current_kboard
->defining_kbd_macro
= orig_defn_macro
;
8409 if (!INTEGERP (obj
))
8414 if (! EQ (obj
, menu_prompt_more_char
)
8415 && (!INTEGERP (menu_prompt_more_char
)
8416 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
8418 if (!NILP (current_kboard
->defining_kbd_macro
))
8419 store_kbd_macro_char (obj
);
8422 /* Help char - go round again */
8426 /* Reading key sequences. */
8428 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
8429 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
8430 keymap, or nil otherwise. Return the index of the first keymap in
8431 which KEY has any binding, or NMAPS if no map has a binding.
8433 If KEY is a meta ASCII character, treat it like meta-prefix-char
8434 followed by the corresponding non-meta character. Keymaps in
8435 CURRENT with non-prefix bindings for meta-prefix-char become nil in
8438 If KEY has no bindings in any of the CURRENT maps, NEXT is left
8441 NEXT may be the same array as CURRENT. */
8444 follow_key (key
, nmaps
, current
, defs
, next
)
8446 Lisp_Object
*current
, *defs
, *next
;
8449 int i
, first_binding
;
8451 first_binding
= nmaps
;
8452 for (i
= nmaps
- 1; i
>= 0; i
--)
8454 if (! NILP (current
[i
]))
8456 defs
[i
] = access_keymap (current
[i
], key
, 1, 0, 1);
8457 if (! NILP (defs
[i
]))
8464 /* Given the set of bindings we've found, produce the next set of maps. */
8465 if (first_binding
< nmaps
)
8466 for (i
= 0; i
< nmaps
; i
++)
8467 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap (defs
[i
], 0, 1);
8469 return first_binding
;
8472 /* Structure used to keep track of partial application of key remapping
8473 such as Vfunction_key_map and Vkey_translation_map. */
8474 typedef struct keyremap
8476 Lisp_Object map
, parent
;
8480 /* Lookup KEY in MAP.
8481 MAP is a keymap mapping keys to key vectors or functions.
8482 If the mapping is a function and DO_FUNCTION is non-zero, then
8483 the function is called with PROMPT as parameter and its return
8484 value is used as the return value of this function (after checking
8485 that it is indeed a vector). */
8488 access_keymap_keyremap (map
, key
, prompt
, do_funcall
)
8489 Lisp_Object map
, key
, prompt
;
8494 next
= access_keymap (map
, key
, 1, 0, 1);
8496 /* Handle symbol with autoload definition. */
8497 if (SYMBOLP (next
) && !NILP (Ffboundp (next
))
8498 && CONSP (XSYMBOL (next
)->function
)
8499 && EQ (XCAR (XSYMBOL (next
)->function
), Qautoload
))
8500 do_autoload (XSYMBOL (next
)->function
, next
);
8502 /* Handle a symbol whose function definition is a keymap
8504 if (SYMBOLP (next
) && !NILP (Ffboundp (next
))
8505 && (!NILP (Farrayp (XSYMBOL (next
)->function
))
8506 || KEYMAPP (XSYMBOL (next
)->function
)))
8507 next
= XSYMBOL (next
)->function
;
8509 /* If the keymap gives a function, not an
8510 array, then call the function with one arg and use
8511 its value instead. */
8512 if (SYMBOLP (next
) && !NILP (Ffboundp (next
)) && do_funcall
)
8517 next
= call1 (next
, prompt
);
8518 /* If the function returned something invalid,
8519 barf--don't ignore it.
8520 (To ignore it safely, we would need to gcpro a bunch of
8521 other variables.) */
8522 if (! (VECTORP (next
) || STRINGP (next
)))
8523 error ("Function %s returns invalid key sequence", tem
);
8528 /* Do one step of the key remapping used for function-key-map and
8529 key-translation-map:
8530 KEYBUF is the buffer holding the input events.
8531 BUFSIZE is its maximum size.
8532 FKEY is a pointer to the keyremap structure to use.
8533 INPUT is the index of the last element in KEYBUF.
8534 DOIT if non-zero says that the remapping can actually take place.
8535 DIFF is used to return the number of keys added/removed by the remapping.
8536 PARENT is the root of the keymap.
8537 PROMPT is the prompt to use if the remapping happens through a function.
8538 The return value is non-zero if the remapping actually took place. */
8541 keyremap_step (keybuf
, bufsize
, fkey
, input
, doit
, diff
, prompt
)
8542 Lisp_Object
*keybuf
, prompt
;
8544 int input
, doit
, *diff
, bufsize
;
8546 Lisp_Object next
, key
;
8548 key
= keybuf
[fkey
->end
++];
8549 next
= access_keymap_keyremap (fkey
->map
, key
, prompt
, doit
);
8551 /* If keybuf[fkey->start..fkey->end] is bound in the
8552 map and we're in a position to do the key remapping, replace it with
8553 the binding and restart with fkey->start at the end. */
8554 if ((VECTORP (next
) || STRINGP (next
)) && doit
)
8556 int len
= XFASTINT (Flength (next
));
8559 *diff
= len
- (fkey
->end
- fkey
->start
);
8561 if (input
+ *diff
>= bufsize
)
8562 error ("Key sequence too long");
8564 /* Shift the keys that follow fkey->end. */
8566 for (i
= fkey
->end
; i
< input
; i
++)
8567 keybuf
[i
+ *diff
] = keybuf
[i
];
8569 for (i
= input
- 1; i
>= fkey
->end
; i
--)
8570 keybuf
[i
+ *diff
] = keybuf
[i
];
8571 /* Overwrite the old keys with the new ones. */
8572 for (i
= 0; i
< len
; i
++)
8573 keybuf
[fkey
->start
+ i
]
8574 = Faref (next
, make_number (i
));
8576 fkey
->start
= fkey
->end
+= *diff
;
8577 fkey
->map
= fkey
->parent
;
8582 fkey
->map
= get_keymap (next
, 0, 1);
8584 /* If we no longer have a bound suffix, try a new position for
8586 if (!CONSP (fkey
->map
))
8588 fkey
->end
= ++fkey
->start
;
8589 fkey
->map
= fkey
->parent
;
8594 /* Read a sequence of keys that ends with a non prefix character,
8595 storing it in KEYBUF, a buffer of size BUFSIZE.
8597 Return the length of the key sequence stored.
8598 Return -1 if the user rejected a command menu.
8600 Echo starting immediately unless `prompt' is 0.
8602 Where a key sequence ends depends on the currently active keymaps.
8603 These include any minor mode keymaps active in the current buffer,
8604 the current buffer's local map, and the global map.
8606 If a key sequence has no other bindings, we check Vfunction_key_map
8607 to see if some trailing subsequence might be the beginning of a
8608 function key's sequence. If so, we try to read the whole function
8609 key, and substitute its symbolic name into the key sequence.
8611 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
8612 `double-' events into similar click events, if that would make them
8613 bound. We try to turn `triple-' events first into `double-' events,
8616 If we get a mouse click in a mode line, vertical divider, or other
8617 non-text area, we treat the click as if it were prefixed by the
8618 symbol denoting that area - `mode-line', `vertical-line', or
8621 If the sequence starts with a mouse click, we read the key sequence
8622 with respect to the buffer clicked on, not the current buffer.
8624 If the user switches frames in the midst of a key sequence, we put
8625 off the switch-frame event until later; the next call to
8626 read_char will return it.
8628 If FIX_CURRENT_BUFFER is nonzero, we restore current_buffer
8629 from the selected window's buffer. */
8632 read_key_sequence (keybuf
, bufsize
, prompt
, dont_downcase_last
,
8633 can_return_switch_frame
, fix_current_buffer
)
8634 Lisp_Object
*keybuf
;
8637 int dont_downcase_last
;
8638 int can_return_switch_frame
;
8639 int fix_current_buffer
;
8641 volatile Lisp_Object from_string
;
8642 volatile int count
= SPECPDL_INDEX ();
8644 /* How many keys there are in the current key sequence. */
8647 /* The length of the echo buffer when we started reading, and
8648 the length of this_command_keys when we started reading. */
8649 volatile int echo_start
;
8650 volatile int keys_start
;
8652 /* The number of keymaps we're scanning right now, and the number of
8653 keymaps we have allocated space for. */
8655 volatile int nmaps_allocated
= 0;
8657 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
8658 the current keymaps. */
8659 Lisp_Object
*volatile defs
= NULL
;
8661 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
8662 in the current keymaps, or nil where it is not a prefix. */
8663 Lisp_Object
*volatile submaps
= NULL
;
8665 /* The local map to start out with at start of key sequence. */
8666 volatile Lisp_Object orig_local_map
;
8668 /* The map from the `keymap' property to start out with at start of
8670 volatile Lisp_Object orig_keymap
;
8672 /* 1 if we have already considered switching to the local-map property
8673 of the place where a mouse click occurred. */
8674 volatile int localized_local_map
= 0;
8676 /* The index in defs[] of the first keymap that has a binding for
8677 this key sequence. In other words, the lowest i such that
8678 defs[i] is non-nil. */
8679 volatile int first_binding
;
8680 /* Index of the first key that has no binding.
8681 It is useless to try fkey.start larger than that. */
8682 volatile int first_unbound
;
8684 /* If t < mock_input, then KEYBUF[t] should be read as the next
8687 We use this to recover after recognizing a function key. Once we
8688 realize that a suffix of the current key sequence is actually a
8689 function key's escape sequence, we replace the suffix with the
8690 function key's binding from Vfunction_key_map. Now keybuf
8691 contains a new and different key sequence, so the echo area,
8692 this_command_keys, and the submaps and defs arrays are wrong. In
8693 this situation, we set mock_input to t, set t to 0, and jump to
8694 restart_sequence; the loop will read keys from keybuf up until
8695 mock_input, thus rebuilding the state; and then it will resume
8696 reading characters from the keyboard. */
8697 volatile int mock_input
= 0;
8699 /* If the sequence is unbound in submaps[], then
8700 keybuf[fkey.start..fkey.end-1] is a prefix in Vfunction_key_map,
8701 and fkey.map is its binding.
8703 These might be > t, indicating that all function key scanning
8704 should hold off until t reaches them. We do this when we've just
8705 recognized a function key, to avoid searching for the function
8706 key's again in Vfunction_key_map. */
8707 volatile keyremap fkey
;
8709 /* Likewise, for key_translation_map. */
8710 volatile keyremap keytran
;
8712 /* If we receive a `switch-frame' or `select-window' event in the middle of
8713 a key sequence, we put it off for later.
8714 While we're reading, we keep the event here. */
8715 volatile Lisp_Object delayed_switch_frame
;
8717 /* See the comment below... */
8718 #if defined (GOBBLE_FIRST_EVENT)
8719 Lisp_Object first_event
;
8722 volatile Lisp_Object original_uppercase
;
8723 volatile int original_uppercase_position
= -1;
8725 /* Gets around Microsoft compiler limitations. */
8728 struct buffer
*starting_buffer
;
8730 /* List of events for which a fake prefix key has been generated. */
8731 volatile Lisp_Object fake_prefixed_keys
= Qnil
;
8733 #if defined (GOBBLE_FIRST_EVENT)
8737 struct gcpro gcpro1
;
8739 GCPRO1 (fake_prefixed_keys
);
8740 raw_keybuf_count
= 0;
8742 last_nonmenu_event
= Qnil
;
8744 delayed_switch_frame
= Qnil
;
8745 fkey
.map
= fkey
.parent
= current_kboard
->Vlocal_function_key_map
;
8746 keytran
.map
= keytran
.parent
= current_kboard
->Vlocal_key_translation_map
;
8747 /* If there is no translation-map, turn off scanning. */
8748 fkey
.start
= fkey
.end
= KEYMAPP (fkey
.map
) ? 0 : bufsize
+ 1;
8749 keytran
.start
= keytran
.end
= KEYMAPP (keytran
.map
) ? 0 : bufsize
+ 1;
8754 echo_prompt (prompt
);
8755 else if (cursor_in_echo_area
8756 && (FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
8757 && NILP (Fzerop (Vecho_keystrokes
)))
8758 /* This doesn't put in a dash if the echo buffer is empty, so
8759 you don't always see a dash hanging out in the minibuffer. */
8763 /* Record the initial state of the echo area and this_command_keys;
8764 we will need to restore them if we replay a key sequence. */
8766 echo_start
= echo_length ();
8767 keys_start
= this_command_key_count
;
8768 this_single_command_key_start
= keys_start
;
8770 #if defined (GOBBLE_FIRST_EVENT)
8771 /* This doesn't quite work, because some of the things that read_char
8772 does cannot safely be bypassed. It seems too risky to try to make
8775 /* Read the first char of the sequence specially, before setting
8776 up any keymaps, in case a filter runs and switches buffers on us. */
8777 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
8779 #endif /* GOBBLE_FIRST_EVENT */
8781 orig_local_map
= get_local_map (PT
, current_buffer
, Qlocal_map
);
8782 orig_keymap
= get_local_map (PT
, current_buffer
, Qkeymap
);
8785 /* We jump here when the key sequence has been thoroughly changed, and
8786 we need to rescan it starting from the beginning. When we jump here,
8787 keybuf[0..mock_input] holds the sequence we should reread. */
8790 starting_buffer
= current_buffer
;
8791 first_unbound
= bufsize
+ 1;
8793 /* Build our list of keymaps.
8794 If we recognize a function key and replace its escape sequence in
8795 keybuf with its symbol, or if the sequence starts with a mouse
8796 click and we need to switch buffers, we jump back here to rebuild
8797 the initial keymaps from the current buffer. */
8800 if (!NILP (current_kboard
->Voverriding_terminal_local_map
)
8801 || !NILP (Voverriding_local_map
))
8803 if (3 > nmaps_allocated
)
8805 submaps
= (Lisp_Object
*) alloca (3 * sizeof (submaps
[0]));
8806 defs
= (Lisp_Object
*) alloca (3 * sizeof (defs
[0]));
8807 nmaps_allocated
= 3;
8809 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
8810 submaps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
8811 if (!NILP (Voverriding_local_map
))
8812 submaps
[nmaps
++] = Voverriding_local_map
;
8820 nminor
= current_minor_maps (0, &maps
);
8821 total
= nminor
+ (!NILP (orig_keymap
) ? 3 : 2);
8823 if (total
> nmaps_allocated
)
8825 submaps
= (Lisp_Object
*) alloca (total
* sizeof (submaps
[0]));
8826 defs
= (Lisp_Object
*) alloca (total
* sizeof (defs
[0]));
8827 nmaps_allocated
= total
;
8830 if (!NILP (orig_keymap
))
8831 submaps
[nmaps
++] = orig_keymap
;
8833 bcopy (maps
, (void *) (submaps
+ nmaps
),
8834 nminor
* sizeof (submaps
[0]));
8838 submaps
[nmaps
++] = orig_local_map
;
8840 submaps
[nmaps
++] = current_global_map
;
8842 /* Find an accurate initial value for first_binding. */
8843 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
8844 if (! NILP (submaps
[first_binding
]))
8847 /* Start from the beginning in keybuf. */
8850 /* These are no-ops the first time through, but if we restart, they
8851 revert the echo area and this_command_keys to their original state. */
8852 this_command_key_count
= keys_start
;
8853 if (INTERACTIVE
&& t
< mock_input
)
8854 echo_truncate (echo_start
);
8856 /* If the best binding for the current key sequence is a keymap, or
8857 we may be looking at a function key's escape sequence, keep on
8859 while (first_binding
< nmaps
8860 /* Keep reading as long as there's a prefix binding. */
8861 ? !NILP (submaps
[first_binding
])
8862 /* Don't return in the middle of a possible function key sequence,
8863 if the only bindings we found were via case conversion.
8864 Thus, if ESC O a has a function-key-map translation
8865 and ESC o has a binding, don't return after ESC O,
8866 so that we can translate ESC O plus the next character. */
8867 : (fkey
.start
< t
|| keytran
.start
< t
))
8870 int used_mouse_menu
= 0;
8872 /* Where the last real key started. If we need to throw away a
8873 key that has expanded into more than one element of keybuf
8874 (say, a mouse click on the mode line which is being treated
8875 as [mode-line (mouse-...)], then we backtrack to this point
8877 volatile int last_real_key_start
;
8879 /* These variables are analogous to echo_start and keys_start;
8880 while those allow us to restart the entire key sequence,
8881 echo_local_start and keys_local_start allow us to throw away
8883 volatile int echo_local_start
, keys_local_start
, local_first_binding
;
8885 eassert (fkey
.end
== t
|| (fkey
.end
> t
&& fkey
.end
<= mock_input
));
8886 eassert (fkey
.start
<= fkey
.end
);
8887 eassert (keytran
.start
<= keytran
.end
);
8888 /* key-translation-map is applied *after* function-key-map. */
8889 eassert (keytran
.end
<= fkey
.start
);
8891 if (first_unbound
< fkey
.start
&& first_unbound
< keytran
.start
)
8892 { /* The prefix upto first_unbound has no binding and has
8893 no translation left to do either, so we know it's unbound.
8894 If we don't stop now, we risk staying here indefinitely
8895 (if the user keeps entering fkey or keytran prefixes
8896 like C-c ESC ESC ESC ESC ...) */
8898 for (i
= first_unbound
+ 1; i
< t
; i
++)
8899 keybuf
[i
- first_unbound
- 1] = keybuf
[i
];
8900 mock_input
= t
- first_unbound
- 1;
8901 fkey
.end
= fkey
.start
-= first_unbound
+ 1;
8902 fkey
.map
= fkey
.parent
;
8903 keytran
.end
= keytran
.start
-= first_unbound
+ 1;
8904 keytran
.map
= keytran
.parent
;
8905 goto replay_sequence
;
8909 error ("Key sequence too long");
8912 echo_local_start
= echo_length ();
8913 keys_local_start
= this_command_key_count
;
8914 local_first_binding
= first_binding
;
8917 /* These are no-ops, unless we throw away a keystroke below and
8918 jumped back up to replay_key; in that case, these restore the
8919 variables to their original state, allowing us to replay the
8921 if (INTERACTIVE
&& t
< mock_input
)
8922 echo_truncate (echo_local_start
);
8923 this_command_key_count
= keys_local_start
;
8924 first_binding
= local_first_binding
;
8926 /* By default, assume each event is "real". */
8927 last_real_key_start
= t
;
8929 /* Does mock_input indicate that we are re-reading a key sequence? */
8933 add_command_key (key
);
8934 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
8935 && NILP (Fzerop (Vecho_keystrokes
)))
8939 /* If not, we should actually read a character. */
8944 KBOARD
*interrupted_kboard
= current_kboard
;
8945 struct frame
*interrupted_frame
= SELECTED_FRAME ();
8946 if (setjmp (wrong_kboard_jmpbuf
))
8948 if (!NILP (delayed_switch_frame
))
8950 interrupted_kboard
->kbd_queue
8951 = Fcons (delayed_switch_frame
,
8952 interrupted_kboard
->kbd_queue
);
8953 delayed_switch_frame
= Qnil
;
8956 interrupted_kboard
->kbd_queue
8957 = Fcons (keybuf
[--t
], interrupted_kboard
->kbd_queue
);
8959 /* If the side queue is non-empty, ensure it begins with a
8960 switch-frame, so we'll replay it in the right context. */
8961 if (CONSP (interrupted_kboard
->kbd_queue
)
8962 && (key
= XCAR (interrupted_kboard
->kbd_queue
),
8963 !(EVENT_HAS_PARAMETERS (key
)
8964 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)),
8968 XSETFRAME (frame
, interrupted_frame
);
8969 interrupted_kboard
->kbd_queue
8970 = Fcons (make_lispy_switch_frame (frame
),
8971 interrupted_kboard
->kbd_queue
);
8974 orig_local_map
= get_local_map (PT
, current_buffer
, Qlocal_map
);
8975 orig_keymap
= get_local_map (PT
, current_buffer
, Qkeymap
);
8976 goto replay_sequence
;
8979 key
= read_char (NILP (prompt
), nmaps
,
8980 (Lisp_Object
*) submaps
, last_nonmenu_event
,
8984 /* read_char returns t when it shows a menu and the user rejects it.
8988 unbind_to (count
, Qnil
);
8993 /* read_char returns -1 at the end of a macro.
8994 Emacs 18 handles this by returning immediately with a
8995 zero, so that's what we'll do. */
8996 if (INTEGERP (key
) && XINT (key
) == -1)
8999 /* The Microsoft C compiler can't handle the goto that
9005 /* If the current buffer has been changed from under us, the
9006 keymap may have changed, so replay the sequence. */
9009 timer_resume_idle ();
9012 /* Reset the current buffer from the selected window
9013 in case something changed the former and not the latter.
9014 This is to be more consistent with the behavior
9015 of the command_loop_1. */
9016 if (fix_current_buffer
)
9018 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
9020 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
9021 Fset_buffer (XWINDOW (selected_window
)->buffer
);
9024 orig_local_map
= get_local_map (PT
, current_buffer
, Qlocal_map
);
9025 orig_keymap
= get_local_map (PT
, current_buffer
, Qkeymap
);
9026 goto replay_sequence
;
9029 /* If we have a quit that was typed in another frame, and
9030 quit_throw_to_read_char switched buffers,
9031 replay to get the right keymap. */
9033 && XINT (key
) == quit_char
9034 && current_buffer
!= starting_buffer
)
9037 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
9041 orig_local_map
= get_local_map (PT
, current_buffer
, Qlocal_map
);
9042 orig_keymap
= get_local_map (PT
, current_buffer
, Qkeymap
);
9043 goto replay_sequence
;
9048 if (EVENT_HAS_PARAMETERS (key
)
9049 /* Either a `switch-frame' or a `select-window' event. */
9050 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)), Qswitch_frame
))
9052 /* If we're at the beginning of a key sequence, and the caller
9053 says it's okay, go ahead and return this event. If we're
9054 in the midst of a key sequence, delay it until the end. */
9055 if (t
> 0 || !can_return_switch_frame
)
9057 delayed_switch_frame
= key
;
9063 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
9066 /* Clicks in non-text areas get prefixed by the symbol
9067 in their CHAR-ADDRESS field. For example, a click on
9068 the mode line is prefixed by the symbol `mode-line'.
9070 Furthermore, key sequences beginning with mouse clicks
9071 are read using the keymaps of the buffer clicked on, not
9072 the current buffer. So we may have to switch the buffer
9075 When we turn one event into two events, we must make sure
9076 that neither of the two looks like the original--so that,
9077 if we replay the events, they won't be expanded again.
9078 If not for this, such reexpansion could happen either here
9079 or when user programs play with this-command-keys. */
9080 if (EVENT_HAS_PARAMETERS (key
))
9085 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
9086 if (EQ (kind
, Qmouse_click
))
9088 Lisp_Object window
, posn
;
9090 window
= POSN_WINDOW (EVENT_START (key
));
9091 posn
= POSN_POSN (EVENT_START (key
));
9094 || (!NILP (fake_prefixed_keys
)
9095 && !NILP (Fmemq (key
, fake_prefixed_keys
))))
9097 /* We're looking a second time at an event for which
9098 we generated a fake prefix key. Set
9099 last_real_key_start appropriately. */
9101 last_real_key_start
= t
- 1;
9104 /* Key sequences beginning with mouse clicks are
9105 read using the keymaps in the buffer clicked on,
9106 not the current buffer. If we're at the
9107 beginning of a key sequence, switch buffers. */
9108 if (last_real_key_start
== 0
9110 && BUFFERP (XWINDOW (window
)->buffer
)
9111 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
9113 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
9117 /* Arrange to go back to the original buffer once we're
9118 done reading the key sequence. Note that we can't
9119 use save_excursion_{save,restore} here, because they
9120 save point as well as the current buffer; we don't
9121 want to save point, because redisplay may change it,
9122 to accommodate a Fset_window_start or something. We
9123 don't want to do this at the top of the function,
9124 because we may get input from a subprocess which
9125 wants to change the selected window and stuff (say,
9127 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
9129 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
9131 set_buffer_internal (XBUFFER (XWINDOW (window
)->buffer
));
9132 orig_local_map
= get_local_map (PT
, current_buffer
,
9134 orig_keymap
= get_local_map (PT
, current_buffer
, Qkeymap
);
9135 goto replay_sequence
;
9138 /* For a mouse click, get the local text-property keymap
9139 of the place clicked on, rather than point. */
9140 if (last_real_key_start
== 0
9141 && CONSP (XCDR (key
))
9142 && ! localized_local_map
)
9144 Lisp_Object map_here
, start
, pos
;
9146 localized_local_map
= 1;
9147 start
= EVENT_START (key
);
9149 if (CONSP (start
) && POSN_INBUFFER_P (start
))
9151 pos
= POSN_BUFFER_POSN (start
);
9153 && XINT (pos
) >= BEG
&& XINT (pos
) <= Z
)
9155 map_here
= get_local_map (XINT (pos
),
9156 current_buffer
, Qlocal_map
);
9157 if (!EQ (map_here
, orig_local_map
))
9159 orig_local_map
= map_here
;
9163 goto replay_sequence
;
9165 map_here
= get_local_map (XINT (pos
),
9166 current_buffer
, Qkeymap
);
9167 if (!EQ (map_here
, orig_keymap
))
9169 orig_keymap
= map_here
;
9173 goto replay_sequence
;
9179 /* Expand mode-line and scroll-bar events into two events:
9180 use posn as a fake prefix key. */
9182 && (NILP (fake_prefixed_keys
)
9183 || NILP (Fmemq (key
, fake_prefixed_keys
))))
9185 if (t
+ 1 >= bufsize
)
9186 error ("Key sequence too long");
9189 keybuf
[t
+ 1] = key
;
9192 /* Record that a fake prefix key has been generated
9193 for KEY. Don't modify the event; this would
9194 prevent proper action when the event is pushed
9195 back into unread-command-events. */
9196 fake_prefixed_keys
= Fcons (key
, fake_prefixed_keys
);
9198 /* If on a mode line string with a local keymap,
9199 reconsider the key sequence with that keymap. */
9200 if (string
= POSN_STRING (EVENT_START (key
)),
9201 (CONSP (string
) && STRINGP (XCAR (string
))))
9203 Lisp_Object pos
, map
, map2
;
9205 pos
= XCDR (string
);
9206 string
= XCAR (string
);
9208 && XINT (pos
) < SCHARS (string
))
9210 map
= Fget_text_property (pos
, Qlocal_map
, string
);
9212 orig_local_map
= map
;
9213 map2
= Fget_text_property (pos
, Qkeymap
, string
);
9216 if (!NILP (map
) || !NILP (map2
))
9217 goto replay_sequence
;
9223 else if (NILP (from_string
)
9224 && (string
= POSN_STRING (EVENT_START (key
)),
9225 (CONSP (string
) && STRINGP (XCAR (string
)))))
9227 /* For a click on a string, i.e. overlay string or a
9228 string displayed via the `display' property,
9229 consider `local-map' and `keymap' properties of
9231 Lisp_Object pos
, map
, map2
;
9233 pos
= XCDR (string
);
9234 string
= XCAR (string
);
9236 && XINT (pos
) < SCHARS (string
))
9238 map
= Fget_text_property (pos
, Qlocal_map
, string
);
9240 orig_local_map
= map
;
9241 map2
= Fget_text_property (pos
, Qkeymap
, string
);
9245 if (!NILP (map
) || !NILP (map2
))
9247 from_string
= string
;
9248 goto replay_sequence
;
9253 else if (CONSP (XCDR (key
))
9254 && CONSP (EVENT_START (key
))
9255 && CONSP (XCDR (EVENT_START (key
))))
9259 posn
= POSN_POSN (EVENT_START (key
));
9260 /* Handle menu-bar events:
9261 insert the dummy prefix event `menu-bar'. */
9262 if (EQ (posn
, Qmenu_bar
) || EQ (posn
, Qtool_bar
))
9264 if (t
+ 1 >= bufsize
)
9265 error ("Key sequence too long");
9269 /* Zap the position in key, so we know that we've
9270 expanded it, and don't try to do so again. */
9271 POSN_SET_POSN (EVENT_START (key
),
9272 Fcons (posn
, Qnil
));
9275 goto replay_sequence
;
9277 else if (CONSP (posn
))
9279 /* We're looking at the second event of a
9280 sequence which we expanded before. Set
9281 last_real_key_start appropriately. */
9282 if (last_real_key_start
== t
&& t
> 0)
9283 last_real_key_start
= t
- 1;
9288 /* We have finally decided that KEY is something we might want
9290 first_binding
= (follow_key (key
,
9291 nmaps
- first_binding
,
9292 submaps
+ first_binding
,
9293 defs
+ first_binding
,
9294 submaps
+ first_binding
)
9297 /* If KEY wasn't bound, we'll try some fallbacks. */
9298 if (first_binding
< nmaps
)
9299 /* This is needed for the following scenario:
9300 event 0: a down-event that gets dropped by calling replay_key.
9301 event 1: some normal prefix like C-h.
9302 After event 0, first_unbound is 0, after event 1 fkey.start
9303 and keytran.start are both 1, so when we see that C-h is bound,
9304 we need to update first_unbound. */
9305 first_unbound
= max (t
+ 1, first_unbound
);
9310 /* Remember the position to put an upper bound on fkey.start. */
9311 first_unbound
= min (t
, first_unbound
);
9313 head
= EVENT_HEAD (key
);
9314 if (help_char_p (head
) && t
> 0)
9316 read_key_sequence_cmd
= Vprefix_help_command
;
9318 last_nonmenu_event
= key
;
9319 /* The Microsoft C compiler can't handle the goto that
9327 Lisp_Object breakdown
;
9330 breakdown
= parse_modifiers (head
);
9331 modifiers
= XINT (XCAR (XCDR (breakdown
)));
9332 /* Attempt to reduce an unbound mouse event to a simpler
9333 event that is bound:
9334 Drags reduce to clicks.
9335 Double-clicks reduce to clicks.
9336 Triple-clicks reduce to double-clicks, then to clicks.
9337 Down-clicks are eliminated.
9338 Double-downs reduce to downs, then are eliminated.
9339 Triple-downs reduce to double-downs, then to downs,
9340 then are eliminated. */
9341 if (modifiers
& (down_modifier
| drag_modifier
9342 | double_modifier
| triple_modifier
))
9344 while (modifiers
& (down_modifier
| drag_modifier
9345 | double_modifier
| triple_modifier
))
9347 Lisp_Object new_head
, new_click
;
9348 if (modifiers
& triple_modifier
)
9349 modifiers
^= (double_modifier
| triple_modifier
);
9350 else if (modifiers
& double_modifier
)
9351 modifiers
&= ~double_modifier
;
9352 else if (modifiers
& drag_modifier
)
9353 modifiers
&= ~drag_modifier
;
9356 /* Dispose of this `down' event by simply jumping
9357 back to replay_key, to get another event.
9359 Note that if this event came from mock input,
9360 then just jumping back to replay_key will just
9361 hand it to us again. So we have to wipe out any
9364 We could delete keybuf[t] and shift everything
9365 after that to the left by one spot, but we'd also
9366 have to fix up any variable that points into
9367 keybuf, and shifting isn't really necessary
9370 Adding prefixes for non-textual mouse clicks
9371 creates two characters of mock input, and both
9372 must be thrown away. If we're only looking at
9373 the prefix now, we can just jump back to
9374 replay_key. On the other hand, if we've already
9375 processed the prefix, and now the actual click
9376 itself is giving us trouble, then we've lost the
9377 state of the keymaps we want to backtrack to, and
9378 we need to replay the whole sequence to rebuild
9381 Beyond that, only function key expansion could
9382 create more than two keys, but that should never
9383 generate mouse events, so it's okay to zero
9384 mock_input in that case too.
9386 FIXME: The above paragraph seems just plain
9387 wrong, if you consider things like
9388 xterm-mouse-mode. -stef
9390 Isn't this just the most wonderful code ever? */
9392 /* If mock_input > t + 1, the above simplification
9393 will actually end up dropping keys on the floor.
9394 This is probably OK for now, but even
9395 if mock_input <= t + 1, we need to adjust fkey
9397 Typical case [header-line down-mouse-N]:
9398 mock_input = 2, t = 1, fkey.end = 1,
9399 last_real_key_start = 0. */
9400 if (fkey
.end
> last_real_key_start
)
9402 fkey
.end
= fkey
.start
9403 = min (last_real_key_start
, fkey
.start
);
9404 fkey
.map
= fkey
.parent
;
9405 if (keytran
.end
> last_real_key_start
)
9407 keytran
.end
= keytran
.start
9408 = min (last_real_key_start
, keytran
.start
);
9409 keytran
.map
= keytran
.parent
;
9412 if (t
== last_real_key_start
)
9419 mock_input
= last_real_key_start
;
9420 goto replay_sequence
;
9425 = apply_modifiers (modifiers
, XCAR (breakdown
));
9427 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
9429 /* Look for a binding for this new key. follow_key
9430 promises that it didn't munge submaps the
9431 last time we called it, since key was unbound. */
9433 = (follow_key (new_click
,
9434 nmaps
- local_first_binding
,
9435 submaps
+ local_first_binding
,
9436 defs
+ local_first_binding
,
9437 submaps
+ local_first_binding
)
9438 + local_first_binding
);
9440 /* If that click is bound, go for it. */
9441 if (first_binding
< nmaps
)
9446 /* Otherwise, we'll leave key set to the drag event. */
9453 /* Normally, last_nonmenu_event gets the previous key we read.
9454 But when a mouse popup menu is being used,
9455 we don't update last_nonmenu_event; it continues to hold the mouse
9456 event that preceded the first level of menu. */
9457 if (!used_mouse_menu
)
9458 last_nonmenu_event
= key
;
9460 /* Record what part of this_command_keys is the current key sequence. */
9461 this_single_command_key_start
= this_command_key_count
- t
;
9463 if (first_binding
< nmaps
&& NILP (submaps
[first_binding
]))
9464 /* There is a binding and it's not a prefix.
9465 There is thus no function-key in this sequence.
9466 Moving fkey.start is important in this case to allow keytran.start
9467 to go over the sequence before we return (since we keep the
9468 invariant that keytran.end <= fkey.start). */
9471 (fkey
.start
= fkey
.end
= t
, fkey
.map
= fkey
.parent
);
9474 /* If the sequence is unbound, see if we can hang a function key
9475 off the end of it. */
9476 /* Continue scan from fkey.end until we find a bound suffix. */
9477 while (fkey
.end
< t
)
9479 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9482 GCPRO3 (fkey
.map
, keytran
.map
, delayed_switch_frame
);
9483 done
= keyremap_step (keybuf
, bufsize
, &fkey
,
9484 max (t
, mock_input
),
9485 /* If there's a binding (i.e.
9486 first_binding >= nmaps) we don't want
9487 to apply this function-key-mapping. */
9488 fkey
.end
+ 1 == t
&& first_binding
>= nmaps
,
9493 mock_input
= diff
+ max (t
, mock_input
);
9494 goto replay_sequence
;
9498 /* Look for this sequence in key-translation-map.
9499 Scan from keytran.end until we find a bound suffix. */
9500 while (keytran
.end
< fkey
.start
)
9502 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9505 GCPRO3 (fkey
.map
, keytran
.map
, delayed_switch_frame
);
9506 done
= keyremap_step (keybuf
, bufsize
, &keytran
, max (t
, mock_input
),
9511 mock_input
= diff
+ max (t
, mock_input
);
9512 /* Adjust the function-key-map counters. */
9516 goto replay_sequence
;
9520 /* If KEY is not defined in any of the keymaps,
9521 and cannot be part of a function key or translation,
9522 and is an upper case letter
9523 use the corresponding lower-case letter instead. */
9524 if (first_binding
>= nmaps
9525 && fkey
.start
>= t
&& keytran
.start
>= t
9527 && ((((XINT (key
) & 0x3ffff)
9528 < XCHAR_TABLE (current_buffer
->downcase_table
)->size
)
9529 && UPPERCASEP (XINT (key
) & 0x3ffff))
9530 || (XINT (key
) & shift_modifier
)))
9532 Lisp_Object new_key
;
9534 original_uppercase
= key
;
9535 original_uppercase_position
= t
- 1;
9537 if (XINT (key
) & shift_modifier
)
9538 XSETINT (new_key
, XINT (key
) & ~shift_modifier
);
9540 XSETINT (new_key
, (DOWNCASE (XINT (key
) & 0x3ffff)
9541 | (XINT (key
) & ~0x3ffff)));
9543 /* We have to do this unconditionally, regardless of whether
9544 the lower-case char is defined in the keymaps, because they
9545 might get translated through function-key-map. */
9546 keybuf
[t
- 1] = new_key
;
9547 mock_input
= max (t
, mock_input
);
9549 goto replay_sequence
;
9551 /* If KEY is not defined in any of the keymaps,
9552 and cannot be part of a function key or translation,
9553 and is a shifted function key,
9554 use the corresponding unshifted function key instead. */
9555 if (first_binding
>= nmaps
9556 && fkey
.start
>= t
&& keytran
.start
>= t
9559 Lisp_Object breakdown
;
9562 breakdown
= parse_modifiers (key
);
9563 modifiers
= XINT (XCAR (XCDR (breakdown
)));
9564 if (modifiers
& shift_modifier
)
9566 Lisp_Object new_key
;
9568 original_uppercase
= key
;
9569 original_uppercase_position
= t
- 1;
9571 modifiers
&= ~shift_modifier
;
9572 new_key
= apply_modifiers (modifiers
,
9575 keybuf
[t
- 1] = new_key
;
9576 mock_input
= max (t
, mock_input
);
9577 fkey
.start
= fkey
.end
= KEYMAPP (fkey
.map
) ? 0 : bufsize
+ 1;
9578 keytran
.start
= keytran
.end
= KEYMAPP (keytran
.map
) ? 0 : bufsize
+ 1;
9580 goto replay_sequence
;
9586 read_key_sequence_cmd
= (first_binding
< nmaps
9587 ? defs
[first_binding
]
9590 unread_switch_frame
= delayed_switch_frame
;
9591 unbind_to (count
, Qnil
);
9593 /* Don't downcase the last character if the caller says don't.
9594 Don't downcase it if the result is undefined, either. */
9595 if ((dont_downcase_last
|| first_binding
>= nmaps
)
9596 && t
- 1 == original_uppercase_position
)
9597 keybuf
[t
- 1] = original_uppercase
;
9599 /* Occasionally we fabricate events, perhaps by expanding something
9600 according to function-key-map, or by adding a prefix symbol to a
9601 mouse click in the scroll bar or modeline. In this cases, return
9602 the entire generated key sequence, even if we hit an unbound
9603 prefix or a definition before the end. This means that you will
9604 be able to push back the event properly, and also means that
9605 read-key-sequence will always return a logical unit.
9608 for (; t
< mock_input
; t
++)
9610 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
9611 && NILP (Fzerop (Vecho_keystrokes
)))
9612 echo_char (keybuf
[t
]);
9613 add_command_key (keybuf
[t
]);
9622 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 5, 0,
9623 doc
: /* Read a sequence of keystrokes and return as a string or vector.
9624 The sequence is sufficient to specify a non-prefix command in the
9625 current local and global maps.
9627 First arg PROMPT is a prompt string. If nil, do not prompt specially.
9628 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos
9629 as a continuation of the previous key.
9631 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not
9632 convert the last event to lower case. (Normally any upper case event
9633 is converted to lower case if the original event is undefined and the lower
9634 case equivalent is defined.) A non-nil value is appropriate for reading
9635 a key sequence to be defined.
9637 A C-g typed while in this function is treated like any other character,
9638 and `quit-flag' is not set.
9640 If the key sequence starts with a mouse click, then the sequence is read
9641 using the keymaps of the buffer of the window clicked in, not the buffer
9642 of the selected window as normal.
9644 `read-key-sequence' drops unbound button-down events, since you normally
9645 only care about the click or drag events which follow them. If a drag
9646 or multi-click event is unbound, but the corresponding click event would
9647 be bound, `read-key-sequence' turns the event into a click event at the
9648 drag's starting position. This means that you don't have to distinguish
9649 between click and drag, double, or triple events unless you want to.
9651 `read-key-sequence' prefixes mouse events on mode lines, the vertical
9652 lines separating windows, and scroll bars with imaginary keys
9653 `mode-line', `vertical-line', and `vertical-scroll-bar'.
9655 Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this
9656 function will process a switch-frame event if the user switches frames
9657 before typing anything. If the user switches frames in the middle of a
9658 key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME
9659 is nil, then the event will be put off until after the current key sequence.
9661 `read-key-sequence' checks `function-key-map' for function key
9662 sequences, where they wouldn't conflict with ordinary bindings. See
9663 `function-key-map' for more details.
9665 The optional fifth argument COMMAND-LOOP, if non-nil, means
9666 that this key sequence is being read by something that will
9667 read commands one after another. It should be nil if the caller
9668 will read just one key sequence. */)
9669 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
9671 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
9672 Lisp_Object can_return_switch_frame
, command_loop
;
9674 Lisp_Object keybuf
[30];
9676 struct gcpro gcpro1
;
9677 int count
= SPECPDL_INDEX ();
9680 CHECK_STRING (prompt
);
9683 specbind (Qinput_method_exit_on_first_char
,
9684 (NILP (command_loop
) ? Qt
: Qnil
));
9685 specbind (Qinput_method_use_echo_area
,
9686 (NILP (command_loop
) ? Qt
: Qnil
));
9688 bzero (keybuf
, sizeof keybuf
);
9690 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
9692 if (NILP (continue_echo
))
9694 this_command_key_count
= 0;
9695 this_command_key_count_reset
= 0;
9696 this_single_command_key_start
= 0;
9699 #ifdef HAVE_X_WINDOWS
9700 if (display_hourglass_p
)
9701 cancel_hourglass ();
9704 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
9705 prompt
, ! NILP (dont_downcase_last
),
9706 ! NILP (can_return_switch_frame
), 0);
9708 #if 0 /* The following is fine for code reading a key sequence and
9709 then proceeding with a lenghty computation, but it's not good
9710 for code reading keys in a loop, like an input method. */
9711 #ifdef HAVE_X_WINDOWS
9712 if (display_hourglass_p
)
9723 return unbind_to (count
, make_event_array (i
, keybuf
));
9726 DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector
,
9727 Sread_key_sequence_vector
, 1, 5, 0,
9728 doc
: /* Like `read-key-sequence' but always return a vector. */)
9729 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
9731 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
9732 Lisp_Object can_return_switch_frame
, command_loop
;
9734 Lisp_Object keybuf
[30];
9736 struct gcpro gcpro1
;
9737 int count
= SPECPDL_INDEX ();
9740 CHECK_STRING (prompt
);
9743 specbind (Qinput_method_exit_on_first_char
,
9744 (NILP (command_loop
) ? Qt
: Qnil
));
9745 specbind (Qinput_method_use_echo_area
,
9746 (NILP (command_loop
) ? Qt
: Qnil
));
9748 bzero (keybuf
, sizeof keybuf
);
9750 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
9752 if (NILP (continue_echo
))
9754 this_command_key_count
= 0;
9755 this_command_key_count_reset
= 0;
9756 this_single_command_key_start
= 0;
9759 #ifdef HAVE_X_WINDOWS
9760 if (display_hourglass_p
)
9761 cancel_hourglass ();
9764 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
9765 prompt
, ! NILP (dont_downcase_last
),
9766 ! NILP (can_return_switch_frame
), 0);
9768 #ifdef HAVE_X_WINDOWS
9769 if (display_hourglass_p
)
9779 return unbind_to (count
, Fvector (i
, keybuf
));
9782 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 4, 0,
9783 doc
: /* Execute CMD as an editor command.
9784 CMD must be a symbol that satisfies the `commandp' predicate.
9785 Optional second arg RECORD-FLAG non-nil
9786 means unconditionally put this command in `command-history'.
9787 Otherwise, that is done only if an arg is read using the minibuffer.
9788 The argument KEYS specifies the value to use instead of (this-command-keys)
9789 when reading the arguments; if it is nil, (this-command-keys) is used.
9790 The argument SPECIAL, if non-nil, means that this command is executing
9791 a special event, so ignore the prefix argument and don't clear it. */)
9792 (cmd
, record_flag
, keys
, special
)
9793 Lisp_Object cmd
, record_flag
, keys
, special
;
9795 register Lisp_Object final
;
9796 register Lisp_Object tem
;
9797 Lisp_Object prefixarg
;
9798 struct backtrace backtrace
;
9799 extern int debug_on_next_call
;
9801 debug_on_next_call
= 0;
9805 prefixarg
= current_kboard
->Vprefix_arg
;
9806 Vcurrent_prefix_arg
= prefixarg
;
9807 current_kboard
->Vprefix_arg
= Qnil
;
9814 tem
= Fget (cmd
, Qdisabled
);
9815 if (!NILP (tem
) && !NILP (Vrun_hooks
))
9817 tem
= Fsymbol_value (Qdisabled_command_function
);
9819 return call1 (Vrun_hooks
, Qdisabled_command_function
);
9825 final
= Findirect_function (cmd
);
9827 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
9829 struct gcpro gcpro1
, gcpro2
;
9831 GCPRO2 (cmd
, prefixarg
);
9832 do_autoload (final
, cmd
);
9839 if (STRINGP (final
) || VECTORP (final
))
9841 /* If requested, place the macro in the command history. For
9842 other sorts of commands, call-interactively takes care of
9844 if (!NILP (record_flag
))
9847 = Fcons (Fcons (Qexecute_kbd_macro
,
9848 Fcons (final
, Fcons (prefixarg
, Qnil
))),
9851 /* Don't keep command history around forever. */
9852 if (NUMBERP (Vhistory_length
) && XINT (Vhistory_length
) > 0)
9854 tem
= Fnthcdr (Vhistory_length
, Vcommand_history
);
9856 XSETCDR (tem
, Qnil
);
9860 return Fexecute_kbd_macro (final
, prefixarg
, Qnil
);
9863 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
9865 backtrace
.next
= backtrace_list
;
9866 backtrace_list
= &backtrace
;
9867 backtrace
.function
= &Qcall_interactively
;
9868 backtrace
.args
= &cmd
;
9869 backtrace
.nargs
= 1;
9870 backtrace
.evalargs
= 0;
9871 backtrace
.debug_on_exit
= 0;
9873 tem
= Fcall_interactively (cmd
, record_flag
, keys
);
9875 backtrace_list
= backtrace
.next
;
9883 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
9885 doc
: /* Read function name, then read its arguments and call it. */)
9887 Lisp_Object prefixarg
;
9889 Lisp_Object function
;
9891 int saved_last_point_position
;
9892 Lisp_Object saved_keys
, saved_last_point_position_buffer
;
9893 Lisp_Object bindings
, value
;
9894 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9895 #ifdef HAVE_X_WINDOWS
9896 /* The call to Fcompleting_read wil start and cancel the hourglass,
9897 but if the hourglass was already scheduled, this means that no
9898 hourglass will be shown for the actual M-x command itself.
9899 So we restart it if it is already scheduled. Note that checking
9900 hourglass_shown_p is not enough, normally the hourglass is not shown,
9901 just scheduled to be shown. */
9902 int hstarted
= hourglass_started ();
9905 saved_keys
= Fvector (this_command_key_count
,
9906 XVECTOR (this_command_keys
)->contents
);
9907 saved_last_point_position_buffer
= last_point_position_buffer
;
9908 saved_last_point_position
= last_point_position
;
9910 GCPRO3 (saved_keys
, prefixarg
, saved_last_point_position_buffer
);
9912 if (EQ (prefixarg
, Qminus
))
9914 else if (CONSP (prefixarg
) && XINT (XCAR (prefixarg
)) == 4)
9915 strcpy (buf
, "C-u ");
9916 else if (CONSP (prefixarg
) && INTEGERP (XCAR (prefixarg
)))
9917 sprintf (buf
, "%ld ", (long) XINT (XCAR (prefixarg
)));
9918 else if (INTEGERP (prefixarg
))
9919 sprintf (buf
, "%ld ", (long) XINT (prefixarg
));
9921 /* This isn't strictly correct if execute-extended-command
9922 is bound to anything else. Perhaps it should use
9923 this_command_keys? */
9924 strcat (buf
, "M-x ");
9926 /* Prompt with buf, and then read a string, completing from and
9927 restricting to the set of all defined commands. Don't provide
9928 any initial input. Save the command read on the extended-command
9930 function
= Fcompleting_read (build_string (buf
),
9931 Vobarray
, Qcommandp
,
9932 Qt
, Qnil
, Qextended_command_history
, Qnil
,
9935 #ifdef HAVE_X_WINDOWS
9936 if (hstarted
) start_hourglass ();
9939 if (STRINGP (function
) && SCHARS (function
) == 0)
9940 error ("No command name given");
9942 /* Set this_command_keys to the concatenation of saved_keys and
9943 function, followed by a RET. */
9948 this_command_key_count
= 0;
9949 this_command_key_count_reset
= 0;
9950 this_single_command_key_start
= 0;
9952 keys
= XVECTOR (saved_keys
)->contents
;
9953 for (i
= 0; i
< XVECTOR (saved_keys
)->size
; i
++)
9954 add_command_key (keys
[i
]);
9956 for (i
= 0; i
< SCHARS (function
); i
++)
9957 add_command_key (Faref (function
, make_number (i
)));
9959 add_command_key (make_number ('\015'));
9962 last_point_position
= saved_last_point_position
;
9963 last_point_position_buffer
= saved_last_point_position_buffer
;
9967 function
= Fintern (function
, Qnil
);
9968 current_kboard
->Vprefix_arg
= prefixarg
;
9969 Vthis_command
= function
;
9970 real_this_command
= function
;
9972 /* If enabled, show which key runs this command. */
9973 if (!NILP (Vsuggest_key_bindings
)
9974 && NILP (Vexecuting_kbd_macro
)
9975 && SYMBOLP (function
))
9976 bindings
= Fwhere_is_internal (function
, Voverriding_local_map
,
9982 GCPRO2 (bindings
, value
);
9983 value
= Fcommand_execute (function
, Qt
, Qnil
, Qnil
);
9985 /* If the command has a key binding, print it now. */
9986 if (!NILP (bindings
)
9987 && ! (VECTORP (bindings
) && EQ (Faref (bindings
, make_number (0)),
9990 /* But first wait, and skip the message if there is input. */
9992 if (!NILP (echo_area_buffer
[0]))
9993 /* This command displayed something in the echo area;
9994 so wait a few seconds, then display our suggestion message. */
9995 delay_time
= (NUMBERP (Vsuggest_key_bindings
)
9996 ? XINT (Vsuggest_key_bindings
) : 2);
9998 /* This command left the echo area empty,
9999 so display our message immediately. */
10002 if (!NILP (Fsit_for (make_number (delay_time
), Qnil
, Qnil
))
10003 && ! CONSP (Vunread_command_events
))
10005 Lisp_Object binding
;
10007 int message_p
= push_message ();
10008 int count
= SPECPDL_INDEX ();
10010 record_unwind_protect (pop_message_unwind
, Qnil
);
10011 binding
= Fkey_description (bindings
, Qnil
);
10014 = (char *) alloca (SCHARS (SYMBOL_NAME (function
))
10017 sprintf (newmessage
, "You can run the command `%s' with %s",
10018 SDATA (SYMBOL_NAME (function
)),
10020 message2_nolog (newmessage
,
10021 strlen (newmessage
),
10022 STRING_MULTIBYTE (binding
));
10023 if (!NILP (Fsit_for ((NUMBERP (Vsuggest_key_bindings
)
10024 ? Vsuggest_key_bindings
: make_number (2)),
10027 restore_message ();
10029 unbind_to (count
, Qnil
);
10033 RETURN_UNGCPRO (value
);
10037 /* Return nonzero if input events are pending. */
10040 detect_input_pending ()
10042 if (!input_pending
)
10043 get_input_pending (&input_pending
, 0);
10045 return input_pending
;
10048 /* Return nonzero if input events other than mouse movements are
10052 detect_input_pending_ignore_squeezables ()
10054 if (!input_pending
)
10055 get_input_pending (&input_pending
, READABLE_EVENTS_IGNORE_SQUEEZABLES
);
10057 return input_pending
;
10060 /* Return nonzero if input events are pending, and run any pending timers. */
10063 detect_input_pending_run_timers (do_display
)
10066 int old_timers_run
= timers_run
;
10068 if (!input_pending
)
10069 get_input_pending (&input_pending
, READABLE_EVENTS_DO_TIMERS_NOW
);
10071 if (old_timers_run
!= timers_run
&& do_display
)
10073 redisplay_preserve_echo_area (8);
10074 /* The following fixes a bug when using lazy-lock with
10075 lazy-lock-defer-on-the-fly set to t, i.e. when fontifying
10076 from an idle timer function. The symptom of the bug is that
10077 the cursor sometimes doesn't become visible until the next X
10078 event is processed. --gerd. */
10080 Lisp_Object tail
, frame
;
10081 FOR_EACH_FRAME (tail
, frame
)
10082 if (FRAME_RIF (XFRAME (frame
)))
10083 FRAME_RIF (XFRAME (frame
))->flush_display (XFRAME (frame
));
10087 return input_pending
;
10090 /* This is called in some cases before a possible quit.
10091 It cases the next call to detect_input_pending to recompute input_pending.
10092 So calling this function unnecessarily can't do any harm. */
10095 clear_input_pending ()
10100 /* Return nonzero if there are pending requeued events.
10101 This isn't used yet. The hope is to make wait_reading_process_output
10102 call it, and return if it runs Lisp code that unreads something.
10103 The problem is, kbd_buffer_get_event needs to be fixed to know what
10104 to do in that case. It isn't trivial. */
10107 requeued_events_pending_p ()
10109 return (!NILP (Vunread_command_events
) || unread_command_char
!= -1);
10113 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
10114 doc
: /* Return t if command input is currently available with no wait.
10115 Actually, the value is nil only if we can be sure that no input is available;
10116 if there is a doubt, the value is t. */)
10119 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1)
10122 get_input_pending (&input_pending
,
10123 READABLE_EVENTS_DO_TIMERS_NOW
10124 | READABLE_EVENTS_FILTER_EVENTS
);
10125 return input_pending
> 0 ? Qt
: Qnil
;
10128 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
10129 doc
: /* Return vector of last 100 events, not counting those from keyboard macros. */)
10132 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
10135 if (total_keys
< NUM_RECENT_KEYS
)
10136 return Fvector (total_keys
, keys
);
10139 val
= Fvector (NUM_RECENT_KEYS
, keys
);
10140 bcopy (keys
+ recent_keys_index
,
10141 XVECTOR (val
)->contents
,
10142 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
10144 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
10145 recent_keys_index
* sizeof (Lisp_Object
));
10150 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
10151 doc
: /* Return the key sequence that invoked this command.
10152 However, if the command has called `read-key-sequence', it returns
10153 the last key sequence that has been read.
10154 The value is a string or a vector. */)
10157 return make_event_array (this_command_key_count
,
10158 XVECTOR (this_command_keys
)->contents
);
10161 DEFUN ("this-command-keys-vector", Fthis_command_keys_vector
, Sthis_command_keys_vector
, 0, 0, 0,
10162 doc
: /* Return the key sequence that invoked this command, as a vector.
10163 However, if the command has called `read-key-sequence', it returns
10164 the last key sequence that has been read. */)
10167 return Fvector (this_command_key_count
,
10168 XVECTOR (this_command_keys
)->contents
);
10171 DEFUN ("this-single-command-keys", Fthis_single_command_keys
,
10172 Sthis_single_command_keys
, 0, 0, 0,
10173 doc
: /* Return the key sequence that invoked this command.
10174 More generally, it returns the last key sequence read, either by
10175 the command loop or by `read-key-sequence'.
10176 Unlike `this-command-keys', this function's value
10177 does not include prefix arguments.
10178 The value is always a vector. */)
10181 return Fvector (this_command_key_count
10182 - this_single_command_key_start
,
10183 (XVECTOR (this_command_keys
)->contents
10184 + this_single_command_key_start
));
10187 DEFUN ("this-single-command-raw-keys", Fthis_single_command_raw_keys
,
10188 Sthis_single_command_raw_keys
, 0, 0, 0,
10189 doc
: /* Return the raw events that were read for this command.
10190 More generally, it returns the last key sequence read, either by
10191 the command loop or by `read-key-sequence'.
10192 Unlike `this-single-command-keys', this function's value
10193 shows the events before all translations (except for input methods).
10194 The value is always a vector. */)
10197 return Fvector (raw_keybuf_count
,
10198 (XVECTOR (raw_keybuf
)->contents
));
10201 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths
,
10202 Sreset_this_command_lengths
, 0, 0, 0,
10203 doc
: /* Make the unread events replace the last command and echo.
10204 Used in `universal-argument-other-key'.
10206 `universal-argument-other-key' rereads the event just typed.
10207 It then gets translated through `function-key-map'.
10208 The translated event has to replace the real events,
10209 both in the value of (this-command-keys) and in echoing.
10210 To achieve this, `universal-argument-other-key' calls
10211 `reset-this-command-lengths', which discards the record of reading
10212 these events the first time. */)
10215 this_command_key_count
= before_command_key_count
;
10216 if (this_command_key_count
< this_single_command_key_start
)
10217 this_single_command_key_start
= this_command_key_count
;
10219 echo_truncate (before_command_echo_length
);
10221 /* Cause whatever we put into unread-command-events
10222 to echo as if it were being freshly read from the keyboard. */
10223 this_command_key_count_reset
= 1;
10228 DEFUN ("clear-this-command-keys", Fclear_this_command_keys
,
10229 Sclear_this_command_keys
, 0, 1, 0,
10230 doc
: /* Clear out the vector that `this-command-keys' returns.
10231 Also clear the record of the last 100 events, unless optional arg
10232 KEEP-RECORD is non-nil. */)
10234 Lisp_Object keep_record
;
10238 this_command_key_count
= 0;
10239 this_command_key_count_reset
= 0;
10241 if (NILP (keep_record
))
10243 for (i
= 0; i
< XVECTOR (recent_keys
)->size
; ++i
)
10244 XVECTOR (recent_keys
)->contents
[i
] = Qnil
;
10246 recent_keys_index
= 0;
10251 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
10252 doc
: /* Return the current depth in recursive edits. */)
10256 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
10260 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
10261 "FOpen dribble file: ",
10262 doc
: /* Start writing all keyboard characters to a dribble file called FILE.
10263 If FILE is nil, close any open dribble file. */)
10274 file
= Fexpand_file_name (file
, Qnil
);
10275 dribble
= fopen (SDATA (file
), "w");
10277 report_file_error ("Opening dribble", Fcons (file
, Qnil
));
10282 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
10283 doc
: /* Discard the contents of the terminal input buffer.
10284 Also end any kbd macro being defined. */)
10287 if (!NILP (current_kboard
->defining_kbd_macro
))
10289 /* Discard the last command from the macro. */
10290 Fcancel_kbd_macro_events ();
10294 update_mode_lines
++;
10296 Vunread_command_events
= Qnil
;
10297 unread_command_char
= -1;
10299 discard_tty_input ();
10301 kbd_fetch_ptr
= kbd_store_ptr
;
10307 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
10308 doc
: /* Stop Emacs and return to superior process. You can resume later.
10309 If `cannot-suspend' is non-nil, or if the system doesn't support job
10310 control, run a subshell instead.
10312 If optional arg STUFFSTRING is non-nil, its characters are stuffed
10313 to be read as terminal input by Emacs's parent, after suspension.
10315 Before suspending, run the normal hook `suspend-hook'.
10316 After resumption run the normal hook `suspend-resume-hook'.
10318 Some operating systems cannot stop the Emacs process and resume it later.
10319 On such systems, Emacs starts a subshell instead of suspending. */)
10321 Lisp_Object stuffstring
;
10323 int count
= SPECPDL_INDEX ();
10324 int old_height
, old_width
;
10326 struct gcpro gcpro1
;
10328 if (tty_list
&& tty_list
->next
)
10329 error ("There are other tty frames open; close them before suspending Emacs");
10331 if (!NILP (stuffstring
))
10332 CHECK_STRING (stuffstring
);
10334 /* Run the functions in suspend-hook. */
10335 if (!NILP (Vrun_hooks
))
10336 call1 (Vrun_hooks
, intern ("suspend-hook"));
10338 GCPRO1 (stuffstring
);
10339 get_tty_size (fileno (CURTTY ()->input
), &old_width
, &old_height
);
10340 reset_all_sys_modes ();
10341 /* sys_suspend can get an error if it tries to fork a subshell
10342 and the system resources aren't available for that. */
10343 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object
))) init_all_sys_modes
,
10345 stuff_buffered_input (stuffstring
);
10346 if (cannot_suspend
)
10350 unbind_to (count
, Qnil
);
10352 /* Check if terminal/window size has changed.
10353 Note that this is not useful when we are running directly
10354 with a window system; but suspend should be disabled in that case. */
10355 get_tty_size (fileno (CURTTY ()->input
), &width
, &height
);
10356 if (width
!= old_width
|| height
!= old_height
)
10357 change_frame_size (SELECTED_FRAME (), height
, width
, 0, 0, 0);
10359 /* Run suspend-resume-hook. */
10360 if (!NILP (Vrun_hooks
))
10361 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
10367 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
10368 Then in any case stuff anything Emacs has read ahead and not used. */
10371 stuff_buffered_input (stuffstring
)
10372 Lisp_Object stuffstring
;
10374 #ifdef SIGTSTP /* stuff_char is defined if SIGTSTP. */
10375 register unsigned char *p
;
10377 if (STRINGP (stuffstring
))
10379 register int count
;
10381 p
= SDATA (stuffstring
);
10382 count
= SBYTES (stuffstring
);
10383 while (count
-- > 0)
10388 /* Anything we have read ahead, put back for the shell to read. */
10389 /* ?? What should this do when we have multiple keyboards??
10390 Should we ignore anything that was typed in at the "wrong" kboard?
10392 rms: we should stuff everything back into the kboard
10394 for (; kbd_fetch_ptr
!= kbd_store_ptr
; kbd_fetch_ptr
++)
10397 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
10398 kbd_fetch_ptr
= kbd_buffer
;
10399 if (kbd_fetch_ptr
->kind
== ASCII_KEYSTROKE_EVENT
)
10400 stuff_char (kbd_fetch_ptr
->code
);
10402 clear_event (kbd_fetch_ptr
);
10406 #endif /* SIGTSTP */
10410 set_waiting_for_input (time_to_clear
)
10411 EMACS_TIME
*time_to_clear
;
10413 input_available_clear_time
= time_to_clear
;
10415 /* Tell handle_interrupt to throw back to read_char, */
10416 waiting_for_input
= 1;
10418 /* If handle_interrupt was called before and buffered a C-g,
10419 make it run again now, to avoid timing error. */
10420 if (!NILP (Vquit_flag
))
10421 quit_throw_to_read_char ();
10425 clear_waiting_for_input ()
10427 /* Tell handle_interrupt not to throw back to read_char, */
10428 waiting_for_input
= 0;
10429 input_available_clear_time
= 0;
10432 /* The SIGINT handler.
10434 If we have a frame on the controlling tty, we assume that the
10435 SIGINT was generated by C-g, so we call handle_interrupt.
10436 Otherwise, the handler kills Emacs. */
10439 interrupt_signal (signalnum
) /* If we don't have an argument, */
10440 int signalnum
; /* some compilers complain in signal calls. */
10442 /* Must preserve main program's value of errno. */
10443 int old_errno
= errno
;
10444 struct device
*device
;
10446 #if defined (USG) && !defined (POSIX_SIGNALS)
10447 /* USG systems forget handlers when they are used;
10448 must reestablish each time */
10449 signal (SIGINT
, interrupt_signal
);
10450 signal (SIGQUIT
, interrupt_signal
);
10453 SIGNAL_THREAD_CHECK (signalnum
);
10455 /* See if we have an active display on our controlling terminal. */
10456 device
= get_named_tty (NULL
);
10459 /* If there are no frames there, let's pretend that we are a
10460 well-behaving UN*X program and quit. */
10461 fatal_error_signal (SIGTERM
);
10465 /* Otherwise, the SIGINT was probably generated by C-g. */
10467 /* Set internal_last_event_frame to the top frame of the
10468 controlling tty, if we have a frame there. We disable the
10469 interrupt key on secondary ttys, so the SIGINT must have come
10470 from the controlling tty. */
10471 internal_last_event_frame
= device
->display_info
.tty
->top_frame
;
10473 handle_interrupt ();
10479 /* This routine is called at interrupt level in response to C-g.
10481 It is called from the SIGINT handler or kbd_buffer_store_event.
10483 If `waiting_for_input' is non zero, then unless `echoing' is
10484 nonzero, immediately throw back to read_char.
10486 Otherwise it sets the Lisp variable quit-flag not-nil. This causes
10487 eval to throw, when it gets a chance. If quit-flag is already
10488 non-nil, it stops the job right away. */
10491 handle_interrupt ()
10497 /* XXX This code needs to be revised for multi-tty support. */
10498 if (!NILP (Vquit_flag
)
10500 && get_named_tty (NULL
)
10504 /* If SIGINT isn't blocked, don't let us be interrupted by
10505 another SIGINT, it might be harmful due to non-reentrancy
10506 in I/O functions. */
10507 sigblock (sigmask (SIGINT
));
10510 reset_all_sys_modes ();
10512 #ifdef SIGTSTP /* Support possible in later USG versions */
10514 * On systems which can suspend the current process and return to the original
10515 * shell, this command causes the user to end up back at the shell.
10516 * The "Auto-save" and "Abort" questions are not asked until
10517 * the user elects to return to emacs, at which point he can save the current
10518 * job and either dump core or continue.
10523 if (sys_suspend () == -1)
10525 printf ("Not running as a subprocess;\n");
10526 printf ("you can continue or abort.\n");
10528 #else /* not VMS */
10529 /* Perhaps should really fork an inferior shell?
10530 But that would not provide any way to get back
10531 to the original shell, ever. */
10532 printf ("No support for stopping a process on this operating system;\n");
10533 printf ("you can continue or abort.\n");
10534 #endif /* not VMS */
10535 #endif /* not SIGTSTP */
10537 /* We must remain inside the screen area when the internal terminal
10538 is used. Note that [Enter] is not echoed by dos. */
10541 /* It doesn't work to autosave while GC is in progress;
10542 the code used for auto-saving doesn't cope with the mark bit. */
10543 if (!gc_in_progress
)
10545 printf ("Auto-save? (y or n) ");
10547 if (((c
= getchar ()) & ~040) == 'Y')
10549 Fdo_auto_save (Qt
, Qnil
);
10551 printf ("\r\nAuto-save done");
10552 #else /* not MSDOS */
10553 printf ("Auto-save done\n");
10554 #endif /* not MSDOS */
10556 while (c
!= '\n') c
= getchar ();
10560 /* During GC, it must be safe to reenable quitting again. */
10561 Vinhibit_quit
= Qnil
;
10564 #endif /* not MSDOS */
10565 printf ("Garbage collection in progress; cannot auto-save now\r\n");
10566 printf ("but will instead do a real quit after garbage collection ends\r\n");
10571 printf ("\r\nAbort? (y or n) ");
10572 #else /* not MSDOS */
10574 printf ("Abort (and enter debugger)? (y or n) ");
10575 #else /* not VMS */
10576 printf ("Abort (and dump core)? (y or n) ");
10577 #endif /* not VMS */
10578 #endif /* not MSDOS */
10580 if (((c
= getchar ()) & ~040) == 'Y')
10582 while (c
!= '\n') c
= getchar ();
10584 printf ("\r\nContinuing...\r\n");
10585 #else /* not MSDOS */
10586 printf ("Continuing...\n");
10587 #endif /* not MSDOS */
10589 init_all_sys_modes ();
10594 /* If executing a function that wants to be interrupted out of
10595 and the user has not deferred quitting by binding `inhibit-quit'
10596 then quit right away. */
10597 if (immediate_quit
&& NILP (Vinhibit_quit
))
10599 struct gl_state_s saved
;
10600 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
10602 immediate_quit
= 0;
10605 GCPRO4 (saved
.object
, saved
.global_code
,
10606 saved
.current_syntax_table
, saved
.old_prop
);
10607 Fsignal (Qquit
, Qnil
);
10612 /* Else request quit when it's safe */
10616 if (waiting_for_input
&& !echoing
)
10617 quit_throw_to_read_char ();
10620 /* Handle a C-g by making read_char return C-g. */
10623 quit_throw_to_read_char ()
10626 /* Prevent another signal from doing this before we finish. */
10627 clear_waiting_for_input ();
10630 Vunread_command_events
= Qnil
;
10631 unread_command_char
= -1;
10633 #if 0 /* Currently, sit_for is called from read_char without turning
10634 off polling. And that can call set_waiting_for_input.
10635 It seems to be harmless. */
10636 #ifdef POLL_FOR_INPUT
10637 /* May be > 1 if in recursive minibuffer. */
10638 if (poll_suppress_count
== 0)
10642 if (FRAMEP (internal_last_event_frame
)
10643 && !EQ (internal_last_event_frame
, selected_frame
))
10644 do_switch_frame (make_lispy_switch_frame (internal_last_event_frame
),
10647 _longjmp (getcjmp
, 1);
10650 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
10651 doc
: /* Set mode of reading keyboard input.
10652 First arg INTERRUPT non-nil means use input interrupts;
10653 nil means use CBREAK mode.
10654 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal
10655 (no effect except in CBREAK mode).
10656 Third arg META t means accept 8-bit input (for a Meta key).
10657 META nil means ignore the top bit, on the assumption it is parity.
10658 Otherwise, accept 8-bit input and don't use the top bit for Meta.
10659 Optional fourth arg QUIT if non-nil specifies character to use for quitting.
10660 See also `current-input-mode'. */)
10661 (interrupt
, flow
, meta
, quit
)
10662 Lisp_Object interrupt
, flow
, meta
, quit
;
10664 /* XXX This function needs to be revised for multi-device support.
10665 Currently it compiles fine, but its semantics are wrong. It sets
10666 global parameters (e.g. interrupt_input) based on only the
10667 current frame's device. */
10670 && (!INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400))
10671 error ("set-input-mode: QUIT must be an ASCII character");
10673 #ifdef POLL_FOR_INPUT
10678 if (FRAME_TERMCAP_P (XFRAME (selected_frame
)))
10679 /* this causes startup screen to be restored and messes with the mouse */
10680 reset_sys_modes (CURTTY ());
10684 /* Note SIGIO has been undef'd if FIONREAD is missing. */
10685 if (FRAME_DEVICE (SELECTED_FRAME ())->read_socket_hook
)
10687 /* When using X, don't give the user a real choice,
10688 because we haven't implemented the mechanisms to support it. */
10689 #ifdef NO_SOCK_SIGIO
10690 interrupt_input
= 0;
10691 #else /* not NO_SOCK_SIGIO */
10692 interrupt_input
= 1;
10693 #endif /* NO_SOCK_SIGIO */
10696 interrupt_input
= !NILP (interrupt
);
10697 #else /* not SIGIO */
10698 interrupt_input
= 0;
10699 #endif /* not SIGIO */
10701 /* Our VMS input only works by interrupts, as of now. */
10703 interrupt_input
= 1;
10706 if (FRAME_TERMCAP_P (XFRAME (selected_frame
)))
10708 struct tty_display_info
*tty
= CURTTY ();
10709 tty
->flow_control
= !NILP (flow
);
10712 else if (EQ (meta
, Qt
))
10719 /* Don't let this value be out of range. */
10720 quit_char
= XINT (quit
) & (NILP (meta
) ? 0177 : 0377);
10723 if (FRAME_TERMCAP_P (XFRAME (selected_frame
)))
10724 init_sys_modes (CURTTY ());
10727 #ifdef POLL_FOR_INPUT
10728 poll_suppress_count
= 1;
10734 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
10735 doc
: /* Return information about the way Emacs currently reads keyboard input.
10736 The value is a list of the form (INTERRUPT FLOW META QUIT), where
10737 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if
10738 nil, Emacs is using CBREAK mode.
10739 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the
10740 terminal; this does not apply if Emacs uses interrupt-driven input.
10741 META is t if accepting 8-bit input with 8th bit as Meta flag.
10742 META nil means ignoring the top bit, on the assumption it is parity.
10743 META is neither t nor nil if accepting 8-bit input and using
10744 all 8 bits as the character code.
10745 QUIT is the character Emacs currently uses to quit.
10746 The elements of this list correspond to the arguments of
10747 `set-input-mode'. */)
10750 Lisp_Object val
[4];
10751 struct frame
*sf
= XFRAME (selected_frame
);
10753 val
[0] = interrupt_input
? Qt
: Qnil
;
10754 if (FRAME_TERMCAP_P (sf
))
10756 val
[1] = FRAME_TTY (sf
)->flow_control
? Qt
: Qnil
;
10757 val
[2] = (FRAME_TTY (sf
)->meta_key
== 2
10759 : (CURTTY ()->meta_key
== 1 ? Qt
: Qnil
));
10766 XSETFASTINT (val
[3], quit_char
);
10768 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
10771 DEFUN ("posn-at-x-y", Fposn_at_x_y
, Sposn_at_x_y
, 2, 4, 0,
10772 doc
: /* Return position information for pixel coordinates X and Y.
10773 By default, X and Y are relative to text area of the selected window.
10774 Optional third arg FRAME-OR-WINDOW non-nil specifies frame or window.
10775 If optional fourth arg WHOLE is non-nil, X is relative to the left
10776 edge of the window.
10778 The return value is similar to a mouse click position:
10779 (WINDOW AREA-OR-POS (X . Y) TIMESTAMP OBJECT POS (COL . ROW)
10780 IMAGE (DX . DY) (WIDTH . HEIGHT))
10781 The `posn-' functions access elements of such lists. */)
10782 (x
, y
, frame_or_window
, whole
)
10783 Lisp_Object x
, y
, frame_or_window
, whole
;
10788 if (NILP (frame_or_window
))
10789 frame_or_window
= selected_window
;
10791 if (WINDOWP (frame_or_window
))
10795 CHECK_LIVE_WINDOW (frame_or_window
);
10797 w
= XWINDOW (frame_or_window
);
10798 XSETINT (x
, (XINT (x
)
10799 + WINDOW_LEFT_EDGE_X (w
)
10801 ? window_box_left_offset (w
, TEXT_AREA
)
10803 XSETINT (y
, WINDOW_TO_FRAME_PIXEL_Y (w
, XINT (y
)));
10804 frame_or_window
= w
->frame
;
10807 CHECK_LIVE_FRAME (frame_or_window
);
10809 return make_lispy_position (XFRAME (frame_or_window
), &x
, &y
, 0);
10812 DEFUN ("posn-at-point", Fposn_at_point
, Sposn_at_point
, 0, 2, 0,
10813 doc
: /* Return position information for buffer POS in WINDOW.
10814 POS defaults to point in WINDOW; WINDOW defaults to the selected window.
10816 Return nil if position is not visible in window. Otherwise,
10817 the return value is similar to that returned by `event-start' for
10818 a mouse click at the upper left corner of the glyph corresponding
10819 to the given buffer position:
10820 (WINDOW AREA-OR-POS (X . Y) TIMESTAMP OBJECT POS (COL . ROW)
10821 IMAGE (DX . DY) (WIDTH . HEIGHT))
10822 The `posn-' functions access elements of such lists. */)
10824 Lisp_Object pos
, window
;
10829 window
= selected_window
;
10831 tem
= Fpos_visible_in_window_p (pos
, window
, Qt
);
10834 Lisp_Object x
= XCAR (tem
);
10835 Lisp_Object y
= XCAR (XCDR (tem
));
10837 /* Point invisible due to hscrolling? */
10840 tem
= Fposn_at_x_y (x
, y
, window
, Qnil
);
10848 * Set up a new kboard object with reasonable initial values.
10854 kb
->Voverriding_terminal_local_map
= Qnil
;
10855 kb
->Vlast_command
= Qnil
;
10856 kb
->Vreal_last_command
= Qnil
;
10857 kb
->Vkeyboard_translate_table
= Qnil
;
10858 kb
->Vprefix_arg
= Qnil
;
10859 kb
->Vlast_prefix_arg
= Qnil
;
10860 kb
->kbd_queue
= Qnil
;
10861 kb
->kbd_queue_has_data
= 0;
10862 kb
->immediate_echo
= 0;
10863 kb
->echo_string
= Qnil
;
10864 kb
->echo_after_prompt
= -1;
10865 kb
->kbd_macro_buffer
= 0;
10866 kb
->kbd_macro_bufsize
= 0;
10867 kb
->defining_kbd_macro
= Qnil
;
10868 kb
->Vlast_kbd_macro
= Qnil
;
10869 kb
->reference_count
= 0;
10870 kb
->Vsystem_key_alist
= Qnil
;
10871 kb
->system_key_syms
= Qnil
;
10872 kb
->Vlocal_function_key_map
= Fmake_sparse_keymap (Qnil
);
10873 Fset_keymap_parent (kb
->Vlocal_function_key_map
, Vfunction_key_map
);
10874 kb
->Vlocal_key_translation_map
= Fmake_sparse_keymap (Qnil
);
10875 Fset_keymap_parent (kb
->Vlocal_key_translation_map
, Vkey_translation_map
);
10876 kb
->Vdefault_minibuffer_frame
= Qnil
;
10880 * Destroy the contents of a kboard object, but not the object itself.
10881 * We use this just before deleting it, or if we're going to initialize
10882 * it a second time.
10888 if (kb
->kbd_macro_buffer
)
10889 xfree (kb
->kbd_macro_buffer
);
10892 #ifdef MULTI_KBOARD
10894 /* Free KB and memory referenced from it. */
10902 for (kbp
= &all_kboards
; *kbp
!= kb
; kbp
= &(*kbp
)->next_kboard
)
10905 *kbp
= kb
->next_kboard
;
10907 /* Prevent a dangling reference to KB. */
10908 if (kb
== current_kboard
10909 && FRAMEP (selected_frame
)
10910 && FRAME_LIVE_P (XFRAME (selected_frame
)))
10912 current_kboard
= XFRAME (selected_frame
)->device
->kboard
;
10913 if (current_kboard
== kb
)
10921 #endif /* MULTI_KBOARD */
10926 /* This is correct before outermost invocation of the editor loop */
10927 command_loop_level
= -1;
10928 immediate_quit
= 0;
10929 quit_char
= Ctl ('g');
10930 Vunread_command_events
= Qnil
;
10931 unread_command_char
= -1;
10932 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
10934 recent_keys_index
= 0;
10935 kbd_fetch_ptr
= kbd_buffer
;
10936 kbd_store_ptr
= kbd_buffer
;
10938 do_mouse_tracking
= Qnil
;
10942 /* This means that command_loop_1 won't try to select anything the first
10944 internal_last_event_frame
= Qnil
;
10945 Vlast_event_frame
= internal_last_event_frame
;
10947 #ifdef MULTI_KBOARD
10948 current_kboard
= initial_kboard
;
10950 wipe_kboard (current_kboard
);
10951 init_kboard (current_kboard
);
10953 if (!noninteractive
)
10955 /* Before multi-tty support, these handlers used to be installed
10956 only if the current session was a tty session. Now an Emacs
10957 session may have multiple display types, so we always handle
10958 SIGINT. There is special code in interrupt_signal to exit
10959 Emacs on SIGINT when there are no termcap frames on the
10960 controlling terminal. */
10961 signal (SIGINT
, interrupt_signal
);
10962 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
10963 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
10964 SIGQUIT and we can't tell which one it will give us. */
10965 signal (SIGQUIT
, interrupt_signal
);
10966 #endif /* HAVE_TERMIO */
10968 /* Note SIGIO has been undef'd if FIONREAD is missing. */
10970 if (!noninteractive
)
10971 signal (SIGIO
, input_available_signal
);
10974 /* Use interrupt input by default, if it works and noninterrupt input
10975 has deficiencies. */
10977 #ifdef INTERRUPT_INPUT
10978 interrupt_input
= 1;
10980 interrupt_input
= 0;
10983 /* Our VMS input only works by interrupts, as of now. */
10985 interrupt_input
= 1;
10991 if (keyboard_init_hook
)
10992 (*keyboard_init_hook
) ();
10994 #ifdef POLL_FOR_INPUT
10995 poll_suppress_count
= 1;
11000 /* This type's only use is in syms_of_keyboard, to initialize the
11001 event header symbols and put properties on them. */
11002 struct event_head
{
11008 struct event_head head_table
[] = {
11009 {&Qmouse_movement
, "mouse-movement", &Qmouse_movement
},
11010 {&Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
},
11011 {&Qswitch_frame
, "switch-frame", &Qswitch_frame
},
11012 {&Qdelete_frame
, "delete-frame", &Qdelete_frame
},
11013 {&Qiconify_frame
, "iconify-frame", &Qiconify_frame
},
11014 {&Qmake_frame_visible
, "make-frame-visible", &Qmake_frame_visible
},
11015 /* `select-window' should be handled just like `switch-frame'
11016 in read_key_sequence. */
11017 {&Qselect_window
, "select-window", &Qswitch_frame
}
11021 syms_of_keyboard ()
11023 Vpre_help_message
= Qnil
;
11024 staticpro (&Vpre_help_message
);
11026 Vlispy_mouse_stem
= build_string ("mouse");
11027 staticpro (&Vlispy_mouse_stem
);
11030 QCimage
= intern (":image");
11031 staticpro (&QCimage
);
11033 staticpro (&Qhelp_echo
);
11034 Qhelp_echo
= intern ("help-echo");
11036 staticpro (&item_properties
);
11037 item_properties
= Qnil
;
11039 staticpro (&tool_bar_item_properties
);
11040 tool_bar_item_properties
= Qnil
;
11041 staticpro (&tool_bar_items_vector
);
11042 tool_bar_items_vector
= Qnil
;
11044 staticpro (&real_this_command
);
11045 real_this_command
= Qnil
;
11047 Qtimer_event_handler
= intern ("timer-event-handler");
11048 staticpro (&Qtimer_event_handler
);
11050 Qdisabled_command_function
= intern ("disabled-command-function");
11051 staticpro (&Qdisabled_command_function
);
11053 Qself_insert_command
= intern ("self-insert-command");
11054 staticpro (&Qself_insert_command
);
11056 Qforward_char
= intern ("forward-char");
11057 staticpro (&Qforward_char
);
11059 Qbackward_char
= intern ("backward-char");
11060 staticpro (&Qbackward_char
);
11062 Qdisabled
= intern ("disabled");
11063 staticpro (&Qdisabled
);
11065 Qundefined
= intern ("undefined");
11066 staticpro (&Qundefined
);
11068 Qpre_command_hook
= intern ("pre-command-hook");
11069 staticpro (&Qpre_command_hook
);
11071 Qpost_command_hook
= intern ("post-command-hook");
11072 staticpro (&Qpost_command_hook
);
11074 Qdeferred_action_function
= intern ("deferred-action-function");
11075 staticpro (&Qdeferred_action_function
);
11077 Qcommand_hook_internal
= intern ("command-hook-internal");
11078 staticpro (&Qcommand_hook_internal
);
11080 Qfunction_key
= intern ("function-key");
11081 staticpro (&Qfunction_key
);
11082 Qmouse_click
= intern ("mouse-click");
11083 staticpro (&Qmouse_click
);
11084 #if defined (WINDOWSNT) || defined (MAC_OS)
11085 Qlanguage_change
= intern ("language-change");
11086 staticpro (&Qlanguage_change
);
11088 Qdrag_n_drop
= intern ("drag-n-drop");
11089 staticpro (&Qdrag_n_drop
);
11091 Qsave_session
= intern ("save-session");
11092 staticpro (&Qsave_session
);
11095 Qmac_apple_event
= intern ("mac-apple-event");
11096 staticpro (&Qmac_apple_event
);
11099 Qusr1_signal
= intern ("usr1-signal");
11100 staticpro (&Qusr1_signal
);
11101 Qusr2_signal
= intern ("usr2-signal");
11102 staticpro (&Qusr2_signal
);
11104 Qmenu_enable
= intern ("menu-enable");
11105 staticpro (&Qmenu_enable
);
11106 Qmenu_alias
= intern ("menu-alias");
11107 staticpro (&Qmenu_alias
);
11108 QCenable
= intern (":enable");
11109 staticpro (&QCenable
);
11110 QCvisible
= intern (":visible");
11111 staticpro (&QCvisible
);
11112 QChelp
= intern (":help");
11113 staticpro (&QChelp
);
11114 QCfilter
= intern (":filter");
11115 staticpro (&QCfilter
);
11116 QCbutton
= intern (":button");
11117 staticpro (&QCbutton
);
11118 QCkeys
= intern (":keys");
11119 staticpro (&QCkeys
);
11120 QCkey_sequence
= intern (":key-sequence");
11121 staticpro (&QCkey_sequence
);
11122 QCtoggle
= intern (":toggle");
11123 staticpro (&QCtoggle
);
11124 QCradio
= intern (":radio");
11125 staticpro (&QCradio
);
11127 Qmode_line
= intern ("mode-line");
11128 staticpro (&Qmode_line
);
11129 Qvertical_line
= intern ("vertical-line");
11130 staticpro (&Qvertical_line
);
11131 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
11132 staticpro (&Qvertical_scroll_bar
);
11133 Qmenu_bar
= intern ("menu-bar");
11134 staticpro (&Qmenu_bar
);
11137 Qmouse_fixup_help_message
= intern ("mouse-fixup-help-message");
11138 staticpro (&Qmouse_fixup_help_message
);
11141 Qabove_handle
= intern ("above-handle");
11142 staticpro (&Qabove_handle
);
11143 Qhandle
= intern ("handle");
11144 staticpro (&Qhandle
);
11145 Qbelow_handle
= intern ("below-handle");
11146 staticpro (&Qbelow_handle
);
11147 Qup
= intern ("up");
11149 Qdown
= intern ("down");
11150 staticpro (&Qdown
);
11151 Qtop
= intern ("top");
11153 Qbottom
= intern ("bottom");
11154 staticpro (&Qbottom
);
11155 Qend_scroll
= intern ("end-scroll");
11156 staticpro (&Qend_scroll
);
11157 Qratio
= intern ("ratio");
11158 staticpro (&Qratio
);
11160 Qevent_kind
= intern ("event-kind");
11161 staticpro (&Qevent_kind
);
11162 Qevent_symbol_elements
= intern ("event-symbol-elements");
11163 staticpro (&Qevent_symbol_elements
);
11164 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
11165 staticpro (&Qevent_symbol_element_mask
);
11166 Qmodifier_cache
= intern ("modifier-cache");
11167 staticpro (&Qmodifier_cache
);
11169 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
11170 staticpro (&Qrecompute_lucid_menubar
);
11171 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
11172 staticpro (&Qactivate_menubar_hook
);
11174 Qpolling_period
= intern ("polling-period");
11175 staticpro (&Qpolling_period
);
11177 Qinput_method_function
= intern ("input-method-function");
11178 staticpro (&Qinput_method_function
);
11180 Qinput_method_exit_on_first_char
= intern ("input-method-exit-on-first-char");
11181 staticpro (&Qinput_method_exit_on_first_char
);
11182 Qinput_method_use_echo_area
= intern ("input-method-use-echo-area");
11183 staticpro (&Qinput_method_use_echo_area
);
11185 Fset (Qinput_method_exit_on_first_char
, Qnil
);
11186 Fset (Qinput_method_use_echo_area
, Qnil
);
11188 last_point_position_buffer
= Qnil
;
11191 struct event_head
*p
;
11193 for (p
= head_table
;
11194 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
11197 *p
->var
= intern (p
->name
);
11198 staticpro (p
->var
);
11199 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
11200 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
11204 button_down_location
= Fmake_vector (make_number (1), Qnil
);
11205 staticpro (&button_down_location
);
11206 mouse_syms
= Fmake_vector (make_number (1), Qnil
);
11207 staticpro (&mouse_syms
);
11208 wheel_syms
= Fmake_vector (make_number (2), Qnil
);
11209 staticpro (&wheel_syms
);
11213 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
11215 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
11216 for (i
= 0; i
< len
; i
++)
11217 if (modifier_names
[i
])
11218 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
11219 staticpro (&modifier_symbols
);
11222 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
11223 staticpro (&recent_keys
);
11225 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
11226 staticpro (&this_command_keys
);
11228 raw_keybuf
= Fmake_vector (make_number (30), Qnil
);
11229 staticpro (&raw_keybuf
);
11231 Qextended_command_history
= intern ("extended-command-history");
11232 Fset (Qextended_command_history
, Qnil
);
11233 staticpro (&Qextended_command_history
);
11235 accent_key_syms
= Qnil
;
11236 staticpro (&accent_key_syms
);
11238 func_key_syms
= Qnil
;
11239 staticpro (&func_key_syms
);
11241 drag_n_drop_syms
= Qnil
;
11242 staticpro (&drag_n_drop_syms
);
11244 unread_switch_frame
= Qnil
;
11245 staticpro (&unread_switch_frame
);
11247 internal_last_event_frame
= Qnil
;
11248 staticpro (&internal_last_event_frame
);
11250 read_key_sequence_cmd
= Qnil
;
11251 staticpro (&read_key_sequence_cmd
);
11253 menu_bar_one_keymap_changed_items
= Qnil
;
11254 staticpro (&menu_bar_one_keymap_changed_items
);
11256 menu_bar_items_vector
= Qnil
;
11257 staticpro (&menu_bar_items_vector
);
11259 defsubr (&Sevent_convert_list
);
11260 defsubr (&Sread_key_sequence
);
11261 defsubr (&Sread_key_sequence_vector
);
11262 defsubr (&Srecursive_edit
);
11264 defsubr (&Strack_mouse
);
11266 defsubr (&Sinput_pending_p
);
11267 defsubr (&Scommand_execute
);
11268 defsubr (&Srecent_keys
);
11269 defsubr (&Sthis_command_keys
);
11270 defsubr (&Sthis_command_keys_vector
);
11271 defsubr (&Sthis_single_command_keys
);
11272 defsubr (&Sthis_single_command_raw_keys
);
11273 defsubr (&Sreset_this_command_lengths
);
11274 defsubr (&Sclear_this_command_keys
);
11275 defsubr (&Ssuspend_emacs
);
11276 defsubr (&Sabort_recursive_edit
);
11277 defsubr (&Sexit_recursive_edit
);
11278 defsubr (&Srecursion_depth
);
11279 defsubr (&Stop_level
);
11280 defsubr (&Sdiscard_input
);
11281 defsubr (&Sopen_dribble_file
);
11282 defsubr (&Sset_input_mode
);
11283 defsubr (&Scurrent_input_mode
);
11284 defsubr (&Sexecute_extended_command
);
11285 defsubr (&Sposn_at_point
);
11286 defsubr (&Sposn_at_x_y
);
11288 DEFVAR_LISP ("last-command-char", &last_command_char
,
11289 doc
: /* Last input event that was part of a command. */);
11291 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char
,
11292 doc
: /* Last input event that was part of a command. */);
11294 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
11295 doc
: /* Last input event in a command, except for mouse menu events.
11296 Mouse menus give back keys that don't look like mouse events;
11297 this variable holds the actual mouse event that led to the menu,
11298 so that you can determine whether the command was run by mouse or not. */);
11300 DEFVAR_LISP ("last-input-char", &last_input_char
,
11301 doc
: /* Last input event. */);
11303 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char
,
11304 doc
: /* Last input event. */);
11306 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
11307 doc
: /* List of events to be read as the command input.
11308 These events are processed first, before actual keyboard input. */);
11309 Vunread_command_events
= Qnil
;
11311 DEFVAR_INT ("unread-command-char", &unread_command_char
,
11312 doc
: /* If not -1, an object to be read as next command input event. */);
11314 DEFVAR_LISP ("unread-post-input-method-events", &Vunread_post_input_method_events
,
11315 doc
: /* List of events to be processed as input by input methods.
11316 These events are processed after `unread-command-events', but
11317 before actual keyboard input. */);
11318 Vunread_post_input_method_events
= Qnil
;
11320 DEFVAR_LISP ("unread-input-method-events", &Vunread_input_method_events
,
11321 doc
: /* List of events to be processed as input by input methods.
11322 These events are processed after `unread-command-events', but
11323 before actual keyboard input. */);
11324 Vunread_input_method_events
= Qnil
;
11326 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
11327 doc
: /* Meta-prefix character code.
11328 Meta-foo as command input turns into this character followed by foo. */);
11329 XSETINT (meta_prefix_char
, 033);
11331 DEFVAR_KBOARD ("last-command", Vlast_command
,
11332 doc
: /* The last command executed.
11333 Normally a symbol with a function definition, but can be whatever was found
11334 in the keymap, or whatever the variable `this-command' was set to by that
11337 The value `mode-exit' is special; it means that the previous command
11338 read an event that told it to exit, and it did so and unread that event.
11339 In other words, the present command is the event that made the previous
11342 The value `kill-region' is special; it means that the previous command
11343 was a kill command.
11345 `last-command' has a separate binding for each display device.
11346 See Info node `(elisp)Multiple displays'. */);
11348 DEFVAR_KBOARD ("real-last-command", Vreal_last_command
,
11349 doc
: /* Same as `last-command', but never altered by Lisp code. */);
11351 DEFVAR_LISP ("this-command", &Vthis_command
,
11352 doc
: /* The command now being executed.
11353 The command can set this variable; whatever is put here
11354 will be in `last-command' during the following command. */);
11355 Vthis_command
= Qnil
;
11357 DEFVAR_LISP ("this-original-command", &Vthis_original_command
,
11358 doc
: /* The command bound to the current key sequence before remapping.
11359 It equals `this-command' if the original command was not remapped through
11360 any of the active keymaps. Otherwise, the value of `this-command' is the
11361 result of looking up the original command in the active keymaps. */);
11362 Vthis_original_command
= Qnil
;
11364 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
11365 doc
: /* *Number of input events between auto-saves.
11366 Zero means disable autosaving due to number of characters typed. */);
11367 auto_save_interval
= 300;
11369 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
11370 doc
: /* *Number of seconds idle time before auto-save.
11371 Zero or nil means disable auto-saving due to idleness.
11372 After auto-saving due to this many seconds of idle time,
11373 Emacs also does a garbage collection if that seems to be warranted. */);
11374 XSETFASTINT (Vauto_save_timeout
, 30);
11376 DEFVAR_LISP ("echo-keystrokes", &Vecho_keystrokes
,
11377 doc
: /* *Nonzero means echo unfinished commands after this many seconds of pause.
11378 The value may be integer or floating point. */);
11379 Vecho_keystrokes
= make_number (1);
11381 DEFVAR_INT ("polling-period", &polling_period
,
11382 doc
: /* *Interval between polling for input during Lisp execution.
11383 The reason for polling is to make C-g work to stop a running program.
11384 Polling is needed only when using X windows and SIGIO does not work.
11385 Polling is automatically disabled in all other cases. */);
11386 polling_period
= 2;
11388 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
11389 doc
: /* *Maximum time between mouse clicks to make a double-click.
11390 Measured in milliseconds. nil means disable double-click recognition;
11391 t means double-clicks have no time limit and are detected
11392 by position only. */);
11393 Vdouble_click_time
= make_number (500);
11395 DEFVAR_INT ("double-click-fuzz", &double_click_fuzz
,
11396 doc
: /* *Maximum mouse movement between clicks to make a double-click.
11397 On window-system frames, value is the number of pixels the mouse may have
11398 moved horizontally or vertically between two clicks to make a double-click.
11399 On non window-system frames, value is interpreted in units of 1/8 characters
11402 This variable is also the threshold for motion of the mouse
11403 to count as a drag. */);
11404 double_click_fuzz
= 3;
11406 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
11407 doc
: /* *Non-nil means inhibit local map menu bar menus. */);
11408 inhibit_local_menu_bar_menus
= 0;
11410 DEFVAR_INT ("num-input-keys", &num_input_keys
,
11411 doc
: /* Number of complete key sequences read as input so far.
11412 This includes key sequences read from keyboard macros.
11413 The number is effectively the number of interactive command invocations. */);
11414 num_input_keys
= 0;
11416 DEFVAR_INT ("num-nonmacro-input-events", &num_nonmacro_input_events
,
11417 doc
: /* Number of input events read from the keyboard so far.
11418 This does not include events generated by keyboard macros. */);
11419 num_nonmacro_input_events
= 0;
11421 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
11422 doc
: /* The frame in which the most recently read event occurred.
11423 If the last event came from a keyboard macro, this is set to `macro'. */);
11424 Vlast_event_frame
= Qnil
;
11426 /* This variable is set up in sysdep.c. */
11427 DEFVAR_LISP ("tty-erase-char", &Vtty_erase_char
,
11428 doc
: /* The ERASE character as set by the user with stty. */);
11430 DEFVAR_LISP ("help-char", &Vhelp_char
,
11431 doc
: /* Character to recognize as meaning Help.
11432 When it is read, do `(eval help-form)', and display result if it's a string.
11433 If the value of `help-form' is nil, this char can be read normally. */);
11434 XSETINT (Vhelp_char
, Ctl ('H'));
11436 DEFVAR_LISP ("help-event-list", &Vhelp_event_list
,
11437 doc
: /* List of input events to recognize as meaning Help.
11438 These work just like the value of `help-char' (see that). */);
11439 Vhelp_event_list
= Qnil
;
11441 DEFVAR_LISP ("help-form", &Vhelp_form
,
11442 doc
: /* Form to execute when character `help-char' is read.
11443 If the form returns a string, that string is displayed.
11444 If `help-form' is nil, the help char is not recognized. */);
11447 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
11448 doc
: /* Command to run when `help-char' character follows a prefix key.
11449 This command is used only when there is no actual binding
11450 for that character after that prefix key. */);
11451 Vprefix_help_command
= Qnil
;
11453 DEFVAR_LISP ("top-level", &Vtop_level
,
11454 doc
: /* Form to evaluate when Emacs starts up.
11455 Useful to set before you dump a modified Emacs. */);
11458 DEFVAR_KBOARD ("keyboard-translate-table", Vkeyboard_translate_table
,
11459 doc
: /* Translate table for local keyboard input, or nil.
11460 If non-nil, the value should be a char-table. Each character read
11461 from the keyboard is looked up in this char-table. If the value found
11462 there is non-nil, then it is used instead of the actual input character.
11464 The value can also be a string or vector, but this is considered obsolete.
11465 If it is a string or vector of length N, character codes N and up are left
11466 untranslated. In a vector, an element which is nil means "no translation".
11468 This is applied to the characters supplied to input methods, not their
11469 output. See also `translation-table-for-input'.
11471 `local-keyboard-translate-table' has a separate binding for each
11472 terminal. See Info node `(elisp)Multiple displays'. */);
11474 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
11475 doc
: /* Non-nil means to always spawn a subshell instead of suspending.
11476 \(Even if the operating system has support for stopping a process.\) */);
11477 cannot_suspend
= 0;
11479 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
11480 doc
: /* Non-nil means prompt with menus when appropriate.
11481 This is done when reading from a keymap that has a prompt string,
11482 for elements that have prompt strings.
11483 The menu is displayed on the screen
11484 if X menus were enabled at configuration
11485 time and the previous event was a mouse click prefix key.
11486 Otherwise, menu prompting uses the echo area. */);
11487 menu_prompting
= 1;
11489 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
11490 doc
: /* Character to see next line of menu prompt.
11491 Type this character while in a menu prompt to rotate around the lines of it. */);
11492 XSETINT (menu_prompt_more_char
, ' ');
11494 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
11495 doc
: /* A mask of additional modifier keys to use with every keyboard character.
11496 Emacs applies the modifiers of the character stored here to each keyboard
11497 character it reads. For example, after evaluating the expression
11498 (setq extra-keyboard-modifiers ?\\C-x)
11499 all input characters will have the control modifier applied to them.
11501 Note that the character ?\\C-@, equivalent to the integer zero, does
11502 not count as a control character; rather, it counts as a character
11503 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero
11504 cancels any modification. */);
11505 extra_keyboard_modifiers
= 0;
11507 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
11508 doc
: /* If an editing command sets this to t, deactivate the mark afterward.
11509 The command loop sets this to nil before each command,
11510 and tests the value when the command returns.
11511 Buffer modification stores t in this variable. */);
11512 Vdeactivate_mark
= Qnil
;
11514 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
11515 doc
: /* Temporary storage of pre-command-hook or post-command-hook. */);
11516 Vcommand_hook_internal
= Qnil
;
11518 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
11519 doc
: /* Normal hook run before each command is executed.
11520 If an unhandled error happens in running this hook,
11521 the hook value is set to nil, since otherwise the error
11522 might happen repeatedly and make Emacs nonfunctional. */);
11523 Vpre_command_hook
= Qnil
;
11525 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
11526 doc
: /* Normal hook run after each command is executed.
11527 If an unhandled error happens in running this hook,
11528 the hook value is set to nil, since otherwise the error
11529 might happen repeatedly and make Emacs nonfunctional. */);
11530 Vpost_command_hook
= Qnil
;
11533 DEFVAR_LISP ("echo-area-clear-hook", ...,
11534 doc
: /* Normal hook run when clearing the echo area. */);
11536 Qecho_area_clear_hook
= intern ("echo-area-clear-hook");
11537 staticpro (&Qecho_area_clear_hook
);
11538 SET_SYMBOL_VALUE (Qecho_area_clear_hook
, Qnil
);
11540 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
11541 doc
: /* Non-nil means menu bar, specified Lucid style, needs to be recomputed. */);
11542 Vlucid_menu_bar_dirty_flag
= Qnil
;
11544 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
11545 doc
: /* List of menu bar items to move to the end of the menu bar.
11546 The elements of the list are event types that may have menu bar bindings. */);
11547 Vmenu_bar_final_items
= Qnil
;
11549 DEFVAR_KBOARD ("overriding-terminal-local-map",
11550 Voverriding_terminal_local_map
,
11551 doc
: /* Per-terminal keymap that overrides all other local keymaps.
11552 If this variable is non-nil, it is used as a keymap instead of the
11553 buffer's local map, and the minor mode keymaps and text property keymaps.
11554 It also replaces `overriding-local-map'.
11556 This variable is intended to let commands such as `universal-argument'
11557 set up a different keymap for reading the next command.
11559 `overriding-terminal-local-map' has a separate binding for each display device.
11560 See Info node `(elisp)Multiple displays'. */);
11562 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
11563 doc
: /* Keymap that overrides all other local keymaps.
11564 If this variable is non-nil, it is used as a keymap--replacing the
11565 buffer's local map, the minor mode keymaps, and char property keymaps. */);
11566 Voverriding_local_map
= Qnil
;
11568 DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag
,
11569 doc
: /* Non-nil means `overriding-local-map' applies to the menu bar.
11570 Otherwise, the menu bar continues to reflect the buffer's local map
11571 and the minor mode maps regardless of `overriding-local-map'. */);
11572 Voverriding_local_map_menu_flag
= Qnil
;
11574 DEFVAR_LISP ("special-event-map", &Vspecial_event_map
,
11575 doc
: /* Keymap defining bindings for special events to execute at low level. */);
11576 Vspecial_event_map
= Fcons (intern ("keymap"), Qnil
);
11578 DEFVAR_LISP ("track-mouse", &do_mouse_tracking
,
11579 doc
: /* *Non-nil means generate motion events for mouse motion. */);
11581 DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist
,
11582 doc
: /* Alist of system-specific X windows key symbols.
11583 Each element should have the form (N . SYMBOL) where N is the
11584 numeric keysym code (sans the \"system-specific\" bit 1<<28)
11585 and SYMBOL is its name.
11587 `system-key-alist' has a separate binding for each display device.
11588 See Info node `(elisp)Multiple displays'.
11590 Note that the currently selected frame has very little to do with
11591 which binding of this variable is active at any given moment. If you
11592 need set or get the binding on a specific display, use
11593 `terminal-local-value' and `set-terminal-local-value'. */);
11595 DEFVAR_KBOARD ("local-function-key-map", Vlocal_function_key_map
,
11596 doc
: /* Keymap mapping ASCII function key sequences onto their preferred forms.
11597 This allows Emacs to recognize function keys sent from ASCII
11598 terminals at any point in a key sequence.
11600 The `read-key-sequence' function replaces any subsequence bound by
11601 `local-function-key-map' with its binding. More precisely, when the
11602 active keymaps have no binding for the current key sequence but
11603 `local-function-key-map' binds a suffix of the sequence to a vector or
11604 string, `read-key-sequence' replaces the matching suffix with its
11605 binding, and continues with the new sequence.
11607 The events that come from bindings in `local-function-key-map' are not
11608 themselves looked up in `local-function-key-map'.
11610 For example, suppose `local-function-key-map' binds `ESC O P' to [f1].
11611 Typing `ESC O P' to `read-key-sequence' would return [f1]. Typing
11612 `C-x ESC O P' would return [?\\C-x f1]. If [f1] were a prefix key,
11613 typing `ESC O P x' would return [f1 x].
11615 `local-function-key-map' has a separate binding for each display
11616 device. See Info node `(elisp)Multiple displays'. If you need to
11617 define a binding on all display devices, change `function-key-map'
11618 instead. Initially, `local-function-key-map' is an empty keymap that
11619 has `function-key-map' as its parent on all display devices.
11621 Note that the currently selected frame has very little to do with
11622 which binding of this variable is active at any given moment. If you
11623 need set or get the binding on a specific display, use
11624 `terminal-local-value' and `set-terminal-local-value'. */);
11626 DEFVAR_LISP ("function-key-map", &Vfunction_key_map
,
11627 doc
: /* The parent keymap of all `local-function-key-map' instances.
11628 Function key definitions that apply to all display devices should go
11629 here. If a mapping is defined in both the current
11630 `local-function-key-map' binding and this variable, then the local
11631 definition will take precendence. */);
11632 Vfunction_key_map
= Fmake_sparse_keymap (Qnil
);
11634 DEFVAR_KBOARD ("local-key-translation-map", Vlocal_key_translation_map
,
11635 doc
: /* Keymap of key translations that can override keymaps.
11636 This keymap works like `function-key-map', but comes after that,
11637 and its non-prefix bindings override ordinary bindings.
11639 `key-translation-map' has a separate binding for each display device.
11640 (See Info node `(elisp)Multiple displays'.) If you need to set a key
11641 translation on all devices, change `global-key-translation-map' instead.
11643 Note that the currently selected frame has very little to do with
11644 which binding of this variable is active at any given moment. If you
11645 need set or get the binding on a specific display, use
11646 `terminal-local-value' and `set-terminal-local-value'. */);
11648 DEFVAR_LISP ("key-translation-map", &Vkey_translation_map
,
11649 doc
: /* The parent keymap of all `local-key-translation-map' instances.
11650 Key translations that apply to all display devices should go here. */);
11651 Vkey_translation_map
= Fmake_sparse_keymap (Qnil
);
11653 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
11654 doc
: /* List of deferred actions to be performed at a later time.
11655 The precise format isn't relevant here; we just check whether it is nil. */);
11656 Vdeferred_action_list
= Qnil
;
11658 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
11659 doc
: /* Function to call to handle deferred actions, after each command.
11660 This function is called with no arguments after each command
11661 whenever `deferred-action-list' is non-nil. */);
11662 Vdeferred_action_function
= Qnil
;
11664 DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings
,
11665 doc
: /* *Non-nil means show the equivalent key-binding when M-x command has one.
11666 The value can be a length of time to show the message for.
11667 If the value is non-nil and not a number, we wait 2 seconds. */);
11668 Vsuggest_key_bindings
= Qt
;
11670 DEFVAR_LISP ("timer-list", &Vtimer_list
,
11671 doc
: /* List of active absolute time timers in order of increasing time. */);
11672 Vtimer_list
= Qnil
;
11674 DEFVAR_LISP ("timer-idle-list", &Vtimer_idle_list
,
11675 doc
: /* List of active idle-time timers in order of increasing time. */);
11676 Vtimer_idle_list
= Qnil
;
11678 DEFVAR_LISP ("input-method-function", &Vinput_method_function
,
11679 doc
: /* If non-nil, the function that implements the current input method.
11680 It's called with one argument, a printing character that was just read.
11681 \(That means a character with code 040...0176.)
11682 Typically this function uses `read-event' to read additional events.
11683 When it does so, it should first bind `input-method-function' to nil
11684 so it will not be called recursively.
11686 The function should return a list of zero or more events
11687 to be used as input. If it wants to put back some events
11688 to be reconsidered, separately, by the input method,
11689 it can add them to the beginning of `unread-command-events'.
11691 The input method function can find in `input-method-previous-method'
11692 the previous echo area message.
11694 The input method function should refer to the variables
11695 `input-method-use-echo-area' and `input-method-exit-on-first-char'
11696 for guidance on what to do. */);
11697 Vinput_method_function
= Qnil
;
11699 DEFVAR_LISP ("input-method-previous-message",
11700 &Vinput_method_previous_message
,
11701 doc
: /* When `input-method-function' is called, hold the previous echo area message.
11702 This variable exists because `read-event' clears the echo area
11703 before running the input method. It is nil if there was no message. */);
11704 Vinput_method_previous_message
= Qnil
;
11706 DEFVAR_LISP ("show-help-function", &Vshow_help_function
,
11707 doc
: /* If non-nil, the function that implements the display of help.
11708 It's called with one argument, the help string to display. */);
11709 Vshow_help_function
= Qnil
;
11711 DEFVAR_LISP ("disable-point-adjustment", &Vdisable_point_adjustment
,
11712 doc
: /* If non-nil, suppress point adjustment after executing a command.
11714 After a command is executed, if point is moved into a region that has
11715 special properties (e.g. composition, display), we adjust point to
11716 the boundary of the region. But, when a command sets this variable to
11717 non-nil, we suppress the point adjustment.
11719 This variable is set to nil before reading a command, and is checked
11720 just after executing the command. */);
11721 Vdisable_point_adjustment
= Qnil
;
11723 DEFVAR_LISP ("global-disable-point-adjustment",
11724 &Vglobal_disable_point_adjustment
,
11725 doc
: /* *If non-nil, always suppress point adjustment.
11727 The default value is nil, in which case, point adjustment are
11728 suppressed only after special commands that set
11729 `disable-point-adjustment' (which see) to non-nil. */);
11730 Vglobal_disable_point_adjustment
= Qnil
;
11732 DEFVAR_LISP ("minibuffer-message-timeout", &Vminibuffer_message_timeout
,
11733 doc
: /* *How long to display an echo-area message when the minibuffer is active.
11734 If the value is not a number, such messages don't time out. */);
11735 Vminibuffer_message_timeout
= make_number (2);
11737 DEFVAR_LISP ("throw-on-input", &Vthrow_on_input
,
11738 doc
: /* If non-nil, any keyboard input throws to this symbol.
11739 The value of that variable is passed to `quit-flag' and later causes a
11740 peculiar kind of quitting. */);
11741 Vthrow_on_input
= Qnil
;
11745 keys_of_keyboard ()
11747 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
11748 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
11749 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
11750 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
11751 initial_define_key (meta_map
, 'x', "execute-extended-command");
11753 initial_define_lispy_key (Vspecial_event_map
, "delete-frame",
11754 "handle-delete-frame");
11755 /* Here we used to use `ignore-event' which would simple set prefix-arg to
11756 current-prefix-arg, as is done in `handle-switch-frame'.
11757 But `handle-switch-frame is not run from the special-map.
11758 Commands from that map are run in a special way that automatically
11759 preserves the prefix-arg. Restoring the prefix arg here is not just
11760 redundant but harmful:
11762 - current-prefix-arg is set to non-nil, prefix-arg is set to nil.
11763 - after the first prompt, the exit-minibuffer-hook is run which may
11764 iconify a frame and thus push a `iconify-frame' event.
11765 - after running exit-minibuffer-hook, current-prefix-arg is
11766 restored to the non-nil value it had before the prompt.
11767 - we enter the second prompt.
11768 current-prefix-arg is non-nil, prefix-arg is nil.
11769 - before running the first real event, we run the special iconify-frame
11770 event, but we pass the `special' arg to execute-command so
11771 current-prefix-arg and prefix-arg are left untouched.
11772 - here we foolishly copy the non-nil current-prefix-arg to prefix-arg.
11773 - the next key event will have a spuriously non-nil current-prefix-arg. */
11774 initial_define_lispy_key (Vspecial_event_map
, "iconify-frame",
11776 initial_define_lispy_key (Vspecial_event_map
, "make-frame-visible",
11778 /* Handling it at such a low-level causes read_key_sequence to get
11779 * confused because it doesn't realize that the current_buffer was
11780 * changed by read_char.
11782 * initial_define_lispy_key (Vspecial_event_map, "select-window",
11783 * "handle-select-window"); */
11784 initial_define_lispy_key (Vspecial_event_map
, "save-session",
11785 "handle-save-session");
11788 /* Mark the pointers in the kboard objects.
11789 Called by the Fgarbage_collector. */
11795 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
11797 if (kb
->kbd_macro_buffer
)
11798 for (p
= kb
->kbd_macro_buffer
; p
< kb
->kbd_macro_ptr
; p
++)
11800 mark_object (kb
->Voverriding_terminal_local_map
);
11801 mark_object (kb
->Vlast_command
);
11802 mark_object (kb
->Vreal_last_command
);
11803 mark_object (kb
->Vkeyboard_translate_table
);
11804 mark_object (kb
->Vprefix_arg
);
11805 mark_object (kb
->Vlast_prefix_arg
);
11806 mark_object (kb
->kbd_queue
);
11807 mark_object (kb
->defining_kbd_macro
);
11808 mark_object (kb
->Vlast_kbd_macro
);
11809 mark_object (kb
->Vsystem_key_alist
);
11810 mark_object (kb
->system_key_syms
);
11811 mark_object (kb
->Vlocal_function_key_map
);
11812 mark_object (kb
->Vlocal_key_translation_map
);
11813 mark_object (kb
->Vdefault_minibuffer_frame
);
11814 mark_object (kb
->echo_string
);
11817 struct input_event
*event
;
11818 for (event
= kbd_fetch_ptr
; event
!= kbd_store_ptr
; event
++)
11820 if (event
== kbd_buffer
+ KBD_BUFFER_SIZE
)
11821 event
= kbd_buffer
;
11822 if (event
->kind
!= SELECTION_REQUEST_EVENT
11823 && event
->kind
!= SELECTION_CLEAR_EVENT
)
11825 mark_object (event
->x
);
11826 mark_object (event
->y
);
11828 mark_object (event
->frame_or_window
);
11829 mark_object (event
->arg
);
11834 /* arch-tag: 774e34d7-6d31-42f3-8397-e079a4e4c9ca
11835 (do not change this comment) */