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, 2006 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. */
29 #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"
64 #include <sys/types.h>
73 /* This is to get the definitions of the XK_ symbols. */
80 #endif /* HAVE_NTGUI */
90 /* Variables for blockinput.h: */
92 /* Non-zero if interrupt input is blocked right now. */
93 int interrupt_input_blocked
;
95 /* Nonzero means an input interrupt has arrived
96 during the current critical section. */
97 int interrupt_input_pending
;
100 /* File descriptor to use for input. */
103 #ifdef HAVE_WINDOW_SYSTEM
104 /* Make all keyboard buffers much bigger when using X windows. */
106 /* But not too big (local data > 32K error) if on Mac OS Classic. */
107 #define KBD_BUFFER_SIZE 512
109 #define KBD_BUFFER_SIZE 4096
111 #else /* No X-windows, character input */
112 #define KBD_BUFFER_SIZE 4096
113 #endif /* No X-windows */
115 #define abs(x) ((x) >= 0 ? (x) : -(x))
117 /* Following definition copied from eval.c */
121 struct backtrace
*next
;
122 Lisp_Object
*function
;
123 Lisp_Object
*args
; /* Points to vector of args. */
124 int nargs
; /* length of vector. If nargs is UNEVALLED,
125 args points to slot holding list of
128 /* Nonzero means call value of debugger when done with this operation. */
133 KBOARD
*initial_kboard
;
134 KBOARD
*current_kboard
;
138 KBOARD the_only_kboard
;
141 /* Non-nil disable property on a command means
142 do not execute it; call disabled-command-function's value instead. */
143 Lisp_Object Qdisabled
, Qdisabled_command_function
;
145 #define NUM_RECENT_KEYS (100)
146 int recent_keys_index
; /* Index for storing next element into recent_keys */
147 int total_keys
; /* Total number of elements stored into recent_keys */
148 Lisp_Object recent_keys
; /* A vector, holding the last 100 keystrokes */
150 /* Vector holding the key sequence that invoked the current command.
151 It is reused for each command, and it may be longer than the current
152 sequence; this_command_key_count indicates how many elements
153 actually mean something.
154 It's easier to staticpro a single Lisp_Object than an array. */
155 Lisp_Object this_command_keys
;
156 int this_command_key_count
;
158 /* 1 after calling Freset_this_command_lengths.
160 int this_command_key_count_reset
;
162 /* This vector is used as a buffer to record the events that were actually read
163 by read_key_sequence. */
164 Lisp_Object raw_keybuf
;
165 int raw_keybuf_count
;
167 #define GROW_RAW_KEYBUF \
168 if (raw_keybuf_count == XVECTOR (raw_keybuf)->size) \
170 int newsize = 2 * XVECTOR (raw_keybuf)->size; \
172 new = Fmake_vector (make_number (newsize), Qnil); \
173 bcopy (XVECTOR (raw_keybuf)->contents, XVECTOR (new)->contents, \
174 raw_keybuf_count * sizeof (Lisp_Object)); \
178 /* Number of elements of this_command_keys
179 that precede this key sequence. */
180 int this_single_command_key_start
;
182 /* Record values of this_command_key_count and echo_length ()
183 before this command was read. */
184 static int before_command_key_count
;
185 static int before_command_echo_length
;
187 extern int minbuf_level
;
189 extern int message_enable_multibyte
;
191 extern struct backtrace
*backtrace_list
;
193 /* If non-nil, the function that implements the display of help.
194 It's called with one argument, the help string to display. */
196 Lisp_Object Vshow_help_function
;
198 /* If a string, the message displayed before displaying a help-echo
201 Lisp_Object Vpre_help_message
;
203 /* Nonzero means do menu prompting. */
205 static int menu_prompting
;
207 /* Character to see next line of menu prompt. */
209 static Lisp_Object menu_prompt_more_char
;
211 /* For longjmp to where kbd input is being done. */
213 static jmp_buf getcjmp
;
215 /* True while doing kbd input. */
216 int waiting_for_input
;
218 /* True while displaying for echoing. Delays C-g throwing. */
222 /* Non-null means we can start echoing at the next input pause even
223 though there is something in the echo area. */
225 static struct kboard
*ok_to_echo_at_next_pause
;
227 /* The kboard last echoing, or null for none. Reset to 0 in
228 cancel_echoing. If non-null, and a current echo area message
229 exists, and echo_message_buffer is eq to the current message
230 buffer, we know that the message comes from echo_kboard. */
232 struct kboard
*echo_kboard
;
234 /* The buffer used for echoing. Set in echo_now, reset in
237 Lisp_Object echo_message_buffer
;
239 /* Nonzero means disregard local maps for the menu bar. */
240 static int inhibit_local_menu_bar_menus
;
242 /* Nonzero means C-g should cause immediate error-signal. */
245 /* The user's hook function for outputting an error message. */
246 Lisp_Object Vcommand_error_function
;
248 /* The user's ERASE setting. */
249 Lisp_Object Vtty_erase_char
;
251 /* Character to recognize as the help char. */
252 Lisp_Object Vhelp_char
;
254 /* List of other event types to recognize as meaning "help". */
255 Lisp_Object Vhelp_event_list
;
257 /* Form to execute when help char is typed. */
258 Lisp_Object Vhelp_form
;
260 /* Command to run when the help character follows a prefix key. */
261 Lisp_Object Vprefix_help_command
;
263 /* List of items that should move to the end of the menu bar. */
264 Lisp_Object Vmenu_bar_final_items
;
266 /* Non-nil means show the equivalent key-binding for
267 any M-x command that has one.
268 The value can be a length of time to show the message for.
269 If the value is non-nil and not a number, we wait 2 seconds. */
270 Lisp_Object Vsuggest_key_bindings
;
272 /* How long to display an echo-area message when the minibuffer is active.
273 If the value is not a number, such messages don't time out. */
274 Lisp_Object Vminibuffer_message_timeout
;
276 /* Character that causes a quit. Normally C-g.
278 If we are running on an ordinary terminal, this must be an ordinary
279 ASCII char, since we want to make it our interrupt character.
281 If we are not running on an ordinary terminal, it still needs to be
282 an ordinary ASCII char. This character needs to be recognized in
283 the input interrupt handler. At this point, the keystroke is
284 represented as a struct input_event, while the desired quit
285 character is specified as a lispy event. The mapping from struct
286 input_events to lispy events cannot run in an interrupt handler,
287 and the reverse mapping is difficult for anything but ASCII
290 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
294 extern Lisp_Object current_global_map
;
295 extern int minibuf_level
;
297 /* If non-nil, this is a map that overrides all other local maps. */
298 Lisp_Object Voverriding_local_map
;
300 /* If non-nil, Voverriding_local_map applies to the menu bar. */
301 Lisp_Object Voverriding_local_map_menu_flag
;
303 /* Keymap that defines special misc events that should
304 be processed immediately at a low level. */
305 Lisp_Object Vspecial_event_map
;
307 /* Current depth in recursive edits. */
308 int command_loop_level
;
310 /* Total number of times command_loop has read a key sequence. */
311 EMACS_INT num_input_keys
;
313 /* Last input character read as a command. */
314 Lisp_Object last_command_char
;
316 /* Last input character read as a command, not counting menus
317 reached by the mouse. */
318 Lisp_Object last_nonmenu_event
;
320 /* Last input character read for any purpose. */
321 Lisp_Object last_input_char
;
323 /* If not Qnil, a list of objects to be read as subsequent command input. */
324 Lisp_Object Vunread_command_events
;
326 /* If not Qnil, a list of objects to be read as subsequent command input
327 including input method processing. */
328 Lisp_Object Vunread_input_method_events
;
330 /* If not Qnil, a list of objects to be read as subsequent command input
331 but NOT including input method processing. */
332 Lisp_Object Vunread_post_input_method_events
;
334 /* If not -1, an event to be read as subsequent command input. */
335 EMACS_INT unread_command_char
;
337 /* If not Qnil, this is a switch-frame event which we decided to put
338 off until the end of a key sequence. This should be read as the
339 next command input, after any unread_command_events.
341 read_key_sequence uses this to delay switch-frame events until the
342 end of the key sequence; Fread_char uses it to put off switch-frame
343 events until a non-ASCII event is acceptable as input. */
344 Lisp_Object unread_switch_frame
;
346 /* A mask of extra modifier bits to put into every keyboard char. */
347 EMACS_INT extra_keyboard_modifiers
;
349 /* Char to use as prefix when a meta character is typed in.
350 This is bound on entry to minibuffer in case ESC is changed there. */
352 Lisp_Object meta_prefix_char
;
354 /* Last size recorded for a current buffer which is not a minibuffer. */
355 static int last_non_minibuf_size
;
357 /* Number of idle seconds before an auto-save and garbage collection. */
358 static Lisp_Object Vauto_save_timeout
;
360 /* Total number of times read_char has returned. */
361 int num_input_events
;
363 /* Total number of times read_char has returned, outside of macros. */
364 EMACS_INT num_nonmacro_input_events
;
366 /* Auto-save automatically when this many characters have been typed
367 since the last time. */
369 static EMACS_INT auto_save_interval
;
371 /* Value of num_nonmacro_input_events as of last auto save. */
375 /* The command being executed by the command loop.
376 Commands may set this, and the value set will be copied into
377 current_kboard->Vlast_command instead of the actual command. */
378 Lisp_Object Vthis_command
;
380 /* This is like Vthis_command, except that commands never set it. */
381 Lisp_Object real_this_command
;
383 /* If the lookup of the command returns a binding, the original
384 command is stored in this-original-command. It is nil otherwise. */
385 Lisp_Object Vthis_original_command
;
387 /* The value of point when the last command was started. */
388 int last_point_position
;
390 /* The buffer that was current when the last command was started. */
391 Lisp_Object last_point_position_buffer
;
393 /* The window that was selected when the last command was started. */
394 Lisp_Object last_point_position_window
;
396 /* The frame in which the last input event occurred, or Qmacro if the
397 last event came from a macro. We use this to determine when to
398 generate switch-frame events. This may be cleared by functions
399 like Fselect_frame, to make sure that a switch-frame event is
400 generated by the next character. */
401 Lisp_Object internal_last_event_frame
;
403 /* A user-visible version of the above, intended to allow users to
404 figure out where the last event came from, if the event doesn't
405 carry that information itself (i.e. if it was a character). */
406 Lisp_Object Vlast_event_frame
;
408 /* The timestamp of the last input event we received from the X server.
409 X Windows wants this for selection ownership. */
410 unsigned long last_event_timestamp
;
412 Lisp_Object Qself_insert_command
;
413 Lisp_Object Qforward_char
;
414 Lisp_Object Qbackward_char
;
415 Lisp_Object Qundefined
;
416 Lisp_Object Qtimer_event_handler
;
418 /* read_key_sequence stores here the command definition of the
419 key sequence that it reads. */
420 Lisp_Object read_key_sequence_cmd
;
422 /* Echo unfinished commands after this many seconds of pause. */
423 Lisp_Object Vecho_keystrokes
;
425 /* Form to evaluate (if non-nil) when Emacs is started. */
426 Lisp_Object Vtop_level
;
428 /* User-supplied table to translate input characters. */
429 Lisp_Object Vkeyboard_translate_table
;
431 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
432 extern Lisp_Object Vfunction_key_map
;
434 /* Another keymap that maps key sequences into key sequences.
435 This one takes precedence over ordinary definitions. */
436 extern Lisp_Object Vkey_translation_map
;
438 /* If non-nil, this implements the current input method. */
439 Lisp_Object Vinput_method_function
;
440 Lisp_Object Qinput_method_function
;
442 /* When we call Vinput_method_function,
443 this holds the echo area message that was just erased. */
444 Lisp_Object Vinput_method_previous_message
;
446 /* Non-nil means deactivate the mark at end of this command. */
447 Lisp_Object Vdeactivate_mark
;
449 /* Menu bar specified in Lucid Emacs fashion. */
451 Lisp_Object Vlucid_menu_bar_dirty_flag
;
452 Lisp_Object Qrecompute_lucid_menubar
, Qactivate_menubar_hook
;
454 Lisp_Object Qecho_area_clear_hook
;
456 /* Hooks to run before and after each command. */
457 Lisp_Object Qpre_command_hook
, Vpre_command_hook
;
458 Lisp_Object Qpost_command_hook
, Vpost_command_hook
;
459 Lisp_Object Qcommand_hook_internal
, Vcommand_hook_internal
;
461 /* List of deferred actions to be performed at a later time.
462 The precise format isn't relevant here; we just check whether it is nil. */
463 Lisp_Object Vdeferred_action_list
;
465 /* Function to call to handle deferred actions, when there are any. */
466 Lisp_Object Vdeferred_action_function
;
467 Lisp_Object Qdeferred_action_function
;
469 Lisp_Object Qinput_method_exit_on_first_char
;
470 Lisp_Object Qinput_method_use_echo_area
;
472 /* File in which we write all commands we read. */
475 /* Nonzero if input is available. */
478 /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
479 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
483 extern char *pending_malloc_warning
;
485 /* Circular buffer for pre-read keyboard input. */
487 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
489 /* Pointer to next available character in kbd_buffer.
490 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
491 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the
492 next available char is in kbd_buffer[0]. */
493 static struct input_event
*kbd_fetch_ptr
;
495 /* Pointer to next place to store character in kbd_buffer. This
496 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
497 character should go in kbd_buffer[0]. */
498 static struct input_event
* volatile kbd_store_ptr
;
500 /* The above pair of variables forms a "queue empty" flag. When we
501 enqueue a non-hook event, we increment kbd_store_ptr. When we
502 dequeue a non-hook event, we increment kbd_fetch_ptr. We say that
503 there is input available iff the two pointers are not equal.
505 Why not just have a flag set and cleared by the enqueuing and
506 dequeuing functions? Such a flag could be screwed up by interrupts
507 at inopportune times. */
509 /* If this flag is non-nil, we check mouse_moved to see when the
510 mouse moves, and motion events will appear in the input stream.
511 Otherwise, mouse motion is ignored. */
512 Lisp_Object do_mouse_tracking
;
514 /* Symbols to head events. */
515 Lisp_Object Qmouse_movement
;
516 Lisp_Object Qscroll_bar_movement
;
517 Lisp_Object Qswitch_frame
;
518 Lisp_Object Qdelete_frame
;
519 Lisp_Object Qiconify_frame
;
520 Lisp_Object Qmake_frame_visible
;
521 Lisp_Object Qselect_window
;
522 Lisp_Object Qhelp_echo
;
525 Lisp_Object Qmouse_fixup_help_message
;
528 /* Symbols to denote kinds of events. */
529 Lisp_Object Qfunction_key
;
530 Lisp_Object Qmouse_click
;
531 #if defined (WINDOWSNT) || defined (MAC_OS)
532 Lisp_Object Qlanguage_change
;
534 Lisp_Object Qdrag_n_drop
;
535 Lisp_Object Qsave_session
;
537 Lisp_Object Qmac_apple_event
;
540 /* Lisp_Object Qmouse_movement; - also an event header */
542 /* Properties of event headers. */
543 Lisp_Object Qevent_kind
;
544 Lisp_Object Qevent_symbol_elements
;
546 /* menu item parts */
547 Lisp_Object Qmenu_alias
;
548 Lisp_Object Qmenu_enable
;
549 Lisp_Object QCenable
, QCvisible
, QChelp
, QCfilter
, QCkeys
, QCkey_sequence
;
550 Lisp_Object QCbutton
, QCtoggle
, QCradio
;
551 extern Lisp_Object Vdefine_key_rebound_commands
;
552 extern Lisp_Object Qmenu_item
;
554 /* An event header symbol HEAD may have a property named
555 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
556 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
557 mask of modifiers applied to it. If present, this is used to help
558 speed up parse_modifiers. */
559 Lisp_Object Qevent_symbol_element_mask
;
561 /* An unmodified event header BASE may have a property named
562 Qmodifier_cache, which is an alist mapping modifier masks onto
563 modified versions of BASE. If present, this helps speed up
565 Lisp_Object Qmodifier_cache
;
567 /* Symbols to use for parts of windows. */
568 Lisp_Object Qmode_line
;
569 Lisp_Object Qvertical_line
;
570 Lisp_Object Qvertical_scroll_bar
;
571 Lisp_Object Qmenu_bar
;
572 extern Lisp_Object Qleft_margin
, Qright_margin
;
573 extern Lisp_Object Qleft_fringe
, Qright_fringe
;
574 extern Lisp_Object QCmap
;
576 Lisp_Object
recursive_edit_unwind (), command_loop ();
577 Lisp_Object
Fthis_command_keys ();
578 Lisp_Object Qextended_command_history
;
579 EMACS_TIME
timer_check ();
581 extern Lisp_Object Vhistory_length
, Vtranslation_table_for_input
;
583 extern char *x_get_keysym_name ();
585 static void record_menu_key ();
586 static int echo_length ();
588 Lisp_Object Qpolling_period
;
590 /* List of absolute timers. Appears in order of next scheduled event. */
591 Lisp_Object Vtimer_list
;
593 /* List of idle time timers. Appears in order of next scheduled event. */
594 Lisp_Object Vtimer_idle_list
;
596 /* Incremented whenever a timer is run. */
599 extern Lisp_Object Vprint_level
, Vprint_length
;
601 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
603 EMACS_TIME
*input_available_clear_time
;
605 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
606 Default is 1 if INTERRUPT_INPUT is defined. */
609 /* Nonzero while interrupts are temporarily deferred during redisplay. */
610 int interrupts_deferred
;
612 /* Nonzero means use ^S/^Q for flow control. */
615 /* Allow m- file to inhibit use of FIONREAD. */
616 #ifdef BROKEN_FIONREAD
620 /* We are unable to use interrupts if FIONREAD is not available,
621 so flush SIGIO so we won't try. */
622 #if !defined (FIONREAD)
628 /* If we support a window system, turn on the code to poll periodically
629 to detect C-g. It isn't actually used when doing interrupt input. */
630 #if defined(HAVE_WINDOW_SYSTEM) && !defined(USE_ASYNC_EVENTS)
631 #define POLL_FOR_INPUT
634 /* After a command is executed, if point is moved into a region that
635 has specific properties (e.g. composition, display), we adjust
636 point to the boundary of the region. But, if a command sets this
637 variable to non-nil, we suppress this point adjustment. This
638 variable is set to nil before reading a command. */
640 Lisp_Object Vdisable_point_adjustment
;
642 /* If non-nil, always disable point adjustment. */
644 Lisp_Object Vglobal_disable_point_adjustment
;
646 /* The time when Emacs started being idle. */
648 static EMACS_TIME timer_idleness_start_time
;
650 /* After Emacs stops being idle, this saves the last value
651 of timer_idleness_start_time from when it was idle. */
653 static EMACS_TIME timer_last_idleness_start_time
;
655 /* If non-nil, events produced by disabled menu items and tool-bar
656 buttons are not ignored. Help functions bind this to allow help on
657 those items and buttons. */
658 Lisp_Object Venable_disabled_menus_and_buttons
;
661 /* Global variable declarations. */
663 /* Flags for readable_events. */
664 #define READABLE_EVENTS_DO_TIMERS_NOW (1 << 0)
665 #define READABLE_EVENTS_FILTER_EVENTS (1 << 1)
666 #define READABLE_EVENTS_IGNORE_SQUEEZABLES (1 << 2)
668 /* Function for init_keyboard to call with no args (if nonzero). */
669 void (*keyboard_init_hook
) ();
671 static int read_avail_input
P_ ((int));
672 static void get_input_pending
P_ ((int *, int));
673 static int readable_events
P_ ((int));
674 static Lisp_Object read_char_x_menu_prompt
P_ ((int, Lisp_Object
*,
675 Lisp_Object
, int *));
676 static Lisp_Object
read_char_x_menu_prompt ();
677 static Lisp_Object read_char_minibuf_menu_prompt
P_ ((int, int,
679 static Lisp_Object make_lispy_event
P_ ((struct input_event
*));
681 static Lisp_Object make_lispy_movement
P_ ((struct frame
*, Lisp_Object
,
682 enum scroll_bar_part
,
683 Lisp_Object
, Lisp_Object
,
686 static Lisp_Object modify_event_symbol
P_ ((int, unsigned, Lisp_Object
,
687 Lisp_Object
, char **,
688 Lisp_Object
*, unsigned));
689 static Lisp_Object make_lispy_switch_frame
P_ ((Lisp_Object
));
690 static int parse_solitary_modifier
P_ ((Lisp_Object
));
691 static int parse_solitary_modifier ();
692 static void save_getcjmp
P_ ((jmp_buf));
693 static void save_getcjmp ();
694 static void restore_getcjmp
P_ ((jmp_buf));
695 static Lisp_Object apply_modifiers
P_ ((int, Lisp_Object
));
696 static void clear_event
P_ ((struct input_event
*));
697 static void any_kboard_state
P_ ((void));
698 static SIGTYPE interrupt_signal
P_ ((int signalnum
));
699 static void timer_start_idle
P_ ((void));
700 static void timer_stop_idle
P_ ((void));
701 static void timer_resume_idle
P_ ((void));
703 /* Nonzero means don't try to suspend even if the operating system seems
705 static int cannot_suspend
;
707 extern Lisp_Object Qidentity
, Qonly
;
709 /* Install the string STR as the beginning of the string of echoing,
710 so that it serves as a prompt for the next character.
711 Also start echoing. */
717 current_kboard
->echo_string
= str
;
718 current_kboard
->echo_after_prompt
= SCHARS (str
);
722 /* Add C to the echo string, if echoing is going on.
723 C can be a character, which is printed prettily ("M-C-x" and all that
724 jazz), or a symbol, whose name is printed. */
730 if (current_kboard
->immediate_echo
)
732 int size
= KEY_DESCRIPTION_SIZE
+ 100;
733 char *buffer
= (char *) alloca (size
);
735 Lisp_Object echo_string
;
737 echo_string
= current_kboard
->echo_string
;
739 /* If someone has passed us a composite event, use its head symbol. */
744 ptr
= push_key_description (XINT (c
), ptr
, 1);
746 else if (SYMBOLP (c
))
748 Lisp_Object name
= SYMBOL_NAME (c
);
749 int nbytes
= SBYTES (name
);
751 if (size
- (ptr
- buffer
) < nbytes
)
753 int offset
= ptr
- buffer
;
754 size
= max (2 * size
, size
+ nbytes
);
755 buffer
= (char *) alloca (size
);
756 ptr
= buffer
+ offset
;
759 ptr
+= copy_text (SDATA (name
), ptr
, nbytes
,
760 STRING_MULTIBYTE (name
), 1);
763 if ((NILP (echo_string
) || SCHARS (echo_string
) == 0)
766 const char *text
= " (Type ? for further options)";
767 int len
= strlen (text
);
769 if (size
- (ptr
- buffer
) < len
)
771 int offset
= ptr
- buffer
;
773 buffer
= (char *) alloca (size
);
774 ptr
= buffer
+ offset
;
777 bcopy (text
, ptr
, len
);
781 /* Replace a dash from echo_dash with a space, otherwise
782 add a space at the end as a separator between keys. */
783 if (STRINGP (echo_string
)
784 && SCHARS (echo_string
) > 1)
786 Lisp_Object last_char
, prev_char
, idx
;
788 idx
= make_number (SCHARS (echo_string
) - 2);
789 prev_char
= Faref (echo_string
, idx
);
791 idx
= make_number (SCHARS (echo_string
) - 1);
792 last_char
= Faref (echo_string
, idx
);
794 /* We test PREV_CHAR to make sure this isn't the echoing
796 if (XINT (last_char
) == '-' && XINT (prev_char
) != ' ')
797 Faset (echo_string
, idx
, make_number (' '));
799 echo_string
= concat2 (echo_string
, build_string (" "));
801 else if (STRINGP (echo_string
))
802 echo_string
= concat2 (echo_string
, build_string (" "));
804 current_kboard
->echo_string
805 = concat2 (echo_string
, make_string (buffer
, ptr
- buffer
));
811 /* Temporarily add a dash to the end of the echo string if it's not
812 empty, so that it serves as a mini-prompt for the very next character. */
817 /* Do nothing if not echoing at all. */
818 if (NILP (current_kboard
->echo_string
))
821 if (!current_kboard
->immediate_echo
822 && SCHARS (current_kboard
->echo_string
) == 0)
825 /* Do nothing if we just printed a prompt. */
826 if (current_kboard
->echo_after_prompt
827 == SCHARS (current_kboard
->echo_string
))
830 /* Do nothing if we have already put a dash at the end. */
831 if (SCHARS (current_kboard
->echo_string
) > 1)
833 Lisp_Object last_char
, prev_char
, idx
;
835 idx
= make_number (SCHARS (current_kboard
->echo_string
) - 2);
836 prev_char
= Faref (current_kboard
->echo_string
, idx
);
838 idx
= make_number (SCHARS (current_kboard
->echo_string
) - 1);
839 last_char
= Faref (current_kboard
->echo_string
, idx
);
841 if (XINT (last_char
) == '-' && XINT (prev_char
) != ' ')
845 /* Put a dash at the end of the buffer temporarily,
846 but make it go away when the next character is added. */
847 current_kboard
->echo_string
= concat2 (current_kboard
->echo_string
,
852 /* Display the current echo string, and begin echoing if not already
858 if (!current_kboard
->immediate_echo
)
861 current_kboard
->immediate_echo
= 1;
863 for (i
= 0; i
< this_command_key_count
; i
++)
867 /* Set before_command_echo_length to the value that would
868 have been saved before the start of this subcommand in
869 command_loop_1, if we had already been echoing then. */
870 if (i
== this_single_command_key_start
)
871 before_command_echo_length
= echo_length ();
873 c
= XVECTOR (this_command_keys
)->contents
[i
];
874 if (! (EVENT_HAS_PARAMETERS (c
)
875 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
879 /* Set before_command_echo_length to the value that would
880 have been saved before the start of this subcommand in
881 command_loop_1, if we had already been echoing then. */
882 if (this_command_key_count
== this_single_command_key_start
)
883 before_command_echo_length
= echo_length ();
885 /* Put a dash at the end to invite the user to type more. */
890 message3_nolog (current_kboard
->echo_string
,
891 SBYTES (current_kboard
->echo_string
),
892 STRING_MULTIBYTE (current_kboard
->echo_string
));
895 /* Record in what buffer we echoed, and from which kboard. */
896 echo_message_buffer
= echo_area_buffer
[0];
897 echo_kboard
= current_kboard
;
899 if (waiting_for_input
&& !NILP (Vquit_flag
))
900 quit_throw_to_read_char ();
903 /* Turn off echoing, for the start of a new command. */
908 current_kboard
->immediate_echo
= 0;
909 current_kboard
->echo_after_prompt
= -1;
910 current_kboard
->echo_string
= Qnil
;
911 ok_to_echo_at_next_pause
= NULL
;
913 echo_message_buffer
= Qnil
;
916 /* Return the length of the current echo string. */
921 return (STRINGP (current_kboard
->echo_string
)
922 ? SCHARS (current_kboard
->echo_string
)
926 /* Truncate the current echo message to its first LEN chars.
927 This and echo_char get used by read_key_sequence when the user
928 switches frames while entering a key sequence. */
931 echo_truncate (nchars
)
934 if (STRINGP (current_kboard
->echo_string
))
935 current_kboard
->echo_string
936 = Fsubstring (current_kboard
->echo_string
,
937 make_number (0), make_number (nchars
));
938 truncate_echo_area (nchars
);
942 /* Functions for manipulating this_command_keys. */
944 add_command_key (key
)
947 #if 0 /* Not needed after we made Freset_this_command_lengths
948 do the job immediately. */
949 /* If reset-this-command-length was called recently, obey it now.
950 See the doc string of that function for an explanation of why. */
951 if (before_command_restore_flag
)
953 this_command_key_count
= before_command_key_count_1
;
954 if (this_command_key_count
< this_single_command_key_start
)
955 this_single_command_key_start
= this_command_key_count
;
956 echo_truncate (before_command_echo_length_1
);
957 before_command_restore_flag
= 0;
961 if (this_command_key_count
>= ASIZE (this_command_keys
))
962 this_command_keys
= larger_vector (this_command_keys
,
963 2 * ASIZE (this_command_keys
),
966 AREF (this_command_keys
, this_command_key_count
) = key
;
967 ++this_command_key_count
;
974 int count
= SPECPDL_INDEX ();
977 if (command_loop_level
> 0)
979 specbind (Qstandard_output
, Qt
);
980 specbind (Qstandard_input
, Qt
);
983 #ifdef HAVE_X_WINDOWS
984 /* The command loop has started an hourglass timer, so we have to
985 cancel it here, otherwise it will fire because the recursive edit
986 can take some time. Do not check for display_hourglass_p here,
987 because it could already be nil. */
991 /* This function may have been called from a debugger called from
992 within redisplay, for instance by Edebugging a function called
993 from fontification-functions. We want to allow redisplay in
994 the debugging session.
996 The recursive edit is left with a `(throw exit ...)'. The `exit'
997 tag is not caught anywhere in redisplay, i.e. when we leave the
998 recursive edit, the original redisplay leading to the recursive
999 edit will be unwound. The outcome should therefore be safe. */
1000 specbind (Qinhibit_redisplay
, Qnil
);
1003 val
= command_loop ();
1005 Fsignal (Qquit
, Qnil
);
1006 /* Handle throw from read_minibuf when using minibuffer
1007 while it's active but we're in another window. */
1009 xsignal1 (Qerror
, val
);
1011 return unbind_to (count
, Qnil
);
1014 /* When an auto-save happens, record the "time", and don't do again soon. */
1019 last_auto_save
= num_nonmacro_input_events
;
1022 /* Make an auto save happen as soon as possible at command level. */
1025 force_auto_save_soon ()
1027 last_auto_save
= - auto_save_interval
- 1;
1029 record_asynch_buffer_change ();
1032 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
1033 doc
: /* Invoke the editor command loop recursively.
1034 To get out of the recursive edit, a command can do `(throw 'exit nil)';
1035 that tells this function to return.
1036 Alternatively, `(throw 'exit t)' makes this function signal an error.
1037 This function is called by the editor initialization to begin editing. */)
1040 int count
= SPECPDL_INDEX ();
1043 /* If we enter while input is blocked, don't lock up here.
1044 This may happen through the debugger during redisplay. */
1045 if (INPUT_BLOCKED_P
)
1048 command_loop_level
++;
1049 update_mode_lines
= 1;
1051 if (command_loop_level
1052 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
1053 buffer
= Fcurrent_buffer ();
1057 /* If we leave recursive_edit_1 below with a `throw' for instance,
1058 like it is done in the splash screen display, we have to
1059 make sure that we restore single_kboard as command_loop_1
1060 would have done if it were left normally. */
1061 record_unwind_protect (recursive_edit_unwind
,
1062 Fcons (buffer
, single_kboard
? Qt
: Qnil
));
1064 recursive_edit_1 ();
1065 return unbind_to (count
, Qnil
);
1069 recursive_edit_unwind (info
)
1072 if (BUFFERP (XCAR (info
)))
1073 Fset_buffer (XCAR (info
));
1075 if (NILP (XCDR (info
)))
1076 any_kboard_state ();
1078 single_kboard_state ();
1080 command_loop_level
--;
1081 update_mode_lines
= 1;
1090 #if 0 /* Theory: if there's anything in Vunread_command_events,
1091 it will right away be read by read_key_sequence,
1092 and then if we do switch KBOARDS, it will go into the side
1093 queue then. So we don't need to do anything special here -- rms. */
1094 if (CONSP (Vunread_command_events
))
1096 current_kboard
->kbd_queue
1097 = nconc2 (Vunread_command_events
, current_kboard
->kbd_queue
);
1098 current_kboard
->kbd_queue_has_data
= 1;
1100 Vunread_command_events
= Qnil
;
1106 /* Switch to the single-kboard state, making current_kboard
1107 the only KBOARD from which further input is accepted. */
1110 single_kboard_state ()
1117 /* If we're in single_kboard state for kboard KBOARD,
1121 not_single_kboard_state (kboard
)
1125 if (kboard
== current_kboard
)
1130 /* Maintain a stack of kboards, so other parts of Emacs
1131 can switch temporarily to the kboard of a given frame
1132 and then revert to the previous status. */
1137 struct kboard_stack
*next
;
1140 static struct kboard_stack
*kboard_stack
;
1143 push_frame_kboard (f
)
1147 struct kboard_stack
*p
1148 = (struct kboard_stack
*) xmalloc (sizeof (struct kboard_stack
));
1150 p
->next
= kboard_stack
;
1151 p
->kboard
= current_kboard
;
1154 current_kboard
= FRAME_KBOARD (f
);
1162 struct kboard_stack
*p
= kboard_stack
;
1163 current_kboard
= p
->kboard
;
1164 kboard_stack
= p
->next
;
1169 /* Handle errors that are not handled at inner levels
1170 by printing an error message and returning to the editor command loop. */
1176 Lisp_Object old_level
, old_length
;
1177 char macroerror
[50];
1179 #ifdef HAVE_X_WINDOWS
1180 if (display_hourglass_p
)
1181 cancel_hourglass ();
1184 if (!NILP (executing_kbd_macro
))
1186 if (executing_kbd_macro_iterations
== 1)
1187 sprintf (macroerror
, "After 1 kbd macro iteration: ");
1189 sprintf (macroerror
, "After %d kbd macro iterations: ",
1190 executing_kbd_macro_iterations
);
1195 Vstandard_output
= Qt
;
1196 Vstandard_input
= Qt
;
1197 Vexecuting_kbd_macro
= Qnil
;
1198 executing_kbd_macro
= Qnil
;
1199 current_kboard
->Vprefix_arg
= Qnil
;
1200 current_kboard
->Vlast_prefix_arg
= Qnil
;
1203 /* Avoid unquittable loop if data contains a circular list. */
1204 old_level
= Vprint_level
;
1205 old_length
= Vprint_length
;
1206 XSETFASTINT (Vprint_level
, 10);
1207 XSETFASTINT (Vprint_length
, 10);
1208 cmd_error_internal (data
, macroerror
);
1209 Vprint_level
= old_level
;
1210 Vprint_length
= old_length
;
1214 Vinhibit_quit
= Qnil
;
1216 if (command_loop_level
== 0 && minibuf_level
== 0)
1217 any_kboard_state ();
1220 return make_number (0);
1223 /* Take actions on handling an error. DATA is the data that describes
1226 CONTEXT is a C-string containing ASCII characters only which
1227 describes the context in which the error happened. If we need to
1228 generalize CONTEXT to allow multibyte characters, make it a Lisp
1232 cmd_error_internal (data
, context
)
1236 struct frame
*sf
= SELECTED_FRAME ();
1238 /* The immediate context is not interesting for Quits,
1239 since they are asyncronous. */
1240 if (EQ (XCAR (data
), Qquit
))
1241 Vsignaling_function
= Qnil
;
1246 /* Use user's specified output function if any. */
1247 if (!NILP (Vcommand_error_function
))
1248 call3 (Vcommand_error_function
, data
,
1249 build_string (context
? context
: ""),
1250 Vsignaling_function
);
1251 /* If the window system or terminal frame hasn't been initialized
1252 yet, or we're not interactive, write the message to stderr and exit. */
1253 else if (!sf
->glyphs_initialized_p
1254 /* This is the case of the frame dumped with Emacs, when we're
1255 running under a window system. */
1256 || (!NILP (Vwindow_system
)
1257 && !inhibit_window_system
1258 && FRAME_TERMCAP_P (sf
))
1261 print_error_message (data
, Qexternal_debugging_output
,
1262 context
, Vsignaling_function
);
1263 Fterpri (Qexternal_debugging_output
);
1264 Fkill_emacs (make_number (-1));
1268 clear_message (1, 0);
1270 message_log_maybe_newline ();
1273 print_error_message (data
, Qt
, context
, Vsignaling_function
);
1276 Vsignaling_function
= Qnil
;
1279 Lisp_Object
command_loop_1 ();
1280 Lisp_Object
command_loop_2 ();
1281 Lisp_Object
top_level_1 ();
1283 /* Entry to editor-command-loop.
1284 This level has the catches for exiting/returning to editor command loop.
1285 It returns nil to exit recursive edit, t to abort it. */
1290 if (command_loop_level
> 0 || minibuf_level
> 0)
1293 val
= internal_catch (Qexit
, command_loop_2
, Qnil
);
1294 executing_kbd_macro
= Qnil
;
1300 internal_catch (Qtop_level
, top_level_1
, Qnil
);
1301 /* Reset single_kboard in case top-level set it while
1302 evaluating an -f option, or we are stuck there for some
1304 any_kboard_state ();
1305 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
1306 executing_kbd_macro
= Qnil
;
1308 /* End of file in -batch run causes exit here. */
1314 /* Here we catch errors in execution of commands within the
1315 editing loop, and reenter the editing loop.
1316 When there is an error, cmd_error runs and returns a non-nil
1317 value to us. A value of nil means that command_loop_1 itself
1318 returned due to end of file (or end of kbd macro). */
1323 register Lisp_Object val
;
1326 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
1327 while (!NILP (val
));
1335 return Feval (Vtop_level
);
1341 /* On entry to the outer level, run the startup file */
1342 if (!NILP (Vtop_level
))
1343 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
1344 else if (!NILP (Vpurify_flag
))
1345 message ("Bare impure Emacs (standard Lisp code not loaded)");
1347 message ("Bare Emacs (standard Lisp code not loaded)");
1351 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
1352 doc
: /* Exit all recursive editing levels. */)
1355 #ifdef HAVE_X_WINDOWS
1356 if (display_hourglass_p
)
1357 cancel_hourglass ();
1360 /* Unblock input if we enter with input blocked. This may happen if
1361 redisplay traps e.g. during tool-bar update with input blocked. */
1362 while (INPUT_BLOCKED_P
)
1365 return Fthrow (Qtop_level
, Qnil
);
1368 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
1369 doc
: /* Exit from the innermost recursive edit or minibuffer. */)
1372 if (command_loop_level
> 0 || minibuf_level
> 0)
1373 Fthrow (Qexit
, Qnil
);
1375 error ("No recursive edit is in progress");
1379 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
1380 doc
: /* Abort the command that requested this recursive edit or minibuffer input. */)
1383 if (command_loop_level
> 0 || minibuf_level
> 0)
1386 error ("No recursive edit is in progress");
1392 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
1393 of this function. */
1396 tracking_off (old_value
)
1397 Lisp_Object old_value
;
1399 do_mouse_tracking
= old_value
;
1400 if (NILP (old_value
))
1402 /* Redisplay may have been preempted because there was input
1403 available, and it assumes it will be called again after the
1404 input has been processed. If the only input available was
1405 the sort that we have just disabled, then we need to call
1407 if (!readable_events (READABLE_EVENTS_DO_TIMERS_NOW
))
1409 redisplay_preserve_echo_area (6);
1410 get_input_pending (&input_pending
,
1411 READABLE_EVENTS_DO_TIMERS_NOW
);
1417 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
1418 doc
: /* Evaluate BODY with mouse movement events enabled.
1419 Within a `track-mouse' form, mouse motion generates input events that
1420 you can read with `read-event'.
1421 Normally, mouse motion is ignored.
1422 usage: (track-mouse BODY ...) */)
1426 int count
= SPECPDL_INDEX ();
1429 record_unwind_protect (tracking_off
, do_mouse_tracking
);
1431 do_mouse_tracking
= Qt
;
1433 val
= Fprogn (args
);
1434 return unbind_to (count
, val
);
1437 /* If mouse has moved on some frame, return one of those frames.
1438 Return 0 otherwise. */
1443 Lisp_Object tail
, frame
;
1445 FOR_EACH_FRAME (tail
, frame
)
1447 if (XFRAME (frame
)->mouse_moved
)
1448 return XFRAME (frame
);
1454 #endif /* HAVE_MOUSE */
1456 /* This is the actual command reading loop,
1457 sans error-handling encapsulation. */
1459 static int read_key_sequence
P_ ((Lisp_Object
*, int, Lisp_Object
,
1461 void safe_run_hooks
P_ ((Lisp_Object
));
1462 static void adjust_point_for_property
P_ ((int, int));
1464 /* Cancel hourglass from protect_unwind.
1466 #ifdef HAVE_X_WINDOWS
1468 cancel_hourglass_unwind (arg
)
1471 cancel_hourglass ();
1482 Lisp_Object keybuf
[30];
1485 int prev_modiff
= 0;
1486 struct buffer
*prev_buffer
= NULL
;
1488 int was_locked
= single_kboard
;
1490 int already_adjusted
;
1492 current_kboard
->Vprefix_arg
= Qnil
;
1493 current_kboard
->Vlast_prefix_arg
= Qnil
;
1494 Vdeactivate_mark
= Qnil
;
1495 waiting_for_input
= 0;
1499 this_command_key_count
= 0;
1500 this_command_key_count_reset
= 0;
1501 this_single_command_key_start
= 0;
1503 if (NILP (Vmemory_full
))
1505 /* Make sure this hook runs after commands that get errors and
1506 throw to top level. */
1507 /* Note that the value cell will never directly contain nil
1508 if the symbol is a local variable. */
1509 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1510 safe_run_hooks (Qpost_command_hook
);
1512 /* If displaying a message, resize the echo area window to fit
1513 that message's size exactly. */
1514 if (!NILP (echo_area_buffer
[0]))
1515 resize_echo_area_exactly ();
1517 if (!NILP (Vdeferred_action_list
))
1518 safe_run_hooks (Qdeferred_action_function
);
1521 /* Do this after running Vpost_command_hook, for consistency. */
1522 current_kboard
->Vlast_command
= Vthis_command
;
1523 current_kboard
->Vreal_last_command
= real_this_command
;
1527 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
1530 /* Make sure the current window's buffer is selected. */
1531 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1532 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1534 /* Display any malloc warning that just came out. Use while because
1535 displaying one warning can cause another. */
1537 while (pending_malloc_warning
)
1538 display_malloc_warning ();
1542 Vdeactivate_mark
= Qnil
;
1544 /* If minibuffer on and echo area in use,
1545 wait a short time and redraw minibuffer. */
1548 && !NILP (echo_area_buffer
[0])
1549 && EQ (minibuf_window
, echo_area_window
))
1551 /* Bind inhibit-quit to t so that C-g gets read in
1552 rather than quitting back to the minibuffer. */
1553 int count
= SPECPDL_INDEX ();
1554 specbind (Qinhibit_quit
, Qt
);
1556 if (NUMBERP (Vminibuffer_message_timeout
))
1557 sit_for (Vminibuffer_message_timeout
, 0, 2);
1561 /* Clear the echo area. */
1563 safe_run_hooks (Qecho_area_clear_hook
);
1565 unbind_to (count
, Qnil
);
1567 /* If a C-g came in before, treat it as input now. */
1568 if (!NILP (Vquit_flag
))
1571 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1576 alloca (0); /* Cause a garbage collection now */
1577 /* Since we can free the most stuff here. */
1578 #endif /* C_ALLOCA */
1581 /* Select the frame that the last event came from. Usually,
1582 switch-frame events will take care of this, but if some lisp
1583 code swallows a switch-frame event, we'll fix things up here.
1584 Is this a good idea? */
1585 if (FRAMEP (internal_last_event_frame
)
1586 && !EQ (internal_last_event_frame
, selected_frame
))
1587 Fselect_frame (internal_last_event_frame
);
1589 /* If it has changed current-menubar from previous value,
1590 really recompute the menubar from the value. */
1591 if (! NILP (Vlucid_menu_bar_dirty_flag
)
1592 && !NILP (Ffboundp (Qrecompute_lucid_menubar
)))
1593 call0 (Qrecompute_lucid_menubar
);
1595 before_command_key_count
= this_command_key_count
;
1596 before_command_echo_length
= echo_length ();
1598 Vthis_command
= Qnil
;
1599 real_this_command
= Qnil
;
1600 Vthis_original_command
= Qnil
;
1602 /* Read next key sequence; i gets its length. */
1603 i
= read_key_sequence (keybuf
, sizeof keybuf
/ sizeof keybuf
[0],
1606 /* A filter may have run while we were reading the input. */
1607 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
1609 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1610 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1614 /* Now we have read a key sequence of length I,
1615 or else I is 0 and we found end of file. */
1617 if (i
== 0) /* End of file -- happens only in */
1618 return Qnil
; /* a kbd macro, at the end. */
1619 /* -1 means read_key_sequence got a menu that was rejected.
1620 Just loop around and read another command. */
1624 this_command_key_count
= 0;
1625 this_command_key_count_reset
= 0;
1626 this_single_command_key_start
= 0;
1630 last_command_char
= keybuf
[i
- 1];
1632 /* If the previous command tried to force a specific window-start,
1633 forget about that, in case this command moves point far away
1634 from that position. But also throw away beg_unchanged and
1635 end_unchanged information in that case, so that redisplay will
1636 update the whole window properly. */
1637 if (!NILP (XWINDOW (selected_window
)->force_start
))
1640 XWINDOW (selected_window
)->force_start
= Qnil
;
1641 b
= XBUFFER (XWINDOW (selected_window
)->buffer
);
1642 BUF_BEG_UNCHANGED (b
) = BUF_END_UNCHANGED (b
) = 0;
1645 cmd
= read_key_sequence_cmd
;
1646 if (!NILP (Vexecuting_kbd_macro
))
1648 if (!NILP (Vquit_flag
))
1650 Vexecuting_kbd_macro
= Qt
;
1651 QUIT
; /* Make some noise. */
1652 /* Will return since macro now empty. */
1656 /* Do redisplay processing after this command except in special
1657 cases identified below. */
1658 prev_buffer
= current_buffer
;
1659 prev_modiff
= MODIFF
;
1660 last_point_position
= PT
;
1661 last_point_position_window
= selected_window
;
1662 XSETBUFFER (last_point_position_buffer
, prev_buffer
);
1664 /* By default, we adjust point to a boundary of a region that
1665 has such a property that should be treated intangible
1666 (e.g. composition, display). But, some commands will set
1667 this variable differently. */
1668 Vdisable_point_adjustment
= Qnil
;
1670 /* Process filters and timers may have messed with deactivate-mark.
1671 reset it before we execute the command. */
1672 Vdeactivate_mark
= Qnil
;
1674 /* Remap command through active keymaps */
1675 Vthis_original_command
= cmd
;
1679 if (cmd1
= Fcommand_remapping (cmd
, Qnil
), !NILP (cmd1
))
1683 /* Execute the command. */
1685 Vthis_command
= cmd
;
1686 real_this_command
= cmd
;
1687 /* Note that the value cell will never directly contain nil
1688 if the symbol is a local variable. */
1689 if (!NILP (Vpre_command_hook
) && !NILP (Vrun_hooks
))
1690 safe_run_hooks (Qpre_command_hook
);
1692 already_adjusted
= 0;
1694 if (NILP (Vthis_command
))
1696 /* nil means key is undefined. */
1697 Lisp_Object keys
= Fvector (i
, keybuf
);
1698 keys
= Fkey_description (keys
, Qnil
);
1700 message_with_string ("%s is undefined", keys
, 0);
1701 current_kboard
->defining_kbd_macro
= Qnil
;
1702 update_mode_lines
= 1;
1703 current_kboard
->Vprefix_arg
= Qnil
;
1707 if (NILP (current_kboard
->Vprefix_arg
) && ! no_direct
)
1709 /* In case we jump to directly_done. */
1710 Vcurrent_prefix_arg
= current_kboard
->Vprefix_arg
;
1712 /* Recognize some common commands in common situations and
1713 do them directly. */
1714 if (EQ (Vthis_command
, Qforward_char
) && PT
< ZV
)
1716 struct Lisp_Char_Table
*dp
1717 = window_display_table (XWINDOW (selected_window
));
1718 lose
= FETCH_CHAR (PT_BYTE
);
1720 if (! NILP (Vpost_command_hook
))
1721 /* Put this before calling adjust_point_for_property
1722 so it will only get called once in any case. */
1724 if (current_buffer
== prev_buffer
1725 && last_point_position
!= PT
1726 && NILP (Vdisable_point_adjustment
)
1727 && NILP (Vglobal_disable_point_adjustment
))
1728 adjust_point_for_property (last_point_position
, 0);
1729 already_adjusted
= 1;
1730 if (PT
== last_point_position
+ 1
1732 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1733 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1734 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1735 && (lose
>= 0x20 && lose
< 0x7f)))
1736 : (lose
>= 0x20 && lose
< 0x7f))
1737 /* To extract the case of continuation on
1738 wide-column characters. */
1739 && (WIDTH_BY_CHAR_HEAD (FETCH_BYTE (PT_BYTE
)) == 1)
1740 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1742 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1744 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1746 && !windows_or_buffers_changed
1747 && EQ (current_buffer
->selective_display
, Qnil
)
1748 && !detect_input_pending ()
1749 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1750 && NILP (Vexecuting_kbd_macro
))
1751 direct_output_forward_char (1);
1754 else if (EQ (Vthis_command
, Qbackward_char
) && PT
> BEGV
)
1756 struct Lisp_Char_Table
*dp
1757 = window_display_table (XWINDOW (selected_window
));
1759 lose
= FETCH_CHAR (PT_BYTE
);
1760 if (! NILP (Vpost_command_hook
))
1762 if (current_buffer
== prev_buffer
1763 && last_point_position
!= PT
1764 && NILP (Vdisable_point_adjustment
)
1765 && NILP (Vglobal_disable_point_adjustment
))
1766 adjust_point_for_property (last_point_position
, 0);
1767 already_adjusted
= 1;
1768 if (PT
== last_point_position
- 1
1770 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1771 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1772 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1773 && (lose
>= 0x20 && lose
< 0x7f)))
1774 : (lose
>= 0x20 && lose
< 0x7f))
1775 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1777 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1779 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1781 && !windows_or_buffers_changed
1782 && EQ (current_buffer
->selective_display
, Qnil
)
1783 && !detect_input_pending ()
1784 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1785 && NILP (Vexecuting_kbd_macro
))
1786 direct_output_forward_char (-1);
1789 else if (EQ (Vthis_command
, Qself_insert_command
)
1790 /* Try this optimization only on char keystrokes. */
1791 && NATNUMP (last_command_char
)
1792 && CHAR_VALID_P (XFASTINT (last_command_char
), 0))
1795 = translate_char (Vtranslation_table_for_input
,
1796 XFASTINT (last_command_char
), 0, 0, 0);
1798 if (NILP (Vexecuting_kbd_macro
)
1799 && !EQ (minibuf_window
, selected_window
))
1801 if (!nonundocount
|| nonundocount
>= 20)
1809 lose
= ((XFASTINT (XWINDOW (selected_window
)->last_modified
)
1811 || (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1813 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1815 || MODIFF
<= SAVE_MODIFF
1816 || windows_or_buffers_changed
1817 || !EQ (current_buffer
->selective_display
, Qnil
)
1818 || detect_input_pending ()
1819 || !NILP (XWINDOW (selected_window
)->column_number_displayed
)
1820 || !NILP (Vexecuting_kbd_macro
));
1822 value
= internal_self_insert (c
, 0);
1827 if (! NILP (Vpost_command_hook
))
1828 /* Put this before calling adjust_point_for_property
1829 so it will only get called once in any case. */
1832 /* VALUE == 1 when AFTER-CHANGE functions are
1833 installed which is the case most of the time
1834 because FONT-LOCK installs one. */
1835 if (!lose
&& !value
)
1836 direct_output_for_insert (c
);
1841 /* Here for a command that isn't executed directly */
1844 #ifdef HAVE_X_WINDOWS
1845 int scount
= SPECPDL_INDEX ();
1847 if (display_hourglass_p
1848 && NILP (Vexecuting_kbd_macro
))
1850 record_unwind_protect (cancel_hourglass_unwind
, Qnil
);
1856 if (NILP (current_kboard
->Vprefix_arg
))
1858 Fcommand_execute (Vthis_command
, Qnil
, Qnil
, Qnil
);
1860 #ifdef HAVE_X_WINDOWS
1861 /* Do not check display_hourglass_p here, because
1862 Fcommand_execute could change it, but we should cancel
1863 hourglass cursor anyway.
1864 But don't cancel the hourglass within a macro
1865 just because a command in the macro finishes. */
1866 if (NILP (Vexecuting_kbd_macro
))
1867 unbind_to (scount
, Qnil
);
1872 current_kboard
->Vlast_prefix_arg
= Vcurrent_prefix_arg
;
1874 /* Note that the value cell will never directly contain nil
1875 if the symbol is a local variable. */
1876 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1877 safe_run_hooks (Qpost_command_hook
);
1879 /* If displaying a message, resize the echo area window to fit
1880 that message's size exactly. */
1881 if (!NILP (echo_area_buffer
[0]))
1882 resize_echo_area_exactly ();
1884 if (!NILP (Vdeferred_action_list
))
1885 safe_run_hooks (Qdeferred_action_function
);
1887 /* If there is a prefix argument,
1888 1) We don't want Vlast_command to be ``universal-argument''
1889 (that would be dumb), so don't set Vlast_command,
1890 2) we want to leave echoing on so that the prefix will be
1891 echoed as part of this key sequence, so don't call
1893 3) we want to leave this_command_key_count non-zero, so that
1894 read_char will realize that it is re-reading a character, and
1895 not echo it a second time.
1897 If the command didn't actually create a prefix arg,
1898 but is merely a frame event that is transparent to prefix args,
1899 then the above doesn't apply. */
1900 if (NILP (current_kboard
->Vprefix_arg
) || CONSP (last_command_char
))
1902 current_kboard
->Vlast_command
= Vthis_command
;
1903 current_kboard
->Vreal_last_command
= real_this_command
;
1905 this_command_key_count
= 0;
1906 this_command_key_count_reset
= 0;
1907 this_single_command_key_start
= 0;
1910 if (!NILP (current_buffer
->mark_active
) && !NILP (Vrun_hooks
))
1912 /* Setting transient-mark-mode to `only' is a way of
1913 turning it on for just one command. */
1915 if (EQ (Vtransient_mark_mode
, Qidentity
))
1916 Vtransient_mark_mode
= Qnil
;
1917 if (EQ (Vtransient_mark_mode
, Qonly
))
1918 Vtransient_mark_mode
= Qidentity
;
1920 if (!NILP (Vdeactivate_mark
) && !NILP (Vtransient_mark_mode
))
1922 /* We could also call `deactivate'mark'. */
1923 if (EQ (Vtransient_mark_mode
, Qlambda
))
1924 Vtransient_mark_mode
= Qnil
;
1927 current_buffer
->mark_active
= Qnil
;
1928 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
1931 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
1932 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
1937 if (current_buffer
== prev_buffer
1938 && last_point_position
!= PT
1939 && NILP (Vdisable_point_adjustment
)
1940 && NILP (Vglobal_disable_point_adjustment
)
1941 && !already_adjusted
)
1942 adjust_point_for_property (last_point_position
, MODIFF
!= prev_modiff
);
1944 /* Install chars successfully executed in kbd macro. */
1946 if (!NILP (current_kboard
->defining_kbd_macro
)
1947 && NILP (current_kboard
->Vprefix_arg
))
1948 finalize_kbd_macro_chars ();
1952 any_kboard_state ();
1957 extern Lisp_Object Qcomposition
, Qdisplay
;
1959 /* Adjust point to a boundary of a region that has such a property
1960 that should be treated intangible. For the moment, we check
1961 `composition', `display' and `invisible' properties.
1962 LAST_PT is the last position of point. */
1964 extern Lisp_Object Qafter_string
, Qbefore_string
;
1965 extern Lisp_Object get_pos_property
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
));
1968 adjust_point_for_property (last_pt
, modified
)
1973 Lisp_Object val
, overlay
, tmp
;
1974 int check_composition
= 1, check_display
= 1, check_invisible
= 1;
1977 /* FIXME: cycling is probably not necessary because these properties
1978 can't be usefully combined anyway. */
1979 while (check_composition
|| check_display
|| check_invisible
)
1981 if (check_composition
1982 && PT
> BEGV
&& PT
< ZV
1983 && get_property_and_range (PT
, Qcomposition
, &val
, &beg
, &end
, Qnil
)
1984 && COMPOSITION_VALID_P (beg
, end
, val
)
1985 && beg
< PT
/* && end > PT <- It's always the case. */
1986 && (last_pt
<= beg
|| last_pt
>= end
))
1989 SET_PT (PT
< last_pt
? beg
: end
);
1990 check_display
= check_invisible
= 1;
1992 check_composition
= 0;
1994 && PT
> BEGV
&& PT
< ZV
1995 && !NILP (val
= get_char_property_and_overlay
1996 (make_number (PT
), Qdisplay
, Qnil
, &overlay
))
1997 && display_prop_intangible_p (val
)
1998 && (!OVERLAYP (overlay
)
1999 ? get_property_and_range (PT
, Qdisplay
, &val
, &beg
, &end
, Qnil
)
2000 : (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)),
2001 end
= OVERLAY_POSITION (OVERLAY_END (overlay
))))
2002 && (beg
< PT
/* && end > PT <- It's always the case. */
2003 || (beg
<= PT
&& STRINGP (val
) && SCHARS (val
) == 0)))
2006 SET_PT (PT
< last_pt
2007 ? (STRINGP (val
) && SCHARS (val
) == 0 ? beg
- 1 : beg
)
2009 check_composition
= check_invisible
= 1;
2012 if (check_invisible
&& PT
> BEGV
&& PT
< ZV
)
2014 int inv
, ellipsis
= 0;
2017 /* Find boundaries `beg' and `end' of the invisible area, if any. */
2019 && !NILP (val
= get_char_property_and_overlay
2020 (make_number (end
), Qinvisible
, Qnil
, &overlay
))
2021 && (inv
= TEXT_PROP_MEANS_INVISIBLE (val
)))
2023 ellipsis
= ellipsis
|| inv
> 1
2024 || (OVERLAYP (overlay
)
2025 && (!NILP (Foverlay_get (overlay
, Qafter_string
))
2026 || !NILP (Foverlay_get (overlay
, Qbefore_string
))));
2027 tmp
= Fnext_single_char_property_change
2028 (make_number (end
), Qinvisible
, Qnil
, Qnil
);
2029 end
= NATNUMP (tmp
) ? XFASTINT (tmp
) : ZV
;
2032 && !NILP (val
= get_char_property_and_overlay
2033 (make_number (beg
- 1), Qinvisible
, Qnil
, &overlay
))
2034 && (inv
= TEXT_PROP_MEANS_INVISIBLE (val
)))
2036 ellipsis
= ellipsis
|| inv
> 1
2037 || (OVERLAYP (overlay
)
2038 && (!NILP (Foverlay_get (overlay
, Qafter_string
))
2039 || !NILP (Foverlay_get (overlay
, Qbefore_string
))));
2040 tmp
= Fprevious_single_char_property_change
2041 (make_number (beg
), Qinvisible
, Qnil
, Qnil
);
2042 beg
= NATNUMP (tmp
) ? XFASTINT (tmp
) : BEGV
;
2045 /* Move away from the inside area. */
2046 if (beg
< PT
&& end
> PT
)
2048 SET_PT ((orig_pt
== PT
&& (last_pt
< beg
|| last_pt
> end
))
2049 /* We haven't moved yet (so we don't need to fear
2050 infinite-looping) and we were outside the range
2051 before (so either end of the range still corresponds
2052 to a move in the right direction): pretend we moved
2053 less than we actually did, so that we still have
2054 more freedom below in choosing which end of the range
2056 ? (orig_pt
= -1, PT
< last_pt
? end
: beg
)
2057 /* We either have moved already or the last point
2058 was already in the range: we don't get to choose
2059 which end of the range we have to go to. */
2060 : (PT
< last_pt
? beg
: end
));
2061 check_composition
= check_display
= 1;
2063 #if 0 /* This assertion isn't correct, because SET_PT may end up setting
2064 the point to something other than its argument, due to
2065 point-motion hooks, intangibility, etc. */
2066 xassert (PT
== beg
|| PT
== end
);
2069 /* Pretend the area doesn't exist if the buffer is not
2071 if (!modified
&& !ellipsis
&& beg
< end
)
2073 if (last_pt
== beg
&& PT
== end
&& end
< ZV
)
2074 (check_composition
= check_display
= 1, SET_PT (end
+ 1));
2075 else if (last_pt
== end
&& PT
== beg
&& beg
> BEGV
)
2076 (check_composition
= check_display
= 1, SET_PT (beg
- 1));
2077 else if (PT
== ((PT
< last_pt
) ? beg
: end
))
2078 /* We've already moved as far as we can. Trying to go
2079 to the other end would mean moving backwards and thus
2080 could lead to an infinite loop. */
2082 else if (val
= get_pos_property (make_number (PT
),
2084 TEXT_PROP_MEANS_INVISIBLE (val
)
2085 && (val
= get_pos_property
2086 (make_number (PT
== beg
? end
: beg
),
2088 !TEXT_PROP_MEANS_INVISIBLE (val
)))
2089 (check_composition
= check_display
= 1,
2090 SET_PT (PT
== beg
? end
: beg
));
2093 check_invisible
= 0;
2097 /* Subroutine for safe_run_hooks: run the hook HOOK. */
2100 safe_run_hooks_1 (hook
)
2103 if (NILP (Vrun_hooks
))
2105 return call1 (Vrun_hooks
, Vinhibit_quit
);
2108 /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */
2111 safe_run_hooks_error (data
)
2114 Lisp_Object args
[3];
2115 args
[0] = build_string ("Error in %s: %s");
2116 args
[1] = Vinhibit_quit
;
2119 return Fset (Vinhibit_quit
, Qnil
);
2122 /* If we get an error while running the hook, cause the hook variable
2123 to be nil. Also inhibit quits, so that C-g won't cause the hook
2124 to mysteriously evaporate. */
2127 safe_run_hooks (hook
)
2130 int count
= SPECPDL_INDEX ();
2131 specbind (Qinhibit_quit
, hook
);
2133 internal_condition_case (safe_run_hooks_1
, Qt
, safe_run_hooks_error
);
2135 unbind_to (count
, Qnil
);
2139 /* Number of seconds between polling for input. This is a Lisp
2140 variable that can be bound. */
2142 EMACS_INT polling_period
;
2144 /* Nonzero means polling for input is temporarily suppressed. */
2146 int poll_suppress_count
;
2148 /* Asynchronous timer for polling. */
2150 struct atimer
*poll_timer
;
2153 #ifdef POLL_FOR_INPUT
2155 /* Poll for input, so what we catch a C-g if it comes in. This
2156 function is called from x_make_frame_visible, see comment
2162 if (interrupt_input_blocked
== 0
2163 && !waiting_for_input
)
2164 read_avail_input (0);
2167 /* Timer callback function for poll_timer. TIMER is equal to
2171 poll_for_input (timer
)
2172 struct atimer
*timer
;
2174 if (poll_suppress_count
== 0)
2176 interrupt_input_pending
= 1;
2178 poll_for_input_1 ();
2182 #endif /* POLL_FOR_INPUT */
2184 /* Begin signals to poll for input, if they are appropriate.
2185 This function is called unconditionally from various places. */
2190 #ifdef POLL_FOR_INPUT
2191 if (read_socket_hook
&& !interrupt_input
)
2193 /* Turn alarm handling on unconditionally. It might have
2194 been turned off in process.c. */
2195 turn_on_atimers (1);
2197 /* If poll timer doesn't exist, are we need one with
2198 a different interval, start a new one. */
2199 if (poll_timer
== NULL
2200 || EMACS_SECS (poll_timer
->interval
) != polling_period
)
2202 EMACS_TIME interval
;
2205 cancel_atimer (poll_timer
);
2207 EMACS_SET_SECS_USECS (interval
, polling_period
, 0);
2208 poll_timer
= start_atimer (ATIMER_CONTINUOUS
, interval
,
2209 poll_for_input
, NULL
);
2212 /* Let the timer's callback function poll for input
2213 if this becomes zero. */
2214 --poll_suppress_count
;
2219 /* Nonzero if we are using polling to handle input asynchronously. */
2222 input_polling_used ()
2224 #ifdef POLL_FOR_INPUT
2225 return read_socket_hook
&& !interrupt_input
;
2231 /* Turn off polling. */
2236 #ifdef POLL_FOR_INPUT
2237 if (read_socket_hook
&& !interrupt_input
)
2238 ++poll_suppress_count
;
2242 /* Set the value of poll_suppress_count to COUNT
2243 and start or stop polling accordingly. */
2246 set_poll_suppress_count (count
)
2249 #ifdef POLL_FOR_INPUT
2250 if (count
== 0 && poll_suppress_count
!= 0)
2252 poll_suppress_count
= 1;
2255 else if (count
!= 0 && poll_suppress_count
== 0)
2259 poll_suppress_count
= count
;
2263 /* Bind polling_period to a value at least N.
2264 But don't decrease it. */
2267 bind_polling_period (n
)
2270 #ifdef POLL_FOR_INPUT
2271 int new = polling_period
;
2276 stop_other_atimers (poll_timer
);
2278 specbind (Qpolling_period
, make_number (new));
2279 /* Start a new alarm with the new period. */
2284 /* Apply the control modifier to CHARACTER. */
2290 /* Save the upper bits here. */
2291 int upper
= c
& ~0177;
2295 /* Everything in the columns containing the upper-case letters
2296 denotes a control character. */
2297 if (c
>= 0100 && c
< 0140)
2301 /* Set the shift modifier for a control char
2302 made from a shifted letter. But only for letters! */
2303 if (oc
>= 'A' && oc
<= 'Z')
2304 c
|= shift_modifier
;
2307 /* The lower-case letters denote control characters too. */
2308 else if (c
>= 'a' && c
<= 'z')
2311 /* Include the bits for control and shift
2312 only if the basic ASCII code can't indicate them. */
2316 /* Replace the high bits. */
2317 c
|= (upper
& ~ctrl_modifier
);
2322 /* Display the help-echo property of the character after the mouse pointer.
2323 Either show it in the echo area, or call show-help-function to display
2324 it by other means (maybe in a tooltip).
2326 If HELP is nil, that means clear the previous help echo.
2328 If HELP is a string, display that string. If HELP is a function,
2329 call it with OBJECT and POS as arguments; the function should
2330 return a help string or nil for none. For all other types of HELP,
2331 evaluate it to obtain a string.
2333 WINDOW is the window in which the help was generated, if any.
2334 It is nil if not in a window.
2336 If OBJECT is a buffer, POS is the position in the buffer where the
2337 `help-echo' text property was found.
2339 If OBJECT is an overlay, that overlay has a `help-echo' property,
2340 and POS is the position in the overlay's buffer under the mouse.
2342 If OBJECT is a string (an overlay string or a string displayed with
2343 the `display' property). POS is the position in that string under
2346 OK_TO_OVERWRITE_KEYSTROKE_ECHO non-zero means it's okay if the help
2347 echo overwrites a keystroke echo currently displayed in the echo
2350 Note: this function may only be called with HELP nil or a string
2351 from X code running asynchronously. */
2354 show_help_echo (help
, window
, object
, pos
, ok_to_overwrite_keystroke_echo
)
2355 Lisp_Object help
, window
, object
, pos
;
2356 int ok_to_overwrite_keystroke_echo
;
2358 if (!NILP (help
) && !STRINGP (help
))
2360 if (FUNCTIONP (help
))
2362 Lisp_Object args
[4];
2367 help
= safe_call (4, args
);
2370 help
= safe_eval (help
);
2372 if (!STRINGP (help
))
2377 if (!noninteractive
&& STRINGP (help
))
2379 /* The mouse-fixup-help-message Lisp function can call
2380 mouse_position_hook, which resets the mouse_moved flags.
2381 This causes trouble if we are trying to read a mouse motion
2382 event (i.e., if we are inside a `track-mouse' form), so we
2383 restore the mouse_moved flag. */
2384 FRAME_PTR f
= NILP (do_mouse_tracking
) ? NULL
: some_mouse_moved ();
2385 help
= call1 (Qmouse_fixup_help_message
, help
);
2391 if (STRINGP (help
) || NILP (help
))
2393 if (!NILP (Vshow_help_function
))
2394 call1 (Vshow_help_function
, help
);
2395 else if (/* Don't overwrite minibuffer contents. */
2396 !MINI_WINDOW_P (XWINDOW (selected_window
))
2397 /* Don't overwrite a keystroke echo. */
2398 && (NILP (echo_message_buffer
)
2399 || ok_to_overwrite_keystroke_echo
)
2400 /* Don't overwrite a prompt. */
2401 && !cursor_in_echo_area
)
2405 int count
= SPECPDL_INDEX ();
2407 if (!help_echo_showing_p
)
2408 Vpre_help_message
= current_message ();
2410 specbind (Qmessage_truncate_lines
, Qt
);
2411 message3_nolog (help
, SBYTES (help
),
2412 STRING_MULTIBYTE (help
));
2413 unbind_to (count
, Qnil
);
2415 else if (STRINGP (Vpre_help_message
))
2417 message3_nolog (Vpre_help_message
,
2418 SBYTES (Vpre_help_message
),
2419 STRING_MULTIBYTE (Vpre_help_message
));
2420 Vpre_help_message
= Qnil
;
2426 help_echo_showing_p
= STRINGP (help
);
2432 /* Input of single characters from keyboard */
2434 Lisp_Object
print_help ();
2435 static Lisp_Object
kbd_buffer_get_event ();
2436 static void record_char ();
2439 static jmp_buf wrong_kboard_jmpbuf
;
2442 #define STOP_POLLING \
2443 do { if (! polling_stopped_here) stop_polling (); \
2444 polling_stopped_here = 1; } while (0)
2446 #define RESUME_POLLING \
2447 do { if (polling_stopped_here) start_polling (); \
2448 polling_stopped_here = 0; } while (0)
2450 /* read a character from the keyboard; call the redisplay if needed */
2451 /* commandflag 0 means do not do auto-saving, but do do redisplay.
2452 -1 means do not do redisplay, but do do autosaving.
2455 /* The arguments MAPS and NMAPS are for menu prompting.
2456 MAPS is an array of keymaps; NMAPS is the length of MAPS.
2458 PREV_EVENT is the previous input event, or nil if we are reading
2459 the first event of a key sequence (or not reading a key sequence).
2460 If PREV_EVENT is t, that is a "magic" value that says
2461 not to run input methods, but in other respects to act as if
2462 not reading a key sequence.
2464 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
2465 if we used a mouse menu to read the input, or zero otherwise. If
2466 USED_MOUSE_MENU is null, we don't dereference it.
2468 If END_TIME is non-null, it is a pointer to an EMACS_TIME
2469 specifying the maximum time to wait until. If no input arrives by
2470 that time, stop waiting and return nil.
2472 Value is t if we showed a menu and the user rejected it. */
2475 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
, end_time
)
2479 Lisp_Object prev_event
;
2480 int *used_mouse_menu
;
2481 EMACS_TIME
*end_time
;
2483 volatile Lisp_Object c
;
2484 int count
, jmpcount
;
2485 jmp_buf local_getcjmp
;
2487 volatile int key_already_recorded
= 0;
2488 Lisp_Object tem
, save
;
2489 volatile Lisp_Object previous_echo_area_message
;
2490 volatile Lisp_Object also_record
;
2491 volatile int reread
;
2492 struct gcpro gcpro1
, gcpro2
;
2493 int polling_stopped_here
= 0;
2497 #if 0 /* This was commented out as part of fixing echo for C-u left. */
2498 before_command_key_count
= this_command_key_count
;
2499 before_command_echo_length
= echo_length ();
2502 previous_echo_area_message
= Qnil
;
2504 GCPRO2 (c
, previous_echo_area_message
);
2509 if (CONSP (Vunread_post_input_method_events
))
2511 c
= XCAR (Vunread_post_input_method_events
);
2512 Vunread_post_input_method_events
2513 = XCDR (Vunread_post_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
)))
2526 if (unread_command_char
!= -1)
2528 XSETINT (c
, unread_command_char
);
2529 unread_command_char
= -1;
2535 if (CONSP (Vunread_command_events
))
2537 c
= XCAR (Vunread_command_events
);
2538 Vunread_command_events
= XCDR (Vunread_command_events
);
2542 /* Undo what sit-for did when it unread additional keys
2543 inside universal-argument. */
2546 && EQ (XCAR (c
), Qt
))
2552 /* Undo what read_char_x_menu_prompt did when it unread
2553 additional keys returned by Fx_popup_menu. */
2555 && EQ (XCDR (c
), Qdisabled
)
2556 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
))))
2559 /* If the queued event is something that used the mouse,
2560 set used_mouse_menu accordingly. */
2562 && (EQ (c
, Qtool_bar
) || EQ (c
, Qmenu_bar
)))
2563 *used_mouse_menu
= 1;
2565 goto reread_for_input_method
;
2568 if (CONSP (Vunread_input_method_events
))
2570 c
= XCAR (Vunread_input_method_events
);
2571 Vunread_input_method_events
= XCDR (Vunread_input_method_events
);
2573 /* Undo what read_char_x_menu_prompt did when it unread
2574 additional keys returned by Fx_popup_menu. */
2576 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
)))
2580 goto reread_for_input_method
;
2583 this_command_key_count_reset
= 0;
2585 if (!NILP (Vexecuting_kbd_macro
))
2587 /* We set this to Qmacro; since that's not a frame, nobody will
2588 try to switch frames on us, and the selected window will
2591 Since this event came from a macro, it would be misleading to
2592 leave internal_last_event_frame set to wherever the last
2593 real event came from. Normally, a switch-frame event selects
2594 internal_last_event_frame after each command is read, but
2595 events read from a macro should never cause a new frame to be
2597 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
2599 /* Exit the macro if we are at the end.
2600 Also, some things replace the macro with t
2601 to force an early exit. */
2602 if (EQ (Vexecuting_kbd_macro
, Qt
)
2603 || executing_kbd_macro_index
>= XFASTINT (Flength (Vexecuting_kbd_macro
)))
2609 c
= Faref (Vexecuting_kbd_macro
, make_number (executing_kbd_macro_index
));
2610 if (STRINGP (Vexecuting_kbd_macro
)
2611 && (XINT (c
) & 0x80) && (XUINT (c
) <= 0xff))
2612 XSETFASTINT (c
, CHAR_META
| (XINT (c
) & ~0x80));
2614 executing_kbd_macro_index
++;
2619 if (!NILP (unread_switch_frame
))
2621 c
= unread_switch_frame
;
2622 unread_switch_frame
= Qnil
;
2624 /* This event should make it into this_command_keys, and get echoed
2625 again, so we do not set `reread'. */
2629 /* if redisplay was requested */
2630 if (commandflag
>= 0)
2632 /* If there is pending input, process any events which are not
2633 user-visible, such as X selection_request events. */
2635 || detect_input_pending_run_timers (0))
2636 swallow_events (0); /* may clear input_pending */
2638 /* Redisplay if no pending input. */
2639 while (!input_pending
)
2641 if (help_echo_showing_p
&& !EQ (selected_window
, minibuf_window
))
2642 redisplay_preserve_echo_area (5);
2647 /* Normal case: no input arrived during redisplay. */
2650 /* Input arrived and pre-empted redisplay.
2651 Process any events which are not user-visible. */
2653 /* If that cleared input_pending, try again to redisplay. */
2657 /* Message turns off echoing unless more keystrokes turn it on again.
2659 The code in 20.x for the condition was
2661 1. echo_area_glyphs && *echo_area_glyphs
2662 2. && echo_area_glyphs != current_kboard->echobuf
2663 3. && ok_to_echo_at_next_pause != echo_area_glyphs
2665 (1) means there's a current message displayed
2667 (2) means it's not the message from echoing from the current
2670 (3) There's only one place in 20.x where ok_to_echo_at_next_pause
2671 is set to a non-null value. This is done in read_char and it is
2672 set to echo_area_glyphs after a call to echo_char. That means
2673 ok_to_echo_at_next_pause is either null or
2674 current_kboard->echobuf with the appropriate current_kboard at
2677 So, condition (3) means in clear text ok_to_echo_at_next_pause
2678 must be either null, or the current message isn't from echoing at
2679 all, or it's from echoing from a different kboard than the
2682 if (/* There currently is something in the echo area. */
2683 !NILP (echo_area_buffer
[0])
2684 && (/* And it's either not from echoing. */
2685 !EQ (echo_area_buffer
[0], echo_message_buffer
)
2686 /* Or it's an echo from a different kboard. */
2687 || echo_kboard
!= current_kboard
2688 /* Or we explicitly allow overwriting whatever there is. */
2689 || ok_to_echo_at_next_pause
== NULL
))
2694 /* Try reading a character via menu prompting in the minibuf.
2695 Try this before the sit-for, because the sit-for
2696 would do the wrong thing if we are supposed to do
2697 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
2698 after a mouse event so don't try a minibuf menu. */
2700 if (nmaps
> 0 && INTERACTIVE
2701 && !NILP (prev_event
) && ! EVENT_HAS_PARAMETERS (prev_event
)
2702 /* Don't bring up a menu if we already have another event. */
2703 && NILP (Vunread_command_events
)
2704 && unread_command_char
< 0
2705 && !detect_input_pending_run_timers (0))
2707 c
= read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
);
2710 key_already_recorded
= 1;
2715 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet.
2716 We will do that below, temporarily for short sections of code,
2717 when appropriate. local_getcjmp must be in effect
2718 around any call to sit_for or kbd_buffer_get_event;
2719 it *must not* be in effect when we call redisplay. */
2721 jmpcount
= SPECPDL_INDEX ();
2722 if (_setjmp (local_getcjmp
))
2724 /* We must have saved the outer value of getcjmp here,
2725 so restore it now. */
2726 restore_getcjmp (save_jump
);
2727 unbind_to (jmpcount
, Qnil
);
2728 XSETINT (c
, quit_char
);
2729 internal_last_event_frame
= selected_frame
;
2730 Vlast_event_frame
= internal_last_event_frame
;
2731 /* If we report the quit char as an event,
2732 don't do so more than once. */
2733 if (!NILP (Vinhibit_quit
))
2738 KBOARD
*kb
= FRAME_KBOARD (XFRAME (selected_frame
));
2739 if (kb
!= current_kboard
)
2741 Lisp_Object link
= kb
->kbd_queue
;
2742 /* We shouldn't get here if we were in single-kboard mode! */
2747 while (CONSP (XCDR (link
)))
2749 if (!NILP (XCDR (link
)))
2753 kb
->kbd_queue
= Fcons (c
, Qnil
);
2755 XSETCDR (link
, Fcons (c
, Qnil
));
2756 kb
->kbd_queue_has_data
= 1;
2757 current_kboard
= kb
;
2758 /* This is going to exit from read_char
2759 so we had better get rid of this frame's stuff. */
2761 longjmp (wrong_kboard_jmpbuf
, 1);
2768 /* Start idle timers if no time limit is supplied. We don't do it
2769 if a time limit is supplied to avoid an infinite recursion in the
2770 situation where an idle timer calls `sit-for'. */
2773 timer_start_idle ();
2775 /* If in middle of key sequence and minibuffer not active,
2776 start echoing if enough time elapses. */
2778 if (minibuf_level
== 0
2780 && !current_kboard
->immediate_echo
2781 && this_command_key_count
> 0
2783 && (FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
2784 && NILP (Fzerop (Vecho_keystrokes
))
2785 && (/* No message. */
2786 NILP (echo_area_buffer
[0])
2787 /* Or empty message. */
2788 || (BUF_BEG (XBUFFER (echo_area_buffer
[0]))
2789 == BUF_Z (XBUFFER (echo_area_buffer
[0])))
2790 /* Or already echoing from same kboard. */
2791 || (echo_kboard
&& ok_to_echo_at_next_pause
== echo_kboard
)
2792 /* Or not echoing before and echoing allowed. */
2793 || (!echo_kboard
&& ok_to_echo_at_next_pause
)))
2795 /* After a mouse event, start echoing right away.
2796 This is because we are probably about to display a menu,
2797 and we don't want to delay before doing so. */
2798 if (EVENT_HAS_PARAMETERS (prev_event
))
2804 save_getcjmp (save_jump
);
2805 restore_getcjmp (local_getcjmp
);
2806 tem0
= sit_for (Vecho_keystrokes
, 1, 1);
2807 restore_getcjmp (save_jump
);
2809 && ! CONSP (Vunread_command_events
))
2814 /* Maybe auto save due to number of keystrokes. */
2816 if (commandflag
!= 0
2817 && auto_save_interval
> 0
2818 && num_nonmacro_input_events
- last_auto_save
> max (auto_save_interval
, 20)
2819 && !detect_input_pending_run_timers (0))
2821 Fdo_auto_save (Qnil
, Qnil
);
2822 /* Hooks can actually change some buffers in auto save. */
2826 /* Try reading using an X menu.
2827 This is never confused with reading using the minibuf
2828 because the recursive call of read_char in read_char_minibuf_menu_prompt
2829 does not pass on any keymaps. */
2831 if (nmaps
> 0 && INTERACTIVE
2832 && !NILP (prev_event
)
2833 && EVENT_HAS_PARAMETERS (prev_event
)
2834 && !EQ (XCAR (prev_event
), Qmenu_bar
)
2835 && !EQ (XCAR (prev_event
), Qtool_bar
)
2836 /* Don't bring up a menu if we already have another event. */
2837 && NILP (Vunread_command_events
)
2838 && unread_command_char
< 0)
2840 c
= read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
2842 /* Now that we have read an event, Emacs is not idle. */
2849 /* Maybe autosave and/or garbage collect due to idleness. */
2851 if (INTERACTIVE
&& NILP (c
))
2853 int delay_level
, buffer_size
;
2855 /* Slow down auto saves logarithmically in size of current buffer,
2856 and garbage collect while we're at it. */
2857 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
2858 last_non_minibuf_size
= Z
- BEG
;
2859 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
2861 while (buffer_size
> 64)
2862 delay_level
++, buffer_size
-= buffer_size
>> 2;
2863 if (delay_level
< 4) delay_level
= 4;
2864 /* delay_level is 4 for files under around 50k, 7 at 100k,
2865 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
2867 /* Auto save if enough time goes by without input. */
2868 if (commandflag
!= 0
2869 && num_nonmacro_input_events
> last_auto_save
2870 && INTEGERP (Vauto_save_timeout
)
2871 && XINT (Vauto_save_timeout
) > 0)
2874 int timeout
= delay_level
* XFASTINT (Vauto_save_timeout
) / 4;
2876 save_getcjmp (save_jump
);
2877 restore_getcjmp (local_getcjmp
);
2878 tem0
= sit_for (make_number (timeout
), 1, 1);
2879 restore_getcjmp (save_jump
);
2882 && ! CONSP (Vunread_command_events
))
2884 Fdo_auto_save (Qnil
, Qnil
);
2886 /* If we have auto-saved and there is still no input
2887 available, garbage collect if there has been enough
2888 consing going on to make it worthwhile. */
2889 if (!detect_input_pending_run_timers (0)
2890 && consing_since_gc
> gc_cons_threshold
/ 2)
2891 Fgarbage_collect ();
2898 /* If this has become non-nil here, it has been set by a timer
2899 or sentinel or filter. */
2900 if (CONSP (Vunread_command_events
))
2902 c
= XCAR (Vunread_command_events
);
2903 Vunread_command_events
= XCDR (Vunread_command_events
);
2906 /* Read something from current KBOARD's side queue, if possible. */
2910 if (current_kboard
->kbd_queue_has_data
)
2912 if (!CONSP (current_kboard
->kbd_queue
))
2914 c
= XCAR (current_kboard
->kbd_queue
);
2915 current_kboard
->kbd_queue
2916 = XCDR (current_kboard
->kbd_queue
);
2917 if (NILP (current_kboard
->kbd_queue
))
2918 current_kboard
->kbd_queue_has_data
= 0;
2919 input_pending
= readable_events (0);
2920 if (EVENT_HAS_PARAMETERS (c
)
2921 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qswitch_frame
))
2922 internal_last_event_frame
= XCAR (XCDR (c
));
2923 Vlast_event_frame
= internal_last_event_frame
;
2928 /* If current_kboard's side queue is empty check the other kboards.
2929 If one of them has data that we have not yet seen here,
2930 switch to it and process the data waiting for it.
2932 Note: if the events queued up for another kboard
2933 have already been seen here, and therefore are not a complete command,
2934 the kbd_queue_has_data field is 0, so we skip that kboard here.
2935 That's to avoid an infinite loop switching between kboards here. */
2936 if (NILP (c
) && !single_kboard
)
2939 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2940 if (kb
->kbd_queue_has_data
)
2942 current_kboard
= kb
;
2943 /* This is going to exit from read_char
2944 so we had better get rid of this frame's stuff. */
2946 longjmp (wrong_kboard_jmpbuf
, 1);
2955 /* Finally, we read from the main queue,
2956 and if that gives us something we can't use yet, we put it on the
2957 appropriate side queue and try again. */
2966 EMACS_GET_TIME (now
);
2967 if (EMACS_TIME_GE (now
, *end_time
))
2971 /* Actually read a character, waiting if necessary. */
2972 save_getcjmp (save_jump
);
2973 restore_getcjmp (local_getcjmp
);
2975 timer_start_idle ();
2976 c
= kbd_buffer_get_event (&kb
, used_mouse_menu
, end_time
);
2977 restore_getcjmp (save_jump
);
2980 if (! NILP (c
) && (kb
!= current_kboard
))
2982 Lisp_Object link
= kb
->kbd_queue
;
2985 while (CONSP (XCDR (link
)))
2987 if (!NILP (XCDR (link
)))
2991 kb
->kbd_queue
= Fcons (c
, Qnil
);
2993 XSETCDR (link
, Fcons (c
, Qnil
));
2994 kb
->kbd_queue_has_data
= 1;
2998 current_kboard
= kb
;
2999 /* This is going to exit from read_char
3000 so we had better get rid of this frame's stuff. */
3002 longjmp (wrong_kboard_jmpbuf
, 1);
3007 /* Terminate Emacs in batch mode if at eof. */
3008 if (noninteractive
&& INTEGERP (c
) && XINT (c
) < 0)
3009 Fkill_emacs (make_number (1));
3013 /* Add in any extra modifiers, where appropriate. */
3014 if ((extra_keyboard_modifiers
& CHAR_CTL
)
3015 || ((extra_keyboard_modifiers
& 0177) < ' '
3016 && (extra_keyboard_modifiers
& 0177) != 0))
3017 XSETINT (c
, make_ctrl_char (XINT (c
)));
3019 /* Transfer any other modifier bits directly from
3020 extra_keyboard_modifiers to c. Ignore the actual character code
3021 in the low 16 bits of extra_keyboard_modifiers. */
3022 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
3033 if (commandflag
>= 0
3034 && !input_pending
&& !detect_input_pending_run_timers (0))
3042 /* Buffer switch events are only for internal wakeups
3043 so don't show them to the user.
3044 Also, don't record a key if we already did. */
3045 if (BUFFERP (c
) || key_already_recorded
)
3048 /* Process special events within read_char
3049 and loop around to read another event. */
3052 tem
= access_keymap (get_keymap (Vspecial_event_map
, 0, 1), c
, 0, 0, 1);
3057 int was_locked
= single_kboard
;
3059 last_input_char
= c
;
3060 Fcommand_execute (tem
, Qnil
, Fvector (1, &last_input_char
), Qt
);
3062 if (CONSP (c
) && EQ (XCAR (c
), Qselect_window
) && !end_time
)
3063 /* We stopped being idle for this event; undo that. This
3064 prevents automatic window selection (under
3065 mouse_autoselect_window from acting as a real input event, for
3066 example banishing the mouse under mouse-avoidance-mode. */
3067 timer_resume_idle ();
3069 /* Resume allowing input from any kboard, if that was true before. */
3071 any_kboard_state ();
3076 /* Handle things that only apply to characters. */
3079 /* If kbd_buffer_get_event gave us an EOF, return that. */
3083 if ((STRINGP (Vkeyboard_translate_table
)
3084 && SCHARS (Vkeyboard_translate_table
) > (unsigned) XFASTINT (c
))
3085 || (VECTORP (Vkeyboard_translate_table
)
3086 && XVECTOR (Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
3087 || (CHAR_TABLE_P (Vkeyboard_translate_table
)
3088 && CHAR_VALID_P (XINT (c
), 0)))
3091 d
= Faref (Vkeyboard_translate_table
, c
);
3092 /* nil in keyboard-translate-table means no translation. */
3098 /* If this event is a mouse click in the menu bar,
3099 return just menu-bar for now. Modify the mouse click event
3100 so we won't do this twice, then queue it up. */
3101 if (EVENT_HAS_PARAMETERS (c
)
3103 && CONSP (EVENT_START (c
))
3104 && CONSP (XCDR (EVENT_START (c
))))
3108 posn
= POSN_POSN (EVENT_START (c
));
3109 /* Handle menu-bar events:
3110 insert the dummy prefix event `menu-bar'. */
3111 if (EQ (posn
, Qmenu_bar
) || EQ (posn
, Qtool_bar
))
3113 /* Change menu-bar to (menu-bar) as the event "position". */
3114 POSN_SET_POSN (EVENT_START (c
), Fcons (posn
, Qnil
));
3117 Vunread_command_events
= Fcons (c
, Vunread_command_events
);
3122 /* Store these characters into recent_keys, the dribble file if any,
3123 and the keyboard macro being defined, if any. */
3125 if (! NILP (also_record
))
3126 record_char (also_record
);
3128 /* Wipe the echo area.
3129 But first, if we are about to use an input method,
3130 save the echo area contents for it to refer to. */
3132 && ! NILP (Vinput_method_function
)
3133 && (unsigned) XINT (c
) >= ' '
3134 && (unsigned) XINT (c
) != 127
3135 && (unsigned) XINT (c
) < 256)
3137 previous_echo_area_message
= Fcurrent_message ();
3138 Vinput_method_previous_message
= previous_echo_area_message
;
3141 /* Now wipe the echo area, except for help events which do their
3142 own stuff with the echo area. */
3144 || (!(EQ (Qhelp_echo
, XCAR (c
)))
3145 && !(EQ (Qswitch_frame
, XCAR (c
)))))
3147 if (!NILP (echo_area_buffer
[0]))
3148 safe_run_hooks (Qecho_area_clear_hook
);
3149 clear_message (1, 0);
3152 reread_for_input_method
:
3154 /* Pass this to the input method, if appropriate. */
3156 && ! NILP (Vinput_method_function
)
3157 /* Don't run the input method within a key sequence,
3158 after the first event of the key sequence. */
3159 && NILP (prev_event
)
3160 && (unsigned) XINT (c
) >= ' '
3161 && (unsigned) XINT (c
) != 127
3162 && (unsigned) XINT (c
) < 256)
3165 int key_count
, key_count_reset
;
3166 struct gcpro gcpro1
;
3167 int count
= SPECPDL_INDEX ();
3169 /* Save the echo status. */
3170 int saved_immediate_echo
= current_kboard
->immediate_echo
;
3171 struct kboard
*saved_ok_to_echo
= ok_to_echo_at_next_pause
;
3172 Lisp_Object saved_echo_string
= current_kboard
->echo_string
;
3173 int saved_echo_after_prompt
= current_kboard
->echo_after_prompt
;
3176 if (before_command_restore_flag
)
3178 this_command_key_count
= before_command_key_count_1
;
3179 if (this_command_key_count
< this_single_command_key_start
)
3180 this_single_command_key_start
= this_command_key_count
;
3181 echo_truncate (before_command_echo_length_1
);
3182 before_command_restore_flag
= 0;
3186 /* Save the this_command_keys status. */
3187 key_count
= this_command_key_count
;
3188 key_count_reset
= this_command_key_count_reset
;
3191 keys
= Fcopy_sequence (this_command_keys
);
3196 /* Clear out this_command_keys. */
3197 this_command_key_count
= 0;
3198 this_command_key_count_reset
= 0;
3200 /* Now wipe the echo area. */
3201 if (!NILP (echo_area_buffer
[0]))
3202 safe_run_hooks (Qecho_area_clear_hook
);
3203 clear_message (1, 0);
3206 /* If we are not reading a key sequence,
3207 never use the echo area. */
3210 specbind (Qinput_method_use_echo_area
, Qt
);
3213 /* Call the input method. */
3214 tem
= call1 (Vinput_method_function
, c
);
3216 tem
= unbind_to (count
, tem
);
3218 /* Restore the saved echoing state
3219 and this_command_keys state. */
3220 this_command_key_count
= key_count
;
3221 this_command_key_count_reset
= key_count_reset
;
3223 this_command_keys
= keys
;
3226 ok_to_echo_at_next_pause
= saved_ok_to_echo
;
3227 current_kboard
->echo_string
= saved_echo_string
;
3228 current_kboard
->echo_after_prompt
= saved_echo_after_prompt
;
3229 if (saved_immediate_echo
)
3234 /* The input method can return no events. */
3237 /* Bring back the previous message, if any. */
3238 if (! NILP (previous_echo_area_message
))
3239 message_with_string ("%s", previous_echo_area_message
, 0);
3242 /* It returned one event or more. */
3244 Vunread_post_input_method_events
3245 = nconc2 (XCDR (tem
), Vunread_post_input_method_events
);
3250 /* Display help if not echoing. */
3251 if (CONSP (c
) && EQ (XCAR (c
), Qhelp_echo
))
3253 /* (help-echo FRAME HELP WINDOW OBJECT POS). */
3254 Lisp_Object help
, object
, position
, window
, tem
;
3256 tem
= Fcdr (XCDR (c
));
3259 window
= Fcar (tem
);
3261 object
= Fcar (tem
);
3263 position
= Fcar (tem
);
3265 show_help_echo (help
, window
, object
, position
, 0);
3267 /* We stopped being idle for this event; undo that. */
3269 timer_resume_idle ();
3273 if ((! reread
|| this_command_key_count
== 0
3274 || this_command_key_count_reset
)
3278 /* Don't echo mouse motion events. */
3279 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
3280 && NILP (Fzerop (Vecho_keystrokes
))
3281 && ! (EVENT_HAS_PARAMETERS (c
)
3282 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
3285 if (! NILP (also_record
))
3286 echo_char (also_record
);
3287 /* Once we reread a character, echoing can happen
3288 the next time we pause to read a new one. */
3289 ok_to_echo_at_next_pause
= current_kboard
;
3292 /* Record this character as part of the current key. */
3293 add_command_key (c
);
3294 if (! NILP (also_record
))
3295 add_command_key (also_record
);
3298 last_input_char
= c
;
3301 /* Process the help character specially if enabled */
3302 if (!NILP (Vhelp_form
) && help_char_p (c
))
3305 count
= SPECPDL_INDEX ();
3307 record_unwind_protect (Fset_window_configuration
,
3308 Fcurrent_window_configuration (Qnil
));
3310 tem0
= Feval (Vhelp_form
);
3312 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
3316 c
= read_char (0, 0, 0, Qnil
, 0, NULL
);
3317 while (BUFFERP (c
));
3318 /* Remove the help from the frame */
3319 unbind_to (count
, Qnil
);
3322 if (EQ (c
, make_number (040)))
3326 c
= read_char (0, 0, 0, Qnil
, 0, NULL
);
3327 while (BUFFERP (c
));
3336 /* Record a key that came from a mouse menu.
3337 Record it for echoing, for this-command-keys, and so on. */
3343 /* Wipe the echo area. */
3344 clear_message (1, 0);
3349 before_command_key_count
= this_command_key_count
;
3350 before_command_echo_length
= echo_length ();
3353 /* Don't echo mouse motion events. */
3354 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
3355 && NILP (Fzerop (Vecho_keystrokes
)))
3359 /* Once we reread a character, echoing can happen
3360 the next time we pause to read a new one. */
3361 ok_to_echo_at_next_pause
= 0;
3364 /* Record this character as part of the current key. */
3365 add_command_key (c
);
3367 /* Re-reading in the middle of a command */
3368 last_input_char
= c
;
3372 /* Return 1 if should recognize C as "the help character". */
3380 if (EQ (c
, Vhelp_char
))
3382 for (tail
= Vhelp_event_list
; CONSP (tail
); tail
= XCDR (tail
))
3383 if (EQ (c
, XCAR (tail
)))
3388 /* Record the input event C in various ways. */
3396 if (CONSP (c
) && (EQ (XCAR (c
), Qhelp_echo
) || EQ (XCAR (c
), Qmouse_movement
)))
3398 /* To avoid filling recent_keys with help-echo and mouse-movement
3399 events, we filter out repeated help-echo events, only store the
3400 first and last in a series of mouse-movement events, and don't
3401 store repeated help-echo events which are only separated by
3402 mouse-movement events. */
3404 Lisp_Object ev1
, ev2
, ev3
;
3407 if ((ix1
= recent_keys_index
- 1) < 0)
3408 ix1
= NUM_RECENT_KEYS
- 1;
3409 ev1
= AREF (recent_keys
, ix1
);
3411 if ((ix2
= ix1
- 1) < 0)
3412 ix2
= NUM_RECENT_KEYS
- 1;
3413 ev2
= AREF (recent_keys
, ix2
);
3415 if ((ix3
= ix2
- 1) < 0)
3416 ix3
= NUM_RECENT_KEYS
- 1;
3417 ev3
= AREF (recent_keys
, ix3
);
3419 if (EQ (XCAR (c
), Qhelp_echo
))
3421 /* Don't record `help-echo' in recent_keys unless it shows some help
3422 message, and a different help than the previously recorded
3424 Lisp_Object help
, last_help
;
3426 help
= Fcar_safe (Fcdr_safe (XCDR (c
)));
3427 if (!STRINGP (help
))
3429 else if (CONSP (ev1
) && EQ (XCAR (ev1
), Qhelp_echo
)
3430 && (last_help
= Fcar_safe (Fcdr_safe (XCDR (ev1
))), EQ (last_help
, help
)))
3432 else if (CONSP (ev1
) && EQ (XCAR (ev1
), Qmouse_movement
)
3433 && CONSP (ev2
) && EQ (XCAR (ev2
), Qhelp_echo
)
3434 && (last_help
= Fcar_safe (Fcdr_safe (XCDR (ev2
))), EQ (last_help
, help
)))
3436 else if (CONSP (ev1
) && EQ (XCAR (ev1
), Qmouse_movement
)
3437 && CONSP (ev2
) && EQ (XCAR (ev2
), Qmouse_movement
)
3438 && CONSP (ev3
) && EQ (XCAR (ev3
), Qhelp_echo
)
3439 && (last_help
= Fcar_safe (Fcdr_safe (XCDR (ev3
))), EQ (last_help
, help
)))
3442 else if (EQ (XCAR (c
), Qmouse_movement
))
3444 /* Only record one pair of `mouse-movement' on a window in recent_keys.
3445 So additional mouse movement events replace the last element. */
3446 Lisp_Object last_window
, window
;
3448 window
= Fcar_safe (Fcar_safe (XCDR (c
)));
3449 if (CONSP (ev1
) && EQ (XCAR (ev1
), Qmouse_movement
)
3450 && (last_window
= Fcar_safe (Fcar_safe (XCDR (ev1
))), EQ (last_window
, window
))
3451 && CONSP (ev2
) && EQ (XCAR (ev2
), Qmouse_movement
)
3452 && (last_window
= Fcar_safe (Fcar_safe (XCDR (ev2
))), EQ (last_window
, window
)))
3454 ASET (recent_keys
, ix1
, c
);
3460 store_kbd_macro_char (c
);
3465 ASET (recent_keys
, recent_keys_index
, c
);
3466 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
3467 recent_keys_index
= 0;
3469 else if (recorded
< 0)
3471 /* We need to remove one or two events from recent_keys.
3472 To do this, we simply put nil at those events and move the
3473 recent_keys_index backwards over those events. Usually,
3474 users will never see those nil events, as they will be
3475 overwritten by the command keys entered to see recent_keys
3478 while (recorded
++ < 0 && total_keys
> 0)
3480 if (total_keys
< NUM_RECENT_KEYS
)
3482 if (--recent_keys_index
< 0)
3483 recent_keys_index
= NUM_RECENT_KEYS
- 1;
3484 ASET (recent_keys
, recent_keys_index
, Qnil
);
3488 num_nonmacro_input_events
++;
3490 /* Write c to the dribble file. If c is a lispy event, write
3491 the event's symbol to the dribble file, in <brackets>. Bleaugh.
3492 If you, dear reader, have a better idea, you've got the source. :-) */
3497 if (XUINT (c
) < 0x100)
3498 putc (XINT (c
), dribble
);
3500 fprintf (dribble
, " 0x%x", (int) XUINT (c
));
3504 Lisp_Object dribblee
;
3506 /* If it's a structured event, take the event header. */
3507 dribblee
= EVENT_HEAD (c
);
3509 if (SYMBOLP (dribblee
))
3511 putc ('<', dribble
);
3512 fwrite (SDATA (SYMBOL_NAME (dribblee
)), sizeof (char),
3513 SBYTES (SYMBOL_NAME (dribblee
)),
3515 putc ('>', dribble
);
3527 struct buffer
*old
= current_buffer
;
3528 Fprinc (object
, Qnil
);
3529 set_buffer_internal (XBUFFER (Vstandard_output
));
3530 call0 (intern ("help-mode"));
3531 set_buffer_internal (old
);
3535 /* Copy out or in the info on where C-g should throw to.
3536 This is used when running Lisp code from within get_char,
3537 in case get_char is called recursively.
3538 See read_process_output. */
3544 bcopy (getcjmp
, temp
, sizeof getcjmp
);
3548 restore_getcjmp (temp
)
3551 bcopy (temp
, getcjmp
, sizeof getcjmp
);
3554 /* Low level keyboard/mouse input.
3555 kbd_buffer_store_event places events in kbd_buffer, and
3556 kbd_buffer_get_event retrieves them. */
3558 /* Return true iff there are any events in the queue that read-char
3559 would return. If this returns false, a read-char would block. */
3561 readable_events (flags
)
3564 if (flags
& READABLE_EVENTS_DO_TIMERS_NOW
)
3567 /* If the buffer contains only FOCUS_IN_EVENT events, and
3568 READABLE_EVENTS_FILTER_EVENTS is set, report it as empty. */
3569 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3571 if (flags
& (READABLE_EVENTS_FILTER_EVENTS
3572 #ifdef USE_TOOLKIT_SCROLL_BARS
3573 | READABLE_EVENTS_IGNORE_SQUEEZABLES
3577 struct input_event
*event
;
3579 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
3586 #ifdef USE_TOOLKIT_SCROLL_BARS
3587 (flags
& READABLE_EVENTS_FILTER_EVENTS
) &&
3589 event
->kind
== FOCUS_IN_EVENT
)
3590 #ifdef USE_TOOLKIT_SCROLL_BARS
3591 && !((flags
& READABLE_EVENTS_IGNORE_SQUEEZABLES
)
3592 && event
->kind
== SCROLL_BAR_CLICK_EVENT
3593 && event
->part
== scroll_bar_handle
3594 && event
->modifiers
== 0)
3599 if (event
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3602 while (event
!= kbd_store_ptr
);
3609 if (!(flags
& READABLE_EVENTS_IGNORE_SQUEEZABLES
)
3610 && !NILP (do_mouse_tracking
) && some_mouse_moved ())
3615 if (current_kboard
->kbd_queue_has_data
)
3621 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
3622 if (kb
->kbd_queue_has_data
)
3628 /* Set this for debugging, to have a way to get out */
3633 event_to_kboard (event
)
3634 struct input_event
*event
;
3637 frame
= event
->frame_or_window
;
3639 frame
= XCAR (frame
);
3640 else if (WINDOWP (frame
))
3641 frame
= WINDOW_FRAME (XWINDOW (frame
));
3643 /* There are still some events that don't set this field.
3644 For now, just ignore the problem.
3645 Also ignore dead frames here. */
3646 if (!FRAMEP (frame
) || !FRAME_LIVE_P (XFRAME (frame
)))
3649 return FRAME_KBOARD (XFRAME (frame
));
3654 Lisp_Object Vthrow_on_input
;
3656 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
3659 kbd_buffer_store_event (event
)
3660 register struct input_event
*event
;
3662 kbd_buffer_store_event_hold (event
, 0);
3665 /* Store EVENT obtained at interrupt level into kbd_buffer, fifo.
3667 If HOLD_QUIT is 0, just stuff EVENT into the fifo.
3668 Else, if HOLD_QUIT.kind != NO_EVENT, discard EVENT.
3669 Else, if EVENT is a quit event, store the quit event
3670 in HOLD_QUIT, and return (thus ignoring further events).
3672 This is used in read_avail_input to postpone the processing
3673 of the quit event until all subsequent input events have been
3674 parsed (and discarded).
3678 kbd_buffer_store_event_hold (event
, hold_quit
)
3679 register struct input_event
*event
;
3680 struct input_event
*hold_quit
;
3682 if (event
->kind
== NO_EVENT
)
3685 if (hold_quit
&& hold_quit
->kind
!= NO_EVENT
)
3688 if (event
->kind
== ASCII_KEYSTROKE_EVENT
)
3690 register int c
= event
->code
& 0377;
3692 if (event
->modifiers
& ctrl_modifier
)
3693 c
= make_ctrl_char (c
);
3695 c
|= (event
->modifiers
3696 & (meta_modifier
| alt_modifier
3697 | hyper_modifier
| super_modifier
));
3703 struct input_event
*sp
;
3706 && (kb
= FRAME_KBOARD (XFRAME (event
->frame_or_window
)),
3707 kb
!= current_kboard
))
3710 = Fcons (make_lispy_switch_frame (event
->frame_or_window
),
3711 Fcons (make_number (c
), Qnil
));
3712 kb
->kbd_queue_has_data
= 1;
3713 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
3715 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3718 if (event_to_kboard (sp
) == kb
)
3720 sp
->kind
= NO_EVENT
;
3721 sp
->frame_or_window
= Qnil
;
3731 bcopy (event
, (char *) hold_quit
, sizeof (*event
));
3735 /* If this results in a quit_char being returned to Emacs as
3736 input, set Vlast_event_frame properly. If this doesn't
3737 get returned to Emacs as an event, the next event read
3738 will set Vlast_event_frame again, so this is safe to do. */
3742 focus
= FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
3744 focus
= event
->frame_or_window
;
3745 internal_last_event_frame
= focus
;
3746 Vlast_event_frame
= focus
;
3749 last_event_timestamp
= event
->timestamp
;
3750 interrupt_signal (0 /* dummy */);
3754 if (c
&& c
== stop_character
)
3760 /* Don't insert two BUFFER_SWITCH_EVENT's in a row.
3761 Just ignore the second one. */
3762 else if (event
->kind
== BUFFER_SWITCH_EVENT
3763 && kbd_fetch_ptr
!= kbd_store_ptr
3764 && ((kbd_store_ptr
== kbd_buffer
3765 ? kbd_buffer
+ KBD_BUFFER_SIZE
- 1
3766 : kbd_store_ptr
- 1)->kind
) == BUFFER_SWITCH_EVENT
)
3769 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
3770 kbd_store_ptr
= kbd_buffer
;
3772 /* Don't let the very last slot in the buffer become full,
3773 since that would make the two pointers equal,
3774 and that is indistinguishable from an empty buffer.
3775 Discard the event if it would fill the last slot. */
3776 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
3778 *kbd_store_ptr
= *event
;
3782 /* If we're inside while-no-input, and this event qualifies
3783 as input, set quit-flag to cause an interrupt. */
3784 if (!NILP (Vthrow_on_input
)
3785 && event
->kind
!= FOCUS_IN_EVENT
3786 && event
->kind
!= HELP_EVENT
3787 && event
->kind
!= DEICONIFY_EVENT
)
3789 Vquit_flag
= Vthrow_on_input
;
3790 /* If we're inside a function that wants immediate quits,
3792 if (immediate_quit
&& NILP (Vinhibit_quit
))
3802 /* Put an input event back in the head of the event queue. */
3805 kbd_buffer_unget_event (event
)
3806 register struct input_event
*event
;
3808 if (kbd_fetch_ptr
== kbd_buffer
)
3809 kbd_fetch_ptr
= kbd_buffer
+ KBD_BUFFER_SIZE
;
3811 /* Don't let the very last slot in the buffer become full, */
3812 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
3815 *kbd_fetch_ptr
= *event
;
3820 /* Generate HELP_EVENT input_events in BUFP which has room for
3821 SIZE events. If there's not enough room in BUFP, ignore this
3824 HELP is the help form.
3826 FRAME is the frame on which the help is generated. OBJECT is the
3827 Lisp object where the help was found (a buffer, a string, an
3828 overlay, or nil if neither from a string nor from a buffer. POS is
3829 the position within OBJECT where the help was found.
3831 Value is the number of input_events generated. */
3834 gen_help_event (help
, frame
, window
, object
, pos
)
3835 Lisp_Object help
, frame
, object
, window
;
3838 struct input_event event
;
3842 event
.kind
= HELP_EVENT
;
3843 event
.frame_or_window
= frame
;
3845 event
.x
= WINDOWP (window
) ? window
: frame
;
3848 kbd_buffer_store_event (&event
);
3852 /* Store HELP_EVENTs for HELP on FRAME in the input queue. */
3855 kbd_buffer_store_help_event (frame
, help
)
3856 Lisp_Object frame
, help
;
3858 struct input_event event
;
3860 event
.kind
= HELP_EVENT
;
3861 event
.frame_or_window
= frame
;
3866 kbd_buffer_store_event (&event
);
3870 /* Discard any mouse events in the event buffer by setting them to
3873 discard_mouse_events ()
3875 struct input_event
*sp
;
3876 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
3878 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3881 if (sp
->kind
== MOUSE_CLICK_EVENT
3882 || sp
->kind
== WHEEL_EVENT
3884 || sp
->kind
== W32_SCROLL_BAR_CLICK_EVENT
3886 || sp
->kind
== SCROLL_BAR_CLICK_EVENT
)
3888 sp
->kind
= NO_EVENT
;
3894 /* Return non-zero if there are any real events waiting in the event
3895 buffer, not counting `NO_EVENT's.
3897 If DISCARD is non-zero, discard NO_EVENT events at the front of
3898 the input queue, possibly leaving the input queue empty if there
3899 are no real input events. */
3902 kbd_buffer_events_waiting (discard
)
3905 struct input_event
*sp
;
3907 for (sp
= kbd_fetch_ptr
;
3908 sp
!= kbd_store_ptr
&& sp
->kind
== NO_EVENT
;
3911 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3918 return sp
!= kbd_store_ptr
&& sp
->kind
!= NO_EVENT
;
3922 /* Clear input event EVENT. */
3926 struct input_event
*event
;
3928 event
->kind
= NO_EVENT
;
3932 /* Read one event from the event buffer, waiting if necessary.
3933 The value is a Lisp object representing the event.
3934 The value is nil for an event that should be ignored,
3935 or that was handled here.
3936 We always read and discard one event. */
3939 kbd_buffer_get_event (kbp
, used_mouse_menu
, end_time
)
3941 int *used_mouse_menu
;
3942 EMACS_TIME
*end_time
;
3951 *kbp
= current_kboard
;
3955 /* Wait until there is input available. */
3958 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3961 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
3965 /* If the quit flag is set, then read_char will return
3966 quit_char, so that counts as "available input." */
3967 if (!NILP (Vquit_flag
))
3968 quit_throw_to_read_char ();
3970 /* One way or another, wait until input is available; then, if
3971 interrupt handlers have not read it, read it now. */
3974 wait_for_kbd_input ();
3976 /* Note SIGIO has been undef'd if FIONREAD is missing. */
3980 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3983 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
3988 EMACS_TIME duration
;
3989 EMACS_GET_TIME (duration
);
3990 if (EMACS_TIME_GE (duration
, *end_time
))
3991 return Qnil
; /* finished waiting */
3994 EMACS_SUB_TIME (duration
, *end_time
, duration
);
3995 wait_reading_process_output (EMACS_SECS (duration
),
3996 EMACS_USECS (duration
),
3997 -1, 1, Qnil
, NULL
, 0);
4001 wait_reading_process_output (0, 0, -1, 1, Qnil
, NULL
, 0);
4003 if (!interrupt_input
&& kbd_fetch_ptr
== kbd_store_ptr
)
4004 /* Pass 1 for EXPECT since we just waited to have input. */
4005 read_avail_input (1);
4006 #endif /* not VMS */
4009 if (CONSP (Vunread_command_events
))
4012 first
= XCAR (Vunread_command_events
);
4013 Vunread_command_events
= XCDR (Vunread_command_events
);
4014 *kbp
= current_kboard
;
4018 /* At this point, we know that there is a readable event available
4019 somewhere. If the event queue is empty, then there must be a
4020 mouse movement enabled and available. */
4021 if (kbd_fetch_ptr
!= kbd_store_ptr
)
4023 struct input_event
*event
;
4025 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
4029 last_event_timestamp
= event
->timestamp
;
4032 *kbp
= event_to_kboard (event
);
4034 *kbp
= current_kboard
; /* Better than returning null ptr? */
4036 *kbp
= &the_only_kboard
;
4041 /* These two kinds of events get special handling
4042 and don't actually appear to the command loop.
4043 We return nil for them. */
4044 if (event
->kind
== SELECTION_REQUEST_EVENT
4045 || event
->kind
== SELECTION_CLEAR_EVENT
)
4048 struct input_event copy
;
4050 /* Remove it from the buffer before processing it,
4051 since otherwise swallow_events will see it
4052 and process it again. */
4054 kbd_fetch_ptr
= event
+ 1;
4055 input_pending
= readable_events (0);
4056 x_handle_selection_event (©
);
4058 /* We're getting selection request events, but we don't have
4064 #if defined (HAVE_X11) || defined (HAVE_NTGUI) || defined (MAC_OS)
4065 else if (event
->kind
== DELETE_WINDOW_EVENT
)
4067 /* Make an event (delete-frame (FRAME)). */
4068 obj
= Fcons (event
->frame_or_window
, Qnil
);
4069 obj
= Fcons (Qdelete_frame
, Fcons (obj
, Qnil
));
4070 kbd_fetch_ptr
= event
+ 1;
4073 #if defined (HAVE_X11) || defined (HAVE_NTGUI) || defined (MAC_OS)
4074 else if (event
->kind
== ICONIFY_EVENT
)
4076 /* Make an event (iconify-frame (FRAME)). */
4077 obj
= Fcons (event
->frame_or_window
, Qnil
);
4078 obj
= Fcons (Qiconify_frame
, Fcons (obj
, Qnil
));
4079 kbd_fetch_ptr
= event
+ 1;
4081 else if (event
->kind
== DEICONIFY_EVENT
)
4083 /* Make an event (make-frame-visible (FRAME)). */
4084 obj
= Fcons (event
->frame_or_window
, Qnil
);
4085 obj
= Fcons (Qmake_frame_visible
, Fcons (obj
, Qnil
));
4086 kbd_fetch_ptr
= event
+ 1;
4089 else if (event
->kind
== BUFFER_SWITCH_EVENT
)
4091 /* The value doesn't matter here; only the type is tested. */
4092 XSETBUFFER (obj
, current_buffer
);
4093 kbd_fetch_ptr
= event
+ 1;
4095 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
4096 || defined (USE_GTK)
4097 else if (event
->kind
== MENU_BAR_ACTIVATE_EVENT
)
4099 kbd_fetch_ptr
= event
+ 1;
4100 input_pending
= readable_events (0);
4101 if (FRAME_LIVE_P (XFRAME (event
->frame_or_window
)))
4102 x_activate_menubar (XFRAME (event
->frame_or_window
));
4105 #if defined (WINDOWSNT) || defined (MAC_OS)
4106 else if (event
->kind
== LANGUAGE_CHANGE_EVENT
)
4109 /* Make an event (language-change (KEY_SCRIPT)). */
4110 obj
= Fcons (make_number (event
->code
), Qnil
);
4112 /* Make an event (language-change (FRAME CHARSET LCID)). */
4113 obj
= Fcons (event
->frame_or_window
, Qnil
);
4115 obj
= Fcons (Qlanguage_change
, Fcons (obj
, Qnil
));
4116 kbd_fetch_ptr
= event
+ 1;
4119 else if (event
->kind
== SAVE_SESSION_EVENT
)
4121 obj
= Fcons (Qsave_session
, Qnil
);
4122 kbd_fetch_ptr
= event
+ 1;
4124 /* Just discard these, by returning nil.
4125 With MULTI_KBOARD, these events are used as placeholders
4126 when we need to randomly delete events from the queue.
4127 (They shouldn't otherwise be found in the buffer,
4128 but on some machines it appears they do show up
4129 even without MULTI_KBOARD.) */
4130 /* On Windows NT/9X, NO_EVENT is used to delete extraneous
4131 mouse events during a popup-menu call. */
4132 else if (event
->kind
== NO_EVENT
)
4133 kbd_fetch_ptr
= event
+ 1;
4134 else if (event
->kind
== HELP_EVENT
)
4136 Lisp_Object object
, position
, help
, frame
, window
;
4138 frame
= event
->frame_or_window
;
4139 object
= event
->arg
;
4140 position
= make_number (event
->code
);
4143 clear_event (event
);
4145 kbd_fetch_ptr
= event
+ 1;
4146 if (!WINDOWP (window
))
4148 obj
= Fcons (Qhelp_echo
,
4149 list5 (frame
, help
, window
, object
, position
));
4151 else if (event
->kind
== FOCUS_IN_EVENT
)
4153 /* Notification of a FocusIn event. The frame receiving the
4154 focus is in event->frame_or_window. Generate a
4155 switch-frame event if necessary. */
4156 Lisp_Object frame
, focus
;
4158 frame
= event
->frame_or_window
;
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
;
4167 kbd_fetch_ptr
= event
+ 1;
4171 /* If this event is on a different frame, return a switch-frame this
4172 time, and leave the event in the queue for next time. */
4176 frame
= event
->frame_or_window
;
4178 frame
= XCAR (frame
);
4179 else if (WINDOWP (frame
))
4180 frame
= WINDOW_FRAME (XWINDOW (frame
));
4182 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
4186 if (! EQ (frame
, internal_last_event_frame
)
4187 && !EQ (frame
, selected_frame
))
4188 obj
= make_lispy_switch_frame (frame
);
4189 internal_last_event_frame
= frame
;
4191 /* If we didn't decide to make a switch-frame event, go ahead
4192 and build a real event from the queue entry. */
4196 obj
= make_lispy_event (event
);
4198 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined(MAC_OS) \
4199 || defined (USE_GTK)
4200 /* If this was a menu selection, then set the flag to inhibit
4201 writing to last_nonmenu_event. Don't do this if the event
4202 we're returning is (menu-bar), though; that indicates the
4203 beginning of the menu sequence, and we might as well leave
4204 that as the `event with parameters' for this selection. */
4206 && !EQ (event
->frame_or_window
, event
->arg
)
4207 && (event
->kind
== MENU_BAR_EVENT
4208 || event
->kind
== TOOL_BAR_EVENT
))
4209 *used_mouse_menu
= 1;
4212 /* Wipe out this event, to catch bugs. */
4213 clear_event (event
);
4214 kbd_fetch_ptr
= event
+ 1;
4219 /* Try generating a mouse motion event. */
4220 else if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
4222 FRAME_PTR f
= some_mouse_moved ();
4223 Lisp_Object bar_window
;
4224 enum scroll_bar_part part
;
4228 *kbp
= current_kboard
;
4229 /* Note that this uses F to determine which display to look at.
4230 If there is no valid info, it does not store anything
4231 so x remains nil. */
4233 (*mouse_position_hook
) (&f
, 0, &bar_window
, &part
, &x
, &y
, &time
);
4237 /* Decide if we should generate a switch-frame event. Don't
4238 generate switch-frame events for motion outside of all Emacs
4244 frame
= FRAME_FOCUS_FRAME (f
);
4246 XSETFRAME (frame
, f
);
4248 if (! EQ (frame
, internal_last_event_frame
)
4249 && !EQ (frame
, selected_frame
))
4250 obj
= make_lispy_switch_frame (frame
);
4251 internal_last_event_frame
= frame
;
4254 /* If we didn't decide to make a switch-frame event, go ahead and
4255 return a mouse-motion event. */
4256 if (!NILP (x
) && NILP (obj
))
4257 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
4259 #endif /* HAVE_MOUSE */
4261 /* We were promised by the above while loop that there was
4262 something for us to read! */
4265 input_pending
= readable_events (0);
4267 Vlast_event_frame
= internal_last_event_frame
;
4272 /* Process any events that are not user-visible,
4273 then return, without reading any user-visible events. */
4276 swallow_events (do_display
)
4281 while (kbd_fetch_ptr
!= kbd_store_ptr
)
4283 struct input_event
*event
;
4285 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
4289 last_event_timestamp
= event
->timestamp
;
4291 /* These two kinds of events get special handling
4292 and don't actually appear to the command loop. */
4293 if (event
->kind
== SELECTION_REQUEST_EVENT
4294 || event
->kind
== SELECTION_CLEAR_EVENT
)
4297 struct input_event copy
;
4299 /* Remove it from the buffer before processing it,
4300 since otherwise swallow_events called recursively could see it
4301 and process it again. */
4303 kbd_fetch_ptr
= event
+ 1;
4304 input_pending
= readable_events (0);
4305 x_handle_selection_event (©
);
4307 /* We're getting selection request events, but we don't have
4316 old_timers_run
= timers_run
;
4317 get_input_pending (&input_pending
, READABLE_EVENTS_DO_TIMERS_NOW
);
4319 if (timers_run
!= old_timers_run
&& do_display
)
4320 redisplay_preserve_echo_area (7);
4323 /* Record the start of when Emacs is idle,
4324 for the sake of running idle-time timers. */
4331 /* If we are already in the idle state, do nothing. */
4332 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
4335 EMACS_GET_TIME (timer_idleness_start_time
);
4337 timer_last_idleness_start_time
= timer_idleness_start_time
;
4339 /* Mark all idle-time timers as once again candidates for running. */
4340 for (timers
= Vtimer_idle_list
; CONSP (timers
); timers
= XCDR (timers
))
4344 timer
= XCAR (timers
);
4346 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
4348 XVECTOR (timer
)->contents
[0] = Qnil
;
4352 /* Record that Emacs is no longer idle, so stop running idle-time timers. */
4357 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
4360 /* Resume idle timer from last idle start time. */
4363 timer_resume_idle ()
4365 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
4368 timer_idleness_start_time
= timer_last_idleness_start_time
;
4371 /* This is only for debugging. */
4372 struct input_event last_timer_event
;
4374 /* Check whether a timer has fired. To prevent larger problems we simply
4375 disregard elements that are not proper timers. Do not make a circular
4376 timer list for the time being.
4378 Returns the number of seconds to wait until the next timer fires. If a
4379 timer is triggering now, return zero seconds.
4380 If no timer is active, return -1 seconds.
4382 If a timer is ripe, we run it, with quitting turned off.
4384 DO_IT_NOW is now ignored. It used to mean that we should
4385 run the timer directly instead of queueing a timer-event.
4386 Now we always run timers directly. */
4389 timer_check (do_it_now
)
4392 EMACS_TIME nexttime
;
4393 EMACS_TIME now
, idleness_now
;
4394 Lisp_Object timers
, idle_timers
, chosen_timer
;
4395 struct gcpro gcpro1
, gcpro2
, gcpro3
;
4397 EMACS_SET_SECS (nexttime
, -1);
4398 EMACS_SET_USECS (nexttime
, -1);
4400 /* Always consider the ordinary timers. */
4401 timers
= Vtimer_list
;
4402 /* Consider the idle timers only if Emacs is idle. */
4403 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
4404 idle_timers
= Vtimer_idle_list
;
4407 chosen_timer
= Qnil
;
4408 GCPRO3 (timers
, idle_timers
, chosen_timer
);
4410 if (CONSP (timers
) || CONSP (idle_timers
))
4412 EMACS_GET_TIME (now
);
4413 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
4414 EMACS_SUB_TIME (idleness_now
, now
, timer_idleness_start_time
);
4417 while (CONSP (timers
) || CONSP (idle_timers
))
4419 Lisp_Object
*vector
;
4420 Lisp_Object timer
= Qnil
, idle_timer
= Qnil
;
4421 EMACS_TIME timer_time
, idle_timer_time
;
4422 EMACS_TIME difference
, timer_difference
, idle_timer_difference
;
4424 /* Skip past invalid timers and timers already handled. */
4427 timer
= XCAR (timers
);
4428 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
4430 timers
= XCDR (timers
);
4433 vector
= XVECTOR (timer
)->contents
;
4435 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
4436 || !INTEGERP (vector
[3])
4437 || ! NILP (vector
[0]))
4439 timers
= XCDR (timers
);
4443 if (!NILP (idle_timers
))
4445 timer
= XCAR (idle_timers
);
4446 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
4448 idle_timers
= XCDR (idle_timers
);
4451 vector
= XVECTOR (timer
)->contents
;
4453 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
4454 || !INTEGERP (vector
[3])
4455 || ! NILP (vector
[0]))
4457 idle_timers
= XCDR (idle_timers
);
4462 /* Set TIMER, TIMER_TIME and TIMER_DIFFERENCE
4463 based on the next ordinary timer.
4464 TIMER_DIFFERENCE is the distance in time from NOW to when
4465 this timer becomes ripe (negative if it's already ripe). */
4468 timer
= XCAR (timers
);
4469 vector
= XVECTOR (timer
)->contents
;
4470 EMACS_SET_SECS (timer_time
,
4471 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
4472 EMACS_SET_USECS (timer_time
, XINT (vector
[3]));
4473 EMACS_SUB_TIME (timer_difference
, timer_time
, now
);
4476 /* Set IDLE_TIMER, IDLE_TIMER_TIME and IDLE_TIMER_DIFFERENCE
4477 based on the next idle timer. */
4478 if (!NILP (idle_timers
))
4480 idle_timer
= XCAR (idle_timers
);
4481 vector
= XVECTOR (idle_timer
)->contents
;
4482 EMACS_SET_SECS (idle_timer_time
,
4483 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
4484 EMACS_SET_USECS (idle_timer_time
, XINT (vector
[3]));
4485 EMACS_SUB_TIME (idle_timer_difference
, idle_timer_time
, idleness_now
);
4488 /* Decide which timer is the next timer,
4489 and set CHOSEN_TIMER, VECTOR and DIFFERENCE accordingly.
4490 Also step down the list where we found that timer. */
4492 if (! NILP (timers
) && ! NILP (idle_timers
))
4495 EMACS_SUB_TIME (temp
, timer_difference
, idle_timer_difference
);
4496 if (EMACS_TIME_NEG_P (temp
))
4498 chosen_timer
= timer
;
4499 timers
= XCDR (timers
);
4500 difference
= timer_difference
;
4504 chosen_timer
= idle_timer
;
4505 idle_timers
= XCDR (idle_timers
);
4506 difference
= idle_timer_difference
;
4509 else if (! NILP (timers
))
4511 chosen_timer
= timer
;
4512 timers
= XCDR (timers
);
4513 difference
= timer_difference
;
4517 chosen_timer
= idle_timer
;
4518 idle_timers
= XCDR (idle_timers
);
4519 difference
= idle_timer_difference
;
4521 vector
= XVECTOR (chosen_timer
)->contents
;
4523 /* If timer is ripe, run it if it hasn't been run. */
4524 if (EMACS_TIME_NEG_P (difference
)
4525 || (EMACS_SECS (difference
) == 0
4526 && EMACS_USECS (difference
) == 0))
4528 if (NILP (vector
[0]))
4530 int was_locked
= single_kboard
;
4531 int count
= SPECPDL_INDEX ();
4532 Lisp_Object old_deactivate_mark
= Vdeactivate_mark
;
4534 /* Mark the timer as triggered to prevent problems if the lisp
4535 code fails to reschedule it right. */
4538 specbind (Qinhibit_quit
, Qt
);
4540 call1 (Qtimer_event_handler
, chosen_timer
);
4541 Vdeactivate_mark
= old_deactivate_mark
;
4543 unbind_to (count
, Qnil
);
4545 /* Resume allowing input from any kboard, if that was true before. */
4547 any_kboard_state ();
4549 /* Since we have handled the event,
4550 we don't need to tell the caller to wake up and do it. */
4554 /* When we encounter a timer that is still waiting,
4555 return the amount of time to wait before it is ripe. */
4562 /* No timers are pending in the future. */
4563 /* Return 0 if we generated an event, and -1 if not. */
4568 DEFUN ("current-idle-time", Fcurrent_idle_time
, Scurrent_idle_time
, 0, 0, 0,
4569 doc
: /* Return the current length of Emacs idleness.
4570 The value is returned as a list of three integers. The first has the
4571 most significant 16 bits of the seconds, while the second has the
4572 least significant 16 bits. The third integer gives the microsecond
4575 The microsecond count is zero on systems that do not provide
4576 resolution finer than a second. */)
4579 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
4581 EMACS_TIME now
, idleness_now
;
4583 EMACS_GET_TIME (now
);
4584 EMACS_SUB_TIME (idleness_now
, now
, timer_idleness_start_time
);
4586 return list3 (make_number ((EMACS_SECS (idleness_now
) >> 16) & 0xffff),
4587 make_number ((EMACS_SECS (idleness_now
) >> 0) & 0xffff),
4588 make_number (EMACS_USECS (idleness_now
)));
4594 /* Caches for modify_event_symbol. */
4595 static Lisp_Object accent_key_syms
;
4596 static Lisp_Object func_key_syms
;
4597 static Lisp_Object mouse_syms
;
4598 static Lisp_Object wheel_syms
;
4599 static Lisp_Object drag_n_drop_syms
;
4601 /* This is a list of keysym codes for special "accent" characters.
4602 It parallels lispy_accent_keys. */
4604 static int lispy_accent_codes
[] =
4606 #ifdef XK_dead_circumflex
4611 #ifdef XK_dead_grave
4616 #ifdef XK_dead_tilde
4621 #ifdef XK_dead_diaeresis
4626 #ifdef XK_dead_macron
4631 #ifdef XK_dead_degree
4636 #ifdef XK_dead_acute
4641 #ifdef XK_dead_cedilla
4646 #ifdef XK_dead_breve
4651 #ifdef XK_dead_ogonek
4656 #ifdef XK_dead_caron
4661 #ifdef XK_dead_doubleacute
4662 XK_dead_doubleacute
,
4666 #ifdef XK_dead_abovedot
4671 #ifdef XK_dead_abovering
4681 #ifdef XK_dead_belowdot
4686 #ifdef XK_dead_voiced_sound
4687 XK_dead_voiced_sound
,
4691 #ifdef XK_dead_semivoiced_sound
4692 XK_dead_semivoiced_sound
,
4708 /* This is a list of Lisp names for special "accent" characters.
4709 It parallels lispy_accent_codes. */
4711 static char *lispy_accent_keys
[] =
4729 "dead-voiced-sound",
4730 "dead-semivoiced-sound",
4736 #define FUNCTION_KEY_OFFSET 0x0
4738 char *lispy_function_keys
[] =
4742 0, /* VK_LBUTTON 0x01 */
4743 0, /* VK_RBUTTON 0x02 */
4744 "cancel", /* VK_CANCEL 0x03 */
4745 0, /* VK_MBUTTON 0x04 */
4747 0, 0, 0, /* 0x05 .. 0x07 */
4749 "backspace", /* VK_BACK 0x08 */
4750 "tab", /* VK_TAB 0x09 */
4752 0, 0, /* 0x0A .. 0x0B */
4754 "clear", /* VK_CLEAR 0x0C */
4755 "return", /* VK_RETURN 0x0D */
4757 0, 0, /* 0x0E .. 0x0F */
4759 0, /* VK_SHIFT 0x10 */
4760 0, /* VK_CONTROL 0x11 */
4761 0, /* VK_MENU 0x12 */
4762 "pause", /* VK_PAUSE 0x13 */
4763 "capslock", /* VK_CAPITAL 0x14 */
4765 0, 0, 0, 0, 0, 0, /* 0x15 .. 0x1A */
4767 "escape", /* VK_ESCAPE 0x1B */
4769 0, 0, 0, 0, /* 0x1C .. 0x1F */
4771 0, /* VK_SPACE 0x20 */
4772 "prior", /* VK_PRIOR 0x21 */
4773 "next", /* VK_NEXT 0x22 */
4774 "end", /* VK_END 0x23 */
4775 "home", /* VK_HOME 0x24 */
4776 "left", /* VK_LEFT 0x25 */
4777 "up", /* VK_UP 0x26 */
4778 "right", /* VK_RIGHT 0x27 */
4779 "down", /* VK_DOWN 0x28 */
4780 "select", /* VK_SELECT 0x29 */
4781 "print", /* VK_PRINT 0x2A */
4782 "execute", /* VK_EXECUTE 0x2B */
4783 "snapshot", /* VK_SNAPSHOT 0x2C */
4784 "insert", /* VK_INSERT 0x2D */
4785 "delete", /* VK_DELETE 0x2E */
4786 "help", /* VK_HELP 0x2F */
4788 /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
4790 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4792 0, 0, 0, 0, 0, 0, 0, /* 0x3A .. 0x40 */
4794 /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
4796 0, 0, 0, 0, 0, 0, 0, 0, 0,
4797 0, 0, 0, 0, 0, 0, 0, 0, 0,
4798 0, 0, 0, 0, 0, 0, 0, 0,
4800 "lwindow", /* VK_LWIN 0x5B */
4801 "rwindow", /* VK_RWIN 0x5C */
4802 "apps", /* VK_APPS 0x5D */
4804 0, 0, /* 0x5E .. 0x5F */
4806 "kp-0", /* VK_NUMPAD0 0x60 */
4807 "kp-1", /* VK_NUMPAD1 0x61 */
4808 "kp-2", /* VK_NUMPAD2 0x62 */
4809 "kp-3", /* VK_NUMPAD3 0x63 */
4810 "kp-4", /* VK_NUMPAD4 0x64 */
4811 "kp-5", /* VK_NUMPAD5 0x65 */
4812 "kp-6", /* VK_NUMPAD6 0x66 */
4813 "kp-7", /* VK_NUMPAD7 0x67 */
4814 "kp-8", /* VK_NUMPAD8 0x68 */
4815 "kp-9", /* VK_NUMPAD9 0x69 */
4816 "kp-multiply", /* VK_MULTIPLY 0x6A */
4817 "kp-add", /* VK_ADD 0x6B */
4818 "kp-separator", /* VK_SEPARATOR 0x6C */
4819 "kp-subtract", /* VK_SUBTRACT 0x6D */
4820 "kp-decimal", /* VK_DECIMAL 0x6E */
4821 "kp-divide", /* VK_DIVIDE 0x6F */
4822 "f1", /* VK_F1 0x70 */
4823 "f2", /* VK_F2 0x71 */
4824 "f3", /* VK_F3 0x72 */
4825 "f4", /* VK_F4 0x73 */
4826 "f5", /* VK_F5 0x74 */
4827 "f6", /* VK_F6 0x75 */
4828 "f7", /* VK_F7 0x76 */
4829 "f8", /* VK_F8 0x77 */
4830 "f9", /* VK_F9 0x78 */
4831 "f10", /* VK_F10 0x79 */
4832 "f11", /* VK_F11 0x7A */
4833 "f12", /* VK_F12 0x7B */
4834 "f13", /* VK_F13 0x7C */
4835 "f14", /* VK_F14 0x7D */
4836 "f15", /* VK_F15 0x7E */
4837 "f16", /* VK_F16 0x7F */
4838 "f17", /* VK_F17 0x80 */
4839 "f18", /* VK_F18 0x81 */
4840 "f19", /* VK_F19 0x82 */
4841 "f20", /* VK_F20 0x83 */
4842 "f21", /* VK_F21 0x84 */
4843 "f22", /* VK_F22 0x85 */
4844 "f23", /* VK_F23 0x86 */
4845 "f24", /* VK_F24 0x87 */
4847 0, 0, 0, 0, /* 0x88 .. 0x8B */
4848 0, 0, 0, 0, /* 0x8C .. 0x8F */
4850 "kp-numlock", /* VK_NUMLOCK 0x90 */
4851 "scroll", /* VK_SCROLL 0x91 */
4853 "kp-space", /* VK_NUMPAD_CLEAR 0x92 */
4854 "kp-enter", /* VK_NUMPAD_ENTER 0x93 */
4855 "kp-prior", /* VK_NUMPAD_PRIOR 0x94 */
4856 "kp-next", /* VK_NUMPAD_NEXT 0x95 */
4857 "kp-end", /* VK_NUMPAD_END 0x96 */
4858 "kp-home", /* VK_NUMPAD_HOME 0x97 */
4859 "kp-left", /* VK_NUMPAD_LEFT 0x98 */
4860 "kp-up", /* VK_NUMPAD_UP 0x99 */
4861 "kp-right", /* VK_NUMPAD_RIGHT 0x9A */
4862 "kp-down", /* VK_NUMPAD_DOWN 0x9B */
4863 "kp-insert", /* VK_NUMPAD_INSERT 0x9C */
4864 "kp-delete", /* VK_NUMPAD_DELETE 0x9D */
4866 0, 0, /* 0x9E .. 0x9F */
4869 * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
4870 * Used only as parameters to GetAsyncKeyState and GetKeyState.
4871 * No other API or message will distinguish left and right keys this way.
4875 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4876 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4877 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4878 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4879 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4885 "attn", /* VK_ATTN 0xF6 */
4886 "crsel", /* VK_CRSEL 0xF7 */
4887 "exsel", /* VK_EXSEL 0xF8 */
4888 "ereof", /* VK_EREOF 0xF9 */
4889 "play", /* VK_PLAY 0xFA */
4890 "zoom", /* VK_ZOOM 0xFB */
4891 "noname", /* VK_NONAME 0xFC */
4892 "pa1", /* VK_PA1 0xFD */
4893 "oem_clear", /* VK_OEM_CLEAR 0xFE */
4897 #else /* not HAVE_NTGUI */
4899 /* This should be dealt with in XTread_socket now, and that doesn't
4900 depend on the client system having the Kana syms defined. See also
4901 the XK_kana_A case below. */
4904 static char *lispy_kana_keys
[] =
4906 /* X Keysym value */
4907 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x400 .. 0x40f */
4908 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x410 .. 0x41f */
4909 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x420 .. 0x42f */
4910 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x430 .. 0x43f */
4911 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x440 .. 0x44f */
4912 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x450 .. 0x45f */
4913 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x460 .. 0x46f */
4914 0,0,0,0,0,0,0,0,0,0,0,0,0,0,"overline",0,
4915 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x480 .. 0x48f */
4916 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x490 .. 0x49f */
4917 0, "kana-fullstop", "kana-openingbracket", "kana-closingbracket",
4918 "kana-comma", "kana-conjunctive", "kana-WO", "kana-a",
4919 "kana-i", "kana-u", "kana-e", "kana-o",
4920 "kana-ya", "kana-yu", "kana-yo", "kana-tsu",
4921 "prolongedsound", "kana-A", "kana-I", "kana-U",
4922 "kana-E", "kana-O", "kana-KA", "kana-KI",
4923 "kana-KU", "kana-KE", "kana-KO", "kana-SA",
4924 "kana-SHI", "kana-SU", "kana-SE", "kana-SO",
4925 "kana-TA", "kana-CHI", "kana-TSU", "kana-TE",
4926 "kana-TO", "kana-NA", "kana-NI", "kana-NU",
4927 "kana-NE", "kana-NO", "kana-HA", "kana-HI",
4928 "kana-FU", "kana-HE", "kana-HO", "kana-MA",
4929 "kana-MI", "kana-MU", "kana-ME", "kana-MO",
4930 "kana-YA", "kana-YU", "kana-YO", "kana-RA",
4931 "kana-RI", "kana-RU", "kana-RE", "kana-RO",
4932 "kana-WA", "kana-N", "voicedsound", "semivoicedsound",
4933 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4e0 .. 0x4ef */
4934 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4f0 .. 0x4ff */
4936 #endif /* XK_kana_A */
4939 #define FUNCTION_KEY_OFFSET 0xff00
4941 /* You'll notice that this table is arranged to be conveniently
4942 indexed by X Windows keysym values. */
4943 static char *lispy_function_keys
[] =
4945 /* X Keysym value */
4947 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00...0f */
4948 "backspace", "tab", "linefeed", "clear",
4950 0, 0, 0, "pause", /* 0xff10...1f */
4951 0, 0, 0, 0, 0, 0, 0, "escape",
4953 0, "kanji", "muhenkan", "henkan", /* 0xff20...2f */
4954 "romaji", "hiragana", "katakana", "hiragana-katakana",
4955 "zenkaku", "hankaku", "zenkaku-hankaku", "touroku",
4956 "massyo", "kana-lock", "kana-shift", "eisu-shift",
4957 "eisu-toggle", /* 0xff30...3f */
4958 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4959 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
4961 "home", "left", "up", "right", /* 0xff50 */ /* IsCursorKey */
4962 "down", "prior", "next", "end",
4963 "begin", 0, 0, 0, 0, 0, 0, 0,
4964 "select", /* 0xff60 */ /* IsMiscFunctionKey */
4975 "break", /* 0xff6b */
4978 0, 0, 0, 0, "backtab", 0, 0, 0, /* 0xff70... */
4979 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff78... */
4980 "kp-space", /* 0xff80 */ /* IsKeypadKey */
4981 0, 0, 0, 0, 0, 0, 0, 0,
4982 "kp-tab", /* 0xff89 */
4984 "kp-enter", /* 0xff8d */
4986 "kp-f1", /* 0xff91 */
4990 "kp-home", /* 0xff95 */
4995 "kp-prior", /* kp-page-up */
4996 "kp-next", /* kp-page-down */
5002 0, 0, 0, 0, 0, 0, 0, 0, 0,
5003 "kp-multiply", /* 0xffaa */
5008 "kp-divide", /* 0xffaf */
5009 "kp-0", /* 0xffb0 */
5010 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
5013 "kp-equal", /* 0xffbd */
5014 "f1", /* 0xffbe */ /* IsFunctionKey */
5016 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
5017 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
5018 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
5019 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
5020 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
5021 0, 0, 0, 0, 0, 0, 0, 0,
5022 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
5023 0, 0, 0, 0, 0, 0, 0, "delete"
5026 /* ISO 9995 Function and Modifier Keys; the first byte is 0xFE. */
5027 #define ISO_FUNCTION_KEY_OFFSET 0xfe00
5029 static char *iso_lispy_function_keys
[] =
5031 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe00 */
5032 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe08 */
5033 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe10 */
5034 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe18 */
5035 "iso-lefttab", /* 0xfe20 */
5036 "iso-move-line-up", "iso-move-line-down",
5037 "iso-partial-line-up", "iso-partial-line-down",
5038 "iso-partial-space-left", "iso-partial-space-right",
5039 "iso-set-margin-left", "iso-set-margin-right", /* 0xffe27, 28 */
5040 "iso-release-margin-left", "iso-release-margin-right",
5041 "iso-release-both-margins",
5042 "iso-fast-cursor-left", "iso-fast-cursor-right",
5043 "iso-fast-cursor-up", "iso-fast-cursor-down",
5044 "iso-continuous-underline", "iso-discontinuous-underline", /* 0xfe30, 31 */
5045 "iso-emphasize", "iso-center-object", "iso-enter", /* ... 0xfe34 */
5048 #endif /* not HAVE_NTGUI */
5050 Lisp_Object Vlispy_mouse_stem
;
5052 static char *lispy_wheel_names
[] =
5054 "wheel-up", "wheel-down"
5057 /* drag-n-drop events are generated when a set of selected files are
5058 dragged from another application and dropped onto an Emacs window. */
5059 static char *lispy_drag_n_drop_names
[] =
5064 /* Scroll bar parts. */
5065 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
5066 Lisp_Object Qup
, Qdown
, Qbottom
, Qend_scroll
;
5067 Lisp_Object Qtop
, Qratio
;
5069 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
5070 Lisp_Object
*scroll_bar_parts
[] = {
5071 &Qabove_handle
, &Qhandle
, &Qbelow_handle
,
5072 &Qup
, &Qdown
, &Qtop
, &Qbottom
, &Qend_scroll
, &Qratio
5075 /* User signal events. */
5076 Lisp_Object Qusr1_signal
, Qusr2_signal
;
5078 Lisp_Object
*lispy_user_signals
[] =
5080 &Qusr1_signal
, &Qusr2_signal
5084 /* A vector, indexed by button number, giving the down-going location
5085 of currently depressed buttons, both scroll bar and non-scroll bar.
5087 The elements have the form
5088 (BUTTON-NUMBER MODIFIER-MASK . REST)
5089 where REST is the cdr of a position as it would be reported in the event.
5091 The make_lispy_event function stores positions here to tell the
5092 difference between click and drag events, and to store the starting
5093 location to be included in drag events. */
5095 static Lisp_Object button_down_location
;
5097 /* Information about the most recent up-going button event: Which
5098 button, what location, and what time. */
5100 static int last_mouse_button
;
5101 static int last_mouse_x
;
5102 static int last_mouse_y
;
5103 static unsigned long button_down_time
;
5105 /* The maximum time between clicks to make a double-click, or Qnil to
5106 disable double-click detection, or Qt for no time limit. */
5108 Lisp_Object Vdouble_click_time
;
5110 /* Maximum number of pixels the mouse may be moved between clicks
5111 to make a double-click. */
5113 EMACS_INT double_click_fuzz
;
5115 /* The number of clicks in this multiple-click. */
5117 int double_click_count
;
5119 /* Return position of a mouse click or wheel event */
5122 make_lispy_position (f
, x
, y
, time
)
5128 enum window_part part
;
5129 Lisp_Object posn
= Qnil
;
5130 Lisp_Object extra_info
= Qnil
;
5133 /* Set `window' to the window under frame pixel coordinates (x,y) */
5135 window
= window_from_coordinates (f
, XINT (*x
), XINT (*y
),
5136 &part
, &wx
, &wy
, 0);
5140 if (WINDOWP (window
))
5142 /* It's a click in window window at frame coordinates (x,y) */
5143 struct window
*w
= XWINDOW (window
);
5144 Lisp_Object string_info
= Qnil
;
5145 int textpos
= -1, rx
= -1, ry
= -1;
5146 int dx
= -1, dy
= -1;
5147 int width
= -1, height
= -1;
5148 Lisp_Object object
= Qnil
;
5150 /* Set event coordinates to window-relative coordinates
5151 for constructing the Lisp event below. */
5155 if (part
== ON_TEXT
)
5157 wx
+= WINDOW_LEFT_MARGIN_WIDTH (w
);
5159 else if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
)
5161 /* Mode line or header line. Look for a string under
5162 the mouse that may have a `local-map' property. */
5166 posn
= part
== ON_MODE_LINE
? Qmode_line
: Qheader_line
;
5168 string
= mode_line_string (w
, part
, &rx
, &ry
, &charpos
,
5169 &object
, &dx
, &dy
, &width
, &height
);
5170 if (STRINGP (string
))
5171 string_info
= Fcons (string
, make_number (charpos
));
5172 if (w
== XWINDOW (selected_window
))
5175 textpos
= XMARKER (w
->pointm
)->charpos
;
5177 else if (part
== ON_VERTICAL_BORDER
)
5179 posn
= Qvertical_line
;
5184 else if (part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
5189 posn
= (part
== ON_LEFT_MARGIN
) ? Qleft_margin
: Qright_margin
;
5191 string
= marginal_area_string (w
, part
, &rx
, &ry
, &charpos
,
5192 &object
, &dx
, &dy
, &width
, &height
);
5193 if (STRINGP (string
))
5194 string_info
= Fcons (string
, make_number (charpos
));
5195 if (part
== ON_LEFT_MARGIN
)
5198 wx
= window_box_right_offset (w
, TEXT_AREA
) - 1;
5200 else if (part
== ON_LEFT_FRINGE
)
5202 posn
= Qleft_fringe
;
5205 wx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5207 : window_box_width (w
, LEFT_MARGIN_AREA
));
5210 else if (part
== ON_RIGHT_FRINGE
)
5212 posn
= Qright_fringe
;
5215 wx
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5216 + window_box_width (w
, TEXT_AREA
)
5217 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5218 ? window_box_width (w
, RIGHT_MARGIN_AREA
)
5224 /* Note: We have no special posn for part == ON_SCROLL_BAR. */
5225 wx
= max (WINDOW_LEFT_MARGIN_WIDTH (w
), wx
);
5230 Lisp_Object string2
, object2
= Qnil
;
5231 struct display_pos p
;
5233 int width2
, height2
;
5234 string2
= buffer_posn_from_coords (w
, &wx
, &wy
, &p
,
5235 &object2
, &dx2
, &dy2
,
5237 textpos
= CHARPOS (p
.pos
);
5238 if (rx
< 0) rx
= wx
;
5239 if (ry
< 0) ry
= wy
;
5240 if (dx
< 0) dx
= dx2
;
5241 if (dy
< 0) dy
= dy2
;
5242 if (width
< 0) width
= width2
;
5243 if (height
< 0) height
= height2
;
5247 posn
= make_number (textpos
);
5248 if (STRINGP (string2
))
5249 string_info
= Fcons (string2
,
5250 make_number (CHARPOS (p
.string_pos
)));
5256 #ifdef HAVE_WINDOW_SYSTEM
5257 if (IMAGEP (object
))
5259 Lisp_Object image_map
, hotspot
;
5260 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
5262 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
5264 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
5265 posn
= XCAR (hotspot
);
5270 extra_info
= Fcons (object
,
5271 Fcons (Fcons (make_number (dx
),
5273 Fcons (Fcons (make_number (width
),
5274 make_number (height
)),
5278 extra_info
= Fcons (string_info
,
5279 Fcons (make_number (textpos
),
5280 Fcons (Fcons (make_number (rx
),
5286 XSETFRAME (window
, f
);
5291 XSETFASTINT (*x
, 0);
5292 XSETFASTINT (*y
, 0);
5295 return Fcons (window
,
5297 Fcons (Fcons (*x
, *y
),
5298 Fcons (make_number (time
),
5302 /* Given a struct input_event, build the lisp event which represents
5303 it. If EVENT is 0, build a mouse movement event from the mouse
5304 movement buffer, which should have a movement event in it.
5306 Note that events must be passed to this function in the order they
5307 are received; this function stores the location of button presses
5308 in order to build drag events when the button is released. */
5311 make_lispy_event (event
)
5312 struct input_event
*event
;
5316 switch (SWITCH_ENUM_CAST (event
->kind
))
5318 /* A simple keystroke. */
5319 case ASCII_KEYSTROKE_EVENT
:
5321 Lisp_Object lispy_c
;
5322 int c
= event
->code
& 0377;
5323 /* Turn ASCII characters into control characters
5325 if (event
->modifiers
& ctrl_modifier
)
5326 c
= make_ctrl_char (c
);
5328 /* Add in the other modifier bits. We took care of ctrl_modifier
5329 just above, and the shift key was taken care of by the X code,
5330 and applied to control characters by make_ctrl_char. */
5331 c
|= (event
->modifiers
5332 & (meta_modifier
| alt_modifier
5333 | hyper_modifier
| super_modifier
));
5334 /* Distinguish Shift-SPC from SPC. */
5335 if ((event
->code
& 0377) == 040
5336 && event
->modifiers
& shift_modifier
)
5337 c
|= shift_modifier
;
5338 button_down_time
= 0;
5339 XSETFASTINT (lispy_c
, c
);
5343 case MULTIBYTE_CHAR_KEYSTROKE_EVENT
:
5345 Lisp_Object lispy_c
;
5346 int c
= event
->code
;
5348 /* Add in the other modifier bits. We took care of ctrl_modifier
5349 just above, and the shift key was taken care of by the X code,
5350 and applied to control characters by make_ctrl_char. */
5351 c
|= (event
->modifiers
5352 & (meta_modifier
| alt_modifier
5353 | hyper_modifier
| super_modifier
| ctrl_modifier
));
5354 /* What about the `shift' modifier ? */
5355 button_down_time
= 0;
5356 XSETFASTINT (lispy_c
, c
);
5360 /* A function key. The symbol may need to have modifier prefixes
5362 case NON_ASCII_KEYSTROKE_EVENT
:
5363 button_down_time
= 0;
5365 for (i
= 0; i
< sizeof (lispy_accent_codes
) / sizeof (int); i
++)
5366 if (event
->code
== lispy_accent_codes
[i
])
5367 return modify_event_symbol (i
,
5369 Qfunction_key
, Qnil
,
5370 lispy_accent_keys
, &accent_key_syms
,
5371 (sizeof (lispy_accent_keys
)
5372 / sizeof (lispy_accent_keys
[0])));
5376 if (event
->code
>= 0x400 && event
->code
< 0x500)
5377 return modify_event_symbol (event
->code
- 0x400,
5378 event
->modifiers
& ~shift_modifier
,
5379 Qfunction_key
, Qnil
,
5380 lispy_kana_keys
, &func_key_syms
,
5381 (sizeof (lispy_kana_keys
)
5382 / sizeof (lispy_kana_keys
[0])));
5383 #endif /* XK_kana_A */
5386 #ifdef ISO_FUNCTION_KEY_OFFSET
5387 if (event
->code
< FUNCTION_KEY_OFFSET
5388 && event
->code
>= ISO_FUNCTION_KEY_OFFSET
)
5389 return modify_event_symbol (event
->code
- ISO_FUNCTION_KEY_OFFSET
,
5391 Qfunction_key
, Qnil
,
5392 iso_lispy_function_keys
, &func_key_syms
,
5393 (sizeof (iso_lispy_function_keys
)
5394 / sizeof (iso_lispy_function_keys
[0])));
5397 /* Handle system-specific or unknown keysyms. */
5398 if (event
->code
& (1 << 28)
5399 || event
->code
- FUNCTION_KEY_OFFSET
< 0
5400 || (event
->code
- FUNCTION_KEY_OFFSET
5401 >= sizeof lispy_function_keys
/ sizeof *lispy_function_keys
)
5402 || !lispy_function_keys
[event
->code
- FUNCTION_KEY_OFFSET
])
5404 /* We need to use an alist rather than a vector as the cache
5405 since we can't make a vector long enuf. */
5406 if (NILP (current_kboard
->system_key_syms
))
5407 current_kboard
->system_key_syms
= Fcons (Qnil
, Qnil
);
5408 return modify_event_symbol (event
->code
,
5411 current_kboard
->Vsystem_key_alist
,
5412 0, ¤t_kboard
->system_key_syms
,
5416 return modify_event_symbol (event
->code
- FUNCTION_KEY_OFFSET
,
5418 Qfunction_key
, Qnil
,
5419 lispy_function_keys
, &func_key_syms
,
5420 (sizeof (lispy_function_keys
)
5421 / sizeof (lispy_function_keys
[0])));
5424 /* A mouse click. Figure out where it is, decide whether it's
5425 a press, click or drag, and build the appropriate structure. */
5426 case MOUSE_CLICK_EVENT
:
5427 #ifndef USE_TOOLKIT_SCROLL_BARS
5428 case SCROLL_BAR_CLICK_EVENT
:
5431 int button
= event
->code
;
5433 Lisp_Object position
;
5434 Lisp_Object
*start_pos_ptr
;
5435 Lisp_Object start_pos
;
5439 /* Build the position as appropriate for this mouse click. */
5440 if (event
->kind
== MOUSE_CLICK_EVENT
)
5442 struct frame
*f
= XFRAME (event
->frame_or_window
);
5443 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
5447 /* Ignore mouse events that were made on frame that
5448 have been deleted. */
5449 if (! FRAME_LIVE_P (f
))
5452 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
5453 /* EVENT->x and EVENT->y are frame-relative pixel
5454 coordinates at this place. Under old redisplay, COLUMN
5455 and ROW are set to frame relative glyph coordinates
5456 which are then used to determine whether this click is
5457 in a menu (non-toolkit version). */
5458 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
5459 &column
, &row
, NULL
, 1);
5461 /* In the non-toolkit version, clicks on the menu bar
5462 are ordinary button events in the event buffer.
5463 Distinguish them, and invoke the menu.
5465 (In the toolkit version, the toolkit handles the menu bar
5466 and Emacs doesn't know about it until after the user
5467 makes a selection.) */
5468 if (row
>= 0 && row
< FRAME_MENU_BAR_LINES (f
)
5469 && (event
->modifiers
& down_modifier
))
5471 Lisp_Object items
, item
;
5476 /* Activate the menu bar on the down event. If the
5477 up event comes in before the menu code can deal with it,
5479 if (! (event
->modifiers
& down_modifier
))
5483 /* Find the menu bar item under `column'. */
5485 items
= FRAME_MENU_BAR_ITEMS (f
);
5486 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
5488 Lisp_Object pos
, string
;
5489 string
= AREF (items
, i
+ 1);
5490 pos
= AREF (items
, i
+ 3);
5493 if (column
>= XINT (pos
)
5494 && column
< XINT (pos
) + SCHARS (string
))
5496 item
= AREF (items
, i
);
5501 /* ELisp manual 2.4b says (x y) are window relative but
5502 code says they are frame-relative. */
5504 = Fcons (event
->frame_or_window
,
5506 Fcons (Fcons (event
->x
, event
->y
),
5507 Fcons (make_number (event
->timestamp
),
5510 return Fcons (item
, Fcons (position
, Qnil
));
5512 #endif /* not USE_X_TOOLKIT && not USE_GTK */
5514 position
= make_lispy_position (f
, &event
->x
, &event
->y
,
5517 #ifndef USE_TOOLKIT_SCROLL_BARS
5520 /* It's a scrollbar click. */
5522 Lisp_Object portion_whole
;
5525 window
= event
->frame_or_window
;
5526 portion_whole
= Fcons (event
->x
, event
->y
);
5527 part
= *scroll_bar_parts
[(int) event
->part
];
5531 Fcons (Qvertical_scroll_bar
,
5532 Fcons (portion_whole
,
5533 Fcons (make_number (event
->timestamp
),
5534 Fcons (part
, Qnil
)))));
5536 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5538 if (button
>= ASIZE (button_down_location
))
5540 button_down_location
= larger_vector (button_down_location
,
5542 mouse_syms
= larger_vector (mouse_syms
, button
+ 1, Qnil
);
5545 start_pos_ptr
= &AREF (button_down_location
, button
);
5546 start_pos
= *start_pos_ptr
;
5547 *start_pos_ptr
= Qnil
;
5550 /* On window-system frames, use the value of
5551 double-click-fuzz as is. On other frames, interpret it
5552 as a multiple of 1/8 characters. */
5556 if (WINDOWP (event
->frame_or_window
))
5557 f
= XFRAME (XWINDOW (event
->frame_or_window
)->frame
);
5558 else if (FRAMEP (event
->frame_or_window
))
5559 f
= XFRAME (event
->frame_or_window
);
5563 if (FRAME_WINDOW_P (f
))
5564 fuzz
= double_click_fuzz
;
5566 fuzz
= double_click_fuzz
/ 8;
5568 is_double
= (button
== last_mouse_button
5569 && (abs (XINT (event
->x
) - last_mouse_x
) <= fuzz
)
5570 && (abs (XINT (event
->y
) - last_mouse_y
) <= fuzz
)
5571 && button_down_time
!= 0
5572 && (EQ (Vdouble_click_time
, Qt
)
5573 || (INTEGERP (Vdouble_click_time
)
5574 && ((int)(event
->timestamp
- button_down_time
)
5575 < XINT (Vdouble_click_time
)))));
5578 last_mouse_button
= button
;
5579 last_mouse_x
= XINT (event
->x
);
5580 last_mouse_y
= XINT (event
->y
);
5582 /* If this is a button press, squirrel away the location, so
5583 we can decide later whether it was a click or a drag. */
5584 if (event
->modifiers
& down_modifier
)
5588 double_click_count
++;
5589 event
->modifiers
|= ((double_click_count
> 2)
5594 double_click_count
= 1;
5595 button_down_time
= event
->timestamp
;
5596 *start_pos_ptr
= Fcopy_alist (position
);
5599 /* Now we're releasing a button - check the co-ordinates to
5600 see if this was a click or a drag. */
5601 else if (event
->modifiers
& up_modifier
)
5603 /* If we did not see a down before this up, ignore the up.
5604 Probably this happened because the down event chose a
5605 menu item. It would be an annoyance to treat the
5606 release of the button that chose the menu item as a
5609 if (!CONSP (start_pos
))
5612 event
->modifiers
&= ~up_modifier
;
5613 #if 0 /* Formerly we treated an up with no down as a click event. */
5614 if (!CONSP (start_pos
))
5615 event
->modifiers
|= click_modifier
;
5620 EMACS_INT xdiff
= double_click_fuzz
, ydiff
= double_click_fuzz
;
5622 /* The third element of every position
5623 should be the (x,y) pair. */
5624 down
= Fcar (Fcdr (Fcdr (start_pos
)));
5626 && INTEGERP (XCAR (down
)) && INTEGERP (XCDR (down
)))
5628 xdiff
= XINT (event
->x
) - XINT (XCAR (down
));
5629 ydiff
= XINT (event
->y
) - XINT (XCDR (down
));
5632 if (xdiff
< double_click_fuzz
&& xdiff
> - double_click_fuzz
5633 && ydiff
< double_click_fuzz
&& ydiff
> - double_click_fuzz
5634 /* Maybe the mouse has moved a lot, caused scrolling, and
5635 eventually ended up at the same screen position (but
5636 not buffer position) in which case it is a drag, not
5638 /* FIXME: OTOH if the buffer position has changed
5639 because of a timer or process filter rather than
5640 because of mouse movement, it should be considered as
5641 a click. But mouse-drag-region completely ignores
5642 this case and it hasn't caused any real problem, so
5643 it's probably OK to ignore it as well. */
5644 && EQ (Fcar (Fcdr (start_pos
)), Fcar (Fcdr (position
))))
5645 /* Mouse hasn't moved (much). */
5646 event
->modifiers
|= click_modifier
;
5649 button_down_time
= 0;
5650 event
->modifiers
|= drag_modifier
;
5653 /* Don't check is_double; treat this as multiple
5654 if the down-event was multiple. */
5655 if (double_click_count
> 1)
5656 event
->modifiers
|= ((double_click_count
> 2)
5662 /* Every mouse event should either have the down_modifier or
5663 the up_modifier set. */
5667 /* Get the symbol we should use for the mouse click. */
5670 head
= modify_event_symbol (button
,
5672 Qmouse_click
, Vlispy_mouse_stem
,
5675 XVECTOR (mouse_syms
)->size
);
5676 if (event
->modifiers
& drag_modifier
)
5681 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
5684 Fcons (make_number (double_click_count
),
5695 Lisp_Object position
;
5698 /* Build the position as appropriate for this mouse click. */
5699 struct frame
*f
= XFRAME (event
->frame_or_window
);
5701 /* Ignore wheel events that were made on frame that have been
5703 if (! FRAME_LIVE_P (f
))
5706 position
= make_lispy_position (f
, &event
->x
, &event
->y
,
5709 /* Set double or triple modifiers to indicate the wheel speed. */
5711 /* On window-system frames, use the value of
5712 double-click-fuzz as is. On other frames, interpret it
5713 as a multiple of 1/8 characters. */
5718 if (WINDOWP (event
->frame_or_window
))
5719 f
= XFRAME (XWINDOW (event
->frame_or_window
)->frame
);
5720 else if (FRAMEP (event
->frame_or_window
))
5721 f
= XFRAME (event
->frame_or_window
);
5725 if (FRAME_WINDOW_P (f
))
5726 fuzz
= double_click_fuzz
;
5728 fuzz
= double_click_fuzz
/ 8;
5730 is_double
= (last_mouse_button
< 0
5731 && (abs (XINT (event
->x
) - last_mouse_x
) <= fuzz
)
5732 && (abs (XINT (event
->y
) - last_mouse_y
) <= fuzz
)
5733 && button_down_time
!= 0
5734 && (EQ (Vdouble_click_time
, Qt
)
5735 || (INTEGERP (Vdouble_click_time
)
5736 && ((int)(event
->timestamp
- button_down_time
)
5737 < XINT (Vdouble_click_time
)))));
5740 double_click_count
++;
5741 event
->modifiers
|= ((double_click_count
> 2)
5747 double_click_count
= 1;
5748 event
->modifiers
|= click_modifier
;
5751 button_down_time
= event
->timestamp
;
5752 /* Use a negative value to distinguish wheel from mouse button. */
5753 last_mouse_button
= -1;
5754 last_mouse_x
= XINT (event
->x
);
5755 last_mouse_y
= XINT (event
->y
);
5761 if (event
->modifiers
& up_modifier
)
5763 /* Emit a wheel-up event. */
5764 event
->modifiers
&= ~up_modifier
;
5767 else if (event
->modifiers
& down_modifier
)
5769 /* Emit a wheel-down event. */
5770 event
->modifiers
&= ~down_modifier
;
5774 /* Every wheel event should either have the down_modifier or
5775 the up_modifier set. */
5778 /* Get the symbol we should use for the wheel event. */
5779 head
= modify_event_symbol (symbol_num
,
5785 ASIZE (wheel_syms
));
5788 if (event
->modifiers
& (double_modifier
| triple_modifier
))
5791 Fcons (make_number (double_click_count
),
5800 #ifdef USE_TOOLKIT_SCROLL_BARS
5802 /* We don't have down and up events if using toolkit scroll bars,
5803 so make this always a click event. Store in the `part' of
5804 the Lisp event a symbol which maps to the following actions:
5806 `above_handle' page up
5807 `below_handle' page down
5811 `bottom' bottom of buffer
5812 `handle' thumb has been dragged.
5813 `end-scroll' end of interaction with scroll bar
5815 The incoming input_event contains in its `part' member an
5816 index of type `enum scroll_bar_part' which we can use as an
5817 index in scroll_bar_parts to get the appropriate symbol. */
5819 case SCROLL_BAR_CLICK_EVENT
:
5821 Lisp_Object position
, head
, window
, portion_whole
, part
;
5823 window
= event
->frame_or_window
;
5824 portion_whole
= Fcons (event
->x
, event
->y
);
5825 part
= *scroll_bar_parts
[(int) event
->part
];
5829 Fcons (Qvertical_scroll_bar
,
5830 Fcons (portion_whole
,
5831 Fcons (make_number (event
->timestamp
),
5832 Fcons (part
, Qnil
)))));
5834 /* Always treat scroll bar events as clicks. */
5835 event
->modifiers
|= click_modifier
;
5836 event
->modifiers
&= ~up_modifier
;
5838 if (event
->code
>= ASIZE (mouse_syms
))
5839 mouse_syms
= larger_vector (mouse_syms
, event
->code
+ 1, Qnil
);
5841 /* Get the symbol we should use for the mouse click. */
5842 head
= modify_event_symbol (event
->code
,
5847 XVECTOR (mouse_syms
)->size
);
5848 return Fcons (head
, Fcons (position
, Qnil
));
5851 #endif /* USE_TOOLKIT_SCROLL_BARS */
5854 case W32_SCROLL_BAR_CLICK_EVENT
:
5856 int button
= event
->code
;
5858 Lisp_Object position
;
5859 Lisp_Object
*start_pos_ptr
;
5860 Lisp_Object start_pos
;
5864 Lisp_Object portion_whole
;
5867 window
= event
->frame_or_window
;
5868 portion_whole
= Fcons (event
->x
, event
->y
);
5869 part
= *scroll_bar_parts
[(int) event
->part
];
5873 Fcons (Qvertical_scroll_bar
,
5874 Fcons (portion_whole
,
5875 Fcons (make_number (event
->timestamp
),
5876 Fcons (part
, Qnil
)))));
5879 /* Always treat W32 scroll bar events as clicks. */
5880 event
->modifiers
|= click_modifier
;
5883 /* Get the symbol we should use for the mouse click. */
5886 head
= modify_event_symbol (button
,
5891 XVECTOR (mouse_syms
)->size
);
5897 #endif /* WINDOWSNT */
5899 case DRAG_N_DROP_EVENT
:
5902 Lisp_Object head
, position
;
5905 f
= XFRAME (event
->frame_or_window
);
5908 /* Ignore mouse events that were made on frames that
5909 have been deleted. */
5910 if (! FRAME_LIVE_P (f
))
5913 position
= make_lispy_position (f
, &event
->x
, &event
->y
,
5916 head
= modify_event_symbol (0, event
->modifiers
,
5918 lispy_drag_n_drop_names
,
5919 &drag_n_drop_syms
, 1);
5925 #endif /* HAVE_MOUSE */
5927 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
5928 || defined (USE_GTK)
5929 case MENU_BAR_EVENT
:
5930 if (EQ (event
->arg
, event
->frame_or_window
))
5931 /* This is the prefix key. We translate this to
5932 `(menu_bar)' because the code in keyboard.c for menu
5933 events, which we use, relies on this. */
5934 return Fcons (Qmenu_bar
, Qnil
);
5938 case SELECT_WINDOW_EVENT
:
5939 /* Make an event (select-window (WINDOW)). */
5940 return Fcons (Qselect_window
,
5941 Fcons (Fcons (event
->frame_or_window
, Qnil
),
5944 case TOOL_BAR_EVENT
:
5945 if (EQ (event
->arg
, event
->frame_or_window
))
5946 /* This is the prefix key. We translate this to
5947 `(tool_bar)' because the code in keyboard.c for tool bar
5948 events, which we use, relies on this. */
5949 return Fcons (Qtool_bar
, Qnil
);
5950 else if (SYMBOLP (event
->arg
))
5951 return apply_modifiers (event
->modifiers
, event
->arg
);
5954 case USER_SIGNAL_EVENT
:
5955 /* A user signal. */
5956 return *lispy_user_signals
[event
->code
];
5958 case SAVE_SESSION_EVENT
:
5959 return Qsave_session
;
5962 case MAC_APPLE_EVENT
:
5964 Lisp_Object spec
[2];
5968 return Fcons (Qmac_apple_event
,
5969 Fcons (Fvector (2, spec
),
5970 Fcons (event
->arg
, Qnil
)));
5974 /* The 'kind' field of the event is something we don't recognize. */
5983 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
5985 Lisp_Object bar_window
;
5986 enum scroll_bar_part part
;
5990 /* Is it a scroll bar movement? */
5991 if (frame
&& ! NILP (bar_window
))
5993 Lisp_Object part_sym
;
5995 part_sym
= *scroll_bar_parts
[(int) part
];
5996 return Fcons (Qscroll_bar_movement
,
5997 (Fcons (Fcons (bar_window
,
5998 Fcons (Qvertical_scroll_bar
,
5999 Fcons (Fcons (x
, y
),
6000 Fcons (make_number (time
),
6006 /* Or is it an ordinary mouse movement? */
6009 Lisp_Object position
;
6011 position
= make_lispy_position (frame
, &x
, &y
, time
);
6013 return Fcons (Qmouse_movement
,
6019 #endif /* HAVE_MOUSE */
6021 /* Construct a switch frame event. */
6023 make_lispy_switch_frame (frame
)
6026 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
6029 /* Manipulating modifiers. */
6031 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
6033 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
6034 SYMBOL's name of the end of the modifiers; the string from this
6035 position is the unmodified symbol name.
6037 This doesn't use any caches. */
6040 parse_modifiers_uncached (symbol
, modifier_end
)
6048 CHECK_SYMBOL (symbol
);
6051 name
= SYMBOL_NAME (symbol
);
6053 for (i
= 0; i
+2 <= SBYTES (name
); )
6055 int this_mod_end
= 0;
6058 /* See if the name continues with a modifier word.
6059 Check that the word appears, but don't check what follows it.
6060 Set this_mod and this_mod_end to record what we find. */
6062 switch (SREF (name
, i
))
6064 #define SINGLE_LETTER_MOD(BIT) \
6065 (this_mod_end = i + 1, this_mod = BIT)
6068 SINGLE_LETTER_MOD (alt_modifier
);
6072 SINGLE_LETTER_MOD (ctrl_modifier
);
6076 SINGLE_LETTER_MOD (hyper_modifier
);
6080 SINGLE_LETTER_MOD (meta_modifier
);
6084 SINGLE_LETTER_MOD (shift_modifier
);
6088 SINGLE_LETTER_MOD (super_modifier
);
6091 #undef SINGLE_LETTER_MOD
6093 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
6094 if (i + LEN + 1 <= SBYTES (name) \
6095 && ! strncmp (SDATA (name) + i, NAME, LEN)) \
6097 this_mod_end = i + LEN; \
6102 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
6103 MULTI_LETTER_MOD (down_modifier
, "down", 4);
6104 MULTI_LETTER_MOD (double_modifier
, "double", 6);
6108 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
6110 #undef MULTI_LETTER_MOD
6114 /* If we found no modifier, stop looking for them. */
6115 if (this_mod_end
== 0)
6118 /* Check there is a dash after the modifier, so that it
6119 really is a modifier. */
6120 if (this_mod_end
>= SBYTES (name
)
6121 || SREF (name
, this_mod_end
) != '-')
6124 /* This modifier is real; look for another. */
6125 modifiers
|= this_mod
;
6126 i
= this_mod_end
+ 1;
6129 /* Should we include the `click' modifier? */
6130 if (! (modifiers
& (down_modifier
| drag_modifier
6131 | double_modifier
| triple_modifier
))
6132 && i
+ 7 == SBYTES (name
)
6133 && strncmp (SDATA (name
) + i
, "mouse-", 6) == 0
6134 && ('0' <= SREF (name
, i
+ 6) && SREF (name
, i
+ 6) <= '9'))
6135 modifiers
|= click_modifier
;
6143 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
6144 prepended to the string BASE[0..BASE_LEN-1].
6145 This doesn't use any caches. */
6147 apply_modifiers_uncached (modifiers
, base
, base_len
, base_len_byte
)
6150 int base_len
, base_len_byte
;
6152 /* Since BASE could contain nulls, we can't use intern here; we have
6153 to use Fintern, which expects a genuine Lisp_String, and keeps a
6156 = (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
6162 /* Only the event queue may use the `up' modifier; it should always
6163 be turned into a click or drag event before presented to lisp code. */
6164 if (modifiers
& up_modifier
)
6167 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
6168 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
6169 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
6170 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
6171 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
6172 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
6173 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
6174 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
6175 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
6176 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
6177 /* The click modifier is denoted by the absence of other modifiers. */
6181 mod_len
= p
- new_mods
;
6185 Lisp_Object new_name
;
6187 new_name
= make_uninit_multibyte_string (mod_len
+ base_len
,
6188 mod_len
+ base_len_byte
);
6189 bcopy (new_mods
, SDATA (new_name
), mod_len
);
6190 bcopy (base
, SDATA (new_name
) + mod_len
, base_len_byte
);
6192 return Fintern (new_name
, Qnil
);
6197 static char *modifier_names
[] =
6199 "up", "down", "drag", "click", "double", "triple", 0, 0,
6200 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6201 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
6203 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
6205 static Lisp_Object modifier_symbols
;
6207 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
6209 lispy_modifier_list (modifiers
)
6212 Lisp_Object modifier_list
;
6215 modifier_list
= Qnil
;
6216 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
6217 if (modifiers
& (1<<i
))
6218 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
6221 return modifier_list
;
6225 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
6226 where UNMODIFIED is the unmodified form of SYMBOL,
6227 MASK is the set of modifiers present in SYMBOL's name.
6228 This is similar to parse_modifiers_uncached, but uses the cache in
6229 SYMBOL's Qevent_symbol_element_mask property, and maintains the
6230 Qevent_symbol_elements property. */
6233 parse_modifiers (symbol
)
6236 Lisp_Object elements
;
6238 elements
= Fget (symbol
, Qevent_symbol_element_mask
);
6239 if (CONSP (elements
))
6244 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
6245 Lisp_Object unmodified
;
6248 unmodified
= Fintern (make_string (SDATA (SYMBOL_NAME (symbol
)) + end
,
6249 SBYTES (SYMBOL_NAME (symbol
)) - end
),
6252 if (modifiers
& ~INTMASK
)
6254 XSETFASTINT (mask
, modifiers
);
6255 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
6257 /* Cache the parsing results on SYMBOL. */
6258 Fput (symbol
, Qevent_symbol_element_mask
,
6260 Fput (symbol
, Qevent_symbol_elements
,
6261 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
6263 /* Since we know that SYMBOL is modifiers applied to unmodified,
6264 it would be nice to put that in unmodified's cache.
6265 But we can't, since we're not sure that parse_modifiers is
6272 /* Apply the modifiers MODIFIERS to the symbol BASE.
6273 BASE must be unmodified.
6275 This is like apply_modifiers_uncached, but uses BASE's
6276 Qmodifier_cache property, if present. It also builds
6277 Qevent_symbol_elements properties, since it has that info anyway.
6279 apply_modifiers copies the value of BASE's Qevent_kind property to
6280 the modified symbol. */
6282 apply_modifiers (modifiers
, base
)
6286 Lisp_Object cache
, index
, entry
, new_symbol
;
6288 /* Mask out upper bits. We don't know where this value's been. */
6289 modifiers
&= INTMASK
;
6291 /* The click modifier never figures into cache indices. */
6292 cache
= Fget (base
, Qmodifier_cache
);
6293 XSETFASTINT (index
, (modifiers
& ~click_modifier
));
6294 entry
= assq_no_quit (index
, cache
);
6297 new_symbol
= XCDR (entry
);
6300 /* We have to create the symbol ourselves. */
6301 new_symbol
= apply_modifiers_uncached (modifiers
,
6302 SDATA (SYMBOL_NAME (base
)),
6303 SCHARS (SYMBOL_NAME (base
)),
6304 SBYTES (SYMBOL_NAME (base
)));
6306 /* Add the new symbol to the base's cache. */
6307 entry
= Fcons (index
, new_symbol
);
6308 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
6310 /* We have the parsing info now for free, so we could add it to
6312 XSETFASTINT (index, modifiers);
6313 Fput (new_symbol, Qevent_symbol_element_mask,
6314 Fcons (base, Fcons (index, Qnil)));
6315 Fput (new_symbol, Qevent_symbol_elements,
6316 Fcons (base, lispy_modifier_list (modifiers)));
6317 Sadly, this is only correct if `base' is indeed a base event,
6318 which is not necessarily the case. -stef */
6321 /* Make sure this symbol is of the same kind as BASE.
6323 You'd think we could just set this once and for all when we
6324 intern the symbol above, but reorder_modifiers may call us when
6325 BASE's property isn't set right; we can't assume that just
6326 because it has a Qmodifier_cache property it must have its
6327 Qevent_kind set right as well. */
6328 if (NILP (Fget (new_symbol
, Qevent_kind
)))
6332 kind
= Fget (base
, Qevent_kind
);
6334 Fput (new_symbol
, Qevent_kind
, kind
);
6341 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
6342 return a symbol with the modifiers placed in the canonical order.
6343 Canonical order is alphabetical, except for down and drag, which
6344 always come last. The 'click' modifier is never written out.
6346 Fdefine_key calls this to make sure that (for example) C-M-foo
6347 and M-C-foo end up being equivalent in the keymap. */
6350 reorder_modifiers (symbol
)
6353 /* It's hopefully okay to write the code this way, since everything
6354 will soon be in caches, and no consing will be done at all. */
6357 parsed
= parse_modifiers (symbol
);
6358 return apply_modifiers ((int) XINT (XCAR (XCDR (parsed
))),
6363 /* For handling events, we often want to produce a symbol whose name
6364 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
6365 to some base, like the name of a function key or mouse button.
6366 modify_event_symbol produces symbols of this sort.
6368 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
6369 is the name of the i'th symbol. TABLE_SIZE is the number of elements
6372 Alternatively, NAME_ALIST_OR_STEM is either an alist mapping codes
6373 into symbol names, or a string specifying a name stem used to
6374 construct a symbol name or the form `STEM-N', where N is the decimal
6375 representation of SYMBOL_NUM. NAME_ALIST_OR_STEM is used if it is
6376 non-nil; otherwise NAME_TABLE is used.
6378 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
6379 persist between calls to modify_event_symbol that it can use to
6380 store a cache of the symbols it's generated for this NAME_TABLE
6381 before. The object stored there may be a vector or an alist.
6383 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
6385 MODIFIERS is a set of modifier bits (as given in struct input_events)
6386 whose prefixes should be applied to the symbol name.
6388 SYMBOL_KIND is the value to be placed in the event_kind property of
6389 the returned symbol.
6391 The symbols we create are supposed to have an
6392 `event-symbol-elements' property, which lists the modifiers present
6393 in the symbol's name. */
6396 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_alist_or_stem
,
6397 name_table
, symbol_table
, table_size
)
6400 Lisp_Object symbol_kind
;
6401 Lisp_Object name_alist_or_stem
;
6403 Lisp_Object
*symbol_table
;
6404 unsigned int table_size
;
6407 Lisp_Object symbol_int
;
6409 /* Get rid of the "vendor-specific" bit here. */
6410 XSETINT (symbol_int
, symbol_num
& 0xffffff);
6412 /* Is this a request for a valid symbol? */
6413 if (symbol_num
< 0 || symbol_num
>= table_size
)
6416 if (CONSP (*symbol_table
))
6417 value
= Fcdr (assq_no_quit (symbol_int
, *symbol_table
));
6419 /* If *symbol_table doesn't seem to be initialized properly, fix that.
6420 *symbol_table should be a lisp vector TABLE_SIZE elements long,
6421 where the Nth element is the symbol for NAME_TABLE[N], or nil if
6422 we've never used that symbol before. */
6425 if (! VECTORP (*symbol_table
)
6426 || XVECTOR (*symbol_table
)->size
!= table_size
)
6430 XSETFASTINT (size
, table_size
);
6431 *symbol_table
= Fmake_vector (size
, Qnil
);
6434 value
= XVECTOR (*symbol_table
)->contents
[symbol_num
];
6437 /* Have we already used this symbol before? */
6440 /* No; let's create it. */
6441 if (CONSP (name_alist_or_stem
))
6442 value
= Fcdr_safe (Fassq (symbol_int
, name_alist_or_stem
));
6443 else if (STRINGP (name_alist_or_stem
))
6445 int len
= SBYTES (name_alist_or_stem
);
6446 char *buf
= (char *) alloca (len
+ 50);
6447 sprintf (buf
, "%s-%ld", SDATA (name_alist_or_stem
),
6448 (long) XINT (symbol_int
) + 1);
6449 value
= intern (buf
);
6451 else if (name_table
!= 0 && name_table
[symbol_num
])
6452 value
= intern (name_table
[symbol_num
]);
6454 #ifdef HAVE_WINDOW_SYSTEM
6457 char *name
= x_get_keysym_name (symbol_num
);
6459 value
= intern (name
);
6466 sprintf (buf
, "key-%d", symbol_num
);
6467 value
= intern (buf
);
6470 if (CONSP (*symbol_table
))
6471 *symbol_table
= Fcons (Fcons (symbol_int
, value
), *symbol_table
);
6473 XVECTOR (*symbol_table
)->contents
[symbol_num
] = value
;
6475 /* Fill in the cache entries for this symbol; this also
6476 builds the Qevent_symbol_elements property, which the user
6478 apply_modifiers (modifiers
& click_modifier
, value
);
6479 Fput (value
, Qevent_kind
, symbol_kind
);
6482 /* Apply modifiers to that symbol. */
6483 return apply_modifiers (modifiers
, value
);
6486 /* Convert a list that represents an event type,
6487 such as (ctrl meta backspace), into the usual representation of that
6488 event type as a number or a symbol. */
6490 DEFUN ("event-convert-list", Fevent_convert_list
, Sevent_convert_list
, 1, 1, 0,
6491 doc
: /* Convert the event description list EVENT-DESC to an event type.
6492 EVENT-DESC should contain one base event type (a character or symbol)
6493 and zero or more modifier names (control, meta, hyper, super, shift, alt,
6494 drag, down, double or triple). The base must be last.
6495 The return value is an event type (a character or symbol) which
6496 has the same base event type and all the specified modifiers. */)
6498 Lisp_Object event_desc
;
6506 while (CONSP (rest
))
6514 /* Given a symbol, see if it is a modifier name. */
6515 if (SYMBOLP (elt
) && CONSP (rest
))
6516 this = parse_solitary_modifier (elt
);
6520 else if (!NILP (base
))
6521 error ("Two bases given in one event");
6527 /* Let the symbol A refer to the character A. */
6528 if (SYMBOLP (base
) && SCHARS (SYMBOL_NAME (base
)) == 1)
6529 XSETINT (base
, SREF (SYMBOL_NAME (base
), 0));
6531 if (INTEGERP (base
))
6533 /* Turn (shift a) into A. */
6534 if ((modifiers
& shift_modifier
) != 0
6535 && (XINT (base
) >= 'a' && XINT (base
) <= 'z'))
6537 XSETINT (base
, XINT (base
) - ('a' - 'A'));
6538 modifiers
&= ~shift_modifier
;
6541 /* Turn (control a) into C-a. */
6542 if (modifiers
& ctrl_modifier
)
6543 return make_number ((modifiers
& ~ctrl_modifier
)
6544 | make_ctrl_char (XINT (base
)));
6546 return make_number (modifiers
| XINT (base
));
6548 else if (SYMBOLP (base
))
6549 return apply_modifiers (modifiers
, base
);
6552 error ("Invalid base event");
6557 /* Try to recognize SYMBOL as a modifier name.
6558 Return the modifier flag bit, or 0 if not recognized. */
6561 parse_solitary_modifier (symbol
)
6564 Lisp_Object name
= SYMBOL_NAME (symbol
);
6566 switch (SREF (name
, 0))
6568 #define SINGLE_LETTER_MOD(BIT) \
6569 if (SBYTES (name) == 1) \
6572 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
6573 if (LEN == SBYTES (name) \
6574 && ! strncmp (SDATA (name), NAME, LEN)) \
6578 SINGLE_LETTER_MOD (alt_modifier
);
6582 MULTI_LETTER_MOD (alt_modifier
, "alt", 3);
6586 SINGLE_LETTER_MOD (ctrl_modifier
);
6590 MULTI_LETTER_MOD (ctrl_modifier
, "ctrl", 4);
6591 MULTI_LETTER_MOD (ctrl_modifier
, "control", 7);
6595 SINGLE_LETTER_MOD (hyper_modifier
);
6599 MULTI_LETTER_MOD (hyper_modifier
, "hyper", 5);
6603 SINGLE_LETTER_MOD (meta_modifier
);
6607 MULTI_LETTER_MOD (meta_modifier
, "meta", 4);
6611 SINGLE_LETTER_MOD (shift_modifier
);
6615 MULTI_LETTER_MOD (shift_modifier
, "shift", 5);
6616 MULTI_LETTER_MOD (super_modifier
, "super", 5);
6617 SINGLE_LETTER_MOD (super_modifier
);
6621 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
6622 MULTI_LETTER_MOD (down_modifier
, "down", 4);
6623 MULTI_LETTER_MOD (double_modifier
, "double", 6);
6627 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
6630 #undef SINGLE_LETTER_MOD
6631 #undef MULTI_LETTER_MOD
6637 /* Return 1 if EVENT is a list whose elements are all integers or symbols.
6638 Such a list is not valid as an event,
6639 but it can be a Lucid-style event type list. */
6642 lucid_event_type_list_p (object
)
6647 if (! CONSP (object
))
6650 if (EQ (XCAR (object
), Qhelp_echo
)
6651 || EQ (XCAR (object
), Qvertical_line
)
6652 || EQ (XCAR (object
), Qmode_line
)
6653 || EQ (XCAR (object
), Qheader_line
))
6656 for (tail
= object
; CONSP (tail
); tail
= XCDR (tail
))
6660 if (! (INTEGERP (elt
) || SYMBOLP (elt
)))
6667 /* Store into *addr a value nonzero if terminal input chars are available.
6668 Serves the purpose of ioctl (0, FIONREAD, addr)
6669 but works even if FIONREAD does not exist.
6670 (In fact, this may actually read some input.)
6672 If READABLE_EVENTS_DO_TIMERS_NOW is set in FLAGS, actually run
6673 timer events that are ripe.
6674 If READABLE_EVENTS_FILTER_EVENTS is set in FLAGS, ignore internal
6675 events (FOCUS_IN_EVENT).
6676 If READABLE_EVENTS_IGNORE_SQUEEZABLES is set in FLAGS, ignore mouse
6677 movements and toolkit scroll bar thumb drags. */
6680 get_input_pending (addr
, flags
)
6684 /* First of all, have we already counted some input? */
6685 *addr
= (!NILP (Vquit_flag
) || readable_events (flags
));
6687 /* If input is being read as it arrives, and we have none, there is none. */
6688 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
6691 /* Try to read some input and see how much we get. */
6693 *addr
= (!NILP (Vquit_flag
) || readable_events (flags
));
6696 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
6699 gobble_input (expected
)
6704 if (interrupt_input
)
6707 mask
= sigblock (sigmask (SIGIO
));
6708 read_avail_input (expected
);
6712 #ifdef POLL_FOR_INPUT
6713 if (read_socket_hook
&& !interrupt_input
&& poll_suppress_count
== 0)
6716 mask
= sigblock (sigmask (SIGALRM
));
6717 read_avail_input (expected
);
6723 read_avail_input (expected
);
6727 /* Put a BUFFER_SWITCH_EVENT in the buffer
6728 so that read_key_sequence will notice the new current buffer. */
6731 record_asynch_buffer_change ()
6733 struct input_event event
;
6737 event
.kind
= BUFFER_SWITCH_EVENT
;
6738 event
.frame_or_window
= Qnil
;
6742 /* We don't need a buffer-switch event unless Emacs is waiting for input.
6743 The purpose of the event is to make read_key_sequence look up the
6744 keymaps again. If we aren't in read_key_sequence, we don't need one,
6745 and the event could cause trouble by messing up (input-pending-p). */
6746 tem
= Fwaiting_for_user_input_p ();
6750 /* We never need these events if we have no asynchronous subprocesses. */
6754 /* Make sure no interrupt happens while storing the event. */
6756 if (interrupt_input
)
6759 mask
= sigblock (sigmask (SIGIO
));
6760 kbd_buffer_store_event (&event
);
6767 kbd_buffer_store_event (&event
);
6774 /* Read any terminal input already buffered up by the system
6775 into the kbd_buffer, but do not wait.
6777 EXPECTED should be nonzero if the caller knows there is some input.
6779 Except on VMS, all input is read by this function.
6780 If interrupt_input is nonzero, this function MUST be called
6781 only when SIGIO is blocked.
6783 Returns the number of keyboard chars read, or -1 meaning
6784 this is a bad time to try to read input. */
6787 read_avail_input (expected
)
6793 if (read_socket_hook
)
6796 struct input_event hold_quit
;
6798 EVENT_INIT (hold_quit
);
6799 hold_quit
.kind
= NO_EVENT
;
6801 /* No need for FIONREAD or fcntl; just say don't wait. */
6802 while (nr
= (*read_socket_hook
) (input_fd
, expected
, &hold_quit
), nr
> 0)
6807 if (hold_quit
.kind
!= NO_EVENT
)
6808 kbd_buffer_store_event (&hold_quit
);
6812 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
6813 the kbd_buffer can really hold. That may prevent loss
6814 of characters on some systems when input is stuffed at us. */
6815 unsigned char cbuf
[KBD_BUFFER_SIZE
- 1];
6818 /* Determine how many characters we should *try* to read. */
6821 #else /* not WINDOWSNT */
6823 n_to_read
= dos_keysns ();
6826 #else /* not MSDOS */
6828 /* Find out how much input is available. */
6829 if (ioctl (input_fd
, FIONREAD
, &n_to_read
) < 0)
6830 /* Formerly simply reported no input, but that sometimes led to
6831 a failure of Emacs to terminate.
6832 SIGHUP seems appropriate if we can't reach the terminal. */
6833 /* ??? Is it really right to send the signal just to this process
6834 rather than to the whole process group?
6835 Perhaps on systems with FIONREAD Emacs is alone in its group. */
6837 if (! noninteractive
)
6838 kill (getpid (), SIGHUP
);
6844 if (n_to_read
> sizeof cbuf
)
6845 n_to_read
= sizeof cbuf
;
6846 #else /* no FIONREAD */
6847 #if defined (USG) || defined (DGUX) || defined(CYGWIN)
6848 /* Read some input if available, but don't wait. */
6849 n_to_read
= sizeof cbuf
;
6850 fcntl (input_fd
, F_SETFL
, O_NDELAY
);
6855 #endif /* not MSDOS */
6856 #endif /* not WINDOWSNT */
6858 /* Now read; for one reason or another, this will not block.
6859 NREAD is set to the number of chars read. */
6863 cbuf
[0] = dos_keyread ();
6866 nread
= emacs_read (input_fd
, cbuf
, n_to_read
);
6868 /* POSIX infers that processes which are not in the session leader's
6869 process group won't get SIGHUP's at logout time. BSDI adheres to
6870 this part standard and returns -1 from read (0) with errno==EIO
6871 when the control tty is taken away.
6872 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
6873 if (nread
== -1 && errno
== EIO
)
6875 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
6876 /* The kernel sometimes fails to deliver SIGHUP for ptys.
6877 This looks incorrect, but it isn't, because _BSD causes
6878 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
6879 and that causes a value other than 0 when there is no input. */
6885 /* We used to retry the read if it was interrupted.
6886 But this does the wrong thing when O_NDELAY causes
6887 an EAGAIN error. Does anybody know of a situation
6888 where a retry is actually needed? */
6890 nread
< 0 && (errno
== EAGAIN
6904 #if defined (USG) || defined (DGUX) || defined (CYGWIN)
6905 fcntl (input_fd
, F_SETFL
, 0);
6906 #endif /* USG or DGUX or CYGWIN */
6907 #endif /* no FIONREAD */
6908 for (i
= 0; i
< nread
; i
++)
6910 struct input_event buf
;
6912 buf
.kind
= ASCII_KEYSTROKE_EVENT
;
6914 if (meta_key
== 1 && (cbuf
[i
] & 0x80))
6915 buf
.modifiers
= meta_modifier
;
6920 buf
.frame_or_window
= selected_frame
;
6923 kbd_buffer_store_event (&buf
);
6924 /* Don't look at input that follows a C-g too closely.
6925 This reduces lossage due to autorepeat on C-g. */
6926 if (buf
.kind
== ASCII_KEYSTROKE_EVENT
6927 && buf
.code
== quit_char
)
6934 #endif /* not VMS */
6937 handle_async_input ()
6940 extern int select_alarmed
;
6943 interrupt_input_pending
= 0;
6948 nread
= read_avail_input (1);
6949 /* -1 means it's not ok to read the input now.
6950 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
6951 0 means there was no keyboard input available. */
6956 select_alarmed
= 1; /* Force the select emulator back to life */
6961 #ifdef SIGIO /* for entire page */
6962 /* Note SIGIO has been undef'd if FIONREAD is missing. */
6965 input_available_signal (signo
)
6968 /* Must preserve main program's value of errno. */
6969 int old_errno
= errno
;
6970 #if defined (USG) && !defined (POSIX_SIGNALS)
6971 /* USG systems forget handlers when they are used;
6972 must reestablish each time */
6973 signal (signo
, input_available_signal
);
6981 interrupt_input_pending
= 1;
6983 SIGNAL_THREAD_CHECK (signo
);
6986 if (input_available_clear_time
)
6987 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
6990 handle_async_input ();
7000 /* Send ourselves a SIGIO.
7002 This function exists so that the UNBLOCK_INPUT macro in
7003 blockinput.h can have some way to take care of input we put off
7004 dealing with, without assuming that every file which uses
7005 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
7007 reinvoke_input_signal ()
7010 handle_async_input ();
7016 static void menu_bar_item
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
, void*));
7017 static Lisp_Object menu_bar_one_keymap_changed_items
;
7019 /* These variables hold the vector under construction within
7020 menu_bar_items and its subroutines, and the current index
7021 for storing into that vector. */
7022 static Lisp_Object menu_bar_items_vector
;
7023 static int menu_bar_items_index
;
7025 /* Return a vector of menu items for a menu bar, appropriate
7026 to the current buffer. Each item has three elements in the vector:
7029 OLD is an old vector we can optionally reuse, or nil. */
7032 menu_bar_items (old
)
7035 /* The number of keymaps we're scanning right now, and the number of
7036 keymaps we have allocated space for. */
7039 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
7040 in the current keymaps, or nil where it is not a prefix. */
7043 Lisp_Object def
, tail
;
7052 /* In order to build the menus, we need to call the keymap
7053 accessors. They all call QUIT. But this function is called
7054 during redisplay, during which a quit is fatal. So inhibit
7055 quitting while building the menus.
7056 We do this instead of specbind because (1) errors will clear it anyway
7057 and (2) this avoids risk of specpdl overflow. */
7058 oquit
= Vinhibit_quit
;
7062 menu_bar_items_vector
= old
;
7064 menu_bar_items_vector
= Fmake_vector (make_number (24), Qnil
);
7065 menu_bar_items_index
= 0;
7067 /* Build our list of keymaps.
7068 If we recognize a function key and replace its escape sequence in
7069 keybuf with its symbol, or if the sequence starts with a mouse
7070 click and we need to switch buffers, we jump back here to rebuild
7071 the initial keymaps from the current buffer. */
7075 /* Should overriding-terminal-local-map and overriding-local-map apply? */
7076 if (!NILP (Voverriding_local_map_menu_flag
))
7078 /* Yes, use them (if non-nil) as well as the global map. */
7079 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
7081 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
7082 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
7083 if (!NILP (Voverriding_local_map
))
7084 maps
[nmaps
++] = Voverriding_local_map
;
7088 /* No, so use major and minor mode keymaps and keymap property.
7089 Note that menu-bar bindings in the local-map and keymap
7090 properties may not work reliable, as they are only
7091 recognized when the menu-bar (or mode-line) is updated,
7092 which does not normally happen after every command. */
7095 nminor
= current_minor_maps (NULL
, &tmaps
);
7096 maps
= (Lisp_Object
*) alloca ((nminor
+ 3) * sizeof (maps
[0]));
7098 if (tem
= get_local_map (PT
, current_buffer
, Qkeymap
), !NILP (tem
))
7099 maps
[nmaps
++] = tem
;
7100 bcopy (tmaps
, (void *) (maps
+ nmaps
), nminor
* sizeof (maps
[0]));
7102 maps
[nmaps
++] = get_local_map (PT
, current_buffer
, Qlocal_map
);
7104 maps
[nmaps
++] = current_global_map
;
7107 /* Look up in each map the dummy prefix key `menu-bar'. */
7111 for (mapno
= nmaps
- 1; mapno
>= 0; mapno
--)
7112 if (!NILP (maps
[mapno
]))
7114 def
= get_keymap (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0, 1),
7118 menu_bar_one_keymap_changed_items
= Qnil
;
7119 map_keymap (def
, menu_bar_item
, Qnil
, NULL
, 1);
7123 /* Move to the end those items that should be at the end. */
7125 for (tail
= Vmenu_bar_final_items
; CONSP (tail
); tail
= XCDR (tail
))
7128 int end
= menu_bar_items_index
;
7130 for (i
= 0; i
< end
; i
+= 4)
7131 if (EQ (XCAR (tail
), XVECTOR (menu_bar_items_vector
)->contents
[i
]))
7133 Lisp_Object tem0
, tem1
, tem2
, tem3
;
7134 /* Move the item at index I to the end,
7135 shifting all the others forward. */
7136 tem0
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 0];
7137 tem1
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 1];
7138 tem2
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
7139 tem3
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3];
7141 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
7142 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
7143 (end
- i
- 4) * sizeof (Lisp_Object
));
7144 XVECTOR (menu_bar_items_vector
)->contents
[end
- 4] = tem0
;
7145 XVECTOR (menu_bar_items_vector
)->contents
[end
- 3] = tem1
;
7146 XVECTOR (menu_bar_items_vector
)->contents
[end
- 2] = tem2
;
7147 XVECTOR (menu_bar_items_vector
)->contents
[end
- 1] = tem3
;
7152 /* Add nil, nil, nil, nil at the end. */
7153 i
= menu_bar_items_index
;
7154 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
7157 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
7158 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
7159 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
7160 menu_bar_items_vector
= tem
;
7162 /* Add this item. */
7163 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
7164 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
7165 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
7166 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
7167 menu_bar_items_index
= i
;
7169 Vinhibit_quit
= oquit
;
7170 return menu_bar_items_vector
;
7173 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
7174 If there's already an item for KEY, add this DEF to it. */
7176 Lisp_Object item_properties
;
7179 menu_bar_item (key
, item
, dummy1
, dummy2
)
7180 Lisp_Object key
, item
, dummy1
;
7183 struct gcpro gcpro1
;
7187 if (EQ (item
, Qundefined
))
7189 /* If a map has an explicit `undefined' as definition,
7190 discard any previously made menu bar item. */
7192 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
7193 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
7195 if (menu_bar_items_index
> i
+ 4)
7196 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
7197 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
7198 (menu_bar_items_index
- i
- 4) * sizeof (Lisp_Object
));
7199 menu_bar_items_index
-= 4;
7203 /* If this keymap has already contributed to this KEY,
7204 don't contribute to it a second time. */
7205 tem
= Fmemq (key
, menu_bar_one_keymap_changed_items
);
7206 if (!NILP (tem
) || NILP (item
))
7209 menu_bar_one_keymap_changed_items
7210 = Fcons (key
, menu_bar_one_keymap_changed_items
);
7212 /* We add to menu_bar_one_keymap_changed_items before doing the
7213 parse_menu_item, so that if it turns out it wasn't a menu item,
7214 it still correctly hides any further menu item. */
7216 i
= parse_menu_item (item
, 0, 1);
7221 item
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
7223 /* Find any existing item for this KEY. */
7224 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
7225 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
7228 /* If we did not find this KEY, add it at the end. */
7229 if (i
== menu_bar_items_index
)
7231 /* If vector is too small, get a bigger one. */
7232 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
7235 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
7236 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
7237 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
7238 menu_bar_items_vector
= tem
;
7241 /* Add this item. */
7242 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = key
;
7243 XVECTOR (menu_bar_items_vector
)->contents
[i
++]
7244 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
7245 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Fcons (item
, Qnil
);
7246 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = make_number (0);
7247 menu_bar_items_index
= i
;
7249 /* We did find an item for this KEY. Add ITEM to its list of maps. */
7253 old
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
7254 /* If the new and the old items are not both keymaps,
7255 the lookup will only find `item'. */
7256 item
= Fcons (item
, KEYMAPP (item
) && KEYMAPP (XCAR (old
)) ? old
: Qnil
);
7257 XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2] = item
;
7261 /* This is used as the handler when calling menu_item_eval_property. */
7263 menu_item_eval_property_1 (arg
)
7266 /* If we got a quit from within the menu computation,
7267 quit all the way out of it. This takes care of C-] in the debugger. */
7268 if (CONSP (arg
) && EQ (XCAR (arg
), Qquit
))
7269 Fsignal (Qquit
, Qnil
);
7274 /* Evaluate an expression and return the result (or nil if something
7275 went wrong). Used to evaluate dynamic parts of menu items. */
7277 menu_item_eval_property (sexpr
)
7280 int count
= SPECPDL_INDEX ();
7282 specbind (Qinhibit_redisplay
, Qt
);
7283 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
,
7284 menu_item_eval_property_1
);
7285 return unbind_to (count
, val
);
7288 /* This function parses a menu item and leaves the result in the
7289 vector item_properties.
7290 ITEM is a key binding, a possible menu item.
7291 If NOTREAL is nonzero, only check for equivalent key bindings, don't
7292 evaluate dynamic expressions in the menu item.
7293 INMENUBAR is > 0 when this is considered for an entry in a menu bar
7295 INMENUBAR is < 0 when this is considered for an entry in a keyboard menu.
7296 parse_menu_item returns true if the item is a menu item and false
7300 parse_menu_item (item
, notreal
, inmenubar
)
7302 int notreal
, inmenubar
;
7304 Lisp_Object def
, tem
, item_string
, start
;
7305 Lisp_Object cachelist
;
7307 Lisp_Object keyhint
;
7318 /* Create item_properties vector if necessary. */
7319 if (NILP (item_properties
))
7321 = Fmake_vector (make_number (ITEM_PROPERTY_ENABLE
+ 1), Qnil
);
7323 /* Initialize optional entries. */
7324 for (i
= ITEM_PROPERTY_DEF
; i
< ITEM_PROPERTY_ENABLE
; i
++)
7325 AREF (item_properties
, i
) = Qnil
;
7326 AREF (item_properties
, ITEM_PROPERTY_ENABLE
) = Qt
;
7328 /* Save the item here to protect it from GC. */
7329 AREF (item_properties
, ITEM_PROPERTY_ITEM
) = item
;
7331 item_string
= XCAR (item
);
7335 if (STRINGP (item_string
))
7337 /* Old format menu item. */
7338 AREF (item_properties
, ITEM_PROPERTY_NAME
) = item_string
;
7340 /* Maybe help string. */
7341 if (CONSP (item
) && STRINGP (XCAR (item
)))
7343 AREF (item_properties
, ITEM_PROPERTY_HELP
) = XCAR (item
);
7348 /* Maybe key binding cache. */
7349 if (CONSP (item
) && CONSP (XCAR (item
))
7350 && (NILP (XCAR (XCAR (item
)))
7351 || VECTORP (XCAR (XCAR (item
)))))
7353 cachelist
= XCAR (item
);
7357 /* This is the real definition--the function to run. */
7358 AREF (item_properties
, ITEM_PROPERTY_DEF
) = item
;
7360 /* Get enable property, if any. */
7363 tem
= Fget (item
, Qmenu_enable
);
7364 if (!NILP (Venable_disabled_menus_and_buttons
))
7365 AREF (item_properties
, ITEM_PROPERTY_ENABLE
) = Qt
;
7366 else if (!NILP (tem
))
7367 AREF (item_properties
, ITEM_PROPERTY_ENABLE
) = tem
;
7370 else if (EQ (item_string
, Qmenu_item
) && CONSP (item
))
7372 /* New format menu item. */
7373 AREF (item_properties
, ITEM_PROPERTY_NAME
) = XCAR (item
);
7374 start
= XCDR (item
);
7377 /* We have a real binding. */
7378 AREF (item_properties
, ITEM_PROPERTY_DEF
) = XCAR (start
);
7380 item
= XCDR (start
);
7381 /* Is there a cache list with key equivalences. */
7382 if (CONSP (item
) && CONSP (XCAR (item
)))
7384 cachelist
= XCAR (item
);
7388 /* Parse properties. */
7389 while (CONSP (item
) && CONSP (XCDR (item
)))
7394 if (EQ (tem
, QCenable
))
7396 if (!NILP (Venable_disabled_menus_and_buttons
))
7397 AREF (item_properties
, ITEM_PROPERTY_ENABLE
) = Qt
;
7399 AREF (item_properties
, ITEM_PROPERTY_ENABLE
) = XCAR (item
);
7401 else if (EQ (tem
, QCvisible
) && !notreal
)
7403 /* If got a visible property and that evaluates to nil
7404 then ignore this item. */
7405 tem
= menu_item_eval_property (XCAR (item
));
7409 else if (EQ (tem
, QChelp
))
7410 AREF (item_properties
, ITEM_PROPERTY_HELP
) = XCAR (item
);
7411 else if (EQ (tem
, QCfilter
))
7413 else if (EQ (tem
, QCkey_sequence
))
7416 if (NILP (cachelist
)
7417 && (SYMBOLP (tem
) || STRINGP (tem
) || VECTORP (tem
)))
7418 /* Be GC protected. Set keyhint to item instead of tem. */
7421 else if (EQ (tem
, QCkeys
))
7424 if (CONSP (tem
) || (STRINGP (tem
) && NILP (cachelist
)))
7425 AREF (item_properties
, ITEM_PROPERTY_KEYEQ
) = tem
;
7427 else if (EQ (tem
, QCbutton
) && CONSP (XCAR (item
)))
7432 if (EQ (type
, QCtoggle
) || EQ (type
, QCradio
))
7434 AREF (item_properties
, ITEM_PROPERTY_SELECTED
)
7436 AREF (item_properties
, ITEM_PROPERTY_TYPE
)
7443 else if (inmenubar
|| !NILP (start
))
7447 return 0; /* not a menu item */
7449 /* If item string is not a string, evaluate it to get string.
7450 If we don't get a string, skip this item. */
7451 item_string
= AREF (item_properties
, ITEM_PROPERTY_NAME
);
7452 if (!(STRINGP (item_string
) || notreal
))
7454 item_string
= menu_item_eval_property (item_string
);
7455 if (!STRINGP (item_string
))
7457 AREF (item_properties
, ITEM_PROPERTY_NAME
) = item_string
;
7460 /* If got a filter apply it on definition. */
7461 def
= AREF (item_properties
, ITEM_PROPERTY_DEF
);
7464 def
= menu_item_eval_property (list2 (XCAR (filter
),
7465 list2 (Qquote
, def
)));
7467 AREF (item_properties
, ITEM_PROPERTY_DEF
) = def
;
7470 /* Enable or disable selection of item. */
7471 tem
= AREF (item_properties
, ITEM_PROPERTY_ENABLE
);
7477 tem
= menu_item_eval_property (tem
);
7478 if (inmenubar
&& NILP (tem
))
7479 return 0; /* Ignore disabled items in menu bar. */
7480 AREF (item_properties
, ITEM_PROPERTY_ENABLE
) = tem
;
7483 /* If we got no definition, this item is just unselectable text which
7484 is OK in a submenu but not in the menubar. */
7486 return (inmenubar
? 0 : 1);
7488 /* See if this is a separate pane or a submenu. */
7489 def
= AREF (item_properties
, ITEM_PROPERTY_DEF
);
7490 tem
= get_keymap (def
, 0, 1);
7491 /* For a subkeymap, just record its details and exit. */
7494 AREF (item_properties
, ITEM_PROPERTY_MAP
) = tem
;
7495 AREF (item_properties
, ITEM_PROPERTY_DEF
) = tem
;
7499 /* At the top level in the menu bar, do likewise for commands also.
7500 The menu bar does not display equivalent key bindings anyway.
7501 ITEM_PROPERTY_DEF is already set up properly. */
7505 /* This is a command. See if there is an equivalent key binding. */
7506 if (NILP (cachelist
))
7508 /* We have to create a cachelist. */
7509 CHECK_IMPURE (start
);
7510 XSETCDR (start
, Fcons (Fcons (Qnil
, Qnil
), XCDR (start
)));
7511 cachelist
= XCAR (XCDR (start
));
7513 tem
= AREF (item_properties
, ITEM_PROPERTY_KEYEQ
);
7514 if (!NILP (keyhint
))
7516 XSETCAR (cachelist
, XCAR (keyhint
));
7519 else if (STRINGP (tem
))
7521 XSETCDR (cachelist
, Fsubstitute_command_keys (tem
));
7522 XSETCAR (cachelist
, Qt
);
7526 tem
= XCAR (cachelist
);
7533 tem
= Fkey_binding (tem
, Qnil
, Qnil
, Qnil
);
7535 prefix
= AREF (item_properties
, ITEM_PROPERTY_KEYEQ
);
7538 def
= XCAR (prefix
);
7539 prefix
= XCDR (prefix
);
7542 def
= AREF (item_properties
, ITEM_PROPERTY_DEF
);
7544 if (NILP (XCAR (cachelist
))) /* Have no saved key. */
7546 if (newcache
/* Always check first time. */
7547 /* Should we check everything when precomputing key
7549 /* If something had no key binding before, don't recheck it
7550 because that is too slow--except if we have a list of
7551 rebound commands in Vdefine_key_rebound_commands, do
7552 recheck any command that appears in that list. */
7553 || (CONSP (Vdefine_key_rebound_commands
)
7554 && !NILP (Fmemq (def
, Vdefine_key_rebound_commands
))))
7557 /* We had a saved key. Is it still bound to the command? */
7560 /* If the command is an alias for another
7561 (such as lmenu.el set it up), check if the
7562 original command matches the cached command. */
7563 && !(SYMBOLP (def
) && EQ (tem
, XSYMBOL (def
)->function
))))
7564 chkcache
= 1; /* Need to recompute key binding. */
7568 /* Recompute equivalent key binding. If the command is an alias
7569 for another (such as lmenu.el set it up), see if the original
7570 command name has equivalent keys. Otherwise look up the
7571 specified command itself. We don't try both, because that
7572 makes lmenu menus slow. */
7574 && SYMBOLP (XSYMBOL (def
)->function
)
7575 && ! NILP (Fget (def
, Qmenu_alias
)))
7576 def
= XSYMBOL (def
)->function
;
7577 tem
= Fwhere_is_internal (def
, Qnil
, Qt
, Qnil
, Qt
);
7578 XSETCAR (cachelist
, tem
);
7581 XSETCDR (cachelist
, Qnil
);
7585 else if (!NILP (keyhint
) && !NILP (XCAR (cachelist
)))
7587 tem
= XCAR (cachelist
);
7591 newcache
= chkcache
;
7594 tem
= Fkey_description (tem
, Qnil
);
7597 if (STRINGP (XCAR (prefix
)))
7598 tem
= concat2 (XCAR (prefix
), tem
);
7599 if (STRINGP (XCDR (prefix
)))
7600 tem
= concat2 (tem
, XCDR (prefix
));
7602 XSETCDR (cachelist
, tem
);
7606 tem
= XCDR (cachelist
);
7607 if (newcache
&& !NILP (tem
))
7609 tem
= concat3 (build_string (" ("), tem
, build_string (")"));
7610 XSETCDR (cachelist
, tem
);
7613 /* If we only want to precompute equivalent key bindings, stop here. */
7617 /* If we have an equivalent key binding, use that. */
7618 AREF (item_properties
, ITEM_PROPERTY_KEYEQ
) = tem
;
7620 /* Include this when menu help is implemented.
7621 tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP];
7622 if (!(NILP (tem) || STRINGP (tem)))
7624 tem = menu_item_eval_property (tem);
7627 XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP] = tem;
7631 /* Handle radio buttons or toggle boxes. */
7632 tem
= AREF (item_properties
, ITEM_PROPERTY_SELECTED
);
7634 AREF (item_properties
, ITEM_PROPERTY_SELECTED
)
7635 = menu_item_eval_property (tem
);
7642 /***********************************************************************
7644 ***********************************************************************/
7646 /* A vector holding tool bar items while they are parsed in function
7647 tool_bar_items. Each item occupies TOOL_BAR_ITEM_NSCLOTS elements
7650 static Lisp_Object tool_bar_items_vector
;
7652 /* A vector holding the result of parse_tool_bar_item. Layout is like
7653 the one for a single item in tool_bar_items_vector. */
7655 static Lisp_Object tool_bar_item_properties
;
7657 /* Next free index in tool_bar_items_vector. */
7659 static int ntool_bar_items
;
7661 /* The symbols `tool-bar', and `:image'. */
7663 extern Lisp_Object Qtool_bar
;
7664 Lisp_Object QCimage
;
7666 /* Function prototypes. */
7668 static void init_tool_bar_items
P_ ((Lisp_Object
));
7669 static void process_tool_bar_item
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
, void*));
7670 static int parse_tool_bar_item
P_ ((Lisp_Object
, Lisp_Object
));
7671 static void append_tool_bar_item
P_ ((void));
7674 /* Return a vector of tool bar items for keymaps currently in effect.
7675 Reuse vector REUSE if non-nil. Return in *NITEMS the number of
7676 tool bar items found. */
7679 tool_bar_items (reuse
, nitems
)
7690 /* In order to build the menus, we need to call the keymap
7691 accessors. They all call QUIT. But this function is called
7692 during redisplay, during which a quit is fatal. So inhibit
7693 quitting while building the menus. We do this instead of
7694 specbind because (1) errors will clear it anyway and (2) this
7695 avoids risk of specpdl overflow. */
7696 oquit
= Vinhibit_quit
;
7699 /* Initialize tool_bar_items_vector and protect it from GC. */
7700 init_tool_bar_items (reuse
);
7702 /* Build list of keymaps in maps. Set nmaps to the number of maps
7705 /* Should overriding-terminal-local-map and overriding-local-map apply? */
7706 if (!NILP (Voverriding_local_map_menu_flag
))
7708 /* Yes, use them (if non-nil) as well as the global map. */
7709 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
7711 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
7712 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
7713 if (!NILP (Voverriding_local_map
))
7714 maps
[nmaps
++] = Voverriding_local_map
;
7718 /* No, so use major and minor mode keymaps and keymap property.
7719 Note that tool-bar bindings in the local-map and keymap
7720 properties may not work reliable, as they are only
7721 recognized when the tool-bar (or mode-line) is updated,
7722 which does not normally happen after every command. */
7725 nminor
= current_minor_maps (NULL
, &tmaps
);
7726 maps
= (Lisp_Object
*) alloca ((nminor
+ 3) * sizeof (maps
[0]));
7728 if (tem
= get_local_map (PT
, current_buffer
, Qkeymap
), !NILP (tem
))
7729 maps
[nmaps
++] = tem
;
7730 bcopy (tmaps
, (void *) (maps
+ nmaps
), nminor
* sizeof (maps
[0]));
7732 maps
[nmaps
++] = get_local_map (PT
, current_buffer
, Qlocal_map
);
7735 /* Add global keymap at the end. */
7736 maps
[nmaps
++] = current_global_map
;
7738 /* Process maps in reverse order and look up in each map the prefix
7740 for (i
= nmaps
- 1; i
>= 0; --i
)
7741 if (!NILP (maps
[i
]))
7745 keymap
= get_keymap (access_keymap (maps
[i
], Qtool_bar
, 1, 0, 1), 0, 1);
7747 map_keymap (keymap
, process_tool_bar_item
, Qnil
, NULL
, 1);
7750 Vinhibit_quit
= oquit
;
7751 *nitems
= ntool_bar_items
/ TOOL_BAR_ITEM_NSLOTS
;
7752 return tool_bar_items_vector
;
7756 /* Process the definition of KEY which is DEF. */
7759 process_tool_bar_item (key
, def
, data
, args
)
7760 Lisp_Object key
, def
, data
;
7764 extern Lisp_Object Qundefined
;
7765 struct gcpro gcpro1
, gcpro2
;
7767 /* Protect KEY and DEF from GC because parse_tool_bar_item may call
7771 if (EQ (def
, Qundefined
))
7773 /* If a map has an explicit `undefined' as definition,
7774 discard any previously made item. */
7775 for (i
= 0; i
< ntool_bar_items
; i
+= TOOL_BAR_ITEM_NSLOTS
)
7777 Lisp_Object
*v
= XVECTOR (tool_bar_items_vector
)->contents
+ i
;
7779 if (EQ (key
, v
[TOOL_BAR_ITEM_KEY
]))
7781 if (ntool_bar_items
> i
+ TOOL_BAR_ITEM_NSLOTS
)
7782 bcopy (v
+ TOOL_BAR_ITEM_NSLOTS
, v
,
7783 ((ntool_bar_items
- i
- TOOL_BAR_ITEM_NSLOTS
)
7784 * sizeof (Lisp_Object
)));
7785 ntool_bar_items
-= TOOL_BAR_ITEM_NSLOTS
;
7790 else if (parse_tool_bar_item (key
, def
))
7791 /* Append a new tool bar item to tool_bar_items_vector. Accept
7792 more than one definition for the same key. */
7793 append_tool_bar_item ();
7799 /* Parse a tool bar item specification ITEM for key KEY and return the
7800 result in tool_bar_item_properties. Value is zero if ITEM is
7803 ITEM is a list `(menu-item CAPTION BINDING PROPS...)'.
7805 CAPTION is the caption of the item, If it's not a string, it is
7806 evaluated to get a string.
7808 BINDING is the tool bar item's binding. Tool-bar items with keymaps
7809 as binding are currently ignored.
7811 The following properties are recognized:
7815 FORM is evaluated and specifies whether the tool bar item is
7816 enabled or disabled.
7820 FORM is evaluated and specifies whether the tool bar item is visible.
7822 - `:filter FUNCTION'
7824 FUNCTION is invoked with one parameter `(quote BINDING)'. Its
7825 result is stored as the new binding.
7827 - `:button (TYPE SELECTED)'
7829 TYPE must be one of `:radio' or `:toggle'. SELECTED is evaluated
7830 and specifies whether the button is selected (pressed) or not.
7834 IMAGES is either a single image specification or a vector of four
7835 image specifications. See enum tool_bar_item_images.
7837 - `:help HELP-STRING'.
7839 Gives a help string to display for the tool bar item. */
7842 parse_tool_bar_item (key
, item
)
7843 Lisp_Object key
, item
;
7845 /* Access slot with index IDX of vector tool_bar_item_properties. */
7846 #define PROP(IDX) XVECTOR (tool_bar_item_properties)->contents[IDX]
7848 Lisp_Object filter
= Qnil
;
7849 Lisp_Object caption
;
7852 /* Defininition looks like `(menu-item CAPTION BINDING PROPS...)'.
7853 Rule out items that aren't lists, don't start with
7854 `menu-item' or whose rest following `tool-bar-item' is not a
7857 || !EQ (XCAR (item
), Qmenu_item
)
7858 || (item
= XCDR (item
),
7862 /* Create tool_bar_item_properties vector if necessary. Reset it to
7864 if (VECTORP (tool_bar_item_properties
))
7866 for (i
= 0; i
< TOOL_BAR_ITEM_NSLOTS
; ++i
)
7870 tool_bar_item_properties
7871 = Fmake_vector (make_number (TOOL_BAR_ITEM_NSLOTS
), Qnil
);
7874 PROP (TOOL_BAR_ITEM_KEY
) = key
;
7875 PROP (TOOL_BAR_ITEM_ENABLED_P
) = Qt
;
7877 /* Get the caption of the item. If the caption is not a string,
7878 evaluate it to get a string. If we don't get a string, skip this
7880 caption
= XCAR (item
);
7881 if (!STRINGP (caption
))
7883 caption
= menu_item_eval_property (caption
);
7884 if (!STRINGP (caption
))
7887 PROP (TOOL_BAR_ITEM_CAPTION
) = caption
;
7889 /* Give up if rest following the caption is not a list. */
7894 /* Store the binding. */
7895 PROP (TOOL_BAR_ITEM_BINDING
) = XCAR (item
);
7898 /* Ignore cached key binding, if any. */
7899 if (CONSP (item
) && CONSP (XCAR (item
)))
7902 /* Process the rest of the properties. */
7903 for (; CONSP (item
) && CONSP (XCDR (item
)); item
= XCDR (XCDR (item
)))
7905 Lisp_Object key
, value
;
7908 value
= XCAR (XCDR (item
));
7910 if (EQ (key
, QCenable
))
7912 /* `:enable FORM'. */
7913 if (!NILP (Venable_disabled_menus_and_buttons
))
7914 PROP (TOOL_BAR_ITEM_ENABLED_P
) = Qt
;
7916 PROP (TOOL_BAR_ITEM_ENABLED_P
) = value
;
7918 else if (EQ (key
, QCvisible
))
7920 /* `:visible FORM'. If got a visible property and that
7921 evaluates to nil then ignore this item. */
7922 if (NILP (menu_item_eval_property (value
)))
7925 else if (EQ (key
, QChelp
))
7926 /* `:help HELP-STRING'. */
7927 PROP (TOOL_BAR_ITEM_HELP
) = value
;
7928 else if (EQ (key
, QCfilter
))
7929 /* ':filter FORM'. */
7931 else if (EQ (key
, QCbutton
) && CONSP (value
))
7933 /* `:button (TYPE . SELECTED)'. */
7934 Lisp_Object type
, selected
;
7936 type
= XCAR (value
);
7937 selected
= XCDR (value
);
7938 if (EQ (type
, QCtoggle
) || EQ (type
, QCradio
))
7940 PROP (TOOL_BAR_ITEM_SELECTED_P
) = selected
;
7941 PROP (TOOL_BAR_ITEM_TYPE
) = type
;
7944 else if (EQ (key
, QCimage
)
7946 || (VECTORP (value
) && XVECTOR (value
)->size
== 4)))
7947 /* Value is either a single image specification or a vector
7948 of 4 such specifications for the different button states. */
7949 PROP (TOOL_BAR_ITEM_IMAGES
) = value
;
7952 /* If got a filter apply it on binding. */
7954 PROP (TOOL_BAR_ITEM_BINDING
)
7955 = menu_item_eval_property (list2 (filter
,
7957 PROP (TOOL_BAR_ITEM_BINDING
))));
7959 /* See if the binding is a keymap. Give up if it is. */
7960 if (CONSP (get_keymap (PROP (TOOL_BAR_ITEM_BINDING
), 0, 1)))
7963 /* Enable or disable selection of item. */
7964 if (!EQ (PROP (TOOL_BAR_ITEM_ENABLED_P
), Qt
))
7965 PROP (TOOL_BAR_ITEM_ENABLED_P
)
7966 = menu_item_eval_property (PROP (TOOL_BAR_ITEM_ENABLED_P
));
7968 /* Handle radio buttons or toggle boxes. */
7969 if (!NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
)))
7970 PROP (TOOL_BAR_ITEM_SELECTED_P
)
7971 = menu_item_eval_property (PROP (TOOL_BAR_ITEM_SELECTED_P
));
7979 /* Initialize tool_bar_items_vector. REUSE, if non-nil, is a vector
7980 that can be reused. */
7983 init_tool_bar_items (reuse
)
7986 if (VECTORP (reuse
))
7987 tool_bar_items_vector
= reuse
;
7989 tool_bar_items_vector
= Fmake_vector (make_number (64), Qnil
);
7990 ntool_bar_items
= 0;
7994 /* Append parsed tool bar item properties from
7995 tool_bar_item_properties */
7998 append_tool_bar_item ()
8000 Lisp_Object
*to
, *from
;
8002 /* Enlarge tool_bar_items_vector if necessary. */
8003 if (ntool_bar_items
+ TOOL_BAR_ITEM_NSLOTS
8004 >= XVECTOR (tool_bar_items_vector
)->size
)
8006 Lisp_Object new_vector
;
8007 int old_size
= XVECTOR (tool_bar_items_vector
)->size
;
8009 new_vector
= Fmake_vector (make_number (2 * old_size
), Qnil
);
8010 bcopy (XVECTOR (tool_bar_items_vector
)->contents
,
8011 XVECTOR (new_vector
)->contents
,
8012 old_size
* sizeof (Lisp_Object
));
8013 tool_bar_items_vector
= new_vector
;
8016 /* Append entries from tool_bar_item_properties to the end of
8017 tool_bar_items_vector. */
8018 to
= XVECTOR (tool_bar_items_vector
)->contents
+ ntool_bar_items
;
8019 from
= XVECTOR (tool_bar_item_properties
)->contents
;
8020 bcopy (from
, to
, TOOL_BAR_ITEM_NSLOTS
* sizeof *to
);
8021 ntool_bar_items
+= TOOL_BAR_ITEM_NSLOTS
;
8028 /* Read a character using menus based on maps in the array MAPS.
8029 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
8030 Return t if we displayed a menu but the user rejected it.
8032 PREV_EVENT is the previous input event, or nil if we are reading
8033 the first event of a key sequence.
8035 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
8036 if we used a mouse menu to read the input, or zero otherwise. If
8037 USED_MOUSE_MENU is null, we don't dereference it.
8039 The prompting is done based on the prompt-string of the map
8040 and the strings associated with various map elements.
8042 This can be done with X menus or with menus put in the minibuf.
8043 These are done in different ways, depending on how the input will be read.
8044 Menus using X are done after auto-saving in read-char, getting the input
8045 event from Fx_popup_menu; menus using the minibuf use read_char recursively
8046 and do auto-saving in the inner call of read_char. */
8049 read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
8052 Lisp_Object prev_event
;
8053 int *used_mouse_menu
;
8056 register Lisp_Object name
= Qnil
;
8058 if (used_mouse_menu
)
8059 *used_mouse_menu
= 0;
8061 /* Use local over global Menu maps */
8063 if (! menu_prompting
)
8066 /* Optionally disregard all but the global map. */
8067 if (inhibit_local_menu_bar_menus
)
8069 maps
+= (nmaps
- 1);
8073 /* Get the menu name from the first map that has one (a prompt string). */
8074 for (mapno
= 0; mapno
< nmaps
; mapno
++)
8076 name
= Fkeymap_prompt (maps
[mapno
]);
8081 /* If we don't have any menus, just read a character normally. */
8082 if (!STRINGP (name
))
8086 /* If we got to this point via a mouse click,
8087 use a real menu for mouse selection. */
8088 if (EVENT_HAS_PARAMETERS (prev_event
)
8089 && !EQ (XCAR (prev_event
), Qmenu_bar
)
8090 && !EQ (XCAR (prev_event
), Qtool_bar
))
8092 /* Display the menu and get the selection. */
8093 Lisp_Object
*realmaps
8094 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
8098 /* Use the maps that are not nil. */
8099 for (mapno
= 0; mapno
< nmaps
; mapno
++)
8100 if (!NILP (maps
[mapno
]))
8101 realmaps
[nmaps1
++] = maps
[mapno
];
8103 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
8108 record_menu_key (XCAR (value
));
8110 /* If we got multiple events, unread all but
8112 There is no way to prevent those unread events
8113 from showing up later in last_nonmenu_event.
8114 So turn symbol and integer events into lists,
8115 to indicate that they came from a mouse menu,
8116 so that when present in last_nonmenu_event
8117 they won't confuse things. */
8118 for (tem
= XCDR (value
); !NILP (tem
); tem
= XCDR (tem
))
8120 record_menu_key (XCAR (tem
));
8121 if (SYMBOLP (XCAR (tem
))
8122 || INTEGERP (XCAR (tem
)))
8123 XSETCAR (tem
, Fcons (XCAR (tem
), Qdisabled
));
8126 /* If we got more than one event, put all but the first
8127 onto this list to be read later.
8128 Return just the first event now. */
8129 Vunread_command_events
8130 = nconc2 (XCDR (value
), Vunread_command_events
);
8131 value
= XCAR (value
);
8133 else if (NILP (value
))
8135 if (used_mouse_menu
)
8136 *used_mouse_menu
= 1;
8139 #endif /* HAVE_MENUS */
8143 /* Buffer in use so far for the minibuf prompts for menu keymaps.
8144 We make this bigger when necessary, and never free it. */
8145 static char *read_char_minibuf_menu_text
;
8146 /* Size of that buffer. */
8147 static int read_char_minibuf_menu_width
;
8150 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
8156 register Lisp_Object name
;
8158 /* FIXME: Use the minibuffer's frame width. */
8159 int width
= FRAME_COLS (SELECTED_FRAME ()) - 4;
8162 Lisp_Object rest
, vector
;
8168 if (! menu_prompting
)
8171 /* Make sure we have a big enough buffer for the menu text. */
8172 if (read_char_minibuf_menu_text
== 0)
8174 read_char_minibuf_menu_width
= width
+ 4;
8175 read_char_minibuf_menu_text
= (char *) xmalloc (width
+ 4);
8177 else if (width
+ 4 > read_char_minibuf_menu_width
)
8179 read_char_minibuf_menu_width
= width
+ 4;
8180 read_char_minibuf_menu_text
8181 = (char *) xrealloc (read_char_minibuf_menu_text
, width
+ 4);
8183 menu
= read_char_minibuf_menu_text
;
8185 /* Get the menu name from the first map that has one (a prompt string). */
8186 for (mapno
= 0; mapno
< nmaps
; mapno
++)
8188 name
= Fkeymap_prompt (maps
[mapno
]);
8193 /* If we don't have any menus, just read a character normally. */
8194 if (!STRINGP (name
))
8197 /* Prompt string always starts with map's prompt, and a space. */
8198 strcpy (menu
, SDATA (name
));
8199 nlength
= SBYTES (name
);
8200 menu
[nlength
++] = ':';
8201 menu
[nlength
++] = ' ';
8204 /* Start prompting at start of first map. */
8208 /* Present the documented bindings, a line at a time. */
8215 Lisp_Object orig_defn_macro
;
8217 /* Loop over elements of map. */
8222 /* If reached end of map, start at beginning of next map. */
8226 /* At end of last map, wrap around to first map if just starting,
8227 or end this line if already have something on it. */
8231 if (notfirst
|| nobindings
) break;
8236 /* Look at the next element of the map. */
8238 elt
= XVECTOR (vector
)->contents
[idx
];
8240 elt
= Fcar_safe (rest
);
8242 if (idx
< 0 && VECTORP (elt
))
8244 /* If we found a dense table in the keymap,
8245 advanced past it, but start scanning its contents. */
8246 rest
= Fcdr_safe (rest
);
8252 /* An ordinary element. */
8253 Lisp_Object event
, tem
;
8257 event
= Fcar_safe (elt
); /* alist */
8258 elt
= Fcdr_safe (elt
);
8262 XSETINT (event
, idx
); /* vector */
8265 /* Ignore the element if it has no prompt string. */
8266 if (INTEGERP (event
) && parse_menu_item (elt
, 0, -1))
8268 /* 1 if the char to type matches the string. */
8270 Lisp_Object upcased_event
, downcased_event
;
8271 Lisp_Object desc
= Qnil
;
8273 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
8275 upcased_event
= Fupcase (event
);
8276 downcased_event
= Fdowncase (event
);
8277 char_matches
= (XINT (upcased_event
) == SREF (s
, 0)
8278 || XINT (downcased_event
) == SREF (s
, 0));
8280 desc
= Fsingle_key_description (event
, Qnil
);
8282 #if 0 /* It is redundant to list the equivalent key bindings because
8283 the prefix is what the user has already typed. */
8285 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
8287 /* Insert equivalent keybinding. */
8288 s
= concat2 (s
, tem
);
8291 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_TYPE
];
8292 if (EQ (tem
, QCradio
) || EQ (tem
, QCtoggle
))
8294 /* Insert button prefix. */
8295 Lisp_Object selected
8296 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
];
8297 if (EQ (tem
, QCradio
))
8298 tem
= build_string (NILP (selected
) ? "(*) " : "( ) ");
8300 tem
= build_string (NILP (selected
) ? "[X] " : "[ ] ");
8301 s
= concat2 (tem
, s
);
8305 /* If we have room for the prompt string, add it to this line.
8306 If this is the first on the line, always add it. */
8307 if ((SCHARS (s
) + i
+ 2
8308 + (char_matches
? 0 : SCHARS (desc
) + 3))
8314 /* Punctuate between strings. */
8317 strcpy (menu
+ i
, ", ");
8323 /* If the char to type doesn't match the string's
8324 first char, explicitly show what char to type. */
8327 /* Add as much of string as fits. */
8328 thiswidth
= SCHARS (desc
);
8329 if (thiswidth
+ i
> width
)
8330 thiswidth
= width
- i
;
8331 bcopy (SDATA (desc
), menu
+ i
, thiswidth
);
8333 strcpy (menu
+ i
, " = ");
8337 /* Add as much of string as fits. */
8338 thiswidth
= SCHARS (s
);
8339 if (thiswidth
+ i
> width
)
8340 thiswidth
= width
- i
;
8341 bcopy (SDATA (s
), menu
+ i
, thiswidth
);
8347 /* If this element does not fit, end the line now,
8348 and save the element for the next line. */
8349 strcpy (menu
+ i
, "...");
8354 /* Move past this element. */
8355 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
8356 /* Handle reaching end of dense table. */
8361 rest
= Fcdr_safe (rest
);
8365 /* Prompt with that and read response. */
8366 message2_nolog (menu
, strlen (menu
),
8367 ! NILP (current_buffer
->enable_multibyte_characters
));
8369 /* Make believe its not a keyboard macro in case the help char
8370 is pressed. Help characters are not recorded because menu prompting
8371 is not used on replay.
8373 orig_defn_macro
= current_kboard
->defining_kbd_macro
;
8374 current_kboard
->defining_kbd_macro
= Qnil
;
8376 obj
= read_char (commandflag
, 0, 0, Qt
, 0, NULL
);
8377 while (BUFFERP (obj
));
8378 current_kboard
->defining_kbd_macro
= orig_defn_macro
;
8380 if (!INTEGERP (obj
))
8385 if (! EQ (obj
, menu_prompt_more_char
)
8386 && (!INTEGERP (menu_prompt_more_char
)
8387 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
8389 if (!NILP (current_kboard
->defining_kbd_macro
))
8390 store_kbd_macro_char (obj
);
8393 /* Help char - go round again */
8397 /* Reading key sequences. */
8399 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
8400 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
8401 keymap, or nil otherwise. Return the index of the first keymap in
8402 which KEY has any binding, or NMAPS if no map has a binding.
8404 If KEY is a meta ASCII character, treat it like meta-prefix-char
8405 followed by the corresponding non-meta character. Keymaps in
8406 CURRENT with non-prefix bindings for meta-prefix-char become nil in
8409 If KEY has no bindings in any of the CURRENT maps, NEXT is left
8412 NEXT may be the same array as CURRENT. */
8415 follow_key (key
, nmaps
, current
, defs
, next
)
8417 Lisp_Object
*current
, *defs
, *next
;
8420 int i
, first_binding
;
8422 first_binding
= nmaps
;
8423 for (i
= nmaps
- 1; i
>= 0; i
--)
8425 if (! NILP (current
[i
]))
8427 defs
[i
] = access_keymap (current
[i
], key
, 1, 0, 1);
8428 if (! NILP (defs
[i
]))
8435 /* Given the set of bindings we've found, produce the next set of maps. */
8436 if (first_binding
< nmaps
)
8437 for (i
= 0; i
< nmaps
; i
++)
8438 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap (defs
[i
], 0, 1);
8440 return first_binding
;
8443 /* Structure used to keep track of partial application of key remapping
8444 such as Vfunction_key_map and Vkey_translation_map. */
8445 typedef struct keyremap
8447 /* This is the map originally specified for this use. */
8449 /* This is a submap reached by looking up, in PARENT,
8450 the events from START to END. */
8452 /* Positions [START, END) in the key sequence buffer
8453 are the key that we have scanned so far.
8454 Those events are the ones that we will replace
8455 if PAREHT maps them into a key sequence. */
8459 /* Lookup KEY in MAP.
8460 MAP is a keymap mapping keys to key vectors or functions.
8461 If the mapping is a function and DO_FUNCTION is non-zero, then
8462 the function is called with PROMPT as parameter and its return
8463 value is used as the return value of this function (after checking
8464 that it is indeed a vector). */
8467 access_keymap_keyremap (map
, key
, prompt
, do_funcall
)
8468 Lisp_Object map
, key
, prompt
;
8473 next
= access_keymap (map
, key
, 1, 0, 1);
8475 /* Handle symbol with autoload definition. */
8476 if (SYMBOLP (next
) && !NILP (Ffboundp (next
))
8477 && CONSP (XSYMBOL (next
)->function
)
8478 && EQ (XCAR (XSYMBOL (next
)->function
), Qautoload
))
8479 do_autoload (XSYMBOL (next
)->function
, next
);
8481 /* Handle a symbol whose function definition is a keymap
8483 if (SYMBOLP (next
) && !NILP (Ffboundp (next
))
8484 && (ARRAYP (XSYMBOL (next
)->function
)
8485 || KEYMAPP (XSYMBOL (next
)->function
)))
8486 next
= XSYMBOL (next
)->function
;
8488 /* If the keymap gives a function, not an
8489 array, then call the function with one arg and use
8490 its value instead. */
8491 if (SYMBOLP (next
) && !NILP (Ffboundp (next
)) && do_funcall
)
8496 next
= call1 (next
, prompt
);
8497 /* If the function returned something invalid,
8498 barf--don't ignore it.
8499 (To ignore it safely, we would need to gcpro a bunch of
8500 other variables.) */
8501 if (! (VECTORP (next
) || STRINGP (next
)))
8502 error ("Function %s returns invalid key sequence", tem
);
8507 /* Do one step of the key remapping used for function-key-map and
8508 key-translation-map:
8509 KEYBUF is the buffer holding the input events.
8510 BUFSIZE is its maximum size.
8511 FKEY is a pointer to the keyremap structure to use.
8512 INPUT is the index of the last element in KEYBUF.
8513 DOIT if non-zero says that the remapping can actually take place.
8514 DIFF is used to return the number of keys added/removed by the remapping.
8515 PARENT is the root of the keymap.
8516 PROMPT is the prompt to use if the remapping happens through a function.
8517 The return value is non-zero if the remapping actually took place. */
8520 keyremap_step (keybuf
, bufsize
, fkey
, input
, doit
, diff
, prompt
)
8521 Lisp_Object
*keybuf
, prompt
;
8523 int input
, doit
, *diff
, bufsize
;
8525 Lisp_Object next
, key
;
8527 key
= keybuf
[fkey
->end
++];
8529 if (KEYMAPP (fkey
->parent
))
8530 next
= access_keymap_keyremap (fkey
->map
, key
, prompt
, doit
);
8534 /* If keybuf[fkey->start..fkey->end] is bound in the
8535 map and we're in a position to do the key remapping, replace it with
8536 the binding and restart with fkey->start at the end. */
8537 if ((VECTORP (next
) || STRINGP (next
)) && doit
)
8539 int len
= XFASTINT (Flength (next
));
8542 *diff
= len
- (fkey
->end
- fkey
->start
);
8544 if (input
+ *diff
>= bufsize
)
8545 error ("Key sequence too long");
8547 /* Shift the keys that follow fkey->end. */
8549 for (i
= fkey
->end
; i
< input
; i
++)
8550 keybuf
[i
+ *diff
] = keybuf
[i
];
8552 for (i
= input
- 1; i
>= fkey
->end
; i
--)
8553 keybuf
[i
+ *diff
] = keybuf
[i
];
8554 /* Overwrite the old keys with the new ones. */
8555 for (i
= 0; i
< len
; i
++)
8556 keybuf
[fkey
->start
+ i
]
8557 = Faref (next
, make_number (i
));
8559 fkey
->start
= fkey
->end
+= *diff
;
8560 fkey
->map
= fkey
->parent
;
8565 fkey
->map
= get_keymap (next
, 0, 1);
8567 /* If we no longer have a bound suffix, try a new position for
8569 if (!CONSP (fkey
->map
))
8571 fkey
->end
= ++fkey
->start
;
8572 fkey
->map
= fkey
->parent
;
8577 /* Read a sequence of keys that ends with a non prefix character,
8578 storing it in KEYBUF, a buffer of size BUFSIZE.
8580 Return the length of the key sequence stored.
8581 Return -1 if the user rejected a command menu.
8583 Echo starting immediately unless `prompt' is 0.
8585 Where a key sequence ends depends on the currently active keymaps.
8586 These include any minor mode keymaps active in the current buffer,
8587 the current buffer's local map, and the global map.
8589 If a key sequence has no other bindings, we check Vfunction_key_map
8590 to see if some trailing subsequence might be the beginning of a
8591 function key's sequence. If so, we try to read the whole function
8592 key, and substitute its symbolic name into the key sequence.
8594 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
8595 `double-' events into similar click events, if that would make them
8596 bound. We try to turn `triple-' events first into `double-' events,
8599 If we get a mouse click in a mode line, vertical divider, or other
8600 non-text area, we treat the click as if it were prefixed by the
8601 symbol denoting that area - `mode-line', `vertical-line', or
8604 If the sequence starts with a mouse click, we read the key sequence
8605 with respect to the buffer clicked on, not the current buffer.
8607 If the user switches frames in the midst of a key sequence, we put
8608 off the switch-frame event until later; the next call to
8609 read_char will return it.
8611 If FIX_CURRENT_BUFFER is nonzero, we restore current_buffer
8612 from the selected window's buffer. */
8615 read_key_sequence (keybuf
, bufsize
, prompt
, dont_downcase_last
,
8616 can_return_switch_frame
, fix_current_buffer
)
8617 Lisp_Object
*keybuf
;
8620 int dont_downcase_last
;
8621 int can_return_switch_frame
;
8622 int fix_current_buffer
;
8624 volatile Lisp_Object from_string
;
8625 volatile int count
= SPECPDL_INDEX ();
8627 /* How many keys there are in the current key sequence. */
8630 /* The length of the echo buffer when we started reading, and
8631 the length of this_command_keys when we started reading. */
8632 volatile int echo_start
;
8633 volatile int keys_start
;
8635 /* The number of keymaps we're scanning right now, and the number of
8636 keymaps we have allocated space for. */
8638 volatile int nmaps_allocated
= 0;
8640 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
8641 the current keymaps. */
8642 Lisp_Object
*volatile defs
= NULL
;
8644 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
8645 in the current keymaps, or nil where it is not a prefix. */
8646 Lisp_Object
*volatile submaps
= NULL
;
8648 /* The local map to start out with at start of key sequence. */
8649 volatile Lisp_Object orig_local_map
;
8651 /* The map from the `keymap' property to start out with at start of
8653 volatile Lisp_Object orig_keymap
;
8655 /* 1 if we have already considered switching to the local-map property
8656 of the place where a mouse click occurred. */
8657 volatile int localized_local_map
= 0;
8659 /* The index in defs[] of the first keymap that has a binding for
8660 this key sequence. In other words, the lowest i such that
8661 defs[i] is non-nil. */
8662 volatile int first_binding
;
8663 /* Index of the first key that has no binding.
8664 It is useless to try fkey.start larger than that. */
8665 volatile int first_unbound
;
8667 /* If t < mock_input, then KEYBUF[t] should be read as the next
8670 We use this to recover after recognizing a function key. Once we
8671 realize that a suffix of the current key sequence is actually a
8672 function key's escape sequence, we replace the suffix with the
8673 function key's binding from Vfunction_key_map. Now keybuf
8674 contains a new and different key sequence, so the echo area,
8675 this_command_keys, and the submaps and defs arrays are wrong. In
8676 this situation, we set mock_input to t, set t to 0, and jump to
8677 restart_sequence; the loop will read keys from keybuf up until
8678 mock_input, thus rebuilding the state; and then it will resume
8679 reading characters from the keyboard. */
8680 volatile int mock_input
= 0;
8682 /* If the sequence is unbound in submaps[], then
8683 keybuf[fkey.start..fkey.end-1] is a prefix in Vfunction_key_map,
8684 and fkey.map is its binding.
8686 These might be > t, indicating that all function key scanning
8687 should hold off until t reaches them. We do this when we've just
8688 recognized a function key, to avoid searching for the function
8689 key's again in Vfunction_key_map. */
8690 volatile keyremap fkey
;
8692 /* Likewise, for key_translation_map. */
8693 volatile keyremap keytran
;
8695 /* If we receive a `switch-frame' or `select-window' event in the middle of
8696 a key sequence, we put it off for later.
8697 While we're reading, we keep the event here. */
8698 volatile Lisp_Object delayed_switch_frame
;
8700 /* See the comment below... */
8701 #if defined (GOBBLE_FIRST_EVENT)
8702 Lisp_Object first_event
;
8705 volatile Lisp_Object original_uppercase
;
8706 volatile int original_uppercase_position
= -1;
8708 /* Gets around Microsoft compiler limitations. */
8711 struct buffer
*starting_buffer
;
8713 /* List of events for which a fake prefix key has been generated. */
8714 volatile Lisp_Object fake_prefixed_keys
= Qnil
;
8716 #if defined (GOBBLE_FIRST_EVENT)
8720 struct gcpro gcpro1
;
8722 GCPRO1 (fake_prefixed_keys
);
8723 raw_keybuf_count
= 0;
8725 last_nonmenu_event
= Qnil
;
8727 delayed_switch_frame
= Qnil
;
8728 fkey
.map
= fkey
.parent
= Vfunction_key_map
;
8729 keytran
.map
= keytran
.parent
= Vkey_translation_map
;
8730 fkey
.start
= fkey
.end
= 0;
8731 keytran
.start
= keytran
.end
= 0;
8736 echo_prompt (prompt
);
8737 else if (cursor_in_echo_area
8738 && (FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
8739 && NILP (Fzerop (Vecho_keystrokes
)))
8740 /* This doesn't put in a dash if the echo buffer is empty, so
8741 you don't always see a dash hanging out in the minibuffer. */
8745 /* Record the initial state of the echo area and this_command_keys;
8746 we will need to restore them if we replay a key sequence. */
8748 echo_start
= echo_length ();
8749 keys_start
= this_command_key_count
;
8750 this_single_command_key_start
= keys_start
;
8752 #if defined (GOBBLE_FIRST_EVENT)
8753 /* This doesn't quite work, because some of the things that read_char
8754 does cannot safely be bypassed. It seems too risky to try to make
8757 /* Read the first char of the sequence specially, before setting
8758 up any keymaps, in case a filter runs and switches buffers on us. */
8759 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
8761 #endif /* GOBBLE_FIRST_EVENT */
8763 orig_local_map
= get_local_map (PT
, current_buffer
, Qlocal_map
);
8764 orig_keymap
= get_local_map (PT
, current_buffer
, Qkeymap
);
8767 /* We jump here when the key sequence has been thoroughly changed, and
8768 we need to rescan it starting from the beginning. When we jump here,
8769 keybuf[0..mock_input] holds the sequence we should reread. */
8772 starting_buffer
= current_buffer
;
8773 first_unbound
= bufsize
+ 1;
8775 /* Build our list of keymaps.
8776 If we recognize a function key and replace its escape sequence in
8777 keybuf with its symbol, or if the sequence starts with a mouse
8778 click and we need to switch buffers, we jump back here to rebuild
8779 the initial keymaps from the current buffer. */
8782 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
8784 if (2 > nmaps_allocated
)
8786 submaps
= (Lisp_Object
*) alloca (2 * sizeof (submaps
[0]));
8787 defs
= (Lisp_Object
*) alloca (2 * sizeof (defs
[0]));
8788 nmaps_allocated
= 2;
8790 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
8791 submaps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
8793 else if (!NILP (Voverriding_local_map
))
8795 if (2 > nmaps_allocated
)
8797 submaps
= (Lisp_Object
*) alloca (2 * sizeof (submaps
[0]));
8798 defs
= (Lisp_Object
*) alloca (2 * sizeof (defs
[0]));
8799 nmaps_allocated
= 2;
8801 if (!NILP (Voverriding_local_map
))
8802 submaps
[nmaps
++] = Voverriding_local_map
;
8810 nminor
= current_minor_maps (0, &maps
);
8811 total
= nminor
+ (!NILP (orig_keymap
) ? 3 : 2);
8813 if (total
> nmaps_allocated
)
8815 submaps
= (Lisp_Object
*) alloca (total
* sizeof (submaps
[0]));
8816 defs
= (Lisp_Object
*) alloca (total
* sizeof (defs
[0]));
8817 nmaps_allocated
= total
;
8820 if (!NILP (orig_keymap
))
8821 submaps
[nmaps
++] = orig_keymap
;
8823 bcopy (maps
, (void *) (submaps
+ nmaps
),
8824 nminor
* sizeof (submaps
[0]));
8828 submaps
[nmaps
++] = orig_local_map
;
8830 submaps
[nmaps
++] = current_global_map
;
8832 /* Find an accurate initial value for first_binding. */
8833 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
8834 if (! NILP (submaps
[first_binding
]))
8837 /* Start from the beginning in keybuf. */
8840 /* These are no-ops the first time through, but if we restart, they
8841 revert the echo area and this_command_keys to their original state. */
8842 this_command_key_count
= keys_start
;
8843 if (INTERACTIVE
&& t
< mock_input
)
8844 echo_truncate (echo_start
);
8846 /* If the best binding for the current key sequence is a keymap, or
8847 we may be looking at a function key's escape sequence, keep on
8849 while (first_binding
< nmaps
8850 /* Keep reading as long as there's a prefix binding. */
8851 ? !NILP (submaps
[first_binding
])
8852 /* Don't return in the middle of a possible function key sequence,
8853 if the only bindings we found were via case conversion.
8854 Thus, if ESC O a has a function-key-map translation
8855 and ESC o has a binding, don't return after ESC O,
8856 so that we can translate ESC O plus the next character. */
8857 : (fkey
.start
< t
|| keytran
.start
< t
))
8860 int used_mouse_menu
= 0;
8862 /* Where the last real key started. If we need to throw away a
8863 key that has expanded into more than one element of keybuf
8864 (say, a mouse click on the mode line which is being treated
8865 as [mode-line (mouse-...)], then we backtrack to this point
8867 volatile int last_real_key_start
;
8869 /* These variables are analogous to echo_start and keys_start;
8870 while those allow us to restart the entire key sequence,
8871 echo_local_start and keys_local_start allow us to throw away
8873 volatile int echo_local_start
, keys_local_start
, local_first_binding
;
8875 eassert (fkey
.end
== t
|| (fkey
.end
> t
&& fkey
.end
<= mock_input
));
8876 eassert (fkey
.start
<= fkey
.end
);
8877 eassert (keytran
.start
<= keytran
.end
);
8878 /* key-translation-map is applied *after* function-key-map. */
8879 eassert (keytran
.end
<= fkey
.start
);
8881 if (first_unbound
< fkey
.start
&& first_unbound
< keytran
.start
)
8882 { /* The prefix upto first_unbound has no binding and has
8883 no translation left to do either, so we know it's unbound.
8884 If we don't stop now, we risk staying here indefinitely
8885 (if the user keeps entering fkey or keytran prefixes
8886 like C-c ESC ESC ESC ESC ...) */
8888 for (i
= first_unbound
+ 1; i
< t
; i
++)
8889 keybuf
[i
- first_unbound
- 1] = keybuf
[i
];
8890 mock_input
= t
- first_unbound
- 1;
8891 fkey
.end
= fkey
.start
-= first_unbound
+ 1;
8892 fkey
.map
= fkey
.parent
;
8893 keytran
.end
= keytran
.start
-= first_unbound
+ 1;
8894 keytran
.map
= keytran
.parent
;
8895 goto replay_sequence
;
8899 error ("Key sequence too long");
8902 echo_local_start
= echo_length ();
8903 keys_local_start
= this_command_key_count
;
8904 local_first_binding
= first_binding
;
8907 /* These are no-ops, unless we throw away a keystroke below and
8908 jumped back up to replay_key; in that case, these restore the
8909 variables to their original state, allowing us to replay the
8911 if (INTERACTIVE
&& t
< mock_input
)
8912 echo_truncate (echo_local_start
);
8913 this_command_key_count
= keys_local_start
;
8914 first_binding
= local_first_binding
;
8916 /* By default, assume each event is "real". */
8917 last_real_key_start
= t
;
8919 /* Does mock_input indicate that we are re-reading a key sequence? */
8923 add_command_key (key
);
8924 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
8925 && NILP (Fzerop (Vecho_keystrokes
)))
8929 /* If not, we should actually read a character. */
8934 KBOARD
*interrupted_kboard
= current_kboard
;
8935 struct frame
*interrupted_frame
= SELECTED_FRAME ();
8936 if (setjmp (wrong_kboard_jmpbuf
))
8938 if (!NILP (delayed_switch_frame
))
8940 interrupted_kboard
->kbd_queue
8941 = Fcons (delayed_switch_frame
,
8942 interrupted_kboard
->kbd_queue
);
8943 delayed_switch_frame
= Qnil
;
8946 interrupted_kboard
->kbd_queue
8947 = Fcons (keybuf
[--t
], interrupted_kboard
->kbd_queue
);
8949 /* If the side queue is non-empty, ensure it begins with a
8950 switch-frame, so we'll replay it in the right context. */
8951 if (CONSP (interrupted_kboard
->kbd_queue
)
8952 && (key
= XCAR (interrupted_kboard
->kbd_queue
),
8953 !(EVENT_HAS_PARAMETERS (key
)
8954 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)),
8958 XSETFRAME (frame
, interrupted_frame
);
8959 interrupted_kboard
->kbd_queue
8960 = Fcons (make_lispy_switch_frame (frame
),
8961 interrupted_kboard
->kbd_queue
);
8964 orig_local_map
= get_local_map (PT
, current_buffer
, Qlocal_map
);
8965 orig_keymap
= get_local_map (PT
, current_buffer
, Qkeymap
);
8966 goto replay_sequence
;
8969 key
= read_char (NILP (prompt
), nmaps
,
8970 (Lisp_Object
*) submaps
, last_nonmenu_event
,
8971 &used_mouse_menu
, NULL
);
8974 /* read_char returns t when it shows a menu and the user rejects it.
8978 unbind_to (count
, Qnil
);
8983 /* read_char returns -1 at the end of a macro.
8984 Emacs 18 handles this by returning immediately with a
8985 zero, so that's what we'll do. */
8986 if (INTEGERP (key
) && XINT (key
) == -1)
8989 /* The Microsoft C compiler can't handle the goto that
8995 /* If the current buffer has been changed from under us, the
8996 keymap may have changed, so replay the sequence. */
8999 timer_resume_idle ();
9002 /* Reset the current buffer from the selected window
9003 in case something changed the former and not the latter.
9004 This is to be more consistent with the behavior
9005 of the command_loop_1. */
9006 if (fix_current_buffer
)
9008 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
9010 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
9011 Fset_buffer (XWINDOW (selected_window
)->buffer
);
9014 orig_local_map
= get_local_map (PT
, current_buffer
, Qlocal_map
);
9015 orig_keymap
= get_local_map (PT
, current_buffer
, Qkeymap
);
9016 goto replay_sequence
;
9019 /* If we have a quit that was typed in another frame, and
9020 quit_throw_to_read_char switched buffers,
9021 replay to get the right keymap. */
9023 && XINT (key
) == quit_char
9024 && current_buffer
!= starting_buffer
)
9027 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
9031 orig_local_map
= get_local_map (PT
, current_buffer
, Qlocal_map
);
9032 orig_keymap
= get_local_map (PT
, current_buffer
, Qkeymap
);
9033 goto replay_sequence
;
9038 if (EVENT_HAS_PARAMETERS (key
)
9039 /* Either a `switch-frame' or a `select-window' event. */
9040 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)), Qswitch_frame
))
9042 /* If we're at the beginning of a key sequence, and the caller
9043 says it's okay, go ahead and return this event. If we're
9044 in the midst of a key sequence, delay it until the end. */
9045 if (t
> 0 || !can_return_switch_frame
)
9047 delayed_switch_frame
= key
;
9053 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
9056 /* Clicks in non-text areas get prefixed by the symbol
9057 in their CHAR-ADDRESS field. For example, a click on
9058 the mode line is prefixed by the symbol `mode-line'.
9060 Furthermore, key sequences beginning with mouse clicks
9061 are read using the keymaps of the buffer clicked on, not
9062 the current buffer. So we may have to switch the buffer
9065 When we turn one event into two events, we must make sure
9066 that neither of the two looks like the original--so that,
9067 if we replay the events, they won't be expanded again.
9068 If not for this, such reexpansion could happen either here
9069 or when user programs play with this-command-keys. */
9070 if (EVENT_HAS_PARAMETERS (key
))
9075 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
9076 if (EQ (kind
, Qmouse_click
))
9078 Lisp_Object window
, posn
;
9080 window
= POSN_WINDOW (EVENT_START (key
));
9081 posn
= POSN_POSN (EVENT_START (key
));
9084 || (!NILP (fake_prefixed_keys
)
9085 && !NILP (Fmemq (key
, fake_prefixed_keys
))))
9087 /* We're looking a second time at an event for which
9088 we generated a fake prefix key. Set
9089 last_real_key_start appropriately. */
9091 last_real_key_start
= t
- 1;
9094 /* Key sequences beginning with mouse clicks are
9095 read using the keymaps in the buffer clicked on,
9096 not the current buffer. If we're at the
9097 beginning of a key sequence, switch buffers. */
9098 if (last_real_key_start
== 0
9100 && BUFFERP (XWINDOW (window
)->buffer
)
9101 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
9103 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
9107 /* Arrange to go back to the original buffer once we're
9108 done reading the key sequence. Note that we can't
9109 use save_excursion_{save,restore} here, because they
9110 save point as well as the current buffer; we don't
9111 want to save point, because redisplay may change it,
9112 to accommodate a Fset_window_start or something. We
9113 don't want to do this at the top of the function,
9114 because we may get input from a subprocess which
9115 wants to change the selected window and stuff (say,
9117 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
9119 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
9121 set_buffer_internal (XBUFFER (XWINDOW (window
)->buffer
));
9122 orig_local_map
= get_local_map (PT
, current_buffer
,
9124 orig_keymap
= get_local_map (PT
, current_buffer
, Qkeymap
);
9125 goto replay_sequence
;
9128 /* For a mouse click, get the local text-property keymap
9129 of the place clicked on, rather than point. */
9130 if (last_real_key_start
== 0
9131 && CONSP (XCDR (key
))
9132 && ! localized_local_map
)
9134 Lisp_Object map_here
, start
, pos
;
9136 localized_local_map
= 1;
9137 start
= EVENT_START (key
);
9139 if (CONSP (start
) && POSN_INBUFFER_P (start
))
9141 pos
= POSN_BUFFER_POSN (start
);
9143 && XINT (pos
) >= BEG
&& XINT (pos
) <= Z
)
9145 map_here
= get_local_map (XINT (pos
),
9146 current_buffer
, Qlocal_map
);
9147 if (!EQ (map_here
, orig_local_map
))
9149 orig_local_map
= map_here
;
9150 ++localized_local_map
;
9153 map_here
= get_local_map (XINT (pos
),
9154 current_buffer
, Qkeymap
);
9155 if (!EQ (map_here
, orig_keymap
))
9157 orig_keymap
= map_here
;
9158 ++localized_local_map
;
9161 if (localized_local_map
> 1)
9166 goto replay_sequence
;
9172 /* Expand mode-line and scroll-bar events into two events:
9173 use posn as a fake prefix key. */
9175 && (NILP (fake_prefixed_keys
)
9176 || NILP (Fmemq (key
, fake_prefixed_keys
))))
9178 if (t
+ 1 >= bufsize
)
9179 error ("Key sequence too long");
9182 keybuf
[t
+ 1] = key
;
9185 /* Record that a fake prefix key has been generated
9186 for KEY. Don't modify the event; this would
9187 prevent proper action when the event is pushed
9188 back into unread-command-events. */
9189 fake_prefixed_keys
= Fcons (key
, fake_prefixed_keys
);
9191 /* If on a mode line string with a local keymap,
9192 reconsider the key sequence with that keymap. */
9193 if (string
= POSN_STRING (EVENT_START (key
)),
9194 (CONSP (string
) && STRINGP (XCAR (string
))))
9196 Lisp_Object pos
, map
, map2
;
9198 pos
= XCDR (string
);
9199 string
= XCAR (string
);
9201 && XINT (pos
) < SCHARS (string
))
9203 map
= Fget_text_property (pos
, Qlocal_map
, string
);
9205 orig_local_map
= map
;
9206 map2
= Fget_text_property (pos
, Qkeymap
, string
);
9209 if (!NILP (map
) || !NILP (map2
))
9210 goto replay_sequence
;
9216 else if (NILP (from_string
)
9217 && (string
= POSN_STRING (EVENT_START (key
)),
9218 (CONSP (string
) && STRINGP (XCAR (string
)))))
9220 /* For a click on a string, i.e. overlay string or a
9221 string displayed via the `display' property,
9222 consider `local-map' and `keymap' properties of
9224 Lisp_Object pos
, map
, map2
;
9226 pos
= XCDR (string
);
9227 string
= XCAR (string
);
9229 && XINT (pos
) < SCHARS (string
))
9231 map
= Fget_text_property (pos
, Qlocal_map
, string
);
9233 orig_local_map
= map
;
9234 map2
= Fget_text_property (pos
, Qkeymap
, string
);
9238 if (!NILP (map
) || !NILP (map2
))
9240 from_string
= string
;
9241 goto replay_sequence
;
9246 else if (CONSP (XCDR (key
))
9247 && CONSP (EVENT_START (key
))
9248 && CONSP (XCDR (EVENT_START (key
))))
9252 posn
= POSN_POSN (EVENT_START (key
));
9253 /* Handle menu-bar events:
9254 insert the dummy prefix event `menu-bar'. */
9255 if (EQ (posn
, Qmenu_bar
) || EQ (posn
, Qtool_bar
))
9257 if (t
+ 1 >= bufsize
)
9258 error ("Key sequence too long");
9262 /* Zap the position in key, so we know that we've
9263 expanded it, and don't try to do so again. */
9264 POSN_SET_POSN (EVENT_START (key
),
9265 Fcons (posn
, Qnil
));
9268 goto replay_sequence
;
9270 else if (CONSP (posn
))
9272 /* We're looking at the second event of a
9273 sequence which we expanded before. Set
9274 last_real_key_start appropriately. */
9275 if (last_real_key_start
== t
&& t
> 0)
9276 last_real_key_start
= t
- 1;
9281 /* We have finally decided that KEY is something we might want
9283 first_binding
= (follow_key (key
,
9284 nmaps
- first_binding
,
9285 submaps
+ first_binding
,
9286 defs
+ first_binding
,
9287 submaps
+ first_binding
)
9290 /* If KEY wasn't bound, we'll try some fallbacks. */
9291 if (first_binding
< nmaps
)
9292 /* This is needed for the following scenario:
9293 event 0: a down-event that gets dropped by calling replay_key.
9294 event 1: some normal prefix like C-h.
9295 After event 0, first_unbound is 0, after event 1 fkey.start
9296 and keytran.start are both 1, so when we see that C-h is bound,
9297 we need to update first_unbound. */
9298 first_unbound
= max (t
+ 1, first_unbound
);
9303 /* Remember the position to put an upper bound on fkey.start. */
9304 first_unbound
= min (t
, first_unbound
);
9306 head
= EVENT_HEAD (key
);
9307 if (help_char_p (head
) && t
> 0)
9309 read_key_sequence_cmd
= Vprefix_help_command
;
9311 last_nonmenu_event
= key
;
9312 /* The Microsoft C compiler can't handle the goto that
9320 Lisp_Object breakdown
;
9323 breakdown
= parse_modifiers (head
);
9324 modifiers
= XINT (XCAR (XCDR (breakdown
)));
9325 /* Attempt to reduce an unbound mouse event to a simpler
9326 event that is bound:
9327 Drags reduce to clicks.
9328 Double-clicks reduce to clicks.
9329 Triple-clicks reduce to double-clicks, then to clicks.
9330 Down-clicks are eliminated.
9331 Double-downs reduce to downs, then are eliminated.
9332 Triple-downs reduce to double-downs, then to downs,
9333 then are eliminated. */
9334 if (modifiers
& (down_modifier
| drag_modifier
9335 | double_modifier
| triple_modifier
))
9337 while (modifiers
& (down_modifier
| drag_modifier
9338 | double_modifier
| triple_modifier
))
9340 Lisp_Object new_head
, new_click
;
9341 if (modifiers
& triple_modifier
)
9342 modifiers
^= (double_modifier
| triple_modifier
);
9343 else if (modifiers
& double_modifier
)
9344 modifiers
&= ~double_modifier
;
9345 else if (modifiers
& drag_modifier
)
9346 modifiers
&= ~drag_modifier
;
9349 /* Dispose of this `down' event by simply jumping
9350 back to replay_key, to get another event.
9352 Note that if this event came from mock input,
9353 then just jumping back to replay_key will just
9354 hand it to us again. So we have to wipe out any
9357 We could delete keybuf[t] and shift everything
9358 after that to the left by one spot, but we'd also
9359 have to fix up any variable that points into
9360 keybuf, and shifting isn't really necessary
9363 Adding prefixes for non-textual mouse clicks
9364 creates two characters of mock input, and both
9365 must be thrown away. If we're only looking at
9366 the prefix now, we can just jump back to
9367 replay_key. On the other hand, if we've already
9368 processed the prefix, and now the actual click
9369 itself is giving us trouble, then we've lost the
9370 state of the keymaps we want to backtrack to, and
9371 we need to replay the whole sequence to rebuild
9374 Beyond that, only function key expansion could
9375 create more than two keys, but that should never
9376 generate mouse events, so it's okay to zero
9377 mock_input in that case too.
9379 FIXME: The above paragraph seems just plain
9380 wrong, if you consider things like
9381 xterm-mouse-mode. -stef
9383 Isn't this just the most wonderful code ever? */
9385 /* If mock_input > t + 1, the above simplification
9386 will actually end up dropping keys on the floor.
9387 This is probably OK for now, but even
9388 if mock_input <= t + 1, we need to adjust fkey
9390 Typical case [header-line down-mouse-N]:
9391 mock_input = 2, t = 1, fkey.end = 1,
9392 last_real_key_start = 0. */
9393 if (fkey
.end
> last_real_key_start
)
9395 fkey
.end
= fkey
.start
9396 = min (last_real_key_start
, fkey
.start
);
9397 fkey
.map
= fkey
.parent
;
9398 if (keytran
.end
> last_real_key_start
)
9400 keytran
.end
= keytran
.start
9401 = min (last_real_key_start
, keytran
.start
);
9402 keytran
.map
= keytran
.parent
;
9405 if (t
== last_real_key_start
)
9412 mock_input
= last_real_key_start
;
9413 goto replay_sequence
;
9418 = apply_modifiers (modifiers
, XCAR (breakdown
));
9420 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
9422 /* Look for a binding for this new key. follow_key
9423 promises that it didn't munge submaps the
9424 last time we called it, since key was unbound. */
9426 = (follow_key (new_click
,
9427 nmaps
- local_first_binding
,
9428 submaps
+ local_first_binding
,
9429 defs
+ local_first_binding
,
9430 submaps
+ local_first_binding
)
9431 + local_first_binding
);
9433 /* If that click is bound, go for it. */
9434 if (first_binding
< nmaps
)
9439 /* Otherwise, we'll leave key set to the drag event. */
9446 /* Normally, last_nonmenu_event gets the previous key we read.
9447 But when a mouse popup menu is being used,
9448 we don't update last_nonmenu_event; it continues to hold the mouse
9449 event that preceded the first level of menu. */
9450 if (!used_mouse_menu
)
9451 last_nonmenu_event
= key
;
9453 /* Record what part of this_command_keys is the current key sequence. */
9454 this_single_command_key_start
= this_command_key_count
- t
;
9456 if (first_binding
< nmaps
&& NILP (submaps
[first_binding
]))
9457 /* There is a binding and it's not a prefix.
9458 There is thus no function-key in this sequence.
9459 Moving fkey.start is important in this case to allow keytran.start
9460 to go over the sequence before we return (since we keep the
9461 invariant that keytran.end <= fkey.start). */
9464 (fkey
.start
= fkey
.end
= t
, fkey
.map
= fkey
.parent
);
9467 /* If the sequence is unbound, see if we can hang a function key
9468 off the end of it. */
9469 /* Continue scan from fkey.end until we find a bound suffix. */
9470 while (fkey
.end
< t
)
9472 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9475 GCPRO3 (fkey
.map
, keytran
.map
, delayed_switch_frame
);
9476 done
= keyremap_step (keybuf
, bufsize
, &fkey
,
9477 max (t
, mock_input
),
9478 /* If there's a binding (i.e.
9479 first_binding >= nmaps) we don't want
9480 to apply this function-key-mapping. */
9481 fkey
.end
+ 1 == t
&& first_binding
>= nmaps
,
9486 mock_input
= diff
+ max (t
, mock_input
);
9487 goto replay_sequence
;
9491 /* Look for this sequence in key-translation-map.
9492 Scan from keytran.end until we find a bound suffix. */
9493 while (keytran
.end
< fkey
.start
)
9495 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9498 GCPRO3 (fkey
.map
, keytran
.map
, delayed_switch_frame
);
9499 done
= keyremap_step (keybuf
, bufsize
, &keytran
, max (t
, mock_input
),
9504 mock_input
= diff
+ max (t
, mock_input
);
9505 /* Adjust the function-key-map counters. */
9509 goto replay_sequence
;
9513 /* If KEY is not defined in any of the keymaps,
9514 and cannot be part of a function key or translation,
9515 and is an upper case letter
9516 use the corresponding lower-case letter instead. */
9517 if (first_binding
>= nmaps
9518 && fkey
.start
>= t
&& keytran
.start
>= t
9520 && ((((XINT (key
) & 0x3ffff)
9521 < XCHAR_TABLE (current_buffer
->downcase_table
)->size
)
9522 && UPPERCASEP (XINT (key
) & 0x3ffff))
9523 || (XINT (key
) & shift_modifier
)))
9525 Lisp_Object new_key
;
9527 original_uppercase
= key
;
9528 original_uppercase_position
= t
- 1;
9530 if (XINT (key
) & shift_modifier
)
9531 XSETINT (new_key
, XINT (key
) & ~shift_modifier
);
9533 XSETINT (new_key
, (DOWNCASE (XINT (key
) & 0x3ffff)
9534 | (XINT (key
) & ~0x3ffff)));
9536 /* We have to do this unconditionally, regardless of whether
9537 the lower-case char is defined in the keymaps, because they
9538 might get translated through function-key-map. */
9539 keybuf
[t
- 1] = new_key
;
9540 mock_input
= max (t
, mock_input
);
9542 goto replay_sequence
;
9544 /* If KEY is not defined in any of the keymaps,
9545 and cannot be part of a function key or translation,
9546 and is a shifted function key,
9547 use the corresponding unshifted function key instead. */
9548 if (first_binding
>= nmaps
9549 && fkey
.start
>= t
&& keytran
.start
>= t
9552 Lisp_Object breakdown
;
9555 breakdown
= parse_modifiers (key
);
9556 modifiers
= XINT (XCAR (XCDR (breakdown
)));
9557 if (modifiers
& shift_modifier
)
9559 Lisp_Object new_key
;
9561 original_uppercase
= key
;
9562 original_uppercase_position
= t
- 1;
9564 modifiers
&= ~shift_modifier
;
9565 new_key
= apply_modifiers (modifiers
,
9568 keybuf
[t
- 1] = new_key
;
9569 mock_input
= max (t
, mock_input
);
9570 fkey
.start
= fkey
.end
= 0;
9571 keytran
.start
= keytran
.end
= 0;
9573 goto replay_sequence
;
9579 read_key_sequence_cmd
= (first_binding
< nmaps
9580 ? defs
[first_binding
]
9583 unread_switch_frame
= delayed_switch_frame
;
9584 unbind_to (count
, Qnil
);
9586 /* Don't downcase the last character if the caller says don't.
9587 Don't downcase it if the result is undefined, either. */
9588 if ((dont_downcase_last
|| first_binding
>= nmaps
)
9590 && t
- 1 == original_uppercase_position
)
9591 keybuf
[t
- 1] = original_uppercase
;
9593 /* Occasionally we fabricate events, perhaps by expanding something
9594 according to function-key-map, or by adding a prefix symbol to a
9595 mouse click in the scroll bar or modeline. In this cases, return
9596 the entire generated key sequence, even if we hit an unbound
9597 prefix or a definition before the end. This means that you will
9598 be able to push back the event properly, and also means that
9599 read-key-sequence will always return a logical unit.
9602 for (; t
< mock_input
; t
++)
9604 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
9605 && NILP (Fzerop (Vecho_keystrokes
)))
9606 echo_char (keybuf
[t
]);
9607 add_command_key (keybuf
[t
]);
9616 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 5, 0,
9617 doc
: /* Read a sequence of keystrokes and return as a string or vector.
9618 The sequence is sufficient to specify a non-prefix command in the
9619 current local and global maps.
9621 First arg PROMPT is a prompt string. If nil, do not prompt specially.
9622 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos
9623 as a continuation of the previous key.
9625 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not
9626 convert the last event to lower case. (Normally any upper case event
9627 is converted to lower case if the original event is undefined and the lower
9628 case equivalent is defined.) A non-nil value is appropriate for reading
9629 a key sequence to be defined.
9631 A C-g typed while in this function is treated like any other character,
9632 and `quit-flag' is not set.
9634 If the key sequence starts with a mouse click, then the sequence is read
9635 using the keymaps of the buffer of the window clicked in, not the buffer
9636 of the selected window as normal.
9638 `read-key-sequence' drops unbound button-down events, since you normally
9639 only care about the click or drag events which follow them. If a drag
9640 or multi-click event is unbound, but the corresponding click event would
9641 be bound, `read-key-sequence' turns the event into a click event at the
9642 drag's starting position. This means that you don't have to distinguish
9643 between click and drag, double, or triple events unless you want to.
9645 `read-key-sequence' prefixes mouse events on mode lines, the vertical
9646 lines separating windows, and scroll bars with imaginary keys
9647 `mode-line', `vertical-line', and `vertical-scroll-bar'.
9649 Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this
9650 function will process a switch-frame event if the user switches frames
9651 before typing anything. If the user switches frames in the middle of a
9652 key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME
9653 is nil, then the event will be put off until after the current key sequence.
9655 `read-key-sequence' checks `function-key-map' for function key
9656 sequences, where they wouldn't conflict with ordinary bindings. See
9657 `function-key-map' for more details.
9659 The optional fifth argument COMMAND-LOOP, if non-nil, means
9660 that this key sequence is being read by something that will
9661 read commands one after another. It should be nil if the caller
9662 will read just one key sequence. */)
9663 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
9665 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
9666 Lisp_Object can_return_switch_frame
, command_loop
;
9668 Lisp_Object keybuf
[30];
9670 struct gcpro gcpro1
;
9671 int count
= SPECPDL_INDEX ();
9674 CHECK_STRING (prompt
);
9677 specbind (Qinput_method_exit_on_first_char
,
9678 (NILP (command_loop
) ? Qt
: Qnil
));
9679 specbind (Qinput_method_use_echo_area
,
9680 (NILP (command_loop
) ? Qt
: Qnil
));
9682 bzero (keybuf
, sizeof keybuf
);
9684 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
9686 if (NILP (continue_echo
))
9688 this_command_key_count
= 0;
9689 this_command_key_count_reset
= 0;
9690 this_single_command_key_start
= 0;
9693 #ifdef HAVE_X_WINDOWS
9694 if (display_hourglass_p
)
9695 cancel_hourglass ();
9698 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
9699 prompt
, ! NILP (dont_downcase_last
),
9700 ! NILP (can_return_switch_frame
), 0);
9702 #if 0 /* The following is fine for code reading a key sequence and
9703 then proceeding with a lenghty computation, but it's not good
9704 for code reading keys in a loop, like an input method. */
9705 #ifdef HAVE_X_WINDOWS
9706 if (display_hourglass_p
)
9717 return unbind_to (count
, make_event_array (i
, keybuf
));
9720 DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector
,
9721 Sread_key_sequence_vector
, 1, 5, 0,
9722 doc
: /* Like `read-key-sequence' but always return a vector. */)
9723 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
9725 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
9726 Lisp_Object can_return_switch_frame
, command_loop
;
9728 Lisp_Object keybuf
[30];
9730 struct gcpro gcpro1
;
9731 int count
= SPECPDL_INDEX ();
9734 CHECK_STRING (prompt
);
9737 specbind (Qinput_method_exit_on_first_char
,
9738 (NILP (command_loop
) ? Qt
: Qnil
));
9739 specbind (Qinput_method_use_echo_area
,
9740 (NILP (command_loop
) ? Qt
: Qnil
));
9742 bzero (keybuf
, sizeof keybuf
);
9744 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
9746 if (NILP (continue_echo
))
9748 this_command_key_count
= 0;
9749 this_command_key_count_reset
= 0;
9750 this_single_command_key_start
= 0;
9753 #ifdef HAVE_X_WINDOWS
9754 if (display_hourglass_p
)
9755 cancel_hourglass ();
9758 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
9759 prompt
, ! NILP (dont_downcase_last
),
9760 ! NILP (can_return_switch_frame
), 0);
9762 #ifdef HAVE_X_WINDOWS
9763 if (display_hourglass_p
)
9773 return unbind_to (count
, Fvector (i
, keybuf
));
9776 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 4, 0,
9777 doc
: /* Execute CMD as an editor command.
9778 CMD must be a symbol that satisfies the `commandp' predicate.
9779 Optional second arg RECORD-FLAG non-nil
9780 means unconditionally put this command in `command-history'.
9781 Otherwise, that is done only if an arg is read using the minibuffer.
9782 The argument KEYS specifies the value to use instead of (this-command-keys)
9783 when reading the arguments; if it is nil, (this-command-keys) is used.
9784 The argument SPECIAL, if non-nil, means that this command is executing
9785 a special event, so ignore the prefix argument and don't clear it. */)
9786 (cmd
, record_flag
, keys
, special
)
9787 Lisp_Object cmd
, record_flag
, keys
, special
;
9789 register Lisp_Object final
;
9790 register Lisp_Object tem
;
9791 Lisp_Object prefixarg
;
9792 struct backtrace backtrace
;
9793 extern int debug_on_next_call
;
9795 debug_on_next_call
= 0;
9799 prefixarg
= current_kboard
->Vprefix_arg
;
9800 Vcurrent_prefix_arg
= prefixarg
;
9801 current_kboard
->Vprefix_arg
= Qnil
;
9808 tem
= Fget (cmd
, Qdisabled
);
9809 if (!NILP (tem
) && !NILP (Vrun_hooks
))
9811 tem
= Fsymbol_value (Qdisabled_command_function
);
9813 return call1 (Vrun_hooks
, Qdisabled_command_function
);
9819 final
= Findirect_function (cmd
, Qnil
);
9821 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
9823 struct gcpro gcpro1
, gcpro2
;
9825 GCPRO2 (cmd
, prefixarg
);
9826 do_autoload (final
, cmd
);
9833 if (STRINGP (final
) || VECTORP (final
))
9835 /* If requested, place the macro in the command history. For
9836 other sorts of commands, call-interactively takes care of
9838 if (!NILP (record_flag
))
9841 = Fcons (Fcons (Qexecute_kbd_macro
,
9842 Fcons (final
, Fcons (prefixarg
, Qnil
))),
9845 /* Don't keep command history around forever. */
9846 if (NUMBERP (Vhistory_length
) && XINT (Vhistory_length
) > 0)
9848 tem
= Fnthcdr (Vhistory_length
, Vcommand_history
);
9850 XSETCDR (tem
, Qnil
);
9854 return Fexecute_kbd_macro (final
, prefixarg
, Qnil
);
9857 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
9859 backtrace
.next
= backtrace_list
;
9860 backtrace_list
= &backtrace
;
9861 backtrace
.function
= &Qcall_interactively
;
9862 backtrace
.args
= &cmd
;
9863 backtrace
.nargs
= 1;
9864 backtrace
.evalargs
= 0;
9865 backtrace
.debug_on_exit
= 0;
9867 tem
= Fcall_interactively (cmd
, record_flag
, keys
);
9869 backtrace_list
= backtrace
.next
;
9877 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
9879 doc
: /* Read function name, then read its arguments and call it.
9881 To pass a numeric argument to the command you are invoking with, specify
9882 the numeric argument to this command.
9884 Noninteractively, the argument PREFIXARG is the prefix argument to
9885 give to the command you invoke, if it asks for an argument. */)
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. */
9993 /* If this command displayed something in the echo area;
9994 wait a few seconds, then display our suggestion message. */
9995 if (NILP (echo_area_buffer
[0]))
9996 waited
= sit_for (make_number (0), 0, 2);
9997 else if (NUMBERP (Vsuggest_key_bindings
))
9998 waited
= sit_for (Vsuggest_key_bindings
, 0, 2);
10000 waited
= sit_for (make_number (2), 0, 2);
10002 if (!NILP (waited
) && ! CONSP (Vunread_command_events
))
10004 Lisp_Object binding
;
10006 int message_p
= push_message ();
10007 int count
= SPECPDL_INDEX ();
10009 record_unwind_protect (pop_message_unwind
, Qnil
);
10010 binding
= Fkey_description (bindings
, Qnil
);
10013 = (char *) alloca (SCHARS (SYMBOL_NAME (function
))
10016 sprintf (newmessage
, "You can run the command `%s' with %s",
10017 SDATA (SYMBOL_NAME (function
)),
10019 message2_nolog (newmessage
,
10020 strlen (newmessage
),
10021 STRING_MULTIBYTE (binding
));
10022 if (NUMBERP (Vsuggest_key_bindings
))
10023 waited
= sit_for (Vsuggest_key_bindings
, 0, 2);
10025 waited
= sit_for (make_number (2), 0, 2);
10027 if (!NILP (waited
) && message_p
)
10028 restore_message ();
10030 unbind_to (count
, Qnil
);
10034 RETURN_UNGCPRO (value
);
10038 /* Return nonzero if input events are pending. */
10041 detect_input_pending ()
10043 if (!input_pending
)
10044 get_input_pending (&input_pending
, 0);
10046 return input_pending
;
10049 /* Return nonzero if input events other than mouse movements are
10053 detect_input_pending_ignore_squeezables ()
10055 if (!input_pending
)
10056 get_input_pending (&input_pending
, READABLE_EVENTS_IGNORE_SQUEEZABLES
);
10058 return input_pending
;
10061 /* Return nonzero if input events are pending, and run any pending timers. */
10064 detect_input_pending_run_timers (do_display
)
10067 int old_timers_run
= timers_run
;
10069 if (!input_pending
)
10070 get_input_pending (&input_pending
, READABLE_EVENTS_DO_TIMERS_NOW
);
10072 if (old_timers_run
!= timers_run
&& do_display
)
10074 redisplay_preserve_echo_area (8);
10075 /* The following fixes a bug when using lazy-lock with
10076 lazy-lock-defer-on-the-fly set to t, i.e. when fontifying
10077 from an idle timer function. The symptom of the bug is that
10078 the cursor sometimes doesn't become visible until the next X
10079 event is processed. --gerd. */
10081 rif
->flush_display (NULL
);
10084 return input_pending
;
10087 /* This is called in some cases before a possible quit.
10088 It cases the next call to detect_input_pending to recompute input_pending.
10089 So calling this function unnecessarily can't do any harm. */
10092 clear_input_pending ()
10097 /* Return nonzero if there are pending requeued events.
10098 This isn't used yet. The hope is to make wait_reading_process_output
10099 call it, and return if it runs Lisp code that unreads something.
10100 The problem is, kbd_buffer_get_event needs to be fixed to know what
10101 to do in that case. It isn't trivial. */
10104 requeued_events_pending_p ()
10106 return (!NILP (Vunread_command_events
) || unread_command_char
!= -1);
10110 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
10111 doc
: /* Return t if command input is currently available with no wait.
10112 Actually, the value is nil only if we can be sure that no input is available;
10113 if there is a doubt, the value is t. */)
10116 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1
10117 || !NILP (Vunread_post_input_method_events
)
10118 || !NILP (Vunread_input_method_events
))
10121 get_input_pending (&input_pending
,
10122 READABLE_EVENTS_DO_TIMERS_NOW
10123 | READABLE_EVENTS_FILTER_EVENTS
);
10124 return input_pending
> 0 ? Qt
: Qnil
;
10127 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
10128 doc
: /* Return vector of last 100 events, not counting those from keyboard macros. */)
10131 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
10134 if (total_keys
< NUM_RECENT_KEYS
)
10135 return Fvector (total_keys
, keys
);
10138 val
= Fvector (NUM_RECENT_KEYS
, keys
);
10139 bcopy (keys
+ recent_keys_index
,
10140 XVECTOR (val
)->contents
,
10141 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
10143 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
10144 recent_keys_index
* sizeof (Lisp_Object
));
10149 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
10150 doc
: /* Return the key sequence that invoked this command.
10151 However, if the command has called `read-key-sequence', it returns
10152 the last key sequence that has been read.
10153 The value is a string or a vector. */)
10156 return make_event_array (this_command_key_count
,
10157 XVECTOR (this_command_keys
)->contents
);
10160 DEFUN ("this-command-keys-vector", Fthis_command_keys_vector
, Sthis_command_keys_vector
, 0, 0, 0,
10161 doc
: /* Return the key sequence that invoked this command, as a vector.
10162 However, if the command has called `read-key-sequence', it returns
10163 the last key sequence that has been read. */)
10166 return Fvector (this_command_key_count
,
10167 XVECTOR (this_command_keys
)->contents
);
10170 DEFUN ("this-single-command-keys", Fthis_single_command_keys
,
10171 Sthis_single_command_keys
, 0, 0, 0,
10172 doc
: /* Return the key sequence that invoked this command.
10173 More generally, it returns the last key sequence read, either by
10174 the command loop or by `read-key-sequence'.
10175 Unlike `this-command-keys', this function's value
10176 does not include prefix arguments.
10177 The value is always a vector. */)
10180 return Fvector (this_command_key_count
10181 - this_single_command_key_start
,
10182 (XVECTOR (this_command_keys
)->contents
10183 + this_single_command_key_start
));
10186 DEFUN ("this-single-command-raw-keys", Fthis_single_command_raw_keys
,
10187 Sthis_single_command_raw_keys
, 0, 0, 0,
10188 doc
: /* Return the raw events that were read for this command.
10189 More generally, it returns the last key sequence read, either by
10190 the command loop or by `read-key-sequence'.
10191 Unlike `this-single-command-keys', this function's value
10192 shows the events before all translations (except for input methods).
10193 The value is always a vector. */)
10196 return Fvector (raw_keybuf_count
,
10197 (XVECTOR (raw_keybuf
)->contents
));
10200 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths
,
10201 Sreset_this_command_lengths
, 0, 0, 0,
10202 doc
: /* Make the unread events replace the last command and echo.
10203 Used in `universal-argument-other-key'.
10205 `universal-argument-other-key' rereads the event just typed.
10206 It then gets translated through `function-key-map'.
10207 The translated event has to replace the real events,
10208 both in the value of (this-command-keys) and in echoing.
10209 To achieve this, `universal-argument-other-key' calls
10210 `reset-this-command-lengths', which discards the record of reading
10211 these events the first time. */)
10214 this_command_key_count
= before_command_key_count
;
10215 if (this_command_key_count
< this_single_command_key_start
)
10216 this_single_command_key_start
= this_command_key_count
;
10218 echo_truncate (before_command_echo_length
);
10220 /* Cause whatever we put into unread-command-events
10221 to echo as if it were being freshly read from the keyboard. */
10222 this_command_key_count_reset
= 1;
10227 DEFUN ("clear-this-command-keys", Fclear_this_command_keys
,
10228 Sclear_this_command_keys
, 0, 1, 0,
10229 doc
: /* Clear out the vector that `this-command-keys' returns.
10230 Also clear the record of the last 100 events, unless optional arg
10231 KEEP-RECORD is non-nil. */)
10233 Lisp_Object keep_record
;
10237 this_command_key_count
= 0;
10238 this_command_key_count_reset
= 0;
10240 if (NILP (keep_record
))
10242 for (i
= 0; i
< XVECTOR (recent_keys
)->size
; ++i
)
10243 XVECTOR (recent_keys
)->contents
[i
] = Qnil
;
10245 recent_keys_index
= 0;
10250 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
10251 doc
: /* Return the current depth in recursive edits. */)
10255 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
10259 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
10260 "FOpen dribble file: ",
10261 doc
: /* Start writing all keyboard characters to a dribble file called FILE.
10262 If FILE is nil, close any open dribble file. */)
10273 file
= Fexpand_file_name (file
, Qnil
);
10274 dribble
= fopen (SDATA (file
), "w");
10276 report_file_error ("Opening dribble", Fcons (file
, Qnil
));
10281 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
10282 doc
: /* Discard the contents of the terminal input buffer.
10283 Also end any kbd macro being defined. */)
10286 if (!NILP (current_kboard
->defining_kbd_macro
))
10288 /* Discard the last command from the macro. */
10289 Fcancel_kbd_macro_events ();
10293 update_mode_lines
++;
10295 Vunread_command_events
= Qnil
;
10296 unread_command_char
= -1;
10298 discard_tty_input ();
10300 kbd_fetch_ptr
= kbd_store_ptr
;
10306 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
10307 doc
: /* Stop Emacs and return to superior process. You can resume later.
10308 If `cannot-suspend' is non-nil, or if the system doesn't support job
10309 control, run a subshell instead.
10311 If optional arg STUFFSTRING is non-nil, its characters are stuffed
10312 to be read as terminal input by Emacs's parent, after suspension.
10314 Before suspending, run the normal hook `suspend-hook'.
10315 After resumption run the normal hook `suspend-resume-hook'.
10317 Some operating systems cannot stop the Emacs process and resume it later.
10318 On such systems, Emacs starts a subshell instead of suspending. */)
10320 Lisp_Object stuffstring
;
10322 int count
= SPECPDL_INDEX ();
10323 int old_height
, old_width
;
10325 struct gcpro gcpro1
;
10327 if (!NILP (stuffstring
))
10328 CHECK_STRING (stuffstring
);
10330 /* Run the functions in suspend-hook. */
10331 if (!NILP (Vrun_hooks
))
10332 call1 (Vrun_hooks
, intern ("suspend-hook"));
10334 GCPRO1 (stuffstring
);
10335 get_frame_size (&old_width
, &old_height
);
10336 reset_sys_modes ();
10337 /* sys_suspend can get an error if it tries to fork a subshell
10338 and the system resources aren't available for that. */
10339 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object
))) init_sys_modes
,
10341 stuff_buffered_input (stuffstring
);
10342 if (cannot_suspend
)
10346 unbind_to (count
, Qnil
);
10348 /* Check if terminal/window size has changed.
10349 Note that this is not useful when we are running directly
10350 with a window system; but suspend should be disabled in that case. */
10351 get_frame_size (&width
, &height
);
10352 if (width
!= old_width
|| height
!= old_height
)
10353 change_frame_size (SELECTED_FRAME (), height
, width
, 0, 0, 0);
10355 /* Run suspend-resume-hook. */
10356 if (!NILP (Vrun_hooks
))
10357 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
10363 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
10364 Then in any case stuff anything Emacs has read ahead and not used. */
10367 stuff_buffered_input (stuffstring
)
10368 Lisp_Object stuffstring
;
10370 #ifdef SIGTSTP /* stuff_char is defined if SIGTSTP. */
10371 register unsigned char *p
;
10373 if (STRINGP (stuffstring
))
10375 register int count
;
10377 p
= SDATA (stuffstring
);
10378 count
= SBYTES (stuffstring
);
10379 while (count
-- > 0)
10384 /* Anything we have read ahead, put back for the shell to read. */
10385 /* ?? What should this do when we have multiple keyboards??
10386 Should we ignore anything that was typed in at the "wrong" kboard?
10388 rms: we should stuff everything back into the kboard
10390 for (; kbd_fetch_ptr
!= kbd_store_ptr
; kbd_fetch_ptr
++)
10393 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
10394 kbd_fetch_ptr
= kbd_buffer
;
10395 if (kbd_fetch_ptr
->kind
== ASCII_KEYSTROKE_EVENT
)
10396 stuff_char (kbd_fetch_ptr
->code
);
10398 clear_event (kbd_fetch_ptr
);
10402 #endif /* SIGTSTP */
10406 set_waiting_for_input (time_to_clear
)
10407 EMACS_TIME
*time_to_clear
;
10409 input_available_clear_time
= time_to_clear
;
10411 /* Tell interrupt_signal to throw back to read_char, */
10412 waiting_for_input
= 1;
10414 /* If interrupt_signal was called before and buffered a C-g,
10415 make it run again now, to avoid timing error. */
10416 if (!NILP (Vquit_flag
))
10417 quit_throw_to_read_char ();
10421 clear_waiting_for_input ()
10423 /* Tell interrupt_signal not to throw back to read_char, */
10424 waiting_for_input
= 0;
10425 input_available_clear_time
= 0;
10428 /* This routine is called at interrupt level in response to C-g.
10430 If interrupt_input, this is the handler for SIGINT. Otherwise, it
10431 is called from kbd_buffer_store_event, in handling SIGIO or
10434 If `waiting_for_input' is non zero, then unless `echoing' is
10435 nonzero, immediately throw back to read_char.
10437 Otherwise it sets the Lisp variable quit-flag not-nil. This causes
10438 eval to throw, when it gets a chance. If quit-flag is already
10439 non-nil, it stops the job right away. */
10442 interrupt_signal (signalnum
) /* If we don't have an argument, */
10443 int signalnum
; /* some compilers complain in signal calls. */
10446 /* Must preserve main program's value of errno. */
10447 int old_errno
= errno
;
10448 struct frame
*sf
= SELECTED_FRAME ();
10450 #if defined (USG) && !defined (POSIX_SIGNALS)
10451 if (!read_socket_hook
&& NILP (Vwindow_system
))
10453 /* USG systems forget handlers when they are used;
10454 must reestablish each time */
10455 signal (SIGINT
, interrupt_signal
);
10456 signal (SIGQUIT
, interrupt_signal
);
10460 SIGNAL_THREAD_CHECK (signalnum
);
10463 if (!NILP (Vquit_flag
)
10464 && (FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
)))
10466 /* If SIGINT isn't blocked, don't let us be interrupted by
10467 another SIGINT, it might be harmful due to non-reentrancy
10468 in I/O functions. */
10469 sigblock (sigmask (SIGINT
));
10472 reset_sys_modes ();
10474 #ifdef SIGTSTP /* Support possible in later USG versions */
10476 * On systems which can suspend the current process and return to the original
10477 * shell, this command causes the user to end up back at the shell.
10478 * The "Auto-save" and "Abort" questions are not asked until
10479 * the user elects to return to emacs, at which point he can save the current
10480 * job and either dump core or continue.
10485 if (sys_suspend () == -1)
10487 printf ("Not running as a subprocess;\n");
10488 printf ("you can continue or abort.\n");
10490 #else /* not VMS */
10491 /* Perhaps should really fork an inferior shell?
10492 But that would not provide any way to get back
10493 to the original shell, ever. */
10494 printf ("No support for stopping a process on this operating system;\n");
10495 printf ("you can continue or abort.\n");
10496 #endif /* not VMS */
10497 #endif /* not SIGTSTP */
10499 /* We must remain inside the screen area when the internal terminal
10500 is used. Note that [Enter] is not echoed by dos. */
10503 /* It doesn't work to autosave while GC is in progress;
10504 the code used for auto-saving doesn't cope with the mark bit. */
10505 if (!gc_in_progress
)
10507 printf ("Auto-save? (y or n) ");
10509 if (((c
= getchar ()) & ~040) == 'Y')
10511 Fdo_auto_save (Qt
, Qnil
);
10513 printf ("\r\nAuto-save done");
10514 #else /* not MSDOS */
10515 printf ("Auto-save done\n");
10516 #endif /* not MSDOS */
10518 while (c
!= '\n') c
= getchar ();
10522 /* During GC, it must be safe to reenable quitting again. */
10523 Vinhibit_quit
= Qnil
;
10526 #endif /* not MSDOS */
10527 printf ("Garbage collection in progress; cannot auto-save now\r\n");
10528 printf ("but will instead do a real quit after garbage collection ends\r\n");
10533 printf ("\r\nAbort? (y or n) ");
10534 #else /* not MSDOS */
10536 printf ("Abort (and enter debugger)? (y or n) ");
10537 #else /* not VMS */
10538 printf ("Abort (and dump core)? (y or n) ");
10539 #endif /* not VMS */
10540 #endif /* not MSDOS */
10542 if (((c
= getchar ()) & ~040) == 'Y')
10544 while (c
!= '\n') c
= getchar ();
10546 printf ("\r\nContinuing...\r\n");
10547 #else /* not MSDOS */
10548 printf ("Continuing...\n");
10549 #endif /* not MSDOS */
10556 /* If executing a function that wants to be interrupted out of
10557 and the user has not deferred quitting by binding `inhibit-quit'
10558 then quit right away. */
10559 if (immediate_quit
&& NILP (Vinhibit_quit
))
10561 struct gl_state_s saved
;
10562 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
10564 immediate_quit
= 0;
10567 GCPRO4 (saved
.object
, saved
.global_code
,
10568 saved
.current_syntax_table
, saved
.old_prop
);
10569 Fsignal (Qquit
, Qnil
);
10574 /* Else request quit when it's safe */
10578 if (waiting_for_input
&& !echoing
)
10579 quit_throw_to_read_char ();
10584 /* Handle a C-g by making read_char return C-g. */
10587 quit_throw_to_read_char ()
10590 /* Prevent another signal from doing this before we finish. */
10591 clear_waiting_for_input ();
10594 Vunread_command_events
= Qnil
;
10595 unread_command_char
= -1;
10597 #if 0 /* Currently, sit_for is called from read_char without turning
10598 off polling. And that can call set_waiting_for_input.
10599 It seems to be harmless. */
10600 #ifdef POLL_FOR_INPUT
10601 /* May be > 1 if in recursive minibuffer. */
10602 if (poll_suppress_count
== 0)
10606 if (FRAMEP (internal_last_event_frame
)
10607 && !EQ (internal_last_event_frame
, selected_frame
))
10608 do_switch_frame (make_lispy_switch_frame (internal_last_event_frame
),
10611 _longjmp (getcjmp
, 1);
10614 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
10615 doc
: /* Set mode of reading keyboard input.
10616 First arg INTERRUPT non-nil means use input interrupts;
10617 nil means use CBREAK mode.
10618 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal
10619 (no effect except in CBREAK mode).
10620 Third arg META t means accept 8-bit input (for a Meta key).
10621 META nil means ignore the top bit, on the assumption it is parity.
10622 Otherwise, accept 8-bit input and don't use the top bit for Meta.
10623 Optional fourth arg QUIT if non-nil specifies character to use for quitting.
10624 See also `current-input-mode'. */)
10625 (interrupt
, flow
, meta
, quit
)
10626 Lisp_Object interrupt
, flow
, meta
, quit
;
10629 && (!INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400))
10630 error ("set-input-mode: QUIT must be an ASCII character");
10632 #ifdef POLL_FOR_INPUT
10637 /* this causes startup screen to be restored and messes with the mouse */
10638 reset_sys_modes ();
10642 /* Note SIGIO has been undef'd if FIONREAD is missing. */
10643 if (read_socket_hook
)
10645 /* When using X, don't give the user a real choice,
10646 because we haven't implemented the mechanisms to support it. */
10647 #ifdef NO_SOCK_SIGIO
10648 interrupt_input
= 0;
10649 #else /* not NO_SOCK_SIGIO */
10650 interrupt_input
= 1;
10651 #endif /* NO_SOCK_SIGIO */
10654 interrupt_input
= !NILP (interrupt
);
10655 #else /* not SIGIO */
10656 interrupt_input
= 0;
10657 #endif /* not SIGIO */
10659 /* Our VMS input only works by interrupts, as of now. */
10661 interrupt_input
= 1;
10664 flow_control
= !NILP (flow
);
10667 else if (EQ (meta
, Qt
))
10672 /* Don't let this value be out of range. */
10673 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
10679 #ifdef POLL_FOR_INPUT
10680 poll_suppress_count
= 1;
10686 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
10687 doc
: /* Return information about the way Emacs currently reads keyboard input.
10688 The value is a list of the form (INTERRUPT FLOW META QUIT), where
10689 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if
10690 nil, Emacs is using CBREAK mode.
10691 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the
10692 terminal; this does not apply if Emacs uses interrupt-driven input.
10693 META is t if accepting 8-bit input with 8th bit as Meta flag.
10694 META nil means ignoring the top bit, on the assumption it is parity.
10695 META is neither t nor nil if accepting 8-bit input and using
10696 all 8 bits as the character code.
10697 QUIT is the character Emacs currently uses to quit.
10698 The elements of this list correspond to the arguments of
10699 `set-input-mode'. */)
10702 Lisp_Object val
[4];
10704 val
[0] = interrupt_input
? Qt
: Qnil
;
10705 val
[1] = flow_control
? Qt
: Qnil
;
10706 val
[2] = meta_key
== 2 ? make_number (0) : meta_key
== 1 ? Qt
: Qnil
;
10707 XSETFASTINT (val
[3], quit_char
);
10709 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
10712 DEFUN ("posn-at-x-y", Fposn_at_x_y
, Sposn_at_x_y
, 2, 4, 0,
10713 doc
: /* Return position information for pixel coordinates X and Y.
10714 By default, X and Y are relative to text area of the selected window.
10715 Optional third arg FRAME-OR-WINDOW non-nil specifies frame or window.
10716 If optional fourth arg WHOLE is non-nil, X is relative to the left
10717 edge of the window.
10719 The return value is similar to a mouse click position:
10720 (WINDOW AREA-OR-POS (X . Y) TIMESTAMP OBJECT POS (COL . ROW)
10721 IMAGE (DX . DY) (WIDTH . HEIGHT))
10722 The `posn-' functions access elements of such lists. */)
10723 (x
, y
, frame_or_window
, whole
)
10724 Lisp_Object x
, y
, frame_or_window
, whole
;
10729 if (NILP (frame_or_window
))
10730 frame_or_window
= selected_window
;
10732 if (WINDOWP (frame_or_window
))
10736 CHECK_LIVE_WINDOW (frame_or_window
);
10738 w
= XWINDOW (frame_or_window
);
10739 XSETINT (x
, (XINT (x
)
10740 + WINDOW_LEFT_EDGE_X (w
)
10742 ? window_box_left_offset (w
, TEXT_AREA
)
10744 XSETINT (y
, WINDOW_TO_FRAME_PIXEL_Y (w
, XINT (y
)));
10745 frame_or_window
= w
->frame
;
10748 CHECK_LIVE_FRAME (frame_or_window
);
10750 return make_lispy_position (XFRAME (frame_or_window
), &x
, &y
, 0);
10753 DEFUN ("posn-at-point", Fposn_at_point
, Sposn_at_point
, 0, 2, 0,
10754 doc
: /* Return position information for buffer POS in WINDOW.
10755 POS defaults to point in WINDOW; WINDOW defaults to the selected window.
10757 Return nil if position is not visible in window. Otherwise,
10758 the return value is similar to that returned by `event-start' for
10759 a mouse click at the upper left corner of the glyph corresponding
10760 to the given buffer position:
10761 (WINDOW AREA-OR-POS (X . Y) TIMESTAMP OBJECT POS (COL . ROW)
10762 IMAGE (DX . DY) (WIDTH . HEIGHT))
10763 The `posn-' functions access elements of such lists. */)
10765 Lisp_Object pos
, window
;
10770 window
= selected_window
;
10772 tem
= Fpos_visible_in_window_p (pos
, window
, Qt
);
10775 Lisp_Object x
= XCAR (tem
);
10776 Lisp_Object y
= XCAR (XCDR (tem
));
10778 /* Point invisible due to hscrolling? */
10781 tem
= Fposn_at_x_y (x
, y
, window
, Qnil
);
10789 * Set up a new kboard object with reasonable initial values.
10795 kb
->Voverriding_terminal_local_map
= Qnil
;
10796 kb
->Vlast_command
= Qnil
;
10797 kb
->Vreal_last_command
= Qnil
;
10798 kb
->Vprefix_arg
= Qnil
;
10799 kb
->Vlast_prefix_arg
= Qnil
;
10800 kb
->kbd_queue
= Qnil
;
10801 kb
->kbd_queue_has_data
= 0;
10802 kb
->immediate_echo
= 0;
10803 kb
->echo_string
= Qnil
;
10804 kb
->echo_after_prompt
= -1;
10805 kb
->kbd_macro_buffer
= 0;
10806 kb
->kbd_macro_bufsize
= 0;
10807 kb
->defining_kbd_macro
= Qnil
;
10808 kb
->Vlast_kbd_macro
= Qnil
;
10809 kb
->reference_count
= 0;
10810 kb
->Vsystem_key_alist
= Qnil
;
10811 kb
->system_key_syms
= Qnil
;
10812 kb
->Vdefault_minibuffer_frame
= Qnil
;
10816 * Destroy the contents of a kboard object, but not the object itself.
10817 * We use this just before deleting it, or if we're going to initialize
10818 * it a second time.
10824 if (kb
->kbd_macro_buffer
)
10825 xfree (kb
->kbd_macro_buffer
);
10828 #ifdef MULTI_KBOARD
10830 /* Free KB and memory referenced from it. */
10838 for (kbp
= &all_kboards
; *kbp
!= kb
; kbp
= &(*kbp
)->next_kboard
)
10841 *kbp
= kb
->next_kboard
;
10843 /* Prevent a dangling reference to KB. */
10844 if (kb
== current_kboard
10845 && FRAMEP (selected_frame
)
10846 && FRAME_LIVE_P (XFRAME (selected_frame
)))
10848 current_kboard
= XFRAME (selected_frame
)->kboard
;
10849 if (current_kboard
== kb
)
10857 #endif /* MULTI_KBOARD */
10862 /* This is correct before outermost invocation of the editor loop */
10863 command_loop_level
= -1;
10864 immediate_quit
= 0;
10865 quit_char
= Ctl ('g');
10866 Vunread_command_events
= Qnil
;
10867 unread_command_char
= -1;
10868 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
10870 recent_keys_index
= 0;
10871 kbd_fetch_ptr
= kbd_buffer
;
10872 kbd_store_ptr
= kbd_buffer
;
10874 do_mouse_tracking
= Qnil
;
10878 /* This means that command_loop_1 won't try to select anything the first
10880 internal_last_event_frame
= Qnil
;
10881 Vlast_event_frame
= internal_last_event_frame
;
10883 #ifdef MULTI_KBOARD
10884 current_kboard
= initial_kboard
;
10886 wipe_kboard (current_kboard
);
10887 init_kboard (current_kboard
);
10889 if (!noninteractive
&& !read_socket_hook
&& NILP (Vwindow_system
))
10891 signal (SIGINT
, interrupt_signal
);
10892 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
10893 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
10894 SIGQUIT and we can't tell which one it will give us. */
10895 signal (SIGQUIT
, interrupt_signal
);
10896 #endif /* HAVE_TERMIO */
10898 /* Note SIGIO has been undef'd if FIONREAD is missing. */
10900 if (!noninteractive
)
10901 signal (SIGIO
, input_available_signal
);
10904 /* Use interrupt input by default, if it works and noninterrupt input
10905 has deficiencies. */
10907 #ifdef INTERRUPT_INPUT
10908 interrupt_input
= 1;
10910 interrupt_input
= 0;
10913 /* Our VMS input only works by interrupts, as of now. */
10915 interrupt_input
= 1;
10921 if (keyboard_init_hook
)
10922 (*keyboard_init_hook
) ();
10924 #ifdef POLL_FOR_INPUT
10925 poll_suppress_count
= 1;
10930 /* This type's only use is in syms_of_keyboard, to initialize the
10931 event header symbols and put properties on them. */
10932 struct event_head
{
10938 struct event_head head_table
[] = {
10939 {&Qmouse_movement
, "mouse-movement", &Qmouse_movement
},
10940 {&Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
},
10941 {&Qswitch_frame
, "switch-frame", &Qswitch_frame
},
10942 {&Qdelete_frame
, "delete-frame", &Qdelete_frame
},
10943 {&Qiconify_frame
, "iconify-frame", &Qiconify_frame
},
10944 {&Qmake_frame_visible
, "make-frame-visible", &Qmake_frame_visible
},
10945 /* `select-window' should be handled just like `switch-frame'
10946 in read_key_sequence. */
10947 {&Qselect_window
, "select-window", &Qswitch_frame
}
10951 syms_of_keyboard ()
10953 Vpre_help_message
= Qnil
;
10954 staticpro (&Vpre_help_message
);
10956 Vlispy_mouse_stem
= build_string ("mouse");
10957 staticpro (&Vlispy_mouse_stem
);
10960 QCimage
= intern (":image");
10961 staticpro (&QCimage
);
10963 staticpro (&Qhelp_echo
);
10964 Qhelp_echo
= intern ("help-echo");
10966 staticpro (&item_properties
);
10967 item_properties
= Qnil
;
10969 staticpro (&tool_bar_item_properties
);
10970 tool_bar_item_properties
= Qnil
;
10971 staticpro (&tool_bar_items_vector
);
10972 tool_bar_items_vector
= Qnil
;
10974 staticpro (&real_this_command
);
10975 real_this_command
= Qnil
;
10977 Qtimer_event_handler
= intern ("timer-event-handler");
10978 staticpro (&Qtimer_event_handler
);
10980 Qdisabled_command_function
= intern ("disabled-command-function");
10981 staticpro (&Qdisabled_command_function
);
10983 Qself_insert_command
= intern ("self-insert-command");
10984 staticpro (&Qself_insert_command
);
10986 Qforward_char
= intern ("forward-char");
10987 staticpro (&Qforward_char
);
10989 Qbackward_char
= intern ("backward-char");
10990 staticpro (&Qbackward_char
);
10992 Qdisabled
= intern ("disabled");
10993 staticpro (&Qdisabled
);
10995 Qundefined
= intern ("undefined");
10996 staticpro (&Qundefined
);
10998 Qpre_command_hook
= intern ("pre-command-hook");
10999 staticpro (&Qpre_command_hook
);
11001 Qpost_command_hook
= intern ("post-command-hook");
11002 staticpro (&Qpost_command_hook
);
11004 Qdeferred_action_function
= intern ("deferred-action-function");
11005 staticpro (&Qdeferred_action_function
);
11007 Qcommand_hook_internal
= intern ("command-hook-internal");
11008 staticpro (&Qcommand_hook_internal
);
11010 Qfunction_key
= intern ("function-key");
11011 staticpro (&Qfunction_key
);
11012 Qmouse_click
= intern ("mouse-click");
11013 staticpro (&Qmouse_click
);
11014 #if defined (WINDOWSNT) || defined (MAC_OS)
11015 Qlanguage_change
= intern ("language-change");
11016 staticpro (&Qlanguage_change
);
11018 Qdrag_n_drop
= intern ("drag-n-drop");
11019 staticpro (&Qdrag_n_drop
);
11021 Qsave_session
= intern ("save-session");
11022 staticpro (&Qsave_session
);
11025 Qmac_apple_event
= intern ("mac-apple-event");
11026 staticpro (&Qmac_apple_event
);
11029 Qusr1_signal
= intern ("usr1-signal");
11030 staticpro (&Qusr1_signal
);
11031 Qusr2_signal
= intern ("usr2-signal");
11032 staticpro (&Qusr2_signal
);
11034 Qmenu_enable
= intern ("menu-enable");
11035 staticpro (&Qmenu_enable
);
11036 Qmenu_alias
= intern ("menu-alias");
11037 staticpro (&Qmenu_alias
);
11038 QCenable
= intern (":enable");
11039 staticpro (&QCenable
);
11040 QCvisible
= intern (":visible");
11041 staticpro (&QCvisible
);
11042 QChelp
= intern (":help");
11043 staticpro (&QChelp
);
11044 QCfilter
= intern (":filter");
11045 staticpro (&QCfilter
);
11046 QCbutton
= intern (":button");
11047 staticpro (&QCbutton
);
11048 QCkeys
= intern (":keys");
11049 staticpro (&QCkeys
);
11050 QCkey_sequence
= intern (":key-sequence");
11051 staticpro (&QCkey_sequence
);
11052 QCtoggle
= intern (":toggle");
11053 staticpro (&QCtoggle
);
11054 QCradio
= intern (":radio");
11055 staticpro (&QCradio
);
11057 Qmode_line
= intern ("mode-line");
11058 staticpro (&Qmode_line
);
11059 Qvertical_line
= intern ("vertical-line");
11060 staticpro (&Qvertical_line
);
11061 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
11062 staticpro (&Qvertical_scroll_bar
);
11063 Qmenu_bar
= intern ("menu-bar");
11064 staticpro (&Qmenu_bar
);
11067 Qmouse_fixup_help_message
= intern ("mouse-fixup-help-message");
11068 staticpro (&Qmouse_fixup_help_message
);
11071 Qabove_handle
= intern ("above-handle");
11072 staticpro (&Qabove_handle
);
11073 Qhandle
= intern ("handle");
11074 staticpro (&Qhandle
);
11075 Qbelow_handle
= intern ("below-handle");
11076 staticpro (&Qbelow_handle
);
11077 Qup
= intern ("up");
11079 Qdown
= intern ("down");
11080 staticpro (&Qdown
);
11081 Qtop
= intern ("top");
11083 Qbottom
= intern ("bottom");
11084 staticpro (&Qbottom
);
11085 Qend_scroll
= intern ("end-scroll");
11086 staticpro (&Qend_scroll
);
11087 Qratio
= intern ("ratio");
11088 staticpro (&Qratio
);
11090 Qevent_kind
= intern ("event-kind");
11091 staticpro (&Qevent_kind
);
11092 Qevent_symbol_elements
= intern ("event-symbol-elements");
11093 staticpro (&Qevent_symbol_elements
);
11094 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
11095 staticpro (&Qevent_symbol_element_mask
);
11096 Qmodifier_cache
= intern ("modifier-cache");
11097 staticpro (&Qmodifier_cache
);
11099 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
11100 staticpro (&Qrecompute_lucid_menubar
);
11101 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
11102 staticpro (&Qactivate_menubar_hook
);
11104 Qpolling_period
= intern ("polling-period");
11105 staticpro (&Qpolling_period
);
11107 Qinput_method_function
= intern ("input-method-function");
11108 staticpro (&Qinput_method_function
);
11110 Qinput_method_exit_on_first_char
= intern ("input-method-exit-on-first-char");
11111 staticpro (&Qinput_method_exit_on_first_char
);
11112 Qinput_method_use_echo_area
= intern ("input-method-use-echo-area");
11113 staticpro (&Qinput_method_use_echo_area
);
11115 Fset (Qinput_method_exit_on_first_char
, Qnil
);
11116 Fset (Qinput_method_use_echo_area
, Qnil
);
11118 last_point_position_buffer
= Qnil
;
11119 last_point_position_window
= Qnil
;
11122 struct event_head
*p
;
11124 for (p
= head_table
;
11125 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
11128 *p
->var
= intern (p
->name
);
11129 staticpro (p
->var
);
11130 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
11131 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
11135 button_down_location
= Fmake_vector (make_number (1), Qnil
);
11136 staticpro (&button_down_location
);
11137 mouse_syms
= Fmake_vector (make_number (1), Qnil
);
11138 staticpro (&mouse_syms
);
11139 wheel_syms
= Fmake_vector (make_number (2), Qnil
);
11140 staticpro (&wheel_syms
);
11144 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
11146 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
11147 for (i
= 0; i
< len
; i
++)
11148 if (modifier_names
[i
])
11149 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
11150 staticpro (&modifier_symbols
);
11153 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
11154 staticpro (&recent_keys
);
11156 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
11157 staticpro (&this_command_keys
);
11159 raw_keybuf
= Fmake_vector (make_number (30), Qnil
);
11160 staticpro (&raw_keybuf
);
11162 Qextended_command_history
= intern ("extended-command-history");
11163 Fset (Qextended_command_history
, Qnil
);
11164 staticpro (&Qextended_command_history
);
11166 accent_key_syms
= Qnil
;
11167 staticpro (&accent_key_syms
);
11169 func_key_syms
= Qnil
;
11170 staticpro (&func_key_syms
);
11172 drag_n_drop_syms
= Qnil
;
11173 staticpro (&drag_n_drop_syms
);
11175 unread_switch_frame
= Qnil
;
11176 staticpro (&unread_switch_frame
);
11178 internal_last_event_frame
= Qnil
;
11179 staticpro (&internal_last_event_frame
);
11181 read_key_sequence_cmd
= Qnil
;
11182 staticpro (&read_key_sequence_cmd
);
11184 menu_bar_one_keymap_changed_items
= Qnil
;
11185 staticpro (&menu_bar_one_keymap_changed_items
);
11187 menu_bar_items_vector
= Qnil
;
11188 staticpro (&menu_bar_items_vector
);
11190 defsubr (&Scurrent_idle_time
);
11191 defsubr (&Sevent_convert_list
);
11192 defsubr (&Sread_key_sequence
);
11193 defsubr (&Sread_key_sequence_vector
);
11194 defsubr (&Srecursive_edit
);
11196 defsubr (&Strack_mouse
);
11198 defsubr (&Sinput_pending_p
);
11199 defsubr (&Scommand_execute
);
11200 defsubr (&Srecent_keys
);
11201 defsubr (&Sthis_command_keys
);
11202 defsubr (&Sthis_command_keys_vector
);
11203 defsubr (&Sthis_single_command_keys
);
11204 defsubr (&Sthis_single_command_raw_keys
);
11205 defsubr (&Sreset_this_command_lengths
);
11206 defsubr (&Sclear_this_command_keys
);
11207 defsubr (&Ssuspend_emacs
);
11208 defsubr (&Sabort_recursive_edit
);
11209 defsubr (&Sexit_recursive_edit
);
11210 defsubr (&Srecursion_depth
);
11211 defsubr (&Stop_level
);
11212 defsubr (&Sdiscard_input
);
11213 defsubr (&Sopen_dribble_file
);
11214 defsubr (&Sset_input_mode
);
11215 defsubr (&Scurrent_input_mode
);
11216 defsubr (&Sexecute_extended_command
);
11217 defsubr (&Sposn_at_point
);
11218 defsubr (&Sposn_at_x_y
);
11220 DEFVAR_LISP ("last-command-char", &last_command_char
,
11221 doc
: /* Last input event that was part of a command. */);
11223 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char
,
11224 doc
: /* Last input event that was part of a command. */);
11226 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
11227 doc
: /* Last input event in a command, except for mouse menu events.
11228 Mouse menus give back keys that don't look like mouse events;
11229 this variable holds the actual mouse event that led to the menu,
11230 so that you can determine whether the command was run by mouse or not. */);
11232 DEFVAR_LISP ("last-input-char", &last_input_char
,
11233 doc
: /* Last input event. */);
11235 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char
,
11236 doc
: /* Last input event. */);
11238 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
11239 doc
: /* List of events to be read as the command input.
11240 These events are processed first, before actual keyboard input.
11241 Events read from this list are not normally added to `this-command-keys',
11242 as they will already have been added once as they were read for the first time.
11243 An element of the form (t . EVENT) forces EVENT to be added to that list. */);
11244 Vunread_command_events
= Qnil
;
11246 DEFVAR_INT ("unread-command-char", &unread_command_char
,
11247 doc
: /* If not -1, an object to be read as next command input event. */);
11249 DEFVAR_LISP ("unread-post-input-method-events", &Vunread_post_input_method_events
,
11250 doc
: /* List of events to be processed as input by input methods.
11251 These events are processed before `unread-command-events'
11252 and actual keyboard input without given to `input-method-function'. */);
11253 Vunread_post_input_method_events
= Qnil
;
11255 DEFVAR_LISP ("unread-input-method-events", &Vunread_input_method_events
,
11256 doc
: /* List of events to be processed as input by input methods.
11257 These events are processed after `unread-command-events', but
11258 before actual keyboard input.
11259 If there's an active input method, the events are given to
11260 `input-method-function'. */);
11261 Vunread_input_method_events
= Qnil
;
11263 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
11264 doc
: /* Meta-prefix character code.
11265 Meta-foo as command input turns into this character followed by foo. */);
11266 XSETINT (meta_prefix_char
, 033);
11268 DEFVAR_KBOARD ("last-command", Vlast_command
,
11269 doc
: /* The last command executed.
11270 Normally a symbol with a function definition, but can be whatever was found
11271 in the keymap, or whatever the variable `this-command' was set to by that
11274 The value `mode-exit' is special; it means that the previous command
11275 read an event that told it to exit, and it did so and unread that event.
11276 In other words, the present command is the event that made the previous
11279 The value `kill-region' is special; it means that the previous command
11280 was a kill command. */);
11282 DEFVAR_KBOARD ("real-last-command", Vreal_last_command
,
11283 doc
: /* Same as `last-command', but never altered by Lisp code. */);
11285 DEFVAR_LISP ("this-command", &Vthis_command
,
11286 doc
: /* The command now being executed.
11287 The command can set this variable; whatever is put here
11288 will be in `last-command' during the following command. */);
11289 Vthis_command
= Qnil
;
11291 DEFVAR_LISP ("this-original-command", &Vthis_original_command
,
11292 doc
: /* The command bound to the current key sequence before remapping.
11293 It equals `this-command' if the original command was not remapped through
11294 any of the active keymaps. Otherwise, the value of `this-command' is the
11295 result of looking up the original command in the active keymaps. */);
11296 Vthis_original_command
= Qnil
;
11298 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
11299 doc
: /* *Number of input events between auto-saves.
11300 Zero means disable autosaving due to number of characters typed. */);
11301 auto_save_interval
= 300;
11303 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
11304 doc
: /* *Number of seconds idle time before auto-save.
11305 Zero or nil means disable auto-saving due to idleness.
11306 After auto-saving due to this many seconds of idle time,
11307 Emacs also does a garbage collection if that seems to be warranted. */);
11308 XSETFASTINT (Vauto_save_timeout
, 30);
11310 DEFVAR_LISP ("echo-keystrokes", &Vecho_keystrokes
,
11311 doc
: /* *Nonzero means echo unfinished commands after this many seconds of pause.
11312 The value may be integer or floating point. */);
11313 Vecho_keystrokes
= make_number (1);
11315 DEFVAR_INT ("polling-period", &polling_period
,
11316 doc
: /* *Interval between polling for input during Lisp execution.
11317 The reason for polling is to make C-g work to stop a running program.
11318 Polling is needed only when using X windows and SIGIO does not work.
11319 Polling is automatically disabled in all other cases. */);
11320 polling_period
= 2;
11322 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
11323 doc
: /* *Maximum time between mouse clicks to make a double-click.
11324 Measured in milliseconds. nil means disable double-click recognition;
11325 t means double-clicks have no time limit and are detected
11326 by position only. */);
11327 Vdouble_click_time
= make_number (500);
11329 DEFVAR_INT ("double-click-fuzz", &double_click_fuzz
,
11330 doc
: /* *Maximum mouse movement between clicks to make a double-click.
11331 On window-system frames, value is the number of pixels the mouse may have
11332 moved horizontally or vertically between two clicks to make a double-click.
11333 On non window-system frames, value is interpreted in units of 1/8 characters
11336 This variable is also the threshold for motion of the mouse
11337 to count as a drag. */);
11338 double_click_fuzz
= 3;
11340 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
11341 doc
: /* *Non-nil means inhibit local map menu bar menus. */);
11342 inhibit_local_menu_bar_menus
= 0;
11344 DEFVAR_INT ("num-input-keys", &num_input_keys
,
11345 doc
: /* Number of complete key sequences read as input so far.
11346 This includes key sequences read from keyboard macros.
11347 The number is effectively the number of interactive command invocations. */);
11348 num_input_keys
= 0;
11350 DEFVAR_INT ("num-nonmacro-input-events", &num_nonmacro_input_events
,
11351 doc
: /* Number of input events read from the keyboard so far.
11352 This does not include events generated by keyboard macros. */);
11353 num_nonmacro_input_events
= 0;
11355 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
11356 doc
: /* The frame in which the most recently read event occurred.
11357 If the last event came from a keyboard macro, this is set to `macro'. */);
11358 Vlast_event_frame
= Qnil
;
11360 /* This variable is set up in sysdep.c. */
11361 DEFVAR_LISP ("tty-erase-char", &Vtty_erase_char
,
11362 doc
: /* The ERASE character as set by the user with stty. */);
11364 DEFVAR_LISP ("help-char", &Vhelp_char
,
11365 doc
: /* Character to recognize as meaning Help.
11366 When it is read, do `(eval help-form)', and display result if it's a string.
11367 If the value of `help-form' is nil, this char can be read normally. */);
11368 XSETINT (Vhelp_char
, Ctl ('H'));
11370 DEFVAR_LISP ("help-event-list", &Vhelp_event_list
,
11371 doc
: /* List of input events to recognize as meaning Help.
11372 These work just like the value of `help-char' (see that). */);
11373 Vhelp_event_list
= Qnil
;
11375 DEFVAR_LISP ("help-form", &Vhelp_form
,
11376 doc
: /* Form to execute when character `help-char' is read.
11377 If the form returns a string, that string is displayed.
11378 If `help-form' is nil, the help char is not recognized. */);
11381 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
11382 doc
: /* Command to run when `help-char' character follows a prefix key.
11383 This command is used only when there is no actual binding
11384 for that character after that prefix key. */);
11385 Vprefix_help_command
= Qnil
;
11387 DEFVAR_LISP ("top-level", &Vtop_level
,
11388 doc
: /* Form to evaluate when Emacs starts up.
11389 Useful to set before you dump a modified Emacs. */);
11392 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
11393 doc
: /* Translate table for keyboard input, or nil.
11394 If non-nil, the value should be a char-table. Each character read
11395 from the keyboard is looked up in this char-table. If the value found
11396 there is non-nil, then it is used instead of the actual input character.
11398 The value can also be a string or vector, but this is considered obsolete.
11399 If it is a string or vector of length N, character codes N and up are left
11400 untranslated. In a vector, an element which is nil means "no translation".
11402 This is applied to the characters supplied to input methods, not their
11403 output. See also `translation-table-for-input'. */);
11404 Vkeyboard_translate_table
= Qnil
;
11406 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
11407 doc
: /* Non-nil means to always spawn a subshell instead of suspending.
11408 \(Even if the operating system has support for stopping a process.\) */);
11409 cannot_suspend
= 0;
11411 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
11412 doc
: /* Non-nil means prompt with menus when appropriate.
11413 This is done when reading from a keymap that has a prompt string,
11414 for elements that have prompt strings.
11415 The menu is displayed on the screen
11416 if X menus were enabled at configuration
11417 time and the previous event was a mouse click prefix key.
11418 Otherwise, menu prompting uses the echo area. */);
11419 menu_prompting
= 1;
11421 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
11422 doc
: /* Character to see next line of menu prompt.
11423 Type this character while in a menu prompt to rotate around the lines of it. */);
11424 XSETINT (menu_prompt_more_char
, ' ');
11426 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
11427 doc
: /* A mask of additional modifier keys to use with every keyboard character.
11428 Emacs applies the modifiers of the character stored here to each keyboard
11429 character it reads. For example, after evaluating the expression
11430 (setq extra-keyboard-modifiers ?\\C-x)
11431 all input characters will have the control modifier applied to them.
11433 Note that the character ?\\C-@, equivalent to the integer zero, does
11434 not count as a control character; rather, it counts as a character
11435 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero
11436 cancels any modification. */);
11437 extra_keyboard_modifiers
= 0;
11439 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
11440 doc
: /* If an editing command sets this to t, deactivate the mark afterward.
11441 The command loop sets this to nil before each command,
11442 and tests the value when the command returns.
11443 Buffer modification stores t in this variable. */);
11444 Vdeactivate_mark
= Qnil
;
11446 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
11447 doc
: /* Temporary storage of pre-command-hook or post-command-hook. */);
11448 Vcommand_hook_internal
= Qnil
;
11450 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
11451 doc
: /* Normal hook run before each command is executed.
11452 If an unhandled error happens in running this hook,
11453 the hook value is set to nil, since otherwise the error
11454 might happen repeatedly and make Emacs nonfunctional. */);
11455 Vpre_command_hook
= Qnil
;
11457 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
11458 doc
: /* Normal hook run after each command is executed.
11459 If an unhandled error happens in running this hook,
11460 the hook value is set to nil, since otherwise the error
11461 might happen repeatedly and make Emacs nonfunctional. */);
11462 Vpost_command_hook
= Qnil
;
11465 DEFVAR_LISP ("echo-area-clear-hook", ...,
11466 doc
: /* Normal hook run when clearing the echo area. */);
11468 Qecho_area_clear_hook
= intern ("echo-area-clear-hook");
11469 staticpro (&Qecho_area_clear_hook
);
11470 SET_SYMBOL_VALUE (Qecho_area_clear_hook
, Qnil
);
11472 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
11473 doc
: /* Non-nil means menu bar, specified Lucid style, needs to be recomputed. */);
11474 Vlucid_menu_bar_dirty_flag
= Qnil
;
11476 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
11477 doc
: /* List of menu bar items to move to the end of the menu bar.
11478 The elements of the list are event types that may have menu bar bindings. */);
11479 Vmenu_bar_final_items
= Qnil
;
11481 DEFVAR_KBOARD ("overriding-terminal-local-map",
11482 Voverriding_terminal_local_map
,
11483 doc
: /* Per-terminal keymap that overrides all other local keymaps.
11484 If this variable is non-nil, it is used as a keymap instead of the
11485 buffer's local map, and the minor mode keymaps and text property keymaps.
11486 It also replaces `overriding-local-map'.
11488 This variable is intended to let commands such as `universal-argument'
11489 set up a different keymap for reading the next command. */);
11491 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
11492 doc
: /* Keymap that overrides all other local keymaps.
11493 If this variable is non-nil, it is used as a keymap--replacing the
11494 buffer's local map, the minor mode keymaps, and char property keymaps. */);
11495 Voverriding_local_map
= Qnil
;
11497 DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag
,
11498 doc
: /* Non-nil means `overriding-local-map' applies to the menu bar.
11499 Otherwise, the menu bar continues to reflect the buffer's local map
11500 and the minor mode maps regardless of `overriding-local-map'. */);
11501 Voverriding_local_map_menu_flag
= Qnil
;
11503 DEFVAR_LISP ("special-event-map", &Vspecial_event_map
,
11504 doc
: /* Keymap defining bindings for special events to execute at low level. */);
11505 Vspecial_event_map
= Fcons (intern ("keymap"), Qnil
);
11507 DEFVAR_LISP ("track-mouse", &do_mouse_tracking
,
11508 doc
: /* *Non-nil means generate motion events for mouse motion. */);
11510 DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist
,
11511 doc
: /* Alist of system-specific X windows key symbols.
11512 Each element should have the form (N . SYMBOL) where N is the
11513 numeric keysym code (sans the \"system-specific\" bit 1<<28)
11514 and SYMBOL is its name. */);
11516 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
11517 doc
: /* List of deferred actions to be performed at a later time.
11518 The precise format isn't relevant here; we just check whether it is nil. */);
11519 Vdeferred_action_list
= Qnil
;
11521 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
11522 doc
: /* Function to call to handle deferred actions, after each command.
11523 This function is called with no arguments after each command
11524 whenever `deferred-action-list' is non-nil. */);
11525 Vdeferred_action_function
= Qnil
;
11527 DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings
,
11528 doc
: /* *Non-nil means show the equivalent key-binding when M-x command has one.
11529 The value can be a length of time to show the message for.
11530 If the value is non-nil and not a number, we wait 2 seconds. */);
11531 Vsuggest_key_bindings
= Qt
;
11533 DEFVAR_LISP ("timer-list", &Vtimer_list
,
11534 doc
: /* List of active absolute time timers in order of increasing time. */);
11535 Vtimer_list
= Qnil
;
11537 DEFVAR_LISP ("timer-idle-list", &Vtimer_idle_list
,
11538 doc
: /* List of active idle-time timers in order of increasing time. */);
11539 Vtimer_idle_list
= Qnil
;
11541 DEFVAR_LISP ("input-method-function", &Vinput_method_function
,
11542 doc
: /* If non-nil, the function that implements the current input method.
11543 It's called with one argument, a printing character that was just read.
11544 \(That means a character with code 040...0176.)
11545 Typically this function uses `read-event' to read additional events.
11546 When it does so, it should first bind `input-method-function' to nil
11547 so it will not be called recursively.
11549 The function should return a list of zero or more events
11550 to be used as input. If it wants to put back some events
11551 to be reconsidered, separately, by the input method,
11552 it can add them to the beginning of `unread-command-events'.
11554 The input method function can find in `input-method-previous-method'
11555 the previous echo area message.
11557 The input method function should refer to the variables
11558 `input-method-use-echo-area' and `input-method-exit-on-first-char'
11559 for guidance on what to do. */);
11560 Vinput_method_function
= Qnil
;
11562 DEFVAR_LISP ("input-method-previous-message",
11563 &Vinput_method_previous_message
,
11564 doc
: /* When `input-method-function' is called, hold the previous echo area message.
11565 This variable exists because `read-event' clears the echo area
11566 before running the input method. It is nil if there was no message. */);
11567 Vinput_method_previous_message
= Qnil
;
11569 DEFVAR_LISP ("show-help-function", &Vshow_help_function
,
11570 doc
: /* If non-nil, the function that implements the display of help.
11571 It's called with one argument, the help string to display. */);
11572 Vshow_help_function
= Qnil
;
11574 DEFVAR_LISP ("disable-point-adjustment", &Vdisable_point_adjustment
,
11575 doc
: /* If non-nil, suppress point adjustment after executing a command.
11577 After a command is executed, if point is moved into a region that has
11578 special properties (e.g. composition, display), we adjust point to
11579 the boundary of the region. But, when a command sets this variable to
11580 non-nil, we suppress the point adjustment.
11582 This variable is set to nil before reading a command, and is checked
11583 just after executing the command. */);
11584 Vdisable_point_adjustment
= Qnil
;
11586 DEFVAR_LISP ("global-disable-point-adjustment",
11587 &Vglobal_disable_point_adjustment
,
11588 doc
: /* *If non-nil, always suppress point adjustment.
11590 The default value is nil, in which case, point adjustment are
11591 suppressed only after special commands that set
11592 `disable-point-adjustment' (which see) to non-nil. */);
11593 Vglobal_disable_point_adjustment
= Qnil
;
11595 DEFVAR_LISP ("minibuffer-message-timeout", &Vminibuffer_message_timeout
,
11596 doc
: /* *How long to display an echo-area message when the minibuffer is active.
11597 If the value is not a number, such messages don't time out. */);
11598 Vminibuffer_message_timeout
= make_number (2);
11600 DEFVAR_LISP ("throw-on-input", &Vthrow_on_input
,
11601 doc
: /* If non-nil, any keyboard input throws to this symbol.
11602 The value of that variable is passed to `quit-flag' and later causes a
11603 peculiar kind of quitting. */);
11604 Vthrow_on_input
= Qnil
;
11606 DEFVAR_LISP ("command-error-function", &Vcommand_error_function
,
11607 doc
: /* If non-nil, function to output error messages.
11608 The arguments are the error data, a list of the form
11609 (SIGNALED-CONDITIONS . SIGNAL-DATA)
11610 such as just as `condition-case' would bind its variable to,
11611 the context (a string which normally goes at the start of the message),
11612 and the Lisp function within which the error was signaled. */);
11613 Vcommand_error_function
= Qnil
;
11615 DEFVAR_LISP ("enable-disabled-menus-and-buttons",
11616 &Venable_disabled_menus_and_buttons
,
11617 doc
: /* If non-nil, don't ignore events produced by disabled menu items and tool-bar.
11619 Help functions bind this to allow help on disabled menu items
11620 and tool-bar buttons. */);
11621 Venable_disabled_menus_and_buttons
= Qnil
;
11625 keys_of_keyboard ()
11627 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
11628 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
11629 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
11630 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
11631 initial_define_key (meta_map
, 'x', "execute-extended-command");
11633 initial_define_lispy_key (Vspecial_event_map
, "delete-frame",
11634 "handle-delete-frame");
11635 /* Here we used to use `ignore-event' which would simple set prefix-arg to
11636 current-prefix-arg, as is done in `handle-switch-frame'.
11637 But `handle-switch-frame is not run from the special-map.
11638 Commands from that map are run in a special way that automatically
11639 preserves the prefix-arg. Restoring the prefix arg here is not just
11640 redundant but harmful:
11642 - current-prefix-arg is set to non-nil, prefix-arg is set to nil.
11643 - after the first prompt, the exit-minibuffer-hook is run which may
11644 iconify a frame and thus push a `iconify-frame' event.
11645 - after running exit-minibuffer-hook, current-prefix-arg is
11646 restored to the non-nil value it had before the prompt.
11647 - we enter the second prompt.
11648 current-prefix-arg is non-nil, prefix-arg is nil.
11649 - before running the first real event, we run the special iconify-frame
11650 event, but we pass the `special' arg to execute-command so
11651 current-prefix-arg and prefix-arg are left untouched.
11652 - here we foolishly copy the non-nil current-prefix-arg to prefix-arg.
11653 - the next key event will have a spuriously non-nil current-prefix-arg. */
11654 initial_define_lispy_key (Vspecial_event_map
, "iconify-frame",
11656 initial_define_lispy_key (Vspecial_event_map
, "make-frame-visible",
11658 /* Handling it at such a low-level causes read_key_sequence to get
11659 * confused because it doesn't realize that the current_buffer was
11660 * changed by read_char.
11662 * initial_define_lispy_key (Vspecial_event_map, "select-window",
11663 * "handle-select-window"); */
11664 initial_define_lispy_key (Vspecial_event_map
, "save-session",
11665 "handle-save-session");
11668 /* Mark the pointers in the kboard objects.
11669 Called by the Fgarbage_collector. */
11675 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
11677 if (kb
->kbd_macro_buffer
)
11678 for (p
= kb
->kbd_macro_buffer
; p
< kb
->kbd_macro_ptr
; p
++)
11680 mark_object (kb
->Voverriding_terminal_local_map
);
11681 mark_object (kb
->Vlast_command
);
11682 mark_object (kb
->Vreal_last_command
);
11683 mark_object (kb
->Vprefix_arg
);
11684 mark_object (kb
->Vlast_prefix_arg
);
11685 mark_object (kb
->kbd_queue
);
11686 mark_object (kb
->defining_kbd_macro
);
11687 mark_object (kb
->Vlast_kbd_macro
);
11688 mark_object (kb
->Vsystem_key_alist
);
11689 mark_object (kb
->system_key_syms
);
11690 mark_object (kb
->Vdefault_minibuffer_frame
);
11691 mark_object (kb
->echo_string
);
11694 struct input_event
*event
;
11695 for (event
= kbd_fetch_ptr
; event
!= kbd_store_ptr
; event
++)
11697 if (event
== kbd_buffer
+ KBD_BUFFER_SIZE
)
11698 event
= kbd_buffer
;
11699 if (event
->kind
!= SELECTION_REQUEST_EVENT
11700 && event
->kind
!= SELECTION_CLEAR_EVENT
)
11702 mark_object (event
->x
);
11703 mark_object (event
->y
);
11705 mark_object (event
->frame_or_window
);
11706 mark_object (event
->arg
);
11711 /* arch-tag: 774e34d7-6d31-42f3-8397-e079a4e4c9ca
11712 (do not change this comment) */