1 /* Keyboard and mouse input; editor command loop.
2 Copyright (C) 1985,86,87,88,89,93,94,95,96,97,99 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. */
27 #include "termhooks.h"
35 #include "dispextern.h"
38 #include "intervals.h"
39 #include "blockinput.h"
49 #include <sys/ioctl.h>
51 #endif /* not MSDOS */
53 #include "syssignal.h"
56 #include <sys/types.h>
61 /* This is to get the definitions of the XK_ symbols. */
68 #endif /* HAVE_NTGUI */
70 /* Include systime.h after xterm.h to avoid double inclusion of time.h. */
75 /* Variables for blockinput.h: */
77 /* Non-zero if interrupt input is blocked right now. */
78 int interrupt_input_blocked
;
80 /* Nonzero means an input interrupt has arrived
81 during the current critical section. */
82 int interrupt_input_pending
;
85 /* File descriptor to use for input. */
88 #ifdef HAVE_WINDOW_SYSTEM
89 /* Make all keyboard buffers much bigger when using X windows. */
91 /* But not too big (local data > 32K error) if on macintosh */
92 #define KBD_BUFFER_SIZE 512
94 #define KBD_BUFFER_SIZE 4096
96 #else /* No X-windows, character input */
97 #define KBD_BUFFER_SIZE 256
98 #endif /* No X-windows */
100 /* Following definition copied from eval.c */
104 struct backtrace
*next
;
105 Lisp_Object
*function
;
106 Lisp_Object
*args
; /* Points to vector of args. */
107 int nargs
; /* length of vector. If nargs is UNEVALLED,
108 args points to slot holding list of
114 KBOARD
*initial_kboard
;
115 KBOARD
*current_kboard
;
119 KBOARD the_only_kboard
;
122 /* Non-nil disable property on a command means
123 do not execute it; call disabled-command-hook's value instead. */
124 Lisp_Object Qdisabled
, Qdisabled_command_hook
;
126 #define NUM_RECENT_KEYS (100)
127 int recent_keys_index
; /* Index for storing next element into recent_keys */
128 int total_keys
; /* Total number of elements stored into recent_keys */
129 Lisp_Object recent_keys
; /* A vector, holding the last 100 keystrokes */
131 /* Vector holding the key sequence that invoked the current command.
132 It is reused for each command, and it may be longer than the current
133 sequence; this_command_key_count indicates how many elements
134 actually mean something.
135 It's easier to staticpro a single Lisp_Object than an array. */
136 Lisp_Object this_command_keys
;
137 int this_command_key_count
;
139 /* This vector is used as a buffer to record the events that were actually read
140 by read_key_sequence. */
141 Lisp_Object raw_keybuf
;
142 int raw_keybuf_count
;
144 #define GROW_RAW_KEYBUF \
145 if (raw_keybuf_count == XVECTOR (raw_keybuf)->size) \
147 int newsize = 2 * XVECTOR (raw_keybuf)->size; \
149 new = Fmake_vector (make_number (newsize), Qnil); \
150 bcopy (XVECTOR (raw_keybuf)->contents, XVECTOR (new)->contents, \
151 raw_keybuf_count * sizeof (Lisp_Object)); \
155 /* Number of elements of this_command_keys
156 that precede this key sequence. */
157 int this_single_command_key_start
;
159 /* Record values of this_command_key_count and echo_length ()
160 before this command was read. */
161 static int before_command_key_count
;
162 static int before_command_echo_length
;
163 /* Values of before_command_key_count and before_command_echo_length
164 saved by reset-this-command-lengths. */
165 static int before_command_key_count_1
;
166 static int before_command_echo_length_1
;
167 /* Flag set by reset-this-command-lengths,
168 saying to reset the lengths when add_command_key is called. */
169 static int before_command_restore_flag
;
171 extern int minbuf_level
;
173 extern int message_enable_multibyte
;
175 extern struct backtrace
*backtrace_list
;
177 /* If non-nil, the function that implements the display of help.
178 It's called with one argument, the help string to display. */
180 Lisp_Object Vshow_help_function
;
182 /* Nonzero means do menu prompting. */
183 static int menu_prompting
;
185 /* Character to see next line of menu prompt. */
186 static Lisp_Object menu_prompt_more_char
;
188 /* For longjmp to where kbd input is being done. */
189 static jmp_buf getcjmp
;
191 /* True while doing kbd input. */
192 int waiting_for_input
;
194 /* True while displaying for echoing. Delays C-g throwing. */
198 /* Non-null means we can start echoing at the next input pause even
199 though there is something in the echo area. */
201 static struct kboard
*ok_to_echo_at_next_pause
;
203 /* The kboard currently echoing, or null for none. Set in echo_now to
204 the kboard echoing. Reset to 0 in cancel_echoing. If non-null,
205 and a current echo area message exists, we know that it comes from
208 static struct kboard
*echo_kboard
;
210 /* Nonzero means disregard local maps for the menu bar. */
211 static int inhibit_local_menu_bar_menus
;
213 /* Nonzero means C-g should cause immediate error-signal. */
216 /* The user's ERASE setting. */
217 Lisp_Object Vtty_erase_char
;
219 /* Character to recognize as the help char. */
220 Lisp_Object Vhelp_char
;
222 /* List of other event types to recognize as meaning "help". */
223 Lisp_Object Vhelp_event_list
;
225 /* Form to execute when help char is typed. */
226 Lisp_Object Vhelp_form
;
228 /* Command to run when the help character follows a prefix key. */
229 Lisp_Object Vprefix_help_command
;
231 /* List of items that should move to the end of the menu bar. */
232 Lisp_Object Vmenu_bar_final_items
;
234 /* Non-nil means show the equivalent key-binding for
235 any M-x command that has one.
236 The value can be a length of time to show the message for.
237 If the value is non-nil and not a number, we wait 2 seconds. */
238 Lisp_Object Vsuggest_key_bindings
;
240 /* Character that causes a quit. Normally C-g.
242 If we are running on an ordinary terminal, this must be an ordinary
243 ASCII char, since we want to make it our interrupt character.
245 If we are not running on an ordinary terminal, it still needs to be
246 an ordinary ASCII char. This character needs to be recognized in
247 the input interrupt handler. At this point, the keystroke is
248 represented as a struct input_event, while the desired quit
249 character is specified as a lispy event. The mapping from struct
250 input_events to lispy events cannot run in an interrupt handler,
251 and the reverse mapping is difficult for anything but ASCII
254 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
258 extern Lisp_Object current_global_map
;
259 extern int minibuf_level
;
261 /* If non-nil, this is a map that overrides all other local maps. */
262 Lisp_Object Voverriding_local_map
;
264 /* If non-nil, Voverriding_local_map applies to the menu bar. */
265 Lisp_Object Voverriding_local_map_menu_flag
;
267 /* Keymap that defines special misc events that should
268 be processed immediately at a low level. */
269 Lisp_Object Vspecial_event_map
;
271 /* Current depth in recursive edits. */
272 int command_loop_level
;
274 /* Total number of times command_loop has read a key sequence. */
277 /* Last input character read as a command. */
278 Lisp_Object last_command_char
;
280 /* Last input character read as a command, not counting menus
281 reached by the mouse. */
282 Lisp_Object last_nonmenu_event
;
284 /* Last input character read for any purpose. */
285 Lisp_Object last_input_char
;
287 /* If not Qnil, a list of objects to be read as subsequent command input. */
288 Lisp_Object Vunread_command_events
;
290 /* If not Qnil, a list of objects to be read as subsequent command input
291 including input method processing. */
292 Lisp_Object Vunread_input_method_events
;
294 /* If not Qnil, a list of objects to be read as subsequent command input
295 but NOT including input method processing. */
296 Lisp_Object Vunread_post_input_method_events
;
298 /* If not -1, an event to be read as subsequent command input. */
299 int unread_command_char
;
301 /* If not Qnil, this is a switch-frame event which we decided to put
302 off until the end of a key sequence. This should be read as the
303 next command input, after any unread_command_events.
305 read_key_sequence uses this to delay switch-frame events until the
306 end of the key sequence; Fread_char uses it to put off switch-frame
307 events until a non-ASCII event is acceptable as input. */
308 Lisp_Object unread_switch_frame
;
310 /* A mask of extra modifier bits to put into every keyboard char. */
311 int extra_keyboard_modifiers
;
313 /* Char to use as prefix when a meta character is typed in.
314 This is bound on entry to minibuffer in case ESC is changed there. */
316 Lisp_Object meta_prefix_char
;
318 /* Last size recorded for a current buffer which is not a minibuffer. */
319 static int last_non_minibuf_size
;
321 /* Number of idle seconds before an auto-save and garbage collection. */
322 static Lisp_Object Vauto_save_timeout
;
324 /* Total number of times read_char has returned. */
325 int num_input_events
;
327 /* Total number of times read_char has returned, outside of macros. */
328 int num_nonmacro_input_events
;
330 /* Auto-save automatically when this many characters have been typed
331 since the last time. */
333 static int auto_save_interval
;
335 /* Value of num_nonmacro_input_events as of last auto save. */
339 /* The command being executed by the command loop.
340 Commands may set this, and the value set will be copied into
341 current_kboard->Vlast_command instead of the actual command. */
342 Lisp_Object Vthis_command
;
344 /* This is like Vthis_command, except that commands never set it. */
345 Lisp_Object real_this_command
;
347 /* The value of point when the last command was executed. */
348 int last_point_position
;
350 /* The buffer that was current when the last command was started. */
351 Lisp_Object last_point_position_buffer
;
353 /* The frame in which the last input event occurred, or Qmacro if the
354 last event came from a macro. We use this to determine when to
355 generate switch-frame events. This may be cleared by functions
356 like Fselect_frame, to make sure that a switch-frame event is
357 generated by the next character. */
358 Lisp_Object internal_last_event_frame
;
360 /* A user-visible version of the above, intended to allow users to
361 figure out where the last event came from, if the event doesn't
362 carry that information itself (i.e. if it was a character). */
363 Lisp_Object Vlast_event_frame
;
365 /* The timestamp of the last input event we received from the X server.
366 X Windows wants this for selection ownership. */
367 unsigned long last_event_timestamp
;
369 Lisp_Object Qself_insert_command
;
370 Lisp_Object Qforward_char
;
371 Lisp_Object Qbackward_char
;
372 Lisp_Object Qundefined
;
373 Lisp_Object Qtimer_event_handler
;
375 /* read_key_sequence stores here the command definition of the
376 key sequence that it reads. */
377 Lisp_Object read_key_sequence_cmd
;
379 /* Form to evaluate (if non-nil) when Emacs is started. */
380 Lisp_Object Vtop_level
;
382 /* User-supplied string to translate input characters through. */
383 Lisp_Object Vkeyboard_translate_table
;
385 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
386 extern Lisp_Object Vfunction_key_map
;
388 /* Another keymap that maps key sequences into key sequences.
389 This one takes precedence over ordinary definitions. */
390 extern Lisp_Object Vkey_translation_map
;
392 /* If non-nil, this implements the current input method. */
393 Lisp_Object Vinput_method_function
;
394 Lisp_Object Qinput_method_function
;
396 /* When we call Vinput_method_function,
397 this holds the echo area message that was just erased. */
398 Lisp_Object Vinput_method_previous_message
;
400 /* Non-nil means deactivate the mark at end of this command. */
401 Lisp_Object Vdeactivate_mark
;
403 /* Menu bar specified in Lucid Emacs fashion. */
405 Lisp_Object Vlucid_menu_bar_dirty_flag
;
406 Lisp_Object Qrecompute_lucid_menubar
, Qactivate_menubar_hook
;
408 Lisp_Object Qecho_area_clear_hook
;
410 /* Hooks to run before and after each command. */
411 Lisp_Object Qpre_command_hook
, Vpre_command_hook
;
412 Lisp_Object Qpost_command_hook
, Vpost_command_hook
;
413 Lisp_Object Qcommand_hook_internal
, Vcommand_hook_internal
;
414 /* Hook run after a command if there's no more input soon. */
415 Lisp_Object Qpost_command_idle_hook
, Vpost_command_idle_hook
;
417 /* Delay time in microseconds before running post-command-idle-hook. */
418 int post_command_idle_delay
;
420 /* List of deferred actions to be performed at a later time.
421 The precise format isn't relevant here; we just check whether it is nil. */
422 Lisp_Object Vdeferred_action_list
;
424 /* Function to call to handle deferred actions, when there are any. */
425 Lisp_Object Vdeferred_action_function
;
426 Lisp_Object Qdeferred_action_function
;
428 Lisp_Object Qinput_method_exit_on_first_char
;
429 Lisp_Object Qinput_method_use_echo_area
;
431 /* File in which we write all commands we read. */
434 /* Nonzero if input is available. */
437 /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
438 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
442 extern char *pending_malloc_warning
;
444 /* Circular buffer for pre-read keyboard input. */
445 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
447 /* Vector to GCPRO the frames and windows mentioned in kbd_buffer.
449 The interrupt-level event handlers will never enqueue an event on a
450 frame which is not in Vframe_list, and once an event is dequeued,
451 internal_last_event_frame or the event itself points to the frame.
454 But while the event is sitting in the queue, it's completely
455 unprotected. Suppose the user types one command which will run for
456 a while and then delete a frame, and then types another event at
457 the frame that will be deleted, before the command gets around to
458 it. Suppose there are no references to this frame elsewhere in
459 Emacs, and a GC occurs before the second event is dequeued. Now we
460 have an event referring to a freed frame, which will crash Emacs
463 Similar things happen when an event on a scroll bar is enqueued; the
464 window may be deleted while the event is in the queue.
466 So, we use this vector to protect the frame_or_window field in the
467 event queue. That way, they'll be dequeued as dead frames or
468 windows, but still valid lisp objects.
470 If kbd_buffer[i].kind != no_event, then
471 (XVECTOR (kbd_buffer_frame_or_window)->contents[i]
472 == kbd_buffer[i].frame_or_window. */
473 static Lisp_Object kbd_buffer_frame_or_window
;
475 /* Pointer to next available character in kbd_buffer.
476 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
477 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the
478 next available char is in kbd_buffer[0]. */
479 static struct input_event
*kbd_fetch_ptr
;
481 /* Pointer to next place to store character in kbd_buffer. This
482 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
483 character should go in kbd_buffer[0]. */
484 static struct input_event
* volatile kbd_store_ptr
;
486 /* The above pair of variables forms a "queue empty" flag. When we
487 enqueue a non-hook event, we increment kbd_store_ptr. When we
488 dequeue a non-hook event, we increment kbd_fetch_ptr. We say that
489 there is input available iff the two pointers are not equal.
491 Why not just have a flag set and cleared by the enqueuing and
492 dequeuing functions? Such a flag could be screwed up by interrupts
493 at inopportune times. */
495 /* If this flag is non-nil, we check mouse_moved to see when the
496 mouse moves, and motion events will appear in the input stream.
497 Otherwise, mouse motion is ignored. */
498 static Lisp_Object do_mouse_tracking
;
500 /* Symbols to head events. */
501 Lisp_Object Qmouse_movement
;
502 Lisp_Object Qscroll_bar_movement
;
503 Lisp_Object Qswitch_frame
;
504 Lisp_Object Qdelete_frame
;
505 Lisp_Object Qiconify_frame
;
506 Lisp_Object Qmake_frame_visible
;
507 Lisp_Object Qhelp_echo
;
509 /* Symbols to denote kinds of events. */
510 Lisp_Object Qfunction_key
;
511 Lisp_Object Qmouse_click
;
513 Lisp_Object Qmouse_wheel
;
514 Lisp_Object Qlanguage_change
;
516 Lisp_Object Qdrag_n_drop
;
517 /* Lisp_Object Qmouse_movement; - also an event header */
519 /* Properties of event headers. */
520 Lisp_Object Qevent_kind
;
521 Lisp_Object Qevent_symbol_elements
;
523 /* menu item parts */
524 Lisp_Object Qmenu_alias
;
525 Lisp_Object Qmenu_enable
;
526 Lisp_Object QCenable
, QCvisible
, QChelp
, QCfilter
, QCkeys
, QCkey_sequence
;
527 Lisp_Object QCbutton
, QCtoggle
, QCradio
;
528 extern Lisp_Object Vdefine_key_rebound_commands
;
529 extern Lisp_Object Qmenu_item
;
531 /* An event header symbol HEAD may have a property named
532 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
533 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
534 mask of modifiers applied to it. If present, this is used to help
535 speed up parse_modifiers. */
536 Lisp_Object Qevent_symbol_element_mask
;
538 /* An unmodified event header BASE may have a property named
539 Qmodifier_cache, which is an alist mapping modifier masks onto
540 modified versions of BASE. If present, this helps speed up
542 Lisp_Object Qmodifier_cache
;
544 /* Symbols to use for parts of windows. */
545 Lisp_Object Qmode_line
;
546 Lisp_Object Qvertical_line
;
547 Lisp_Object Qvertical_scroll_bar
;
548 Lisp_Object Qmenu_bar
;
550 Lisp_Object
recursive_edit_unwind (), command_loop ();
551 Lisp_Object
Fthis_command_keys ();
552 Lisp_Object Qextended_command_history
;
553 EMACS_TIME
timer_check ();
555 extern Lisp_Object Vhistory_length
;
557 extern char *x_get_keysym_name ();
559 static void record_menu_key ();
561 Lisp_Object Qpolling_period
;
563 /* List of absolute timers. Appears in order of next scheduled event. */
564 Lisp_Object Vtimer_list
;
566 /* List of idle time timers. Appears in order of next scheduled event. */
567 Lisp_Object Vtimer_idle_list
;
569 /* Incremented whenever a timer is run. */
572 extern Lisp_Object Vprint_level
, Vprint_length
;
574 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
576 EMACS_TIME
*input_available_clear_time
;
578 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
579 Default is 1 if INTERRUPT_INPUT is defined. */
582 /* Nonzero while interrupts are temporarily deferred during redisplay. */
583 int interrupts_deferred
;
585 /* Nonzero means use ^S/^Q for flow control. */
588 /* Allow m- file to inhibit use of FIONREAD. */
589 #ifdef BROKEN_FIONREAD
593 /* We are unable to use interrupts if FIONREAD is not available,
594 so flush SIGIO so we won't try. */
601 /* If we support a window system, turn on the code to poll periodically
602 to detect C-g. It isn't actually used when doing interrupt input. */
603 #ifdef HAVE_WINDOW_SYSTEM
604 #define POLL_FOR_INPUT
607 /* After a command is executed, if point is moved into a region that
608 has specific properties (e.g. composition, display), we adjust
609 point to the boundary of the region. But, if a command sets this
610 valiable to non-nil, we suppress this point adjustment. This
611 variable is set to nil before reading a command. */
612 Lisp_Object Vdisable_point_adjustment
;
614 /* If non-nil, always disable point adjustment. */
615 Lisp_Object Vglobal_disable_point_adjustment
;
618 /* Global variable declarations. */
620 /* Function for init_keyboard to call with no args (if nonzero). */
621 void (*keyboard_init_hook
) ();
623 static int read_avail_input ();
624 static void get_input_pending ();
625 static int readable_events ();
626 static Lisp_Object
read_char_x_menu_prompt ();
627 static Lisp_Object
read_char_minibuf_menu_prompt ();
628 static Lisp_Object
make_lispy_event ();
630 static Lisp_Object
make_lispy_movement ();
632 static Lisp_Object
modify_event_symbol ();
633 static Lisp_Object
make_lispy_switch_frame ();
634 static int parse_solitary_modifier ();
635 static void save_getcjmp ();
636 static void restore_getcjmp ();
637 static Lisp_Object apply_modifiers
P_ ((int, Lisp_Object
));
639 /* > 0 if we are to echo keystrokes. */
640 static int echo_keystrokes
;
642 /* Nonzero means don't try to suspend even if the operating system seems
644 static int cannot_suspend
;
646 #define min(a,b) ((a)<(b)?(a):(b))
647 #define max(a,b) ((a)>(b)?(a):(b))
649 /* Install the string STR as the beginning of the string of echoing,
650 so that it serves as a prompt for the next character.
651 Also start echoing. */
657 int len
= strlen (str
);
659 if (len
> ECHOBUFSIZE
- 4)
660 len
= ECHOBUFSIZE
- 4;
661 bcopy (str
, current_kboard
->echobuf
, len
);
662 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
663 *current_kboard
->echoptr
= '\0';
665 current_kboard
->echo_after_prompt
= len
;
670 /* Add C to the echo string, if echoing is going on.
671 C can be a character, which is printed prettily ("M-C-x" and all that
672 jazz), or a symbol, whose name is printed. */
678 extern char *push_key_description ();
680 if (current_kboard
->immediate_echo
)
682 char *ptr
= current_kboard
->echoptr
;
684 if (ptr
!= current_kboard
->echobuf
)
687 /* If someone has passed us a composite event, use its head symbol. */
692 if (ptr
- current_kboard
->echobuf
693 > ECHOBUFSIZE
- KEY_DESCRIPTION_SIZE
)
696 ptr
= push_key_description (XINT (c
), ptr
);
698 else if (SYMBOLP (c
))
700 struct Lisp_String
*name
= XSYMBOL (c
)->name
;
701 if ((ptr
- current_kboard
->echobuf
) + STRING_BYTES (name
) + 4
704 bcopy (name
->data
, ptr
, STRING_BYTES (name
));
705 ptr
+= STRING_BYTES (name
);
708 if (current_kboard
->echoptr
== current_kboard
->echobuf
711 strcpy (ptr
, " (Type ? for further options)");
716 current_kboard
->echoptr
= ptr
;
722 /* Temporarily add a dash to the end of the echo string if it's not
723 empty, so that it serves as a mini-prompt for the very next character. */
728 if (!current_kboard
->immediate_echo
729 && current_kboard
->echoptr
== current_kboard
->echobuf
)
731 /* Do nothing if we just printed a prompt. */
732 if (current_kboard
->echo_after_prompt
733 == current_kboard
->echoptr
- current_kboard
->echobuf
)
735 /* Do nothing if not echoing at all. */
736 if (current_kboard
->echoptr
== 0)
739 /* Put a dash at the end of the buffer temporarily,
740 but make it go away when the next character is added. */
741 current_kboard
->echoptr
[0] = '-';
742 current_kboard
->echoptr
[1] = 0;
747 /* Display the current echo string, and begin echoing if not already
753 if (!current_kboard
->immediate_echo
)
756 current_kboard
->immediate_echo
= 1;
758 for (i
= 0; i
< this_command_key_count
; i
++)
761 c
= XVECTOR (this_command_keys
)->contents
[i
];
762 if (! (EVENT_HAS_PARAMETERS (c
)
763 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
770 echo_kboard
= current_kboard
;
771 message2_nolog (current_kboard
->echobuf
, strlen (current_kboard
->echobuf
),
772 ! NILP (current_buffer
->enable_multibyte_characters
));
775 if (waiting_for_input
&& !NILP (Vquit_flag
))
776 quit_throw_to_read_char ();
779 /* Turn off echoing, for the start of a new command. */
784 current_kboard
->immediate_echo
= 0;
785 current_kboard
->echoptr
= current_kboard
->echobuf
;
786 current_kboard
->echo_after_prompt
= -1;
787 ok_to_echo_at_next_pause
= 0;
791 /* Return the length of the current echo string. */
796 return current_kboard
->echoptr
- current_kboard
->echobuf
;
799 /* Truncate the current echo message to its first LEN chars.
800 This and echo_char get used by read_key_sequence when the user
801 switches frames while entering a key sequence. */
807 current_kboard
->echobuf
[len
] = '\0';
808 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
809 truncate_echo_area (len
);
813 /* Functions for manipulating this_command_keys. */
815 add_command_key (key
)
818 int size
= XVECTOR (this_command_keys
)->size
;
820 /* If reset-this-command-length was called recently, obey it now.
821 See the doc string of that function for an explanation of why. */
822 if (before_command_restore_flag
)
824 this_command_key_count
= before_command_key_count_1
;
825 if (this_command_key_count
< this_single_command_key_start
)
826 this_single_command_key_start
= this_command_key_count
;
827 echo_truncate (before_command_echo_length_1
);
828 before_command_restore_flag
= 0;
831 if (this_command_key_count
>= size
)
833 Lisp_Object new_keys
;
835 new_keys
= Fmake_vector (make_number (size
* 2), Qnil
);
836 bcopy (XVECTOR (this_command_keys
)->contents
,
837 XVECTOR (new_keys
)->contents
,
838 size
* sizeof (Lisp_Object
));
840 this_command_keys
= new_keys
;
843 XVECTOR (this_command_keys
)->contents
[this_command_key_count
++] = key
;
849 int count
= specpdl_ptr
- specpdl
;
852 if (command_loop_level
> 0)
854 specbind (Qstandard_output
, Qt
);
855 specbind (Qstandard_input
, Qt
);
858 val
= command_loop ();
860 Fsignal (Qquit
, Qnil
);
861 /* Handle throw from read_minibuf when using minibuffer
862 while it's active but we're in another window. */
864 Fsignal (Qerror
, Fcons (val
, Qnil
));
866 return unbind_to (count
, Qnil
);
869 /* When an auto-save happens, record the "time", and don't do again soon. */
874 last_auto_save
= num_nonmacro_input_events
;
877 /* Make an auto save happen as soon as possible at command level. */
880 force_auto_save_soon ()
882 last_auto_save
= - auto_save_interval
- 1;
884 record_asynch_buffer_change ();
887 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
888 "Invoke the editor command loop recursively.\n\
889 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
890 that tells this function to return.\n\
891 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
892 This function is called by the editor initialization to begin editing.")
895 int count
= specpdl_ptr
- specpdl
;
897 command_loop_level
++;
898 update_mode_lines
= 1;
900 record_unwind_protect (recursive_edit_unwind
,
902 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
906 return unbind_to (count
, Qnil
);
910 recursive_edit_unwind (buffer
)
914 Fset_buffer (buffer
);
916 command_loop_level
--;
917 update_mode_lines
= 1;
925 #if 0 /* Theory: if there's anything in Vunread_command_events,
926 it will right away be read by read_key_sequence,
927 and then if we do switch KBOARDS, it will go into the side
928 queue then. So we don't need to do anything special here -- rms. */
929 if (CONSP (Vunread_command_events
))
931 current_kboard
->kbd_queue
932 = nconc2 (Vunread_command_events
, current_kboard
->kbd_queue
);
933 current_kboard
->kbd_queue_has_data
= 1;
935 Vunread_command_events
= Qnil
;
941 /* Switch to the single-kboard state, making current_kboard
942 the only KBOARD from which further input is accepted. */
945 single_kboard_state ()
952 /* Maintain a stack of kboards, so other parts of Emacs
953 can switch temporarily to the kboard of a given frame
954 and then revert to the previous status. */
959 struct kboard_stack
*next
;
962 static struct kboard_stack
*kboard_stack
;
965 push_frame_kboard (f
)
969 struct kboard_stack
*p
970 = (struct kboard_stack
*) xmalloc (sizeof (struct kboard_stack
));
972 p
->next
= kboard_stack
;
973 p
->kboard
= current_kboard
;
976 current_kboard
= FRAME_KBOARD (f
);
984 struct kboard_stack
*p
= kboard_stack
;
985 current_kboard
= p
->kboard
;
986 kboard_stack
= p
->next
;
991 /* Handle errors that are not handled at inner levels
992 by printing an error message and returning to the editor command loop. */
998 Lisp_Object old_level
, old_length
;
1001 if (!NILP (executing_macro
))
1003 if (executing_macro_iterations
== 1)
1004 sprintf (macroerror
, "After 1 kbd macro iteration: ");
1006 sprintf (macroerror
, "After %d kbd macro iterations: ",
1007 executing_macro_iterations
);
1012 Vstandard_output
= Qt
;
1013 Vstandard_input
= Qt
;
1014 Vexecuting_macro
= Qnil
;
1015 executing_macro
= Qnil
;
1016 current_kboard
->Vprefix_arg
= Qnil
;
1017 current_kboard
->Vlast_prefix_arg
= Qnil
;
1020 /* Avoid unquittable loop if data contains a circular list. */
1021 old_level
= Vprint_level
;
1022 old_length
= Vprint_length
;
1023 XSETFASTINT (Vprint_level
, 10);
1024 XSETFASTINT (Vprint_length
, 10);
1025 cmd_error_internal (data
, macroerror
);
1026 Vprint_level
= old_level
;
1027 Vprint_length
= old_length
;
1031 Vinhibit_quit
= Qnil
;
1033 any_kboard_state ();
1036 return make_number (0);
1039 /* Take actions on handling an error. DATA is the data that describes
1042 CONTEXT is a C-string containing ASCII characters only which
1043 describes the context in which the error happened. If we need to
1044 generalize CONTEXT to allow multibyte characters, make it a Lisp
1048 cmd_error_internal (data
, context
)
1053 int kill_emacs_p
= 0;
1054 struct frame
*sf
= SELECTED_FRAME ();
1058 clear_message (1, 0);
1060 /* If the window system or terminal frame hasn't been initialized
1061 yet, or we're not interactive, it's best to dump this message out
1062 to stderr and exit. */
1063 if (!sf
->glyphs_initialized_p
1064 /* This is the case of the frame dumped with Emacs, when we're
1065 running under a window system. */
1066 || (!NILP (Vwindow_system
)
1067 && !inhibit_window_system
1068 && FRAME_TERMCAP_P (sf
))
1071 stream
= Qexternal_debugging_output
;
1082 write_string_1 (context
, -1, stream
);
1084 print_error_message (data
, stream
);
1086 /* If the window system or terminal frame hasn't been initialized
1087 yet, or we're in -batch mode, this error should cause Emacs to exit. */
1091 Fkill_emacs (make_number (-1));
1095 Lisp_Object
command_loop_1 ();
1096 Lisp_Object
command_loop_2 ();
1097 Lisp_Object
top_level_1 ();
1099 /* Entry to editor-command-loop.
1100 This level has the catches for exiting/returning to editor command loop.
1101 It returns nil to exit recursive edit, t to abort it. */
1106 if (command_loop_level
> 0 || minibuf_level
> 0)
1109 val
= internal_catch (Qexit
, command_loop_2
, Qnil
);
1110 executing_macro
= Qnil
;
1116 internal_catch (Qtop_level
, top_level_1
, Qnil
);
1117 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
1118 executing_macro
= Qnil
;
1120 /* End of file in -batch run causes exit here. */
1126 /* Here we catch errors in execution of commands within the
1127 editing loop, and reenter the editing loop.
1128 When there is an error, cmd_error runs and returns a non-nil
1129 value to us. A value of nil means that cmd_loop_1 itself
1130 returned due to end of file (or end of kbd macro). */
1135 register Lisp_Object val
;
1138 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
1139 while (!NILP (val
));
1147 return Feval (Vtop_level
);
1153 /* On entry to the outer level, run the startup file */
1154 if (!NILP (Vtop_level
))
1155 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
1156 else if (!NILP (Vpurify_flag
))
1157 message ("Bare impure Emacs (standard Lisp code not loaded)");
1159 message ("Bare Emacs (standard Lisp code not loaded)");
1163 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
1164 "Exit all recursive editing levels.")
1167 Fthrow (Qtop_level
, Qnil
);
1170 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
1171 "Exit from the innermost recursive edit or minibuffer.")
1174 if (command_loop_level
> 0 || minibuf_level
> 0)
1175 Fthrow (Qexit
, Qnil
);
1177 error ("No recursive edit is in progress");
1180 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
1181 "Abort the command that requested this recursive edit or minibuffer input.")
1184 if (command_loop_level
> 0 || minibuf_level
> 0)
1187 error ("No recursive edit is in progress");
1190 /* This is the actual command reading loop,
1191 sans error-handling encapsulation. */
1193 Lisp_Object
Fcommand_execute ();
1194 static int read_key_sequence ();
1195 void safe_run_hooks ();
1196 static void adjust_point_for_property ();
1204 Lisp_Object keybuf
[30];
1208 struct buffer
*prev_buffer
;
1210 int was_locked
= single_kboard
;
1213 current_kboard
->Vprefix_arg
= Qnil
;
1214 current_kboard
->Vlast_prefix_arg
= Qnil
;
1215 Vdeactivate_mark
= Qnil
;
1216 waiting_for_input
= 0;
1220 this_command_key_count
= 0;
1221 this_single_command_key_start
= 0;
1223 /* Make sure this hook runs after commands that get errors and
1224 throw to top level. */
1225 /* Note that the value cell will never directly contain nil
1226 if the symbol is a local variable. */
1227 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1228 safe_run_hooks (Qpost_command_hook
);
1230 /* If displaying a message, resize the echo area window to fit
1231 that message's size exactly. */
1232 if (!NILP (echo_area_buffer
[0]))
1233 resize_echo_area_axactly ();
1235 if (!NILP (Vdeferred_action_list
))
1236 call0 (Vdeferred_action_function
);
1238 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1240 if (NILP (Vunread_command_events
)
1241 && NILP (Vunread_input_method_events
)
1242 && NILP (Vunread_post_input_method_events
)
1243 && NILP (Vexecuting_macro
)
1244 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1, 1)))
1245 safe_run_hooks (Qpost_command_idle_hook
);
1248 /* Do this after running Vpost_command_hook, for consistency. */
1249 current_kboard
->Vlast_command
= Vthis_command
;
1250 current_kboard
->Vreal_last_command
= real_this_command
;
1254 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
1257 /* Make sure the current window's buffer is selected. */
1258 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1259 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1261 /* Display any malloc warning that just came out. Use while because
1262 displaying one warning can cause another. */
1264 while (pending_malloc_warning
)
1265 display_malloc_warning ();
1269 Vdeactivate_mark
= Qnil
;
1271 /* If minibuffer on and echo area in use,
1272 wait 2 sec and redraw minibuffer. */
1275 && !NILP (echo_area_buffer
[0])
1276 && EQ (minibuf_window
, echo_area_window
))
1278 /* Bind inhibit-quit to t so that C-g gets read in
1279 rather than quitting back to the minibuffer. */
1280 int count
= specpdl_ptr
- specpdl
;
1281 specbind (Qinhibit_quit
, Qt
);
1283 Fsit_for (make_number (2), Qnil
, Qnil
);
1284 /* Clear the echo area. */
1286 safe_run_hooks (Qecho_area_clear_hook
);
1288 unbind_to (count
, Qnil
);
1290 /* If a C-g came in before, treat it as input now. */
1291 if (!NILP (Vquit_flag
))
1294 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1299 alloca (0); /* Cause a garbage collection now */
1300 /* Since we can free the most stuff here. */
1301 #endif /* C_ALLOCA */
1304 /* Select the frame that the last event came from. Usually,
1305 switch-frame events will take care of this, but if some lisp
1306 code swallows a switch-frame event, we'll fix things up here.
1307 Is this a good idea? */
1308 if (FRAMEP (internal_last_event_frame
)
1309 && !EQ (internal_last_event_frame
, selected_frame
))
1310 Fselect_frame (internal_last_event_frame
, Qnil
);
1312 /* If it has changed current-menubar from previous value,
1313 really recompute the menubar from the value. */
1314 if (! NILP (Vlucid_menu_bar_dirty_flag
)
1315 && !NILP (Ffboundp (Qrecompute_lucid_menubar
)))
1316 call0 (Qrecompute_lucid_menubar
);
1318 before_command_key_count
= this_command_key_count
;
1319 before_command_echo_length
= echo_length ();
1321 Vthis_command
= Qnil
;
1322 real_this_command
= Qnil
;
1324 /* Read next key sequence; i gets its length. */
1325 i
= read_key_sequence (keybuf
, sizeof keybuf
/ sizeof keybuf
[0],
1328 /* A filter may have run while we were reading the input. */
1329 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
1331 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1332 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1336 /* Now we have read a key sequence of length I,
1337 or else I is 0 and we found end of file. */
1339 if (i
== 0) /* End of file -- happens only in */
1340 return Qnil
; /* a kbd macro, at the end. */
1341 /* -1 means read_key_sequence got a menu that was rejected.
1342 Just loop around and read another command. */
1346 this_command_key_count
= 0;
1347 this_single_command_key_start
= 0;
1351 last_command_char
= keybuf
[i
- 1];
1353 /* If the previous command tried to force a specific window-start,
1354 forget about that, in case this command moves point far away
1355 from that position. But also throw away beg_unchanged and
1356 end_unchanged information in that case, so that redisplay will
1357 update the whole window properly. */
1358 if (!NILP (XWINDOW (selected_window
)->force_start
))
1361 XWINDOW (selected_window
)->force_start
= Qnil
;
1362 b
= XBUFFER (XWINDOW (selected_window
)->buffer
);
1363 BUF_BEG_UNCHANGED (b
) = BUF_END_UNCHANGED (b
) = 0;
1366 cmd
= read_key_sequence_cmd
;
1367 if (!NILP (Vexecuting_macro
))
1369 if (!NILP (Vquit_flag
))
1371 Vexecuting_macro
= Qt
;
1372 QUIT
; /* Make some noise. */
1373 /* Will return since macro now empty. */
1377 /* Do redisplay processing after this command except in special
1378 cases identified below. */
1379 prev_buffer
= current_buffer
;
1380 prev_modiff
= MODIFF
;
1381 last_point_position
= PT
;
1382 XSETBUFFER (last_point_position_buffer
, prev_buffer
);
1384 /* By default, we adjust point to a boundary of a region that
1385 has such a property that should be treated intangible
1386 (e.g. composition, display). But, some commands will set
1387 this variable differently. */
1388 Vdisable_point_adjustment
= Qnil
;
1390 /* Execute the command. */
1392 Vthis_command
= cmd
;
1393 real_this_command
= cmd
;
1394 /* Note that the value cell will never directly contain nil
1395 if the symbol is a local variable. */
1396 if (!NILP (Vpre_command_hook
) && !NILP (Vrun_hooks
))
1397 safe_run_hooks (Qpre_command_hook
);
1399 if (NILP (Vthis_command
))
1401 /* nil means key is undefined. */
1403 current_kboard
->defining_kbd_macro
= Qnil
;
1404 update_mode_lines
= 1;
1405 current_kboard
->Vprefix_arg
= Qnil
;
1409 if (NILP (current_kboard
->Vprefix_arg
) && ! no_direct
)
1411 /* In case we jump to directly_done. */
1412 Vcurrent_prefix_arg
= current_kboard
->Vprefix_arg
;
1414 /* Recognize some common commands in common situations and
1415 do them directly. */
1416 if (EQ (Vthis_command
, Qforward_char
) && PT
< ZV
)
1418 struct Lisp_Char_Table
*dp
1419 = window_display_table (XWINDOW (selected_window
));
1420 lose
= FETCH_CHAR (PT_BYTE
);
1423 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1424 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1425 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1426 && (lose
>= 0x20 && lose
< 0x7f)))
1427 : (lose
>= 0x20 && lose
< 0x7f))
1428 /* To extract the case of continuation on
1429 wide-column characters. */
1430 && (WIDTH_BY_CHAR_HEAD (FETCH_BYTE (PT_BYTE
)) == 1)
1431 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1433 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1435 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1437 && !windows_or_buffers_changed
1438 && EQ (current_buffer
->selective_display
, Qnil
)
1439 && !detect_input_pending ()
1440 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1441 && NILP (Vexecuting_macro
))
1442 direct_output_forward_char (1);
1445 else if (EQ (Vthis_command
, Qbackward_char
) && PT
> BEGV
)
1447 struct Lisp_Char_Table
*dp
1448 = window_display_table (XWINDOW (selected_window
));
1450 lose
= FETCH_CHAR (PT_BYTE
);
1452 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1453 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1454 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1455 && (lose
>= 0x20 && lose
< 0x7f)))
1456 : (lose
>= 0x20 && lose
< 0x7f))
1457 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1459 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1461 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1463 && !windows_or_buffers_changed
1464 && EQ (current_buffer
->selective_display
, Qnil
)
1465 && !detect_input_pending ()
1466 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1467 && NILP (Vexecuting_macro
))
1468 direct_output_forward_char (-1);
1471 else if (EQ (Vthis_command
, Qself_insert_command
)
1472 /* Try this optimization only on ascii keystrokes. */
1473 && INTEGERP (last_command_char
))
1475 unsigned int c
= XINT (last_command_char
);
1477 if (NILP (Vexecuting_macro
)
1478 && !EQ (minibuf_window
, selected_window
))
1480 if (!nonundocount
|| nonundocount
>= 20)
1488 lose
= ((XFASTINT (XWINDOW (selected_window
)->last_modified
)
1490 || (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1492 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1494 || MODIFF
<= SAVE_MODIFF
1495 || windows_or_buffers_changed
1496 || !EQ (current_buffer
->selective_display
, Qnil
)
1497 || detect_input_pending ()
1498 || !NILP (XWINDOW (selected_window
)->column_number_displayed
)
1499 || !NILP (Vexecuting_macro
));
1501 value
= internal_self_insert (c
, 0);
1506 /* VALUE == 1 when AFTER-CHANGE functions are
1507 installed which is the case most of the time
1508 because FONT-LOCK installs one. */
1509 if (!lose
&& !value
)
1510 direct_output_for_insert (c
);
1515 /* Here for a command that isn't executed directly */
1517 #ifdef HAVE_X_WINDOWS
1518 if (display_busy_cursor_p
)
1520 if (inhibit_busy_cursor
!= 2)
1521 inhibit_busy_cursor
= 0;
1522 if (!inhibit_busy_cursor
)
1523 Fx_show_busy_cursor ();
1528 if (NILP (current_kboard
->Vprefix_arg
))
1530 Fcommand_execute (Vthis_command
, Qnil
, Qnil
, Qnil
);
1533 current_kboard
->Vlast_prefix_arg
= Vcurrent_prefix_arg
;
1535 /* Note that the value cell will never directly contain nil
1536 if the symbol is a local variable. */
1537 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1538 safe_run_hooks (Qpost_command_hook
);
1540 /* If displaying a message, resize the echo area window to fit
1541 that message's size exactly. */
1542 if (!NILP (echo_area_buffer
[0]))
1543 resize_echo_area_axactly ();
1545 if (!NILP (Vdeferred_action_list
))
1546 safe_run_hooks (Qdeferred_action_function
);
1548 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1550 if (NILP (Vunread_command_events
)
1551 && NILP (Vunread_input_method_events
)
1552 && NILP (Vunread_post_input_method_events
)
1553 && NILP (Vexecuting_macro
)
1554 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1, 1)))
1555 safe_run_hooks (Qpost_command_idle_hook
);
1558 /* If there is a prefix argument,
1559 1) We don't want Vlast_command to be ``universal-argument''
1560 (that would be dumb), so don't set Vlast_command,
1561 2) we want to leave echoing on so that the prefix will be
1562 echoed as part of this key sequence, so don't call
1564 3) we want to leave this_command_key_count non-zero, so that
1565 read_char will realize that it is re-reading a character, and
1566 not echo it a second time.
1568 If the command didn't actually create a prefix arg,
1569 but is merely a frame event that is transparent to prefix args,
1570 then the above doesn't apply. */
1571 if (NILP (current_kboard
->Vprefix_arg
) || CONSP (last_command_char
))
1573 current_kboard
->Vlast_command
= Vthis_command
;
1574 current_kboard
->Vreal_last_command
= real_this_command
;
1576 this_command_key_count
= 0;
1577 this_single_command_key_start
= 0;
1580 if (!NILP (current_buffer
->mark_active
) && !NILP (Vrun_hooks
))
1582 if (!NILP (Vdeactivate_mark
) && !NILP (Vtransient_mark_mode
))
1584 current_buffer
->mark_active
= Qnil
;
1585 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
1587 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
1588 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
1593 if (current_buffer
== prev_buffer
1594 && last_point_position
!= PT
1595 && NILP (Vdisable_point_adjustment
)
1596 && NILP (Vglobal_disable_point_adjustment
))
1597 adjust_point_for_property (last_point_position
);
1599 /* Install chars successfully executed in kbd macro. */
1601 if (!NILP (current_kboard
->defining_kbd_macro
)
1602 && NILP (current_kboard
->Vprefix_arg
))
1603 finalize_kbd_macro_chars ();
1607 any_kboard_state ();
1612 extern Lisp_Object Qcomposition
, Qdisplay
;
1614 /* Adjust point to a boundary of a region that has such a property
1615 that should be treated intangible. For the moment, we check
1616 `composition' and `display' property. LAST_PT is the last position
1620 adjust_point_for_property (last_pt
)
1625 int check_composition
= 1, check_display
= 1;
1627 while (check_composition
|| check_display
)
1629 if (check_composition
1630 && PT
> BEGV
&& PT
< ZV
1631 && get_property_and_range (PT
, Qcomposition
, &val
, &start
, &end
, Qnil
)
1632 && COMPOSITION_VALID_P (start
, end
, val
)
1633 && start
< PT
&& end
> PT
1634 && (last_pt
<= start
|| last_pt
>= end
))
1642 check_composition
= 0;
1644 && PT
> BEGV
&& PT
< ZV
1645 && get_property_and_range (PT
, Qdisplay
, &val
, &start
, &end
, Qnil
)
1646 && start
< PT
&& end
> PT
1647 && (last_pt
<= start
|| last_pt
>= end
))
1653 check_composition
= 1;
1659 /* Subroutine for safe_run_hooks: run the hook HOOK. */
1662 safe_run_hooks_1 (hook
)
1665 return call1 (Vrun_hooks
, Vinhibit_quit
);
1668 /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */
1671 safe_run_hooks_error (data
)
1674 Fset (Vinhibit_quit
, Qnil
);
1677 /* If we get an error while running the hook, cause the hook variable
1678 to be nil. Also inhibit quits, so that C-g won't cause the hook
1679 to mysteriously evaporate. */
1682 safe_run_hooks (hook
)
1685 int count
= specpdl_ptr
- specpdl
;
1686 specbind (Qinhibit_quit
, hook
);
1688 internal_condition_case (safe_run_hooks_1
, Qt
, safe_run_hooks_error
);
1690 unbind_to (count
, Qnil
);
1693 /* Number of seconds between polling for input. */
1696 /* Nonzero means polling for input is temporarily suppressed. */
1697 int poll_suppress_count
;
1699 /* Nonzero if polling_for_input is actually being used. */
1700 int polling_for_input
;
1702 #ifdef POLL_FOR_INPUT
1704 /* Handle an alarm once each second and read pending input
1705 so as to handle a C-g if it comces in. */
1708 input_poll_signal (signalnum
) /* If we don't have an argument, */
1709 int signalnum
; /* some compilers complain in signal calls. */
1711 /* This causes the call to start_polling at the end
1712 to do its job. It also arranges for a quit or error
1713 from within read_avail_input to resume polling. */
1714 poll_suppress_count
++;
1715 if (interrupt_input_blocked
== 0
1716 && !waiting_for_input
)
1717 read_avail_input (0);
1718 /* Turn on the SIGALRM handler and request another alarm. */
1724 /* Begin signals to poll for input, if they are appropriate.
1725 This function is called unconditionally from various places. */
1730 #ifdef POLL_FOR_INPUT
1731 if (read_socket_hook
&& !interrupt_input
)
1733 poll_suppress_count
--;
1734 if (poll_suppress_count
== 0)
1736 signal (SIGALRM
, input_poll_signal
);
1737 polling_for_input
= 1;
1738 alarm (polling_period
);
1744 /* Nonzero if we are using polling to handle input asynchronously. */
1747 input_polling_used ()
1749 #ifdef POLL_FOR_INPUT
1750 return read_socket_hook
&& !interrupt_input
;
1756 /* Turn off polling. */
1761 #ifdef POLL_FOR_INPUT
1762 if (read_socket_hook
&& !interrupt_input
)
1764 if (poll_suppress_count
== 0)
1766 polling_for_input
= 0;
1769 poll_suppress_count
++;
1774 /* Set the value of poll_suppress_count to COUNT
1775 and start or stop polling accordingly. */
1778 set_poll_suppress_count (count
)
1781 #ifdef POLL_FOR_INPUT
1782 if (count
== 0 && poll_suppress_count
!= 0)
1784 poll_suppress_count
= 1;
1787 else if (count
!= 0 && poll_suppress_count
== 0)
1791 poll_suppress_count
= count
;
1795 /* Bind polling_period to a value at least N.
1796 But don't decrease it. */
1799 bind_polling_period (n
)
1802 #ifdef POLL_FOR_INPUT
1803 int new = polling_period
;
1809 specbind (Qpolling_period
, make_number (new));
1810 /* Start a new alarm with the new period. */
1815 /* Apply the control modifier to CHARACTER. */
1821 /* Save the upper bits here. */
1822 int upper
= c
& ~0177;
1826 /* Everything in the columns containing the upper-case letters
1827 denotes a control character. */
1828 if (c
>= 0100 && c
< 0140)
1832 /* Set the shift modifier for a control char
1833 made from a shifted letter. But only for letters! */
1834 if (oc
>= 'A' && oc
<= 'Z')
1835 c
|= shift_modifier
;
1838 /* The lower-case letters denote control characters too. */
1839 else if (c
>= 'a' && c
<= 'z')
1842 /* Include the bits for control and shift
1843 only if the basic ASCII code can't indicate them. */
1847 /* Replace the high bits. */
1848 c
|= (upper
& ~ctrl_modifier
);
1855 /* Input of single characters from keyboard */
1857 Lisp_Object
print_help ();
1858 static Lisp_Object
kbd_buffer_get_event ();
1859 static void record_char ();
1862 static jmp_buf wrong_kboard_jmpbuf
;
1865 /* read a character from the keyboard; call the redisplay if needed */
1866 /* commandflag 0 means do not do auto-saving, but do do redisplay.
1867 -1 means do not do redisplay, but do do autosaving.
1870 /* The arguments MAPS and NMAPS are for menu prompting.
1871 MAPS is an array of keymaps; NMAPS is the length of MAPS.
1873 PREV_EVENT is the previous input event, or nil if we are reading
1874 the first event of a key sequence (or not reading a key sequence).
1875 If PREV_EVENT is t, that is a "magic" value that says
1876 not to run input methods, but in other respects to act as if
1877 not reading a key sequence.
1879 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
1880 if we used a mouse menu to read the input, or zero otherwise. If
1881 USED_MOUSE_MENU is null, we don't dereference it.
1883 Value is t if we showed a menu and the user rejected it. */
1886 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
)
1890 Lisp_Object prev_event
;
1891 int *used_mouse_menu
;
1895 jmp_buf local_getcjmp
;
1897 int key_already_recorded
= 0;
1898 Lisp_Object tem
, save
;
1899 Lisp_Object previous_echo_area_message
;
1900 Lisp_Object also_record
;
1902 struct gcpro gcpro1
, gcpro2
;
1906 before_command_key_count
= this_command_key_count
;
1907 before_command_echo_length
= echo_length ();
1909 previous_echo_area_message
= Qnil
;
1911 GCPRO2 (c
, previous_echo_area_message
);
1916 if (CONSP (Vunread_post_input_method_events
))
1918 c
= XCAR (Vunread_post_input_method_events
);
1919 Vunread_post_input_method_events
1920 = XCDR (Vunread_post_input_method_events
);
1922 /* Undo what read_char_x_menu_prompt did when it unread
1923 additional keys returned by Fx_popup_menu. */
1925 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
)))
1933 if (unread_command_char
!= -1)
1935 XSETINT (c
, unread_command_char
);
1936 unread_command_char
= -1;
1942 if (CONSP (Vunread_command_events
))
1944 c
= XCAR (Vunread_command_events
);
1945 Vunread_command_events
= XCDR (Vunread_command_events
);
1947 /* Undo what read_char_x_menu_prompt did when it unread
1948 additional keys returned by Fx_popup_menu. */
1950 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
)))
1955 goto reread_for_input_method
;
1958 if (CONSP (Vunread_input_method_events
))
1960 c
= XCAR (Vunread_input_method_events
);
1961 Vunread_input_method_events
= XCDR (Vunread_input_method_events
);
1963 /* Undo what read_char_x_menu_prompt did when it unread
1964 additional keys returned by Fx_popup_menu. */
1966 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
)))
1970 goto reread_for_input_method
;
1973 /* If there is no function key translated before
1974 reset-this-command-lengths takes effect, forget about it. */
1975 before_command_restore_flag
= 0;
1977 if (!NILP (Vexecuting_macro
))
1979 /* We set this to Qmacro; since that's not a frame, nobody will
1980 try to switch frames on us, and the selected window will
1983 Since this event came from a macro, it would be misleading to
1984 leave internal_last_event_frame set to wherever the last
1985 real event came from. Normally, a switch-frame event selects
1986 internal_last_event_frame after each command is read, but
1987 events read from a macro should never cause a new frame to be
1989 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
1991 /* Exit the macro if we are at the end.
1992 Also, some things replace the macro with t
1993 to force an early exit. */
1994 if (EQ (Vexecuting_macro
, Qt
)
1995 || executing_macro_index
>= XFASTINT (Flength (Vexecuting_macro
)))
2001 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
2002 if (STRINGP (Vexecuting_macro
)
2003 && (XINT (c
) & 0x80))
2004 XSETFASTINT (c
, CHAR_META
| (XINT (c
) & ~0x80));
2006 executing_macro_index
++;
2011 if (!NILP (unread_switch_frame
))
2013 c
= unread_switch_frame
;
2014 unread_switch_frame
= Qnil
;
2016 /* This event should make it into this_command_keys, and get echoed
2017 again, so we do not set `reread'. */
2021 /* if redisplay was requested */
2022 if (commandflag
>= 0)
2024 /* If there is pending input, process any events which are not
2025 user-visible, such as X selection_request events. */
2027 || detect_input_pending_run_timers (0))
2028 swallow_events (0); /* may clear input_pending */
2030 /* Redisplay if no pending input. */
2031 while (!input_pending
)
2036 /* Normal case: no input arrived during redisplay. */
2039 /* Input arrived and pre-empted redisplay.
2040 Process any events which are not user-visible. */
2042 /* If that cleared input_pending, try again to redisplay. */
2046 /* Message turns off echoing unless more keystrokes turn it on again. */
2047 if (/* There is a current message. */
2048 !NILP (echo_area_buffer
[0])
2049 /* And we're not echoing from this kboard. */
2050 && echo_kboard
!= current_kboard
2051 /* And it's either not ok to echo (ok_to_echo == NULL), or the
2052 last char echoed was from a different kboard. */
2053 && ok_to_echo_at_next_pause
!= echo_kboard
)
2056 /* If already echoing, continue. */
2059 /* Try reading a character via menu prompting in the minibuf.
2060 Try this before the sit-for, because the sit-for
2061 would do the wrong thing if we are supposed to do
2062 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
2063 after a mouse event so don't try a minibuf menu. */
2065 if (nmaps
> 0 && INTERACTIVE
2066 && !NILP (prev_event
) && ! EVENT_HAS_PARAMETERS (prev_event
)
2067 /* Don't bring up a menu if we already have another event. */
2068 && NILP (Vunread_command_events
)
2069 && unread_command_char
< 0
2070 && !detect_input_pending_run_timers (0))
2072 c
= read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
);
2075 key_already_recorded
= 1;
2080 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet.
2081 We will do that below, temporarily for short sections of code,
2082 when appropriate. local_getcjmp must be in effect
2083 around any call to sit_for or kbd_buffer_get_event;
2084 it *must not* be in effect when we call redisplay. */
2086 if (_setjmp (local_getcjmp
))
2088 XSETINT (c
, quit_char
);
2089 internal_last_event_frame
= selected_frame
;
2090 Vlast_event_frame
= internal_last_event_frame
;
2091 /* If we report the quit char as an event,
2092 don't do so more than once. */
2093 if (!NILP (Vinhibit_quit
))
2098 KBOARD
*kb
= FRAME_KBOARD (XFRAME (selected_frame
));
2099 if (kb
!= current_kboard
)
2101 Lisp_Object
*tailp
= &kb
->kbd_queue
;
2102 /* We shouldn't get here if we were in single-kboard mode! */
2105 while (CONSP (*tailp
))
2106 tailp
= &XCDR (*tailp
);
2109 *tailp
= Fcons (c
, Qnil
);
2110 kb
->kbd_queue_has_data
= 1;
2111 current_kboard
= kb
;
2112 /* This is going to exit from read_char
2113 so we had better get rid of this frame's stuff. */
2115 longjmp (wrong_kboard_jmpbuf
, 1);
2122 timer_start_idle ();
2124 /* If in middle of key sequence and minibuffer not active,
2125 start echoing if enough time elapses. */
2127 if (minibuf_level
== 0
2128 && !current_kboard
->immediate_echo
2129 && this_command_key_count
> 0
2131 && echo_keystrokes
> 0
2132 && (/* No message. */
2133 NILP (echo_area_buffer
[0])
2134 /* Or empty message. */
2135 || (BUF_BEG (XBUFFER (echo_area_buffer
[0]))
2136 == BUF_Z (XBUFFER (echo_area_buffer
[0])))
2137 /* Or already echoing from same kboard. */
2138 || (echo_kboard
&& ok_to_echo_at_next_pause
== echo_kboard
)
2139 /* Or not echoing before and echoing allowed. */
2140 || (!echo_kboard
&& ok_to_echo_at_next_pause
)))
2144 /* After a mouse event, start echoing right away.
2145 This is because we are probably about to display a menu,
2146 and we don't want to delay before doing so. */
2147 if (EVENT_HAS_PARAMETERS (prev_event
))
2151 save_getcjmp (save_jump
);
2152 restore_getcjmp (local_getcjmp
);
2153 tem0
= sit_for (echo_keystrokes
, 0, 1, 1, 0);
2154 restore_getcjmp (save_jump
);
2156 && ! CONSP (Vunread_command_events
))
2161 /* Maybe auto save due to number of keystrokes. */
2163 if (commandflag
!= 0
2164 && auto_save_interval
> 0
2165 && num_nonmacro_input_events
- last_auto_save
> max (auto_save_interval
, 20)
2166 && !detect_input_pending_run_timers (0))
2168 Fdo_auto_save (Qnil
, Qnil
);
2169 /* Hooks can actually change some buffers in auto save. */
2173 /* Try reading using an X menu.
2174 This is never confused with reading using the minibuf
2175 because the recursive call of read_char in read_char_minibuf_menu_prompt
2176 does not pass on any keymaps. */
2178 if (nmaps
> 0 && INTERACTIVE
2179 && !NILP (prev_event
)
2180 && EVENT_HAS_PARAMETERS (prev_event
)
2181 && !EQ (XCAR (prev_event
), Qmenu_bar
)
2182 && !EQ (XCAR (prev_event
), Qtool_bar
)
2183 /* Don't bring up a menu if we already have another event. */
2184 && NILP (Vunread_command_events
)
2185 && unread_command_char
< 0)
2187 c
= read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
2189 /* Now that we have read an event, Emacs is not idle. */
2195 /* Maybe autosave and/or garbage collect due to idleness. */
2197 if (INTERACTIVE
&& NILP (c
))
2199 int delay_level
, buffer_size
;
2201 /* Slow down auto saves logarithmically in size of current buffer,
2202 and garbage collect while we're at it. */
2203 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
2204 last_non_minibuf_size
= Z
- BEG
;
2205 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
2207 while (buffer_size
> 64)
2208 delay_level
++, buffer_size
-= buffer_size
>> 2;
2209 if (delay_level
< 4) delay_level
= 4;
2210 /* delay_level is 4 for files under around 50k, 7 at 100k,
2211 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
2213 /* Auto save if enough time goes by without input. */
2214 if (commandflag
!= 0
2215 && num_nonmacro_input_events
> last_auto_save
2216 && INTEGERP (Vauto_save_timeout
)
2217 && XINT (Vauto_save_timeout
) > 0)
2221 save_getcjmp (save_jump
);
2222 restore_getcjmp (local_getcjmp
);
2223 tem0
= sit_for (delay_level
* XFASTINT (Vauto_save_timeout
) / 4,
2225 restore_getcjmp (save_jump
);
2228 && ! CONSP (Vunread_command_events
))
2230 Fdo_auto_save (Qnil
, Qnil
);
2232 /* If we have auto-saved and there is still no input
2233 available, garbage collect if there has been enough
2234 consing going on to make it worthwhile. */
2235 if (!detect_input_pending_run_timers (0)
2236 && consing_since_gc
> gc_cons_threshold
/ 2)
2237 Fgarbage_collect ();
2244 /* If this has become non-nil here, it has been set by a timer
2245 or sentinel or filter. */
2246 if (CONSP (Vunread_command_events
))
2248 c
= XCAR (Vunread_command_events
);
2249 Vunread_command_events
= XCDR (Vunread_command_events
);
2252 /* Read something from current KBOARD's side queue, if possible. */
2256 if (current_kboard
->kbd_queue_has_data
)
2258 if (!CONSP (current_kboard
->kbd_queue
))
2260 c
= XCAR (current_kboard
->kbd_queue
);
2261 current_kboard
->kbd_queue
2262 = XCDR (current_kboard
->kbd_queue
);
2263 if (NILP (current_kboard
->kbd_queue
))
2264 current_kboard
->kbd_queue_has_data
= 0;
2265 input_pending
= readable_events (0);
2266 if (EVENT_HAS_PARAMETERS (c
)
2267 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qswitch_frame
))
2268 internal_last_event_frame
= XCAR (XCDR (c
));
2269 Vlast_event_frame
= internal_last_event_frame
;
2274 /* If current_kboard's side queue is empty check the other kboards.
2275 If one of them has data that we have not yet seen here,
2276 switch to it and process the data waiting for it.
2278 Note: if the events queued up for another kboard
2279 have already been seen here, and therefore are not a complete command,
2280 the kbd_queue_has_data field is 0, so we skip that kboard here.
2281 That's to avoid an infinite loop switching between kboards here. */
2282 if (NILP (c
) && !single_kboard
)
2285 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2286 if (kb
->kbd_queue_has_data
)
2288 current_kboard
= kb
;
2289 /* This is going to exit from read_char
2290 so we had better get rid of this frame's stuff. */
2292 longjmp (wrong_kboard_jmpbuf
, 1);
2301 /* Finally, we read from the main queue,
2302 and if that gives us something we can't use yet, we put it on the
2303 appropriate side queue and try again. */
2309 /* Actually read a character, waiting if necessary. */
2310 save_getcjmp (save_jump
);
2311 restore_getcjmp (local_getcjmp
);
2312 c
= kbd_buffer_get_event (&kb
, used_mouse_menu
);
2313 restore_getcjmp (save_jump
);
2316 if (! NILP (c
) && (kb
!= current_kboard
))
2318 Lisp_Object
*tailp
= &kb
->kbd_queue
;
2319 while (CONSP (*tailp
))
2320 tailp
= &XCDR (*tailp
);
2323 *tailp
= Fcons (c
, Qnil
);
2324 kb
->kbd_queue_has_data
= 1;
2328 current_kboard
= kb
;
2329 /* This is going to exit from read_char
2330 so we had better get rid of this frame's stuff. */
2332 longjmp (wrong_kboard_jmpbuf
, 1);
2337 /* Terminate Emacs in batch mode if at eof. */
2338 if (noninteractive
&& INTEGERP (c
) && XINT (c
) < 0)
2339 Fkill_emacs (make_number (1));
2343 /* Add in any extra modifiers, where appropriate. */
2344 if ((extra_keyboard_modifiers
& CHAR_CTL
)
2345 || ((extra_keyboard_modifiers
& 0177) < ' '
2346 && (extra_keyboard_modifiers
& 0177) != 0))
2347 XSETINT (c
, make_ctrl_char (XINT (c
)));
2349 /* Transfer any other modifier bits directly from
2350 extra_keyboard_modifiers to c. Ignore the actual character code
2351 in the low 16 bits of extra_keyboard_modifiers. */
2352 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
2363 if (commandflag
>= 0
2364 && !input_pending
&& !detect_input_pending_run_timers (0))
2372 /* Buffer switch events are only for internal wakeups
2373 so don't show them to the user.
2374 Also, don't record a key if we already did. */
2375 if (BUFFERP (c
) || key_already_recorded
)
2378 /* Process special events within read_char
2379 and loop around to read another event. */
2382 tem
= get_keyelt (access_keymap (get_keymap_1 (Vspecial_event_map
, 0, 0),
2388 int was_locked
= single_kboard
;
2390 last_input_char
= c
;
2391 Fcommand_execute (tem
, Qnil
, Fvector (1, &last_input_char
), Qt
);
2393 /* Resume allowing input from any kboard, if that was true before. */
2395 any_kboard_state ();
2400 /* Handle things that only apply to characters. */
2403 /* If kbd_buffer_get_event gave us an EOF, return that. */
2407 if ((STRINGP (Vkeyboard_translate_table
)
2408 && XSTRING (Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
2409 || (VECTORP (Vkeyboard_translate_table
)
2410 && XVECTOR (Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
2411 || (CHAR_TABLE_P (Vkeyboard_translate_table
)
2412 && CHAR_TABLE_ORDINARY_SLOTS
> (unsigned) XFASTINT (c
)))
2415 d
= Faref (Vkeyboard_translate_table
, c
);
2416 /* nil in keyboard-translate-table means no translation. */
2422 /* If this event is a mouse click in the menu bar,
2423 return just menu-bar for now. Modify the mouse click event
2424 so we won't do this twice, then queue it up. */
2425 if (EVENT_HAS_PARAMETERS (c
)
2427 && CONSP (EVENT_START (c
))
2428 && CONSP (XCDR (EVENT_START (c
))))
2432 posn
= POSN_BUFFER_POSN (EVENT_START (c
));
2433 /* Handle menu-bar events:
2434 insert the dummy prefix event `menu-bar'. */
2435 if (EQ (posn
, Qmenu_bar
) || EQ (posn
, Qtool_bar
))
2437 /* Change menu-bar to (menu-bar) as the event "position". */
2438 POSN_BUFFER_POSN (EVENT_START (c
)) = Fcons (posn
, Qnil
);
2441 Vunread_command_events
= Fcons (c
, Vunread_command_events
);
2446 /* Store these characters into recent_keys, the dribble file if any,
2447 and the keyboard macro being defined, if any. */
2449 if (! NILP (also_record
))
2450 record_char (also_record
);
2452 /* Wipe the echo area.
2453 But first, if we are about to use an input method,
2454 save the echo area contents for it to refer to. */
2456 && ! NILP (Vinput_method_function
)
2457 && (unsigned) XINT (c
) >= ' '
2458 && (unsigned) XINT (c
) < 127)
2460 previous_echo_area_message
= Fcurrent_message ();
2461 Vinput_method_previous_message
= previous_echo_area_message
;
2464 /* Now wipe the echo area. */
2465 if (!NILP (echo_area_buffer
[0]))
2466 safe_run_hooks (Qecho_area_clear_hook
);
2467 clear_message (1, 0);
2469 reread_for_input_method
:
2471 /* Pass this to the input method, if appropriate. */
2473 && ! NILP (Vinput_method_function
)
2474 /* Don't run the input method within a key sequence,
2475 after the first event of the key sequence. */
2476 && NILP (prev_event
)
2477 && (unsigned) XINT (c
) >= ' '
2478 && (unsigned) XINT (c
) < 127)
2482 struct gcpro gcpro1
;
2483 int count
= specpdl_ptr
- specpdl
;
2485 /* Save the echo status. */
2486 int saved_immediate_echo
= current_kboard
->immediate_echo
;
2487 struct kboard
*saved_ok_to_echo
= ok_to_echo_at_next_pause
;
2488 int saved_echo_after_prompt
= current_kboard
->echo_after_prompt
;
2490 if (before_command_restore_flag
)
2492 this_command_key_count
= before_command_key_count_1
;
2493 if (this_command_key_count
< this_single_command_key_start
)
2494 this_single_command_key_start
= this_command_key_count
;
2495 echo_truncate (before_command_echo_length_1
);
2496 before_command_restore_flag
= 0;
2499 /* Save the this_command_keys status. */
2500 key_count
= this_command_key_count
;
2503 keys
= Fcopy_sequence (this_command_keys
);
2508 /* Clear out this_command_keys. */
2509 this_command_key_count
= 0;
2511 /* Now wipe the echo area. */
2512 if (!NILP (echo_area_buffer
[0]))
2513 safe_run_hooks (Qecho_area_clear_hook
);
2514 clear_message (1, 0);
2517 /* If we are not reading a key sequence,
2518 never use the echo area. */
2521 specbind (Qinput_method_use_echo_area
, Qt
);
2524 /* Call the input method. */
2525 tem
= call1 (Vinput_method_function
, c
);
2527 tem
= unbind_to (count
, tem
);
2529 /* Restore the saved echoing state
2530 and this_command_keys state. */
2531 this_command_key_count
= key_count
;
2533 this_command_keys
= keys
;
2536 ok_to_echo_at_next_pause
= saved_ok_to_echo
;
2537 current_kboard
->echo_after_prompt
= saved_echo_after_prompt
;
2538 if (saved_immediate_echo
)
2543 /* The input method can return no events. */
2546 /* Bring back the previous message, if any. */
2547 if (! NILP (previous_echo_area_message
))
2548 message_with_string ("%s", previous_echo_area_message
, 0);
2551 /* It returned one event or more. */
2553 Vunread_post_input_method_events
2554 = nconc2 (XCDR (tem
), Vunread_post_input_method_events
);
2559 /* Display help if not echoing. */
2561 && EQ (XCAR (c
), Qhelp_echo
))
2563 Lisp_Object msg
= XCDR (XCDR (c
));
2565 if (!NILP (Vshow_help_function
))
2566 call1 (Vshow_help_function
, msg
);
2567 else if (!echoing
&& !MINI_WINDOW_P (XWINDOW (selected_window
)))
2570 message3_nolog (msg
, XSTRING (msg
)->size
, STRING_MULTIBYTE (msg
));
2578 if (this_command_key_count
== 0 || ! reread
)
2580 before_command_key_count
= this_command_key_count
;
2581 before_command_echo_length
= echo_length ();
2583 /* Don't echo mouse motion events. */
2585 && ! (EVENT_HAS_PARAMETERS (c
)
2586 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
2589 if (! NILP (also_record
))
2590 echo_char (also_record
);
2591 /* Once we reread a character, echoing can happen
2592 the next time we pause to read a new one. */
2593 ok_to_echo_at_next_pause
= current_kboard
;
2596 /* Record this character as part of the current key. */
2597 add_command_key (c
);
2598 if (! NILP (also_record
))
2599 add_command_key (also_record
);
2602 last_input_char
= c
;
2605 /* Process the help character specially if enabled */
2606 if (!NILP (Vhelp_form
) && help_char_p (c
))
2609 count
= specpdl_ptr
- specpdl
;
2611 record_unwind_protect (Fset_window_configuration
,
2612 Fcurrent_window_configuration (Qnil
));
2614 tem0
= Feval (Vhelp_form
);
2616 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
2620 c
= read_char (0, 0, 0, Qnil
, 0);
2621 while (BUFFERP (c
));
2622 /* Remove the help from the frame */
2623 unbind_to (count
, Qnil
);
2626 if (EQ (c
, make_number (040)))
2630 c
= read_char (0, 0, 0, Qnil
, 0);
2631 while (BUFFERP (c
));
2638 /* Record a key that came from a mouse menu.
2639 Record it for echoing, for this-command-keys, and so on. */
2645 /* Wipe the echo area. */
2646 clear_message (1, 0);
2650 before_command_key_count
= this_command_key_count
;
2651 before_command_echo_length
= echo_length ();
2653 /* Don't echo mouse motion events. */
2654 if (echo_keystrokes
)
2658 /* Once we reread a character, echoing can happen
2659 the next time we pause to read a new one. */
2660 ok_to_echo_at_next_pause
= 0;
2663 /* Record this character as part of the current key. */
2664 add_command_key (c
);
2666 /* Re-reading in the middle of a command */
2667 last_input_char
= c
;
2671 /* Return 1 if should recognize C as "the help character". */
2679 if (EQ (c
, Vhelp_char
))
2681 for (tail
= Vhelp_event_list
; CONSP (tail
); tail
= XCDR (tail
))
2682 if (EQ (c
, XCAR (tail
)))
2687 /* Record the input event C in various ways. */
2694 XVECTOR (recent_keys
)->contents
[recent_keys_index
] = c
;
2695 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
2696 recent_keys_index
= 0;
2698 /* Write c to the dribble file. If c is a lispy event, write
2699 the event's symbol to the dribble file, in <brackets>. Bleaugh.
2700 If you, dear reader, have a better idea, you've got the source. :-) */
2705 if (XUINT (c
) < 0x100)
2706 putc (XINT (c
), dribble
);
2708 fprintf (dribble
, " 0x%x", (int) XUINT (c
));
2712 Lisp_Object dribblee
;
2714 /* If it's a structured event, take the event header. */
2715 dribblee
= EVENT_HEAD (c
);
2717 if (SYMBOLP (dribblee
))
2719 putc ('<', dribble
);
2720 fwrite (XSYMBOL (dribblee
)->name
->data
, sizeof (char),
2721 STRING_BYTES (XSYMBOL (dribblee
)->name
),
2723 putc ('>', dribble
);
2730 store_kbd_macro_char (c
);
2732 num_nonmacro_input_events
++;
2739 struct buffer
*old
= current_buffer
;
2740 Fprinc (object
, Qnil
);
2741 set_buffer_internal (XBUFFER (Vstandard_output
));
2742 call0 (intern ("help-mode"));
2743 set_buffer_internal (old
);
2747 /* Copy out or in the info on where C-g should throw to.
2748 This is used when running Lisp code from within get_char,
2749 in case get_char is called recursively.
2750 See read_process_output. */
2756 bcopy (getcjmp
, temp
, sizeof getcjmp
);
2760 restore_getcjmp (temp
)
2763 bcopy (temp
, getcjmp
, sizeof getcjmp
);
2768 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
2769 of this function. */
2772 tracking_off (old_value
)
2773 Lisp_Object old_value
;
2775 do_mouse_tracking
= old_value
;
2776 if (NILP (old_value
))
2778 /* Redisplay may have been preempted because there was input
2779 available, and it assumes it will be called again after the
2780 input has been processed. If the only input available was
2781 the sort that we have just disabled, then we need to call
2783 if (!readable_events (1))
2785 redisplay_preserve_echo_area ();
2786 get_input_pending (&input_pending
, 1);
2791 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
2792 "Evaluate BODY with mouse movement events enabled.\n\
2793 Within a `track-mouse' form, mouse motion generates input events that\n\
2794 you can read with `read-event'.\n\
2795 Normally, mouse motion is ignored.")
2799 int count
= specpdl_ptr
- specpdl
;
2802 record_unwind_protect (tracking_off
, do_mouse_tracking
);
2804 do_mouse_tracking
= Qt
;
2806 val
= Fprogn (args
);
2807 return unbind_to (count
, val
);
2810 /* If mouse has moved on some frame, return one of those frames.
2811 Return 0 otherwise. */
2816 Lisp_Object tail
, frame
;
2818 FOR_EACH_FRAME (tail
, frame
)
2820 if (XFRAME (frame
)->mouse_moved
)
2821 return XFRAME (frame
);
2827 #endif /* HAVE_MOUSE */
2829 /* Low level keyboard/mouse input.
2830 kbd_buffer_store_event places events in kbd_buffer, and
2831 kbd_buffer_get_event retrieves them. */
2833 /* Return true iff there are any events in the queue that read-char
2834 would return. If this returns false, a read-char would block. */
2836 readable_events (do_timers_now
)
2840 timer_check (do_timers_now
);
2842 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2845 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2850 if (current_kboard
->kbd_queue_has_data
)
2856 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2857 if (kb
->kbd_queue_has_data
)
2863 /* Set this for debugging, to have a way to get out */
2868 event_to_kboard (event
)
2869 struct input_event
*event
;
2872 frame
= event
->frame_or_window
;
2874 frame
= XCAR (frame
);
2875 else if (WINDOWP (frame
))
2876 frame
= WINDOW_FRAME (XWINDOW (frame
));
2878 /* There are still some events that don't set this field.
2879 For now, just ignore the problem.
2880 Also ignore dead frames here. */
2881 if (!FRAMEP (frame
) || !FRAME_LIVE_P (XFRAME (frame
)))
2884 return FRAME_KBOARD (XFRAME (frame
));
2888 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
2891 kbd_buffer_store_event (event
)
2892 register struct input_event
*event
;
2894 if (event
->kind
== no_event
)
2897 if (event
->kind
== ascii_keystroke
)
2899 register int c
= event
->code
& 0377;
2901 if (event
->modifiers
& ctrl_modifier
)
2902 c
= make_ctrl_char (c
);
2904 c
|= (event
->modifiers
2905 & (meta_modifier
| alt_modifier
2906 | hyper_modifier
| super_modifier
));
2910 extern SIGTYPE
interrupt_signal ();
2913 struct input_event
*sp
;
2916 && (kb
= FRAME_KBOARD (XFRAME (event
->frame_or_window
)),
2917 kb
!= current_kboard
))
2920 = Fcons (make_lispy_switch_frame (event
->frame_or_window
),
2921 Fcons (make_number (c
), Qnil
));
2922 kb
->kbd_queue_has_data
= 1;
2923 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
2925 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
2928 if (event_to_kboard (sp
) == kb
)
2930 sp
->kind
= no_event
;
2931 sp
->frame_or_window
= Qnil
;
2938 /* If this results in a quit_char being returned to Emacs as
2939 input, set Vlast_event_frame properly. If this doesn't
2940 get returned to Emacs as an event, the next event read
2941 will set Vlast_event_frame again, so this is safe to do. */
2945 focus
= FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
2947 focus
= event
->frame_or_window
;
2948 internal_last_event_frame
= focus
;
2949 Vlast_event_frame
= focus
;
2952 last_event_timestamp
= event
->timestamp
;
2953 interrupt_signal ();
2957 if (c
&& c
== stop_character
)
2963 /* Don't insert two buffer_switch_event's in a row.
2964 Just ignore the second one. */
2965 else if (event
->kind
== buffer_switch_event
2966 && kbd_fetch_ptr
!= kbd_store_ptr
2967 && kbd_store_ptr
->kind
== buffer_switch_event
)
2970 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
2971 kbd_store_ptr
= kbd_buffer
;
2973 /* Don't let the very last slot in the buffer become full,
2974 since that would make the two pointers equal,
2975 and that is indistinguishable from an empty buffer.
2976 Discard the event if it would fill the last slot. */
2977 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
2979 struct input_event
*sp
= kbd_store_ptr
;
2980 sp
->kind
= event
->kind
;
2981 if (event
->kind
== selection_request_event
)
2983 /* We must not use the ordinary copying code for this case,
2984 since `part' is an enum and copying it might not copy enough
2986 bcopy (event
, (char *) sp
, sizeof (*event
));
2990 sp
->code
= event
->code
;
2991 sp
->part
= event
->part
;
2992 sp
->frame_or_window
= event
->frame_or_window
;
2993 sp
->modifiers
= event
->modifiers
;
2996 sp
->timestamp
= event
->timestamp
;
2998 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_store_ptr
3000 = event
->frame_or_window
);
3006 /* Discard any mouse events in the event buffer by setting them to
3009 discard_mouse_events ()
3011 struct input_event
*sp
;
3012 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
3014 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3017 if (sp
->kind
== mouse_click
3019 || sp
->kind
== w32_scroll_bar_click
3021 || sp
->kind
== scroll_bar_click
)
3023 sp
->kind
= no_event
;
3028 /* Read one event from the event buffer, waiting if necessary.
3029 The value is a Lisp object representing the event.
3030 The value is nil for an event that should be ignored,
3031 or that was handled here.
3032 We always read and discard one event. */
3035 kbd_buffer_get_event (kbp
, used_mouse_menu
)
3037 int *used_mouse_menu
;
3046 *kbp
= current_kboard
;
3050 /* Wait until there is input available. */
3053 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3056 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
3060 /* If the quit flag is set, then read_char will return
3061 quit_char, so that counts as "available input." */
3062 if (!NILP (Vquit_flag
))
3063 quit_throw_to_read_char ();
3065 /* One way or another, wait until input is available; then, if
3066 interrupt handlers have not read it, read it now. */
3069 wait_for_kbd_input ();
3071 /* Note SIGIO has been undef'd if FIONREAD is missing. */
3075 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3078 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
3082 Lisp_Object minus_one
;
3084 XSETINT (minus_one
, -1);
3085 wait_reading_process_input (0, 0, minus_one
, 1);
3087 if (!interrupt_input
&& kbd_fetch_ptr
== kbd_store_ptr
)
3088 /* Pass 1 for EXPECT since we just waited to have input. */
3089 read_avail_input (1);
3091 #endif /* not VMS */
3094 if (CONSP (Vunread_command_events
))
3097 first
= XCAR (Vunread_command_events
);
3098 Vunread_command_events
= XCDR (Vunread_command_events
);
3099 *kbp
= current_kboard
;
3103 /* At this point, we know that there is a readable event available
3104 somewhere. If the event queue is empty, then there must be a
3105 mouse movement enabled and available. */
3106 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3108 struct input_event
*event
;
3110 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
3114 last_event_timestamp
= event
->timestamp
;
3117 *kbp
= event_to_kboard (event
);
3119 *kbp
= current_kboard
; /* Better than returning null ptr? */
3121 *kbp
= &the_only_kboard
;
3126 /* These two kinds of events get special handling
3127 and don't actually appear to the command loop.
3128 We return nil for them. */
3129 if (event
->kind
== selection_request_event
)
3132 struct input_event copy
;
3134 /* Remove it from the buffer before processing it,
3135 since otherwise swallow_events will see it
3136 and process it again. */
3138 kbd_fetch_ptr
= event
+ 1;
3139 input_pending
= readable_events (0);
3140 x_handle_selection_request (©
);
3142 /* We're getting selection request events, but we don't have
3148 else if (event
->kind
== selection_clear_event
)
3151 struct input_event copy
;
3153 /* Remove it from the buffer before processing it. */
3155 kbd_fetch_ptr
= event
+ 1;
3156 input_pending
= readable_events (0);
3157 x_handle_selection_clear (©
);
3159 /* We're getting selection request events, but we don't have
3164 #if defined (HAVE_X11) || defined (HAVE_NTGUI)
3165 else if (event
->kind
== delete_window_event
)
3167 /* Make an event (delete-frame (FRAME)). */
3168 obj
= Fcons (event
->frame_or_window
, Qnil
);
3169 obj
= Fcons (Qdelete_frame
, Fcons (obj
, Qnil
));
3170 kbd_fetch_ptr
= event
+ 1;
3172 else if (event
->kind
== iconify_event
)
3174 /* Make an event (iconify-frame (FRAME)). */
3175 obj
= Fcons (event
->frame_or_window
, Qnil
);
3176 obj
= Fcons (Qiconify_frame
, Fcons (obj
, Qnil
));
3177 kbd_fetch_ptr
= event
+ 1;
3179 else if (event
->kind
== deiconify_event
)
3181 /* Make an event (make-frame-visible (FRAME)). */
3182 obj
= Fcons (event
->frame_or_window
, Qnil
);
3183 obj
= Fcons (Qmake_frame_visible
, Fcons (obj
, Qnil
));
3184 kbd_fetch_ptr
= event
+ 1;
3187 else if (event
->kind
== buffer_switch_event
)
3189 /* The value doesn't matter here; only the type is tested. */
3190 XSETBUFFER (obj
, current_buffer
);
3191 kbd_fetch_ptr
= event
+ 1;
3193 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
3194 else if (event
->kind
== menu_bar_activate_event
)
3196 kbd_fetch_ptr
= event
+ 1;
3197 input_pending
= readable_events (0);
3198 if (FRAME_LIVE_P (XFRAME (event
->frame_or_window
)))
3199 x_activate_menubar (XFRAME (event
->frame_or_window
));
3203 else if (event
->kind
== language_change_event
)
3205 /* Make an event (language-change (FRAME CHARSET LCID)). */
3206 obj
= Fcons (event
->modifiers
, Qnil
);
3207 obj
= Fcons (event
->code
, Qnil
);
3208 obj
= Fcons (event
->frame_or_window
, obj
);
3209 obj
= Fcons (Qlanguage_change
, Fcons (obj
, Qnil
));
3210 kbd_fetch_ptr
= event
+ 1;
3213 /* Just discard these, by returning nil.
3214 With MULTI_KBOARD, these events are used as placeholders
3215 when we need to randomly delete events from the queue.
3216 (They shouldn't otherwise be found in the buffer,
3217 but on some machines it appears they do show up
3218 even without MULTI_KBOARD.) */
3219 /* On Windows NT/9X, no_event is used to delete extraneous
3220 mouse events during a popup-menu call. */
3221 else if (event
->kind
== no_event
)
3222 kbd_fetch_ptr
= event
+ 1;
3223 else if (event
->kind
== HELP_EVENT
)
3225 /* The car of event->frame_or_window is a frame,
3226 the cdr is the help to display. */
3227 obj
= Fcons (Qhelp_echo
, event
->frame_or_window
);
3228 kbd_fetch_ptr
= event
+ 1;
3230 /* If this event is on a different frame, return a switch-frame this
3231 time, and leave the event in the queue for next time. */
3237 frame
= event
->frame_or_window
;
3239 frame
= XCAR (frame
);
3240 else if (WINDOWP (frame
))
3241 frame
= WINDOW_FRAME (XWINDOW (frame
));
3243 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
3247 if (! EQ (frame
, internal_last_event_frame
)
3248 && !EQ (frame
, selected_frame
))
3249 obj
= make_lispy_switch_frame (frame
);
3250 internal_last_event_frame
= frame
;
3252 /* If we didn't decide to make a switch-frame event, go ahead
3253 and build a real event from the queue entry. */
3257 obj
= make_lispy_event (event
);
3258 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
3259 /* If this was a menu selection, then set the flag to inhibit
3260 writing to last_nonmenu_event. Don't do this if the event
3261 we're returning is (menu-bar), though; that indicates the
3262 beginning of the menu sequence, and we might as well leave
3263 that as the `event with parameters' for this selection. */
3264 if ((event
->kind
== menu_bar_event
3265 || event
->kind
== TOOL_BAR_EVENT
)
3266 && !(CONSP (obj
) && EQ (XCAR (obj
), Qmenu_bar
))
3267 && !(CONSP (obj
) && EQ (XCAR (obj
), Qtool_bar
))
3269 *used_mouse_menu
= 1;
3272 /* Wipe out this event, to catch bugs. */
3273 event
->kind
= no_event
;
3274 XVECTOR (kbd_buffer_frame_or_window
)->contents
[event
- kbd_buffer
] = Qnil
;
3276 kbd_fetch_ptr
= event
+ 1;
3281 /* Try generating a mouse motion event. */
3282 else if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
3284 FRAME_PTR f
= some_mouse_moved ();
3285 Lisp_Object bar_window
;
3286 enum scroll_bar_part part
;
3290 *kbp
= current_kboard
;
3291 /* Note that this uses F to determine which display to look at.
3292 If there is no valid info, it does not store anything
3293 so x remains nil. */
3295 (*mouse_position_hook
) (&f
, 0, &bar_window
, &part
, &x
, &y
, &time
);
3299 /* Decide if we should generate a switch-frame event. Don't
3300 generate switch-frame events for motion outside of all Emacs
3306 frame
= FRAME_FOCUS_FRAME (f
);
3308 XSETFRAME (frame
, f
);
3310 if (! EQ (frame
, internal_last_event_frame
)
3311 && !EQ (frame
, selected_frame
))
3312 obj
= make_lispy_switch_frame (frame
);
3313 internal_last_event_frame
= frame
;
3316 /* If we didn't decide to make a switch-frame event, go ahead and
3317 return a mouse-motion event. */
3318 if (!NILP (x
) && NILP (obj
))
3319 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
3321 #endif /* HAVE_MOUSE */
3323 /* We were promised by the above while loop that there was
3324 something for us to read! */
3327 input_pending
= readable_events (0);
3329 Vlast_event_frame
= internal_last_event_frame
;
3334 /* Process any events that are not user-visible,
3335 then return, without reading any user-visible events. */
3338 swallow_events (do_display
)
3343 while (kbd_fetch_ptr
!= kbd_store_ptr
)
3345 struct input_event
*event
;
3347 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
3351 last_event_timestamp
= event
->timestamp
;
3353 /* These two kinds of events get special handling
3354 and don't actually appear to the command loop. */
3355 if (event
->kind
== selection_request_event
)
3358 struct input_event copy
;
3360 /* Remove it from the buffer before processing it,
3361 since otherwise swallow_events called recursively could see it
3362 and process it again. */
3364 kbd_fetch_ptr
= event
+ 1;
3365 input_pending
= readable_events (0);
3366 x_handle_selection_request (©
);
3368 /* We're getting selection request events, but we don't have
3374 else if (event
->kind
== selection_clear_event
)
3377 struct input_event copy
;
3379 /* Remove it from the buffer before processing it, */
3382 kbd_fetch_ptr
= event
+ 1;
3383 input_pending
= readable_events (0);
3384 x_handle_selection_clear (©
);
3386 /* We're getting selection request events, but we don't have
3395 old_timers_run
= timers_run
;
3396 get_input_pending (&input_pending
, 1);
3398 if (timers_run
!= old_timers_run
&& do_display
)
3399 redisplay_preserve_echo_area ();
3402 static EMACS_TIME timer_idleness_start_time
;
3404 /* Record the start of when Emacs is idle,
3405 for the sake of running idle-time timers. */
3412 /* If we are already in the idle state, do nothing. */
3413 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3416 EMACS_GET_TIME (timer_idleness_start_time
);
3418 /* Mark all idle-time timers as once again candidates for running. */
3419 for (timers
= Vtimer_idle_list
; CONSP (timers
); timers
= XCDR (timers
))
3423 timer
= XCAR (timers
);
3425 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3427 XVECTOR (timer
)->contents
[0] = Qnil
;
3431 /* Record that Emacs is no longer idle, so stop running idle-time timers. */
3436 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
3439 /* This is only for debugging. */
3440 struct input_event last_timer_event
;
3442 /* Check whether a timer has fired. To prevent larger problems we simply
3443 disregard elements that are not proper timers. Do not make a circular
3444 timer list for the time being.
3446 Returns the number of seconds to wait until the next timer fires. If a
3447 timer is triggering now, return zero seconds.
3448 If no timer is active, return -1 seconds.
3450 If a timer is ripe, we run it, with quitting turned off.
3452 DO_IT_NOW is now ignored. It used to mean that we should
3453 run the timer directly instead of queueing a timer-event.
3454 Now we always run timers directly. */
3457 timer_check (do_it_now
)
3460 EMACS_TIME nexttime
;
3461 EMACS_TIME now
, idleness_now
;
3462 Lisp_Object timers
, idle_timers
, chosen_timer
;
3463 struct gcpro gcpro1
, gcpro2
, gcpro3
;
3465 EMACS_SET_SECS (nexttime
, -1);
3466 EMACS_SET_USECS (nexttime
, -1);
3468 /* Always consider the ordinary timers. */
3469 timers
= Vtimer_list
;
3470 /* Consider the idle timers only if Emacs is idle. */
3471 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3472 idle_timers
= Vtimer_idle_list
;
3475 chosen_timer
= Qnil
;
3476 GCPRO3 (timers
, idle_timers
, chosen_timer
);
3478 if (CONSP (timers
) || CONSP (idle_timers
))
3480 EMACS_GET_TIME (now
);
3481 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3482 EMACS_SUB_TIME (idleness_now
, now
, timer_idleness_start_time
);
3485 while (CONSP (timers
) || CONSP (idle_timers
))
3487 Lisp_Object
*vector
;
3488 Lisp_Object timer
, idle_timer
;
3489 EMACS_TIME timer_time
, idle_timer_time
;
3490 EMACS_TIME difference
, timer_difference
, idle_timer_difference
;
3492 /* Skip past invalid timers and timers already handled. */
3495 timer
= XCAR (timers
);
3496 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3498 timers
= XCDR (timers
);
3501 vector
= XVECTOR (timer
)->contents
;
3503 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
3504 || !INTEGERP (vector
[3])
3505 || ! NILP (vector
[0]))
3507 timers
= XCDR (timers
);
3511 if (!NILP (idle_timers
))
3513 timer
= XCAR (idle_timers
);
3514 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3516 idle_timers
= XCDR (idle_timers
);
3519 vector
= XVECTOR (timer
)->contents
;
3521 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
3522 || !INTEGERP (vector
[3])
3523 || ! NILP (vector
[0]))
3525 idle_timers
= XCDR (idle_timers
);
3530 /* Set TIMER, TIMER_TIME and TIMER_DIFFERENCE
3531 based on the next ordinary timer.
3532 TIMER_DIFFERENCE is the distance in time from NOW to when
3533 this timer becomes ripe (negative if it's already ripe). */
3536 timer
= XCAR (timers
);
3537 vector
= XVECTOR (timer
)->contents
;
3538 EMACS_SET_SECS (timer_time
,
3539 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
3540 EMACS_SET_USECS (timer_time
, XINT (vector
[3]));
3541 EMACS_SUB_TIME (timer_difference
, timer_time
, now
);
3544 /* Set IDLE_TIMER, IDLE_TIMER_TIME and IDLE_TIMER_DIFFERENCE
3545 based on the next idle timer. */
3546 if (!NILP (idle_timers
))
3548 idle_timer
= XCAR (idle_timers
);
3549 vector
= XVECTOR (idle_timer
)->contents
;
3550 EMACS_SET_SECS (idle_timer_time
,
3551 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
3552 EMACS_SET_USECS (idle_timer_time
, XINT (vector
[3]));
3553 EMACS_SUB_TIME (idle_timer_difference
, idle_timer_time
, idleness_now
);
3556 /* Decide which timer is the next timer,
3557 and set CHOSEN_TIMER, VECTOR and DIFFERENCE accordingly.
3558 Also step down the list where we found that timer. */
3560 if (! NILP (timers
) && ! NILP (idle_timers
))
3563 EMACS_SUB_TIME (temp
, timer_difference
, idle_timer_difference
);
3564 if (EMACS_TIME_NEG_P (temp
))
3566 chosen_timer
= timer
;
3567 timers
= XCDR (timers
);
3568 difference
= timer_difference
;
3572 chosen_timer
= idle_timer
;
3573 idle_timers
= XCDR (idle_timers
);
3574 difference
= idle_timer_difference
;
3577 else if (! NILP (timers
))
3579 chosen_timer
= timer
;
3580 timers
= XCDR (timers
);
3581 difference
= timer_difference
;
3585 chosen_timer
= idle_timer
;
3586 idle_timers
= XCDR (idle_timers
);
3587 difference
= idle_timer_difference
;
3589 vector
= XVECTOR (chosen_timer
)->contents
;
3591 /* If timer is rupe, run it if it hasn't been run. */
3592 if (EMACS_TIME_NEG_P (difference
)
3593 || (EMACS_SECS (difference
) == 0
3594 && EMACS_USECS (difference
) == 0))
3596 if (NILP (vector
[0]))
3598 int was_locked
= single_kboard
;
3599 int count
= specpdl_ptr
- specpdl
;
3600 #ifdef HAVE_WINDOW_SYSTEM
3601 int old_inhibit_busy_cursor
= inhibit_busy_cursor
;
3604 /* Mark the timer as triggered to prevent problems if the lisp
3605 code fails to reschedule it right. */
3608 specbind (Qinhibit_quit
, Qt
);
3610 #ifdef HAVE_WINDOW_SYSTEM
3611 inhibit_busy_cursor
= 2;
3614 call1 (Qtimer_event_handler
, chosen_timer
);
3617 #ifdef HAVE_WINDOW_SYSTEM
3618 inhibit_busy_cursor
= old_inhibit_busy_cursor
;
3621 unbind_to (count
, Qnil
);
3623 /* Resume allowing input from any kboard, if that was true before. */
3625 any_kboard_state ();
3627 /* Since we have handled the event,
3628 we don't need to tell the caller to wake up and do it. */
3632 /* When we encounter a timer that is still waiting,
3633 return the amount of time to wait before it is ripe. */
3640 /* No timers are pending in the future. */
3641 /* Return 0 if we generated an event, and -1 if not. */
3646 /* Caches for modify_event_symbol. */
3647 static Lisp_Object accent_key_syms
;
3648 static Lisp_Object func_key_syms
;
3649 static Lisp_Object mouse_syms
;
3651 static Lisp_Object mouse_wheel_syms
;
3653 static Lisp_Object drag_n_drop_syms
;
3655 /* This is a list of keysym codes for special "accent" characters.
3656 It parallels lispy_accent_keys. */
3658 static int lispy_accent_codes
[] =
3660 #ifdef XK_dead_circumflex
3665 #ifdef XK_dead_grave
3670 #ifdef XK_dead_tilde
3675 #ifdef XK_dead_diaeresis
3680 #ifdef XK_dead_macron
3685 #ifdef XK_dead_degree
3690 #ifdef XK_dead_acute
3695 #ifdef XK_dead_cedilla
3700 #ifdef XK_dead_breve
3705 #ifdef XK_dead_ogonek
3710 #ifdef XK_dead_caron
3715 #ifdef XK_dead_doubleacute
3716 XK_dead_doubleacute
,
3720 #ifdef XK_dead_abovedot
3727 /* This is a list of Lisp names for special "accent" characters.
3728 It parallels lispy_accent_codes. */
3730 static char *lispy_accent_keys
[] =
3748 #define FUNCTION_KEY_OFFSET 0x0
3750 char *lispy_function_keys
[] =
3754 0, /* VK_LBUTTON 0x01 */
3755 0, /* VK_RBUTTON 0x02 */
3756 "cancel", /* VK_CANCEL 0x03 */
3757 0, /* VK_MBUTTON 0x04 */
3759 0, 0, 0, /* 0x05 .. 0x07 */
3761 "backspace", /* VK_BACK 0x08 */
3762 "tab", /* VK_TAB 0x09 */
3764 0, 0, /* 0x0A .. 0x0B */
3766 "clear", /* VK_CLEAR 0x0C */
3767 "return", /* VK_RETURN 0x0D */
3769 0, 0, /* 0x0E .. 0x0F */
3771 0, /* VK_SHIFT 0x10 */
3772 0, /* VK_CONTROL 0x11 */
3773 0, /* VK_MENU 0x12 */
3774 "pause", /* VK_PAUSE 0x13 */
3775 "capslock", /* VK_CAPITAL 0x14 */
3777 0, 0, 0, 0, 0, 0, /* 0x15 .. 0x1A */
3779 "escape", /* VK_ESCAPE 0x1B */
3781 0, 0, 0, 0, /* 0x1C .. 0x1F */
3783 0, /* VK_SPACE 0x20 */
3784 "prior", /* VK_PRIOR 0x21 */
3785 "next", /* VK_NEXT 0x22 */
3786 "end", /* VK_END 0x23 */
3787 "home", /* VK_HOME 0x24 */
3788 "left", /* VK_LEFT 0x25 */
3789 "up", /* VK_UP 0x26 */
3790 "right", /* VK_RIGHT 0x27 */
3791 "down", /* VK_DOWN 0x28 */
3792 "select", /* VK_SELECT 0x29 */
3793 "print", /* VK_PRINT 0x2A */
3794 "execute", /* VK_EXECUTE 0x2B */
3795 "snapshot", /* VK_SNAPSHOT 0x2C */
3796 "insert", /* VK_INSERT 0x2D */
3797 "delete", /* VK_DELETE 0x2E */
3798 "help", /* VK_HELP 0x2F */
3800 /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
3802 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3804 0, 0, 0, 0, 0, 0, 0, /* 0x3A .. 0x40 */
3806 /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
3808 0, 0, 0, 0, 0, 0, 0, 0, 0,
3809 0, 0, 0, 0, 0, 0, 0, 0, 0,
3810 0, 0, 0, 0, 0, 0, 0, 0,
3812 "lwindow", /* VK_LWIN 0x5B */
3813 "rwindow", /* VK_RWIN 0x5C */
3814 "apps", /* VK_APPS 0x5D */
3816 0, 0, /* 0x5E .. 0x5F */
3818 "kp-0", /* VK_NUMPAD0 0x60 */
3819 "kp-1", /* VK_NUMPAD1 0x61 */
3820 "kp-2", /* VK_NUMPAD2 0x62 */
3821 "kp-3", /* VK_NUMPAD3 0x63 */
3822 "kp-4", /* VK_NUMPAD4 0x64 */
3823 "kp-5", /* VK_NUMPAD5 0x65 */
3824 "kp-6", /* VK_NUMPAD6 0x66 */
3825 "kp-7", /* VK_NUMPAD7 0x67 */
3826 "kp-8", /* VK_NUMPAD8 0x68 */
3827 "kp-9", /* VK_NUMPAD9 0x69 */
3828 "kp-multiply", /* VK_MULTIPLY 0x6A */
3829 "kp-add", /* VK_ADD 0x6B */
3830 "kp-separator", /* VK_SEPARATOR 0x6C */
3831 "kp-subtract", /* VK_SUBTRACT 0x6D */
3832 "kp-decimal", /* VK_DECIMAL 0x6E */
3833 "kp-divide", /* VK_DIVIDE 0x6F */
3834 "f1", /* VK_F1 0x70 */
3835 "f2", /* VK_F2 0x71 */
3836 "f3", /* VK_F3 0x72 */
3837 "f4", /* VK_F4 0x73 */
3838 "f5", /* VK_F5 0x74 */
3839 "f6", /* VK_F6 0x75 */
3840 "f7", /* VK_F7 0x76 */
3841 "f8", /* VK_F8 0x77 */
3842 "f9", /* VK_F9 0x78 */
3843 "f10", /* VK_F10 0x79 */
3844 "f11", /* VK_F11 0x7A */
3845 "f12", /* VK_F12 0x7B */
3846 "f13", /* VK_F13 0x7C */
3847 "f14", /* VK_F14 0x7D */
3848 "f15", /* VK_F15 0x7E */
3849 "f16", /* VK_F16 0x7F */
3850 "f17", /* VK_F17 0x80 */
3851 "f18", /* VK_F18 0x81 */
3852 "f19", /* VK_F19 0x82 */
3853 "f20", /* VK_F20 0x83 */
3854 "f21", /* VK_F21 0x84 */
3855 "f22", /* VK_F22 0x85 */
3856 "f23", /* VK_F23 0x86 */
3857 "f24", /* VK_F24 0x87 */
3859 0, 0, 0, 0, /* 0x88 .. 0x8B */
3860 0, 0, 0, 0, /* 0x8C .. 0x8F */
3862 "kp-numlock", /* VK_NUMLOCK 0x90 */
3863 "scroll", /* VK_SCROLL 0x91 */
3865 "kp-space", /* VK_NUMPAD_CLEAR 0x92 */
3866 "kp-enter", /* VK_NUMPAD_ENTER 0x93 */
3867 "kp-prior", /* VK_NUMPAD_PRIOR 0x94 */
3868 "kp-next", /* VK_NUMPAD_NEXT 0x95 */
3869 "kp-end", /* VK_NUMPAD_END 0x96 */
3870 "kp-home", /* VK_NUMPAD_HOME 0x97 */
3871 "kp-left", /* VK_NUMPAD_LEFT 0x98 */
3872 "kp-up", /* VK_NUMPAD_UP 0x99 */
3873 "kp-right", /* VK_NUMPAD_RIGHT 0x9A */
3874 "kp-down", /* VK_NUMPAD_DOWN 0x9B */
3875 "kp-insert", /* VK_NUMPAD_INSERT 0x9C */
3876 "kp-delete", /* VK_NUMPAD_DELETE 0x9D */
3878 0, 0, /* 0x9E .. 0x9F */
3881 * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
3882 * Used only as parameters to GetAsyncKeyState and GetKeyState.
3883 * No other API or message will distinguish left and right keys this way.
3887 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3888 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3889 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3890 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3891 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3897 "attn", /* VK_ATTN 0xF6 */
3898 "crsel", /* VK_CRSEL 0xF7 */
3899 "exsel", /* VK_EXSEL 0xF8 */
3900 "ereof", /* VK_EREOF 0xF9 */
3901 "play", /* VK_PLAY 0xFA */
3902 "zoom", /* VK_ZOOM 0xFB */
3903 "noname", /* VK_NONAME 0xFC */
3904 "pa1", /* VK_PA1 0xFD */
3905 "oem_clear", /* VK_OEM_CLEAR 0xFE */
3909 #else /* not HAVE_NTGUI */
3912 static char *lispy_kana_keys
[] =
3914 /* X Keysym value */
3915 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x400 .. 0x40f */
3916 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x410 .. 0x41f */
3917 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x420 .. 0x42f */
3918 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x430 .. 0x43f */
3919 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x440 .. 0x44f */
3920 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x450 .. 0x45f */
3921 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x460 .. 0x46f */
3922 0,0,0,0,0,0,0,0,0,0,0,0,0,0,"overline",0,
3923 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x480 .. 0x48f */
3924 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x490 .. 0x49f */
3925 0, "kana-fullstop", "kana-openingbracket", "kana-closingbracket",
3926 "kana-comma", "kana-conjunctive", "kana-WO", "kana-a",
3927 "kana-i", "kana-u", "kana-e", "kana-o",
3928 "kana-ya", "kana-yu", "kana-yo", "kana-tsu",
3929 "prolongedsound", "kana-A", "kana-I", "kana-U",
3930 "kana-E", "kana-O", "kana-KA", "kana-KI",
3931 "kana-KU", "kana-KE", "kana-KO", "kana-SA",
3932 "kana-SHI", "kana-SU", "kana-SE", "kana-SO",
3933 "kana-TA", "kana-CHI", "kana-TSU", "kana-TE",
3934 "kana-TO", "kana-NA", "kana-NI", "kana-NU",
3935 "kana-NE", "kana-NO", "kana-HA", "kana-HI",
3936 "kana-FU", "kana-HE", "kana-HO", "kana-MA",
3937 "kana-MI", "kana-MU", "kana-ME", "kana-MO",
3938 "kana-YA", "kana-YU", "kana-YO", "kana-RA",
3939 "kana-RI", "kana-RU", "kana-RE", "kana-RO",
3940 "kana-WA", "kana-N", "voicedsound", "semivoicedsound",
3941 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4e0 .. 0x4ef */
3942 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4f0 .. 0x4ff */
3944 #endif /* XK_kana_A */
3946 #define FUNCTION_KEY_OFFSET 0xff00
3948 /* You'll notice that this table is arranged to be conveniently
3949 indexed by X Windows keysym values. */
3950 static char *lispy_function_keys
[] =
3952 /* X Keysym value */
3954 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00...0f */
3955 "backspace", "tab", "linefeed", "clear",
3957 0, 0, 0, "pause", /* 0xff10...1f */
3958 0, 0, 0, 0, 0, 0, 0, "escape",
3960 0, "kanji", "muhenkan", "henkan", /* 0xff20...2f */
3961 "romaji", "hiragana", "katakana", "hiragana-katakana",
3962 "zenkaku", "hankaku", "zenkaku-hankaku", "touroku",
3963 "massyo", "kana-lock", "kana-shift", "eisu-shift",
3964 "eisu-toggle", /* 0xff30...3f */
3965 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3966 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
3968 "home", "left", "up", "right", /* 0xff50 */ /* IsCursorKey */
3969 "down", "prior", "next", "end",
3970 "begin", 0, 0, 0, 0, 0, 0, 0,
3971 "select", /* 0xff60 */ /* IsMiscFunctionKey */
3982 "break", /* 0xff6b */
3985 0, 0, 0, 0, "backtab", 0, 0, 0, /* 0xff70... */
3986 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff78... */
3987 "kp-space", /* 0xff80 */ /* IsKeypadKey */
3988 0, 0, 0, 0, 0, 0, 0, 0,
3989 "kp-tab", /* 0xff89 */
3991 "kp-enter", /* 0xff8d */
3993 "kp-f1", /* 0xff91 */
3997 "kp-home", /* 0xff95 */
4002 "kp-prior", /* kp-page-up */
4003 "kp-next", /* kp-page-down */
4009 0, 0, 0, 0, 0, 0, 0, 0, 0,
4010 "kp-multiply", /* 0xffaa */
4015 "kp-divide", /* 0xffaf */
4016 "kp-0", /* 0xffb0 */
4017 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
4020 "kp-equal", /* 0xffbd */
4021 "f1", /* 0xffbe */ /* IsFunctionKey */
4023 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
4024 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
4025 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
4026 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
4027 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
4028 0, 0, 0, 0, 0, 0, 0, 0,
4029 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
4030 0, 0, 0, 0, 0, 0, 0, "delete"
4033 /* ISO 9995 Function and Modifier Keys; the first byte is 0xFE. */
4034 #define ISO_FUNCTION_KEY_OFFSET 0xfe00
4036 static char *iso_lispy_function_keys
[] =
4038 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe00 */
4039 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe08 */
4040 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe10 */
4041 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe18 */
4042 "iso-lefttab", /* 0xfe20 */
4043 "iso-move-line-up", "iso-move-line-down",
4044 "iso-partial-line-up", "iso-partial-line-down",
4045 "iso-partial-space-left", "iso-partial-space-right",
4046 "iso-set-margin-left", "iso-set-margin-right", /* 0xffe27, 28 */
4047 "iso-release-margin-left", "iso-release-margin-right",
4048 "iso-release-both-margins",
4049 "iso-fast-cursor-left", "iso-fast-cursor-right",
4050 "iso-fast-cursor-up", "iso-fast-cursor-down",
4051 "iso-continuous-underline", "iso-discontinuous-underline", /* 0xfe30, 31 */
4052 "iso-emphasize", "iso-center-object", "iso-enter", /* ... 0xfe34 */
4055 #endif /* not HAVE_NTGUI */
4057 static char *lispy_mouse_names
[] =
4059 "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5"
4063 /* mouse-wheel events are generated by the wheel on devices such as
4064 the MS Intellimouse. The wheel sits in between the left and right
4065 mouse buttons, and is typically used to scroll or zoom the window
4066 underneath the pointer. mouse-wheel events specify the object on
4067 which they operate, and a delta corresponding to the amount and
4068 direction that the wheel is rotated. Clicking the mouse-wheel
4069 generates a mouse-2 event. */
4070 static char *lispy_mouse_wheel_names
[] =
4075 #endif /* WINDOWSNT */
4077 /* drag-n-drop events are generated when a set of selected files are
4078 dragged from another application and dropped onto an Emacs window. */
4079 static char *lispy_drag_n_drop_names
[] =
4084 /* Scroll bar parts. */
4085 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
4086 Lisp_Object Qup
, Qdown
, Qbottom
, Qend_scroll
;
4087 Lisp_Object Qtop
, Qratio
;
4089 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
4090 Lisp_Object
*scroll_bar_parts
[] = {
4091 &Qabove_handle
, &Qhandle
, &Qbelow_handle
,
4092 &Qup
, &Qdown
, &Qtop
, &Qbottom
, &Qend_scroll
, &Qratio
4095 /* User signal events. */
4096 Lisp_Object Qusr1_signal
, Qusr2_signal
;
4098 Lisp_Object
*lispy_user_signals
[] =
4100 &Qusr1_signal
, &Qusr2_signal
4104 /* A vector, indexed by button number, giving the down-going location
4105 of currently depressed buttons, both scroll bar and non-scroll bar.
4107 The elements have the form
4108 (BUTTON-NUMBER MODIFIER-MASK . REST)
4109 where REST is the cdr of a position as it would be reported in the event.
4111 The make_lispy_event function stores positions here to tell the
4112 difference between click and drag events, and to store the starting
4113 location to be included in drag events. */
4115 static Lisp_Object button_down_location
;
4117 /* Information about the most recent up-going button event: Which
4118 button, what location, and what time. */
4120 static int last_mouse_button
;
4121 static int last_mouse_x
;
4122 static int last_mouse_y
;
4123 static unsigned long button_down_time
;
4125 /* The maximum time between clicks to make a double-click,
4126 or Qnil to disable double-click detection,
4127 or Qt for no time limit. */
4128 Lisp_Object Vdouble_click_time
;
4130 /* The number of clicks in this multiple-click. */
4132 int double_click_count
;
4134 /* Given a struct input_event, build the lisp event which represents
4135 it. If EVENT is 0, build a mouse movement event from the mouse
4136 movement buffer, which should have a movement event in it.
4138 Note that events must be passed to this function in the order they
4139 are received; this function stores the location of button presses
4140 in order to build drag events when the button is released. */
4143 make_lispy_event (event
)
4144 struct input_event
*event
;
4148 switch (SWITCH_ENUM_CAST (event
->kind
))
4150 /* A simple keystroke. */
4151 case ascii_keystroke
:
4153 Lisp_Object lispy_c
;
4154 int c
= event
->code
& 0377;
4155 /* Turn ASCII characters into control characters
4157 if (event
->modifiers
& ctrl_modifier
)
4158 c
= make_ctrl_char (c
);
4160 /* Add in the other modifier bits. We took care of ctrl_modifier
4161 just above, and the shift key was taken care of by the X code,
4162 and applied to control characters by make_ctrl_char. */
4163 c
|= (event
->modifiers
4164 & (meta_modifier
| alt_modifier
4165 | hyper_modifier
| super_modifier
));
4166 /* Distinguish Shift-SPC from SPC. */
4167 if ((event
->code
& 0377) == 040
4168 && event
->modifiers
& shift_modifier
)
4169 c
|= shift_modifier
;
4170 button_down_time
= 0;
4171 XSETFASTINT (lispy_c
, c
);
4175 /* A function key. The symbol may need to have modifier prefixes
4177 case non_ascii_keystroke
:
4178 button_down_time
= 0;
4180 for (i
= 0; i
< sizeof (lispy_accent_codes
) / sizeof (int); i
++)
4181 if (event
->code
== lispy_accent_codes
[i
])
4182 return modify_event_symbol (i
,
4184 Qfunction_key
, Qnil
,
4185 lispy_accent_keys
, &accent_key_syms
,
4186 (sizeof (lispy_accent_keys
)
4187 / sizeof (lispy_accent_keys
[0])));
4189 /* Handle system-specific keysyms. */
4190 if (event
->code
& (1 << 28))
4192 /* We need to use an alist rather than a vector as the cache
4193 since we can't make a vector long enuf. */
4194 if (NILP (current_kboard
->system_key_syms
))
4195 current_kboard
->system_key_syms
= Fcons (Qnil
, Qnil
);
4196 return modify_event_symbol (event
->code
,
4199 current_kboard
->Vsystem_key_alist
,
4200 0, ¤t_kboard
->system_key_syms
,
4205 if (event
->code
>= 0x400 && event
->code
< 0x500)
4206 return modify_event_symbol (event
->code
- 0x400,
4207 event
->modifiers
& ~shift_modifier
,
4208 Qfunction_key
, Qnil
,
4209 lispy_kana_keys
, &func_key_syms
,
4210 (sizeof (lispy_kana_keys
)
4211 / sizeof (lispy_kana_keys
[0])));
4212 #endif /* XK_kana_A */
4214 #ifdef ISO_FUNCTION_KEY_OFFSET
4215 if (event
->code
< FUNCTION_KEY_OFFSET
4216 && event
->code
>= ISO_FUNCTION_KEY_OFFSET
)
4217 return modify_event_symbol (event
->code
- ISO_FUNCTION_KEY_OFFSET
,
4219 Qfunction_key
, Qnil
,
4220 iso_lispy_function_keys
, &func_key_syms
,
4221 (sizeof (iso_lispy_function_keys
)
4222 / sizeof (iso_lispy_function_keys
[0])));
4225 return modify_event_symbol (event
->code
- FUNCTION_KEY_OFFSET
,
4227 Qfunction_key
, Qnil
,
4228 lispy_function_keys
, &func_key_syms
,
4229 (sizeof (lispy_function_keys
)
4230 / sizeof (lispy_function_keys
[0])));
4233 /* A mouse click. Figure out where it is, decide whether it's
4234 a press, click or drag, and build the appropriate structure. */
4236 #ifndef USE_TOOLKIT_SCROLL_BARS
4237 case scroll_bar_click
:
4240 int button
= event
->code
;
4242 Lisp_Object position
;
4243 Lisp_Object
*start_pos_ptr
;
4244 Lisp_Object start_pos
;
4246 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
4249 /* Build the position as appropriate for this mouse click. */
4250 if (event
->kind
== mouse_click
)
4253 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
4256 Lisp_Object string_info
= Qnil
;
4259 /* Ignore mouse events that were made on frame that
4260 have been deleted. */
4261 if (! FRAME_LIVE_P (f
))
4264 /* EVENT->x and EVENT->y are frame-relative pixel
4265 coordinates at this place. Under old redisplay, COLUMN
4266 and ROW are set to frame relative glyph coordinates
4267 which are then used to determine whether this click is
4268 in a menu (non-toolkit version). */
4269 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4270 &column
, &row
, NULL
, 1);
4272 #ifndef USE_X_TOOLKIT
4273 /* In the non-toolkit version, clicks on the menu bar
4274 are ordinary button events in the event buffer.
4275 Distinguish them, and invoke the menu.
4277 (In the toolkit version, the toolkit handles the menu bar
4278 and Emacs doesn't know about it until after the user
4279 makes a selection.) */
4280 if (row
>= 0 && row
< FRAME_MENU_BAR_LINES (f
)
4281 && (event
->modifiers
& down_modifier
))
4283 Lisp_Object items
, item
;
4288 /* Activate the menu bar on the down event. If the
4289 up event comes in before the menu code can deal with it,
4291 if (! (event
->modifiers
& down_modifier
))
4295 /* Find the menu bar item under `column'. */
4297 items
= FRAME_MENU_BAR_ITEMS (f
);
4298 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
4300 Lisp_Object pos
, string
;
4301 string
= XVECTOR (items
)->contents
[i
+ 1];
4302 pos
= XVECTOR (items
)->contents
[i
+ 3];
4305 if (column
>= XINT (pos
)
4306 && column
< XINT (pos
) + XSTRING (string
)->size
)
4308 item
= XVECTOR (items
)->contents
[i
];
4313 /* ELisp manual 2.4b says (x y) are window relative but
4314 code says they are frame-relative. */
4316 = Fcons (event
->frame_or_window
,
4318 Fcons (Fcons (event
->x
, event
->y
),
4319 Fcons (make_number (event
->timestamp
),
4322 return Fcons (item
, Fcons (position
, Qnil
));
4324 #endif /* not USE_X_TOOLKIT */
4326 /* Set `window' to the window under frame pixel coordinates
4327 event->x/event->y. */
4328 window
= window_from_coordinates (f
, XINT (event
->x
),
4329 XINT (event
->y
), &part
, 0);
4331 if (!WINDOWP (window
))
4333 window
= event
->frame_or_window
;
4338 /* It's a click in window window at frame coordinates
4339 event->x/ event->y. */
4340 struct window
*w
= XWINDOW (window
);
4342 /* Get window relative coordinates. Original code
4343 `rounded' this to glyph boundaries. */
4344 int wx
= FRAME_TO_WINDOW_PIXEL_X (w
, XINT (event
->x
));
4345 int wy
= FRAME_TO_WINDOW_PIXEL_Y (w
, XINT (event
->y
));
4347 /* Set event coordinates to window-relative coordinates
4348 for constructing the Lisp event below. */
4349 XSETINT (event
->x
, wx
);
4350 XSETINT (event
->y
, wy
);
4352 if (part
== 1 || part
== 3)
4354 /* Mode line or top line. Look for a string under
4355 the mouse that may have a `local-map' property. */
4359 posn
= part
== 1 ? Qmode_line
: Qheader_line
;
4360 string
= mode_line_string (w
, wx
, wy
, part
== 1, &charpos
);
4361 if (STRINGP (string
))
4362 string_info
= Fcons (string
, make_number (charpos
));
4365 posn
= Qvertical_line
;
4367 XSETINT (posn
, buffer_posn_from_coords (w
, &wx
, &wy
));
4373 Fcons (Fcons (event
->x
, event
->y
),
4374 Fcons (make_number (event
->timestamp
),
4377 : Fcons (string_info
, Qnil
))))));
4379 #ifndef USE_TOOLKIT_SCROLL_BARS
4382 /* It's a scrollbar click. */
4384 Lisp_Object portion_whole
;
4387 window
= event
->frame_or_window
;
4388 portion_whole
= Fcons (event
->x
, event
->y
);
4389 part
= *scroll_bar_parts
[(int) event
->part
];
4393 Fcons (Qvertical_scroll_bar
,
4394 Fcons (portion_whole
,
4395 Fcons (make_number (event
->timestamp
),
4396 Fcons (part
, Qnil
)))));
4398 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4400 start_pos_ptr
= &XVECTOR (button_down_location
)->contents
[button
];
4402 start_pos
= *start_pos_ptr
;
4403 *start_pos_ptr
= Qnil
;
4405 is_double
= (button
== last_mouse_button
4406 && XINT (event
->x
) == last_mouse_x
4407 && XINT (event
->y
) == last_mouse_y
4408 && button_down_time
!= 0
4409 && (EQ (Vdouble_click_time
, Qt
)
4410 || (INTEGERP (Vdouble_click_time
)
4411 && ((int)(event
->timestamp
- button_down_time
)
4412 < XINT (Vdouble_click_time
)))));
4413 last_mouse_button
= button
;
4414 last_mouse_x
= XINT (event
->x
);
4415 last_mouse_y
= XINT (event
->y
);
4417 /* If this is a button press, squirrel away the location, so
4418 we can decide later whether it was a click or a drag. */
4419 if (event
->modifiers
& down_modifier
)
4423 double_click_count
++;
4424 event
->modifiers
|= ((double_click_count
> 2)
4429 double_click_count
= 1;
4430 button_down_time
= event
->timestamp
;
4431 *start_pos_ptr
= Fcopy_alist (position
);
4434 /* Now we're releasing a button - check the co-ordinates to
4435 see if this was a click or a drag. */
4436 else if (event
->modifiers
& up_modifier
)
4438 /* If we did not see a down before this up,
4439 ignore the up. Probably this happened because
4440 the down event chose a menu item.
4441 It would be an annoyance to treat the release
4442 of the button that chose the menu item
4443 as a separate event. */
4445 if (!CONSP (start_pos
))
4448 event
->modifiers
&= ~up_modifier
;
4449 #if 0 /* Formerly we treated an up with no down as a click event. */
4450 if (!CONSP (start_pos
))
4451 event
->modifiers
|= click_modifier
;
4455 /* The third element of every position should be the (x,y)
4459 down
= Fnth (make_number (2), start_pos
);
4460 if (EQ (event
->x
, XCAR (down
))
4461 && EQ (event
->y
, XCDR (down
)))
4463 event
->modifiers
|= click_modifier
;
4467 button_down_time
= 0;
4468 event
->modifiers
|= drag_modifier
;
4470 /* Don't check is_double; treat this as multiple
4471 if the down-event was multiple. */
4472 if (double_click_count
> 1)
4473 event
->modifiers
|= ((double_click_count
> 2)
4479 /* Every mouse event should either have the down_modifier or
4480 the up_modifier set. */
4484 /* Get the symbol we should use for the mouse click. */
4487 head
= modify_event_symbol (button
,
4490 lispy_mouse_names
, &mouse_syms
,
4491 (sizeof (lispy_mouse_names
)
4492 / sizeof (lispy_mouse_names
[0])));
4493 if (event
->modifiers
& drag_modifier
)
4498 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
4501 Fcons (make_number (double_click_count
),
4510 #if USE_TOOLKIT_SCROLL_BARS
4512 /* We don't have down and up events if using toolkit scroll bars,
4513 so make this always a click event. Store in the `part' of
4514 the Lisp event a symbol which maps to the following actions:
4516 `above_handle' page up
4517 `below_handle' page down
4521 `bottom' bottom of buffer
4522 `handle' thumb has been dragged.
4523 `end-scroll' end of interaction with scroll bar
4525 The incoming input_event contains in its `part' member an
4526 index of type `enum scroll_bar_part' which we can use as an
4527 index in scroll_bar_parts to get the appropriate symbol. */
4529 case scroll_bar_click
:
4531 Lisp_Object position
, head
, window
, portion_whole
, part
;
4533 window
= event
->frame_or_window
;
4534 portion_whole
= Fcons (event
->x
, event
->y
);
4535 part
= *scroll_bar_parts
[(int) event
->part
];
4539 Fcons (Qvertical_scroll_bar
,
4540 Fcons (portion_whole
,
4541 Fcons (make_number (event
->timestamp
),
4542 Fcons (part
, Qnil
)))));
4544 /* Always treat scroll bar events as clicks. */
4545 event
->modifiers
|= click_modifier
;
4547 /* Get the symbol we should use for the mouse click. */
4548 head
= modify_event_symbol (event
->code
,
4551 lispy_mouse_names
, &mouse_syms
,
4552 (sizeof (lispy_mouse_names
)
4553 / sizeof (lispy_mouse_names
[0])));
4554 return Fcons (head
, Fcons (position
, Qnil
));
4557 #endif /* USE_TOOLKIT_SCROLL_BARS */
4560 case w32_scroll_bar_click
:
4562 int button
= event
->code
;
4564 Lisp_Object position
;
4565 Lisp_Object
*start_pos_ptr
;
4566 Lisp_Object start_pos
;
4568 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
4573 Lisp_Object portion_whole
;
4576 window
= event
->frame_or_window
;
4577 portion_whole
= Fcons (event
->x
, event
->y
);
4578 part
= *scroll_bar_parts
[(int) event
->part
];
4582 Fcons (Qvertical_scroll_bar
,
4583 Fcons (portion_whole
,
4584 Fcons (make_number (event
->timestamp
),
4585 Fcons (part
, Qnil
)))));
4588 /* Always treat W32 scroll bar events as clicks. */
4589 event
->modifiers
|= click_modifier
;
4592 /* Get the symbol we should use for the mouse click. */
4595 head
= modify_event_symbol (button
,
4598 lispy_mouse_names
, &mouse_syms
,
4599 (sizeof (lispy_mouse_names
)
4600 / sizeof (lispy_mouse_names
[0])));
4609 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
4612 Lisp_Object head
, position
;
4615 /* Ignore mouse events that were made on frame that
4616 have been deleted. */
4617 if (! FRAME_LIVE_P (f
))
4619 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4620 &column
, &row
, NULL
, 1);
4621 window
= window_from_coordinates (f
, column
, row
, &part
, 0);
4623 if (!WINDOWP (window
))
4625 window
= event
->frame_or_window
;
4630 int pixcolumn
, pixrow
;
4631 column
-= XINT (XWINDOW (window
)->left
);
4632 row
-= XINT (XWINDOW (window
)->top
);
4633 glyph_to_pixel_coords (f
, column
, row
, &pixcolumn
, &pixrow
);
4634 XSETINT (event
->x
, pixcolumn
);
4635 XSETINT (event
->y
, pixrow
);
4640 posn
= Qvertical_line
;
4642 posn
= Qheader_line
;
4645 buffer_posn_from_coords (XWINDOW (window
),
4650 Lisp_Object head
, position
;
4655 Fcons (Fcons (event
->x
, event
->y
),
4656 Fcons (make_number (event
->timestamp
),
4659 head
= modify_event_symbol (0, event
->modifiers
,
4661 lispy_mouse_wheel_names
,
4662 &mouse_wheel_syms
, 1);
4665 Fcons (make_number (event
->code
),
4669 #endif /* WINDOWSNT */
4680 /* The frame_or_window field should be a cons of the frame in
4681 which the event occurred and a list of the filenames
4683 if (! CONSP (event
->frame_or_window
))
4686 f
= XFRAME (XCAR (event
->frame_or_window
));
4687 files
= XCDR (event
->frame_or_window
);
4689 /* Ignore mouse events that were made on frames that
4690 have been deleted. */
4691 if (! FRAME_LIVE_P (f
))
4693 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4694 &column
, &row
, NULL
, 1);
4695 window
= window_from_coordinates (f
, column
, row
, &part
, 0);
4697 if (!WINDOWP (window
))
4699 window
= XCAR (event
->frame_or_window
);
4704 /* It's an event in window `window' at frame coordinates
4705 event->x/ event->y. */
4706 struct window
*w
= XWINDOW (window
);
4708 /* Get window relative coordinates. */
4709 int wx
= FRAME_TO_WINDOW_PIXEL_X (w
, XINT (event
->x
));
4710 int wy
= FRAME_TO_WINDOW_PIXEL_Y (w
, XINT (event
->y
));
4712 /* Set event coordinates to window-relative coordinates
4713 for constructing the Lisp event below. */
4714 XSETINT (event
->x
, wx
);
4715 XSETINT (event
->y
, wy
);
4720 posn
= Qvertical_line
;
4722 posn
= Qheader_line
;
4724 XSETINT (posn
, buffer_posn_from_coords (w
, &wx
, &wy
));
4728 Lisp_Object head
, position
;
4733 Fcons (Fcons (event
->x
, event
->y
),
4734 Fcons (make_number (event
->timestamp
),
4737 head
= modify_event_symbol (0, event
->modifiers
,
4739 lispy_drag_n_drop_names
,
4740 &drag_n_drop_syms
, 1);
4747 #endif /* HAVE_MOUSE */
4749 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
4750 case menu_bar_event
:
4751 /* The event value is in the cdr of the frame_or_window slot. */
4752 if (!CONSP (event
->frame_or_window
))
4754 return XCDR (event
->frame_or_window
);
4757 case TOOL_BAR_EVENT
:
4760 if (!CONSP (event
->frame_or_window
))
4762 key
= XCDR (event
->frame_or_window
);
4764 key
= apply_modifiers (event
->modifiers
, key
);
4769 /* A user signal. */
4770 return *lispy_user_signals
[event
->code
];
4772 /* The 'kind' field of the event is something we don't recognize. */
4781 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
4783 Lisp_Object bar_window
;
4784 enum scroll_bar_part part
;
4788 /* Is it a scroll bar movement? */
4789 if (frame
&& ! NILP (bar_window
))
4791 Lisp_Object part_sym
;
4793 part_sym
= *scroll_bar_parts
[(int) part
];
4794 return Fcons (Qscroll_bar_movement
,
4795 (Fcons (Fcons (bar_window
,
4796 Fcons (Qvertical_scroll_bar
,
4797 Fcons (Fcons (x
, y
),
4798 Fcons (make_number (time
),
4804 /* Or is it an ordinary mouse movement? */
4812 /* It's in a frame; which window on that frame? */
4813 window
= window_from_coordinates (frame
, XINT (x
), XINT (y
), &area
, 0);
4817 if (WINDOWP (window
))
4819 struct window
*w
= XWINDOW (window
);
4822 /* Get window relative coordinates. */
4823 wx
= FRAME_TO_WINDOW_PIXEL_X (w
, XINT (x
));
4824 wy
= FRAME_TO_WINDOW_PIXEL_Y (w
, XINT (y
));
4831 posn
= Qvertical_line
;
4833 posn
= Qheader_line
;
4835 XSETINT (posn
, buffer_posn_from_coords (w
, &wx
, &wy
));
4837 else if (frame
!= 0)
4839 XSETFRAME (window
, frame
);
4850 return Fcons (Qmouse_movement
,
4851 Fcons (Fcons (window
,
4853 Fcons (Fcons (x
, y
),
4854 Fcons (make_number (time
),
4860 #endif /* HAVE_MOUSE */
4862 /* Construct a switch frame event. */
4864 make_lispy_switch_frame (frame
)
4867 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
4870 /* Manipulating modifiers. */
4872 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
4874 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
4875 SYMBOL's name of the end of the modifiers; the string from this
4876 position is the unmodified symbol name.
4878 This doesn't use any caches. */
4881 parse_modifiers_uncached (symbol
, modifier_end
)
4885 struct Lisp_String
*name
;
4889 CHECK_SYMBOL (symbol
, 1);
4892 name
= XSYMBOL (symbol
)->name
;
4894 for (i
= 0; i
+2 <= STRING_BYTES (name
); )
4896 int this_mod_end
= 0;
4899 /* See if the name continues with a modifier word.
4900 Check that the word appears, but don't check what follows it.
4901 Set this_mod and this_mod_end to record what we find. */
4903 switch (name
->data
[i
])
4905 #define SINGLE_LETTER_MOD(BIT) \
4906 (this_mod_end = i + 1, this_mod = BIT)
4909 SINGLE_LETTER_MOD (alt_modifier
);
4913 SINGLE_LETTER_MOD (ctrl_modifier
);
4917 SINGLE_LETTER_MOD (hyper_modifier
);
4921 SINGLE_LETTER_MOD (meta_modifier
);
4925 SINGLE_LETTER_MOD (shift_modifier
);
4929 SINGLE_LETTER_MOD (super_modifier
);
4932 #undef SINGLE_LETTER_MOD
4935 /* If we found no modifier, stop looking for them. */
4936 if (this_mod_end
== 0)
4939 /* Check there is a dash after the modifier, so that it
4940 really is a modifier. */
4941 if (this_mod_end
>= STRING_BYTES (name
)
4942 || name
->data
[this_mod_end
] != '-')
4945 /* This modifier is real; look for another. */
4946 modifiers
|= this_mod
;
4947 i
= this_mod_end
+ 1;
4950 /* Should we include the `click' modifier? */
4951 if (! (modifiers
& (down_modifier
| drag_modifier
4952 | double_modifier
| triple_modifier
))
4953 && i
+ 7 == STRING_BYTES (name
)
4954 && strncmp (name
->data
+ i
, "mouse-", 6) == 0
4955 && ('0' <= name
->data
[i
+ 6] && name
->data
[i
+ 6] <= '9'))
4956 modifiers
|= click_modifier
;
4964 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
4965 prepended to the string BASE[0..BASE_LEN-1].
4966 This doesn't use any caches. */
4968 apply_modifiers_uncached (modifiers
, base
, base_len
, base_len_byte
)
4971 int base_len
, base_len_byte
;
4973 /* Since BASE could contain nulls, we can't use intern here; we have
4974 to use Fintern, which expects a genuine Lisp_String, and keeps a
4977 = (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
4983 /* Only the event queue may use the `up' modifier; it should always
4984 be turned into a click or drag event before presented to lisp code. */
4985 if (modifiers
& up_modifier
)
4988 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
4989 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
4990 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
4991 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
4992 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
4993 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
4994 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
4995 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
4996 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
4997 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
4998 /* The click modifier is denoted by the absence of other modifiers. */
5002 mod_len
= p
- new_mods
;
5006 Lisp_Object new_name
;
5008 new_name
= make_uninit_multibyte_string (mod_len
+ base_len
,
5009 mod_len
+ base_len_byte
);
5010 bcopy (new_mods
, XSTRING (new_name
)->data
, mod_len
);
5011 bcopy (base
, XSTRING (new_name
)->data
+ mod_len
, base_len_byte
);
5013 return Fintern (new_name
, Qnil
);
5018 static char *modifier_names
[] =
5020 "up", "down", "drag", "click", "double", "triple", 0, 0,
5021 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5022 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
5024 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
5026 static Lisp_Object modifier_symbols
;
5028 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
5030 lispy_modifier_list (modifiers
)
5033 Lisp_Object modifier_list
;
5036 modifier_list
= Qnil
;
5037 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
5038 if (modifiers
& (1<<i
))
5039 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
5042 return modifier_list
;
5046 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
5047 where UNMODIFIED is the unmodified form of SYMBOL,
5048 MASK is the set of modifiers present in SYMBOL's name.
5049 This is similar to parse_modifiers_uncached, but uses the cache in
5050 SYMBOL's Qevent_symbol_element_mask property, and maintains the
5051 Qevent_symbol_elements property. */
5054 parse_modifiers (symbol
)
5057 Lisp_Object elements
;
5059 elements
= Fget (symbol
, Qevent_symbol_element_mask
);
5060 if (CONSP (elements
))
5065 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
5066 Lisp_Object unmodified
;
5069 unmodified
= Fintern (make_string (XSYMBOL (symbol
)->name
->data
+ end
,
5070 STRING_BYTES (XSYMBOL (symbol
)->name
) - end
),
5073 if (modifiers
& ~(((EMACS_INT
)1 << VALBITS
) - 1))
5075 XSETFASTINT (mask
, modifiers
);
5076 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
5078 /* Cache the parsing results on SYMBOL. */
5079 Fput (symbol
, Qevent_symbol_element_mask
,
5081 Fput (symbol
, Qevent_symbol_elements
,
5082 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
5084 /* Since we know that SYMBOL is modifiers applied to unmodified,
5085 it would be nice to put that in unmodified's cache.
5086 But we can't, since we're not sure that parse_modifiers is
5093 /* Apply the modifiers MODIFIERS to the symbol BASE.
5094 BASE must be unmodified.
5096 This is like apply_modifiers_uncached, but uses BASE's
5097 Qmodifier_cache property, if present. It also builds
5098 Qevent_symbol_elements properties, since it has that info anyway.
5100 apply_modifiers copies the value of BASE's Qevent_kind property to
5101 the modified symbol. */
5103 apply_modifiers (modifiers
, base
)
5107 Lisp_Object cache
, index
, entry
, new_symbol
;
5109 /* Mask out upper bits. We don't know where this value's been. */
5110 modifiers
&= ((EMACS_INT
)1 << VALBITS
) - 1;
5112 /* The click modifier never figures into cache indices. */
5113 cache
= Fget (base
, Qmodifier_cache
);
5114 XSETFASTINT (index
, (modifiers
& ~click_modifier
));
5115 entry
= assq_no_quit (index
, cache
);
5118 new_symbol
= XCDR (entry
);
5121 /* We have to create the symbol ourselves. */
5122 new_symbol
= apply_modifiers_uncached (modifiers
,
5123 XSYMBOL (base
)->name
->data
,
5124 XSYMBOL (base
)->name
->size
,
5125 STRING_BYTES (XSYMBOL (base
)->name
));
5127 /* Add the new symbol to the base's cache. */
5128 entry
= Fcons (index
, new_symbol
);
5129 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
5131 /* We have the parsing info now for free, so add it to the caches. */
5132 XSETFASTINT (index
, modifiers
);
5133 Fput (new_symbol
, Qevent_symbol_element_mask
,
5134 Fcons (base
, Fcons (index
, Qnil
)));
5135 Fput (new_symbol
, Qevent_symbol_elements
,
5136 Fcons (base
, lispy_modifier_list (modifiers
)));
5139 /* Make sure this symbol is of the same kind as BASE.
5141 You'd think we could just set this once and for all when we
5142 intern the symbol above, but reorder_modifiers may call us when
5143 BASE's property isn't set right; we can't assume that just
5144 because it has a Qmodifier_cache property it must have its
5145 Qevent_kind set right as well. */
5146 if (NILP (Fget (new_symbol
, Qevent_kind
)))
5150 kind
= Fget (base
, Qevent_kind
);
5152 Fput (new_symbol
, Qevent_kind
, kind
);
5159 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
5160 return a symbol with the modifiers placed in the canonical order.
5161 Canonical order is alphabetical, except for down and drag, which
5162 always come last. The 'click' modifier is never written out.
5164 Fdefine_key calls this to make sure that (for example) C-M-foo
5165 and M-C-foo end up being equivalent in the keymap. */
5168 reorder_modifiers (symbol
)
5171 /* It's hopefully okay to write the code this way, since everything
5172 will soon be in caches, and no consing will be done at all. */
5175 parsed
= parse_modifiers (symbol
);
5176 return apply_modifiers ((int) XINT (XCAR (XCDR (parsed
))),
5181 /* For handling events, we often want to produce a symbol whose name
5182 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
5183 to some base, like the name of a function key or mouse button.
5184 modify_event_symbol produces symbols of this sort.
5186 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
5187 is the name of the i'th symbol. TABLE_SIZE is the number of elements
5190 Alternatively, NAME_ALIST is an alist mapping codes into symbol names.
5191 NAME_ALIST is used if it is non-nil; otherwise NAME_TABLE is used.
5193 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
5194 persist between calls to modify_event_symbol that it can use to
5195 store a cache of the symbols it's generated for this NAME_TABLE
5196 before. The object stored there may be a vector or an alist.
5198 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
5200 MODIFIERS is a set of modifier bits (as given in struct input_events)
5201 whose prefixes should be applied to the symbol name.
5203 SYMBOL_KIND is the value to be placed in the event_kind property of
5204 the returned symbol.
5206 The symbols we create are supposed to have an
5207 `event-symbol-elements' property, which lists the modifiers present
5208 in the symbol's name. */
5211 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_alist
,
5212 name_table
, symbol_table
, table_size
)
5215 Lisp_Object symbol_kind
;
5216 Lisp_Object name_alist
;
5218 Lisp_Object
*symbol_table
;
5219 unsigned int table_size
;
5222 Lisp_Object symbol_int
;
5224 /* Get rid of the "vendor-specific" bit here. */
5225 XSETINT (symbol_int
, symbol_num
& 0xffffff);
5227 /* Is this a request for a valid symbol? */
5228 if (symbol_num
< 0 || symbol_num
>= table_size
)
5231 if (CONSP (*symbol_table
))
5232 value
= Fcdr (assq_no_quit (symbol_int
, *symbol_table
));
5234 /* If *symbol_table doesn't seem to be initialized properly, fix that.
5235 *symbol_table should be a lisp vector TABLE_SIZE elements long,
5236 where the Nth element is the symbol for NAME_TABLE[N], or nil if
5237 we've never used that symbol before. */
5240 if (! VECTORP (*symbol_table
)
5241 || XVECTOR (*symbol_table
)->size
!= table_size
)
5245 XSETFASTINT (size
, table_size
);
5246 *symbol_table
= Fmake_vector (size
, Qnil
);
5249 value
= XVECTOR (*symbol_table
)->contents
[symbol_num
];
5252 /* Have we already used this symbol before? */
5255 /* No; let's create it. */
5256 if (!NILP (name_alist
))
5257 value
= Fcdr_safe (Fassq (symbol_int
, name_alist
));
5258 else if (name_table
!= 0 && name_table
[symbol_num
])
5259 value
= intern (name_table
[symbol_num
]);
5261 #ifdef HAVE_WINDOW_SYSTEM
5264 char *name
= x_get_keysym_name (symbol_num
);
5266 value
= intern (name
);
5273 sprintf (buf
, "key-%d", symbol_num
);
5274 value
= intern (buf
);
5277 if (CONSP (*symbol_table
))
5278 *symbol_table
= Fcons (Fcons (symbol_int
, value
), *symbol_table
);
5280 XVECTOR (*symbol_table
)->contents
[symbol_num
] = value
;
5282 /* Fill in the cache entries for this symbol; this also
5283 builds the Qevent_symbol_elements property, which the user
5285 apply_modifiers (modifiers
& click_modifier
, value
);
5286 Fput (value
, Qevent_kind
, symbol_kind
);
5289 /* Apply modifiers to that symbol. */
5290 return apply_modifiers (modifiers
, value
);
5293 /* Convert a list that represents an event type,
5294 such as (ctrl meta backspace), into the usual representation of that
5295 event type as a number or a symbol. */
5297 DEFUN ("event-convert-list", Fevent_convert_list
, Sevent_convert_list
, 1, 1, 0,
5298 "Convert the event description list EVENT-DESC to an event type.\n\
5299 EVENT-DESC should contain one base event type (a character or symbol)\n\
5300 and zero or more modifier names (control, meta, hyper, super, shift, alt,\n\
5301 drag, down, double or triple). The base must be last.\n\
5302 The return value is an event type (a character or symbol) which\n\
5303 has the same base event type and all the specified modifiers.")
5305 Lisp_Object event_desc
;
5313 while (CONSP (rest
))
5321 /* Given a symbol, see if it is a modifier name. */
5322 if (SYMBOLP (elt
) && CONSP (rest
))
5323 this = parse_solitary_modifier (elt
);
5327 else if (!NILP (base
))
5328 error ("Two bases given in one event");
5334 /* Let the symbol A refer to the character A. */
5335 if (SYMBOLP (base
) && XSYMBOL (base
)->name
->size
== 1)
5336 XSETINT (base
, XSYMBOL (base
)->name
->data
[0]);
5338 if (INTEGERP (base
))
5340 /* Turn (shift a) into A. */
5341 if ((modifiers
& shift_modifier
) != 0
5342 && (XINT (base
) >= 'a' && XINT (base
) <= 'z'))
5344 XSETINT (base
, XINT (base
) - ('a' - 'A'));
5345 modifiers
&= ~shift_modifier
;
5348 /* Turn (control a) into C-a. */
5349 if (modifiers
& ctrl_modifier
)
5350 return make_number ((modifiers
& ~ctrl_modifier
)
5351 | make_ctrl_char (XINT (base
)));
5353 return make_number (modifiers
| XINT (base
));
5355 else if (SYMBOLP (base
))
5356 return apply_modifiers (modifiers
, base
);
5358 error ("Invalid base event");
5361 /* Try to recognize SYMBOL as a modifier name.
5362 Return the modifier flag bit, or 0 if not recognized. */
5365 parse_solitary_modifier (symbol
)
5368 struct Lisp_String
*name
= XSYMBOL (symbol
)->name
;
5370 switch (name
->data
[0])
5372 #define SINGLE_LETTER_MOD(BIT) \
5373 if (STRING_BYTES (name) == 1) \
5376 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
5377 if (LEN == STRING_BYTES (name) \
5378 && ! strncmp (name->data, NAME, LEN)) \
5382 SINGLE_LETTER_MOD (alt_modifier
);
5386 MULTI_LETTER_MOD (alt_modifier
, "alt", 3);
5390 SINGLE_LETTER_MOD (ctrl_modifier
);
5394 MULTI_LETTER_MOD (ctrl_modifier
, "ctrl", 4);
5395 MULTI_LETTER_MOD (ctrl_modifier
, "control", 7);
5399 SINGLE_LETTER_MOD (hyper_modifier
);
5403 MULTI_LETTER_MOD (hyper_modifier
, "hyper", 5);
5407 SINGLE_LETTER_MOD (meta_modifier
);
5411 MULTI_LETTER_MOD (meta_modifier
, "meta", 4);
5415 SINGLE_LETTER_MOD (shift_modifier
);
5419 MULTI_LETTER_MOD (shift_modifier
, "shift", 5);
5420 MULTI_LETTER_MOD (super_modifier
, "super", 5);
5421 SINGLE_LETTER_MOD (super_modifier
);
5425 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
5426 MULTI_LETTER_MOD (down_modifier
, "down", 4);
5427 MULTI_LETTER_MOD (double_modifier
, "double", 6);
5431 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
5434 #undef SINGLE_LETTER_MOD
5435 #undef MULTI_LETTER_MOD
5441 /* Return 1 if EVENT is a list whose elements are all integers or symbols.
5442 Such a list is not valid as an event,
5443 but it can be a Lucid-style event type list. */
5446 lucid_event_type_list_p (object
)
5451 if (! CONSP (object
))
5454 for (tail
= object
; CONSP (tail
); tail
= XCDR (tail
))
5458 if (! (INTEGERP (elt
) || SYMBOLP (elt
)))
5465 /* Store into *addr a value nonzero if terminal input chars are available.
5466 Serves the purpose of ioctl (0, FIONREAD, addr)
5467 but works even if FIONREAD does not exist.
5468 (In fact, this may actually read some input.)
5470 If DO_TIMERS_NOW is nonzero, actually run timer events that are ripe. */
5473 get_input_pending (addr
, do_timers_now
)
5477 /* First of all, have we already counted some input? */
5478 *addr
= !NILP (Vquit_flag
) || readable_events (do_timers_now
);
5480 /* If input is being read as it arrives, and we have none, there is none. */
5481 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
5484 /* Try to read some input and see how much we get. */
5486 *addr
= !NILP (Vquit_flag
) || readable_events (do_timers_now
);
5489 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
5492 gobble_input (expected
)
5497 if (interrupt_input
)
5500 mask
= sigblock (sigmask (SIGIO
));
5501 read_avail_input (expected
);
5505 #ifdef POLL_FOR_INPUT
5506 if (read_socket_hook
&& !interrupt_input
&& poll_suppress_count
== 0)
5509 mask
= sigblock (sigmask (SIGALRM
));
5510 read_avail_input (expected
);
5516 read_avail_input (expected
);
5520 /* Put a buffer_switch_event in the buffer
5521 so that read_key_sequence will notice the new current buffer. */
5524 record_asynch_buffer_change ()
5526 struct input_event event
;
5529 event
.kind
= buffer_switch_event
;
5530 event
.frame_or_window
= Qnil
;
5533 /* We don't need a buffer-switch event unless Emacs is waiting for input.
5534 The purpose of the event is to make read_key_sequence look up the
5535 keymaps again. If we aren't in read_key_sequence, we don't need one,
5536 and the event could cause trouble by messing up (input-pending-p). */
5537 tem
= Fwaiting_for_user_input_p ();
5541 /* We never need these events if we have no asynchronous subprocesses. */
5545 /* Make sure no interrupt happens while storing the event. */
5547 if (interrupt_input
)
5550 mask
= sigblock (sigmask (SIGIO
));
5551 kbd_buffer_store_event (&event
);
5558 kbd_buffer_store_event (&event
);
5565 /* Read any terminal input already buffered up by the system
5566 into the kbd_buffer, but do not wait.
5568 EXPECTED should be nonzero if the caller knows there is some input.
5570 Except on VMS, all input is read by this function.
5571 If interrupt_input is nonzero, this function MUST be called
5572 only when SIGIO is blocked.
5574 Returns the number of keyboard chars read, or -1 meaning
5575 this is a bad time to try to read input. */
5578 read_avail_input (expected
)
5581 struct input_event buf
[KBD_BUFFER_SIZE
];
5585 if (read_socket_hook
)
5586 /* No need for FIONREAD or fcntl; just say don't wait. */
5587 nread
= (*read_socket_hook
) (input_fd
, buf
, KBD_BUFFER_SIZE
, expected
);
5590 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
5591 the kbd_buffer can really hold. That may prevent loss
5592 of characters on some systems when input is stuffed at us. */
5593 unsigned char cbuf
[KBD_BUFFER_SIZE
- 1];
5596 /* Determine how many characters we should *try* to read. */
5599 #else /* not WINDOWSNT */
5601 n_to_read
= dos_keysns ();
5604 #else /* not MSDOS */
5606 /* Find out how much input is available. */
5607 if (ioctl (input_fd
, FIONREAD
, &n_to_read
) < 0)
5608 /* Formerly simply reported no input, but that sometimes led to
5609 a failure of Emacs to terminate.
5610 SIGHUP seems appropriate if we can't reach the terminal. */
5611 /* ??? Is it really right to send the signal just to this process
5612 rather than to the whole process group?
5613 Perhaps on systems with FIONREAD Emacs is alone in its group. */
5614 kill (getpid (), SIGHUP
);
5617 if (n_to_read
> sizeof cbuf
)
5618 n_to_read
= sizeof cbuf
;
5619 #else /* no FIONREAD */
5620 #if defined (USG) || defined (DGUX)
5621 /* Read some input if available, but don't wait. */
5622 n_to_read
= sizeof cbuf
;
5623 fcntl (input_fd
, F_SETFL
, O_NDELAY
);
5628 #endif /* not MSDOS */
5629 #endif /* not WINDOWSNT */
5631 /* Now read; for one reason or another, this will not block.
5632 NREAD is set to the number of chars read. */
5636 cbuf
[0] = dos_keyread ();
5639 nread
= emacs_read (input_fd
, cbuf
, n_to_read
);
5641 /* POSIX infers that processes which are not in the session leader's
5642 process group won't get SIGHUP's at logout time. BSDI adheres to
5643 this part standard and returns -1 from read (0) with errno==EIO
5644 when the control tty is taken away.
5645 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
5646 if (nread
== -1 && errno
== EIO
)
5648 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
5649 /* The kernel sometimes fails to deliver SIGHUP for ptys.
5650 This looks incorrect, but it isn't, because _BSD causes
5651 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
5652 and that causes a value other than 0 when there is no input. */
5658 /* We used to retry the read if it was interrupted.
5659 But this does the wrong thing when O_NDELAY causes
5660 an EAGAIN error. Does anybody know of a situation
5661 where a retry is actually needed? */
5663 nread
< 0 && (errno
== EAGAIN
5677 #if defined (USG) || defined (DGUX)
5678 fcntl (input_fd
, F_SETFL
, 0);
5679 #endif /* USG or DGUX */
5680 #endif /* no FIONREAD */
5681 for (i
= 0; i
< nread
; i
++)
5683 buf
[i
].kind
= ascii_keystroke
;
5684 buf
[i
].modifiers
= 0;
5685 if (meta_key
== 1 && (cbuf
[i
] & 0x80))
5686 buf
[i
].modifiers
= meta_modifier
;
5690 buf
[i
].code
= cbuf
[i
];
5691 buf
[i
].frame_or_window
= selected_frame
;
5695 /* Scan the chars for C-g and store them in kbd_buffer. */
5696 for (i
= 0; i
< nread
; i
++)
5698 kbd_buffer_store_event (&buf
[i
]);
5699 /* Don't look at input that follows a C-g too closely.
5700 This reduces lossage due to autorepeat on C-g. */
5701 if (buf
[i
].kind
== ascii_keystroke
5702 && buf
[i
].code
== quit_char
)
5708 #endif /* not VMS */
5710 #ifdef SIGIO /* for entire page */
5711 /* Note SIGIO has been undef'd if FIONREAD is missing. */
5714 input_available_signal (signo
)
5717 /* Must preserve main program's value of errno. */
5718 int old_errno
= errno
;
5720 extern int select_alarmed
;
5723 #if defined (USG) && !defined (POSIX_SIGNALS)
5724 /* USG systems forget handlers when they are used;
5725 must reestablish each time */
5726 signal (signo
, input_available_signal
);
5733 if (input_available_clear_time
)
5734 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
5739 nread
= read_avail_input (1);
5740 /* -1 means it's not ok to read the input now.
5741 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
5742 0 means there was no keyboard input available. */
5747 select_alarmed
= 1; /* Force the select emulator back to life */
5758 /* Send ourselves a SIGIO.
5760 This function exists so that the UNBLOCK_INPUT macro in
5761 blockinput.h can have some way to take care of input we put off
5762 dealing with, without assuming that every file which uses
5763 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
5765 reinvoke_input_signal ()
5768 kill (getpid (), SIGIO
);
5774 /* Return the prompt-string of a sparse keymap.
5775 This is the first element which is a string.
5776 Return nil if there is none. */
5784 register Lisp_Object tem
;
5793 static void menu_bar_item ();
5794 static void menu_bar_one_keymap ();
5796 /* These variables hold the vector under construction within
5797 menu_bar_items and its subroutines, and the current index
5798 for storing into that vector. */
5799 static Lisp_Object menu_bar_items_vector
;
5800 static int menu_bar_items_index
;
5802 /* Return a vector of menu items for a menu bar, appropriate
5803 to the current buffer. Each item has three elements in the vector:
5806 OLD is an old vector we can optionally reuse, or nil. */
5809 menu_bar_items (old
)
5812 /* The number of keymaps we're scanning right now, and the number of
5813 keymaps we have allocated space for. */
5816 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
5817 in the current keymaps, or nil where it is not a prefix. */
5820 Lisp_Object def
, tem
, tail
;
5829 struct gcpro gcpro1
;
5831 /* In order to build the menus, we need to call the keymap
5832 accessors. They all call QUIT. But this function is called
5833 during redisplay, during which a quit is fatal. So inhibit
5834 quitting while building the menus.
5835 We do this instead of specbind because (1) errors will clear it anyway
5836 and (2) this avoids risk of specpdl overflow. */
5837 oquit
= Vinhibit_quit
;
5841 menu_bar_items_vector
= old
;
5843 menu_bar_items_vector
= Fmake_vector (make_number (24), Qnil
);
5844 menu_bar_items_index
= 0;
5846 GCPRO1 (menu_bar_items_vector
);
5848 /* Build our list of keymaps.
5849 If we recognize a function key and replace its escape sequence in
5850 keybuf with its symbol, or if the sequence starts with a mouse
5851 click and we need to switch buffers, we jump back here to rebuild
5852 the initial keymaps from the current buffer. */
5856 /* Should overriding-terminal-local-map and overriding-local-map apply? */
5857 if (!NILP (Voverriding_local_map_menu_flag
))
5859 /* Yes, use them (if non-nil) as well as the global map. */
5860 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
5862 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
5863 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
5864 if (!NILP (Voverriding_local_map
))
5865 maps
[nmaps
++] = Voverriding_local_map
;
5869 /* No, so use major and minor mode keymaps. */
5870 nmaps
= current_minor_maps (NULL
, &tmaps
);
5871 maps
= (Lisp_Object
*) alloca ((nmaps
+ 2) * sizeof (maps
[0]));
5872 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
5873 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
5875 maps
[nmaps
++] = current_global_map
;
5878 /* Look up in each map the dummy prefix key `menu-bar'. */
5882 for (mapno
= nmaps
- 1; mapno
>= 0; mapno
--)
5884 if (! NILP (maps
[mapno
]))
5885 def
= get_keyelt (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0), 0);
5889 tem
= Fkeymapp (def
);
5891 menu_bar_one_keymap (def
);
5894 /* Move to the end those items that should be at the end. */
5896 for (tail
= Vmenu_bar_final_items
; CONSP (tail
); tail
= XCDR (tail
))
5899 int end
= menu_bar_items_index
;
5901 for (i
= 0; i
< end
; i
+= 4)
5902 if (EQ (XCAR (tail
), XVECTOR (menu_bar_items_vector
)->contents
[i
]))
5904 Lisp_Object tem0
, tem1
, tem2
, tem3
;
5905 /* Move the item at index I to the end,
5906 shifting all the others forward. */
5907 tem0
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 0];
5908 tem1
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 1];
5909 tem2
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
5910 tem3
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3];
5912 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
5913 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
5914 (end
- i
- 4) * sizeof (Lisp_Object
));
5915 XVECTOR (menu_bar_items_vector
)->contents
[end
- 4] = tem0
;
5916 XVECTOR (menu_bar_items_vector
)->contents
[end
- 3] = tem1
;
5917 XVECTOR (menu_bar_items_vector
)->contents
[end
- 2] = tem2
;
5918 XVECTOR (menu_bar_items_vector
)->contents
[end
- 1] = tem3
;
5923 /* Add nil, nil, nil, nil at the end. */
5924 i
= menu_bar_items_index
;
5925 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
5928 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
5929 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
5930 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
5931 menu_bar_items_vector
= tem
;
5933 /* Add this item. */
5934 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5935 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5936 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5937 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5938 menu_bar_items_index
= i
;
5940 Vinhibit_quit
= oquit
;
5942 return menu_bar_items_vector
;
5945 /* Scan one map KEYMAP, accumulating any menu items it defines
5946 in menu_bar_items_vector. */
5948 static Lisp_Object menu_bar_one_keymap_changed_items
;
5951 menu_bar_one_keymap (keymap
)
5954 Lisp_Object tail
, item
;
5956 menu_bar_one_keymap_changed_items
= Qnil
;
5958 /* Loop over all keymap entries that have menu strings. */
5959 for (tail
= keymap
; CONSP (tail
); tail
= XCDR (tail
))
5963 menu_bar_item (XCAR (item
), XCDR (item
));
5964 else if (VECTORP (item
))
5966 /* Loop over the char values represented in the vector. */
5967 int len
= XVECTOR (item
)->size
;
5969 for (c
= 0; c
< len
; c
++)
5971 Lisp_Object character
;
5972 XSETFASTINT (character
, c
);
5973 menu_bar_item (character
, XVECTOR (item
)->contents
[c
]);
5979 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
5980 If there's already an item for KEY, add this DEF to it. */
5982 Lisp_Object item_properties
;
5985 menu_bar_item (key
, item
)
5986 Lisp_Object key
, item
;
5988 struct gcpro gcpro1
;
5992 if (EQ (item
, Qundefined
))
5994 /* If a map has an explicit `undefined' as definition,
5995 discard any previously made menu bar item. */
5997 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
5998 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
6000 if (menu_bar_items_index
> i
+ 4)
6001 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
6002 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
6003 (menu_bar_items_index
- i
- 4) * sizeof (Lisp_Object
));
6004 menu_bar_items_index
-= 4;
6008 /* If there's no definition for this key yet,
6009 just ignore `undefined'. */
6013 GCPRO1 (key
); /* Is this necessary? */
6014 i
= parse_menu_item (item
, 0, 1);
6019 /* If this keymap has already contributed to this KEY,
6020 don't contribute to it a second time. */
6021 tem
= Fmemq (key
, menu_bar_one_keymap_changed_items
);
6025 menu_bar_one_keymap_changed_items
6026 = Fcons (key
, menu_bar_one_keymap_changed_items
);
6028 item
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
6030 /* Find any existing item for this KEY. */
6031 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
6032 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
6035 /* If we did not find this KEY, add it at the end. */
6036 if (i
== menu_bar_items_index
)
6038 /* If vector is too small, get a bigger one. */
6039 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
6042 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
6043 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
6044 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
6045 menu_bar_items_vector
= tem
;
6048 /* Add this item. */
6049 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = key
;
6050 XVECTOR (menu_bar_items_vector
)->contents
[i
++]
6051 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
6052 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Fcons (item
, Qnil
);
6053 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = make_number (0);
6054 menu_bar_items_index
= i
;
6056 /* We did find an item for this KEY. Add ITEM to its list of maps. */
6060 old
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
6061 XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2] = Fcons (item
, old
);
6065 /* This is used as the handler when calling menu_item_eval_property. */
6067 menu_item_eval_property_1 (arg
)
6070 /* If we got a quit from within the menu computation,
6071 quit all the way out of it. This takes care of C-] in the debugger. */
6072 if (CONSP (arg
) && EQ (XCAR (arg
), Qquit
))
6073 Fsignal (Qquit
, Qnil
);
6078 /* Evaluate an expression and return the result (or nil if something
6079 went wrong). Used to evaluate dynamic parts of menu items. */
6081 menu_item_eval_property (sexpr
)
6084 int count
= specpdl_ptr
- specpdl
;
6086 specbind (Qinhibit_redisplay
, Qt
);
6087 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
,
6088 menu_item_eval_property_1
);
6089 return unbind_to (count
, val
);
6092 /* This function parses a menu item and leaves the result in the
6093 vector item_properties.
6094 ITEM is a key binding, a possible menu item.
6095 If NOTREAL is nonzero, only check for equivalent key bindings, don't
6096 evaluate dynamic expressions in the menu item.
6097 INMENUBAR is > 0 when this is considered for an entry in a menu bar
6099 INMENUBAR is < 0 when this is considered for an entry in a keyboard menu.
6100 parse_menu_item returns true if the item is a menu item and false
6104 parse_menu_item (item
, notreal
, inmenubar
)
6106 int notreal
, inmenubar
;
6108 Lisp_Object def
, tem
, item_string
, start
;
6109 Lisp_Object cachelist
;
6111 Lisp_Object keyhint
;
6122 /* Create item_properties vector if necessary. */
6123 if (NILP (item_properties
))
6125 = Fmake_vector (make_number (ITEM_PROPERTY_ENABLE
+ 1), Qnil
);
6127 /* Initialize optional entries. */
6128 for (i
= ITEM_PROPERTY_DEF
; i
< ITEM_PROPERTY_ENABLE
; i
++)
6129 XVECTOR (item_properties
)->contents
[i
] = Qnil
;
6130 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
] = Qt
;
6132 /* Save the item here to protect it from GC. */
6133 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ITEM
] = item
;
6135 item_string
= XCAR (item
);
6139 if (STRINGP (item_string
))
6141 /* Old format menu item. */
6142 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
] = item_string
;
6144 /* Maybe help string. */
6145 if (CONSP (item
) && STRINGP (XCAR (item
)))
6147 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_HELP
]
6153 /* Maybee key binding cache. */
6154 if (CONSP (item
) && CONSP (XCAR (item
))
6155 && (NILP (XCAR (XCAR (item
)))
6156 || VECTORP (XCAR (XCAR (item
)))))
6158 cachelist
= XCAR (item
);
6162 /* This is the real definition--the function to run. */
6163 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
] = item
;
6165 /* Get enable property, if any. */
6168 tem
= Fget (item
, Qmenu_enable
);
6170 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
] = tem
;
6173 else if (EQ (item_string
, Qmenu_item
) && CONSP (item
))
6175 /* New format menu item. */
6176 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
]
6178 start
= XCDR (item
);
6181 /* We have a real binding. */
6182 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
]
6185 item
= XCDR (start
);
6186 /* Is there a cache list with key equivalences. */
6187 if (CONSP (item
) && CONSP (XCAR (item
)))
6189 cachelist
= XCAR (item
);
6193 /* Parse properties. */
6194 while (CONSP (item
) && CONSP (XCDR (item
)))
6199 if (EQ (tem
, QCenable
))
6200 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
]
6202 else if (EQ (tem
, QCvisible
) && !notreal
)
6204 /* If got a visible property and that evaluates to nil
6205 then ignore this item. */
6206 tem
= menu_item_eval_property (XCAR (item
));
6210 else if (EQ (tem
, QChelp
))
6211 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_HELP
]
6213 else if (EQ (tem
, QCfilter
))
6215 else if (EQ (tem
, QCkey_sequence
))
6218 if (NILP (cachelist
)
6219 && (SYMBOLP (tem
) || STRINGP (tem
) || VECTORP (tem
)))
6220 /* Be GC protected. Set keyhint to item instead of tem. */
6223 else if (EQ (tem
, QCkeys
))
6226 if (CONSP (tem
) || (STRINGP (tem
) && NILP (cachelist
)))
6227 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
]
6230 else if (EQ (tem
, QCbutton
) && CONSP (XCAR (item
)))
6235 if (EQ (type
, QCtoggle
) || EQ (type
, QCradio
))
6237 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
]
6239 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_TYPE
]
6246 else if (inmenubar
|| !NILP (start
))
6250 return 0; /* not a menu item */
6252 /* If item string is not a string, evaluate it to get string.
6253 If we don't get a string, skip this item. */
6254 item_string
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
6255 if (!(STRINGP (item_string
) || notreal
))
6257 item_string
= menu_item_eval_property (item_string
);
6258 if (!STRINGP (item_string
))
6260 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
] = item_string
;
6263 /* If got a filter apply it on definition. */
6264 def
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
6267 def
= menu_item_eval_property (list2 (XCAR (filter
),
6268 list2 (Qquote
, def
)));
6270 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
] = def
;
6273 /* If we got no definition, this item is just unselectable text which
6274 is OK in a submenu but not in the menubar. */
6276 return (inmenubar
? 0 : 1);
6278 /* Enable or disable selection of item. */
6279 tem
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
];
6285 tem
= menu_item_eval_property (tem
);
6286 if (inmenubar
&& NILP (tem
))
6287 return 0; /* Ignore disabled items in menu bar. */
6288 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
] = tem
;
6291 /* See if this is a separate pane or a submenu. */
6292 def
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
6293 tem
= get_keymap_1 (def
, 0, 1);
6294 /* For a subkeymap, just record its details and exit. */
6297 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_MAP
] = tem
;
6298 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
] = tem
;
6301 /* At the top level in the menu bar, do likewise for commands also.
6302 The menu bar does not display equivalent key bindings anyway.
6303 ITEM_PROPERTY_DEF is already set up properly. */
6307 /* This is a command. See if there is an equivalent key binding. */
6308 if (NILP (cachelist
))
6310 /* We have to create a cachelist. */
6311 CHECK_IMPURE (start
);
6312 XCDR (start
) = Fcons (Fcons (Qnil
, Qnil
), XCDR (start
));
6313 cachelist
= XCAR (XCDR (start
));
6315 tem
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
6316 if (!NILP (keyhint
))
6318 XCAR (cachelist
) = XCAR (keyhint
);
6321 else if (STRINGP (tem
))
6323 XCDR (cachelist
) = Fsubstitute_command_keys (tem
);
6324 XCAR (cachelist
) = Qt
;
6327 tem
= XCAR (cachelist
);
6334 tem
= Fkey_binding (tem
, Qnil
);
6336 prefix
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
6339 def
= XCAR (prefix
);
6340 prefix
= XCDR (prefix
);
6343 def
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
6345 if (NILP (XCAR (cachelist
))) /* Have no saved key. */
6347 if (newcache
/* Always check first time. */
6348 /* Should we check everything when precomputing key
6351 /* If something had no key binding before, don't recheck it
6352 because that is too slow--except if we have a list of
6353 rebound commands in Vdefine_key_rebound_commands, do
6354 recheck any command that appears in that list. */
6355 || (CONSP (Vdefine_key_rebound_commands
)
6356 && !NILP (Fmemq (def
, Vdefine_key_rebound_commands
))))
6359 /* We had a saved key. Is it still bound to the command? */
6362 /* If the command is an alias for another
6363 (such as lmenu.el set it up), check if the
6364 original command matches the cached command. */
6365 && !(SYMBOLP (def
) && EQ (tem
, XSYMBOL (def
)->function
))))
6366 chkcache
= 1; /* Need to recompute key binding. */
6370 /* Recompute equivalent key binding. If the command is an alias
6371 for another (such as lmenu.el set it up), see if the original
6372 command name has equivalent keys. Otherwise look up the
6373 specified command itself. We don't try both, because that
6374 makes lmenu menus slow. */
6375 if (SYMBOLP (def
) && SYMBOLP (XSYMBOL (def
)->function
)
6376 && ! NILP (Fget (def
, Qmenu_alias
)))
6377 def
= XSYMBOL (def
)->function
;
6378 tem
= Fwhere_is_internal (def
, Qnil
, Qt
, Qnil
);
6379 XCAR (cachelist
) = tem
;
6382 XCDR (cachelist
) = Qnil
;
6386 else if (!NILP (keyhint
) && !NILP (XCAR (cachelist
)))
6388 tem
= XCAR (cachelist
);
6392 newcache
= chkcache
;
6395 tem
= Fkey_description (tem
);
6398 if (STRINGP (XCAR (prefix
)))
6399 tem
= concat2 (XCAR (prefix
), tem
);
6400 if (STRINGP (XCDR (prefix
)))
6401 tem
= concat2 (tem
, XCDR (prefix
));
6403 XCDR (cachelist
) = tem
;
6407 tem
= XCDR (cachelist
);
6408 if (newcache
&& !NILP (tem
))
6410 tem
= concat3 (build_string (" ("), tem
, build_string (")"));
6411 XCDR (cachelist
) = tem
;
6414 /* If we only want to precompute equivalent key bindings, stop here. */
6418 /* If we have an equivalent key binding, use that. */
6419 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
] = tem
;
6421 /* Include this when menu help is implemented.
6422 tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP];
6423 if (!(NILP (tem) || STRINGP (tem)))
6425 tem = menu_item_eval_property (tem);
6428 XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP] = tem;
6432 /* Handle radio buttons or toggle boxes. */
6433 tem
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
];
6435 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
]
6436 = menu_item_eval_property (tem
);
6443 /***********************************************************************
6445 ***********************************************************************/
6447 /* A vector holding tool bar items while they are parsed in function
6448 tool_bar_items runs Each item occupies TOOL_BAR_ITEM_NSCLOTS elements
6451 static Lisp_Object tool_bar_items_vector
;
6453 /* A vector holding the result of parse_tool_bar_item. Layout is like
6454 the one for a single item in tool_bar_items_vector. */
6456 static Lisp_Object tool_bar_item_properties
;
6458 /* Next free index in tool_bar_items_vector. */
6460 static int ntool_bar_items
;
6462 /* The symbols `tool-bar', and `:image'. */
6464 extern Lisp_Object Qtool_bar
;
6465 Lisp_Object QCimage
;
6467 /* Function prototypes. */
6469 static void init_tool_bar_items
P_ ((Lisp_Object
));
6470 static void process_tool_bar_item
P_ ((Lisp_Object
, Lisp_Object
));
6471 static int parse_tool_bar_item
P_ ((Lisp_Object
, Lisp_Object
));
6472 static void append_tool_bar_item
P_ ((void));
6475 /* Return a vector of tool bar items for keymaps currently in effect.
6476 Reuse vector REUSE if non-nil. Return in *NITEMS the number of
6477 tool bar items found. */
6480 tool_bar_items (reuse
, nitems
)
6488 extern Lisp_Object Voverriding_local_map_menu_flag
;
6489 extern Lisp_Object Voverriding_local_map
;
6493 /* In order to build the menus, we need to call the keymap
6494 accessors. They all call QUIT. But this function is called
6495 during redisplay, during which a quit is fatal. So inhibit
6496 quitting while building the menus. We do this instead of
6497 specbind because (1) errors will clear it anyway and (2) this
6498 avoids risk of specpdl overflow. */
6499 oquit
= Vinhibit_quit
;
6502 /* Initialize tool_bar_items_vector and protect it from GC. */
6503 init_tool_bar_items (reuse
);
6505 /* Build list of keymaps in maps. Set nmaps to the number of maps
6508 /* Should overriding-terminal-local-map and overriding-local-map apply? */
6509 if (!NILP (Voverriding_local_map_menu_flag
))
6511 /* Yes, use them (if non-nil) as well as the global map. */
6512 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
6514 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
6515 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
6516 if (!NILP (Voverriding_local_map
))
6517 maps
[nmaps
++] = Voverriding_local_map
;
6521 /* No, so use major and minor mode keymaps. */
6522 nmaps
= current_minor_maps (NULL
, &tmaps
);
6523 maps
= (Lisp_Object
*) alloca ((nmaps
+ 2) * sizeof (maps
[0]));
6524 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
6525 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
6528 /* Add global keymap at the end. */
6529 maps
[nmaps
++] = current_global_map
;
6531 /* Process maps in reverse order and look up in each map the prefix
6533 for (i
= nmaps
- 1; i
>= 0; --i
)
6534 if (!NILP (maps
[i
]))
6538 keymap
= get_keyelt (access_keymap (maps
[i
], Qtool_bar
, 1, 1), 0);
6539 if (!NILP (Fkeymapp (keymap
)))
6543 /* KEYMAP is a list `(keymap (KEY . BINDING) ...)'. */
6544 for (tail
= keymap
; CONSP (tail
); tail
= XCDR (tail
))
6546 Lisp_Object keydef
= XCAR (tail
);
6548 process_tool_bar_item (XCAR (keydef
), XCDR (keydef
));
6553 Vinhibit_quit
= oquit
;
6554 *nitems
= ntool_bar_items
/ TOOL_BAR_ITEM_NSLOTS
;
6555 return tool_bar_items_vector
;
6559 /* Process the definition of KEY which is DEF. */
6562 process_tool_bar_item (key
, def
)
6563 Lisp_Object key
, def
;
6566 extern Lisp_Object Qundefined
;
6567 struct gcpro gcpro1
, gcpro2
;
6569 /* Protect KEY and DEF from GC because parse_tool_bar_item may call
6573 if (EQ (def
, Qundefined
))
6575 /* If a map has an explicit `undefined' as definition,
6576 discard any previously made item. */
6577 for (i
= 0; i
< ntool_bar_items
; i
+= TOOL_BAR_ITEM_NSLOTS
)
6579 Lisp_Object
*v
= XVECTOR (tool_bar_items_vector
)->contents
+ i
;
6581 if (EQ (key
, v
[TOOL_BAR_ITEM_KEY
]))
6583 if (ntool_bar_items
> i
+ TOOL_BAR_ITEM_NSLOTS
)
6584 bcopy (v
+ TOOL_BAR_ITEM_NSLOTS
, v
,
6585 ((ntool_bar_items
- i
- TOOL_BAR_ITEM_NSLOTS
)
6586 * sizeof (Lisp_Object
)));
6587 ntool_bar_items
-= TOOL_BAR_ITEM_NSLOTS
;
6592 else if (parse_tool_bar_item (key
, def
))
6593 /* Append a new tool bar item to tool_bar_items_vector. Accept
6594 more than one definition for the same key. */
6595 append_tool_bar_item ();
6601 /* Parse a tool bar item specification ITEM for key KEY and return the
6602 result in tool_bar_item_properties. Value is zero if ITEM is
6605 ITEM is a list `(menu-item CAPTION BINDING PROPS...)'.
6607 CAPTION is the caption of the item, If it's not a string, it is
6608 evaluated to get a string.
6610 BINDING is the tool bar item's binding. Tool-bar items with keymaps
6611 as binding are currently ignored.
6613 The following properties are recognized:
6617 FORM is evaluated and specifies whether the tool bar item is
6618 enabled or disabled.
6622 FORM is evaluated and specifies whether the tool bar item is visible.
6624 - `:filter FUNCTION'
6626 FUNCTION is invoked with one parameter `(quote BINDING)'. Its
6627 result is stored as the new binding.
6629 - `:button (TYPE SELECTED)'
6631 TYPE must be one of `:radio' or `:toggle'. SELECTED is evaluated
6632 and specifies whether the button is selected (pressed) or not.
6636 IMAGES is either a single image specification or a vector of four
6637 image specifications. See enum tool_bar_item_images.
6639 - `:help HELP-STRING'.
6641 Gives a help string to display for the tool bar item. */
6644 parse_tool_bar_item (key
, item
)
6645 Lisp_Object key
, item
;
6647 /* Access slot with index IDX of vector tool_bar_item_properties. */
6648 #define PROP(IDX) XVECTOR (tool_bar_item_properties)->contents[IDX]
6650 Lisp_Object filter
= Qnil
;
6651 Lisp_Object caption
;
6652 extern Lisp_Object QCenable
, QCvisible
, QChelp
, QCfilter
;
6653 extern Lisp_Object QCbutton
, QCtoggle
, QCradio
;
6656 /* Defininition looks like `(tool-bar-item CAPTION BINDING
6657 PROPS...)'. Rule out items that aren't lists, don't start with
6658 `tool-bar-item' or whose rest following `tool-bar-item' is not a
6661 || !EQ (XCAR (item
), Qmenu_item
)
6662 || (item
= XCDR (item
),
6666 /* Create tool_bar_item_properties vector if necessary. Reset it to
6668 if (VECTORP (tool_bar_item_properties
))
6670 for (i
= 0; i
< TOOL_BAR_ITEM_NSLOTS
; ++i
)
6674 tool_bar_item_properties
6675 = Fmake_vector (make_number (TOOL_BAR_ITEM_NSLOTS
), Qnil
);
6678 PROP (TOOL_BAR_ITEM_KEY
) = key
;
6679 PROP (TOOL_BAR_ITEM_ENABLED_P
) = Qt
;
6681 /* Get the caption of the item. If the caption is not a string,
6682 evaluate it to get a string. If we don't get a string, skip this
6684 caption
= XCAR (item
);
6685 if (!STRINGP (caption
))
6687 caption
= menu_item_eval_property (caption
);
6688 if (!STRINGP (caption
))
6691 PROP (TOOL_BAR_ITEM_CAPTION
) = caption
;
6693 /* Give up if rest following the caption is not a list. */
6698 /* Store the binding. */
6699 PROP (TOOL_BAR_ITEM_BINDING
) = XCAR (item
);
6702 /* Process the rest of the properties. */
6703 for (; CONSP (item
) && CONSP (XCDR (item
)); item
= XCDR (XCDR (item
)))
6705 Lisp_Object key
, value
;
6708 value
= XCAR (XCDR (item
));
6710 if (EQ (key
, QCenable
))
6711 /* `:enable FORM'. */
6712 PROP (TOOL_BAR_ITEM_ENABLED_P
) = value
;
6713 else if (EQ (key
, QCvisible
))
6715 /* `:visible FORM'. If got a visible property and that
6716 evaluates to nil then ignore this item. */
6717 if (NILP (menu_item_eval_property (value
)))
6720 else if (EQ (key
, QChelp
))
6721 /* `:help HELP-STRING'. */
6722 PROP (TOOL_BAR_ITEM_HELP
) = value
;
6723 else if (EQ (key
, QCfilter
))
6724 /* ':filter FORM'. */
6726 else if (EQ (key
, QCbutton
) && CONSP (value
))
6728 /* `:button (TYPE . SELECTED)'. */
6729 Lisp_Object type
, selected
;
6731 type
= XCAR (value
);
6732 selected
= XCDR (value
);
6733 if (EQ (type
, QCtoggle
) || EQ (type
, QCradio
))
6735 PROP (TOOL_BAR_ITEM_SELECTED_P
) = selected
;
6736 PROP (TOOL_BAR_ITEM_TYPE
) = type
;
6739 else if (EQ (key
, QCimage
)
6741 || (VECTORP (value
) && XVECTOR (value
)->size
== 4)))
6742 /* Value is either a single image specification or a vector
6743 of 4 such specifications for the different buttion states. */
6744 PROP (TOOL_BAR_ITEM_IMAGES
) = value
;
6747 /* If got a filter apply it on binding. */
6749 PROP (TOOL_BAR_ITEM_BINDING
)
6750 = menu_item_eval_property (list2 (filter
,
6752 PROP (TOOL_BAR_ITEM_BINDING
))));
6754 /* See if the binding is a keymap. Give up if it is. */
6755 if (!NILP (get_keymap_1 (PROP (TOOL_BAR_ITEM_BINDING
), 0, 1)))
6758 /* Enable or disable selection of item. */
6759 if (!EQ (PROP (TOOL_BAR_ITEM_ENABLED_P
), Qt
))
6760 PROP (TOOL_BAR_ITEM_ENABLED_P
)
6761 = menu_item_eval_property (PROP (TOOL_BAR_ITEM_ENABLED_P
));
6763 /* Handle radio buttons or toggle boxes. */
6764 if (!NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
)))
6765 PROP (TOOL_BAR_ITEM_SELECTED_P
)
6766 = menu_item_eval_property (PROP (TOOL_BAR_ITEM_SELECTED_P
));
6774 /* Initialize tool_bar_items_vector. REUSE, if non-nil, is a vector
6775 that can be reused. */
6778 init_tool_bar_items (reuse
)
6781 if (VECTORP (reuse
))
6782 tool_bar_items_vector
= reuse
;
6784 tool_bar_items_vector
= Fmake_vector (make_number (64), Qnil
);
6785 ntool_bar_items
= 0;
6789 /* Append parsed tool bar item properties from
6790 tool_bar_item_properties */
6793 append_tool_bar_item ()
6795 Lisp_Object
*to
, *from
;
6797 /* Enlarge tool_bar_items_vector if necessary. */
6798 if (ntool_bar_items
+ TOOL_BAR_ITEM_NSLOTS
6799 >= XVECTOR (tool_bar_items_vector
)->size
)
6801 Lisp_Object new_vector
;
6802 int old_size
= XVECTOR (tool_bar_items_vector
)->size
;
6804 new_vector
= Fmake_vector (make_number (2 * old_size
), Qnil
);
6805 bcopy (XVECTOR (tool_bar_items_vector
)->contents
,
6806 XVECTOR (new_vector
)->contents
,
6807 old_size
* sizeof (Lisp_Object
));
6808 tool_bar_items_vector
= new_vector
;
6811 /* Append entries from tool_bar_item_properties to the end of
6812 tool_bar_items_vector. */
6813 to
= XVECTOR (tool_bar_items_vector
)->contents
+ ntool_bar_items
;
6814 from
= XVECTOR (tool_bar_item_properties
)->contents
;
6815 bcopy (from
, to
, TOOL_BAR_ITEM_NSLOTS
* sizeof *to
);
6816 ntool_bar_items
+= TOOL_BAR_ITEM_NSLOTS
;
6823 /* Read a character using menus based on maps in the array MAPS.
6824 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
6825 Return t if we displayed a menu but the user rejected it.
6827 PREV_EVENT is the previous input event, or nil if we are reading
6828 the first event of a key sequence.
6830 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
6831 if we used a mouse menu to read the input, or zero otherwise. If
6832 USED_MOUSE_MENU is null, we don't dereference it.
6834 The prompting is done based on the prompt-string of the map
6835 and the strings associated with various map elements.
6837 This can be done with X menus or with menus put in the minibuf.
6838 These are done in different ways, depending on how the input will be read.
6839 Menus using X are done after auto-saving in read-char, getting the input
6840 event from Fx_popup_menu; menus using the minibuf use read_char recursively
6841 and do auto-saving in the inner call of read_char. */
6844 read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
6847 Lisp_Object prev_event
;
6848 int *used_mouse_menu
;
6851 register Lisp_Object name
;
6853 if (used_mouse_menu
)
6854 *used_mouse_menu
= 0;
6856 /* Use local over global Menu maps */
6858 if (! menu_prompting
)
6861 /* Optionally disregard all but the global map. */
6862 if (inhibit_local_menu_bar_menus
)
6864 maps
+= (nmaps
- 1);
6868 /* Get the menu name from the first map that has one (a prompt string). */
6869 for (mapno
= 0; mapno
< nmaps
; mapno
++)
6871 name
= map_prompt (maps
[mapno
]);
6876 /* If we don't have any menus, just read a character normally. */
6881 /* If we got to this point via a mouse click,
6882 use a real menu for mouse selection. */
6883 if (EVENT_HAS_PARAMETERS (prev_event
)
6884 && !EQ (XCAR (prev_event
), Qmenu_bar
)
6885 && !EQ (XCAR (prev_event
), Qtool_bar
))
6887 /* Display the menu and get the selection. */
6888 Lisp_Object
*realmaps
6889 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
6893 /* Use the maps that are not nil. */
6894 for (mapno
= 0; mapno
< nmaps
; mapno
++)
6895 if (!NILP (maps
[mapno
]))
6896 realmaps
[nmaps1
++] = maps
[mapno
];
6898 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
6903 record_menu_key (XCAR (value
));
6905 /* If we got multiple events, unread all but
6907 There is no way to prevent those unread events
6908 from showing up later in last_nonmenu_event.
6909 So turn symbol and integer events into lists,
6910 to indicate that they came from a mouse menu,
6911 so that when present in last_nonmenu_event
6912 they won't confuse things. */
6913 for (tem
= XCDR (value
); !NILP (tem
);
6916 record_menu_key (XCAR (tem
));
6917 if (SYMBOLP (XCAR (tem
))
6918 || INTEGERP (XCAR (tem
)))
6920 = Fcons (XCAR (tem
), Qnil
);
6923 /* If we got more than one event, put all but the first
6924 onto this list to be read later.
6925 Return just the first event now. */
6926 Vunread_command_events
6927 = nconc2 (XCDR (value
), Vunread_command_events
);
6928 value
= XCAR (value
);
6930 else if (NILP (value
))
6932 if (used_mouse_menu
)
6933 *used_mouse_menu
= 1;
6936 #endif /* HAVE_MENUS */
6940 /* Buffer in use so far for the minibuf prompts for menu keymaps.
6941 We make this bigger when necessary, and never free it. */
6942 static char *read_char_minibuf_menu_text
;
6943 /* Size of that buffer. */
6944 static int read_char_minibuf_menu_width
;
6947 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
6953 register Lisp_Object name
;
6955 int width
= FRAME_WIDTH (SELECTED_FRAME ()) - 4;
6958 Lisp_Object rest
, vector
;
6961 if (! menu_prompting
)
6964 /* Make sure we have a big enough buffer for the menu text. */
6965 if (read_char_minibuf_menu_text
== 0)
6967 read_char_minibuf_menu_width
= width
+ 4;
6968 read_char_minibuf_menu_text
= (char *) xmalloc (width
+ 4);
6970 else if (width
+ 4 > read_char_minibuf_menu_width
)
6972 read_char_minibuf_menu_width
= width
+ 4;
6973 read_char_minibuf_menu_text
6974 = (char *) xrealloc (read_char_minibuf_menu_text
, width
+ 4);
6976 menu
= read_char_minibuf_menu_text
;
6978 /* Get the menu name from the first map that has one (a prompt string). */
6979 for (mapno
= 0; mapno
< nmaps
; mapno
++)
6981 name
= map_prompt (maps
[mapno
]);
6986 /* If we don't have any menus, just read a character normally. */
6990 /* Prompt string always starts with map's prompt, and a space. */
6991 strcpy (menu
, XSTRING (name
)->data
);
6992 nlength
= STRING_BYTES (XSTRING (name
));
6993 menu
[nlength
++] = ':';
6994 menu
[nlength
++] = ' ';
6997 /* Start prompting at start of first map. */
7001 /* Present the documented bindings, a line at a time. */
7008 Lisp_Object orig_defn_macro
;
7010 /* Loop over elements of map. */
7015 /* If reached end of map, start at beginning of next map. */
7019 /* At end of last map, wrap around to first map if just starting,
7020 or end this line if already have something on it. */
7024 if (notfirst
|| nobindings
) break;
7029 /* Look at the next element of the map. */
7031 elt
= XVECTOR (vector
)->contents
[idx
];
7033 elt
= Fcar_safe (rest
);
7035 if (idx
< 0 && VECTORP (elt
))
7037 /* If we found a dense table in the keymap,
7038 advanced past it, but start scanning its contents. */
7039 rest
= Fcdr_safe (rest
);
7045 /* An ordinary element. */
7046 Lisp_Object event
, tem
;
7050 event
= Fcar_safe (elt
); /* alist */
7051 elt
= Fcdr_safe (elt
);
7055 XSETINT (event
, idx
); /* vector */
7058 /* Ignore the element if it has no prompt string. */
7059 if (INTEGERP (event
) && parse_menu_item (elt
, 0, -1))
7061 /* 1 if the char to type matches the string. */
7063 Lisp_Object upcased_event
, downcased_event
;
7066 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
7068 upcased_event
= Fupcase (event
);
7069 downcased_event
= Fdowncase (event
);
7070 char_matches
= (XINT (upcased_event
) == XSTRING (s
)->data
[0]
7071 || XINT (downcased_event
) == XSTRING (s
)->data
[0]);
7073 desc
= Fsingle_key_description (event
);
7076 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
7078 /* Insert equivalent keybinding. */
7079 s
= concat2 (s
, tem
);
7082 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_TYPE
];
7083 if (EQ (tem
, QCradio
) || EQ (tem
, QCtoggle
))
7085 /* Insert button prefix. */
7086 Lisp_Object selected
7087 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
];
7088 if (EQ (tem
, QCradio
))
7089 tem
= build_string (NILP (selected
) ? "(*) " : "( ) ");
7091 tem
= build_string (NILP (selected
) ? "[X] " : "[ ] ");
7092 s
= concat2 (tem
, s
);
7096 /* If we have room for the prompt string, add it to this line.
7097 If this is the first on the line, always add it. */
7098 if ((XSTRING (s
)->size
+ i
+ 2
7099 + (char_matches
? 0 : XSTRING (desc
)->size
+ 3))
7105 /* Punctuate between strings. */
7108 strcpy (menu
+ i
, ", ");
7114 /* If the char to type doesn't match the string's
7115 first char, explicitly show what char to type. */
7118 /* Add as much of string as fits. */
7119 thiswidth
= XSTRING (desc
)->size
;
7120 if (thiswidth
+ i
> width
)
7121 thiswidth
= width
- i
;
7122 bcopy (XSTRING (desc
)->data
, menu
+ i
, thiswidth
);
7124 strcpy (menu
+ i
, " = ");
7128 /* Add as much of string as fits. */
7129 thiswidth
= XSTRING (s
)->size
;
7130 if (thiswidth
+ i
> width
)
7131 thiswidth
= width
- i
;
7132 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
7138 /* If this element does not fit, end the line now,
7139 and save the element for the next line. */
7140 strcpy (menu
+ i
, "...");
7145 /* Move past this element. */
7146 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
7147 /* Handle reaching end of dense table. */
7152 rest
= Fcdr_safe (rest
);
7156 /* Prompt with that and read response. */
7157 message2_nolog (menu
, strlen (menu
),
7158 ! NILP (current_buffer
->enable_multibyte_characters
));
7160 /* Make believe its not a keyboard macro in case the help char
7161 is pressed. Help characters are not recorded because menu prompting
7162 is not used on replay.
7164 orig_defn_macro
= current_kboard
->defining_kbd_macro
;
7165 current_kboard
->defining_kbd_macro
= Qnil
;
7167 obj
= read_char (commandflag
, 0, 0, Qnil
, 0);
7168 while (BUFFERP (obj
));
7169 current_kboard
->defining_kbd_macro
= orig_defn_macro
;
7171 if (!INTEGERP (obj
))
7176 if (! EQ (obj
, menu_prompt_more_char
)
7177 && (!INTEGERP (menu_prompt_more_char
)
7178 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
7180 if (!NILP (current_kboard
->defining_kbd_macro
))
7181 store_kbd_macro_char (obj
);
7184 /* Help char - go round again */
7188 /* Reading key sequences. */
7190 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
7191 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
7192 keymap, or nil otherwise. Return the index of the first keymap in
7193 which KEY has any binding, or NMAPS if no map has a binding.
7195 If KEY is a meta ASCII character, treat it like meta-prefix-char
7196 followed by the corresponding non-meta character. Keymaps in
7197 CURRENT with non-prefix bindings for meta-prefix-char become nil in
7200 If KEY has no bindings in any of the CURRENT maps, NEXT is left
7203 NEXT may be the same array as CURRENT. */
7206 follow_key (key
, nmaps
, current
, defs
, next
)
7208 Lisp_Object
*current
, *defs
, *next
;
7211 int i
, first_binding
;
7214 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
7215 followed by the corresponding non-meta character.
7216 Put the results into DEFS, since we are going to alter that anyway.
7217 Do not alter CURRENT or NEXT. */
7218 if (INTEGERP (key
) && (XINT (key
) & CHAR_META
))
7220 for (i
= 0; i
< nmaps
; i
++)
7221 if (! NILP (current
[i
]))
7224 def
= get_keyelt (access_keymap (current
[i
],
7225 meta_prefix_char
, 1, 0), 0);
7227 /* Note that since we pass the resulting bindings through
7228 get_keymap_1, non-prefix bindings for meta-prefix-char
7230 defs
[i
] = get_keymap_1 (def
, 0, 1);
7236 XSETINT (key
, XFASTINT (key
) & ~CHAR_META
);
7239 first_binding
= nmaps
;
7240 for (i
= nmaps
- 1; i
>= 0; i
--)
7242 if (! NILP (current
[i
]))
7250 defs
[i
] = get_keyelt (access_keymap (map
, key
, 1, 0), 0);
7251 if (! NILP (defs
[i
]))
7258 /* Given the set of bindings we've found, produce the next set of maps. */
7259 if (first_binding
< nmaps
)
7260 for (i
= 0; i
< nmaps
; i
++)
7261 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0, 1);
7263 return first_binding
;
7266 /* Read a sequence of keys that ends with a non prefix character,
7267 storing it in KEYBUF, a buffer of size BUFSIZE.
7269 Return the length of the key sequence stored.
7270 Return -1 if the user rejected a command menu.
7272 Echo starting immediately unless `prompt' is 0.
7274 Where a key sequence ends depends on the currently active keymaps.
7275 These include any minor mode keymaps active in the current buffer,
7276 the current buffer's local map, and the global map.
7278 If a key sequence has no other bindings, we check Vfunction_key_map
7279 to see if some trailing subsequence might be the beginning of a
7280 function key's sequence. If so, we try to read the whole function
7281 key, and substitute its symbolic name into the key sequence.
7283 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
7284 `double-' events into similar click events, if that would make them
7285 bound. We try to turn `triple-' events first into `double-' events,
7288 If we get a mouse click in a mode line, vertical divider, or other
7289 non-text area, we treat the click as if it were prefixed by the
7290 symbol denoting that area - `mode-line', `vertical-line', or
7293 If the sequence starts with a mouse click, we read the key sequence
7294 with respect to the buffer clicked on, not the current buffer.
7296 If the user switches frames in the midst of a key sequence, we put
7297 off the switch-frame event until later; the next call to
7298 read_char will return it.
7300 If FIX_CURRENT_BUFFER is nonzero, we restore current_buffer
7301 from the selected window's buffer. */
7304 read_key_sequence (keybuf
, bufsize
, prompt
, dont_downcase_last
,
7305 can_return_switch_frame
, fix_current_buffer
)
7306 Lisp_Object
*keybuf
;
7309 int dont_downcase_last
;
7310 int can_return_switch_frame
;
7311 int fix_current_buffer
;
7313 int count
= specpdl_ptr
- specpdl
;
7315 /* How many keys there are in the current key sequence. */
7318 /* The length of the echo buffer when we started reading, and
7319 the length of this_command_keys when we started reading. */
7323 /* The number of keymaps we're scanning right now, and the number of
7324 keymaps we have allocated space for. */
7326 int nmaps_allocated
= 0;
7328 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
7329 the current keymaps. */
7332 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
7333 in the current keymaps, or nil where it is not a prefix. */
7334 Lisp_Object
*submaps
;
7336 /* The local map to start out with at start of key sequence. */
7337 Lisp_Object orig_local_map
;
7339 /* 1 if we have already considered switching to the local-map property
7340 of the place where a mouse click occurred. */
7341 int localized_local_map
= 0;
7343 /* The index in defs[] of the first keymap that has a binding for
7344 this key sequence. In other words, the lowest i such that
7345 defs[i] is non-nil. */
7348 /* If t < mock_input, then KEYBUF[t] should be read as the next
7351 We use this to recover after recognizing a function key. Once we
7352 realize that a suffix of the current key sequence is actually a
7353 function key's escape sequence, we replace the suffix with the
7354 function key's binding from Vfunction_key_map. Now keybuf
7355 contains a new and different key sequence, so the echo area,
7356 this_command_keys, and the submaps and defs arrays are wrong. In
7357 this situation, we set mock_input to t, set t to 0, and jump to
7358 restart_sequence; the loop will read keys from keybuf up until
7359 mock_input, thus rebuilding the state; and then it will resume
7360 reading characters from the keyboard. */
7363 /* If the sequence is unbound in submaps[], then
7364 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
7365 and fkey_map is its binding.
7367 These might be > t, indicating that all function key scanning
7368 should hold off until t reaches them. We do this when we've just
7369 recognized a function key, to avoid searching for the function
7370 key's again in Vfunction_key_map. */
7371 int fkey_start
= 0, fkey_end
= 0;
7372 Lisp_Object fkey_map
;
7374 /* Likewise, for key_translation_map. */
7375 int keytran_start
= 0, keytran_end
= 0;
7376 Lisp_Object keytran_map
;
7378 /* If we receive a ``switch-frame'' event in the middle of a key sequence,
7379 we put it off for later. While we're reading, we keep the event here. */
7380 Lisp_Object delayed_switch_frame
;
7382 /* See the comment below... */
7383 #if defined (GOBBLE_FIRST_EVENT)
7384 Lisp_Object first_event
;
7387 Lisp_Object original_uppercase
;
7388 int original_uppercase_position
= -1;
7390 /* Gets around Microsoft compiler limitations. */
7393 struct buffer
*starting_buffer
;
7395 /* Nonzero if we seem to have got the beginning of a binding
7396 in function_key_map. */
7397 int function_key_possible
= 0;
7398 int key_translation_possible
= 0;
7400 /* Save the status of key translation before each step,
7401 so that we can restore this after downcasing. */
7402 Lisp_Object prev_fkey_map
;
7403 int prev_fkey_start
;
7406 Lisp_Object prev_keytran_map
;
7407 int prev_keytran_start
;
7408 int prev_keytran_end
;
7410 #if defined (GOBBLE_FIRST_EVENT)
7414 raw_keybuf_count
= 0;
7416 last_nonmenu_event
= Qnil
;
7418 delayed_switch_frame
= Qnil
;
7419 fkey_map
= Vfunction_key_map
;
7420 keytran_map
= Vkey_translation_map
;
7422 /* If there is no function-key-map, turn off function key scanning. */
7423 if (NILP (Fkeymapp (Vfunction_key_map
)))
7424 fkey_start
= fkey_end
= bufsize
+ 1;
7426 /* If there is no key-translation-map, turn off scanning. */
7427 if (NILP (Fkeymapp (Vkey_translation_map
)))
7428 keytran_start
= keytran_end
= bufsize
+ 1;
7433 echo_prompt (XSTRING (prompt
)->data
);
7434 else if (cursor_in_echo_area
&& echo_keystrokes
)
7435 /* This doesn't put in a dash if the echo buffer is empty, so
7436 you don't always see a dash hanging out in the minibuffer. */
7440 /* Record the initial state of the echo area and this_command_keys;
7441 we will need to restore them if we replay a key sequence. */
7443 echo_start
= echo_length ();
7444 keys_start
= this_command_key_count
;
7445 this_single_command_key_start
= keys_start
;
7447 #if defined (GOBBLE_FIRST_EVENT)
7448 /* This doesn't quite work, because some of the things that read_char
7449 does cannot safely be bypassed. It seems too risky to try to make
7452 /* Read the first char of the sequence specially, before setting
7453 up any keymaps, in case a filter runs and switches buffers on us. */
7454 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
7456 #endif /* GOBBLE_FIRST_EVENT */
7458 orig_local_map
= get_local_map (PT
, current_buffer
);
7460 /* We jump here when the key sequence has been thoroughly changed, and
7461 we need to rescan it starting from the beginning. When we jump here,
7462 keybuf[0..mock_input] holds the sequence we should reread. */
7465 starting_buffer
= current_buffer
;
7466 function_key_possible
= 0;
7467 key_translation_possible
= 0;
7469 /* Build our list of keymaps.
7470 If we recognize a function key and replace its escape sequence in
7471 keybuf with its symbol, or if the sequence starts with a mouse
7472 click and we need to switch buffers, we jump back here to rebuild
7473 the initial keymaps from the current buffer. */
7477 if (!NILP (current_kboard
->Voverriding_terminal_local_map
)
7478 || !NILP (Voverriding_local_map
))
7480 if (3 > nmaps_allocated
)
7482 submaps
= (Lisp_Object
*) alloca (3 * sizeof (submaps
[0]));
7483 defs
= (Lisp_Object
*) alloca (3 * sizeof (defs
[0]));
7484 nmaps_allocated
= 3;
7487 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
7488 submaps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
7489 if (!NILP (Voverriding_local_map
))
7490 submaps
[nmaps
++] = Voverriding_local_map
;
7494 nmaps
= current_minor_maps (0, &maps
);
7495 if (nmaps
+ 2 > nmaps_allocated
)
7497 submaps
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (submaps
[0]));
7498 defs
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (defs
[0]));
7499 nmaps_allocated
= nmaps
+ 2;
7501 bcopy (maps
, submaps
, nmaps
* sizeof (submaps
[0]));
7502 submaps
[nmaps
++] = orig_local_map
;
7504 submaps
[nmaps
++] = current_global_map
;
7507 /* Find an accurate initial value for first_binding. */
7508 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
7509 if (! NILP (submaps
[first_binding
]))
7512 /* Start from the beginning in keybuf. */
7515 /* These are no-ops the first time through, but if we restart, they
7516 revert the echo area and this_command_keys to their original state. */
7517 this_command_key_count
= keys_start
;
7518 if (INTERACTIVE
&& t
< mock_input
)
7519 echo_truncate (echo_start
);
7521 /* If the best binding for the current key sequence is a keymap, or
7522 we may be looking at a function key's escape sequence, keep on
7524 while ((first_binding
< nmaps
&& ! NILP (submaps
[first_binding
]))
7525 || (first_binding
>= nmaps
7527 /* mock input is never part of a function key's sequence. */
7528 && mock_input
<= fkey_start
)
7529 || (first_binding
>= nmaps
7530 && keytran_start
< t
&& key_translation_possible
)
7531 /* Don't return in the middle of a possible function key sequence,
7532 if the only bindings we found were via case conversion.
7533 Thus, if ESC O a has a function-key-map translation
7534 and ESC o has a binding, don't return after ESC O,
7535 so that we can translate ESC O plus the next character. */
7539 int used_mouse_menu
= 0;
7541 /* Where the last real key started. If we need to throw away a
7542 key that has expanded into more than one element of keybuf
7543 (say, a mouse click on the mode line which is being treated
7544 as [mode-line (mouse-...)], then we backtrack to this point
7546 int last_real_key_start
;
7548 /* These variables are analogous to echo_start and keys_start;
7549 while those allow us to restart the entire key sequence,
7550 echo_local_start and keys_local_start allow us to throw away
7552 int echo_local_start
, keys_local_start
, local_first_binding
;
7555 error ("Key sequence too long");
7558 echo_local_start
= echo_length ();
7559 keys_local_start
= this_command_key_count
;
7560 local_first_binding
= first_binding
;
7563 /* These are no-ops, unless we throw away a keystroke below and
7564 jumped back up to replay_key; in that case, these restore the
7565 variables to their original state, allowing us to replay the
7567 if (INTERACTIVE
&& t
< mock_input
)
7568 echo_truncate (echo_local_start
);
7569 this_command_key_count
= keys_local_start
;
7570 first_binding
= local_first_binding
;
7572 /* By default, assume each event is "real". */
7573 last_real_key_start
= t
;
7575 /* Does mock_input indicate that we are re-reading a key sequence? */
7579 add_command_key (key
);
7580 if (echo_keystrokes
)
7584 /* If not, we should actually read a character. */
7589 KBOARD
*interrupted_kboard
= current_kboard
;
7590 struct frame
*interrupted_frame
= SELECTED_FRAME ();
7591 if (setjmp (wrong_kboard_jmpbuf
))
7593 if (!NILP (delayed_switch_frame
))
7595 interrupted_kboard
->kbd_queue
7596 = Fcons (delayed_switch_frame
,
7597 interrupted_kboard
->kbd_queue
);
7598 delayed_switch_frame
= Qnil
;
7601 interrupted_kboard
->kbd_queue
7602 = Fcons (keybuf
[--t
], interrupted_kboard
->kbd_queue
);
7604 /* If the side queue is non-empty, ensure it begins with a
7605 switch-frame, so we'll replay it in the right context. */
7606 if (CONSP (interrupted_kboard
->kbd_queue
)
7607 && (key
= XCAR (interrupted_kboard
->kbd_queue
),
7608 !(EVENT_HAS_PARAMETERS (key
)
7609 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)),
7613 XSETFRAME (frame
, interrupted_frame
);
7614 interrupted_kboard
->kbd_queue
7615 = Fcons (make_lispy_switch_frame (frame
),
7616 interrupted_kboard
->kbd_queue
);
7619 orig_local_map
= get_local_map (PT
, current_buffer
);
7620 goto replay_sequence
;
7623 key
= read_char (NILP (prompt
), nmaps
, submaps
, last_nonmenu_event
,
7627 /* read_char returns t when it shows a menu and the user rejects it.
7631 unbind_to (count
, Qnil
);
7635 /* read_char returns -1 at the end of a macro.
7636 Emacs 18 handles this by returning immediately with a
7637 zero, so that's what we'll do. */
7638 if (INTEGERP (key
) && XINT (key
) == -1)
7641 /* The Microsoft C compiler can't handle the goto that
7647 /* If the current buffer has been changed from under us, the
7648 keymap may have changed, so replay the sequence. */
7652 /* Reset the current buffer from the selected window
7653 in case something changed the former and not the latter.
7654 This is to be more consistent with the behavior
7655 of the command_loop_1. */
7656 if (fix_current_buffer
)
7658 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7660 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
7661 Fset_buffer (XWINDOW (selected_window
)->buffer
);
7664 orig_local_map
= get_local_map (PT
, current_buffer
);
7665 goto replay_sequence
;
7668 /* If we have a quit that was typed in another frame, and
7669 quit_throw_to_read_char switched buffers,
7670 replay to get the right keymap. */
7671 if (XINT (key
) == quit_char
&& current_buffer
!= starting_buffer
)
7674 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
7678 orig_local_map
= get_local_map (PT
, current_buffer
);
7679 goto replay_sequence
;
7684 if (EVENT_HAS_PARAMETERS (key
)
7685 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)), Qswitch_frame
))
7687 /* If we're at the beginning of a key sequence, and the caller
7688 says it's okay, go ahead and return this event. If we're
7689 in the midst of a key sequence, delay it until the end. */
7690 if (t
> 0 || !can_return_switch_frame
)
7692 delayed_switch_frame
= key
;
7698 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
7701 /* Clicks in non-text areas get prefixed by the symbol
7702 in their CHAR-ADDRESS field. For example, a click on
7703 the mode line is prefixed by the symbol `mode-line'.
7705 Furthermore, key sequences beginning with mouse clicks
7706 are read using the keymaps of the buffer clicked on, not
7707 the current buffer. So we may have to switch the buffer
7710 When we turn one event into two events, we must make sure
7711 that neither of the two looks like the original--so that,
7712 if we replay the events, they won't be expanded again.
7713 If not for this, such reexpansion could happen either here
7714 or when user programs play with this-command-keys. */
7715 if (EVENT_HAS_PARAMETERS (key
))
7719 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
7720 if (EQ (kind
, Qmouse_click
))
7722 Lisp_Object window
, posn
;
7724 window
= POSN_WINDOW (EVENT_START (key
));
7725 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
7729 /* We're looking at the second event of a
7730 sequence which we expanded before. Set
7731 last_real_key_start appropriately. */
7733 last_real_key_start
= t
- 1;
7736 /* Key sequences beginning with mouse clicks are
7737 read using the keymaps in the buffer clicked on,
7738 not the current buffer. If we're at the
7739 beginning of a key sequence, switch buffers. */
7740 if (last_real_key_start
== 0
7742 && BUFFERP (XWINDOW (window
)->buffer
)
7743 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
7745 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
7749 /* Arrange to go back to the original buffer once we're
7750 done reading the key sequence. Note that we can't
7751 use save_excursion_{save,restore} here, because they
7752 save point as well as the current buffer; we don't
7753 want to save point, because redisplay may change it,
7754 to accommodate a Fset_window_start or something. We
7755 don't want to do this at the top of the function,
7756 because we may get input from a subprocess which
7757 wants to change the selected window and stuff (say,
7759 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
7761 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7763 set_buffer_internal (XBUFFER (XWINDOW (window
)->buffer
));
7764 orig_local_map
= get_local_map (PT
, current_buffer
);
7765 goto replay_sequence
;
7768 /* For a mouse click, get the local text-property keymap
7769 of the place clicked on, rather than point. */
7770 if (last_real_key_start
== 0
7771 && CONSP (XCDR (key
))
7772 && ! localized_local_map
)
7774 Lisp_Object map_here
, start
, pos
;
7776 localized_local_map
= 1;
7777 start
= EVENT_START (key
);
7779 if (CONSP (start
) && CONSP (XCDR (start
)))
7781 pos
= POSN_BUFFER_POSN (start
);
7783 && XINT (pos
) >= BEG
&& XINT (pos
) <= Z
)
7785 map_here
= get_local_map (XINT (pos
), current_buffer
);
7786 if (!EQ (map_here
, orig_local_map
))
7788 orig_local_map
= map_here
;
7792 goto replay_sequence
;
7798 /* Expand mode-line and scroll-bar events into two events:
7799 use posn as a fake prefix key. */
7802 if (t
+ 1 >= bufsize
)
7803 error ("Key sequence too long");
7808 /* Zap the position in key, so we know that we've
7809 expanded it, and don't try to do so again. */
7810 POSN_BUFFER_POSN (EVENT_START (key
))
7811 = Fcons (posn
, Qnil
);
7813 /* If on a mode line string with a local keymap,
7814 reconsider the key sequence with that keymap. */
7815 if (CONSP (POSN_STRING (EVENT_START (key
))))
7817 Lisp_Object string
, pos
, map
;
7819 string
= POSN_STRING (EVENT_START (key
));
7820 pos
= XCDR (string
);
7821 string
= XCAR (string
);
7824 && pos
< XSTRING (string
)->size
7825 && (map
= Fget_text_property (pos
, Qlocal_map
,
7829 orig_local_map
= map
;
7830 goto replay_sequence
;
7837 else if (CONSP (XCDR (key
))
7838 && CONSP (EVENT_START (key
))
7839 && CONSP (XCDR (EVENT_START (key
))))
7843 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
7844 /* Handle menu-bar events:
7845 insert the dummy prefix event `menu-bar'. */
7846 if (EQ (posn
, Qmenu_bar
) || EQ (posn
, Qtool_bar
))
7848 if (t
+ 1 >= bufsize
)
7849 error ("Key sequence too long");
7853 /* Zap the position in key, so we know that we've
7854 expanded it, and don't try to do so again. */
7855 POSN_BUFFER_POSN (EVENT_START (key
))
7856 = Fcons (posn
, Qnil
);
7859 goto replay_sequence
;
7861 else if (CONSP (posn
))
7863 /* We're looking at the second event of a
7864 sequence which we expanded before. Set
7865 last_real_key_start appropriately. */
7866 if (last_real_key_start
== t
&& t
> 0)
7867 last_real_key_start
= t
- 1;
7872 /* We have finally decided that KEY is something we might want
7874 first_binding
= (follow_key (key
,
7875 nmaps
- first_binding
,
7876 submaps
+ first_binding
,
7877 defs
+ first_binding
,
7878 submaps
+ first_binding
)
7881 /* If KEY wasn't bound, we'll try some fallbacks. */
7882 if (first_binding
>= nmaps
)
7886 head
= EVENT_HEAD (key
);
7887 if (help_char_p (head
) && t
> 0)
7889 read_key_sequence_cmd
= Vprefix_help_command
;
7891 last_nonmenu_event
= key
;
7892 /* The Microsoft C compiler can't handle the goto that
7900 Lisp_Object breakdown
;
7903 breakdown
= parse_modifiers (head
);
7904 modifiers
= XINT (XCAR (XCDR (breakdown
)));
7905 /* Attempt to reduce an unbound mouse event to a simpler
7906 event that is bound:
7907 Drags reduce to clicks.
7908 Double-clicks reduce to clicks.
7909 Triple-clicks reduce to double-clicks, then to clicks.
7910 Down-clicks are eliminated.
7911 Double-downs reduce to downs, then are eliminated.
7912 Triple-downs reduce to double-downs, then to downs,
7913 then are eliminated. */
7914 if (modifiers
& (down_modifier
| drag_modifier
7915 | double_modifier
| triple_modifier
))
7917 while (modifiers
& (down_modifier
| drag_modifier
7918 | double_modifier
| triple_modifier
))
7920 Lisp_Object new_head
, new_click
;
7921 if (modifiers
& triple_modifier
)
7922 modifiers
^= (double_modifier
| triple_modifier
);
7923 else if (modifiers
& double_modifier
)
7924 modifiers
&= ~double_modifier
;
7925 else if (modifiers
& drag_modifier
)
7926 modifiers
&= ~drag_modifier
;
7929 /* Dispose of this `down' event by simply jumping
7930 back to replay_key, to get another event.
7932 Note that if this event came from mock input,
7933 then just jumping back to replay_key will just
7934 hand it to us again. So we have to wipe out any
7937 We could delete keybuf[t] and shift everything
7938 after that to the left by one spot, but we'd also
7939 have to fix up any variable that points into
7940 keybuf, and shifting isn't really necessary
7943 Adding prefixes for non-textual mouse clicks
7944 creates two characters of mock input, and both
7945 must be thrown away. If we're only looking at
7946 the prefix now, we can just jump back to
7947 replay_key. On the other hand, if we've already
7948 processed the prefix, and now the actual click
7949 itself is giving us trouble, then we've lost the
7950 state of the keymaps we want to backtrack to, and
7951 we need to replay the whole sequence to rebuild
7954 Beyond that, only function key expansion could
7955 create more than two keys, but that should never
7956 generate mouse events, so it's okay to zero
7957 mock_input in that case too.
7959 Isn't this just the most wonderful code ever? */
7960 if (t
== last_real_key_start
)
7967 mock_input
= last_real_key_start
;
7968 goto replay_sequence
;
7973 = apply_modifiers (modifiers
, XCAR (breakdown
));
7975 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
7977 /* Look for a binding for this new key. follow_key
7978 promises that it didn't munge submaps the
7979 last time we called it, since key was unbound. */
7981 = (follow_key (new_click
,
7982 nmaps
- local_first_binding
,
7983 submaps
+ local_first_binding
,
7984 defs
+ local_first_binding
,
7985 submaps
+ local_first_binding
)
7986 + local_first_binding
);
7988 /* If that click is bound, go for it. */
7989 if (first_binding
< nmaps
)
7994 /* Otherwise, we'll leave key set to the drag event. */
8001 /* Normally, last_nonmenu_event gets the previous key we read.
8002 But when a mouse popup menu is being used,
8003 we don't update last_nonmenu_event; it continues to hold the mouse
8004 event that preceded the first level of menu. */
8005 if (!used_mouse_menu
)
8006 last_nonmenu_event
= key
;
8008 /* Record what part of this_command_keys is the current key sequence. */
8009 this_single_command_key_start
= this_command_key_count
- t
;
8011 prev_fkey_map
= fkey_map
;
8012 prev_fkey_start
= fkey_start
;
8013 prev_fkey_end
= fkey_end
;
8015 prev_keytran_map
= keytran_map
;
8016 prev_keytran_start
= keytran_start
;
8017 prev_keytran_end
= keytran_end
;
8019 /* If the sequence is unbound, see if we can hang a function key
8020 off the end of it. We only want to scan real keyboard input
8021 for function key sequences, so if mock_input says that we're
8022 re-reading old events, don't examine it. */
8023 if (first_binding
>= nmaps
8026 Lisp_Object fkey_next
;
8028 /* Continue scan from fkey_end until we find a bound suffix.
8029 If we fail, increment fkey_start
8030 and start fkey_end from there. */
8031 while (fkey_end
< t
)
8035 key
= keybuf
[fkey_end
++];
8036 /* Look up meta-characters by prefixing them
8037 with meta_prefix_char. I hate this. */
8038 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
8043 (access_keymap (fkey_map
, meta_prefix_char
, 1, 0), 0),
8045 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
8048 fkey_next
= fkey_map
;
8051 = get_keyelt (access_keymap (fkey_next
, key
, 1, 0), 1);
8053 /* Handle symbol with autoload definition. */
8054 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
8055 && CONSP (XSYMBOL (fkey_next
)->function
)
8056 && EQ (XCAR (XSYMBOL (fkey_next
)->function
), Qautoload
))
8057 do_autoload (XSYMBOL (fkey_next
)->function
,
8060 /* Handle a symbol whose function definition is a keymap
8062 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
8063 && (!NILP (Farrayp (XSYMBOL (fkey_next
)->function
))
8064 || !NILP (Fkeymapp (XSYMBOL (fkey_next
)->function
))))
8065 fkey_next
= XSYMBOL (fkey_next
)->function
;
8067 #if 0 /* I didn't turn this on, because it might cause trouble
8068 for the mapping of return into C-m and tab into C-i. */
8069 /* Optionally don't map function keys into other things.
8070 This enables the user to redefine kp- keys easily. */
8071 if (SYMBOLP (key
) && !NILP (Vinhibit_function_key_mapping
))
8075 /* If the function key map gives a function, not an
8076 array, then call the function with no args and use
8077 its value instead. */
8078 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
8081 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8085 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
8086 fkey_next
= call1 (fkey_next
, prompt
);
8088 /* If the function returned something invalid,
8089 barf--don't ignore it.
8090 (To ignore it safely, we would need to gcpro a bunch of
8091 other variables.) */
8092 if (! (VECTORP (fkey_next
) || STRINGP (fkey_next
)))
8093 error ("Function in key-translation-map returns invalid key sequence");
8096 function_key_possible
= ! NILP (fkey_next
);
8098 /* If keybuf[fkey_start..fkey_end] is bound in the
8099 function key map and it's a suffix of the current
8100 sequence (i.e. fkey_end == t), replace it with
8101 the binding and restart with fkey_start at the end. */
8102 if ((VECTORP (fkey_next
) || STRINGP (fkey_next
))
8105 int len
= XFASTINT (Flength (fkey_next
));
8107 t
= fkey_start
+ len
;
8109 error ("Key sequence too long");
8111 if (VECTORP (fkey_next
))
8112 bcopy (XVECTOR (fkey_next
)->contents
,
8113 keybuf
+ fkey_start
,
8114 (t
- fkey_start
) * sizeof (keybuf
[0]));
8115 else if (STRINGP (fkey_next
))
8119 for (i
= 0; i
< len
; i
++)
8120 XSETFASTINT (keybuf
[fkey_start
+ i
],
8121 XSTRING (fkey_next
)->data
[i
]);
8125 fkey_start
= fkey_end
= t
;
8126 fkey_map
= Vfunction_key_map
;
8128 /* Do pass the results through key-translation-map.
8129 But don't retranslate what key-translation-map
8130 has already translated. */
8131 keytran_end
= keytran_start
;
8132 keytran_map
= Vkey_translation_map
;
8134 goto replay_sequence
;
8137 fkey_map
= get_keymap_1 (fkey_next
, 0, 1);
8139 /* If we no longer have a bound suffix, try a new positions for
8141 if (NILP (fkey_map
))
8143 fkey_end
= ++fkey_start
;
8144 fkey_map
= Vfunction_key_map
;
8145 function_key_possible
= 0;
8150 /* Look for this sequence in key-translation-map. */
8152 Lisp_Object keytran_next
;
8154 /* Scan from keytran_end until we find a bound suffix. */
8155 while (keytran_end
< t
)
8159 key
= keybuf
[keytran_end
++];
8160 /* Look up meta-characters by prefixing them
8161 with meta_prefix_char. I hate this. */
8162 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
8167 (access_keymap (keytran_map
, meta_prefix_char
, 1, 0), 0),
8169 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
8172 keytran_next
= keytran_map
;
8175 = get_keyelt (access_keymap (keytran_next
, key
, 1, 0), 1);
8177 /* Handle symbol with autoload definition. */
8178 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
8179 && CONSP (XSYMBOL (keytran_next
)->function
)
8180 && EQ (XCAR (XSYMBOL (keytran_next
)->function
), Qautoload
))
8181 do_autoload (XSYMBOL (keytran_next
)->function
,
8184 /* Handle a symbol whose function definition is a keymap
8186 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
8187 && (!NILP (Farrayp (XSYMBOL (keytran_next
)->function
))
8188 || !NILP (Fkeymapp (XSYMBOL (keytran_next
)->function
))))
8189 keytran_next
= XSYMBOL (keytran_next
)->function
;
8191 /* If the key translation map gives a function, not an
8192 array, then call the function with one arg and use
8193 its value instead. */
8194 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
8195 && keytran_end
== t
)
8197 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8201 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
8202 keytran_next
= call1 (keytran_next
, prompt
);
8204 /* If the function returned something invalid,
8205 barf--don't ignore it.
8206 (To ignore it safely, we would need to gcpro a bunch of
8207 other variables.) */
8208 if (! (VECTORP (keytran_next
) || STRINGP (keytran_next
)))
8209 error ("Function in key-translation-map returns invalid key sequence");
8212 key_translation_possible
= ! NILP (keytran_next
);
8214 /* If keybuf[keytran_start..keytran_end] is bound in the
8215 key translation map and it's a suffix of the current
8216 sequence (i.e. keytran_end == t), replace it with
8217 the binding and restart with keytran_start at the end. */
8218 if ((VECTORP (keytran_next
) || STRINGP (keytran_next
))
8219 && keytran_end
== t
)
8221 int len
= XFASTINT (Flength (keytran_next
));
8223 t
= keytran_start
+ len
;
8225 error ("Key sequence too long");
8227 if (VECTORP (keytran_next
))
8228 bcopy (XVECTOR (keytran_next
)->contents
,
8229 keybuf
+ keytran_start
,
8230 (t
- keytran_start
) * sizeof (keybuf
[0]));
8231 else if (STRINGP (keytran_next
))
8235 for (i
= 0; i
< len
; i
++)
8236 XSETFASTINT (keybuf
[keytran_start
+ i
],
8237 XSTRING (keytran_next
)->data
[i
]);
8241 keytran_start
= keytran_end
= t
;
8242 keytran_map
= Vkey_translation_map
;
8244 /* Don't pass the results of key-translation-map
8245 through function-key-map. */
8246 fkey_start
= fkey_end
= t
;
8247 fkey_map
= Vfunction_key_map
;
8249 goto replay_sequence
;
8252 keytran_map
= get_keymap_1 (keytran_next
, 0, 1);
8254 /* If we no longer have a bound suffix, try a new positions for
8256 if (NILP (keytran_map
))
8258 keytran_end
= ++keytran_start
;
8259 keytran_map
= Vkey_translation_map
;
8260 key_translation_possible
= 0;
8265 /* If KEY is not defined in any of the keymaps,
8266 and cannot be part of a function key or translation,
8267 and is an upper case letter
8268 use the corresponding lower-case letter instead. */
8269 if (first_binding
== nmaps
&& ! function_key_possible
8270 && ! key_translation_possible
8272 && ((((XINT (key
) & 0x3ffff)
8273 < XCHAR_TABLE (current_buffer
->downcase_table
)->size
)
8274 && UPPERCASEP (XINT (key
) & 0x3ffff))
8275 || (XINT (key
) & shift_modifier
)))
8277 Lisp_Object new_key
;
8279 original_uppercase
= key
;
8280 original_uppercase_position
= t
- 1;
8282 if (XINT (key
) & shift_modifier
)
8283 XSETINT (new_key
, XINT (key
) & ~shift_modifier
);
8285 XSETINT (new_key
, (DOWNCASE (XINT (key
) & 0x3ffff)
8286 | (XINT (key
) & ~0x3ffff)));
8288 /* We have to do this unconditionally, regardless of whether
8289 the lower-case char is defined in the keymaps, because they
8290 might get translated through function-key-map. */
8291 keybuf
[t
- 1] = new_key
;
8294 fkey_map
= prev_fkey_map
;
8295 fkey_start
= prev_fkey_start
;
8296 fkey_end
= prev_fkey_end
;
8298 keytran_map
= prev_keytran_map
;
8299 keytran_start
= prev_keytran_start
;
8300 keytran_end
= prev_keytran_end
;
8302 goto replay_sequence
;
8304 /* If KEY is not defined in any of the keymaps,
8305 and cannot be part of a function key or translation,
8306 and is a shifted function key,
8307 use the corresponding unshifted function key instead. */
8308 if (first_binding
== nmaps
&& ! function_key_possible
8309 && ! key_translation_possible
8312 Lisp_Object breakdown
;
8315 breakdown
= parse_modifiers (key
);
8316 modifiers
= XINT (XCAR (XCDR (breakdown
)));
8317 if (modifiers
& shift_modifier
)
8319 Lisp_Object new_key
;
8321 original_uppercase
= key
;
8322 original_uppercase_position
= t
- 1;
8324 modifiers
&= ~shift_modifier
;
8325 new_key
= apply_modifiers (modifiers
,
8328 keybuf
[t
- 1] = new_key
;
8331 fkey_map
= prev_fkey_map
;
8332 fkey_start
= prev_fkey_start
;
8333 fkey_end
= prev_fkey_end
;
8335 keytran_map
= prev_keytran_map
;
8336 keytran_start
= prev_keytran_start
;
8337 keytran_end
= prev_keytran_end
;
8339 goto replay_sequence
;
8345 read_key_sequence_cmd
= (first_binding
< nmaps
8346 ? defs
[first_binding
]
8349 unread_switch_frame
= delayed_switch_frame
;
8350 unbind_to (count
, Qnil
);
8352 /* Don't downcase the last character if the caller says don't.
8353 Don't downcase it if the result is undefined, either. */
8354 if ((dont_downcase_last
|| first_binding
>= nmaps
)
8355 && t
- 1 == original_uppercase_position
)
8356 keybuf
[t
- 1] = original_uppercase
;
8358 /* Occasionally we fabricate events, perhaps by expanding something
8359 according to function-key-map, or by adding a prefix symbol to a
8360 mouse click in the scroll bar or modeline. In this cases, return
8361 the entire generated key sequence, even if we hit an unbound
8362 prefix or a definition before the end. This means that you will
8363 be able to push back the event properly, and also means that
8364 read-key-sequence will always return a logical unit.
8367 for (; t
< mock_input
; t
++)
8369 if (echo_keystrokes
)
8370 echo_char (keybuf
[t
]);
8371 add_command_key (keybuf
[t
]);
8379 #if 0 /* This doc string is too long for some compilers.
8380 This commented-out definition serves for DOC. */
8381 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
8382 "Read a sequence of keystrokes and return as a string or vector.\n\
8383 The sequence is sufficient to specify a non-prefix command in the\n\
8384 current local and global maps.\n\
8386 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
8387 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
8388 as a continuation of the previous key.\n\
8390 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not\n\
8391 convert the last event to lower case. (Normally any upper case event\n\
8392 is converted to lower case if the original event is undefined and the lower\n\
8393 case equivalent is defined.) A non-nil value is appropriate for reading\n\
8394 a key sequence to be defined.\n\
8396 A C-g typed while in this function is treated like any other character,\n\
8397 and `quit-flag' is not set.\n\
8399 If the key sequence starts with a mouse click, then the sequence is read\n\
8400 using the keymaps of the buffer of the window clicked in, not the buffer\n\
8401 of the selected window as normal.\n\
8403 `read-key-sequence' drops unbound button-down events, since you normally\n\
8404 only care about the click or drag events which follow them. If a drag\n\
8405 or multi-click event is unbound, but the corresponding click event would\n\
8406 be bound, `read-key-sequence' turns the event into a click event at the\n\
8407 drag's starting position. This means that you don't have to distinguish\n\
8408 between click and drag, double, or triple events unless you want to.\n\
8410 `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\
8411 lines separating windows, and scroll bars with imaginary keys\n\
8412 `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\
8414 Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this\n\
8415 function will process a switch-frame event if the user switches frames\n\
8416 before typing anything. If the user switches frames in the middle of a\n\
8417 key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME\n\
8418 is nil, then the event will be put off until after the current key sequence.\n\
8420 `read-key-sequence' checks `function-key-map' for function key\n\
8421 sequences, where they wouldn't conflict with ordinary bindings. See\n\
8422 `function-key-map' for more details.\n\
8424 The optional fifth argument COMMAND-LOOP, if non-nil, means\n\
8425 that this key sequence is being read by something that will\n\
8426 read commands one after another. It should be nil if the caller\n\
8427 will read just one key sequence.")
8428 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
, command
-loop
)
8431 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 5, 0,
8433 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
8435 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
8436 Lisp_Object can_return_switch_frame
, command_loop
;
8438 Lisp_Object keybuf
[30];
8440 struct gcpro gcpro1
;
8441 int count
= specpdl_ptr
- specpdl
;
8444 CHECK_STRING (prompt
, 0);
8447 specbind (Qinput_method_exit_on_first_char
,
8448 (NILP (command_loop
) ? Qt
: Qnil
));
8449 specbind (Qinput_method_use_echo_area
,
8450 (NILP (command_loop
) ? Qt
: Qnil
));
8452 bzero (keybuf
, sizeof keybuf
);
8454 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
8456 if (NILP (continue_echo
))
8458 this_command_key_count
= 0;
8459 this_single_command_key_start
= 0;
8462 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
8463 prompt
, ! NILP (dont_downcase_last
),
8464 ! NILP (can_return_switch_frame
), 0);
8472 return unbind_to (count
, make_event_array (i
, keybuf
));
8475 DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector
,
8476 Sread_key_sequence_vector
, 1, 5, 0,
8477 "Like `read-key-sequence' but always return a vector.")
8478 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
8480 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
8481 Lisp_Object can_return_switch_frame
, command_loop
;
8483 Lisp_Object keybuf
[30];
8485 struct gcpro gcpro1
;
8486 int count
= specpdl_ptr
- specpdl
;
8489 CHECK_STRING (prompt
, 0);
8492 specbind (Qinput_method_exit_on_first_char
,
8493 (NILP (command_loop
) ? Qt
: Qnil
));
8494 specbind (Qinput_method_use_echo_area
,
8495 (NILP (command_loop
) ? Qt
: Qnil
));
8497 bzero (keybuf
, sizeof keybuf
);
8499 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
8501 if (NILP (continue_echo
))
8503 this_command_key_count
= 0;
8504 this_single_command_key_start
= 0;
8507 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
8508 prompt
, ! NILP (dont_downcase_last
),
8509 ! NILP (can_return_switch_frame
), 0);
8517 return unbind_to (count
, Fvector (i
, keybuf
));
8520 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 4, 0,
8521 "Execute CMD as an editor command.\n\
8522 CMD must be a symbol that satisfies the `commandp' predicate.\n\
8523 Optional second arg RECORD-FLAG non-nil\n\
8524 means unconditionally put this command in `command-history'.\n\
8525 Otherwise, that is done only if an arg is read using the minibuffer.\n\
8526 The argument KEYS specifies the value to use instead of (this-command-keys)\n\
8527 when reading the arguments; if it is nil, (this-command-keys) is used.\n\
8528 The argument SPECIAL, if non-nil, means that this command is executing\n\
8529 a special event, so ignore the prefix argument and don't clear it.")
8530 (cmd
, record_flag
, keys
, special
)
8531 Lisp_Object cmd
, record_flag
, keys
, special
;
8533 register Lisp_Object final
;
8534 register Lisp_Object tem
;
8535 Lisp_Object prefixarg
;
8536 struct backtrace backtrace
;
8537 extern int debug_on_next_call
;
8539 debug_on_next_call
= 0;
8543 prefixarg
= current_kboard
->Vprefix_arg
;
8544 Vcurrent_prefix_arg
= prefixarg
;
8545 current_kboard
->Vprefix_arg
= Qnil
;
8552 tem
= Fget (cmd
, Qdisabled
);
8553 if (!NILP (tem
) && !NILP (Vrun_hooks
))
8555 tem
= Fsymbol_value (Qdisabled_command_hook
);
8557 return call1 (Vrun_hooks
, Qdisabled_command_hook
);
8563 final
= Findirect_function (cmd
);
8565 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
8567 struct gcpro gcpro1
, gcpro2
;
8569 GCPRO2 (cmd
, prefixarg
);
8570 do_autoload (final
, cmd
);
8577 if (STRINGP (final
) || VECTORP (final
))
8579 /* If requested, place the macro in the command history. For
8580 other sorts of commands, call-interactively takes care of
8582 if (!NILP (record_flag
))
8585 = Fcons (Fcons (Qexecute_kbd_macro
,
8586 Fcons (final
, Fcons (prefixarg
, Qnil
))),
8589 /* Don't keep command history around forever. */
8590 if (NUMBERP (Vhistory_length
) && XINT (Vhistory_length
) > 0)
8592 tem
= Fnthcdr (Vhistory_length
, Vcommand_history
);
8598 return Fexecute_kbd_macro (final
, prefixarg
);
8601 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
8603 backtrace
.next
= backtrace_list
;
8604 backtrace_list
= &backtrace
;
8605 backtrace
.function
= &Qcall_interactively
;
8606 backtrace
.args
= &cmd
;
8607 backtrace
.nargs
= 1;
8608 backtrace
.evalargs
= 0;
8610 tem
= Fcall_interactively (cmd
, record_flag
, keys
);
8612 backtrace_list
= backtrace
.next
;
8618 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
8620 "Read function name, then read its arguments and call it.")
8622 Lisp_Object prefixarg
;
8624 Lisp_Object function
;
8626 Lisp_Object saved_keys
;
8627 Lisp_Object bindings
, value
;
8628 struct gcpro gcpro1
, gcpro2
;
8630 saved_keys
= Fvector (this_command_key_count
,
8631 XVECTOR (this_command_keys
)->contents
);
8633 GCPRO2 (saved_keys
, prefixarg
);
8635 if (EQ (prefixarg
, Qminus
))
8637 else if (CONSP (prefixarg
) && XINT (XCAR (prefixarg
)) == 4)
8638 strcpy (buf
, "C-u ");
8639 else if (CONSP (prefixarg
) && INTEGERP (XCAR (prefixarg
)))
8641 if (sizeof (int) == sizeof (EMACS_INT
))
8642 sprintf (buf
, "%d ", XINT (XCAR (prefixarg
)));
8643 else if (sizeof (long) == sizeof (EMACS_INT
))
8644 sprintf (buf
, "%ld ", (long) XINT (XCAR (prefixarg
)));
8648 else if (INTEGERP (prefixarg
))
8650 if (sizeof (int) == sizeof (EMACS_INT
))
8651 sprintf (buf
, "%d ", XINT (prefixarg
));
8652 else if (sizeof (long) == sizeof (EMACS_INT
))
8653 sprintf (buf
, "%ld ", (long) XINT (prefixarg
));
8658 /* This isn't strictly correct if execute-extended-command
8659 is bound to anything else. Perhaps it should use
8660 this_command_keys? */
8661 strcat (buf
, "M-x ");
8663 /* Prompt with buf, and then read a string, completing from and
8664 restricting to the set of all defined commands. Don't provide
8665 any initial input. Save the command read on the extended-command
8667 function
= Fcompleting_read (build_string (buf
),
8668 Vobarray
, Qcommandp
,
8669 Qt
, Qnil
, Qextended_command_history
, Qnil
,
8672 if (STRINGP (function
) && XSTRING (function
)->size
== 0)
8673 error ("No command name given");
8675 /* Set this_command_keys to the concatenation of saved_keys and
8676 function, followed by a RET. */
8678 struct Lisp_String
*str
;
8682 this_command_key_count
= 0;
8683 this_single_command_key_start
= 0;
8685 keys
= XVECTOR (saved_keys
)->contents
;
8686 for (i
= 0; i
< XVECTOR (saved_keys
)->size
; i
++)
8687 add_command_key (keys
[i
]);
8689 str
= XSTRING (function
);
8690 for (i
= 0; i
< str
->size
; i
++)
8691 add_command_key (Faref (function
, make_number (i
)));
8693 add_command_key (make_number ('\015'));
8698 function
= Fintern (function
, Qnil
);
8699 current_kboard
->Vprefix_arg
= prefixarg
;
8700 Vthis_command
= function
;
8701 real_this_command
= function
;
8703 /* If enabled, show which key runs this command. */
8704 if (!NILP (Vsuggest_key_bindings
)
8705 && NILP (Vexecuting_macro
)
8706 && SYMBOLP (function
))
8707 bindings
= Fwhere_is_internal (function
, Voverriding_local_map
,
8713 GCPRO2 (bindings
, value
);
8714 value
= Fcommand_execute (function
, Qt
, Qnil
, Qnil
);
8716 /* If the command has a key binding, print it now. */
8717 if (!NILP (bindings
)
8718 && ! (VECTORP (bindings
) && EQ (Faref (bindings
, make_number (0)),
8721 /* But first wait, and skip the message if there is input. */
8723 if (!NILP (echo_area_buffer
[0]))
8724 /* This command displayed something in the echo area;
8725 so wait a few seconds, then display our suggestion message. */
8726 delay_time
= (NUMBERP (Vsuggest_key_bindings
)
8727 ? XINT (Vsuggest_key_bindings
) : 2);
8729 /* This command left the echo area empty,
8730 so display our message immediately. */
8733 if (!NILP (Fsit_for (make_number (delay_time
), Qnil
, Qnil
))
8734 && ! CONSP (Vunread_command_events
))
8736 Lisp_Object binding
;
8738 int message_p
= push_message ();
8740 binding
= Fkey_description (bindings
);
8743 = (char *) alloca (XSYMBOL (function
)->name
->size
8744 + STRING_BYTES (XSTRING (binding
))
8746 sprintf (newmessage
, "You can run the command `%s' with %s",
8747 XSYMBOL (function
)->name
->data
,
8748 XSTRING (binding
)->data
);
8749 message2_nolog (newmessage
,
8750 strlen (newmessage
),
8751 STRING_MULTIBYTE (binding
));
8752 if (!NILP (Fsit_for ((NUMBERP (Vsuggest_key_bindings
)
8753 ? Vsuggest_key_bindings
: make_number (2)),
8762 RETURN_UNGCPRO (value
);
8765 /* Find the set of keymaps now active.
8766 Store into *MAPS_P a vector holding the various maps
8767 and return the number of them. The vector was malloc'd
8768 and the caller should free it. */
8771 current_active_maps (maps_p
)
8772 Lisp_Object
**maps_p
;
8774 Lisp_Object
*tmaps
, *maps
;
8777 /* Should overriding-terminal-local-map and overriding-local-map apply? */
8778 if (!NILP (Voverriding_local_map_menu_flag
))
8780 /* Yes, use them (if non-nil) as well as the global map. */
8781 maps
= (Lisp_Object
*) xmalloc (3 * sizeof (maps
[0]));
8783 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
8784 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
8785 if (!NILP (Voverriding_local_map
))
8786 maps
[nmaps
++] = Voverriding_local_map
;
8790 /* No, so use major and minor mode keymaps. */
8791 nmaps
= current_minor_maps (NULL
, &tmaps
);
8792 maps
= (Lisp_Object
*) xmalloc ((nmaps
+ 2) * sizeof (maps
[0]));
8793 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
8794 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
8796 maps
[nmaps
++] = current_global_map
;
8802 /* Return nonzero if input events are pending. */
8805 detect_input_pending ()
8808 get_input_pending (&input_pending
, 0);
8810 return input_pending
;
8813 /* Return nonzero if input events are pending, and run any pending timers. */
8816 detect_input_pending_run_timers (do_display
)
8819 int old_timers_run
= timers_run
;
8822 get_input_pending (&input_pending
, 1);
8824 if (old_timers_run
!= timers_run
&& do_display
)
8826 redisplay_preserve_echo_area ();
8827 /* The following fixes a bug when using lazy-lock with
8828 lazy-lock-defer-on-the-fly set to t, i.e. when fontifying
8829 from an idle timer function. The symptom of the bug is that
8830 the cursor sometimes doesn't become visible until the next X
8831 event is processed. --gerd. */
8833 rif
->flush_display (NULL
);
8836 return input_pending
;
8839 /* This is called in some cases before a possible quit.
8840 It cases the next call to detect_input_pending to recompute input_pending.
8841 So calling this function unnecessarily can't do any harm. */
8844 clear_input_pending ()
8849 /* Return nonzero if there are pending requeued events.
8850 This isn't used yet. The hope is to make wait_reading_process_input
8851 call it, and return return if it runs Lisp code that unreads something.
8852 The problem is, kbd_buffer_get_event needs to be fixed to know what
8853 to do in that case. It isn't trivial. */
8856 requeued_events_pending_p ()
8858 return (!NILP (Vunread_command_events
) || unread_command_char
!= -1);
8862 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
8863 "T if command input is currently available with no waiting.\n\
8864 Actually, the value is nil only if we can be sure that no input is available.")
8867 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1)
8870 get_input_pending (&input_pending
, 1);
8871 return input_pending
> 0 ? Qt
: Qnil
;
8874 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
8875 "Return vector of last 100 events, not counting those from keyboard macros.")
8878 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
8881 if (total_keys
< NUM_RECENT_KEYS
)
8882 return Fvector (total_keys
, keys
);
8885 val
= Fvector (NUM_RECENT_KEYS
, keys
);
8886 bcopy (keys
+ recent_keys_index
,
8887 XVECTOR (val
)->contents
,
8888 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
8890 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
8891 recent_keys_index
* sizeof (Lisp_Object
));
8896 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
8897 "Return the key sequence that invoked this command.\n\
8898 The value is a string or a vector.")
8901 return make_event_array (this_command_key_count
,
8902 XVECTOR (this_command_keys
)->contents
);
8905 DEFUN ("this-command-keys-vector", Fthis_command_keys_vector
, Sthis_command_keys_vector
, 0, 0, 0,
8906 "Return the key sequence that invoked this command, as a vector.")
8909 return Fvector (this_command_key_count
,
8910 XVECTOR (this_command_keys
)->contents
);
8913 DEFUN ("this-single-command-keys", Fthis_single_command_keys
,
8914 Sthis_single_command_keys
, 0, 0, 0,
8915 "Return the key sequence that invoked this command.\n\
8916 Unlike `this-command-keys', this function's value\n\
8917 does not include prefix arguments.\n\
8918 The value is always a vector.")
8921 return Fvector (this_command_key_count
8922 - this_single_command_key_start
,
8923 (XVECTOR (this_command_keys
)->contents
8924 + this_single_command_key_start
));
8927 DEFUN ("this-single-command-raw-keys", Fthis_single_command_raw_keys
,
8928 Sthis_single_command_raw_keys
, 0, 0, 0,
8929 "Return the raw events that were read for this command.\n\
8930 Unlike `this-single-command-keys', this function's value\n\
8931 shows the events before all translations (except for input methods).\n\
8932 The value is always a vector.")
8935 return Fvector (raw_keybuf_count
,
8936 (XVECTOR (raw_keybuf
)->contents
));
8939 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths
,
8940 Sreset_this_command_lengths
, 0, 0, 0,
8941 "Used for complicated reasons in `universal-argument-other-key'.\n\
8943 `universal-argument-other-key' rereads the event just typed.\n\
8944 It then gets translated through `function-key-map'.\n\
8945 The translated event gets included in the echo area and in\n\
8946 the value of `this-command-keys' in addition to the raw original event.\n\
8947 That is not right.\n\
8949 Calling this function directs the translated event to replace\n\
8950 the original event, so that only one version of the event actually\n\
8951 appears in the echo area and in the value of `this-command-keys.'.")
8954 before_command_restore_flag
= 1;
8955 before_command_key_count_1
= before_command_key_count
;
8956 before_command_echo_length_1
= before_command_echo_length
;
8960 DEFUN ("clear-this-command-keys", Fclear_this_command_keys
,
8961 Sclear_this_command_keys
, 0, 0, 0,
8962 "Clear out the vector that `this-command-keys' returns.")
8965 this_command_key_count
= 0;
8969 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
8970 "Return the current depth in recursive edits.")
8974 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
8978 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
8979 "FOpen dribble file: ",
8980 "Start writing all keyboard characters to a dribble file called FILE.\n\
8981 If FILE is nil, close any open dribble file.")
8992 file
= Fexpand_file_name (file
, Qnil
);
8993 dribble
= fopen (XSTRING (file
)->data
, "w");
8995 report_file_error ("Opening dribble", Fcons (file
, Qnil
));
9000 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
9001 "Discard the contents of the terminal input buffer.\n\
9002 Also cancel any kbd macro being defined.")
9005 current_kboard
->defining_kbd_macro
= Qnil
;
9006 update_mode_lines
++;
9008 Vunread_command_events
= Qnil
;
9009 unread_command_char
= -1;
9011 discard_tty_input ();
9013 kbd_fetch_ptr
= kbd_store_ptr
;
9014 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
9020 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
9021 "Stop Emacs and return to superior process. You can resume later.\n\
9022 If `cannot-suspend' is non-nil, or if the system doesn't support job\n\
9023 control, run a subshell instead.\n\n\
9024 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
9025 to be read as terminal input by Emacs's parent, after suspension.\n\
9027 Before suspending, run the normal hook `suspend-hook'.\n\
9028 After resumption run the normal hook `suspend-resume-hook'.\n\
9030 Some operating systems cannot stop the Emacs process and resume it later.\n\
9031 On such systems, Emacs starts a subshell instead of suspending.")
9033 Lisp_Object stuffstring
;
9035 int count
= specpdl_ptr
- specpdl
;
9036 int old_height
, old_width
;
9038 struct gcpro gcpro1
;
9040 if (!NILP (stuffstring
))
9041 CHECK_STRING (stuffstring
, 0);
9043 /* Run the functions in suspend-hook. */
9044 if (!NILP (Vrun_hooks
))
9045 call1 (Vrun_hooks
, intern ("suspend-hook"));
9047 GCPRO1 (stuffstring
);
9048 get_frame_size (&old_width
, &old_height
);
9050 /* sys_suspend can get an error if it tries to fork a subshell
9051 and the system resources aren't available for that. */
9052 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object
))) init_sys_modes
,
9054 stuff_buffered_input (stuffstring
);
9059 unbind_to (count
, Qnil
);
9061 /* Check if terminal/window size has changed.
9062 Note that this is not useful when we are running directly
9063 with a window system; but suspend should be disabled in that case. */
9064 get_frame_size (&width
, &height
);
9065 if (width
!= old_width
|| height
!= old_height
)
9066 change_frame_size (SELECTED_FRAME (), height
, width
, 0, 0, 0);
9068 /* Run suspend-resume-hook. */
9069 if (!NILP (Vrun_hooks
))
9070 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
9076 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
9077 Then in any case stuff anything Emacs has read ahead and not used. */
9080 stuff_buffered_input (stuffstring
)
9081 Lisp_Object stuffstring
;
9083 /* stuff_char works only in BSD, versions 4.2 and up. */
9086 register unsigned char *p
;
9088 if (STRINGP (stuffstring
))
9092 p
= XSTRING (stuffstring
)->data
;
9093 count
= STRING_BYTES (XSTRING (stuffstring
));
9098 /* Anything we have read ahead, put back for the shell to read. */
9099 /* ?? What should this do when we have multiple keyboards??
9100 Should we ignore anything that was typed in at the "wrong" kboard? */
9101 for (; kbd_fetch_ptr
!= kbd_store_ptr
; kbd_fetch_ptr
++)
9103 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
9104 kbd_fetch_ptr
= kbd_buffer
;
9105 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
9106 stuff_char (kbd_fetch_ptr
->code
);
9107 kbd_fetch_ptr
->kind
= no_event
;
9108 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_fetch_ptr
9114 #endif /* BSD_SYSTEM and not BSD4_1 */
9118 set_waiting_for_input (time_to_clear
)
9119 EMACS_TIME
*time_to_clear
;
9121 input_available_clear_time
= time_to_clear
;
9123 /* Tell interrupt_signal to throw back to read_char, */
9124 waiting_for_input
= 1;
9126 /* If interrupt_signal was called before and buffered a C-g,
9127 make it run again now, to avoid timing error. */
9128 if (!NILP (Vquit_flag
))
9129 quit_throw_to_read_char ();
9133 clear_waiting_for_input ()
9135 /* Tell interrupt_signal not to throw back to read_char, */
9136 waiting_for_input
= 0;
9137 input_available_clear_time
= 0;
9140 /* This routine is called at interrupt level in response to C-G.
9141 If interrupt_input, this is the handler for SIGINT.
9142 Otherwise, it is called from kbd_buffer_store_event,
9143 in handling SIGIO or SIGTINT.
9145 If `waiting_for_input' is non zero, then unless `echoing' is nonzero,
9146 immediately throw back to read_char.
9148 Otherwise it sets the Lisp variable quit-flag not-nil.
9149 This causes eval to throw, when it gets a chance.
9150 If quit-flag is already non-nil, it stops the job right away. */
9153 interrupt_signal (signalnum
) /* If we don't have an argument, */
9154 int signalnum
; /* some compilers complain in signal calls. */
9157 /* Must preserve main program's value of errno. */
9158 int old_errno
= errno
;
9159 struct frame
*sf
= SELECTED_FRAME ();
9161 #if defined (USG) && !defined (POSIX_SIGNALS)
9162 if (!read_socket_hook
&& NILP (Vwindow_system
))
9164 /* USG systems forget handlers when they are used;
9165 must reestablish each time */
9166 signal (SIGINT
, interrupt_signal
);
9167 signal (SIGQUIT
, interrupt_signal
);
9173 if (!NILP (Vquit_flag
)
9174 && (FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
)))
9176 /* If SIGINT isn't blocked, don't let us be interrupted by
9177 another SIGINT, it might be harmful due to non-reentrancy
9178 in I/O functions. */
9179 sigblock (sigmask (SIGINT
));
9184 #ifdef SIGTSTP /* Support possible in later USG versions */
9186 * On systems which can suspend the current process and return to the original
9187 * shell, this command causes the user to end up back at the shell.
9188 * The "Auto-save" and "Abort" questions are not asked until
9189 * the user elects to return to emacs, at which point he can save the current
9190 * job and either dump core or continue.
9195 if (sys_suspend () == -1)
9197 printf ("Not running as a subprocess;\n");
9198 printf ("you can continue or abort.\n");
9201 /* Perhaps should really fork an inferior shell?
9202 But that would not provide any way to get back
9203 to the original shell, ever. */
9204 printf ("No support for stopping a process on this operating system;\n");
9205 printf ("you can continue or abort.\n");
9206 #endif /* not VMS */
9207 #endif /* not SIGTSTP */
9209 /* We must remain inside the screen area when the internal terminal
9210 is used. Note that [Enter] is not echoed by dos. */
9213 /* It doesn't work to autosave while GC is in progress;
9214 the code used for auto-saving doesn't cope with the mark bit. */
9215 if (!gc_in_progress
)
9217 printf ("Auto-save? (y or n) ");
9219 if (((c
= getchar ()) & ~040) == 'Y')
9221 Fdo_auto_save (Qt
, Qnil
);
9223 printf ("\r\nAuto-save done");
9224 #else /* not MSDOS */
9225 printf ("Auto-save done\n");
9226 #endif /* not MSDOS */
9228 while (c
!= '\n') c
= getchar ();
9232 /* During GC, it must be safe to reenable quitting again. */
9233 Vinhibit_quit
= Qnil
;
9236 #endif /* not MSDOS */
9237 printf ("Garbage collection in progress; cannot auto-save now\r\n");
9238 printf ("but will instead do a real quit after garbage collection ends\r\n");
9243 printf ("\r\nAbort? (y or n) ");
9244 #else /* not MSDOS */
9246 printf ("Abort (and enter debugger)? (y or n) ");
9248 printf ("Abort (and dump core)? (y or n) ");
9249 #endif /* not VMS */
9250 #endif /* not MSDOS */
9252 if (((c
= getchar ()) & ~040) == 'Y')
9254 while (c
!= '\n') c
= getchar ();
9256 printf ("\r\nContinuing...\r\n");
9257 #else /* not MSDOS */
9258 printf ("Continuing...\n");
9259 #endif /* not MSDOS */
9266 /* If executing a function that wants to be interrupted out of
9267 and the user has not deferred quitting by binding `inhibit-quit'
9268 then quit right away. */
9269 if (immediate_quit
&& NILP (Vinhibit_quit
))
9271 struct gl_state_s saved
;
9272 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9277 GCPRO4 (saved
.object
, saved
.global_code
,
9278 saved
.current_syntax_table
, saved
.old_prop
);
9279 Fsignal (Qquit
, Qnil
);
9284 /* Else request quit when it's safe */
9288 if (waiting_for_input
&& !echoing
)
9289 quit_throw_to_read_char ();
9294 /* Handle a C-g by making read_char return C-g. */
9297 quit_throw_to_read_char ()
9300 /* Prevent another signal from doing this before we finish. */
9301 clear_waiting_for_input ();
9304 Vunread_command_events
= Qnil
;
9305 unread_command_char
= -1;
9307 #if 0 /* Currently, sit_for is called from read_char without turning
9308 off polling. And that can call set_waiting_for_input.
9309 It seems to be harmless. */
9310 #ifdef POLL_FOR_INPUT
9311 /* May be > 1 if in recursive minibuffer. */
9312 if (poll_suppress_count
== 0)
9316 if (FRAMEP (internal_last_event_frame
)
9317 && !EQ (internal_last_event_frame
, selected_frame
))
9318 do_switch_frame (make_lispy_switch_frame (internal_last_event_frame
),
9321 _longjmp (getcjmp
, 1);
9324 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
9325 "Set mode of reading keyboard input.\n\
9326 First arg INTERRUPT non-nil means use input interrupts;\n\
9327 nil means use CBREAK mode.\n\
9328 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
9329 (no effect except in CBREAK mode).\n\
9330 Third arg META t means accept 8-bit input (for a Meta key).\n\
9331 META nil means ignore the top bit, on the assumption it is parity.\n\
9332 Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\
9333 Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\
9334 See also `current-input-mode'.")
9335 (interrupt
, flow
, meta
, quit
)
9336 Lisp_Object interrupt
, flow
, meta
, quit
;
9339 && (!INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400))
9340 error ("set-input-mode: QUIT must be an ASCII character");
9342 #ifdef POLL_FOR_INPUT
9347 /* this causes startup screen to be restored and messes with the mouse */
9352 /* Note SIGIO has been undef'd if FIONREAD is missing. */
9353 if (read_socket_hook
)
9355 /* When using X, don't give the user a real choice,
9356 because we haven't implemented the mechanisms to support it. */
9357 #ifdef NO_SOCK_SIGIO
9358 interrupt_input
= 0;
9359 #else /* not NO_SOCK_SIGIO */
9360 interrupt_input
= 1;
9361 #endif /* NO_SOCK_SIGIO */
9364 interrupt_input
= !NILP (interrupt
);
9365 #else /* not SIGIO */
9366 interrupt_input
= 0;
9367 #endif /* not SIGIO */
9369 /* Our VMS input only works by interrupts, as of now. */
9371 interrupt_input
= 1;
9374 flow_control
= !NILP (flow
);
9377 else if (EQ (meta
, Qt
))
9382 /* Don't let this value be out of range. */
9383 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
9389 #ifdef POLL_FOR_INPUT
9390 poll_suppress_count
= 1;
9396 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
9397 "Return information about the way Emacs currently reads keyboard input.\n\
9398 The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
9399 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\
9400 nil, Emacs is using CBREAK mode.\n\
9401 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\
9402 terminal; this does not apply if Emacs uses interrupt-driven input.\n\
9403 META is t if accepting 8-bit input with 8th bit as Meta flag.\n\
9404 META nil means ignoring the top bit, on the assumption it is parity.\n\
9405 META is neither t nor nil if accepting 8-bit input and using\n\
9406 all 8 bits as the character code.\n\
9407 QUIT is the character Emacs currently uses to quit.\n\
9408 The elements of this list correspond to the arguments of\n\
9414 val
[0] = interrupt_input
? Qt
: Qnil
;
9415 val
[1] = flow_control
? Qt
: Qnil
;
9416 val
[2] = meta_key
== 2 ? make_number (0) : meta_key
== 1 ? Qt
: Qnil
;
9417 XSETFASTINT (val
[3], quit_char
);
9419 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
9424 * Set up a new kboard object with reasonable initial values.
9430 kb
->Voverriding_terminal_local_map
= Qnil
;
9431 kb
->Vlast_command
= Qnil
;
9432 kb
->Vreal_last_command
= Qnil
;
9433 kb
->Vprefix_arg
= Qnil
;
9434 kb
->Vlast_prefix_arg
= Qnil
;
9435 kb
->kbd_queue
= Qnil
;
9436 kb
->kbd_queue_has_data
= 0;
9437 kb
->immediate_echo
= 0;
9438 kb
->echoptr
= kb
->echobuf
;
9439 kb
->echo_after_prompt
= -1;
9440 kb
->kbd_macro_buffer
= 0;
9441 kb
->kbd_macro_bufsize
= 0;
9442 kb
->defining_kbd_macro
= Qnil
;
9443 kb
->Vlast_kbd_macro
= Qnil
;
9444 kb
->reference_count
= 0;
9445 kb
->Vsystem_key_alist
= Qnil
;
9446 kb
->system_key_syms
= Qnil
;
9447 kb
->Vdefault_minibuffer_frame
= Qnil
;
9451 * Destroy the contents of a kboard object, but not the object itself.
9452 * We use this just before deleting it, or if we're going to initialize
9459 if (kb
->kbd_macro_buffer
)
9460 xfree (kb
->kbd_macro_buffer
);
9469 for (kbp
= &all_kboards
; *kbp
!= kb
; kbp
= &(*kbp
)->next_kboard
)
9472 *kbp
= kb
->next_kboard
;
9481 /* This is correct before outermost invocation of the editor loop */
9482 command_loop_level
= -1;
9484 quit_char
= Ctl ('g');
9485 Vunread_command_events
= Qnil
;
9486 unread_command_char
= -1;
9487 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
9489 recent_keys_index
= 0;
9490 kbd_fetch_ptr
= kbd_buffer
;
9491 kbd_store_ptr
= kbd_buffer
;
9492 kbd_buffer_frame_or_window
9493 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
9495 do_mouse_tracking
= Qnil
;
9499 /* This means that command_loop_1 won't try to select anything the first
9501 internal_last_event_frame
= Qnil
;
9502 Vlast_event_frame
= internal_last_event_frame
;
9505 current_kboard
= initial_kboard
;
9507 wipe_kboard (current_kboard
);
9508 init_kboard (current_kboard
);
9511 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
9513 kbd_buffer_frame_or_window
9514 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
9515 if (!noninteractive
&& !read_socket_hook
&& NILP (Vwindow_system
))
9517 signal (SIGINT
, interrupt_signal
);
9518 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
9519 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
9520 SIGQUIT and we can't tell which one it will give us. */
9521 signal (SIGQUIT
, interrupt_signal
);
9522 #endif /* HAVE_TERMIO */
9524 /* Note SIGIO has been undef'd if FIONREAD is missing. */
9526 if (!noninteractive
)
9527 signal (SIGIO
, input_available_signal
);
9530 /* Use interrupt input by default, if it works and noninterrupt input
9531 has deficiencies. */
9533 #ifdef INTERRUPT_INPUT
9534 interrupt_input
= 1;
9536 interrupt_input
= 0;
9539 /* Our VMS input only works by interrupts, as of now. */
9541 interrupt_input
= 1;
9547 if (keyboard_init_hook
)
9548 (*keyboard_init_hook
) ();
9550 #ifdef POLL_FOR_INPUT
9551 poll_suppress_count
= 1;
9556 /* This type's only use is in syms_of_keyboard, to initialize the
9557 event header symbols and put properties on them. */
9564 struct event_head head_table
[] = {
9565 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
9566 &Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
,
9567 &Qswitch_frame
, "switch-frame", &Qswitch_frame
,
9568 &Qdelete_frame
, "delete-frame", &Qdelete_frame
,
9569 &Qiconify_frame
, "iconify-frame", &Qiconify_frame
,
9570 &Qmake_frame_visible
, "make-frame-visible", &Qmake_frame_visible
,
9577 QCimage
= intern (":image");
9578 staticpro (&QCimage
);
9580 staticpro (&Qhelp_echo
);
9581 Qhelp_echo
= intern ("help-echo");
9583 staticpro (&item_properties
);
9584 item_properties
= Qnil
;
9586 staticpro (&tool_bar_item_properties
);
9587 tool_bar_item_properties
= Qnil
;
9588 staticpro (&tool_bar_items_vector
);
9589 tool_bar_items_vector
= Qnil
;
9591 staticpro (&real_this_command
);
9592 real_this_command
= Qnil
;
9594 Qtimer_event_handler
= intern ("timer-event-handler");
9595 staticpro (&Qtimer_event_handler
);
9597 Qdisabled_command_hook
= intern ("disabled-command-hook");
9598 staticpro (&Qdisabled_command_hook
);
9600 Qself_insert_command
= intern ("self-insert-command");
9601 staticpro (&Qself_insert_command
);
9603 Qforward_char
= intern ("forward-char");
9604 staticpro (&Qforward_char
);
9606 Qbackward_char
= intern ("backward-char");
9607 staticpro (&Qbackward_char
);
9609 Qdisabled
= intern ("disabled");
9610 staticpro (&Qdisabled
);
9612 Qundefined
= intern ("undefined");
9613 staticpro (&Qundefined
);
9615 Qpre_command_hook
= intern ("pre-command-hook");
9616 staticpro (&Qpre_command_hook
);
9618 Qpost_command_hook
= intern ("post-command-hook");
9619 staticpro (&Qpost_command_hook
);
9621 Qpost_command_idle_hook
= intern ("post-command-idle-hook");
9622 staticpro (&Qpost_command_idle_hook
);
9624 Qdeferred_action_function
= intern ("deferred-action-function");
9625 staticpro (&Qdeferred_action_function
);
9627 Qcommand_hook_internal
= intern ("command-hook-internal");
9628 staticpro (&Qcommand_hook_internal
);
9630 Qfunction_key
= intern ("function-key");
9631 staticpro (&Qfunction_key
);
9632 Qmouse_click
= intern ("mouse-click");
9633 staticpro (&Qmouse_click
);
9635 Qmouse_wheel
= intern ("mouse-wheel");
9636 staticpro (&Qmouse_wheel
);
9637 Qlanguage_change
= intern ("language-change");
9638 staticpro (&Qlanguage_change
);
9640 Qdrag_n_drop
= intern ("drag-n-drop");
9641 staticpro (&Qdrag_n_drop
);
9643 Qusr1_signal
= intern ("usr1-signal");
9644 staticpro (&Qusr1_signal
);
9645 Qusr2_signal
= intern ("usr2-signal");
9646 staticpro (&Qusr2_signal
);
9648 Qmenu_enable
= intern ("menu-enable");
9649 staticpro (&Qmenu_enable
);
9650 Qmenu_alias
= intern ("menu-alias");
9651 staticpro (&Qmenu_alias
);
9652 QCenable
= intern (":enable");
9653 staticpro (&QCenable
);
9654 QCvisible
= intern (":visible");
9655 staticpro (&QCvisible
);
9656 QChelp
= intern (":help");
9657 staticpro (&QChelp
);
9658 QCfilter
= intern (":filter");
9659 staticpro (&QCfilter
);
9660 QCbutton
= intern (":button");
9661 staticpro (&QCbutton
);
9662 QCkeys
= intern (":keys");
9663 staticpro (&QCkeys
);
9664 QCkey_sequence
= intern (":key-sequence");
9665 staticpro (&QCkey_sequence
);
9666 QCtoggle
= intern (":toggle");
9667 staticpro (&QCtoggle
);
9668 QCradio
= intern (":radio");
9669 staticpro (&QCradio
);
9671 Qmode_line
= intern ("mode-line");
9672 staticpro (&Qmode_line
);
9673 Qvertical_line
= intern ("vertical-line");
9674 staticpro (&Qvertical_line
);
9675 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
9676 staticpro (&Qvertical_scroll_bar
);
9677 Qmenu_bar
= intern ("menu-bar");
9678 staticpro (&Qmenu_bar
);
9680 Qabove_handle
= intern ("above-handle");
9681 staticpro (&Qabove_handle
);
9682 Qhandle
= intern ("handle");
9683 staticpro (&Qhandle
);
9684 Qbelow_handle
= intern ("below-handle");
9685 staticpro (&Qbelow_handle
);
9686 Qup
= intern ("up");
9688 Qdown
= intern ("down");
9690 Qtop
= intern ("top");
9692 Qbottom
= intern ("bottom");
9693 staticpro (&Qbottom
);
9694 Qend_scroll
= intern ("end-scroll");
9695 staticpro (&Qend_scroll
);
9696 Qratio
= intern ("ratio");
9697 staticpro (&Qratio
);
9699 Qevent_kind
= intern ("event-kind");
9700 staticpro (&Qevent_kind
);
9701 Qevent_symbol_elements
= intern ("event-symbol-elements");
9702 staticpro (&Qevent_symbol_elements
);
9703 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
9704 staticpro (&Qevent_symbol_element_mask
);
9705 Qmodifier_cache
= intern ("modifier-cache");
9706 staticpro (&Qmodifier_cache
);
9708 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
9709 staticpro (&Qrecompute_lucid_menubar
);
9710 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
9711 staticpro (&Qactivate_menubar_hook
);
9713 Qpolling_period
= intern ("polling-period");
9714 staticpro (&Qpolling_period
);
9716 Qinput_method_function
= intern ("input-method-function");
9717 staticpro (&Qinput_method_function
);
9719 Qinput_method_exit_on_first_char
= intern ("input-method-exit-on-first-char");
9720 staticpro (&Qinput_method_exit_on_first_char
);
9721 Qinput_method_use_echo_area
= intern ("input-method-use-echo-area");
9722 staticpro (&Qinput_method_use_echo_area
);
9724 Fset (Qinput_method_exit_on_first_char
, Qnil
);
9725 Fset (Qinput_method_use_echo_area
, Qnil
);
9728 struct event_head
*p
;
9730 for (p
= head_table
;
9731 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
9734 *p
->var
= intern (p
->name
);
9736 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
9737 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
9741 button_down_location
= Fmake_vector (make_number (NUM_MOUSE_BUTTONS
), Qnil
);
9742 staticpro (&button_down_location
);
9746 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
9748 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
9749 for (i
= 0; i
< len
; i
++)
9750 if (modifier_names
[i
])
9751 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
9752 staticpro (&modifier_symbols
);
9755 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
9756 staticpro (&recent_keys
);
9758 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
9759 staticpro (&this_command_keys
);
9761 raw_keybuf
= Fmake_vector (make_number (30), Qnil
);
9762 staticpro (&raw_keybuf
);
9764 Qextended_command_history
= intern ("extended-command-history");
9765 Fset (Qextended_command_history
, Qnil
);
9766 staticpro (&Qextended_command_history
);
9768 kbd_buffer_frame_or_window
9769 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
9770 staticpro (&kbd_buffer_frame_or_window
);
9772 accent_key_syms
= Qnil
;
9773 staticpro (&accent_key_syms
);
9775 func_key_syms
= Qnil
;
9776 staticpro (&func_key_syms
);
9779 staticpro (&mouse_syms
);
9782 mouse_wheel_syms
= Qnil
;
9783 staticpro (&mouse_wheel_syms
);
9785 drag_n_drop_syms
= Qnil
;
9786 staticpro (&drag_n_drop_syms
);
9789 unread_switch_frame
= Qnil
;
9790 staticpro (&unread_switch_frame
);
9792 internal_last_event_frame
= Qnil
;
9793 staticpro (&internal_last_event_frame
);
9795 read_key_sequence_cmd
= Qnil
;
9796 staticpro (&read_key_sequence_cmd
);
9798 menu_bar_one_keymap_changed_items
= Qnil
;
9799 staticpro (&menu_bar_one_keymap_changed_items
);
9801 defsubr (&Sevent_convert_list
);
9802 defsubr (&Sread_key_sequence
);
9803 defsubr (&Sread_key_sequence_vector
);
9804 defsubr (&Srecursive_edit
);
9806 defsubr (&Strack_mouse
);
9808 defsubr (&Sinput_pending_p
);
9809 defsubr (&Scommand_execute
);
9810 defsubr (&Srecent_keys
);
9811 defsubr (&Sthis_command_keys
);
9812 defsubr (&Sthis_command_keys_vector
);
9813 defsubr (&Sthis_single_command_keys
);
9814 defsubr (&Sthis_single_command_raw_keys
);
9815 defsubr (&Sreset_this_command_lengths
);
9816 defsubr (&Sclear_this_command_keys
);
9817 defsubr (&Ssuspend_emacs
);
9818 defsubr (&Sabort_recursive_edit
);
9819 defsubr (&Sexit_recursive_edit
);
9820 defsubr (&Srecursion_depth
);
9821 defsubr (&Stop_level
);
9822 defsubr (&Sdiscard_input
);
9823 defsubr (&Sopen_dribble_file
);
9824 defsubr (&Sset_input_mode
);
9825 defsubr (&Scurrent_input_mode
);
9826 defsubr (&Sexecute_extended_command
);
9828 DEFVAR_LISP ("last-command-char", &last_command_char
,
9829 "Last input event that was part of a command.");
9831 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char
,
9832 "Last input event that was part of a command.");
9834 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
9835 "Last input event in a command, except for mouse menu events.\n\
9836 Mouse menus give back keys that don't look like mouse events;\n\
9837 this variable holds the actual mouse event that led to the menu,\n\
9838 so that you can determine whether the command was run by mouse or not.");
9840 DEFVAR_LISP ("last-input-char", &last_input_char
,
9841 "Last input event.");
9843 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char
,
9844 "Last input event.");
9846 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
9847 "List of events to be read as the command input.\n\
9848 These events are processed first, before actual keyboard input.");
9849 Vunread_command_events
= Qnil
;
9851 DEFVAR_INT ("unread-command-char", &unread_command_char
,
9852 "If not -1, an object to be read as next command input event.");
9854 DEFVAR_LISP ("unread-post-input-method-events", &Vunread_post_input_method_events
,
9855 "List of events to be processed as input by input methods.\n\
9856 These events are processed after `unread-command-events', but\n\
9857 before actual keyboard input.");
9858 Vunread_post_input_method_events
= Qnil
;
9860 DEFVAR_LISP ("unread-input-method-events", &Vunread_input_method_events
,
9861 "List of events to be processed as input by input methods.\n\
9862 These events are processed after `unread-command-events', but\n\
9863 before actual keyboard input.");
9864 Vunread_input_method_events
= Qnil
;
9866 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
9867 "Meta-prefix character code.\n\
9868 Meta-foo as command input turns into this character followed by foo.");
9869 XSETINT (meta_prefix_char
, 033);
9871 DEFVAR_KBOARD ("last-command", Vlast_command
,
9872 "The last command executed.\n\
9873 Normally a symbol with a function definition, but can be whatever was found\n\
9874 in the keymap, or whatever the variable `this-command' was set to by that\n\
9877 The value `mode-exit' is special; it means that the previous command\n\
9878 read an event that told it to exit, and it did so and unread that event.\n\
9879 In other words, the present command is the event that made the previous\n\
9882 The value `kill-region' is special; it means that the previous command\n\
9883 was a kill command.");
9885 DEFVAR_KBOARD ("real-last-command", Vreal_last_command
,
9886 "Same as `last-command', but never altered by Lisp code.");
9888 DEFVAR_LISP ("this-command", &Vthis_command
,
9889 "The command now being executed.\n\
9890 The command can set this variable; whatever is put here\n\
9891 will be in `last-command' during the following command.");
9892 Vthis_command
= Qnil
;
9894 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
9895 "*Number of input events between auto-saves.\n\
9896 Zero means disable autosaving due to number of characters typed.");
9897 auto_save_interval
= 300;
9899 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
9900 "*Number of seconds idle time before auto-save.\n\
9901 Zero or nil means disable auto-saving due to idleness.\n\
9902 After auto-saving due to this many seconds of idle time,\n\
9903 Emacs also does a garbage collection if that seems to be warranted.");
9904 XSETFASTINT (Vauto_save_timeout
, 30);
9906 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes
,
9907 "*Nonzero means echo unfinished commands after this many seconds of pause.");
9908 echo_keystrokes
= 1;
9910 DEFVAR_INT ("polling-period", &polling_period
,
9911 "*Interval between polling for input during Lisp execution.\n\
9912 The reason for polling is to make C-g work to stop a running program.\n\
9913 Polling is needed only when using X windows and SIGIO does not work.\n\
9914 Polling is automatically disabled in all other cases.");
9917 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
9918 "*Maximum time between mouse clicks to make a double-click.\n\
9919 Measured in milliseconds. nil means disable double-click recognition;\n\
9920 t means double-clicks have no time limit and are detected\n\
9921 by position only.");
9922 Vdouble_click_time
= make_number (500);
9924 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
9925 "*Non-nil means inhibit local map menu bar menus.");
9926 inhibit_local_menu_bar_menus
= 0;
9928 DEFVAR_INT ("num-input-keys", &num_input_keys
,
9929 "Number of complete key sequences read as input so far.\n\
9930 This includes key sequences read from keyboard macros.\n\
9931 The number is effectively the number of interactive command invocations.");
9934 DEFVAR_INT ("num-nonmacro-input-events", &num_nonmacro_input_events
,
9935 "Number of input events read from the keyboard so far.\n\
9936 This does not include events generated by keyboard macros.");
9937 num_nonmacro_input_events
= 0;
9939 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
9940 "The frame in which the most recently read event occurred.\n\
9941 If the last event came from a keyboard macro, this is set to `macro'.");
9942 Vlast_event_frame
= Qnil
;
9944 /* This variable is set up in sysdep.c. */
9945 DEFVAR_LISP ("tty-erase-char", &Vtty_erase_char
,
9946 "The ERASE character as set by the user with stty.");
9948 DEFVAR_LISP ("help-char", &Vhelp_char
,
9949 "Character to recognize as meaning Help.\n\
9950 When it is read, do `(eval help-form)', and display result if it's a string.\n\
9951 If the value of `help-form' is nil, this char can be read normally.");
9952 XSETINT (Vhelp_char
, Ctl ('H'));
9954 DEFVAR_LISP ("help-event-list", &Vhelp_event_list
,
9955 "List of input events to recognize as meaning Help.\n\
9956 These work just like the value of `help-char' (see that).");
9957 Vhelp_event_list
= Qnil
;
9959 DEFVAR_LISP ("help-form", &Vhelp_form
,
9960 "Form to execute when character `help-char' is read.\n\
9961 If the form returns a string, that string is displayed.\n\
9962 If `help-form' is nil, the help char is not recognized.");
9965 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
9966 "Command to run when `help-char' character follows a prefix key.\n\
9967 This command is used only when there is no actual binding\n\
9968 for that character after that prefix key.");
9969 Vprefix_help_command
= Qnil
;
9971 DEFVAR_LISP ("top-level", &Vtop_level
,
9972 "Form to evaluate when Emacs starts up.\n\
9973 Useful to set before you dump a modified Emacs.");
9976 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
9977 "Translate table for keyboard input, or nil.\n\
9978 Each character is looked up in this string and the contents used instead.\n\
9979 The value may be a string, a vector, or a char-table.\n\
9980 If it is a string or vector of length N,\n\
9981 character codes N and up are untranslated.\n\
9982 In a vector or a char-table, an element which is nil means \"no translation\".");
9983 Vkeyboard_translate_table
= Qnil
;
9985 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
9986 "Non-nil means to always spawn a subshell instead of suspending.\n\
9987 \(Even if the operating system has support for stopping a process.\)");
9990 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
9991 "Non-nil means prompt with menus when appropriate.\n\
9992 This is done when reading from a keymap that has a prompt string,\n\
9993 for elements that have prompt strings.\n\
9994 The menu is displayed on the screen\n\
9995 if X menus were enabled at configuration\n\
9996 time and the previous event was a mouse click prefix key.\n\
9997 Otherwise, menu prompting uses the echo area.");
10000 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
10001 "Character to see next line of menu prompt.\n\
10002 Type this character while in a menu prompt to rotate around the lines of it.");
10003 XSETINT (menu_prompt_more_char
, ' ');
10005 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
10006 "A mask of additional modifier keys to use with every keyboard character.\n\
10007 Emacs applies the modifiers of the character stored here to each keyboard\n\
10008 character it reads. For example, after evaluating the expression\n\
10009 (setq extra-keyboard-modifiers ?\\C-x)\n\
10010 all input characters will have the control modifier applied to them.\n\
10012 Note that the character ?\\C-@, equivalent to the integer zero, does\n\
10013 not count as a control character; rather, it counts as a character\n\
10014 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\
10015 cancels any modification.");
10016 extra_keyboard_modifiers
= 0;
10018 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
10019 "If an editing command sets this to t, deactivate the mark afterward.\n\
10020 The command loop sets this to nil before each command,\n\
10021 and tests the value when the command returns.\n\
10022 Buffer modification stores t in this variable.");
10023 Vdeactivate_mark
= Qnil
;
10025 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
10026 "Temporary storage of pre-command-hook or post-command-hook.");
10027 Vcommand_hook_internal
= Qnil
;
10029 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
10030 "Normal hook run before each command is executed.\n\
10031 If an unhandled error happens in running this hook,\n\
10032 the hook value is set to nil, since otherwise the error\n\
10033 might happen repeatedly and make Emacs nonfunctional.");
10034 Vpre_command_hook
= Qnil
;
10036 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
10037 "Normal hook run after each command is executed.\n\
10038 If an unhandled error happens in running this hook,\n\
10039 the hook value is set to nil, since otherwise the error\n\
10040 might happen repeatedly and make Emacs nonfunctional.");
10041 Vpost_command_hook
= Qnil
;
10043 DEFVAR_LISP ("post-command-idle-hook", &Vpost_command_idle_hook
,
10044 "Normal hook run after each command is executed, if idle.\n\
10045 Errors running the hook are caught and ignored.\n\
10046 This feature is obsolete; use idle timers instead. See `etc/NEWS'.");
10047 Vpost_command_idle_hook
= Qnil
;
10049 DEFVAR_INT ("post-command-idle-delay", &post_command_idle_delay
,
10050 "Delay time before running `post-command-idle-hook'.\n\
10051 This is measured in microseconds.");
10052 post_command_idle_delay
= 100000;
10055 DEFVAR_LISP ("echo-area-clear-hook", ...,
10056 "Normal hook run when clearing the echo area.");
10058 Qecho_area_clear_hook
= intern ("echo-area-clear-hook");
10059 XSYMBOL (Qecho_area_clear_hook
)->value
= Qnil
;
10061 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
10062 "t means menu bar, specified Lucid style, needs to be recomputed.");
10063 Vlucid_menu_bar_dirty_flag
= Qnil
;
10065 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
10066 "List of menu bar items to move to the end of the menu bar.\n\
10067 The elements of the list are event types that may have menu bar bindings.");
10068 Vmenu_bar_final_items
= Qnil
;
10070 DEFVAR_KBOARD ("overriding-terminal-local-map",
10071 Voverriding_terminal_local_map
,
10072 "Per-terminal keymap that overrides all other local keymaps.\n\
10073 If this variable is non-nil, it is used as a keymap instead of the\n\
10074 buffer's local map, and the minor mode keymaps and text property keymaps.\n\
10075 This variable is intended to let commands such as `universal-argumemnt'\n\
10076 set up a different keymap for reading the next command.");
10078 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
10079 "Keymap that overrides all other local keymaps.\n\
10080 If this variable is non-nil, it is used as a keymap instead of the\n\
10081 buffer's local map, and the minor mode keymaps and text property keymaps.");
10082 Voverriding_local_map
= Qnil
;
10084 DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag
,
10085 "Non-nil means `overriding-local-map' applies to the menu bar.\n\
10086 Otherwise, the menu bar continues to reflect the buffer's local map\n\
10087 and the minor mode maps regardless of `overriding-local-map'.");
10088 Voverriding_local_map_menu_flag
= Qnil
;
10090 DEFVAR_LISP ("special-event-map", &Vspecial_event_map
,
10091 "Keymap defining bindings for special events to execute at low level.");
10092 Vspecial_event_map
= Fcons (intern ("keymap"), Qnil
);
10094 DEFVAR_LISP ("track-mouse", &do_mouse_tracking
,
10095 "*Non-nil means generate motion events for mouse motion.");
10097 DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist
,
10098 "Alist of system-specific X windows key symbols.\n\
10099 Each element should have the form (N . SYMBOL) where N is the\n\
10100 numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\
10101 and SYMBOL is its name.");
10103 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
10104 "List of deferred actions to be performed at a later time.\n\
10105 The precise format isn't relevant here; we just check whether it is nil.");
10106 Vdeferred_action_list
= Qnil
;
10108 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
10109 "Function to call to handle deferred actions, after each command.\n\
10110 This function is called with no arguments after each command\n\
10111 whenever `deferred-action-list' is non-nil.");
10112 Vdeferred_action_function
= Qnil
;
10114 DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings
,
10115 "*Non-nil means show the equivalent key-binding when M-x command has one.\n\
10116 The value can be a length of time to show the message for.\n\
10117 If the value is non-nil and not a number, we wait 2 seconds.");
10118 Vsuggest_key_bindings
= Qt
;
10120 DEFVAR_LISP ("timer-list", &Vtimer_list
,
10121 "List of active absolute time timers in order of increasing time");
10122 Vtimer_list
= Qnil
;
10124 DEFVAR_LISP ("timer-idle-list", &Vtimer_idle_list
,
10125 "List of active idle-time timers in order of increasing time");
10126 Vtimer_idle_list
= Qnil
;
10128 DEFVAR_LISP ("input-method-function", &Vinput_method_function
,
10129 "If non-nil, the function that implements the current input method.\n\
10130 It's called with one argument, a printing character that was just read.\n\
10131 \(That means a character with code 040...0176.)\n\
10132 Typically this function uses `read-event' to read additional events.\n\
10133 When it does so, it should first bind `input-method-function' to nil\n\
10134 so it will not be called recursively.\n\
10136 The function should return a list of zero or more events\n\
10137 to be used as input. If it wants to put back some events\n\
10138 to be reconsidered, separately, by the input method,\n\
10139 it can add them to the beginning of `unread-command-events'.\n\
10141 The input method function can find in `input-method-previous-method'\n\
10142 the previous echo area message.\n\
10144 The input method function should refer to the variables\n\
10145 `input-method-use-echo-area' and `input-method-exit-on-first-char'\n\
10146 for guidance on what to do.");
10147 Vinput_method_function
= Qnil
;
10149 DEFVAR_LISP ("input-method-previous-message",
10150 &Vinput_method_previous_message
,
10151 "When `input-method-function' is called, hold the previous echo area message.\n\
10152 This variable exists because `read-event' clears the echo area\n\
10153 before running the input method. It is nil if there was no message.");
10154 Vinput_method_previous_message
= Qnil
;
10156 DEFVAR_LISP ("show-help-function", &Vshow_help_function
,
10157 "If non-nil, the function that implements the display of help.\n\
10158 It's called with one argument, the help string to display.");
10159 Vshow_help_function
= Qnil
;
10161 DEFVAR_LISP ("disable-point-adjustment", &Vdisable_point_adjustment
,
10162 "If non-nil, suppress point adjustment after executing a command.\n\
10164 After a command is executed, if point is moved into a region that has\n\
10165 special properties (e.g. composition, display), we adjust point to\n\
10166 the boundary of the region. But, several special commands sets this\n\
10167 variable to non-nil, then we suppress the point adjustment.\n\
10169 This variable is set to nil before reading a command, and is checked\n\
10170 just after executing the command");
10171 Vdisable_point_adjustment
= Qnil
;
10173 DEFVAR_LISP ("global-disable-point-adjustment",
10174 &Vglobal_disable_point_adjustment
,
10175 "*If non-nil, always suppress point adjustment.\n\
10177 The default value is nil, in which case, point adjustment are\n\
10178 suppressed only after special commands that set\n\
10179 `disable-point-adjustment' (which see) to non-nil.");
10180 Vglobal_disable_point_adjustment
= Qnil
;
10184 keys_of_keyboard ()
10186 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
10187 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
10188 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
10189 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
10190 initial_define_key (meta_map
, 'x', "execute-extended-command");
10192 initial_define_lispy_key (Vspecial_event_map
, "delete-frame",
10193 "handle-delete-frame");
10194 initial_define_lispy_key (Vspecial_event_map
, "iconify-frame",
10196 initial_define_lispy_key (Vspecial_event_map
, "make-frame-visible",