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, 2007 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 3, or (at your option)
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
30 #include "termhooks.h"
38 #include "dispextern.h"
40 #include "intervals.h"
42 #include "blockinput.h"
49 #ifdef HAVE_GTK_AND_PTHREAD
57 #include <sys/ioctl.h>
59 #endif /* not MSDOS */
61 #include "syssignal.h"
63 #include <sys/types.h>
72 /* This is to get the definitions of the XK_ symbols. */
79 #endif /* HAVE_NTGUI */
89 /* Variables for blockinput.h: */
91 /* Non-zero if interrupt input is blocked right now. */
92 volatile int interrupt_input_blocked
;
94 /* Nonzero means an input interrupt has arrived
95 during the current critical section. */
96 int interrupt_input_pending
;
99 #ifdef HAVE_WINDOW_SYSTEM
100 /* Make all keyboard buffers much bigger when using X windows. */
102 /* But not too big (local data > 32K error) if on Mac OS Classic. */
103 #define KBD_BUFFER_SIZE 512
105 #define KBD_BUFFER_SIZE 4096
107 #else /* No X-windows, character input */
108 #define KBD_BUFFER_SIZE 4096
109 #endif /* No X-windows */
111 /* Following definition copied from eval.c */
115 struct backtrace
*next
;
116 Lisp_Object
*function
;
117 Lisp_Object
*args
; /* Points to vector of args. */
118 int nargs
; /* length of vector. If nargs is UNEVALLED,
119 args points to slot holding list of
122 /* Nonzero means call value of debugger when done with this operation. */
127 KBOARD
*initial_kboard
;
128 KBOARD
*current_kboard
;
132 KBOARD the_only_kboard
;
135 /* Non-nil disable property on a command means
136 do not execute it; call disabled-command-function's value instead. */
137 Lisp_Object Qdisabled
, Qdisabled_command_function
;
139 #define NUM_RECENT_KEYS (300)
140 int recent_keys_index
; /* Index for storing next element into recent_keys */
141 int total_keys
; /* Total number of elements stored into recent_keys */
142 Lisp_Object recent_keys
; /* Vector holds the last NUM_RECENT_KEYS keystrokes */
144 /* Vector holding the key sequence that invoked the current command.
145 It is reused for each command, and it may be longer than the current
146 sequence; this_command_key_count indicates how many elements
147 actually mean something.
148 It's easier to staticpro a single Lisp_Object than an array. */
149 Lisp_Object this_command_keys
;
150 int this_command_key_count
;
152 /* 1 after calling Freset_this_command_lengths.
154 int this_command_key_count_reset
;
156 /* This vector is used as a buffer to record the events that were actually read
157 by read_key_sequence. */
158 Lisp_Object raw_keybuf
;
159 int raw_keybuf_count
;
161 #define GROW_RAW_KEYBUF \
162 if (raw_keybuf_count == XVECTOR (raw_keybuf)->size) \
164 int newsize = 2 * XVECTOR (raw_keybuf)->size; \
166 new = Fmake_vector (make_number (newsize), Qnil); \
167 bcopy (XVECTOR (raw_keybuf)->contents, XVECTOR (new)->contents, \
168 raw_keybuf_count * sizeof (Lisp_Object)); \
172 /* Number of elements of this_command_keys
173 that precede this key sequence. */
174 int this_single_command_key_start
;
176 /* Record values of this_command_key_count and echo_length ()
177 before this command was read. */
178 static int before_command_key_count
;
179 static int before_command_echo_length
;
181 extern int minbuf_level
;
183 extern int message_enable_multibyte
;
185 extern struct backtrace
*backtrace_list
;
187 /* If non-nil, the function that implements the display of help.
188 It's called with one argument, the help string to display. */
190 Lisp_Object Vshow_help_function
;
192 /* If a string, the message displayed before displaying a help-echo
195 Lisp_Object Vpre_help_message
;
197 /* Nonzero means do menu prompting. */
199 static int menu_prompting
;
201 /* Character to see next line of menu prompt. */
203 static Lisp_Object menu_prompt_more_char
;
205 /* For longjmp to where kbd input is being done. */
207 static jmp_buf getcjmp
;
209 /* True while doing kbd input. */
210 int waiting_for_input
;
212 /* True while displaying for echoing. Delays C-g throwing. */
216 /* Non-null means we can start echoing at the next input pause even
217 though there is something in the echo area. */
219 static struct kboard
*ok_to_echo_at_next_pause
;
221 /* The kboard last echoing, or null for none. Reset to 0 in
222 cancel_echoing. If non-null, and a current echo area message
223 exists, and echo_message_buffer is eq to the current message
224 buffer, we know that the message comes from echo_kboard. */
226 struct kboard
*echo_kboard
;
228 /* The buffer used for echoing. Set in echo_now, reset in
231 Lisp_Object echo_message_buffer
;
233 /* Nonzero means disregard local maps for the menu bar. */
234 static int inhibit_local_menu_bar_menus
;
236 /* Nonzero means C-g should cause immediate error-signal. */
239 /* The user's hook function for outputting an error message. */
240 Lisp_Object Vcommand_error_function
;
242 /* The user's ERASE setting. */
243 Lisp_Object Vtty_erase_char
;
245 /* Character to recognize as the help char. */
246 Lisp_Object Vhelp_char
;
248 /* List of other event types to recognize as meaning "help". */
249 Lisp_Object Vhelp_event_list
;
251 /* Form to execute when help char is typed. */
252 Lisp_Object Vhelp_form
;
254 /* Command to run when the help character follows a prefix key. */
255 Lisp_Object Vprefix_help_command
;
257 /* List of items that should move to the end of the menu bar. */
258 Lisp_Object Vmenu_bar_final_items
;
260 /* Non-nil means show the equivalent key-binding for
261 any M-x command that has one.
262 The value can be a length of time to show the message for.
263 If the value is non-nil and not a number, we wait 2 seconds. */
264 Lisp_Object Vsuggest_key_bindings
;
266 /* How long to display an echo-area message when the minibuffer is active.
267 If the value is not a number, such messages don't time out. */
268 Lisp_Object Vminibuffer_message_timeout
;
270 /* Character that causes a quit. Normally C-g.
272 If we are running on an ordinary terminal, this must be an ordinary
273 ASCII char, since we want to make it our interrupt character.
275 If we are not running on an ordinary terminal, it still needs to be
276 an ordinary ASCII char. This character needs to be recognized in
277 the input interrupt handler. At this point, the keystroke is
278 represented as a struct input_event, while the desired quit
279 character is specified as a lispy event. The mapping from struct
280 input_events to lispy events cannot run in an interrupt handler,
281 and the reverse mapping is difficult for anything but ASCII
284 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
288 extern Lisp_Object current_global_map
;
289 extern int minibuf_level
;
291 /* If non-nil, this is a map that overrides all other local maps. */
292 Lisp_Object Voverriding_local_map
;
294 /* If non-nil, Voverriding_local_map applies to the menu bar. */
295 Lisp_Object Voverriding_local_map_menu_flag
;
297 /* Keymap that defines special misc events that should
298 be processed immediately at a low level. */
299 Lisp_Object Vspecial_event_map
;
301 /* Current depth in recursive edits. */
302 int command_loop_level
;
304 /* Total number of times command_loop has read a key sequence. */
305 EMACS_INT num_input_keys
;
307 /* Last input character read as a command. */
308 Lisp_Object last_command_char
;
310 /* Last input character read as a command, not counting menus
311 reached by the mouse. */
312 Lisp_Object last_nonmenu_event
;
314 /* Last input character read for any purpose. */
315 Lisp_Object last_input_char
;
317 /* If not Qnil, a list of objects to be read as subsequent command input. */
318 Lisp_Object Vunread_command_events
;
320 /* If not Qnil, a list of objects to be read as subsequent command input
321 including input method processing. */
322 Lisp_Object Vunread_input_method_events
;
324 /* If not Qnil, a list of objects to be read as subsequent command input
325 but NOT including input method processing. */
326 Lisp_Object Vunread_post_input_method_events
;
328 /* If not -1, an event to be read as subsequent command input. */
329 EMACS_INT unread_command_char
;
331 /* If not Qnil, this is a switch-frame event which we decided to put
332 off until the end of a key sequence. This should be read as the
333 next command input, after any unread_command_events.
335 read_key_sequence uses this to delay switch-frame events until the
336 end of the key sequence; Fread_char uses it to put off switch-frame
337 events until a non-ASCII event is acceptable as input. */
338 Lisp_Object unread_switch_frame
;
340 /* A mask of extra modifier bits to put into every keyboard char. */
341 EMACS_INT extra_keyboard_modifiers
;
343 /* Char to use as prefix when a meta character is typed in.
344 This is bound on entry to minibuffer in case ESC is changed there. */
346 Lisp_Object meta_prefix_char
;
348 /* Last size recorded for a current buffer which is not a minibuffer. */
349 static int last_non_minibuf_size
;
351 /* Number of idle seconds before an auto-save and garbage collection. */
352 static Lisp_Object Vauto_save_timeout
;
354 /* Total number of times read_char has returned. */
355 int num_input_events
;
357 /* Total number of times read_char has returned, outside of macros. */
358 EMACS_INT num_nonmacro_input_events
;
360 /* Auto-save automatically when this many characters have been typed
361 since the last time. */
363 static EMACS_INT auto_save_interval
;
365 /* Value of num_nonmacro_input_events as of last auto save. */
369 /* The command being executed by the command loop.
370 Commands may set this, and the value set will be copied into
371 current_kboard->Vlast_command instead of the actual command. */
372 Lisp_Object Vthis_command
;
374 /* This is like Vthis_command, except that commands never set it. */
375 Lisp_Object real_this_command
;
377 /* If the lookup of the command returns a binding, the original
378 command is stored in this-original-command. It is nil otherwise. */
379 Lisp_Object Vthis_original_command
;
381 /* The value of point when the last command was started. */
382 int last_point_position
;
384 /* The buffer that was current when the last command was started. */
385 Lisp_Object last_point_position_buffer
;
387 /* The window that was selected when the last command was started. */
388 Lisp_Object last_point_position_window
;
390 /* The frame in which the last input event occurred, or Qmacro if the
391 last event came from a macro. We use this to determine when to
392 generate switch-frame events. This may be cleared by functions
393 like Fselect_frame, to make sure that a switch-frame event is
394 generated by the next character. */
395 Lisp_Object internal_last_event_frame
;
397 /* A user-visible version of the above, intended to allow users to
398 figure out where the last event came from, if the event doesn't
399 carry that information itself (i.e. if it was a character). */
400 Lisp_Object Vlast_event_frame
;
402 /* The timestamp of the last input event we received from the X server.
403 X Windows wants this for selection ownership. */
404 unsigned long last_event_timestamp
;
406 Lisp_Object Qself_insert_command
;
407 Lisp_Object Qforward_char
;
408 Lisp_Object Qbackward_char
;
409 Lisp_Object Qundefined
;
410 Lisp_Object Qtimer_event_handler
;
412 /* read_key_sequence stores here the command definition of the
413 key sequence that it reads. */
414 Lisp_Object read_key_sequence_cmd
;
416 /* Echo unfinished commands after this many seconds of pause. */
417 Lisp_Object Vecho_keystrokes
;
419 /* Form to evaluate (if non-nil) when Emacs is started. */
420 Lisp_Object Vtop_level
;
422 /* If non-nil, this implements the current input method. */
423 Lisp_Object Vinput_method_function
;
424 Lisp_Object Qinput_method_function
;
426 /* When we call Vinput_method_function,
427 this holds the echo area message that was just erased. */
428 Lisp_Object Vinput_method_previous_message
;
430 /* Non-nil means deactivate the mark at end of this command. */
431 Lisp_Object Vdeactivate_mark
;
433 /* Menu bar specified in Lucid Emacs fashion. */
435 Lisp_Object Vlucid_menu_bar_dirty_flag
;
436 Lisp_Object Qrecompute_lucid_menubar
, Qactivate_menubar_hook
;
438 Lisp_Object Qecho_area_clear_hook
;
440 /* Hooks to run before and after each command. */
441 Lisp_Object Qpre_command_hook
, Vpre_command_hook
;
442 Lisp_Object Qpost_command_hook
, Vpost_command_hook
;
443 Lisp_Object Qcommand_hook_internal
, Vcommand_hook_internal
;
445 /* Parent keymap of terminal-local function-key-map instances. */
446 Lisp_Object Vfunction_key_map
;
448 /* Keymap of key translations that can override keymaps. */
449 Lisp_Object Vkey_translation_map
;
451 /* List of deferred actions to be performed at a later time.
452 The precise format isn't relevant here; we just check whether it is nil. */
453 Lisp_Object Vdeferred_action_list
;
455 /* Function to call to handle deferred actions, when there are any. */
456 Lisp_Object Vdeferred_action_function
;
457 Lisp_Object Qdeferred_action_function
;
459 Lisp_Object Qinput_method_exit_on_first_char
;
460 Lisp_Object Qinput_method_use_echo_area
;
462 /* File in which we write all commands we read. */
465 /* Nonzero if input is available. */
468 extern char *pending_malloc_warning
;
470 /* Circular buffer for pre-read keyboard input. */
472 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
474 /* Pointer to next available character in kbd_buffer.
475 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
476 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the
477 next available char is in kbd_buffer[0]. */
478 static struct input_event
*kbd_fetch_ptr
;
480 /* Pointer to next place to store character in kbd_buffer. This
481 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
482 character should go in kbd_buffer[0]. */
483 static struct input_event
* volatile kbd_store_ptr
;
485 /* The above pair of variables forms a "queue empty" flag. When we
486 enqueue a non-hook event, we increment kbd_store_ptr. When we
487 dequeue a non-hook event, we increment kbd_fetch_ptr. We say that
488 there is input available if the two pointers are not equal.
490 Why not just have a flag set and cleared by the enqueuing and
491 dequeuing functions? Such a flag could be screwed up by interrupts
492 at inopportune times. */
494 /* If this flag is non-nil, we check mouse_moved to see when the
495 mouse moves, and motion events will appear in the input stream.
496 Otherwise, mouse motion is ignored. */
497 Lisp_Object do_mouse_tracking
;
499 /* Symbols to head events. */
500 Lisp_Object Qmouse_movement
;
501 Lisp_Object Qscroll_bar_movement
;
502 Lisp_Object Qswitch_frame
;
503 Lisp_Object Qdelete_frame
;
504 Lisp_Object Qiconify_frame
;
505 Lisp_Object Qmake_frame_visible
;
506 Lisp_Object Qselect_window
;
507 Lisp_Object Qhelp_echo
;
509 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
510 Lisp_Object Qmouse_fixup_help_message
;
513 /* Symbols to denote kinds of events. */
514 Lisp_Object Qfunction_key
;
515 Lisp_Object Qmouse_click
;
516 #if defined (WINDOWSNT) || defined (MAC_OS)
517 Lisp_Object Qlanguage_change
;
519 Lisp_Object Qdrag_n_drop
;
520 Lisp_Object Qsave_session
;
522 Lisp_Object Qmac_apple_event
;
525 /* Lisp_Object Qmouse_movement; - also an event header */
527 /* Properties of event headers. */
528 Lisp_Object Qevent_kind
;
529 Lisp_Object Qevent_symbol_elements
;
531 /* menu item parts */
532 Lisp_Object Qmenu_alias
;
533 Lisp_Object Qmenu_enable
;
534 Lisp_Object QCenable
, QCvisible
, QChelp
, QCfilter
, QCkeys
, QCkey_sequence
;
535 Lisp_Object QCbutton
, QCtoggle
, QCradio
;
536 extern Lisp_Object Vdefine_key_rebound_commands
;
537 extern Lisp_Object Qmenu_item
;
539 /* An event header symbol HEAD may have a property named
540 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
541 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
542 mask of modifiers applied to it. If present, this is used to help
543 speed up parse_modifiers. */
544 Lisp_Object Qevent_symbol_element_mask
;
546 /* An unmodified event header BASE may have a property named
547 Qmodifier_cache, which is an alist mapping modifier masks onto
548 modified versions of BASE. If present, this helps speed up
550 Lisp_Object Qmodifier_cache
;
552 /* Symbols to use for parts of windows. */
553 Lisp_Object Qmode_line
;
554 Lisp_Object Qvertical_line
;
555 Lisp_Object Qvertical_scroll_bar
;
556 Lisp_Object Qmenu_bar
;
557 extern Lisp_Object Qleft_margin
, Qright_margin
;
558 extern Lisp_Object Qleft_fringe
, Qright_fringe
;
559 extern Lisp_Object QCmap
;
561 Lisp_Object
recursive_edit_unwind (), command_loop ();
562 Lisp_Object
Fthis_command_keys ();
563 Lisp_Object Qextended_command_history
;
564 EMACS_TIME
timer_check ();
566 extern Lisp_Object Vhistory_length
, Vtranslation_table_for_input
;
568 extern char *x_get_keysym_name ();
570 static void record_menu_key ();
571 static int echo_length ();
573 Lisp_Object Qpolling_period
;
575 /* List of absolute timers. Appears in order of next scheduled event. */
576 Lisp_Object Vtimer_list
;
578 /* List of idle time timers. Appears in order of next scheduled event. */
579 Lisp_Object Vtimer_idle_list
;
581 /* Incremented whenever a timer is run. */
584 extern Lisp_Object Vprint_level
, Vprint_length
;
586 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
588 EMACS_TIME
*input_available_clear_time
;
590 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
591 Default is 1 if INTERRUPT_INPUT is defined. */
594 /* Nonzero while interrupts are temporarily deferred during redisplay. */
595 int interrupts_deferred
;
597 /* Allow m- file to inhibit use of FIONREAD. */
598 #ifdef BROKEN_FIONREAD
602 /* We are unable to use interrupts if FIONREAD is not available,
603 so flush SIGIO so we won't try. */
604 #if !defined (FIONREAD)
610 /* If we support a window system, turn on the code to poll periodically
611 to detect C-g. It isn't actually used when doing interrupt input. */
612 #if defined(HAVE_WINDOW_SYSTEM) && !defined(USE_ASYNC_EVENTS)
613 #define POLL_FOR_INPUT
616 /* After a command is executed, if point is moved into a region that
617 has specific properties (e.g. composition, display), we adjust
618 point to the boundary of the region. But, if a command sets this
619 variable to non-nil, we suppress this point adjustment. This
620 variable is set to nil before reading a command. */
622 Lisp_Object Vdisable_point_adjustment
;
624 /* If non-nil, always disable point adjustment. */
626 Lisp_Object Vglobal_disable_point_adjustment
;
628 /* The time when Emacs started being idle. */
630 static EMACS_TIME timer_idleness_start_time
;
632 /* After Emacs stops being idle, this saves the last value
633 of timer_idleness_start_time from when it was idle. */
635 static EMACS_TIME timer_last_idleness_start_time
;
637 /* If non-nil, events produced by disabled menu items and tool-bar
638 buttons are not ignored. Help functions bind this to allow help on
639 those items and buttons. */
640 Lisp_Object Venable_disabled_menus_and_buttons
;
643 /* Global variable declarations. */
645 /* Flags for readable_events. */
646 #define READABLE_EVENTS_DO_TIMERS_NOW (1 << 0)
647 #define READABLE_EVENTS_FILTER_EVENTS (1 << 1)
648 #define READABLE_EVENTS_IGNORE_SQUEEZABLES (1 << 2)
650 /* Function for init_keyboard to call with no args (if nonzero). */
651 void (*keyboard_init_hook
) ();
653 static int read_avail_input
P_ ((int));
654 static void get_input_pending
P_ ((int *, int));
655 static int readable_events
P_ ((int));
656 static Lisp_Object read_char_x_menu_prompt
P_ ((int, Lisp_Object
*,
657 Lisp_Object
, int *));
658 static Lisp_Object
read_char_x_menu_prompt ();
659 static Lisp_Object read_char_minibuf_menu_prompt
P_ ((int, int,
661 static Lisp_Object make_lispy_event
P_ ((struct input_event
*));
662 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
663 static Lisp_Object make_lispy_movement
P_ ((struct frame
*, Lisp_Object
,
664 enum scroll_bar_part
,
665 Lisp_Object
, Lisp_Object
,
668 static Lisp_Object modify_event_symbol
P_ ((int, unsigned, Lisp_Object
,
669 Lisp_Object
, char **,
670 Lisp_Object
*, unsigned));
671 static Lisp_Object make_lispy_switch_frame
P_ ((Lisp_Object
));
672 static int parse_solitary_modifier
P_ ((Lisp_Object
));
673 static int parse_solitary_modifier ();
674 static void save_getcjmp
P_ ((jmp_buf));
675 static void save_getcjmp ();
676 static void restore_getcjmp
P_ ((jmp_buf));
677 static Lisp_Object apply_modifiers
P_ ((int, Lisp_Object
));
678 static void clear_event
P_ ((struct input_event
*));
680 static Lisp_Object restore_kboard_configuration
P_ ((Lisp_Object
));
682 static SIGTYPE interrupt_signal
P_ ((int signalnum
));
683 static void handle_interrupt
P_ ((void));
684 static void timer_start_idle
P_ ((void));
685 static void timer_stop_idle
P_ ((void));
686 static void timer_resume_idle
P_ ((void));
687 static SIGTYPE handle_user_signal
P_ ((int));
688 static char *find_user_signal_name
P_ ((int));
689 static int store_user_signal_events
P_ ((void));
691 /* Nonzero means don't try to suspend even if the operating system seems
693 static int cannot_suspend
;
695 extern Lisp_Object Qidentity
, Qonly
;
697 /* Install the string STR as the beginning of the string of echoing,
698 so that it serves as a prompt for the next character.
699 Also start echoing. */
705 current_kboard
->echo_string
= str
;
706 current_kboard
->echo_after_prompt
= SCHARS (str
);
710 /* Add C to the echo string, if echoing is going on.
711 C can be a character, which is printed prettily ("M-C-x" and all that
712 jazz), or a symbol, whose name is printed. */
718 if (current_kboard
->immediate_echo
)
720 int size
= KEY_DESCRIPTION_SIZE
+ 100;
721 char *buffer
= (char *) alloca (size
);
723 Lisp_Object echo_string
;
725 echo_string
= current_kboard
->echo_string
;
727 /* If someone has passed us a composite event, use its head symbol. */
732 ptr
= push_key_description (XINT (c
), ptr
, 1);
734 else if (SYMBOLP (c
))
736 Lisp_Object name
= SYMBOL_NAME (c
);
737 int nbytes
= SBYTES (name
);
739 if (size
- (ptr
- buffer
) < nbytes
)
741 int offset
= ptr
- buffer
;
742 size
= max (2 * size
, size
+ nbytes
);
743 buffer
= (char *) alloca (size
);
744 ptr
= buffer
+ offset
;
747 ptr
+= copy_text (SDATA (name
), ptr
, nbytes
,
748 STRING_MULTIBYTE (name
), 1);
751 if ((NILP (echo_string
) || SCHARS (echo_string
) == 0)
754 const char *text
= " (Type ? for further options)";
755 int len
= strlen (text
);
757 if (size
- (ptr
- buffer
) < len
)
759 int offset
= ptr
- buffer
;
761 buffer
= (char *) alloca (size
);
762 ptr
= buffer
+ offset
;
765 bcopy (text
, ptr
, len
);
769 /* Replace a dash from echo_dash with a space, otherwise
770 add a space at the end as a separator between keys. */
771 if (STRINGP (echo_string
)
772 && SCHARS (echo_string
) > 1)
774 Lisp_Object last_char
, prev_char
, idx
;
776 idx
= make_number (SCHARS (echo_string
) - 2);
777 prev_char
= Faref (echo_string
, idx
);
779 idx
= make_number (SCHARS (echo_string
) - 1);
780 last_char
= Faref (echo_string
, idx
);
782 /* We test PREV_CHAR to make sure this isn't the echoing
784 if (XINT (last_char
) == '-' && XINT (prev_char
) != ' ')
785 Faset (echo_string
, idx
, make_number (' '));
787 echo_string
= concat2 (echo_string
, build_string (" "));
789 else if (STRINGP (echo_string
))
790 echo_string
= concat2 (echo_string
, build_string (" "));
792 current_kboard
->echo_string
793 = concat2 (echo_string
, make_string (buffer
, ptr
- buffer
));
799 /* Temporarily add a dash to the end of the echo string if it's not
800 empty, so that it serves as a mini-prompt for the very next character. */
805 /* Do nothing if not echoing at all. */
806 if (NILP (current_kboard
->echo_string
))
809 if (!current_kboard
->immediate_echo
810 && SCHARS (current_kboard
->echo_string
) == 0)
813 /* Do nothing if we just printed a prompt. */
814 if (current_kboard
->echo_after_prompt
815 == SCHARS (current_kboard
->echo_string
))
818 /* Do nothing if we have already put a dash at the end. */
819 if (SCHARS (current_kboard
->echo_string
) > 1)
821 Lisp_Object last_char
, prev_char
, idx
;
823 idx
= make_number (SCHARS (current_kboard
->echo_string
) - 2);
824 prev_char
= Faref (current_kboard
->echo_string
, idx
);
826 idx
= make_number (SCHARS (current_kboard
->echo_string
) - 1);
827 last_char
= Faref (current_kboard
->echo_string
, idx
);
829 if (XINT (last_char
) == '-' && XINT (prev_char
) != ' ')
833 /* Put a dash at the end of the buffer temporarily,
834 but make it go away when the next character is added. */
835 current_kboard
->echo_string
= concat2 (current_kboard
->echo_string
,
840 /* Display the current echo string, and begin echoing if not already
846 if (!current_kboard
->immediate_echo
)
849 current_kboard
->immediate_echo
= 1;
851 for (i
= 0; i
< this_command_key_count
; i
++)
855 /* Set before_command_echo_length to the value that would
856 have been saved before the start of this subcommand in
857 command_loop_1, if we had already been echoing then. */
858 if (i
== this_single_command_key_start
)
859 before_command_echo_length
= echo_length ();
861 c
= XVECTOR (this_command_keys
)->contents
[i
];
862 if (! (EVENT_HAS_PARAMETERS (c
)
863 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
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 (this_command_key_count
== this_single_command_key_start
)
871 before_command_echo_length
= echo_length ();
873 /* Put a dash at the end to invite the user to type more. */
878 message3_nolog (current_kboard
->echo_string
,
879 SBYTES (current_kboard
->echo_string
),
880 STRING_MULTIBYTE (current_kboard
->echo_string
));
883 /* Record in what buffer we echoed, and from which kboard. */
884 echo_message_buffer
= echo_area_buffer
[0];
885 echo_kboard
= current_kboard
;
887 if (waiting_for_input
&& !NILP (Vquit_flag
))
888 quit_throw_to_read_char ();
891 /* Turn off echoing, for the start of a new command. */
896 current_kboard
->immediate_echo
= 0;
897 current_kboard
->echo_after_prompt
= -1;
898 current_kboard
->echo_string
= Qnil
;
899 ok_to_echo_at_next_pause
= NULL
;
901 echo_message_buffer
= Qnil
;
904 /* Return the length of the current echo string. */
909 return (STRINGP (current_kboard
->echo_string
)
910 ? SCHARS (current_kboard
->echo_string
)
914 /* Truncate the current echo message to its first LEN chars.
915 This and echo_char get used by read_key_sequence when the user
916 switches frames while entering a key sequence. */
919 echo_truncate (nchars
)
922 if (STRINGP (current_kboard
->echo_string
))
923 current_kboard
->echo_string
924 = Fsubstring (current_kboard
->echo_string
,
925 make_number (0), make_number (nchars
));
926 truncate_echo_area (nchars
);
930 /* Functions for manipulating this_command_keys. */
932 add_command_key (key
)
935 #if 0 /* Not needed after we made Freset_this_command_lengths
936 do the job immediately. */
937 /* If reset-this-command-length was called recently, obey it now.
938 See the doc string of that function for an explanation of why. */
939 if (before_command_restore_flag
)
941 this_command_key_count
= before_command_key_count_1
;
942 if (this_command_key_count
< this_single_command_key_start
)
943 this_single_command_key_start
= this_command_key_count
;
944 echo_truncate (before_command_echo_length_1
);
945 before_command_restore_flag
= 0;
949 if (this_command_key_count
>= ASIZE (this_command_keys
))
950 this_command_keys
= larger_vector (this_command_keys
,
951 2 * ASIZE (this_command_keys
),
954 AREF (this_command_keys
, this_command_key_count
) = key
;
955 ++this_command_key_count
;
962 int count
= SPECPDL_INDEX ();
965 if (command_loop_level
> 0)
967 specbind (Qstandard_output
, Qt
);
968 specbind (Qstandard_input
, Qt
);
971 #ifdef HAVE_X_WINDOWS
972 /* The command loop has started an hourglass timer, so we have to
973 cancel it here, otherwise it will fire because the recursive edit
974 can take some time. Do not check for display_hourglass_p here,
975 because it could already be nil. */
979 /* This function may have been called from a debugger called from
980 within redisplay, for instance by Edebugging a function called
981 from fontification-functions. We want to allow redisplay in
982 the debugging session.
984 The recursive edit is left with a `(throw exit ...)'. The `exit'
985 tag is not caught anywhere in redisplay, i.e. when we leave the
986 recursive edit, the original redisplay leading to the recursive
987 edit will be unwound. The outcome should therefore be safe. */
988 specbind (Qinhibit_redisplay
, Qnil
);
991 val
= command_loop ();
993 Fsignal (Qquit
, Qnil
);
994 /* Handle throw from read_minibuf when using minibuffer
995 while it's active but we're in another window. */
997 xsignal1 (Qerror
, val
);
999 return unbind_to (count
, Qnil
);
1002 /* When an auto-save happens, record the "time", and don't do again soon. */
1007 last_auto_save
= num_nonmacro_input_events
;
1010 /* Make an auto save happen as soon as possible at command level. */
1013 force_auto_save_soon ()
1015 last_auto_save
= - auto_save_interval
- 1;
1017 record_asynch_buffer_change ();
1020 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
1021 doc
: /* Invoke the editor command loop recursively.
1022 To get out of the recursive edit, a command can do `(throw 'exit nil)';
1023 that tells this function to return.
1024 Alternatively, `(throw 'exit t)' makes this function signal an error.
1025 This function is called by the editor initialization to begin editing. */)
1028 int count
= SPECPDL_INDEX ();
1031 /* If we enter while input is blocked, don't lock up here.
1032 This may happen through the debugger during redisplay. */
1033 if (INPUT_BLOCKED_P
)
1036 command_loop_level
++;
1037 update_mode_lines
= 1;
1039 if (command_loop_level
1040 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
1041 buffer
= Fcurrent_buffer ();
1045 /* If we leave recursive_edit_1 below with a `throw' for instance,
1046 like it is done in the splash screen display, we have to
1047 make sure that we restore single_kboard as command_loop_1
1048 would have done if it were left normally. */
1049 if (command_loop_level
> 0)
1050 temporarily_switch_to_single_kboard (SELECTED_FRAME ());
1051 record_unwind_protect (recursive_edit_unwind
, buffer
);
1053 recursive_edit_1 ();
1054 return unbind_to (count
, Qnil
);
1058 recursive_edit_unwind (buffer
)
1061 if (BUFFERP (buffer
))
1062 Fset_buffer (buffer
);
1064 command_loop_level
--;
1065 update_mode_lines
= 1;
1070 #if 0 /* These two functions are now replaced with
1071 temporarily_switch_to_single_kboard. */
1076 #if 0 /* Theory: if there's anything in Vunread_command_events,
1077 it will right away be read by read_key_sequence,
1078 and then if we do switch KBOARDS, it will go into the side
1079 queue then. So we don't need to do anything special here -- rms. */
1080 if (CONSP (Vunread_command_events
))
1082 current_kboard
->kbd_queue
1083 = nconc2 (Vunread_command_events
, current_kboard
->kbd_queue
);
1084 current_kboard
->kbd_queue_has_data
= 1;
1086 Vunread_command_events
= Qnil
;
1092 /* Switch to the single-kboard state, making current_kboard
1093 the only KBOARD from which further input is accepted. */
1096 single_kboard_state ()
1104 /* If we're in single_kboard state for kboard KBOARD,
1108 not_single_kboard_state (kboard
)
1112 if (kboard
== current_kboard
)
1117 /* Maintain a stack of kboards, so other parts of Emacs
1118 can switch temporarily to the kboard of a given frame
1119 and then revert to the previous status. */
1124 struct kboard_stack
*next
;
1127 static struct kboard_stack
*kboard_stack
;
1134 struct kboard_stack
*p
1135 = (struct kboard_stack
*) xmalloc (sizeof (struct kboard_stack
));
1137 p
->next
= kboard_stack
;
1138 p
->kboard
= current_kboard
;
1150 struct kboard_stack
*p
= kboard_stack
;
1152 for (t
= terminal_list
; t
; t
= t
->next_terminal
)
1154 if (t
->kboard
== p
->kboard
)
1156 current_kboard
= p
->kboard
;
1163 /* The terminal we remembered has been deleted. */
1164 current_kboard
= FRAME_KBOARD (SELECTED_FRAME ());
1167 kboard_stack
= p
->next
;
1172 /* Switch to single_kboard mode, making current_kboard the only KBOARD
1173 from which further input is accepted. If F is non-nil, set its
1174 KBOARD as the current keyboard.
1176 This function uses record_unwind_protect to return to the previous
1179 If Emacs is already in single_kboard mode, and F's keyboard is
1180 locked, then this function will throw an errow. */
1183 temporarily_switch_to_single_kboard (f
)
1187 int was_locked
= single_kboard
;
1190 if (f
!= NULL
&& FRAME_KBOARD (f
) != current_kboard
)
1191 /* We can not switch keyboards while in single_kboard mode.
1192 In rare cases, Lisp code may call `recursive-edit' (or
1193 `read-minibuffer' or `y-or-n-p') after it switched to a
1194 locked frame. For example, this is likely to happen
1195 when server.el connects to a new terminal while Emacs is in
1196 single_kboard mode. It is best to throw an error instead
1197 of presenting the user with a frozen screen. */
1198 error ("Terminal %d is locked, cannot read from it",
1199 FRAME_TERMINAL (f
)->id
);
1201 /* This call is unnecessary, but helps
1202 `restore_kboard_configuration' discover if somebody changed
1203 `current_kboard' behind our back. */
1204 push_kboard (current_kboard
);
1207 current_kboard
= FRAME_KBOARD (f
);
1209 record_unwind_protect (restore_kboard_configuration
,
1210 (was_locked
? Qt
: Qnil
));
1214 #if 0 /* This function is not needed anymore. */
1216 record_single_kboard_state ()
1219 push_kboard (current_kboard
);
1220 record_unwind_protect (restore_kboard_configuration
,
1221 (single_kboard
? Qt
: Qnil
));
1227 restore_kboard_configuration (was_locked
)
1228 Lisp_Object was_locked
;
1230 if (NILP (was_locked
))
1234 struct kboard
*prev
= current_kboard
;
1237 /* The pop should not change the kboard. */
1238 if (single_kboard
&& current_kboard
!= prev
)
1246 /* Handle errors that are not handled at inner levels
1247 by printing an error message and returning to the editor command loop. */
1253 Lisp_Object old_level
, old_length
;
1254 char macroerror
[50];
1256 #ifdef HAVE_X_WINDOWS
1257 if (display_hourglass_p
)
1258 cancel_hourglass ();
1261 if (!NILP (executing_kbd_macro
))
1263 if (executing_kbd_macro_iterations
== 1)
1264 sprintf (macroerror
, "After 1 kbd macro iteration: ");
1266 sprintf (macroerror
, "After %d kbd macro iterations: ",
1267 executing_kbd_macro_iterations
);
1272 Vstandard_output
= Qt
;
1273 Vstandard_input
= Qt
;
1274 Vexecuting_kbd_macro
= Qnil
;
1275 executing_kbd_macro
= Qnil
;
1276 current_kboard
->Vprefix_arg
= Qnil
;
1277 current_kboard
->Vlast_prefix_arg
= Qnil
;
1280 /* Avoid unquittable loop if data contains a circular list. */
1281 old_level
= Vprint_level
;
1282 old_length
= Vprint_length
;
1283 XSETFASTINT (Vprint_level
, 10);
1284 XSETFASTINT (Vprint_length
, 10);
1285 cmd_error_internal (data
, macroerror
);
1286 Vprint_level
= old_level
;
1287 Vprint_length
= old_length
;
1291 Vinhibit_quit
= Qnil
;
1292 #if 0 /* This shouldn't be necessary anymore. --lorentey */
1294 if (command_loop_level
== 0 && minibuf_level
== 0)
1295 any_kboard_state ();
1299 return make_number (0);
1302 /* Take actions on handling an error. DATA is the data that describes
1305 CONTEXT is a C-string containing ASCII characters only which
1306 describes the context in which the error happened. If we need to
1307 generalize CONTEXT to allow multibyte characters, make it a Lisp
1311 cmd_error_internal (data
, context
)
1315 struct frame
*sf
= SELECTED_FRAME ();
1317 /* The immediate context is not interesting for Quits,
1318 since they are asyncronous. */
1319 if (EQ (XCAR (data
), Qquit
))
1320 Vsignaling_function
= Qnil
;
1325 /* Use user's specified output function if any. */
1326 if (!NILP (Vcommand_error_function
))
1327 call3 (Vcommand_error_function
, data
,
1328 context
? build_string (context
) : empty_unibyte_string
,
1329 Vsignaling_function
);
1330 /* If the window system or terminal frame hasn't been initialized
1331 yet, or we're not interactive, write the message to stderr and exit. */
1332 else if (!sf
->glyphs_initialized_p
1333 || FRAME_INITIAL_P (sf
)
1336 print_error_message (data
, Qexternal_debugging_output
,
1337 context
, Vsignaling_function
);
1338 Fterpri (Qexternal_debugging_output
);
1339 Fkill_emacs (make_number (-1));
1343 clear_message (1, 0);
1345 message_log_maybe_newline ();
1348 print_error_message (data
, Qt
, context
, Vsignaling_function
);
1351 Vsignaling_function
= Qnil
;
1354 Lisp_Object
command_loop_1 ();
1355 Lisp_Object
command_loop_2 ();
1356 Lisp_Object
top_level_1 ();
1358 /* Entry to editor-command-loop.
1359 This level has the catches for exiting/returning to editor command loop.
1360 It returns nil to exit recursive edit, t to abort it. */
1365 if (command_loop_level
> 0 || minibuf_level
> 0)
1368 val
= internal_catch (Qexit
, command_loop_2
, Qnil
);
1369 executing_kbd_macro
= Qnil
;
1375 internal_catch (Qtop_level
, top_level_1
, Qnil
);
1376 #if 0 /* This shouldn't be necessary anymore. --lorentey */
1377 /* Reset single_kboard in case top-level set it while
1378 evaluating an -f option, or we are stuck there for some
1380 any_kboard_state ();
1382 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
1383 executing_kbd_macro
= Qnil
;
1385 /* End of file in -batch run causes exit here. */
1391 /* Here we catch errors in execution of commands within the
1392 editing loop, and reenter the editing loop.
1393 When there is an error, cmd_error runs and returns a non-nil
1394 value to us. A value of nil means that command_loop_1 itself
1395 returned due to end of file (or end of kbd macro). */
1400 register Lisp_Object val
;
1403 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
1404 while (!NILP (val
));
1412 return Feval (Vtop_level
);
1418 /* On entry to the outer level, run the startup file */
1419 if (!NILP (Vtop_level
))
1420 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
1421 else if (!NILP (Vpurify_flag
))
1422 message ("Bare impure Emacs (standard Lisp code not loaded)");
1424 message ("Bare Emacs (standard Lisp code not loaded)");
1428 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
1429 doc
: /* Exit all recursive editing levels. */)
1432 #ifdef HAVE_X_WINDOWS
1433 if (display_hourglass_p
)
1434 cancel_hourglass ();
1437 /* Unblock input if we enter with input blocked. This may happen if
1438 redisplay traps e.g. during tool-bar update with input blocked. */
1439 while (INPUT_BLOCKED_P
)
1442 return Fthrow (Qtop_level
, Qnil
);
1445 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
1446 doc
: /* Exit from the innermost recursive edit or minibuffer. */)
1449 if (command_loop_level
> 0 || minibuf_level
> 0)
1450 Fthrow (Qexit
, Qnil
);
1452 error ("No recursive edit is in progress");
1456 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
1457 doc
: /* Abort the command that requested this recursive edit or minibuffer input. */)
1460 if (command_loop_level
> 0 || minibuf_level
> 0)
1463 error ("No recursive edit is in progress");
1467 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1469 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
1470 of this function. */
1473 tracking_off (old_value
)
1474 Lisp_Object old_value
;
1476 do_mouse_tracking
= old_value
;
1477 if (NILP (old_value
))
1479 /* Redisplay may have been preempted because there was input
1480 available, and it assumes it will be called again after the
1481 input has been processed. If the only input available was
1482 the sort that we have just disabled, then we need to call
1484 if (!readable_events (READABLE_EVENTS_DO_TIMERS_NOW
))
1486 redisplay_preserve_echo_area (6);
1487 get_input_pending (&input_pending
,
1488 READABLE_EVENTS_DO_TIMERS_NOW
);
1494 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
1495 doc
: /* Evaluate BODY with mouse movement events enabled.
1496 Within a `track-mouse' form, mouse motion generates input events that
1497 you can read with `read-event'.
1498 Normally, mouse motion is ignored.
1499 usage: (track-mouse BODY...) */)
1503 int count
= SPECPDL_INDEX ();
1506 record_unwind_protect (tracking_off
, do_mouse_tracking
);
1508 do_mouse_tracking
= Qt
;
1510 val
= Fprogn (args
);
1511 return unbind_to (count
, val
);
1514 /* If mouse has moved on some frame, return one of those frames.
1518 If ignore_mouse_drag_p is non-zero, ignore (implicit) mouse movement
1519 after resizing the tool-bar window. */
1521 int ignore_mouse_drag_p
;
1526 Lisp_Object tail
, frame
;
1528 if (ignore_mouse_drag_p
)
1530 /* ignore_mouse_drag_p = 0; */
1534 FOR_EACH_FRAME (tail
, frame
)
1536 if (XFRAME (frame
)->mouse_moved
)
1537 return XFRAME (frame
);
1543 #endif /* HAVE_MOUSE || HAVE_GPM */
1545 /* This is the actual command reading loop,
1546 sans error-handling encapsulation. */
1548 static int read_key_sequence
P_ ((Lisp_Object
*, int, Lisp_Object
,
1550 void safe_run_hooks
P_ ((Lisp_Object
));
1551 static void adjust_point_for_property
P_ ((int, int));
1553 /* Cancel hourglass from protect_unwind.
1555 #ifdef HAVE_X_WINDOWS
1557 cancel_hourglass_unwind (arg
)
1560 cancel_hourglass ();
1571 Lisp_Object keybuf
[30];
1574 int prev_modiff
= 0;
1575 struct buffer
*prev_buffer
= NULL
;
1576 #if 0 /* This shouldn't be necessary anymore. --lorentey */
1578 int was_locked
= single_kboard
;
1581 int already_adjusted
= 0;
1583 current_kboard
->Vprefix_arg
= Qnil
;
1584 current_kboard
->Vlast_prefix_arg
= Qnil
;
1585 Vdeactivate_mark
= Qnil
;
1586 waiting_for_input
= 0;
1590 this_command_key_count
= 0;
1591 this_command_key_count_reset
= 0;
1592 this_single_command_key_start
= 0;
1594 if (NILP (Vmemory_full
))
1596 /* Make sure this hook runs after commands that get errors and
1597 throw to top level. */
1598 /* Note that the value cell will never directly contain nil
1599 if the symbol is a local variable. */
1600 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1601 safe_run_hooks (Qpost_command_hook
);
1603 /* If displaying a message, resize the echo area window to fit
1604 that message's size exactly. */
1605 if (!NILP (echo_area_buffer
[0]))
1606 resize_echo_area_exactly ();
1608 if (!NILP (Vdeferred_action_list
))
1609 safe_run_hooks (Qdeferred_action_function
);
1612 /* Do this after running Vpost_command_hook, for consistency. */
1613 current_kboard
->Vlast_command
= Vthis_command
;
1614 current_kboard
->Vreal_last_command
= real_this_command
;
1615 if (!CONSP (last_command_char
))
1616 current_kboard
->Vlast_repeatable_command
= real_this_command
;
1620 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
1623 /* Make sure the current window's buffer is selected. */
1624 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1625 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1627 /* Display any malloc warning that just came out. Use while because
1628 displaying one warning can cause another. */
1630 while (pending_malloc_warning
)
1631 display_malloc_warning ();
1635 Vdeactivate_mark
= Qnil
;
1637 /* If minibuffer on and echo area in use,
1638 wait a short time and redraw minibuffer. */
1641 && !NILP (echo_area_buffer
[0])
1642 && EQ (minibuf_window
, echo_area_window
))
1644 /* Bind inhibit-quit to t so that C-g gets read in
1645 rather than quitting back to the minibuffer. */
1646 int count
= SPECPDL_INDEX ();
1647 specbind (Qinhibit_quit
, Qt
);
1649 if (NUMBERP (Vminibuffer_message_timeout
))
1650 sit_for (Vminibuffer_message_timeout
, 0, 2);
1654 /* Clear the echo area. */
1656 safe_run_hooks (Qecho_area_clear_hook
);
1658 unbind_to (count
, Qnil
);
1660 /* If a C-g came in before, treat it as input now. */
1661 if (!NILP (Vquit_flag
))
1664 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1669 /* Select the frame that the last event came from. Usually,
1670 switch-frame events will take care of this, but if some lisp
1671 code swallows a switch-frame event, we'll fix things up here.
1672 Is this a good idea? */
1673 if (FRAMEP (internal_last_event_frame
)
1674 && !EQ (internal_last_event_frame
, selected_frame
))
1675 Fselect_frame (internal_last_event_frame
);
1677 /* If it has changed current-menubar from previous value,
1678 really recompute the menubar from the value. */
1679 if (! NILP (Vlucid_menu_bar_dirty_flag
)
1680 && !NILP (Ffboundp (Qrecompute_lucid_menubar
)))
1681 call0 (Qrecompute_lucid_menubar
);
1683 before_command_key_count
= this_command_key_count
;
1684 before_command_echo_length
= echo_length ();
1686 Vthis_command
= Qnil
;
1687 real_this_command
= Qnil
;
1688 Vthis_original_command
= Qnil
;
1690 /* Read next key sequence; i gets its length. */
1691 i
= read_key_sequence (keybuf
, sizeof keybuf
/ sizeof keybuf
[0],
1694 /* A filter may have run while we were reading the input. */
1695 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
1697 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1698 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1702 /* Now we have read a key sequence of length I,
1703 or else I is 0 and we found end of file. */
1705 if (i
== 0) /* End of file -- happens only in */
1706 return Qnil
; /* a kbd macro, at the end. */
1707 /* -1 means read_key_sequence got a menu that was rejected.
1708 Just loop around and read another command. */
1712 this_command_key_count
= 0;
1713 this_command_key_count_reset
= 0;
1714 this_single_command_key_start
= 0;
1718 last_command_char
= keybuf
[i
- 1];
1720 /* If the previous command tried to force a specific window-start,
1721 forget about that, in case this command moves point far away
1722 from that position. But also throw away beg_unchanged and
1723 end_unchanged information in that case, so that redisplay will
1724 update the whole window properly. */
1725 if (!NILP (XWINDOW (selected_window
)->force_start
))
1728 XWINDOW (selected_window
)->force_start
= Qnil
;
1729 b
= XBUFFER (XWINDOW (selected_window
)->buffer
);
1730 BUF_BEG_UNCHANGED (b
) = BUF_END_UNCHANGED (b
) = 0;
1733 cmd
= read_key_sequence_cmd
;
1734 if (!NILP (Vexecuting_kbd_macro
))
1736 if (!NILP (Vquit_flag
))
1738 Vexecuting_kbd_macro
= Qt
;
1739 QUIT
; /* Make some noise. */
1740 /* Will return since macro now empty. */
1744 /* Do redisplay processing after this command except in special
1745 cases identified below. */
1746 prev_buffer
= current_buffer
;
1747 prev_modiff
= MODIFF
;
1748 last_point_position
= PT
;
1749 last_point_position_window
= selected_window
;
1750 XSETBUFFER (last_point_position_buffer
, prev_buffer
);
1752 /* By default, we adjust point to a boundary of a region that
1753 has such a property that should be treated intangible
1754 (e.g. composition, display). But, some commands will set
1755 this variable differently. */
1756 Vdisable_point_adjustment
= Qnil
;
1758 /* Process filters and timers may have messed with deactivate-mark.
1759 reset it before we execute the command. */
1760 Vdeactivate_mark
= Qnil
;
1762 /* Remap command through active keymaps */
1763 Vthis_original_command
= cmd
;
1767 if (cmd1
= Fcommand_remapping (cmd
, Qnil
, Qnil
), !NILP (cmd1
))
1771 /* Execute the command. */
1773 Vthis_command
= cmd
;
1774 real_this_command
= cmd
;
1775 /* Note that the value cell will never directly contain nil
1776 if the symbol is a local variable. */
1777 if (!NILP (Vpre_command_hook
) && !NILP (Vrun_hooks
))
1778 safe_run_hooks (Qpre_command_hook
);
1780 already_adjusted
= 0;
1782 if (NILP (Vthis_command
))
1784 /* nil means key is undefined. */
1785 Lisp_Object keys
= Fvector (i
, keybuf
);
1786 keys
= Fkey_description (keys
, Qnil
);
1788 message_with_string ("%s is undefined", keys
, 0);
1789 current_kboard
->defining_kbd_macro
= Qnil
;
1790 update_mode_lines
= 1;
1791 current_kboard
->Vprefix_arg
= Qnil
;
1795 if (NILP (current_kboard
->Vprefix_arg
) && ! no_direct
)
1797 /* In case we jump to directly_done. */
1798 Vcurrent_prefix_arg
= current_kboard
->Vprefix_arg
;
1800 /* Recognize some common commands in common situations and
1801 do them directly. */
1802 if (EQ (Vthis_command
, Qforward_char
) && PT
< ZV
)
1804 struct Lisp_Char_Table
*dp
1805 = window_display_table (XWINDOW (selected_window
));
1806 lose
= FETCH_CHAR (PT_BYTE
);
1808 if (! NILP (Vpost_command_hook
))
1809 /* Put this before calling adjust_point_for_property
1810 so it will only get called once in any case. */
1812 if (current_buffer
== prev_buffer
1813 && last_point_position
!= PT
1814 && NILP (Vdisable_point_adjustment
)
1815 && NILP (Vglobal_disable_point_adjustment
))
1816 adjust_point_for_property (last_point_position
, 0);
1817 already_adjusted
= 1;
1818 if (PT
== last_point_position
+ 1
1820 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1821 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1822 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1823 && (lose
>= 0x20 && lose
< 0x7f)))
1824 : (lose
>= 0x20 && lose
< 0x7f))
1825 /* To extract the case of continuation on
1826 wide-column characters. */
1827 && (WIDTH_BY_CHAR_HEAD (FETCH_BYTE (PT_BYTE
)) == 1)
1828 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1830 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1832 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1834 && !windows_or_buffers_changed
1835 && EQ (current_buffer
->selective_display
, Qnil
)
1836 && !detect_input_pending ()
1837 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1838 && NILP (Vexecuting_kbd_macro
))
1839 direct_output_forward_char (1);
1842 else if (EQ (Vthis_command
, Qbackward_char
) && PT
> BEGV
)
1844 struct Lisp_Char_Table
*dp
1845 = window_display_table (XWINDOW (selected_window
));
1847 lose
= FETCH_CHAR (PT_BYTE
);
1848 if (! NILP (Vpost_command_hook
))
1850 if (current_buffer
== prev_buffer
1851 && last_point_position
!= PT
1852 && NILP (Vdisable_point_adjustment
)
1853 && NILP (Vglobal_disable_point_adjustment
))
1854 adjust_point_for_property (last_point_position
, 0);
1855 already_adjusted
= 1;
1856 if (PT
== last_point_position
- 1
1858 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1859 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1860 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1861 && (lose
>= 0x20 && lose
< 0x7f)))
1862 : (lose
>= 0x20 && lose
< 0x7f))
1863 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1865 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1867 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1869 && !windows_or_buffers_changed
1870 && EQ (current_buffer
->selective_display
, Qnil
)
1871 && !detect_input_pending ()
1872 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1873 && NILP (Vexecuting_kbd_macro
))
1874 direct_output_forward_char (-1);
1877 else if (EQ (Vthis_command
, Qself_insert_command
)
1878 /* Try this optimization only on char keystrokes. */
1879 && NATNUMP (last_command_char
)
1880 && CHAR_VALID_P (XFASTINT (last_command_char
), 0))
1883 = translate_char (Vtranslation_table_for_input
,
1884 XFASTINT (last_command_char
), 0, 0, 0);
1886 if (NILP (Vexecuting_kbd_macro
)
1887 && !EQ (minibuf_window
, selected_window
))
1889 if (!nonundocount
|| nonundocount
>= 20)
1897 lose
= ((XFASTINT (XWINDOW (selected_window
)->last_modified
)
1899 || (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1901 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1903 || MODIFF
<= SAVE_MODIFF
1904 || windows_or_buffers_changed
1905 || !EQ (current_buffer
->selective_display
, Qnil
)
1906 || detect_input_pending ()
1907 || !NILP (XWINDOW (selected_window
)->column_number_displayed
)
1908 || !NILP (Vexecuting_kbd_macro
));
1910 value
= internal_self_insert (c
, 0);
1915 if (! NILP (Vpost_command_hook
))
1916 /* Put this before calling adjust_point_for_property
1917 so it will only get called once in any case. */
1920 /* VALUE == 1 when AFTER-CHANGE functions are
1921 installed which is the case most of the time
1922 because FONT-LOCK installs one. */
1923 if (!lose
&& !value
)
1924 direct_output_for_insert (c
);
1929 /* Here for a command that isn't executed directly */
1932 #ifdef HAVE_X_WINDOWS
1933 int scount
= SPECPDL_INDEX ();
1935 if (display_hourglass_p
1936 && NILP (Vexecuting_kbd_macro
))
1938 record_unwind_protect (cancel_hourglass_unwind
, Qnil
);
1944 if (NILP (current_kboard
->Vprefix_arg
))
1946 Fcommand_execute (Vthis_command
, Qnil
, Qnil
, Qnil
);
1948 #ifdef HAVE_X_WINDOWS
1949 /* Do not check display_hourglass_p here, because
1950 Fcommand_execute could change it, but we should cancel
1951 hourglass cursor anyway.
1952 But don't cancel the hourglass within a macro
1953 just because a command in the macro finishes. */
1954 if (NILP (Vexecuting_kbd_macro
))
1955 unbind_to (scount
, Qnil
);
1960 current_kboard
->Vlast_prefix_arg
= Vcurrent_prefix_arg
;
1962 /* Note that the value cell will never directly contain nil
1963 if the symbol is a local variable. */
1964 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1965 safe_run_hooks (Qpost_command_hook
);
1967 /* If displaying a message, resize the echo area window to fit
1968 that message's size exactly. */
1969 if (!NILP (echo_area_buffer
[0]))
1970 resize_echo_area_exactly ();
1972 if (!NILP (Vdeferred_action_list
))
1973 safe_run_hooks (Qdeferred_action_function
);
1975 /* If there is a prefix argument,
1976 1) We don't want Vlast_command to be ``universal-argument''
1977 (that would be dumb), so don't set Vlast_command,
1978 2) we want to leave echoing on so that the prefix will be
1979 echoed as part of this key sequence, so don't call
1981 3) we want to leave this_command_key_count non-zero, so that
1982 read_char will realize that it is re-reading a character, and
1983 not echo it a second time.
1985 If the command didn't actually create a prefix arg,
1986 but is merely a frame event that is transparent to prefix args,
1987 then the above doesn't apply. */
1988 if (NILP (current_kboard
->Vprefix_arg
) || CONSP (last_command_char
))
1990 current_kboard
->Vlast_command
= Vthis_command
;
1991 current_kboard
->Vreal_last_command
= real_this_command
;
1992 if (!CONSP (last_command_char
))
1993 current_kboard
->Vlast_repeatable_command
= real_this_command
;
1995 this_command_key_count
= 0;
1996 this_command_key_count_reset
= 0;
1997 this_single_command_key_start
= 0;
2000 if (!NILP (current_buffer
->mark_active
) && !NILP (Vrun_hooks
))
2002 /* Setting transient-mark-mode to `only' is a way of
2003 turning it on for just one command. */
2005 if (EQ (Vtransient_mark_mode
, Qidentity
))
2006 Vtransient_mark_mode
= Qnil
;
2007 if (EQ (Vtransient_mark_mode
, Qonly
))
2008 Vtransient_mark_mode
= Qidentity
;
2010 if (!NILP (Vdeactivate_mark
) && !NILP (Vtransient_mark_mode
))
2012 /* We could also call `deactivate'mark'. */
2013 if (EQ (Vtransient_mark_mode
, Qlambda
))
2014 Vtransient_mark_mode
= Qnil
;
2017 current_buffer
->mark_active
= Qnil
;
2018 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
2021 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
2022 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
2027 if (current_buffer
== prev_buffer
2028 && last_point_position
!= PT
2029 && NILP (Vdisable_point_adjustment
)
2030 && NILP (Vglobal_disable_point_adjustment
)
2031 && !already_adjusted
)
2032 adjust_point_for_property (last_point_position
, MODIFF
!= prev_modiff
);
2034 /* Install chars successfully executed in kbd macro. */
2036 if (!NILP (current_kboard
->defining_kbd_macro
)
2037 && NILP (current_kboard
->Vprefix_arg
))
2038 finalize_kbd_macro_chars ();
2039 #if 0 /* This shouldn't be necessary anymore. --lorentey */
2042 any_kboard_state ();
2048 extern Lisp_Object Qcomposition
, Qdisplay
;
2050 /* Adjust point to a boundary of a region that has such a property
2051 that should be treated intangible. For the moment, we check
2052 `composition', `display' and `invisible' properties.
2053 LAST_PT is the last position of point. */
2055 extern Lisp_Object Qafter_string
, Qbefore_string
;
2056 extern Lisp_Object get_pos_property
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
));
2059 adjust_point_for_property (last_pt
, modified
)
2064 Lisp_Object val
, overlay
, tmp
;
2065 int check_composition
= 1, check_display
= 1, check_invisible
= 1;
2068 /* FIXME: cycling is probably not necessary because these properties
2069 can't be usefully combined anyway. */
2070 while (check_composition
|| check_display
|| check_invisible
)
2072 if (check_composition
2073 && PT
> BEGV
&& PT
< ZV
2074 && get_property_and_range (PT
, Qcomposition
, &val
, &beg
, &end
, Qnil
)
2075 && COMPOSITION_VALID_P (beg
, end
, val
)
2076 && beg
< PT
/* && end > PT <- It's always the case. */
2077 && (last_pt
<= beg
|| last_pt
>= end
))
2080 SET_PT (PT
< last_pt
? beg
: end
);
2081 check_display
= check_invisible
= 1;
2083 check_composition
= 0;
2085 && PT
> BEGV
&& PT
< ZV
2086 && !NILP (val
= get_char_property_and_overlay
2087 (make_number (PT
), Qdisplay
, Qnil
, &overlay
))
2088 && display_prop_intangible_p (val
)
2089 && (!OVERLAYP (overlay
)
2090 ? get_property_and_range (PT
, Qdisplay
, &val
, &beg
, &end
, Qnil
)
2091 : (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)),
2092 end
= OVERLAY_POSITION (OVERLAY_END (overlay
))))
2093 && (beg
< PT
/* && end > PT <- It's always the case. */
2094 || (beg
<= PT
&& STRINGP (val
) && SCHARS (val
) == 0)))
2097 SET_PT (PT
< last_pt
2098 ? (STRINGP (val
) && SCHARS (val
) == 0 ? beg
- 1 : beg
)
2100 check_composition
= check_invisible
= 1;
2103 if (check_invisible
&& PT
> BEGV
&& PT
< ZV
)
2105 int inv
, ellipsis
= 0;
2108 /* Find boundaries `beg' and `end' of the invisible area, if any. */
2110 && !NILP (val
= get_char_property_and_overlay
2111 (make_number (end
), Qinvisible
, Qnil
, &overlay
))
2112 && (inv
= TEXT_PROP_MEANS_INVISIBLE (val
)))
2114 ellipsis
= ellipsis
|| inv
> 1
2115 || (OVERLAYP (overlay
)
2116 && (!NILP (Foverlay_get (overlay
, Qafter_string
))
2117 || !NILP (Foverlay_get (overlay
, Qbefore_string
))));
2118 tmp
= Fnext_single_char_property_change
2119 (make_number (end
), Qinvisible
, Qnil
, Qnil
);
2120 end
= NATNUMP (tmp
) ? XFASTINT (tmp
) : ZV
;
2123 && !NILP (val
= get_char_property_and_overlay
2124 (make_number (beg
- 1), Qinvisible
, Qnil
, &overlay
))
2125 && (inv
= TEXT_PROP_MEANS_INVISIBLE (val
)))
2127 ellipsis
= ellipsis
|| inv
> 1
2128 || (OVERLAYP (overlay
)
2129 && (!NILP (Foverlay_get (overlay
, Qafter_string
))
2130 || !NILP (Foverlay_get (overlay
, Qbefore_string
))));
2131 tmp
= Fprevious_single_char_property_change
2132 (make_number (beg
), Qinvisible
, Qnil
, Qnil
);
2133 beg
= NATNUMP (tmp
) ? XFASTINT (tmp
) : BEGV
;
2136 /* Move away from the inside area. */
2137 if (beg
< PT
&& end
> PT
)
2139 SET_PT ((orig_pt
== PT
&& (last_pt
< beg
|| last_pt
> end
))
2140 /* We haven't moved yet (so we don't need to fear
2141 infinite-looping) and we were outside the range
2142 before (so either end of the range still corresponds
2143 to a move in the right direction): pretend we moved
2144 less than we actually did, so that we still have
2145 more freedom below in choosing which end of the range
2147 ? (orig_pt
= -1, PT
< last_pt
? end
: beg
)
2148 /* We either have moved already or the last point
2149 was already in the range: we don't get to choose
2150 which end of the range we have to go to. */
2151 : (PT
< last_pt
? beg
: end
));
2152 check_composition
= check_display
= 1;
2154 #if 0 /* This assertion isn't correct, because SET_PT may end up setting
2155 the point to something other than its argument, due to
2156 point-motion hooks, intangibility, etc. */
2157 xassert (PT
== beg
|| PT
== end
);
2160 /* Pretend the area doesn't exist if the buffer is not
2162 if (!modified
&& !ellipsis
&& beg
< end
)
2164 if (last_pt
== beg
&& PT
== end
&& end
< ZV
)
2165 (check_composition
= check_display
= 1, SET_PT (end
+ 1));
2166 else if (last_pt
== end
&& PT
== beg
&& beg
> BEGV
)
2167 (check_composition
= check_display
= 1, SET_PT (beg
- 1));
2168 else if (PT
== ((PT
< last_pt
) ? beg
: end
))
2169 /* We've already moved as far as we can. Trying to go
2170 to the other end would mean moving backwards and thus
2171 could lead to an infinite loop. */
2173 else if (val
= get_pos_property (make_number (PT
),
2175 TEXT_PROP_MEANS_INVISIBLE (val
)
2176 && (val
= get_pos_property
2177 (make_number (PT
== beg
? end
: beg
),
2179 !TEXT_PROP_MEANS_INVISIBLE (val
)))
2180 (check_composition
= check_display
= 1,
2181 SET_PT (PT
== beg
? end
: beg
));
2184 check_invisible
= 0;
2188 /* Subroutine for safe_run_hooks: run the hook HOOK. */
2191 safe_run_hooks_1 (hook
)
2194 if (NILP (Vrun_hooks
))
2196 return call1 (Vrun_hooks
, Vinhibit_quit
);
2199 /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */
2202 safe_run_hooks_error (data
)
2205 Lisp_Object args
[3];
2206 args
[0] = build_string ("Error in %s: %s");
2207 args
[1] = Vinhibit_quit
;
2210 return Fset (Vinhibit_quit
, Qnil
);
2213 /* If we get an error while running the hook, cause the hook variable
2214 to be nil. Also inhibit quits, so that C-g won't cause the hook
2215 to mysteriously evaporate. */
2218 safe_run_hooks (hook
)
2221 int count
= SPECPDL_INDEX ();
2222 specbind (Qinhibit_quit
, hook
);
2224 internal_condition_case (safe_run_hooks_1
, Qt
, safe_run_hooks_error
);
2226 unbind_to (count
, Qnil
);
2230 /* Number of seconds between polling for input. This is a Lisp
2231 variable that can be bound. */
2233 EMACS_INT polling_period
;
2235 /* Nonzero means polling for input is temporarily suppressed. */
2237 int poll_suppress_count
;
2239 /* Asynchronous timer for polling. */
2241 struct atimer
*poll_timer
;
2244 #ifdef POLL_FOR_INPUT
2246 /* Poll for input, so what we catch a C-g if it comes in. This
2247 function is called from x_make_frame_visible, see comment
2253 if (interrupt_input_blocked
== 0
2254 && !waiting_for_input
)
2255 read_avail_input (0);
2258 /* Timer callback function for poll_timer. TIMER is equal to
2262 poll_for_input (timer
)
2263 struct atimer
*timer
;
2265 if (poll_suppress_count
== 0)
2267 interrupt_input_pending
= 1;
2269 poll_for_input_1 ();
2273 #endif /* POLL_FOR_INPUT */
2275 /* Begin signals to poll for input, if they are appropriate.
2276 This function is called unconditionally from various places. */
2281 #ifdef POLL_FOR_INPUT
2282 /* XXX This condition was (read_socket_hook && !interrupt_input),
2283 but read_socket_hook is not global anymore. Let's pretend that
2285 if (!interrupt_input
)
2287 /* Turn alarm handling on unconditionally. It might have
2288 been turned off in process.c. */
2289 turn_on_atimers (1);
2291 /* If poll timer doesn't exist, are we need one with
2292 a different interval, start a new one. */
2293 if (poll_timer
== NULL
2294 || EMACS_SECS (poll_timer
->interval
) != polling_period
)
2296 EMACS_TIME interval
;
2299 cancel_atimer (poll_timer
);
2301 EMACS_SET_SECS_USECS (interval
, polling_period
, 0);
2302 poll_timer
= start_atimer (ATIMER_CONTINUOUS
, interval
,
2303 poll_for_input
, NULL
);
2306 /* Let the timer's callback function poll for input
2307 if this becomes zero. */
2308 --poll_suppress_count
;
2313 /* Nonzero if we are using polling to handle input asynchronously. */
2316 input_polling_used ()
2318 #ifdef POLL_FOR_INPUT
2319 /* XXX This condition was (read_socket_hook && !interrupt_input),
2320 but read_socket_hook is not global anymore. Let's pretend that
2322 return !interrupt_input
;
2328 /* Turn off polling. */
2333 #ifdef POLL_FOR_INPUT
2334 /* XXX This condition was (read_socket_hook && !interrupt_input),
2335 but read_socket_hook is not global anymore. Let's pretend that
2337 if (!interrupt_input
)
2338 ++poll_suppress_count
;
2342 /* Set the value of poll_suppress_count to COUNT
2343 and start or stop polling accordingly. */
2346 set_poll_suppress_count (count
)
2349 #ifdef POLL_FOR_INPUT
2350 if (count
== 0 && poll_suppress_count
!= 0)
2352 poll_suppress_count
= 1;
2355 else if (count
!= 0 && poll_suppress_count
== 0)
2359 poll_suppress_count
= count
;
2363 /* Bind polling_period to a value at least N.
2364 But don't decrease it. */
2367 bind_polling_period (n
)
2370 #ifdef POLL_FOR_INPUT
2371 int new = polling_period
;
2376 stop_other_atimers (poll_timer
);
2378 specbind (Qpolling_period
, make_number (new));
2379 /* Start a new alarm with the new period. */
2384 /* Apply the control modifier to CHARACTER. */
2390 /* Save the upper bits here. */
2391 int upper
= c
& ~0177;
2395 /* Everything in the columns containing the upper-case letters
2396 denotes a control character. */
2397 if (c
>= 0100 && c
< 0140)
2401 /* Set the shift modifier for a control char
2402 made from a shifted letter. But only for letters! */
2403 if (oc
>= 'A' && oc
<= 'Z')
2404 c
|= shift_modifier
;
2407 /* The lower-case letters denote control characters too. */
2408 else if (c
>= 'a' && c
<= 'z')
2411 /* Include the bits for control and shift
2412 only if the basic ASCII code can't indicate them. */
2416 /* Replace the high bits. */
2417 c
|= (upper
& ~ctrl_modifier
);
2422 /* Display the help-echo property of the character after the mouse pointer.
2423 Either show it in the echo area, or call show-help-function to display
2424 it by other means (maybe in a tooltip).
2426 If HELP is nil, that means clear the previous help echo.
2428 If HELP is a string, display that string. If HELP is a function,
2429 call it with OBJECT and POS as arguments; the function should
2430 return a help string or nil for none. For all other types of HELP,
2431 evaluate it to obtain a string.
2433 WINDOW is the window in which the help was generated, if any.
2434 It is nil if not in a window.
2436 If OBJECT is a buffer, POS is the position in the buffer where the
2437 `help-echo' text property was found.
2439 If OBJECT is an overlay, that overlay has a `help-echo' property,
2440 and POS is the position in the overlay's buffer under the mouse.
2442 If OBJECT is a string (an overlay string or a string displayed with
2443 the `display' property). POS is the position in that string under
2446 OK_TO_OVERWRITE_KEYSTROKE_ECHO non-zero means it's okay if the help
2447 echo overwrites a keystroke echo currently displayed in the echo
2450 Note: this function may only be called with HELP nil or a string
2451 from X code running asynchronously. */
2454 show_help_echo (help
, window
, object
, pos
, ok_to_overwrite_keystroke_echo
)
2455 Lisp_Object help
, window
, object
, pos
;
2456 int ok_to_overwrite_keystroke_echo
;
2458 if (!NILP (help
) && !STRINGP (help
))
2460 if (FUNCTIONP (help
))
2462 Lisp_Object args
[4];
2467 help
= safe_call (4, args
);
2470 help
= safe_eval (help
);
2472 if (!STRINGP (help
))
2476 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
2477 if (!noninteractive
&& STRINGP (help
))
2479 /* The mouse-fixup-help-message Lisp function can call
2480 mouse_position_hook, which resets the mouse_moved flags.
2481 This causes trouble if we are trying to read a mouse motion
2482 event (i.e., if we are inside a `track-mouse' form), so we
2483 restore the mouse_moved flag. */
2484 FRAME_PTR f
= NILP (do_mouse_tracking
) ? NULL
: some_mouse_moved ();
2485 help
= call1 (Qmouse_fixup_help_message
, help
);
2491 if (STRINGP (help
) || NILP (help
))
2493 if (!NILP (Vshow_help_function
))
2494 call1 (Vshow_help_function
, help
);
2495 else if (/* Don't overwrite minibuffer contents. */
2496 !MINI_WINDOW_P (XWINDOW (selected_window
))
2497 /* Don't overwrite a keystroke echo. */
2498 && (NILP (echo_message_buffer
)
2499 || ok_to_overwrite_keystroke_echo
)
2500 /* Don't overwrite a prompt. */
2501 && !cursor_in_echo_area
)
2505 int count
= SPECPDL_INDEX ();
2507 if (!help_echo_showing_p
)
2508 Vpre_help_message
= current_message ();
2510 specbind (Qmessage_truncate_lines
, Qt
);
2511 message3_nolog (help
, SBYTES (help
),
2512 STRING_MULTIBYTE (help
));
2513 unbind_to (count
, Qnil
);
2515 else if (STRINGP (Vpre_help_message
))
2517 message3_nolog (Vpre_help_message
,
2518 SBYTES (Vpre_help_message
),
2519 STRING_MULTIBYTE (Vpre_help_message
));
2520 Vpre_help_message
= Qnil
;
2526 help_echo_showing_p
= STRINGP (help
);
2532 /* Input of single characters from keyboard */
2534 Lisp_Object
print_help ();
2535 static Lisp_Object
kbd_buffer_get_event ();
2536 static void record_char ();
2538 static Lisp_Object help_form_saved_window_configs
;
2540 read_char_help_form_unwind (arg
)
2542 Lisp_Object window_config
= XCAR (help_form_saved_window_configs
);
2543 help_form_saved_window_configs
= XCDR (help_form_saved_window_configs
);
2544 if (!NILP (window_config
))
2545 Fset_window_configuration (window_config
);
2549 #define STOP_POLLING \
2550 do { if (! polling_stopped_here) stop_polling (); \
2551 polling_stopped_here = 1; } while (0)
2553 #define RESUME_POLLING \
2554 do { if (polling_stopped_here) start_polling (); \
2555 polling_stopped_here = 0; } while (0)
2557 /* read a character from the keyboard; call the redisplay if needed */
2558 /* commandflag 0 means do not do auto-saving, but do do redisplay.
2559 -1 means do not do redisplay, but do do autosaving.
2562 /* The arguments MAPS and NMAPS are for menu prompting.
2563 MAPS is an array of keymaps; NMAPS is the length of MAPS.
2565 PREV_EVENT is the previous input event, or nil if we are reading
2566 the first event of a key sequence (or not reading a key sequence).
2567 If PREV_EVENT is t, that is a "magic" value that says
2568 not to run input methods, but in other respects to act as if
2569 not reading a key sequence.
2571 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
2572 if we used a mouse menu to read the input, or zero otherwise. If
2573 USED_MOUSE_MENU is null, we don't dereference it.
2575 Value is -2 when we find input on another keyboard. A second call
2576 to read_char will read it.
2578 If END_TIME is non-null, it is a pointer to an EMACS_TIME
2579 specifying the maximum time to wait until. If no input arrives by
2580 that time, stop waiting and return nil.
2582 Value is t if we showed a menu and the user rejected it. */
2585 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
, end_time
)
2589 Lisp_Object prev_event
;
2590 int *used_mouse_menu
;
2591 EMACS_TIME
*end_time
;
2593 volatile Lisp_Object c
;
2594 int count
, jmpcount
;
2595 jmp_buf local_getcjmp
;
2597 volatile int key_already_recorded
= 0;
2598 Lisp_Object tem
, save
;
2599 volatile Lisp_Object previous_echo_area_message
;
2600 volatile Lisp_Object also_record
;
2601 volatile int reread
;
2602 struct gcpro gcpro1
, gcpro2
;
2603 int polling_stopped_here
= 0;
2604 struct kboard
*orig_kboard
= current_kboard
;
2608 #if 0 /* This was commented out as part of fixing echo for C-u left. */
2609 before_command_key_count
= this_command_key_count
;
2610 before_command_echo_length
= echo_length ();
2613 previous_echo_area_message
= Qnil
;
2615 GCPRO2 (c
, previous_echo_area_message
);
2620 if (CONSP (Vunread_post_input_method_events
))
2622 c
= XCAR (Vunread_post_input_method_events
);
2623 Vunread_post_input_method_events
2624 = XCDR (Vunread_post_input_method_events
);
2626 /* Undo what read_char_x_menu_prompt did when it unread
2627 additional keys returned by Fx_popup_menu. */
2629 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
)))
2637 if (unread_command_char
!= -1)
2639 XSETINT (c
, unread_command_char
);
2640 unread_command_char
= -1;
2646 if (CONSP (Vunread_command_events
))
2648 c
= XCAR (Vunread_command_events
);
2649 Vunread_command_events
= XCDR (Vunread_command_events
);
2653 /* Undo what sit-for did when it unread additional keys
2654 inside universal-argument. */
2657 && EQ (XCAR (c
), Qt
))
2663 /* Undo what read_char_x_menu_prompt did when it unread
2664 additional keys returned by Fx_popup_menu. */
2666 && EQ (XCDR (c
), Qdisabled
)
2667 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
))))
2670 /* If the queued event is something that used the mouse,
2671 set used_mouse_menu accordingly. */
2673 && (EQ (c
, Qtool_bar
) || EQ (c
, Qmenu_bar
)))
2674 *used_mouse_menu
= 1;
2676 goto reread_for_input_method
;
2679 if (CONSP (Vunread_input_method_events
))
2681 c
= XCAR (Vunread_input_method_events
);
2682 Vunread_input_method_events
= XCDR (Vunread_input_method_events
);
2684 /* Undo what read_char_x_menu_prompt did when it unread
2685 additional keys returned by Fx_popup_menu. */
2687 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
)))
2691 goto reread_for_input_method
;
2694 this_command_key_count_reset
= 0;
2696 if (!NILP (Vexecuting_kbd_macro
))
2698 /* We set this to Qmacro; since that's not a frame, nobody will
2699 try to switch frames on us, and the selected window will
2702 Since this event came from a macro, it would be misleading to
2703 leave internal_last_event_frame set to wherever the last
2704 real event came from. Normally, a switch-frame event selects
2705 internal_last_event_frame after each command is read, but
2706 events read from a macro should never cause a new frame to be
2708 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
2710 /* Exit the macro if we are at the end.
2711 Also, some things replace the macro with t
2712 to force an early exit. */
2713 if (EQ (Vexecuting_kbd_macro
, Qt
)
2714 || executing_kbd_macro_index
>= XFASTINT (Flength (Vexecuting_kbd_macro
)))
2720 c
= Faref (Vexecuting_kbd_macro
, make_number (executing_kbd_macro_index
));
2721 if (STRINGP (Vexecuting_kbd_macro
)
2722 && (XINT (c
) & 0x80) && (XUINT (c
) <= 0xff))
2723 XSETFASTINT (c
, CHAR_META
| (XINT (c
) & ~0x80));
2725 executing_kbd_macro_index
++;
2730 if (!NILP (unread_switch_frame
))
2732 c
= unread_switch_frame
;
2733 unread_switch_frame
= Qnil
;
2735 /* This event should make it into this_command_keys, and get echoed
2736 again, so we do not set `reread'. */
2740 /* if redisplay was requested */
2741 if (commandflag
>= 0)
2743 /* If there is pending input, process any events which are not
2744 user-visible, such as X selection_request events. */
2746 || detect_input_pending_run_timers (0))
2747 swallow_events (0); /* may clear input_pending */
2749 /* Redisplay if no pending input. */
2750 while (!input_pending
)
2752 if (help_echo_showing_p
&& !EQ (selected_window
, minibuf_window
))
2753 redisplay_preserve_echo_area (5);
2758 /* Normal case: no input arrived during redisplay. */
2761 /* Input arrived and pre-empted redisplay.
2762 Process any events which are not user-visible. */
2764 /* If that cleared input_pending, try again to redisplay. */
2768 /* Message turns off echoing unless more keystrokes turn it on again.
2770 The code in 20.x for the condition was
2772 1. echo_area_glyphs && *echo_area_glyphs
2773 2. && echo_area_glyphs != current_kboard->echobuf
2774 3. && ok_to_echo_at_next_pause != echo_area_glyphs
2776 (1) means there's a current message displayed
2778 (2) means it's not the message from echoing from the current
2781 (3) There's only one place in 20.x where ok_to_echo_at_next_pause
2782 is set to a non-null value. This is done in read_char and it is
2783 set to echo_area_glyphs after a call to echo_char. That means
2784 ok_to_echo_at_next_pause is either null or
2785 current_kboard->echobuf with the appropriate current_kboard at
2788 So, condition (3) means in clear text ok_to_echo_at_next_pause
2789 must be either null, or the current message isn't from echoing at
2790 all, or it's from echoing from a different kboard than the
2793 if (/* There currently is something in the echo area. */
2794 !NILP (echo_area_buffer
[0])
2795 && (/* And it's either not from echoing. */
2796 !EQ (echo_area_buffer
[0], echo_message_buffer
)
2797 /* Or it's an echo from a different kboard. */
2798 || echo_kboard
!= current_kboard
2799 /* Or we explicitly allow overwriting whatever there is. */
2800 || ok_to_echo_at_next_pause
== NULL
))
2805 /* Try reading a character via menu prompting in the minibuf.
2806 Try this before the sit-for, because the sit-for
2807 would do the wrong thing if we are supposed to do
2808 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
2809 after a mouse event so don't try a minibuf menu. */
2811 if (nmaps
> 0 && INTERACTIVE
2812 && !NILP (prev_event
) && ! EVENT_HAS_PARAMETERS (prev_event
)
2813 /* Don't bring up a menu if we already have another event. */
2814 && NILP (Vunread_command_events
)
2815 && unread_command_char
< 0
2816 && !detect_input_pending_run_timers (0))
2818 c
= read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
);
2820 if (INTEGERP (c
) && XINT (c
) == -2)
2821 return c
; /* wrong_kboard_jmpbuf */
2825 key_already_recorded
= 1;
2830 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet.
2831 We will do that below, temporarily for short sections of code,
2832 when appropriate. local_getcjmp must be in effect
2833 around any call to sit_for or kbd_buffer_get_event;
2834 it *must not* be in effect when we call redisplay. */
2836 jmpcount
= SPECPDL_INDEX ();
2837 if (_setjmp (local_getcjmp
))
2839 /* Handle quits while reading the keyboard. */
2840 /* We must have saved the outer value of getcjmp here,
2841 so restore it now. */
2842 restore_getcjmp (save_jump
);
2843 unbind_to (jmpcount
, Qnil
);
2844 XSETINT (c
, quit_char
);
2845 internal_last_event_frame
= selected_frame
;
2846 Vlast_event_frame
= internal_last_event_frame
;
2847 /* If we report the quit char as an event,
2848 don't do so more than once. */
2849 if (!NILP (Vinhibit_quit
))
2854 KBOARD
*kb
= FRAME_KBOARD (XFRAME (selected_frame
));
2855 if (kb
!= current_kboard
)
2857 Lisp_Object link
= kb
->kbd_queue
;
2858 /* We shouldn't get here if we were in single-kboard mode! */
2863 while (CONSP (XCDR (link
)))
2865 if (!NILP (XCDR (link
)))
2869 kb
->kbd_queue
= Fcons (c
, Qnil
);
2871 XSETCDR (link
, Fcons (c
, Qnil
));
2872 kb
->kbd_queue_has_data
= 1;
2873 current_kboard
= kb
;
2874 /* This is going to exit from read_char
2875 so we had better get rid of this frame's stuff. */
2877 return make_number (-2); /* wrong_kboard_jmpbuf */
2884 /* Start idle timers if no time limit is supplied. We don't do it
2885 if a time limit is supplied to avoid an infinite recursion in the
2886 situation where an idle timer calls `sit-for'. */
2889 timer_start_idle ();
2891 /* If in middle of key sequence and minibuffer not active,
2892 start echoing if enough time elapses. */
2894 if (minibuf_level
== 0
2896 && !current_kboard
->immediate_echo
2897 && this_command_key_count
> 0
2899 && (FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
2900 && NILP (Fzerop (Vecho_keystrokes
))
2901 && (/* No message. */
2902 NILP (echo_area_buffer
[0])
2903 /* Or empty message. */
2904 || (BUF_BEG (XBUFFER (echo_area_buffer
[0]))
2905 == BUF_Z (XBUFFER (echo_area_buffer
[0])))
2906 /* Or already echoing from same kboard. */
2907 || (echo_kboard
&& ok_to_echo_at_next_pause
== echo_kboard
)
2908 /* Or not echoing before and echoing allowed. */
2909 || (!echo_kboard
&& ok_to_echo_at_next_pause
)))
2911 /* After a mouse event, start echoing right away.
2912 This is because we are probably about to display a menu,
2913 and we don't want to delay before doing so. */
2914 if (EVENT_HAS_PARAMETERS (prev_event
))
2920 save_getcjmp (save_jump
);
2921 restore_getcjmp (local_getcjmp
);
2922 tem0
= sit_for (Vecho_keystrokes
, 1, 1);
2923 restore_getcjmp (save_jump
);
2925 && ! CONSP (Vunread_command_events
))
2930 /* Maybe auto save due to number of keystrokes. */
2932 if (commandflag
!= 0
2933 && auto_save_interval
> 0
2934 && num_nonmacro_input_events
- last_auto_save
> max (auto_save_interval
, 20)
2935 && !detect_input_pending_run_timers (0))
2937 Fdo_auto_save (Qnil
, Qnil
);
2938 /* Hooks can actually change some buffers in auto save. */
2942 /* Try reading using an X menu.
2943 This is never confused with reading using the minibuf
2944 because the recursive call of read_char in read_char_minibuf_menu_prompt
2945 does not pass on any keymaps. */
2947 if (nmaps
> 0 && INTERACTIVE
2948 && !NILP (prev_event
)
2949 && EVENT_HAS_PARAMETERS (prev_event
)
2950 && !EQ (XCAR (prev_event
), Qmenu_bar
)
2951 && !EQ (XCAR (prev_event
), Qtool_bar
)
2952 /* Don't bring up a menu if we already have another event. */
2953 && NILP (Vunread_command_events
)
2954 && unread_command_char
< 0)
2956 c
= read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
2958 /* Now that we have read an event, Emacs is not idle. */
2965 /* Maybe autosave and/or garbage collect due to idleness. */
2967 if (INTERACTIVE
&& NILP (c
))
2969 int delay_level
, buffer_size
;
2971 /* Slow down auto saves logarithmically in size of current buffer,
2972 and garbage collect while we're at it. */
2973 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
2974 last_non_minibuf_size
= Z
- BEG
;
2975 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
2977 while (buffer_size
> 64)
2978 delay_level
++, buffer_size
-= buffer_size
>> 2;
2979 if (delay_level
< 4) delay_level
= 4;
2980 /* delay_level is 4 for files under around 50k, 7 at 100k,
2981 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
2983 /* Auto save if enough time goes by without input. */
2984 if (commandflag
!= 0
2985 && num_nonmacro_input_events
> last_auto_save
2986 && INTEGERP (Vauto_save_timeout
)
2987 && XINT (Vauto_save_timeout
) > 0)
2990 int timeout
= delay_level
* XFASTINT (Vauto_save_timeout
) / 4;
2992 save_getcjmp (save_jump
);
2993 restore_getcjmp (local_getcjmp
);
2994 tem0
= sit_for (make_number (timeout
), 1, 1);
2995 restore_getcjmp (save_jump
);
2998 && ! CONSP (Vunread_command_events
))
3000 Fdo_auto_save (Qnil
, Qnil
);
3002 /* If we have auto-saved and there is still no input
3003 available, garbage collect if there has been enough
3004 consing going on to make it worthwhile. */
3005 if (!detect_input_pending_run_timers (0)
3006 && consing_since_gc
> gc_cons_threshold
/ 2)
3007 Fgarbage_collect ();
3014 /* Notify the caller if an autosave hook, or a timer, sentinel or
3015 filter in the sit_for calls above have changed the current
3016 kboard. This could happen if they use the minibuffer or start a
3017 recursive edit, like the fancy splash screen in server.el's
3018 filter. If this longjmp wasn't here, read_key_sequence would
3019 interpret the next key sequence using the wrong translation
3020 tables and function keymaps. */
3021 if (NILP (c
) && current_kboard
!= orig_kboard
)
3024 return make_number (-2); /* wrong_kboard_jmpbuf */
3027 /* If this has become non-nil here, it has been set by a timer
3028 or sentinel or filter. */
3029 if (CONSP (Vunread_command_events
))
3031 c
= XCAR (Vunread_command_events
);
3032 Vunread_command_events
= XCDR (Vunread_command_events
);
3035 /* Read something from current KBOARD's side queue, if possible. */
3039 if (current_kboard
->kbd_queue_has_data
)
3041 if (!CONSP (current_kboard
->kbd_queue
))
3043 c
= XCAR (current_kboard
->kbd_queue
);
3044 current_kboard
->kbd_queue
3045 = XCDR (current_kboard
->kbd_queue
);
3046 if (NILP (current_kboard
->kbd_queue
))
3047 current_kboard
->kbd_queue_has_data
= 0;
3048 input_pending
= readable_events (0);
3049 if (EVENT_HAS_PARAMETERS (c
)
3050 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qswitch_frame
))
3051 internal_last_event_frame
= XCAR (XCDR (c
));
3052 Vlast_event_frame
= internal_last_event_frame
;
3057 /* If current_kboard's side queue is empty check the other kboards.
3058 If one of them has data that we have not yet seen here,
3059 switch to it and process the data waiting for it.
3061 Note: if the events queued up for another kboard
3062 have already been seen here, and therefore are not a complete command,
3063 the kbd_queue_has_data field is 0, so we skip that kboard here.
3064 That's to avoid an infinite loop switching between kboards here. */
3065 if (NILP (c
) && !single_kboard
)
3068 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
3069 if (kb
->kbd_queue_has_data
)
3071 current_kboard
= kb
;
3072 /* This is going to exit from read_char
3073 so we had better get rid of this frame's stuff. */
3075 return make_number (-2); /* wrong_kboard_jmpbuf */
3084 /* Finally, we read from the main queue,
3085 and if that gives us something we can't use yet, we put it on the
3086 appropriate side queue and try again. */
3095 EMACS_GET_TIME (now
);
3096 if (EMACS_TIME_GE (now
, *end_time
))
3100 /* Actually read a character, waiting if necessary. */
3101 save_getcjmp (save_jump
);
3102 restore_getcjmp (local_getcjmp
);
3104 timer_start_idle ();
3105 c
= kbd_buffer_get_event (&kb
, used_mouse_menu
, end_time
);
3106 restore_getcjmp (save_jump
);
3109 if (! NILP (c
) && (kb
!= current_kboard
))
3111 Lisp_Object link
= kb
->kbd_queue
;
3114 while (CONSP (XCDR (link
)))
3116 if (!NILP (XCDR (link
)))
3120 kb
->kbd_queue
= Fcons (c
, Qnil
);
3122 XSETCDR (link
, Fcons (c
, Qnil
));
3123 kb
->kbd_queue_has_data
= 1;
3127 current_kboard
= kb
;
3128 /* This is going to exit from read_char
3129 so we had better get rid of this frame's stuff. */
3131 return make_number (-2);
3136 /* Terminate Emacs in batch mode if at eof. */
3137 if (noninteractive
&& INTEGERP (c
) && XINT (c
) < 0)
3138 Fkill_emacs (make_number (1));
3142 /* Add in any extra modifiers, where appropriate. */
3143 if ((extra_keyboard_modifiers
& CHAR_CTL
)
3144 || ((extra_keyboard_modifiers
& 0177) < ' '
3145 && (extra_keyboard_modifiers
& 0177) != 0))
3146 XSETINT (c
, make_ctrl_char (XINT (c
)));
3148 /* Transfer any other modifier bits directly from
3149 extra_keyboard_modifiers to c. Ignore the actual character code
3150 in the low 16 bits of extra_keyboard_modifiers. */
3151 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
3162 if (commandflag
>= 0
3163 && !input_pending
&& !detect_input_pending_run_timers (0))
3171 /* Buffer switch events are only for internal wakeups
3172 so don't show them to the user.
3173 Also, don't record a key if we already did. */
3174 if (BUFFERP (c
) || key_already_recorded
)
3177 /* Process special events within read_char
3178 and loop around to read another event. */
3181 tem
= access_keymap (get_keymap (Vspecial_event_map
, 0, 1), c
, 0, 0, 1);
3186 #if 0 /* This shouldn't be necessary anymore. --lorentey */
3187 int was_locked
= single_kboard
;
3188 int count
= SPECPDL_INDEX ();
3189 record_single_kboard_state ();
3192 last_input_char
= c
;
3193 Fcommand_execute (tem
, Qnil
, Fvector (1, &last_input_char
), Qt
);
3195 if (CONSP (c
) && EQ (XCAR (c
), Qselect_window
) && !end_time
)
3196 /* We stopped being idle for this event; undo that. This
3197 prevents automatic window selection (under
3198 mouse_autoselect_window from acting as a real input event, for
3199 example banishing the mouse under mouse-avoidance-mode. */
3200 timer_resume_idle ();
3202 #if 0 /* This shouldn't be necessary anymore. --lorentey */
3203 /* Resume allowing input from any kboard, if that was true before. */
3205 any_kboard_state ();
3206 unbind_to (count
, Qnil
);
3212 /* Handle things that only apply to characters. */
3215 /* If kbd_buffer_get_event gave us an EOF, return that. */
3219 if ((STRINGP (current_kboard
->Vkeyboard_translate_table
)
3220 && SCHARS (current_kboard
->Vkeyboard_translate_table
) > (unsigned) XFASTINT (c
))
3221 || (VECTORP (current_kboard
->Vkeyboard_translate_table
)
3222 && XVECTOR (current_kboard
->Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
3223 || (CHAR_TABLE_P (current_kboard
->Vkeyboard_translate_table
)
3224 && CHAR_VALID_P (XINT (c
), 0)))
3227 d
= Faref (current_kboard
->Vkeyboard_translate_table
, c
);
3228 /* nil in keyboard-translate-table means no translation. */
3234 /* If this event is a mouse click in the menu bar,
3235 return just menu-bar for now. Modify the mouse click event
3236 so we won't do this twice, then queue it up. */
3237 if (EVENT_HAS_PARAMETERS (c
)
3239 && CONSP (EVENT_START (c
))
3240 && CONSP (XCDR (EVENT_START (c
))))
3244 posn
= POSN_POSN (EVENT_START (c
));
3245 /* Handle menu-bar events:
3246 insert the dummy prefix event `menu-bar'. */
3247 if (EQ (posn
, Qmenu_bar
) || EQ (posn
, Qtool_bar
))
3249 /* Change menu-bar to (menu-bar) as the event "position". */
3250 POSN_SET_POSN (EVENT_START (c
), Fcons (posn
, Qnil
));
3253 Vunread_command_events
= Fcons (c
, Vunread_command_events
);
3258 /* Store these characters into recent_keys, the dribble file if any,
3259 and the keyboard macro being defined, if any. */
3261 if (! NILP (also_record
))
3262 record_char (also_record
);
3264 /* Wipe the echo area.
3265 But first, if we are about to use an input method,
3266 save the echo area contents for it to refer to. */
3268 && ! NILP (Vinput_method_function
)
3269 && (unsigned) XINT (c
) >= ' '
3270 && (unsigned) XINT (c
) != 127
3271 && (unsigned) XINT (c
) < 256)
3273 previous_echo_area_message
= Fcurrent_message ();
3274 Vinput_method_previous_message
= previous_echo_area_message
;
3277 /* Now wipe the echo area, except for help events which do their
3278 own stuff with the echo area. */
3280 || (!(EQ (Qhelp_echo
, XCAR (c
)))
3281 && !(EQ (Qswitch_frame
, XCAR (c
)))))
3283 if (!NILP (echo_area_buffer
[0]))
3284 safe_run_hooks (Qecho_area_clear_hook
);
3285 clear_message (1, 0);
3288 reread_for_input_method
:
3290 /* Pass this to the input method, if appropriate. */
3292 && ! NILP (Vinput_method_function
)
3293 /* Don't run the input method within a key sequence,
3294 after the first event of the key sequence. */
3295 && NILP (prev_event
)
3296 && (unsigned) XINT (c
) >= ' '
3297 && (unsigned) XINT (c
) != 127
3298 && (unsigned) XINT (c
) < 256)
3301 int key_count
, key_count_reset
;
3302 struct gcpro gcpro1
;
3303 int count
= SPECPDL_INDEX ();
3305 /* Save the echo status. */
3306 int saved_immediate_echo
= current_kboard
->immediate_echo
;
3307 struct kboard
*saved_ok_to_echo
= ok_to_echo_at_next_pause
;
3308 Lisp_Object saved_echo_string
= current_kboard
->echo_string
;
3309 int saved_echo_after_prompt
= current_kboard
->echo_after_prompt
;
3312 if (before_command_restore_flag
)
3314 this_command_key_count
= before_command_key_count_1
;
3315 if (this_command_key_count
< this_single_command_key_start
)
3316 this_single_command_key_start
= this_command_key_count
;
3317 echo_truncate (before_command_echo_length_1
);
3318 before_command_restore_flag
= 0;
3322 /* Save the this_command_keys status. */
3323 key_count
= this_command_key_count
;
3324 key_count_reset
= this_command_key_count_reset
;
3327 keys
= Fcopy_sequence (this_command_keys
);
3332 /* Clear out this_command_keys. */
3333 this_command_key_count
= 0;
3334 this_command_key_count_reset
= 0;
3336 /* Now wipe the echo area. */
3337 if (!NILP (echo_area_buffer
[0]))
3338 safe_run_hooks (Qecho_area_clear_hook
);
3339 clear_message (1, 0);
3342 /* If we are not reading a key sequence,
3343 never use the echo area. */
3346 specbind (Qinput_method_use_echo_area
, Qt
);
3349 /* Call the input method. */
3350 tem
= call1 (Vinput_method_function
, c
);
3352 tem
= unbind_to (count
, tem
);
3354 /* Restore the saved echoing state
3355 and this_command_keys state. */
3356 this_command_key_count
= key_count
;
3357 this_command_key_count_reset
= key_count_reset
;
3359 this_command_keys
= keys
;
3362 ok_to_echo_at_next_pause
= saved_ok_to_echo
;
3363 current_kboard
->echo_string
= saved_echo_string
;
3364 current_kboard
->echo_after_prompt
= saved_echo_after_prompt
;
3365 if (saved_immediate_echo
)
3370 /* The input method can return no events. */
3373 /* Bring back the previous message, if any. */
3374 if (! NILP (previous_echo_area_message
))
3375 message_with_string ("%s", previous_echo_area_message
, 0);
3378 /* It returned one event or more. */
3380 Vunread_post_input_method_events
3381 = nconc2 (XCDR (tem
), Vunread_post_input_method_events
);
3386 /* Display help if not echoing. */
3387 if (CONSP (c
) && EQ (XCAR (c
), Qhelp_echo
))
3389 /* (help-echo FRAME HELP WINDOW OBJECT POS). */
3390 Lisp_Object help
, object
, position
, window
, tem
;
3392 tem
= Fcdr (XCDR (c
));
3395 window
= Fcar (tem
);
3397 object
= Fcar (tem
);
3399 position
= Fcar (tem
);
3401 show_help_echo (help
, window
, object
, position
, 0);
3403 /* We stopped being idle for this event; undo that. */
3405 timer_resume_idle ();
3409 if ((! reread
|| this_command_key_count
== 0
3410 || this_command_key_count_reset
)
3414 /* Don't echo mouse motion events. */
3415 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
3416 && NILP (Fzerop (Vecho_keystrokes
))
3417 && ! (EVENT_HAS_PARAMETERS (c
)
3418 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
3421 if (! NILP (also_record
))
3422 echo_char (also_record
);
3423 /* Once we reread a character, echoing can happen
3424 the next time we pause to read a new one. */
3425 ok_to_echo_at_next_pause
= current_kboard
;
3428 /* Record this character as part of the current key. */
3429 add_command_key (c
);
3430 if (! NILP (also_record
))
3431 add_command_key (also_record
);
3434 last_input_char
= c
;
3437 /* Process the help character specially if enabled */
3438 if (!NILP (Vhelp_form
) && help_char_p (c
))
3441 count
= SPECPDL_INDEX ();
3443 help_form_saved_window_configs
3444 = Fcons (Fcurrent_window_configuration (Qnil
),
3445 help_form_saved_window_configs
);
3446 record_unwind_protect (read_char_help_form_unwind
, Qnil
);
3448 tem0
= Feval (Vhelp_form
);
3450 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
3455 c
= read_char (0, 0, 0, Qnil
, 0, NULL
);
3456 if (EVENT_HAS_PARAMETERS (c
)
3457 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_click
))
3458 XSETCAR (help_form_saved_window_configs
, Qnil
);
3460 while (BUFFERP (c
));
3461 /* Remove the help from the frame */
3462 unbind_to (count
, Qnil
);
3465 if (EQ (c
, make_number (040)))
3469 c
= read_char (0, 0, 0, Qnil
, 0, NULL
);
3470 while (BUFFERP (c
));
3479 /* Record a key that came from a mouse menu.
3480 Record it for echoing, for this-command-keys, and so on. */
3486 /* Wipe the echo area. */
3487 clear_message (1, 0);
3492 before_command_key_count
= this_command_key_count
;
3493 before_command_echo_length
= echo_length ();
3496 /* Don't echo mouse motion events. */
3497 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
3498 && NILP (Fzerop (Vecho_keystrokes
)))
3502 /* Once we reread a character, echoing can happen
3503 the next time we pause to read a new one. */
3504 ok_to_echo_at_next_pause
= 0;
3507 /* Record this character as part of the current key. */
3508 add_command_key (c
);
3510 /* Re-reading in the middle of a command */
3511 last_input_char
= c
;
3515 /* Return 1 if should recognize C as "the help character". */
3523 if (EQ (c
, Vhelp_char
))
3525 for (tail
= Vhelp_event_list
; CONSP (tail
); tail
= XCDR (tail
))
3526 if (EQ (c
, XCAR (tail
)))
3531 /* Record the input event C in various ways. */
3539 if (CONSP (c
) && (EQ (XCAR (c
), Qhelp_echo
) || EQ (XCAR (c
), Qmouse_movement
)))
3541 /* To avoid filling recent_keys with help-echo and mouse-movement
3542 events, we filter out repeated help-echo events, only store the
3543 first and last in a series of mouse-movement events, and don't
3544 store repeated help-echo events which are only separated by
3545 mouse-movement events. */
3547 Lisp_Object ev1
, ev2
, ev3
;
3550 if ((ix1
= recent_keys_index
- 1) < 0)
3551 ix1
= NUM_RECENT_KEYS
- 1;
3552 ev1
= AREF (recent_keys
, ix1
);
3554 if ((ix2
= ix1
- 1) < 0)
3555 ix2
= NUM_RECENT_KEYS
- 1;
3556 ev2
= AREF (recent_keys
, ix2
);
3558 if ((ix3
= ix2
- 1) < 0)
3559 ix3
= NUM_RECENT_KEYS
- 1;
3560 ev3
= AREF (recent_keys
, ix3
);
3562 if (EQ (XCAR (c
), Qhelp_echo
))
3564 /* Don't record `help-echo' in recent_keys unless it shows some help
3565 message, and a different help than the previously recorded
3567 Lisp_Object help
, last_help
;
3569 help
= Fcar_safe (Fcdr_safe (XCDR (c
)));
3570 if (!STRINGP (help
))
3572 else if (CONSP (ev1
) && EQ (XCAR (ev1
), Qhelp_echo
)
3573 && (last_help
= Fcar_safe (Fcdr_safe (XCDR (ev1
))), EQ (last_help
, help
)))
3575 else if (CONSP (ev1
) && EQ (XCAR (ev1
), Qmouse_movement
)
3576 && CONSP (ev2
) && EQ (XCAR (ev2
), Qhelp_echo
)
3577 && (last_help
= Fcar_safe (Fcdr_safe (XCDR (ev2
))), EQ (last_help
, help
)))
3579 else if (CONSP (ev1
) && EQ (XCAR (ev1
), Qmouse_movement
)
3580 && CONSP (ev2
) && EQ (XCAR (ev2
), Qmouse_movement
)
3581 && CONSP (ev3
) && EQ (XCAR (ev3
), Qhelp_echo
)
3582 && (last_help
= Fcar_safe (Fcdr_safe (XCDR (ev3
))), EQ (last_help
, help
)))
3585 else if (EQ (XCAR (c
), Qmouse_movement
))
3587 /* Only record one pair of `mouse-movement' on a window in recent_keys.
3588 So additional mouse movement events replace the last element. */
3589 Lisp_Object last_window
, window
;
3591 window
= Fcar_safe (Fcar_safe (XCDR (c
)));
3592 if (CONSP (ev1
) && EQ (XCAR (ev1
), Qmouse_movement
)
3593 && (last_window
= Fcar_safe (Fcar_safe (XCDR (ev1
))), EQ (last_window
, window
))
3594 && CONSP (ev2
) && EQ (XCAR (ev2
), Qmouse_movement
)
3595 && (last_window
= Fcar_safe (Fcar_safe (XCDR (ev2
))), EQ (last_window
, window
)))
3597 ASET (recent_keys
, ix1
, c
);
3603 store_kbd_macro_char (c
);
3608 ASET (recent_keys
, recent_keys_index
, c
);
3609 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
3610 recent_keys_index
= 0;
3612 else if (recorded
< 0)
3614 /* We need to remove one or two events from recent_keys.
3615 To do this, we simply put nil at those events and move the
3616 recent_keys_index backwards over those events. Usually,
3617 users will never see those nil events, as they will be
3618 overwritten by the command keys entered to see recent_keys
3621 while (recorded
++ < 0 && total_keys
> 0)
3623 if (total_keys
< NUM_RECENT_KEYS
)
3625 if (--recent_keys_index
< 0)
3626 recent_keys_index
= NUM_RECENT_KEYS
- 1;
3627 ASET (recent_keys
, recent_keys_index
, Qnil
);
3631 num_nonmacro_input_events
++;
3633 /* Write c to the dribble file. If c is a lispy event, write
3634 the event's symbol to the dribble file, in <brackets>. Bleaugh.
3635 If you, dear reader, have a better idea, you've got the source. :-) */
3641 if (XUINT (c
) < 0x100)
3642 putc (XINT (c
), dribble
);
3644 fprintf (dribble
, " 0x%x", (int) XUINT (c
));
3648 Lisp_Object dribblee
;
3650 /* If it's a structured event, take the event header. */
3651 dribblee
= EVENT_HEAD (c
);
3653 if (SYMBOLP (dribblee
))
3655 putc ('<', dribble
);
3656 fwrite (SDATA (SYMBOL_NAME (dribblee
)), sizeof (char),
3657 SBYTES (SYMBOL_NAME (dribblee
)),
3659 putc ('>', dribble
);
3672 struct buffer
*old
= current_buffer
;
3673 Fprinc (object
, Qnil
);
3674 set_buffer_internal (XBUFFER (Vstandard_output
));
3675 call0 (intern ("help-mode"));
3676 set_buffer_internal (old
);
3680 /* Copy out or in the info on where C-g should throw to.
3681 This is used when running Lisp code from within get_char,
3682 in case get_char is called recursively.
3683 See read_process_output. */
3689 bcopy (getcjmp
, temp
, sizeof getcjmp
);
3693 restore_getcjmp (temp
)
3696 bcopy (temp
, getcjmp
, sizeof getcjmp
);
3699 /* Low level keyboard/mouse input.
3700 kbd_buffer_store_event places events in kbd_buffer, and
3701 kbd_buffer_get_event retrieves them. */
3703 /* Return true if there are any events in the queue that read-char
3704 would return. If this returns false, a read-char would block. */
3706 readable_events (flags
)
3709 if (flags
& READABLE_EVENTS_DO_TIMERS_NOW
)
3712 /* If the buffer contains only FOCUS_IN_EVENT events, and
3713 READABLE_EVENTS_FILTER_EVENTS is set, report it as empty. */
3714 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3716 if (flags
& (READABLE_EVENTS_FILTER_EVENTS
3717 #ifdef USE_TOOLKIT_SCROLL_BARS
3718 | READABLE_EVENTS_IGNORE_SQUEEZABLES
3722 struct input_event
*event
;
3724 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
3731 #ifdef USE_TOOLKIT_SCROLL_BARS
3732 (flags
& READABLE_EVENTS_FILTER_EVENTS
) &&
3734 event
->kind
== FOCUS_IN_EVENT
)
3735 #ifdef USE_TOOLKIT_SCROLL_BARS
3736 && !((flags
& READABLE_EVENTS_IGNORE_SQUEEZABLES
)
3737 && event
->kind
== SCROLL_BAR_CLICK_EVENT
3738 && event
->part
== scroll_bar_handle
3739 && event
->modifiers
== 0)
3744 if (event
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3747 while (event
!= kbd_store_ptr
);
3753 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
3754 if (!(flags
& READABLE_EVENTS_IGNORE_SQUEEZABLES
)
3755 && !NILP (do_mouse_tracking
) && some_mouse_moved ())
3760 if (current_kboard
->kbd_queue_has_data
)
3766 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
3767 if (kb
->kbd_queue_has_data
)
3773 /* Set this for debugging, to have a way to get out */
3778 event_to_kboard (event
)
3779 struct input_event
*event
;
3782 frame
= event
->frame_or_window
;
3784 frame
= XCAR (frame
);
3785 else if (WINDOWP (frame
))
3786 frame
= WINDOW_FRAME (XWINDOW (frame
));
3788 /* There are still some events that don't set this field.
3789 For now, just ignore the problem.
3790 Also ignore dead frames here. */
3791 if (!FRAMEP (frame
) || !FRAME_LIVE_P (XFRAME (frame
)))
3794 return FRAME_KBOARD (XFRAME (frame
));
3799 Lisp_Object Vthrow_on_input
;
3801 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
3804 kbd_buffer_store_event (event
)
3805 register struct input_event
*event
;
3807 kbd_buffer_store_event_hold (event
, 0);
3810 /* Store EVENT obtained at interrupt level into kbd_buffer, fifo.
3812 If HOLD_QUIT is 0, just stuff EVENT into the fifo.
3813 Else, if HOLD_QUIT.kind != NO_EVENT, discard EVENT.
3814 Else, if EVENT is a quit event, store the quit event
3815 in HOLD_QUIT, and return (thus ignoring further events).
3817 This is used in read_avail_input to postpone the processing
3818 of the quit event until all subsequent input events have been
3819 parsed (and discarded).
3823 kbd_buffer_store_event_hold (event
, hold_quit
)
3824 register struct input_event
*event
;
3825 struct input_event
*hold_quit
;
3827 if (event
->kind
== NO_EVENT
)
3830 if (hold_quit
&& hold_quit
->kind
!= NO_EVENT
)
3833 if (event
->kind
== ASCII_KEYSTROKE_EVENT
)
3835 register int c
= event
->code
& 0377;
3837 if (event
->modifiers
& ctrl_modifier
)
3838 c
= make_ctrl_char (c
);
3840 c
|= (event
->modifiers
3841 & (meta_modifier
| alt_modifier
3842 | hyper_modifier
| super_modifier
));
3847 KBOARD
*kb
= FRAME_KBOARD (XFRAME (event
->frame_or_window
));
3848 struct input_event
*sp
;
3850 if (single_kboard
&& kb
!= current_kboard
)
3853 = Fcons (make_lispy_switch_frame (event
->frame_or_window
),
3854 Fcons (make_number (c
), Qnil
));
3855 kb
->kbd_queue_has_data
= 1;
3856 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
3858 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3861 if (event_to_kboard (sp
) == kb
)
3863 sp
->kind
= NO_EVENT
;
3864 sp
->frame_or_window
= Qnil
;
3874 bcopy (event
, (char *) hold_quit
, sizeof (*event
));
3878 /* If this results in a quit_char being returned to Emacs as
3879 input, set Vlast_event_frame properly. If this doesn't
3880 get returned to Emacs as an event, the next event read
3881 will set Vlast_event_frame again, so this is safe to do. */
3885 focus
= FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
3887 focus
= event
->frame_or_window
;
3888 internal_last_event_frame
= focus
;
3889 Vlast_event_frame
= focus
;
3892 last_event_timestamp
= event
->timestamp
;
3893 handle_interrupt ();
3897 if (c
&& c
== stop_character
)
3903 /* Don't insert two BUFFER_SWITCH_EVENT's in a row.
3904 Just ignore the second one. */
3905 else if (event
->kind
== BUFFER_SWITCH_EVENT
3906 && kbd_fetch_ptr
!= kbd_store_ptr
3907 && ((kbd_store_ptr
== kbd_buffer
3908 ? kbd_buffer
+ KBD_BUFFER_SIZE
- 1
3909 : kbd_store_ptr
- 1)->kind
) == BUFFER_SWITCH_EVENT
)
3912 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
3913 kbd_store_ptr
= kbd_buffer
;
3915 /* Don't let the very last slot in the buffer become full,
3916 since that would make the two pointers equal,
3917 and that is indistinguishable from an empty buffer.
3918 Discard the event if it would fill the last slot. */
3919 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
3921 *kbd_store_ptr
= *event
;
3925 /* If we're inside while-no-input, and this event qualifies
3926 as input, set quit-flag to cause an interrupt. */
3927 if (!NILP (Vthrow_on_input
)
3928 && event
->kind
!= FOCUS_IN_EVENT
3929 && event
->kind
!= HELP_EVENT
3930 && event
->kind
!= DEICONIFY_EVENT
)
3932 Vquit_flag
= Vthrow_on_input
;
3933 /* If we're inside a function that wants immediate quits,
3935 if (immediate_quit
&& NILP (Vinhibit_quit
))
3945 /* Put an input event back in the head of the event queue. */
3948 kbd_buffer_unget_event (event
)
3949 register struct input_event
*event
;
3951 if (kbd_fetch_ptr
== kbd_buffer
)
3952 kbd_fetch_ptr
= kbd_buffer
+ KBD_BUFFER_SIZE
;
3954 /* Don't let the very last slot in the buffer become full, */
3955 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
3958 *kbd_fetch_ptr
= *event
;
3963 /* Generate HELP_EVENT input_events in BUFP which has room for
3964 SIZE events. If there's not enough room in BUFP, ignore this
3967 HELP is the help form.
3969 FRAME is the frame on which the help is generated. OBJECT is the
3970 Lisp object where the help was found (a buffer, a string, an
3971 overlay, or nil if neither from a string nor from a buffer. POS is
3972 the position within OBJECT where the help was found.
3974 Value is the number of input_events generated. */
3977 gen_help_event (help
, frame
, window
, object
, pos
)
3978 Lisp_Object help
, frame
, object
, window
;
3981 struct input_event event
;
3985 event
.kind
= HELP_EVENT
;
3986 event
.frame_or_window
= frame
;
3988 event
.x
= WINDOWP (window
) ? window
: frame
;
3991 kbd_buffer_store_event (&event
);
3995 /* Store HELP_EVENTs for HELP on FRAME in the input queue. */
3998 kbd_buffer_store_help_event (frame
, help
)
3999 Lisp_Object frame
, help
;
4001 struct input_event event
;
4003 event
.kind
= HELP_EVENT
;
4004 event
.frame_or_window
= frame
;
4009 kbd_buffer_store_event (&event
);
4013 /* Discard any mouse events in the event buffer by setting them to
4016 discard_mouse_events ()
4018 struct input_event
*sp
;
4019 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
4021 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
4024 if (sp
->kind
== MOUSE_CLICK_EVENT
4025 || sp
->kind
== WHEEL_EVENT
4026 || sp
->kind
== HORIZ_WHEEL_EVENT
4028 || sp
->kind
== W32_SCROLL_BAR_CLICK_EVENT
4031 || sp
->kind
== GPM_CLICK_EVENT
4033 || sp
->kind
== SCROLL_BAR_CLICK_EVENT
)
4035 sp
->kind
= NO_EVENT
;
4041 /* Return non-zero if there are any real events waiting in the event
4042 buffer, not counting `NO_EVENT's.
4044 If DISCARD is non-zero, discard NO_EVENT events at the front of
4045 the input queue, possibly leaving the input queue empty if there
4046 are no real input events. */
4049 kbd_buffer_events_waiting (discard
)
4052 struct input_event
*sp
;
4054 for (sp
= kbd_fetch_ptr
;
4055 sp
!= kbd_store_ptr
&& sp
->kind
== NO_EVENT
;
4058 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
4065 return sp
!= kbd_store_ptr
&& sp
->kind
!= NO_EVENT
;
4069 /* Clear input event EVENT. */
4073 struct input_event
*event
;
4075 event
->kind
= NO_EVENT
;
4079 /* Read one event from the event buffer, waiting if necessary.
4080 The value is a Lisp object representing the event.
4081 The value is nil for an event that should be ignored,
4082 or that was handled here.
4083 We always read and discard one event. */
4086 kbd_buffer_get_event (kbp
, used_mouse_menu
, end_time
)
4088 int *used_mouse_menu
;
4089 EMACS_TIME
*end_time
;
4098 *kbp
= current_kboard
;
4102 /* Wait until there is input available. */
4105 /* Break loop if there's an unread command event. Needed in
4106 moused window autoselection which uses a timer to insert such
4108 if (CONSP (Vunread_command_events
))
4111 if (kbd_fetch_ptr
!= kbd_store_ptr
)
4113 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
4114 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
4118 /* If the quit flag is set, then read_char will return
4119 quit_char, so that counts as "available input." */
4120 if (!NILP (Vquit_flag
))
4121 quit_throw_to_read_char ();
4123 /* One way or another, wait until input is available; then, if
4124 interrupt handlers have not read it, read it now. */
4127 wait_for_kbd_input ();
4129 /* Note SIGIO has been undef'd if FIONREAD is missing. */
4133 if (kbd_fetch_ptr
!= kbd_store_ptr
)
4135 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
4136 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
4141 EMACS_TIME duration
;
4142 EMACS_GET_TIME (duration
);
4143 if (EMACS_TIME_GE (duration
, *end_time
))
4144 return Qnil
; /* finished waiting */
4147 EMACS_SUB_TIME (duration
, *end_time
, duration
);
4148 wait_reading_process_output (EMACS_SECS (duration
),
4149 EMACS_USECS (duration
),
4150 -1, 1, Qnil
, NULL
, 0);
4154 wait_reading_process_output (0, 0, -1, 1, Qnil
, NULL
, 0);
4156 if (!interrupt_input
&& kbd_fetch_ptr
== kbd_store_ptr
)
4157 /* Pass 1 for EXPECT since we just waited to have input. */
4158 read_avail_input (1);
4159 #endif /* not VMS */
4162 if (CONSP (Vunread_command_events
))
4165 first
= XCAR (Vunread_command_events
);
4166 Vunread_command_events
= XCDR (Vunread_command_events
);
4167 *kbp
= current_kboard
;
4171 /* At this point, we know that there is a readable event available
4172 somewhere. If the event queue is empty, then there must be a
4173 mouse movement enabled and available. */
4174 if (kbd_fetch_ptr
!= kbd_store_ptr
)
4176 struct input_event
*event
;
4178 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
4182 last_event_timestamp
= event
->timestamp
;
4185 *kbp
= event_to_kboard (event
);
4187 *kbp
= current_kboard
; /* Better than returning null ptr? */
4189 *kbp
= &the_only_kboard
;
4194 /* These two kinds of events get special handling
4195 and don't actually appear to the command loop.
4196 We return nil for them. */
4197 if (event
->kind
== SELECTION_REQUEST_EVENT
4198 || event
->kind
== SELECTION_CLEAR_EVENT
)
4201 struct input_event copy
;
4203 /* Remove it from the buffer before processing it,
4204 since otherwise swallow_events will see it
4205 and process it again. */
4207 kbd_fetch_ptr
= event
+ 1;
4208 input_pending
= readable_events (0);
4209 x_handle_selection_event (©
);
4211 /* We're getting selection request events, but we don't have
4217 #if defined (HAVE_X11) || defined (HAVE_NTGUI) || defined (MAC_OS)
4218 else if (event
->kind
== DELETE_WINDOW_EVENT
)
4220 /* Make an event (delete-frame (FRAME)). */
4221 obj
= Fcons (event
->frame_or_window
, Qnil
);
4222 obj
= Fcons (Qdelete_frame
, Fcons (obj
, Qnil
));
4223 kbd_fetch_ptr
= event
+ 1;
4226 #if defined (HAVE_X11) || defined (HAVE_NTGUI) || defined (MAC_OS)
4227 else if (event
->kind
== ICONIFY_EVENT
)
4229 /* Make an event (iconify-frame (FRAME)). */
4230 obj
= Fcons (event
->frame_or_window
, Qnil
);
4231 obj
= Fcons (Qiconify_frame
, Fcons (obj
, Qnil
));
4232 kbd_fetch_ptr
= event
+ 1;
4234 else if (event
->kind
== DEICONIFY_EVENT
)
4236 /* Make an event (make-frame-visible (FRAME)). */
4237 obj
= Fcons (event
->frame_or_window
, Qnil
);
4238 obj
= Fcons (Qmake_frame_visible
, Fcons (obj
, Qnil
));
4239 kbd_fetch_ptr
= event
+ 1;
4242 else if (event
->kind
== BUFFER_SWITCH_EVENT
)
4244 /* The value doesn't matter here; only the type is tested. */
4245 XSETBUFFER (obj
, current_buffer
);
4246 kbd_fetch_ptr
= event
+ 1;
4248 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
4249 || defined (USE_GTK)
4250 else if (event
->kind
== MENU_BAR_ACTIVATE_EVENT
)
4252 kbd_fetch_ptr
= event
+ 1;
4253 input_pending
= readable_events (0);
4254 if (FRAME_LIVE_P (XFRAME (event
->frame_or_window
)))
4255 x_activate_menubar (XFRAME (event
->frame_or_window
));
4258 #if defined (WINDOWSNT) || defined (MAC_OS)
4259 else if (event
->kind
== LANGUAGE_CHANGE_EVENT
)
4262 /* Make an event (language-change (KEY_SCRIPT)). */
4263 obj
= Fcons (make_number (event
->code
), Qnil
);
4265 /* Make an event (language-change (FRAME CHARSET LCID)). */
4266 obj
= Fcons (event
->frame_or_window
, Qnil
);
4268 obj
= Fcons (Qlanguage_change
, Fcons (obj
, Qnil
));
4269 kbd_fetch_ptr
= event
+ 1;
4272 else if (event
->kind
== SAVE_SESSION_EVENT
)
4274 obj
= Fcons (Qsave_session
, Qnil
);
4275 kbd_fetch_ptr
= event
+ 1;
4277 /* Just discard these, by returning nil.
4278 With MULTI_KBOARD, these events are used as placeholders
4279 when we need to randomly delete events from the queue.
4280 (They shouldn't otherwise be found in the buffer,
4281 but on some machines it appears they do show up
4282 even without MULTI_KBOARD.) */
4283 /* On Windows NT/9X, NO_EVENT is used to delete extraneous
4284 mouse events during a popup-menu call. */
4285 else if (event
->kind
== NO_EVENT
)
4286 kbd_fetch_ptr
= event
+ 1;
4287 else if (event
->kind
== HELP_EVENT
)
4289 Lisp_Object object
, position
, help
, frame
, window
;
4291 frame
= event
->frame_or_window
;
4292 object
= event
->arg
;
4293 position
= make_number (event
->code
);
4296 clear_event (event
);
4298 kbd_fetch_ptr
= event
+ 1;
4299 if (!WINDOWP (window
))
4301 obj
= Fcons (Qhelp_echo
,
4302 list5 (frame
, help
, window
, object
, position
));
4304 else if (event
->kind
== FOCUS_IN_EVENT
)
4306 /* Notification of a FocusIn event. The frame receiving the
4307 focus is in event->frame_or_window. Generate a
4308 switch-frame event if necessary. */
4309 Lisp_Object frame
, focus
;
4311 frame
= event
->frame_or_window
;
4312 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
4316 if (!EQ (frame
, internal_last_event_frame
)
4317 && !EQ (frame
, selected_frame
))
4318 obj
= make_lispy_switch_frame (frame
);
4319 internal_last_event_frame
= frame
;
4320 kbd_fetch_ptr
= event
+ 1;
4324 /* If this event is on a different frame, return a switch-frame this
4325 time, and leave the event in the queue for next time. */
4329 frame
= event
->frame_or_window
;
4331 frame
= XCAR (frame
);
4332 else if (WINDOWP (frame
))
4333 frame
= WINDOW_FRAME (XWINDOW (frame
));
4335 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
4339 if (! EQ (frame
, internal_last_event_frame
)
4340 && !EQ (frame
, selected_frame
))
4341 obj
= make_lispy_switch_frame (frame
);
4342 internal_last_event_frame
= frame
;
4344 /* If we didn't decide to make a switch-frame event, go ahead
4345 and build a real event from the queue entry. */
4349 obj
= make_lispy_event (event
);
4351 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined(MAC_OS) \
4352 || defined (USE_GTK)
4353 /* If this was a menu selection, then set the flag to inhibit
4354 writing to last_nonmenu_event. Don't do this if the event
4355 we're returning is (menu-bar), though; that indicates the
4356 beginning of the menu sequence, and we might as well leave
4357 that as the `event with parameters' for this selection. */
4359 && !EQ (event
->frame_or_window
, event
->arg
)
4360 && (event
->kind
== MENU_BAR_EVENT
4361 || event
->kind
== TOOL_BAR_EVENT
))
4362 *used_mouse_menu
= 1;
4365 /* Wipe out this event, to catch bugs. */
4366 clear_event (event
);
4367 kbd_fetch_ptr
= event
+ 1;
4371 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
4372 /* Try generating a mouse motion event. */
4373 else if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
4375 FRAME_PTR f
= some_mouse_moved ();
4376 Lisp_Object bar_window
;
4377 enum scroll_bar_part part
;
4381 *kbp
= current_kboard
;
4382 /* Note that this uses F to determine which terminal to look at.
4383 If there is no valid info, it does not store anything
4384 so x remains nil. */
4387 /* XXX Can f or mouse_position_hook be NULL here? */
4388 if (f
&& FRAME_TERMINAL (f
)->mouse_position_hook
)
4389 (*FRAME_TERMINAL (f
)->mouse_position_hook
) (&f
, 0, &bar_window
,
4390 &part
, &x
, &y
, &time
);
4394 /* Decide if we should generate a switch-frame event. Don't
4395 generate switch-frame events for motion outside of all Emacs
4401 frame
= FRAME_FOCUS_FRAME (f
);
4403 XSETFRAME (frame
, f
);
4405 if (! EQ (frame
, internal_last_event_frame
)
4406 && !EQ (frame
, selected_frame
))
4407 obj
= make_lispy_switch_frame (frame
);
4408 internal_last_event_frame
= frame
;
4411 /* If we didn't decide to make a switch-frame event, go ahead and
4412 return a mouse-motion event. */
4413 if (!NILP (x
) && NILP (obj
))
4414 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
4416 #endif /* HAVE_MOUSE || HAVE GPM */
4418 /* We were promised by the above while loop that there was
4419 something for us to read! */
4422 input_pending
= readable_events (0);
4424 Vlast_event_frame
= internal_last_event_frame
;
4429 /* Process any events that are not user-visible,
4430 then return, without reading any user-visible events. */
4433 swallow_events (do_display
)
4438 while (kbd_fetch_ptr
!= kbd_store_ptr
)
4440 struct input_event
*event
;
4442 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
4446 last_event_timestamp
= event
->timestamp
;
4448 /* These two kinds of events get special handling
4449 and don't actually appear to the command loop. */
4450 if (event
->kind
== SELECTION_REQUEST_EVENT
4451 || event
->kind
== SELECTION_CLEAR_EVENT
)
4454 struct input_event copy
;
4456 /* Remove it from the buffer before processing it,
4457 since otherwise swallow_events called recursively could see it
4458 and process it again. */
4460 kbd_fetch_ptr
= event
+ 1;
4461 input_pending
= readable_events (0);
4462 x_handle_selection_event (©
);
4464 /* We're getting selection request events, but we don't have
4473 old_timers_run
= timers_run
;
4474 get_input_pending (&input_pending
, READABLE_EVENTS_DO_TIMERS_NOW
);
4476 if (timers_run
!= old_timers_run
&& do_display
)
4477 redisplay_preserve_echo_area (7);
4480 /* Record the start of when Emacs is idle,
4481 for the sake of running idle-time timers. */
4488 /* If we are already in the idle state, do nothing. */
4489 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
4492 EMACS_GET_TIME (timer_idleness_start_time
);
4494 timer_last_idleness_start_time
= timer_idleness_start_time
;
4496 /* Mark all idle-time timers as once again candidates for running. */
4497 for (timers
= Vtimer_idle_list
; CONSP (timers
); timers
= XCDR (timers
))
4501 timer
= XCAR (timers
);
4503 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
4505 XVECTOR (timer
)->contents
[0] = Qnil
;
4509 /* Record that Emacs is no longer idle, so stop running idle-time timers. */
4514 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
4517 /* Resume idle timer from last idle start time. */
4520 timer_resume_idle ()
4522 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
4525 timer_idleness_start_time
= timer_last_idleness_start_time
;
4528 /* This is only for debugging. */
4529 struct input_event last_timer_event
;
4531 /* Check whether a timer has fired. To prevent larger problems we simply
4532 disregard elements that are not proper timers. Do not make a circular
4533 timer list for the time being.
4535 Returns the number of seconds to wait until the next timer fires. If a
4536 timer is triggering now, return zero seconds.
4537 If no timer is active, return -1 seconds.
4539 If a timer is ripe, we run it, with quitting turned off.
4541 DO_IT_NOW is now ignored. It used to mean that we should
4542 run the timer directly instead of queueing a timer-event.
4543 Now we always run timers directly. */
4546 timer_check (do_it_now
)
4549 EMACS_TIME nexttime
;
4550 EMACS_TIME now
, idleness_now
;
4551 Lisp_Object timers
, idle_timers
, chosen_timer
;
4552 struct gcpro gcpro1
, gcpro2
, gcpro3
;
4554 EMACS_SET_SECS (nexttime
, -1);
4555 EMACS_SET_USECS (nexttime
, -1);
4557 /* Always consider the ordinary timers. */
4558 timers
= Vtimer_list
;
4559 /* Consider the idle timers only if Emacs is idle. */
4560 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
4561 idle_timers
= Vtimer_idle_list
;
4564 chosen_timer
= Qnil
;
4565 GCPRO3 (timers
, idle_timers
, chosen_timer
);
4567 if (CONSP (timers
) || CONSP (idle_timers
))
4569 EMACS_GET_TIME (now
);
4570 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
4571 EMACS_SUB_TIME (idleness_now
, now
, timer_idleness_start_time
);
4574 while (CONSP (timers
) || CONSP (idle_timers
))
4576 Lisp_Object
*vector
;
4577 Lisp_Object timer
= Qnil
, idle_timer
= Qnil
;
4578 EMACS_TIME timer_time
, idle_timer_time
;
4579 EMACS_TIME difference
, timer_difference
, idle_timer_difference
;
4581 /* Skip past invalid timers and timers already handled. */
4584 timer
= XCAR (timers
);
4585 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
4587 timers
= XCDR (timers
);
4590 vector
= XVECTOR (timer
)->contents
;
4592 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
4593 || !INTEGERP (vector
[3])
4594 || ! NILP (vector
[0]))
4596 timers
= XCDR (timers
);
4600 if (!NILP (idle_timers
))
4602 timer
= XCAR (idle_timers
);
4603 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
4605 idle_timers
= XCDR (idle_timers
);
4608 vector
= XVECTOR (timer
)->contents
;
4610 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
4611 || !INTEGERP (vector
[3])
4612 || ! NILP (vector
[0]))
4614 idle_timers
= XCDR (idle_timers
);
4619 /* Set TIMER, TIMER_TIME and TIMER_DIFFERENCE
4620 based on the next ordinary timer.
4621 TIMER_DIFFERENCE is the distance in time from NOW to when
4622 this timer becomes ripe (negative if it's already ripe). */
4625 timer
= XCAR (timers
);
4626 vector
= XVECTOR (timer
)->contents
;
4627 EMACS_SET_SECS (timer_time
,
4628 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
4629 EMACS_SET_USECS (timer_time
, XINT (vector
[3]));
4630 EMACS_SUB_TIME (timer_difference
, timer_time
, now
);
4633 /* Set IDLE_TIMER, IDLE_TIMER_TIME and IDLE_TIMER_DIFFERENCE
4634 based on the next idle timer. */
4635 if (!NILP (idle_timers
))
4637 idle_timer
= XCAR (idle_timers
);
4638 vector
= XVECTOR (idle_timer
)->contents
;
4639 EMACS_SET_SECS (idle_timer_time
,
4640 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
4641 EMACS_SET_USECS (idle_timer_time
, XINT (vector
[3]));
4642 EMACS_SUB_TIME (idle_timer_difference
, idle_timer_time
, idleness_now
);
4645 /* Decide which timer is the next timer,
4646 and set CHOSEN_TIMER, VECTOR and DIFFERENCE accordingly.
4647 Also step down the list where we found that timer. */
4649 if (! NILP (timers
) && ! NILP (idle_timers
))
4652 EMACS_SUB_TIME (temp
, timer_difference
, idle_timer_difference
);
4653 if (EMACS_TIME_NEG_P (temp
))
4655 chosen_timer
= timer
;
4656 timers
= XCDR (timers
);
4657 difference
= timer_difference
;
4661 chosen_timer
= idle_timer
;
4662 idle_timers
= XCDR (idle_timers
);
4663 difference
= idle_timer_difference
;
4666 else if (! NILP (timers
))
4668 chosen_timer
= timer
;
4669 timers
= XCDR (timers
);
4670 difference
= timer_difference
;
4674 chosen_timer
= idle_timer
;
4675 idle_timers
= XCDR (idle_timers
);
4676 difference
= idle_timer_difference
;
4678 vector
= XVECTOR (chosen_timer
)->contents
;
4680 /* If timer is ripe, run it if it hasn't been run. */
4681 if (EMACS_TIME_NEG_P (difference
)
4682 || (EMACS_SECS (difference
) == 0
4683 && EMACS_USECS (difference
) == 0))
4685 if (NILP (vector
[0]))
4687 int count
= SPECPDL_INDEX ();
4688 Lisp_Object old_deactivate_mark
= Vdeactivate_mark
;
4690 #if 0 /* This shouldn't be necessary anymore. --lorentey */
4691 /* On unbind_to, resume allowing input from any kboard, if that
4693 record_single_kboard_state ();
4695 /* Mark the timer as triggered to prevent problems if the lisp
4696 code fails to reschedule it right. */
4699 specbind (Qinhibit_quit
, Qt
);
4701 call1 (Qtimer_event_handler
, chosen_timer
);
4702 Vdeactivate_mark
= old_deactivate_mark
;
4704 unbind_to (count
, Qnil
);
4706 /* Since we have handled the event,
4707 we don't need to tell the caller to wake up and do it. */
4711 /* When we encounter a timer that is still waiting,
4712 return the amount of time to wait before it is ripe. */
4719 /* No timers are pending in the future. */
4720 /* Return 0 if we generated an event, and -1 if not. */
4725 DEFUN ("current-idle-time", Fcurrent_idle_time
, Scurrent_idle_time
, 0, 0, 0,
4726 doc
: /* Return the current length of Emacs idleness.
4727 The value is returned as a list of three integers. The first has the
4728 most significant 16 bits of the seconds, while the second has the
4729 least significant 16 bits. The third integer gives the microsecond
4732 The microsecond count is zero on systems that do not provide
4733 resolution finer than a second. */)
4736 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
4738 EMACS_TIME now
, idleness_now
;
4740 EMACS_GET_TIME (now
);
4741 EMACS_SUB_TIME (idleness_now
, now
, timer_idleness_start_time
);
4743 return list3 (make_number ((EMACS_SECS (idleness_now
) >> 16) & 0xffff),
4744 make_number ((EMACS_SECS (idleness_now
) >> 0) & 0xffff),
4745 make_number (EMACS_USECS (idleness_now
)));
4751 /* Caches for modify_event_symbol. */
4752 static Lisp_Object accent_key_syms
;
4753 static Lisp_Object func_key_syms
;
4754 static Lisp_Object mouse_syms
;
4755 static Lisp_Object wheel_syms
;
4756 static Lisp_Object drag_n_drop_syms
;
4758 /* This is a list of keysym codes for special "accent" characters.
4759 It parallels lispy_accent_keys. */
4761 static int lispy_accent_codes
[] =
4763 #ifdef XK_dead_circumflex
4768 #ifdef XK_dead_grave
4773 #ifdef XK_dead_tilde
4778 #ifdef XK_dead_diaeresis
4783 #ifdef XK_dead_macron
4788 #ifdef XK_dead_degree
4793 #ifdef XK_dead_acute
4798 #ifdef XK_dead_cedilla
4803 #ifdef XK_dead_breve
4808 #ifdef XK_dead_ogonek
4813 #ifdef XK_dead_caron
4818 #ifdef XK_dead_doubleacute
4819 XK_dead_doubleacute
,
4823 #ifdef XK_dead_abovedot
4828 #ifdef XK_dead_abovering
4838 #ifdef XK_dead_belowdot
4843 #ifdef XK_dead_voiced_sound
4844 XK_dead_voiced_sound
,
4848 #ifdef XK_dead_semivoiced_sound
4849 XK_dead_semivoiced_sound
,
4865 /* This is a list of Lisp names for special "accent" characters.
4866 It parallels lispy_accent_codes. */
4868 static char *lispy_accent_keys
[] =
4886 "dead-voiced-sound",
4887 "dead-semivoiced-sound",
4893 #define FUNCTION_KEY_OFFSET 0x0
4895 char *lispy_function_keys
[] =
4899 0, /* VK_LBUTTON 0x01 */
4900 0, /* VK_RBUTTON 0x02 */
4901 "cancel", /* VK_CANCEL 0x03 */
4902 0, /* VK_MBUTTON 0x04 */
4904 0, 0, 0, /* 0x05 .. 0x07 */
4906 "backspace", /* VK_BACK 0x08 */
4907 "tab", /* VK_TAB 0x09 */
4909 0, 0, /* 0x0A .. 0x0B */
4911 "clear", /* VK_CLEAR 0x0C */
4912 "return", /* VK_RETURN 0x0D */
4914 0, 0, /* 0x0E .. 0x0F */
4916 0, /* VK_SHIFT 0x10 */
4917 0, /* VK_CONTROL 0x11 */
4918 0, /* VK_MENU 0x12 */
4919 "pause", /* VK_PAUSE 0x13 */
4920 "capslock", /* VK_CAPITAL 0x14 */
4922 0, 0, 0, 0, 0, 0, /* 0x15 .. 0x1A */
4924 "escape", /* VK_ESCAPE 0x1B */
4926 0, 0, 0, 0, /* 0x1C .. 0x1F */
4928 0, /* VK_SPACE 0x20 */
4929 "prior", /* VK_PRIOR 0x21 */
4930 "next", /* VK_NEXT 0x22 */
4931 "end", /* VK_END 0x23 */
4932 "home", /* VK_HOME 0x24 */
4933 "left", /* VK_LEFT 0x25 */
4934 "up", /* VK_UP 0x26 */
4935 "right", /* VK_RIGHT 0x27 */
4936 "down", /* VK_DOWN 0x28 */
4937 "select", /* VK_SELECT 0x29 */
4938 "print", /* VK_PRINT 0x2A */
4939 "execute", /* VK_EXECUTE 0x2B */
4940 "snapshot", /* VK_SNAPSHOT 0x2C */
4941 "insert", /* VK_INSERT 0x2D */
4942 "delete", /* VK_DELETE 0x2E */
4943 "help", /* VK_HELP 0x2F */
4945 /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
4947 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4949 0, 0, 0, 0, 0, 0, 0, /* 0x3A .. 0x40 */
4951 /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
4953 0, 0, 0, 0, 0, 0, 0, 0, 0,
4954 0, 0, 0, 0, 0, 0, 0, 0, 0,
4955 0, 0, 0, 0, 0, 0, 0, 0,
4957 "lwindow", /* VK_LWIN 0x5B */
4958 "rwindow", /* VK_RWIN 0x5C */
4959 "apps", /* VK_APPS 0x5D */
4961 0, 0, /* 0x5E .. 0x5F */
4963 "kp-0", /* VK_NUMPAD0 0x60 */
4964 "kp-1", /* VK_NUMPAD1 0x61 */
4965 "kp-2", /* VK_NUMPAD2 0x62 */
4966 "kp-3", /* VK_NUMPAD3 0x63 */
4967 "kp-4", /* VK_NUMPAD4 0x64 */
4968 "kp-5", /* VK_NUMPAD5 0x65 */
4969 "kp-6", /* VK_NUMPAD6 0x66 */
4970 "kp-7", /* VK_NUMPAD7 0x67 */
4971 "kp-8", /* VK_NUMPAD8 0x68 */
4972 "kp-9", /* VK_NUMPAD9 0x69 */
4973 "kp-multiply", /* VK_MULTIPLY 0x6A */
4974 "kp-add", /* VK_ADD 0x6B */
4975 "kp-separator", /* VK_SEPARATOR 0x6C */
4976 "kp-subtract", /* VK_SUBTRACT 0x6D */
4977 "kp-decimal", /* VK_DECIMAL 0x6E */
4978 "kp-divide", /* VK_DIVIDE 0x6F */
4979 "f1", /* VK_F1 0x70 */
4980 "f2", /* VK_F2 0x71 */
4981 "f3", /* VK_F3 0x72 */
4982 "f4", /* VK_F4 0x73 */
4983 "f5", /* VK_F5 0x74 */
4984 "f6", /* VK_F6 0x75 */
4985 "f7", /* VK_F7 0x76 */
4986 "f8", /* VK_F8 0x77 */
4987 "f9", /* VK_F9 0x78 */
4988 "f10", /* VK_F10 0x79 */
4989 "f11", /* VK_F11 0x7A */
4990 "f12", /* VK_F12 0x7B */
4991 "f13", /* VK_F13 0x7C */
4992 "f14", /* VK_F14 0x7D */
4993 "f15", /* VK_F15 0x7E */
4994 "f16", /* VK_F16 0x7F */
4995 "f17", /* VK_F17 0x80 */
4996 "f18", /* VK_F18 0x81 */
4997 "f19", /* VK_F19 0x82 */
4998 "f20", /* VK_F20 0x83 */
4999 "f21", /* VK_F21 0x84 */
5000 "f22", /* VK_F22 0x85 */
5001 "f23", /* VK_F23 0x86 */
5002 "f24", /* VK_F24 0x87 */
5004 0, 0, 0, 0, /* 0x88 .. 0x8B */
5005 0, 0, 0, 0, /* 0x8C .. 0x8F */
5007 "kp-numlock", /* VK_NUMLOCK 0x90 */
5008 "scroll", /* VK_SCROLL 0x91 */
5010 "kp-space", /* VK_NUMPAD_CLEAR 0x92 */
5011 "kp-enter", /* VK_NUMPAD_ENTER 0x93 */
5012 "kp-prior", /* VK_NUMPAD_PRIOR 0x94 */
5013 "kp-next", /* VK_NUMPAD_NEXT 0x95 */
5014 "kp-end", /* VK_NUMPAD_END 0x96 */
5015 "kp-home", /* VK_NUMPAD_HOME 0x97 */
5016 "kp-left", /* VK_NUMPAD_LEFT 0x98 */
5017 "kp-up", /* VK_NUMPAD_UP 0x99 */
5018 "kp-right", /* VK_NUMPAD_RIGHT 0x9A */
5019 "kp-down", /* VK_NUMPAD_DOWN 0x9B */
5020 "kp-insert", /* VK_NUMPAD_INSERT 0x9C */
5021 "kp-delete", /* VK_NUMPAD_DELETE 0x9D */
5023 0, 0, /* 0x9E .. 0x9F */
5026 * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
5027 * Used only as parameters to GetAsyncKeyState and GetKeyState.
5028 * No other API or message will distinguish left and right keys this way.
5032 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5033 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5034 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5035 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5036 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5042 "attn", /* VK_ATTN 0xF6 */
5043 "crsel", /* VK_CRSEL 0xF7 */
5044 "exsel", /* VK_EXSEL 0xF8 */
5045 "ereof", /* VK_EREOF 0xF9 */
5046 "play", /* VK_PLAY 0xFA */
5047 "zoom", /* VK_ZOOM 0xFB */
5048 "noname", /* VK_NONAME 0xFC */
5049 "pa1", /* VK_PA1 0xFD */
5050 "oem_clear", /* VK_OEM_CLEAR 0xFE */
5054 #else /* not HAVE_NTGUI */
5056 /* This should be dealt with in XTread_socket now, and that doesn't
5057 depend on the client system having the Kana syms defined. See also
5058 the XK_kana_A case below. */
5061 static char *lispy_kana_keys
[] =
5063 /* X Keysym value */
5064 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x400 .. 0x40f */
5065 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x410 .. 0x41f */
5066 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x420 .. 0x42f */
5067 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x430 .. 0x43f */
5068 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x440 .. 0x44f */
5069 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x450 .. 0x45f */
5070 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x460 .. 0x46f */
5071 0,0,0,0,0,0,0,0,0,0,0,0,0,0,"overline",0,
5072 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x480 .. 0x48f */
5073 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x490 .. 0x49f */
5074 0, "kana-fullstop", "kana-openingbracket", "kana-closingbracket",
5075 "kana-comma", "kana-conjunctive", "kana-WO", "kana-a",
5076 "kana-i", "kana-u", "kana-e", "kana-o",
5077 "kana-ya", "kana-yu", "kana-yo", "kana-tsu",
5078 "prolongedsound", "kana-A", "kana-I", "kana-U",
5079 "kana-E", "kana-O", "kana-KA", "kana-KI",
5080 "kana-KU", "kana-KE", "kana-KO", "kana-SA",
5081 "kana-SHI", "kana-SU", "kana-SE", "kana-SO",
5082 "kana-TA", "kana-CHI", "kana-TSU", "kana-TE",
5083 "kana-TO", "kana-NA", "kana-NI", "kana-NU",
5084 "kana-NE", "kana-NO", "kana-HA", "kana-HI",
5085 "kana-FU", "kana-HE", "kana-HO", "kana-MA",
5086 "kana-MI", "kana-MU", "kana-ME", "kana-MO",
5087 "kana-YA", "kana-YU", "kana-YO", "kana-RA",
5088 "kana-RI", "kana-RU", "kana-RE", "kana-RO",
5089 "kana-WA", "kana-N", "voicedsound", "semivoicedsound",
5090 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4e0 .. 0x4ef */
5091 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4f0 .. 0x4ff */
5093 #endif /* XK_kana_A */
5096 #define FUNCTION_KEY_OFFSET 0xff00
5098 /* You'll notice that this table is arranged to be conveniently
5099 indexed by X Windows keysym values. */
5100 static char *lispy_function_keys
[] =
5102 /* X Keysym value */
5104 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00...0f */
5105 "backspace", "tab", "linefeed", "clear",
5107 0, 0, 0, "pause", /* 0xff10...1f */
5108 0, 0, 0, 0, 0, 0, 0, "escape",
5110 0, "kanji", "muhenkan", "henkan", /* 0xff20...2f */
5111 "romaji", "hiragana", "katakana", "hiragana-katakana",
5112 "zenkaku", "hankaku", "zenkaku-hankaku", "touroku",
5113 "massyo", "kana-lock", "kana-shift", "eisu-shift",
5114 "eisu-toggle", /* 0xff30...3f */
5115 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5116 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
5118 "home", "left", "up", "right", /* 0xff50 */ /* IsCursorKey */
5119 "down", "prior", "next", "end",
5120 "begin", 0, 0, 0, 0, 0, 0, 0,
5121 "select", /* 0xff60 */ /* IsMiscFunctionKey */
5132 "break", /* 0xff6b */
5135 0, 0, 0, 0, "backtab", 0, 0, 0, /* 0xff70... */
5136 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff78... */
5137 "kp-space", /* 0xff80 */ /* IsKeypadKey */
5138 0, 0, 0, 0, 0, 0, 0, 0,
5139 "kp-tab", /* 0xff89 */
5141 "kp-enter", /* 0xff8d */
5143 "kp-f1", /* 0xff91 */
5147 "kp-home", /* 0xff95 */
5152 "kp-prior", /* kp-page-up */
5153 "kp-next", /* kp-page-down */
5159 0, 0, 0, 0, 0, 0, 0, 0, 0,
5160 "kp-multiply", /* 0xffaa */
5165 "kp-divide", /* 0xffaf */
5166 "kp-0", /* 0xffb0 */
5167 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
5170 "kp-equal", /* 0xffbd */
5171 "f1", /* 0xffbe */ /* IsFunctionKey */
5173 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
5174 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
5175 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
5176 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
5177 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
5178 0, 0, 0, 0, 0, 0, 0, 0,
5179 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
5180 0, 0, 0, 0, 0, 0, 0, "delete"
5183 /* ISO 9995 Function and Modifier Keys; the first byte is 0xFE. */
5184 #define ISO_FUNCTION_KEY_OFFSET 0xfe00
5186 static char *iso_lispy_function_keys
[] =
5188 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe00 */
5189 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe08 */
5190 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe10 */
5191 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe18 */
5192 "iso-lefttab", /* 0xfe20 */
5193 "iso-move-line-up", "iso-move-line-down",
5194 "iso-partial-line-up", "iso-partial-line-down",
5195 "iso-partial-space-left", "iso-partial-space-right",
5196 "iso-set-margin-left", "iso-set-margin-right", /* 0xffe27, 28 */
5197 "iso-release-margin-left", "iso-release-margin-right",
5198 "iso-release-both-margins",
5199 "iso-fast-cursor-left", "iso-fast-cursor-right",
5200 "iso-fast-cursor-up", "iso-fast-cursor-down",
5201 "iso-continuous-underline", "iso-discontinuous-underline", /* 0xfe30, 31 */
5202 "iso-emphasize", "iso-center-object", "iso-enter", /* ... 0xfe34 */
5205 #endif /* not HAVE_NTGUI */
5207 Lisp_Object Vlispy_mouse_stem
;
5209 static char *lispy_wheel_names
[] =
5211 "wheel-up", "wheel-down", "wheel-left", "wheel-right"
5214 /* drag-n-drop events are generated when a set of selected files are
5215 dragged from another application and dropped onto an Emacs window. */
5216 static char *lispy_drag_n_drop_names
[] =
5221 /* Scroll bar parts. */
5222 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
5223 Lisp_Object Qup
, Qdown
, Qbottom
, Qend_scroll
;
5224 Lisp_Object Qtop
, Qratio
;
5226 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
5227 Lisp_Object
*scroll_bar_parts
[] = {
5228 &Qabove_handle
, &Qhandle
, &Qbelow_handle
,
5229 &Qup
, &Qdown
, &Qtop
, &Qbottom
, &Qend_scroll
, &Qratio
5232 /* A vector, indexed by button number, giving the down-going location
5233 of currently depressed buttons, both scroll bar and non-scroll bar.
5235 The elements have the form
5236 (BUTTON-NUMBER MODIFIER-MASK . REST)
5237 where REST is the cdr of a position as it would be reported in the event.
5239 The make_lispy_event function stores positions here to tell the
5240 difference between click and drag events, and to store the starting
5241 location to be included in drag events. */
5243 static Lisp_Object button_down_location
;
5245 /* Information about the most recent up-going button event: Which
5246 button, what location, and what time. */
5248 static int last_mouse_button
;
5249 static int last_mouse_x
;
5250 static int last_mouse_y
;
5251 static unsigned long button_down_time
;
5253 /* The maximum time between clicks to make a double-click, or Qnil to
5254 disable double-click detection, or Qt for no time limit. */
5256 Lisp_Object Vdouble_click_time
;
5258 /* Maximum number of pixels the mouse may be moved between clicks
5259 to make a double-click. */
5261 EMACS_INT double_click_fuzz
;
5263 /* The number of clicks in this multiple-click. */
5265 int double_click_count
;
5267 /* Return position of a mouse click or wheel event */
5270 make_lispy_position (f
, x
, y
, time
)
5276 enum window_part part
;
5277 Lisp_Object posn
= Qnil
;
5278 Lisp_Object extra_info
= Qnil
;
5281 /* Set `window' to the window under frame pixel coordinates (x,y) */
5283 window
= window_from_coordinates (f
, XINT (*x
), XINT (*y
),
5284 &part
, &wx
, &wy
, 0);
5288 if (WINDOWP (window
))
5290 /* It's a click in window window at frame coordinates (x,y) */
5291 struct window
*w
= XWINDOW (window
);
5292 Lisp_Object string_info
= Qnil
;
5293 int textpos
= -1, rx
= -1, ry
= -1;
5294 int dx
= -1, dy
= -1;
5295 int width
= -1, height
= -1;
5296 Lisp_Object object
= Qnil
;
5298 /* Set event coordinates to window-relative coordinates
5299 for constructing the Lisp event below. */
5303 if (part
== ON_TEXT
)
5305 wx
+= WINDOW_LEFT_MARGIN_WIDTH (w
);
5307 else if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
)
5309 /* Mode line or header line. Look for a string under
5310 the mouse that may have a `local-map' property. */
5314 posn
= part
== ON_MODE_LINE
? Qmode_line
: Qheader_line
;
5316 string
= mode_line_string (w
, part
, &rx
, &ry
, &charpos
,
5317 &object
, &dx
, &dy
, &width
, &height
);
5318 if (STRINGP (string
))
5319 string_info
= Fcons (string
, make_number (charpos
));
5320 if (w
== XWINDOW (selected_window
))
5323 textpos
= XMARKER (w
->pointm
)->charpos
;
5325 else if (part
== ON_VERTICAL_BORDER
)
5327 posn
= Qvertical_line
;
5332 else if (part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
5337 posn
= (part
== ON_LEFT_MARGIN
) ? Qleft_margin
: Qright_margin
;
5339 string
= marginal_area_string (w
, part
, &rx
, &ry
, &charpos
,
5340 &object
, &dx
, &dy
, &width
, &height
);
5341 if (STRINGP (string
))
5342 string_info
= Fcons (string
, make_number (charpos
));
5343 if (part
== ON_LEFT_MARGIN
)
5346 wx
= window_box_right_offset (w
, TEXT_AREA
) - 1;
5348 else if (part
== ON_LEFT_FRINGE
)
5350 posn
= Qleft_fringe
;
5353 wx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5355 : window_box_width (w
, LEFT_MARGIN_AREA
));
5358 else if (part
== ON_RIGHT_FRINGE
)
5360 posn
= Qright_fringe
;
5363 wx
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5364 + window_box_width (w
, TEXT_AREA
)
5365 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5366 ? window_box_width (w
, RIGHT_MARGIN_AREA
)
5372 /* Note: We have no special posn for part == ON_SCROLL_BAR. */
5373 wx
= max (WINDOW_LEFT_MARGIN_WIDTH (w
), wx
);
5378 Lisp_Object string2
, object2
= Qnil
;
5379 struct display_pos p
;
5381 int width2
, height2
;
5382 string2
= buffer_posn_from_coords (w
, &wx
, &wy
, &p
,
5383 &object2
, &dx2
, &dy2
,
5385 textpos
= CHARPOS (p
.pos
);
5386 if (rx
< 0) rx
= wx
;
5387 if (ry
< 0) ry
= wy
;
5388 if (dx
< 0) dx
= dx2
;
5389 if (dy
< 0) dy
= dy2
;
5390 if (width
< 0) width
= width2
;
5391 if (height
< 0) height
= height2
;
5395 posn
= make_number (textpos
);
5396 if (STRINGP (string2
))
5397 string_info
= Fcons (string2
,
5398 make_number (CHARPOS (p
.string_pos
)));
5404 #ifdef HAVE_WINDOW_SYSTEM
5405 if (IMAGEP (object
))
5407 Lisp_Object image_map
, hotspot
;
5408 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
5410 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
5412 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
5413 posn
= XCAR (hotspot
);
5418 extra_info
= Fcons (object
,
5419 Fcons (Fcons (make_number (dx
),
5421 Fcons (Fcons (make_number (width
),
5422 make_number (height
)),
5426 extra_info
= Fcons (string_info
,
5427 Fcons (make_number (textpos
),
5428 Fcons (Fcons (make_number (rx
),
5434 XSETFRAME (window
, f
);
5439 XSETFASTINT (*x
, 0);
5440 XSETFASTINT (*y
, 0);
5443 return Fcons (window
,
5445 Fcons (Fcons (*x
, *y
),
5446 Fcons (make_number (time
),
5450 /* Given a struct input_event, build the lisp event which represents
5451 it. If EVENT is 0, build a mouse movement event from the mouse
5452 movement buffer, which should have a movement event in it.
5454 Note that events must be passed to this function in the order they
5455 are received; this function stores the location of button presses
5456 in order to build drag events when the button is released. */
5459 make_lispy_event (event
)
5460 struct input_event
*event
;
5464 switch (SWITCH_ENUM_CAST (event
->kind
))
5466 /* A simple keystroke. */
5467 case ASCII_KEYSTROKE_EVENT
:
5469 Lisp_Object lispy_c
;
5470 int c
= event
->code
& 0377;
5471 /* Turn ASCII characters into control characters
5473 if (event
->modifiers
& ctrl_modifier
)
5474 c
= make_ctrl_char (c
);
5476 /* Add in the other modifier bits. We took care of ctrl_modifier
5477 just above, and the shift key was taken care of by the X code,
5478 and applied to control characters by make_ctrl_char. */
5479 c
|= (event
->modifiers
5480 & (meta_modifier
| alt_modifier
5481 | hyper_modifier
| super_modifier
));
5482 /* Distinguish Shift-SPC from SPC. */
5483 if ((event
->code
& 0377) == 040
5484 && event
->modifiers
& shift_modifier
)
5485 c
|= shift_modifier
;
5486 button_down_time
= 0;
5487 XSETFASTINT (lispy_c
, c
);
5491 case MULTIBYTE_CHAR_KEYSTROKE_EVENT
:
5493 Lisp_Object lispy_c
;
5494 int c
= event
->code
;
5496 /* Add in the other modifier bits. We took care of ctrl_modifier
5497 just above, and the shift key was taken care of by the X code,
5498 and applied to control characters by make_ctrl_char. */
5499 c
|= (event
->modifiers
5500 & (meta_modifier
| alt_modifier
5501 | hyper_modifier
| super_modifier
| ctrl_modifier
));
5502 /* What about the `shift' modifier ? */
5503 button_down_time
= 0;
5504 XSETFASTINT (lispy_c
, c
);
5508 /* A function key. The symbol may need to have modifier prefixes
5510 case NON_ASCII_KEYSTROKE_EVENT
:
5511 button_down_time
= 0;
5513 for (i
= 0; i
< sizeof (lispy_accent_codes
) / sizeof (int); i
++)
5514 if (event
->code
== lispy_accent_codes
[i
])
5515 return modify_event_symbol (i
,
5517 Qfunction_key
, Qnil
,
5518 lispy_accent_keys
, &accent_key_syms
,
5519 (sizeof (lispy_accent_keys
)
5520 / sizeof (lispy_accent_keys
[0])));
5524 if (event
->code
>= 0x400 && event
->code
< 0x500)
5525 return modify_event_symbol (event
->code
- 0x400,
5526 event
->modifiers
& ~shift_modifier
,
5527 Qfunction_key
, Qnil
,
5528 lispy_kana_keys
, &func_key_syms
,
5529 (sizeof (lispy_kana_keys
)
5530 / sizeof (lispy_kana_keys
[0])));
5531 #endif /* XK_kana_A */
5534 #ifdef ISO_FUNCTION_KEY_OFFSET
5535 if (event
->code
< FUNCTION_KEY_OFFSET
5536 && event
->code
>= ISO_FUNCTION_KEY_OFFSET
)
5537 return modify_event_symbol (event
->code
- ISO_FUNCTION_KEY_OFFSET
,
5539 Qfunction_key
, Qnil
,
5540 iso_lispy_function_keys
, &func_key_syms
,
5541 (sizeof (iso_lispy_function_keys
)
5542 / sizeof (iso_lispy_function_keys
[0])));
5545 /* Handle system-specific or unknown keysyms. */
5546 if (event
->code
& (1 << 28)
5547 || event
->code
- FUNCTION_KEY_OFFSET
< 0
5548 || (event
->code
- FUNCTION_KEY_OFFSET
5549 >= sizeof lispy_function_keys
/ sizeof *lispy_function_keys
)
5550 || !lispy_function_keys
[event
->code
- FUNCTION_KEY_OFFSET
])
5552 /* We need to use an alist rather than a vector as the cache
5553 since we can't make a vector long enuf. */
5554 if (NILP (current_kboard
->system_key_syms
))
5555 current_kboard
->system_key_syms
= Fcons (Qnil
, Qnil
);
5556 return modify_event_symbol (event
->code
,
5559 current_kboard
->Vsystem_key_alist
,
5560 0, ¤t_kboard
->system_key_syms
,
5564 return modify_event_symbol (event
->code
- FUNCTION_KEY_OFFSET
,
5566 Qfunction_key
, Qnil
,
5567 lispy_function_keys
, &func_key_syms
,
5568 (sizeof (lispy_function_keys
)
5569 / sizeof (lispy_function_keys
[0])));
5572 /* A mouse click. Figure out where it is, decide whether it's
5573 a press, click or drag, and build the appropriate structure. */
5574 case MOUSE_CLICK_EVENT
:
5575 #ifndef USE_TOOLKIT_SCROLL_BARS
5576 case SCROLL_BAR_CLICK_EVENT
:
5579 int button
= event
->code
;
5581 Lisp_Object position
;
5582 Lisp_Object
*start_pos_ptr
;
5583 Lisp_Object start_pos
;
5587 /* Build the position as appropriate for this mouse click. */
5588 if (event
->kind
== MOUSE_CLICK_EVENT
)
5590 struct frame
*f
= XFRAME (event
->frame_or_window
);
5591 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
5595 /* Ignore mouse events that were made on frame that
5596 have been deleted. */
5597 if (! FRAME_LIVE_P (f
))
5600 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
5601 /* EVENT->x and EVENT->y are frame-relative pixel
5602 coordinates at this place. Under old redisplay, COLUMN
5603 and ROW are set to frame relative glyph coordinates
5604 which are then used to determine whether this click is
5605 in a menu (non-toolkit version). */
5606 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
5607 &column
, &row
, NULL
, 1);
5609 /* In the non-toolkit version, clicks on the menu bar
5610 are ordinary button events in the event buffer.
5611 Distinguish them, and invoke the menu.
5613 (In the toolkit version, the toolkit handles the menu bar
5614 and Emacs doesn't know about it until after the user
5615 makes a selection.) */
5616 if (row
>= 0 && row
< FRAME_MENU_BAR_LINES (f
)
5617 && (event
->modifiers
& down_modifier
))
5619 Lisp_Object items
, item
;
5624 /* Activate the menu bar on the down event. If the
5625 up event comes in before the menu code can deal with it,
5627 if (! (event
->modifiers
& down_modifier
))
5631 /* Find the menu bar item under `column'. */
5633 items
= FRAME_MENU_BAR_ITEMS (f
);
5634 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
5636 Lisp_Object pos
, string
;
5637 string
= AREF (items
, i
+ 1);
5638 pos
= AREF (items
, i
+ 3);
5641 if (column
>= XINT (pos
)
5642 && column
< XINT (pos
) + SCHARS (string
))
5644 item
= AREF (items
, i
);
5649 /* ELisp manual 2.4b says (x y) are window relative but
5650 code says they are frame-relative. */
5652 = Fcons (event
->frame_or_window
,
5654 Fcons (Fcons (event
->x
, event
->y
),
5655 Fcons (make_number (event
->timestamp
),
5658 return Fcons (item
, Fcons (position
, Qnil
));
5660 #endif /* not USE_X_TOOLKIT && not USE_GTK */
5662 position
= make_lispy_position (f
, &event
->x
, &event
->y
,
5665 #ifndef USE_TOOLKIT_SCROLL_BARS
5668 /* It's a scrollbar click. */
5670 Lisp_Object portion_whole
;
5673 window
= event
->frame_or_window
;
5674 portion_whole
= Fcons (event
->x
, event
->y
);
5675 part
= *scroll_bar_parts
[(int) event
->part
];
5679 Fcons (Qvertical_scroll_bar
,
5680 Fcons (portion_whole
,
5681 Fcons (make_number (event
->timestamp
),
5682 Fcons (part
, Qnil
)))));
5684 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5686 if (button
>= ASIZE (button_down_location
))
5688 button_down_location
= larger_vector (button_down_location
,
5690 mouse_syms
= larger_vector (mouse_syms
, button
+ 1, Qnil
);
5693 start_pos_ptr
= &AREF (button_down_location
, button
);
5694 start_pos
= *start_pos_ptr
;
5695 *start_pos_ptr
= Qnil
;
5698 /* On window-system frames, use the value of
5699 double-click-fuzz as is. On other frames, interpret it
5700 as a multiple of 1/8 characters. */
5704 if (WINDOWP (event
->frame_or_window
))
5705 f
= XFRAME (XWINDOW (event
->frame_or_window
)->frame
);
5706 else if (FRAMEP (event
->frame_or_window
))
5707 f
= XFRAME (event
->frame_or_window
);
5711 if (FRAME_WINDOW_P (f
))
5712 fuzz
= double_click_fuzz
;
5714 fuzz
= double_click_fuzz
/ 8;
5716 is_double
= (button
== last_mouse_button
5717 && (abs (XINT (event
->x
) - last_mouse_x
) <= fuzz
)
5718 && (abs (XINT (event
->y
) - last_mouse_y
) <= fuzz
)
5719 && button_down_time
!= 0
5720 && (EQ (Vdouble_click_time
, Qt
)
5721 || (INTEGERP (Vdouble_click_time
)
5722 && ((int)(event
->timestamp
- button_down_time
)
5723 < XINT (Vdouble_click_time
)))));
5726 last_mouse_button
= button
;
5727 last_mouse_x
= XINT (event
->x
);
5728 last_mouse_y
= XINT (event
->y
);
5730 /* If this is a button press, squirrel away the location, so
5731 we can decide later whether it was a click or a drag. */
5732 if (event
->modifiers
& down_modifier
)
5736 double_click_count
++;
5737 event
->modifiers
|= ((double_click_count
> 2)
5742 double_click_count
= 1;
5743 button_down_time
= event
->timestamp
;
5744 *start_pos_ptr
= Fcopy_alist (position
);
5745 ignore_mouse_drag_p
= 0;
5748 /* Now we're releasing a button - check the co-ordinates to
5749 see if this was a click or a drag. */
5750 else if (event
->modifiers
& up_modifier
)
5752 /* If we did not see a down before this up, ignore the up.
5753 Probably this happened because the down event chose a
5754 menu item. It would be an annoyance to treat the
5755 release of the button that chose the menu item as a
5758 if (!CONSP (start_pos
))
5761 event
->modifiers
&= ~up_modifier
;
5762 #if 0 /* Formerly we treated an up with no down as a click event. */
5763 if (!CONSP (start_pos
))
5764 event
->modifiers
|= click_modifier
;
5769 EMACS_INT xdiff
= double_click_fuzz
, ydiff
= double_click_fuzz
;
5771 /* The third element of every position
5772 should be the (x,y) pair. */
5773 down
= Fcar (Fcdr (Fcdr (start_pos
)));
5775 && INTEGERP (XCAR (down
)) && INTEGERP (XCDR (down
)))
5777 xdiff
= XINT (event
->x
) - XINT (XCAR (down
));
5778 ydiff
= XINT (event
->y
) - XINT (XCDR (down
));
5781 if (ignore_mouse_drag_p
)
5783 event
->modifiers
|= click_modifier
;
5784 ignore_mouse_drag_p
= 0;
5786 else if (xdiff
< double_click_fuzz
&& xdiff
> - double_click_fuzz
5787 && ydiff
< double_click_fuzz
&& ydiff
> - double_click_fuzz
5788 /* Maybe the mouse has moved a lot, caused scrolling, and
5789 eventually ended up at the same screen position (but
5790 not buffer position) in which case it is a drag, not
5792 /* FIXME: OTOH if the buffer position has changed
5793 because of a timer or process filter rather than
5794 because of mouse movement, it should be considered as
5795 a click. But mouse-drag-region completely ignores
5796 this case and it hasn't caused any real problem, so
5797 it's probably OK to ignore it as well. */
5798 && EQ (Fcar (Fcdr (start_pos
)), Fcar (Fcdr (position
))))
5799 /* Mouse hasn't moved (much). */
5800 event
->modifiers
|= click_modifier
;
5803 button_down_time
= 0;
5804 event
->modifiers
|= drag_modifier
;
5807 /* Don't check is_double; treat this as multiple
5808 if the down-event was multiple. */
5809 if (double_click_count
> 1)
5810 event
->modifiers
|= ((double_click_count
> 2)
5816 /* Every mouse event should either have the down_modifier or
5817 the up_modifier set. */
5821 /* Get the symbol we should use for the mouse click. */
5824 head
= modify_event_symbol (button
,
5826 Qmouse_click
, Vlispy_mouse_stem
,
5829 XVECTOR (mouse_syms
)->size
);
5830 if (event
->modifiers
& drag_modifier
)
5835 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
5838 Fcons (make_number (double_click_count
),
5848 case HORIZ_WHEEL_EVENT
:
5850 Lisp_Object position
;
5853 /* Build the position as appropriate for this mouse click. */
5854 struct frame
*f
= XFRAME (event
->frame_or_window
);
5856 /* Ignore wheel events that were made on frame that have been
5858 if (! FRAME_LIVE_P (f
))
5861 position
= make_lispy_position (f
, &event
->x
, &event
->y
,
5864 /* Set double or triple modifiers to indicate the wheel speed. */
5866 /* On window-system frames, use the value of
5867 double-click-fuzz as is. On other frames, interpret it
5868 as a multiple of 1/8 characters. */
5873 if (WINDOWP (event
->frame_or_window
))
5874 f
= XFRAME (XWINDOW (event
->frame_or_window
)->frame
);
5875 else if (FRAMEP (event
->frame_or_window
))
5876 f
= XFRAME (event
->frame_or_window
);
5880 if (FRAME_WINDOW_P (f
))
5881 fuzz
= double_click_fuzz
;
5883 fuzz
= double_click_fuzz
/ 8;
5885 is_double
= (last_mouse_button
< 0
5886 && (abs (XINT (event
->x
) - last_mouse_x
) <= fuzz
)
5887 && (abs (XINT (event
->y
) - last_mouse_y
) <= fuzz
)
5888 && button_down_time
!= 0
5889 && (EQ (Vdouble_click_time
, Qt
)
5890 || (INTEGERP (Vdouble_click_time
)
5891 && ((int)(event
->timestamp
- button_down_time
)
5892 < XINT (Vdouble_click_time
)))));
5895 double_click_count
++;
5896 event
->modifiers
|= ((double_click_count
> 2)
5902 double_click_count
= 1;
5903 event
->modifiers
|= click_modifier
;
5906 button_down_time
= event
->timestamp
;
5907 /* Use a negative value to distinguish wheel from mouse button. */
5908 last_mouse_button
= -1;
5909 last_mouse_x
= XINT (event
->x
);
5910 last_mouse_y
= XINT (event
->y
);
5916 if (event
->modifiers
& up_modifier
)
5918 /* Emit a wheel-up event. */
5919 event
->modifiers
&= ~up_modifier
;
5922 else if (event
->modifiers
& down_modifier
)
5924 /* Emit a wheel-down event. */
5925 event
->modifiers
&= ~down_modifier
;
5929 /* Every wheel event should either have the down_modifier or
5930 the up_modifier set. */
5933 if (event
->kind
== HORIZ_WHEEL_EVENT
)
5936 /* Get the symbol we should use for the wheel event. */
5937 head
= modify_event_symbol (symbol_num
,
5943 ASIZE (wheel_syms
));
5946 if (event
->modifiers
& (double_modifier
| triple_modifier
))
5949 Fcons (make_number (double_click_count
),
5958 #ifdef USE_TOOLKIT_SCROLL_BARS
5960 /* We don't have down and up events if using toolkit scroll bars,
5961 so make this always a click event. Store in the `part' of
5962 the Lisp event a symbol which maps to the following actions:
5964 `above_handle' page up
5965 `below_handle' page down
5969 `bottom' bottom of buffer
5970 `handle' thumb has been dragged.
5971 `end-scroll' end of interaction with scroll bar
5973 The incoming input_event contains in its `part' member an
5974 index of type `enum scroll_bar_part' which we can use as an
5975 index in scroll_bar_parts to get the appropriate symbol. */
5977 case SCROLL_BAR_CLICK_EVENT
:
5979 Lisp_Object position
, head
, window
, portion_whole
, part
;
5981 window
= event
->frame_or_window
;
5982 portion_whole
= Fcons (event
->x
, event
->y
);
5983 part
= *scroll_bar_parts
[(int) event
->part
];
5987 Fcons (Qvertical_scroll_bar
,
5988 Fcons (portion_whole
,
5989 Fcons (make_number (event
->timestamp
),
5990 Fcons (part
, Qnil
)))));
5992 /* Always treat scroll bar events as clicks. */
5993 event
->modifiers
|= click_modifier
;
5994 event
->modifiers
&= ~up_modifier
;
5996 if (event
->code
>= ASIZE (mouse_syms
))
5997 mouse_syms
= larger_vector (mouse_syms
, event
->code
+ 1, Qnil
);
5999 /* Get the symbol we should use for the mouse click. */
6000 head
= modify_event_symbol (event
->code
,
6005 XVECTOR (mouse_syms
)->size
);
6006 return Fcons (head
, Fcons (position
, Qnil
));
6009 #endif /* USE_TOOLKIT_SCROLL_BARS */
6012 case W32_SCROLL_BAR_CLICK_EVENT
:
6014 int button
= event
->code
;
6016 Lisp_Object position
;
6017 Lisp_Object
*start_pos_ptr
;
6018 Lisp_Object start_pos
;
6022 Lisp_Object portion_whole
;
6025 window
= event
->frame_or_window
;
6026 portion_whole
= Fcons (event
->x
, event
->y
);
6027 part
= *scroll_bar_parts
[(int) event
->part
];
6031 Fcons (Qvertical_scroll_bar
,
6032 Fcons (portion_whole
,
6033 Fcons (make_number (event
->timestamp
),
6034 Fcons (part
, Qnil
)))));
6037 /* Always treat W32 scroll bar events as clicks. */
6038 event
->modifiers
|= click_modifier
;
6041 /* Get the symbol we should use for the mouse click. */
6044 head
= modify_event_symbol (button
,
6049 XVECTOR (mouse_syms
)->size
);
6055 #endif /* WINDOWSNT */
6057 case DRAG_N_DROP_EVENT
:
6060 Lisp_Object head
, position
;
6063 f
= XFRAME (event
->frame_or_window
);
6066 /* Ignore mouse events that were made on frames that
6067 have been deleted. */
6068 if (! FRAME_LIVE_P (f
))
6071 position
= make_lispy_position (f
, &event
->x
, &event
->y
,
6074 head
= modify_event_symbol (0, event
->modifiers
,
6076 lispy_drag_n_drop_names
,
6077 &drag_n_drop_syms
, 1);
6083 #endif /* HAVE_MOUSE */
6085 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
6086 || defined (USE_GTK)
6087 case MENU_BAR_EVENT
:
6088 if (EQ (event
->arg
, event
->frame_or_window
))
6089 /* This is the prefix key. We translate this to
6090 `(menu_bar)' because the code in keyboard.c for menu
6091 events, which we use, relies on this. */
6092 return Fcons (Qmenu_bar
, Qnil
);
6096 case SELECT_WINDOW_EVENT
:
6097 /* Make an event (select-window (WINDOW)). */
6098 return Fcons (Qselect_window
,
6099 Fcons (Fcons (event
->frame_or_window
, Qnil
),
6102 case TOOL_BAR_EVENT
:
6103 if (EQ (event
->arg
, event
->frame_or_window
))
6104 /* This is the prefix key. We translate this to
6105 `(tool_bar)' because the code in keyboard.c for tool bar
6106 events, which we use, relies on this. */
6107 return Fcons (Qtool_bar
, Qnil
);
6108 else if (SYMBOLP (event
->arg
))
6109 return apply_modifiers (event
->modifiers
, event
->arg
);
6112 case USER_SIGNAL_EVENT
:
6113 /* A user signal. */
6115 char *name
= find_user_signal_name (event
->code
);
6118 return intern (name
);
6121 case SAVE_SESSION_EVENT
:
6122 return Qsave_session
;
6125 case MAC_APPLE_EVENT
:
6127 Lisp_Object spec
[2];
6131 return Fcons (Qmac_apple_event
,
6132 Fcons (Fvector (2, spec
),
6133 Fcons (event
->arg
, Qnil
)));
6138 case GPM_CLICK_EVENT
:
6140 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
6141 Lisp_Object head
, position
;
6142 Lisp_Object
*start_pos_ptr
;
6143 Lisp_Object start_pos
;
6144 int button
= event
->code
;
6146 if (button
>= ASIZE (button_down_location
))
6148 button_down_location
= larger_vector (button_down_location
,
6150 mouse_syms
= larger_vector (mouse_syms
, button
+ 1, Qnil
);
6153 start_pos_ptr
= &AREF (button_down_location
, button
);
6154 start_pos
= *start_pos_ptr
;
6156 position
= make_lispy_position (f
, &event
->x
, &event
->y
,
6159 if (event
->modifiers
& down_modifier
)
6160 *start_pos_ptr
= Fcopy_alist (position
);
6161 else if (event
->modifiers
& (up_modifier
| drag_modifier
))
6163 if (!CONSP (start_pos
))
6165 event
->modifiers
&= ~up_modifier
;
6168 head
= modify_event_symbol (button
,
6170 Qmouse_click
, Vlispy_mouse_stem
,
6173 XVECTOR (mouse_syms
)->size
);
6175 if (event
->modifiers
& drag_modifier
)
6180 else if (event
->modifiers
& double_modifier
)
6183 Fcons (make_number (2),
6185 else if (event
->modifiers
& triple_modifier
)
6188 Fcons (make_number (3),
6195 #endif /* HAVE_GPM */
6197 /* The 'kind' field of the event is something we don't recognize. */
6203 #if defined(HAVE_MOUSE) || defined(HAVE_GPM)
6206 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
6208 Lisp_Object bar_window
;
6209 enum scroll_bar_part part
;
6213 /* Is it a scroll bar movement? */
6214 if (frame
&& ! NILP (bar_window
))
6216 Lisp_Object part_sym
;
6218 part_sym
= *scroll_bar_parts
[(int) part
];
6219 return Fcons (Qscroll_bar_movement
,
6220 (Fcons (Fcons (bar_window
,
6221 Fcons (Qvertical_scroll_bar
,
6222 Fcons (Fcons (x
, y
),
6223 Fcons (make_number (time
),
6229 /* Or is it an ordinary mouse movement? */
6232 Lisp_Object position
;
6234 position
= make_lispy_position (frame
, &x
, &y
, time
);
6236 return Fcons (Qmouse_movement
,
6242 #endif /* HAVE_MOUSE || HAVE GPM */
6244 /* Construct a switch frame event. */
6246 make_lispy_switch_frame (frame
)
6249 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
6252 /* Manipulating modifiers. */
6254 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
6256 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
6257 SYMBOL's name of the end of the modifiers; the string from this
6258 position is the unmodified symbol name.
6260 This doesn't use any caches. */
6263 parse_modifiers_uncached (symbol
, modifier_end
)
6271 CHECK_SYMBOL (symbol
);
6274 name
= SYMBOL_NAME (symbol
);
6276 for (i
= 0; i
+2 <= SBYTES (name
); )
6278 int this_mod_end
= 0;
6281 /* See if the name continues with a modifier word.
6282 Check that the word appears, but don't check what follows it.
6283 Set this_mod and this_mod_end to record what we find. */
6285 switch (SREF (name
, i
))
6287 #define SINGLE_LETTER_MOD(BIT) \
6288 (this_mod_end = i + 1, this_mod = BIT)
6291 SINGLE_LETTER_MOD (alt_modifier
);
6295 SINGLE_LETTER_MOD (ctrl_modifier
);
6299 SINGLE_LETTER_MOD (hyper_modifier
);
6303 SINGLE_LETTER_MOD (meta_modifier
);
6307 SINGLE_LETTER_MOD (shift_modifier
);
6311 SINGLE_LETTER_MOD (super_modifier
);
6314 #undef SINGLE_LETTER_MOD
6316 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
6317 if (i + LEN + 1 <= SBYTES (name) \
6318 && ! strncmp (SDATA (name) + i, NAME, LEN)) \
6320 this_mod_end = i + LEN; \
6325 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
6326 MULTI_LETTER_MOD (down_modifier
, "down", 4);
6327 MULTI_LETTER_MOD (double_modifier
, "double", 6);
6331 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
6333 #undef MULTI_LETTER_MOD
6337 /* If we found no modifier, stop looking for them. */
6338 if (this_mod_end
== 0)
6341 /* Check there is a dash after the modifier, so that it
6342 really is a modifier. */
6343 if (this_mod_end
>= SBYTES (name
)
6344 || SREF (name
, this_mod_end
) != '-')
6347 /* This modifier is real; look for another. */
6348 modifiers
|= this_mod
;
6349 i
= this_mod_end
+ 1;
6352 /* Should we include the `click' modifier? */
6353 if (! (modifiers
& (down_modifier
| drag_modifier
6354 | double_modifier
| triple_modifier
))
6355 && i
+ 7 == SBYTES (name
)
6356 && strncmp (SDATA (name
) + i
, "mouse-", 6) == 0
6357 && ('0' <= SREF (name
, i
+ 6) && SREF (name
, i
+ 6) <= '9'))
6358 modifiers
|= click_modifier
;
6366 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
6367 prepended to the string BASE[0..BASE_LEN-1].
6368 This doesn't use any caches. */
6370 apply_modifiers_uncached (modifiers
, base
, base_len
, base_len_byte
)
6373 int base_len
, base_len_byte
;
6375 /* Since BASE could contain nulls, we can't use intern here; we have
6376 to use Fintern, which expects a genuine Lisp_String, and keeps a
6379 = (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
6385 /* Only the event queue may use the `up' modifier; it should always
6386 be turned into a click or drag event before presented to lisp code. */
6387 if (modifiers
& up_modifier
)
6390 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
6391 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
6392 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
6393 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
6394 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
6395 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
6396 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
6397 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
6398 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
6399 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
6400 /* The click modifier is denoted by the absence of other modifiers. */
6404 mod_len
= p
- new_mods
;
6408 Lisp_Object new_name
;
6410 new_name
= make_uninit_multibyte_string (mod_len
+ base_len
,
6411 mod_len
+ base_len_byte
);
6412 bcopy (new_mods
, SDATA (new_name
), mod_len
);
6413 bcopy (base
, SDATA (new_name
) + mod_len
, base_len_byte
);
6415 return Fintern (new_name
, Qnil
);
6420 static char *modifier_names
[] =
6422 "up", "down", "drag", "click", "double", "triple", 0, 0,
6423 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6424 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
6426 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
6428 static Lisp_Object modifier_symbols
;
6430 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
6432 lispy_modifier_list (modifiers
)
6435 Lisp_Object modifier_list
;
6438 modifier_list
= Qnil
;
6439 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
6440 if (modifiers
& (1<<i
))
6441 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
6444 return modifier_list
;
6448 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
6449 where UNMODIFIED is the unmodified form of SYMBOL,
6450 MASK is the set of modifiers present in SYMBOL's name.
6451 This is similar to parse_modifiers_uncached, but uses the cache in
6452 SYMBOL's Qevent_symbol_element_mask property, and maintains the
6453 Qevent_symbol_elements property. */
6456 parse_modifiers (symbol
)
6459 Lisp_Object elements
;
6461 elements
= Fget (symbol
, Qevent_symbol_element_mask
);
6462 if (CONSP (elements
))
6467 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
6468 Lisp_Object unmodified
;
6471 unmodified
= Fintern (make_string (SDATA (SYMBOL_NAME (symbol
)) + end
,
6472 SBYTES (SYMBOL_NAME (symbol
)) - end
),
6475 if (modifiers
& ~INTMASK
)
6477 XSETFASTINT (mask
, modifiers
);
6478 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
6480 /* Cache the parsing results on SYMBOL. */
6481 Fput (symbol
, Qevent_symbol_element_mask
,
6483 Fput (symbol
, Qevent_symbol_elements
,
6484 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
6486 /* Since we know that SYMBOL is modifiers applied to unmodified,
6487 it would be nice to put that in unmodified's cache.
6488 But we can't, since we're not sure that parse_modifiers is
6495 /* Apply the modifiers MODIFIERS to the symbol BASE.
6496 BASE must be unmodified.
6498 This is like apply_modifiers_uncached, but uses BASE's
6499 Qmodifier_cache property, if present. It also builds
6500 Qevent_symbol_elements properties, since it has that info anyway.
6502 apply_modifiers copies the value of BASE's Qevent_kind property to
6503 the modified symbol. */
6505 apply_modifiers (modifiers
, base
)
6509 Lisp_Object cache
, index
, entry
, new_symbol
;
6511 /* Mask out upper bits. We don't know where this value's been. */
6512 modifiers
&= INTMASK
;
6514 /* The click modifier never figures into cache indices. */
6515 cache
= Fget (base
, Qmodifier_cache
);
6516 XSETFASTINT (index
, (modifiers
& ~click_modifier
));
6517 entry
= assq_no_quit (index
, cache
);
6520 new_symbol
= XCDR (entry
);
6523 /* We have to create the symbol ourselves. */
6524 new_symbol
= apply_modifiers_uncached (modifiers
,
6525 SDATA (SYMBOL_NAME (base
)),
6526 SCHARS (SYMBOL_NAME (base
)),
6527 SBYTES (SYMBOL_NAME (base
)));
6529 /* Add the new symbol to the base's cache. */
6530 entry
= Fcons (index
, new_symbol
);
6531 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
6533 /* We have the parsing info now for free, so we could add it to
6535 XSETFASTINT (index, modifiers);
6536 Fput (new_symbol, Qevent_symbol_element_mask,
6537 Fcons (base, Fcons (index, Qnil)));
6538 Fput (new_symbol, Qevent_symbol_elements,
6539 Fcons (base, lispy_modifier_list (modifiers)));
6540 Sadly, this is only correct if `base' is indeed a base event,
6541 which is not necessarily the case. -stef */
6544 /* Make sure this symbol is of the same kind as BASE.
6546 You'd think we could just set this once and for all when we
6547 intern the symbol above, but reorder_modifiers may call us when
6548 BASE's property isn't set right; we can't assume that just
6549 because it has a Qmodifier_cache property it must have its
6550 Qevent_kind set right as well. */
6551 if (NILP (Fget (new_symbol
, Qevent_kind
)))
6555 kind
= Fget (base
, Qevent_kind
);
6557 Fput (new_symbol
, Qevent_kind
, kind
);
6564 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
6565 return a symbol with the modifiers placed in the canonical order.
6566 Canonical order is alphabetical, except for down and drag, which
6567 always come last. The 'click' modifier is never written out.
6569 Fdefine_key calls this to make sure that (for example) C-M-foo
6570 and M-C-foo end up being equivalent in the keymap. */
6573 reorder_modifiers (symbol
)
6576 /* It's hopefully okay to write the code this way, since everything
6577 will soon be in caches, and no consing will be done at all. */
6580 parsed
= parse_modifiers (symbol
);
6581 return apply_modifiers ((int) XINT (XCAR (XCDR (parsed
))),
6586 /* For handling events, we often want to produce a symbol whose name
6587 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
6588 to some base, like the name of a function key or mouse button.
6589 modify_event_symbol produces symbols of this sort.
6591 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
6592 is the name of the i'th symbol. TABLE_SIZE is the number of elements
6595 Alternatively, NAME_ALIST_OR_STEM is either an alist mapping codes
6596 into symbol names, or a string specifying a name stem used to
6597 construct a symbol name or the form `STEM-N', where N is the decimal
6598 representation of SYMBOL_NUM. NAME_ALIST_OR_STEM is used if it is
6599 non-nil; otherwise NAME_TABLE is used.
6601 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
6602 persist between calls to modify_event_symbol that it can use to
6603 store a cache of the symbols it's generated for this NAME_TABLE
6604 before. The object stored there may be a vector or an alist.
6606 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
6608 MODIFIERS is a set of modifier bits (as given in struct input_events)
6609 whose prefixes should be applied to the symbol name.
6611 SYMBOL_KIND is the value to be placed in the event_kind property of
6612 the returned symbol.
6614 The symbols we create are supposed to have an
6615 `event-symbol-elements' property, which lists the modifiers present
6616 in the symbol's name. */
6619 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_alist_or_stem
,
6620 name_table
, symbol_table
, table_size
)
6623 Lisp_Object symbol_kind
;
6624 Lisp_Object name_alist_or_stem
;
6626 Lisp_Object
*symbol_table
;
6627 unsigned int table_size
;
6630 Lisp_Object symbol_int
;
6632 /* Get rid of the "vendor-specific" bit here. */
6633 XSETINT (symbol_int
, symbol_num
& 0xffffff);
6635 /* Is this a request for a valid symbol? */
6636 if (symbol_num
< 0 || symbol_num
>= table_size
)
6639 if (CONSP (*symbol_table
))
6640 value
= Fcdr (assq_no_quit (symbol_int
, *symbol_table
));
6642 /* If *symbol_table doesn't seem to be initialized properly, fix that.
6643 *symbol_table should be a lisp vector TABLE_SIZE elements long,
6644 where the Nth element is the symbol for NAME_TABLE[N], or nil if
6645 we've never used that symbol before. */
6648 if (! VECTORP (*symbol_table
)
6649 || XVECTOR (*symbol_table
)->size
!= table_size
)
6653 XSETFASTINT (size
, table_size
);
6654 *symbol_table
= Fmake_vector (size
, Qnil
);
6657 value
= XVECTOR (*symbol_table
)->contents
[symbol_num
];
6660 /* Have we already used this symbol before? */
6663 /* No; let's create it. */
6664 if (CONSP (name_alist_or_stem
))
6665 value
= Fcdr_safe (Fassq (symbol_int
, name_alist_or_stem
));
6666 else if (STRINGP (name_alist_or_stem
))
6668 int len
= SBYTES (name_alist_or_stem
);
6669 char *buf
= (char *) alloca (len
+ 50);
6670 sprintf (buf
, "%s-%ld", SDATA (name_alist_or_stem
),
6671 (long) XINT (symbol_int
) + 1);
6672 value
= intern (buf
);
6674 else if (name_table
!= 0 && name_table
[symbol_num
])
6675 value
= intern (name_table
[symbol_num
]);
6677 #ifdef HAVE_WINDOW_SYSTEM
6680 char *name
= x_get_keysym_name (symbol_num
);
6682 value
= intern (name
);
6689 sprintf (buf
, "key-%d", symbol_num
);
6690 value
= intern (buf
);
6693 if (CONSP (*symbol_table
))
6694 *symbol_table
= Fcons (Fcons (symbol_int
, value
), *symbol_table
);
6696 XVECTOR (*symbol_table
)->contents
[symbol_num
] = value
;
6698 /* Fill in the cache entries for this symbol; this also
6699 builds the Qevent_symbol_elements property, which the user
6701 apply_modifiers (modifiers
& click_modifier
, value
);
6702 Fput (value
, Qevent_kind
, symbol_kind
);
6705 /* Apply modifiers to that symbol. */
6706 return apply_modifiers (modifiers
, value
);
6709 /* Convert a list that represents an event type,
6710 such as (ctrl meta backspace), into the usual representation of that
6711 event type as a number or a symbol. */
6713 DEFUN ("event-convert-list", Fevent_convert_list
, Sevent_convert_list
, 1, 1, 0,
6714 doc
: /* Convert the event description list EVENT-DESC to an event type.
6715 EVENT-DESC should contain one base event type (a character or symbol)
6716 and zero or more modifier names (control, meta, hyper, super, shift, alt,
6717 drag, down, double or triple). The base must be last.
6718 The return value is an event type (a character or symbol) which
6719 has the same base event type and all the specified modifiers. */)
6721 Lisp_Object event_desc
;
6729 while (CONSP (rest
))
6737 /* Given a symbol, see if it is a modifier name. */
6738 if (SYMBOLP (elt
) && CONSP (rest
))
6739 this = parse_solitary_modifier (elt
);
6743 else if (!NILP (base
))
6744 error ("Two bases given in one event");
6750 /* Let the symbol A refer to the character A. */
6751 if (SYMBOLP (base
) && SCHARS (SYMBOL_NAME (base
)) == 1)
6752 XSETINT (base
, SREF (SYMBOL_NAME (base
), 0));
6754 if (INTEGERP (base
))
6756 /* Turn (shift a) into A. */
6757 if ((modifiers
& shift_modifier
) != 0
6758 && (XINT (base
) >= 'a' && XINT (base
) <= 'z'))
6760 XSETINT (base
, XINT (base
) - ('a' - 'A'));
6761 modifiers
&= ~shift_modifier
;
6764 /* Turn (control a) into C-a. */
6765 if (modifiers
& ctrl_modifier
)
6766 return make_number ((modifiers
& ~ctrl_modifier
)
6767 | make_ctrl_char (XINT (base
)));
6769 return make_number (modifiers
| XINT (base
));
6771 else if (SYMBOLP (base
))
6772 return apply_modifiers (modifiers
, base
);
6775 error ("Invalid base event");
6780 /* Try to recognize SYMBOL as a modifier name.
6781 Return the modifier flag bit, or 0 if not recognized. */
6784 parse_solitary_modifier (symbol
)
6787 Lisp_Object name
= SYMBOL_NAME (symbol
);
6789 switch (SREF (name
, 0))
6791 #define SINGLE_LETTER_MOD(BIT) \
6792 if (SBYTES (name) == 1) \
6795 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
6796 if (LEN == SBYTES (name) \
6797 && ! strncmp (SDATA (name), NAME, LEN)) \
6801 SINGLE_LETTER_MOD (alt_modifier
);
6805 MULTI_LETTER_MOD (alt_modifier
, "alt", 3);
6809 SINGLE_LETTER_MOD (ctrl_modifier
);
6813 MULTI_LETTER_MOD (ctrl_modifier
, "ctrl", 4);
6814 MULTI_LETTER_MOD (ctrl_modifier
, "control", 7);
6818 SINGLE_LETTER_MOD (hyper_modifier
);
6822 MULTI_LETTER_MOD (hyper_modifier
, "hyper", 5);
6826 SINGLE_LETTER_MOD (meta_modifier
);
6830 MULTI_LETTER_MOD (meta_modifier
, "meta", 4);
6834 SINGLE_LETTER_MOD (shift_modifier
);
6838 MULTI_LETTER_MOD (shift_modifier
, "shift", 5);
6839 MULTI_LETTER_MOD (super_modifier
, "super", 5);
6840 SINGLE_LETTER_MOD (super_modifier
);
6844 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
6845 MULTI_LETTER_MOD (down_modifier
, "down", 4);
6846 MULTI_LETTER_MOD (double_modifier
, "double", 6);
6850 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
6853 #undef SINGLE_LETTER_MOD
6854 #undef MULTI_LETTER_MOD
6860 /* Return 1 if EVENT is a list whose elements are all integers or symbols.
6861 Such a list is not valid as an event,
6862 but it can be a Lucid-style event type list. */
6865 lucid_event_type_list_p (object
)
6870 if (! CONSP (object
))
6873 if (EQ (XCAR (object
), Qhelp_echo
)
6874 || EQ (XCAR (object
), Qvertical_line
)
6875 || EQ (XCAR (object
), Qmode_line
)
6876 || EQ (XCAR (object
), Qheader_line
))
6879 for (tail
= object
; CONSP (tail
); tail
= XCDR (tail
))
6883 if (! (INTEGERP (elt
) || SYMBOLP (elt
)))
6890 /* Store into *addr a value nonzero if terminal input chars are available.
6891 Serves the purpose of ioctl (0, FIONREAD, addr)
6892 but works even if FIONREAD does not exist.
6893 (In fact, this may actually read some input.)
6895 If READABLE_EVENTS_DO_TIMERS_NOW is set in FLAGS, actually run
6896 timer events that are ripe.
6897 If READABLE_EVENTS_FILTER_EVENTS is set in FLAGS, ignore internal
6898 events (FOCUS_IN_EVENT).
6899 If READABLE_EVENTS_IGNORE_SQUEEZABLES is set in FLAGS, ignore mouse
6900 movements and toolkit scroll bar thumb drags. */
6903 get_input_pending (addr
, flags
)
6907 /* First of all, have we already counted some input? */
6908 *addr
= (!NILP (Vquit_flag
) || readable_events (flags
));
6910 /* If input is being read as it arrives, and we have none, there is none. */
6911 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
6914 /* Try to read some input and see how much we get. */
6916 *addr
= (!NILP (Vquit_flag
) || readable_events (flags
));
6919 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
6922 gobble_input (expected
)
6927 if (interrupt_input
)
6930 mask
= sigblock (sigmask (SIGIO
));
6931 read_avail_input (expected
);
6935 #ifdef POLL_FOR_INPUT
6936 /* XXX This condition was (read_socket_hook && !interrupt_input),
6937 but read_socket_hook is not global anymore. Let's pretend that
6939 if (!interrupt_input
&& poll_suppress_count
== 0)
6942 mask
= sigblock (sigmask (SIGALRM
));
6943 read_avail_input (expected
);
6949 read_avail_input (expected
);
6953 /* Put a BUFFER_SWITCH_EVENT in the buffer
6954 so that read_key_sequence will notice the new current buffer. */
6957 record_asynch_buffer_change ()
6959 struct input_event event
;
6963 event
.kind
= BUFFER_SWITCH_EVENT
;
6964 event
.frame_or_window
= Qnil
;
6968 /* We don't need a buffer-switch event unless Emacs is waiting for input.
6969 The purpose of the event is to make read_key_sequence look up the
6970 keymaps again. If we aren't in read_key_sequence, we don't need one,
6971 and the event could cause trouble by messing up (input-pending-p). */
6972 tem
= Fwaiting_for_user_input_p ();
6976 /* We never need these events if we have no asynchronous subprocesses. */
6980 /* Make sure no interrupt happens while storing the event. */
6982 if (interrupt_input
)
6985 mask
= sigblock (sigmask (SIGIO
));
6986 kbd_buffer_store_event (&event
);
6993 kbd_buffer_store_event (&event
);
7000 /* Read any terminal input already buffered up by the system
7001 into the kbd_buffer, but do not wait.
7003 EXPECTED should be nonzero if the caller knows there is some input.
7005 Except on VMS, all input is read by this function.
7006 If interrupt_input is nonzero, this function MUST be called
7007 only when SIGIO is blocked.
7009 Returns the number of keyboard chars read, or -1 meaning
7010 this is a bad time to try to read input. */
7013 read_avail_input (expected
)
7020 /* Store pending user signal events, if any. */
7021 if (store_user_signal_events ())
7024 /* Loop through the available terminals, and call their input hooks. */
7028 struct terminal
*next
= t
->next_terminal
;
7030 if (t
->read_socket_hook
)
7033 struct input_event hold_quit
;
7035 EVENT_INIT (hold_quit
);
7036 hold_quit
.kind
= NO_EVENT
;
7038 /* No need for FIONREAD or fcntl; just say don't wait. */
7039 while (nr
= (*t
->read_socket_hook
) (t
, expected
, &hold_quit
), nr
> 0)
7045 if (nr
== -1) /* Not OK to read input now. */
7049 else if (nr
== -2) /* Non-transient error. */
7051 /* The terminal device terminated; it should be closed. */
7053 /* Kill Emacs if this was our last terminal. */
7054 if (!terminal_list
->next_terminal
)
7055 /* Formerly simply reported no input, but that
7056 sometimes led to a failure of Emacs to terminate.
7057 SIGHUP seems appropriate if we can't reach the
7059 /* ??? Is it really right to send the signal just to
7060 this process rather than to the whole process
7061 group? Perhaps on systems with FIONREAD Emacs is
7062 alone in its group. */
7063 kill (getpid (), SIGHUP
);
7065 /* XXX Is calling delete_terminal safe here? It calls Fdelete_frame. */
7066 if (t
->delete_terminal_hook
)
7067 (*t
->delete_terminal_hook
) (t
);
7069 delete_terminal (t
);
7072 if (hold_quit
.kind
!= NO_EVENT
)
7073 kbd_buffer_store_event (&hold_quit
);
7085 /* This is the tty way of reading available input.
7087 Note that each terminal device has its own `struct terminal' object,
7088 and so this function is called once for each individual termcap
7089 terminal. The first parameter indicates which terminal to read from. */
7092 tty_read_avail_input (struct terminal
*terminal
,
7094 struct input_event
*hold_quit
)
7096 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
7097 the kbd_buffer can really hold. That may prevent loss
7098 of characters on some systems when input is stuffed at us. */
7099 unsigned char cbuf
[KBD_BUFFER_SIZE
- 1];
7101 struct tty_display_info
*tty
= terminal
->display_info
.tty
;
7104 if (!terminal
->name
) /* Don't read from a dead terminal. */
7107 if (terminal
->type
!= output_termcap
)
7110 /* XXX I think the following code should be moved to separate hook
7111 functions in system-dependent files. */
7114 #else /* not WINDOWSNT */
7116 n_to_read
= dos_keysns ();
7120 cbuf
[0] = dos_keyread ();
7123 #else /* not MSDOS */
7125 if (! tty
->term_initted
) /* In case we get called during bootstrap. */
7129 return 0; /* The terminal is suspended. */
7135 struct input_event hold_quit
;
7138 EVENT_INIT (hold_quit
);
7139 hold_quit
.kind
= NO_EVENT
;
7141 while (gpm
= Gpm_GetEvent (&event
), gpm
== 1) {
7142 nread
+= handle_one_term_event (tty
, &event
, &hold_quit
);
7144 if (hold_quit
.kind
!= NO_EVENT
)
7145 kbd_buffer_store_event (&hold_quit
);
7149 #endif /* HAVE_GPM */
7151 /* Determine how many characters we should *try* to read. */
7153 /* Find out how much input is available. */
7154 if (ioctl (fileno (tty
->input
), FIONREAD
, &n_to_read
) < 0)
7156 if (! noninteractive
)
7157 return -2; /* Close this terminal. */
7163 if (n_to_read
> sizeof cbuf
)
7164 n_to_read
= sizeof cbuf
;
7165 #else /* no FIONREAD */
7166 #if defined (USG) || defined (DGUX) || defined(CYGWIN)
7167 /* Read some input if available, but don't wait. */
7168 n_to_read
= sizeof cbuf
;
7169 fcntl (fileno (tty
->input
), F_SETFL
, O_NDELAY
);
7175 /* Now read; for one reason or another, this will not block.
7176 NREAD is set to the number of chars read. */
7179 nread
= emacs_read (fileno (tty
->input
), cbuf
, n_to_read
);
7180 /* POSIX infers that processes which are not in the session leader's
7181 process group won't get SIGHUP's at logout time. BSDI adheres to
7182 this part standard and returns -1 from read (0) with errno==EIO
7183 when the control tty is taken away.
7184 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
7185 if (nread
== -1 && errno
== EIO
)
7186 return -2; /* Close this terminal. */
7187 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
7188 /* The kernel sometimes fails to deliver SIGHUP for ptys.
7189 This looks incorrect, but it isn't, because _BSD causes
7190 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
7191 and that causes a value other than 0 when there is no input. */
7193 return -2; /* Close this terminal. */
7197 /* We used to retry the read if it was interrupted.
7198 But this does the wrong thing when O_NDELAY causes
7199 an EAGAIN error. Does anybody know of a situation
7200 where a retry is actually needed? */
7202 nread
< 0 && (errno
== EAGAIN
7216 #if defined (USG) || defined (DGUX) || defined (CYGWIN)
7217 fcntl (fileno (tty
->input
), F_SETFL
, 0);
7218 #endif /* USG or DGUX or CYGWIN */
7219 #endif /* no FIONREAD */
7224 #endif /* not MSDOS */
7225 #endif /* not WINDOWSNT */
7227 for (i
= 0; i
< nread
; i
++)
7229 struct input_event buf
;
7231 buf
.kind
= ASCII_KEYSTROKE_EVENT
;
7233 if (tty
->meta_key
== 1 && (cbuf
[i
] & 0x80))
7234 buf
.modifiers
= meta_modifier
;
7235 if (tty
->meta_key
!= 2)
7239 /* Set the frame corresponding to the active tty. Note that the
7240 value of selected_frame is not reliable here, redisplay tends
7241 to temporarily change it. */
7242 buf
.frame_or_window
= tty
->top_frame
;
7245 kbd_buffer_store_event (&buf
);
7246 /* Don't look at input that follows a C-g too closely.
7247 This reduces lossage due to autorepeat on C-g. */
7248 if (buf
.kind
== ASCII_KEYSTROKE_EVENT
7249 && buf
.code
== quit_char
)
7255 #endif /* not VMS */
7258 handle_async_input ()
7261 extern int select_alarmed
;
7264 interrupt_input_pending
= 0;
7269 nread
= read_avail_input (1);
7270 /* -1 means it's not ok to read the input now.
7271 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
7272 0 means there was no keyboard input available. */
7277 select_alarmed
= 1; /* Force the select emulator back to life */
7282 #ifdef SIGIO /* for entire page */
7283 /* Note SIGIO has been undef'd if FIONREAD is missing. */
7286 input_available_signal (signo
)
7289 /* Must preserve main program's value of errno. */
7290 int old_errno
= errno
;
7291 #if defined (USG) && !defined (POSIX_SIGNALS)
7292 /* USG systems forget handlers when they are used;
7293 must reestablish each time */
7294 signal (signo
, input_available_signal
);
7302 interrupt_input_pending
= 1;
7304 SIGNAL_THREAD_CHECK (signo
);
7307 if (input_available_clear_time
)
7308 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
7311 handle_async_input ();
7321 /* Send ourselves a SIGIO.
7323 This function exists so that the UNBLOCK_INPUT macro in
7324 blockinput.h can have some way to take care of input we put off
7325 dealing with, without assuming that every file which uses
7326 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
7328 reinvoke_input_signal ()
7331 handle_async_input ();
7337 /* User signal events. */
7339 struct user_signal_info
7341 /* Signal number. */
7344 /* Name of the signal. */
7347 /* Number of pending signals. */
7350 struct user_signal_info
*next
;
7353 /* List of user signals. */
7354 static struct user_signal_info
*user_signals
= NULL
;
7357 add_user_signal (sig
, name
)
7361 struct user_signal_info
*p
;
7363 for (p
= user_signals
; p
; p
= p
->next
)
7365 /* Already added. */
7368 p
= xmalloc (sizeof (struct user_signal_info
));
7370 p
->name
= xstrdup (name
);
7372 p
->next
= user_signals
;
7375 signal (sig
, handle_user_signal
);
7379 handle_user_signal (sig
)
7382 int old_errno
= errno
;
7383 struct user_signal_info
*p
;
7385 #if defined (USG) && !defined (POSIX_SIGNALS)
7386 /* USG systems forget handlers when they are used;
7387 must reestablish each time */
7388 signal (sig
, handle_user_signal
);
7391 SIGNAL_THREAD_CHECK (sig
);
7393 for (p
= user_signals
; p
; p
= p
->next
)
7398 if (interrupt_input
)
7399 kill (getpid (), SIGIO
);
7403 /* Tell wait_reading_process_output that it needs to wake
7404 up and look around. */
7405 if (input_available_clear_time
)
7406 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
7415 find_user_signal_name (sig
)
7418 struct user_signal_info
*p
;
7420 for (p
= user_signals
; p
; p
= p
->next
)
7428 store_user_signal_events ()
7430 struct user_signal_info
*p
;
7431 struct input_event buf
;
7434 for (p
= user_signals
; p
; p
= p
->next
)
7435 if (p
->npending
> 0)
7441 bzero (&buf
, sizeof buf
);
7442 buf
.kind
= USER_SIGNAL_EVENT
;
7443 buf
.frame_or_window
= selected_frame
;
7445 nstored
+= p
->npending
;
7447 mask
= sigblock (sigmask (p
->sig
));
7451 kbd_buffer_store_event (&buf
);
7454 while (p
->npending
> 0);
7462 static void menu_bar_item
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
, void*));
7463 static Lisp_Object menu_bar_one_keymap_changed_items
;
7465 /* These variables hold the vector under construction within
7466 menu_bar_items and its subroutines, and the current index
7467 for storing into that vector. */
7468 static Lisp_Object menu_bar_items_vector
;
7469 static int menu_bar_items_index
;
7471 /* Return a vector of menu items for a menu bar, appropriate
7472 to the current buffer. Each item has three elements in the vector:
7475 OLD is an old vector we can optionally reuse, or nil. */
7478 menu_bar_items (old
)
7481 /* The number of keymaps we're scanning right now, and the number of
7482 keymaps we have allocated space for. */
7485 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
7486 in the current keymaps, or nil where it is not a prefix. */
7489 Lisp_Object def
, tail
;
7498 /* In order to build the menus, we need to call the keymap
7499 accessors. They all call QUIT. But this function is called
7500 during redisplay, during which a quit is fatal. So inhibit
7501 quitting while building the menus.
7502 We do this instead of specbind because (1) errors will clear it anyway
7503 and (2) this avoids risk of specpdl overflow. */
7504 oquit
= Vinhibit_quit
;
7508 menu_bar_items_vector
= old
;
7510 menu_bar_items_vector
= Fmake_vector (make_number (24), Qnil
);
7511 menu_bar_items_index
= 0;
7513 /* Build our list of keymaps.
7514 If we recognize a function key and replace its escape sequence in
7515 keybuf with its symbol, or if the sequence starts with a mouse
7516 click and we need to switch buffers, we jump back here to rebuild
7517 the initial keymaps from the current buffer. */
7521 /* Should overriding-terminal-local-map and overriding-local-map apply? */
7522 if (!NILP (Voverriding_local_map_menu_flag
))
7524 /* Yes, use them (if non-nil) as well as the global map. */
7525 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
7527 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
7528 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
7529 if (!NILP (Voverriding_local_map
))
7530 maps
[nmaps
++] = Voverriding_local_map
;
7534 /* No, so use major and minor mode keymaps and keymap property.
7535 Note that menu-bar bindings in the local-map and keymap
7536 properties may not work reliable, as they are only
7537 recognized when the menu-bar (or mode-line) is updated,
7538 which does not normally happen after every command. */
7541 nminor
= current_minor_maps (NULL
, &tmaps
);
7542 maps
= (Lisp_Object
*) alloca ((nminor
+ 3) * sizeof (maps
[0]));
7544 if (tem
= get_local_map (PT
, current_buffer
, Qkeymap
), !NILP (tem
))
7545 maps
[nmaps
++] = tem
;
7546 bcopy (tmaps
, (void *) (maps
+ nmaps
), nminor
* sizeof (maps
[0]));
7548 maps
[nmaps
++] = get_local_map (PT
, current_buffer
, Qlocal_map
);
7550 maps
[nmaps
++] = current_global_map
;
7553 /* Look up in each map the dummy prefix key `menu-bar'. */
7557 for (mapno
= nmaps
- 1; mapno
>= 0; mapno
--)
7558 if (!NILP (maps
[mapno
]))
7560 def
= get_keymap (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0, 1),
7564 menu_bar_one_keymap_changed_items
= Qnil
;
7565 map_keymap (def
, menu_bar_item
, Qnil
, NULL
, 1);
7569 /* Move to the end those items that should be at the end. */
7571 for (tail
= Vmenu_bar_final_items
; CONSP (tail
); tail
= XCDR (tail
))
7574 int end
= menu_bar_items_index
;
7576 for (i
= 0; i
< end
; i
+= 4)
7577 if (EQ (XCAR (tail
), XVECTOR (menu_bar_items_vector
)->contents
[i
]))
7579 Lisp_Object tem0
, tem1
, tem2
, tem3
;
7580 /* Move the item at index I to the end,
7581 shifting all the others forward. */
7582 tem0
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 0];
7583 tem1
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 1];
7584 tem2
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
7585 tem3
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3];
7587 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
7588 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
7589 (end
- i
- 4) * sizeof (Lisp_Object
));
7590 XVECTOR (menu_bar_items_vector
)->contents
[end
- 4] = tem0
;
7591 XVECTOR (menu_bar_items_vector
)->contents
[end
- 3] = tem1
;
7592 XVECTOR (menu_bar_items_vector
)->contents
[end
- 2] = tem2
;
7593 XVECTOR (menu_bar_items_vector
)->contents
[end
- 1] = tem3
;
7598 /* Add nil, nil, nil, nil at the end. */
7599 i
= menu_bar_items_index
;
7600 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
7603 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
7604 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
7605 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
7606 menu_bar_items_vector
= tem
;
7608 /* Add this item. */
7609 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
7610 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
7611 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
7612 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
7613 menu_bar_items_index
= i
;
7615 Vinhibit_quit
= oquit
;
7616 return menu_bar_items_vector
;
7619 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
7620 If there's already an item for KEY, add this DEF to it. */
7622 Lisp_Object item_properties
;
7625 menu_bar_item (key
, item
, dummy1
, dummy2
)
7626 Lisp_Object key
, item
, dummy1
;
7629 struct gcpro gcpro1
;
7633 if (EQ (item
, Qundefined
))
7635 /* If a map has an explicit `undefined' as definition,
7636 discard any previously made menu bar item. */
7638 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
7639 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
7641 if (menu_bar_items_index
> i
+ 4)
7642 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
7643 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
7644 (menu_bar_items_index
- i
- 4) * sizeof (Lisp_Object
));
7645 menu_bar_items_index
-= 4;
7649 /* If this keymap has already contributed to this KEY,
7650 don't contribute to it a second time. */
7651 tem
= Fmemq (key
, menu_bar_one_keymap_changed_items
);
7652 if (!NILP (tem
) || NILP (item
))
7655 menu_bar_one_keymap_changed_items
7656 = Fcons (key
, menu_bar_one_keymap_changed_items
);
7658 /* We add to menu_bar_one_keymap_changed_items before doing the
7659 parse_menu_item, so that if it turns out it wasn't a menu item,
7660 it still correctly hides any further menu item. */
7662 i
= parse_menu_item (item
, 0, 1);
7667 item
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
7669 /* Find any existing item for this KEY. */
7670 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
7671 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
7674 /* If we did not find this KEY, add it at the end. */
7675 if (i
== menu_bar_items_index
)
7677 /* If vector is too small, get a bigger one. */
7678 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
7681 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
7682 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
7683 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
7684 menu_bar_items_vector
= tem
;
7687 /* Add this item. */
7688 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = key
;
7689 XVECTOR (menu_bar_items_vector
)->contents
[i
++]
7690 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
7691 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Fcons (item
, Qnil
);
7692 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = make_number (0);
7693 menu_bar_items_index
= i
;
7695 /* We did find an item for this KEY. Add ITEM to its list of maps. */
7699 old
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
7700 /* If the new and the old items are not both keymaps,
7701 the lookup will only find `item'. */
7702 item
= Fcons (item
, KEYMAPP (item
) && KEYMAPP (XCAR (old
)) ? old
: Qnil
);
7703 XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2] = item
;
7707 /* This is used as the handler when calling menu_item_eval_property. */
7709 menu_item_eval_property_1 (arg
)
7712 /* If we got a quit from within the menu computation,
7713 quit all the way out of it. This takes care of C-] in the debugger. */
7714 if (CONSP (arg
) && EQ (XCAR (arg
), Qquit
))
7715 Fsignal (Qquit
, Qnil
);
7720 /* Evaluate an expression and return the result (or nil if something
7721 went wrong). Used to evaluate dynamic parts of menu items. */
7723 menu_item_eval_property (sexpr
)
7726 int count
= SPECPDL_INDEX ();
7728 specbind (Qinhibit_redisplay
, Qt
);
7729 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
,
7730 menu_item_eval_property_1
);
7731 return unbind_to (count
, val
);
7734 /* This function parses a menu item and leaves the result in the
7735 vector item_properties.
7736 ITEM is a key binding, a possible menu item.
7737 If NOTREAL is nonzero, only check for equivalent key bindings, don't
7738 evaluate dynamic expressions in the menu item.
7739 INMENUBAR is > 0 when this is considered for an entry in a menu bar
7741 INMENUBAR is < 0 when this is considered for an entry in a keyboard menu.
7742 parse_menu_item returns true if the item is a menu item and false
7746 parse_menu_item (item
, notreal
, inmenubar
)
7748 int notreal
, inmenubar
;
7750 Lisp_Object def
, tem
, item_string
, start
;
7751 Lisp_Object cachelist
;
7753 Lisp_Object keyhint
;
7764 /* Create item_properties vector if necessary. */
7765 if (NILP (item_properties
))
7767 = Fmake_vector (make_number (ITEM_PROPERTY_ENABLE
+ 1), Qnil
);
7769 /* Initialize optional entries. */
7770 for (i
= ITEM_PROPERTY_DEF
; i
< ITEM_PROPERTY_ENABLE
; i
++)
7771 AREF (item_properties
, i
) = Qnil
;
7772 AREF (item_properties
, ITEM_PROPERTY_ENABLE
) = Qt
;
7774 /* Save the item here to protect it from GC. */
7775 AREF (item_properties
, ITEM_PROPERTY_ITEM
) = item
;
7777 item_string
= XCAR (item
);
7781 if (STRINGP (item_string
))
7783 /* Old format menu item. */
7784 AREF (item_properties
, ITEM_PROPERTY_NAME
) = item_string
;
7786 /* Maybe help string. */
7787 if (CONSP (item
) && STRINGP (XCAR (item
)))
7789 AREF (item_properties
, ITEM_PROPERTY_HELP
) = XCAR (item
);
7794 /* Maybe key binding cache. */
7795 if (CONSP (item
) && CONSP (XCAR (item
))
7796 && (NILP (XCAR (XCAR (item
)))
7797 || VECTORP (XCAR (XCAR (item
)))))
7799 cachelist
= XCAR (item
);
7803 /* This is the real definition--the function to run. */
7804 AREF (item_properties
, ITEM_PROPERTY_DEF
) = item
;
7806 /* Get enable property, if any. */
7809 tem
= Fget (item
, Qmenu_enable
);
7810 if (!NILP (Venable_disabled_menus_and_buttons
))
7811 AREF (item_properties
, ITEM_PROPERTY_ENABLE
) = Qt
;
7812 else if (!NILP (tem
))
7813 AREF (item_properties
, ITEM_PROPERTY_ENABLE
) = tem
;
7816 else if (EQ (item_string
, Qmenu_item
) && CONSP (item
))
7818 /* New format menu item. */
7819 AREF (item_properties
, ITEM_PROPERTY_NAME
) = XCAR (item
);
7820 start
= XCDR (item
);
7823 /* We have a real binding. */
7824 AREF (item_properties
, ITEM_PROPERTY_DEF
) = XCAR (start
);
7826 item
= XCDR (start
);
7827 /* Is there a cache list with key equivalences. */
7828 if (CONSP (item
) && CONSP (XCAR (item
)))
7830 cachelist
= XCAR (item
);
7834 /* Parse properties. */
7835 while (CONSP (item
) && CONSP (XCDR (item
)))
7840 if (EQ (tem
, QCenable
))
7842 if (!NILP (Venable_disabled_menus_and_buttons
))
7843 AREF (item_properties
, ITEM_PROPERTY_ENABLE
) = Qt
;
7845 AREF (item_properties
, ITEM_PROPERTY_ENABLE
) = XCAR (item
);
7847 else if (EQ (tem
, QCvisible
) && !notreal
)
7849 /* If got a visible property and that evaluates to nil
7850 then ignore this item. */
7851 tem
= menu_item_eval_property (XCAR (item
));
7855 else if (EQ (tem
, QChelp
))
7856 AREF (item_properties
, ITEM_PROPERTY_HELP
) = XCAR (item
);
7857 else if (EQ (tem
, QCfilter
))
7859 else if (EQ (tem
, QCkey_sequence
))
7862 if (NILP (cachelist
)
7863 && (SYMBOLP (tem
) || STRINGP (tem
) || VECTORP (tem
)))
7864 /* Be GC protected. Set keyhint to item instead of tem. */
7867 else if (EQ (tem
, QCkeys
))
7870 if (CONSP (tem
) || (STRINGP (tem
) && NILP (cachelist
)))
7871 AREF (item_properties
, ITEM_PROPERTY_KEYEQ
) = tem
;
7873 else if (EQ (tem
, QCbutton
) && CONSP (XCAR (item
)))
7878 if (EQ (type
, QCtoggle
) || EQ (type
, QCradio
))
7880 AREF (item_properties
, ITEM_PROPERTY_SELECTED
)
7882 AREF (item_properties
, ITEM_PROPERTY_TYPE
)
7889 else if (inmenubar
|| !NILP (start
))
7893 return 0; /* not a menu item */
7895 /* If item string is not a string, evaluate it to get string.
7896 If we don't get a string, skip this item. */
7897 item_string
= AREF (item_properties
, ITEM_PROPERTY_NAME
);
7898 if (!(STRINGP (item_string
) || notreal
))
7900 item_string
= menu_item_eval_property (item_string
);
7901 if (!STRINGP (item_string
))
7903 AREF (item_properties
, ITEM_PROPERTY_NAME
) = item_string
;
7906 /* If got a filter apply it on definition. */
7907 def
= AREF (item_properties
, ITEM_PROPERTY_DEF
);
7910 def
= menu_item_eval_property (list2 (XCAR (filter
),
7911 list2 (Qquote
, def
)));
7913 AREF (item_properties
, ITEM_PROPERTY_DEF
) = def
;
7916 /* Enable or disable selection of item. */
7917 tem
= AREF (item_properties
, ITEM_PROPERTY_ENABLE
);
7923 tem
= menu_item_eval_property (tem
);
7924 if (inmenubar
&& NILP (tem
))
7925 return 0; /* Ignore disabled items in menu bar. */
7926 AREF (item_properties
, ITEM_PROPERTY_ENABLE
) = tem
;
7929 /* If we got no definition, this item is just unselectable text which
7930 is OK in a submenu but not in the menubar. */
7932 return (inmenubar
? 0 : 1);
7934 /* See if this is a separate pane or a submenu. */
7935 def
= AREF (item_properties
, ITEM_PROPERTY_DEF
);
7936 tem
= get_keymap (def
, 0, 1);
7937 /* For a subkeymap, just record its details and exit. */
7940 AREF (item_properties
, ITEM_PROPERTY_MAP
) = tem
;
7941 AREF (item_properties
, ITEM_PROPERTY_DEF
) = tem
;
7945 /* At the top level in the menu bar, do likewise for commands also.
7946 The menu bar does not display equivalent key bindings anyway.
7947 ITEM_PROPERTY_DEF is already set up properly. */
7951 /* This is a command. See if there is an equivalent key binding. */
7952 if (NILP (cachelist
))
7954 /* We have to create a cachelist. */
7955 CHECK_IMPURE (start
);
7956 XSETCDR (start
, Fcons (Fcons (Qnil
, Qnil
), XCDR (start
)));
7957 cachelist
= XCAR (XCDR (start
));
7959 tem
= AREF (item_properties
, ITEM_PROPERTY_KEYEQ
);
7960 if (!NILP (keyhint
))
7962 XSETCAR (cachelist
, XCAR (keyhint
));
7965 else if (STRINGP (tem
))
7967 XSETCDR (cachelist
, Fsubstitute_command_keys (tem
));
7968 XSETCAR (cachelist
, Qt
);
7972 tem
= XCAR (cachelist
);
7979 tem
= Fkey_binding (tem
, Qnil
, Qnil
, Qnil
);
7981 prefix
= AREF (item_properties
, ITEM_PROPERTY_KEYEQ
);
7984 def
= XCAR (prefix
);
7985 prefix
= XCDR (prefix
);
7988 def
= AREF (item_properties
, ITEM_PROPERTY_DEF
);
7990 if (NILP (XCAR (cachelist
))) /* Have no saved key. */
7992 if (newcache
/* Always check first time. */
7993 /* Should we check everything when precomputing key
7995 /* If something had no key binding before, don't recheck it
7996 because that is too slow--except if we have a list of
7997 rebound commands in Vdefine_key_rebound_commands, do
7998 recheck any command that appears in that list. */
7999 || (CONSP (Vdefine_key_rebound_commands
)
8000 && !NILP (Fmemq (def
, Vdefine_key_rebound_commands
))))
8003 /* We had a saved key. Is it still bound to the command? */
8006 /* If the command is an alias for another
8007 (such as lmenu.el set it up), check if the
8008 original command matches the cached command. */
8009 && !(SYMBOLP (def
) && EQ (tem
, XSYMBOL (def
)->function
))))
8010 chkcache
= 1; /* Need to recompute key binding. */
8014 /* Recompute equivalent key binding. If the command is an alias
8015 for another (such as lmenu.el set it up), see if the original
8016 command name has equivalent keys. Otherwise look up the
8017 specified command itself. We don't try both, because that
8018 makes lmenu menus slow. */
8020 && SYMBOLP (XSYMBOL (def
)->function
)
8021 && ! NILP (Fget (def
, Qmenu_alias
)))
8022 def
= XSYMBOL (def
)->function
;
8023 tem
= Fwhere_is_internal (def
, Qnil
, Qt
, Qnil
, Qt
);
8024 XSETCAR (cachelist
, tem
);
8027 XSETCDR (cachelist
, Qnil
);
8031 else if (!NILP (keyhint
) && !NILP (XCAR (cachelist
)))
8033 tem
= XCAR (cachelist
);
8037 newcache
= chkcache
;
8040 tem
= Fkey_description (tem
, Qnil
);
8043 if (STRINGP (XCAR (prefix
)))
8044 tem
= concat2 (XCAR (prefix
), tem
);
8045 if (STRINGP (XCDR (prefix
)))
8046 tem
= concat2 (tem
, XCDR (prefix
));
8048 XSETCDR (cachelist
, tem
);
8052 tem
= XCDR (cachelist
);
8053 if (newcache
&& !NILP (tem
))
8055 tem
= concat3 (build_string (" ("), tem
, build_string (")"));
8056 XSETCDR (cachelist
, tem
);
8059 /* If we only want to precompute equivalent key bindings, stop here. */
8063 /* If we have an equivalent key binding, use that. */
8064 AREF (item_properties
, ITEM_PROPERTY_KEYEQ
) = tem
;
8066 /* Include this when menu help is implemented.
8067 tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP];
8068 if (!(NILP (tem) || STRINGP (tem)))
8070 tem = menu_item_eval_property (tem);
8073 XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP] = tem;
8077 /* Handle radio buttons or toggle boxes. */
8078 tem
= AREF (item_properties
, ITEM_PROPERTY_SELECTED
);
8080 AREF (item_properties
, ITEM_PROPERTY_SELECTED
)
8081 = menu_item_eval_property (tem
);
8088 /***********************************************************************
8090 ***********************************************************************/
8092 /* A vector holding tool bar items while they are parsed in function
8093 tool_bar_items. Each item occupies TOOL_BAR_ITEM_NSCLOTS elements
8096 static Lisp_Object tool_bar_items_vector
;
8098 /* A vector holding the result of parse_tool_bar_item. Layout is like
8099 the one for a single item in tool_bar_items_vector. */
8101 static Lisp_Object tool_bar_item_properties
;
8103 /* Next free index in tool_bar_items_vector. */
8105 static int ntool_bar_items
;
8107 /* The symbols `tool-bar', `:image' and `:rtl'. */
8109 extern Lisp_Object Qtool_bar
;
8110 Lisp_Object QCimage
;
8113 /* Function prototypes. */
8115 static void init_tool_bar_items
P_ ((Lisp_Object
));
8116 static void process_tool_bar_item
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
, void*));
8117 static int parse_tool_bar_item
P_ ((Lisp_Object
, Lisp_Object
));
8118 static void append_tool_bar_item
P_ ((void));
8121 /* Return a vector of tool bar items for keymaps currently in effect.
8122 Reuse vector REUSE if non-nil. Return in *NITEMS the number of
8123 tool bar items found. */
8126 tool_bar_items (reuse
, nitems
)
8137 /* In order to build the menus, we need to call the keymap
8138 accessors. They all call QUIT. But this function is called
8139 during redisplay, during which a quit is fatal. So inhibit
8140 quitting while building the menus. We do this instead of
8141 specbind because (1) errors will clear it anyway and (2) this
8142 avoids risk of specpdl overflow. */
8143 oquit
= Vinhibit_quit
;
8146 /* Initialize tool_bar_items_vector and protect it from GC. */
8147 init_tool_bar_items (reuse
);
8149 /* Build list of keymaps in maps. Set nmaps to the number of maps
8152 /* Should overriding-terminal-local-map and overriding-local-map apply? */
8153 if (!NILP (Voverriding_local_map_menu_flag
))
8155 /* Yes, use them (if non-nil) as well as the global map. */
8156 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
8158 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
8159 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
8160 if (!NILP (Voverriding_local_map
))
8161 maps
[nmaps
++] = Voverriding_local_map
;
8165 /* No, so use major and minor mode keymaps and keymap property.
8166 Note that tool-bar bindings in the local-map and keymap
8167 properties may not work reliable, as they are only
8168 recognized when the tool-bar (or mode-line) is updated,
8169 which does not normally happen after every command. */
8172 nminor
= current_minor_maps (NULL
, &tmaps
);
8173 maps
= (Lisp_Object
*) alloca ((nminor
+ 3) * sizeof (maps
[0]));
8175 if (tem
= get_local_map (PT
, current_buffer
, Qkeymap
), !NILP (tem
))
8176 maps
[nmaps
++] = tem
;
8177 bcopy (tmaps
, (void *) (maps
+ nmaps
), nminor
* sizeof (maps
[0]));
8179 maps
[nmaps
++] = get_local_map (PT
, current_buffer
, Qlocal_map
);
8182 /* Add global keymap at the end. */
8183 maps
[nmaps
++] = current_global_map
;
8185 /* Process maps in reverse order and look up in each map the prefix
8187 for (i
= nmaps
- 1; i
>= 0; --i
)
8188 if (!NILP (maps
[i
]))
8192 keymap
= get_keymap (access_keymap (maps
[i
], Qtool_bar
, 1, 0, 1), 0, 1);
8194 map_keymap (keymap
, process_tool_bar_item
, Qnil
, NULL
, 1);
8197 Vinhibit_quit
= oquit
;
8198 *nitems
= ntool_bar_items
/ TOOL_BAR_ITEM_NSLOTS
;
8199 return tool_bar_items_vector
;
8203 /* Process the definition of KEY which is DEF. */
8206 process_tool_bar_item (key
, def
, data
, args
)
8207 Lisp_Object key
, def
, data
;
8211 extern Lisp_Object Qundefined
;
8212 struct gcpro gcpro1
, gcpro2
;
8214 /* Protect KEY and DEF from GC because parse_tool_bar_item may call
8218 if (EQ (def
, Qundefined
))
8220 /* If a map has an explicit `undefined' as definition,
8221 discard any previously made item. */
8222 for (i
= 0; i
< ntool_bar_items
; i
+= TOOL_BAR_ITEM_NSLOTS
)
8224 Lisp_Object
*v
= XVECTOR (tool_bar_items_vector
)->contents
+ i
;
8226 if (EQ (key
, v
[TOOL_BAR_ITEM_KEY
]))
8228 if (ntool_bar_items
> i
+ TOOL_BAR_ITEM_NSLOTS
)
8229 bcopy (v
+ TOOL_BAR_ITEM_NSLOTS
, v
,
8230 ((ntool_bar_items
- i
- TOOL_BAR_ITEM_NSLOTS
)
8231 * sizeof (Lisp_Object
)));
8232 ntool_bar_items
-= TOOL_BAR_ITEM_NSLOTS
;
8237 else if (parse_tool_bar_item (key
, def
))
8238 /* Append a new tool bar item to tool_bar_items_vector. Accept
8239 more than one definition for the same key. */
8240 append_tool_bar_item ();
8246 /* Parse a tool bar item specification ITEM for key KEY and return the
8247 result in tool_bar_item_properties. Value is zero if ITEM is
8250 ITEM is a list `(menu-item CAPTION BINDING PROPS...)'.
8252 CAPTION is the caption of the item, If it's not a string, it is
8253 evaluated to get a string.
8255 BINDING is the tool bar item's binding. Tool-bar items with keymaps
8256 as binding are currently ignored.
8258 The following properties are recognized:
8262 FORM is evaluated and specifies whether the tool bar item is
8263 enabled or disabled.
8267 FORM is evaluated and specifies whether the tool bar item is visible.
8269 - `:filter FUNCTION'
8271 FUNCTION is invoked with one parameter `(quote BINDING)'. Its
8272 result is stored as the new binding.
8274 - `:button (TYPE SELECTED)'
8276 TYPE must be one of `:radio' or `:toggle'. SELECTED is evaluated
8277 and specifies whether the button is selected (pressed) or not.
8281 IMAGES is either a single image specification or a vector of four
8282 image specifications. See enum tool_bar_item_images.
8284 - `:help HELP-STRING'.
8286 Gives a help string to display for the tool bar item. */
8289 parse_tool_bar_item (key
, item
)
8290 Lisp_Object key
, item
;
8292 /* Access slot with index IDX of vector tool_bar_item_properties. */
8293 #define PROP(IDX) XVECTOR (tool_bar_item_properties)->contents[IDX]
8295 Lisp_Object filter
= Qnil
;
8296 Lisp_Object caption
;
8299 /* Defininition looks like `(menu-item CAPTION BINDING PROPS...)'.
8300 Rule out items that aren't lists, don't start with
8301 `menu-item' or whose rest following `tool-bar-item' is not a
8304 || !EQ (XCAR (item
), Qmenu_item
)
8305 || (item
= XCDR (item
),
8309 /* Create tool_bar_item_properties vector if necessary. Reset it to
8311 if (VECTORP (tool_bar_item_properties
))
8313 for (i
= 0; i
< TOOL_BAR_ITEM_NSLOTS
; ++i
)
8317 tool_bar_item_properties
8318 = Fmake_vector (make_number (TOOL_BAR_ITEM_NSLOTS
), Qnil
);
8321 PROP (TOOL_BAR_ITEM_KEY
) = key
;
8322 PROP (TOOL_BAR_ITEM_ENABLED_P
) = Qt
;
8324 /* Get the caption of the item. If the caption is not a string,
8325 evaluate it to get a string. If we don't get a string, skip this
8327 caption
= XCAR (item
);
8328 if (!STRINGP (caption
))
8330 caption
= menu_item_eval_property (caption
);
8331 if (!STRINGP (caption
))
8334 PROP (TOOL_BAR_ITEM_CAPTION
) = caption
;
8336 /* Give up if rest following the caption is not a list. */
8341 /* Store the binding. */
8342 PROP (TOOL_BAR_ITEM_BINDING
) = XCAR (item
);
8345 /* Ignore cached key binding, if any. */
8346 if (CONSP (item
) && CONSP (XCAR (item
)))
8349 /* Process the rest of the properties. */
8350 for (; CONSP (item
) && CONSP (XCDR (item
)); item
= XCDR (XCDR (item
)))
8352 Lisp_Object key
, value
;
8355 value
= XCAR (XCDR (item
));
8357 if (EQ (key
, QCenable
))
8359 /* `:enable FORM'. */
8360 if (!NILP (Venable_disabled_menus_and_buttons
))
8361 PROP (TOOL_BAR_ITEM_ENABLED_P
) = Qt
;
8363 PROP (TOOL_BAR_ITEM_ENABLED_P
) = value
;
8365 else if (EQ (key
, QCvisible
))
8367 /* `:visible FORM'. If got a visible property and that
8368 evaluates to nil then ignore this item. */
8369 if (NILP (menu_item_eval_property (value
)))
8372 else if (EQ (key
, QChelp
))
8373 /* `:help HELP-STRING'. */
8374 PROP (TOOL_BAR_ITEM_HELP
) = value
;
8375 else if (EQ (key
, QCfilter
))
8376 /* ':filter FORM'. */
8378 else if (EQ (key
, QCbutton
) && CONSP (value
))
8380 /* `:button (TYPE . SELECTED)'. */
8381 Lisp_Object type
, selected
;
8383 type
= XCAR (value
);
8384 selected
= XCDR (value
);
8385 if (EQ (type
, QCtoggle
) || EQ (type
, QCradio
))
8387 PROP (TOOL_BAR_ITEM_SELECTED_P
) = selected
;
8388 PROP (TOOL_BAR_ITEM_TYPE
) = type
;
8391 else if (EQ (key
, QCimage
)
8393 || (VECTORP (value
) && XVECTOR (value
)->size
== 4)))
8394 /* Value is either a single image specification or a vector
8395 of 4 such specifications for the different button states. */
8396 PROP (TOOL_BAR_ITEM_IMAGES
) = value
;
8397 else if (EQ (key
, Qrtl
))
8399 PROP (TOOL_BAR_ITEM_RTL_IMAGE
) = value
;
8402 /* If got a filter apply it on binding. */
8404 PROP (TOOL_BAR_ITEM_BINDING
)
8405 = menu_item_eval_property (list2 (filter
,
8407 PROP (TOOL_BAR_ITEM_BINDING
))));
8409 /* See if the binding is a keymap. Give up if it is. */
8410 if (CONSP (get_keymap (PROP (TOOL_BAR_ITEM_BINDING
), 0, 1)))
8413 /* Enable or disable selection of item. */
8414 if (!EQ (PROP (TOOL_BAR_ITEM_ENABLED_P
), Qt
))
8415 PROP (TOOL_BAR_ITEM_ENABLED_P
)
8416 = menu_item_eval_property (PROP (TOOL_BAR_ITEM_ENABLED_P
));
8418 /* Handle radio buttons or toggle boxes. */
8419 if (!NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
)))
8420 PROP (TOOL_BAR_ITEM_SELECTED_P
)
8421 = menu_item_eval_property (PROP (TOOL_BAR_ITEM_SELECTED_P
));
8429 /* Initialize tool_bar_items_vector. REUSE, if non-nil, is a vector
8430 that can be reused. */
8433 init_tool_bar_items (reuse
)
8436 if (VECTORP (reuse
))
8437 tool_bar_items_vector
= reuse
;
8439 tool_bar_items_vector
= Fmake_vector (make_number (64), Qnil
);
8440 ntool_bar_items
= 0;
8444 /* Append parsed tool bar item properties from
8445 tool_bar_item_properties */
8448 append_tool_bar_item ()
8450 Lisp_Object
*to
, *from
;
8452 /* Enlarge tool_bar_items_vector if necessary. */
8453 if (ntool_bar_items
+ TOOL_BAR_ITEM_NSLOTS
8454 >= XVECTOR (tool_bar_items_vector
)->size
)
8456 Lisp_Object new_vector
;
8457 int old_size
= XVECTOR (tool_bar_items_vector
)->size
;
8459 new_vector
= Fmake_vector (make_number (2 * old_size
), Qnil
);
8460 bcopy (XVECTOR (tool_bar_items_vector
)->contents
,
8461 XVECTOR (new_vector
)->contents
,
8462 old_size
* sizeof (Lisp_Object
));
8463 tool_bar_items_vector
= new_vector
;
8466 /* Append entries from tool_bar_item_properties to the end of
8467 tool_bar_items_vector. */
8468 to
= XVECTOR (tool_bar_items_vector
)->contents
+ ntool_bar_items
;
8469 from
= XVECTOR (tool_bar_item_properties
)->contents
;
8470 bcopy (from
, to
, TOOL_BAR_ITEM_NSLOTS
* sizeof *to
);
8471 ntool_bar_items
+= TOOL_BAR_ITEM_NSLOTS
;
8478 /* Read a character using menus based on maps in the array MAPS.
8479 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
8480 Return t if we displayed a menu but the user rejected it.
8482 PREV_EVENT is the previous input event, or nil if we are reading
8483 the first event of a key sequence.
8485 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
8486 if we used a mouse menu to read the input, or zero otherwise. If
8487 USED_MOUSE_MENU is null, we don't dereference it.
8489 The prompting is done based on the prompt-string of the map
8490 and the strings associated with various map elements.
8492 This can be done with X menus or with menus put in the minibuf.
8493 These are done in different ways, depending on how the input will be read.
8494 Menus using X are done after auto-saving in read-char, getting the input
8495 event from Fx_popup_menu; menus using the minibuf use read_char recursively
8496 and do auto-saving in the inner call of read_char. */
8499 read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
8502 Lisp_Object prev_event
;
8503 int *used_mouse_menu
;
8506 register Lisp_Object name
= Qnil
;
8508 if (used_mouse_menu
)
8509 *used_mouse_menu
= 0;
8511 /* Use local over global Menu maps */
8513 if (! menu_prompting
)
8516 /* Optionally disregard all but the global map. */
8517 if (inhibit_local_menu_bar_menus
)
8519 maps
+= (nmaps
- 1);
8523 /* Get the menu name from the first map that has one (a prompt string). */
8524 for (mapno
= 0; mapno
< nmaps
; mapno
++)
8526 name
= Fkeymap_prompt (maps
[mapno
]);
8531 /* If we don't have any menus, just read a character normally. */
8532 if (!STRINGP (name
))
8536 /* If we got to this point via a mouse click,
8537 use a real menu for mouse selection. */
8538 if (EVENT_HAS_PARAMETERS (prev_event
)
8539 && !EQ (XCAR (prev_event
), Qmenu_bar
)
8540 && !EQ (XCAR (prev_event
), Qtool_bar
))
8542 /* Display the menu and get the selection. */
8543 Lisp_Object
*realmaps
8544 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
8548 /* Use the maps that are not nil. */
8549 for (mapno
= 0; mapno
< nmaps
; mapno
++)
8550 if (!NILP (maps
[mapno
]))
8551 realmaps
[nmaps1
++] = maps
[mapno
];
8553 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
8558 record_menu_key (XCAR (value
));
8560 /* If we got multiple events, unread all but
8562 There is no way to prevent those unread events
8563 from showing up later in last_nonmenu_event.
8564 So turn symbol and integer events into lists,
8565 to indicate that they came from a mouse menu,
8566 so that when present in last_nonmenu_event
8567 they won't confuse things. */
8568 for (tem
= XCDR (value
); !NILP (tem
); tem
= XCDR (tem
))
8570 record_menu_key (XCAR (tem
));
8571 if (SYMBOLP (XCAR (tem
))
8572 || INTEGERP (XCAR (tem
)))
8573 XSETCAR (tem
, Fcons (XCAR (tem
), Qdisabled
));
8576 /* If we got more than one event, put all but the first
8577 onto this list to be read later.
8578 Return just the first event now. */
8579 Vunread_command_events
8580 = nconc2 (XCDR (value
), Vunread_command_events
);
8581 value
= XCAR (value
);
8583 else if (NILP (value
))
8585 if (used_mouse_menu
)
8586 *used_mouse_menu
= 1;
8589 #endif /* HAVE_MENUS */
8593 /* Buffer in use so far for the minibuf prompts for menu keymaps.
8594 We make this bigger when necessary, and never free it. */
8595 static char *read_char_minibuf_menu_text
;
8596 /* Size of that buffer. */
8597 static int read_char_minibuf_menu_width
;
8600 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
8606 register Lisp_Object name
;
8608 /* FIXME: Use the minibuffer's frame width. */
8609 int width
= FRAME_COLS (SELECTED_FRAME ()) - 4;
8612 Lisp_Object rest
, vector
;
8618 if (! menu_prompting
)
8621 /* Make sure we have a big enough buffer for the menu text. */
8622 if (read_char_minibuf_menu_text
== 0)
8624 read_char_minibuf_menu_width
= width
+ 4;
8625 read_char_minibuf_menu_text
= (char *) xmalloc (width
+ 4);
8627 else if (width
+ 4 > read_char_minibuf_menu_width
)
8629 read_char_minibuf_menu_width
= width
+ 4;
8630 read_char_minibuf_menu_text
8631 = (char *) xrealloc (read_char_minibuf_menu_text
, width
+ 4);
8633 menu
= read_char_minibuf_menu_text
;
8635 /* Get the menu name from the first map that has one (a prompt string). */
8636 for (mapno
= 0; mapno
< nmaps
; mapno
++)
8638 name
= Fkeymap_prompt (maps
[mapno
]);
8643 /* If we don't have any menus, just read a character normally. */
8644 if (!STRINGP (name
))
8647 /* Prompt string always starts with map's prompt, and a space. */
8648 strcpy (menu
, SDATA (name
));
8649 nlength
= SBYTES (name
);
8650 menu
[nlength
++] = ':';
8651 menu
[nlength
++] = ' ';
8654 /* Start prompting at start of first map. */
8658 /* Present the documented bindings, a line at a time. */
8665 Lisp_Object orig_defn_macro
;
8667 /* Loop over elements of map. */
8672 /* If reached end of map, start at beginning of next map. */
8676 /* At end of last map, wrap around to first map if just starting,
8677 or end this line if already have something on it. */
8681 if (notfirst
|| nobindings
) break;
8686 /* Look at the next element of the map. */
8688 elt
= XVECTOR (vector
)->contents
[idx
];
8690 elt
= Fcar_safe (rest
);
8692 if (idx
< 0 && VECTORP (elt
))
8694 /* If we found a dense table in the keymap,
8695 advanced past it, but start scanning its contents. */
8696 rest
= Fcdr_safe (rest
);
8702 /* An ordinary element. */
8703 Lisp_Object event
, tem
;
8707 event
= Fcar_safe (elt
); /* alist */
8708 elt
= Fcdr_safe (elt
);
8712 XSETINT (event
, idx
); /* vector */
8715 /* Ignore the element if it has no prompt string. */
8716 if (INTEGERP (event
) && parse_menu_item (elt
, 0, -1))
8718 /* 1 if the char to type matches the string. */
8720 Lisp_Object upcased_event
, downcased_event
;
8721 Lisp_Object desc
= Qnil
;
8723 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
8725 upcased_event
= Fupcase (event
);
8726 downcased_event
= Fdowncase (event
);
8727 char_matches
= (XINT (upcased_event
) == SREF (s
, 0)
8728 || XINT (downcased_event
) == SREF (s
, 0));
8730 desc
= Fsingle_key_description (event
, Qnil
);
8732 #if 0 /* It is redundant to list the equivalent key bindings because
8733 the prefix is what the user has already typed. */
8735 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
8737 /* Insert equivalent keybinding. */
8738 s
= concat2 (s
, tem
);
8741 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_TYPE
];
8742 if (EQ (tem
, QCradio
) || EQ (tem
, QCtoggle
))
8744 /* Insert button prefix. */
8745 Lisp_Object selected
8746 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
];
8747 if (EQ (tem
, QCradio
))
8748 tem
= build_string (NILP (selected
) ? "(*) " : "( ) ");
8750 tem
= build_string (NILP (selected
) ? "[X] " : "[ ] ");
8751 s
= concat2 (tem
, s
);
8755 /* If we have room for the prompt string, add it to this line.
8756 If this is the first on the line, always add it. */
8757 if ((SCHARS (s
) + i
+ 2
8758 + (char_matches
? 0 : SCHARS (desc
) + 3))
8764 /* Punctuate between strings. */
8767 strcpy (menu
+ i
, ", ");
8773 /* If the char to type doesn't match the string's
8774 first char, explicitly show what char to type. */
8777 /* Add as much of string as fits. */
8778 thiswidth
= SCHARS (desc
);
8779 if (thiswidth
+ i
> width
)
8780 thiswidth
= width
- i
;
8781 bcopy (SDATA (desc
), menu
+ i
, thiswidth
);
8783 strcpy (menu
+ i
, " = ");
8787 /* Add as much of string as fits. */
8788 thiswidth
= SCHARS (s
);
8789 if (thiswidth
+ i
> width
)
8790 thiswidth
= width
- i
;
8791 bcopy (SDATA (s
), menu
+ i
, thiswidth
);
8797 /* If this element does not fit, end the line now,
8798 and save the element for the next line. */
8799 strcpy (menu
+ i
, "...");
8804 /* Move past this element. */
8805 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
8806 /* Handle reaching end of dense table. */
8811 rest
= Fcdr_safe (rest
);
8815 /* Prompt with that and read response. */
8816 message2_nolog (menu
, strlen (menu
),
8817 ! NILP (current_buffer
->enable_multibyte_characters
));
8819 /* Make believe its not a keyboard macro in case the help char
8820 is pressed. Help characters are not recorded because menu prompting
8821 is not used on replay.
8823 orig_defn_macro
= current_kboard
->defining_kbd_macro
;
8824 current_kboard
->defining_kbd_macro
= Qnil
;
8826 obj
= read_char (commandflag
, 0, 0, Qt
, 0, NULL
);
8827 while (BUFFERP (obj
));
8828 current_kboard
->defining_kbd_macro
= orig_defn_macro
;
8830 if (!INTEGERP (obj
))
8832 else if (XINT (obj
) == -2)
8837 if (! EQ (obj
, menu_prompt_more_char
)
8838 && (!INTEGERP (menu_prompt_more_char
)
8839 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
8841 if (!NILP (current_kboard
->defining_kbd_macro
))
8842 store_kbd_macro_char (obj
);
8845 /* Help char - go round again */
8849 /* Reading key sequences. */
8851 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
8852 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
8853 keymap, or nil otherwise. Return the index of the first keymap in
8854 which KEY has any binding, or NMAPS if no map has a binding.
8856 If KEY is a meta ASCII character, treat it like meta-prefix-char
8857 followed by the corresponding non-meta character. Keymaps in
8858 CURRENT with non-prefix bindings for meta-prefix-char become nil in
8861 If KEY has no bindings in any of the CURRENT maps, NEXT is left
8864 NEXT may be the same array as CURRENT. */
8867 follow_key (key
, nmaps
, current
, defs
, next
)
8869 Lisp_Object
*current
, *defs
, *next
;
8872 int i
, first_binding
;
8874 first_binding
= nmaps
;
8875 for (i
= nmaps
- 1; i
>= 0; i
--)
8877 if (! NILP (current
[i
]))
8879 defs
[i
] = access_keymap (current
[i
], key
, 1, 0, 1);
8880 if (! NILP (defs
[i
]))
8887 /* Given the set of bindings we've found, produce the next set of maps. */
8888 if (first_binding
< nmaps
)
8889 for (i
= 0; i
< nmaps
; i
++)
8890 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap (defs
[i
], 0, 1);
8892 return first_binding
;
8895 /* Structure used to keep track of partial application of key remapping
8896 such as Vfunction_key_map and Vkey_translation_map. */
8897 typedef struct keyremap
8899 /* This is the map originally specified for this use. */
8901 /* This is a submap reached by looking up, in PARENT,
8902 the events from START to END. */
8904 /* Positions [START, END) in the key sequence buffer
8905 are the key that we have scanned so far.
8906 Those events are the ones that we will replace
8907 if PAREHT maps them into a key sequence. */
8911 /* Lookup KEY in MAP.
8912 MAP is a keymap mapping keys to key vectors or functions.
8913 If the mapping is a function and DO_FUNCTION is non-zero, then
8914 the function is called with PROMPT as parameter and its return
8915 value is used as the return value of this function (after checking
8916 that it is indeed a vector). */
8919 access_keymap_keyremap (map
, key
, prompt
, do_funcall
)
8920 Lisp_Object map
, key
, prompt
;
8925 next
= access_keymap (map
, key
, 1, 0, 1);
8927 /* Handle symbol with autoload definition. */
8928 if (SYMBOLP (next
) && !NILP (Ffboundp (next
))
8929 && CONSP (XSYMBOL (next
)->function
)
8930 && EQ (XCAR (XSYMBOL (next
)->function
), Qautoload
))
8931 do_autoload (XSYMBOL (next
)->function
, next
);
8933 /* Handle a symbol whose function definition is a keymap
8935 if (SYMBOLP (next
) && !NILP (Ffboundp (next
))
8936 && (ARRAYP (XSYMBOL (next
)->function
)
8937 || KEYMAPP (XSYMBOL (next
)->function
)))
8938 next
= XSYMBOL (next
)->function
;
8940 /* If the keymap gives a function, not an
8941 array, then call the function with one arg and use
8942 its value instead. */
8943 if (SYMBOLP (next
) && !NILP (Ffboundp (next
)) && do_funcall
)
8948 next
= call1 (next
, prompt
);
8949 /* If the function returned something invalid,
8950 barf--don't ignore it.
8951 (To ignore it safely, we would need to gcpro a bunch of
8952 other variables.) */
8953 if (! (VECTORP (next
) || STRINGP (next
)))
8954 error ("Function %s returns invalid key sequence", tem
);
8959 /* Do one step of the key remapping used for function-key-map and
8960 key-translation-map:
8961 KEYBUF is the buffer holding the input events.
8962 BUFSIZE is its maximum size.
8963 FKEY is a pointer to the keyremap structure to use.
8964 INPUT is the index of the last element in KEYBUF.
8965 DOIT if non-zero says that the remapping can actually take place.
8966 DIFF is used to return the number of keys added/removed by the remapping.
8967 PARENT is the root of the keymap.
8968 PROMPT is the prompt to use if the remapping happens through a function.
8969 The return value is non-zero if the remapping actually took place. */
8972 keyremap_step (keybuf
, bufsize
, fkey
, input
, doit
, diff
, prompt
)
8973 Lisp_Object
*keybuf
, prompt
;
8975 int input
, doit
, *diff
, bufsize
;
8977 Lisp_Object next
, key
;
8979 key
= keybuf
[fkey
->end
++];
8981 if (KEYMAPP (fkey
->parent
))
8982 next
= access_keymap_keyremap (fkey
->map
, key
, prompt
, doit
);
8986 /* If keybuf[fkey->start..fkey->end] is bound in the
8987 map and we're in a position to do the key remapping, replace it with
8988 the binding and restart with fkey->start at the end. */
8989 if ((VECTORP (next
) || STRINGP (next
)) && doit
)
8991 int len
= XFASTINT (Flength (next
));
8994 *diff
= len
- (fkey
->end
- fkey
->start
);
8996 if (input
+ *diff
>= bufsize
)
8997 error ("Key sequence too long");
8999 /* Shift the keys that follow fkey->end. */
9001 for (i
= fkey
->end
; i
< input
; i
++)
9002 keybuf
[i
+ *diff
] = keybuf
[i
];
9004 for (i
= input
- 1; i
>= fkey
->end
; i
--)
9005 keybuf
[i
+ *diff
] = keybuf
[i
];
9006 /* Overwrite the old keys with the new ones. */
9007 for (i
= 0; i
< len
; i
++)
9008 keybuf
[fkey
->start
+ i
]
9009 = Faref (next
, make_number (i
));
9011 fkey
->start
= fkey
->end
+= *diff
;
9012 fkey
->map
= fkey
->parent
;
9017 fkey
->map
= get_keymap (next
, 0, 1);
9019 /* If we no longer have a bound suffix, try a new position for
9021 if (!CONSP (fkey
->map
))
9023 fkey
->end
= ++fkey
->start
;
9024 fkey
->map
= fkey
->parent
;
9029 /* Read a sequence of keys that ends with a non prefix character,
9030 storing it in KEYBUF, a buffer of size BUFSIZE.
9032 Return the length of the key sequence stored.
9033 Return -1 if the user rejected a command menu.
9035 Echo starting immediately unless `prompt' is 0.
9037 Where a key sequence ends depends on the currently active keymaps.
9038 These include any minor mode keymaps active in the current buffer,
9039 the current buffer's local map, and the global map.
9041 If a key sequence has no other bindings, we check Vfunction_key_map
9042 to see if some trailing subsequence might be the beginning of a
9043 function key's sequence. If so, we try to read the whole function
9044 key, and substitute its symbolic name into the key sequence.
9046 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
9047 `double-' events into similar click events, if that would make them
9048 bound. We try to turn `triple-' events first into `double-' events,
9051 If we get a mouse click in a mode line, vertical divider, or other
9052 non-text area, we treat the click as if it were prefixed by the
9053 symbol denoting that area - `mode-line', `vertical-line', or
9056 If the sequence starts with a mouse click, we read the key sequence
9057 with respect to the buffer clicked on, not the current buffer.
9059 If the user switches frames in the midst of a key sequence, we put
9060 off the switch-frame event until later; the next call to
9061 read_char will return it.
9063 If FIX_CURRENT_BUFFER is nonzero, we restore current_buffer
9064 from the selected window's buffer. */
9067 read_key_sequence (keybuf
, bufsize
, prompt
, dont_downcase_last
,
9068 can_return_switch_frame
, fix_current_buffer
)
9069 Lisp_Object
*keybuf
;
9072 int dont_downcase_last
;
9073 int can_return_switch_frame
;
9074 int fix_current_buffer
;
9076 volatile Lisp_Object from_string
;
9077 volatile int count
= SPECPDL_INDEX ();
9079 /* How many keys there are in the current key sequence. */
9082 /* The length of the echo buffer when we started reading, and
9083 the length of this_command_keys when we started reading. */
9084 volatile int echo_start
;
9085 volatile int keys_start
;
9087 /* The number of keymaps we're scanning right now, and the number of
9088 keymaps we have allocated space for. */
9090 volatile int nmaps_allocated
= 0;
9092 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
9093 the current keymaps. */
9094 Lisp_Object
*volatile defs
= NULL
;
9096 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
9097 in the current keymaps, or nil where it is not a prefix. */
9098 Lisp_Object
*volatile submaps
= NULL
;
9100 /* The local map to start out with at start of key sequence. */
9101 volatile Lisp_Object orig_local_map
;
9103 /* The map from the `keymap' property to start out with at start of
9105 volatile Lisp_Object orig_keymap
;
9107 /* 1 if we have already considered switching to the local-map property
9108 of the place where a mouse click occurred. */
9109 volatile int localized_local_map
= 0;
9111 /* The index in submaps[] of the first keymap that has a binding for
9112 this key sequence. In other words, the lowest i such that
9113 submaps[i] is non-nil. */
9114 volatile int first_binding
;
9115 /* Index of the first key that has no binding.
9116 It is useless to try fkey.start larger than that. */
9117 volatile int first_unbound
;
9119 /* If t < mock_input, then KEYBUF[t] should be read as the next
9122 We use this to recover after recognizing a function key. Once we
9123 realize that a suffix of the current key sequence is actually a
9124 function key's escape sequence, we replace the suffix with the
9125 function key's binding from Vfunction_key_map. Now keybuf
9126 contains a new and different key sequence, so the echo area,
9127 this_command_keys, and the submaps and defs arrays are wrong. In
9128 this situation, we set mock_input to t, set t to 0, and jump to
9129 restart_sequence; the loop will read keys from keybuf up until
9130 mock_input, thus rebuilding the state; and then it will resume
9131 reading characters from the keyboard. */
9132 volatile int mock_input
= 0;
9134 /* If the sequence is unbound in submaps[], then
9135 keybuf[fkey.start..fkey.end-1] is a prefix in Vfunction_key_map,
9136 and fkey.map is its binding.
9138 These might be > t, indicating that all function key scanning
9139 should hold off until t reaches them. We do this when we've just
9140 recognized a function key, to avoid searching for the function
9141 key's again in Vfunction_key_map. */
9142 volatile keyremap fkey
;
9144 /* Likewise, for key_translation_map and input-decode-map. */
9145 volatile keyremap keytran
, indec
;
9147 /* If we receive a `switch-frame' or `select-window' event in the middle of
9148 a key sequence, we put it off for later.
9149 While we're reading, we keep the event here. */
9150 volatile Lisp_Object delayed_switch_frame
;
9152 /* See the comment below... */
9153 #if defined (GOBBLE_FIRST_EVENT)
9154 Lisp_Object first_event
;
9157 volatile Lisp_Object original_uppercase
;
9158 volatile int original_uppercase_position
= -1;
9160 /* Gets around Microsoft compiler limitations. */
9163 struct buffer
*starting_buffer
;
9165 /* List of events for which a fake prefix key has been generated. */
9166 volatile Lisp_Object fake_prefixed_keys
= Qnil
;
9168 #if defined (GOBBLE_FIRST_EVENT)
9172 struct gcpro gcpro1
;
9174 GCPRO1 (fake_prefixed_keys
);
9175 raw_keybuf_count
= 0;
9177 last_nonmenu_event
= Qnil
;
9179 delayed_switch_frame
= Qnil
;
9184 echo_prompt (prompt
);
9185 else if (cursor_in_echo_area
9186 && (FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
9187 && NILP (Fzerop (Vecho_keystrokes
)))
9188 /* This doesn't put in a dash if the echo buffer is empty, so
9189 you don't always see a dash hanging out in the minibuffer. */
9193 /* Record the initial state of the echo area and this_command_keys;
9194 we will need to restore them if we replay a key sequence. */
9196 echo_start
= echo_length ();
9197 keys_start
= this_command_key_count
;
9198 this_single_command_key_start
= keys_start
;
9200 #if defined (GOBBLE_FIRST_EVENT)
9201 /* This doesn't quite work, because some of the things that read_char
9202 does cannot safely be bypassed. It seems too risky to try to make
9205 /* Read the first char of the sequence specially, before setting
9206 up any keymaps, in case a filter runs and switches buffers on us. */
9207 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
9209 #endif /* GOBBLE_FIRST_EVENT */
9211 orig_local_map
= get_local_map (PT
, current_buffer
, Qlocal_map
);
9212 orig_keymap
= get_local_map (PT
, current_buffer
, Qkeymap
);
9215 /* We jump here when the key sequence has been thoroughly changed, and
9216 we need to rescan it starting from the beginning. When we jump here,
9217 keybuf[0..mock_input] holds the sequence we should reread. */
9220 /* We may switch keyboards between rescans, so we need to
9221 reinitialize fkey and keytran before each replay. */
9222 indec
.map
= indec
.parent
= current_kboard
->Vinput_decode_map
;
9223 fkey
.map
= fkey
.parent
= current_kboard
->Vlocal_function_key_map
;
9224 keytran
.map
= keytran
.parent
= Vkey_translation_map
;
9225 indec
.start
= indec
.end
= 0;
9226 fkey
.start
= fkey
.end
= 0;
9227 keytran
.start
= keytran
.end
= 0;
9229 starting_buffer
= current_buffer
;
9230 first_unbound
= bufsize
+ 1;
9232 /* Build our list of keymaps.
9233 If we recognize a function key and replace its escape sequence in
9234 keybuf with its symbol, or if the sequence starts with a mouse
9235 click and we need to switch buffers, we jump back here to rebuild
9236 the initial keymaps from the current buffer. */
9239 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
9241 if (2 > nmaps_allocated
)
9243 submaps
= (Lisp_Object
*) alloca (2 * sizeof (submaps
[0]));
9244 defs
= (Lisp_Object
*) alloca (2 * sizeof (defs
[0]));
9245 nmaps_allocated
= 2;
9247 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
9248 submaps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
9250 else if (!NILP (Voverriding_local_map
))
9252 if (2 > nmaps_allocated
)
9254 submaps
= (Lisp_Object
*) alloca (2 * sizeof (submaps
[0]));
9255 defs
= (Lisp_Object
*) alloca (2 * sizeof (defs
[0]));
9256 nmaps_allocated
= 2;
9258 if (!NILP (Voverriding_local_map
))
9259 submaps
[nmaps
++] = Voverriding_local_map
;
9267 nminor
= current_minor_maps (0, &maps
);
9268 total
= nminor
+ (!NILP (orig_keymap
) ? 3 : 2);
9270 if (total
> nmaps_allocated
)
9272 submaps
= (Lisp_Object
*) alloca (total
* sizeof (submaps
[0]));
9273 defs
= (Lisp_Object
*) alloca (total
* sizeof (defs
[0]));
9274 nmaps_allocated
= total
;
9277 if (!NILP (orig_keymap
))
9278 submaps
[nmaps
++] = orig_keymap
;
9280 bcopy (maps
, (void *) (submaps
+ nmaps
),
9281 nminor
* sizeof (submaps
[0]));
9285 submaps
[nmaps
++] = orig_local_map
;
9287 submaps
[nmaps
++] = current_global_map
;
9289 /* Find an accurate initial value for first_binding. */
9290 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
9291 if (! NILP (submaps
[first_binding
]))
9294 /* Start from the beginning in keybuf. */
9297 /* These are no-ops the first time through, but if we restart, they
9298 revert the echo area and this_command_keys to their original state. */
9299 this_command_key_count
= keys_start
;
9300 if (INTERACTIVE
&& t
< mock_input
)
9301 echo_truncate (echo_start
);
9303 /* If the best binding for the current key sequence is a keymap, or
9304 we may be looking at a function key's escape sequence, keep on
9306 while (first_binding
< nmaps
9307 /* Keep reading as long as there's a prefix binding. */
9308 ? !NILP (submaps
[first_binding
])
9309 /* Don't return in the middle of a possible function key sequence,
9310 if the only bindings we found were via case conversion.
9311 Thus, if ESC O a has a function-key-map translation
9312 and ESC o has a binding, don't return after ESC O,
9313 so that we can translate ESC O plus the next character. */
9314 : (/* indec.start < t || fkey.start < t || */ keytran
.start
< t
))
9317 int used_mouse_menu
= 0;
9319 /* Where the last real key started. If we need to throw away a
9320 key that has expanded into more than one element of keybuf
9321 (say, a mouse click on the mode line which is being treated
9322 as [mode-line (mouse-...)], then we backtrack to this point
9324 volatile int last_real_key_start
;
9326 /* These variables are analogous to echo_start and keys_start;
9327 while those allow us to restart the entire key sequence,
9328 echo_local_start and keys_local_start allow us to throw away
9330 volatile int echo_local_start
, keys_local_start
, local_first_binding
;
9332 eassert (indec
.end
== t
|| (indec
.end
> t
&& indec
.end
<= mock_input
));
9333 eassert (indec
.start
<= indec
.end
);
9334 eassert (fkey
.start
<= fkey
.end
);
9335 eassert (keytran
.start
<= keytran
.end
);
9336 /* key-translation-map is applied *after* function-key-map
9337 which is itself applied *after* input-decode-map. */
9338 eassert (fkey
.end
<= indec
.start
);
9339 eassert (keytran
.end
<= fkey
.start
);
9341 if (/* first_unbound < indec.start && first_unbound < fkey.start && */
9342 first_unbound
< keytran
.start
)
9343 { /* The prefix upto first_unbound has no binding and has
9344 no translation left to do either, so we know it's unbound.
9345 If we don't stop now, we risk staying here indefinitely
9346 (if the user keeps entering fkey or keytran prefixes
9347 like C-c ESC ESC ESC ESC ...) */
9349 for (i
= first_unbound
+ 1; i
< t
; i
++)
9350 keybuf
[i
- first_unbound
- 1] = keybuf
[i
];
9351 mock_input
= t
- first_unbound
- 1;
9352 indec
.end
= indec
.start
-= first_unbound
+ 1;
9353 indec
.map
= indec
.parent
;
9354 fkey
.end
= fkey
.start
-= first_unbound
+ 1;
9355 fkey
.map
= fkey
.parent
;
9356 keytran
.end
= keytran
.start
-= first_unbound
+ 1;
9357 keytran
.map
= keytran
.parent
;
9358 goto replay_sequence
;
9362 error ("Key sequence too long");
9365 echo_local_start
= echo_length ();
9366 keys_local_start
= this_command_key_count
;
9367 local_first_binding
= first_binding
;
9370 /* These are no-ops, unless we throw away a keystroke below and
9371 jumped back up to replay_key; in that case, these restore the
9372 variables to their original state, allowing us to replay the
9374 if (INTERACTIVE
&& t
< mock_input
)
9375 echo_truncate (echo_local_start
);
9376 this_command_key_count
= keys_local_start
;
9377 first_binding
= local_first_binding
;
9379 /* By default, assume each event is "real". */
9380 last_real_key_start
= t
;
9382 /* Does mock_input indicate that we are re-reading a key sequence? */
9386 add_command_key (key
);
9387 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
9388 && NILP (Fzerop (Vecho_keystrokes
)))
9392 /* If not, we should actually read a character. */
9397 KBOARD
*interrupted_kboard
= current_kboard
;
9398 struct frame
*interrupted_frame
= SELECTED_FRAME ();
9400 key
= read_char (NILP (prompt
), nmaps
,
9401 (Lisp_Object
*) submaps
, last_nonmenu_event
,
9402 &used_mouse_menu
, NULL
);
9404 if (INTEGERP (key
) && XINT (key
) == -2) /* wrong_kboard_jmpbuf */
9409 for (k
= all_kboards
; k
; k
= k
->next_kboard
)
9410 if (k
== interrupted_kboard
)
9415 /* Don't touch interrupted_kboard when it's been
9417 delayed_switch_frame
= Qnil
;
9418 goto replay_sequence
;
9421 if (!NILP (delayed_switch_frame
))
9423 interrupted_kboard
->kbd_queue
9424 = Fcons (delayed_switch_frame
,
9425 interrupted_kboard
->kbd_queue
);
9426 delayed_switch_frame
= Qnil
;
9430 interrupted_kboard
->kbd_queue
9431 = Fcons (keybuf
[--t
], interrupted_kboard
->kbd_queue
);
9433 /* If the side queue is non-empty, ensure it begins with a
9434 switch-frame, so we'll replay it in the right context. */
9435 if (CONSP (interrupted_kboard
->kbd_queue
)
9436 && (key
= XCAR (interrupted_kboard
->kbd_queue
),
9437 !(EVENT_HAS_PARAMETERS (key
)
9438 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)),
9442 XSETFRAME (frame
, interrupted_frame
);
9443 interrupted_kboard
->kbd_queue
9444 = Fcons (make_lispy_switch_frame (frame
),
9445 interrupted_kboard
->kbd_queue
);
9448 orig_local_map
= get_local_map (PT
, current_buffer
, Qlocal_map
);
9449 orig_keymap
= get_local_map (PT
, current_buffer
, Qkeymap
);
9450 goto replay_sequence
;
9455 /* read_char returns t when it shows a menu and the user rejects it.
9459 unbind_to (count
, Qnil
);
9464 /* read_char returns -1 at the end of a macro.
9465 Emacs 18 handles this by returning immediately with a
9466 zero, so that's what we'll do. */
9467 if (INTEGERP (key
) && XINT (key
) == -1)
9470 /* The Microsoft C compiler can't handle the goto that
9476 /* If the current buffer has been changed from under us, the
9477 keymap may have changed, so replay the sequence. */
9480 timer_resume_idle ();
9483 /* Reset the current buffer from the selected window
9484 in case something changed the former and not the latter.
9485 This is to be more consistent with the behavior
9486 of the command_loop_1. */
9487 if (fix_current_buffer
)
9489 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
9491 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
9492 Fset_buffer (XWINDOW (selected_window
)->buffer
);
9495 orig_local_map
= get_local_map (PT
, current_buffer
, Qlocal_map
);
9496 orig_keymap
= get_local_map (PT
, current_buffer
, Qkeymap
);
9497 goto replay_sequence
;
9500 /* If we have a quit that was typed in another frame, and
9501 quit_throw_to_read_char switched buffers,
9502 replay to get the right keymap. */
9504 && XINT (key
) == quit_char
9505 && current_buffer
!= starting_buffer
)
9508 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
9512 orig_local_map
= get_local_map (PT
, current_buffer
, Qlocal_map
);
9513 orig_keymap
= get_local_map (PT
, current_buffer
, Qkeymap
);
9514 goto replay_sequence
;
9519 if (EVENT_HAS_PARAMETERS (key
)
9520 /* Either a `switch-frame' or a `select-window' event. */
9521 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)), Qswitch_frame
))
9523 /* If we're at the beginning of a key sequence, and the caller
9524 says it's okay, go ahead and return this event. If we're
9525 in the midst of a key sequence, delay it until the end. */
9526 if (t
> 0 || !can_return_switch_frame
)
9528 delayed_switch_frame
= key
;
9534 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
9537 /* Clicks in non-text areas get prefixed by the symbol
9538 in their CHAR-ADDRESS field. For example, a click on
9539 the mode line is prefixed by the symbol `mode-line'.
9541 Furthermore, key sequences beginning with mouse clicks
9542 are read using the keymaps of the buffer clicked on, not
9543 the current buffer. So we may have to switch the buffer
9546 When we turn one event into two events, we must make sure
9547 that neither of the two looks like the original--so that,
9548 if we replay the events, they won't be expanded again.
9549 If not for this, such reexpansion could happen either here
9550 or when user programs play with this-command-keys. */
9551 if (EVENT_HAS_PARAMETERS (key
))
9556 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
9557 if (EQ (kind
, Qmouse_click
))
9559 Lisp_Object window
, posn
;
9561 window
= POSN_WINDOW (EVENT_START (key
));
9562 posn
= POSN_POSN (EVENT_START (key
));
9565 || (!NILP (fake_prefixed_keys
)
9566 && !NILP (Fmemq (key
, fake_prefixed_keys
))))
9568 /* We're looking a second time at an event for which
9569 we generated a fake prefix key. Set
9570 last_real_key_start appropriately. */
9572 last_real_key_start
= t
- 1;
9575 /* Key sequences beginning with mouse clicks are
9576 read using the keymaps in the buffer clicked on,
9577 not the current buffer. If we're at the
9578 beginning of a key sequence, switch buffers. */
9579 if (last_real_key_start
== 0
9581 && BUFFERP (XWINDOW (window
)->buffer
)
9582 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
9584 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
9588 /* Arrange to go back to the original buffer once we're
9589 done reading the key sequence. Note that we can't
9590 use save_excursion_{save,restore} here, because they
9591 save point as well as the current buffer; we don't
9592 want to save point, because redisplay may change it,
9593 to accommodate a Fset_window_start or something. We
9594 don't want to do this at the top of the function,
9595 because we may get input from a subprocess which
9596 wants to change the selected window and stuff (say,
9598 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
9600 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
9602 set_buffer_internal (XBUFFER (XWINDOW (window
)->buffer
));
9603 orig_local_map
= get_local_map (PT
, current_buffer
,
9605 orig_keymap
= get_local_map (PT
, current_buffer
, Qkeymap
);
9606 goto replay_sequence
;
9609 /* For a mouse click, get the local text-property keymap
9610 of the place clicked on, rather than point. */
9611 if (last_real_key_start
== 0
9612 && CONSP (XCDR (key
))
9613 && ! localized_local_map
)
9615 Lisp_Object map_here
, start
, pos
;
9617 localized_local_map
= 1;
9618 start
= EVENT_START (key
);
9620 if (CONSP (start
) && POSN_INBUFFER_P (start
))
9622 pos
= POSN_BUFFER_POSN (start
);
9624 && XINT (pos
) >= BEGV
9625 && XINT (pos
) <= ZV
)
9627 map_here
= get_local_map (XINT (pos
),
9628 current_buffer
, Qlocal_map
);
9629 if (!EQ (map_here
, orig_local_map
))
9631 orig_local_map
= map_here
;
9632 ++localized_local_map
;
9635 map_here
= get_local_map (XINT (pos
),
9636 current_buffer
, Qkeymap
);
9637 if (!EQ (map_here
, orig_keymap
))
9639 orig_keymap
= map_here
;
9640 ++localized_local_map
;
9643 if (localized_local_map
> 1)
9648 goto replay_sequence
;
9654 /* Expand mode-line and scroll-bar events into two events:
9655 use posn as a fake prefix key. */
9657 && (NILP (fake_prefixed_keys
)
9658 || NILP (Fmemq (key
, fake_prefixed_keys
))))
9660 if (t
+ 1 >= bufsize
)
9661 error ("Key sequence too long");
9664 keybuf
[t
+ 1] = key
;
9667 /* Record that a fake prefix key has been generated
9668 for KEY. Don't modify the event; this would
9669 prevent proper action when the event is pushed
9670 back into unread-command-events. */
9671 fake_prefixed_keys
= Fcons (key
, fake_prefixed_keys
);
9673 /* If on a mode line string with a local keymap,
9674 reconsider the key sequence with that keymap. */
9675 if (string
= POSN_STRING (EVENT_START (key
)),
9676 (CONSP (string
) && STRINGP (XCAR (string
))))
9678 Lisp_Object pos
, map
, map2
;
9680 pos
= XCDR (string
);
9681 string
= XCAR (string
);
9683 && XINT (pos
) < SCHARS (string
))
9685 map
= Fget_text_property (pos
, Qlocal_map
, string
);
9687 orig_local_map
= map
;
9688 map2
= Fget_text_property (pos
, Qkeymap
, string
);
9691 if (!NILP (map
) || !NILP (map2
))
9692 goto replay_sequence
;
9698 else if (NILP (from_string
)
9699 && (string
= POSN_STRING (EVENT_START (key
)),
9700 (CONSP (string
) && STRINGP (XCAR (string
)))))
9702 /* For a click on a string, i.e. overlay string or a
9703 string displayed via the `display' property,
9704 consider `local-map' and `keymap' properties of
9706 Lisp_Object pos
, map
, map2
;
9708 pos
= XCDR (string
);
9709 string
= XCAR (string
);
9711 && XINT (pos
) < SCHARS (string
))
9713 map
= Fget_text_property (pos
, Qlocal_map
, string
);
9715 orig_local_map
= map
;
9716 map2
= Fget_text_property (pos
, Qkeymap
, string
);
9720 if (!NILP (map
) || !NILP (map2
))
9722 from_string
= string
;
9725 goto replay_sequence
;
9730 else if (CONSP (XCDR (key
))
9731 && CONSP (EVENT_START (key
))
9732 && CONSP (XCDR (EVENT_START (key
))))
9736 posn
= POSN_POSN (EVENT_START (key
));
9737 /* Handle menu-bar events:
9738 insert the dummy prefix event `menu-bar'. */
9739 if (EQ (posn
, Qmenu_bar
) || EQ (posn
, Qtool_bar
))
9741 if (t
+ 1 >= bufsize
)
9742 error ("Key sequence too long");
9746 /* Zap the position in key, so we know that we've
9747 expanded it, and don't try to do so again. */
9748 POSN_SET_POSN (EVENT_START (key
),
9749 Fcons (posn
, Qnil
));
9752 goto replay_sequence
;
9754 else if (CONSP (posn
))
9756 /* We're looking at the second event of a
9757 sequence which we expanded before. Set
9758 last_real_key_start appropriately. */
9759 if (last_real_key_start
== t
&& t
> 0)
9760 last_real_key_start
= t
- 1;
9765 /* We have finally decided that KEY is something we might want
9767 first_binding
= (follow_key (key
,
9768 nmaps
- first_binding
,
9769 submaps
+ first_binding
,
9770 defs
+ first_binding
,
9771 submaps
+ first_binding
)
9774 /* If KEY wasn't bound, we'll try some fallbacks. */
9775 if (first_binding
< nmaps
)
9776 /* This is needed for the following scenario:
9777 event 0: a down-event that gets dropped by calling replay_key.
9778 event 1: some normal prefix like C-h.
9779 After event 0, first_unbound is 0, after event 1 indec.start,
9780 fkey.start, and keytran.start are all 1, so when we see that
9781 C-h is bound, we need to update first_unbound. */
9782 first_unbound
= max (t
+ 1, first_unbound
);
9787 /* Remember the position to put an upper bound on indec.start. */
9788 first_unbound
= min (t
, first_unbound
);
9790 head
= EVENT_HEAD (key
);
9791 if (help_char_p (head
) && t
> 0)
9793 read_key_sequence_cmd
= Vprefix_help_command
;
9795 last_nonmenu_event
= key
;
9796 /* The Microsoft C compiler can't handle the goto that
9804 Lisp_Object breakdown
;
9807 breakdown
= parse_modifiers (head
);
9808 modifiers
= XINT (XCAR (XCDR (breakdown
)));
9809 /* Attempt to reduce an unbound mouse event to a simpler
9810 event that is bound:
9811 Drags reduce to clicks.
9812 Double-clicks reduce to clicks.
9813 Triple-clicks reduce to double-clicks, then to clicks.
9814 Down-clicks are eliminated.
9815 Double-downs reduce to downs, then are eliminated.
9816 Triple-downs reduce to double-downs, then to downs,
9817 then are eliminated. */
9818 if (modifiers
& (down_modifier
| drag_modifier
9819 | double_modifier
| triple_modifier
))
9821 while (modifiers
& (down_modifier
| drag_modifier
9822 | double_modifier
| triple_modifier
))
9824 Lisp_Object new_head
, new_click
;
9825 if (modifiers
& triple_modifier
)
9826 modifiers
^= (double_modifier
| triple_modifier
);
9827 else if (modifiers
& double_modifier
)
9828 modifiers
&= ~double_modifier
;
9829 else if (modifiers
& drag_modifier
)
9830 modifiers
&= ~drag_modifier
;
9833 /* Dispose of this `down' event by simply jumping
9834 back to replay_key, to get another event.
9836 Note that if this event came from mock input,
9837 then just jumping back to replay_key will just
9838 hand it to us again. So we have to wipe out any
9841 We could delete keybuf[t] and shift everything
9842 after that to the left by one spot, but we'd also
9843 have to fix up any variable that points into
9844 keybuf, and shifting isn't really necessary
9847 Adding prefixes for non-textual mouse clicks
9848 creates two characters of mock input, and both
9849 must be thrown away. If we're only looking at
9850 the prefix now, we can just jump back to
9851 replay_key. On the other hand, if we've already
9852 processed the prefix, and now the actual click
9853 itself is giving us trouble, then we've lost the
9854 state of the keymaps we want to backtrack to, and
9855 we need to replay the whole sequence to rebuild
9858 Beyond that, only function key expansion could
9859 create more than two keys, but that should never
9860 generate mouse events, so it's okay to zero
9861 mock_input in that case too.
9863 FIXME: The above paragraph seems just plain
9864 wrong, if you consider things like
9865 xterm-mouse-mode. -stef
9867 Isn't this just the most wonderful code ever? */
9869 /* If mock_input > t + 1, the above simplification
9870 will actually end up dropping keys on the floor.
9871 This is probably OK for now, but even
9872 if mock_input <= t + 1, we need to adjust indec,
9874 Typical case [header-line down-mouse-N]:
9875 mock_input = 2, t = 1, fkey.end = 1,
9876 last_real_key_start = 0. */
9877 if (indec
.end
> last_real_key_start
)
9879 indec
.end
= indec
.start
9880 = min (last_real_key_start
, indec
.start
);
9881 indec
.map
= indec
.parent
;
9882 if (fkey
.end
> last_real_key_start
)
9884 fkey
.end
= fkey
.start
9885 = min (last_real_key_start
, fkey
.start
);
9886 fkey
.map
= fkey
.parent
;
9887 if (keytran
.end
> last_real_key_start
)
9889 keytran
.end
= keytran
.start
9890 = min (last_real_key_start
, keytran
.start
);
9891 keytran
.map
= keytran
.parent
;
9895 if (t
== last_real_key_start
)
9902 mock_input
= last_real_key_start
;
9903 goto replay_sequence
;
9908 = apply_modifiers (modifiers
, XCAR (breakdown
));
9910 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
9912 /* Look for a binding for this new key. follow_key
9913 promises that it didn't munge submaps the
9914 last time we called it, since key was unbound. */
9916 = (follow_key (new_click
,
9917 nmaps
- local_first_binding
,
9918 submaps
+ local_first_binding
,
9919 defs
+ local_first_binding
,
9920 submaps
+ local_first_binding
)
9921 + local_first_binding
);
9923 /* If that click is bound, go for it. */
9924 if (first_binding
< nmaps
)
9929 /* Otherwise, we'll leave key set to the drag event. */
9936 /* Normally, last_nonmenu_event gets the previous key we read.
9937 But when a mouse popup menu is being used,
9938 we don't update last_nonmenu_event; it continues to hold the mouse
9939 event that preceded the first level of menu. */
9940 if (!used_mouse_menu
)
9941 last_nonmenu_event
= key
;
9943 /* Record what part of this_command_keys is the current key sequence. */
9944 this_single_command_key_start
= this_command_key_count
- t
;
9946 /* Look for this sequence in input-decode-map.
9947 Scan from indec.end until we find a bound suffix. */
9948 while (indec
.end
< t
)
9950 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9953 GCPRO4 (indec
.map
, fkey
.map
, keytran
.map
, delayed_switch_frame
);
9954 done
= keyremap_step (keybuf
, bufsize
, &indec
, max (t
, mock_input
),
9959 mock_input
= diff
+ max (t
, mock_input
);
9960 goto replay_sequence
;
9964 if (first_binding
< nmaps
&& NILP (submaps
[first_binding
])
9965 && indec
.start
>= t
)
9966 /* There is a binding and it's not a prefix.
9967 (and it doesn't have any input-decode-map translation pending).
9968 There is thus no function-key in this sequence.
9969 Moving fkey.start is important in this case to allow keytran.start
9970 to go over the sequence before we return (since we keep the
9971 invariant that keytran.end <= fkey.start). */
9974 (fkey
.start
= fkey
.end
= t
, fkey
.map
= fkey
.parent
);
9977 /* If the sequence is unbound, see if we can hang a function key
9978 off the end of it. */
9979 /* Continue scan from fkey.end until we find a bound suffix. */
9980 while (fkey
.end
< indec
.start
)
9982 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9985 GCPRO4 (indec
.map
, fkey
.map
, keytran
.map
, delayed_switch_frame
);
9986 done
= keyremap_step (keybuf
, bufsize
, &fkey
,
9987 max (t
, mock_input
),
9988 /* If there's a binding (i.e.
9989 first_binding >= nmaps) we don't want
9990 to apply this function-key-mapping. */
9991 fkey
.end
+ 1 == t
&& first_binding
>= nmaps
,
9996 mock_input
= diff
+ max (t
, mock_input
);
9997 /* Adjust the input-decode-map counters. */
9999 indec
.start
+= diff
;
10001 goto replay_sequence
;
10005 /* Look for this sequence in key-translation-map.
10006 Scan from keytran.end until we find a bound suffix. */
10007 while (keytran
.end
< fkey
.start
)
10009 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
10012 GCPRO4 (indec
.map
, fkey
.map
, keytran
.map
, delayed_switch_frame
);
10013 done
= keyremap_step (keybuf
, bufsize
, &keytran
, max (t
, mock_input
),
10018 mock_input
= diff
+ max (t
, mock_input
);
10019 /* Adjust the function-key-map and input-decode-map counters. */
10021 indec
.start
+= diff
;
10023 fkey
.start
+= diff
;
10025 goto replay_sequence
;
10029 /* If KEY is not defined in any of the keymaps,
10030 and cannot be part of a function key or translation,
10031 and is an upper case letter
10032 use the corresponding lower-case letter instead. */
10033 if (first_binding
>= nmaps
10034 && /* indec.start >= t && fkey.start >= t && */ keytran
.start
>= t
10036 && ((((XINT (key
) & 0x3ffff)
10037 < XCHAR_TABLE (current_buffer
->downcase_table
)->size
)
10038 && UPPERCASEP (XINT (key
) & 0x3ffff))
10039 || (XINT (key
) & shift_modifier
)))
10041 Lisp_Object new_key
;
10043 original_uppercase
= key
;
10044 original_uppercase_position
= t
- 1;
10046 if (XINT (key
) & shift_modifier
)
10047 XSETINT (new_key
, XINT (key
) & ~shift_modifier
);
10049 XSETINT (new_key
, (DOWNCASE (XINT (key
) & 0x3ffff)
10050 | (XINT (key
) & ~0x3ffff)));
10052 /* We have to do this unconditionally, regardless of whether
10053 the lower-case char is defined in the keymaps, because they
10054 might get translated through function-key-map. */
10055 keybuf
[t
- 1] = new_key
;
10056 mock_input
= max (t
, mock_input
);
10058 goto replay_sequence
;
10060 /* If KEY is not defined in any of the keymaps,
10061 and cannot be part of a function key or translation,
10062 and is a shifted function key,
10063 use the corresponding unshifted function key instead. */
10064 if (first_binding
>= nmaps
10065 && /* indec.start >= t && fkey.start >= t && */ keytran
.start
>= t
10068 Lisp_Object breakdown
;
10071 breakdown
= parse_modifiers (key
);
10072 modifiers
= XINT (XCAR (XCDR (breakdown
)));
10073 if (modifiers
& shift_modifier
)
10075 Lisp_Object new_key
;
10077 original_uppercase
= key
;
10078 original_uppercase_position
= t
- 1;
10080 modifiers
&= ~shift_modifier
;
10081 new_key
= apply_modifiers (modifiers
,
10084 keybuf
[t
- 1] = new_key
;
10085 mock_input
= max (t
, mock_input
);
10086 goto replay_sequence
;
10092 read_key_sequence_cmd
= (first_binding
< nmaps
10093 ? defs
[first_binding
]
10096 unread_switch_frame
= delayed_switch_frame
;
10097 unbind_to (count
, Qnil
);
10099 /* Don't downcase the last character if the caller says don't.
10100 Don't downcase it if the result is undefined, either. */
10101 if ((dont_downcase_last
|| first_binding
>= nmaps
)
10103 && t
- 1 == original_uppercase_position
)
10104 keybuf
[t
- 1] = original_uppercase
;
10106 /* Occasionally we fabricate events, perhaps by expanding something
10107 according to function-key-map, or by adding a prefix symbol to a
10108 mouse click in the scroll bar or modeline. In this cases, return
10109 the entire generated key sequence, even if we hit an unbound
10110 prefix or a definition before the end. This means that you will
10111 be able to push back the event properly, and also means that
10112 read-key-sequence will always return a logical unit.
10115 for (; t
< mock_input
; t
++)
10117 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
10118 && NILP (Fzerop (Vecho_keystrokes
)))
10119 echo_char (keybuf
[t
]);
10120 add_command_key (keybuf
[t
]);
10129 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 5, 0,
10130 doc
: /* Read a sequence of keystrokes and return as a string or vector.
10131 The sequence is sufficient to specify a non-prefix command in the
10132 current local and global maps.
10134 First arg PROMPT is a prompt string. If nil, do not prompt specially.
10135 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos
10136 as a continuation of the previous key.
10138 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not
10139 convert the last event to lower case. (Normally any upper case event
10140 is converted to lower case if the original event is undefined and the lower
10141 case equivalent is defined.) A non-nil value is appropriate for reading
10142 a key sequence to be defined.
10144 A C-g typed while in this function is treated like any other character,
10145 and `quit-flag' is not set.
10147 If the key sequence starts with a mouse click, then the sequence is read
10148 using the keymaps of the buffer of the window clicked in, not the buffer
10149 of the selected window as normal.
10151 `read-key-sequence' drops unbound button-down events, since you normally
10152 only care about the click or drag events which follow them. If a drag
10153 or multi-click event is unbound, but the corresponding click event would
10154 be bound, `read-key-sequence' turns the event into a click event at the
10155 drag's starting position. This means that you don't have to distinguish
10156 between click and drag, double, or triple events unless you want to.
10158 `read-key-sequence' prefixes mouse events on mode lines, the vertical
10159 lines separating windows, and scroll bars with imaginary keys
10160 `mode-line', `vertical-line', and `vertical-scroll-bar'.
10162 Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this
10163 function will process a switch-frame event if the user switches frames
10164 before typing anything. If the user switches frames in the middle of a
10165 key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME
10166 is nil, then the event will be put off until after the current key sequence.
10168 `read-key-sequence' checks `function-key-map' for function key
10169 sequences, where they wouldn't conflict with ordinary bindings. See
10170 `function-key-map' for more details.
10172 The optional fifth argument COMMAND-LOOP, if non-nil, means
10173 that this key sequence is being read by something that will
10174 read commands one after another. It should be nil if the caller
10175 will read just one key sequence. */)
10176 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
10178 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
10179 Lisp_Object can_return_switch_frame
, command_loop
;
10181 Lisp_Object keybuf
[30];
10183 struct gcpro gcpro1
;
10184 int count
= SPECPDL_INDEX ();
10186 if (!NILP (prompt
))
10187 CHECK_STRING (prompt
);
10190 specbind (Qinput_method_exit_on_first_char
,
10191 (NILP (command_loop
) ? Qt
: Qnil
));
10192 specbind (Qinput_method_use_echo_area
,
10193 (NILP (command_loop
) ? Qt
: Qnil
));
10195 bzero (keybuf
, sizeof keybuf
);
10196 GCPRO1 (keybuf
[0]);
10197 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
10199 if (NILP (continue_echo
))
10201 this_command_key_count
= 0;
10202 this_command_key_count_reset
= 0;
10203 this_single_command_key_start
= 0;
10206 #ifdef HAVE_X_WINDOWS
10207 if (display_hourglass_p
)
10208 cancel_hourglass ();
10211 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
10212 prompt
, ! NILP (dont_downcase_last
),
10213 ! NILP (can_return_switch_frame
), 0);
10215 #if 0 /* The following is fine for code reading a key sequence and
10216 then proceeding with a lenghty computation, but it's not good
10217 for code reading keys in a loop, like an input method. */
10218 #ifdef HAVE_X_WINDOWS
10219 if (display_hourglass_p
)
10220 start_hourglass ();
10230 return unbind_to (count
, make_event_array (i
, keybuf
));
10233 DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector
,
10234 Sread_key_sequence_vector
, 1, 5, 0,
10235 doc
: /* Like `read-key-sequence' but always return a vector. */)
10236 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
10238 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
10239 Lisp_Object can_return_switch_frame
, command_loop
;
10241 Lisp_Object keybuf
[30];
10243 struct gcpro gcpro1
;
10244 int count
= SPECPDL_INDEX ();
10246 if (!NILP (prompt
))
10247 CHECK_STRING (prompt
);
10250 specbind (Qinput_method_exit_on_first_char
,
10251 (NILP (command_loop
) ? Qt
: Qnil
));
10252 specbind (Qinput_method_use_echo_area
,
10253 (NILP (command_loop
) ? Qt
: Qnil
));
10255 bzero (keybuf
, sizeof keybuf
);
10256 GCPRO1 (keybuf
[0]);
10257 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
10259 if (NILP (continue_echo
))
10261 this_command_key_count
= 0;
10262 this_command_key_count_reset
= 0;
10263 this_single_command_key_start
= 0;
10266 #ifdef HAVE_X_WINDOWS
10267 if (display_hourglass_p
)
10268 cancel_hourglass ();
10271 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
10272 prompt
, ! NILP (dont_downcase_last
),
10273 ! NILP (can_return_switch_frame
), 0);
10275 #ifdef HAVE_X_WINDOWS
10276 if (display_hourglass_p
)
10277 start_hourglass ();
10286 return unbind_to (count
, Fvector (i
, keybuf
));
10289 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 4, 0,
10290 doc
: /* Execute CMD as an editor command.
10291 CMD must be a symbol that satisfies the `commandp' predicate.
10292 Optional second arg RECORD-FLAG non-nil
10293 means unconditionally put this command in `command-history'.
10294 Otherwise, that is done only if an arg is read using the minibuffer.
10295 The argument KEYS specifies the value to use instead of (this-command-keys)
10296 when reading the arguments; if it is nil, (this-command-keys) is used.
10297 The argument SPECIAL, if non-nil, means that this command is executing
10298 a special event, so ignore the prefix argument and don't clear it. */)
10299 (cmd
, record_flag
, keys
, special
)
10300 Lisp_Object cmd
, record_flag
, keys
, special
;
10302 register Lisp_Object final
;
10303 register Lisp_Object tem
;
10304 Lisp_Object prefixarg
;
10305 struct backtrace backtrace
;
10306 extern int debug_on_next_call
;
10308 debug_on_next_call
= 0;
10310 if (NILP (special
))
10312 prefixarg
= current_kboard
->Vprefix_arg
;
10313 Vcurrent_prefix_arg
= prefixarg
;
10314 current_kboard
->Vprefix_arg
= Qnil
;
10321 tem
= Fget (cmd
, Qdisabled
);
10322 if (!NILP (tem
) && !NILP (Vrun_hooks
))
10324 tem
= Fsymbol_value (Qdisabled_command_function
);
10326 return call1 (Vrun_hooks
, Qdisabled_command_function
);
10332 final
= Findirect_function (cmd
, Qnil
);
10334 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
10336 struct gcpro gcpro1
, gcpro2
;
10338 GCPRO2 (cmd
, prefixarg
);
10339 do_autoload (final
, cmd
);
10346 if (STRINGP (final
) || VECTORP (final
))
10348 /* If requested, place the macro in the command history. For
10349 other sorts of commands, call-interactively takes care of
10351 if (!NILP (record_flag
))
10354 = Fcons (Fcons (Qexecute_kbd_macro
,
10355 Fcons (final
, Fcons (prefixarg
, Qnil
))),
10358 /* Don't keep command history around forever. */
10359 if (NUMBERP (Vhistory_length
) && XINT (Vhistory_length
) > 0)
10361 tem
= Fnthcdr (Vhistory_length
, Vcommand_history
);
10363 XSETCDR (tem
, Qnil
);
10367 return Fexecute_kbd_macro (final
, prefixarg
, Qnil
);
10370 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
10372 backtrace
.next
= backtrace_list
;
10373 backtrace_list
= &backtrace
;
10374 backtrace
.function
= &Qcall_interactively
;
10375 backtrace
.args
= &cmd
;
10376 backtrace
.nargs
= 1;
10377 backtrace
.evalargs
= 0;
10378 backtrace
.debug_on_exit
= 0;
10380 tem
= Fcall_interactively (cmd
, record_flag
, keys
);
10382 backtrace_list
= backtrace
.next
;
10390 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
10392 doc
: /* Read function name, then read its arguments and call it.
10394 To pass a numeric argument to the command you are invoking with, specify
10395 the numeric argument to this command.
10397 Noninteractively, the argument PREFIXARG is the prefix argument to
10398 give to the command you invoke, if it asks for an argument. */)
10400 Lisp_Object prefixarg
;
10402 Lisp_Object function
;
10404 int saved_last_point_position
;
10405 Lisp_Object saved_keys
, saved_last_point_position_buffer
;
10406 Lisp_Object bindings
, value
;
10407 struct gcpro gcpro1
, gcpro2
, gcpro3
;
10408 #ifdef HAVE_X_WINDOWS
10409 /* The call to Fcompleting_read wil start and cancel the hourglass,
10410 but if the hourglass was already scheduled, this means that no
10411 hourglass will be shown for the actual M-x command itself.
10412 So we restart it if it is already scheduled. Note that checking
10413 hourglass_shown_p is not enough, normally the hourglass is not shown,
10414 just scheduled to be shown. */
10415 int hstarted
= hourglass_started ();
10418 saved_keys
= Fvector (this_command_key_count
,
10419 XVECTOR (this_command_keys
)->contents
);
10420 saved_last_point_position_buffer
= last_point_position_buffer
;
10421 saved_last_point_position
= last_point_position
;
10423 GCPRO3 (saved_keys
, prefixarg
, saved_last_point_position_buffer
);
10425 if (EQ (prefixarg
, Qminus
))
10426 strcpy (buf
, "- ");
10427 else if (CONSP (prefixarg
) && XINT (XCAR (prefixarg
)) == 4)
10428 strcpy (buf
, "C-u ");
10429 else if (CONSP (prefixarg
) && INTEGERP (XCAR (prefixarg
)))
10430 sprintf (buf
, "%ld ", (long) XINT (XCAR (prefixarg
)));
10431 else if (INTEGERP (prefixarg
))
10432 sprintf (buf
, "%ld ", (long) XINT (prefixarg
));
10434 /* This isn't strictly correct if execute-extended-command
10435 is bound to anything else. Perhaps it should use
10436 this_command_keys? */
10437 strcat (buf
, "M-x ");
10439 /* Prompt with buf, and then read a string, completing from and
10440 restricting to the set of all defined commands. Don't provide
10441 any initial input. Save the command read on the extended-command
10443 function
= Fcompleting_read (build_string (buf
),
10444 Vobarray
, Qcommandp
,
10445 Qt
, Qnil
, Qextended_command_history
, Qnil
,
10448 #ifdef HAVE_X_WINDOWS
10449 if (hstarted
) start_hourglass ();
10452 if (STRINGP (function
) && SCHARS (function
) == 0)
10453 error ("No command name given");
10455 /* Set this_command_keys to the concatenation of saved_keys and
10456 function, followed by a RET. */
10461 this_command_key_count
= 0;
10462 this_command_key_count_reset
= 0;
10463 this_single_command_key_start
= 0;
10465 keys
= XVECTOR (saved_keys
)->contents
;
10466 for (i
= 0; i
< XVECTOR (saved_keys
)->size
; i
++)
10467 add_command_key (keys
[i
]);
10469 for (i
= 0; i
< SCHARS (function
); i
++)
10470 add_command_key (Faref (function
, make_number (i
)));
10472 add_command_key (make_number ('\015'));
10475 last_point_position
= saved_last_point_position
;
10476 last_point_position_buffer
= saved_last_point_position_buffer
;
10480 function
= Fintern (function
, Qnil
);
10481 current_kboard
->Vprefix_arg
= prefixarg
;
10482 Vthis_command
= function
;
10483 real_this_command
= function
;
10485 /* If enabled, show which key runs this command. */
10486 if (!NILP (Vsuggest_key_bindings
)
10487 && NILP (Vexecuting_kbd_macro
)
10488 && SYMBOLP (function
))
10489 bindings
= Fwhere_is_internal (function
, Voverriding_local_map
,
10495 GCPRO2 (bindings
, value
);
10496 value
= Fcommand_execute (function
, Qt
, Qnil
, Qnil
);
10498 /* If the command has a key binding, print it now. */
10499 if (!NILP (bindings
)
10500 && ! (VECTORP (bindings
) && EQ (Faref (bindings
, make_number (0)),
10503 /* But first wait, and skip the message if there is input. */
10504 Lisp_Object waited
;
10506 /* If this command displayed something in the echo area;
10507 wait a few seconds, then display our suggestion message. */
10508 if (NILP (echo_area_buffer
[0]))
10509 waited
= sit_for (make_number (0), 0, 2);
10510 else if (NUMBERP (Vsuggest_key_bindings
))
10511 waited
= sit_for (Vsuggest_key_bindings
, 0, 2);
10513 waited
= sit_for (make_number (2), 0, 2);
10515 if (!NILP (waited
) && ! CONSP (Vunread_command_events
))
10517 Lisp_Object binding
;
10519 int message_p
= push_message ();
10520 int count
= SPECPDL_INDEX ();
10522 record_unwind_protect (pop_message_unwind
, Qnil
);
10523 binding
= Fkey_description (bindings
, Qnil
);
10526 = (char *) alloca (SCHARS (SYMBOL_NAME (function
))
10529 sprintf (newmessage
, "You can run the command `%s' with %s",
10530 SDATA (SYMBOL_NAME (function
)),
10532 message2_nolog (newmessage
,
10533 strlen (newmessage
),
10534 STRING_MULTIBYTE (binding
));
10535 if (NUMBERP (Vsuggest_key_bindings
))
10536 waited
= sit_for (Vsuggest_key_bindings
, 0, 2);
10538 waited
= sit_for (make_number (2), 0, 2);
10540 if (!NILP (waited
) && message_p
)
10541 restore_message ();
10543 unbind_to (count
, Qnil
);
10547 RETURN_UNGCPRO (value
);
10551 /* Return nonzero if input events are pending. */
10554 detect_input_pending ()
10556 if (!input_pending
)
10557 get_input_pending (&input_pending
, 0);
10559 return input_pending
;
10562 /* Return nonzero if input events other than mouse movements are
10566 detect_input_pending_ignore_squeezables ()
10568 if (!input_pending
)
10569 get_input_pending (&input_pending
, READABLE_EVENTS_IGNORE_SQUEEZABLES
);
10571 return input_pending
;
10574 /* Return nonzero if input events are pending, and run any pending timers. */
10577 detect_input_pending_run_timers (do_display
)
10580 int old_timers_run
= timers_run
;
10582 if (!input_pending
)
10583 get_input_pending (&input_pending
, READABLE_EVENTS_DO_TIMERS_NOW
);
10585 if (old_timers_run
!= timers_run
&& do_display
)
10587 redisplay_preserve_echo_area (8);
10588 /* The following fixes a bug when using lazy-lock with
10589 lazy-lock-defer-on-the-fly set to t, i.e. when fontifying
10590 from an idle timer function. The symptom of the bug is that
10591 the cursor sometimes doesn't become visible until the next X
10592 event is processed. --gerd. */
10594 Lisp_Object tail
, frame
;
10595 FOR_EACH_FRAME (tail
, frame
)
10596 if (FRAME_RIF (XFRAME (frame
)))
10597 FRAME_RIF (XFRAME (frame
))->flush_display (XFRAME (frame
));
10601 return input_pending
;
10604 /* This is called in some cases before a possible quit.
10605 It cases the next call to detect_input_pending to recompute input_pending.
10606 So calling this function unnecessarily can't do any harm. */
10609 clear_input_pending ()
10614 /* Return nonzero if there are pending requeued events.
10615 This isn't used yet. The hope is to make wait_reading_process_output
10616 call it, and return if it runs Lisp code that unreads something.
10617 The problem is, kbd_buffer_get_event needs to be fixed to know what
10618 to do in that case. It isn't trivial. */
10621 requeued_events_pending_p ()
10623 return (!NILP (Vunread_command_events
) || unread_command_char
!= -1);
10627 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
10628 doc
: /* Return t if command input is currently available with no wait.
10629 Actually, the value is nil only if we can be sure that no input is available;
10630 if there is a doubt, the value is t. */)
10633 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1
10634 || !NILP (Vunread_post_input_method_events
)
10635 || !NILP (Vunread_input_method_events
))
10638 get_input_pending (&input_pending
,
10639 READABLE_EVENTS_DO_TIMERS_NOW
10640 | READABLE_EVENTS_FILTER_EVENTS
);
10641 return input_pending
> 0 ? Qt
: Qnil
;
10644 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
10645 doc
: /* Return vector of last 300 events, not counting those from keyboard macros. */)
10648 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
10651 if (total_keys
< NUM_RECENT_KEYS
)
10652 return Fvector (total_keys
, keys
);
10655 val
= Fvector (NUM_RECENT_KEYS
, keys
);
10656 bcopy (keys
+ recent_keys_index
,
10657 XVECTOR (val
)->contents
,
10658 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
10660 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
10661 recent_keys_index
* sizeof (Lisp_Object
));
10666 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
10667 doc
: /* Return the key sequence that invoked this command.
10668 However, if the command has called `read-key-sequence', it returns
10669 the last key sequence that has been read.
10670 The value is a string or a vector.
10672 See also `this-command-keys-vector'. */)
10675 return make_event_array (this_command_key_count
,
10676 XVECTOR (this_command_keys
)->contents
);
10679 DEFUN ("this-command-keys-vector", Fthis_command_keys_vector
, Sthis_command_keys_vector
, 0, 0, 0,
10680 doc
: /* Return the key sequence that invoked this command, as a vector.
10681 However, if the command has called `read-key-sequence', it returns
10682 the last key sequence that has been read.
10684 See also `this-command-keys'. */)
10687 return Fvector (this_command_key_count
,
10688 XVECTOR (this_command_keys
)->contents
);
10691 DEFUN ("this-single-command-keys", Fthis_single_command_keys
,
10692 Sthis_single_command_keys
, 0, 0, 0,
10693 doc
: /* Return the key sequence that invoked this command.
10694 More generally, it returns the last key sequence read, either by
10695 the command loop or by `read-key-sequence'.
10696 Unlike `this-command-keys', this function's value
10697 does not include prefix arguments.
10698 The value is always a vector. */)
10701 return Fvector (this_command_key_count
10702 - this_single_command_key_start
,
10703 (XVECTOR (this_command_keys
)->contents
10704 + this_single_command_key_start
));
10707 DEFUN ("this-single-command-raw-keys", Fthis_single_command_raw_keys
,
10708 Sthis_single_command_raw_keys
, 0, 0, 0,
10709 doc
: /* Return the raw events that were read for this command.
10710 More generally, it returns the last key sequence read, either by
10711 the command loop or by `read-key-sequence'.
10712 Unlike `this-single-command-keys', this function's value
10713 shows the events before all translations (except for input methods).
10714 The value is always a vector. */)
10717 return Fvector (raw_keybuf_count
,
10718 (XVECTOR (raw_keybuf
)->contents
));
10721 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths
,
10722 Sreset_this_command_lengths
, 0, 0, 0,
10723 doc
: /* Make the unread events replace the last command and echo.
10724 Used in `universal-argument-other-key'.
10726 `universal-argument-other-key' rereads the event just typed.
10727 It then gets translated through `function-key-map'.
10728 The translated event has to replace the real events,
10729 both in the value of (this-command-keys) and in echoing.
10730 To achieve this, `universal-argument-other-key' calls
10731 `reset-this-command-lengths', which discards the record of reading
10732 these events the first time. */)
10735 this_command_key_count
= before_command_key_count
;
10736 if (this_command_key_count
< this_single_command_key_start
)
10737 this_single_command_key_start
= this_command_key_count
;
10739 echo_truncate (before_command_echo_length
);
10741 /* Cause whatever we put into unread-command-events
10742 to echo as if it were being freshly read from the keyboard. */
10743 this_command_key_count_reset
= 1;
10748 DEFUN ("clear-this-command-keys", Fclear_this_command_keys
,
10749 Sclear_this_command_keys
, 0, 1, 0,
10750 doc
: /* Clear out the vector that `this-command-keys' returns.
10751 Also clear the record of the last 100 events, unless optional arg
10752 KEEP-RECORD is non-nil. */)
10754 Lisp_Object keep_record
;
10758 this_command_key_count
= 0;
10759 this_command_key_count_reset
= 0;
10761 if (NILP (keep_record
))
10763 for (i
= 0; i
< XVECTOR (recent_keys
)->size
; ++i
)
10764 XVECTOR (recent_keys
)->contents
[i
] = Qnil
;
10766 recent_keys_index
= 0;
10771 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
10772 doc
: /* Return the current depth in recursive edits. */)
10776 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
10780 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
10781 "FOpen dribble file: ",
10782 doc
: /* Start writing all keyboard characters to a dribble file called FILE.
10783 If FILE is nil, close any open dribble file. */)
10796 file
= Fexpand_file_name (file
, Qnil
);
10797 dribble
= fopen (SDATA (file
), "w");
10799 report_file_error ("Opening dribble", Fcons (file
, Qnil
));
10804 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
10805 doc
: /* Discard the contents of the terminal input buffer.
10806 Also end any kbd macro being defined. */)
10809 if (!NILP (current_kboard
->defining_kbd_macro
))
10811 /* Discard the last command from the macro. */
10812 Fcancel_kbd_macro_events ();
10816 update_mode_lines
++;
10818 Vunread_command_events
= Qnil
;
10819 unread_command_char
= -1;
10821 discard_tty_input ();
10823 kbd_fetch_ptr
= kbd_store_ptr
;
10829 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
10830 doc
: /* Stop Emacs and return to superior process. You can resume later.
10831 If `cannot-suspend' is non-nil, or if the system doesn't support job
10832 control, run a subshell instead.
10834 If optional arg STUFFSTRING is non-nil, its characters are stuffed
10835 to be read as terminal input by Emacs's parent, after suspension.
10837 Before suspending, run the normal hook `suspend-hook'.
10838 After resumption run the normal hook `suspend-resume-hook'.
10840 Some operating systems cannot stop the Emacs process and resume it later.
10841 On such systems, Emacs starts a subshell instead of suspending. */)
10843 Lisp_Object stuffstring
;
10845 int count
= SPECPDL_INDEX ();
10846 int old_height
, old_width
;
10848 struct gcpro gcpro1
;
10850 if (tty_list
&& tty_list
->next
)
10851 error ("There are other tty frames open; close them before suspending Emacs");
10853 if (!NILP (stuffstring
))
10854 CHECK_STRING (stuffstring
);
10856 /* Run the functions in suspend-hook. */
10857 if (!NILP (Vrun_hooks
))
10858 call1 (Vrun_hooks
, intern ("suspend-hook"));
10860 GCPRO1 (stuffstring
);
10861 get_tty_size (fileno (CURTTY ()->input
), &old_width
, &old_height
);
10862 reset_all_sys_modes ();
10863 /* sys_suspend can get an error if it tries to fork a subshell
10864 and the system resources aren't available for that. */
10865 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object
))) init_all_sys_modes
,
10867 stuff_buffered_input (stuffstring
);
10868 if (cannot_suspend
)
10872 unbind_to (count
, Qnil
);
10874 /* Check if terminal/window size has changed.
10875 Note that this is not useful when we are running directly
10876 with a window system; but suspend should be disabled in that case. */
10877 get_tty_size (fileno (CURTTY ()->input
), &width
, &height
);
10878 if (width
!= old_width
|| height
!= old_height
)
10879 change_frame_size (SELECTED_FRAME (), height
, width
, 0, 0, 0);
10881 /* Run suspend-resume-hook. */
10882 if (!NILP (Vrun_hooks
))
10883 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
10889 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
10890 Then in any case stuff anything Emacs has read ahead and not used. */
10893 stuff_buffered_input (stuffstring
)
10894 Lisp_Object stuffstring
;
10896 #ifdef SIGTSTP /* stuff_char is defined if SIGTSTP. */
10897 register unsigned char *p
;
10899 if (STRINGP (stuffstring
))
10901 register int count
;
10903 p
= SDATA (stuffstring
);
10904 count
= SBYTES (stuffstring
);
10905 while (count
-- > 0)
10910 /* Anything we have read ahead, put back for the shell to read. */
10911 /* ?? What should this do when we have multiple keyboards??
10912 Should we ignore anything that was typed in at the "wrong" kboard?
10914 rms: we should stuff everything back into the kboard
10916 for (; kbd_fetch_ptr
!= kbd_store_ptr
; kbd_fetch_ptr
++)
10919 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
10920 kbd_fetch_ptr
= kbd_buffer
;
10921 if (kbd_fetch_ptr
->kind
== ASCII_KEYSTROKE_EVENT
)
10922 stuff_char (kbd_fetch_ptr
->code
);
10924 clear_event (kbd_fetch_ptr
);
10928 #endif /* SIGTSTP */
10932 set_waiting_for_input (time_to_clear
)
10933 EMACS_TIME
*time_to_clear
;
10935 input_available_clear_time
= time_to_clear
;
10937 /* Tell handle_interrupt to throw back to read_char, */
10938 waiting_for_input
= 1;
10940 /* If handle_interrupt was called before and buffered a C-g,
10941 make it run again now, to avoid timing error. */
10942 if (!NILP (Vquit_flag
))
10943 quit_throw_to_read_char ();
10947 clear_waiting_for_input ()
10949 /* Tell handle_interrupt not to throw back to read_char, */
10950 waiting_for_input
= 0;
10951 input_available_clear_time
= 0;
10954 /* The SIGINT handler.
10956 If we have a frame on the controlling tty, we assume that the
10957 SIGINT was generated by C-g, so we call handle_interrupt.
10958 Otherwise, the handler kills Emacs. */
10961 interrupt_signal (signalnum
) /* If we don't have an argument, */
10962 int signalnum
; /* some compilers complain in signal calls. */
10964 /* Must preserve main program's value of errno. */
10965 int old_errno
= errno
;
10966 struct terminal
*terminal
;
10968 #if defined (USG) && !defined (POSIX_SIGNALS)
10969 /* USG systems forget handlers when they are used;
10970 must reestablish each time */
10971 signal (SIGINT
, interrupt_signal
);
10972 signal (SIGQUIT
, interrupt_signal
);
10975 SIGNAL_THREAD_CHECK (signalnum
);
10977 /* See if we have an active terminal on our controlling tty. */
10978 terminal
= get_named_tty ("/dev/tty");
10981 /* If there are no frames there, let's pretend that we are a
10982 well-behaving UN*X program and quit. */
10983 Fkill_emacs (Qnil
);
10987 /* Otherwise, the SIGINT was probably generated by C-g. */
10989 /* Set internal_last_event_frame to the top frame of the
10990 controlling tty, if we have a frame there. We disable the
10991 interrupt key on secondary ttys, so the SIGINT must have come
10992 from the controlling tty. */
10993 internal_last_event_frame
= terminal
->display_info
.tty
->top_frame
;
10995 handle_interrupt ();
11001 /* This routine is called at interrupt level in response to C-g.
11003 It is called from the SIGINT handler or kbd_buffer_store_event.
11005 If `waiting_for_input' is non zero, then unless `echoing' is
11006 nonzero, immediately throw back to read_char.
11008 Otherwise it sets the Lisp variable quit-flag not-nil. This causes
11009 eval to throw, when it gets a chance. If quit-flag is already
11010 non-nil, it stops the job right away. */
11013 handle_interrupt ()
11019 /* XXX This code needs to be revised for multi-tty support. */
11020 if (!NILP (Vquit_flag
)
11022 && get_named_tty ("/dev/tty")
11026 /* If SIGINT isn't blocked, don't let us be interrupted by
11027 another SIGINT, it might be harmful due to non-reentrancy
11028 in I/O functions. */
11029 sigblock (sigmask (SIGINT
));
11032 reset_all_sys_modes ();
11034 #ifdef SIGTSTP /* Support possible in later USG versions */
11036 * On systems which can suspend the current process and return to the original
11037 * shell, this command causes the user to end up back at the shell.
11038 * The "Auto-save" and "Abort" questions are not asked until
11039 * the user elects to return to emacs, at which point he can save the current
11040 * job and either dump core or continue.
11045 if (sys_suspend () == -1)
11047 printf ("Not running as a subprocess;\n");
11048 printf ("you can continue or abort.\n");
11050 #else /* not VMS */
11051 /* Perhaps should really fork an inferior shell?
11052 But that would not provide any way to get back
11053 to the original shell, ever. */
11054 printf ("No support for stopping a process on this operating system;\n");
11055 printf ("you can continue or abort.\n");
11056 #endif /* not VMS */
11057 #endif /* not SIGTSTP */
11059 /* We must remain inside the screen area when the internal terminal
11060 is used. Note that [Enter] is not echoed by dos. */
11063 /* It doesn't work to autosave while GC is in progress;
11064 the code used for auto-saving doesn't cope with the mark bit. */
11065 if (!gc_in_progress
)
11067 printf ("Auto-save? (y or n) ");
11069 if (((c
= getchar ()) & ~040) == 'Y')
11071 Fdo_auto_save (Qt
, Qnil
);
11073 printf ("\r\nAuto-save done");
11074 #else /* not MSDOS */
11075 printf ("Auto-save done\n");
11076 #endif /* not MSDOS */
11078 while (c
!= '\n') c
= getchar ();
11082 /* During GC, it must be safe to reenable quitting again. */
11083 Vinhibit_quit
= Qnil
;
11086 #endif /* not MSDOS */
11087 printf ("Garbage collection in progress; cannot auto-save now\r\n");
11088 printf ("but will instead do a real quit after garbage collection ends\r\n");
11093 printf ("\r\nAbort? (y or n) ");
11094 #else /* not MSDOS */
11096 printf ("Abort (and enter debugger)? (y or n) ");
11097 #else /* not VMS */
11098 printf ("Abort (and dump core)? (y or n) ");
11099 #endif /* not VMS */
11100 #endif /* not MSDOS */
11102 if (((c
= getchar ()) & ~040) == 'Y')
11104 while (c
!= '\n') c
= getchar ();
11106 printf ("\r\nContinuing...\r\n");
11107 #else /* not MSDOS */
11108 printf ("Continuing...\n");
11109 #endif /* not MSDOS */
11111 init_all_sys_modes ();
11116 /* If executing a function that wants to be interrupted out of
11117 and the user has not deferred quitting by binding `inhibit-quit'
11118 then quit right away. */
11119 if (immediate_quit
&& NILP (Vinhibit_quit
))
11121 struct gl_state_s saved
;
11122 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
11124 immediate_quit
= 0;
11127 GCPRO4 (saved
.object
, saved
.global_code
,
11128 saved
.current_syntax_table
, saved
.old_prop
);
11129 Fsignal (Qquit
, Qnil
);
11134 /* Else request quit when it's safe */
11138 if (waiting_for_input
&& !echoing
)
11139 quit_throw_to_read_char ();
11142 /* Handle a C-g by making read_char return C-g. */
11145 quit_throw_to_read_char ()
11148 /* Prevent another signal from doing this before we finish. */
11149 clear_waiting_for_input ();
11152 Vunread_command_events
= Qnil
;
11153 unread_command_char
= -1;
11155 #if 0 /* Currently, sit_for is called from read_char without turning
11156 off polling. And that can call set_waiting_for_input.
11157 It seems to be harmless. */
11158 #ifdef POLL_FOR_INPUT
11159 /* May be > 1 if in recursive minibuffer. */
11160 if (poll_suppress_count
== 0)
11164 if (FRAMEP (internal_last_event_frame
)
11165 && !EQ (internal_last_event_frame
, selected_frame
))
11166 do_switch_frame (make_lispy_switch_frame (internal_last_event_frame
),
11169 _longjmp (getcjmp
, 1);
11172 DEFUN ("set-input-interrupt-mode", Fset_input_interrupt_mode
, Sset_input_interrupt_mode
, 1, 1, 0,
11173 doc
: /* Set interrupt mode of reading keyboard input.
11174 If INTERRUPT is non-nil, Emacs will use input interrupts;
11175 otherwise Emacs uses CBREAK mode.
11177 See also `current-input-mode'. */)
11179 Lisp_Object interrupt
;
11181 int new_interrupt_input
;
11183 /* Note SIGIO has been undef'd if FIONREAD is missing. */
11184 #ifdef HAVE_X_WINDOWS
11185 if (x_display_list
!= NULL
)
11187 /* When using X, don't give the user a real choice,
11188 because we haven't implemented the mechanisms to support it. */
11189 #ifdef NO_SOCK_SIGIO
11190 new_interrupt_input
= 0;
11191 #else /* not NO_SOCK_SIGIO */
11192 new_interrupt_input
= 1;
11193 #endif /* NO_SOCK_SIGIO */
11197 new_interrupt_input
= !NILP (interrupt
);
11198 #else /* not SIGIO */
11199 new_interrupt_input
= 0;
11200 #endif /* not SIGIO */
11202 /* Our VMS input only works by interrupts, as of now. */
11204 new_interrupt_input
= 1;
11207 if (new_interrupt_input
!= interrupt_input
)
11209 #ifdef POLL_FOR_INPUT
11213 /* this causes startup screen to be restored and messes with the mouse */
11214 reset_all_sys_modes ();
11216 interrupt_input
= new_interrupt_input
;
11218 init_all_sys_modes ();
11221 #ifdef POLL_FOR_INPUT
11222 poll_suppress_count
= 1;
11229 DEFUN ("set-output-flow-control", Fset_output_flow_control
, Sset_output_flow_control
, 1, 2, 0,
11230 doc
: /* Enable or disable ^S/^Q flow control for output to TERMINAL.
11231 If FLOW is non-nil, flow control is enabled and you cannot use C-s or
11232 C-q in key sequences.
11234 This setting only has an effect on tty terminals and only when
11235 Emacs reads input in CBREAK mode; see `set-input-interrupt-mode'.
11237 See also `current-input-mode'. */)
11239 Lisp_Object flow
, terminal
;
11241 struct terminal
*t
= get_terminal (terminal
, 1);
11242 struct tty_display_info
*tty
;
11243 if (t
== NULL
|| t
->type
!= output_termcap
)
11245 tty
= t
->display_info
.tty
;
11247 if (tty
->flow_control
!= !NILP (flow
))
11250 /* this causes startup screen to be restored and messes with the mouse */
11251 reset_sys_modes (tty
);
11254 tty
->flow_control
= !NILP (flow
);
11257 init_sys_modes (tty
);
11263 DEFUN ("set-input-meta-mode", Fset_input_meta_mode
, Sset_input_meta_mode
, 1, 2, 0,
11264 doc
: /* Enable or disable 8-bit input on TERMINAL.
11265 If META is t, Emacs will accept 8-bit input, and interpret the 8th
11266 bit as the Meta modifier.
11268 If META is nil, Emacs will ignore the top bit, on the assumption it is
11271 Otherwise, Emacs will accept and pass through 8-bit input without
11272 specially interpreting the top bit.
11274 This setting only has an effect on tty terminal devices.
11276 Optional parameter TERMINAL specifies the tty terminal device to use.
11277 It may be a terminal id, a frame, or nil for the terminal used by the
11278 currently selected frame.
11280 See also `current-input-mode'. */)
11282 Lisp_Object meta
, terminal
;
11284 struct terminal
*t
= get_terminal (terminal
, 1);
11285 struct tty_display_info
*tty
;
11288 if (t
== NULL
|| t
->type
!= output_termcap
)
11290 tty
= t
->display_info
.tty
;
11294 else if (EQ (meta
, Qt
))
11299 if (tty
->meta_key
!= new_meta
)
11302 /* this causes startup screen to be restored and messes with the mouse */
11303 reset_sys_modes (tty
);
11306 tty
->meta_key
= new_meta
;
11309 init_sys_modes (tty
);
11315 DEFUN ("set-quit-char", Fset_quit_char
, Sset_quit_char
, 1, 1, 0,
11316 doc
: /* Specify character used for quitting.
11317 QUIT must be an ASCII character.
11319 This function only has an effect on the controlling tty of the Emacs
11322 See also `current-input-mode'. */)
11326 struct terminal
*t
= get_named_tty ("/dev/tty");
11327 struct tty_display_info
*tty
;
11328 if (t
== NULL
|| t
->type
!= output_termcap
)
11330 tty
= t
->display_info
.tty
;
11332 if (NILP (quit
) || !INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400)
11333 error ("QUIT must be an ASCII character");
11336 /* this causes startup screen to be restored and messes with the mouse */
11337 reset_sys_modes (tty
);
11340 /* Don't let this value be out of range. */
11341 quit_char
= XINT (quit
) & (tty
->meta_key
== 0 ? 0177 : 0377);
11344 init_sys_modes (tty
);
11350 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
11351 doc
: /* Set mode of reading keyboard input.
11352 First arg INTERRUPT non-nil means use input interrupts;
11353 nil means use CBREAK mode.
11354 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal
11355 (no effect except in CBREAK mode).
11356 Third arg META t means accept 8-bit input (for a Meta key).
11357 META nil means ignore the top bit, on the assumption it is parity.
11358 Otherwise, accept 8-bit input and don't use the top bit for Meta.
11359 Optional fourth arg QUIT if non-nil specifies character to use for quitting.
11360 See also `current-input-mode'. */)
11361 (interrupt
, flow
, meta
, quit
)
11362 Lisp_Object interrupt
, flow
, meta
, quit
;
11364 Fset_input_interrupt_mode (interrupt
);
11365 Fset_output_flow_control (flow
, Qnil
);
11366 Fset_input_meta_mode (meta
, Qnil
);
11368 Fset_quit_char (quit
);
11372 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
11373 doc
: /* Return information about the way Emacs currently reads keyboard input.
11374 The value is a list of the form (INTERRUPT FLOW META QUIT), where
11375 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if
11376 nil, Emacs is using CBREAK mode.
11377 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the
11378 terminal; this does not apply if Emacs uses interrupt-driven input.
11379 META is t if accepting 8-bit input with 8th bit as Meta flag.
11380 META nil means ignoring the top bit, on the assumption it is parity.
11381 META is neither t nor nil if accepting 8-bit input and using
11382 all 8 bits as the character code.
11383 QUIT is the character Emacs currently uses to quit.
11384 The elements of this list correspond to the arguments of
11385 `set-input-mode'. */)
11388 Lisp_Object val
[4];
11389 struct frame
*sf
= XFRAME (selected_frame
);
11391 val
[0] = interrupt_input
? Qt
: Qnil
;
11392 if (FRAME_TERMCAP_P (sf
))
11394 val
[1] = FRAME_TTY (sf
)->flow_control
? Qt
: Qnil
;
11395 val
[2] = (FRAME_TTY (sf
)->meta_key
== 2
11397 : (CURTTY ()->meta_key
== 1 ? Qt
: Qnil
));
11404 XSETFASTINT (val
[3], quit_char
);
11406 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
11409 DEFUN ("posn-at-x-y", Fposn_at_x_y
, Sposn_at_x_y
, 2, 4, 0,
11410 doc
: /* Return position information for pixel coordinates X and Y.
11411 By default, X and Y are relative to text area of the selected window.
11412 Optional third arg FRAME-OR-WINDOW non-nil specifies frame or window.
11413 If optional fourth arg WHOLE is non-nil, X is relative to the left
11414 edge of the window.
11416 The return value is similar to a mouse click position:
11417 (WINDOW AREA-OR-POS (X . Y) TIMESTAMP OBJECT POS (COL . ROW)
11418 IMAGE (DX . DY) (WIDTH . HEIGHT))
11419 The `posn-' functions access elements of such lists. */)
11420 (x
, y
, frame_or_window
, whole
)
11421 Lisp_Object x
, y
, frame_or_window
, whole
;
11426 if (NILP (frame_or_window
))
11427 frame_or_window
= selected_window
;
11429 if (WINDOWP (frame_or_window
))
11433 CHECK_LIVE_WINDOW (frame_or_window
);
11435 w
= XWINDOW (frame_or_window
);
11436 XSETINT (x
, (XINT (x
)
11437 + WINDOW_LEFT_EDGE_X (w
)
11439 ? window_box_left_offset (w
, TEXT_AREA
)
11441 XSETINT (y
, WINDOW_TO_FRAME_PIXEL_Y (w
, XINT (y
)));
11442 frame_or_window
= w
->frame
;
11445 CHECK_LIVE_FRAME (frame_or_window
);
11447 return make_lispy_position (XFRAME (frame_or_window
), &x
, &y
, 0);
11450 DEFUN ("posn-at-point", Fposn_at_point
, Sposn_at_point
, 0, 2, 0,
11451 doc
: /* Return position information for buffer POS in WINDOW.
11452 POS defaults to point in WINDOW; WINDOW defaults to the selected window.
11454 Return nil if position is not visible in window. Otherwise,
11455 the return value is similar to that returned by `event-start' for
11456 a mouse click at the upper left corner of the glyph corresponding
11457 to the given buffer position:
11458 (WINDOW AREA-OR-POS (X . Y) TIMESTAMP OBJECT POS (COL . ROW)
11459 IMAGE (DX . DY) (WIDTH . HEIGHT))
11460 The `posn-' functions access elements of such lists. */)
11462 Lisp_Object pos
, window
;
11467 window
= selected_window
;
11469 tem
= Fpos_visible_in_window_p (pos
, window
, Qt
);
11472 Lisp_Object x
= XCAR (tem
);
11473 Lisp_Object y
= XCAR (XCDR (tem
));
11475 /* Point invisible due to hscrolling? */
11478 tem
= Fposn_at_x_y (x
, y
, window
, Qnil
);
11486 * Set up a new kboard object with reasonable initial values.
11492 kb
->Voverriding_terminal_local_map
= Qnil
;
11493 kb
->Vlast_command
= Qnil
;
11494 kb
->Vreal_last_command
= Qnil
;
11495 kb
->Vkeyboard_translate_table
= Qnil
;
11496 kb
->Vlast_repeatable_command
= Qnil
;
11497 kb
->Vprefix_arg
= Qnil
;
11498 kb
->Vlast_prefix_arg
= Qnil
;
11499 kb
->kbd_queue
= Qnil
;
11500 kb
->kbd_queue_has_data
= 0;
11501 kb
->immediate_echo
= 0;
11502 kb
->echo_string
= Qnil
;
11503 kb
->echo_after_prompt
= -1;
11504 kb
->kbd_macro_buffer
= 0;
11505 kb
->kbd_macro_bufsize
= 0;
11506 kb
->defining_kbd_macro
= Qnil
;
11507 kb
->Vlast_kbd_macro
= Qnil
;
11508 kb
->reference_count
= 0;
11509 kb
->Vsystem_key_alist
= Qnil
;
11510 kb
->system_key_syms
= Qnil
;
11511 kb
->Vinput_decode_map
= Fmake_sparse_keymap (Qnil
);
11512 kb
->Vlocal_function_key_map
= Fmake_sparse_keymap (Qnil
);
11513 Fset_keymap_parent (kb
->Vlocal_function_key_map
, Vfunction_key_map
);
11514 kb
->Vdefault_minibuffer_frame
= Qnil
;
11518 * Destroy the contents of a kboard object, but not the object itself.
11519 * We use this just before deleting it, or if we're going to initialize
11520 * it a second time.
11526 if (kb
->kbd_macro_buffer
)
11527 xfree (kb
->kbd_macro_buffer
);
11530 #ifdef MULTI_KBOARD
11532 /* Free KB and memory referenced from it. */
11540 for (kbp
= &all_kboards
; *kbp
!= kb
; kbp
= &(*kbp
)->next_kboard
)
11543 *kbp
= kb
->next_kboard
;
11545 /* Prevent a dangling reference to KB. */
11546 if (kb
== current_kboard
11547 && FRAMEP (selected_frame
)
11548 && FRAME_LIVE_P (XFRAME (selected_frame
)))
11550 current_kboard
= FRAME_KBOARD (XFRAME (selected_frame
));
11552 if (current_kboard
== kb
)
11560 #endif /* MULTI_KBOARD */
11565 /* This is correct before outermost invocation of the editor loop */
11566 command_loop_level
= -1;
11567 immediate_quit
= 0;
11568 quit_char
= Ctl ('g');
11569 Vunread_command_events
= Qnil
;
11570 unread_command_char
= -1;
11571 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
11573 recent_keys_index
= 0;
11574 kbd_fetch_ptr
= kbd_buffer
;
11575 kbd_store_ptr
= kbd_buffer
;
11576 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
11577 do_mouse_tracking
= Qnil
;
11580 interrupt_input_blocked
= 0;
11581 interrupt_input_pending
= 0;
11583 /* This means that command_loop_1 won't try to select anything the first
11585 internal_last_event_frame
= Qnil
;
11586 Vlast_event_frame
= internal_last_event_frame
;
11588 #ifdef MULTI_KBOARD
11589 current_kboard
= initial_kboard
;
11591 wipe_kboard (current_kboard
);
11592 init_kboard (current_kboard
);
11594 if (!noninteractive
)
11596 /* Before multi-tty support, these handlers used to be installed
11597 only if the current session was a tty session. Now an Emacs
11598 session may have multiple display types, so we always handle
11599 SIGINT. There is special code in interrupt_signal to exit
11600 Emacs on SIGINT when there are no termcap frames on the
11601 controlling terminal. */
11602 signal (SIGINT
, interrupt_signal
);
11603 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
11604 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
11605 SIGQUIT and we can't tell which one it will give us. */
11606 signal (SIGQUIT
, interrupt_signal
);
11607 #endif /* HAVE_TERMIO */
11609 /* Note SIGIO has been undef'd if FIONREAD is missing. */
11611 if (!noninteractive
)
11612 signal (SIGIO
, input_available_signal
);
11615 /* Use interrupt input by default, if it works and noninterrupt input
11616 has deficiencies. */
11618 #ifdef INTERRUPT_INPUT
11619 interrupt_input
= 1;
11621 interrupt_input
= 0;
11624 /* Our VMS input only works by interrupts, as of now. */
11626 interrupt_input
= 1;
11632 if (keyboard_init_hook
)
11633 (*keyboard_init_hook
) ();
11635 #ifdef POLL_FOR_INPUT
11636 poll_suppress_count
= 1;
11641 /* This type's only use is in syms_of_keyboard, to initialize the
11642 event header symbols and put properties on them. */
11643 struct event_head
{
11649 struct event_head head_table
[] = {
11650 {&Qmouse_movement
, "mouse-movement", &Qmouse_movement
},
11651 {&Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
},
11652 {&Qswitch_frame
, "switch-frame", &Qswitch_frame
},
11653 {&Qdelete_frame
, "delete-frame", &Qdelete_frame
},
11654 {&Qiconify_frame
, "iconify-frame", &Qiconify_frame
},
11655 {&Qmake_frame_visible
, "make-frame-visible", &Qmake_frame_visible
},
11656 /* `select-window' should be handled just like `switch-frame'
11657 in read_key_sequence. */
11658 {&Qselect_window
, "select-window", &Qswitch_frame
}
11662 syms_of_keyboard ()
11664 Vpre_help_message
= Qnil
;
11665 staticpro (&Vpre_help_message
);
11667 Vlispy_mouse_stem
= build_string ("mouse");
11668 staticpro (&Vlispy_mouse_stem
);
11671 QCimage
= intern (":image");
11672 staticpro (&QCimage
);
11674 staticpro (&Qhelp_echo
);
11675 Qhelp_echo
= intern ("help-echo");
11678 Qrtl
= intern (":rtl");
11680 staticpro (&item_properties
);
11681 item_properties
= Qnil
;
11683 staticpro (&tool_bar_item_properties
);
11684 tool_bar_item_properties
= Qnil
;
11685 staticpro (&tool_bar_items_vector
);
11686 tool_bar_items_vector
= Qnil
;
11688 staticpro (&real_this_command
);
11689 real_this_command
= Qnil
;
11691 Qtimer_event_handler
= intern ("timer-event-handler");
11692 staticpro (&Qtimer_event_handler
);
11694 Qdisabled_command_function
= intern ("disabled-command-function");
11695 staticpro (&Qdisabled_command_function
);
11697 Qself_insert_command
= intern ("self-insert-command");
11698 staticpro (&Qself_insert_command
);
11700 Qforward_char
= intern ("forward-char");
11701 staticpro (&Qforward_char
);
11703 Qbackward_char
= intern ("backward-char");
11704 staticpro (&Qbackward_char
);
11706 Qdisabled
= intern ("disabled");
11707 staticpro (&Qdisabled
);
11709 Qundefined
= intern ("undefined");
11710 staticpro (&Qundefined
);
11712 Qpre_command_hook
= intern ("pre-command-hook");
11713 staticpro (&Qpre_command_hook
);
11715 Qpost_command_hook
= intern ("post-command-hook");
11716 staticpro (&Qpost_command_hook
);
11718 Qdeferred_action_function
= intern ("deferred-action-function");
11719 staticpro (&Qdeferred_action_function
);
11721 Qcommand_hook_internal
= intern ("command-hook-internal");
11722 staticpro (&Qcommand_hook_internal
);
11724 Qfunction_key
= intern ("function-key");
11725 staticpro (&Qfunction_key
);
11726 Qmouse_click
= intern ("mouse-click");
11727 staticpro (&Qmouse_click
);
11728 #if defined (WINDOWSNT) || defined (MAC_OS)
11729 Qlanguage_change
= intern ("language-change");
11730 staticpro (&Qlanguage_change
);
11732 Qdrag_n_drop
= intern ("drag-n-drop");
11733 staticpro (&Qdrag_n_drop
);
11735 Qsave_session
= intern ("save-session");
11736 staticpro (&Qsave_session
);
11739 Qmac_apple_event
= intern ("mac-apple-event");
11740 staticpro (&Qmac_apple_event
);
11743 Qmenu_enable
= intern ("menu-enable");
11744 staticpro (&Qmenu_enable
);
11745 Qmenu_alias
= intern ("menu-alias");
11746 staticpro (&Qmenu_alias
);
11747 QCenable
= intern (":enable");
11748 staticpro (&QCenable
);
11749 QCvisible
= intern (":visible");
11750 staticpro (&QCvisible
);
11751 QChelp
= intern (":help");
11752 staticpro (&QChelp
);
11753 QCfilter
= intern (":filter");
11754 staticpro (&QCfilter
);
11755 QCbutton
= intern (":button");
11756 staticpro (&QCbutton
);
11757 QCkeys
= intern (":keys");
11758 staticpro (&QCkeys
);
11759 QCkey_sequence
= intern (":key-sequence");
11760 staticpro (&QCkey_sequence
);
11761 QCtoggle
= intern (":toggle");
11762 staticpro (&QCtoggle
);
11763 QCradio
= intern (":radio");
11764 staticpro (&QCradio
);
11766 Qmode_line
= intern ("mode-line");
11767 staticpro (&Qmode_line
);
11768 Qvertical_line
= intern ("vertical-line");
11769 staticpro (&Qvertical_line
);
11770 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
11771 staticpro (&Qvertical_scroll_bar
);
11772 Qmenu_bar
= intern ("menu-bar");
11773 staticpro (&Qmenu_bar
);
11775 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
11776 Qmouse_fixup_help_message
= intern ("mouse-fixup-help-message");
11777 staticpro (&Qmouse_fixup_help_message
);
11780 Qabove_handle
= intern ("above-handle");
11781 staticpro (&Qabove_handle
);
11782 Qhandle
= intern ("handle");
11783 staticpro (&Qhandle
);
11784 Qbelow_handle
= intern ("below-handle");
11785 staticpro (&Qbelow_handle
);
11786 Qup
= intern ("up");
11788 Qdown
= intern ("down");
11789 staticpro (&Qdown
);
11790 Qtop
= intern ("top");
11792 Qbottom
= intern ("bottom");
11793 staticpro (&Qbottom
);
11794 Qend_scroll
= intern ("end-scroll");
11795 staticpro (&Qend_scroll
);
11796 Qratio
= intern ("ratio");
11797 staticpro (&Qratio
);
11799 Qevent_kind
= intern ("event-kind");
11800 staticpro (&Qevent_kind
);
11801 Qevent_symbol_elements
= intern ("event-symbol-elements");
11802 staticpro (&Qevent_symbol_elements
);
11803 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
11804 staticpro (&Qevent_symbol_element_mask
);
11805 Qmodifier_cache
= intern ("modifier-cache");
11806 staticpro (&Qmodifier_cache
);
11808 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
11809 staticpro (&Qrecompute_lucid_menubar
);
11810 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
11811 staticpro (&Qactivate_menubar_hook
);
11813 Qpolling_period
= intern ("polling-period");
11814 staticpro (&Qpolling_period
);
11816 Qinput_method_function
= intern ("input-method-function");
11817 staticpro (&Qinput_method_function
);
11819 Qinput_method_exit_on_first_char
= intern ("input-method-exit-on-first-char");
11820 staticpro (&Qinput_method_exit_on_first_char
);
11821 Qinput_method_use_echo_area
= intern ("input-method-use-echo-area");
11822 staticpro (&Qinput_method_use_echo_area
);
11824 Fset (Qinput_method_exit_on_first_char
, Qnil
);
11825 Fset (Qinput_method_use_echo_area
, Qnil
);
11827 last_point_position_buffer
= Qnil
;
11828 last_point_position_window
= Qnil
;
11831 struct event_head
*p
;
11833 for (p
= head_table
;
11834 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
11837 *p
->var
= intern (p
->name
);
11838 staticpro (p
->var
);
11839 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
11840 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
11844 button_down_location
= Fmake_vector (make_number (1), Qnil
);
11845 staticpro (&button_down_location
);
11846 mouse_syms
= Fmake_vector (make_number (1), Qnil
);
11847 staticpro (&mouse_syms
);
11848 wheel_syms
= Fmake_vector (make_number (4), Qnil
);
11849 staticpro (&wheel_syms
);
11853 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
11855 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
11856 for (i
= 0; i
< len
; i
++)
11857 if (modifier_names
[i
])
11858 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
11859 staticpro (&modifier_symbols
);
11862 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
11863 staticpro (&recent_keys
);
11865 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
11866 staticpro (&this_command_keys
);
11868 raw_keybuf
= Fmake_vector (make_number (30), Qnil
);
11869 staticpro (&raw_keybuf
);
11871 Qextended_command_history
= intern ("extended-command-history");
11872 Fset (Qextended_command_history
, Qnil
);
11873 staticpro (&Qextended_command_history
);
11875 accent_key_syms
= Qnil
;
11876 staticpro (&accent_key_syms
);
11878 func_key_syms
= Qnil
;
11879 staticpro (&func_key_syms
);
11881 drag_n_drop_syms
= Qnil
;
11882 staticpro (&drag_n_drop_syms
);
11884 unread_switch_frame
= Qnil
;
11885 staticpro (&unread_switch_frame
);
11887 internal_last_event_frame
= Qnil
;
11888 staticpro (&internal_last_event_frame
);
11890 read_key_sequence_cmd
= Qnil
;
11891 staticpro (&read_key_sequence_cmd
);
11893 menu_bar_one_keymap_changed_items
= Qnil
;
11894 staticpro (&menu_bar_one_keymap_changed_items
);
11896 menu_bar_items_vector
= Qnil
;
11897 staticpro (&menu_bar_items_vector
);
11899 help_form_saved_window_configs
= Qnil
;
11900 staticpro (&help_form_saved_window_configs
);
11902 defsubr (&Scurrent_idle_time
);
11903 defsubr (&Sevent_convert_list
);
11904 defsubr (&Sread_key_sequence
);
11905 defsubr (&Sread_key_sequence_vector
);
11906 defsubr (&Srecursive_edit
);
11907 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
11908 defsubr (&Strack_mouse
);
11910 defsubr (&Sinput_pending_p
);
11911 defsubr (&Scommand_execute
);
11912 defsubr (&Srecent_keys
);
11913 defsubr (&Sthis_command_keys
);
11914 defsubr (&Sthis_command_keys_vector
);
11915 defsubr (&Sthis_single_command_keys
);
11916 defsubr (&Sthis_single_command_raw_keys
);
11917 defsubr (&Sreset_this_command_lengths
);
11918 defsubr (&Sclear_this_command_keys
);
11919 defsubr (&Ssuspend_emacs
);
11920 defsubr (&Sabort_recursive_edit
);
11921 defsubr (&Sexit_recursive_edit
);
11922 defsubr (&Srecursion_depth
);
11923 defsubr (&Stop_level
);
11924 defsubr (&Sdiscard_input
);
11925 defsubr (&Sopen_dribble_file
);
11926 defsubr (&Sset_input_interrupt_mode
);
11927 defsubr (&Sset_output_flow_control
);
11928 defsubr (&Sset_input_meta_mode
);
11929 defsubr (&Sset_quit_char
);
11930 defsubr (&Sset_input_mode
);
11931 defsubr (&Scurrent_input_mode
);
11932 defsubr (&Sexecute_extended_command
);
11933 defsubr (&Sposn_at_point
);
11934 defsubr (&Sposn_at_x_y
);
11936 DEFVAR_LISP ("last-command-char", &last_command_char
,
11937 doc
: /* Last input event that was part of a command. */);
11939 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char
,
11940 doc
: /* Last input event that was part of a command. */);
11942 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
11943 doc
: /* Last input event in a command, except for mouse menu events.
11944 Mouse menus give back keys that don't look like mouse events;
11945 this variable holds the actual mouse event that led to the menu,
11946 so that you can determine whether the command was run by mouse or not. */);
11948 DEFVAR_LISP ("last-input-char", &last_input_char
,
11949 doc
: /* Last input event. */);
11951 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char
,
11952 doc
: /* Last input event. */);
11954 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
11955 doc
: /* List of events to be read as the command input.
11956 These events are processed first, before actual keyboard input.
11957 Events read from this list are not normally added to `this-command-keys',
11958 as they will already have been added once as they were read for the first time.
11959 An element of the form (t . EVENT) forces EVENT to be added to that list. */);
11960 Vunread_command_events
= Qnil
;
11962 DEFVAR_INT ("unread-command-char", &unread_command_char
,
11963 doc
: /* If not -1, an object to be read as next command input event. */);
11965 DEFVAR_LISP ("unread-post-input-method-events", &Vunread_post_input_method_events
,
11966 doc
: /* List of events to be processed as input by input methods.
11967 These events are processed before `unread-command-events'
11968 and actual keyboard input, but are not given to `input-method-function'. */);
11969 Vunread_post_input_method_events
= Qnil
;
11971 DEFVAR_LISP ("unread-input-method-events", &Vunread_input_method_events
,
11972 doc
: /* List of events to be processed as input by input methods.
11973 These events are processed after `unread-command-events', but
11974 before actual keyboard input.
11975 If there's an active input method, the events are given to
11976 `input-method-function'. */);
11977 Vunread_input_method_events
= Qnil
;
11979 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
11980 doc
: /* Meta-prefix character code.
11981 Meta-foo as command input turns into this character followed by foo. */);
11982 XSETINT (meta_prefix_char
, 033);
11984 DEFVAR_KBOARD ("last-command", Vlast_command
,
11985 doc
: /* The last command executed.
11986 Normally a symbol with a function definition, but can be whatever was found
11987 in the keymap, or whatever the variable `this-command' was set to by that
11990 The value `mode-exit' is special; it means that the previous command
11991 read an event that told it to exit, and it did so and unread that event.
11992 In other words, the present command is the event that made the previous
11995 The value `kill-region' is special; it means that the previous command
11996 was a kill command.
11998 `last-command' has a separate binding for each terminal device.
11999 See Info node `(elisp)Multiple displays'. */);
12001 DEFVAR_KBOARD ("real-last-command", Vreal_last_command
,
12002 doc
: /* Same as `last-command', but never altered by Lisp code. */);
12004 DEFVAR_KBOARD ("last-repeatable-command", Vlast_repeatable_command
,
12005 doc
: /* Last command that may be repeated.
12006 The last command executed that was not bound to an input event.
12007 This is the command `repeat' will try to repeat. */);
12009 DEFVAR_LISP ("this-command", &Vthis_command
,
12010 doc
: /* The command now being executed.
12011 The command can set this variable; whatever is put here
12012 will be in `last-command' during the following command. */);
12013 Vthis_command
= Qnil
;
12015 DEFVAR_LISP ("this-original-command", &Vthis_original_command
,
12016 doc
: /* The command bound to the current key sequence before remapping.
12017 It equals `this-command' if the original command was not remapped through
12018 any of the active keymaps. Otherwise, the value of `this-command' is the
12019 result of looking up the original command in the active keymaps. */);
12020 Vthis_original_command
= Qnil
;
12022 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
12023 doc
: /* *Number of input events between auto-saves.
12024 Zero means disable autosaving due to number of characters typed. */);
12025 auto_save_interval
= 300;
12027 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
12028 doc
: /* *Number of seconds idle time before auto-save.
12029 Zero or nil means disable auto-saving due to idleness.
12030 After auto-saving due to this many seconds of idle time,
12031 Emacs also does a garbage collection if that seems to be warranted. */);
12032 XSETFASTINT (Vauto_save_timeout
, 30);
12034 DEFVAR_LISP ("echo-keystrokes", &Vecho_keystrokes
,
12035 doc
: /* *Nonzero means echo unfinished commands after this many seconds of pause.
12036 The value may be integer or floating point. */);
12037 Vecho_keystrokes
= make_number (1);
12039 DEFVAR_INT ("polling-period", &polling_period
,
12040 doc
: /* *Interval between polling for input during Lisp execution.
12041 The reason for polling is to make C-g work to stop a running program.
12042 Polling is needed only when using X windows and SIGIO does not work.
12043 Polling is automatically disabled in all other cases. */);
12044 polling_period
= 2;
12046 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
12047 doc
: /* *Maximum time between mouse clicks to make a double-click.
12048 Measured in milliseconds. The value nil means disable double-click
12049 recognition; t means double-clicks have no time limit and are detected
12050 by position only. */);
12051 Vdouble_click_time
= make_number (500);
12053 DEFVAR_INT ("double-click-fuzz", &double_click_fuzz
,
12054 doc
: /* *Maximum mouse movement between clicks to make a double-click.
12055 On window-system frames, value is the number of pixels the mouse may have
12056 moved horizontally or vertically between two clicks to make a double-click.
12057 On non window-system frames, value is interpreted in units of 1/8 characters
12060 This variable is also the threshold for motion of the mouse
12061 to count as a drag. */);
12062 double_click_fuzz
= 3;
12064 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
12065 doc
: /* *Non-nil means inhibit local map menu bar menus. */);
12066 inhibit_local_menu_bar_menus
= 0;
12068 DEFVAR_INT ("num-input-keys", &num_input_keys
,
12069 doc
: /* Number of complete key sequences read as input so far.
12070 This includes key sequences read from keyboard macros.
12071 The number is effectively the number of interactive command invocations. */);
12072 num_input_keys
= 0;
12074 DEFVAR_INT ("num-nonmacro-input-events", &num_nonmacro_input_events
,
12075 doc
: /* Number of input events read from the keyboard so far.
12076 This does not include events generated by keyboard macros. */);
12077 num_nonmacro_input_events
= 0;
12079 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
12080 doc
: /* The frame in which the most recently read event occurred.
12081 If the last event came from a keyboard macro, this is set to `macro'. */);
12082 Vlast_event_frame
= Qnil
;
12084 /* This variable is set up in sysdep.c. */
12085 DEFVAR_LISP ("tty-erase-char", &Vtty_erase_char
,
12086 doc
: /* The ERASE character as set by the user with stty. */);
12088 DEFVAR_LISP ("help-char", &Vhelp_char
,
12089 doc
: /* Character to recognize as meaning Help.
12090 When it is read, do `(eval help-form)', and display result if it's a string.
12091 If the value of `help-form' is nil, this char can be read normally. */);
12092 XSETINT (Vhelp_char
, Ctl ('H'));
12094 DEFVAR_LISP ("help-event-list", &Vhelp_event_list
,
12095 doc
: /* List of input events to recognize as meaning Help.
12096 These work just like the value of `help-char' (see that). */);
12097 Vhelp_event_list
= Qnil
;
12099 DEFVAR_LISP ("help-form", &Vhelp_form
,
12100 doc
: /* Form to execute when character `help-char' is read.
12101 If the form returns a string, that string is displayed.
12102 If `help-form' is nil, the help char is not recognized. */);
12105 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
12106 doc
: /* Command to run when `help-char' character follows a prefix key.
12107 This command is used only when there is no actual binding
12108 for that character after that prefix key. */);
12109 Vprefix_help_command
= Qnil
;
12111 DEFVAR_LISP ("top-level", &Vtop_level
,
12112 doc
: /* Form to evaluate when Emacs starts up.
12113 Useful to set before you dump a modified Emacs. */);
12116 DEFVAR_KBOARD ("keyboard-translate-table", Vkeyboard_translate_table
,
12117 doc
: /* Translate table for local keyboard input, or nil.
12118 If non-nil, the value should be a char-table. Each character read
12119 from the keyboard is looked up in this char-table. If the value found
12120 there is non-nil, then it is used instead of the actual input character.
12122 The value can also be a string or vector, but this is considered obsolete.
12123 If it is a string or vector of length N, character codes N and up are left
12124 untranslated. In a vector, an element which is nil means "no translation".
12126 This is applied to the characters supplied to input methods, not their
12127 output. See also `translation-table-for-input'.
12129 This variable has a separate binding for each terminal. See Info node
12130 `(elisp)Multiple displays'. */);
12132 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
12133 doc
: /* Non-nil means to always spawn a subshell instead of suspending.
12134 \(Even if the operating system has support for stopping a process.\) */);
12135 cannot_suspend
= 0;
12137 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
12138 doc
: /* Non-nil means prompt with menus when appropriate.
12139 This is done when reading from a keymap that has a prompt string,
12140 for elements that have prompt strings.
12141 The menu is displayed on the screen
12142 if X menus were enabled at configuration
12143 time and the previous event was a mouse click prefix key.
12144 Otherwise, menu prompting uses the echo area. */);
12145 menu_prompting
= 1;
12147 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
12148 doc
: /* Character to see next line of menu prompt.
12149 Type this character while in a menu prompt to rotate around the lines of it. */);
12150 XSETINT (menu_prompt_more_char
, ' ');
12152 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
12153 doc
: /* A mask of additional modifier keys to use with every keyboard character.
12154 Emacs applies the modifiers of the character stored here to each keyboard
12155 character it reads. For example, after evaluating the expression
12156 (setq extra-keyboard-modifiers ?\\C-x)
12157 all input characters will have the control modifier applied to them.
12159 Note that the character ?\\C-@, equivalent to the integer zero, does
12160 not count as a control character; rather, it counts as a character
12161 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero
12162 cancels any modification. */);
12163 extra_keyboard_modifiers
= 0;
12165 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
12166 doc
: /* If an editing command sets this to t, deactivate the mark afterward.
12167 The command loop sets this to nil before each command,
12168 and tests the value when the command returns.
12169 Buffer modification stores t in this variable. */);
12170 Vdeactivate_mark
= Qnil
;
12172 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
12173 doc
: /* Temporary storage of pre-command-hook or post-command-hook. */);
12174 Vcommand_hook_internal
= Qnil
;
12176 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
12177 doc
: /* Normal hook run before each command is executed.
12178 If an unhandled error happens in running this hook,
12179 the hook value is set to nil, since otherwise the error
12180 might happen repeatedly and make Emacs nonfunctional. */);
12181 Vpre_command_hook
= Qnil
;
12183 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
12184 doc
: /* Normal hook run after each command is executed.
12185 If an unhandled error happens in running this hook,
12186 the hook value is set to nil, since otherwise the error
12187 might happen repeatedly and make Emacs nonfunctional. */);
12188 Vpost_command_hook
= Qnil
;
12191 DEFVAR_LISP ("echo-area-clear-hook", ...,
12192 doc
: /* Normal hook run when clearing the echo area. */);
12194 Qecho_area_clear_hook
= intern ("echo-area-clear-hook");
12195 staticpro (&Qecho_area_clear_hook
);
12196 SET_SYMBOL_VALUE (Qecho_area_clear_hook
, Qnil
);
12198 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
12199 doc
: /* Non-nil means menu bar, specified Lucid style, needs to be recomputed. */);
12200 Vlucid_menu_bar_dirty_flag
= Qnil
;
12202 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
12203 doc
: /* List of menu bar items to move to the end of the menu bar.
12204 The elements of the list are event types that may have menu bar bindings. */);
12205 Vmenu_bar_final_items
= Qnil
;
12207 DEFVAR_KBOARD ("overriding-terminal-local-map",
12208 Voverriding_terminal_local_map
,
12209 doc
: /* Per-terminal keymap that overrides all other local keymaps.
12210 If this variable is non-nil, it is used as a keymap instead of the
12211 buffer's local map, and the minor mode keymaps and text property keymaps.
12212 It also replaces `overriding-local-map'.
12214 This variable is intended to let commands such as `universal-argument'
12215 set up a different keymap for reading the next command.
12217 `overriding-terminal-local-map' has a separate binding for each
12219 See Info node `(elisp)Multiple displays'. */);
12221 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
12222 doc
: /* Keymap that overrides all other local keymaps.
12223 If this variable is non-nil, it is used as a keymap--replacing the
12224 buffer's local map, the minor mode keymaps, and char property keymaps. */);
12225 Voverriding_local_map
= Qnil
;
12227 DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag
,
12228 doc
: /* Non-nil means `overriding-local-map' applies to the menu bar.
12229 Otherwise, the menu bar continues to reflect the buffer's local map
12230 and the minor mode maps regardless of `overriding-local-map'. */);
12231 Voverriding_local_map_menu_flag
= Qnil
;
12233 DEFVAR_LISP ("special-event-map", &Vspecial_event_map
,
12234 doc
: /* Keymap defining bindings for special events to execute at low level. */);
12235 Vspecial_event_map
= Fcons (intern ("keymap"), Qnil
);
12237 DEFVAR_LISP ("track-mouse", &do_mouse_tracking
,
12238 doc
: /* *Non-nil means generate motion events for mouse motion. */);
12240 DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist
,
12241 doc
: /* Alist of system-specific X windows key symbols.
12242 Each element should have the form (N . SYMBOL) where N is the
12243 numeric keysym code (sans the \"system-specific\" bit 1<<28)
12244 and SYMBOL is its name.
12246 `system-key-alist' has a separate binding for each terminal device.
12247 See Info node `(elisp)Multiple displays'. */);
12249 DEFVAR_KBOARD ("local-function-key-map", Vlocal_function_key_map
,
12250 doc
: /* Keymap that translates key sequences to key sequences during input.
12251 This is used mainly for mapping key sequences into some preferred
12252 key events (symbols).
12254 The `read-key-sequence' function replaces any subsequence bound by
12255 `local-function-key-map' with its binding. More precisely, when the
12256 active keymaps have no binding for the current key sequence but
12257 `local-function-key-map' binds a suffix of the sequence to a vector or
12258 string, `read-key-sequence' replaces the matching suffix with its
12259 binding, and continues with the new sequence.
12261 If the binding is a function, it is called with one argument (the prompt)
12262 and its return value (a key sequence) is used.
12264 The events that come from bindings in `local-function-key-map' are not
12265 themselves looked up in `local-function-key-map'.
12267 For example, suppose `local-function-key-map' binds `ESC O P' to [f1].
12268 Typing `ESC O P' to `read-key-sequence' would return [f1]. Typing
12269 `C-x ESC O P' would return [?\\C-x f1]. If [f1] were a prefix key,
12270 typing `ESC O P x' would return [f1 x].
12272 `local-function-key-map' has a separate binding for each terminal
12273 device. See Info node `(elisp)Multiple displays'. If you need to
12274 define a binding on all terminals, change `function-key-map'
12275 instead. Initially, `local-function-key-map' is an empty keymap that
12276 has `function-key-map' as its parent on all terminal devices. */);
12278 DEFVAR_KBOARD ("input-decode-map", Vinput_decode_map
,
12279 doc
: /* Keymap that decodes input escape sequences.
12280 This is used mainly for mapping ASCII function key sequences into
12281 real Emacs function key events (symbols).
12283 The `read-key-sequence' function replaces any subsequence bound by
12284 `local-function-key-map' with its binding. Contrary to `function-key-map',
12285 this map applies its rebinding regardless of the presence of an ordinary
12286 binding. So it is more like `key-translation-map' except that it applies
12287 before `function-key-map' rather than after.
12289 If the binding is a function, it is called with one argument (the prompt)
12290 and its return value (a key sequence) is used.
12292 The events that come from bindings in `input-decode-map' are not
12293 themselves looked up in `input-decode-map'.
12295 This variable is keyboard-local. */);
12297 DEFVAR_LISP ("function-key-map", &Vfunction_key_map
,
12298 doc
: /* The parent keymap of all `local-function-key-map' instances.
12299 Function key definitions that apply to all terminal devices should go
12300 here. If a mapping is defined in both the current
12301 `local-function-key-map' binding and this variable, then the local
12302 definition will take precendence. */);
12303 Vfunction_key_map
= Fmake_sparse_keymap (Qnil
);
12305 DEFVAR_LISP ("key-translation-map", &Vkey_translation_map
,
12306 doc
: /* Keymap of key translations that can override keymaps.
12307 This keymap works like `function-key-map', but comes after that,
12308 and its non-prefix bindings override ordinary bindings.
12309 Another difference is that it is global rather than keyboard-local. */);
12310 Vkey_translation_map
= Fmake_sparse_keymap (Qnil
);
12312 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
12313 doc
: /* List of deferred actions to be performed at a later time.
12314 The precise format isn't relevant here; we just check whether it is nil. */);
12315 Vdeferred_action_list
= Qnil
;
12317 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
12318 doc
: /* Function to call to handle deferred actions, after each command.
12319 This function is called with no arguments after each command
12320 whenever `deferred-action-list' is non-nil. */);
12321 Vdeferred_action_function
= Qnil
;
12323 DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings
,
12324 doc
: /* *Non-nil means show the equivalent key-binding when M-x command has one.
12325 The value can be a length of time to show the message for.
12326 If the value is non-nil and not a number, we wait 2 seconds. */);
12327 Vsuggest_key_bindings
= Qt
;
12329 DEFVAR_LISP ("timer-list", &Vtimer_list
,
12330 doc
: /* List of active absolute time timers in order of increasing time. */);
12331 Vtimer_list
= Qnil
;
12333 DEFVAR_LISP ("timer-idle-list", &Vtimer_idle_list
,
12334 doc
: /* List of active idle-time timers in order of increasing time. */);
12335 Vtimer_idle_list
= Qnil
;
12337 DEFVAR_LISP ("input-method-function", &Vinput_method_function
,
12338 doc
: /* If non-nil, the function that implements the current input method.
12339 It's called with one argument, a printing character that was just read.
12340 \(That means a character with code 040...0176.)
12341 Typically this function uses `read-event' to read additional events.
12342 When it does so, it should first bind `input-method-function' to nil
12343 so it will not be called recursively.
12345 The function should return a list of zero or more events
12346 to be used as input. If it wants to put back some events
12347 to be reconsidered, separately, by the input method,
12348 it can add them to the beginning of `unread-command-events'.
12350 The input method function can find in `input-method-previous-method'
12351 the previous echo area message.
12353 The input method function should refer to the variables
12354 `input-method-use-echo-area' and `input-method-exit-on-first-char'
12355 for guidance on what to do. */);
12356 Vinput_method_function
= Qnil
;
12358 DEFVAR_LISP ("input-method-previous-message",
12359 &Vinput_method_previous_message
,
12360 doc
: /* When `input-method-function' is called, hold the previous echo area message.
12361 This variable exists because `read-event' clears the echo area
12362 before running the input method. It is nil if there was no message. */);
12363 Vinput_method_previous_message
= Qnil
;
12365 DEFVAR_LISP ("show-help-function", &Vshow_help_function
,
12366 doc
: /* If non-nil, the function that implements the display of help.
12367 It's called with one argument, the help string to display. */);
12368 Vshow_help_function
= Qnil
;
12370 DEFVAR_LISP ("disable-point-adjustment", &Vdisable_point_adjustment
,
12371 doc
: /* If non-nil, suppress point adjustment after executing a command.
12373 After a command is executed, if point is moved into a region that has
12374 special properties (e.g. composition, display), we adjust point to
12375 the boundary of the region. But, when a command sets this variable to
12376 non-nil, we suppress the point adjustment.
12378 This variable is set to nil before reading a command, and is checked
12379 just after executing the command. */);
12380 Vdisable_point_adjustment
= Qnil
;
12382 DEFVAR_LISP ("global-disable-point-adjustment",
12383 &Vglobal_disable_point_adjustment
,
12384 doc
: /* *If non-nil, always suppress point adjustment.
12386 The default value is nil, in which case, point adjustment are
12387 suppressed only after special commands that set
12388 `disable-point-adjustment' (which see) to non-nil. */);
12389 Vglobal_disable_point_adjustment
= Qnil
;
12391 DEFVAR_LISP ("minibuffer-message-timeout", &Vminibuffer_message_timeout
,
12392 doc
: /* *How long to display an echo-area message when the minibuffer is active.
12393 If the value is not a number, such messages don't time out. */);
12394 Vminibuffer_message_timeout
= make_number (2);
12396 DEFVAR_LISP ("throw-on-input", &Vthrow_on_input
,
12397 doc
: /* If non-nil, any keyboard input throws to this symbol.
12398 The value of that variable is passed to `quit-flag' and later causes a
12399 peculiar kind of quitting. */);
12400 Vthrow_on_input
= Qnil
;
12402 DEFVAR_LISP ("command-error-function", &Vcommand_error_function
,
12403 doc
: /* If non-nil, function to output error messages.
12404 The arguments are the error data, a list of the form
12405 (SIGNALED-CONDITIONS . SIGNAL-DATA)
12406 such as just as `condition-case' would bind its variable to,
12407 the context (a string which normally goes at the start of the message),
12408 and the Lisp function within which the error was signaled. */);
12409 Vcommand_error_function
= Qnil
;
12411 DEFVAR_LISP ("enable-disabled-menus-and-buttons",
12412 &Venable_disabled_menus_and_buttons
,
12413 doc
: /* If non-nil, don't ignore events produced by disabled menu items and tool-bar.
12415 Help functions bind this to allow help on disabled menu items
12416 and tool-bar buttons. */);
12417 Venable_disabled_menus_and_buttons
= Qnil
;
12421 keys_of_keyboard ()
12423 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
12424 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
12425 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
12426 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
12427 initial_define_key (meta_map
, 'x', "execute-extended-command");
12429 initial_define_lispy_key (Vspecial_event_map
, "delete-frame",
12430 "handle-delete-frame");
12431 /* Here we used to use `ignore-event' which would simple set prefix-arg to
12432 current-prefix-arg, as is done in `handle-switch-frame'.
12433 But `handle-switch-frame is not run from the special-map.
12434 Commands from that map are run in a special way that automatically
12435 preserves the prefix-arg. Restoring the prefix arg here is not just
12436 redundant but harmful:
12438 - current-prefix-arg is set to non-nil, prefix-arg is set to nil.
12439 - after the first prompt, the exit-minibuffer-hook is run which may
12440 iconify a frame and thus push a `iconify-frame' event.
12441 - after running exit-minibuffer-hook, current-prefix-arg is
12442 restored to the non-nil value it had before the prompt.
12443 - we enter the second prompt.
12444 current-prefix-arg is non-nil, prefix-arg is nil.
12445 - before running the first real event, we run the special iconify-frame
12446 event, but we pass the `special' arg to execute-command so
12447 current-prefix-arg and prefix-arg are left untouched.
12448 - here we foolishly copy the non-nil current-prefix-arg to prefix-arg.
12449 - the next key event will have a spuriously non-nil current-prefix-arg. */
12450 initial_define_lispy_key (Vspecial_event_map
, "iconify-frame",
12452 initial_define_lispy_key (Vspecial_event_map
, "make-frame-visible",
12454 /* Handling it at such a low-level causes read_key_sequence to get
12455 * confused because it doesn't realize that the current_buffer was
12456 * changed by read_char.
12458 * initial_define_lispy_key (Vspecial_event_map, "select-window",
12459 * "handle-select-window"); */
12460 initial_define_lispy_key (Vspecial_event_map
, "save-session",
12461 "handle-save-session");
12464 /* Mark the pointers in the kboard objects.
12465 Called by the Fgarbage_collector. */
12471 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
12473 if (kb
->kbd_macro_buffer
)
12474 for (p
= kb
->kbd_macro_buffer
; p
< kb
->kbd_macro_ptr
; p
++)
12476 mark_object (kb
->Voverriding_terminal_local_map
);
12477 mark_object (kb
->Vlast_command
);
12478 mark_object (kb
->Vreal_last_command
);
12479 mark_object (kb
->Vkeyboard_translate_table
);
12480 mark_object (kb
->Vlast_repeatable_command
);
12481 mark_object (kb
->Vprefix_arg
);
12482 mark_object (kb
->Vlast_prefix_arg
);
12483 mark_object (kb
->kbd_queue
);
12484 mark_object (kb
->defining_kbd_macro
);
12485 mark_object (kb
->Vlast_kbd_macro
);
12486 mark_object (kb
->Vsystem_key_alist
);
12487 mark_object (kb
->system_key_syms
);
12488 mark_object (kb
->Vinput_decode_map
);
12489 mark_object (kb
->Vlocal_function_key_map
);
12490 mark_object (kb
->Vdefault_minibuffer_frame
);
12491 mark_object (kb
->echo_string
);
12494 struct input_event
*event
;
12495 for (event
= kbd_fetch_ptr
; event
!= kbd_store_ptr
; event
++)
12497 if (event
== kbd_buffer
+ KBD_BUFFER_SIZE
)
12498 event
= kbd_buffer
;
12499 if (event
->kind
!= SELECTION_REQUEST_EVENT
12500 && event
->kind
!= SELECTION_CLEAR_EVENT
)
12502 mark_object (event
->x
);
12503 mark_object (event
->y
);
12505 mark_object (event
->frame_or_window
);
12506 mark_object (event
->arg
);
12511 /* arch-tag: 774e34d7-6d31-42f3-8397-e079a4e4c9ca
12512 (do not change this comment) */