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, 2008, 2009, 2010 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 of the License, or
11 (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>. */
29 #include "termhooks.h"
35 #include "character.h"
37 #include "dispextern.h"
39 #include "intervals.h"
41 #include "blockinput.h"
47 #ifdef HAVE_GTK_AND_PTHREAD
54 #include <sys/ioctl.h>
55 #endif /* not MSDOS */
57 #include "syssignal.h"
59 #include <sys/types.h>
68 /* This is to get the definitions of the XK_ symbols. */
75 #endif /* HAVE_NTGUI */
85 /* Variables for blockinput.h: */
87 /* Non-zero if interrupt input is blocked right now. */
88 volatile int interrupt_input_blocked
;
90 /* Nonzero means an input interrupt has arrived
91 during the current critical section. */
92 int interrupt_input_pending
;
94 /* This var should be (interrupt_input_pending || pending_atimers).
95 The QUIT macro checks this instead of interrupt_input_pending and
96 pending_atimers separately, to reduce code size. So, any code that
97 changes interrupt_input_pending or pending_atimers should update
103 #define KBD_BUFFER_SIZE 4096
105 KBOARD
*initial_kboard
;
106 KBOARD
*current_kboard
;
110 /* Non-nil disable property on a command means
111 do not execute it; call disabled-command-function's value instead. */
112 Lisp_Object Qdisabled
, Qdisabled_command_function
;
114 #define NUM_RECENT_KEYS (300)
115 int recent_keys_index
; /* Index for storing next element into recent_keys */
116 int total_keys
; /* Total number of elements stored into recent_keys */
117 Lisp_Object recent_keys
; /* Vector holds the last NUM_RECENT_KEYS keystrokes */
119 /* Vector holding the key sequence that invoked the current command.
120 It is reused for each command, and it may be longer than the current
121 sequence; this_command_key_count indicates how many elements
122 actually mean something.
123 It's easier to staticpro a single Lisp_Object than an array. */
124 Lisp_Object this_command_keys
;
125 int this_command_key_count
;
127 /* 1 after calling Freset_this_command_lengths.
129 int this_command_key_count_reset
;
131 /* This vector is used as a buffer to record the events that were actually read
132 by read_key_sequence. */
133 Lisp_Object raw_keybuf
;
134 int raw_keybuf_count
;
136 /* Non-nil if the present key sequence was obtained by shift translation. */
137 Lisp_Object Vthis_command_keys_shift_translated
;
139 #define GROW_RAW_KEYBUF \
140 if (raw_keybuf_count == XVECTOR (raw_keybuf)->size) \
141 raw_keybuf = larger_vector (raw_keybuf, raw_keybuf_count * 2, Qnil) \
143 /* Number of elements of this_command_keys
144 that precede this key sequence. */
145 int this_single_command_key_start
;
147 /* Record values of this_command_key_count and echo_length ()
148 before this command was read. */
149 static int before_command_key_count
;
150 static int before_command_echo_length
;
152 extern int minbuf_level
;
154 extern int message_enable_multibyte
;
156 /* If non-nil, the function that implements the display of help.
157 It's called with one argument, the help string to display. */
159 Lisp_Object Vshow_help_function
;
161 /* Nonzero means do menu prompting. */
163 static int menu_prompting
;
165 /* Character to see next line of menu prompt. */
167 static Lisp_Object menu_prompt_more_char
;
169 /* For longjmp to where kbd input is being done. */
171 static jmp_buf getcjmp
;
173 /* True while doing kbd input. */
174 int waiting_for_input
;
176 /* True while displaying for echoing. Delays C-g throwing. */
180 /* Non-null means we can start echoing at the next input pause even
181 though there is something in the echo area. */
183 static struct kboard
*ok_to_echo_at_next_pause
;
185 /* The kboard last echoing, or null for none. Reset to 0 in
186 cancel_echoing. If non-null, and a current echo area message
187 exists, and echo_message_buffer is eq to the current message
188 buffer, we know that the message comes from echo_kboard. */
190 struct kboard
*echo_kboard
;
192 /* The buffer used for echoing. Set in echo_now, reset in
195 Lisp_Object echo_message_buffer
;
197 /* Nonzero means disregard local maps for the menu bar. */
198 static int inhibit_local_menu_bar_menus
;
200 /* Nonzero means C-g should cause immediate error-signal. */
203 /* The user's hook function for outputting an error message. */
204 Lisp_Object Vcommand_error_function
;
206 /* The user's ERASE setting. */
207 Lisp_Object Vtty_erase_char
;
209 /* Character to recognize as the help char. */
210 Lisp_Object Vhelp_char
;
212 /* List of other event types to recognize as meaning "help". */
213 Lisp_Object Vhelp_event_list
;
215 /* Form to execute when help char is typed. */
216 Lisp_Object Vhelp_form
;
218 /* Command to run when the help character follows a prefix key. */
219 Lisp_Object Vprefix_help_command
;
221 /* List of items that should move to the end of the menu bar. */
222 Lisp_Object Vmenu_bar_final_items
;
224 /* Non-nil means show the equivalent key-binding for
225 any M-x command that has one.
226 The value can be a length of time to show the message for.
227 If the value is non-nil and not a number, we wait 2 seconds. */
228 Lisp_Object Vsuggest_key_bindings
;
230 /* How long to display an echo-area message when the minibuffer is active.
231 If the value is not a number, such messages don't time out. */
232 Lisp_Object Vminibuffer_message_timeout
;
234 /* Character that causes a quit. Normally C-g.
236 If we are running on an ordinary terminal, this must be an ordinary
237 ASCII char, since we want to make it our interrupt character.
239 If we are not running on an ordinary terminal, it still needs to be
240 an ordinary ASCII char. This character needs to be recognized in
241 the input interrupt handler. At this point, the keystroke is
242 represented as a struct input_event, while the desired quit
243 character is specified as a lispy event. The mapping from struct
244 input_events to lispy events cannot run in an interrupt handler,
245 and the reverse mapping is difficult for anything but ASCII
248 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
252 extern Lisp_Object current_global_map
;
253 extern int minibuf_level
;
255 /* If non-nil, this is a map that overrides all other local maps. */
256 Lisp_Object Voverriding_local_map
;
258 /* If non-nil, Voverriding_local_map applies to the menu bar. */
259 Lisp_Object Voverriding_local_map_menu_flag
;
261 /* Keymap that defines special misc events that should
262 be processed immediately at a low level. */
263 Lisp_Object Vspecial_event_map
;
265 /* Current depth in recursive edits. */
266 int command_loop_level
;
268 /* Total number of times command_loop has read a key sequence. */
269 EMACS_INT num_input_keys
;
271 /* Last input event read as a command. */
272 Lisp_Object last_command_event
;
274 /* Last input character read as a command, not counting menus
275 reached by the mouse. */
276 Lisp_Object last_nonmenu_event
;
278 /* Last input event read for any purpose. */
279 Lisp_Object last_input_event
;
281 /* If not Qnil, a list of objects to be read as subsequent command input. */
282 Lisp_Object Vunread_command_events
;
284 /* If not Qnil, a list of objects to be read as subsequent command input
285 including input method processing. */
286 Lisp_Object Vunread_input_method_events
;
288 /* If not Qnil, a list of objects to be read as subsequent command input
289 but NOT including input method processing. */
290 Lisp_Object Vunread_post_input_method_events
;
292 /* If not -1, an event to be read as subsequent command input. */
293 EMACS_INT unread_command_char
;
295 /* If not Qnil, this is a switch-frame event which we decided to put
296 off until the end of a key sequence. This should be read as the
297 next command input, after any unread_command_events.
299 read_key_sequence uses this to delay switch-frame events until the
300 end of the key sequence; Fread_char uses it to put off switch-frame
301 events until a non-ASCII event is acceptable as input. */
302 Lisp_Object unread_switch_frame
;
304 /* A mask of extra modifier bits to put into every keyboard char. */
305 EMACS_INT extra_keyboard_modifiers
;
307 /* Char to use as prefix when a meta character is typed in.
308 This is bound on entry to minibuffer in case ESC is changed there. */
310 Lisp_Object meta_prefix_char
;
312 /* Last size recorded for a current buffer which is not a minibuffer. */
313 static int last_non_minibuf_size
;
315 /* Number of idle seconds before an auto-save and garbage collection. */
316 static Lisp_Object Vauto_save_timeout
;
318 /* Total number of times read_char has returned. */
319 int num_input_events
;
321 /* Total number of times read_char has returned, outside of macros. */
322 EMACS_INT num_nonmacro_input_events
;
324 /* Auto-save automatically when this many characters have been typed
325 since the last time. */
327 static EMACS_INT auto_save_interval
;
329 /* Value of num_nonmacro_input_events as of last auto save. */
333 /* The command being executed by the command loop.
334 Commands may set this, and the value set will be copied into
335 current_kboard->Vlast_command instead of the actual command. */
336 Lisp_Object Vthis_command
;
338 /* This is like Vthis_command, except that commands never set it. */
339 Lisp_Object real_this_command
;
341 /* If the lookup of the command returns a binding, the original
342 command is stored in this-original-command. It is nil otherwise. */
343 Lisp_Object Vthis_original_command
;
345 /* The value of point when the last command was started. */
346 int last_point_position
;
348 /* The buffer that was current when the last command was started. */
349 Lisp_Object last_point_position_buffer
;
351 /* The window that was selected when the last command was started. */
352 Lisp_Object last_point_position_window
;
354 /* The frame in which the last input event occurred, or Qmacro if the
355 last event came from a macro. We use this to determine when to
356 generate switch-frame events. This may be cleared by functions
357 like Fselect_frame, to make sure that a switch-frame event is
358 generated by the next character. */
359 Lisp_Object internal_last_event_frame
;
361 /* A user-visible version of the above, intended to allow users to
362 figure out where the last event came from, if the event doesn't
363 carry that information itself (i.e. if it was a character). */
364 Lisp_Object Vlast_event_frame
;
366 /* The timestamp of the last input event we received from the X server.
367 X Windows wants this for selection ownership. */
368 unsigned long last_event_timestamp
;
370 Lisp_Object Qself_insert_command
;
371 Lisp_Object Qforward_char
;
372 Lisp_Object Qbackward_char
;
373 Lisp_Object Qundefined
;
374 Lisp_Object Qtimer_event_handler
;
376 /* read_key_sequence stores here the command definition of the
377 key sequence that it reads. */
378 Lisp_Object read_key_sequence_cmd
;
380 /* Echo unfinished commands after this many seconds of pause. */
381 Lisp_Object Vecho_keystrokes
;
383 /* Form to evaluate (if non-nil) when Emacs is started. */
384 Lisp_Object Vtop_level
;
386 /* If non-nil, this implements the current input method. */
387 Lisp_Object Vinput_method_function
;
388 Lisp_Object Qinput_method_function
;
390 /* When we call Vinput_method_function,
391 this holds the echo area message that was just erased. */
392 Lisp_Object Vinput_method_previous_message
;
394 /* Non-nil means deactivate the mark at end of this command. */
395 Lisp_Object Vdeactivate_mark
;
396 Lisp_Object Qdeactivate_mark
;
398 /* Menu bar specified in Lucid Emacs fashion. */
400 Lisp_Object Vlucid_menu_bar_dirty_flag
;
401 Lisp_Object Qrecompute_lucid_menubar
, Qactivate_menubar_hook
;
403 Lisp_Object Qecho_area_clear_hook
;
405 /* Hooks to run before and after each command. */
406 Lisp_Object Qpre_command_hook
, Vpre_command_hook
;
407 Lisp_Object Qpost_command_hook
, Vpost_command_hook
;
408 Lisp_Object Qcommand_hook_internal
, Vcommand_hook_internal
;
410 /* Parent keymap of terminal-local function-key-map instances. */
411 Lisp_Object Vfunction_key_map
;
413 /* Keymap of key translations that can override keymaps. */
414 Lisp_Object Vkey_translation_map
;
416 /* List of deferred actions to be performed at a later time.
417 The precise format isn't relevant here; we just check whether it is nil. */
418 Lisp_Object Vdeferred_action_list
;
420 /* Function to call to handle deferred actions, when there are any. */
421 Lisp_Object Vdeferred_action_function
;
422 Lisp_Object Qdeferred_action_function
;
424 Lisp_Object Qinput_method_exit_on_first_char
;
425 Lisp_Object Qinput_method_use_echo_area
;
427 /* File in which we write all commands we read. */
430 /* Nonzero if input is available. */
433 extern char *pending_malloc_warning
;
435 /* Circular buffer for pre-read keyboard input. */
437 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
439 /* Pointer to next available character in kbd_buffer.
440 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
441 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the
442 next available char is in kbd_buffer[0]. */
443 static struct input_event
*kbd_fetch_ptr
;
445 /* Pointer to next place to store character in kbd_buffer. This
446 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
447 character should go in kbd_buffer[0]. */
448 static struct input_event
* volatile kbd_store_ptr
;
450 /* The above pair of variables forms a "queue empty" flag. When we
451 enqueue a non-hook event, we increment kbd_store_ptr. When we
452 dequeue a non-hook event, we increment kbd_fetch_ptr. We say that
453 there is input available if the two pointers are not equal.
455 Why not just have a flag set and cleared by the enqueuing and
456 dequeuing functions? Such a flag could be screwed up by interrupts
457 at inopportune times. */
459 /* If this flag is non-nil, we check mouse_moved to see when the
460 mouse moves, and motion events will appear in the input stream.
461 Otherwise, mouse motion is ignored. */
462 Lisp_Object do_mouse_tracking
;
464 /* Symbols to head events. */
465 Lisp_Object Qmouse_movement
;
466 Lisp_Object Qscroll_bar_movement
;
467 Lisp_Object Qswitch_frame
;
468 Lisp_Object Qdelete_frame
;
469 Lisp_Object Qiconify_frame
;
470 Lisp_Object Qmake_frame_visible
;
471 Lisp_Object Qselect_window
;
472 Lisp_Object Qhelp_echo
;
474 extern Lisp_Object Qremap
;
476 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
477 Lisp_Object Qmouse_fixup_help_message
;
480 /* Symbols to denote kinds of events. */
481 Lisp_Object Qfunction_key
;
482 Lisp_Object Qmouse_click
;
483 #if defined (WINDOWSNT)
484 Lisp_Object Qlanguage_change
;
486 Lisp_Object Qdrag_n_drop
;
487 Lisp_Object Qsave_session
;
489 Lisp_Object Qdbus_event
;
491 Lisp_Object Qconfig_changed_event
;
493 /* Lisp_Object Qmouse_movement; - also an event header */
495 /* Properties of event headers. */
496 Lisp_Object Qevent_kind
;
497 Lisp_Object Qevent_symbol_elements
;
499 /* menu item parts */
500 Lisp_Object Qmenu_enable
;
501 Lisp_Object QCenable
, QCvisible
, QChelp
, QCfilter
, QCkeys
, QCkey_sequence
;
502 Lisp_Object QCbutton
, QCtoggle
, QCradio
;
503 extern Lisp_Object Qmenu_item
;
505 /* An event header symbol HEAD may have a property named
506 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
507 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
508 mask of modifiers applied to it. If present, this is used to help
509 speed up parse_modifiers. */
510 Lisp_Object Qevent_symbol_element_mask
;
512 /* An unmodified event header BASE may have a property named
513 Qmodifier_cache, which is an alist mapping modifier masks onto
514 modified versions of BASE. If present, this helps speed up
516 Lisp_Object Qmodifier_cache
;
518 /* Symbols to use for parts of windows. */
519 Lisp_Object Qmode_line
;
520 Lisp_Object Qvertical_line
;
521 Lisp_Object Qvertical_scroll_bar
;
522 Lisp_Object Qmenu_bar
;
523 extern Lisp_Object Qleft_margin
, Qright_margin
;
524 extern Lisp_Object Qleft_fringe
, Qright_fringe
;
525 extern Lisp_Object QCmap
;
527 Lisp_Object
recursive_edit_unwind (), command_loop ();
528 Lisp_Object
Fthis_command_keys ();
529 Lisp_Object Qextended_command_history
;
530 EMACS_TIME
timer_check ();
532 extern Lisp_Object Vhistory_length
, Vtranslation_table_for_input
;
534 extern char *x_get_keysym_name ();
536 static void record_menu_key ();
537 static int echo_length ();
539 Lisp_Object Qpolling_period
;
541 /* List of absolute timers. Appears in order of next scheduled event. */
542 Lisp_Object Vtimer_list
;
544 /* List of idle time timers. Appears in order of next scheduled event. */
545 Lisp_Object Vtimer_idle_list
;
547 /* Incremented whenever a timer is run. */
550 extern Lisp_Object Vprint_level
, Vprint_length
;
552 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
554 EMACS_TIME
*input_available_clear_time
;
556 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
557 Default is 1 if INTERRUPT_INPUT is defined. */
560 /* Nonzero while interrupts are temporarily deferred during redisplay. */
561 int interrupts_deferred
;
563 /* Allow m- file to inhibit use of FIONREAD. */
564 #ifdef BROKEN_FIONREAD
568 /* We are unable to use interrupts if FIONREAD is not available,
569 so flush SIGIO so we won't try. */
570 #if !defined (FIONREAD)
576 /* If we support a window system, turn on the code to poll periodically
577 to detect C-g. It isn't actually used when doing interrupt input. */
578 #if defined(HAVE_WINDOW_SYSTEM) && !defined(USE_ASYNC_EVENTS)
579 #define POLL_FOR_INPUT
582 /* After a command is executed, if point is moved into a region that
583 has specific properties (e.g. composition, display), we adjust
584 point to the boundary of the region. But, if a command sets this
585 variable to non-nil, we suppress this point adjustment. This
586 variable is set to nil before reading a command. */
588 Lisp_Object Vdisable_point_adjustment
;
590 /* If non-nil, always disable point adjustment. */
592 Lisp_Object Vglobal_disable_point_adjustment
;
594 /* The time when Emacs started being idle. */
596 static EMACS_TIME timer_idleness_start_time
;
598 /* After Emacs stops being idle, this saves the last value
599 of timer_idleness_start_time from when it was idle. */
601 static EMACS_TIME timer_last_idleness_start_time
;
603 /* If non-nil, events produced by disabled menu items and tool-bar
604 buttons are not ignored. Help functions bind this to allow help on
605 those items and buttons. */
606 Lisp_Object Venable_disabled_menus_and_buttons
;
609 /* Global variable declarations. */
611 /* Flags for readable_events. */
612 #define READABLE_EVENTS_DO_TIMERS_NOW (1 << 0)
613 #define READABLE_EVENTS_FILTER_EVENTS (1 << 1)
614 #define READABLE_EVENTS_IGNORE_SQUEEZABLES (1 << 2)
616 /* Function for init_keyboard to call with no args (if nonzero). */
617 void (*keyboard_init_hook
) ();
619 static int read_avail_input
P_ ((int));
620 static void get_input_pending
P_ ((int *, int));
621 static int readable_events
P_ ((int));
622 static Lisp_Object read_char_x_menu_prompt
P_ ((int, Lisp_Object
*,
623 Lisp_Object
, int *));
624 static Lisp_Object
read_char_x_menu_prompt ();
625 static Lisp_Object read_char_minibuf_menu_prompt
P_ ((int, int,
627 static Lisp_Object make_lispy_event
P_ ((struct input_event
*));
628 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
629 static Lisp_Object make_lispy_movement
P_ ((struct frame
*, Lisp_Object
,
630 enum scroll_bar_part
,
631 Lisp_Object
, Lisp_Object
,
634 static Lisp_Object modify_event_symbol
P_ ((int, unsigned, Lisp_Object
,
635 Lisp_Object
, char **,
636 Lisp_Object
*, unsigned));
637 static Lisp_Object make_lispy_switch_frame
P_ ((Lisp_Object
));
638 static void save_getcjmp
P_ ((jmp_buf));
639 static void save_getcjmp ();
640 static void restore_getcjmp
P_ ((jmp_buf));
641 static Lisp_Object apply_modifiers
P_ ((int, Lisp_Object
));
642 static void clear_event
P_ ((struct input_event
*));
643 static Lisp_Object restore_kboard_configuration
P_ ((Lisp_Object
));
644 static SIGTYPE interrupt_signal
P_ ((int signalnum
));
645 static void handle_interrupt
P_ ((void));
646 static void timer_start_idle
P_ ((void));
647 static void timer_stop_idle
P_ ((void));
648 static void timer_resume_idle
P_ ((void));
649 static SIGTYPE handle_user_signal
P_ ((int));
650 static char *find_user_signal_name
P_ ((int));
651 static int store_user_signal_events
P_ ((void));
653 /* Nonzero means don't try to suspend even if the operating system seems
655 static int cannot_suspend
;
657 extern Lisp_Object Qidentity
, Qonly
;
659 /* Install the string STR as the beginning of the string of echoing,
660 so that it serves as a prompt for the next character.
661 Also start echoing. */
667 current_kboard
->echo_string
= str
;
668 current_kboard
->echo_after_prompt
= SCHARS (str
);
672 /* Add C to the echo string, if echoing is going on.
673 C can be a character, which is printed prettily ("M-C-x" and all that
674 jazz), or a symbol, whose name is printed. */
680 if (current_kboard
->immediate_echo
)
682 int size
= KEY_DESCRIPTION_SIZE
+ 100;
683 char *buffer
= (char *) alloca (size
);
685 Lisp_Object echo_string
;
687 echo_string
= current_kboard
->echo_string
;
689 /* If someone has passed us a composite event, use its head symbol. */
694 ptr
= push_key_description (XINT (c
), ptr
, 1);
696 else if (SYMBOLP (c
))
698 Lisp_Object name
= SYMBOL_NAME (c
);
699 int nbytes
= SBYTES (name
);
701 if (size
- (ptr
- buffer
) < nbytes
)
703 int offset
= ptr
- buffer
;
704 size
= max (2 * size
, size
+ nbytes
);
705 buffer
= (char *) alloca (size
);
706 ptr
= buffer
+ offset
;
709 ptr
+= copy_text (SDATA (name
), ptr
, nbytes
,
710 STRING_MULTIBYTE (name
), 1);
713 if ((NILP (echo_string
) || SCHARS (echo_string
) == 0)
716 const char *text
= " (Type ? for further options)";
717 int len
= strlen (text
);
719 if (size
- (ptr
- buffer
) < len
)
721 int offset
= ptr
- buffer
;
723 buffer
= (char *) alloca (size
);
724 ptr
= buffer
+ offset
;
727 bcopy (text
, ptr
, len
);
731 /* Replace a dash from echo_dash with a space, otherwise
732 add a space at the end as a separator between keys. */
733 if (STRINGP (echo_string
)
734 && SCHARS (echo_string
) > 1)
736 Lisp_Object last_char
, prev_char
, idx
;
738 idx
= make_number (SCHARS (echo_string
) - 2);
739 prev_char
= Faref (echo_string
, idx
);
741 idx
= make_number (SCHARS (echo_string
) - 1);
742 last_char
= Faref (echo_string
, idx
);
744 /* We test PREV_CHAR to make sure this isn't the echoing
746 if (XINT (last_char
) == '-' && XINT (prev_char
) != ' ')
747 Faset (echo_string
, idx
, make_number (' '));
749 echo_string
= concat2 (echo_string
, build_string (" "));
751 else if (STRINGP (echo_string
))
752 echo_string
= concat2 (echo_string
, build_string (" "));
754 current_kboard
->echo_string
755 = concat2 (echo_string
, make_string (buffer
, ptr
- buffer
));
761 /* Temporarily add a dash to the end of the echo string if it's not
762 empty, so that it serves as a mini-prompt for the very next character. */
767 /* Do nothing if not echoing at all. */
768 if (NILP (current_kboard
->echo_string
))
771 if (!current_kboard
->immediate_echo
772 && SCHARS (current_kboard
->echo_string
) == 0)
775 /* Do nothing if we just printed a prompt. */
776 if (current_kboard
->echo_after_prompt
777 == SCHARS (current_kboard
->echo_string
))
780 /* Do nothing if we have already put a dash at the end. */
781 if (SCHARS (current_kboard
->echo_string
) > 1)
783 Lisp_Object last_char
, prev_char
, idx
;
785 idx
= make_number (SCHARS (current_kboard
->echo_string
) - 2);
786 prev_char
= Faref (current_kboard
->echo_string
, idx
);
788 idx
= make_number (SCHARS (current_kboard
->echo_string
) - 1);
789 last_char
= Faref (current_kboard
->echo_string
, idx
);
791 if (XINT (last_char
) == '-' && XINT (prev_char
) != ' ')
795 /* Put a dash at the end of the buffer temporarily,
796 but make it go away when the next character is added. */
797 current_kboard
->echo_string
= concat2 (current_kboard
->echo_string
,
802 /* Display the current echo string, and begin echoing if not already
808 if (!current_kboard
->immediate_echo
)
811 current_kboard
->immediate_echo
= 1;
813 for (i
= 0; i
< this_command_key_count
; i
++)
817 /* Set before_command_echo_length to the value that would
818 have been saved before the start of this subcommand in
819 command_loop_1, if we had already been echoing then. */
820 if (i
== this_single_command_key_start
)
821 before_command_echo_length
= echo_length ();
823 c
= XVECTOR (this_command_keys
)->contents
[i
];
824 if (! (EVENT_HAS_PARAMETERS (c
)
825 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
829 /* Set before_command_echo_length to the value that would
830 have been saved before the start of this subcommand in
831 command_loop_1, if we had already been echoing then. */
832 if (this_command_key_count
== this_single_command_key_start
)
833 before_command_echo_length
= echo_length ();
835 /* Put a dash at the end to invite the user to type more. */
840 message3_nolog (current_kboard
->echo_string
,
841 SBYTES (current_kboard
->echo_string
),
842 STRING_MULTIBYTE (current_kboard
->echo_string
));
845 /* Record in what buffer we echoed, and from which kboard. */
846 echo_message_buffer
= echo_area_buffer
[0];
847 echo_kboard
= current_kboard
;
849 if (waiting_for_input
&& !NILP (Vquit_flag
))
850 quit_throw_to_read_char ();
853 /* Turn off echoing, for the start of a new command. */
858 current_kboard
->immediate_echo
= 0;
859 current_kboard
->echo_after_prompt
= -1;
860 current_kboard
->echo_string
= Qnil
;
861 ok_to_echo_at_next_pause
= NULL
;
863 echo_message_buffer
= Qnil
;
866 /* Return the length of the current echo string. */
871 return (STRINGP (current_kboard
->echo_string
)
872 ? SCHARS (current_kboard
->echo_string
)
876 /* Truncate the current echo message to its first LEN chars.
877 This and echo_char get used by read_key_sequence when the user
878 switches frames while entering a key sequence. */
881 echo_truncate (nchars
)
884 if (STRINGP (current_kboard
->echo_string
))
885 current_kboard
->echo_string
886 = Fsubstring (current_kboard
->echo_string
,
887 make_number (0), make_number (nchars
));
888 truncate_echo_area (nchars
);
892 /* Functions for manipulating this_command_keys. */
894 add_command_key (key
)
897 #if 0 /* Not needed after we made Freset_this_command_lengths
898 do the job immediately. */
899 /* If reset-this-command-length was called recently, obey it now.
900 See the doc string of that function for an explanation of why. */
901 if (before_command_restore_flag
)
903 this_command_key_count
= before_command_key_count_1
;
904 if (this_command_key_count
< this_single_command_key_start
)
905 this_single_command_key_start
= this_command_key_count
;
906 echo_truncate (before_command_echo_length_1
);
907 before_command_restore_flag
= 0;
911 if (this_command_key_count
>= ASIZE (this_command_keys
))
912 this_command_keys
= larger_vector (this_command_keys
,
913 2 * ASIZE (this_command_keys
),
916 ASET (this_command_keys
, this_command_key_count
, key
);
917 ++this_command_key_count
;
924 int count
= SPECPDL_INDEX ();
927 if (command_loop_level
> 0)
929 specbind (Qstandard_output
, Qt
);
930 specbind (Qstandard_input
, Qt
);
933 #ifdef HAVE_WINDOW_SYSTEM
934 /* The command loop has started an hourglass timer, so we have to
935 cancel it here, otherwise it will fire because the recursive edit
936 can take some time. Do not check for display_hourglass_p here,
937 because it could already be nil. */
941 /* This function may have been called from a debugger called from
942 within redisplay, for instance by Edebugging a function called
943 from fontification-functions. We want to allow redisplay in
944 the debugging session.
946 The recursive edit is left with a `(throw exit ...)'. The `exit'
947 tag is not caught anywhere in redisplay, i.e. when we leave the
948 recursive edit, the original redisplay leading to the recursive
949 edit will be unwound. The outcome should therefore be safe. */
950 specbind (Qinhibit_redisplay
, Qnil
);
953 val
= command_loop ();
955 Fsignal (Qquit
, Qnil
);
956 /* Handle throw from read_minibuf when using minibuffer
957 while it's active but we're in another window. */
959 xsignal1 (Qerror
, val
);
961 return unbind_to (count
, Qnil
);
964 /* When an auto-save happens, record the "time", and don't do again soon. */
969 last_auto_save
= num_nonmacro_input_events
;
972 /* Make an auto save happen as soon as possible at command level. */
975 force_auto_save_soon ()
977 last_auto_save
= - auto_save_interval
- 1;
979 record_asynch_buffer_change ();
982 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
983 doc
: /* Invoke the editor command loop recursively.
984 To get out of the recursive edit, a command can do `(throw 'exit nil)';
985 that tells this function to return.
986 Alternatively, `(throw 'exit t)' makes this function signal an error.
987 This function is called by the editor initialization to begin editing. */)
990 int count
= SPECPDL_INDEX ();
993 /* If we enter while input is blocked, don't lock up here.
994 This may happen through the debugger during redisplay. */
998 command_loop_level
++;
999 update_mode_lines
= 1;
1001 if (command_loop_level
1002 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
1003 buffer
= Fcurrent_buffer ();
1007 /* If we leave recursive_edit_1 below with a `throw' for instance,
1008 like it is done in the splash screen display, we have to
1009 make sure that we restore single_kboard as command_loop_1
1010 would have done if it were left normally. */
1011 if (command_loop_level
> 0)
1012 temporarily_switch_to_single_kboard (SELECTED_FRAME ());
1013 record_unwind_protect (recursive_edit_unwind
, buffer
);
1015 recursive_edit_1 ();
1016 return unbind_to (count
, Qnil
);
1020 recursive_edit_unwind (buffer
)
1023 if (BUFFERP (buffer
))
1024 Fset_buffer (buffer
);
1026 command_loop_level
--;
1027 update_mode_lines
= 1;
1032 #if 0 /* These two functions are now replaced with
1033 temporarily_switch_to_single_kboard. */
1037 #if 0 /* Theory: if there's anything in Vunread_command_events,
1038 it will right away be read by read_key_sequence,
1039 and then if we do switch KBOARDS, it will go into the side
1040 queue then. So we don't need to do anything special here -- rms. */
1041 if (CONSP (Vunread_command_events
))
1043 current_kboard
->kbd_queue
1044 = nconc2 (Vunread_command_events
, current_kboard
->kbd_queue
);
1045 current_kboard
->kbd_queue_has_data
= 1;
1047 Vunread_command_events
= Qnil
;
1052 /* Switch to the single-kboard state, making current_kboard
1053 the only KBOARD from which further input is accepted. */
1056 single_kboard_state ()
1062 /* If we're in single_kboard state for kboard KBOARD,
1066 not_single_kboard_state (kboard
)
1069 if (kboard
== current_kboard
)
1073 /* Maintain a stack of kboards, so other parts of Emacs
1074 can switch temporarily to the kboard of a given frame
1075 and then revert to the previous status. */
1080 struct kboard_stack
*next
;
1083 static struct kboard_stack
*kboard_stack
;
1089 struct kboard_stack
*p
1090 = (struct kboard_stack
*) xmalloc (sizeof (struct kboard_stack
));
1092 p
->next
= kboard_stack
;
1093 p
->kboard
= current_kboard
;
1103 struct kboard_stack
*p
= kboard_stack
;
1105 for (t
= terminal_list
; t
; t
= t
->next_terminal
)
1107 if (t
->kboard
== p
->kboard
)
1109 current_kboard
= p
->kboard
;
1116 /* The terminal we remembered has been deleted. */
1117 current_kboard
= FRAME_KBOARD (SELECTED_FRAME ());
1120 kboard_stack
= p
->next
;
1124 /* Switch to single_kboard mode, making current_kboard the only KBOARD
1125 from which further input is accepted. If F is non-nil, set its
1126 KBOARD as the current keyboard.
1128 This function uses record_unwind_protect to return to the previous
1131 If Emacs is already in single_kboard mode, and F's keyboard is
1132 locked, then this function will throw an errow. */
1135 temporarily_switch_to_single_kboard (f
)
1138 int was_locked
= single_kboard
;
1141 if (f
!= NULL
&& FRAME_KBOARD (f
) != current_kboard
)
1142 /* We can not switch keyboards while in single_kboard mode.
1143 In rare cases, Lisp code may call `recursive-edit' (or
1144 `read-minibuffer' or `y-or-n-p') after it switched to a
1145 locked frame. For example, this is likely to happen
1146 when server.el connects to a new terminal while Emacs is in
1147 single_kboard mode. It is best to throw an error instead
1148 of presenting the user with a frozen screen. */
1149 error ("Terminal %d is locked, cannot read from it",
1150 FRAME_TERMINAL (f
)->id
);
1152 /* This call is unnecessary, but helps
1153 `restore_kboard_configuration' discover if somebody changed
1154 `current_kboard' behind our back. */
1155 push_kboard (current_kboard
);
1158 current_kboard
= FRAME_KBOARD (f
);
1160 record_unwind_protect (restore_kboard_configuration
,
1161 (was_locked
? Qt
: Qnil
));
1164 #if 0 /* This function is not needed anymore. */
1166 record_single_kboard_state ()
1169 push_kboard (current_kboard
);
1170 record_unwind_protect (restore_kboard_configuration
,
1171 (single_kboard
? Qt
: Qnil
));
1176 restore_kboard_configuration (was_locked
)
1177 Lisp_Object was_locked
;
1179 if (NILP (was_locked
))
1183 struct kboard
*prev
= current_kboard
;
1186 /* The pop should not change the kboard. */
1187 if (single_kboard
&& current_kboard
!= prev
)
1194 /* Handle errors that are not handled at inner levels
1195 by printing an error message and returning to the editor command loop. */
1201 Lisp_Object old_level
, old_length
;
1202 char macroerror
[50];
1204 #ifdef HAVE_WINDOW_SYSTEM
1205 if (display_hourglass_p
)
1206 cancel_hourglass ();
1209 if (!NILP (executing_kbd_macro
))
1211 if (executing_kbd_macro_iterations
== 1)
1212 sprintf (macroerror
, "After 1 kbd macro iteration: ");
1214 sprintf (macroerror
, "After %d kbd macro iterations: ",
1215 executing_kbd_macro_iterations
);
1220 Vstandard_output
= Qt
;
1221 Vstandard_input
= Qt
;
1222 Vexecuting_kbd_macro
= Qnil
;
1223 executing_kbd_macro
= Qnil
;
1224 current_kboard
->Vprefix_arg
= Qnil
;
1225 current_kboard
->Vlast_prefix_arg
= Qnil
;
1228 /* Avoid unquittable loop if data contains a circular list. */
1229 old_level
= Vprint_level
;
1230 old_length
= Vprint_length
;
1231 XSETFASTINT (Vprint_level
, 10);
1232 XSETFASTINT (Vprint_length
, 10);
1233 cmd_error_internal (data
, macroerror
);
1234 Vprint_level
= old_level
;
1235 Vprint_length
= old_length
;
1239 Vinhibit_quit
= Qnil
;
1240 #if 0 /* This shouldn't be necessary anymore. --lorentey */
1241 if (command_loop_level
== 0 && minibuf_level
== 0)
1242 any_kboard_state ();
1245 return make_number (0);
1248 /* Take actions on handling an error. DATA is the data that describes
1251 CONTEXT is a C-string containing ASCII characters only which
1252 describes the context in which the error happened. If we need to
1253 generalize CONTEXT to allow multibyte characters, make it a Lisp
1257 cmd_error_internal (data
, context
)
1261 struct frame
*sf
= SELECTED_FRAME ();
1263 /* The immediate context is not interesting for Quits,
1264 since they are asyncronous. */
1265 if (EQ (XCAR (data
), Qquit
))
1266 Vsignaling_function
= Qnil
;
1271 /* Use user's specified output function if any. */
1272 if (!NILP (Vcommand_error_function
))
1273 call3 (Vcommand_error_function
, data
,
1274 context
? build_string (context
) : empty_unibyte_string
,
1275 Vsignaling_function
);
1276 /* If the window system or terminal frame hasn't been initialized
1277 yet, or we're not interactive, write the message to stderr and exit. */
1278 else if (!sf
->glyphs_initialized_p
1279 /* The initial frame is a special non-displaying frame. It
1280 will be current in daemon mode when there are no frames
1281 to display, and in non-daemon mode before the real frame
1282 has finished initializing. If an error is thrown in the
1283 latter case while creating the frame, then the frame
1284 will never be displayed, so the safest thing to do is
1285 write to stderr and quit. In daemon mode, there are
1286 many other potential errors that do not prevent frames
1287 from being created, so continuing as normal is better in
1289 || (!IS_DAEMON
&& FRAME_INITIAL_P (sf
))
1292 print_error_message (data
, Qexternal_debugging_output
,
1293 context
, Vsignaling_function
);
1294 Fterpri (Qexternal_debugging_output
);
1295 Fkill_emacs (make_number (-1));
1299 clear_message (1, 0);
1301 message_log_maybe_newline ();
1304 print_error_message (data
, Qt
, context
, Vsignaling_function
);
1307 Vsignaling_function
= Qnil
;
1310 Lisp_Object
command_loop_1 ();
1311 Lisp_Object
command_loop_2 ();
1312 Lisp_Object
top_level_1 ();
1314 /* Entry to editor-command-loop.
1315 This level has the catches for exiting/returning to editor command loop.
1316 It returns nil to exit recursive edit, t to abort it. */
1321 if (command_loop_level
> 0 || minibuf_level
> 0)
1324 val
= internal_catch (Qexit
, command_loop_2
, Qnil
);
1325 executing_kbd_macro
= Qnil
;
1331 internal_catch (Qtop_level
, top_level_1
, Qnil
);
1332 #if 0 /* This shouldn't be necessary anymore. --lorentey */
1333 /* Reset single_kboard in case top-level set it while
1334 evaluating an -f option, or we are stuck there for some
1336 any_kboard_state ();
1338 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
1339 executing_kbd_macro
= Qnil
;
1341 /* End of file in -batch run causes exit here. */
1347 /* Here we catch errors in execution of commands within the
1348 editing loop, and reenter the editing loop.
1349 When there is an error, cmd_error runs and returns a non-nil
1350 value to us. A value of nil means that command_loop_1 itself
1351 returned due to end of file (or end of kbd macro). */
1356 register Lisp_Object val
;
1359 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
1360 while (!NILP (val
));
1368 return Feval (Vtop_level
);
1374 /* On entry to the outer level, run the startup file */
1375 if (!NILP (Vtop_level
))
1376 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
1377 else if (!NILP (Vpurify_flag
))
1378 message ("Bare impure Emacs (standard Lisp code not loaded)");
1380 message ("Bare Emacs (standard Lisp code not loaded)");
1384 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
1385 doc
: /* Exit all recursive editing levels.
1386 This also exits all active minibuffers. */)
1389 #ifdef HAVE_WINDOW_SYSTEM
1390 if (display_hourglass_p
)
1391 cancel_hourglass ();
1394 /* Unblock input if we enter with input blocked. This may happen if
1395 redisplay traps e.g. during tool-bar update with input blocked. */
1396 while (INPUT_BLOCKED_P
)
1399 return Fthrow (Qtop_level
, Qnil
);
1402 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
1403 doc
: /* Exit from the innermost recursive edit or minibuffer. */)
1406 if (command_loop_level
> 0 || minibuf_level
> 0)
1407 Fthrow (Qexit
, Qnil
);
1409 error ("No recursive edit is in progress");
1413 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
1414 doc
: /* Abort the command that requested this recursive edit or minibuffer input. */)
1417 if (command_loop_level
> 0 || minibuf_level
> 0)
1420 error ("No recursive edit is in progress");
1424 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1426 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
1427 of this function. */
1430 tracking_off (old_value
)
1431 Lisp_Object old_value
;
1433 do_mouse_tracking
= old_value
;
1434 if (NILP (old_value
))
1436 /* Redisplay may have been preempted because there was input
1437 available, and it assumes it will be called again after the
1438 input has been processed. If the only input available was
1439 the sort that we have just disabled, then we need to call
1441 if (!readable_events (READABLE_EVENTS_DO_TIMERS_NOW
))
1443 redisplay_preserve_echo_area (6);
1444 get_input_pending (&input_pending
,
1445 READABLE_EVENTS_DO_TIMERS_NOW
);
1451 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
1452 doc
: /* Evaluate BODY with mouse movement events enabled.
1453 Within a `track-mouse' form, mouse motion generates input events that
1454 you can read with `read-event'.
1455 Normally, mouse motion is ignored.
1456 usage: (track-mouse BODY...) */)
1460 int count
= SPECPDL_INDEX ();
1463 record_unwind_protect (tracking_off
, do_mouse_tracking
);
1465 do_mouse_tracking
= Qt
;
1467 val
= Fprogn (args
);
1468 return unbind_to (count
, val
);
1471 /* If mouse has moved on some frame, return one of those frames.
1475 If ignore_mouse_drag_p is non-zero, ignore (implicit) mouse movement
1476 after resizing the tool-bar window. */
1478 int ignore_mouse_drag_p
;
1483 Lisp_Object tail
, frame
;
1485 if (ignore_mouse_drag_p
)
1487 /* ignore_mouse_drag_p = 0; */
1491 FOR_EACH_FRAME (tail
, frame
)
1493 if (XFRAME (frame
)->mouse_moved
)
1494 return XFRAME (frame
);
1500 #endif /* HAVE_MOUSE || HAVE_GPM */
1502 /* This is the actual command reading loop,
1503 sans error-handling encapsulation. */
1505 static int read_key_sequence
P_ ((Lisp_Object
*, int, Lisp_Object
,
1507 void safe_run_hooks
P_ ((Lisp_Object
));
1508 static void adjust_point_for_property
P_ ((int, int));
1510 /* Cancel hourglass from protect_unwind.
1512 #ifdef HAVE_WINDOW_SYSTEM
1514 cancel_hourglass_unwind (arg
)
1517 cancel_hourglass ();
1522 extern int nonundocount
; /* Declared in cmds.c. */
1529 Lisp_Object keybuf
[30];
1531 int prev_modiff
= 0;
1532 struct buffer
*prev_buffer
= NULL
;
1533 #if 0 /* This shouldn't be necessary anymore. --lorentey */
1534 int was_locked
= single_kboard
;
1536 int already_adjusted
= 0;
1538 current_kboard
->Vprefix_arg
= Qnil
;
1539 current_kboard
->Vlast_prefix_arg
= Qnil
;
1540 Vdeactivate_mark
= Qnil
;
1541 waiting_for_input
= 0;
1544 this_command_key_count
= 0;
1545 this_command_key_count_reset
= 0;
1546 this_single_command_key_start
= 0;
1548 if (NILP (Vmemory_full
))
1550 /* Make sure this hook runs after commands that get errors and
1551 throw to top level. */
1552 /* Note that the value cell will never directly contain nil
1553 if the symbol is a local variable. */
1554 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1555 safe_run_hooks (Qpost_command_hook
);
1557 /* If displaying a message, resize the echo area window to fit
1558 that message's size exactly. */
1559 if (!NILP (echo_area_buffer
[0]))
1560 resize_echo_area_exactly ();
1562 if (!NILP (Vdeferred_action_list
))
1563 safe_run_hooks (Qdeferred_action_function
);
1566 /* Do this after running Vpost_command_hook, for consistency. */
1567 current_kboard
->Vlast_command
= Vthis_command
;
1568 current_kboard
->Vreal_last_command
= real_this_command
;
1569 if (!CONSP (last_command_event
))
1570 current_kboard
->Vlast_repeatable_command
= real_this_command
;
1574 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
1577 /* Make sure the current window's buffer is selected. */
1578 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1579 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1581 /* Display any malloc warning that just came out. Use while because
1582 displaying one warning can cause another. */
1584 while (pending_malloc_warning
)
1585 display_malloc_warning ();
1587 Vdeactivate_mark
= Qnil
;
1589 /* If minibuffer on and echo area in use,
1590 wait a short time and redraw minibuffer. */
1593 && !NILP (echo_area_buffer
[0])
1594 && EQ (minibuf_window
, echo_area_window
)
1595 && NUMBERP (Vminibuffer_message_timeout
))
1597 /* Bind inhibit-quit to t so that C-g gets read in
1598 rather than quitting back to the minibuffer. */
1599 int count
= SPECPDL_INDEX ();
1600 specbind (Qinhibit_quit
, Qt
);
1602 sit_for (Vminibuffer_message_timeout
, 0, 2);
1604 /* Clear the echo area. */
1606 safe_run_hooks (Qecho_area_clear_hook
);
1608 unbind_to (count
, Qnil
);
1610 /* If a C-g came in before, treat it as input now. */
1611 if (!NILP (Vquit_flag
))
1614 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1619 /* Select the frame that the last event came from. Usually,
1620 switch-frame events will take care of this, but if some lisp
1621 code swallows a switch-frame event, we'll fix things up here.
1622 Is this a good idea? */
1623 if (FRAMEP (internal_last_event_frame
)
1624 && !EQ (internal_last_event_frame
, selected_frame
))
1625 Fselect_frame (internal_last_event_frame
, Qnil
);
1627 /* If it has changed current-menubar from previous value,
1628 really recompute the menubar from the value. */
1629 if (! NILP (Vlucid_menu_bar_dirty_flag
)
1630 && !NILP (Ffboundp (Qrecompute_lucid_menubar
)))
1631 call0 (Qrecompute_lucid_menubar
);
1633 before_command_key_count
= this_command_key_count
;
1634 before_command_echo_length
= echo_length ();
1636 Vthis_command
= Qnil
;
1637 real_this_command
= Qnil
;
1638 Vthis_original_command
= Qnil
;
1639 Vthis_command_keys_shift_translated
= Qnil
;
1641 /* Read next key sequence; i gets its length. */
1642 i
= read_key_sequence (keybuf
, sizeof keybuf
/ sizeof keybuf
[0],
1645 /* A filter may have run while we were reading the input. */
1646 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
1648 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1649 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1653 /* Now we have read a key sequence of length I,
1654 or else I is 0 and we found end of file. */
1656 if (i
== 0) /* End of file -- happens only in */
1657 return Qnil
; /* a kbd macro, at the end. */
1658 /* -1 means read_key_sequence got a menu that was rejected.
1659 Just loop around and read another command. */
1663 this_command_key_count
= 0;
1664 this_command_key_count_reset
= 0;
1665 this_single_command_key_start
= 0;
1669 last_command_event
= keybuf
[i
- 1];
1671 /* If the previous command tried to force a specific window-start,
1672 forget about that, in case this command moves point far away
1673 from that position. But also throw away beg_unchanged and
1674 end_unchanged information in that case, so that redisplay will
1675 update the whole window properly. */
1676 if (!NILP (XWINDOW (selected_window
)->force_start
))
1679 XWINDOW (selected_window
)->force_start
= Qnil
;
1680 b
= XBUFFER (XWINDOW (selected_window
)->buffer
);
1681 BUF_BEG_UNCHANGED (b
) = BUF_END_UNCHANGED (b
) = 0;
1684 cmd
= read_key_sequence_cmd
;
1685 if (!NILP (Vexecuting_kbd_macro
))
1687 if (!NILP (Vquit_flag
))
1689 Vexecuting_kbd_macro
= Qt
;
1690 QUIT
; /* Make some noise. */
1691 /* Will return since macro now empty. */
1695 /* Do redisplay processing after this command except in special
1696 cases identified below. */
1697 prev_buffer
= current_buffer
;
1698 prev_modiff
= MODIFF
;
1699 last_point_position
= PT
;
1700 last_point_position_window
= selected_window
;
1701 XSETBUFFER (last_point_position_buffer
, prev_buffer
);
1703 /* By default, we adjust point to a boundary of a region that
1704 has such a property that should be treated intangible
1705 (e.g. composition, display). But, some commands will set
1706 this variable differently. */
1707 Vdisable_point_adjustment
= Qnil
;
1709 /* Process filters and timers may have messed with deactivate-mark.
1710 reset it before we execute the command. */
1711 Vdeactivate_mark
= Qnil
;
1713 /* Remap command through active keymaps */
1714 Vthis_original_command
= cmd
;
1718 if (cmd1
= Fcommand_remapping (cmd
, Qnil
, Qnil
), !NILP (cmd1
))
1722 /* Execute the command. */
1724 Vthis_command
= cmd
;
1725 real_this_command
= cmd
;
1726 /* Note that the value cell will never directly contain nil
1727 if the symbol is a local variable. */
1728 if (!NILP (Vpre_command_hook
) && !NILP (Vrun_hooks
))
1729 safe_run_hooks (Qpre_command_hook
);
1731 already_adjusted
= 0;
1733 if (NILP (Vthis_command
))
1735 /* nil means key is undefined. */
1736 Lisp_Object keys
= Fvector (i
, keybuf
);
1737 keys
= Fkey_description (keys
, Qnil
);
1739 message_with_string ("%s is undefined", keys
, 0);
1740 current_kboard
->defining_kbd_macro
= Qnil
;
1741 update_mode_lines
= 1;
1742 current_kboard
->Vprefix_arg
= Qnil
;
1746 if (NILP (current_kboard
->Vprefix_arg
))
1748 /* In case we jump to directly_done. */
1749 Vcurrent_prefix_arg
= current_kboard
->Vprefix_arg
;
1751 /* Recognize some common commands in common situations and
1752 do them directly. */
1753 if (EQ (Vthis_command
, Qforward_char
) && PT
< ZV
1754 && NILP (Vthis_command_keys_shift_translated
)
1755 && !CONSP (Vtransient_mark_mode
))
1757 struct Lisp_Char_Table
*dp
1758 = window_display_table (XWINDOW (selected_window
));
1759 lose
= FETCH_CHAR (PT_BYTE
);
1761 if (! NILP (Vpost_command_hook
))
1762 /* Put this before calling adjust_point_for_property
1763 so it will only get called once in any case. */
1765 if (current_buffer
== prev_buffer
1766 && last_point_position
!= PT
1767 && NILP (Vdisable_point_adjustment
)
1768 && NILP (Vglobal_disable_point_adjustment
))
1769 adjust_point_for_property (last_point_position
, 0);
1770 already_adjusted
= 1;
1771 if (PT
== last_point_position
+ 1
1773 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1774 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1775 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1776 && (lose
>= 0x20 && lose
< 0x7f)))
1777 : (lose
>= 0x20 && lose
< 0x7f))
1778 /* To extract the case of continuation on
1779 wide-column characters. */
1780 && ASCII_BYTE_P (lose
)
1781 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1783 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1785 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1787 && !windows_or_buffers_changed
1788 && EQ (current_buffer
->selective_display
, Qnil
)
1789 && !detect_input_pending ()
1790 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1791 && NILP (Vexecuting_kbd_macro
))
1792 direct_output_forward_char (1);
1795 else if (EQ (Vthis_command
, Qbackward_char
) && PT
> BEGV
1796 && NILP (Vthis_command_keys_shift_translated
)
1797 && !CONSP (Vtransient_mark_mode
))
1799 struct Lisp_Char_Table
*dp
1800 = window_display_table (XWINDOW (selected_window
));
1802 lose
= FETCH_CHAR (PT_BYTE
);
1803 if (! NILP (Vpost_command_hook
))
1805 if (current_buffer
== prev_buffer
1806 && last_point_position
!= PT
1807 && NILP (Vdisable_point_adjustment
)
1808 && NILP (Vglobal_disable_point_adjustment
))
1809 adjust_point_for_property (last_point_position
, 0);
1810 already_adjusted
= 1;
1811 if (PT
== last_point_position
- 1
1813 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1814 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1815 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1816 && (lose
>= 0x20 && lose
< 0x7f)))
1817 : (lose
>= 0x20 && lose
< 0x7f))
1818 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1820 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1822 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1824 && !windows_or_buffers_changed
1825 && EQ (current_buffer
->selective_display
, Qnil
)
1826 && !detect_input_pending ()
1827 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1828 && NILP (Vexecuting_kbd_macro
))
1829 direct_output_forward_char (-1);
1832 else if (EQ (Vthis_command
, Qself_insert_command
)
1833 /* Try this optimization only on char keystrokes. */
1834 && NATNUMP (last_command_event
)
1835 && CHAR_VALID_P (XFASTINT (last_command_event
), 0))
1838 = translate_char (Vtranslation_table_for_input
,
1839 XFASTINT (last_command_event
));
1841 if (NILP (Vexecuting_kbd_macro
)
1842 && !EQ (minibuf_window
, selected_window
))
1844 if (!nonundocount
|| nonundocount
>= 20)
1852 lose
= ((XFASTINT (XWINDOW (selected_window
)->last_modified
)
1854 || (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1856 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1858 || MODIFF
<= SAVE_MODIFF
1859 || windows_or_buffers_changed
1860 || !EQ (current_buffer
->selective_display
, Qnil
)
1861 || detect_input_pending ()
1862 || !NILP (XWINDOW (selected_window
)->column_number_displayed
)
1863 || !NILP (Vexecuting_kbd_macro
));
1865 value
= internal_self_insert (c
, 0);
1870 frame_make_pointer_invisible ();
1872 if (! NILP (Vpost_command_hook
))
1873 /* Put this before calling adjust_point_for_property
1874 so it will only get called once in any case. */
1877 /* VALUE == 1 when AFTER-CHANGE functions are
1878 installed which is the case most of the time
1879 because FONT-LOCK installs one. */
1880 if (!lose
&& !value
)
1881 direct_output_for_insert (c
);
1886 /* Here for a command that isn't executed directly */
1889 #ifdef HAVE_WINDOW_SYSTEM
1890 int scount
= SPECPDL_INDEX ();
1892 if (display_hourglass_p
1893 && NILP (Vexecuting_kbd_macro
))
1895 record_unwind_protect (cancel_hourglass_unwind
, Qnil
);
1901 if (NILP (current_kboard
->Vprefix_arg
)) /* FIXME: Why? --Stef */
1903 Fcommand_execute (Vthis_command
, Qnil
, Qnil
, Qnil
);
1905 #ifdef HAVE_WINDOW_SYSTEM
1906 /* Do not check display_hourglass_p here, because
1907 Fcommand_execute could change it, but we should cancel
1908 hourglass cursor anyway.
1909 But don't cancel the hourglass within a macro
1910 just because a command in the macro finishes. */
1911 if (NILP (Vexecuting_kbd_macro
))
1912 unbind_to (scount
, Qnil
);
1917 current_kboard
->Vlast_prefix_arg
= Vcurrent_prefix_arg
;
1919 /* Note that the value cell will never directly contain nil
1920 if the symbol is a local variable. */
1921 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1922 safe_run_hooks (Qpost_command_hook
);
1924 /* If displaying a message, resize the echo area window to fit
1925 that message's size exactly. */
1926 if (!NILP (echo_area_buffer
[0]))
1927 resize_echo_area_exactly ();
1929 if (!NILP (Vdeferred_action_list
))
1930 safe_run_hooks (Qdeferred_action_function
);
1932 /* If there is a prefix argument,
1933 1) We don't want Vlast_command to be ``universal-argument''
1934 (that would be dumb), so don't set Vlast_command,
1935 2) we want to leave echoing on so that the prefix will be
1936 echoed as part of this key sequence, so don't call
1938 3) we want to leave this_command_key_count non-zero, so that
1939 read_char will realize that it is re-reading a character, and
1940 not echo it a second time.
1942 If the command didn't actually create a prefix arg,
1943 but is merely a frame event that is transparent to prefix args,
1944 then the above doesn't apply. */
1945 if (NILP (current_kboard
->Vprefix_arg
) || CONSP (last_command_event
))
1947 current_kboard
->Vlast_command
= Vthis_command
;
1948 current_kboard
->Vreal_last_command
= real_this_command
;
1949 if (!CONSP (last_command_event
))
1950 current_kboard
->Vlast_repeatable_command
= real_this_command
;
1952 this_command_key_count
= 0;
1953 this_command_key_count_reset
= 0;
1954 this_single_command_key_start
= 0;
1957 if (!NILP (current_buffer
->mark_active
) && !NILP (Vrun_hooks
))
1959 /* In Emacs 22, setting transient-mark-mode to `only' was a
1960 way of turning it on for just one command. This usage is
1961 obsolete, but support it anyway. */
1962 if (EQ (Vtransient_mark_mode
, Qidentity
))
1963 Vtransient_mark_mode
= Qnil
;
1964 else if (EQ (Vtransient_mark_mode
, Qonly
))
1965 Vtransient_mark_mode
= Qidentity
;
1967 if (!NILP (Vdeactivate_mark
))
1968 call0 (Qdeactivate_mark
);
1969 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
1970 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
1975 if (current_buffer
== prev_buffer
1976 && last_point_position
!= PT
1977 && NILP (Vdisable_point_adjustment
)
1978 && NILP (Vglobal_disable_point_adjustment
))
1980 if (last_point_position
> BEGV
1981 && last_point_position
< ZV
1982 && (composition_adjust_point (last_point_position
,
1983 last_point_position
)
1984 != last_point_position
))
1985 /* The last point was temporarily set within a grapheme
1986 cluster to prevent automatic composition. To recover
1987 the automatic composition, we must update the
1989 windows_or_buffers_changed
++;
1990 if (!already_adjusted
)
1991 adjust_point_for_property (last_point_position
,
1992 MODIFF
!= prev_modiff
);
1995 /* Install chars successfully executed in kbd macro. */
1997 if (!NILP (current_kboard
->defining_kbd_macro
)
1998 && NILP (current_kboard
->Vprefix_arg
))
1999 finalize_kbd_macro_chars ();
2000 #if 0 /* This shouldn't be necessary anymore. --lorentey */
2002 any_kboard_state ();
2007 extern Lisp_Object Qcomposition
, Qdisplay
;
2009 /* Adjust point to a boundary of a region that has such a property
2010 that should be treated intangible. For the moment, we check
2011 `composition', `display' and `invisible' properties.
2012 LAST_PT is the last position of point. */
2014 extern Lisp_Object Qafter_string
, Qbefore_string
;
2015 extern Lisp_Object get_pos_property
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
));
2018 adjust_point_for_property (last_pt
, modified
)
2023 Lisp_Object val
, overlay
, tmp
;
2024 /* When called after buffer modification, we should temporarily
2025 suppress the point adjustment for automatic composition so that a
2026 user can keep inserting another character at point or keep
2027 deleting characters around point. */
2028 int check_composition
= ! modified
, check_display
= 1, check_invisible
= 1;
2031 /* FIXME: cycling is probably not necessary because these properties
2032 can't be usefully combined anyway. */
2033 while (check_composition
|| check_display
|| check_invisible
)
2035 /* FIXME: check `intangible'. */
2036 if (check_composition
2037 && PT
> BEGV
&& PT
< ZV
2038 && (beg
= composition_adjust_point (last_pt
, PT
)) != PT
)
2041 check_display
= check_invisible
= 1;
2043 check_composition
= 0;
2045 && PT
> BEGV
&& PT
< ZV
2046 && !NILP (val
= get_char_property_and_overlay
2047 (make_number (PT
), Qdisplay
, Qnil
, &overlay
))
2048 && display_prop_intangible_p (val
)
2049 && (!OVERLAYP (overlay
)
2050 ? get_property_and_range (PT
, Qdisplay
, &val
, &beg
, &end
, Qnil
)
2051 : (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)),
2052 end
= OVERLAY_POSITION (OVERLAY_END (overlay
))))
2053 && (beg
< PT
/* && end > PT <- It's always the case. */
2054 || (beg
<= PT
&& STRINGP (val
) && SCHARS (val
) == 0)))
2057 SET_PT (PT
< last_pt
2058 ? (STRINGP (val
) && SCHARS (val
) == 0 ? beg
- 1 : beg
)
2060 check_composition
= check_invisible
= 1;
2063 if (check_invisible
&& PT
> BEGV
&& PT
< ZV
)
2065 int inv
, ellipsis
= 0;
2068 /* Find boundaries `beg' and `end' of the invisible area, if any. */
2071 /* FIXME: We should stop if we find a spot between
2072 two runs of `invisible' where inserted text would
2073 be visible. This is important when we have two
2074 invisible boundaries that enclose an area: if the
2075 area is empty, we need this test in order to make
2076 it possible to place point in the middle rather
2077 than skip both boundaries. However, this code
2078 also stops anywhere in a non-sticky text-property,
2079 which breaks (e.g.) Org mode. */
2080 && (val
= get_pos_property (make_number (end
),
2082 TEXT_PROP_MEANS_INVISIBLE (val
))
2084 && !NILP (val
= get_char_property_and_overlay
2085 (make_number (end
), Qinvisible
, Qnil
, &overlay
))
2086 && (inv
= TEXT_PROP_MEANS_INVISIBLE (val
)))
2088 ellipsis
= ellipsis
|| inv
> 1
2089 || (OVERLAYP (overlay
)
2090 && (!NILP (Foverlay_get (overlay
, Qafter_string
))
2091 || !NILP (Foverlay_get (overlay
, Qbefore_string
))));
2092 tmp
= Fnext_single_char_property_change
2093 (make_number (end
), Qinvisible
, Qnil
, Qnil
);
2094 end
= NATNUMP (tmp
) ? XFASTINT (tmp
) : ZV
;
2098 && (val
= get_pos_property (make_number (beg
),
2100 TEXT_PROP_MEANS_INVISIBLE (val
))
2102 && !NILP (val
= get_char_property_and_overlay
2103 (make_number (beg
- 1), Qinvisible
, Qnil
, &overlay
))
2104 && (inv
= TEXT_PROP_MEANS_INVISIBLE (val
)))
2106 ellipsis
= ellipsis
|| inv
> 1
2107 || (OVERLAYP (overlay
)
2108 && (!NILP (Foverlay_get (overlay
, Qafter_string
))
2109 || !NILP (Foverlay_get (overlay
, Qbefore_string
))));
2110 tmp
= Fprevious_single_char_property_change
2111 (make_number (beg
), Qinvisible
, Qnil
, Qnil
);
2112 beg
= NATNUMP (tmp
) ? XFASTINT (tmp
) : BEGV
;
2115 /* Move away from the inside area. */
2116 if (beg
< PT
&& end
> PT
)
2118 SET_PT ((orig_pt
== PT
&& (last_pt
< beg
|| last_pt
> end
))
2119 /* We haven't moved yet (so we don't need to fear
2120 infinite-looping) and we were outside the range
2121 before (so either end of the range still corresponds
2122 to a move in the right direction): pretend we moved
2123 less than we actually did, so that we still have
2124 more freedom below in choosing which end of the range
2126 ? (orig_pt
= -1, PT
< last_pt
? end
: beg
)
2127 /* We either have moved already or the last point
2128 was already in the range: we don't get to choose
2129 which end of the range we have to go to. */
2130 : (PT
< last_pt
? beg
: end
));
2131 check_composition
= check_display
= 1;
2133 #if 0 /* This assertion isn't correct, because SET_PT may end up setting
2134 the point to something other than its argument, due to
2135 point-motion hooks, intangibility, etc. */
2136 xassert (PT
== beg
|| PT
== end
);
2139 /* Pretend the area doesn't exist if the buffer is not
2141 if (!modified
&& !ellipsis
&& beg
< end
)
2143 if (last_pt
== beg
&& PT
== end
&& end
< ZV
)
2144 (check_composition
= check_display
= 1, SET_PT (end
+ 1));
2145 else if (last_pt
== end
&& PT
== beg
&& beg
> BEGV
)
2146 (check_composition
= check_display
= 1, SET_PT (beg
- 1));
2147 else if (PT
== ((PT
< last_pt
) ? beg
: end
))
2148 /* We've already moved as far as we can. Trying to go
2149 to the other end would mean moving backwards and thus
2150 could lead to an infinite loop. */
2152 else if (val
= get_pos_property (make_number (PT
),
2154 TEXT_PROP_MEANS_INVISIBLE (val
)
2155 && (val
= get_pos_property
2156 (make_number (PT
== beg
? end
: beg
),
2158 !TEXT_PROP_MEANS_INVISIBLE (val
)))
2159 (check_composition
= check_display
= 1,
2160 SET_PT (PT
== beg
? end
: beg
));
2163 check_invisible
= 0;
2167 /* Subroutine for safe_run_hooks: run the hook HOOK. */
2170 safe_run_hooks_1 (hook
)
2173 if (NILP (Vrun_hooks
))
2175 return call1 (Vrun_hooks
, Vinhibit_quit
);
2178 /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */
2181 safe_run_hooks_error (data
)
2184 Lisp_Object args
[3];
2185 args
[0] = build_string ("Error in %s: %s");
2186 args
[1] = Vinhibit_quit
;
2189 return Fset (Vinhibit_quit
, Qnil
);
2192 /* If we get an error while running the hook, cause the hook variable
2193 to be nil. Also inhibit quits, so that C-g won't cause the hook
2194 to mysteriously evaporate. */
2197 safe_run_hooks (hook
)
2200 int count
= SPECPDL_INDEX ();
2201 specbind (Qinhibit_quit
, hook
);
2203 internal_condition_case (safe_run_hooks_1
, Qt
, safe_run_hooks_error
);
2205 unbind_to (count
, Qnil
);
2209 /* Number of seconds between polling for input. This is a Lisp
2210 variable that can be bound. */
2212 EMACS_INT polling_period
;
2214 /* Nonzero means polling for input is temporarily suppressed. */
2216 int poll_suppress_count
;
2218 /* Asynchronous timer for polling. */
2220 struct atimer
*poll_timer
;
2223 #ifdef POLL_FOR_INPUT
2225 /* Poll for input, so that we catch a C-g if it comes in. This
2226 function is called from x_make_frame_visible, see comment
2232 /* Tell ns_read_socket() it is being called asynchronously so it can avoid
2233 doing anything dangerous. */
2237 if (interrupt_input_blocked
== 0
2238 && !waiting_for_input
)
2239 read_avail_input (0);
2245 /* Timer callback function for poll_timer. TIMER is equal to
2249 poll_for_input (timer
)
2250 struct atimer
*timer
;
2252 if (poll_suppress_count
== 0)
2255 interrupt_input_pending
= 1;
2256 pending_signals
= 1;
2258 poll_for_input_1 ();
2263 #endif /* POLL_FOR_INPUT */
2265 /* Begin signals to poll for input, if they are appropriate.
2266 This function is called unconditionally from various places. */
2271 #ifdef POLL_FOR_INPUT
2272 /* XXX This condition was (read_socket_hook && !interrupt_input),
2273 but read_socket_hook is not global anymore. Let's pretend that
2275 if (!interrupt_input
)
2277 /* Turn alarm handling on unconditionally. It might have
2278 been turned off in process.c. */
2279 turn_on_atimers (1);
2281 /* If poll timer doesn't exist, are we need one with
2282 a different interval, start a new one. */
2283 if (poll_timer
== NULL
2284 || EMACS_SECS (poll_timer
->interval
) != polling_period
)
2286 EMACS_TIME interval
;
2289 cancel_atimer (poll_timer
);
2291 EMACS_SET_SECS_USECS (interval
, polling_period
, 0);
2292 poll_timer
= start_atimer (ATIMER_CONTINUOUS
, interval
,
2293 poll_for_input
, NULL
);
2296 /* Let the timer's callback function poll for input
2297 if this becomes zero. */
2298 --poll_suppress_count
;
2303 /* Nonzero if we are using polling to handle input asynchronously. */
2306 input_polling_used ()
2308 #ifdef POLL_FOR_INPUT
2309 /* XXX This condition was (read_socket_hook && !interrupt_input),
2310 but read_socket_hook is not global anymore. Let's pretend that
2312 return !interrupt_input
;
2318 /* Turn off polling. */
2323 #ifdef POLL_FOR_INPUT
2324 /* XXX This condition was (read_socket_hook && !interrupt_input),
2325 but read_socket_hook is not global anymore. Let's pretend that
2327 if (!interrupt_input
)
2328 ++poll_suppress_count
;
2332 /* Set the value of poll_suppress_count to COUNT
2333 and start or stop polling accordingly. */
2336 set_poll_suppress_count (count
)
2339 #ifdef POLL_FOR_INPUT
2340 if (count
== 0 && poll_suppress_count
!= 0)
2342 poll_suppress_count
= 1;
2345 else if (count
!= 0 && poll_suppress_count
== 0)
2349 poll_suppress_count
= count
;
2353 /* Bind polling_period to a value at least N.
2354 But don't decrease it. */
2357 bind_polling_period (n
)
2360 #ifdef POLL_FOR_INPUT
2361 int new = polling_period
;
2366 stop_other_atimers (poll_timer
);
2368 specbind (Qpolling_period
, make_number (new));
2369 /* Start a new alarm with the new period. */
2374 /* Apply the control modifier to CHARACTER. */
2380 /* Save the upper bits here. */
2381 int upper
= c
& ~0177;
2383 if (! ASCII_BYTE_P (c
))
2384 return c
|= ctrl_modifier
;
2388 /* Everything in the columns containing the upper-case letters
2389 denotes a control character. */
2390 if (c
>= 0100 && c
< 0140)
2394 /* Set the shift modifier for a control char
2395 made from a shifted letter. But only for letters! */
2396 if (oc
>= 'A' && oc
<= 'Z')
2397 c
|= shift_modifier
;
2400 /* The lower-case letters denote control characters too. */
2401 else if (c
>= 'a' && c
<= 'z')
2404 /* Include the bits for control and shift
2405 only if the basic ASCII code can't indicate them. */
2409 /* Replace the high bits. */
2410 c
|= (upper
& ~ctrl_modifier
);
2415 /* Display the help-echo property of the character after the mouse pointer.
2416 Either show it in the echo area, or call show-help-function to display
2417 it by other means (maybe in a tooltip).
2419 If HELP is nil, that means clear the previous help echo.
2421 If HELP is a string, display that string. If HELP is a function,
2422 call it with OBJECT and POS as arguments; the function should
2423 return a help string or nil for none. For all other types of HELP,
2424 evaluate it to obtain a string.
2426 WINDOW is the window in which the help was generated, if any.
2427 It is nil if not in a window.
2429 If OBJECT is a buffer, POS is the position in the buffer where the
2430 `help-echo' text property was found.
2432 If OBJECT is an overlay, that overlay has a `help-echo' property,
2433 and POS is the position in the overlay's buffer under the mouse.
2435 If OBJECT is a string (an overlay string or a string displayed with
2436 the `display' property). POS is the position in that string under
2439 OK_TO_OVERWRITE_KEYSTROKE_ECHO non-zero means it's okay if the help
2440 echo overwrites a keystroke echo currently displayed in the echo
2443 Note: this function may only be called with HELP nil or a string
2444 from X code running asynchronously. */
2447 show_help_echo (help
, window
, object
, pos
, ok_to_overwrite_keystroke_echo
)
2448 Lisp_Object help
, window
, object
, pos
;
2449 int ok_to_overwrite_keystroke_echo
;
2451 if (!NILP (help
) && !STRINGP (help
))
2453 if (FUNCTIONP (help
))
2455 Lisp_Object args
[4];
2460 help
= safe_call (4, args
);
2463 help
= safe_eval (help
);
2465 if (!STRINGP (help
))
2469 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
2470 if (!noninteractive
&& STRINGP (help
))
2472 /* The mouse-fixup-help-message Lisp function can call
2473 mouse_position_hook, which resets the mouse_moved flags.
2474 This causes trouble if we are trying to read a mouse motion
2475 event (i.e., if we are inside a `track-mouse' form), so we
2476 restore the mouse_moved flag. */
2477 FRAME_PTR f
= NILP (do_mouse_tracking
) ? NULL
: some_mouse_moved ();
2478 help
= call1 (Qmouse_fixup_help_message
, help
);
2484 if (STRINGP (help
) || NILP (help
))
2486 if (!NILP (Vshow_help_function
))
2487 call1 (Vshow_help_function
, help
);
2488 help_echo_showing_p
= STRINGP (help
);
2494 /* Input of single characters from keyboard */
2496 Lisp_Object
print_help ();
2497 static Lisp_Object
kbd_buffer_get_event ();
2498 static void record_char ();
2500 static Lisp_Object help_form_saved_window_configs
;
2502 read_char_help_form_unwind (Lisp_Object arg
)
2504 Lisp_Object window_config
= XCAR (help_form_saved_window_configs
);
2505 help_form_saved_window_configs
= XCDR (help_form_saved_window_configs
);
2506 if (!NILP (window_config
))
2507 Fset_window_configuration (window_config
);
2511 #define STOP_POLLING \
2512 do { if (! polling_stopped_here) stop_polling (); \
2513 polling_stopped_here = 1; } while (0)
2515 #define RESUME_POLLING \
2516 do { if (polling_stopped_here) start_polling (); \
2517 polling_stopped_here = 0; } while (0)
2519 /* read a character from the keyboard; call the redisplay if needed */
2520 /* commandflag 0 means do not do auto-saving, but do do redisplay.
2521 -1 means do not do redisplay, but do do autosaving.
2524 /* The arguments MAPS and NMAPS are for menu prompting.
2525 MAPS is an array of keymaps; NMAPS is the length of MAPS.
2527 PREV_EVENT is the previous input event, or nil if we are reading
2528 the first event of a key sequence (or not reading a key sequence).
2529 If PREV_EVENT is t, that is a "magic" value that says
2530 not to run input methods, but in other respects to act as if
2531 not reading a key sequence.
2533 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
2534 if we used a mouse menu to read the input, or zero otherwise. If
2535 USED_MOUSE_MENU is null, we don't dereference it.
2537 Value is -2 when we find input on another keyboard. A second call
2538 to read_char will read it.
2540 If END_TIME is non-null, it is a pointer to an EMACS_TIME
2541 specifying the maximum time to wait until. If no input arrives by
2542 that time, stop waiting and return nil.
2544 Value is t if we showed a menu and the user rejected it. */
2547 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
, end_time
)
2551 Lisp_Object prev_event
;
2552 int *used_mouse_menu
;
2553 EMACS_TIME
*end_time
;
2555 volatile Lisp_Object c
;
2556 int count
, jmpcount
;
2557 jmp_buf local_getcjmp
;
2559 volatile int key_already_recorded
= 0;
2560 Lisp_Object tem
, save
;
2561 volatile Lisp_Object previous_echo_area_message
;
2562 volatile Lisp_Object also_record
;
2563 volatile int reread
;
2564 struct gcpro gcpro1
, gcpro2
;
2565 int polling_stopped_here
= 0;
2566 struct kboard
*orig_kboard
= current_kboard
;
2570 #if 0 /* This was commented out as part of fixing echo for C-u left. */
2571 before_command_key_count
= this_command_key_count
;
2572 before_command_echo_length
= echo_length ();
2575 previous_echo_area_message
= Qnil
;
2577 GCPRO2 (c
, previous_echo_area_message
);
2582 if (CONSP (Vunread_post_input_method_events
))
2584 c
= XCAR (Vunread_post_input_method_events
);
2585 Vunread_post_input_method_events
2586 = XCDR (Vunread_post_input_method_events
);
2588 /* Undo what read_char_x_menu_prompt did when it unread
2589 additional keys returned by Fx_popup_menu. */
2591 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
)))
2599 if (unread_command_char
!= -1)
2601 XSETINT (c
, unread_command_char
);
2602 unread_command_char
= -1;
2608 if (CONSP (Vunread_command_events
))
2610 int was_disabled
= 0;
2612 c
= XCAR (Vunread_command_events
);
2613 Vunread_command_events
= XCDR (Vunread_command_events
);
2617 /* Undo what sit-for did when it unread additional keys
2618 inside universal-argument. */
2621 && EQ (XCAR (c
), Qt
))
2627 /* Undo what read_char_x_menu_prompt did when it unread
2628 additional keys returned by Fx_popup_menu. */
2630 && EQ (XCDR (c
), Qdisabled
)
2631 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
))))
2637 /* If the queued event is something that used the mouse,
2638 set used_mouse_menu accordingly. */
2640 /* Also check was_disabled so last-nonmenu-event won't return
2641 a bad value when submenus are involved. (Bug#447) */
2642 && (EQ (c
, Qtool_bar
) || EQ (c
, Qmenu_bar
) || was_disabled
))
2643 *used_mouse_menu
= 1;
2645 goto reread_for_input_method
;
2648 if (CONSP (Vunread_input_method_events
))
2650 c
= XCAR (Vunread_input_method_events
);
2651 Vunread_input_method_events
= XCDR (Vunread_input_method_events
);
2653 /* Undo what read_char_x_menu_prompt did when it unread
2654 additional keys returned by Fx_popup_menu. */
2656 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
)))
2660 goto reread_for_input_method
;
2663 this_command_key_count_reset
= 0;
2665 if (!NILP (Vexecuting_kbd_macro
))
2667 /* We set this to Qmacro; since that's not a frame, nobody will
2668 try to switch frames on us, and the selected window will
2671 Since this event came from a macro, it would be misleading to
2672 leave internal_last_event_frame set to wherever the last
2673 real event came from. Normally, a switch-frame event selects
2674 internal_last_event_frame after each command is read, but
2675 events read from a macro should never cause a new frame to be
2677 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
2679 /* Exit the macro if we are at the end.
2680 Also, some things replace the macro with t
2681 to force an early exit. */
2682 if (EQ (Vexecuting_kbd_macro
, Qt
)
2683 || executing_kbd_macro_index
>= XFASTINT (Flength (Vexecuting_kbd_macro
)))
2689 c
= Faref (Vexecuting_kbd_macro
, make_number (executing_kbd_macro_index
));
2690 if (STRINGP (Vexecuting_kbd_macro
)
2691 && (XINT (c
) & 0x80) && (XUINT (c
) <= 0xff))
2692 XSETFASTINT (c
, CHAR_META
| (XINT (c
) & ~0x80));
2694 executing_kbd_macro_index
++;
2699 if (!NILP (unread_switch_frame
))
2701 c
= unread_switch_frame
;
2702 unread_switch_frame
= Qnil
;
2704 /* This event should make it into this_command_keys, and get echoed
2705 again, so we do not set `reread'. */
2709 /* if redisplay was requested */
2710 if (commandflag
>= 0)
2712 int echo_current
= EQ (echo_message_buffer
, echo_area_buffer
[0]);
2714 /* If there is pending input, process any events which are not
2715 user-visible, such as X selection_request events. */
2717 || detect_input_pending_run_timers (0))
2718 swallow_events (0); /* may clear input_pending */
2720 /* Redisplay if no pending input. */
2721 while (!input_pending
)
2723 if (help_echo_showing_p
&& !EQ (selected_window
, minibuf_window
))
2724 redisplay_preserve_echo_area (5);
2729 /* Normal case: no input arrived during redisplay. */
2732 /* Input arrived and pre-empted redisplay.
2733 Process any events which are not user-visible. */
2735 /* If that cleared input_pending, try again to redisplay. */
2738 /* Prevent the redisplay we just did
2739 from messing up echoing of the input after the prompt. */
2740 if (commandflag
== 0 && echo_current
)
2741 echo_message_buffer
= echo_area_buffer
[0];
2745 /* Message turns off echoing unless more keystrokes turn it on again.
2747 The code in 20.x for the condition was
2749 1. echo_area_glyphs && *echo_area_glyphs
2750 2. && echo_area_glyphs != current_kboard->echobuf
2751 3. && ok_to_echo_at_next_pause != echo_area_glyphs
2753 (1) means there's a current message displayed
2755 (2) means it's not the message from echoing from the current
2758 (3) There's only one place in 20.x where ok_to_echo_at_next_pause
2759 is set to a non-null value. This is done in read_char and it is
2760 set to echo_area_glyphs after a call to echo_char. That means
2761 ok_to_echo_at_next_pause is either null or
2762 current_kboard->echobuf with the appropriate current_kboard at
2765 So, condition (3) means in clear text ok_to_echo_at_next_pause
2766 must be either null, or the current message isn't from echoing at
2767 all, or it's from echoing from a different kboard than the
2770 if (/* There currently is something in the echo area. */
2771 !NILP (echo_area_buffer
[0])
2772 && (/* And it's either not from echoing. */
2773 !EQ (echo_area_buffer
[0], echo_message_buffer
)
2774 /* Or it's an echo from a different kboard. */
2775 || echo_kboard
!= current_kboard
2776 /* Or we explicitly allow overwriting whatever there is. */
2777 || ok_to_echo_at_next_pause
== NULL
))
2782 /* Try reading a character via menu prompting in the minibuf.
2783 Try this before the sit-for, because the sit-for
2784 would do the wrong thing if we are supposed to do
2785 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
2786 after a mouse event so don't try a minibuf menu. */
2788 if (nmaps
> 0 && INTERACTIVE
2789 && !NILP (prev_event
) && ! EVENT_HAS_PARAMETERS (prev_event
)
2790 /* Don't bring up a menu if we already have another event. */
2791 && NILP (Vunread_command_events
)
2792 && unread_command_char
< 0
2793 && !detect_input_pending_run_timers (0))
2795 c
= read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
);
2797 if (INTEGERP (c
) && XINT (c
) == -2)
2798 return c
; /* wrong_kboard_jmpbuf */
2802 key_already_recorded
= 1;
2807 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet.
2808 We will do that below, temporarily for short sections of code,
2809 when appropriate. local_getcjmp must be in effect
2810 around any call to sit_for or kbd_buffer_get_event;
2811 it *must not* be in effect when we call redisplay. */
2813 jmpcount
= SPECPDL_INDEX ();
2814 if (_setjmp (local_getcjmp
))
2816 /* Handle quits while reading the keyboard. */
2817 /* We must have saved the outer value of getcjmp here,
2818 so restore it now. */
2819 restore_getcjmp (save_jump
);
2820 unbind_to (jmpcount
, Qnil
);
2821 XSETINT (c
, quit_char
);
2822 internal_last_event_frame
= selected_frame
;
2823 Vlast_event_frame
= internal_last_event_frame
;
2824 /* If we report the quit char as an event,
2825 don't do so more than once. */
2826 if (!NILP (Vinhibit_quit
))
2830 KBOARD
*kb
= FRAME_KBOARD (XFRAME (selected_frame
));
2831 if (kb
!= current_kboard
)
2833 Lisp_Object link
= kb
->kbd_queue
;
2834 /* We shouldn't get here if we were in single-kboard mode! */
2839 while (CONSP (XCDR (link
)))
2841 if (!NILP (XCDR (link
)))
2845 kb
->kbd_queue
= Fcons (c
, Qnil
);
2847 XSETCDR (link
, Fcons (c
, Qnil
));
2848 kb
->kbd_queue_has_data
= 1;
2849 current_kboard
= kb
;
2850 /* This is going to exit from read_char
2851 so we had better get rid of this frame's stuff. */
2853 return make_number (-2); /* wrong_kboard_jmpbuf */
2859 /* Start idle timers if no time limit is supplied. We don't do it
2860 if a time limit is supplied to avoid an infinite recursion in the
2861 situation where an idle timer calls `sit-for'. */
2864 timer_start_idle ();
2866 /* If in middle of key sequence and minibuffer not active,
2867 start echoing if enough time elapses. */
2869 if (minibuf_level
== 0
2871 && !current_kboard
->immediate_echo
2872 && this_command_key_count
> 0
2874 && (FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
2875 && NILP (Fzerop (Vecho_keystrokes
))
2876 && (/* No message. */
2877 NILP (echo_area_buffer
[0])
2878 /* Or empty message. */
2879 || (BUF_BEG (XBUFFER (echo_area_buffer
[0]))
2880 == BUF_Z (XBUFFER (echo_area_buffer
[0])))
2881 /* Or already echoing from same kboard. */
2882 || (echo_kboard
&& ok_to_echo_at_next_pause
== echo_kboard
)
2883 /* Or not echoing before and echoing allowed. */
2884 || (!echo_kboard
&& ok_to_echo_at_next_pause
)))
2886 /* After a mouse event, start echoing right away.
2887 This is because we are probably about to display a menu,
2888 and we don't want to delay before doing so. */
2889 if (EVENT_HAS_PARAMETERS (prev_event
))
2895 save_getcjmp (save_jump
);
2896 restore_getcjmp (local_getcjmp
);
2897 tem0
= sit_for (Vecho_keystrokes
, 1, 1);
2898 restore_getcjmp (save_jump
);
2900 && ! CONSP (Vunread_command_events
))
2905 /* Maybe auto save due to number of keystrokes. */
2907 if (commandflag
!= 0
2908 && auto_save_interval
> 0
2909 && num_nonmacro_input_events
- last_auto_save
> max (auto_save_interval
, 20)
2910 && !detect_input_pending_run_timers (0))
2912 Fdo_auto_save (Qnil
, Qnil
);
2913 /* Hooks can actually change some buffers in auto save. */
2917 /* Try reading using an X menu.
2918 This is never confused with reading using the minibuf
2919 because the recursive call of read_char in read_char_minibuf_menu_prompt
2920 does not pass on any keymaps. */
2922 if (nmaps
> 0 && INTERACTIVE
2923 && !NILP (prev_event
)
2924 && EVENT_HAS_PARAMETERS (prev_event
)
2925 && !EQ (XCAR (prev_event
), Qmenu_bar
)
2926 && !EQ (XCAR (prev_event
), Qtool_bar
)
2927 /* Don't bring up a menu if we already have another event. */
2928 && NILP (Vunread_command_events
)
2929 && unread_command_char
< 0)
2931 c
= read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
2933 /* Now that we have read an event, Emacs is not idle. */
2940 /* Maybe autosave and/or garbage collect due to idleness. */
2942 if (INTERACTIVE
&& NILP (c
))
2944 int delay_level
, buffer_size
;
2946 /* Slow down auto saves logarithmically in size of current buffer,
2947 and garbage collect while we're at it. */
2948 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
2949 last_non_minibuf_size
= Z
- BEG
;
2950 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
2952 while (buffer_size
> 64)
2953 delay_level
++, buffer_size
-= buffer_size
>> 2;
2954 if (delay_level
< 4) delay_level
= 4;
2955 /* delay_level is 4 for files under around 50k, 7 at 100k,
2956 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
2958 /* Auto save if enough time goes by without input. */
2959 if (commandflag
!= 0
2960 && num_nonmacro_input_events
> last_auto_save
2961 && INTEGERP (Vauto_save_timeout
)
2962 && XINT (Vauto_save_timeout
) > 0)
2965 int timeout
= delay_level
* XFASTINT (Vauto_save_timeout
) / 4;
2967 save_getcjmp (save_jump
);
2968 restore_getcjmp (local_getcjmp
);
2969 tem0
= sit_for (make_number (timeout
), 1, 1);
2970 restore_getcjmp (save_jump
);
2973 && ! CONSP (Vunread_command_events
))
2975 Fdo_auto_save (Qnil
, Qnil
);
2977 /* If we have auto-saved and there is still no input
2978 available, garbage collect if there has been enough
2979 consing going on to make it worthwhile. */
2980 if (!detect_input_pending_run_timers (0)
2981 && consing_since_gc
> gc_cons_threshold
/ 2)
2982 Fgarbage_collect ();
2989 /* Notify the caller if an autosave hook, or a timer, sentinel or
2990 filter in the sit_for calls above have changed the current
2991 kboard. This could happen if they use the minibuffer or start a
2992 recursive edit, like the fancy splash screen in server.el's
2993 filter. If this longjmp wasn't here, read_key_sequence would
2994 interpret the next key sequence using the wrong translation
2995 tables and function keymaps. */
2996 if (NILP (c
) && current_kboard
!= orig_kboard
)
2999 return make_number (-2); /* wrong_kboard_jmpbuf */
3002 /* If this has become non-nil here, it has been set by a timer
3003 or sentinel or filter. */
3004 if (CONSP (Vunread_command_events
))
3006 c
= XCAR (Vunread_command_events
);
3007 Vunread_command_events
= XCDR (Vunread_command_events
);
3010 /* Read something from current KBOARD's side queue, if possible. */
3014 if (current_kboard
->kbd_queue_has_data
)
3016 if (!CONSP (current_kboard
->kbd_queue
))
3018 c
= XCAR (current_kboard
->kbd_queue
);
3019 current_kboard
->kbd_queue
3020 = XCDR (current_kboard
->kbd_queue
);
3021 if (NILP (current_kboard
->kbd_queue
))
3022 current_kboard
->kbd_queue_has_data
= 0;
3023 input_pending
= readable_events (0);
3024 if (EVENT_HAS_PARAMETERS (c
)
3025 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qswitch_frame
))
3026 internal_last_event_frame
= XCAR (XCDR (c
));
3027 Vlast_event_frame
= internal_last_event_frame
;
3031 /* If current_kboard's side queue is empty check the other kboards.
3032 If one of them has data that we have not yet seen here,
3033 switch to it and process the data waiting for it.
3035 Note: if the events queued up for another kboard
3036 have already been seen here, and therefore are not a complete command,
3037 the kbd_queue_has_data field is 0, so we skip that kboard here.
3038 That's to avoid an infinite loop switching between kboards here. */
3039 if (NILP (c
) && !single_kboard
)
3042 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
3043 if (kb
->kbd_queue_has_data
)
3045 current_kboard
= kb
;
3046 /* This is going to exit from read_char
3047 so we had better get rid of this frame's stuff. */
3049 return make_number (-2); /* wrong_kboard_jmpbuf */
3057 /* Finally, we read from the main queue,
3058 and if that gives us something we can't use yet, we put it on the
3059 appropriate side queue and try again. */
3068 EMACS_GET_TIME (now
);
3069 if (EMACS_TIME_GE (now
, *end_time
))
3073 /* Actually read a character, waiting if necessary. */
3074 save_getcjmp (save_jump
);
3075 restore_getcjmp (local_getcjmp
);
3077 timer_start_idle ();
3078 c
= kbd_buffer_get_event (&kb
, used_mouse_menu
, end_time
);
3079 restore_getcjmp (save_jump
);
3081 if (! NILP (c
) && (kb
!= current_kboard
))
3083 Lisp_Object link
= kb
->kbd_queue
;
3086 while (CONSP (XCDR (link
)))
3088 if (!NILP (XCDR (link
)))
3092 kb
->kbd_queue
= Fcons (c
, Qnil
);
3094 XSETCDR (link
, Fcons (c
, Qnil
));
3095 kb
->kbd_queue_has_data
= 1;
3099 current_kboard
= kb
;
3100 /* This is going to exit from read_char
3101 so we had better get rid of this frame's stuff. */
3103 return make_number (-2);
3107 /* Terminate Emacs in batch mode if at eof. */
3108 if (noninteractive
&& INTEGERP (c
) && XINT (c
) < 0)
3109 Fkill_emacs (make_number (1));
3113 /* Add in any extra modifiers, where appropriate. */
3114 if ((extra_keyboard_modifiers
& CHAR_CTL
)
3115 || ((extra_keyboard_modifiers
& 0177) < ' '
3116 && (extra_keyboard_modifiers
& 0177) != 0))
3117 XSETINT (c
, make_ctrl_char (XINT (c
)));
3119 /* Transfer any other modifier bits directly from
3120 extra_keyboard_modifiers to c. Ignore the actual character code
3121 in the low 16 bits of extra_keyboard_modifiers. */
3122 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
3133 if (commandflag
>= 0
3134 && !input_pending
&& !detect_input_pending_run_timers (0))
3142 /* Buffer switch events are only for internal wakeups
3143 so don't show them to the user.
3144 Also, don't record a key if we already did. */
3145 if (BUFFERP (c
) || key_already_recorded
)
3148 /* Process special events within read_char
3149 and loop around to read another event. */
3152 tem
= access_keymap (get_keymap (Vspecial_event_map
, 0, 1), c
, 0, 0, 1);
3157 struct buffer
*prev_buffer
= current_buffer
;
3158 #if 0 /* This shouldn't be necessary anymore. --lorentey */
3159 int was_locked
= single_kboard
;
3160 int count
= SPECPDL_INDEX ();
3161 record_single_kboard_state ();
3164 last_input_event
= c
;
3165 Fcommand_execute (tem
, Qnil
, Fvector (1, &last_input_event
), Qt
);
3167 if (CONSP (c
) && EQ (XCAR (c
), Qselect_window
) && !end_time
)
3168 /* We stopped being idle for this event; undo that. This
3169 prevents automatic window selection (under
3170 mouse_autoselect_window from acting as a real input event, for
3171 example banishing the mouse under mouse-avoidance-mode. */
3172 timer_resume_idle ();
3174 #if 0 /* This shouldn't be necessary anymore. --lorentey */
3175 /* Resume allowing input from any kboard, if that was true before. */
3177 any_kboard_state ();
3178 unbind_to (count
, Qnil
);
3181 if (current_buffer
!= prev_buffer
)
3183 /* The command may have changed the keymaps. Pretend there
3184 is input in another keyboard and return. This will
3185 recalculate keymaps. */
3186 c
= make_number (-2);
3193 /* Handle things that only apply to characters. */
3196 /* If kbd_buffer_get_event gave us an EOF, return that. */
3200 if ((STRINGP (current_kboard
->Vkeyboard_translate_table
)
3201 && SCHARS (current_kboard
->Vkeyboard_translate_table
) > (unsigned) XFASTINT (c
))
3202 || (VECTORP (current_kboard
->Vkeyboard_translate_table
)
3203 && XVECTOR (current_kboard
->Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
3204 || (CHAR_TABLE_P (current_kboard
->Vkeyboard_translate_table
)
3208 d
= Faref (current_kboard
->Vkeyboard_translate_table
, c
);
3209 /* nil in keyboard-translate-table means no translation. */
3215 /* If this event is a mouse click in the menu bar,
3216 return just menu-bar for now. Modify the mouse click event
3217 so we won't do this twice, then queue it up. */
3218 if (EVENT_HAS_PARAMETERS (c
)
3220 && CONSP (EVENT_START (c
))
3221 && CONSP (XCDR (EVENT_START (c
))))
3225 posn
= POSN_POSN (EVENT_START (c
));
3226 /* Handle menu-bar events:
3227 insert the dummy prefix event `menu-bar'. */
3228 if (EQ (posn
, Qmenu_bar
) || EQ (posn
, Qtool_bar
))
3230 /* Change menu-bar to (menu-bar) as the event "position". */
3231 POSN_SET_POSN (EVENT_START (c
), Fcons (posn
, Qnil
));
3234 Vunread_command_events
= Fcons (c
, Vunread_command_events
);
3239 /* Store these characters into recent_keys, the dribble file if any,
3240 and the keyboard macro being defined, if any. */
3242 if (! NILP (also_record
))
3243 record_char (also_record
);
3245 /* Wipe the echo area.
3246 But first, if we are about to use an input method,
3247 save the echo area contents for it to refer to. */
3249 && ! NILP (Vinput_method_function
)
3250 && (unsigned) XINT (c
) >= ' '
3251 && (unsigned) XINT (c
) != 127
3252 && (unsigned) XINT (c
) < 256)
3254 previous_echo_area_message
= Fcurrent_message ();
3255 Vinput_method_previous_message
= previous_echo_area_message
;
3258 /* Now wipe the echo area, except for help events which do their
3259 own stuff with the echo area. */
3261 || (!(EQ (Qhelp_echo
, XCAR (c
)))
3262 && !(EQ (Qswitch_frame
, XCAR (c
)))))
3264 if (!NILP (echo_area_buffer
[0]))
3265 safe_run_hooks (Qecho_area_clear_hook
);
3266 clear_message (1, 0);
3269 reread_for_input_method
:
3271 /* Pass this to the input method, if appropriate. */
3273 && ! NILP (Vinput_method_function
)
3274 /* Don't run the input method within a key sequence,
3275 after the first event of the key sequence. */
3276 && NILP (prev_event
)
3277 && (unsigned) XINT (c
) >= ' '
3278 && (unsigned) XINT (c
) != 127
3279 && (unsigned) XINT (c
) < 256)
3282 int key_count
, key_count_reset
;
3283 struct gcpro gcpro1
;
3284 int count
= SPECPDL_INDEX ();
3286 /* Save the echo status. */
3287 int saved_immediate_echo
= current_kboard
->immediate_echo
;
3288 struct kboard
*saved_ok_to_echo
= ok_to_echo_at_next_pause
;
3289 Lisp_Object saved_echo_string
= current_kboard
->echo_string
;
3290 int saved_echo_after_prompt
= current_kboard
->echo_after_prompt
;
3293 if (before_command_restore_flag
)
3295 this_command_key_count
= before_command_key_count_1
;
3296 if (this_command_key_count
< this_single_command_key_start
)
3297 this_single_command_key_start
= this_command_key_count
;
3298 echo_truncate (before_command_echo_length_1
);
3299 before_command_restore_flag
= 0;
3303 /* Save the this_command_keys status. */
3304 key_count
= this_command_key_count
;
3305 key_count_reset
= this_command_key_count_reset
;
3308 keys
= Fcopy_sequence (this_command_keys
);
3313 /* Clear out this_command_keys. */
3314 this_command_key_count
= 0;
3315 this_command_key_count_reset
= 0;
3317 /* Now wipe the echo area. */
3318 if (!NILP (echo_area_buffer
[0]))
3319 safe_run_hooks (Qecho_area_clear_hook
);
3320 clear_message (1, 0);
3323 /* If we are not reading a key sequence,
3324 never use the echo area. */
3327 specbind (Qinput_method_use_echo_area
, Qt
);
3330 /* Call the input method. */
3331 tem
= call1 (Vinput_method_function
, c
);
3333 tem
= unbind_to (count
, tem
);
3335 /* Restore the saved echoing state
3336 and this_command_keys state. */
3337 this_command_key_count
= key_count
;
3338 this_command_key_count_reset
= key_count_reset
;
3340 this_command_keys
= keys
;
3343 ok_to_echo_at_next_pause
= saved_ok_to_echo
;
3344 current_kboard
->echo_string
= saved_echo_string
;
3345 current_kboard
->echo_after_prompt
= saved_echo_after_prompt
;
3346 if (saved_immediate_echo
)
3351 /* The input method can return no events. */
3354 /* Bring back the previous message, if any. */
3355 if (! NILP (previous_echo_area_message
))
3356 message_with_string ("%s", previous_echo_area_message
, 0);
3359 /* It returned one event or more. */
3361 Vunread_post_input_method_events
3362 = nconc2 (XCDR (tem
), Vunread_post_input_method_events
);
3367 /* Display help if not echoing. */
3368 if (CONSP (c
) && EQ (XCAR (c
), Qhelp_echo
))
3370 /* (help-echo FRAME HELP WINDOW OBJECT POS). */
3371 Lisp_Object help
, object
, position
, window
, tem
;
3373 tem
= Fcdr (XCDR (c
));
3376 window
= Fcar (tem
);
3378 object
= Fcar (tem
);
3380 position
= Fcar (tem
);
3382 show_help_echo (help
, window
, object
, position
, 0);
3384 /* We stopped being idle for this event; undo that. */
3386 timer_resume_idle ();
3390 if ((! reread
|| this_command_key_count
== 0
3391 || this_command_key_count_reset
)
3395 /* Don't echo mouse motion events. */
3396 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
3397 && NILP (Fzerop (Vecho_keystrokes
))
3398 && ! (EVENT_HAS_PARAMETERS (c
)
3399 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
3402 if (! NILP (also_record
))
3403 echo_char (also_record
);
3404 /* Once we reread a character, echoing can happen
3405 the next time we pause to read a new one. */
3406 ok_to_echo_at_next_pause
= current_kboard
;
3409 /* Record this character as part of the current key. */
3410 add_command_key (c
);
3411 if (! NILP (also_record
))
3412 add_command_key (also_record
);
3415 last_input_event
= c
;
3418 /* Process the help character specially if enabled */
3419 if (!NILP (Vhelp_form
) && help_char_p (c
))
3422 count
= SPECPDL_INDEX ();
3424 help_form_saved_window_configs
3425 = Fcons (Fcurrent_window_configuration (Qnil
),
3426 help_form_saved_window_configs
);
3427 record_unwind_protect (read_char_help_form_unwind
, Qnil
);
3429 tem0
= Feval (Vhelp_form
);
3431 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
3436 c
= read_char (0, 0, 0, Qnil
, 0, NULL
);
3437 if (EVENT_HAS_PARAMETERS (c
)
3438 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_click
))
3439 XSETCAR (help_form_saved_window_configs
, Qnil
);
3441 while (BUFFERP (c
));
3442 /* Remove the help from the frame */
3443 unbind_to (count
, Qnil
);
3446 if (EQ (c
, make_number (040)))
3450 c
= read_char (0, 0, 0, Qnil
, 0, NULL
);
3451 while (BUFFERP (c
));
3460 /* Record a key that came from a mouse menu.
3461 Record it for echoing, for this-command-keys, and so on. */
3467 /* Wipe the echo area. */
3468 clear_message (1, 0);
3473 before_command_key_count
= this_command_key_count
;
3474 before_command_echo_length
= echo_length ();
3477 /* Don't echo mouse motion events. */
3478 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
3479 && NILP (Fzerop (Vecho_keystrokes
)))
3483 /* Once we reread a character, echoing can happen
3484 the next time we pause to read a new one. */
3485 ok_to_echo_at_next_pause
= 0;
3488 /* Record this character as part of the current key. */
3489 add_command_key (c
);
3491 /* Re-reading in the middle of a command */
3492 last_input_event
= c
;
3496 /* Return 1 if should recognize C as "the help character". */
3504 if (EQ (c
, Vhelp_char
))
3506 for (tail
= Vhelp_event_list
; CONSP (tail
); tail
= XCDR (tail
))
3507 if (EQ (c
, XCAR (tail
)))
3512 /* Record the input event C in various ways. */
3520 if (CONSP (c
) && (EQ (XCAR (c
), Qhelp_echo
) || EQ (XCAR (c
), Qmouse_movement
)))
3522 /* To avoid filling recent_keys with help-echo and mouse-movement
3523 events, we filter out repeated help-echo events, only store the
3524 first and last in a series of mouse-movement events, and don't
3525 store repeated help-echo events which are only separated by
3526 mouse-movement events. */
3528 Lisp_Object ev1
, ev2
, ev3
;
3531 if ((ix1
= recent_keys_index
- 1) < 0)
3532 ix1
= NUM_RECENT_KEYS
- 1;
3533 ev1
= AREF (recent_keys
, ix1
);
3535 if ((ix2
= ix1
- 1) < 0)
3536 ix2
= NUM_RECENT_KEYS
- 1;
3537 ev2
= AREF (recent_keys
, ix2
);
3539 if ((ix3
= ix2
- 1) < 0)
3540 ix3
= NUM_RECENT_KEYS
- 1;
3541 ev3
= AREF (recent_keys
, ix3
);
3543 if (EQ (XCAR (c
), Qhelp_echo
))
3545 /* Don't record `help-echo' in recent_keys unless it shows some help
3546 message, and a different help than the previously recorded
3548 Lisp_Object help
, last_help
;
3550 help
= Fcar_safe (Fcdr_safe (XCDR (c
)));
3551 if (!STRINGP (help
))
3553 else if (CONSP (ev1
) && EQ (XCAR (ev1
), Qhelp_echo
)
3554 && (last_help
= Fcar_safe (Fcdr_safe (XCDR (ev1
))), EQ (last_help
, help
)))
3556 else if (CONSP (ev1
) && EQ (XCAR (ev1
), Qmouse_movement
)
3557 && CONSP (ev2
) && EQ (XCAR (ev2
), Qhelp_echo
)
3558 && (last_help
= Fcar_safe (Fcdr_safe (XCDR (ev2
))), EQ (last_help
, help
)))
3560 else if (CONSP (ev1
) && EQ (XCAR (ev1
), Qmouse_movement
)
3561 && CONSP (ev2
) && EQ (XCAR (ev2
), Qmouse_movement
)
3562 && CONSP (ev3
) && EQ (XCAR (ev3
), Qhelp_echo
)
3563 && (last_help
= Fcar_safe (Fcdr_safe (XCDR (ev3
))), EQ (last_help
, help
)))
3566 else if (EQ (XCAR (c
), Qmouse_movement
))
3568 /* Only record one pair of `mouse-movement' on a window in recent_keys.
3569 So additional mouse movement events replace the last element. */
3570 Lisp_Object last_window
, window
;
3572 window
= Fcar_safe (Fcar_safe (XCDR (c
)));
3573 if (CONSP (ev1
) && EQ (XCAR (ev1
), Qmouse_movement
)
3574 && (last_window
= Fcar_safe (Fcar_safe (XCDR (ev1
))), EQ (last_window
, window
))
3575 && CONSP (ev2
) && EQ (XCAR (ev2
), Qmouse_movement
)
3576 && (last_window
= Fcar_safe (Fcar_safe (XCDR (ev2
))), EQ (last_window
, window
)))
3578 ASET (recent_keys
, ix1
, c
);
3584 store_kbd_macro_char (c
);
3589 ASET (recent_keys
, recent_keys_index
, c
);
3590 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
3591 recent_keys_index
= 0;
3593 else if (recorded
< 0)
3595 /* We need to remove one or two events from recent_keys.
3596 To do this, we simply put nil at those events and move the
3597 recent_keys_index backwards over those events. Usually,
3598 users will never see those nil events, as they will be
3599 overwritten by the command keys entered to see recent_keys
3602 while (recorded
++ < 0 && total_keys
> 0)
3604 if (total_keys
< NUM_RECENT_KEYS
)
3606 if (--recent_keys_index
< 0)
3607 recent_keys_index
= NUM_RECENT_KEYS
- 1;
3608 ASET (recent_keys
, recent_keys_index
, Qnil
);
3612 num_nonmacro_input_events
++;
3614 /* Write c to the dribble file. If c is a lispy event, write
3615 the event's symbol to the dribble file, in <brackets>. Bleaugh.
3616 If you, dear reader, have a better idea, you've got the source. :-) */
3622 if (XUINT (c
) < 0x100)
3623 putc (XINT (c
), dribble
);
3625 fprintf (dribble
, " 0x%x", (int) XUINT (c
));
3629 Lisp_Object dribblee
;
3631 /* If it's a structured event, take the event header. */
3632 dribblee
= EVENT_HEAD (c
);
3634 if (SYMBOLP (dribblee
))
3636 putc ('<', dribble
);
3637 fwrite (SDATA (SYMBOL_NAME (dribblee
)), sizeof (char),
3638 SBYTES (SYMBOL_NAME (dribblee
)),
3640 putc ('>', dribble
);
3653 struct buffer
*old
= current_buffer
;
3654 Fprinc (object
, Qnil
);
3655 set_buffer_internal (XBUFFER (Vstandard_output
));
3656 call0 (intern ("help-mode"));
3657 set_buffer_internal (old
);
3661 /* Copy out or in the info on where C-g should throw to.
3662 This is used when running Lisp code from within get_char,
3663 in case get_char is called recursively.
3664 See read_process_output. */
3670 bcopy (getcjmp
, temp
, sizeof getcjmp
);
3674 restore_getcjmp (temp
)
3677 bcopy (temp
, getcjmp
, sizeof getcjmp
);
3680 /* Low level keyboard/mouse input.
3681 kbd_buffer_store_event places events in kbd_buffer, and
3682 kbd_buffer_get_event retrieves them. */
3684 /* Return true if there are any events in the queue that read-char
3685 would return. If this returns false, a read-char would block. */
3687 readable_events (flags
)
3691 /* Check whether a D-Bus message has arrived. */
3692 if (xd_pending_messages () > 0)
3694 #endif /* HAVE_DBUS */
3696 if (flags
& READABLE_EVENTS_DO_TIMERS_NOW
)
3699 /* If the buffer contains only FOCUS_IN_EVENT events, and
3700 READABLE_EVENTS_FILTER_EVENTS is set, report it as empty. */
3701 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3703 if (flags
& (READABLE_EVENTS_FILTER_EVENTS
3704 #ifdef USE_TOOLKIT_SCROLL_BARS
3705 | READABLE_EVENTS_IGNORE_SQUEEZABLES
3709 struct input_event
*event
;
3711 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
3718 #ifdef USE_TOOLKIT_SCROLL_BARS
3719 (flags
& READABLE_EVENTS_FILTER_EVENTS
) &&
3721 event
->kind
== FOCUS_IN_EVENT
)
3722 #ifdef USE_TOOLKIT_SCROLL_BARS
3723 && !((flags
& READABLE_EVENTS_IGNORE_SQUEEZABLES
)
3724 && event
->kind
== SCROLL_BAR_CLICK_EVENT
3725 && event
->part
== scroll_bar_handle
3726 && event
->modifiers
== 0)
3731 if (event
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3734 while (event
!= kbd_store_ptr
);
3740 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
3741 if (!(flags
& READABLE_EVENTS_IGNORE_SQUEEZABLES
)
3742 && !NILP (do_mouse_tracking
) && some_mouse_moved ())
3747 if (current_kboard
->kbd_queue_has_data
)
3753 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
3754 if (kb
->kbd_queue_has_data
)
3760 /* Set this for debugging, to have a way to get out */
3764 event_to_kboard (event
)
3765 struct input_event
*event
;
3768 frame
= event
->frame_or_window
;
3770 frame
= XCAR (frame
);
3771 else if (WINDOWP (frame
))
3772 frame
= WINDOW_FRAME (XWINDOW (frame
));
3774 /* There are still some events that don't set this field.
3775 For now, just ignore the problem.
3776 Also ignore dead frames here. */
3777 if (!FRAMEP (frame
) || !FRAME_LIVE_P (XFRAME (frame
)))
3780 return FRAME_KBOARD (XFRAME (frame
));
3784 Lisp_Object Vthrow_on_input
;
3786 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
3789 kbd_buffer_store_event (event
)
3790 register struct input_event
*event
;
3792 kbd_buffer_store_event_hold (event
, 0);
3795 /* Store EVENT obtained at interrupt level into kbd_buffer, fifo.
3797 If HOLD_QUIT is 0, just stuff EVENT into the fifo.
3798 Else, if HOLD_QUIT.kind != NO_EVENT, discard EVENT.
3799 Else, if EVENT is a quit event, store the quit event
3800 in HOLD_QUIT, and return (thus ignoring further events).
3802 This is used in read_avail_input to postpone the processing
3803 of the quit event until all subsequent input events have been
3804 parsed (and discarded).
3808 kbd_buffer_store_event_hold (event
, hold_quit
)
3809 register struct input_event
*event
;
3810 struct input_event
*hold_quit
;
3812 if (event
->kind
== NO_EVENT
)
3815 if (hold_quit
&& hold_quit
->kind
!= NO_EVENT
)
3818 if (event
->kind
== ASCII_KEYSTROKE_EVENT
)
3820 register int c
= event
->code
& 0377;
3822 if (event
->modifiers
& ctrl_modifier
)
3823 c
= make_ctrl_char (c
);
3825 c
|= (event
->modifiers
3826 & (meta_modifier
| alt_modifier
3827 | hyper_modifier
| super_modifier
));
3831 KBOARD
*kb
= FRAME_KBOARD (XFRAME (event
->frame_or_window
));
3832 struct input_event
*sp
;
3834 if (single_kboard
&& kb
!= current_kboard
)
3837 = Fcons (make_lispy_switch_frame (event
->frame_or_window
),
3838 Fcons (make_number (c
), Qnil
));
3839 kb
->kbd_queue_has_data
= 1;
3840 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
3842 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3845 if (event_to_kboard (sp
) == kb
)
3847 sp
->kind
= NO_EVENT
;
3848 sp
->frame_or_window
= Qnil
;
3857 bcopy (event
, (char *) hold_quit
, sizeof (*event
));
3861 /* If this results in a quit_char being returned to Emacs as
3862 input, set Vlast_event_frame properly. If this doesn't
3863 get returned to Emacs as an event, the next event read
3864 will set Vlast_event_frame again, so this is safe to do. */
3868 focus
= FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
3870 focus
= event
->frame_or_window
;
3871 internal_last_event_frame
= focus
;
3872 Vlast_event_frame
= focus
;
3875 last_event_timestamp
= event
->timestamp
;
3876 handle_interrupt ();
3880 if (c
&& c
== stop_character
)
3886 /* Don't insert two BUFFER_SWITCH_EVENT's in a row.
3887 Just ignore the second one. */
3888 else if (event
->kind
== BUFFER_SWITCH_EVENT
3889 && kbd_fetch_ptr
!= kbd_store_ptr
3890 && ((kbd_store_ptr
== kbd_buffer
3891 ? kbd_buffer
+ KBD_BUFFER_SIZE
- 1
3892 : kbd_store_ptr
- 1)->kind
) == BUFFER_SWITCH_EVENT
)
3895 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
3896 kbd_store_ptr
= kbd_buffer
;
3898 /* Don't let the very last slot in the buffer become full,
3899 since that would make the two pointers equal,
3900 and that is indistinguishable from an empty buffer.
3901 Discard the event if it would fill the last slot. */
3902 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
3904 *kbd_store_ptr
= *event
;
3908 /* If we're inside while-no-input, and this event qualifies
3909 as input, set quit-flag to cause an interrupt. */
3910 if (!NILP (Vthrow_on_input
)
3911 && event
->kind
!= FOCUS_IN_EVENT
3912 && event
->kind
!= HELP_EVENT
3913 && event
->kind
!= DEICONIFY_EVENT
)
3915 Vquit_flag
= Vthrow_on_input
;
3916 /* If we're inside a function that wants immediate quits,
3918 if (immediate_quit
&& NILP (Vinhibit_quit
))
3928 /* Put an input event back in the head of the event queue. */
3931 kbd_buffer_unget_event (event
)
3932 register struct input_event
*event
;
3934 if (kbd_fetch_ptr
== kbd_buffer
)
3935 kbd_fetch_ptr
= kbd_buffer
+ KBD_BUFFER_SIZE
;
3937 /* Don't let the very last slot in the buffer become full, */
3938 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
3941 *kbd_fetch_ptr
= *event
;
3946 /* Generate HELP_EVENT input_events in BUFP which has room for
3947 SIZE events. If there's not enough room in BUFP, ignore this
3950 HELP is the help form.
3952 FRAME is the frame on which the help is generated. OBJECT is the
3953 Lisp object where the help was found (a buffer, a string, an
3954 overlay, or nil if neither from a string nor from a buffer. POS is
3955 the position within OBJECT where the help was found.
3957 Value is the number of input_events generated. */
3960 gen_help_event (help
, frame
, window
, object
, pos
)
3961 Lisp_Object help
, frame
, object
, window
;
3964 struct input_event event
;
3968 event
.kind
= HELP_EVENT
;
3969 event
.frame_or_window
= frame
;
3971 event
.x
= WINDOWP (window
) ? window
: frame
;
3974 kbd_buffer_store_event (&event
);
3978 /* Store HELP_EVENTs for HELP on FRAME in the input queue. */
3981 kbd_buffer_store_help_event (frame
, help
)
3982 Lisp_Object frame
, help
;
3984 struct input_event event
;
3986 event
.kind
= HELP_EVENT
;
3987 event
.frame_or_window
= frame
;
3992 kbd_buffer_store_event (&event
);
3996 /* Discard any mouse events in the event buffer by setting them to
3999 discard_mouse_events ()
4001 struct input_event
*sp
;
4002 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
4004 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
4007 if (sp
->kind
== MOUSE_CLICK_EVENT
4008 || sp
->kind
== WHEEL_EVENT
4009 || sp
->kind
== HORIZ_WHEEL_EVENT
4011 || sp
->kind
== GPM_CLICK_EVENT
4013 || sp
->kind
== SCROLL_BAR_CLICK_EVENT
)
4015 sp
->kind
= NO_EVENT
;
4021 /* Return non-zero if there are any real events waiting in the event
4022 buffer, not counting `NO_EVENT's.
4024 If DISCARD is non-zero, discard NO_EVENT events at the front of
4025 the input queue, possibly leaving the input queue empty if there
4026 are no real input events. */
4029 kbd_buffer_events_waiting (discard
)
4032 struct input_event
*sp
;
4034 for (sp
= kbd_fetch_ptr
;
4035 sp
!= kbd_store_ptr
&& sp
->kind
== NO_EVENT
;
4038 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
4045 return sp
!= kbd_store_ptr
&& sp
->kind
!= NO_EVENT
;
4049 /* Clear input event EVENT. */
4053 struct input_event
*event
;
4055 event
->kind
= NO_EVENT
;
4059 /* Read one event from the event buffer, waiting if necessary.
4060 The value is a Lisp object representing the event.
4061 The value is nil for an event that should be ignored,
4062 or that was handled here.
4063 We always read and discard one event. */
4066 kbd_buffer_get_event (kbp
, used_mouse_menu
, end_time
)
4068 int *used_mouse_menu
;
4069 EMACS_TIME
*end_time
;
4075 /* In case we are running as a daemon, only do this before
4076 detaching from the terminal. */
4077 || (IS_DAEMON
&& daemon_pipe
[1] >= 0))
4081 *kbp
= current_kboard
;
4085 /* Wait until there is input available. */
4088 /* Break loop if there's an unread command event. Needed in
4089 moused window autoselection which uses a timer to insert such
4091 if (CONSP (Vunread_command_events
))
4094 if (kbd_fetch_ptr
!= kbd_store_ptr
)
4096 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
4097 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
4101 /* If the quit flag is set, then read_char will return
4102 quit_char, so that counts as "available input." */
4103 if (!NILP (Vquit_flag
))
4104 quit_throw_to_read_char ();
4106 /* One way or another, wait until input is available; then, if
4107 interrupt handlers have not read it, read it now. */
4109 /* Note SIGIO has been undef'd if FIONREAD is missing. */
4113 if (kbd_fetch_ptr
!= kbd_store_ptr
)
4115 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
4116 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
4121 EMACS_TIME duration
;
4122 EMACS_GET_TIME (duration
);
4123 if (EMACS_TIME_GE (duration
, *end_time
))
4124 return Qnil
; /* finished waiting */
4127 EMACS_SUB_TIME (duration
, *end_time
, duration
);
4128 wait_reading_process_output (EMACS_SECS (duration
),
4129 EMACS_USECS (duration
),
4130 -1, 1, Qnil
, NULL
, 0);
4134 wait_reading_process_output (0, 0, -1, 1, Qnil
, NULL
, 0);
4136 if (!interrupt_input
&& kbd_fetch_ptr
== kbd_store_ptr
)
4137 /* Pass 1 for EXPECT since we just waited to have input. */
4138 read_avail_input (1);
4141 if (CONSP (Vunread_command_events
))
4144 first
= XCAR (Vunread_command_events
);
4145 Vunread_command_events
= XCDR (Vunread_command_events
);
4146 *kbp
= current_kboard
;
4150 /* At this point, we know that there is a readable event available
4151 somewhere. If the event queue is empty, then there must be a
4152 mouse movement enabled and available. */
4153 if (kbd_fetch_ptr
!= kbd_store_ptr
)
4155 struct input_event
*event
;
4157 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
4161 last_event_timestamp
= event
->timestamp
;
4163 *kbp
= event_to_kboard (event
);
4165 *kbp
= current_kboard
; /* Better than returning null ptr? */
4169 /* These two kinds of events get special handling
4170 and don't actually appear to the command loop.
4171 We return nil for them. */
4172 if (event
->kind
== SELECTION_REQUEST_EVENT
4173 || event
->kind
== SELECTION_CLEAR_EVENT
)
4176 struct input_event copy
;
4178 /* Remove it from the buffer before processing it,
4179 since otherwise swallow_events will see it
4180 and process it again. */
4182 kbd_fetch_ptr
= event
+ 1;
4183 input_pending
= readable_events (0);
4184 x_handle_selection_event (©
);
4186 /* We're getting selection request events, but we don't have
4192 #if defined (HAVE_NS)
4193 else if (event
->kind
== NS_TEXT_EVENT
)
4195 if (event
->code
== KEY_NS_PUT_WORKING_TEXT
)
4196 obj
= Fcons (intern ("ns-put-working-text"), Qnil
);
4198 obj
= Fcons (intern ("ns-unput-working-text"), Qnil
);
4199 kbd_fetch_ptr
= event
+ 1;
4200 if (used_mouse_menu
)
4201 *used_mouse_menu
= 1;
4205 #if defined (HAVE_X11) || defined (HAVE_NTGUI) \
4206 || defined (HAVE_NS)
4207 else if (event
->kind
== DELETE_WINDOW_EVENT
)
4209 /* Make an event (delete-frame (FRAME)). */
4210 obj
= Fcons (event
->frame_or_window
, Qnil
);
4211 obj
= Fcons (Qdelete_frame
, Fcons (obj
, Qnil
));
4212 kbd_fetch_ptr
= event
+ 1;
4215 #if defined (HAVE_X11) || defined (HAVE_NTGUI) \
4216 || defined (HAVE_NS)
4217 else if (event
->kind
== ICONIFY_EVENT
)
4219 /* Make an event (iconify-frame (FRAME)). */
4220 obj
= Fcons (event
->frame_or_window
, Qnil
);
4221 obj
= Fcons (Qiconify_frame
, Fcons (obj
, Qnil
));
4222 kbd_fetch_ptr
= event
+ 1;
4224 else if (event
->kind
== DEICONIFY_EVENT
)
4226 /* Make an event (make-frame-visible (FRAME)). */
4227 obj
= Fcons (event
->frame_or_window
, Qnil
);
4228 obj
= Fcons (Qmake_frame_visible
, Fcons (obj
, Qnil
));
4229 kbd_fetch_ptr
= event
+ 1;
4232 else if (event
->kind
== BUFFER_SWITCH_EVENT
)
4234 /* The value doesn't matter here; only the type is tested. */
4235 XSETBUFFER (obj
, current_buffer
);
4236 kbd_fetch_ptr
= event
+ 1;
4238 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
4239 || defined(HAVE_NS) || defined (USE_GTK)
4240 else if (event
->kind
== MENU_BAR_ACTIVATE_EVENT
)
4242 kbd_fetch_ptr
= event
+ 1;
4243 input_pending
= readable_events (0);
4244 if (FRAME_LIVE_P (XFRAME (event
->frame_or_window
)))
4245 x_activate_menubar (XFRAME (event
->frame_or_window
));
4248 #if defined (WINDOWSNT)
4249 else if (event
->kind
== LANGUAGE_CHANGE_EVENT
)
4251 /* Make an event (language-change (FRAME CHARSET LCID)). */
4252 obj
= Fcons (event
->frame_or_window
, Qnil
);
4253 obj
= Fcons (Qlanguage_change
, Fcons (obj
, Qnil
));
4254 kbd_fetch_ptr
= event
+ 1;
4257 else if (event
->kind
== SAVE_SESSION_EVENT
)
4259 obj
= Fcons (Qsave_session
, Qnil
);
4260 kbd_fetch_ptr
= event
+ 1;
4262 /* Just discard these, by returning nil.
4263 With MULTI_KBOARD, these events are used as placeholders
4264 when we need to randomly delete events from the queue.
4265 (They shouldn't otherwise be found in the buffer,
4266 but on some machines it appears they do show up
4267 even without MULTI_KBOARD.) */
4268 /* On Windows NT/9X, NO_EVENT is used to delete extraneous
4269 mouse events during a popup-menu call. */
4270 else if (event
->kind
== NO_EVENT
)
4271 kbd_fetch_ptr
= event
+ 1;
4272 else if (event
->kind
== HELP_EVENT
)
4274 Lisp_Object object
, position
, help
, frame
, window
;
4276 frame
= event
->frame_or_window
;
4277 object
= event
->arg
;
4278 position
= make_number (event
->code
);
4281 clear_event (event
);
4283 kbd_fetch_ptr
= event
+ 1;
4284 if (!WINDOWP (window
))
4286 obj
= Fcons (Qhelp_echo
,
4287 list5 (frame
, help
, window
, object
, position
));
4289 else if (event
->kind
== FOCUS_IN_EVENT
)
4291 /* Notification of a FocusIn event. The frame receiving the
4292 focus is in event->frame_or_window. Generate a
4293 switch-frame event if necessary. */
4294 Lisp_Object frame
, focus
;
4296 frame
= event
->frame_or_window
;
4297 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
4301 if (!EQ (frame
, internal_last_event_frame
)
4302 && !EQ (frame
, selected_frame
))
4303 obj
= make_lispy_switch_frame (frame
);
4304 internal_last_event_frame
= frame
;
4305 kbd_fetch_ptr
= event
+ 1;
4308 else if (event
->kind
== DBUS_EVENT
)
4310 obj
= make_lispy_event (event
);
4311 kbd_fetch_ptr
= event
+ 1;
4314 else if (event
->kind
== CONFIG_CHANGED_EVENT
)
4316 obj
= make_lispy_event (event
);
4317 kbd_fetch_ptr
= event
+ 1;
4321 /* If this event is on a different frame, return a switch-frame this
4322 time, and leave the event in the queue for next time. */
4326 frame
= event
->frame_or_window
;
4328 frame
= XCAR (frame
);
4329 else if (WINDOWP (frame
))
4330 frame
= WINDOW_FRAME (XWINDOW (frame
));
4332 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
4336 if (! EQ (frame
, internal_last_event_frame
)
4337 && !EQ (frame
, selected_frame
))
4338 obj
= make_lispy_switch_frame (frame
);
4339 internal_last_event_frame
= frame
;
4341 /* If we didn't decide to make a switch-frame event, go ahead
4342 and build a real event from the queue entry. */
4346 obj
= make_lispy_event (event
);
4348 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
4349 || defined(HAVE_NS) || defined (USE_GTK)
4350 /* If this was a menu selection, then set the flag to inhibit
4351 writing to last_nonmenu_event. Don't do this if the event
4352 we're returning is (menu-bar), though; that indicates the
4353 beginning of the menu sequence, and we might as well leave
4354 that as the `event with parameters' for this selection. */
4356 && !EQ (event
->frame_or_window
, event
->arg
)
4357 && (event
->kind
== MENU_BAR_EVENT
4358 || event
->kind
== TOOL_BAR_EVENT
))
4359 *used_mouse_menu
= 1;
4362 /* certain system events are non-key events */
4364 && event
->kind
== NS_NONKEY_EVENT
)
4365 *used_mouse_menu
= 1;
4368 /* Wipe out this event, to catch bugs. */
4369 clear_event (event
);
4370 kbd_fetch_ptr
= event
+ 1;
4374 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
4375 /* Try generating a mouse motion event. */
4376 else if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
4378 FRAME_PTR f
= some_mouse_moved ();
4379 Lisp_Object bar_window
;
4380 enum scroll_bar_part part
;
4384 *kbp
= current_kboard
;
4385 /* Note that this uses F to determine which terminal to look at.
4386 If there is no valid info, it does not store anything
4387 so x remains nil. */
4390 /* XXX Can f or mouse_position_hook be NULL here? */
4391 if (f
&& FRAME_TERMINAL (f
)->mouse_position_hook
)
4392 (*FRAME_TERMINAL (f
)->mouse_position_hook
) (&f
, 0, &bar_window
,
4393 &part
, &x
, &y
, &time
);
4397 /* Decide if we should generate a switch-frame event. Don't
4398 generate switch-frame events for motion outside of all Emacs
4404 frame
= FRAME_FOCUS_FRAME (f
);
4406 XSETFRAME (frame
, f
);
4408 if (! EQ (frame
, internal_last_event_frame
)
4409 && !EQ (frame
, selected_frame
))
4410 obj
= make_lispy_switch_frame (frame
);
4411 internal_last_event_frame
= frame
;
4414 /* If we didn't decide to make a switch-frame event, go ahead and
4415 return a mouse-motion event. */
4416 if (!NILP (x
) && NILP (obj
))
4417 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
4419 #endif /* HAVE_MOUSE || HAVE GPM */
4421 /* We were promised by the above while loop that there was
4422 something for us to read! */
4425 input_pending
= readable_events (0);
4427 Vlast_event_frame
= internal_last_event_frame
;
4432 /* Process any events that are not user-visible,
4433 then return, without reading any user-visible events. */
4436 swallow_events (do_display
)
4441 while (kbd_fetch_ptr
!= kbd_store_ptr
)
4443 struct input_event
*event
;
4445 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
4449 last_event_timestamp
= event
->timestamp
;
4451 /* These two kinds of events get special handling
4452 and don't actually appear to the command loop. */
4453 if (event
->kind
== SELECTION_REQUEST_EVENT
4454 || event
->kind
== SELECTION_CLEAR_EVENT
)
4457 struct input_event copy
;
4459 /* Remove it from the buffer before processing it,
4460 since otherwise swallow_events called recursively could see it
4461 and process it again. */
4463 kbd_fetch_ptr
= event
+ 1;
4464 input_pending
= readable_events (0);
4465 x_handle_selection_event (©
);
4467 /* We're getting selection request events, but we don't have
4476 old_timers_run
= timers_run
;
4477 get_input_pending (&input_pending
, READABLE_EVENTS_DO_TIMERS_NOW
);
4479 if (timers_run
!= old_timers_run
&& do_display
)
4480 redisplay_preserve_echo_area (7);
4483 /* Record the start of when Emacs is idle,
4484 for the sake of running idle-time timers. */
4491 /* If we are already in the idle state, do nothing. */
4492 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
4495 EMACS_GET_TIME (timer_idleness_start_time
);
4497 timer_last_idleness_start_time
= timer_idleness_start_time
;
4499 /* Mark all idle-time timers as once again candidates for running. */
4500 for (timers
= Vtimer_idle_list
; CONSP (timers
); timers
= XCDR (timers
))
4504 timer
= XCAR (timers
);
4506 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
4508 XVECTOR (timer
)->contents
[0] = Qnil
;
4512 /* Record that Emacs is no longer idle, so stop running idle-time timers. */
4517 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
4520 /* Resume idle timer from last idle start time. */
4523 timer_resume_idle ()
4525 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
4528 timer_idleness_start_time
= timer_last_idleness_start_time
;
4531 /* This is only for debugging. */
4532 struct input_event last_timer_event
;
4534 /* List of elisp functions to call, delayed because they were generated in
4535 a context where Elisp could not be safely run (e.g. redisplay, signal,
4536 ...). Each element has the form (FUN . ARGS). */
4537 Lisp_Object pending_funcalls
;
4539 extern Lisp_Object Qapply
;
4541 /* Check whether a timer has fired. To prevent larger problems we simply
4542 disregard elements that are not proper timers. Do not make a circular
4543 timer list for the time being.
4545 Returns the time to wait until the next timer fires. If a
4546 timer is triggering now, return zero.
4547 If no timer is active, return -1.
4549 If a timer is ripe, we run it, with quitting turned off.
4550 In that case we return 0 to indicate that a new timer_check_2 call
4556 EMACS_TIME nexttime
;
4557 EMACS_TIME now
, idleness_now
;
4558 Lisp_Object timers
, idle_timers
, chosen_timer
;
4559 struct gcpro gcpro1
, gcpro2
, gcpro3
;
4561 EMACS_SET_SECS (nexttime
, -1);
4562 EMACS_SET_USECS (nexttime
, -1);
4564 /* Always consider the ordinary timers. */
4565 timers
= Vtimer_list
;
4566 /* Consider the idle timers only if Emacs is idle. */
4567 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
4568 idle_timers
= Vtimer_idle_list
;
4571 chosen_timer
= Qnil
;
4572 GCPRO3 (timers
, idle_timers
, chosen_timer
);
4574 /* First run the code that was delayed. */
4575 while (CONSP (pending_funcalls
))
4577 Lisp_Object funcall
= XCAR (pending_funcalls
);
4578 pending_funcalls
= XCDR (pending_funcalls
);
4579 safe_call2 (Qapply
, XCAR (funcall
), XCDR (funcall
));
4582 if (CONSP (timers
) || CONSP (idle_timers
))
4584 EMACS_GET_TIME (now
);
4585 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
4586 EMACS_SUB_TIME (idleness_now
, now
, timer_idleness_start_time
);
4589 while (CONSP (timers
) || CONSP (idle_timers
))
4591 Lisp_Object
*vector
;
4592 Lisp_Object timer
= Qnil
, idle_timer
= Qnil
;
4593 EMACS_TIME timer_time
, idle_timer_time
;
4594 EMACS_TIME difference
, timer_difference
, idle_timer_difference
;
4596 /* Skip past invalid timers and timers already handled. */
4599 timer
= XCAR (timers
);
4600 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
4602 timers
= XCDR (timers
);
4605 vector
= XVECTOR (timer
)->contents
;
4607 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
4608 || !INTEGERP (vector
[3])
4609 || ! NILP (vector
[0]))
4611 timers
= XCDR (timers
);
4615 if (!NILP (idle_timers
))
4617 timer
= XCAR (idle_timers
);
4618 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
4620 idle_timers
= XCDR (idle_timers
);
4623 vector
= XVECTOR (timer
)->contents
;
4625 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
4626 || !INTEGERP (vector
[3])
4627 || ! NILP (vector
[0]))
4629 idle_timers
= XCDR (idle_timers
);
4634 /* Set TIMER, TIMER_TIME and TIMER_DIFFERENCE
4635 based on the next ordinary timer.
4636 TIMER_DIFFERENCE is the distance in time from NOW to when
4637 this timer becomes ripe (negative if it's already ripe). */
4640 timer
= XCAR (timers
);
4641 vector
= XVECTOR (timer
)->contents
;
4642 EMACS_SET_SECS (timer_time
,
4643 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
4644 EMACS_SET_USECS (timer_time
, XINT (vector
[3]));
4645 EMACS_SUB_TIME (timer_difference
, timer_time
, now
);
4648 /* Set IDLE_TIMER, IDLE_TIMER_TIME and IDLE_TIMER_DIFFERENCE
4649 based on the next idle timer. */
4650 if (!NILP (idle_timers
))
4652 idle_timer
= XCAR (idle_timers
);
4653 vector
= XVECTOR (idle_timer
)->contents
;
4654 EMACS_SET_SECS (idle_timer_time
,
4655 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
4656 EMACS_SET_USECS (idle_timer_time
, XINT (vector
[3]));
4657 EMACS_SUB_TIME (idle_timer_difference
, idle_timer_time
, idleness_now
);
4660 /* Decide which timer is the next timer,
4661 and set CHOSEN_TIMER, VECTOR and DIFFERENCE accordingly.
4662 Also step down the list where we found that timer. */
4664 if (! NILP (timers
) && ! NILP (idle_timers
))
4667 EMACS_SUB_TIME (temp
, timer_difference
, idle_timer_difference
);
4668 if (EMACS_TIME_NEG_P (temp
))
4670 chosen_timer
= timer
;
4671 timers
= XCDR (timers
);
4672 difference
= timer_difference
;
4676 chosen_timer
= idle_timer
;
4677 idle_timers
= XCDR (idle_timers
);
4678 difference
= idle_timer_difference
;
4681 else if (! NILP (timers
))
4683 chosen_timer
= timer
;
4684 timers
= XCDR (timers
);
4685 difference
= timer_difference
;
4689 chosen_timer
= idle_timer
;
4690 idle_timers
= XCDR (idle_timers
);
4691 difference
= idle_timer_difference
;
4693 vector
= XVECTOR (chosen_timer
)->contents
;
4695 /* If timer is ripe, run it if it hasn't been run. */
4696 if (EMACS_TIME_NEG_P (difference
)
4697 || (EMACS_SECS (difference
) == 0
4698 && EMACS_USECS (difference
) == 0))
4700 if (NILP (vector
[0]))
4702 int count
= SPECPDL_INDEX ();
4703 Lisp_Object old_deactivate_mark
= Vdeactivate_mark
;
4705 /* Mark the timer as triggered to prevent problems if the lisp
4706 code fails to reschedule it right. */
4709 specbind (Qinhibit_quit
, Qt
);
4711 call1 (Qtimer_event_handler
, chosen_timer
);
4712 Vdeactivate_mark
= old_deactivate_mark
;
4714 unbind_to (count
, Qnil
);
4716 /* Since we have handled the event,
4717 we don't need to tell the caller to wake up and do it. */
4718 /* But the caller must still wait for the next timer, so
4719 return 0 to indicate that. */
4722 EMACS_SET_SECS (nexttime
, 0);
4723 EMACS_SET_USECS (nexttime
, 0);
4726 /* When we encounter a timer that is still waiting,
4727 return the amount of time to wait before it is ripe. */
4734 /* No timers are pending in the future. */
4735 /* Return 0 if we generated an event, and -1 if not. */
4741 /* Check whether a timer has fired. To prevent larger problems we simply
4742 disregard elements that are not proper timers. Do not make a circular
4743 timer list for the time being.
4745 Returns the time to wait until the next timer fires.
4746 If no timer is active, return -1.
4748 As long as any timer is ripe, we run it.
4750 DO_IT_NOW is now ignored. It used to mean that we should
4751 run the timer directly instead of queueing a timer-event.
4752 Now we always run timers directly. */
4755 timer_check (do_it_now
)
4758 EMACS_TIME nexttime
;
4762 nexttime
= timer_check_2 ();
4764 while (EMACS_SECS (nexttime
) == 0 && EMACS_USECS (nexttime
) == 0);
4769 DEFUN ("current-idle-time", Fcurrent_idle_time
, Scurrent_idle_time
, 0, 0, 0,
4770 doc
: /* Return the current length of Emacs idleness, or nil.
4771 The value when Emacs is idle is a list of three integers. The first has
4772 the most significant 16 bits of the seconds, while the second has the least
4773 significant 16 bits. The third integer gives the microsecond count.
4775 The value when Emacs is not idle is nil.
4777 The microsecond count is zero on systems that do not provide
4778 resolution finer than a second. */)
4781 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
4783 EMACS_TIME now
, idleness_now
;
4785 EMACS_GET_TIME (now
);
4786 EMACS_SUB_TIME (idleness_now
, now
, timer_idleness_start_time
);
4788 return list3 (make_number ((EMACS_SECS (idleness_now
) >> 16) & 0xffff),
4789 make_number ((EMACS_SECS (idleness_now
) >> 0) & 0xffff),
4790 make_number (EMACS_USECS (idleness_now
)));
4796 /* Caches for modify_event_symbol. */
4797 static Lisp_Object accent_key_syms
;
4798 static Lisp_Object func_key_syms
;
4799 static Lisp_Object mouse_syms
;
4800 static Lisp_Object wheel_syms
;
4801 static Lisp_Object drag_n_drop_syms
;
4803 /* This is a list of keysym codes for special "accent" characters.
4804 It parallels lispy_accent_keys. */
4806 static const int lispy_accent_codes
[] =
4808 #ifdef XK_dead_circumflex
4813 #ifdef XK_dead_grave
4818 #ifdef XK_dead_tilde
4823 #ifdef XK_dead_diaeresis
4828 #ifdef XK_dead_macron
4833 #ifdef XK_dead_degree
4838 #ifdef XK_dead_acute
4843 #ifdef XK_dead_cedilla
4848 #ifdef XK_dead_breve
4853 #ifdef XK_dead_ogonek
4858 #ifdef XK_dead_caron
4863 #ifdef XK_dead_doubleacute
4864 XK_dead_doubleacute
,
4868 #ifdef XK_dead_abovedot
4873 #ifdef XK_dead_abovering
4883 #ifdef XK_dead_belowdot
4888 #ifdef XK_dead_voiced_sound
4889 XK_dead_voiced_sound
,
4893 #ifdef XK_dead_semivoiced_sound
4894 XK_dead_semivoiced_sound
,
4910 /* This is a list of Lisp names for special "accent" characters.
4911 It parallels lispy_accent_codes. */
4913 static char *lispy_accent_keys
[] =
4931 "dead-voiced-sound",
4932 "dead-semivoiced-sound",
4938 #define FUNCTION_KEY_OFFSET 0x0
4940 char *lispy_function_keys
[] =
4944 0, /* VK_LBUTTON 0x01 */
4945 0, /* VK_RBUTTON 0x02 */
4946 "cancel", /* VK_CANCEL 0x03 */
4947 0, /* VK_MBUTTON 0x04 */
4949 0, 0, 0, /* 0x05 .. 0x07 */
4951 "backspace", /* VK_BACK 0x08 */
4952 "tab", /* VK_TAB 0x09 */
4954 0, 0, /* 0x0A .. 0x0B */
4956 "clear", /* VK_CLEAR 0x0C */
4957 "return", /* VK_RETURN 0x0D */
4959 0, 0, /* 0x0E .. 0x0F */
4961 0, /* VK_SHIFT 0x10 */
4962 0, /* VK_CONTROL 0x11 */
4963 0, /* VK_MENU 0x12 */
4964 "pause", /* VK_PAUSE 0x13 */
4965 "capslock", /* VK_CAPITAL 0x14 */
4966 "kana", /* VK_KANA/VK_HANGUL 0x15 */
4968 "junja", /* VK_JUNJA 0x17 */
4969 "final", /* VK_FINAL 0x18 */
4970 "kanji", /* VK_KANJI/VK_HANJA 0x19 */
4972 "escape", /* VK_ESCAPE 0x1B */
4973 "convert", /* VK_CONVERT 0x1C */
4974 "non-convert", /* VK_NONCONVERT 0x1D */
4975 "accept", /* VK_ACCEPT 0x1E */
4976 "mode-change", /* VK_MODECHANGE 0x1F */
4977 0, /* VK_SPACE 0x20 */
4978 "prior", /* VK_PRIOR 0x21 */
4979 "next", /* VK_NEXT 0x22 */
4980 "end", /* VK_END 0x23 */
4981 "home", /* VK_HOME 0x24 */
4982 "left", /* VK_LEFT 0x25 */
4983 "up", /* VK_UP 0x26 */
4984 "right", /* VK_RIGHT 0x27 */
4985 "down", /* VK_DOWN 0x28 */
4986 "select", /* VK_SELECT 0x29 */
4987 "print", /* VK_PRINT 0x2A */
4988 "execute", /* VK_EXECUTE 0x2B */
4989 "snapshot", /* VK_SNAPSHOT 0x2C */
4990 "insert", /* VK_INSERT 0x2D */
4991 "delete", /* VK_DELETE 0x2E */
4992 "help", /* VK_HELP 0x2F */
4994 /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
4996 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4998 0, 0, 0, 0, 0, 0, 0, /* 0x3A .. 0x40 */
5000 /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
5002 0, 0, 0, 0, 0, 0, 0, 0, 0,
5003 0, 0, 0, 0, 0, 0, 0, 0, 0,
5004 0, 0, 0, 0, 0, 0, 0, 0,
5006 "lwindow", /* VK_LWIN 0x5B */
5007 "rwindow", /* VK_RWIN 0x5C */
5008 "apps", /* VK_APPS 0x5D */
5011 "kp-0", /* VK_NUMPAD0 0x60 */
5012 "kp-1", /* VK_NUMPAD1 0x61 */
5013 "kp-2", /* VK_NUMPAD2 0x62 */
5014 "kp-3", /* VK_NUMPAD3 0x63 */
5015 "kp-4", /* VK_NUMPAD4 0x64 */
5016 "kp-5", /* VK_NUMPAD5 0x65 */
5017 "kp-6", /* VK_NUMPAD6 0x66 */
5018 "kp-7", /* VK_NUMPAD7 0x67 */
5019 "kp-8", /* VK_NUMPAD8 0x68 */
5020 "kp-9", /* VK_NUMPAD9 0x69 */
5021 "kp-multiply", /* VK_MULTIPLY 0x6A */
5022 "kp-add", /* VK_ADD 0x6B */
5023 "kp-separator", /* VK_SEPARATOR 0x6C */
5024 "kp-subtract", /* VK_SUBTRACT 0x6D */
5025 "kp-decimal", /* VK_DECIMAL 0x6E */
5026 "kp-divide", /* VK_DIVIDE 0x6F */
5027 "f1", /* VK_F1 0x70 */
5028 "f2", /* VK_F2 0x71 */
5029 "f3", /* VK_F3 0x72 */
5030 "f4", /* VK_F4 0x73 */
5031 "f5", /* VK_F5 0x74 */
5032 "f6", /* VK_F6 0x75 */
5033 "f7", /* VK_F7 0x76 */
5034 "f8", /* VK_F8 0x77 */
5035 "f9", /* VK_F9 0x78 */
5036 "f10", /* VK_F10 0x79 */
5037 "f11", /* VK_F11 0x7A */
5038 "f12", /* VK_F12 0x7B */
5039 "f13", /* VK_F13 0x7C */
5040 "f14", /* VK_F14 0x7D */
5041 "f15", /* VK_F15 0x7E */
5042 "f16", /* VK_F16 0x7F */
5043 "f17", /* VK_F17 0x80 */
5044 "f18", /* VK_F18 0x81 */
5045 "f19", /* VK_F19 0x82 */
5046 "f20", /* VK_F20 0x83 */
5047 "f21", /* VK_F21 0x84 */
5048 "f22", /* VK_F22 0x85 */
5049 "f23", /* VK_F23 0x86 */
5050 "f24", /* VK_F24 0x87 */
5052 0, 0, 0, 0, /* 0x88 .. 0x8B */
5053 0, 0, 0, 0, /* 0x8C .. 0x8F */
5055 "kp-numlock", /* VK_NUMLOCK 0x90 */
5056 "scroll", /* VK_SCROLL 0x91 */
5057 /* Not sure where the following block comes from.
5058 Windows headers have NEC and Fujitsu specific keys in
5059 this block, but nothing generic. */
5060 "kp-space", /* VK_NUMPAD_CLEAR 0x92 */
5061 "kp-enter", /* VK_NUMPAD_ENTER 0x93 */
5062 "kp-prior", /* VK_NUMPAD_PRIOR 0x94 */
5063 "kp-next", /* VK_NUMPAD_NEXT 0x95 */
5064 "kp-end", /* VK_NUMPAD_END 0x96 */
5065 "kp-home", /* VK_NUMPAD_HOME 0x97 */
5066 "kp-left", /* VK_NUMPAD_LEFT 0x98 */
5067 "kp-up", /* VK_NUMPAD_UP 0x99 */
5068 "kp-right", /* VK_NUMPAD_RIGHT 0x9A */
5069 "kp-down", /* VK_NUMPAD_DOWN 0x9B */
5070 "kp-insert", /* VK_NUMPAD_INSERT 0x9C */
5071 "kp-delete", /* VK_NUMPAD_DELETE 0x9D */
5073 0, 0, /* 0x9E .. 0x9F */
5076 * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
5077 * Used only as parameters to GetAsyncKeyState and GetKeyState.
5078 * No other API or message will distinguish left and right keys this way.
5083 /* Multimedia keys. These are handled as WM_APPCOMMAND, which allows us
5084 to enable them selectively, and gives access to a few more functions.
5085 See lispy_multimedia_keys below. */
5086 0, 0, 0, 0, 0, 0, 0, /* 0xA6 .. 0xAC Browser */
5087 0, 0, 0, /* 0xAD .. 0xAF Volume */
5088 0, 0, 0, 0, /* 0xB0 .. 0xB3 Media */
5089 0, 0, 0, 0, /* 0xB4 .. 0xB7 Apps */
5091 /* 0xB8 .. 0xC0 "OEM" keys - all seem to be punctuation. */
5092 0, 0, 0, 0, 0, 0, 0, 0, 0,
5094 /* 0xC1 - 0xDA unallocated, 0xDB-0xDF more OEM keys */
5095 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5096 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5099 "ax", /* VK_OEM_AX 0xE1 */
5100 0, /* VK_OEM_102 0xE2 */
5101 "ico-help", /* VK_ICO_HELP 0xE3 */
5102 "ico-00", /* VK_ICO_00 0xE4 */
5103 0, /* VK_PROCESSKEY 0xE5 */
5104 "ico-clear", /* VK_ICO_CLEAR 0xE6 */
5105 "packet", /* VK_PACKET 0xE7 */
5107 "reset", /* VK_OEM_RESET 0xE9 */
5108 "jump", /* VK_OEM_JUMP 0xEA */
5109 "oem-pa1", /* VK_OEM_PA1 0xEB */
5110 "oem-pa2", /* VK_OEM_PA2 0xEC */
5111 "oem-pa3", /* VK_OEM_PA3 0xED */
5112 "wsctrl", /* VK_OEM_WSCTRL 0xEE */
5113 "cusel", /* VK_OEM_CUSEL 0xEF */
5114 "oem-attn", /* VK_OEM_ATTN 0xF0 */
5115 "finish", /* VK_OEM_FINISH 0xF1 */
5116 "copy", /* VK_OEM_COPY 0xF2 */
5117 "auto", /* VK_OEM_AUTO 0xF3 */
5118 "enlw", /* VK_OEM_ENLW 0xF4 */
5119 "backtab", /* VK_OEM_BACKTAB 0xF5 */
5120 "attn", /* VK_ATTN 0xF6 */
5121 "crsel", /* VK_CRSEL 0xF7 */
5122 "exsel", /* VK_EXSEL 0xF8 */
5123 "ereof", /* VK_EREOF 0xF9 */
5124 "play", /* VK_PLAY 0xFA */
5125 "zoom", /* VK_ZOOM 0xFB */
5126 "noname", /* VK_NONAME 0xFC */
5127 "pa1", /* VK_PA1 0xFD */
5128 "oem_clear", /* VK_OEM_CLEAR 0xFE */
5132 /* Some of these duplicate the "Media keys" on newer keyboards,
5133 but they are delivered to the application in a different way. */
5134 static char *lispy_multimedia_keys
[] =
5142 "browser-favorites",
5179 "toggle-dictate-command",
5185 "media-fast-forward",
5188 "media-channel-down"
5191 #else /* not HAVE_NTGUI */
5193 /* This should be dealt with in XTread_socket now, and that doesn't
5194 depend on the client system having the Kana syms defined. See also
5195 the XK_kana_A case below. */
5198 static char *lispy_kana_keys
[] =
5200 /* X Keysym value */
5201 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x400 .. 0x40f */
5202 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x410 .. 0x41f */
5203 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x420 .. 0x42f */
5204 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x430 .. 0x43f */
5205 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x440 .. 0x44f */
5206 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x450 .. 0x45f */
5207 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x460 .. 0x46f */
5208 0,0,0,0,0,0,0,0,0,0,0,0,0,0,"overline",0,
5209 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x480 .. 0x48f */
5210 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x490 .. 0x49f */
5211 0, "kana-fullstop", "kana-openingbracket", "kana-closingbracket",
5212 "kana-comma", "kana-conjunctive", "kana-WO", "kana-a",
5213 "kana-i", "kana-u", "kana-e", "kana-o",
5214 "kana-ya", "kana-yu", "kana-yo", "kana-tsu",
5215 "prolongedsound", "kana-A", "kana-I", "kana-U",
5216 "kana-E", "kana-O", "kana-KA", "kana-KI",
5217 "kana-KU", "kana-KE", "kana-KO", "kana-SA",
5218 "kana-SHI", "kana-SU", "kana-SE", "kana-SO",
5219 "kana-TA", "kana-CHI", "kana-TSU", "kana-TE",
5220 "kana-TO", "kana-NA", "kana-NI", "kana-NU",
5221 "kana-NE", "kana-NO", "kana-HA", "kana-HI",
5222 "kana-FU", "kana-HE", "kana-HO", "kana-MA",
5223 "kana-MI", "kana-MU", "kana-ME", "kana-MO",
5224 "kana-YA", "kana-YU", "kana-YO", "kana-RA",
5225 "kana-RI", "kana-RU", "kana-RE", "kana-RO",
5226 "kana-WA", "kana-N", "voicedsound", "semivoicedsound",
5227 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4e0 .. 0x4ef */
5228 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4f0 .. 0x4ff */
5230 #endif /* XK_kana_A */
5233 #define FUNCTION_KEY_OFFSET 0xff00
5235 /* You'll notice that this table is arranged to be conveniently
5236 indexed by X Windows keysym values. */
5237 static char *lispy_function_keys
[] =
5239 /* X Keysym value */
5241 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00...0f */
5242 "backspace", "tab", "linefeed", "clear",
5244 0, 0, 0, "pause", /* 0xff10...1f */
5245 0, 0, 0, 0, 0, 0, 0, "escape",
5247 0, "kanji", "muhenkan", "henkan", /* 0xff20...2f */
5248 "romaji", "hiragana", "katakana", "hiragana-katakana",
5249 "zenkaku", "hankaku", "zenkaku-hankaku", "touroku",
5250 "massyo", "kana-lock", "kana-shift", "eisu-shift",
5251 "eisu-toggle", /* 0xff30...3f */
5252 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5253 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
5255 "home", "left", "up", "right", /* 0xff50 */ /* IsCursorKey */
5256 "down", "prior", "next", "end",
5257 "begin", 0, 0, 0, 0, 0, 0, 0,
5258 "select", /* 0xff60 */ /* IsMiscFunctionKey */
5269 "break", /* 0xff6b */
5272 0, 0, 0, 0, "backtab", 0, 0, 0, /* 0xff70... */
5273 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff78... */
5274 "kp-space", /* 0xff80 */ /* IsKeypadKey */
5275 0, 0, 0, 0, 0, 0, 0, 0,
5276 "kp-tab", /* 0xff89 */
5278 "kp-enter", /* 0xff8d */
5280 "kp-f1", /* 0xff91 */
5284 "kp-home", /* 0xff95 */
5289 "kp-prior", /* kp-page-up */
5290 "kp-next", /* kp-page-down */
5296 0, 0, 0, 0, 0, 0, 0, 0, 0,
5297 "kp-multiply", /* 0xffaa */
5302 "kp-divide", /* 0xffaf */
5303 "kp-0", /* 0xffb0 */
5304 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
5307 "kp-equal", /* 0xffbd */
5308 "f1", /* 0xffbe */ /* IsFunctionKey */
5310 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
5311 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
5312 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
5313 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
5314 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
5315 0, 0, 0, 0, 0, 0, 0, 0,
5316 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
5317 0, 0, 0, 0, 0, 0, 0, "delete"
5320 /* ISO 9995 Function and Modifier Keys; the first byte is 0xFE. */
5321 #define ISO_FUNCTION_KEY_OFFSET 0xfe00
5323 static char *iso_lispy_function_keys
[] =
5325 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe00 */
5326 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe08 */
5327 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe10 */
5328 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe18 */
5329 "iso-lefttab", /* 0xfe20 */
5330 "iso-move-line-up", "iso-move-line-down",
5331 "iso-partial-line-up", "iso-partial-line-down",
5332 "iso-partial-space-left", "iso-partial-space-right",
5333 "iso-set-margin-left", "iso-set-margin-right", /* 0xffe27, 28 */
5334 "iso-release-margin-left", "iso-release-margin-right",
5335 "iso-release-both-margins",
5336 "iso-fast-cursor-left", "iso-fast-cursor-right",
5337 "iso-fast-cursor-up", "iso-fast-cursor-down",
5338 "iso-continuous-underline", "iso-discontinuous-underline", /* 0xfe30, 31 */
5339 "iso-emphasize", "iso-center-object", "iso-enter", /* ... 0xfe34 */
5342 #endif /* not HAVE_NTGUI */
5344 Lisp_Object Vlispy_mouse_stem
;
5346 static char *lispy_wheel_names
[] =
5348 "wheel-up", "wheel-down", "wheel-left", "wheel-right"
5351 /* drag-n-drop events are generated when a set of selected files are
5352 dragged from another application and dropped onto an Emacs window. */
5353 static char *lispy_drag_n_drop_names
[] =
5358 /* Scroll bar parts. */
5359 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
5360 Lisp_Object Qup
, Qdown
, Qbottom
, Qend_scroll
;
5361 Lisp_Object Qtop
, Qratio
;
5363 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
5364 Lisp_Object
*scroll_bar_parts
[] = {
5365 &Qabove_handle
, &Qhandle
, &Qbelow_handle
,
5366 &Qup
, &Qdown
, &Qtop
, &Qbottom
, &Qend_scroll
, &Qratio
5369 /* A vector, indexed by button number, giving the down-going location
5370 of currently depressed buttons, both scroll bar and non-scroll bar.
5372 The elements have the form
5373 (BUTTON-NUMBER MODIFIER-MASK . REST)
5374 where REST is the cdr of a position as it would be reported in the event.
5376 The make_lispy_event function stores positions here to tell the
5377 difference between click and drag events, and to store the starting
5378 location to be included in drag events. */
5380 static Lisp_Object button_down_location
;
5382 /* Information about the most recent up-going button event: Which
5383 button, what location, and what time. */
5385 static int last_mouse_button
;
5386 static int last_mouse_x
;
5387 static int last_mouse_y
;
5388 static unsigned long button_down_time
;
5390 /* The maximum time between clicks to make a double-click, or Qnil to
5391 disable double-click detection, or Qt for no time limit. */
5393 Lisp_Object Vdouble_click_time
;
5395 /* Maximum number of pixels the mouse may be moved between clicks
5396 to make a double-click. */
5398 EMACS_INT double_click_fuzz
;
5400 /* The number of clicks in this multiple-click. */
5402 int double_click_count
;
5404 /* Return position of a mouse click or wheel event */
5407 make_lispy_position (f
, x
, y
, time
)
5413 enum window_part part
;
5414 Lisp_Object posn
= Qnil
;
5415 Lisp_Object extra_info
= Qnil
;
5418 /* Set `window' to the window under frame pixel coordinates (x,y) */
5420 window
= window_from_coordinates (f
, XINT (*x
), XINT (*y
),
5421 &part
, &wx
, &wy
, 0);
5425 if (WINDOWP (window
))
5427 /* It's a click in window window at frame coordinates (x,y) */
5428 struct window
*w
= XWINDOW (window
);
5429 Lisp_Object string_info
= Qnil
;
5430 int textpos
= -1, rx
= -1, ry
= -1;
5431 int dx
= -1, dy
= -1;
5432 int width
= -1, height
= -1;
5433 Lisp_Object object
= Qnil
;
5435 /* Set event coordinates to window-relative coordinates
5436 for constructing the Lisp event below. */
5440 if (part
== ON_TEXT
)
5442 wx
+= WINDOW_LEFT_MARGIN_WIDTH (w
);
5444 else if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
)
5446 /* Mode line or header line. Look for a string under
5447 the mouse that may have a `local-map' property. */
5451 posn
= part
== ON_MODE_LINE
? Qmode_line
: Qheader_line
;
5453 string
= mode_line_string (w
, part
, &rx
, &ry
, &charpos
,
5454 &object
, &dx
, &dy
, &width
, &height
);
5455 if (STRINGP (string
))
5456 string_info
= Fcons (string
, make_number (charpos
));
5457 if (w
== XWINDOW (selected_window
)
5458 && current_buffer
== XBUFFER (w
->buffer
))
5461 textpos
= XMARKER (w
->pointm
)->charpos
;
5463 else if (part
== ON_VERTICAL_BORDER
)
5465 posn
= Qvertical_line
;
5470 else if (part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
5475 posn
= (part
== ON_LEFT_MARGIN
) ? Qleft_margin
: Qright_margin
;
5477 string
= marginal_area_string (w
, part
, &rx
, &ry
, &charpos
,
5478 &object
, &dx
, &dy
, &width
, &height
);
5479 if (STRINGP (string
))
5480 string_info
= Fcons (string
, make_number (charpos
));
5481 if (part
== ON_LEFT_MARGIN
)
5484 wx
= window_box_right_offset (w
, TEXT_AREA
) - 1;
5486 else if (part
== ON_LEFT_FRINGE
)
5488 posn
= Qleft_fringe
;
5491 wx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5493 : window_box_width (w
, LEFT_MARGIN_AREA
));
5496 else if (part
== ON_RIGHT_FRINGE
)
5498 posn
= Qright_fringe
;
5501 wx
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5502 + window_box_width (w
, TEXT_AREA
)
5503 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5504 ? window_box_width (w
, RIGHT_MARGIN_AREA
)
5510 /* Note: We have no special posn for part == ON_SCROLL_BAR. */
5511 wx
= max (WINDOW_LEFT_MARGIN_WIDTH (w
), wx
);
5516 Lisp_Object string2
, object2
= Qnil
;
5517 struct display_pos p
;
5519 int width2
, height2
;
5520 string2
= buffer_posn_from_coords (w
, &wx
, &wy
, &p
,
5521 &object2
, &dx2
, &dy2
,
5523 textpos
= CHARPOS (p
.pos
);
5524 if (rx
< 0) rx
= wx
;
5525 if (ry
< 0) ry
= wy
;
5526 if (dx
< 0) dx
= dx2
;
5527 if (dy
< 0) dy
= dy2
;
5528 if (width
< 0) width
= width2
;
5529 if (height
< 0) height
= height2
;
5533 posn
= make_number (textpos
);
5534 if (STRINGP (string2
))
5535 string_info
= Fcons (string2
,
5536 make_number (CHARPOS (p
.string_pos
)));
5542 #ifdef HAVE_WINDOW_SYSTEM
5543 if (IMAGEP (object
))
5545 Lisp_Object image_map
, hotspot
;
5546 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
5548 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
5550 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
5551 posn
= XCAR (hotspot
);
5556 extra_info
= Fcons (object
,
5557 Fcons (Fcons (make_number (dx
),
5559 Fcons (Fcons (make_number (width
),
5560 make_number (height
)),
5564 extra_info
= Fcons (string_info
,
5565 Fcons (make_number (textpos
),
5566 Fcons (Fcons (make_number (rx
),
5572 XSETFRAME (window
, f
);
5577 XSETFASTINT (*x
, 0);
5578 XSETFASTINT (*y
, 0);
5581 return Fcons (window
,
5583 Fcons (Fcons (*x
, *y
),
5584 Fcons (make_number (time
),
5588 /* Given a struct input_event, build the lisp event which represents
5589 it. If EVENT is 0, build a mouse movement event from the mouse
5590 movement buffer, which should have a movement event in it.
5592 Note that events must be passed to this function in the order they
5593 are received; this function stores the location of button presses
5594 in order to build drag events when the button is released. */
5597 make_lispy_event (event
)
5598 struct input_event
*event
;
5602 switch (SWITCH_ENUM_CAST (event
->kind
))
5604 /* A simple keystroke. */
5605 case ASCII_KEYSTROKE_EVENT
:
5606 case MULTIBYTE_CHAR_KEYSTROKE_EVENT
:
5608 Lisp_Object lispy_c
;
5609 int c
= event
->code
;
5610 if (event
->kind
== ASCII_KEYSTROKE_EVENT
)
5613 eassert (c
== event
->code
);
5614 /* Turn ASCII characters into control characters
5616 if (event
->modifiers
& ctrl_modifier
)
5618 c
= make_ctrl_char (c
);
5619 event
->modifiers
&= ~ctrl_modifier
;
5623 /* Add in the other modifier bits. The shift key was taken care
5624 of by the X code. */
5625 c
|= (event
->modifiers
5626 & (meta_modifier
| alt_modifier
5627 | hyper_modifier
| super_modifier
| ctrl_modifier
));
5628 /* Distinguish Shift-SPC from SPC. */
5629 if ((event
->code
) == 040
5630 && event
->modifiers
& shift_modifier
)
5631 c
|= shift_modifier
;
5632 button_down_time
= 0;
5633 XSETFASTINT (lispy_c
, c
);
5638 /* NS_NONKEY_EVENTs are just like NON_ASCII_KEYSTROKE_EVENTs,
5639 except that they are non-key events (last-nonmenu-event is nil). */
5640 case NS_NONKEY_EVENT
:
5643 /* A function key. The symbol may need to have modifier prefixes
5645 case NON_ASCII_KEYSTROKE_EVENT
:
5646 button_down_time
= 0;
5648 for (i
= 0; i
< sizeof (lispy_accent_codes
) / sizeof (int); i
++)
5649 if (event
->code
== lispy_accent_codes
[i
])
5650 return modify_event_symbol (i
,
5652 Qfunction_key
, Qnil
,
5653 lispy_accent_keys
, &accent_key_syms
,
5654 (sizeof (lispy_accent_keys
)
5655 / sizeof (lispy_accent_keys
[0])));
5659 if (event
->code
>= 0x400 && event
->code
< 0x500)
5660 return modify_event_symbol (event
->code
- 0x400,
5661 event
->modifiers
& ~shift_modifier
,
5662 Qfunction_key
, Qnil
,
5663 lispy_kana_keys
, &func_key_syms
,
5664 (sizeof (lispy_kana_keys
)
5665 / sizeof (lispy_kana_keys
[0])));
5666 #endif /* XK_kana_A */
5669 #ifdef ISO_FUNCTION_KEY_OFFSET
5670 if (event
->code
< FUNCTION_KEY_OFFSET
5671 && event
->code
>= ISO_FUNCTION_KEY_OFFSET
)
5672 return modify_event_symbol (event
->code
- ISO_FUNCTION_KEY_OFFSET
,
5674 Qfunction_key
, Qnil
,
5675 iso_lispy_function_keys
, &func_key_syms
,
5676 (sizeof (iso_lispy_function_keys
)
5677 / sizeof (iso_lispy_function_keys
[0])));
5680 /* Handle system-specific or unknown keysyms. */
5681 if (event
->code
& (1 << 28)
5682 || event
->code
- FUNCTION_KEY_OFFSET
< 0
5683 || (event
->code
- FUNCTION_KEY_OFFSET
5684 >= sizeof lispy_function_keys
/ sizeof *lispy_function_keys
)
5685 || !lispy_function_keys
[event
->code
- FUNCTION_KEY_OFFSET
])
5687 /* We need to use an alist rather than a vector as the cache
5688 since we can't make a vector long enuf. */
5689 if (NILP (current_kboard
->system_key_syms
))
5690 current_kboard
->system_key_syms
= Fcons (Qnil
, Qnil
);
5691 return modify_event_symbol (event
->code
,
5694 current_kboard
->Vsystem_key_alist
,
5695 0, ¤t_kboard
->system_key_syms
,
5699 return modify_event_symbol (event
->code
- FUNCTION_KEY_OFFSET
,
5701 Qfunction_key
, Qnil
,
5702 lispy_function_keys
, &func_key_syms
,
5703 (sizeof (lispy_function_keys
)
5704 / sizeof (lispy_function_keys
[0])));
5707 case MULTIMEDIA_KEY_EVENT
:
5708 if (event
->code
< (sizeof (lispy_multimedia_keys
)
5709 / sizeof (lispy_multimedia_keys
[0]))
5710 && event
->code
> 0 && lispy_multimedia_keys
[event
->code
])
5712 return modify_event_symbol (event
->code
, event
->modifiers
,
5713 Qfunction_key
, Qnil
,
5714 lispy_multimedia_keys
, &func_key_syms
,
5715 (sizeof (lispy_multimedia_keys
)
5716 / sizeof (lispy_multimedia_keys
[0])));
5722 /* A mouse click. Figure out where it is, decide whether it's
5723 a press, click or drag, and build the appropriate structure. */
5724 case MOUSE_CLICK_EVENT
:
5725 #ifndef USE_TOOLKIT_SCROLL_BARS
5726 case SCROLL_BAR_CLICK_EVENT
:
5729 int button
= event
->code
;
5731 Lisp_Object position
;
5732 Lisp_Object
*start_pos_ptr
;
5733 Lisp_Object start_pos
;
5737 /* Build the position as appropriate for this mouse click. */
5738 if (event
->kind
== MOUSE_CLICK_EVENT
)
5740 struct frame
*f
= XFRAME (event
->frame_or_window
);
5741 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK) && ! defined (HAVE_NS)
5745 /* Ignore mouse events that were made on frame that
5746 have been deleted. */
5747 if (! FRAME_LIVE_P (f
))
5750 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK) && ! defined (HAVE_NS)
5751 /* EVENT->x and EVENT->y are frame-relative pixel
5752 coordinates at this place. Under old redisplay, COLUMN
5753 and ROW are set to frame relative glyph coordinates
5754 which are then used to determine whether this click is
5755 in a menu (non-toolkit version). */
5756 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
5757 &column
, &row
, NULL
, 1);
5759 /* In the non-toolkit version, clicks on the menu bar
5760 are ordinary button events in the event buffer.
5761 Distinguish them, and invoke the menu.
5763 (In the toolkit version, the toolkit handles the menu bar
5764 and Emacs doesn't know about it until after the user
5765 makes a selection.) */
5766 if (row
>= 0 && row
< FRAME_MENU_BAR_LINES (f
)
5767 && (event
->modifiers
& down_modifier
))
5769 Lisp_Object items
, item
;
5774 /* Activate the menu bar on the down event. If the
5775 up event comes in before the menu code can deal with it,
5777 if (! (event
->modifiers
& down_modifier
))
5781 /* Find the menu bar item under `column'. */
5783 items
= FRAME_MENU_BAR_ITEMS (f
);
5784 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
5786 Lisp_Object pos
, string
;
5787 string
= AREF (items
, i
+ 1);
5788 pos
= AREF (items
, i
+ 3);
5791 if (column
>= XINT (pos
)
5792 && column
< XINT (pos
) + SCHARS (string
))
5794 item
= AREF (items
, i
);
5799 /* ELisp manual 2.4b says (x y) are window relative but
5800 code says they are frame-relative. */
5802 = Fcons (event
->frame_or_window
,
5804 Fcons (Fcons (event
->x
, event
->y
),
5805 Fcons (make_number (event
->timestamp
),
5808 return Fcons (item
, Fcons (position
, Qnil
));
5810 #endif /* not USE_X_TOOLKIT && not USE_GTK && not HAVE_NS */
5812 position
= make_lispy_position (f
, &event
->x
, &event
->y
,
5815 #ifndef USE_TOOLKIT_SCROLL_BARS
5818 /* It's a scrollbar click. */
5820 Lisp_Object portion_whole
;
5823 window
= event
->frame_or_window
;
5824 portion_whole
= Fcons (event
->x
, event
->y
);
5825 part
= *scroll_bar_parts
[(int) event
->part
];
5829 Fcons (Qvertical_scroll_bar
,
5830 Fcons (portion_whole
,
5831 Fcons (make_number (event
->timestamp
),
5832 Fcons (part
, Qnil
)))));
5834 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5836 if (button
>= ASIZE (button_down_location
))
5838 button_down_location
= larger_vector (button_down_location
,
5840 mouse_syms
= larger_vector (mouse_syms
, button
+ 1, Qnil
);
5843 start_pos_ptr
= &AREF (button_down_location
, button
);
5844 start_pos
= *start_pos_ptr
;
5845 *start_pos_ptr
= Qnil
;
5848 /* On window-system frames, use the value of
5849 double-click-fuzz as is. On other frames, interpret it
5850 as a multiple of 1/8 characters. */
5854 if (WINDOWP (event
->frame_or_window
))
5855 f
= XFRAME (XWINDOW (event
->frame_or_window
)->frame
);
5856 else if (FRAMEP (event
->frame_or_window
))
5857 f
= XFRAME (event
->frame_or_window
);
5861 if (FRAME_WINDOW_P (f
))
5862 fuzz
= double_click_fuzz
;
5864 fuzz
= double_click_fuzz
/ 8;
5866 is_double
= (button
== last_mouse_button
5867 && (eabs (XINT (event
->x
) - last_mouse_x
) <= fuzz
)
5868 && (eabs (XINT (event
->y
) - last_mouse_y
) <= fuzz
)
5869 && button_down_time
!= 0
5870 && (EQ (Vdouble_click_time
, Qt
)
5871 || (INTEGERP (Vdouble_click_time
)
5872 && ((int)(event
->timestamp
- button_down_time
)
5873 < XINT (Vdouble_click_time
)))));
5876 last_mouse_button
= button
;
5877 last_mouse_x
= XINT (event
->x
);
5878 last_mouse_y
= XINT (event
->y
);
5880 /* If this is a button press, squirrel away the location, so
5881 we can decide later whether it was a click or a drag. */
5882 if (event
->modifiers
& down_modifier
)
5886 double_click_count
++;
5887 event
->modifiers
|= ((double_click_count
> 2)
5892 double_click_count
= 1;
5893 button_down_time
= event
->timestamp
;
5894 *start_pos_ptr
= Fcopy_alist (position
);
5895 ignore_mouse_drag_p
= 0;
5898 /* Now we're releasing a button - check the co-ordinates to
5899 see if this was a click or a drag. */
5900 else if (event
->modifiers
& up_modifier
)
5902 /* If we did not see a down before this up, ignore the up.
5903 Probably this happened because the down event chose a
5904 menu item. It would be an annoyance to treat the
5905 release of the button that chose the menu item as a
5908 if (!CONSP (start_pos
))
5911 event
->modifiers
&= ~up_modifier
;
5912 #if 0 /* Formerly we treated an up with no down as a click event. */
5913 if (!CONSP (start_pos
))
5914 event
->modifiers
|= click_modifier
;
5919 EMACS_INT xdiff
= double_click_fuzz
, ydiff
= double_click_fuzz
;
5921 /* The third element of every position
5922 should be the (x,y) pair. */
5923 down
= Fcar (Fcdr (Fcdr (start_pos
)));
5925 && INTEGERP (XCAR (down
)) && INTEGERP (XCDR (down
)))
5927 xdiff
= XINT (event
->x
) - XINT (XCAR (down
));
5928 ydiff
= XINT (event
->y
) - XINT (XCDR (down
));
5931 if (ignore_mouse_drag_p
)
5933 event
->modifiers
|= click_modifier
;
5934 ignore_mouse_drag_p
= 0;
5936 else if (xdiff
< double_click_fuzz
&& xdiff
> - double_click_fuzz
5937 && ydiff
< double_click_fuzz
&& ydiff
> - double_click_fuzz
5938 /* Maybe the mouse has moved a lot, caused scrolling, and
5939 eventually ended up at the same screen position (but
5940 not buffer position) in which case it is a drag, not
5942 /* FIXME: OTOH if the buffer position has changed
5943 because of a timer or process filter rather than
5944 because of mouse movement, it should be considered as
5945 a click. But mouse-drag-region completely ignores
5946 this case and it hasn't caused any real problem, so
5947 it's probably OK to ignore it as well. */
5948 && EQ (Fcar (Fcdr (start_pos
)), Fcar (Fcdr (position
))))
5949 /* Mouse hasn't moved (much). */
5950 event
->modifiers
|= click_modifier
;
5953 button_down_time
= 0;
5954 event
->modifiers
|= drag_modifier
;
5957 /* Don't check is_double; treat this as multiple
5958 if the down-event was multiple. */
5959 if (double_click_count
> 1)
5960 event
->modifiers
|= ((double_click_count
> 2)
5966 /* Every mouse event should either have the down_modifier or
5967 the up_modifier set. */
5971 /* Get the symbol we should use for the mouse click. */
5974 head
= modify_event_symbol (button
,
5976 Qmouse_click
, Vlispy_mouse_stem
,
5979 XVECTOR (mouse_syms
)->size
);
5980 if (event
->modifiers
& drag_modifier
)
5985 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
5988 Fcons (make_number (double_click_count
),
5998 case HORIZ_WHEEL_EVENT
:
6000 Lisp_Object position
;
6003 /* Build the position as appropriate for this mouse click. */
6004 struct frame
*f
= XFRAME (event
->frame_or_window
);
6006 /* Ignore wheel events that were made on frame that have been
6008 if (! FRAME_LIVE_P (f
))
6011 position
= make_lispy_position (f
, &event
->x
, &event
->y
,
6014 /* Set double or triple modifiers to indicate the wheel speed. */
6016 /* On window-system frames, use the value of
6017 double-click-fuzz as is. On other frames, interpret it
6018 as a multiple of 1/8 characters. */
6024 if (WINDOWP (event
->frame_or_window
))
6025 f
= XFRAME (XWINDOW (event
->frame_or_window
)->frame
);
6026 else if (FRAMEP (event
->frame_or_window
))
6027 f
= XFRAME (event
->frame_or_window
);
6031 if (FRAME_WINDOW_P (f
))
6032 fuzz
= double_click_fuzz
;
6034 fuzz
= double_click_fuzz
/ 8;
6036 if (event
->modifiers
& up_modifier
)
6038 /* Emit a wheel-up event. */
6039 event
->modifiers
&= ~up_modifier
;
6042 else if (event
->modifiers
& down_modifier
)
6044 /* Emit a wheel-down event. */
6045 event
->modifiers
&= ~down_modifier
;
6049 /* Every wheel event should either have the down_modifier or
6050 the up_modifier set. */
6053 if (event
->kind
== HORIZ_WHEEL_EVENT
)
6056 is_double
= (last_mouse_button
== - (1 + symbol_num
)
6057 && (eabs (XINT (event
->x
) - last_mouse_x
) <= fuzz
)
6058 && (eabs (XINT (event
->y
) - last_mouse_y
) <= fuzz
)
6059 && button_down_time
!= 0
6060 && (EQ (Vdouble_click_time
, Qt
)
6061 || (INTEGERP (Vdouble_click_time
)
6062 && ((int)(event
->timestamp
- button_down_time
)
6063 < XINT (Vdouble_click_time
)))));
6066 double_click_count
++;
6067 event
->modifiers
|= ((double_click_count
> 2)
6073 double_click_count
= 1;
6074 event
->modifiers
|= click_modifier
;
6077 button_down_time
= event
->timestamp
;
6078 /* Use a negative value to distinguish wheel from mouse button. */
6079 last_mouse_button
= - (1 + symbol_num
);
6080 last_mouse_x
= XINT (event
->x
);
6081 last_mouse_y
= XINT (event
->y
);
6083 /* Get the symbol we should use for the wheel event. */
6084 head
= modify_event_symbol (symbol_num
,
6090 ASIZE (wheel_syms
));
6093 if (event
->modifiers
& (double_modifier
| triple_modifier
))
6096 Fcons (make_number (double_click_count
),
6105 #ifdef USE_TOOLKIT_SCROLL_BARS
6107 /* We don't have down and up events if using toolkit scroll bars,
6108 so make this always a click event. Store in the `part' of
6109 the Lisp event a symbol which maps to the following actions:
6111 `above_handle' page up
6112 `below_handle' page down
6116 `bottom' bottom of buffer
6117 `handle' thumb has been dragged.
6118 `end-scroll' end of interaction with scroll bar
6120 The incoming input_event contains in its `part' member an
6121 index of type `enum scroll_bar_part' which we can use as an
6122 index in scroll_bar_parts to get the appropriate symbol. */
6124 case SCROLL_BAR_CLICK_EVENT
:
6126 Lisp_Object position
, head
, window
, portion_whole
, part
;
6128 window
= event
->frame_or_window
;
6129 portion_whole
= Fcons (event
->x
, event
->y
);
6130 part
= *scroll_bar_parts
[(int) event
->part
];
6134 Fcons (Qvertical_scroll_bar
,
6135 Fcons (portion_whole
,
6136 Fcons (make_number (event
->timestamp
),
6137 Fcons (part
, Qnil
)))));
6139 /* Always treat scroll bar events as clicks. */
6140 event
->modifiers
|= click_modifier
;
6141 event
->modifiers
&= ~up_modifier
;
6143 if (event
->code
>= ASIZE (mouse_syms
))
6144 mouse_syms
= larger_vector (mouse_syms
, event
->code
+ 1, Qnil
);
6146 /* Get the symbol we should use for the mouse click. */
6147 head
= modify_event_symbol (event
->code
,
6152 XVECTOR (mouse_syms
)->size
);
6153 return Fcons (head
, Fcons (position
, Qnil
));
6156 #endif /* USE_TOOLKIT_SCROLL_BARS */
6158 case DRAG_N_DROP_EVENT
:
6161 Lisp_Object head
, position
;
6164 f
= XFRAME (event
->frame_or_window
);
6167 /* Ignore mouse events that were made on frames that
6168 have been deleted. */
6169 if (! FRAME_LIVE_P (f
))
6172 position
= make_lispy_position (f
, &event
->x
, &event
->y
,
6175 head
= modify_event_symbol (0, event
->modifiers
,
6177 lispy_drag_n_drop_names
,
6178 &drag_n_drop_syms
, 1);
6184 #endif /* HAVE_MOUSE */
6186 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
6187 || defined(HAVE_NS) || defined (USE_GTK)
6188 case MENU_BAR_EVENT
:
6189 if (EQ (event
->arg
, event
->frame_or_window
))
6190 /* This is the prefix key. We translate this to
6191 `(menu_bar)' because the code in keyboard.c for menu
6192 events, which we use, relies on this. */
6193 return Fcons (Qmenu_bar
, Qnil
);
6197 case SELECT_WINDOW_EVENT
:
6198 /* Make an event (select-window (WINDOW)). */
6199 return Fcons (Qselect_window
,
6200 Fcons (Fcons (event
->frame_or_window
, Qnil
),
6203 case TOOL_BAR_EVENT
:
6204 if (EQ (event
->arg
, event
->frame_or_window
))
6205 /* This is the prefix key. We translate this to
6206 `(tool_bar)' because the code in keyboard.c for tool bar
6207 events, which we use, relies on this. */
6208 return Fcons (Qtool_bar
, Qnil
);
6209 else if (SYMBOLP (event
->arg
))
6210 return apply_modifiers (event
->modifiers
, event
->arg
);
6213 case USER_SIGNAL_EVENT
:
6214 /* A user signal. */
6216 char *name
= find_user_signal_name (event
->code
);
6219 return intern (name
);
6222 case SAVE_SESSION_EVENT
:
6223 return Qsave_session
;
6228 return Fcons (Qdbus_event
, event
->arg
);
6230 #endif /* HAVE_DBUS */
6232 case CONFIG_CHANGED_EVENT
:
6233 return Fcons (Qconfig_changed_event
,
6235 Fcons (event
->frame_or_window
, Qnil
)));
6237 case GPM_CLICK_EVENT
:
6239 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
6240 Lisp_Object head
, position
;
6241 Lisp_Object
*start_pos_ptr
;
6242 Lisp_Object start_pos
;
6243 int button
= event
->code
;
6245 if (button
>= ASIZE (button_down_location
))
6247 button_down_location
= larger_vector (button_down_location
,
6249 mouse_syms
= larger_vector (mouse_syms
, button
+ 1, Qnil
);
6252 start_pos_ptr
= &AREF (button_down_location
, button
);
6253 start_pos
= *start_pos_ptr
;
6255 position
= make_lispy_position (f
, &event
->x
, &event
->y
,
6258 if (event
->modifiers
& down_modifier
)
6259 *start_pos_ptr
= Fcopy_alist (position
);
6260 else if (event
->modifiers
& (up_modifier
| drag_modifier
))
6262 if (!CONSP (start_pos
))
6264 event
->modifiers
&= ~up_modifier
;
6267 head
= modify_event_symbol (button
,
6269 Qmouse_click
, Vlispy_mouse_stem
,
6272 XVECTOR (mouse_syms
)->size
);
6274 if (event
->modifiers
& drag_modifier
)
6279 else if (event
->modifiers
& double_modifier
)
6282 Fcons (make_number (2),
6284 else if (event
->modifiers
& triple_modifier
)
6287 Fcons (make_number (3),
6294 #endif /* HAVE_GPM */
6296 /* The 'kind' field of the event is something we don't recognize. */
6302 #if defined(HAVE_MOUSE) || defined(HAVE_GPM)
6305 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
6307 Lisp_Object bar_window
;
6308 enum scroll_bar_part part
;
6312 /* Is it a scroll bar movement? */
6313 if (frame
&& ! NILP (bar_window
))
6315 Lisp_Object part_sym
;
6317 part_sym
= *scroll_bar_parts
[(int) part
];
6318 return Fcons (Qscroll_bar_movement
,
6319 (Fcons (Fcons (bar_window
,
6320 Fcons (Qvertical_scroll_bar
,
6321 Fcons (Fcons (x
, y
),
6322 Fcons (make_number (time
),
6328 /* Or is it an ordinary mouse movement? */
6331 Lisp_Object position
;
6333 position
= make_lispy_position (frame
, &x
, &y
, time
);
6335 return Fcons (Qmouse_movement
,
6341 #endif /* HAVE_MOUSE || HAVE GPM */
6343 /* Construct a switch frame event. */
6345 make_lispy_switch_frame (frame
)
6348 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
6351 /* Manipulating modifiers. */
6353 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
6355 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
6356 SYMBOL's name of the end of the modifiers; the string from this
6357 position is the unmodified symbol name.
6359 This doesn't use any caches. */
6362 parse_modifiers_uncached (symbol
, modifier_end
)
6370 CHECK_SYMBOL (symbol
);
6373 name
= SYMBOL_NAME (symbol
);
6375 for (i
= 0; i
+2 <= SBYTES (name
); )
6377 int this_mod_end
= 0;
6380 /* See if the name continues with a modifier word.
6381 Check that the word appears, but don't check what follows it.
6382 Set this_mod and this_mod_end to record what we find. */
6384 switch (SREF (name
, i
))
6386 #define SINGLE_LETTER_MOD(BIT) \
6387 (this_mod_end = i + 1, this_mod = BIT)
6390 SINGLE_LETTER_MOD (alt_modifier
);
6394 SINGLE_LETTER_MOD (ctrl_modifier
);
6398 SINGLE_LETTER_MOD (hyper_modifier
);
6402 SINGLE_LETTER_MOD (meta_modifier
);
6406 SINGLE_LETTER_MOD (shift_modifier
);
6410 SINGLE_LETTER_MOD (super_modifier
);
6413 #undef SINGLE_LETTER_MOD
6415 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
6416 if (i + LEN + 1 <= SBYTES (name) \
6417 && ! strncmp (SDATA (name) + i, NAME, LEN)) \
6419 this_mod_end = i + LEN; \
6424 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
6425 MULTI_LETTER_MOD (down_modifier
, "down", 4);
6426 MULTI_LETTER_MOD (double_modifier
, "double", 6);
6430 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
6432 #undef MULTI_LETTER_MOD
6436 /* If we found no modifier, stop looking for them. */
6437 if (this_mod_end
== 0)
6440 /* Check there is a dash after the modifier, so that it
6441 really is a modifier. */
6442 if (this_mod_end
>= SBYTES (name
)
6443 || SREF (name
, this_mod_end
) != '-')
6446 /* This modifier is real; look for another. */
6447 modifiers
|= this_mod
;
6448 i
= this_mod_end
+ 1;
6451 /* Should we include the `click' modifier? */
6452 if (! (modifiers
& (down_modifier
| drag_modifier
6453 | double_modifier
| triple_modifier
))
6454 && i
+ 7 == SBYTES (name
)
6455 && strncmp (SDATA (name
) + i
, "mouse-", 6) == 0
6456 && ('0' <= SREF (name
, i
+ 6) && SREF (name
, i
+ 6) <= '9'))
6457 modifiers
|= click_modifier
;
6459 if (! (modifiers
& (double_modifier
| triple_modifier
))
6460 && i
+ 6 < SBYTES (name
)
6461 && strncmp (SDATA (name
) + i
, "wheel-", 6) == 0)
6462 modifiers
|= click_modifier
;
6470 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
6471 prepended to the string BASE[0..BASE_LEN-1].
6472 This doesn't use any caches. */
6474 apply_modifiers_uncached (modifiers
, base
, base_len
, base_len_byte
)
6477 int base_len
, base_len_byte
;
6479 /* Since BASE could contain nulls, we can't use intern here; we have
6480 to use Fintern, which expects a genuine Lisp_String, and keeps a
6483 = (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
6489 /* Only the event queue may use the `up' modifier; it should always
6490 be turned into a click or drag event before presented to lisp code. */
6491 if (modifiers
& up_modifier
)
6494 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
6495 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
6496 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
6497 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
6498 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
6499 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
6500 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
6501 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
6502 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
6503 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
6504 /* The click modifier is denoted by the absence of other modifiers. */
6508 mod_len
= p
- new_mods
;
6512 Lisp_Object new_name
;
6514 new_name
= make_uninit_multibyte_string (mod_len
+ base_len
,
6515 mod_len
+ base_len_byte
);
6516 bcopy (new_mods
, SDATA (new_name
), mod_len
);
6517 bcopy (base
, SDATA (new_name
) + mod_len
, base_len_byte
);
6519 return Fintern (new_name
, Qnil
);
6524 static const char *modifier_names
[] =
6526 "up", "down", "drag", "click", "double", "triple", 0, 0,
6527 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6528 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
6530 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
6532 static Lisp_Object modifier_symbols
;
6534 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
6536 lispy_modifier_list (modifiers
)
6539 Lisp_Object modifier_list
;
6542 modifier_list
= Qnil
;
6543 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
6544 if (modifiers
& (1<<i
))
6545 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
6548 return modifier_list
;
6552 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
6553 where UNMODIFIED is the unmodified form of SYMBOL,
6554 MASK is the set of modifiers present in SYMBOL's name.
6555 This is similar to parse_modifiers_uncached, but uses the cache in
6556 SYMBOL's Qevent_symbol_element_mask property, and maintains the
6557 Qevent_symbol_elements property. */
6559 #define KEY_TO_CHAR(k) (XINT (k) & ((1 << CHARACTERBITS) - 1))
6562 parse_modifiers (symbol
)
6565 Lisp_Object elements
;
6567 if (INTEGERP (symbol
))
6568 return (Fcons (make_number (KEY_TO_CHAR (symbol
)),
6569 Fcons (make_number (XINT (symbol
) & CHAR_MODIFIER_MASK
),
6571 else if (!SYMBOLP (symbol
))
6574 elements
= Fget (symbol
, Qevent_symbol_element_mask
);
6575 if (CONSP (elements
))
6580 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
6581 Lisp_Object unmodified
;
6584 unmodified
= Fintern (make_string (SDATA (SYMBOL_NAME (symbol
)) + end
,
6585 SBYTES (SYMBOL_NAME (symbol
)) - end
),
6588 if (modifiers
& ~INTMASK
)
6590 XSETFASTINT (mask
, modifiers
);
6591 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
6593 /* Cache the parsing results on SYMBOL. */
6594 Fput (symbol
, Qevent_symbol_element_mask
,
6596 Fput (symbol
, Qevent_symbol_elements
,
6597 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
6599 /* Since we know that SYMBOL is modifiers applied to unmodified,
6600 it would be nice to put that in unmodified's cache.
6601 But we can't, since we're not sure that parse_modifiers is
6608 DEFUN ("internal-event-symbol-parse-modifiers", Fevent_symbol_parse_modifiers
,
6609 Sevent_symbol_parse_modifiers
, 1, 1, 0,
6610 doc
: /* Parse the event symbol. For internal use. */)
6614 /* Fill the cache if needed. */
6615 parse_modifiers (symbol
);
6616 /* Ignore the result (which is stored on Qevent_symbol_element_mask)
6617 and use the Lispier representation stored on Qevent_symbol_elements
6619 return Fget (symbol
, Qevent_symbol_elements
);
6622 /* Apply the modifiers MODIFIERS to the symbol BASE.
6623 BASE must be unmodified.
6625 This is like apply_modifiers_uncached, but uses BASE's
6626 Qmodifier_cache property, if present. It also builds
6627 Qevent_symbol_elements properties, since it has that info anyway.
6629 apply_modifiers copies the value of BASE's Qevent_kind property to
6630 the modified symbol. */
6632 apply_modifiers (modifiers
, base
)
6636 Lisp_Object cache
, index
, entry
, new_symbol
;
6638 /* Mask out upper bits. We don't know where this value's been. */
6639 modifiers
&= INTMASK
;
6641 if (INTEGERP (base
))
6642 return make_number (XINT (base
) | modifiers
);
6644 /* The click modifier never figures into cache indices. */
6645 cache
= Fget (base
, Qmodifier_cache
);
6646 XSETFASTINT (index
, (modifiers
& ~click_modifier
));
6647 entry
= assq_no_quit (index
, cache
);
6650 new_symbol
= XCDR (entry
);
6653 /* We have to create the symbol ourselves. */
6654 new_symbol
= apply_modifiers_uncached (modifiers
,
6655 SDATA (SYMBOL_NAME (base
)),
6656 SCHARS (SYMBOL_NAME (base
)),
6657 SBYTES (SYMBOL_NAME (base
)));
6659 /* Add the new symbol to the base's cache. */
6660 entry
= Fcons (index
, new_symbol
);
6661 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
6663 /* We have the parsing info now for free, so we could add it to
6665 XSETFASTINT (index, modifiers);
6666 Fput (new_symbol, Qevent_symbol_element_mask,
6667 Fcons (base, Fcons (index, Qnil)));
6668 Fput (new_symbol, Qevent_symbol_elements,
6669 Fcons (base, lispy_modifier_list (modifiers)));
6670 Sadly, this is only correct if `base' is indeed a base event,
6671 which is not necessarily the case. -stef */
6674 /* Make sure this symbol is of the same kind as BASE.
6676 You'd think we could just set this once and for all when we
6677 intern the symbol above, but reorder_modifiers may call us when
6678 BASE's property isn't set right; we can't assume that just
6679 because it has a Qmodifier_cache property it must have its
6680 Qevent_kind set right as well. */
6681 if (NILP (Fget (new_symbol
, Qevent_kind
)))
6685 kind
= Fget (base
, Qevent_kind
);
6687 Fput (new_symbol
, Qevent_kind
, kind
);
6694 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
6695 return a symbol with the modifiers placed in the canonical order.
6696 Canonical order is alphabetical, except for down and drag, which
6697 always come last. The 'click' modifier is never written out.
6699 Fdefine_key calls this to make sure that (for example) C-M-foo
6700 and M-C-foo end up being equivalent in the keymap. */
6703 reorder_modifiers (symbol
)
6706 /* It's hopefully okay to write the code this way, since everything
6707 will soon be in caches, and no consing will be done at all. */
6710 parsed
= parse_modifiers (symbol
);
6711 return apply_modifiers ((int) XINT (XCAR (XCDR (parsed
))),
6716 /* For handling events, we often want to produce a symbol whose name
6717 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
6718 to some base, like the name of a function key or mouse button.
6719 modify_event_symbol produces symbols of this sort.
6721 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
6722 is the name of the i'th symbol. TABLE_SIZE is the number of elements
6725 Alternatively, NAME_ALIST_OR_STEM is either an alist mapping codes
6726 into symbol names, or a string specifying a name stem used to
6727 construct a symbol name or the form `STEM-N', where N is the decimal
6728 representation of SYMBOL_NUM. NAME_ALIST_OR_STEM is used if it is
6729 non-nil; otherwise NAME_TABLE is used.
6731 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
6732 persist between calls to modify_event_symbol that it can use to
6733 store a cache of the symbols it's generated for this NAME_TABLE
6734 before. The object stored there may be a vector or an alist.
6736 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
6738 MODIFIERS is a set of modifier bits (as given in struct input_events)
6739 whose prefixes should be applied to the symbol name.
6741 SYMBOL_KIND is the value to be placed in the event_kind property of
6742 the returned symbol.
6744 The symbols we create are supposed to have an
6745 `event-symbol-elements' property, which lists the modifiers present
6746 in the symbol's name. */
6749 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_alist_or_stem
,
6750 name_table
, symbol_table
, table_size
)
6753 Lisp_Object symbol_kind
;
6754 Lisp_Object name_alist_or_stem
;
6756 Lisp_Object
*symbol_table
;
6757 unsigned int table_size
;
6760 Lisp_Object symbol_int
;
6762 /* Get rid of the "vendor-specific" bit here. */
6763 XSETINT (symbol_int
, symbol_num
& 0xffffff);
6765 /* Is this a request for a valid symbol? */
6766 if (symbol_num
< 0 || symbol_num
>= table_size
)
6769 if (CONSP (*symbol_table
))
6770 value
= Fcdr (assq_no_quit (symbol_int
, *symbol_table
));
6772 /* If *symbol_table doesn't seem to be initialized properly, fix that.
6773 *symbol_table should be a lisp vector TABLE_SIZE elements long,
6774 where the Nth element is the symbol for NAME_TABLE[N], or nil if
6775 we've never used that symbol before. */
6778 if (! VECTORP (*symbol_table
)
6779 || XVECTOR (*symbol_table
)->size
!= table_size
)
6783 XSETFASTINT (size
, table_size
);
6784 *symbol_table
= Fmake_vector (size
, Qnil
);
6787 value
= XVECTOR (*symbol_table
)->contents
[symbol_num
];
6790 /* Have we already used this symbol before? */
6793 /* No; let's create it. */
6794 if (CONSP (name_alist_or_stem
))
6795 value
= Fcdr_safe (Fassq (symbol_int
, name_alist_or_stem
));
6796 else if (STRINGP (name_alist_or_stem
))
6798 int len
= SBYTES (name_alist_or_stem
);
6799 char *buf
= (char *) alloca (len
+ 50);
6800 sprintf (buf
, "%s-%ld", SDATA (name_alist_or_stem
),
6801 (long) XINT (symbol_int
) + 1);
6802 value
= intern (buf
);
6804 else if (name_table
!= 0 && name_table
[symbol_num
])
6805 value
= intern (name_table
[symbol_num
]);
6807 #ifdef HAVE_WINDOW_SYSTEM
6810 char *name
= x_get_keysym_name (symbol_num
);
6812 value
= intern (name
);
6819 sprintf (buf
, "key-%d", symbol_num
);
6820 value
= intern (buf
);
6823 if (CONSP (*symbol_table
))
6824 *symbol_table
= Fcons (Fcons (symbol_int
, value
), *symbol_table
);
6826 XVECTOR (*symbol_table
)->contents
[symbol_num
] = value
;
6828 /* Fill in the cache entries for this symbol; this also
6829 builds the Qevent_symbol_elements property, which the user
6831 apply_modifiers (modifiers
& click_modifier
, value
);
6832 Fput (value
, Qevent_kind
, symbol_kind
);
6835 /* Apply modifiers to that symbol. */
6836 return apply_modifiers (modifiers
, value
);
6839 /* Convert a list that represents an event type,
6840 such as (ctrl meta backspace), into the usual representation of that
6841 event type as a number or a symbol. */
6843 DEFUN ("event-convert-list", Fevent_convert_list
, Sevent_convert_list
, 1, 1, 0,
6844 doc
: /* Convert the event description list EVENT-DESC to an event type.
6845 EVENT-DESC should contain one base event type (a character or symbol)
6846 and zero or more modifier names (control, meta, hyper, super, shift, alt,
6847 drag, down, double or triple). The base must be last.
6848 The return value is an event type (a character or symbol) which
6849 has the same base event type and all the specified modifiers. */)
6851 Lisp_Object event_desc
;
6859 while (CONSP (rest
))
6867 /* Given a symbol, see if it is a modifier name. */
6868 if (SYMBOLP (elt
) && CONSP (rest
))
6869 this = parse_solitary_modifier (elt
);
6873 else if (!NILP (base
))
6874 error ("Two bases given in one event");
6880 /* Let the symbol A refer to the character A. */
6881 if (SYMBOLP (base
) && SCHARS (SYMBOL_NAME (base
)) == 1)
6882 XSETINT (base
, SREF (SYMBOL_NAME (base
), 0));
6884 if (INTEGERP (base
))
6886 /* Turn (shift a) into A. */
6887 if ((modifiers
& shift_modifier
) != 0
6888 && (XINT (base
) >= 'a' && XINT (base
) <= 'z'))
6890 XSETINT (base
, XINT (base
) - ('a' - 'A'));
6891 modifiers
&= ~shift_modifier
;
6894 /* Turn (control a) into C-a. */
6895 if (modifiers
& ctrl_modifier
)
6896 return make_number ((modifiers
& ~ctrl_modifier
)
6897 | make_ctrl_char (XINT (base
)));
6899 return make_number (modifiers
| XINT (base
));
6901 else if (SYMBOLP (base
))
6902 return apply_modifiers (modifiers
, base
);
6905 error ("Invalid base event");
6910 /* Try to recognize SYMBOL as a modifier name.
6911 Return the modifier flag bit, or 0 if not recognized. */
6914 parse_solitary_modifier (Lisp_Object symbol
)
6916 Lisp_Object name
= SYMBOL_NAME (symbol
);
6918 switch (SREF (name
, 0))
6920 #define SINGLE_LETTER_MOD(BIT) \
6921 if (SBYTES (name) == 1) \
6924 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
6925 if (LEN == SBYTES (name) \
6926 && ! strncmp (SDATA (name), NAME, LEN)) \
6930 SINGLE_LETTER_MOD (alt_modifier
);
6934 MULTI_LETTER_MOD (alt_modifier
, "alt", 3);
6938 SINGLE_LETTER_MOD (ctrl_modifier
);
6942 MULTI_LETTER_MOD (ctrl_modifier
, "ctrl", 4);
6943 MULTI_LETTER_MOD (ctrl_modifier
, "control", 7);
6947 SINGLE_LETTER_MOD (hyper_modifier
);
6951 MULTI_LETTER_MOD (hyper_modifier
, "hyper", 5);
6955 SINGLE_LETTER_MOD (meta_modifier
);
6959 MULTI_LETTER_MOD (meta_modifier
, "meta", 4);
6963 SINGLE_LETTER_MOD (shift_modifier
);
6967 MULTI_LETTER_MOD (shift_modifier
, "shift", 5);
6968 MULTI_LETTER_MOD (super_modifier
, "super", 5);
6969 SINGLE_LETTER_MOD (super_modifier
);
6973 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
6974 MULTI_LETTER_MOD (down_modifier
, "down", 4);
6975 MULTI_LETTER_MOD (double_modifier
, "double", 6);
6979 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
6982 #undef SINGLE_LETTER_MOD
6983 #undef MULTI_LETTER_MOD
6989 /* Return 1 if EVENT is a list whose elements are all integers or symbols.
6990 Such a list is not valid as an event,
6991 but it can be a Lucid-style event type list. */
6994 lucid_event_type_list_p (object
)
6999 if (! CONSP (object
))
7002 if (EQ (XCAR (object
), Qhelp_echo
)
7003 || EQ (XCAR (object
), Qvertical_line
)
7004 || EQ (XCAR (object
), Qmode_line
)
7005 || EQ (XCAR (object
), Qheader_line
))
7008 for (tail
= object
; CONSP (tail
); tail
= XCDR (tail
))
7012 if (! (INTEGERP (elt
) || SYMBOLP (elt
)))
7019 /* Store into *addr a value nonzero if terminal input chars are available.
7020 Serves the purpose of ioctl (0, FIONREAD, addr)
7021 but works even if FIONREAD does not exist.
7022 (In fact, this may actually read some input.)
7024 If READABLE_EVENTS_DO_TIMERS_NOW is set in FLAGS, actually run
7025 timer events that are ripe.
7026 If READABLE_EVENTS_FILTER_EVENTS is set in FLAGS, ignore internal
7027 events (FOCUS_IN_EVENT).
7028 If READABLE_EVENTS_IGNORE_SQUEEZABLES is set in FLAGS, ignore mouse
7029 movements and toolkit scroll bar thumb drags. */
7032 get_input_pending (addr
, flags
)
7036 /* First of all, have we already counted some input? */
7037 *addr
= (!NILP (Vquit_flag
) || readable_events (flags
));
7039 /* If input is being read as it arrives, and we have none, there is none. */
7040 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
7043 /* Try to read some input and see how much we get. */
7045 *addr
= (!NILP (Vquit_flag
) || readable_events (flags
));
7048 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
7051 gobble_input (expected
)
7055 /* Read D-Bus messages. */
7056 xd_read_queued_messages ();
7057 #endif /* HAVE_DBUS */
7060 if (interrupt_input
)
7063 mask
= sigblock (sigmask (SIGIO
));
7064 read_avail_input (expected
);
7068 #ifdef POLL_FOR_INPUT
7069 /* XXX This condition was (read_socket_hook && !interrupt_input),
7070 but read_socket_hook is not global anymore. Let's pretend that
7072 if (!interrupt_input
&& poll_suppress_count
== 0)
7075 mask
= sigblock (sigmask (SIGALRM
));
7076 read_avail_input (expected
);
7082 read_avail_input (expected
);
7085 /* Put a BUFFER_SWITCH_EVENT in the buffer
7086 so that read_key_sequence will notice the new current buffer. */
7089 record_asynch_buffer_change ()
7091 struct input_event event
;
7095 event
.kind
= BUFFER_SWITCH_EVENT
;
7096 event
.frame_or_window
= Qnil
;
7100 /* We don't need a buffer-switch event unless Emacs is waiting for input.
7101 The purpose of the event is to make read_key_sequence look up the
7102 keymaps again. If we aren't in read_key_sequence, we don't need one,
7103 and the event could cause trouble by messing up (input-pending-p). */
7104 tem
= Fwaiting_for_user_input_p ();
7108 /* We never need these events if we have no asynchronous subprocesses. */
7112 /* Make sure no interrupt happens while storing the event. */
7114 if (interrupt_input
)
7117 mask
= sigblock (sigmask (SIGIO
));
7118 kbd_buffer_store_event (&event
);
7125 kbd_buffer_store_event (&event
);
7130 /* Read any terminal input already buffered up by the system
7131 into the kbd_buffer, but do not wait.
7133 EXPECTED should be nonzero if the caller knows there is some input.
7135 Returns the number of keyboard chars read, or -1 meaning
7136 this is a bad time to try to read input. */
7139 read_avail_input (expected
)
7146 /* Store pending user signal events, if any. */
7147 if (store_user_signal_events ())
7150 /* Loop through the available terminals, and call their input hooks. */
7154 struct terminal
*next
= t
->next_terminal
;
7156 if (t
->read_socket_hook
)
7159 struct input_event hold_quit
;
7161 EVENT_INIT (hold_quit
);
7162 hold_quit
.kind
= NO_EVENT
;
7164 /* No need for FIONREAD or fcntl; just say don't wait. */
7165 while (nr
= (*t
->read_socket_hook
) (t
, expected
, &hold_quit
), nr
> 0)
7171 if (nr
== -1) /* Not OK to read input now. */
7175 else if (nr
== -2) /* Non-transient error. */
7177 /* The terminal device terminated; it should be closed. */
7179 /* Kill Emacs if this was our last terminal. */
7180 if (!terminal_list
->next_terminal
)
7181 /* Formerly simply reported no input, but that
7182 sometimes led to a failure of Emacs to terminate.
7183 SIGHUP seems appropriate if we can't reach the
7185 /* ??? Is it really right to send the signal just to
7186 this process rather than to the whole process
7187 group? Perhaps on systems with FIONREAD Emacs is
7188 alone in its group. */
7189 kill (getpid (), SIGHUP
);
7191 /* XXX Is calling delete_terminal safe here? It calls delete_frame. */
7194 XSETTERMINAL (tmp
, t
);
7195 Fdelete_terminal (tmp
, Qnoelisp
);
7199 if (hold_quit
.kind
!= NO_EVENT
)
7200 kbd_buffer_store_event (&hold_quit
);
7209 frame_make_pointer_visible ();
7215 decode_keyboard_code (struct tty_display_info
*tty
,
7216 struct coding_system
*coding
,
7217 unsigned char *buf
, int nbytes
)
7219 unsigned char *src
= buf
;
7220 const unsigned char *p
;
7225 if (tty
->meta_key
!= 2)
7226 for (i
= 0; i
< nbytes
; i
++)
7228 if (coding
->carryover_bytes
> 0)
7230 src
= alloca (coding
->carryover_bytes
+ nbytes
);
7231 memcpy (src
, coding
->carryover
, coding
->carryover_bytes
);
7232 memcpy (src
+ coding
->carryover_bytes
, buf
, nbytes
);
7233 nbytes
+= coding
->carryover_bytes
;
7235 coding
->destination
= alloca (nbytes
* 4);
7236 coding
->dst_bytes
= nbytes
* 4;
7237 decode_coding_c_string (coding
, src
, nbytes
, Qnil
);
7238 if (coding
->produced_char
== 0)
7240 for (i
= 0, p
= coding
->destination
; i
< coding
->produced_char
; i
++)
7242 struct input_event buf
;
7245 buf
.code
= STRING_CHAR_ADVANCE (p
);
7246 buf
.kind
= (ASCII_CHAR_P (buf
.code
)
7247 ? ASCII_KEYSTROKE_EVENT
: MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
7248 /* See the comment in tty_read_avail_input. */
7249 buf
.frame_or_window
= tty
->top_frame
;
7251 kbd_buffer_store_event (&buf
);
7255 /* This is the tty way of reading available input.
7257 Note that each terminal device has its own `struct terminal' object,
7258 and so this function is called once for each individual termcap
7259 terminal. The first parameter indicates which terminal to read from. */
7262 tty_read_avail_input (struct terminal
*terminal
,
7264 struct input_event
*hold_quit
)
7266 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
7267 the kbd_buffer can really hold. That may prevent loss
7268 of characters on some systems when input is stuffed at us. */
7269 unsigned char cbuf
[KBD_BUFFER_SIZE
- 1];
7271 struct tty_display_info
*tty
= terminal
->display_info
.tty
;
7274 if (!terminal
->name
) /* Don't read from a dead terminal. */
7277 if (terminal
->type
!= output_termcap
7278 && terminal
->type
!= output_msdos_raw
)
7281 /* XXX I think the following code should be moved to separate hook
7282 functions in system-dependent files. */
7285 #else /* not WINDOWSNT */
7286 if (! tty
->term_initted
) /* In case we get called during bootstrap. */
7290 return 0; /* The terminal is suspended. */
7293 n_to_read
= dos_keysns ();
7297 cbuf
[0] = dos_keyread ();
7300 #else /* not MSDOS */
7305 struct input_event hold_quit
;
7306 int gpm
, fd
= gpm_fd
;
7308 EVENT_INIT (hold_quit
);
7309 hold_quit
.kind
= NO_EVENT
;
7311 /* gpm==1 if event received.
7312 gpm==0 if the GPM daemon has closed the connection, in which case
7313 Gpm_GetEvent closes gpm_fd and clears it to -1, which is why
7314 we save it in `fd' so close_gpm can remove it from the
7316 gpm==-1 if a protocol error or EWOULDBLOCK; the latter is normal. */
7317 while (gpm
= Gpm_GetEvent (&event
), gpm
== 1) {
7318 nread
+= handle_one_term_event (tty
, &event
, &hold_quit
);
7321 /* Presumably the GPM daemon has closed the connection. */
7323 if (hold_quit
.kind
!= NO_EVENT
)
7324 kbd_buffer_store_event (&hold_quit
);
7328 #endif /* HAVE_GPM */
7330 /* Determine how many characters we should *try* to read. */
7332 /* Find out how much input is available. */
7333 if (ioctl (fileno (tty
->input
), FIONREAD
, &n_to_read
) < 0)
7335 if (! noninteractive
)
7336 return -2; /* Close this terminal. */
7342 if (n_to_read
> sizeof cbuf
)
7343 n_to_read
= sizeof cbuf
;
7344 #else /* no FIONREAD */
7345 #if defined (USG) || defined(CYGWIN)
7346 /* Read some input if available, but don't wait. */
7347 n_to_read
= sizeof cbuf
;
7348 fcntl (fileno (tty
->input
), F_SETFL
, O_NDELAY
);
7354 /* Now read; for one reason or another, this will not block.
7355 NREAD is set to the number of chars read. */
7358 nread
= emacs_read (fileno (tty
->input
), cbuf
, n_to_read
);
7359 /* POSIX infers that processes which are not in the session leader's
7360 process group won't get SIGHUP's at logout time. BSDI adheres to
7361 this part standard and returns -1 from read (0) with errno==EIO
7362 when the control tty is taken away.
7363 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
7364 if (nread
== -1 && errno
== EIO
)
7365 return -2; /* Close this terminal. */
7366 #if defined (AIX) && defined (_BSD)
7367 /* The kernel sometimes fails to deliver SIGHUP for ptys.
7368 This looks incorrect, but it isn't, because _BSD causes
7369 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
7370 and that causes a value other than 0 when there is no input. */
7372 return -2; /* Close this terminal. */
7376 /* We used to retry the read if it was interrupted.
7377 But this does the wrong thing when O_NDELAY causes
7378 an EAGAIN error. Does anybody know of a situation
7379 where a retry is actually needed? */
7381 nread
< 0 && (errno
== EAGAIN
7395 #if defined (USG) || defined (CYGWIN)
7396 fcntl (fileno (tty
->input
), F_SETFL
, 0);
7397 #endif /* USG or CYGWIN */
7398 #endif /* no FIONREAD */
7403 #endif /* not MSDOS */
7404 #endif /* not WINDOWSNT */
7406 if (TERMINAL_KEYBOARD_CODING (terminal
)->common_flags
7407 & CODING_REQUIRE_DECODING_MASK
)
7409 struct coding_system
*coding
= TERMINAL_KEYBOARD_CODING (terminal
);
7412 /* Decode the key sequence except for those with meta
7414 for (i
= from
= 0; ; i
++)
7415 if (i
== nread
|| (tty
->meta_key
== 1 && (cbuf
[i
] & 0x80)))
7417 struct input_event buf
;
7419 decode_keyboard_code (tty
, coding
, cbuf
+ from
, i
- from
);
7424 buf
.kind
= ASCII_KEYSTROKE_EVENT
;
7425 buf
.modifiers
= meta_modifier
;
7426 buf
.code
= cbuf
[i
] & ~0x80;
7427 /* See the comment below. */
7428 buf
.frame_or_window
= tty
->top_frame
;
7430 kbd_buffer_store_event (&buf
);
7436 for (i
= 0; i
< nread
; i
++)
7438 struct input_event buf
;
7440 buf
.kind
= ASCII_KEYSTROKE_EVENT
;
7442 if (tty
->meta_key
== 1 && (cbuf
[i
] & 0x80))
7443 buf
.modifiers
= meta_modifier
;
7444 if (tty
->meta_key
!= 2)
7448 /* Set the frame corresponding to the active tty. Note that the
7449 value of selected_frame is not reliable here, redisplay tends
7450 to temporarily change it. */
7451 buf
.frame_or_window
= tty
->top_frame
;
7454 kbd_buffer_store_event (&buf
);
7455 /* Don't look at input that follows a C-g too closely.
7456 This reduces lossage due to autorepeat on C-g. */
7457 if (buf
.kind
== ASCII_KEYSTROKE_EVENT
7458 && buf
.code
== quit_char
)
7466 handle_async_input ()
7468 interrupt_input_pending
= 0;
7470 pending_signals
= pending_atimers
;
7472 /* Tell ns_read_socket() it is being called asynchronously so it can avoid
7473 doing anything dangerous. */
7480 nread
= read_avail_input (1);
7481 /* -1 means it's not ok to read the input now.
7482 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
7483 0 means there was no keyboard input available. */
7493 process_pending_signals ()
7495 if (interrupt_input_pending
)
7496 handle_async_input ();
7497 do_pending_atimers ();
7500 #ifdef SIGIO /* for entire page */
7501 /* Note SIGIO has been undef'd if FIONREAD is missing. */
7504 input_available_signal (signo
)
7507 /* Must preserve main program's value of errno. */
7508 int old_errno
= errno
;
7509 #if defined (USG) && !defined (POSIX_SIGNALS)
7510 /* USG systems forget handlers when they are used;
7511 must reestablish each time */
7512 signal (signo
, input_available_signal
);
7515 SIGNAL_THREAD_CHECK (signo
);
7518 interrupt_input_pending
= 1;
7519 pending_signals
= 1;
7522 if (input_available_clear_time
)
7523 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
7526 handle_async_input ();
7533 /* Send ourselves a SIGIO.
7535 This function exists so that the UNBLOCK_INPUT macro in
7536 blockinput.h can have some way to take care of input we put off
7537 dealing with, without assuming that every file which uses
7538 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
7540 reinvoke_input_signal ()
7543 handle_async_input ();
7549 /* User signal events. */
7551 struct user_signal_info
7553 /* Signal number. */
7556 /* Name of the signal. */
7559 /* Number of pending signals. */
7562 struct user_signal_info
*next
;
7565 /* List of user signals. */
7566 static struct user_signal_info
*user_signals
= NULL
;
7569 add_user_signal (sig
, name
)
7573 struct user_signal_info
*p
;
7575 for (p
= user_signals
; p
; p
= p
->next
)
7577 /* Already added. */
7580 p
= xmalloc (sizeof (struct user_signal_info
));
7582 p
->name
= xstrdup (name
);
7584 p
->next
= user_signals
;
7587 signal (sig
, handle_user_signal
);
7591 handle_user_signal (sig
)
7594 int old_errno
= errno
;
7595 struct user_signal_info
*p
;
7597 #if defined (USG) && !defined (POSIX_SIGNALS)
7598 /* USG systems forget handlers when they are used;
7599 must reestablish each time */
7600 signal (sig
, handle_user_signal
);
7603 SIGNAL_THREAD_CHECK (sig
);
7605 for (p
= user_signals
; p
; p
= p
->next
)
7610 if (interrupt_input
)
7611 kill (getpid (), SIGIO
);
7615 /* Tell wait_reading_process_output that it needs to wake
7616 up and look around. */
7617 if (input_available_clear_time
)
7618 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
7627 find_user_signal_name (sig
)
7630 struct user_signal_info
*p
;
7632 for (p
= user_signals
; p
; p
= p
->next
)
7640 store_user_signal_events ()
7642 struct user_signal_info
*p
;
7643 struct input_event buf
;
7646 for (p
= user_signals
; p
; p
= p
->next
)
7647 if (p
->npending
> 0)
7653 bzero (&buf
, sizeof buf
);
7654 buf
.kind
= USER_SIGNAL_EVENT
;
7655 buf
.frame_or_window
= selected_frame
;
7657 nstored
+= p
->npending
;
7659 mask
= sigblock (sigmask (p
->sig
));
7663 kbd_buffer_store_event (&buf
);
7666 while (p
->npending
> 0);
7674 static void menu_bar_item
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
, void*));
7675 static Lisp_Object menu_bar_one_keymap_changed_items
;
7677 /* These variables hold the vector under construction within
7678 menu_bar_items and its subroutines, and the current index
7679 for storing into that vector. */
7680 static Lisp_Object menu_bar_items_vector
;
7681 static int menu_bar_items_index
;
7683 /* Return a vector of menu items for a menu bar, appropriate
7684 to the current buffer. Each item has three elements in the vector:
7687 OLD is an old vector we can optionally reuse, or nil. */
7690 menu_bar_items (old
)
7693 /* The number of keymaps we're scanning right now, and the number of
7694 keymaps we have allocated space for. */
7697 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
7698 in the current keymaps, or nil where it is not a prefix. */
7701 Lisp_Object def
, tail
;
7710 /* In order to build the menus, we need to call the keymap
7711 accessors. They all call QUIT. But this function is called
7712 during redisplay, during which a quit is fatal. So inhibit
7713 quitting while building the menus.
7714 We do this instead of specbind because (1) errors will clear it anyway
7715 and (2) this avoids risk of specpdl overflow. */
7716 oquit
= Vinhibit_quit
;
7720 menu_bar_items_vector
= old
;
7722 menu_bar_items_vector
= Fmake_vector (make_number (24), Qnil
);
7723 menu_bar_items_index
= 0;
7725 /* Build our list of keymaps.
7726 If we recognize a function key and replace its escape sequence in
7727 keybuf with its symbol, or if the sequence starts with a mouse
7728 click and we need to switch buffers, we jump back here to rebuild
7729 the initial keymaps from the current buffer. */
7733 /* Should overriding-terminal-local-map and overriding-local-map apply? */
7734 if (!NILP (Voverriding_local_map_menu_flag
))
7736 /* Yes, use them (if non-nil) as well as the global map. */
7737 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
7739 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
7740 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
7741 if (!NILP (Voverriding_local_map
))
7742 maps
[nmaps
++] = Voverriding_local_map
;
7746 /* No, so use major and minor mode keymaps and keymap property.
7747 Note that menu-bar bindings in the local-map and keymap
7748 properties may not work reliable, as they are only
7749 recognized when the menu-bar (or mode-line) is updated,
7750 which does not normally happen after every command. */
7753 nminor
= current_minor_maps (NULL
, &tmaps
);
7754 maps
= (Lisp_Object
*) alloca ((nminor
+ 3) * sizeof (maps
[0]));
7756 if (tem
= get_local_map (PT
, current_buffer
, Qkeymap
), !NILP (tem
))
7757 maps
[nmaps
++] = tem
;
7758 bcopy (tmaps
, (void *) (maps
+ nmaps
), nminor
* sizeof (maps
[0]));
7760 maps
[nmaps
++] = get_local_map (PT
, current_buffer
, Qlocal_map
);
7762 maps
[nmaps
++] = current_global_map
;
7765 /* Look up in each map the dummy prefix key `menu-bar'. */
7769 for (mapno
= nmaps
- 1; mapno
>= 0; mapno
--)
7770 if (!NILP (maps
[mapno
]))
7772 def
= get_keymap (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0, 1),
7776 menu_bar_one_keymap_changed_items
= Qnil
;
7777 map_keymap (def
, menu_bar_item
, Qnil
, NULL
, 1);
7781 /* Move to the end those items that should be at the end. */
7783 for (tail
= Vmenu_bar_final_items
; CONSP (tail
); tail
= XCDR (tail
))
7786 int end
= menu_bar_items_index
;
7788 for (i
= 0; i
< end
; i
+= 4)
7789 if (EQ (XCAR (tail
), XVECTOR (menu_bar_items_vector
)->contents
[i
]))
7791 Lisp_Object tem0
, tem1
, tem2
, tem3
;
7792 /* Move the item at index I to the end,
7793 shifting all the others forward. */
7794 tem0
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 0];
7795 tem1
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 1];
7796 tem2
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
7797 tem3
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3];
7799 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
7800 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
7801 (end
- i
- 4) * sizeof (Lisp_Object
));
7802 XVECTOR (menu_bar_items_vector
)->contents
[end
- 4] = tem0
;
7803 XVECTOR (menu_bar_items_vector
)->contents
[end
- 3] = tem1
;
7804 XVECTOR (menu_bar_items_vector
)->contents
[end
- 2] = tem2
;
7805 XVECTOR (menu_bar_items_vector
)->contents
[end
- 1] = tem3
;
7810 /* Add nil, nil, nil, nil at the end. */
7811 i
= menu_bar_items_index
;
7812 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
7813 menu_bar_items_vector
= larger_vector (menu_bar_items_vector
, 2 * i
, Qnil
);
7814 /* Add this item. */
7815 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
7816 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
7817 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
7818 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
7819 menu_bar_items_index
= i
;
7821 Vinhibit_quit
= oquit
;
7822 return menu_bar_items_vector
;
7825 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
7826 If there's already an item for KEY, add this DEF to it. */
7828 Lisp_Object item_properties
;
7831 menu_bar_item (key
, item
, dummy1
, dummy2
)
7832 Lisp_Object key
, item
, dummy1
;
7835 struct gcpro gcpro1
;
7839 if (EQ (item
, Qundefined
))
7841 /* If a map has an explicit `undefined' as definition,
7842 discard any previously made menu bar item. */
7844 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
7845 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
7847 if (menu_bar_items_index
> i
+ 4)
7848 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
7849 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
7850 (menu_bar_items_index
- i
- 4) * sizeof (Lisp_Object
));
7851 menu_bar_items_index
-= 4;
7855 /* If this keymap has already contributed to this KEY,
7856 don't contribute to it a second time. */
7857 tem
= Fmemq (key
, menu_bar_one_keymap_changed_items
);
7858 if (!NILP (tem
) || NILP (item
))
7861 menu_bar_one_keymap_changed_items
7862 = Fcons (key
, menu_bar_one_keymap_changed_items
);
7864 /* We add to menu_bar_one_keymap_changed_items before doing the
7865 parse_menu_item, so that if it turns out it wasn't a menu item,
7866 it still correctly hides any further menu item. */
7868 i
= parse_menu_item (item
, 1);
7873 item
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
7875 /* Find any existing item for this KEY. */
7876 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
7877 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
7880 /* If we did not find this KEY, add it at the end. */
7881 if (i
== menu_bar_items_index
)
7883 /* If vector is too small, get a bigger one. */
7884 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
7885 menu_bar_items_vector
= larger_vector (menu_bar_items_vector
, 2 * i
, Qnil
);
7886 /* Add this item. */
7887 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = key
;
7888 XVECTOR (menu_bar_items_vector
)->contents
[i
++]
7889 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
7890 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Fcons (item
, Qnil
);
7891 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = make_number (0);
7892 menu_bar_items_index
= i
;
7894 /* We did find an item for this KEY. Add ITEM to its list of maps. */
7898 old
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
7899 /* If the new and the old items are not both keymaps,
7900 the lookup will only find `item'. */
7901 item
= Fcons (item
, KEYMAPP (item
) && KEYMAPP (XCAR (old
)) ? old
: Qnil
);
7902 XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2] = item
;
7906 /* This is used as the handler when calling menu_item_eval_property. */
7908 menu_item_eval_property_1 (arg
)
7911 /* If we got a quit from within the menu computation,
7912 quit all the way out of it. This takes care of C-] in the debugger. */
7913 if (CONSP (arg
) && EQ (XCAR (arg
), Qquit
))
7914 Fsignal (Qquit
, Qnil
);
7919 /* Evaluate an expression and return the result (or nil if something
7920 went wrong). Used to evaluate dynamic parts of menu items. */
7922 menu_item_eval_property (sexpr
)
7925 int count
= SPECPDL_INDEX ();
7927 specbind (Qinhibit_redisplay
, Qt
);
7928 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
,
7929 menu_item_eval_property_1
);
7930 return unbind_to (count
, val
);
7933 /* This function parses a menu item and leaves the result in the
7934 vector item_properties.
7935 ITEM is a key binding, a possible menu item.
7936 INMENUBAR is > 0 when this is considered for an entry in a menu bar
7938 INMENUBAR is < 0 when this is considered for an entry in a keyboard menu.
7939 parse_menu_item returns true if the item is a menu item and false
7943 parse_menu_item (item
, inmenubar
)
7947 Lisp_Object def
, tem
, item_string
, start
;
7949 Lisp_Object keyhint
;
7958 /* Create item_properties vector if necessary. */
7959 if (NILP (item_properties
))
7961 = Fmake_vector (make_number (ITEM_PROPERTY_ENABLE
+ 1), Qnil
);
7963 /* Initialize optional entries. */
7964 for (i
= ITEM_PROPERTY_DEF
; i
< ITEM_PROPERTY_ENABLE
; i
++)
7965 ASET (item_properties
, i
, Qnil
);
7966 ASET (item_properties
, ITEM_PROPERTY_ENABLE
, Qt
);
7968 /* Save the item here to protect it from GC. */
7969 ASET (item_properties
, ITEM_PROPERTY_ITEM
, item
);
7971 item_string
= XCAR (item
);
7975 if (STRINGP (item_string
))
7977 /* Old format menu item. */
7978 ASET (item_properties
, ITEM_PROPERTY_NAME
, item_string
);
7980 /* Maybe help string. */
7981 if (CONSP (item
) && STRINGP (XCAR (item
)))
7983 ASET (item_properties
, ITEM_PROPERTY_HELP
, XCAR (item
));
7988 /* Maybe an obsolete key binding cache. */
7989 if (CONSP (item
) && CONSP (XCAR (item
))
7990 && (NILP (XCAR (XCAR (item
)))
7991 || VECTORP (XCAR (XCAR (item
)))))
7994 /* This is the real definition--the function to run. */
7995 ASET (item_properties
, ITEM_PROPERTY_DEF
, item
);
7997 /* Get enable property, if any. */
8000 tem
= Fget (item
, Qmenu_enable
);
8001 if (!NILP (Venable_disabled_menus_and_buttons
))
8002 ASET (item_properties
, ITEM_PROPERTY_ENABLE
, Qt
);
8003 else if (!NILP (tem
))
8004 ASET (item_properties
, ITEM_PROPERTY_ENABLE
, tem
);
8007 else if (EQ (item_string
, Qmenu_item
) && CONSP (item
))
8009 /* New format menu item. */
8010 ASET (item_properties
, ITEM_PROPERTY_NAME
, XCAR (item
));
8011 start
= XCDR (item
);
8014 /* We have a real binding. */
8015 ASET (item_properties
, ITEM_PROPERTY_DEF
, XCAR (start
));
8017 item
= XCDR (start
);
8018 /* Is there an obsolete cache list with key equivalences. */
8019 if (CONSP (item
) && CONSP (XCAR (item
)))
8022 /* Parse properties. */
8023 while (CONSP (item
) && CONSP (XCDR (item
)))
8028 if (EQ (tem
, QCenable
))
8030 if (!NILP (Venable_disabled_menus_and_buttons
))
8031 ASET (item_properties
, ITEM_PROPERTY_ENABLE
, Qt
);
8033 ASET (item_properties
, ITEM_PROPERTY_ENABLE
, XCAR (item
));
8035 else if (EQ (tem
, QCvisible
))
8037 /* If got a visible property and that evaluates to nil
8038 then ignore this item. */
8039 tem
= menu_item_eval_property (XCAR (item
));
8043 else if (EQ (tem
, QChelp
))
8044 ASET (item_properties
, ITEM_PROPERTY_HELP
, XCAR (item
));
8045 else if (EQ (tem
, QCfilter
))
8047 else if (EQ (tem
, QCkey_sequence
))
8050 if (SYMBOLP (tem
) || STRINGP (tem
) || VECTORP (tem
))
8051 /* Be GC protected. Set keyhint to item instead of tem. */
8054 else if (EQ (tem
, QCkeys
))
8057 if (CONSP (tem
) || STRINGP (tem
))
8058 ASET (item_properties
, ITEM_PROPERTY_KEYEQ
, tem
);
8060 else if (EQ (tem
, QCbutton
) && CONSP (XCAR (item
)))
8065 if (EQ (type
, QCtoggle
) || EQ (type
, QCradio
))
8067 ASET (item_properties
, ITEM_PROPERTY_SELECTED
,
8069 ASET (item_properties
, ITEM_PROPERTY_TYPE
, type
);
8075 else if (inmenubar
|| !NILP (start
))
8079 return 0; /* not a menu item */
8081 /* If item string is not a string, evaluate it to get string.
8082 If we don't get a string, skip this item. */
8083 item_string
= AREF (item_properties
, ITEM_PROPERTY_NAME
);
8084 if (!(STRINGP (item_string
)))
8086 item_string
= menu_item_eval_property (item_string
);
8087 if (!STRINGP (item_string
))
8089 ASET (item_properties
, ITEM_PROPERTY_NAME
, item_string
);
8092 /* If got a filter apply it on definition. */
8093 def
= AREF (item_properties
, ITEM_PROPERTY_DEF
);
8096 def
= menu_item_eval_property (list2 (XCAR (filter
),
8097 list2 (Qquote
, def
)));
8099 ASET (item_properties
, ITEM_PROPERTY_DEF
, def
);
8102 /* Enable or disable selection of item. */
8103 tem
= AREF (item_properties
, ITEM_PROPERTY_ENABLE
);
8106 tem
= menu_item_eval_property (tem
);
8107 if (inmenubar
&& NILP (tem
))
8108 return 0; /* Ignore disabled items in menu bar. */
8109 ASET (item_properties
, ITEM_PROPERTY_ENABLE
, tem
);
8112 /* If we got no definition, this item is just unselectable text which
8113 is OK in a submenu but not in the menubar. */
8115 return (inmenubar
? 0 : 1);
8117 /* See if this is a separate pane or a submenu. */
8118 def
= AREF (item_properties
, ITEM_PROPERTY_DEF
);
8119 tem
= get_keymap (def
, 0, 1);
8120 /* For a subkeymap, just record its details and exit. */
8123 ASET (item_properties
, ITEM_PROPERTY_MAP
, tem
);
8124 ASET (item_properties
, ITEM_PROPERTY_DEF
, tem
);
8128 /* At the top level in the menu bar, do likewise for commands also.
8129 The menu bar does not display equivalent key bindings anyway.
8130 ITEM_PROPERTY_DEF is already set up properly. */
8134 { /* This is a command. See if there is an equivalent key binding. */
8135 Lisp_Object keyeq
= AREF (item_properties
, ITEM_PROPERTY_KEYEQ
);
8137 /* The previous code preferred :key-sequence to :keys, so we
8138 preserve this behavior. */
8139 if (STRINGP (keyeq
) && !CONSP (keyhint
))
8140 keyeq
= Fsubstitute_command_keys (keyeq
);
8143 Lisp_Object prefix
= keyeq
;
8144 Lisp_Object keys
= Qnil
;
8148 def
= XCAR (prefix
);
8149 prefix
= XCDR (prefix
);
8152 def
= AREF (item_properties
, ITEM_PROPERTY_DEF
);
8154 if (CONSP (keyhint
) && !NILP (XCAR (keyhint
)))
8156 keys
= XCAR (keyhint
);
8157 tem
= Fkey_binding (keys
, Qnil
, Qnil
, Qnil
);
8159 /* We have a suggested key. Is it bound to the command? */
8162 /* If the command is an alias for another
8163 (such as lmenu.el set it up), check if the
8164 original command matches the cached command. */
8165 && !(SYMBOLP (def
) && EQ (tem
, XSYMBOL (def
)->function
))))
8170 keys
= Fwhere_is_internal (def
, Qnil
, Qt
, Qnil
, Qnil
);
8174 tem
= Fkey_description (keys
, Qnil
);
8177 if (STRINGP (XCAR (prefix
)))
8178 tem
= concat2 (XCAR (prefix
), tem
);
8179 if (STRINGP (XCDR (prefix
)))
8180 tem
= concat2 (tem
, XCDR (prefix
));
8182 keyeq
= concat2 (build_string (" "), tem
);
8183 /* keyeq = concat3(build_string(" ("),tem,build_string(")")); */
8189 /* If we have an equivalent key binding, use that. */
8190 ASET (item_properties
, ITEM_PROPERTY_KEYEQ
, keyeq
);
8193 /* Include this when menu help is implemented.
8194 tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP];
8195 if (!(NILP (tem) || STRINGP (tem)))
8197 tem = menu_item_eval_property (tem);
8200 XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP] = tem;
8204 /* Handle radio buttons or toggle boxes. */
8205 tem
= AREF (item_properties
, ITEM_PROPERTY_SELECTED
);
8207 ASET (item_properties
, ITEM_PROPERTY_SELECTED
,
8208 menu_item_eval_property (tem
));
8215 /***********************************************************************
8217 ***********************************************************************/
8219 /* A vector holding tool bar items while they are parsed in function
8220 tool_bar_items. Each item occupies TOOL_BAR_ITEM_NSCLOTS elements
8223 static Lisp_Object tool_bar_items_vector
;
8225 /* A vector holding the result of parse_tool_bar_item. Layout is like
8226 the one for a single item in tool_bar_items_vector. */
8228 static Lisp_Object tool_bar_item_properties
;
8230 /* Next free index in tool_bar_items_vector. */
8232 static int ntool_bar_items
;
8234 /* The symbols `tool-bar', `:image' and `:rtl'. */
8236 extern Lisp_Object Qtool_bar
;
8237 Lisp_Object QCimage
;
8240 /* Function prototypes. */
8242 static void init_tool_bar_items
P_ ((Lisp_Object
));
8243 static void process_tool_bar_item
P_ ((Lisp_Object
, Lisp_Object
, Lisp_Object
, void*));
8244 static int parse_tool_bar_item
P_ ((Lisp_Object
, Lisp_Object
));
8245 static void append_tool_bar_item
P_ ((void));
8248 /* Return a vector of tool bar items for keymaps currently in effect.
8249 Reuse vector REUSE if non-nil. Return in *NITEMS the number of
8250 tool bar items found. */
8253 tool_bar_items (reuse
, nitems
)
8264 /* In order to build the menus, we need to call the keymap
8265 accessors. They all call QUIT. But this function is called
8266 during redisplay, during which a quit is fatal. So inhibit
8267 quitting while building the menus. We do this instead of
8268 specbind because (1) errors will clear it anyway and (2) this
8269 avoids risk of specpdl overflow. */
8270 oquit
= Vinhibit_quit
;
8273 /* Initialize tool_bar_items_vector and protect it from GC. */
8274 init_tool_bar_items (reuse
);
8276 /* Build list of keymaps in maps. Set nmaps to the number of maps
8279 /* Should overriding-terminal-local-map and overriding-local-map apply? */
8280 if (!NILP (Voverriding_local_map_menu_flag
))
8282 /* Yes, use them (if non-nil) as well as the global map. */
8283 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
8285 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
8286 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
8287 if (!NILP (Voverriding_local_map
))
8288 maps
[nmaps
++] = Voverriding_local_map
;
8292 /* No, so use major and minor mode keymaps and keymap property.
8293 Note that tool-bar bindings in the local-map and keymap
8294 properties may not work reliable, as they are only
8295 recognized when the tool-bar (or mode-line) is updated,
8296 which does not normally happen after every command. */
8299 nminor
= current_minor_maps (NULL
, &tmaps
);
8300 maps
= (Lisp_Object
*) alloca ((nminor
+ 3) * sizeof (maps
[0]));
8302 if (tem
= get_local_map (PT
, current_buffer
, Qkeymap
), !NILP (tem
))
8303 maps
[nmaps
++] = tem
;
8304 bcopy (tmaps
, (void *) (maps
+ nmaps
), nminor
* sizeof (maps
[0]));
8306 maps
[nmaps
++] = get_local_map (PT
, current_buffer
, Qlocal_map
);
8309 /* Add global keymap at the end. */
8310 maps
[nmaps
++] = current_global_map
;
8312 /* Process maps in reverse order and look up in each map the prefix
8314 for (i
= nmaps
- 1; i
>= 0; --i
)
8315 if (!NILP (maps
[i
]))
8319 keymap
= get_keymap (access_keymap (maps
[i
], Qtool_bar
, 1, 0, 1), 0, 1);
8321 map_keymap (keymap
, process_tool_bar_item
, Qnil
, NULL
, 1);
8324 Vinhibit_quit
= oquit
;
8325 *nitems
= ntool_bar_items
/ TOOL_BAR_ITEM_NSLOTS
;
8326 return tool_bar_items_vector
;
8330 /* Process the definition of KEY which is DEF. */
8333 process_tool_bar_item (key
, def
, data
, args
)
8334 Lisp_Object key
, def
, data
;
8338 extern Lisp_Object Qundefined
;
8339 struct gcpro gcpro1
, gcpro2
;
8341 /* Protect KEY and DEF from GC because parse_tool_bar_item may call
8345 if (EQ (def
, Qundefined
))
8347 /* If a map has an explicit `undefined' as definition,
8348 discard any previously made item. */
8349 for (i
= 0; i
< ntool_bar_items
; i
+= TOOL_BAR_ITEM_NSLOTS
)
8351 Lisp_Object
*v
= XVECTOR (tool_bar_items_vector
)->contents
+ i
;
8353 if (EQ (key
, v
[TOOL_BAR_ITEM_KEY
]))
8355 if (ntool_bar_items
> i
+ TOOL_BAR_ITEM_NSLOTS
)
8356 bcopy (v
+ TOOL_BAR_ITEM_NSLOTS
, v
,
8357 ((ntool_bar_items
- i
- TOOL_BAR_ITEM_NSLOTS
)
8358 * sizeof (Lisp_Object
)));
8359 ntool_bar_items
-= TOOL_BAR_ITEM_NSLOTS
;
8364 else if (parse_tool_bar_item (key
, def
))
8365 /* Append a new tool bar item to tool_bar_items_vector. Accept
8366 more than one definition for the same key. */
8367 append_tool_bar_item ();
8373 /* Parse a tool bar item specification ITEM for key KEY and return the
8374 result in tool_bar_item_properties. Value is zero if ITEM is
8377 ITEM is a list `(menu-item CAPTION BINDING PROPS...)'.
8379 CAPTION is the caption of the item, If it's not a string, it is
8380 evaluated to get a string.
8382 BINDING is the tool bar item's binding. Tool-bar items with keymaps
8383 as binding are currently ignored.
8385 The following properties are recognized:
8389 FORM is evaluated and specifies whether the tool bar item is
8390 enabled or disabled.
8394 FORM is evaluated and specifies whether the tool bar item is visible.
8396 - `:filter FUNCTION'
8398 FUNCTION is invoked with one parameter `(quote BINDING)'. Its
8399 result is stored as the new binding.
8401 - `:button (TYPE SELECTED)'
8403 TYPE must be one of `:radio' or `:toggle'. SELECTED is evaluated
8404 and specifies whether the button is selected (pressed) or not.
8408 IMAGES is either a single image specification or a vector of four
8409 image specifications. See enum tool_bar_item_images.
8411 - `:help HELP-STRING'.
8413 Gives a help string to display for the tool bar item. */
8416 parse_tool_bar_item (key
, item
)
8417 Lisp_Object key
, item
;
8419 /* Access slot with index IDX of vector tool_bar_item_properties. */
8420 #define PROP(IDX) XVECTOR (tool_bar_item_properties)->contents[IDX]
8422 Lisp_Object filter
= Qnil
;
8423 Lisp_Object caption
;
8426 /* Defininition looks like `(menu-item CAPTION BINDING PROPS...)'.
8427 Rule out items that aren't lists, don't start with
8428 `menu-item' or whose rest following `tool-bar-item' is not a
8431 || !EQ (XCAR (item
), Qmenu_item
)
8432 || (item
= XCDR (item
),
8436 /* Create tool_bar_item_properties vector if necessary. Reset it to
8438 if (VECTORP (tool_bar_item_properties
))
8440 for (i
= 0; i
< TOOL_BAR_ITEM_NSLOTS
; ++i
)
8444 tool_bar_item_properties
8445 = Fmake_vector (make_number (TOOL_BAR_ITEM_NSLOTS
), Qnil
);
8448 PROP (TOOL_BAR_ITEM_KEY
) = key
;
8449 PROP (TOOL_BAR_ITEM_ENABLED_P
) = Qt
;
8451 /* Get the caption of the item. If the caption is not a string,
8452 evaluate it to get a string. If we don't get a string, skip this
8454 caption
= XCAR (item
);
8455 if (!STRINGP (caption
))
8457 caption
= menu_item_eval_property (caption
);
8458 if (!STRINGP (caption
))
8461 PROP (TOOL_BAR_ITEM_CAPTION
) = caption
;
8463 /* Give up if rest following the caption is not a list. */
8468 /* Store the binding. */
8469 PROP (TOOL_BAR_ITEM_BINDING
) = XCAR (item
);
8472 /* Ignore cached key binding, if any. */
8473 if (CONSP (item
) && CONSP (XCAR (item
)))
8476 /* Process the rest of the properties. */
8477 for (; CONSP (item
) && CONSP (XCDR (item
)); item
= XCDR (XCDR (item
)))
8479 Lisp_Object key
, value
;
8482 value
= XCAR (XCDR (item
));
8484 if (EQ (key
, QCenable
))
8486 /* `:enable FORM'. */
8487 if (!NILP (Venable_disabled_menus_and_buttons
))
8488 PROP (TOOL_BAR_ITEM_ENABLED_P
) = Qt
;
8490 PROP (TOOL_BAR_ITEM_ENABLED_P
) = value
;
8492 else if (EQ (key
, QCvisible
))
8494 /* `:visible FORM'. If got a visible property and that
8495 evaluates to nil then ignore this item. */
8496 if (NILP (menu_item_eval_property (value
)))
8499 else if (EQ (key
, QChelp
))
8500 /* `:help HELP-STRING'. */
8501 PROP (TOOL_BAR_ITEM_HELP
) = value
;
8502 else if (EQ (key
, QCfilter
))
8503 /* ':filter FORM'. */
8505 else if (EQ (key
, QCbutton
) && CONSP (value
))
8507 /* `:button (TYPE . SELECTED)'. */
8508 Lisp_Object type
, selected
;
8510 type
= XCAR (value
);
8511 selected
= XCDR (value
);
8512 if (EQ (type
, QCtoggle
) || EQ (type
, QCradio
))
8514 PROP (TOOL_BAR_ITEM_SELECTED_P
) = selected
;
8515 PROP (TOOL_BAR_ITEM_TYPE
) = type
;
8518 else if (EQ (key
, QCimage
)
8520 || (VECTORP (value
) && XVECTOR (value
)->size
== 4)))
8521 /* Value is either a single image specification or a vector
8522 of 4 such specifications for the different button states. */
8523 PROP (TOOL_BAR_ITEM_IMAGES
) = value
;
8524 else if (EQ (key
, Qrtl
))
8526 PROP (TOOL_BAR_ITEM_RTL_IMAGE
) = value
;
8529 /* If got a filter apply it on binding. */
8531 PROP (TOOL_BAR_ITEM_BINDING
)
8532 = menu_item_eval_property (list2 (filter
,
8534 PROP (TOOL_BAR_ITEM_BINDING
))));
8536 /* See if the binding is a keymap. Give up if it is. */
8537 if (CONSP (get_keymap (PROP (TOOL_BAR_ITEM_BINDING
), 0, 1)))
8540 /* Enable or disable selection of item. */
8541 if (!EQ (PROP (TOOL_BAR_ITEM_ENABLED_P
), Qt
))
8542 PROP (TOOL_BAR_ITEM_ENABLED_P
)
8543 = menu_item_eval_property (PROP (TOOL_BAR_ITEM_ENABLED_P
));
8545 /* Handle radio buttons or toggle boxes. */
8546 if (!NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
)))
8547 PROP (TOOL_BAR_ITEM_SELECTED_P
)
8548 = menu_item_eval_property (PROP (TOOL_BAR_ITEM_SELECTED_P
));
8556 /* Initialize tool_bar_items_vector. REUSE, if non-nil, is a vector
8557 that can be reused. */
8560 init_tool_bar_items (reuse
)
8563 if (VECTORP (reuse
))
8564 tool_bar_items_vector
= reuse
;
8566 tool_bar_items_vector
= Fmake_vector (make_number (64), Qnil
);
8567 ntool_bar_items
= 0;
8571 /* Append parsed tool bar item properties from
8572 tool_bar_item_properties */
8575 append_tool_bar_item ()
8577 Lisp_Object
*to
, *from
;
8579 /* Enlarge tool_bar_items_vector if necessary. */
8580 if (ntool_bar_items
+ TOOL_BAR_ITEM_NSLOTS
8581 >= XVECTOR (tool_bar_items_vector
)->size
)
8582 tool_bar_items_vector
8583 = larger_vector (tool_bar_items_vector
,
8584 2 * XVECTOR (tool_bar_items_vector
)->size
, Qnil
);
8586 /* Append entries from tool_bar_item_properties to the end of
8587 tool_bar_items_vector. */
8588 to
= XVECTOR (tool_bar_items_vector
)->contents
+ ntool_bar_items
;
8589 from
= XVECTOR (tool_bar_item_properties
)->contents
;
8590 bcopy (from
, to
, TOOL_BAR_ITEM_NSLOTS
* sizeof *to
);
8591 ntool_bar_items
+= TOOL_BAR_ITEM_NSLOTS
;
8598 /* Read a character using menus based on maps in the array MAPS.
8599 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
8600 Return t if we displayed a menu but the user rejected it.
8602 PREV_EVENT is the previous input event, or nil if we are reading
8603 the first event of a key sequence.
8605 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
8606 if we used a mouse menu to read the input, or zero otherwise. If
8607 USED_MOUSE_MENU is null, we don't dereference it.
8609 The prompting is done based on the prompt-string of the map
8610 and the strings associated with various map elements.
8612 This can be done with X menus or with menus put in the minibuf.
8613 These are done in different ways, depending on how the input will be read.
8614 Menus using X are done after auto-saving in read-char, getting the input
8615 event from Fx_popup_menu; menus using the minibuf use read_char recursively
8616 and do auto-saving in the inner call of read_char. */
8619 read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
8622 Lisp_Object prev_event
;
8623 int *used_mouse_menu
;
8627 if (used_mouse_menu
)
8628 *used_mouse_menu
= 0;
8630 /* Use local over global Menu maps */
8632 if (! menu_prompting
)
8635 /* Optionally disregard all but the global map. */
8636 if (inhibit_local_menu_bar_menus
)
8638 maps
+= (nmaps
- 1);
8643 /* If we got to this point via a mouse click,
8644 use a real menu for mouse selection. */
8645 if (EVENT_HAS_PARAMETERS (prev_event
)
8646 && !EQ (XCAR (prev_event
), Qmenu_bar
)
8647 && !EQ (XCAR (prev_event
), Qtool_bar
))
8649 /* Display the menu and get the selection. */
8650 Lisp_Object
*realmaps
8651 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
8655 /* Use the maps that are not nil. */
8656 for (mapno
= 0; mapno
< nmaps
; mapno
++)
8657 if (!NILP (maps
[mapno
]))
8658 realmaps
[nmaps1
++] = maps
[mapno
];
8660 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
8665 record_menu_key (XCAR (value
));
8667 /* If we got multiple events, unread all but
8669 There is no way to prevent those unread events
8670 from showing up later in last_nonmenu_event.
8671 So turn symbol and integer events into lists,
8672 to indicate that they came from a mouse menu,
8673 so that when present in last_nonmenu_event
8674 they won't confuse things. */
8675 for (tem
= XCDR (value
); CONSP (tem
); tem
= XCDR (tem
))
8677 record_menu_key (XCAR (tem
));
8678 if (SYMBOLP (XCAR (tem
))
8679 || INTEGERP (XCAR (tem
)))
8680 XSETCAR (tem
, Fcons (XCAR (tem
), Qdisabled
));
8683 /* If we got more than one event, put all but the first
8684 onto this list to be read later.
8685 Return just the first event now. */
8686 Vunread_command_events
8687 = nconc2 (XCDR (value
), Vunread_command_events
);
8688 value
= XCAR (value
);
8690 else if (NILP (value
))
8692 if (used_mouse_menu
)
8693 *used_mouse_menu
= 1;
8696 #endif /* HAVE_MENUS */
8700 /* Buffer in use so far for the minibuf prompts for menu keymaps.
8701 We make this bigger when necessary, and never free it. */
8702 static char *read_char_minibuf_menu_text
;
8703 /* Size of that buffer. */
8704 static int read_char_minibuf_menu_width
;
8707 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
8713 register Lisp_Object name
;
8715 /* FIXME: Use the minibuffer's frame width. */
8716 int width
= FRAME_COLS (SELECTED_FRAME ()) - 4;
8719 Lisp_Object rest
, vector
;
8725 if (! menu_prompting
)
8728 /* Get the menu name from the first map that has one (a prompt string). */
8729 for (mapno
= 0; mapno
< nmaps
; mapno
++)
8731 name
= Fkeymap_prompt (maps
[mapno
]);
8736 /* If we don't have any menus, just read a character normally. */
8737 if (!STRINGP (name
))
8740 /* Make sure we have a big enough buffer for the menu text. */
8741 width
= max (width
, SBYTES (name
));
8742 if (read_char_minibuf_menu_text
== 0)
8744 read_char_minibuf_menu_width
= width
+ 4;
8745 read_char_minibuf_menu_text
= (char *) xmalloc (width
+ 4);
8747 else if (width
+ 4 > read_char_minibuf_menu_width
)
8749 read_char_minibuf_menu_width
= width
+ 4;
8750 read_char_minibuf_menu_text
8751 = (char *) xrealloc (read_char_minibuf_menu_text
, width
+ 4);
8753 menu
= read_char_minibuf_menu_text
;
8755 /* Prompt string always starts with map's prompt, and a space. */
8756 strcpy (menu
, SDATA (name
));
8757 nlength
= SBYTES (name
);
8758 menu
[nlength
++] = ':';
8759 menu
[nlength
++] = ' ';
8762 /* Start prompting at start of first map. */
8766 /* Present the documented bindings, a line at a time. */
8773 Lisp_Object orig_defn_macro
;
8775 /* Loop over elements of map. */
8780 /* If reached end of map, start at beginning of next map. */
8784 /* At end of last map, wrap around to first map if just starting,
8785 or end this line if already have something on it. */
8789 if (notfirst
|| nobindings
) break;
8794 /* Look at the next element of the map. */
8796 elt
= XVECTOR (vector
)->contents
[idx
];
8798 elt
= Fcar_safe (rest
);
8800 if (idx
< 0 && VECTORP (elt
))
8802 /* If we found a dense table in the keymap,
8803 advanced past it, but start scanning its contents. */
8804 rest
= Fcdr_safe (rest
);
8810 /* An ordinary element. */
8811 Lisp_Object event
, tem
;
8815 event
= Fcar_safe (elt
); /* alist */
8816 elt
= Fcdr_safe (elt
);
8820 XSETINT (event
, idx
); /* vector */
8823 /* Ignore the element if it has no prompt string. */
8824 if (INTEGERP (event
) && parse_menu_item (elt
, -1))
8826 /* 1 if the char to type matches the string. */
8828 Lisp_Object upcased_event
, downcased_event
;
8829 Lisp_Object desc
= Qnil
;
8831 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
8833 upcased_event
= Fupcase (event
);
8834 downcased_event
= Fdowncase (event
);
8835 char_matches
= (XINT (upcased_event
) == SREF (s
, 0)
8836 || XINT (downcased_event
) == SREF (s
, 0));
8838 desc
= Fsingle_key_description (event
, Qnil
);
8840 #if 0 /* It is redundant to list the equivalent key bindings because
8841 the prefix is what the user has already typed. */
8843 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
8845 /* Insert equivalent keybinding. */
8846 s
= concat2 (s
, tem
);
8849 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_TYPE
];
8850 if (EQ (tem
, QCradio
) || EQ (tem
, QCtoggle
))
8852 /* Insert button prefix. */
8853 Lisp_Object selected
8854 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
];
8855 if (EQ (tem
, QCradio
))
8856 tem
= build_string (NILP (selected
) ? "(*) " : "( ) ");
8858 tem
= build_string (NILP (selected
) ? "[X] " : "[ ] ");
8859 s
= concat2 (tem
, s
);
8863 /* If we have room for the prompt string, add it to this line.
8864 If this is the first on the line, always add it. */
8865 if ((SCHARS (s
) + i
+ 2
8866 + (char_matches
? 0 : SCHARS (desc
) + 3))
8872 /* Punctuate between strings. */
8875 strcpy (menu
+ i
, ", ");
8881 /* If the char to type doesn't match the string's
8882 first char, explicitly show what char to type. */
8885 /* Add as much of string as fits. */
8886 thiswidth
= SCHARS (desc
);
8887 if (thiswidth
+ i
> width
)
8888 thiswidth
= width
- i
;
8889 bcopy (SDATA (desc
), menu
+ i
, thiswidth
);
8891 strcpy (menu
+ i
, " = ");
8895 /* Add as much of string as fits. */
8896 thiswidth
= SCHARS (s
);
8897 if (thiswidth
+ i
> width
)
8898 thiswidth
= width
- i
;
8899 bcopy (SDATA (s
), menu
+ i
, thiswidth
);
8905 /* If this element does not fit, end the line now,
8906 and save the element for the next line. */
8907 strcpy (menu
+ i
, "...");
8912 /* Move past this element. */
8913 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
8914 /* Handle reaching end of dense table. */
8919 rest
= Fcdr_safe (rest
);
8923 /* Prompt with that and read response. */
8924 message2_nolog (menu
, strlen (menu
),
8925 ! NILP (current_buffer
->enable_multibyte_characters
));
8927 /* Make believe its not a keyboard macro in case the help char
8928 is pressed. Help characters are not recorded because menu prompting
8929 is not used on replay.
8931 orig_defn_macro
= current_kboard
->defining_kbd_macro
;
8932 current_kboard
->defining_kbd_macro
= Qnil
;
8934 obj
= read_char (commandflag
, 0, 0, Qt
, 0, NULL
);
8935 while (BUFFERP (obj
));
8936 current_kboard
->defining_kbd_macro
= orig_defn_macro
;
8938 if (!INTEGERP (obj
))
8940 else if (XINT (obj
) == -2)
8945 if (! EQ (obj
, menu_prompt_more_char
)
8946 && (!INTEGERP (menu_prompt_more_char
)
8947 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
8949 if (!NILP (current_kboard
->defining_kbd_macro
))
8950 store_kbd_macro_char (obj
);
8953 /* Help char - go round again */
8957 /* Reading key sequences. */
8959 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
8960 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
8961 keymap, or nil otherwise. Return the index of the first keymap in
8962 which KEY has any binding, or NMAPS if no map has a binding.
8964 If KEY is a meta ASCII character, treat it like meta-prefix-char
8965 followed by the corresponding non-meta character. Keymaps in
8966 CURRENT with non-prefix bindings for meta-prefix-char become nil in
8969 If KEY has no bindings in any of the CURRENT maps, NEXT is left
8972 NEXT may be the same array as CURRENT. */
8975 follow_key (key
, nmaps
, current
, defs
, next
)
8977 Lisp_Object
*current
, *defs
, *next
;
8980 int i
, first_binding
;
8982 first_binding
= nmaps
;
8983 for (i
= nmaps
- 1; i
>= 0; i
--)
8985 if (! NILP (current
[i
]))
8987 defs
[i
] = access_keymap (current
[i
], key
, 1, 0, 1);
8988 if (! NILP (defs
[i
]))
8995 /* Given the set of bindings we've found, produce the next set of maps. */
8996 if (first_binding
< nmaps
)
8997 for (i
= 0; i
< nmaps
; i
++)
8998 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap (defs
[i
], 0, 1);
9000 return first_binding
;
9003 /* Structure used to keep track of partial application of key remapping
9004 such as Vfunction_key_map and Vkey_translation_map. */
9005 typedef struct keyremap
9007 /* This is the map originally specified for this use. */
9009 /* This is a submap reached by looking up, in PARENT,
9010 the events from START to END. */
9012 /* Positions [START, END) in the key sequence buffer
9013 are the key that we have scanned so far.
9014 Those events are the ones that we will replace
9015 if PAREHT maps them into a key sequence. */
9019 /* Lookup KEY in MAP.
9020 MAP is a keymap mapping keys to key vectors or functions.
9021 If the mapping is a function and DO_FUNCTION is non-zero, then
9022 the function is called with PROMPT as parameter and its return
9023 value is used as the return value of this function (after checking
9024 that it is indeed a vector). */
9027 access_keymap_keyremap (map
, key
, prompt
, do_funcall
)
9028 Lisp_Object map
, key
, prompt
;
9033 next
= access_keymap (map
, key
, 1, 0, 1);
9035 /* Handle symbol with autoload definition. */
9036 if (SYMBOLP (next
) && !NILP (Ffboundp (next
))
9037 && CONSP (XSYMBOL (next
)->function
)
9038 && EQ (XCAR (XSYMBOL (next
)->function
), Qautoload
))
9039 do_autoload (XSYMBOL (next
)->function
, next
);
9041 /* Handle a symbol whose function definition is a keymap
9043 if (SYMBOLP (next
) && !NILP (Ffboundp (next
))
9044 && (ARRAYP (XSYMBOL (next
)->function
)
9045 || KEYMAPP (XSYMBOL (next
)->function
)))
9046 next
= XSYMBOL (next
)->function
;
9048 /* If the keymap gives a function, not an
9049 array, then call the function with one arg and use
9050 its value instead. */
9051 if (SYMBOLP (next
) && !NILP (Ffboundp (next
)) && do_funcall
)
9056 next
= call1 (next
, prompt
);
9057 /* If the function returned something invalid,
9058 barf--don't ignore it.
9059 (To ignore it safely, we would need to gcpro a bunch of
9060 other variables.) */
9061 if (! (VECTORP (next
) || STRINGP (next
)))
9062 error ("Function %s returns invalid key sequence", tem
);
9067 /* Do one step of the key remapping used for function-key-map and
9068 key-translation-map:
9069 KEYBUF is the buffer holding the input events.
9070 BUFSIZE is its maximum size.
9071 FKEY is a pointer to the keyremap structure to use.
9072 INPUT is the index of the last element in KEYBUF.
9073 DOIT if non-zero says that the remapping can actually take place.
9074 DIFF is used to return the number of keys added/removed by the remapping.
9075 PARENT is the root of the keymap.
9076 PROMPT is the prompt to use if the remapping happens through a function.
9077 The return value is non-zero if the remapping actually took place. */
9080 keyremap_step (keybuf
, bufsize
, fkey
, input
, doit
, diff
, prompt
)
9081 Lisp_Object
*keybuf
, prompt
;
9083 int input
, doit
, *diff
, bufsize
;
9085 Lisp_Object next
, key
;
9087 key
= keybuf
[fkey
->end
++];
9089 if (KEYMAPP (fkey
->parent
))
9090 next
= access_keymap_keyremap (fkey
->map
, key
, prompt
, doit
);
9094 /* If keybuf[fkey->start..fkey->end] is bound in the
9095 map and we're in a position to do the key remapping, replace it with
9096 the binding and restart with fkey->start at the end. */
9097 if ((VECTORP (next
) || STRINGP (next
)) && doit
)
9099 int len
= XFASTINT (Flength (next
));
9102 *diff
= len
- (fkey
->end
- fkey
->start
);
9104 if (input
+ *diff
>= bufsize
)
9105 error ("Key sequence too long");
9107 /* Shift the keys that follow fkey->end. */
9109 for (i
= fkey
->end
; i
< input
; i
++)
9110 keybuf
[i
+ *diff
] = keybuf
[i
];
9112 for (i
= input
- 1; i
>= fkey
->end
; i
--)
9113 keybuf
[i
+ *diff
] = keybuf
[i
];
9114 /* Overwrite the old keys with the new ones. */
9115 for (i
= 0; i
< len
; i
++)
9116 keybuf
[fkey
->start
+ i
]
9117 = Faref (next
, make_number (i
));
9119 fkey
->start
= fkey
->end
+= *diff
;
9120 fkey
->map
= fkey
->parent
;
9125 fkey
->map
= get_keymap (next
, 0, 1);
9127 /* If we no longer have a bound suffix, try a new position for
9129 if (!CONSP (fkey
->map
))
9131 fkey
->end
= ++fkey
->start
;
9132 fkey
->map
= fkey
->parent
;
9137 /* Read a sequence of keys that ends with a non prefix character,
9138 storing it in KEYBUF, a buffer of size BUFSIZE.
9140 Return the length of the key sequence stored.
9141 Return -1 if the user rejected a command menu.
9143 Echo starting immediately unless `prompt' is 0.
9145 Where a key sequence ends depends on the currently active keymaps.
9146 These include any minor mode keymaps active in the current buffer,
9147 the current buffer's local map, and the global map.
9149 If a key sequence has no other bindings, we check Vfunction_key_map
9150 to see if some trailing subsequence might be the beginning of a
9151 function key's sequence. If so, we try to read the whole function
9152 key, and substitute its symbolic name into the key sequence.
9154 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
9155 `double-' events into similar click events, if that would make them
9156 bound. We try to turn `triple-' events first into `double-' events,
9159 If we get a mouse click in a mode line, vertical divider, or other
9160 non-text area, we treat the click as if it were prefixed by the
9161 symbol denoting that area - `mode-line', `vertical-line', or
9164 If the sequence starts with a mouse click, we read the key sequence
9165 with respect to the buffer clicked on, not the current buffer.
9167 If the user switches frames in the midst of a key sequence, we put
9168 off the switch-frame event until later; the next call to
9169 read_char will return it.
9171 If FIX_CURRENT_BUFFER is nonzero, we restore current_buffer
9172 from the selected window's buffer. */
9175 read_key_sequence (keybuf
, bufsize
, prompt
, dont_downcase_last
,
9176 can_return_switch_frame
, fix_current_buffer
)
9177 Lisp_Object
*keybuf
;
9180 int dont_downcase_last
;
9181 int can_return_switch_frame
;
9182 int fix_current_buffer
;
9184 Lisp_Object from_string
;
9185 int count
= SPECPDL_INDEX ();
9187 /* How many keys there are in the current key sequence. */
9190 /* The length of the echo buffer when we started reading, and
9191 the length of this_command_keys when we started reading. */
9195 /* The number of keymaps we're scanning right now, and the number of
9196 keymaps we have allocated space for. */
9198 int nmaps_allocated
= 0;
9200 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
9201 the current keymaps. */
9202 Lisp_Object
*defs
= NULL
;
9204 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
9205 in the current keymaps, or nil where it is not a prefix. */
9206 Lisp_Object
*submaps
= NULL
;
9208 /* The local map to start out with at start of key sequence. */
9209 Lisp_Object orig_local_map
;
9211 /* The map from the `keymap' property to start out with at start of
9213 Lisp_Object orig_keymap
;
9215 /* 1 if we have already considered switching to the local-map property
9216 of the place where a mouse click occurred. */
9217 int localized_local_map
= 0;
9219 /* The index in submaps[] of the first keymap that has a binding for
9220 this key sequence. In other words, the lowest i such that
9221 submaps[i] is non-nil. */
9223 /* Index of the first key that has no binding.
9224 It is useless to try fkey.start larger than that. */
9227 /* If t < mock_input, then KEYBUF[t] should be read as the next
9230 We use this to recover after recognizing a function key. Once we
9231 realize that a suffix of the current key sequence is actually a
9232 function key's escape sequence, we replace the suffix with the
9233 function key's binding from Vfunction_key_map. Now keybuf
9234 contains a new and different key sequence, so the echo area,
9235 this_command_keys, and the submaps and defs arrays are wrong. In
9236 this situation, we set mock_input to t, set t to 0, and jump to
9237 restart_sequence; the loop will read keys from keybuf up until
9238 mock_input, thus rebuilding the state; and then it will resume
9239 reading characters from the keyboard. */
9242 /* If the sequence is unbound in submaps[], then
9243 keybuf[fkey.start..fkey.end-1] is a prefix in Vfunction_key_map,
9244 and fkey.map is its binding.
9246 These might be > t, indicating that all function key scanning
9247 should hold off until t reaches them. We do this when we've just
9248 recognized a function key, to avoid searching for the function
9249 key's again in Vfunction_key_map. */
9252 /* Likewise, for key_translation_map and input-decode-map. */
9253 keyremap keytran
, indec
;
9255 /* Non-zero if we are trying to map a key by changing an upper-case
9256 letter to lower case, or a shifted function key to an unshifted
9258 int shift_translated
= 0;
9260 /* If we receive a `switch-frame' or `select-window' event in the middle of
9261 a key sequence, we put it off for later.
9262 While we're reading, we keep the event here. */
9263 Lisp_Object delayed_switch_frame
;
9265 /* See the comment below... */
9266 #if defined (GOBBLE_FIRST_EVENT)
9267 Lisp_Object first_event
;
9270 Lisp_Object original_uppercase
;
9271 int original_uppercase_position
= -1;
9273 /* Gets around Microsoft compiler limitations. */
9276 struct buffer
*starting_buffer
;
9278 /* List of events for which a fake prefix key has been generated. */
9279 Lisp_Object fake_prefixed_keys
= Qnil
;
9281 #if defined (GOBBLE_FIRST_EVENT)
9285 struct gcpro gcpro1
;
9287 GCPRO1 (fake_prefixed_keys
);
9288 raw_keybuf_count
= 0;
9290 last_nonmenu_event
= Qnil
;
9292 delayed_switch_frame
= Qnil
;
9297 echo_prompt (prompt
);
9298 else if (cursor_in_echo_area
9299 && (FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
9300 && NILP (Fzerop (Vecho_keystrokes
)))
9301 /* This doesn't put in a dash if the echo buffer is empty, so
9302 you don't always see a dash hanging out in the minibuffer. */
9306 /* Record the initial state of the echo area and this_command_keys;
9307 we will need to restore them if we replay a key sequence. */
9309 echo_start
= echo_length ();
9310 keys_start
= this_command_key_count
;
9311 this_single_command_key_start
= keys_start
;
9313 #if defined (GOBBLE_FIRST_EVENT)
9314 /* This doesn't quite work, because some of the things that read_char
9315 does cannot safely be bypassed. It seems too risky to try to make
9318 /* Read the first char of the sequence specially, before setting
9319 up any keymaps, in case a filter runs and switches buffers on us. */
9320 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
9322 #endif /* GOBBLE_FIRST_EVENT */
9324 orig_local_map
= get_local_map (PT
, current_buffer
, Qlocal_map
);
9325 orig_keymap
= get_local_map (PT
, current_buffer
, Qkeymap
);
9328 /* We jump here when we need to reinitialize fkey and keytran; this
9329 happens if we switch keyboards between rescans. */
9330 replay_entire_sequence
:
9332 indec
.map
= indec
.parent
= current_kboard
->Vinput_decode_map
;
9333 fkey
.map
= fkey
.parent
= current_kboard
->Vlocal_function_key_map
;
9334 keytran
.map
= keytran
.parent
= Vkey_translation_map
;
9335 indec
.start
= indec
.end
= 0;
9336 fkey
.start
= fkey
.end
= 0;
9337 keytran
.start
= keytran
.end
= 0;
9339 /* We jump here when the key sequence has been thoroughly changed, and
9340 we need to rescan it starting from the beginning. When we jump here,
9341 keybuf[0..mock_input] holds the sequence we should reread. */
9344 starting_buffer
= current_buffer
;
9345 first_unbound
= bufsize
+ 1;
9347 /* Build our list of keymaps.
9348 If we recognize a function key and replace its escape sequence in
9349 keybuf with its symbol, or if the sequence starts with a mouse
9350 click and we need to switch buffers, we jump back here to rebuild
9351 the initial keymaps from the current buffer. */
9354 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
9356 if (2 > nmaps_allocated
)
9358 submaps
= (Lisp_Object
*) alloca (2 * sizeof (submaps
[0]));
9359 defs
= (Lisp_Object
*) alloca (2 * sizeof (defs
[0]));
9360 nmaps_allocated
= 2;
9362 submaps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
9364 else if (!NILP (Voverriding_local_map
))
9366 if (2 > nmaps_allocated
)
9368 submaps
= (Lisp_Object
*) alloca (2 * sizeof (submaps
[0]));
9369 defs
= (Lisp_Object
*) alloca (2 * sizeof (defs
[0]));
9370 nmaps_allocated
= 2;
9372 submaps
[nmaps
++] = Voverriding_local_map
;
9380 nminor
= current_minor_maps (0, &maps
);
9381 total
= nminor
+ (!NILP (orig_keymap
) ? 3 : 2);
9383 if (total
> nmaps_allocated
)
9385 submaps
= (Lisp_Object
*) alloca (total
* sizeof (submaps
[0]));
9386 defs
= (Lisp_Object
*) alloca (total
* sizeof (defs
[0]));
9387 nmaps_allocated
= total
;
9390 if (!NILP (orig_keymap
))
9391 submaps
[nmaps
++] = orig_keymap
;
9393 bcopy (maps
, (void *) (submaps
+ nmaps
),
9394 nminor
* sizeof (submaps
[0]));
9398 submaps
[nmaps
++] = orig_local_map
;
9400 submaps
[nmaps
++] = current_global_map
;
9402 /* Find an accurate initial value for first_binding. */
9403 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
9404 if (! NILP (submaps
[first_binding
]))
9407 /* Start from the beginning in keybuf. */
9410 /* These are no-ops the first time through, but if we restart, they
9411 revert the echo area and this_command_keys to their original state. */
9412 this_command_key_count
= keys_start
;
9413 if (INTERACTIVE
&& t
< mock_input
)
9414 echo_truncate (echo_start
);
9416 /* If the best binding for the current key sequence is a keymap, or
9417 we may be looking at a function key's escape sequence, keep on
9419 while (first_binding
< nmaps
9420 /* Keep reading as long as there's a prefix binding. */
9421 ? !NILP (submaps
[first_binding
])
9422 /* Don't return in the middle of a possible function key sequence,
9423 if the only bindings we found were via case conversion.
9424 Thus, if ESC O a has a function-key-map translation
9425 and ESC o has a binding, don't return after ESC O,
9426 so that we can translate ESC O plus the next character. */
9427 : (/* indec.start < t || fkey.start < t || */ keytran
.start
< t
))
9430 int used_mouse_menu
= 0;
9432 /* Where the last real key started. If we need to throw away a
9433 key that has expanded into more than one element of keybuf
9434 (say, a mouse click on the mode line which is being treated
9435 as [mode-line (mouse-...)], then we backtrack to this point
9437 int last_real_key_start
;
9439 /* These variables are analogous to echo_start and keys_start;
9440 while those allow us to restart the entire key sequence,
9441 echo_local_start and keys_local_start allow us to throw away
9443 int echo_local_start
, keys_local_start
, local_first_binding
;
9445 eassert (indec
.end
== t
|| (indec
.end
> t
&& indec
.end
<= mock_input
));
9446 eassert (indec
.start
<= indec
.end
);
9447 eassert (fkey
.start
<= fkey
.end
);
9448 eassert (keytran
.start
<= keytran
.end
);
9449 /* key-translation-map is applied *after* function-key-map
9450 which is itself applied *after* input-decode-map. */
9451 eassert (fkey
.end
<= indec
.start
);
9452 eassert (keytran
.end
<= fkey
.start
);
9454 if (/* first_unbound < indec.start && first_unbound < fkey.start && */
9455 first_unbound
< keytran
.start
)
9456 { /* The prefix upto first_unbound has no binding and has
9457 no translation left to do either, so we know it's unbound.
9458 If we don't stop now, we risk staying here indefinitely
9459 (if the user keeps entering fkey or keytran prefixes
9460 like C-c ESC ESC ESC ESC ...) */
9462 for (i
= first_unbound
+ 1; i
< t
; i
++)
9463 keybuf
[i
- first_unbound
- 1] = keybuf
[i
];
9464 mock_input
= t
- first_unbound
- 1;
9465 indec
.end
= indec
.start
-= first_unbound
+ 1;
9466 indec
.map
= indec
.parent
;
9467 fkey
.end
= fkey
.start
-= first_unbound
+ 1;
9468 fkey
.map
= fkey
.parent
;
9469 keytran
.end
= keytran
.start
-= first_unbound
+ 1;
9470 keytran
.map
= keytran
.parent
;
9471 goto replay_sequence
;
9475 error ("Key sequence too long");
9478 echo_local_start
= echo_length ();
9479 keys_local_start
= this_command_key_count
;
9480 local_first_binding
= first_binding
;
9483 /* These are no-ops, unless we throw away a keystroke below and
9484 jumped back up to replay_key; in that case, these restore the
9485 variables to their original state, allowing us to replay the
9487 if (INTERACTIVE
&& t
< mock_input
)
9488 echo_truncate (echo_local_start
);
9489 this_command_key_count
= keys_local_start
;
9490 first_binding
= local_first_binding
;
9492 /* By default, assume each event is "real". */
9493 last_real_key_start
= t
;
9495 /* Does mock_input indicate that we are re-reading a key sequence? */
9499 add_command_key (key
);
9500 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
9501 && NILP (Fzerop (Vecho_keystrokes
)))
9505 /* If not, we should actually read a character. */
9509 KBOARD
*interrupted_kboard
= current_kboard
;
9510 struct frame
*interrupted_frame
= SELECTED_FRAME ();
9511 key
= read_char (NILP (prompt
), nmaps
,
9512 (Lisp_Object
*) submaps
, last_nonmenu_event
,
9513 &used_mouse_menu
, NULL
);
9514 if ((INTEGERP (key
) && XINT (key
) == -2) /* wrong_kboard_jmpbuf */
9515 /* When switching to a new tty (with a new keyboard),
9516 read_char returns the new buffer, rather than -2
9517 (Bug#5095). This is because `terminal-init-xterm'
9518 calls read-char, which eats the wrong_kboard_jmpbuf
9519 return. Any better way to fix this? -- cyd */
9520 || (interrupted_kboard
!= current_kboard
))
9525 for (k
= all_kboards
; k
; k
= k
->next_kboard
)
9526 if (k
== interrupted_kboard
)
9531 /* Don't touch interrupted_kboard when it's been
9533 delayed_switch_frame
= Qnil
;
9534 goto replay_entire_sequence
;
9537 if (!NILP (delayed_switch_frame
))
9539 interrupted_kboard
->kbd_queue
9540 = Fcons (delayed_switch_frame
,
9541 interrupted_kboard
->kbd_queue
);
9542 delayed_switch_frame
= Qnil
;
9546 interrupted_kboard
->kbd_queue
9547 = Fcons (keybuf
[--t
], interrupted_kboard
->kbd_queue
);
9549 /* If the side queue is non-empty, ensure it begins with a
9550 switch-frame, so we'll replay it in the right context. */
9551 if (CONSP (interrupted_kboard
->kbd_queue
)
9552 && (key
= XCAR (interrupted_kboard
->kbd_queue
),
9553 !(EVENT_HAS_PARAMETERS (key
)
9554 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)),
9558 XSETFRAME (frame
, interrupted_frame
);
9559 interrupted_kboard
->kbd_queue
9560 = Fcons (make_lispy_switch_frame (frame
),
9561 interrupted_kboard
->kbd_queue
);
9564 orig_local_map
= get_local_map (PT
, current_buffer
, Qlocal_map
);
9565 orig_keymap
= get_local_map (PT
, current_buffer
, Qkeymap
);
9566 goto replay_entire_sequence
;
9570 /* read_char returns t when it shows a menu and the user rejects it.
9574 unbind_to (count
, Qnil
);
9579 /* read_char returns -1 at the end of a macro.
9580 Emacs 18 handles this by returning immediately with a
9581 zero, so that's what we'll do. */
9582 if (INTEGERP (key
) && XINT (key
) == -1)
9585 /* The Microsoft C compiler can't handle the goto that
9591 /* If the current buffer has been changed from under us, the
9592 keymap may have changed, so replay the sequence. */
9595 timer_resume_idle ();
9598 /* Reset the current buffer from the selected window
9599 in case something changed the former and not the latter.
9600 This is to be more consistent with the behavior
9601 of the command_loop_1. */
9602 if (fix_current_buffer
)
9604 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
9606 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
9607 Fset_buffer (XWINDOW (selected_window
)->buffer
);
9610 orig_local_map
= get_local_map (PT
, current_buffer
, Qlocal_map
);
9611 orig_keymap
= get_local_map (PT
, current_buffer
, Qkeymap
);
9612 goto replay_sequence
;
9615 /* If we have a quit that was typed in another frame, and
9616 quit_throw_to_read_char switched buffers,
9617 replay to get the right keymap. */
9619 && XINT (key
) == quit_char
9620 && current_buffer
!= starting_buffer
)
9623 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
9627 orig_local_map
= get_local_map (PT
, current_buffer
, Qlocal_map
);
9628 orig_keymap
= get_local_map (PT
, current_buffer
, Qkeymap
);
9629 goto replay_sequence
;
9634 if (EVENT_HAS_PARAMETERS (key
)
9635 /* Either a `switch-frame' or a `select-window' event. */
9636 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)), Qswitch_frame
))
9638 /* If we're at the beginning of a key sequence, and the caller
9639 says it's okay, go ahead and return this event. If we're
9640 in the midst of a key sequence, delay it until the end. */
9641 if (t
> 0 || !can_return_switch_frame
)
9643 delayed_switch_frame
= key
;
9649 ASET (raw_keybuf
, raw_keybuf_count
, key
);
9653 /* Clicks in non-text areas get prefixed by the symbol
9654 in their CHAR-ADDRESS field. For example, a click on
9655 the mode line is prefixed by the symbol `mode-line'.
9657 Furthermore, key sequences beginning with mouse clicks
9658 are read using the keymaps of the buffer clicked on, not
9659 the current buffer. So we may have to switch the buffer
9662 When we turn one event into two events, we must make sure
9663 that neither of the two looks like the original--so that,
9664 if we replay the events, they won't be expanded again.
9665 If not for this, such reexpansion could happen either here
9666 or when user programs play with this-command-keys. */
9667 if (EVENT_HAS_PARAMETERS (key
))
9672 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
9673 if (EQ (kind
, Qmouse_click
))
9675 Lisp_Object window
, posn
;
9677 window
= POSN_WINDOW (EVENT_START (key
));
9678 posn
= POSN_POSN (EVENT_START (key
));
9681 || (!NILP (fake_prefixed_keys
)
9682 && !NILP (Fmemq (key
, fake_prefixed_keys
))))
9684 /* We're looking a second time at an event for which
9685 we generated a fake prefix key. Set
9686 last_real_key_start appropriately. */
9688 last_real_key_start
= t
- 1;
9691 /* Key sequences beginning with mouse clicks are
9692 read using the keymaps in the buffer clicked on,
9693 not the current buffer. If we're at the
9694 beginning of a key sequence, switch buffers. */
9695 if (last_real_key_start
== 0
9697 && BUFFERP (XWINDOW (window
)->buffer
)
9698 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
9700 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
9704 /* Arrange to go back to the original buffer once we're
9705 done reading the key sequence. Note that we can't
9706 use save_excursion_{save,restore} here, because they
9707 save point as well as the current buffer; we don't
9708 want to save point, because redisplay may change it,
9709 to accommodate a Fset_window_start or something. We
9710 don't want to do this at the top of the function,
9711 because we may get input from a subprocess which
9712 wants to change the selected window and stuff (say,
9714 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
9716 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
9718 set_buffer_internal (XBUFFER (XWINDOW (window
)->buffer
));
9719 orig_local_map
= get_local_map (PT
, current_buffer
,
9721 orig_keymap
= get_local_map (PT
, current_buffer
, Qkeymap
);
9722 goto replay_sequence
;
9725 /* For a mouse click, get the local text-property keymap
9726 of the place clicked on, rather than point. */
9727 if (last_real_key_start
== 0
9728 && CONSP (XCDR (key
))
9729 && ! localized_local_map
)
9731 Lisp_Object map_here
, start
, pos
;
9733 localized_local_map
= 1;
9734 start
= EVENT_START (key
);
9736 if (CONSP (start
) && POSN_INBUFFER_P (start
))
9738 pos
= POSN_BUFFER_POSN (start
);
9740 && XINT (pos
) >= BEGV
9741 && XINT (pos
) <= ZV
)
9743 map_here
= get_local_map (XINT (pos
),
9744 current_buffer
, Qlocal_map
);
9745 if (!EQ (map_here
, orig_local_map
))
9747 orig_local_map
= map_here
;
9748 ++localized_local_map
;
9751 map_here
= get_local_map (XINT (pos
),
9752 current_buffer
, Qkeymap
);
9753 if (!EQ (map_here
, orig_keymap
))
9755 orig_keymap
= map_here
;
9756 ++localized_local_map
;
9759 if (localized_local_map
> 1)
9764 goto replay_sequence
;
9770 /* Expand mode-line and scroll-bar events into two events:
9771 use posn as a fake prefix key. */
9773 && (NILP (fake_prefixed_keys
)
9774 || NILP (Fmemq (key
, fake_prefixed_keys
))))
9776 if (t
+ 1 >= bufsize
)
9777 error ("Key sequence too long");
9780 keybuf
[t
+ 1] = key
;
9783 /* Record that a fake prefix key has been generated
9784 for KEY. Don't modify the event; this would
9785 prevent proper action when the event is pushed
9786 back into unread-command-events. */
9787 fake_prefixed_keys
= Fcons (key
, fake_prefixed_keys
);
9789 /* If on a mode line string with a local keymap,
9790 reconsider the key sequence with that keymap. */
9791 if (string
= POSN_STRING (EVENT_START (key
)),
9792 (CONSP (string
) && STRINGP (XCAR (string
))))
9794 Lisp_Object pos
, map
, map2
;
9796 pos
= XCDR (string
);
9797 string
= XCAR (string
);
9799 && XINT (pos
) < SCHARS (string
))
9801 map
= Fget_text_property (pos
, Qlocal_map
, string
);
9803 orig_local_map
= map
;
9804 map2
= Fget_text_property (pos
, Qkeymap
, string
);
9807 if (!NILP (map
) || !NILP (map2
))
9808 goto replay_sequence
;
9814 else if (NILP (from_string
)
9815 && (string
= POSN_STRING (EVENT_START (key
)),
9816 (CONSP (string
) && STRINGP (XCAR (string
)))))
9818 /* For a click on a string, i.e. overlay string or a
9819 string displayed via the `display' property,
9820 consider `local-map' and `keymap' properties of
9822 Lisp_Object pos
, map
, map2
;
9824 pos
= XCDR (string
);
9825 string
= XCAR (string
);
9827 && XINT (pos
) < SCHARS (string
))
9829 map
= Fget_text_property (pos
, Qlocal_map
, string
);
9831 orig_local_map
= map
;
9832 map2
= Fget_text_property (pos
, Qkeymap
, string
);
9836 if (!NILP (map
) || !NILP (map2
))
9838 from_string
= string
;
9841 goto replay_sequence
;
9846 else if (CONSP (XCDR (key
))
9847 && CONSP (EVENT_START (key
))
9848 && CONSP (XCDR (EVENT_START (key
))))
9852 posn
= POSN_POSN (EVENT_START (key
));
9853 /* Handle menu-bar events:
9854 insert the dummy prefix event `menu-bar'. */
9855 if (EQ (posn
, Qmenu_bar
) || EQ (posn
, Qtool_bar
))
9857 if (t
+ 1 >= bufsize
)
9858 error ("Key sequence too long");
9862 /* Zap the position in key, so we know that we've
9863 expanded it, and don't try to do so again. */
9864 POSN_SET_POSN (EVENT_START (key
),
9865 Fcons (posn
, Qnil
));
9868 goto replay_sequence
;
9870 else if (CONSP (posn
))
9872 /* We're looking at the second event of a
9873 sequence which we expanded before. Set
9874 last_real_key_start appropriately. */
9875 if (last_real_key_start
== t
&& t
> 0)
9876 last_real_key_start
= t
- 1;
9881 /* We have finally decided that KEY is something we might want
9883 first_binding
= (follow_key (key
,
9884 nmaps
- first_binding
,
9885 submaps
+ first_binding
,
9886 defs
+ first_binding
,
9887 submaps
+ first_binding
)
9890 /* If KEY wasn't bound, we'll try some fallbacks. */
9891 if (first_binding
< nmaps
)
9892 /* This is needed for the following scenario:
9893 event 0: a down-event that gets dropped by calling replay_key.
9894 event 1: some normal prefix like C-h.
9895 After event 0, first_unbound is 0, after event 1 indec.start,
9896 fkey.start, and keytran.start are all 1, so when we see that
9897 C-h is bound, we need to update first_unbound. */
9898 first_unbound
= max (t
+ 1, first_unbound
);
9903 /* Remember the position to put an upper bound on indec.start. */
9904 first_unbound
= min (t
, first_unbound
);
9906 head
= EVENT_HEAD (key
);
9907 if (help_char_p (head
) && t
> 0)
9909 read_key_sequence_cmd
= Vprefix_help_command
;
9911 last_nonmenu_event
= key
;
9912 /* The Microsoft C compiler can't handle the goto that
9920 Lisp_Object breakdown
;
9923 breakdown
= parse_modifiers (head
);
9924 modifiers
= XINT (XCAR (XCDR (breakdown
)));
9925 /* Attempt to reduce an unbound mouse event to a simpler
9926 event that is bound:
9927 Drags reduce to clicks.
9928 Double-clicks reduce to clicks.
9929 Triple-clicks reduce to double-clicks, then to clicks.
9930 Down-clicks are eliminated.
9931 Double-downs reduce to downs, then are eliminated.
9932 Triple-downs reduce to double-downs, then to downs,
9933 then are eliminated. */
9934 if (modifiers
& (down_modifier
| drag_modifier
9935 | double_modifier
| triple_modifier
))
9937 while (modifiers
& (down_modifier
| drag_modifier
9938 | double_modifier
| triple_modifier
))
9940 Lisp_Object new_head
, new_click
;
9941 if (modifiers
& triple_modifier
)
9942 modifiers
^= (double_modifier
| triple_modifier
);
9943 else if (modifiers
& double_modifier
)
9944 modifiers
&= ~double_modifier
;
9945 else if (modifiers
& drag_modifier
)
9946 modifiers
&= ~drag_modifier
;
9949 /* Dispose of this `down' event by simply jumping
9950 back to replay_key, to get another event.
9952 Note that if this event came from mock input,
9953 then just jumping back to replay_key will just
9954 hand it to us again. So we have to wipe out any
9957 We could delete keybuf[t] and shift everything
9958 after that to the left by one spot, but we'd also
9959 have to fix up any variable that points into
9960 keybuf, and shifting isn't really necessary
9963 Adding prefixes for non-textual mouse clicks
9964 creates two characters of mock input, and both
9965 must be thrown away. If we're only looking at
9966 the prefix now, we can just jump back to
9967 replay_key. On the other hand, if we've already
9968 processed the prefix, and now the actual click
9969 itself is giving us trouble, then we've lost the
9970 state of the keymaps we want to backtrack to, and
9971 we need to replay the whole sequence to rebuild
9974 Beyond that, only function key expansion could
9975 create more than two keys, but that should never
9976 generate mouse events, so it's okay to zero
9977 mock_input in that case too.
9979 FIXME: The above paragraph seems just plain
9980 wrong, if you consider things like
9981 xterm-mouse-mode. -stef
9983 Isn't this just the most wonderful code ever? */
9985 /* If mock_input > t + 1, the above simplification
9986 will actually end up dropping keys on the floor.
9987 This is probably OK for now, but even
9988 if mock_input <= t + 1, we need to adjust indec,
9990 Typical case [header-line down-mouse-N]:
9991 mock_input = 2, t = 1, fkey.end = 1,
9992 last_real_key_start = 0. */
9993 if (indec
.end
> last_real_key_start
)
9995 indec
.end
= indec
.start
9996 = min (last_real_key_start
, indec
.start
);
9997 indec
.map
= indec
.parent
;
9998 if (fkey
.end
> last_real_key_start
)
10000 fkey
.end
= fkey
.start
10001 = min (last_real_key_start
, fkey
.start
);
10002 fkey
.map
= fkey
.parent
;
10003 if (keytran
.end
> last_real_key_start
)
10005 keytran
.end
= keytran
.start
10006 = min (last_real_key_start
, keytran
.start
);
10007 keytran
.map
= keytran
.parent
;
10011 if (t
== last_real_key_start
)
10018 mock_input
= last_real_key_start
;
10019 goto replay_sequence
;
10024 = apply_modifiers (modifiers
, XCAR (breakdown
));
10026 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
10028 /* Look for a binding for this new key. follow_key
10029 promises that it didn't munge submaps the
10030 last time we called it, since key was unbound. */
10032 = (follow_key (new_click
,
10033 nmaps
- local_first_binding
,
10034 submaps
+ local_first_binding
,
10035 defs
+ local_first_binding
,
10036 submaps
+ local_first_binding
)
10037 + local_first_binding
);
10039 /* If that click is bound, go for it. */
10040 if (first_binding
< nmaps
)
10045 /* Otherwise, we'll leave key set to the drag event. */
10052 /* Normally, last_nonmenu_event gets the previous key we read.
10053 But when a mouse popup menu is being used,
10054 we don't update last_nonmenu_event; it continues to hold the mouse
10055 event that preceded the first level of menu. */
10056 if (!used_mouse_menu
)
10057 last_nonmenu_event
= key
;
10059 /* Record what part of this_command_keys is the current key sequence. */
10060 this_single_command_key_start
= this_command_key_count
- t
;
10062 /* Look for this sequence in input-decode-map.
10063 Scan from indec.end until we find a bound suffix. */
10064 while (indec
.end
< t
)
10066 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
10069 GCPRO4 (indec
.map
, fkey
.map
, keytran
.map
, delayed_switch_frame
);
10070 done
= keyremap_step (keybuf
, bufsize
, &indec
, max (t
, mock_input
),
10075 mock_input
= diff
+ max (t
, mock_input
);
10076 goto replay_sequence
;
10080 if (first_binding
< nmaps
&& NILP (submaps
[first_binding
])
10081 && indec
.start
>= t
)
10082 /* There is a binding and it's not a prefix.
10083 (and it doesn't have any input-decode-map translation pending).
10084 There is thus no function-key in this sequence.
10085 Moving fkey.start is important in this case to allow keytran.start
10086 to go over the sequence before we return (since we keep the
10087 invariant that keytran.end <= fkey.start). */
10089 if (fkey
.start
< t
)
10090 (fkey
.start
= fkey
.end
= t
, fkey
.map
= fkey
.parent
);
10093 /* If the sequence is unbound, see if we can hang a function key
10094 off the end of it. */
10095 /* Continue scan from fkey.end until we find a bound suffix. */
10096 while (fkey
.end
< indec
.start
)
10098 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
10101 GCPRO4 (indec
.map
, fkey
.map
, keytran
.map
, delayed_switch_frame
);
10102 done
= keyremap_step (keybuf
, bufsize
, &fkey
,
10103 max (t
, mock_input
),
10104 /* If there's a binding (i.e.
10105 first_binding >= nmaps) we don't want
10106 to apply this function-key-mapping. */
10107 fkey
.end
+ 1 == t
&& first_binding
>= nmaps
,
10112 mock_input
= diff
+ max (t
, mock_input
);
10113 /* Adjust the input-decode-map counters. */
10115 indec
.start
+= diff
;
10117 goto replay_sequence
;
10121 /* Look for this sequence in key-translation-map.
10122 Scan from keytran.end until we find a bound suffix. */
10123 while (keytran
.end
< fkey
.start
)
10125 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
10128 GCPRO4 (indec
.map
, fkey
.map
, keytran
.map
, delayed_switch_frame
);
10129 done
= keyremap_step (keybuf
, bufsize
, &keytran
, max (t
, mock_input
),
10134 mock_input
= diff
+ max (t
, mock_input
);
10135 /* Adjust the function-key-map and input-decode-map counters. */
10137 indec
.start
+= diff
;
10139 fkey
.start
+= diff
;
10141 goto replay_sequence
;
10145 /* If KEY is not defined in any of the keymaps,
10146 and cannot be part of a function key or translation,
10147 and is an upper case letter
10148 use the corresponding lower-case letter instead. */
10149 if (first_binding
>= nmaps
10150 && /* indec.start >= t && fkey.start >= t && */ keytran
.start
>= t
10152 && ((CHARACTERP (make_number (XINT (key
) & ~CHAR_MODIFIER_MASK
))
10153 && UPPERCASEP (XINT (key
) & ~CHAR_MODIFIER_MASK
))
10154 || (XINT (key
) & shift_modifier
)))
10156 Lisp_Object new_key
;
10158 original_uppercase
= key
;
10159 original_uppercase_position
= t
- 1;
10161 if (XINT (key
) & shift_modifier
)
10162 XSETINT (new_key
, XINT (key
) & ~shift_modifier
);
10164 XSETINT (new_key
, (DOWNCASE (XINT (key
) & ~CHAR_MODIFIER_MASK
)
10165 | (XINT (key
) & CHAR_MODIFIER_MASK
)));
10167 /* We have to do this unconditionally, regardless of whether
10168 the lower-case char is defined in the keymaps, because they
10169 might get translated through function-key-map. */
10170 keybuf
[t
- 1] = new_key
;
10171 mock_input
= max (t
, mock_input
);
10172 shift_translated
= 1;
10174 goto replay_sequence
;
10176 /* If KEY is not defined in any of the keymaps,
10177 and cannot be part of a function key or translation,
10178 and is a shifted function key,
10179 use the corresponding unshifted function key instead. */
10180 if (first_binding
>= nmaps
10181 && /* indec.start >= t && fkey.start >= t && */ keytran
.start
>= t
)
10183 Lisp_Object breakdown
= parse_modifiers (key
);
10185 = CONSP (breakdown
) ? (XINT (XCAR (XCDR (breakdown
)))) : 0;
10187 if (modifiers
& shift_modifier
10188 /* Treat uppercase keys as shifted. */
10190 && (KEY_TO_CHAR (key
)
10191 < XCHAR_TABLE (current_buffer
->downcase_table
)->size
)
10192 && UPPERCASEP (KEY_TO_CHAR (key
))))
10194 Lisp_Object new_key
10195 = (modifiers
& shift_modifier
10196 ? apply_modifiers (modifiers
& ~shift_modifier
,
10198 : make_number (DOWNCASE (KEY_TO_CHAR (key
)) | modifiers
));
10200 original_uppercase
= key
;
10201 original_uppercase_position
= t
- 1;
10203 /* We have to do this unconditionally, regardless of whether
10204 the lower-case char is defined in the keymaps, because they
10205 might get translated through function-key-map. */
10206 keybuf
[t
- 1] = new_key
;
10207 mock_input
= max (t
, mock_input
);
10208 /* Reset fkey (and consequently keytran) to apply
10209 function-key-map on the result, so that S-backspace is
10210 correctly mapped to DEL (via backspace). OTOH,
10211 input-decode-map doesn't need to go through it again. */
10212 fkey
.start
= fkey
.end
= 0;
10213 keytran
.start
= keytran
.end
= 0;
10214 shift_translated
= 1;
10216 goto replay_sequence
;
10221 read_key_sequence_cmd
= (first_binding
< nmaps
10222 ? defs
[first_binding
]
10225 unread_switch_frame
= delayed_switch_frame
;
10226 unbind_to (count
, Qnil
);
10228 /* Don't downcase the last character if the caller says don't.
10229 Don't downcase it if the result is undefined, either. */
10230 if ((dont_downcase_last
|| first_binding
>= nmaps
)
10232 && t
- 1 == original_uppercase_position
)
10234 keybuf
[t
- 1] = original_uppercase
;
10235 shift_translated
= 0;
10238 if (shift_translated
)
10239 Vthis_command_keys_shift_translated
= Qt
;
10241 /* Occasionally we fabricate events, perhaps by expanding something
10242 according to function-key-map, or by adding a prefix symbol to a
10243 mouse click in the scroll bar or modeline. In this cases, return
10244 the entire generated key sequence, even if we hit an unbound
10245 prefix or a definition before the end. This means that you will
10246 be able to push back the event properly, and also means that
10247 read-key-sequence will always return a logical unit.
10250 for (; t
< mock_input
; t
++)
10252 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
10253 && NILP (Fzerop (Vecho_keystrokes
)))
10254 echo_char (keybuf
[t
]);
10255 add_command_key (keybuf
[t
]);
10262 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 5, 0,
10263 doc
: /* Read a sequence of keystrokes and return as a string or vector.
10264 The sequence is sufficient to specify a non-prefix command in the
10265 current local and global maps.
10267 First arg PROMPT is a prompt string. If nil, do not prompt specially.
10268 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos
10269 as a continuation of the previous key.
10271 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not
10272 convert the last event to lower case. (Normally any upper case event
10273 is converted to lower case if the original event is undefined and the lower
10274 case equivalent is defined.) A non-nil value is appropriate for reading
10275 a key sequence to be defined.
10277 A C-g typed while in this function is treated like any other character,
10278 and `quit-flag' is not set.
10280 If the key sequence starts with a mouse click, then the sequence is read
10281 using the keymaps of the buffer of the window clicked in, not the buffer
10282 of the selected window as normal.
10284 `read-key-sequence' drops unbound button-down events, since you normally
10285 only care about the click or drag events which follow them. If a drag
10286 or multi-click event is unbound, but the corresponding click event would
10287 be bound, `read-key-sequence' turns the event into a click event at the
10288 drag's starting position. This means that you don't have to distinguish
10289 between click and drag, double, or triple events unless you want to.
10291 `read-key-sequence' prefixes mouse events on mode lines, the vertical
10292 lines separating windows, and scroll bars with imaginary keys
10293 `mode-line', `vertical-line', and `vertical-scroll-bar'.
10295 Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this
10296 function will process a switch-frame event if the user switches frames
10297 before typing anything. If the user switches frames in the middle of a
10298 key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME
10299 is nil, then the event will be put off until after the current key sequence.
10301 `read-key-sequence' checks `function-key-map' for function key
10302 sequences, where they wouldn't conflict with ordinary bindings. See
10303 `function-key-map' for more details.
10305 The optional fifth argument COMMAND-LOOP, if non-nil, means
10306 that this key sequence is being read by something that will
10307 read commands one after another. It should be nil if the caller
10308 will read just one key sequence. */)
10309 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
10311 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
10312 Lisp_Object can_return_switch_frame
, command_loop
;
10314 Lisp_Object keybuf
[30];
10316 struct gcpro gcpro1
;
10317 int count
= SPECPDL_INDEX ();
10319 if (!NILP (prompt
))
10320 CHECK_STRING (prompt
);
10323 specbind (Qinput_method_exit_on_first_char
,
10324 (NILP (command_loop
) ? Qt
: Qnil
));
10325 specbind (Qinput_method_use_echo_area
,
10326 (NILP (command_loop
) ? Qt
: Qnil
));
10328 bzero (keybuf
, sizeof keybuf
);
10329 GCPRO1 (keybuf
[0]);
10330 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
10332 if (NILP (continue_echo
))
10334 this_command_key_count
= 0;
10335 this_command_key_count_reset
= 0;
10336 this_single_command_key_start
= 0;
10339 #ifdef HAVE_WINDOW_SYSTEM
10340 if (display_hourglass_p
)
10341 cancel_hourglass ();
10344 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
10345 prompt
, ! NILP (dont_downcase_last
),
10346 ! NILP (can_return_switch_frame
), 0);
10348 #if 0 /* The following is fine for code reading a key sequence and
10349 then proceeding with a lenghty computation, but it's not good
10350 for code reading keys in a loop, like an input method. */
10351 #ifdef HAVE_WINDOW_SYSTEM
10352 if (display_hourglass_p
)
10353 start_hourglass ();
10363 return unbind_to (count
, make_event_array (i
, keybuf
));
10366 DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector
,
10367 Sread_key_sequence_vector
, 1, 5, 0,
10368 doc
: /* Like `read-key-sequence' but always return a vector. */)
10369 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
10371 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
10372 Lisp_Object can_return_switch_frame
, command_loop
;
10374 Lisp_Object keybuf
[30];
10376 struct gcpro gcpro1
;
10377 int count
= SPECPDL_INDEX ();
10379 if (!NILP (prompt
))
10380 CHECK_STRING (prompt
);
10383 specbind (Qinput_method_exit_on_first_char
,
10384 (NILP (command_loop
) ? Qt
: Qnil
));
10385 specbind (Qinput_method_use_echo_area
,
10386 (NILP (command_loop
) ? Qt
: Qnil
));
10388 bzero (keybuf
, sizeof keybuf
);
10389 GCPRO1 (keybuf
[0]);
10390 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
10392 if (NILP (continue_echo
))
10394 this_command_key_count
= 0;
10395 this_command_key_count_reset
= 0;
10396 this_single_command_key_start
= 0;
10399 #ifdef HAVE_WINDOW_SYSTEM
10400 if (display_hourglass_p
)
10401 cancel_hourglass ();
10404 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
10405 prompt
, ! NILP (dont_downcase_last
),
10406 ! NILP (can_return_switch_frame
), 0);
10408 #ifdef HAVE_WINDOW_SYSTEM
10409 if (display_hourglass_p
)
10410 start_hourglass ();
10419 return unbind_to (count
, Fvector (i
, keybuf
));
10422 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 4, 0,
10423 doc
: /* Execute CMD as an editor command.
10424 CMD must be a symbol that satisfies the `commandp' predicate.
10425 Optional second arg RECORD-FLAG non-nil
10426 means unconditionally put this command in `command-history'.
10427 Otherwise, that is done only if an arg is read using the minibuffer.
10428 The argument KEYS specifies the value to use instead of (this-command-keys)
10429 when reading the arguments; if it is nil, (this-command-keys) is used.
10430 The argument SPECIAL, if non-nil, means that this command is executing
10431 a special event, so ignore the prefix argument and don't clear it. */)
10432 (cmd
, record_flag
, keys
, special
)
10433 Lisp_Object cmd
, record_flag
, keys
, special
;
10435 register Lisp_Object final
;
10436 register Lisp_Object tem
;
10437 Lisp_Object prefixarg
;
10438 extern int debug_on_next_call
;
10440 debug_on_next_call
= 0;
10442 if (NILP (special
))
10444 prefixarg
= current_kboard
->Vprefix_arg
;
10445 Vcurrent_prefix_arg
= prefixarg
;
10446 current_kboard
->Vprefix_arg
= Qnil
;
10453 tem
= Fget (cmd
, Qdisabled
);
10454 if (!NILP (tem
) && !NILP (Vrun_hooks
))
10456 tem
= Fsymbol_value (Qdisabled_command_function
);
10458 return call1 (Vrun_hooks
, Qdisabled_command_function
);
10464 final
= Findirect_function (cmd
, Qnil
);
10466 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
10468 struct gcpro gcpro1
, gcpro2
;
10470 GCPRO2 (cmd
, prefixarg
);
10471 do_autoload (final
, cmd
);
10478 if (STRINGP (final
) || VECTORP (final
))
10480 /* If requested, place the macro in the command history. For
10481 other sorts of commands, call-interactively takes care of
10483 if (!NILP (record_flag
))
10486 = Fcons (Fcons (Qexecute_kbd_macro
,
10487 Fcons (final
, Fcons (prefixarg
, Qnil
))),
10490 /* Don't keep command history around forever. */
10491 if (NUMBERP (Vhistory_length
) && XINT (Vhistory_length
) > 0)
10493 tem
= Fnthcdr (Vhistory_length
, Vcommand_history
);
10495 XSETCDR (tem
, Qnil
);
10499 return Fexecute_kbd_macro (final
, prefixarg
, Qnil
);
10502 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
10503 /* Don't call Fcall_interactively directly because we want to make
10504 sure the backtrace has an entry for `call-interactively'.
10505 For the same reason, pass `cmd' rather than `final'. */
10506 return call3 (Qcall_interactively
, cmd
, record_flag
, keys
);
10513 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
10515 doc
: /* Read function name, then read its arguments and call it.
10517 To pass a numeric argument to the command you are invoking with, specify
10518 the numeric argument to this command.
10520 Noninteractively, the argument PREFIXARG is the prefix argument to
10521 give to the command you invoke, if it asks for an argument. */)
10523 Lisp_Object prefixarg
;
10525 Lisp_Object function
;
10527 int saved_last_point_position
;
10528 Lisp_Object saved_keys
, saved_last_point_position_buffer
;
10529 Lisp_Object bindings
, value
;
10530 struct gcpro gcpro1
, gcpro2
, gcpro3
;
10531 #ifdef HAVE_WINDOW_SYSTEM
10532 /* The call to Fcompleting_read wil start and cancel the hourglass,
10533 but if the hourglass was already scheduled, this means that no
10534 hourglass will be shown for the actual M-x command itself.
10535 So we restart it if it is already scheduled. Note that checking
10536 hourglass_shown_p is not enough, normally the hourglass is not shown,
10537 just scheduled to be shown. */
10538 int hstarted
= hourglass_started ();
10541 saved_keys
= Fvector (this_command_key_count
,
10542 XVECTOR (this_command_keys
)->contents
);
10543 saved_last_point_position_buffer
= last_point_position_buffer
;
10544 saved_last_point_position
= last_point_position
;
10546 GCPRO3 (saved_keys
, prefixarg
, saved_last_point_position_buffer
);
10548 if (EQ (prefixarg
, Qminus
))
10549 strcpy (buf
, "- ");
10550 else if (CONSP (prefixarg
) && XINT (XCAR (prefixarg
)) == 4)
10551 strcpy (buf
, "C-u ");
10552 else if (CONSP (prefixarg
) && INTEGERP (XCAR (prefixarg
)))
10553 sprintf (buf
, "%ld ", (long) XINT (XCAR (prefixarg
)));
10554 else if (INTEGERP (prefixarg
))
10555 sprintf (buf
, "%ld ", (long) XINT (prefixarg
));
10557 /* This isn't strictly correct if execute-extended-command
10558 is bound to anything else. Perhaps it should use
10559 this_command_keys? */
10560 strcat (buf
, "M-x ");
10562 /* Prompt with buf, and then read a string, completing from and
10563 restricting to the set of all defined commands. Don't provide
10564 any initial input. Save the command read on the extended-command
10566 function
= Fcompleting_read (build_string (buf
),
10567 Vobarray
, Qcommandp
,
10568 Qt
, Qnil
, Qextended_command_history
, Qnil
,
10571 #ifdef HAVE_WINDOW_SYSTEM
10572 if (hstarted
) start_hourglass ();
10575 if (STRINGP (function
) && SCHARS (function
) == 0)
10576 error ("No command name given");
10578 /* Set this_command_keys to the concatenation of saved_keys and
10579 function, followed by a RET. */
10584 this_command_key_count
= 0;
10585 this_command_key_count_reset
= 0;
10586 this_single_command_key_start
= 0;
10588 keys
= XVECTOR (saved_keys
)->contents
;
10589 for (i
= 0; i
< XVECTOR (saved_keys
)->size
; i
++)
10590 add_command_key (keys
[i
]);
10592 for (i
= 0; i
< SCHARS (function
); i
++)
10593 add_command_key (Faref (function
, make_number (i
)));
10595 add_command_key (make_number ('\015'));
10598 last_point_position
= saved_last_point_position
;
10599 last_point_position_buffer
= saved_last_point_position_buffer
;
10603 function
= Fintern (function
, Qnil
);
10604 current_kboard
->Vprefix_arg
= prefixarg
;
10605 Vthis_command
= function
;
10606 real_this_command
= function
;
10608 /* If enabled, show which key runs this command. */
10609 if (!NILP (Vsuggest_key_bindings
)
10610 && NILP (Vexecuting_kbd_macro
)
10611 && SYMBOLP (function
))
10612 bindings
= Fwhere_is_internal (function
, Voverriding_local_map
,
10618 GCPRO3 (bindings
, value
, function
);
10619 value
= Fcommand_execute (function
, Qt
, Qnil
, Qnil
);
10621 /* If the command has a key binding, print it now. */
10622 if (!NILP (bindings
)
10623 && ! (VECTORP (bindings
) && EQ (Faref (bindings
, make_number (0)),
10626 /* But first wait, and skip the message if there is input. */
10627 Lisp_Object waited
;
10629 /* If this command displayed something in the echo area;
10630 wait a few seconds, then display our suggestion message. */
10631 if (NILP (echo_area_buffer
[0]))
10632 waited
= sit_for (make_number (0), 0, 2);
10633 else if (NUMBERP (Vsuggest_key_bindings
))
10634 waited
= sit_for (Vsuggest_key_bindings
, 0, 2);
10636 waited
= sit_for (make_number (2), 0, 2);
10638 if (!NILP (waited
) && ! CONSP (Vunread_command_events
))
10640 Lisp_Object binding
;
10642 int message_p
= push_message ();
10643 int count
= SPECPDL_INDEX ();
10645 record_unwind_protect (pop_message_unwind
, Qnil
);
10646 binding
= Fkey_description (bindings
, Qnil
);
10649 = (char *) alloca (SCHARS (SYMBOL_NAME (function
))
10652 sprintf (newmessage
, "You can run the command `%s' with %s",
10653 SDATA (SYMBOL_NAME (function
)),
10655 message2_nolog (newmessage
,
10656 strlen (newmessage
),
10657 STRING_MULTIBYTE (binding
));
10658 if (NUMBERP (Vsuggest_key_bindings
))
10659 waited
= sit_for (Vsuggest_key_bindings
, 0, 2);
10661 waited
= sit_for (make_number (2), 0, 2);
10663 if (!NILP (waited
) && message_p
)
10664 restore_message ();
10666 unbind_to (count
, Qnil
);
10670 RETURN_UNGCPRO (value
);
10674 /* Return nonzero if input events are pending. */
10677 detect_input_pending ()
10679 if (!input_pending
)
10680 get_input_pending (&input_pending
, 0);
10682 return input_pending
;
10685 /* Return nonzero if input events other than mouse movements are
10689 detect_input_pending_ignore_squeezables ()
10691 if (!input_pending
)
10692 get_input_pending (&input_pending
, READABLE_EVENTS_IGNORE_SQUEEZABLES
);
10694 return input_pending
;
10697 /* Return nonzero if input events are pending, and run any pending timers. */
10700 detect_input_pending_run_timers (do_display
)
10703 int old_timers_run
= timers_run
;
10705 if (!input_pending
)
10706 get_input_pending (&input_pending
, READABLE_EVENTS_DO_TIMERS_NOW
);
10708 if (old_timers_run
!= timers_run
&& do_display
)
10710 redisplay_preserve_echo_area (8);
10711 /* The following fixes a bug when using lazy-lock with
10712 lazy-lock-defer-on-the-fly set to t, i.e. when fontifying
10713 from an idle timer function. The symptom of the bug is that
10714 the cursor sometimes doesn't become visible until the next X
10715 event is processed. --gerd. */
10717 Lisp_Object tail
, frame
;
10718 FOR_EACH_FRAME (tail
, frame
)
10719 if (FRAME_RIF (XFRAME (frame
)))
10720 FRAME_RIF (XFRAME (frame
))->flush_display (XFRAME (frame
));
10724 return input_pending
;
10727 /* This is called in some cases before a possible quit.
10728 It cases the next call to detect_input_pending to recompute input_pending.
10729 So calling this function unnecessarily can't do any harm. */
10732 clear_input_pending ()
10737 /* Return nonzero if there are pending requeued events.
10738 This isn't used yet. The hope is to make wait_reading_process_output
10739 call it, and return if it runs Lisp code that unreads something.
10740 The problem is, kbd_buffer_get_event needs to be fixed to know what
10741 to do in that case. It isn't trivial. */
10744 requeued_events_pending_p ()
10746 return (!NILP (Vunread_command_events
) || unread_command_char
!= -1);
10750 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
10751 doc
: /* Return t if command input is currently available with no wait.
10752 Actually, the value is nil only if we can be sure that no input is available;
10753 if there is a doubt, the value is t. */)
10756 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1
10757 || !NILP (Vunread_post_input_method_events
)
10758 || !NILP (Vunread_input_method_events
))
10761 get_input_pending (&input_pending
,
10762 READABLE_EVENTS_DO_TIMERS_NOW
10763 | READABLE_EVENTS_FILTER_EVENTS
);
10764 return input_pending
> 0 ? Qt
: Qnil
;
10767 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
10768 doc
: /* Return vector of last 300 events, not counting those from keyboard macros. */)
10771 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
10774 if (total_keys
< NUM_RECENT_KEYS
)
10775 return Fvector (total_keys
, keys
);
10778 val
= Fvector (NUM_RECENT_KEYS
, keys
);
10779 bcopy (keys
+ recent_keys_index
,
10780 XVECTOR (val
)->contents
,
10781 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
10783 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
10784 recent_keys_index
* sizeof (Lisp_Object
));
10789 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
10790 doc
: /* Return the key sequence that invoked this command.
10791 However, if the command has called `read-key-sequence', it returns
10792 the last key sequence that has been read.
10793 The value is a string or a vector.
10795 See also `this-command-keys-vector'. */)
10798 return make_event_array (this_command_key_count
,
10799 XVECTOR (this_command_keys
)->contents
);
10802 DEFUN ("this-command-keys-vector", Fthis_command_keys_vector
, Sthis_command_keys_vector
, 0, 0, 0,
10803 doc
: /* Return the key sequence that invoked this command, as a vector.
10804 However, if the command has called `read-key-sequence', it returns
10805 the last key sequence that has been read.
10807 See also `this-command-keys'. */)
10810 return Fvector (this_command_key_count
,
10811 XVECTOR (this_command_keys
)->contents
);
10814 DEFUN ("this-single-command-keys", Fthis_single_command_keys
,
10815 Sthis_single_command_keys
, 0, 0, 0,
10816 doc
: /* Return the key sequence that invoked this command.
10817 More generally, it returns the last key sequence read, either by
10818 the command loop or by `read-key-sequence'.
10819 Unlike `this-command-keys', this function's value
10820 does not include prefix arguments.
10821 The value is always a vector. */)
10824 return Fvector (this_command_key_count
10825 - this_single_command_key_start
,
10826 (XVECTOR (this_command_keys
)->contents
10827 + this_single_command_key_start
));
10830 DEFUN ("this-single-command-raw-keys", Fthis_single_command_raw_keys
,
10831 Sthis_single_command_raw_keys
, 0, 0, 0,
10832 doc
: /* Return the raw events that were read for this command.
10833 More generally, it returns the last key sequence read, either by
10834 the command loop or by `read-key-sequence'.
10835 Unlike `this-single-command-keys', this function's value
10836 shows the events before all translations (except for input methods).
10837 The value is always a vector. */)
10840 return Fvector (raw_keybuf_count
,
10841 (XVECTOR (raw_keybuf
)->contents
));
10844 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths
,
10845 Sreset_this_command_lengths
, 0, 0, 0,
10846 doc
: /* Make the unread events replace the last command and echo.
10847 Used in `universal-argument-other-key'.
10849 `universal-argument-other-key' rereads the event just typed.
10850 It then gets translated through `function-key-map'.
10851 The translated event has to replace the real events,
10852 both in the value of (this-command-keys) and in echoing.
10853 To achieve this, `universal-argument-other-key' calls
10854 `reset-this-command-lengths', which discards the record of reading
10855 these events the first time. */)
10858 this_command_key_count
= before_command_key_count
;
10859 if (this_command_key_count
< this_single_command_key_start
)
10860 this_single_command_key_start
= this_command_key_count
;
10862 echo_truncate (before_command_echo_length
);
10864 /* Cause whatever we put into unread-command-events
10865 to echo as if it were being freshly read from the keyboard. */
10866 this_command_key_count_reset
= 1;
10871 DEFUN ("clear-this-command-keys", Fclear_this_command_keys
,
10872 Sclear_this_command_keys
, 0, 1, 0,
10873 doc
: /* Clear out the vector that `this-command-keys' returns.
10874 Also clear the record of the last 100 events, unless optional arg
10875 KEEP-RECORD is non-nil. */)
10877 Lisp_Object keep_record
;
10881 this_command_key_count
= 0;
10882 this_command_key_count_reset
= 0;
10884 if (NILP (keep_record
))
10886 for (i
= 0; i
< XVECTOR (recent_keys
)->size
; ++i
)
10887 XVECTOR (recent_keys
)->contents
[i
] = Qnil
;
10889 recent_keys_index
= 0;
10894 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
10895 doc
: /* Return the current depth in recursive edits. */)
10899 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
10903 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
10904 "FOpen dribble file: ",
10905 doc
: /* Start writing all keyboard characters to a dribble file called FILE.
10906 If FILE is nil, close any open dribble file. */)
10919 file
= Fexpand_file_name (file
, Qnil
);
10920 dribble
= fopen (SDATA (file
), "w");
10922 report_file_error ("Opening dribble", Fcons (file
, Qnil
));
10927 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
10928 doc
: /* Discard the contents of the terminal input buffer.
10929 Also end any kbd macro being defined. */)
10932 if (!NILP (current_kboard
->defining_kbd_macro
))
10934 /* Discard the last command from the macro. */
10935 Fcancel_kbd_macro_events ();
10939 update_mode_lines
++;
10941 Vunread_command_events
= Qnil
;
10942 unread_command_char
= -1;
10944 discard_tty_input ();
10946 kbd_fetch_ptr
= kbd_store_ptr
;
10952 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
10953 doc
: /* Stop Emacs and return to superior process. You can resume later.
10954 If `cannot-suspend' is non-nil, or if the system doesn't support job
10955 control, run a subshell instead.
10957 If optional arg STUFFSTRING is non-nil, its characters are stuffed
10958 to be read as terminal input by Emacs's parent, after suspension.
10960 Before suspending, run the normal hook `suspend-hook'.
10961 After resumption run the normal hook `suspend-resume-hook'.
10963 Some operating systems cannot stop the Emacs process and resume it later.
10964 On such systems, Emacs starts a subshell instead of suspending. */)
10966 Lisp_Object stuffstring
;
10968 int count
= SPECPDL_INDEX ();
10969 int old_height
, old_width
;
10971 struct gcpro gcpro1
;
10973 if (tty_list
&& tty_list
->next
)
10974 error ("There are other tty frames open; close them before suspending Emacs");
10976 if (!NILP (stuffstring
))
10977 CHECK_STRING (stuffstring
);
10979 /* Run the functions in suspend-hook. */
10980 if (!NILP (Vrun_hooks
))
10981 call1 (Vrun_hooks
, intern ("suspend-hook"));
10983 GCPRO1 (stuffstring
);
10984 get_tty_size (fileno (CURTTY ()->input
), &old_width
, &old_height
);
10985 reset_all_sys_modes ();
10986 /* sys_suspend can get an error if it tries to fork a subshell
10987 and the system resources aren't available for that. */
10988 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object
))) init_all_sys_modes
,
10990 stuff_buffered_input (stuffstring
);
10991 if (cannot_suspend
)
10995 unbind_to (count
, Qnil
);
10997 /* Check if terminal/window size has changed.
10998 Note that this is not useful when we are running directly
10999 with a window system; but suspend should be disabled in that case. */
11000 get_tty_size (fileno (CURTTY ()->input
), &width
, &height
);
11001 if (width
!= old_width
|| height
!= old_height
)
11002 change_frame_size (SELECTED_FRAME (), height
, width
, 0, 0, 0);
11004 /* Run suspend-resume-hook. */
11005 if (!NILP (Vrun_hooks
))
11006 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
11012 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
11013 Then in any case stuff anything Emacs has read ahead and not used. */
11016 stuff_buffered_input (stuffstring
)
11017 Lisp_Object stuffstring
;
11019 #ifdef SIGTSTP /* stuff_char is defined if SIGTSTP. */
11020 register unsigned char *p
;
11022 if (STRINGP (stuffstring
))
11024 register int count
;
11026 p
= SDATA (stuffstring
);
11027 count
= SBYTES (stuffstring
);
11028 while (count
-- > 0)
11033 /* Anything we have read ahead, put back for the shell to read. */
11034 /* ?? What should this do when we have multiple keyboards??
11035 Should we ignore anything that was typed in at the "wrong" kboard?
11037 rms: we should stuff everything back into the kboard
11039 for (; kbd_fetch_ptr
!= kbd_store_ptr
; kbd_fetch_ptr
++)
11042 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
11043 kbd_fetch_ptr
= kbd_buffer
;
11044 if (kbd_fetch_ptr
->kind
== ASCII_KEYSTROKE_EVENT
)
11045 stuff_char (kbd_fetch_ptr
->code
);
11047 clear_event (kbd_fetch_ptr
);
11051 #endif /* SIGTSTP */
11055 set_waiting_for_input (time_to_clear
)
11056 EMACS_TIME
*time_to_clear
;
11058 input_available_clear_time
= time_to_clear
;
11060 /* Tell handle_interrupt to throw back to read_char, */
11061 waiting_for_input
= 1;
11063 /* If handle_interrupt was called before and buffered a C-g,
11064 make it run again now, to avoid timing error. */
11065 if (!NILP (Vquit_flag
))
11066 quit_throw_to_read_char ();
11070 clear_waiting_for_input ()
11072 /* Tell handle_interrupt not to throw back to read_char, */
11073 waiting_for_input
= 0;
11074 input_available_clear_time
= 0;
11077 /* The SIGINT handler.
11079 If we have a frame on the controlling tty, we assume that the
11080 SIGINT was generated by C-g, so we call handle_interrupt.
11081 Otherwise, the handler kills Emacs. */
11084 interrupt_signal (signalnum
) /* If we don't have an argument, */
11085 int signalnum
; /* some compilers complain in signal calls. */
11087 /* Must preserve main program's value of errno. */
11088 int old_errno
= errno
;
11089 struct terminal
*terminal
;
11091 #if defined (USG) && !defined (POSIX_SIGNALS)
11092 /* USG systems forget handlers when they are used;
11093 must reestablish each time */
11094 signal (SIGINT
, interrupt_signal
);
11095 signal (SIGQUIT
, interrupt_signal
);
11098 SIGNAL_THREAD_CHECK (signalnum
);
11100 /* See if we have an active terminal on our controlling tty. */
11101 terminal
= get_named_tty ("/dev/tty");
11104 /* If there are no frames there, let's pretend that we are a
11105 well-behaving UN*X program and quit. */
11106 Fkill_emacs (Qnil
);
11110 /* Otherwise, the SIGINT was probably generated by C-g. */
11112 /* Set internal_last_event_frame to the top frame of the
11113 controlling tty, if we have a frame there. We disable the
11114 interrupt key on secondary ttys, so the SIGINT must have come
11115 from the controlling tty. */
11116 internal_last_event_frame
= terminal
->display_info
.tty
->top_frame
;
11118 handle_interrupt ();
11124 /* This routine is called at interrupt level in response to C-g.
11126 It is called from the SIGINT handler or kbd_buffer_store_event.
11128 If `waiting_for_input' is non zero, then unless `echoing' is
11129 nonzero, immediately throw back to read_char.
11131 Otherwise it sets the Lisp variable quit-flag not-nil. This causes
11132 eval to throw, when it gets a chance. If quit-flag is already
11133 non-nil, it stops the job right away. */
11136 handle_interrupt ()
11142 /* XXX This code needs to be revised for multi-tty support. */
11143 if (!NILP (Vquit_flag
) && get_named_tty ("/dev/tty"))
11145 /* If SIGINT isn't blocked, don't let us be interrupted by
11146 another SIGINT, it might be harmful due to non-reentrancy
11147 in I/O functions. */
11148 sigblock (sigmask (SIGINT
));
11151 reset_all_sys_modes ();
11153 #ifdef SIGTSTP /* Support possible in later USG versions */
11155 * On systems which can suspend the current process and return to the original
11156 * shell, this command causes the user to end up back at the shell.
11157 * The "Auto-save" and "Abort" questions are not asked until
11158 * the user elects to return to emacs, at which point he can save the current
11159 * job and either dump core or continue.
11163 /* Perhaps should really fork an inferior shell?
11164 But that would not provide any way to get back
11165 to the original shell, ever. */
11166 printf ("No support for stopping a process on this operating system;\n");
11167 printf ("you can continue or abort.\n");
11168 #endif /* not SIGTSTP */
11170 /* We must remain inside the screen area when the internal terminal
11171 is used. Note that [Enter] is not echoed by dos. */
11172 cursor_to (SELECTED_FRAME (), 0, 0);
11174 /* It doesn't work to autosave while GC is in progress;
11175 the code used for auto-saving doesn't cope with the mark bit. */
11176 if (!gc_in_progress
)
11178 printf ("Auto-save? (y or n) ");
11180 if (((c
= getchar ()) & ~040) == 'Y')
11182 Fdo_auto_save (Qt
, Qnil
);
11184 printf ("\r\nAuto-save done");
11185 #else /* not MSDOS */
11186 printf ("Auto-save done\n");
11187 #endif /* not MSDOS */
11189 while (c
!= '\n') c
= getchar ();
11193 /* During GC, it must be safe to reenable quitting again. */
11194 Vinhibit_quit
= Qnil
;
11197 #endif /* not MSDOS */
11198 printf ("Garbage collection in progress; cannot auto-save now\r\n");
11199 printf ("but will instead do a real quit after garbage collection ends\r\n");
11204 printf ("\r\nAbort? (y or n) ");
11205 #else /* not MSDOS */
11206 printf ("Abort (and dump core)? (y or n) ");
11207 #endif /* not MSDOS */
11209 if (((c
= getchar ()) & ~040) == 'Y')
11211 while (c
!= '\n') c
= getchar ();
11213 printf ("\r\nContinuing...\r\n");
11214 #else /* not MSDOS */
11215 printf ("Continuing...\n");
11216 #endif /* not MSDOS */
11218 init_all_sys_modes ();
11223 /* If executing a function that wants to be interrupted out of
11224 and the user has not deferred quitting by binding `inhibit-quit'
11225 then quit right away. */
11226 if (immediate_quit
&& NILP (Vinhibit_quit
))
11228 struct gl_state_s saved
;
11229 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
11231 immediate_quit
= 0;
11234 GCPRO4 (saved
.object
, saved
.global_code
,
11235 saved
.current_syntax_table
, saved
.old_prop
);
11236 Fsignal (Qquit
, Qnil
);
11241 /* Else request quit when it's safe */
11245 /* TODO: The longjmp in this call throws the NS event loop integration off,
11246 and it seems to do fine without this. Probably some attention
11247 needs to be paid to the setting of waiting_for_input in
11248 wait_reading_process_output() under HAVE_NS because of the call
11249 to ns_select there (needed because otherwise events aren't picked up
11250 outside of polling since we don't get SIGIO like X and we don't have a
11251 separate event loop thread like W32. */
11253 if (waiting_for_input
&& !echoing
)
11254 quit_throw_to_read_char ();
11258 /* Handle a C-g by making read_char return C-g. */
11261 quit_throw_to_read_char ()
11264 /* Prevent another signal from doing this before we finish. */
11265 clear_waiting_for_input ();
11268 Vunread_command_events
= Qnil
;
11269 unread_command_char
= -1;
11271 #if 0 /* Currently, sit_for is called from read_char without turning
11272 off polling. And that can call set_waiting_for_input.
11273 It seems to be harmless. */
11274 #ifdef POLL_FOR_INPUT
11275 /* May be > 1 if in recursive minibuffer. */
11276 if (poll_suppress_count
== 0)
11280 if (FRAMEP (internal_last_event_frame
)
11281 && !EQ (internal_last_event_frame
, selected_frame
))
11282 do_switch_frame (make_lispy_switch_frame (internal_last_event_frame
),
11285 _longjmp (getcjmp
, 1);
11288 DEFUN ("set-input-interrupt-mode", Fset_input_interrupt_mode
, Sset_input_interrupt_mode
, 1, 1, 0,
11289 doc
: /* Set interrupt mode of reading keyboard input.
11290 If INTERRUPT is non-nil, Emacs will use input interrupts;
11291 otherwise Emacs uses CBREAK mode.
11293 See also `current-input-mode'. */)
11295 Lisp_Object interrupt
;
11297 int new_interrupt_input
;
11299 /* Note SIGIO has been undef'd if FIONREAD is missing. */
11300 #ifdef HAVE_X_WINDOWS
11301 if (x_display_list
!= NULL
)
11303 /* When using X, don't give the user a real choice,
11304 because we haven't implemented the mechanisms to support it. */
11305 #ifdef NO_SOCK_SIGIO
11306 new_interrupt_input
= 0;
11307 #else /* not NO_SOCK_SIGIO */
11308 new_interrupt_input
= 1;
11309 #endif /* NO_SOCK_SIGIO */
11312 #endif /* HAVE_X_WINDOWS */
11313 new_interrupt_input
= !NILP (interrupt
);
11314 #else /* not SIGIO */
11315 new_interrupt_input
= 0;
11316 #endif /* not SIGIO */
11318 if (new_interrupt_input
!= interrupt_input
)
11320 #ifdef POLL_FOR_INPUT
11324 /* this causes startup screen to be restored and messes with the mouse */
11325 reset_all_sys_modes ();
11327 interrupt_input
= new_interrupt_input
;
11329 init_all_sys_modes ();
11332 #ifdef POLL_FOR_INPUT
11333 poll_suppress_count
= 1;
11340 DEFUN ("set-output-flow-control", Fset_output_flow_control
, Sset_output_flow_control
, 1, 2, 0,
11341 doc
: /* Enable or disable ^S/^Q flow control for output to TERMINAL.
11342 If FLOW is non-nil, flow control is enabled and you cannot use C-s or
11343 C-q in key sequences.
11345 This setting only has an effect on tty terminals and only when
11346 Emacs reads input in CBREAK mode; see `set-input-interrupt-mode'.
11348 See also `current-input-mode'. */)
11350 Lisp_Object flow
, terminal
;
11352 struct terminal
*t
= get_terminal (terminal
, 1);
11353 struct tty_display_info
*tty
;
11354 if (t
== NULL
|| (t
->type
!= output_termcap
&& t
->type
!= output_msdos_raw
))
11356 tty
= t
->display_info
.tty
;
11358 if (tty
->flow_control
!= !NILP (flow
))
11361 /* this causes startup screen to be restored and messes with the mouse */
11362 reset_sys_modes (tty
);
11365 tty
->flow_control
= !NILP (flow
);
11368 init_sys_modes (tty
);
11374 DEFUN ("set-input-meta-mode", Fset_input_meta_mode
, Sset_input_meta_mode
, 1, 2, 0,
11375 doc
: /* Enable or disable 8-bit input on TERMINAL.
11376 If META is t, Emacs will accept 8-bit input, and interpret the 8th
11377 bit as the Meta modifier.
11379 If META is nil, Emacs will ignore the top bit, on the assumption it is
11382 Otherwise, Emacs will accept and pass through 8-bit input without
11383 specially interpreting the top bit.
11385 This setting only has an effect on tty terminal devices.
11387 Optional parameter TERMINAL specifies the tty terminal device to use.
11388 It may be a terminal object, a frame, or nil for the terminal used by
11389 the currently selected frame.
11391 See also `current-input-mode'. */)
11393 Lisp_Object meta
, terminal
;
11395 struct terminal
*t
= get_terminal (terminal
, 1);
11396 struct tty_display_info
*tty
;
11399 if (t
== NULL
|| (t
->type
!= output_termcap
&& t
->type
!= output_msdos_raw
))
11401 tty
= t
->display_info
.tty
;
11405 else if (EQ (meta
, Qt
))
11410 if (tty
->meta_key
!= new_meta
)
11413 /* this causes startup screen to be restored and messes with the mouse */
11414 reset_sys_modes (tty
);
11417 tty
->meta_key
= new_meta
;
11420 init_sys_modes (tty
);
11426 DEFUN ("set-quit-char", Fset_quit_char
, Sset_quit_char
, 1, 1, 0,
11427 doc
: /* Specify character used for quitting.
11428 QUIT must be an ASCII character.
11430 This function only has an effect on the controlling tty of the Emacs
11433 See also `current-input-mode'. */)
11437 struct terminal
*t
= get_named_tty ("/dev/tty");
11438 struct tty_display_info
*tty
;
11439 if (t
== NULL
|| (t
->type
!= output_termcap
&& t
->type
!= output_msdos_raw
))
11441 tty
= t
->display_info
.tty
;
11443 if (NILP (quit
) || !INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400)
11444 error ("QUIT must be an ASCII character");
11447 /* this causes startup screen to be restored and messes with the mouse */
11448 reset_sys_modes (tty
);
11451 /* Don't let this value be out of range. */
11452 quit_char
= XINT (quit
) & (tty
->meta_key
== 0 ? 0177 : 0377);
11455 init_sys_modes (tty
);
11461 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
11462 doc
: /* Set mode of reading keyboard input.
11463 First arg INTERRUPT non-nil means use input interrupts;
11464 nil means use CBREAK mode.
11465 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal
11466 (no effect except in CBREAK mode).
11467 Third arg META t means accept 8-bit input (for a Meta key).
11468 META nil means ignore the top bit, on the assumption it is parity.
11469 Otherwise, accept 8-bit input and don't use the top bit for Meta.
11470 Optional fourth arg QUIT if non-nil specifies character to use for quitting.
11471 See also `current-input-mode'. */)
11472 (interrupt
, flow
, meta
, quit
)
11473 Lisp_Object interrupt
, flow
, meta
, quit
;
11475 Fset_input_interrupt_mode (interrupt
);
11476 Fset_output_flow_control (flow
, Qnil
);
11477 Fset_input_meta_mode (meta
, Qnil
);
11479 Fset_quit_char (quit
);
11483 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
11484 doc
: /* Return information about the way Emacs currently reads keyboard input.
11485 The value is a list of the form (INTERRUPT FLOW META QUIT), where
11486 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if
11487 nil, Emacs is using CBREAK mode.
11488 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the
11489 terminal; this does not apply if Emacs uses interrupt-driven input.
11490 META is t if accepting 8-bit input with 8th bit as Meta flag.
11491 META nil means ignoring the top bit, on the assumption it is parity.
11492 META is neither t nor nil if accepting 8-bit input and using
11493 all 8 bits as the character code.
11494 QUIT is the character Emacs currently uses to quit.
11495 The elements of this list correspond to the arguments of
11496 `set-input-mode'. */)
11499 Lisp_Object val
[4];
11500 struct frame
*sf
= XFRAME (selected_frame
);
11502 val
[0] = interrupt_input
? Qt
: Qnil
;
11503 if (FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
11505 val
[1] = FRAME_TTY (sf
)->flow_control
? Qt
: Qnil
;
11506 val
[2] = (FRAME_TTY (sf
)->meta_key
== 2
11508 : (CURTTY ()->meta_key
== 1 ? Qt
: Qnil
));
11515 XSETFASTINT (val
[3], quit_char
);
11517 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
11520 DEFUN ("posn-at-x-y", Fposn_at_x_y
, Sposn_at_x_y
, 2, 4, 0,
11521 doc
: /* Return position information for pixel coordinates X and Y.
11522 By default, X and Y are relative to text area of the selected window.
11523 Optional third arg FRAME-OR-WINDOW non-nil specifies frame or window.
11524 If optional fourth arg WHOLE is non-nil, X is relative to the left
11525 edge of the window.
11527 The return value is similar to a mouse click position:
11528 (WINDOW AREA-OR-POS (X . Y) TIMESTAMP OBJECT POS (COL . ROW)
11529 IMAGE (DX . DY) (WIDTH . HEIGHT))
11530 The `posn-' functions access elements of such lists. */)
11531 (x
, y
, frame_or_window
, whole
)
11532 Lisp_Object x
, y
, frame_or_window
, whole
;
11537 if (NILP (frame_or_window
))
11538 frame_or_window
= selected_window
;
11540 if (WINDOWP (frame_or_window
))
11544 CHECK_LIVE_WINDOW (frame_or_window
);
11546 w
= XWINDOW (frame_or_window
);
11547 XSETINT (x
, (XINT (x
)
11548 + WINDOW_LEFT_EDGE_X (w
)
11550 ? window_box_left_offset (w
, TEXT_AREA
)
11552 XSETINT (y
, WINDOW_TO_FRAME_PIXEL_Y (w
, XINT (y
)));
11553 frame_or_window
= w
->frame
;
11556 CHECK_LIVE_FRAME (frame_or_window
);
11558 return make_lispy_position (XFRAME (frame_or_window
), &x
, &y
, 0);
11561 DEFUN ("posn-at-point", Fposn_at_point
, Sposn_at_point
, 0, 2, 0,
11562 doc
: /* Return position information for buffer POS in WINDOW.
11563 POS defaults to point in WINDOW; WINDOW defaults to the selected window.
11565 Return nil if position is not visible in window. Otherwise,
11566 the return value is similar to that returned by `event-start' for
11567 a mouse click at the upper left corner of the glyph corresponding
11568 to the given buffer position:
11569 (WINDOW AREA-OR-POS (X . Y) TIMESTAMP OBJECT POS (COL . ROW)
11570 IMAGE (DX . DY) (WIDTH . HEIGHT))
11571 The `posn-' functions access elements of such lists. */)
11573 Lisp_Object pos
, window
;
11578 window
= selected_window
;
11580 tem
= Fpos_visible_in_window_p (pos
, window
, Qt
);
11583 Lisp_Object x
= XCAR (tem
);
11584 Lisp_Object y
= XCAR (XCDR (tem
));
11586 /* Point invisible due to hscrolling? */
11589 tem
= Fposn_at_x_y (x
, y
, window
, Qnil
);
11597 * Set up a new kboard object with reasonable initial values.
11603 kb
->Voverriding_terminal_local_map
= Qnil
;
11604 kb
->Vlast_command
= Qnil
;
11605 kb
->Vreal_last_command
= Qnil
;
11606 kb
->Vkeyboard_translate_table
= Qnil
;
11607 kb
->Vlast_repeatable_command
= Qnil
;
11608 kb
->Vprefix_arg
= Qnil
;
11609 kb
->Vlast_prefix_arg
= Qnil
;
11610 kb
->kbd_queue
= Qnil
;
11611 kb
->kbd_queue_has_data
= 0;
11612 kb
->immediate_echo
= 0;
11613 kb
->echo_string
= Qnil
;
11614 kb
->echo_after_prompt
= -1;
11615 kb
->kbd_macro_buffer
= 0;
11616 kb
->kbd_macro_bufsize
= 0;
11617 kb
->defining_kbd_macro
= Qnil
;
11618 kb
->Vlast_kbd_macro
= Qnil
;
11619 kb
->reference_count
= 0;
11620 kb
->Vsystem_key_alist
= Qnil
;
11621 kb
->system_key_syms
= Qnil
;
11622 kb
->Vwindow_system
= Qt
; /* Unset. */
11623 kb
->Vinput_decode_map
= Fmake_sparse_keymap (Qnil
);
11624 kb
->Vlocal_function_key_map
= Fmake_sparse_keymap (Qnil
);
11625 Fset_keymap_parent (kb
->Vlocal_function_key_map
, Vfunction_key_map
);
11626 kb
->Vdefault_minibuffer_frame
= Qnil
;
11630 * Destroy the contents of a kboard object, but not the object itself.
11631 * We use this just before deleting it, or if we're going to initialize
11632 * it a second time.
11638 xfree (kb
->kbd_macro_buffer
);
11641 /* Free KB and memory referenced from it. */
11649 for (kbp
= &all_kboards
; *kbp
!= kb
; kbp
= &(*kbp
)->next_kboard
)
11652 *kbp
= kb
->next_kboard
;
11654 /* Prevent a dangling reference to KB. */
11655 if (kb
== current_kboard
11656 && FRAMEP (selected_frame
)
11657 && FRAME_LIVE_P (XFRAME (selected_frame
)))
11659 current_kboard
= FRAME_KBOARD (XFRAME (selected_frame
));
11661 if (current_kboard
== kb
)
11672 /* This is correct before outermost invocation of the editor loop */
11673 command_loop_level
= -1;
11674 immediate_quit
= 0;
11675 quit_char
= Ctl ('g');
11676 Vunread_command_events
= Qnil
;
11677 unread_command_char
= -1;
11678 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
11680 recent_keys_index
= 0;
11681 kbd_fetch_ptr
= kbd_buffer
;
11682 kbd_store_ptr
= kbd_buffer
;
11683 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
11684 do_mouse_tracking
= Qnil
;
11687 interrupt_input_blocked
= 0;
11688 interrupt_input_pending
= 0;
11690 pending_signals
= 0;
11693 /* This means that command_loop_1 won't try to select anything the first
11695 internal_last_event_frame
= Qnil
;
11696 Vlast_event_frame
= internal_last_event_frame
;
11698 current_kboard
= initial_kboard
;
11699 /* Re-initialize the keyboard again. */
11700 wipe_kboard (current_kboard
);
11701 init_kboard (current_kboard
);
11702 /* A value of nil for Vwindow_system normally means a tty, but we also use
11703 it for the initial terminal since there is no window system there. */
11704 current_kboard
->Vwindow_system
= Qnil
;
11706 if (!noninteractive
)
11708 /* Before multi-tty support, these handlers used to be installed
11709 only if the current session was a tty session. Now an Emacs
11710 session may have multiple display types, so we always handle
11711 SIGINT. There is special code in interrupt_signal to exit
11712 Emacs on SIGINT when there are no termcap frames on the
11713 controlling terminal. */
11714 signal (SIGINT
, interrupt_signal
);
11715 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
11716 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
11717 SIGQUIT and we can't tell which one it will give us. */
11718 signal (SIGQUIT
, interrupt_signal
);
11719 #endif /* HAVE_TERMIO */
11721 /* Note SIGIO has been undef'd if FIONREAD is missing. */
11723 if (!noninteractive
)
11724 signal (SIGIO
, input_available_signal
);
11727 /* Use interrupt input by default, if it works and noninterrupt input
11728 has deficiencies. */
11730 #ifdef INTERRUPT_INPUT
11731 interrupt_input
= 1;
11733 interrupt_input
= 0;
11739 if (keyboard_init_hook
)
11740 (*keyboard_init_hook
) ();
11742 #ifdef POLL_FOR_INPUT
11744 poll_suppress_count
= 1;
11749 /* This type's only use is in syms_of_keyboard, to initialize the
11750 event header symbols and put properties on them. */
11751 struct event_head
{
11757 struct event_head head_table
[] = {
11758 {&Qmouse_movement
, "mouse-movement", &Qmouse_movement
},
11759 {&Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
},
11760 {&Qswitch_frame
, "switch-frame", &Qswitch_frame
},
11761 {&Qdelete_frame
, "delete-frame", &Qdelete_frame
},
11762 {&Qiconify_frame
, "iconify-frame", &Qiconify_frame
},
11763 {&Qmake_frame_visible
, "make-frame-visible", &Qmake_frame_visible
},
11764 /* `select-window' should be handled just like `switch-frame'
11765 in read_key_sequence. */
11766 {&Qselect_window
, "select-window", &Qswitch_frame
}
11770 syms_of_keyboard ()
11772 pending_funcalls
= Qnil
;
11773 staticpro (&pending_funcalls
);
11775 Vlispy_mouse_stem
= make_pure_c_string ("mouse");
11776 staticpro (&Vlispy_mouse_stem
);
11779 QCimage
= intern_c_string (":image");
11780 staticpro (&QCimage
);
11782 staticpro (&Qhelp_echo
);
11783 Qhelp_echo
= intern_c_string ("help-echo");
11786 Qrtl
= intern_c_string (":rtl");
11788 staticpro (&item_properties
);
11789 item_properties
= Qnil
;
11791 staticpro (&tool_bar_item_properties
);
11792 tool_bar_item_properties
= Qnil
;
11793 staticpro (&tool_bar_items_vector
);
11794 tool_bar_items_vector
= Qnil
;
11796 staticpro (&real_this_command
);
11797 real_this_command
= Qnil
;
11799 Qtimer_event_handler
= intern_c_string ("timer-event-handler");
11800 staticpro (&Qtimer_event_handler
);
11802 Qdisabled_command_function
= intern_c_string ("disabled-command-function");
11803 staticpro (&Qdisabled_command_function
);
11805 Qself_insert_command
= intern_c_string ("self-insert-command");
11806 staticpro (&Qself_insert_command
);
11808 Qforward_char
= intern_c_string ("forward-char");
11809 staticpro (&Qforward_char
);
11811 Qbackward_char
= intern_c_string ("backward-char");
11812 staticpro (&Qbackward_char
);
11814 Qdisabled
= intern_c_string ("disabled");
11815 staticpro (&Qdisabled
);
11817 Qundefined
= intern_c_string ("undefined");
11818 staticpro (&Qundefined
);
11820 Qpre_command_hook
= intern_c_string ("pre-command-hook");
11821 staticpro (&Qpre_command_hook
);
11823 Qpost_command_hook
= intern_c_string ("post-command-hook");
11824 staticpro (&Qpost_command_hook
);
11826 Qdeferred_action_function
= intern_c_string ("deferred-action-function");
11827 staticpro (&Qdeferred_action_function
);
11829 Qcommand_hook_internal
= intern_c_string ("command-hook-internal");
11830 staticpro (&Qcommand_hook_internal
);
11832 Qfunction_key
= intern_c_string ("function-key");
11833 staticpro (&Qfunction_key
);
11834 Qmouse_click
= intern_c_string ("mouse-click");
11835 staticpro (&Qmouse_click
);
11836 #if defined (WINDOWSNT)
11837 Qlanguage_change
= intern_c_string ("language-change");
11838 staticpro (&Qlanguage_change
);
11840 Qdrag_n_drop
= intern_c_string ("drag-n-drop");
11841 staticpro (&Qdrag_n_drop
);
11843 Qsave_session
= intern_c_string ("save-session");
11844 staticpro (&Qsave_session
);
11847 Qdbus_event
= intern_c_string ("dbus-event");
11848 staticpro (&Qdbus_event
);
11851 Qconfig_changed_event
= intern_c_string ("config-changed-event");
11852 staticpro (&Qconfig_changed_event
);
11854 Qmenu_enable
= intern_c_string ("menu-enable");
11855 staticpro (&Qmenu_enable
);
11856 QCenable
= intern_c_string (":enable");
11857 staticpro (&QCenable
);
11858 QCvisible
= intern_c_string (":visible");
11859 staticpro (&QCvisible
);
11860 QChelp
= intern_c_string (":help");
11861 staticpro (&QChelp
);
11862 QCfilter
= intern_c_string (":filter");
11863 staticpro (&QCfilter
);
11864 QCbutton
= intern_c_string (":button");
11865 staticpro (&QCbutton
);
11866 QCkeys
= intern_c_string (":keys");
11867 staticpro (&QCkeys
);
11868 QCkey_sequence
= intern_c_string (":key-sequence");
11869 staticpro (&QCkey_sequence
);
11870 QCtoggle
= intern_c_string (":toggle");
11871 staticpro (&QCtoggle
);
11872 QCradio
= intern_c_string (":radio");
11873 staticpro (&QCradio
);
11875 Qmode_line
= intern_c_string ("mode-line");
11876 staticpro (&Qmode_line
);
11877 Qvertical_line
= intern_c_string ("vertical-line");
11878 staticpro (&Qvertical_line
);
11879 Qvertical_scroll_bar
= intern_c_string ("vertical-scroll-bar");
11880 staticpro (&Qvertical_scroll_bar
);
11881 Qmenu_bar
= intern_c_string ("menu-bar");
11882 staticpro (&Qmenu_bar
);
11884 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
11885 Qmouse_fixup_help_message
= intern_c_string ("mouse-fixup-help-message");
11886 staticpro (&Qmouse_fixup_help_message
);
11889 Qabove_handle
= intern_c_string ("above-handle");
11890 staticpro (&Qabove_handle
);
11891 Qhandle
= intern_c_string ("handle");
11892 staticpro (&Qhandle
);
11893 Qbelow_handle
= intern_c_string ("below-handle");
11894 staticpro (&Qbelow_handle
);
11895 Qup
= intern_c_string ("up");
11897 Qdown
= intern_c_string ("down");
11898 staticpro (&Qdown
);
11899 Qtop
= intern_c_string ("top");
11901 Qbottom
= intern_c_string ("bottom");
11902 staticpro (&Qbottom
);
11903 Qend_scroll
= intern_c_string ("end-scroll");
11904 staticpro (&Qend_scroll
);
11905 Qratio
= intern_c_string ("ratio");
11906 staticpro (&Qratio
);
11908 Qevent_kind
= intern_c_string ("event-kind");
11909 staticpro (&Qevent_kind
);
11910 Qevent_symbol_elements
= intern_c_string ("event-symbol-elements");
11911 staticpro (&Qevent_symbol_elements
);
11912 Qevent_symbol_element_mask
= intern_c_string ("event-symbol-element-mask");
11913 staticpro (&Qevent_symbol_element_mask
);
11914 Qmodifier_cache
= intern_c_string ("modifier-cache");
11915 staticpro (&Qmodifier_cache
);
11917 Qrecompute_lucid_menubar
= intern_c_string ("recompute-lucid-menubar");
11918 staticpro (&Qrecompute_lucid_menubar
);
11919 Qactivate_menubar_hook
= intern_c_string ("activate-menubar-hook");
11920 staticpro (&Qactivate_menubar_hook
);
11922 Qpolling_period
= intern_c_string ("polling-period");
11923 staticpro (&Qpolling_period
);
11925 Qinput_method_function
= intern_c_string ("input-method-function");
11926 staticpro (&Qinput_method_function
);
11928 Qinput_method_exit_on_first_char
= intern_c_string ("input-method-exit-on-first-char");
11929 staticpro (&Qinput_method_exit_on_first_char
);
11930 Qinput_method_use_echo_area
= intern_c_string ("input-method-use-echo-area");
11931 staticpro (&Qinput_method_use_echo_area
);
11933 Fset (Qinput_method_exit_on_first_char
, Qnil
);
11934 Fset (Qinput_method_use_echo_area
, Qnil
);
11936 last_point_position_buffer
= Qnil
;
11937 last_point_position_window
= Qnil
;
11940 struct event_head
*p
;
11942 for (p
= head_table
;
11943 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
11946 *p
->var
= intern_c_string (p
->name
);
11947 staticpro (p
->var
);
11948 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
11949 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
11953 button_down_location
= Fmake_vector (make_number (5), Qnil
);
11954 staticpro (&button_down_location
);
11955 mouse_syms
= Fmake_vector (make_number (5), Qnil
);
11956 staticpro (&mouse_syms
);
11957 wheel_syms
= Fmake_vector (make_number (sizeof (lispy_wheel_names
)
11958 / sizeof (lispy_wheel_names
[0])),
11960 staticpro (&wheel_syms
);
11964 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
11966 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
11967 for (i
= 0; i
< len
; i
++)
11968 if (modifier_names
[i
])
11969 XVECTOR (modifier_symbols
)->contents
[i
] = intern_c_string (modifier_names
[i
]);
11970 staticpro (&modifier_symbols
);
11973 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
11974 staticpro (&recent_keys
);
11976 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
11977 staticpro (&this_command_keys
);
11979 raw_keybuf
= Fmake_vector (make_number (30), Qnil
);
11980 staticpro (&raw_keybuf
);
11982 Qextended_command_history
= intern_c_string ("extended-command-history");
11983 Fset (Qextended_command_history
, Qnil
);
11984 staticpro (&Qextended_command_history
);
11986 accent_key_syms
= Qnil
;
11987 staticpro (&accent_key_syms
);
11989 func_key_syms
= Qnil
;
11990 staticpro (&func_key_syms
);
11992 drag_n_drop_syms
= Qnil
;
11993 staticpro (&drag_n_drop_syms
);
11995 unread_switch_frame
= Qnil
;
11996 staticpro (&unread_switch_frame
);
11998 internal_last_event_frame
= Qnil
;
11999 staticpro (&internal_last_event_frame
);
12001 read_key_sequence_cmd
= Qnil
;
12002 staticpro (&read_key_sequence_cmd
);
12004 menu_bar_one_keymap_changed_items
= Qnil
;
12005 staticpro (&menu_bar_one_keymap_changed_items
);
12007 menu_bar_items_vector
= Qnil
;
12008 staticpro (&menu_bar_items_vector
);
12010 help_form_saved_window_configs
= Qnil
;
12011 staticpro (&help_form_saved_window_configs
);
12013 defsubr (&Scurrent_idle_time
);
12014 defsubr (&Sevent_symbol_parse_modifiers
);
12015 defsubr (&Sevent_convert_list
);
12016 defsubr (&Sread_key_sequence
);
12017 defsubr (&Sread_key_sequence_vector
);
12018 defsubr (&Srecursive_edit
);
12019 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
12020 defsubr (&Strack_mouse
);
12022 defsubr (&Sinput_pending_p
);
12023 defsubr (&Scommand_execute
);
12024 defsubr (&Srecent_keys
);
12025 defsubr (&Sthis_command_keys
);
12026 defsubr (&Sthis_command_keys_vector
);
12027 defsubr (&Sthis_single_command_keys
);
12028 defsubr (&Sthis_single_command_raw_keys
);
12029 defsubr (&Sreset_this_command_lengths
);
12030 defsubr (&Sclear_this_command_keys
);
12031 defsubr (&Ssuspend_emacs
);
12032 defsubr (&Sabort_recursive_edit
);
12033 defsubr (&Sexit_recursive_edit
);
12034 defsubr (&Srecursion_depth
);
12035 defsubr (&Stop_level
);
12036 defsubr (&Sdiscard_input
);
12037 defsubr (&Sopen_dribble_file
);
12038 defsubr (&Sset_input_interrupt_mode
);
12039 defsubr (&Sset_output_flow_control
);
12040 defsubr (&Sset_input_meta_mode
);
12041 defsubr (&Sset_quit_char
);
12042 defsubr (&Sset_input_mode
);
12043 defsubr (&Scurrent_input_mode
);
12044 defsubr (&Sexecute_extended_command
);
12045 defsubr (&Sposn_at_point
);
12046 defsubr (&Sposn_at_x_y
);
12048 DEFVAR_LISP ("last-command-event", &last_command_event
,
12049 doc
: /* Last input event that was part of a command. */);
12051 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
12052 doc
: /* Last input event in a command, except for mouse menu events.
12053 Mouse menus give back keys that don't look like mouse events;
12054 this variable holds the actual mouse event that led to the menu,
12055 so that you can determine whether the command was run by mouse or not. */);
12057 DEFVAR_LISP ("last-input-event", &last_input_event
,
12058 doc
: /* Last input event. */);
12060 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
12061 doc
: /* List of events to be read as the command input.
12062 These events are processed first, before actual keyboard input.
12063 Events read from this list are not normally added to `this-command-keys',
12064 as they will already have been added once as they were read for the first time.
12065 An element of the form (t . EVENT) forces EVENT to be added to that list. */);
12066 Vunread_command_events
= Qnil
;
12068 DEFVAR_INT ("unread-command-char", &unread_command_char
,
12069 doc
: /* If not -1, an object to be read as next command input event. */);
12071 DEFVAR_LISP ("unread-post-input-method-events", &Vunread_post_input_method_events
,
12072 doc
: /* List of events to be processed as input by input methods.
12073 These events are processed before `unread-command-events'
12074 and actual keyboard input, but are not given to `input-method-function'. */);
12075 Vunread_post_input_method_events
= Qnil
;
12077 DEFVAR_LISP ("unread-input-method-events", &Vunread_input_method_events
,
12078 doc
: /* List of events to be processed as input by input methods.
12079 These events are processed after `unread-command-events', but
12080 before actual keyboard input.
12081 If there's an active input method, the events are given to
12082 `input-method-function'. */);
12083 Vunread_input_method_events
= Qnil
;
12085 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
12086 doc
: /* Meta-prefix character code.
12087 Meta-foo as command input turns into this character followed by foo. */);
12088 XSETINT (meta_prefix_char
, 033);
12090 DEFVAR_KBOARD ("last-command", Vlast_command
,
12091 doc
: /* The last command executed.
12092 Normally a symbol with a function definition, but can be whatever was found
12093 in the keymap, or whatever the variable `this-command' was set to by that
12096 The value `mode-exit' is special; it means that the previous command
12097 read an event that told it to exit, and it did so and unread that event.
12098 In other words, the present command is the event that made the previous
12101 The value `kill-region' is special; it means that the previous command
12102 was a kill command.
12104 `last-command' has a separate binding for each terminal device.
12105 See Info node `(elisp)Multiple Terminals'. */);
12107 DEFVAR_KBOARD ("real-last-command", Vreal_last_command
,
12108 doc
: /* Same as `last-command', but never altered by Lisp code. */);
12110 DEFVAR_KBOARD ("last-repeatable-command", Vlast_repeatable_command
,
12111 doc
: /* Last command that may be repeated.
12112 The last command executed that was not bound to an input event.
12113 This is the command `repeat' will try to repeat. */);
12115 DEFVAR_LISP ("this-command", &Vthis_command
,
12116 doc
: /* The command now being executed.
12117 The command can set this variable; whatever is put here
12118 will be in `last-command' during the following command. */);
12119 Vthis_command
= Qnil
;
12121 DEFVAR_LISP ("this-command-keys-shift-translated",
12122 &Vthis_command_keys_shift_translated
,
12123 doc
: /* Non-nil if the key sequence activating this command was shift-translated.
12124 Shift-translation occurs when there is no binding for the key sequence
12125 as entered, but a binding was found by changing an upper-case letter
12126 to lower-case, or a shifted function key to an unshifted one. */);
12127 Vthis_command_keys_shift_translated
= Qnil
;
12129 DEFVAR_LISP ("this-original-command", &Vthis_original_command
,
12130 doc
: /* The command bound to the current key sequence before remapping.
12131 It equals `this-command' if the original command was not remapped through
12132 any of the active keymaps. Otherwise, the value of `this-command' is the
12133 result of looking up the original command in the active keymaps. */);
12134 Vthis_original_command
= Qnil
;
12136 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
12137 doc
: /* *Number of input events between auto-saves.
12138 Zero means disable autosaving due to number of characters typed. */);
12139 auto_save_interval
= 300;
12141 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
12142 doc
: /* *Number of seconds idle time before auto-save.
12143 Zero or nil means disable auto-saving due to idleness.
12144 After auto-saving due to this many seconds of idle time,
12145 Emacs also does a garbage collection if that seems to be warranted. */);
12146 XSETFASTINT (Vauto_save_timeout
, 30);
12148 DEFVAR_LISP ("echo-keystrokes", &Vecho_keystrokes
,
12149 doc
: /* *Nonzero means echo unfinished commands after this many seconds of pause.
12150 The value may be integer or floating point. */);
12151 Vecho_keystrokes
= make_number (1);
12153 DEFVAR_INT ("polling-period", &polling_period
,
12154 doc
: /* *Interval between polling for input during Lisp execution.
12155 The reason for polling is to make C-g work to stop a running program.
12156 Polling is needed only when using X windows and SIGIO does not work.
12157 Polling is automatically disabled in all other cases. */);
12158 polling_period
= 2;
12160 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
12161 doc
: /* *Maximum time between mouse clicks to make a double-click.
12162 Measured in milliseconds. The value nil means disable double-click
12163 recognition; t means double-clicks have no time limit and are detected
12164 by position only. */);
12165 Vdouble_click_time
= make_number (500);
12167 DEFVAR_INT ("double-click-fuzz", &double_click_fuzz
,
12168 doc
: /* *Maximum mouse movement between clicks to make a double-click.
12169 On window-system frames, value is the number of pixels the mouse may have
12170 moved horizontally or vertically between two clicks to make a double-click.
12171 On non window-system frames, value is interpreted in units of 1/8 characters
12174 This variable is also the threshold for motion of the mouse
12175 to count as a drag. */);
12176 double_click_fuzz
= 3;
12178 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
12179 doc
: /* *Non-nil means inhibit local map menu bar menus. */);
12180 inhibit_local_menu_bar_menus
= 0;
12182 DEFVAR_INT ("num-input-keys", &num_input_keys
,
12183 doc
: /* Number of complete key sequences read as input so far.
12184 This includes key sequences read from keyboard macros.
12185 The number is effectively the number of interactive command invocations. */);
12186 num_input_keys
= 0;
12188 DEFVAR_INT ("num-nonmacro-input-events", &num_nonmacro_input_events
,
12189 doc
: /* Number of input events read from the keyboard so far.
12190 This does not include events generated by keyboard macros. */);
12191 num_nonmacro_input_events
= 0;
12193 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
12194 doc
: /* The frame in which the most recently read event occurred.
12195 If the last event came from a keyboard macro, this is set to `macro'. */);
12196 Vlast_event_frame
= Qnil
;
12198 /* This variable is set up in sysdep.c. */
12199 DEFVAR_LISP ("tty-erase-char", &Vtty_erase_char
,
12200 doc
: /* The ERASE character as set by the user with stty. */);
12202 DEFVAR_LISP ("help-char", &Vhelp_char
,
12203 doc
: /* Character to recognize as meaning Help.
12204 When it is read, do `(eval help-form)', and display result if it's a string.
12205 If the value of `help-form' is nil, this char can be read normally. */);
12206 XSETINT (Vhelp_char
, Ctl ('H'));
12208 DEFVAR_LISP ("help-event-list", &Vhelp_event_list
,
12209 doc
: /* List of input events to recognize as meaning Help.
12210 These work just like the value of `help-char' (see that). */);
12211 Vhelp_event_list
= Qnil
;
12213 DEFVAR_LISP ("help-form", &Vhelp_form
,
12214 doc
: /* Form to execute when character `help-char' is read.
12215 If the form returns a string, that string is displayed.
12216 If `help-form' is nil, the help char is not recognized. */);
12219 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
12220 doc
: /* Command to run when `help-char' character follows a prefix key.
12221 This command is used only when there is no actual binding
12222 for that character after that prefix key. */);
12223 Vprefix_help_command
= Qnil
;
12225 DEFVAR_LISP ("top-level", &Vtop_level
,
12226 doc
: /* Form to evaluate when Emacs starts up.
12227 Useful to set before you dump a modified Emacs. */);
12230 DEFVAR_KBOARD ("keyboard-translate-table", Vkeyboard_translate_table
,
12231 doc
: /* Translate table for local keyboard input, or nil.
12232 If non-nil, the value should be a char-table. Each character read
12233 from the keyboard is looked up in this char-table. If the value found
12234 there is non-nil, then it is used instead of the actual input character.
12236 The value can also be a string or vector, but this is considered obsolete.
12237 If it is a string or vector of length N, character codes N and up are left
12238 untranslated. In a vector, an element which is nil means "no translation".
12240 This is applied to the characters supplied to input methods, not their
12241 output. See also `translation-table-for-input'.
12243 This variable has a separate binding for each terminal.
12244 See Info node `(elisp)Multiple Terminals'. */);
12246 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
12247 doc
: /* Non-nil means to always spawn a subshell instead of suspending.
12248 \(Even if the operating system has support for stopping a process.\) */);
12249 cannot_suspend
= 0;
12251 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
12252 doc
: /* Non-nil means prompt with menus when appropriate.
12253 This is done when reading from a keymap that has a prompt string,
12254 for elements that have prompt strings.
12255 The menu is displayed on the screen
12256 if X menus were enabled at configuration
12257 time and the previous event was a mouse click prefix key.
12258 Otherwise, menu prompting uses the echo area. */);
12259 menu_prompting
= 1;
12261 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
12262 doc
: /* Character to see next line of menu prompt.
12263 Type this character while in a menu prompt to rotate around the lines of it. */);
12264 XSETINT (menu_prompt_more_char
, ' ');
12266 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
12267 doc
: /* A mask of additional modifier keys to use with every keyboard character.
12268 Emacs applies the modifiers of the character stored here to each keyboard
12269 character it reads. For example, after evaluating the expression
12270 (setq extra-keyboard-modifiers ?\\C-x)
12271 all input characters will have the control modifier applied to them.
12273 Note that the character ?\\C-@, equivalent to the integer zero, does
12274 not count as a control character; rather, it counts as a character
12275 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero
12276 cancels any modification. */);
12277 extra_keyboard_modifiers
= 0;
12279 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
12280 doc
: /* If an editing command sets this to t, deactivate the mark afterward.
12281 The command loop sets this to nil before each command,
12282 and tests the value when the command returns.
12283 Buffer modification stores t in this variable. */);
12284 Vdeactivate_mark
= Qnil
;
12285 Qdeactivate_mark
= intern_c_string ("deactivate-mark");
12286 staticpro (&Qdeactivate_mark
);
12288 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
12289 doc
: /* Temporary storage of `pre-command-hook' or `post-command-hook'. */);
12290 Vcommand_hook_internal
= Qnil
;
12292 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
12293 doc
: /* Normal hook run before each command is executed.
12294 If an unhandled error happens in running this hook,
12295 the hook value is set to nil, since otherwise the error
12296 might happen repeatedly and make Emacs nonfunctional. */);
12297 Vpre_command_hook
= Qnil
;
12299 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
12300 doc
: /* Normal hook run after each command is executed.
12301 If an unhandled error happens in running this hook,
12302 the hook value is set to nil, since otherwise the error
12303 might happen repeatedly and make Emacs nonfunctional. */);
12304 Vpost_command_hook
= Qnil
;
12307 DEFVAR_LISP ("echo-area-clear-hook", ...,
12308 doc
: /* Normal hook run when clearing the echo area. */);
12310 Qecho_area_clear_hook
= intern_c_string ("echo-area-clear-hook");
12311 staticpro (&Qecho_area_clear_hook
);
12312 Fset (Qecho_area_clear_hook
, Qnil
);
12314 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
12315 doc
: /* Non-nil means menu bar, specified Lucid style, needs to be recomputed. */);
12316 Vlucid_menu_bar_dirty_flag
= Qnil
;
12318 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
12319 doc
: /* List of menu bar items to move to the end of the menu bar.
12320 The elements of the list are event types that may have menu bar bindings. */);
12321 Vmenu_bar_final_items
= Qnil
;
12323 DEFVAR_KBOARD ("overriding-terminal-local-map",
12324 Voverriding_terminal_local_map
,
12325 doc
: /* Per-terminal keymap that overrides all other local keymaps.
12326 If this variable is non-nil, it is used as a keymap instead of the
12327 buffer's local map, and the minor mode keymaps and text property keymaps.
12328 It also replaces `overriding-local-map'.
12330 This variable is intended to let commands such as `universal-argument'
12331 set up a different keymap for reading the next command.
12333 `overriding-terminal-local-map' has a separate binding for each
12335 See Info node `(elisp)Multiple Terminals'. */);
12337 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
12338 doc
: /* Keymap that overrides all other local keymaps.
12339 If this variable is non-nil, it is used as a keymap--replacing the
12340 buffer's local map, the minor mode keymaps, and char property keymaps. */);
12341 Voverriding_local_map
= Qnil
;
12343 DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag
,
12344 doc
: /* Non-nil means `overriding-local-map' applies to the menu bar.
12345 Otherwise, the menu bar continues to reflect the buffer's local map
12346 and the minor mode maps regardless of `overriding-local-map'. */);
12347 Voverriding_local_map_menu_flag
= Qnil
;
12349 DEFVAR_LISP ("special-event-map", &Vspecial_event_map
,
12350 doc
: /* Keymap defining bindings for special events to execute at low level. */);
12351 Vspecial_event_map
= Fcons (intern_c_string ("keymap"), Qnil
);
12353 DEFVAR_LISP ("track-mouse", &do_mouse_tracking
,
12354 doc
: /* *Non-nil means generate motion events for mouse motion. */);
12356 DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist
,
12357 doc
: /* Alist of system-specific X windows key symbols.
12358 Each element should have the form (N . SYMBOL) where N is the
12359 numeric keysym code (sans the \"system-specific\" bit 1<<28)
12360 and SYMBOL is its name.
12362 `system-key-alist' has a separate binding for each terminal device.
12363 See Info node `(elisp)Multiple Terminals'. */);
12365 DEFVAR_KBOARD ("local-function-key-map", Vlocal_function_key_map
,
12366 doc
: /* Keymap that translates key sequences to key sequences during input.
12367 This is used mainly for mapping key sequences into some preferred
12368 key events (symbols).
12370 The `read-key-sequence' function replaces any subsequence bound by
12371 `local-function-key-map' with its binding. More precisely, when the
12372 active keymaps have no binding for the current key sequence but
12373 `local-function-key-map' binds a suffix of the sequence to a vector or
12374 string, `read-key-sequence' replaces the matching suffix with its
12375 binding, and continues with the new sequence.
12377 If the binding is a function, it is called with one argument (the prompt)
12378 and its return value (a key sequence) is used.
12380 The events that come from bindings in `local-function-key-map' are not
12381 themselves looked up in `local-function-key-map'.
12383 For example, suppose `local-function-key-map' binds `ESC O P' to [f1].
12384 Typing `ESC O P' to `read-key-sequence' would return [f1]. Typing
12385 `C-x ESC O P' would return [?\\C-x f1]. If [f1] were a prefix key,
12386 typing `ESC O P x' would return [f1 x].
12388 `local-function-key-map' has a separate binding for each terminal
12389 device. See Info node `(elisp)Multiple Terminals'. If you need to
12390 define a binding on all terminals, change `function-key-map'
12391 instead. Initially, `local-function-key-map' is an empty keymap that
12392 has `function-key-map' as its parent on all terminal devices. */);
12394 DEFVAR_KBOARD ("input-decode-map", Vinput_decode_map
,
12395 doc
: /* Keymap that decodes input escape sequences.
12396 This is used mainly for mapping ASCII function key sequences into
12397 real Emacs function key events (symbols).
12399 The `read-key-sequence' function replaces any subsequence bound by
12400 `input-decode-map' with its binding. Contrary to `function-key-map',
12401 this map applies its rebinding regardless of the presence of an ordinary
12402 binding. So it is more like `key-translation-map' except that it applies
12403 before `function-key-map' rather than after.
12405 If the binding is a function, it is called with one argument (the prompt)
12406 and its return value (a key sequence) is used.
12408 The events that come from bindings in `input-decode-map' are not
12409 themselves looked up in `input-decode-map'.
12411 This variable is keyboard-local. */);
12413 DEFVAR_LISP ("function-key-map", &Vfunction_key_map
,
12414 doc
: /* The parent keymap of all `local-function-key-map' instances.
12415 Function key definitions that apply to all terminal devices should go
12416 here. If a mapping is defined in both the current
12417 `local-function-key-map' binding and this variable, then the local
12418 definition will take precendence. */);
12419 Vfunction_key_map
= Fmake_sparse_keymap (Qnil
);
12421 DEFVAR_LISP ("key-translation-map", &Vkey_translation_map
,
12422 doc
: /* Keymap of key translations that can override keymaps.
12423 This keymap works like `function-key-map', but comes after that,
12424 and its non-prefix bindings override ordinary bindings.
12425 Another difference is that it is global rather than keyboard-local. */);
12426 Vkey_translation_map
= Fmake_sparse_keymap (Qnil
);
12428 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
12429 doc
: /* List of deferred actions to be performed at a later time.
12430 The precise format isn't relevant here; we just check whether it is nil. */);
12431 Vdeferred_action_list
= Qnil
;
12433 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
12434 doc
: /* Function to call to handle deferred actions, after each command.
12435 This function is called with no arguments after each command
12436 whenever `deferred-action-list' is non-nil. */);
12437 Vdeferred_action_function
= Qnil
;
12439 DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings
,
12440 doc
: /* *Non-nil means show the equivalent key-binding when M-x command has one.
12441 The value can be a length of time to show the message for.
12442 If the value is non-nil and not a number, we wait 2 seconds. */);
12443 Vsuggest_key_bindings
= Qt
;
12445 DEFVAR_LISP ("timer-list", &Vtimer_list
,
12446 doc
: /* List of active absolute time timers in order of increasing time. */);
12447 Vtimer_list
= Qnil
;
12449 DEFVAR_LISP ("timer-idle-list", &Vtimer_idle_list
,
12450 doc
: /* List of active idle-time timers in order of increasing time. */);
12451 Vtimer_idle_list
= Qnil
;
12453 DEFVAR_LISP ("input-method-function", &Vinput_method_function
,
12454 doc
: /* If non-nil, the function that implements the current input method.
12455 It's called with one argument, a printing character that was just read.
12456 \(That means a character with code 040...0176.)
12457 Typically this function uses `read-event' to read additional events.
12458 When it does so, it should first bind `input-method-function' to nil
12459 so it will not be called recursively.
12461 The function should return a list of zero or more events
12462 to be used as input. If it wants to put back some events
12463 to be reconsidered, separately, by the input method,
12464 it can add them to the beginning of `unread-command-events'.
12466 The input method function can find in `input-method-previous-message'
12467 the previous echo area message.
12469 The input method function should refer to the variables
12470 `input-method-use-echo-area' and `input-method-exit-on-first-char'
12471 for guidance on what to do. */);
12472 Vinput_method_function
= Qnil
;
12474 DEFVAR_LISP ("input-method-previous-message",
12475 &Vinput_method_previous_message
,
12476 doc
: /* When `input-method-function' is called, hold the previous echo area message.
12477 This variable exists because `read-event' clears the echo area
12478 before running the input method. It is nil if there was no message. */);
12479 Vinput_method_previous_message
= Qnil
;
12481 DEFVAR_LISP ("show-help-function", &Vshow_help_function
,
12482 doc
: /* If non-nil, the function that implements the display of help.
12483 It's called with one argument, the help string to display. */);
12484 Vshow_help_function
= Qnil
;
12486 DEFVAR_LISP ("disable-point-adjustment", &Vdisable_point_adjustment
,
12487 doc
: /* If non-nil, suppress point adjustment after executing a command.
12489 After a command is executed, if point is moved into a region that has
12490 special properties (e.g. composition, display), we adjust point to
12491 the boundary of the region. But, when a command sets this variable to
12492 non-nil, we suppress the point adjustment.
12494 This variable is set to nil before reading a command, and is checked
12495 just after executing the command. */);
12496 Vdisable_point_adjustment
= Qnil
;
12498 DEFVAR_LISP ("global-disable-point-adjustment",
12499 &Vglobal_disable_point_adjustment
,
12500 doc
: /* *If non-nil, always suppress point adjustment.
12502 The default value is nil, in which case, point adjustment are
12503 suppressed only after special commands that set
12504 `disable-point-adjustment' (which see) to non-nil. */);
12505 Vglobal_disable_point_adjustment
= Qnil
;
12507 DEFVAR_LISP ("minibuffer-message-timeout", &Vminibuffer_message_timeout
,
12508 doc
: /* *How long to display an echo-area message when the minibuffer is active.
12509 If the value is not a number, such messages don't time out. */);
12510 Vminibuffer_message_timeout
= make_number (2);
12512 DEFVAR_LISP ("throw-on-input", &Vthrow_on_input
,
12513 doc
: /* If non-nil, any keyboard input throws to this symbol.
12514 The value of that variable is passed to `quit-flag' and later causes a
12515 peculiar kind of quitting. */);
12516 Vthrow_on_input
= Qnil
;
12518 DEFVAR_LISP ("command-error-function", &Vcommand_error_function
,
12519 doc
: /* If non-nil, function to output error messages.
12520 The arguments are the error data, a list of the form
12521 (SIGNALED-CONDITIONS . SIGNAL-DATA)
12522 such as just as `condition-case' would bind its variable to,
12523 the context (a string which normally goes at the start of the message),
12524 and the Lisp function within which the error was signaled. */);
12525 Vcommand_error_function
= Qnil
;
12527 DEFVAR_LISP ("enable-disabled-menus-and-buttons",
12528 &Venable_disabled_menus_and_buttons
,
12529 doc
: /* If non-nil, don't ignore events produced by disabled menu items and tool-bar.
12531 Help functions bind this to allow help on disabled menu items
12532 and tool-bar buttons. */);
12533 Venable_disabled_menus_and_buttons
= Qnil
;
12535 /* Create the initial keyboard. */
12536 initial_kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
12537 init_kboard (initial_kboard
);
12538 /* Vwindow_system is left at t for now. */
12539 initial_kboard
->next_kboard
= all_kboards
;
12540 all_kboards
= initial_kboard
;
12544 keys_of_keyboard ()
12546 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
12547 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
12548 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
12549 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
12550 initial_define_key (meta_map
, 'x', "execute-extended-command");
12552 initial_define_lispy_key (Vspecial_event_map
, "delete-frame",
12553 "handle-delete-frame");
12554 initial_define_lispy_key (Vspecial_event_map
, "ns-put-working-text",
12555 "ns-put-working-text");
12556 initial_define_lispy_key (Vspecial_event_map
, "ns-unput-working-text",
12557 "ns-unput-working-text");
12558 /* Here we used to use `ignore-event' which would simple set prefix-arg to
12559 current-prefix-arg, as is done in `handle-switch-frame'.
12560 But `handle-switch-frame is not run from the special-map.
12561 Commands from that map are run in a special way that automatically
12562 preserves the prefix-arg. Restoring the prefix arg here is not just
12563 redundant but harmful:
12565 - current-prefix-arg is set to non-nil, prefix-arg is set to nil.
12566 - after the first prompt, the exit-minibuffer-hook is run which may
12567 iconify a frame and thus push a `iconify-frame' event.
12568 - after running exit-minibuffer-hook, current-prefix-arg is
12569 restored to the non-nil value it had before the prompt.
12570 - we enter the second prompt.
12571 current-prefix-arg is non-nil, prefix-arg is nil.
12572 - before running the first real event, we run the special iconify-frame
12573 event, but we pass the `special' arg to execute-command so
12574 current-prefix-arg and prefix-arg are left untouched.
12575 - here we foolishly copy the non-nil current-prefix-arg to prefix-arg.
12576 - the next key event will have a spuriously non-nil current-prefix-arg. */
12577 initial_define_lispy_key (Vspecial_event_map
, "iconify-frame",
12579 initial_define_lispy_key (Vspecial_event_map
, "make-frame-visible",
12581 /* Handling it at such a low-level causes read_key_sequence to get
12582 * confused because it doesn't realize that the current_buffer was
12583 * changed by read_char.
12585 * initial_define_lispy_key (Vspecial_event_map, "select-window",
12586 * "handle-select-window"); */
12587 initial_define_lispy_key (Vspecial_event_map
, "save-session",
12588 "handle-save-session");
12591 /* Define a special event which is raised for dbus callback
12593 initial_define_lispy_key (Vspecial_event_map
, "dbus-event",
12594 "dbus-handle-event");
12597 initial_define_lispy_key (Vspecial_event_map
, "config-changed-event",
12601 /* Mark the pointers in the kboard objects.
12602 Called by the Fgarbage_collector. */
12608 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
12610 if (kb
->kbd_macro_buffer
)
12611 for (p
= kb
->kbd_macro_buffer
; p
< kb
->kbd_macro_ptr
; p
++)
12613 mark_object (kb
->Voverriding_terminal_local_map
);
12614 mark_object (kb
->Vlast_command
);
12615 mark_object (kb
->Vreal_last_command
);
12616 mark_object (kb
->Vkeyboard_translate_table
);
12617 mark_object (kb
->Vlast_repeatable_command
);
12618 mark_object (kb
->Vprefix_arg
);
12619 mark_object (kb
->Vlast_prefix_arg
);
12620 mark_object (kb
->kbd_queue
);
12621 mark_object (kb
->defining_kbd_macro
);
12622 mark_object (kb
->Vlast_kbd_macro
);
12623 mark_object (kb
->Vsystem_key_alist
);
12624 mark_object (kb
->system_key_syms
);
12625 mark_object (kb
->Vwindow_system
);
12626 mark_object (kb
->Vinput_decode_map
);
12627 mark_object (kb
->Vlocal_function_key_map
);
12628 mark_object (kb
->Vdefault_minibuffer_frame
);
12629 mark_object (kb
->echo_string
);
12632 struct input_event
*event
;
12633 for (event
= kbd_fetch_ptr
; event
!= kbd_store_ptr
; event
++)
12635 if (event
== kbd_buffer
+ KBD_BUFFER_SIZE
)
12636 event
= kbd_buffer
;
12637 if (event
->kind
!= SELECTION_REQUEST_EVENT
12638 && event
->kind
!= SELECTION_CLEAR_EVENT
)
12640 mark_object (event
->x
);
12641 mark_object (event
->y
);
12643 mark_object (event
->frame_or_window
);
12644 mark_object (event
->arg
);
12649 /* arch-tag: 774e34d7-6d31-42f3-8397-e079a4e4c9ca
12650 (do not change this comment) */