1 /* Keyboard and mouse input; editor command loop.
2 Copyright (C) 1985,86,87,88,89,93,94,95,96,97,99, 2000
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
28 #include "termhooks.h"
37 #include "dispextern.h"
39 #include "intervals.h"
40 #include "blockinput.h"
52 #include <sys/ioctl.h>
54 #endif /* not MSDOS */
56 #include "syssignal.h"
59 #include <sys/types.h>
64 /* This is to get the definitions of the XK_ symbols. */
71 #endif /* HAVE_NTGUI */
73 /* Include systime.h after xterm.h to avoid double inclusion of time.h. */
80 /* Variables for blockinput.h: */
82 /* Non-zero if interrupt input is blocked right now. */
83 int interrupt_input_blocked
;
85 /* Nonzero means an input interrupt has arrived
86 during the current critical section. */
87 int interrupt_input_pending
;
90 /* File descriptor to use for input. */
93 #ifdef HAVE_WINDOW_SYSTEM
94 /* Make all keyboard buffers much bigger when using X windows. */
96 /* But not too big (local data > 32K error) if on macintosh */
97 #define KBD_BUFFER_SIZE 512
99 #define KBD_BUFFER_SIZE 4096
101 #else /* No X-windows, character input */
102 #define KBD_BUFFER_SIZE 256
103 #endif /* No X-windows */
105 /* Following definition copied from eval.c */
109 struct backtrace
*next
;
110 Lisp_Object
*function
;
111 Lisp_Object
*args
; /* Points to vector of args. */
112 int nargs
; /* length of vector. If nargs is UNEVALLED,
113 args points to slot holding list of
119 KBOARD
*initial_kboard
;
120 KBOARD
*current_kboard
;
124 KBOARD the_only_kboard
;
127 /* Non-nil disable property on a command means
128 do not execute it; call disabled-command-hook's value instead. */
129 Lisp_Object Qdisabled
, Qdisabled_command_hook
;
131 #define NUM_RECENT_KEYS (100)
132 int recent_keys_index
; /* Index for storing next element into recent_keys */
133 int total_keys
; /* Total number of elements stored into recent_keys */
134 Lisp_Object recent_keys
; /* A vector, holding the last 100 keystrokes */
136 /* Vector holding the key sequence that invoked the current command.
137 It is reused for each command, and it may be longer than the current
138 sequence; this_command_key_count indicates how many elements
139 actually mean something.
140 It's easier to staticpro a single Lisp_Object than an array. */
141 Lisp_Object this_command_keys
;
142 int this_command_key_count
;
144 /* This vector is used as a buffer to record the events that were actually read
145 by read_key_sequence. */
146 Lisp_Object raw_keybuf
;
147 int raw_keybuf_count
;
149 #define GROW_RAW_KEYBUF \
150 if (raw_keybuf_count == XVECTOR (raw_keybuf)->size) \
152 int newsize = 2 * XVECTOR (raw_keybuf)->size; \
154 new = Fmake_vector (make_number (newsize), Qnil); \
155 bcopy (XVECTOR (raw_keybuf)->contents, XVECTOR (new)->contents, \
156 raw_keybuf_count * sizeof (Lisp_Object)); \
160 /* Number of elements of this_command_keys
161 that precede this key sequence. */
162 int this_single_command_key_start
;
164 /* Record values of this_command_key_count and echo_length ()
165 before this command was read. */
166 static int before_command_key_count
;
167 static int before_command_echo_length
;
168 /* Values of before_command_key_count and before_command_echo_length
169 saved by reset-this-command-lengths. */
170 static int before_command_key_count_1
;
171 static int before_command_echo_length_1
;
172 /* Flag set by reset-this-command-lengths,
173 saying to reset the lengths when add_command_key is called. */
174 static int before_command_restore_flag
;
176 extern int minbuf_level
;
178 extern int message_enable_multibyte
;
180 extern struct backtrace
*backtrace_list
;
182 /* If non-nil, the function that implements the display of help.
183 It's called with one argument, the help string to display. */
185 Lisp_Object Vshow_help_function
;
187 /* Nonzero means do menu prompting. */
188 static int menu_prompting
;
190 /* Character to see next line of menu prompt. */
191 static Lisp_Object menu_prompt_more_char
;
193 /* For longjmp to where kbd input is being done. */
194 static jmp_buf getcjmp
;
196 /* True while doing kbd input. */
197 int waiting_for_input
;
199 /* True while displaying for echoing. Delays C-g throwing. */
203 /* Non-null means we can start echoing at the next input pause even
204 though there is something in the echo area. */
206 static struct kboard
*ok_to_echo_at_next_pause
;
208 /* The kboard last echoing, or null for none. Reset to 0 in
209 cancel_echoing. If non-null, and a current echo area message
210 exists, and echo_message_buffer is eq to the current message
211 buffer, we know that the message comes from echo_kboard. */
213 static struct kboard
*echo_kboard
;
215 /* The buffer used for echoing. Set in echo_now, reset in
218 static Lisp_Object echo_message_buffer
;
220 /* Nonzero means disregard local maps for the menu bar. */
221 static int inhibit_local_menu_bar_menus
;
223 /* Nonzero means C-g should cause immediate error-signal. */
226 /* The user's ERASE setting. */
227 Lisp_Object Vtty_erase_char
;
229 /* Character to recognize as the help char. */
230 Lisp_Object Vhelp_char
;
232 /* List of other event types to recognize as meaning "help". */
233 Lisp_Object Vhelp_event_list
;
235 /* Form to execute when help char is typed. */
236 Lisp_Object Vhelp_form
;
238 /* Command to run when the help character follows a prefix key. */
239 Lisp_Object Vprefix_help_command
;
241 /* List of items that should move to the end of the menu bar. */
242 Lisp_Object Vmenu_bar_final_items
;
244 /* Non-nil means show the equivalent key-binding for
245 any M-x command that has one.
246 The value can be a length of time to show the message for.
247 If the value is non-nil and not a number, we wait 2 seconds. */
248 Lisp_Object Vsuggest_key_bindings
;
250 /* Character that causes a quit. Normally C-g.
252 If we are running on an ordinary terminal, this must be an ordinary
253 ASCII char, since we want to make it our interrupt character.
255 If we are not running on an ordinary terminal, it still needs to be
256 an ordinary ASCII char. This character needs to be recognized in
257 the input interrupt handler. At this point, the keystroke is
258 represented as a struct input_event, while the desired quit
259 character is specified as a lispy event. The mapping from struct
260 input_events to lispy events cannot run in an interrupt handler,
261 and the reverse mapping is difficult for anything but ASCII
264 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
268 extern Lisp_Object current_global_map
;
269 extern int minibuf_level
;
271 /* If non-nil, this is a map that overrides all other local maps. */
272 Lisp_Object Voverriding_local_map
;
274 /* If non-nil, Voverriding_local_map applies to the menu bar. */
275 Lisp_Object Voverriding_local_map_menu_flag
;
277 /* Keymap that defines special misc events that should
278 be processed immediately at a low level. */
279 Lisp_Object Vspecial_event_map
;
281 /* Current depth in recursive edits. */
282 int command_loop_level
;
284 /* Total number of times command_loop has read a key sequence. */
287 /* Last input character read as a command. */
288 Lisp_Object last_command_char
;
290 /* Last input character read as a command, not counting menus
291 reached by the mouse. */
292 Lisp_Object last_nonmenu_event
;
294 /* Last input character read for any purpose. */
295 Lisp_Object last_input_char
;
297 /* If not Qnil, a list of objects to be read as subsequent command input. */
298 Lisp_Object Vunread_command_events
;
300 /* If not Qnil, a list of objects to be read as subsequent command input
301 including input method processing. */
302 Lisp_Object Vunread_input_method_events
;
304 /* If not Qnil, a list of objects to be read as subsequent command input
305 but NOT including input method processing. */
306 Lisp_Object Vunread_post_input_method_events
;
308 /* If not -1, an event to be read as subsequent command input. */
309 int unread_command_char
;
311 /* If not Qnil, this is a switch-frame event which we decided to put
312 off until the end of a key sequence. This should be read as the
313 next command input, after any unread_command_events.
315 read_key_sequence uses this to delay switch-frame events until the
316 end of the key sequence; Fread_char uses it to put off switch-frame
317 events until a non-ASCII event is acceptable as input. */
318 Lisp_Object unread_switch_frame
;
320 /* A mask of extra modifier bits to put into every keyboard char. */
321 int extra_keyboard_modifiers
;
323 /* Char to use as prefix when a meta character is typed in.
324 This is bound on entry to minibuffer in case ESC is changed there. */
326 Lisp_Object meta_prefix_char
;
328 /* Last size recorded for a current buffer which is not a minibuffer. */
329 static int last_non_minibuf_size
;
331 /* Number of idle seconds before an auto-save and garbage collection. */
332 static Lisp_Object Vauto_save_timeout
;
334 /* Total number of times read_char has returned. */
335 int num_input_events
;
337 /* Total number of times read_char has returned, outside of macros. */
338 int num_nonmacro_input_events
;
340 /* Auto-save automatically when this many characters have been typed
341 since the last time. */
343 static int auto_save_interval
;
345 /* Value of num_nonmacro_input_events as of last auto save. */
349 /* The command being executed by the command loop.
350 Commands may set this, and the value set will be copied into
351 current_kboard->Vlast_command instead of the actual command. */
352 Lisp_Object Vthis_command
;
354 /* This is like Vthis_command, except that commands never set it. */
355 Lisp_Object real_this_command
;
357 /* The value of point when the last command was executed. */
358 int last_point_position
;
360 /* The buffer that was current when the last command was started. */
361 Lisp_Object last_point_position_buffer
;
363 /* The frame in which the last input event occurred, or Qmacro if the
364 last event came from a macro. We use this to determine when to
365 generate switch-frame events. This may be cleared by functions
366 like Fselect_frame, to make sure that a switch-frame event is
367 generated by the next character. */
368 Lisp_Object internal_last_event_frame
;
370 /* A user-visible version of the above, intended to allow users to
371 figure out where the last event came from, if the event doesn't
372 carry that information itself (i.e. if it was a character). */
373 Lisp_Object Vlast_event_frame
;
375 /* The timestamp of the last input event we received from the X server.
376 X Windows wants this for selection ownership. */
377 unsigned long last_event_timestamp
;
379 Lisp_Object Qself_insert_command
;
380 Lisp_Object Qforward_char
;
381 Lisp_Object Qbackward_char
;
382 Lisp_Object Qundefined
;
383 Lisp_Object Qtimer_event_handler
;
385 /* read_key_sequence stores here the command definition of the
386 key sequence that it reads. */
387 Lisp_Object read_key_sequence_cmd
;
389 /* Echo unfinished commands after this many seconds of pause. */
390 Lisp_Object Vecho_keystrokes
;
392 /* Form to evaluate (if non-nil) when Emacs is started. */
393 Lisp_Object Vtop_level
;
395 /* User-supplied string to translate input characters through. */
396 Lisp_Object Vkeyboard_translate_table
;
398 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
399 extern Lisp_Object Vfunction_key_map
;
401 /* Another keymap that maps key sequences into key sequences.
402 This one takes precedence over ordinary definitions. */
403 extern Lisp_Object Vkey_translation_map
;
405 /* If non-nil, this implements the current input method. */
406 Lisp_Object Vinput_method_function
;
407 Lisp_Object Qinput_method_function
;
409 /* When we call Vinput_method_function,
410 this holds the echo area message that was just erased. */
411 Lisp_Object Vinput_method_previous_message
;
413 /* Non-nil means deactivate the mark at end of this command. */
414 Lisp_Object Vdeactivate_mark
;
416 /* Menu bar specified in Lucid Emacs fashion. */
418 Lisp_Object Vlucid_menu_bar_dirty_flag
;
419 Lisp_Object Qrecompute_lucid_menubar
, Qactivate_menubar_hook
;
421 Lisp_Object Qecho_area_clear_hook
;
423 /* Hooks to run before and after each command. */
424 Lisp_Object Qpre_command_hook
, Vpre_command_hook
;
425 Lisp_Object Qpost_command_hook
, Vpost_command_hook
;
426 Lisp_Object Qcommand_hook_internal
, Vcommand_hook_internal
;
427 /* Hook run after a command if there's no more input soon. */
428 Lisp_Object Qpost_command_idle_hook
, Vpost_command_idle_hook
;
430 /* Delay time in microseconds before running post-command-idle-hook. */
431 int post_command_idle_delay
;
433 /* List of deferred actions to be performed at a later time.
434 The precise format isn't relevant here; we just check whether it is nil. */
435 Lisp_Object Vdeferred_action_list
;
437 /* Function to call to handle deferred actions, when there are any. */
438 Lisp_Object Vdeferred_action_function
;
439 Lisp_Object Qdeferred_action_function
;
441 Lisp_Object Qinput_method_exit_on_first_char
;
442 Lisp_Object Qinput_method_use_echo_area
;
444 /* File in which we write all commands we read. */
447 /* Nonzero if input is available. */
450 /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
451 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
455 /* Non-zero means force key bindings update in parse_menu_item. */
457 int update_menu_bindings
;
459 extern char *pending_malloc_warning
;
461 /* Circular buffer for pre-read keyboard input. */
463 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
465 /* Vector to GCPRO the Lisp objects referenced from kbd_buffer.
467 The interrupt-level event handlers will never enqueue an event on a
468 frame which is not in Vframe_list, and once an event is dequeued,
469 internal_last_event_frame or the event itself points to the frame.
472 But while the event is sitting in the queue, it's completely
473 unprotected. Suppose the user types one command which will run for
474 a while and then delete a frame, and then types another event at
475 the frame that will be deleted, before the command gets around to
476 it. Suppose there are no references to this frame elsewhere in
477 Emacs, and a GC occurs before the second event is dequeued. Now we
478 have an event referring to a freed frame, which will crash Emacs
481 Similar things happen when an event on a scroll bar is enqueued; the
482 window may be deleted while the event is in the queue.
484 So, we use this vector to protect the Lisp_Objects in the event
485 queue. That way, they'll be dequeued as dead frames or windows,
486 but still valid Lisp objects.
488 If kbd_buffer[i].kind != no_event, then
490 AREF (kbd_buffer_gcpro, 2 * i) == kbd_buffer[i].frame_or_window.
491 AREF (kbd_buffer_gcpro, 2 * i + 1) == kbd_buffer[i].arg. */
493 static Lisp_Object kbd_buffer_gcpro
;
495 /* Pointer to next available character in kbd_buffer.
496 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
497 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the
498 next available char is in kbd_buffer[0]. */
499 static struct input_event
*kbd_fetch_ptr
;
501 /* Pointer to next place to store character in kbd_buffer. This
502 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
503 character should go in kbd_buffer[0]. */
504 static struct input_event
* volatile kbd_store_ptr
;
506 /* The above pair of variables forms a "queue empty" flag. When we
507 enqueue a non-hook event, we increment kbd_store_ptr. When we
508 dequeue a non-hook event, we increment kbd_fetch_ptr. We say that
509 there is input available iff the two pointers are not equal.
511 Why not just have a flag set and cleared by the enqueuing and
512 dequeuing functions? Such a flag could be screwed up by interrupts
513 at inopportune times. */
515 /* If this flag is non-nil, we check mouse_moved to see when the
516 mouse moves, and motion events will appear in the input stream.
517 Otherwise, mouse motion is ignored. */
518 static Lisp_Object do_mouse_tracking
;
520 /* Symbols to head events. */
521 Lisp_Object Qmouse_movement
;
522 Lisp_Object Qscroll_bar_movement
;
523 Lisp_Object Qswitch_frame
;
524 Lisp_Object Qdelete_frame
;
525 Lisp_Object Qiconify_frame
;
526 Lisp_Object Qmake_frame_visible
;
527 Lisp_Object Qhelp_echo
;
529 /* Symbols to denote kinds of events. */
530 Lisp_Object Qfunction_key
;
531 Lisp_Object Qmouse_click
;
533 Lisp_Object Qmouse_wheel
;
534 Lisp_Object Qlanguage_change
;
536 Lisp_Object Qdrag_n_drop
;
537 /* Lisp_Object Qmouse_movement; - also an event header */
539 /* Properties of event headers. */
540 Lisp_Object Qevent_kind
;
541 Lisp_Object Qevent_symbol_elements
;
543 /* menu item parts */
544 Lisp_Object Qmenu_alias
;
545 Lisp_Object Qmenu_enable
;
546 Lisp_Object QCenable
, QCvisible
, QChelp
, QCfilter
, QCkeys
, QCkey_sequence
;
547 Lisp_Object QCbutton
, QCtoggle
, QCradio
;
548 extern Lisp_Object Vdefine_key_rebound_commands
;
549 extern Lisp_Object Qmenu_item
;
551 /* An event header symbol HEAD may have a property named
552 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
553 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
554 mask of modifiers applied to it. If present, this is used to help
555 speed up parse_modifiers. */
556 Lisp_Object Qevent_symbol_element_mask
;
558 /* An unmodified event header BASE may have a property named
559 Qmodifier_cache, which is an alist mapping modifier masks onto
560 modified versions of BASE. If present, this helps speed up
562 Lisp_Object Qmodifier_cache
;
564 /* Symbols to use for parts of windows. */
565 Lisp_Object Qmode_line
;
566 Lisp_Object Qvertical_line
;
567 Lisp_Object Qvertical_scroll_bar
;
568 Lisp_Object Qmenu_bar
;
570 Lisp_Object
recursive_edit_unwind (), command_loop ();
571 Lisp_Object
Fthis_command_keys ();
572 Lisp_Object Qextended_command_history
;
573 EMACS_TIME
timer_check ();
575 extern Lisp_Object Vhistory_length
;
577 extern char *x_get_keysym_name ();
579 static void record_menu_key ();
581 Lisp_Object Qpolling_period
;
583 /* List of absolute timers. Appears in order of next scheduled event. */
584 Lisp_Object Vtimer_list
;
586 /* List of idle time timers. Appears in order of next scheduled event. */
587 Lisp_Object Vtimer_idle_list
;
589 /* Incremented whenever a timer is run. */
592 extern Lisp_Object Vprint_level
, Vprint_length
;
594 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
596 EMACS_TIME
*input_available_clear_time
;
598 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
599 Default is 1 if INTERRUPT_INPUT is defined. */
602 /* Nonzero while interrupts are temporarily deferred during redisplay. */
603 int interrupts_deferred
;
605 /* Nonzero means use ^S/^Q for flow control. */
608 /* Allow m- file to inhibit use of FIONREAD. */
609 #ifdef BROKEN_FIONREAD
613 /* We are unable to use interrupts if FIONREAD is not available,
614 so flush SIGIO so we won't try. */
621 /* If we support a window system, turn on the code to poll periodically
622 to detect C-g. It isn't actually used when doing interrupt input. */
623 #ifdef HAVE_WINDOW_SYSTEM
624 #define POLL_FOR_INPUT
627 /* After a command is executed, if point is moved into a region that
628 has specific properties (e.g. composition, display), we adjust
629 point to the boundary of the region. But, if a command sets this
630 valiable to non-nil, we suppress this point adjustment. This
631 variable is set to nil before reading a command. */
633 Lisp_Object Vdisable_point_adjustment
;
635 /* If non-nil, always disable point adjustment. */
637 Lisp_Object Vglobal_disable_point_adjustment
;
640 /* Global variable declarations. */
642 /* Function for init_keyboard to call with no args (if nonzero). */
643 void (*keyboard_init_hook
) ();
645 static int read_avail_input
P_ ((int));
646 static void get_input_pending
P_ ((int *, int));
647 static int readable_events
P_ ((int));
648 static Lisp_Object read_char_x_menu_prompt
P_ ((int, Lisp_Object
*,
649 Lisp_Object
, int *));
650 static Lisp_Object
read_char_x_menu_prompt ();
651 static Lisp_Object read_char_minibuf_menu_prompt
P_ ((int, int,
653 static Lisp_Object make_lispy_event
P_ ((struct input_event
*));
655 static Lisp_Object make_lispy_movement
P_ ((struct frame
*, Lisp_Object
,
656 enum scroll_bar_part
,
657 Lisp_Object
, Lisp_Object
,
660 static Lisp_Object modify_event_symbol
P_ ((int, unsigned, Lisp_Object
,
661 Lisp_Object
, char **,
662 Lisp_Object
*, unsigned));
663 static Lisp_Object make_lispy_switch_frame
P_ ((Lisp_Object
));
664 static int parse_solitary_modifier
P_ ((Lisp_Object
));
665 static int parse_solitary_modifier ();
666 static void save_getcjmp
P_ ((jmp_buf));
667 static void save_getcjmp ();
668 static void restore_getcjmp
P_ ((jmp_buf));
669 static Lisp_Object apply_modifiers
P_ ((int, Lisp_Object
));
670 static void clear_event
P_ ((struct input_event
*));
672 /* Nonzero means don't try to suspend even if the operating system seems
674 static int cannot_suspend
;
676 #define min(a,b) ((a)<(b)?(a):(b))
677 #define max(a,b) ((a)>(b)?(a):(b))
679 /* Install the string STR as the beginning of the string of echoing,
680 so that it serves as a prompt for the next character.
681 Also start echoing. */
687 int len
= strlen (str
);
689 if (len
> ECHOBUFSIZE
- 4)
690 len
= ECHOBUFSIZE
- 4;
691 bcopy (str
, current_kboard
->echobuf
, len
);
692 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
693 *current_kboard
->echoptr
= '\0';
695 current_kboard
->echo_after_prompt
= len
;
700 /* Add C to the echo string, if echoing is going on.
701 C can be a character, which is printed prettily ("M-C-x" and all that
702 jazz), or a symbol, whose name is printed. */
708 extern char *push_key_description ();
710 if (current_kboard
->immediate_echo
)
712 char *ptr
= current_kboard
->echoptr
;
714 if (ptr
!= current_kboard
->echobuf
)
717 /* If someone has passed us a composite event, use its head symbol. */
722 if (ptr
- current_kboard
->echobuf
723 > ECHOBUFSIZE
- KEY_DESCRIPTION_SIZE
)
726 ptr
= push_key_description (XINT (c
), ptr
);
728 else if (SYMBOLP (c
))
730 struct Lisp_String
*name
= XSYMBOL (c
)->name
;
731 if ((ptr
- current_kboard
->echobuf
) + STRING_BYTES (name
) + 4
734 bcopy (name
->data
, ptr
, STRING_BYTES (name
));
735 ptr
+= STRING_BYTES (name
);
738 if (current_kboard
->echoptr
== current_kboard
->echobuf
741 strcpy (ptr
, " (Type ? for further options)");
746 current_kboard
->echoptr
= ptr
;
752 /* Temporarily add a dash to the end of the echo string if it's not
753 empty, so that it serves as a mini-prompt for the very next character. */
758 if (!current_kboard
->immediate_echo
759 && current_kboard
->echoptr
== current_kboard
->echobuf
)
761 /* Do nothing if we just printed a prompt. */
762 if (current_kboard
->echo_after_prompt
763 == current_kboard
->echoptr
- current_kboard
->echobuf
)
765 /* Do nothing if not echoing at all. */
766 if (current_kboard
->echoptr
== 0)
769 /* Put a dash at the end of the buffer temporarily,
770 but make it go away when the next character is added. */
771 current_kboard
->echoptr
[0] = '-';
772 current_kboard
->echoptr
[1] = 0;
777 /* Display the current echo string, and begin echoing if not already
783 if (!current_kboard
->immediate_echo
)
786 current_kboard
->immediate_echo
= 1;
788 for (i
= 0; i
< this_command_key_count
; i
++)
791 c
= XVECTOR (this_command_keys
)->contents
[i
];
792 if (! (EVENT_HAS_PARAMETERS (c
)
793 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
800 message2_nolog (current_kboard
->echobuf
, strlen (current_kboard
->echobuf
),
801 ! NILP (current_buffer
->enable_multibyte_characters
));
804 /* Record in what buffer we echoed, and from which kboard. */
805 echo_message_buffer
= echo_area_buffer
[0];
806 echo_kboard
= current_kboard
;
808 if (waiting_for_input
&& !NILP (Vquit_flag
))
809 quit_throw_to_read_char ();
812 /* Turn off echoing, for the start of a new command. */
817 current_kboard
->immediate_echo
= 0;
818 current_kboard
->echoptr
= current_kboard
->echobuf
;
819 current_kboard
->echo_after_prompt
= -1;
820 ok_to_echo_at_next_pause
= NULL
;
822 echo_message_buffer
= Qnil
;
825 /* Return the length of the current echo string. */
830 return current_kboard
->echoptr
- current_kboard
->echobuf
;
833 /* Truncate the current echo message to its first LEN chars.
834 This and echo_char get used by read_key_sequence when the user
835 switches frames while entering a key sequence. */
841 current_kboard
->echobuf
[len
] = '\0';
842 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
843 truncate_echo_area (len
);
847 /* Functions for manipulating this_command_keys. */
849 add_command_key (key
)
852 int size
= XVECTOR (this_command_keys
)->size
;
854 /* If reset-this-command-length was called recently, obey it now.
855 See the doc string of that function for an explanation of why. */
856 if (before_command_restore_flag
)
858 this_command_key_count
= before_command_key_count_1
;
859 if (this_command_key_count
< this_single_command_key_start
)
860 this_single_command_key_start
= this_command_key_count
;
861 echo_truncate (before_command_echo_length_1
);
862 before_command_restore_flag
= 0;
865 if (this_command_key_count
>= size
)
867 Lisp_Object new_keys
;
869 new_keys
= Fmake_vector (make_number (size
* 2), Qnil
);
870 bcopy (XVECTOR (this_command_keys
)->contents
,
871 XVECTOR (new_keys
)->contents
,
872 size
* sizeof (Lisp_Object
));
874 this_command_keys
= new_keys
;
877 XVECTOR (this_command_keys
)->contents
[this_command_key_count
++] = key
;
883 int count
= specpdl_ptr
- specpdl
;
886 if (command_loop_level
> 0)
888 specbind (Qstandard_output
, Qt
);
889 specbind (Qstandard_input
, Qt
);
892 #ifdef HAVE_X_WINDOWS
893 /* The command loop has started a busy-cursor timer, so we have to
894 cancel it here, otherwise it will fire because the recursive edit
895 can take some time. */
896 if (display_busy_cursor_p
)
897 cancel_busy_cursor ();
900 val
= command_loop ();
902 Fsignal (Qquit
, Qnil
);
903 /* Handle throw from read_minibuf when using minibuffer
904 while it's active but we're in another window. */
906 Fsignal (Qerror
, Fcons (val
, Qnil
));
908 return unbind_to (count
, Qnil
);
911 /* When an auto-save happens, record the "time", and don't do again soon. */
916 last_auto_save
= num_nonmacro_input_events
;
919 /* Make an auto save happen as soon as possible at command level. */
922 force_auto_save_soon ()
924 last_auto_save
= - auto_save_interval
- 1;
926 record_asynch_buffer_change ();
929 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
930 "Invoke the editor command loop recursively.\n\
931 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
932 that tells this function to return.\n\
933 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
934 This function is called by the editor initialization to begin editing.")
937 int count
= specpdl_ptr
- specpdl
;
939 command_loop_level
++;
940 update_mode_lines
= 1;
942 /* This function may have been called from a debugger called from
943 within redisplay, for instance by Edebugging a function called
944 from fontification-functions. We want to allow redisplay in
945 the debugging session.
947 The recursive edit is left with a `(throw exit ...)'. The `exit'
948 tag is not caught anywhere in redisplay, i.e. when we leave the
949 recursive edit, the original redisplay leading to the recursive
950 edit will be unwound. The outcome should therefore be safe. */
951 specbind (Qinhibit_redisplay
, Qnil
);
954 record_unwind_protect (recursive_edit_unwind
,
956 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
960 return unbind_to (count
, Qnil
);
964 recursive_edit_unwind (buffer
)
968 Fset_buffer (buffer
);
970 command_loop_level
--;
971 update_mode_lines
= 1;
979 #if 0 /* Theory: if there's anything in Vunread_command_events,
980 it will right away be read by read_key_sequence,
981 and then if we do switch KBOARDS, it will go into the side
982 queue then. So we don't need to do anything special here -- rms. */
983 if (CONSP (Vunread_command_events
))
985 current_kboard
->kbd_queue
986 = nconc2 (Vunread_command_events
, current_kboard
->kbd_queue
);
987 current_kboard
->kbd_queue_has_data
= 1;
989 Vunread_command_events
= Qnil
;
995 /* Switch to the single-kboard state, making current_kboard
996 the only KBOARD from which further input is accepted. */
999 single_kboard_state ()
1006 /* Maintain a stack of kboards, so other parts of Emacs
1007 can switch temporarily to the kboard of a given frame
1008 and then revert to the previous status. */
1013 struct kboard_stack
*next
;
1016 static struct kboard_stack
*kboard_stack
;
1019 push_frame_kboard (f
)
1023 struct kboard_stack
*p
1024 = (struct kboard_stack
*) xmalloc (sizeof (struct kboard_stack
));
1026 p
->next
= kboard_stack
;
1027 p
->kboard
= current_kboard
;
1030 current_kboard
= FRAME_KBOARD (f
);
1038 struct kboard_stack
*p
= kboard_stack
;
1039 current_kboard
= p
->kboard
;
1040 kboard_stack
= p
->next
;
1045 /* Handle errors that are not handled at inner levels
1046 by printing an error message and returning to the editor command loop. */
1052 Lisp_Object old_level
, old_length
;
1053 char macroerror
[50];
1055 if (!NILP (executing_macro
))
1057 if (executing_macro_iterations
== 1)
1058 sprintf (macroerror
, "After 1 kbd macro iteration: ");
1060 sprintf (macroerror
, "After %d kbd macro iterations: ",
1061 executing_macro_iterations
);
1066 Vstandard_output
= Qt
;
1067 Vstandard_input
= Qt
;
1068 Vexecuting_macro
= Qnil
;
1069 executing_macro
= Qnil
;
1070 current_kboard
->Vprefix_arg
= Qnil
;
1071 current_kboard
->Vlast_prefix_arg
= Qnil
;
1074 /* Avoid unquittable loop if data contains a circular list. */
1075 old_level
= Vprint_level
;
1076 old_length
= Vprint_length
;
1077 XSETFASTINT (Vprint_level
, 10);
1078 XSETFASTINT (Vprint_length
, 10);
1079 cmd_error_internal (data
, macroerror
);
1080 Vprint_level
= old_level
;
1081 Vprint_length
= old_length
;
1085 Vinhibit_quit
= Qnil
;
1087 any_kboard_state ();
1090 return make_number (0);
1093 /* Take actions on handling an error. DATA is the data that describes
1096 CONTEXT is a C-string containing ASCII characters only which
1097 describes the context in which the error happened. If we need to
1098 generalize CONTEXT to allow multibyte characters, make it a Lisp
1102 cmd_error_internal (data
, context
)
1107 int kill_emacs_p
= 0;
1108 struct frame
*sf
= SELECTED_FRAME ();
1112 clear_message (1, 0);
1114 /* If the window system or terminal frame hasn't been initialized
1115 yet, or we're not interactive, it's best to dump this message out
1116 to stderr and exit. */
1117 if (!sf
->glyphs_initialized_p
1118 /* This is the case of the frame dumped with Emacs, when we're
1119 running under a window system. */
1120 || (!NILP (Vwindow_system
)
1121 && !inhibit_window_system
1122 && FRAME_TERMCAP_P (sf
))
1125 stream
= Qexternal_debugging_output
;
1136 write_string_1 (context
, -1, stream
);
1138 print_error_message (data
, stream
);
1140 /* If the window system or terminal frame hasn't been initialized
1141 yet, or we're in -batch mode, this error should cause Emacs to exit. */
1145 Fkill_emacs (make_number (-1));
1149 Lisp_Object
command_loop_1 ();
1150 Lisp_Object
command_loop_2 ();
1151 Lisp_Object
top_level_1 ();
1153 /* Entry to editor-command-loop.
1154 This level has the catches for exiting/returning to editor command loop.
1155 It returns nil to exit recursive edit, t to abort it. */
1160 if (command_loop_level
> 0 || minibuf_level
> 0)
1163 val
= internal_catch (Qexit
, command_loop_2
, Qnil
);
1164 executing_macro
= Qnil
;
1170 internal_catch (Qtop_level
, top_level_1
, Qnil
);
1171 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
1172 executing_macro
= Qnil
;
1174 /* End of file in -batch run causes exit here. */
1180 /* Here we catch errors in execution of commands within the
1181 editing loop, and reenter the editing loop.
1182 When there is an error, cmd_error runs and returns a non-nil
1183 value to us. A value of nil means that cmd_loop_1 itself
1184 returned due to end of file (or end of kbd macro). */
1189 register Lisp_Object val
;
1192 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
1193 while (!NILP (val
));
1201 return Feval (Vtop_level
);
1207 /* On entry to the outer level, run the startup file */
1208 if (!NILP (Vtop_level
))
1209 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
1210 else if (!NILP (Vpurify_flag
))
1211 message ("Bare impure Emacs (standard Lisp code not loaded)");
1213 message ("Bare Emacs (standard Lisp code not loaded)");
1217 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
1218 "Exit all recursive editing levels.")
1221 #ifdef HAVE_X_WINDOWS
1222 if (display_busy_cursor_p
)
1223 cancel_busy_cursor ();
1225 return Fthrow (Qtop_level
, Qnil
);
1228 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
1229 "Exit from the innermost recursive edit or minibuffer.")
1232 if (command_loop_level
> 0 || minibuf_level
> 0)
1233 Fthrow (Qexit
, Qnil
);
1235 error ("No recursive edit is in progress");
1239 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
1240 "Abort the command that requested this recursive edit or minibuffer input.")
1243 if (command_loop_level
> 0 || minibuf_level
> 0)
1246 error ("No recursive edit is in progress");
1250 /* This is the actual command reading loop,
1251 sans error-handling encapsulation. */
1253 Lisp_Object
Fcommand_execute ();
1254 static int read_key_sequence ();
1255 void safe_run_hooks ();
1256 static void adjust_point_for_property ();
1264 Lisp_Object keybuf
[30];
1268 struct buffer
*prev_buffer
= NULL
;
1270 int was_locked
= single_kboard
;
1273 current_kboard
->Vprefix_arg
= Qnil
;
1274 current_kboard
->Vlast_prefix_arg
= Qnil
;
1275 Vdeactivate_mark
= Qnil
;
1276 waiting_for_input
= 0;
1280 this_command_key_count
= 0;
1281 this_single_command_key_start
= 0;
1283 /* Make sure this hook runs after commands that get errors and
1284 throw to top level. */
1285 /* Note that the value cell will never directly contain nil
1286 if the symbol is a local variable. */
1287 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1288 safe_run_hooks (Qpost_command_hook
);
1290 /* If displaying a message, resize the echo area window to fit
1291 that message's size exactly. */
1292 if (!NILP (echo_area_buffer
[0]))
1293 resize_echo_area_axactly ();
1295 if (!NILP (Vdeferred_action_list
))
1296 call0 (Vdeferred_action_function
);
1298 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1300 if (NILP (Vunread_command_events
)
1301 && NILP (Vunread_input_method_events
)
1302 && NILP (Vunread_post_input_method_events
)
1303 && NILP (Vexecuting_macro
)
1304 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1, 1)))
1305 safe_run_hooks (Qpost_command_idle_hook
);
1308 /* Do this after running Vpost_command_hook, for consistency. */
1309 current_kboard
->Vlast_command
= Vthis_command
;
1310 current_kboard
->Vreal_last_command
= real_this_command
;
1314 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
1317 /* Make sure the current window's buffer is selected. */
1318 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1319 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1321 /* Display any malloc warning that just came out. Use while because
1322 displaying one warning can cause another. */
1324 while (pending_malloc_warning
)
1325 display_malloc_warning ();
1329 Vdeactivate_mark
= Qnil
;
1331 /* If minibuffer on and echo area in use,
1332 wait 2 sec and redraw minibuffer. */
1335 && !NILP (echo_area_buffer
[0])
1336 && EQ (minibuf_window
, echo_area_window
))
1338 /* Bind inhibit-quit to t so that C-g gets read in
1339 rather than quitting back to the minibuffer. */
1340 int count
= specpdl_ptr
- specpdl
;
1341 specbind (Qinhibit_quit
, Qt
);
1343 Fsit_for (make_number (2), Qnil
, Qnil
);
1344 /* Clear the echo area. */
1346 safe_run_hooks (Qecho_area_clear_hook
);
1348 unbind_to (count
, Qnil
);
1350 /* If a C-g came in before, treat it as input now. */
1351 if (!NILP (Vquit_flag
))
1354 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1359 alloca (0); /* Cause a garbage collection now */
1360 /* Since we can free the most stuff here. */
1361 #endif /* C_ALLOCA */
1364 /* Select the frame that the last event came from. Usually,
1365 switch-frame events will take care of this, but if some lisp
1366 code swallows a switch-frame event, we'll fix things up here.
1367 Is this a good idea? */
1368 if (FRAMEP (internal_last_event_frame
)
1369 && !EQ (internal_last_event_frame
, selected_frame
))
1370 Fselect_frame (internal_last_event_frame
, Qnil
);
1372 /* If it has changed current-menubar from previous value,
1373 really recompute the menubar from the value. */
1374 if (! NILP (Vlucid_menu_bar_dirty_flag
)
1375 && !NILP (Ffboundp (Qrecompute_lucid_menubar
)))
1376 call0 (Qrecompute_lucid_menubar
);
1378 before_command_key_count
= this_command_key_count
;
1379 before_command_echo_length
= echo_length ();
1381 Vthis_command
= Qnil
;
1382 real_this_command
= Qnil
;
1384 /* Read next key sequence; i gets its length. */
1385 i
= read_key_sequence (keybuf
, sizeof keybuf
/ sizeof keybuf
[0],
1388 /* A filter may have run while we were reading the input. */
1389 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
1391 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1392 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1396 /* Now we have read a key sequence of length I,
1397 or else I is 0 and we found end of file. */
1399 if (i
== 0) /* End of file -- happens only in */
1400 return Qnil
; /* a kbd macro, at the end. */
1401 /* -1 means read_key_sequence got a menu that was rejected.
1402 Just loop around and read another command. */
1406 this_command_key_count
= 0;
1407 this_single_command_key_start
= 0;
1411 last_command_char
= keybuf
[i
- 1];
1413 /* If the previous command tried to force a specific window-start,
1414 forget about that, in case this command moves point far away
1415 from that position. But also throw away beg_unchanged and
1416 end_unchanged information in that case, so that redisplay will
1417 update the whole window properly. */
1418 if (!NILP (XWINDOW (selected_window
)->force_start
))
1421 XWINDOW (selected_window
)->force_start
= Qnil
;
1422 b
= XBUFFER (XWINDOW (selected_window
)->buffer
);
1423 BUF_BEG_UNCHANGED (b
) = BUF_END_UNCHANGED (b
) = 0;
1426 cmd
= read_key_sequence_cmd
;
1427 if (!NILP (Vexecuting_macro
))
1429 if (!NILP (Vquit_flag
))
1431 Vexecuting_macro
= Qt
;
1432 QUIT
; /* Make some noise. */
1433 /* Will return since macro now empty. */
1437 /* Do redisplay processing after this command except in special
1438 cases identified below. */
1439 prev_buffer
= current_buffer
;
1440 prev_modiff
= MODIFF
;
1441 last_point_position
= PT
;
1442 XSETBUFFER (last_point_position_buffer
, prev_buffer
);
1444 /* By default, we adjust point to a boundary of a region that
1445 has such a property that should be treated intangible
1446 (e.g. composition, display). But, some commands will set
1447 this variable differently. */
1448 Vdisable_point_adjustment
= Qnil
;
1450 /* Execute the command. */
1452 Vthis_command
= cmd
;
1453 real_this_command
= cmd
;
1454 /* Note that the value cell will never directly contain nil
1455 if the symbol is a local variable. */
1456 if (!NILP (Vpre_command_hook
) && !NILP (Vrun_hooks
))
1457 safe_run_hooks (Qpre_command_hook
);
1459 if (NILP (Vthis_command
))
1461 /* nil means key is undefined. */
1463 current_kboard
->defining_kbd_macro
= Qnil
;
1464 update_mode_lines
= 1;
1465 current_kboard
->Vprefix_arg
= Qnil
;
1469 if (NILP (current_kboard
->Vprefix_arg
) && ! no_direct
)
1471 /* In case we jump to directly_done. */
1472 Vcurrent_prefix_arg
= current_kboard
->Vprefix_arg
;
1474 /* Recognize some common commands in common situations and
1475 do them directly. */
1476 if (EQ (Vthis_command
, Qforward_char
) && PT
< ZV
)
1478 struct Lisp_Char_Table
*dp
1479 = window_display_table (XWINDOW (selected_window
));
1480 lose
= FETCH_CHAR (PT_BYTE
);
1483 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1484 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1485 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1486 && (lose
>= 0x20 && lose
< 0x7f)))
1487 : (lose
>= 0x20 && lose
< 0x7f))
1488 /* To extract the case of continuation on
1489 wide-column characters. */
1490 && (WIDTH_BY_CHAR_HEAD (FETCH_BYTE (PT_BYTE
)) == 1)
1491 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1493 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1495 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1497 && !windows_or_buffers_changed
1498 && EQ (current_buffer
->selective_display
, Qnil
)
1499 && !detect_input_pending ()
1500 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1501 && NILP (Vexecuting_macro
))
1502 direct_output_forward_char (1);
1505 else if (EQ (Vthis_command
, Qbackward_char
) && PT
> BEGV
)
1507 struct Lisp_Char_Table
*dp
1508 = window_display_table (XWINDOW (selected_window
));
1510 lose
= FETCH_CHAR (PT_BYTE
);
1512 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1513 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1514 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1515 && (lose
>= 0x20 && lose
< 0x7f)))
1516 : (lose
>= 0x20 && lose
< 0x7f))
1517 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1519 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1521 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1523 && !windows_or_buffers_changed
1524 && EQ (current_buffer
->selective_display
, Qnil
)
1525 && !detect_input_pending ()
1526 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1527 && NILP (Vexecuting_macro
))
1528 direct_output_forward_char (-1);
1531 else if (EQ (Vthis_command
, Qself_insert_command
)
1532 /* Try this optimization only on ascii keystrokes. */
1533 && INTEGERP (last_command_char
))
1535 unsigned int c
= XINT (last_command_char
);
1537 if (NILP (Vexecuting_macro
)
1538 && !EQ (minibuf_window
, selected_window
))
1540 if (!nonundocount
|| nonundocount
>= 20)
1548 lose
= ((XFASTINT (XWINDOW (selected_window
)->last_modified
)
1550 || (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1552 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1554 || MODIFF
<= SAVE_MODIFF
1555 || windows_or_buffers_changed
1556 || !EQ (current_buffer
->selective_display
, Qnil
)
1557 || detect_input_pending ()
1558 || !NILP (XWINDOW (selected_window
)->column_number_displayed
)
1559 || !NILP (Vexecuting_macro
));
1561 value
= internal_self_insert (c
, 0);
1566 /* VALUE == 1 when AFTER-CHANGE functions are
1567 installed which is the case most of the time
1568 because FONT-LOCK installs one. */
1569 if (!lose
&& !value
)
1570 direct_output_for_insert (c
);
1575 /* Here for a command that isn't executed directly */
1577 #ifdef HAVE_X_WINDOWS
1578 if (display_busy_cursor_p
)
1579 start_busy_cursor ();
1583 if (NILP (current_kboard
->Vprefix_arg
))
1585 Fcommand_execute (Vthis_command
, Qnil
, Qnil
, Qnil
);
1587 #ifdef HAVE_X_WINDOWS
1588 if (display_busy_cursor_p
)
1589 cancel_busy_cursor ();
1593 current_kboard
->Vlast_prefix_arg
= Vcurrent_prefix_arg
;
1595 /* Note that the value cell will never directly contain nil
1596 if the symbol is a local variable. */
1597 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1598 safe_run_hooks (Qpost_command_hook
);
1600 /* If displaying a message, resize the echo area window to fit
1601 that message's size exactly. */
1602 if (!NILP (echo_area_buffer
[0]))
1603 resize_echo_area_axactly ();
1605 if (!NILP (Vdeferred_action_list
))
1606 safe_run_hooks (Qdeferred_action_function
);
1608 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1610 if (NILP (Vunread_command_events
)
1611 && NILP (Vunread_input_method_events
)
1612 && NILP (Vunread_post_input_method_events
)
1613 && NILP (Vexecuting_macro
)
1614 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1, 1)))
1615 safe_run_hooks (Qpost_command_idle_hook
);
1618 /* If there is a prefix argument,
1619 1) We don't want Vlast_command to be ``universal-argument''
1620 (that would be dumb), so don't set Vlast_command,
1621 2) we want to leave echoing on so that the prefix will be
1622 echoed as part of this key sequence, so don't call
1624 3) we want to leave this_command_key_count non-zero, so that
1625 read_char will realize that it is re-reading a character, and
1626 not echo it a second time.
1628 If the command didn't actually create a prefix arg,
1629 but is merely a frame event that is transparent to prefix args,
1630 then the above doesn't apply. */
1631 if (NILP (current_kboard
->Vprefix_arg
) || CONSP (last_command_char
))
1633 current_kboard
->Vlast_command
= Vthis_command
;
1634 current_kboard
->Vreal_last_command
= real_this_command
;
1636 this_command_key_count
= 0;
1637 this_single_command_key_start
= 0;
1640 if (!NILP (current_buffer
->mark_active
) && !NILP (Vrun_hooks
))
1642 if (!NILP (Vdeactivate_mark
) && !NILP (Vtransient_mark_mode
))
1644 current_buffer
->mark_active
= Qnil
;
1645 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
1647 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
1648 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
1653 if (current_buffer
== prev_buffer
1654 && last_point_position
!= PT
1655 && NILP (Vdisable_point_adjustment
)
1656 && NILP (Vglobal_disable_point_adjustment
))
1657 adjust_point_for_property (last_point_position
);
1659 /* Install chars successfully executed in kbd macro. */
1661 if (!NILP (current_kboard
->defining_kbd_macro
)
1662 && NILP (current_kboard
->Vprefix_arg
))
1663 finalize_kbd_macro_chars ();
1667 any_kboard_state ();
1672 extern Lisp_Object Qcomposition
, Qdisplay
;
1674 /* Adjust point to a boundary of a region that has such a property
1675 that should be treated intangible. For the moment, we check
1676 `composition' and `display' property. LAST_PT is the last position
1680 adjust_point_for_property (last_pt
)
1685 int check_composition
= 1, check_display
= 1;
1687 while (check_composition
|| check_display
)
1689 if (check_composition
1690 && PT
> BEGV
&& PT
< ZV
1691 && get_property_and_range (PT
, Qcomposition
, &val
, &start
, &end
, Qnil
)
1692 && COMPOSITION_VALID_P (start
, end
, val
)
1693 && start
< PT
&& end
> PT
1694 && (last_pt
<= start
|| last_pt
>= end
))
1702 check_composition
= 0;
1704 && PT
> BEGV
&& PT
< ZV
1705 && get_property_and_range (PT
, Qdisplay
, &val
, &start
, &end
, Qnil
)
1706 && display_prop_intangible_p (val
)
1707 && start
< PT
&& end
> PT
1708 && (last_pt
<= start
|| last_pt
>= end
))
1714 check_composition
= 1;
1720 /* Subroutine for safe_run_hooks: run the hook HOOK. */
1723 safe_run_hooks_1 (hook
)
1726 return call1 (Vrun_hooks
, Vinhibit_quit
);
1729 /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */
1732 safe_run_hooks_error (data
)
1735 return Fset (Vinhibit_quit
, Qnil
);
1738 /* If we get an error while running the hook, cause the hook variable
1739 to be nil. Also inhibit quits, so that C-g won't cause the hook
1740 to mysteriously evaporate. */
1743 safe_run_hooks (hook
)
1746 int count
= specpdl_ptr
- specpdl
;
1747 specbind (Qinhibit_quit
, hook
);
1749 internal_condition_case (safe_run_hooks_1
, Qt
, safe_run_hooks_error
);
1751 unbind_to (count
, Qnil
);
1755 /* Number of seconds between polling for input. This is a Lisp
1756 variable that can be bound. */
1760 /* Nonzero means polling for input is temporarily suppressed. */
1762 int poll_suppress_count
;
1764 /* Asynchronous timer for polling. */
1766 struct atimer
*poll_timer
;
1769 #ifdef POLL_FOR_INPUT
1771 /* Poll for input, so what we catch a C-g if it comes in. This
1772 function is called from x_make_frame_visible, see comment
1778 if (interrupt_input_blocked
== 0
1779 && !waiting_for_input
)
1780 read_avail_input (0);
1783 /* Timer callback function for poll_timer. TIMER is equal to
1787 poll_for_input (timer
)
1788 struct atimer
*timer
;
1790 if (poll_suppress_count
== 0)
1791 poll_for_input_1 ();
1794 #endif /* POLL_FOR_INPUT */
1796 /* Begin signals to poll for input, if they are appropriate.
1797 This function is called unconditionally from various places. */
1802 #ifdef POLL_FOR_INPUT
1803 if (read_socket_hook
&& !interrupt_input
)
1805 /* Turn alarm handling on unconditionally. It might have
1806 been turned off in process.c. */
1807 turn_on_atimers (1);
1809 /* If poll timer doesn't exist, are we need one with
1810 a different interval, start a new one. */
1811 if (poll_timer
== NULL
1812 || EMACS_SECS (poll_timer
->interval
) != polling_period
)
1814 EMACS_TIME interval
;
1817 cancel_atimer (poll_timer
);
1819 EMACS_SET_SECS_USECS (interval
, polling_period
, 0);
1820 poll_timer
= start_atimer (ATIMER_CONTINUOUS
, interval
,
1821 poll_for_input
, NULL
);
1824 /* Let the timer's callback function poll for input
1825 if this becomes zero. */
1826 --poll_suppress_count
;
1831 /* Nonzero if we are using polling to handle input asynchronously. */
1834 input_polling_used ()
1836 #ifdef POLL_FOR_INPUT
1837 return read_socket_hook
&& !interrupt_input
;
1843 /* Turn off polling. */
1848 #ifdef POLL_FOR_INPUT
1849 if (read_socket_hook
&& !interrupt_input
)
1850 ++poll_suppress_count
;
1854 /* Set the value of poll_suppress_count to COUNT
1855 and start or stop polling accordingly. */
1858 set_poll_suppress_count (count
)
1861 #ifdef POLL_FOR_INPUT
1862 if (count
== 0 && poll_suppress_count
!= 0)
1864 poll_suppress_count
= 1;
1867 else if (count
!= 0 && poll_suppress_count
== 0)
1871 poll_suppress_count
= count
;
1875 /* Bind polling_period to a value at least N.
1876 But don't decrease it. */
1879 bind_polling_period (n
)
1882 #ifdef POLL_FOR_INPUT
1883 int new = polling_period
;
1888 stop_other_atimers (poll_timer
);
1890 specbind (Qpolling_period
, make_number (new));
1891 /* Start a new alarm with the new period. */
1896 /* Apply the control modifier to CHARACTER. */
1902 /* Save the upper bits here. */
1903 int upper
= c
& ~0177;
1907 /* Everything in the columns containing the upper-case letters
1908 denotes a control character. */
1909 if (c
>= 0100 && c
< 0140)
1913 /* Set the shift modifier for a control char
1914 made from a shifted letter. But only for letters! */
1915 if (oc
>= 'A' && oc
<= 'Z')
1916 c
|= shift_modifier
;
1919 /* The lower-case letters denote control characters too. */
1920 else if (c
>= 'a' && c
<= 'z')
1923 /* Include the bits for control and shift
1924 only if the basic ASCII code can't indicate them. */
1928 /* Replace the high bits. */
1929 c
|= (upper
& ~ctrl_modifier
);
1934 /* Display help echo in the echo area.
1936 HELP a string means display that string, HELP nil means clear the
1937 help echo. If HELP is a function, call it with OBJECT and POS as
1938 arguments; the function should return a help string or nil for
1939 none. For all other types of HELP evaluate it to obtain a string.
1941 WINDOW is the window in which the help was generated, if any.
1942 It is nil if not in a window.
1944 If OBJECT is a buffer, POS is the position in the buffer where the
1945 `help-echo' text property was found.
1947 If OBJECT is an overlay, that overlay has a `help-echo' property,
1948 and POS is the position in the overlay's buffer under the mouse.
1950 If OBJECT is a string (an overlay string or a string displayed with
1951 the `display' property). POS is the position in that string under
1954 OK_TO_IVERWRITE_KEYSTROKE_ECHO non-zero means it's okay if the help
1955 echo overwrites a keystroke echo currently displayed in the echo
1958 Note: this function may only be called with HELP nil or a string
1959 from X code running asynchronously. */
1962 show_help_echo (help
, window
, object
, pos
, ok_to_overwrite_keystroke_echo
)
1963 Lisp_Object help
, window
, object
, pos
;
1964 int ok_to_overwrite_keystroke_echo
;
1966 if (!NILP (help
) && !STRINGP (help
))
1968 if (FUNCTIONP (help
))
1970 Lisp_Object args
[4];
1975 help
= safe_call (4, args
);
1978 help
= safe_eval (help
);
1980 if (!STRINGP (help
))
1984 if (STRINGP (help
) || NILP (help
))
1986 if (!NILP (Vshow_help_function
))
1987 call1 (Vshow_help_function
, help
);
1988 else if (/* Don't overwrite minibuffer contents. */
1989 !MINI_WINDOW_P (XWINDOW (selected_window
))
1990 /* Don't overwrite a keystroke echo. */
1991 && (NILP (echo_message_buffer
)
1992 || ok_to_overwrite_keystroke_echo
)
1993 /* Don't overwrite a prompt. */
1994 && !cursor_in_echo_area
)
1998 int count
= specpdl_ptr
- specpdl
;
1999 specbind (Qmessage_truncate_lines
, Qt
);
2000 message3_nolog (help
, XSTRING (help
)->size
,
2001 STRING_MULTIBYTE (help
));
2002 unbind_to (count
, Qnil
);
2008 help_echo_showing_p
= STRINGP (help
);
2014 /* Input of single characters from keyboard */
2016 Lisp_Object
print_help ();
2017 static Lisp_Object
kbd_buffer_get_event ();
2018 static void record_char ();
2021 static jmp_buf wrong_kboard_jmpbuf
;
2024 /* read a character from the keyboard; call the redisplay if needed */
2025 /* commandflag 0 means do not do auto-saving, but do do redisplay.
2026 -1 means do not do redisplay, but do do autosaving.
2029 /* The arguments MAPS and NMAPS are for menu prompting.
2030 MAPS is an array of keymaps; NMAPS is the length of MAPS.
2032 PREV_EVENT is the previous input event, or nil if we are reading
2033 the first event of a key sequence (or not reading a key sequence).
2034 If PREV_EVENT is t, that is a "magic" value that says
2035 not to run input methods, but in other respects to act as if
2036 not reading a key sequence.
2038 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
2039 if we used a mouse menu to read the input, or zero otherwise. If
2040 USED_MOUSE_MENU is null, we don't dereference it.
2042 Value is t if we showed a menu and the user rejected it. */
2045 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
)
2049 Lisp_Object prev_event
;
2050 int *used_mouse_menu
;
2052 volatile Lisp_Object c
;
2054 jmp_buf local_getcjmp
;
2056 volatile int key_already_recorded
= 0;
2057 Lisp_Object tem
, save
;
2058 volatile Lisp_Object previous_echo_area_message
;
2059 volatile Lisp_Object also_record
;
2060 volatile int reread
;
2061 struct gcpro gcpro1
, gcpro2
;
2065 before_command_key_count
= this_command_key_count
;
2066 before_command_echo_length
= echo_length ();
2068 previous_echo_area_message
= Qnil
;
2070 GCPRO2 (c
, previous_echo_area_message
);
2075 if (CONSP (Vunread_post_input_method_events
))
2077 c
= XCAR (Vunread_post_input_method_events
);
2078 Vunread_post_input_method_events
2079 = XCDR (Vunread_post_input_method_events
);
2081 /* Undo what read_char_x_menu_prompt did when it unread
2082 additional keys returned by Fx_popup_menu. */
2084 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
)))
2092 if (unread_command_char
!= -1)
2094 XSETINT (c
, unread_command_char
);
2095 unread_command_char
= -1;
2101 if (CONSP (Vunread_command_events
))
2103 c
= XCAR (Vunread_command_events
);
2104 Vunread_command_events
= XCDR (Vunread_command_events
);
2106 /* Undo what read_char_x_menu_prompt did when it unread
2107 additional keys returned by Fx_popup_menu. */
2109 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
)))
2114 goto reread_for_input_method
;
2117 if (CONSP (Vunread_input_method_events
))
2119 c
= XCAR (Vunread_input_method_events
);
2120 Vunread_input_method_events
= XCDR (Vunread_input_method_events
);
2122 /* Undo what read_char_x_menu_prompt did when it unread
2123 additional keys returned by Fx_popup_menu. */
2125 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
)))
2129 goto reread_for_input_method
;
2132 /* If there is no function key translated before
2133 reset-this-command-lengths takes effect, forget about it. */
2134 before_command_restore_flag
= 0;
2136 if (!NILP (Vexecuting_macro
))
2138 /* We set this to Qmacro; since that's not a frame, nobody will
2139 try to switch frames on us, and the selected window will
2142 Since this event came from a macro, it would be misleading to
2143 leave internal_last_event_frame set to wherever the last
2144 real event came from. Normally, a switch-frame event selects
2145 internal_last_event_frame after each command is read, but
2146 events read from a macro should never cause a new frame to be
2148 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
2150 /* Exit the macro if we are at the end.
2151 Also, some things replace the macro with t
2152 to force an early exit. */
2153 if (EQ (Vexecuting_macro
, Qt
)
2154 || executing_macro_index
>= XFASTINT (Flength (Vexecuting_macro
)))
2160 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
2161 if (STRINGP (Vexecuting_macro
)
2162 && (XINT (c
) & 0x80))
2163 XSETFASTINT (c
, CHAR_META
| (XINT (c
) & ~0x80));
2165 executing_macro_index
++;
2170 if (!NILP (unread_switch_frame
))
2172 c
= unread_switch_frame
;
2173 unread_switch_frame
= Qnil
;
2175 /* This event should make it into this_command_keys, and get echoed
2176 again, so we do not set `reread'. */
2180 /* if redisplay was requested */
2181 if (commandflag
>= 0)
2183 /* If there is pending input, process any events which are not
2184 user-visible, such as X selection_request events. */
2186 || detect_input_pending_run_timers (0))
2187 swallow_events (0); /* may clear input_pending */
2189 /* Redisplay if no pending input. */
2190 while (!input_pending
)
2192 if (help_echo_showing_p
&& !EQ (selected_window
, minibuf_window
))
2193 redisplay_preserve_echo_area ();
2198 /* Normal case: no input arrived during redisplay. */
2201 /* Input arrived and pre-empted redisplay.
2202 Process any events which are not user-visible. */
2204 /* If that cleared input_pending, try again to redisplay. */
2208 /* Message turns off echoing unless more keystrokes turn it on again.
2210 The code in 20.x for the condition was
2212 1. echo_area_glyphs && *echo_area_glyphs
2213 2. && echo_area_glyphs != current_kboard->echobuf
2214 3. && ok_to_echo_at_next_pause != echo_area_glyphs
2216 (1) means there's a current message displayed
2218 (2) means it's not the message from echoing from the current
2221 (3) There's only one place in 20.x where ok_to_echo_at_next_pause
2222 is set to a non-null value. This is done in read_char and it is
2223 set to echo_area_glyphs after a call to echo_char. That means
2224 ok_to_echo_at_next_pause is either null or
2225 current_kboard->echobuf with the appropriate current_kboard at
2228 So, condition (3) means in clear text ok_to_echo_at_next_pause
2229 must be either null, or the current message isn't from echoing at
2230 all, or it's from echoing from a different kboard than the
2233 if (/* There currently something in the echo area */
2234 !NILP (echo_area_buffer
[0])
2235 && (/* And it's either not from echoing. */
2236 !EQ (echo_area_buffer
[0], echo_message_buffer
)
2237 /* Or it's an echo from a different kboard. */
2238 || echo_kboard
!= current_kboard
2239 /* Or we explicitly allow overwriting whatever there is. */
2240 || ok_to_echo_at_next_pause
== NULL
))
2245 /* Try reading a character via menu prompting in the minibuf.
2246 Try this before the sit-for, because the sit-for
2247 would do the wrong thing if we are supposed to do
2248 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
2249 after a mouse event so don't try a minibuf menu. */
2251 if (nmaps
> 0 && INTERACTIVE
2252 && !NILP (prev_event
) && ! EVENT_HAS_PARAMETERS (prev_event
)
2253 /* Don't bring up a menu if we already have another event. */
2254 && NILP (Vunread_command_events
)
2255 && unread_command_char
< 0
2256 && !detect_input_pending_run_timers (0))
2258 c
= read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
);
2261 key_already_recorded
= 1;
2266 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet.
2267 We will do that below, temporarily for short sections of code,
2268 when appropriate. local_getcjmp must be in effect
2269 around any call to sit_for or kbd_buffer_get_event;
2270 it *must not* be in effect when we call redisplay. */
2272 if (_setjmp (local_getcjmp
))
2274 XSETINT (c
, quit_char
);
2275 internal_last_event_frame
= selected_frame
;
2276 Vlast_event_frame
= internal_last_event_frame
;
2277 /* If we report the quit char as an event,
2278 don't do so more than once. */
2279 if (!NILP (Vinhibit_quit
))
2284 KBOARD
*kb
= FRAME_KBOARD (XFRAME (selected_frame
));
2285 if (kb
!= current_kboard
)
2287 Lisp_Object
*tailp
= &kb
->kbd_queue
;
2288 /* We shouldn't get here if we were in single-kboard mode! */
2291 while (CONSP (*tailp
))
2292 tailp
= &XCDR (*tailp
);
2295 *tailp
= Fcons (c
, Qnil
);
2296 kb
->kbd_queue_has_data
= 1;
2297 current_kboard
= kb
;
2298 /* This is going to exit from read_char
2299 so we had better get rid of this frame's stuff. */
2301 longjmp (wrong_kboard_jmpbuf
, 1);
2308 timer_start_idle ();
2310 /* If in middle of key sequence and minibuffer not active,
2311 start echoing if enough time elapses. */
2313 if (minibuf_level
== 0
2314 && !current_kboard
->immediate_echo
2315 && this_command_key_count
> 0
2317 && (FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
2318 && NILP (Fzerop (Vecho_keystrokes
))
2319 && (/* No message. */
2320 NILP (echo_area_buffer
[0])
2321 /* Or empty message. */
2322 || (BUF_BEG (XBUFFER (echo_area_buffer
[0]))
2323 == BUF_Z (XBUFFER (echo_area_buffer
[0])))
2324 /* Or already echoing from same kboard. */
2325 || (echo_kboard
&& ok_to_echo_at_next_pause
== echo_kboard
)
2326 /* Or not echoing before and echoing allowed. */
2327 || (!echo_kboard
&& ok_to_echo_at_next_pause
)))
2331 /* After a mouse event, start echoing right away.
2332 This is because we are probably about to display a menu,
2333 and we don't want to delay before doing so. */
2334 if (EVENT_HAS_PARAMETERS (prev_event
))
2339 double duration
= extract_float (Vecho_keystrokes
);
2340 sec
= (int) duration
;
2341 usec
= (duration
- sec
) * 1000000;
2342 save_getcjmp (save_jump
);
2343 restore_getcjmp (local_getcjmp
);
2344 tem0
= sit_for (sec
, usec
, 1, 1, 0);
2345 restore_getcjmp (save_jump
);
2347 && ! CONSP (Vunread_command_events
))
2352 /* Maybe auto save due to number of keystrokes. */
2354 if (commandflag
!= 0
2355 && auto_save_interval
> 0
2356 && num_nonmacro_input_events
- last_auto_save
> max (auto_save_interval
, 20)
2357 && !detect_input_pending_run_timers (0))
2359 Fdo_auto_save (Qnil
, Qnil
);
2360 /* Hooks can actually change some buffers in auto save. */
2364 /* Try reading using an X menu.
2365 This is never confused with reading using the minibuf
2366 because the recursive call of read_char in read_char_minibuf_menu_prompt
2367 does not pass on any keymaps. */
2369 if (nmaps
> 0 && INTERACTIVE
2370 && !NILP (prev_event
)
2371 && EVENT_HAS_PARAMETERS (prev_event
)
2372 && !EQ (XCAR (prev_event
), Qmenu_bar
)
2373 && !EQ (XCAR (prev_event
), Qtool_bar
)
2374 /* Don't bring up a menu if we already have another event. */
2375 && NILP (Vunread_command_events
)
2376 && unread_command_char
< 0)
2378 c
= read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
2380 /* Now that we have read an event, Emacs is not idle. */
2386 /* Maybe autosave and/or garbage collect due to idleness. */
2388 if (INTERACTIVE
&& NILP (c
))
2390 int delay_level
, buffer_size
;
2392 /* Slow down auto saves logarithmically in size of current buffer,
2393 and garbage collect while we're at it. */
2394 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
2395 last_non_minibuf_size
= Z
- BEG
;
2396 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
2398 while (buffer_size
> 64)
2399 delay_level
++, buffer_size
-= buffer_size
>> 2;
2400 if (delay_level
< 4) delay_level
= 4;
2401 /* delay_level is 4 for files under around 50k, 7 at 100k,
2402 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
2404 /* Auto save if enough time goes by without input. */
2405 if (commandflag
!= 0
2406 && num_nonmacro_input_events
> last_auto_save
2407 && INTEGERP (Vauto_save_timeout
)
2408 && XINT (Vauto_save_timeout
) > 0)
2412 save_getcjmp (save_jump
);
2413 restore_getcjmp (local_getcjmp
);
2414 tem0
= sit_for (delay_level
* XFASTINT (Vauto_save_timeout
) / 4,
2416 restore_getcjmp (save_jump
);
2419 && ! CONSP (Vunread_command_events
))
2421 Fdo_auto_save (Qnil
, Qnil
);
2423 /* If we have auto-saved and there is still no input
2424 available, garbage collect if there has been enough
2425 consing going on to make it worthwhile. */
2426 if (!detect_input_pending_run_timers (0)
2427 && consing_since_gc
> gc_cons_threshold
/ 2)
2428 Fgarbage_collect ();
2435 /* If this has become non-nil here, it has been set by a timer
2436 or sentinel or filter. */
2437 if (CONSP (Vunread_command_events
))
2439 c
= XCAR (Vunread_command_events
);
2440 Vunread_command_events
= XCDR (Vunread_command_events
);
2443 /* Read something from current KBOARD's side queue, if possible. */
2447 if (current_kboard
->kbd_queue_has_data
)
2449 if (!CONSP (current_kboard
->kbd_queue
))
2451 c
= XCAR (current_kboard
->kbd_queue
);
2452 current_kboard
->kbd_queue
2453 = XCDR (current_kboard
->kbd_queue
);
2454 if (NILP (current_kboard
->kbd_queue
))
2455 current_kboard
->kbd_queue_has_data
= 0;
2456 input_pending
= readable_events (0);
2457 if (EVENT_HAS_PARAMETERS (c
)
2458 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qswitch_frame
))
2459 internal_last_event_frame
= XCAR (XCDR (c
));
2460 Vlast_event_frame
= internal_last_event_frame
;
2465 /* If current_kboard's side queue is empty check the other kboards.
2466 If one of them has data that we have not yet seen here,
2467 switch to it and process the data waiting for it.
2469 Note: if the events queued up for another kboard
2470 have already been seen here, and therefore are not a complete command,
2471 the kbd_queue_has_data field is 0, so we skip that kboard here.
2472 That's to avoid an infinite loop switching between kboards here. */
2473 if (NILP (c
) && !single_kboard
)
2476 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2477 if (kb
->kbd_queue_has_data
)
2479 current_kboard
= kb
;
2480 /* This is going to exit from read_char
2481 so we had better get rid of this frame's stuff. */
2483 longjmp (wrong_kboard_jmpbuf
, 1);
2492 /* Finally, we read from the main queue,
2493 and if that gives us something we can't use yet, we put it on the
2494 appropriate side queue and try again. */
2500 /* Actually read a character, waiting if necessary. */
2501 save_getcjmp (save_jump
);
2502 restore_getcjmp (local_getcjmp
);
2503 c
= kbd_buffer_get_event (&kb
, used_mouse_menu
);
2504 restore_getcjmp (save_jump
);
2507 if (! NILP (c
) && (kb
!= current_kboard
))
2509 Lisp_Object
*tailp
= &kb
->kbd_queue
;
2510 while (CONSP (*tailp
))
2511 tailp
= &XCDR (*tailp
);
2514 *tailp
= Fcons (c
, Qnil
);
2515 kb
->kbd_queue_has_data
= 1;
2519 current_kboard
= kb
;
2520 /* This is going to exit from read_char
2521 so we had better get rid of this frame's stuff. */
2523 longjmp (wrong_kboard_jmpbuf
, 1);
2528 /* Terminate Emacs in batch mode if at eof. */
2529 if (noninteractive
&& INTEGERP (c
) && XINT (c
) < 0)
2530 Fkill_emacs (make_number (1));
2534 /* Add in any extra modifiers, where appropriate. */
2535 if ((extra_keyboard_modifiers
& CHAR_CTL
)
2536 || ((extra_keyboard_modifiers
& 0177) < ' '
2537 && (extra_keyboard_modifiers
& 0177) != 0))
2538 XSETINT (c
, make_ctrl_char (XINT (c
)));
2540 /* Transfer any other modifier bits directly from
2541 extra_keyboard_modifiers to c. Ignore the actual character code
2542 in the low 16 bits of extra_keyboard_modifiers. */
2543 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
2554 if (commandflag
>= 0
2555 && !input_pending
&& !detect_input_pending_run_timers (0))
2563 /* Buffer switch events are only for internal wakeups
2564 so don't show them to the user.
2565 Also, don't record a key if we already did. */
2566 if (BUFFERP (c
) || key_already_recorded
)
2569 /* Process special events within read_char
2570 and loop around to read another event. */
2573 tem
= access_keymap (get_keymap_1 (Vspecial_event_map
, 0, 0), c
, 0, 0, 1);
2578 int was_locked
= single_kboard
;
2580 last_input_char
= c
;
2581 Fcommand_execute (tem
, Qnil
, Fvector (1, &last_input_char
), Qt
);
2583 /* Resume allowing input from any kboard, if that was true before. */
2585 any_kboard_state ();
2590 /* Handle things that only apply to characters. */
2593 /* If kbd_buffer_get_event gave us an EOF, return that. */
2597 if ((STRINGP (Vkeyboard_translate_table
)
2598 && XSTRING (Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
2599 || (VECTORP (Vkeyboard_translate_table
)
2600 && XVECTOR (Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
2601 || (CHAR_TABLE_P (Vkeyboard_translate_table
)
2602 && CHAR_TABLE_ORDINARY_SLOTS
> (unsigned) XFASTINT (c
)))
2605 d
= Faref (Vkeyboard_translate_table
, c
);
2606 /* nil in keyboard-translate-table means no translation. */
2612 /* If this event is a mouse click in the menu bar,
2613 return just menu-bar for now. Modify the mouse click event
2614 so we won't do this twice, then queue it up. */
2615 if (EVENT_HAS_PARAMETERS (c
)
2617 && CONSP (EVENT_START (c
))
2618 && CONSP (XCDR (EVENT_START (c
))))
2622 posn
= POSN_BUFFER_POSN (EVENT_START (c
));
2623 /* Handle menu-bar events:
2624 insert the dummy prefix event `menu-bar'. */
2625 if (EQ (posn
, Qmenu_bar
) || EQ (posn
, Qtool_bar
))
2627 /* Change menu-bar to (menu-bar) as the event "position". */
2628 POSN_BUFFER_POSN (EVENT_START (c
)) = Fcons (posn
, Qnil
);
2631 Vunread_command_events
= Fcons (c
, Vunread_command_events
);
2636 /* Store these characters into recent_keys, the dribble file if any,
2637 and the keyboard macro being defined, if any. */
2639 if (! NILP (also_record
))
2640 record_char (also_record
);
2642 /* Wipe the echo area.
2643 But first, if we are about to use an input method,
2644 save the echo area contents for it to refer to. */
2646 && ! NILP (Vinput_method_function
)
2647 && (unsigned) XINT (c
) >= ' '
2648 && (unsigned) XINT (c
) != 127
2649 && (unsigned) XINT (c
) < 256)
2651 previous_echo_area_message
= Fcurrent_message ();
2652 Vinput_method_previous_message
= previous_echo_area_message
;
2655 /* Now wipe the echo area, except for help events which do their
2656 own stuff with the echo area. */
2657 if (!CONSP (c
) || !(EQ (Qhelp_echo
, XCAR (c
))))
2659 if (!NILP (echo_area_buffer
[0]))
2660 safe_run_hooks (Qecho_area_clear_hook
);
2661 clear_message (1, 0);
2664 reread_for_input_method
:
2666 /* Pass this to the input method, if appropriate. */
2668 && ! NILP (Vinput_method_function
)
2669 /* Don't run the input method within a key sequence,
2670 after the first event of the key sequence. */
2671 && NILP (prev_event
)
2672 && (unsigned) XINT (c
) >= ' '
2673 && (unsigned) XINT (c
) != 127
2674 && (unsigned) XINT (c
) < 256)
2678 struct gcpro gcpro1
;
2679 int count
= specpdl_ptr
- specpdl
;
2681 /* Save the echo status. */
2682 int saved_immediate_echo
= current_kboard
->immediate_echo
;
2683 struct kboard
*saved_ok_to_echo
= ok_to_echo_at_next_pause
;
2684 int saved_echo_after_prompt
= current_kboard
->echo_after_prompt
;
2686 if (before_command_restore_flag
)
2688 this_command_key_count
= before_command_key_count_1
;
2689 if (this_command_key_count
< this_single_command_key_start
)
2690 this_single_command_key_start
= this_command_key_count
;
2691 echo_truncate (before_command_echo_length_1
);
2692 before_command_restore_flag
= 0;
2695 /* Save the this_command_keys status. */
2696 key_count
= this_command_key_count
;
2699 keys
= Fcopy_sequence (this_command_keys
);
2704 /* Clear out this_command_keys. */
2705 this_command_key_count
= 0;
2707 /* Now wipe the echo area. */
2708 if (!NILP (echo_area_buffer
[0]))
2709 safe_run_hooks (Qecho_area_clear_hook
);
2710 clear_message (1, 0);
2713 /* If we are not reading a key sequence,
2714 never use the echo area. */
2717 specbind (Qinput_method_use_echo_area
, Qt
);
2720 /* Call the input method. */
2721 tem
= call1 (Vinput_method_function
, c
);
2723 tem
= unbind_to (count
, tem
);
2725 /* Restore the saved echoing state
2726 and this_command_keys state. */
2727 this_command_key_count
= key_count
;
2729 this_command_keys
= keys
;
2732 ok_to_echo_at_next_pause
= saved_ok_to_echo
;
2733 current_kboard
->echo_after_prompt
= saved_echo_after_prompt
;
2734 if (saved_immediate_echo
)
2739 /* The input method can return no events. */
2742 /* Bring back the previous message, if any. */
2743 if (! NILP (previous_echo_area_message
))
2744 message_with_string ("%s", previous_echo_area_message
, 0);
2747 /* It returned one event or more. */
2749 Vunread_post_input_method_events
2750 = nconc2 (XCDR (tem
), Vunread_post_input_method_events
);
2755 /* Display help if not echoing. */
2756 if (CONSP (c
) && EQ (XCAR (c
), Qhelp_echo
))
2758 /* (help-echo FRAME HELP WINDOW OBJECT POS). */
2759 Lisp_Object help
, object
, position
, window
;
2760 help
= Fnth (make_number (2), c
);
2761 window
= Fnth (make_number (3), c
);
2762 object
= Fnth (make_number (4), c
);
2763 position
= Fnth (make_number (5), c
);
2764 show_help_echo (help
, window
, object
, position
, 0);
2768 if (this_command_key_count
== 0 || ! reread
)
2770 before_command_key_count
= this_command_key_count
;
2771 before_command_echo_length
= echo_length ();
2773 /* Don't echo mouse motion events. */
2774 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
2775 && NILP (Fzerop (Vecho_keystrokes
))
2776 && ! (EVENT_HAS_PARAMETERS (c
)
2777 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
2780 if (! NILP (also_record
))
2781 echo_char (also_record
);
2782 /* Once we reread a character, echoing can happen
2783 the next time we pause to read a new one. */
2784 ok_to_echo_at_next_pause
= current_kboard
;
2787 /* Record this character as part of the current key. */
2788 add_command_key (c
);
2789 if (! NILP (also_record
))
2790 add_command_key (also_record
);
2793 last_input_char
= c
;
2796 /* Process the help character specially if enabled */
2797 if (!NILP (Vhelp_form
) && help_char_p (c
))
2800 count
= specpdl_ptr
- specpdl
;
2802 record_unwind_protect (Fset_window_configuration
,
2803 Fcurrent_window_configuration (Qnil
));
2805 tem0
= Feval (Vhelp_form
);
2807 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
2811 c
= read_char (0, 0, 0, Qnil
, 0);
2812 while (BUFFERP (c
));
2813 /* Remove the help from the frame */
2814 unbind_to (count
, Qnil
);
2817 if (EQ (c
, make_number (040)))
2821 c
= read_char (0, 0, 0, Qnil
, 0);
2822 while (BUFFERP (c
));
2829 /* Record a key that came from a mouse menu.
2830 Record it for echoing, for this-command-keys, and so on. */
2836 /* Wipe the echo area. */
2837 clear_message (1, 0);
2841 before_command_key_count
= this_command_key_count
;
2842 before_command_echo_length
= echo_length ();
2844 /* Don't echo mouse motion events. */
2845 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
2846 && NILP (Fzerop (Vecho_keystrokes
)))
2850 /* Once we reread a character, echoing can happen
2851 the next time we pause to read a new one. */
2852 ok_to_echo_at_next_pause
= 0;
2855 /* Record this character as part of the current key. */
2856 add_command_key (c
);
2858 /* Re-reading in the middle of a command */
2859 last_input_char
= c
;
2863 /* Return 1 if should recognize C as "the help character". */
2871 if (EQ (c
, Vhelp_char
))
2873 for (tail
= Vhelp_event_list
; CONSP (tail
); tail
= XCDR (tail
))
2874 if (EQ (c
, XCAR (tail
)))
2879 /* Record the input event C in various ways. */
2886 XVECTOR (recent_keys
)->contents
[recent_keys_index
] = c
;
2887 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
2888 recent_keys_index
= 0;
2890 /* Write c to the dribble file. If c is a lispy event, write
2891 the event's symbol to the dribble file, in <brackets>. Bleaugh.
2892 If you, dear reader, have a better idea, you've got the source. :-) */
2897 if (XUINT (c
) < 0x100)
2898 putc (XINT (c
), dribble
);
2900 fprintf (dribble
, " 0x%x", (int) XUINT (c
));
2904 Lisp_Object dribblee
;
2906 /* If it's a structured event, take the event header. */
2907 dribblee
= EVENT_HEAD (c
);
2909 if (SYMBOLP (dribblee
))
2911 putc ('<', dribble
);
2912 fwrite (XSYMBOL (dribblee
)->name
->data
, sizeof (char),
2913 STRING_BYTES (XSYMBOL (dribblee
)->name
),
2915 putc ('>', dribble
);
2922 store_kbd_macro_char (c
);
2924 num_nonmacro_input_events
++;
2931 struct buffer
*old
= current_buffer
;
2932 Fprinc (object
, Qnil
);
2933 set_buffer_internal (XBUFFER (Vstandard_output
));
2934 call0 (intern ("help-mode"));
2935 set_buffer_internal (old
);
2939 /* Copy out or in the info on where C-g should throw to.
2940 This is used when running Lisp code from within get_char,
2941 in case get_char is called recursively.
2942 See read_process_output. */
2948 bcopy (getcjmp
, temp
, sizeof getcjmp
);
2952 restore_getcjmp (temp
)
2955 bcopy (temp
, getcjmp
, sizeof getcjmp
);
2960 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
2961 of this function. */
2964 tracking_off (old_value
)
2965 Lisp_Object old_value
;
2967 do_mouse_tracking
= old_value
;
2968 if (NILP (old_value
))
2970 /* Redisplay may have been preempted because there was input
2971 available, and it assumes it will be called again after the
2972 input has been processed. If the only input available was
2973 the sort that we have just disabled, then we need to call
2975 if (!readable_events (1))
2977 redisplay_preserve_echo_area ();
2978 get_input_pending (&input_pending
, 1);
2984 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
2985 "Evaluate BODY with mouse movement events enabled.\n\
2986 Within a `track-mouse' form, mouse motion generates input events that\n\
2987 you can read with `read-event'.\n\
2988 Normally, mouse motion is ignored.")
2992 int count
= specpdl_ptr
- specpdl
;
2995 record_unwind_protect (tracking_off
, do_mouse_tracking
);
2997 do_mouse_tracking
= Qt
;
2999 val
= Fprogn (args
);
3000 return unbind_to (count
, val
);
3003 /* If mouse has moved on some frame, return one of those frames.
3004 Return 0 otherwise. */
3009 Lisp_Object tail
, frame
;
3011 FOR_EACH_FRAME (tail
, frame
)
3013 if (XFRAME (frame
)->mouse_moved
)
3014 return XFRAME (frame
);
3020 #endif /* HAVE_MOUSE */
3022 /* Low level keyboard/mouse input.
3023 kbd_buffer_store_event places events in kbd_buffer, and
3024 kbd_buffer_get_event retrieves them. */
3026 /* Return true iff there are any events in the queue that read-char
3027 would return. If this returns false, a read-char would block. */
3029 readable_events (do_timers_now
)
3033 timer_check (do_timers_now
);
3035 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3038 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
3043 if (current_kboard
->kbd_queue_has_data
)
3049 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
3050 if (kb
->kbd_queue_has_data
)
3056 /* Set this for debugging, to have a way to get out */
3061 event_to_kboard (event
)
3062 struct input_event
*event
;
3065 frame
= event
->frame_or_window
;
3067 frame
= XCAR (frame
);
3068 else if (WINDOWP (frame
))
3069 frame
= WINDOW_FRAME (XWINDOW (frame
));
3071 /* There are still some events that don't set this field.
3072 For now, just ignore the problem.
3073 Also ignore dead frames here. */
3074 if (!FRAMEP (frame
) || !FRAME_LIVE_P (XFRAME (frame
)))
3077 return FRAME_KBOARD (XFRAME (frame
));
3081 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
3084 kbd_buffer_store_event (event
)
3085 register struct input_event
*event
;
3087 if (event
->kind
== no_event
)
3090 if (event
->kind
== ascii_keystroke
)
3092 register int c
= event
->code
& 0377;
3094 if (event
->modifiers
& ctrl_modifier
)
3095 c
= make_ctrl_char (c
);
3097 c
|= (event
->modifiers
3098 & (meta_modifier
| alt_modifier
3099 | hyper_modifier
| super_modifier
));
3103 extern SIGTYPE
interrupt_signal ();
3106 struct input_event
*sp
;
3109 && (kb
= FRAME_KBOARD (XFRAME (event
->frame_or_window
)),
3110 kb
!= current_kboard
))
3113 = Fcons (make_lispy_switch_frame (event
->frame_or_window
),
3114 Fcons (make_number (c
), Qnil
));
3115 kb
->kbd_queue_has_data
= 1;
3116 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
3118 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3121 if (event_to_kboard (sp
) == kb
)
3123 sp
->kind
= no_event
;
3124 sp
->frame_or_window
= Qnil
;
3132 /* If this results in a quit_char being returned to Emacs as
3133 input, set Vlast_event_frame properly. If this doesn't
3134 get returned to Emacs as an event, the next event read
3135 will set Vlast_event_frame again, so this is safe to do. */
3139 focus
= FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
3141 focus
= event
->frame_or_window
;
3142 internal_last_event_frame
= focus
;
3143 Vlast_event_frame
= focus
;
3146 last_event_timestamp
= event
->timestamp
;
3147 interrupt_signal ();
3151 if (c
&& c
== stop_character
)
3157 /* Don't insert two buffer_switch_event's in a row.
3158 Just ignore the second one. */
3159 else if (event
->kind
== buffer_switch_event
3160 && kbd_fetch_ptr
!= kbd_store_ptr
3161 && kbd_store_ptr
->kind
== buffer_switch_event
)
3164 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
3165 kbd_store_ptr
= kbd_buffer
;
3167 /* Don't let the very last slot in the buffer become full,
3168 since that would make the two pointers equal,
3169 and that is indistinguishable from an empty buffer.
3170 Discard the event if it would fill the last slot. */
3171 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
3175 #if 0 /* The selection_request_event case looks bogus, and it's error
3176 prone to assign individual members for other events, in case
3177 the input_event structure is changed. --2000-07-13, gerd. */
3178 struct input_event
*sp
= kbd_store_ptr
;
3179 sp
->kind
= event
->kind
;
3180 if (event
->kind
== selection_request_event
)
3182 /* We must not use the ordinary copying code for this case,
3183 since `part' is an enum and copying it might not copy enough
3185 bcopy (event
, (char *) sp
, sizeof (*event
));
3190 sp
->code
= event
->code
;
3191 sp
->part
= event
->part
;
3192 sp
->frame_or_window
= event
->frame_or_window
;
3193 sp
->arg
= event
->arg
;
3194 sp
->modifiers
= event
->modifiers
;
3197 sp
->timestamp
= event
->timestamp
;
3200 *kbd_store_ptr
= *event
;
3203 idx
= 2 * (kbd_store_ptr
- kbd_buffer
);
3204 ASET (kbd_buffer_gcpro
, idx
, event
->frame_or_window
);
3205 ASET (kbd_buffer_gcpro
, idx
+ 1, event
->arg
);
3211 /* Generate HELP_EVENT input_events in BUFP which has room for
3212 SIZE events. If there's not enough room in BUFP, ignore this
3215 HELP is the help form.
3217 FRAME is the frame on which the help is generated. OBJECT is the
3218 Lisp object where the help was found (a buffer, a string, an
3219 overlay, or nil if neither from a string nor from a buffer. POS is
3220 the position within OBJECT where the help was found.
3222 Value is the number of input_events generated. */
3225 gen_help_event (bufp
, size
, help
, frame
, window
, object
, pos
)
3226 struct input_event
*bufp
;
3228 Lisp_Object help
, frame
, object
, window
;
3231 int nevents_stored
= 0;
3235 bufp
->kind
= HELP_EVENT
;
3236 bufp
->frame_or_window
= frame
;
3238 bufp
->x
= make_number (pos
);
3242 bufp
->kind
= HELP_EVENT
;
3243 bufp
->frame_or_window
= WINDOWP (window
) ? window
: frame
;
3249 return nevents_stored
;
3253 /* Store HELP_EVENTs for HELP on FRAME in the input queue. */
3256 kbd_buffer_store_help_event (frame
, help
)
3257 Lisp_Object frame
, help
;
3259 struct input_event event
;
3261 event
.kind
= HELP_EVENT
;
3262 event
.frame_or_window
= frame
;
3264 event
.x
= make_number (0);
3266 kbd_buffer_store_event (&event
);
3268 event
.kind
= HELP_EVENT
;
3269 event
.frame_or_window
= frame
;
3271 event
.x
= make_number (0);
3273 kbd_buffer_store_event (&event
);
3277 /* Discard any mouse events in the event buffer by setting them to
3280 discard_mouse_events ()
3282 struct input_event
*sp
;
3283 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
3285 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3288 if (sp
->kind
== mouse_click
3290 || sp
->kind
== w32_scroll_bar_click
3292 || sp
->kind
== scroll_bar_click
)
3294 sp
->kind
= no_event
;
3300 /* Return non-zero if there are any real events waiting in the event
3301 buffer, not counting `no_event's.
3303 If DISCARD is non-zero, discard no_event events at the front of
3304 the input queue, possibly leaving the input queue empty if there
3305 are no real input events. */
3308 kbd_buffer_events_waiting (discard
)
3311 struct input_event
*sp
;
3313 for (sp
= kbd_fetch_ptr
;
3314 sp
!= kbd_store_ptr
&& sp
->kind
== no_event
;
3317 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3324 return sp
!= kbd_store_ptr
&& sp
->kind
!= no_event
;
3328 /* Clear input event EVENT. */
3332 struct input_event
*event
;
3334 int idx
= 2 * (event
- kbd_buffer
);
3335 ASET (kbd_buffer_gcpro
, idx
, Qnil
);
3336 ASET (kbd_buffer_gcpro
, idx
+ 1, Qnil
);
3337 event
->kind
= no_event
;
3341 /* Read one event from the event buffer, waiting if necessary.
3342 The value is a Lisp object representing the event.
3343 The value is nil for an event that should be ignored,
3344 or that was handled here.
3345 We always read and discard one event. */
3348 kbd_buffer_get_event (kbp
, used_mouse_menu
)
3350 int *used_mouse_menu
;
3359 *kbp
= current_kboard
;
3363 /* Wait until there is input available. */
3366 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3369 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
3373 /* If the quit flag is set, then read_char will return
3374 quit_char, so that counts as "available input." */
3375 if (!NILP (Vquit_flag
))
3376 quit_throw_to_read_char ();
3378 /* One way or another, wait until input is available; then, if
3379 interrupt handlers have not read it, read it now. */
3382 wait_for_kbd_input ();
3384 /* Note SIGIO has been undef'd if FIONREAD is missing. */
3388 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3391 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
3395 Lisp_Object minus_one
;
3397 XSETINT (minus_one
, -1);
3398 wait_reading_process_input (0, 0, minus_one
, 1);
3400 if (!interrupt_input
&& kbd_fetch_ptr
== kbd_store_ptr
)
3401 /* Pass 1 for EXPECT since we just waited to have input. */
3402 read_avail_input (1);
3404 #endif /* not VMS */
3407 if (CONSP (Vunread_command_events
))
3410 first
= XCAR (Vunread_command_events
);
3411 Vunread_command_events
= XCDR (Vunread_command_events
);
3412 *kbp
= current_kboard
;
3416 /* At this point, we know that there is a readable event available
3417 somewhere. If the event queue is empty, then there must be a
3418 mouse movement enabled and available. */
3419 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3421 struct input_event
*event
;
3423 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
3427 last_event_timestamp
= event
->timestamp
;
3430 *kbp
= event_to_kboard (event
);
3432 *kbp
= current_kboard
; /* Better than returning null ptr? */
3434 *kbp
= &the_only_kboard
;
3439 /* These two kinds of events get special handling
3440 and don't actually appear to the command loop.
3441 We return nil for them. */
3442 if (event
->kind
== selection_request_event
)
3445 struct input_event copy
;
3447 /* Remove it from the buffer before processing it,
3448 since otherwise swallow_events will see it
3449 and process it again. */
3451 kbd_fetch_ptr
= event
+ 1;
3452 input_pending
= readable_events (0);
3453 x_handle_selection_request (©
);
3455 /* We're getting selection request events, but we don't have
3461 else if (event
->kind
== selection_clear_event
)
3464 struct input_event copy
;
3466 /* Remove it from the buffer before processing it. */
3468 kbd_fetch_ptr
= event
+ 1;
3469 input_pending
= readable_events (0);
3470 x_handle_selection_clear (©
);
3472 /* We're getting selection request events, but we don't have
3477 #if defined (HAVE_X11) || defined (HAVE_NTGUI)
3478 else if (event
->kind
== delete_window_event
)
3480 /* Make an event (delete-frame (FRAME)). */
3481 obj
= Fcons (event
->frame_or_window
, Qnil
);
3482 obj
= Fcons (Qdelete_frame
, Fcons (obj
, Qnil
));
3483 kbd_fetch_ptr
= event
+ 1;
3485 else if (event
->kind
== iconify_event
)
3487 /* Make an event (iconify-frame (FRAME)). */
3488 obj
= Fcons (event
->frame_or_window
, Qnil
);
3489 obj
= Fcons (Qiconify_frame
, Fcons (obj
, Qnil
));
3490 kbd_fetch_ptr
= event
+ 1;
3492 else if (event
->kind
== deiconify_event
)
3494 /* Make an event (make-frame-visible (FRAME)). */
3495 obj
= Fcons (event
->frame_or_window
, Qnil
);
3496 obj
= Fcons (Qmake_frame_visible
, Fcons (obj
, Qnil
));
3497 kbd_fetch_ptr
= event
+ 1;
3500 else if (event
->kind
== buffer_switch_event
)
3502 /* The value doesn't matter here; only the type is tested. */
3503 XSETBUFFER (obj
, current_buffer
);
3504 kbd_fetch_ptr
= event
+ 1;
3506 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
3507 else if (event
->kind
== menu_bar_activate_event
)
3509 kbd_fetch_ptr
= event
+ 1;
3510 input_pending
= readable_events (0);
3511 if (FRAME_LIVE_P (XFRAME (event
->frame_or_window
)))
3512 x_activate_menubar (XFRAME (event
->frame_or_window
));
3516 else if (event
->kind
== language_change_event
)
3518 /* Make an event (language-change (FRAME CHARSET LCID)). */
3519 obj
= Fcons (event
->modifiers
, Qnil
);
3520 obj
= Fcons (event
->code
, Qnil
);
3521 obj
= Fcons (event
->frame_or_window
, obj
);
3522 obj
= Fcons (Qlanguage_change
, Fcons (obj
, Qnil
));
3523 kbd_fetch_ptr
= event
+ 1;
3526 /* Just discard these, by returning nil.
3527 With MULTI_KBOARD, these events are used as placeholders
3528 when we need to randomly delete events from the queue.
3529 (They shouldn't otherwise be found in the buffer,
3530 but on some machines it appears they do show up
3531 even without MULTI_KBOARD.) */
3532 /* On Windows NT/9X, no_event is used to delete extraneous
3533 mouse events during a popup-menu call. */
3534 else if (event
->kind
== no_event
)
3535 kbd_fetch_ptr
= event
+ 1;
3536 else if (event
->kind
== HELP_EVENT
)
3538 /* There are always two HELP_EVENTs in the input queue. */
3539 Lisp_Object object
, position
, help
, frame
, window
;
3541 xassert (event
->code
== 0);
3542 frame
= event
->frame_or_window
;
3543 object
= event
->arg
;
3544 position
= event
->x
;
3545 clear_event (event
);
3547 kbd_fetch_ptr
= event
+ 1;
3548 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
3551 xassert (event
->code
== 1);
3553 window
= event
->frame_or_window
;
3554 if (!WINDOWP (window
))
3556 obj
= Fcons (Qhelp_echo
,
3557 list5 (frame
, help
, window
, object
, position
));
3558 clear_event (event
);
3559 kbd_fetch_ptr
= event
+ 1;
3561 else if (event
->kind
== FOCUS_IN_EVENT
)
3563 /* Notification of a FocusIn event. The frame receiving the
3564 focus is in event->frame_or_window. Generate a
3565 switch-frame event if necessary. */
3566 Lisp_Object frame
, focus
;
3568 frame
= event
->frame_or_window
;
3569 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
3573 if (!EQ (frame
, internal_last_event_frame
)
3574 && !EQ (frame
, selected_frame
))
3575 obj
= make_lispy_switch_frame (frame
);
3576 internal_last_event_frame
= frame
;
3577 kbd_fetch_ptr
= event
+ 1;
3581 /* If this event is on a different frame, return a switch-frame this
3582 time, and leave the event in the queue for next time. */
3586 frame
= event
->frame_or_window
;
3588 frame
= XCAR (frame
);
3589 else if (WINDOWP (frame
))
3590 frame
= WINDOW_FRAME (XWINDOW (frame
));
3592 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
3596 if (! EQ (frame
, internal_last_event_frame
)
3597 && !EQ (frame
, selected_frame
))
3598 obj
= make_lispy_switch_frame (frame
);
3599 internal_last_event_frame
= frame
;
3601 /* If we didn't decide to make a switch-frame event, go ahead
3602 and build a real event from the queue entry. */
3608 obj
= make_lispy_event (event
);
3610 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
3611 /* If this was a menu selection, then set the flag to inhibit
3612 writing to last_nonmenu_event. Don't do this if the event
3613 we're returning is (menu-bar), though; that indicates the
3614 beginning of the menu sequence, and we might as well leave
3615 that as the `event with parameters' for this selection. */
3617 && !EQ (event
->frame_or_window
, event
->arg
)
3618 && (event
->kind
== MENU_BAR_EVENT
3619 || event
->kind
== TOOL_BAR_EVENT
))
3620 *used_mouse_menu
= 1;
3623 /* Wipe out this event, to catch bugs. */
3624 clear_event (event
);
3625 kbd_fetch_ptr
= event
+ 1;
3630 /* Try generating a mouse motion event. */
3631 else if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
3633 FRAME_PTR f
= some_mouse_moved ();
3634 Lisp_Object bar_window
;
3635 enum scroll_bar_part part
;
3639 *kbp
= current_kboard
;
3640 /* Note that this uses F to determine which display to look at.
3641 If there is no valid info, it does not store anything
3642 so x remains nil. */
3644 (*mouse_position_hook
) (&f
, 0, &bar_window
, &part
, &x
, &y
, &time
);
3648 /* Decide if we should generate a switch-frame event. Don't
3649 generate switch-frame events for motion outside of all Emacs
3655 frame
= FRAME_FOCUS_FRAME (f
);
3657 XSETFRAME (frame
, f
);
3659 if (! EQ (frame
, internal_last_event_frame
)
3660 && !EQ (frame
, selected_frame
))
3661 obj
= make_lispy_switch_frame (frame
);
3662 internal_last_event_frame
= frame
;
3665 /* If we didn't decide to make a switch-frame event, go ahead and
3666 return a mouse-motion event. */
3667 if (!NILP (x
) && NILP (obj
))
3668 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
3670 #endif /* HAVE_MOUSE */
3672 /* We were promised by the above while loop that there was
3673 something for us to read! */
3676 input_pending
= readable_events (0);
3678 Vlast_event_frame
= internal_last_event_frame
;
3683 /* Process any events that are not user-visible,
3684 then return, without reading any user-visible events. */
3687 swallow_events (do_display
)
3692 while (kbd_fetch_ptr
!= kbd_store_ptr
)
3694 struct input_event
*event
;
3696 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
3700 last_event_timestamp
= event
->timestamp
;
3702 /* These two kinds of events get special handling
3703 and don't actually appear to the command loop. */
3704 if (event
->kind
== selection_request_event
)
3707 struct input_event copy
;
3709 /* Remove it from the buffer before processing it,
3710 since otherwise swallow_events called recursively could see it
3711 and process it again. */
3713 kbd_fetch_ptr
= event
+ 1;
3714 input_pending
= readable_events (0);
3715 x_handle_selection_request (©
);
3717 /* We're getting selection request events, but we don't have
3723 else if (event
->kind
== selection_clear_event
)
3726 struct input_event copy
;
3728 /* Remove it from the buffer before processing it, */
3731 kbd_fetch_ptr
= event
+ 1;
3732 input_pending
= readable_events (0);
3733 x_handle_selection_clear (©
);
3735 /* We're getting selection request events, but we don't have
3744 old_timers_run
= timers_run
;
3745 get_input_pending (&input_pending
, 1);
3747 if (timers_run
!= old_timers_run
&& do_display
)
3748 redisplay_preserve_echo_area ();
3751 static EMACS_TIME timer_idleness_start_time
;
3753 /* Record the start of when Emacs is idle,
3754 for the sake of running idle-time timers. */
3761 /* If we are already in the idle state, do nothing. */
3762 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3765 EMACS_GET_TIME (timer_idleness_start_time
);
3767 /* Mark all idle-time timers as once again candidates for running. */
3768 for (timers
= Vtimer_idle_list
; CONSP (timers
); timers
= XCDR (timers
))
3772 timer
= XCAR (timers
);
3774 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3776 XVECTOR (timer
)->contents
[0] = Qnil
;
3780 /* Record that Emacs is no longer idle, so stop running idle-time timers. */
3785 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
3788 /* This is only for debugging. */
3789 struct input_event last_timer_event
;
3791 /* Check whether a timer has fired. To prevent larger problems we simply
3792 disregard elements that are not proper timers. Do not make a circular
3793 timer list for the time being.
3795 Returns the number of seconds to wait until the next timer fires. If a
3796 timer is triggering now, return zero seconds.
3797 If no timer is active, return -1 seconds.
3799 If a timer is ripe, we run it, with quitting turned off.
3801 DO_IT_NOW is now ignored. It used to mean that we should
3802 run the timer directly instead of queueing a timer-event.
3803 Now we always run timers directly. */
3806 timer_check (do_it_now
)
3809 EMACS_TIME nexttime
;
3810 EMACS_TIME now
, idleness_now
;
3811 Lisp_Object timers
, idle_timers
, chosen_timer
;
3812 struct gcpro gcpro1
, gcpro2
, gcpro3
;
3814 EMACS_SET_SECS (nexttime
, -1);
3815 EMACS_SET_USECS (nexttime
, -1);
3817 /* Always consider the ordinary timers. */
3818 timers
= Vtimer_list
;
3819 /* Consider the idle timers only if Emacs is idle. */
3820 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3821 idle_timers
= Vtimer_idle_list
;
3824 chosen_timer
= Qnil
;
3825 GCPRO3 (timers
, idle_timers
, chosen_timer
);
3827 if (CONSP (timers
) || CONSP (idle_timers
))
3829 EMACS_GET_TIME (now
);
3830 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3831 EMACS_SUB_TIME (idleness_now
, now
, timer_idleness_start_time
);
3834 while (CONSP (timers
) || CONSP (idle_timers
))
3836 Lisp_Object
*vector
;
3837 Lisp_Object timer
= Qnil
, idle_timer
= Qnil
;
3838 EMACS_TIME timer_time
, idle_timer_time
;
3839 EMACS_TIME difference
, timer_difference
, idle_timer_difference
;
3841 /* Skip past invalid timers and timers already handled. */
3844 timer
= XCAR (timers
);
3845 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3847 timers
= XCDR (timers
);
3850 vector
= XVECTOR (timer
)->contents
;
3852 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
3853 || !INTEGERP (vector
[3])
3854 || ! NILP (vector
[0]))
3856 timers
= XCDR (timers
);
3860 if (!NILP (idle_timers
))
3862 timer
= XCAR (idle_timers
);
3863 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3865 idle_timers
= XCDR (idle_timers
);
3868 vector
= XVECTOR (timer
)->contents
;
3870 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
3871 || !INTEGERP (vector
[3])
3872 || ! NILP (vector
[0]))
3874 idle_timers
= XCDR (idle_timers
);
3879 /* Set TIMER, TIMER_TIME and TIMER_DIFFERENCE
3880 based on the next ordinary timer.
3881 TIMER_DIFFERENCE is the distance in time from NOW to when
3882 this timer becomes ripe (negative if it's already ripe). */
3885 timer
= XCAR (timers
);
3886 vector
= XVECTOR (timer
)->contents
;
3887 EMACS_SET_SECS (timer_time
,
3888 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
3889 EMACS_SET_USECS (timer_time
, XINT (vector
[3]));
3890 EMACS_SUB_TIME (timer_difference
, timer_time
, now
);
3893 /* Set IDLE_TIMER, IDLE_TIMER_TIME and IDLE_TIMER_DIFFERENCE
3894 based on the next idle timer. */
3895 if (!NILP (idle_timers
))
3897 idle_timer
= XCAR (idle_timers
);
3898 vector
= XVECTOR (idle_timer
)->contents
;
3899 EMACS_SET_SECS (idle_timer_time
,
3900 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
3901 EMACS_SET_USECS (idle_timer_time
, XINT (vector
[3]));
3902 EMACS_SUB_TIME (idle_timer_difference
, idle_timer_time
, idleness_now
);
3905 /* Decide which timer is the next timer,
3906 and set CHOSEN_TIMER, VECTOR and DIFFERENCE accordingly.
3907 Also step down the list where we found that timer. */
3909 if (! NILP (timers
) && ! NILP (idle_timers
))
3912 EMACS_SUB_TIME (temp
, timer_difference
, idle_timer_difference
);
3913 if (EMACS_TIME_NEG_P (temp
))
3915 chosen_timer
= timer
;
3916 timers
= XCDR (timers
);
3917 difference
= timer_difference
;
3921 chosen_timer
= idle_timer
;
3922 idle_timers
= XCDR (idle_timers
);
3923 difference
= idle_timer_difference
;
3926 else if (! NILP (timers
))
3928 chosen_timer
= timer
;
3929 timers
= XCDR (timers
);
3930 difference
= timer_difference
;
3934 chosen_timer
= idle_timer
;
3935 idle_timers
= XCDR (idle_timers
);
3936 difference
= idle_timer_difference
;
3938 vector
= XVECTOR (chosen_timer
)->contents
;
3940 /* If timer is ripe, run it if it hasn't been run. */
3941 if (EMACS_TIME_NEG_P (difference
)
3942 || (EMACS_SECS (difference
) == 0
3943 && EMACS_USECS (difference
) == 0))
3945 if (NILP (vector
[0]))
3947 int was_locked
= single_kboard
;
3948 int count
= specpdl_ptr
- specpdl
;
3950 /* Mark the timer as triggered to prevent problems if the lisp
3951 code fails to reschedule it right. */
3954 specbind (Qinhibit_quit
, Qt
);
3956 call1 (Qtimer_event_handler
, chosen_timer
);
3959 unbind_to (count
, Qnil
);
3961 /* Resume allowing input from any kboard, if that was true before. */
3963 any_kboard_state ();
3965 /* Since we have handled the event,
3966 we don't need to tell the caller to wake up and do it. */
3970 /* When we encounter a timer that is still waiting,
3971 return the amount of time to wait before it is ripe. */
3978 /* No timers are pending in the future. */
3979 /* Return 0 if we generated an event, and -1 if not. */
3984 /* Caches for modify_event_symbol. */
3985 static Lisp_Object accent_key_syms
;
3986 static Lisp_Object func_key_syms
;
3987 static Lisp_Object mouse_syms
;
3989 static Lisp_Object mouse_wheel_syms
;
3991 static Lisp_Object drag_n_drop_syms
;
3993 /* This is a list of keysym codes for special "accent" characters.
3994 It parallels lispy_accent_keys. */
3996 static int lispy_accent_codes
[] =
3998 #ifdef XK_dead_circumflex
4003 #ifdef XK_dead_grave
4008 #ifdef XK_dead_tilde
4013 #ifdef XK_dead_diaeresis
4018 #ifdef XK_dead_macron
4023 #ifdef XK_dead_degree
4028 #ifdef XK_dead_acute
4033 #ifdef XK_dead_cedilla
4038 #ifdef XK_dead_breve
4043 #ifdef XK_dead_ogonek
4048 #ifdef XK_dead_caron
4053 #ifdef XK_dead_doubleacute
4054 XK_dead_doubleacute
,
4058 #ifdef XK_dead_abovedot
4065 /* This is a list of Lisp names for special "accent" characters.
4066 It parallels lispy_accent_codes. */
4068 static char *lispy_accent_keys
[] =
4086 #define FUNCTION_KEY_OFFSET 0x0
4088 char *lispy_function_keys
[] =
4092 0, /* VK_LBUTTON 0x01 */
4093 0, /* VK_RBUTTON 0x02 */
4094 "cancel", /* VK_CANCEL 0x03 */
4095 0, /* VK_MBUTTON 0x04 */
4097 0, 0, 0, /* 0x05 .. 0x07 */
4099 "backspace", /* VK_BACK 0x08 */
4100 "tab", /* VK_TAB 0x09 */
4102 0, 0, /* 0x0A .. 0x0B */
4104 "clear", /* VK_CLEAR 0x0C */
4105 "return", /* VK_RETURN 0x0D */
4107 0, 0, /* 0x0E .. 0x0F */
4109 0, /* VK_SHIFT 0x10 */
4110 0, /* VK_CONTROL 0x11 */
4111 0, /* VK_MENU 0x12 */
4112 "pause", /* VK_PAUSE 0x13 */
4113 "capslock", /* VK_CAPITAL 0x14 */
4115 0, 0, 0, 0, 0, 0, /* 0x15 .. 0x1A */
4117 "escape", /* VK_ESCAPE 0x1B */
4119 0, 0, 0, 0, /* 0x1C .. 0x1F */
4121 0, /* VK_SPACE 0x20 */
4122 "prior", /* VK_PRIOR 0x21 */
4123 "next", /* VK_NEXT 0x22 */
4124 "end", /* VK_END 0x23 */
4125 "home", /* VK_HOME 0x24 */
4126 "left", /* VK_LEFT 0x25 */
4127 "up", /* VK_UP 0x26 */
4128 "right", /* VK_RIGHT 0x27 */
4129 "down", /* VK_DOWN 0x28 */
4130 "select", /* VK_SELECT 0x29 */
4131 "print", /* VK_PRINT 0x2A */
4132 "execute", /* VK_EXECUTE 0x2B */
4133 "snapshot", /* VK_SNAPSHOT 0x2C */
4134 "insert", /* VK_INSERT 0x2D */
4135 "delete", /* VK_DELETE 0x2E */
4136 "help", /* VK_HELP 0x2F */
4138 /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
4140 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4142 0, 0, 0, 0, 0, 0, 0, /* 0x3A .. 0x40 */
4144 /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
4146 0, 0, 0, 0, 0, 0, 0, 0, 0,
4147 0, 0, 0, 0, 0, 0, 0, 0, 0,
4148 0, 0, 0, 0, 0, 0, 0, 0,
4150 "lwindow", /* VK_LWIN 0x5B */
4151 "rwindow", /* VK_RWIN 0x5C */
4152 "apps", /* VK_APPS 0x5D */
4154 0, 0, /* 0x5E .. 0x5F */
4156 "kp-0", /* VK_NUMPAD0 0x60 */
4157 "kp-1", /* VK_NUMPAD1 0x61 */
4158 "kp-2", /* VK_NUMPAD2 0x62 */
4159 "kp-3", /* VK_NUMPAD3 0x63 */
4160 "kp-4", /* VK_NUMPAD4 0x64 */
4161 "kp-5", /* VK_NUMPAD5 0x65 */
4162 "kp-6", /* VK_NUMPAD6 0x66 */
4163 "kp-7", /* VK_NUMPAD7 0x67 */
4164 "kp-8", /* VK_NUMPAD8 0x68 */
4165 "kp-9", /* VK_NUMPAD9 0x69 */
4166 "kp-multiply", /* VK_MULTIPLY 0x6A */
4167 "kp-add", /* VK_ADD 0x6B */
4168 "kp-separator", /* VK_SEPARATOR 0x6C */
4169 "kp-subtract", /* VK_SUBTRACT 0x6D */
4170 "kp-decimal", /* VK_DECIMAL 0x6E */
4171 "kp-divide", /* VK_DIVIDE 0x6F */
4172 "f1", /* VK_F1 0x70 */
4173 "f2", /* VK_F2 0x71 */
4174 "f3", /* VK_F3 0x72 */
4175 "f4", /* VK_F4 0x73 */
4176 "f5", /* VK_F5 0x74 */
4177 "f6", /* VK_F6 0x75 */
4178 "f7", /* VK_F7 0x76 */
4179 "f8", /* VK_F8 0x77 */
4180 "f9", /* VK_F9 0x78 */
4181 "f10", /* VK_F10 0x79 */
4182 "f11", /* VK_F11 0x7A */
4183 "f12", /* VK_F12 0x7B */
4184 "f13", /* VK_F13 0x7C */
4185 "f14", /* VK_F14 0x7D */
4186 "f15", /* VK_F15 0x7E */
4187 "f16", /* VK_F16 0x7F */
4188 "f17", /* VK_F17 0x80 */
4189 "f18", /* VK_F18 0x81 */
4190 "f19", /* VK_F19 0x82 */
4191 "f20", /* VK_F20 0x83 */
4192 "f21", /* VK_F21 0x84 */
4193 "f22", /* VK_F22 0x85 */
4194 "f23", /* VK_F23 0x86 */
4195 "f24", /* VK_F24 0x87 */
4197 0, 0, 0, 0, /* 0x88 .. 0x8B */
4198 0, 0, 0, 0, /* 0x8C .. 0x8F */
4200 "kp-numlock", /* VK_NUMLOCK 0x90 */
4201 "scroll", /* VK_SCROLL 0x91 */
4203 "kp-space", /* VK_NUMPAD_CLEAR 0x92 */
4204 "kp-enter", /* VK_NUMPAD_ENTER 0x93 */
4205 "kp-prior", /* VK_NUMPAD_PRIOR 0x94 */
4206 "kp-next", /* VK_NUMPAD_NEXT 0x95 */
4207 "kp-end", /* VK_NUMPAD_END 0x96 */
4208 "kp-home", /* VK_NUMPAD_HOME 0x97 */
4209 "kp-left", /* VK_NUMPAD_LEFT 0x98 */
4210 "kp-up", /* VK_NUMPAD_UP 0x99 */
4211 "kp-right", /* VK_NUMPAD_RIGHT 0x9A */
4212 "kp-down", /* VK_NUMPAD_DOWN 0x9B */
4213 "kp-insert", /* VK_NUMPAD_INSERT 0x9C */
4214 "kp-delete", /* VK_NUMPAD_DELETE 0x9D */
4216 0, 0, /* 0x9E .. 0x9F */
4219 * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
4220 * Used only as parameters to GetAsyncKeyState and GetKeyState.
4221 * No other API or message will distinguish left and right keys this way.
4225 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4226 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4227 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4228 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4229 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4235 "attn", /* VK_ATTN 0xF6 */
4236 "crsel", /* VK_CRSEL 0xF7 */
4237 "exsel", /* VK_EXSEL 0xF8 */
4238 "ereof", /* VK_EREOF 0xF9 */
4239 "play", /* VK_PLAY 0xFA */
4240 "zoom", /* VK_ZOOM 0xFB */
4241 "noname", /* VK_NONAME 0xFC */
4242 "pa1", /* VK_PA1 0xFD */
4243 "oem_clear", /* VK_OEM_CLEAR 0xFE */
4247 #else /* not HAVE_NTGUI */
4250 static char *lispy_kana_keys
[] =
4252 /* X Keysym value */
4253 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x400 .. 0x40f */
4254 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x410 .. 0x41f */
4255 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x420 .. 0x42f */
4256 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x430 .. 0x43f */
4257 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x440 .. 0x44f */
4258 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x450 .. 0x45f */
4259 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x460 .. 0x46f */
4260 0,0,0,0,0,0,0,0,0,0,0,0,0,0,"overline",0,
4261 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x480 .. 0x48f */
4262 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x490 .. 0x49f */
4263 0, "kana-fullstop", "kana-openingbracket", "kana-closingbracket",
4264 "kana-comma", "kana-conjunctive", "kana-WO", "kana-a",
4265 "kana-i", "kana-u", "kana-e", "kana-o",
4266 "kana-ya", "kana-yu", "kana-yo", "kana-tsu",
4267 "prolongedsound", "kana-A", "kana-I", "kana-U",
4268 "kana-E", "kana-O", "kana-KA", "kana-KI",
4269 "kana-KU", "kana-KE", "kana-KO", "kana-SA",
4270 "kana-SHI", "kana-SU", "kana-SE", "kana-SO",
4271 "kana-TA", "kana-CHI", "kana-TSU", "kana-TE",
4272 "kana-TO", "kana-NA", "kana-NI", "kana-NU",
4273 "kana-NE", "kana-NO", "kana-HA", "kana-HI",
4274 "kana-FU", "kana-HE", "kana-HO", "kana-MA",
4275 "kana-MI", "kana-MU", "kana-ME", "kana-MO",
4276 "kana-YA", "kana-YU", "kana-YO", "kana-RA",
4277 "kana-RI", "kana-RU", "kana-RE", "kana-RO",
4278 "kana-WA", "kana-N", "voicedsound", "semivoicedsound",
4279 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4e0 .. 0x4ef */
4280 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4f0 .. 0x4ff */
4282 #endif /* XK_kana_A */
4284 #define FUNCTION_KEY_OFFSET 0xff00
4286 /* You'll notice that this table is arranged to be conveniently
4287 indexed by X Windows keysym values. */
4288 static char *lispy_function_keys
[] =
4290 /* X Keysym value */
4292 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00...0f */
4293 "backspace", "tab", "linefeed", "clear",
4295 0, 0, 0, "pause", /* 0xff10...1f */
4296 0, 0, 0, 0, 0, 0, 0, "escape",
4298 0, "kanji", "muhenkan", "henkan", /* 0xff20...2f */
4299 "romaji", "hiragana", "katakana", "hiragana-katakana",
4300 "zenkaku", "hankaku", "zenkaku-hankaku", "touroku",
4301 "massyo", "kana-lock", "kana-shift", "eisu-shift",
4302 "eisu-toggle", /* 0xff30...3f */
4303 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4304 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
4306 "home", "left", "up", "right", /* 0xff50 */ /* IsCursorKey */
4307 "down", "prior", "next", "end",
4308 "begin", 0, 0, 0, 0, 0, 0, 0,
4309 "select", /* 0xff60 */ /* IsMiscFunctionKey */
4320 "break", /* 0xff6b */
4323 0, 0, 0, 0, "backtab", 0, 0, 0, /* 0xff70... */
4324 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff78... */
4325 "kp-space", /* 0xff80 */ /* IsKeypadKey */
4326 0, 0, 0, 0, 0, 0, 0, 0,
4327 "kp-tab", /* 0xff89 */
4329 "kp-enter", /* 0xff8d */
4331 "kp-f1", /* 0xff91 */
4335 "kp-home", /* 0xff95 */
4340 "kp-prior", /* kp-page-up */
4341 "kp-next", /* kp-page-down */
4347 0, 0, 0, 0, 0, 0, 0, 0, 0,
4348 "kp-multiply", /* 0xffaa */
4353 "kp-divide", /* 0xffaf */
4354 "kp-0", /* 0xffb0 */
4355 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
4358 "kp-equal", /* 0xffbd */
4359 "f1", /* 0xffbe */ /* IsFunctionKey */
4361 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
4362 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
4363 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
4364 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
4365 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
4366 0, 0, 0, 0, 0, 0, 0, 0,
4367 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
4368 0, 0, 0, 0, 0, 0, 0, "delete"
4371 /* ISO 9995 Function and Modifier Keys; the first byte is 0xFE. */
4372 #define ISO_FUNCTION_KEY_OFFSET 0xfe00
4374 static char *iso_lispy_function_keys
[] =
4376 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe00 */
4377 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe08 */
4378 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe10 */
4379 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe18 */
4380 "iso-lefttab", /* 0xfe20 */
4381 "iso-move-line-up", "iso-move-line-down",
4382 "iso-partial-line-up", "iso-partial-line-down",
4383 "iso-partial-space-left", "iso-partial-space-right",
4384 "iso-set-margin-left", "iso-set-margin-right", /* 0xffe27, 28 */
4385 "iso-release-margin-left", "iso-release-margin-right",
4386 "iso-release-both-margins",
4387 "iso-fast-cursor-left", "iso-fast-cursor-right",
4388 "iso-fast-cursor-up", "iso-fast-cursor-down",
4389 "iso-continuous-underline", "iso-discontinuous-underline", /* 0xfe30, 31 */
4390 "iso-emphasize", "iso-center-object", "iso-enter", /* ... 0xfe34 */
4393 #endif /* not HAVE_NTGUI */
4395 Lisp_Object Vlispy_mouse_stem
;
4398 /* mouse-wheel events are generated by the wheel on devices such as
4399 the MS Intellimouse. The wheel sits in between the left and right
4400 mouse buttons, and is typically used to scroll or zoom the window
4401 underneath the pointer. mouse-wheel events specify the object on
4402 which they operate, and a delta corresponding to the amount and
4403 direction that the wheel is rotated. Clicking the mouse-wheel
4404 generates a mouse-2 event. */
4405 static char *lispy_mouse_wheel_names
[] =
4410 #endif /* WINDOWSNT */
4412 /* drag-n-drop events are generated when a set of selected files are
4413 dragged from another application and dropped onto an Emacs window. */
4414 static char *lispy_drag_n_drop_names
[] =
4419 /* Scroll bar parts. */
4420 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
4421 Lisp_Object Qup
, Qdown
, Qbottom
, Qend_scroll
;
4422 Lisp_Object Qtop
, Qratio
;
4424 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
4425 Lisp_Object
*scroll_bar_parts
[] = {
4426 &Qabove_handle
, &Qhandle
, &Qbelow_handle
,
4427 &Qup
, &Qdown
, &Qtop
, &Qbottom
, &Qend_scroll
, &Qratio
4430 /* User signal events. */
4431 Lisp_Object Qusr1_signal
, Qusr2_signal
;
4433 Lisp_Object
*lispy_user_signals
[] =
4435 &Qusr1_signal
, &Qusr2_signal
4439 /* A vector, indexed by button number, giving the down-going location
4440 of currently depressed buttons, both scroll bar and non-scroll bar.
4442 The elements have the form
4443 (BUTTON-NUMBER MODIFIER-MASK . REST)
4444 where REST is the cdr of a position as it would be reported in the event.
4446 The make_lispy_event function stores positions here to tell the
4447 difference between click and drag events, and to store the starting
4448 location to be included in drag events. */
4450 static Lisp_Object button_down_location
;
4452 /* Information about the most recent up-going button event: Which
4453 button, what location, and what time. */
4455 static int last_mouse_button
;
4456 static int last_mouse_x
;
4457 static int last_mouse_y
;
4458 static unsigned long button_down_time
;
4460 /* The maximum time between clicks to make a double-click,
4461 or Qnil to disable double-click detection,
4462 or Qt for no time limit. */
4463 Lisp_Object Vdouble_click_time
;
4465 /* The number of clicks in this multiple-click. */
4467 int double_click_count
;
4469 /* Given a struct input_event, build the lisp event which represents
4470 it. If EVENT is 0, build a mouse movement event from the mouse
4471 movement buffer, which should have a movement event in it.
4473 Note that events must be passed to this function in the order they
4474 are received; this function stores the location of button presses
4475 in order to build drag events when the button is released. */
4478 make_lispy_event (event
)
4479 struct input_event
*event
;
4483 switch (SWITCH_ENUM_CAST (event
->kind
))
4485 /* A simple keystroke. */
4486 case ascii_keystroke
:
4488 Lisp_Object lispy_c
;
4489 int c
= event
->code
& 0377;
4490 /* Turn ASCII characters into control characters
4492 if (event
->modifiers
& ctrl_modifier
)
4493 c
= make_ctrl_char (c
);
4495 /* Add in the other modifier bits. We took care of ctrl_modifier
4496 just above, and the shift key was taken care of by the X code,
4497 and applied to control characters by make_ctrl_char. */
4498 c
|= (event
->modifiers
4499 & (meta_modifier
| alt_modifier
4500 | hyper_modifier
| super_modifier
));
4501 /* Distinguish Shift-SPC from SPC. */
4502 if ((event
->code
& 0377) == 040
4503 && event
->modifiers
& shift_modifier
)
4504 c
|= shift_modifier
;
4505 button_down_time
= 0;
4506 XSETFASTINT (lispy_c
, c
);
4510 case multibyte_char_keystroke
:
4512 Lisp_Object lispy_c
;
4514 XSETFASTINT (lispy_c
, event
->code
);
4518 /* A function key. The symbol may need to have modifier prefixes
4520 case non_ascii_keystroke
:
4521 button_down_time
= 0;
4523 for (i
= 0; i
< sizeof (lispy_accent_codes
) / sizeof (int); i
++)
4524 if (event
->code
== lispy_accent_codes
[i
])
4525 return modify_event_symbol (i
,
4527 Qfunction_key
, Qnil
,
4528 lispy_accent_keys
, &accent_key_syms
,
4529 (sizeof (lispy_accent_keys
)
4530 / sizeof (lispy_accent_keys
[0])));
4532 /* Handle system-specific keysyms. */
4533 if (event
->code
& (1 << 28))
4535 /* We need to use an alist rather than a vector as the cache
4536 since we can't make a vector long enuf. */
4537 if (NILP (current_kboard
->system_key_syms
))
4538 current_kboard
->system_key_syms
= Fcons (Qnil
, Qnil
);
4539 return modify_event_symbol (event
->code
,
4542 current_kboard
->Vsystem_key_alist
,
4543 0, ¤t_kboard
->system_key_syms
,
4548 if (event
->code
>= 0x400 && event
->code
< 0x500)
4549 return modify_event_symbol (event
->code
- 0x400,
4550 event
->modifiers
& ~shift_modifier
,
4551 Qfunction_key
, Qnil
,
4552 lispy_kana_keys
, &func_key_syms
,
4553 (sizeof (lispy_kana_keys
)
4554 / sizeof (lispy_kana_keys
[0])));
4555 #endif /* XK_kana_A */
4557 #ifdef ISO_FUNCTION_KEY_OFFSET
4558 if (event
->code
< FUNCTION_KEY_OFFSET
4559 && event
->code
>= ISO_FUNCTION_KEY_OFFSET
)
4560 return modify_event_symbol (event
->code
- ISO_FUNCTION_KEY_OFFSET
,
4562 Qfunction_key
, Qnil
,
4563 iso_lispy_function_keys
, &func_key_syms
,
4564 (sizeof (iso_lispy_function_keys
)
4565 / sizeof (iso_lispy_function_keys
[0])));
4568 return modify_event_symbol (event
->code
- FUNCTION_KEY_OFFSET
,
4570 Qfunction_key
, Qnil
,
4571 lispy_function_keys
, &func_key_syms
,
4572 (sizeof (lispy_function_keys
)
4573 / sizeof (lispy_function_keys
[0])));
4576 /* A mouse click. Figure out where it is, decide whether it's
4577 a press, click or drag, and build the appropriate structure. */
4579 #ifndef USE_TOOLKIT_SCROLL_BARS
4580 case scroll_bar_click
:
4583 int button
= event
->code
;
4585 Lisp_Object position
;
4586 Lisp_Object
*start_pos_ptr
;
4587 Lisp_Object start_pos
;
4591 /* Build the position as appropriate for this mouse click. */
4592 if (event
->kind
== mouse_click
)
4595 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
4598 Lisp_Object string_info
= Qnil
;
4601 /* Ignore mouse events that were made on frame that
4602 have been deleted. */
4603 if (! FRAME_LIVE_P (f
))
4606 /* EVENT->x and EVENT->y are frame-relative pixel
4607 coordinates at this place. Under old redisplay, COLUMN
4608 and ROW are set to frame relative glyph coordinates
4609 which are then used to determine whether this click is
4610 in a menu (non-toolkit version). */
4611 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4612 &column
, &row
, NULL
, 1);
4614 #ifndef USE_X_TOOLKIT
4615 /* In the non-toolkit version, clicks on the menu bar
4616 are ordinary button events in the event buffer.
4617 Distinguish them, and invoke the menu.
4619 (In the toolkit version, the toolkit handles the menu bar
4620 and Emacs doesn't know about it until after the user
4621 makes a selection.) */
4622 if (row
>= 0 && row
< FRAME_MENU_BAR_LINES (f
)
4623 && (event
->modifiers
& down_modifier
))
4625 Lisp_Object items
, item
;
4630 /* Activate the menu bar on the down event. If the
4631 up event comes in before the menu code can deal with it,
4633 if (! (event
->modifiers
& down_modifier
))
4637 /* Find the menu bar item under `column'. */
4639 items
= FRAME_MENU_BAR_ITEMS (f
);
4640 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
4642 Lisp_Object pos
, string
;
4643 string
= XVECTOR (items
)->contents
[i
+ 1];
4644 pos
= XVECTOR (items
)->contents
[i
+ 3];
4647 if (column
>= XINT (pos
)
4648 && column
< XINT (pos
) + XSTRING (string
)->size
)
4650 item
= XVECTOR (items
)->contents
[i
];
4655 /* ELisp manual 2.4b says (x y) are window relative but
4656 code says they are frame-relative. */
4658 = Fcons (event
->frame_or_window
,
4660 Fcons (Fcons (event
->x
, event
->y
),
4661 Fcons (make_number (event
->timestamp
),
4664 return Fcons (item
, Fcons (position
, Qnil
));
4666 #endif /* not USE_X_TOOLKIT */
4668 /* Set `window' to the window under frame pixel coordinates
4669 event->x/event->y. */
4670 window
= window_from_coordinates (f
, XINT (event
->x
),
4671 XINT (event
->y
), &part
, 0);
4673 if (!WINDOWP (window
))
4675 window
= event
->frame_or_window
;
4680 /* It's a click in window window at frame coordinates
4681 event->x/ event->y. */
4682 struct window
*w
= XWINDOW (window
);
4684 /* Get window relative coordinates. Original code
4685 `rounded' this to glyph boundaries. */
4686 int wx
= FRAME_TO_WINDOW_PIXEL_X (w
, XINT (event
->x
));
4687 int wy
= FRAME_TO_WINDOW_PIXEL_Y (w
, XINT (event
->y
));
4689 /* Set event coordinates to window-relative coordinates
4690 for constructing the Lisp event below. */
4691 XSETINT (event
->x
, wx
);
4692 XSETINT (event
->y
, wy
);
4694 if (part
== 1 || part
== 3)
4696 /* Mode line or top line. Look for a string under
4697 the mouse that may have a `local-map' property. */
4701 posn
= part
== 1 ? Qmode_line
: Qheader_line
;
4702 string
= mode_line_string (w
, wx
, wy
, part
== 1, &charpos
);
4703 if (STRINGP (string
))
4704 string_info
= Fcons (string
, make_number (charpos
));
4707 posn
= Qvertical_line
;
4709 XSETINT (posn
, buffer_posn_from_coords (w
, &wx
, &wy
));
4715 Fcons (Fcons (event
->x
, event
->y
),
4716 Fcons (make_number (event
->timestamp
),
4719 : Fcons (string_info
, Qnil
))))));
4721 #ifndef USE_TOOLKIT_SCROLL_BARS
4724 /* It's a scrollbar click. */
4726 Lisp_Object portion_whole
;
4729 window
= event
->frame_or_window
;
4730 portion_whole
= Fcons (event
->x
, event
->y
);
4731 part
= *scroll_bar_parts
[(int) event
->part
];
4735 Fcons (Qvertical_scroll_bar
,
4736 Fcons (portion_whole
,
4737 Fcons (make_number (event
->timestamp
),
4738 Fcons (part
, Qnil
)))));
4740 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4742 if (button
>= XVECTOR (button_down_location
)->size
)
4744 button_down_location
= larger_vector (button_down_location
,
4746 mouse_syms
= larger_vector (mouse_syms
, button
+ 1, Qnil
);
4749 start_pos_ptr
= &XVECTOR (button_down_location
)->contents
[button
];
4751 start_pos
= *start_pos_ptr
;
4752 *start_pos_ptr
= Qnil
;
4754 is_double
= (button
== last_mouse_button
4755 && XINT (event
->x
) == last_mouse_x
4756 && XINT (event
->y
) == last_mouse_y
4757 && button_down_time
!= 0
4758 && (EQ (Vdouble_click_time
, Qt
)
4759 || (INTEGERP (Vdouble_click_time
)
4760 && ((int)(event
->timestamp
- button_down_time
)
4761 < XINT (Vdouble_click_time
)))));
4762 last_mouse_button
= button
;
4763 last_mouse_x
= XINT (event
->x
);
4764 last_mouse_y
= XINT (event
->y
);
4766 /* If this is a button press, squirrel away the location, so
4767 we can decide later whether it was a click or a drag. */
4768 if (event
->modifiers
& down_modifier
)
4772 double_click_count
++;
4773 event
->modifiers
|= ((double_click_count
> 2)
4778 double_click_count
= 1;
4779 button_down_time
= event
->timestamp
;
4780 *start_pos_ptr
= Fcopy_alist (position
);
4783 /* Now we're releasing a button - check the co-ordinates to
4784 see if this was a click or a drag. */
4785 else if (event
->modifiers
& up_modifier
)
4787 /* If we did not see a down before this up,
4788 ignore the up. Probably this happened because
4789 the down event chose a menu item.
4790 It would be an annoyance to treat the release
4791 of the button that chose the menu item
4792 as a separate event. */
4794 if (!CONSP (start_pos
))
4797 event
->modifiers
&= ~up_modifier
;
4798 #if 0 /* Formerly we treated an up with no down as a click event. */
4799 if (!CONSP (start_pos
))
4800 event
->modifiers
|= click_modifier
;
4804 /* The third element of every position should be the (x,y)
4808 down
= Fnth (make_number (2), start_pos
);
4809 if (EQ (event
->x
, XCAR (down
))
4810 && EQ (event
->y
, XCDR (down
)))
4812 event
->modifiers
|= click_modifier
;
4816 button_down_time
= 0;
4817 event
->modifiers
|= drag_modifier
;
4819 /* Don't check is_double; treat this as multiple
4820 if the down-event was multiple. */
4821 if (double_click_count
> 1)
4822 event
->modifiers
|= ((double_click_count
> 2)
4828 /* Every mouse event should either have the down_modifier or
4829 the up_modifier set. */
4833 /* Get the symbol we should use for the mouse click. */
4836 head
= modify_event_symbol (button
,
4838 Qmouse_click
, Vlispy_mouse_stem
,
4841 XVECTOR (mouse_syms
)->size
);
4842 if (event
->modifiers
& drag_modifier
)
4847 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
4850 Fcons (make_number (double_click_count
),
4859 #if USE_TOOLKIT_SCROLL_BARS
4861 /* We don't have down and up events if using toolkit scroll bars,
4862 so make this always a click event. Store in the `part' of
4863 the Lisp event a symbol which maps to the following actions:
4865 `above_handle' page up
4866 `below_handle' page down
4870 `bottom' bottom of buffer
4871 `handle' thumb has been dragged.
4872 `end-scroll' end of interaction with scroll bar
4874 The incoming input_event contains in its `part' member an
4875 index of type `enum scroll_bar_part' which we can use as an
4876 index in scroll_bar_parts to get the appropriate symbol. */
4878 case scroll_bar_click
:
4880 Lisp_Object position
, head
, window
, portion_whole
, part
;
4882 window
= event
->frame_or_window
;
4883 portion_whole
= Fcons (event
->x
, event
->y
);
4884 part
= *scroll_bar_parts
[(int) event
->part
];
4888 Fcons (Qvertical_scroll_bar
,
4889 Fcons (portion_whole
,
4890 Fcons (make_number (event
->timestamp
),
4891 Fcons (part
, Qnil
)))));
4893 /* Always treat scroll bar events as clicks. */
4894 event
->modifiers
|= click_modifier
;
4896 /* Get the symbol we should use for the mouse click. */
4897 head
= modify_event_symbol (event
->code
,
4902 XVECTOR (mouse_syms
)->size
);
4903 return Fcons (head
, Fcons (position
, Qnil
));
4906 #endif /* USE_TOOLKIT_SCROLL_BARS */
4909 case w32_scroll_bar_click
:
4911 int button
= event
->code
;
4913 Lisp_Object position
;
4914 Lisp_Object
*start_pos_ptr
;
4915 Lisp_Object start_pos
;
4919 Lisp_Object portion_whole
;
4922 window
= event
->frame_or_window
;
4923 portion_whole
= Fcons (event
->x
, event
->y
);
4924 part
= *scroll_bar_parts
[(int) event
->part
];
4928 Fcons (Qvertical_scroll_bar
,
4929 Fcons (portion_whole
,
4930 Fcons (make_number (event
->timestamp
),
4931 Fcons (part
, Qnil
)))));
4934 /* Always treat W32 scroll bar events as clicks. */
4935 event
->modifiers
|= click_modifier
;
4938 /* Get the symbol we should use for the mouse click. */
4941 head
= modify_event_symbol (button
,
4946 XVECTOR (mouse_syms
)->size
);
4955 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
4958 Lisp_Object head
, position
;
4961 /* Ignore mouse events that were made on frame that
4962 have been deleted. */
4963 if (! FRAME_LIVE_P (f
))
4965 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4966 &column
, &row
, NULL
, 1);
4967 window
= window_from_coordinates (f
, column
, row
, &part
, 0);
4969 if (!WINDOWP (window
))
4971 window
= event
->frame_or_window
;
4976 int pixcolumn
, pixrow
;
4977 column
-= XINT (XWINDOW (window
)->left
);
4978 row
-= XINT (XWINDOW (window
)->top
);
4979 glyph_to_pixel_coords (XWINDOW(window
), column
, row
,
4980 &pixcolumn
, &pixrow
);
4981 XSETINT (event
->x
, pixcolumn
);
4982 XSETINT (event
->y
, pixrow
);
4987 posn
= Qvertical_line
;
4989 posn
= Qheader_line
;
4992 buffer_posn_from_coords (XWINDOW (window
),
4997 Lisp_Object head
, position
;
5002 Fcons (Fcons (event
->x
, event
->y
),
5003 Fcons (make_number (event
->timestamp
),
5006 head
= modify_event_symbol (0, event
->modifiers
,
5008 lispy_mouse_wheel_names
,
5009 &mouse_wheel_syms
, 1);
5012 Fcons (make_number (event
->code
),
5016 #endif /* WINDOWSNT */
5027 /* The frame_or_window field should be a cons of the frame in
5028 which the event occurred and a list of the filenames
5030 if (! CONSP (event
->frame_or_window
))
5033 f
= XFRAME (XCAR (event
->frame_or_window
));
5034 files
= XCDR (event
->frame_or_window
);
5036 /* Ignore mouse events that were made on frames that
5037 have been deleted. */
5038 if (! FRAME_LIVE_P (f
))
5040 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
5041 &column
, &row
, NULL
, 1);
5042 window
= window_from_coordinates (f
, column
, row
, &part
, 0);
5044 if (!WINDOWP (window
))
5046 window
= XCAR (event
->frame_or_window
);
5051 /* It's an event in window `window' at frame coordinates
5052 event->x/ event->y. */
5053 struct window
*w
= XWINDOW (window
);
5055 /* Get window relative coordinates. */
5056 int wx
= FRAME_TO_WINDOW_PIXEL_X (w
, XINT (event
->x
));
5057 int wy
= FRAME_TO_WINDOW_PIXEL_Y (w
, XINT (event
->y
));
5059 /* Set event coordinates to window-relative coordinates
5060 for constructing the Lisp event below. */
5061 XSETINT (event
->x
, wx
);
5062 XSETINT (event
->y
, wy
);
5067 posn
= Qvertical_line
;
5069 posn
= Qheader_line
;
5071 XSETINT (posn
, buffer_posn_from_coords (w
, &wx
, &wy
));
5075 Lisp_Object head
, position
;
5080 Fcons (Fcons (event
->x
, event
->y
),
5081 Fcons (make_number (event
->timestamp
),
5084 head
= modify_event_symbol (0, event
->modifiers
,
5086 lispy_drag_n_drop_names
,
5087 &drag_n_drop_syms
, 1);
5094 #endif /* HAVE_MOUSE */
5096 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
5097 case MENU_BAR_EVENT
:
5098 if (EQ (event
->arg
, event
->frame_or_window
))
5099 /* This is the prefix key. We translate this to
5100 `(menu_bar)' because the code in keyboard.c for menu
5101 events, which we use, relies on this. */
5102 return Fcons (Qmenu_bar
, Qnil
);
5106 case TOOL_BAR_EVENT
:
5107 if (EQ (event
->arg
, event
->frame_or_window
))
5108 /* This is the prefix key. We translate this to
5109 `(tool_bar)' because the code in keyboard.c for menu
5110 events, which we use, relies on this. */
5111 return Fcons (Qtool_bar
, Qnil
);
5112 else if (SYMBOLP (event
->arg
))
5113 return apply_modifiers (event
->modifiers
, event
->arg
);
5116 case USER_SIGNAL_EVENT
:
5117 /* A user signal. */
5118 return *lispy_user_signals
[event
->code
];
5120 /* The 'kind' field of the event is something we don't recognize. */
5129 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
5131 Lisp_Object bar_window
;
5132 enum scroll_bar_part part
;
5136 /* Is it a scroll bar movement? */
5137 if (frame
&& ! NILP (bar_window
))
5139 Lisp_Object part_sym
;
5141 part_sym
= *scroll_bar_parts
[(int) part
];
5142 return Fcons (Qscroll_bar_movement
,
5143 (Fcons (Fcons (bar_window
,
5144 Fcons (Qvertical_scroll_bar
,
5145 Fcons (Fcons (x
, y
),
5146 Fcons (make_number (time
),
5152 /* Or is it an ordinary mouse movement? */
5160 /* It's in a frame; which window on that frame? */
5161 window
= window_from_coordinates (frame
, XINT (x
), XINT (y
), &area
, 0);
5165 if (WINDOWP (window
))
5167 struct window
*w
= XWINDOW (window
);
5170 /* Get window relative coordinates. */
5171 wx
= FRAME_TO_WINDOW_PIXEL_X (w
, XINT (x
));
5172 wy
= FRAME_TO_WINDOW_PIXEL_Y (w
, XINT (y
));
5179 posn
= Qvertical_line
;
5181 posn
= Qheader_line
;
5183 XSETINT (posn
, buffer_posn_from_coords (w
, &wx
, &wy
));
5185 else if (frame
!= 0)
5187 XSETFRAME (window
, frame
);
5198 return Fcons (Qmouse_movement
,
5199 Fcons (Fcons (window
,
5201 Fcons (Fcons (x
, y
),
5202 Fcons (make_number (time
),
5208 #endif /* HAVE_MOUSE */
5210 /* Construct a switch frame event. */
5212 make_lispy_switch_frame (frame
)
5215 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
5218 /* Manipulating modifiers. */
5220 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
5222 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
5223 SYMBOL's name of the end of the modifiers; the string from this
5224 position is the unmodified symbol name.
5226 This doesn't use any caches. */
5229 parse_modifiers_uncached (symbol
, modifier_end
)
5233 struct Lisp_String
*name
;
5237 CHECK_SYMBOL (symbol
, 1);
5240 name
= XSYMBOL (symbol
)->name
;
5242 for (i
= 0; i
+2 <= STRING_BYTES (name
); )
5244 int this_mod_end
= 0;
5247 /* See if the name continues with a modifier word.
5248 Check that the word appears, but don't check what follows it.
5249 Set this_mod and this_mod_end to record what we find. */
5251 switch (name
->data
[i
])
5253 #define SINGLE_LETTER_MOD(BIT) \
5254 (this_mod_end = i + 1, this_mod = BIT)
5257 SINGLE_LETTER_MOD (alt_modifier
);
5261 SINGLE_LETTER_MOD (ctrl_modifier
);
5265 SINGLE_LETTER_MOD (hyper_modifier
);
5269 SINGLE_LETTER_MOD (meta_modifier
);
5273 SINGLE_LETTER_MOD (shift_modifier
);
5277 SINGLE_LETTER_MOD (super_modifier
);
5280 #undef SINGLE_LETTER_MOD
5283 /* If we found no modifier, stop looking for them. */
5284 if (this_mod_end
== 0)
5287 /* Check there is a dash after the modifier, so that it
5288 really is a modifier. */
5289 if (this_mod_end
>= STRING_BYTES (name
)
5290 || name
->data
[this_mod_end
] != '-')
5293 /* This modifier is real; look for another. */
5294 modifiers
|= this_mod
;
5295 i
= this_mod_end
+ 1;
5298 /* Should we include the `click' modifier? */
5299 if (! (modifiers
& (down_modifier
| drag_modifier
5300 | double_modifier
| triple_modifier
))
5301 && i
+ 7 == STRING_BYTES (name
)
5302 && strncmp (name
->data
+ i
, "mouse-", 6) == 0
5303 && ('0' <= name
->data
[i
+ 6] && name
->data
[i
+ 6] <= '9'))
5304 modifiers
|= click_modifier
;
5312 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
5313 prepended to the string BASE[0..BASE_LEN-1].
5314 This doesn't use any caches. */
5316 apply_modifiers_uncached (modifiers
, base
, base_len
, base_len_byte
)
5319 int base_len
, base_len_byte
;
5321 /* Since BASE could contain nulls, we can't use intern here; we have
5322 to use Fintern, which expects a genuine Lisp_String, and keeps a
5325 = (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
5331 /* Only the event queue may use the `up' modifier; it should always
5332 be turned into a click or drag event before presented to lisp code. */
5333 if (modifiers
& up_modifier
)
5336 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
5337 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
5338 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
5339 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
5340 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
5341 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
5342 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
5343 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
5344 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
5345 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
5346 /* The click modifier is denoted by the absence of other modifiers. */
5350 mod_len
= p
- new_mods
;
5354 Lisp_Object new_name
;
5356 new_name
= make_uninit_multibyte_string (mod_len
+ base_len
,
5357 mod_len
+ base_len_byte
);
5358 bcopy (new_mods
, XSTRING (new_name
)->data
, mod_len
);
5359 bcopy (base
, XSTRING (new_name
)->data
+ mod_len
, base_len_byte
);
5361 return Fintern (new_name
, Qnil
);
5366 static char *modifier_names
[] =
5368 "up", "down", "drag", "click", "double", "triple", 0, 0,
5369 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5370 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
5372 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
5374 static Lisp_Object modifier_symbols
;
5376 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
5378 lispy_modifier_list (modifiers
)
5381 Lisp_Object modifier_list
;
5384 modifier_list
= Qnil
;
5385 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
5386 if (modifiers
& (1<<i
))
5387 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
5390 return modifier_list
;
5394 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
5395 where UNMODIFIED is the unmodified form of SYMBOL,
5396 MASK is the set of modifiers present in SYMBOL's name.
5397 This is similar to parse_modifiers_uncached, but uses the cache in
5398 SYMBOL's Qevent_symbol_element_mask property, and maintains the
5399 Qevent_symbol_elements property. */
5402 parse_modifiers (symbol
)
5405 Lisp_Object elements
;
5407 elements
= Fget (symbol
, Qevent_symbol_element_mask
);
5408 if (CONSP (elements
))
5413 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
5414 Lisp_Object unmodified
;
5417 unmodified
= Fintern (make_string (XSYMBOL (symbol
)->name
->data
+ end
,
5418 STRING_BYTES (XSYMBOL (symbol
)->name
) - end
),
5421 if (modifiers
& ~(((EMACS_INT
)1 << VALBITS
) - 1))
5423 XSETFASTINT (mask
, modifiers
);
5424 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
5426 /* Cache the parsing results on SYMBOL. */
5427 Fput (symbol
, Qevent_symbol_element_mask
,
5429 Fput (symbol
, Qevent_symbol_elements
,
5430 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
5432 /* Since we know that SYMBOL is modifiers applied to unmodified,
5433 it would be nice to put that in unmodified's cache.
5434 But we can't, since we're not sure that parse_modifiers is
5441 /* Apply the modifiers MODIFIERS to the symbol BASE.
5442 BASE must be unmodified.
5444 This is like apply_modifiers_uncached, but uses BASE's
5445 Qmodifier_cache property, if present. It also builds
5446 Qevent_symbol_elements properties, since it has that info anyway.
5448 apply_modifiers copies the value of BASE's Qevent_kind property to
5449 the modified symbol. */
5451 apply_modifiers (modifiers
, base
)
5455 Lisp_Object cache
, index
, entry
, new_symbol
;
5457 /* Mask out upper bits. We don't know where this value's been. */
5458 modifiers
&= ((EMACS_INT
)1 << VALBITS
) - 1;
5460 /* The click modifier never figures into cache indices. */
5461 cache
= Fget (base
, Qmodifier_cache
);
5462 XSETFASTINT (index
, (modifiers
& ~click_modifier
));
5463 entry
= assq_no_quit (index
, cache
);
5466 new_symbol
= XCDR (entry
);
5469 /* We have to create the symbol ourselves. */
5470 new_symbol
= apply_modifiers_uncached (modifiers
,
5471 XSYMBOL (base
)->name
->data
,
5472 XSYMBOL (base
)->name
->size
,
5473 STRING_BYTES (XSYMBOL (base
)->name
));
5475 /* Add the new symbol to the base's cache. */
5476 entry
= Fcons (index
, new_symbol
);
5477 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
5479 /* We have the parsing info now for free, so add it to the caches. */
5480 XSETFASTINT (index
, modifiers
);
5481 Fput (new_symbol
, Qevent_symbol_element_mask
,
5482 Fcons (base
, Fcons (index
, Qnil
)));
5483 Fput (new_symbol
, Qevent_symbol_elements
,
5484 Fcons (base
, lispy_modifier_list (modifiers
)));
5487 /* Make sure this symbol is of the same kind as BASE.
5489 You'd think we could just set this once and for all when we
5490 intern the symbol above, but reorder_modifiers may call us when
5491 BASE's property isn't set right; we can't assume that just
5492 because it has a Qmodifier_cache property it must have its
5493 Qevent_kind set right as well. */
5494 if (NILP (Fget (new_symbol
, Qevent_kind
)))
5498 kind
= Fget (base
, Qevent_kind
);
5500 Fput (new_symbol
, Qevent_kind
, kind
);
5507 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
5508 return a symbol with the modifiers placed in the canonical order.
5509 Canonical order is alphabetical, except for down and drag, which
5510 always come last. The 'click' modifier is never written out.
5512 Fdefine_key calls this to make sure that (for example) C-M-foo
5513 and M-C-foo end up being equivalent in the keymap. */
5516 reorder_modifiers (symbol
)
5519 /* It's hopefully okay to write the code this way, since everything
5520 will soon be in caches, and no consing will be done at all. */
5523 parsed
= parse_modifiers (symbol
);
5524 return apply_modifiers ((int) XINT (XCAR (XCDR (parsed
))),
5529 /* For handling events, we often want to produce a symbol whose name
5530 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
5531 to some base, like the name of a function key or mouse button.
5532 modify_event_symbol produces symbols of this sort.
5534 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
5535 is the name of the i'th symbol. TABLE_SIZE is the number of elements
5538 Alternatively, NAME_ALIST_OR_STEM is either an alist mapping codes
5539 into symbol names, or a string specifying a name stem used to
5540 construct a symbol name or the form `STEM-N', where N is the decimal
5541 representation of SYMBOL_NUM. NAME_ALIST_OR_STEM is used if it is
5542 non-nil; otherwise NAME_TABLE is used.
5544 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
5545 persist between calls to modify_event_symbol that it can use to
5546 store a cache of the symbols it's generated for this NAME_TABLE
5547 before. The object stored there may be a vector or an alist.
5549 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
5551 MODIFIERS is a set of modifier bits (as given in struct input_events)
5552 whose prefixes should be applied to the symbol name.
5554 SYMBOL_KIND is the value to be placed in the event_kind property of
5555 the returned symbol.
5557 The symbols we create are supposed to have an
5558 `event-symbol-elements' property, which lists the modifiers present
5559 in the symbol's name. */
5562 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_alist_or_stem
,
5563 name_table
, symbol_table
, table_size
)
5566 Lisp_Object symbol_kind
;
5567 Lisp_Object name_alist_or_stem
;
5569 Lisp_Object
*symbol_table
;
5570 unsigned int table_size
;
5573 Lisp_Object symbol_int
;
5575 /* Get rid of the "vendor-specific" bit here. */
5576 XSETINT (symbol_int
, symbol_num
& 0xffffff);
5578 /* Is this a request for a valid symbol? */
5579 if (symbol_num
< 0 || symbol_num
>= table_size
)
5582 if (CONSP (*symbol_table
))
5583 value
= Fcdr (assq_no_quit (symbol_int
, *symbol_table
));
5585 /* If *symbol_table doesn't seem to be initialized properly, fix that.
5586 *symbol_table should be a lisp vector TABLE_SIZE elements long,
5587 where the Nth element is the symbol for NAME_TABLE[N], or nil if
5588 we've never used that symbol before. */
5591 if (! VECTORP (*symbol_table
)
5592 || XVECTOR (*symbol_table
)->size
!= table_size
)
5596 XSETFASTINT (size
, table_size
);
5597 *symbol_table
= Fmake_vector (size
, Qnil
);
5600 value
= XVECTOR (*symbol_table
)->contents
[symbol_num
];
5603 /* Have we already used this symbol before? */
5606 /* No; let's create it. */
5607 if (CONSP (name_alist_or_stem
))
5608 value
= Fcdr_safe (Fassq (symbol_int
, name_alist_or_stem
));
5609 else if (STRINGP (name_alist_or_stem
))
5611 int len
= STRING_BYTES (XSTRING (name_alist_or_stem
));
5612 char *buf
= (char *) alloca (len
+ 50);
5613 sprintf (buf
, "%s-%d", XSTRING (name_alist_or_stem
)->data
,
5614 XINT (symbol_int
) + 1);
5615 value
= intern (buf
);
5617 else if (name_table
!= 0 && name_table
[symbol_num
])
5618 value
= intern (name_table
[symbol_num
]);
5620 #ifdef HAVE_WINDOW_SYSTEM
5623 char *name
= x_get_keysym_name (symbol_num
);
5625 value
= intern (name
);
5632 sprintf (buf
, "key-%d", symbol_num
);
5633 value
= intern (buf
);
5636 if (CONSP (*symbol_table
))
5637 *symbol_table
= Fcons (Fcons (symbol_int
, value
), *symbol_table
);
5639 XVECTOR (*symbol_table
)->contents
[symbol_num
] = value
;
5641 /* Fill in the cache entries for this symbol; this also
5642 builds the Qevent_symbol_elements property, which the user
5644 apply_modifiers (modifiers
& click_modifier
, value
);
5645 Fput (value
, Qevent_kind
, symbol_kind
);
5648 /* Apply modifiers to that symbol. */
5649 return apply_modifiers (modifiers
, value
);
5652 /* Convert a list that represents an event type,
5653 such as (ctrl meta backspace), into the usual representation of that
5654 event type as a number or a symbol. */
5656 DEFUN ("event-convert-list", Fevent_convert_list
, Sevent_convert_list
, 1, 1, 0,
5657 "Convert the event description list EVENT-DESC to an event type.\n\
5658 EVENT-DESC should contain one base event type (a character or symbol)\n\
5659 and zero or more modifier names (control, meta, hyper, super, shift, alt,\n\
5660 drag, down, double or triple). The base must be last.\n\
5661 The return value is an event type (a character or symbol) which\n\
5662 has the same base event type and all the specified modifiers.")
5664 Lisp_Object event_desc
;
5672 while (CONSP (rest
))
5680 /* Given a symbol, see if it is a modifier name. */
5681 if (SYMBOLP (elt
) && CONSP (rest
))
5682 this = parse_solitary_modifier (elt
);
5686 else if (!NILP (base
))
5687 error ("Two bases given in one event");
5693 /* Let the symbol A refer to the character A. */
5694 if (SYMBOLP (base
) && XSYMBOL (base
)->name
->size
== 1)
5695 XSETINT (base
, XSYMBOL (base
)->name
->data
[0]);
5697 if (INTEGERP (base
))
5699 /* Turn (shift a) into A. */
5700 if ((modifiers
& shift_modifier
) != 0
5701 && (XINT (base
) >= 'a' && XINT (base
) <= 'z'))
5703 XSETINT (base
, XINT (base
) - ('a' - 'A'));
5704 modifiers
&= ~shift_modifier
;
5707 /* Turn (control a) into C-a. */
5708 if (modifiers
& ctrl_modifier
)
5709 return make_number ((modifiers
& ~ctrl_modifier
)
5710 | make_ctrl_char (XINT (base
)));
5712 return make_number (modifiers
| XINT (base
));
5714 else if (SYMBOLP (base
))
5715 return apply_modifiers (modifiers
, base
);
5718 error ("Invalid base event");
5723 /* Try to recognize SYMBOL as a modifier name.
5724 Return the modifier flag bit, or 0 if not recognized. */
5727 parse_solitary_modifier (symbol
)
5730 struct Lisp_String
*name
= XSYMBOL (symbol
)->name
;
5732 switch (name
->data
[0])
5734 #define SINGLE_LETTER_MOD(BIT) \
5735 if (STRING_BYTES (name) == 1) \
5738 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
5739 if (LEN == STRING_BYTES (name) \
5740 && ! strncmp (name->data, NAME, LEN)) \
5744 SINGLE_LETTER_MOD (alt_modifier
);
5748 MULTI_LETTER_MOD (alt_modifier
, "alt", 3);
5752 SINGLE_LETTER_MOD (ctrl_modifier
);
5756 MULTI_LETTER_MOD (ctrl_modifier
, "ctrl", 4);
5757 MULTI_LETTER_MOD (ctrl_modifier
, "control", 7);
5761 SINGLE_LETTER_MOD (hyper_modifier
);
5765 MULTI_LETTER_MOD (hyper_modifier
, "hyper", 5);
5769 SINGLE_LETTER_MOD (meta_modifier
);
5773 MULTI_LETTER_MOD (meta_modifier
, "meta", 4);
5777 SINGLE_LETTER_MOD (shift_modifier
);
5781 MULTI_LETTER_MOD (shift_modifier
, "shift", 5);
5782 MULTI_LETTER_MOD (super_modifier
, "super", 5);
5783 SINGLE_LETTER_MOD (super_modifier
);
5787 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
5788 MULTI_LETTER_MOD (down_modifier
, "down", 4);
5789 MULTI_LETTER_MOD (double_modifier
, "double", 6);
5793 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
5796 #undef SINGLE_LETTER_MOD
5797 #undef MULTI_LETTER_MOD
5803 /* Return 1 if EVENT is a list whose elements are all integers or symbols.
5804 Such a list is not valid as an event,
5805 but it can be a Lucid-style event type list. */
5808 lucid_event_type_list_p (object
)
5813 if (! CONSP (object
))
5816 for (tail
= object
; CONSP (tail
); tail
= XCDR (tail
))
5820 if (! (INTEGERP (elt
) || SYMBOLP (elt
)))
5827 /* Store into *addr a value nonzero if terminal input chars are available.
5828 Serves the purpose of ioctl (0, FIONREAD, addr)
5829 but works even if FIONREAD does not exist.
5830 (In fact, this may actually read some input.)
5832 If DO_TIMERS_NOW is nonzero, actually run timer events that are ripe. */
5835 get_input_pending (addr
, do_timers_now
)
5839 /* First of all, have we already counted some input? */
5840 *addr
= !NILP (Vquit_flag
) || readable_events (do_timers_now
);
5842 /* If input is being read as it arrives, and we have none, there is none. */
5843 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
5846 /* Try to read some input and see how much we get. */
5848 *addr
= !NILP (Vquit_flag
) || readable_events (do_timers_now
);
5851 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
5854 gobble_input (expected
)
5859 if (interrupt_input
)
5862 mask
= sigblock (sigmask (SIGIO
));
5863 read_avail_input (expected
);
5867 #ifdef POLL_FOR_INPUT
5868 if (read_socket_hook
&& !interrupt_input
&& poll_suppress_count
== 0)
5871 mask
= sigblock (sigmask (SIGALRM
));
5872 read_avail_input (expected
);
5878 read_avail_input (expected
);
5882 /* Put a buffer_switch_event in the buffer
5883 so that read_key_sequence will notice the new current buffer. */
5886 record_asynch_buffer_change ()
5888 struct input_event event
;
5891 event
.kind
= buffer_switch_event
;
5892 event
.frame_or_window
= Qnil
;
5896 /* We don't need a buffer-switch event unless Emacs is waiting for input.
5897 The purpose of the event is to make read_key_sequence look up the
5898 keymaps again. If we aren't in read_key_sequence, we don't need one,
5899 and the event could cause trouble by messing up (input-pending-p). */
5900 tem
= Fwaiting_for_user_input_p ();
5904 /* We never need these events if we have no asynchronous subprocesses. */
5908 /* Make sure no interrupt happens while storing the event. */
5910 if (interrupt_input
)
5913 mask
= sigblock (sigmask (SIGIO
));
5914 kbd_buffer_store_event (&event
);
5921 kbd_buffer_store_event (&event
);
5928 /* Read any terminal input already buffered up by the system
5929 into the kbd_buffer, but do not wait.
5931 EXPECTED should be nonzero if the caller knows there is some input.
5933 Except on VMS, all input is read by this function.
5934 If interrupt_input is nonzero, this function MUST be called
5935 only when SIGIO is blocked.
5937 Returns the number of keyboard chars read, or -1 meaning
5938 this is a bad time to try to read input. */
5941 read_avail_input (expected
)
5944 struct input_event buf
[KBD_BUFFER_SIZE
];
5948 if (read_socket_hook
)
5949 /* No need for FIONREAD or fcntl; just say don't wait. */
5950 nread
= (*read_socket_hook
) (input_fd
, buf
, KBD_BUFFER_SIZE
, expected
);
5953 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
5954 the kbd_buffer can really hold. That may prevent loss
5955 of characters on some systems when input is stuffed at us. */
5956 unsigned char cbuf
[KBD_BUFFER_SIZE
- 1];
5959 /* Determine how many characters we should *try* to read. */
5962 #else /* not WINDOWSNT */
5964 n_to_read
= dos_keysns ();
5967 #else /* not MSDOS */
5969 /* Find out how much input is available. */
5970 if (ioctl (input_fd
, FIONREAD
, &n_to_read
) < 0)
5971 /* Formerly simply reported no input, but that sometimes led to
5972 a failure of Emacs to terminate.
5973 SIGHUP seems appropriate if we can't reach the terminal. */
5974 /* ??? Is it really right to send the signal just to this process
5975 rather than to the whole process group?
5976 Perhaps on systems with FIONREAD Emacs is alone in its group. */
5977 kill (getpid (), SIGHUP
);
5980 if (n_to_read
> sizeof cbuf
)
5981 n_to_read
= sizeof cbuf
;
5982 #else /* no FIONREAD */
5983 #if defined (USG) || defined (DGUX)
5984 /* Read some input if available, but don't wait. */
5985 n_to_read
= sizeof cbuf
;
5986 fcntl (input_fd
, F_SETFL
, O_NDELAY
);
5991 #endif /* not MSDOS */
5992 #endif /* not WINDOWSNT */
5994 /* Now read; for one reason or another, this will not block.
5995 NREAD is set to the number of chars read. */
5999 cbuf
[0] = dos_keyread ();
6002 nread
= emacs_read (input_fd
, cbuf
, n_to_read
);
6004 /* POSIX infers that processes which are not in the session leader's
6005 process group won't get SIGHUP's at logout time. BSDI adheres to
6006 this part standard and returns -1 from read (0) with errno==EIO
6007 when the control tty is taken away.
6008 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
6009 if (nread
== -1 && errno
== EIO
)
6011 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
6012 /* The kernel sometimes fails to deliver SIGHUP for ptys.
6013 This looks incorrect, but it isn't, because _BSD causes
6014 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
6015 and that causes a value other than 0 when there is no input. */
6021 /* We used to retry the read if it was interrupted.
6022 But this does the wrong thing when O_NDELAY causes
6023 an EAGAIN error. Does anybody know of a situation
6024 where a retry is actually needed? */
6026 nread
< 0 && (errno
== EAGAIN
6040 #if defined (USG) || defined (DGUX)
6041 fcntl (input_fd
, F_SETFL
, 0);
6042 #endif /* USG or DGUX */
6043 #endif /* no FIONREAD */
6044 for (i
= 0; i
< nread
; i
++)
6046 buf
[i
].kind
= ascii_keystroke
;
6047 buf
[i
].modifiers
= 0;
6048 if (meta_key
== 1 && (cbuf
[i
] & 0x80))
6049 buf
[i
].modifiers
= meta_modifier
;
6053 buf
[i
].code
= cbuf
[i
];
6054 buf
[i
].frame_or_window
= selected_frame
;
6059 /* Scan the chars for C-g and store them in kbd_buffer. */
6060 for (i
= 0; i
< nread
; i
++)
6062 kbd_buffer_store_event (&buf
[i
]);
6063 /* Don't look at input that follows a C-g too closely.
6064 This reduces lossage due to autorepeat on C-g. */
6065 if (buf
[i
].kind
== ascii_keystroke
6066 && buf
[i
].code
== quit_char
)
6072 #endif /* not VMS */
6074 #ifdef SIGIO /* for entire page */
6075 /* Note SIGIO has been undef'd if FIONREAD is missing. */
6078 input_available_signal (signo
)
6081 /* Must preserve main program's value of errno. */
6082 int old_errno
= errno
;
6084 extern int select_alarmed
;
6087 #if defined (USG) && !defined (POSIX_SIGNALS)
6088 /* USG systems forget handlers when they are used;
6089 must reestablish each time */
6090 signal (signo
, input_available_signal
);
6097 if (input_available_clear_time
)
6098 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
6103 nread
= read_avail_input (1);
6104 /* -1 means it's not ok to read the input now.
6105 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
6106 0 means there was no keyboard input available. */
6111 select_alarmed
= 1; /* Force the select emulator back to life */
6122 /* Send ourselves a SIGIO.
6124 This function exists so that the UNBLOCK_INPUT macro in
6125 blockinput.h can have some way to take care of input we put off
6126 dealing with, without assuming that every file which uses
6127 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
6129 reinvoke_input_signal ()
6132 kill (getpid (), SIGIO
);
6138 /* Return the prompt-string of a sparse keymap.
6139 This is the first element which is a string.
6140 Return nil if there is none. */
6148 register Lisp_Object tem
;
6157 static void menu_bar_item
P_ ((Lisp_Object
, Lisp_Object
));
6158 static void menu_bar_one_keymap
P_ ((Lisp_Object
));
6160 /* These variables hold the vector under construction within
6161 menu_bar_items and its subroutines, and the current index
6162 for storing into that vector. */
6163 static Lisp_Object menu_bar_items_vector
;
6164 static int menu_bar_items_index
;
6166 /* Return a vector of menu items for a menu bar, appropriate
6167 to the current buffer. Each item has three elements in the vector:
6170 OLD is an old vector we can optionally reuse, or nil. */
6173 menu_bar_items (old
)
6176 /* The number of keymaps we're scanning right now, and the number of
6177 keymaps we have allocated space for. */
6180 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
6181 in the current keymaps, or nil where it is not a prefix. */
6184 Lisp_Object def
, tem
, tail
;
6193 struct gcpro gcpro1
;
6195 /* In order to build the menus, we need to call the keymap
6196 accessors. They all call QUIT. But this function is called
6197 during redisplay, during which a quit is fatal. So inhibit
6198 quitting while building the menus.
6199 We do this instead of specbind because (1) errors will clear it anyway
6200 and (2) this avoids risk of specpdl overflow. */
6201 oquit
= Vinhibit_quit
;
6205 menu_bar_items_vector
= old
;
6207 menu_bar_items_vector
= Fmake_vector (make_number (24), Qnil
);
6208 menu_bar_items_index
= 0;
6210 GCPRO1 (menu_bar_items_vector
);
6212 /* Build our list of keymaps.
6213 If we recognize a function key and replace its escape sequence in
6214 keybuf with its symbol, or if the sequence starts with a mouse
6215 click and we need to switch buffers, we jump back here to rebuild
6216 the initial keymaps from the current buffer. */
6220 /* Should overriding-terminal-local-map and overriding-local-map apply? */
6221 if (!NILP (Voverriding_local_map_menu_flag
))
6223 /* Yes, use them (if non-nil) as well as the global map. */
6224 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
6226 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
6227 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
6228 if (!NILP (Voverriding_local_map
))
6229 maps
[nmaps
++] = Voverriding_local_map
;
6233 /* No, so use major and minor mode keymaps and keymap property. */
6235 Lisp_Object map
= get_local_map (PT
, current_buffer
, keymap
);
6238 nmaps
= current_minor_maps (NULL
, &tmaps
);
6239 maps
= (Lisp_Object
*) alloca ((nmaps
+ extra_maps
)
6240 * sizeof (maps
[0]));
6241 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
6243 maps
[nmaps
++] = map
;
6244 maps
[nmaps
++] = get_local_map (PT
, current_buffer
, local_map
);
6246 maps
[nmaps
++] = current_global_map
;
6249 /* Look up in each map the dummy prefix key `menu-bar'. */
6253 for (mapno
= nmaps
- 1; mapno
>= 0; mapno
--)
6254 if (!NILP (maps
[mapno
]))
6256 def
= access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0, 0);
6257 tem
= Fkeymapp (def
);
6259 menu_bar_one_keymap (def
);
6262 /* Move to the end those items that should be at the end. */
6264 for (tail
= Vmenu_bar_final_items
; CONSP (tail
); tail
= XCDR (tail
))
6267 int end
= menu_bar_items_index
;
6269 for (i
= 0; i
< end
; i
+= 4)
6270 if (EQ (XCAR (tail
), XVECTOR (menu_bar_items_vector
)->contents
[i
]))
6272 Lisp_Object tem0
, tem1
, tem2
, tem3
;
6273 /* Move the item at index I to the end,
6274 shifting all the others forward. */
6275 tem0
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 0];
6276 tem1
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 1];
6277 tem2
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
6278 tem3
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3];
6280 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
6281 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
6282 (end
- i
- 4) * sizeof (Lisp_Object
));
6283 XVECTOR (menu_bar_items_vector
)->contents
[end
- 4] = tem0
;
6284 XVECTOR (menu_bar_items_vector
)->contents
[end
- 3] = tem1
;
6285 XVECTOR (menu_bar_items_vector
)->contents
[end
- 2] = tem2
;
6286 XVECTOR (menu_bar_items_vector
)->contents
[end
- 1] = tem3
;
6291 /* Add nil, nil, nil, nil at the end. */
6292 i
= menu_bar_items_index
;
6293 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
6296 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
6297 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
6298 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
6299 menu_bar_items_vector
= tem
;
6301 /* Add this item. */
6302 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
6303 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
6304 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
6305 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
6306 menu_bar_items_index
= i
;
6308 Vinhibit_quit
= oquit
;
6310 return menu_bar_items_vector
;
6313 /* Scan one map KEYMAP, accumulating any menu items it defines
6314 in menu_bar_items_vector. */
6316 static Lisp_Object menu_bar_one_keymap_changed_items
;
6319 menu_bar_one_keymap (keymap
)
6322 Lisp_Object tail
, item
;
6324 /* If KEYMAP is a symbol, its function definition is the keymap
6326 if (SYMBOLP (keymap
))
6327 keymap
= indirect_function (keymap
);
6329 menu_bar_one_keymap_changed_items
= Qnil
;
6331 /* Loop over all keymap entries that have menu strings. */
6332 for (tail
= keymap
; CONSP (tail
); tail
= XCDR (tail
))
6336 menu_bar_item (XCAR (item
), XCDR (item
));
6337 else if (VECTORP (item
))
6339 /* Loop over the char values represented in the vector. */
6340 int len
= XVECTOR (item
)->size
;
6342 for (c
= 0; c
< len
; c
++)
6344 Lisp_Object character
;
6345 XSETFASTINT (character
, c
);
6346 menu_bar_item (character
, XVECTOR (item
)->contents
[c
]);
6352 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
6353 If there's already an item for KEY, add this DEF to it. */
6355 Lisp_Object item_properties
;
6358 menu_bar_item (key
, item
)
6359 Lisp_Object key
, item
;
6361 struct gcpro gcpro1
;
6365 if (EQ (item
, Qundefined
))
6367 /* If a map has an explicit `undefined' as definition,
6368 discard any previously made menu bar item. */
6370 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
6371 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
6373 if (menu_bar_items_index
> i
+ 4)
6374 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
6375 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
6376 (menu_bar_items_index
- i
- 4) * sizeof (Lisp_Object
));
6377 menu_bar_items_index
-= 4;
6381 /* If this keymap has already contributed to this KEY,
6382 don't contribute to it a second time. */
6383 tem
= Fmemq (key
, menu_bar_one_keymap_changed_items
);
6384 if (!NILP (tem
) || NILP (item
))
6387 menu_bar_one_keymap_changed_items
6388 = Fcons (key
, menu_bar_one_keymap_changed_items
);
6390 /* We add to menu_bar_one_keymap_changed_items before doing the
6391 parse_menu_item, so that if it turns out it wasn't a menu item,
6392 it still correctly hides any further menu item. */
6394 i
= parse_menu_item (item
, 0, 1);
6399 item
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
6401 /* Find any existing item for this KEY. */
6402 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
6403 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
6406 /* If we did not find this KEY, add it at the end. */
6407 if (i
== menu_bar_items_index
)
6409 /* If vector is too small, get a bigger one. */
6410 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
6413 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
6414 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
6415 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
6416 menu_bar_items_vector
= tem
;
6419 /* Add this item. */
6420 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = key
;
6421 XVECTOR (menu_bar_items_vector
)->contents
[i
++]
6422 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
6423 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Fcons (item
, Qnil
);
6424 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = make_number (0);
6425 menu_bar_items_index
= i
;
6427 /* We did find an item for this KEY. Add ITEM to its list of maps. */
6431 old
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
6432 XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2] = Fcons (item
, old
);
6436 /* This is used as the handler when calling menu_item_eval_property. */
6438 menu_item_eval_property_1 (arg
)
6441 /* If we got a quit from within the menu computation,
6442 quit all the way out of it. This takes care of C-] in the debugger. */
6443 if (CONSP (arg
) && EQ (XCAR (arg
), Qquit
))
6444 Fsignal (Qquit
, Qnil
);
6449 /* Evaluate an expression and return the result (or nil if something
6450 went wrong). Used to evaluate dynamic parts of menu items. */
6452 menu_item_eval_property (sexpr
)
6455 int count
= specpdl_ptr
- specpdl
;
6457 specbind (Qinhibit_redisplay
, Qt
);
6458 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
,
6459 menu_item_eval_property_1
);
6460 return unbind_to (count
, val
);
6463 /* This function parses a menu item and leaves the result in the
6464 vector item_properties.
6465 ITEM is a key binding, a possible menu item.
6466 If NOTREAL is nonzero, only check for equivalent key bindings, don't
6467 evaluate dynamic expressions in the menu item.
6468 INMENUBAR is > 0 when this is considered for an entry in a menu bar
6470 INMENUBAR is < 0 when this is considered for an entry in a keyboard menu.
6471 parse_menu_item returns true if the item is a menu item and false
6475 parse_menu_item (item
, notreal
, inmenubar
)
6477 int notreal
, inmenubar
;
6479 Lisp_Object def
, tem
, item_string
, start
;
6480 Lisp_Object cachelist
;
6482 Lisp_Object keyhint
;
6493 /* Create item_properties vector if necessary. */
6494 if (NILP (item_properties
))
6496 = Fmake_vector (make_number (ITEM_PROPERTY_ENABLE
+ 1), Qnil
);
6498 /* Initialize optional entries. */
6499 for (i
= ITEM_PROPERTY_DEF
; i
< ITEM_PROPERTY_ENABLE
; i
++)
6500 AREF (item_properties
, i
) = Qnil
;
6501 AREF (item_properties
, ITEM_PROPERTY_ENABLE
) = Qt
;
6503 /* Save the item here to protect it from GC. */
6504 AREF (item_properties
, ITEM_PROPERTY_ITEM
) = item
;
6506 item_string
= XCAR (item
);
6510 if (STRINGP (item_string
))
6512 /* Old format menu item. */
6513 AREF (item_properties
, ITEM_PROPERTY_NAME
) = item_string
;
6515 /* Maybe help string. */
6516 if (CONSP (item
) && STRINGP (XCAR (item
)))
6518 AREF (item_properties
, ITEM_PROPERTY_HELP
) = XCAR (item
);
6523 /* Maybe key binding cache. */
6524 if (CONSP (item
) && CONSP (XCAR (item
))
6525 && (NILP (XCAR (XCAR (item
)))
6526 || VECTORP (XCAR (XCAR (item
)))))
6528 cachelist
= XCAR (item
);
6532 /* This is the real definition--the function to run. */
6533 AREF (item_properties
, ITEM_PROPERTY_DEF
) = item
;
6535 /* Get enable property, if any. */
6538 tem
= Fget (item
, Qmenu_enable
);
6540 AREF (item_properties
, ITEM_PROPERTY_ENABLE
) = tem
;
6543 else if (EQ (item_string
, Qmenu_item
) && CONSP (item
))
6545 /* New format menu item. */
6546 AREF (item_properties
, ITEM_PROPERTY_NAME
) = XCAR (item
);
6547 start
= XCDR (item
);
6550 /* We have a real binding. */
6551 AREF (item_properties
, ITEM_PROPERTY_DEF
) = XCAR (start
);
6553 item
= XCDR (start
);
6554 /* Is there a cache list with key equivalences. */
6555 if (CONSP (item
) && CONSP (XCAR (item
)))
6557 cachelist
= XCAR (item
);
6561 /* Parse properties. */
6562 while (CONSP (item
) && CONSP (XCDR (item
)))
6567 if (EQ (tem
, QCenable
))
6568 AREF (item_properties
, ITEM_PROPERTY_ENABLE
) = XCAR (item
);
6569 else if (EQ (tem
, QCvisible
) && !notreal
)
6571 /* If got a visible property and that evaluates to nil
6572 then ignore this item. */
6573 tem
= menu_item_eval_property (XCAR (item
));
6577 else if (EQ (tem
, QChelp
))
6578 AREF (item_properties
, ITEM_PROPERTY_HELP
) = XCAR (item
);
6579 else if (EQ (tem
, QCfilter
))
6581 else if (EQ (tem
, QCkey_sequence
))
6584 if (NILP (cachelist
)
6585 && (SYMBOLP (tem
) || STRINGP (tem
) || VECTORP (tem
)))
6586 /* Be GC protected. Set keyhint to item instead of tem. */
6589 else if (EQ (tem
, QCkeys
))
6592 if (CONSP (tem
) || (STRINGP (tem
) && NILP (cachelist
)))
6593 AREF (item_properties
, ITEM_PROPERTY_KEYEQ
) = tem
;
6595 else if (EQ (tem
, QCbutton
) && CONSP (XCAR (item
)))
6600 if (EQ (type
, QCtoggle
) || EQ (type
, QCradio
))
6602 AREF (item_properties
, ITEM_PROPERTY_SELECTED
)
6604 AREF (item_properties
, ITEM_PROPERTY_TYPE
)
6611 else if (inmenubar
|| !NILP (start
))
6615 return 0; /* not a menu item */
6617 /* If item string is not a string, evaluate it to get string.
6618 If we don't get a string, skip this item. */
6619 item_string
= AREF (item_properties
, ITEM_PROPERTY_NAME
);
6620 if (!(STRINGP (item_string
) || notreal
))
6622 item_string
= menu_item_eval_property (item_string
);
6623 if (!STRINGP (item_string
))
6625 AREF (item_properties
, ITEM_PROPERTY_NAME
) = item_string
;
6628 /* If got a filter apply it on definition. */
6629 def
= AREF (item_properties
, ITEM_PROPERTY_DEF
);
6632 def
= menu_item_eval_property (list2 (XCAR (filter
),
6633 list2 (Qquote
, def
)));
6635 AREF (item_properties
, ITEM_PROPERTY_DEF
) = def
;
6638 /* If we got no definition, this item is just unselectable text which
6639 is OK in a submenu but not in the menubar. */
6641 return (inmenubar
? 0 : 1);
6643 /* Enable or disable selection of item. */
6644 tem
= AREF (item_properties
, ITEM_PROPERTY_ENABLE
);
6650 tem
= menu_item_eval_property (tem
);
6651 if (inmenubar
&& NILP (tem
))
6652 return 0; /* Ignore disabled items in menu bar. */
6653 AREF (item_properties
, ITEM_PROPERTY_ENABLE
) = tem
;
6656 /* See if this is a separate pane or a submenu. */
6657 def
= AREF (item_properties
, ITEM_PROPERTY_DEF
);
6658 tem
= get_keymap_1 (def
, 0, 1);
6659 /* For a subkeymap, just record its details and exit. */
6662 AREF (item_properties
, ITEM_PROPERTY_MAP
) = tem
;
6663 AREF (item_properties
, ITEM_PROPERTY_DEF
) = tem
;
6667 /* At the top level in the menu bar, do likewise for commands also.
6668 The menu bar does not display equivalent key bindings anyway.
6669 ITEM_PROPERTY_DEF is already set up properly. */
6673 /* This is a command. See if there is an equivalent key binding. */
6674 if (NILP (cachelist
))
6676 /* We have to create a cachelist. */
6677 CHECK_IMPURE (start
);
6678 XCDR (start
) = Fcons (Fcons (Qnil
, Qnil
), XCDR (start
));
6679 cachelist
= XCAR (XCDR (start
));
6681 tem
= AREF (item_properties
, ITEM_PROPERTY_KEYEQ
);
6682 if (!NILP (keyhint
))
6684 XCAR (cachelist
) = XCAR (keyhint
);
6687 else if (STRINGP (tem
))
6689 XCDR (cachelist
) = Fsubstitute_command_keys (tem
);
6690 XCAR (cachelist
) = Qt
;
6694 tem
= XCAR (cachelist
);
6701 tem
= Fkey_binding (tem
, Qnil
);
6703 prefix
= AREF (item_properties
, ITEM_PROPERTY_KEYEQ
);
6706 def
= XCAR (prefix
);
6707 prefix
= XCDR (prefix
);
6710 def
= AREF (item_properties
, ITEM_PROPERTY_DEF
);
6712 if (!update_menu_bindings
)
6714 else if (NILP (XCAR (cachelist
))) /* Have no saved key. */
6716 if (newcache
/* Always check first time. */
6717 /* Should we check everything when precomputing key
6719 /* If something had no key binding before, don't recheck it
6720 because that is too slow--except if we have a list of
6721 rebound commands in Vdefine_key_rebound_commands, do
6722 recheck any command that appears in that list. */
6723 || (CONSP (Vdefine_key_rebound_commands
)
6724 && !NILP (Fmemq (def
, Vdefine_key_rebound_commands
))))
6727 /* We had a saved key. Is it still bound to the command? */
6730 /* If the command is an alias for another
6731 (such as lmenu.el set it up), check if the
6732 original command matches the cached command. */
6733 && !(SYMBOLP (def
) && EQ (tem
, XSYMBOL (def
)->function
))))
6734 chkcache
= 1; /* Need to recompute key binding. */
6738 /* Recompute equivalent key binding. If the command is an alias
6739 for another (such as lmenu.el set it up), see if the original
6740 command name has equivalent keys. Otherwise look up the
6741 specified command itself. We don't try both, because that
6742 makes lmenu menus slow. */
6744 && SYMBOLP (XSYMBOL (def
)->function
)
6745 && ! NILP (Fget (def
, Qmenu_alias
)))
6746 def
= XSYMBOL (def
)->function
;
6747 tem
= Fwhere_is_internal (def
, Qnil
, Qt
, Qnil
);
6748 XCAR (cachelist
) = tem
;
6751 XCDR (cachelist
) = Qnil
;
6755 else if (!NILP (keyhint
) && !NILP (XCAR (cachelist
)))
6757 tem
= XCAR (cachelist
);
6761 newcache
= chkcache
;
6764 tem
= Fkey_description (tem
);
6767 if (STRINGP (XCAR (prefix
)))
6768 tem
= concat2 (XCAR (prefix
), tem
);
6769 if (STRINGP (XCDR (prefix
)))
6770 tem
= concat2 (tem
, XCDR (prefix
));
6772 XCDR (cachelist
) = tem
;
6776 tem
= XCDR (cachelist
);
6777 if (newcache
&& !NILP (tem
))
6779 tem
= concat3 (build_string (" ("), tem
, build_string (")"));
6780 XCDR (cachelist
) = tem
;
6783 /* If we only want to precompute equivalent key bindings, stop here. */
6787 /* If we have an equivalent key binding, use that. */
6788 AREF (item_properties
, ITEM_PROPERTY_KEYEQ
) = tem
;
6790 /* Include this when menu help is implemented.
6791 tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP];
6792 if (!(NILP (tem) || STRINGP (tem)))
6794 tem = menu_item_eval_property (tem);
6797 XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP] = tem;
6801 /* Handle radio buttons or toggle boxes. */
6802 tem
= AREF (item_properties
, ITEM_PROPERTY_SELECTED
);
6804 AREF (item_properties
, ITEM_PROPERTY_SELECTED
)
6805 = menu_item_eval_property (tem
);
6812 /***********************************************************************
6814 ***********************************************************************/
6816 /* A vector holding tool bar items while they are parsed in function
6817 tool_bar_items runs Each item occupies TOOL_BAR_ITEM_NSCLOTS elements
6820 static Lisp_Object tool_bar_items_vector
;
6822 /* A vector holding the result of parse_tool_bar_item. Layout is like
6823 the one for a single item in tool_bar_items_vector. */
6825 static Lisp_Object tool_bar_item_properties
;
6827 /* Next free index in tool_bar_items_vector. */
6829 static int ntool_bar_items
;
6831 /* The symbols `tool-bar', and `:image'. */
6833 extern Lisp_Object Qtool_bar
;
6834 Lisp_Object QCimage
;
6836 /* Function prototypes. */
6838 static void init_tool_bar_items
P_ ((Lisp_Object
));
6839 static void process_tool_bar_item
P_ ((Lisp_Object
, Lisp_Object
));
6840 static int parse_tool_bar_item
P_ ((Lisp_Object
, Lisp_Object
));
6841 static void append_tool_bar_item
P_ ((void));
6844 /* Return a vector of tool bar items for keymaps currently in effect.
6845 Reuse vector REUSE if non-nil. Return in *NITEMS the number of
6846 tool bar items found. */
6849 tool_bar_items (reuse
, nitems
)
6857 extern Lisp_Object Voverriding_local_map_menu_flag
;
6858 extern Lisp_Object Voverriding_local_map
;
6862 /* In order to build the menus, we need to call the keymap
6863 accessors. They all call QUIT. But this function is called
6864 during redisplay, during which a quit is fatal. So inhibit
6865 quitting while building the menus. We do this instead of
6866 specbind because (1) errors will clear it anyway and (2) this
6867 avoids risk of specpdl overflow. */
6868 oquit
= Vinhibit_quit
;
6871 /* Initialize tool_bar_items_vector and protect it from GC. */
6872 init_tool_bar_items (reuse
);
6874 /* Build list of keymaps in maps. Set nmaps to the number of maps
6877 /* Should overriding-terminal-local-map and overriding-local-map apply? */
6878 if (!NILP (Voverriding_local_map_menu_flag
))
6880 /* Yes, use them (if non-nil) as well as the global map. */
6881 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
6883 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
6884 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
6885 if (!NILP (Voverriding_local_map
))
6886 maps
[nmaps
++] = Voverriding_local_map
;
6890 /* No, so use major and minor mode keymaps and keymap property. */
6892 Lisp_Object map
= get_local_map (PT
, current_buffer
, keymap
);
6895 nmaps
= current_minor_maps (NULL
, &tmaps
);
6896 maps
= (Lisp_Object
*) alloca ((nmaps
+ extra_maps
)
6897 * sizeof (maps
[0]));
6898 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
6900 maps
[nmaps
++] = map
;
6901 maps
[nmaps
++] = get_local_map (PT
, current_buffer
, local_map
);
6904 /* Add global keymap at the end. */
6905 maps
[nmaps
++] = current_global_map
;
6907 /* Process maps in reverse order and look up in each map the prefix
6909 for (i
= nmaps
- 1; i
>= 0; --i
)
6910 if (!NILP (maps
[i
]))
6914 /* Why set the `noinherit' flag ? -sm */
6915 keymap
= access_keymap (maps
[i
], Qtool_bar
, 1, 1, 0);
6916 if (!NILP (Fkeymapp (keymap
)))
6920 /* If KEYMAP is a symbol, its function definition is the
6922 if (SYMBOLP (keymap
))
6923 keymap
= indirect_function (keymap
);
6925 /* KEYMAP is a list `(keymap (KEY . BINDING) ...)'. */
6926 for (tail
= keymap
; CONSP (tail
); tail
= XCDR (tail
))
6928 Lisp_Object keydef
= XCAR (tail
);
6930 process_tool_bar_item (XCAR (keydef
), XCDR (keydef
));
6935 Vinhibit_quit
= oquit
;
6936 *nitems
= ntool_bar_items
/ TOOL_BAR_ITEM_NSLOTS
;
6937 return tool_bar_items_vector
;
6941 /* Process the definition of KEY which is DEF. */
6944 process_tool_bar_item (key
, def
)
6945 Lisp_Object key
, def
;
6948 extern Lisp_Object Qundefined
;
6949 struct gcpro gcpro1
, gcpro2
;
6951 /* Protect KEY and DEF from GC because parse_tool_bar_item may call
6955 if (EQ (def
, Qundefined
))
6957 /* If a map has an explicit `undefined' as definition,
6958 discard any previously made item. */
6959 for (i
= 0; i
< ntool_bar_items
; i
+= TOOL_BAR_ITEM_NSLOTS
)
6961 Lisp_Object
*v
= XVECTOR (tool_bar_items_vector
)->contents
+ i
;
6963 if (EQ (key
, v
[TOOL_BAR_ITEM_KEY
]))
6965 if (ntool_bar_items
> i
+ TOOL_BAR_ITEM_NSLOTS
)
6966 bcopy (v
+ TOOL_BAR_ITEM_NSLOTS
, v
,
6967 ((ntool_bar_items
- i
- TOOL_BAR_ITEM_NSLOTS
)
6968 * sizeof (Lisp_Object
)));
6969 ntool_bar_items
-= TOOL_BAR_ITEM_NSLOTS
;
6974 else if (parse_tool_bar_item (key
, def
))
6975 /* Append a new tool bar item to tool_bar_items_vector. Accept
6976 more than one definition for the same key. */
6977 append_tool_bar_item ();
6983 /* Parse a tool bar item specification ITEM for key KEY and return the
6984 result in tool_bar_item_properties. Value is zero if ITEM is
6987 ITEM is a list `(menu-item CAPTION BINDING PROPS...)'.
6989 CAPTION is the caption of the item, If it's not a string, it is
6990 evaluated to get a string.
6992 BINDING is the tool bar item's binding. Tool-bar items with keymaps
6993 as binding are currently ignored.
6995 The following properties are recognized:
6999 FORM is evaluated and specifies whether the tool bar item is
7000 enabled or disabled.
7004 FORM is evaluated and specifies whether the tool bar item is visible.
7006 - `:filter FUNCTION'
7008 FUNCTION is invoked with one parameter `(quote BINDING)'. Its
7009 result is stored as the new binding.
7011 - `:button (TYPE SELECTED)'
7013 TYPE must be one of `:radio' or `:toggle'. SELECTED is evaluated
7014 and specifies whether the button is selected (pressed) or not.
7018 IMAGES is either a single image specification or a vector of four
7019 image specifications. See enum tool_bar_item_images.
7021 - `:help HELP-STRING'.
7023 Gives a help string to display for the tool bar item. */
7026 parse_tool_bar_item (key
, item
)
7027 Lisp_Object key
, item
;
7029 /* Access slot with index IDX of vector tool_bar_item_properties. */
7030 #define PROP(IDX) XVECTOR (tool_bar_item_properties)->contents[IDX]
7032 Lisp_Object filter
= Qnil
;
7033 Lisp_Object caption
;
7034 extern Lisp_Object QCenable
, QCvisible
, QChelp
, QCfilter
;
7035 extern Lisp_Object QCbutton
, QCtoggle
, QCradio
;
7038 /* Defininition looks like `(menu-item CAPTION BINDING PROPS...)'.
7039 Rule out items that aren't lists, don't start with
7040 `menu-item' or whose rest following `tool-bar-item' is not a
7043 || !EQ (XCAR (item
), Qmenu_item
)
7044 || (item
= XCDR (item
),
7048 /* Create tool_bar_item_properties vector if necessary. Reset it to
7050 if (VECTORP (tool_bar_item_properties
))
7052 for (i
= 0; i
< TOOL_BAR_ITEM_NSLOTS
; ++i
)
7056 tool_bar_item_properties
7057 = Fmake_vector (make_number (TOOL_BAR_ITEM_NSLOTS
), Qnil
);
7060 PROP (TOOL_BAR_ITEM_KEY
) = key
;
7061 PROP (TOOL_BAR_ITEM_ENABLED_P
) = Qt
;
7063 /* Get the caption of the item. If the caption is not a string,
7064 evaluate it to get a string. If we don't get a string, skip this
7066 caption
= XCAR (item
);
7067 if (!STRINGP (caption
))
7069 caption
= menu_item_eval_property (caption
);
7070 if (!STRINGP (caption
))
7073 PROP (TOOL_BAR_ITEM_CAPTION
) = caption
;
7075 /* Give up if rest following the caption is not a list. */
7080 /* Store the binding. */
7081 PROP (TOOL_BAR_ITEM_BINDING
) = XCAR (item
);
7084 /* Ignore cached key binding, if any. */
7085 if (CONSP (item
) && CONSP (XCAR (item
)))
7088 /* Process the rest of the properties. */
7089 for (; CONSP (item
) && CONSP (XCDR (item
)); item
= XCDR (XCDR (item
)))
7091 Lisp_Object key
, value
;
7094 value
= XCAR (XCDR (item
));
7096 if (EQ (key
, QCenable
))
7097 /* `:enable FORM'. */
7098 PROP (TOOL_BAR_ITEM_ENABLED_P
) = value
;
7099 else if (EQ (key
, QCvisible
))
7101 /* `:visible FORM'. If got a visible property and that
7102 evaluates to nil then ignore this item. */
7103 if (NILP (menu_item_eval_property (value
)))
7106 else if (EQ (key
, QChelp
))
7107 /* `:help HELP-STRING'. */
7108 PROP (TOOL_BAR_ITEM_HELP
) = value
;
7109 else if (EQ (key
, QCfilter
))
7110 /* ':filter FORM'. */
7112 else if (EQ (key
, QCbutton
) && CONSP (value
))
7114 /* `:button (TYPE . SELECTED)'. */
7115 Lisp_Object type
, selected
;
7117 type
= XCAR (value
);
7118 selected
= XCDR (value
);
7119 if (EQ (type
, QCtoggle
) || EQ (type
, QCradio
))
7121 PROP (TOOL_BAR_ITEM_SELECTED_P
) = selected
;
7122 PROP (TOOL_BAR_ITEM_TYPE
) = type
;
7125 else if (EQ (key
, QCimage
)
7127 || (VECTORP (value
) && XVECTOR (value
)->size
== 4)))
7128 /* Value is either a single image specification or a vector
7129 of 4 such specifications for the different buttion states. */
7130 PROP (TOOL_BAR_ITEM_IMAGES
) = value
;
7133 /* If got a filter apply it on binding. */
7135 PROP (TOOL_BAR_ITEM_BINDING
)
7136 = menu_item_eval_property (list2 (filter
,
7138 PROP (TOOL_BAR_ITEM_BINDING
))));
7140 /* See if the binding is a keymap. Give up if it is. */
7141 if (!NILP (get_keymap_1 (PROP (TOOL_BAR_ITEM_BINDING
), 0, 1)))
7144 /* Enable or disable selection of item. */
7145 if (!EQ (PROP (TOOL_BAR_ITEM_ENABLED_P
), Qt
))
7146 PROP (TOOL_BAR_ITEM_ENABLED_P
)
7147 = menu_item_eval_property (PROP (TOOL_BAR_ITEM_ENABLED_P
));
7149 /* Handle radio buttons or toggle boxes. */
7150 if (!NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
)))
7151 PROP (TOOL_BAR_ITEM_SELECTED_P
)
7152 = menu_item_eval_property (PROP (TOOL_BAR_ITEM_SELECTED_P
));
7160 /* Initialize tool_bar_items_vector. REUSE, if non-nil, is a vector
7161 that can be reused. */
7164 init_tool_bar_items (reuse
)
7167 if (VECTORP (reuse
))
7168 tool_bar_items_vector
= reuse
;
7170 tool_bar_items_vector
= Fmake_vector (make_number (64), Qnil
);
7171 ntool_bar_items
= 0;
7175 /* Append parsed tool bar item properties from
7176 tool_bar_item_properties */
7179 append_tool_bar_item ()
7181 Lisp_Object
*to
, *from
;
7183 /* Enlarge tool_bar_items_vector if necessary. */
7184 if (ntool_bar_items
+ TOOL_BAR_ITEM_NSLOTS
7185 >= XVECTOR (tool_bar_items_vector
)->size
)
7187 Lisp_Object new_vector
;
7188 int old_size
= XVECTOR (tool_bar_items_vector
)->size
;
7190 new_vector
= Fmake_vector (make_number (2 * old_size
), Qnil
);
7191 bcopy (XVECTOR (tool_bar_items_vector
)->contents
,
7192 XVECTOR (new_vector
)->contents
,
7193 old_size
* sizeof (Lisp_Object
));
7194 tool_bar_items_vector
= new_vector
;
7197 /* Append entries from tool_bar_item_properties to the end of
7198 tool_bar_items_vector. */
7199 to
= XVECTOR (tool_bar_items_vector
)->contents
+ ntool_bar_items
;
7200 from
= XVECTOR (tool_bar_item_properties
)->contents
;
7201 bcopy (from
, to
, TOOL_BAR_ITEM_NSLOTS
* sizeof *to
);
7202 ntool_bar_items
+= TOOL_BAR_ITEM_NSLOTS
;
7209 /* Read a character using menus based on maps in the array MAPS.
7210 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
7211 Return t if we displayed a menu but the user rejected it.
7213 PREV_EVENT is the previous input event, or nil if we are reading
7214 the first event of a key sequence.
7216 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
7217 if we used a mouse menu to read the input, or zero otherwise. If
7218 USED_MOUSE_MENU is null, we don't dereference it.
7220 The prompting is done based on the prompt-string of the map
7221 and the strings associated with various map elements.
7223 This can be done with X menus or with menus put in the minibuf.
7224 These are done in different ways, depending on how the input will be read.
7225 Menus using X are done after auto-saving in read-char, getting the input
7226 event from Fx_popup_menu; menus using the minibuf use read_char recursively
7227 and do auto-saving in the inner call of read_char. */
7230 read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
7233 Lisp_Object prev_event
;
7234 int *used_mouse_menu
;
7237 register Lisp_Object name
;
7239 if (used_mouse_menu
)
7240 *used_mouse_menu
= 0;
7242 /* Use local over global Menu maps */
7244 if (! menu_prompting
)
7247 /* Optionally disregard all but the global map. */
7248 if (inhibit_local_menu_bar_menus
)
7250 maps
+= (nmaps
- 1);
7254 /* Get the menu name from the first map that has one (a prompt string). */
7255 for (mapno
= 0; mapno
< nmaps
; mapno
++)
7257 name
= map_prompt (maps
[mapno
]);
7262 /* If we don't have any menus, just read a character normally. */
7267 /* If we got to this point via a mouse click,
7268 use a real menu for mouse selection. */
7269 if (EVENT_HAS_PARAMETERS (prev_event
)
7270 && !EQ (XCAR (prev_event
), Qmenu_bar
)
7271 && !EQ (XCAR (prev_event
), Qtool_bar
))
7273 /* Display the menu and get the selection. */
7274 Lisp_Object
*realmaps
7275 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
7279 /* Use the maps that are not nil. */
7280 for (mapno
= 0; mapno
< nmaps
; mapno
++)
7281 if (!NILP (maps
[mapno
]))
7282 realmaps
[nmaps1
++] = maps
[mapno
];
7284 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
7289 record_menu_key (XCAR (value
));
7291 /* If we got multiple events, unread all but
7293 There is no way to prevent those unread events
7294 from showing up later in last_nonmenu_event.
7295 So turn symbol and integer events into lists,
7296 to indicate that they came from a mouse menu,
7297 so that when present in last_nonmenu_event
7298 they won't confuse things. */
7299 for (tem
= XCDR (value
); !NILP (tem
);
7302 record_menu_key (XCAR (tem
));
7303 if (SYMBOLP (XCAR (tem
))
7304 || INTEGERP (XCAR (tem
)))
7306 = Fcons (XCAR (tem
), Qnil
);
7309 /* If we got more than one event, put all but the first
7310 onto this list to be read later.
7311 Return just the first event now. */
7312 Vunread_command_events
7313 = nconc2 (XCDR (value
), Vunread_command_events
);
7314 value
= XCAR (value
);
7316 else if (NILP (value
))
7318 if (used_mouse_menu
)
7319 *used_mouse_menu
= 1;
7322 #endif /* HAVE_MENUS */
7326 /* Buffer in use so far for the minibuf prompts for menu keymaps.
7327 We make this bigger when necessary, and never free it. */
7328 static char *read_char_minibuf_menu_text
;
7329 /* Size of that buffer. */
7330 static int read_char_minibuf_menu_width
;
7333 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
7339 register Lisp_Object name
;
7341 int width
= FRAME_WIDTH (SELECTED_FRAME ()) - 4;
7344 Lisp_Object rest
, vector
;
7349 if (! menu_prompting
)
7352 /* Make sure we have a big enough buffer for the menu text. */
7353 if (read_char_minibuf_menu_text
== 0)
7355 read_char_minibuf_menu_width
= width
+ 4;
7356 read_char_minibuf_menu_text
= (char *) xmalloc (width
+ 4);
7358 else if (width
+ 4 > read_char_minibuf_menu_width
)
7360 read_char_minibuf_menu_width
= width
+ 4;
7361 read_char_minibuf_menu_text
7362 = (char *) xrealloc (read_char_minibuf_menu_text
, width
+ 4);
7364 menu
= read_char_minibuf_menu_text
;
7366 /* Get the menu name from the first map that has one (a prompt string). */
7367 for (mapno
= 0; mapno
< nmaps
; mapno
++)
7369 name
= map_prompt (maps
[mapno
]);
7374 /* If we don't have any menus, just read a character normally. */
7378 /* Prompt string always starts with map's prompt, and a space. */
7379 strcpy (menu
, XSTRING (name
)->data
);
7380 nlength
= STRING_BYTES (XSTRING (name
));
7381 menu
[nlength
++] = ':';
7382 menu
[nlength
++] = ' ';
7385 /* Start prompting at start of first map. */
7389 /* Present the documented bindings, a line at a time. */
7396 Lisp_Object orig_defn_macro
;
7398 /* Loop over elements of map. */
7403 /* If reached end of map, start at beginning of next map. */
7407 /* At end of last map, wrap around to first map if just starting,
7408 or end this line if already have something on it. */
7412 if (notfirst
|| nobindings
) break;
7417 /* Look at the next element of the map. */
7419 elt
= XVECTOR (vector
)->contents
[idx
];
7421 elt
= Fcar_safe (rest
);
7423 if (idx
< 0 && VECTORP (elt
))
7425 /* If we found a dense table in the keymap,
7426 advanced past it, but start scanning its contents. */
7427 rest
= Fcdr_safe (rest
);
7433 /* An ordinary element. */
7434 Lisp_Object event
, tem
;
7438 event
= Fcar_safe (elt
); /* alist */
7439 elt
= Fcdr_safe (elt
);
7443 XSETINT (event
, idx
); /* vector */
7446 /* Ignore the element if it has no prompt string. */
7447 if (INTEGERP (event
) && parse_menu_item (elt
, 0, -1))
7449 /* 1 if the char to type matches the string. */
7451 Lisp_Object upcased_event
, downcased_event
;
7452 Lisp_Object desc
= Qnil
;
7454 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
7456 upcased_event
= Fupcase (event
);
7457 downcased_event
= Fdowncase (event
);
7458 char_matches
= (XINT (upcased_event
) == XSTRING (s
)->data
[0]
7459 || XINT (downcased_event
) == XSTRING (s
)->data
[0]);
7461 desc
= Fsingle_key_description (event
, Qnil
);
7464 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
7466 /* Insert equivalent keybinding. */
7467 s
= concat2 (s
, tem
);
7470 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_TYPE
];
7471 if (EQ (tem
, QCradio
) || EQ (tem
, QCtoggle
))
7473 /* Insert button prefix. */
7474 Lisp_Object selected
7475 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
];
7476 if (EQ (tem
, QCradio
))
7477 tem
= build_string (NILP (selected
) ? "(*) " : "( ) ");
7479 tem
= build_string (NILP (selected
) ? "[X] " : "[ ] ");
7480 s
= concat2 (tem
, s
);
7484 /* If we have room for the prompt string, add it to this line.
7485 If this is the first on the line, always add it. */
7486 if ((XSTRING (s
)->size
+ i
+ 2
7487 + (char_matches
? 0 : XSTRING (desc
)->size
+ 3))
7493 /* Punctuate between strings. */
7496 strcpy (menu
+ i
, ", ");
7502 /* If the char to type doesn't match the string's
7503 first char, explicitly show what char to type. */
7506 /* Add as much of string as fits. */
7507 thiswidth
= XSTRING (desc
)->size
;
7508 if (thiswidth
+ i
> width
)
7509 thiswidth
= width
- i
;
7510 bcopy (XSTRING (desc
)->data
, menu
+ i
, thiswidth
);
7512 strcpy (menu
+ i
, " = ");
7516 /* Add as much of string as fits. */
7517 thiswidth
= XSTRING (s
)->size
;
7518 if (thiswidth
+ i
> width
)
7519 thiswidth
= width
- i
;
7520 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
7526 /* If this element does not fit, end the line now,
7527 and save the element for the next line. */
7528 strcpy (menu
+ i
, "...");
7533 /* Move past this element. */
7534 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
7535 /* Handle reaching end of dense table. */
7540 rest
= Fcdr_safe (rest
);
7544 /* Prompt with that and read response. */
7545 message2_nolog (menu
, strlen (menu
),
7546 ! NILP (current_buffer
->enable_multibyte_characters
));
7548 /* Make believe its not a keyboard macro in case the help char
7549 is pressed. Help characters are not recorded because menu prompting
7550 is not used on replay.
7552 orig_defn_macro
= current_kboard
->defining_kbd_macro
;
7553 current_kboard
->defining_kbd_macro
= Qnil
;
7555 obj
= read_char (commandflag
, 0, 0, Qt
, 0);
7556 while (BUFFERP (obj
));
7557 current_kboard
->defining_kbd_macro
= orig_defn_macro
;
7559 if (!INTEGERP (obj
))
7564 if (! EQ (obj
, menu_prompt_more_char
)
7565 && (!INTEGERP (menu_prompt_more_char
)
7566 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
7568 if (!NILP (current_kboard
->defining_kbd_macro
))
7569 store_kbd_macro_char (obj
);
7572 /* Help char - go round again */
7576 /* Reading key sequences. */
7578 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
7579 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
7580 keymap, or nil otherwise. Return the index of the first keymap in
7581 which KEY has any binding, or NMAPS if no map has a binding.
7583 If KEY is a meta ASCII character, treat it like meta-prefix-char
7584 followed by the corresponding non-meta character. Keymaps in
7585 CURRENT with non-prefix bindings for meta-prefix-char become nil in
7588 If KEY has no bindings in any of the CURRENT maps, NEXT is left
7591 NEXT may be the same array as CURRENT. */
7594 follow_key (key
, nmaps
, current
, defs
, next
)
7596 Lisp_Object
*current
, *defs
, *next
;
7599 int i
, first_binding
;
7602 first_binding
= nmaps
;
7603 for (i
= nmaps
- 1; i
>= 0; i
--)
7605 if (! NILP (current
[i
]))
7613 defs
[i
] = access_keymap (map
, key
, 1, 0, 1);
7614 if (! NILP (defs
[i
]))
7621 /* Given the set of bindings we've found, produce the next set of maps. */
7622 if (first_binding
< nmaps
)
7623 for (i
= 0; i
< nmaps
; i
++)
7624 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0, 1);
7626 return first_binding
;
7629 /* Read a sequence of keys that ends with a non prefix character,
7630 storing it in KEYBUF, a buffer of size BUFSIZE.
7632 Return the length of the key sequence stored.
7633 Return -1 if the user rejected a command menu.
7635 Echo starting immediately unless `prompt' is 0.
7637 Where a key sequence ends depends on the currently active keymaps.
7638 These include any minor mode keymaps active in the current buffer,
7639 the current buffer's local map, and the global map.
7641 If a key sequence has no other bindings, we check Vfunction_key_map
7642 to see if some trailing subsequence might be the beginning of a
7643 function key's sequence. If so, we try to read the whole function
7644 key, and substitute its symbolic name into the key sequence.
7646 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
7647 `double-' events into similar click events, if that would make them
7648 bound. We try to turn `triple-' events first into `double-' events,
7651 If we get a mouse click in a mode line, vertical divider, or other
7652 non-text area, we treat the click as if it were prefixed by the
7653 symbol denoting that area - `mode-line', `vertical-line', or
7656 If the sequence starts with a mouse click, we read the key sequence
7657 with respect to the buffer clicked on, not the current buffer.
7659 If the user switches frames in the midst of a key sequence, we put
7660 off the switch-frame event until later; the next call to
7661 read_char will return it.
7663 If FIX_CURRENT_BUFFER is nonzero, we restore current_buffer
7664 from the selected window's buffer. */
7667 read_key_sequence (keybuf
, bufsize
, prompt
, dont_downcase_last
,
7668 can_return_switch_frame
, fix_current_buffer
)
7669 Lisp_Object
*keybuf
;
7672 int dont_downcase_last
;
7673 int can_return_switch_frame
;
7674 int fix_current_buffer
;
7676 volatile int count
= specpdl_ptr
- specpdl
;
7678 /* How many keys there are in the current key sequence. */
7681 /* The length of the echo buffer when we started reading, and
7682 the length of this_command_keys when we started reading. */
7683 volatile int echo_start
;
7684 volatile int keys_start
;
7686 /* The number of keymaps we're scanning right now, and the number of
7687 keymaps we have allocated space for. */
7689 volatile int nmaps_allocated
= 0;
7691 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
7692 the current keymaps. */
7693 Lisp_Object
*volatile defs
= NULL
;
7695 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
7696 in the current keymaps, or nil where it is not a prefix. */
7697 Lisp_Object
*volatile submaps
= NULL
;
7699 /* The local map to start out with at start of key sequence. */
7700 volatile Lisp_Object orig_local_map
;
7702 /* The map from the `keymap' property to start out with at start of
7704 volatile Lisp_Object orig_keymap
;
7706 /* 1 if we have already considered switching to the local-map property
7707 of the place where a mouse click occurred. */
7708 volatile int localized_local_map
= 0;
7710 /* The index in defs[] of the first keymap that has a binding for
7711 this key sequence. In other words, the lowest i such that
7712 defs[i] is non-nil. */
7713 volatile int first_binding
;
7715 /* If t < mock_input, then KEYBUF[t] should be read as the next
7718 We use this to recover after recognizing a function key. Once we
7719 realize that a suffix of the current key sequence is actually a
7720 function key's escape sequence, we replace the suffix with the
7721 function key's binding from Vfunction_key_map. Now keybuf
7722 contains a new and different key sequence, so the echo area,
7723 this_command_keys, and the submaps and defs arrays are wrong. In
7724 this situation, we set mock_input to t, set t to 0, and jump to
7725 restart_sequence; the loop will read keys from keybuf up until
7726 mock_input, thus rebuilding the state; and then it will resume
7727 reading characters from the keyboard. */
7728 volatile int mock_input
= 0;
7730 /* If the sequence is unbound in submaps[], then
7731 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
7732 and fkey_map is its binding.
7734 These might be > t, indicating that all function key scanning
7735 should hold off until t reaches them. We do this when we've just
7736 recognized a function key, to avoid searching for the function
7737 key's again in Vfunction_key_map. */
7738 volatile int fkey_start
= 0, fkey_end
= 0;
7739 volatile Lisp_Object fkey_map
;
7741 /* Likewise, for key_translation_map. */
7742 volatile int keytran_start
= 0, keytran_end
= 0;
7743 volatile Lisp_Object keytran_map
;
7745 /* If we receive a ``switch-frame'' event in the middle of a key sequence,
7746 we put it off for later. While we're reading, we keep the event here. */
7747 volatile Lisp_Object delayed_switch_frame
;
7749 /* See the comment below... */
7750 #if defined (GOBBLE_FIRST_EVENT)
7751 Lisp_Object first_event
;
7754 volatile Lisp_Object original_uppercase
;
7755 volatile int original_uppercase_position
= -1;
7757 /* Gets around Microsoft compiler limitations. */
7760 struct buffer
*starting_buffer
;
7762 /* Nonzero if we seem to have got the beginning of a binding
7763 in function_key_map. */
7764 volatile int function_key_possible
= 0;
7765 volatile int key_translation_possible
= 0;
7767 /* Save the status of key translation before each step,
7768 so that we can restore this after downcasing. */
7769 Lisp_Object prev_fkey_map
;
7770 int prev_fkey_start
;
7773 Lisp_Object prev_keytran_map
;
7774 int prev_keytran_start
;
7775 int prev_keytran_end
;
7777 #if defined (GOBBLE_FIRST_EVENT)
7781 raw_keybuf_count
= 0;
7783 last_nonmenu_event
= Qnil
;
7785 delayed_switch_frame
= Qnil
;
7786 fkey_map
= Vfunction_key_map
;
7787 keytran_map
= Vkey_translation_map
;
7789 /* If there is no function-key-map, turn off function key scanning. */
7790 if (NILP (Fkeymapp (Vfunction_key_map
)))
7791 fkey_start
= fkey_end
= bufsize
+ 1;
7793 /* If there is no key-translation-map, turn off scanning. */
7794 if (NILP (Fkeymapp (Vkey_translation_map
)))
7795 keytran_start
= keytran_end
= bufsize
+ 1;
7800 echo_prompt (XSTRING (prompt
)->data
);
7801 else if (cursor_in_echo_area
7802 && (FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
7803 && NILP (Fzerop (Vecho_keystrokes
)))
7804 /* This doesn't put in a dash if the echo buffer is empty, so
7805 you don't always see a dash hanging out in the minibuffer. */
7809 /* Record the initial state of the echo area and this_command_keys;
7810 we will need to restore them if we replay a key sequence. */
7812 echo_start
= echo_length ();
7813 keys_start
= this_command_key_count
;
7814 this_single_command_key_start
= keys_start
;
7816 #if defined (GOBBLE_FIRST_EVENT)
7817 /* This doesn't quite work, because some of the things that read_char
7818 does cannot safely be bypassed. It seems too risky to try to make
7821 /* Read the first char of the sequence specially, before setting
7822 up any keymaps, in case a filter runs and switches buffers on us. */
7823 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
7825 #endif /* GOBBLE_FIRST_EVENT */
7827 orig_local_map
= get_local_map (PT
, current_buffer
, local_map
);
7828 orig_keymap
= get_local_map (PT
, current_buffer
, keymap
);
7830 /* We jump here when the key sequence has been thoroughly changed, and
7831 we need to rescan it starting from the beginning. When we jump here,
7832 keybuf[0..mock_input] holds the sequence we should reread. */
7835 starting_buffer
= current_buffer
;
7836 function_key_possible
= 0;
7837 key_translation_possible
= 0;
7839 /* Build our list of keymaps.
7840 If we recognize a function key and replace its escape sequence in
7841 keybuf with its symbol, or if the sequence starts with a mouse
7842 click and we need to switch buffers, we jump back here to rebuild
7843 the initial keymaps from the current buffer. */
7847 if (!NILP (current_kboard
->Voverriding_terminal_local_map
)
7848 || !NILP (Voverriding_local_map
))
7850 if (3 > nmaps_allocated
)
7852 submaps
= (Lisp_Object
*) alloca (3 * sizeof (submaps
[0]));
7853 defs
= (Lisp_Object
*) alloca (3 * sizeof (defs
[0]));
7854 nmaps_allocated
= 3;
7857 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
7858 submaps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
7859 if (!NILP (Voverriding_local_map
))
7860 submaps
[nmaps
++] = Voverriding_local_map
;
7865 nmaps
= current_minor_maps (0, &maps
);
7866 if (!NILP (orig_keymap
))
7868 if (nmaps
+ extra_maps
> nmaps_allocated
)
7870 submaps
= (Lisp_Object
*) alloca ((nmaps
+extra_maps
)
7871 * sizeof (submaps
[0]));
7872 defs
= (Lisp_Object
*) alloca ((nmaps
+extra_maps
)
7873 * sizeof (defs
[0]));
7874 nmaps_allocated
= nmaps
+ extra_maps
;
7876 bcopy (maps
, (void *) submaps
, nmaps
* sizeof (submaps
[0]));
7877 if (!NILP (orig_keymap
))
7878 submaps
[nmaps
++] = orig_keymap
;
7879 submaps
[nmaps
++] = orig_local_map
;
7881 submaps
[nmaps
++] = current_global_map
;
7884 /* Find an accurate initial value for first_binding. */
7885 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
7886 if (! NILP (submaps
[first_binding
]))
7889 /* Start from the beginning in keybuf. */
7892 /* These are no-ops the first time through, but if we restart, they
7893 revert the echo area and this_command_keys to their original state. */
7894 this_command_key_count
= keys_start
;
7895 if (INTERACTIVE
&& t
< mock_input
)
7896 echo_truncate (echo_start
);
7898 /* If the best binding for the current key sequence is a keymap, or
7899 we may be looking at a function key's escape sequence, keep on
7901 while ((first_binding
< nmaps
&& ! NILP (submaps
[first_binding
]))
7902 || (first_binding
>= nmaps
7904 /* mock input is never part of a function key's sequence. */
7905 && mock_input
<= fkey_start
)
7906 || (first_binding
>= nmaps
7907 && keytran_start
< t
&& key_translation_possible
)
7908 /* Don't return in the middle of a possible function key sequence,
7909 if the only bindings we found were via case conversion.
7910 Thus, if ESC O a has a function-key-map translation
7911 and ESC o has a binding, don't return after ESC O,
7912 so that we can translate ESC O plus the next character. */
7916 int used_mouse_menu
= 0;
7918 /* Where the last real key started. If we need to throw away a
7919 key that has expanded into more than one element of keybuf
7920 (say, a mouse click on the mode line which is being treated
7921 as [mode-line (mouse-...)], then we backtrack to this point
7923 volatile int last_real_key_start
;
7925 /* These variables are analogous to echo_start and keys_start;
7926 while those allow us to restart the entire key sequence,
7927 echo_local_start and keys_local_start allow us to throw away
7929 volatile int echo_local_start
, keys_local_start
, local_first_binding
;
7932 error ("Key sequence too long");
7935 echo_local_start
= echo_length ();
7936 keys_local_start
= this_command_key_count
;
7937 local_first_binding
= first_binding
;
7940 /* These are no-ops, unless we throw away a keystroke below and
7941 jumped back up to replay_key; in that case, these restore the
7942 variables to their original state, allowing us to replay the
7944 if (INTERACTIVE
&& t
< mock_input
)
7945 echo_truncate (echo_local_start
);
7946 this_command_key_count
= keys_local_start
;
7947 first_binding
= local_first_binding
;
7949 /* By default, assume each event is "real". */
7950 last_real_key_start
= t
;
7952 /* Does mock_input indicate that we are re-reading a key sequence? */
7956 add_command_key (key
);
7957 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
7958 && NILP (Fzerop (Vecho_keystrokes
)))
7962 /* If not, we should actually read a character. */
7967 KBOARD
*interrupted_kboard
= current_kboard
;
7968 struct frame
*interrupted_frame
= SELECTED_FRAME ();
7969 if (setjmp (wrong_kboard_jmpbuf
))
7971 if (!NILP (delayed_switch_frame
))
7973 interrupted_kboard
->kbd_queue
7974 = Fcons (delayed_switch_frame
,
7975 interrupted_kboard
->kbd_queue
);
7976 delayed_switch_frame
= Qnil
;
7979 interrupted_kboard
->kbd_queue
7980 = Fcons (keybuf
[--t
], interrupted_kboard
->kbd_queue
);
7982 /* If the side queue is non-empty, ensure it begins with a
7983 switch-frame, so we'll replay it in the right context. */
7984 if (CONSP (interrupted_kboard
->kbd_queue
)
7985 && (key
= XCAR (interrupted_kboard
->kbd_queue
),
7986 !(EVENT_HAS_PARAMETERS (key
)
7987 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)),
7991 XSETFRAME (frame
, interrupted_frame
);
7992 interrupted_kboard
->kbd_queue
7993 = Fcons (make_lispy_switch_frame (frame
),
7994 interrupted_kboard
->kbd_queue
);
7997 orig_local_map
= get_local_map (PT
, current_buffer
, local_map
);
7998 orig_keymap
= get_local_map (PT
, current_buffer
, keymap
);
7999 goto replay_sequence
;
8002 key
= read_char (NILP (prompt
), nmaps
,
8003 (Lisp_Object
*) submaps
, last_nonmenu_event
,
8007 /* read_char returns t when it shows a menu and the user rejects it.
8011 unbind_to (count
, Qnil
);
8015 /* read_char returns -1 at the end of a macro.
8016 Emacs 18 handles this by returning immediately with a
8017 zero, so that's what we'll do. */
8018 if (INTEGERP (key
) && XINT (key
) == -1)
8021 /* The Microsoft C compiler can't handle the goto that
8027 /* If the current buffer has been changed from under us, the
8028 keymap may have changed, so replay the sequence. */
8032 /* Reset the current buffer from the selected window
8033 in case something changed the former and not the latter.
8034 This is to be more consistent with the behavior
8035 of the command_loop_1. */
8036 if (fix_current_buffer
)
8038 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8040 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
8041 Fset_buffer (XWINDOW (selected_window
)->buffer
);
8044 orig_local_map
= get_local_map (PT
, current_buffer
, local_map
);
8045 orig_keymap
= get_local_map (PT
, current_buffer
, keymap
);
8046 goto replay_sequence
;
8049 /* If we have a quit that was typed in another frame, and
8050 quit_throw_to_read_char switched buffers,
8051 replay to get the right keymap. */
8052 if (XINT (key
) == quit_char
&& current_buffer
!= starting_buffer
)
8055 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
8059 orig_local_map
= get_local_map (PT
, current_buffer
, local_map
);
8060 orig_keymap
= get_local_map (PT
, current_buffer
, keymap
);
8061 goto replay_sequence
;
8066 if (EVENT_HAS_PARAMETERS (key
)
8067 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)), Qswitch_frame
))
8069 /* If we're at the beginning of a key sequence, and the caller
8070 says it's okay, go ahead and return this event. If we're
8071 in the midst of a key sequence, delay it until the end. */
8072 if (t
> 0 || !can_return_switch_frame
)
8074 delayed_switch_frame
= key
;
8080 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
8083 /* Clicks in non-text areas get prefixed by the symbol
8084 in their CHAR-ADDRESS field. For example, a click on
8085 the mode line is prefixed by the symbol `mode-line'.
8087 Furthermore, key sequences beginning with mouse clicks
8088 are read using the keymaps of the buffer clicked on, not
8089 the current buffer. So we may have to switch the buffer
8092 When we turn one event into two events, we must make sure
8093 that neither of the two looks like the original--so that,
8094 if we replay the events, they won't be expanded again.
8095 If not for this, such reexpansion could happen either here
8096 or when user programs play with this-command-keys. */
8097 if (EVENT_HAS_PARAMETERS (key
))
8101 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
8102 if (EQ (kind
, Qmouse_click
))
8104 Lisp_Object window
, posn
;
8106 window
= POSN_WINDOW (EVENT_START (key
));
8107 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
8111 /* We're looking at the second event of a
8112 sequence which we expanded before. Set
8113 last_real_key_start appropriately. */
8115 last_real_key_start
= t
- 1;
8118 /* Key sequences beginning with mouse clicks are
8119 read using the keymaps in the buffer clicked on,
8120 not the current buffer. If we're at the
8121 beginning of a key sequence, switch buffers. */
8122 if (last_real_key_start
== 0
8124 && BUFFERP (XWINDOW (window
)->buffer
)
8125 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
8127 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
8131 /* Arrange to go back to the original buffer once we're
8132 done reading the key sequence. Note that we can't
8133 use save_excursion_{save,restore} here, because they
8134 save point as well as the current buffer; we don't
8135 want to save point, because redisplay may change it,
8136 to accommodate a Fset_window_start or something. We
8137 don't want to do this at the top of the function,
8138 because we may get input from a subprocess which
8139 wants to change the selected window and stuff (say,
8141 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
8143 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8145 set_buffer_internal (XBUFFER (XWINDOW
8148 orig_local_map
= get_local_map (PT
, current_buffer
,
8150 orig_keymap
= get_local_map (PT
, current_buffer
, keymap
);
8151 goto replay_sequence
;
8154 /* For a mouse click, get the local text-property keymap
8155 of the place clicked on, rather than point. */
8156 if (last_real_key_start
== 0
8157 && CONSP (XCDR (key
))
8158 && ! localized_local_map
)
8160 Lisp_Object map_here
, start
, pos
;
8162 localized_local_map
= 1;
8163 start
= EVENT_START (key
);
8165 if (CONSP (start
) && CONSP (XCDR (start
)))
8167 pos
= POSN_BUFFER_POSN (start
);
8169 && XINT (pos
) >= BEG
&& XINT (pos
) <= Z
)
8171 map_here
= get_local_map (XINT (pos
),
8172 current_buffer
, local_map
);
8173 if (!EQ (map_here
, orig_local_map
))
8175 orig_local_map
= map_here
;
8179 goto replay_sequence
;
8181 map_here
= get_local_map (XINT (pos
),
8182 current_buffer
, keymap
);
8183 if (!EQ (map_here
, orig_keymap
))
8185 orig_keymap
= map_here
;
8189 goto replay_sequence
;
8195 /* Expand mode-line and scroll-bar events into two events:
8196 use posn as a fake prefix key. */
8199 if (t
+ 1 >= bufsize
)
8200 error ("Key sequence too long");
8205 /* Zap the position in key, so we know that we've
8206 expanded it, and don't try to do so again. */
8207 POSN_BUFFER_POSN (EVENT_START (key
))
8208 = Fcons (posn
, Qnil
);
8210 /* If on a mode line string with a local keymap,
8211 reconsider the key sequence with that keymap. */
8212 if (CONSP (POSN_STRING (EVENT_START (key
))))
8214 Lisp_Object string
, pos
, map
, map2
;
8216 string
= POSN_STRING (EVENT_START (key
));
8217 pos
= XCDR (string
);
8218 string
= XCAR (string
);
8220 && XINT (pos
) < XSTRING (string
)->size
)
8222 map
= Fget_text_property (pos
, Qlocal_map
, string
);
8224 orig_local_map
= map
;
8225 map2
= Fget_text_property (pos
, Qkeymap
, string
);
8228 if (!NILP (map
) || !NILP (map2
))
8229 goto replay_sequence
;
8236 else if (CONSP (XCDR (key
))
8237 && CONSP (EVENT_START (key
))
8238 && CONSP (XCDR (EVENT_START (key
))))
8242 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
8243 /* Handle menu-bar events:
8244 insert the dummy prefix event `menu-bar'. */
8245 if (EQ (posn
, Qmenu_bar
) || EQ (posn
, Qtool_bar
))
8247 if (t
+ 1 >= bufsize
)
8248 error ("Key sequence too long");
8252 /* Zap the position in key, so we know that we've
8253 expanded it, and don't try to do so again. */
8254 POSN_BUFFER_POSN (EVENT_START (key
))
8255 = Fcons (posn
, Qnil
);
8258 goto replay_sequence
;
8260 else if (CONSP (posn
))
8262 /* We're looking at the second event of a
8263 sequence which we expanded before. Set
8264 last_real_key_start appropriately. */
8265 if (last_real_key_start
== t
&& t
> 0)
8266 last_real_key_start
= t
- 1;
8271 /* We have finally decided that KEY is something we might want
8273 first_binding
= (follow_key (key
,
8274 nmaps
- first_binding
,
8275 submaps
+ first_binding
,
8276 defs
+ first_binding
,
8277 submaps
+ first_binding
)
8280 /* If KEY wasn't bound, we'll try some fallbacks. */
8281 if (first_binding
>= nmaps
)
8285 head
= EVENT_HEAD (key
);
8286 if (help_char_p (head
) && t
> 0)
8288 read_key_sequence_cmd
= Vprefix_help_command
;
8290 last_nonmenu_event
= key
;
8291 /* The Microsoft C compiler can't handle the goto that
8299 Lisp_Object breakdown
;
8302 breakdown
= parse_modifiers (head
);
8303 modifiers
= XINT (XCAR (XCDR (breakdown
)));
8304 /* Attempt to reduce an unbound mouse event to a simpler
8305 event that is bound:
8306 Drags reduce to clicks.
8307 Double-clicks reduce to clicks.
8308 Triple-clicks reduce to double-clicks, then to clicks.
8309 Down-clicks are eliminated.
8310 Double-downs reduce to downs, then are eliminated.
8311 Triple-downs reduce to double-downs, then to downs,
8312 then are eliminated. */
8313 if (modifiers
& (down_modifier
| drag_modifier
8314 | double_modifier
| triple_modifier
))
8316 while (modifiers
& (down_modifier
| drag_modifier
8317 | double_modifier
| triple_modifier
))
8319 Lisp_Object new_head
, new_click
;
8320 if (modifiers
& triple_modifier
)
8321 modifiers
^= (double_modifier
| triple_modifier
);
8322 else if (modifiers
& double_modifier
)
8323 modifiers
&= ~double_modifier
;
8324 else if (modifiers
& drag_modifier
)
8325 modifiers
&= ~drag_modifier
;
8328 /* Dispose of this `down' event by simply jumping
8329 back to replay_key, to get another event.
8331 Note that if this event came from mock input,
8332 then just jumping back to replay_key will just
8333 hand it to us again. So we have to wipe out any
8336 We could delete keybuf[t] and shift everything
8337 after that to the left by one spot, but we'd also
8338 have to fix up any variable that points into
8339 keybuf, and shifting isn't really necessary
8342 Adding prefixes for non-textual mouse clicks
8343 creates two characters of mock input, and both
8344 must be thrown away. If we're only looking at
8345 the prefix now, we can just jump back to
8346 replay_key. On the other hand, if we've already
8347 processed the prefix, and now the actual click
8348 itself is giving us trouble, then we've lost the
8349 state of the keymaps we want to backtrack to, and
8350 we need to replay the whole sequence to rebuild
8353 Beyond that, only function key expansion could
8354 create more than two keys, but that should never
8355 generate mouse events, so it's okay to zero
8356 mock_input in that case too.
8358 Isn't this just the most wonderful code ever? */
8359 if (t
== last_real_key_start
)
8366 mock_input
= last_real_key_start
;
8367 goto replay_sequence
;
8372 = apply_modifiers (modifiers
, XCAR (breakdown
));
8374 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
8376 /* Look for a binding for this new key. follow_key
8377 promises that it didn't munge submaps the
8378 last time we called it, since key was unbound. */
8380 = (follow_key (new_click
,
8381 nmaps
- local_first_binding
,
8382 submaps
+ local_first_binding
,
8383 defs
+ local_first_binding
,
8384 submaps
+ local_first_binding
)
8385 + local_first_binding
);
8387 /* If that click is bound, go for it. */
8388 if (first_binding
< nmaps
)
8393 /* Otherwise, we'll leave key set to the drag event. */
8400 /* Normally, last_nonmenu_event gets the previous key we read.
8401 But when a mouse popup menu is being used,
8402 we don't update last_nonmenu_event; it continues to hold the mouse
8403 event that preceded the first level of menu. */
8404 if (!used_mouse_menu
)
8405 last_nonmenu_event
= key
;
8407 /* Record what part of this_command_keys is the current key sequence. */
8408 this_single_command_key_start
= this_command_key_count
- t
;
8410 prev_fkey_map
= fkey_map
;
8411 prev_fkey_start
= fkey_start
;
8412 prev_fkey_end
= fkey_end
;
8414 prev_keytran_map
= keytran_map
;
8415 prev_keytran_start
= keytran_start
;
8416 prev_keytran_end
= keytran_end
;
8418 /* If the sequence is unbound, see if we can hang a function key
8419 off the end of it. We only want to scan real keyboard input
8420 for function key sequences, so if mock_input says that we're
8421 re-reading old events, don't examine it. */
8422 if (first_binding
>= nmaps
8425 Lisp_Object fkey_next
;
8427 /* Continue scan from fkey_end until we find a bound suffix.
8428 If we fail, increment fkey_start
8429 and start fkey_end from there. */
8430 while (fkey_end
< t
)
8434 key
= keybuf
[fkey_end
++];
8436 = access_keymap (fkey_map
, key
, 1, 0, 1);
8438 /* Handle symbol with autoload definition. */
8439 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
8440 && CONSP (XSYMBOL (fkey_next
)->function
)
8441 && EQ (XCAR (XSYMBOL (fkey_next
)->function
), Qautoload
))
8442 do_autoload (XSYMBOL (fkey_next
)->function
,
8445 /* Handle a symbol whose function definition is a keymap
8447 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
8448 && (!NILP (Farrayp (XSYMBOL (fkey_next
)->function
))
8449 || !NILP (Fkeymapp (XSYMBOL (fkey_next
)->function
))))
8450 fkey_next
= XSYMBOL (fkey_next
)->function
;
8452 #if 0 /* I didn't turn this on, because it might cause trouble
8453 for the mapping of return into C-m and tab into C-i. */
8454 /* Optionally don't map function keys into other things.
8455 This enables the user to redefine kp- keys easily. */
8456 if (SYMBOLP (key
) && !NILP (Vinhibit_function_key_mapping
))
8460 /* If the function key map gives a function, not an
8461 array, then call the function with no args and use
8462 its value instead. */
8463 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
8466 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8470 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
8471 fkey_next
= call1 (fkey_next
, prompt
);
8473 /* If the function returned something invalid,
8474 barf--don't ignore it.
8475 (To ignore it safely, we would need to gcpro a bunch of
8476 other variables.) */
8477 if (! (VECTORP (fkey_next
) || STRINGP (fkey_next
)))
8478 error ("Function in key-translation-map returns invalid key sequence");
8481 function_key_possible
= ! NILP (fkey_next
);
8483 /* If keybuf[fkey_start..fkey_end] is bound in the
8484 function key map and it's a suffix of the current
8485 sequence (i.e. fkey_end == t), replace it with
8486 the binding and restart with fkey_start at the end. */
8487 if ((VECTORP (fkey_next
) || STRINGP (fkey_next
))
8490 int len
= XFASTINT (Flength (fkey_next
));
8492 t
= fkey_start
+ len
;
8494 error ("Key sequence too long");
8496 if (VECTORP (fkey_next
))
8497 bcopy (XVECTOR (fkey_next
)->contents
,
8498 keybuf
+ fkey_start
,
8499 (t
- fkey_start
) * sizeof (keybuf
[0]));
8500 else if (STRINGP (fkey_next
))
8504 for (i
= 0; i
< len
; i
++)
8505 XSETFASTINT (keybuf
[fkey_start
+ i
],
8506 XSTRING (fkey_next
)->data
[i
]);
8510 fkey_start
= fkey_end
= t
;
8511 fkey_map
= Vfunction_key_map
;
8513 /* Do pass the results through key-translation-map.
8514 But don't retranslate what key-translation-map
8515 has already translated. */
8516 keytran_end
= keytran_start
;
8517 keytran_map
= Vkey_translation_map
;
8519 goto replay_sequence
;
8522 fkey_map
= get_keymap_1 (fkey_next
, 0, 1);
8524 /* If we no longer have a bound suffix, try a new positions for
8526 if (NILP (fkey_map
))
8528 fkey_end
= ++fkey_start
;
8529 fkey_map
= Vfunction_key_map
;
8530 function_key_possible
= 0;
8535 /* Look for this sequence in key-translation-map. */
8537 Lisp_Object keytran_next
;
8539 /* Scan from keytran_end until we find a bound suffix. */
8540 while (keytran_end
< t
)
8544 key
= keybuf
[keytran_end
++];
8546 = access_keymap (keytran_map
, key
, 1, 0, 1);
8548 /* Handle symbol with autoload definition. */
8549 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
8550 && CONSP (XSYMBOL (keytran_next
)->function
)
8551 && EQ (XCAR (XSYMBOL (keytran_next
)->function
), Qautoload
))
8552 do_autoload (XSYMBOL (keytran_next
)->function
,
8555 /* Handle a symbol whose function definition is a keymap
8557 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
8558 && (!NILP (Farrayp (XSYMBOL (keytran_next
)->function
))
8559 || !NILP (Fkeymapp (XSYMBOL (keytran_next
)->function
))))
8560 keytran_next
= XSYMBOL (keytran_next
)->function
;
8562 /* If the key translation map gives a function, not an
8563 array, then call the function with one arg and use
8564 its value instead. */
8565 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
8566 && keytran_end
== t
)
8568 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8572 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
8573 keytran_next
= call1 (keytran_next
, prompt
);
8575 /* If the function returned something invalid,
8576 barf--don't ignore it.
8577 (To ignore it safely, we would need to gcpro a bunch of
8578 other variables.) */
8579 if (! (VECTORP (keytran_next
) || STRINGP (keytran_next
)))
8580 error ("Function in key-translation-map returns invalid key sequence");
8583 key_translation_possible
= ! NILP (keytran_next
);
8585 /* If keybuf[keytran_start..keytran_end] is bound in the
8586 key translation map and it's a suffix of the current
8587 sequence (i.e. keytran_end == t), replace it with
8588 the binding and restart with keytran_start at the end. */
8589 if ((VECTORP (keytran_next
) || STRINGP (keytran_next
))
8590 && keytran_end
== t
)
8592 int len
= XFASTINT (Flength (keytran_next
));
8594 t
= keytran_start
+ len
;
8596 error ("Key sequence too long");
8598 if (VECTORP (keytran_next
))
8599 bcopy (XVECTOR (keytran_next
)->contents
,
8600 keybuf
+ keytran_start
,
8601 (t
- keytran_start
) * sizeof (keybuf
[0]));
8602 else if (STRINGP (keytran_next
))
8606 for (i
= 0; i
< len
; i
++)
8607 XSETFASTINT (keybuf
[keytran_start
+ i
],
8608 XSTRING (keytran_next
)->data
[i
]);
8612 keytran_start
= keytran_end
= t
;
8613 keytran_map
= Vkey_translation_map
;
8615 /* Don't pass the results of key-translation-map
8616 through function-key-map. */
8617 fkey_start
= fkey_end
= t
;
8618 fkey_map
= Vfunction_key_map
;
8620 goto replay_sequence
;
8623 keytran_map
= get_keymap_1 (keytran_next
, 0, 1);
8625 /* If we no longer have a bound suffix, try a new positions for
8627 if (NILP (keytran_map
))
8629 keytran_end
= ++keytran_start
;
8630 keytran_map
= Vkey_translation_map
;
8631 key_translation_possible
= 0;
8636 /* If KEY is not defined in any of the keymaps,
8637 and cannot be part of a function key or translation,
8638 and is an upper case letter
8639 use the corresponding lower-case letter instead. */
8640 if (first_binding
== nmaps
&& ! function_key_possible
8641 && ! key_translation_possible
8643 && ((((XINT (key
) & 0x3ffff)
8644 < XCHAR_TABLE (current_buffer
->downcase_table
)->size
)
8645 && UPPERCASEP (XINT (key
) & 0x3ffff))
8646 || (XINT (key
) & shift_modifier
)))
8648 Lisp_Object new_key
;
8650 original_uppercase
= key
;
8651 original_uppercase_position
= t
- 1;
8653 if (XINT (key
) & shift_modifier
)
8654 XSETINT (new_key
, XINT (key
) & ~shift_modifier
);
8656 XSETINT (new_key
, (DOWNCASE (XINT (key
) & 0x3ffff)
8657 | (XINT (key
) & ~0x3ffff)));
8659 /* We have to do this unconditionally, regardless of whether
8660 the lower-case char is defined in the keymaps, because they
8661 might get translated through function-key-map. */
8662 keybuf
[t
- 1] = new_key
;
8665 fkey_map
= prev_fkey_map
;
8666 fkey_start
= prev_fkey_start
;
8667 fkey_end
= prev_fkey_end
;
8669 keytran_map
= prev_keytran_map
;
8670 keytran_start
= prev_keytran_start
;
8671 keytran_end
= prev_keytran_end
;
8673 goto replay_sequence
;
8675 /* If KEY is not defined in any of the keymaps,
8676 and cannot be part of a function key or translation,
8677 and is a shifted function key,
8678 use the corresponding unshifted function key instead. */
8679 if (first_binding
== nmaps
&& ! function_key_possible
8680 && ! key_translation_possible
8683 Lisp_Object breakdown
;
8686 breakdown
= parse_modifiers (key
);
8687 modifiers
= XINT (XCAR (XCDR (breakdown
)));
8688 if (modifiers
& shift_modifier
)
8690 Lisp_Object new_key
;
8692 original_uppercase
= key
;
8693 original_uppercase_position
= t
- 1;
8695 modifiers
&= ~shift_modifier
;
8696 new_key
= apply_modifiers (modifiers
,
8699 keybuf
[t
- 1] = new_key
;
8702 fkey_map
= prev_fkey_map
;
8703 fkey_start
= prev_fkey_start
;
8704 fkey_end
= prev_fkey_end
;
8706 keytran_map
= prev_keytran_map
;
8707 keytran_start
= prev_keytran_start
;
8708 keytran_end
= prev_keytran_end
;
8710 goto replay_sequence
;
8716 read_key_sequence_cmd
= (first_binding
< nmaps
8717 ? defs
[first_binding
]
8720 unread_switch_frame
= delayed_switch_frame
;
8721 unbind_to (count
, Qnil
);
8723 /* Don't downcase the last character if the caller says don't.
8724 Don't downcase it if the result is undefined, either. */
8725 if ((dont_downcase_last
|| first_binding
>= nmaps
)
8726 && t
- 1 == original_uppercase_position
)
8727 keybuf
[t
- 1] = original_uppercase
;
8729 /* Occasionally we fabricate events, perhaps by expanding something
8730 according to function-key-map, or by adding a prefix symbol to a
8731 mouse click in the scroll bar or modeline. In this cases, return
8732 the entire generated key sequence, even if we hit an unbound
8733 prefix or a definition before the end. This means that you will
8734 be able to push back the event properly, and also means that
8735 read-key-sequence will always return a logical unit.
8738 for (; t
< mock_input
; t
++)
8740 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
8741 && NILP (Fzerop (Vecho_keystrokes
)))
8742 echo_char (keybuf
[t
]);
8743 add_command_key (keybuf
[t
]);
8751 #if 0 /* This doc string is too long for some compilers.
8752 This commented-out definition serves for DOC. */
8753 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
8754 "Read a sequence of keystrokes and return as a string or vector.\n\
8755 The sequence is sufficient to specify a non-prefix command in the\n\
8756 current local and global maps.\n\
8758 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
8759 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
8760 as a continuation of the previous key.\n\
8762 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not\n\
8763 convert the last event to lower case. (Normally any upper case event\n\
8764 is converted to lower case if the original event is undefined and the lower\n\
8765 case equivalent is defined.) A non-nil value is appropriate for reading\n\
8766 a key sequence to be defined.\n\
8768 A C-g typed while in this function is treated like any other character,\n\
8769 and `quit-flag' is not set.\n\
8771 If the key sequence starts with a mouse click, then the sequence is read\n\
8772 using the keymaps of the buffer of the window clicked in, not the buffer\n\
8773 of the selected window as normal.\n\
8775 `read-key-sequence' drops unbound button-down events, since you normally\n\
8776 only care about the click or drag events which follow them. If a drag\n\
8777 or multi-click event is unbound, but the corresponding click event would\n\
8778 be bound, `read-key-sequence' turns the event into a click event at the\n\
8779 drag's starting position. This means that you don't have to distinguish\n\
8780 between click and drag, double, or triple events unless you want to.\n\
8782 `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\
8783 lines separating windows, and scroll bars with imaginary keys\n\
8784 `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\
8786 Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this\n\
8787 function will process a switch-frame event if the user switches frames\n\
8788 before typing anything. If the user switches frames in the middle of a\n\
8789 key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME\n\
8790 is nil, then the event will be put off until after the current key sequence.\n\
8792 `read-key-sequence' checks `function-key-map' for function key\n\
8793 sequences, where they wouldn't conflict with ordinary bindings. See\n\
8794 `function-key-map' for more details.\n\
8796 The optional fifth argument COMMAND-LOOP, if non-nil, means\n\
8797 that this key sequence is being read by something that will\n\
8798 read commands one after another. It should be nil if the caller\n\
8799 will read just one key sequence.")
8800 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
, command
-loop
)
8803 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 5, 0,
8805 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
8807 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
8808 Lisp_Object can_return_switch_frame
, command_loop
;
8810 Lisp_Object keybuf
[30];
8812 struct gcpro gcpro1
;
8813 int count
= specpdl_ptr
- specpdl
;
8816 CHECK_STRING (prompt
, 0);
8819 specbind (Qinput_method_exit_on_first_char
,
8820 (NILP (command_loop
) ? Qt
: Qnil
));
8821 specbind (Qinput_method_use_echo_area
,
8822 (NILP (command_loop
) ? Qt
: Qnil
));
8824 bzero (keybuf
, sizeof keybuf
);
8826 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
8828 if (NILP (continue_echo
))
8830 this_command_key_count
= 0;
8831 this_single_command_key_start
= 0;
8834 #ifdef HAVE_X_WINDOWS
8835 if (display_busy_cursor_p
)
8836 cancel_busy_cursor ();
8839 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
8840 prompt
, ! NILP (dont_downcase_last
),
8841 ! NILP (can_return_switch_frame
), 0);
8843 #ifdef HAVE_X_WINDOWS
8844 if (display_busy_cursor_p
)
8845 start_busy_cursor ();
8854 return unbind_to (count
, make_event_array (i
, keybuf
));
8857 DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector
,
8858 Sread_key_sequence_vector
, 1, 5, 0,
8859 "Like `read-key-sequence' but always return a vector.")
8860 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
8862 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
8863 Lisp_Object can_return_switch_frame
, command_loop
;
8865 Lisp_Object keybuf
[30];
8867 struct gcpro gcpro1
;
8868 int count
= specpdl_ptr
- specpdl
;
8871 CHECK_STRING (prompt
, 0);
8874 specbind (Qinput_method_exit_on_first_char
,
8875 (NILP (command_loop
) ? Qt
: Qnil
));
8876 specbind (Qinput_method_use_echo_area
,
8877 (NILP (command_loop
) ? Qt
: Qnil
));
8879 bzero (keybuf
, sizeof keybuf
);
8881 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
8883 if (NILP (continue_echo
))
8885 this_command_key_count
= 0;
8886 this_single_command_key_start
= 0;
8889 #ifdef HAVE_X_WINDOWS
8890 if (display_busy_cursor_p
)
8891 cancel_busy_cursor ();
8894 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
8895 prompt
, ! NILP (dont_downcase_last
),
8896 ! NILP (can_return_switch_frame
), 0);
8898 #ifdef HAVE_X_WINDOWS
8899 if (display_busy_cursor_p
)
8900 start_busy_cursor ();
8909 return unbind_to (count
, Fvector (i
, keybuf
));
8912 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 4, 0,
8913 "Execute CMD as an editor command.\n\
8914 CMD must be a symbol that satisfies the `commandp' predicate.\n\
8915 Optional second arg RECORD-FLAG non-nil\n\
8916 means unconditionally put this command in `command-history'.\n\
8917 Otherwise, that is done only if an arg is read using the minibuffer.\n\
8918 The argument KEYS specifies the value to use instead of (this-command-keys)\n\
8919 when reading the arguments; if it is nil, (this-command-keys) is used.\n\
8920 The argument SPECIAL, if non-nil, means that this command is executing\n\
8921 a special event, so ignore the prefix argument and don't clear it.")
8922 (cmd
, record_flag
, keys
, special
)
8923 Lisp_Object cmd
, record_flag
, keys
, special
;
8925 register Lisp_Object final
;
8926 register Lisp_Object tem
;
8927 Lisp_Object prefixarg
;
8928 struct backtrace backtrace
;
8929 extern int debug_on_next_call
;
8931 debug_on_next_call
= 0;
8935 prefixarg
= current_kboard
->Vprefix_arg
;
8936 Vcurrent_prefix_arg
= prefixarg
;
8937 current_kboard
->Vprefix_arg
= Qnil
;
8944 tem
= Fget (cmd
, Qdisabled
);
8945 if (!NILP (tem
) && !NILP (Vrun_hooks
))
8947 tem
= Fsymbol_value (Qdisabled_command_hook
);
8949 return call1 (Vrun_hooks
, Qdisabled_command_hook
);
8955 final
= Findirect_function (cmd
);
8957 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
8959 struct gcpro gcpro1
, gcpro2
;
8961 GCPRO2 (cmd
, prefixarg
);
8962 do_autoload (final
, cmd
);
8969 if (STRINGP (final
) || VECTORP (final
))
8971 /* If requested, place the macro in the command history. For
8972 other sorts of commands, call-interactively takes care of
8974 if (!NILP (record_flag
))
8977 = Fcons (Fcons (Qexecute_kbd_macro
,
8978 Fcons (final
, Fcons (prefixarg
, Qnil
))),
8981 /* Don't keep command history around forever. */
8982 if (NUMBERP (Vhistory_length
) && XINT (Vhistory_length
) > 0)
8984 tem
= Fnthcdr (Vhistory_length
, Vcommand_history
);
8990 return Fexecute_kbd_macro (final
, prefixarg
);
8993 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
8995 backtrace
.next
= backtrace_list
;
8996 backtrace_list
= &backtrace
;
8997 backtrace
.function
= &Qcall_interactively
;
8998 backtrace
.args
= &cmd
;
8999 backtrace
.nargs
= 1;
9000 backtrace
.evalargs
= 0;
9002 tem
= Fcall_interactively (cmd
, record_flag
, keys
);
9004 backtrace_list
= backtrace
.next
;
9010 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
9012 "Read function name, then read its arguments and call it.")
9014 Lisp_Object prefixarg
;
9016 Lisp_Object function
;
9018 Lisp_Object saved_keys
;
9019 Lisp_Object bindings
, value
;
9020 struct gcpro gcpro1
, gcpro2
;
9022 saved_keys
= Fvector (this_command_key_count
,
9023 XVECTOR (this_command_keys
)->contents
);
9025 GCPRO2 (saved_keys
, prefixarg
);
9027 if (EQ (prefixarg
, Qminus
))
9029 else if (CONSP (prefixarg
) && XINT (XCAR (prefixarg
)) == 4)
9030 strcpy (buf
, "C-u ");
9031 else if (CONSP (prefixarg
) && INTEGERP (XCAR (prefixarg
)))
9033 if (sizeof (int) == sizeof (EMACS_INT
))
9034 sprintf (buf
, "%d ", XINT (XCAR (prefixarg
)));
9035 else if (sizeof (long) == sizeof (EMACS_INT
))
9036 sprintf (buf
, "%ld ", (long) XINT (XCAR (prefixarg
)));
9040 else if (INTEGERP (prefixarg
))
9042 if (sizeof (int) == sizeof (EMACS_INT
))
9043 sprintf (buf
, "%d ", XINT (prefixarg
));
9044 else if (sizeof (long) == sizeof (EMACS_INT
))
9045 sprintf (buf
, "%ld ", (long) XINT (prefixarg
));
9050 /* This isn't strictly correct if execute-extended-command
9051 is bound to anything else. Perhaps it should use
9052 this_command_keys? */
9053 strcat (buf
, "M-x ");
9055 /* Prompt with buf, and then read a string, completing from and
9056 restricting to the set of all defined commands. Don't provide
9057 any initial input. Save the command read on the extended-command
9059 function
= Fcompleting_read (build_string (buf
),
9060 Vobarray
, Qcommandp
,
9061 Qt
, Qnil
, Qextended_command_history
, Qnil
,
9064 if (STRINGP (function
) && XSTRING (function
)->size
== 0)
9065 error ("No command name given");
9067 /* Set this_command_keys to the concatenation of saved_keys and
9068 function, followed by a RET. */
9070 struct Lisp_String
*str
;
9074 this_command_key_count
= 0;
9075 this_single_command_key_start
= 0;
9077 keys
= XVECTOR (saved_keys
)->contents
;
9078 for (i
= 0; i
< XVECTOR (saved_keys
)->size
; i
++)
9079 add_command_key (keys
[i
]);
9081 str
= XSTRING (function
);
9082 for (i
= 0; i
< str
->size
; i
++)
9083 add_command_key (Faref (function
, make_number (i
)));
9085 add_command_key (make_number ('\015'));
9090 function
= Fintern (function
, Qnil
);
9091 current_kboard
->Vprefix_arg
= prefixarg
;
9092 Vthis_command
= function
;
9093 real_this_command
= function
;
9095 /* If enabled, show which key runs this command. */
9096 if (!NILP (Vsuggest_key_bindings
)
9097 && NILP (Vexecuting_macro
)
9098 && SYMBOLP (function
))
9099 bindings
= Fwhere_is_internal (function
, Voverriding_local_map
,
9105 GCPRO2 (bindings
, value
);
9106 value
= Fcommand_execute (function
, Qt
, Qnil
, Qnil
);
9108 /* If the command has a key binding, print it now. */
9109 if (!NILP (bindings
)
9110 && ! (VECTORP (bindings
) && EQ (Faref (bindings
, make_number (0)),
9113 /* But first wait, and skip the message if there is input. */
9115 if (!NILP (echo_area_buffer
[0]))
9116 /* This command displayed something in the echo area;
9117 so wait a few seconds, then display our suggestion message. */
9118 delay_time
= (NUMBERP (Vsuggest_key_bindings
)
9119 ? XINT (Vsuggest_key_bindings
) : 2);
9121 /* This command left the echo area empty,
9122 so display our message immediately. */
9125 if (!NILP (Fsit_for (make_number (delay_time
), Qnil
, Qnil
))
9126 && ! CONSP (Vunread_command_events
))
9128 Lisp_Object binding
;
9130 int message_p
= push_message ();
9132 binding
= Fkey_description (bindings
);
9135 = (char *) alloca (XSYMBOL (function
)->name
->size
9136 + STRING_BYTES (XSTRING (binding
))
9138 sprintf (newmessage
, "You can run the command `%s' with %s",
9139 XSYMBOL (function
)->name
->data
,
9140 XSTRING (binding
)->data
);
9141 message2_nolog (newmessage
,
9142 strlen (newmessage
),
9143 STRING_MULTIBYTE (binding
));
9144 if (!NILP (Fsit_for ((NUMBERP (Vsuggest_key_bindings
)
9145 ? Vsuggest_key_bindings
: make_number (2)),
9154 RETURN_UNGCPRO (value
);
9157 /* Find the set of keymaps now active.
9158 Store into *MAPS_P a vector holding the various maps
9159 and return the number of them. The vector was malloc'd
9160 and the caller should free it. */
9163 current_active_maps (maps_p
)
9164 Lisp_Object
**maps_p
;
9166 Lisp_Object
*tmaps
, *maps
;
9169 /* Should overriding-terminal-local-map and overriding-local-map apply? */
9170 if (!NILP (Voverriding_local_map_menu_flag
))
9172 /* Yes, use them (if non-nil) as well as the global map. */
9173 maps
= (Lisp_Object
*) xmalloc (3 * sizeof (maps
[0]));
9175 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
9176 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
9177 if (!NILP (Voverriding_local_map
))
9178 maps
[nmaps
++] = Voverriding_local_map
;
9182 /* No, so use major and minor mode keymaps and keymap property. */
9184 Lisp_Object map
= get_local_map (PT
, current_buffer
, keymap
);
9187 nmaps
= current_minor_maps (NULL
, &tmaps
);
9188 maps
= (Lisp_Object
*) alloca ((nmaps
+ extra_maps
)
9189 * sizeof (maps
[0]));
9190 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
9192 maps
[nmaps
++] = map
;
9193 maps
[nmaps
++] = get_local_map (PT
, current_buffer
, local_map
);
9195 maps
[nmaps
++] = current_global_map
;
9201 /* Return nonzero if input events are pending. */
9204 detect_input_pending ()
9207 get_input_pending (&input_pending
, 0);
9209 return input_pending
;
9212 /* Return nonzero if input events are pending, and run any pending timers. */
9215 detect_input_pending_run_timers (do_display
)
9218 int old_timers_run
= timers_run
;
9221 get_input_pending (&input_pending
, 1);
9223 if (old_timers_run
!= timers_run
&& do_display
)
9225 redisplay_preserve_echo_area ();
9226 /* The following fixes a bug when using lazy-lock with
9227 lazy-lock-defer-on-the-fly set to t, i.e. when fontifying
9228 from an idle timer function. The symptom of the bug is that
9229 the cursor sometimes doesn't become visible until the next X
9230 event is processed. --gerd. */
9232 rif
->flush_display (NULL
);
9235 return input_pending
;
9238 /* This is called in some cases before a possible quit.
9239 It cases the next call to detect_input_pending to recompute input_pending.
9240 So calling this function unnecessarily can't do any harm. */
9243 clear_input_pending ()
9248 /* Return nonzero if there are pending requeued events.
9249 This isn't used yet. The hope is to make wait_reading_process_input
9250 call it, and return return if it runs Lisp code that unreads something.
9251 The problem is, kbd_buffer_get_event needs to be fixed to know what
9252 to do in that case. It isn't trivial. */
9255 requeued_events_pending_p ()
9257 return (!NILP (Vunread_command_events
) || unread_command_char
!= -1);
9261 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
9262 "T if command input is currently available with no waiting.\n\
9263 Actually, the value is nil only if we can be sure that no input is available.")
9266 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1)
9269 get_input_pending (&input_pending
, 1);
9270 return input_pending
> 0 ? Qt
: Qnil
;
9273 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
9274 "Return vector of last 100 events, not counting those from keyboard macros.")
9277 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
9280 if (total_keys
< NUM_RECENT_KEYS
)
9281 return Fvector (total_keys
, keys
);
9284 val
= Fvector (NUM_RECENT_KEYS
, keys
);
9285 bcopy (keys
+ recent_keys_index
,
9286 XVECTOR (val
)->contents
,
9287 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
9289 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
9290 recent_keys_index
* sizeof (Lisp_Object
));
9295 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
9296 "Return the key sequence that invoked this command.\n\
9297 The value is a string or a vector.")
9300 return make_event_array (this_command_key_count
,
9301 XVECTOR (this_command_keys
)->contents
);
9304 DEFUN ("this-command-keys-vector", Fthis_command_keys_vector
, Sthis_command_keys_vector
, 0, 0, 0,
9305 "Return the key sequence that invoked this command, as a vector.")
9308 return Fvector (this_command_key_count
,
9309 XVECTOR (this_command_keys
)->contents
);
9312 DEFUN ("this-single-command-keys", Fthis_single_command_keys
,
9313 Sthis_single_command_keys
, 0, 0, 0,
9314 "Return the key sequence that invoked this command.\n\
9315 Unlike `this-command-keys', this function's value\n\
9316 does not include prefix arguments.\n\
9317 The value is always a vector.")
9320 return Fvector (this_command_key_count
9321 - this_single_command_key_start
,
9322 (XVECTOR (this_command_keys
)->contents
9323 + this_single_command_key_start
));
9326 DEFUN ("this-single-command-raw-keys", Fthis_single_command_raw_keys
,
9327 Sthis_single_command_raw_keys
, 0, 0, 0,
9328 "Return the raw events that were read for this command.\n\
9329 Unlike `this-single-command-keys', this function's value\n\
9330 shows the events before all translations (except for input methods).\n\
9331 The value is always a vector.")
9334 return Fvector (raw_keybuf_count
,
9335 (XVECTOR (raw_keybuf
)->contents
));
9338 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths
,
9339 Sreset_this_command_lengths
, 0, 0, 0,
9340 "Used for complicated reasons in `universal-argument-other-key'.\n\
9342 `universal-argument-other-key' rereads the event just typed.\n\
9343 It then gets translated through `function-key-map'.\n\
9344 The translated event gets included in the echo area and in\n\
9345 the value of `this-command-keys' in addition to the raw original event.\n\
9346 That is not right.\n\
9348 Calling this function directs the translated event to replace\n\
9349 the original event, so that only one version of the event actually\n\
9350 appears in the echo area and in the value of `this-command-keys.'.")
9353 before_command_restore_flag
= 1;
9354 before_command_key_count_1
= before_command_key_count
;
9355 before_command_echo_length_1
= before_command_echo_length
;
9359 DEFUN ("clear-this-command-keys", Fclear_this_command_keys
,
9360 Sclear_this_command_keys
, 0, 0, 0,
9361 "Clear out the vector that `this-command-keys' returns.\n\
9362 Clear vector containing last 100 events.")
9367 this_command_key_count
= 0;
9369 for (i
= 0; i
< XVECTOR (recent_keys
)->size
; ++i
)
9370 XVECTOR (recent_keys
)->contents
[i
] = Qnil
;
9372 recent_keys_index
= 0;
9376 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
9377 "Return the current depth in recursive edits.")
9381 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
9385 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
9386 "FOpen dribble file: ",
9387 "Start writing all keyboard characters to a dribble file called FILE.\n\
9388 If FILE is nil, close any open dribble file.")
9399 file
= Fexpand_file_name (file
, Qnil
);
9400 dribble
= fopen (XSTRING (file
)->data
, "w");
9402 report_file_error ("Opening dribble", Fcons (file
, Qnil
));
9407 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
9408 "Discard the contents of the terminal input buffer.\n\
9409 Also cancel any kbd macro being defined.")
9412 current_kboard
->defining_kbd_macro
= Qnil
;
9413 update_mode_lines
++;
9415 Vunread_command_events
= Qnil
;
9416 unread_command_char
= -1;
9418 discard_tty_input ();
9420 kbd_fetch_ptr
= kbd_store_ptr
;
9421 Ffillarray (kbd_buffer_gcpro
, Qnil
);
9427 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
9428 "Stop Emacs and return to superior process. You can resume later.\n\
9429 If `cannot-suspend' is non-nil, or if the system doesn't support job\n\
9430 control, run a subshell instead.\n\n\
9431 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
9432 to be read as terminal input by Emacs's parent, after suspension.\n\
9434 Before suspending, run the normal hook `suspend-hook'.\n\
9435 After resumption run the normal hook `suspend-resume-hook'.\n\
9437 Some operating systems cannot stop the Emacs process and resume it later.\n\
9438 On such systems, Emacs starts a subshell instead of suspending.")
9440 Lisp_Object stuffstring
;
9442 int count
= specpdl_ptr
- specpdl
;
9443 int old_height
, old_width
;
9445 struct gcpro gcpro1
;
9447 if (!NILP (stuffstring
))
9448 CHECK_STRING (stuffstring
, 0);
9450 /* Run the functions in suspend-hook. */
9451 if (!NILP (Vrun_hooks
))
9452 call1 (Vrun_hooks
, intern ("suspend-hook"));
9454 GCPRO1 (stuffstring
);
9455 get_frame_size (&old_width
, &old_height
);
9457 /* sys_suspend can get an error if it tries to fork a subshell
9458 and the system resources aren't available for that. */
9459 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object
))) init_sys_modes
,
9461 stuff_buffered_input (stuffstring
);
9466 unbind_to (count
, Qnil
);
9468 /* Check if terminal/window size has changed.
9469 Note that this is not useful when we are running directly
9470 with a window system; but suspend should be disabled in that case. */
9471 get_frame_size (&width
, &height
);
9472 if (width
!= old_width
|| height
!= old_height
)
9473 change_frame_size (SELECTED_FRAME (), height
, width
, 0, 0, 0);
9475 /* Run suspend-resume-hook. */
9476 if (!NILP (Vrun_hooks
))
9477 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
9483 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
9484 Then in any case stuff anything Emacs has read ahead and not used. */
9487 stuff_buffered_input (stuffstring
)
9488 Lisp_Object stuffstring
;
9490 /* stuff_char works only in BSD, versions 4.2 and up. */
9493 register unsigned char *p
;
9495 if (STRINGP (stuffstring
))
9499 p
= XSTRING (stuffstring
)->data
;
9500 count
= STRING_BYTES (XSTRING (stuffstring
));
9506 /* Anything we have read ahead, put back for the shell to read. */
9507 /* ?? What should this do when we have multiple keyboards??
9508 Should we ignore anything that was typed in at the "wrong" kboard? */
9509 for (; kbd_fetch_ptr
!= kbd_store_ptr
; kbd_fetch_ptr
++)
9513 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
9514 kbd_fetch_ptr
= kbd_buffer
;
9515 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
9516 stuff_char (kbd_fetch_ptr
->code
);
9518 kbd_fetch_ptr
->kind
= no_event
;
9519 idx
= 2 * (kbd_fetch_ptr
- kbd_buffer
);
9520 ASET (kbd_buffer_gcpro
, idx
, Qnil
);
9521 ASET (kbd_buffer_gcpro
, idx
+ 1, Qnil
);
9526 #endif /* BSD_SYSTEM and not BSD4_1 */
9530 set_waiting_for_input (time_to_clear
)
9531 EMACS_TIME
*time_to_clear
;
9533 input_available_clear_time
= time_to_clear
;
9535 /* Tell interrupt_signal to throw back to read_char, */
9536 waiting_for_input
= 1;
9538 /* If interrupt_signal was called before and buffered a C-g,
9539 make it run again now, to avoid timing error. */
9540 if (!NILP (Vquit_flag
))
9541 quit_throw_to_read_char ();
9545 clear_waiting_for_input ()
9547 /* Tell interrupt_signal not to throw back to read_char, */
9548 waiting_for_input
= 0;
9549 input_available_clear_time
= 0;
9552 /* This routine is called at interrupt level in response to C-G.
9554 If interrupt_input, this is the handler for SIGINT. Otherwise, it
9555 is called from kbd_buffer_store_event, in handling SIGIO or
9558 If `waiting_for_input' is non zero, then unless `echoing' is
9559 nonzero, immediately throw back to read_char.
9561 Otherwise it sets the Lisp variable quit-flag not-nil. This causes
9562 eval to throw, when it gets a chance. If quit-flag is already
9563 non-nil, it stops the job right away. */
9566 interrupt_signal (signalnum
) /* If we don't have an argument, */
9567 int signalnum
; /* some compilers complain in signal calls. */
9570 /* Must preserve main program's value of errno. */
9571 int old_errno
= errno
;
9572 struct frame
*sf
= SELECTED_FRAME ();
9574 #if defined (USG) && !defined (POSIX_SIGNALS)
9575 if (!read_socket_hook
&& NILP (Vwindow_system
))
9577 /* USG systems forget handlers when they are used;
9578 must reestablish each time */
9579 signal (SIGINT
, interrupt_signal
);
9580 signal (SIGQUIT
, interrupt_signal
);
9586 if (!NILP (Vquit_flag
)
9587 && (FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
)))
9589 /* If SIGINT isn't blocked, don't let us be interrupted by
9590 another SIGINT, it might be harmful due to non-reentrancy
9591 in I/O functions. */
9592 sigblock (sigmask (SIGINT
));
9597 #ifdef SIGTSTP /* Support possible in later USG versions */
9599 * On systems which can suspend the current process and return to the original
9600 * shell, this command causes the user to end up back at the shell.
9601 * The "Auto-save" and "Abort" questions are not asked until
9602 * the user elects to return to emacs, at which point he can save the current
9603 * job and either dump core or continue.
9608 if (sys_suspend () == -1)
9610 printf ("Not running as a subprocess;\n");
9611 printf ("you can continue or abort.\n");
9614 /* Perhaps should really fork an inferior shell?
9615 But that would not provide any way to get back
9616 to the original shell, ever. */
9617 printf ("No support for stopping a process on this operating system;\n");
9618 printf ("you can continue or abort.\n");
9619 #endif /* not VMS */
9620 #endif /* not SIGTSTP */
9622 /* We must remain inside the screen area when the internal terminal
9623 is used. Note that [Enter] is not echoed by dos. */
9626 /* It doesn't work to autosave while GC is in progress;
9627 the code used for auto-saving doesn't cope with the mark bit. */
9628 if (!gc_in_progress
)
9630 printf ("Auto-save? (y or n) ");
9632 if (((c
= getchar ()) & ~040) == 'Y')
9634 Fdo_auto_save (Qt
, Qnil
);
9636 printf ("\r\nAuto-save done");
9637 #else /* not MSDOS */
9638 printf ("Auto-save done\n");
9639 #endif /* not MSDOS */
9641 while (c
!= '\n') c
= getchar ();
9645 /* During GC, it must be safe to reenable quitting again. */
9646 Vinhibit_quit
= Qnil
;
9649 #endif /* not MSDOS */
9650 printf ("Garbage collection in progress; cannot auto-save now\r\n");
9651 printf ("but will instead do a real quit after garbage collection ends\r\n");
9656 printf ("\r\nAbort? (y or n) ");
9657 #else /* not MSDOS */
9659 printf ("Abort (and enter debugger)? (y or n) ");
9661 printf ("Abort (and dump core)? (y or n) ");
9662 #endif /* not VMS */
9663 #endif /* not MSDOS */
9665 if (((c
= getchar ()) & ~040) == 'Y')
9667 while (c
!= '\n') c
= getchar ();
9669 printf ("\r\nContinuing...\r\n");
9670 #else /* not MSDOS */
9671 printf ("Continuing...\n");
9672 #endif /* not MSDOS */
9679 /* If executing a function that wants to be interrupted out of
9680 and the user has not deferred quitting by binding `inhibit-quit'
9681 then quit right away. */
9682 if (immediate_quit
&& NILP (Vinhibit_quit
))
9684 struct gl_state_s saved
;
9685 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9690 GCPRO4 (saved
.object
, saved
.global_code
,
9691 saved
.current_syntax_table
, saved
.old_prop
);
9692 Fsignal (Qquit
, Qnil
);
9697 /* Else request quit when it's safe */
9701 if (waiting_for_input
&& !echoing
)
9702 quit_throw_to_read_char ();
9707 /* Handle a C-g by making read_char return C-g. */
9710 quit_throw_to_read_char ()
9713 /* Prevent another signal from doing this before we finish. */
9714 clear_waiting_for_input ();
9717 Vunread_command_events
= Qnil
;
9718 unread_command_char
= -1;
9720 #if 0 /* Currently, sit_for is called from read_char without turning
9721 off polling. And that can call set_waiting_for_input.
9722 It seems to be harmless. */
9723 #ifdef POLL_FOR_INPUT
9724 /* May be > 1 if in recursive minibuffer. */
9725 if (poll_suppress_count
== 0)
9729 if (FRAMEP (internal_last_event_frame
)
9730 && !EQ (internal_last_event_frame
, selected_frame
))
9731 do_switch_frame (make_lispy_switch_frame (internal_last_event_frame
),
9734 _longjmp (getcjmp
, 1);
9737 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
9738 "Set mode of reading keyboard input.\n\
9739 First arg INTERRUPT non-nil means use input interrupts;\n\
9740 nil means use CBREAK mode.\n\
9741 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
9742 (no effect except in CBREAK mode).\n\
9743 Third arg META t means accept 8-bit input (for a Meta key).\n\
9744 META nil means ignore the top bit, on the assumption it is parity.\n\
9745 Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\
9746 Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\
9747 See also `current-input-mode'.")
9748 (interrupt
, flow
, meta
, quit
)
9749 Lisp_Object interrupt
, flow
, meta
, quit
;
9752 && (!INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400))
9753 error ("set-input-mode: QUIT must be an ASCII character");
9755 #ifdef POLL_FOR_INPUT
9760 /* this causes startup screen to be restored and messes with the mouse */
9765 /* Note SIGIO has been undef'd if FIONREAD is missing. */
9766 if (read_socket_hook
)
9768 /* When using X, don't give the user a real choice,
9769 because we haven't implemented the mechanisms to support it. */
9770 #ifdef NO_SOCK_SIGIO
9771 interrupt_input
= 0;
9772 #else /* not NO_SOCK_SIGIO */
9773 interrupt_input
= 1;
9774 #endif /* NO_SOCK_SIGIO */
9777 interrupt_input
= !NILP (interrupt
);
9778 #else /* not SIGIO */
9779 interrupt_input
= 0;
9780 #endif /* not SIGIO */
9782 /* Our VMS input only works by interrupts, as of now. */
9784 interrupt_input
= 1;
9787 flow_control
= !NILP (flow
);
9790 else if (EQ (meta
, Qt
))
9795 /* Don't let this value be out of range. */
9796 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
9802 #ifdef POLL_FOR_INPUT
9803 poll_suppress_count
= 1;
9809 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
9810 "Return information about the way Emacs currently reads keyboard input.\n\
9811 The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
9812 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\
9813 nil, Emacs is using CBREAK mode.\n\
9814 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\
9815 terminal; this does not apply if Emacs uses interrupt-driven input.\n\
9816 META is t if accepting 8-bit input with 8th bit as Meta flag.\n\
9817 META nil means ignoring the top bit, on the assumption it is parity.\n\
9818 META is neither t nor nil if accepting 8-bit input and using\n\
9819 all 8 bits as the character code.\n\
9820 QUIT is the character Emacs currently uses to quit.\n\
9821 The elements of this list correspond to the arguments of\n\
9827 val
[0] = interrupt_input
? Qt
: Qnil
;
9828 val
[1] = flow_control
? Qt
: Qnil
;
9829 val
[2] = meta_key
== 2 ? make_number (0) : meta_key
== 1 ? Qt
: Qnil
;
9830 XSETFASTINT (val
[3], quit_char
);
9832 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
9837 * Set up a new kboard object with reasonable initial values.
9843 kb
->Voverriding_terminal_local_map
= Qnil
;
9844 kb
->Vlast_command
= Qnil
;
9845 kb
->Vreal_last_command
= Qnil
;
9846 kb
->Vprefix_arg
= Qnil
;
9847 kb
->Vlast_prefix_arg
= Qnil
;
9848 kb
->kbd_queue
= Qnil
;
9849 kb
->kbd_queue_has_data
= 0;
9850 kb
->immediate_echo
= 0;
9851 kb
->echoptr
= kb
->echobuf
;
9852 kb
->echo_after_prompt
= -1;
9853 kb
->kbd_macro_buffer
= 0;
9854 kb
->kbd_macro_bufsize
= 0;
9855 kb
->defining_kbd_macro
= Qnil
;
9856 kb
->Vlast_kbd_macro
= Qnil
;
9857 kb
->reference_count
= 0;
9858 kb
->Vsystem_key_alist
= Qnil
;
9859 kb
->system_key_syms
= Qnil
;
9860 kb
->Vdefault_minibuffer_frame
= Qnil
;
9864 * Destroy the contents of a kboard object, but not the object itself.
9865 * We use this just before deleting it, or if we're going to initialize
9872 if (kb
->kbd_macro_buffer
)
9873 xfree (kb
->kbd_macro_buffer
);
9882 for (kbp
= &all_kboards
; *kbp
!= kb
; kbp
= &(*kbp
)->next_kboard
)
9885 *kbp
= kb
->next_kboard
;
9894 /* This is correct before outermost invocation of the editor loop */
9895 command_loop_level
= -1;
9897 quit_char
= Ctl ('g');
9898 Vunread_command_events
= Qnil
;
9899 unread_command_char
= -1;
9900 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
9902 recent_keys_index
= 0;
9903 kbd_fetch_ptr
= kbd_buffer
;
9904 kbd_store_ptr
= kbd_buffer
;
9905 kbd_buffer_gcpro
= Fmake_vector (make_number (2 * KBD_BUFFER_SIZE
), Qnil
);
9907 do_mouse_tracking
= Qnil
;
9911 /* This means that command_loop_1 won't try to select anything the first
9913 internal_last_event_frame
= Qnil
;
9914 Vlast_event_frame
= internal_last_event_frame
;
9917 current_kboard
= initial_kboard
;
9919 wipe_kboard (current_kboard
);
9920 init_kboard (current_kboard
);
9922 if (!noninteractive
&& !read_socket_hook
&& NILP (Vwindow_system
))
9924 signal (SIGINT
, interrupt_signal
);
9925 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
9926 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
9927 SIGQUIT and we can't tell which one it will give us. */
9928 signal (SIGQUIT
, interrupt_signal
);
9929 #endif /* HAVE_TERMIO */
9931 /* Note SIGIO has been undef'd if FIONREAD is missing. */
9933 if (!noninteractive
)
9934 signal (SIGIO
, input_available_signal
);
9937 /* Use interrupt input by default, if it works and noninterrupt input
9938 has deficiencies. */
9940 #ifdef INTERRUPT_INPUT
9941 interrupt_input
= 1;
9943 interrupt_input
= 0;
9946 /* Our VMS input only works by interrupts, as of now. */
9948 interrupt_input
= 1;
9954 if (keyboard_init_hook
)
9955 (*keyboard_init_hook
) ();
9957 #ifdef POLL_FOR_INPUT
9958 poll_suppress_count
= 1;
9963 /* This type's only use is in syms_of_keyboard, to initialize the
9964 event header symbols and put properties on them. */
9971 struct event_head head_table
[] = {
9972 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
9973 &Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
,
9974 &Qswitch_frame
, "switch-frame", &Qswitch_frame
,
9975 &Qdelete_frame
, "delete-frame", &Qdelete_frame
,
9976 &Qiconify_frame
, "iconify-frame", &Qiconify_frame
,
9977 &Qmake_frame_visible
, "make-frame-visible", &Qmake_frame_visible
,
9983 Vlispy_mouse_stem
= build_string ("mouse");
9984 staticpro (&Vlispy_mouse_stem
);
9987 QCimage
= intern (":image");
9988 staticpro (&QCimage
);
9990 staticpro (&Qhelp_echo
);
9991 Qhelp_echo
= intern ("help-echo");
9993 staticpro (&item_properties
);
9994 item_properties
= Qnil
;
9996 staticpro (&tool_bar_item_properties
);
9997 tool_bar_item_properties
= Qnil
;
9998 staticpro (&tool_bar_items_vector
);
9999 tool_bar_items_vector
= Qnil
;
10001 staticpro (&real_this_command
);
10002 real_this_command
= Qnil
;
10004 Qtimer_event_handler
= intern ("timer-event-handler");
10005 staticpro (&Qtimer_event_handler
);
10007 Qdisabled_command_hook
= intern ("disabled-command-hook");
10008 staticpro (&Qdisabled_command_hook
);
10010 Qself_insert_command
= intern ("self-insert-command");
10011 staticpro (&Qself_insert_command
);
10013 Qforward_char
= intern ("forward-char");
10014 staticpro (&Qforward_char
);
10016 Qbackward_char
= intern ("backward-char");
10017 staticpro (&Qbackward_char
);
10019 Qdisabled
= intern ("disabled");
10020 staticpro (&Qdisabled
);
10022 Qundefined
= intern ("undefined");
10023 staticpro (&Qundefined
);
10025 Qpre_command_hook
= intern ("pre-command-hook");
10026 staticpro (&Qpre_command_hook
);
10028 Qpost_command_hook
= intern ("post-command-hook");
10029 staticpro (&Qpost_command_hook
);
10031 Qpost_command_idle_hook
= intern ("post-command-idle-hook");
10032 staticpro (&Qpost_command_idle_hook
);
10034 Qdeferred_action_function
= intern ("deferred-action-function");
10035 staticpro (&Qdeferred_action_function
);
10037 Qcommand_hook_internal
= intern ("command-hook-internal");
10038 staticpro (&Qcommand_hook_internal
);
10040 Qfunction_key
= intern ("function-key");
10041 staticpro (&Qfunction_key
);
10042 Qmouse_click
= intern ("mouse-click");
10043 staticpro (&Qmouse_click
);
10045 Qmouse_wheel
= intern ("mouse-wheel");
10046 staticpro (&Qmouse_wheel
);
10047 Qlanguage_change
= intern ("language-change");
10048 staticpro (&Qlanguage_change
);
10050 Qdrag_n_drop
= intern ("drag-n-drop");
10051 staticpro (&Qdrag_n_drop
);
10053 Qusr1_signal
= intern ("usr1-signal");
10054 staticpro (&Qusr1_signal
);
10055 Qusr2_signal
= intern ("usr2-signal");
10056 staticpro (&Qusr2_signal
);
10058 Qmenu_enable
= intern ("menu-enable");
10059 staticpro (&Qmenu_enable
);
10060 Qmenu_alias
= intern ("menu-alias");
10061 staticpro (&Qmenu_alias
);
10062 QCenable
= intern (":enable");
10063 staticpro (&QCenable
);
10064 QCvisible
= intern (":visible");
10065 staticpro (&QCvisible
);
10066 QChelp
= intern (":help");
10067 staticpro (&QChelp
);
10068 QCfilter
= intern (":filter");
10069 staticpro (&QCfilter
);
10070 QCbutton
= intern (":button");
10071 staticpro (&QCbutton
);
10072 QCkeys
= intern (":keys");
10073 staticpro (&QCkeys
);
10074 QCkey_sequence
= intern (":key-sequence");
10075 staticpro (&QCkey_sequence
);
10076 QCtoggle
= intern (":toggle");
10077 staticpro (&QCtoggle
);
10078 QCradio
= intern (":radio");
10079 staticpro (&QCradio
);
10081 Qmode_line
= intern ("mode-line");
10082 staticpro (&Qmode_line
);
10083 Qvertical_line
= intern ("vertical-line");
10084 staticpro (&Qvertical_line
);
10085 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
10086 staticpro (&Qvertical_scroll_bar
);
10087 Qmenu_bar
= intern ("menu-bar");
10088 staticpro (&Qmenu_bar
);
10090 Qabove_handle
= intern ("above-handle");
10091 staticpro (&Qabove_handle
);
10092 Qhandle
= intern ("handle");
10093 staticpro (&Qhandle
);
10094 Qbelow_handle
= intern ("below-handle");
10095 staticpro (&Qbelow_handle
);
10096 Qup
= intern ("up");
10098 Qdown
= intern ("down");
10099 staticpro (&Qdown
);
10100 Qtop
= intern ("top");
10102 Qbottom
= intern ("bottom");
10103 staticpro (&Qbottom
);
10104 Qend_scroll
= intern ("end-scroll");
10105 staticpro (&Qend_scroll
);
10106 Qratio
= intern ("ratio");
10107 staticpro (&Qratio
);
10109 Qevent_kind
= intern ("event-kind");
10110 staticpro (&Qevent_kind
);
10111 Qevent_symbol_elements
= intern ("event-symbol-elements");
10112 staticpro (&Qevent_symbol_elements
);
10113 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
10114 staticpro (&Qevent_symbol_element_mask
);
10115 Qmodifier_cache
= intern ("modifier-cache");
10116 staticpro (&Qmodifier_cache
);
10118 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
10119 staticpro (&Qrecompute_lucid_menubar
);
10120 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
10121 staticpro (&Qactivate_menubar_hook
);
10123 Qpolling_period
= intern ("polling-period");
10124 staticpro (&Qpolling_period
);
10126 Qinput_method_function
= intern ("input-method-function");
10127 staticpro (&Qinput_method_function
);
10129 Qinput_method_exit_on_first_char
= intern ("input-method-exit-on-first-char");
10130 staticpro (&Qinput_method_exit_on_first_char
);
10131 Qinput_method_use_echo_area
= intern ("input-method-use-echo-area");
10132 staticpro (&Qinput_method_use_echo_area
);
10134 Fset (Qinput_method_exit_on_first_char
, Qnil
);
10135 Fset (Qinput_method_use_echo_area
, Qnil
);
10137 last_point_position_buffer
= Qnil
;
10140 struct event_head
*p
;
10142 for (p
= head_table
;
10143 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
10146 *p
->var
= intern (p
->name
);
10147 staticpro (p
->var
);
10148 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
10149 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
10153 button_down_location
= Fmake_vector (make_number (1), Qnil
);
10154 staticpro (&button_down_location
);
10155 mouse_syms
= Fmake_vector (make_number (1), Qnil
);
10156 staticpro (&mouse_syms
);
10160 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
10162 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
10163 for (i
= 0; i
< len
; i
++)
10164 if (modifier_names
[i
])
10165 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
10166 staticpro (&modifier_symbols
);
10169 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
10170 staticpro (&recent_keys
);
10172 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
10173 staticpro (&this_command_keys
);
10175 raw_keybuf
= Fmake_vector (make_number (30), Qnil
);
10176 staticpro (&raw_keybuf
);
10178 Qextended_command_history
= intern ("extended-command-history");
10179 Fset (Qextended_command_history
, Qnil
);
10180 staticpro (&Qextended_command_history
);
10182 kbd_buffer_gcpro
= Fmake_vector (make_number (2 * KBD_BUFFER_SIZE
), Qnil
);
10183 staticpro (&kbd_buffer_gcpro
);
10185 accent_key_syms
= Qnil
;
10186 staticpro (&accent_key_syms
);
10188 func_key_syms
= Qnil
;
10189 staticpro (&func_key_syms
);
10192 mouse_wheel_syms
= Qnil
;
10193 staticpro (&mouse_wheel_syms
);
10195 drag_n_drop_syms
= Qnil
;
10196 staticpro (&drag_n_drop_syms
);
10199 unread_switch_frame
= Qnil
;
10200 staticpro (&unread_switch_frame
);
10202 internal_last_event_frame
= Qnil
;
10203 staticpro (&internal_last_event_frame
);
10205 read_key_sequence_cmd
= Qnil
;
10206 staticpro (&read_key_sequence_cmd
);
10208 menu_bar_one_keymap_changed_items
= Qnil
;
10209 staticpro (&menu_bar_one_keymap_changed_items
);
10211 defsubr (&Sevent_convert_list
);
10212 defsubr (&Sread_key_sequence
);
10213 defsubr (&Sread_key_sequence_vector
);
10214 defsubr (&Srecursive_edit
);
10216 defsubr (&Strack_mouse
);
10218 defsubr (&Sinput_pending_p
);
10219 defsubr (&Scommand_execute
);
10220 defsubr (&Srecent_keys
);
10221 defsubr (&Sthis_command_keys
);
10222 defsubr (&Sthis_command_keys_vector
);
10223 defsubr (&Sthis_single_command_keys
);
10224 defsubr (&Sthis_single_command_raw_keys
);
10225 defsubr (&Sreset_this_command_lengths
);
10226 defsubr (&Sclear_this_command_keys
);
10227 defsubr (&Ssuspend_emacs
);
10228 defsubr (&Sabort_recursive_edit
);
10229 defsubr (&Sexit_recursive_edit
);
10230 defsubr (&Srecursion_depth
);
10231 defsubr (&Stop_level
);
10232 defsubr (&Sdiscard_input
);
10233 defsubr (&Sopen_dribble_file
);
10234 defsubr (&Sset_input_mode
);
10235 defsubr (&Scurrent_input_mode
);
10236 defsubr (&Sexecute_extended_command
);
10238 DEFVAR_LISP ("last-command-char", &last_command_char
,
10239 "Last input event that was part of a command.");
10241 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char
,
10242 "Last input event that was part of a command.");
10244 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
10245 "Last input event in a command, except for mouse menu events.\n\
10246 Mouse menus give back keys that don't look like mouse events;\n\
10247 this variable holds the actual mouse event that led to the menu,\n\
10248 so that you can determine whether the command was run by mouse or not.");
10250 DEFVAR_LISP ("last-input-char", &last_input_char
,
10251 "Last input event.");
10253 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char
,
10254 "Last input event.");
10256 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
10257 "List of events to be read as the command input.\n\
10258 These events are processed first, before actual keyboard input.");
10259 Vunread_command_events
= Qnil
;
10261 DEFVAR_INT ("unread-command-char", &unread_command_char
,
10262 "If not -1, an object to be read as next command input event.");
10264 DEFVAR_LISP ("unread-post-input-method-events", &Vunread_post_input_method_events
,
10265 "List of events to be processed as input by input methods.\n\
10266 These events are processed after `unread-command-events', but\n\
10267 before actual keyboard input.");
10268 Vunread_post_input_method_events
= Qnil
;
10270 DEFVAR_LISP ("unread-input-method-events", &Vunread_input_method_events
,
10271 "List of events to be processed as input by input methods.\n\
10272 These events are processed after `unread-command-events', but\n\
10273 before actual keyboard input.");
10274 Vunread_input_method_events
= Qnil
;
10276 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
10277 "Meta-prefix character code.\n\
10278 Meta-foo as command input turns into this character followed by foo.");
10279 XSETINT (meta_prefix_char
, 033);
10281 DEFVAR_KBOARD ("last-command", Vlast_command
,
10282 "The last command executed.\n\
10283 Normally a symbol with a function definition, but can be whatever was found\n\
10284 in the keymap, or whatever the variable `this-command' was set to by that\n\
10287 The value `mode-exit' is special; it means that the previous command\n\
10288 read an event that told it to exit, and it did so and unread that event.\n\
10289 In other words, the present command is the event that made the previous\n\
10292 The value `kill-region' is special; it means that the previous command\n\
10293 was a kill command.");
10295 DEFVAR_KBOARD ("real-last-command", Vreal_last_command
,
10296 "Same as `last-command', but never altered by Lisp code.");
10298 DEFVAR_LISP ("this-command", &Vthis_command
,
10299 "The command now being executed.\n\
10300 The command can set this variable; whatever is put here\n\
10301 will be in `last-command' during the following command.");
10302 Vthis_command
= Qnil
;
10304 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
10305 "*Number of input events between auto-saves.\n\
10306 Zero means disable autosaving due to number of characters typed.");
10307 auto_save_interval
= 300;
10309 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
10310 "*Number of seconds idle time before auto-save.\n\
10311 Zero or nil means disable auto-saving due to idleness.\n\
10312 After auto-saving due to this many seconds of idle time,\n\
10313 Emacs also does a garbage collection if that seems to be warranted.");
10314 XSETFASTINT (Vauto_save_timeout
, 30);
10316 DEFVAR_LISP ("echo-keystrokes", &Vecho_keystrokes
,
10317 "*Nonzero means echo unfinished commands after this many seconds of pause.\n\
10318 The value may be integer or floating point.");
10319 Vecho_keystrokes
= make_number (1);
10321 DEFVAR_INT ("polling-period", &polling_period
,
10322 "*Interval between polling for input during Lisp execution.\n\
10323 The reason for polling is to make C-g work to stop a running program.\n\
10324 Polling is needed only when using X windows and SIGIO does not work.\n\
10325 Polling is automatically disabled in all other cases.");
10326 polling_period
= 2;
10328 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
10329 "*Maximum time between mouse clicks to make a double-click.\n\
10330 Measured in milliseconds. nil means disable double-click recognition;\n\
10331 t means double-clicks have no time limit and are detected\n\
10332 by position only.");
10333 Vdouble_click_time
= make_number (500);
10335 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
10336 "*Non-nil means inhibit local map menu bar menus.");
10337 inhibit_local_menu_bar_menus
= 0;
10339 DEFVAR_INT ("num-input-keys", &num_input_keys
,
10340 "Number of complete key sequences read as input so far.\n\
10341 This includes key sequences read from keyboard macros.\n\
10342 The number is effectively the number of interactive command invocations.");
10343 num_input_keys
= 0;
10345 DEFVAR_INT ("num-nonmacro-input-events", &num_nonmacro_input_events
,
10346 "Number of input events read from the keyboard so far.\n\
10347 This does not include events generated by keyboard macros.");
10348 num_nonmacro_input_events
= 0;
10350 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
10351 "The frame in which the most recently read event occurred.\n\
10352 If the last event came from a keyboard macro, this is set to `macro'.");
10353 Vlast_event_frame
= Qnil
;
10355 /* This variable is set up in sysdep.c. */
10356 DEFVAR_LISP ("tty-erase-char", &Vtty_erase_char
,
10357 "The ERASE character as set by the user with stty.");
10359 DEFVAR_LISP ("help-char", &Vhelp_char
,
10360 "Character to recognize as meaning Help.\n\
10361 When it is read, do `(eval help-form)', and display result if it's a string.\n\
10362 If the value of `help-form' is nil, this char can be read normally.");
10363 XSETINT (Vhelp_char
, Ctl ('H'));
10365 DEFVAR_LISP ("help-event-list", &Vhelp_event_list
,
10366 "List of input events to recognize as meaning Help.\n\
10367 These work just like the value of `help-char' (see that).");
10368 Vhelp_event_list
= Qnil
;
10370 DEFVAR_LISP ("help-form", &Vhelp_form
,
10371 "Form to execute when character `help-char' is read.\n\
10372 If the form returns a string, that string is displayed.\n\
10373 If `help-form' is nil, the help char is not recognized.");
10376 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
10377 "Command to run when `help-char' character follows a prefix key.\n\
10378 This command is used only when there is no actual binding\n\
10379 for that character after that prefix key.");
10380 Vprefix_help_command
= Qnil
;
10382 DEFVAR_LISP ("top-level", &Vtop_level
,
10383 "Form to evaluate when Emacs starts up.\n\
10384 Useful to set before you dump a modified Emacs.");
10387 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
10388 "Translate table for keyboard input, or nil.\n\
10389 Each character is looked up in this string and the contents used instead.\n\
10390 The value may be a string, a vector, or a char-table.\n\
10391 If it is a string or vector of length N,\n\
10392 character codes N and up are untranslated.\n\
10393 In a vector or a char-table, an element which is nil means \"no translation\".");
10394 Vkeyboard_translate_table
= Qnil
;
10396 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
10397 "Non-nil means to always spawn a subshell instead of suspending.\n\
10398 \(Even if the operating system has support for stopping a process.\)");
10399 cannot_suspend
= 0;
10401 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
10402 "Non-nil means prompt with menus when appropriate.\n\
10403 This is done when reading from a keymap that has a prompt string,\n\
10404 for elements that have prompt strings.\n\
10405 The menu is displayed on the screen\n\
10406 if X menus were enabled at configuration\n\
10407 time and the previous event was a mouse click prefix key.\n\
10408 Otherwise, menu prompting uses the echo area.");
10409 menu_prompting
= 1;
10411 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
10412 "Character to see next line of menu prompt.\n\
10413 Type this character while in a menu prompt to rotate around the lines of it.");
10414 XSETINT (menu_prompt_more_char
, ' ');
10416 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
10417 "A mask of additional modifier keys to use with every keyboard character.\n\
10418 Emacs applies the modifiers of the character stored here to each keyboard\n\
10419 character it reads. For example, after evaluating the expression\n\
10420 (setq extra-keyboard-modifiers ?\\C-x)\n\
10421 all input characters will have the control modifier applied to them.\n\
10423 Note that the character ?\\C-@, equivalent to the integer zero, does\n\
10424 not count as a control character; rather, it counts as a character\n\
10425 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\
10426 cancels any modification.");
10427 extra_keyboard_modifiers
= 0;
10429 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
10430 "If an editing command sets this to t, deactivate the mark afterward.\n\
10431 The command loop sets this to nil before each command,\n\
10432 and tests the value when the command returns.\n\
10433 Buffer modification stores t in this variable.");
10434 Vdeactivate_mark
= Qnil
;
10436 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
10437 "Temporary storage of pre-command-hook or post-command-hook.");
10438 Vcommand_hook_internal
= Qnil
;
10440 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
10441 "Normal hook run before each command is executed.\n\
10442 If an unhandled error happens in running this hook,\n\
10443 the hook value is set to nil, since otherwise the error\n\
10444 might happen repeatedly and make Emacs nonfunctional.");
10445 Vpre_command_hook
= Qnil
;
10447 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
10448 "Normal hook run after each command is executed.\n\
10449 If an unhandled error happens in running this hook,\n\
10450 the hook value is set to nil, since otherwise the error\n\
10451 might happen repeatedly and make Emacs nonfunctional.");
10452 Vpost_command_hook
= Qnil
;
10454 DEFVAR_LISP ("post-command-idle-hook", &Vpost_command_idle_hook
,
10455 "Normal hook run after each command is executed, if idle.\n\
10456 Errors running the hook are caught and ignored.\n\
10457 This feature is obsolete; use idle timers instead. See `etc/NEWS'.");
10458 Vpost_command_idle_hook
= Qnil
;
10460 DEFVAR_INT ("post-command-idle-delay", &post_command_idle_delay
,
10461 "Delay time before running `post-command-idle-hook'.\n\
10462 This is measured in microseconds.");
10463 post_command_idle_delay
= 100000;
10466 DEFVAR_LISP ("echo-area-clear-hook", ...,
10467 "Normal hook run when clearing the echo area.");
10469 Qecho_area_clear_hook
= intern ("echo-area-clear-hook");
10470 XSYMBOL (Qecho_area_clear_hook
)->value
= Qnil
;
10472 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
10473 "t means menu bar, specified Lucid style, needs to be recomputed.");
10474 Vlucid_menu_bar_dirty_flag
= Qnil
;
10476 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
10477 "List of menu bar items to move to the end of the menu bar.\n\
10478 The elements of the list are event types that may have menu bar bindings.");
10479 Vmenu_bar_final_items
= Qnil
;
10481 DEFVAR_KBOARD ("overriding-terminal-local-map",
10482 Voverriding_terminal_local_map
,
10483 "Per-terminal keymap that overrides all other local keymaps.\n\
10484 If this variable is non-nil, it is used as a keymap instead of the\n\
10485 buffer's local map, and the minor mode keymaps and text property keymaps.\n\
10486 This variable is intended to let commands such as `universal-argumemnt'\n\
10487 set up a different keymap for reading the next command.");
10489 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
10490 "Keymap that overrides all other local keymaps.\n\
10491 If this variable is non-nil, it is used as a keymap instead of the\n\
10492 buffer's local map, and the minor mode keymaps and text property keymaps.");
10493 Voverriding_local_map
= Qnil
;
10495 DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag
,
10496 "Non-nil means `overriding-local-map' applies to the menu bar.\n\
10497 Otherwise, the menu bar continues to reflect the buffer's local map\n\
10498 and the minor mode maps regardless of `overriding-local-map'.");
10499 Voverriding_local_map_menu_flag
= Qnil
;
10501 DEFVAR_LISP ("special-event-map", &Vspecial_event_map
,
10502 "Keymap defining bindings for special events to execute at low level.");
10503 Vspecial_event_map
= Fcons (intern ("keymap"), Qnil
);
10505 DEFVAR_LISP ("track-mouse", &do_mouse_tracking
,
10506 "*Non-nil means generate motion events for mouse motion.");
10508 DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist
,
10509 "Alist of system-specific X windows key symbols.\n\
10510 Each element should have the form (N . SYMBOL) where N is the\n\
10511 numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\
10512 and SYMBOL is its name.");
10514 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
10515 "List of deferred actions to be performed at a later time.\n\
10516 The precise format isn't relevant here; we just check whether it is nil.");
10517 Vdeferred_action_list
= Qnil
;
10519 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
10520 "Function to call to handle deferred actions, after each command.\n\
10521 This function is called with no arguments after each command\n\
10522 whenever `deferred-action-list' is non-nil.");
10523 Vdeferred_action_function
= Qnil
;
10525 DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings
,
10526 "*Non-nil means show the equivalent key-binding when M-x command has one.\n\
10527 The value can be a length of time to show the message for.\n\
10528 If the value is non-nil and not a number, we wait 2 seconds.");
10529 Vsuggest_key_bindings
= Qt
;
10531 DEFVAR_LISP ("timer-list", &Vtimer_list
,
10532 "List of active absolute time timers in order of increasing time");
10533 Vtimer_list
= Qnil
;
10535 DEFVAR_LISP ("timer-idle-list", &Vtimer_idle_list
,
10536 "List of active idle-time timers in order of increasing time");
10537 Vtimer_idle_list
= Qnil
;
10539 DEFVAR_LISP ("input-method-function", &Vinput_method_function
,
10540 "If non-nil, the function that implements the current input method.\n\
10541 It's called with one argument, a printing character that was just read.\n\
10542 \(That means a character with code 040...0176.)\n\
10543 Typically this function uses `read-event' to read additional events.\n\
10544 When it does so, it should first bind `input-method-function' to nil\n\
10545 so it will not be called recursively.\n\
10547 The function should return a list of zero or more events\n\
10548 to be used as input. If it wants to put back some events\n\
10549 to be reconsidered, separately, by the input method,\n\
10550 it can add them to the beginning of `unread-command-events'.\n\
10552 The input method function can find in `input-method-previous-method'\n\
10553 the previous echo area message.\n\
10555 The input method function should refer to the variables\n\
10556 `input-method-use-echo-area' and `input-method-exit-on-first-char'\n\
10557 for guidance on what to do.");
10558 Vinput_method_function
= Qnil
;
10560 DEFVAR_LISP ("input-method-previous-message",
10561 &Vinput_method_previous_message
,
10562 "When `input-method-function' is called, hold the previous echo area message.\n\
10563 This variable exists because `read-event' clears the echo area\n\
10564 before running the input method. It is nil if there was no message.");
10565 Vinput_method_previous_message
= Qnil
;
10567 DEFVAR_LISP ("show-help-function", &Vshow_help_function
,
10568 "If non-nil, the function that implements the display of help.\n\
10569 It's called with one argument, the help string to display.");
10570 Vshow_help_function
= Qnil
;
10572 DEFVAR_LISP ("disable-point-adjustment", &Vdisable_point_adjustment
,
10573 "If non-nil, suppress point adjustment after executing a command.\n\
10575 After a command is executed, if point is moved into a region that has\n\
10576 special properties (e.g. composition, display), we adjust point to\n\
10577 the boundary of the region. But, several special commands sets this\n\
10578 variable to non-nil, then we suppress the point adjustment.\n\
10580 This variable is set to nil before reading a command, and is checked\n\
10581 just after executing the command");
10582 Vdisable_point_adjustment
= Qnil
;
10584 DEFVAR_LISP ("global-disable-point-adjustment",
10585 &Vglobal_disable_point_adjustment
,
10586 "*If non-nil, always suppress point adjustment.\n\
10588 The default value is nil, in which case, point adjustment are\n\
10589 suppressed only after special commands that set\n\
10590 `disable-point-adjustment' (which see) to non-nil.");
10591 Vglobal_disable_point_adjustment
= Qnil
;
10593 DEFVAR_LISP ("update-menu-bindings", &update_menu_bindings
,
10594 "Non-nil means updating menu bindings is allowed.\n\
10595 A value of nil means menu bindings should not be updated.\n\
10596 Used during Emacs' startup.");
10597 update_menu_bindings
= 1;
10601 keys_of_keyboard ()
10603 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
10604 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
10605 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
10606 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
10607 initial_define_key (meta_map
, 'x', "execute-extended-command");
10609 initial_define_lispy_key (Vspecial_event_map
, "delete-frame",
10610 "handle-delete-frame");
10611 initial_define_lispy_key (Vspecial_event_map
, "iconify-frame",
10613 initial_define_lispy_key (Vspecial_event_map
, "make-frame-visible",