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 extern char *pending_malloc_warning
;
457 /* Circular buffer for pre-read keyboard input. */
459 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
461 /* Vector to GCPRO the Lisp objects referenced from kbd_buffer.
463 The interrupt-level event handlers will never enqueue an event on a
464 frame which is not in Vframe_list, and once an event is dequeued,
465 internal_last_event_frame or the event itself points to the frame.
468 But while the event is sitting in the queue, it's completely
469 unprotected. Suppose the user types one command which will run for
470 a while and then delete a frame, and then types another event at
471 the frame that will be deleted, before the command gets around to
472 it. Suppose there are no references to this frame elsewhere in
473 Emacs, and a GC occurs before the second event is dequeued. Now we
474 have an event referring to a freed frame, which will crash Emacs
477 Similar things happen when an event on a scroll bar is enqueued; the
478 window may be deleted while the event is in the queue.
480 So, we use this vector to protect the Lisp_Objects in the event
481 queue. That way, they'll be dequeued as dead frames or windows,
482 but still valid Lisp objects.
484 If kbd_buffer[i].kind != no_event, then
486 AREF (kbd_buffer_gcpro, 2 * i) == kbd_buffer[i].frame_or_window.
487 AREF (kbd_buffer_gcpro, 2 * i + 1) == kbd_buffer[i].arg. */
489 static Lisp_Object kbd_buffer_gcpro
;
491 /* Pointer to next available character in kbd_buffer.
492 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
493 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the
494 next available char is in kbd_buffer[0]. */
495 static struct input_event
*kbd_fetch_ptr
;
497 /* Pointer to next place to store character in kbd_buffer. This
498 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
499 character should go in kbd_buffer[0]. */
500 static struct input_event
* volatile kbd_store_ptr
;
502 /* The above pair of variables forms a "queue empty" flag. When we
503 enqueue a non-hook event, we increment kbd_store_ptr. When we
504 dequeue a non-hook event, we increment kbd_fetch_ptr. We say that
505 there is input available iff the two pointers are not equal.
507 Why not just have a flag set and cleared by the enqueuing and
508 dequeuing functions? Such a flag could be screwed up by interrupts
509 at inopportune times. */
511 /* If this flag is non-nil, we check mouse_moved to see when the
512 mouse moves, and motion events will appear in the input stream.
513 Otherwise, mouse motion is ignored. */
514 static Lisp_Object do_mouse_tracking
;
516 /* Symbols to head events. */
517 Lisp_Object Qmouse_movement
;
518 Lisp_Object Qscroll_bar_movement
;
519 Lisp_Object Qswitch_frame
;
520 Lisp_Object Qdelete_frame
;
521 Lisp_Object Qiconify_frame
;
522 Lisp_Object Qmake_frame_visible
;
523 Lisp_Object Qhelp_echo
;
525 /* Symbols to denote kinds of events. */
526 Lisp_Object Qfunction_key
;
527 Lisp_Object Qmouse_click
;
529 Lisp_Object Qmouse_wheel
;
530 Lisp_Object Qlanguage_change
;
532 Lisp_Object Qdrag_n_drop
;
533 /* Lisp_Object Qmouse_movement; - also an event header */
535 /* Properties of event headers. */
536 Lisp_Object Qevent_kind
;
537 Lisp_Object Qevent_symbol_elements
;
539 /* menu item parts */
540 Lisp_Object Qmenu_alias
;
541 Lisp_Object Qmenu_enable
;
542 Lisp_Object QCenable
, QCvisible
, QChelp
, QCfilter
, QCkeys
, QCkey_sequence
;
543 Lisp_Object QCbutton
, QCtoggle
, QCradio
;
544 extern Lisp_Object Vdefine_key_rebound_commands
;
545 extern Lisp_Object Qmenu_item
;
547 /* An event header symbol HEAD may have a property named
548 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
549 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
550 mask of modifiers applied to it. If present, this is used to help
551 speed up parse_modifiers. */
552 Lisp_Object Qevent_symbol_element_mask
;
554 /* An unmodified event header BASE may have a property named
555 Qmodifier_cache, which is an alist mapping modifier masks onto
556 modified versions of BASE. If present, this helps speed up
558 Lisp_Object Qmodifier_cache
;
560 /* Symbols to use for parts of windows. */
561 Lisp_Object Qmode_line
;
562 Lisp_Object Qvertical_line
;
563 Lisp_Object Qvertical_scroll_bar
;
564 Lisp_Object Qmenu_bar
;
566 Lisp_Object
recursive_edit_unwind (), command_loop ();
567 Lisp_Object
Fthis_command_keys ();
568 Lisp_Object Qextended_command_history
;
569 EMACS_TIME
timer_check ();
571 extern Lisp_Object Vhistory_length
;
573 extern char *x_get_keysym_name ();
575 static void record_menu_key ();
577 Lisp_Object Qpolling_period
;
579 /* List of absolute timers. Appears in order of next scheduled event. */
580 Lisp_Object Vtimer_list
;
582 /* List of idle time timers. Appears in order of next scheduled event. */
583 Lisp_Object Vtimer_idle_list
;
585 /* Incremented whenever a timer is run. */
588 extern Lisp_Object Vprint_level
, Vprint_length
;
590 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
592 EMACS_TIME
*input_available_clear_time
;
594 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
595 Default is 1 if INTERRUPT_INPUT is defined. */
598 /* Nonzero while interrupts are temporarily deferred during redisplay. */
599 int interrupts_deferred
;
601 /* Nonzero means use ^S/^Q for flow control. */
604 /* Allow m- file to inhibit use of FIONREAD. */
605 #ifdef BROKEN_FIONREAD
609 /* We are unable to use interrupts if FIONREAD is not available,
610 so flush SIGIO so we won't try. */
617 /* If we support a window system, turn on the code to poll periodically
618 to detect C-g. It isn't actually used when doing interrupt input. */
619 #ifdef HAVE_WINDOW_SYSTEM
620 #define POLL_FOR_INPUT
623 /* After a command is executed, if point is moved into a region that
624 has specific properties (e.g. composition, display), we adjust
625 point to the boundary of the region. But, if a command sets this
626 valiable to non-nil, we suppress this point adjustment. This
627 variable is set to nil before reading a command. */
629 Lisp_Object Vdisable_point_adjustment
;
631 /* If non-nil, always disable point adjustment. */
633 Lisp_Object Vglobal_disable_point_adjustment
;
636 /* Global variable declarations. */
638 /* Function for init_keyboard to call with no args (if nonzero). */
639 void (*keyboard_init_hook
) ();
641 static int read_avail_input
P_ ((int));
642 static void get_input_pending
P_ ((int *, int));
643 static int readable_events
P_ ((int));
644 static Lisp_Object read_char_x_menu_prompt
P_ ((int, Lisp_Object
*,
645 Lisp_Object
, int *));
646 static Lisp_Object
read_char_x_menu_prompt ();
647 static Lisp_Object read_char_minibuf_menu_prompt
P_ ((int, int,
649 static Lisp_Object make_lispy_event
P_ ((struct input_event
*));
651 static Lisp_Object make_lispy_movement
P_ ((struct frame
*, Lisp_Object
,
652 enum scroll_bar_part
,
653 Lisp_Object
, Lisp_Object
,
656 static Lisp_Object modify_event_symbol
P_ ((int, unsigned, Lisp_Object
,
657 Lisp_Object
, char **,
658 Lisp_Object
*, unsigned));
659 static Lisp_Object make_lispy_switch_frame
P_ ((Lisp_Object
));
660 static int parse_solitary_modifier
P_ ((Lisp_Object
));
661 static int parse_solitary_modifier ();
662 static void save_getcjmp
P_ ((jmp_buf));
663 static void save_getcjmp ();
664 static void restore_getcjmp
P_ ((jmp_buf));
665 static Lisp_Object apply_modifiers
P_ ((int, Lisp_Object
));
666 static void clear_event
P_ ((struct input_event
*));
668 /* Nonzero means don't try to suspend even if the operating system seems
670 static int cannot_suspend
;
672 #define min(a,b) ((a)<(b)?(a):(b))
673 #define max(a,b) ((a)>(b)?(a):(b))
675 /* Install the string STR as the beginning of the string of echoing,
676 so that it serves as a prompt for the next character.
677 Also start echoing. */
683 int len
= strlen (str
);
685 if (len
> ECHOBUFSIZE
- 4)
686 len
= ECHOBUFSIZE
- 4;
687 bcopy (str
, current_kboard
->echobuf
, len
);
688 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
689 *current_kboard
->echoptr
= '\0';
691 current_kboard
->echo_after_prompt
= len
;
696 /* Add C to the echo string, if echoing is going on.
697 C can be a character, which is printed prettily ("M-C-x" and all that
698 jazz), or a symbol, whose name is printed. */
704 extern char *push_key_description ();
706 if (current_kboard
->immediate_echo
)
708 char *ptr
= current_kboard
->echoptr
;
710 if (ptr
!= current_kboard
->echobuf
)
713 /* If someone has passed us a composite event, use its head symbol. */
718 if (ptr
- current_kboard
->echobuf
719 > ECHOBUFSIZE
- KEY_DESCRIPTION_SIZE
)
722 ptr
= push_key_description (XINT (c
), ptr
);
724 else if (SYMBOLP (c
))
726 struct Lisp_String
*name
= XSYMBOL (c
)->name
;
727 if ((ptr
- current_kboard
->echobuf
) + STRING_BYTES (name
) + 4
730 bcopy (name
->data
, ptr
, STRING_BYTES (name
));
731 ptr
+= STRING_BYTES (name
);
734 if (current_kboard
->echoptr
== current_kboard
->echobuf
737 strcpy (ptr
, " (Type ? for further options)");
742 current_kboard
->echoptr
= ptr
;
748 /* Temporarily add a dash to the end of the echo string if it's not
749 empty, so that it serves as a mini-prompt for the very next character. */
754 if (!current_kboard
->immediate_echo
755 && current_kboard
->echoptr
== current_kboard
->echobuf
)
757 /* Do nothing if we just printed a prompt. */
758 if (current_kboard
->echo_after_prompt
759 == current_kboard
->echoptr
- current_kboard
->echobuf
)
761 /* Do nothing if not echoing at all. */
762 if (current_kboard
->echoptr
== 0)
765 /* Put a dash at the end of the buffer temporarily,
766 but make it go away when the next character is added. */
767 current_kboard
->echoptr
[0] = '-';
768 current_kboard
->echoptr
[1] = 0;
773 /* Display the current echo string, and begin echoing if not already
779 if (!current_kboard
->immediate_echo
)
782 current_kboard
->immediate_echo
= 1;
784 for (i
= 0; i
< this_command_key_count
; i
++)
787 c
= XVECTOR (this_command_keys
)->contents
[i
];
788 if (! (EVENT_HAS_PARAMETERS (c
)
789 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
796 message2_nolog (current_kboard
->echobuf
, strlen (current_kboard
->echobuf
),
797 ! NILP (current_buffer
->enable_multibyte_characters
));
800 /* Record in what buffer we echoed, and from which kboard. */
801 echo_message_buffer
= echo_area_buffer
[0];
802 echo_kboard
= current_kboard
;
804 if (waiting_for_input
&& !NILP (Vquit_flag
))
805 quit_throw_to_read_char ();
808 /* Turn off echoing, for the start of a new command. */
813 current_kboard
->immediate_echo
= 0;
814 current_kboard
->echoptr
= current_kboard
->echobuf
;
815 current_kboard
->echo_after_prompt
= -1;
816 ok_to_echo_at_next_pause
= NULL
;
818 echo_message_buffer
= Qnil
;
821 /* Return the length of the current echo string. */
826 return current_kboard
->echoptr
- current_kboard
->echobuf
;
829 /* Truncate the current echo message to its first LEN chars.
830 This and echo_char get used by read_key_sequence when the user
831 switches frames while entering a key sequence. */
837 current_kboard
->echobuf
[len
] = '\0';
838 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
839 truncate_echo_area (len
);
843 /* Functions for manipulating this_command_keys. */
845 add_command_key (key
)
848 int size
= XVECTOR (this_command_keys
)->size
;
850 /* If reset-this-command-length was called recently, obey it now.
851 See the doc string of that function for an explanation of why. */
852 if (before_command_restore_flag
)
854 this_command_key_count
= before_command_key_count_1
;
855 if (this_command_key_count
< this_single_command_key_start
)
856 this_single_command_key_start
= this_command_key_count
;
857 echo_truncate (before_command_echo_length_1
);
858 before_command_restore_flag
= 0;
861 if (this_command_key_count
>= size
)
863 Lisp_Object new_keys
;
865 new_keys
= Fmake_vector (make_number (size
* 2), Qnil
);
866 bcopy (XVECTOR (this_command_keys
)->contents
,
867 XVECTOR (new_keys
)->contents
,
868 size
* sizeof (Lisp_Object
));
870 this_command_keys
= new_keys
;
873 XVECTOR (this_command_keys
)->contents
[this_command_key_count
++] = key
;
879 int count
= specpdl_ptr
- specpdl
;
882 if (command_loop_level
> 0)
884 specbind (Qstandard_output
, Qt
);
885 specbind (Qstandard_input
, Qt
);
888 #ifdef HAVE_X_WINDOWS
889 /* The command loop has started a busy-cursor timer, so we have to
890 cancel it here, otherwise it will fire because the recursive edit
891 can take some time. */
892 if (display_busy_cursor_p
)
893 cancel_busy_cursor ();
896 val
= command_loop ();
898 Fsignal (Qquit
, Qnil
);
899 /* Handle throw from read_minibuf when using minibuffer
900 while it's active but we're in another window. */
902 Fsignal (Qerror
, Fcons (val
, Qnil
));
904 return unbind_to (count
, Qnil
);
907 /* When an auto-save happens, record the "time", and don't do again soon. */
912 last_auto_save
= num_nonmacro_input_events
;
915 /* Make an auto save happen as soon as possible at command level. */
918 force_auto_save_soon ()
920 last_auto_save
= - auto_save_interval
- 1;
922 record_asynch_buffer_change ();
925 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
926 "Invoke the editor command loop recursively.\n\
927 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
928 that tells this function to return.\n\
929 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
930 This function is called by the editor initialization to begin editing.")
933 int count
= specpdl_ptr
- specpdl
;
935 command_loop_level
++;
936 update_mode_lines
= 1;
938 record_unwind_protect (recursive_edit_unwind
,
940 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
944 return unbind_to (count
, Qnil
);
948 recursive_edit_unwind (buffer
)
952 Fset_buffer (buffer
);
954 command_loop_level
--;
955 update_mode_lines
= 1;
963 #if 0 /* Theory: if there's anything in Vunread_command_events,
964 it will right away be read by read_key_sequence,
965 and then if we do switch KBOARDS, it will go into the side
966 queue then. So we don't need to do anything special here -- rms. */
967 if (CONSP (Vunread_command_events
))
969 current_kboard
->kbd_queue
970 = nconc2 (Vunread_command_events
, current_kboard
->kbd_queue
);
971 current_kboard
->kbd_queue_has_data
= 1;
973 Vunread_command_events
= Qnil
;
979 /* Switch to the single-kboard state, making current_kboard
980 the only KBOARD from which further input is accepted. */
983 single_kboard_state ()
990 /* Maintain a stack of kboards, so other parts of Emacs
991 can switch temporarily to the kboard of a given frame
992 and then revert to the previous status. */
997 struct kboard_stack
*next
;
1000 static struct kboard_stack
*kboard_stack
;
1003 push_frame_kboard (f
)
1007 struct kboard_stack
*p
1008 = (struct kboard_stack
*) xmalloc (sizeof (struct kboard_stack
));
1010 p
->next
= kboard_stack
;
1011 p
->kboard
= current_kboard
;
1014 current_kboard
= FRAME_KBOARD (f
);
1022 struct kboard_stack
*p
= kboard_stack
;
1023 current_kboard
= p
->kboard
;
1024 kboard_stack
= p
->next
;
1029 /* Handle errors that are not handled at inner levels
1030 by printing an error message and returning to the editor command loop. */
1036 Lisp_Object old_level
, old_length
;
1037 char macroerror
[50];
1039 if (!NILP (executing_macro
))
1041 if (executing_macro_iterations
== 1)
1042 sprintf (macroerror
, "After 1 kbd macro iteration: ");
1044 sprintf (macroerror
, "After %d kbd macro iterations: ",
1045 executing_macro_iterations
);
1050 Vstandard_output
= Qt
;
1051 Vstandard_input
= Qt
;
1052 Vexecuting_macro
= Qnil
;
1053 executing_macro
= Qnil
;
1054 current_kboard
->Vprefix_arg
= Qnil
;
1055 current_kboard
->Vlast_prefix_arg
= Qnil
;
1058 /* Avoid unquittable loop if data contains a circular list. */
1059 old_level
= Vprint_level
;
1060 old_length
= Vprint_length
;
1061 XSETFASTINT (Vprint_level
, 10);
1062 XSETFASTINT (Vprint_length
, 10);
1063 cmd_error_internal (data
, macroerror
);
1064 Vprint_level
= old_level
;
1065 Vprint_length
= old_length
;
1069 Vinhibit_quit
= Qnil
;
1071 any_kboard_state ();
1074 return make_number (0);
1077 /* Take actions on handling an error. DATA is the data that describes
1080 CONTEXT is a C-string containing ASCII characters only which
1081 describes the context in which the error happened. If we need to
1082 generalize CONTEXT to allow multibyte characters, make it a Lisp
1086 cmd_error_internal (data
, context
)
1091 int kill_emacs_p
= 0;
1092 struct frame
*sf
= SELECTED_FRAME ();
1096 clear_message (1, 0);
1098 /* If the window system or terminal frame hasn't been initialized
1099 yet, or we're not interactive, it's best to dump this message out
1100 to stderr and exit. */
1101 if (!sf
->glyphs_initialized_p
1102 /* This is the case of the frame dumped with Emacs, when we're
1103 running under a window system. */
1104 || (!NILP (Vwindow_system
)
1105 && !inhibit_window_system
1106 && FRAME_TERMCAP_P (sf
))
1109 stream
= Qexternal_debugging_output
;
1120 write_string_1 (context
, -1, stream
);
1122 print_error_message (data
, stream
);
1124 /* If the window system or terminal frame hasn't been initialized
1125 yet, or we're in -batch mode, this error should cause Emacs to exit. */
1129 Fkill_emacs (make_number (-1));
1133 Lisp_Object
command_loop_1 ();
1134 Lisp_Object
command_loop_2 ();
1135 Lisp_Object
top_level_1 ();
1137 /* Entry to editor-command-loop.
1138 This level has the catches for exiting/returning to editor command loop.
1139 It returns nil to exit recursive edit, t to abort it. */
1144 if (command_loop_level
> 0 || minibuf_level
> 0)
1147 val
= internal_catch (Qexit
, command_loop_2
, Qnil
);
1148 executing_macro
= Qnil
;
1154 internal_catch (Qtop_level
, top_level_1
, Qnil
);
1155 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
1156 executing_macro
= Qnil
;
1158 /* End of file in -batch run causes exit here. */
1164 /* Here we catch errors in execution of commands within the
1165 editing loop, and reenter the editing loop.
1166 When there is an error, cmd_error runs and returns a non-nil
1167 value to us. A value of nil means that cmd_loop_1 itself
1168 returned due to end of file (or end of kbd macro). */
1173 register Lisp_Object val
;
1176 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
1177 while (!NILP (val
));
1185 return Feval (Vtop_level
);
1191 /* On entry to the outer level, run the startup file */
1192 if (!NILP (Vtop_level
))
1193 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
1194 else if (!NILP (Vpurify_flag
))
1195 message ("Bare impure Emacs (standard Lisp code not loaded)");
1197 message ("Bare Emacs (standard Lisp code not loaded)");
1201 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
1202 "Exit all recursive editing levels.")
1205 #ifdef HAVE_X_WINDOWS
1206 if (display_busy_cursor_p
)
1207 cancel_busy_cursor ();
1209 return Fthrow (Qtop_level
, Qnil
);
1212 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
1213 "Exit from the innermost recursive edit or minibuffer.")
1216 if (command_loop_level
> 0 || minibuf_level
> 0)
1217 Fthrow (Qexit
, Qnil
);
1219 error ("No recursive edit is in progress");
1223 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
1224 "Abort the command that requested this recursive edit or minibuffer input.")
1227 if (command_loop_level
> 0 || minibuf_level
> 0)
1230 error ("No recursive edit is in progress");
1234 /* This is the actual command reading loop,
1235 sans error-handling encapsulation. */
1237 Lisp_Object
Fcommand_execute ();
1238 static int read_key_sequence ();
1239 void safe_run_hooks ();
1240 static void adjust_point_for_property ();
1248 Lisp_Object keybuf
[30];
1252 struct buffer
*prev_buffer
= NULL
;
1254 int was_locked
= single_kboard
;
1257 current_kboard
->Vprefix_arg
= Qnil
;
1258 current_kboard
->Vlast_prefix_arg
= Qnil
;
1259 Vdeactivate_mark
= Qnil
;
1260 waiting_for_input
= 0;
1264 this_command_key_count
= 0;
1265 this_single_command_key_start
= 0;
1267 /* Make sure this hook runs after commands that get errors and
1268 throw to top level. */
1269 /* Note that the value cell will never directly contain nil
1270 if the symbol is a local variable. */
1271 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1272 safe_run_hooks (Qpost_command_hook
);
1274 /* If displaying a message, resize the echo area window to fit
1275 that message's size exactly. */
1276 if (!NILP (echo_area_buffer
[0]))
1277 resize_echo_area_axactly ();
1279 if (!NILP (Vdeferred_action_list
))
1280 call0 (Vdeferred_action_function
);
1282 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1284 if (NILP (Vunread_command_events
)
1285 && NILP (Vunread_input_method_events
)
1286 && NILP (Vunread_post_input_method_events
)
1287 && NILP (Vexecuting_macro
)
1288 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1, 1)))
1289 safe_run_hooks (Qpost_command_idle_hook
);
1292 /* Do this after running Vpost_command_hook, for consistency. */
1293 current_kboard
->Vlast_command
= Vthis_command
;
1294 current_kboard
->Vreal_last_command
= real_this_command
;
1298 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
1301 /* Make sure the current window's buffer is selected. */
1302 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1303 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1305 /* Display any malloc warning that just came out. Use while because
1306 displaying one warning can cause another. */
1308 while (pending_malloc_warning
)
1309 display_malloc_warning ();
1313 Vdeactivate_mark
= Qnil
;
1315 /* If minibuffer on and echo area in use,
1316 wait 2 sec and redraw minibuffer. */
1319 && !NILP (echo_area_buffer
[0])
1320 && EQ (minibuf_window
, echo_area_window
))
1322 /* Bind inhibit-quit to t so that C-g gets read in
1323 rather than quitting back to the minibuffer. */
1324 int count
= specpdl_ptr
- specpdl
;
1325 specbind (Qinhibit_quit
, Qt
);
1327 Fsit_for (make_number (2), Qnil
, Qnil
);
1328 /* Clear the echo area. */
1330 safe_run_hooks (Qecho_area_clear_hook
);
1332 unbind_to (count
, Qnil
);
1334 /* If a C-g came in before, treat it as input now. */
1335 if (!NILP (Vquit_flag
))
1338 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1343 alloca (0); /* Cause a garbage collection now */
1344 /* Since we can free the most stuff here. */
1345 #endif /* C_ALLOCA */
1348 /* Select the frame that the last event came from. Usually,
1349 switch-frame events will take care of this, but if some lisp
1350 code swallows a switch-frame event, we'll fix things up here.
1351 Is this a good idea? */
1352 if (FRAMEP (internal_last_event_frame
)
1353 && !EQ (internal_last_event_frame
, selected_frame
))
1354 Fselect_frame (internal_last_event_frame
, Qnil
);
1356 /* If it has changed current-menubar from previous value,
1357 really recompute the menubar from the value. */
1358 if (! NILP (Vlucid_menu_bar_dirty_flag
)
1359 && !NILP (Ffboundp (Qrecompute_lucid_menubar
)))
1360 call0 (Qrecompute_lucid_menubar
);
1362 before_command_key_count
= this_command_key_count
;
1363 before_command_echo_length
= echo_length ();
1365 Vthis_command
= Qnil
;
1366 real_this_command
= Qnil
;
1368 /* Read next key sequence; i gets its length. */
1369 i
= read_key_sequence (keybuf
, sizeof keybuf
/ sizeof keybuf
[0],
1372 /* A filter may have run while we were reading the input. */
1373 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
1375 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1376 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1380 /* Now we have read a key sequence of length I,
1381 or else I is 0 and we found end of file. */
1383 if (i
== 0) /* End of file -- happens only in */
1384 return Qnil
; /* a kbd macro, at the end. */
1385 /* -1 means read_key_sequence got a menu that was rejected.
1386 Just loop around and read another command. */
1390 this_command_key_count
= 0;
1391 this_single_command_key_start
= 0;
1395 last_command_char
= keybuf
[i
- 1];
1397 /* If the previous command tried to force a specific window-start,
1398 forget about that, in case this command moves point far away
1399 from that position. But also throw away beg_unchanged and
1400 end_unchanged information in that case, so that redisplay will
1401 update the whole window properly. */
1402 if (!NILP (XWINDOW (selected_window
)->force_start
))
1405 XWINDOW (selected_window
)->force_start
= Qnil
;
1406 b
= XBUFFER (XWINDOW (selected_window
)->buffer
);
1407 BUF_BEG_UNCHANGED (b
) = BUF_END_UNCHANGED (b
) = 0;
1410 cmd
= read_key_sequence_cmd
;
1411 if (!NILP (Vexecuting_macro
))
1413 if (!NILP (Vquit_flag
))
1415 Vexecuting_macro
= Qt
;
1416 QUIT
; /* Make some noise. */
1417 /* Will return since macro now empty. */
1421 /* Do redisplay processing after this command except in special
1422 cases identified below. */
1423 prev_buffer
= current_buffer
;
1424 prev_modiff
= MODIFF
;
1425 last_point_position
= PT
;
1426 XSETBUFFER (last_point_position_buffer
, prev_buffer
);
1428 /* By default, we adjust point to a boundary of a region that
1429 has such a property that should be treated intangible
1430 (e.g. composition, display). But, some commands will set
1431 this variable differently. */
1432 Vdisable_point_adjustment
= Qnil
;
1434 /* Execute the command. */
1436 Vthis_command
= cmd
;
1437 real_this_command
= cmd
;
1438 /* Note that the value cell will never directly contain nil
1439 if the symbol is a local variable. */
1440 if (!NILP (Vpre_command_hook
) && !NILP (Vrun_hooks
))
1441 safe_run_hooks (Qpre_command_hook
);
1443 if (NILP (Vthis_command
))
1445 /* nil means key is undefined. */
1447 current_kboard
->defining_kbd_macro
= Qnil
;
1448 update_mode_lines
= 1;
1449 current_kboard
->Vprefix_arg
= Qnil
;
1453 if (NILP (current_kboard
->Vprefix_arg
) && ! no_direct
)
1455 /* In case we jump to directly_done. */
1456 Vcurrent_prefix_arg
= current_kboard
->Vprefix_arg
;
1458 /* Recognize some common commands in common situations and
1459 do them directly. */
1460 if (EQ (Vthis_command
, Qforward_char
) && PT
< ZV
)
1462 struct Lisp_Char_Table
*dp
1463 = window_display_table (XWINDOW (selected_window
));
1464 lose
= FETCH_CHAR (PT_BYTE
);
1467 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1468 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1469 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1470 && (lose
>= 0x20 && lose
< 0x7f)))
1471 : (lose
>= 0x20 && lose
< 0x7f))
1472 /* To extract the case of continuation on
1473 wide-column characters. */
1474 && (WIDTH_BY_CHAR_HEAD (FETCH_BYTE (PT_BYTE
)) == 1)
1475 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1477 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1479 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1481 && !windows_or_buffers_changed
1482 && EQ (current_buffer
->selective_display
, Qnil
)
1483 && !detect_input_pending ()
1484 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1485 && NILP (Vexecuting_macro
))
1486 direct_output_forward_char (1);
1489 else if (EQ (Vthis_command
, Qbackward_char
) && PT
> BEGV
)
1491 struct Lisp_Char_Table
*dp
1492 = window_display_table (XWINDOW (selected_window
));
1494 lose
= FETCH_CHAR (PT_BYTE
);
1496 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1497 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1498 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1499 && (lose
>= 0x20 && lose
< 0x7f)))
1500 : (lose
>= 0x20 && lose
< 0x7f))
1501 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1503 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1505 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1507 && !windows_or_buffers_changed
1508 && EQ (current_buffer
->selective_display
, Qnil
)
1509 && !detect_input_pending ()
1510 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1511 && NILP (Vexecuting_macro
))
1512 direct_output_forward_char (-1);
1515 else if (EQ (Vthis_command
, Qself_insert_command
)
1516 /* Try this optimization only on ascii keystrokes. */
1517 && INTEGERP (last_command_char
))
1519 unsigned int c
= XINT (last_command_char
);
1521 if (NILP (Vexecuting_macro
)
1522 && !EQ (minibuf_window
, selected_window
))
1524 if (!nonundocount
|| nonundocount
>= 20)
1532 lose
= ((XFASTINT (XWINDOW (selected_window
)->last_modified
)
1534 || (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1536 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1538 || MODIFF
<= SAVE_MODIFF
1539 || windows_or_buffers_changed
1540 || !EQ (current_buffer
->selective_display
, Qnil
)
1541 || detect_input_pending ()
1542 || !NILP (XWINDOW (selected_window
)->column_number_displayed
)
1543 || !NILP (Vexecuting_macro
));
1545 value
= internal_self_insert (c
, 0);
1550 /* VALUE == 1 when AFTER-CHANGE functions are
1551 installed which is the case most of the time
1552 because FONT-LOCK installs one. */
1553 if (!lose
&& !value
)
1554 direct_output_for_insert (c
);
1559 /* Here for a command that isn't executed directly */
1561 #ifdef HAVE_X_WINDOWS
1562 if (display_busy_cursor_p
)
1563 start_busy_cursor ();
1567 if (NILP (current_kboard
->Vprefix_arg
))
1569 Fcommand_execute (Vthis_command
, Qnil
, Qnil
, Qnil
);
1571 #ifdef HAVE_X_WINDOWS
1572 if (display_busy_cursor_p
)
1573 cancel_busy_cursor ();
1577 current_kboard
->Vlast_prefix_arg
= Vcurrent_prefix_arg
;
1579 /* Note that the value cell will never directly contain nil
1580 if the symbol is a local variable. */
1581 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1582 safe_run_hooks (Qpost_command_hook
);
1584 /* If displaying a message, resize the echo area window to fit
1585 that message's size exactly. */
1586 if (!NILP (echo_area_buffer
[0]))
1587 resize_echo_area_axactly ();
1589 if (!NILP (Vdeferred_action_list
))
1590 safe_run_hooks (Qdeferred_action_function
);
1592 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1594 if (NILP (Vunread_command_events
)
1595 && NILP (Vunread_input_method_events
)
1596 && NILP (Vunread_post_input_method_events
)
1597 && NILP (Vexecuting_macro
)
1598 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1, 1)))
1599 safe_run_hooks (Qpost_command_idle_hook
);
1602 /* If there is a prefix argument,
1603 1) We don't want Vlast_command to be ``universal-argument''
1604 (that would be dumb), so don't set Vlast_command,
1605 2) we want to leave echoing on so that the prefix will be
1606 echoed as part of this key sequence, so don't call
1608 3) we want to leave this_command_key_count non-zero, so that
1609 read_char will realize that it is re-reading a character, and
1610 not echo it a second time.
1612 If the command didn't actually create a prefix arg,
1613 but is merely a frame event that is transparent to prefix args,
1614 then the above doesn't apply. */
1615 if (NILP (current_kboard
->Vprefix_arg
) || CONSP (last_command_char
))
1617 current_kboard
->Vlast_command
= Vthis_command
;
1618 current_kboard
->Vreal_last_command
= real_this_command
;
1620 this_command_key_count
= 0;
1621 this_single_command_key_start
= 0;
1624 if (!NILP (current_buffer
->mark_active
) && !NILP (Vrun_hooks
))
1626 if (!NILP (Vdeactivate_mark
) && !NILP (Vtransient_mark_mode
))
1628 current_buffer
->mark_active
= Qnil
;
1629 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
1631 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
1632 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
1637 if (current_buffer
== prev_buffer
1638 && last_point_position
!= PT
1639 && NILP (Vdisable_point_adjustment
)
1640 && NILP (Vglobal_disable_point_adjustment
))
1641 adjust_point_for_property (last_point_position
);
1643 /* Install chars successfully executed in kbd macro. */
1645 if (!NILP (current_kboard
->defining_kbd_macro
)
1646 && NILP (current_kboard
->Vprefix_arg
))
1647 finalize_kbd_macro_chars ();
1651 any_kboard_state ();
1656 extern Lisp_Object Qcomposition
, Qdisplay
;
1658 /* Adjust point to a boundary of a region that has such a property
1659 that should be treated intangible. For the moment, we check
1660 `composition' and `display' property. LAST_PT is the last position
1664 adjust_point_for_property (last_pt
)
1669 int check_composition
= 1, check_display
= 1;
1671 while (check_composition
|| check_display
)
1673 if (check_composition
1674 && PT
> BEGV
&& PT
< ZV
1675 && get_property_and_range (PT
, Qcomposition
, &val
, &start
, &end
, Qnil
)
1676 && COMPOSITION_VALID_P (start
, end
, val
)
1677 && start
< PT
&& end
> PT
1678 && (last_pt
<= start
|| last_pt
>= end
))
1686 check_composition
= 0;
1688 && PT
> BEGV
&& PT
< ZV
1689 && get_property_and_range (PT
, Qdisplay
, &val
, &start
, &end
, Qnil
)
1690 && display_prop_intangible_p (val
)
1691 && start
< PT
&& end
> PT
1692 && (last_pt
<= start
|| last_pt
>= end
))
1698 check_composition
= 1;
1704 /* Subroutine for safe_run_hooks: run the hook HOOK. */
1707 safe_run_hooks_1 (hook
)
1710 return call1 (Vrun_hooks
, Vinhibit_quit
);
1713 /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */
1716 safe_run_hooks_error (data
)
1719 return Fset (Vinhibit_quit
, Qnil
);
1722 /* If we get an error while running the hook, cause the hook variable
1723 to be nil. Also inhibit quits, so that C-g won't cause the hook
1724 to mysteriously evaporate. */
1727 safe_run_hooks (hook
)
1730 int count
= specpdl_ptr
- specpdl
;
1731 specbind (Qinhibit_quit
, hook
);
1733 internal_condition_case (safe_run_hooks_1
, Qt
, safe_run_hooks_error
);
1735 unbind_to (count
, Qnil
);
1739 /* Number of seconds between polling for input. This is a Lisp
1740 variable that can be bound. */
1744 /* Nonzero means polling for input is temporarily suppressed. */
1746 int poll_suppress_count
;
1748 /* Asynchronous timer for polling. */
1750 struct atimer
*poll_timer
;
1753 #ifdef POLL_FOR_INPUT
1755 /* Poll for input, so what we catch a C-g if it comes in. This
1756 function is called from x_make_frame_visible, see comment
1762 if (interrupt_input_blocked
== 0
1763 && !waiting_for_input
)
1764 read_avail_input (0);
1767 /* Timer callback function for poll_timer. TIMER is equal to
1771 poll_for_input (timer
)
1772 struct atimer
*timer
;
1774 if (poll_suppress_count
== 0)
1775 poll_for_input_1 ();
1778 #endif /* POLL_FOR_INPUT */
1780 /* Begin signals to poll for input, if they are appropriate.
1781 This function is called unconditionally from various places. */
1786 #ifdef POLL_FOR_INPUT
1787 if (read_socket_hook
&& !interrupt_input
)
1789 /* Turn alarm handling on unconditionally. It might have
1790 been turned off in process.c. */
1791 turn_on_atimers (1);
1793 /* If poll timer doesn't exist, are we need one with
1794 a different interval, start a new one. */
1795 if (poll_timer
== NULL
1796 || EMACS_SECS (poll_timer
->interval
) != polling_period
)
1798 EMACS_TIME interval
;
1801 cancel_atimer (poll_timer
);
1803 EMACS_SET_SECS_USECS (interval
, polling_period
, 0);
1804 poll_timer
= start_atimer (ATIMER_CONTINUOUS
, interval
,
1805 poll_for_input
, NULL
);
1808 /* Let the timer's callback function poll for input
1809 if this becomes zero. */
1810 --poll_suppress_count
;
1815 /* Nonzero if we are using polling to handle input asynchronously. */
1818 input_polling_used ()
1820 #ifdef POLL_FOR_INPUT
1821 return read_socket_hook
&& !interrupt_input
;
1827 /* Turn off polling. */
1832 #ifdef POLL_FOR_INPUT
1833 if (read_socket_hook
&& !interrupt_input
)
1834 ++poll_suppress_count
;
1838 /* Set the value of poll_suppress_count to COUNT
1839 and start or stop polling accordingly. */
1842 set_poll_suppress_count (count
)
1845 #ifdef POLL_FOR_INPUT
1846 if (count
== 0 && poll_suppress_count
!= 0)
1848 poll_suppress_count
= 1;
1851 else if (count
!= 0 && poll_suppress_count
== 0)
1855 poll_suppress_count
= count
;
1859 /* Bind polling_period to a value at least N.
1860 But don't decrease it. */
1863 bind_polling_period (n
)
1866 #ifdef POLL_FOR_INPUT
1867 int new = polling_period
;
1872 stop_other_atimers (poll_timer
);
1874 specbind (Qpolling_period
, make_number (new));
1875 /* Start a new alarm with the new period. */
1880 /* Apply the control modifier to CHARACTER. */
1886 /* Save the upper bits here. */
1887 int upper
= c
& ~0177;
1891 /* Everything in the columns containing the upper-case letters
1892 denotes a control character. */
1893 if (c
>= 0100 && c
< 0140)
1897 /* Set the shift modifier for a control char
1898 made from a shifted letter. But only for letters! */
1899 if (oc
>= 'A' && oc
<= 'Z')
1900 c
|= shift_modifier
;
1903 /* The lower-case letters denote control characters too. */
1904 else if (c
>= 'a' && c
<= 'z')
1907 /* Include the bits for control and shift
1908 only if the basic ASCII code can't indicate them. */
1912 /* Replace the high bits. */
1913 c
|= (upper
& ~ctrl_modifier
);
1918 /* Display help echo in the echo area.
1920 HELP a string means display that string, HELP nil means clear the
1921 help echo. If HELP is a function, call it with OBJECT and POS as
1922 arguments; the function should return a help string or nil for
1923 none. For all other types of HELP evaluate it to obtain a string.
1925 WINDOW is the window in which the help was generated, if any.
1926 It is nil if not in a window.
1928 If OBJECT is a buffer, POS is the position in the buffer where the
1929 `help-echo' text property was found.
1931 If OBJECT is an overlay, that overlay has a `help-echo' property,
1932 and POS is the position in the overlay's buffer under the mouse.
1934 If OBJECT is a string (an overlay string or a string displayed with
1935 the `display' property). POS is the position in that string under
1938 OK_TO_IVERWRITE_KEYSTROKE_ECHO non-zero means it's okay if the help
1939 echo overwrites a keystroke echo currently displayed in the echo
1942 Note: this function may only be called with HELP nil or a string
1943 from X code running asynchronously. */
1946 show_help_echo (help
, window
, object
, pos
, ok_to_overwrite_keystroke_echo
)
1947 Lisp_Object help
, window
, object
, pos
;
1948 int ok_to_overwrite_keystroke_echo
;
1950 if (!NILP (help
) && !STRINGP (help
))
1952 if (FUNCTIONP (help
))
1954 Lisp_Object args
[4];
1959 help
= call_function (4, args
);
1962 help
= eval_form (help
);
1964 if (!STRINGP (help
))
1968 if (STRINGP (help
) || NILP (help
))
1970 if (!NILP (Vshow_help_function
))
1971 call1 (Vshow_help_function
, help
);
1972 else if (/* Don't overwrite minibuffer contents. */
1973 !MINI_WINDOW_P (XWINDOW (selected_window
))
1974 /* Don't overwrite a keystroke echo. */
1975 && (NILP (echo_message_buffer
)
1976 || ok_to_overwrite_keystroke_echo
)
1977 /* Don't overwrite a prompt. */
1978 && !cursor_in_echo_area
)
1982 int count
= specpdl_ptr
- specpdl
;
1983 specbind (Qmessage_truncate_lines
, Qt
);
1984 message3_nolog (help
, XSTRING (help
)->size
,
1985 STRING_MULTIBYTE (help
));
1986 unbind_to (count
, Qnil
);
1992 help_echo_showing_p
= STRINGP (help
);
1998 /* Input of single characters from keyboard */
2000 Lisp_Object
print_help ();
2001 static Lisp_Object
kbd_buffer_get_event ();
2002 static void record_char ();
2005 static jmp_buf wrong_kboard_jmpbuf
;
2008 /* read a character from the keyboard; call the redisplay if needed */
2009 /* commandflag 0 means do not do auto-saving, but do do redisplay.
2010 -1 means do not do redisplay, but do do autosaving.
2013 /* The arguments MAPS and NMAPS are for menu prompting.
2014 MAPS is an array of keymaps; NMAPS is the length of MAPS.
2016 PREV_EVENT is the previous input event, or nil if we are reading
2017 the first event of a key sequence (or not reading a key sequence).
2018 If PREV_EVENT is t, that is a "magic" value that says
2019 not to run input methods, but in other respects to act as if
2020 not reading a key sequence.
2022 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
2023 if we used a mouse menu to read the input, or zero otherwise. If
2024 USED_MOUSE_MENU is null, we don't dereference it.
2026 Value is t if we showed a menu and the user rejected it. */
2029 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
)
2033 Lisp_Object prev_event
;
2034 int *used_mouse_menu
;
2036 volatile Lisp_Object c
;
2038 jmp_buf local_getcjmp
;
2040 volatile int key_already_recorded
= 0;
2041 Lisp_Object tem
, save
;
2042 volatile Lisp_Object previous_echo_area_message
;
2043 volatile Lisp_Object also_record
;
2044 volatile int reread
;
2045 struct gcpro gcpro1
, gcpro2
;
2049 before_command_key_count
= this_command_key_count
;
2050 before_command_echo_length
= echo_length ();
2052 previous_echo_area_message
= Qnil
;
2054 GCPRO2 (c
, previous_echo_area_message
);
2059 if (CONSP (Vunread_post_input_method_events
))
2061 c
= XCAR (Vunread_post_input_method_events
);
2062 Vunread_post_input_method_events
2063 = XCDR (Vunread_post_input_method_events
);
2065 /* Undo what read_char_x_menu_prompt did when it unread
2066 additional keys returned by Fx_popup_menu. */
2068 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
)))
2076 if (unread_command_char
!= -1)
2078 XSETINT (c
, unread_command_char
);
2079 unread_command_char
= -1;
2085 if (CONSP (Vunread_command_events
))
2087 c
= XCAR (Vunread_command_events
);
2088 Vunread_command_events
= XCDR (Vunread_command_events
);
2090 /* Undo what read_char_x_menu_prompt did when it unread
2091 additional keys returned by Fx_popup_menu. */
2093 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
)))
2098 goto reread_for_input_method
;
2101 if (CONSP (Vunread_input_method_events
))
2103 c
= XCAR (Vunread_input_method_events
);
2104 Vunread_input_method_events
= XCDR (Vunread_input_method_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
)))
2113 goto reread_for_input_method
;
2116 /* If there is no function key translated before
2117 reset-this-command-lengths takes effect, forget about it. */
2118 before_command_restore_flag
= 0;
2120 if (!NILP (Vexecuting_macro
))
2122 /* We set this to Qmacro; since that's not a frame, nobody will
2123 try to switch frames on us, and the selected window will
2126 Since this event came from a macro, it would be misleading to
2127 leave internal_last_event_frame set to wherever the last
2128 real event came from. Normally, a switch-frame event selects
2129 internal_last_event_frame after each command is read, but
2130 events read from a macro should never cause a new frame to be
2132 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
2134 /* Exit the macro if we are at the end.
2135 Also, some things replace the macro with t
2136 to force an early exit. */
2137 if (EQ (Vexecuting_macro
, Qt
)
2138 || executing_macro_index
>= XFASTINT (Flength (Vexecuting_macro
)))
2144 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
2145 if (STRINGP (Vexecuting_macro
)
2146 && (XINT (c
) & 0x80))
2147 XSETFASTINT (c
, CHAR_META
| (XINT (c
) & ~0x80));
2149 executing_macro_index
++;
2154 if (!NILP (unread_switch_frame
))
2156 c
= unread_switch_frame
;
2157 unread_switch_frame
= Qnil
;
2159 /* This event should make it into this_command_keys, and get echoed
2160 again, so we do not set `reread'. */
2164 /* if redisplay was requested */
2165 if (commandflag
>= 0)
2167 /* If there is pending input, process any events which are not
2168 user-visible, such as X selection_request events. */
2170 || detect_input_pending_run_timers (0))
2171 swallow_events (0); /* may clear input_pending */
2173 /* Redisplay if no pending input. */
2174 while (!input_pending
)
2176 if (help_echo_showing_p
&& !EQ (selected_window
, minibuf_window
))
2177 redisplay_preserve_echo_area ();
2182 /* Normal case: no input arrived during redisplay. */
2185 /* Input arrived and pre-empted redisplay.
2186 Process any events which are not user-visible. */
2188 /* If that cleared input_pending, try again to redisplay. */
2192 /* Message turns off echoing unless more keystrokes turn it on again.
2194 The code in 20.x for the condition was
2196 1. echo_area_glyphs && *echo_area_glyphs
2197 2. && echo_area_glyphs != current_kboard->echobuf
2198 3. && ok_to_echo_at_next_pause != echo_area_glyphs
2200 (1) means there's a current message displayed
2202 (2) means it's not the message from echoing from the current
2205 (3) There's only one place in 20.x where ok_to_echo_at_next_pause
2206 is set to a non-null value. This is done in read_char and it is
2207 set to echo_area_glyphs after a call to echo_char. That means
2208 ok_to_echo_at_next_pause is either null or
2209 current_kboard->echobuf with the appropriate current_kboard at
2212 So, condition (3) means in clear text ok_to_echo_at_next_pause
2213 must be either null, or the current message isn't from echoing at
2214 all, or it's from echoing from a different kboard than the
2217 if (/* There currently something in the echo area */
2218 !NILP (echo_area_buffer
[0])
2219 && (/* And it's either not from echoing. */
2220 !EQ (echo_area_buffer
[0], echo_message_buffer
)
2221 /* Or it's an echo from a different kboard. */
2222 || echo_kboard
!= current_kboard
2223 /* Or we explicitly allow overwriting whatever there is. */
2224 || ok_to_echo_at_next_pause
== NULL
))
2229 /* Try reading a character via menu prompting in the minibuf.
2230 Try this before the sit-for, because the sit-for
2231 would do the wrong thing if we are supposed to do
2232 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
2233 after a mouse event so don't try a minibuf menu. */
2235 if (nmaps
> 0 && INTERACTIVE
2236 && !NILP (prev_event
) && ! EVENT_HAS_PARAMETERS (prev_event
)
2237 /* Don't bring up a menu if we already have another event. */
2238 && NILP (Vunread_command_events
)
2239 && unread_command_char
< 0
2240 && !detect_input_pending_run_timers (0))
2242 c
= read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
);
2245 key_already_recorded
= 1;
2250 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet.
2251 We will do that below, temporarily for short sections of code,
2252 when appropriate. local_getcjmp must be in effect
2253 around any call to sit_for or kbd_buffer_get_event;
2254 it *must not* be in effect when we call redisplay. */
2256 if (_setjmp (local_getcjmp
))
2258 XSETINT (c
, quit_char
);
2259 internal_last_event_frame
= selected_frame
;
2260 Vlast_event_frame
= internal_last_event_frame
;
2261 /* If we report the quit char as an event,
2262 don't do so more than once. */
2263 if (!NILP (Vinhibit_quit
))
2268 KBOARD
*kb
= FRAME_KBOARD (XFRAME (selected_frame
));
2269 if (kb
!= current_kboard
)
2271 Lisp_Object
*tailp
= &kb
->kbd_queue
;
2272 /* We shouldn't get here if we were in single-kboard mode! */
2275 while (CONSP (*tailp
))
2276 tailp
= &XCDR (*tailp
);
2279 *tailp
= Fcons (c
, Qnil
);
2280 kb
->kbd_queue_has_data
= 1;
2281 current_kboard
= kb
;
2282 /* This is going to exit from read_char
2283 so we had better get rid of this frame's stuff. */
2285 longjmp (wrong_kboard_jmpbuf
, 1);
2292 timer_start_idle ();
2294 /* If in middle of key sequence and minibuffer not active,
2295 start echoing if enough time elapses. */
2297 if (minibuf_level
== 0
2298 && !current_kboard
->immediate_echo
2299 && this_command_key_count
> 0
2301 && (FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
2302 && NILP (Fzerop (Vecho_keystrokes
))
2303 && (/* No message. */
2304 NILP (echo_area_buffer
[0])
2305 /* Or empty message. */
2306 || (BUF_BEG (XBUFFER (echo_area_buffer
[0]))
2307 == BUF_Z (XBUFFER (echo_area_buffer
[0])))
2308 /* Or already echoing from same kboard. */
2309 || (echo_kboard
&& ok_to_echo_at_next_pause
== echo_kboard
)
2310 /* Or not echoing before and echoing allowed. */
2311 || (!echo_kboard
&& ok_to_echo_at_next_pause
)))
2315 /* After a mouse event, start echoing right away.
2316 This is because we are probably about to display a menu,
2317 and we don't want to delay before doing so. */
2318 if (EVENT_HAS_PARAMETERS (prev_event
))
2323 double duration
= extract_float (Vecho_keystrokes
);
2324 sec
= (int) duration
;
2325 usec
= (duration
- sec
) * 1000000;
2326 save_getcjmp (save_jump
);
2327 restore_getcjmp (local_getcjmp
);
2328 tem0
= sit_for (sec
, usec
, 1, 1, 0);
2329 restore_getcjmp (save_jump
);
2331 && ! CONSP (Vunread_command_events
))
2336 /* Maybe auto save due to number of keystrokes. */
2338 if (commandflag
!= 0
2339 && auto_save_interval
> 0
2340 && num_nonmacro_input_events
- last_auto_save
> max (auto_save_interval
, 20)
2341 && !detect_input_pending_run_timers (0))
2343 Fdo_auto_save (Qnil
, Qnil
);
2344 /* Hooks can actually change some buffers in auto save. */
2348 /* Try reading using an X menu.
2349 This is never confused with reading using the minibuf
2350 because the recursive call of read_char in read_char_minibuf_menu_prompt
2351 does not pass on any keymaps. */
2353 if (nmaps
> 0 && INTERACTIVE
2354 && !NILP (prev_event
)
2355 && EVENT_HAS_PARAMETERS (prev_event
)
2356 && !EQ (XCAR (prev_event
), Qmenu_bar
)
2357 && !EQ (XCAR (prev_event
), Qtool_bar
)
2358 /* Don't bring up a menu if we already have another event. */
2359 && NILP (Vunread_command_events
)
2360 && unread_command_char
< 0)
2362 c
= read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
2364 /* Now that we have read an event, Emacs is not idle. */
2370 /* Maybe autosave and/or garbage collect due to idleness. */
2372 if (INTERACTIVE
&& NILP (c
))
2374 int delay_level
, buffer_size
;
2376 /* Slow down auto saves logarithmically in size of current buffer,
2377 and garbage collect while we're at it. */
2378 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
2379 last_non_minibuf_size
= Z
- BEG
;
2380 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
2382 while (buffer_size
> 64)
2383 delay_level
++, buffer_size
-= buffer_size
>> 2;
2384 if (delay_level
< 4) delay_level
= 4;
2385 /* delay_level is 4 for files under around 50k, 7 at 100k,
2386 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
2388 /* Auto save if enough time goes by without input. */
2389 if (commandflag
!= 0
2390 && num_nonmacro_input_events
> last_auto_save
2391 && INTEGERP (Vauto_save_timeout
)
2392 && XINT (Vauto_save_timeout
) > 0)
2396 save_getcjmp (save_jump
);
2397 restore_getcjmp (local_getcjmp
);
2398 tem0
= sit_for (delay_level
* XFASTINT (Vauto_save_timeout
) / 4,
2400 restore_getcjmp (save_jump
);
2403 && ! CONSP (Vunread_command_events
))
2405 Fdo_auto_save (Qnil
, Qnil
);
2407 /* If we have auto-saved and there is still no input
2408 available, garbage collect if there has been enough
2409 consing going on to make it worthwhile. */
2410 if (!detect_input_pending_run_timers (0)
2411 && consing_since_gc
> gc_cons_threshold
/ 2)
2412 Fgarbage_collect ();
2419 /* If this has become non-nil here, it has been set by a timer
2420 or sentinel or filter. */
2421 if (CONSP (Vunread_command_events
))
2423 c
= XCAR (Vunread_command_events
);
2424 Vunread_command_events
= XCDR (Vunread_command_events
);
2427 /* Read something from current KBOARD's side queue, if possible. */
2431 if (current_kboard
->kbd_queue_has_data
)
2433 if (!CONSP (current_kboard
->kbd_queue
))
2435 c
= XCAR (current_kboard
->kbd_queue
);
2436 current_kboard
->kbd_queue
2437 = XCDR (current_kboard
->kbd_queue
);
2438 if (NILP (current_kboard
->kbd_queue
))
2439 current_kboard
->kbd_queue_has_data
= 0;
2440 input_pending
= readable_events (0);
2441 if (EVENT_HAS_PARAMETERS (c
)
2442 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qswitch_frame
))
2443 internal_last_event_frame
= XCAR (XCDR (c
));
2444 Vlast_event_frame
= internal_last_event_frame
;
2449 /* If current_kboard's side queue is empty check the other kboards.
2450 If one of them has data that we have not yet seen here,
2451 switch to it and process the data waiting for it.
2453 Note: if the events queued up for another kboard
2454 have already been seen here, and therefore are not a complete command,
2455 the kbd_queue_has_data field is 0, so we skip that kboard here.
2456 That's to avoid an infinite loop switching between kboards here. */
2457 if (NILP (c
) && !single_kboard
)
2460 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2461 if (kb
->kbd_queue_has_data
)
2463 current_kboard
= kb
;
2464 /* This is going to exit from read_char
2465 so we had better get rid of this frame's stuff. */
2467 longjmp (wrong_kboard_jmpbuf
, 1);
2476 /* Finally, we read from the main queue,
2477 and if that gives us something we can't use yet, we put it on the
2478 appropriate side queue and try again. */
2484 /* Actually read a character, waiting if necessary. */
2485 save_getcjmp (save_jump
);
2486 restore_getcjmp (local_getcjmp
);
2487 c
= kbd_buffer_get_event (&kb
, used_mouse_menu
);
2488 restore_getcjmp (save_jump
);
2491 if (! NILP (c
) && (kb
!= current_kboard
))
2493 Lisp_Object
*tailp
= &kb
->kbd_queue
;
2494 while (CONSP (*tailp
))
2495 tailp
= &XCDR (*tailp
);
2498 *tailp
= Fcons (c
, Qnil
);
2499 kb
->kbd_queue_has_data
= 1;
2503 current_kboard
= kb
;
2504 /* This is going to exit from read_char
2505 so we had better get rid of this frame's stuff. */
2507 longjmp (wrong_kboard_jmpbuf
, 1);
2512 /* Terminate Emacs in batch mode if at eof. */
2513 if (noninteractive
&& INTEGERP (c
) && XINT (c
) < 0)
2514 Fkill_emacs (make_number (1));
2518 /* Add in any extra modifiers, where appropriate. */
2519 if ((extra_keyboard_modifiers
& CHAR_CTL
)
2520 || ((extra_keyboard_modifiers
& 0177) < ' '
2521 && (extra_keyboard_modifiers
& 0177) != 0))
2522 XSETINT (c
, make_ctrl_char (XINT (c
)));
2524 /* Transfer any other modifier bits directly from
2525 extra_keyboard_modifiers to c. Ignore the actual character code
2526 in the low 16 bits of extra_keyboard_modifiers. */
2527 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
2538 if (commandflag
>= 0
2539 && !input_pending
&& !detect_input_pending_run_timers (0))
2547 /* Buffer switch events are only for internal wakeups
2548 so don't show them to the user.
2549 Also, don't record a key if we already did. */
2550 if (BUFFERP (c
) || key_already_recorded
)
2553 /* Process special events within read_char
2554 and loop around to read another event. */
2557 tem
= get_keyelt (access_keymap (get_keymap_1 (Vspecial_event_map
, 0, 0),
2563 int was_locked
= single_kboard
;
2565 last_input_char
= c
;
2566 Fcommand_execute (tem
, Qnil
, Fvector (1, &last_input_char
), Qt
);
2568 /* Resume allowing input from any kboard, if that was true before. */
2570 any_kboard_state ();
2575 /* Handle things that only apply to characters. */
2578 /* If kbd_buffer_get_event gave us an EOF, return that. */
2582 if ((STRINGP (Vkeyboard_translate_table
)
2583 && XSTRING (Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
2584 || (VECTORP (Vkeyboard_translate_table
)
2585 && XVECTOR (Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
2586 || (CHAR_TABLE_P (Vkeyboard_translate_table
)
2587 && CHAR_TABLE_ORDINARY_SLOTS
> (unsigned) XFASTINT (c
)))
2590 d
= Faref (Vkeyboard_translate_table
, c
);
2591 /* nil in keyboard-translate-table means no translation. */
2597 /* If this event is a mouse click in the menu bar,
2598 return just menu-bar for now. Modify the mouse click event
2599 so we won't do this twice, then queue it up. */
2600 if (EVENT_HAS_PARAMETERS (c
)
2602 && CONSP (EVENT_START (c
))
2603 && CONSP (XCDR (EVENT_START (c
))))
2607 posn
= POSN_BUFFER_POSN (EVENT_START (c
));
2608 /* Handle menu-bar events:
2609 insert the dummy prefix event `menu-bar'. */
2610 if (EQ (posn
, Qmenu_bar
) || EQ (posn
, Qtool_bar
))
2612 /* Change menu-bar to (menu-bar) as the event "position". */
2613 POSN_BUFFER_POSN (EVENT_START (c
)) = Fcons (posn
, Qnil
);
2616 Vunread_command_events
= Fcons (c
, Vunread_command_events
);
2621 /* Store these characters into recent_keys, the dribble file if any,
2622 and the keyboard macro being defined, if any. */
2624 if (! NILP (also_record
))
2625 record_char (also_record
);
2627 /* Wipe the echo area.
2628 But first, if we are about to use an input method,
2629 save the echo area contents for it to refer to. */
2631 && ! NILP (Vinput_method_function
)
2632 && (unsigned) XINT (c
) >= ' '
2633 && (unsigned) XINT (c
) != 127
2634 && (unsigned) XINT (c
) < 256)
2636 previous_echo_area_message
= Fcurrent_message ();
2637 Vinput_method_previous_message
= previous_echo_area_message
;
2640 /* Now wipe the echo area, except for help events which do their
2641 own stuff with the echo area. */
2642 if (!CONSP (c
) || !(EQ (Qhelp_echo
, XCAR (c
))))
2644 if (!NILP (echo_area_buffer
[0]))
2645 safe_run_hooks (Qecho_area_clear_hook
);
2646 clear_message (1, 0);
2649 reread_for_input_method
:
2651 /* Pass this to the input method, if appropriate. */
2653 && ! NILP (Vinput_method_function
)
2654 /* Don't run the input method within a key sequence,
2655 after the first event of the key sequence. */
2656 && NILP (prev_event
)
2657 && (unsigned) XINT (c
) >= ' '
2658 && (unsigned) XINT (c
) != 127
2659 && (unsigned) XINT (c
) < 256)
2663 struct gcpro gcpro1
;
2664 int count
= specpdl_ptr
- specpdl
;
2666 /* Save the echo status. */
2667 int saved_immediate_echo
= current_kboard
->immediate_echo
;
2668 struct kboard
*saved_ok_to_echo
= ok_to_echo_at_next_pause
;
2669 int saved_echo_after_prompt
= current_kboard
->echo_after_prompt
;
2671 if (before_command_restore_flag
)
2673 this_command_key_count
= before_command_key_count_1
;
2674 if (this_command_key_count
< this_single_command_key_start
)
2675 this_single_command_key_start
= this_command_key_count
;
2676 echo_truncate (before_command_echo_length_1
);
2677 before_command_restore_flag
= 0;
2680 /* Save the this_command_keys status. */
2681 key_count
= this_command_key_count
;
2684 keys
= Fcopy_sequence (this_command_keys
);
2689 /* Clear out this_command_keys. */
2690 this_command_key_count
= 0;
2692 /* Now wipe the echo area. */
2693 if (!NILP (echo_area_buffer
[0]))
2694 safe_run_hooks (Qecho_area_clear_hook
);
2695 clear_message (1, 0);
2698 /* If we are not reading a key sequence,
2699 never use the echo area. */
2702 specbind (Qinput_method_use_echo_area
, Qt
);
2705 /* Call the input method. */
2706 tem
= call1 (Vinput_method_function
, c
);
2708 tem
= unbind_to (count
, tem
);
2710 /* Restore the saved echoing state
2711 and this_command_keys state. */
2712 this_command_key_count
= key_count
;
2714 this_command_keys
= keys
;
2717 ok_to_echo_at_next_pause
= saved_ok_to_echo
;
2718 current_kboard
->echo_after_prompt
= saved_echo_after_prompt
;
2719 if (saved_immediate_echo
)
2724 /* The input method can return no events. */
2727 /* Bring back the previous message, if any. */
2728 if (! NILP (previous_echo_area_message
))
2729 message_with_string ("%s", previous_echo_area_message
, 0);
2732 /* It returned one event or more. */
2734 Vunread_post_input_method_events
2735 = nconc2 (XCDR (tem
), Vunread_post_input_method_events
);
2740 /* Display help if not echoing. */
2741 if (CONSP (c
) && EQ (XCAR (c
), Qhelp_echo
))
2743 /* (help-echo FRAME HELP WINDOW OBJECT POS). */
2744 Lisp_Object help
, object
, position
, window
;
2745 help
= Fnth (make_number (2), c
);
2746 window
= Fnth (make_number (3), c
);
2747 object
= Fnth (make_number (4), c
);
2748 position
= Fnth (make_number (5), c
);
2749 show_help_echo (help
, window
, object
, position
, 0);
2753 if (this_command_key_count
== 0 || ! reread
)
2755 before_command_key_count
= this_command_key_count
;
2756 before_command_echo_length
= echo_length ();
2758 /* Don't echo mouse motion events. */
2759 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
2760 && NILP (Fzerop (Vecho_keystrokes
))
2761 && ! (EVENT_HAS_PARAMETERS (c
)
2762 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
2765 if (! NILP (also_record
))
2766 echo_char (also_record
);
2767 /* Once we reread a character, echoing can happen
2768 the next time we pause to read a new one. */
2769 ok_to_echo_at_next_pause
= current_kboard
;
2772 /* Record this character as part of the current key. */
2773 add_command_key (c
);
2774 if (! NILP (also_record
))
2775 add_command_key (also_record
);
2778 last_input_char
= c
;
2781 /* Process the help character specially if enabled */
2782 if (!NILP (Vhelp_form
) && help_char_p (c
))
2785 count
= specpdl_ptr
- specpdl
;
2787 record_unwind_protect (Fset_window_configuration
,
2788 Fcurrent_window_configuration (Qnil
));
2790 tem0
= Feval (Vhelp_form
);
2792 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
2796 c
= read_char (0, 0, 0, Qnil
, 0);
2797 while (BUFFERP (c
));
2798 /* Remove the help from the frame */
2799 unbind_to (count
, Qnil
);
2802 if (EQ (c
, make_number (040)))
2806 c
= read_char (0, 0, 0, Qnil
, 0);
2807 while (BUFFERP (c
));
2814 /* Record a key that came from a mouse menu.
2815 Record it for echoing, for this-command-keys, and so on. */
2821 /* Wipe the echo area. */
2822 clear_message (1, 0);
2826 before_command_key_count
= this_command_key_count
;
2827 before_command_echo_length
= echo_length ();
2829 /* Don't echo mouse motion events. */
2830 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
2831 && NILP (Fzerop (Vecho_keystrokes
)))
2835 /* Once we reread a character, echoing can happen
2836 the next time we pause to read a new one. */
2837 ok_to_echo_at_next_pause
= 0;
2840 /* Record this character as part of the current key. */
2841 add_command_key (c
);
2843 /* Re-reading in the middle of a command */
2844 last_input_char
= c
;
2848 /* Return 1 if should recognize C as "the help character". */
2856 if (EQ (c
, Vhelp_char
))
2858 for (tail
= Vhelp_event_list
; CONSP (tail
); tail
= XCDR (tail
))
2859 if (EQ (c
, XCAR (tail
)))
2864 /* Record the input event C in various ways. */
2871 XVECTOR (recent_keys
)->contents
[recent_keys_index
] = c
;
2872 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
2873 recent_keys_index
= 0;
2875 /* Write c to the dribble file. If c is a lispy event, write
2876 the event's symbol to the dribble file, in <brackets>. Bleaugh.
2877 If you, dear reader, have a better idea, you've got the source. :-) */
2882 if (XUINT (c
) < 0x100)
2883 putc (XINT (c
), dribble
);
2885 fprintf (dribble
, " 0x%x", (int) XUINT (c
));
2889 Lisp_Object dribblee
;
2891 /* If it's a structured event, take the event header. */
2892 dribblee
= EVENT_HEAD (c
);
2894 if (SYMBOLP (dribblee
))
2896 putc ('<', dribble
);
2897 fwrite (XSYMBOL (dribblee
)->name
->data
, sizeof (char),
2898 STRING_BYTES (XSYMBOL (dribblee
)->name
),
2900 putc ('>', dribble
);
2907 store_kbd_macro_char (c
);
2909 num_nonmacro_input_events
++;
2916 struct buffer
*old
= current_buffer
;
2917 Fprinc (object
, Qnil
);
2918 set_buffer_internal (XBUFFER (Vstandard_output
));
2919 call0 (intern ("help-mode"));
2920 set_buffer_internal (old
);
2924 /* Copy out or in the info on where C-g should throw to.
2925 This is used when running Lisp code from within get_char,
2926 in case get_char is called recursively.
2927 See read_process_output. */
2933 bcopy (getcjmp
, temp
, sizeof getcjmp
);
2937 restore_getcjmp (temp
)
2940 bcopy (temp
, getcjmp
, sizeof getcjmp
);
2945 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
2946 of this function. */
2949 tracking_off (old_value
)
2950 Lisp_Object old_value
;
2952 do_mouse_tracking
= old_value
;
2953 if (NILP (old_value
))
2955 /* Redisplay may have been preempted because there was input
2956 available, and it assumes it will be called again after the
2957 input has been processed. If the only input available was
2958 the sort that we have just disabled, then we need to call
2960 if (!readable_events (1))
2962 redisplay_preserve_echo_area ();
2963 get_input_pending (&input_pending
, 1);
2969 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
2970 "Evaluate BODY with mouse movement events enabled.\n\
2971 Within a `track-mouse' form, mouse motion generates input events that\n\
2972 you can read with `read-event'.\n\
2973 Normally, mouse motion is ignored.")
2977 int count
= specpdl_ptr
- specpdl
;
2980 record_unwind_protect (tracking_off
, do_mouse_tracking
);
2982 do_mouse_tracking
= Qt
;
2984 val
= Fprogn (args
);
2985 return unbind_to (count
, val
);
2988 /* If mouse has moved on some frame, return one of those frames.
2989 Return 0 otherwise. */
2994 Lisp_Object tail
, frame
;
2996 FOR_EACH_FRAME (tail
, frame
)
2998 if (XFRAME (frame
)->mouse_moved
)
2999 return XFRAME (frame
);
3005 #endif /* HAVE_MOUSE */
3007 /* Low level keyboard/mouse input.
3008 kbd_buffer_store_event places events in kbd_buffer, and
3009 kbd_buffer_get_event retrieves them. */
3011 /* Return true iff there are any events in the queue that read-char
3012 would return. If this returns false, a read-char would block. */
3014 readable_events (do_timers_now
)
3018 timer_check (do_timers_now
);
3020 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3023 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
3028 if (current_kboard
->kbd_queue_has_data
)
3034 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
3035 if (kb
->kbd_queue_has_data
)
3041 /* Set this for debugging, to have a way to get out */
3046 event_to_kboard (event
)
3047 struct input_event
*event
;
3050 frame
= event
->frame_or_window
;
3052 frame
= XCAR (frame
);
3053 else if (WINDOWP (frame
))
3054 frame
= WINDOW_FRAME (XWINDOW (frame
));
3056 /* There are still some events that don't set this field.
3057 For now, just ignore the problem.
3058 Also ignore dead frames here. */
3059 if (!FRAMEP (frame
) || !FRAME_LIVE_P (XFRAME (frame
)))
3062 return FRAME_KBOARD (XFRAME (frame
));
3066 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
3069 kbd_buffer_store_event (event
)
3070 register struct input_event
*event
;
3072 if (event
->kind
== no_event
)
3075 if (event
->kind
== ascii_keystroke
)
3077 register int c
= event
->code
& 0377;
3079 if (event
->modifiers
& ctrl_modifier
)
3080 c
= make_ctrl_char (c
);
3082 c
|= (event
->modifiers
3083 & (meta_modifier
| alt_modifier
3084 | hyper_modifier
| super_modifier
));
3088 extern SIGTYPE
interrupt_signal ();
3091 struct input_event
*sp
;
3094 && (kb
= FRAME_KBOARD (XFRAME (event
->frame_or_window
)),
3095 kb
!= current_kboard
))
3098 = Fcons (make_lispy_switch_frame (event
->frame_or_window
),
3099 Fcons (make_number (c
), Qnil
));
3100 kb
->kbd_queue_has_data
= 1;
3101 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
3103 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3106 if (event_to_kboard (sp
) == kb
)
3108 sp
->kind
= no_event
;
3109 sp
->frame_or_window
= Qnil
;
3117 /* If this results in a quit_char being returned to Emacs as
3118 input, set Vlast_event_frame properly. If this doesn't
3119 get returned to Emacs as an event, the next event read
3120 will set Vlast_event_frame again, so this is safe to do. */
3124 focus
= FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
3126 focus
= event
->frame_or_window
;
3127 internal_last_event_frame
= focus
;
3128 Vlast_event_frame
= focus
;
3131 last_event_timestamp
= event
->timestamp
;
3132 interrupt_signal ();
3136 if (c
&& c
== stop_character
)
3142 /* Don't insert two buffer_switch_event's in a row.
3143 Just ignore the second one. */
3144 else if (event
->kind
== buffer_switch_event
3145 && kbd_fetch_ptr
!= kbd_store_ptr
3146 && kbd_store_ptr
->kind
== buffer_switch_event
)
3149 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
3150 kbd_store_ptr
= kbd_buffer
;
3152 /* Don't let the very last slot in the buffer become full,
3153 since that would make the two pointers equal,
3154 and that is indistinguishable from an empty buffer.
3155 Discard the event if it would fill the last slot. */
3156 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
3160 #if 0 /* The selection_request_event case looks bogus, and it's error
3161 prone to assign individual members for other events, in case
3162 the input_event structure is changed. --2000-07-13, gerd. */
3163 struct input_event
*sp
= kbd_store_ptr
;
3164 sp
->kind
= event
->kind
;
3165 if (event
->kind
== selection_request_event
)
3167 /* We must not use the ordinary copying code for this case,
3168 since `part' is an enum and copying it might not copy enough
3170 bcopy (event
, (char *) sp
, sizeof (*event
));
3175 sp
->code
= event
->code
;
3176 sp
->part
= event
->part
;
3177 sp
->frame_or_window
= event
->frame_or_window
;
3178 sp
->arg
= event
->arg
;
3179 sp
->modifiers
= event
->modifiers
;
3182 sp
->timestamp
= event
->timestamp
;
3185 *kbd_store_ptr
= *event
;
3188 idx
= 2 * (kbd_store_ptr
- kbd_buffer
);
3189 ASET (kbd_buffer_gcpro
, idx
, event
->frame_or_window
);
3190 ASET (kbd_buffer_gcpro
, idx
+ 1, event
->arg
);
3196 /* Generate HELP_EVENT input_events in BUFP which has room for
3197 SIZE events. If there's not enough room in BUFP, ignore this
3200 HELP is the help form.
3202 FRAME is the frame on which the help is generated. OBJECT is the
3203 Lisp object where the help was found (a buffer, a string, an
3204 overlay, or nil if neither from a string nor from a buffer. POS is
3205 the position within OBJECT where the help was found.
3207 Value is the number of input_events generated. */
3210 gen_help_event (bufp
, size
, help
, frame
, window
, object
, pos
)
3211 struct input_event
*bufp
;
3213 Lisp_Object help
, frame
, object
, window
;
3216 int nevents_stored
= 0;
3220 bufp
->kind
= HELP_EVENT
;
3221 bufp
->frame_or_window
= frame
;
3223 bufp
->x
= make_number (pos
);
3227 bufp
->kind
= HELP_EVENT
;
3228 bufp
->frame_or_window
= WINDOWP (window
) ? window
: frame
;
3234 return nevents_stored
;
3238 /* Store HELP_EVENTs for HELP on FRAME in the input queue. */
3241 kbd_buffer_store_help_event (frame
, help
)
3242 Lisp_Object frame
, help
;
3244 struct input_event event
;
3246 event
.kind
= HELP_EVENT
;
3247 event
.frame_or_window
= frame
;
3249 event
.x
= make_number (0);
3251 kbd_buffer_store_event (&event
);
3253 event
.kind
= HELP_EVENT
;
3254 event
.frame_or_window
= frame
;
3256 event
.x
= make_number (0);
3258 kbd_buffer_store_event (&event
);
3262 /* Discard any mouse events in the event buffer by setting them to
3265 discard_mouse_events ()
3267 struct input_event
*sp
;
3268 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
3270 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3273 if (sp
->kind
== mouse_click
3275 || sp
->kind
== w32_scroll_bar_click
3277 || sp
->kind
== scroll_bar_click
)
3279 sp
->kind
= no_event
;
3285 /* Return non-zero if there are any real events waiting in the event
3286 buffer, not counting `no_event's.
3288 If DISCARD is non-zero, discard no_event events at the front of
3289 the input queue, possibly leaving the input queue empty if there
3290 are no real input events. */
3293 kbd_buffer_events_waiting (discard
)
3296 struct input_event
*sp
;
3298 for (sp
= kbd_fetch_ptr
;
3299 sp
!= kbd_store_ptr
&& sp
->kind
== no_event
;
3302 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3309 return sp
!= kbd_store_ptr
&& sp
->kind
!= no_event
;
3313 /* Clear input event EVENT. */
3317 struct input_event
*event
;
3319 int idx
= 2 * (event
- kbd_buffer
);
3320 ASET (kbd_buffer_gcpro
, idx
, Qnil
);
3321 ASET (kbd_buffer_gcpro
, idx
+ 1, Qnil
);
3322 event
->kind
= no_event
;
3326 /* Read one event from the event buffer, waiting if necessary.
3327 The value is a Lisp object representing the event.
3328 The value is nil for an event that should be ignored,
3329 or that was handled here.
3330 We always read and discard one event. */
3333 kbd_buffer_get_event (kbp
, used_mouse_menu
)
3335 int *used_mouse_menu
;
3344 *kbp
= current_kboard
;
3348 /* Wait until there is input available. */
3351 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3354 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
3358 /* If the quit flag is set, then read_char will return
3359 quit_char, so that counts as "available input." */
3360 if (!NILP (Vquit_flag
))
3361 quit_throw_to_read_char ();
3363 /* One way or another, wait until input is available; then, if
3364 interrupt handlers have not read it, read it now. */
3367 wait_for_kbd_input ();
3369 /* Note SIGIO has been undef'd if FIONREAD is missing. */
3373 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3376 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
3380 Lisp_Object minus_one
;
3382 XSETINT (minus_one
, -1);
3383 wait_reading_process_input (0, 0, minus_one
, 1);
3385 if (!interrupt_input
&& kbd_fetch_ptr
== kbd_store_ptr
)
3386 /* Pass 1 for EXPECT since we just waited to have input. */
3387 read_avail_input (1);
3389 #endif /* not VMS */
3392 if (CONSP (Vunread_command_events
))
3395 first
= XCAR (Vunread_command_events
);
3396 Vunread_command_events
= XCDR (Vunread_command_events
);
3397 *kbp
= current_kboard
;
3401 /* At this point, we know that there is a readable event available
3402 somewhere. If the event queue is empty, then there must be a
3403 mouse movement enabled and available. */
3404 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3406 struct input_event
*event
;
3408 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
3412 last_event_timestamp
= event
->timestamp
;
3415 *kbp
= event_to_kboard (event
);
3417 *kbp
= current_kboard
; /* Better than returning null ptr? */
3419 *kbp
= &the_only_kboard
;
3424 /* These two kinds of events get special handling
3425 and don't actually appear to the command loop.
3426 We return nil for them. */
3427 if (event
->kind
== selection_request_event
)
3430 struct input_event copy
;
3432 /* Remove it from the buffer before processing it,
3433 since otherwise swallow_events will see it
3434 and process it again. */
3436 kbd_fetch_ptr
= event
+ 1;
3437 input_pending
= readable_events (0);
3438 x_handle_selection_request (©
);
3440 /* We're getting selection request events, but we don't have
3446 else if (event
->kind
== selection_clear_event
)
3449 struct input_event copy
;
3451 /* Remove it from the buffer before processing it. */
3453 kbd_fetch_ptr
= event
+ 1;
3454 input_pending
= readable_events (0);
3455 x_handle_selection_clear (©
);
3457 /* We're getting selection request events, but we don't have
3462 #if defined (HAVE_X11) || defined (HAVE_NTGUI)
3463 else if (event
->kind
== delete_window_event
)
3465 /* Make an event (delete-frame (FRAME)). */
3466 obj
= Fcons (event
->frame_or_window
, Qnil
);
3467 obj
= Fcons (Qdelete_frame
, Fcons (obj
, Qnil
));
3468 kbd_fetch_ptr
= event
+ 1;
3470 else if (event
->kind
== iconify_event
)
3472 /* Make an event (iconify-frame (FRAME)). */
3473 obj
= Fcons (event
->frame_or_window
, Qnil
);
3474 obj
= Fcons (Qiconify_frame
, Fcons (obj
, Qnil
));
3475 kbd_fetch_ptr
= event
+ 1;
3477 else if (event
->kind
== deiconify_event
)
3479 /* Make an event (make-frame-visible (FRAME)). */
3480 obj
= Fcons (event
->frame_or_window
, Qnil
);
3481 obj
= Fcons (Qmake_frame_visible
, Fcons (obj
, Qnil
));
3482 kbd_fetch_ptr
= event
+ 1;
3485 else if (event
->kind
== buffer_switch_event
)
3487 /* The value doesn't matter here; only the type is tested. */
3488 XSETBUFFER (obj
, current_buffer
);
3489 kbd_fetch_ptr
= event
+ 1;
3491 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
3492 else if (event
->kind
== menu_bar_activate_event
)
3494 kbd_fetch_ptr
= event
+ 1;
3495 input_pending
= readable_events (0);
3496 if (FRAME_LIVE_P (XFRAME (event
->frame_or_window
)))
3497 x_activate_menubar (XFRAME (event
->frame_or_window
));
3501 else if (event
->kind
== language_change_event
)
3503 /* Make an event (language-change (FRAME CHARSET LCID)). */
3504 obj
= Fcons (event
->modifiers
, Qnil
);
3505 obj
= Fcons (event
->code
, Qnil
);
3506 obj
= Fcons (event
->frame_or_window
, obj
);
3507 obj
= Fcons (Qlanguage_change
, Fcons (obj
, Qnil
));
3508 kbd_fetch_ptr
= event
+ 1;
3511 /* Just discard these, by returning nil.
3512 With MULTI_KBOARD, these events are used as placeholders
3513 when we need to randomly delete events from the queue.
3514 (They shouldn't otherwise be found in the buffer,
3515 but on some machines it appears they do show up
3516 even without MULTI_KBOARD.) */
3517 /* On Windows NT/9X, no_event is used to delete extraneous
3518 mouse events during a popup-menu call. */
3519 else if (event
->kind
== no_event
)
3520 kbd_fetch_ptr
= event
+ 1;
3521 else if (event
->kind
== HELP_EVENT
)
3523 /* There are always two HELP_EVENTs in the input queue. */
3524 Lisp_Object object
, position
, help
, frame
, window
;
3526 xassert (event
->code
== 0);
3527 frame
= event
->frame_or_window
;
3528 object
= event
->arg
;
3529 position
= event
->x
;
3530 clear_event (event
);
3532 kbd_fetch_ptr
= event
+ 1;
3533 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
3536 xassert (event
->code
== 1);
3538 window
= event
->frame_or_window
;
3539 if (!WINDOWP (window
))
3541 obj
= Fcons (Qhelp_echo
,
3542 list5 (frame
, help
, window
, object
, position
));
3543 clear_event (event
);
3544 kbd_fetch_ptr
= event
+ 1;
3546 else if (event
->kind
== FOCUS_IN_EVENT
)
3548 /* Notification of a FocusIn event. The frame receiving the
3549 focus is in event->frame_or_window. Generate a
3550 switch-frame event if necessary. */
3551 Lisp_Object frame
, focus
;
3553 frame
= event
->frame_or_window
;
3554 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
3558 if (!EQ (frame
, internal_last_event_frame
)
3559 && !EQ (frame
, selected_frame
))
3560 obj
= make_lispy_switch_frame (frame
);
3561 internal_last_event_frame
= frame
;
3562 kbd_fetch_ptr
= event
+ 1;
3566 /* If this event is on a different frame, return a switch-frame this
3567 time, and leave the event in the queue for next time. */
3571 frame
= event
->frame_or_window
;
3573 frame
= XCAR (frame
);
3574 else if (WINDOWP (frame
))
3575 frame
= WINDOW_FRAME (XWINDOW (frame
));
3577 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
3581 if (! EQ (frame
, internal_last_event_frame
)
3582 && !EQ (frame
, selected_frame
))
3583 obj
= make_lispy_switch_frame (frame
);
3584 internal_last_event_frame
= frame
;
3586 /* If we didn't decide to make a switch-frame event, go ahead
3587 and build a real event from the queue entry. */
3593 obj
= make_lispy_event (event
);
3595 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
3596 /* If this was a menu selection, then set the flag to inhibit
3597 writing to last_nonmenu_event. Don't do this if the event
3598 we're returning is (menu-bar), though; that indicates the
3599 beginning of the menu sequence, and we might as well leave
3600 that as the `event with parameters' for this selection. */
3602 && !EQ (event
->frame_or_window
, event
->arg
)
3603 && (event
->kind
== MENU_BAR_EVENT
3604 || event
->kind
== TOOL_BAR_EVENT
))
3605 *used_mouse_menu
= 1;
3608 /* Wipe out this event, to catch bugs. */
3609 clear_event (event
);
3610 kbd_fetch_ptr
= event
+ 1;
3615 /* Try generating a mouse motion event. */
3616 else if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
3618 FRAME_PTR f
= some_mouse_moved ();
3619 Lisp_Object bar_window
;
3620 enum scroll_bar_part part
;
3624 *kbp
= current_kboard
;
3625 /* Note that this uses F to determine which display to look at.
3626 If there is no valid info, it does not store anything
3627 so x remains nil. */
3629 (*mouse_position_hook
) (&f
, 0, &bar_window
, &part
, &x
, &y
, &time
);
3633 /* Decide if we should generate a switch-frame event. Don't
3634 generate switch-frame events for motion outside of all Emacs
3640 frame
= FRAME_FOCUS_FRAME (f
);
3642 XSETFRAME (frame
, f
);
3644 if (! EQ (frame
, internal_last_event_frame
)
3645 && !EQ (frame
, selected_frame
))
3646 obj
= make_lispy_switch_frame (frame
);
3647 internal_last_event_frame
= frame
;
3650 /* If we didn't decide to make a switch-frame event, go ahead and
3651 return a mouse-motion event. */
3652 if (!NILP (x
) && NILP (obj
))
3653 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
3655 #endif /* HAVE_MOUSE */
3657 /* We were promised by the above while loop that there was
3658 something for us to read! */
3661 input_pending
= readable_events (0);
3663 Vlast_event_frame
= internal_last_event_frame
;
3668 /* Process any events that are not user-visible,
3669 then return, without reading any user-visible events. */
3672 swallow_events (do_display
)
3677 while (kbd_fetch_ptr
!= kbd_store_ptr
)
3679 struct input_event
*event
;
3681 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
3685 last_event_timestamp
= event
->timestamp
;
3687 /* These two kinds of events get special handling
3688 and don't actually appear to the command loop. */
3689 if (event
->kind
== selection_request_event
)
3692 struct input_event copy
;
3694 /* Remove it from the buffer before processing it,
3695 since otherwise swallow_events called recursively could see it
3696 and process it again. */
3698 kbd_fetch_ptr
= event
+ 1;
3699 input_pending
= readable_events (0);
3700 x_handle_selection_request (©
);
3702 /* We're getting selection request events, but we don't have
3708 else if (event
->kind
== selection_clear_event
)
3711 struct input_event copy
;
3713 /* Remove it from the buffer before processing it, */
3716 kbd_fetch_ptr
= event
+ 1;
3717 input_pending
= readable_events (0);
3718 x_handle_selection_clear (©
);
3720 /* We're getting selection request events, but we don't have
3729 old_timers_run
= timers_run
;
3730 get_input_pending (&input_pending
, 1);
3732 if (timers_run
!= old_timers_run
&& do_display
)
3733 redisplay_preserve_echo_area ();
3736 static EMACS_TIME timer_idleness_start_time
;
3738 /* Record the start of when Emacs is idle,
3739 for the sake of running idle-time timers. */
3746 /* If we are already in the idle state, do nothing. */
3747 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3750 EMACS_GET_TIME (timer_idleness_start_time
);
3752 /* Mark all idle-time timers as once again candidates for running. */
3753 for (timers
= Vtimer_idle_list
; CONSP (timers
); timers
= XCDR (timers
))
3757 timer
= XCAR (timers
);
3759 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3761 XVECTOR (timer
)->contents
[0] = Qnil
;
3765 /* Record that Emacs is no longer idle, so stop running idle-time timers. */
3770 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
3773 /* This is only for debugging. */
3774 struct input_event last_timer_event
;
3776 /* Check whether a timer has fired. To prevent larger problems we simply
3777 disregard elements that are not proper timers. Do not make a circular
3778 timer list for the time being.
3780 Returns the number of seconds to wait until the next timer fires. If a
3781 timer is triggering now, return zero seconds.
3782 If no timer is active, return -1 seconds.
3784 If a timer is ripe, we run it, with quitting turned off.
3786 DO_IT_NOW is now ignored. It used to mean that we should
3787 run the timer directly instead of queueing a timer-event.
3788 Now we always run timers directly. */
3791 timer_check (do_it_now
)
3794 EMACS_TIME nexttime
;
3795 EMACS_TIME now
, idleness_now
;
3796 Lisp_Object timers
, idle_timers
, chosen_timer
;
3797 struct gcpro gcpro1
, gcpro2
, gcpro3
;
3799 EMACS_SET_SECS (nexttime
, -1);
3800 EMACS_SET_USECS (nexttime
, -1);
3802 /* Always consider the ordinary timers. */
3803 timers
= Vtimer_list
;
3804 /* Consider the idle timers only if Emacs is idle. */
3805 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3806 idle_timers
= Vtimer_idle_list
;
3809 chosen_timer
= Qnil
;
3810 GCPRO3 (timers
, idle_timers
, chosen_timer
);
3812 if (CONSP (timers
) || CONSP (idle_timers
))
3814 EMACS_GET_TIME (now
);
3815 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3816 EMACS_SUB_TIME (idleness_now
, now
, timer_idleness_start_time
);
3819 while (CONSP (timers
) || CONSP (idle_timers
))
3821 Lisp_Object
*vector
;
3822 Lisp_Object timer
= Qnil
, idle_timer
= Qnil
;
3823 EMACS_TIME timer_time
, idle_timer_time
;
3824 EMACS_TIME difference
, timer_difference
, idle_timer_difference
;
3826 /* Skip past invalid timers and timers already handled. */
3829 timer
= XCAR (timers
);
3830 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3832 timers
= XCDR (timers
);
3835 vector
= XVECTOR (timer
)->contents
;
3837 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
3838 || !INTEGERP (vector
[3])
3839 || ! NILP (vector
[0]))
3841 timers
= XCDR (timers
);
3845 if (!NILP (idle_timers
))
3847 timer
= XCAR (idle_timers
);
3848 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3850 idle_timers
= XCDR (idle_timers
);
3853 vector
= XVECTOR (timer
)->contents
;
3855 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
3856 || !INTEGERP (vector
[3])
3857 || ! NILP (vector
[0]))
3859 idle_timers
= XCDR (idle_timers
);
3864 /* Set TIMER, TIMER_TIME and TIMER_DIFFERENCE
3865 based on the next ordinary timer.
3866 TIMER_DIFFERENCE is the distance in time from NOW to when
3867 this timer becomes ripe (negative if it's already ripe). */
3870 timer
= XCAR (timers
);
3871 vector
= XVECTOR (timer
)->contents
;
3872 EMACS_SET_SECS (timer_time
,
3873 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
3874 EMACS_SET_USECS (timer_time
, XINT (vector
[3]));
3875 EMACS_SUB_TIME (timer_difference
, timer_time
, now
);
3878 /* Set IDLE_TIMER, IDLE_TIMER_TIME and IDLE_TIMER_DIFFERENCE
3879 based on the next idle timer. */
3880 if (!NILP (idle_timers
))
3882 idle_timer
= XCAR (idle_timers
);
3883 vector
= XVECTOR (idle_timer
)->contents
;
3884 EMACS_SET_SECS (idle_timer_time
,
3885 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
3886 EMACS_SET_USECS (idle_timer_time
, XINT (vector
[3]));
3887 EMACS_SUB_TIME (idle_timer_difference
, idle_timer_time
, idleness_now
);
3890 /* Decide which timer is the next timer,
3891 and set CHOSEN_TIMER, VECTOR and DIFFERENCE accordingly.
3892 Also step down the list where we found that timer. */
3894 if (! NILP (timers
) && ! NILP (idle_timers
))
3897 EMACS_SUB_TIME (temp
, timer_difference
, idle_timer_difference
);
3898 if (EMACS_TIME_NEG_P (temp
))
3900 chosen_timer
= timer
;
3901 timers
= XCDR (timers
);
3902 difference
= timer_difference
;
3906 chosen_timer
= idle_timer
;
3907 idle_timers
= XCDR (idle_timers
);
3908 difference
= idle_timer_difference
;
3911 else if (! NILP (timers
))
3913 chosen_timer
= timer
;
3914 timers
= XCDR (timers
);
3915 difference
= timer_difference
;
3919 chosen_timer
= idle_timer
;
3920 idle_timers
= XCDR (idle_timers
);
3921 difference
= idle_timer_difference
;
3923 vector
= XVECTOR (chosen_timer
)->contents
;
3925 /* If timer is ripe, run it if it hasn't been run. */
3926 if (EMACS_TIME_NEG_P (difference
)
3927 || (EMACS_SECS (difference
) == 0
3928 && EMACS_USECS (difference
) == 0))
3930 if (NILP (vector
[0]))
3932 int was_locked
= single_kboard
;
3933 int count
= specpdl_ptr
- specpdl
;
3935 /* Mark the timer as triggered to prevent problems if the lisp
3936 code fails to reschedule it right. */
3939 specbind (Qinhibit_quit
, Qt
);
3941 call1 (Qtimer_event_handler
, chosen_timer
);
3944 unbind_to (count
, Qnil
);
3946 /* Resume allowing input from any kboard, if that was true before. */
3948 any_kboard_state ();
3950 /* Since we have handled the event,
3951 we don't need to tell the caller to wake up and do it. */
3955 /* When we encounter a timer that is still waiting,
3956 return the amount of time to wait before it is ripe. */
3963 /* No timers are pending in the future. */
3964 /* Return 0 if we generated an event, and -1 if not. */
3969 /* Caches for modify_event_symbol. */
3970 static Lisp_Object accent_key_syms
;
3971 static Lisp_Object func_key_syms
;
3972 static Lisp_Object mouse_syms
;
3974 static Lisp_Object mouse_wheel_syms
;
3976 static Lisp_Object drag_n_drop_syms
;
3978 /* This is a list of keysym codes for special "accent" characters.
3979 It parallels lispy_accent_keys. */
3981 static int lispy_accent_codes
[] =
3983 #ifdef XK_dead_circumflex
3988 #ifdef XK_dead_grave
3993 #ifdef XK_dead_tilde
3998 #ifdef XK_dead_diaeresis
4003 #ifdef XK_dead_macron
4008 #ifdef XK_dead_degree
4013 #ifdef XK_dead_acute
4018 #ifdef XK_dead_cedilla
4023 #ifdef XK_dead_breve
4028 #ifdef XK_dead_ogonek
4033 #ifdef XK_dead_caron
4038 #ifdef XK_dead_doubleacute
4039 XK_dead_doubleacute
,
4043 #ifdef XK_dead_abovedot
4050 /* This is a list of Lisp names for special "accent" characters.
4051 It parallels lispy_accent_codes. */
4053 static char *lispy_accent_keys
[] =
4071 #define FUNCTION_KEY_OFFSET 0x0
4073 char *lispy_function_keys
[] =
4077 0, /* VK_LBUTTON 0x01 */
4078 0, /* VK_RBUTTON 0x02 */
4079 "cancel", /* VK_CANCEL 0x03 */
4080 0, /* VK_MBUTTON 0x04 */
4082 0, 0, 0, /* 0x05 .. 0x07 */
4084 "backspace", /* VK_BACK 0x08 */
4085 "tab", /* VK_TAB 0x09 */
4087 0, 0, /* 0x0A .. 0x0B */
4089 "clear", /* VK_CLEAR 0x0C */
4090 "return", /* VK_RETURN 0x0D */
4092 0, 0, /* 0x0E .. 0x0F */
4094 0, /* VK_SHIFT 0x10 */
4095 0, /* VK_CONTROL 0x11 */
4096 0, /* VK_MENU 0x12 */
4097 "pause", /* VK_PAUSE 0x13 */
4098 "capslock", /* VK_CAPITAL 0x14 */
4100 0, 0, 0, 0, 0, 0, /* 0x15 .. 0x1A */
4102 "escape", /* VK_ESCAPE 0x1B */
4104 0, 0, 0, 0, /* 0x1C .. 0x1F */
4106 0, /* VK_SPACE 0x20 */
4107 "prior", /* VK_PRIOR 0x21 */
4108 "next", /* VK_NEXT 0x22 */
4109 "end", /* VK_END 0x23 */
4110 "home", /* VK_HOME 0x24 */
4111 "left", /* VK_LEFT 0x25 */
4112 "up", /* VK_UP 0x26 */
4113 "right", /* VK_RIGHT 0x27 */
4114 "down", /* VK_DOWN 0x28 */
4115 "select", /* VK_SELECT 0x29 */
4116 "print", /* VK_PRINT 0x2A */
4117 "execute", /* VK_EXECUTE 0x2B */
4118 "snapshot", /* VK_SNAPSHOT 0x2C */
4119 "insert", /* VK_INSERT 0x2D */
4120 "delete", /* VK_DELETE 0x2E */
4121 "help", /* VK_HELP 0x2F */
4123 /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
4125 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4127 0, 0, 0, 0, 0, 0, 0, /* 0x3A .. 0x40 */
4129 /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
4131 0, 0, 0, 0, 0, 0, 0, 0, 0,
4132 0, 0, 0, 0, 0, 0, 0, 0, 0,
4133 0, 0, 0, 0, 0, 0, 0, 0,
4135 "lwindow", /* VK_LWIN 0x5B */
4136 "rwindow", /* VK_RWIN 0x5C */
4137 "apps", /* VK_APPS 0x5D */
4139 0, 0, /* 0x5E .. 0x5F */
4141 "kp-0", /* VK_NUMPAD0 0x60 */
4142 "kp-1", /* VK_NUMPAD1 0x61 */
4143 "kp-2", /* VK_NUMPAD2 0x62 */
4144 "kp-3", /* VK_NUMPAD3 0x63 */
4145 "kp-4", /* VK_NUMPAD4 0x64 */
4146 "kp-5", /* VK_NUMPAD5 0x65 */
4147 "kp-6", /* VK_NUMPAD6 0x66 */
4148 "kp-7", /* VK_NUMPAD7 0x67 */
4149 "kp-8", /* VK_NUMPAD8 0x68 */
4150 "kp-9", /* VK_NUMPAD9 0x69 */
4151 "kp-multiply", /* VK_MULTIPLY 0x6A */
4152 "kp-add", /* VK_ADD 0x6B */
4153 "kp-separator", /* VK_SEPARATOR 0x6C */
4154 "kp-subtract", /* VK_SUBTRACT 0x6D */
4155 "kp-decimal", /* VK_DECIMAL 0x6E */
4156 "kp-divide", /* VK_DIVIDE 0x6F */
4157 "f1", /* VK_F1 0x70 */
4158 "f2", /* VK_F2 0x71 */
4159 "f3", /* VK_F3 0x72 */
4160 "f4", /* VK_F4 0x73 */
4161 "f5", /* VK_F5 0x74 */
4162 "f6", /* VK_F6 0x75 */
4163 "f7", /* VK_F7 0x76 */
4164 "f8", /* VK_F8 0x77 */
4165 "f9", /* VK_F9 0x78 */
4166 "f10", /* VK_F10 0x79 */
4167 "f11", /* VK_F11 0x7A */
4168 "f12", /* VK_F12 0x7B */
4169 "f13", /* VK_F13 0x7C */
4170 "f14", /* VK_F14 0x7D */
4171 "f15", /* VK_F15 0x7E */
4172 "f16", /* VK_F16 0x7F */
4173 "f17", /* VK_F17 0x80 */
4174 "f18", /* VK_F18 0x81 */
4175 "f19", /* VK_F19 0x82 */
4176 "f20", /* VK_F20 0x83 */
4177 "f21", /* VK_F21 0x84 */
4178 "f22", /* VK_F22 0x85 */
4179 "f23", /* VK_F23 0x86 */
4180 "f24", /* VK_F24 0x87 */
4182 0, 0, 0, 0, /* 0x88 .. 0x8B */
4183 0, 0, 0, 0, /* 0x8C .. 0x8F */
4185 "kp-numlock", /* VK_NUMLOCK 0x90 */
4186 "scroll", /* VK_SCROLL 0x91 */
4188 "kp-space", /* VK_NUMPAD_CLEAR 0x92 */
4189 "kp-enter", /* VK_NUMPAD_ENTER 0x93 */
4190 "kp-prior", /* VK_NUMPAD_PRIOR 0x94 */
4191 "kp-next", /* VK_NUMPAD_NEXT 0x95 */
4192 "kp-end", /* VK_NUMPAD_END 0x96 */
4193 "kp-home", /* VK_NUMPAD_HOME 0x97 */
4194 "kp-left", /* VK_NUMPAD_LEFT 0x98 */
4195 "kp-up", /* VK_NUMPAD_UP 0x99 */
4196 "kp-right", /* VK_NUMPAD_RIGHT 0x9A */
4197 "kp-down", /* VK_NUMPAD_DOWN 0x9B */
4198 "kp-insert", /* VK_NUMPAD_INSERT 0x9C */
4199 "kp-delete", /* VK_NUMPAD_DELETE 0x9D */
4201 0, 0, /* 0x9E .. 0x9F */
4204 * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
4205 * Used only as parameters to GetAsyncKeyState and GetKeyState.
4206 * No other API or message will distinguish left and right keys this way.
4210 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4211 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4212 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4213 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4214 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4220 "attn", /* VK_ATTN 0xF6 */
4221 "crsel", /* VK_CRSEL 0xF7 */
4222 "exsel", /* VK_EXSEL 0xF8 */
4223 "ereof", /* VK_EREOF 0xF9 */
4224 "play", /* VK_PLAY 0xFA */
4225 "zoom", /* VK_ZOOM 0xFB */
4226 "noname", /* VK_NONAME 0xFC */
4227 "pa1", /* VK_PA1 0xFD */
4228 "oem_clear", /* VK_OEM_CLEAR 0xFE */
4232 #else /* not HAVE_NTGUI */
4235 static char *lispy_kana_keys
[] =
4237 /* X Keysym value */
4238 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x400 .. 0x40f */
4239 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x410 .. 0x41f */
4240 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x420 .. 0x42f */
4241 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x430 .. 0x43f */
4242 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x440 .. 0x44f */
4243 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x450 .. 0x45f */
4244 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x460 .. 0x46f */
4245 0,0,0,0,0,0,0,0,0,0,0,0,0,0,"overline",0,
4246 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x480 .. 0x48f */
4247 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x490 .. 0x49f */
4248 0, "kana-fullstop", "kana-openingbracket", "kana-closingbracket",
4249 "kana-comma", "kana-conjunctive", "kana-WO", "kana-a",
4250 "kana-i", "kana-u", "kana-e", "kana-o",
4251 "kana-ya", "kana-yu", "kana-yo", "kana-tsu",
4252 "prolongedsound", "kana-A", "kana-I", "kana-U",
4253 "kana-E", "kana-O", "kana-KA", "kana-KI",
4254 "kana-KU", "kana-KE", "kana-KO", "kana-SA",
4255 "kana-SHI", "kana-SU", "kana-SE", "kana-SO",
4256 "kana-TA", "kana-CHI", "kana-TSU", "kana-TE",
4257 "kana-TO", "kana-NA", "kana-NI", "kana-NU",
4258 "kana-NE", "kana-NO", "kana-HA", "kana-HI",
4259 "kana-FU", "kana-HE", "kana-HO", "kana-MA",
4260 "kana-MI", "kana-MU", "kana-ME", "kana-MO",
4261 "kana-YA", "kana-YU", "kana-YO", "kana-RA",
4262 "kana-RI", "kana-RU", "kana-RE", "kana-RO",
4263 "kana-WA", "kana-N", "voicedsound", "semivoicedsound",
4264 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4e0 .. 0x4ef */
4265 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4f0 .. 0x4ff */
4267 #endif /* XK_kana_A */
4269 #define FUNCTION_KEY_OFFSET 0xff00
4271 /* You'll notice that this table is arranged to be conveniently
4272 indexed by X Windows keysym values. */
4273 static char *lispy_function_keys
[] =
4275 /* X Keysym value */
4277 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00...0f */
4278 "backspace", "tab", "linefeed", "clear",
4280 0, 0, 0, "pause", /* 0xff10...1f */
4281 0, 0, 0, 0, 0, 0, 0, "escape",
4283 0, "kanji", "muhenkan", "henkan", /* 0xff20...2f */
4284 "romaji", "hiragana", "katakana", "hiragana-katakana",
4285 "zenkaku", "hankaku", "zenkaku-hankaku", "touroku",
4286 "massyo", "kana-lock", "kana-shift", "eisu-shift",
4287 "eisu-toggle", /* 0xff30...3f */
4288 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4289 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
4291 "home", "left", "up", "right", /* 0xff50 */ /* IsCursorKey */
4292 "down", "prior", "next", "end",
4293 "begin", 0, 0, 0, 0, 0, 0, 0,
4294 "select", /* 0xff60 */ /* IsMiscFunctionKey */
4305 "break", /* 0xff6b */
4308 0, 0, 0, 0, "backtab", 0, 0, 0, /* 0xff70... */
4309 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff78... */
4310 "kp-space", /* 0xff80 */ /* IsKeypadKey */
4311 0, 0, 0, 0, 0, 0, 0, 0,
4312 "kp-tab", /* 0xff89 */
4314 "kp-enter", /* 0xff8d */
4316 "kp-f1", /* 0xff91 */
4320 "kp-home", /* 0xff95 */
4325 "kp-prior", /* kp-page-up */
4326 "kp-next", /* kp-page-down */
4332 0, 0, 0, 0, 0, 0, 0, 0, 0,
4333 "kp-multiply", /* 0xffaa */
4338 "kp-divide", /* 0xffaf */
4339 "kp-0", /* 0xffb0 */
4340 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
4343 "kp-equal", /* 0xffbd */
4344 "f1", /* 0xffbe */ /* IsFunctionKey */
4346 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
4347 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
4348 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
4349 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
4350 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
4351 0, 0, 0, 0, 0, 0, 0, 0,
4352 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
4353 0, 0, 0, 0, 0, 0, 0, "delete"
4356 /* ISO 9995 Function and Modifier Keys; the first byte is 0xFE. */
4357 #define ISO_FUNCTION_KEY_OFFSET 0xfe00
4359 static char *iso_lispy_function_keys
[] =
4361 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe00 */
4362 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe08 */
4363 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe10 */
4364 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe18 */
4365 "iso-lefttab", /* 0xfe20 */
4366 "iso-move-line-up", "iso-move-line-down",
4367 "iso-partial-line-up", "iso-partial-line-down",
4368 "iso-partial-space-left", "iso-partial-space-right",
4369 "iso-set-margin-left", "iso-set-margin-right", /* 0xffe27, 28 */
4370 "iso-release-margin-left", "iso-release-margin-right",
4371 "iso-release-both-margins",
4372 "iso-fast-cursor-left", "iso-fast-cursor-right",
4373 "iso-fast-cursor-up", "iso-fast-cursor-down",
4374 "iso-continuous-underline", "iso-discontinuous-underline", /* 0xfe30, 31 */
4375 "iso-emphasize", "iso-center-object", "iso-enter", /* ... 0xfe34 */
4378 #endif /* not HAVE_NTGUI */
4380 Lisp_Object Vlispy_mouse_stem
;
4383 /* mouse-wheel events are generated by the wheel on devices such as
4384 the MS Intellimouse. The wheel sits in between the left and right
4385 mouse buttons, and is typically used to scroll or zoom the window
4386 underneath the pointer. mouse-wheel events specify the object on
4387 which they operate, and a delta corresponding to the amount and
4388 direction that the wheel is rotated. Clicking the mouse-wheel
4389 generates a mouse-2 event. */
4390 static char *lispy_mouse_wheel_names
[] =
4395 #endif /* WINDOWSNT */
4397 /* drag-n-drop events are generated when a set of selected files are
4398 dragged from another application and dropped onto an Emacs window. */
4399 static char *lispy_drag_n_drop_names
[] =
4404 /* Scroll bar parts. */
4405 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
4406 Lisp_Object Qup
, Qdown
, Qbottom
, Qend_scroll
;
4407 Lisp_Object Qtop
, Qratio
;
4409 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
4410 Lisp_Object
*scroll_bar_parts
[] = {
4411 &Qabove_handle
, &Qhandle
, &Qbelow_handle
,
4412 &Qup
, &Qdown
, &Qtop
, &Qbottom
, &Qend_scroll
, &Qratio
4415 /* User signal events. */
4416 Lisp_Object Qusr1_signal
, Qusr2_signal
;
4418 Lisp_Object
*lispy_user_signals
[] =
4420 &Qusr1_signal
, &Qusr2_signal
4424 /* A vector, indexed by button number, giving the down-going location
4425 of currently depressed buttons, both scroll bar and non-scroll bar.
4427 The elements have the form
4428 (BUTTON-NUMBER MODIFIER-MASK . REST)
4429 where REST is the cdr of a position as it would be reported in the event.
4431 The make_lispy_event function stores positions here to tell the
4432 difference between click and drag events, and to store the starting
4433 location to be included in drag events. */
4435 static Lisp_Object button_down_location
;
4437 /* Information about the most recent up-going button event: Which
4438 button, what location, and what time. */
4440 static int last_mouse_button
;
4441 static int last_mouse_x
;
4442 static int last_mouse_y
;
4443 static unsigned long button_down_time
;
4445 /* The maximum time between clicks to make a double-click,
4446 or Qnil to disable double-click detection,
4447 or Qt for no time limit. */
4448 Lisp_Object Vdouble_click_time
;
4450 /* The number of clicks in this multiple-click. */
4452 int double_click_count
;
4454 /* Given a struct input_event, build the lisp event which represents
4455 it. If EVENT is 0, build a mouse movement event from the mouse
4456 movement buffer, which should have a movement event in it.
4458 Note that events must be passed to this function in the order they
4459 are received; this function stores the location of button presses
4460 in order to build drag events when the button is released. */
4463 make_lispy_event (event
)
4464 struct input_event
*event
;
4468 switch (SWITCH_ENUM_CAST (event
->kind
))
4470 /* A simple keystroke. */
4471 case ascii_keystroke
:
4473 Lisp_Object lispy_c
;
4474 int c
= event
->code
& 0377;
4475 /* Turn ASCII characters into control characters
4477 if (event
->modifiers
& ctrl_modifier
)
4478 c
= make_ctrl_char (c
);
4480 /* Add in the other modifier bits. We took care of ctrl_modifier
4481 just above, and the shift key was taken care of by the X code,
4482 and applied to control characters by make_ctrl_char. */
4483 c
|= (event
->modifiers
4484 & (meta_modifier
| alt_modifier
4485 | hyper_modifier
| super_modifier
));
4486 /* Distinguish Shift-SPC from SPC. */
4487 if ((event
->code
& 0377) == 040
4488 && event
->modifiers
& shift_modifier
)
4489 c
|= shift_modifier
;
4490 button_down_time
= 0;
4491 XSETFASTINT (lispy_c
, c
);
4495 case multibyte_char_keystroke
:
4497 Lisp_Object lispy_c
;
4499 XSETFASTINT (lispy_c
, event
->code
);
4503 /* A function key. The symbol may need to have modifier prefixes
4505 case non_ascii_keystroke
:
4506 button_down_time
= 0;
4508 for (i
= 0; i
< sizeof (lispy_accent_codes
) / sizeof (int); i
++)
4509 if (event
->code
== lispy_accent_codes
[i
])
4510 return modify_event_symbol (i
,
4512 Qfunction_key
, Qnil
,
4513 lispy_accent_keys
, &accent_key_syms
,
4514 (sizeof (lispy_accent_keys
)
4515 / sizeof (lispy_accent_keys
[0])));
4517 /* Handle system-specific keysyms. */
4518 if (event
->code
& (1 << 28))
4520 /* We need to use an alist rather than a vector as the cache
4521 since we can't make a vector long enuf. */
4522 if (NILP (current_kboard
->system_key_syms
))
4523 current_kboard
->system_key_syms
= Fcons (Qnil
, Qnil
);
4524 return modify_event_symbol (event
->code
,
4527 current_kboard
->Vsystem_key_alist
,
4528 0, ¤t_kboard
->system_key_syms
,
4533 if (event
->code
>= 0x400 && event
->code
< 0x500)
4534 return modify_event_symbol (event
->code
- 0x400,
4535 event
->modifiers
& ~shift_modifier
,
4536 Qfunction_key
, Qnil
,
4537 lispy_kana_keys
, &func_key_syms
,
4538 (sizeof (lispy_kana_keys
)
4539 / sizeof (lispy_kana_keys
[0])));
4540 #endif /* XK_kana_A */
4542 #ifdef ISO_FUNCTION_KEY_OFFSET
4543 if (event
->code
< FUNCTION_KEY_OFFSET
4544 && event
->code
>= ISO_FUNCTION_KEY_OFFSET
)
4545 return modify_event_symbol (event
->code
- ISO_FUNCTION_KEY_OFFSET
,
4547 Qfunction_key
, Qnil
,
4548 iso_lispy_function_keys
, &func_key_syms
,
4549 (sizeof (iso_lispy_function_keys
)
4550 / sizeof (iso_lispy_function_keys
[0])));
4553 return modify_event_symbol (event
->code
- FUNCTION_KEY_OFFSET
,
4555 Qfunction_key
, Qnil
,
4556 lispy_function_keys
, &func_key_syms
,
4557 (sizeof (lispy_function_keys
)
4558 / sizeof (lispy_function_keys
[0])));
4561 /* A mouse click. Figure out where it is, decide whether it's
4562 a press, click or drag, and build the appropriate structure. */
4564 #ifndef USE_TOOLKIT_SCROLL_BARS
4565 case scroll_bar_click
:
4568 int button
= event
->code
;
4570 Lisp_Object position
;
4571 Lisp_Object
*start_pos_ptr
;
4572 Lisp_Object start_pos
;
4576 /* Build the position as appropriate for this mouse click. */
4577 if (event
->kind
== mouse_click
)
4580 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
4583 Lisp_Object string_info
= Qnil
;
4586 /* Ignore mouse events that were made on frame that
4587 have been deleted. */
4588 if (! FRAME_LIVE_P (f
))
4591 /* EVENT->x and EVENT->y are frame-relative pixel
4592 coordinates at this place. Under old redisplay, COLUMN
4593 and ROW are set to frame relative glyph coordinates
4594 which are then used to determine whether this click is
4595 in a menu (non-toolkit version). */
4596 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4597 &column
, &row
, NULL
, 1);
4599 #ifndef USE_X_TOOLKIT
4600 /* In the non-toolkit version, clicks on the menu bar
4601 are ordinary button events in the event buffer.
4602 Distinguish them, and invoke the menu.
4604 (In the toolkit version, the toolkit handles the menu bar
4605 and Emacs doesn't know about it until after the user
4606 makes a selection.) */
4607 if (row
>= 0 && row
< FRAME_MENU_BAR_LINES (f
)
4608 && (event
->modifiers
& down_modifier
))
4610 Lisp_Object items
, item
;
4615 /* Activate the menu bar on the down event. If the
4616 up event comes in before the menu code can deal with it,
4618 if (! (event
->modifiers
& down_modifier
))
4622 /* Find the menu bar item under `column'. */
4624 items
= FRAME_MENU_BAR_ITEMS (f
);
4625 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
4627 Lisp_Object pos
, string
;
4628 string
= XVECTOR (items
)->contents
[i
+ 1];
4629 pos
= XVECTOR (items
)->contents
[i
+ 3];
4632 if (column
>= XINT (pos
)
4633 && column
< XINT (pos
) + XSTRING (string
)->size
)
4635 item
= XVECTOR (items
)->contents
[i
];
4640 /* ELisp manual 2.4b says (x y) are window relative but
4641 code says they are frame-relative. */
4643 = Fcons (event
->frame_or_window
,
4645 Fcons (Fcons (event
->x
, event
->y
),
4646 Fcons (make_number (event
->timestamp
),
4649 return Fcons (item
, Fcons (position
, Qnil
));
4651 #endif /* not USE_X_TOOLKIT */
4653 /* Set `window' to the window under frame pixel coordinates
4654 event->x/event->y. */
4655 window
= window_from_coordinates (f
, XINT (event
->x
),
4656 XINT (event
->y
), &part
, 0);
4658 if (!WINDOWP (window
))
4660 window
= event
->frame_or_window
;
4665 /* It's a click in window window at frame coordinates
4666 event->x/ event->y. */
4667 struct window
*w
= XWINDOW (window
);
4669 /* Get window relative coordinates. Original code
4670 `rounded' this to glyph boundaries. */
4671 int wx
= FRAME_TO_WINDOW_PIXEL_X (w
, XINT (event
->x
));
4672 int wy
= FRAME_TO_WINDOW_PIXEL_Y (w
, XINT (event
->y
));
4674 /* Set event coordinates to window-relative coordinates
4675 for constructing the Lisp event below. */
4676 XSETINT (event
->x
, wx
);
4677 XSETINT (event
->y
, wy
);
4679 if (part
== 1 || part
== 3)
4681 /* Mode line or top line. Look for a string under
4682 the mouse that may have a `local-map' property. */
4686 posn
= part
== 1 ? Qmode_line
: Qheader_line
;
4687 string
= mode_line_string (w
, wx
, wy
, part
== 1, &charpos
);
4688 if (STRINGP (string
))
4689 string_info
= Fcons (string
, make_number (charpos
));
4692 posn
= Qvertical_line
;
4694 XSETINT (posn
, buffer_posn_from_coords (w
, &wx
, &wy
));
4700 Fcons (Fcons (event
->x
, event
->y
),
4701 Fcons (make_number (event
->timestamp
),
4704 : Fcons (string_info
, Qnil
))))));
4706 #ifndef USE_TOOLKIT_SCROLL_BARS
4709 /* It's a scrollbar click. */
4711 Lisp_Object portion_whole
;
4714 window
= event
->frame_or_window
;
4715 portion_whole
= Fcons (event
->x
, event
->y
);
4716 part
= *scroll_bar_parts
[(int) event
->part
];
4720 Fcons (Qvertical_scroll_bar
,
4721 Fcons (portion_whole
,
4722 Fcons (make_number (event
->timestamp
),
4723 Fcons (part
, Qnil
)))));
4725 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4727 if (button
>= XVECTOR (button_down_location
)->size
)
4729 button_down_location
= larger_vector (button_down_location
,
4731 mouse_syms
= larger_vector (mouse_syms
, button
+ 1, Qnil
);
4734 start_pos_ptr
= &XVECTOR (button_down_location
)->contents
[button
];
4736 start_pos
= *start_pos_ptr
;
4737 *start_pos_ptr
= Qnil
;
4739 is_double
= (button
== last_mouse_button
4740 && XINT (event
->x
) == last_mouse_x
4741 && XINT (event
->y
) == last_mouse_y
4742 && button_down_time
!= 0
4743 && (EQ (Vdouble_click_time
, Qt
)
4744 || (INTEGERP (Vdouble_click_time
)
4745 && ((int)(event
->timestamp
- button_down_time
)
4746 < XINT (Vdouble_click_time
)))));
4747 last_mouse_button
= button
;
4748 last_mouse_x
= XINT (event
->x
);
4749 last_mouse_y
= XINT (event
->y
);
4751 /* If this is a button press, squirrel away the location, so
4752 we can decide later whether it was a click or a drag. */
4753 if (event
->modifiers
& down_modifier
)
4757 double_click_count
++;
4758 event
->modifiers
|= ((double_click_count
> 2)
4763 double_click_count
= 1;
4764 button_down_time
= event
->timestamp
;
4765 *start_pos_ptr
= Fcopy_alist (position
);
4768 /* Now we're releasing a button - check the co-ordinates to
4769 see if this was a click or a drag. */
4770 else if (event
->modifiers
& up_modifier
)
4772 /* If we did not see a down before this up,
4773 ignore the up. Probably this happened because
4774 the down event chose a menu item.
4775 It would be an annoyance to treat the release
4776 of the button that chose the menu item
4777 as a separate event. */
4779 if (!CONSP (start_pos
))
4782 event
->modifiers
&= ~up_modifier
;
4783 #if 0 /* Formerly we treated an up with no down as a click event. */
4784 if (!CONSP (start_pos
))
4785 event
->modifiers
|= click_modifier
;
4789 /* The third element of every position should be the (x,y)
4793 down
= Fnth (make_number (2), start_pos
);
4794 if (EQ (event
->x
, XCAR (down
))
4795 && EQ (event
->y
, XCDR (down
)))
4797 event
->modifiers
|= click_modifier
;
4801 button_down_time
= 0;
4802 event
->modifiers
|= drag_modifier
;
4804 /* Don't check is_double; treat this as multiple
4805 if the down-event was multiple. */
4806 if (double_click_count
> 1)
4807 event
->modifiers
|= ((double_click_count
> 2)
4813 /* Every mouse event should either have the down_modifier or
4814 the up_modifier set. */
4818 /* Get the symbol we should use for the mouse click. */
4821 head
= modify_event_symbol (button
,
4823 Qmouse_click
, Vlispy_mouse_stem
,
4826 XVECTOR (mouse_syms
)->size
);
4827 if (event
->modifiers
& drag_modifier
)
4832 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
4835 Fcons (make_number (double_click_count
),
4844 #if USE_TOOLKIT_SCROLL_BARS
4846 /* We don't have down and up events if using toolkit scroll bars,
4847 so make this always a click event. Store in the `part' of
4848 the Lisp event a symbol which maps to the following actions:
4850 `above_handle' page up
4851 `below_handle' page down
4855 `bottom' bottom of buffer
4856 `handle' thumb has been dragged.
4857 `end-scroll' end of interaction with scroll bar
4859 The incoming input_event contains in its `part' member an
4860 index of type `enum scroll_bar_part' which we can use as an
4861 index in scroll_bar_parts to get the appropriate symbol. */
4863 case scroll_bar_click
:
4865 Lisp_Object position
, head
, window
, portion_whole
, part
;
4867 window
= event
->frame_or_window
;
4868 portion_whole
= Fcons (event
->x
, event
->y
);
4869 part
= *scroll_bar_parts
[(int) event
->part
];
4873 Fcons (Qvertical_scroll_bar
,
4874 Fcons (portion_whole
,
4875 Fcons (make_number (event
->timestamp
),
4876 Fcons (part
, Qnil
)))));
4878 /* Always treat scroll bar events as clicks. */
4879 event
->modifiers
|= click_modifier
;
4881 /* Get the symbol we should use for the mouse click. */
4882 head
= modify_event_symbol (event
->code
,
4887 XVECTOR (mouse_syms
)->size
);
4888 return Fcons (head
, Fcons (position
, Qnil
));
4891 #endif /* USE_TOOLKIT_SCROLL_BARS */
4894 case w32_scroll_bar_click
:
4896 int button
= event
->code
;
4898 Lisp_Object position
;
4899 Lisp_Object
*start_pos_ptr
;
4900 Lisp_Object start_pos
;
4904 Lisp_Object portion_whole
;
4907 window
= event
->frame_or_window
;
4908 portion_whole
= Fcons (event
->x
, event
->y
);
4909 part
= *scroll_bar_parts
[(int) event
->part
];
4913 Fcons (Qvertical_scroll_bar
,
4914 Fcons (portion_whole
,
4915 Fcons (make_number (event
->timestamp
),
4916 Fcons (part
, Qnil
)))));
4919 /* Always treat W32 scroll bar events as clicks. */
4920 event
->modifiers
|= click_modifier
;
4923 /* Get the symbol we should use for the mouse click. */
4926 head
= modify_event_symbol (button
,
4931 XVECTOR (mouse_syms
)->size
);
4940 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
4943 Lisp_Object head
, position
;
4946 /* Ignore mouse events that were made on frame that
4947 have been deleted. */
4948 if (! FRAME_LIVE_P (f
))
4950 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4951 &column
, &row
, NULL
, 1);
4952 window
= window_from_coordinates (f
, column
, row
, &part
, 0);
4954 if (!WINDOWP (window
))
4956 window
= event
->frame_or_window
;
4961 int pixcolumn
, pixrow
;
4962 column
-= XINT (XWINDOW (window
)->left
);
4963 row
-= XINT (XWINDOW (window
)->top
);
4964 glyph_to_pixel_coords (XWINDOW(window
), column
, row
,
4965 &pixcolumn
, &pixrow
);
4966 XSETINT (event
->x
, pixcolumn
);
4967 XSETINT (event
->y
, pixrow
);
4972 posn
= Qvertical_line
;
4974 posn
= Qheader_line
;
4977 buffer_posn_from_coords (XWINDOW (window
),
4982 Lisp_Object head
, position
;
4987 Fcons (Fcons (event
->x
, event
->y
),
4988 Fcons (make_number (event
->timestamp
),
4991 head
= modify_event_symbol (0, event
->modifiers
,
4993 lispy_mouse_wheel_names
,
4994 &mouse_wheel_syms
, 1);
4997 Fcons (make_number (event
->code
),
5001 #endif /* WINDOWSNT */
5012 /* The frame_or_window field should be a cons of the frame in
5013 which the event occurred and a list of the filenames
5015 if (! CONSP (event
->frame_or_window
))
5018 f
= XFRAME (XCAR (event
->frame_or_window
));
5019 files
= XCDR (event
->frame_or_window
);
5021 /* Ignore mouse events that were made on frames that
5022 have been deleted. */
5023 if (! FRAME_LIVE_P (f
))
5025 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
5026 &column
, &row
, NULL
, 1);
5027 window
= window_from_coordinates (f
, column
, row
, &part
, 0);
5029 if (!WINDOWP (window
))
5031 window
= XCAR (event
->frame_or_window
);
5036 /* It's an event in window `window' at frame coordinates
5037 event->x/ event->y. */
5038 struct window
*w
= XWINDOW (window
);
5040 /* Get window relative coordinates. */
5041 int wx
= FRAME_TO_WINDOW_PIXEL_X (w
, XINT (event
->x
));
5042 int wy
= FRAME_TO_WINDOW_PIXEL_Y (w
, XINT (event
->y
));
5044 /* Set event coordinates to window-relative coordinates
5045 for constructing the Lisp event below. */
5046 XSETINT (event
->x
, wx
);
5047 XSETINT (event
->y
, wy
);
5052 posn
= Qvertical_line
;
5054 posn
= Qheader_line
;
5056 XSETINT (posn
, buffer_posn_from_coords (w
, &wx
, &wy
));
5060 Lisp_Object head
, position
;
5065 Fcons (Fcons (event
->x
, event
->y
),
5066 Fcons (make_number (event
->timestamp
),
5069 head
= modify_event_symbol (0, event
->modifiers
,
5071 lispy_drag_n_drop_names
,
5072 &drag_n_drop_syms
, 1);
5079 #endif /* HAVE_MOUSE */
5081 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
5082 case MENU_BAR_EVENT
:
5083 if (EQ (event
->arg
, event
->frame_or_window
))
5084 /* This is the prefix key. We translate this to
5085 `(menu_bar)' because the code in keyboard.c for menu
5086 events, which we use, relies on this. */
5087 return Fcons (Qmenu_bar
, Qnil
);
5091 case TOOL_BAR_EVENT
:
5092 if (EQ (event
->arg
, event
->frame_or_window
))
5093 /* This is the prefix key. We translate this to
5094 `(tool_bar)' because the code in keyboard.c for menu
5095 events, which we use, relies on this. */
5096 return Fcons (Qtool_bar
, Qnil
);
5097 else if (SYMBOLP (event
->arg
))
5098 return apply_modifiers (event
->modifiers
, event
->arg
);
5101 case USER_SIGNAL_EVENT
:
5102 /* A user signal. */
5103 return *lispy_user_signals
[event
->code
];
5105 /* The 'kind' field of the event is something we don't recognize. */
5114 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
5116 Lisp_Object bar_window
;
5117 enum scroll_bar_part part
;
5121 /* Is it a scroll bar movement? */
5122 if (frame
&& ! NILP (bar_window
))
5124 Lisp_Object part_sym
;
5126 part_sym
= *scroll_bar_parts
[(int) part
];
5127 return Fcons (Qscroll_bar_movement
,
5128 (Fcons (Fcons (bar_window
,
5129 Fcons (Qvertical_scroll_bar
,
5130 Fcons (Fcons (x
, y
),
5131 Fcons (make_number (time
),
5137 /* Or is it an ordinary mouse movement? */
5145 /* It's in a frame; which window on that frame? */
5146 window
= window_from_coordinates (frame
, XINT (x
), XINT (y
), &area
, 0);
5150 if (WINDOWP (window
))
5152 struct window
*w
= XWINDOW (window
);
5155 /* Get window relative coordinates. */
5156 wx
= FRAME_TO_WINDOW_PIXEL_X (w
, XINT (x
));
5157 wy
= FRAME_TO_WINDOW_PIXEL_Y (w
, XINT (y
));
5164 posn
= Qvertical_line
;
5166 posn
= Qheader_line
;
5168 XSETINT (posn
, buffer_posn_from_coords (w
, &wx
, &wy
));
5170 else if (frame
!= 0)
5172 XSETFRAME (window
, frame
);
5183 return Fcons (Qmouse_movement
,
5184 Fcons (Fcons (window
,
5186 Fcons (Fcons (x
, y
),
5187 Fcons (make_number (time
),
5193 #endif /* HAVE_MOUSE */
5195 /* Construct a switch frame event. */
5197 make_lispy_switch_frame (frame
)
5200 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
5203 /* Manipulating modifiers. */
5205 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
5207 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
5208 SYMBOL's name of the end of the modifiers; the string from this
5209 position is the unmodified symbol name.
5211 This doesn't use any caches. */
5214 parse_modifiers_uncached (symbol
, modifier_end
)
5218 struct Lisp_String
*name
;
5222 CHECK_SYMBOL (symbol
, 1);
5225 name
= XSYMBOL (symbol
)->name
;
5227 for (i
= 0; i
+2 <= STRING_BYTES (name
); )
5229 int this_mod_end
= 0;
5232 /* See if the name continues with a modifier word.
5233 Check that the word appears, but don't check what follows it.
5234 Set this_mod and this_mod_end to record what we find. */
5236 switch (name
->data
[i
])
5238 #define SINGLE_LETTER_MOD(BIT) \
5239 (this_mod_end = i + 1, this_mod = BIT)
5242 SINGLE_LETTER_MOD (alt_modifier
);
5246 SINGLE_LETTER_MOD (ctrl_modifier
);
5250 SINGLE_LETTER_MOD (hyper_modifier
);
5254 SINGLE_LETTER_MOD (meta_modifier
);
5258 SINGLE_LETTER_MOD (shift_modifier
);
5262 SINGLE_LETTER_MOD (super_modifier
);
5265 #undef SINGLE_LETTER_MOD
5268 /* If we found no modifier, stop looking for them. */
5269 if (this_mod_end
== 0)
5272 /* Check there is a dash after the modifier, so that it
5273 really is a modifier. */
5274 if (this_mod_end
>= STRING_BYTES (name
)
5275 || name
->data
[this_mod_end
] != '-')
5278 /* This modifier is real; look for another. */
5279 modifiers
|= this_mod
;
5280 i
= this_mod_end
+ 1;
5283 /* Should we include the `click' modifier? */
5284 if (! (modifiers
& (down_modifier
| drag_modifier
5285 | double_modifier
| triple_modifier
))
5286 && i
+ 7 == STRING_BYTES (name
)
5287 && strncmp (name
->data
+ i
, "mouse-", 6) == 0
5288 && ('0' <= name
->data
[i
+ 6] && name
->data
[i
+ 6] <= '9'))
5289 modifiers
|= click_modifier
;
5297 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
5298 prepended to the string BASE[0..BASE_LEN-1].
5299 This doesn't use any caches. */
5301 apply_modifiers_uncached (modifiers
, base
, base_len
, base_len_byte
)
5304 int base_len
, base_len_byte
;
5306 /* Since BASE could contain nulls, we can't use intern here; we have
5307 to use Fintern, which expects a genuine Lisp_String, and keeps a
5310 = (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
5316 /* Only the event queue may use the `up' modifier; it should always
5317 be turned into a click or drag event before presented to lisp code. */
5318 if (modifiers
& up_modifier
)
5321 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
5322 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
5323 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
5324 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
5325 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
5326 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
5327 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
5328 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
5329 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
5330 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
5331 /* The click modifier is denoted by the absence of other modifiers. */
5335 mod_len
= p
- new_mods
;
5339 Lisp_Object new_name
;
5341 new_name
= make_uninit_multibyte_string (mod_len
+ base_len
,
5342 mod_len
+ base_len_byte
);
5343 bcopy (new_mods
, XSTRING (new_name
)->data
, mod_len
);
5344 bcopy (base
, XSTRING (new_name
)->data
+ mod_len
, base_len_byte
);
5346 return Fintern (new_name
, Qnil
);
5351 static char *modifier_names
[] =
5353 "up", "down", "drag", "click", "double", "triple", 0, 0,
5354 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5355 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
5357 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
5359 static Lisp_Object modifier_symbols
;
5361 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
5363 lispy_modifier_list (modifiers
)
5366 Lisp_Object modifier_list
;
5369 modifier_list
= Qnil
;
5370 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
5371 if (modifiers
& (1<<i
))
5372 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
5375 return modifier_list
;
5379 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
5380 where UNMODIFIED is the unmodified form of SYMBOL,
5381 MASK is the set of modifiers present in SYMBOL's name.
5382 This is similar to parse_modifiers_uncached, but uses the cache in
5383 SYMBOL's Qevent_symbol_element_mask property, and maintains the
5384 Qevent_symbol_elements property. */
5387 parse_modifiers (symbol
)
5390 Lisp_Object elements
;
5392 elements
= Fget (symbol
, Qevent_symbol_element_mask
);
5393 if (CONSP (elements
))
5398 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
5399 Lisp_Object unmodified
;
5402 unmodified
= Fintern (make_string (XSYMBOL (symbol
)->name
->data
+ end
,
5403 STRING_BYTES (XSYMBOL (symbol
)->name
) - end
),
5406 if (modifiers
& ~(((EMACS_INT
)1 << VALBITS
) - 1))
5408 XSETFASTINT (mask
, modifiers
);
5409 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
5411 /* Cache the parsing results on SYMBOL. */
5412 Fput (symbol
, Qevent_symbol_element_mask
,
5414 Fput (symbol
, Qevent_symbol_elements
,
5415 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
5417 /* Since we know that SYMBOL is modifiers applied to unmodified,
5418 it would be nice to put that in unmodified's cache.
5419 But we can't, since we're not sure that parse_modifiers is
5426 /* Apply the modifiers MODIFIERS to the symbol BASE.
5427 BASE must be unmodified.
5429 This is like apply_modifiers_uncached, but uses BASE's
5430 Qmodifier_cache property, if present. It also builds
5431 Qevent_symbol_elements properties, since it has that info anyway.
5433 apply_modifiers copies the value of BASE's Qevent_kind property to
5434 the modified symbol. */
5436 apply_modifiers (modifiers
, base
)
5440 Lisp_Object cache
, index
, entry
, new_symbol
;
5442 /* Mask out upper bits. We don't know where this value's been. */
5443 modifiers
&= ((EMACS_INT
)1 << VALBITS
) - 1;
5445 /* The click modifier never figures into cache indices. */
5446 cache
= Fget (base
, Qmodifier_cache
);
5447 XSETFASTINT (index
, (modifiers
& ~click_modifier
));
5448 entry
= assq_no_quit (index
, cache
);
5451 new_symbol
= XCDR (entry
);
5454 /* We have to create the symbol ourselves. */
5455 new_symbol
= apply_modifiers_uncached (modifiers
,
5456 XSYMBOL (base
)->name
->data
,
5457 XSYMBOL (base
)->name
->size
,
5458 STRING_BYTES (XSYMBOL (base
)->name
));
5460 /* Add the new symbol to the base's cache. */
5461 entry
= Fcons (index
, new_symbol
);
5462 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
5464 /* We have the parsing info now for free, so add it to the caches. */
5465 XSETFASTINT (index
, modifiers
);
5466 Fput (new_symbol
, Qevent_symbol_element_mask
,
5467 Fcons (base
, Fcons (index
, Qnil
)));
5468 Fput (new_symbol
, Qevent_symbol_elements
,
5469 Fcons (base
, lispy_modifier_list (modifiers
)));
5472 /* Make sure this symbol is of the same kind as BASE.
5474 You'd think we could just set this once and for all when we
5475 intern the symbol above, but reorder_modifiers may call us when
5476 BASE's property isn't set right; we can't assume that just
5477 because it has a Qmodifier_cache property it must have its
5478 Qevent_kind set right as well. */
5479 if (NILP (Fget (new_symbol
, Qevent_kind
)))
5483 kind
= Fget (base
, Qevent_kind
);
5485 Fput (new_symbol
, Qevent_kind
, kind
);
5492 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
5493 return a symbol with the modifiers placed in the canonical order.
5494 Canonical order is alphabetical, except for down and drag, which
5495 always come last. The 'click' modifier is never written out.
5497 Fdefine_key calls this to make sure that (for example) C-M-foo
5498 and M-C-foo end up being equivalent in the keymap. */
5501 reorder_modifiers (symbol
)
5504 /* It's hopefully okay to write the code this way, since everything
5505 will soon be in caches, and no consing will be done at all. */
5508 parsed
= parse_modifiers (symbol
);
5509 return apply_modifiers ((int) XINT (XCAR (XCDR (parsed
))),
5514 /* For handling events, we often want to produce a symbol whose name
5515 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
5516 to some base, like the name of a function key or mouse button.
5517 modify_event_symbol produces symbols of this sort.
5519 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
5520 is the name of the i'th symbol. TABLE_SIZE is the number of elements
5523 Alternatively, NAME_ALIST_OR_STEM is either an alist mapping codes
5524 into symbol names, or a string specifying a name stem used to
5525 construct a symbol name or the form `STEM-N', where N is the decimal
5526 representation of SYMBOL_NUM. NAME_ALIST_OR_STEM is used if it is
5527 non-nil; otherwise NAME_TABLE is used.
5529 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
5530 persist between calls to modify_event_symbol that it can use to
5531 store a cache of the symbols it's generated for this NAME_TABLE
5532 before. The object stored there may be a vector or an alist.
5534 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
5536 MODIFIERS is a set of modifier bits (as given in struct input_events)
5537 whose prefixes should be applied to the symbol name.
5539 SYMBOL_KIND is the value to be placed in the event_kind property of
5540 the returned symbol.
5542 The symbols we create are supposed to have an
5543 `event-symbol-elements' property, which lists the modifiers present
5544 in the symbol's name. */
5547 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_alist_or_stem
,
5548 name_table
, symbol_table
, table_size
)
5551 Lisp_Object symbol_kind
;
5552 Lisp_Object name_alist_or_stem
;
5554 Lisp_Object
*symbol_table
;
5555 unsigned int table_size
;
5558 Lisp_Object symbol_int
;
5560 /* Get rid of the "vendor-specific" bit here. */
5561 XSETINT (symbol_int
, symbol_num
& 0xffffff);
5563 /* Is this a request for a valid symbol? */
5564 if (symbol_num
< 0 || symbol_num
>= table_size
)
5567 if (CONSP (*symbol_table
))
5568 value
= Fcdr (assq_no_quit (symbol_int
, *symbol_table
));
5570 /* If *symbol_table doesn't seem to be initialized properly, fix that.
5571 *symbol_table should be a lisp vector TABLE_SIZE elements long,
5572 where the Nth element is the symbol for NAME_TABLE[N], or nil if
5573 we've never used that symbol before. */
5576 if (! VECTORP (*symbol_table
)
5577 || XVECTOR (*symbol_table
)->size
!= table_size
)
5581 XSETFASTINT (size
, table_size
);
5582 *symbol_table
= Fmake_vector (size
, Qnil
);
5585 value
= XVECTOR (*symbol_table
)->contents
[symbol_num
];
5588 /* Have we already used this symbol before? */
5591 /* No; let's create it. */
5592 if (CONSP (name_alist_or_stem
))
5593 value
= Fcdr_safe (Fassq (symbol_int
, name_alist_or_stem
));
5594 else if (STRINGP (name_alist_or_stem
))
5596 int len
= STRING_BYTES (XSTRING (name_alist_or_stem
));
5597 char *buf
= (char *) alloca (len
+ 50);
5598 sprintf (buf
, "%s-%d", XSTRING (name_alist_or_stem
)->data
,
5599 XINT (symbol_int
) + 1);
5600 value
= intern (buf
);
5602 else if (name_table
!= 0 && name_table
[symbol_num
])
5603 value
= intern (name_table
[symbol_num
]);
5605 #ifdef HAVE_WINDOW_SYSTEM
5608 char *name
= x_get_keysym_name (symbol_num
);
5610 value
= intern (name
);
5617 sprintf (buf
, "key-%d", symbol_num
);
5618 value
= intern (buf
);
5621 if (CONSP (*symbol_table
))
5622 *symbol_table
= Fcons (Fcons (symbol_int
, value
), *symbol_table
);
5624 XVECTOR (*symbol_table
)->contents
[symbol_num
] = value
;
5626 /* Fill in the cache entries for this symbol; this also
5627 builds the Qevent_symbol_elements property, which the user
5629 apply_modifiers (modifiers
& click_modifier
, value
);
5630 Fput (value
, Qevent_kind
, symbol_kind
);
5633 /* Apply modifiers to that symbol. */
5634 return apply_modifiers (modifiers
, value
);
5637 /* Convert a list that represents an event type,
5638 such as (ctrl meta backspace), into the usual representation of that
5639 event type as a number or a symbol. */
5641 DEFUN ("event-convert-list", Fevent_convert_list
, Sevent_convert_list
, 1, 1, 0,
5642 "Convert the event description list EVENT-DESC to an event type.\n\
5643 EVENT-DESC should contain one base event type (a character or symbol)\n\
5644 and zero or more modifier names (control, meta, hyper, super, shift, alt,\n\
5645 drag, down, double or triple). The base must be last.\n\
5646 The return value is an event type (a character or symbol) which\n\
5647 has the same base event type and all the specified modifiers.")
5649 Lisp_Object event_desc
;
5657 while (CONSP (rest
))
5665 /* Given a symbol, see if it is a modifier name. */
5666 if (SYMBOLP (elt
) && CONSP (rest
))
5667 this = parse_solitary_modifier (elt
);
5671 else if (!NILP (base
))
5672 error ("Two bases given in one event");
5678 /* Let the symbol A refer to the character A. */
5679 if (SYMBOLP (base
) && XSYMBOL (base
)->name
->size
== 1)
5680 XSETINT (base
, XSYMBOL (base
)->name
->data
[0]);
5682 if (INTEGERP (base
))
5684 /* Turn (shift a) into A. */
5685 if ((modifiers
& shift_modifier
) != 0
5686 && (XINT (base
) >= 'a' && XINT (base
) <= 'z'))
5688 XSETINT (base
, XINT (base
) - ('a' - 'A'));
5689 modifiers
&= ~shift_modifier
;
5692 /* Turn (control a) into C-a. */
5693 if (modifiers
& ctrl_modifier
)
5694 return make_number ((modifiers
& ~ctrl_modifier
)
5695 | make_ctrl_char (XINT (base
)));
5697 return make_number (modifiers
| XINT (base
));
5699 else if (SYMBOLP (base
))
5700 return apply_modifiers (modifiers
, base
);
5703 error ("Invalid base event");
5708 /* Try to recognize SYMBOL as a modifier name.
5709 Return the modifier flag bit, or 0 if not recognized. */
5712 parse_solitary_modifier (symbol
)
5715 struct Lisp_String
*name
= XSYMBOL (symbol
)->name
;
5717 switch (name
->data
[0])
5719 #define SINGLE_LETTER_MOD(BIT) \
5720 if (STRING_BYTES (name) == 1) \
5723 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
5724 if (LEN == STRING_BYTES (name) \
5725 && ! strncmp (name->data, NAME, LEN)) \
5729 SINGLE_LETTER_MOD (alt_modifier
);
5733 MULTI_LETTER_MOD (alt_modifier
, "alt", 3);
5737 SINGLE_LETTER_MOD (ctrl_modifier
);
5741 MULTI_LETTER_MOD (ctrl_modifier
, "ctrl", 4);
5742 MULTI_LETTER_MOD (ctrl_modifier
, "control", 7);
5746 SINGLE_LETTER_MOD (hyper_modifier
);
5750 MULTI_LETTER_MOD (hyper_modifier
, "hyper", 5);
5754 SINGLE_LETTER_MOD (meta_modifier
);
5758 MULTI_LETTER_MOD (meta_modifier
, "meta", 4);
5762 SINGLE_LETTER_MOD (shift_modifier
);
5766 MULTI_LETTER_MOD (shift_modifier
, "shift", 5);
5767 MULTI_LETTER_MOD (super_modifier
, "super", 5);
5768 SINGLE_LETTER_MOD (super_modifier
);
5772 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
5773 MULTI_LETTER_MOD (down_modifier
, "down", 4);
5774 MULTI_LETTER_MOD (double_modifier
, "double", 6);
5778 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
5781 #undef SINGLE_LETTER_MOD
5782 #undef MULTI_LETTER_MOD
5788 /* Return 1 if EVENT is a list whose elements are all integers or symbols.
5789 Such a list is not valid as an event,
5790 but it can be a Lucid-style event type list. */
5793 lucid_event_type_list_p (object
)
5798 if (! CONSP (object
))
5801 for (tail
= object
; CONSP (tail
); tail
= XCDR (tail
))
5805 if (! (INTEGERP (elt
) || SYMBOLP (elt
)))
5812 /* Store into *addr a value nonzero if terminal input chars are available.
5813 Serves the purpose of ioctl (0, FIONREAD, addr)
5814 but works even if FIONREAD does not exist.
5815 (In fact, this may actually read some input.)
5817 If DO_TIMERS_NOW is nonzero, actually run timer events that are ripe. */
5820 get_input_pending (addr
, do_timers_now
)
5824 /* First of all, have we already counted some input? */
5825 *addr
= !NILP (Vquit_flag
) || readable_events (do_timers_now
);
5827 /* If input is being read as it arrives, and we have none, there is none. */
5828 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
5831 /* Try to read some input and see how much we get. */
5833 *addr
= !NILP (Vquit_flag
) || readable_events (do_timers_now
);
5836 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
5839 gobble_input (expected
)
5844 if (interrupt_input
)
5847 mask
= sigblock (sigmask (SIGIO
));
5848 read_avail_input (expected
);
5852 #ifdef POLL_FOR_INPUT
5853 if (read_socket_hook
&& !interrupt_input
&& poll_suppress_count
== 0)
5856 mask
= sigblock (sigmask (SIGALRM
));
5857 read_avail_input (expected
);
5863 read_avail_input (expected
);
5867 /* Put a buffer_switch_event in the buffer
5868 so that read_key_sequence will notice the new current buffer. */
5871 record_asynch_buffer_change ()
5873 struct input_event event
;
5876 event
.kind
= buffer_switch_event
;
5877 event
.frame_or_window
= Qnil
;
5881 /* We don't need a buffer-switch event unless Emacs is waiting for input.
5882 The purpose of the event is to make read_key_sequence look up the
5883 keymaps again. If we aren't in read_key_sequence, we don't need one,
5884 and the event could cause trouble by messing up (input-pending-p). */
5885 tem
= Fwaiting_for_user_input_p ();
5889 /* We never need these events if we have no asynchronous subprocesses. */
5893 /* Make sure no interrupt happens while storing the event. */
5895 if (interrupt_input
)
5898 mask
= sigblock (sigmask (SIGIO
));
5899 kbd_buffer_store_event (&event
);
5906 kbd_buffer_store_event (&event
);
5913 /* Read any terminal input already buffered up by the system
5914 into the kbd_buffer, but do not wait.
5916 EXPECTED should be nonzero if the caller knows there is some input.
5918 Except on VMS, all input is read by this function.
5919 If interrupt_input is nonzero, this function MUST be called
5920 only when SIGIO is blocked.
5922 Returns the number of keyboard chars read, or -1 meaning
5923 this is a bad time to try to read input. */
5926 read_avail_input (expected
)
5929 struct input_event buf
[KBD_BUFFER_SIZE
];
5933 if (read_socket_hook
)
5934 /* No need for FIONREAD or fcntl; just say don't wait. */
5935 nread
= (*read_socket_hook
) (input_fd
, buf
, KBD_BUFFER_SIZE
, expected
);
5938 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
5939 the kbd_buffer can really hold. That may prevent loss
5940 of characters on some systems when input is stuffed at us. */
5941 unsigned char cbuf
[KBD_BUFFER_SIZE
- 1];
5944 /* Determine how many characters we should *try* to read. */
5947 #else /* not WINDOWSNT */
5949 n_to_read
= dos_keysns ();
5952 #else /* not MSDOS */
5954 /* Find out how much input is available. */
5955 if (ioctl (input_fd
, FIONREAD
, &n_to_read
) < 0)
5956 /* Formerly simply reported no input, but that sometimes led to
5957 a failure of Emacs to terminate.
5958 SIGHUP seems appropriate if we can't reach the terminal. */
5959 /* ??? Is it really right to send the signal just to this process
5960 rather than to the whole process group?
5961 Perhaps on systems with FIONREAD Emacs is alone in its group. */
5962 kill (getpid (), SIGHUP
);
5965 if (n_to_read
> sizeof cbuf
)
5966 n_to_read
= sizeof cbuf
;
5967 #else /* no FIONREAD */
5968 #if defined (USG) || defined (DGUX)
5969 /* Read some input if available, but don't wait. */
5970 n_to_read
= sizeof cbuf
;
5971 fcntl (input_fd
, F_SETFL
, O_NDELAY
);
5976 #endif /* not MSDOS */
5977 #endif /* not WINDOWSNT */
5979 /* Now read; for one reason or another, this will not block.
5980 NREAD is set to the number of chars read. */
5984 cbuf
[0] = dos_keyread ();
5987 nread
= emacs_read (input_fd
, cbuf
, n_to_read
);
5989 /* POSIX infers that processes which are not in the session leader's
5990 process group won't get SIGHUP's at logout time. BSDI adheres to
5991 this part standard and returns -1 from read (0) with errno==EIO
5992 when the control tty is taken away.
5993 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
5994 if (nread
== -1 && errno
== EIO
)
5996 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
5997 /* The kernel sometimes fails to deliver SIGHUP for ptys.
5998 This looks incorrect, but it isn't, because _BSD causes
5999 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
6000 and that causes a value other than 0 when there is no input. */
6006 /* We used to retry the read if it was interrupted.
6007 But this does the wrong thing when O_NDELAY causes
6008 an EAGAIN error. Does anybody know of a situation
6009 where a retry is actually needed? */
6011 nread
< 0 && (errno
== EAGAIN
6025 #if defined (USG) || defined (DGUX)
6026 fcntl (input_fd
, F_SETFL
, 0);
6027 #endif /* USG or DGUX */
6028 #endif /* no FIONREAD */
6029 for (i
= 0; i
< nread
; i
++)
6031 buf
[i
].kind
= ascii_keystroke
;
6032 buf
[i
].modifiers
= 0;
6033 if (meta_key
== 1 && (cbuf
[i
] & 0x80))
6034 buf
[i
].modifiers
= meta_modifier
;
6038 buf
[i
].code
= cbuf
[i
];
6039 buf
[i
].frame_or_window
= selected_frame
;
6044 /* Scan the chars for C-g and store them in kbd_buffer. */
6045 for (i
= 0; i
< nread
; i
++)
6047 kbd_buffer_store_event (&buf
[i
]);
6048 /* Don't look at input that follows a C-g too closely.
6049 This reduces lossage due to autorepeat on C-g. */
6050 if (buf
[i
].kind
== ascii_keystroke
6051 && buf
[i
].code
== quit_char
)
6057 #endif /* not VMS */
6059 #ifdef SIGIO /* for entire page */
6060 /* Note SIGIO has been undef'd if FIONREAD is missing. */
6063 input_available_signal (signo
)
6066 /* Must preserve main program's value of errno. */
6067 int old_errno
= errno
;
6069 extern int select_alarmed
;
6072 #if defined (USG) && !defined (POSIX_SIGNALS)
6073 /* USG systems forget handlers when they are used;
6074 must reestablish each time */
6075 signal (signo
, input_available_signal
);
6082 if (input_available_clear_time
)
6083 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
6088 nread
= read_avail_input (1);
6089 /* -1 means it's not ok to read the input now.
6090 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
6091 0 means there was no keyboard input available. */
6096 select_alarmed
= 1; /* Force the select emulator back to life */
6107 /* Send ourselves a SIGIO.
6109 This function exists so that the UNBLOCK_INPUT macro in
6110 blockinput.h can have some way to take care of input we put off
6111 dealing with, without assuming that every file which uses
6112 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
6114 reinvoke_input_signal ()
6117 kill (getpid (), SIGIO
);
6123 /* Return the prompt-string of a sparse keymap.
6124 This is the first element which is a string.
6125 Return nil if there is none. */
6133 register Lisp_Object tem
;
6142 static void menu_bar_item ();
6143 static void menu_bar_one_keymap ();
6145 /* These variables hold the vector under construction within
6146 menu_bar_items and its subroutines, and the current index
6147 for storing into that vector. */
6148 static Lisp_Object menu_bar_items_vector
;
6149 static int menu_bar_items_index
;
6151 /* Return a vector of menu items for a menu bar, appropriate
6152 to the current buffer. Each item has three elements in the vector:
6155 OLD is an old vector we can optionally reuse, or nil. */
6158 menu_bar_items (old
)
6161 /* The number of keymaps we're scanning right now, and the number of
6162 keymaps we have allocated space for. */
6165 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
6166 in the current keymaps, or nil where it is not a prefix. */
6169 Lisp_Object def
, tem
, tail
;
6178 struct gcpro gcpro1
;
6180 /* In order to build the menus, we need to call the keymap
6181 accessors. They all call QUIT. But this function is called
6182 during redisplay, during which a quit is fatal. So inhibit
6183 quitting while building the menus.
6184 We do this instead of specbind because (1) errors will clear it anyway
6185 and (2) this avoids risk of specpdl overflow. */
6186 oquit
= Vinhibit_quit
;
6190 menu_bar_items_vector
= old
;
6192 menu_bar_items_vector
= Fmake_vector (make_number (24), Qnil
);
6193 menu_bar_items_index
= 0;
6195 GCPRO1 (menu_bar_items_vector
);
6197 /* Build our list of keymaps.
6198 If we recognize a function key and replace its escape sequence in
6199 keybuf with its symbol, or if the sequence starts with a mouse
6200 click and we need to switch buffers, we jump back here to rebuild
6201 the initial keymaps from the current buffer. */
6205 /* Should overriding-terminal-local-map and overriding-local-map apply? */
6206 if (!NILP (Voverriding_local_map_menu_flag
))
6208 /* Yes, use them (if non-nil) as well as the global map. */
6209 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
6211 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
6212 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
6213 if (!NILP (Voverriding_local_map
))
6214 maps
[nmaps
++] = Voverriding_local_map
;
6218 /* No, so use major and minor mode keymaps and keymap property. */
6220 Lisp_Object map
= get_local_map (PT
, current_buffer
, keymap
);
6223 nmaps
= current_minor_maps (NULL
, &tmaps
);
6224 maps
= (Lisp_Object
*) alloca ((nmaps
+ extra_maps
)
6225 * sizeof (maps
[0]));
6226 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
6228 maps
[nmaps
++] = map
;
6229 maps
[nmaps
++] = get_local_map (PT
, current_buffer
, local_map
);
6231 maps
[nmaps
++] = current_global_map
;
6234 /* Look up in each map the dummy prefix key `menu-bar'. */
6238 for (mapno
= nmaps
- 1; mapno
>= 0; mapno
--)
6240 if (! NILP (maps
[mapno
]))
6241 def
= get_keyelt (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0), 0);
6245 tem
= Fkeymapp (def
);
6247 menu_bar_one_keymap (def
);
6250 /* Move to the end those items that should be at the end. */
6252 for (tail
= Vmenu_bar_final_items
; CONSP (tail
); tail
= XCDR (tail
))
6255 int end
= menu_bar_items_index
;
6257 for (i
= 0; i
< end
; i
+= 4)
6258 if (EQ (XCAR (tail
), XVECTOR (menu_bar_items_vector
)->contents
[i
]))
6260 Lisp_Object tem0
, tem1
, tem2
, tem3
;
6261 /* Move the item at index I to the end,
6262 shifting all the others forward. */
6263 tem0
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 0];
6264 tem1
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 1];
6265 tem2
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
6266 tem3
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3];
6268 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
6269 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
6270 (end
- i
- 4) * sizeof (Lisp_Object
));
6271 XVECTOR (menu_bar_items_vector
)->contents
[end
- 4] = tem0
;
6272 XVECTOR (menu_bar_items_vector
)->contents
[end
- 3] = tem1
;
6273 XVECTOR (menu_bar_items_vector
)->contents
[end
- 2] = tem2
;
6274 XVECTOR (menu_bar_items_vector
)->contents
[end
- 1] = tem3
;
6279 /* Add nil, nil, nil, nil at the end. */
6280 i
= menu_bar_items_index
;
6281 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
6284 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
6285 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
6286 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
6287 menu_bar_items_vector
= tem
;
6289 /* Add this item. */
6290 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
6291 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
6292 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
6293 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
6294 menu_bar_items_index
= i
;
6296 Vinhibit_quit
= oquit
;
6298 return menu_bar_items_vector
;
6301 /* Scan one map KEYMAP, accumulating any menu items it defines
6302 in menu_bar_items_vector. */
6304 static Lisp_Object menu_bar_one_keymap_changed_items
;
6307 menu_bar_one_keymap (keymap
)
6310 Lisp_Object tail
, item
;
6312 menu_bar_one_keymap_changed_items
= Qnil
;
6314 /* Loop over all keymap entries that have menu strings. */
6315 for (tail
= keymap
; CONSP (tail
); tail
= XCDR (tail
))
6319 menu_bar_item (XCAR (item
), XCDR (item
));
6320 else if (VECTORP (item
))
6322 /* Loop over the char values represented in the vector. */
6323 int len
= XVECTOR (item
)->size
;
6325 for (c
= 0; c
< len
; c
++)
6327 Lisp_Object character
;
6328 XSETFASTINT (character
, c
);
6329 menu_bar_item (character
, XVECTOR (item
)->contents
[c
]);
6335 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
6336 If there's already an item for KEY, add this DEF to it. */
6338 Lisp_Object item_properties
;
6341 menu_bar_item (key
, item
)
6342 Lisp_Object key
, item
;
6344 struct gcpro gcpro1
;
6348 if (EQ (item
, Qundefined
))
6350 /* If a map has an explicit `undefined' as definition,
6351 discard any previously made menu bar item. */
6353 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
6354 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
6356 if (menu_bar_items_index
> i
+ 4)
6357 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
6358 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
6359 (menu_bar_items_index
- i
- 4) * sizeof (Lisp_Object
));
6360 menu_bar_items_index
-= 4;
6364 /* If this keymap has already contributed to this KEY,
6365 don't contribute to it a second time. */
6366 tem
= Fmemq (key
, menu_bar_one_keymap_changed_items
);
6367 if (!NILP (tem
) || NILP (item
))
6370 menu_bar_one_keymap_changed_items
6371 = Fcons (key
, menu_bar_one_keymap_changed_items
);
6373 /* We add to menu_bar_one_keymap_changed_items before doing the
6374 parse_menu_item, so that if it turns out it wasn't a menu item,
6375 it still correctly hides any further menu item. */
6377 i
= parse_menu_item (item
, 0, 1);
6382 item
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
6384 /* Find any existing item for this KEY. */
6385 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
6386 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
6389 /* If we did not find this KEY, add it at the end. */
6390 if (i
== menu_bar_items_index
)
6392 /* If vector is too small, get a bigger one. */
6393 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
6396 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
6397 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
6398 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
6399 menu_bar_items_vector
= tem
;
6402 /* Add this item. */
6403 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = key
;
6404 XVECTOR (menu_bar_items_vector
)->contents
[i
++]
6405 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
6406 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Fcons (item
, Qnil
);
6407 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = make_number (0);
6408 menu_bar_items_index
= i
;
6410 /* We did find an item for this KEY. Add ITEM to its list of maps. */
6414 old
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
6415 XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2] = Fcons (item
, old
);
6419 /* This is used as the handler when calling menu_item_eval_property. */
6421 menu_item_eval_property_1 (arg
)
6424 /* If we got a quit from within the menu computation,
6425 quit all the way out of it. This takes care of C-] in the debugger. */
6426 if (CONSP (arg
) && EQ (XCAR (arg
), Qquit
))
6427 Fsignal (Qquit
, Qnil
);
6432 /* Evaluate an expression and return the result (or nil if something
6433 went wrong). Used to evaluate dynamic parts of menu items. */
6435 menu_item_eval_property (sexpr
)
6438 int count
= specpdl_ptr
- specpdl
;
6440 specbind (Qinhibit_redisplay
, Qt
);
6441 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
,
6442 menu_item_eval_property_1
);
6443 return unbind_to (count
, val
);
6446 /* This function parses a menu item and leaves the result in the
6447 vector item_properties.
6448 ITEM is a key binding, a possible menu item.
6449 If NOTREAL is nonzero, only check for equivalent key bindings, don't
6450 evaluate dynamic expressions in the menu item.
6451 INMENUBAR is > 0 when this is considered for an entry in a menu bar
6453 INMENUBAR is < 0 when this is considered for an entry in a keyboard menu.
6454 parse_menu_item returns true if the item is a menu item and false
6458 parse_menu_item (item
, notreal
, inmenubar
)
6460 int notreal
, inmenubar
;
6462 Lisp_Object def
, tem
, item_string
, start
;
6463 Lisp_Object cachelist
;
6465 Lisp_Object keyhint
;
6476 /* Create item_properties vector if necessary. */
6477 if (NILP (item_properties
))
6479 = Fmake_vector (make_number (ITEM_PROPERTY_ENABLE
+ 1), Qnil
);
6481 /* Initialize optional entries. */
6482 for (i
= ITEM_PROPERTY_DEF
; i
< ITEM_PROPERTY_ENABLE
; i
++)
6483 XVECTOR (item_properties
)->contents
[i
] = Qnil
;
6484 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
] = Qt
;
6486 /* Save the item here to protect it from GC. */
6487 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ITEM
] = item
;
6489 item_string
= XCAR (item
);
6493 if (STRINGP (item_string
))
6495 /* Old format menu item. */
6496 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
] = item_string
;
6498 /* Maybe help string. */
6499 if (CONSP (item
) && STRINGP (XCAR (item
)))
6501 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_HELP
]
6507 /* Maybe key binding cache. */
6508 if (CONSP (item
) && CONSP (XCAR (item
))
6509 && (NILP (XCAR (XCAR (item
)))
6510 || VECTORP (XCAR (XCAR (item
)))))
6512 cachelist
= XCAR (item
);
6516 /* This is the real definition--the function to run. */
6517 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
] = item
;
6519 /* Get enable property, if any. */
6522 tem
= Fget (item
, Qmenu_enable
);
6524 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
] = tem
;
6527 else if (EQ (item_string
, Qmenu_item
) && CONSP (item
))
6529 /* New format menu item. */
6530 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
]
6532 start
= XCDR (item
);
6535 /* We have a real binding. */
6536 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
]
6539 item
= XCDR (start
);
6540 /* Is there a cache list with key equivalences. */
6541 if (CONSP (item
) && CONSP (XCAR (item
)))
6543 cachelist
= XCAR (item
);
6547 /* Parse properties. */
6548 while (CONSP (item
) && CONSP (XCDR (item
)))
6553 if (EQ (tem
, QCenable
))
6554 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
]
6556 else if (EQ (tem
, QCvisible
) && !notreal
)
6558 /* If got a visible property and that evaluates to nil
6559 then ignore this item. */
6560 tem
= menu_item_eval_property (XCAR (item
));
6564 else if (EQ (tem
, QChelp
))
6565 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_HELP
]
6567 else if (EQ (tem
, QCfilter
))
6569 else if (EQ (tem
, QCkey_sequence
))
6572 if (NILP (cachelist
)
6573 && (SYMBOLP (tem
) || STRINGP (tem
) || VECTORP (tem
)))
6574 /* Be GC protected. Set keyhint to item instead of tem. */
6577 else if (EQ (tem
, QCkeys
))
6580 if (CONSP (tem
) || (STRINGP (tem
) && NILP (cachelist
)))
6581 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
]
6584 else if (EQ (tem
, QCbutton
) && CONSP (XCAR (item
)))
6589 if (EQ (type
, QCtoggle
) || EQ (type
, QCradio
))
6591 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
]
6593 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_TYPE
]
6600 else if (inmenubar
|| !NILP (start
))
6604 return 0; /* not a menu item */
6606 /* If item string is not a string, evaluate it to get string.
6607 If we don't get a string, skip this item. */
6608 item_string
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
6609 if (!(STRINGP (item_string
) || notreal
))
6611 item_string
= menu_item_eval_property (item_string
);
6612 if (!STRINGP (item_string
))
6614 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
] = item_string
;
6617 /* If got a filter apply it on definition. */
6618 def
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
6621 def
= menu_item_eval_property (list2 (XCAR (filter
),
6622 list2 (Qquote
, def
)));
6624 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
] = def
;
6627 /* If we got no definition, this item is just unselectable text which
6628 is OK in a submenu but not in the menubar. */
6630 return (inmenubar
? 0 : 1);
6632 /* Enable or disable selection of item. */
6633 tem
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
];
6639 tem
= menu_item_eval_property (tem
);
6640 if (inmenubar
&& NILP (tem
))
6641 return 0; /* Ignore disabled items in menu bar. */
6642 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
] = tem
;
6645 /* See if this is a separate pane or a submenu. */
6646 def
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
6647 tem
= get_keymap_1 (def
, 0, 1);
6648 /* For a subkeymap, just record its details and exit. */
6651 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_MAP
] = tem
;
6652 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
] = tem
;
6655 /* At the top level in the menu bar, do likewise for commands also.
6656 The menu bar does not display equivalent key bindings anyway.
6657 ITEM_PROPERTY_DEF is already set up properly. */
6661 /* This is a command. See if there is an equivalent key binding. */
6662 if (NILP (cachelist
))
6664 /* We have to create a cachelist. */
6665 CHECK_IMPURE (start
);
6666 XCDR (start
) = Fcons (Fcons (Qnil
, Qnil
), XCDR (start
));
6667 cachelist
= XCAR (XCDR (start
));
6669 tem
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
6670 if (!NILP (keyhint
))
6672 XCAR (cachelist
) = XCAR (keyhint
);
6675 else if (STRINGP (tem
))
6677 XCDR (cachelist
) = Fsubstitute_command_keys (tem
);
6678 XCAR (cachelist
) = Qt
;
6681 tem
= XCAR (cachelist
);
6688 tem
= Fkey_binding (tem
, Qnil
);
6690 prefix
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
6693 def
= XCAR (prefix
);
6694 prefix
= XCDR (prefix
);
6697 def
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
6699 if (NILP (XCAR (cachelist
))) /* Have no saved key. */
6701 if (newcache
/* Always check first time. */
6702 /* Should we check everything when precomputing key
6705 /* If something had no key binding before, don't recheck it
6706 because that is too slow--except if we have a list of
6707 rebound commands in Vdefine_key_rebound_commands, do
6708 recheck any command that appears in that list. */
6709 || (CONSP (Vdefine_key_rebound_commands
)
6710 && !NILP (Fmemq (def
, Vdefine_key_rebound_commands
))))
6713 /* We had a saved key. Is it still bound to the command? */
6716 /* If the command is an alias for another
6717 (such as lmenu.el set it up), check if the
6718 original command matches the cached command. */
6719 && !(SYMBOLP (def
) && EQ (tem
, XSYMBOL (def
)->function
))))
6720 chkcache
= 1; /* Need to recompute key binding. */
6724 /* Recompute equivalent key binding. If the command is an alias
6725 for another (such as lmenu.el set it up), see if the original
6726 command name has equivalent keys. Otherwise look up the
6727 specified command itself. We don't try both, because that
6728 makes lmenu menus slow. */
6729 if (SYMBOLP (def
) && SYMBOLP (XSYMBOL (def
)->function
)
6730 && ! NILP (Fget (def
, Qmenu_alias
)))
6731 def
= XSYMBOL (def
)->function
;
6732 tem
= Fwhere_is_internal (def
, Qnil
, Qt
, Qnil
);
6733 XCAR (cachelist
) = tem
;
6736 XCDR (cachelist
) = Qnil
;
6740 else if (!NILP (keyhint
) && !NILP (XCAR (cachelist
)))
6742 tem
= XCAR (cachelist
);
6746 newcache
= chkcache
;
6749 tem
= Fkey_description (tem
);
6752 if (STRINGP (XCAR (prefix
)))
6753 tem
= concat2 (XCAR (prefix
), tem
);
6754 if (STRINGP (XCDR (prefix
)))
6755 tem
= concat2 (tem
, XCDR (prefix
));
6757 XCDR (cachelist
) = tem
;
6761 tem
= XCDR (cachelist
);
6762 if (newcache
&& !NILP (tem
))
6764 tem
= concat3 (build_string (" ("), tem
, build_string (")"));
6765 XCDR (cachelist
) = tem
;
6768 /* If we only want to precompute equivalent key bindings, stop here. */
6772 /* If we have an equivalent key binding, use that. */
6773 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
] = tem
;
6775 /* Include this when menu help is implemented.
6776 tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP];
6777 if (!(NILP (tem) || STRINGP (tem)))
6779 tem = menu_item_eval_property (tem);
6782 XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP] = tem;
6786 /* Handle radio buttons or toggle boxes. */
6787 tem
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
];
6789 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
]
6790 = menu_item_eval_property (tem
);
6797 /***********************************************************************
6799 ***********************************************************************/
6801 /* A vector holding tool bar items while they are parsed in function
6802 tool_bar_items runs Each item occupies TOOL_BAR_ITEM_NSCLOTS elements
6805 static Lisp_Object tool_bar_items_vector
;
6807 /* A vector holding the result of parse_tool_bar_item. Layout is like
6808 the one for a single item in tool_bar_items_vector. */
6810 static Lisp_Object tool_bar_item_properties
;
6812 /* Next free index in tool_bar_items_vector. */
6814 static int ntool_bar_items
;
6816 /* The symbols `tool-bar', and `:image'. */
6818 extern Lisp_Object Qtool_bar
;
6819 Lisp_Object QCimage
;
6821 /* Function prototypes. */
6823 static void init_tool_bar_items
P_ ((Lisp_Object
));
6824 static void process_tool_bar_item
P_ ((Lisp_Object
, Lisp_Object
));
6825 static int parse_tool_bar_item
P_ ((Lisp_Object
, Lisp_Object
));
6826 static void append_tool_bar_item
P_ ((void));
6829 /* Return a vector of tool bar items for keymaps currently in effect.
6830 Reuse vector REUSE if non-nil. Return in *NITEMS the number of
6831 tool bar items found. */
6834 tool_bar_items (reuse
, nitems
)
6842 extern Lisp_Object Voverriding_local_map_menu_flag
;
6843 extern Lisp_Object Voverriding_local_map
;
6847 /* In order to build the menus, we need to call the keymap
6848 accessors. They all call QUIT. But this function is called
6849 during redisplay, during which a quit is fatal. So inhibit
6850 quitting while building the menus. We do this instead of
6851 specbind because (1) errors will clear it anyway and (2) this
6852 avoids risk of specpdl overflow. */
6853 oquit
= Vinhibit_quit
;
6856 /* Initialize tool_bar_items_vector and protect it from GC. */
6857 init_tool_bar_items (reuse
);
6859 /* Build list of keymaps in maps. Set nmaps to the number of maps
6862 /* Should overriding-terminal-local-map and overriding-local-map apply? */
6863 if (!NILP (Voverriding_local_map_menu_flag
))
6865 /* Yes, use them (if non-nil) as well as the global map. */
6866 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
6868 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
6869 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
6870 if (!NILP (Voverriding_local_map
))
6871 maps
[nmaps
++] = Voverriding_local_map
;
6875 /* No, so use major and minor mode keymaps and keymap property. */
6877 Lisp_Object map
= get_local_map (PT
, current_buffer
, keymap
);
6880 nmaps
= current_minor_maps (NULL
, &tmaps
);
6881 maps
= (Lisp_Object
*) alloca ((nmaps
+ extra_maps
)
6882 * sizeof (maps
[0]));
6883 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
6885 maps
[nmaps
++] = map
;
6886 maps
[nmaps
++] = get_local_map (PT
, current_buffer
, local_map
);
6889 /* Add global keymap at the end. */
6890 maps
[nmaps
++] = current_global_map
;
6892 /* Process maps in reverse order and look up in each map the prefix
6894 for (i
= nmaps
- 1; i
>= 0; --i
)
6895 if (!NILP (maps
[i
]))
6899 keymap
= get_keyelt (access_keymap (maps
[i
], Qtool_bar
, 1, 1), 0);
6900 if (!NILP (Fkeymapp (keymap
)))
6904 /* KEYMAP is a list `(keymap (KEY . BINDING) ...)'. */
6905 for (tail
= keymap
; CONSP (tail
); tail
= XCDR (tail
))
6907 Lisp_Object keydef
= XCAR (tail
);
6909 process_tool_bar_item (XCAR (keydef
), XCDR (keydef
));
6914 Vinhibit_quit
= oquit
;
6915 *nitems
= ntool_bar_items
/ TOOL_BAR_ITEM_NSLOTS
;
6916 return tool_bar_items_vector
;
6920 /* Process the definition of KEY which is DEF. */
6923 process_tool_bar_item (key
, def
)
6924 Lisp_Object key
, def
;
6927 extern Lisp_Object Qundefined
;
6928 struct gcpro gcpro1
, gcpro2
;
6930 /* Protect KEY and DEF from GC because parse_tool_bar_item may call
6934 if (EQ (def
, Qundefined
))
6936 /* If a map has an explicit `undefined' as definition,
6937 discard any previously made item. */
6938 for (i
= 0; i
< ntool_bar_items
; i
+= TOOL_BAR_ITEM_NSLOTS
)
6940 Lisp_Object
*v
= XVECTOR (tool_bar_items_vector
)->contents
+ i
;
6942 if (EQ (key
, v
[TOOL_BAR_ITEM_KEY
]))
6944 if (ntool_bar_items
> i
+ TOOL_BAR_ITEM_NSLOTS
)
6945 bcopy (v
+ TOOL_BAR_ITEM_NSLOTS
, v
,
6946 ((ntool_bar_items
- i
- TOOL_BAR_ITEM_NSLOTS
)
6947 * sizeof (Lisp_Object
)));
6948 ntool_bar_items
-= TOOL_BAR_ITEM_NSLOTS
;
6953 else if (parse_tool_bar_item (key
, def
))
6954 /* Append a new tool bar item to tool_bar_items_vector. Accept
6955 more than one definition for the same key. */
6956 append_tool_bar_item ();
6962 /* Parse a tool bar item specification ITEM for key KEY and return the
6963 result in tool_bar_item_properties. Value is zero if ITEM is
6966 ITEM is a list `(menu-item CAPTION BINDING PROPS...)'.
6968 CAPTION is the caption of the item, If it's not a string, it is
6969 evaluated to get a string.
6971 BINDING is the tool bar item's binding. Tool-bar items with keymaps
6972 as binding are currently ignored.
6974 The following properties are recognized:
6978 FORM is evaluated and specifies whether the tool bar item is
6979 enabled or disabled.
6983 FORM is evaluated and specifies whether the tool bar item is visible.
6985 - `:filter FUNCTION'
6987 FUNCTION is invoked with one parameter `(quote BINDING)'. Its
6988 result is stored as the new binding.
6990 - `:button (TYPE SELECTED)'
6992 TYPE must be one of `:radio' or `:toggle'. SELECTED is evaluated
6993 and specifies whether the button is selected (pressed) or not.
6997 IMAGES is either a single image specification or a vector of four
6998 image specifications. See enum tool_bar_item_images.
7000 - `:help HELP-STRING'.
7002 Gives a help string to display for the tool bar item. */
7005 parse_tool_bar_item (key
, item
)
7006 Lisp_Object key
, item
;
7008 /* Access slot with index IDX of vector tool_bar_item_properties. */
7009 #define PROP(IDX) XVECTOR (tool_bar_item_properties)->contents[IDX]
7011 Lisp_Object filter
= Qnil
;
7012 Lisp_Object caption
;
7013 extern Lisp_Object QCenable
, QCvisible
, QChelp
, QCfilter
;
7014 extern Lisp_Object QCbutton
, QCtoggle
, QCradio
;
7017 /* Defininition looks like `(menu-item CAPTION BINDING PROPS...)'.
7018 Rule out items that aren't lists, don't start with
7019 `menu-item' or whose rest following `tool-bar-item' is not a
7022 || !EQ (XCAR (item
), Qmenu_item
)
7023 || (item
= XCDR (item
),
7027 /* Create tool_bar_item_properties vector if necessary. Reset it to
7029 if (VECTORP (tool_bar_item_properties
))
7031 for (i
= 0; i
< TOOL_BAR_ITEM_NSLOTS
; ++i
)
7035 tool_bar_item_properties
7036 = Fmake_vector (make_number (TOOL_BAR_ITEM_NSLOTS
), Qnil
);
7039 PROP (TOOL_BAR_ITEM_KEY
) = key
;
7040 PROP (TOOL_BAR_ITEM_ENABLED_P
) = Qt
;
7042 /* Get the caption of the item. If the caption is not a string,
7043 evaluate it to get a string. If we don't get a string, skip this
7045 caption
= XCAR (item
);
7046 if (!STRINGP (caption
))
7048 caption
= menu_item_eval_property (caption
);
7049 if (!STRINGP (caption
))
7052 PROP (TOOL_BAR_ITEM_CAPTION
) = caption
;
7054 /* Give up if rest following the caption is not a list. */
7059 /* Store the binding. */
7060 PROP (TOOL_BAR_ITEM_BINDING
) = XCAR (item
);
7063 /* Ignore cached key binding, if any. */
7064 if (CONSP (item
) && CONSP (XCAR (item
)))
7067 /* Process the rest of the properties. */
7068 for (; CONSP (item
) && CONSP (XCDR (item
)); item
= XCDR (XCDR (item
)))
7070 Lisp_Object key
, value
;
7073 value
= XCAR (XCDR (item
));
7075 if (EQ (key
, QCenable
))
7076 /* `:enable FORM'. */
7077 PROP (TOOL_BAR_ITEM_ENABLED_P
) = value
;
7078 else if (EQ (key
, QCvisible
))
7080 /* `:visible FORM'. If got a visible property and that
7081 evaluates to nil then ignore this item. */
7082 if (NILP (menu_item_eval_property (value
)))
7085 else if (EQ (key
, QChelp
))
7086 /* `:help HELP-STRING'. */
7087 PROP (TOOL_BAR_ITEM_HELP
) = value
;
7088 else if (EQ (key
, QCfilter
))
7089 /* ':filter FORM'. */
7091 else if (EQ (key
, QCbutton
) && CONSP (value
))
7093 /* `:button (TYPE . SELECTED)'. */
7094 Lisp_Object type
, selected
;
7096 type
= XCAR (value
);
7097 selected
= XCDR (value
);
7098 if (EQ (type
, QCtoggle
) || EQ (type
, QCradio
))
7100 PROP (TOOL_BAR_ITEM_SELECTED_P
) = selected
;
7101 PROP (TOOL_BAR_ITEM_TYPE
) = type
;
7104 else if (EQ (key
, QCimage
)
7106 || (VECTORP (value
) && XVECTOR (value
)->size
== 4)))
7107 /* Value is either a single image specification or a vector
7108 of 4 such specifications for the different buttion states. */
7109 PROP (TOOL_BAR_ITEM_IMAGES
) = value
;
7112 /* If got a filter apply it on binding. */
7114 PROP (TOOL_BAR_ITEM_BINDING
)
7115 = menu_item_eval_property (list2 (filter
,
7117 PROP (TOOL_BAR_ITEM_BINDING
))));
7119 /* See if the binding is a keymap. Give up if it is. */
7120 if (!NILP (get_keymap_1 (PROP (TOOL_BAR_ITEM_BINDING
), 0, 1)))
7123 /* Enable or disable selection of item. */
7124 if (!EQ (PROP (TOOL_BAR_ITEM_ENABLED_P
), Qt
))
7125 PROP (TOOL_BAR_ITEM_ENABLED_P
)
7126 = menu_item_eval_property (PROP (TOOL_BAR_ITEM_ENABLED_P
));
7128 /* Handle radio buttons or toggle boxes. */
7129 if (!NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
)))
7130 PROP (TOOL_BAR_ITEM_SELECTED_P
)
7131 = menu_item_eval_property (PROP (TOOL_BAR_ITEM_SELECTED_P
));
7139 /* Initialize tool_bar_items_vector. REUSE, if non-nil, is a vector
7140 that can be reused. */
7143 init_tool_bar_items (reuse
)
7146 if (VECTORP (reuse
))
7147 tool_bar_items_vector
= reuse
;
7149 tool_bar_items_vector
= Fmake_vector (make_number (64), Qnil
);
7150 ntool_bar_items
= 0;
7154 /* Append parsed tool bar item properties from
7155 tool_bar_item_properties */
7158 append_tool_bar_item ()
7160 Lisp_Object
*to
, *from
;
7162 /* Enlarge tool_bar_items_vector if necessary. */
7163 if (ntool_bar_items
+ TOOL_BAR_ITEM_NSLOTS
7164 >= XVECTOR (tool_bar_items_vector
)->size
)
7166 Lisp_Object new_vector
;
7167 int old_size
= XVECTOR (tool_bar_items_vector
)->size
;
7169 new_vector
= Fmake_vector (make_number (2 * old_size
), Qnil
);
7170 bcopy (XVECTOR (tool_bar_items_vector
)->contents
,
7171 XVECTOR (new_vector
)->contents
,
7172 old_size
* sizeof (Lisp_Object
));
7173 tool_bar_items_vector
= new_vector
;
7176 /* Append entries from tool_bar_item_properties to the end of
7177 tool_bar_items_vector. */
7178 to
= XVECTOR (tool_bar_items_vector
)->contents
+ ntool_bar_items
;
7179 from
= XVECTOR (tool_bar_item_properties
)->contents
;
7180 bcopy (from
, to
, TOOL_BAR_ITEM_NSLOTS
* sizeof *to
);
7181 ntool_bar_items
+= TOOL_BAR_ITEM_NSLOTS
;
7188 /* Read a character using menus based on maps in the array MAPS.
7189 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
7190 Return t if we displayed a menu but the user rejected it.
7192 PREV_EVENT is the previous input event, or nil if we are reading
7193 the first event of a key sequence.
7195 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
7196 if we used a mouse menu to read the input, or zero otherwise. If
7197 USED_MOUSE_MENU is null, we don't dereference it.
7199 The prompting is done based on the prompt-string of the map
7200 and the strings associated with various map elements.
7202 This can be done with X menus or with menus put in the minibuf.
7203 These are done in different ways, depending on how the input will be read.
7204 Menus using X are done after auto-saving in read-char, getting the input
7205 event from Fx_popup_menu; menus using the minibuf use read_char recursively
7206 and do auto-saving in the inner call of read_char. */
7209 read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
7212 Lisp_Object prev_event
;
7213 int *used_mouse_menu
;
7216 register Lisp_Object name
;
7218 if (used_mouse_menu
)
7219 *used_mouse_menu
= 0;
7221 /* Use local over global Menu maps */
7223 if (! menu_prompting
)
7226 /* Optionally disregard all but the global map. */
7227 if (inhibit_local_menu_bar_menus
)
7229 maps
+= (nmaps
- 1);
7233 /* Get the menu name from the first map that has one (a prompt string). */
7234 for (mapno
= 0; mapno
< nmaps
; mapno
++)
7236 name
= map_prompt (maps
[mapno
]);
7241 /* If we don't have any menus, just read a character normally. */
7246 /* If we got to this point via a mouse click,
7247 use a real menu for mouse selection. */
7248 if (EVENT_HAS_PARAMETERS (prev_event
)
7249 && !EQ (XCAR (prev_event
), Qmenu_bar
)
7250 && !EQ (XCAR (prev_event
), Qtool_bar
))
7252 /* Display the menu and get the selection. */
7253 Lisp_Object
*realmaps
7254 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
7258 /* Use the maps that are not nil. */
7259 for (mapno
= 0; mapno
< nmaps
; mapno
++)
7260 if (!NILP (maps
[mapno
]))
7261 realmaps
[nmaps1
++] = maps
[mapno
];
7263 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
7268 record_menu_key (XCAR (value
));
7270 /* If we got multiple events, unread all but
7272 There is no way to prevent those unread events
7273 from showing up later in last_nonmenu_event.
7274 So turn symbol and integer events into lists,
7275 to indicate that they came from a mouse menu,
7276 so that when present in last_nonmenu_event
7277 they won't confuse things. */
7278 for (tem
= XCDR (value
); !NILP (tem
);
7281 record_menu_key (XCAR (tem
));
7282 if (SYMBOLP (XCAR (tem
))
7283 || INTEGERP (XCAR (tem
)))
7285 = Fcons (XCAR (tem
), Qnil
);
7288 /* If we got more than one event, put all but the first
7289 onto this list to be read later.
7290 Return just the first event now. */
7291 Vunread_command_events
7292 = nconc2 (XCDR (value
), Vunread_command_events
);
7293 value
= XCAR (value
);
7295 else if (NILP (value
))
7297 if (used_mouse_menu
)
7298 *used_mouse_menu
= 1;
7301 #endif /* HAVE_MENUS */
7305 /* Buffer in use so far for the minibuf prompts for menu keymaps.
7306 We make this bigger when necessary, and never free it. */
7307 static char *read_char_minibuf_menu_text
;
7308 /* Size of that buffer. */
7309 static int read_char_minibuf_menu_width
;
7312 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
7318 register Lisp_Object name
;
7320 int width
= FRAME_WIDTH (SELECTED_FRAME ()) - 4;
7323 Lisp_Object rest
, vector
;
7328 if (! menu_prompting
)
7331 /* Make sure we have a big enough buffer for the menu text. */
7332 if (read_char_minibuf_menu_text
== 0)
7334 read_char_minibuf_menu_width
= width
+ 4;
7335 read_char_minibuf_menu_text
= (char *) xmalloc (width
+ 4);
7337 else if (width
+ 4 > read_char_minibuf_menu_width
)
7339 read_char_minibuf_menu_width
= width
+ 4;
7340 read_char_minibuf_menu_text
7341 = (char *) xrealloc (read_char_minibuf_menu_text
, width
+ 4);
7343 menu
= read_char_minibuf_menu_text
;
7345 /* Get the menu name from the first map that has one (a prompt string). */
7346 for (mapno
= 0; mapno
< nmaps
; mapno
++)
7348 name
= map_prompt (maps
[mapno
]);
7353 /* If we don't have any menus, just read a character normally. */
7357 /* Prompt string always starts with map's prompt, and a space. */
7358 strcpy (menu
, XSTRING (name
)->data
);
7359 nlength
= STRING_BYTES (XSTRING (name
));
7360 menu
[nlength
++] = ':';
7361 menu
[nlength
++] = ' ';
7364 /* Start prompting at start of first map. */
7368 /* Present the documented bindings, a line at a time. */
7375 Lisp_Object orig_defn_macro
;
7377 /* Loop over elements of map. */
7382 /* If reached end of map, start at beginning of next map. */
7386 /* At end of last map, wrap around to first map if just starting,
7387 or end this line if already have something on it. */
7391 if (notfirst
|| nobindings
) break;
7396 /* Look at the next element of the map. */
7398 elt
= XVECTOR (vector
)->contents
[idx
];
7400 elt
= Fcar_safe (rest
);
7402 if (idx
< 0 && VECTORP (elt
))
7404 /* If we found a dense table in the keymap,
7405 advanced past it, but start scanning its contents. */
7406 rest
= Fcdr_safe (rest
);
7412 /* An ordinary element. */
7413 Lisp_Object event
, tem
;
7417 event
= Fcar_safe (elt
); /* alist */
7418 elt
= Fcdr_safe (elt
);
7422 XSETINT (event
, idx
); /* vector */
7425 /* Ignore the element if it has no prompt string. */
7426 if (INTEGERP (event
) && parse_menu_item (elt
, 0, -1))
7428 /* 1 if the char to type matches the string. */
7430 Lisp_Object upcased_event
, downcased_event
;
7431 Lisp_Object desc
= Qnil
;
7433 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
7435 upcased_event
= Fupcase (event
);
7436 downcased_event
= Fdowncase (event
);
7437 char_matches
= (XINT (upcased_event
) == XSTRING (s
)->data
[0]
7438 || XINT (downcased_event
) == XSTRING (s
)->data
[0]);
7440 desc
= Fsingle_key_description (event
, Qnil
);
7443 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
7445 /* Insert equivalent keybinding. */
7446 s
= concat2 (s
, tem
);
7449 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_TYPE
];
7450 if (EQ (tem
, QCradio
) || EQ (tem
, QCtoggle
))
7452 /* Insert button prefix. */
7453 Lisp_Object selected
7454 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
];
7455 if (EQ (tem
, QCradio
))
7456 tem
= build_string (NILP (selected
) ? "(*) " : "( ) ");
7458 tem
= build_string (NILP (selected
) ? "[X] " : "[ ] ");
7459 s
= concat2 (tem
, s
);
7463 /* If we have room for the prompt string, add it to this line.
7464 If this is the first on the line, always add it. */
7465 if ((XSTRING (s
)->size
+ i
+ 2
7466 + (char_matches
? 0 : XSTRING (desc
)->size
+ 3))
7472 /* Punctuate between strings. */
7475 strcpy (menu
+ i
, ", ");
7481 /* If the char to type doesn't match the string's
7482 first char, explicitly show what char to type. */
7485 /* Add as much of string as fits. */
7486 thiswidth
= XSTRING (desc
)->size
;
7487 if (thiswidth
+ i
> width
)
7488 thiswidth
= width
- i
;
7489 bcopy (XSTRING (desc
)->data
, menu
+ i
, thiswidth
);
7491 strcpy (menu
+ i
, " = ");
7495 /* Add as much of string as fits. */
7496 thiswidth
= XSTRING (s
)->size
;
7497 if (thiswidth
+ i
> width
)
7498 thiswidth
= width
- i
;
7499 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
7505 /* If this element does not fit, end the line now,
7506 and save the element for the next line. */
7507 strcpy (menu
+ i
, "...");
7512 /* Move past this element. */
7513 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
7514 /* Handle reaching end of dense table. */
7519 rest
= Fcdr_safe (rest
);
7523 /* Prompt with that and read response. */
7524 message2_nolog (menu
, strlen (menu
),
7525 ! NILP (current_buffer
->enable_multibyte_characters
));
7527 /* Make believe its not a keyboard macro in case the help char
7528 is pressed. Help characters are not recorded because menu prompting
7529 is not used on replay.
7531 orig_defn_macro
= current_kboard
->defining_kbd_macro
;
7532 current_kboard
->defining_kbd_macro
= Qnil
;
7534 obj
= read_char (commandflag
, 0, 0, Qt
, 0);
7535 while (BUFFERP (obj
));
7536 current_kboard
->defining_kbd_macro
= orig_defn_macro
;
7538 if (!INTEGERP (obj
))
7543 if (! EQ (obj
, menu_prompt_more_char
)
7544 && (!INTEGERP (menu_prompt_more_char
)
7545 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
7547 if (!NILP (current_kboard
->defining_kbd_macro
))
7548 store_kbd_macro_char (obj
);
7551 /* Help char - go round again */
7555 /* Reading key sequences. */
7557 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
7558 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
7559 keymap, or nil otherwise. Return the index of the first keymap in
7560 which KEY has any binding, or NMAPS if no map has a binding.
7562 If KEY is a meta ASCII character, treat it like meta-prefix-char
7563 followed by the corresponding non-meta character. Keymaps in
7564 CURRENT with non-prefix bindings for meta-prefix-char become nil in
7567 If KEY has no bindings in any of the CURRENT maps, NEXT is left
7570 NEXT may be the same array as CURRENT. */
7573 follow_key (key
, nmaps
, current
, defs
, next
)
7575 Lisp_Object
*current
, *defs
, *next
;
7578 int i
, first_binding
;
7581 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
7582 followed by the corresponding non-meta character.
7583 Put the results into DEFS, since we are going to alter that anyway.
7584 Do not alter CURRENT or NEXT. */
7585 if (INTEGERP (key
) && (XUINT (key
) & CHAR_META
))
7587 for (i
= 0; i
< nmaps
; i
++)
7588 if (! NILP (current
[i
]))
7591 def
= get_keyelt (access_keymap (current
[i
],
7592 meta_prefix_char
, 1, 0), 0);
7594 /* Note that since we pass the resulting bindings through
7595 get_keymap_1, non-prefix bindings for meta-prefix-char
7597 defs
[i
] = get_keymap_1 (def
, 0, 1);
7603 XSETINT (key
, XFASTINT (key
) & ~CHAR_META
);
7606 first_binding
= nmaps
;
7607 for (i
= nmaps
- 1; i
>= 0; i
--)
7609 if (! NILP (current
[i
]))
7617 defs
[i
] = get_keyelt (access_keymap (map
, key
, 1, 0), 1);
7618 if (! NILP (defs
[i
]))
7625 /* Given the set of bindings we've found, produce the next set of maps. */
7626 if (first_binding
< nmaps
)
7627 for (i
= 0; i
< nmaps
; i
++)
7628 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0, 1);
7630 return first_binding
;
7633 /* Read a sequence of keys that ends with a non prefix character,
7634 storing it in KEYBUF, a buffer of size BUFSIZE.
7636 Return the length of the key sequence stored.
7637 Return -1 if the user rejected a command menu.
7639 Echo starting immediately unless `prompt' is 0.
7641 Where a key sequence ends depends on the currently active keymaps.
7642 These include any minor mode keymaps active in the current buffer,
7643 the current buffer's local map, and the global map.
7645 If a key sequence has no other bindings, we check Vfunction_key_map
7646 to see if some trailing subsequence might be the beginning of a
7647 function key's sequence. If so, we try to read the whole function
7648 key, and substitute its symbolic name into the key sequence.
7650 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
7651 `double-' events into similar click events, if that would make them
7652 bound. We try to turn `triple-' events first into `double-' events,
7655 If we get a mouse click in a mode line, vertical divider, or other
7656 non-text area, we treat the click as if it were prefixed by the
7657 symbol denoting that area - `mode-line', `vertical-line', or
7660 If the sequence starts with a mouse click, we read the key sequence
7661 with respect to the buffer clicked on, not the current buffer.
7663 If the user switches frames in the midst of a key sequence, we put
7664 off the switch-frame event until later; the next call to
7665 read_char will return it.
7667 If FIX_CURRENT_BUFFER is nonzero, we restore current_buffer
7668 from the selected window's buffer. */
7671 read_key_sequence (keybuf
, bufsize
, prompt
, dont_downcase_last
,
7672 can_return_switch_frame
, fix_current_buffer
)
7673 Lisp_Object
*keybuf
;
7676 int dont_downcase_last
;
7677 int can_return_switch_frame
;
7678 int fix_current_buffer
;
7680 volatile int count
= specpdl_ptr
- specpdl
;
7682 /* How many keys there are in the current key sequence. */
7685 /* The length of the echo buffer when we started reading, and
7686 the length of this_command_keys when we started reading. */
7687 volatile int echo_start
;
7688 volatile int keys_start
;
7690 /* The number of keymaps we're scanning right now, and the number of
7691 keymaps we have allocated space for. */
7693 volatile int nmaps_allocated
= 0;
7695 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
7696 the current keymaps. */
7697 Lisp_Object
*volatile defs
= NULL
;
7699 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
7700 in the current keymaps, or nil where it is not a prefix. */
7701 Lisp_Object
*volatile submaps
= NULL
;
7703 /* The local map to start out with at start of key sequence. */
7704 volatile Lisp_Object orig_local_map
;
7706 /* The map from the `keymap' property to start out with at start of
7708 volatile Lisp_Object orig_keymap
;
7710 /* 1 if we have already considered switching to the local-map property
7711 of the place where a mouse click occurred. */
7712 volatile int localized_local_map
= 0;
7714 /* The index in defs[] of the first keymap that has a binding for
7715 this key sequence. In other words, the lowest i such that
7716 defs[i] is non-nil. */
7717 volatile int first_binding
;
7719 /* If t < mock_input, then KEYBUF[t] should be read as the next
7722 We use this to recover after recognizing a function key. Once we
7723 realize that a suffix of the current key sequence is actually a
7724 function key's escape sequence, we replace the suffix with the
7725 function key's binding from Vfunction_key_map. Now keybuf
7726 contains a new and different key sequence, so the echo area,
7727 this_command_keys, and the submaps and defs arrays are wrong. In
7728 this situation, we set mock_input to t, set t to 0, and jump to
7729 restart_sequence; the loop will read keys from keybuf up until
7730 mock_input, thus rebuilding the state; and then it will resume
7731 reading characters from the keyboard. */
7732 volatile int mock_input
= 0;
7734 /* If the sequence is unbound in submaps[], then
7735 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
7736 and fkey_map is its binding.
7738 These might be > t, indicating that all function key scanning
7739 should hold off until t reaches them. We do this when we've just
7740 recognized a function key, to avoid searching for the function
7741 key's again in Vfunction_key_map. */
7742 volatile int fkey_start
= 0, fkey_end
= 0;
7743 volatile Lisp_Object fkey_map
;
7745 /* Likewise, for key_translation_map. */
7746 volatile int keytran_start
= 0, keytran_end
= 0;
7747 volatile Lisp_Object keytran_map
;
7749 /* If we receive a ``switch-frame'' event in the middle of a key sequence,
7750 we put it off for later. While we're reading, we keep the event here. */
7751 volatile Lisp_Object delayed_switch_frame
;
7753 /* See the comment below... */
7754 #if defined (GOBBLE_FIRST_EVENT)
7755 Lisp_Object first_event
;
7758 volatile Lisp_Object original_uppercase
;
7759 volatile int original_uppercase_position
= -1;
7761 /* Gets around Microsoft compiler limitations. */
7764 struct buffer
*starting_buffer
;
7766 /* Nonzero if we seem to have got the beginning of a binding
7767 in function_key_map. */
7768 volatile int function_key_possible
= 0;
7769 volatile int key_translation_possible
= 0;
7771 /* Save the status of key translation before each step,
7772 so that we can restore this after downcasing. */
7773 Lisp_Object prev_fkey_map
;
7774 int prev_fkey_start
;
7777 Lisp_Object prev_keytran_map
;
7778 int prev_keytran_start
;
7779 int prev_keytran_end
;
7781 #if defined (GOBBLE_FIRST_EVENT)
7785 raw_keybuf_count
= 0;
7787 last_nonmenu_event
= Qnil
;
7789 delayed_switch_frame
= Qnil
;
7790 fkey_map
= Vfunction_key_map
;
7791 keytran_map
= Vkey_translation_map
;
7793 /* If there is no function-key-map, turn off function key scanning. */
7794 if (NILP (Fkeymapp (Vfunction_key_map
)))
7795 fkey_start
= fkey_end
= bufsize
+ 1;
7797 /* If there is no key-translation-map, turn off scanning. */
7798 if (NILP (Fkeymapp (Vkey_translation_map
)))
7799 keytran_start
= keytran_end
= bufsize
+ 1;
7804 echo_prompt (XSTRING (prompt
)->data
);
7805 else if (cursor_in_echo_area
7806 && (FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
7807 && NILP (Fzerop (Vecho_keystrokes
)))
7808 /* This doesn't put in a dash if the echo buffer is empty, so
7809 you don't always see a dash hanging out in the minibuffer. */
7813 /* Record the initial state of the echo area and this_command_keys;
7814 we will need to restore them if we replay a key sequence. */
7816 echo_start
= echo_length ();
7817 keys_start
= this_command_key_count
;
7818 this_single_command_key_start
= keys_start
;
7820 #if defined (GOBBLE_FIRST_EVENT)
7821 /* This doesn't quite work, because some of the things that read_char
7822 does cannot safely be bypassed. It seems too risky to try to make
7825 /* Read the first char of the sequence specially, before setting
7826 up any keymaps, in case a filter runs and switches buffers on us. */
7827 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
7829 #endif /* GOBBLE_FIRST_EVENT */
7831 orig_local_map
= get_local_map (PT
, current_buffer
, local_map
);
7832 orig_keymap
= get_local_map (PT
, current_buffer
, keymap
);
7834 /* We jump here when the key sequence has been thoroughly changed, and
7835 we need to rescan it starting from the beginning. When we jump here,
7836 keybuf[0..mock_input] holds the sequence we should reread. */
7839 starting_buffer
= current_buffer
;
7840 function_key_possible
= 0;
7841 key_translation_possible
= 0;
7843 /* Build our list of keymaps.
7844 If we recognize a function key and replace its escape sequence in
7845 keybuf with its symbol, or if the sequence starts with a mouse
7846 click and we need to switch buffers, we jump back here to rebuild
7847 the initial keymaps from the current buffer. */
7851 if (!NILP (current_kboard
->Voverriding_terminal_local_map
)
7852 || !NILP (Voverriding_local_map
))
7854 if (3 > nmaps_allocated
)
7856 submaps
= (Lisp_Object
*) alloca (3 * sizeof (submaps
[0]));
7857 defs
= (Lisp_Object
*) alloca (3 * sizeof (defs
[0]));
7858 nmaps_allocated
= 3;
7861 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
7862 submaps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
7863 if (!NILP (Voverriding_local_map
))
7864 submaps
[nmaps
++] = Voverriding_local_map
;
7869 nmaps
= current_minor_maps (0, &maps
);
7870 if (!NILP (orig_keymap
))
7872 if (nmaps
+ extra_maps
> nmaps_allocated
)
7874 submaps
= (Lisp_Object
*) alloca ((nmaps
+extra_maps
)
7875 * sizeof (submaps
[0]));
7876 defs
= (Lisp_Object
*) alloca ((nmaps
+extra_maps
)
7877 * sizeof (defs
[0]));
7878 nmaps_allocated
= nmaps
+ extra_maps
;
7880 bcopy (maps
, (void *) submaps
, nmaps
* sizeof (submaps
[0]));
7881 if (!NILP (orig_keymap
))
7882 submaps
[nmaps
++] = orig_keymap
;
7883 submaps
[nmaps
++] = orig_local_map
;
7885 submaps
[nmaps
++] = current_global_map
;
7888 /* Find an accurate initial value for first_binding. */
7889 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
7890 if (! NILP (submaps
[first_binding
]))
7893 /* Start from the beginning in keybuf. */
7896 /* These are no-ops the first time through, but if we restart, they
7897 revert the echo area and this_command_keys to their original state. */
7898 this_command_key_count
= keys_start
;
7899 if (INTERACTIVE
&& t
< mock_input
)
7900 echo_truncate (echo_start
);
7902 /* If the best binding for the current key sequence is a keymap, or
7903 we may be looking at a function key's escape sequence, keep on
7905 while ((first_binding
< nmaps
&& ! NILP (submaps
[first_binding
]))
7906 || (first_binding
>= nmaps
7908 /* mock input is never part of a function key's sequence. */
7909 && mock_input
<= fkey_start
)
7910 || (first_binding
>= nmaps
7911 && keytran_start
< t
&& key_translation_possible
)
7912 /* Don't return in the middle of a possible function key sequence,
7913 if the only bindings we found were via case conversion.
7914 Thus, if ESC O a has a function-key-map translation
7915 and ESC o has a binding, don't return after ESC O,
7916 so that we can translate ESC O plus the next character. */
7920 int used_mouse_menu
= 0;
7922 /* Where the last real key started. If we need to throw away a
7923 key that has expanded into more than one element of keybuf
7924 (say, a mouse click on the mode line which is being treated
7925 as [mode-line (mouse-...)], then we backtrack to this point
7927 volatile int last_real_key_start
;
7929 /* These variables are analogous to echo_start and keys_start;
7930 while those allow us to restart the entire key sequence,
7931 echo_local_start and keys_local_start allow us to throw away
7933 volatile int echo_local_start
, keys_local_start
, local_first_binding
;
7936 error ("Key sequence too long");
7939 echo_local_start
= echo_length ();
7940 keys_local_start
= this_command_key_count
;
7941 local_first_binding
= first_binding
;
7944 /* These are no-ops, unless we throw away a keystroke below and
7945 jumped back up to replay_key; in that case, these restore the
7946 variables to their original state, allowing us to replay the
7948 if (INTERACTIVE
&& t
< mock_input
)
7949 echo_truncate (echo_local_start
);
7950 this_command_key_count
= keys_local_start
;
7951 first_binding
= local_first_binding
;
7953 /* By default, assume each event is "real". */
7954 last_real_key_start
= t
;
7956 /* Does mock_input indicate that we are re-reading a key sequence? */
7960 add_command_key (key
);
7961 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
7962 && NILP (Fzerop (Vecho_keystrokes
)))
7966 /* If not, we should actually read a character. */
7971 KBOARD
*interrupted_kboard
= current_kboard
;
7972 struct frame
*interrupted_frame
= SELECTED_FRAME ();
7973 if (setjmp (wrong_kboard_jmpbuf
))
7975 if (!NILP (delayed_switch_frame
))
7977 interrupted_kboard
->kbd_queue
7978 = Fcons (delayed_switch_frame
,
7979 interrupted_kboard
->kbd_queue
);
7980 delayed_switch_frame
= Qnil
;
7983 interrupted_kboard
->kbd_queue
7984 = Fcons (keybuf
[--t
], interrupted_kboard
->kbd_queue
);
7986 /* If the side queue is non-empty, ensure it begins with a
7987 switch-frame, so we'll replay it in the right context. */
7988 if (CONSP (interrupted_kboard
->kbd_queue
)
7989 && (key
= XCAR (interrupted_kboard
->kbd_queue
),
7990 !(EVENT_HAS_PARAMETERS (key
)
7991 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)),
7995 XSETFRAME (frame
, interrupted_frame
);
7996 interrupted_kboard
->kbd_queue
7997 = Fcons (make_lispy_switch_frame (frame
),
7998 interrupted_kboard
->kbd_queue
);
8001 orig_local_map
= get_local_map (PT
, current_buffer
, local_map
);
8002 orig_keymap
= get_local_map (PT
, current_buffer
, keymap
);
8003 goto replay_sequence
;
8006 key
= read_char (NILP (prompt
), nmaps
,
8007 (Lisp_Object
*) submaps
, last_nonmenu_event
,
8011 /* read_char returns t when it shows a menu and the user rejects it.
8015 unbind_to (count
, Qnil
);
8019 /* read_char returns -1 at the end of a macro.
8020 Emacs 18 handles this by returning immediately with a
8021 zero, so that's what we'll do. */
8022 if (INTEGERP (key
) && XINT (key
) == -1)
8025 /* The Microsoft C compiler can't handle the goto that
8031 /* If the current buffer has been changed from under us, the
8032 keymap may have changed, so replay the sequence. */
8036 /* Reset the current buffer from the selected window
8037 in case something changed the former and not the latter.
8038 This is to be more consistent with the behavior
8039 of the command_loop_1. */
8040 if (fix_current_buffer
)
8042 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8044 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
8045 Fset_buffer (XWINDOW (selected_window
)->buffer
);
8048 orig_local_map
= get_local_map (PT
, current_buffer
, local_map
);
8049 orig_keymap
= get_local_map (PT
, current_buffer
, keymap
);
8050 goto replay_sequence
;
8053 /* If we have a quit that was typed in another frame, and
8054 quit_throw_to_read_char switched buffers,
8055 replay to get the right keymap. */
8056 if (XINT (key
) == quit_char
&& current_buffer
!= starting_buffer
)
8059 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
8063 orig_local_map
= get_local_map (PT
, current_buffer
, local_map
);
8064 orig_keymap
= get_local_map (PT
, current_buffer
, keymap
);
8065 goto replay_sequence
;
8070 if (EVENT_HAS_PARAMETERS (key
)
8071 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)), Qswitch_frame
))
8073 /* If we're at the beginning of a key sequence, and the caller
8074 says it's okay, go ahead and return this event. If we're
8075 in the midst of a key sequence, delay it until the end. */
8076 if (t
> 0 || !can_return_switch_frame
)
8078 delayed_switch_frame
= key
;
8084 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
8087 /* Clicks in non-text areas get prefixed by the symbol
8088 in their CHAR-ADDRESS field. For example, a click on
8089 the mode line is prefixed by the symbol `mode-line'.
8091 Furthermore, key sequences beginning with mouse clicks
8092 are read using the keymaps of the buffer clicked on, not
8093 the current buffer. So we may have to switch the buffer
8096 When we turn one event into two events, we must make sure
8097 that neither of the two looks like the original--so that,
8098 if we replay the events, they won't be expanded again.
8099 If not for this, such reexpansion could happen either here
8100 or when user programs play with this-command-keys. */
8101 if (EVENT_HAS_PARAMETERS (key
))
8105 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
8106 if (EQ (kind
, Qmouse_click
))
8108 Lisp_Object window
, posn
;
8110 window
= POSN_WINDOW (EVENT_START (key
));
8111 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
8115 /* We're looking at the second event of a
8116 sequence which we expanded before. Set
8117 last_real_key_start appropriately. */
8119 last_real_key_start
= t
- 1;
8122 /* Key sequences beginning with mouse clicks are
8123 read using the keymaps in the buffer clicked on,
8124 not the current buffer. If we're at the
8125 beginning of a key sequence, switch buffers. */
8126 if (last_real_key_start
== 0
8128 && BUFFERP (XWINDOW (window
)->buffer
)
8129 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
8131 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
8135 /* Arrange to go back to the original buffer once we're
8136 done reading the key sequence. Note that we can't
8137 use save_excursion_{save,restore} here, because they
8138 save point as well as the current buffer; we don't
8139 want to save point, because redisplay may change it,
8140 to accommodate a Fset_window_start or something. We
8141 don't want to do this at the top of the function,
8142 because we may get input from a subprocess which
8143 wants to change the selected window and stuff (say,
8145 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
8147 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8149 set_buffer_internal (XBUFFER (XWINDOW
8152 orig_local_map
= get_local_map (PT
, current_buffer
,
8154 orig_keymap
= get_local_map (PT
, current_buffer
, keymap
);
8155 goto replay_sequence
;
8158 /* For a mouse click, get the local text-property keymap
8159 of the place clicked on, rather than point. */
8160 if (last_real_key_start
== 0
8161 && CONSP (XCDR (key
))
8162 && ! localized_local_map
)
8164 Lisp_Object map_here
, start
, pos
;
8166 localized_local_map
= 1;
8167 start
= EVENT_START (key
);
8169 if (CONSP (start
) && CONSP (XCDR (start
)))
8171 pos
= POSN_BUFFER_POSN (start
);
8173 && XINT (pos
) >= BEG
&& XINT (pos
) <= Z
)
8175 map_here
= get_local_map (XINT (pos
),
8176 current_buffer
, local_map
);
8177 if (!EQ (map_here
, orig_local_map
))
8179 orig_local_map
= map_here
;
8183 goto replay_sequence
;
8185 map_here
= get_local_map (XINT (pos
),
8186 current_buffer
, keymap
);
8187 if (!EQ (map_here
, orig_keymap
))
8189 orig_keymap
= map_here
;
8193 goto replay_sequence
;
8199 /* Expand mode-line and scroll-bar events into two events:
8200 use posn as a fake prefix key. */
8203 if (t
+ 1 >= bufsize
)
8204 error ("Key sequence too long");
8209 /* Zap the position in key, so we know that we've
8210 expanded it, and don't try to do so again. */
8211 POSN_BUFFER_POSN (EVENT_START (key
))
8212 = Fcons (posn
, Qnil
);
8214 /* If on a mode line string with a local keymap,
8215 reconsider the key sequence with that keymap. */
8216 if (CONSP (POSN_STRING (EVENT_START (key
))))
8218 Lisp_Object string
, pos
, map
, map2
;
8220 string
= POSN_STRING (EVENT_START (key
));
8221 pos
= XCDR (string
);
8222 string
= XCAR (string
);
8224 && XINT (pos
) < XSTRING (string
)->size
)
8226 map
= Fget_text_property (pos
, Qlocal_map
, string
);
8228 orig_local_map
= map
;
8229 map2
= Fget_text_property (pos
, Qkeymap
, string
);
8232 if (!NILP (map
) || !NILP (map2
))
8233 goto replay_sequence
;
8240 else if (CONSP (XCDR (key
))
8241 && CONSP (EVENT_START (key
))
8242 && CONSP (XCDR (EVENT_START (key
))))
8246 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
8247 /* Handle menu-bar events:
8248 insert the dummy prefix event `menu-bar'. */
8249 if (EQ (posn
, Qmenu_bar
) || EQ (posn
, Qtool_bar
))
8251 if (t
+ 1 >= bufsize
)
8252 error ("Key sequence too long");
8256 /* Zap the position in key, so we know that we've
8257 expanded it, and don't try to do so again. */
8258 POSN_BUFFER_POSN (EVENT_START (key
))
8259 = Fcons (posn
, Qnil
);
8262 goto replay_sequence
;
8264 else if (CONSP (posn
))
8266 /* We're looking at the second event of a
8267 sequence which we expanded before. Set
8268 last_real_key_start appropriately. */
8269 if (last_real_key_start
== t
&& t
> 0)
8270 last_real_key_start
= t
- 1;
8275 /* We have finally decided that KEY is something we might want
8277 first_binding
= (follow_key (key
,
8278 nmaps
- first_binding
,
8279 submaps
+ first_binding
,
8280 defs
+ first_binding
,
8281 submaps
+ first_binding
)
8284 /* If KEY wasn't bound, we'll try some fallbacks. */
8285 if (first_binding
>= nmaps
)
8289 head
= EVENT_HEAD (key
);
8290 if (help_char_p (head
) && t
> 0)
8292 read_key_sequence_cmd
= Vprefix_help_command
;
8294 last_nonmenu_event
= key
;
8295 /* The Microsoft C compiler can't handle the goto that
8303 Lisp_Object breakdown
;
8306 breakdown
= parse_modifiers (head
);
8307 modifiers
= XINT (XCAR (XCDR (breakdown
)));
8308 /* Attempt to reduce an unbound mouse event to a simpler
8309 event that is bound:
8310 Drags reduce to clicks.
8311 Double-clicks reduce to clicks.
8312 Triple-clicks reduce to double-clicks, then to clicks.
8313 Down-clicks are eliminated.
8314 Double-downs reduce to downs, then are eliminated.
8315 Triple-downs reduce to double-downs, then to downs,
8316 then are eliminated. */
8317 if (modifiers
& (down_modifier
| drag_modifier
8318 | double_modifier
| triple_modifier
))
8320 while (modifiers
& (down_modifier
| drag_modifier
8321 | double_modifier
| triple_modifier
))
8323 Lisp_Object new_head
, new_click
;
8324 if (modifiers
& triple_modifier
)
8325 modifiers
^= (double_modifier
| triple_modifier
);
8326 else if (modifiers
& double_modifier
)
8327 modifiers
&= ~double_modifier
;
8328 else if (modifiers
& drag_modifier
)
8329 modifiers
&= ~drag_modifier
;
8332 /* Dispose of this `down' event by simply jumping
8333 back to replay_key, to get another event.
8335 Note that if this event came from mock input,
8336 then just jumping back to replay_key will just
8337 hand it to us again. So we have to wipe out any
8340 We could delete keybuf[t] and shift everything
8341 after that to the left by one spot, but we'd also
8342 have to fix up any variable that points into
8343 keybuf, and shifting isn't really necessary
8346 Adding prefixes for non-textual mouse clicks
8347 creates two characters of mock input, and both
8348 must be thrown away. If we're only looking at
8349 the prefix now, we can just jump back to
8350 replay_key. On the other hand, if we've already
8351 processed the prefix, and now the actual click
8352 itself is giving us trouble, then we've lost the
8353 state of the keymaps we want to backtrack to, and
8354 we need to replay the whole sequence to rebuild
8357 Beyond that, only function key expansion could
8358 create more than two keys, but that should never
8359 generate mouse events, so it's okay to zero
8360 mock_input in that case too.
8362 Isn't this just the most wonderful code ever? */
8363 if (t
== last_real_key_start
)
8370 mock_input
= last_real_key_start
;
8371 goto replay_sequence
;
8376 = apply_modifiers (modifiers
, XCAR (breakdown
));
8378 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
8380 /* Look for a binding for this new key. follow_key
8381 promises that it didn't munge submaps the
8382 last time we called it, since key was unbound. */
8384 = (follow_key (new_click
,
8385 nmaps
- local_first_binding
,
8386 submaps
+ local_first_binding
,
8387 defs
+ local_first_binding
,
8388 submaps
+ local_first_binding
)
8389 + local_first_binding
);
8391 /* If that click is bound, go for it. */
8392 if (first_binding
< nmaps
)
8397 /* Otherwise, we'll leave key set to the drag event. */
8404 /* Normally, last_nonmenu_event gets the previous key we read.
8405 But when a mouse popup menu is being used,
8406 we don't update last_nonmenu_event; it continues to hold the mouse
8407 event that preceded the first level of menu. */
8408 if (!used_mouse_menu
)
8409 last_nonmenu_event
= key
;
8411 /* Record what part of this_command_keys is the current key sequence. */
8412 this_single_command_key_start
= this_command_key_count
- t
;
8414 prev_fkey_map
= fkey_map
;
8415 prev_fkey_start
= fkey_start
;
8416 prev_fkey_end
= fkey_end
;
8418 prev_keytran_map
= keytran_map
;
8419 prev_keytran_start
= keytran_start
;
8420 prev_keytran_end
= keytran_end
;
8422 /* If the sequence is unbound, see if we can hang a function key
8423 off the end of it. We only want to scan real keyboard input
8424 for function key sequences, so if mock_input says that we're
8425 re-reading old events, don't examine it. */
8426 if (first_binding
>= nmaps
8429 Lisp_Object fkey_next
;
8431 /* Continue scan from fkey_end until we find a bound suffix.
8432 If we fail, increment fkey_start
8433 and start fkey_end from there. */
8434 while (fkey_end
< t
)
8438 key
= keybuf
[fkey_end
++];
8439 /* Look up meta-characters by prefixing them
8440 with meta_prefix_char. I hate this. */
8441 if (INTEGERP (key
) && XUINT (key
) & meta_modifier
)
8446 (access_keymap (fkey_map
, meta_prefix_char
, 1, 0), 0),
8448 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
8451 fkey_next
= fkey_map
;
8454 = get_keyelt (access_keymap (fkey_next
, key
, 1, 0), 1);
8456 /* Handle symbol with autoload definition. */
8457 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
8458 && CONSP (XSYMBOL (fkey_next
)->function
)
8459 && EQ (XCAR (XSYMBOL (fkey_next
)->function
), Qautoload
))
8460 do_autoload (XSYMBOL (fkey_next
)->function
,
8463 /* Handle a symbol whose function definition is a keymap
8465 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
8466 && (!NILP (Farrayp (XSYMBOL (fkey_next
)->function
))
8467 || !NILP (Fkeymapp (XSYMBOL (fkey_next
)->function
))))
8468 fkey_next
= XSYMBOL (fkey_next
)->function
;
8470 #if 0 /* I didn't turn this on, because it might cause trouble
8471 for the mapping of return into C-m and tab into C-i. */
8472 /* Optionally don't map function keys into other things.
8473 This enables the user to redefine kp- keys easily. */
8474 if (SYMBOLP (key
) && !NILP (Vinhibit_function_key_mapping
))
8478 /* If the function key map gives a function, not an
8479 array, then call the function with no args and use
8480 its value instead. */
8481 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
8484 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8488 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
8489 fkey_next
= call1 (fkey_next
, prompt
);
8491 /* If the function returned something invalid,
8492 barf--don't ignore it.
8493 (To ignore it safely, we would need to gcpro a bunch of
8494 other variables.) */
8495 if (! (VECTORP (fkey_next
) || STRINGP (fkey_next
)))
8496 error ("Function in key-translation-map returns invalid key sequence");
8499 function_key_possible
= ! NILP (fkey_next
);
8501 /* If keybuf[fkey_start..fkey_end] is bound in the
8502 function key map and it's a suffix of the current
8503 sequence (i.e. fkey_end == t), replace it with
8504 the binding and restart with fkey_start at the end. */
8505 if ((VECTORP (fkey_next
) || STRINGP (fkey_next
))
8508 int len
= XFASTINT (Flength (fkey_next
));
8510 t
= fkey_start
+ len
;
8512 error ("Key sequence too long");
8514 if (VECTORP (fkey_next
))
8515 bcopy (XVECTOR (fkey_next
)->contents
,
8516 keybuf
+ fkey_start
,
8517 (t
- fkey_start
) * sizeof (keybuf
[0]));
8518 else if (STRINGP (fkey_next
))
8522 for (i
= 0; i
< len
; i
++)
8523 XSETFASTINT (keybuf
[fkey_start
+ i
],
8524 XSTRING (fkey_next
)->data
[i
]);
8528 fkey_start
= fkey_end
= t
;
8529 fkey_map
= Vfunction_key_map
;
8531 /* Do pass the results through key-translation-map.
8532 But don't retranslate what key-translation-map
8533 has already translated. */
8534 keytran_end
= keytran_start
;
8535 keytran_map
= Vkey_translation_map
;
8537 goto replay_sequence
;
8540 fkey_map
= get_keymap_1 (fkey_next
, 0, 1);
8542 /* If we no longer have a bound suffix, try a new positions for
8544 if (NILP (fkey_map
))
8546 fkey_end
= ++fkey_start
;
8547 fkey_map
= Vfunction_key_map
;
8548 function_key_possible
= 0;
8553 /* Look for this sequence in key-translation-map. */
8555 Lisp_Object keytran_next
;
8557 /* Scan from keytran_end until we find a bound suffix. */
8558 while (keytran_end
< t
)
8562 key
= keybuf
[keytran_end
++];
8563 /* Look up meta-characters by prefixing them
8564 with meta_prefix_char. I hate this. */
8565 if (INTEGERP (key
) && XUINT (key
) & meta_modifier
)
8570 (access_keymap (keytran_map
, meta_prefix_char
, 1, 0), 0),
8572 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
8575 keytran_next
= keytran_map
;
8578 = get_keyelt (access_keymap (keytran_next
, key
, 1, 0), 1);
8580 /* Handle symbol with autoload definition. */
8581 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
8582 && CONSP (XSYMBOL (keytran_next
)->function
)
8583 && EQ (XCAR (XSYMBOL (keytran_next
)->function
), Qautoload
))
8584 do_autoload (XSYMBOL (keytran_next
)->function
,
8587 /* Handle a symbol whose function definition is a keymap
8589 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
8590 && (!NILP (Farrayp (XSYMBOL (keytran_next
)->function
))
8591 || !NILP (Fkeymapp (XSYMBOL (keytran_next
)->function
))))
8592 keytran_next
= XSYMBOL (keytran_next
)->function
;
8594 /* If the key translation map gives a function, not an
8595 array, then call the function with one arg and use
8596 its value instead. */
8597 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
8598 && keytran_end
== t
)
8600 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8604 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
8605 keytran_next
= call1 (keytran_next
, prompt
);
8607 /* If the function returned something invalid,
8608 barf--don't ignore it.
8609 (To ignore it safely, we would need to gcpro a bunch of
8610 other variables.) */
8611 if (! (VECTORP (keytran_next
) || STRINGP (keytran_next
)))
8612 error ("Function in key-translation-map returns invalid key sequence");
8615 key_translation_possible
= ! NILP (keytran_next
);
8617 /* If keybuf[keytran_start..keytran_end] is bound in the
8618 key translation map and it's a suffix of the current
8619 sequence (i.e. keytran_end == t), replace it with
8620 the binding and restart with keytran_start at the end. */
8621 if ((VECTORP (keytran_next
) || STRINGP (keytran_next
))
8622 && keytran_end
== t
)
8624 int len
= XFASTINT (Flength (keytran_next
));
8626 t
= keytran_start
+ len
;
8628 error ("Key sequence too long");
8630 if (VECTORP (keytran_next
))
8631 bcopy (XVECTOR (keytran_next
)->contents
,
8632 keybuf
+ keytran_start
,
8633 (t
- keytran_start
) * sizeof (keybuf
[0]));
8634 else if (STRINGP (keytran_next
))
8638 for (i
= 0; i
< len
; i
++)
8639 XSETFASTINT (keybuf
[keytran_start
+ i
],
8640 XSTRING (keytran_next
)->data
[i
]);
8644 keytran_start
= keytran_end
= t
;
8645 keytran_map
= Vkey_translation_map
;
8647 /* Don't pass the results of key-translation-map
8648 through function-key-map. */
8649 fkey_start
= fkey_end
= t
;
8650 fkey_map
= Vfunction_key_map
;
8652 goto replay_sequence
;
8655 keytran_map
= get_keymap_1 (keytran_next
, 0, 1);
8657 /* If we no longer have a bound suffix, try a new positions for
8659 if (NILP (keytran_map
))
8661 keytran_end
= ++keytran_start
;
8662 keytran_map
= Vkey_translation_map
;
8663 key_translation_possible
= 0;
8668 /* If KEY is not defined in any of the keymaps,
8669 and cannot be part of a function key or translation,
8670 and is an upper case letter
8671 use the corresponding lower-case letter instead. */
8672 if (first_binding
== nmaps
&& ! function_key_possible
8673 && ! key_translation_possible
8675 && ((((XINT (key
) & 0x3ffff)
8676 < XCHAR_TABLE (current_buffer
->downcase_table
)->size
)
8677 && UPPERCASEP (XINT (key
) & 0x3ffff))
8678 || (XINT (key
) & shift_modifier
)))
8680 Lisp_Object new_key
;
8682 original_uppercase
= key
;
8683 original_uppercase_position
= t
- 1;
8685 if (XINT (key
) & shift_modifier
)
8686 XSETINT (new_key
, XINT (key
) & ~shift_modifier
);
8688 XSETINT (new_key
, (DOWNCASE (XINT (key
) & 0x3ffff)
8689 | (XINT (key
) & ~0x3ffff)));
8691 /* We have to do this unconditionally, regardless of whether
8692 the lower-case char is defined in the keymaps, because they
8693 might get translated through function-key-map. */
8694 keybuf
[t
- 1] = new_key
;
8697 fkey_map
= prev_fkey_map
;
8698 fkey_start
= prev_fkey_start
;
8699 fkey_end
= prev_fkey_end
;
8701 keytran_map
= prev_keytran_map
;
8702 keytran_start
= prev_keytran_start
;
8703 keytran_end
= prev_keytran_end
;
8705 goto replay_sequence
;
8707 /* If KEY is not defined in any of the keymaps,
8708 and cannot be part of a function key or translation,
8709 and is a shifted function key,
8710 use the corresponding unshifted function key instead. */
8711 if (first_binding
== nmaps
&& ! function_key_possible
8712 && ! key_translation_possible
8715 Lisp_Object breakdown
;
8718 breakdown
= parse_modifiers (key
);
8719 modifiers
= XINT (XCAR (XCDR (breakdown
)));
8720 if (modifiers
& shift_modifier
)
8722 Lisp_Object new_key
;
8724 original_uppercase
= key
;
8725 original_uppercase_position
= t
- 1;
8727 modifiers
&= ~shift_modifier
;
8728 new_key
= apply_modifiers (modifiers
,
8731 keybuf
[t
- 1] = new_key
;
8734 fkey_map
= prev_fkey_map
;
8735 fkey_start
= prev_fkey_start
;
8736 fkey_end
= prev_fkey_end
;
8738 keytran_map
= prev_keytran_map
;
8739 keytran_start
= prev_keytran_start
;
8740 keytran_end
= prev_keytran_end
;
8742 goto replay_sequence
;
8748 read_key_sequence_cmd
= (first_binding
< nmaps
8749 ? defs
[first_binding
]
8752 unread_switch_frame
= delayed_switch_frame
;
8753 unbind_to (count
, Qnil
);
8755 /* Don't downcase the last character if the caller says don't.
8756 Don't downcase it if the result is undefined, either. */
8757 if ((dont_downcase_last
|| first_binding
>= nmaps
)
8758 && t
- 1 == original_uppercase_position
)
8759 keybuf
[t
- 1] = original_uppercase
;
8761 /* Occasionally we fabricate events, perhaps by expanding something
8762 according to function-key-map, or by adding a prefix symbol to a
8763 mouse click in the scroll bar or modeline. In this cases, return
8764 the entire generated key sequence, even if we hit an unbound
8765 prefix or a definition before the end. This means that you will
8766 be able to push back the event properly, and also means that
8767 read-key-sequence will always return a logical unit.
8770 for (; t
< mock_input
; t
++)
8772 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
8773 && NILP (Fzerop (Vecho_keystrokes
)))
8774 echo_char (keybuf
[t
]);
8775 add_command_key (keybuf
[t
]);
8783 #if 0 /* This doc string is too long for some compilers.
8784 This commented-out definition serves for DOC. */
8785 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
8786 "Read a sequence of keystrokes and return as a string or vector.\n\
8787 The sequence is sufficient to specify a non-prefix command in the\n\
8788 current local and global maps.\n\
8790 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
8791 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
8792 as a continuation of the previous key.\n\
8794 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not\n\
8795 convert the last event to lower case. (Normally any upper case event\n\
8796 is converted to lower case if the original event is undefined and the lower\n\
8797 case equivalent is defined.) A non-nil value is appropriate for reading\n\
8798 a key sequence to be defined.\n\
8800 A C-g typed while in this function is treated like any other character,\n\
8801 and `quit-flag' is not set.\n\
8803 If the key sequence starts with a mouse click, then the sequence is read\n\
8804 using the keymaps of the buffer of the window clicked in, not the buffer\n\
8805 of the selected window as normal.\n\
8807 `read-key-sequence' drops unbound button-down events, since you normally\n\
8808 only care about the click or drag events which follow them. If a drag\n\
8809 or multi-click event is unbound, but the corresponding click event would\n\
8810 be bound, `read-key-sequence' turns the event into a click event at the\n\
8811 drag's starting position. This means that you don't have to distinguish\n\
8812 between click and drag, double, or triple events unless you want to.\n\
8814 `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\
8815 lines separating windows, and scroll bars with imaginary keys\n\
8816 `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\
8818 Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this\n\
8819 function will process a switch-frame event if the user switches frames\n\
8820 before typing anything. If the user switches frames in the middle of a\n\
8821 key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME\n\
8822 is nil, then the event will be put off until after the current key sequence.\n\
8824 `read-key-sequence' checks `function-key-map' for function key\n\
8825 sequences, where they wouldn't conflict with ordinary bindings. See\n\
8826 `function-key-map' for more details.\n\
8828 The optional fifth argument COMMAND-LOOP, if non-nil, means\n\
8829 that this key sequence is being read by something that will\n\
8830 read commands one after another. It should be nil if the caller\n\
8831 will read just one key sequence.")
8832 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
, command
-loop
)
8835 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 5, 0,
8837 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
8839 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
8840 Lisp_Object can_return_switch_frame
, command_loop
;
8842 Lisp_Object keybuf
[30];
8844 struct gcpro gcpro1
;
8845 int count
= specpdl_ptr
- specpdl
;
8848 CHECK_STRING (prompt
, 0);
8851 specbind (Qinput_method_exit_on_first_char
,
8852 (NILP (command_loop
) ? Qt
: Qnil
));
8853 specbind (Qinput_method_use_echo_area
,
8854 (NILP (command_loop
) ? Qt
: Qnil
));
8856 bzero (keybuf
, sizeof keybuf
);
8858 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
8860 if (NILP (continue_echo
))
8862 this_command_key_count
= 0;
8863 this_single_command_key_start
= 0;
8866 #ifdef HAVE_X_WINDOWS
8867 if (display_busy_cursor_p
)
8868 cancel_busy_cursor ();
8871 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
8872 prompt
, ! NILP (dont_downcase_last
),
8873 ! NILP (can_return_switch_frame
), 0);
8875 #ifdef HAVE_X_WINDOWS
8876 if (display_busy_cursor_p
)
8877 start_busy_cursor ();
8886 return unbind_to (count
, make_event_array (i
, keybuf
));
8889 DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector
,
8890 Sread_key_sequence_vector
, 1, 5, 0,
8891 "Like `read-key-sequence' but always return a vector.")
8892 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
8894 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
8895 Lisp_Object can_return_switch_frame
, command_loop
;
8897 Lisp_Object keybuf
[30];
8899 struct gcpro gcpro1
;
8900 int count
= specpdl_ptr
- specpdl
;
8903 CHECK_STRING (prompt
, 0);
8906 specbind (Qinput_method_exit_on_first_char
,
8907 (NILP (command_loop
) ? Qt
: Qnil
));
8908 specbind (Qinput_method_use_echo_area
,
8909 (NILP (command_loop
) ? Qt
: Qnil
));
8911 bzero (keybuf
, sizeof keybuf
);
8913 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
8915 if (NILP (continue_echo
))
8917 this_command_key_count
= 0;
8918 this_single_command_key_start
= 0;
8921 #ifdef HAVE_X_WINDOWS
8922 if (display_busy_cursor_p
)
8923 cancel_busy_cursor ();
8926 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
8927 prompt
, ! NILP (dont_downcase_last
),
8928 ! NILP (can_return_switch_frame
), 0);
8930 #ifdef HAVE_X_WINDOWS
8931 if (display_busy_cursor_p
)
8932 start_busy_cursor ();
8941 return unbind_to (count
, Fvector (i
, keybuf
));
8944 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 4, 0,
8945 "Execute CMD as an editor command.\n\
8946 CMD must be a symbol that satisfies the `commandp' predicate.\n\
8947 Optional second arg RECORD-FLAG non-nil\n\
8948 means unconditionally put this command in `command-history'.\n\
8949 Otherwise, that is done only if an arg is read using the minibuffer.\n\
8950 The argument KEYS specifies the value to use instead of (this-command-keys)\n\
8951 when reading the arguments; if it is nil, (this-command-keys) is used.\n\
8952 The argument SPECIAL, if non-nil, means that this command is executing\n\
8953 a special event, so ignore the prefix argument and don't clear it.")
8954 (cmd
, record_flag
, keys
, special
)
8955 Lisp_Object cmd
, record_flag
, keys
, special
;
8957 register Lisp_Object final
;
8958 register Lisp_Object tem
;
8959 Lisp_Object prefixarg
;
8960 struct backtrace backtrace
;
8961 extern int debug_on_next_call
;
8963 debug_on_next_call
= 0;
8967 prefixarg
= current_kboard
->Vprefix_arg
;
8968 Vcurrent_prefix_arg
= prefixarg
;
8969 current_kboard
->Vprefix_arg
= Qnil
;
8976 tem
= Fget (cmd
, Qdisabled
);
8977 if (!NILP (tem
) && !NILP (Vrun_hooks
))
8979 tem
= Fsymbol_value (Qdisabled_command_hook
);
8981 return call1 (Vrun_hooks
, Qdisabled_command_hook
);
8987 final
= Findirect_function (cmd
);
8989 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
8991 struct gcpro gcpro1
, gcpro2
;
8993 GCPRO2 (cmd
, prefixarg
);
8994 do_autoload (final
, cmd
);
9001 if (STRINGP (final
) || VECTORP (final
))
9003 /* If requested, place the macro in the command history. For
9004 other sorts of commands, call-interactively takes care of
9006 if (!NILP (record_flag
))
9009 = Fcons (Fcons (Qexecute_kbd_macro
,
9010 Fcons (final
, Fcons (prefixarg
, Qnil
))),
9013 /* Don't keep command history around forever. */
9014 if (NUMBERP (Vhistory_length
) && XINT (Vhistory_length
) > 0)
9016 tem
= Fnthcdr (Vhistory_length
, Vcommand_history
);
9022 return Fexecute_kbd_macro (final
, prefixarg
);
9025 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
9027 backtrace
.next
= backtrace_list
;
9028 backtrace_list
= &backtrace
;
9029 backtrace
.function
= &Qcall_interactively
;
9030 backtrace
.args
= &cmd
;
9031 backtrace
.nargs
= 1;
9032 backtrace
.evalargs
= 0;
9034 tem
= Fcall_interactively (cmd
, record_flag
, keys
);
9036 backtrace_list
= backtrace
.next
;
9042 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
9044 "Read function name, then read its arguments and call it.")
9046 Lisp_Object prefixarg
;
9048 Lisp_Object function
;
9050 Lisp_Object saved_keys
;
9051 Lisp_Object bindings
, value
;
9052 struct gcpro gcpro1
, gcpro2
;
9054 saved_keys
= Fvector (this_command_key_count
,
9055 XVECTOR (this_command_keys
)->contents
);
9057 GCPRO2 (saved_keys
, prefixarg
);
9059 if (EQ (prefixarg
, Qminus
))
9061 else if (CONSP (prefixarg
) && XINT (XCAR (prefixarg
)) == 4)
9062 strcpy (buf
, "C-u ");
9063 else if (CONSP (prefixarg
) && INTEGERP (XCAR (prefixarg
)))
9065 if (sizeof (int) == sizeof (EMACS_INT
))
9066 sprintf (buf
, "%d ", XINT (XCAR (prefixarg
)));
9067 else if (sizeof (long) == sizeof (EMACS_INT
))
9068 sprintf (buf
, "%ld ", (long) XINT (XCAR (prefixarg
)));
9072 else if (INTEGERP (prefixarg
))
9074 if (sizeof (int) == sizeof (EMACS_INT
))
9075 sprintf (buf
, "%d ", XINT (prefixarg
));
9076 else if (sizeof (long) == sizeof (EMACS_INT
))
9077 sprintf (buf
, "%ld ", (long) XINT (prefixarg
));
9082 /* This isn't strictly correct if execute-extended-command
9083 is bound to anything else. Perhaps it should use
9084 this_command_keys? */
9085 strcat (buf
, "M-x ");
9087 /* Prompt with buf, and then read a string, completing from and
9088 restricting to the set of all defined commands. Don't provide
9089 any initial input. Save the command read on the extended-command
9091 function
= Fcompleting_read (build_string (buf
),
9092 Vobarray
, Qcommandp
,
9093 Qt
, Qnil
, Qextended_command_history
, Qnil
,
9096 if (STRINGP (function
) && XSTRING (function
)->size
== 0)
9097 error ("No command name given");
9099 /* Set this_command_keys to the concatenation of saved_keys and
9100 function, followed by a RET. */
9102 struct Lisp_String
*str
;
9106 this_command_key_count
= 0;
9107 this_single_command_key_start
= 0;
9109 keys
= XVECTOR (saved_keys
)->contents
;
9110 for (i
= 0; i
< XVECTOR (saved_keys
)->size
; i
++)
9111 add_command_key (keys
[i
]);
9113 str
= XSTRING (function
);
9114 for (i
= 0; i
< str
->size
; i
++)
9115 add_command_key (Faref (function
, make_number (i
)));
9117 add_command_key (make_number ('\015'));
9122 function
= Fintern (function
, Qnil
);
9123 current_kboard
->Vprefix_arg
= prefixarg
;
9124 Vthis_command
= function
;
9125 real_this_command
= function
;
9127 /* If enabled, show which key runs this command. */
9128 if (!NILP (Vsuggest_key_bindings
)
9129 && NILP (Vexecuting_macro
)
9130 && SYMBOLP (function
))
9131 bindings
= Fwhere_is_internal (function
, Voverriding_local_map
,
9137 GCPRO2 (bindings
, value
);
9138 value
= Fcommand_execute (function
, Qt
, Qnil
, Qnil
);
9140 /* If the command has a key binding, print it now. */
9141 if (!NILP (bindings
)
9142 && ! (VECTORP (bindings
) && EQ (Faref (bindings
, make_number (0)),
9145 /* But first wait, and skip the message if there is input. */
9147 if (!NILP (echo_area_buffer
[0]))
9148 /* This command displayed something in the echo area;
9149 so wait a few seconds, then display our suggestion message. */
9150 delay_time
= (NUMBERP (Vsuggest_key_bindings
)
9151 ? XINT (Vsuggest_key_bindings
) : 2);
9153 /* This command left the echo area empty,
9154 so display our message immediately. */
9157 if (!NILP (Fsit_for (make_number (delay_time
), Qnil
, Qnil
))
9158 && ! CONSP (Vunread_command_events
))
9160 Lisp_Object binding
;
9162 int message_p
= push_message ();
9164 binding
= Fkey_description (bindings
);
9167 = (char *) alloca (XSYMBOL (function
)->name
->size
9168 + STRING_BYTES (XSTRING (binding
))
9170 sprintf (newmessage
, "You can run the command `%s' with %s",
9171 XSYMBOL (function
)->name
->data
,
9172 XSTRING (binding
)->data
);
9173 message2_nolog (newmessage
,
9174 strlen (newmessage
),
9175 STRING_MULTIBYTE (binding
));
9176 if (!NILP (Fsit_for ((NUMBERP (Vsuggest_key_bindings
)
9177 ? Vsuggest_key_bindings
: make_number (2)),
9186 RETURN_UNGCPRO (value
);
9189 /* Find the set of keymaps now active.
9190 Store into *MAPS_P a vector holding the various maps
9191 and return the number of them. The vector was malloc'd
9192 and the caller should free it. */
9195 current_active_maps (maps_p
)
9196 Lisp_Object
**maps_p
;
9198 Lisp_Object
*tmaps
, *maps
;
9201 /* Should overriding-terminal-local-map and overriding-local-map apply? */
9202 if (!NILP (Voverriding_local_map_menu_flag
))
9204 /* Yes, use them (if non-nil) as well as the global map. */
9205 maps
= (Lisp_Object
*) xmalloc (3 * sizeof (maps
[0]));
9207 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
9208 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
9209 if (!NILP (Voverriding_local_map
))
9210 maps
[nmaps
++] = Voverriding_local_map
;
9214 /* No, so use major and minor mode keymaps and keymap property. */
9216 Lisp_Object map
= get_local_map (PT
, current_buffer
, keymap
);
9219 nmaps
= current_minor_maps (NULL
, &tmaps
);
9220 maps
= (Lisp_Object
*) alloca ((nmaps
+ extra_maps
)
9221 * sizeof (maps
[0]));
9222 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
9224 maps
[nmaps
++] = map
;
9225 maps
[nmaps
++] = get_local_map (PT
, current_buffer
, local_map
);
9227 maps
[nmaps
++] = current_global_map
;
9233 /* Return nonzero if input events are pending. */
9236 detect_input_pending ()
9239 get_input_pending (&input_pending
, 0);
9241 return input_pending
;
9244 /* Return nonzero if input events are pending, and run any pending timers. */
9247 detect_input_pending_run_timers (do_display
)
9250 int old_timers_run
= timers_run
;
9253 get_input_pending (&input_pending
, 1);
9255 if (old_timers_run
!= timers_run
&& do_display
)
9257 redisplay_preserve_echo_area ();
9258 /* The following fixes a bug when using lazy-lock with
9259 lazy-lock-defer-on-the-fly set to t, i.e. when fontifying
9260 from an idle timer function. The symptom of the bug is that
9261 the cursor sometimes doesn't become visible until the next X
9262 event is processed. --gerd. */
9264 rif
->flush_display (NULL
);
9267 return input_pending
;
9270 /* This is called in some cases before a possible quit.
9271 It cases the next call to detect_input_pending to recompute input_pending.
9272 So calling this function unnecessarily can't do any harm. */
9275 clear_input_pending ()
9280 /* Return nonzero if there are pending requeued events.
9281 This isn't used yet. The hope is to make wait_reading_process_input
9282 call it, and return return if it runs Lisp code that unreads something.
9283 The problem is, kbd_buffer_get_event needs to be fixed to know what
9284 to do in that case. It isn't trivial. */
9287 requeued_events_pending_p ()
9289 return (!NILP (Vunread_command_events
) || unread_command_char
!= -1);
9293 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
9294 "T if command input is currently available with no waiting.\n\
9295 Actually, the value is nil only if we can be sure that no input is available.")
9298 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1)
9301 get_input_pending (&input_pending
, 1);
9302 return input_pending
> 0 ? Qt
: Qnil
;
9305 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
9306 "Return vector of last 100 events, not counting those from keyboard macros.")
9309 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
9312 if (total_keys
< NUM_RECENT_KEYS
)
9313 return Fvector (total_keys
, keys
);
9316 val
= Fvector (NUM_RECENT_KEYS
, keys
);
9317 bcopy (keys
+ recent_keys_index
,
9318 XVECTOR (val
)->contents
,
9319 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
9321 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
9322 recent_keys_index
* sizeof (Lisp_Object
));
9327 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
9328 "Return the key sequence that invoked this command.\n\
9329 The value is a string or a vector.")
9332 return make_event_array (this_command_key_count
,
9333 XVECTOR (this_command_keys
)->contents
);
9336 DEFUN ("this-command-keys-vector", Fthis_command_keys_vector
, Sthis_command_keys_vector
, 0, 0, 0,
9337 "Return the key sequence that invoked this command, as a vector.")
9340 return Fvector (this_command_key_count
,
9341 XVECTOR (this_command_keys
)->contents
);
9344 DEFUN ("this-single-command-keys", Fthis_single_command_keys
,
9345 Sthis_single_command_keys
, 0, 0, 0,
9346 "Return the key sequence that invoked this command.\n\
9347 Unlike `this-command-keys', this function's value\n\
9348 does not include prefix arguments.\n\
9349 The value is always a vector.")
9352 return Fvector (this_command_key_count
9353 - this_single_command_key_start
,
9354 (XVECTOR (this_command_keys
)->contents
9355 + this_single_command_key_start
));
9358 DEFUN ("this-single-command-raw-keys", Fthis_single_command_raw_keys
,
9359 Sthis_single_command_raw_keys
, 0, 0, 0,
9360 "Return the raw events that were read for this command.\n\
9361 Unlike `this-single-command-keys', this function's value\n\
9362 shows the events before all translations (except for input methods).\n\
9363 The value is always a vector.")
9366 return Fvector (raw_keybuf_count
,
9367 (XVECTOR (raw_keybuf
)->contents
));
9370 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths
,
9371 Sreset_this_command_lengths
, 0, 0, 0,
9372 "Used for complicated reasons in `universal-argument-other-key'.\n\
9374 `universal-argument-other-key' rereads the event just typed.\n\
9375 It then gets translated through `function-key-map'.\n\
9376 The translated event gets included in the echo area and in\n\
9377 the value of `this-command-keys' in addition to the raw original event.\n\
9378 That is not right.\n\
9380 Calling this function directs the translated event to replace\n\
9381 the original event, so that only one version of the event actually\n\
9382 appears in the echo area and in the value of `this-command-keys.'.")
9385 before_command_restore_flag
= 1;
9386 before_command_key_count_1
= before_command_key_count
;
9387 before_command_echo_length_1
= before_command_echo_length
;
9391 DEFUN ("clear-this-command-keys", Fclear_this_command_keys
,
9392 Sclear_this_command_keys
, 0, 0, 0,
9393 "Clear out the vector that `this-command-keys' returns.\n\
9394 Clear vector containing last 100 events.")
9399 this_command_key_count
= 0;
9401 for (i
= 0; i
< XVECTOR (recent_keys
)->size
; ++i
)
9402 XVECTOR (recent_keys
)->contents
[i
] = Qnil
;
9404 recent_keys_index
= 0;
9408 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
9409 "Return the current depth in recursive edits.")
9413 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
9417 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
9418 "FOpen dribble file: ",
9419 "Start writing all keyboard characters to a dribble file called FILE.\n\
9420 If FILE is nil, close any open dribble file.")
9431 file
= Fexpand_file_name (file
, Qnil
);
9432 dribble
= fopen (XSTRING (file
)->data
, "w");
9434 report_file_error ("Opening dribble", Fcons (file
, Qnil
));
9439 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
9440 "Discard the contents of the terminal input buffer.\n\
9441 Also cancel any kbd macro being defined.")
9444 current_kboard
->defining_kbd_macro
= Qnil
;
9445 update_mode_lines
++;
9447 Vunread_command_events
= Qnil
;
9448 unread_command_char
= -1;
9450 discard_tty_input ();
9452 kbd_fetch_ptr
= kbd_store_ptr
;
9453 Ffillarray (kbd_buffer_gcpro
, Qnil
);
9459 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
9460 "Stop Emacs and return to superior process. You can resume later.\n\
9461 If `cannot-suspend' is non-nil, or if the system doesn't support job\n\
9462 control, run a subshell instead.\n\n\
9463 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
9464 to be read as terminal input by Emacs's parent, after suspension.\n\
9466 Before suspending, run the normal hook `suspend-hook'.\n\
9467 After resumption run the normal hook `suspend-resume-hook'.\n\
9469 Some operating systems cannot stop the Emacs process and resume it later.\n\
9470 On such systems, Emacs starts a subshell instead of suspending.")
9472 Lisp_Object stuffstring
;
9474 int count
= specpdl_ptr
- specpdl
;
9475 int old_height
, old_width
;
9477 struct gcpro gcpro1
;
9479 if (!NILP (stuffstring
))
9480 CHECK_STRING (stuffstring
, 0);
9482 /* Run the functions in suspend-hook. */
9483 if (!NILP (Vrun_hooks
))
9484 call1 (Vrun_hooks
, intern ("suspend-hook"));
9486 GCPRO1 (stuffstring
);
9487 get_frame_size (&old_width
, &old_height
);
9489 /* sys_suspend can get an error if it tries to fork a subshell
9490 and the system resources aren't available for that. */
9491 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object
))) init_sys_modes
,
9493 stuff_buffered_input (stuffstring
);
9498 unbind_to (count
, Qnil
);
9500 /* Check if terminal/window size has changed.
9501 Note that this is not useful when we are running directly
9502 with a window system; but suspend should be disabled in that case. */
9503 get_frame_size (&width
, &height
);
9504 if (width
!= old_width
|| height
!= old_height
)
9505 change_frame_size (SELECTED_FRAME (), height
, width
, 0, 0, 0);
9507 /* Run suspend-resume-hook. */
9508 if (!NILP (Vrun_hooks
))
9509 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
9515 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
9516 Then in any case stuff anything Emacs has read ahead and not used. */
9519 stuff_buffered_input (stuffstring
)
9520 Lisp_Object stuffstring
;
9522 /* stuff_char works only in BSD, versions 4.2 and up. */
9525 register unsigned char *p
;
9527 if (STRINGP (stuffstring
))
9531 p
= XSTRING (stuffstring
)->data
;
9532 count
= STRING_BYTES (XSTRING (stuffstring
));
9538 /* Anything we have read ahead, put back for the shell to read. */
9539 /* ?? What should this do when we have multiple keyboards??
9540 Should we ignore anything that was typed in at the "wrong" kboard? */
9541 for (; kbd_fetch_ptr
!= kbd_store_ptr
; kbd_fetch_ptr
++)
9545 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
9546 kbd_fetch_ptr
= kbd_buffer
;
9547 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
9548 stuff_char (kbd_fetch_ptr
->code
);
9550 kbd_fetch_ptr
->kind
= no_event
;
9551 idx
= 2 * (kbd_fetch_ptr
- kbd_buffer
);
9552 ASET (kbd_buffer_gcpro
, idx
, Qnil
);
9553 ASET (kbd_buffer_gcpro
, idx
+ 1, Qnil
);
9558 #endif /* BSD_SYSTEM and not BSD4_1 */
9562 set_waiting_for_input (time_to_clear
)
9563 EMACS_TIME
*time_to_clear
;
9565 input_available_clear_time
= time_to_clear
;
9567 /* Tell interrupt_signal to throw back to read_char, */
9568 waiting_for_input
= 1;
9570 /* If interrupt_signal was called before and buffered a C-g,
9571 make it run again now, to avoid timing error. */
9572 if (!NILP (Vquit_flag
))
9573 quit_throw_to_read_char ();
9577 clear_waiting_for_input ()
9579 /* Tell interrupt_signal not to throw back to read_char, */
9580 waiting_for_input
= 0;
9581 input_available_clear_time
= 0;
9584 /* This routine is called at interrupt level in response to C-G.
9586 If interrupt_input, this is the handler for SIGINT. Otherwise, it
9587 is called from kbd_buffer_store_event, in handling SIGIO or
9590 If `waiting_for_input' is non zero, then unless `echoing' is
9591 nonzero, immediately throw back to read_char.
9593 Otherwise it sets the Lisp variable quit-flag not-nil. This causes
9594 eval to throw, when it gets a chance. If quit-flag is already
9595 non-nil, it stops the job right away. */
9598 interrupt_signal (signalnum
) /* If we don't have an argument, */
9599 int signalnum
; /* some compilers complain in signal calls. */
9602 /* Must preserve main program's value of errno. */
9603 int old_errno
= errno
;
9604 struct frame
*sf
= SELECTED_FRAME ();
9606 #if defined (USG) && !defined (POSIX_SIGNALS)
9607 if (!read_socket_hook
&& NILP (Vwindow_system
))
9609 /* USG systems forget handlers when they are used;
9610 must reestablish each time */
9611 signal (SIGINT
, interrupt_signal
);
9612 signal (SIGQUIT
, interrupt_signal
);
9618 if (!NILP (Vquit_flag
)
9619 && (FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
)))
9621 /* If SIGINT isn't blocked, don't let us be interrupted by
9622 another SIGINT, it might be harmful due to non-reentrancy
9623 in I/O functions. */
9624 sigblock (sigmask (SIGINT
));
9629 #ifdef SIGTSTP /* Support possible in later USG versions */
9631 * On systems which can suspend the current process and return to the original
9632 * shell, this command causes the user to end up back at the shell.
9633 * The "Auto-save" and "Abort" questions are not asked until
9634 * the user elects to return to emacs, at which point he can save the current
9635 * job and either dump core or continue.
9640 if (sys_suspend () == -1)
9642 printf ("Not running as a subprocess;\n");
9643 printf ("you can continue or abort.\n");
9646 /* Perhaps should really fork an inferior shell?
9647 But that would not provide any way to get back
9648 to the original shell, ever. */
9649 printf ("No support for stopping a process on this operating system;\n");
9650 printf ("you can continue or abort.\n");
9651 #endif /* not VMS */
9652 #endif /* not SIGTSTP */
9654 /* We must remain inside the screen area when the internal terminal
9655 is used. Note that [Enter] is not echoed by dos. */
9658 /* It doesn't work to autosave while GC is in progress;
9659 the code used for auto-saving doesn't cope with the mark bit. */
9660 if (!gc_in_progress
)
9662 printf ("Auto-save? (y or n) ");
9664 if (((c
= getchar ()) & ~040) == 'Y')
9666 Fdo_auto_save (Qt
, Qnil
);
9668 printf ("\r\nAuto-save done");
9669 #else /* not MSDOS */
9670 printf ("Auto-save done\n");
9671 #endif /* not MSDOS */
9673 while (c
!= '\n') c
= getchar ();
9677 /* During GC, it must be safe to reenable quitting again. */
9678 Vinhibit_quit
= Qnil
;
9681 #endif /* not MSDOS */
9682 printf ("Garbage collection in progress; cannot auto-save now\r\n");
9683 printf ("but will instead do a real quit after garbage collection ends\r\n");
9688 printf ("\r\nAbort? (y or n) ");
9689 #else /* not MSDOS */
9691 printf ("Abort (and enter debugger)? (y or n) ");
9693 printf ("Abort (and dump core)? (y or n) ");
9694 #endif /* not VMS */
9695 #endif /* not MSDOS */
9697 if (((c
= getchar ()) & ~040) == 'Y')
9699 while (c
!= '\n') c
= getchar ();
9701 printf ("\r\nContinuing...\r\n");
9702 #else /* not MSDOS */
9703 printf ("Continuing...\n");
9704 #endif /* not MSDOS */
9711 /* If executing a function that wants to be interrupted out of
9712 and the user has not deferred quitting by binding `inhibit-quit'
9713 then quit right away. */
9714 if (immediate_quit
&& NILP (Vinhibit_quit
))
9716 struct gl_state_s saved
;
9717 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9722 GCPRO4 (saved
.object
, saved
.global_code
,
9723 saved
.current_syntax_table
, saved
.old_prop
);
9724 Fsignal (Qquit
, Qnil
);
9729 /* Else request quit when it's safe */
9733 if (waiting_for_input
&& !echoing
)
9734 quit_throw_to_read_char ();
9739 /* Handle a C-g by making read_char return C-g. */
9742 quit_throw_to_read_char ()
9745 /* Prevent another signal from doing this before we finish. */
9746 clear_waiting_for_input ();
9749 Vunread_command_events
= Qnil
;
9750 unread_command_char
= -1;
9752 #if 0 /* Currently, sit_for is called from read_char without turning
9753 off polling. And that can call set_waiting_for_input.
9754 It seems to be harmless. */
9755 #ifdef POLL_FOR_INPUT
9756 /* May be > 1 if in recursive minibuffer. */
9757 if (poll_suppress_count
== 0)
9761 if (FRAMEP (internal_last_event_frame
)
9762 && !EQ (internal_last_event_frame
, selected_frame
))
9763 do_switch_frame (make_lispy_switch_frame (internal_last_event_frame
),
9766 _longjmp (getcjmp
, 1);
9769 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
9770 "Set mode of reading keyboard input.\n\
9771 First arg INTERRUPT non-nil means use input interrupts;\n\
9772 nil means use CBREAK mode.\n\
9773 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
9774 (no effect except in CBREAK mode).\n\
9775 Third arg META t means accept 8-bit input (for a Meta key).\n\
9776 META nil means ignore the top bit, on the assumption it is parity.\n\
9777 Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\
9778 Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\
9779 See also `current-input-mode'.")
9780 (interrupt
, flow
, meta
, quit
)
9781 Lisp_Object interrupt
, flow
, meta
, quit
;
9784 && (!INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400))
9785 error ("set-input-mode: QUIT must be an ASCII character");
9787 #ifdef POLL_FOR_INPUT
9792 /* this causes startup screen to be restored and messes with the mouse */
9797 /* Note SIGIO has been undef'd if FIONREAD is missing. */
9798 if (read_socket_hook
)
9800 /* When using X, don't give the user a real choice,
9801 because we haven't implemented the mechanisms to support it. */
9802 #ifdef NO_SOCK_SIGIO
9803 interrupt_input
= 0;
9804 #else /* not NO_SOCK_SIGIO */
9805 interrupt_input
= 1;
9806 #endif /* NO_SOCK_SIGIO */
9809 interrupt_input
= !NILP (interrupt
);
9810 #else /* not SIGIO */
9811 interrupt_input
= 0;
9812 #endif /* not SIGIO */
9814 /* Our VMS input only works by interrupts, as of now. */
9816 interrupt_input
= 1;
9819 flow_control
= !NILP (flow
);
9822 else if (EQ (meta
, Qt
))
9827 /* Don't let this value be out of range. */
9828 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
9834 #ifdef POLL_FOR_INPUT
9835 poll_suppress_count
= 1;
9841 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
9842 "Return information about the way Emacs currently reads keyboard input.\n\
9843 The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
9844 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\
9845 nil, Emacs is using CBREAK mode.\n\
9846 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\
9847 terminal; this does not apply if Emacs uses interrupt-driven input.\n\
9848 META is t if accepting 8-bit input with 8th bit as Meta flag.\n\
9849 META nil means ignoring the top bit, on the assumption it is parity.\n\
9850 META is neither t nor nil if accepting 8-bit input and using\n\
9851 all 8 bits as the character code.\n\
9852 QUIT is the character Emacs currently uses to quit.\n\
9853 The elements of this list correspond to the arguments of\n\
9859 val
[0] = interrupt_input
? Qt
: Qnil
;
9860 val
[1] = flow_control
? Qt
: Qnil
;
9861 val
[2] = meta_key
== 2 ? make_number (0) : meta_key
== 1 ? Qt
: Qnil
;
9862 XSETFASTINT (val
[3], quit_char
);
9864 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
9869 * Set up a new kboard object with reasonable initial values.
9875 kb
->Voverriding_terminal_local_map
= Qnil
;
9876 kb
->Vlast_command
= Qnil
;
9877 kb
->Vreal_last_command
= Qnil
;
9878 kb
->Vprefix_arg
= Qnil
;
9879 kb
->Vlast_prefix_arg
= Qnil
;
9880 kb
->kbd_queue
= Qnil
;
9881 kb
->kbd_queue_has_data
= 0;
9882 kb
->immediate_echo
= 0;
9883 kb
->echoptr
= kb
->echobuf
;
9884 kb
->echo_after_prompt
= -1;
9885 kb
->kbd_macro_buffer
= 0;
9886 kb
->kbd_macro_bufsize
= 0;
9887 kb
->defining_kbd_macro
= Qnil
;
9888 kb
->Vlast_kbd_macro
= Qnil
;
9889 kb
->reference_count
= 0;
9890 kb
->Vsystem_key_alist
= Qnil
;
9891 kb
->system_key_syms
= Qnil
;
9892 kb
->Vdefault_minibuffer_frame
= Qnil
;
9896 * Destroy the contents of a kboard object, but not the object itself.
9897 * We use this just before deleting it, or if we're going to initialize
9904 if (kb
->kbd_macro_buffer
)
9905 xfree (kb
->kbd_macro_buffer
);
9914 for (kbp
= &all_kboards
; *kbp
!= kb
; kbp
= &(*kbp
)->next_kboard
)
9917 *kbp
= kb
->next_kboard
;
9926 /* This is correct before outermost invocation of the editor loop */
9927 command_loop_level
= -1;
9929 quit_char
= Ctl ('g');
9930 Vunread_command_events
= Qnil
;
9931 unread_command_char
= -1;
9932 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
9934 recent_keys_index
= 0;
9935 kbd_fetch_ptr
= kbd_buffer
;
9936 kbd_store_ptr
= kbd_buffer
;
9937 kbd_buffer_gcpro
= Fmake_vector (make_number (2 * KBD_BUFFER_SIZE
), Qnil
);
9939 do_mouse_tracking
= Qnil
;
9943 /* This means that command_loop_1 won't try to select anything the first
9945 internal_last_event_frame
= Qnil
;
9946 Vlast_event_frame
= internal_last_event_frame
;
9949 current_kboard
= initial_kboard
;
9951 wipe_kboard (current_kboard
);
9952 init_kboard (current_kboard
);
9954 if (!noninteractive
&& !read_socket_hook
&& NILP (Vwindow_system
))
9956 signal (SIGINT
, interrupt_signal
);
9957 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
9958 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
9959 SIGQUIT and we can't tell which one it will give us. */
9960 signal (SIGQUIT
, interrupt_signal
);
9961 #endif /* HAVE_TERMIO */
9963 /* Note SIGIO has been undef'd if FIONREAD is missing. */
9965 if (!noninteractive
)
9966 signal (SIGIO
, input_available_signal
);
9969 /* Use interrupt input by default, if it works and noninterrupt input
9970 has deficiencies. */
9972 #ifdef INTERRUPT_INPUT
9973 interrupt_input
= 1;
9975 interrupt_input
= 0;
9978 /* Our VMS input only works by interrupts, as of now. */
9980 interrupt_input
= 1;
9986 if (keyboard_init_hook
)
9987 (*keyboard_init_hook
) ();
9989 #ifdef POLL_FOR_INPUT
9990 poll_suppress_count
= 1;
9995 /* This type's only use is in syms_of_keyboard, to initialize the
9996 event header symbols and put properties on them. */
10003 struct event_head head_table
[] = {
10004 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
10005 &Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
,
10006 &Qswitch_frame
, "switch-frame", &Qswitch_frame
,
10007 &Qdelete_frame
, "delete-frame", &Qdelete_frame
,
10008 &Qiconify_frame
, "iconify-frame", &Qiconify_frame
,
10009 &Qmake_frame_visible
, "make-frame-visible", &Qmake_frame_visible
,
10013 syms_of_keyboard ()
10015 Vlispy_mouse_stem
= build_string ("mouse");
10016 staticpro (&Vlispy_mouse_stem
);
10019 QCimage
= intern (":image");
10020 staticpro (&QCimage
);
10022 staticpro (&Qhelp_echo
);
10023 Qhelp_echo
= intern ("help-echo");
10025 staticpro (&item_properties
);
10026 item_properties
= Qnil
;
10028 staticpro (&tool_bar_item_properties
);
10029 tool_bar_item_properties
= Qnil
;
10030 staticpro (&tool_bar_items_vector
);
10031 tool_bar_items_vector
= Qnil
;
10033 staticpro (&real_this_command
);
10034 real_this_command
= Qnil
;
10036 Qtimer_event_handler
= intern ("timer-event-handler");
10037 staticpro (&Qtimer_event_handler
);
10039 Qdisabled_command_hook
= intern ("disabled-command-hook");
10040 staticpro (&Qdisabled_command_hook
);
10042 Qself_insert_command
= intern ("self-insert-command");
10043 staticpro (&Qself_insert_command
);
10045 Qforward_char
= intern ("forward-char");
10046 staticpro (&Qforward_char
);
10048 Qbackward_char
= intern ("backward-char");
10049 staticpro (&Qbackward_char
);
10051 Qdisabled
= intern ("disabled");
10052 staticpro (&Qdisabled
);
10054 Qundefined
= intern ("undefined");
10055 staticpro (&Qundefined
);
10057 Qpre_command_hook
= intern ("pre-command-hook");
10058 staticpro (&Qpre_command_hook
);
10060 Qpost_command_hook
= intern ("post-command-hook");
10061 staticpro (&Qpost_command_hook
);
10063 Qpost_command_idle_hook
= intern ("post-command-idle-hook");
10064 staticpro (&Qpost_command_idle_hook
);
10066 Qdeferred_action_function
= intern ("deferred-action-function");
10067 staticpro (&Qdeferred_action_function
);
10069 Qcommand_hook_internal
= intern ("command-hook-internal");
10070 staticpro (&Qcommand_hook_internal
);
10072 Qfunction_key
= intern ("function-key");
10073 staticpro (&Qfunction_key
);
10074 Qmouse_click
= intern ("mouse-click");
10075 staticpro (&Qmouse_click
);
10077 Qmouse_wheel
= intern ("mouse-wheel");
10078 staticpro (&Qmouse_wheel
);
10079 Qlanguage_change
= intern ("language-change");
10080 staticpro (&Qlanguage_change
);
10082 Qdrag_n_drop
= intern ("drag-n-drop");
10083 staticpro (&Qdrag_n_drop
);
10085 Qusr1_signal
= intern ("usr1-signal");
10086 staticpro (&Qusr1_signal
);
10087 Qusr2_signal
= intern ("usr2-signal");
10088 staticpro (&Qusr2_signal
);
10090 Qmenu_enable
= intern ("menu-enable");
10091 staticpro (&Qmenu_enable
);
10092 Qmenu_alias
= intern ("menu-alias");
10093 staticpro (&Qmenu_alias
);
10094 QCenable
= intern (":enable");
10095 staticpro (&QCenable
);
10096 QCvisible
= intern (":visible");
10097 staticpro (&QCvisible
);
10098 QChelp
= intern (":help");
10099 staticpro (&QChelp
);
10100 QCfilter
= intern (":filter");
10101 staticpro (&QCfilter
);
10102 QCbutton
= intern (":button");
10103 staticpro (&QCbutton
);
10104 QCkeys
= intern (":keys");
10105 staticpro (&QCkeys
);
10106 QCkey_sequence
= intern (":key-sequence");
10107 staticpro (&QCkey_sequence
);
10108 QCtoggle
= intern (":toggle");
10109 staticpro (&QCtoggle
);
10110 QCradio
= intern (":radio");
10111 staticpro (&QCradio
);
10113 Qmode_line
= intern ("mode-line");
10114 staticpro (&Qmode_line
);
10115 Qvertical_line
= intern ("vertical-line");
10116 staticpro (&Qvertical_line
);
10117 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
10118 staticpro (&Qvertical_scroll_bar
);
10119 Qmenu_bar
= intern ("menu-bar");
10120 staticpro (&Qmenu_bar
);
10122 Qabove_handle
= intern ("above-handle");
10123 staticpro (&Qabove_handle
);
10124 Qhandle
= intern ("handle");
10125 staticpro (&Qhandle
);
10126 Qbelow_handle
= intern ("below-handle");
10127 staticpro (&Qbelow_handle
);
10128 Qup
= intern ("up");
10130 Qdown
= intern ("down");
10131 staticpro (&Qdown
);
10132 Qtop
= intern ("top");
10134 Qbottom
= intern ("bottom");
10135 staticpro (&Qbottom
);
10136 Qend_scroll
= intern ("end-scroll");
10137 staticpro (&Qend_scroll
);
10138 Qratio
= intern ("ratio");
10139 staticpro (&Qratio
);
10141 Qevent_kind
= intern ("event-kind");
10142 staticpro (&Qevent_kind
);
10143 Qevent_symbol_elements
= intern ("event-symbol-elements");
10144 staticpro (&Qevent_symbol_elements
);
10145 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
10146 staticpro (&Qevent_symbol_element_mask
);
10147 Qmodifier_cache
= intern ("modifier-cache");
10148 staticpro (&Qmodifier_cache
);
10150 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
10151 staticpro (&Qrecompute_lucid_menubar
);
10152 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
10153 staticpro (&Qactivate_menubar_hook
);
10155 Qpolling_period
= intern ("polling-period");
10156 staticpro (&Qpolling_period
);
10158 Qinput_method_function
= intern ("input-method-function");
10159 staticpro (&Qinput_method_function
);
10161 Qinput_method_exit_on_first_char
= intern ("input-method-exit-on-first-char");
10162 staticpro (&Qinput_method_exit_on_first_char
);
10163 Qinput_method_use_echo_area
= intern ("input-method-use-echo-area");
10164 staticpro (&Qinput_method_use_echo_area
);
10166 Fset (Qinput_method_exit_on_first_char
, Qnil
);
10167 Fset (Qinput_method_use_echo_area
, Qnil
);
10169 last_point_position_buffer
= Qnil
;
10172 struct event_head
*p
;
10174 for (p
= head_table
;
10175 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
10178 *p
->var
= intern (p
->name
);
10179 staticpro (p
->var
);
10180 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
10181 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
10185 button_down_location
= Fmake_vector (make_number (1), Qnil
);
10186 staticpro (&button_down_location
);
10187 mouse_syms
= Fmake_vector (make_number (1), Qnil
);
10188 staticpro (&mouse_syms
);
10192 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
10194 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
10195 for (i
= 0; i
< len
; i
++)
10196 if (modifier_names
[i
])
10197 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
10198 staticpro (&modifier_symbols
);
10201 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
10202 staticpro (&recent_keys
);
10204 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
10205 staticpro (&this_command_keys
);
10207 raw_keybuf
= Fmake_vector (make_number (30), Qnil
);
10208 staticpro (&raw_keybuf
);
10210 Qextended_command_history
= intern ("extended-command-history");
10211 Fset (Qextended_command_history
, Qnil
);
10212 staticpro (&Qextended_command_history
);
10214 kbd_buffer_gcpro
= Fmake_vector (make_number (2 * KBD_BUFFER_SIZE
), Qnil
);
10215 staticpro (&kbd_buffer_gcpro
);
10217 accent_key_syms
= Qnil
;
10218 staticpro (&accent_key_syms
);
10220 func_key_syms
= Qnil
;
10221 staticpro (&func_key_syms
);
10224 mouse_wheel_syms
= Qnil
;
10225 staticpro (&mouse_wheel_syms
);
10227 drag_n_drop_syms
= Qnil
;
10228 staticpro (&drag_n_drop_syms
);
10231 unread_switch_frame
= Qnil
;
10232 staticpro (&unread_switch_frame
);
10234 internal_last_event_frame
= Qnil
;
10235 staticpro (&internal_last_event_frame
);
10237 read_key_sequence_cmd
= Qnil
;
10238 staticpro (&read_key_sequence_cmd
);
10240 menu_bar_one_keymap_changed_items
= Qnil
;
10241 staticpro (&menu_bar_one_keymap_changed_items
);
10243 defsubr (&Sevent_convert_list
);
10244 defsubr (&Sread_key_sequence
);
10245 defsubr (&Sread_key_sequence_vector
);
10246 defsubr (&Srecursive_edit
);
10248 defsubr (&Strack_mouse
);
10250 defsubr (&Sinput_pending_p
);
10251 defsubr (&Scommand_execute
);
10252 defsubr (&Srecent_keys
);
10253 defsubr (&Sthis_command_keys
);
10254 defsubr (&Sthis_command_keys_vector
);
10255 defsubr (&Sthis_single_command_keys
);
10256 defsubr (&Sthis_single_command_raw_keys
);
10257 defsubr (&Sreset_this_command_lengths
);
10258 defsubr (&Sclear_this_command_keys
);
10259 defsubr (&Ssuspend_emacs
);
10260 defsubr (&Sabort_recursive_edit
);
10261 defsubr (&Sexit_recursive_edit
);
10262 defsubr (&Srecursion_depth
);
10263 defsubr (&Stop_level
);
10264 defsubr (&Sdiscard_input
);
10265 defsubr (&Sopen_dribble_file
);
10266 defsubr (&Sset_input_mode
);
10267 defsubr (&Scurrent_input_mode
);
10268 defsubr (&Sexecute_extended_command
);
10270 DEFVAR_LISP ("last-command-char", &last_command_char
,
10271 "Last input event that was part of a command.");
10273 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char
,
10274 "Last input event that was part of a command.");
10276 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
10277 "Last input event in a command, except for mouse menu events.\n\
10278 Mouse menus give back keys that don't look like mouse events;\n\
10279 this variable holds the actual mouse event that led to the menu,\n\
10280 so that you can determine whether the command was run by mouse or not.");
10282 DEFVAR_LISP ("last-input-char", &last_input_char
,
10283 "Last input event.");
10285 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char
,
10286 "Last input event.");
10288 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
10289 "List of events to be read as the command input.\n\
10290 These events are processed first, before actual keyboard input.");
10291 Vunread_command_events
= Qnil
;
10293 DEFVAR_INT ("unread-command-char", &unread_command_char
,
10294 "If not -1, an object to be read as next command input event.");
10296 DEFVAR_LISP ("unread-post-input-method-events", &Vunread_post_input_method_events
,
10297 "List of events to be processed as input by input methods.\n\
10298 These events are processed after `unread-command-events', but\n\
10299 before actual keyboard input.");
10300 Vunread_post_input_method_events
= Qnil
;
10302 DEFVAR_LISP ("unread-input-method-events", &Vunread_input_method_events
,
10303 "List of events to be processed as input by input methods.\n\
10304 These events are processed after `unread-command-events', but\n\
10305 before actual keyboard input.");
10306 Vunread_input_method_events
= Qnil
;
10308 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
10309 "Meta-prefix character code.\n\
10310 Meta-foo as command input turns into this character followed by foo.");
10311 XSETINT (meta_prefix_char
, 033);
10313 DEFVAR_KBOARD ("last-command", Vlast_command
,
10314 "The last command executed.\n\
10315 Normally a symbol with a function definition, but can be whatever was found\n\
10316 in the keymap, or whatever the variable `this-command' was set to by that\n\
10319 The value `mode-exit' is special; it means that the previous command\n\
10320 read an event that told it to exit, and it did so and unread that event.\n\
10321 In other words, the present command is the event that made the previous\n\
10324 The value `kill-region' is special; it means that the previous command\n\
10325 was a kill command.");
10327 DEFVAR_KBOARD ("real-last-command", Vreal_last_command
,
10328 "Same as `last-command', but never altered by Lisp code.");
10330 DEFVAR_LISP ("this-command", &Vthis_command
,
10331 "The command now being executed.\n\
10332 The command can set this variable; whatever is put here\n\
10333 will be in `last-command' during the following command.");
10334 Vthis_command
= Qnil
;
10336 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
10337 "*Number of input events between auto-saves.\n\
10338 Zero means disable autosaving due to number of characters typed.");
10339 auto_save_interval
= 300;
10341 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
10342 "*Number of seconds idle time before auto-save.\n\
10343 Zero or nil means disable auto-saving due to idleness.\n\
10344 After auto-saving due to this many seconds of idle time,\n\
10345 Emacs also does a garbage collection if that seems to be warranted.");
10346 XSETFASTINT (Vauto_save_timeout
, 30);
10348 DEFVAR_LISP ("echo-keystrokes", &Vecho_keystrokes
,
10349 "*Nonzero means echo unfinished commands after this many seconds of pause.\n\
10350 The value may be integer or floating point.");
10351 Vecho_keystrokes
= make_number (1);
10353 DEFVAR_INT ("polling-period", &polling_period
,
10354 "*Interval between polling for input during Lisp execution.\n\
10355 The reason for polling is to make C-g work to stop a running program.\n\
10356 Polling is needed only when using X windows and SIGIO does not work.\n\
10357 Polling is automatically disabled in all other cases.");
10358 polling_period
= 2;
10360 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
10361 "*Maximum time between mouse clicks to make a double-click.\n\
10362 Measured in milliseconds. nil means disable double-click recognition;\n\
10363 t means double-clicks have no time limit and are detected\n\
10364 by position only.");
10365 Vdouble_click_time
= make_number (500);
10367 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
10368 "*Non-nil means inhibit local map menu bar menus.");
10369 inhibit_local_menu_bar_menus
= 0;
10371 DEFVAR_INT ("num-input-keys", &num_input_keys
,
10372 "Number of complete key sequences read as input so far.\n\
10373 This includes key sequences read from keyboard macros.\n\
10374 The number is effectively the number of interactive command invocations.");
10375 num_input_keys
= 0;
10377 DEFVAR_INT ("num-nonmacro-input-events", &num_nonmacro_input_events
,
10378 "Number of input events read from the keyboard so far.\n\
10379 This does not include events generated by keyboard macros.");
10380 num_nonmacro_input_events
= 0;
10382 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
10383 "The frame in which the most recently read event occurred.\n\
10384 If the last event came from a keyboard macro, this is set to `macro'.");
10385 Vlast_event_frame
= Qnil
;
10387 /* This variable is set up in sysdep.c. */
10388 DEFVAR_LISP ("tty-erase-char", &Vtty_erase_char
,
10389 "The ERASE character as set by the user with stty.");
10391 DEFVAR_LISP ("help-char", &Vhelp_char
,
10392 "Character to recognize as meaning Help.\n\
10393 When it is read, do `(eval help-form)', and display result if it's a string.\n\
10394 If the value of `help-form' is nil, this char can be read normally.");
10395 XSETINT (Vhelp_char
, Ctl ('H'));
10397 DEFVAR_LISP ("help-event-list", &Vhelp_event_list
,
10398 "List of input events to recognize as meaning Help.\n\
10399 These work just like the value of `help-char' (see that).");
10400 Vhelp_event_list
= Qnil
;
10402 DEFVAR_LISP ("help-form", &Vhelp_form
,
10403 "Form to execute when character `help-char' is read.\n\
10404 If the form returns a string, that string is displayed.\n\
10405 If `help-form' is nil, the help char is not recognized.");
10408 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
10409 "Command to run when `help-char' character follows a prefix key.\n\
10410 This command is used only when there is no actual binding\n\
10411 for that character after that prefix key.");
10412 Vprefix_help_command
= Qnil
;
10414 DEFVAR_LISP ("top-level", &Vtop_level
,
10415 "Form to evaluate when Emacs starts up.\n\
10416 Useful to set before you dump a modified Emacs.");
10419 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
10420 "Translate table for keyboard input, or nil.\n\
10421 Each character is looked up in this string and the contents used instead.\n\
10422 The value may be a string, a vector, or a char-table.\n\
10423 If it is a string or vector of length N,\n\
10424 character codes N and up are untranslated.\n\
10425 In a vector or a char-table, an element which is nil means \"no translation\".");
10426 Vkeyboard_translate_table
= Qnil
;
10428 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
10429 "Non-nil means to always spawn a subshell instead of suspending.\n\
10430 \(Even if the operating system has support for stopping a process.\)");
10431 cannot_suspend
= 0;
10433 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
10434 "Non-nil means prompt with menus when appropriate.\n\
10435 This is done when reading from a keymap that has a prompt string,\n\
10436 for elements that have prompt strings.\n\
10437 The menu is displayed on the screen\n\
10438 if X menus were enabled at configuration\n\
10439 time and the previous event was a mouse click prefix key.\n\
10440 Otherwise, menu prompting uses the echo area.");
10441 menu_prompting
= 1;
10443 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
10444 "Character to see next line of menu prompt.\n\
10445 Type this character while in a menu prompt to rotate around the lines of it.");
10446 XSETINT (menu_prompt_more_char
, ' ');
10448 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
10449 "A mask of additional modifier keys to use with every keyboard character.\n\
10450 Emacs applies the modifiers of the character stored here to each keyboard\n\
10451 character it reads. For example, after evaluating the expression\n\
10452 (setq extra-keyboard-modifiers ?\\C-x)\n\
10453 all input characters will have the control modifier applied to them.\n\
10455 Note that the character ?\\C-@, equivalent to the integer zero, does\n\
10456 not count as a control character; rather, it counts as a character\n\
10457 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\
10458 cancels any modification.");
10459 extra_keyboard_modifiers
= 0;
10461 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
10462 "If an editing command sets this to t, deactivate the mark afterward.\n\
10463 The command loop sets this to nil before each command,\n\
10464 and tests the value when the command returns.\n\
10465 Buffer modification stores t in this variable.");
10466 Vdeactivate_mark
= Qnil
;
10468 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
10469 "Temporary storage of pre-command-hook or post-command-hook.");
10470 Vcommand_hook_internal
= Qnil
;
10472 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
10473 "Normal hook run before each command is executed.\n\
10474 If an unhandled error happens in running this hook,\n\
10475 the hook value is set to nil, since otherwise the error\n\
10476 might happen repeatedly and make Emacs nonfunctional.");
10477 Vpre_command_hook
= Qnil
;
10479 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
10480 "Normal hook run after each command is executed.\n\
10481 If an unhandled error happens in running this hook,\n\
10482 the hook value is set to nil, since otherwise the error\n\
10483 might happen repeatedly and make Emacs nonfunctional.");
10484 Vpost_command_hook
= Qnil
;
10486 DEFVAR_LISP ("post-command-idle-hook", &Vpost_command_idle_hook
,
10487 "Normal hook run after each command is executed, if idle.\n\
10488 Errors running the hook are caught and ignored.\n\
10489 This feature is obsolete; use idle timers instead. See `etc/NEWS'.");
10490 Vpost_command_idle_hook
= Qnil
;
10492 DEFVAR_INT ("post-command-idle-delay", &post_command_idle_delay
,
10493 "Delay time before running `post-command-idle-hook'.\n\
10494 This is measured in microseconds.");
10495 post_command_idle_delay
= 100000;
10498 DEFVAR_LISP ("echo-area-clear-hook", ...,
10499 "Normal hook run when clearing the echo area.");
10501 Qecho_area_clear_hook
= intern ("echo-area-clear-hook");
10502 XSYMBOL (Qecho_area_clear_hook
)->value
= Qnil
;
10504 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
10505 "t means menu bar, specified Lucid style, needs to be recomputed.");
10506 Vlucid_menu_bar_dirty_flag
= Qnil
;
10508 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
10509 "List of menu bar items to move to the end of the menu bar.\n\
10510 The elements of the list are event types that may have menu bar bindings.");
10511 Vmenu_bar_final_items
= Qnil
;
10513 DEFVAR_KBOARD ("overriding-terminal-local-map",
10514 Voverriding_terminal_local_map
,
10515 "Per-terminal keymap that overrides all other local keymaps.\n\
10516 If this variable is non-nil, it is used as a keymap instead of the\n\
10517 buffer's local map, and the minor mode keymaps and text property keymaps.\n\
10518 This variable is intended to let commands such as `universal-argumemnt'\n\
10519 set up a different keymap for reading the next command.");
10521 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
10522 "Keymap that overrides all other local keymaps.\n\
10523 If this variable is non-nil, it is used as a keymap instead of the\n\
10524 buffer's local map, and the minor mode keymaps and text property keymaps.");
10525 Voverriding_local_map
= Qnil
;
10527 DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag
,
10528 "Non-nil means `overriding-local-map' applies to the menu bar.\n\
10529 Otherwise, the menu bar continues to reflect the buffer's local map\n\
10530 and the minor mode maps regardless of `overriding-local-map'.");
10531 Voverriding_local_map_menu_flag
= Qnil
;
10533 DEFVAR_LISP ("special-event-map", &Vspecial_event_map
,
10534 "Keymap defining bindings for special events to execute at low level.");
10535 Vspecial_event_map
= Fcons (intern ("keymap"), Qnil
);
10537 DEFVAR_LISP ("track-mouse", &do_mouse_tracking
,
10538 "*Non-nil means generate motion events for mouse motion.");
10540 DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist
,
10541 "Alist of system-specific X windows key symbols.\n\
10542 Each element should have the form (N . SYMBOL) where N is the\n\
10543 numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\
10544 and SYMBOL is its name.");
10546 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
10547 "List of deferred actions to be performed at a later time.\n\
10548 The precise format isn't relevant here; we just check whether it is nil.");
10549 Vdeferred_action_list
= Qnil
;
10551 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
10552 "Function to call to handle deferred actions, after each command.\n\
10553 This function is called with no arguments after each command\n\
10554 whenever `deferred-action-list' is non-nil.");
10555 Vdeferred_action_function
= Qnil
;
10557 DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings
,
10558 "*Non-nil means show the equivalent key-binding when M-x command has one.\n\
10559 The value can be a length of time to show the message for.\n\
10560 If the value is non-nil and not a number, we wait 2 seconds.");
10561 Vsuggest_key_bindings
= Qt
;
10563 DEFVAR_LISP ("timer-list", &Vtimer_list
,
10564 "List of active absolute time timers in order of increasing time");
10565 Vtimer_list
= Qnil
;
10567 DEFVAR_LISP ("timer-idle-list", &Vtimer_idle_list
,
10568 "List of active idle-time timers in order of increasing time");
10569 Vtimer_idle_list
= Qnil
;
10571 DEFVAR_LISP ("input-method-function", &Vinput_method_function
,
10572 "If non-nil, the function that implements the current input method.\n\
10573 It's called with one argument, a printing character that was just read.\n\
10574 \(That means a character with code 040...0176.)\n\
10575 Typically this function uses `read-event' to read additional events.\n\
10576 When it does so, it should first bind `input-method-function' to nil\n\
10577 so it will not be called recursively.\n\
10579 The function should return a list of zero or more events\n\
10580 to be used as input. If it wants to put back some events\n\
10581 to be reconsidered, separately, by the input method,\n\
10582 it can add them to the beginning of `unread-command-events'.\n\
10584 The input method function can find in `input-method-previous-method'\n\
10585 the previous echo area message.\n\
10587 The input method function should refer to the variables\n\
10588 `input-method-use-echo-area' and `input-method-exit-on-first-char'\n\
10589 for guidance on what to do.");
10590 Vinput_method_function
= Qnil
;
10592 DEFVAR_LISP ("input-method-previous-message",
10593 &Vinput_method_previous_message
,
10594 "When `input-method-function' is called, hold the previous echo area message.\n\
10595 This variable exists because `read-event' clears the echo area\n\
10596 before running the input method. It is nil if there was no message.");
10597 Vinput_method_previous_message
= Qnil
;
10599 DEFVAR_LISP ("show-help-function", &Vshow_help_function
,
10600 "If non-nil, the function that implements the display of help.\n\
10601 It's called with one argument, the help string to display.");
10602 Vshow_help_function
= Qnil
;
10604 DEFVAR_LISP ("disable-point-adjustment", &Vdisable_point_adjustment
,
10605 "If non-nil, suppress point adjustment after executing a command.\n\
10607 After a command is executed, if point is moved into a region that has\n\
10608 special properties (e.g. composition, display), we adjust point to\n\
10609 the boundary of the region. But, several special commands sets this\n\
10610 variable to non-nil, then we suppress the point adjustment.\n\
10612 This variable is set to nil before reading a command, and is checked\n\
10613 just after executing the command");
10614 Vdisable_point_adjustment
= Qnil
;
10616 DEFVAR_LISP ("global-disable-point-adjustment",
10617 &Vglobal_disable_point_adjustment
,
10618 "*If non-nil, always suppress point adjustment.\n\
10620 The default value is nil, in which case, point adjustment are\n\
10621 suppressed only after special commands that set\n\
10622 `disable-point-adjustment' (which see) to non-nil.");
10623 Vglobal_disable_point_adjustment
= Qnil
;
10627 keys_of_keyboard ()
10629 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
10630 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
10631 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
10632 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
10633 initial_define_key (meta_map
, 'x', "execute-extended-command");
10635 initial_define_lispy_key (Vspecial_event_map
, "delete-frame",
10636 "handle-delete-frame");
10637 initial_define_lispy_key (Vspecial_event_map
, "iconify-frame",
10639 initial_define_lispy_key (Vspecial_event_map
, "make-frame-visible",