1 /* Keyboard and mouse input; editor command loop.
2 Copyright (C) 1985,86,87,88,89,93,94,95,96,97 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Allow config.h to undefine symbols found here. */
29 #include "termhooks.h"
37 #include "dispextern.h"
40 #include "intervals.h"
41 #include "blockinput.h"
51 #include <sys/ioctl.h>
53 #endif /* not MSDOS */
55 #include "syssignal.h"
58 /* This is to get the definitions of the XK_ symbols. */
65 #endif /* HAVE_NTGUI */
67 /* Include systime.h after xterm.h to avoid double inclusion of time.h. */
72 /* Variables for blockinput.h: */
74 /* Non-zero if interrupt input is blocked right now. */
75 int interrupt_input_blocked
;
77 /* Nonzero means an input interrupt has arrived
78 during the current critical section. */
79 int interrupt_input_pending
;
82 /* File descriptor to use for input. */
85 #ifdef HAVE_WINDOW_SYSTEM
86 /* Make all keyboard buffers much bigger when using X windows. */
87 #define KBD_BUFFER_SIZE 4096
88 #else /* No X-windows, character input */
89 #define KBD_BUFFER_SIZE 256
90 #endif /* No X-windows */
92 /* Following definition copied from eval.c */
96 struct backtrace
*next
;
97 Lisp_Object
*function
;
98 Lisp_Object
*args
; /* Points to vector of args. */
99 int nargs
; /* length of vector. If nargs is UNEVALLED,
100 args points to slot holding list of
106 KBOARD
*initial_kboard
;
107 KBOARD
*current_kboard
;
111 KBOARD the_only_kboard
;
114 /* Non-nil disable property on a command means
115 do not execute it; call disabled-command-hook's value instead. */
116 Lisp_Object Qdisabled
, Qdisabled_command_hook
;
118 #define NUM_RECENT_KEYS (100)
119 int recent_keys_index
; /* Index for storing next element into recent_keys */
120 int total_keys
; /* Total number of elements stored into recent_keys */
121 Lisp_Object recent_keys
; /* A vector, holding the last 100 keystrokes */
123 /* Vector holding the key sequence that invoked the current command.
124 It is reused for each command, and it may be longer than the current
125 sequence; this_command_key_count indicates how many elements
126 actually mean something.
127 It's easier to staticpro a single Lisp_Object than an array. */
128 Lisp_Object this_command_keys
;
129 int this_command_key_count
;
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 #define GROW_RAW_KEYBUF \
137 if (raw_keybuf_count == XVECTOR (raw_keybuf)->size) \
139 int newsize = 2 * XVECTOR (raw_keybuf)->size; \
141 new = Fmake_vector (make_number (newsize), Qnil); \
142 bcopy (XVECTOR (raw_keybuf)->contents, XVECTOR (new)->contents, \
143 raw_keybuf_count * sizeof (Lisp_Object)); \
147 /* Number of elements of this_command_keys
148 that precede this key sequence. */
149 int this_single_command_key_start
;
151 /* Record values of this_command_key_count and echo_length ()
152 before this command was read. */
153 static int before_command_key_count
;
154 static int before_command_echo_length
;
155 /* Values of before_command_key_count and before_command_echo_length
156 saved by reset-this-command-lengths. */
157 static int before_command_key_count_1
;
158 static int before_command_echo_length_1
;
159 /* Flag set by reset-this-command-lengths,
160 saying to reset the lengths when add_command_key is called. */
161 static int before_command_restore_flag
;
163 extern int minbuf_level
;
165 extern int message_enable_multibyte
;
167 extern struct backtrace
*backtrace_list
;
169 /* If non-nil, the function that implements the display of help.
170 It's called with one argument, the help string to display. */
172 Lisp_Object Vshow_help_function
;
174 /* Nonzero means do menu prompting. */
175 static int menu_prompting
;
177 /* Character to see next line of menu prompt. */
178 static Lisp_Object menu_prompt_more_char
;
180 /* For longjmp to where kbd input is being done. */
181 static jmp_buf getcjmp
;
183 /* True while doing kbd input. */
184 int waiting_for_input
;
186 /* True while displaying for echoing. Delays C-g throwing. */
189 /* True means we can start echoing at the next input pause
190 even though there is something in the echo area. */
191 static char *ok_to_echo_at_next_pause
;
193 /* Nonzero means disregard local maps for the menu bar. */
194 static int inhibit_local_menu_bar_menus
;
196 /* Nonzero means C-g should cause immediate error-signal. */
199 /* The user's ERASE setting. */
200 Lisp_Object Vtty_erase_char
;
202 /* Character to recognize as the help char. */
203 Lisp_Object Vhelp_char
;
205 /* List of other event types to recognize as meaning "help". */
206 Lisp_Object Vhelp_event_list
;
208 /* Form to execute when help char is typed. */
209 Lisp_Object Vhelp_form
;
211 /* Command to run when the help character follows a prefix key. */
212 Lisp_Object Vprefix_help_command
;
214 /* List of items that should move to the end of the menu bar. */
215 Lisp_Object Vmenu_bar_final_items
;
217 /* Non-nil means show the equivalent key-binding for
218 any M-x command that has one.
219 The value can be a length of time to show the message for.
220 If the value is non-nil and not a number, we wait 2 seconds. */
221 Lisp_Object Vsuggest_key_bindings
;
223 /* Character that causes a quit. Normally C-g.
225 If we are running on an ordinary terminal, this must be an ordinary
226 ASCII char, since we want to make it our interrupt character.
228 If we are not running on an ordinary terminal, it still needs to be
229 an ordinary ASCII char. This character needs to be recognized in
230 the input interrupt handler. At this point, the keystroke is
231 represented as a struct input_event, while the desired quit
232 character is specified as a lispy event. The mapping from struct
233 input_events to lispy events cannot run in an interrupt handler,
234 and the reverse mapping is difficult for anything but ASCII
237 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
241 extern Lisp_Object current_global_map
;
242 extern int minibuf_level
;
244 /* If non-nil, this is a map that overrides all other local maps. */
245 Lisp_Object Voverriding_local_map
;
247 /* If non-nil, Voverriding_local_map applies to the menu bar. */
248 Lisp_Object Voverriding_local_map_menu_flag
;
250 /* Keymap that defines special misc events that should
251 be processed immediately at a low level. */
252 Lisp_Object Vspecial_event_map
;
254 /* Current depth in recursive edits. */
255 int command_loop_level
;
257 /* Total number of times command_loop has read a key sequence. */
260 /* Last input character read as a command. */
261 Lisp_Object last_command_char
;
263 /* Last input character read as a command, not counting menus
264 reached by the mouse. */
265 Lisp_Object last_nonmenu_event
;
267 /* Last input character read for any purpose. */
268 Lisp_Object last_input_char
;
270 /* If not Qnil, a list of objects to be read as subsequent command input. */
271 Lisp_Object Vunread_command_events
;
273 /* If not Qnil, a list of objects to be read as subsequent command input
274 including input method processing. */
275 Lisp_Object Vunread_input_method_events
;
277 /* If not Qnil, a list of objects to be read as subsequent command input
278 but NOT including input method processing. */
279 Lisp_Object Vunread_post_input_method_events
;
281 /* If not -1, an event to be read as subsequent command input. */
282 int unread_command_char
;
284 /* If not Qnil, this is a switch-frame event which we decided to put
285 off until the end of a key sequence. This should be read as the
286 next command input, after any unread_command_events.
288 read_key_sequence uses this to delay switch-frame events until the
289 end of the key sequence; Fread_char uses it to put off switch-frame
290 events until a non-ASCII event is acceptable as input. */
291 Lisp_Object unread_switch_frame
;
293 /* A mask of extra modifier bits to put into every keyboard char. */
294 int extra_keyboard_modifiers
;
296 /* Char to use as prefix when a meta character is typed in.
297 This is bound on entry to minibuffer in case ESC is changed there. */
299 Lisp_Object meta_prefix_char
;
301 /* Last size recorded for a current buffer which is not a minibuffer. */
302 static int last_non_minibuf_size
;
304 /* Number of idle seconds before an auto-save and garbage collection. */
305 static Lisp_Object Vauto_save_timeout
;
307 /* Total number of times read_char has returned. */
308 int num_input_events
;
310 /* Total number of times read_char has returned, outside of macros. */
311 int num_nonmacro_input_events
;
313 /* Auto-save automatically when this many characters have been typed
314 since the last time. */
316 static int auto_save_interval
;
318 /* Value of num_nonmacro_input_events as of last auto save. */
322 /* The command being executed by the command loop.
323 Commands may set this, and the value set will be copied into
324 current_kboard->Vlast_command instead of the actual command. */
325 Lisp_Object Vthis_command
;
327 /* This is like Vthis_command, except that commands never set it. */
328 Lisp_Object real_this_command
;
330 /* The value of point when the last command was executed. */
331 int last_point_position
;
333 /* The buffer that was current when the last command was started. */
334 Lisp_Object last_point_position_buffer
;
336 /* The frame in which the last input event occurred, or Qmacro if the
337 last event came from a macro. We use this to determine when to
338 generate switch-frame events. This may be cleared by functions
339 like Fselect_frame, to make sure that a switch-frame event is
340 generated by the next character. */
341 Lisp_Object internal_last_event_frame
;
343 /* A user-visible version of the above, intended to allow users to
344 figure out where the last event came from, if the event doesn't
345 carry that information itself (i.e. if it was a character). */
346 Lisp_Object Vlast_event_frame
;
348 /* The timestamp of the last input event we received from the X server.
349 X Windows wants this for selection ownership. */
350 unsigned long last_event_timestamp
;
352 Lisp_Object Qself_insert_command
;
353 Lisp_Object Qforward_char
;
354 Lisp_Object Qbackward_char
;
355 Lisp_Object Qundefined
;
356 Lisp_Object Qtimer_event_handler
;
358 /* read_key_sequence stores here the command definition of the
359 key sequence that it reads. */
360 Lisp_Object read_key_sequence_cmd
;
362 /* Form to evaluate (if non-nil) when Emacs is started. */
363 Lisp_Object Vtop_level
;
365 /* User-supplied string to translate input characters through. */
366 Lisp_Object Vkeyboard_translate_table
;
368 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
369 extern Lisp_Object Vfunction_key_map
;
371 /* Another keymap that maps key sequences into key sequences.
372 This one takes precedence over ordinary definitions. */
373 extern Lisp_Object Vkey_translation_map
;
375 /* If non-nil, this implements the current input method. */
376 Lisp_Object Vinput_method_function
;
377 Lisp_Object Qinput_method_function
;
379 /* When we call Vinput_method_function,
380 this holds the echo area message that was just erased. */
381 Lisp_Object Vinput_method_previous_message
;
383 /* Non-nil means deactivate the mark at end of this command. */
384 Lisp_Object Vdeactivate_mark
;
386 /* Menu bar specified in Lucid Emacs fashion. */
388 Lisp_Object Vlucid_menu_bar_dirty_flag
;
389 Lisp_Object Qrecompute_lucid_menubar
, Qactivate_menubar_hook
;
391 Lisp_Object Qecho_area_clear_hook
;
393 /* Hooks to run before and after each command. */
394 Lisp_Object Qpre_command_hook
, Vpre_command_hook
;
395 Lisp_Object Qpost_command_hook
, Vpost_command_hook
;
396 Lisp_Object Qcommand_hook_internal
, Vcommand_hook_internal
;
397 /* Hook run after a command if there's no more input soon. */
398 Lisp_Object Qpost_command_idle_hook
, Vpost_command_idle_hook
;
400 /* Delay time in microseconds before running post-command-idle-hook. */
401 int post_command_idle_delay
;
403 /* List of deferred actions to be performed at a later time.
404 The precise format isn't relevant here; we just check whether it is nil. */
405 Lisp_Object Vdeferred_action_list
;
407 /* Function to call to handle deferred actions, when there are any. */
408 Lisp_Object Vdeferred_action_function
;
409 Lisp_Object Qdeferred_action_function
;
411 Lisp_Object Qinput_method_exit_on_first_char
;
412 Lisp_Object Qinput_method_use_echo_area
;
414 /* File in which we write all commands we read. */
417 /* Nonzero if input is available. */
420 /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
421 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
425 extern char *pending_malloc_warning
;
427 /* Circular buffer for pre-read keyboard input. */
428 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
430 /* Vector to GCPRO the frames and windows mentioned in kbd_buffer.
432 The interrupt-level event handlers will never enqueue an event on a
433 frame which is not in Vframe_list, and once an event is dequeued,
434 internal_last_event_frame or the event itself points to the frame.
437 But while the event is sitting in the queue, it's completely
438 unprotected. Suppose the user types one command which will run for
439 a while and then delete a frame, and then types another event at
440 the frame that will be deleted, before the command gets around to
441 it. Suppose there are no references to this frame elsewhere in
442 Emacs, and a GC occurs before the second event is dequeued. Now we
443 have an event referring to a freed frame, which will crash Emacs
446 Similar things happen when an event on a scroll bar is enqueued; the
447 window may be deleted while the event is in the queue.
449 So, we use this vector to protect the frame_or_window field in the
450 event queue. That way, they'll be dequeued as dead frames or
451 windows, but still valid lisp objects.
453 If kbd_buffer[i].kind != no_event, then
454 (XVECTOR (kbd_buffer_frame_or_window)->contents[i]
455 == kbd_buffer[i].frame_or_window. */
456 static Lisp_Object kbd_buffer_frame_or_window
;
458 /* Pointer to next available character in kbd_buffer.
459 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
460 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the
461 next available char is in kbd_buffer[0]. */
462 static struct input_event
*kbd_fetch_ptr
;
464 /* Pointer to next place to store character in kbd_buffer. This
465 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
466 character should go in kbd_buffer[0]. */
467 static struct input_event
* volatile kbd_store_ptr
;
469 /* The above pair of variables forms a "queue empty" flag. When we
470 enqueue a non-hook event, we increment kbd_store_ptr. When we
471 dequeue a non-hook event, we increment kbd_fetch_ptr. We say that
472 there is input available iff the two pointers are not equal.
474 Why not just have a flag set and cleared by the enqueuing and
475 dequeuing functions? Such a flag could be screwed up by interrupts
476 at inopportune times. */
478 /* If this flag is non-nil, we check mouse_moved to see when the
479 mouse moves, and motion events will appear in the input stream.
480 Otherwise, mouse motion is ignored. */
481 static Lisp_Object do_mouse_tracking
;
483 /* Symbols to head events. */
484 Lisp_Object Qmouse_movement
;
485 Lisp_Object Qscroll_bar_movement
;
486 Lisp_Object Qswitch_frame
;
487 Lisp_Object Qdelete_frame
;
488 Lisp_Object Qiconify_frame
;
489 Lisp_Object Qmake_frame_visible
;
490 Lisp_Object Qhelp_echo
;
492 /* Symbols to denote kinds of events. */
493 Lisp_Object Qfunction_key
;
494 Lisp_Object Qmouse_click
;
496 Lisp_Object Qmouse_wheel
;
497 Lisp_Object Qlanguage_change
;
499 Lisp_Object Qdrag_n_drop
;
500 /* Lisp_Object Qmouse_movement; - also an event header */
502 /* Properties of event headers. */
503 Lisp_Object Qevent_kind
;
504 Lisp_Object Qevent_symbol_elements
;
506 /* menu item parts */
507 Lisp_Object Qmenu_alias
;
508 Lisp_Object Qmenu_enable
;
509 Lisp_Object QCenable
, QCvisible
, QChelp
, QCfilter
, QCkeys
, QCkey_sequence
;
510 Lisp_Object QCbutton
, QCtoggle
, QCradio
;
511 extern Lisp_Object Vdefine_key_rebound_commands
;
512 extern Lisp_Object Qmenu_item
;
514 /* An event header symbol HEAD may have a property named
515 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
516 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
517 mask of modifiers applied to it. If present, this is used to help
518 speed up parse_modifiers. */
519 Lisp_Object Qevent_symbol_element_mask
;
521 /* An unmodified event header BASE may have a property named
522 Qmodifier_cache, which is an alist mapping modifier masks onto
523 modified versions of BASE. If present, this helps speed up
525 Lisp_Object Qmodifier_cache
;
527 /* Symbols to use for parts of windows. */
528 Lisp_Object Qmode_line
;
529 Lisp_Object Qvertical_line
;
530 Lisp_Object Qvertical_scroll_bar
;
531 Lisp_Object Qmenu_bar
;
533 Lisp_Object
recursive_edit_unwind (), command_loop ();
534 Lisp_Object
Fthis_command_keys ();
535 Lisp_Object Qextended_command_history
;
536 EMACS_TIME
timer_check ();
538 extern Lisp_Object Vhistory_length
;
540 extern char *x_get_keysym_name ();
542 static void record_menu_key ();
544 Lisp_Object Qpolling_period
;
546 /* List of absolute timers. Appears in order of next scheduled event. */
547 Lisp_Object Vtimer_list
;
549 /* List of idle time timers. Appears in order of next scheduled event. */
550 Lisp_Object Vtimer_idle_list
;
552 /* Incremented whenever a timer is run. */
555 extern Lisp_Object Vprint_level
, Vprint_length
;
557 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
559 EMACS_TIME
*input_available_clear_time
;
561 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
562 Default is 1 if INTERRUPT_INPUT is defined. */
565 /* Nonzero while interrupts are temporarily deferred during redisplay. */
566 int interrupts_deferred
;
568 /* Nonzero means use ^S/^Q for flow control. */
571 /* Allow m- file to inhibit use of FIONREAD. */
572 #ifdef BROKEN_FIONREAD
576 /* We are unable to use interrupts if FIONREAD is not available,
577 so flush SIGIO so we won't try. */
584 /* If we support a window system, turn on the code to poll periodically
585 to detect C-g. It isn't actually used when doing interrupt input. */
586 #ifdef HAVE_WINDOW_SYSTEM
587 #define POLL_FOR_INPUT
590 /* Global variable declarations. */
592 /* Function for init_keyboard to call with no args (if nonzero). */
593 void (*keyboard_init_hook
) ();
595 static int read_avail_input ();
596 static void get_input_pending ();
597 static int readable_events ();
598 static Lisp_Object
read_char_x_menu_prompt ();
599 static Lisp_Object
read_char_minibuf_menu_prompt ();
600 static Lisp_Object
make_lispy_event ();
602 static Lisp_Object
make_lispy_movement ();
604 static Lisp_Object
modify_event_symbol ();
605 static Lisp_Object
make_lispy_switch_frame ();
606 static int parse_solitary_modifier ();
607 static void save_getcjmp ();
608 static void restore_getcjmp ();
609 static Lisp_Object apply_modifiers
P_ ((int, Lisp_Object
));
611 /* > 0 if we are to echo keystrokes. */
612 static int echo_keystrokes
;
614 /* Nonzero means don't try to suspend even if the operating system seems
616 static int cannot_suspend
;
618 #define min(a,b) ((a)<(b)?(a):(b))
619 #define max(a,b) ((a)>(b)?(a):(b))
621 /* Install the string STR as the beginning of the string of echoing,
622 so that it serves as a prompt for the next character.
623 Also start echoing. */
629 int len
= strlen (str
);
631 if (len
> ECHOBUFSIZE
- 4)
632 len
= ECHOBUFSIZE
- 4;
633 bcopy (str
, current_kboard
->echobuf
, len
);
634 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
635 *current_kboard
->echoptr
= '\0';
637 current_kboard
->echo_after_prompt
= len
;
642 /* Add C to the echo string, if echoing is going on.
643 C can be a character, which is printed prettily ("M-C-x" and all that
644 jazz), or a symbol, whose name is printed. */
650 extern char *push_key_description ();
652 if (current_kboard
->immediate_echo
)
654 char *ptr
= current_kboard
->echoptr
;
656 if (ptr
!= current_kboard
->echobuf
)
659 /* If someone has passed us a composite event, use its head symbol. */
664 if (ptr
- current_kboard
->echobuf
> ECHOBUFSIZE
- 6)
667 ptr
= push_key_description (XINT (c
), ptr
);
669 else if (SYMBOLP (c
))
671 struct Lisp_String
*name
= XSYMBOL (c
)->name
;
672 if ((ptr
- current_kboard
->echobuf
) + STRING_BYTES (name
) + 4
675 bcopy (name
->data
, ptr
, STRING_BYTES (name
));
676 ptr
+= STRING_BYTES (name
);
679 if (current_kboard
->echoptr
== current_kboard
->echobuf
682 strcpy (ptr
, " (Type ? for further options)");
687 current_kboard
->echoptr
= ptr
;
693 /* Temporarily add a dash to the end of the echo string if it's not
694 empty, so that it serves as a mini-prompt for the very next character. */
699 if (!current_kboard
->immediate_echo
700 && current_kboard
->echoptr
== current_kboard
->echobuf
)
702 /* Do nothing if we just printed a prompt. */
703 if (current_kboard
->echo_after_prompt
704 == current_kboard
->echoptr
- current_kboard
->echobuf
)
706 /* Do nothing if not echoing at all. */
707 if (current_kboard
->echoptr
== 0)
710 /* Put a dash at the end of the buffer temporarily,
711 but make it go away when the next character is added. */
712 current_kboard
->echoptr
[0] = '-';
713 current_kboard
->echoptr
[1] = 0;
718 /* Display the current echo string, and begin echoing if not already
724 if (!current_kboard
->immediate_echo
)
727 current_kboard
->immediate_echo
= 1;
729 for (i
= 0; i
< this_command_key_count
; i
++)
732 c
= XVECTOR (this_command_keys
)->contents
[i
];
733 if (! (EVENT_HAS_PARAMETERS (c
)
734 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
741 message2_nolog (current_kboard
->echobuf
, strlen (current_kboard
->echobuf
),
742 ! NILP (current_buffer
->enable_multibyte_characters
));
746 if (waiting_for_input
&& !NILP (Vquit_flag
))
747 quit_throw_to_read_char ();
750 /* Turn off echoing, for the start of a new command. */
755 current_kboard
->immediate_echo
= 0;
756 current_kboard
->echoptr
= current_kboard
->echobuf
;
757 current_kboard
->echo_after_prompt
= -1;
758 ok_to_echo_at_next_pause
= 0;
761 /* Return the length of the current echo string. */
766 return current_kboard
->echoptr
- current_kboard
->echobuf
;
769 /* Truncate the current echo message to its first LEN chars.
770 This and echo_char get used by read_key_sequence when the user
771 switches frames while entering a key sequence. */
777 current_kboard
->echobuf
[len
] = '\0';
778 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
779 truncate_echo_area (len
);
783 /* Functions for manipulating this_command_keys. */
785 add_command_key (key
)
788 int size
= XVECTOR (this_command_keys
)->size
;
790 /* If reset-this-command-length was called recently, obey it now.
791 See the doc string of that function for an explanation of why. */
792 if (before_command_restore_flag
)
794 this_command_key_count
= before_command_key_count_1
;
795 if (this_command_key_count
< this_single_command_key_start
)
796 this_single_command_key_start
= this_command_key_count
;
797 echo_truncate (before_command_echo_length_1
);
798 before_command_restore_flag
= 0;
801 if (this_command_key_count
>= size
)
803 Lisp_Object new_keys
;
805 new_keys
= Fmake_vector (make_number (size
* 2), Qnil
);
806 bcopy (XVECTOR (this_command_keys
)->contents
,
807 XVECTOR (new_keys
)->contents
,
808 size
* sizeof (Lisp_Object
));
810 this_command_keys
= new_keys
;
813 XVECTOR (this_command_keys
)->contents
[this_command_key_count
++] = key
;
819 int count
= specpdl_ptr
- specpdl
;
822 if (command_loop_level
> 0)
824 specbind (Qstandard_output
, Qt
);
825 specbind (Qstandard_input
, Qt
);
828 val
= command_loop ();
830 Fsignal (Qquit
, Qnil
);
831 /* Handle throw from read_minibuf when using minibuffer
832 while it's active but we're in another window. */
834 Fsignal (Qerror
, Fcons (val
, Qnil
));
836 return unbind_to (count
, Qnil
);
839 /* When an auto-save happens, record the "time", and don't do again soon. */
844 last_auto_save
= num_nonmacro_input_events
;
847 /* Make an auto save happen as soon as possible at command level. */
850 force_auto_save_soon ()
852 last_auto_save
= - auto_save_interval
- 1;
854 record_asynch_buffer_change ();
857 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
858 "Invoke the editor command loop recursively.\n\
859 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
860 that tells this function to return.\n\
861 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
862 This function is called by the editor initialization to begin editing.")
865 int count
= specpdl_ptr
- specpdl
;
868 command_loop_level
++;
869 update_mode_lines
= 1;
871 record_unwind_protect (recursive_edit_unwind
,
873 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
877 return unbind_to (count
, Qnil
);
881 recursive_edit_unwind (buffer
)
885 Fset_buffer (buffer
);
887 command_loop_level
--;
888 update_mode_lines
= 1;
896 #if 0 /* Theory: if there's anything in Vunread_command_events,
897 it will right away be read by read_key_sequence,
898 and then if we do switch KBOARDS, it will go into the side
899 queue then. So we don't need to do anything special here -- rms. */
900 if (CONSP (Vunread_command_events
))
902 current_kboard
->kbd_queue
903 = nconc2 (Vunread_command_events
, current_kboard
->kbd_queue
);
904 current_kboard
->kbd_queue_has_data
= 1;
906 Vunread_command_events
= Qnil
;
912 /* Switch to the single-kboard state, making current_kboard
913 the only KBOARD from which further input is accepted. */
916 single_kboard_state ()
923 /* Maintain a stack of kboards, so other parts of Emacs
924 can switch temporarily to the kboard of a given frame
925 and then revert to the previous status. */
930 struct kboard_stack
*next
;
933 static struct kboard_stack
*kboard_stack
;
936 push_frame_kboard (f
)
940 struct kboard_stack
*p
941 = (struct kboard_stack
*) xmalloc (sizeof (struct kboard_stack
));
943 p
->next
= kboard_stack
;
944 p
->kboard
= current_kboard
;
947 current_kboard
= FRAME_KBOARD (f
);
955 struct kboard_stack
*p
= kboard_stack
;
956 current_kboard
= p
->kboard
;
957 kboard_stack
= p
->next
;
962 /* Handle errors that are not handled at inner levels
963 by printing an error message and returning to the editor command loop. */
969 Lisp_Object old_level
, old_length
;
972 if (!NILP (executing_macro
))
974 if (executing_macro_iterations
== 1)
975 sprintf (macroerror
, "After 1 kbd macro iteration: ");
977 sprintf (macroerror
, "After %d kbd macro iterations: ",
978 executing_macro_iterations
);
983 Vstandard_output
= Qt
;
984 Vstandard_input
= Qt
;
985 Vexecuting_macro
= Qnil
;
986 executing_macro
= Qnil
;
987 current_kboard
->Vprefix_arg
= Qnil
;
988 current_kboard
->Vlast_prefix_arg
= Qnil
;
991 /* Avoid unquittable loop if data contains a circular list. */
992 old_level
= Vprint_level
;
993 old_length
= Vprint_length
;
994 XSETFASTINT (Vprint_level
, 10);
995 XSETFASTINT (Vprint_length
, 10);
996 cmd_error_internal (data
, macroerror
);
997 Vprint_level
= old_level
;
998 Vprint_length
= old_length
;
1002 Vinhibit_quit
= Qnil
;
1004 any_kboard_state ();
1007 return make_number (0);
1010 /* Take actions on handling an error. DATA is the data that describes
1013 CONTEXT is a C-string containing ASCII characters only which
1014 describes the context in which the error happened. If we need to
1015 generalize CONTEXT to allow multibyte characters, make it a Lisp
1019 cmd_error_internal (data
, context
)
1024 int kill_emacs_p
= 0;
1028 echo_area_glyphs
= 0;
1029 echo_area_message
= Qnil
;
1031 /* If the window system or terminal frame hasn't been initialized
1032 yet, or we're not interactive, it's best to dump this message out
1033 to stderr and exit. */
1034 if (!selected_frame
->glyphs_initialized_p
1035 /* This is the case of the frame dumped with Emacs, when we're
1036 running under a window system. */
1037 || (!NILP (Vwindow_system
)
1038 && !inhibit_window_system
1039 && !FRAME_WINDOW_P (selected_frame
))
1042 stream
= Qexternal_debugging_output
;
1053 write_string_1 (context
, -1, stream
);
1055 print_error_message (data
, stream
);
1057 /* If the window system or terminal frame hasn't been initialized
1058 yet, or we're in -batch mode, this error should cause Emacs to exit. */
1062 Fkill_emacs (make_number (-1));
1066 Lisp_Object
command_loop_1 ();
1067 Lisp_Object
command_loop_2 ();
1068 Lisp_Object
top_level_1 ();
1070 /* Entry to editor-command-loop.
1071 This level has the catches for exiting/returning to editor command loop.
1072 It returns nil to exit recursive edit, t to abort it. */
1077 if (command_loop_level
> 0 || minibuf_level
> 0)
1080 val
= internal_catch (Qexit
, command_loop_2
, Qnil
);
1081 executing_macro
= Qnil
;
1087 internal_catch (Qtop_level
, top_level_1
, Qnil
);
1088 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
1089 executing_macro
= Qnil
;
1091 /* End of file in -batch run causes exit here. */
1097 /* Here we catch errors in execution of commands within the
1098 editing loop, and reenter the editing loop.
1099 When there is an error, cmd_error runs and returns a non-nil
1100 value to us. A value of nil means that cmd_loop_1 itself
1101 returned due to end of file (or end of kbd macro). */
1106 register Lisp_Object val
;
1109 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
1110 while (!NILP (val
));
1118 return Feval (Vtop_level
);
1124 /* On entry to the outer level, run the startup file */
1125 if (!NILP (Vtop_level
))
1126 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
1127 else if (!NILP (Vpurify_flag
))
1128 message ("Bare impure Emacs (standard Lisp code not loaded)");
1130 message ("Bare Emacs (standard Lisp code not loaded)");
1134 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
1135 "Exit all recursive editing levels.")
1138 Fthrow (Qtop_level
, Qnil
);
1141 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
1142 "Exit from the innermost recursive edit or minibuffer.")
1145 if (command_loop_level
> 0 || minibuf_level
> 0)
1146 Fthrow (Qexit
, Qnil
);
1148 error ("No recursive edit is in progress");
1151 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
1152 "Abort the command that requested this recursive edit or minibuffer input.")
1155 if (command_loop_level
> 0 || minibuf_level
> 0)
1158 error ("No recursive edit is in progress");
1161 /* This is the actual command reading loop,
1162 sans error-handling encapsulation. */
1164 Lisp_Object
Fcommand_execute ();
1165 static int read_key_sequence ();
1166 void safe_run_hooks ();
1171 Lisp_Object cmd
, tem
;
1174 Lisp_Object keybuf
[30];
1179 struct buffer
*prev_buffer
;
1181 int was_locked
= single_kboard
;
1184 current_kboard
->Vprefix_arg
= Qnil
;
1185 current_kboard
->Vlast_prefix_arg
= Qnil
;
1186 Vdeactivate_mark
= Qnil
;
1187 waiting_for_input
= 0;
1192 this_command_key_count
= 0;
1193 this_single_command_key_start
= 0;
1195 /* Make sure this hook runs after commands that get errors and
1196 throw to top level. */
1197 /* Note that the value cell will never directly contain nil
1198 if the symbol is a local variable. */
1199 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1200 safe_run_hooks (Qpost_command_hook
);
1202 if (!NILP (Vdeferred_action_list
))
1203 call0 (Vdeferred_action_function
);
1205 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1207 if (NILP (Vunread_command_events
)
1208 && NILP (Vunread_input_method_events
)
1209 && NILP (Vunread_post_input_method_events
)
1210 && NILP (Vexecuting_macro
)
1211 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1, 1)))
1212 safe_run_hooks (Qpost_command_idle_hook
);
1215 /* Do this after running Vpost_command_hook, for consistency. */
1216 current_kboard
->Vlast_command
= Vthis_command
;
1217 current_kboard
->Vreal_last_command
= real_this_command
;
1221 if (! FRAME_LIVE_P (selected_frame
))
1224 /* Make sure the current window's buffer is selected. */
1225 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1226 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1228 /* Display any malloc warning that just came out. Use while because
1229 displaying one warning can cause another. */
1231 while (pending_malloc_warning
)
1232 display_malloc_warning ();
1236 Vdeactivate_mark
= Qnil
;
1238 /* If minibuffer on and echo area in use,
1239 wait 2 sec and redraw minibuffer. */
1242 && (echo_area_glyphs
|| STRINGP (echo_area_message
))
1243 && EQ (minibuf_window
, echo_area_window
))
1245 /* Bind inhibit-quit to t so that C-g gets read in
1246 rather than quitting back to the minibuffer. */
1247 int count
= specpdl_ptr
- specpdl
;
1248 specbind (Qinhibit_quit
, Qt
);
1250 Fsit_for (make_number (2), Qnil
, Qnil
);
1251 /* Clear the echo area. */
1253 safe_run_hooks (Qecho_area_clear_hook
);
1255 unbind_to (count
, Qnil
);
1257 /* If a C-g came in before, treat it as input now. */
1258 if (!NILP (Vquit_flag
))
1261 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1266 alloca (0); /* Cause a garbage collection now */
1267 /* Since we can free the most stuff here. */
1268 #endif /* C_ALLOCA */
1271 /* Select the frame that the last event came from. Usually,
1272 switch-frame events will take care of this, but if some lisp
1273 code swallows a switch-frame event, we'll fix things up here.
1274 Is this a good idea? */
1275 if (FRAMEP (internal_last_event_frame
)
1276 && XFRAME (internal_last_event_frame
) != selected_frame
)
1277 Fselect_frame (internal_last_event_frame
, Qnil
);
1279 /* If it has changed current-menubar from previous value,
1280 really recompute the menubar from the value. */
1281 if (! NILP (Vlucid_menu_bar_dirty_flag
)
1282 && !NILP (Ffboundp (Qrecompute_lucid_menubar
)))
1283 call0 (Qrecompute_lucid_menubar
);
1285 before_command_key_count
= this_command_key_count
;
1286 before_command_echo_length
= echo_length ();
1288 Vthis_command
= Qnil
;
1289 real_this_command
= Qnil
;
1291 /* Read next key sequence; i gets its length. */
1292 i
= read_key_sequence (keybuf
, sizeof keybuf
/ sizeof keybuf
[0],
1295 /* A filter may have run while we were reading the input. */
1296 if (! FRAME_LIVE_P (selected_frame
))
1298 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1299 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1303 /* Now we have read a key sequence of length I,
1304 or else I is 0 and we found end of file. */
1306 if (i
== 0) /* End of file -- happens only in */
1307 return Qnil
; /* a kbd macro, at the end. */
1308 /* -1 means read_key_sequence got a menu that was rejected.
1309 Just loop around and read another command. */
1313 this_command_key_count
= 0;
1314 this_single_command_key_start
= 0;
1318 last_command_char
= keybuf
[i
- 1];
1320 /* If the previous command tried to force a specific window-start,
1321 forget about that, in case this command moves point far away
1322 from that position. But also throw away beg_unchanged and
1323 end_unchanged information in that case, so that redisplay will
1324 update the whole window properly. */
1325 if (!NILP (XWINDOW (selected_window
)->force_start
))
1327 XWINDOW (selected_window
)->force_start
= Qnil
;
1328 beg_unchanged
= end_unchanged
= 0;
1331 cmd
= read_key_sequence_cmd
;
1332 if (!NILP (Vexecuting_macro
))
1334 if (!NILP (Vquit_flag
))
1336 Vexecuting_macro
= Qt
;
1337 QUIT
; /* Make some noise. */
1338 /* Will return since macro now empty. */
1342 /* Do redisplay processing after this command except in special
1343 cases identified below that set no_redisplay to 1.
1344 (actually, there's currently no way to prevent the redisplay,
1345 and no_redisplay is ignored.
1346 Perhaps someday we will really implement it.) */
1349 prev_buffer
= current_buffer
;
1350 prev_modiff
= MODIFF
;
1351 last_point_position
= PT
;
1352 XSETBUFFER (last_point_position_buffer
, prev_buffer
);
1354 /* Execute the command. */
1356 Vthis_command
= cmd
;
1357 real_this_command
= cmd
;
1358 /* Note that the value cell will never directly contain nil
1359 if the symbol is a local variable. */
1360 if (!NILP (Vpre_command_hook
) && !NILP (Vrun_hooks
))
1361 safe_run_hooks (Qpre_command_hook
);
1363 if (NILP (Vthis_command
))
1365 /* nil means key is undefined. */
1367 current_kboard
->defining_kbd_macro
= Qnil
;
1368 update_mode_lines
= 1;
1369 current_kboard
->Vprefix_arg
= Qnil
;
1373 if (NILP (current_kboard
->Vprefix_arg
) && ! no_direct
)
1375 /* In case we jump to directly_done. */
1376 Vcurrent_prefix_arg
= current_kboard
->Vprefix_arg
;
1378 /* Recognize some common commands in common situations and
1379 do them directly. */
1380 if (EQ (Vthis_command
, Qforward_char
) && PT
< ZV
)
1382 struct Lisp_Char_Table
*dp
1383 = window_display_table (XWINDOW (selected_window
));
1384 lose
= FETCH_CHAR (PT_BYTE
);
1387 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1388 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1389 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1390 && (lose
>= 0x20 && lose
< 0x7f)))
1391 : (lose
>= 0x20 && lose
< 0x7f))
1392 /* To extract the case of continuation on
1393 wide-column characters. */
1394 && (WIDTH_BY_CHAR_HEAD (FETCH_BYTE (PT_BYTE
)) == 1)
1395 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1397 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1399 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1401 && !windows_or_buffers_changed
1402 && EQ (current_buffer
->selective_display
, Qnil
)
1403 && !detect_input_pending ()
1404 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1405 && NILP (Vexecuting_macro
))
1406 no_redisplay
= direct_output_forward_char (1);
1409 else if (EQ (Vthis_command
, Qbackward_char
) && PT
> BEGV
)
1411 struct Lisp_Char_Table
*dp
1412 = window_display_table (XWINDOW (selected_window
));
1414 lose
= FETCH_CHAR (PT_BYTE
);
1416 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1417 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1418 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1419 && (lose
>= 0x20 && lose
< 0x7f)))
1420 : (lose
>= 0x20 && lose
< 0x7f))
1421 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1423 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1425 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1427 && !windows_or_buffers_changed
1428 && EQ (current_buffer
->selective_display
, Qnil
)
1429 && !detect_input_pending ()
1430 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1431 && NILP (Vexecuting_macro
))
1432 no_redisplay
= direct_output_forward_char (-1);
1435 else if (EQ (Vthis_command
, Qself_insert_command
)
1436 /* Try this optimization only on ascii keystrokes. */
1437 && INTEGERP (last_command_char
))
1439 unsigned int c
= XINT (last_command_char
);
1441 if (NILP (Vexecuting_macro
)
1442 && !EQ (minibuf_window
, selected_window
))
1444 if (!nonundocount
|| nonundocount
>= 20)
1452 lose
= ((XFASTINT (XWINDOW (selected_window
)->last_modified
)
1454 || (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1456 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1458 || MODIFF
<= SAVE_MODIFF
1459 || windows_or_buffers_changed
1460 || !EQ (current_buffer
->selective_display
, Qnil
)
1461 || detect_input_pending ()
1462 || !NILP (XWINDOW (selected_window
)->column_number_displayed
)
1463 || !NILP (Vexecuting_macro
));
1465 value
= internal_self_insert (c
, 0);
1470 /* VALUE == 1 when AFTER-CHANGE functions are
1471 installed which is the case most of the time
1472 because FONT-LOCK installs one. */
1473 if (!lose
&& !value
)
1474 no_redisplay
= direct_output_for_insert (c
);
1479 /* Here for a command that isn't executed directly */
1481 #ifdef HAVE_X_WINDOWS
1482 if (display_busy_cursor_p
)
1484 if (inhibit_busy_cursor
!= 2)
1485 inhibit_busy_cursor
= 0;
1486 if (!inhibit_busy_cursor
)
1487 Fx_show_busy_cursor ();
1492 if (NILP (current_kboard
->Vprefix_arg
))
1494 Fcommand_execute (Vthis_command
, Qnil
, Qnil
, Qnil
);
1497 current_kboard
->Vlast_prefix_arg
= Vcurrent_prefix_arg
;
1499 /* Note that the value cell will never directly contain nil
1500 if the symbol is a local variable. */
1501 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1502 safe_run_hooks (Qpost_command_hook
);
1504 if (!NILP (Vdeferred_action_list
))
1505 safe_run_hooks (Qdeferred_action_function
);
1507 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1509 if (NILP (Vunread_command_events
)
1510 && NILP (Vunread_input_method_events
)
1511 && NILP (Vunread_post_input_method_events
)
1512 && NILP (Vexecuting_macro
)
1513 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1, 1)))
1514 safe_run_hooks (Qpost_command_idle_hook
);
1517 /* If there is a prefix argument,
1518 1) We don't want Vlast_command to be ``universal-argument''
1519 (that would be dumb), so don't set Vlast_command,
1520 2) we want to leave echoing on so that the prefix will be
1521 echoed as part of this key sequence, so don't call
1523 3) we want to leave this_command_key_count non-zero, so that
1524 read_char will realize that it is re-reading a character, and
1525 not echo it a second time.
1527 If the command didn't actually create a prefix arg,
1528 but is merely a frame event that is transparent to prefix args,
1529 then the above doesn't apply. */
1530 if (NILP (current_kboard
->Vprefix_arg
) || CONSP (last_command_char
))
1532 current_kboard
->Vlast_command
= Vthis_command
;
1533 current_kboard
->Vreal_last_command
= real_this_command
;
1535 this_command_key_count
= 0;
1536 this_single_command_key_start
= 0;
1539 if (!NILP (current_buffer
->mark_active
) && !NILP (Vrun_hooks
))
1541 if (!NILP (Vdeactivate_mark
) && !NILP (Vtransient_mark_mode
))
1543 current_buffer
->mark_active
= Qnil
;
1544 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
1546 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
1547 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
1551 /* Install chars successfully executed in kbd macro. */
1553 if (!NILP (current_kboard
->defining_kbd_macro
)
1554 && NILP (current_kboard
->Vprefix_arg
))
1555 finalize_kbd_macro_chars ();
1559 any_kboard_state ();
1564 /* Subroutine for safe_run_hooks: run the hook HOOK. */
1567 safe_run_hooks_1 (hook
)
1570 return call1 (Vrun_hooks
, Vinhibit_quit
);
1573 /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */
1576 safe_run_hooks_error (data
)
1579 Fset (Vinhibit_quit
, Qnil
);
1582 /* If we get an error while running the hook, cause the hook variable
1583 to be nil. Also inhibit quits, so that C-g won't cause the hook
1584 to mysteriously evaporate. */
1587 safe_run_hooks (hook
)
1591 int count
= specpdl_ptr
- specpdl
;
1592 specbind (Qinhibit_quit
, hook
);
1594 internal_condition_case (safe_run_hooks_1
, Qt
, safe_run_hooks_error
);
1596 unbind_to (count
, Qnil
);
1599 /* Number of seconds between polling for input. */
1602 /* Nonzero means polling for input is temporarily suppressed. */
1603 int poll_suppress_count
;
1605 /* Nonzero if polling_for_input is actually being used. */
1606 int polling_for_input
;
1608 #ifdef POLL_FOR_INPUT
1610 /* Handle an alarm once each second and read pending input
1611 so as to handle a C-g if it comces in. */
1614 input_poll_signal (signalnum
) /* If we don't have an argument, */
1615 int signalnum
; /* some compilers complain in signal calls. */
1617 /* This causes the call to start_polling at the end
1618 to do its job. It also arranges for a quit or error
1619 from within read_avail_input to resume polling. */
1620 poll_suppress_count
++;
1621 if (interrupt_input_blocked
== 0
1622 && !waiting_for_input
)
1623 read_avail_input (0);
1624 /* Turn on the SIGALRM handler and request another alarm. */
1630 /* Begin signals to poll for input, if they are appropriate.
1631 This function is called unconditionally from various places. */
1636 #ifdef POLL_FOR_INPUT
1637 if (read_socket_hook
&& !interrupt_input
)
1639 poll_suppress_count
--;
1640 if (poll_suppress_count
== 0)
1642 signal (SIGALRM
, input_poll_signal
);
1643 polling_for_input
= 1;
1644 alarm (polling_period
);
1650 /* Nonzero if we are using polling to handle input asynchronously. */
1653 input_polling_used ()
1655 #ifdef POLL_FOR_INPUT
1656 return read_socket_hook
&& !interrupt_input
;
1662 /* Turn off polling. */
1667 #ifdef POLL_FOR_INPUT
1668 if (read_socket_hook
&& !interrupt_input
)
1670 if (poll_suppress_count
== 0)
1672 polling_for_input
= 0;
1675 poll_suppress_count
++;
1680 /* Set the value of poll_suppress_count to COUNT
1681 and start or stop polling accordingly. */
1684 set_poll_suppress_count (count
)
1687 #ifdef POLL_FOR_INPUT
1688 if (count
== 0 && poll_suppress_count
!= 0)
1690 poll_suppress_count
= 1;
1693 else if (count
!= 0 && poll_suppress_count
== 0)
1697 poll_suppress_count
= count
;
1701 /* Bind polling_period to a value at least N.
1702 But don't decrease it. */
1705 bind_polling_period (n
)
1708 #ifdef POLL_FOR_INPUT
1709 int new = polling_period
;
1715 specbind (Qpolling_period
, make_number (new));
1716 /* Start a new alarm with the new period. */
1721 /* Apply the control modifier to CHARACTER. */
1727 /* Save the upper bits here. */
1728 int upper
= c
& ~0177;
1732 /* Everything in the columns containing the upper-case letters
1733 denotes a control character. */
1734 if (c
>= 0100 && c
< 0140)
1738 /* Set the shift modifier for a control char
1739 made from a shifted letter. But only for letters! */
1740 if (oc
>= 'A' && oc
<= 'Z')
1741 c
|= shift_modifier
;
1744 /* The lower-case letters denote control characters too. */
1745 else if (c
>= 'a' && c
<= 'z')
1748 /* Include the bits for control and shift
1749 only if the basic ASCII code can't indicate them. */
1753 /* Replace the high bits. */
1754 c
|= (upper
& ~ctrl_modifier
);
1761 /* Input of single characters from keyboard */
1763 Lisp_Object
print_help ();
1764 static Lisp_Object
kbd_buffer_get_event ();
1765 static void record_char ();
1768 static jmp_buf wrong_kboard_jmpbuf
;
1771 /* read a character from the keyboard; call the redisplay if needed */
1772 /* commandflag 0 means do not do auto-saving, but do do redisplay.
1773 -1 means do not do redisplay, but do do autosaving.
1776 /* The arguments MAPS and NMAPS are for menu prompting.
1777 MAPS is an array of keymaps; NMAPS is the length of MAPS.
1779 PREV_EVENT is the previous input event, or nil if we are reading
1780 the first event of a key sequence (or not reading a key sequence).
1781 If PREV_EVENT is t, that is a "magic" value that says
1782 not to run input methods, but in other respects to act as if
1783 not reading a key sequence.
1785 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
1786 if we used a mouse menu to read the input, or zero otherwise. If
1787 USED_MOUSE_MENU is null, we don't dereference it.
1789 Value is t if we showed a menu and the user rejected it. */
1792 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
)
1796 Lisp_Object prev_event
;
1797 int *used_mouse_menu
;
1801 jmp_buf local_getcjmp
;
1803 int key_already_recorded
= 0;
1804 Lisp_Object tem
, save
;
1805 Lisp_Object previous_echo_area_message
;
1806 Lisp_Object also_record
;
1808 struct gcpro gcpro1
, gcpro2
;
1812 before_command_key_count
= this_command_key_count
;
1813 before_command_echo_length
= echo_length ();
1815 previous_echo_area_message
= Qnil
;
1817 GCPRO2 (c
, previous_echo_area_message
);
1822 if (CONSP (Vunread_post_input_method_events
))
1824 c
= XCONS (Vunread_post_input_method_events
)->car
;
1825 Vunread_post_input_method_events
1826 = XCONS (Vunread_post_input_method_events
)->cdr
;
1828 /* Undo what read_char_x_menu_prompt did when it unread
1829 additional keys returned by Fx_popup_menu. */
1831 && (SYMBOLP (XCONS (c
)->car
) || INTEGERP (XCONS (c
)->car
))
1832 && NILP (XCONS (c
)->cdr
))
1839 if (unread_command_char
!= -1)
1841 XSETINT (c
, unread_command_char
);
1842 unread_command_char
= -1;
1848 if (CONSP (Vunread_command_events
))
1850 c
= XCONS (Vunread_command_events
)->car
;
1851 Vunread_command_events
= XCONS (Vunread_command_events
)->cdr
;
1853 /* Undo what read_char_x_menu_prompt did when it unread
1854 additional keys returned by Fx_popup_menu. */
1856 && (SYMBOLP (XCONS (c
)->car
) || INTEGERP (XCONS (c
)->car
))
1857 && NILP (XCONS (c
)->cdr
))
1861 goto reread_for_input_method
;
1864 if (CONSP (Vunread_input_method_events
))
1866 c
= XCONS (Vunread_input_method_events
)->car
;
1867 Vunread_input_method_events
= XCONS (Vunread_input_method_events
)->cdr
;
1869 /* Undo what read_char_x_menu_prompt did when it unread
1870 additional keys returned by Fx_popup_menu. */
1872 && (SYMBOLP (XCONS (c
)->car
) || INTEGERP (XCONS (c
)->car
))
1873 && NILP (XCONS (c
)->cdr
))
1876 goto reread_for_input_method
;
1879 /* If there is no function key translated before
1880 reset-this-command-lengths takes effect, forget about it. */
1881 before_command_restore_flag
= 0;
1883 if (!NILP (Vexecuting_macro
))
1885 /* We set this to Qmacro; since that's not a frame, nobody will
1886 try to switch frames on us, and the selected window will
1889 Since this event came from a macro, it would be misleading to
1890 leave internal_last_event_frame set to wherever the last
1891 real event came from. Normally, a switch-frame event selects
1892 internal_last_event_frame after each command is read, but
1893 events read from a macro should never cause a new frame to be
1895 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
1897 /* Exit the macro if we are at the end.
1898 Also, some things replace the macro with t
1899 to force an early exit. */
1900 if (EQ (Vexecuting_macro
, Qt
)
1901 || executing_macro_index
>= XFASTINT (Flength (Vexecuting_macro
)))
1907 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
1908 if (STRINGP (Vexecuting_macro
)
1909 && (XINT (c
) & 0x80))
1910 XSETFASTINT (c
, CHAR_META
| (XINT (c
) & ~0x80));
1912 executing_macro_index
++;
1917 if (!NILP (unread_switch_frame
))
1919 c
= unread_switch_frame
;
1920 unread_switch_frame
= Qnil
;
1922 /* This event should make it into this_command_keys, and get echoed
1923 again, so we do not set `reread'. */
1927 /* if redisplay was requested */
1928 if (commandflag
>= 0)
1930 /* If there is pending input, process any events which are not
1931 user-visible, such as X selection_request events. */
1933 || detect_input_pending_run_timers (0))
1934 swallow_events (0); /* may clear input_pending */
1936 /* Redisplay if no pending input. */
1937 while (!input_pending
)
1942 /* Normal case: no input arrived during redisplay. */
1945 /* Input arrived and pre-empted redisplay.
1946 Process any events which are not user-visible. */
1948 /* If that cleared input_pending, try again to redisplay. */
1952 /* Message turns off echoing unless more keystrokes turn it on again. */
1953 if (echo_area_glyphs
1954 && *echo_area_glyphs
1955 && echo_area_glyphs
!= current_kboard
->echobuf
1956 && ok_to_echo_at_next_pause
!= echo_area_glyphs
)
1958 else if (STRINGP (echo_area_message
))
1961 /* If already echoing, continue. */
1964 /* Try reading a character via menu prompting in the minibuf.
1965 Try this before the sit-for, because the sit-for
1966 would do the wrong thing if we are supposed to do
1967 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
1968 after a mouse event so don't try a minibuf menu. */
1970 if (nmaps
> 0 && INTERACTIVE
1971 && !NILP (prev_event
) && ! EVENT_HAS_PARAMETERS (prev_event
)
1972 /* Don't bring up a menu if we already have another event. */
1973 && NILP (Vunread_command_events
)
1974 && unread_command_char
< 0
1975 && !detect_input_pending_run_timers (0))
1977 c
= read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
);
1980 key_already_recorded
= 1;
1985 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet.
1986 We will do that below, temporarily for short sections of code,
1987 when appropriate. local_getcjmp must be in effect
1988 around any call to sit_for or kbd_buffer_get_event;
1989 it *must not* be in effect when we call redisplay. */
1991 if (_setjmp (local_getcjmp
))
1993 XSETINT (c
, quit_char
);
1994 XSETFRAME (internal_last_event_frame
, selected_frame
);
1995 Vlast_event_frame
= internal_last_event_frame
;
1996 /* If we report the quit char as an event,
1997 don't do so more than once. */
1998 if (!NILP (Vinhibit_quit
))
2003 KBOARD
*kb
= FRAME_KBOARD (selected_frame
);
2004 if (kb
!= current_kboard
)
2006 Lisp_Object
*tailp
= &kb
->kbd_queue
;
2007 /* We shouldn't get here if we were in single-kboard mode! */
2010 while (CONSP (*tailp
))
2011 tailp
= &XCONS (*tailp
)->cdr
;
2014 *tailp
= Fcons (c
, Qnil
);
2015 kb
->kbd_queue_has_data
= 1;
2016 current_kboard
= kb
;
2017 /* This is going to exit from read_char
2018 so we had better get rid of this frame's stuff. */
2020 longjmp (wrong_kboard_jmpbuf
, 1);
2027 timer_start_idle ();
2029 /* If in middle of key sequence and minibuffer not active,
2030 start echoing if enough time elapses. */
2032 if (minibuf_level
== 0
2033 && !current_kboard
->immediate_echo
2034 && this_command_key_count
> 0
2036 && echo_keystrokes
> 0
2037 && !STRINGP (echo_area_message
)
2038 && (echo_area_glyphs
== 0 || *echo_area_glyphs
== 0
2039 || ok_to_echo_at_next_pause
== echo_area_glyphs
))
2043 /* After a mouse event, start echoing right away.
2044 This is because we are probably about to display a menu,
2045 and we don't want to delay before doing so. */
2046 if (EVENT_HAS_PARAMETERS (prev_event
))
2050 save_getcjmp (save_jump
);
2051 restore_getcjmp (local_getcjmp
);
2052 tem0
= sit_for (echo_keystrokes
, 0, 1, 1, 0);
2053 restore_getcjmp (save_jump
);
2055 && ! CONSP (Vunread_command_events
))
2060 /* Maybe auto save due to number of keystrokes. */
2062 if (commandflag
!= 0
2063 && auto_save_interval
> 0
2064 && num_nonmacro_input_events
- last_auto_save
> max (auto_save_interval
, 20)
2065 && !detect_input_pending_run_timers (0))
2067 Fdo_auto_save (Qnil
, Qnil
);
2068 /* Hooks can actually change some buffers in auto save. */
2072 /* Try reading using an X menu.
2073 This is never confused with reading using the minibuf
2074 because the recursive call of read_char in read_char_minibuf_menu_prompt
2075 does not pass on any keymaps. */
2077 if (nmaps
> 0 && INTERACTIVE
2078 && !NILP (prev_event
)
2079 && EVENT_HAS_PARAMETERS (prev_event
)
2080 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
)
2081 && !EQ (XCONS (prev_event
)->car
, Qtoolbar
)
2082 /* Don't bring up a menu if we already have another event. */
2083 && NILP (Vunread_command_events
)
2084 && unread_command_char
< 0)
2086 c
= read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
2088 /* Now that we have read an event, Emacs is not idle. */
2094 /* Maybe autosave and/or garbage collect due to idleness. */
2096 if (INTERACTIVE
&& NILP (c
))
2098 int delay_level
, buffer_size
;
2100 /* Slow down auto saves logarithmically in size of current buffer,
2101 and garbage collect while we're at it. */
2102 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
2103 last_non_minibuf_size
= Z
- BEG
;
2104 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
2106 while (buffer_size
> 64)
2107 delay_level
++, buffer_size
-= buffer_size
>> 2;
2108 if (delay_level
< 4) delay_level
= 4;
2109 /* delay_level is 4 for files under around 50k, 7 at 100k,
2110 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
2112 /* Auto save if enough time goes by without input. */
2113 if (commandflag
!= 0
2114 && num_nonmacro_input_events
> last_auto_save
2115 && INTEGERP (Vauto_save_timeout
)
2116 && XINT (Vauto_save_timeout
) > 0)
2120 save_getcjmp (save_jump
);
2121 restore_getcjmp (local_getcjmp
);
2122 tem0
= sit_for (delay_level
* XFASTINT (Vauto_save_timeout
) / 4,
2124 restore_getcjmp (save_jump
);
2127 && ! CONSP (Vunread_command_events
))
2129 Fdo_auto_save (Qnil
, Qnil
);
2131 /* If we have auto-saved and there is still no input
2132 available, garbage collect if there has been enough
2133 consing going on to make it worthwhile. */
2134 if (!detect_input_pending_run_timers (0)
2135 && consing_since_gc
> gc_cons_threshold
/ 2)
2136 Fgarbage_collect ();
2143 /* If this has become non-nil here, it has been set by a timer
2144 or sentinel or filter. */
2145 if (CONSP (Vunread_command_events
))
2147 c
= XCONS (Vunread_command_events
)->car
;
2148 Vunread_command_events
= XCONS (Vunread_command_events
)->cdr
;
2151 /* Read something from current KBOARD's side queue, if possible. */
2155 if (current_kboard
->kbd_queue_has_data
)
2157 if (!CONSP (current_kboard
->kbd_queue
))
2159 c
= XCONS (current_kboard
->kbd_queue
)->car
;
2160 current_kboard
->kbd_queue
2161 = XCONS (current_kboard
->kbd_queue
)->cdr
;
2162 if (NILP (current_kboard
->kbd_queue
))
2163 current_kboard
->kbd_queue_has_data
= 0;
2164 input_pending
= readable_events (0);
2165 if (EVENT_HAS_PARAMETERS (c
)
2166 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qswitch_frame
))
2167 internal_last_event_frame
= XCONS (XCONS (c
)->cdr
)->car
;
2168 Vlast_event_frame
= internal_last_event_frame
;
2173 /* If current_kboard's side queue is empty check the other kboards.
2174 If one of them has data that we have not yet seen here,
2175 switch to it and process the data waiting for it.
2177 Note: if the events queued up for another kboard
2178 have already been seen here, and therefore are not a complete command,
2179 the kbd_queue_has_data field is 0, so we skip that kboard here.
2180 That's to avoid an infinite loop switching between kboards here. */
2181 if (NILP (c
) && !single_kboard
)
2184 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2185 if (kb
->kbd_queue_has_data
)
2187 current_kboard
= kb
;
2188 /* This is going to exit from read_char
2189 so we had better get rid of this frame's stuff. */
2191 longjmp (wrong_kboard_jmpbuf
, 1);
2200 /* Finally, we read from the main queue,
2201 and if that gives us something we can't use yet, we put it on the
2202 appropriate side queue and try again. */
2208 /* Actually read a character, waiting if necessary. */
2209 save_getcjmp (save_jump
);
2210 restore_getcjmp (local_getcjmp
);
2211 c
= kbd_buffer_get_event (&kb
, used_mouse_menu
);
2212 restore_getcjmp (save_jump
);
2215 if (! NILP (c
) && (kb
!= current_kboard
))
2217 Lisp_Object
*tailp
= &kb
->kbd_queue
;
2218 while (CONSP (*tailp
))
2219 tailp
= &XCONS (*tailp
)->cdr
;
2222 *tailp
= Fcons (c
, Qnil
);
2223 kb
->kbd_queue_has_data
= 1;
2227 current_kboard
= kb
;
2228 /* This is going to exit from read_char
2229 so we had better get rid of this frame's stuff. */
2231 longjmp (wrong_kboard_jmpbuf
, 1);
2236 /* Terminate Emacs in batch mode if at eof. */
2237 if (noninteractive
&& INTEGERP (c
) && XINT (c
) < 0)
2238 Fkill_emacs (make_number (1));
2242 /* Add in any extra modifiers, where appropriate. */
2243 if ((extra_keyboard_modifiers
& CHAR_CTL
)
2244 || ((extra_keyboard_modifiers
& 0177) < ' '
2245 && (extra_keyboard_modifiers
& 0177) != 0))
2246 XSETINT (c
, make_ctrl_char (XINT (c
)));
2248 /* Transfer any other modifier bits directly from
2249 extra_keyboard_modifiers to c. Ignore the actual character code
2250 in the low 16 bits of extra_keyboard_modifiers. */
2251 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
2262 if (commandflag
>= 0
2263 && !input_pending
&& !detect_input_pending_run_timers (0))
2271 /* Buffer switch events are only for internal wakeups
2272 so don't show them to the user.
2273 Also, don't record a key if we already did. */
2274 if (BUFFERP (c
) || key_already_recorded
)
2277 /* Process special events within read_char
2278 and loop around to read another event. */
2281 tem
= get_keyelt (access_keymap (get_keymap_1 (Vspecial_event_map
, 0, 0),
2287 int was_locked
= single_kboard
;
2289 last_input_char
= c
;
2290 Fcommand_execute (tem
, Qnil
, Fvector (1, &last_input_char
), Qt
);
2292 /* Resume allowing input from any kboard, if that was true before. */
2294 any_kboard_state ();
2299 /* Handle things that only apply to characters. */
2302 /* If kbd_buffer_get_event gave us an EOF, return that. */
2306 if ((STRINGP (Vkeyboard_translate_table
)
2307 && XSTRING (Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
2308 || (VECTORP (Vkeyboard_translate_table
)
2309 && XVECTOR (Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
2310 || (CHAR_TABLE_P (Vkeyboard_translate_table
)
2311 && CHAR_TABLE_ORDINARY_SLOTS
> (unsigned) XFASTINT (c
)))
2314 d
= Faref (Vkeyboard_translate_table
, c
);
2315 /* nil in keyboard-translate-table means no translation. */
2321 /* If this event is a mouse click in the menu bar,
2322 return just menu-bar for now. Modify the mouse click event
2323 so we won't do this twice, then queue it up. */
2324 if (EVENT_HAS_PARAMETERS (c
)
2325 && CONSP (XCONS (c
)->cdr
)
2326 && CONSP (EVENT_START (c
))
2327 && CONSP (XCONS (EVENT_START (c
))->cdr
))
2331 posn
= POSN_BUFFER_POSN (EVENT_START (c
));
2332 /* Handle menu-bar events:
2333 insert the dummy prefix event `menu-bar'. */
2334 if (EQ (posn
, Qmenu_bar
) || EQ (posn
, Qtoolbar
))
2336 /* Change menu-bar to (menu-bar) as the event "position". */
2337 POSN_BUFFER_POSN (EVENT_START (c
)) = Fcons (posn
, Qnil
);
2340 Vunread_command_events
= Fcons (c
, Vunread_command_events
);
2345 /* Store these characters into recent_keys, the dribble file if any,
2346 and the keyboard macro being defined, if any. */
2348 if (! NILP (also_record
))
2349 record_char (also_record
);
2351 /* Wipe the echo area.
2352 But first, if we are about to use an input method,
2353 save the echo area contents for it to refer to. */
2355 && ! NILP (Vinput_method_function
)
2356 && (unsigned) XINT (c
) >= ' '
2357 && (unsigned) XINT (c
) < 127)
2359 previous_echo_area_message
= Fcurrent_message ();
2360 Vinput_method_previous_message
= previous_echo_area_message
;
2363 /* Now wipe the echo area. */
2364 if (echo_area_glyphs
|| STRINGP (echo_area_message
))
2365 safe_run_hooks (Qecho_area_clear_hook
);
2366 echo_area_glyphs
= 0;
2367 echo_area_message
= Qnil
;
2369 reread_for_input_method
:
2371 /* Pass this to the input method, if appropriate. */
2373 && ! NILP (Vinput_method_function
)
2374 /* Don't run the input method within a key sequence,
2375 after the first event of the key sequence. */
2376 && NILP (prev_event
)
2377 && (unsigned) XINT (c
) >= ' '
2378 && (unsigned) XINT (c
) < 127)
2382 struct gcpro gcpro1
;
2383 int count
= specpdl_ptr
- specpdl
;
2385 /* Save the echo status. */
2386 int saved_immediate_echo
= current_kboard
->immediate_echo
;
2387 char *saved_ok_to_echo
= ok_to_echo_at_next_pause
;
2388 int saved_echo_after_prompt
= current_kboard
->echo_after_prompt
;
2390 if (before_command_restore_flag
)
2392 this_command_key_count
= before_command_key_count_1
;
2393 if (this_command_key_count
< this_single_command_key_start
)
2394 this_single_command_key_start
= this_command_key_count
;
2395 echo_truncate (before_command_echo_length_1
);
2396 before_command_restore_flag
= 0;
2399 /* Save the this_command_keys status. */
2400 key_count
= this_command_key_count
;
2403 keys
= Fcopy_sequence (this_command_keys
);
2408 /* Clear out this_command_keys. */
2409 this_command_key_count
= 0;
2411 /* Now wipe the echo area. */
2412 if (echo_area_glyphs
|| STRINGP (echo_area_message
))
2413 safe_run_hooks (Qecho_area_clear_hook
);
2414 echo_area_glyphs
= 0;
2415 echo_area_message
= Qnil
;
2418 /* If we are not reading a key sequence,
2419 never use the echo area. */
2422 specbind (Qinput_method_use_echo_area
, Qt
);
2425 /* Call the input method. */
2426 tem
= call1 (Vinput_method_function
, c
);
2428 tem
= unbind_to (count
, tem
);
2430 /* Restore the saved echoing state
2431 and this_command_keys state. */
2432 this_command_key_count
= key_count
;
2434 this_command_keys
= keys
;
2437 ok_to_echo_at_next_pause
= saved_ok_to_echo
;
2438 current_kboard
->echo_after_prompt
= saved_echo_after_prompt
;
2439 if (saved_immediate_echo
)
2444 /* The input method can return no events. */
2447 /* Bring back the previous message, if any. */
2448 if (! NILP (previous_echo_area_message
))
2449 message_with_string ("%s", previous_echo_area_message
, 0);
2452 /* It returned one event or more. */
2453 c
= XCONS (tem
)->car
;
2454 Vunread_post_input_method_events
2455 = nconc2 (XCONS (tem
)->cdr
, Vunread_post_input_method_events
);
2460 /* Display help if not echoing. */
2462 && EQ (XCAR (c
), Qhelp_echo
))
2464 Lisp_Object msg
= XCDR (XCDR (c
));
2466 if (!NILP (Vshow_help_function
))
2467 call1 (Vshow_help_function
, msg
);
2468 else if (!echoing
&& !MINI_WINDOW_P (XWINDOW (selected_window
)))
2471 message3_nolog (msg
, XSTRING (msg
)->size
, STRING_MULTIBYTE (msg
));
2479 if (this_command_key_count
== 0 || ! reread
)
2481 before_command_key_count
= this_command_key_count
;
2482 before_command_echo_length
= echo_length ();
2484 /* Don't echo mouse motion events. */
2486 && ! (EVENT_HAS_PARAMETERS (c
)
2487 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
2490 if (! NILP (also_record
))
2491 echo_char (also_record
);
2492 /* Once we reread a character, echoing can happen
2493 the next time we pause to read a new one. */
2494 ok_to_echo_at_next_pause
= echo_area_glyphs
;
2497 /* Record this character as part of the current key. */
2498 add_command_key (c
);
2499 if (! NILP (also_record
))
2500 add_command_key (also_record
);
2503 last_input_char
= c
;
2506 /* Process the help character specially if enabled */
2507 if (!NILP (Vhelp_form
) && help_char_p (c
))
2510 count
= specpdl_ptr
- specpdl
;
2512 record_unwind_protect (Fset_window_configuration
,
2513 Fcurrent_window_configuration (Qnil
));
2515 tem0
= Feval (Vhelp_form
);
2517 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
2521 c
= read_char (0, 0, 0, Qnil
, 0);
2522 while (BUFFERP (c
));
2523 /* Remove the help from the frame */
2524 unbind_to (count
, Qnil
);
2527 if (EQ (c
, make_number (040)))
2531 c
= read_char (0, 0, 0, Qnil
, 0);
2532 while (BUFFERP (c
));
2539 /* Record a key that came from a mouse menu.
2540 Record it for echoing, for this-command-keys, and so on. */
2546 /* Wipe the echo area. */
2547 echo_area_glyphs
= 0;
2548 echo_area_message
= Qnil
;
2552 before_command_key_count
= this_command_key_count
;
2553 before_command_echo_length
= echo_length ();
2555 /* Don't echo mouse motion events. */
2556 if (echo_keystrokes
)
2560 /* Once we reread a character, echoing can happen
2561 the next time we pause to read a new one. */
2562 ok_to_echo_at_next_pause
= 0;
2565 /* Record this character as part of the current key. */
2566 add_command_key (c
);
2568 /* Re-reading in the middle of a command */
2569 last_input_char
= c
;
2573 /* Return 1 if should recognize C as "the help character". */
2581 if (EQ (c
, Vhelp_char
))
2583 for (tail
= Vhelp_event_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
2584 if (EQ (c
, XCONS (tail
)->car
))
2589 /* Record the input event C in various ways. */
2596 XVECTOR (recent_keys
)->contents
[recent_keys_index
] = c
;
2597 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
2598 recent_keys_index
= 0;
2600 /* Write c to the dribble file. If c is a lispy event, write
2601 the event's symbol to the dribble file, in <brackets>. Bleaugh.
2602 If you, dear reader, have a better idea, you've got the source. :-) */
2607 if (XUINT (c
) < 0x100)
2608 putc (XINT (c
), dribble
);
2610 fprintf (dribble
, " 0x%x", (int) XUINT (c
));
2614 Lisp_Object dribblee
;
2616 /* If it's a structured event, take the event header. */
2617 dribblee
= EVENT_HEAD (c
);
2619 if (SYMBOLP (dribblee
))
2621 putc ('<', dribble
);
2622 fwrite (XSYMBOL (dribblee
)->name
->data
, sizeof (char),
2623 STRING_BYTES (XSYMBOL (dribblee
)->name
),
2625 putc ('>', dribble
);
2632 store_kbd_macro_char (c
);
2634 num_nonmacro_input_events
++;
2641 struct buffer
*old
= current_buffer
;
2642 Fprinc (object
, Qnil
);
2643 set_buffer_internal (XBUFFER (Vstandard_output
));
2644 call0 (intern ("help-mode"));
2645 set_buffer_internal (old
);
2649 /* Copy out or in the info on where C-g should throw to.
2650 This is used when running Lisp code from within get_char,
2651 in case get_char is called recursively.
2652 See read_process_output. */
2658 bcopy (getcjmp
, temp
, sizeof getcjmp
);
2662 restore_getcjmp (temp
)
2665 bcopy (temp
, getcjmp
, sizeof getcjmp
);
2670 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
2671 of this function. */
2674 tracking_off (old_value
)
2675 Lisp_Object old_value
;
2677 do_mouse_tracking
= old_value
;
2678 if (NILP (old_value
))
2680 /* Redisplay may have been preempted because there was input
2681 available, and it assumes it will be called again after the
2682 input has been processed. If the only input available was
2683 the sort that we have just disabled, then we need to call
2685 if (!readable_events (1))
2687 redisplay_preserve_echo_area ();
2688 get_input_pending (&input_pending
, 1);
2693 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
2694 "Evaluate BODY with mouse movement events enabled.\n\
2695 Within a `track-mouse' form, mouse motion generates input events that\n\
2696 you can read with `read-event'.\n\
2697 Normally, mouse motion is ignored.")
2701 int count
= specpdl_ptr
- specpdl
;
2704 record_unwind_protect (tracking_off
, do_mouse_tracking
);
2706 do_mouse_tracking
= Qt
;
2708 val
= Fprogn (args
);
2709 return unbind_to (count
, val
);
2712 /* If mouse has moved on some frame, return one of those frames.
2713 Return 0 otherwise. */
2718 Lisp_Object tail
, frame
;
2720 FOR_EACH_FRAME (tail
, frame
)
2722 if (XFRAME (frame
)->mouse_moved
)
2723 return XFRAME (frame
);
2729 #endif /* HAVE_MOUSE */
2731 /* Low level keyboard/mouse input.
2732 kbd_buffer_store_event places events in kbd_buffer, and
2733 kbd_buffer_get_event retrieves them. */
2735 /* Return true iff there are any events in the queue that read-char
2736 would return. If this returns false, a read-char would block. */
2738 readable_events (do_timers_now
)
2742 timer_check (do_timers_now
);
2744 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2747 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2752 if (current_kboard
->kbd_queue_has_data
)
2758 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2759 if (kb
->kbd_queue_has_data
)
2765 /* Set this for debugging, to have a way to get out */
2770 event_to_kboard (event
)
2771 struct input_event
*event
;
2774 frame
= event
->frame_or_window
;
2776 frame
= XCONS (frame
)->car
;
2777 else if (WINDOWP (frame
))
2778 frame
= WINDOW_FRAME (XWINDOW (frame
));
2780 /* There are still some events that don't set this field.
2781 For now, just ignore the problem.
2782 Also ignore dead frames here. */
2783 if (!FRAMEP (frame
) || !FRAME_LIVE_P (XFRAME (frame
)))
2786 return FRAME_KBOARD (XFRAME (frame
));
2790 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
2793 kbd_buffer_store_event (event
)
2794 register struct input_event
*event
;
2796 if (event
->kind
== no_event
)
2799 if (event
->kind
== ascii_keystroke
)
2801 register int c
= event
->code
& 0377;
2803 if (event
->modifiers
& ctrl_modifier
)
2804 c
= make_ctrl_char (c
);
2806 c
|= (event
->modifiers
2807 & (meta_modifier
| alt_modifier
2808 | hyper_modifier
| super_modifier
));
2812 extern SIGTYPE
interrupt_signal ();
2815 struct input_event
*sp
;
2818 && (kb
= FRAME_KBOARD (XFRAME (event
->frame_or_window
)),
2819 kb
!= current_kboard
))
2822 = Fcons (make_lispy_switch_frame (event
->frame_or_window
),
2823 Fcons (make_number (c
), Qnil
));
2824 kb
->kbd_queue_has_data
= 1;
2825 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
2827 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
2830 if (event_to_kboard (sp
) == kb
)
2832 sp
->kind
= no_event
;
2833 sp
->frame_or_window
= Qnil
;
2840 /* If this results in a quit_char being returned to Emacs as
2841 input, set Vlast_event_frame properly. If this doesn't
2842 get returned to Emacs as an event, the next event read
2843 will set Vlast_event_frame again, so this is safe to do. */
2847 focus
= FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
2849 focus
= event
->frame_or_window
;
2850 internal_last_event_frame
= focus
;
2851 Vlast_event_frame
= focus
;
2854 last_event_timestamp
= event
->timestamp
;
2855 interrupt_signal ();
2859 if (c
&& c
== stop_character
)
2865 /* Don't insert two buffer_switch_event's in a row.
2866 Just ignore the second one. */
2867 else if (event
->kind
== buffer_switch_event
2868 && kbd_fetch_ptr
!= kbd_store_ptr
2869 && kbd_store_ptr
->kind
== buffer_switch_event
)
2872 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
2873 kbd_store_ptr
= kbd_buffer
;
2875 /* Don't let the very last slot in the buffer become full,
2876 since that would make the two pointers equal,
2877 and that is indistinguishable from an empty buffer.
2878 Discard the event if it would fill the last slot. */
2879 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
2881 struct input_event
*sp
= kbd_store_ptr
;
2882 sp
->kind
= event
->kind
;
2883 if (event
->kind
== selection_request_event
)
2885 /* We must not use the ordinary copying code for this case,
2886 since `part' is an enum and copying it might not copy enough
2888 bcopy (event
, (char *) sp
, sizeof (*event
));
2892 sp
->code
= event
->code
;
2893 sp
->part
= event
->part
;
2894 sp
->frame_or_window
= event
->frame_or_window
;
2895 sp
->modifiers
= event
->modifiers
;
2898 sp
->timestamp
= event
->timestamp
;
2900 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_store_ptr
2902 = event
->frame_or_window
);
2908 /* Discard any mouse events in the event buffer by setting them to
2911 discard_mouse_events ()
2913 struct input_event
*sp
;
2914 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
2916 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
2919 if (sp
->kind
== mouse_click
2921 || sp
->kind
== w32_scroll_bar_click
2923 || sp
->kind
== scroll_bar_click
)
2925 sp
->kind
= no_event
;
2930 /* Read one event from the event buffer, waiting if necessary.
2931 The value is a Lisp object representing the event.
2932 The value is nil for an event that should be ignored,
2933 or that was handled here.
2934 We always read and discard one event. */
2937 kbd_buffer_get_event (kbp
, used_mouse_menu
)
2939 int *used_mouse_menu
;
2943 EMACS_TIME next_timer_delay
;
2949 *kbp
= current_kboard
;
2953 /* Wait until there is input available. */
2956 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2959 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2963 /* If the quit flag is set, then read_char will return
2964 quit_char, so that counts as "available input." */
2965 if (!NILP (Vquit_flag
))
2966 quit_throw_to_read_char ();
2968 /* One way or another, wait until input is available; then, if
2969 interrupt handlers have not read it, read it now. */
2972 wait_for_kbd_input ();
2974 /* Note SIGIO has been undef'd if FIONREAD is missing. */
2978 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2981 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2985 Lisp_Object minus_one
;
2987 XSETINT (minus_one
, -1);
2988 wait_reading_process_input (0, 0, minus_one
, 1);
2990 if (!interrupt_input
&& kbd_fetch_ptr
== kbd_store_ptr
)
2991 /* Pass 1 for EXPECT since we just waited to have input. */
2992 read_avail_input (1);
2994 #endif /* not VMS */
2997 if (CONSP (Vunread_command_events
))
3000 first
= XCONS (Vunread_command_events
)->car
;
3001 Vunread_command_events
= XCONS (Vunread_command_events
)->cdr
;
3002 *kbp
= current_kboard
;
3006 /* At this point, we know that there is a readable event available
3007 somewhere. If the event queue is empty, then there must be a
3008 mouse movement enabled and available. */
3009 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3011 struct input_event
*event
;
3013 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
3017 last_event_timestamp
= event
->timestamp
;
3020 *kbp
= event_to_kboard (event
);
3022 *kbp
= current_kboard
; /* Better than returning null ptr? */
3024 *kbp
= &the_only_kboard
;
3029 /* These two kinds of events get special handling
3030 and don't actually appear to the command loop.
3031 We return nil for them. */
3032 if (event
->kind
== selection_request_event
)
3035 struct input_event copy
;
3037 /* Remove it from the buffer before processing it,
3038 since otherwise swallow_events will see it
3039 and process it again. */
3041 kbd_fetch_ptr
= event
+ 1;
3042 input_pending
= readable_events (0);
3043 x_handle_selection_request (©
);
3045 /* We're getting selection request events, but we don't have
3051 else if (event
->kind
== selection_clear_event
)
3054 struct input_event copy
;
3056 /* Remove it from the buffer before processing it. */
3058 kbd_fetch_ptr
= event
+ 1;
3059 input_pending
= readable_events (0);
3060 x_handle_selection_clear (©
);
3062 /* We're getting selection request events, but we don't have
3067 #if defined (HAVE_X11) || defined (HAVE_NTGUI)
3068 else if (event
->kind
== delete_window_event
)
3070 /* Make an event (delete-frame (FRAME)). */
3071 obj
= Fcons (event
->frame_or_window
, Qnil
);
3072 obj
= Fcons (Qdelete_frame
, Fcons (obj
, Qnil
));
3073 kbd_fetch_ptr
= event
+ 1;
3075 else if (event
->kind
== iconify_event
)
3077 /* Make an event (iconify-frame (FRAME)). */
3078 obj
= Fcons (event
->frame_or_window
, Qnil
);
3079 obj
= Fcons (Qiconify_frame
, Fcons (obj
, Qnil
));
3080 kbd_fetch_ptr
= event
+ 1;
3082 else if (event
->kind
== deiconify_event
)
3084 /* Make an event (make-frame-visible (FRAME)). */
3085 obj
= Fcons (event
->frame_or_window
, Qnil
);
3086 obj
= Fcons (Qmake_frame_visible
, Fcons (obj
, Qnil
));
3087 kbd_fetch_ptr
= event
+ 1;
3090 else if (event
->kind
== buffer_switch_event
)
3092 /* The value doesn't matter here; only the type is tested. */
3093 XSETBUFFER (obj
, current_buffer
);
3094 kbd_fetch_ptr
= event
+ 1;
3096 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
3097 else if (event
->kind
== menu_bar_activate_event
)
3099 kbd_fetch_ptr
= event
+ 1;
3100 input_pending
= readable_events (0);
3101 if (FRAME_LIVE_P (XFRAME (event
->frame_or_window
)))
3102 x_activate_menubar (XFRAME (event
->frame_or_window
));
3106 else if (event
->kind
== language_change_event
)
3108 /* Make an event (language-change (FRAME CHARSET LCID)). */
3109 obj
= Fcons (event
->modifiers
, Qnil
);
3110 obj
= Fcons (event
->code
, Qnil
);
3111 obj
= Fcons (event
->frame_or_window
, obj
);
3112 obj
= Fcons (Qlanguage_change
, Fcons (obj
, Qnil
));
3113 kbd_fetch_ptr
= event
+ 1;
3116 /* Just discard these, by returning nil.
3117 With MULTI_KBOARD, these events are used as placeholders
3118 when we need to randomly delete events from the queue.
3119 (They shouldn't otherwise be found in the buffer,
3120 but on some machines it appears they do show up
3121 even without MULTI_KBOARD.) */
3122 /* On Windows NT/9X, no_event is used to delete extraneous
3123 mouse events during a popup-menu call. */
3124 else if (event
->kind
== no_event
)
3125 kbd_fetch_ptr
= event
+ 1;
3126 else if (event
->kind
== HELP_EVENT
)
3128 /* The car of event->frame_or_window is a frame,
3129 the cdr is the help to display. */
3130 obj
= Fcons (Qhelp_echo
, event
->frame_or_window
);
3131 kbd_fetch_ptr
= event
+ 1;
3133 /* If this event is on a different frame, return a switch-frame this
3134 time, and leave the event in the queue for next time. */
3140 frame
= event
->frame_or_window
;
3142 frame
= XCONS (frame
)->car
;
3143 else if (WINDOWP (frame
))
3144 frame
= WINDOW_FRAME (XWINDOW (frame
));
3146 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
3150 if (! EQ (frame
, internal_last_event_frame
)
3151 && XFRAME (frame
) != selected_frame
)
3152 obj
= make_lispy_switch_frame (frame
);
3153 internal_last_event_frame
= frame
;
3155 /* If we didn't decide to make a switch-frame event, go ahead
3156 and build a real event from the queue entry. */
3160 obj
= make_lispy_event (event
);
3161 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
3162 /* If this was a menu selection, then set the flag to inhibit
3163 writing to last_nonmenu_event. Don't do this if the event
3164 we're returning is (menu-bar), though; that indicates the
3165 beginning of the menu sequence, and we might as well leave
3166 that as the `event with parameters' for this selection. */
3167 if ((event
->kind
== menu_bar_event
3168 || event
->kind
== TOOLBAR_EVENT
)
3169 && !(CONSP (obj
) && EQ (XCONS (obj
)->car
, Qmenu_bar
))
3170 && !(CONSP (obj
) && EQ (XCONS (obj
)->car
, Qtoolbar
))
3172 *used_mouse_menu
= 1;
3175 /* Wipe out this event, to catch bugs. */
3176 event
->kind
= no_event
;
3177 XVECTOR (kbd_buffer_frame_or_window
)->contents
[event
- kbd_buffer
] = Qnil
;
3179 kbd_fetch_ptr
= event
+ 1;
3184 /* Try generating a mouse motion event. */
3185 else if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
3187 FRAME_PTR f
= some_mouse_moved ();
3188 Lisp_Object bar_window
;
3189 enum scroll_bar_part part
;
3193 *kbp
= current_kboard
;
3194 /* Note that this uses F to determine which display to look at.
3195 If there is no valid info, it does not store anything
3196 so x remains nil. */
3198 (*mouse_position_hook
) (&f
, 0, &bar_window
, &part
, &x
, &y
, &time
);
3202 /* Decide if we should generate a switch-frame event. Don't
3203 generate switch-frame events for motion outside of all Emacs
3209 frame
= FRAME_FOCUS_FRAME (f
);
3211 XSETFRAME (frame
, f
);
3213 if (! EQ (frame
, internal_last_event_frame
)
3214 && XFRAME (frame
) != selected_frame
)
3215 obj
= make_lispy_switch_frame (frame
);
3216 internal_last_event_frame
= frame
;
3219 /* If we didn't decide to make a switch-frame event, go ahead and
3220 return a mouse-motion event. */
3221 if (!NILP (x
) && NILP (obj
))
3222 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
3224 #endif /* HAVE_MOUSE */
3226 /* We were promised by the above while loop that there was
3227 something for us to read! */
3230 input_pending
= readable_events (0);
3232 Vlast_event_frame
= internal_last_event_frame
;
3237 /* Process any events that are not user-visible,
3238 then return, without reading any user-visible events. */
3241 swallow_events (do_display
)
3246 while (kbd_fetch_ptr
!= kbd_store_ptr
)
3248 struct input_event
*event
;
3250 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
3254 last_event_timestamp
= event
->timestamp
;
3256 /* These two kinds of events get special handling
3257 and don't actually appear to the command loop. */
3258 if (event
->kind
== selection_request_event
)
3261 struct input_event copy
;
3263 /* Remove it from the buffer before processing it,
3264 since otherwise swallow_events called recursively could see it
3265 and process it again. */
3267 kbd_fetch_ptr
= event
+ 1;
3268 input_pending
= readable_events (0);
3269 x_handle_selection_request (©
);
3271 /* We're getting selection request events, but we don't have
3277 else if (event
->kind
== selection_clear_event
)
3280 struct input_event copy
;
3282 /* Remove it from the buffer before processing it, */
3285 kbd_fetch_ptr
= event
+ 1;
3286 input_pending
= readable_events (0);
3287 x_handle_selection_clear (©
);
3289 /* We're getting selection request events, but we don't have
3298 old_timers_run
= timers_run
;
3299 get_input_pending (&input_pending
, 1);
3301 if (timers_run
!= old_timers_run
&& do_display
)
3302 redisplay_preserve_echo_area ();
3305 static EMACS_TIME timer_idleness_start_time
;
3307 /* Record the start of when Emacs is idle,
3308 for the sake of running idle-time timers. */
3315 /* If we are already in the idle state, do nothing. */
3316 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3319 EMACS_GET_TIME (timer_idleness_start_time
);
3321 /* Mark all idle-time timers as once again candidates for running. */
3322 for (timers
= Vtimer_idle_list
; CONSP (timers
); timers
= XCONS (timers
)->cdr
)
3326 timer
= XCONS (timers
)->car
;
3328 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3330 XVECTOR (timer
)->contents
[0] = Qnil
;
3334 /* Record that Emacs is no longer idle, so stop running idle-time timers. */
3339 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
3342 /* This is only for debugging. */
3343 struct input_event last_timer_event
;
3345 /* Check whether a timer has fired. To prevent larger problems we simply
3346 disregard elements that are not proper timers. Do not make a circular
3347 timer list for the time being.
3349 Returns the number of seconds to wait until the next timer fires. If a
3350 timer is triggering now, return zero seconds.
3351 If no timer is active, return -1 seconds.
3353 If a timer is ripe, we run it, with quitting turned off.
3355 DO_IT_NOW is now ignored. It used to mean that we should
3356 run the timer directly instead of queueing a timer-event.
3357 Now we always run timers directly. */
3360 timer_check (do_it_now
)
3363 EMACS_TIME nexttime
;
3364 EMACS_TIME now
, idleness_now
;
3365 Lisp_Object timers
, idle_timers
, chosen_timer
;
3366 struct gcpro gcpro1
, gcpro2
, gcpro3
;
3368 EMACS_SET_SECS (nexttime
, -1);
3369 EMACS_SET_USECS (nexttime
, -1);
3371 /* Always consider the ordinary timers. */
3372 timers
= Vtimer_list
;
3373 /* Consider the idle timers only if Emacs is idle. */
3374 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3375 idle_timers
= Vtimer_idle_list
;
3378 chosen_timer
= Qnil
;
3379 GCPRO3 (timers
, idle_timers
, chosen_timer
);
3381 if (CONSP (timers
) || CONSP (idle_timers
))
3383 EMACS_GET_TIME (now
);
3384 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3385 EMACS_SUB_TIME (idleness_now
, now
, timer_idleness_start_time
);
3388 while (CONSP (timers
) || CONSP (idle_timers
))
3390 int triggertime
= EMACS_SECS (now
);
3391 Lisp_Object
*vector
;
3392 Lisp_Object timer
, idle_timer
;
3393 EMACS_TIME timer_time
, idle_timer_time
;
3394 EMACS_TIME difference
, timer_difference
, idle_timer_difference
;
3396 /* Skip past invalid timers and timers already handled. */
3399 timer
= XCONS (timers
)->car
;
3400 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3402 timers
= XCONS (timers
)->cdr
;
3405 vector
= XVECTOR (timer
)->contents
;
3407 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
3408 || !INTEGERP (vector
[3])
3409 || ! NILP (vector
[0]))
3411 timers
= XCONS (timers
)->cdr
;
3415 if (!NILP (idle_timers
))
3417 timer
= XCONS (idle_timers
)->car
;
3418 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3420 idle_timers
= XCONS (idle_timers
)->cdr
;
3423 vector
= XVECTOR (timer
)->contents
;
3425 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
3426 || !INTEGERP (vector
[3])
3427 || ! NILP (vector
[0]))
3429 idle_timers
= XCONS (idle_timers
)->cdr
;
3434 /* Set TIMER, TIMER_TIME and TIMER_DIFFERENCE
3435 based on the next ordinary timer.
3436 TIMER_DIFFERENCE is the distance in time from NOW to when
3437 this timer becomes ripe (negative if it's already ripe). */
3440 timer
= XCONS (timers
)->car
;
3441 vector
= XVECTOR (timer
)->contents
;
3442 EMACS_SET_SECS (timer_time
,
3443 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
3444 EMACS_SET_USECS (timer_time
, XINT (vector
[3]));
3445 EMACS_SUB_TIME (timer_difference
, timer_time
, now
);
3448 /* Set IDLE_TIMER, IDLE_TIMER_TIME and IDLE_TIMER_DIFFERENCE
3449 based on the next idle timer. */
3450 if (!NILP (idle_timers
))
3452 idle_timer
= XCONS (idle_timers
)->car
;
3453 vector
= XVECTOR (idle_timer
)->contents
;
3454 EMACS_SET_SECS (idle_timer_time
,
3455 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
3456 EMACS_SET_USECS (idle_timer_time
, XINT (vector
[3]));
3457 EMACS_SUB_TIME (idle_timer_difference
, idle_timer_time
, idleness_now
);
3460 /* Decide which timer is the next timer,
3461 and set CHOSEN_TIMER, VECTOR and DIFFERENCE accordingly.
3462 Also step down the list where we found that timer. */
3464 if (! NILP (timers
) && ! NILP (idle_timers
))
3467 EMACS_SUB_TIME (temp
, timer_difference
, idle_timer_difference
);
3468 if (EMACS_TIME_NEG_P (temp
))
3470 chosen_timer
= timer
;
3471 timers
= XCONS (timers
)->cdr
;
3472 difference
= timer_difference
;
3476 chosen_timer
= idle_timer
;
3477 idle_timers
= XCONS (idle_timers
)->cdr
;
3478 difference
= idle_timer_difference
;
3481 else if (! NILP (timers
))
3483 chosen_timer
= timer
;
3484 timers
= XCONS (timers
)->cdr
;
3485 difference
= timer_difference
;
3489 chosen_timer
= idle_timer
;
3490 idle_timers
= XCONS (idle_timers
)->cdr
;
3491 difference
= idle_timer_difference
;
3493 vector
= XVECTOR (chosen_timer
)->contents
;
3495 /* If timer is rupe, run it if it hasn't been run. */
3496 if (EMACS_TIME_NEG_P (difference
)
3497 || (EMACS_SECS (difference
) == 0
3498 && EMACS_USECS (difference
) == 0))
3500 if (NILP (vector
[0]))
3503 int was_locked
= single_kboard
;
3504 int count
= specpdl_ptr
- specpdl
;
3505 #ifdef HAVE_WINDOW_SYSTEM
3506 int old_inhibit_busy_cursor
= inhibit_busy_cursor
;
3509 /* Mark the timer as triggered to prevent problems if the lisp
3510 code fails to reschedule it right. */
3513 specbind (Qinhibit_quit
, Qt
);
3515 #ifdef HAVE_WINDOW_SYSTEM
3516 inhibit_busy_cursor
= 2;
3519 call1 (Qtimer_event_handler
, chosen_timer
);
3522 #ifdef HAVE_WINDOW_SYSTEM
3523 inhibit_busy_cursor
= old_inhibit_busy_cursor
;
3526 unbind_to (count
, Qnil
);
3528 /* Resume allowing input from any kboard, if that was true before. */
3530 any_kboard_state ();
3532 /* Since we have handled the event,
3533 we don't need to tell the caller to wake up and do it. */
3537 /* When we encounter a timer that is still waiting,
3538 return the amount of time to wait before it is ripe. */
3545 /* No timers are pending in the future. */
3546 /* Return 0 if we generated an event, and -1 if not. */
3551 /* Caches for modify_event_symbol. */
3552 static Lisp_Object accent_key_syms
;
3553 static Lisp_Object func_key_syms
;
3554 static Lisp_Object mouse_syms
;
3556 static Lisp_Object mouse_wheel_syms
;
3558 static Lisp_Object drag_n_drop_syms
;
3560 /* This is a list of keysym codes for special "accent" characters.
3561 It parallels lispy_accent_keys. */
3563 static int lispy_accent_codes
[] =
3565 #ifdef XK_dead_circumflex
3570 #ifdef XK_dead_grave
3575 #ifdef XK_dead_tilde
3580 #ifdef XK_dead_diaeresis
3585 #ifdef XK_dead_macron
3590 #ifdef XK_dead_degree
3595 #ifdef XK_dead_acute
3600 #ifdef XK_dead_cedilla
3605 #ifdef XK_dead_breve
3610 #ifdef XK_dead_ogonek
3615 #ifdef XK_dead_caron
3620 #ifdef XK_dead_doubleacute
3621 XK_dead_doubleacute
,
3625 #ifdef XK_dead_abovedot
3632 /* This is a list of Lisp names for special "accent" characters.
3633 It parallels lispy_accent_codes. */
3635 static char *lispy_accent_keys
[] =
3653 #define FUNCTION_KEY_OFFSET 0x0
3655 char *lispy_function_keys
[] =
3659 0, /* VK_LBUTTON 0x01 */
3660 0, /* VK_RBUTTON 0x02 */
3661 "cancel", /* VK_CANCEL 0x03 */
3662 0, /* VK_MBUTTON 0x04 */
3664 0, 0, 0, /* 0x05 .. 0x07 */
3666 "backspace", /* VK_BACK 0x08 */
3667 "tab", /* VK_TAB 0x09 */
3669 0, 0, /* 0x0A .. 0x0B */
3671 "clear", /* VK_CLEAR 0x0C */
3672 "return", /* VK_RETURN 0x0D */
3674 0, 0, /* 0x0E .. 0x0F */
3676 0, /* VK_SHIFT 0x10 */
3677 0, /* VK_CONTROL 0x11 */
3678 0, /* VK_MENU 0x12 */
3679 "pause", /* VK_PAUSE 0x13 */
3680 "capslock", /* VK_CAPITAL 0x14 */
3682 0, 0, 0, 0, 0, 0, /* 0x15 .. 0x1A */
3684 "escape", /* VK_ESCAPE 0x1B */
3686 0, 0, 0, 0, /* 0x1C .. 0x1F */
3688 0, /* VK_SPACE 0x20 */
3689 "prior", /* VK_PRIOR 0x21 */
3690 "next", /* VK_NEXT 0x22 */
3691 "end", /* VK_END 0x23 */
3692 "home", /* VK_HOME 0x24 */
3693 "left", /* VK_LEFT 0x25 */
3694 "up", /* VK_UP 0x26 */
3695 "right", /* VK_RIGHT 0x27 */
3696 "down", /* VK_DOWN 0x28 */
3697 "select", /* VK_SELECT 0x29 */
3698 "print", /* VK_PRINT 0x2A */
3699 "execute", /* VK_EXECUTE 0x2B */
3700 "snapshot", /* VK_SNAPSHOT 0x2C */
3701 "insert", /* VK_INSERT 0x2D */
3702 "delete", /* VK_DELETE 0x2E */
3703 "help", /* VK_HELP 0x2F */
3705 /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
3707 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3709 0, 0, 0, 0, 0, 0, 0, /* 0x3A .. 0x40 */
3711 /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
3713 0, 0, 0, 0, 0, 0, 0, 0, 0,
3714 0, 0, 0, 0, 0, 0, 0, 0, 0,
3715 0, 0, 0, 0, 0, 0, 0, 0,
3717 "lwindow", /* VK_LWIN 0x5B */
3718 "rwindow", /* VK_RWIN 0x5C */
3719 "apps", /* VK_APPS 0x5D */
3721 0, 0, /* 0x5E .. 0x5F */
3723 "kp-0", /* VK_NUMPAD0 0x60 */
3724 "kp-1", /* VK_NUMPAD1 0x61 */
3725 "kp-2", /* VK_NUMPAD2 0x62 */
3726 "kp-3", /* VK_NUMPAD3 0x63 */
3727 "kp-4", /* VK_NUMPAD4 0x64 */
3728 "kp-5", /* VK_NUMPAD5 0x65 */
3729 "kp-6", /* VK_NUMPAD6 0x66 */
3730 "kp-7", /* VK_NUMPAD7 0x67 */
3731 "kp-8", /* VK_NUMPAD8 0x68 */
3732 "kp-9", /* VK_NUMPAD9 0x69 */
3733 "kp-multiply", /* VK_MULTIPLY 0x6A */
3734 "kp-add", /* VK_ADD 0x6B */
3735 "kp-separator", /* VK_SEPARATOR 0x6C */
3736 "kp-subtract", /* VK_SUBTRACT 0x6D */
3737 "kp-decimal", /* VK_DECIMAL 0x6E */
3738 "kp-divide", /* VK_DIVIDE 0x6F */
3739 "f1", /* VK_F1 0x70 */
3740 "f2", /* VK_F2 0x71 */
3741 "f3", /* VK_F3 0x72 */
3742 "f4", /* VK_F4 0x73 */
3743 "f5", /* VK_F5 0x74 */
3744 "f6", /* VK_F6 0x75 */
3745 "f7", /* VK_F7 0x76 */
3746 "f8", /* VK_F8 0x77 */
3747 "f9", /* VK_F9 0x78 */
3748 "f10", /* VK_F10 0x79 */
3749 "f11", /* VK_F11 0x7A */
3750 "f12", /* VK_F12 0x7B */
3751 "f13", /* VK_F13 0x7C */
3752 "f14", /* VK_F14 0x7D */
3753 "f15", /* VK_F15 0x7E */
3754 "f16", /* VK_F16 0x7F */
3755 "f17", /* VK_F17 0x80 */
3756 "f18", /* VK_F18 0x81 */
3757 "f19", /* VK_F19 0x82 */
3758 "f20", /* VK_F20 0x83 */
3759 "f21", /* VK_F21 0x84 */
3760 "f22", /* VK_F22 0x85 */
3761 "f23", /* VK_F23 0x86 */
3762 "f24", /* VK_F24 0x87 */
3764 0, 0, 0, 0, /* 0x88 .. 0x8B */
3765 0, 0, 0, 0, /* 0x8C .. 0x8F */
3767 "kp-numlock", /* VK_NUMLOCK 0x90 */
3768 "scroll", /* VK_SCROLL 0x91 */
3770 "kp-space", /* VK_NUMPAD_CLEAR 0x92 */
3771 "kp-enter", /* VK_NUMPAD_ENTER 0x93 */
3772 "kp-prior", /* VK_NUMPAD_PRIOR 0x94 */
3773 "kp-next", /* VK_NUMPAD_NEXT 0x95 */
3774 "kp-end", /* VK_NUMPAD_END 0x96 */
3775 "kp-home", /* VK_NUMPAD_HOME 0x97 */
3776 "kp-left", /* VK_NUMPAD_LEFT 0x98 */
3777 "kp-up", /* VK_NUMPAD_UP 0x99 */
3778 "kp-right", /* VK_NUMPAD_RIGHT 0x9A */
3779 "kp-down", /* VK_NUMPAD_DOWN 0x9B */
3780 "kp-insert", /* VK_NUMPAD_INSERT 0x9C */
3781 "kp-delete", /* VK_NUMPAD_DELETE 0x9D */
3783 0, 0, /* 0x9E .. 0x9F */
3786 * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
3787 * Used only as parameters to GetAsyncKeyState and GetKeyState.
3788 * No other API or message will distinguish left and right keys this way.
3792 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3793 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3794 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3795 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3796 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3802 "attn", /* VK_ATTN 0xF6 */
3803 "crsel", /* VK_CRSEL 0xF7 */
3804 "exsel", /* VK_EXSEL 0xF8 */
3805 "ereof", /* VK_EREOF 0xF9 */
3806 "play", /* VK_PLAY 0xFA */
3807 "zoom", /* VK_ZOOM 0xFB */
3808 "noname", /* VK_NONAME 0xFC */
3809 "pa1", /* VK_PA1 0xFD */
3810 "oem_clear", /* VK_OEM_CLEAR 0xFE */
3814 #else /* not HAVE_NTGUI */
3817 static char *lispy_kana_keys
[] =
3819 /* X Keysym value */
3820 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x400 .. 0x40f */
3821 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x410 .. 0x41f */
3822 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x420 .. 0x42f */
3823 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x430 .. 0x43f */
3824 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x440 .. 0x44f */
3825 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x450 .. 0x45f */
3826 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x460 .. 0x46f */
3827 0,0,0,0,0,0,0,0,0,0,0,0,0,0,"overline",0,
3828 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x480 .. 0x48f */
3829 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x490 .. 0x49f */
3830 0, "kana-fullstop", "kana-openingbracket", "kana-closingbracket",
3831 "kana-comma", "kana-conjunctive", "kana-WO", "kana-a",
3832 "kana-i", "kana-u", "kana-e", "kana-o",
3833 "kana-ya", "kana-yu", "kana-yo", "kana-tsu",
3834 "prolongedsound", "kana-A", "kana-I", "kana-U",
3835 "kana-E", "kana-O", "kana-KA", "kana-KI",
3836 "kana-KU", "kana-KE", "kana-KO", "kana-SA",
3837 "kana-SHI", "kana-SU", "kana-SE", "kana-SO",
3838 "kana-TA", "kana-CHI", "kana-TSU", "kana-TE",
3839 "kana-TO", "kana-NA", "kana-NI", "kana-NU",
3840 "kana-NE", "kana-NO", "kana-HA", "kana-HI",
3841 "kana-FU", "kana-HE", "kana-HO", "kana-MA",
3842 "kana-MI", "kana-MU", "kana-ME", "kana-MO",
3843 "kana-YA", "kana-YU", "kana-YO", "kana-RA",
3844 "kana-RI", "kana-RU", "kana-RE", "kana-RO",
3845 "kana-WA", "kana-N", "voicedsound", "semivoicedsound",
3846 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4e0 .. 0x4ef */
3847 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4f0 .. 0x4ff */
3849 #endif /* XK_kana_A */
3851 #define FUNCTION_KEY_OFFSET 0xff00
3853 /* You'll notice that this table is arranged to be conveniently
3854 indexed by X Windows keysym values. */
3855 static char *lispy_function_keys
[] =
3857 /* X Keysym value */
3859 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00...0f */
3860 "backspace", "tab", "linefeed", "clear",
3862 0, 0, 0, "pause", /* 0xff10...1f */
3863 0, 0, 0, 0, 0, 0, 0, "escape",
3865 0, "kanji", "muhenkan", "henkan", /* 0xff20...2f */
3866 "romaji", "hiragana", "katakana", "hiragana-katakana",
3867 "zenkaku", "hankaku", "zenkaku-hankaku", "touroku",
3868 "massyo", "kana-lock", "kana-shift", "eisu-shift",
3869 "eisu-toggle", /* 0xff30...3f */
3870 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3871 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
3873 "home", "left", "up", "right", /* 0xff50 */ /* IsCursorKey */
3874 "down", "prior", "next", "end",
3875 "begin", 0, 0, 0, 0, 0, 0, 0,
3876 "select", /* 0xff60 */ /* IsMiscFunctionKey */
3887 "break", /* 0xff6b */
3890 0, 0, 0, 0, "backtab", 0, 0, 0, /* 0xff70... */
3891 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff78... */
3892 "kp-space", /* 0xff80 */ /* IsKeypadKey */
3893 0, 0, 0, 0, 0, 0, 0, 0,
3894 "kp-tab", /* 0xff89 */
3896 "kp-enter", /* 0xff8d */
3898 "kp-f1", /* 0xff91 */
3902 "kp-home", /* 0xff95 */
3907 "kp-prior", /* kp-page-up */
3908 "kp-next", /* kp-page-down */
3914 0, 0, 0, 0, 0, 0, 0, 0, 0,
3915 "kp-multiply", /* 0xffaa */
3920 "kp-divide", /* 0xffaf */
3921 "kp-0", /* 0xffb0 */
3922 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
3925 "kp-equal", /* 0xffbd */
3926 "f1", /* 0xffbe */ /* IsFunctionKey */
3928 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
3929 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
3930 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
3931 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
3932 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
3933 0, 0, 0, 0, 0, 0, 0, 0,
3934 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
3935 0, 0, 0, 0, 0, 0, 0, "delete"
3938 /* ISO 9995 Function and Modifier Keys; the first byte is 0xFE. */
3939 #define ISO_FUNCTION_KEY_OFFSET 0xfe00
3941 static char *iso_lispy_function_keys
[] =
3943 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe00 */
3944 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe08 */
3945 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe10 */
3946 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe18 */
3947 "iso-lefttab", /* 0xfe20 */
3948 "iso-move-line-up", "iso-move-line-down",
3949 "iso-partial-line-up", "iso-partial-line-down",
3950 "iso-partial-space-left", "iso-partial-space-right",
3951 "iso-set-margin-left", "iso-set-margin-right", /* 0xffe27, 28 */
3952 "iso-release-margin-left", "iso-release-margin-right",
3953 "iso-release-both-margins",
3954 "iso-fast-cursor-left", "iso-fast-cursor-right",
3955 "iso-fast-cursor-up", "iso-fast-cursor-down",
3956 "iso-continuous-underline", "iso-discontinuous-underline", /* 0xfe30, 31 */
3957 "iso-emphasize", "iso-center-object", "iso-enter", /* ... 0xfe34 */
3960 #endif /* not HAVE_NTGUI */
3962 static char *lispy_mouse_names
[] =
3964 "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5"
3968 /* mouse-wheel events are generated by the wheel on devices such as
3969 the MS Intellimouse. The wheel sits in between the left and right
3970 mouse buttons, and is typically used to scroll or zoom the window
3971 underneath the pointer. mouse-wheel events specify the object on
3972 which they operate, and a delta corresponding to the amount and
3973 direction that the wheel is rotated. Clicking the mouse-wheel
3974 generates a mouse-2 event. */
3975 static char *lispy_mouse_wheel_names
[] =
3980 #endif /* WINDOWSNT */
3982 /* drag-n-drop events are generated when a set of selected files are
3983 dragged from another application and dropped onto an Emacs window. */
3984 static char *lispy_drag_n_drop_names
[] =
3989 /* Scroll bar parts. */
3990 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
3991 Lisp_Object Qup
, Qdown
, Qbottom
, Qend_scroll
;
3994 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
3995 Lisp_Object
*scroll_bar_parts
[] = {
3996 &Qabove_handle
, &Qhandle
, &Qbelow_handle
,
3997 &Qup
, &Qdown
, &Qtop
, &Qbottom
, &Qend_scroll
4000 /* User signal events. */
4001 Lisp_Object Qusr1_signal
, Qusr2_signal
;
4003 Lisp_Object
*lispy_user_signals
[] =
4005 &Qusr1_signal
, &Qusr2_signal
4009 /* A vector, indexed by button number, giving the down-going location
4010 of currently depressed buttons, both scroll bar and non-scroll bar.
4012 The elements have the form
4013 (BUTTON-NUMBER MODIFIER-MASK . REST)
4014 where REST is the cdr of a position as it would be reported in the event.
4016 The make_lispy_event function stores positions here to tell the
4017 difference between click and drag events, and to store the starting
4018 location to be included in drag events. */
4020 static Lisp_Object button_down_location
;
4022 /* Information about the most recent up-going button event: Which
4023 button, what location, and what time. */
4025 static int last_mouse_button
;
4026 static int last_mouse_x
;
4027 static int last_mouse_y
;
4028 static unsigned long button_down_time
;
4030 /* The maximum time between clicks to make a double-click,
4031 or Qnil to disable double-click detection,
4032 or Qt for no time limit. */
4033 Lisp_Object Vdouble_click_time
;
4035 /* The number of clicks in this multiple-click. */
4037 int double_click_count
;
4039 /* Given a struct input_event, build the lisp event which represents
4040 it. If EVENT is 0, build a mouse movement event from the mouse
4041 movement buffer, which should have a movement event in it.
4043 Note that events must be passed to this function in the order they
4044 are received; this function stores the location of button presses
4045 in order to build drag events when the button is released. */
4048 make_lispy_event (event
)
4049 struct input_event
*event
;
4053 switch (SWITCH_ENUM_CAST (event
->kind
))
4055 /* A simple keystroke. */
4056 case ascii_keystroke
:
4058 Lisp_Object lispy_c
;
4059 int c
= event
->code
& 0377;
4060 /* Turn ASCII characters into control characters
4062 if (event
->modifiers
& ctrl_modifier
)
4063 c
= make_ctrl_char (c
);
4065 /* Add in the other modifier bits. We took care of ctrl_modifier
4066 just above, and the shift key was taken care of by the X code,
4067 and applied to control characters by make_ctrl_char. */
4068 c
|= (event
->modifiers
4069 & (meta_modifier
| alt_modifier
4070 | hyper_modifier
| super_modifier
));
4071 /* Distinguish Shift-SPC from SPC. */
4072 if ((event
->code
& 0377) == 040
4073 && event
->modifiers
& shift_modifier
)
4074 c
|= shift_modifier
;
4075 button_down_time
= 0;
4076 XSETFASTINT (lispy_c
, c
);
4080 /* A function key. The symbol may need to have modifier prefixes
4082 case non_ascii_keystroke
:
4083 button_down_time
= 0;
4085 for (i
= 0; i
< sizeof (lispy_accent_codes
) / sizeof (int); i
++)
4086 if (event
->code
== lispy_accent_codes
[i
])
4087 return modify_event_symbol (i
,
4089 Qfunction_key
, Qnil
,
4090 lispy_accent_keys
, &accent_key_syms
,
4091 (sizeof (lispy_accent_keys
)
4092 / sizeof (lispy_accent_keys
[0])));
4094 /* Handle system-specific keysyms. */
4095 if (event
->code
& (1 << 28))
4097 /* We need to use an alist rather than a vector as the cache
4098 since we can't make a vector long enuf. */
4099 if (NILP (current_kboard
->system_key_syms
))
4100 current_kboard
->system_key_syms
= Fcons (Qnil
, Qnil
);
4101 return modify_event_symbol (event
->code
,
4104 current_kboard
->Vsystem_key_alist
,
4105 0, ¤t_kboard
->system_key_syms
,
4110 if (event
->code
>= 0x400 && event
->code
< 0x500)
4111 return modify_event_symbol (event
->code
- 0x400,
4112 event
->modifiers
& ~shift_modifier
,
4113 Qfunction_key
, Qnil
,
4114 lispy_kana_keys
, &func_key_syms
,
4115 (sizeof (lispy_kana_keys
)
4116 / sizeof (lispy_kana_keys
[0])));
4117 #endif /* XK_kana_A */
4119 #ifdef ISO_FUNCTION_KEY_OFFSET
4120 if (event
->code
< FUNCTION_KEY_OFFSET
4121 && event
->code
>= ISO_FUNCTION_KEY_OFFSET
)
4122 return modify_event_symbol (event
->code
- ISO_FUNCTION_KEY_OFFSET
,
4124 Qfunction_key
, Qnil
,
4125 iso_lispy_function_keys
, &func_key_syms
,
4126 (sizeof (iso_lispy_function_keys
)
4127 / sizeof (iso_lispy_function_keys
[0])));
4130 return modify_event_symbol (event
->code
- FUNCTION_KEY_OFFSET
,
4132 Qfunction_key
, Qnil
,
4133 lispy_function_keys
, &func_key_syms
,
4134 (sizeof (lispy_function_keys
)
4135 / sizeof (lispy_function_keys
[0])));
4138 /* A mouse click. Figure out where it is, decide whether it's
4139 a press, click or drag, and build the appropriate structure. */
4141 #ifndef USE_TOOLKIT_SCROLL_BARS
4142 case scroll_bar_click
:
4145 int button
= event
->code
;
4147 Lisp_Object position
;
4148 Lisp_Object
*start_pos_ptr
;
4149 Lisp_Object start_pos
;
4151 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
4154 /* Build the position as appropriate for this mouse click. */
4155 if (event
->kind
== mouse_click
)
4158 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
4161 Lisp_Object string_info
= Qnil
;
4164 /* Ignore mouse events that were made on frame that
4165 have been deleted. */
4166 if (! FRAME_LIVE_P (f
))
4169 /* EVENT->x and EVENT->y are frame-relative pixel
4170 coordinates at this place. Under old redisplay, COLUMN
4171 and ROW are set to frame relative glyph coordinates
4172 which are then used to determine whether this click is
4173 in a menu (non-toolkit version). */
4174 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4175 &column
, &row
, NULL
, 1);
4177 #ifndef USE_X_TOOLKIT
4178 /* In the non-toolkit version, clicks on the menu bar
4179 are ordinary button events in the event buffer.
4180 Distinguish them, and invoke the menu.
4182 (In the toolkit version, the toolkit handles the menu bar
4183 and Emacs doesn't know about it until after the user
4184 makes a selection.) */
4185 if (row
>= 0 && row
< FRAME_MENU_BAR_LINES (f
)
4186 && (event
->modifiers
& down_modifier
))
4188 Lisp_Object items
, item
;
4193 /* Activate the menu bar on the down event. If the
4194 up event comes in before the menu code can deal with it,
4196 if (! (event
->modifiers
& down_modifier
))
4200 /* Find the menu bar item under `column'. */
4202 items
= FRAME_MENU_BAR_ITEMS (f
);
4203 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
4205 Lisp_Object pos
, string
;
4206 string
= XVECTOR (items
)->contents
[i
+ 1];
4207 pos
= XVECTOR (items
)->contents
[i
+ 3];
4210 if (column
>= XINT (pos
)
4211 && column
< XINT (pos
) + XSTRING (string
)->size
)
4213 item
= XVECTOR (items
)->contents
[i
];
4218 /* ELisp manual 2.4b says (x y) are window relative but
4219 code says they are frame-relative. */
4221 = Fcons (event
->frame_or_window
,
4223 Fcons (Fcons (event
->x
, event
->y
),
4224 Fcons (make_number (event
->timestamp
),
4227 return Fcons (item
, Fcons (position
, Qnil
));
4229 #endif /* not USE_X_TOOLKIT */
4231 /* Set `window' to the window under frame pixel coordinates
4232 event->x/event->y. */
4233 window
= window_from_coordinates (f
, XINT (event
->x
),
4234 XINT (event
->y
), &part
, 0);
4236 if (!WINDOWP (window
))
4238 window
= event
->frame_or_window
;
4243 /* It's a click in window window at frame coordinates
4244 event->x/ event->y. */
4245 struct window
*w
= XWINDOW (window
);
4247 /* Get window relative coordinates. Original code
4248 `rounded' this to glyph boundaries. */
4249 int wx
= FRAME_TO_WINDOW_PIXEL_X (w
, XINT (event
->x
));
4250 int wy
= FRAME_TO_WINDOW_PIXEL_Y (w
, XINT (event
->y
));
4252 /* Set event coordinates to window-relative coordinates
4253 for constructing the Lisp event below. */
4254 XSETINT (event
->x
, wx
);
4255 XSETINT (event
->y
, wy
);
4257 if (part
== 1 || part
== 3)
4259 /* Mode line or top line. Look for a string under
4260 the mouse that may have a `local-map' property. */
4264 posn
= part
== 1 ? Qmode_line
: Qtop_line
;
4265 string
= mode_line_string (w
, wx
, wy
, part
== 1, &charpos
);
4266 if (STRINGP (string
))
4267 string_info
= Fcons (string
, make_number (charpos
));
4270 posn
= Qvertical_line
;
4272 XSETINT (posn
, buffer_posn_from_coords (w
, &wx
, &wy
));
4278 Fcons (Fcons (event
->x
, event
->y
),
4279 Fcons (make_number (event
->timestamp
),
4282 : Fcons (string_info
, Qnil
))))));
4284 #ifndef USE_TOOLKIT_SCROLL_BARS
4287 /* It's a scrollbar click. */
4289 Lisp_Object portion_whole
;
4292 window
= event
->frame_or_window
;
4293 portion_whole
= Fcons (event
->x
, event
->y
);
4294 part
= *scroll_bar_parts
[(int) event
->part
];
4298 Fcons (Qvertical_scroll_bar
,
4299 Fcons (portion_whole
,
4300 Fcons (make_number (event
->timestamp
),
4301 Fcons (part
, Qnil
)))));
4303 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4305 start_pos_ptr
= &XVECTOR (button_down_location
)->contents
[button
];
4307 start_pos
= *start_pos_ptr
;
4308 *start_pos_ptr
= Qnil
;
4310 is_double
= (button
== last_mouse_button
4311 && XINT (event
->x
) == last_mouse_x
4312 && XINT (event
->y
) == last_mouse_y
4313 && button_down_time
!= 0
4314 && (EQ (Vdouble_click_time
, Qt
)
4315 || (INTEGERP (Vdouble_click_time
)
4316 && ((int)(event
->timestamp
- button_down_time
)
4317 < XINT (Vdouble_click_time
)))));
4318 last_mouse_button
= button
;
4319 last_mouse_x
= XINT (event
->x
);
4320 last_mouse_y
= XINT (event
->y
);
4322 /* If this is a button press, squirrel away the location, so
4323 we can decide later whether it was a click or a drag. */
4324 if (event
->modifiers
& down_modifier
)
4328 double_click_count
++;
4329 event
->modifiers
|= ((double_click_count
> 2)
4334 double_click_count
= 1;
4335 button_down_time
= event
->timestamp
;
4336 *start_pos_ptr
= Fcopy_alist (position
);
4339 /* Now we're releasing a button - check the co-ordinates to
4340 see if this was a click or a drag. */
4341 else if (event
->modifiers
& up_modifier
)
4343 /* If we did not see a down before this up,
4344 ignore the up. Probably this happened because
4345 the down event chose a menu item.
4346 It would be an annoyance to treat the release
4347 of the button that chose the menu item
4348 as a separate event. */
4350 if (!CONSP (start_pos
))
4353 event
->modifiers
&= ~up_modifier
;
4354 #if 0 /* Formerly we treated an up with no down as a click event. */
4355 if (!CONSP (start_pos
))
4356 event
->modifiers
|= click_modifier
;
4360 /* The third element of every position should be the (x,y)
4364 down
= Fnth (make_number (2), start_pos
);
4365 if (EQ (event
->x
, XCONS (down
)->car
)
4366 && EQ (event
->y
, XCONS (down
)->cdr
))
4368 event
->modifiers
|= click_modifier
;
4372 button_down_time
= 0;
4373 event
->modifiers
|= drag_modifier
;
4375 /* Don't check is_double; treat this as multiple
4376 if the down-event was multiple. */
4377 if (double_click_count
> 1)
4378 event
->modifiers
|= ((double_click_count
> 2)
4384 /* Every mouse event should either have the down_modifier or
4385 the up_modifier set. */
4389 /* Get the symbol we should use for the mouse click. */
4392 head
= modify_event_symbol (button
,
4395 lispy_mouse_names
, &mouse_syms
,
4396 (sizeof (lispy_mouse_names
)
4397 / sizeof (lispy_mouse_names
[0])));
4398 if (event
->modifiers
& drag_modifier
)
4403 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
4406 Fcons (make_number (double_click_count
),
4415 #if USE_TOOLKIT_SCROLL_BARS
4417 /* We don't have down and up events if using toolkit scroll bars,
4418 so make this always a click event. Store in the `part' of
4419 the Lisp event a symbol which maps to the following actions:
4421 `above_handle' page up
4422 `below_handle' page down
4426 `bottom' bottom of buffer
4427 `handle' thumb has been dragged.
4428 `end-scroll' end of interaction with scroll bar
4430 The incoming input_event contains in its `part' member an
4431 index of type `enum scroll_bar_part' which we can use as an
4432 index in scroll_bar_parts to get the appropriate symbol. */
4434 case scroll_bar_click
:
4436 Lisp_Object position
, head
, window
, portion_whole
, part
;
4438 window
= event
->frame_or_window
;
4439 portion_whole
= Fcons (event
->x
, event
->y
);
4440 part
= *scroll_bar_parts
[(int) event
->part
];
4444 Fcons (Qvertical_scroll_bar
,
4445 Fcons (portion_whole
,
4446 Fcons (make_number (event
->timestamp
),
4447 Fcons (part
, Qnil
)))));
4449 /* Always treat scroll bar events as clicks. */
4450 event
->modifiers
|= click_modifier
;
4452 /* Get the symbol we should use for the mouse click. */
4453 head
= modify_event_symbol (event
->code
,
4456 lispy_mouse_names
, &mouse_syms
,
4457 (sizeof (lispy_mouse_names
)
4458 / sizeof (lispy_mouse_names
[0])));
4459 return Fcons (head
, Fcons (position
, Qnil
));
4462 #endif /* USE_TOOLKIT_SCROLL_BARS */
4465 case w32_scroll_bar_click
:
4467 int button
= event
->code
;
4469 Lisp_Object position
;
4470 Lisp_Object
*start_pos_ptr
;
4471 Lisp_Object start_pos
;
4473 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
4478 Lisp_Object portion_whole
;
4481 window
= event
->frame_or_window
;
4482 portion_whole
= Fcons (event
->x
, event
->y
);
4483 part
= *scroll_bar_parts
[(int) event
->part
];
4487 Fcons (Qvertical_scroll_bar
,
4488 Fcons (portion_whole
,
4489 Fcons (make_number (event
->timestamp
),
4490 Fcons (part
, Qnil
)))));
4493 /* Always treat W32 scroll bar events as clicks. */
4494 event
->modifiers
|= click_modifier
;
4497 /* Get the symbol we should use for the mouse click. */
4500 head
= modify_event_symbol (button
,
4503 lispy_mouse_names
, &mouse_syms
,
4504 (sizeof (lispy_mouse_names
)
4505 / sizeof (lispy_mouse_names
[0])));
4514 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
4517 Lisp_Object head
, position
;
4520 /* Ignore mouse events that were made on frame that
4521 have been deleted. */
4522 if (! FRAME_LIVE_P (f
))
4524 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4525 &column
, &row
, NULL
, 1);
4526 window
= window_from_coordinates (f
, column
, row
, &part
, 0);
4528 if (!WINDOWP (window
))
4530 window
= event
->frame_or_window
;
4535 int pixcolumn
, pixrow
;
4536 column
-= XINT (XWINDOW (window
)->left
);
4537 row
-= XINT (XWINDOW (window
)->top
);
4538 glyph_to_pixel_coords (f
, column
, row
, &pixcolumn
, &pixrow
);
4539 XSETINT (event
->x
, pixcolumn
);
4540 XSETINT (event
->y
, pixrow
);
4545 posn
= Qvertical_line
;
4550 buffer_posn_from_coords (XWINDOW (window
),
4555 Lisp_Object head
, position
;
4560 Fcons (Fcons (event
->x
, event
->y
),
4561 Fcons (make_number (event
->timestamp
),
4564 head
= modify_event_symbol (0, event
->modifiers
,
4566 lispy_mouse_wheel_names
,
4567 &mouse_wheel_syms
, 1);
4570 Fcons (make_number (event
->code
),
4574 #endif /* WINDOWSNT */
4582 Lisp_Object head
, position
;
4586 /* The frame_or_window field should be a cons of the frame in
4587 which the event occurred and a list of the filenames
4589 if (! CONSP (event
->frame_or_window
))
4592 f
= XFRAME (XCONS (event
->frame_or_window
)->car
);
4593 files
= XCONS (event
->frame_or_window
)->cdr
;
4595 /* Ignore mouse events that were made on frames that
4596 have been deleted. */
4597 if (! FRAME_LIVE_P (f
))
4599 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4600 &column
, &row
, NULL
, 1);
4601 window
= window_from_coordinates (f
, column
, row
, &part
, 0);
4603 if (!WINDOWP (window
))
4605 window
= XCONS (event
->frame_or_window
)->car
;
4610 /* It's an event in window `window' at frame coordinates
4611 event->x/ event->y. */
4612 struct window
*w
= XWINDOW (window
);
4614 /* Get window relative coordinates. */
4615 int wx
= FRAME_TO_WINDOW_PIXEL_X (w
, XINT (event
->x
));
4616 int wy
= FRAME_TO_WINDOW_PIXEL_Y (w
, XINT (event
->y
));
4618 /* Set event coordinates to window-relative coordinates
4619 for constructing the Lisp event below. */
4620 XSETINT (event
->x
, wx
);
4621 XSETINT (event
->y
, wy
);
4626 posn
= Qvertical_line
;
4630 XSETINT (posn
, buffer_posn_from_coords (w
, &wx
, &wy
));
4634 Lisp_Object head
, position
;
4639 Fcons (Fcons (event
->x
, event
->y
),
4640 Fcons (make_number (event
->timestamp
),
4643 head
= modify_event_symbol (0, event
->modifiers
,
4645 lispy_drag_n_drop_names
,
4646 &drag_n_drop_syms
, 1);
4653 #endif /* HAVE_MOUSE */
4655 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
4656 case menu_bar_event
:
4657 /* The event value is in the cdr of the frame_or_window slot. */
4658 if (!CONSP (event
->frame_or_window
))
4660 return XCONS (event
->frame_or_window
)->cdr
;
4666 if (!CONSP (event
->frame_or_window
))
4668 key
= XCDR (event
->frame_or_window
);
4670 key
= apply_modifiers (event
->modifiers
, key
);
4675 /* A user signal. */
4676 return *lispy_user_signals
[event
->code
];
4678 /* The 'kind' field of the event is something we don't recognize. */
4687 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
4689 Lisp_Object bar_window
;
4690 enum scroll_bar_part part
;
4694 /* Is it a scroll bar movement? */
4695 if (frame
&& ! NILP (bar_window
))
4697 Lisp_Object part_sym
;
4699 part_sym
= *scroll_bar_parts
[(int) part
];
4700 return Fcons (Qscroll_bar_movement
,
4701 (Fcons (Fcons (bar_window
,
4702 Fcons (Qvertical_scroll_bar
,
4703 Fcons (Fcons (x
, y
),
4704 Fcons (make_number (time
),
4710 /* Or is it an ordinary mouse movement? */
4718 /* It's in a frame; which window on that frame? */
4719 window
= window_from_coordinates (frame
, XINT (x
), XINT (y
), &area
, 0);
4723 if (WINDOWP (window
))
4725 struct window
*w
= XWINDOW (window
);
4730 /* Get window relative coordinates. */
4731 wx
= FRAME_TO_WINDOW_PIXEL_X (w
, XINT (x
));
4732 wy
= FRAME_TO_WINDOW_PIXEL_Y (w
, XINT (y
));
4739 posn
= Qvertical_line
;
4743 XSETINT (posn
, buffer_posn_from_coords (w
, &wx
, &wy
));
4745 else if (frame
!= 0)
4747 XSETFRAME (window
, frame
);
4758 return Fcons (Qmouse_movement
,
4759 Fcons (Fcons (window
,
4761 Fcons (Fcons (x
, y
),
4762 Fcons (make_number (time
),
4768 #endif /* HAVE_MOUSE */
4770 /* Construct a switch frame event. */
4772 make_lispy_switch_frame (frame
)
4775 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
4778 /* Manipulating modifiers. */
4780 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
4782 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
4783 SYMBOL's name of the end of the modifiers; the string from this
4784 position is the unmodified symbol name.
4786 This doesn't use any caches. */
4789 parse_modifiers_uncached (symbol
, modifier_end
)
4793 struct Lisp_String
*name
;
4797 CHECK_SYMBOL (symbol
, 1);
4800 name
= XSYMBOL (symbol
)->name
;
4802 for (i
= 0; i
+2 <= STRING_BYTES (name
); )
4804 int this_mod_end
= 0;
4807 /* See if the name continues with a modifier word.
4808 Check that the word appears, but don't check what follows it.
4809 Set this_mod and this_mod_end to record what we find. */
4811 switch (name
->data
[i
])
4813 #define SINGLE_LETTER_MOD(BIT) \
4814 (this_mod_end = i + 1, this_mod = BIT)
4817 SINGLE_LETTER_MOD (alt_modifier
);
4821 SINGLE_LETTER_MOD (ctrl_modifier
);
4825 SINGLE_LETTER_MOD (hyper_modifier
);
4829 SINGLE_LETTER_MOD (meta_modifier
);
4833 SINGLE_LETTER_MOD (shift_modifier
);
4837 SINGLE_LETTER_MOD (super_modifier
);
4840 #undef SINGLE_LETTER_MOD
4843 /* If we found no modifier, stop looking for them. */
4844 if (this_mod_end
== 0)
4847 /* Check there is a dash after the modifier, so that it
4848 really is a modifier. */
4849 if (this_mod_end
>= STRING_BYTES (name
)
4850 || name
->data
[this_mod_end
] != '-')
4853 /* This modifier is real; look for another. */
4854 modifiers
|= this_mod
;
4855 i
= this_mod_end
+ 1;
4858 /* Should we include the `click' modifier? */
4859 if (! (modifiers
& (down_modifier
| drag_modifier
4860 | double_modifier
| triple_modifier
))
4861 && i
+ 7 == STRING_BYTES (name
)
4862 && strncmp (name
->data
+ i
, "mouse-", 6) == 0
4863 && ('0' <= name
->data
[i
+ 6] && name
->data
[i
+ 6] <= '9'))
4864 modifiers
|= click_modifier
;
4872 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
4873 prepended to the string BASE[0..BASE_LEN-1].
4874 This doesn't use any caches. */
4876 apply_modifiers_uncached (modifiers
, base
, base_len
, base_len_byte
)
4879 int base_len
, base_len_byte
;
4881 /* Since BASE could contain nulls, we can't use intern here; we have
4882 to use Fintern, which expects a genuine Lisp_String, and keeps a
4885 = (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
4891 /* Only the event queue may use the `up' modifier; it should always
4892 be turned into a click or drag event before presented to lisp code. */
4893 if (modifiers
& up_modifier
)
4896 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
4897 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
4898 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
4899 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
4900 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
4901 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
4902 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
4903 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
4904 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
4905 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
4906 /* The click modifier is denoted by the absence of other modifiers. */
4910 mod_len
= p
- new_mods
;
4914 Lisp_Object new_name
;
4916 new_name
= make_uninit_multibyte_string (mod_len
+ base_len
,
4917 mod_len
+ base_len_byte
);
4918 bcopy (new_mods
, XSTRING (new_name
)->data
, mod_len
);
4919 bcopy (base
, XSTRING (new_name
)->data
+ mod_len
, base_len_byte
);
4921 return Fintern (new_name
, Qnil
);
4926 static char *modifier_names
[] =
4928 "up", "down", "drag", "click", "double", "triple", 0, 0,
4929 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4930 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
4932 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
4934 static Lisp_Object modifier_symbols
;
4936 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
4938 lispy_modifier_list (modifiers
)
4941 Lisp_Object modifier_list
;
4944 modifier_list
= Qnil
;
4945 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
4946 if (modifiers
& (1<<i
))
4947 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
4950 return modifier_list
;
4954 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
4955 where UNMODIFIED is the unmodified form of SYMBOL,
4956 MASK is the set of modifiers present in SYMBOL's name.
4957 This is similar to parse_modifiers_uncached, but uses the cache in
4958 SYMBOL's Qevent_symbol_element_mask property, and maintains the
4959 Qevent_symbol_elements property. */
4962 parse_modifiers (symbol
)
4965 Lisp_Object elements
;
4967 elements
= Fget (symbol
, Qevent_symbol_element_mask
);
4968 if (CONSP (elements
))
4973 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
4974 Lisp_Object unmodified
;
4977 unmodified
= Fintern (make_string (XSYMBOL (symbol
)->name
->data
+ end
,
4978 STRING_BYTES (XSYMBOL (symbol
)->name
) - end
),
4981 if (modifiers
& ~(((EMACS_INT
)1 << VALBITS
) - 1))
4983 XSETFASTINT (mask
, modifiers
);
4984 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
4986 /* Cache the parsing results on SYMBOL. */
4987 Fput (symbol
, Qevent_symbol_element_mask
,
4989 Fput (symbol
, Qevent_symbol_elements
,
4990 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
4992 /* Since we know that SYMBOL is modifiers applied to unmodified,
4993 it would be nice to put that in unmodified's cache.
4994 But we can't, since we're not sure that parse_modifiers is
5001 /* Apply the modifiers MODIFIERS to the symbol BASE.
5002 BASE must be unmodified.
5004 This is like apply_modifiers_uncached, but uses BASE's
5005 Qmodifier_cache property, if present. It also builds
5006 Qevent_symbol_elements properties, since it has that info anyway.
5008 apply_modifiers copies the value of BASE's Qevent_kind property to
5009 the modified symbol. */
5011 apply_modifiers (modifiers
, base
)
5015 Lisp_Object cache
, index
, entry
, new_symbol
;
5017 /* Mask out upper bits. We don't know where this value's been. */
5018 modifiers
&= ((EMACS_INT
)1 << VALBITS
) - 1;
5020 /* The click modifier never figures into cache indices. */
5021 cache
= Fget (base
, Qmodifier_cache
);
5022 XSETFASTINT (index
, (modifiers
& ~click_modifier
));
5023 entry
= assq_no_quit (index
, cache
);
5026 new_symbol
= XCONS (entry
)->cdr
;
5029 /* We have to create the symbol ourselves. */
5030 new_symbol
= apply_modifiers_uncached (modifiers
,
5031 XSYMBOL (base
)->name
->data
,
5032 XSYMBOL (base
)->name
->size
,
5033 STRING_BYTES (XSYMBOL (base
)->name
));
5035 /* Add the new symbol to the base's cache. */
5036 entry
= Fcons (index
, new_symbol
);
5037 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
5039 /* We have the parsing info now for free, so add it to the caches. */
5040 XSETFASTINT (index
, modifiers
);
5041 Fput (new_symbol
, Qevent_symbol_element_mask
,
5042 Fcons (base
, Fcons (index
, Qnil
)));
5043 Fput (new_symbol
, Qevent_symbol_elements
,
5044 Fcons (base
, lispy_modifier_list (modifiers
)));
5047 /* Make sure this symbol is of the same kind as BASE.
5049 You'd think we could just set this once and for all when we
5050 intern the symbol above, but reorder_modifiers may call us when
5051 BASE's property isn't set right; we can't assume that just
5052 because it has a Qmodifier_cache property it must have its
5053 Qevent_kind set right as well. */
5054 if (NILP (Fget (new_symbol
, Qevent_kind
)))
5058 kind
= Fget (base
, Qevent_kind
);
5060 Fput (new_symbol
, Qevent_kind
, kind
);
5067 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
5068 return a symbol with the modifiers placed in the canonical order.
5069 Canonical order is alphabetical, except for down and drag, which
5070 always come last. The 'click' modifier is never written out.
5072 Fdefine_key calls this to make sure that (for example) C-M-foo
5073 and M-C-foo end up being equivalent in the keymap. */
5076 reorder_modifiers (symbol
)
5079 /* It's hopefully okay to write the code this way, since everything
5080 will soon be in caches, and no consing will be done at all. */
5083 parsed
= parse_modifiers (symbol
);
5084 return apply_modifiers ((int) XINT (XCONS (XCONS (parsed
)->cdr
)->car
),
5085 XCONS (parsed
)->car
);
5089 /* For handling events, we often want to produce a symbol whose name
5090 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
5091 to some base, like the name of a function key or mouse button.
5092 modify_event_symbol produces symbols of this sort.
5094 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
5095 is the name of the i'th symbol. TABLE_SIZE is the number of elements
5098 Alternatively, NAME_ALIST is an alist mapping codes into symbol names.
5099 NAME_ALIST is used if it is non-nil; otherwise NAME_TABLE is used.
5101 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
5102 persist between calls to modify_event_symbol that it can use to
5103 store a cache of the symbols it's generated for this NAME_TABLE
5104 before. The object stored there may be a vector or an alist.
5106 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
5108 MODIFIERS is a set of modifier bits (as given in struct input_events)
5109 whose prefixes should be applied to the symbol name.
5111 SYMBOL_KIND is the value to be placed in the event_kind property of
5112 the returned symbol.
5114 The symbols we create are supposed to have an
5115 `event-symbol-elements' property, which lists the modifiers present
5116 in the symbol's name. */
5119 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_alist
,
5120 name_table
, symbol_table
, table_size
)
5123 Lisp_Object symbol_kind
;
5124 Lisp_Object name_alist
;
5126 Lisp_Object
*symbol_table
;
5127 unsigned int table_size
;
5130 Lisp_Object symbol_int
;
5132 /* Get rid of the "vendor-specific" bit here. */
5133 XSETINT (symbol_int
, symbol_num
& 0xffffff);
5135 /* Is this a request for a valid symbol? */
5136 if (symbol_num
< 0 || symbol_num
>= table_size
)
5139 if (CONSP (*symbol_table
))
5140 value
= Fcdr (assq_no_quit (symbol_int
, *symbol_table
));
5142 /* If *symbol_table doesn't seem to be initialized properly, fix that.
5143 *symbol_table should be a lisp vector TABLE_SIZE elements long,
5144 where the Nth element is the symbol for NAME_TABLE[N], or nil if
5145 we've never used that symbol before. */
5148 if (! VECTORP (*symbol_table
)
5149 || XVECTOR (*symbol_table
)->size
!= table_size
)
5153 XSETFASTINT (size
, table_size
);
5154 *symbol_table
= Fmake_vector (size
, Qnil
);
5157 value
= XVECTOR (*symbol_table
)->contents
[symbol_num
];
5160 /* Have we already used this symbol before? */
5163 /* No; let's create it. */
5164 if (!NILP (name_alist
))
5165 value
= Fcdr_safe (Fassq (symbol_int
, name_alist
));
5166 else if (name_table
!= 0 && name_table
[symbol_num
])
5167 value
= intern (name_table
[symbol_num
]);
5169 #ifdef HAVE_WINDOW_SYSTEM
5172 char *name
= x_get_keysym_name (symbol_num
);
5174 value
= intern (name
);
5181 sprintf (buf
, "key-%d", symbol_num
);
5182 value
= intern (buf
);
5185 if (CONSP (*symbol_table
))
5186 *symbol_table
= Fcons (Fcons (symbol_int
, value
), *symbol_table
);
5188 XVECTOR (*symbol_table
)->contents
[symbol_num
] = value
;
5190 /* Fill in the cache entries for this symbol; this also
5191 builds the Qevent_symbol_elements property, which the user
5193 apply_modifiers (modifiers
& click_modifier
, value
);
5194 Fput (value
, Qevent_kind
, symbol_kind
);
5197 /* Apply modifiers to that symbol. */
5198 return apply_modifiers (modifiers
, value
);
5201 /* Convert a list that represents an event type,
5202 such as (ctrl meta backspace), into the usual representation of that
5203 event type as a number or a symbol. */
5205 DEFUN ("event-convert-list", Fevent_convert_list
, Sevent_convert_list
, 1, 1, 0,
5206 "Convert the event description list EVENT-DESC to an event type.\n\
5207 EVENT-DESC should contain one base event type (a character or symbol)\n\
5208 and zero or more modifier names (control, meta, hyper, super, shift, alt,\n\
5209 drag, down, double or triple). The base must be last.\n\
5210 The return value is an event type (a character or symbol) which\n\
5211 has the same base event type and all the specified modifiers.")
5213 Lisp_Object event_desc
;
5221 while (CONSP (rest
))
5226 elt
= XCONS (rest
)->car
;
5227 rest
= XCONS (rest
)->cdr
;
5229 /* Given a symbol, see if it is a modifier name. */
5230 if (SYMBOLP (elt
) && CONSP (rest
))
5231 this = parse_solitary_modifier (elt
);
5235 else if (!NILP (base
))
5236 error ("Two bases given in one event");
5242 /* Let the symbol A refer to the character A. */
5243 if (SYMBOLP (base
) && XSYMBOL (base
)->name
->size
== 1)
5244 XSETINT (base
, XSYMBOL (base
)->name
->data
[0]);
5246 if (INTEGERP (base
))
5248 /* Turn (shift a) into A. */
5249 if ((modifiers
& shift_modifier
) != 0
5250 && (XINT (base
) >= 'a' && XINT (base
) <= 'z'))
5252 XSETINT (base
, XINT (base
) - ('a' - 'A'));
5253 modifiers
&= ~shift_modifier
;
5256 /* Turn (control a) into C-a. */
5257 if (modifiers
& ctrl_modifier
)
5258 return make_number ((modifiers
& ~ctrl_modifier
)
5259 | make_ctrl_char (XINT (base
)));
5261 return make_number (modifiers
| XINT (base
));
5263 else if (SYMBOLP (base
))
5264 return apply_modifiers (modifiers
, base
);
5266 error ("Invalid base event");
5269 /* Try to recognize SYMBOL as a modifier name.
5270 Return the modifier flag bit, or 0 if not recognized. */
5273 parse_solitary_modifier (symbol
)
5276 struct Lisp_String
*name
= XSYMBOL (symbol
)->name
;
5278 switch (name
->data
[0])
5280 #define SINGLE_LETTER_MOD(BIT) \
5281 if (STRING_BYTES (name) == 1) \
5284 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
5285 if (LEN == STRING_BYTES (name) \
5286 && ! strncmp (name->data, NAME, LEN)) \
5290 SINGLE_LETTER_MOD (alt_modifier
);
5294 MULTI_LETTER_MOD (alt_modifier
, "alt", 3);
5298 SINGLE_LETTER_MOD (ctrl_modifier
);
5302 MULTI_LETTER_MOD (ctrl_modifier
, "ctrl", 4);
5303 MULTI_LETTER_MOD (ctrl_modifier
, "control", 7);
5307 SINGLE_LETTER_MOD (hyper_modifier
);
5311 MULTI_LETTER_MOD (hyper_modifier
, "hyper", 5);
5315 SINGLE_LETTER_MOD (meta_modifier
);
5319 MULTI_LETTER_MOD (meta_modifier
, "meta", 4);
5323 SINGLE_LETTER_MOD (shift_modifier
);
5327 MULTI_LETTER_MOD (shift_modifier
, "shift", 5);
5328 MULTI_LETTER_MOD (super_modifier
, "super", 5);
5329 SINGLE_LETTER_MOD (super_modifier
);
5333 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
5334 MULTI_LETTER_MOD (down_modifier
, "down", 4);
5335 MULTI_LETTER_MOD (double_modifier
, "double", 6);
5339 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
5342 #undef SINGLE_LETTER_MOD
5343 #undef MULTI_LETTER_MOD
5349 /* Return 1 if EVENT is a list whose elements are all integers or symbols.
5350 Such a list is not valid as an event,
5351 but it can be a Lucid-style event type list. */
5354 lucid_event_type_list_p (object
)
5359 if (! CONSP (object
))
5362 for (tail
= object
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5365 elt
= XCONS (tail
)->car
;
5366 if (! (INTEGERP (elt
) || SYMBOLP (elt
)))
5373 /* Store into *addr a value nonzero if terminal input chars are available.
5374 Serves the purpose of ioctl (0, FIONREAD, addr)
5375 but works even if FIONREAD does not exist.
5376 (In fact, this may actually read some input.)
5378 If DO_TIMERS_NOW is nonzero, actually run timer events that are ripe. */
5381 get_input_pending (addr
, do_timers_now
)
5385 /* First of all, have we already counted some input? */
5386 *addr
= !NILP (Vquit_flag
) || readable_events (do_timers_now
);
5388 /* If input is being read as it arrives, and we have none, there is none. */
5389 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
5392 /* Try to read some input and see how much we get. */
5394 *addr
= !NILP (Vquit_flag
) || readable_events (do_timers_now
);
5397 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
5400 gobble_input (expected
)
5405 if (interrupt_input
)
5408 mask
= sigblock (sigmask (SIGIO
));
5409 read_avail_input (expected
);
5413 #ifdef POLL_FOR_INPUT
5414 if (read_socket_hook
&& !interrupt_input
&& poll_suppress_count
== 0)
5417 mask
= sigblock (sigmask (SIGALRM
));
5418 read_avail_input (expected
);
5424 read_avail_input (expected
);
5428 /* Put a buffer_switch_event in the buffer
5429 so that read_key_sequence will notice the new current buffer. */
5432 record_asynch_buffer_change ()
5434 struct input_event event
;
5437 event
.kind
= buffer_switch_event
;
5438 event
.frame_or_window
= Qnil
;
5441 /* We don't need a buffer-switch event unless Emacs is waiting for input.
5442 The purpose of the event is to make read_key_sequence look up the
5443 keymaps again. If we aren't in read_key_sequence, we don't need one,
5444 and the event could cause trouble by messing up (input-pending-p). */
5445 tem
= Fwaiting_for_user_input_p ();
5449 /* We never need these events if we have no asynchronous subprocesses. */
5453 /* Make sure no interrupt happens while storing the event. */
5455 if (interrupt_input
)
5458 mask
= sigblock (sigmask (SIGIO
));
5459 kbd_buffer_store_event (&event
);
5466 kbd_buffer_store_event (&event
);
5473 /* Read any terminal input already buffered up by the system
5474 into the kbd_buffer, but do not wait.
5476 EXPECTED should be nonzero if the caller knows there is some input.
5478 Except on VMS, all input is read by this function.
5479 If interrupt_input is nonzero, this function MUST be called
5480 only when SIGIO is blocked.
5482 Returns the number of keyboard chars read, or -1 meaning
5483 this is a bad time to try to read input. */
5486 read_avail_input (expected
)
5489 struct input_event buf
[KBD_BUFFER_SIZE
];
5493 if (read_socket_hook
)
5494 /* No need for FIONREAD or fcntl; just say don't wait. */
5495 nread
= (*read_socket_hook
) (input_fd
, buf
, KBD_BUFFER_SIZE
, expected
);
5498 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
5499 the kbd_buffer can really hold. That may prevent loss
5500 of characters on some systems when input is stuffed at us. */
5501 unsigned char cbuf
[KBD_BUFFER_SIZE
- 1];
5504 /* Determine how many characters we should *try* to read. */
5507 #else /* not WINDOWSNT */
5509 n_to_read
= dos_keysns ();
5512 #else /* not MSDOS */
5514 /* Find out how much input is available. */
5515 if (ioctl (input_fd
, FIONREAD
, &n_to_read
) < 0)
5516 /* Formerly simply reported no input, but that sometimes led to
5517 a failure of Emacs to terminate.
5518 SIGHUP seems appropriate if we can't reach the terminal. */
5519 /* ??? Is it really right to send the signal just to this process
5520 rather than to the whole process group?
5521 Perhaps on systems with FIONREAD Emacs is alone in its group. */
5522 kill (getpid (), SIGHUP
);
5525 if (n_to_read
> sizeof cbuf
)
5526 n_to_read
= sizeof cbuf
;
5527 #else /* no FIONREAD */
5528 #if defined (USG) || defined (DGUX)
5529 /* Read some input if available, but don't wait. */
5530 n_to_read
= sizeof cbuf
;
5531 fcntl (input_fd
, F_SETFL
, O_NDELAY
);
5536 #endif /* not MSDOS */
5537 #endif /* not WINDOWSNT */
5539 /* Now read; for one reason or another, this will not block.
5540 NREAD is set to the number of chars read. */
5544 cbuf
[0] = dos_keyread ();
5547 nread
= read (input_fd
, cbuf
, n_to_read
);
5549 /* POSIX infers that processes which are not in the session leader's
5550 process group won't get SIGHUP's at logout time. BSDI adheres to
5551 this part standard and returns -1 from read (0) with errno==EIO
5552 when the control tty is taken away.
5553 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
5554 if (nread
== -1 && errno
== EIO
)
5556 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
5557 /* The kernel sometimes fails to deliver SIGHUP for ptys.
5558 This looks incorrect, but it isn't, because _BSD causes
5559 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
5560 and that causes a value other than 0 when there is no input. */
5566 /* We used to retry the read if it was interrupted.
5567 But this does the wrong thing when O_NDELAY causes
5568 an EAGAIN error. Does anybody know of a situation
5569 where a retry is actually needed? */
5571 nread
< 0 && (errno
== EAGAIN
5585 #if defined (USG) || defined (DGUX)
5586 fcntl (input_fd
, F_SETFL
, 0);
5587 #endif /* USG or DGUX */
5588 #endif /* no FIONREAD */
5589 for (i
= 0; i
< nread
; i
++)
5591 buf
[i
].kind
= ascii_keystroke
;
5592 buf
[i
].modifiers
= 0;
5593 if (meta_key
== 1 && (cbuf
[i
] & 0x80))
5594 buf
[i
].modifiers
= meta_modifier
;
5598 buf
[i
].code
= cbuf
[i
];
5599 XSETFRAME (buf
[i
].frame_or_window
, selected_frame
);
5603 /* Scan the chars for C-g and store them in kbd_buffer. */
5604 for (i
= 0; i
< nread
; i
++)
5606 kbd_buffer_store_event (&buf
[i
]);
5607 /* Don't look at input that follows a C-g too closely.
5608 This reduces lossage due to autorepeat on C-g. */
5609 if (buf
[i
].kind
== ascii_keystroke
5610 && buf
[i
].code
== quit_char
)
5616 #endif /* not VMS */
5618 #ifdef SIGIO /* for entire page */
5619 /* Note SIGIO has been undef'd if FIONREAD is missing. */
5622 input_available_signal (signo
)
5625 /* Must preserve main program's value of errno. */
5626 int old_errno
= errno
;
5628 extern int select_alarmed
;
5631 #if defined (USG) && !defined (POSIX_SIGNALS)
5632 /* USG systems forget handlers when they are used;
5633 must reestablish each time */
5634 signal (signo
, input_available_signal
);
5641 if (input_available_clear_time
)
5642 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
5647 nread
= read_avail_input (1);
5648 /* -1 means it's not ok to read the input now.
5649 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
5650 0 means there was no keyboard input available. */
5655 select_alarmed
= 1; /* Force the select emulator back to life */
5666 /* Send ourselves a SIGIO.
5668 This function exists so that the UNBLOCK_INPUT macro in
5669 blockinput.h can have some way to take care of input we put off
5670 dealing with, without assuming that every file which uses
5671 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
5673 reinvoke_input_signal ()
5676 kill (getpid (), SIGIO
);
5682 /* Return the prompt-string of a sparse keymap.
5683 This is the first element which is a string.
5684 Return nil if there is none. */
5692 register Lisp_Object tem
;
5701 static void menu_bar_item ();
5702 static void menu_bar_one_keymap ();
5704 /* These variables hold the vector under construction within
5705 menu_bar_items and its subroutines, and the current index
5706 for storing into that vector. */
5707 static Lisp_Object menu_bar_items_vector
;
5708 static int menu_bar_items_index
;
5710 /* Return a vector of menu items for a menu bar, appropriate
5711 to the current buffer. Each item has three elements in the vector:
5714 OLD is an old vector we can optionally reuse, or nil. */
5717 menu_bar_items (old
)
5720 /* The number of keymaps we're scanning right now, and the number of
5721 keymaps we have allocated space for. */
5724 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
5725 in the current keymaps, or nil where it is not a prefix. */
5728 Lisp_Object def
, tem
, tail
;
5737 struct gcpro gcpro1
;
5739 /* In order to build the menus, we need to call the keymap
5740 accessors. They all call QUIT. But this function is called
5741 during redisplay, during which a quit is fatal. So inhibit
5742 quitting while building the menus.
5743 We do this instead of specbind because (1) errors will clear it anyway
5744 and (2) this avoids risk of specpdl overflow. */
5745 oquit
= Vinhibit_quit
;
5749 menu_bar_items_vector
= old
;
5751 menu_bar_items_vector
= Fmake_vector (make_number (24), Qnil
);
5752 menu_bar_items_index
= 0;
5754 GCPRO1 (menu_bar_items_vector
);
5756 /* Build our list of keymaps.
5757 If we recognize a function key and replace its escape sequence in
5758 keybuf with its symbol, or if the sequence starts with a mouse
5759 click and we need to switch buffers, we jump back here to rebuild
5760 the initial keymaps from the current buffer. */
5764 /* Should overriding-terminal-local-map and overriding-local-map apply? */
5765 if (!NILP (Voverriding_local_map_menu_flag
))
5767 /* Yes, use them (if non-nil) as well as the global map. */
5768 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
5770 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
5771 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
5772 if (!NILP (Voverriding_local_map
))
5773 maps
[nmaps
++] = Voverriding_local_map
;
5777 /* No, so use major and minor mode keymaps. */
5778 nmaps
= current_minor_maps (NULL
, &tmaps
);
5779 maps
= (Lisp_Object
*) alloca ((nmaps
+ 2) * sizeof (maps
[0]));
5780 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
5781 #ifdef USE_TEXT_PROPERTIES
5782 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
5784 maps
[nmaps
++] = current_buffer
->keymap
;
5787 maps
[nmaps
++] = current_global_map
;
5790 /* Look up in each map the dummy prefix key `menu-bar'. */
5794 for (mapno
= nmaps
- 1; mapno
>= 0; mapno
--)
5796 if (! NILP (maps
[mapno
]))
5797 def
= get_keyelt (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0), 0);
5801 tem
= Fkeymapp (def
);
5803 menu_bar_one_keymap (def
);
5806 /* Move to the end those items that should be at the end. */
5808 for (tail
= Vmenu_bar_final_items
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5811 int end
= menu_bar_items_index
;
5813 for (i
= 0; i
< end
; i
+= 4)
5814 if (EQ (XCONS (tail
)->car
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
5816 Lisp_Object tem0
, tem1
, tem2
, tem3
;
5817 /* Move the item at index I to the end,
5818 shifting all the others forward. */
5819 tem0
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 0];
5820 tem1
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 1];
5821 tem2
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
5822 tem3
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3];
5824 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
5825 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
5826 (end
- i
- 4) * sizeof (Lisp_Object
));
5827 XVECTOR (menu_bar_items_vector
)->contents
[end
- 4] = tem0
;
5828 XVECTOR (menu_bar_items_vector
)->contents
[end
- 3] = tem1
;
5829 XVECTOR (menu_bar_items_vector
)->contents
[end
- 2] = tem2
;
5830 XVECTOR (menu_bar_items_vector
)->contents
[end
- 1] = tem3
;
5835 /* Add nil, nil, nil, nil at the end. */
5836 i
= menu_bar_items_index
;
5837 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
5840 int newsize
= 2 * i
;
5841 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
5842 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
5843 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
5844 menu_bar_items_vector
= tem
;
5846 /* Add this item. */
5847 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5848 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5849 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5850 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5851 menu_bar_items_index
= i
;
5853 Vinhibit_quit
= oquit
;
5855 return menu_bar_items_vector
;
5858 /* Scan one map KEYMAP, accumulating any menu items it defines
5859 in menu_bar_items_vector. */
5861 static Lisp_Object menu_bar_one_keymap_changed_items
;
5864 menu_bar_one_keymap (keymap
)
5867 Lisp_Object tail
, item
, table
;
5869 menu_bar_one_keymap_changed_items
= Qnil
;
5871 /* Loop over all keymap entries that have menu strings. */
5872 for (tail
= keymap
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5874 item
= XCONS (tail
)->car
;
5876 menu_bar_item (XCONS (item
)->car
, XCONS (item
)->cdr
);
5877 else if (VECTORP (item
))
5879 /* Loop over the char values represented in the vector. */
5880 int len
= XVECTOR (item
)->size
;
5882 for (c
= 0; c
< len
; c
++)
5884 Lisp_Object character
;
5885 XSETFASTINT (character
, c
);
5886 menu_bar_item (character
, XVECTOR (item
)->contents
[c
]);
5892 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
5893 If there's already an item for KEY, add this DEF to it. */
5895 Lisp_Object item_properties
;
5898 menu_bar_item (key
, item
)
5899 Lisp_Object key
, item
;
5901 struct gcpro gcpro1
;
5905 if (EQ (item
, Qundefined
))
5907 /* If a map has an explicit `undefined' as definition,
5908 discard any previously made menu bar item. */
5910 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
5911 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
5913 if (menu_bar_items_index
> i
+ 4)
5914 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
5915 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
5916 (menu_bar_items_index
- i
- 4) * sizeof (Lisp_Object
));
5917 menu_bar_items_index
-= 4;
5921 /* If there's no definition for this key yet,
5922 just ignore `undefined'. */
5926 GCPRO1 (key
); /* Is this necessary? */
5927 i
= parse_menu_item (item
, 0, 1);
5932 /* If this keymap has already contributed to this KEY,
5933 don't contribute to it a second time. */
5934 tem
= Fmemq (key
, menu_bar_one_keymap_changed_items
);
5938 menu_bar_one_keymap_changed_items
5939 = Fcons (key
, menu_bar_one_keymap_changed_items
);
5941 item
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
5943 /* Find any existing item for this KEY. */
5944 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
5945 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
5948 /* If we did not find this KEY, add it at the end. */
5949 if (i
== menu_bar_items_index
)
5951 /* If vector is too small, get a bigger one. */
5952 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
5955 int newsize
= 2 * i
;
5956 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
5957 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
5958 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
5959 menu_bar_items_vector
= tem
;
5962 /* Add this item. */
5963 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = key
;
5964 XVECTOR (menu_bar_items_vector
)->contents
[i
++]
5965 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
5966 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Fcons (item
, Qnil
);
5967 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = make_number (0);
5968 menu_bar_items_index
= i
;
5970 /* We did find an item for this KEY. Add ITEM to its list of maps. */
5974 old
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
5975 XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2] = Fcons (item
, old
);
5979 /* This is used as the handler when calling menu_item_eval_property. */
5981 menu_item_eval_property_1 (arg
)
5984 /* If we got a quit from within the menu computation,
5985 quit all the way out of it. This takes care of C-] in the debugger. */
5986 if (CONSP (arg
) && EQ (XCONS (arg
)->car
, Qquit
))
5987 Fsignal (Qquit
, Qnil
);
5992 /* Evaluate an expression and return the result (or nil if something
5993 went wrong). Used to evaluate dynamic parts of menu items. */
5995 menu_item_eval_property (sexpr
)
5998 int count
= specpdl_ptr
- specpdl
;
6000 specbind (Qinhibit_redisplay
, Qt
);
6001 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
,
6002 menu_item_eval_property_1
);
6003 return unbind_to (count
, val
);
6006 /* This function parses a menu item and leaves the result in the
6007 vector item_properties.
6008 ITEM is a key binding, a possible menu item.
6009 If NOTREAL is nonzero, only check for equivalent key bindings, don't
6010 evaluate dynamic expressions in the menu item.
6011 INMENUBAR is > 0 when this is considered for an entry in a menu bar
6013 INMENUBAR is < 0 when this is considered for an entry in a keyboard menu.
6014 parse_menu_item returns true if the item is a menu item and false
6018 parse_menu_item (item
, notreal
, inmenubar
)
6020 int notreal
, inmenubar
;
6022 Lisp_Object def
, tem
, item_string
, start
;
6023 Lisp_Object cachelist
;
6025 Lisp_Object keyhint
;
6036 /* Create item_properties vector if necessary. */
6037 if (NILP (item_properties
))
6039 = Fmake_vector (make_number (ITEM_PROPERTY_ENABLE
+ 1), Qnil
);
6041 /* Initialize optional entries. */
6042 for (i
= ITEM_PROPERTY_DEF
; i
< ITEM_PROPERTY_ENABLE
; i
++)
6043 XVECTOR (item_properties
)->contents
[i
] = Qnil
;
6044 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
] = Qt
;
6046 /* Save the item here to protect it from GC. */
6047 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ITEM
] = item
;
6049 item_string
= XCONS (item
)->car
;
6052 item
= XCONS (item
)->cdr
;
6053 if (STRINGP (item_string
))
6055 /* Old format menu item. */
6056 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
] = item_string
;
6058 /* Maybe help string. */
6059 if (CONSP (item
) && STRINGP (XCONS (item
)->car
))
6061 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_HELP
]
6062 = XCONS (item
)->car
;
6064 item
= XCONS (item
)->cdr
;
6067 /* Maybee key binding cache. */
6068 if (CONSP (item
) && CONSP (XCONS (item
)->car
)
6069 && (NILP (XCONS (XCONS (item
)->car
)->car
)
6070 || VECTORP (XCONS (XCONS (item
)->car
)->car
)))
6072 cachelist
= XCONS (item
)->car
;
6073 item
= XCONS (item
)->cdr
;
6076 /* This is the real definition--the function to run. */
6077 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
] = item
;
6079 /* Get enable property, if any. */
6082 tem
= Fget (item
, Qmenu_enable
);
6084 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
] = tem
;
6087 else if (EQ (item_string
, Qmenu_item
) && CONSP (item
))
6089 /* New format menu item. */
6090 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
]
6091 = XCONS (item
)->car
;
6092 start
= XCONS (item
)->cdr
;
6095 /* We have a real binding. */
6096 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
]
6097 = XCONS (start
)->car
;
6099 item
= XCONS (start
)->cdr
;
6100 /* Is there a cache list with key equivalences. */
6101 if (CONSP (item
) && CONSP (XCONS (item
)->car
))
6103 cachelist
= XCONS (item
)->car
;
6104 item
= XCONS (item
)->cdr
;
6107 /* Parse properties. */
6108 while (CONSP (item
) && CONSP (XCONS (item
)->cdr
))
6110 tem
= XCONS (item
)->car
;
6111 item
= XCONS (item
)->cdr
;
6113 if (EQ (tem
, QCenable
))
6114 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
]
6115 = XCONS (item
)->car
;
6116 else if (EQ (tem
, QCvisible
) && !notreal
)
6118 /* If got a visible property and that evaluates to nil
6119 then ignore this item. */
6120 tem
= menu_item_eval_property (XCONS (item
)->car
);
6124 else if (EQ (tem
, QChelp
))
6125 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_HELP
]
6126 = XCONS (item
)->car
;
6127 else if (EQ (tem
, QCfilter
))
6129 else if (EQ (tem
, QCkey_sequence
))
6131 tem
= XCONS (item
)->car
;
6132 if (NILP (cachelist
)
6133 && (SYMBOLP (tem
) || STRINGP (tem
) || VECTORP (tem
)))
6134 /* Be GC protected. Set keyhint to item instead of tem. */
6137 else if (EQ (tem
, QCkeys
))
6139 tem
= XCONS (item
)->car
;
6140 if (CONSP (tem
) || STRINGP (tem
) && NILP (cachelist
))
6141 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
]
6144 else if (EQ (tem
, QCbutton
) && CONSP (XCONS (item
)->car
))
6147 tem
= XCONS (item
)->car
;
6148 type
= XCONS (tem
)->car
;
6149 if (EQ (type
, QCtoggle
) || EQ (type
, QCradio
))
6151 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
]
6153 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_TYPE
]
6157 item
= XCONS (item
)->cdr
;
6160 else if (inmenubar
|| !NILP (start
))
6164 return 0; /* not a menu item */
6166 /* If item string is not a string, evaluate it to get string.
6167 If we don't get a string, skip this item. */
6168 item_string
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
6169 if (!(STRINGP (item_string
) || notreal
))
6171 item_string
= menu_item_eval_property (item_string
);
6172 if (!STRINGP (item_string
))
6174 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
] = item_string
;
6177 /* If got a filter apply it on definition. */
6178 def
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
6181 def
= menu_item_eval_property (list2 (XCONS (filter
)->car
,
6182 list2 (Qquote
, def
)));
6184 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
] = def
;
6187 /* If we got no definition, this item is just unselectable text which
6188 is OK in a submenu but not in the menubar. */
6190 return (inmenubar
? 0 : 1);
6192 /* Enable or disable selection of item. */
6193 tem
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
];
6199 tem
= menu_item_eval_property (tem
);
6200 if (inmenubar
&& NILP (tem
))
6201 return 0; /* Ignore disabled items in menu bar. */
6202 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
] = tem
;
6205 /* See if this is a separate pane or a submenu. */
6206 def
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
6207 tem
= get_keymap_1 (def
, 0, 1);
6208 /* For a subkeymap, just record its details and exit. */
6211 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_MAP
] = tem
;
6212 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
] = tem
;
6215 /* At the top level in the menu bar, do likewise for commands also.
6216 The menu bar does not display equivalent key bindings anyway.
6217 ITEM_PROPERTY_DEF is already set up properly. */
6221 /* This is a command. See if there is an equivalent key binding. */
6222 if (NILP (cachelist
))
6224 /* We have to create a cachelist. */
6225 CHECK_IMPURE (start
);
6226 XCONS (start
)->cdr
= Fcons (Fcons (Qnil
, Qnil
), XCONS (start
)->cdr
);
6227 cachelist
= XCONS (XCONS (start
)->cdr
)->car
;
6229 tem
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
6230 if (!NILP (keyhint
))
6232 XCONS (cachelist
)->car
= XCONS (keyhint
)->car
;
6235 else if (STRINGP (tem
))
6237 XCONS (cachelist
)->cdr
= Fsubstitute_command_keys (tem
);
6238 XCONS (cachelist
)->car
= Qt
;
6241 tem
= XCONS (cachelist
)->car
;
6248 tem
= Fkey_binding (tem
, Qnil
);
6250 prefix
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
6253 def
= XCONS (prefix
)->car
;
6254 prefix
= XCONS (prefix
)->cdr
;
6257 def
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
6259 if (NILP (XCONS (cachelist
)->car
)) /* Have no saved key. */
6261 if (newcache
/* Always check first time. */
6262 /* Should we check everything when precomputing key
6265 /* If something had no key binding before, don't recheck it
6266 because that is too slow--except if we have a list of
6267 rebound commands in Vdefine_key_rebound_commands, do
6268 recheck any command that appears in that list. */
6269 || (CONSP (Vdefine_key_rebound_commands
)
6270 && !NILP (Fmemq (def
, Vdefine_key_rebound_commands
))))
6273 /* We had a saved key. Is it still bound to the command? */
6276 /* If the command is an alias for another
6277 (such as lmenu.el set it up), check if the
6278 original command matches the cached command. */
6279 && !(SYMBOLP (def
) && EQ (tem
, XSYMBOL (def
)->function
)))
6280 chkcache
= 1; /* Need to recompute key binding. */
6284 /* Recompute equivalent key binding. If the command is an alias
6285 for another (such as lmenu.el set it up), see if the original
6286 command name has equivalent keys. Otherwise look up the
6287 specified command itself. We don't try both, because that
6288 makes lmenu menus slow. */
6289 if (SYMBOLP (def
) && SYMBOLP (XSYMBOL (def
)->function
)
6290 && ! NILP (Fget (def
, Qmenu_alias
)))
6291 def
= XSYMBOL (def
)->function
;
6292 tem
= Fwhere_is_internal (def
, Qnil
, Qt
, Qnil
);
6293 XCONS (cachelist
)->car
= tem
;
6296 XCONS (cachelist
)->cdr
= Qnil
;
6300 else if (!NILP (keyhint
) && !NILP (XCONS (cachelist
)->car
))
6302 tem
= XCONS (cachelist
)->car
;
6306 newcache
= chkcache
;
6309 tem
= Fkey_description (tem
);
6312 if (STRINGP (XCONS (prefix
)->car
))
6313 tem
= concat2 (XCONS (prefix
)->car
, tem
);
6314 if (STRINGP (XCONS (prefix
)->cdr
))
6315 tem
= concat2 (tem
, XCONS (prefix
)->cdr
);
6317 XCONS (cachelist
)->cdr
= tem
;
6321 tem
= XCONS (cachelist
)->cdr
;
6322 if (newcache
&& !NILP (tem
))
6324 tem
= concat3 (build_string (" ("), tem
, build_string (")"));
6325 XCONS (cachelist
)->cdr
= tem
;
6328 /* If we only want to precompute equivalent key bindings, stop here. */
6332 /* If we have an equivalent key binding, use that. */
6333 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
] = tem
;
6335 /* Include this when menu help is implemented.
6336 tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP];
6337 if (!(NILP (tem) || STRINGP (tem)))
6339 tem = menu_item_eval_property (tem);
6342 XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP] = tem;
6346 /* Handle radio buttons or toggle boxes. */
6347 tem
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
];
6349 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
]
6350 = menu_item_eval_property (tem
);
6357 /***********************************************************************
6359 ***********************************************************************/
6361 /* A vector holding toolbar items while they are parsed in function
6362 toolbar_items runs Each item occupies TOOLBAR_ITEM_NSCLOTS
6363 elements in the vector. */
6365 static Lisp_Object toolbar_items_vector
;
6367 /* A vector holding the result of parse_toolbar_item. Layout is like
6368 the one for a single item in toolbar_items_vector. */
6370 static Lisp_Object toolbar_item_properties
;
6372 /* Next free index in toolbar_items_vector. */
6374 static int ntoolbar_items
;
6376 /* The symbols `toolbar', `toolbar-item', and `:image'. */
6378 extern Lisp_Object Qtoolbar
;
6379 Lisp_Object QCimage
;
6381 /* Function prototypes. */
6383 static void init_toolbar_items
P_ ((Lisp_Object
));
6384 static void process_toolbar_item
P_ ((Lisp_Object
, Lisp_Object
));
6385 static int parse_toolbar_item
P_ ((Lisp_Object
, Lisp_Object
));
6386 static void append_toolbar_item
P_ ((void));
6389 /* Return a vector of toolbar items for keymaps currently in effect.
6390 Reuse vector REUSE if non-nil. Return in *NITEMS the number of
6391 toolbar items found. */
6394 toolbar_items (reuse
, nitems
)
6402 extern Lisp_Object Voverriding_local_map_menu_flag
;
6403 extern Lisp_Object Voverriding_local_map
;
6407 /* In order to build the menus, we need to call the keymap
6408 accessors. They all call QUIT. But this function is called
6409 during redisplay, during which a quit is fatal. So inhibit
6410 quitting while building the menus. We do this instead of
6411 specbind because (1) errors will clear it anyway and (2) this
6412 avoids risk of specpdl overflow. */
6413 oquit
= Vinhibit_quit
;
6416 /* Initialize toolbar_items_vector and protect it from GC. */
6417 init_toolbar_items (reuse
);
6419 /* Build list of keymaps in maps. Set nmaps to the number of maps
6422 /* Should overriding-terminal-local-map and overriding-local-map apply? */
6423 if (!NILP (Voverriding_local_map_menu_flag
))
6425 /* Yes, use them (if non-nil) as well as the global map. */
6426 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
6428 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
6429 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
6430 if (!NILP (Voverriding_local_map
))
6431 maps
[nmaps
++] = Voverriding_local_map
;
6435 /* No, so use major and minor mode keymaps. */
6436 nmaps
= current_minor_maps (NULL
, &tmaps
);
6437 maps
= (Lisp_Object
*) alloca ((nmaps
+ 2) * sizeof (maps
[0]));
6438 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
6439 #ifdef USE_TEXT_PROPERTIES
6440 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
6442 maps
[nmaps
++] = current_buffer
->keymap
;
6446 /* Add global keymap at the end. */
6447 maps
[nmaps
++] = current_global_map
;
6449 /* Process maps in reverse order and look up in each map the prefix
6451 for (i
= nmaps
- 1; i
>= 0; --i
)
6452 if (!NILP (maps
[i
]))
6456 keymap
= get_keyelt (access_keymap (maps
[i
], Qtoolbar
, 1, 1), 0);
6457 if (!NILP (Fkeymapp (keymap
)))
6461 /* KEYMAP is a list `(keymap (KEY . BINDING) ...)'. */
6462 for (tail
= keymap
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
6464 Lisp_Object keydef
= XCAR (tail
);
6466 process_toolbar_item (XCAR (keydef
), XCDR (keydef
));
6471 Vinhibit_quit
= oquit
;
6472 *nitems
= ntoolbar_items
/ TOOLBAR_ITEM_NSLOTS
;
6473 return toolbar_items_vector
;
6477 /* Process the definition of KEY which is DEF. */
6480 process_toolbar_item (key
, def
)
6481 Lisp_Object key
, def
;
6484 extern Lisp_Object Qundefined
;
6485 struct gcpro gcpro1
, gcpro2
;
6487 /* Protect KEY and DEF from GC because parse_toolbar_item may call
6491 if (EQ (def
, Qundefined
))
6493 /* If a map has an explicit `undefined' as definition,
6494 discard any previously made item. */
6495 for (i
= 0; i
< ntoolbar_items
; i
+= TOOLBAR_ITEM_NSLOTS
)
6497 Lisp_Object
*v
= XVECTOR (toolbar_items_vector
)->contents
+ i
;
6499 if (EQ (key
, v
[TOOLBAR_ITEM_KEY
]))
6501 if (ntoolbar_items
> i
+ TOOLBAR_ITEM_NSLOTS
)
6502 bcopy (v
+ TOOLBAR_ITEM_NSLOTS
, v
,
6503 ((ntoolbar_items
- i
- TOOLBAR_ITEM_NSLOTS
)
6504 * sizeof (Lisp_Object
)));
6505 ntoolbar_items
-= TOOLBAR_ITEM_NSLOTS
;
6510 else if (parse_toolbar_item (key
, def
))
6511 /* Append a new toolbar item to toolbar_items_vector. Accept
6512 more than one definition for the same key. */
6513 append_toolbar_item ();
6519 /* Parse a toolbar item specification ITEM for key KEY and return the
6520 result in toolbar_item_properties. Value is zero if ITEM is
6523 ITEM is a list `(menu-item CAPTION BINDING PROPS...)'.
6525 CAPTION is the caption of the item, If it's not a string, it is
6526 evaluated to get a string.
6528 BINDING is the toolbar item's binding. Toolbar items with keymaps
6529 as binding are currently ignored.
6531 The following properties are recognized:
6535 FORM is evaluated and specifies whether the toolbar item is enabled
6540 FORM is evaluated and specifies whether the toolbar item is visible.
6542 - `:filter FUNCTION'
6544 FUNCTION is invoked with one parameter `(quote BINDING)'. Its
6545 result is stored as the new binding.
6547 - `:button (TYPE SELECTED)'
6549 TYPE must be one of `:radio' or `:toggle'. SELECTED is evaluated
6550 and specifies whether the button is selected (pressed) or not.
6554 IMAGES is either a single image specification or a vector of four
6555 image specifications. See enum toolbar_item_images.
6557 - `:help HELP-STRING'.
6559 Gives a help string to display for the toolbar item. */
6562 parse_toolbar_item (key
, item
)
6563 Lisp_Object key
, item
;
6565 /* Access slot with index IDX of vector toolbar_item_properties. */
6566 #define PROP(IDX) XVECTOR (toolbar_item_properties)->contents[IDX]
6568 Lisp_Object filter
= Qnil
;
6569 Lisp_Object caption
;
6570 extern Lisp_Object QCenable
, QCvisible
, QChelp
, QCfilter
;
6571 extern Lisp_Object QCbutton
, QCtoggle
, QCradio
;
6573 struct gcpro gcpro1
;
6575 /* Defininition looks like `(toolbar-item CAPTION BINDING
6576 PROPS...)'. Rule out items that aren't lists, don't start with
6577 `toolbar-item' or whose rest following `toolbar-item' is not a
6580 || !EQ (XCAR (item
), Qmenu_item
)
6581 || (item
= XCDR (item
),
6585 /* Create toolbar_item_properties vector if necessary. Reset it to
6587 if (VECTORP (toolbar_item_properties
))
6589 for (i
= 0; i
< TOOLBAR_ITEM_NSLOTS
; ++i
)
6593 toolbar_item_properties
6594 = Fmake_vector (make_number (TOOLBAR_ITEM_NSLOTS
), Qnil
);
6597 PROP (TOOLBAR_ITEM_KEY
) = key
;
6598 PROP (TOOLBAR_ITEM_ENABLED_P
) = Qt
;
6600 /* Get the caption of the item. If the caption is not a string,
6601 evaluate it to get a string. If we don't get a string, skip this
6603 caption
= XCAR (item
);
6604 if (!STRINGP (caption
))
6606 caption
= menu_item_eval_property (caption
);
6607 if (!STRINGP (caption
))
6610 PROP (TOOLBAR_ITEM_CAPTION
) = caption
;
6612 /* Give up if rest following the caption is not a list. */
6617 /* Store the binding. */
6618 PROP (TOOLBAR_ITEM_BINDING
) = XCAR (item
);
6621 /* Process the rest of the properties. */
6622 for (; CONSP (item
) && CONSP (XCDR (item
)); item
= XCDR (XCDR (item
)))
6624 Lisp_Object key
, value
;
6627 value
= XCAR (XCDR (item
));
6629 if (EQ (key
, QCenable
))
6630 /* `:enable FORM'. */
6631 PROP (TOOLBAR_ITEM_ENABLED_P
) = value
;
6632 else if (EQ (key
, QCvisible
))
6634 /* `:visible FORM'. If got a visible property and that
6635 evaluates to nil then ignore this item. */
6636 if (NILP (menu_item_eval_property (value
)))
6639 else if (EQ (key
, QChelp
))
6640 /* `:help HELP-STRING'. */
6641 PROP (TOOLBAR_ITEM_HELP
) = value
;
6642 else if (EQ (key
, QCfilter
))
6643 /* ':filter FORM'. */
6645 else if (EQ (key
, QCbutton
) && CONSP (value
))
6647 /* `:button (TYPE . SELECTED)'. */
6648 Lisp_Object type
, selected
;
6650 type
= XCAR (value
);
6651 selected
= XCDR (value
);
6652 if (EQ (type
, QCtoggle
) || EQ (type
, QCradio
))
6654 PROP (TOOLBAR_ITEM_SELECTED_P
) = selected
;
6655 PROP (TOOLBAR_ITEM_TYPE
) = type
;
6658 else if (EQ (key
, QCimage
)
6660 || (VECTORP (value
) && XVECTOR (value
)->size
== 4)))
6661 /* Value is either a single image specification or a vector
6662 of 4 such specifications for the different buttion states. */
6663 PROP (TOOLBAR_ITEM_IMAGES
) = value
;
6666 /* If got a filter apply it on binding. */
6668 PROP (TOOLBAR_ITEM_BINDING
)
6669 = menu_item_eval_property (list2 (filter
,
6671 PROP (TOOLBAR_ITEM_BINDING
))));
6673 /* See if the binding is a keymap. Give up if it is. */
6674 if (!NILP (get_keymap_1 (PROP (TOOLBAR_ITEM_BINDING
), 0, 1)))
6677 /* Enable or disable selection of item. */
6678 if (!EQ (PROP (TOOLBAR_ITEM_ENABLED_P
), Qt
))
6679 PROP (TOOLBAR_ITEM_ENABLED_P
)
6680 = menu_item_eval_property (PROP (TOOLBAR_ITEM_ENABLED_P
));
6682 /* Handle radio buttons or toggle boxes. */
6683 if (!NILP (PROP (TOOLBAR_ITEM_SELECTED_P
)))
6684 PROP (TOOLBAR_ITEM_SELECTED_P
)
6685 = menu_item_eval_property (PROP (TOOLBAR_ITEM_SELECTED_P
));
6693 /* Initialize Vtoolbar_items. REUSE, if non-nil, is a vector that can
6697 init_toolbar_items (reuse
)
6700 if (VECTORP (reuse
))
6701 toolbar_items_vector
= reuse
;
6703 toolbar_items_vector
= Fmake_vector (make_number (64), Qnil
);
6708 /* Append parsed toolbar item properties from toolbar_item_properties */
6711 append_toolbar_item ()
6713 Lisp_Object
*to
, *from
;
6715 /* Enlarge toolbar_items_vector if necessary. */
6716 if (ntoolbar_items
+ TOOLBAR_ITEM_NSLOTS
6717 >= XVECTOR (toolbar_items_vector
)->size
)
6719 Lisp_Object new_vector
;
6720 int old_size
= XVECTOR (toolbar_items_vector
)->size
;
6722 new_vector
= Fmake_vector (make_number (2 * old_size
), Qnil
);
6723 bcopy (XVECTOR (toolbar_items_vector
)->contents
,
6724 XVECTOR (new_vector
)->contents
,
6725 old_size
* sizeof (Lisp_Object
));
6726 toolbar_items_vector
= new_vector
;
6729 /* Append entries from toolbar_item_properties to the end of
6730 toolbar_items_vector. */
6731 to
= XVECTOR (toolbar_items_vector
)->contents
+ ntoolbar_items
;
6732 from
= XVECTOR (toolbar_item_properties
)->contents
;
6733 bcopy (from
, to
, TOOLBAR_ITEM_NSLOTS
* sizeof *to
);
6734 ntoolbar_items
+= TOOLBAR_ITEM_NSLOTS
;
6741 /* Read a character using menus based on maps in the array MAPS.
6742 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
6743 Return t if we displayed a menu but the user rejected it.
6745 PREV_EVENT is the previous input event, or nil if we are reading
6746 the first event of a key sequence.
6748 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
6749 if we used a mouse menu to read the input, or zero otherwise. If
6750 USED_MOUSE_MENU is null, we don't dereference it.
6752 The prompting is done based on the prompt-string of the map
6753 and the strings associated with various map elements.
6755 This can be done with X menus or with menus put in the minibuf.
6756 These are done in different ways, depending on how the input will be read.
6757 Menus using X are done after auto-saving in read-char, getting the input
6758 event from Fx_popup_menu; menus using the minibuf use read_char recursively
6759 and do auto-saving in the inner call of read_char. */
6762 read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
6765 Lisp_Object prev_event
;
6766 int *used_mouse_menu
;
6769 register Lisp_Object name
;
6770 Lisp_Object rest
, vector
;
6772 if (used_mouse_menu
)
6773 *used_mouse_menu
= 0;
6775 /* Use local over global Menu maps */
6777 if (! menu_prompting
)
6780 /* Optionally disregard all but the global map. */
6781 if (inhibit_local_menu_bar_menus
)
6783 maps
+= (nmaps
- 1);
6787 /* Get the menu name from the first map that has one (a prompt string). */
6788 for (mapno
= 0; mapno
< nmaps
; mapno
++)
6790 name
= map_prompt (maps
[mapno
]);
6795 /* If we don't have any menus, just read a character normally. */
6800 /* If we got to this point via a mouse click,
6801 use a real menu for mouse selection. */
6802 if (EVENT_HAS_PARAMETERS (prev_event
)
6803 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
)
6804 && !EQ (XCONS (prev_event
)->car
, Qtoolbar
))
6806 /* Display the menu and get the selection. */
6807 Lisp_Object
*realmaps
6808 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
6812 /* Use the maps that are not nil. */
6813 for (mapno
= 0; mapno
< nmaps
; mapno
++)
6814 if (!NILP (maps
[mapno
]))
6815 realmaps
[nmaps1
++] = maps
[mapno
];
6817 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
6822 record_menu_key (XCONS (value
)->car
);
6824 /* If we got multiple events, unread all but
6826 There is no way to prevent those unread events
6827 from showing up later in last_nonmenu_event.
6828 So turn symbol and integer events into lists,
6829 to indicate that they came from a mouse menu,
6830 so that when present in last_nonmenu_event
6831 they won't confuse things. */
6832 for (tem
= XCONS (value
)->cdr
; !NILP (tem
);
6833 tem
= XCONS (tem
)->cdr
)
6835 record_menu_key (XCONS (tem
)->car
);
6836 if (SYMBOLP (XCONS (tem
)->car
)
6837 || INTEGERP (XCONS (tem
)->car
))
6839 = Fcons (XCONS (tem
)->car
, Qnil
);
6842 /* If we got more than one event, put all but the first
6843 onto this list to be read later.
6844 Return just the first event now. */
6845 Vunread_command_events
6846 = nconc2 (XCONS (value
)->cdr
, Vunread_command_events
);
6847 value
= XCONS (value
)->car
;
6849 else if (NILP (value
))
6851 if (used_mouse_menu
)
6852 *used_mouse_menu
= 1;
6855 #endif /* HAVE_MENUS */
6859 /* Buffer in use so far for the minibuf prompts for menu keymaps.
6860 We make this bigger when necessary, and never free it. */
6861 static char *read_char_minibuf_menu_text
;
6862 /* Size of that buffer. */
6863 static int read_char_minibuf_menu_width
;
6866 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
6872 register Lisp_Object name
;
6874 int width
= FRAME_WIDTH (selected_frame
) - 4;
6877 Lisp_Object rest
, vector
;
6880 if (! menu_prompting
)
6883 /* Make sure we have a big enough buffer for the menu text. */
6884 if (read_char_minibuf_menu_text
== 0)
6886 read_char_minibuf_menu_width
= width
+ 4;
6887 read_char_minibuf_menu_text
= (char *) xmalloc (width
+ 4);
6889 else if (width
+ 4 > read_char_minibuf_menu_width
)
6891 read_char_minibuf_menu_width
= width
+ 4;
6892 read_char_minibuf_menu_text
6893 = (char *) xrealloc (read_char_minibuf_menu_text
, width
+ 4);
6895 menu
= read_char_minibuf_menu_text
;
6897 /* Get the menu name from the first map that has one (a prompt string). */
6898 for (mapno
= 0; mapno
< nmaps
; mapno
++)
6900 name
= map_prompt (maps
[mapno
]);
6905 /* If we don't have any menus, just read a character normally. */
6909 /* Prompt string always starts with map's prompt, and a space. */
6910 strcpy (menu
, XSTRING (name
)->data
);
6911 nlength
= STRING_BYTES (XSTRING (name
));
6912 menu
[nlength
++] = ':';
6913 menu
[nlength
++] = ' ';
6916 /* Start prompting at start of first map. */
6920 /* Present the documented bindings, a line at a time. */
6927 Lisp_Object orig_defn_macro
;
6929 /* Loop over elements of map. */
6934 /* If reached end of map, start at beginning of next map. */
6938 /* At end of last map, wrap around to first map if just starting,
6939 or end this line if already have something on it. */
6943 if (notfirst
|| nobindings
) break;
6948 /* Look at the next element of the map. */
6950 elt
= XVECTOR (vector
)->contents
[idx
];
6952 elt
= Fcar_safe (rest
);
6954 if (idx
< 0 && VECTORP (elt
))
6956 /* If we found a dense table in the keymap,
6957 advanced past it, but start scanning its contents. */
6958 rest
= Fcdr_safe (rest
);
6964 /* An ordinary element. */
6965 Lisp_Object event
, tem
;
6969 event
= Fcar_safe (elt
); /* alist */
6970 elt
= Fcdr_safe (elt
);
6974 XSETINT (event
, idx
); /* vector */
6977 /* Ignore the element if it has no prompt string. */
6978 if (INTEGERP (event
) && parse_menu_item (elt
, 0, -1))
6980 /* 1 if the char to type matches the string. */
6982 Lisp_Object upcased_event
, downcased_event
;
6985 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
6987 upcased_event
= Fupcase (event
);
6988 downcased_event
= Fdowncase (event
);
6989 char_matches
= (XINT (upcased_event
) == XSTRING (s
)->data
[0]
6990 || XINT (downcased_event
) == XSTRING (s
)->data
[0]);
6992 desc
= Fsingle_key_description (event
);
6995 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
6997 /* Insert equivalent keybinding. */
6998 s
= concat2 (s
, tem
);
7001 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_TYPE
];
7002 if (EQ (tem
, QCradio
) || EQ (tem
, QCtoggle
))
7004 /* Insert button prefix. */
7005 Lisp_Object selected
7006 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
];
7007 if (EQ (tem
, QCradio
))
7008 tem
= build_string (NILP (selected
) ? "(*) " : "( ) ");
7010 tem
= build_string (NILP (selected
) ? "[X] " : "[ ] ");
7011 s
= concat2 (tem
, s
);
7015 /* If we have room for the prompt string, add it to this line.
7016 If this is the first on the line, always add it. */
7017 if ((XSTRING (s
)->size
+ i
+ 2
7018 + (char_matches
? 0 : XSTRING (desc
)->size
+ 3))
7024 /* Punctuate between strings. */
7027 strcpy (menu
+ i
, ", ");
7033 /* If the char to type doesn't match the string's
7034 first char, explicitly show what char to type. */
7037 /* Add as much of string as fits. */
7038 thiswidth
= XSTRING (desc
)->size
;
7039 if (thiswidth
+ i
> width
)
7040 thiswidth
= width
- i
;
7041 bcopy (XSTRING (desc
)->data
, menu
+ i
, thiswidth
);
7043 strcpy (menu
+ i
, " = ");
7047 /* Add as much of string as fits. */
7048 thiswidth
= XSTRING (s
)->size
;
7049 if (thiswidth
+ i
> width
)
7050 thiswidth
= width
- i
;
7051 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
7057 /* If this element does not fit, end the line now,
7058 and save the element for the next line. */
7059 strcpy (menu
+ i
, "...");
7064 /* Move past this element. */
7065 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
7066 /* Handle reaching end of dense table. */
7071 rest
= Fcdr_safe (rest
);
7075 /* Prompt with that and read response. */
7076 message2_nolog (menu
, strlen (menu
),
7077 ! NILP (current_buffer
->enable_multibyte_characters
));
7079 /* Make believe its not a keyboard macro in case the help char
7080 is pressed. Help characters are not recorded because menu prompting
7081 is not used on replay.
7083 orig_defn_macro
= current_kboard
->defining_kbd_macro
;
7084 current_kboard
->defining_kbd_macro
= Qnil
;
7086 obj
= read_char (commandflag
, 0, 0, Qnil
, 0);
7087 while (BUFFERP (obj
));
7088 current_kboard
->defining_kbd_macro
= orig_defn_macro
;
7090 if (!INTEGERP (obj
))
7095 if (! EQ (obj
, menu_prompt_more_char
)
7096 && (!INTEGERP (menu_prompt_more_char
)
7097 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
7099 if (!NILP (current_kboard
->defining_kbd_macro
))
7100 store_kbd_macro_char (obj
);
7103 /* Help char - go round again */
7107 /* Reading key sequences. */
7109 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
7110 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
7111 keymap, or nil otherwise. Return the index of the first keymap in
7112 which KEY has any binding, or NMAPS if no map has a binding.
7114 If KEY is a meta ASCII character, treat it like meta-prefix-char
7115 followed by the corresponding non-meta character. Keymaps in
7116 CURRENT with non-prefix bindings for meta-prefix-char become nil in
7119 If KEY has no bindings in any of the CURRENT maps, NEXT is left
7122 NEXT may be the same array as CURRENT. */
7125 follow_key (key
, nmaps
, current
, defs
, next
)
7127 Lisp_Object
*current
, *defs
, *next
;
7130 int i
, first_binding
;
7133 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
7134 followed by the corresponding non-meta character.
7135 Put the results into DEFS, since we are going to alter that anyway.
7136 Do not alter CURRENT or NEXT. */
7137 if (INTEGERP (key
) && (XINT (key
) & CHAR_META
))
7139 for (i
= 0; i
< nmaps
; i
++)
7140 if (! NILP (current
[i
]))
7143 def
= get_keyelt (access_keymap (current
[i
],
7144 meta_prefix_char
, 1, 0), 0);
7146 /* Note that since we pass the resulting bindings through
7147 get_keymap_1, non-prefix bindings for meta-prefix-char
7149 defs
[i
] = get_keymap_1 (def
, 0, 1);
7155 XSETINT (key
, XFASTINT (key
) & ~CHAR_META
);
7158 first_binding
= nmaps
;
7159 for (i
= nmaps
- 1; i
>= 0; i
--)
7161 if (! NILP (current
[i
]))
7169 defs
[i
] = get_keyelt (access_keymap (map
, key
, 1, 0), 0);
7170 if (! NILP (defs
[i
]))
7177 /* Given the set of bindings we've found, produce the next set of maps. */
7178 if (first_binding
< nmaps
)
7179 for (i
= 0; i
< nmaps
; i
++)
7180 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0, 1);
7182 return first_binding
;
7185 /* Read a sequence of keys that ends with a non prefix character,
7186 storing it in KEYBUF, a buffer of size BUFSIZE.
7188 Return the length of the key sequence stored.
7189 Return -1 if the user rejected a command menu.
7191 Echo starting immediately unless `prompt' is 0.
7193 Where a key sequence ends depends on the currently active keymaps.
7194 These include any minor mode keymaps active in the current buffer,
7195 the current buffer's local map, and the global map.
7197 If a key sequence has no other bindings, we check Vfunction_key_map
7198 to see if some trailing subsequence might be the beginning of a
7199 function key's sequence. If so, we try to read the whole function
7200 key, and substitute its symbolic name into the key sequence.
7202 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
7203 `double-' events into similar click events, if that would make them
7204 bound. We try to turn `triple-' events first into `double-' events,
7207 If we get a mouse click in a mode line, vertical divider, or other
7208 non-text area, we treat the click as if it were prefixed by the
7209 symbol denoting that area - `mode-line', `vertical-line', or
7212 If the sequence starts with a mouse click, we read the key sequence
7213 with respect to the buffer clicked on, not the current buffer.
7215 If the user switches frames in the midst of a key sequence, we put
7216 off the switch-frame event until later; the next call to
7217 read_char will return it.
7219 If FIX_CURRENT_BUFFER is nonzero, we restore current_buffer
7220 from the selected window's buffer. */
7223 read_key_sequence (keybuf
, bufsize
, prompt
, dont_downcase_last
,
7224 can_return_switch_frame
, fix_current_buffer
)
7225 Lisp_Object
*keybuf
;
7228 int dont_downcase_last
;
7229 int can_return_switch_frame
;
7230 int fix_current_buffer
;
7232 int count
= specpdl_ptr
- specpdl
;
7234 /* How many keys there are in the current key sequence. */
7237 /* The length of the echo buffer when we started reading, and
7238 the length of this_command_keys when we started reading. */
7242 /* The number of keymaps we're scanning right now, and the number of
7243 keymaps we have allocated space for. */
7245 int nmaps_allocated
= 0;
7247 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
7248 the current keymaps. */
7251 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
7252 in the current keymaps, or nil where it is not a prefix. */
7253 Lisp_Object
*submaps
;
7255 /* The local map to start out with at start of key sequence. */
7256 Lisp_Object orig_local_map
;
7258 /* 1 if we have already considered switching to the local-map property
7259 of the place where a mouse click occurred. */
7260 int localized_local_map
= 0;
7262 /* The index in defs[] of the first keymap that has a binding for
7263 this key sequence. In other words, the lowest i such that
7264 defs[i] is non-nil. */
7267 /* If t < mock_input, then KEYBUF[t] should be read as the next
7270 We use this to recover after recognizing a function key. Once we
7271 realize that a suffix of the current key sequence is actually a
7272 function key's escape sequence, we replace the suffix with the
7273 function key's binding from Vfunction_key_map. Now keybuf
7274 contains a new and different key sequence, so the echo area,
7275 this_command_keys, and the submaps and defs arrays are wrong. In
7276 this situation, we set mock_input to t, set t to 0, and jump to
7277 restart_sequence; the loop will read keys from keybuf up until
7278 mock_input, thus rebuilding the state; and then it will resume
7279 reading characters from the keyboard. */
7282 /* If the sequence is unbound in submaps[], then
7283 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
7284 and fkey_map is its binding.
7286 These might be > t, indicating that all function key scanning
7287 should hold off until t reaches them. We do this when we've just
7288 recognized a function key, to avoid searching for the function
7289 key's again in Vfunction_key_map. */
7290 int fkey_start
= 0, fkey_end
= 0;
7291 Lisp_Object fkey_map
;
7293 /* Likewise, for key_translation_map. */
7294 int keytran_start
= 0, keytran_end
= 0;
7295 Lisp_Object keytran_map
;
7297 /* If we receive a ``switch-frame'' event in the middle of a key sequence,
7298 we put it off for later. While we're reading, we keep the event here. */
7299 Lisp_Object delayed_switch_frame
;
7301 /* See the comment below... */
7302 #if defined (GOBBLE_FIRST_EVENT)
7303 Lisp_Object first_event
;
7306 Lisp_Object original_uppercase
;
7307 int original_uppercase_position
= -1;
7309 /* Gets around Microsoft compiler limitations. */
7312 struct buffer
*starting_buffer
;
7314 /* Nonzero if we seem to have got the beginning of a binding
7315 in function_key_map. */
7316 int function_key_possible
= 0;
7317 int key_translation_possible
= 0;
7319 /* Save the status of key translation before each step,
7320 so that we can restore this after downcasing. */
7321 Lisp_Object prev_fkey_map
;
7322 int prev_fkey_start
;
7325 Lisp_Object prev_keytran_map
;
7326 int prev_keytran_start
;
7327 int prev_keytran_end
;
7331 raw_keybuf_count
= 0;
7333 last_nonmenu_event
= Qnil
;
7335 delayed_switch_frame
= Qnil
;
7336 fkey_map
= Vfunction_key_map
;
7337 keytran_map
= Vkey_translation_map
;
7339 /* If there is no function-key-map, turn off function key scanning. */
7340 if (NILP (Fkeymapp (Vfunction_key_map
)))
7341 fkey_start
= fkey_end
= bufsize
+ 1;
7343 /* If there is no key-translation-map, turn off scanning. */
7344 if (NILP (Fkeymapp (Vkey_translation_map
)))
7345 keytran_start
= keytran_end
= bufsize
+ 1;
7350 echo_prompt (XSTRING (prompt
)->data
);
7351 else if (cursor_in_echo_area
&& echo_keystrokes
)
7352 /* This doesn't put in a dash if the echo buffer is empty, so
7353 you don't always see a dash hanging out in the minibuffer. */
7357 /* Record the initial state of the echo area and this_command_keys;
7358 we will need to restore them if we replay a key sequence. */
7360 echo_start
= echo_length ();
7361 keys_start
= this_command_key_count
;
7362 this_single_command_key_start
= keys_start
;
7364 #if defined (GOBBLE_FIRST_EVENT)
7365 /* This doesn't quite work, because some of the things that read_char
7366 does cannot safely be bypassed. It seems too risky to try to make
7369 /* Read the first char of the sequence specially, before setting
7370 up any keymaps, in case a filter runs and switches buffers on us. */
7371 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
7373 #endif /* GOBBLE_FIRST_EVENT */
7375 orig_local_map
= get_local_map (PT
, current_buffer
);
7377 /* We jump here when the key sequence has been thoroughly changed, and
7378 we need to rescan it starting from the beginning. When we jump here,
7379 keybuf[0..mock_input] holds the sequence we should reread. */
7382 starting_buffer
= current_buffer
;
7383 function_key_possible
= 0;
7384 key_translation_possible
= 0;
7386 /* Build our list of keymaps.
7387 If we recognize a function key and replace its escape sequence in
7388 keybuf with its symbol, or if the sequence starts with a mouse
7389 click and we need to switch buffers, we jump back here to rebuild
7390 the initial keymaps from the current buffer. */
7394 if (!NILP (current_kboard
->Voverriding_terminal_local_map
)
7395 || !NILP (Voverriding_local_map
))
7397 if (3 > nmaps_allocated
)
7399 submaps
= (Lisp_Object
*) alloca (3 * sizeof (submaps
[0]));
7400 defs
= (Lisp_Object
*) alloca (3 * sizeof (defs
[0]));
7401 nmaps_allocated
= 3;
7404 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
7405 submaps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
7406 if (!NILP (Voverriding_local_map
))
7407 submaps
[nmaps
++] = Voverriding_local_map
;
7411 nmaps
= current_minor_maps (0, &maps
);
7412 if (nmaps
+ 2 > nmaps_allocated
)
7414 submaps
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (submaps
[0]));
7415 defs
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (defs
[0]));
7416 nmaps_allocated
= nmaps
+ 2;
7418 bcopy (maps
, submaps
, nmaps
* sizeof (submaps
[0]));
7419 #ifdef USE_TEXT_PROPERTIES
7420 submaps
[nmaps
++] = orig_local_map
;
7422 submaps
[nmaps
++] = current_buffer
->keymap
;
7425 submaps
[nmaps
++] = current_global_map
;
7428 /* Find an accurate initial value for first_binding. */
7429 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
7430 if (! NILP (submaps
[first_binding
]))
7433 /* Start from the beginning in keybuf. */
7436 /* These are no-ops the first time through, but if we restart, they
7437 revert the echo area and this_command_keys to their original state. */
7438 this_command_key_count
= keys_start
;
7439 if (INTERACTIVE
&& t
< mock_input
)
7440 echo_truncate (echo_start
);
7442 /* If the best binding for the current key sequence is a keymap, or
7443 we may be looking at a function key's escape sequence, keep on
7445 while ((first_binding
< nmaps
&& ! NILP (submaps
[first_binding
]))
7446 || (first_binding
>= nmaps
7448 /* mock input is never part of a function key's sequence. */
7449 && mock_input
<= fkey_start
)
7450 || (first_binding
>= nmaps
7451 && keytran_start
< t
&& key_translation_possible
)
7452 /* Don't return in the middle of a possible function key sequence,
7453 if the only bindings we found were via case conversion.
7454 Thus, if ESC O a has a function-key-map translation
7455 and ESC o has a binding, don't return after ESC O,
7456 so that we can translate ESC O plus the next character. */
7460 int used_mouse_menu
= 0;
7462 /* Where the last real key started. If we need to throw away a
7463 key that has expanded into more than one element of keybuf
7464 (say, a mouse click on the mode line which is being treated
7465 as [mode-line (mouse-...)], then we backtrack to this point
7467 int last_real_key_start
;
7469 /* These variables are analogous to echo_start and keys_start;
7470 while those allow us to restart the entire key sequence,
7471 echo_local_start and keys_local_start allow us to throw away
7473 int echo_local_start
, keys_local_start
, local_first_binding
;
7476 error ("Key sequence too long");
7479 echo_local_start
= echo_length ();
7480 keys_local_start
= this_command_key_count
;
7481 local_first_binding
= first_binding
;
7484 /* These are no-ops, unless we throw away a keystroke below and
7485 jumped back up to replay_key; in that case, these restore the
7486 variables to their original state, allowing us to replay the
7488 if (INTERACTIVE
&& t
< mock_input
)
7489 echo_truncate (echo_local_start
);
7490 this_command_key_count
= keys_local_start
;
7491 first_binding
= local_first_binding
;
7493 /* By default, assume each event is "real". */
7494 last_real_key_start
= t
;
7496 /* Does mock_input indicate that we are re-reading a key sequence? */
7500 add_command_key (key
);
7501 if (echo_keystrokes
)
7505 /* If not, we should actually read a character. */
7508 struct buffer
*buf
= current_buffer
;
7512 KBOARD
*interrupted_kboard
= current_kboard
;
7513 struct frame
*interrupted_frame
= selected_frame
;
7514 if (setjmp (wrong_kboard_jmpbuf
))
7516 if (!NILP (delayed_switch_frame
))
7518 interrupted_kboard
->kbd_queue
7519 = Fcons (delayed_switch_frame
,
7520 interrupted_kboard
->kbd_queue
);
7521 delayed_switch_frame
= Qnil
;
7524 interrupted_kboard
->kbd_queue
7525 = Fcons (keybuf
[--t
], interrupted_kboard
->kbd_queue
);
7527 /* If the side queue is non-empty, ensure it begins with a
7528 switch-frame, so we'll replay it in the right context. */
7529 if (CONSP (interrupted_kboard
->kbd_queue
)
7530 && (key
= XCONS (interrupted_kboard
->kbd_queue
)->car
,
7531 !(EVENT_HAS_PARAMETERS (key
)
7532 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)),
7536 XSETFRAME (frame
, interrupted_frame
);
7537 interrupted_kboard
->kbd_queue
7538 = Fcons (make_lispy_switch_frame (frame
),
7539 interrupted_kboard
->kbd_queue
);
7542 orig_local_map
= get_local_map (PT
, current_buffer
);
7543 goto replay_sequence
;
7546 key
= read_char (NILP (prompt
), nmaps
, submaps
, last_nonmenu_event
,
7550 /* read_char returns t when it shows a menu and the user rejects it.
7554 unbind_to (count
, Qnil
);
7558 /* read_char returns -1 at the end of a macro.
7559 Emacs 18 handles this by returning immediately with a
7560 zero, so that's what we'll do. */
7561 if (INTEGERP (key
) && XINT (key
) == -1)
7564 /* The Microsoft C compiler can't handle the goto that
7570 /* If the current buffer has been changed from under us, the
7571 keymap may have changed, so replay the sequence. */
7575 /* Reset the current buffer from the selected window
7576 in case something changed the former and not the latter.
7577 This is to be more consistent with the behavior
7578 of the command_loop_1. */
7579 if (fix_current_buffer
)
7581 if (! FRAME_LIVE_P (selected_frame
))
7583 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
7584 Fset_buffer (XWINDOW (selected_window
)->buffer
);
7587 orig_local_map
= get_local_map (PT
, current_buffer
);
7588 goto replay_sequence
;
7591 /* If we have a quit that was typed in another frame, and
7592 quit_throw_to_read_char switched buffers,
7593 replay to get the right keymap. */
7594 if (XINT (key
) == quit_char
&& current_buffer
!= starting_buffer
)
7597 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
7601 orig_local_map
= get_local_map (PT
, current_buffer
);
7602 goto replay_sequence
;
7607 if (EVENT_HAS_PARAMETERS (key
)
7608 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)), Qswitch_frame
))
7610 /* If we're at the beginning of a key sequence, and the caller
7611 says it's okay, go ahead and return this event. If we're
7612 in the midst of a key sequence, delay it until the end. */
7613 if (t
> 0 || !can_return_switch_frame
)
7615 delayed_switch_frame
= key
;
7621 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
7624 /* Clicks in non-text areas get prefixed by the symbol
7625 in their CHAR-ADDRESS field. For example, a click on
7626 the mode line is prefixed by the symbol `mode-line'.
7628 Furthermore, key sequences beginning with mouse clicks
7629 are read using the keymaps of the buffer clicked on, not
7630 the current buffer. So we may have to switch the buffer
7633 When we turn one event into two events, we must make sure
7634 that neither of the two looks like the original--so that,
7635 if we replay the events, they won't be expanded again.
7636 If not for this, such reexpansion could happen either here
7637 or when user programs play with this-command-keys. */
7638 if (EVENT_HAS_PARAMETERS (key
))
7642 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
7643 if (EQ (kind
, Qmouse_click
))
7645 Lisp_Object window
, posn
;
7647 window
= POSN_WINDOW (EVENT_START (key
));
7648 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
7652 /* We're looking at the second event of a
7653 sequence which we expanded before. Set
7654 last_real_key_start appropriately. */
7656 last_real_key_start
= t
- 1;
7659 /* Key sequences beginning with mouse clicks are
7660 read using the keymaps in the buffer clicked on,
7661 not the current buffer. If we're at the
7662 beginning of a key sequence, switch buffers. */
7663 if (last_real_key_start
== 0
7665 && BUFFERP (XWINDOW (window
)->buffer
)
7666 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
7668 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
7672 /* Arrange to go back to the original buffer once we're
7673 done reading the key sequence. Note that we can't
7674 use save_excursion_{save,restore} here, because they
7675 save point as well as the current buffer; we don't
7676 want to save point, because redisplay may change it,
7677 to accommodate a Fset_window_start or something. We
7678 don't want to do this at the top of the function,
7679 because we may get input from a subprocess which
7680 wants to change the selected window and stuff (say,
7682 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
7684 if (! FRAME_LIVE_P (selected_frame
))
7686 set_buffer_internal (XBUFFER (XWINDOW (window
)->buffer
));
7687 orig_local_map
= get_local_map (PT
, current_buffer
);
7688 goto replay_sequence
;
7691 /* For a mouse click, get the local text-property keymap
7692 of the place clicked on, rather than point. */
7693 if (last_real_key_start
== 0
7694 && CONSP (XCONS (key
)->cdr
)
7695 && ! localized_local_map
)
7697 Lisp_Object map_here
, start
, pos
;
7699 localized_local_map
= 1;
7700 start
= EVENT_START (key
);
7702 if (CONSP (start
) && CONSP (XCONS (start
)->cdr
))
7704 pos
= POSN_BUFFER_POSN (start
);
7706 && XINT (pos
) >= BEG
&& XINT (pos
) <= Z
)
7708 map_here
= get_local_map (XINT (pos
), current_buffer
);
7709 if (!EQ (map_here
, orig_local_map
))
7711 orig_local_map
= map_here
;
7715 goto replay_sequence
;
7721 /* Expand mode-line and scroll-bar events into two events:
7722 use posn as a fake prefix key. */
7725 if (t
+ 1 >= bufsize
)
7726 error ("Key sequence too long");
7731 /* Zap the position in key, so we know that we've
7732 expanded it, and don't try to do so again. */
7733 POSN_BUFFER_POSN (EVENT_START (key
))
7734 = Fcons (posn
, Qnil
);
7736 /* If on a mode line string with a local keymap,
7737 reconsider the key sequence with that keymap. */
7738 if (CONSP (POSN_STRING (EVENT_START (key
))))
7740 Lisp_Object string
, pos
, map
;
7742 string
= POSN_STRING (EVENT_START (key
));
7743 pos
= XCDR (string
);
7744 string
= XCAR (string
);
7747 && pos
< XSTRING (string
)->size
7748 && (map
= Fget_text_property (pos
, Qlocal_map
,
7752 orig_local_map
= map
;
7753 goto replay_sequence
;
7760 else if (CONSP (XCONS (key
)->cdr
)
7761 && CONSP (EVENT_START (key
))
7762 && CONSP (XCONS (EVENT_START (key
))->cdr
))
7766 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
7767 /* Handle menu-bar events:
7768 insert the dummy prefix event `menu-bar'. */
7769 if (EQ (posn
, Qmenu_bar
) || EQ (posn
, Qtoolbar
))
7771 if (t
+ 1 >= bufsize
)
7772 error ("Key sequence too long");
7776 /* Zap the position in key, so we know that we've
7777 expanded it, and don't try to do so again. */
7778 POSN_BUFFER_POSN (EVENT_START (key
))
7779 = Fcons (posn
, Qnil
);
7782 goto replay_sequence
;
7784 else if (CONSP (posn
))
7786 /* We're looking at the second event of a
7787 sequence which we expanded before. Set
7788 last_real_key_start appropriately. */
7789 if (last_real_key_start
== t
&& t
> 0)
7790 last_real_key_start
= t
- 1;
7795 /* We have finally decided that KEY is something we might want
7797 first_binding
= (follow_key (key
,
7798 nmaps
- first_binding
,
7799 submaps
+ first_binding
,
7800 defs
+ first_binding
,
7801 submaps
+ first_binding
)
7804 /* If KEY wasn't bound, we'll try some fallbacks. */
7805 if (first_binding
>= nmaps
)
7809 head
= EVENT_HEAD (key
);
7810 if (help_char_p (head
) && t
> 0)
7812 read_key_sequence_cmd
= Vprefix_help_command
;
7814 last_nonmenu_event
= key
;
7815 /* The Microsoft C compiler can't handle the goto that
7823 Lisp_Object breakdown
;
7826 breakdown
= parse_modifiers (head
);
7827 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
7828 /* Attempt to reduce an unbound mouse event to a simpler
7829 event that is bound:
7830 Drags reduce to clicks.
7831 Double-clicks reduce to clicks.
7832 Triple-clicks reduce to double-clicks, then to clicks.
7833 Down-clicks are eliminated.
7834 Double-downs reduce to downs, then are eliminated.
7835 Triple-downs reduce to double-downs, then to downs,
7836 then are eliminated. */
7837 if (modifiers
& (down_modifier
| drag_modifier
7838 | double_modifier
| triple_modifier
))
7840 while (modifiers
& (down_modifier
| drag_modifier
7841 | double_modifier
| triple_modifier
))
7843 Lisp_Object new_head
, new_click
;
7844 if (modifiers
& triple_modifier
)
7845 modifiers
^= (double_modifier
| triple_modifier
);
7846 else if (modifiers
& double_modifier
)
7847 modifiers
&= ~double_modifier
;
7848 else if (modifiers
& drag_modifier
)
7849 modifiers
&= ~drag_modifier
;
7852 /* Dispose of this `down' event by simply jumping
7853 back to replay_key, to get another event.
7855 Note that if this event came from mock input,
7856 then just jumping back to replay_key will just
7857 hand it to us again. So we have to wipe out any
7860 We could delete keybuf[t] and shift everything
7861 after that to the left by one spot, but we'd also
7862 have to fix up any variable that points into
7863 keybuf, and shifting isn't really necessary
7866 Adding prefixes for non-textual mouse clicks
7867 creates two characters of mock input, and both
7868 must be thrown away. If we're only looking at
7869 the prefix now, we can just jump back to
7870 replay_key. On the other hand, if we've already
7871 processed the prefix, and now the actual click
7872 itself is giving us trouble, then we've lost the
7873 state of the keymaps we want to backtrack to, and
7874 we need to replay the whole sequence to rebuild
7877 Beyond that, only function key expansion could
7878 create more than two keys, but that should never
7879 generate mouse events, so it's okay to zero
7880 mock_input in that case too.
7882 Isn't this just the most wonderful code ever? */
7883 if (t
== last_real_key_start
)
7890 mock_input
= last_real_key_start
;
7891 goto replay_sequence
;
7896 = apply_modifiers (modifiers
, XCONS (breakdown
)->car
);
7898 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
7900 /* Look for a binding for this new key. follow_key
7901 promises that it didn't munge submaps the
7902 last time we called it, since key was unbound. */
7904 = (follow_key (new_click
,
7905 nmaps
- local_first_binding
,
7906 submaps
+ local_first_binding
,
7907 defs
+ local_first_binding
,
7908 submaps
+ local_first_binding
)
7909 + local_first_binding
);
7911 /* If that click is bound, go for it. */
7912 if (first_binding
< nmaps
)
7917 /* Otherwise, we'll leave key set to the drag event. */
7924 /* Normally, last_nonmenu_event gets the previous key we read.
7925 But when a mouse popup menu is being used,
7926 we don't update last_nonmenu_event; it continues to hold the mouse
7927 event that preceded the first level of menu. */
7928 if (!used_mouse_menu
)
7929 last_nonmenu_event
= key
;
7931 /* Record what part of this_command_keys is the current key sequence. */
7932 this_single_command_key_start
= this_command_key_count
- t
;
7934 prev_fkey_map
= fkey_map
;
7935 prev_fkey_start
= fkey_start
;
7936 prev_fkey_end
= fkey_end
;
7938 prev_keytran_map
= keytran_map
;
7939 prev_keytran_start
= keytran_start
;
7940 prev_keytran_end
= keytran_end
;
7942 /* If the sequence is unbound, see if we can hang a function key
7943 off the end of it. We only want to scan real keyboard input
7944 for function key sequences, so if mock_input says that we're
7945 re-reading old events, don't examine it. */
7946 if (first_binding
>= nmaps
7949 Lisp_Object fkey_next
;
7951 /* Continue scan from fkey_end until we find a bound suffix.
7952 If we fail, increment fkey_start
7953 and start fkey_end from there. */
7954 while (fkey_end
< t
)
7958 key
= keybuf
[fkey_end
++];
7959 /* Look up meta-characters by prefixing them
7960 with meta_prefix_char. I hate this. */
7961 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
7966 (access_keymap (fkey_map
, meta_prefix_char
, 1, 0), 0),
7968 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
7971 fkey_next
= fkey_map
;
7974 = get_keyelt (access_keymap (fkey_next
, key
, 1, 0), 1);
7976 /* Handle symbol with autoload definition. */
7977 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
7978 && CONSP (XSYMBOL (fkey_next
)->function
)
7979 && EQ (XCONS (XSYMBOL (fkey_next
)->function
)->car
, Qautoload
))
7980 do_autoload (XSYMBOL (fkey_next
)->function
,
7983 /* Handle a symbol whose function definition is a keymap
7985 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
7986 && (!NILP (Farrayp (XSYMBOL (fkey_next
)->function
))
7987 || !NILP (Fkeymapp (XSYMBOL (fkey_next
)->function
))))
7988 fkey_next
= XSYMBOL (fkey_next
)->function
;
7990 #if 0 /* I didn't turn this on, because it might cause trouble
7991 for the mapping of return into C-m and tab into C-i. */
7992 /* Optionally don't map function keys into other things.
7993 This enables the user to redefine kp- keys easily. */
7994 if (SYMBOLP (key
) && !NILP (Vinhibit_function_key_mapping
))
7998 /* If the function key map gives a function, not an
7999 array, then call the function with no args and use
8000 its value instead. */
8001 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
8004 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8008 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
8009 fkey_next
= call1 (fkey_next
, prompt
);
8011 /* If the function returned something invalid,
8012 barf--don't ignore it.
8013 (To ignore it safely, we would need to gcpro a bunch of
8014 other variables.) */
8015 if (! (VECTORP (fkey_next
) || STRINGP (fkey_next
)))
8016 error ("Function in key-translation-map returns invalid key sequence");
8019 function_key_possible
= ! NILP (fkey_next
);
8021 /* If keybuf[fkey_start..fkey_end] is bound in the
8022 function key map and it's a suffix of the current
8023 sequence (i.e. fkey_end == t), replace it with
8024 the binding and restart with fkey_start at the end. */
8025 if ((VECTORP (fkey_next
) || STRINGP (fkey_next
))
8028 int len
= XFASTINT (Flength (fkey_next
));
8030 t
= fkey_start
+ len
;
8032 error ("Key sequence too long");
8034 if (VECTORP (fkey_next
))
8035 bcopy (XVECTOR (fkey_next
)->contents
,
8036 keybuf
+ fkey_start
,
8037 (t
- fkey_start
) * sizeof (keybuf
[0]));
8038 else if (STRINGP (fkey_next
))
8042 for (i
= 0; i
< len
; i
++)
8043 XSETFASTINT (keybuf
[fkey_start
+ i
],
8044 XSTRING (fkey_next
)->data
[i
]);
8048 fkey_start
= fkey_end
= t
;
8049 fkey_map
= Vfunction_key_map
;
8051 /* Do pass the results through key-translation-map.
8052 But don't retranslate what key-translation-map
8053 has already translated. */
8054 keytran_end
= keytran_start
;
8055 keytran_map
= Vkey_translation_map
;
8057 goto replay_sequence
;
8060 fkey_map
= get_keymap_1 (fkey_next
, 0, 1);
8062 /* If we no longer have a bound suffix, try a new positions for
8064 if (NILP (fkey_map
))
8066 fkey_end
= ++fkey_start
;
8067 fkey_map
= Vfunction_key_map
;
8068 function_key_possible
= 0;
8073 /* Look for this sequence in key-translation-map. */
8075 Lisp_Object keytran_next
;
8077 /* Scan from keytran_end until we find a bound suffix. */
8078 while (keytran_end
< t
)
8082 key
= keybuf
[keytran_end
++];
8083 /* Look up meta-characters by prefixing them
8084 with meta_prefix_char. I hate this. */
8085 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
8090 (access_keymap (keytran_map
, meta_prefix_char
, 1, 0), 0),
8092 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
8095 keytran_next
= keytran_map
;
8098 = get_keyelt (access_keymap (keytran_next
, key
, 1, 0), 1);
8100 /* Handle symbol with autoload definition. */
8101 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
8102 && CONSP (XSYMBOL (keytran_next
)->function
)
8103 && EQ (XCONS (XSYMBOL (keytran_next
)->function
)->car
, Qautoload
))
8104 do_autoload (XSYMBOL (keytran_next
)->function
,
8107 /* Handle a symbol whose function definition is a keymap
8109 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
8110 && (!NILP (Farrayp (XSYMBOL (keytran_next
)->function
))
8111 || !NILP (Fkeymapp (XSYMBOL (keytran_next
)->function
))))
8112 keytran_next
= XSYMBOL (keytran_next
)->function
;
8114 /* If the key translation map gives a function, not an
8115 array, then call the function with one arg and use
8116 its value instead. */
8117 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
8118 && keytran_end
== t
)
8120 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8124 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
8125 keytran_next
= call1 (keytran_next
, prompt
);
8127 /* If the function returned something invalid,
8128 barf--don't ignore it.
8129 (To ignore it safely, we would need to gcpro a bunch of
8130 other variables.) */
8131 if (! (VECTORP (keytran_next
) || STRINGP (keytran_next
)))
8132 error ("Function in key-translation-map returns invalid key sequence");
8135 key_translation_possible
= ! NILP (keytran_next
);
8137 /* If keybuf[keytran_start..keytran_end] is bound in the
8138 key translation map and it's a suffix of the current
8139 sequence (i.e. keytran_end == t), replace it with
8140 the binding and restart with keytran_start at the end. */
8141 if ((VECTORP (keytran_next
) || STRINGP (keytran_next
))
8142 && keytran_end
== t
)
8144 int len
= XFASTINT (Flength (keytran_next
));
8146 t
= keytran_start
+ len
;
8148 error ("Key sequence too long");
8150 if (VECTORP (keytran_next
))
8151 bcopy (XVECTOR (keytran_next
)->contents
,
8152 keybuf
+ keytran_start
,
8153 (t
- keytran_start
) * sizeof (keybuf
[0]));
8154 else if (STRINGP (keytran_next
))
8158 for (i
= 0; i
< len
; i
++)
8159 XSETFASTINT (keybuf
[keytran_start
+ i
],
8160 XSTRING (keytran_next
)->data
[i
]);
8164 keytran_start
= keytran_end
= t
;
8165 keytran_map
= Vkey_translation_map
;
8167 /* Don't pass the results of key-translation-map
8168 through function-key-map. */
8169 fkey_start
= fkey_end
= t
;
8170 fkey_map
= Vfunction_key_map
;
8172 goto replay_sequence
;
8175 keytran_map
= get_keymap_1 (keytran_next
, 0, 1);
8177 /* If we no longer have a bound suffix, try a new positions for
8179 if (NILP (keytran_map
))
8181 keytran_end
= ++keytran_start
;
8182 keytran_map
= Vkey_translation_map
;
8183 key_translation_possible
= 0;
8188 /* If KEY is not defined in any of the keymaps,
8189 and cannot be part of a function key or translation,
8190 and is an upper case letter
8191 use the corresponding lower-case letter instead. */
8192 if (first_binding
== nmaps
&& ! function_key_possible
8193 && ! key_translation_possible
8195 && ((((XINT (key
) & 0x3ffff)
8196 < XCHAR_TABLE (current_buffer
->downcase_table
)->size
)
8197 && UPPERCASEP (XINT (key
) & 0x3ffff))
8198 || (XINT (key
) & shift_modifier
)))
8200 Lisp_Object new_key
;
8202 original_uppercase
= key
;
8203 original_uppercase_position
= t
- 1;
8205 if (XINT (key
) & shift_modifier
)
8206 XSETINT (new_key
, XINT (key
) & ~shift_modifier
);
8208 XSETINT (new_key
, (DOWNCASE (XINT (key
) & 0x3ffff)
8209 | (XINT (key
) & ~0x3ffff)));
8211 /* We have to do this unconditionally, regardless of whether
8212 the lower-case char is defined in the keymaps, because they
8213 might get translated through function-key-map. */
8214 keybuf
[t
- 1] = new_key
;
8217 fkey_map
= prev_fkey_map
;
8218 fkey_start
= prev_fkey_start
;
8219 fkey_end
= prev_fkey_end
;
8221 keytran_map
= prev_keytran_map
;
8222 keytran_start
= prev_keytran_start
;
8223 keytran_end
= prev_keytran_end
;
8225 goto replay_sequence
;
8227 /* If KEY is not defined in any of the keymaps,
8228 and cannot be part of a function key or translation,
8229 and is a shifted function key,
8230 use the corresponding unshifted function key instead. */
8231 if (first_binding
== nmaps
&& ! function_key_possible
8232 && ! key_translation_possible
8235 Lisp_Object breakdown
;
8238 breakdown
= parse_modifiers (key
);
8239 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
8240 if (modifiers
& shift_modifier
)
8242 Lisp_Object new_key
;
8244 original_uppercase
= key
;
8245 original_uppercase_position
= t
- 1;
8247 modifiers
&= ~shift_modifier
;
8248 new_key
= apply_modifiers (modifiers
,
8249 XCONS (breakdown
)->car
);
8251 keybuf
[t
- 1] = new_key
;
8254 fkey_map
= prev_fkey_map
;
8255 fkey_start
= prev_fkey_start
;
8256 fkey_end
= prev_fkey_end
;
8258 keytran_map
= prev_keytran_map
;
8259 keytran_start
= prev_keytran_start
;
8260 keytran_end
= prev_keytran_end
;
8262 goto replay_sequence
;
8268 read_key_sequence_cmd
= (first_binding
< nmaps
8269 ? defs
[first_binding
]
8272 unread_switch_frame
= delayed_switch_frame
;
8273 unbind_to (count
, Qnil
);
8275 /* Don't downcase the last character if the caller says don't.
8276 Don't downcase it if the result is undefined, either. */
8277 if ((dont_downcase_last
|| first_binding
>= nmaps
)
8278 && t
- 1 == original_uppercase_position
)
8279 keybuf
[t
- 1] = original_uppercase
;
8281 /* Occasionally we fabricate events, perhaps by expanding something
8282 according to function-key-map, or by adding a prefix symbol to a
8283 mouse click in the scroll bar or modeline. In this cases, return
8284 the entire generated key sequence, even if we hit an unbound
8285 prefix or a definition before the end. This means that you will
8286 be able to push back the event properly, and also means that
8287 read-key-sequence will always return a logical unit.
8290 for (; t
< mock_input
; t
++)
8292 if (echo_keystrokes
)
8293 echo_char (keybuf
[t
]);
8294 add_command_key (keybuf
[t
]);
8302 #if 0 /* This doc string is too long for some compilers.
8303 This commented-out definition serves for DOC. */
8304 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
8305 "Read a sequence of keystrokes and return as a string or vector.\n\
8306 The sequence is sufficient to specify a non-prefix command in the\n\
8307 current local and global maps.\n\
8309 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
8310 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
8311 as a continuation of the previous key.\n\
8313 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not\n\
8314 convert the last event to lower case. (Normally any upper case event\n\
8315 is converted to lower case if the original event is undefined and the lower\n\
8316 case equivalent is defined.) A non-nil value is appropriate for reading\n\
8317 a key sequence to be defined.\n\
8319 A C-g typed while in this function is treated like any other character,\n\
8320 and `quit-flag' is not set.\n\
8322 If the key sequence starts with a mouse click, then the sequence is read\n\
8323 using the keymaps of the buffer of the window clicked in, not the buffer\n\
8324 of the selected window as normal.\n\
8326 `read-key-sequence' drops unbound button-down events, since you normally\n\
8327 only care about the click or drag events which follow them. If a drag\n\
8328 or multi-click event is unbound, but the corresponding click event would\n\
8329 be bound, `read-key-sequence' turns the event into a click event at the\n\
8330 drag's starting position. This means that you don't have to distinguish\n\
8331 between click and drag, double, or triple events unless you want to.\n\
8333 `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\
8334 lines separating windows, and scroll bars with imaginary keys\n\
8335 `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\
8337 Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this\n\
8338 function will process a switch-frame event if the user switches frames\n\
8339 before typing anything. If the user switches frames in the middle of a\n\
8340 key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME\n\
8341 is nil, then the event will be put off until after the current key sequence.\n\
8343 `read-key-sequence' checks `function-key-map' for function key\n\
8344 sequences, where they wouldn't conflict with ordinary bindings. See\n\
8345 `function-key-map' for more details.\n\
8347 The optional fifth argument COMMAND-LOOP, if non-nil, means\n\
8348 that this key sequence is being read by something that will\n\
8349 read commands one after another. It should be nil if the caller\n\
8350 will read just one key sequence.")
8351 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
, command
-loop
)
8354 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 5, 0,
8356 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
8358 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
8359 Lisp_Object can_return_switch_frame
, command_loop
;
8361 Lisp_Object keybuf
[30];
8363 struct gcpro gcpro1
, gcpro2
;
8364 int count
= specpdl_ptr
- specpdl
;
8367 CHECK_STRING (prompt
, 0);
8370 specbind (Qinput_method_exit_on_first_char
,
8371 (NILP (command_loop
) ? Qt
: Qnil
));
8372 specbind (Qinput_method_use_echo_area
,
8373 (NILP (command_loop
) ? Qt
: Qnil
));
8375 bzero (keybuf
, sizeof keybuf
);
8377 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
8379 if (NILP (continue_echo
))
8381 this_command_key_count
= 0;
8382 this_single_command_key_start
= 0;
8385 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
8386 prompt
, ! NILP (dont_downcase_last
),
8387 ! NILP (can_return_switch_frame
), 0);
8395 return unbind_to (count
, make_event_array (i
, keybuf
));
8398 DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector
,
8399 Sread_key_sequence_vector
, 1, 5, 0,
8400 "Like `read-key-sequence' but always return a vector.")
8401 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
8403 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
8404 Lisp_Object can_return_switch_frame
, command_loop
;
8406 Lisp_Object keybuf
[30];
8408 struct gcpro gcpro1
, gcpro2
;
8409 int count
= specpdl_ptr
- specpdl
;
8412 CHECK_STRING (prompt
, 0);
8415 specbind (Qinput_method_exit_on_first_char
,
8416 (NILP (command_loop
) ? Qt
: Qnil
));
8417 specbind (Qinput_method_use_echo_area
,
8418 (NILP (command_loop
) ? Qt
: Qnil
));
8420 bzero (keybuf
, sizeof keybuf
);
8422 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
8424 if (NILP (continue_echo
))
8426 this_command_key_count
= 0;
8427 this_single_command_key_start
= 0;
8430 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
8431 prompt
, ! NILP (dont_downcase_last
),
8432 ! NILP (can_return_switch_frame
), 0);
8440 return unbind_to (count
, Fvector (i
, keybuf
));
8443 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 4, 0,
8444 "Execute CMD as an editor command.\n\
8445 CMD must be a symbol that satisfies the `commandp' predicate.\n\
8446 Optional second arg RECORD-FLAG non-nil\n\
8447 means unconditionally put this command in `command-history'.\n\
8448 Otherwise, that is done only if an arg is read using the minibuffer.\n\
8449 The argument KEYS specifies the value to use instead of (this-command-keys)\n\
8450 when reading the arguments; if it is nil, (this-command-keys) is used.\n\
8451 The argument SPECIAL, if non-nil, means that this command is executing\n\
8452 a special event, so ignore the prefix argument and don't clear it.")
8453 (cmd
, record_flag
, keys
, special
)
8454 Lisp_Object cmd
, record_flag
, keys
, special
;
8456 register Lisp_Object final
;
8457 register Lisp_Object tem
;
8458 Lisp_Object prefixarg
;
8459 struct backtrace backtrace
;
8460 extern int debug_on_next_call
;
8462 debug_on_next_call
= 0;
8466 prefixarg
= current_kboard
->Vprefix_arg
;
8467 Vcurrent_prefix_arg
= prefixarg
;
8468 current_kboard
->Vprefix_arg
= Qnil
;
8475 tem
= Fget (cmd
, Qdisabled
);
8476 if (!NILP (tem
) && !NILP (Vrun_hooks
))
8478 tem
= Fsymbol_value (Qdisabled_command_hook
);
8480 return call1 (Vrun_hooks
, Qdisabled_command_hook
);
8486 final
= Findirect_function (cmd
);
8488 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
8490 struct gcpro gcpro1
, gcpro2
;
8492 GCPRO2 (cmd
, prefixarg
);
8493 do_autoload (final
, cmd
);
8500 if (STRINGP (final
) || VECTORP (final
))
8502 /* If requested, place the macro in the command history. For
8503 other sorts of commands, call-interactively takes care of
8505 if (!NILP (record_flag
))
8508 = Fcons (Fcons (Qexecute_kbd_macro
,
8509 Fcons (final
, Fcons (prefixarg
, Qnil
))),
8512 /* Don't keep command history around forever. */
8513 if (NUMBERP (Vhistory_length
) && XINT (Vhistory_length
) > 0)
8515 tem
= Fnthcdr (Vhistory_length
, Vcommand_history
);
8517 XCONS (tem
)->cdr
= Qnil
;
8521 return Fexecute_kbd_macro (final
, prefixarg
);
8524 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
8526 backtrace
.next
= backtrace_list
;
8527 backtrace_list
= &backtrace
;
8528 backtrace
.function
= &Qcall_interactively
;
8529 backtrace
.args
= &cmd
;
8530 backtrace
.nargs
= 1;
8531 backtrace
.evalargs
= 0;
8533 tem
= Fcall_interactively (cmd
, record_flag
, keys
);
8535 backtrace_list
= backtrace
.next
;
8541 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
8543 "Read function name, then read its arguments and call it.")
8545 Lisp_Object prefixarg
;
8547 Lisp_Object function
;
8549 Lisp_Object saved_keys
;
8550 Lisp_Object bindings
, value
;
8551 struct gcpro gcpro1
, gcpro2
;
8553 saved_keys
= Fvector (this_command_key_count
,
8554 XVECTOR (this_command_keys
)->contents
);
8556 GCPRO2 (saved_keys
, prefixarg
);
8558 if (EQ (prefixarg
, Qminus
))
8560 else if (CONSP (prefixarg
) && XINT (XCONS (prefixarg
)->car
) == 4)
8561 strcpy (buf
, "C-u ");
8562 else if (CONSP (prefixarg
) && INTEGERP (XCONS (prefixarg
)->car
))
8564 if (sizeof (int) == sizeof (EMACS_INT
))
8565 sprintf (buf
, "%d ", XINT (XCONS (prefixarg
)->car
));
8566 else if (sizeof (long) == sizeof (EMACS_INT
))
8567 sprintf (buf
, "%ld ", XINT (XCONS (prefixarg
)->car
));
8571 else if (INTEGERP (prefixarg
))
8573 if (sizeof (int) == sizeof (EMACS_INT
))
8574 sprintf (buf
, "%d ", XINT (prefixarg
));
8575 else if (sizeof (long) == sizeof (EMACS_INT
))
8576 sprintf (buf
, "%ld ", XINT (prefixarg
));
8581 /* This isn't strictly correct if execute-extended-command
8582 is bound to anything else. Perhaps it should use
8583 this_command_keys? */
8584 strcat (buf
, "M-x ");
8586 /* Prompt with buf, and then read a string, completing from and
8587 restricting to the set of all defined commands. Don't provide
8588 any initial input. Save the command read on the extended-command
8590 function
= Fcompleting_read (build_string (buf
),
8591 Vobarray
, Qcommandp
,
8592 Qt
, Qnil
, Qextended_command_history
, Qnil
,
8595 if (STRINGP (function
) && XSTRING (function
)->size
== 0)
8596 error ("No command name given");
8598 /* Set this_command_keys to the concatenation of saved_keys and
8599 function, followed by a RET. */
8601 struct Lisp_String
*str
;
8605 this_command_key_count
= 0;
8606 this_single_command_key_start
= 0;
8608 keys
= XVECTOR (saved_keys
)->contents
;
8609 for (i
= 0; i
< XVECTOR (saved_keys
)->size
; i
++)
8610 add_command_key (keys
[i
]);
8612 str
= XSTRING (function
);
8613 for (i
= 0; i
< str
->size
; i
++)
8614 add_command_key (Faref (function
, make_number (i
)));
8616 add_command_key (make_number ('\015'));
8621 function
= Fintern (function
, Qnil
);
8622 current_kboard
->Vprefix_arg
= prefixarg
;
8623 Vthis_command
= function
;
8624 real_this_command
= function
;
8626 /* If enabled, show which key runs this command. */
8627 if (!NILP (Vsuggest_key_bindings
)
8628 && NILP (Vexecuting_macro
)
8629 && SYMBOLP (function
))
8630 bindings
= Fwhere_is_internal (function
, Voverriding_local_map
,
8636 GCPRO2 (bindings
, value
);
8637 value
= Fcommand_execute (function
, Qt
, Qnil
, Qnil
);
8639 /* If the command has a key binding, print it now. */
8640 if (!NILP (bindings
)
8641 && ! (VECTORP (bindings
) && EQ (Faref (bindings
, make_number (0)),
8644 /* But first wait, and skip the message if there is input. */
8646 if (echo_area_glyphs
!= 0 || STRINGP (echo_area_message
))
8647 /* This command displayed something in the echo area;
8648 so wait a few seconds, then display our suggestion message. */
8649 delay_time
= (NUMBERP (Vsuggest_key_bindings
)
8650 ? XINT (Vsuggest_key_bindings
) : 2);
8652 /* This command left the echo area empty,
8653 so display our message immediately. */
8656 if (!NILP (Fsit_for (make_number (delay_time
), Qnil
, Qnil
))
8657 && ! CONSP (Vunread_command_events
))
8659 Lisp_Object binding
;
8661 char *oldmessage
= echo_area_glyphs
;
8662 Lisp_Object oldmessage_string
= echo_area_message
;
8663 int oldmessage_len
= echo_area_glyphs_length
;
8664 int oldmultibyte
= message_enable_multibyte
;
8666 binding
= Fkey_description (bindings
);
8669 = (char *) alloca (XSYMBOL (function
)->name
->size
8670 + STRING_BYTES (XSTRING (binding
))
8672 sprintf (newmessage
, "You can run the command `%s' with %s",
8673 XSYMBOL (function
)->name
->data
,
8674 XSTRING (binding
)->data
);
8675 message2_nolog (newmessage
,
8676 strlen (newmessage
),
8677 STRING_MULTIBYTE (binding
));
8678 if (!NILP (Fsit_for ((NUMBERP (Vsuggest_key_bindings
)
8679 ? Vsuggest_key_bindings
: make_number (2)),
8682 if (STRINGP (oldmessage_string
))
8683 message3_nolog (oldmessage_string
, oldmessage_len
,
8686 message2_nolog (oldmessage
, oldmessage_len
, oldmultibyte
);
8691 RETURN_UNGCPRO (value
);
8694 /* Find the set of keymaps now active.
8695 Store into *MAPS_P a vector holding the various maps
8696 and return the number of them. The vector was malloc'd
8697 and the caller should free it. */
8700 current_active_maps (maps_p
)
8701 Lisp_Object
**maps_p
;
8703 Lisp_Object
*tmaps
, *maps
;
8706 /* Should overriding-terminal-local-map and overriding-local-map apply? */
8707 if (!NILP (Voverriding_local_map_menu_flag
))
8709 /* Yes, use them (if non-nil) as well as the global map. */
8710 maps
= (Lisp_Object
*) xmalloc (3 * sizeof (maps
[0]));
8712 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
8713 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
8714 if (!NILP (Voverriding_local_map
))
8715 maps
[nmaps
++] = Voverriding_local_map
;
8719 /* No, so use major and minor mode keymaps. */
8720 nmaps
= current_minor_maps (NULL
, &tmaps
);
8721 maps
= (Lisp_Object
*) xmalloc ((nmaps
+ 2) * sizeof (maps
[0]));
8722 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
8723 #ifdef USE_TEXT_PROPERTIES
8724 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
8726 maps
[nmaps
++] = current_buffer
->keymap
;
8729 maps
[nmaps
++] = current_global_map
;
8735 /* Return nonzero if input events are pending. */
8738 detect_input_pending ()
8741 get_input_pending (&input_pending
, 0);
8743 return input_pending
;
8746 /* Return nonzero if input events are pending, and run any pending timers. */
8749 detect_input_pending_run_timers (do_display
)
8752 int old_timers_run
= timers_run
;
8755 get_input_pending (&input_pending
, 1);
8757 if (old_timers_run
!= timers_run
&& do_display
)
8759 redisplay_preserve_echo_area ();
8760 /* The following fixes a bug when using lazy-lock with
8761 lazy-lock-defer-on-the-fly set to t, i.e. when fontifying
8762 from an idle timer function. The symptom of the bug is that
8763 the cursor sometimes doesn't become visible until the next X
8764 event is processed. --gerd. */
8766 rif
->flush_display (NULL
);
8769 return input_pending
;
8772 /* This is called in some cases before a possible quit.
8773 It cases the next call to detect_input_pending to recompute input_pending.
8774 So calling this function unnecessarily can't do any harm. */
8777 clear_input_pending ()
8782 /* Return nonzero if there are pending requeued events.
8783 This isn't used yet. The hope is to make wait_reading_process_input
8784 call it, and return return if it runs Lisp code that unreads something.
8785 The problem is, kbd_buffer_get_event needs to be fixed to know what
8786 to do in that case. It isn't trivial. */
8789 requeued_events_pending_p ()
8791 return (!NILP (Vunread_command_events
) || unread_command_char
!= -1);
8795 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
8796 "T if command input is currently available with no waiting.\n\
8797 Actually, the value is nil only if we can be sure that no input is available.")
8800 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1)
8803 get_input_pending (&input_pending
, 1);
8804 return input_pending
> 0 ? Qt
: Qnil
;
8807 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
8808 "Return vector of last 100 events, not counting those from keyboard macros.")
8811 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
8814 if (total_keys
< NUM_RECENT_KEYS
)
8815 return Fvector (total_keys
, keys
);
8818 val
= Fvector (NUM_RECENT_KEYS
, keys
);
8819 bcopy (keys
+ recent_keys_index
,
8820 XVECTOR (val
)->contents
,
8821 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
8823 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
8824 recent_keys_index
* sizeof (Lisp_Object
));
8829 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
8830 "Return the key sequence that invoked this command.\n\
8831 The value is a string or a vector.")
8834 return make_event_array (this_command_key_count
,
8835 XVECTOR (this_command_keys
)->contents
);
8838 DEFUN ("this-command-keys-vector", Fthis_command_keys_vector
, Sthis_command_keys_vector
, 0, 0, 0,
8839 "Return the key sequence that invoked this command, as a vector.")
8842 return Fvector (this_command_key_count
,
8843 XVECTOR (this_command_keys
)->contents
);
8846 DEFUN ("this-single-command-keys", Fthis_single_command_keys
,
8847 Sthis_single_command_keys
, 0, 0, 0,
8848 "Return the key sequence that invoked this command.\n\
8849 Unlike `this-command-keys', this function's value\n\
8850 does not include prefix arguments.\n\
8851 The value is always a vector.")
8854 return Fvector (this_command_key_count
8855 - this_single_command_key_start
,
8856 (XVECTOR (this_command_keys
)->contents
8857 + this_single_command_key_start
));
8860 DEFUN ("this-single-command-raw-keys", Fthis_single_command_raw_keys
,
8861 Sthis_single_command_raw_keys
, 0, 0, 0,
8862 "Return the raw events that were read for this command.\n\
8863 Unlike `this-single-command-keys', this function's value\n\
8864 shows the events before all translations (except for input methods).\n\
8865 The value is always a vector.")
8868 return Fvector (raw_keybuf_count
,
8869 (XVECTOR (raw_keybuf
)->contents
));
8872 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths
,
8873 Sreset_this_command_lengths
, 0, 0, 0,
8874 "Used for complicated reasons in `universal-argument-other-key'.\n\
8876 `universal-argument-other-key' rereads the event just typed.\n\
8877 It then gets translated through `function-key-map'.\n\
8878 The translated event gets included in the echo area and in\n\
8879 the value of `this-command-keys' in addition to the raw original event.\n\
8880 That is not right.\n\
8882 Calling this function directs the translated event to replace\n\
8883 the original event, so that only one version of the event actually\n\
8884 appears in the echo area and in the value of `this-command-keys.'.")
8887 before_command_restore_flag
= 1;
8888 before_command_key_count_1
= before_command_key_count
;
8889 before_command_echo_length_1
= before_command_echo_length
;
8893 DEFUN ("clear-this-command-keys", Fclear_this_command_keys
,
8894 Sclear_this_command_keys
, 0, 0, 0,
8895 "Clear out the vector that `this-command-keys' returns.")
8898 this_command_key_count
= 0;
8902 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
8903 "Return the current depth in recursive edits.")
8907 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
8911 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
8912 "FOpen dribble file: ",
8913 "Start writing all keyboard characters to a dribble file called FILE.\n\
8914 If FILE is nil, close any open dribble file.")
8925 file
= Fexpand_file_name (file
, Qnil
);
8926 dribble
= fopen (XSTRING (file
)->data
, "w");
8928 report_file_error ("Opening dribble", Fcons (file
, Qnil
));
8933 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
8934 "Discard the contents of the terminal input buffer.\n\
8935 Also cancel any kbd macro being defined.")
8938 current_kboard
->defining_kbd_macro
= Qnil
;
8939 update_mode_lines
++;
8941 Vunread_command_events
= Qnil
;
8942 unread_command_char
= -1;
8944 discard_tty_input ();
8946 kbd_fetch_ptr
= kbd_store_ptr
;
8947 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
8953 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
8954 "Stop Emacs and return to superior process. You can resume later.\n\
8955 If `cannot-suspend' is non-nil, or if the system doesn't support job\n\
8956 control, run a subshell instead.\n\n\
8957 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
8958 to be read as terminal input by Emacs's parent, after suspension.\n\
8960 Before suspending, run the normal hook `suspend-hook'.\n\
8961 After resumption run the normal hook `suspend-resume-hook'.\n\
8963 Some operating systems cannot stop the Emacs process and resume it later.\n\
8964 On such systems, Emacs starts a subshell instead of suspending.")
8966 Lisp_Object stuffstring
;
8969 int count
= specpdl_ptr
- specpdl
;
8970 int old_height
, old_width
;
8972 struct gcpro gcpro1
, gcpro2
;
8974 if (!NILP (stuffstring
))
8975 CHECK_STRING (stuffstring
, 0);
8977 /* Run the functions in suspend-hook. */
8978 if (!NILP (Vrun_hooks
))
8979 call1 (Vrun_hooks
, intern ("suspend-hook"));
8981 GCPRO1 (stuffstring
);
8982 get_frame_size (&old_width
, &old_height
);
8984 /* sys_suspend can get an error if it tries to fork a subshell
8985 and the system resources aren't available for that. */
8986 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object
))) init_sys_modes
,
8988 stuff_buffered_input (stuffstring
);
8993 unbind_to (count
, Qnil
);
8995 /* Check if terminal/window size has changed.
8996 Note that this is not useful when we are running directly
8997 with a window system; but suspend should be disabled in that case. */
8998 get_frame_size (&width
, &height
);
8999 if (width
!= old_width
|| height
!= old_height
)
9000 change_frame_size (selected_frame
, height
, width
, 0, 0);
9002 /* Run suspend-resume-hook. */
9003 if (!NILP (Vrun_hooks
))
9004 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
9010 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
9011 Then in any case stuff anything Emacs has read ahead and not used. */
9014 stuff_buffered_input (stuffstring
)
9015 Lisp_Object stuffstring
;
9017 /* stuff_char works only in BSD, versions 4.2 and up. */
9020 register unsigned char *p
;
9022 if (STRINGP (stuffstring
))
9026 p
= XSTRING (stuffstring
)->data
;
9027 count
= STRING_BYTES (XSTRING (stuffstring
));
9032 /* Anything we have read ahead, put back for the shell to read. */
9033 /* ?? What should this do when we have multiple keyboards??
9034 Should we ignore anything that was typed in at the "wrong" kboard? */
9035 for (; kbd_fetch_ptr
!= kbd_store_ptr
; kbd_fetch_ptr
++)
9037 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
9038 kbd_fetch_ptr
= kbd_buffer
;
9039 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
9040 stuff_char (kbd_fetch_ptr
->code
);
9041 kbd_fetch_ptr
->kind
= no_event
;
9042 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_fetch_ptr
9048 #endif /* BSD_SYSTEM and not BSD4_1 */
9052 set_waiting_for_input (time_to_clear
)
9053 EMACS_TIME
*time_to_clear
;
9055 input_available_clear_time
= time_to_clear
;
9057 /* Tell interrupt_signal to throw back to read_char, */
9058 waiting_for_input
= 1;
9060 /* If interrupt_signal was called before and buffered a C-g,
9061 make it run again now, to avoid timing error. */
9062 if (!NILP (Vquit_flag
))
9063 quit_throw_to_read_char ();
9067 clear_waiting_for_input ()
9069 /* Tell interrupt_signal not to throw back to read_char, */
9070 waiting_for_input
= 0;
9071 input_available_clear_time
= 0;
9074 /* This routine is called at interrupt level in response to C-G.
9075 If interrupt_input, this is the handler for SIGINT.
9076 Otherwise, it is called from kbd_buffer_store_event,
9077 in handling SIGIO or SIGTINT.
9079 If `waiting_for_input' is non zero, then unless `echoing' is nonzero,
9080 immediately throw back to read_char.
9082 Otherwise it sets the Lisp variable quit-flag not-nil.
9083 This causes eval to throw, when it gets a chance.
9084 If quit-flag is already non-nil, it stops the job right away. */
9087 interrupt_signal (signalnum
) /* If we don't have an argument, */
9088 int signalnum
; /* some compilers complain in signal calls. */
9091 /* Must preserve main program's value of errno. */
9092 int old_errno
= errno
;
9094 #if defined (USG) && !defined (POSIX_SIGNALS)
9095 if (!read_socket_hook
&& NILP (Vwindow_system
))
9097 /* USG systems forget handlers when they are used;
9098 must reestablish each time */
9099 signal (SIGINT
, interrupt_signal
);
9100 signal (SIGQUIT
, interrupt_signal
);
9106 if (!NILP (Vquit_flag
)
9107 && (FRAME_TERMCAP_P (selected_frame
) || FRAME_MSDOS_P (selected_frame
)))
9109 /* If SIGINT isn't blocked, don't let us be interrupted by
9110 another SIGINT, it might be harmful due to non-reentrancy
9111 in I/O functions. */
9112 sigblock (sigmask (SIGINT
));
9117 #ifdef SIGTSTP /* Support possible in later USG versions */
9119 * On systems which can suspend the current process and return to the original
9120 * shell, this command causes the user to end up back at the shell.
9121 * The "Auto-save" and "Abort" questions are not asked until
9122 * the user elects to return to emacs, at which point he can save the current
9123 * job and either dump core or continue.
9128 if (sys_suspend () == -1)
9130 printf ("Not running as a subprocess;\n");
9131 printf ("you can continue or abort.\n");
9134 /* Perhaps should really fork an inferior shell?
9135 But that would not provide any way to get back
9136 to the original shell, ever. */
9137 printf ("No support for stopping a process on this operating system;\n");
9138 printf ("you can continue or abort.\n");
9139 #endif /* not VMS */
9140 #endif /* not SIGTSTP */
9142 /* We must remain inside the screen area when the internal terminal
9143 is used. Note that [Enter] is not echoed by dos. */
9146 /* It doesn't work to autosave while GC is in progress;
9147 the code used for auto-saving doesn't cope with the mark bit. */
9148 if (!gc_in_progress
)
9150 printf ("Auto-save? (y or n) ");
9152 if (((c
= getchar ()) & ~040) == 'Y')
9154 Fdo_auto_save (Qt
, Qnil
);
9156 printf ("\r\nAuto-save done");
9157 #else /* not MSDOS */
9158 printf ("Auto-save done\n");
9159 #endif /* not MSDOS */
9161 while (c
!= '\n') c
= getchar ();
9165 /* During GC, it must be safe to reenable quitting again. */
9166 Vinhibit_quit
= Qnil
;
9169 #endif /* not MSDOS */
9170 printf ("Garbage collection in progress; cannot auto-save now\r\n");
9171 printf ("but will instead do a real quit after garbage collection ends\r\n");
9176 printf ("\r\nAbort? (y or n) ");
9177 #else /* not MSDOS */
9179 printf ("Abort (and enter debugger)? (y or n) ");
9181 printf ("Abort (and dump core)? (y or n) ");
9182 #endif /* not VMS */
9183 #endif /* not MSDOS */
9185 if (((c
= getchar ()) & ~040) == 'Y')
9187 while (c
!= '\n') c
= getchar ();
9189 printf ("\r\nContinuing...\r\n");
9190 #else /* not MSDOS */
9191 printf ("Continuing...\n");
9192 #endif /* not MSDOS */
9199 /* If executing a function that wants to be interrupted out of
9200 and the user has not deferred quitting by binding `inhibit-quit'
9201 then quit right away. */
9202 if (immediate_quit
&& NILP (Vinhibit_quit
))
9204 struct gl_state_s saved
;
9205 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9210 GCPRO4 (saved
.object
, saved
.global_code
,
9211 saved
.current_syntax_table
, saved
.old_prop
);
9212 Fsignal (Qquit
, Qnil
);
9217 /* Else request quit when it's safe */
9221 if (waiting_for_input
&& !echoing
)
9222 quit_throw_to_read_char ();
9227 /* Handle a C-g by making read_char return C-g. */
9230 quit_throw_to_read_char ()
9233 /* Prevent another signal from doing this before we finish. */
9234 clear_waiting_for_input ();
9237 Vunread_command_events
= Qnil
;
9238 unread_command_char
= -1;
9240 #if 0 /* Currently, sit_for is called from read_char without turning
9241 off polling. And that can call set_waiting_for_input.
9242 It seems to be harmless. */
9243 #ifdef POLL_FOR_INPUT
9244 /* May be > 1 if in recursive minibuffer. */
9245 if (poll_suppress_count
== 0)
9249 if (FRAMEP (internal_last_event_frame
)
9250 && XFRAME (internal_last_event_frame
) != selected_frame
)
9251 do_switch_frame (make_lispy_switch_frame (internal_last_event_frame
),
9254 _longjmp (getcjmp
, 1);
9257 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
9258 "Set mode of reading keyboard input.\n\
9259 First arg INTERRUPT non-nil means use input interrupts;\n\
9260 nil means use CBREAK mode.\n\
9261 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
9262 (no effect except in CBREAK mode).\n\
9263 Third arg META t means accept 8-bit input (for a Meta key).\n\
9264 META nil means ignore the top bit, on the assumption it is parity.\n\
9265 Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\
9266 Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\
9267 See also `current-input-mode'.")
9268 (interrupt
, flow
, meta
, quit
)
9269 Lisp_Object interrupt
, flow
, meta
, quit
;
9272 && (!INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400))
9273 error ("set-input-mode: QUIT must be an ASCII character");
9275 #ifdef POLL_FOR_INPUT
9280 /* this causes startup screen to be restored and messes with the mouse */
9285 /* Note SIGIO has been undef'd if FIONREAD is missing. */
9286 if (read_socket_hook
)
9288 /* When using X, don't give the user a real choice,
9289 because we haven't implemented the mechanisms to support it. */
9290 #ifdef NO_SOCK_SIGIO
9291 interrupt_input
= 0;
9292 #else /* not NO_SOCK_SIGIO */
9293 interrupt_input
= 1;
9294 #endif /* NO_SOCK_SIGIO */
9297 interrupt_input
= !NILP (interrupt
);
9298 #else /* not SIGIO */
9299 interrupt_input
= 0;
9300 #endif /* not SIGIO */
9302 /* Our VMS input only works by interrupts, as of now. */
9304 interrupt_input
= 1;
9307 flow_control
= !NILP (flow
);
9310 else if (EQ (meta
, Qt
))
9315 /* Don't let this value be out of range. */
9316 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
9322 #ifdef POLL_FOR_INPUT
9323 poll_suppress_count
= 1;
9329 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
9330 "Return information about the way Emacs currently reads keyboard input.\n\
9331 The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
9332 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\
9333 nil, Emacs is using CBREAK mode.\n\
9334 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\
9335 terminal; this does not apply if Emacs uses interrupt-driven input.\n\
9336 META is t if accepting 8-bit input with 8th bit as Meta flag.\n\
9337 META nil means ignoring the top bit, on the assumption it is parity.\n\
9338 META is neither t nor nil if accepting 8-bit input and using\n\
9339 all 8 bits as the character code.\n\
9340 QUIT is the character Emacs currently uses to quit.\n\
9341 The elements of this list correspond to the arguments of\n\
9347 val
[0] = interrupt_input
? Qt
: Qnil
;
9348 val
[1] = flow_control
? Qt
: Qnil
;
9349 val
[2] = meta_key
== 2 ? make_number (0) : meta_key
== 1 ? Qt
: Qnil
;
9350 XSETFASTINT (val
[3], quit_char
);
9352 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
9357 * Set up a new kboard object with reasonable initial values.
9363 kb
->Voverriding_terminal_local_map
= Qnil
;
9364 kb
->Vlast_command
= Qnil
;
9365 kb
->Vreal_last_command
= Qnil
;
9366 kb
->Vprefix_arg
= Qnil
;
9367 kb
->Vlast_prefix_arg
= Qnil
;
9368 kb
->kbd_queue
= Qnil
;
9369 kb
->kbd_queue_has_data
= 0;
9370 kb
->immediate_echo
= 0;
9371 kb
->echoptr
= kb
->echobuf
;
9372 kb
->echo_after_prompt
= -1;
9373 kb
->kbd_macro_buffer
= 0;
9374 kb
->kbd_macro_bufsize
= 0;
9375 kb
->defining_kbd_macro
= Qnil
;
9376 kb
->Vlast_kbd_macro
= Qnil
;
9377 kb
->reference_count
= 0;
9378 kb
->Vsystem_key_alist
= Qnil
;
9379 kb
->system_key_syms
= Qnil
;
9380 kb
->Vdefault_minibuffer_frame
= Qnil
;
9384 * Destroy the contents of a kboard object, but not the object itself.
9385 * We use this just before deleting it, or if we're going to initialize
9392 if (kb
->kbd_macro_buffer
)
9393 xfree (kb
->kbd_macro_buffer
);
9402 for (kbp
= &all_kboards
; *kbp
!= kb
; kbp
= &(*kbp
)->next_kboard
)
9405 *kbp
= kb
->next_kboard
;
9414 /* This is correct before outermost invocation of the editor loop */
9415 command_loop_level
= -1;
9417 quit_char
= Ctl ('g');
9418 Vunread_command_events
= Qnil
;
9419 unread_command_char
= -1;
9420 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
9422 recent_keys_index
= 0;
9423 kbd_fetch_ptr
= kbd_buffer
;
9424 kbd_store_ptr
= kbd_buffer
;
9425 kbd_buffer_frame_or_window
9426 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
9428 do_mouse_tracking
= Qnil
;
9432 /* This means that command_loop_1 won't try to select anything the first
9434 internal_last_event_frame
= Qnil
;
9435 Vlast_event_frame
= internal_last_event_frame
;
9438 current_kboard
= initial_kboard
;
9440 wipe_kboard (current_kboard
);
9441 init_kboard (current_kboard
);
9444 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
9446 kbd_buffer_frame_or_window
9447 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
9448 if (!noninteractive
&& !read_socket_hook
&& NILP (Vwindow_system
))
9450 signal (SIGINT
, interrupt_signal
);
9451 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
9452 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
9453 SIGQUIT and we can't tell which one it will give us. */
9454 signal (SIGQUIT
, interrupt_signal
);
9455 #endif /* HAVE_TERMIO */
9457 /* Note SIGIO has been undef'd if FIONREAD is missing. */
9459 if (!noninteractive
)
9460 signal (SIGIO
, input_available_signal
);
9463 /* Use interrupt input by default, if it works and noninterrupt input
9464 has deficiencies. */
9466 #ifdef INTERRUPT_INPUT
9467 interrupt_input
= 1;
9469 interrupt_input
= 0;
9472 /* Our VMS input only works by interrupts, as of now. */
9474 interrupt_input
= 1;
9480 if (keyboard_init_hook
)
9481 (*keyboard_init_hook
) ();
9483 #ifdef POLL_FOR_INPUT
9484 poll_suppress_count
= 1;
9489 /* This type's only use is in syms_of_keyboard, to initialize the
9490 event header symbols and put properties on them. */
9497 struct event_head head_table
[] = {
9498 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
9499 &Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
,
9500 &Qswitch_frame
, "switch-frame", &Qswitch_frame
,
9501 &Qdelete_frame
, "delete-frame", &Qdelete_frame
,
9502 &Qiconify_frame
, "iconify-frame", &Qiconify_frame
,
9503 &Qmake_frame_visible
, "make-frame-visible", &Qmake_frame_visible
,
9510 QCimage
= intern (":image");
9511 staticpro (&QCimage
);
9513 staticpro (&Qhelp_echo
);
9514 Qhelp_echo
= intern ("help-echo");
9516 staticpro (&item_properties
);
9517 item_properties
= Qnil
;
9519 staticpro (&toolbar_item_properties
);
9520 toolbar_item_properties
= Qnil
;
9521 staticpro (&toolbar_items_vector
);
9522 toolbar_items_vector
= Qnil
;
9524 staticpro (&real_this_command
);
9525 real_this_command
= Qnil
;
9527 Qtimer_event_handler
= intern ("timer-event-handler");
9528 staticpro (&Qtimer_event_handler
);
9530 Qdisabled_command_hook
= intern ("disabled-command-hook");
9531 staticpro (&Qdisabled_command_hook
);
9533 Qself_insert_command
= intern ("self-insert-command");
9534 staticpro (&Qself_insert_command
);
9536 Qforward_char
= intern ("forward-char");
9537 staticpro (&Qforward_char
);
9539 Qbackward_char
= intern ("backward-char");
9540 staticpro (&Qbackward_char
);
9542 Qdisabled
= intern ("disabled");
9543 staticpro (&Qdisabled
);
9545 Qundefined
= intern ("undefined");
9546 staticpro (&Qundefined
);
9548 Qpre_command_hook
= intern ("pre-command-hook");
9549 staticpro (&Qpre_command_hook
);
9551 Qpost_command_hook
= intern ("post-command-hook");
9552 staticpro (&Qpost_command_hook
);
9554 Qpost_command_idle_hook
= intern ("post-command-idle-hook");
9555 staticpro (&Qpost_command_idle_hook
);
9557 Qdeferred_action_function
= intern ("deferred-action-function");
9558 staticpro (&Qdeferred_action_function
);
9560 Qcommand_hook_internal
= intern ("command-hook-internal");
9561 staticpro (&Qcommand_hook_internal
);
9563 Qfunction_key
= intern ("function-key");
9564 staticpro (&Qfunction_key
);
9565 Qmouse_click
= intern ("mouse-click");
9566 staticpro (&Qmouse_click
);
9568 Qmouse_wheel
= intern ("mouse-wheel");
9569 staticpro (&Qmouse_wheel
);
9570 Qlanguage_change
= intern ("language-change");
9571 staticpro (&Qlanguage_change
);
9573 Qdrag_n_drop
= intern ("drag-n-drop");
9574 staticpro (&Qdrag_n_drop
);
9576 Qusr1_signal
= intern ("usr1-signal");
9577 staticpro (&Qusr1_signal
);
9578 Qusr2_signal
= intern ("usr2-signal");
9579 staticpro (&Qusr2_signal
);
9581 Qmenu_enable
= intern ("menu-enable");
9582 staticpro (&Qmenu_enable
);
9583 Qmenu_alias
= intern ("menu-alias");
9584 staticpro (&Qmenu_alias
);
9585 QCenable
= intern (":enable");
9586 staticpro (&QCenable
);
9587 QCvisible
= intern (":visible");
9588 staticpro (&QCvisible
);
9589 QChelp
= intern (":help");
9590 staticpro (&QChelp
);
9591 QCfilter
= intern (":filter");
9592 staticpro (&QCfilter
);
9593 QCbutton
= intern (":button");
9594 staticpro (&QCbutton
);
9595 QCkeys
= intern (":keys");
9596 staticpro (&QCkeys
);
9597 QCkey_sequence
= intern (":key-sequence");
9598 staticpro (&QCkey_sequence
);
9599 QCtoggle
= intern (":toggle");
9600 staticpro (&QCtoggle
);
9601 QCradio
= intern (":radio");
9602 staticpro (&QCradio
);
9604 Qmode_line
= intern ("mode-line");
9605 staticpro (&Qmode_line
);
9606 Qvertical_line
= intern ("vertical-line");
9607 staticpro (&Qvertical_line
);
9608 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
9609 staticpro (&Qvertical_scroll_bar
);
9610 Qmenu_bar
= intern ("menu-bar");
9611 staticpro (&Qmenu_bar
);
9613 Qabove_handle
= intern ("above-handle");
9614 staticpro (&Qabove_handle
);
9615 Qhandle
= intern ("handle");
9616 staticpro (&Qhandle
);
9617 Qbelow_handle
= intern ("below-handle");
9618 staticpro (&Qbelow_handle
);
9619 Qup
= intern ("up");
9621 Qdown
= intern ("down");
9623 Qtop
= intern ("top");
9625 Qbottom
= intern ("bottom");
9626 staticpro (&Qbottom
);
9627 Qend_scroll
= intern ("end-scroll");
9628 staticpro (&Qend_scroll
);
9630 Qevent_kind
= intern ("event-kind");
9631 staticpro (&Qevent_kind
);
9632 Qevent_symbol_elements
= intern ("event-symbol-elements");
9633 staticpro (&Qevent_symbol_elements
);
9634 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
9635 staticpro (&Qevent_symbol_element_mask
);
9636 Qmodifier_cache
= intern ("modifier-cache");
9637 staticpro (&Qmodifier_cache
);
9639 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
9640 staticpro (&Qrecompute_lucid_menubar
);
9641 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
9642 staticpro (&Qactivate_menubar_hook
);
9644 Qpolling_period
= intern ("polling-period");
9645 staticpro (&Qpolling_period
);
9647 Qinput_method_function
= intern ("input-method-function");
9648 staticpro (&Qinput_method_function
);
9650 Qinput_method_exit_on_first_char
= intern ("input-method-exit-on-first-char");
9651 staticpro (&Qinput_method_exit_on_first_char
);
9652 Qinput_method_use_echo_area
= intern ("input-method-use-echo-area");
9653 staticpro (&Qinput_method_use_echo_area
);
9655 Fset (Qinput_method_exit_on_first_char
, Qnil
);
9656 Fset (Qinput_method_use_echo_area
, Qnil
);
9659 struct event_head
*p
;
9661 for (p
= head_table
;
9662 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
9665 *p
->var
= intern (p
->name
);
9667 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
9668 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
9672 button_down_location
= Fmake_vector (make_number (NUM_MOUSE_BUTTONS
), Qnil
);
9673 staticpro (&button_down_location
);
9677 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
9679 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
9680 for (i
= 0; i
< len
; i
++)
9681 if (modifier_names
[i
])
9682 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
9683 staticpro (&modifier_symbols
);
9686 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
9687 staticpro (&recent_keys
);
9689 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
9690 staticpro (&this_command_keys
);
9692 raw_keybuf
= Fmake_vector (make_number (30), Qnil
);
9693 staticpro (&raw_keybuf
);
9695 Qextended_command_history
= intern ("extended-command-history");
9696 Fset (Qextended_command_history
, Qnil
);
9697 staticpro (&Qextended_command_history
);
9699 kbd_buffer_frame_or_window
9700 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
9701 staticpro (&kbd_buffer_frame_or_window
);
9703 accent_key_syms
= Qnil
;
9704 staticpro (&accent_key_syms
);
9706 func_key_syms
= Qnil
;
9707 staticpro (&func_key_syms
);
9710 staticpro (&mouse_syms
);
9713 mouse_wheel_syms
= Qnil
;
9714 staticpro (&mouse_wheel_syms
);
9716 drag_n_drop_syms
= Qnil
;
9717 staticpro (&drag_n_drop_syms
);
9720 unread_switch_frame
= Qnil
;
9721 staticpro (&unread_switch_frame
);
9723 internal_last_event_frame
= Qnil
;
9724 staticpro (&internal_last_event_frame
);
9726 read_key_sequence_cmd
= Qnil
;
9727 staticpro (&read_key_sequence_cmd
);
9729 menu_bar_one_keymap_changed_items
= Qnil
;
9730 staticpro (&menu_bar_one_keymap_changed_items
);
9732 defsubr (&Sevent_convert_list
);
9733 defsubr (&Sread_key_sequence
);
9734 defsubr (&Sread_key_sequence_vector
);
9735 defsubr (&Srecursive_edit
);
9737 defsubr (&Strack_mouse
);
9739 defsubr (&Sinput_pending_p
);
9740 defsubr (&Scommand_execute
);
9741 defsubr (&Srecent_keys
);
9742 defsubr (&Sthis_command_keys
);
9743 defsubr (&Sthis_command_keys_vector
);
9744 defsubr (&Sthis_single_command_keys
);
9745 defsubr (&Sthis_single_command_raw_keys
);
9746 defsubr (&Sreset_this_command_lengths
);
9747 defsubr (&Sclear_this_command_keys
);
9748 defsubr (&Ssuspend_emacs
);
9749 defsubr (&Sabort_recursive_edit
);
9750 defsubr (&Sexit_recursive_edit
);
9751 defsubr (&Srecursion_depth
);
9752 defsubr (&Stop_level
);
9753 defsubr (&Sdiscard_input
);
9754 defsubr (&Sopen_dribble_file
);
9755 defsubr (&Sset_input_mode
);
9756 defsubr (&Scurrent_input_mode
);
9757 defsubr (&Sexecute_extended_command
);
9759 DEFVAR_LISP ("last-command-char", &last_command_char
,
9760 "Last input event that was part of a command.");
9762 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char
,
9763 "Last input event that was part of a command.");
9765 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
9766 "Last input event in a command, except for mouse menu events.\n\
9767 Mouse menus give back keys that don't look like mouse events;\n\
9768 this variable holds the actual mouse event that led to the menu,\n\
9769 so that you can determine whether the command was run by mouse or not.");
9771 DEFVAR_LISP ("last-input-char", &last_input_char
,
9772 "Last input event.");
9774 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char
,
9775 "Last input event.");
9777 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
9778 "List of events to be read as the command input.\n\
9779 These events are processed first, before actual keyboard input.");
9780 Vunread_command_events
= Qnil
;
9782 DEFVAR_INT ("unread-command-char", &unread_command_char
,
9783 "If not -1, an object to be read as next command input event.");
9785 DEFVAR_LISP ("unread-post-input-method-events", &Vunread_post_input_method_events
,
9786 "List of events to be processed as input by input methods.\n\
9787 These events are processed after `unread-command-events', but\n\
9788 before actual keyboard input.");
9789 Vunread_post_input_method_events
= Qnil
;
9791 DEFVAR_LISP ("unread-input-method-events", &Vunread_input_method_events
,
9792 "List of events to be processed as input by input methods.\n\
9793 These events are processed after `unread-command-events', but\n\
9794 before actual keyboard input.");
9795 Vunread_input_method_events
= Qnil
;
9797 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
9798 "Meta-prefix character code.\n\
9799 Meta-foo as command input turns into this character followed by foo.");
9800 XSETINT (meta_prefix_char
, 033);
9802 DEFVAR_KBOARD ("last-command", Vlast_command
,
9803 "The last command executed.\n\
9804 Normally a symbol with a function definition, but can be whatever was found\n\
9805 in the keymap, or whatever the variable `this-command' was set to by that\n\
9808 The value `mode-exit' is special; it means that the previous command\n\
9809 read an event that told it to exit, and it did so and unread that event.\n\
9810 In other words, the present command is the event that made the previous\n\
9813 The value `kill-region' is special; it means that the previous command\n\
9814 was a kill command.");
9816 DEFVAR_KBOARD ("real-last-command", Vreal_last_command
,
9817 "Same as `last-command', but never altered by Lisp code.");
9819 DEFVAR_LISP ("this-command", &Vthis_command
,
9820 "The command now being executed.\n\
9821 The command can set this variable; whatever is put here\n\
9822 will be in `last-command' during the following command.");
9823 Vthis_command
= Qnil
;
9825 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
9826 "*Number of keyboard input characters between auto-saves.\n\
9827 Zero means disable autosaving due to number of characters typed.");
9828 auto_save_interval
= 300;
9830 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
9831 "*Number of seconds idle time before auto-save.\n\
9832 Zero or nil means disable auto-saving due to idleness.\n\
9833 After auto-saving due to this many seconds of idle time,\n\
9834 Emacs also does a garbage collection if that seems to be warranted.");
9835 XSETFASTINT (Vauto_save_timeout
, 30);
9837 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes
,
9838 "*Nonzero means echo unfinished commands after this many seconds of pause.");
9839 echo_keystrokes
= 1;
9841 DEFVAR_INT ("polling-period", &polling_period
,
9842 "*Interval between polling for input during Lisp execution.\n\
9843 The reason for polling is to make C-g work to stop a running program.\n\
9844 Polling is needed only when using X windows and SIGIO does not work.\n\
9845 Polling is automatically disabled in all other cases.");
9848 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
9849 "*Maximum time between mouse clicks to make a double-click.\n\
9850 Measured in milliseconds. nil means disable double-click recognition;\n\
9851 t means double-clicks have no time limit and are detected\n\
9852 by position only.");
9853 Vdouble_click_time
= make_number (500);
9855 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
9856 "*Non-nil means inhibit local map menu bar menus.");
9857 inhibit_local_menu_bar_menus
= 0;
9859 DEFVAR_INT ("num-input-keys", &num_input_keys
,
9860 "Number of complete key sequences read as input so far.\n\
9861 This includes key sequences read from keyboard macros.\n\
9862 The number is effectively the number of interactive command invocations.");
9865 DEFVAR_INT ("num-nonmacro-input-events", &num_nonmacro_input_events
,
9866 "Number of input events read from the keyboard so far.\n\
9867 This does not include events generated by keyboard macros.");
9868 num_nonmacro_input_events
= 0;
9870 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
9871 "The frame in which the most recently read event occurred.\n\
9872 If the last event came from a keyboard macro, this is set to `macro'.");
9873 Vlast_event_frame
= Qnil
;
9875 /* This variable is set up in sysdep.c. */
9876 DEFVAR_LISP ("tty-erase-char", &Vtty_erase_char
,
9877 "The ERASE character as set by the user with stty.");
9879 DEFVAR_LISP ("help-char", &Vhelp_char
,
9880 "Character to recognize as meaning Help.\n\
9881 When it is read, do `(eval help-form)', and display result if it's a string.\n\
9882 If the value of `help-form' is nil, this char can be read normally.");
9883 XSETINT (Vhelp_char
, Ctl ('H'));
9885 DEFVAR_LISP ("help-event-list", &Vhelp_event_list
,
9886 "List of input events to recognize as meaning Help.\n\
9887 These work just like the value of `help-char' (see that).");
9888 Vhelp_event_list
= Qnil
;
9890 DEFVAR_LISP ("help-form", &Vhelp_form
,
9891 "Form to execute when character `help-char' is read.\n\
9892 If the form returns a string, that string is displayed.\n\
9893 If `help-form' is nil, the help char is not recognized.");
9896 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
9897 "Command to run when `help-char' character follows a prefix key.\n\
9898 This command is used only when there is no actual binding\n\
9899 for that character after that prefix key.");
9900 Vprefix_help_command
= Qnil
;
9902 DEFVAR_LISP ("top-level", &Vtop_level
,
9903 "Form to evaluate when Emacs starts up.\n\
9904 Useful to set before you dump a modified Emacs.");
9907 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
9908 "Translate table for keyboard input, or nil.\n\
9909 Each character is looked up in this string and the contents used instead.\n\
9910 The value may be a string, a vector, or a char-table.\n\
9911 If it is a string or vector of length N,\n\
9912 character codes N and up are untranslated.\n\
9913 In a vector or a char-table, an element which is nil means \"no translation\".");
9914 Vkeyboard_translate_table
= Qnil
;
9916 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
9917 "Non-nil means to always spawn a subshell instead of suspending.\n\
9918 \(Even if the operating system has support for stopping a process.\)");
9921 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
9922 "Non-nil means prompt with menus when appropriate.\n\
9923 This is done when reading from a keymap that has a prompt string,\n\
9924 for elements that have prompt strings.\n\
9925 The menu is displayed on the screen\n\
9926 if X menus were enabled at configuration\n\
9927 time and the previous event was a mouse click prefix key.\n\
9928 Otherwise, menu prompting uses the echo area.");
9931 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
9932 "Character to see next line of menu prompt.\n\
9933 Type this character while in a menu prompt to rotate around the lines of it.");
9934 XSETINT (menu_prompt_more_char
, ' ');
9936 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
9937 "A mask of additional modifier keys to use with every keyboard character.\n\
9938 Emacs applies the modifiers of the character stored here to each keyboard\n\
9939 character it reads. For example, after evaluating the expression\n\
9940 (setq extra-keyboard-modifiers ?\\C-x)\n\
9941 all input characters will have the control modifier applied to them.\n\
9943 Note that the character ?\\C-@, equivalent to the integer zero, does\n\
9944 not count as a control character; rather, it counts as a character\n\
9945 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\
9946 cancels any modification.");
9947 extra_keyboard_modifiers
= 0;
9949 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
9950 "If an editing command sets this to t, deactivate the mark afterward.\n\
9951 The command loop sets this to nil before each command,\n\
9952 and tests the value when the command returns.\n\
9953 Buffer modification stores t in this variable.");
9954 Vdeactivate_mark
= Qnil
;
9956 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
9957 "Temporary storage of pre-command-hook or post-command-hook.");
9958 Vcommand_hook_internal
= Qnil
;
9960 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
9961 "Normal hook run before each command is executed.\n\
9962 If an unhandled error happens in running this hook,\n\
9963 the hook value is set to nil, since otherwise the error\n\
9964 might happen repeatedly and make Emacs nonfunctional.");
9965 Vpre_command_hook
= Qnil
;
9967 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
9968 "Normal hook run after each command is executed.\n\
9969 If an unhandled error happens in running this hook,\n\
9970 the hook value is set to nil, since otherwise the error\n\
9971 might happen repeatedly and make Emacs nonfunctional.");
9972 Vpost_command_hook
= Qnil
;
9974 DEFVAR_LISP ("post-command-idle-hook", &Vpost_command_idle_hook
,
9975 "Normal hook run after each command is executed, if idle.\n\
9976 Errors running the hook are caught and ignored.\n\
9977 This feature is obsolete; use idle timers instead. See `etc/NEWS'.");
9978 Vpost_command_idle_hook
= Qnil
;
9980 DEFVAR_INT ("post-command-idle-delay", &post_command_idle_delay
,
9981 "Delay time before running `post-command-idle-hook'.\n\
9982 This is measured in microseconds.");
9983 post_command_idle_delay
= 100000;
9986 DEFVAR_LISP ("echo-area-clear-hook", ...,
9987 "Normal hook run when clearing the echo area.");
9989 Qecho_area_clear_hook
= intern ("echo-area-clear-hook");
9990 XSYMBOL (Qecho_area_clear_hook
)->value
= Qnil
;
9992 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
9993 "t means menu bar, specified Lucid style, needs to be recomputed.");
9994 Vlucid_menu_bar_dirty_flag
= Qnil
;
9996 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
9997 "List of menu bar items to move to the end of the menu bar.\n\
9998 The elements of the list are event types that may have menu bar bindings.");
9999 Vmenu_bar_final_items
= Qnil
;
10001 DEFVAR_KBOARD ("overriding-terminal-local-map",
10002 Voverriding_terminal_local_map
,
10003 "Per-terminal keymap that overrides all other local keymaps.\n\
10004 If this variable is non-nil, it is used as a keymap instead of the\n\
10005 buffer's local map, and the minor mode keymaps and text property keymaps.\n\
10006 This variable is intended to let commands such as `universal-argumemnt'\n\
10007 set up a different keymap for reading the next command.");
10009 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
10010 "Keymap that overrides all other local keymaps.\n\
10011 If this variable is non-nil, it is used as a keymap instead of the\n\
10012 buffer's local map, and the minor mode keymaps and text property keymaps.");
10013 Voverriding_local_map
= Qnil
;
10015 DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag
,
10016 "Non-nil means `overriding-local-map' applies to the menu bar.\n\
10017 Otherwise, the menu bar continues to reflect the buffer's local map\n\
10018 and the minor mode maps regardless of `overriding-local-map'.");
10019 Voverriding_local_map_menu_flag
= Qnil
;
10021 DEFVAR_LISP ("special-event-map", &Vspecial_event_map
,
10022 "Keymap defining bindings for special events to execute at low level.");
10023 Vspecial_event_map
= Fcons (intern ("keymap"), Qnil
);
10025 DEFVAR_LISP ("track-mouse", &do_mouse_tracking
,
10026 "*Non-nil means generate motion events for mouse motion.");
10028 DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist
,
10029 "Alist of system-specific X windows key symbols.\n\
10030 Each element should have the form (N . SYMBOL) where N is the\n\
10031 numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\
10032 and SYMBOL is its name.");
10034 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
10035 "List of deferred actions to be performed at a later time.\n\
10036 The precise format isn't relevant here; we just check whether it is nil.");
10037 Vdeferred_action_list
= Qnil
;
10039 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
10040 "Function to call to handle deferred actions, after each command.\n\
10041 This function is called with no arguments after each command\n\
10042 whenever `deferred-action-list' is non-nil.");
10043 Vdeferred_action_function
= Qnil
;
10045 DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings
,
10046 "*Non-nil means show the equivalent key-binding when M-x command has one.\n\
10047 The value can be a length of time to show the message for.\n\
10048 If the value is non-nil and not a number, we wait 2 seconds.");
10049 Vsuggest_key_bindings
= Qt
;
10051 DEFVAR_LISP ("timer-list", &Vtimer_list
,
10052 "List of active absolute time timers in order of increasing time");
10053 Vtimer_list
= Qnil
;
10055 DEFVAR_LISP ("timer-idle-list", &Vtimer_idle_list
,
10056 "List of active idle-time timers in order of increasing time");
10057 Vtimer_idle_list
= Qnil
;
10059 DEFVAR_LISP ("input-method-function", &Vinput_method_function
,
10060 "If non-nil, the function that implements the current input method.\n\
10061 It's called with one argument, a printing character that was just read.\n\
10062 \(That means a character with code 040...0176.)\n\
10063 Typically this function uses `read-event' to read additional events.\n\
10064 When it does so, it should first bind `input-method-function' to nil\n\
10065 so it will not be called recursively.\n\
10067 The function should return a list of zero or more events\n\
10068 to be used as input. If it wants to put back some events\n\
10069 to be reconsidered, separately, by the input method,\n\
10070 it can add them to the beginning of `unread-command-events'.\n\
10072 The input method function can find in `input-method-previous-method'\n\
10073 the previous echo area message.\n\
10075 The input method function should refer to the variables\n\
10076 `input-method-use-echo-area' and `input-method-exit-on-first-char'\n\
10077 for guidance on what to do.");
10078 Vinput_method_function
= Qnil
;
10080 DEFVAR_LISP ("input-method-previous-message",
10081 &Vinput_method_previous_message
,
10082 "When `input-method-function' is called, hold the previous echo area message.\n\
10083 This variable exists because `read-event' clears the echo area\n\
10084 before running the input method. It is nil if there was no message.");
10085 Vinput_method_previous_message
= Qnil
;
10087 DEFVAR_LISP ("show-help-function", &Vshow_help_function
,
10088 "If non-nil, the function that implements the display of help.\n\
10089 It's called with one argument, the help string to display.");
10090 Vshow_help_function
= Qnil
;
10094 keys_of_keyboard ()
10096 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
10097 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
10098 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
10099 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
10100 initial_define_key (meta_map
, 'x', "execute-extended-command");
10102 initial_define_lispy_key (Vspecial_event_map
, "delete-frame",
10103 "handle-delete-frame");
10104 initial_define_lispy_key (Vspecial_event_map
, "iconify-frame",
10106 initial_define_lispy_key (Vspecial_event_map
, "make-frame-visible",