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 /* Global variable declarations. */
609 /* Function for init_keyboard to call with no args (if nonzero). */
610 void (*keyboard_init_hook
) ();
612 static int read_avail_input ();
613 static void get_input_pending ();
614 static int readable_events ();
615 static Lisp_Object
read_char_x_menu_prompt ();
616 static Lisp_Object
read_char_minibuf_menu_prompt ();
617 static Lisp_Object
make_lispy_event ();
619 static Lisp_Object
make_lispy_movement ();
621 static Lisp_Object
modify_event_symbol ();
622 static Lisp_Object
make_lispy_switch_frame ();
623 static int parse_solitary_modifier ();
624 static void save_getcjmp ();
625 static void restore_getcjmp ();
626 static Lisp_Object apply_modifiers
P_ ((int, Lisp_Object
));
628 /* > 0 if we are to echo keystrokes. */
629 static int echo_keystrokes
;
631 /* Nonzero means don't try to suspend even if the operating system seems
633 static int cannot_suspend
;
635 #define min(a,b) ((a)<(b)?(a):(b))
636 #define max(a,b) ((a)>(b)?(a):(b))
638 /* Install the string STR as the beginning of the string of echoing,
639 so that it serves as a prompt for the next character.
640 Also start echoing. */
646 int len
= strlen (str
);
648 if (len
> ECHOBUFSIZE
- 4)
649 len
= ECHOBUFSIZE
- 4;
650 bcopy (str
, current_kboard
->echobuf
, len
);
651 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
652 *current_kboard
->echoptr
= '\0';
654 current_kboard
->echo_after_prompt
= len
;
659 /* Add C to the echo string, if echoing is going on.
660 C can be a character, which is printed prettily ("M-C-x" and all that
661 jazz), or a symbol, whose name is printed. */
667 extern char *push_key_description ();
669 if (current_kboard
->immediate_echo
)
671 char *ptr
= current_kboard
->echoptr
;
673 if (ptr
!= current_kboard
->echobuf
)
676 /* If someone has passed us a composite event, use its head symbol. */
681 if (ptr
- current_kboard
->echobuf
682 > ECHOBUFSIZE
- KEY_DESCRIPTION_SIZE
)
685 ptr
= push_key_description (XINT (c
), ptr
);
687 else if (SYMBOLP (c
))
689 struct Lisp_String
*name
= XSYMBOL (c
)->name
;
690 if ((ptr
- current_kboard
->echobuf
) + STRING_BYTES (name
) + 4
693 bcopy (name
->data
, ptr
, STRING_BYTES (name
));
694 ptr
+= STRING_BYTES (name
);
697 if (current_kboard
->echoptr
== current_kboard
->echobuf
700 strcpy (ptr
, " (Type ? for further options)");
705 current_kboard
->echoptr
= ptr
;
711 /* Temporarily add a dash to the end of the echo string if it's not
712 empty, so that it serves as a mini-prompt for the very next character. */
717 if (!current_kboard
->immediate_echo
718 && current_kboard
->echoptr
== current_kboard
->echobuf
)
720 /* Do nothing if we just printed a prompt. */
721 if (current_kboard
->echo_after_prompt
722 == current_kboard
->echoptr
- current_kboard
->echobuf
)
724 /* Do nothing if not echoing at all. */
725 if (current_kboard
->echoptr
== 0)
728 /* Put a dash at the end of the buffer temporarily,
729 but make it go away when the next character is added. */
730 current_kboard
->echoptr
[0] = '-';
731 current_kboard
->echoptr
[1] = 0;
736 /* Display the current echo string, and begin echoing if not already
742 if (!current_kboard
->immediate_echo
)
745 current_kboard
->immediate_echo
= 1;
747 for (i
= 0; i
< this_command_key_count
; i
++)
750 c
= XVECTOR (this_command_keys
)->contents
[i
];
751 if (! (EVENT_HAS_PARAMETERS (c
)
752 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
759 echo_kboard
= current_kboard
;
760 message2_nolog (current_kboard
->echobuf
, strlen (current_kboard
->echobuf
),
761 ! NILP (current_buffer
->enable_multibyte_characters
));
764 if (waiting_for_input
&& !NILP (Vquit_flag
))
765 quit_throw_to_read_char ();
768 /* Turn off echoing, for the start of a new command. */
773 current_kboard
->immediate_echo
= 0;
774 current_kboard
->echoptr
= current_kboard
->echobuf
;
775 current_kboard
->echo_after_prompt
= -1;
776 ok_to_echo_at_next_pause
= 0;
780 /* Return the length of the current echo string. */
785 return current_kboard
->echoptr
- current_kboard
->echobuf
;
788 /* Truncate the current echo message to its first LEN chars.
789 This and echo_char get used by read_key_sequence when the user
790 switches frames while entering a key sequence. */
796 current_kboard
->echobuf
[len
] = '\0';
797 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
798 truncate_echo_area (len
);
802 /* Functions for manipulating this_command_keys. */
804 add_command_key (key
)
807 int size
= XVECTOR (this_command_keys
)->size
;
809 /* If reset-this-command-length was called recently, obey it now.
810 See the doc string of that function for an explanation of why. */
811 if (before_command_restore_flag
)
813 this_command_key_count
= before_command_key_count_1
;
814 if (this_command_key_count
< this_single_command_key_start
)
815 this_single_command_key_start
= this_command_key_count
;
816 echo_truncate (before_command_echo_length_1
);
817 before_command_restore_flag
= 0;
820 if (this_command_key_count
>= size
)
822 Lisp_Object new_keys
;
824 new_keys
= Fmake_vector (make_number (size
* 2), Qnil
);
825 bcopy (XVECTOR (this_command_keys
)->contents
,
826 XVECTOR (new_keys
)->contents
,
827 size
* sizeof (Lisp_Object
));
829 this_command_keys
= new_keys
;
832 XVECTOR (this_command_keys
)->contents
[this_command_key_count
++] = key
;
838 int count
= specpdl_ptr
- specpdl
;
841 if (command_loop_level
> 0)
843 specbind (Qstandard_output
, Qt
);
844 specbind (Qstandard_input
, Qt
);
847 val
= command_loop ();
849 Fsignal (Qquit
, Qnil
);
850 /* Handle throw from read_minibuf when using minibuffer
851 while it's active but we're in another window. */
853 Fsignal (Qerror
, Fcons (val
, Qnil
));
855 return unbind_to (count
, Qnil
);
858 /* When an auto-save happens, record the "time", and don't do again soon. */
863 last_auto_save
= num_nonmacro_input_events
;
866 /* Make an auto save happen as soon as possible at command level. */
869 force_auto_save_soon ()
871 last_auto_save
= - auto_save_interval
- 1;
873 record_asynch_buffer_change ();
876 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
877 "Invoke the editor command loop recursively.\n\
878 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
879 that tells this function to return.\n\
880 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
881 This function is called by the editor initialization to begin editing.")
884 int count
= specpdl_ptr
- specpdl
;
886 command_loop_level
++;
887 update_mode_lines
= 1;
889 record_unwind_protect (recursive_edit_unwind
,
891 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
895 return unbind_to (count
, Qnil
);
899 recursive_edit_unwind (buffer
)
903 Fset_buffer (buffer
);
905 command_loop_level
--;
906 update_mode_lines
= 1;
914 #if 0 /* Theory: if there's anything in Vunread_command_events,
915 it will right away be read by read_key_sequence,
916 and then if we do switch KBOARDS, it will go into the side
917 queue then. So we don't need to do anything special here -- rms. */
918 if (CONSP (Vunread_command_events
))
920 current_kboard
->kbd_queue
921 = nconc2 (Vunread_command_events
, current_kboard
->kbd_queue
);
922 current_kboard
->kbd_queue_has_data
= 1;
924 Vunread_command_events
= Qnil
;
930 /* Switch to the single-kboard state, making current_kboard
931 the only KBOARD from which further input is accepted. */
934 single_kboard_state ()
941 /* Maintain a stack of kboards, so other parts of Emacs
942 can switch temporarily to the kboard of a given frame
943 and then revert to the previous status. */
948 struct kboard_stack
*next
;
951 static struct kboard_stack
*kboard_stack
;
954 push_frame_kboard (f
)
958 struct kboard_stack
*p
959 = (struct kboard_stack
*) xmalloc (sizeof (struct kboard_stack
));
961 p
->next
= kboard_stack
;
962 p
->kboard
= current_kboard
;
965 current_kboard
= FRAME_KBOARD (f
);
973 struct kboard_stack
*p
= kboard_stack
;
974 current_kboard
= p
->kboard
;
975 kboard_stack
= p
->next
;
980 /* Handle errors that are not handled at inner levels
981 by printing an error message and returning to the editor command loop. */
987 Lisp_Object old_level
, old_length
;
990 if (!NILP (executing_macro
))
992 if (executing_macro_iterations
== 1)
993 sprintf (macroerror
, "After 1 kbd macro iteration: ");
995 sprintf (macroerror
, "After %d kbd macro iterations: ",
996 executing_macro_iterations
);
1001 Vstandard_output
= Qt
;
1002 Vstandard_input
= Qt
;
1003 Vexecuting_macro
= Qnil
;
1004 executing_macro
= Qnil
;
1005 current_kboard
->Vprefix_arg
= Qnil
;
1006 current_kboard
->Vlast_prefix_arg
= Qnil
;
1009 /* Avoid unquittable loop if data contains a circular list. */
1010 old_level
= Vprint_level
;
1011 old_length
= Vprint_length
;
1012 XSETFASTINT (Vprint_level
, 10);
1013 XSETFASTINT (Vprint_length
, 10);
1014 cmd_error_internal (data
, macroerror
);
1015 Vprint_level
= old_level
;
1016 Vprint_length
= old_length
;
1020 Vinhibit_quit
= Qnil
;
1022 any_kboard_state ();
1025 return make_number (0);
1028 /* Take actions on handling an error. DATA is the data that describes
1031 CONTEXT is a C-string containing ASCII characters only which
1032 describes the context in which the error happened. If we need to
1033 generalize CONTEXT to allow multibyte characters, make it a Lisp
1037 cmd_error_internal (data
, context
)
1042 int kill_emacs_p
= 0;
1043 struct frame
*sf
= SELECTED_FRAME ();
1047 clear_message (1, 0);
1049 /* If the window system or terminal frame hasn't been initialized
1050 yet, or we're not interactive, it's best to dump this message out
1051 to stderr and exit. */
1052 if (!sf
->glyphs_initialized_p
1053 /* This is the case of the frame dumped with Emacs, when we're
1054 running under a window system. */
1055 || (!NILP (Vwindow_system
)
1056 && !inhibit_window_system
1057 && FRAME_TERMCAP_P (sf
))
1060 stream
= Qexternal_debugging_output
;
1071 write_string_1 (context
, -1, stream
);
1073 print_error_message (data
, stream
);
1075 /* If the window system or terminal frame hasn't been initialized
1076 yet, or we're in -batch mode, this error should cause Emacs to exit. */
1080 Fkill_emacs (make_number (-1));
1084 Lisp_Object
command_loop_1 ();
1085 Lisp_Object
command_loop_2 ();
1086 Lisp_Object
top_level_1 ();
1088 /* Entry to editor-command-loop.
1089 This level has the catches for exiting/returning to editor command loop.
1090 It returns nil to exit recursive edit, t to abort it. */
1095 if (command_loop_level
> 0 || minibuf_level
> 0)
1098 val
= internal_catch (Qexit
, command_loop_2
, Qnil
);
1099 executing_macro
= Qnil
;
1105 internal_catch (Qtop_level
, top_level_1
, Qnil
);
1106 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
1107 executing_macro
= Qnil
;
1109 /* End of file in -batch run causes exit here. */
1115 /* Here we catch errors in execution of commands within the
1116 editing loop, and reenter the editing loop.
1117 When there is an error, cmd_error runs and returns a non-nil
1118 value to us. A value of nil means that cmd_loop_1 itself
1119 returned due to end of file (or end of kbd macro). */
1124 register Lisp_Object val
;
1127 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
1128 while (!NILP (val
));
1136 return Feval (Vtop_level
);
1142 /* On entry to the outer level, run the startup file */
1143 if (!NILP (Vtop_level
))
1144 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
1145 else if (!NILP (Vpurify_flag
))
1146 message ("Bare impure Emacs (standard Lisp code not loaded)");
1148 message ("Bare Emacs (standard Lisp code not loaded)");
1152 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
1153 "Exit all recursive editing levels.")
1156 Fthrow (Qtop_level
, Qnil
);
1159 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
1160 "Exit from the innermost recursive edit or minibuffer.")
1163 if (command_loop_level
> 0 || minibuf_level
> 0)
1164 Fthrow (Qexit
, Qnil
);
1166 error ("No recursive edit is in progress");
1169 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
1170 "Abort the command that requested this recursive edit or minibuffer input.")
1173 if (command_loop_level
> 0 || minibuf_level
> 0)
1176 error ("No recursive edit is in progress");
1179 /* This is the actual command reading loop,
1180 sans error-handling encapsulation. */
1182 Lisp_Object
Fcommand_execute ();
1183 static int read_key_sequence ();
1184 void safe_run_hooks ();
1192 Lisp_Object keybuf
[30];
1196 struct buffer
*prev_buffer
;
1198 int was_locked
= single_kboard
;
1201 current_kboard
->Vprefix_arg
= Qnil
;
1202 current_kboard
->Vlast_prefix_arg
= Qnil
;
1203 Vdeactivate_mark
= Qnil
;
1204 waiting_for_input
= 0;
1208 this_command_key_count
= 0;
1209 this_single_command_key_start
= 0;
1211 /* Make sure this hook runs after commands that get errors and
1212 throw to top level. */
1213 /* Note that the value cell will never directly contain nil
1214 if the symbol is a local variable. */
1215 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1216 safe_run_hooks (Qpost_command_hook
);
1218 /* If displaying a message, resize the echo area window to fit
1219 that message's size exactly. */
1220 if (!NILP (echo_area_buffer
[0]))
1221 resize_echo_area_axactly ();
1223 if (!NILP (Vdeferred_action_list
))
1224 call0 (Vdeferred_action_function
);
1226 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1228 if (NILP (Vunread_command_events
)
1229 && NILP (Vunread_input_method_events
)
1230 && NILP (Vunread_post_input_method_events
)
1231 && NILP (Vexecuting_macro
)
1232 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1, 1)))
1233 safe_run_hooks (Qpost_command_idle_hook
);
1236 /* Do this after running Vpost_command_hook, for consistency. */
1237 current_kboard
->Vlast_command
= Vthis_command
;
1238 current_kboard
->Vreal_last_command
= real_this_command
;
1242 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
1245 /* Make sure the current window's buffer is selected. */
1246 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1247 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1249 /* Display any malloc warning that just came out. Use while because
1250 displaying one warning can cause another. */
1252 while (pending_malloc_warning
)
1253 display_malloc_warning ();
1257 Vdeactivate_mark
= Qnil
;
1259 /* If minibuffer on and echo area in use,
1260 wait 2 sec and redraw minibuffer. */
1263 && !NILP (echo_area_buffer
[0])
1264 && EQ (minibuf_window
, echo_area_window
))
1266 /* Bind inhibit-quit to t so that C-g gets read in
1267 rather than quitting back to the minibuffer. */
1268 int count
= specpdl_ptr
- specpdl
;
1269 specbind (Qinhibit_quit
, Qt
);
1271 Fsit_for (make_number (2), Qnil
, Qnil
);
1272 /* Clear the echo area. */
1274 safe_run_hooks (Qecho_area_clear_hook
);
1276 unbind_to (count
, Qnil
);
1278 /* If a C-g came in before, treat it as input now. */
1279 if (!NILP (Vquit_flag
))
1282 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1287 alloca (0); /* Cause a garbage collection now */
1288 /* Since we can free the most stuff here. */
1289 #endif /* C_ALLOCA */
1292 /* Select the frame that the last event came from. Usually,
1293 switch-frame events will take care of this, but if some lisp
1294 code swallows a switch-frame event, we'll fix things up here.
1295 Is this a good idea? */
1296 if (FRAMEP (internal_last_event_frame
)
1297 && !EQ (internal_last_event_frame
, selected_frame
))
1298 Fselect_frame (internal_last_event_frame
, Qnil
);
1300 /* If it has changed current-menubar from previous value,
1301 really recompute the menubar from the value. */
1302 if (! NILP (Vlucid_menu_bar_dirty_flag
)
1303 && !NILP (Ffboundp (Qrecompute_lucid_menubar
)))
1304 call0 (Qrecompute_lucid_menubar
);
1306 before_command_key_count
= this_command_key_count
;
1307 before_command_echo_length
= echo_length ();
1309 Vthis_command
= Qnil
;
1310 real_this_command
= Qnil
;
1312 /* Read next key sequence; i gets its length. */
1313 i
= read_key_sequence (keybuf
, sizeof keybuf
/ sizeof keybuf
[0],
1316 /* A filter may have run while we were reading the input. */
1317 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
1319 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1320 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1324 /* Now we have read a key sequence of length I,
1325 or else I is 0 and we found end of file. */
1327 if (i
== 0) /* End of file -- happens only in */
1328 return Qnil
; /* a kbd macro, at the end. */
1329 /* -1 means read_key_sequence got a menu that was rejected.
1330 Just loop around and read another command. */
1334 this_command_key_count
= 0;
1335 this_single_command_key_start
= 0;
1339 last_command_char
= keybuf
[i
- 1];
1341 /* If the previous command tried to force a specific window-start,
1342 forget about that, in case this command moves point far away
1343 from that position. But also throw away beg_unchanged and
1344 end_unchanged information in that case, so that redisplay will
1345 update the whole window properly. */
1346 if (!NILP (XWINDOW (selected_window
)->force_start
))
1349 XWINDOW (selected_window
)->force_start
= Qnil
;
1350 b
= XBUFFER (XWINDOW (selected_window
)->buffer
);
1351 BUF_BEG_UNCHANGED (b
) = BUF_END_UNCHANGED (b
) = 0;
1354 cmd
= read_key_sequence_cmd
;
1355 if (!NILP (Vexecuting_macro
))
1357 if (!NILP (Vquit_flag
))
1359 Vexecuting_macro
= Qt
;
1360 QUIT
; /* Make some noise. */
1361 /* Will return since macro now empty. */
1365 /* Do redisplay processing after this command except in special
1366 cases identified below. */
1367 prev_buffer
= current_buffer
;
1368 prev_modiff
= MODIFF
;
1369 last_point_position
= PT
;
1370 XSETBUFFER (last_point_position_buffer
, prev_buffer
);
1372 /* Execute the command. */
1374 Vthis_command
= cmd
;
1375 real_this_command
= cmd
;
1376 /* Note that the value cell will never directly contain nil
1377 if the symbol is a local variable. */
1378 if (!NILP (Vpre_command_hook
) && !NILP (Vrun_hooks
))
1379 safe_run_hooks (Qpre_command_hook
);
1381 if (NILP (Vthis_command
))
1383 /* nil means key is undefined. */
1385 current_kboard
->defining_kbd_macro
= Qnil
;
1386 update_mode_lines
= 1;
1387 current_kboard
->Vprefix_arg
= Qnil
;
1391 if (NILP (current_kboard
->Vprefix_arg
) && ! no_direct
)
1393 /* In case we jump to directly_done. */
1394 Vcurrent_prefix_arg
= current_kboard
->Vprefix_arg
;
1396 /* Recognize some common commands in common situations and
1397 do them directly. */
1398 if (EQ (Vthis_command
, Qforward_char
) && PT
< ZV
)
1400 struct Lisp_Char_Table
*dp
1401 = window_display_table (XWINDOW (selected_window
));
1402 lose
= FETCH_CHAR (PT_BYTE
);
1405 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1406 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1407 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1408 && (lose
>= 0x20 && lose
< 0x7f)))
1409 : (lose
>= 0x20 && lose
< 0x7f))
1410 /* To extract the case of continuation on
1411 wide-column characters. */
1412 && (WIDTH_BY_CHAR_HEAD (FETCH_BYTE (PT_BYTE
)) == 1)
1413 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1415 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1417 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1419 && !windows_or_buffers_changed
1420 && EQ (current_buffer
->selective_display
, Qnil
)
1421 && !detect_input_pending ()
1422 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1423 && NILP (Vexecuting_macro
))
1424 direct_output_forward_char (1);
1427 else if (EQ (Vthis_command
, Qbackward_char
) && PT
> BEGV
)
1429 struct Lisp_Char_Table
*dp
1430 = window_display_table (XWINDOW (selected_window
));
1432 lose
= FETCH_CHAR (PT_BYTE
);
1434 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1435 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1436 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1437 && (lose
>= 0x20 && lose
< 0x7f)))
1438 : (lose
>= 0x20 && lose
< 0x7f))
1439 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1441 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1443 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1445 && !windows_or_buffers_changed
1446 && EQ (current_buffer
->selective_display
, Qnil
)
1447 && !detect_input_pending ()
1448 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1449 && NILP (Vexecuting_macro
))
1450 direct_output_forward_char (-1);
1453 else if (EQ (Vthis_command
, Qself_insert_command
)
1454 /* Try this optimization only on ascii keystrokes. */
1455 && INTEGERP (last_command_char
))
1457 unsigned int c
= XINT (last_command_char
);
1459 if (NILP (Vexecuting_macro
)
1460 && !EQ (minibuf_window
, selected_window
))
1462 if (!nonundocount
|| nonundocount
>= 20)
1470 lose
= ((XFASTINT (XWINDOW (selected_window
)->last_modified
)
1472 || (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1474 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1476 || MODIFF
<= SAVE_MODIFF
1477 || windows_or_buffers_changed
1478 || !EQ (current_buffer
->selective_display
, Qnil
)
1479 || detect_input_pending ()
1480 || !NILP (XWINDOW (selected_window
)->column_number_displayed
)
1481 || !NILP (Vexecuting_macro
));
1483 value
= internal_self_insert (c
, 0);
1488 /* VALUE == 1 when AFTER-CHANGE functions are
1489 installed which is the case most of the time
1490 because FONT-LOCK installs one. */
1491 if (!lose
&& !value
)
1492 direct_output_for_insert (c
);
1497 /* Here for a command that isn't executed directly */
1499 #ifdef HAVE_X_WINDOWS
1500 if (display_busy_cursor_p
)
1502 if (inhibit_busy_cursor
!= 2)
1503 inhibit_busy_cursor
= 0;
1504 if (!inhibit_busy_cursor
)
1505 Fx_show_busy_cursor ();
1510 if (NILP (current_kboard
->Vprefix_arg
))
1512 Fcommand_execute (Vthis_command
, Qnil
, Qnil
, Qnil
);
1515 current_kboard
->Vlast_prefix_arg
= Vcurrent_prefix_arg
;
1517 /* Note that the value cell will never directly contain nil
1518 if the symbol is a local variable. */
1519 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1520 safe_run_hooks (Qpost_command_hook
);
1522 /* If displaying a message, resize the echo area window to fit
1523 that message's size exactly. */
1524 if (!NILP (echo_area_buffer
[0]))
1525 resize_echo_area_axactly ();
1527 if (!NILP (Vdeferred_action_list
))
1528 safe_run_hooks (Qdeferred_action_function
);
1530 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1532 if (NILP (Vunread_command_events
)
1533 && NILP (Vunread_input_method_events
)
1534 && NILP (Vunread_post_input_method_events
)
1535 && NILP (Vexecuting_macro
)
1536 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1, 1)))
1537 safe_run_hooks (Qpost_command_idle_hook
);
1540 /* If there is a prefix argument,
1541 1) We don't want Vlast_command to be ``universal-argument''
1542 (that would be dumb), so don't set Vlast_command,
1543 2) we want to leave echoing on so that the prefix will be
1544 echoed as part of this key sequence, so don't call
1546 3) we want to leave this_command_key_count non-zero, so that
1547 read_char will realize that it is re-reading a character, and
1548 not echo it a second time.
1550 If the command didn't actually create a prefix arg,
1551 but is merely a frame event that is transparent to prefix args,
1552 then the above doesn't apply. */
1553 if (NILP (current_kboard
->Vprefix_arg
) || CONSP (last_command_char
))
1555 current_kboard
->Vlast_command
= Vthis_command
;
1556 current_kboard
->Vreal_last_command
= real_this_command
;
1558 this_command_key_count
= 0;
1559 this_single_command_key_start
= 0;
1562 if (!NILP (current_buffer
->mark_active
) && !NILP (Vrun_hooks
))
1564 if (!NILP (Vdeactivate_mark
) && !NILP (Vtransient_mark_mode
))
1566 current_buffer
->mark_active
= Qnil
;
1567 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
1569 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
1570 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
1574 /* Install chars successfully executed in kbd macro. */
1576 if (!NILP (current_kboard
->defining_kbd_macro
)
1577 && NILP (current_kboard
->Vprefix_arg
))
1578 finalize_kbd_macro_chars ();
1582 any_kboard_state ();
1587 /* Subroutine for safe_run_hooks: run the hook HOOK. */
1590 safe_run_hooks_1 (hook
)
1593 return call1 (Vrun_hooks
, Vinhibit_quit
);
1596 /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */
1599 safe_run_hooks_error (data
)
1602 Fset (Vinhibit_quit
, Qnil
);
1605 /* If we get an error while running the hook, cause the hook variable
1606 to be nil. Also inhibit quits, so that C-g won't cause the hook
1607 to mysteriously evaporate. */
1610 safe_run_hooks (hook
)
1613 int count
= specpdl_ptr
- specpdl
;
1614 specbind (Qinhibit_quit
, hook
);
1616 internal_condition_case (safe_run_hooks_1
, Qt
, safe_run_hooks_error
);
1618 unbind_to (count
, Qnil
);
1621 /* Number of seconds between polling for input. */
1624 /* Nonzero means polling for input is temporarily suppressed. */
1625 int poll_suppress_count
;
1627 /* Nonzero if polling_for_input is actually being used. */
1628 int polling_for_input
;
1630 #ifdef POLL_FOR_INPUT
1632 /* Handle an alarm once each second and read pending input
1633 so as to handle a C-g if it comces in. */
1636 input_poll_signal (signalnum
) /* If we don't have an argument, */
1637 int signalnum
; /* some compilers complain in signal calls. */
1639 /* This causes the call to start_polling at the end
1640 to do its job. It also arranges for a quit or error
1641 from within read_avail_input to resume polling. */
1642 poll_suppress_count
++;
1643 if (interrupt_input_blocked
== 0
1644 && !waiting_for_input
)
1645 read_avail_input (0);
1646 /* Turn on the SIGALRM handler and request another alarm. */
1652 /* Begin signals to poll for input, if they are appropriate.
1653 This function is called unconditionally from various places. */
1658 #ifdef POLL_FOR_INPUT
1659 if (read_socket_hook
&& !interrupt_input
)
1661 poll_suppress_count
--;
1662 if (poll_suppress_count
== 0)
1664 signal (SIGALRM
, input_poll_signal
);
1665 polling_for_input
= 1;
1666 alarm (polling_period
);
1672 /* Nonzero if we are using polling to handle input asynchronously. */
1675 input_polling_used ()
1677 #ifdef POLL_FOR_INPUT
1678 return read_socket_hook
&& !interrupt_input
;
1684 /* Turn off polling. */
1689 #ifdef POLL_FOR_INPUT
1690 if (read_socket_hook
&& !interrupt_input
)
1692 if (poll_suppress_count
== 0)
1694 polling_for_input
= 0;
1697 poll_suppress_count
++;
1702 /* Set the value of poll_suppress_count to COUNT
1703 and start or stop polling accordingly. */
1706 set_poll_suppress_count (count
)
1709 #ifdef POLL_FOR_INPUT
1710 if (count
== 0 && poll_suppress_count
!= 0)
1712 poll_suppress_count
= 1;
1715 else if (count
!= 0 && poll_suppress_count
== 0)
1719 poll_suppress_count
= count
;
1723 /* Bind polling_period to a value at least N.
1724 But don't decrease it. */
1727 bind_polling_period (n
)
1730 #ifdef POLL_FOR_INPUT
1731 int new = polling_period
;
1737 specbind (Qpolling_period
, make_number (new));
1738 /* Start a new alarm with the new period. */
1743 /* Apply the control modifier to CHARACTER. */
1749 /* Save the upper bits here. */
1750 int upper
= c
& ~0177;
1754 /* Everything in the columns containing the upper-case letters
1755 denotes a control character. */
1756 if (c
>= 0100 && c
< 0140)
1760 /* Set the shift modifier for a control char
1761 made from a shifted letter. But only for letters! */
1762 if (oc
>= 'A' && oc
<= 'Z')
1763 c
|= shift_modifier
;
1766 /* The lower-case letters denote control characters too. */
1767 else if (c
>= 'a' && c
<= 'z')
1770 /* Include the bits for control and shift
1771 only if the basic ASCII code can't indicate them. */
1775 /* Replace the high bits. */
1776 c
|= (upper
& ~ctrl_modifier
);
1783 /* Input of single characters from keyboard */
1785 Lisp_Object
print_help ();
1786 static Lisp_Object
kbd_buffer_get_event ();
1787 static void record_char ();
1790 static jmp_buf wrong_kboard_jmpbuf
;
1793 /* read a character from the keyboard; call the redisplay if needed */
1794 /* commandflag 0 means do not do auto-saving, but do do redisplay.
1795 -1 means do not do redisplay, but do do autosaving.
1798 /* The arguments MAPS and NMAPS are for menu prompting.
1799 MAPS is an array of keymaps; NMAPS is the length of MAPS.
1801 PREV_EVENT is the previous input event, or nil if we are reading
1802 the first event of a key sequence (or not reading a key sequence).
1803 If PREV_EVENT is t, that is a "magic" value that says
1804 not to run input methods, but in other respects to act as if
1805 not reading a key sequence.
1807 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
1808 if we used a mouse menu to read the input, or zero otherwise. If
1809 USED_MOUSE_MENU is null, we don't dereference it.
1811 Value is t if we showed a menu and the user rejected it. */
1814 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
)
1818 Lisp_Object prev_event
;
1819 int *used_mouse_menu
;
1823 jmp_buf local_getcjmp
;
1825 int key_already_recorded
= 0;
1826 Lisp_Object tem
, save
;
1827 Lisp_Object previous_echo_area_message
;
1828 Lisp_Object also_record
;
1830 struct gcpro gcpro1
, gcpro2
;
1834 before_command_key_count
= this_command_key_count
;
1835 before_command_echo_length
= echo_length ();
1837 previous_echo_area_message
= Qnil
;
1839 GCPRO2 (c
, previous_echo_area_message
);
1844 if (CONSP (Vunread_post_input_method_events
))
1846 c
= XCAR (Vunread_post_input_method_events
);
1847 Vunread_post_input_method_events
1848 = XCDR (Vunread_post_input_method_events
);
1850 /* Undo what read_char_x_menu_prompt did when it unread
1851 additional keys returned by Fx_popup_menu. */
1853 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
)))
1861 if (unread_command_char
!= -1)
1863 XSETINT (c
, unread_command_char
);
1864 unread_command_char
= -1;
1870 if (CONSP (Vunread_command_events
))
1872 c
= XCAR (Vunread_command_events
);
1873 Vunread_command_events
= XCDR (Vunread_command_events
);
1875 /* Undo what read_char_x_menu_prompt did when it unread
1876 additional keys returned by Fx_popup_menu. */
1878 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
)))
1883 goto reread_for_input_method
;
1886 if (CONSP (Vunread_input_method_events
))
1888 c
= XCAR (Vunread_input_method_events
);
1889 Vunread_input_method_events
= XCDR (Vunread_input_method_events
);
1891 /* Undo what read_char_x_menu_prompt did when it unread
1892 additional keys returned by Fx_popup_menu. */
1894 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
)))
1898 goto reread_for_input_method
;
1901 /* If there is no function key translated before
1902 reset-this-command-lengths takes effect, forget about it. */
1903 before_command_restore_flag
= 0;
1905 if (!NILP (Vexecuting_macro
))
1907 /* We set this to Qmacro; since that's not a frame, nobody will
1908 try to switch frames on us, and the selected window will
1911 Since this event came from a macro, it would be misleading to
1912 leave internal_last_event_frame set to wherever the last
1913 real event came from. Normally, a switch-frame event selects
1914 internal_last_event_frame after each command is read, but
1915 events read from a macro should never cause a new frame to be
1917 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
1919 /* Exit the macro if we are at the end.
1920 Also, some things replace the macro with t
1921 to force an early exit. */
1922 if (EQ (Vexecuting_macro
, Qt
)
1923 || executing_macro_index
>= XFASTINT (Flength (Vexecuting_macro
)))
1929 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
1930 if (STRINGP (Vexecuting_macro
)
1931 && (XINT (c
) & 0x80))
1932 XSETFASTINT (c
, CHAR_META
| (XINT (c
) & ~0x80));
1934 executing_macro_index
++;
1939 if (!NILP (unread_switch_frame
))
1941 c
= unread_switch_frame
;
1942 unread_switch_frame
= Qnil
;
1944 /* This event should make it into this_command_keys, and get echoed
1945 again, so we do not set `reread'. */
1949 /* if redisplay was requested */
1950 if (commandflag
>= 0)
1952 /* If there is pending input, process any events which are not
1953 user-visible, such as X selection_request events. */
1955 || detect_input_pending_run_timers (0))
1956 swallow_events (0); /* may clear input_pending */
1958 /* Redisplay if no pending input. */
1959 while (!input_pending
)
1964 /* Normal case: no input arrived during redisplay. */
1967 /* Input arrived and pre-empted redisplay.
1968 Process any events which are not user-visible. */
1970 /* If that cleared input_pending, try again to redisplay. */
1974 /* Message turns off echoing unless more keystrokes turn it on again. */
1975 if (/* There is a current message. */
1976 !NILP (echo_area_buffer
[0])
1977 /* And we're not echoing from this kboard. */
1978 && echo_kboard
!= current_kboard
1979 /* And it's either not ok to echo (ok_to_echo == NULL), or the
1980 last char echoed was from a different kboard. */
1981 && ok_to_echo_at_next_pause
!= echo_kboard
)
1984 /* If already echoing, continue. */
1987 /* Try reading a character via menu prompting in the minibuf.
1988 Try this before the sit-for, because the sit-for
1989 would do the wrong thing if we are supposed to do
1990 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
1991 after a mouse event so don't try a minibuf menu. */
1993 if (nmaps
> 0 && INTERACTIVE
1994 && !NILP (prev_event
) && ! EVENT_HAS_PARAMETERS (prev_event
)
1995 /* Don't bring up a menu if we already have another event. */
1996 && NILP (Vunread_command_events
)
1997 && unread_command_char
< 0
1998 && !detect_input_pending_run_timers (0))
2000 c
= read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
);
2003 key_already_recorded
= 1;
2008 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet.
2009 We will do that below, temporarily for short sections of code,
2010 when appropriate. local_getcjmp must be in effect
2011 around any call to sit_for or kbd_buffer_get_event;
2012 it *must not* be in effect when we call redisplay. */
2014 if (_setjmp (local_getcjmp
))
2016 XSETINT (c
, quit_char
);
2017 internal_last_event_frame
= selected_frame
;
2018 Vlast_event_frame
= internal_last_event_frame
;
2019 /* If we report the quit char as an event,
2020 don't do so more than once. */
2021 if (!NILP (Vinhibit_quit
))
2026 KBOARD
*kb
= FRAME_KBOARD (XFRAME (selected_frame
));
2027 if (kb
!= current_kboard
)
2029 Lisp_Object
*tailp
= &kb
->kbd_queue
;
2030 /* We shouldn't get here if we were in single-kboard mode! */
2033 while (CONSP (*tailp
))
2034 tailp
= &XCDR (*tailp
);
2037 *tailp
= Fcons (c
, Qnil
);
2038 kb
->kbd_queue_has_data
= 1;
2039 current_kboard
= kb
;
2040 /* This is going to exit from read_char
2041 so we had better get rid of this frame's stuff. */
2043 longjmp (wrong_kboard_jmpbuf
, 1);
2050 timer_start_idle ();
2052 /* If in middle of key sequence and minibuffer not active,
2053 start echoing if enough time elapses. */
2055 if (minibuf_level
== 0
2056 && !current_kboard
->immediate_echo
2057 && this_command_key_count
> 0
2059 && echo_keystrokes
> 0
2060 && (/* No message. */
2061 NILP (echo_area_buffer
[0])
2062 /* Or empty message. */
2063 || (BUF_BEG (XBUFFER (echo_area_buffer
[0]))
2064 == BUF_Z (XBUFFER (echo_area_buffer
[0])))
2065 /* Or already echoing from same kboard. */
2066 || (echo_kboard
&& ok_to_echo_at_next_pause
== echo_kboard
)
2067 /* Or not echoing before and echoing allowed. */
2068 || (!echo_kboard
&& ok_to_echo_at_next_pause
)))
2072 /* After a mouse event, start echoing right away.
2073 This is because we are probably about to display a menu,
2074 and we don't want to delay before doing so. */
2075 if (EVENT_HAS_PARAMETERS (prev_event
))
2079 save_getcjmp (save_jump
);
2080 restore_getcjmp (local_getcjmp
);
2081 tem0
= sit_for (echo_keystrokes
, 0, 1, 1, 0);
2082 restore_getcjmp (save_jump
);
2084 && ! CONSP (Vunread_command_events
))
2089 /* Maybe auto save due to number of keystrokes. */
2091 if (commandflag
!= 0
2092 && auto_save_interval
> 0
2093 && num_nonmacro_input_events
- last_auto_save
> max (auto_save_interval
, 20)
2094 && !detect_input_pending_run_timers (0))
2096 Fdo_auto_save (Qnil
, Qnil
);
2097 /* Hooks can actually change some buffers in auto save. */
2101 /* Try reading using an X menu.
2102 This is never confused with reading using the minibuf
2103 because the recursive call of read_char in read_char_minibuf_menu_prompt
2104 does not pass on any keymaps. */
2106 if (nmaps
> 0 && INTERACTIVE
2107 && !NILP (prev_event
)
2108 && EVENT_HAS_PARAMETERS (prev_event
)
2109 && !EQ (XCAR (prev_event
), Qmenu_bar
)
2110 && !EQ (XCAR (prev_event
), Qtool_bar
)
2111 /* Don't bring up a menu if we already have another event. */
2112 && NILP (Vunread_command_events
)
2113 && unread_command_char
< 0)
2115 c
= read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
2117 /* Now that we have read an event, Emacs is not idle. */
2123 /* Maybe autosave and/or garbage collect due to idleness. */
2125 if (INTERACTIVE
&& NILP (c
))
2127 int delay_level
, buffer_size
;
2129 /* Slow down auto saves logarithmically in size of current buffer,
2130 and garbage collect while we're at it. */
2131 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
2132 last_non_minibuf_size
= Z
- BEG
;
2133 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
2135 while (buffer_size
> 64)
2136 delay_level
++, buffer_size
-= buffer_size
>> 2;
2137 if (delay_level
< 4) delay_level
= 4;
2138 /* delay_level is 4 for files under around 50k, 7 at 100k,
2139 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
2141 /* Auto save if enough time goes by without input. */
2142 if (commandflag
!= 0
2143 && num_nonmacro_input_events
> last_auto_save
2144 && INTEGERP (Vauto_save_timeout
)
2145 && XINT (Vauto_save_timeout
) > 0)
2149 save_getcjmp (save_jump
);
2150 restore_getcjmp (local_getcjmp
);
2151 tem0
= sit_for (delay_level
* XFASTINT (Vauto_save_timeout
) / 4,
2153 restore_getcjmp (save_jump
);
2156 && ! CONSP (Vunread_command_events
))
2158 Fdo_auto_save (Qnil
, Qnil
);
2160 /* If we have auto-saved and there is still no input
2161 available, garbage collect if there has been enough
2162 consing going on to make it worthwhile. */
2163 if (!detect_input_pending_run_timers (0)
2164 && consing_since_gc
> gc_cons_threshold
/ 2)
2165 Fgarbage_collect ();
2172 /* If this has become non-nil here, it has been set by a timer
2173 or sentinel or filter. */
2174 if (CONSP (Vunread_command_events
))
2176 c
= XCAR (Vunread_command_events
);
2177 Vunread_command_events
= XCDR (Vunread_command_events
);
2180 /* Read something from current KBOARD's side queue, if possible. */
2184 if (current_kboard
->kbd_queue_has_data
)
2186 if (!CONSP (current_kboard
->kbd_queue
))
2188 c
= XCAR (current_kboard
->kbd_queue
);
2189 current_kboard
->kbd_queue
2190 = XCDR (current_kboard
->kbd_queue
);
2191 if (NILP (current_kboard
->kbd_queue
))
2192 current_kboard
->kbd_queue_has_data
= 0;
2193 input_pending
= readable_events (0);
2194 if (EVENT_HAS_PARAMETERS (c
)
2195 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qswitch_frame
))
2196 internal_last_event_frame
= XCAR (XCDR (c
));
2197 Vlast_event_frame
= internal_last_event_frame
;
2202 /* If current_kboard's side queue is empty check the other kboards.
2203 If one of them has data that we have not yet seen here,
2204 switch to it and process the data waiting for it.
2206 Note: if the events queued up for another kboard
2207 have already been seen here, and therefore are not a complete command,
2208 the kbd_queue_has_data field is 0, so we skip that kboard here.
2209 That's to avoid an infinite loop switching between kboards here. */
2210 if (NILP (c
) && !single_kboard
)
2213 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2214 if (kb
->kbd_queue_has_data
)
2216 current_kboard
= kb
;
2217 /* This is going to exit from read_char
2218 so we had better get rid of this frame's stuff. */
2220 longjmp (wrong_kboard_jmpbuf
, 1);
2229 /* Finally, we read from the main queue,
2230 and if that gives us something we can't use yet, we put it on the
2231 appropriate side queue and try again. */
2237 /* Actually read a character, waiting if necessary. */
2238 save_getcjmp (save_jump
);
2239 restore_getcjmp (local_getcjmp
);
2240 c
= kbd_buffer_get_event (&kb
, used_mouse_menu
);
2241 restore_getcjmp (save_jump
);
2244 if (! NILP (c
) && (kb
!= current_kboard
))
2246 Lisp_Object
*tailp
= &kb
->kbd_queue
;
2247 while (CONSP (*tailp
))
2248 tailp
= &XCDR (*tailp
);
2251 *tailp
= Fcons (c
, Qnil
);
2252 kb
->kbd_queue_has_data
= 1;
2256 current_kboard
= kb
;
2257 /* This is going to exit from read_char
2258 so we had better get rid of this frame's stuff. */
2260 longjmp (wrong_kboard_jmpbuf
, 1);
2265 /* Terminate Emacs in batch mode if at eof. */
2266 if (noninteractive
&& INTEGERP (c
) && XINT (c
) < 0)
2267 Fkill_emacs (make_number (1));
2271 /* Add in any extra modifiers, where appropriate. */
2272 if ((extra_keyboard_modifiers
& CHAR_CTL
)
2273 || ((extra_keyboard_modifiers
& 0177) < ' '
2274 && (extra_keyboard_modifiers
& 0177) != 0))
2275 XSETINT (c
, make_ctrl_char (XINT (c
)));
2277 /* Transfer any other modifier bits directly from
2278 extra_keyboard_modifiers to c. Ignore the actual character code
2279 in the low 16 bits of extra_keyboard_modifiers. */
2280 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
2291 if (commandflag
>= 0
2292 && !input_pending
&& !detect_input_pending_run_timers (0))
2300 /* Buffer switch events are only for internal wakeups
2301 so don't show them to the user.
2302 Also, don't record a key if we already did. */
2303 if (BUFFERP (c
) || key_already_recorded
)
2306 /* Process special events within read_char
2307 and loop around to read another event. */
2310 tem
= get_keyelt (access_keymap (get_keymap_1 (Vspecial_event_map
, 0, 0),
2316 int was_locked
= single_kboard
;
2318 last_input_char
= c
;
2319 Fcommand_execute (tem
, Qnil
, Fvector (1, &last_input_char
), Qt
);
2321 /* Resume allowing input from any kboard, if that was true before. */
2323 any_kboard_state ();
2328 /* Handle things that only apply to characters. */
2331 /* If kbd_buffer_get_event gave us an EOF, return that. */
2335 if ((STRINGP (Vkeyboard_translate_table
)
2336 && XSTRING (Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
2337 || (VECTORP (Vkeyboard_translate_table
)
2338 && XVECTOR (Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
2339 || (CHAR_TABLE_P (Vkeyboard_translate_table
)
2340 && CHAR_TABLE_ORDINARY_SLOTS
> (unsigned) XFASTINT (c
)))
2343 d
= Faref (Vkeyboard_translate_table
, c
);
2344 /* nil in keyboard-translate-table means no translation. */
2350 /* If this event is a mouse click in the menu bar,
2351 return just menu-bar for now. Modify the mouse click event
2352 so we won't do this twice, then queue it up. */
2353 if (EVENT_HAS_PARAMETERS (c
)
2355 && CONSP (EVENT_START (c
))
2356 && CONSP (XCDR (EVENT_START (c
))))
2360 posn
= POSN_BUFFER_POSN (EVENT_START (c
));
2361 /* Handle menu-bar events:
2362 insert the dummy prefix event `menu-bar'. */
2363 if (EQ (posn
, Qmenu_bar
) || EQ (posn
, Qtool_bar
))
2365 /* Change menu-bar to (menu-bar) as the event "position". */
2366 POSN_BUFFER_POSN (EVENT_START (c
)) = Fcons (posn
, Qnil
);
2369 Vunread_command_events
= Fcons (c
, Vunread_command_events
);
2374 /* Store these characters into recent_keys, the dribble file if any,
2375 and the keyboard macro being defined, if any. */
2377 if (! NILP (also_record
))
2378 record_char (also_record
);
2380 /* Wipe the echo area.
2381 But first, if we are about to use an input method,
2382 save the echo area contents for it to refer to. */
2384 && ! NILP (Vinput_method_function
)
2385 && (unsigned) XINT (c
) >= ' '
2386 && (unsigned) XINT (c
) < 127)
2388 previous_echo_area_message
= Fcurrent_message ();
2389 Vinput_method_previous_message
= previous_echo_area_message
;
2392 /* Now wipe the echo area. */
2393 if (!NILP (echo_area_buffer
[0]))
2394 safe_run_hooks (Qecho_area_clear_hook
);
2395 clear_message (1, 0);
2397 reread_for_input_method
:
2399 /* Pass this to the input method, if appropriate. */
2401 && ! NILP (Vinput_method_function
)
2402 /* Don't run the input method within a key sequence,
2403 after the first event of the key sequence. */
2404 && NILP (prev_event
)
2405 && (unsigned) XINT (c
) >= ' '
2406 && (unsigned) XINT (c
) < 127)
2410 struct gcpro gcpro1
;
2411 int count
= specpdl_ptr
- specpdl
;
2413 /* Save the echo status. */
2414 int saved_immediate_echo
= current_kboard
->immediate_echo
;
2415 struct kboard
*saved_ok_to_echo
= ok_to_echo_at_next_pause
;
2416 int saved_echo_after_prompt
= current_kboard
->echo_after_prompt
;
2418 if (before_command_restore_flag
)
2420 this_command_key_count
= before_command_key_count_1
;
2421 if (this_command_key_count
< this_single_command_key_start
)
2422 this_single_command_key_start
= this_command_key_count
;
2423 echo_truncate (before_command_echo_length_1
);
2424 before_command_restore_flag
= 0;
2427 /* Save the this_command_keys status. */
2428 key_count
= this_command_key_count
;
2431 keys
= Fcopy_sequence (this_command_keys
);
2436 /* Clear out this_command_keys. */
2437 this_command_key_count
= 0;
2439 /* Now wipe the echo area. */
2440 if (!NILP (echo_area_buffer
[0]))
2441 safe_run_hooks (Qecho_area_clear_hook
);
2442 clear_message (1, 0);
2445 /* If we are not reading a key sequence,
2446 never use the echo area. */
2449 specbind (Qinput_method_use_echo_area
, Qt
);
2452 /* Call the input method. */
2453 tem
= call1 (Vinput_method_function
, c
);
2455 tem
= unbind_to (count
, tem
);
2457 /* Restore the saved echoing state
2458 and this_command_keys state. */
2459 this_command_key_count
= key_count
;
2461 this_command_keys
= keys
;
2464 ok_to_echo_at_next_pause
= saved_ok_to_echo
;
2465 current_kboard
->echo_after_prompt
= saved_echo_after_prompt
;
2466 if (saved_immediate_echo
)
2471 /* The input method can return no events. */
2474 /* Bring back the previous message, if any. */
2475 if (! NILP (previous_echo_area_message
))
2476 message_with_string ("%s", previous_echo_area_message
, 0);
2479 /* It returned one event or more. */
2481 Vunread_post_input_method_events
2482 = nconc2 (XCDR (tem
), Vunread_post_input_method_events
);
2487 /* Display help if not echoing. */
2489 && EQ (XCAR (c
), Qhelp_echo
))
2491 Lisp_Object msg
= XCDR (XCDR (c
));
2493 if (!NILP (Vshow_help_function
))
2494 call1 (Vshow_help_function
, msg
);
2495 else if (!echoing
&& !MINI_WINDOW_P (XWINDOW (selected_window
)))
2498 message3_nolog (msg
, XSTRING (msg
)->size
, STRING_MULTIBYTE (msg
));
2506 if (this_command_key_count
== 0 || ! reread
)
2508 before_command_key_count
= this_command_key_count
;
2509 before_command_echo_length
= echo_length ();
2511 /* Don't echo mouse motion events. */
2513 && ! (EVENT_HAS_PARAMETERS (c
)
2514 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
2517 if (! NILP (also_record
))
2518 echo_char (also_record
);
2519 /* Once we reread a character, echoing can happen
2520 the next time we pause to read a new one. */
2521 ok_to_echo_at_next_pause
= current_kboard
;
2524 /* Record this character as part of the current key. */
2525 add_command_key (c
);
2526 if (! NILP (also_record
))
2527 add_command_key (also_record
);
2530 last_input_char
= c
;
2533 /* Process the help character specially if enabled */
2534 if (!NILP (Vhelp_form
) && help_char_p (c
))
2537 count
= specpdl_ptr
- specpdl
;
2539 record_unwind_protect (Fset_window_configuration
,
2540 Fcurrent_window_configuration (Qnil
));
2542 tem0
= Feval (Vhelp_form
);
2544 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
2548 c
= read_char (0, 0, 0, Qnil
, 0);
2549 while (BUFFERP (c
));
2550 /* Remove the help from the frame */
2551 unbind_to (count
, Qnil
);
2554 if (EQ (c
, make_number (040)))
2558 c
= read_char (0, 0, 0, Qnil
, 0);
2559 while (BUFFERP (c
));
2566 /* Record a key that came from a mouse menu.
2567 Record it for echoing, for this-command-keys, and so on. */
2573 /* Wipe the echo area. */
2574 clear_message (1, 0);
2578 before_command_key_count
= this_command_key_count
;
2579 before_command_echo_length
= echo_length ();
2581 /* Don't echo mouse motion events. */
2582 if (echo_keystrokes
)
2586 /* Once we reread a character, echoing can happen
2587 the next time we pause to read a new one. */
2588 ok_to_echo_at_next_pause
= 0;
2591 /* Record this character as part of the current key. */
2592 add_command_key (c
);
2594 /* Re-reading in the middle of a command */
2595 last_input_char
= c
;
2599 /* Return 1 if should recognize C as "the help character". */
2607 if (EQ (c
, Vhelp_char
))
2609 for (tail
= Vhelp_event_list
; CONSP (tail
); tail
= XCDR (tail
))
2610 if (EQ (c
, XCAR (tail
)))
2615 /* Record the input event C in various ways. */
2622 XVECTOR (recent_keys
)->contents
[recent_keys_index
] = c
;
2623 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
2624 recent_keys_index
= 0;
2626 /* Write c to the dribble file. If c is a lispy event, write
2627 the event's symbol to the dribble file, in <brackets>. Bleaugh.
2628 If you, dear reader, have a better idea, you've got the source. :-) */
2633 if (XUINT (c
) < 0x100)
2634 putc (XINT (c
), dribble
);
2636 fprintf (dribble
, " 0x%x", (int) XUINT (c
));
2640 Lisp_Object dribblee
;
2642 /* If it's a structured event, take the event header. */
2643 dribblee
= EVENT_HEAD (c
);
2645 if (SYMBOLP (dribblee
))
2647 putc ('<', dribble
);
2648 fwrite (XSYMBOL (dribblee
)->name
->data
, sizeof (char),
2649 STRING_BYTES (XSYMBOL (dribblee
)->name
),
2651 putc ('>', dribble
);
2658 store_kbd_macro_char (c
);
2660 num_nonmacro_input_events
++;
2667 struct buffer
*old
= current_buffer
;
2668 Fprinc (object
, Qnil
);
2669 set_buffer_internal (XBUFFER (Vstandard_output
));
2670 call0 (intern ("help-mode"));
2671 set_buffer_internal (old
);
2675 /* Copy out or in the info on where C-g should throw to.
2676 This is used when running Lisp code from within get_char,
2677 in case get_char is called recursively.
2678 See read_process_output. */
2684 bcopy (getcjmp
, temp
, sizeof getcjmp
);
2688 restore_getcjmp (temp
)
2691 bcopy (temp
, getcjmp
, sizeof getcjmp
);
2696 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
2697 of this function. */
2700 tracking_off (old_value
)
2701 Lisp_Object old_value
;
2703 do_mouse_tracking
= old_value
;
2704 if (NILP (old_value
))
2706 /* Redisplay may have been preempted because there was input
2707 available, and it assumes it will be called again after the
2708 input has been processed. If the only input available was
2709 the sort that we have just disabled, then we need to call
2711 if (!readable_events (1))
2713 redisplay_preserve_echo_area ();
2714 get_input_pending (&input_pending
, 1);
2719 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
2720 "Evaluate BODY with mouse movement events enabled.\n\
2721 Within a `track-mouse' form, mouse motion generates input events that\n\
2722 you can read with `read-event'.\n\
2723 Normally, mouse motion is ignored.")
2727 int count
= specpdl_ptr
- specpdl
;
2730 record_unwind_protect (tracking_off
, do_mouse_tracking
);
2732 do_mouse_tracking
= Qt
;
2734 val
= Fprogn (args
);
2735 return unbind_to (count
, val
);
2738 /* If mouse has moved on some frame, return one of those frames.
2739 Return 0 otherwise. */
2744 Lisp_Object tail
, frame
;
2746 FOR_EACH_FRAME (tail
, frame
)
2748 if (XFRAME (frame
)->mouse_moved
)
2749 return XFRAME (frame
);
2755 #endif /* HAVE_MOUSE */
2757 /* Low level keyboard/mouse input.
2758 kbd_buffer_store_event places events in kbd_buffer, and
2759 kbd_buffer_get_event retrieves them. */
2761 /* Return true iff there are any events in the queue that read-char
2762 would return. If this returns false, a read-char would block. */
2764 readable_events (do_timers_now
)
2768 timer_check (do_timers_now
);
2770 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2773 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2778 if (current_kboard
->kbd_queue_has_data
)
2784 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2785 if (kb
->kbd_queue_has_data
)
2791 /* Set this for debugging, to have a way to get out */
2796 event_to_kboard (event
)
2797 struct input_event
*event
;
2800 frame
= event
->frame_or_window
;
2802 frame
= XCAR (frame
);
2803 else if (WINDOWP (frame
))
2804 frame
= WINDOW_FRAME (XWINDOW (frame
));
2806 /* There are still some events that don't set this field.
2807 For now, just ignore the problem.
2808 Also ignore dead frames here. */
2809 if (!FRAMEP (frame
) || !FRAME_LIVE_P (XFRAME (frame
)))
2812 return FRAME_KBOARD (XFRAME (frame
));
2816 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
2819 kbd_buffer_store_event (event
)
2820 register struct input_event
*event
;
2822 if (event
->kind
== no_event
)
2825 if (event
->kind
== ascii_keystroke
)
2827 register int c
= event
->code
& 0377;
2829 if (event
->modifiers
& ctrl_modifier
)
2830 c
= make_ctrl_char (c
);
2832 c
|= (event
->modifiers
2833 & (meta_modifier
| alt_modifier
2834 | hyper_modifier
| super_modifier
));
2838 extern SIGTYPE
interrupt_signal ();
2841 struct input_event
*sp
;
2844 && (kb
= FRAME_KBOARD (XFRAME (event
->frame_or_window
)),
2845 kb
!= current_kboard
))
2848 = Fcons (make_lispy_switch_frame (event
->frame_or_window
),
2849 Fcons (make_number (c
), Qnil
));
2850 kb
->kbd_queue_has_data
= 1;
2851 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
2853 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
2856 if (event_to_kboard (sp
) == kb
)
2858 sp
->kind
= no_event
;
2859 sp
->frame_or_window
= Qnil
;
2866 /* If this results in a quit_char being returned to Emacs as
2867 input, set Vlast_event_frame properly. If this doesn't
2868 get returned to Emacs as an event, the next event read
2869 will set Vlast_event_frame again, so this is safe to do. */
2873 focus
= FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
2875 focus
= event
->frame_or_window
;
2876 internal_last_event_frame
= focus
;
2877 Vlast_event_frame
= focus
;
2880 last_event_timestamp
= event
->timestamp
;
2881 interrupt_signal ();
2885 if (c
&& c
== stop_character
)
2891 /* Don't insert two buffer_switch_event's in a row.
2892 Just ignore the second one. */
2893 else if (event
->kind
== buffer_switch_event
2894 && kbd_fetch_ptr
!= kbd_store_ptr
2895 && kbd_store_ptr
->kind
== buffer_switch_event
)
2898 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
2899 kbd_store_ptr
= kbd_buffer
;
2901 /* Don't let the very last slot in the buffer become full,
2902 since that would make the two pointers equal,
2903 and that is indistinguishable from an empty buffer.
2904 Discard the event if it would fill the last slot. */
2905 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
2907 struct input_event
*sp
= kbd_store_ptr
;
2908 sp
->kind
= event
->kind
;
2909 if (event
->kind
== selection_request_event
)
2911 /* We must not use the ordinary copying code for this case,
2912 since `part' is an enum and copying it might not copy enough
2914 bcopy (event
, (char *) sp
, sizeof (*event
));
2918 sp
->code
= event
->code
;
2919 sp
->part
= event
->part
;
2920 sp
->frame_or_window
= event
->frame_or_window
;
2921 sp
->modifiers
= event
->modifiers
;
2924 sp
->timestamp
= event
->timestamp
;
2926 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_store_ptr
2928 = event
->frame_or_window
);
2934 /* Discard any mouse events in the event buffer by setting them to
2937 discard_mouse_events ()
2939 struct input_event
*sp
;
2940 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
2942 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
2945 if (sp
->kind
== mouse_click
2947 || sp
->kind
== w32_scroll_bar_click
2949 || sp
->kind
== scroll_bar_click
)
2951 sp
->kind
= no_event
;
2956 /* Read one event from the event buffer, waiting if necessary.
2957 The value is a Lisp object representing the event.
2958 The value is nil for an event that should be ignored,
2959 or that was handled here.
2960 We always read and discard one event. */
2963 kbd_buffer_get_event (kbp
, used_mouse_menu
)
2965 int *used_mouse_menu
;
2974 *kbp
= current_kboard
;
2978 /* Wait until there is input available. */
2981 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2984 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2988 /* If the quit flag is set, then read_char will return
2989 quit_char, so that counts as "available input." */
2990 if (!NILP (Vquit_flag
))
2991 quit_throw_to_read_char ();
2993 /* One way or another, wait until input is available; then, if
2994 interrupt handlers have not read it, read it now. */
2997 wait_for_kbd_input ();
2999 /* Note SIGIO has been undef'd if FIONREAD is missing. */
3003 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3006 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
3010 Lisp_Object minus_one
;
3012 XSETINT (minus_one
, -1);
3013 wait_reading_process_input (0, 0, minus_one
, 1);
3015 if (!interrupt_input
&& kbd_fetch_ptr
== kbd_store_ptr
)
3016 /* Pass 1 for EXPECT since we just waited to have input. */
3017 read_avail_input (1);
3019 #endif /* not VMS */
3022 if (CONSP (Vunread_command_events
))
3025 first
= XCAR (Vunread_command_events
);
3026 Vunread_command_events
= XCDR (Vunread_command_events
);
3027 *kbp
= current_kboard
;
3031 /* At this point, we know that there is a readable event available
3032 somewhere. If the event queue is empty, then there must be a
3033 mouse movement enabled and available. */
3034 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3036 struct input_event
*event
;
3038 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
3042 last_event_timestamp
= event
->timestamp
;
3045 *kbp
= event_to_kboard (event
);
3047 *kbp
= current_kboard
; /* Better than returning null ptr? */
3049 *kbp
= &the_only_kboard
;
3054 /* These two kinds of events get special handling
3055 and don't actually appear to the command loop.
3056 We return nil for them. */
3057 if (event
->kind
== selection_request_event
)
3060 struct input_event copy
;
3062 /* Remove it from the buffer before processing it,
3063 since otherwise swallow_events will see it
3064 and process it again. */
3066 kbd_fetch_ptr
= event
+ 1;
3067 input_pending
= readable_events (0);
3068 x_handle_selection_request (©
);
3070 /* We're getting selection request events, but we don't have
3076 else if (event
->kind
== selection_clear_event
)
3079 struct input_event copy
;
3081 /* Remove it from the buffer before processing it. */
3083 kbd_fetch_ptr
= event
+ 1;
3084 input_pending
= readable_events (0);
3085 x_handle_selection_clear (©
);
3087 /* We're getting selection request events, but we don't have
3092 #if defined (HAVE_X11) || defined (HAVE_NTGUI)
3093 else if (event
->kind
== delete_window_event
)
3095 /* Make an event (delete-frame (FRAME)). */
3096 obj
= Fcons (event
->frame_or_window
, Qnil
);
3097 obj
= Fcons (Qdelete_frame
, Fcons (obj
, Qnil
));
3098 kbd_fetch_ptr
= event
+ 1;
3100 else if (event
->kind
== iconify_event
)
3102 /* Make an event (iconify-frame (FRAME)). */
3103 obj
= Fcons (event
->frame_or_window
, Qnil
);
3104 obj
= Fcons (Qiconify_frame
, Fcons (obj
, Qnil
));
3105 kbd_fetch_ptr
= event
+ 1;
3107 else if (event
->kind
== deiconify_event
)
3109 /* Make an event (make-frame-visible (FRAME)). */
3110 obj
= Fcons (event
->frame_or_window
, Qnil
);
3111 obj
= Fcons (Qmake_frame_visible
, Fcons (obj
, Qnil
));
3112 kbd_fetch_ptr
= event
+ 1;
3115 else if (event
->kind
== buffer_switch_event
)
3117 /* The value doesn't matter here; only the type is tested. */
3118 XSETBUFFER (obj
, current_buffer
);
3119 kbd_fetch_ptr
= event
+ 1;
3121 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
3122 else if (event
->kind
== menu_bar_activate_event
)
3124 kbd_fetch_ptr
= event
+ 1;
3125 input_pending
= readable_events (0);
3126 if (FRAME_LIVE_P (XFRAME (event
->frame_or_window
)))
3127 x_activate_menubar (XFRAME (event
->frame_or_window
));
3131 else if (event
->kind
== language_change_event
)
3133 /* Make an event (language-change (FRAME CHARSET LCID)). */
3134 obj
= Fcons (event
->modifiers
, Qnil
);
3135 obj
= Fcons (event
->code
, Qnil
);
3136 obj
= Fcons (event
->frame_or_window
, obj
);
3137 obj
= Fcons (Qlanguage_change
, Fcons (obj
, Qnil
));
3138 kbd_fetch_ptr
= event
+ 1;
3141 /* Just discard these, by returning nil.
3142 With MULTI_KBOARD, these events are used as placeholders
3143 when we need to randomly delete events from the queue.
3144 (They shouldn't otherwise be found in the buffer,
3145 but on some machines it appears they do show up
3146 even without MULTI_KBOARD.) */
3147 /* On Windows NT/9X, no_event is used to delete extraneous
3148 mouse events during a popup-menu call. */
3149 else if (event
->kind
== no_event
)
3150 kbd_fetch_ptr
= event
+ 1;
3151 else if (event
->kind
== HELP_EVENT
)
3153 /* The car of event->frame_or_window is a frame,
3154 the cdr is the help to display. */
3155 obj
= Fcons (Qhelp_echo
, event
->frame_or_window
);
3156 kbd_fetch_ptr
= event
+ 1;
3158 /* If this event is on a different frame, return a switch-frame this
3159 time, and leave the event in the queue for next time. */
3165 frame
= event
->frame_or_window
;
3167 frame
= XCAR (frame
);
3168 else if (WINDOWP (frame
))
3169 frame
= WINDOW_FRAME (XWINDOW (frame
));
3171 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
3175 if (! EQ (frame
, internal_last_event_frame
)
3176 && !EQ (frame
, selected_frame
))
3177 obj
= make_lispy_switch_frame (frame
);
3178 internal_last_event_frame
= frame
;
3180 /* If we didn't decide to make a switch-frame event, go ahead
3181 and build a real event from the queue entry. */
3185 obj
= make_lispy_event (event
);
3186 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
3187 /* If this was a menu selection, then set the flag to inhibit
3188 writing to last_nonmenu_event. Don't do this if the event
3189 we're returning is (menu-bar), though; that indicates the
3190 beginning of the menu sequence, and we might as well leave
3191 that as the `event with parameters' for this selection. */
3192 if ((event
->kind
== menu_bar_event
3193 || event
->kind
== TOOL_BAR_EVENT
)
3194 && !(CONSP (obj
) && EQ (XCAR (obj
), Qmenu_bar
))
3195 && !(CONSP (obj
) && EQ (XCAR (obj
), Qtool_bar
))
3197 *used_mouse_menu
= 1;
3200 /* Wipe out this event, to catch bugs. */
3201 event
->kind
= no_event
;
3202 XVECTOR (kbd_buffer_frame_or_window
)->contents
[event
- kbd_buffer
] = Qnil
;
3204 kbd_fetch_ptr
= event
+ 1;
3209 /* Try generating a mouse motion event. */
3210 else if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
3212 FRAME_PTR f
= some_mouse_moved ();
3213 Lisp_Object bar_window
;
3214 enum scroll_bar_part part
;
3218 *kbp
= current_kboard
;
3219 /* Note that this uses F to determine which display to look at.
3220 If there is no valid info, it does not store anything
3221 so x remains nil. */
3223 (*mouse_position_hook
) (&f
, 0, &bar_window
, &part
, &x
, &y
, &time
);
3227 /* Decide if we should generate a switch-frame event. Don't
3228 generate switch-frame events for motion outside of all Emacs
3234 frame
= FRAME_FOCUS_FRAME (f
);
3236 XSETFRAME (frame
, f
);
3238 if (! EQ (frame
, internal_last_event_frame
)
3239 && !EQ (frame
, selected_frame
))
3240 obj
= make_lispy_switch_frame (frame
);
3241 internal_last_event_frame
= frame
;
3244 /* If we didn't decide to make a switch-frame event, go ahead and
3245 return a mouse-motion event. */
3246 if (!NILP (x
) && NILP (obj
))
3247 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
3249 #endif /* HAVE_MOUSE */
3251 /* We were promised by the above while loop that there was
3252 something for us to read! */
3255 input_pending
= readable_events (0);
3257 Vlast_event_frame
= internal_last_event_frame
;
3262 /* Process any events that are not user-visible,
3263 then return, without reading any user-visible events. */
3266 swallow_events (do_display
)
3271 while (kbd_fetch_ptr
!= kbd_store_ptr
)
3273 struct input_event
*event
;
3275 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
3279 last_event_timestamp
= event
->timestamp
;
3281 /* These two kinds of events get special handling
3282 and don't actually appear to the command loop. */
3283 if (event
->kind
== selection_request_event
)
3286 struct input_event copy
;
3288 /* Remove it from the buffer before processing it,
3289 since otherwise swallow_events called recursively could see it
3290 and process it again. */
3292 kbd_fetch_ptr
= event
+ 1;
3293 input_pending
= readable_events (0);
3294 x_handle_selection_request (©
);
3296 /* We're getting selection request events, but we don't have
3302 else if (event
->kind
== selection_clear_event
)
3305 struct input_event copy
;
3307 /* Remove it from the buffer before processing it, */
3310 kbd_fetch_ptr
= event
+ 1;
3311 input_pending
= readable_events (0);
3312 x_handle_selection_clear (©
);
3314 /* We're getting selection request events, but we don't have
3323 old_timers_run
= timers_run
;
3324 get_input_pending (&input_pending
, 1);
3326 if (timers_run
!= old_timers_run
&& do_display
)
3327 redisplay_preserve_echo_area ();
3330 static EMACS_TIME timer_idleness_start_time
;
3332 /* Record the start of when Emacs is idle,
3333 for the sake of running idle-time timers. */
3340 /* If we are already in the idle state, do nothing. */
3341 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3344 EMACS_GET_TIME (timer_idleness_start_time
);
3346 /* Mark all idle-time timers as once again candidates for running. */
3347 for (timers
= Vtimer_idle_list
; CONSP (timers
); timers
= XCDR (timers
))
3351 timer
= XCAR (timers
);
3353 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3355 XVECTOR (timer
)->contents
[0] = Qnil
;
3359 /* Record that Emacs is no longer idle, so stop running idle-time timers. */
3364 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
3367 /* This is only for debugging. */
3368 struct input_event last_timer_event
;
3370 /* Check whether a timer has fired. To prevent larger problems we simply
3371 disregard elements that are not proper timers. Do not make a circular
3372 timer list for the time being.
3374 Returns the number of seconds to wait until the next timer fires. If a
3375 timer is triggering now, return zero seconds.
3376 If no timer is active, return -1 seconds.
3378 If a timer is ripe, we run it, with quitting turned off.
3380 DO_IT_NOW is now ignored. It used to mean that we should
3381 run the timer directly instead of queueing a timer-event.
3382 Now we always run timers directly. */
3385 timer_check (do_it_now
)
3388 EMACS_TIME nexttime
;
3389 EMACS_TIME now
, idleness_now
;
3390 Lisp_Object timers
, idle_timers
, chosen_timer
;
3391 struct gcpro gcpro1
, gcpro2
, gcpro3
;
3393 EMACS_SET_SECS (nexttime
, -1);
3394 EMACS_SET_USECS (nexttime
, -1);
3396 /* Always consider the ordinary timers. */
3397 timers
= Vtimer_list
;
3398 /* Consider the idle timers only if Emacs is idle. */
3399 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3400 idle_timers
= Vtimer_idle_list
;
3403 chosen_timer
= Qnil
;
3404 GCPRO3 (timers
, idle_timers
, chosen_timer
);
3406 if (CONSP (timers
) || CONSP (idle_timers
))
3408 EMACS_GET_TIME (now
);
3409 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3410 EMACS_SUB_TIME (idleness_now
, now
, timer_idleness_start_time
);
3413 while (CONSP (timers
) || CONSP (idle_timers
))
3415 Lisp_Object
*vector
;
3416 Lisp_Object timer
, idle_timer
;
3417 EMACS_TIME timer_time
, idle_timer_time
;
3418 EMACS_TIME difference
, timer_difference
, idle_timer_difference
;
3420 /* Skip past invalid timers and timers already handled. */
3423 timer
= XCAR (timers
);
3424 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3426 timers
= XCDR (timers
);
3429 vector
= XVECTOR (timer
)->contents
;
3431 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
3432 || !INTEGERP (vector
[3])
3433 || ! NILP (vector
[0]))
3435 timers
= XCDR (timers
);
3439 if (!NILP (idle_timers
))
3441 timer
= XCAR (idle_timers
);
3442 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3444 idle_timers
= XCDR (idle_timers
);
3447 vector
= XVECTOR (timer
)->contents
;
3449 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
3450 || !INTEGERP (vector
[3])
3451 || ! NILP (vector
[0]))
3453 idle_timers
= XCDR (idle_timers
);
3458 /* Set TIMER, TIMER_TIME and TIMER_DIFFERENCE
3459 based on the next ordinary timer.
3460 TIMER_DIFFERENCE is the distance in time from NOW to when
3461 this timer becomes ripe (negative if it's already ripe). */
3464 timer
= XCAR (timers
);
3465 vector
= XVECTOR (timer
)->contents
;
3466 EMACS_SET_SECS (timer_time
,
3467 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
3468 EMACS_SET_USECS (timer_time
, XINT (vector
[3]));
3469 EMACS_SUB_TIME (timer_difference
, timer_time
, now
);
3472 /* Set IDLE_TIMER, IDLE_TIMER_TIME and IDLE_TIMER_DIFFERENCE
3473 based on the next idle timer. */
3474 if (!NILP (idle_timers
))
3476 idle_timer
= XCAR (idle_timers
);
3477 vector
= XVECTOR (idle_timer
)->contents
;
3478 EMACS_SET_SECS (idle_timer_time
,
3479 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
3480 EMACS_SET_USECS (idle_timer_time
, XINT (vector
[3]));
3481 EMACS_SUB_TIME (idle_timer_difference
, idle_timer_time
, idleness_now
);
3484 /* Decide which timer is the next timer,
3485 and set CHOSEN_TIMER, VECTOR and DIFFERENCE accordingly.
3486 Also step down the list where we found that timer. */
3488 if (! NILP (timers
) && ! NILP (idle_timers
))
3491 EMACS_SUB_TIME (temp
, timer_difference
, idle_timer_difference
);
3492 if (EMACS_TIME_NEG_P (temp
))
3494 chosen_timer
= timer
;
3495 timers
= XCDR (timers
);
3496 difference
= timer_difference
;
3500 chosen_timer
= idle_timer
;
3501 idle_timers
= XCDR (idle_timers
);
3502 difference
= idle_timer_difference
;
3505 else if (! NILP (timers
))
3507 chosen_timer
= timer
;
3508 timers
= XCDR (timers
);
3509 difference
= timer_difference
;
3513 chosen_timer
= idle_timer
;
3514 idle_timers
= XCDR (idle_timers
);
3515 difference
= idle_timer_difference
;
3517 vector
= XVECTOR (chosen_timer
)->contents
;
3519 /* If timer is rupe, run it if it hasn't been run. */
3520 if (EMACS_TIME_NEG_P (difference
)
3521 || (EMACS_SECS (difference
) == 0
3522 && EMACS_USECS (difference
) == 0))
3524 if (NILP (vector
[0]))
3526 int was_locked
= single_kboard
;
3527 int count
= specpdl_ptr
- specpdl
;
3528 #ifdef HAVE_WINDOW_SYSTEM
3529 int old_inhibit_busy_cursor
= inhibit_busy_cursor
;
3532 /* Mark the timer as triggered to prevent problems if the lisp
3533 code fails to reschedule it right. */
3536 specbind (Qinhibit_quit
, Qt
);
3538 #ifdef HAVE_WINDOW_SYSTEM
3539 inhibit_busy_cursor
= 2;
3542 call1 (Qtimer_event_handler
, chosen_timer
);
3545 #ifdef HAVE_WINDOW_SYSTEM
3546 inhibit_busy_cursor
= old_inhibit_busy_cursor
;
3549 unbind_to (count
, Qnil
);
3551 /* Resume allowing input from any kboard, if that was true before. */
3553 any_kboard_state ();
3555 /* Since we have handled the event,
3556 we don't need to tell the caller to wake up and do it. */
3560 /* When we encounter a timer that is still waiting,
3561 return the amount of time to wait before it is ripe. */
3568 /* No timers are pending in the future. */
3569 /* Return 0 if we generated an event, and -1 if not. */
3574 /* Caches for modify_event_symbol. */
3575 static Lisp_Object accent_key_syms
;
3576 static Lisp_Object func_key_syms
;
3577 static Lisp_Object mouse_syms
;
3579 static Lisp_Object mouse_wheel_syms
;
3581 static Lisp_Object drag_n_drop_syms
;
3583 /* This is a list of keysym codes for special "accent" characters.
3584 It parallels lispy_accent_keys. */
3586 static int lispy_accent_codes
[] =
3588 #ifdef XK_dead_circumflex
3593 #ifdef XK_dead_grave
3598 #ifdef XK_dead_tilde
3603 #ifdef XK_dead_diaeresis
3608 #ifdef XK_dead_macron
3613 #ifdef XK_dead_degree
3618 #ifdef XK_dead_acute
3623 #ifdef XK_dead_cedilla
3628 #ifdef XK_dead_breve
3633 #ifdef XK_dead_ogonek
3638 #ifdef XK_dead_caron
3643 #ifdef XK_dead_doubleacute
3644 XK_dead_doubleacute
,
3648 #ifdef XK_dead_abovedot
3655 /* This is a list of Lisp names for special "accent" characters.
3656 It parallels lispy_accent_codes. */
3658 static char *lispy_accent_keys
[] =
3676 #define FUNCTION_KEY_OFFSET 0x0
3678 char *lispy_function_keys
[] =
3682 0, /* VK_LBUTTON 0x01 */
3683 0, /* VK_RBUTTON 0x02 */
3684 "cancel", /* VK_CANCEL 0x03 */
3685 0, /* VK_MBUTTON 0x04 */
3687 0, 0, 0, /* 0x05 .. 0x07 */
3689 "backspace", /* VK_BACK 0x08 */
3690 "tab", /* VK_TAB 0x09 */
3692 0, 0, /* 0x0A .. 0x0B */
3694 "clear", /* VK_CLEAR 0x0C */
3695 "return", /* VK_RETURN 0x0D */
3697 0, 0, /* 0x0E .. 0x0F */
3699 0, /* VK_SHIFT 0x10 */
3700 0, /* VK_CONTROL 0x11 */
3701 0, /* VK_MENU 0x12 */
3702 "pause", /* VK_PAUSE 0x13 */
3703 "capslock", /* VK_CAPITAL 0x14 */
3705 0, 0, 0, 0, 0, 0, /* 0x15 .. 0x1A */
3707 "escape", /* VK_ESCAPE 0x1B */
3709 0, 0, 0, 0, /* 0x1C .. 0x1F */
3711 0, /* VK_SPACE 0x20 */
3712 "prior", /* VK_PRIOR 0x21 */
3713 "next", /* VK_NEXT 0x22 */
3714 "end", /* VK_END 0x23 */
3715 "home", /* VK_HOME 0x24 */
3716 "left", /* VK_LEFT 0x25 */
3717 "up", /* VK_UP 0x26 */
3718 "right", /* VK_RIGHT 0x27 */
3719 "down", /* VK_DOWN 0x28 */
3720 "select", /* VK_SELECT 0x29 */
3721 "print", /* VK_PRINT 0x2A */
3722 "execute", /* VK_EXECUTE 0x2B */
3723 "snapshot", /* VK_SNAPSHOT 0x2C */
3724 "insert", /* VK_INSERT 0x2D */
3725 "delete", /* VK_DELETE 0x2E */
3726 "help", /* VK_HELP 0x2F */
3728 /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
3730 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3732 0, 0, 0, 0, 0, 0, 0, /* 0x3A .. 0x40 */
3734 /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
3736 0, 0, 0, 0, 0, 0, 0, 0, 0,
3737 0, 0, 0, 0, 0, 0, 0, 0, 0,
3738 0, 0, 0, 0, 0, 0, 0, 0,
3740 "lwindow", /* VK_LWIN 0x5B */
3741 "rwindow", /* VK_RWIN 0x5C */
3742 "apps", /* VK_APPS 0x5D */
3744 0, 0, /* 0x5E .. 0x5F */
3746 "kp-0", /* VK_NUMPAD0 0x60 */
3747 "kp-1", /* VK_NUMPAD1 0x61 */
3748 "kp-2", /* VK_NUMPAD2 0x62 */
3749 "kp-3", /* VK_NUMPAD3 0x63 */
3750 "kp-4", /* VK_NUMPAD4 0x64 */
3751 "kp-5", /* VK_NUMPAD5 0x65 */
3752 "kp-6", /* VK_NUMPAD6 0x66 */
3753 "kp-7", /* VK_NUMPAD7 0x67 */
3754 "kp-8", /* VK_NUMPAD8 0x68 */
3755 "kp-9", /* VK_NUMPAD9 0x69 */
3756 "kp-multiply", /* VK_MULTIPLY 0x6A */
3757 "kp-add", /* VK_ADD 0x6B */
3758 "kp-separator", /* VK_SEPARATOR 0x6C */
3759 "kp-subtract", /* VK_SUBTRACT 0x6D */
3760 "kp-decimal", /* VK_DECIMAL 0x6E */
3761 "kp-divide", /* VK_DIVIDE 0x6F */
3762 "f1", /* VK_F1 0x70 */
3763 "f2", /* VK_F2 0x71 */
3764 "f3", /* VK_F3 0x72 */
3765 "f4", /* VK_F4 0x73 */
3766 "f5", /* VK_F5 0x74 */
3767 "f6", /* VK_F6 0x75 */
3768 "f7", /* VK_F7 0x76 */
3769 "f8", /* VK_F8 0x77 */
3770 "f9", /* VK_F9 0x78 */
3771 "f10", /* VK_F10 0x79 */
3772 "f11", /* VK_F11 0x7A */
3773 "f12", /* VK_F12 0x7B */
3774 "f13", /* VK_F13 0x7C */
3775 "f14", /* VK_F14 0x7D */
3776 "f15", /* VK_F15 0x7E */
3777 "f16", /* VK_F16 0x7F */
3778 "f17", /* VK_F17 0x80 */
3779 "f18", /* VK_F18 0x81 */
3780 "f19", /* VK_F19 0x82 */
3781 "f20", /* VK_F20 0x83 */
3782 "f21", /* VK_F21 0x84 */
3783 "f22", /* VK_F22 0x85 */
3784 "f23", /* VK_F23 0x86 */
3785 "f24", /* VK_F24 0x87 */
3787 0, 0, 0, 0, /* 0x88 .. 0x8B */
3788 0, 0, 0, 0, /* 0x8C .. 0x8F */
3790 "kp-numlock", /* VK_NUMLOCK 0x90 */
3791 "scroll", /* VK_SCROLL 0x91 */
3793 "kp-space", /* VK_NUMPAD_CLEAR 0x92 */
3794 "kp-enter", /* VK_NUMPAD_ENTER 0x93 */
3795 "kp-prior", /* VK_NUMPAD_PRIOR 0x94 */
3796 "kp-next", /* VK_NUMPAD_NEXT 0x95 */
3797 "kp-end", /* VK_NUMPAD_END 0x96 */
3798 "kp-home", /* VK_NUMPAD_HOME 0x97 */
3799 "kp-left", /* VK_NUMPAD_LEFT 0x98 */
3800 "kp-up", /* VK_NUMPAD_UP 0x99 */
3801 "kp-right", /* VK_NUMPAD_RIGHT 0x9A */
3802 "kp-down", /* VK_NUMPAD_DOWN 0x9B */
3803 "kp-insert", /* VK_NUMPAD_INSERT 0x9C */
3804 "kp-delete", /* VK_NUMPAD_DELETE 0x9D */
3806 0, 0, /* 0x9E .. 0x9F */
3809 * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
3810 * Used only as parameters to GetAsyncKeyState and GetKeyState.
3811 * No other API or message will distinguish left and right keys this way.
3815 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3816 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3817 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3818 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3819 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3825 "attn", /* VK_ATTN 0xF6 */
3826 "crsel", /* VK_CRSEL 0xF7 */
3827 "exsel", /* VK_EXSEL 0xF8 */
3828 "ereof", /* VK_EREOF 0xF9 */
3829 "play", /* VK_PLAY 0xFA */
3830 "zoom", /* VK_ZOOM 0xFB */
3831 "noname", /* VK_NONAME 0xFC */
3832 "pa1", /* VK_PA1 0xFD */
3833 "oem_clear", /* VK_OEM_CLEAR 0xFE */
3837 #else /* not HAVE_NTGUI */
3840 static char *lispy_kana_keys
[] =
3842 /* X Keysym value */
3843 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x400 .. 0x40f */
3844 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x410 .. 0x41f */
3845 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x420 .. 0x42f */
3846 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x430 .. 0x43f */
3847 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x440 .. 0x44f */
3848 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x450 .. 0x45f */
3849 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x460 .. 0x46f */
3850 0,0,0,0,0,0,0,0,0,0,0,0,0,0,"overline",0,
3851 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x480 .. 0x48f */
3852 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x490 .. 0x49f */
3853 0, "kana-fullstop", "kana-openingbracket", "kana-closingbracket",
3854 "kana-comma", "kana-conjunctive", "kana-WO", "kana-a",
3855 "kana-i", "kana-u", "kana-e", "kana-o",
3856 "kana-ya", "kana-yu", "kana-yo", "kana-tsu",
3857 "prolongedsound", "kana-A", "kana-I", "kana-U",
3858 "kana-E", "kana-O", "kana-KA", "kana-KI",
3859 "kana-KU", "kana-KE", "kana-KO", "kana-SA",
3860 "kana-SHI", "kana-SU", "kana-SE", "kana-SO",
3861 "kana-TA", "kana-CHI", "kana-TSU", "kana-TE",
3862 "kana-TO", "kana-NA", "kana-NI", "kana-NU",
3863 "kana-NE", "kana-NO", "kana-HA", "kana-HI",
3864 "kana-FU", "kana-HE", "kana-HO", "kana-MA",
3865 "kana-MI", "kana-MU", "kana-ME", "kana-MO",
3866 "kana-YA", "kana-YU", "kana-YO", "kana-RA",
3867 "kana-RI", "kana-RU", "kana-RE", "kana-RO",
3868 "kana-WA", "kana-N", "voicedsound", "semivoicedsound",
3869 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4e0 .. 0x4ef */
3870 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4f0 .. 0x4ff */
3872 #endif /* XK_kana_A */
3874 #define FUNCTION_KEY_OFFSET 0xff00
3876 /* You'll notice that this table is arranged to be conveniently
3877 indexed by X Windows keysym values. */
3878 static char *lispy_function_keys
[] =
3880 /* X Keysym value */
3882 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00...0f */
3883 "backspace", "tab", "linefeed", "clear",
3885 0, 0, 0, "pause", /* 0xff10...1f */
3886 0, 0, 0, 0, 0, 0, 0, "escape",
3888 0, "kanji", "muhenkan", "henkan", /* 0xff20...2f */
3889 "romaji", "hiragana", "katakana", "hiragana-katakana",
3890 "zenkaku", "hankaku", "zenkaku-hankaku", "touroku",
3891 "massyo", "kana-lock", "kana-shift", "eisu-shift",
3892 "eisu-toggle", /* 0xff30...3f */
3893 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3894 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
3896 "home", "left", "up", "right", /* 0xff50 */ /* IsCursorKey */
3897 "down", "prior", "next", "end",
3898 "begin", 0, 0, 0, 0, 0, 0, 0,
3899 "select", /* 0xff60 */ /* IsMiscFunctionKey */
3910 "break", /* 0xff6b */
3913 0, 0, 0, 0, "backtab", 0, 0, 0, /* 0xff70... */
3914 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff78... */
3915 "kp-space", /* 0xff80 */ /* IsKeypadKey */
3916 0, 0, 0, 0, 0, 0, 0, 0,
3917 "kp-tab", /* 0xff89 */
3919 "kp-enter", /* 0xff8d */
3921 "kp-f1", /* 0xff91 */
3925 "kp-home", /* 0xff95 */
3930 "kp-prior", /* kp-page-up */
3931 "kp-next", /* kp-page-down */
3937 0, 0, 0, 0, 0, 0, 0, 0, 0,
3938 "kp-multiply", /* 0xffaa */
3943 "kp-divide", /* 0xffaf */
3944 "kp-0", /* 0xffb0 */
3945 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
3948 "kp-equal", /* 0xffbd */
3949 "f1", /* 0xffbe */ /* IsFunctionKey */
3951 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
3952 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
3953 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
3954 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
3955 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
3956 0, 0, 0, 0, 0, 0, 0, 0,
3957 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
3958 0, 0, 0, 0, 0, 0, 0, "delete"
3961 /* ISO 9995 Function and Modifier Keys; the first byte is 0xFE. */
3962 #define ISO_FUNCTION_KEY_OFFSET 0xfe00
3964 static char *iso_lispy_function_keys
[] =
3966 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe00 */
3967 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe08 */
3968 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe10 */
3969 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe18 */
3970 "iso-lefttab", /* 0xfe20 */
3971 "iso-move-line-up", "iso-move-line-down",
3972 "iso-partial-line-up", "iso-partial-line-down",
3973 "iso-partial-space-left", "iso-partial-space-right",
3974 "iso-set-margin-left", "iso-set-margin-right", /* 0xffe27, 28 */
3975 "iso-release-margin-left", "iso-release-margin-right",
3976 "iso-release-both-margins",
3977 "iso-fast-cursor-left", "iso-fast-cursor-right",
3978 "iso-fast-cursor-up", "iso-fast-cursor-down",
3979 "iso-continuous-underline", "iso-discontinuous-underline", /* 0xfe30, 31 */
3980 "iso-emphasize", "iso-center-object", "iso-enter", /* ... 0xfe34 */
3983 #endif /* not HAVE_NTGUI */
3985 static char *lispy_mouse_names
[] =
3987 "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5"
3991 /* mouse-wheel events are generated by the wheel on devices such as
3992 the MS Intellimouse. The wheel sits in between the left and right
3993 mouse buttons, and is typically used to scroll or zoom the window
3994 underneath the pointer. mouse-wheel events specify the object on
3995 which they operate, and a delta corresponding to the amount and
3996 direction that the wheel is rotated. Clicking the mouse-wheel
3997 generates a mouse-2 event. */
3998 static char *lispy_mouse_wheel_names
[] =
4003 #endif /* WINDOWSNT */
4005 /* drag-n-drop events are generated when a set of selected files are
4006 dragged from another application and dropped onto an Emacs window. */
4007 static char *lispy_drag_n_drop_names
[] =
4012 /* Scroll bar parts. */
4013 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
4014 Lisp_Object Qup
, Qdown
, Qbottom
, Qend_scroll
;
4015 Lisp_Object Qtop
, Qratio
;
4017 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
4018 Lisp_Object
*scroll_bar_parts
[] = {
4019 &Qabove_handle
, &Qhandle
, &Qbelow_handle
,
4020 &Qup
, &Qdown
, &Qtop
, &Qbottom
, &Qend_scroll
, &Qratio
4023 /* User signal events. */
4024 Lisp_Object Qusr1_signal
, Qusr2_signal
;
4026 Lisp_Object
*lispy_user_signals
[] =
4028 &Qusr1_signal
, &Qusr2_signal
4032 /* A vector, indexed by button number, giving the down-going location
4033 of currently depressed buttons, both scroll bar and non-scroll bar.
4035 The elements have the form
4036 (BUTTON-NUMBER MODIFIER-MASK . REST)
4037 where REST is the cdr of a position as it would be reported in the event.
4039 The make_lispy_event function stores positions here to tell the
4040 difference between click and drag events, and to store the starting
4041 location to be included in drag events. */
4043 static Lisp_Object button_down_location
;
4045 /* Information about the most recent up-going button event: Which
4046 button, what location, and what time. */
4048 static int last_mouse_button
;
4049 static int last_mouse_x
;
4050 static int last_mouse_y
;
4051 static unsigned long button_down_time
;
4053 /* The maximum time between clicks to make a double-click,
4054 or Qnil to disable double-click detection,
4055 or Qt for no time limit. */
4056 Lisp_Object Vdouble_click_time
;
4058 /* The number of clicks in this multiple-click. */
4060 int double_click_count
;
4062 /* Given a struct input_event, build the lisp event which represents
4063 it. If EVENT is 0, build a mouse movement event from the mouse
4064 movement buffer, which should have a movement event in it.
4066 Note that events must be passed to this function in the order they
4067 are received; this function stores the location of button presses
4068 in order to build drag events when the button is released. */
4071 make_lispy_event (event
)
4072 struct input_event
*event
;
4076 switch (SWITCH_ENUM_CAST (event
->kind
))
4078 /* A simple keystroke. */
4079 case ascii_keystroke
:
4081 Lisp_Object lispy_c
;
4082 int c
= event
->code
& 0377;
4083 /* Turn ASCII characters into control characters
4085 if (event
->modifiers
& ctrl_modifier
)
4086 c
= make_ctrl_char (c
);
4088 /* Add in the other modifier bits. We took care of ctrl_modifier
4089 just above, and the shift key was taken care of by the X code,
4090 and applied to control characters by make_ctrl_char. */
4091 c
|= (event
->modifiers
4092 & (meta_modifier
| alt_modifier
4093 | hyper_modifier
| super_modifier
));
4094 /* Distinguish Shift-SPC from SPC. */
4095 if ((event
->code
& 0377) == 040
4096 && event
->modifiers
& shift_modifier
)
4097 c
|= shift_modifier
;
4098 button_down_time
= 0;
4099 XSETFASTINT (lispy_c
, c
);
4103 /* A function key. The symbol may need to have modifier prefixes
4105 case non_ascii_keystroke
:
4106 button_down_time
= 0;
4108 for (i
= 0; i
< sizeof (lispy_accent_codes
) / sizeof (int); i
++)
4109 if (event
->code
== lispy_accent_codes
[i
])
4110 return modify_event_symbol (i
,
4112 Qfunction_key
, Qnil
,
4113 lispy_accent_keys
, &accent_key_syms
,
4114 (sizeof (lispy_accent_keys
)
4115 / sizeof (lispy_accent_keys
[0])));
4117 /* Handle system-specific keysyms. */
4118 if (event
->code
& (1 << 28))
4120 /* We need to use an alist rather than a vector as the cache
4121 since we can't make a vector long enuf. */
4122 if (NILP (current_kboard
->system_key_syms
))
4123 current_kboard
->system_key_syms
= Fcons (Qnil
, Qnil
);
4124 return modify_event_symbol (event
->code
,
4127 current_kboard
->Vsystem_key_alist
,
4128 0, ¤t_kboard
->system_key_syms
,
4133 if (event
->code
>= 0x400 && event
->code
< 0x500)
4134 return modify_event_symbol (event
->code
- 0x400,
4135 event
->modifiers
& ~shift_modifier
,
4136 Qfunction_key
, Qnil
,
4137 lispy_kana_keys
, &func_key_syms
,
4138 (sizeof (lispy_kana_keys
)
4139 / sizeof (lispy_kana_keys
[0])));
4140 #endif /* XK_kana_A */
4142 #ifdef ISO_FUNCTION_KEY_OFFSET
4143 if (event
->code
< FUNCTION_KEY_OFFSET
4144 && event
->code
>= ISO_FUNCTION_KEY_OFFSET
)
4145 return modify_event_symbol (event
->code
- ISO_FUNCTION_KEY_OFFSET
,
4147 Qfunction_key
, Qnil
,
4148 iso_lispy_function_keys
, &func_key_syms
,
4149 (sizeof (iso_lispy_function_keys
)
4150 / sizeof (iso_lispy_function_keys
[0])));
4153 return modify_event_symbol (event
->code
- FUNCTION_KEY_OFFSET
,
4155 Qfunction_key
, Qnil
,
4156 lispy_function_keys
, &func_key_syms
,
4157 (sizeof (lispy_function_keys
)
4158 / sizeof (lispy_function_keys
[0])));
4161 /* A mouse click. Figure out where it is, decide whether it's
4162 a press, click or drag, and build the appropriate structure. */
4164 #ifndef USE_TOOLKIT_SCROLL_BARS
4165 case scroll_bar_click
:
4168 int button
= event
->code
;
4170 Lisp_Object position
;
4171 Lisp_Object
*start_pos_ptr
;
4172 Lisp_Object start_pos
;
4174 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
4177 /* Build the position as appropriate for this mouse click. */
4178 if (event
->kind
== mouse_click
)
4181 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
4184 Lisp_Object string_info
= Qnil
;
4187 /* Ignore mouse events that were made on frame that
4188 have been deleted. */
4189 if (! FRAME_LIVE_P (f
))
4192 /* EVENT->x and EVENT->y are frame-relative pixel
4193 coordinates at this place. Under old redisplay, COLUMN
4194 and ROW are set to frame relative glyph coordinates
4195 which are then used to determine whether this click is
4196 in a menu (non-toolkit version). */
4197 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4198 &column
, &row
, NULL
, 1);
4200 #ifndef USE_X_TOOLKIT
4201 /* In the non-toolkit version, clicks on the menu bar
4202 are ordinary button events in the event buffer.
4203 Distinguish them, and invoke the menu.
4205 (In the toolkit version, the toolkit handles the menu bar
4206 and Emacs doesn't know about it until after the user
4207 makes a selection.) */
4208 if (row
>= 0 && row
< FRAME_MENU_BAR_LINES (f
)
4209 && (event
->modifiers
& down_modifier
))
4211 Lisp_Object items
, item
;
4216 /* Activate the menu bar on the down event. If the
4217 up event comes in before the menu code can deal with it,
4219 if (! (event
->modifiers
& down_modifier
))
4223 /* Find the menu bar item under `column'. */
4225 items
= FRAME_MENU_BAR_ITEMS (f
);
4226 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
4228 Lisp_Object pos
, string
;
4229 string
= XVECTOR (items
)->contents
[i
+ 1];
4230 pos
= XVECTOR (items
)->contents
[i
+ 3];
4233 if (column
>= XINT (pos
)
4234 && column
< XINT (pos
) + XSTRING (string
)->size
)
4236 item
= XVECTOR (items
)->contents
[i
];
4241 /* ELisp manual 2.4b says (x y) are window relative but
4242 code says they are frame-relative. */
4244 = Fcons (event
->frame_or_window
,
4246 Fcons (Fcons (event
->x
, event
->y
),
4247 Fcons (make_number (event
->timestamp
),
4250 return Fcons (item
, Fcons (position
, Qnil
));
4252 #endif /* not USE_X_TOOLKIT */
4254 /* Set `window' to the window under frame pixel coordinates
4255 event->x/event->y. */
4256 window
= window_from_coordinates (f
, XINT (event
->x
),
4257 XINT (event
->y
), &part
, 0);
4259 if (!WINDOWP (window
))
4261 window
= event
->frame_or_window
;
4266 /* It's a click in window window at frame coordinates
4267 event->x/ event->y. */
4268 struct window
*w
= XWINDOW (window
);
4270 /* Get window relative coordinates. Original code
4271 `rounded' this to glyph boundaries. */
4272 int wx
= FRAME_TO_WINDOW_PIXEL_X (w
, XINT (event
->x
));
4273 int wy
= FRAME_TO_WINDOW_PIXEL_Y (w
, XINT (event
->y
));
4275 /* Set event coordinates to window-relative coordinates
4276 for constructing the Lisp event below. */
4277 XSETINT (event
->x
, wx
);
4278 XSETINT (event
->y
, wy
);
4280 if (part
== 1 || part
== 3)
4282 /* Mode line or top line. Look for a string under
4283 the mouse that may have a `local-map' property. */
4287 posn
= part
== 1 ? Qmode_line
: Qheader_line
;
4288 string
= mode_line_string (w
, wx
, wy
, part
== 1, &charpos
);
4289 if (STRINGP (string
))
4290 string_info
= Fcons (string
, make_number (charpos
));
4293 posn
= Qvertical_line
;
4295 XSETINT (posn
, buffer_posn_from_coords (w
, &wx
, &wy
));
4301 Fcons (Fcons (event
->x
, event
->y
),
4302 Fcons (make_number (event
->timestamp
),
4305 : Fcons (string_info
, Qnil
))))));
4307 #ifndef USE_TOOLKIT_SCROLL_BARS
4310 /* It's a scrollbar click. */
4312 Lisp_Object portion_whole
;
4315 window
= event
->frame_or_window
;
4316 portion_whole
= Fcons (event
->x
, event
->y
);
4317 part
= *scroll_bar_parts
[(int) event
->part
];
4321 Fcons (Qvertical_scroll_bar
,
4322 Fcons (portion_whole
,
4323 Fcons (make_number (event
->timestamp
),
4324 Fcons (part
, Qnil
)))));
4326 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4328 start_pos_ptr
= &XVECTOR (button_down_location
)->contents
[button
];
4330 start_pos
= *start_pos_ptr
;
4331 *start_pos_ptr
= Qnil
;
4333 is_double
= (button
== last_mouse_button
4334 && XINT (event
->x
) == last_mouse_x
4335 && XINT (event
->y
) == last_mouse_y
4336 && button_down_time
!= 0
4337 && (EQ (Vdouble_click_time
, Qt
)
4338 || (INTEGERP (Vdouble_click_time
)
4339 && ((int)(event
->timestamp
- button_down_time
)
4340 < XINT (Vdouble_click_time
)))));
4341 last_mouse_button
= button
;
4342 last_mouse_x
= XINT (event
->x
);
4343 last_mouse_y
= XINT (event
->y
);
4345 /* If this is a button press, squirrel away the location, so
4346 we can decide later whether it was a click or a drag. */
4347 if (event
->modifiers
& down_modifier
)
4351 double_click_count
++;
4352 event
->modifiers
|= ((double_click_count
> 2)
4357 double_click_count
= 1;
4358 button_down_time
= event
->timestamp
;
4359 *start_pos_ptr
= Fcopy_alist (position
);
4362 /* Now we're releasing a button - check the co-ordinates to
4363 see if this was a click or a drag. */
4364 else if (event
->modifiers
& up_modifier
)
4366 /* If we did not see a down before this up,
4367 ignore the up. Probably this happened because
4368 the down event chose a menu item.
4369 It would be an annoyance to treat the release
4370 of the button that chose the menu item
4371 as a separate event. */
4373 if (!CONSP (start_pos
))
4376 event
->modifiers
&= ~up_modifier
;
4377 #if 0 /* Formerly we treated an up with no down as a click event. */
4378 if (!CONSP (start_pos
))
4379 event
->modifiers
|= click_modifier
;
4383 /* The third element of every position should be the (x,y)
4387 down
= Fnth (make_number (2), start_pos
);
4388 if (EQ (event
->x
, XCAR (down
))
4389 && EQ (event
->y
, XCDR (down
)))
4391 event
->modifiers
|= click_modifier
;
4395 button_down_time
= 0;
4396 event
->modifiers
|= drag_modifier
;
4398 /* Don't check is_double; treat this as multiple
4399 if the down-event was multiple. */
4400 if (double_click_count
> 1)
4401 event
->modifiers
|= ((double_click_count
> 2)
4407 /* Every mouse event should either have the down_modifier or
4408 the up_modifier set. */
4412 /* Get the symbol we should use for the mouse click. */
4415 head
= modify_event_symbol (button
,
4418 lispy_mouse_names
, &mouse_syms
,
4419 (sizeof (lispy_mouse_names
)
4420 / sizeof (lispy_mouse_names
[0])));
4421 if (event
->modifiers
& drag_modifier
)
4426 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
4429 Fcons (make_number (double_click_count
),
4438 #if USE_TOOLKIT_SCROLL_BARS
4440 /* We don't have down and up events if using toolkit scroll bars,
4441 so make this always a click event. Store in the `part' of
4442 the Lisp event a symbol which maps to the following actions:
4444 `above_handle' page up
4445 `below_handle' page down
4449 `bottom' bottom of buffer
4450 `handle' thumb has been dragged.
4451 `end-scroll' end of interaction with scroll bar
4453 The incoming input_event contains in its `part' member an
4454 index of type `enum scroll_bar_part' which we can use as an
4455 index in scroll_bar_parts to get the appropriate symbol. */
4457 case scroll_bar_click
:
4459 Lisp_Object position
, head
, window
, portion_whole
, part
;
4461 window
= event
->frame_or_window
;
4462 portion_whole
= Fcons (event
->x
, event
->y
);
4463 part
= *scroll_bar_parts
[(int) event
->part
];
4467 Fcons (Qvertical_scroll_bar
,
4468 Fcons (portion_whole
,
4469 Fcons (make_number (event
->timestamp
),
4470 Fcons (part
, Qnil
)))));
4472 /* Always treat scroll bar events as clicks. */
4473 event
->modifiers
|= click_modifier
;
4475 /* Get the symbol we should use for the mouse click. */
4476 head
= modify_event_symbol (event
->code
,
4479 lispy_mouse_names
, &mouse_syms
,
4480 (sizeof (lispy_mouse_names
)
4481 / sizeof (lispy_mouse_names
[0])));
4482 return Fcons (head
, Fcons (position
, Qnil
));
4485 #endif /* USE_TOOLKIT_SCROLL_BARS */
4488 case w32_scroll_bar_click
:
4490 int button
= event
->code
;
4492 Lisp_Object position
;
4493 Lisp_Object
*start_pos_ptr
;
4494 Lisp_Object start_pos
;
4496 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
4501 Lisp_Object portion_whole
;
4504 window
= event
->frame_or_window
;
4505 portion_whole
= Fcons (event
->x
, event
->y
);
4506 part
= *scroll_bar_parts
[(int) event
->part
];
4510 Fcons (Qvertical_scroll_bar
,
4511 Fcons (portion_whole
,
4512 Fcons (make_number (event
->timestamp
),
4513 Fcons (part
, Qnil
)))));
4516 /* Always treat W32 scroll bar events as clicks. */
4517 event
->modifiers
|= click_modifier
;
4520 /* Get the symbol we should use for the mouse click. */
4523 head
= modify_event_symbol (button
,
4526 lispy_mouse_names
, &mouse_syms
,
4527 (sizeof (lispy_mouse_names
)
4528 / sizeof (lispy_mouse_names
[0])));
4537 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
4540 Lisp_Object head
, position
;
4543 /* Ignore mouse events that were made on frame that
4544 have been deleted. */
4545 if (! FRAME_LIVE_P (f
))
4547 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4548 &column
, &row
, NULL
, 1);
4549 window
= window_from_coordinates (f
, column
, row
, &part
, 0);
4551 if (!WINDOWP (window
))
4553 window
= event
->frame_or_window
;
4558 int pixcolumn
, pixrow
;
4559 column
-= XINT (XWINDOW (window
)->left
);
4560 row
-= XINT (XWINDOW (window
)->top
);
4561 glyph_to_pixel_coords (f
, column
, row
, &pixcolumn
, &pixrow
);
4562 XSETINT (event
->x
, pixcolumn
);
4563 XSETINT (event
->y
, pixrow
);
4568 posn
= Qvertical_line
;
4570 posn
= Qheader_line
;
4573 buffer_posn_from_coords (XWINDOW (window
),
4578 Lisp_Object head
, position
;
4583 Fcons (Fcons (event
->x
, event
->y
),
4584 Fcons (make_number (event
->timestamp
),
4587 head
= modify_event_symbol (0, event
->modifiers
,
4589 lispy_mouse_wheel_names
,
4590 &mouse_wheel_syms
, 1);
4593 Fcons (make_number (event
->code
),
4597 #endif /* WINDOWSNT */
4608 /* The frame_or_window field should be a cons of the frame in
4609 which the event occurred and a list of the filenames
4611 if (! CONSP (event
->frame_or_window
))
4614 f
= XFRAME (XCAR (event
->frame_or_window
));
4615 files
= XCDR (event
->frame_or_window
);
4617 /* Ignore mouse events that were made on frames that
4618 have been deleted. */
4619 if (! FRAME_LIVE_P (f
))
4621 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4622 &column
, &row
, NULL
, 1);
4623 window
= window_from_coordinates (f
, column
, row
, &part
, 0);
4625 if (!WINDOWP (window
))
4627 window
= XCAR (event
->frame_or_window
);
4632 /* It's an event in window `window' at frame coordinates
4633 event->x/ event->y. */
4634 struct window
*w
= XWINDOW (window
);
4636 /* Get window relative coordinates. */
4637 int wx
= FRAME_TO_WINDOW_PIXEL_X (w
, XINT (event
->x
));
4638 int wy
= FRAME_TO_WINDOW_PIXEL_Y (w
, XINT (event
->y
));
4640 /* Set event coordinates to window-relative coordinates
4641 for constructing the Lisp event below. */
4642 XSETINT (event
->x
, wx
);
4643 XSETINT (event
->y
, wy
);
4648 posn
= Qvertical_line
;
4650 posn
= Qheader_line
;
4652 XSETINT (posn
, buffer_posn_from_coords (w
, &wx
, &wy
));
4656 Lisp_Object head
, position
;
4661 Fcons (Fcons (event
->x
, event
->y
),
4662 Fcons (make_number (event
->timestamp
),
4665 head
= modify_event_symbol (0, event
->modifiers
,
4667 lispy_drag_n_drop_names
,
4668 &drag_n_drop_syms
, 1);
4675 #endif /* HAVE_MOUSE */
4677 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
4678 case menu_bar_event
:
4679 /* The event value is in the cdr of the frame_or_window slot. */
4680 if (!CONSP (event
->frame_or_window
))
4682 return XCDR (event
->frame_or_window
);
4685 case TOOL_BAR_EVENT
:
4688 if (!CONSP (event
->frame_or_window
))
4690 key
= XCDR (event
->frame_or_window
);
4692 key
= apply_modifiers (event
->modifiers
, key
);
4697 /* A user signal. */
4698 return *lispy_user_signals
[event
->code
];
4700 /* The 'kind' field of the event is something we don't recognize. */
4709 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
4711 Lisp_Object bar_window
;
4712 enum scroll_bar_part part
;
4716 /* Is it a scroll bar movement? */
4717 if (frame
&& ! NILP (bar_window
))
4719 Lisp_Object part_sym
;
4721 part_sym
= *scroll_bar_parts
[(int) part
];
4722 return Fcons (Qscroll_bar_movement
,
4723 (Fcons (Fcons (bar_window
,
4724 Fcons (Qvertical_scroll_bar
,
4725 Fcons (Fcons (x
, y
),
4726 Fcons (make_number (time
),
4732 /* Or is it an ordinary mouse movement? */
4740 /* It's in a frame; which window on that frame? */
4741 window
= window_from_coordinates (frame
, XINT (x
), XINT (y
), &area
, 0);
4745 if (WINDOWP (window
))
4747 struct window
*w
= XWINDOW (window
);
4750 /* Get window relative coordinates. */
4751 wx
= FRAME_TO_WINDOW_PIXEL_X (w
, XINT (x
));
4752 wy
= FRAME_TO_WINDOW_PIXEL_Y (w
, XINT (y
));
4759 posn
= Qvertical_line
;
4761 posn
= Qheader_line
;
4763 XSETINT (posn
, buffer_posn_from_coords (w
, &wx
, &wy
));
4765 else if (frame
!= 0)
4767 XSETFRAME (window
, frame
);
4778 return Fcons (Qmouse_movement
,
4779 Fcons (Fcons (window
,
4781 Fcons (Fcons (x
, y
),
4782 Fcons (make_number (time
),
4788 #endif /* HAVE_MOUSE */
4790 /* Construct a switch frame event. */
4792 make_lispy_switch_frame (frame
)
4795 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
4798 /* Manipulating modifiers. */
4800 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
4802 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
4803 SYMBOL's name of the end of the modifiers; the string from this
4804 position is the unmodified symbol name.
4806 This doesn't use any caches. */
4809 parse_modifiers_uncached (symbol
, modifier_end
)
4813 struct Lisp_String
*name
;
4817 CHECK_SYMBOL (symbol
, 1);
4820 name
= XSYMBOL (symbol
)->name
;
4822 for (i
= 0; i
+2 <= STRING_BYTES (name
); )
4824 int this_mod_end
= 0;
4827 /* See if the name continues with a modifier word.
4828 Check that the word appears, but don't check what follows it.
4829 Set this_mod and this_mod_end to record what we find. */
4831 switch (name
->data
[i
])
4833 #define SINGLE_LETTER_MOD(BIT) \
4834 (this_mod_end = i + 1, this_mod = BIT)
4837 SINGLE_LETTER_MOD (alt_modifier
);
4841 SINGLE_LETTER_MOD (ctrl_modifier
);
4845 SINGLE_LETTER_MOD (hyper_modifier
);
4849 SINGLE_LETTER_MOD (meta_modifier
);
4853 SINGLE_LETTER_MOD (shift_modifier
);
4857 SINGLE_LETTER_MOD (super_modifier
);
4860 #undef SINGLE_LETTER_MOD
4863 /* If we found no modifier, stop looking for them. */
4864 if (this_mod_end
== 0)
4867 /* Check there is a dash after the modifier, so that it
4868 really is a modifier. */
4869 if (this_mod_end
>= STRING_BYTES (name
)
4870 || name
->data
[this_mod_end
] != '-')
4873 /* This modifier is real; look for another. */
4874 modifiers
|= this_mod
;
4875 i
= this_mod_end
+ 1;
4878 /* Should we include the `click' modifier? */
4879 if (! (modifiers
& (down_modifier
| drag_modifier
4880 | double_modifier
| triple_modifier
))
4881 && i
+ 7 == STRING_BYTES (name
)
4882 && strncmp (name
->data
+ i
, "mouse-", 6) == 0
4883 && ('0' <= name
->data
[i
+ 6] && name
->data
[i
+ 6] <= '9'))
4884 modifiers
|= click_modifier
;
4892 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
4893 prepended to the string BASE[0..BASE_LEN-1].
4894 This doesn't use any caches. */
4896 apply_modifiers_uncached (modifiers
, base
, base_len
, base_len_byte
)
4899 int base_len
, base_len_byte
;
4901 /* Since BASE could contain nulls, we can't use intern here; we have
4902 to use Fintern, which expects a genuine Lisp_String, and keeps a
4905 = (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
4911 /* Only the event queue may use the `up' modifier; it should always
4912 be turned into a click or drag event before presented to lisp code. */
4913 if (modifiers
& up_modifier
)
4916 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
4917 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
4918 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
4919 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
4920 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
4921 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
4922 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
4923 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
4924 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
4925 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
4926 /* The click modifier is denoted by the absence of other modifiers. */
4930 mod_len
= p
- new_mods
;
4934 Lisp_Object new_name
;
4936 new_name
= make_uninit_multibyte_string (mod_len
+ base_len
,
4937 mod_len
+ base_len_byte
);
4938 bcopy (new_mods
, XSTRING (new_name
)->data
, mod_len
);
4939 bcopy (base
, XSTRING (new_name
)->data
+ mod_len
, base_len_byte
);
4941 return Fintern (new_name
, Qnil
);
4946 static char *modifier_names
[] =
4948 "up", "down", "drag", "click", "double", "triple", 0, 0,
4949 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4950 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
4952 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
4954 static Lisp_Object modifier_symbols
;
4956 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
4958 lispy_modifier_list (modifiers
)
4961 Lisp_Object modifier_list
;
4964 modifier_list
= Qnil
;
4965 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
4966 if (modifiers
& (1<<i
))
4967 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
4970 return modifier_list
;
4974 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
4975 where UNMODIFIED is the unmodified form of SYMBOL,
4976 MASK is the set of modifiers present in SYMBOL's name.
4977 This is similar to parse_modifiers_uncached, but uses the cache in
4978 SYMBOL's Qevent_symbol_element_mask property, and maintains the
4979 Qevent_symbol_elements property. */
4982 parse_modifiers (symbol
)
4985 Lisp_Object elements
;
4987 elements
= Fget (symbol
, Qevent_symbol_element_mask
);
4988 if (CONSP (elements
))
4993 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
4994 Lisp_Object unmodified
;
4997 unmodified
= Fintern (make_string (XSYMBOL (symbol
)->name
->data
+ end
,
4998 STRING_BYTES (XSYMBOL (symbol
)->name
) - end
),
5001 if (modifiers
& ~(((EMACS_INT
)1 << VALBITS
) - 1))
5003 XSETFASTINT (mask
, modifiers
);
5004 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
5006 /* Cache the parsing results on SYMBOL. */
5007 Fput (symbol
, Qevent_symbol_element_mask
,
5009 Fput (symbol
, Qevent_symbol_elements
,
5010 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
5012 /* Since we know that SYMBOL is modifiers applied to unmodified,
5013 it would be nice to put that in unmodified's cache.
5014 But we can't, since we're not sure that parse_modifiers is
5021 /* Apply the modifiers MODIFIERS to the symbol BASE.
5022 BASE must be unmodified.
5024 This is like apply_modifiers_uncached, but uses BASE's
5025 Qmodifier_cache property, if present. It also builds
5026 Qevent_symbol_elements properties, since it has that info anyway.
5028 apply_modifiers copies the value of BASE's Qevent_kind property to
5029 the modified symbol. */
5031 apply_modifiers (modifiers
, base
)
5035 Lisp_Object cache
, index
, entry
, new_symbol
;
5037 /* Mask out upper bits. We don't know where this value's been. */
5038 modifiers
&= ((EMACS_INT
)1 << VALBITS
) - 1;
5040 /* The click modifier never figures into cache indices. */
5041 cache
= Fget (base
, Qmodifier_cache
);
5042 XSETFASTINT (index
, (modifiers
& ~click_modifier
));
5043 entry
= assq_no_quit (index
, cache
);
5046 new_symbol
= XCDR (entry
);
5049 /* We have to create the symbol ourselves. */
5050 new_symbol
= apply_modifiers_uncached (modifiers
,
5051 XSYMBOL (base
)->name
->data
,
5052 XSYMBOL (base
)->name
->size
,
5053 STRING_BYTES (XSYMBOL (base
)->name
));
5055 /* Add the new symbol to the base's cache. */
5056 entry
= Fcons (index
, new_symbol
);
5057 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
5059 /* We have the parsing info now for free, so add it to the caches. */
5060 XSETFASTINT (index
, modifiers
);
5061 Fput (new_symbol
, Qevent_symbol_element_mask
,
5062 Fcons (base
, Fcons (index
, Qnil
)));
5063 Fput (new_symbol
, Qevent_symbol_elements
,
5064 Fcons (base
, lispy_modifier_list (modifiers
)));
5067 /* Make sure this symbol is of the same kind as BASE.
5069 You'd think we could just set this once and for all when we
5070 intern the symbol above, but reorder_modifiers may call us when
5071 BASE's property isn't set right; we can't assume that just
5072 because it has a Qmodifier_cache property it must have its
5073 Qevent_kind set right as well. */
5074 if (NILP (Fget (new_symbol
, Qevent_kind
)))
5078 kind
= Fget (base
, Qevent_kind
);
5080 Fput (new_symbol
, Qevent_kind
, kind
);
5087 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
5088 return a symbol with the modifiers placed in the canonical order.
5089 Canonical order is alphabetical, except for down and drag, which
5090 always come last. The 'click' modifier is never written out.
5092 Fdefine_key calls this to make sure that (for example) C-M-foo
5093 and M-C-foo end up being equivalent in the keymap. */
5096 reorder_modifiers (symbol
)
5099 /* It's hopefully okay to write the code this way, since everything
5100 will soon be in caches, and no consing will be done at all. */
5103 parsed
= parse_modifiers (symbol
);
5104 return apply_modifiers ((int) XINT (XCAR (XCDR (parsed
))),
5109 /* For handling events, we often want to produce a symbol whose name
5110 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
5111 to some base, like the name of a function key or mouse button.
5112 modify_event_symbol produces symbols of this sort.
5114 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
5115 is the name of the i'th symbol. TABLE_SIZE is the number of elements
5118 Alternatively, NAME_ALIST is an alist mapping codes into symbol names.
5119 NAME_ALIST is used if it is non-nil; otherwise NAME_TABLE is used.
5121 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
5122 persist between calls to modify_event_symbol that it can use to
5123 store a cache of the symbols it's generated for this NAME_TABLE
5124 before. The object stored there may be a vector or an alist.
5126 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
5128 MODIFIERS is a set of modifier bits (as given in struct input_events)
5129 whose prefixes should be applied to the symbol name.
5131 SYMBOL_KIND is the value to be placed in the event_kind property of
5132 the returned symbol.
5134 The symbols we create are supposed to have an
5135 `event-symbol-elements' property, which lists the modifiers present
5136 in the symbol's name. */
5139 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_alist
,
5140 name_table
, symbol_table
, table_size
)
5143 Lisp_Object symbol_kind
;
5144 Lisp_Object name_alist
;
5146 Lisp_Object
*symbol_table
;
5147 unsigned int table_size
;
5150 Lisp_Object symbol_int
;
5152 /* Get rid of the "vendor-specific" bit here. */
5153 XSETINT (symbol_int
, symbol_num
& 0xffffff);
5155 /* Is this a request for a valid symbol? */
5156 if (symbol_num
< 0 || symbol_num
>= table_size
)
5159 if (CONSP (*symbol_table
))
5160 value
= Fcdr (assq_no_quit (symbol_int
, *symbol_table
));
5162 /* If *symbol_table doesn't seem to be initialized properly, fix that.
5163 *symbol_table should be a lisp vector TABLE_SIZE elements long,
5164 where the Nth element is the symbol for NAME_TABLE[N], or nil if
5165 we've never used that symbol before. */
5168 if (! VECTORP (*symbol_table
)
5169 || XVECTOR (*symbol_table
)->size
!= table_size
)
5173 XSETFASTINT (size
, table_size
);
5174 *symbol_table
= Fmake_vector (size
, Qnil
);
5177 value
= XVECTOR (*symbol_table
)->contents
[symbol_num
];
5180 /* Have we already used this symbol before? */
5183 /* No; let's create it. */
5184 if (!NILP (name_alist
))
5185 value
= Fcdr_safe (Fassq (symbol_int
, name_alist
));
5186 else if (name_table
!= 0 && name_table
[symbol_num
])
5187 value
= intern (name_table
[symbol_num
]);
5189 #ifdef HAVE_WINDOW_SYSTEM
5192 char *name
= x_get_keysym_name (symbol_num
);
5194 value
= intern (name
);
5201 sprintf (buf
, "key-%d", symbol_num
);
5202 value
= intern (buf
);
5205 if (CONSP (*symbol_table
))
5206 *symbol_table
= Fcons (Fcons (symbol_int
, value
), *symbol_table
);
5208 XVECTOR (*symbol_table
)->contents
[symbol_num
] = value
;
5210 /* Fill in the cache entries for this symbol; this also
5211 builds the Qevent_symbol_elements property, which the user
5213 apply_modifiers (modifiers
& click_modifier
, value
);
5214 Fput (value
, Qevent_kind
, symbol_kind
);
5217 /* Apply modifiers to that symbol. */
5218 return apply_modifiers (modifiers
, value
);
5221 /* Convert a list that represents an event type,
5222 such as (ctrl meta backspace), into the usual representation of that
5223 event type as a number or a symbol. */
5225 DEFUN ("event-convert-list", Fevent_convert_list
, Sevent_convert_list
, 1, 1, 0,
5226 "Convert the event description list EVENT-DESC to an event type.\n\
5227 EVENT-DESC should contain one base event type (a character or symbol)\n\
5228 and zero or more modifier names (control, meta, hyper, super, shift, alt,\n\
5229 drag, down, double or triple). The base must be last.\n\
5230 The return value is an event type (a character or symbol) which\n\
5231 has the same base event type and all the specified modifiers.")
5233 Lisp_Object event_desc
;
5241 while (CONSP (rest
))
5249 /* Given a symbol, see if it is a modifier name. */
5250 if (SYMBOLP (elt
) && CONSP (rest
))
5251 this = parse_solitary_modifier (elt
);
5255 else if (!NILP (base
))
5256 error ("Two bases given in one event");
5262 /* Let the symbol A refer to the character A. */
5263 if (SYMBOLP (base
) && XSYMBOL (base
)->name
->size
== 1)
5264 XSETINT (base
, XSYMBOL (base
)->name
->data
[0]);
5266 if (INTEGERP (base
))
5268 /* Turn (shift a) into A. */
5269 if ((modifiers
& shift_modifier
) != 0
5270 && (XINT (base
) >= 'a' && XINT (base
) <= 'z'))
5272 XSETINT (base
, XINT (base
) - ('a' - 'A'));
5273 modifiers
&= ~shift_modifier
;
5276 /* Turn (control a) into C-a. */
5277 if (modifiers
& ctrl_modifier
)
5278 return make_number ((modifiers
& ~ctrl_modifier
)
5279 | make_ctrl_char (XINT (base
)));
5281 return make_number (modifiers
| XINT (base
));
5283 else if (SYMBOLP (base
))
5284 return apply_modifiers (modifiers
, base
);
5286 error ("Invalid base event");
5289 /* Try to recognize SYMBOL as a modifier name.
5290 Return the modifier flag bit, or 0 if not recognized. */
5293 parse_solitary_modifier (symbol
)
5296 struct Lisp_String
*name
= XSYMBOL (symbol
)->name
;
5298 switch (name
->data
[0])
5300 #define SINGLE_LETTER_MOD(BIT) \
5301 if (STRING_BYTES (name) == 1) \
5304 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
5305 if (LEN == STRING_BYTES (name) \
5306 && ! strncmp (name->data, NAME, LEN)) \
5310 SINGLE_LETTER_MOD (alt_modifier
);
5314 MULTI_LETTER_MOD (alt_modifier
, "alt", 3);
5318 SINGLE_LETTER_MOD (ctrl_modifier
);
5322 MULTI_LETTER_MOD (ctrl_modifier
, "ctrl", 4);
5323 MULTI_LETTER_MOD (ctrl_modifier
, "control", 7);
5327 SINGLE_LETTER_MOD (hyper_modifier
);
5331 MULTI_LETTER_MOD (hyper_modifier
, "hyper", 5);
5335 SINGLE_LETTER_MOD (meta_modifier
);
5339 MULTI_LETTER_MOD (meta_modifier
, "meta", 4);
5343 SINGLE_LETTER_MOD (shift_modifier
);
5347 MULTI_LETTER_MOD (shift_modifier
, "shift", 5);
5348 MULTI_LETTER_MOD (super_modifier
, "super", 5);
5349 SINGLE_LETTER_MOD (super_modifier
);
5353 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
5354 MULTI_LETTER_MOD (down_modifier
, "down", 4);
5355 MULTI_LETTER_MOD (double_modifier
, "double", 6);
5359 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
5362 #undef SINGLE_LETTER_MOD
5363 #undef MULTI_LETTER_MOD
5369 /* Return 1 if EVENT is a list whose elements are all integers or symbols.
5370 Such a list is not valid as an event,
5371 but it can be a Lucid-style event type list. */
5374 lucid_event_type_list_p (object
)
5379 if (! CONSP (object
))
5382 for (tail
= object
; CONSP (tail
); tail
= XCDR (tail
))
5386 if (! (INTEGERP (elt
) || SYMBOLP (elt
)))
5393 /* Store into *addr a value nonzero if terminal input chars are available.
5394 Serves the purpose of ioctl (0, FIONREAD, addr)
5395 but works even if FIONREAD does not exist.
5396 (In fact, this may actually read some input.)
5398 If DO_TIMERS_NOW is nonzero, actually run timer events that are ripe. */
5401 get_input_pending (addr
, do_timers_now
)
5405 /* First of all, have we already counted some input? */
5406 *addr
= !NILP (Vquit_flag
) || readable_events (do_timers_now
);
5408 /* If input is being read as it arrives, and we have none, there is none. */
5409 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
5412 /* Try to read some input and see how much we get. */
5414 *addr
= !NILP (Vquit_flag
) || readable_events (do_timers_now
);
5417 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
5420 gobble_input (expected
)
5425 if (interrupt_input
)
5428 mask
= sigblock (sigmask (SIGIO
));
5429 read_avail_input (expected
);
5433 #ifdef POLL_FOR_INPUT
5434 if (read_socket_hook
&& !interrupt_input
&& poll_suppress_count
== 0)
5437 mask
= sigblock (sigmask (SIGALRM
));
5438 read_avail_input (expected
);
5444 read_avail_input (expected
);
5448 /* Put a buffer_switch_event in the buffer
5449 so that read_key_sequence will notice the new current buffer. */
5452 record_asynch_buffer_change ()
5454 struct input_event event
;
5457 event
.kind
= buffer_switch_event
;
5458 event
.frame_or_window
= Qnil
;
5461 /* We don't need a buffer-switch event unless Emacs is waiting for input.
5462 The purpose of the event is to make read_key_sequence look up the
5463 keymaps again. If we aren't in read_key_sequence, we don't need one,
5464 and the event could cause trouble by messing up (input-pending-p). */
5465 tem
= Fwaiting_for_user_input_p ();
5469 /* We never need these events if we have no asynchronous subprocesses. */
5473 /* Make sure no interrupt happens while storing the event. */
5475 if (interrupt_input
)
5478 mask
= sigblock (sigmask (SIGIO
));
5479 kbd_buffer_store_event (&event
);
5486 kbd_buffer_store_event (&event
);
5493 /* Read any terminal input already buffered up by the system
5494 into the kbd_buffer, but do not wait.
5496 EXPECTED should be nonzero if the caller knows there is some input.
5498 Except on VMS, all input is read by this function.
5499 If interrupt_input is nonzero, this function MUST be called
5500 only when SIGIO is blocked.
5502 Returns the number of keyboard chars read, or -1 meaning
5503 this is a bad time to try to read input. */
5506 read_avail_input (expected
)
5509 struct input_event buf
[KBD_BUFFER_SIZE
];
5513 if (read_socket_hook
)
5514 /* No need for FIONREAD or fcntl; just say don't wait. */
5515 nread
= (*read_socket_hook
) (input_fd
, buf
, KBD_BUFFER_SIZE
, expected
);
5518 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
5519 the kbd_buffer can really hold. That may prevent loss
5520 of characters on some systems when input is stuffed at us. */
5521 unsigned char cbuf
[KBD_BUFFER_SIZE
- 1];
5524 /* Determine how many characters we should *try* to read. */
5527 #else /* not WINDOWSNT */
5529 n_to_read
= dos_keysns ();
5532 #else /* not MSDOS */
5534 /* Find out how much input is available. */
5535 if (ioctl (input_fd
, FIONREAD
, &n_to_read
) < 0)
5536 /* Formerly simply reported no input, but that sometimes led to
5537 a failure of Emacs to terminate.
5538 SIGHUP seems appropriate if we can't reach the terminal. */
5539 /* ??? Is it really right to send the signal just to this process
5540 rather than to the whole process group?
5541 Perhaps on systems with FIONREAD Emacs is alone in its group. */
5542 kill (getpid (), SIGHUP
);
5545 if (n_to_read
> sizeof cbuf
)
5546 n_to_read
= sizeof cbuf
;
5547 #else /* no FIONREAD */
5548 #if defined (USG) || defined (DGUX)
5549 /* Read some input if available, but don't wait. */
5550 n_to_read
= sizeof cbuf
;
5551 fcntl (input_fd
, F_SETFL
, O_NDELAY
);
5556 #endif /* not MSDOS */
5557 #endif /* not WINDOWSNT */
5559 /* Now read; for one reason or another, this will not block.
5560 NREAD is set to the number of chars read. */
5564 cbuf
[0] = dos_keyread ();
5567 nread
= emacs_read (input_fd
, cbuf
, n_to_read
);
5569 /* POSIX infers that processes which are not in the session leader's
5570 process group won't get SIGHUP's at logout time. BSDI adheres to
5571 this part standard and returns -1 from read (0) with errno==EIO
5572 when the control tty is taken away.
5573 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
5574 if (nread
== -1 && errno
== EIO
)
5576 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
5577 /* The kernel sometimes fails to deliver SIGHUP for ptys.
5578 This looks incorrect, but it isn't, because _BSD causes
5579 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
5580 and that causes a value other than 0 when there is no input. */
5586 /* We used to retry the read if it was interrupted.
5587 But this does the wrong thing when O_NDELAY causes
5588 an EAGAIN error. Does anybody know of a situation
5589 where a retry is actually needed? */
5591 nread
< 0 && (errno
== EAGAIN
5605 #if defined (USG) || defined (DGUX)
5606 fcntl (input_fd
, F_SETFL
, 0);
5607 #endif /* USG or DGUX */
5608 #endif /* no FIONREAD */
5609 for (i
= 0; i
< nread
; i
++)
5611 buf
[i
].kind
= ascii_keystroke
;
5612 buf
[i
].modifiers
= 0;
5613 if (meta_key
== 1 && (cbuf
[i
] & 0x80))
5614 buf
[i
].modifiers
= meta_modifier
;
5618 buf
[i
].code
= cbuf
[i
];
5619 buf
[i
].frame_or_window
= selected_frame
;
5623 /* Scan the chars for C-g and store them in kbd_buffer. */
5624 for (i
= 0; i
< nread
; i
++)
5626 kbd_buffer_store_event (&buf
[i
]);
5627 /* Don't look at input that follows a C-g too closely.
5628 This reduces lossage due to autorepeat on C-g. */
5629 if (buf
[i
].kind
== ascii_keystroke
5630 && buf
[i
].code
== quit_char
)
5636 #endif /* not VMS */
5638 #ifdef SIGIO /* for entire page */
5639 /* Note SIGIO has been undef'd if FIONREAD is missing. */
5642 input_available_signal (signo
)
5645 /* Must preserve main program's value of errno. */
5646 int old_errno
= errno
;
5648 extern int select_alarmed
;
5651 #if defined (USG) && !defined (POSIX_SIGNALS)
5652 /* USG systems forget handlers when they are used;
5653 must reestablish each time */
5654 signal (signo
, input_available_signal
);
5661 if (input_available_clear_time
)
5662 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
5667 nread
= read_avail_input (1);
5668 /* -1 means it's not ok to read the input now.
5669 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
5670 0 means there was no keyboard input available. */
5675 select_alarmed
= 1; /* Force the select emulator back to life */
5686 /* Send ourselves a SIGIO.
5688 This function exists so that the UNBLOCK_INPUT macro in
5689 blockinput.h can have some way to take care of input we put off
5690 dealing with, without assuming that every file which uses
5691 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
5693 reinvoke_input_signal ()
5696 kill (getpid (), SIGIO
);
5702 /* Return the prompt-string of a sparse keymap.
5703 This is the first element which is a string.
5704 Return nil if there is none. */
5712 register Lisp_Object tem
;
5721 static void menu_bar_item ();
5722 static void menu_bar_one_keymap ();
5724 /* These variables hold the vector under construction within
5725 menu_bar_items and its subroutines, and the current index
5726 for storing into that vector. */
5727 static Lisp_Object menu_bar_items_vector
;
5728 static int menu_bar_items_index
;
5730 /* Return a vector of menu items for a menu bar, appropriate
5731 to the current buffer. Each item has three elements in the vector:
5734 OLD is an old vector we can optionally reuse, or nil. */
5737 menu_bar_items (old
)
5740 /* The number of keymaps we're scanning right now, and the number of
5741 keymaps we have allocated space for. */
5744 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
5745 in the current keymaps, or nil where it is not a prefix. */
5748 Lisp_Object def
, tem
, tail
;
5757 struct gcpro gcpro1
;
5759 /* In order to build the menus, we need to call the keymap
5760 accessors. They all call QUIT. But this function is called
5761 during redisplay, during which a quit is fatal. So inhibit
5762 quitting while building the menus.
5763 We do this instead of specbind because (1) errors will clear it anyway
5764 and (2) this avoids risk of specpdl overflow. */
5765 oquit
= Vinhibit_quit
;
5769 menu_bar_items_vector
= old
;
5771 menu_bar_items_vector
= Fmake_vector (make_number (24), Qnil
);
5772 menu_bar_items_index
= 0;
5774 GCPRO1 (menu_bar_items_vector
);
5776 /* Build our list of keymaps.
5777 If we recognize a function key and replace its escape sequence in
5778 keybuf with its symbol, or if the sequence starts with a mouse
5779 click and we need to switch buffers, we jump back here to rebuild
5780 the initial keymaps from the current buffer. */
5784 /* Should overriding-terminal-local-map and overriding-local-map apply? */
5785 if (!NILP (Voverriding_local_map_menu_flag
))
5787 /* Yes, use them (if non-nil) as well as the global map. */
5788 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
5790 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
5791 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
5792 if (!NILP (Voverriding_local_map
))
5793 maps
[nmaps
++] = Voverriding_local_map
;
5797 /* No, so use major and minor mode keymaps. */
5798 nmaps
= current_minor_maps (NULL
, &tmaps
);
5799 maps
= (Lisp_Object
*) alloca ((nmaps
+ 2) * sizeof (maps
[0]));
5800 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
5801 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
5803 maps
[nmaps
++] = current_global_map
;
5806 /* Look up in each map the dummy prefix key `menu-bar'. */
5810 for (mapno
= nmaps
- 1; mapno
>= 0; mapno
--)
5812 if (! NILP (maps
[mapno
]))
5813 def
= get_keyelt (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0), 0);
5817 tem
= Fkeymapp (def
);
5819 menu_bar_one_keymap (def
);
5822 /* Move to the end those items that should be at the end. */
5824 for (tail
= Vmenu_bar_final_items
; CONSP (tail
); tail
= XCDR (tail
))
5827 int end
= menu_bar_items_index
;
5829 for (i
= 0; i
< end
; i
+= 4)
5830 if (EQ (XCAR (tail
), XVECTOR (menu_bar_items_vector
)->contents
[i
]))
5832 Lisp_Object tem0
, tem1
, tem2
, tem3
;
5833 /* Move the item at index I to the end,
5834 shifting all the others forward. */
5835 tem0
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 0];
5836 tem1
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 1];
5837 tem2
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
5838 tem3
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3];
5840 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
5841 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
5842 (end
- i
- 4) * sizeof (Lisp_Object
));
5843 XVECTOR (menu_bar_items_vector
)->contents
[end
- 4] = tem0
;
5844 XVECTOR (menu_bar_items_vector
)->contents
[end
- 3] = tem1
;
5845 XVECTOR (menu_bar_items_vector
)->contents
[end
- 2] = tem2
;
5846 XVECTOR (menu_bar_items_vector
)->contents
[end
- 1] = tem3
;
5851 /* Add nil, nil, nil, nil at the end. */
5852 i
= menu_bar_items_index
;
5853 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
5856 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
5857 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
5858 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
5859 menu_bar_items_vector
= tem
;
5861 /* Add this item. */
5862 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5863 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5864 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5865 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5866 menu_bar_items_index
= i
;
5868 Vinhibit_quit
= oquit
;
5870 return menu_bar_items_vector
;
5873 /* Scan one map KEYMAP, accumulating any menu items it defines
5874 in menu_bar_items_vector. */
5876 static Lisp_Object menu_bar_one_keymap_changed_items
;
5879 menu_bar_one_keymap (keymap
)
5882 Lisp_Object tail
, item
;
5884 menu_bar_one_keymap_changed_items
= Qnil
;
5886 /* Loop over all keymap entries that have menu strings. */
5887 for (tail
= keymap
; CONSP (tail
); tail
= XCDR (tail
))
5891 menu_bar_item (XCAR (item
), XCDR (item
));
5892 else if (VECTORP (item
))
5894 /* Loop over the char values represented in the vector. */
5895 int len
= XVECTOR (item
)->size
;
5897 for (c
= 0; c
< len
; c
++)
5899 Lisp_Object character
;
5900 XSETFASTINT (character
, c
);
5901 menu_bar_item (character
, XVECTOR (item
)->contents
[c
]);
5907 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
5908 If there's already an item for KEY, add this DEF to it. */
5910 Lisp_Object item_properties
;
5913 menu_bar_item (key
, item
)
5914 Lisp_Object key
, item
;
5916 struct gcpro gcpro1
;
5920 if (EQ (item
, Qundefined
))
5922 /* If a map has an explicit `undefined' as definition,
5923 discard any previously made menu bar item. */
5925 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
5926 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
5928 if (menu_bar_items_index
> i
+ 4)
5929 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
5930 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
5931 (menu_bar_items_index
- i
- 4) * sizeof (Lisp_Object
));
5932 menu_bar_items_index
-= 4;
5936 /* If there's no definition for this key yet,
5937 just ignore `undefined'. */
5941 GCPRO1 (key
); /* Is this necessary? */
5942 i
= parse_menu_item (item
, 0, 1);
5947 /* If this keymap has already contributed to this KEY,
5948 don't contribute to it a second time. */
5949 tem
= Fmemq (key
, menu_bar_one_keymap_changed_items
);
5953 menu_bar_one_keymap_changed_items
5954 = Fcons (key
, menu_bar_one_keymap_changed_items
);
5956 item
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
5958 /* Find any existing item for this KEY. */
5959 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
5960 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
5963 /* If we did not find this KEY, add it at the end. */
5964 if (i
== menu_bar_items_index
)
5966 /* If vector is too small, get a bigger one. */
5967 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
5970 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
5971 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
5972 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
5973 menu_bar_items_vector
= tem
;
5976 /* Add this item. */
5977 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = key
;
5978 XVECTOR (menu_bar_items_vector
)->contents
[i
++]
5979 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
5980 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Fcons (item
, Qnil
);
5981 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = make_number (0);
5982 menu_bar_items_index
= i
;
5984 /* We did find an item for this KEY. Add ITEM to its list of maps. */
5988 old
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
5989 XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2] = Fcons (item
, old
);
5993 /* This is used as the handler when calling menu_item_eval_property. */
5995 menu_item_eval_property_1 (arg
)
5998 /* If we got a quit from within the menu computation,
5999 quit all the way out of it. This takes care of C-] in the debugger. */
6000 if (CONSP (arg
) && EQ (XCAR (arg
), Qquit
))
6001 Fsignal (Qquit
, Qnil
);
6006 /* Evaluate an expression and return the result (or nil if something
6007 went wrong). Used to evaluate dynamic parts of menu items. */
6009 menu_item_eval_property (sexpr
)
6012 int count
= specpdl_ptr
- specpdl
;
6014 specbind (Qinhibit_redisplay
, Qt
);
6015 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
,
6016 menu_item_eval_property_1
);
6017 return unbind_to (count
, val
);
6020 /* This function parses a menu item and leaves the result in the
6021 vector item_properties.
6022 ITEM is a key binding, a possible menu item.
6023 If NOTREAL is nonzero, only check for equivalent key bindings, don't
6024 evaluate dynamic expressions in the menu item.
6025 INMENUBAR is > 0 when this is considered for an entry in a menu bar
6027 INMENUBAR is < 0 when this is considered for an entry in a keyboard menu.
6028 parse_menu_item returns true if the item is a menu item and false
6032 parse_menu_item (item
, notreal
, inmenubar
)
6034 int notreal
, inmenubar
;
6036 Lisp_Object def
, tem
, item_string
, start
;
6037 Lisp_Object cachelist
;
6039 Lisp_Object keyhint
;
6050 /* Create item_properties vector if necessary. */
6051 if (NILP (item_properties
))
6053 = Fmake_vector (make_number (ITEM_PROPERTY_ENABLE
+ 1), Qnil
);
6055 /* Initialize optional entries. */
6056 for (i
= ITEM_PROPERTY_DEF
; i
< ITEM_PROPERTY_ENABLE
; i
++)
6057 XVECTOR (item_properties
)->contents
[i
] = Qnil
;
6058 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
] = Qt
;
6060 /* Save the item here to protect it from GC. */
6061 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ITEM
] = item
;
6063 item_string
= XCAR (item
);
6067 if (STRINGP (item_string
))
6069 /* Old format menu item. */
6070 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
] = item_string
;
6072 /* Maybe help string. */
6073 if (CONSP (item
) && STRINGP (XCAR (item
)))
6075 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_HELP
]
6081 /* Maybee key binding cache. */
6082 if (CONSP (item
) && CONSP (XCAR (item
))
6083 && (NILP (XCAR (XCAR (item
)))
6084 || VECTORP (XCAR (XCAR (item
)))))
6086 cachelist
= XCAR (item
);
6090 /* This is the real definition--the function to run. */
6091 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
] = item
;
6093 /* Get enable property, if any. */
6096 tem
= Fget (item
, Qmenu_enable
);
6098 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
] = tem
;
6101 else if (EQ (item_string
, Qmenu_item
) && CONSP (item
))
6103 /* New format menu item. */
6104 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
]
6106 start
= XCDR (item
);
6109 /* We have a real binding. */
6110 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
]
6113 item
= XCDR (start
);
6114 /* Is there a cache list with key equivalences. */
6115 if (CONSP (item
) && CONSP (XCAR (item
)))
6117 cachelist
= XCAR (item
);
6121 /* Parse properties. */
6122 while (CONSP (item
) && CONSP (XCDR (item
)))
6127 if (EQ (tem
, QCenable
))
6128 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
]
6130 else if (EQ (tem
, QCvisible
) && !notreal
)
6132 /* If got a visible property and that evaluates to nil
6133 then ignore this item. */
6134 tem
= menu_item_eval_property (XCAR (item
));
6138 else if (EQ (tem
, QChelp
))
6139 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_HELP
]
6141 else if (EQ (tem
, QCfilter
))
6143 else if (EQ (tem
, QCkey_sequence
))
6146 if (NILP (cachelist
)
6147 && (SYMBOLP (tem
) || STRINGP (tem
) || VECTORP (tem
)))
6148 /* Be GC protected. Set keyhint to item instead of tem. */
6151 else if (EQ (tem
, QCkeys
))
6154 if (CONSP (tem
) || (STRINGP (tem
) && NILP (cachelist
)))
6155 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
]
6158 else if (EQ (tem
, QCbutton
) && CONSP (XCAR (item
)))
6163 if (EQ (type
, QCtoggle
) || EQ (type
, QCradio
))
6165 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
]
6167 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_TYPE
]
6174 else if (inmenubar
|| !NILP (start
))
6178 return 0; /* not a menu item */
6180 /* If item string is not a string, evaluate it to get string.
6181 If we don't get a string, skip this item. */
6182 item_string
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
6183 if (!(STRINGP (item_string
) || notreal
))
6185 item_string
= menu_item_eval_property (item_string
);
6186 if (!STRINGP (item_string
))
6188 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
] = item_string
;
6191 /* If got a filter apply it on definition. */
6192 def
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
6195 def
= menu_item_eval_property (list2 (XCAR (filter
),
6196 list2 (Qquote
, def
)));
6198 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
] = def
;
6201 /* If we got no definition, this item is just unselectable text which
6202 is OK in a submenu but not in the menubar. */
6204 return (inmenubar
? 0 : 1);
6206 /* Enable or disable selection of item. */
6207 tem
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
];
6213 tem
= menu_item_eval_property (tem
);
6214 if (inmenubar
&& NILP (tem
))
6215 return 0; /* Ignore disabled items in menu bar. */
6216 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
] = tem
;
6219 /* See if this is a separate pane or a submenu. */
6220 def
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
6221 tem
= get_keymap_1 (def
, 0, 1);
6222 /* For a subkeymap, just record its details and exit. */
6225 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_MAP
] = tem
;
6226 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
] = tem
;
6229 /* At the top level in the menu bar, do likewise for commands also.
6230 The menu bar does not display equivalent key bindings anyway.
6231 ITEM_PROPERTY_DEF is already set up properly. */
6235 /* This is a command. See if there is an equivalent key binding. */
6236 if (NILP (cachelist
))
6238 /* We have to create a cachelist. */
6239 CHECK_IMPURE (start
);
6240 XCDR (start
) = Fcons (Fcons (Qnil
, Qnil
), XCDR (start
));
6241 cachelist
= XCAR (XCDR (start
));
6243 tem
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
6244 if (!NILP (keyhint
))
6246 XCAR (cachelist
) = XCAR (keyhint
);
6249 else if (STRINGP (tem
))
6251 XCDR (cachelist
) = Fsubstitute_command_keys (tem
);
6252 XCAR (cachelist
) = Qt
;
6255 tem
= XCAR (cachelist
);
6262 tem
= Fkey_binding (tem
, Qnil
);
6264 prefix
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
6267 def
= XCAR (prefix
);
6268 prefix
= XCDR (prefix
);
6271 def
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
6273 if (NILP (XCAR (cachelist
))) /* Have no saved key. */
6275 if (newcache
/* Always check first time. */
6276 /* Should we check everything when precomputing key
6279 /* If something had no key binding before, don't recheck it
6280 because that is too slow--except if we have a list of
6281 rebound commands in Vdefine_key_rebound_commands, do
6282 recheck any command that appears in that list. */
6283 || (CONSP (Vdefine_key_rebound_commands
)
6284 && !NILP (Fmemq (def
, Vdefine_key_rebound_commands
))))
6287 /* We had a saved key. Is it still bound to the command? */
6290 /* If the command is an alias for another
6291 (such as lmenu.el set it up), check if the
6292 original command matches the cached command. */
6293 && !(SYMBOLP (def
) && EQ (tem
, XSYMBOL (def
)->function
))))
6294 chkcache
= 1; /* Need to recompute key binding. */
6298 /* Recompute equivalent key binding. If the command is an alias
6299 for another (such as lmenu.el set it up), see if the original
6300 command name has equivalent keys. Otherwise look up the
6301 specified command itself. We don't try both, because that
6302 makes lmenu menus slow. */
6303 if (SYMBOLP (def
) && SYMBOLP (XSYMBOL (def
)->function
)
6304 && ! NILP (Fget (def
, Qmenu_alias
)))
6305 def
= XSYMBOL (def
)->function
;
6306 tem
= Fwhere_is_internal (def
, Qnil
, Qt
, Qnil
);
6307 XCAR (cachelist
) = tem
;
6310 XCDR (cachelist
) = Qnil
;
6314 else if (!NILP (keyhint
) && !NILP (XCAR (cachelist
)))
6316 tem
= XCAR (cachelist
);
6320 newcache
= chkcache
;
6323 tem
= Fkey_description (tem
);
6326 if (STRINGP (XCAR (prefix
)))
6327 tem
= concat2 (XCAR (prefix
), tem
);
6328 if (STRINGP (XCDR (prefix
)))
6329 tem
= concat2 (tem
, XCDR (prefix
));
6331 XCDR (cachelist
) = tem
;
6335 tem
= XCDR (cachelist
);
6336 if (newcache
&& !NILP (tem
))
6338 tem
= concat3 (build_string (" ("), tem
, build_string (")"));
6339 XCDR (cachelist
) = tem
;
6342 /* If we only want to precompute equivalent key bindings, stop here. */
6346 /* If we have an equivalent key binding, use that. */
6347 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
] = tem
;
6349 /* Include this when menu help is implemented.
6350 tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP];
6351 if (!(NILP (tem) || STRINGP (tem)))
6353 tem = menu_item_eval_property (tem);
6356 XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP] = tem;
6360 /* Handle radio buttons or toggle boxes. */
6361 tem
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
];
6363 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
]
6364 = menu_item_eval_property (tem
);
6371 /***********************************************************************
6373 ***********************************************************************/
6375 /* A vector holding tool bar items while they are parsed in function
6376 tool_bar_items runs Each item occupies TOOL_BAR_ITEM_NSCLOTS elements
6379 static Lisp_Object tool_bar_items_vector
;
6381 /* A vector holding the result of parse_tool_bar_item. Layout is like
6382 the one for a single item in tool_bar_items_vector. */
6384 static Lisp_Object tool_bar_item_properties
;
6386 /* Next free index in tool_bar_items_vector. */
6388 static int ntool_bar_items
;
6390 /* The symbols `tool-bar', and `:image'. */
6392 extern Lisp_Object Qtool_bar
;
6393 Lisp_Object QCimage
;
6395 /* Function prototypes. */
6397 static void init_tool_bar_items
P_ ((Lisp_Object
));
6398 static void process_tool_bar_item
P_ ((Lisp_Object
, Lisp_Object
));
6399 static int parse_tool_bar_item
P_ ((Lisp_Object
, Lisp_Object
));
6400 static void append_tool_bar_item
P_ ((void));
6403 /* Return a vector of tool bar items for keymaps currently in effect.
6404 Reuse vector REUSE if non-nil. Return in *NITEMS the number of
6405 tool bar items found. */
6408 tool_bar_items (reuse
, nitems
)
6416 extern Lisp_Object Voverriding_local_map_menu_flag
;
6417 extern Lisp_Object Voverriding_local_map
;
6421 /* In order to build the menus, we need to call the keymap
6422 accessors. They all call QUIT. But this function is called
6423 during redisplay, during which a quit is fatal. So inhibit
6424 quitting while building the menus. We do this instead of
6425 specbind because (1) errors will clear it anyway and (2) this
6426 avoids risk of specpdl overflow. */
6427 oquit
= Vinhibit_quit
;
6430 /* Initialize tool_bar_items_vector and protect it from GC. */
6431 init_tool_bar_items (reuse
);
6433 /* Build list of keymaps in maps. Set nmaps to the number of maps
6436 /* Should overriding-terminal-local-map and overriding-local-map apply? */
6437 if (!NILP (Voverriding_local_map_menu_flag
))
6439 /* Yes, use them (if non-nil) as well as the global map. */
6440 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
6442 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
6443 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
6444 if (!NILP (Voverriding_local_map
))
6445 maps
[nmaps
++] = Voverriding_local_map
;
6449 /* No, so use major and minor mode keymaps. */
6450 nmaps
= current_minor_maps (NULL
, &tmaps
);
6451 maps
= (Lisp_Object
*) alloca ((nmaps
+ 2) * sizeof (maps
[0]));
6452 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
6453 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
6456 /* Add global keymap at the end. */
6457 maps
[nmaps
++] = current_global_map
;
6459 /* Process maps in reverse order and look up in each map the prefix
6461 for (i
= nmaps
- 1; i
>= 0; --i
)
6462 if (!NILP (maps
[i
]))
6466 keymap
= get_keyelt (access_keymap (maps
[i
], Qtool_bar
, 1, 1), 0);
6467 if (!NILP (Fkeymapp (keymap
)))
6471 /* KEYMAP is a list `(keymap (KEY . BINDING) ...)'. */
6472 for (tail
= keymap
; CONSP (tail
); tail
= XCDR (tail
))
6474 Lisp_Object keydef
= XCAR (tail
);
6476 process_tool_bar_item (XCAR (keydef
), XCDR (keydef
));
6481 Vinhibit_quit
= oquit
;
6482 *nitems
= ntool_bar_items
/ TOOL_BAR_ITEM_NSLOTS
;
6483 return tool_bar_items_vector
;
6487 /* Process the definition of KEY which is DEF. */
6490 process_tool_bar_item (key
, def
)
6491 Lisp_Object key
, def
;
6494 extern Lisp_Object Qundefined
;
6495 struct gcpro gcpro1
, gcpro2
;
6497 /* Protect KEY and DEF from GC because parse_tool_bar_item may call
6501 if (EQ (def
, Qundefined
))
6503 /* If a map has an explicit `undefined' as definition,
6504 discard any previously made item. */
6505 for (i
= 0; i
< ntool_bar_items
; i
+= TOOL_BAR_ITEM_NSLOTS
)
6507 Lisp_Object
*v
= XVECTOR (tool_bar_items_vector
)->contents
+ i
;
6509 if (EQ (key
, v
[TOOL_BAR_ITEM_KEY
]))
6511 if (ntool_bar_items
> i
+ TOOL_BAR_ITEM_NSLOTS
)
6512 bcopy (v
+ TOOL_BAR_ITEM_NSLOTS
, v
,
6513 ((ntool_bar_items
- i
- TOOL_BAR_ITEM_NSLOTS
)
6514 * sizeof (Lisp_Object
)));
6515 ntool_bar_items
-= TOOL_BAR_ITEM_NSLOTS
;
6520 else if (parse_tool_bar_item (key
, def
))
6521 /* Append a new tool bar item to tool_bar_items_vector. Accept
6522 more than one definition for the same key. */
6523 append_tool_bar_item ();
6529 /* Parse a tool bar item specification ITEM for key KEY and return the
6530 result in tool_bar_item_properties. Value is zero if ITEM is
6533 ITEM is a list `(menu-item CAPTION BINDING PROPS...)'.
6535 CAPTION is the caption of the item, If it's not a string, it is
6536 evaluated to get a string.
6538 BINDING is the tool bar item's binding. Tool-bar items with keymaps
6539 as binding are currently ignored.
6541 The following properties are recognized:
6545 FORM is evaluated and specifies whether the tool bar item is
6546 enabled or disabled.
6550 FORM is evaluated and specifies whether the tool bar item is visible.
6552 - `:filter FUNCTION'
6554 FUNCTION is invoked with one parameter `(quote BINDING)'. Its
6555 result is stored as the new binding.
6557 - `:button (TYPE SELECTED)'
6559 TYPE must be one of `:radio' or `:toggle'. SELECTED is evaluated
6560 and specifies whether the button is selected (pressed) or not.
6564 IMAGES is either a single image specification or a vector of four
6565 image specifications. See enum tool_bar_item_images.
6567 - `:help HELP-STRING'.
6569 Gives a help string to display for the tool bar item. */
6572 parse_tool_bar_item (key
, item
)
6573 Lisp_Object key
, item
;
6575 /* Access slot with index IDX of vector tool_bar_item_properties. */
6576 #define PROP(IDX) XVECTOR (tool_bar_item_properties)->contents[IDX]
6578 Lisp_Object filter
= Qnil
;
6579 Lisp_Object caption
;
6580 extern Lisp_Object QCenable
, QCvisible
, QChelp
, QCfilter
;
6581 extern Lisp_Object QCbutton
, QCtoggle
, QCradio
;
6584 /* Defininition looks like `(tool-bar-item CAPTION BINDING
6585 PROPS...)'. Rule out items that aren't lists, don't start with
6586 `tool-bar-item' or whose rest following `tool-bar-item' is not a
6589 || !EQ (XCAR (item
), Qmenu_item
)
6590 || (item
= XCDR (item
),
6594 /* Create tool_bar_item_properties vector if necessary. Reset it to
6596 if (VECTORP (tool_bar_item_properties
))
6598 for (i
= 0; i
< TOOL_BAR_ITEM_NSLOTS
; ++i
)
6602 tool_bar_item_properties
6603 = Fmake_vector (make_number (TOOL_BAR_ITEM_NSLOTS
), Qnil
);
6606 PROP (TOOL_BAR_ITEM_KEY
) = key
;
6607 PROP (TOOL_BAR_ITEM_ENABLED_P
) = Qt
;
6609 /* Get the caption of the item. If the caption is not a string,
6610 evaluate it to get a string. If we don't get a string, skip this
6612 caption
= XCAR (item
);
6613 if (!STRINGP (caption
))
6615 caption
= menu_item_eval_property (caption
);
6616 if (!STRINGP (caption
))
6619 PROP (TOOL_BAR_ITEM_CAPTION
) = caption
;
6621 /* Give up if rest following the caption is not a list. */
6626 /* Store the binding. */
6627 PROP (TOOL_BAR_ITEM_BINDING
) = XCAR (item
);
6630 /* Process the rest of the properties. */
6631 for (; CONSP (item
) && CONSP (XCDR (item
)); item
= XCDR (XCDR (item
)))
6633 Lisp_Object key
, value
;
6636 value
= XCAR (XCDR (item
));
6638 if (EQ (key
, QCenable
))
6639 /* `:enable FORM'. */
6640 PROP (TOOL_BAR_ITEM_ENABLED_P
) = value
;
6641 else if (EQ (key
, QCvisible
))
6643 /* `:visible FORM'. If got a visible property and that
6644 evaluates to nil then ignore this item. */
6645 if (NILP (menu_item_eval_property (value
)))
6648 else if (EQ (key
, QChelp
))
6649 /* `:help HELP-STRING'. */
6650 PROP (TOOL_BAR_ITEM_HELP
) = value
;
6651 else if (EQ (key
, QCfilter
))
6652 /* ':filter FORM'. */
6654 else if (EQ (key
, QCbutton
) && CONSP (value
))
6656 /* `:button (TYPE . SELECTED)'. */
6657 Lisp_Object type
, selected
;
6659 type
= XCAR (value
);
6660 selected
= XCDR (value
);
6661 if (EQ (type
, QCtoggle
) || EQ (type
, QCradio
))
6663 PROP (TOOL_BAR_ITEM_SELECTED_P
) = selected
;
6664 PROP (TOOL_BAR_ITEM_TYPE
) = type
;
6667 else if (EQ (key
, QCimage
)
6669 || (VECTORP (value
) && XVECTOR (value
)->size
== 4)))
6670 /* Value is either a single image specification or a vector
6671 of 4 such specifications for the different buttion states. */
6672 PROP (TOOL_BAR_ITEM_IMAGES
) = value
;
6675 /* If got a filter apply it on binding. */
6677 PROP (TOOL_BAR_ITEM_BINDING
)
6678 = menu_item_eval_property (list2 (filter
,
6680 PROP (TOOL_BAR_ITEM_BINDING
))));
6682 /* See if the binding is a keymap. Give up if it is. */
6683 if (!NILP (get_keymap_1 (PROP (TOOL_BAR_ITEM_BINDING
), 0, 1)))
6686 /* Enable or disable selection of item. */
6687 if (!EQ (PROP (TOOL_BAR_ITEM_ENABLED_P
), Qt
))
6688 PROP (TOOL_BAR_ITEM_ENABLED_P
)
6689 = menu_item_eval_property (PROP (TOOL_BAR_ITEM_ENABLED_P
));
6691 /* Handle radio buttons or toggle boxes. */
6692 if (!NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
)))
6693 PROP (TOOL_BAR_ITEM_SELECTED_P
)
6694 = menu_item_eval_property (PROP (TOOL_BAR_ITEM_SELECTED_P
));
6702 /* Initialize tool_bar_items_vector. REUSE, if non-nil, is a vector
6703 that can be reused. */
6706 init_tool_bar_items (reuse
)
6709 if (VECTORP (reuse
))
6710 tool_bar_items_vector
= reuse
;
6712 tool_bar_items_vector
= Fmake_vector (make_number (64), Qnil
);
6713 ntool_bar_items
= 0;
6717 /* Append parsed tool bar item properties from
6718 tool_bar_item_properties */
6721 append_tool_bar_item ()
6723 Lisp_Object
*to
, *from
;
6725 /* Enlarge tool_bar_items_vector if necessary. */
6726 if (ntool_bar_items
+ TOOL_BAR_ITEM_NSLOTS
6727 >= XVECTOR (tool_bar_items_vector
)->size
)
6729 Lisp_Object new_vector
;
6730 int old_size
= XVECTOR (tool_bar_items_vector
)->size
;
6732 new_vector
= Fmake_vector (make_number (2 * old_size
), Qnil
);
6733 bcopy (XVECTOR (tool_bar_items_vector
)->contents
,
6734 XVECTOR (new_vector
)->contents
,
6735 old_size
* sizeof (Lisp_Object
));
6736 tool_bar_items_vector
= new_vector
;
6739 /* Append entries from tool_bar_item_properties to the end of
6740 tool_bar_items_vector. */
6741 to
= XVECTOR (tool_bar_items_vector
)->contents
+ ntool_bar_items
;
6742 from
= XVECTOR (tool_bar_item_properties
)->contents
;
6743 bcopy (from
, to
, TOOL_BAR_ITEM_NSLOTS
* sizeof *to
);
6744 ntool_bar_items
+= TOOL_BAR_ITEM_NSLOTS
;
6751 /* Read a character using menus based on maps in the array MAPS.
6752 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
6753 Return t if we displayed a menu but the user rejected it.
6755 PREV_EVENT is the previous input event, or nil if we are reading
6756 the first event of a key sequence.
6758 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
6759 if we used a mouse menu to read the input, or zero otherwise. If
6760 USED_MOUSE_MENU is null, we don't dereference it.
6762 The prompting is done based on the prompt-string of the map
6763 and the strings associated with various map elements.
6765 This can be done with X menus or with menus put in the minibuf.
6766 These are done in different ways, depending on how the input will be read.
6767 Menus using X are done after auto-saving in read-char, getting the input
6768 event from Fx_popup_menu; menus using the minibuf use read_char recursively
6769 and do auto-saving in the inner call of read_char. */
6772 read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
6775 Lisp_Object prev_event
;
6776 int *used_mouse_menu
;
6779 register Lisp_Object name
;
6781 if (used_mouse_menu
)
6782 *used_mouse_menu
= 0;
6784 /* Use local over global Menu maps */
6786 if (! menu_prompting
)
6789 /* Optionally disregard all but the global map. */
6790 if (inhibit_local_menu_bar_menus
)
6792 maps
+= (nmaps
- 1);
6796 /* Get the menu name from the first map that has one (a prompt string). */
6797 for (mapno
= 0; mapno
< nmaps
; mapno
++)
6799 name
= map_prompt (maps
[mapno
]);
6804 /* If we don't have any menus, just read a character normally. */
6809 /* If we got to this point via a mouse click,
6810 use a real menu for mouse selection. */
6811 if (EVENT_HAS_PARAMETERS (prev_event
)
6812 && !EQ (XCAR (prev_event
), Qmenu_bar
)
6813 && !EQ (XCAR (prev_event
), Qtool_bar
))
6815 /* Display the menu and get the selection. */
6816 Lisp_Object
*realmaps
6817 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
6821 /* Use the maps that are not nil. */
6822 for (mapno
= 0; mapno
< nmaps
; mapno
++)
6823 if (!NILP (maps
[mapno
]))
6824 realmaps
[nmaps1
++] = maps
[mapno
];
6826 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
6831 record_menu_key (XCAR (value
));
6833 /* If we got multiple events, unread all but
6835 There is no way to prevent those unread events
6836 from showing up later in last_nonmenu_event.
6837 So turn symbol and integer events into lists,
6838 to indicate that they came from a mouse menu,
6839 so that when present in last_nonmenu_event
6840 they won't confuse things. */
6841 for (tem
= XCDR (value
); !NILP (tem
);
6844 record_menu_key (XCAR (tem
));
6845 if (SYMBOLP (XCAR (tem
))
6846 || INTEGERP (XCAR (tem
)))
6848 = Fcons (XCAR (tem
), Qnil
);
6851 /* If we got more than one event, put all but the first
6852 onto this list to be read later.
6853 Return just the first event now. */
6854 Vunread_command_events
6855 = nconc2 (XCDR (value
), Vunread_command_events
);
6856 value
= XCAR (value
);
6858 else if (NILP (value
))
6860 if (used_mouse_menu
)
6861 *used_mouse_menu
= 1;
6864 #endif /* HAVE_MENUS */
6868 /* Buffer in use so far for the minibuf prompts for menu keymaps.
6869 We make this bigger when necessary, and never free it. */
6870 static char *read_char_minibuf_menu_text
;
6871 /* Size of that buffer. */
6872 static int read_char_minibuf_menu_width
;
6875 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
6881 register Lisp_Object name
;
6883 int width
= FRAME_WIDTH (SELECTED_FRAME ()) - 4;
6886 Lisp_Object rest
, vector
;
6889 if (! menu_prompting
)
6892 /* Make sure we have a big enough buffer for the menu text. */
6893 if (read_char_minibuf_menu_text
== 0)
6895 read_char_minibuf_menu_width
= width
+ 4;
6896 read_char_minibuf_menu_text
= (char *) xmalloc (width
+ 4);
6898 else if (width
+ 4 > read_char_minibuf_menu_width
)
6900 read_char_minibuf_menu_width
= width
+ 4;
6901 read_char_minibuf_menu_text
6902 = (char *) xrealloc (read_char_minibuf_menu_text
, width
+ 4);
6904 menu
= read_char_minibuf_menu_text
;
6906 /* Get the menu name from the first map that has one (a prompt string). */
6907 for (mapno
= 0; mapno
< nmaps
; mapno
++)
6909 name
= map_prompt (maps
[mapno
]);
6914 /* If we don't have any menus, just read a character normally. */
6918 /* Prompt string always starts with map's prompt, and a space. */
6919 strcpy (menu
, XSTRING (name
)->data
);
6920 nlength
= STRING_BYTES (XSTRING (name
));
6921 menu
[nlength
++] = ':';
6922 menu
[nlength
++] = ' ';
6925 /* Start prompting at start of first map. */
6929 /* Present the documented bindings, a line at a time. */
6936 Lisp_Object orig_defn_macro
;
6938 /* Loop over elements of map. */
6943 /* If reached end of map, start at beginning of next map. */
6947 /* At end of last map, wrap around to first map if just starting,
6948 or end this line if already have something on it. */
6952 if (notfirst
|| nobindings
) break;
6957 /* Look at the next element of the map. */
6959 elt
= XVECTOR (vector
)->contents
[idx
];
6961 elt
= Fcar_safe (rest
);
6963 if (idx
< 0 && VECTORP (elt
))
6965 /* If we found a dense table in the keymap,
6966 advanced past it, but start scanning its contents. */
6967 rest
= Fcdr_safe (rest
);
6973 /* An ordinary element. */
6974 Lisp_Object event
, tem
;
6978 event
= Fcar_safe (elt
); /* alist */
6979 elt
= Fcdr_safe (elt
);
6983 XSETINT (event
, idx
); /* vector */
6986 /* Ignore the element if it has no prompt string. */
6987 if (INTEGERP (event
) && parse_menu_item (elt
, 0, -1))
6989 /* 1 if the char to type matches the string. */
6991 Lisp_Object upcased_event
, downcased_event
;
6994 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
6996 upcased_event
= Fupcase (event
);
6997 downcased_event
= Fdowncase (event
);
6998 char_matches
= (XINT (upcased_event
) == XSTRING (s
)->data
[0]
6999 || XINT (downcased_event
) == XSTRING (s
)->data
[0]);
7001 desc
= Fsingle_key_description (event
);
7004 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
7006 /* Insert equivalent keybinding. */
7007 s
= concat2 (s
, tem
);
7010 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_TYPE
];
7011 if (EQ (tem
, QCradio
) || EQ (tem
, QCtoggle
))
7013 /* Insert button prefix. */
7014 Lisp_Object selected
7015 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
];
7016 if (EQ (tem
, QCradio
))
7017 tem
= build_string (NILP (selected
) ? "(*) " : "( ) ");
7019 tem
= build_string (NILP (selected
) ? "[X] " : "[ ] ");
7020 s
= concat2 (tem
, s
);
7024 /* If we have room for the prompt string, add it to this line.
7025 If this is the first on the line, always add it. */
7026 if ((XSTRING (s
)->size
+ i
+ 2
7027 + (char_matches
? 0 : XSTRING (desc
)->size
+ 3))
7033 /* Punctuate between strings. */
7036 strcpy (menu
+ i
, ", ");
7042 /* If the char to type doesn't match the string's
7043 first char, explicitly show what char to type. */
7046 /* Add as much of string as fits. */
7047 thiswidth
= XSTRING (desc
)->size
;
7048 if (thiswidth
+ i
> width
)
7049 thiswidth
= width
- i
;
7050 bcopy (XSTRING (desc
)->data
, menu
+ i
, thiswidth
);
7052 strcpy (menu
+ i
, " = ");
7056 /* Add as much of string as fits. */
7057 thiswidth
= XSTRING (s
)->size
;
7058 if (thiswidth
+ i
> width
)
7059 thiswidth
= width
- i
;
7060 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
7066 /* If this element does not fit, end the line now,
7067 and save the element for the next line. */
7068 strcpy (menu
+ i
, "...");
7073 /* Move past this element. */
7074 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
7075 /* Handle reaching end of dense table. */
7080 rest
= Fcdr_safe (rest
);
7084 /* Prompt with that and read response. */
7085 message2_nolog (menu
, strlen (menu
),
7086 ! NILP (current_buffer
->enable_multibyte_characters
));
7088 /* Make believe its not a keyboard macro in case the help char
7089 is pressed. Help characters are not recorded because menu prompting
7090 is not used on replay.
7092 orig_defn_macro
= current_kboard
->defining_kbd_macro
;
7093 current_kboard
->defining_kbd_macro
= Qnil
;
7095 obj
= read_char (commandflag
, 0, 0, Qnil
, 0);
7096 while (BUFFERP (obj
));
7097 current_kboard
->defining_kbd_macro
= orig_defn_macro
;
7099 if (!INTEGERP (obj
))
7104 if (! EQ (obj
, menu_prompt_more_char
)
7105 && (!INTEGERP (menu_prompt_more_char
)
7106 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
7108 if (!NILP (current_kboard
->defining_kbd_macro
))
7109 store_kbd_macro_char (obj
);
7112 /* Help char - go round again */
7116 /* Reading key sequences. */
7118 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
7119 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
7120 keymap, or nil otherwise. Return the index of the first keymap in
7121 which KEY has any binding, or NMAPS if no map has a binding.
7123 If KEY is a meta ASCII character, treat it like meta-prefix-char
7124 followed by the corresponding non-meta character. Keymaps in
7125 CURRENT with non-prefix bindings for meta-prefix-char become nil in
7128 If KEY has no bindings in any of the CURRENT maps, NEXT is left
7131 NEXT may be the same array as CURRENT. */
7134 follow_key (key
, nmaps
, current
, defs
, next
)
7136 Lisp_Object
*current
, *defs
, *next
;
7139 int i
, first_binding
;
7142 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
7143 followed by the corresponding non-meta character.
7144 Put the results into DEFS, since we are going to alter that anyway.
7145 Do not alter CURRENT or NEXT. */
7146 if (INTEGERP (key
) && (XINT (key
) & CHAR_META
))
7148 for (i
= 0; i
< nmaps
; i
++)
7149 if (! NILP (current
[i
]))
7152 def
= get_keyelt (access_keymap (current
[i
],
7153 meta_prefix_char
, 1, 0), 0);
7155 /* Note that since we pass the resulting bindings through
7156 get_keymap_1, non-prefix bindings for meta-prefix-char
7158 defs
[i
] = get_keymap_1 (def
, 0, 1);
7164 XSETINT (key
, XFASTINT (key
) & ~CHAR_META
);
7167 first_binding
= nmaps
;
7168 for (i
= nmaps
- 1; i
>= 0; i
--)
7170 if (! NILP (current
[i
]))
7178 defs
[i
] = get_keyelt (access_keymap (map
, key
, 1, 0), 0);
7179 if (! NILP (defs
[i
]))
7186 /* Given the set of bindings we've found, produce the next set of maps. */
7187 if (first_binding
< nmaps
)
7188 for (i
= 0; i
< nmaps
; i
++)
7189 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0, 1);
7191 return first_binding
;
7194 /* Read a sequence of keys that ends with a non prefix character,
7195 storing it in KEYBUF, a buffer of size BUFSIZE.
7197 Return the length of the key sequence stored.
7198 Return -1 if the user rejected a command menu.
7200 Echo starting immediately unless `prompt' is 0.
7202 Where a key sequence ends depends on the currently active keymaps.
7203 These include any minor mode keymaps active in the current buffer,
7204 the current buffer's local map, and the global map.
7206 If a key sequence has no other bindings, we check Vfunction_key_map
7207 to see if some trailing subsequence might be the beginning of a
7208 function key's sequence. If so, we try to read the whole function
7209 key, and substitute its symbolic name into the key sequence.
7211 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
7212 `double-' events into similar click events, if that would make them
7213 bound. We try to turn `triple-' events first into `double-' events,
7216 If we get a mouse click in a mode line, vertical divider, or other
7217 non-text area, we treat the click as if it were prefixed by the
7218 symbol denoting that area - `mode-line', `vertical-line', or
7221 If the sequence starts with a mouse click, we read the key sequence
7222 with respect to the buffer clicked on, not the current buffer.
7224 If the user switches frames in the midst of a key sequence, we put
7225 off the switch-frame event until later; the next call to
7226 read_char will return it.
7228 If FIX_CURRENT_BUFFER is nonzero, we restore current_buffer
7229 from the selected window's buffer. */
7232 read_key_sequence (keybuf
, bufsize
, prompt
, dont_downcase_last
,
7233 can_return_switch_frame
, fix_current_buffer
)
7234 Lisp_Object
*keybuf
;
7237 int dont_downcase_last
;
7238 int can_return_switch_frame
;
7239 int fix_current_buffer
;
7241 int count
= specpdl_ptr
- specpdl
;
7243 /* How many keys there are in the current key sequence. */
7246 /* The length of the echo buffer when we started reading, and
7247 the length of this_command_keys when we started reading. */
7251 /* The number of keymaps we're scanning right now, and the number of
7252 keymaps we have allocated space for. */
7254 int nmaps_allocated
= 0;
7256 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
7257 the current keymaps. */
7260 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
7261 in the current keymaps, or nil where it is not a prefix. */
7262 Lisp_Object
*submaps
;
7264 /* The local map to start out with at start of key sequence. */
7265 Lisp_Object orig_local_map
;
7267 /* 1 if we have already considered switching to the local-map property
7268 of the place where a mouse click occurred. */
7269 int localized_local_map
= 0;
7271 /* The index in defs[] of the first keymap that has a binding for
7272 this key sequence. In other words, the lowest i such that
7273 defs[i] is non-nil. */
7276 /* If t < mock_input, then KEYBUF[t] should be read as the next
7279 We use this to recover after recognizing a function key. Once we
7280 realize that a suffix of the current key sequence is actually a
7281 function key's escape sequence, we replace the suffix with the
7282 function key's binding from Vfunction_key_map. Now keybuf
7283 contains a new and different key sequence, so the echo area,
7284 this_command_keys, and the submaps and defs arrays are wrong. In
7285 this situation, we set mock_input to t, set t to 0, and jump to
7286 restart_sequence; the loop will read keys from keybuf up until
7287 mock_input, thus rebuilding the state; and then it will resume
7288 reading characters from the keyboard. */
7291 /* If the sequence is unbound in submaps[], then
7292 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
7293 and fkey_map is its binding.
7295 These might be > t, indicating that all function key scanning
7296 should hold off until t reaches them. We do this when we've just
7297 recognized a function key, to avoid searching for the function
7298 key's again in Vfunction_key_map. */
7299 int fkey_start
= 0, fkey_end
= 0;
7300 Lisp_Object fkey_map
;
7302 /* Likewise, for key_translation_map. */
7303 int keytran_start
= 0, keytran_end
= 0;
7304 Lisp_Object keytran_map
;
7306 /* If we receive a ``switch-frame'' event in the middle of a key sequence,
7307 we put it off for later. While we're reading, we keep the event here. */
7308 Lisp_Object delayed_switch_frame
;
7310 /* See the comment below... */
7311 #if defined (GOBBLE_FIRST_EVENT)
7312 Lisp_Object first_event
;
7315 Lisp_Object original_uppercase
;
7316 int original_uppercase_position
= -1;
7318 /* Gets around Microsoft compiler limitations. */
7321 struct buffer
*starting_buffer
;
7323 /* Nonzero if we seem to have got the beginning of a binding
7324 in function_key_map. */
7325 int function_key_possible
= 0;
7326 int key_translation_possible
= 0;
7328 /* Save the status of key translation before each step,
7329 so that we can restore this after downcasing. */
7330 Lisp_Object prev_fkey_map
;
7331 int prev_fkey_start
;
7334 Lisp_Object prev_keytran_map
;
7335 int prev_keytran_start
;
7336 int prev_keytran_end
;
7338 #if defined (GOBBLE_FIRST_EVENT)
7342 raw_keybuf_count
= 0;
7344 last_nonmenu_event
= Qnil
;
7346 delayed_switch_frame
= Qnil
;
7347 fkey_map
= Vfunction_key_map
;
7348 keytran_map
= Vkey_translation_map
;
7350 /* If there is no function-key-map, turn off function key scanning. */
7351 if (NILP (Fkeymapp (Vfunction_key_map
)))
7352 fkey_start
= fkey_end
= bufsize
+ 1;
7354 /* If there is no key-translation-map, turn off scanning. */
7355 if (NILP (Fkeymapp (Vkey_translation_map
)))
7356 keytran_start
= keytran_end
= bufsize
+ 1;
7361 echo_prompt (XSTRING (prompt
)->data
);
7362 else if (cursor_in_echo_area
&& echo_keystrokes
)
7363 /* This doesn't put in a dash if the echo buffer is empty, so
7364 you don't always see a dash hanging out in the minibuffer. */
7368 /* Record the initial state of the echo area and this_command_keys;
7369 we will need to restore them if we replay a key sequence. */
7371 echo_start
= echo_length ();
7372 keys_start
= this_command_key_count
;
7373 this_single_command_key_start
= keys_start
;
7375 #if defined (GOBBLE_FIRST_EVENT)
7376 /* This doesn't quite work, because some of the things that read_char
7377 does cannot safely be bypassed. It seems too risky to try to make
7380 /* Read the first char of the sequence specially, before setting
7381 up any keymaps, in case a filter runs and switches buffers on us. */
7382 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
7384 #endif /* GOBBLE_FIRST_EVENT */
7386 orig_local_map
= get_local_map (PT
, current_buffer
);
7388 /* We jump here when the key sequence has been thoroughly changed, and
7389 we need to rescan it starting from the beginning. When we jump here,
7390 keybuf[0..mock_input] holds the sequence we should reread. */
7393 starting_buffer
= current_buffer
;
7394 function_key_possible
= 0;
7395 key_translation_possible
= 0;
7397 /* Build our list of keymaps.
7398 If we recognize a function key and replace its escape sequence in
7399 keybuf with its symbol, or if the sequence starts with a mouse
7400 click and we need to switch buffers, we jump back here to rebuild
7401 the initial keymaps from the current buffer. */
7405 if (!NILP (current_kboard
->Voverriding_terminal_local_map
)
7406 || !NILP (Voverriding_local_map
))
7408 if (3 > nmaps_allocated
)
7410 submaps
= (Lisp_Object
*) alloca (3 * sizeof (submaps
[0]));
7411 defs
= (Lisp_Object
*) alloca (3 * sizeof (defs
[0]));
7412 nmaps_allocated
= 3;
7415 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
7416 submaps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
7417 if (!NILP (Voverriding_local_map
))
7418 submaps
[nmaps
++] = Voverriding_local_map
;
7422 nmaps
= current_minor_maps (0, &maps
);
7423 if (nmaps
+ 2 > nmaps_allocated
)
7425 submaps
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (submaps
[0]));
7426 defs
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (defs
[0]));
7427 nmaps_allocated
= nmaps
+ 2;
7429 bcopy (maps
, submaps
, nmaps
* sizeof (submaps
[0]));
7430 submaps
[nmaps
++] = orig_local_map
;
7432 submaps
[nmaps
++] = current_global_map
;
7435 /* Find an accurate initial value for first_binding. */
7436 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
7437 if (! NILP (submaps
[first_binding
]))
7440 /* Start from the beginning in keybuf. */
7443 /* These are no-ops the first time through, but if we restart, they
7444 revert the echo area and this_command_keys to their original state. */
7445 this_command_key_count
= keys_start
;
7446 if (INTERACTIVE
&& t
< mock_input
)
7447 echo_truncate (echo_start
);
7449 /* If the best binding for the current key sequence is a keymap, or
7450 we may be looking at a function key's escape sequence, keep on
7452 while ((first_binding
< nmaps
&& ! NILP (submaps
[first_binding
]))
7453 || (first_binding
>= nmaps
7455 /* mock input is never part of a function key's sequence. */
7456 && mock_input
<= fkey_start
)
7457 || (first_binding
>= nmaps
7458 && keytran_start
< t
&& key_translation_possible
)
7459 /* Don't return in the middle of a possible function key sequence,
7460 if the only bindings we found were via case conversion.
7461 Thus, if ESC O a has a function-key-map translation
7462 and ESC o has a binding, don't return after ESC O,
7463 so that we can translate ESC O plus the next character. */
7467 int used_mouse_menu
= 0;
7469 /* Where the last real key started. If we need to throw away a
7470 key that has expanded into more than one element of keybuf
7471 (say, a mouse click on the mode line which is being treated
7472 as [mode-line (mouse-...)], then we backtrack to this point
7474 int last_real_key_start
;
7476 /* These variables are analogous to echo_start and keys_start;
7477 while those allow us to restart the entire key sequence,
7478 echo_local_start and keys_local_start allow us to throw away
7480 int echo_local_start
, keys_local_start
, local_first_binding
;
7483 error ("Key sequence too long");
7486 echo_local_start
= echo_length ();
7487 keys_local_start
= this_command_key_count
;
7488 local_first_binding
= first_binding
;
7491 /* These are no-ops, unless we throw away a keystroke below and
7492 jumped back up to replay_key; in that case, these restore the
7493 variables to their original state, allowing us to replay the
7495 if (INTERACTIVE
&& t
< mock_input
)
7496 echo_truncate (echo_local_start
);
7497 this_command_key_count
= keys_local_start
;
7498 first_binding
= local_first_binding
;
7500 /* By default, assume each event is "real". */
7501 last_real_key_start
= t
;
7503 /* Does mock_input indicate that we are re-reading a key sequence? */
7507 add_command_key (key
);
7508 if (echo_keystrokes
)
7512 /* If not, we should actually read a character. */
7517 KBOARD
*interrupted_kboard
= current_kboard
;
7518 struct frame
*interrupted_frame
= SELECTED_FRAME ();
7519 if (setjmp (wrong_kboard_jmpbuf
))
7521 if (!NILP (delayed_switch_frame
))
7523 interrupted_kboard
->kbd_queue
7524 = Fcons (delayed_switch_frame
,
7525 interrupted_kboard
->kbd_queue
);
7526 delayed_switch_frame
= Qnil
;
7529 interrupted_kboard
->kbd_queue
7530 = Fcons (keybuf
[--t
], interrupted_kboard
->kbd_queue
);
7532 /* If the side queue is non-empty, ensure it begins with a
7533 switch-frame, so we'll replay it in the right context. */
7534 if (CONSP (interrupted_kboard
->kbd_queue
)
7535 && (key
= XCAR (interrupted_kboard
->kbd_queue
),
7536 !(EVENT_HAS_PARAMETERS (key
)
7537 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)),
7541 XSETFRAME (frame
, interrupted_frame
);
7542 interrupted_kboard
->kbd_queue
7543 = Fcons (make_lispy_switch_frame (frame
),
7544 interrupted_kboard
->kbd_queue
);
7547 orig_local_map
= get_local_map (PT
, current_buffer
);
7548 goto replay_sequence
;
7551 key
= read_char (NILP (prompt
), nmaps
, submaps
, last_nonmenu_event
,
7555 /* read_char returns t when it shows a menu and the user rejects it.
7559 unbind_to (count
, Qnil
);
7563 /* read_char returns -1 at the end of a macro.
7564 Emacs 18 handles this by returning immediately with a
7565 zero, so that's what we'll do. */
7566 if (INTEGERP (key
) && XINT (key
) == -1)
7569 /* The Microsoft C compiler can't handle the goto that
7575 /* If the current buffer has been changed from under us, the
7576 keymap may have changed, so replay the sequence. */
7580 /* Reset the current buffer from the selected window
7581 in case something changed the former and not the latter.
7582 This is to be more consistent with the behavior
7583 of the command_loop_1. */
7584 if (fix_current_buffer
)
7586 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7588 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
7589 Fset_buffer (XWINDOW (selected_window
)->buffer
);
7592 orig_local_map
= get_local_map (PT
, current_buffer
);
7593 goto replay_sequence
;
7596 /* If we have a quit that was typed in another frame, and
7597 quit_throw_to_read_char switched buffers,
7598 replay to get the right keymap. */
7599 if (XINT (key
) == quit_char
&& current_buffer
!= starting_buffer
)
7602 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
7606 orig_local_map
= get_local_map (PT
, current_buffer
);
7607 goto replay_sequence
;
7612 if (EVENT_HAS_PARAMETERS (key
)
7613 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)), Qswitch_frame
))
7615 /* If we're at the beginning of a key sequence, and the caller
7616 says it's okay, go ahead and return this event. If we're
7617 in the midst of a key sequence, delay it until the end. */
7618 if (t
> 0 || !can_return_switch_frame
)
7620 delayed_switch_frame
= key
;
7626 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
7629 /* Clicks in non-text areas get prefixed by the symbol
7630 in their CHAR-ADDRESS field. For example, a click on
7631 the mode line is prefixed by the symbol `mode-line'.
7633 Furthermore, key sequences beginning with mouse clicks
7634 are read using the keymaps of the buffer clicked on, not
7635 the current buffer. So we may have to switch the buffer
7638 When we turn one event into two events, we must make sure
7639 that neither of the two looks like the original--so that,
7640 if we replay the events, they won't be expanded again.
7641 If not for this, such reexpansion could happen either here
7642 or when user programs play with this-command-keys. */
7643 if (EVENT_HAS_PARAMETERS (key
))
7647 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
7648 if (EQ (kind
, Qmouse_click
))
7650 Lisp_Object window
, posn
;
7652 window
= POSN_WINDOW (EVENT_START (key
));
7653 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
7657 /* We're looking at the second event of a
7658 sequence which we expanded before. Set
7659 last_real_key_start appropriately. */
7661 last_real_key_start
= t
- 1;
7664 /* Key sequences beginning with mouse clicks are
7665 read using the keymaps in the buffer clicked on,
7666 not the current buffer. If we're at the
7667 beginning of a key sequence, switch buffers. */
7668 if (last_real_key_start
== 0
7670 && BUFFERP (XWINDOW (window
)->buffer
)
7671 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
7673 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
7677 /* Arrange to go back to the original buffer once we're
7678 done reading the key sequence. Note that we can't
7679 use save_excursion_{save,restore} here, because they
7680 save point as well as the current buffer; we don't
7681 want to save point, because redisplay may change it,
7682 to accommodate a Fset_window_start or something. We
7683 don't want to do this at the top of the function,
7684 because we may get input from a subprocess which
7685 wants to change the selected window and stuff (say,
7687 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
7689 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7691 set_buffer_internal (XBUFFER (XWINDOW (window
)->buffer
));
7692 orig_local_map
= get_local_map (PT
, current_buffer
);
7693 goto replay_sequence
;
7696 /* For a mouse click, get the local text-property keymap
7697 of the place clicked on, rather than point. */
7698 if (last_real_key_start
== 0
7699 && CONSP (XCDR (key
))
7700 && ! localized_local_map
)
7702 Lisp_Object map_here
, start
, pos
;
7704 localized_local_map
= 1;
7705 start
= EVENT_START (key
);
7707 if (CONSP (start
) && CONSP (XCDR (start
)))
7709 pos
= POSN_BUFFER_POSN (start
);
7711 && XINT (pos
) >= BEG
&& XINT (pos
) <= Z
)
7713 map_here
= get_local_map (XINT (pos
), current_buffer
);
7714 if (!EQ (map_here
, orig_local_map
))
7716 orig_local_map
= map_here
;
7720 goto replay_sequence
;
7726 /* Expand mode-line and scroll-bar events into two events:
7727 use posn as a fake prefix key. */
7730 if (t
+ 1 >= bufsize
)
7731 error ("Key sequence too long");
7736 /* Zap the position in key, so we know that we've
7737 expanded it, and don't try to do so again. */
7738 POSN_BUFFER_POSN (EVENT_START (key
))
7739 = Fcons (posn
, Qnil
);
7741 /* If on a mode line string with a local keymap,
7742 reconsider the key sequence with that keymap. */
7743 if (CONSP (POSN_STRING (EVENT_START (key
))))
7745 Lisp_Object string
, pos
, map
;
7747 string
= POSN_STRING (EVENT_START (key
));
7748 pos
= XCDR (string
);
7749 string
= XCAR (string
);
7752 && pos
< XSTRING (string
)->size
7753 && (map
= Fget_text_property (pos
, Qlocal_map
,
7757 orig_local_map
= map
;
7758 goto replay_sequence
;
7765 else if (CONSP (XCDR (key
))
7766 && CONSP (EVENT_START (key
))
7767 && CONSP (XCDR (EVENT_START (key
))))
7771 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
7772 /* Handle menu-bar events:
7773 insert the dummy prefix event `menu-bar'. */
7774 if (EQ (posn
, Qmenu_bar
) || EQ (posn
, Qtool_bar
))
7776 if (t
+ 1 >= bufsize
)
7777 error ("Key sequence too long");
7781 /* Zap the position in key, so we know that we've
7782 expanded it, and don't try to do so again. */
7783 POSN_BUFFER_POSN (EVENT_START (key
))
7784 = Fcons (posn
, Qnil
);
7787 goto replay_sequence
;
7789 else if (CONSP (posn
))
7791 /* We're looking at the second event of a
7792 sequence which we expanded before. Set
7793 last_real_key_start appropriately. */
7794 if (last_real_key_start
== t
&& t
> 0)
7795 last_real_key_start
= t
- 1;
7800 /* We have finally decided that KEY is something we might want
7802 first_binding
= (follow_key (key
,
7803 nmaps
- first_binding
,
7804 submaps
+ first_binding
,
7805 defs
+ first_binding
,
7806 submaps
+ first_binding
)
7809 /* If KEY wasn't bound, we'll try some fallbacks. */
7810 if (first_binding
>= nmaps
)
7814 head
= EVENT_HEAD (key
);
7815 if (help_char_p (head
) && t
> 0)
7817 read_key_sequence_cmd
= Vprefix_help_command
;
7819 last_nonmenu_event
= key
;
7820 /* The Microsoft C compiler can't handle the goto that
7828 Lisp_Object breakdown
;
7831 breakdown
= parse_modifiers (head
);
7832 modifiers
= XINT (XCAR (XCDR (breakdown
)));
7833 /* Attempt to reduce an unbound mouse event to a simpler
7834 event that is bound:
7835 Drags reduce to clicks.
7836 Double-clicks reduce to clicks.
7837 Triple-clicks reduce to double-clicks, then to clicks.
7838 Down-clicks are eliminated.
7839 Double-downs reduce to downs, then are eliminated.
7840 Triple-downs reduce to double-downs, then to downs,
7841 then are eliminated. */
7842 if (modifiers
& (down_modifier
| drag_modifier
7843 | double_modifier
| triple_modifier
))
7845 while (modifiers
& (down_modifier
| drag_modifier
7846 | double_modifier
| triple_modifier
))
7848 Lisp_Object new_head
, new_click
;
7849 if (modifiers
& triple_modifier
)
7850 modifiers
^= (double_modifier
| triple_modifier
);
7851 else if (modifiers
& double_modifier
)
7852 modifiers
&= ~double_modifier
;
7853 else if (modifiers
& drag_modifier
)
7854 modifiers
&= ~drag_modifier
;
7857 /* Dispose of this `down' event by simply jumping
7858 back to replay_key, to get another event.
7860 Note that if this event came from mock input,
7861 then just jumping back to replay_key will just
7862 hand it to us again. So we have to wipe out any
7865 We could delete keybuf[t] and shift everything
7866 after that to the left by one spot, but we'd also
7867 have to fix up any variable that points into
7868 keybuf, and shifting isn't really necessary
7871 Adding prefixes for non-textual mouse clicks
7872 creates two characters of mock input, and both
7873 must be thrown away. If we're only looking at
7874 the prefix now, we can just jump back to
7875 replay_key. On the other hand, if we've already
7876 processed the prefix, and now the actual click
7877 itself is giving us trouble, then we've lost the
7878 state of the keymaps we want to backtrack to, and
7879 we need to replay the whole sequence to rebuild
7882 Beyond that, only function key expansion could
7883 create more than two keys, but that should never
7884 generate mouse events, so it's okay to zero
7885 mock_input in that case too.
7887 Isn't this just the most wonderful code ever? */
7888 if (t
== last_real_key_start
)
7895 mock_input
= last_real_key_start
;
7896 goto replay_sequence
;
7901 = apply_modifiers (modifiers
, XCAR (breakdown
));
7903 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
7905 /* Look for a binding for this new key. follow_key
7906 promises that it didn't munge submaps the
7907 last time we called it, since key was unbound. */
7909 = (follow_key (new_click
,
7910 nmaps
- local_first_binding
,
7911 submaps
+ local_first_binding
,
7912 defs
+ local_first_binding
,
7913 submaps
+ local_first_binding
)
7914 + local_first_binding
);
7916 /* If that click is bound, go for it. */
7917 if (first_binding
< nmaps
)
7922 /* Otherwise, we'll leave key set to the drag event. */
7929 /* Normally, last_nonmenu_event gets the previous key we read.
7930 But when a mouse popup menu is being used,
7931 we don't update last_nonmenu_event; it continues to hold the mouse
7932 event that preceded the first level of menu. */
7933 if (!used_mouse_menu
)
7934 last_nonmenu_event
= key
;
7936 /* Record what part of this_command_keys is the current key sequence. */
7937 this_single_command_key_start
= this_command_key_count
- t
;
7939 prev_fkey_map
= fkey_map
;
7940 prev_fkey_start
= fkey_start
;
7941 prev_fkey_end
= fkey_end
;
7943 prev_keytran_map
= keytran_map
;
7944 prev_keytran_start
= keytran_start
;
7945 prev_keytran_end
= keytran_end
;
7947 /* If the sequence is unbound, see if we can hang a function key
7948 off the end of it. We only want to scan real keyboard input
7949 for function key sequences, so if mock_input says that we're
7950 re-reading old events, don't examine it. */
7951 if (first_binding
>= nmaps
7954 Lisp_Object fkey_next
;
7956 /* Continue scan from fkey_end until we find a bound suffix.
7957 If we fail, increment fkey_start
7958 and start fkey_end from there. */
7959 while (fkey_end
< t
)
7963 key
= keybuf
[fkey_end
++];
7964 /* Look up meta-characters by prefixing them
7965 with meta_prefix_char. I hate this. */
7966 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
7971 (access_keymap (fkey_map
, meta_prefix_char
, 1, 0), 0),
7973 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
7976 fkey_next
= fkey_map
;
7979 = get_keyelt (access_keymap (fkey_next
, key
, 1, 0), 1);
7981 /* Handle symbol with autoload definition. */
7982 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
7983 && CONSP (XSYMBOL (fkey_next
)->function
)
7984 && EQ (XCAR (XSYMBOL (fkey_next
)->function
), Qautoload
))
7985 do_autoload (XSYMBOL (fkey_next
)->function
,
7988 /* Handle a symbol whose function definition is a keymap
7990 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
7991 && (!NILP (Farrayp (XSYMBOL (fkey_next
)->function
))
7992 || !NILP (Fkeymapp (XSYMBOL (fkey_next
)->function
))))
7993 fkey_next
= XSYMBOL (fkey_next
)->function
;
7995 #if 0 /* I didn't turn this on, because it might cause trouble
7996 for the mapping of return into C-m and tab into C-i. */
7997 /* Optionally don't map function keys into other things.
7998 This enables the user to redefine kp- keys easily. */
7999 if (SYMBOLP (key
) && !NILP (Vinhibit_function_key_mapping
))
8003 /* If the function key map gives a function, not an
8004 array, then call the function with no args and use
8005 its value instead. */
8006 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
8009 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8013 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
8014 fkey_next
= call1 (fkey_next
, prompt
);
8016 /* If the function returned something invalid,
8017 barf--don't ignore it.
8018 (To ignore it safely, we would need to gcpro a bunch of
8019 other variables.) */
8020 if (! (VECTORP (fkey_next
) || STRINGP (fkey_next
)))
8021 error ("Function in key-translation-map returns invalid key sequence");
8024 function_key_possible
= ! NILP (fkey_next
);
8026 /* If keybuf[fkey_start..fkey_end] is bound in the
8027 function key map and it's a suffix of the current
8028 sequence (i.e. fkey_end == t), replace it with
8029 the binding and restart with fkey_start at the end. */
8030 if ((VECTORP (fkey_next
) || STRINGP (fkey_next
))
8033 int len
= XFASTINT (Flength (fkey_next
));
8035 t
= fkey_start
+ len
;
8037 error ("Key sequence too long");
8039 if (VECTORP (fkey_next
))
8040 bcopy (XVECTOR (fkey_next
)->contents
,
8041 keybuf
+ fkey_start
,
8042 (t
- fkey_start
) * sizeof (keybuf
[0]));
8043 else if (STRINGP (fkey_next
))
8047 for (i
= 0; i
< len
; i
++)
8048 XSETFASTINT (keybuf
[fkey_start
+ i
],
8049 XSTRING (fkey_next
)->data
[i
]);
8053 fkey_start
= fkey_end
= t
;
8054 fkey_map
= Vfunction_key_map
;
8056 /* Do pass the results through key-translation-map.
8057 But don't retranslate what key-translation-map
8058 has already translated. */
8059 keytran_end
= keytran_start
;
8060 keytran_map
= Vkey_translation_map
;
8062 goto replay_sequence
;
8065 fkey_map
= get_keymap_1 (fkey_next
, 0, 1);
8067 /* If we no longer have a bound suffix, try a new positions for
8069 if (NILP (fkey_map
))
8071 fkey_end
= ++fkey_start
;
8072 fkey_map
= Vfunction_key_map
;
8073 function_key_possible
= 0;
8078 /* Look for this sequence in key-translation-map. */
8080 Lisp_Object keytran_next
;
8082 /* Scan from keytran_end until we find a bound suffix. */
8083 while (keytran_end
< t
)
8087 key
= keybuf
[keytran_end
++];
8088 /* Look up meta-characters by prefixing them
8089 with meta_prefix_char. I hate this. */
8090 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
8095 (access_keymap (keytran_map
, meta_prefix_char
, 1, 0), 0),
8097 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
8100 keytran_next
= keytran_map
;
8103 = get_keyelt (access_keymap (keytran_next
, key
, 1, 0), 1);
8105 /* Handle symbol with autoload definition. */
8106 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
8107 && CONSP (XSYMBOL (keytran_next
)->function
)
8108 && EQ (XCAR (XSYMBOL (keytran_next
)->function
), Qautoload
))
8109 do_autoload (XSYMBOL (keytran_next
)->function
,
8112 /* Handle a symbol whose function definition is a keymap
8114 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
8115 && (!NILP (Farrayp (XSYMBOL (keytran_next
)->function
))
8116 || !NILP (Fkeymapp (XSYMBOL (keytran_next
)->function
))))
8117 keytran_next
= XSYMBOL (keytran_next
)->function
;
8119 /* If the key translation map gives a function, not an
8120 array, then call the function with one arg and use
8121 its value instead. */
8122 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
8123 && keytran_end
== t
)
8125 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8129 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
8130 keytran_next
= call1 (keytran_next
, prompt
);
8132 /* If the function returned something invalid,
8133 barf--don't ignore it.
8134 (To ignore it safely, we would need to gcpro a bunch of
8135 other variables.) */
8136 if (! (VECTORP (keytran_next
) || STRINGP (keytran_next
)))
8137 error ("Function in key-translation-map returns invalid key sequence");
8140 key_translation_possible
= ! NILP (keytran_next
);
8142 /* If keybuf[keytran_start..keytran_end] is bound in the
8143 key translation map and it's a suffix of the current
8144 sequence (i.e. keytran_end == t), replace it with
8145 the binding and restart with keytran_start at the end. */
8146 if ((VECTORP (keytran_next
) || STRINGP (keytran_next
))
8147 && keytran_end
== t
)
8149 int len
= XFASTINT (Flength (keytran_next
));
8151 t
= keytran_start
+ len
;
8153 error ("Key sequence too long");
8155 if (VECTORP (keytran_next
))
8156 bcopy (XVECTOR (keytran_next
)->contents
,
8157 keybuf
+ keytran_start
,
8158 (t
- keytran_start
) * sizeof (keybuf
[0]));
8159 else if (STRINGP (keytran_next
))
8163 for (i
= 0; i
< len
; i
++)
8164 XSETFASTINT (keybuf
[keytran_start
+ i
],
8165 XSTRING (keytran_next
)->data
[i
]);
8169 keytran_start
= keytran_end
= t
;
8170 keytran_map
= Vkey_translation_map
;
8172 /* Don't pass the results of key-translation-map
8173 through function-key-map. */
8174 fkey_start
= fkey_end
= t
;
8175 fkey_map
= Vfunction_key_map
;
8177 goto replay_sequence
;
8180 keytran_map
= get_keymap_1 (keytran_next
, 0, 1);
8182 /* If we no longer have a bound suffix, try a new positions for
8184 if (NILP (keytran_map
))
8186 keytran_end
= ++keytran_start
;
8187 keytran_map
= Vkey_translation_map
;
8188 key_translation_possible
= 0;
8193 /* If KEY is not defined in any of the keymaps,
8194 and cannot be part of a function key or translation,
8195 and is an upper case letter
8196 use the corresponding lower-case letter instead. */
8197 if (first_binding
== nmaps
&& ! function_key_possible
8198 && ! key_translation_possible
8200 && ((((XINT (key
) & 0x3ffff)
8201 < XCHAR_TABLE (current_buffer
->downcase_table
)->size
)
8202 && UPPERCASEP (XINT (key
) & 0x3ffff))
8203 || (XINT (key
) & shift_modifier
)))
8205 Lisp_Object new_key
;
8207 original_uppercase
= key
;
8208 original_uppercase_position
= t
- 1;
8210 if (XINT (key
) & shift_modifier
)
8211 XSETINT (new_key
, XINT (key
) & ~shift_modifier
);
8213 XSETINT (new_key
, (DOWNCASE (XINT (key
) & 0x3ffff)
8214 | (XINT (key
) & ~0x3ffff)));
8216 /* We have to do this unconditionally, regardless of whether
8217 the lower-case char is defined in the keymaps, because they
8218 might get translated through function-key-map. */
8219 keybuf
[t
- 1] = new_key
;
8222 fkey_map
= prev_fkey_map
;
8223 fkey_start
= prev_fkey_start
;
8224 fkey_end
= prev_fkey_end
;
8226 keytran_map
= prev_keytran_map
;
8227 keytran_start
= prev_keytran_start
;
8228 keytran_end
= prev_keytran_end
;
8230 goto replay_sequence
;
8232 /* If KEY is not defined in any of the keymaps,
8233 and cannot be part of a function key or translation,
8234 and is a shifted function key,
8235 use the corresponding unshifted function key instead. */
8236 if (first_binding
== nmaps
&& ! function_key_possible
8237 && ! key_translation_possible
8240 Lisp_Object breakdown
;
8243 breakdown
= parse_modifiers (key
);
8244 modifiers
= XINT (XCAR (XCDR (breakdown
)));
8245 if (modifiers
& shift_modifier
)
8247 Lisp_Object new_key
;
8249 original_uppercase
= key
;
8250 original_uppercase_position
= t
- 1;
8252 modifiers
&= ~shift_modifier
;
8253 new_key
= apply_modifiers (modifiers
,
8256 keybuf
[t
- 1] = new_key
;
8259 fkey_map
= prev_fkey_map
;
8260 fkey_start
= prev_fkey_start
;
8261 fkey_end
= prev_fkey_end
;
8263 keytran_map
= prev_keytran_map
;
8264 keytran_start
= prev_keytran_start
;
8265 keytran_end
= prev_keytran_end
;
8267 goto replay_sequence
;
8273 read_key_sequence_cmd
= (first_binding
< nmaps
8274 ? defs
[first_binding
]
8277 unread_switch_frame
= delayed_switch_frame
;
8278 unbind_to (count
, Qnil
);
8280 /* Don't downcase the last character if the caller says don't.
8281 Don't downcase it if the result is undefined, either. */
8282 if ((dont_downcase_last
|| first_binding
>= nmaps
)
8283 && t
- 1 == original_uppercase_position
)
8284 keybuf
[t
- 1] = original_uppercase
;
8286 /* Occasionally we fabricate events, perhaps by expanding something
8287 according to function-key-map, or by adding a prefix symbol to a
8288 mouse click in the scroll bar or modeline. In this cases, return
8289 the entire generated key sequence, even if we hit an unbound
8290 prefix or a definition before the end. This means that you will
8291 be able to push back the event properly, and also means that
8292 read-key-sequence will always return a logical unit.
8295 for (; t
< mock_input
; t
++)
8297 if (echo_keystrokes
)
8298 echo_char (keybuf
[t
]);
8299 add_command_key (keybuf
[t
]);
8307 #if 0 /* This doc string is too long for some compilers.
8308 This commented-out definition serves for DOC. */
8309 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
8310 "Read a sequence of keystrokes and return as a string or vector.\n\
8311 The sequence is sufficient to specify a non-prefix command in the\n\
8312 current local and global maps.\n\
8314 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
8315 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
8316 as a continuation of the previous key.\n\
8318 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not\n\
8319 convert the last event to lower case. (Normally any upper case event\n\
8320 is converted to lower case if the original event is undefined and the lower\n\
8321 case equivalent is defined.) A non-nil value is appropriate for reading\n\
8322 a key sequence to be defined.\n\
8324 A C-g typed while in this function is treated like any other character,\n\
8325 and `quit-flag' is not set.\n\
8327 If the key sequence starts with a mouse click, then the sequence is read\n\
8328 using the keymaps of the buffer of the window clicked in, not the buffer\n\
8329 of the selected window as normal.\n\
8331 `read-key-sequence' drops unbound button-down events, since you normally\n\
8332 only care about the click or drag events which follow them. If a drag\n\
8333 or multi-click event is unbound, but the corresponding click event would\n\
8334 be bound, `read-key-sequence' turns the event into a click event at the\n\
8335 drag's starting position. This means that you don't have to distinguish\n\
8336 between click and drag, double, or triple events unless you want to.\n\
8338 `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\
8339 lines separating windows, and scroll bars with imaginary keys\n\
8340 `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\
8342 Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this\n\
8343 function will process a switch-frame event if the user switches frames\n\
8344 before typing anything. If the user switches frames in the middle of a\n\
8345 key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME\n\
8346 is nil, then the event will be put off until after the current key sequence.\n\
8348 `read-key-sequence' checks `function-key-map' for function key\n\
8349 sequences, where they wouldn't conflict with ordinary bindings. See\n\
8350 `function-key-map' for more details.\n\
8352 The optional fifth argument COMMAND-LOOP, if non-nil, means\n\
8353 that this key sequence is being read by something that will\n\
8354 read commands one after another. It should be nil if the caller\n\
8355 will read just one key sequence.")
8356 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
, command
-loop
)
8359 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 5, 0,
8361 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
8363 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
8364 Lisp_Object can_return_switch_frame
, command_loop
;
8366 Lisp_Object keybuf
[30];
8368 struct gcpro gcpro1
;
8369 int count
= specpdl_ptr
- specpdl
;
8372 CHECK_STRING (prompt
, 0);
8375 specbind (Qinput_method_exit_on_first_char
,
8376 (NILP (command_loop
) ? Qt
: Qnil
));
8377 specbind (Qinput_method_use_echo_area
,
8378 (NILP (command_loop
) ? Qt
: Qnil
));
8380 bzero (keybuf
, sizeof keybuf
);
8382 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
8384 if (NILP (continue_echo
))
8386 this_command_key_count
= 0;
8387 this_single_command_key_start
= 0;
8390 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
8391 prompt
, ! NILP (dont_downcase_last
),
8392 ! NILP (can_return_switch_frame
), 0);
8400 return unbind_to (count
, make_event_array (i
, keybuf
));
8403 DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector
,
8404 Sread_key_sequence_vector
, 1, 5, 0,
8405 "Like `read-key-sequence' but always return a vector.")
8406 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
8408 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
8409 Lisp_Object can_return_switch_frame
, command_loop
;
8411 Lisp_Object keybuf
[30];
8413 struct gcpro gcpro1
;
8414 int count
= specpdl_ptr
- specpdl
;
8417 CHECK_STRING (prompt
, 0);
8420 specbind (Qinput_method_exit_on_first_char
,
8421 (NILP (command_loop
) ? Qt
: Qnil
));
8422 specbind (Qinput_method_use_echo_area
,
8423 (NILP (command_loop
) ? Qt
: Qnil
));
8425 bzero (keybuf
, sizeof keybuf
);
8427 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
8429 if (NILP (continue_echo
))
8431 this_command_key_count
= 0;
8432 this_single_command_key_start
= 0;
8435 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
8436 prompt
, ! NILP (dont_downcase_last
),
8437 ! NILP (can_return_switch_frame
), 0);
8445 return unbind_to (count
, Fvector (i
, keybuf
));
8448 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 4, 0,
8449 "Execute CMD as an editor command.\n\
8450 CMD must be a symbol that satisfies the `commandp' predicate.\n\
8451 Optional second arg RECORD-FLAG non-nil\n\
8452 means unconditionally put this command in `command-history'.\n\
8453 Otherwise, that is done only if an arg is read using the minibuffer.\n\
8454 The argument KEYS specifies the value to use instead of (this-command-keys)\n\
8455 when reading the arguments; if it is nil, (this-command-keys) is used.\n\
8456 The argument SPECIAL, if non-nil, means that this command is executing\n\
8457 a special event, so ignore the prefix argument and don't clear it.")
8458 (cmd
, record_flag
, keys
, special
)
8459 Lisp_Object cmd
, record_flag
, keys
, special
;
8461 register Lisp_Object final
;
8462 register Lisp_Object tem
;
8463 Lisp_Object prefixarg
;
8464 struct backtrace backtrace
;
8465 extern int debug_on_next_call
;
8467 debug_on_next_call
= 0;
8471 prefixarg
= current_kboard
->Vprefix_arg
;
8472 Vcurrent_prefix_arg
= prefixarg
;
8473 current_kboard
->Vprefix_arg
= Qnil
;
8480 tem
= Fget (cmd
, Qdisabled
);
8481 if (!NILP (tem
) && !NILP (Vrun_hooks
))
8483 tem
= Fsymbol_value (Qdisabled_command_hook
);
8485 return call1 (Vrun_hooks
, Qdisabled_command_hook
);
8491 final
= Findirect_function (cmd
);
8493 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
8495 struct gcpro gcpro1
, gcpro2
;
8497 GCPRO2 (cmd
, prefixarg
);
8498 do_autoload (final
, cmd
);
8505 if (STRINGP (final
) || VECTORP (final
))
8507 /* If requested, place the macro in the command history. For
8508 other sorts of commands, call-interactively takes care of
8510 if (!NILP (record_flag
))
8513 = Fcons (Fcons (Qexecute_kbd_macro
,
8514 Fcons (final
, Fcons (prefixarg
, Qnil
))),
8517 /* Don't keep command history around forever. */
8518 if (NUMBERP (Vhistory_length
) && XINT (Vhistory_length
) > 0)
8520 tem
= Fnthcdr (Vhistory_length
, Vcommand_history
);
8526 return Fexecute_kbd_macro (final
, prefixarg
);
8529 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
8531 backtrace
.next
= backtrace_list
;
8532 backtrace_list
= &backtrace
;
8533 backtrace
.function
= &Qcall_interactively
;
8534 backtrace
.args
= &cmd
;
8535 backtrace
.nargs
= 1;
8536 backtrace
.evalargs
= 0;
8538 tem
= Fcall_interactively (cmd
, record_flag
, keys
);
8540 backtrace_list
= backtrace
.next
;
8546 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
8548 "Read function name, then read its arguments and call it.")
8550 Lisp_Object prefixarg
;
8552 Lisp_Object function
;
8554 Lisp_Object saved_keys
;
8555 Lisp_Object bindings
, value
;
8556 struct gcpro gcpro1
, gcpro2
;
8558 saved_keys
= Fvector (this_command_key_count
,
8559 XVECTOR (this_command_keys
)->contents
);
8561 GCPRO2 (saved_keys
, prefixarg
);
8563 if (EQ (prefixarg
, Qminus
))
8565 else if (CONSP (prefixarg
) && XINT (XCAR (prefixarg
)) == 4)
8566 strcpy (buf
, "C-u ");
8567 else if (CONSP (prefixarg
) && INTEGERP (XCAR (prefixarg
)))
8569 if (sizeof (int) == sizeof (EMACS_INT
))
8570 sprintf (buf
, "%d ", XINT (XCAR (prefixarg
)));
8571 else if (sizeof (long) == sizeof (EMACS_INT
))
8572 sprintf (buf
, "%ld ", (long) XINT (XCAR (prefixarg
)));
8576 else if (INTEGERP (prefixarg
))
8578 if (sizeof (int) == sizeof (EMACS_INT
))
8579 sprintf (buf
, "%d ", XINT (prefixarg
));
8580 else if (sizeof (long) == sizeof (EMACS_INT
))
8581 sprintf (buf
, "%ld ", (long) XINT (prefixarg
));
8586 /* This isn't strictly correct if execute-extended-command
8587 is bound to anything else. Perhaps it should use
8588 this_command_keys? */
8589 strcat (buf
, "M-x ");
8591 /* Prompt with buf, and then read a string, completing from and
8592 restricting to the set of all defined commands. Don't provide
8593 any initial input. Save the command read on the extended-command
8595 function
= Fcompleting_read (build_string (buf
),
8596 Vobarray
, Qcommandp
,
8597 Qt
, Qnil
, Qextended_command_history
, Qnil
,
8600 if (STRINGP (function
) && XSTRING (function
)->size
== 0)
8601 error ("No command name given");
8603 /* Set this_command_keys to the concatenation of saved_keys and
8604 function, followed by a RET. */
8606 struct Lisp_String
*str
;
8610 this_command_key_count
= 0;
8611 this_single_command_key_start
= 0;
8613 keys
= XVECTOR (saved_keys
)->contents
;
8614 for (i
= 0; i
< XVECTOR (saved_keys
)->size
; i
++)
8615 add_command_key (keys
[i
]);
8617 str
= XSTRING (function
);
8618 for (i
= 0; i
< str
->size
; i
++)
8619 add_command_key (Faref (function
, make_number (i
)));
8621 add_command_key (make_number ('\015'));
8626 function
= Fintern (function
, Qnil
);
8627 current_kboard
->Vprefix_arg
= prefixarg
;
8628 Vthis_command
= function
;
8629 real_this_command
= function
;
8631 /* If enabled, show which key runs this command. */
8632 if (!NILP (Vsuggest_key_bindings
)
8633 && NILP (Vexecuting_macro
)
8634 && SYMBOLP (function
))
8635 bindings
= Fwhere_is_internal (function
, Voverriding_local_map
,
8641 GCPRO2 (bindings
, value
);
8642 value
= Fcommand_execute (function
, Qt
, Qnil
, Qnil
);
8644 /* If the command has a key binding, print it now. */
8645 if (!NILP (bindings
)
8646 && ! (VECTORP (bindings
) && EQ (Faref (bindings
, make_number (0)),
8649 /* But first wait, and skip the message if there is input. */
8651 if (!NILP (echo_area_buffer
[0]))
8652 /* This command displayed something in the echo area;
8653 so wait a few seconds, then display our suggestion message. */
8654 delay_time
= (NUMBERP (Vsuggest_key_bindings
)
8655 ? XINT (Vsuggest_key_bindings
) : 2);
8657 /* This command left the echo area empty,
8658 so display our message immediately. */
8661 if (!NILP (Fsit_for (make_number (delay_time
), Qnil
, Qnil
))
8662 && ! CONSP (Vunread_command_events
))
8664 Lisp_Object binding
;
8666 int message_p
= push_message ();
8668 binding
= Fkey_description (bindings
);
8671 = (char *) alloca (XSYMBOL (function
)->name
->size
8672 + STRING_BYTES (XSTRING (binding
))
8674 sprintf (newmessage
, "You can run the command `%s' with %s",
8675 XSYMBOL (function
)->name
->data
,
8676 XSTRING (binding
)->data
);
8677 message2_nolog (newmessage
,
8678 strlen (newmessage
),
8679 STRING_MULTIBYTE (binding
));
8680 if (!NILP (Fsit_for ((NUMBERP (Vsuggest_key_bindings
)
8681 ? Vsuggest_key_bindings
: make_number (2)),
8690 RETURN_UNGCPRO (value
);
8693 /* Find the set of keymaps now active.
8694 Store into *MAPS_P a vector holding the various maps
8695 and return the number of them. The vector was malloc'd
8696 and the caller should free it. */
8699 current_active_maps (maps_p
)
8700 Lisp_Object
**maps_p
;
8702 Lisp_Object
*tmaps
, *maps
;
8705 /* Should overriding-terminal-local-map and overriding-local-map apply? */
8706 if (!NILP (Voverriding_local_map_menu_flag
))
8708 /* Yes, use them (if non-nil) as well as the global map. */
8709 maps
= (Lisp_Object
*) xmalloc (3 * sizeof (maps
[0]));
8711 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
8712 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
8713 if (!NILP (Voverriding_local_map
))
8714 maps
[nmaps
++] = Voverriding_local_map
;
8718 /* No, so use major and minor mode keymaps. */
8719 nmaps
= current_minor_maps (NULL
, &tmaps
);
8720 maps
= (Lisp_Object
*) xmalloc ((nmaps
+ 2) * sizeof (maps
[0]));
8721 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
8722 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
8724 maps
[nmaps
++] = current_global_map
;
8730 /* Return nonzero if input events are pending. */
8733 detect_input_pending ()
8736 get_input_pending (&input_pending
, 0);
8738 return input_pending
;
8741 /* Return nonzero if input events are pending, and run any pending timers. */
8744 detect_input_pending_run_timers (do_display
)
8747 int old_timers_run
= timers_run
;
8750 get_input_pending (&input_pending
, 1);
8752 if (old_timers_run
!= timers_run
&& do_display
)
8754 redisplay_preserve_echo_area ();
8755 /* The following fixes a bug when using lazy-lock with
8756 lazy-lock-defer-on-the-fly set to t, i.e. when fontifying
8757 from an idle timer function. The symptom of the bug is that
8758 the cursor sometimes doesn't become visible until the next X
8759 event is processed. --gerd. */
8761 rif
->flush_display (NULL
);
8764 return input_pending
;
8767 /* This is called in some cases before a possible quit.
8768 It cases the next call to detect_input_pending to recompute input_pending.
8769 So calling this function unnecessarily can't do any harm. */
8772 clear_input_pending ()
8777 /* Return nonzero if there are pending requeued events.
8778 This isn't used yet. The hope is to make wait_reading_process_input
8779 call it, and return return if it runs Lisp code that unreads something.
8780 The problem is, kbd_buffer_get_event needs to be fixed to know what
8781 to do in that case. It isn't trivial. */
8784 requeued_events_pending_p ()
8786 return (!NILP (Vunread_command_events
) || unread_command_char
!= -1);
8790 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
8791 "T if command input is currently available with no waiting.\n\
8792 Actually, the value is nil only if we can be sure that no input is available.")
8795 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1)
8798 get_input_pending (&input_pending
, 1);
8799 return input_pending
> 0 ? Qt
: Qnil
;
8802 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
8803 "Return vector of last 100 events, not counting those from keyboard macros.")
8806 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
8809 if (total_keys
< NUM_RECENT_KEYS
)
8810 return Fvector (total_keys
, keys
);
8813 val
= Fvector (NUM_RECENT_KEYS
, keys
);
8814 bcopy (keys
+ recent_keys_index
,
8815 XVECTOR (val
)->contents
,
8816 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
8818 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
8819 recent_keys_index
* sizeof (Lisp_Object
));
8824 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
8825 "Return the key sequence that invoked this command.\n\
8826 The value is a string or a vector.")
8829 return make_event_array (this_command_key_count
,
8830 XVECTOR (this_command_keys
)->contents
);
8833 DEFUN ("this-command-keys-vector", Fthis_command_keys_vector
, Sthis_command_keys_vector
, 0, 0, 0,
8834 "Return the key sequence that invoked this command, as a vector.")
8837 return Fvector (this_command_key_count
,
8838 XVECTOR (this_command_keys
)->contents
);
8841 DEFUN ("this-single-command-keys", Fthis_single_command_keys
,
8842 Sthis_single_command_keys
, 0, 0, 0,
8843 "Return the key sequence that invoked this command.\n\
8844 Unlike `this-command-keys', this function's value\n\
8845 does not include prefix arguments.\n\
8846 The value is always a vector.")
8849 return Fvector (this_command_key_count
8850 - this_single_command_key_start
,
8851 (XVECTOR (this_command_keys
)->contents
8852 + this_single_command_key_start
));
8855 DEFUN ("this-single-command-raw-keys", Fthis_single_command_raw_keys
,
8856 Sthis_single_command_raw_keys
, 0, 0, 0,
8857 "Return the raw events that were read for this command.\n\
8858 Unlike `this-single-command-keys', this function's value\n\
8859 shows the events before all translations (except for input methods).\n\
8860 The value is always a vector.")
8863 return Fvector (raw_keybuf_count
,
8864 (XVECTOR (raw_keybuf
)->contents
));
8867 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths
,
8868 Sreset_this_command_lengths
, 0, 0, 0,
8869 "Used for complicated reasons in `universal-argument-other-key'.\n\
8871 `universal-argument-other-key' rereads the event just typed.\n\
8872 It then gets translated through `function-key-map'.\n\
8873 The translated event gets included in the echo area and in\n\
8874 the value of `this-command-keys' in addition to the raw original event.\n\
8875 That is not right.\n\
8877 Calling this function directs the translated event to replace\n\
8878 the original event, so that only one version of the event actually\n\
8879 appears in the echo area and in the value of `this-command-keys.'.")
8882 before_command_restore_flag
= 1;
8883 before_command_key_count_1
= before_command_key_count
;
8884 before_command_echo_length_1
= before_command_echo_length
;
8888 DEFUN ("clear-this-command-keys", Fclear_this_command_keys
,
8889 Sclear_this_command_keys
, 0, 0, 0,
8890 "Clear out the vector that `this-command-keys' returns.")
8893 this_command_key_count
= 0;
8897 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
8898 "Return the current depth in recursive edits.")
8902 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
8906 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
8907 "FOpen dribble file: ",
8908 "Start writing all keyboard characters to a dribble file called FILE.\n\
8909 If FILE is nil, close any open dribble file.")
8920 file
= Fexpand_file_name (file
, Qnil
);
8921 dribble
= fopen (XSTRING (file
)->data
, "w");
8923 report_file_error ("Opening dribble", Fcons (file
, Qnil
));
8928 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
8929 "Discard the contents of the terminal input buffer.\n\
8930 Also cancel any kbd macro being defined.")
8933 current_kboard
->defining_kbd_macro
= Qnil
;
8934 update_mode_lines
++;
8936 Vunread_command_events
= Qnil
;
8937 unread_command_char
= -1;
8939 discard_tty_input ();
8941 kbd_fetch_ptr
= kbd_store_ptr
;
8942 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
8948 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
8949 "Stop Emacs and return to superior process. You can resume later.\n\
8950 If `cannot-suspend' is non-nil, or if the system doesn't support job\n\
8951 control, run a subshell instead.\n\n\
8952 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
8953 to be read as terminal input by Emacs's parent, after suspension.\n\
8955 Before suspending, run the normal hook `suspend-hook'.\n\
8956 After resumption run the normal hook `suspend-resume-hook'.\n\
8958 Some operating systems cannot stop the Emacs process and resume it later.\n\
8959 On such systems, Emacs starts a subshell instead of suspending.")
8961 Lisp_Object stuffstring
;
8963 int count
= specpdl_ptr
- specpdl
;
8964 int old_height
, old_width
;
8966 struct gcpro gcpro1
;
8968 if (!NILP (stuffstring
))
8969 CHECK_STRING (stuffstring
, 0);
8971 /* Run the functions in suspend-hook. */
8972 if (!NILP (Vrun_hooks
))
8973 call1 (Vrun_hooks
, intern ("suspend-hook"));
8975 GCPRO1 (stuffstring
);
8976 get_frame_size (&old_width
, &old_height
);
8978 /* sys_suspend can get an error if it tries to fork a subshell
8979 and the system resources aren't available for that. */
8980 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object
))) init_sys_modes
,
8982 stuff_buffered_input (stuffstring
);
8987 unbind_to (count
, Qnil
);
8989 /* Check if terminal/window size has changed.
8990 Note that this is not useful when we are running directly
8991 with a window system; but suspend should be disabled in that case. */
8992 get_frame_size (&width
, &height
);
8993 if (width
!= old_width
|| height
!= old_height
)
8994 change_frame_size (SELECTED_FRAME (), height
, width
, 0, 0, 0);
8996 /* Run suspend-resume-hook. */
8997 if (!NILP (Vrun_hooks
))
8998 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
9004 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
9005 Then in any case stuff anything Emacs has read ahead and not used. */
9008 stuff_buffered_input (stuffstring
)
9009 Lisp_Object stuffstring
;
9011 /* stuff_char works only in BSD, versions 4.2 and up. */
9014 register unsigned char *p
;
9016 if (STRINGP (stuffstring
))
9020 p
= XSTRING (stuffstring
)->data
;
9021 count
= STRING_BYTES (XSTRING (stuffstring
));
9026 /* Anything we have read ahead, put back for the shell to read. */
9027 /* ?? What should this do when we have multiple keyboards??
9028 Should we ignore anything that was typed in at the "wrong" kboard? */
9029 for (; kbd_fetch_ptr
!= kbd_store_ptr
; kbd_fetch_ptr
++)
9031 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
9032 kbd_fetch_ptr
= kbd_buffer
;
9033 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
9034 stuff_char (kbd_fetch_ptr
->code
);
9035 kbd_fetch_ptr
->kind
= no_event
;
9036 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_fetch_ptr
9042 #endif /* BSD_SYSTEM and not BSD4_1 */
9046 set_waiting_for_input (time_to_clear
)
9047 EMACS_TIME
*time_to_clear
;
9049 input_available_clear_time
= time_to_clear
;
9051 /* Tell interrupt_signal to throw back to read_char, */
9052 waiting_for_input
= 1;
9054 /* If interrupt_signal was called before and buffered a C-g,
9055 make it run again now, to avoid timing error. */
9056 if (!NILP (Vquit_flag
))
9057 quit_throw_to_read_char ();
9061 clear_waiting_for_input ()
9063 /* Tell interrupt_signal not to throw back to read_char, */
9064 waiting_for_input
= 0;
9065 input_available_clear_time
= 0;
9068 /* This routine is called at interrupt level in response to C-G.
9069 If interrupt_input, this is the handler for SIGINT.
9070 Otherwise, it is called from kbd_buffer_store_event,
9071 in handling SIGIO or SIGTINT.
9073 If `waiting_for_input' is non zero, then unless `echoing' is nonzero,
9074 immediately throw back to read_char.
9076 Otherwise it sets the Lisp variable quit-flag not-nil.
9077 This causes eval to throw, when it gets a chance.
9078 If quit-flag is already non-nil, it stops the job right away. */
9081 interrupt_signal (signalnum
) /* If we don't have an argument, */
9082 int signalnum
; /* some compilers complain in signal calls. */
9085 /* Must preserve main program's value of errno. */
9086 int old_errno
= errno
;
9087 struct frame
*sf
= SELECTED_FRAME ();
9089 #if defined (USG) && !defined (POSIX_SIGNALS)
9090 if (!read_socket_hook
&& NILP (Vwindow_system
))
9092 /* USG systems forget handlers when they are used;
9093 must reestablish each time */
9094 signal (SIGINT
, interrupt_signal
);
9095 signal (SIGQUIT
, interrupt_signal
);
9101 if (!NILP (Vquit_flag
)
9102 && (FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
)))
9104 /* If SIGINT isn't blocked, don't let us be interrupted by
9105 another SIGINT, it might be harmful due to non-reentrancy
9106 in I/O functions. */
9107 sigblock (sigmask (SIGINT
));
9112 #ifdef SIGTSTP /* Support possible in later USG versions */
9114 * On systems which can suspend the current process and return to the original
9115 * shell, this command causes the user to end up back at the shell.
9116 * The "Auto-save" and "Abort" questions are not asked until
9117 * the user elects to return to emacs, at which point he can save the current
9118 * job and either dump core or continue.
9123 if (sys_suspend () == -1)
9125 printf ("Not running as a subprocess;\n");
9126 printf ("you can continue or abort.\n");
9129 /* Perhaps should really fork an inferior shell?
9130 But that would not provide any way to get back
9131 to the original shell, ever. */
9132 printf ("No support for stopping a process on this operating system;\n");
9133 printf ("you can continue or abort.\n");
9134 #endif /* not VMS */
9135 #endif /* not SIGTSTP */
9137 /* We must remain inside the screen area when the internal terminal
9138 is used. Note that [Enter] is not echoed by dos. */
9141 /* It doesn't work to autosave while GC is in progress;
9142 the code used for auto-saving doesn't cope with the mark bit. */
9143 if (!gc_in_progress
)
9145 printf ("Auto-save? (y or n) ");
9147 if (((c
= getchar ()) & ~040) == 'Y')
9149 Fdo_auto_save (Qt
, Qnil
);
9151 printf ("\r\nAuto-save done");
9152 #else /* not MSDOS */
9153 printf ("Auto-save done\n");
9154 #endif /* not MSDOS */
9156 while (c
!= '\n') c
= getchar ();
9160 /* During GC, it must be safe to reenable quitting again. */
9161 Vinhibit_quit
= Qnil
;
9164 #endif /* not MSDOS */
9165 printf ("Garbage collection in progress; cannot auto-save now\r\n");
9166 printf ("but will instead do a real quit after garbage collection ends\r\n");
9171 printf ("\r\nAbort? (y or n) ");
9172 #else /* not MSDOS */
9174 printf ("Abort (and enter debugger)? (y or n) ");
9176 printf ("Abort (and dump core)? (y or n) ");
9177 #endif /* not VMS */
9178 #endif /* not MSDOS */
9180 if (((c
= getchar ()) & ~040) == 'Y')
9182 while (c
!= '\n') c
= getchar ();
9184 printf ("\r\nContinuing...\r\n");
9185 #else /* not MSDOS */
9186 printf ("Continuing...\n");
9187 #endif /* not MSDOS */
9194 /* If executing a function that wants to be interrupted out of
9195 and the user has not deferred quitting by binding `inhibit-quit'
9196 then quit right away. */
9197 if (immediate_quit
&& NILP (Vinhibit_quit
))
9199 struct gl_state_s saved
;
9200 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9205 GCPRO4 (saved
.object
, saved
.global_code
,
9206 saved
.current_syntax_table
, saved
.old_prop
);
9207 Fsignal (Qquit
, Qnil
);
9212 /* Else request quit when it's safe */
9216 if (waiting_for_input
&& !echoing
)
9217 quit_throw_to_read_char ();
9222 /* Handle a C-g by making read_char return C-g. */
9225 quit_throw_to_read_char ()
9228 /* Prevent another signal from doing this before we finish. */
9229 clear_waiting_for_input ();
9232 Vunread_command_events
= Qnil
;
9233 unread_command_char
= -1;
9235 #if 0 /* Currently, sit_for is called from read_char without turning
9236 off polling. And that can call set_waiting_for_input.
9237 It seems to be harmless. */
9238 #ifdef POLL_FOR_INPUT
9239 /* May be > 1 if in recursive minibuffer. */
9240 if (poll_suppress_count
== 0)
9244 if (FRAMEP (internal_last_event_frame
)
9245 && !EQ (internal_last_event_frame
, selected_frame
))
9246 do_switch_frame (make_lispy_switch_frame (internal_last_event_frame
),
9249 _longjmp (getcjmp
, 1);
9252 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
9253 "Set mode of reading keyboard input.\n\
9254 First arg INTERRUPT non-nil means use input interrupts;\n\
9255 nil means use CBREAK mode.\n\
9256 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
9257 (no effect except in CBREAK mode).\n\
9258 Third arg META t means accept 8-bit input (for a Meta key).\n\
9259 META nil means ignore the top bit, on the assumption it is parity.\n\
9260 Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\
9261 Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\
9262 See also `current-input-mode'.")
9263 (interrupt
, flow
, meta
, quit
)
9264 Lisp_Object interrupt
, flow
, meta
, quit
;
9267 && (!INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400))
9268 error ("set-input-mode: QUIT must be an ASCII character");
9270 #ifdef POLL_FOR_INPUT
9275 /* this causes startup screen to be restored and messes with the mouse */
9280 /* Note SIGIO has been undef'd if FIONREAD is missing. */
9281 if (read_socket_hook
)
9283 /* When using X, don't give the user a real choice,
9284 because we haven't implemented the mechanisms to support it. */
9285 #ifdef NO_SOCK_SIGIO
9286 interrupt_input
= 0;
9287 #else /* not NO_SOCK_SIGIO */
9288 interrupt_input
= 1;
9289 #endif /* NO_SOCK_SIGIO */
9292 interrupt_input
= !NILP (interrupt
);
9293 #else /* not SIGIO */
9294 interrupt_input
= 0;
9295 #endif /* not SIGIO */
9297 /* Our VMS input only works by interrupts, as of now. */
9299 interrupt_input
= 1;
9302 flow_control
= !NILP (flow
);
9305 else if (EQ (meta
, Qt
))
9310 /* Don't let this value be out of range. */
9311 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
9317 #ifdef POLL_FOR_INPUT
9318 poll_suppress_count
= 1;
9324 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
9325 "Return information about the way Emacs currently reads keyboard input.\n\
9326 The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
9327 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\
9328 nil, Emacs is using CBREAK mode.\n\
9329 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\
9330 terminal; this does not apply if Emacs uses interrupt-driven input.\n\
9331 META is t if accepting 8-bit input with 8th bit as Meta flag.\n\
9332 META nil means ignoring the top bit, on the assumption it is parity.\n\
9333 META is neither t nor nil if accepting 8-bit input and using\n\
9334 all 8 bits as the character code.\n\
9335 QUIT is the character Emacs currently uses to quit.\n\
9336 The elements of this list correspond to the arguments of\n\
9342 val
[0] = interrupt_input
? Qt
: Qnil
;
9343 val
[1] = flow_control
? Qt
: Qnil
;
9344 val
[2] = meta_key
== 2 ? make_number (0) : meta_key
== 1 ? Qt
: Qnil
;
9345 XSETFASTINT (val
[3], quit_char
);
9347 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
9352 * Set up a new kboard object with reasonable initial values.
9358 kb
->Voverriding_terminal_local_map
= Qnil
;
9359 kb
->Vlast_command
= Qnil
;
9360 kb
->Vreal_last_command
= Qnil
;
9361 kb
->Vprefix_arg
= Qnil
;
9362 kb
->Vlast_prefix_arg
= Qnil
;
9363 kb
->kbd_queue
= Qnil
;
9364 kb
->kbd_queue_has_data
= 0;
9365 kb
->immediate_echo
= 0;
9366 kb
->echoptr
= kb
->echobuf
;
9367 kb
->echo_after_prompt
= -1;
9368 kb
->kbd_macro_buffer
= 0;
9369 kb
->kbd_macro_bufsize
= 0;
9370 kb
->defining_kbd_macro
= Qnil
;
9371 kb
->Vlast_kbd_macro
= Qnil
;
9372 kb
->reference_count
= 0;
9373 kb
->Vsystem_key_alist
= Qnil
;
9374 kb
->system_key_syms
= Qnil
;
9375 kb
->Vdefault_minibuffer_frame
= Qnil
;
9379 * Destroy the contents of a kboard object, but not the object itself.
9380 * We use this just before deleting it, or if we're going to initialize
9387 if (kb
->kbd_macro_buffer
)
9388 xfree (kb
->kbd_macro_buffer
);
9397 for (kbp
= &all_kboards
; *kbp
!= kb
; kbp
= &(*kbp
)->next_kboard
)
9400 *kbp
= kb
->next_kboard
;
9409 /* This is correct before outermost invocation of the editor loop */
9410 command_loop_level
= -1;
9412 quit_char
= Ctl ('g');
9413 Vunread_command_events
= Qnil
;
9414 unread_command_char
= -1;
9415 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
9417 recent_keys_index
= 0;
9418 kbd_fetch_ptr
= kbd_buffer
;
9419 kbd_store_ptr
= kbd_buffer
;
9420 kbd_buffer_frame_or_window
9421 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
9423 do_mouse_tracking
= Qnil
;
9427 /* This means that command_loop_1 won't try to select anything the first
9429 internal_last_event_frame
= Qnil
;
9430 Vlast_event_frame
= internal_last_event_frame
;
9433 current_kboard
= initial_kboard
;
9435 wipe_kboard (current_kboard
);
9436 init_kboard (current_kboard
);
9439 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
9441 kbd_buffer_frame_or_window
9442 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
9443 if (!noninteractive
&& !read_socket_hook
&& NILP (Vwindow_system
))
9445 signal (SIGINT
, interrupt_signal
);
9446 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
9447 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
9448 SIGQUIT and we can't tell which one it will give us. */
9449 signal (SIGQUIT
, interrupt_signal
);
9450 #endif /* HAVE_TERMIO */
9452 /* Note SIGIO has been undef'd if FIONREAD is missing. */
9454 if (!noninteractive
)
9455 signal (SIGIO
, input_available_signal
);
9458 /* Use interrupt input by default, if it works and noninterrupt input
9459 has deficiencies. */
9461 #ifdef INTERRUPT_INPUT
9462 interrupt_input
= 1;
9464 interrupt_input
= 0;
9467 /* Our VMS input only works by interrupts, as of now. */
9469 interrupt_input
= 1;
9475 if (keyboard_init_hook
)
9476 (*keyboard_init_hook
) ();
9478 #ifdef POLL_FOR_INPUT
9479 poll_suppress_count
= 1;
9484 /* This type's only use is in syms_of_keyboard, to initialize the
9485 event header symbols and put properties on them. */
9492 struct event_head head_table
[] = {
9493 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
9494 &Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
,
9495 &Qswitch_frame
, "switch-frame", &Qswitch_frame
,
9496 &Qdelete_frame
, "delete-frame", &Qdelete_frame
,
9497 &Qiconify_frame
, "iconify-frame", &Qiconify_frame
,
9498 &Qmake_frame_visible
, "make-frame-visible", &Qmake_frame_visible
,
9505 QCimage
= intern (":image");
9506 staticpro (&QCimage
);
9508 staticpro (&Qhelp_echo
);
9509 Qhelp_echo
= intern ("help-echo");
9511 staticpro (&item_properties
);
9512 item_properties
= Qnil
;
9514 staticpro (&tool_bar_item_properties
);
9515 tool_bar_item_properties
= Qnil
;
9516 staticpro (&tool_bar_items_vector
);
9517 tool_bar_items_vector
= Qnil
;
9519 staticpro (&real_this_command
);
9520 real_this_command
= Qnil
;
9522 Qtimer_event_handler
= intern ("timer-event-handler");
9523 staticpro (&Qtimer_event_handler
);
9525 Qdisabled_command_hook
= intern ("disabled-command-hook");
9526 staticpro (&Qdisabled_command_hook
);
9528 Qself_insert_command
= intern ("self-insert-command");
9529 staticpro (&Qself_insert_command
);
9531 Qforward_char
= intern ("forward-char");
9532 staticpro (&Qforward_char
);
9534 Qbackward_char
= intern ("backward-char");
9535 staticpro (&Qbackward_char
);
9537 Qdisabled
= intern ("disabled");
9538 staticpro (&Qdisabled
);
9540 Qundefined
= intern ("undefined");
9541 staticpro (&Qundefined
);
9543 Qpre_command_hook
= intern ("pre-command-hook");
9544 staticpro (&Qpre_command_hook
);
9546 Qpost_command_hook
= intern ("post-command-hook");
9547 staticpro (&Qpost_command_hook
);
9549 Qpost_command_idle_hook
= intern ("post-command-idle-hook");
9550 staticpro (&Qpost_command_idle_hook
);
9552 Qdeferred_action_function
= intern ("deferred-action-function");
9553 staticpro (&Qdeferred_action_function
);
9555 Qcommand_hook_internal
= intern ("command-hook-internal");
9556 staticpro (&Qcommand_hook_internal
);
9558 Qfunction_key
= intern ("function-key");
9559 staticpro (&Qfunction_key
);
9560 Qmouse_click
= intern ("mouse-click");
9561 staticpro (&Qmouse_click
);
9563 Qmouse_wheel
= intern ("mouse-wheel");
9564 staticpro (&Qmouse_wheel
);
9565 Qlanguage_change
= intern ("language-change");
9566 staticpro (&Qlanguage_change
);
9568 Qdrag_n_drop
= intern ("drag-n-drop");
9569 staticpro (&Qdrag_n_drop
);
9571 Qusr1_signal
= intern ("usr1-signal");
9572 staticpro (&Qusr1_signal
);
9573 Qusr2_signal
= intern ("usr2-signal");
9574 staticpro (&Qusr2_signal
);
9576 Qmenu_enable
= intern ("menu-enable");
9577 staticpro (&Qmenu_enable
);
9578 Qmenu_alias
= intern ("menu-alias");
9579 staticpro (&Qmenu_alias
);
9580 QCenable
= intern (":enable");
9581 staticpro (&QCenable
);
9582 QCvisible
= intern (":visible");
9583 staticpro (&QCvisible
);
9584 QChelp
= intern (":help");
9585 staticpro (&QChelp
);
9586 QCfilter
= intern (":filter");
9587 staticpro (&QCfilter
);
9588 QCbutton
= intern (":button");
9589 staticpro (&QCbutton
);
9590 QCkeys
= intern (":keys");
9591 staticpro (&QCkeys
);
9592 QCkey_sequence
= intern (":key-sequence");
9593 staticpro (&QCkey_sequence
);
9594 QCtoggle
= intern (":toggle");
9595 staticpro (&QCtoggle
);
9596 QCradio
= intern (":radio");
9597 staticpro (&QCradio
);
9599 Qmode_line
= intern ("mode-line");
9600 staticpro (&Qmode_line
);
9601 Qvertical_line
= intern ("vertical-line");
9602 staticpro (&Qvertical_line
);
9603 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
9604 staticpro (&Qvertical_scroll_bar
);
9605 Qmenu_bar
= intern ("menu-bar");
9606 staticpro (&Qmenu_bar
);
9608 Qabove_handle
= intern ("above-handle");
9609 staticpro (&Qabove_handle
);
9610 Qhandle
= intern ("handle");
9611 staticpro (&Qhandle
);
9612 Qbelow_handle
= intern ("below-handle");
9613 staticpro (&Qbelow_handle
);
9614 Qup
= intern ("up");
9616 Qdown
= intern ("down");
9618 Qtop
= intern ("top");
9620 Qbottom
= intern ("bottom");
9621 staticpro (&Qbottom
);
9622 Qend_scroll
= intern ("end-scroll");
9623 staticpro (&Qend_scroll
);
9624 Qratio
= intern ("ratio");
9625 staticpro (&Qratio
);
9627 Qevent_kind
= intern ("event-kind");
9628 staticpro (&Qevent_kind
);
9629 Qevent_symbol_elements
= intern ("event-symbol-elements");
9630 staticpro (&Qevent_symbol_elements
);
9631 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
9632 staticpro (&Qevent_symbol_element_mask
);
9633 Qmodifier_cache
= intern ("modifier-cache");
9634 staticpro (&Qmodifier_cache
);
9636 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
9637 staticpro (&Qrecompute_lucid_menubar
);
9638 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
9639 staticpro (&Qactivate_menubar_hook
);
9641 Qpolling_period
= intern ("polling-period");
9642 staticpro (&Qpolling_period
);
9644 Qinput_method_function
= intern ("input-method-function");
9645 staticpro (&Qinput_method_function
);
9647 Qinput_method_exit_on_first_char
= intern ("input-method-exit-on-first-char");
9648 staticpro (&Qinput_method_exit_on_first_char
);
9649 Qinput_method_use_echo_area
= intern ("input-method-use-echo-area");
9650 staticpro (&Qinput_method_use_echo_area
);
9652 Fset (Qinput_method_exit_on_first_char
, Qnil
);
9653 Fset (Qinput_method_use_echo_area
, Qnil
);
9656 struct event_head
*p
;
9658 for (p
= head_table
;
9659 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
9662 *p
->var
= intern (p
->name
);
9664 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
9665 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
9669 button_down_location
= Fmake_vector (make_number (NUM_MOUSE_BUTTONS
), Qnil
);
9670 staticpro (&button_down_location
);
9674 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
9676 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
9677 for (i
= 0; i
< len
; i
++)
9678 if (modifier_names
[i
])
9679 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
9680 staticpro (&modifier_symbols
);
9683 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
9684 staticpro (&recent_keys
);
9686 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
9687 staticpro (&this_command_keys
);
9689 raw_keybuf
= Fmake_vector (make_number (30), Qnil
);
9690 staticpro (&raw_keybuf
);
9692 Qextended_command_history
= intern ("extended-command-history");
9693 Fset (Qextended_command_history
, Qnil
);
9694 staticpro (&Qextended_command_history
);
9696 kbd_buffer_frame_or_window
9697 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
9698 staticpro (&kbd_buffer_frame_or_window
);
9700 accent_key_syms
= Qnil
;
9701 staticpro (&accent_key_syms
);
9703 func_key_syms
= Qnil
;
9704 staticpro (&func_key_syms
);
9707 staticpro (&mouse_syms
);
9710 mouse_wheel_syms
= Qnil
;
9711 staticpro (&mouse_wheel_syms
);
9713 drag_n_drop_syms
= Qnil
;
9714 staticpro (&drag_n_drop_syms
);
9717 unread_switch_frame
= Qnil
;
9718 staticpro (&unread_switch_frame
);
9720 internal_last_event_frame
= Qnil
;
9721 staticpro (&internal_last_event_frame
);
9723 read_key_sequence_cmd
= Qnil
;
9724 staticpro (&read_key_sequence_cmd
);
9726 menu_bar_one_keymap_changed_items
= Qnil
;
9727 staticpro (&menu_bar_one_keymap_changed_items
);
9729 defsubr (&Sevent_convert_list
);
9730 defsubr (&Sread_key_sequence
);
9731 defsubr (&Sread_key_sequence_vector
);
9732 defsubr (&Srecursive_edit
);
9734 defsubr (&Strack_mouse
);
9736 defsubr (&Sinput_pending_p
);
9737 defsubr (&Scommand_execute
);
9738 defsubr (&Srecent_keys
);
9739 defsubr (&Sthis_command_keys
);
9740 defsubr (&Sthis_command_keys_vector
);
9741 defsubr (&Sthis_single_command_keys
);
9742 defsubr (&Sthis_single_command_raw_keys
);
9743 defsubr (&Sreset_this_command_lengths
);
9744 defsubr (&Sclear_this_command_keys
);
9745 defsubr (&Ssuspend_emacs
);
9746 defsubr (&Sabort_recursive_edit
);
9747 defsubr (&Sexit_recursive_edit
);
9748 defsubr (&Srecursion_depth
);
9749 defsubr (&Stop_level
);
9750 defsubr (&Sdiscard_input
);
9751 defsubr (&Sopen_dribble_file
);
9752 defsubr (&Sset_input_mode
);
9753 defsubr (&Scurrent_input_mode
);
9754 defsubr (&Sexecute_extended_command
);
9756 DEFVAR_LISP ("last-command-char", &last_command_char
,
9757 "Last input event that was part of a command.");
9759 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char
,
9760 "Last input event that was part of a command.");
9762 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
9763 "Last input event in a command, except for mouse menu events.\n\
9764 Mouse menus give back keys that don't look like mouse events;\n\
9765 this variable holds the actual mouse event that led to the menu,\n\
9766 so that you can determine whether the command was run by mouse or not.");
9768 DEFVAR_LISP ("last-input-char", &last_input_char
,
9769 "Last input event.");
9771 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char
,
9772 "Last input event.");
9774 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
9775 "List of events to be read as the command input.\n\
9776 These events are processed first, before actual keyboard input.");
9777 Vunread_command_events
= Qnil
;
9779 DEFVAR_INT ("unread-command-char", &unread_command_char
,
9780 "If not -1, an object to be read as next command input event.");
9782 DEFVAR_LISP ("unread-post-input-method-events", &Vunread_post_input_method_events
,
9783 "List of events to be processed as input by input methods.\n\
9784 These events are processed after `unread-command-events', but\n\
9785 before actual keyboard input.");
9786 Vunread_post_input_method_events
= Qnil
;
9788 DEFVAR_LISP ("unread-input-method-events", &Vunread_input_method_events
,
9789 "List of events to be processed as input by input methods.\n\
9790 These events are processed after `unread-command-events', but\n\
9791 before actual keyboard input.");
9792 Vunread_input_method_events
= Qnil
;
9794 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
9795 "Meta-prefix character code.\n\
9796 Meta-foo as command input turns into this character followed by foo.");
9797 XSETINT (meta_prefix_char
, 033);
9799 DEFVAR_KBOARD ("last-command", Vlast_command
,
9800 "The last command executed.\n\
9801 Normally a symbol with a function definition, but can be whatever was found\n\
9802 in the keymap, or whatever the variable `this-command' was set to by that\n\
9805 The value `mode-exit' is special; it means that the previous command\n\
9806 read an event that told it to exit, and it did so and unread that event.\n\
9807 In other words, the present command is the event that made the previous\n\
9810 The value `kill-region' is special; it means that the previous command\n\
9811 was a kill command.");
9813 DEFVAR_KBOARD ("real-last-command", Vreal_last_command
,
9814 "Same as `last-command', but never altered by Lisp code.");
9816 DEFVAR_LISP ("this-command", &Vthis_command
,
9817 "The command now being executed.\n\
9818 The command can set this variable; whatever is put here\n\
9819 will be in `last-command' during the following command.");
9820 Vthis_command
= Qnil
;
9822 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
9823 "*Number of input events between auto-saves.\n\
9824 Zero means disable autosaving due to number of characters typed.");
9825 auto_save_interval
= 300;
9827 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
9828 "*Number of seconds idle time before auto-save.\n\
9829 Zero or nil means disable auto-saving due to idleness.\n\
9830 After auto-saving due to this many seconds of idle time,\n\
9831 Emacs also does a garbage collection if that seems to be warranted.");
9832 XSETFASTINT (Vauto_save_timeout
, 30);
9834 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes
,
9835 "*Nonzero means echo unfinished commands after this many seconds of pause.");
9836 echo_keystrokes
= 1;
9838 DEFVAR_INT ("polling-period", &polling_period
,
9839 "*Interval between polling for input during Lisp execution.\n\
9840 The reason for polling is to make C-g work to stop a running program.\n\
9841 Polling is needed only when using X windows and SIGIO does not work.\n\
9842 Polling is automatically disabled in all other cases.");
9845 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
9846 "*Maximum time between mouse clicks to make a double-click.\n\
9847 Measured in milliseconds. nil means disable double-click recognition;\n\
9848 t means double-clicks have no time limit and are detected\n\
9849 by position only.");
9850 Vdouble_click_time
= make_number (500);
9852 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
9853 "*Non-nil means inhibit local map menu bar menus.");
9854 inhibit_local_menu_bar_menus
= 0;
9856 DEFVAR_INT ("num-input-keys", &num_input_keys
,
9857 "Number of complete key sequences read as input so far.\n\
9858 This includes key sequences read from keyboard macros.\n\
9859 The number is effectively the number of interactive command invocations.");
9862 DEFVAR_INT ("num-nonmacro-input-events", &num_nonmacro_input_events
,
9863 "Number of input events read from the keyboard so far.\n\
9864 This does not include events generated by keyboard macros.");
9865 num_nonmacro_input_events
= 0;
9867 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
9868 "The frame in which the most recently read event occurred.\n\
9869 If the last event came from a keyboard macro, this is set to `macro'.");
9870 Vlast_event_frame
= Qnil
;
9872 /* This variable is set up in sysdep.c. */
9873 DEFVAR_LISP ("tty-erase-char", &Vtty_erase_char
,
9874 "The ERASE character as set by the user with stty.");
9876 DEFVAR_LISP ("help-char", &Vhelp_char
,
9877 "Character to recognize as meaning Help.\n\
9878 When it is read, do `(eval help-form)', and display result if it's a string.\n\
9879 If the value of `help-form' is nil, this char can be read normally.");
9880 XSETINT (Vhelp_char
, Ctl ('H'));
9882 DEFVAR_LISP ("help-event-list", &Vhelp_event_list
,
9883 "List of input events to recognize as meaning Help.\n\
9884 These work just like the value of `help-char' (see that).");
9885 Vhelp_event_list
= Qnil
;
9887 DEFVAR_LISP ("help-form", &Vhelp_form
,
9888 "Form to execute when character `help-char' is read.\n\
9889 If the form returns a string, that string is displayed.\n\
9890 If `help-form' is nil, the help char is not recognized.");
9893 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
9894 "Command to run when `help-char' character follows a prefix key.\n\
9895 This command is used only when there is no actual binding\n\
9896 for that character after that prefix key.");
9897 Vprefix_help_command
= Qnil
;
9899 DEFVAR_LISP ("top-level", &Vtop_level
,
9900 "Form to evaluate when Emacs starts up.\n\
9901 Useful to set before you dump a modified Emacs.");
9904 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
9905 "Translate table for keyboard input, or nil.\n\
9906 Each character is looked up in this string and the contents used instead.\n\
9907 The value may be a string, a vector, or a char-table.\n\
9908 If it is a string or vector of length N,\n\
9909 character codes N and up are untranslated.\n\
9910 In a vector or a char-table, an element which is nil means \"no translation\".");
9911 Vkeyboard_translate_table
= Qnil
;
9913 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
9914 "Non-nil means to always spawn a subshell instead of suspending.\n\
9915 \(Even if the operating system has support for stopping a process.\)");
9918 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
9919 "Non-nil means prompt with menus when appropriate.\n\
9920 This is done when reading from a keymap that has a prompt string,\n\
9921 for elements that have prompt strings.\n\
9922 The menu is displayed on the screen\n\
9923 if X menus were enabled at configuration\n\
9924 time and the previous event was a mouse click prefix key.\n\
9925 Otherwise, menu prompting uses the echo area.");
9928 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
9929 "Character to see next line of menu prompt.\n\
9930 Type this character while in a menu prompt to rotate around the lines of it.");
9931 XSETINT (menu_prompt_more_char
, ' ');
9933 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
9934 "A mask of additional modifier keys to use with every keyboard character.\n\
9935 Emacs applies the modifiers of the character stored here to each keyboard\n\
9936 character it reads. For example, after evaluating the expression\n\
9937 (setq extra-keyboard-modifiers ?\\C-x)\n\
9938 all input characters will have the control modifier applied to them.\n\
9940 Note that the character ?\\C-@, equivalent to the integer zero, does\n\
9941 not count as a control character; rather, it counts as a character\n\
9942 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\
9943 cancels any modification.");
9944 extra_keyboard_modifiers
= 0;
9946 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
9947 "If an editing command sets this to t, deactivate the mark afterward.\n\
9948 The command loop sets this to nil before each command,\n\
9949 and tests the value when the command returns.\n\
9950 Buffer modification stores t in this variable.");
9951 Vdeactivate_mark
= Qnil
;
9953 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
9954 "Temporary storage of pre-command-hook or post-command-hook.");
9955 Vcommand_hook_internal
= Qnil
;
9957 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
9958 "Normal hook run before each command is executed.\n\
9959 If an unhandled error happens in running this hook,\n\
9960 the hook value is set to nil, since otherwise the error\n\
9961 might happen repeatedly and make Emacs nonfunctional.");
9962 Vpre_command_hook
= Qnil
;
9964 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
9965 "Normal hook run after each command is executed.\n\
9966 If an unhandled error happens in running this hook,\n\
9967 the hook value is set to nil, since otherwise the error\n\
9968 might happen repeatedly and make Emacs nonfunctional.");
9969 Vpost_command_hook
= Qnil
;
9971 DEFVAR_LISP ("post-command-idle-hook", &Vpost_command_idle_hook
,
9972 "Normal hook run after each command is executed, if idle.\n\
9973 Errors running the hook are caught and ignored.\n\
9974 This feature is obsolete; use idle timers instead. See `etc/NEWS'.");
9975 Vpost_command_idle_hook
= Qnil
;
9977 DEFVAR_INT ("post-command-idle-delay", &post_command_idle_delay
,
9978 "Delay time before running `post-command-idle-hook'.\n\
9979 This is measured in microseconds.");
9980 post_command_idle_delay
= 100000;
9983 DEFVAR_LISP ("echo-area-clear-hook", ...,
9984 "Normal hook run when clearing the echo area.");
9986 Qecho_area_clear_hook
= intern ("echo-area-clear-hook");
9987 XSYMBOL (Qecho_area_clear_hook
)->value
= Qnil
;
9989 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
9990 "t means menu bar, specified Lucid style, needs to be recomputed.");
9991 Vlucid_menu_bar_dirty_flag
= Qnil
;
9993 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
9994 "List of menu bar items to move to the end of the menu bar.\n\
9995 The elements of the list are event types that may have menu bar bindings.");
9996 Vmenu_bar_final_items
= Qnil
;
9998 DEFVAR_KBOARD ("overriding-terminal-local-map",
9999 Voverriding_terminal_local_map
,
10000 "Per-terminal keymap that overrides all other local keymaps.\n\
10001 If this variable is non-nil, it is used as a keymap instead of the\n\
10002 buffer's local map, and the minor mode keymaps and text property keymaps.\n\
10003 This variable is intended to let commands such as `universal-argumemnt'\n\
10004 set up a different keymap for reading the next command.");
10006 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
10007 "Keymap that overrides all other local keymaps.\n\
10008 If this variable is non-nil, it is used as a keymap instead of the\n\
10009 buffer's local map, and the minor mode keymaps and text property keymaps.");
10010 Voverriding_local_map
= Qnil
;
10012 DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag
,
10013 "Non-nil means `overriding-local-map' applies to the menu bar.\n\
10014 Otherwise, the menu bar continues to reflect the buffer's local map\n\
10015 and the minor mode maps regardless of `overriding-local-map'.");
10016 Voverriding_local_map_menu_flag
= Qnil
;
10018 DEFVAR_LISP ("special-event-map", &Vspecial_event_map
,
10019 "Keymap defining bindings for special events to execute at low level.");
10020 Vspecial_event_map
= Fcons (intern ("keymap"), Qnil
);
10022 DEFVAR_LISP ("track-mouse", &do_mouse_tracking
,
10023 "*Non-nil means generate motion events for mouse motion.");
10025 DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist
,
10026 "Alist of system-specific X windows key symbols.\n\
10027 Each element should have the form (N . SYMBOL) where N is the\n\
10028 numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\
10029 and SYMBOL is its name.");
10031 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
10032 "List of deferred actions to be performed at a later time.\n\
10033 The precise format isn't relevant here; we just check whether it is nil.");
10034 Vdeferred_action_list
= Qnil
;
10036 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
10037 "Function to call to handle deferred actions, after each command.\n\
10038 This function is called with no arguments after each command\n\
10039 whenever `deferred-action-list' is non-nil.");
10040 Vdeferred_action_function
= Qnil
;
10042 DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings
,
10043 "*Non-nil means show the equivalent key-binding when M-x command has one.\n\
10044 The value can be a length of time to show the message for.\n\
10045 If the value is non-nil and not a number, we wait 2 seconds.");
10046 Vsuggest_key_bindings
= Qt
;
10048 DEFVAR_LISP ("timer-list", &Vtimer_list
,
10049 "List of active absolute time timers in order of increasing time");
10050 Vtimer_list
= Qnil
;
10052 DEFVAR_LISP ("timer-idle-list", &Vtimer_idle_list
,
10053 "List of active idle-time timers in order of increasing time");
10054 Vtimer_idle_list
= Qnil
;
10056 DEFVAR_LISP ("input-method-function", &Vinput_method_function
,
10057 "If non-nil, the function that implements the current input method.\n\
10058 It's called with one argument, a printing character that was just read.\n\
10059 \(That means a character with code 040...0176.)\n\
10060 Typically this function uses `read-event' to read additional events.\n\
10061 When it does so, it should first bind `input-method-function' to nil\n\
10062 so it will not be called recursively.\n\
10064 The function should return a list of zero or more events\n\
10065 to be used as input. If it wants to put back some events\n\
10066 to be reconsidered, separately, by the input method,\n\
10067 it can add them to the beginning of `unread-command-events'.\n\
10069 The input method function can find in `input-method-previous-method'\n\
10070 the previous echo area message.\n\
10072 The input method function should refer to the variables\n\
10073 `input-method-use-echo-area' and `input-method-exit-on-first-char'\n\
10074 for guidance on what to do.");
10075 Vinput_method_function
= Qnil
;
10077 DEFVAR_LISP ("input-method-previous-message",
10078 &Vinput_method_previous_message
,
10079 "When `input-method-function' is called, hold the previous echo area message.\n\
10080 This variable exists because `read-event' clears the echo area\n\
10081 before running the input method. It is nil if there was no message.");
10082 Vinput_method_previous_message
= Qnil
;
10084 DEFVAR_LISP ("show-help-function", &Vshow_help_function
,
10085 "If non-nil, the function that implements the display of help.\n\
10086 It's called with one argument, the help string to display.");
10087 Vshow_help_function
= Qnil
;
10091 keys_of_keyboard ()
10093 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
10094 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
10095 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
10096 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
10097 initial_define_key (meta_map
, 'x', "execute-extended-command");
10099 initial_define_lispy_key (Vspecial_event_map
, "delete-frame",
10100 "handle-delete-frame");
10101 initial_define_lispy_key (Vspecial_event_map
, "iconify-frame",
10103 initial_define_lispy_key (Vspecial_event_map
, "make-frame-visible",