1 /* Keyboard and mouse input; editor command loop.
2 Copyright (C) 1985,86,87,88,89,93,94,95,96,97 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Allow config.h to undefine symbols found here. */
29 #include "termhooks.h"
37 #include "dispextern.h"
40 #include "intervals.h"
41 #include "blockinput.h"
51 #include <sys/ioctl.h>
53 #endif /* not MSDOS */
55 #include "syssignal.h"
58 /* This is to get the definitions of the XK_ symbols. */
65 #endif /* HAVE_NTGUI */
67 /* Include systime.h after xterm.h to avoid double inclusion of time.h. */
72 /* Variables for blockinput.h: */
74 /* Non-zero if interrupt input is blocked right now. */
75 int interrupt_input_blocked
;
77 /* Nonzero means an input interrupt has arrived
78 during the current critical section. */
79 int interrupt_input_pending
;
82 /* File descriptor to use for input. */
85 #ifdef HAVE_WINDOW_SYSTEM
86 /* Make all keyboard buffers much bigger when using X windows. */
87 #define KBD_BUFFER_SIZE 4096
88 #else /* No X-windows, character input */
89 #define KBD_BUFFER_SIZE 256
90 #endif /* No X-windows */
92 /* Following definition copied from eval.c */
96 struct backtrace
*next
;
97 Lisp_Object
*function
;
98 Lisp_Object
*args
; /* Points to vector of args. */
99 int nargs
; /* length of vector. If nargs is UNEVALLED,
100 args points to slot holding list of
106 KBOARD
*initial_kboard
;
107 KBOARD
*current_kboard
;
111 KBOARD the_only_kboard
;
114 /* Non-nil disable property on a command means
115 do not execute it; call disabled-command-hook's value instead. */
116 Lisp_Object Qdisabled
, Qdisabled_command_hook
;
118 #define NUM_RECENT_KEYS (100)
119 int recent_keys_index
; /* Index for storing next element into recent_keys */
120 int total_keys
; /* Total number of elements stored into recent_keys */
121 Lisp_Object recent_keys
; /* A vector, holding the last 100 keystrokes */
123 /* Vector holding the key sequence that invoked the current command.
124 It is reused for each command, and it may be longer than the current
125 sequence; this_command_key_count indicates how many elements
126 actually mean something.
127 It's easier to staticpro a single Lisp_Object than an array. */
128 Lisp_Object this_command_keys
;
129 int this_command_key_count
;
131 /* This vector is used as a buffer to record the events that were actually read
132 by read_key_sequence. */
133 Lisp_Object raw_keybuf
;
134 int raw_keybuf_count
;
136 #define GROW_RAW_KEYBUF \
137 if (raw_keybuf_count == XVECTOR (raw_keybuf)->size) \
139 int newsize = 2 * XVECTOR (raw_keybuf)->size; \
141 new = Fmake_vector (make_number (newsize), Qnil); \
142 bcopy (XVECTOR (raw_keybuf)->contents, XVECTOR (new)->contents, \
143 raw_keybuf_count * sizeof (Lisp_Object)); \
147 /* Number of elements of this_command_keys
148 that precede this key sequence. */
149 int this_single_command_key_start
;
151 /* Record values of this_command_key_count and echo_length ()
152 before this command was read. */
153 static int before_command_key_count
;
154 static int before_command_echo_length
;
155 /* Values of before_command_key_count and before_command_echo_length
156 saved by reset-this-command-lengths. */
157 static int before_command_key_count_1
;
158 static int before_command_echo_length_1
;
159 /* Flag set by reset-this-command-lengths,
160 saying to reset the lengths when add_command_key is called. */
161 static int before_command_restore_flag
;
163 extern int minbuf_level
;
165 extern int message_enable_multibyte
;
167 extern struct backtrace
*backtrace_list
;
169 /* Nonzero means do menu prompting. */
170 static int menu_prompting
;
172 /* Character to see next line of menu prompt. */
173 static Lisp_Object menu_prompt_more_char
;
175 /* For longjmp to where kbd input is being done. */
176 static jmp_buf getcjmp
;
178 /* True while doing kbd input. */
179 int waiting_for_input
;
181 /* True while displaying for echoing. Delays C-g throwing. */
184 /* True means we can start echoing at the next input pause
185 even though there is something in the echo area. */
186 static char *ok_to_echo_at_next_pause
;
188 /* Nonzero means disregard local maps for the menu bar. */
189 static int inhibit_local_menu_bar_menus
;
191 /* Nonzero means C-g should cause immediate error-signal. */
194 /* The user's ERASE setting. */
195 Lisp_Object Vtty_erase_char
;
197 /* Character to recognize as the help char. */
198 Lisp_Object Vhelp_char
;
200 /* List of other event types to recognize as meaning "help". */
201 Lisp_Object Vhelp_event_list
;
203 /* Form to execute when help char is typed. */
204 Lisp_Object Vhelp_form
;
206 /* Command to run when the help character follows a prefix key. */
207 Lisp_Object Vprefix_help_command
;
209 /* List of items that should move to the end of the menu bar. */
210 Lisp_Object Vmenu_bar_final_items
;
212 /* Non-nil means show the equivalent key-binding for
213 any M-x command that has one.
214 The value can be a length of time to show the message for.
215 If the value is non-nil and not a number, we wait 2 seconds. */
216 Lisp_Object Vsuggest_key_bindings
;
218 /* Character that causes a quit. Normally C-g.
220 If we are running on an ordinary terminal, this must be an ordinary
221 ASCII char, since we want to make it our interrupt character.
223 If we are not running on an ordinary terminal, it still needs to be
224 an ordinary ASCII char. This character needs to be recognized in
225 the input interrupt handler. At this point, the keystroke is
226 represented as a struct input_event, while the desired quit
227 character is specified as a lispy event. The mapping from struct
228 input_events to lispy events cannot run in an interrupt handler,
229 and the reverse mapping is difficult for anything but ASCII
232 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
236 extern Lisp_Object current_global_map
;
237 extern int minibuf_level
;
239 /* If non-nil, this is a map that overrides all other local maps. */
240 Lisp_Object Voverriding_local_map
;
242 /* If non-nil, Voverriding_local_map applies to the menu bar. */
243 Lisp_Object Voverriding_local_map_menu_flag
;
245 /* Keymap that defines special misc events that should
246 be processed immediately at a low level. */
247 Lisp_Object Vspecial_event_map
;
249 /* Current depth in recursive edits. */
250 int command_loop_level
;
252 /* Total number of times command_loop has read a key sequence. */
255 /* Last input character read as a command. */
256 Lisp_Object last_command_char
;
258 /* Last input character read as a command, not counting menus
259 reached by the mouse. */
260 Lisp_Object last_nonmenu_event
;
262 /* Last input character read for any purpose. */
263 Lisp_Object last_input_char
;
265 /* If not Qnil, a list of objects to be read as subsequent command input. */
266 Lisp_Object Vunread_command_events
;
268 /* If not Qnil, a list of objects to be read as subsequent command input
269 including input method processing. */
270 Lisp_Object Vunread_input_method_events
;
272 /* If not Qnil, a list of objects to be read as subsequent command input
273 but NOT including input method processing. */
274 Lisp_Object Vunread_post_input_method_events
;
276 /* If not -1, an event to be read as subsequent command input. */
277 int unread_command_char
;
279 /* If not Qnil, this is a switch-frame event which we decided to put
280 off until the end of a key sequence. This should be read as the
281 next command input, after any unread_command_events.
283 read_key_sequence uses this to delay switch-frame events until the
284 end of the key sequence; Fread_char uses it to put off switch-frame
285 events until a non-ASCII event is acceptable as input. */
286 Lisp_Object unread_switch_frame
;
288 /* A mask of extra modifier bits to put into every keyboard char. */
289 int extra_keyboard_modifiers
;
291 /* Char to use as prefix when a meta character is typed in.
292 This is bound on entry to minibuffer in case ESC is changed there. */
294 Lisp_Object meta_prefix_char
;
296 /* Last size recorded for a current buffer which is not a minibuffer. */
297 static int last_non_minibuf_size
;
299 /* Number of idle seconds before an auto-save and garbage collection. */
300 static Lisp_Object Vauto_save_timeout
;
302 /* Total number of times read_char has returned. */
303 int num_input_events
;
305 /* Total number of times read_char has returned, outside of macros. */
306 int num_nonmacro_input_events
;
308 /* Auto-save automatically when this many characters have been typed
309 since the last time. */
311 static int auto_save_interval
;
313 /* Value of num_nonmacro_input_events as of last auto save. */
317 /* The command being executed by the command loop.
318 Commands may set this, and the value set will be copied into
319 current_kboard->Vlast_command instead of the actual command. */
320 Lisp_Object Vthis_command
;
322 /* This is like Vthis_command, except that commands never set it. */
323 Lisp_Object real_this_command
;
325 /* The value of point when the last command was executed. */
326 int last_point_position
;
328 /* The buffer that was current when the last command was started. */
329 Lisp_Object last_point_position_buffer
;
331 /* The frame in which the last input event occurred, or Qmacro if the
332 last event came from a macro. We use this to determine when to
333 generate switch-frame events. This may be cleared by functions
334 like Fselect_frame, to make sure that a switch-frame event is
335 generated by the next character. */
336 Lisp_Object internal_last_event_frame
;
338 /* A user-visible version of the above, intended to allow users to
339 figure out where the last event came from, if the event doesn't
340 carry that information itself (i.e. if it was a character). */
341 Lisp_Object Vlast_event_frame
;
343 /* The timestamp of the last input event we received from the X server.
344 X Windows wants this for selection ownership. */
345 unsigned long last_event_timestamp
;
347 Lisp_Object Qself_insert_command
;
348 Lisp_Object Qforward_char
;
349 Lisp_Object Qbackward_char
;
350 Lisp_Object Qundefined
;
351 Lisp_Object Qtimer_event_handler
;
353 /* read_key_sequence stores here the command definition of the
354 key sequence that it reads. */
355 Lisp_Object read_key_sequence_cmd
;
357 /* Form to evaluate (if non-nil) when Emacs is started. */
358 Lisp_Object Vtop_level
;
360 /* User-supplied string to translate input characters through. */
361 Lisp_Object Vkeyboard_translate_table
;
363 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
364 extern Lisp_Object Vfunction_key_map
;
366 /* Another keymap that maps key sequences into key sequences.
367 This one takes precedence over ordinary definitions. */
368 extern Lisp_Object Vkey_translation_map
;
370 /* If non-nil, this implements the current input method. */
371 Lisp_Object Vinput_method_function
;
372 Lisp_Object Qinput_method_function
;
374 /* When we call Vinput_method_function,
375 this holds the echo area message that was just erased. */
376 Lisp_Object Vinput_method_previous_message
;
378 /* Non-nil means deactivate the mark at end of this command. */
379 Lisp_Object Vdeactivate_mark
;
381 /* Menu bar specified in Lucid Emacs fashion. */
383 Lisp_Object Vlucid_menu_bar_dirty_flag
;
384 Lisp_Object Qrecompute_lucid_menubar
, Qactivate_menubar_hook
;
386 Lisp_Object Qecho_area_clear_hook
;
388 /* Hooks to run before and after each command. */
389 Lisp_Object Qpre_command_hook
, Vpre_command_hook
;
390 Lisp_Object Qpost_command_hook
, Vpost_command_hook
;
391 Lisp_Object Qcommand_hook_internal
, Vcommand_hook_internal
;
392 /* Hook run after a command if there's no more input soon. */
393 Lisp_Object Qpost_command_idle_hook
, Vpost_command_idle_hook
;
395 /* Delay time in microseconds before running post-command-idle-hook. */
396 int post_command_idle_delay
;
398 /* List of deferred actions to be performed at a later time.
399 The precise format isn't relevant here; we just check whether it is nil. */
400 Lisp_Object Vdeferred_action_list
;
402 /* Function to call to handle deferred actions, when there are any. */
403 Lisp_Object Vdeferred_action_function
;
404 Lisp_Object Qdeferred_action_function
;
406 Lisp_Object Qinput_method_exit_on_first_char
;
407 Lisp_Object Qinput_method_use_echo_area
;
409 /* File in which we write all commands we read. */
412 /* Nonzero if input is available. */
415 /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
416 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
420 extern char *pending_malloc_warning
;
422 /* Circular buffer for pre-read keyboard input. */
423 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
425 /* Vector to GCPRO the frames and windows mentioned in kbd_buffer.
427 The interrupt-level event handlers will never enqueue an event on a
428 frame which is not in Vframe_list, and once an event is dequeued,
429 internal_last_event_frame or the event itself points to the frame.
432 But while the event is sitting in the queue, it's completely
433 unprotected. Suppose the user types one command which will run for
434 a while and then delete a frame, and then types another event at
435 the frame that will be deleted, before the command gets around to
436 it. Suppose there are no references to this frame elsewhere in
437 Emacs, and a GC occurs before the second event is dequeued. Now we
438 have an event referring to a freed frame, which will crash Emacs
441 Similar things happen when an event on a scroll bar is enqueued; the
442 window may be deleted while the event is in the queue.
444 So, we use this vector to protect the frame_or_window field in the
445 event queue. That way, they'll be dequeued as dead frames or
446 windows, but still valid lisp objects.
448 If kbd_buffer[i].kind != no_event, then
449 (XVECTOR (kbd_buffer_frame_or_window)->contents[i]
450 == kbd_buffer[i].frame_or_window. */
451 static Lisp_Object kbd_buffer_frame_or_window
;
453 /* Pointer to next available character in kbd_buffer.
454 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
455 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the
456 next available char is in kbd_buffer[0]. */
457 static struct input_event
*kbd_fetch_ptr
;
459 /* Pointer to next place to store character in kbd_buffer. This
460 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
461 character should go in kbd_buffer[0]. */
462 static volatile struct input_event
*kbd_store_ptr
;
464 /* The above pair of variables forms a "queue empty" flag. When we
465 enqueue a non-hook event, we increment kbd_store_ptr. When we
466 dequeue a non-hook event, we increment kbd_fetch_ptr. We say that
467 there is input available iff the two pointers are not equal.
469 Why not just have a flag set and cleared by the enqueuing and
470 dequeuing functions? Such a flag could be screwed up by interrupts
471 at inopportune times. */
473 /* If this flag is non-nil, we check mouse_moved to see when the
474 mouse moves, and motion events will appear in the input stream.
475 Otherwise, mouse motion is ignored. */
476 static Lisp_Object do_mouse_tracking
;
478 /* Symbols to head events. */
479 Lisp_Object Qmouse_movement
;
480 Lisp_Object Qscroll_bar_movement
;
481 Lisp_Object Qswitch_frame
;
482 Lisp_Object Qdelete_frame
;
483 Lisp_Object Qiconify_frame
;
484 Lisp_Object Qmake_frame_visible
;
486 /* Symbols to denote kinds of events. */
487 Lisp_Object Qfunction_key
;
488 Lisp_Object Qmouse_click
;
490 Lisp_Object Qmouse_wheel
;
492 Lisp_Object Qdrag_n_drop
;
493 /* Lisp_Object Qmouse_movement; - also an event header */
495 /* Properties of event headers. */
496 Lisp_Object Qevent_kind
;
497 Lisp_Object Qevent_symbol_elements
;
499 /* menu item parts */
500 Lisp_Object Qmenu_alias
;
501 Lisp_Object Qmenu_enable
;
502 Lisp_Object QCenable
, QCvisible
, QChelp
, QCfilter
, QCkeys
, QCkey_sequence
;
503 Lisp_Object QCbutton
, QCtoggle
, QCradio
;
504 extern Lisp_Object Vdefine_key_rebound_commands
;
505 extern Lisp_Object Qmenu_item
;
507 /* An event header symbol HEAD may have a property named
508 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
509 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
510 mask of modifiers applied to it. If present, this is used to help
511 speed up parse_modifiers. */
512 Lisp_Object Qevent_symbol_element_mask
;
514 /* An unmodified event header BASE may have a property named
515 Qmodifier_cache, which is an alist mapping modifier masks onto
516 modified versions of BASE. If present, this helps speed up
518 Lisp_Object Qmodifier_cache
;
520 /* Symbols to use for parts of windows. */
521 Lisp_Object Qmode_line
;
522 Lisp_Object Qvertical_line
;
523 Lisp_Object Qvertical_scroll_bar
;
524 Lisp_Object Qmenu_bar
;
526 Lisp_Object
recursive_edit_unwind (), command_loop ();
527 Lisp_Object
Fthis_command_keys ();
528 Lisp_Object Qextended_command_history
;
529 EMACS_TIME
timer_check ();
531 extern Lisp_Object Vhistory_length
;
533 extern char *x_get_keysym_name ();
535 static void record_menu_key ();
537 Lisp_Object Qpolling_period
;
539 /* List of absolute timers. Appears in order of next scheduled event. */
540 Lisp_Object Vtimer_list
;
542 /* List of idle time timers. Appears in order of next scheduled event. */
543 Lisp_Object Vtimer_idle_list
;
545 /* Incremented whenever a timer is run. */
548 extern Lisp_Object Vprint_level
, Vprint_length
;
550 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
552 EMACS_TIME
*input_available_clear_time
;
554 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
555 Default is 1 if INTERRUPT_INPUT is defined. */
558 /* Nonzero while interrupts are temporarily deferred during redisplay. */
559 int interrupts_deferred
;
561 /* Nonzero means use ^S/^Q for flow control. */
564 /* Allow m- file to inhibit use of FIONREAD. */
565 #ifdef BROKEN_FIONREAD
569 /* We are unable to use interrupts if FIONREAD is not available,
570 so flush SIGIO so we won't try. */
577 /* If we support a window system, turn on the code to poll periodically
578 to detect C-g. It isn't actually used when doing interrupt input. */
579 #ifdef HAVE_WINDOW_SYSTEM
580 #define POLL_FOR_INPUT
583 /* Global variable declarations. */
585 /* Function for init_keyboard to call with no args (if nonzero). */
586 void (*keyboard_init_hook
) ();
588 static int read_avail_input ();
589 static void get_input_pending ();
590 static int readable_events ();
591 static Lisp_Object
read_char_x_menu_prompt ();
592 static Lisp_Object
read_char_minibuf_menu_prompt ();
593 static Lisp_Object
make_lispy_event ();
595 static Lisp_Object
make_lispy_movement ();
597 static Lisp_Object
modify_event_symbol ();
598 static Lisp_Object
make_lispy_switch_frame ();
599 static int parse_solitary_modifier ();
600 static void save_getcjmp ();
601 static void restore_getcjmp ();
603 /* > 0 if we are to echo keystrokes. */
604 static int echo_keystrokes
;
606 /* Nonzero means don't try to suspend even if the operating system seems
608 static int cannot_suspend
;
610 #define min(a,b) ((a)<(b)?(a):(b))
611 #define max(a,b) ((a)>(b)?(a):(b))
613 /* Install the string STR as the beginning of the string of echoing,
614 so that it serves as a prompt for the next character.
615 Also start echoing. */
621 int len
= strlen (str
);
623 if (len
> ECHOBUFSIZE
- 4)
624 len
= ECHOBUFSIZE
- 4;
625 bcopy (str
, current_kboard
->echobuf
, len
);
626 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
627 *current_kboard
->echoptr
= '\0';
629 current_kboard
->echo_after_prompt
= len
;
634 /* Add C to the echo string, if echoing is going on.
635 C can be a character, which is printed prettily ("M-C-x" and all that
636 jazz), or a symbol, whose name is printed. */
642 extern char *push_key_description ();
644 if (current_kboard
->immediate_echo
)
646 char *ptr
= current_kboard
->echoptr
;
648 if (ptr
!= current_kboard
->echobuf
)
651 /* If someone has passed us a composite event, use its head symbol. */
656 if (ptr
- current_kboard
->echobuf
> ECHOBUFSIZE
- 6)
659 ptr
= push_key_description (XINT (c
), ptr
);
661 else if (SYMBOLP (c
))
663 struct Lisp_String
*name
= XSYMBOL (c
)->name
;
664 if ((ptr
- current_kboard
->echobuf
) + STRING_BYTES (name
) + 4
667 bcopy (name
->data
, ptr
, STRING_BYTES (name
));
668 ptr
+= STRING_BYTES (name
);
671 if (current_kboard
->echoptr
== current_kboard
->echobuf
674 strcpy (ptr
, " (Type ? for further options)");
679 current_kboard
->echoptr
= ptr
;
685 /* Temporarily add a dash to the end of the echo string if it's not
686 empty, so that it serves as a mini-prompt for the very next character. */
691 if (!current_kboard
->immediate_echo
692 && current_kboard
->echoptr
== current_kboard
->echobuf
)
694 /* Do nothing if we just printed a prompt. */
695 if (current_kboard
->echo_after_prompt
696 == current_kboard
->echoptr
- current_kboard
->echobuf
)
698 /* Do nothing if not echoing at all. */
699 if (current_kboard
->echoptr
== 0)
702 /* Put a dash at the end of the buffer temporarily,
703 but make it go away when the next character is added. */
704 current_kboard
->echoptr
[0] = '-';
705 current_kboard
->echoptr
[1] = 0;
710 /* Display the current echo string, and begin echoing if not already
716 if (!current_kboard
->immediate_echo
)
719 current_kboard
->immediate_echo
= 1;
721 for (i
= 0; i
< this_command_key_count
; i
++)
724 c
= XVECTOR (this_command_keys
)->contents
[i
];
725 if (! (EVENT_HAS_PARAMETERS (c
)
726 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
733 message2_nolog (current_kboard
->echobuf
, strlen (current_kboard
->echobuf
),
734 ! NILP (current_buffer
->enable_multibyte_characters
));
738 if (waiting_for_input
&& !NILP (Vquit_flag
))
739 quit_throw_to_read_char ();
742 /* Turn off echoing, for the start of a new command. */
747 current_kboard
->immediate_echo
= 0;
748 current_kboard
->echoptr
= current_kboard
->echobuf
;
749 current_kboard
->echo_after_prompt
= -1;
750 ok_to_echo_at_next_pause
= 0;
753 /* Return the length of the current echo string. */
758 return current_kboard
->echoptr
- current_kboard
->echobuf
;
761 /* Truncate the current echo message to its first LEN chars.
762 This and echo_char get used by read_key_sequence when the user
763 switches frames while entering a key sequence. */
769 current_kboard
->echobuf
[len
] = '\0';
770 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
771 truncate_echo_area (len
);
775 /* Functions for manipulating this_command_keys. */
777 add_command_key (key
)
780 int size
= XVECTOR (this_command_keys
)->size
;
782 /* If reset-this-command-length was called recently, obey it now.
783 See the doc string of that function for an explanation of why. */
784 if (before_command_restore_flag
)
786 this_command_key_count
= before_command_key_count_1
;
787 if (this_command_key_count
< this_single_command_key_start
)
788 this_single_command_key_start
= this_command_key_count
;
789 echo_truncate (before_command_echo_length_1
);
790 before_command_restore_flag
= 0;
793 if (this_command_key_count
>= size
)
795 Lisp_Object new_keys
;
797 new_keys
= Fmake_vector (make_number (size
* 2), Qnil
);
798 bcopy (XVECTOR (this_command_keys
)->contents
,
799 XVECTOR (new_keys
)->contents
,
800 size
* sizeof (Lisp_Object
));
802 this_command_keys
= new_keys
;
805 XVECTOR (this_command_keys
)->contents
[this_command_key_count
++] = key
;
811 int count
= specpdl_ptr
- specpdl
;
814 if (command_loop_level
> 0)
816 specbind (Qstandard_output
, Qt
);
817 specbind (Qstandard_input
, Qt
);
820 val
= command_loop ();
822 Fsignal (Qquit
, Qnil
);
823 /* Handle throw from read_minibuf when using minibuffer
824 while it's active but we're in another window. */
826 Fsignal (Qerror
, Fcons (val
, Qnil
));
828 return unbind_to (count
, Qnil
);
831 /* When an auto-save happens, record the "time", and don't do again soon. */
836 last_auto_save
= num_nonmacro_input_events
;
839 /* Make an auto save happen as soon as possible at command level. */
842 force_auto_save_soon ()
844 last_auto_save
= - auto_save_interval
- 1;
846 record_asynch_buffer_change ();
849 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
850 "Invoke the editor command loop recursively.\n\
851 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
852 that tells this function to return.\n\
853 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
854 This function is called by the editor initialization to begin editing.")
857 int count
= specpdl_ptr
- specpdl
;
860 command_loop_level
++;
861 update_mode_lines
= 1;
863 record_unwind_protect (recursive_edit_unwind
,
865 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
869 return unbind_to (count
, Qnil
);
873 recursive_edit_unwind (buffer
)
877 Fset_buffer (buffer
);
879 command_loop_level
--;
880 update_mode_lines
= 1;
888 #if 0 /* Theory: if there's anything in Vunread_command_events,
889 it will right away be read by read_key_sequence,
890 and then if we do switch KBOARDS, it will go into the side
891 queue then. So we don't need to do anything special here -- rms. */
892 if (CONSP (Vunread_command_events
))
894 current_kboard
->kbd_queue
895 = nconc2 (Vunread_command_events
, current_kboard
->kbd_queue
);
896 current_kboard
->kbd_queue_has_data
= 1;
898 Vunread_command_events
= Qnil
;
904 /* Switch to the single-kboard state, making current_kboard
905 the only KBOARD from which further input is accepted. */
908 single_kboard_state ()
915 /* Maintain a stack of kboards, so other parts of Emacs
916 can switch temporarily to the kboard of a given frame
917 and then revert to the previous status. */
922 struct kboard_stack
*next
;
925 static struct kboard_stack
*kboard_stack
;
928 push_frame_kboard (f
)
932 struct kboard_stack
*p
933 = (struct kboard_stack
*) xmalloc (sizeof (struct kboard_stack
));
935 p
->next
= kboard_stack
;
936 p
->kboard
= current_kboard
;
939 current_kboard
= FRAME_KBOARD (f
);
947 struct kboard_stack
*p
= kboard_stack
;
948 current_kboard
= p
->kboard
;
949 kboard_stack
= p
->next
;
954 /* Handle errors that are not handled at inner levels
955 by printing an error message and returning to the editor command loop. */
961 Lisp_Object old_level
, old_length
;
964 if (!NILP (executing_macro
))
966 if (executing_macro_iterations
== 1)
967 sprintf (macroerror
, "After 1 kbd macro iteration: ");
969 sprintf (macroerror
, "After %d kbd macro iterations: ",
970 executing_macro_iterations
);
975 Vstandard_output
= Qt
;
976 Vstandard_input
= Qt
;
977 Vexecuting_macro
= Qnil
;
978 executing_macro
= Qnil
;
979 current_kboard
->Vprefix_arg
= Qnil
;
980 current_kboard
->Vlast_prefix_arg
= Qnil
;
983 /* Avoid unquittable loop if data contains a circular list. */
984 old_level
= Vprint_level
;
985 old_length
= Vprint_length
;
986 XSETFASTINT (Vprint_level
, 10);
987 XSETFASTINT (Vprint_length
, 10);
988 cmd_error_internal (data
, macroerror
);
989 Vprint_level
= old_level
;
990 Vprint_length
= old_length
;
994 Vinhibit_quit
= Qnil
;
999 return make_number (0);
1002 /* Take actions on handling an error. DATA is the data that describes
1005 CONTEXT is a C-string containing ASCII characters only which
1006 describes the context in which the error happened. If we need to
1007 generalize CONTEXT to allow multibyte characters, make it a Lisp
1011 cmd_error_internal (data
, context
)
1019 echo_area_glyphs
= 0;
1021 /* If the window system or terminal frame hasn't been initialized
1022 yet, or we're not interactive, it's best to dump this message out
1023 to stderr and exit. */
1024 if (! FRAME_MESSAGE_BUF (selected_frame
)
1026 stream
= Qexternal_debugging_output
;
1035 write_string_1 (context
, -1, stream
);
1037 print_error_message (data
, stream
);
1039 /* If the window system or terminal frame hasn't been initialized
1040 yet, or we're in -batch mode, this error should cause Emacs to exit. */
1041 if (! FRAME_MESSAGE_BUF (selected_frame
)
1045 Fkill_emacs (make_number (-1));
1049 Lisp_Object
command_loop_1 ();
1050 Lisp_Object
command_loop_2 ();
1051 Lisp_Object
top_level_1 ();
1053 /* Entry to editor-command-loop.
1054 This level has the catches for exiting/returning to editor command loop.
1055 It returns nil to exit recursive edit, t to abort it. */
1060 if (command_loop_level
> 0 || minibuf_level
> 0)
1062 Lisp_Object val
= internal_catch (Qexit
, command_loop_2
, Qnil
);
1063 executing_macro
= Qnil
;
1069 internal_catch (Qtop_level
, top_level_1
, Qnil
);
1070 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
1071 executing_macro
= Qnil
;
1073 /* End of file in -batch run causes exit here. */
1079 /* Here we catch errors in execution of commands within the
1080 editing loop, and reenter the editing loop.
1081 When there is an error, cmd_error runs and returns a non-nil
1082 value to us. A value of nil means that cmd_loop_1 itself
1083 returned due to end of file (or end of kbd macro). */
1088 register Lisp_Object val
;
1091 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
1092 while (!NILP (val
));
1100 return Feval (Vtop_level
);
1106 /* On entry to the outer level, run the startup file */
1107 if (!NILP (Vtop_level
))
1108 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
1109 else if (!NILP (Vpurify_flag
))
1110 message ("Bare impure Emacs (standard Lisp code not loaded)");
1112 message ("Bare Emacs (standard Lisp code not loaded)");
1116 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
1117 "Exit all recursive editing levels.")
1120 Fthrow (Qtop_level
, Qnil
);
1123 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
1124 "Exit from the innermost recursive edit or minibuffer.")
1127 if (command_loop_level
> 0 || minibuf_level
> 0)
1128 Fthrow (Qexit
, Qnil
);
1130 error ("No recursive edit is in progress");
1133 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
1134 "Abort the command that requested this recursive edit or minibuffer input.")
1137 if (command_loop_level
> 0 || minibuf_level
> 0)
1140 error ("No recursive edit is in progress");
1143 /* This is the actual command reading loop,
1144 sans error-handling encapsulation. */
1146 Lisp_Object
Fcommand_execute ();
1147 static int read_key_sequence ();
1148 void safe_run_hooks ();
1153 Lisp_Object cmd
, tem
;
1156 Lisp_Object keybuf
[30];
1161 struct buffer
*prev_buffer
;
1163 int was_locked
= single_kboard
;
1166 current_kboard
->Vprefix_arg
= Qnil
;
1167 current_kboard
->Vlast_prefix_arg
= Qnil
;
1168 Vdeactivate_mark
= Qnil
;
1169 waiting_for_input
= 0;
1174 this_command_key_count
= 0;
1175 this_single_command_key_start
= 0;
1177 /* Make sure this hook runs after commands that get errors and
1178 throw to top level. */
1179 /* Note that the value cell will never directly contain nil
1180 if the symbol is a local variable. */
1181 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1182 safe_run_hooks (Qpost_command_hook
);
1184 if (!NILP (Vdeferred_action_list
))
1185 call0 (Vdeferred_action_function
);
1187 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1189 if (NILP (Vunread_command_events
)
1190 && NILP (Vunread_input_method_events
)
1191 && NILP (Vunread_post_input_method_events
)
1192 && NILP (Vexecuting_macro
)
1193 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1, 1)))
1194 safe_run_hooks (Qpost_command_idle_hook
);
1197 /* Do this after running Vpost_command_hook, for consistency. */
1198 current_kboard
->Vlast_command
= Vthis_command
;
1199 current_kboard
->Vreal_last_command
= real_this_command
;
1203 /* Make sure the current window's buffer is selected. */
1204 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1205 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1207 /* Display any malloc warning that just came out. Use while because
1208 displaying one warning can cause another. */
1210 while (pending_malloc_warning
)
1211 display_malloc_warning ();
1215 Vdeactivate_mark
= Qnil
;
1217 /* If minibuffer on and echo area in use,
1218 wait 2 sec and redraw minibuffer. */
1220 if (minibuf_level
&& echo_area_glyphs
1221 && EQ (minibuf_window
, echo_area_window
))
1223 /* Bind inhibit-quit to t so that C-g gets read in
1224 rather than quitting back to the minibuffer. */
1225 int count
= specpdl_ptr
- specpdl
;
1226 specbind (Qinhibit_quit
, Qt
);
1228 Fsit_for (make_number (2), Qnil
, Qnil
);
1229 /* Clear the echo area. */
1231 safe_run_hooks (Qecho_area_clear_hook
);
1233 unbind_to (count
, Qnil
);
1235 /* If a C-g came in before, treat it as input now. */
1236 if (!NILP (Vquit_flag
))
1239 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1244 alloca (0); /* Cause a garbage collection now */
1245 /* Since we can free the most stuff here. */
1246 #endif /* C_ALLOCA */
1249 /* Select the frame that the last event came from. Usually,
1250 switch-frame events will take care of this, but if some lisp
1251 code swallows a switch-frame event, we'll fix things up here.
1252 Is this a good idea? */
1253 if (FRAMEP (internal_last_event_frame
)
1254 && XFRAME (internal_last_event_frame
) != selected_frame
)
1255 Fselect_frame (internal_last_event_frame
, Qnil
);
1257 /* If it has changed current-menubar from previous value,
1258 really recompute the menubar from the value. */
1259 if (! NILP (Vlucid_menu_bar_dirty_flag
)
1260 && !NILP (Ffboundp (Qrecompute_lucid_menubar
)))
1261 call0 (Qrecompute_lucid_menubar
);
1263 before_command_key_count
= this_command_key_count
;
1264 before_command_echo_length
= echo_length ();
1266 Vthis_command
= Qnil
;
1267 real_this_command
= Qnil
;
1269 /* Read next key sequence; i gets its length. */
1270 i
= read_key_sequence (keybuf
, sizeof keybuf
/ sizeof keybuf
[0],
1273 /* A filter may have run while we were reading the input. */
1274 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1275 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1279 /* Now we have read a key sequence of length I,
1280 or else I is 0 and we found end of file. */
1282 if (i
== 0) /* End of file -- happens only in */
1283 return Qnil
; /* a kbd macro, at the end. */
1284 /* -1 means read_key_sequence got a menu that was rejected.
1285 Just loop around and read another command. */
1289 this_command_key_count
= 0;
1290 this_single_command_key_start
= 0;
1294 last_command_char
= keybuf
[i
- 1];
1296 /* If the previous command tried to force a specific window-start,
1297 forget about that, in case this command moves point far away
1298 from that position. But also throw away beg_unchanged and
1299 end_unchanged information in that case, so that redisplay will
1300 update the whole window properly. */
1301 if (!NILP (XWINDOW (selected_window
)->force_start
))
1303 XWINDOW (selected_window
)->force_start
= Qnil
;
1304 beg_unchanged
= end_unchanged
= 0;
1307 cmd
= read_key_sequence_cmd
;
1308 if (!NILP (Vexecuting_macro
))
1310 if (!NILP (Vquit_flag
))
1312 Vexecuting_macro
= Qt
;
1313 QUIT
; /* Make some noise. */
1314 /* Will return since macro now empty. */
1318 /* Do redisplay processing after this command except in special
1319 cases identified below that set no_redisplay to 1.
1320 (actually, there's currently no way to prevent the redisplay,
1321 and no_redisplay is ignored.
1322 Perhaps someday we will really implement it.) */
1325 prev_buffer
= current_buffer
;
1326 prev_modiff
= MODIFF
;
1327 last_point_position
= PT
;
1328 XSETBUFFER (last_point_position_buffer
, prev_buffer
);
1330 /* Execute the command. */
1332 Vthis_command
= cmd
;
1333 real_this_command
= cmd
;
1334 /* Note that the value cell will never directly contain nil
1335 if the symbol is a local variable. */
1336 if (!NILP (Vpre_command_hook
) && !NILP (Vrun_hooks
))
1337 safe_run_hooks (Qpre_command_hook
);
1339 if (NILP (Vthis_command
))
1341 /* nil means key is undefined. */
1343 current_kboard
->defining_kbd_macro
= Qnil
;
1344 update_mode_lines
= 1;
1345 current_kboard
->Vprefix_arg
= Qnil
;
1349 if (NILP (current_kboard
->Vprefix_arg
) && ! no_direct
)
1351 /* In case we jump to directly_done. */
1352 Vcurrent_prefix_arg
= current_kboard
->Vprefix_arg
;
1354 /* Recognize some common commands in common situations and
1355 do them directly. */
1356 if (EQ (Vthis_command
, Qforward_char
) && PT
< ZV
)
1358 struct Lisp_Char_Table
*dp
1359 = window_display_table (XWINDOW (selected_window
));
1360 lose
= FETCH_CHAR (PT_BYTE
);
1363 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1364 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1365 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1366 && (lose
>= 0x20 && lose
< 0x7f)))
1367 : (lose
>= 0x20 && lose
< 0x7f))
1368 /* To extract the case of continuation on
1369 wide-column characters. */
1370 && (WIDTH_BY_CHAR_HEAD (FETCH_BYTE (PT_BYTE
)) == 1)
1371 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1373 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1375 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1377 && !windows_or_buffers_changed
1378 && EQ (current_buffer
->selective_display
, Qnil
)
1379 && !detect_input_pending ()
1380 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1381 && NILP (Vexecuting_macro
))
1382 no_redisplay
= direct_output_forward_char (1);
1385 else if (EQ (Vthis_command
, Qbackward_char
) && PT
> BEGV
)
1387 struct Lisp_Char_Table
*dp
1388 = window_display_table (XWINDOW (selected_window
));
1390 lose
= FETCH_CHAR (PT_BYTE
);
1392 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1393 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1394 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1395 && (lose
>= 0x20 && lose
< 0x7f)))
1396 : (lose
>= 0x20 && lose
< 0x7f))
1397 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1399 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1401 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1403 && !windows_or_buffers_changed
1404 && EQ (current_buffer
->selective_display
, Qnil
)
1405 && !detect_input_pending ()
1406 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1407 && NILP (Vexecuting_macro
))
1408 no_redisplay
= direct_output_forward_char (-1);
1411 else if (EQ (Vthis_command
, Qself_insert_command
)
1412 /* Try this optimization only on ascii keystrokes. */
1413 && INTEGERP (last_command_char
))
1415 unsigned int c
= XINT (last_command_char
);
1418 if (NILP (Vexecuting_macro
)
1419 && !EQ (minibuf_window
, selected_window
))
1421 if (!nonundocount
|| nonundocount
>= 20)
1428 lose
= ((XFASTINT (XWINDOW (selected_window
)->last_modified
)
1430 || (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1432 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1434 || MODIFF
<= SAVE_MODIFF
1435 || windows_or_buffers_changed
1436 || !EQ (current_buffer
->selective_display
, Qnil
)
1437 || detect_input_pending ()
1438 || !NILP (XWINDOW (selected_window
)->column_number_displayed
)
1439 || !NILP (Vexecuting_macro
));
1440 value
= internal_self_insert (c
, 0);
1447 && (PT
== ZV
|| FETCH_BYTE (PT_BYTE
) == '\n'))
1449 struct Lisp_Char_Table
*dp
1450 = window_display_table (XWINDOW (selected_window
));
1453 /* Add the offset to the character, for Finsert_char.
1454 We pass internal_self_insert the unmodified character
1455 because it itself does this offsetting. */
1456 if (! NILP (current_buffer
->enable_multibyte_characters
))
1457 lose
= unibyte_char_to_multibyte (lose
);
1463 obj
= DISP_CHAR_VECTOR (dp
, lose
);
1466 /* Do it only for char codes
1467 that by default display as themselves. */
1468 if (lose
>= 0x20 && lose
<= 0x7e)
1469 no_redisplay
= direct_output_for_insert (lose
);
1471 else if (VECTORP (obj
)
1472 && XVECTOR (obj
)->size
== 1
1473 && (obj
= XVECTOR (obj
)->contents
[0],
1475 /* Insist face not specified in glyph. */
1476 && (XINT (obj
) & ((-1) << 8)) == 0)
1478 = direct_output_for_insert (XINT (obj
));
1482 if (lose
>= 0x20 && lose
<= 0x7e)
1483 no_redisplay
= direct_output_for_insert (lose
);
1490 /* Here for a command that isn't executed directly */
1493 if (NILP (current_kboard
->Vprefix_arg
))
1495 Fcommand_execute (Vthis_command
, Qnil
, Qnil
, Qnil
);
1498 current_kboard
->Vlast_prefix_arg
= Vcurrent_prefix_arg
;
1500 /* Note that the value cell will never directly contain nil
1501 if the symbol is a local variable. */
1502 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1503 safe_run_hooks (Qpost_command_hook
);
1505 if (!NILP (Vdeferred_action_list
))
1506 safe_run_hooks (Qdeferred_action_function
);
1508 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1510 if (NILP (Vunread_command_events
)
1511 && NILP (Vunread_input_method_events
)
1512 && NILP (Vunread_post_input_method_events
)
1513 && NILP (Vexecuting_macro
)
1514 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1, 1)))
1515 safe_run_hooks (Qpost_command_idle_hook
);
1518 /* If there is a prefix argument,
1519 1) We don't want Vlast_command to be ``universal-argument''
1520 (that would be dumb), so don't set Vlast_command,
1521 2) we want to leave echoing on so that the prefix will be
1522 echoed as part of this key sequence, so don't call
1524 3) we want to leave this_command_key_count non-zero, so that
1525 read_char will realize that it is re-reading a character, and
1526 not echo it a second time.
1528 If the command didn't actually create a prefix arg,
1529 but is merely a frame event that is transparent to prefix args,
1530 then the above doesn't apply. */
1531 if (NILP (current_kboard
->Vprefix_arg
) || CONSP (last_command_char
))
1533 current_kboard
->Vlast_command
= Vthis_command
;
1534 current_kboard
->Vreal_last_command
= real_this_command
;
1536 this_command_key_count
= 0;
1537 this_single_command_key_start
= 0;
1540 if (!NILP (current_buffer
->mark_active
) && !NILP (Vrun_hooks
))
1542 if (!NILP (Vdeactivate_mark
) && !NILP (Vtransient_mark_mode
))
1544 current_buffer
->mark_active
= Qnil
;
1545 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
1547 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
1548 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
1552 /* Install chars successfully executed in kbd macro. */
1554 if (!NILP (current_kboard
->defining_kbd_macro
)
1555 && NILP (current_kboard
->Vprefix_arg
))
1556 finalize_kbd_macro_chars ();
1560 any_kboard_state ();
1565 /* Subroutine for safe_run_hooks: run the hook HOOK. */
1568 safe_run_hooks_1 (hook
)
1571 return call1 (Vrun_hooks
, Vinhibit_quit
);
1574 /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */
1577 safe_run_hooks_error (data
)
1580 Fset (Vinhibit_quit
, Qnil
);
1583 /* If we get an error while running the hook, cause the hook variable
1584 to be nil. Also inhibit quits, so that C-g won't cause the hook
1585 to mysteriously evaporate. */
1588 safe_run_hooks (hook
)
1592 int count
= specpdl_ptr
- specpdl
;
1593 specbind (Qinhibit_quit
, hook
);
1595 internal_condition_case (safe_run_hooks_1
, Qt
, safe_run_hooks_error
);
1597 unbind_to (count
, Qnil
);
1600 /* Number of seconds between polling for input. */
1603 /* Nonzero means polling for input is temporarily suppressed. */
1604 int poll_suppress_count
;
1606 /* Nonzero if polling_for_input is actually being used. */
1607 int polling_for_input
;
1609 #ifdef POLL_FOR_INPUT
1611 /* Handle an alarm once each second and read pending input
1612 so as to handle a C-g if it comces in. */
1615 input_poll_signal (signalnum
) /* If we don't have an argument, */
1616 int signalnum
; /* some compilers complain in signal calls. */
1618 /* This causes the call to start_polling at the end
1619 to do its job. It also arranges for a quit or error
1620 from within read_avail_input to resume polling. */
1621 poll_suppress_count
++;
1622 if (interrupt_input_blocked
== 0
1623 && !waiting_for_input
)
1624 read_avail_input (0);
1625 /* Turn on the SIGALRM handler and request another alarm. */
1631 /* Begin signals to poll for input, if they are appropriate.
1632 This function is called unconditionally from various places. */
1637 #ifdef POLL_FOR_INPUT
1638 if (read_socket_hook
&& !interrupt_input
)
1640 poll_suppress_count
--;
1641 if (poll_suppress_count
== 0)
1643 signal (SIGALRM
, input_poll_signal
);
1644 polling_for_input
= 1;
1645 alarm (polling_period
);
1651 /* Nonzero if we are using polling to handle input asynchronously. */
1654 input_polling_used ()
1656 #ifdef POLL_FOR_INPUT
1657 return read_socket_hook
&& !interrupt_input
;
1663 /* Turn off polling. */
1668 #ifdef POLL_FOR_INPUT
1669 if (read_socket_hook
&& !interrupt_input
)
1671 if (poll_suppress_count
== 0)
1673 polling_for_input
= 0;
1676 poll_suppress_count
++;
1681 /* Set the value of poll_suppress_count to COUNT
1682 and start or stop polling accordingly. */
1685 set_poll_suppress_count (count
)
1688 #ifdef POLL_FOR_INPUT
1689 if (count
== 0 && poll_suppress_count
!= 0)
1691 poll_suppress_count
= 1;
1694 else if (count
!= 0 && poll_suppress_count
== 0)
1698 poll_suppress_count
= count
;
1702 /* Bind polling_period to a value at least N.
1703 But don't decrease it. */
1706 bind_polling_period (n
)
1709 #ifdef POLL_FOR_INPUT
1710 int new = polling_period
;
1716 specbind (Qpolling_period
, make_number (new));
1717 /* Start a new alarm with the new period. */
1722 /* Apply the control modifier to CHARACTER. */
1728 /* Save the upper bits here. */
1729 int upper
= c
& ~0177;
1733 /* Everything in the columns containing the upper-case letters
1734 denotes a control character. */
1735 if (c
>= 0100 && c
< 0140)
1739 /* Set the shift modifier for a control char
1740 made from a shifted letter. But only for letters! */
1741 if (oc
>= 'A' && oc
<= 'Z')
1742 c
|= shift_modifier
;
1745 /* The lower-case letters denote control characters too. */
1746 else if (c
>= 'a' && c
<= 'z')
1749 /* Include the bits for control and shift
1750 only if the basic ASCII code can't indicate them. */
1754 /* Replace the high bits. */
1755 c
|= (upper
& ~ctrl_modifier
);
1762 /* Input of single characters from keyboard */
1764 Lisp_Object
print_help ();
1765 static Lisp_Object
kbd_buffer_get_event ();
1766 static void record_char ();
1769 static jmp_buf wrong_kboard_jmpbuf
;
1772 /* read a character from the keyboard; call the redisplay if needed */
1773 /* commandflag 0 means do not do auto-saving, but do do redisplay.
1774 -1 means do not do redisplay, but do do autosaving.
1777 /* The arguments MAPS and NMAPS are for menu prompting.
1778 MAPS is an array of keymaps; NMAPS is the length of MAPS.
1780 PREV_EVENT is the previous input event, or nil if we are reading
1781 the first event of a key sequence (or not reading a key sequence).
1782 If PREV_EVENT is t, that is a "magic" value that says
1783 not to run input methods, but in other respects to act as if
1784 not reading a key sequence.
1786 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
1787 if we used a mouse menu to read the input, or zero otherwise. If
1788 USED_MOUSE_MENU is null, we don't dereference it.
1790 Value is t if we showed a menu and the user rejected it. */
1793 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
)
1797 Lisp_Object prev_event
;
1798 int *used_mouse_menu
;
1802 jmp_buf local_getcjmp
;
1804 int key_already_recorded
= 0;
1805 Lisp_Object tem
, save
;
1806 Lisp_Object echo_area_message
;
1807 Lisp_Object also_record
;
1809 struct gcpro gcpro1
, gcpro2
;
1813 before_command_key_count
= this_command_key_count
;
1814 before_command_echo_length
= echo_length ();
1816 echo_area_message
= Qnil
;
1818 GCPRO2 (c
, echo_area_message
);
1823 if (CONSP (Vunread_post_input_method_events
))
1825 c
= XCONS (Vunread_post_input_method_events
)->car
;
1826 Vunread_post_input_method_events
1827 = XCONS (Vunread_post_input_method_events
)->cdr
;
1829 /* Undo what read_char_x_menu_prompt did when it unread
1830 additional keys returned by Fx_popup_menu. */
1832 && (SYMBOLP (XCONS (c
)->car
) || INTEGERP (XCONS (c
)->car
))
1833 && NILP (XCONS (c
)->cdr
))
1840 if (unread_command_char
!= -1)
1842 XSETINT (c
, unread_command_char
);
1843 unread_command_char
= -1;
1849 if (CONSP (Vunread_command_events
))
1851 c
= XCONS (Vunread_command_events
)->car
;
1852 Vunread_command_events
= XCONS (Vunread_command_events
)->cdr
;
1854 /* Undo what read_char_x_menu_prompt did when it unread
1855 additional keys returned by Fx_popup_menu. */
1857 && (SYMBOLP (XCONS (c
)->car
) || INTEGERP (XCONS (c
)->car
))
1858 && NILP (XCONS (c
)->cdr
))
1862 goto reread_for_input_method
;
1865 if (CONSP (Vunread_input_method_events
))
1867 c
= XCONS (Vunread_input_method_events
)->car
;
1868 Vunread_input_method_events
= XCONS (Vunread_input_method_events
)->cdr
;
1870 /* Undo what read_char_x_menu_prompt did when it unread
1871 additional keys returned by Fx_popup_menu. */
1873 && (SYMBOLP (XCONS (c
)->car
) || INTEGERP (XCONS (c
)->car
))
1874 && NILP (XCONS (c
)->cdr
))
1877 goto reread_for_input_method
;
1880 /* If there is no function key translated before
1881 reset-this-command-lengths takes effect, forget about it. */
1882 before_command_restore_flag
= 0;
1884 if (!NILP (Vexecuting_macro
))
1886 /* We set this to Qmacro; since that's not a frame, nobody will
1887 try to switch frames on us, and the selected window will
1890 Since this event came from a macro, it would be misleading to
1891 leave internal_last_event_frame set to wherever the last
1892 real event came from. Normally, a switch-frame event selects
1893 internal_last_event_frame after each command is read, but
1894 events read from a macro should never cause a new frame to be
1896 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
1898 /* Exit the macro if we are at the end.
1899 Also, some things replace the macro with t
1900 to force an early exit. */
1901 if (EQ (Vexecuting_macro
, Qt
)
1902 || executing_macro_index
>= XFASTINT (Flength (Vexecuting_macro
)))
1908 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
1909 if (STRINGP (Vexecuting_macro
)
1910 && (XINT (c
) & 0x80))
1911 XSETFASTINT (c
, CHAR_META
| (XINT (c
) & ~0x80));
1913 executing_macro_index
++;
1918 if (!NILP (unread_switch_frame
))
1920 c
= unread_switch_frame
;
1921 unread_switch_frame
= Qnil
;
1923 /* This event should make it into this_command_keys, and get echoed
1924 again, so we do not set `reread'. */
1928 /* if redisplay was requested */
1929 if (commandflag
>= 0)
1931 /* If there is pending input, process any events which are not
1932 user-visible, such as X selection_request events. */
1934 || detect_input_pending_run_timers (0))
1935 swallow_events (0); /* may clear input_pending */
1937 /* Redisplay if no pending input. */
1938 while (!input_pending
)
1943 /* Normal case: no input arrived during redisplay. */
1946 /* Input arrived and pre-empted redisplay.
1947 Process any events which are not user-visible. */
1949 /* If that cleared input_pending, try again to redisplay. */
1953 /* Message turns off echoing unless more keystrokes turn it on again. */
1954 if (echo_area_glyphs
&& *echo_area_glyphs
1955 && echo_area_glyphs
!= current_kboard
->echobuf
1956 && ok_to_echo_at_next_pause
!= echo_area_glyphs
)
1959 /* If already echoing, continue. */
1962 /* Try reading a character via menu prompting in the minibuf.
1963 Try this before the sit-for, because the sit-for
1964 would do the wrong thing if we are supposed to do
1965 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
1966 after a mouse event so don't try a minibuf menu. */
1968 if (nmaps
> 0 && INTERACTIVE
1969 && !NILP (prev_event
) && ! EVENT_HAS_PARAMETERS (prev_event
)
1970 /* Don't bring up a menu if we already have another event. */
1971 && NILP (Vunread_command_events
)
1972 && unread_command_char
< 0
1973 && !detect_input_pending_run_timers (0))
1975 c
= read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
);
1978 key_already_recorded
= 1;
1983 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet.
1984 We will do that below, temporarily for short sections of code,
1985 when appropriate. local_getcjmp must be in effect
1986 around any call to sit_for or kbd_buffer_get_event;
1987 it *must not* be in effect when we call redisplay. */
1989 if (_setjmp (local_getcjmp
))
1991 XSETINT (c
, quit_char
);
1992 XSETFRAME (internal_last_event_frame
, selected_frame
);
1993 Vlast_event_frame
= internal_last_event_frame
;
1994 /* If we report the quit char as an event,
1995 don't do so more than once. */
1996 if (!NILP (Vinhibit_quit
))
2001 KBOARD
*kb
= FRAME_KBOARD (selected_frame
);
2002 if (kb
!= current_kboard
)
2004 Lisp_Object
*tailp
= &kb
->kbd_queue
;
2005 /* We shouldn't get here if we were in single-kboard mode! */
2008 while (CONSP (*tailp
))
2009 tailp
= &XCONS (*tailp
)->cdr
;
2012 *tailp
= Fcons (c
, Qnil
);
2013 kb
->kbd_queue_has_data
= 1;
2014 current_kboard
= kb
;
2015 /* This is going to exit from read_char
2016 so we had better get rid of this frame's stuff. */
2018 longjmp (wrong_kboard_jmpbuf
, 1);
2025 timer_start_idle ();
2027 /* If in middle of key sequence and minibuffer not active,
2028 start echoing if enough time elapses. */
2030 if (minibuf_level
== 0 && !current_kboard
->immediate_echo
2031 && this_command_key_count
> 0
2033 && echo_keystrokes
> 0
2034 && (echo_area_glyphs
== 0 || *echo_area_glyphs
== 0
2035 || ok_to_echo_at_next_pause
== echo_area_glyphs
))
2039 /* After a mouse event, start echoing right away.
2040 This is because we are probably about to display a menu,
2041 and we don't want to delay before doing so. */
2042 if (EVENT_HAS_PARAMETERS (prev_event
))
2046 save_getcjmp (save_jump
);
2047 restore_getcjmp (local_getcjmp
);
2048 tem0
= sit_for (echo_keystrokes
, 0, 1, 1, 0);
2049 restore_getcjmp (save_jump
);
2051 && ! CONSP (Vunread_command_events
))
2056 /* Maybe auto save due to number of keystrokes. */
2058 if (commandflag
!= 0
2059 && auto_save_interval
> 0
2060 && num_nonmacro_input_events
- last_auto_save
> max (auto_save_interval
, 20)
2061 && !detect_input_pending_run_timers (0))
2063 Fdo_auto_save (Qnil
, Qnil
);
2064 /* Hooks can actually change some buffers in auto save. */
2068 /* Try reading using an X menu.
2069 This is never confused with reading using the minibuf
2070 because the recursive call of read_char in read_char_minibuf_menu_prompt
2071 does not pass on any keymaps. */
2073 if (nmaps
> 0 && INTERACTIVE
2074 && !NILP (prev_event
)
2075 && EVENT_HAS_PARAMETERS (prev_event
)
2076 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
)
2077 /* Don't bring up a menu if we already have another event. */
2078 && NILP (Vunread_command_events
)
2079 && unread_command_char
< 0)
2081 c
= read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
2083 /* Now that we have read an event, Emacs is not idle. */
2089 /* Maybe autosave and/or garbage collect due to idleness. */
2091 if (INTERACTIVE
&& NILP (c
))
2093 int delay_level
, buffer_size
;
2095 /* Slow down auto saves logarithmically in size of current buffer,
2096 and garbage collect while we're at it. */
2097 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
2098 last_non_minibuf_size
= Z
- BEG
;
2099 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
2101 while (buffer_size
> 64)
2102 delay_level
++, buffer_size
-= buffer_size
>> 2;
2103 if (delay_level
< 4) delay_level
= 4;
2104 /* delay_level is 4 for files under around 50k, 7 at 100k,
2105 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
2107 /* Auto save if enough time goes by without input. */
2108 if (commandflag
!= 0
2109 && num_nonmacro_input_events
> last_auto_save
2110 && INTEGERP (Vauto_save_timeout
)
2111 && XINT (Vauto_save_timeout
) > 0)
2115 save_getcjmp (save_jump
);
2116 restore_getcjmp (local_getcjmp
);
2117 tem0
= sit_for (delay_level
* XFASTINT (Vauto_save_timeout
) / 4,
2119 restore_getcjmp (save_jump
);
2122 && ! CONSP (Vunread_command_events
))
2124 Fdo_auto_save (Qnil
, Qnil
);
2126 /* If we have auto-saved and there is still no input
2127 available, garbage collect if there has been enough
2128 consing going on to make it worthwhile. */
2129 if (!detect_input_pending_run_timers (0)
2130 && consing_since_gc
> gc_cons_threshold
/ 2)
2131 Fgarbage_collect ();
2138 /* If this has become non-nil here, it has been set by a timer
2139 or sentinel or filter. */
2140 if (CONSP (Vunread_command_events
))
2142 c
= XCONS (Vunread_command_events
)->car
;
2143 Vunread_command_events
= XCONS (Vunread_command_events
)->cdr
;
2146 /* Read something from current KBOARD's side queue, if possible. */
2150 if (current_kboard
->kbd_queue_has_data
)
2152 if (!CONSP (current_kboard
->kbd_queue
))
2154 c
= XCONS (current_kboard
->kbd_queue
)->car
;
2155 current_kboard
->kbd_queue
2156 = XCONS (current_kboard
->kbd_queue
)->cdr
;
2157 if (NILP (current_kboard
->kbd_queue
))
2158 current_kboard
->kbd_queue_has_data
= 0;
2159 input_pending
= readable_events (0);
2160 if (EVENT_HAS_PARAMETERS (c
)
2161 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qswitch_frame
))
2162 internal_last_event_frame
= XCONS (XCONS (c
)->cdr
)->car
;
2163 Vlast_event_frame
= internal_last_event_frame
;
2168 /* If current_kboard's side queue is empty check the other kboards.
2169 If one of them has data that we have not yet seen here,
2170 switch to it and process the data waiting for it.
2172 Note: if the events queued up for another kboard
2173 have already been seen here, and therefore are not a complete command,
2174 the kbd_queue_has_data field is 0, so we skip that kboard here.
2175 That's to avoid an infinite loop switching between kboards here. */
2176 if (NILP (c
) && !single_kboard
)
2179 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2180 if (kb
->kbd_queue_has_data
)
2182 current_kboard
= kb
;
2183 /* This is going to exit from read_char
2184 so we had better get rid of this frame's stuff. */
2186 longjmp (wrong_kboard_jmpbuf
, 1);
2195 /* Finally, we read from the main queue,
2196 and if that gives us something we can't use yet, we put it on the
2197 appropriate side queue and try again. */
2203 /* Actually read a character, waiting if necessary. */
2204 save_getcjmp (save_jump
);
2205 restore_getcjmp (local_getcjmp
);
2206 c
= kbd_buffer_get_event (&kb
, used_mouse_menu
);
2207 restore_getcjmp (save_jump
);
2210 if (! NILP (c
) && (kb
!= current_kboard
))
2212 Lisp_Object
*tailp
= &kb
->kbd_queue
;
2213 while (CONSP (*tailp
))
2214 tailp
= &XCONS (*tailp
)->cdr
;
2217 *tailp
= Fcons (c
, Qnil
);
2218 kb
->kbd_queue_has_data
= 1;
2222 current_kboard
= kb
;
2223 /* This is going to exit from read_char
2224 so we had better get rid of this frame's stuff. */
2226 longjmp (wrong_kboard_jmpbuf
, 1);
2231 /* Terminate Emacs in batch mode if at eof. */
2232 if (noninteractive
&& INTEGERP (c
) && XINT (c
) < 0)
2233 Fkill_emacs (make_number (1));
2237 /* Add in any extra modifiers, where appropriate. */
2238 if ((extra_keyboard_modifiers
& CHAR_CTL
)
2239 || ((extra_keyboard_modifiers
& 0177) < ' '
2240 && (extra_keyboard_modifiers
& 0177) != 0))
2241 XSETINT (c
, make_ctrl_char (XINT (c
)));
2243 /* Transfer any other modifier bits directly from
2244 extra_keyboard_modifiers to c. Ignore the actual character code
2245 in the low 16 bits of extra_keyboard_modifiers. */
2246 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
2257 if (commandflag
>= 0
2258 && !input_pending
&& !detect_input_pending_run_timers (0))
2266 /* Buffer switch events are only for internal wakeups
2267 so don't show them to the user.
2268 Also, don't record a key if we already did. */
2269 if (BUFFERP (c
) || key_already_recorded
)
2272 /* Process special events within read_char
2273 and loop around to read another event. */
2276 tem
= get_keyelt (access_keymap (get_keymap_1 (Vspecial_event_map
, 0, 0),
2282 int was_locked
= single_kboard
;
2284 last_input_char
= c
;
2285 Fcommand_execute (tem
, Qnil
, Fvector (1, &last_input_char
), Qt
);
2287 /* Resume allowing input from any kboard, if that was true before. */
2289 any_kboard_state ();
2294 /* Handle things that only apply to characters. */
2297 /* If kbd_buffer_get_event gave us an EOF, return that. */
2301 if ((STRINGP (Vkeyboard_translate_table
)
2302 && XSTRING (Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
2303 || (VECTORP (Vkeyboard_translate_table
)
2304 && XVECTOR (Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
2305 || (CHAR_TABLE_P (Vkeyboard_translate_table
)
2306 && CHAR_TABLE_ORDINARY_SLOTS
> (unsigned) XFASTINT (c
)))
2309 d
= Faref (Vkeyboard_translate_table
, c
);
2310 /* nil in keyboard-translate-table means no translation. */
2316 /* If this event is a mouse click in the menu bar,
2317 return just menu-bar for now. Modify the mouse click event
2318 so we won't do this twice, then queue it up. */
2319 if (EVENT_HAS_PARAMETERS (c
)
2320 && CONSP (XCONS (c
)->cdr
)
2321 && CONSP (EVENT_START (c
))
2322 && CONSP (XCONS (EVENT_START (c
))->cdr
))
2326 posn
= POSN_BUFFER_POSN (EVENT_START (c
));
2327 /* Handle menu-bar events:
2328 insert the dummy prefix event `menu-bar'. */
2329 if (EQ (posn
, Qmenu_bar
))
2331 /* Change menu-bar to (menu-bar) as the event "position". */
2332 POSN_BUFFER_POSN (EVENT_START (c
)) = Fcons (posn
, Qnil
);
2335 Vunread_command_events
= Fcons (c
, Vunread_command_events
);
2340 /* Store these characters into recent_keys, the dribble file if any,
2341 and the keyboard macro being defined, if any. */
2343 if (! NILP (also_record
))
2344 record_char (also_record
);
2346 /* Wipe the echo area.
2347 But first, if we are about to use an input method,
2348 save the echo area contents for it to refer to. */
2350 && ! NILP (Vinput_method_function
)
2351 && (unsigned) XINT (c
) >= ' '
2352 && (unsigned) XINT (c
) < 127)
2353 Vinput_method_previous_message
= echo_area_message
= Fcurrent_message ();
2355 /* Now wipe the echo area. */
2356 if (echo_area_glyphs
)
2357 safe_run_hooks (Qecho_area_clear_hook
);
2358 echo_area_glyphs
= 0;
2360 reread_for_input_method
:
2362 /* Pass this to the input method, if appropriate. */
2364 && ! NILP (Vinput_method_function
)
2365 /* Don't run the input method within a key sequence,
2366 after the first event of the key sequence. */
2367 && NILP (prev_event
)
2368 && (unsigned) XINT (c
) >= ' '
2369 && (unsigned) XINT (c
) < 127)
2373 struct gcpro gcpro1
;
2374 int count
= specpdl_ptr
- specpdl
;
2376 /* Save the echo status. */
2377 int saved_immediate_echo
= current_kboard
->immediate_echo
;
2378 char *saved_ok_to_echo
= ok_to_echo_at_next_pause
;
2379 int saved_echo_after_prompt
= current_kboard
->echo_after_prompt
;
2381 if (before_command_restore_flag
)
2383 this_command_key_count
= before_command_key_count_1
;
2384 if (this_command_key_count
< this_single_command_key_start
)
2385 this_single_command_key_start
= this_command_key_count
;
2386 echo_truncate (before_command_echo_length_1
);
2387 before_command_restore_flag
= 0;
2390 /* Save the this_command_keys status. */
2391 key_count
= this_command_key_count
;
2394 keys
= Fcopy_sequence (this_command_keys
);
2399 /* Clear out this_command_keys. */
2400 this_command_key_count
= 0;
2402 /* Now wipe the echo area. */
2403 if (echo_area_glyphs
)
2404 safe_run_hooks (Qecho_area_clear_hook
);
2405 echo_area_glyphs
= 0;
2408 /* If we are not reading a key sequence,
2409 never use the echo area. */
2412 specbind (Qinput_method_exit_on_first_char
, Qt
);
2413 specbind (Qinput_method_use_echo_area
, Qt
);
2416 /* Call the input method. */
2417 tem
= call1 (Vinput_method_function
, c
);
2419 tem
= unbind_to (count
, tem
);
2421 /* Restore the saved echoing state
2422 and this_command_keys state. */
2423 this_command_key_count
= key_count
;
2425 this_command_keys
= keys
;
2428 ok_to_echo_at_next_pause
= saved_ok_to_echo
;
2429 current_kboard
->echo_after_prompt
= saved_echo_after_prompt
;
2430 if (saved_immediate_echo
)
2435 /* The input method can return no events. */
2438 /* Bring back the previous message, if any. */
2439 if (! NILP (echo_area_message
))
2440 message_with_string ("%s", echo_area_message
, 0);
2443 /* It returned one event or more. */
2444 c
= XCONS (tem
)->car
;
2445 Vunread_post_input_method_events
2446 = nconc2 (XCONS (tem
)->cdr
, Vunread_post_input_method_events
);
2451 if (this_command_key_count
== 0 || ! reread
)
2453 before_command_key_count
= this_command_key_count
;
2454 before_command_echo_length
= echo_length ();
2456 /* Don't echo mouse motion events. */
2458 && ! (EVENT_HAS_PARAMETERS (c
)
2459 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
2462 if (! NILP (also_record
))
2463 echo_char (also_record
);
2464 /* Once we reread a character, echoing can happen
2465 the next time we pause to read a new one. */
2466 ok_to_echo_at_next_pause
= echo_area_glyphs
;
2469 /* Record this character as part of the current key. */
2470 add_command_key (c
);
2471 if (! NILP (also_record
))
2472 add_command_key (also_record
);
2475 last_input_char
= c
;
2478 /* Process the help character specially if enabled */
2479 if (!NILP (Vhelp_form
) && help_char_p (c
))
2482 count
= specpdl_ptr
- specpdl
;
2484 record_unwind_protect (Fset_window_configuration
,
2485 Fcurrent_window_configuration (Qnil
));
2487 tem0
= Feval (Vhelp_form
);
2489 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
2493 c
= read_char (0, 0, 0, Qnil
, 0);
2494 while (BUFFERP (c
));
2495 /* Remove the help from the frame */
2496 unbind_to (count
, Qnil
);
2499 if (EQ (c
, make_number (040)))
2503 c
= read_char (0, 0, 0, Qnil
, 0);
2504 while (BUFFERP (c
));
2511 /* Record a key that came from a mouse menu.
2512 Record it for echoing, for this-command-keys, and so on. */
2518 /* Wipe the echo area. */
2519 echo_area_glyphs
= 0;
2523 before_command_key_count
= this_command_key_count
;
2524 before_command_echo_length
= echo_length ();
2526 /* Don't echo mouse motion events. */
2527 if (echo_keystrokes
)
2531 /* Once we reread a character, echoing can happen
2532 the next time we pause to read a new one. */
2533 ok_to_echo_at_next_pause
= 0;
2536 /* Record this character as part of the current key. */
2537 add_command_key (c
);
2539 /* Re-reading in the middle of a command */
2540 last_input_char
= c
;
2544 /* Return 1 if should recognize C as "the help character". */
2552 if (EQ (c
, Vhelp_char
))
2554 for (tail
= Vhelp_event_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
2555 if (EQ (c
, XCONS (tail
)->car
))
2560 /* Record the input event C in various ways. */
2567 XVECTOR (recent_keys
)->contents
[recent_keys_index
] = c
;
2568 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
2569 recent_keys_index
= 0;
2571 /* Write c to the dribble file. If c is a lispy event, write
2572 the event's symbol to the dribble file, in <brackets>. Bleaugh.
2573 If you, dear reader, have a better idea, you've got the source. :-) */
2578 if (XUINT (c
) < 0x100)
2579 putc (XINT (c
), dribble
);
2581 fprintf (dribble
, " 0x%x", (int) XUINT (c
));
2585 Lisp_Object dribblee
;
2587 /* If it's a structured event, take the event header. */
2588 dribblee
= EVENT_HEAD (c
);
2590 if (SYMBOLP (dribblee
))
2592 putc ('<', dribble
);
2593 fwrite (XSYMBOL (dribblee
)->name
->data
, sizeof (char),
2594 STRING_BYTES (XSYMBOL (dribblee
)->name
),
2596 putc ('>', dribble
);
2603 store_kbd_macro_char (c
);
2605 num_nonmacro_input_events
++;
2612 struct buffer
*old
= current_buffer
;
2613 Fprinc (object
, Qnil
);
2614 set_buffer_internal (XBUFFER (Vstandard_output
));
2615 call0 (intern ("help-mode"));
2616 set_buffer_internal (old
);
2620 /* Copy out or in the info on where C-g should throw to.
2621 This is used when running Lisp code from within get_char,
2622 in case get_char is called recursively.
2623 See read_process_output. */
2629 bcopy (getcjmp
, temp
, sizeof getcjmp
);
2633 restore_getcjmp (temp
)
2636 bcopy (temp
, getcjmp
, sizeof getcjmp
);
2641 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
2642 of this function. */
2645 tracking_off (old_value
)
2646 Lisp_Object old_value
;
2648 do_mouse_tracking
= old_value
;
2649 if (NILP (old_value
))
2651 /* Redisplay may have been preempted because there was input
2652 available, and it assumes it will be called again after the
2653 input has been processed. If the only input available was
2654 the sort that we have just disabled, then we need to call
2656 if (!readable_events (1))
2658 redisplay_preserve_echo_area ();
2659 get_input_pending (&input_pending
, 1);
2664 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
2665 "Evaluate BODY with mouse movement events enabled.\n\
2666 Within a `track-mouse' form, mouse motion generates input events that\n\
2667 you can read with `read-event'.\n\
2668 Normally, mouse motion is ignored.")
2672 int count
= specpdl_ptr
- specpdl
;
2675 record_unwind_protect (tracking_off
, do_mouse_tracking
);
2677 do_mouse_tracking
= Qt
;
2679 val
= Fprogn (args
);
2680 return unbind_to (count
, val
);
2683 /* If mouse has moved on some frame, return one of those frames.
2684 Return 0 otherwise. */
2689 Lisp_Object tail
, frame
;
2691 FOR_EACH_FRAME (tail
, frame
)
2693 if (XFRAME (frame
)->mouse_moved
)
2694 return XFRAME (frame
);
2700 #endif /* HAVE_MOUSE */
2702 /* Low level keyboard/mouse input.
2703 kbd_buffer_store_event places events in kbd_buffer, and
2704 kbd_buffer_get_event retrieves them. */
2706 /* Return true iff there are any events in the queue that read-char
2707 would return. If this returns false, a read-char would block. */
2709 readable_events (do_timers_now
)
2713 timer_check (do_timers_now
);
2715 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2718 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2723 if (current_kboard
->kbd_queue_has_data
)
2729 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2730 if (kb
->kbd_queue_has_data
)
2736 /* Set this for debugging, to have a way to get out */
2741 event_to_kboard (event
)
2742 struct input_event
*event
;
2745 frame
= event
->frame_or_window
;
2747 frame
= XCONS (frame
)->car
;
2748 else if (WINDOWP (frame
))
2749 frame
= WINDOW_FRAME (XWINDOW (frame
));
2751 /* There are still some events that don't set this field.
2752 For now, just ignore the problem.
2753 Also ignore dead frames here. */
2754 if (!FRAMEP (frame
) || !FRAME_LIVE_P (XFRAME (frame
)))
2757 return FRAME_KBOARD (XFRAME (frame
));
2761 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
2764 kbd_buffer_store_event (event
)
2765 register struct input_event
*event
;
2767 if (event
->kind
== no_event
)
2770 if (event
->kind
== ascii_keystroke
)
2772 register int c
= event
->code
& 0377;
2774 if (event
->modifiers
& ctrl_modifier
)
2775 c
= make_ctrl_char (c
);
2777 c
|= (event
->modifiers
2778 & (meta_modifier
| alt_modifier
2779 | hyper_modifier
| super_modifier
));
2783 extern SIGTYPE
interrupt_signal ();
2786 struct input_event
*sp
;
2789 && (kb
= FRAME_KBOARD (XFRAME (event
->frame_or_window
)),
2790 kb
!= current_kboard
))
2793 = Fcons (make_lispy_switch_frame (event
->frame_or_window
),
2794 Fcons (make_number (c
), Qnil
));
2795 kb
->kbd_queue_has_data
= 1;
2796 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
2798 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
2801 if (event_to_kboard (sp
) == kb
)
2803 sp
->kind
= no_event
;
2804 sp
->frame_or_window
= Qnil
;
2811 /* If this results in a quit_char being returned to Emacs as
2812 input, set Vlast_event_frame properly. If this doesn't
2813 get returned to Emacs as an event, the next event read
2814 will set Vlast_event_frame again, so this is safe to do. */
2818 focus
= FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
2820 focus
= event
->frame_or_window
;
2821 internal_last_event_frame
= focus
;
2822 Vlast_event_frame
= focus
;
2825 last_event_timestamp
= event
->timestamp
;
2826 interrupt_signal ();
2830 if (c
&& c
== stop_character
)
2836 /* Don't insert two buffer_switch_event's in a row.
2837 Just ignore the second one. */
2838 else if (event
->kind
== buffer_switch_event
2839 && kbd_fetch_ptr
!= kbd_store_ptr
2840 && kbd_store_ptr
->kind
== buffer_switch_event
)
2843 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
2844 kbd_store_ptr
= kbd_buffer
;
2846 /* Don't let the very last slot in the buffer become full,
2847 since that would make the two pointers equal,
2848 and that is indistinguishable from an empty buffer.
2849 Discard the event if it would fill the last slot. */
2850 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
2852 volatile struct input_event
*sp
= kbd_store_ptr
;
2853 sp
->kind
= event
->kind
;
2854 if (event
->kind
== selection_request_event
)
2856 /* We must not use the ordinary copying code for this case,
2857 since `part' is an enum and copying it might not copy enough
2859 bcopy (event
, (char *) sp
, sizeof (*event
));
2863 sp
->code
= event
->code
;
2864 sp
->part
= event
->part
;
2865 sp
->frame_or_window
= event
->frame_or_window
;
2866 sp
->modifiers
= event
->modifiers
;
2869 sp
->timestamp
= event
->timestamp
;
2871 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_store_ptr
2873 = event
->frame_or_window
);
2879 /* Discard any mouse events in the event buffer by setting them to
2882 discard_mouse_events ()
2884 struct input_event
*sp
;
2885 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
2887 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
2890 if (sp
->kind
== mouse_click
2892 || sp
->kind
== w32_scroll_bar_click
2894 || sp
->kind
== scroll_bar_click
)
2896 sp
->kind
= no_event
;
2901 /* Read one event from the event buffer, waiting if necessary.
2902 The value is a Lisp object representing the event.
2903 The value is nil for an event that should be ignored,
2904 or that was handled here.
2905 We always read and discard one event. */
2908 kbd_buffer_get_event (kbp
, used_mouse_menu
)
2910 int *used_mouse_menu
;
2914 EMACS_TIME next_timer_delay
;
2920 *kbp
= current_kboard
;
2924 /* Wait until there is input available. */
2927 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2930 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2934 /* If the quit flag is set, then read_char will return
2935 quit_char, so that counts as "available input." */
2936 if (!NILP (Vquit_flag
))
2937 quit_throw_to_read_char ();
2939 /* One way or another, wait until input is available; then, if
2940 interrupt handlers have not read it, read it now. */
2943 wait_for_kbd_input ();
2945 /* Note SIGIO has been undef'd if FIONREAD is missing. */
2949 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2952 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2956 Lisp_Object minus_one
;
2958 XSETINT (minus_one
, -1);
2959 wait_reading_process_input (0, 0, minus_one
, 1);
2961 if (!interrupt_input
&& kbd_fetch_ptr
== kbd_store_ptr
)
2962 /* Pass 1 for EXPECT since we just waited to have input. */
2963 read_avail_input (1);
2965 #endif /* not VMS */
2968 if (CONSP (Vunread_command_events
))
2971 first
= XCONS (Vunread_command_events
)->car
;
2972 Vunread_command_events
= XCONS (Vunread_command_events
)->cdr
;
2973 *kbp
= current_kboard
;
2977 /* At this point, we know that there is a readable event available
2978 somewhere. If the event queue is empty, then there must be a
2979 mouse movement enabled and available. */
2980 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2982 struct input_event
*event
;
2984 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2988 last_event_timestamp
= event
->timestamp
;
2991 *kbp
= event_to_kboard (event
);
2993 *kbp
= current_kboard
; /* Better than returning null ptr? */
2995 *kbp
= &the_only_kboard
;
3000 /* These two kinds of events get special handling
3001 and don't actually appear to the command loop.
3002 We return nil for them. */
3003 if (event
->kind
== selection_request_event
)
3006 struct input_event copy
;
3008 /* Remove it from the buffer before processing it,
3009 since otherwise swallow_events will see it
3010 and process it again. */
3012 kbd_fetch_ptr
= event
+ 1;
3013 input_pending
= readable_events (0);
3014 x_handle_selection_request (©
);
3016 /* We're getting selection request events, but we don't have
3022 else if (event
->kind
== selection_clear_event
)
3025 struct input_event copy
;
3027 /* Remove it from the buffer before processing it. */
3029 kbd_fetch_ptr
= event
+ 1;
3030 input_pending
= readable_events (0);
3031 x_handle_selection_clear (©
);
3033 /* We're getting selection request events, but we don't have
3038 #if defined (HAVE_X11) || defined (HAVE_NTGUI)
3039 else if (event
->kind
== delete_window_event
)
3041 /* Make an event (delete-frame (FRAME)). */
3042 obj
= Fcons (event
->frame_or_window
, Qnil
);
3043 obj
= Fcons (Qdelete_frame
, Fcons (obj
, Qnil
));
3044 kbd_fetch_ptr
= event
+ 1;
3046 else if (event
->kind
== iconify_event
)
3048 /* Make an event (iconify-frame (FRAME)). */
3049 obj
= Fcons (event
->frame_or_window
, Qnil
);
3050 obj
= Fcons (Qiconify_frame
, Fcons (obj
, Qnil
));
3051 kbd_fetch_ptr
= event
+ 1;
3053 else if (event
->kind
== deiconify_event
)
3055 /* Make an event (make-frame-visible (FRAME)). */
3056 obj
= Fcons (event
->frame_or_window
, Qnil
);
3057 obj
= Fcons (Qmake_frame_visible
, Fcons (obj
, Qnil
));
3058 kbd_fetch_ptr
= event
+ 1;
3061 else if (event
->kind
== buffer_switch_event
)
3063 /* The value doesn't matter here; only the type is tested. */
3064 XSETBUFFER (obj
, current_buffer
);
3065 kbd_fetch_ptr
= event
+ 1;
3067 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
3068 else if (event
->kind
== menu_bar_activate_event
)
3070 kbd_fetch_ptr
= event
+ 1;
3071 input_pending
= readable_events (0);
3072 if (FRAME_LIVE_P (XFRAME (event
->frame_or_window
)))
3073 x_activate_menubar (XFRAME (event
->frame_or_window
));
3076 /* Just discard these, by returning nil.
3077 With MULTI_KBOARD, these events are used as placeholders
3078 when we need to randomly delete events from the queue.
3079 (They shouldn't otherwise be found in the buffer,
3080 but on some machines it appears they do show up
3081 even without MULTI_KBOARD.) */
3082 /* On Windows NT/9X, no_event is used to delete extraneous
3083 mouse events during a popup-menu call. */
3084 else if (event
->kind
== no_event
)
3085 kbd_fetch_ptr
= event
+ 1;
3087 /* If this event is on a different frame, return a switch-frame this
3088 time, and leave the event in the queue for next time. */
3094 frame
= event
->frame_or_window
;
3096 frame
= XCONS (frame
)->car
;
3097 else if (WINDOWP (frame
))
3098 frame
= WINDOW_FRAME (XWINDOW (frame
));
3100 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
3104 if (! EQ (frame
, internal_last_event_frame
)
3105 && XFRAME (frame
) != selected_frame
)
3106 obj
= make_lispy_switch_frame (frame
);
3107 internal_last_event_frame
= frame
;
3109 /* If we didn't decide to make a switch-frame event, go ahead
3110 and build a real event from the queue entry. */
3114 obj
= make_lispy_event (event
);
3115 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
3116 /* If this was a menu selection, then set the flag to inhibit
3117 writing to last_nonmenu_event. Don't do this if the event
3118 we're returning is (menu-bar), though; that indicates the
3119 beginning of the menu sequence, and we might as well leave
3120 that as the `event with parameters' for this selection. */
3121 if (event
->kind
== menu_bar_event
3122 && !(CONSP (obj
) && EQ (XCONS (obj
)->car
, Qmenu_bar
))
3124 *used_mouse_menu
= 1;
3127 /* Wipe out this event, to catch bugs. */
3128 event
->kind
= no_event
;
3129 XVECTOR (kbd_buffer_frame_or_window
)->contents
[event
- kbd_buffer
] = Qnil
;
3131 kbd_fetch_ptr
= event
+ 1;
3136 /* Try generating a mouse motion event. */
3137 else if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
3139 FRAME_PTR f
= some_mouse_moved ();
3140 Lisp_Object bar_window
;
3141 enum scroll_bar_part part
;
3145 *kbp
= current_kboard
;
3146 /* Note that this uses F to determine which display to look at.
3147 If there is no valid info, it does not store anything
3148 so x remains nil. */
3150 (*mouse_position_hook
) (&f
, 0, &bar_window
, &part
, &x
, &y
, &time
);
3154 /* Decide if we should generate a switch-frame event. Don't
3155 generate switch-frame events for motion outside of all Emacs
3161 frame
= FRAME_FOCUS_FRAME (f
);
3163 XSETFRAME (frame
, f
);
3165 if (! EQ (frame
, internal_last_event_frame
)
3166 && XFRAME (frame
) != selected_frame
)
3167 obj
= make_lispy_switch_frame (frame
);
3168 internal_last_event_frame
= frame
;
3171 /* If we didn't decide to make a switch-frame event, go ahead and
3172 return a mouse-motion event. */
3173 if (!NILP (x
) && NILP (obj
))
3174 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
3176 #endif /* HAVE_MOUSE */
3178 /* We were promised by the above while loop that there was
3179 something for us to read! */
3182 input_pending
= readable_events (0);
3184 Vlast_event_frame
= internal_last_event_frame
;
3189 /* Process any events that are not user-visible,
3190 then return, without reading any user-visible events. */
3193 swallow_events (do_display
)
3198 while (kbd_fetch_ptr
!= kbd_store_ptr
)
3200 struct input_event
*event
;
3202 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
3206 last_event_timestamp
= event
->timestamp
;
3208 /* These two kinds of events get special handling
3209 and don't actually appear to the command loop. */
3210 if (event
->kind
== selection_request_event
)
3213 struct input_event copy
;
3215 /* Remove it from the buffer before processing it,
3216 since otherwise swallow_events called recursively could see it
3217 and process it again. */
3219 kbd_fetch_ptr
= event
+ 1;
3220 input_pending
= readable_events (0);
3221 x_handle_selection_request (©
);
3223 /* We're getting selection request events, but we don't have
3229 else if (event
->kind
== selection_clear_event
)
3232 struct input_event copy
;
3234 /* Remove it from the buffer before processing it, */
3237 kbd_fetch_ptr
= event
+ 1;
3238 input_pending
= readable_events (0);
3239 x_handle_selection_clear (©
);
3241 /* We're getting selection request events, but we don't have
3250 old_timers_run
= timers_run
;
3251 get_input_pending (&input_pending
, 1);
3253 if (timers_run
!= old_timers_run
&& do_display
)
3254 redisplay_preserve_echo_area ();
3257 static EMACS_TIME timer_idleness_start_time
;
3259 /* Record the start of when Emacs is idle,
3260 for the sake of running idle-time timers. */
3267 /* If we are already in the idle state, do nothing. */
3268 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3271 EMACS_GET_TIME (timer_idleness_start_time
);
3273 /* Mark all idle-time timers as once again candidates for running. */
3274 for (timers
= Vtimer_idle_list
; CONSP (timers
); timers
= XCONS (timers
)->cdr
)
3278 timer
= XCONS (timers
)->car
;
3280 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3282 XVECTOR (timer
)->contents
[0] = Qnil
;
3286 /* Record that Emacs is no longer idle, so stop running idle-time timers. */
3291 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
3294 /* This is only for debugging. */
3295 struct input_event last_timer_event
;
3297 /* Check whether a timer has fired. To prevent larger problems we simply
3298 disregard elements that are not proper timers. Do not make a circular
3299 timer list for the time being.
3301 Returns the number of seconds to wait until the next timer fires. If a
3302 timer is triggering now, return zero seconds.
3303 If no timer is active, return -1 seconds.
3305 If a timer is ripe, we run it, with quitting turned off.
3307 DO_IT_NOW is now ignored. It used to mean that we should
3308 run the timer directly instead of queueing a timer-event.
3309 Now we always run timers directly. */
3312 timer_check (do_it_now
)
3315 EMACS_TIME nexttime
;
3316 EMACS_TIME now
, idleness_now
;
3317 Lisp_Object timers
, idle_timers
, chosen_timer
;
3318 struct gcpro gcpro1
, gcpro2
, gcpro3
;
3320 EMACS_SET_SECS (nexttime
, -1);
3321 EMACS_SET_USECS (nexttime
, -1);
3323 /* Always consider the ordinary timers. */
3324 timers
= Vtimer_list
;
3325 /* Consider the idle timers only if Emacs is idle. */
3326 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3327 idle_timers
= Vtimer_idle_list
;
3330 chosen_timer
= Qnil
;
3331 GCPRO3 (timers
, idle_timers
, chosen_timer
);
3333 if (CONSP (timers
) || CONSP (idle_timers
))
3335 EMACS_GET_TIME (now
);
3336 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3337 EMACS_SUB_TIME (idleness_now
, now
, timer_idleness_start_time
);
3340 while (CONSP (timers
) || CONSP (idle_timers
))
3342 int triggertime
= EMACS_SECS (now
);
3343 Lisp_Object
*vector
;
3344 Lisp_Object timer
, idle_timer
;
3345 EMACS_TIME timer_time
, idle_timer_time
;
3346 EMACS_TIME difference
, timer_difference
, idle_timer_difference
;
3348 /* Skip past invalid timers and timers already handled. */
3351 timer
= XCONS (timers
)->car
;
3352 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3354 timers
= XCONS (timers
)->cdr
;
3357 vector
= XVECTOR (timer
)->contents
;
3359 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
3360 || !INTEGERP (vector
[3])
3361 || ! NILP (vector
[0]))
3363 timers
= XCONS (timers
)->cdr
;
3367 if (!NILP (idle_timers
))
3369 timer
= XCONS (idle_timers
)->car
;
3370 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3372 idle_timers
= XCONS (idle_timers
)->cdr
;
3375 vector
= XVECTOR (timer
)->contents
;
3377 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
3378 || !INTEGERP (vector
[3])
3379 || ! NILP (vector
[0]))
3381 idle_timers
= XCONS (idle_timers
)->cdr
;
3386 /* Set TIMER, TIMER_TIME and TIMER_DIFFERENCE
3387 based on the next ordinary timer.
3388 TIMER_DIFFERENCE is the distance in time from NOW to when
3389 this timer becomes ripe (negative if it's already ripe). */
3392 timer
= XCONS (timers
)->car
;
3393 vector
= XVECTOR (timer
)->contents
;
3394 EMACS_SET_SECS (timer_time
,
3395 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
3396 EMACS_SET_USECS (timer_time
, XINT (vector
[3]));
3397 EMACS_SUB_TIME (timer_difference
, timer_time
, now
);
3400 /* Set IDLE_TIMER, IDLE_TIMER_TIME and IDLE_TIMER_DIFFERENCE
3401 based on the next idle timer. */
3402 if (!NILP (idle_timers
))
3404 idle_timer
= XCONS (idle_timers
)->car
;
3405 vector
= XVECTOR (idle_timer
)->contents
;
3406 EMACS_SET_SECS (idle_timer_time
,
3407 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
3408 EMACS_SET_USECS (idle_timer_time
, XINT (vector
[3]));
3409 EMACS_SUB_TIME (idle_timer_difference
, idle_timer_time
, idleness_now
);
3412 /* Decide which timer is the next timer,
3413 and set CHOSEN_TIMER, VECTOR and DIFFERENCE accordingly.
3414 Also step down the list where we found that timer. */
3416 if (! NILP (timers
) && ! NILP (idle_timers
))
3419 EMACS_SUB_TIME (temp
, timer_difference
, idle_timer_difference
);
3420 if (EMACS_TIME_NEG_P (temp
))
3422 chosen_timer
= timer
;
3423 timers
= XCONS (timers
)->cdr
;
3424 difference
= timer_difference
;
3428 chosen_timer
= idle_timer
;
3429 idle_timers
= XCONS (idle_timers
)->cdr
;
3430 difference
= idle_timer_difference
;
3433 else if (! NILP (timers
))
3435 chosen_timer
= timer
;
3436 timers
= XCONS (timers
)->cdr
;
3437 difference
= timer_difference
;
3441 chosen_timer
= idle_timer
;
3442 idle_timers
= XCONS (idle_timers
)->cdr
;
3443 difference
= idle_timer_difference
;
3445 vector
= XVECTOR (chosen_timer
)->contents
;
3447 /* If timer is rupe, run it if it hasn't been run. */
3448 if (EMACS_TIME_NEG_P (difference
)
3449 || (EMACS_SECS (difference
) == 0
3450 && EMACS_USECS (difference
) == 0))
3452 if (NILP (vector
[0]))
3455 int was_locked
= single_kboard
;
3456 int count
= specpdl_ptr
- specpdl
;
3458 /* Mark the timer as triggered to prevent problems if the lisp
3459 code fails to reschedule it right. */
3462 specbind (Qinhibit_quit
, Qt
);
3464 call1 (Qtimer_event_handler
, chosen_timer
);
3467 unbind_to (count
, Qnil
);
3469 /* Resume allowing input from any kboard, if that was true before. */
3471 any_kboard_state ();
3473 /* Since we have handled the event,
3474 we don't need to tell the caller to wake up and do it. */
3478 /* When we encounter a timer that is still waiting,
3479 return the amount of time to wait before it is ripe. */
3486 /* No timers are pending in the future. */
3487 /* Return 0 if we generated an event, and -1 if not. */
3492 /* Caches for modify_event_symbol. */
3493 static Lisp_Object accent_key_syms
;
3494 static Lisp_Object func_key_syms
;
3495 static Lisp_Object mouse_syms
;
3497 static Lisp_Object mouse_wheel_syms
;
3499 static Lisp_Object drag_n_drop_syms
;
3501 /* This is a list of keysym codes for special "accent" characters.
3502 It parallels lispy_accent_keys. */
3504 static int lispy_accent_codes
[] =
3506 #ifdef XK_dead_circumflex
3511 #ifdef XK_dead_grave
3516 #ifdef XK_dead_tilde
3521 #ifdef XK_dead_diaeresis
3526 #ifdef XK_dead_macron
3531 #ifdef XK_dead_degree
3536 #ifdef XK_dead_acute
3541 #ifdef XK_dead_cedilla
3546 #ifdef XK_dead_breve
3551 #ifdef XK_dead_ogonek
3556 #ifdef XK_dead_caron
3561 #ifdef XK_dead_doubleacute
3562 XK_dead_doubleacute
,
3566 #ifdef XK_dead_abovedot
3573 /* This is a list of Lisp names for special "accent" characters.
3574 It parallels lispy_accent_codes. */
3576 static char *lispy_accent_keys
[] =
3594 #define FUNCTION_KEY_OFFSET 0x0
3596 char *lispy_function_keys
[] =
3600 0, /* VK_LBUTTON 0x01 */
3601 0, /* VK_RBUTTON 0x02 */
3602 "cancel", /* VK_CANCEL 0x03 */
3603 0, /* VK_MBUTTON 0x04 */
3605 0, 0, 0, /* 0x05 .. 0x07 */
3607 "backspace", /* VK_BACK 0x08 */
3608 "tab", /* VK_TAB 0x09 */
3610 0, 0, /* 0x0A .. 0x0B */
3612 "clear", /* VK_CLEAR 0x0C */
3613 "return", /* VK_RETURN 0x0D */
3615 0, 0, /* 0x0E .. 0x0F */
3617 "shift", /* VK_SHIFT 0x10 */
3618 "control", /* VK_CONTROL 0x11 */
3619 "menu", /* VK_MENU 0x12 */
3620 "pause", /* VK_PAUSE 0x13 */
3621 "capital", /* VK_CAPITAL 0x14 */
3623 0, 0, 0, 0, 0, 0, /* 0x15 .. 0x1A */
3625 0, /* VK_ESCAPE 0x1B */
3627 0, 0, 0, 0, /* 0x1C .. 0x1F */
3629 0, /* VK_SPACE 0x20 */
3630 "prior", /* VK_PRIOR 0x21 */
3631 "next", /* VK_NEXT 0x22 */
3632 "end", /* VK_END 0x23 */
3633 "home", /* VK_HOME 0x24 */
3634 "left", /* VK_LEFT 0x25 */
3635 "up", /* VK_UP 0x26 */
3636 "right", /* VK_RIGHT 0x27 */
3637 "down", /* VK_DOWN 0x28 */
3638 "select", /* VK_SELECT 0x29 */
3639 "print", /* VK_PRINT 0x2A */
3640 "execute", /* VK_EXECUTE 0x2B */
3641 "snapshot", /* VK_SNAPSHOT 0x2C */
3642 "insert", /* VK_INSERT 0x2D */
3643 "delete", /* VK_DELETE 0x2E */
3644 "help", /* VK_HELP 0x2F */
3646 /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
3648 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3650 0, 0, 0, 0, 0, 0, 0, /* 0x3A .. 0x40 */
3652 /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
3654 0, 0, 0, 0, 0, 0, 0, 0, 0,
3655 0, 0, 0, 0, 0, 0, 0, 0, 0,
3656 0, 0, 0, 0, 0, 0, 0, 0,
3658 "lwindow", /* VK_LWIN 0x5B */
3659 "rwindow", /* VK_RWIN 0x5C */
3660 "apps", /* VK_APPS 0x5D */
3662 0, 0, /* 0x5E .. 0x5F */
3664 "kp-0", /* VK_NUMPAD0 0x60 */
3665 "kp-1", /* VK_NUMPAD1 0x61 */
3666 "kp-2", /* VK_NUMPAD2 0x62 */
3667 "kp-3", /* VK_NUMPAD3 0x63 */
3668 "kp-4", /* VK_NUMPAD4 0x64 */
3669 "kp-5", /* VK_NUMPAD5 0x65 */
3670 "kp-6", /* VK_NUMPAD6 0x66 */
3671 "kp-7", /* VK_NUMPAD7 0x67 */
3672 "kp-8", /* VK_NUMPAD8 0x68 */
3673 "kp-9", /* VK_NUMPAD9 0x69 */
3674 "kp-multiply", /* VK_MULTIPLY 0x6A */
3675 "kp-add", /* VK_ADD 0x6B */
3676 "kp-separator", /* VK_SEPARATOR 0x6C */
3677 "kp-subtract", /* VK_SUBTRACT 0x6D */
3678 "kp-decimal", /* VK_DECIMAL 0x6E */
3679 "kp-divide", /* VK_DIVIDE 0x6F */
3680 "f1", /* VK_F1 0x70 */
3681 "f2", /* VK_F2 0x71 */
3682 "f3", /* VK_F3 0x72 */
3683 "f4", /* VK_F4 0x73 */
3684 "f5", /* VK_F5 0x74 */
3685 "f6", /* VK_F6 0x75 */
3686 "f7", /* VK_F7 0x76 */
3687 "f8", /* VK_F8 0x77 */
3688 "f9", /* VK_F9 0x78 */
3689 "f10", /* VK_F10 0x79 */
3690 "f11", /* VK_F11 0x7A */
3691 "f12", /* VK_F12 0x7B */
3692 "f13", /* VK_F13 0x7C */
3693 "f14", /* VK_F14 0x7D */
3694 "f15", /* VK_F15 0x7E */
3695 "f16", /* VK_F16 0x7F */
3696 "f17", /* VK_F17 0x80 */
3697 "f18", /* VK_F18 0x81 */
3698 "f19", /* VK_F19 0x82 */
3699 "f20", /* VK_F20 0x83 */
3700 "f21", /* VK_F21 0x84 */
3701 "f22", /* VK_F22 0x85 */
3702 "f23", /* VK_F23 0x86 */
3703 "f24", /* VK_F24 0x87 */
3705 0, 0, 0, 0, /* 0x88 .. 0x8B */
3706 0, 0, 0, 0, /* 0x8C .. 0x8F */
3708 "kp-numlock", /* VK_NUMLOCK 0x90 */
3709 "scroll", /* VK_SCROLL 0x91 */
3711 "kp-space", /* VK_NUMPAD_CLEAR 0x92 */
3712 "kp-enter", /* VK_NUMPAD_ENTER 0x93 */
3713 "kp-prior", /* VK_NUMPAD_PRIOR 0x94 */
3714 "kp-next", /* VK_NUMPAD_NEXT 0x95 */
3715 "kp-end", /* VK_NUMPAD_END 0x96 */
3716 "kp-home", /* VK_NUMPAD_HOME 0x97 */
3717 "kp-left", /* VK_NUMPAD_LEFT 0x98 */
3718 "kp-up", /* VK_NUMPAD_UP 0x99 */
3719 "kp-right", /* VK_NUMPAD_RIGHT 0x9A */
3720 "kp-down", /* VK_NUMPAD_DOWN 0x9B */
3721 "kp-insert", /* VK_NUMPAD_INSERT 0x9C */
3722 "kp-delete", /* VK_NUMPAD_DELETE 0x9D */
3724 0, 0, /* 0x9E .. 0x9F */
3727 * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
3728 * Used only as parameters to GetAsyncKeyState and GetKeyState.
3729 * No other API or message will distinguish left and right keys this way.
3733 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3734 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3735 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3736 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3737 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3743 "attn", /* VK_ATTN 0xF6 */
3744 "crsel", /* VK_CRSEL 0xF7 */
3745 "exsel", /* VK_EXSEL 0xF8 */
3746 "ereof", /* VK_EREOF 0xF9 */
3747 "play", /* VK_PLAY 0xFA */
3748 "zoom", /* VK_ZOOM 0xFB */
3749 "noname", /* VK_NONAME 0xFC */
3750 "pa1", /* VK_PA1 0xFD */
3751 "oem_clear", /* VK_OEM_CLEAR 0xFE */
3754 #else /* not HAVE_NTGUI */
3757 static char *lispy_kana_keys
[] =
3759 /* X Keysym value */
3760 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x400 .. 0x40f */
3761 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x410 .. 0x41f */
3762 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x420 .. 0x42f */
3763 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x430 .. 0x43f */
3764 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x440 .. 0x44f */
3765 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x450 .. 0x45f */
3766 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x460 .. 0x46f */
3767 0,0,0,0,0,0,0,0,0,0,0,0,0,0,"overline",0,
3768 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x480 .. 0x48f */
3769 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x490 .. 0x49f */
3770 0, "kana-fullstop", "kana-openingbracket", "kana-closingbracket",
3771 "kana-comma", "kana-conjunctive", "kana-WO", "kana-a",
3772 "kana-i", "kana-u", "kana-e", "kana-o",
3773 "kana-ya", "kana-yu", "kana-yo", "kana-tsu",
3774 "prolongedsound", "kana-A", "kana-I", "kana-U",
3775 "kana-E", "kana-O", "kana-KA", "kana-KI",
3776 "kana-KU", "kana-KE", "kana-KO", "kana-SA",
3777 "kana-SHI", "kana-SU", "kana-SE", "kana-SO",
3778 "kana-TA", "kana-CHI", "kana-TSU", "kana-TE",
3779 "kana-TO", "kana-NA", "kana-NI", "kana-NU",
3780 "kana-NE", "kana-NO", "kana-HA", "kana-HI",
3781 "kana-FU", "kana-HE", "kana-HO", "kana-MA",
3782 "kana-MI", "kana-MU", "kana-ME", "kana-MO",
3783 "kana-YA", "kana-YU", "kana-YO", "kana-RA",
3784 "kana-RI", "kana-RU", "kana-RE", "kana-RO",
3785 "kana-WA", "kana-N", "voicedsound", "semivoicedsound",
3786 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4e0 .. 0x4ef */
3787 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4f0 .. 0x4ff */
3789 #endif /* XK_kana_A */
3791 #define FUNCTION_KEY_OFFSET 0xff00
3793 /* You'll notice that this table is arranged to be conveniently
3794 indexed by X Windows keysym values. */
3795 static char *lispy_function_keys
[] =
3797 /* X Keysym value */
3799 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00...0f */
3800 "backspace", "tab", "linefeed", "clear",
3802 0, 0, 0, "pause", /* 0xff10...1f */
3803 0, 0, 0, 0, 0, 0, 0, "escape",
3805 0, "kanji", "muhenkan", "henkan", /* 0xff20...2f */
3806 "romaji", "hiragana", "katakana", "hiragana-katakana",
3807 "zenkaku", "hankaku", "zenkaku-hankaku", "touroku",
3808 "massyo", "kana-lock", "kana-shift", "eisu-shift",
3809 "eisu-toggle", /* 0xff30...3f */
3810 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3811 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
3813 "home", "left", "up", "right", /* 0xff50 */ /* IsCursorKey */
3814 "down", "prior", "next", "end",
3815 "begin", 0, 0, 0, 0, 0, 0, 0,
3816 "select", /* 0xff60 */ /* IsMiscFunctionKey */
3827 "break", /* 0xff6b */
3830 0, 0, 0, 0, "backtab", 0, 0, 0, /* 0xff70... */
3831 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff78... */
3832 "kp-space", /* 0xff80 */ /* IsKeypadKey */
3833 0, 0, 0, 0, 0, 0, 0, 0,
3834 "kp-tab", /* 0xff89 */
3836 "kp-enter", /* 0xff8d */
3838 "kp-f1", /* 0xff91 */
3842 "kp-home", /* 0xff95 */
3847 "kp-prior", /* kp-page-up */
3848 "kp-next", /* kp-page-down */
3854 0, 0, 0, 0, 0, 0, 0, 0, 0,
3855 "kp-multiply", /* 0xffaa */
3860 "kp-divide", /* 0xffaf */
3861 "kp-0", /* 0xffb0 */
3862 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
3865 "kp-equal", /* 0xffbd */
3866 "f1", /* 0xffbe */ /* IsFunctionKey */
3868 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
3869 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
3870 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
3871 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
3872 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
3873 0, 0, 0, 0, 0, 0, 0, 0,
3874 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
3875 0, 0, 0, 0, 0, 0, 0, "delete"
3878 /* ISO 9995 Function and Modifier Keys; the first byte is 0xFE. */
3879 #define ISO_FUNCTION_KEY_OFFSET 0xfe00
3881 static char *iso_lispy_function_keys
[] =
3883 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe00 */
3884 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe08 */
3885 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe10 */
3886 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe18 */
3887 "iso-lefttab", /* 0xfe20 */
3888 "iso-move-line-up", "iso-move-line-down",
3889 "iso-partial-line-up", "iso-partial-line-down",
3890 "iso-partial-space-left", "iso-partial-space-right",
3891 "iso-set-margin-left", "iso-set-margin-right", /* 0xffe27, 28 */
3892 "iso-release-margin-left", "iso-release-margin-right",
3893 "iso-release-both-margins",
3894 "iso-fast-cursor-left", "iso-fast-cursor-right",
3895 "iso-fast-cursor-up", "iso-fast-cursor-down",
3896 "iso-continuous-underline", "iso-discontinuous-underline", /* 0xfe30, 31 */
3897 "iso-emphasize", "iso-center-object", "iso-enter", /* ... 0xfe34 */
3900 #endif /* not HAVE_NTGUI */
3902 static char *lispy_mouse_names
[] =
3904 "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5"
3908 /* mouse-wheel events are generated by the wheel on devices such as
3909 the MS Intellimouse. The wheel sits in between the left and right
3910 mouse buttons, and is typically used to scroll or zoom the window
3911 underneath the pointer. mouse-wheel events specify the object on
3912 which they operate, and a delta corresponding to the amount and
3913 direction that the wheel is rotated. Clicking the mouse-wheel
3914 generates a mouse-2 event. */
3915 static char *lispy_mouse_wheel_names
[] =
3920 #endif /* WINDOWSNT */
3922 /* drag-n-drop events are generated when a set of selected files are
3923 dragged from another application and dropped onto an Emacs window. */
3924 static char *lispy_drag_n_drop_names
[] =
3929 /* Scroll bar parts. */
3930 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
3931 Lisp_Object Qup
, Qdown
;
3933 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
3934 Lisp_Object
*scroll_bar_parts
[] = {
3935 &Qabove_handle
, &Qhandle
, &Qbelow_handle
,
3940 /* A vector, indexed by button number, giving the down-going location
3941 of currently depressed buttons, both scroll bar and non-scroll bar.
3943 The elements have the form
3944 (BUTTON-NUMBER MODIFIER-MASK . REST)
3945 where REST is the cdr of a position as it would be reported in the event.
3947 The make_lispy_event function stores positions here to tell the
3948 difference between click and drag events, and to store the starting
3949 location to be included in drag events. */
3951 static Lisp_Object button_down_location
;
3953 /* Information about the most recent up-going button event: Which
3954 button, what location, and what time. */
3956 static int last_mouse_button
;
3957 static int last_mouse_x
;
3958 static int last_mouse_y
;
3959 static unsigned long button_down_time
;
3961 /* The maximum time between clicks to make a double-click,
3962 or Qnil to disable double-click detection,
3963 or Qt for no time limit. */
3964 Lisp_Object Vdouble_click_time
;
3966 /* The number of clicks in this multiple-click. */
3968 int double_click_count
;
3970 /* Given a struct input_event, build the lisp event which represents
3971 it. If EVENT is 0, build a mouse movement event from the mouse
3972 movement buffer, which should have a movement event in it.
3974 Note that events must be passed to this function in the order they
3975 are received; this function stores the location of button presses
3976 in order to build drag events when the button is released. */
3979 make_lispy_event (event
)
3980 struct input_event
*event
;
3984 switch (SWITCH_ENUM_CAST (event
->kind
))
3986 /* A simple keystroke. */
3987 case ascii_keystroke
:
3989 Lisp_Object lispy_c
;
3990 int c
= event
->code
& 0377;
3991 /* Turn ASCII characters into control characters
3993 if (event
->modifiers
& ctrl_modifier
)
3994 c
= make_ctrl_char (c
);
3996 /* Add in the other modifier bits. We took care of ctrl_modifier
3997 just above, and the shift key was taken care of by the X code,
3998 and applied to control characters by make_ctrl_char. */
3999 c
|= (event
->modifiers
4000 & (meta_modifier
| alt_modifier
4001 | hyper_modifier
| super_modifier
));
4002 /* Distinguish Shift-SPC from SPC. */
4003 if ((event
->code
& 0377) == 040
4004 && event
->modifiers
& shift_modifier
)
4005 c
|= shift_modifier
;
4006 button_down_time
= 0;
4007 XSETFASTINT (lispy_c
, c
);
4011 /* A function key. The symbol may need to have modifier prefixes
4013 case non_ascii_keystroke
:
4014 button_down_time
= 0;
4016 for (i
= 0; i
< sizeof (lispy_accent_codes
) / sizeof (int); i
++)
4017 if (event
->code
== lispy_accent_codes
[i
])
4018 return modify_event_symbol (i
,
4020 Qfunction_key
, Qnil
,
4021 lispy_accent_keys
, &accent_key_syms
,
4022 (sizeof (lispy_accent_keys
)
4023 / sizeof (lispy_accent_keys
[0])));
4025 /* Handle system-specific keysyms. */
4026 if (event
->code
& (1 << 28))
4028 /* We need to use an alist rather than a vector as the cache
4029 since we can't make a vector long enuf. */
4030 if (NILP (current_kboard
->system_key_syms
))
4031 current_kboard
->system_key_syms
= Fcons (Qnil
, Qnil
);
4032 return modify_event_symbol (event
->code
,
4035 current_kboard
->Vsystem_key_alist
,
4036 0, ¤t_kboard
->system_key_syms
,
4041 if (event
->code
>= 0x400 && event
->code
< 0x500)
4042 return modify_event_symbol (event
->code
- 0x400,
4043 event
->modifiers
& ~shift_modifier
,
4044 Qfunction_key
, Qnil
,
4045 lispy_kana_keys
, &func_key_syms
,
4046 (sizeof (lispy_kana_keys
)
4047 / sizeof (lispy_kana_keys
[0])));
4048 #endif /* XK_kana_A */
4050 #ifdef ISO_FUNCTION_KEY_OFFSET
4051 if (event
->code
< FUNCTION_KEY_OFFSET
4052 && event
->code
>= ISO_FUNCTION_KEY_OFFSET
)
4053 return modify_event_symbol (event
->code
- ISO_FUNCTION_KEY_OFFSET
,
4055 Qfunction_key
, Qnil
,
4056 iso_lispy_function_keys
, &func_key_syms
,
4057 (sizeof (iso_lispy_function_keys
)
4058 / sizeof (iso_lispy_function_keys
[0])));
4061 return modify_event_symbol (event
->code
- FUNCTION_KEY_OFFSET
,
4063 Qfunction_key
, Qnil
,
4064 lispy_function_keys
, &func_key_syms
,
4065 (sizeof (lispy_function_keys
)
4066 / sizeof (lispy_function_keys
[0])));
4069 /* A mouse click. Figure out where it is, decide whether it's
4070 a press, click or drag, and build the appropriate structure. */
4072 case scroll_bar_click
:
4074 int button
= event
->code
;
4076 Lisp_Object position
;
4077 Lisp_Object
*start_pos_ptr
;
4078 Lisp_Object start_pos
;
4080 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
4083 /* Build the position as appropriate for this mouse click. */
4084 if (event
->kind
== mouse_click
)
4087 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
4092 /* Ignore mouse events that were made on frame that
4093 have been deleted. */
4094 if (! FRAME_LIVE_P (f
))
4097 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4098 &column
, &row
, NULL
, 1);
4100 #ifndef USE_X_TOOLKIT
4101 /* In the non-toolkit version, clicks on the menu bar
4102 are ordinary button events in the event buffer.
4103 Distinguish them, and invoke the menu.
4105 (In the toolkit version, the toolkit handles the menu bar
4106 and Emacs doesn't know about it until after the user
4107 makes a selection.) */
4108 if (row
>= 0 && row
< FRAME_MENU_BAR_LINES (f
)
4109 && (event
->modifiers
& down_modifier
))
4111 Lisp_Object items
, item
;
4116 /* Activate the menu bar on the down event. If the
4117 up event comes in before the menu code can deal with it,
4119 if (! (event
->modifiers
& down_modifier
))
4124 items
= FRAME_MENU_BAR_ITEMS (f
);
4125 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
4127 Lisp_Object pos
, string
;
4128 string
= XVECTOR (items
)->contents
[i
+ 1];
4129 pos
= XVECTOR (items
)->contents
[i
+ 3];
4132 if (column
>= XINT (pos
)
4133 && column
< XINT (pos
) + XSTRING (string
)->size
)
4135 item
= XVECTOR (items
)->contents
[i
];
4141 = Fcons (event
->frame_or_window
,
4143 Fcons (Fcons (event
->x
, event
->y
),
4144 Fcons (make_number (event
->timestamp
),
4147 return Fcons (item
, Fcons (position
, Qnil
));
4149 #endif /* not USE_X_TOOLKIT */
4151 window
= window_from_coordinates (f
, column
, row
, &part
);
4153 if (!WINDOWP (window
))
4155 window
= event
->frame_or_window
;
4160 int pixcolumn
, pixrow
;
4161 column
-= WINDOW_LEFT_MARGIN (XWINDOW (window
));
4162 row
-= XINT (XWINDOW (window
)->top
);
4163 glyph_to_pixel_coords (f
, column
, row
, &pixcolumn
, &pixrow
);
4164 XSETINT (event
->x
, pixcolumn
);
4165 XSETINT (event
->y
, pixrow
);
4170 posn
= Qvertical_line
;
4173 buffer_posn_from_coords (XWINDOW (window
),
4180 Fcons (Fcons (event
->x
, event
->y
),
4181 Fcons (make_number (event
->timestamp
),
4187 Lisp_Object portion_whole
;
4190 window
= event
->frame_or_window
;
4191 portion_whole
= Fcons (event
->x
, event
->y
);
4192 part
= *scroll_bar_parts
[(int) event
->part
];
4196 Fcons (Qvertical_scroll_bar
,
4197 Fcons (portion_whole
,
4198 Fcons (make_number (event
->timestamp
),
4199 Fcons (part
, Qnil
)))));
4202 start_pos_ptr
= &XVECTOR (button_down_location
)->contents
[button
];
4204 start_pos
= *start_pos_ptr
;
4205 *start_pos_ptr
= Qnil
;
4207 is_double
= (button
== last_mouse_button
4208 && XINT (event
->x
) == last_mouse_x
4209 && XINT (event
->y
) == last_mouse_y
4210 && button_down_time
!= 0
4211 && (EQ (Vdouble_click_time
, Qt
)
4212 || (INTEGERP (Vdouble_click_time
)
4213 && ((int)(event
->timestamp
- button_down_time
)
4214 < XINT (Vdouble_click_time
)))));
4215 last_mouse_button
= button
;
4216 last_mouse_x
= XINT (event
->x
);
4217 last_mouse_y
= XINT (event
->y
);
4219 /* If this is a button press, squirrel away the location, so
4220 we can decide later whether it was a click or a drag. */
4221 if (event
->modifiers
& down_modifier
)
4225 double_click_count
++;
4226 event
->modifiers
|= ((double_click_count
> 2)
4231 double_click_count
= 1;
4232 button_down_time
= event
->timestamp
;
4233 *start_pos_ptr
= Fcopy_alist (position
);
4236 /* Now we're releasing a button - check the co-ordinates to
4237 see if this was a click or a drag. */
4238 else if (event
->modifiers
& up_modifier
)
4240 /* If we did not see a down before this up,
4241 ignore the up. Probably this happened because
4242 the down event chose a menu item.
4243 It would be an annoyance to treat the release
4244 of the button that chose the menu item
4245 as a separate event. */
4247 if (!CONSP (start_pos
))
4250 event
->modifiers
&= ~up_modifier
;
4251 #if 0 /* Formerly we treated an up with no down as a click event. */
4252 if (!CONSP (start_pos
))
4253 event
->modifiers
|= click_modifier
;
4257 /* The third element of every position should be the (x,y)
4261 down
= Fnth (make_number (2), start_pos
);
4262 if (EQ (event
->x
, XCONS (down
)->car
)
4263 && EQ (event
->y
, XCONS (down
)->cdr
))
4265 event
->modifiers
|= click_modifier
;
4269 button_down_time
= 0;
4270 event
->modifiers
|= drag_modifier
;
4272 /* Don't check is_double; treat this as multiple
4273 if the down-event was multiple. */
4274 if (double_click_count
> 1)
4275 event
->modifiers
|= ((double_click_count
> 2)
4281 /* Every mouse event should either have the down_modifier or
4282 the up_modifier set. */
4286 /* Get the symbol we should use for the mouse click. */
4289 head
= modify_event_symbol (button
,
4292 lispy_mouse_names
, &mouse_syms
,
4293 (sizeof (lispy_mouse_names
)
4294 / sizeof (lispy_mouse_names
[0])));
4295 if (event
->modifiers
& drag_modifier
)
4300 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
4303 Fcons (make_number (double_click_count
),
4313 case w32_scroll_bar_click
:
4315 int button
= event
->code
;
4317 Lisp_Object position
;
4318 Lisp_Object
*start_pos_ptr
;
4319 Lisp_Object start_pos
;
4321 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
4326 Lisp_Object portion_whole
;
4329 window
= event
->frame_or_window
;
4330 portion_whole
= Fcons (event
->x
, event
->y
);
4331 part
= *scroll_bar_parts
[(int) event
->part
];
4335 Fcons (Qvertical_scroll_bar
,
4336 Fcons (portion_whole
,
4337 Fcons (make_number (event
->timestamp
),
4338 Fcons (part
, Qnil
)))));
4341 /* Always treat W32 scroll bar events as clicks. */
4342 event
->modifiers
|= click_modifier
;
4345 /* Get the symbol we should use for the mouse click. */
4348 head
= modify_event_symbol (button
,
4351 lispy_mouse_names
, &mouse_syms
,
4352 (sizeof (lispy_mouse_names
)
4353 / sizeof (lispy_mouse_names
[0])));
4362 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
4365 Lisp_Object head
, position
;
4368 /* Ignore mouse events that were made on frame that
4369 have been deleted. */
4370 if (! FRAME_LIVE_P (f
))
4372 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4373 &column
, &row
, NULL
, 1);
4374 window
= window_from_coordinates (f
, column
, row
, &part
);
4376 if (!WINDOWP (window
))
4378 window
= event
->frame_or_window
;
4383 int pixcolumn
, pixrow
;
4384 column
-= XINT (XWINDOW (window
)->left
);
4385 row
-= XINT (XWINDOW (window
)->top
);
4386 glyph_to_pixel_coords (f
, column
, row
, &pixcolumn
, &pixrow
);
4387 XSETINT (event
->x
, pixcolumn
);
4388 XSETINT (event
->y
, pixrow
);
4393 posn
= Qvertical_line
;
4396 buffer_posn_from_coords (XWINDOW (window
),
4401 Lisp_Object head
, position
;
4406 Fcons (Fcons (event
->x
, event
->y
),
4407 Fcons (make_number (event
->timestamp
),
4410 head
= modify_event_symbol (0, event
->modifiers
,
4412 lispy_mouse_wheel_names
,
4413 &mouse_wheel_syms
, 1);
4416 Fcons (make_number (event
->code
),
4420 #endif /* WINDOWSNT */
4428 Lisp_Object head
, position
;
4432 /* The frame_or_window field should be a cons of the frame in
4433 which the event occurred and a list of the filenames
4435 if (! CONSP (event
->frame_or_window
))
4438 f
= XFRAME (XCONS (event
->frame_or_window
)->car
);
4439 files
= XCONS (event
->frame_or_window
)->cdr
;
4441 /* Ignore mouse events that were made on frames that
4442 have been deleted. */
4443 if (! FRAME_LIVE_P (f
))
4445 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4446 &column
, &row
, NULL
, 1);
4447 window
= window_from_coordinates (f
, column
, row
, &part
);
4449 if (!WINDOWP (window
))
4451 window
= XCONS (event
->frame_or_window
)->car
;
4456 int pixcolumn
, pixrow
;
4457 column
-= XINT (XWINDOW (window
)->left
);
4458 row
-= XINT (XWINDOW (window
)->top
);
4459 glyph_to_pixel_coords (f
, column
, row
, &pixcolumn
, &pixrow
);
4460 XSETINT (event
->x
, pixcolumn
);
4461 XSETINT (event
->y
, pixrow
);
4466 posn
= Qvertical_line
;
4469 buffer_posn_from_coords (XWINDOW (window
),
4474 Lisp_Object head
, position
;
4479 Fcons (Fcons (event
->x
, event
->y
),
4480 Fcons (make_number (event
->timestamp
),
4483 head
= modify_event_symbol (0, event
->modifiers
,
4485 lispy_drag_n_drop_names
,
4486 &drag_n_drop_syms
, 1);
4493 #endif /* HAVE_MOUSE */
4495 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
4496 case menu_bar_event
:
4497 /* The event value is in the cdr of the frame_or_window slot. */
4498 if (!CONSP (event
->frame_or_window
))
4500 return XCONS (event
->frame_or_window
)->cdr
;
4503 /* The 'kind' field of the event is something we don't recognize. */
4512 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
4514 Lisp_Object bar_window
;
4515 enum scroll_bar_part part
;
4519 /* Is it a scroll bar movement? */
4520 if (frame
&& ! NILP (bar_window
))
4522 Lisp_Object part_sym
;
4524 part_sym
= *scroll_bar_parts
[(int) part
];
4525 return Fcons (Qscroll_bar_movement
,
4526 (Fcons (Fcons (bar_window
,
4527 Fcons (Qvertical_scroll_bar
,
4528 Fcons (Fcons (x
, y
),
4529 Fcons (make_number (time
),
4535 /* Or is it an ordinary mouse movement? */
4545 /* It's in a frame; which window on that frame? */
4546 pixel_to_glyph_coords (frame
, XINT (x
), XINT (y
), &column
, &row
,
4548 window
= window_from_coordinates (frame
, column
, row
, &area
);
4553 if (WINDOWP (window
))
4555 int pixcolumn
, pixrow
;
4556 column
-= WINDOW_LEFT_MARGIN (XWINDOW (window
));
4557 row
-= XINT (XWINDOW (window
)->top
);
4558 glyph_to_pixel_coords (frame
, column
, row
, &pixcolumn
, &pixrow
);
4559 XSETINT (x
, pixcolumn
);
4560 XSETINT (y
, pixrow
);
4565 posn
= Qvertical_line
;
4568 buffer_posn_from_coords (XWINDOW (window
), column
, row
));
4570 else if (frame
!= 0)
4572 XSETFRAME (window
, frame
);
4583 return Fcons (Qmouse_movement
,
4584 Fcons (Fcons (window
,
4586 Fcons (Fcons (x
, y
),
4587 Fcons (make_number (time
),
4593 #endif /* HAVE_MOUSE */
4595 /* Construct a switch frame event. */
4597 make_lispy_switch_frame (frame
)
4600 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
4603 /* Manipulating modifiers. */
4605 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
4607 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
4608 SYMBOL's name of the end of the modifiers; the string from this
4609 position is the unmodified symbol name.
4611 This doesn't use any caches. */
4614 parse_modifiers_uncached (symbol
, modifier_end
)
4618 struct Lisp_String
*name
;
4622 CHECK_SYMBOL (symbol
, 1);
4625 name
= XSYMBOL (symbol
)->name
;
4627 for (i
= 0; i
+2 <= STRING_BYTES (name
); )
4629 int this_mod_end
= 0;
4632 /* See if the name continues with a modifier word.
4633 Check that the word appears, but don't check what follows it.
4634 Set this_mod and this_mod_end to record what we find. */
4636 switch (name
->data
[i
])
4638 #define SINGLE_LETTER_MOD(BIT) \
4639 (this_mod_end = i + 1, this_mod = BIT)
4642 SINGLE_LETTER_MOD (alt_modifier
);
4646 SINGLE_LETTER_MOD (ctrl_modifier
);
4650 SINGLE_LETTER_MOD (hyper_modifier
);
4654 SINGLE_LETTER_MOD (meta_modifier
);
4658 SINGLE_LETTER_MOD (shift_modifier
);
4662 SINGLE_LETTER_MOD (super_modifier
);
4665 #undef SINGLE_LETTER_MOD
4668 /* If we found no modifier, stop looking for them. */
4669 if (this_mod_end
== 0)
4672 /* Check there is a dash after the modifier, so that it
4673 really is a modifier. */
4674 if (this_mod_end
>= STRING_BYTES (name
)
4675 || name
->data
[this_mod_end
] != '-')
4678 /* This modifier is real; look for another. */
4679 modifiers
|= this_mod
;
4680 i
= this_mod_end
+ 1;
4683 /* Should we include the `click' modifier? */
4684 if (! (modifiers
& (down_modifier
| drag_modifier
4685 | double_modifier
| triple_modifier
))
4686 && i
+ 7 == STRING_BYTES (name
)
4687 && strncmp (name
->data
+ i
, "mouse-", 6) == 0
4688 && ('0' <= name
->data
[i
+ 6] && name
->data
[i
+ 6] <= '9'))
4689 modifiers
|= click_modifier
;
4697 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
4698 prepended to the string BASE[0..BASE_LEN-1].
4699 This doesn't use any caches. */
4701 apply_modifiers_uncached (modifiers
, base
, base_len
, base_len_byte
)
4704 int base_len
, base_len_byte
;
4706 /* Since BASE could contain nulls, we can't use intern here; we have
4707 to use Fintern, which expects a genuine Lisp_String, and keeps a
4710 = (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
4716 /* Only the event queue may use the `up' modifier; it should always
4717 be turned into a click or drag event before presented to lisp code. */
4718 if (modifiers
& up_modifier
)
4721 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
4722 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
4723 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
4724 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
4725 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
4726 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
4727 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
4728 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
4729 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
4730 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
4731 /* The click modifier is denoted by the absence of other modifiers. */
4735 mod_len
= p
- new_mods
;
4739 Lisp_Object new_name
;
4741 new_name
= make_uninit_multibyte_string (mod_len
+ base_len
,
4742 mod_len
+ base_len_byte
);
4743 bcopy (new_mods
, XSTRING (new_name
)->data
, mod_len
);
4744 bcopy (base
, XSTRING (new_name
)->data
+ mod_len
, base_len_byte
);
4746 return Fintern (new_name
, Qnil
);
4751 static char *modifier_names
[] =
4753 "up", "down", "drag", "click", "double", "triple", 0, 0,
4754 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4755 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
4757 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
4759 static Lisp_Object modifier_symbols
;
4761 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
4763 lispy_modifier_list (modifiers
)
4766 Lisp_Object modifier_list
;
4769 modifier_list
= Qnil
;
4770 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
4771 if (modifiers
& (1<<i
))
4772 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
4775 return modifier_list
;
4779 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
4780 where UNMODIFIED is the unmodified form of SYMBOL,
4781 MASK is the set of modifiers present in SYMBOL's name.
4782 This is similar to parse_modifiers_uncached, but uses the cache in
4783 SYMBOL's Qevent_symbol_element_mask property, and maintains the
4784 Qevent_symbol_elements property. */
4787 parse_modifiers (symbol
)
4790 Lisp_Object elements
;
4792 elements
= Fget (symbol
, Qevent_symbol_element_mask
);
4793 if (CONSP (elements
))
4798 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
4799 Lisp_Object unmodified
;
4802 unmodified
= Fintern (make_string (XSYMBOL (symbol
)->name
->data
+ end
,
4803 STRING_BYTES (XSYMBOL (symbol
)->name
) - end
),
4806 if (modifiers
& ~(((EMACS_INT
)1 << VALBITS
) - 1))
4808 XSETFASTINT (mask
, modifiers
);
4809 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
4811 /* Cache the parsing results on SYMBOL. */
4812 Fput (symbol
, Qevent_symbol_element_mask
,
4814 Fput (symbol
, Qevent_symbol_elements
,
4815 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
4817 /* Since we know that SYMBOL is modifiers applied to unmodified,
4818 it would be nice to put that in unmodified's cache.
4819 But we can't, since we're not sure that parse_modifiers is
4826 /* Apply the modifiers MODIFIERS to the symbol BASE.
4827 BASE must be unmodified.
4829 This is like apply_modifiers_uncached, but uses BASE's
4830 Qmodifier_cache property, if present. It also builds
4831 Qevent_symbol_elements properties, since it has that info anyway.
4833 apply_modifiers copies the value of BASE's Qevent_kind property to
4834 the modified symbol. */
4836 apply_modifiers (modifiers
, base
)
4840 Lisp_Object cache
, index
, entry
, new_symbol
;
4842 /* Mask out upper bits. We don't know where this value's been. */
4843 modifiers
&= ((EMACS_INT
)1 << VALBITS
) - 1;
4845 /* The click modifier never figures into cache indices. */
4846 cache
= Fget (base
, Qmodifier_cache
);
4847 XSETFASTINT (index
, (modifiers
& ~click_modifier
));
4848 entry
= assq_no_quit (index
, cache
);
4851 new_symbol
= XCONS (entry
)->cdr
;
4854 /* We have to create the symbol ourselves. */
4855 new_symbol
= apply_modifiers_uncached (modifiers
,
4856 XSYMBOL (base
)->name
->data
,
4857 XSYMBOL (base
)->name
->size
,
4858 STRING_BYTES (XSYMBOL (base
)->name
));
4860 /* Add the new symbol to the base's cache. */
4861 entry
= Fcons (index
, new_symbol
);
4862 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
4864 /* We have the parsing info now for free, so add it to the caches. */
4865 XSETFASTINT (index
, modifiers
);
4866 Fput (new_symbol
, Qevent_symbol_element_mask
,
4867 Fcons (base
, Fcons (index
, Qnil
)));
4868 Fput (new_symbol
, Qevent_symbol_elements
,
4869 Fcons (base
, lispy_modifier_list (modifiers
)));
4872 /* Make sure this symbol is of the same kind as BASE.
4874 You'd think we could just set this once and for all when we
4875 intern the symbol above, but reorder_modifiers may call us when
4876 BASE's property isn't set right; we can't assume that just
4877 because it has a Qmodifier_cache property it must have its
4878 Qevent_kind set right as well. */
4879 if (NILP (Fget (new_symbol
, Qevent_kind
)))
4883 kind
= Fget (base
, Qevent_kind
);
4885 Fput (new_symbol
, Qevent_kind
, kind
);
4892 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
4893 return a symbol with the modifiers placed in the canonical order.
4894 Canonical order is alphabetical, except for down and drag, which
4895 always come last. The 'click' modifier is never written out.
4897 Fdefine_key calls this to make sure that (for example) C-M-foo
4898 and M-C-foo end up being equivalent in the keymap. */
4901 reorder_modifiers (symbol
)
4904 /* It's hopefully okay to write the code this way, since everything
4905 will soon be in caches, and no consing will be done at all. */
4908 parsed
= parse_modifiers (symbol
);
4909 return apply_modifiers ((int) XINT (XCONS (XCONS (parsed
)->cdr
)->car
),
4910 XCONS (parsed
)->car
);
4914 /* For handling events, we often want to produce a symbol whose name
4915 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
4916 to some base, like the name of a function key or mouse button.
4917 modify_event_symbol produces symbols of this sort.
4919 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
4920 is the name of the i'th symbol. TABLE_SIZE is the number of elements
4923 Alternatively, NAME_ALIST is an alist mapping codes into symbol names.
4924 NAME_ALIST is used if it is non-nil; otherwise NAME_TABLE is used.
4926 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
4927 persist between calls to modify_event_symbol that it can use to
4928 store a cache of the symbols it's generated for this NAME_TABLE
4929 before. The object stored there may be a vector or an alist.
4931 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
4933 MODIFIERS is a set of modifier bits (as given in struct input_events)
4934 whose prefixes should be applied to the symbol name.
4936 SYMBOL_KIND is the value to be placed in the event_kind property of
4937 the returned symbol.
4939 The symbols we create are supposed to have an
4940 `event-symbol-elements' property, which lists the modifiers present
4941 in the symbol's name. */
4944 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_alist
,
4945 name_table
, symbol_table
, table_size
)
4948 Lisp_Object symbol_kind
;
4949 Lisp_Object name_alist
;
4951 Lisp_Object
*symbol_table
;
4952 unsigned int table_size
;
4955 Lisp_Object symbol_int
;
4957 /* Get rid of the "vendor-specific" bit here. */
4958 XSETINT (symbol_int
, symbol_num
& 0xffffff);
4960 /* Is this a request for a valid symbol? */
4961 if (symbol_num
< 0 || symbol_num
>= table_size
)
4964 if (CONSP (*symbol_table
))
4965 value
= Fcdr (assq_no_quit (symbol_int
, *symbol_table
));
4967 /* If *symbol_table doesn't seem to be initialized properly, fix that.
4968 *symbol_table should be a lisp vector TABLE_SIZE elements long,
4969 where the Nth element is the symbol for NAME_TABLE[N], or nil if
4970 we've never used that symbol before. */
4973 if (! VECTORP (*symbol_table
)
4974 || XVECTOR (*symbol_table
)->size
!= table_size
)
4978 XSETFASTINT (size
, table_size
);
4979 *symbol_table
= Fmake_vector (size
, Qnil
);
4982 value
= XVECTOR (*symbol_table
)->contents
[symbol_num
];
4985 /* Have we already used this symbol before? */
4988 /* No; let's create it. */
4989 if (!NILP (name_alist
))
4990 value
= Fcdr_safe (Fassq (symbol_int
, name_alist
));
4991 else if (name_table
!= 0 && name_table
[symbol_num
])
4992 value
= intern (name_table
[symbol_num
]);
4994 #ifdef HAVE_WINDOW_SYSTEM
4997 char *name
= x_get_keysym_name (symbol_num
);
4999 value
= intern (name
);
5006 sprintf (buf
, "key-%d", symbol_num
);
5007 value
= intern (buf
);
5010 if (CONSP (*symbol_table
))
5011 *symbol_table
= Fcons (Fcons (symbol_int
, value
), *symbol_table
);
5013 XVECTOR (*symbol_table
)->contents
[symbol_num
] = value
;
5015 /* Fill in the cache entries for this symbol; this also
5016 builds the Qevent_symbol_elements property, which the user
5018 apply_modifiers (modifiers
& click_modifier
, value
);
5019 Fput (value
, Qevent_kind
, symbol_kind
);
5022 /* Apply modifiers to that symbol. */
5023 return apply_modifiers (modifiers
, value
);
5026 /* Convert a list that represents an event type,
5027 such as (ctrl meta backspace), into the usual representation of that
5028 event type as a number or a symbol. */
5030 DEFUN ("event-convert-list", Fevent_convert_list
, Sevent_convert_list
, 1, 1, 0,
5031 "Convert the event description list EVENT-DESC to an event type.\n\
5032 EVENT-DESC should contain one base event type (a character or symbol)\n\
5033 and zero or more modifier names (control, meta, hyper, super, shift, alt,\n\
5034 drag, down, double or triple). The base must be last.\n\
5035 The return value is an event type (a character or symbol) which\n\
5036 has the same base event type and all the specified modifiers.")
5038 Lisp_Object event_desc
;
5046 while (CONSP (rest
))
5051 elt
= XCONS (rest
)->car
;
5052 rest
= XCONS (rest
)->cdr
;
5054 /* Given a symbol, see if it is a modifier name. */
5055 if (SYMBOLP (elt
) && CONSP (rest
))
5056 this = parse_solitary_modifier (elt
);
5060 else if (!NILP (base
))
5061 error ("Two bases given in one event");
5067 /* Let the symbol A refer to the character A. */
5068 if (SYMBOLP (base
) && XSYMBOL (base
)->name
->size
== 1)
5069 XSETINT (base
, XSYMBOL (base
)->name
->data
[0]);
5071 if (INTEGERP (base
))
5073 /* Turn (shift a) into A. */
5074 if ((modifiers
& shift_modifier
) != 0
5075 && (XINT (base
) >= 'a' && XINT (base
) <= 'z'))
5077 XSETINT (base
, XINT (base
) - ('a' - 'A'));
5078 modifiers
&= ~shift_modifier
;
5081 /* Turn (control a) into C-a. */
5082 if (modifiers
& ctrl_modifier
)
5083 return make_number ((modifiers
& ~ctrl_modifier
)
5084 | make_ctrl_char (XINT (base
)));
5086 return make_number (modifiers
| XINT (base
));
5088 else if (SYMBOLP (base
))
5089 return apply_modifiers (modifiers
, base
);
5091 error ("Invalid base event");
5094 /* Try to recognize SYMBOL as a modifier name.
5095 Return the modifier flag bit, or 0 if not recognized. */
5098 parse_solitary_modifier (symbol
)
5101 struct Lisp_String
*name
= XSYMBOL (symbol
)->name
;
5103 switch (name
->data
[0])
5105 #define SINGLE_LETTER_MOD(BIT) \
5106 if (STRING_BYTES (name) == 1) \
5109 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
5110 if (LEN == STRING_BYTES (name) \
5111 && ! strncmp (name->data, NAME, LEN)) \
5115 SINGLE_LETTER_MOD (alt_modifier
);
5119 MULTI_LETTER_MOD (alt_modifier
, "alt", 3);
5123 SINGLE_LETTER_MOD (ctrl_modifier
);
5127 MULTI_LETTER_MOD (ctrl_modifier
, "ctrl", 4);
5128 MULTI_LETTER_MOD (ctrl_modifier
, "control", 7);
5132 SINGLE_LETTER_MOD (hyper_modifier
);
5136 MULTI_LETTER_MOD (hyper_modifier
, "hyper", 5);
5140 SINGLE_LETTER_MOD (meta_modifier
);
5144 MULTI_LETTER_MOD (meta_modifier
, "meta", 4);
5148 SINGLE_LETTER_MOD (shift_modifier
);
5152 MULTI_LETTER_MOD (shift_modifier
, "shift", 5);
5153 MULTI_LETTER_MOD (super_modifier
, "super", 5);
5154 SINGLE_LETTER_MOD (super_modifier
);
5158 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
5159 MULTI_LETTER_MOD (down_modifier
, "down", 4);
5160 MULTI_LETTER_MOD (double_modifier
, "double", 6);
5164 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
5167 #undef SINGLE_LETTER_MOD
5168 #undef MULTI_LETTER_MOD
5174 /* Return 1 if EVENT is a list whose elements are all integers or symbols.
5175 Such a list is not valid as an event,
5176 but it can be a Lucid-style event type list. */
5179 lucid_event_type_list_p (object
)
5184 if (! CONSP (object
))
5187 for (tail
= object
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5190 elt
= XCONS (tail
)->car
;
5191 if (! (INTEGERP (elt
) || SYMBOLP (elt
)))
5198 /* Store into *addr a value nonzero if terminal input chars are available.
5199 Serves the purpose of ioctl (0, FIONREAD, addr)
5200 but works even if FIONREAD does not exist.
5201 (In fact, this may actually read some input.)
5203 If DO_TIMERS_NOW is nonzero, actually run timer events that are ripe. */
5206 get_input_pending (addr
, do_timers_now
)
5210 /* First of all, have we already counted some input? */
5211 *addr
= !NILP (Vquit_flag
) || readable_events (do_timers_now
);
5213 /* If input is being read as it arrives, and we have none, there is none. */
5214 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
5217 /* Try to read some input and see how much we get. */
5219 *addr
= !NILP (Vquit_flag
) || readable_events (do_timers_now
);
5222 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
5225 gobble_input (expected
)
5230 if (interrupt_input
)
5233 mask
= sigblock (sigmask (SIGIO
));
5234 read_avail_input (expected
);
5238 #ifdef POLL_FOR_INPUT
5239 if (read_socket_hook
&& !interrupt_input
&& poll_suppress_count
== 0)
5242 mask
= sigblock (sigmask (SIGALRM
));
5243 read_avail_input (expected
);
5249 read_avail_input (expected
);
5253 /* Put a buffer_switch_event in the buffer
5254 so that read_key_sequence will notice the new current buffer. */
5257 record_asynch_buffer_change ()
5259 struct input_event event
;
5262 event
.kind
= buffer_switch_event
;
5263 event
.frame_or_window
= Qnil
;
5266 /* We don't need a buffer-switch event unless Emacs is waiting for input.
5267 The purpose of the event is to make read_key_sequence look up the
5268 keymaps again. If we aren't in read_key_sequence, we don't need one,
5269 and the event could cause trouble by messing up (input-pending-p). */
5270 tem
= Fwaiting_for_user_input_p ();
5274 /* We never need these events if we have no asynchronous subprocesses. */
5278 /* Make sure no interrupt happens while storing the event. */
5280 if (interrupt_input
)
5283 mask
= sigblock (sigmask (SIGIO
));
5284 kbd_buffer_store_event (&event
);
5291 kbd_buffer_store_event (&event
);
5298 /* Read any terminal input already buffered up by the system
5299 into the kbd_buffer, but do not wait.
5301 EXPECTED should be nonzero if the caller knows there is some input.
5303 Except on VMS, all input is read by this function.
5304 If interrupt_input is nonzero, this function MUST be called
5305 only when SIGIO is blocked.
5307 Returns the number of keyboard chars read, or -1 meaning
5308 this is a bad time to try to read input. */
5311 read_avail_input (expected
)
5314 struct input_event buf
[KBD_BUFFER_SIZE
];
5318 if (read_socket_hook
)
5319 /* No need for FIONREAD or fcntl; just say don't wait. */
5320 nread
= (*read_socket_hook
) (input_fd
, buf
, KBD_BUFFER_SIZE
, expected
);
5323 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
5324 the kbd_buffer can really hold. That may prevent loss
5325 of characters on some systems when input is stuffed at us. */
5326 unsigned char cbuf
[KBD_BUFFER_SIZE
- 1];
5329 /* Determine how many characters we should *try* to read. */
5332 #else /* not WINDOWSNT */
5334 n_to_read
= dos_keysns ();
5337 #else /* not MSDOS */
5339 /* Find out how much input is available. */
5340 if (ioctl (input_fd
, FIONREAD
, &n_to_read
) < 0)
5341 /* Formerly simply reported no input, but that sometimes led to
5342 a failure of Emacs to terminate.
5343 SIGHUP seems appropriate if we can't reach the terminal. */
5344 /* ??? Is it really right to send the signal just to this process
5345 rather than to the whole process group?
5346 Perhaps on systems with FIONREAD Emacs is alone in its group. */
5347 kill (getpid (), SIGHUP
);
5350 if (n_to_read
> sizeof cbuf
)
5351 n_to_read
= sizeof cbuf
;
5352 #else /* no FIONREAD */
5353 #if defined (USG) || defined (DGUX)
5354 /* Read some input if available, but don't wait. */
5355 n_to_read
= sizeof cbuf
;
5356 fcntl (input_fd
, F_SETFL
, O_NDELAY
);
5361 #endif /* not MSDOS */
5362 #endif /* not WINDOWSNT */
5364 /* Now read; for one reason or another, this will not block.
5365 NREAD is set to the number of chars read. */
5369 cbuf
[0] = dos_keyread ();
5372 nread
= read (input_fd
, cbuf
, n_to_read
);
5374 /* POSIX infers that processes which are not in the session leader's
5375 process group won't get SIGHUP's at logout time. BSDI adheres to
5376 this part standard and returns -1 from read (0) with errno==EIO
5377 when the control tty is taken away.
5378 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
5379 if (nread
== -1 && errno
== EIO
)
5381 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
5382 /* The kernel sometimes fails to deliver SIGHUP for ptys.
5383 This looks incorrect, but it isn't, because _BSD causes
5384 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
5385 and that causes a value other than 0 when there is no input. */
5391 /* We used to retry the read if it was interrupted.
5392 But this does the wrong thing when O_NDELAY causes
5393 an EAGAIN error. Does anybody know of a situation
5394 where a retry is actually needed? */
5396 nread
< 0 && (errno
== EAGAIN
5410 #if defined (USG) || defined (DGUX)
5411 fcntl (input_fd
, F_SETFL
, 0);
5412 #endif /* USG or DGUX */
5413 #endif /* no FIONREAD */
5414 for (i
= 0; i
< nread
; i
++)
5416 buf
[i
].kind
= ascii_keystroke
;
5417 buf
[i
].modifiers
= 0;
5418 if (meta_key
== 1 && (cbuf
[i
] & 0x80))
5419 buf
[i
].modifiers
= meta_modifier
;
5423 buf
[i
].code
= cbuf
[i
];
5424 XSETFRAME (buf
[i
].frame_or_window
, selected_frame
);
5428 /* Scan the chars for C-g and store them in kbd_buffer. */
5429 for (i
= 0; i
< nread
; i
++)
5431 kbd_buffer_store_event (&buf
[i
]);
5432 /* Don't look at input that follows a C-g too closely.
5433 This reduces lossage due to autorepeat on C-g. */
5434 if (buf
[i
].kind
== ascii_keystroke
5435 && buf
[i
].code
== quit_char
)
5441 #endif /* not VMS */
5443 #ifdef SIGIO /* for entire page */
5444 /* Note SIGIO has been undef'd if FIONREAD is missing. */
5447 input_available_signal (signo
)
5450 /* Must preserve main program's value of errno. */
5451 int old_errno
= errno
;
5453 extern int select_alarmed
;
5456 #if defined (USG) && !defined (POSIX_SIGNALS)
5457 /* USG systems forget handlers when they are used;
5458 must reestablish each time */
5459 signal (signo
, input_available_signal
);
5466 if (input_available_clear_time
)
5467 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
5472 nread
= read_avail_input (1);
5473 /* -1 means it's not ok to read the input now.
5474 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
5475 0 means there was no keyboard input available. */
5480 select_alarmed
= 1; /* Force the select emulator back to life */
5491 /* Send ourselves a SIGIO.
5493 This function exists so that the UNBLOCK_INPUT macro in
5494 blockinput.h can have some way to take care of input we put off
5495 dealing with, without assuming that every file which uses
5496 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
5498 reinvoke_input_signal ()
5501 kill (getpid (), SIGIO
);
5507 /* Return the prompt-string of a sparse keymap.
5508 This is the first element which is a string.
5509 Return nil if there is none. */
5517 register Lisp_Object tem
;
5526 static void menu_bar_item ();
5527 static void menu_bar_one_keymap ();
5529 /* These variables hold the vector under construction within
5530 menu_bar_items and its subroutines, and the current index
5531 for storing into that vector. */
5532 static Lisp_Object menu_bar_items_vector
;
5533 static int menu_bar_items_index
;
5535 /* Return a vector of menu items for a menu bar, appropriate
5536 to the current buffer. Each item has three elements in the vector:
5539 OLD is an old vector we can optionally reuse, or nil. */
5542 menu_bar_items (old
)
5545 /* The number of keymaps we're scanning right now, and the number of
5546 keymaps we have allocated space for. */
5549 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
5550 in the current keymaps, or nil where it is not a prefix. */
5553 Lisp_Object def
, tem
, tail
;
5562 struct gcpro gcpro1
;
5564 /* In order to build the menus, we need to call the keymap
5565 accessors. They all call QUIT. But this function is called
5566 during redisplay, during which a quit is fatal. So inhibit
5567 quitting while building the menus.
5568 We do this instead of specbind because (1) errors will clear it anyway
5569 and (2) this avoids risk of specpdl overflow. */
5570 oquit
= Vinhibit_quit
;
5574 menu_bar_items_vector
= old
;
5576 menu_bar_items_vector
= Fmake_vector (make_number (24), Qnil
);
5577 menu_bar_items_index
= 0;
5579 GCPRO1 (menu_bar_items_vector
);
5581 /* Build our list of keymaps.
5582 If we recognize a function key and replace its escape sequence in
5583 keybuf with its symbol, or if the sequence starts with a mouse
5584 click and we need to switch buffers, we jump back here to rebuild
5585 the initial keymaps from the current buffer. */
5589 /* Should overriding-terminal-local-map and overriding-local-map apply? */
5590 if (!NILP (Voverriding_local_map_menu_flag
))
5592 /* Yes, use them (if non-nil) as well as the global map. */
5593 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
5595 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
5596 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
5597 if (!NILP (Voverriding_local_map
))
5598 maps
[nmaps
++] = Voverriding_local_map
;
5602 /* No, so use major and minor mode keymaps. */
5603 nmaps
= current_minor_maps (NULL
, &tmaps
);
5604 maps
= (Lisp_Object
*) alloca ((nmaps
+ 2) * sizeof (maps
[0]));
5605 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
5606 #ifdef USE_TEXT_PROPERTIES
5607 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
5609 maps
[nmaps
++] = current_buffer
->keymap
;
5612 maps
[nmaps
++] = current_global_map
;
5615 /* Look up in each map the dummy prefix key `menu-bar'. */
5619 for (mapno
= nmaps
- 1; mapno
>= 0; mapno
--)
5621 if (! NILP (maps
[mapno
]))
5622 def
= get_keyelt (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0), 0);
5626 tem
= Fkeymapp (def
);
5628 menu_bar_one_keymap (def
);
5631 /* Move to the end those items that should be at the end. */
5633 for (tail
= Vmenu_bar_final_items
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5636 int end
= menu_bar_items_index
;
5638 for (i
= 0; i
< end
; i
+= 4)
5639 if (EQ (XCONS (tail
)->car
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
5641 Lisp_Object tem0
, tem1
, tem2
, tem3
;
5642 /* Move the item at index I to the end,
5643 shifting all the others forward. */
5644 tem0
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 0];
5645 tem1
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 1];
5646 tem2
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
5647 tem3
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3];
5649 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
5650 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
5651 (end
- i
- 4) * sizeof (Lisp_Object
));
5652 XVECTOR (menu_bar_items_vector
)->contents
[end
- 4] = tem0
;
5653 XVECTOR (menu_bar_items_vector
)->contents
[end
- 3] = tem1
;
5654 XVECTOR (menu_bar_items_vector
)->contents
[end
- 2] = tem2
;
5655 XVECTOR (menu_bar_items_vector
)->contents
[end
- 1] = tem3
;
5660 /* Add nil, nil, nil, nil at the end. */
5661 i
= menu_bar_items_index
;
5662 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
5665 int newsize
= 2 * i
;
5666 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
5667 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
5668 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
5669 menu_bar_items_vector
= tem
;
5671 /* Add this item. */
5672 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5673 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5674 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5675 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5676 menu_bar_items_index
= i
;
5678 Vinhibit_quit
= oquit
;
5680 return menu_bar_items_vector
;
5683 /* Scan one map KEYMAP, accumulating any menu items it defines
5684 in menu_bar_items_vector. */
5687 menu_bar_one_keymap (keymap
)
5690 Lisp_Object tail
, item
, table
;
5692 /* Loop over all keymap entries that have menu strings. */
5693 for (tail
= keymap
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5695 item
= XCONS (tail
)->car
;
5697 menu_bar_item (XCONS (item
)->car
, XCONS (item
)->cdr
);
5698 else if (VECTORP (item
))
5700 /* Loop over the char values represented in the vector. */
5701 int len
= XVECTOR (item
)->size
;
5703 for (c
= 0; c
< len
; c
++)
5705 Lisp_Object character
;
5706 XSETFASTINT (character
, c
);
5707 menu_bar_item (character
, XVECTOR (item
)->contents
[c
]);
5713 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
5714 If there's already an item for KEY, add this DEF to it. */
5716 Lisp_Object item_properties
;
5719 menu_bar_item (key
, item
)
5720 Lisp_Object key
, item
;
5722 struct gcpro gcpro1
;
5725 if (EQ (item
, Qundefined
))
5727 /* If a map has an explicit `undefined' as definition,
5728 discard any previously made menu bar item. */
5730 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
5731 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
5733 if (menu_bar_items_index
> i
+ 4)
5734 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
5735 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
5736 (menu_bar_items_index
- i
- 4) * sizeof (Lisp_Object
));
5737 menu_bar_items_index
-= 4;
5741 /* If there's no definition for this key yet,
5742 just ignore `undefined'. */
5746 GCPRO1 (key
); /* Is this necessary? */
5747 i
= parse_menu_item (item
, 0, 1);
5752 item
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
5754 /* Find any existing item for this KEY. */
5755 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
5756 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
5759 /* If we did not find this KEY, add it at the end. */
5760 if (i
== menu_bar_items_index
)
5762 /* If vector is too small, get a bigger one. */
5763 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
5766 int newsize
= 2 * i
;
5767 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
5768 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
5769 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
5770 menu_bar_items_vector
= tem
;
5773 /* Add this item. */
5774 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = key
;
5775 XVECTOR (menu_bar_items_vector
)->contents
[i
++]
5776 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
5777 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Fcons (item
, Qnil
);
5778 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = make_number (0);
5779 menu_bar_items_index
= i
;
5781 /* We did find an item for this KEY. Add ITEM to its list of maps. */
5785 old
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
5786 XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2] = Fcons (item
, old
);
5790 /* This is used as the handler when calling menu_item_eval_property. */
5792 menu_item_eval_property_1 (arg
)
5795 /* If we got a quit from within the menu computation,
5796 quit all the way out of it. This takes care of C-] in the debugger. */
5797 if (CONSP (arg
) && EQ (XCONS (arg
)->car
, Qquit
))
5798 Fsignal (Qquit
, Qnil
);
5803 /* Evaluate an expression and return the result (or nil if something
5804 went wrong). Used to evaluate dynamic parts of menu items. */
5806 menu_item_eval_property (sexpr
)
5809 int count
= specpdl_ptr
- specpdl
;
5811 specbind (Qinhibit_redisplay
, Qt
);
5812 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
,
5813 menu_item_eval_property_1
);
5814 return unbind_to (count
, val
);
5817 /* This function parses a menu item and leaves the result in the
5818 vector item_properties.
5819 ITEM is a key binding, a possible menu item.
5820 If NOTREAL is nonzero, only check for equivalent key bindings, don't
5821 evaluate dynamic expressions in the menu item.
5822 INMENUBAR is > 0 when this is considered for an entry in a menu bar
5824 INMENUBAR is < 0 when this is considered for an entry in a keyboard menu.
5825 parse_menu_item returns true if the item is a menu item and false
5829 parse_menu_item (item
, notreal
, inmenubar
)
5831 int notreal
, inmenubar
;
5833 Lisp_Object def
, tem
, item_string
, start
;
5834 Lisp_Object cachelist
= Qnil
;
5835 Lisp_Object filter
= Qnil
;
5836 Lisp_Object keyhint
= Qnil
;
5843 /* Create item_properties vector if necessary. */
5844 if (NILP (item_properties
))
5846 = Fmake_vector (make_number (ITEM_PROPERTY_ENABLE
+ 1), Qnil
);
5848 /* Initialize optional entries. */
5849 for (i
= ITEM_PROPERTY_DEF
; i
< ITEM_PROPERTY_ENABLE
; i
++)
5850 XVECTOR (item_properties
)->contents
[i
] = Qnil
;
5851 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
] = Qt
;
5853 /* Save the item here to protect it from GC. */
5854 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ITEM
] = item
;
5856 item_string
= XCONS (item
)->car
;
5859 item
= XCONS (item
)->cdr
;
5860 if (STRINGP (item_string
))
5862 /* Old format menu item. */
5863 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
] = item_string
;
5865 /* Maybe help string. */
5866 if (CONSP (item
) && STRINGP (XCONS (item
)->car
))
5868 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_HELP
]
5869 = XCONS (item
)->car
;
5871 item
= XCONS (item
)->cdr
;
5874 /* Maybee key binding cache. */
5875 if (CONSP (item
) && CONSP (XCONS (item
)->car
)
5876 && (NILP (XCONS (XCONS (item
)->car
)->car
)
5877 || VECTORP (XCONS (XCONS (item
)->car
)->car
)))
5879 cachelist
= XCONS (item
)->car
;
5880 item
= XCONS (item
)->cdr
;
5883 /* This is the real definition--the function to run. */
5884 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
] = item
;
5886 /* Get enable property, if any. */
5889 tem
= Fget (item
, Qmenu_enable
);
5891 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
] = tem
;
5894 else if (EQ (item_string
, Qmenu_item
) && CONSP (item
))
5896 /* New format menu item. */
5897 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
]
5898 = XCONS (item
)->car
;
5899 start
= XCONS (item
)->cdr
;
5902 /* We have a real binding. */
5903 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
]
5904 = XCONS (start
)->car
;
5906 item
= XCONS (start
)->cdr
;
5907 /* Is there a cache list with key equivalences. */
5908 if (CONSP (item
) && CONSP (XCONS (item
)->car
))
5910 cachelist
= XCONS (item
)->car
;
5911 item
= XCONS (item
)->cdr
;
5914 /* Parse properties. */
5915 while (CONSP (item
) && CONSP (XCONS (item
)->cdr
))
5917 tem
= XCONS (item
)->car
;
5918 item
= XCONS (item
)->cdr
;
5920 if (EQ (tem
, QCenable
))
5921 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
]
5922 = XCONS (item
)->car
;
5923 else if (EQ (tem
, QCvisible
) && !notreal
)
5925 /* If got a visible property and that evaluates to nil
5926 then ignore this item. */
5927 tem
= menu_item_eval_property (XCONS (item
)->car
);
5931 else if (EQ (tem
, QChelp
))
5932 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_HELP
]
5933 = XCONS (item
)->car
;
5934 else if (EQ (tem
, QCfilter
))
5936 else if (EQ (tem
, QCkey_sequence
))
5938 tem
= XCONS (item
)->car
;
5939 if (NILP (cachelist
)
5940 && (SYMBOLP (tem
) || STRINGP (tem
) || VECTORP (tem
)))
5941 /* Be GC protected. Set keyhint to item instead of tem. */
5944 else if (EQ (tem
, QCkeys
))
5946 tem
= XCONS (item
)->car
;
5947 if (CONSP (tem
) || STRINGP (tem
) && NILP (cachelist
))
5948 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
]
5951 else if (EQ (tem
, QCbutton
) && CONSP (XCONS (item
)->car
))
5954 tem
= XCONS (item
)->car
;
5955 type
= XCONS (tem
)->car
;
5956 if (EQ (type
, QCtoggle
) || EQ (type
, QCradio
))
5958 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
]
5960 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_TYPE
]
5964 item
= XCONS (item
)->cdr
;
5967 else if (inmenubar
|| !NILP (start
))
5971 return 0; /* not a menu item */
5973 /* If item string is not a string, evaluate it to get string.
5974 If we don't get a string, skip this item. */
5975 item_string
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
5976 if (!(STRINGP (item_string
) || notreal
))
5978 item_string
= menu_item_eval_property (item_string
);
5979 if (!STRINGP (item_string
))
5981 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
] = item_string
;
5984 /* If got a filter apply it on definition. */
5985 def
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
5988 def
= menu_item_eval_property (list2 (XCONS (filter
)->car
,
5989 list2 (Qquote
, def
)));
5991 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
] = def
;
5994 /* If we got no definition, this item is just unselectable text which
5995 is OK in a submenu but not in the menubar. */
5997 return (inmenubar
? 0 : 1);
5999 /* Enable or disable selection of item. */
6000 tem
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
];
6006 tem
= menu_item_eval_property (tem
);
6007 if (inmenubar
&& NILP (tem
))
6008 return 0; /* Ignore disabled items in menu bar. */
6009 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
] = tem
;
6012 /* See if this is a separate pane or a submenu. */
6013 def
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
6014 tem
= get_keymap_1 (def
, 0, 1);
6017 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_MAP
] = tem
;
6018 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
] = tem
;
6021 else if (inmenubar
> 0)
6022 return 0; /* Entries in menu bar must be submenus. */
6024 /* This is a command. See if there is an equivalent key binding. */
6025 if (NILP (cachelist
))
6027 /* We have to create a cachelist. */
6028 CHECK_IMPURE (start
);
6029 XCONS (start
)->cdr
= Fcons (Fcons (Qnil
, Qnil
), XCONS (start
)->cdr
);
6030 cachelist
= XCONS (XCONS (start
)->cdr
)->car
;
6032 tem
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
6033 if (!NILP (keyhint
))
6035 XCONS (cachelist
)->car
= XCONS (keyhint
)->car
;
6038 else if (STRINGP (tem
))
6040 XCONS (cachelist
)->cdr
= Fsubstitute_command_keys (tem
);
6041 XCONS (cachelist
)->car
= Qt
;
6044 tem
= XCONS (cachelist
)->car
;
6051 tem
= Fkey_binding (tem
, Qnil
);
6053 prefix
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
6056 def
= XCONS (prefix
)->car
;
6057 prefix
= XCONS (prefix
)->cdr
;
6060 def
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
6062 if (NILP (XCONS (cachelist
)->car
)) /* Have no saved key. */
6064 if (newcache
/* Always check first time. */
6065 /* Should we check everything when precomputing key
6068 /* If something had no key binding before, don't recheck it
6069 because that is too slow--except if we have a list of
6070 rebound commands in Vdefine_key_rebound_commands, do
6071 recheck any command that appears in that list. */
6072 || (CONSP (Vdefine_key_rebound_commands
)
6073 && !NILP (Fmemq (def
, Vdefine_key_rebound_commands
))))
6076 /* We had a saved key. Is it still bound to the command? */
6079 /* If the command is an alias for another
6080 (such as lmenu.el set it up), check if the
6081 original command matches the cached command. */
6082 && !(SYMBOLP (def
) && EQ (tem
, XSYMBOL (def
)->function
)))
6083 chkcache
= 1; /* Need to recompute key binding. */
6087 /* Recompute equivalent key binding. If the command is an alias
6088 for another (such as lmenu.el set it up), see if the original
6089 command name has equivalent keys. Otherwise look up the
6090 specified command itself. We don't try both, because that
6091 makes lmenu menus slow. */
6092 if (SYMBOLP (def
) && SYMBOLP (XSYMBOL (def
)->function
)
6093 && ! NILP (Fget (def
, Qmenu_alias
)))
6094 def
= XSYMBOL (def
)->function
;
6095 tem
= Fwhere_is_internal (def
, Qnil
, Qt
, Qnil
);
6096 XCONS (cachelist
)->car
= tem
;
6099 XCONS (cachelist
)->cdr
= Qnil
;
6103 else if (!NILP (keyhint
) && !NILP (XCONS (cachelist
)->car
))
6105 tem
= XCONS (cachelist
)->car
;
6109 newcache
= chkcache
;
6112 tem
= Fkey_description (tem
);
6115 if (STRINGP (XCONS (prefix
)->car
))
6116 tem
= concat2 (XCONS (prefix
)->car
, tem
);
6117 if (STRINGP (XCONS (prefix
)->cdr
))
6118 tem
= concat2 (tem
, XCONS (prefix
)->cdr
);
6120 XCONS (cachelist
)->cdr
= tem
;
6124 tem
= XCONS (cachelist
)->cdr
;
6125 if (newcache
&& !NILP (tem
))
6127 tem
= concat3 (build_string (" ("), tem
, build_string (")"));
6128 XCONS (cachelist
)->cdr
= tem
;
6131 /* If we only want to precompute equivalent key bindings, stop here. */
6135 /* If we have an equivalent key binding, use that. */
6136 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
] = tem
;
6138 /* Include this when menu help is implemented.
6139 tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP];
6140 if (!(NILP (tem) || STRINGP (tem)))
6142 tem = menu_item_eval_property (tem);
6145 XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP] = tem;
6149 /* Handle radio buttons or toggle boxes. */
6150 tem
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
];
6152 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
]
6153 = menu_item_eval_property (tem
);
6158 /* Read a character using menus based on maps in the array MAPS.
6159 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
6160 Return t if we displayed a menu but the user rejected it.
6162 PREV_EVENT is the previous input event, or nil if we are reading
6163 the first event of a key sequence.
6165 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
6166 if we used a mouse menu to read the input, or zero otherwise. If
6167 USED_MOUSE_MENU is null, we don't dereference it.
6169 The prompting is done based on the prompt-string of the map
6170 and the strings associated with various map elements.
6172 This can be done with X menus or with menus put in the minibuf.
6173 These are done in different ways, depending on how the input will be read.
6174 Menus using X are done after auto-saving in read-char, getting the input
6175 event from Fx_popup_menu; menus using the minibuf use read_char recursively
6176 and do auto-saving in the inner call of read_char. */
6179 read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
6182 Lisp_Object prev_event
;
6183 int *used_mouse_menu
;
6186 register Lisp_Object name
;
6187 Lisp_Object rest
, vector
;
6189 if (used_mouse_menu
)
6190 *used_mouse_menu
= 0;
6192 /* Use local over global Menu maps */
6194 if (! menu_prompting
)
6197 /* Optionally disregard all but the global map. */
6198 if (inhibit_local_menu_bar_menus
)
6200 maps
+= (nmaps
- 1);
6204 /* Get the menu name from the first map that has one (a prompt string). */
6205 for (mapno
= 0; mapno
< nmaps
; mapno
++)
6207 name
= map_prompt (maps
[mapno
]);
6212 /* If we don't have any menus, just read a character normally. */
6217 /* If we got to this point via a mouse click,
6218 use a real menu for mouse selection. */
6219 if (EVENT_HAS_PARAMETERS (prev_event
)
6220 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
))
6222 /* Display the menu and get the selection. */
6223 Lisp_Object
*realmaps
6224 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
6228 /* Use the maps that are not nil. */
6229 for (mapno
= 0; mapno
< nmaps
; mapno
++)
6230 if (!NILP (maps
[mapno
]))
6231 realmaps
[nmaps1
++] = maps
[mapno
];
6233 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
6238 record_menu_key (XCONS (value
)->car
);
6240 /* If we got multiple events, unread all but
6242 There is no way to prevent those unread events
6243 from showing up later in last_nonmenu_event.
6244 So turn symbol and integer events into lists,
6245 to indicate that they came from a mouse menu,
6246 so that when present in last_nonmenu_event
6247 they won't confuse things. */
6248 for (tem
= XCONS (value
)->cdr
; !NILP (tem
);
6249 tem
= XCONS (tem
)->cdr
)
6251 record_menu_key (XCONS (tem
)->car
);
6252 if (SYMBOLP (XCONS (tem
)->car
)
6253 || INTEGERP (XCONS (tem
)->car
))
6255 = Fcons (XCONS (tem
)->car
, Qnil
);
6258 /* If we got more than one event, put all but the first
6259 onto this list to be read later.
6260 Return just the first event now. */
6261 Vunread_command_events
6262 = nconc2 (XCONS (value
)->cdr
, Vunread_command_events
);
6263 value
= XCONS (value
)->car
;
6265 else if (NILP (value
))
6267 if (used_mouse_menu
)
6268 *used_mouse_menu
= 1;
6271 #endif /* HAVE_MENUS */
6275 /* Buffer in use so far for the minibuf prompts for menu keymaps.
6276 We make this bigger when necessary, and never free it. */
6277 static char *read_char_minibuf_menu_text
;
6278 /* Size of that buffer. */
6279 static int read_char_minibuf_menu_width
;
6282 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
6288 register Lisp_Object name
;
6290 int width
= FRAME_WIDTH (selected_frame
) - 4;
6293 Lisp_Object rest
, vector
;
6296 if (! menu_prompting
)
6299 /* Make sure we have a big enough buffer for the menu text. */
6300 if (read_char_minibuf_menu_text
== 0)
6302 read_char_minibuf_menu_width
= width
+ 4;
6303 read_char_minibuf_menu_text
= (char *) xmalloc (width
+ 4);
6305 else if (width
+ 4 > read_char_minibuf_menu_width
)
6307 read_char_minibuf_menu_width
= width
+ 4;
6308 read_char_minibuf_menu_text
6309 = (char *) xrealloc (read_char_minibuf_menu_text
, width
+ 4);
6311 menu
= read_char_minibuf_menu_text
;
6313 /* Get the menu name from the first map that has one (a prompt string). */
6314 for (mapno
= 0; mapno
< nmaps
; mapno
++)
6316 name
= map_prompt (maps
[mapno
]);
6321 /* If we don't have any menus, just read a character normally. */
6325 /* Prompt string always starts with map's prompt, and a space. */
6326 strcpy (menu
, XSTRING (name
)->data
);
6327 nlength
= STRING_BYTES (XSTRING (name
));
6328 menu
[nlength
++] = ':';
6329 menu
[nlength
++] = ' ';
6332 /* Start prompting at start of first map. */
6336 /* Present the documented bindings, a line at a time. */
6343 Lisp_Object orig_defn_macro
;
6345 /* Loop over elements of map. */
6350 /* If reached end of map, start at beginning of next map. */
6354 /* At end of last map, wrap around to first map if just starting,
6355 or end this line if already have something on it. */
6359 if (notfirst
|| nobindings
) break;
6364 /* Look at the next element of the map. */
6366 elt
= XVECTOR (vector
)->contents
[idx
];
6368 elt
= Fcar_safe (rest
);
6370 if (idx
< 0 && VECTORP (elt
))
6372 /* If we found a dense table in the keymap,
6373 advanced past it, but start scanning its contents. */
6374 rest
= Fcdr_safe (rest
);
6380 /* An ordinary element. */
6381 Lisp_Object event
, tem
;
6385 event
= Fcar_safe (elt
); /* alist */
6386 elt
= Fcdr_safe (elt
);
6390 XSETINT (event
, idx
); /* vector */
6393 /* Ignore the element if it has no prompt string. */
6394 if (INTEGERP (event
) && parse_menu_item (elt
, 0, -1))
6396 /* 1 if the char to type matches the string. */
6398 Lisp_Object upcased_event
, downcased_event
;
6401 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
6403 upcased_event
= Fupcase (event
);
6404 downcased_event
= Fdowncase (event
);
6405 char_matches
= (XINT (upcased_event
) == XSTRING (s
)->data
[0]
6406 || XINT (downcased_event
) == XSTRING (s
)->data
[0]);
6408 desc
= Fsingle_key_description (event
);
6411 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
6413 /* Insert equivalent keybinding. */
6414 s
= concat2 (s
, tem
);
6417 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_TYPE
];
6418 if (EQ (tem
, QCradio
) || EQ (tem
, QCtoggle
))
6420 /* Insert button prefix. */
6421 Lisp_Object selected
6422 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
];
6423 if (EQ (tem
, QCradio
))
6424 tem
= build_string (NILP (selected
) ? "(*) " : "( ) ");
6426 tem
= build_string (NILP (selected
) ? "[X] " : "[ ] ");
6427 s
= concat2 (tem
, s
);
6431 /* If we have room for the prompt string, add it to this line.
6432 If this is the first on the line, always add it. */
6433 if ((XSTRING (s
)->size
+ i
+ 2
6434 + (char_matches
? 0 : XSTRING (desc
)->size
+ 3))
6440 /* Punctuate between strings. */
6443 strcpy (menu
+ i
, ", ");
6449 /* If the char to type doesn't match the string's
6450 first char, explicitly show what char to type. */
6453 /* Add as much of string as fits. */
6454 thiswidth
= XSTRING (desc
)->size
;
6455 if (thiswidth
+ i
> width
)
6456 thiswidth
= width
- i
;
6457 bcopy (XSTRING (desc
)->data
, menu
+ i
, thiswidth
);
6459 strcpy (menu
+ i
, " = ");
6463 /* Add as much of string as fits. */
6464 thiswidth
= XSTRING (s
)->size
;
6465 if (thiswidth
+ i
> width
)
6466 thiswidth
= width
- i
;
6467 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
6473 /* If this element does not fit, end the line now,
6474 and save the element for the next line. */
6475 strcpy (menu
+ i
, "...");
6480 /* Move past this element. */
6481 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
6482 /* Handle reaching end of dense table. */
6487 rest
= Fcdr_safe (rest
);
6491 /* Prompt with that and read response. */
6492 message2_nolog (menu
, strlen (menu
),
6493 ! NILP (current_buffer
->enable_multibyte_characters
));
6495 /* Make believe its not a keyboard macro in case the help char
6496 is pressed. Help characters are not recorded because menu prompting
6497 is not used on replay.
6499 orig_defn_macro
= current_kboard
->defining_kbd_macro
;
6500 current_kboard
->defining_kbd_macro
= Qnil
;
6502 obj
= read_char (commandflag
, 0, 0, Qnil
, 0);
6503 while (BUFFERP (obj
));
6504 current_kboard
->defining_kbd_macro
= orig_defn_macro
;
6506 if (!INTEGERP (obj
))
6511 if (! EQ (obj
, menu_prompt_more_char
)
6512 && (!INTEGERP (menu_prompt_more_char
)
6513 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
6515 if (!NILP (current_kboard
->defining_kbd_macro
))
6516 store_kbd_macro_char (obj
);
6519 /* Help char - go round again */
6523 /* Reading key sequences. */
6525 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
6526 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
6527 keymap, or nil otherwise. Return the index of the first keymap in
6528 which KEY has any binding, or NMAPS if no map has a binding.
6530 If KEY is a meta ASCII character, treat it like meta-prefix-char
6531 followed by the corresponding non-meta character. Keymaps in
6532 CURRENT with non-prefix bindings for meta-prefix-char become nil in
6535 If KEY has no bindings in any of the CURRENT maps, NEXT is left
6538 NEXT may be the same array as CURRENT. */
6541 follow_key (key
, nmaps
, current
, defs
, next
)
6543 Lisp_Object
*current
, *defs
, *next
;
6546 int i
, first_binding
;
6549 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
6550 followed by the corresponding non-meta character.
6551 Put the results into DEFS, since we are going to alter that anyway.
6552 Do not alter CURRENT or NEXT. */
6553 if (INTEGERP (key
) && (XINT (key
) & CHAR_META
))
6555 for (i
= 0; i
< nmaps
; i
++)
6556 if (! NILP (current
[i
]))
6559 def
= get_keyelt (access_keymap (current
[i
],
6560 meta_prefix_char
, 1, 0), 0);
6562 /* Note that since we pass the resulting bindings through
6563 get_keymap_1, non-prefix bindings for meta-prefix-char
6565 defs
[i
] = get_keymap_1 (def
, 0, 1);
6571 XSETINT (key
, XFASTINT (key
) & ~CHAR_META
);
6574 first_binding
= nmaps
;
6575 for (i
= nmaps
- 1; i
>= 0; i
--)
6577 if (! NILP (current
[i
]))
6585 defs
[i
] = get_keyelt (access_keymap (map
, key
, 1, 0), 0);
6586 if (! NILP (defs
[i
]))
6593 /* Given the set of bindings we've found, produce the next set of maps. */
6594 if (first_binding
< nmaps
)
6595 for (i
= 0; i
< nmaps
; i
++)
6596 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0, 1);
6598 return first_binding
;
6601 /* Read a sequence of keys that ends with a non prefix character,
6602 storing it in KEYBUF, a buffer of size BUFSIZE.
6604 Return the length of the key sequence stored.
6605 Return -1 if the user rejected a command menu.
6607 Echo starting immediately unless `prompt' is 0.
6609 Where a key sequence ends depends on the currently active keymaps.
6610 These include any minor mode keymaps active in the current buffer,
6611 the current buffer's local map, and the global map.
6613 If a key sequence has no other bindings, we check Vfunction_key_map
6614 to see if some trailing subsequence might be the beginning of a
6615 function key's sequence. If so, we try to read the whole function
6616 key, and substitute its symbolic name into the key sequence.
6618 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
6619 `double-' events into similar click events, if that would make them
6620 bound. We try to turn `triple-' events first into `double-' events,
6623 If we get a mouse click in a mode line, vertical divider, or other
6624 non-text area, we treat the click as if it were prefixed by the
6625 symbol denoting that area - `mode-line', `vertical-line', or
6628 If the sequence starts with a mouse click, we read the key sequence
6629 with respect to the buffer clicked on, not the current buffer.
6631 If the user switches frames in the midst of a key sequence, we put
6632 off the switch-frame event until later; the next call to
6633 read_char will return it.
6635 If FIX_CURRENT_BUFFER is nonzero, we restore current_buffer
6636 from the selected window's buffer. */
6639 read_key_sequence (keybuf
, bufsize
, prompt
, dont_downcase_last
,
6640 can_return_switch_frame
, fix_current_buffer
)
6641 Lisp_Object
*keybuf
;
6644 int dont_downcase_last
;
6645 int can_return_switch_frame
;
6646 int fix_current_buffer
;
6648 int count
= specpdl_ptr
- specpdl
;
6650 /* How many keys there are in the current key sequence. */
6653 /* The length of the echo buffer when we started reading, and
6654 the length of this_command_keys when we started reading. */
6658 /* The number of keymaps we're scanning right now, and the number of
6659 keymaps we have allocated space for. */
6661 int nmaps_allocated
= 0;
6663 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
6664 the current keymaps. */
6667 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
6668 in the current keymaps, or nil where it is not a prefix. */
6669 Lisp_Object
*submaps
;
6671 /* The local map to start out with at start of key sequence. */
6672 Lisp_Object orig_local_map
;
6674 /* 1 if we have already considered switching to the local-map property
6675 of the place where a mouse click occurred. */
6676 int localized_local_map
= 0;
6678 /* The index in defs[] of the first keymap that has a binding for
6679 this key sequence. In other words, the lowest i such that
6680 defs[i] is non-nil. */
6683 /* If t < mock_input, then KEYBUF[t] should be read as the next
6686 We use this to recover after recognizing a function key. Once we
6687 realize that a suffix of the current key sequence is actually a
6688 function key's escape sequence, we replace the suffix with the
6689 function key's binding from Vfunction_key_map. Now keybuf
6690 contains a new and different key sequence, so the echo area,
6691 this_command_keys, and the submaps and defs arrays are wrong. In
6692 this situation, we set mock_input to t, set t to 0, and jump to
6693 restart_sequence; the loop will read keys from keybuf up until
6694 mock_input, thus rebuilding the state; and then it will resume
6695 reading characters from the keyboard. */
6698 /* If the sequence is unbound in submaps[], then
6699 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
6700 and fkey_map is its binding.
6702 These might be > t, indicating that all function key scanning
6703 should hold off until t reaches them. We do this when we've just
6704 recognized a function key, to avoid searching for the function
6705 key's again in Vfunction_key_map. */
6706 int fkey_start
= 0, fkey_end
= 0;
6707 Lisp_Object fkey_map
;
6709 /* Likewise, for key_translation_map. */
6710 int keytran_start
= 0, keytran_end
= 0;
6711 Lisp_Object keytran_map
;
6713 /* If we receive a ``switch-frame'' event in the middle of a key sequence,
6714 we put it off for later. While we're reading, we keep the event here. */
6715 Lisp_Object delayed_switch_frame
;
6717 /* See the comment below... */
6718 #if defined (GOBBLE_FIRST_EVENT)
6719 Lisp_Object first_event
;
6722 Lisp_Object original_uppercase
;
6723 int original_uppercase_position
= -1;
6725 /* Gets around Microsoft compiler limitations. */
6728 struct buffer
*starting_buffer
;
6730 /* Nonzero if we seem to have got the beginning of a binding
6731 in function_key_map. */
6732 int function_key_possible
= 0;
6733 int key_translation_possible
= 0;
6735 /* Save the status of key translation before each step,
6736 so that we can restore this after downcasing. */
6737 Lisp_Object prev_fkey_map
;
6738 int prev_fkey_start
;
6741 Lisp_Object prev_keytran_map
;
6742 int prev_keytran_start
;
6743 int prev_keytran_end
;
6747 raw_keybuf_count
= 0;
6749 last_nonmenu_event
= Qnil
;
6751 delayed_switch_frame
= Qnil
;
6752 fkey_map
= Vfunction_key_map
;
6753 keytran_map
= Vkey_translation_map
;
6755 /* If there is no function-key-map, turn off function key scanning. */
6756 if (NILP (Fkeymapp (Vfunction_key_map
)))
6757 fkey_start
= fkey_end
= bufsize
+ 1;
6759 /* If there is no key-translation-map, turn off scanning. */
6760 if (NILP (Fkeymapp (Vkey_translation_map
)))
6761 keytran_start
= keytran_end
= bufsize
+ 1;
6766 echo_prompt (XSTRING (prompt
)->data
);
6767 else if (cursor_in_echo_area
&& echo_keystrokes
)
6768 /* This doesn't put in a dash if the echo buffer is empty, so
6769 you don't always see a dash hanging out in the minibuffer. */
6773 /* Record the initial state of the echo area and this_command_keys;
6774 we will need to restore them if we replay a key sequence. */
6776 echo_start
= echo_length ();
6777 keys_start
= this_command_key_count
;
6778 this_single_command_key_start
= keys_start
;
6780 #if defined (GOBBLE_FIRST_EVENT)
6781 /* This doesn't quite work, because some of the things that read_char
6782 does cannot safely be bypassed. It seems too risky to try to make
6785 /* Read the first char of the sequence specially, before setting
6786 up any keymaps, in case a filter runs and switches buffers on us. */
6787 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
6789 #endif /* GOBBLE_FIRST_EVENT */
6791 orig_local_map
= get_local_map (PT
, current_buffer
);
6793 /* We jump here when the key sequence has been thoroughly changed, and
6794 we need to rescan it starting from the beginning. When we jump here,
6795 keybuf[0..mock_input] holds the sequence we should reread. */
6798 starting_buffer
= current_buffer
;
6799 function_key_possible
= 0;
6800 key_translation_possible
= 0;
6802 /* Build our list of keymaps.
6803 If we recognize a function key and replace its escape sequence in
6804 keybuf with its symbol, or if the sequence starts with a mouse
6805 click and we need to switch buffers, we jump back here to rebuild
6806 the initial keymaps from the current buffer. */
6810 if (!NILP (current_kboard
->Voverriding_terminal_local_map
)
6811 || !NILP (Voverriding_local_map
))
6813 if (3 > nmaps_allocated
)
6815 submaps
= (Lisp_Object
*) alloca (3 * sizeof (submaps
[0]));
6816 defs
= (Lisp_Object
*) alloca (3 * sizeof (defs
[0]));
6817 nmaps_allocated
= 3;
6820 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
6821 submaps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
6822 if (!NILP (Voverriding_local_map
))
6823 submaps
[nmaps
++] = Voverriding_local_map
;
6827 nmaps
= current_minor_maps (0, &maps
);
6828 if (nmaps
+ 2 > nmaps_allocated
)
6830 submaps
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (submaps
[0]));
6831 defs
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (defs
[0]));
6832 nmaps_allocated
= nmaps
+ 2;
6834 bcopy (maps
, submaps
, nmaps
* sizeof (submaps
[0]));
6835 #ifdef USE_TEXT_PROPERTIES
6836 submaps
[nmaps
++] = orig_local_map
;
6838 submaps
[nmaps
++] = current_buffer
->keymap
;
6841 submaps
[nmaps
++] = current_global_map
;
6844 /* Find an accurate initial value for first_binding. */
6845 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
6846 if (! NILP (submaps
[first_binding
]))
6849 /* Start from the beginning in keybuf. */
6852 /* These are no-ops the first time through, but if we restart, they
6853 revert the echo area and this_command_keys to their original state. */
6854 this_command_key_count
= keys_start
;
6855 if (INTERACTIVE
&& t
< mock_input
)
6856 echo_truncate (echo_start
);
6858 /* If the best binding for the current key sequence is a keymap, or
6859 we may be looking at a function key's escape sequence, keep on
6861 while ((first_binding
< nmaps
&& ! NILP (submaps
[first_binding
]))
6862 || (first_binding
>= nmaps
6864 /* mock input is never part of a function key's sequence. */
6865 && mock_input
<= fkey_start
)
6866 || (first_binding
>= nmaps
6867 && keytran_start
< t
&& key_translation_possible
)
6868 /* Don't return in the middle of a possible function key sequence,
6869 if the only bindings we found were via case conversion.
6870 Thus, if ESC O a has a function-key-map translation
6871 and ESC o has a binding, don't return after ESC O,
6872 so that we can translate ESC O plus the next character. */
6876 int used_mouse_menu
= 0;
6878 /* Where the last real key started. If we need to throw away a
6879 key that has expanded into more than one element of keybuf
6880 (say, a mouse click on the mode line which is being treated
6881 as [mode-line (mouse-...)], then we backtrack to this point
6883 int last_real_key_start
;
6885 /* These variables are analogous to echo_start and keys_start;
6886 while those allow us to restart the entire key sequence,
6887 echo_local_start and keys_local_start allow us to throw away
6889 int echo_local_start
, keys_local_start
, local_first_binding
;
6892 error ("Key sequence too long");
6895 echo_local_start
= echo_length ();
6896 keys_local_start
= this_command_key_count
;
6897 local_first_binding
= first_binding
;
6900 /* These are no-ops, unless we throw away a keystroke below and
6901 jumped back up to replay_key; in that case, these restore the
6902 variables to their original state, allowing us to replay the
6904 if (INTERACTIVE
&& t
< mock_input
)
6905 echo_truncate (echo_local_start
);
6906 this_command_key_count
= keys_local_start
;
6907 first_binding
= local_first_binding
;
6909 /* By default, assume each event is "real". */
6910 last_real_key_start
= t
;
6912 /* Does mock_input indicate that we are re-reading a key sequence? */
6916 add_command_key (key
);
6917 if (echo_keystrokes
)
6921 /* If not, we should actually read a character. */
6924 struct buffer
*buf
= current_buffer
;
6928 KBOARD
*interrupted_kboard
= current_kboard
;
6929 struct frame
*interrupted_frame
= selected_frame
;
6930 if (setjmp (wrong_kboard_jmpbuf
))
6932 if (!NILP (delayed_switch_frame
))
6934 interrupted_kboard
->kbd_queue
6935 = Fcons (delayed_switch_frame
,
6936 interrupted_kboard
->kbd_queue
);
6937 delayed_switch_frame
= Qnil
;
6940 interrupted_kboard
->kbd_queue
6941 = Fcons (keybuf
[--t
], interrupted_kboard
->kbd_queue
);
6943 /* If the side queue is non-empty, ensure it begins with a
6944 switch-frame, so we'll replay it in the right context. */
6945 if (CONSP (interrupted_kboard
->kbd_queue
)
6946 && (key
= XCONS (interrupted_kboard
->kbd_queue
)->car
,
6947 !(EVENT_HAS_PARAMETERS (key
)
6948 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)),
6952 XSETFRAME (frame
, interrupted_frame
);
6953 interrupted_kboard
->kbd_queue
6954 = Fcons (make_lispy_switch_frame (frame
),
6955 interrupted_kboard
->kbd_queue
);
6958 orig_local_map
= get_local_map (PT
, current_buffer
);
6959 goto replay_sequence
;
6962 key
= read_char (NILP (prompt
), nmaps
, submaps
, last_nonmenu_event
,
6966 /* read_char returns t when it shows a menu and the user rejects it.
6970 unbind_to (count
, Qnil
);
6974 /* read_char returns -1 at the end of a macro.
6975 Emacs 18 handles this by returning immediately with a
6976 zero, so that's what we'll do. */
6977 if (INTEGERP (key
) && XINT (key
) == -1)
6980 /* The Microsoft C compiler can't handle the goto that
6986 /* If the current buffer has been changed from under us, the
6987 keymap may have changed, so replay the sequence. */
6991 /* Reset the current buffer from the selected window
6992 in case something changed the former and not the latter.
6993 This is to be more consistent with the behavior
6994 of the command_loop_1. */
6995 if (fix_current_buffer
)
6996 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
6997 Fset_buffer (XWINDOW (selected_window
)->buffer
);
6999 orig_local_map
= get_local_map (PT
, current_buffer
);
7000 goto replay_sequence
;
7003 /* If we have a quit that was typed in another frame, and
7004 quit_throw_to_read_char switched buffers,
7005 replay to get the right keymap. */
7006 if (XINT (key
) == quit_char
&& current_buffer
!= starting_buffer
)
7009 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
7013 orig_local_map
= get_local_map (PT
, current_buffer
);
7014 goto replay_sequence
;
7019 if (EVENT_HAS_PARAMETERS (key
)
7020 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)), Qswitch_frame
))
7022 /* If we're at the beginning of a key sequence, and the caller
7023 says it's okay, go ahead and return this event. If we're
7024 in the midst of a key sequence, delay it until the end. */
7025 if (t
> 0 || !can_return_switch_frame
)
7027 delayed_switch_frame
= key
;
7033 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
7036 /* Clicks in non-text areas get prefixed by the symbol
7037 in their CHAR-ADDRESS field. For example, a click on
7038 the mode line is prefixed by the symbol `mode-line'.
7040 Furthermore, key sequences beginning with mouse clicks
7041 are read using the keymaps of the buffer clicked on, not
7042 the current buffer. So we may have to switch the buffer
7045 When we turn one event into two events, we must make sure
7046 that neither of the two looks like the original--so that,
7047 if we replay the events, they won't be expanded again.
7048 If not for this, such reexpansion could happen either here
7049 or when user programs play with this-command-keys. */
7050 if (EVENT_HAS_PARAMETERS (key
))
7054 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
7055 if (EQ (kind
, Qmouse_click
))
7057 Lisp_Object window
, posn
;
7059 window
= POSN_WINDOW (EVENT_START (key
));
7060 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
7063 /* We're looking at the second event of a
7064 sequence which we expanded before. Set
7065 last_real_key_start appropriately. */
7067 last_real_key_start
= t
- 1;
7070 /* Key sequences beginning with mouse clicks are
7071 read using the keymaps in the buffer clicked on,
7072 not the current buffer. If we're at the
7073 beginning of a key sequence, switch buffers. */
7074 if (last_real_key_start
== 0
7076 && BUFFERP (XWINDOW (window
)->buffer
)
7077 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
7079 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
7083 /* Arrange to go back to the original buffer once we're
7084 done reading the key sequence. Note that we can't
7085 use save_excursion_{save,restore} here, because they
7086 save point as well as the current buffer; we don't
7087 want to save point, because redisplay may change it,
7088 to accommodate a Fset_window_start or something. We
7089 don't want to do this at the top of the function,
7090 because we may get input from a subprocess which
7091 wants to change the selected window and stuff (say,
7093 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
7095 set_buffer_internal (XBUFFER (XWINDOW (window
)->buffer
));
7096 orig_local_map
= get_local_map (PT
, current_buffer
);
7097 goto replay_sequence
;
7099 /* For a mouse click, get the local text-property keymap
7100 of the place clicked on, rather than point. */
7101 if (last_real_key_start
== 0 && CONSP (XCONS (key
)->cdr
)
7102 && ! localized_local_map
)
7104 Lisp_Object map_here
, start
, pos
;
7106 localized_local_map
= 1;
7107 start
= EVENT_START (key
);
7108 if (CONSP (start
) && CONSP (XCONS (start
)->cdr
))
7110 pos
= POSN_BUFFER_POSN (start
);
7112 && XINT (pos
) >= BEG
&& XINT (pos
) <= Z
)
7114 map_here
= get_local_map (XINT (pos
), current_buffer
);
7115 if (!EQ (map_here
, orig_local_map
))
7117 orig_local_map
= map_here
;
7121 goto replay_sequence
;
7127 /* Expand mode-line and scroll-bar events into two events:
7128 use posn as a fake prefix key. */
7131 if (t
+ 1 >= bufsize
)
7132 error ("Key sequence too long");
7137 /* Zap the position in key, so we know that we've
7138 expanded it, and don't try to do so again. */
7139 POSN_BUFFER_POSN (EVENT_START (key
))
7140 = Fcons (posn
, Qnil
);
7144 else if (CONSP (XCONS (key
)->cdr
)
7145 && CONSP (EVENT_START (key
))
7146 && CONSP (XCONS (EVENT_START (key
))->cdr
))
7150 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
7151 /* Handle menu-bar events:
7152 insert the dummy prefix event `menu-bar'. */
7153 if (EQ (posn
, Qmenu_bar
))
7155 if (t
+ 1 >= bufsize
)
7156 error ("Key sequence too long");
7160 /* Zap the position in key, so we know that we've
7161 expanded it, and don't try to do so again. */
7162 POSN_BUFFER_POSN (EVENT_START (key
))
7163 = Fcons (posn
, Qnil
);
7166 goto replay_sequence
;
7168 else if (CONSP (posn
))
7170 /* We're looking at the second event of a
7171 sequence which we expanded before. Set
7172 last_real_key_start appropriately. */
7173 if (last_real_key_start
== t
&& t
> 0)
7174 last_real_key_start
= t
- 1;
7179 /* We have finally decided that KEY is something we might want
7181 first_binding
= (follow_key (key
,
7182 nmaps
- first_binding
,
7183 submaps
+ first_binding
,
7184 defs
+ first_binding
,
7185 submaps
+ first_binding
)
7188 /* If KEY wasn't bound, we'll try some fallbacks. */
7189 if (first_binding
>= nmaps
)
7193 head
= EVENT_HEAD (key
);
7194 if (help_char_p (head
) && t
> 0)
7196 read_key_sequence_cmd
= Vprefix_help_command
;
7198 last_nonmenu_event
= key
;
7199 /* The Microsoft C compiler can't handle the goto that
7207 Lisp_Object breakdown
;
7210 breakdown
= parse_modifiers (head
);
7211 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
7212 /* Attempt to reduce an unbound mouse event to a simpler
7213 event that is bound:
7214 Drags reduce to clicks.
7215 Double-clicks reduce to clicks.
7216 Triple-clicks reduce to double-clicks, then to clicks.
7217 Down-clicks are eliminated.
7218 Double-downs reduce to downs, then are eliminated.
7219 Triple-downs reduce to double-downs, then to downs,
7220 then are eliminated. */
7221 if (modifiers
& (down_modifier
| drag_modifier
7222 | double_modifier
| triple_modifier
))
7224 while (modifiers
& (down_modifier
| drag_modifier
7225 | double_modifier
| triple_modifier
))
7227 Lisp_Object new_head
, new_click
;
7228 if (modifiers
& triple_modifier
)
7229 modifiers
^= (double_modifier
| triple_modifier
);
7230 else if (modifiers
& double_modifier
)
7231 modifiers
&= ~double_modifier
;
7232 else if (modifiers
& drag_modifier
)
7233 modifiers
&= ~drag_modifier
;
7236 /* Dispose of this `down' event by simply jumping
7237 back to replay_key, to get another event.
7239 Note that if this event came from mock input,
7240 then just jumping back to replay_key will just
7241 hand it to us again. So we have to wipe out any
7244 We could delete keybuf[t] and shift everything
7245 after that to the left by one spot, but we'd also
7246 have to fix up any variable that points into
7247 keybuf, and shifting isn't really necessary
7250 Adding prefixes for non-textual mouse clicks
7251 creates two characters of mock input, and both
7252 must be thrown away. If we're only looking at
7253 the prefix now, we can just jump back to
7254 replay_key. On the other hand, if we've already
7255 processed the prefix, and now the actual click
7256 itself is giving us trouble, then we've lost the
7257 state of the keymaps we want to backtrack to, and
7258 we need to replay the whole sequence to rebuild
7261 Beyond that, only function key expansion could
7262 create more than two keys, but that should never
7263 generate mouse events, so it's okay to zero
7264 mock_input in that case too.
7266 Isn't this just the most wonderful code ever? */
7267 if (t
== last_real_key_start
)
7274 mock_input
= last_real_key_start
;
7275 goto replay_sequence
;
7280 = apply_modifiers (modifiers
, XCONS (breakdown
)->car
);
7282 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
7284 /* Look for a binding for this new key. follow_key
7285 promises that it didn't munge submaps the
7286 last time we called it, since key was unbound. */
7288 = (follow_key (new_click
,
7289 nmaps
- local_first_binding
,
7290 submaps
+ local_first_binding
,
7291 defs
+ local_first_binding
,
7292 submaps
+ local_first_binding
)
7293 + local_first_binding
);
7295 /* If that click is bound, go for it. */
7296 if (first_binding
< nmaps
)
7301 /* Otherwise, we'll leave key set to the drag event. */
7308 /* Normally, last_nonmenu_event gets the previous key we read.
7309 But when a mouse popup menu is being used,
7310 we don't update last_nonmenu_event; it continues to hold the mouse
7311 event that preceded the first level of menu. */
7312 if (!used_mouse_menu
)
7313 last_nonmenu_event
= key
;
7315 /* Record what part of this_command_keys is the current key sequence. */
7316 this_single_command_key_start
= this_command_key_count
- t
;
7318 prev_fkey_map
= fkey_map
;
7319 prev_fkey_start
= fkey_start
;
7320 prev_fkey_end
= fkey_end
;
7322 prev_keytran_map
= keytran_map
;
7323 prev_keytran_start
= keytran_start
;
7324 prev_keytran_end
= keytran_end
;
7326 /* If the sequence is unbound, see if we can hang a function key
7327 off the end of it. We only want to scan real keyboard input
7328 for function key sequences, so if mock_input says that we're
7329 re-reading old events, don't examine it. */
7330 if (first_binding
>= nmaps
7333 Lisp_Object fkey_next
;
7335 /* Continue scan from fkey_end until we find a bound suffix.
7336 If we fail, increment fkey_start
7337 and start fkey_end from there. */
7338 while (fkey_end
< t
)
7342 key
= keybuf
[fkey_end
++];
7343 /* Look up meta-characters by prefixing them
7344 with meta_prefix_char. I hate this. */
7345 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
7350 (access_keymap (fkey_map
, meta_prefix_char
, 1, 0), 0),
7352 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
7355 fkey_next
= fkey_map
;
7358 = get_keyelt (access_keymap (fkey_next
, key
, 1, 0), 0);
7360 #if 0 /* I didn't turn this on, because it might cause trouble
7361 for the mapping of return into C-m and tab into C-i. */
7362 /* Optionally don't map function keys into other things.
7363 This enables the user to redefine kp- keys easily. */
7364 if (SYMBOLP (key
) && !NILP (Vinhibit_function_key_mapping
))
7368 /* If the function key map gives a function, not an
7369 array, then call the function with no args and use
7370 its value instead. */
7371 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
7374 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7378 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
7379 fkey_next
= call1 (fkey_next
, prompt
);
7381 /* If the function returned something invalid,
7382 barf--don't ignore it.
7383 (To ignore it safely, we would need to gcpro a bunch of
7384 other variables.) */
7385 if (! (VECTORP (fkey_next
) || STRINGP (fkey_next
)))
7386 error ("Function in key-translation-map returns invalid key sequence");
7389 function_key_possible
= ! NILP (fkey_next
);
7391 /* If keybuf[fkey_start..fkey_end] is bound in the
7392 function key map and it's a suffix of the current
7393 sequence (i.e. fkey_end == t), replace it with
7394 the binding and restart with fkey_start at the end. */
7395 if ((VECTORP (fkey_next
) || STRINGP (fkey_next
))
7398 int len
= XFASTINT (Flength (fkey_next
));
7400 t
= fkey_start
+ len
;
7402 error ("Key sequence too long");
7404 if (VECTORP (fkey_next
))
7405 bcopy (XVECTOR (fkey_next
)->contents
,
7406 keybuf
+ fkey_start
,
7407 (t
- fkey_start
) * sizeof (keybuf
[0]));
7408 else if (STRINGP (fkey_next
))
7412 for (i
= 0; i
< len
; i
++)
7413 XSETFASTINT (keybuf
[fkey_start
+ i
],
7414 XSTRING (fkey_next
)->data
[i
]);
7418 fkey_start
= fkey_end
= t
;
7419 fkey_map
= Vfunction_key_map
;
7421 /* Do pass the results through key-translation-map. */
7422 keytran_start
= keytran_end
= 0;
7423 keytran_map
= Vkey_translation_map
;
7425 goto replay_sequence
;
7428 fkey_map
= get_keymap_1 (fkey_next
, 0, 1);
7430 /* If we no longer have a bound suffix, try a new positions for
7432 if (NILP (fkey_map
))
7434 fkey_end
= ++fkey_start
;
7435 fkey_map
= Vfunction_key_map
;
7436 function_key_possible
= 0;
7441 /* Look for this sequence in key-translation-map. */
7443 Lisp_Object keytran_next
;
7445 /* Scan from keytran_end until we find a bound suffix. */
7446 while (keytran_end
< t
)
7450 key
= keybuf
[keytran_end
++];
7451 /* Look up meta-characters by prefixing them
7452 with meta_prefix_char. I hate this. */
7453 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
7458 (access_keymap (keytran_map
, meta_prefix_char
, 1, 0), 0),
7460 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
7463 keytran_next
= keytran_map
;
7466 = get_keyelt (access_keymap (keytran_next
, key
, 1, 0), 0);
7468 /* If the key translation map gives a function, not an
7469 array, then call the function with no args and use
7470 its value instead. */
7471 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
7472 && keytran_end
== t
)
7474 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7478 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
7479 keytran_next
= call1 (keytran_next
, prompt
);
7481 /* If the function returned something invalid,
7482 barf--don't ignore it.
7483 (To ignore it safely, we would need to gcpro a bunch of
7484 other variables.) */
7485 if (! (VECTORP (keytran_next
) || STRINGP (keytran_next
)))
7486 error ("Function in key-translation-map returns invalid key sequence");
7489 key_translation_possible
= ! NILP (keytran_next
);
7491 /* If keybuf[keytran_start..keytran_end] is bound in the
7492 key translation map and it's a suffix of the current
7493 sequence (i.e. keytran_end == t), replace it with
7494 the binding and restart with keytran_start at the end. */
7495 if ((VECTORP (keytran_next
) || STRINGP (keytran_next
))
7496 && keytran_end
== t
)
7498 int len
= XFASTINT (Flength (keytran_next
));
7500 t
= keytran_start
+ len
;
7502 error ("Key sequence too long");
7504 if (VECTORP (keytran_next
))
7505 bcopy (XVECTOR (keytran_next
)->contents
,
7506 keybuf
+ keytran_start
,
7507 (t
- keytran_start
) * sizeof (keybuf
[0]));
7508 else if (STRINGP (keytran_next
))
7512 for (i
= 0; i
< len
; i
++)
7513 XSETFASTINT (keybuf
[keytran_start
+ i
],
7514 XSTRING (keytran_next
)->data
[i
]);
7518 keytran_start
= keytran_end
= t
;
7519 keytran_map
= Vkey_translation_map
;
7521 /* Don't pass the results of key-translation-map
7522 through function-key-map. */
7523 fkey_start
= fkey_end
= t
;
7524 fkey_map
= Vkey_translation_map
;
7526 goto replay_sequence
;
7529 keytran_map
= get_keymap_1 (keytran_next
, 0, 1);
7531 /* If we no longer have a bound suffix, try a new positions for
7533 if (NILP (keytran_map
))
7535 keytran_end
= ++keytran_start
;
7536 keytran_map
= Vkey_translation_map
;
7537 key_translation_possible
= 0;
7542 /* If KEY is not defined in any of the keymaps,
7543 and cannot be part of a function key or translation,
7544 and is an upper case letter
7545 use the corresponding lower-case letter instead. */
7546 if (first_binding
== nmaps
&& ! function_key_possible
7547 && ! key_translation_possible
7549 && ((((XINT (key
) & 0x3ffff)
7550 < XCHAR_TABLE (current_buffer
->downcase_table
)->size
)
7551 && UPPERCASEP (XINT (key
) & 0x3ffff))
7552 || (XINT (key
) & shift_modifier
)))
7554 Lisp_Object new_key
;
7556 original_uppercase
= key
;
7557 original_uppercase_position
= t
- 1;
7559 if (XINT (key
) & shift_modifier
)
7560 XSETINT (new_key
, XINT (key
) & ~shift_modifier
);
7562 XSETINT (new_key
, (DOWNCASE (XINT (key
) & 0x3ffff)
7563 | (XINT (key
) & ~0x3ffff)));
7565 /* We have to do this unconditionally, regardless of whether
7566 the lower-case char is defined in the keymaps, because they
7567 might get translated through function-key-map. */
7568 keybuf
[t
- 1] = new_key
;
7571 fkey_map
= prev_fkey_map
;
7572 fkey_start
= prev_fkey_start
;
7573 fkey_end
= prev_fkey_end
;
7575 keytran_map
= prev_keytran_map
;
7576 keytran_start
= prev_keytran_start
;
7577 keytran_end
= prev_keytran_end
;
7579 goto replay_sequence
;
7581 /* If KEY is not defined in any of the keymaps,
7582 and cannot be part of a function key or translation,
7583 and is a shifted function key,
7584 use the corresponding unshifted function key instead. */
7585 if (first_binding
== nmaps
&& ! function_key_possible
7586 && ! key_translation_possible
7589 Lisp_Object breakdown
;
7592 breakdown
= parse_modifiers (key
);
7593 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
7594 if (modifiers
& shift_modifier
)
7596 Lisp_Object new_key
;
7598 original_uppercase
= key
;
7599 original_uppercase_position
= t
- 1;
7601 modifiers
&= ~shift_modifier
;
7602 new_key
= apply_modifiers (modifiers
,
7603 XCONS (breakdown
)->car
);
7605 keybuf
[t
- 1] = new_key
;
7608 fkey_map
= prev_fkey_map
;
7609 fkey_start
= prev_fkey_start
;
7610 fkey_end
= prev_fkey_end
;
7612 keytran_map
= prev_keytran_map
;
7613 keytran_start
= prev_keytran_start
;
7614 keytran_end
= prev_keytran_end
;
7616 goto replay_sequence
;
7622 read_key_sequence_cmd
= (first_binding
< nmaps
7623 ? defs
[first_binding
]
7626 unread_switch_frame
= delayed_switch_frame
;
7627 unbind_to (count
, Qnil
);
7629 /* Don't downcase the last character if the caller says don't.
7630 Don't downcase it if the result is undefined, either. */
7631 if ((dont_downcase_last
|| first_binding
>= nmaps
)
7632 && t
- 1 == original_uppercase_position
)
7633 keybuf
[t
- 1] = original_uppercase
;
7635 /* Occasionally we fabricate events, perhaps by expanding something
7636 according to function-key-map, or by adding a prefix symbol to a
7637 mouse click in the scroll bar or modeline. In this cases, return
7638 the entire generated key sequence, even if we hit an unbound
7639 prefix or a definition before the end. This means that you will
7640 be able to push back the event properly, and also means that
7641 read-key-sequence will always return a logical unit.
7644 for (; t
< mock_input
; t
++)
7646 if (echo_keystrokes
)
7647 echo_char (keybuf
[t
]);
7648 add_command_key (keybuf
[t
]);
7656 #if 0 /* This doc string is too long for some compilers.
7657 This commented-out definition serves for DOC. */
7658 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
7659 "Read a sequence of keystrokes and return as a string or vector.\n\
7660 The sequence is sufficient to specify a non-prefix command in the\n\
7661 current local and global maps.\n\
7663 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
7664 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
7665 as a continuation of the previous key.\n\
7667 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not\n\
7668 convert the last event to lower case. (Normally any upper case event\n\
7669 is converted to lower case if the original event is undefined and the lower\n\
7670 case equivalent is defined.) A non-nil value is appropriate for reading\n\
7671 a key sequence to be defined.\n\
7673 A C-g typed while in this function is treated like any other character,\n\
7674 and `quit-flag' is not set.\n\
7676 If the key sequence starts with a mouse click, then the sequence is read\n\
7677 using the keymaps of the buffer of the window clicked in, not the buffer\n\
7678 of the selected window as normal.\n\
7680 `read-key-sequence' drops unbound button-down events, since you normally\n\
7681 only care about the click or drag events which follow them. If a drag\n\
7682 or multi-click event is unbound, but the corresponding click event would\n\
7683 be bound, `read-key-sequence' turns the event into a click event at the\n\
7684 drag's starting position. This means that you don't have to distinguish\n\
7685 between click and drag, double, or triple events unless you want to.\n\
7687 `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\
7688 lines separating windows, and scroll bars with imaginary keys\n\
7689 `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\
7691 Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this\n\
7692 function will process a switch-frame event if the user switches frames\n\
7693 before typing anything. If the user switches frames in the middle of a\n\
7694 key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME\n\
7695 is nil, then the event will be put off until after the current key sequence.\n\
7697 `read-key-sequence' checks `function-key-map' for function key\n\
7698 sequences, where they wouldn't conflict with ordinary bindings. See\n\
7699 `function-key-map' for more details.\n\
7701 The optional fifth argument COMMAND-LOOP, if non-nil, means\n\
7702 that this key sequence is being read by something that will\n\
7703 read commands one after another. It should be nil if the caller\n\
7704 will read just one key sequence.")
7705 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
, command
-loop
)
7708 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 5, 0,
7710 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
7712 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
7713 Lisp_Object can_return_switch_frame
, command_loop
;
7715 Lisp_Object keybuf
[30];
7717 struct gcpro gcpro1
, gcpro2
;
7718 int count
= specpdl_ptr
- specpdl
;
7721 CHECK_STRING (prompt
, 0);
7724 specbind (Qinput_method_exit_on_first_char
,
7725 (NILP (command_loop
) ? Qt
: Qnil
));
7726 specbind (Qinput_method_use_echo_area
,
7727 (NILP (command_loop
) ? Qt
: Qnil
));
7729 bzero (keybuf
, sizeof keybuf
);
7731 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
7733 if (NILP (continue_echo
))
7735 this_command_key_count
= 0;
7736 this_single_command_key_start
= 0;
7739 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
7740 prompt
, ! NILP (dont_downcase_last
),
7741 ! NILP (can_return_switch_frame
), 0);
7749 return unbind_to (count
, make_event_array (i
, keybuf
));
7752 DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector
,
7753 Sread_key_sequence_vector
, 1, 5, 0,
7754 "Like `read-key-sequence' but always return a vector.")
7755 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
7757 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
7758 Lisp_Object can_return_switch_frame
, command_loop
;
7760 Lisp_Object keybuf
[30];
7762 struct gcpro gcpro1
, gcpro2
;
7763 int count
= specpdl_ptr
- specpdl
;
7766 CHECK_STRING (prompt
, 0);
7769 specbind (Qinput_method_exit_on_first_char
,
7770 (NILP (command_loop
) ? Qt
: Qnil
));
7771 specbind (Qinput_method_use_echo_area
,
7772 (NILP (command_loop
) ? Qt
: Qnil
));
7774 bzero (keybuf
, sizeof keybuf
);
7776 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
7778 if (NILP (continue_echo
))
7780 this_command_key_count
= 0;
7781 this_single_command_key_start
= 0;
7784 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
7785 prompt
, ! NILP (dont_downcase_last
),
7786 ! NILP (can_return_switch_frame
), 0);
7794 return unbind_to (count
, Fvector (i
, keybuf
));
7797 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 4, 0,
7798 "Execute CMD as an editor command.\n\
7799 CMD must be a symbol that satisfies the `commandp' predicate.\n\
7800 Optional second arg RECORD-FLAG non-nil\n\
7801 means unconditionally put this command in `command-history'.\n\
7802 Otherwise, that is done only if an arg is read using the minibuffer.\n\
7803 The argument KEYS specifies the value to use instead of (this-command-keys)\n\
7804 when reading the arguments; if it is nil, (this-command-keys) is used.\n\
7805 The argument SPECIAL, if non-nil, means that this command is executing\n\
7806 a special event, so ignore the prefix argument and don't clear it.")
7807 (cmd
, record_flag
, keys
, special
)
7808 Lisp_Object cmd
, record_flag
, keys
, special
;
7810 register Lisp_Object final
;
7811 register Lisp_Object tem
;
7812 Lisp_Object prefixarg
;
7813 struct backtrace backtrace
;
7814 extern int debug_on_next_call
;
7816 debug_on_next_call
= 0;
7820 prefixarg
= current_kboard
->Vprefix_arg
;
7821 Vcurrent_prefix_arg
= prefixarg
;
7822 current_kboard
->Vprefix_arg
= Qnil
;
7829 tem
= Fget (cmd
, Qdisabled
);
7830 if (!NILP (tem
) && !NILP (Vrun_hooks
))
7832 tem
= Fsymbol_value (Qdisabled_command_hook
);
7834 return call1 (Vrun_hooks
, Qdisabled_command_hook
);
7840 final
= Findirect_function (cmd
);
7842 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
7844 struct gcpro gcpro1
, gcpro2
;
7846 GCPRO2 (cmd
, prefixarg
);
7847 do_autoload (final
, cmd
);
7854 if (STRINGP (final
) || VECTORP (final
))
7856 /* If requested, place the macro in the command history. For
7857 other sorts of commands, call-interactively takes care of
7859 if (!NILP (record_flag
))
7862 = Fcons (Fcons (Qexecute_kbd_macro
,
7863 Fcons (final
, Fcons (prefixarg
, Qnil
))),
7866 /* Don't keep command history around forever. */
7867 if (NUMBERP (Vhistory_length
) && XINT (Vhistory_length
) > 0)
7869 tem
= Fnthcdr (Vhistory_length
, Vcommand_history
);
7871 XCONS (tem
)->cdr
= Qnil
;
7875 return Fexecute_kbd_macro (final
, prefixarg
);
7878 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
7880 backtrace
.next
= backtrace_list
;
7881 backtrace_list
= &backtrace
;
7882 backtrace
.function
= &Qcall_interactively
;
7883 backtrace
.args
= &cmd
;
7884 backtrace
.nargs
= 1;
7885 backtrace
.evalargs
= 0;
7887 tem
= Fcall_interactively (cmd
, record_flag
, keys
);
7889 backtrace_list
= backtrace
.next
;
7895 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
7897 "Read function name, then read its arguments and call it.")
7899 Lisp_Object prefixarg
;
7901 Lisp_Object function
;
7903 Lisp_Object saved_keys
;
7904 Lisp_Object bindings
, value
;
7905 struct gcpro gcpro1
, gcpro2
;
7907 saved_keys
= Fvector (this_command_key_count
,
7908 XVECTOR (this_command_keys
)->contents
);
7910 GCPRO2 (saved_keys
, prefixarg
);
7912 if (EQ (prefixarg
, Qminus
))
7914 else if (CONSP (prefixarg
) && XINT (XCONS (prefixarg
)->car
) == 4)
7915 strcpy (buf
, "C-u ");
7916 else if (CONSP (prefixarg
) && INTEGERP (XCONS (prefixarg
)->car
))
7918 if (sizeof (int) == sizeof (EMACS_INT
))
7919 sprintf (buf
, "%d ", XINT (XCONS (prefixarg
)->car
));
7920 else if (sizeof (long) == sizeof (EMACS_INT
))
7921 sprintf (buf
, "%ld ", XINT (XCONS (prefixarg
)->car
));
7925 else if (INTEGERP (prefixarg
))
7927 if (sizeof (int) == sizeof (EMACS_INT
))
7928 sprintf (buf
, "%d ", XINT (prefixarg
));
7929 else if (sizeof (long) == sizeof (EMACS_INT
))
7930 sprintf (buf
, "%ld ", XINT (prefixarg
));
7935 /* This isn't strictly correct if execute-extended-command
7936 is bound to anything else. Perhaps it should use
7937 this_command_keys? */
7938 strcat (buf
, "M-x ");
7940 /* Prompt with buf, and then read a string, completing from and
7941 restricting to the set of all defined commands. Don't provide
7942 any initial input. Save the command read on the extended-command
7944 function
= Fcompleting_read (build_string (buf
),
7945 Vobarray
, Qcommandp
,
7946 Qt
, Qnil
, Qextended_command_history
, Qnil
,
7949 if (STRINGP (function
) && XSTRING (function
)->size
== 0)
7950 error ("No command name given");
7952 /* Set this_command_keys to the concatenation of saved_keys and
7953 function, followed by a RET. */
7955 struct Lisp_String
*str
;
7959 this_command_key_count
= 0;
7960 this_single_command_key_start
= 0;
7962 keys
= XVECTOR (saved_keys
)->contents
;
7963 for (i
= 0; i
< XVECTOR (saved_keys
)->size
; i
++)
7964 add_command_key (keys
[i
]);
7966 str
= XSTRING (function
);
7967 for (i
= 0; i
< str
->size
; i
++)
7968 add_command_key (Faref (function
, make_number (i
)));
7970 add_command_key (make_number ('\015'));
7975 function
= Fintern (function
, Qnil
);
7976 current_kboard
->Vprefix_arg
= prefixarg
;
7977 Vthis_command
= function
;
7978 real_this_command
= function
;
7980 /* If enabled, show which key runs this command. */
7981 if (!NILP (Vsuggest_key_bindings
)
7982 && NILP (Vexecuting_macro
)
7983 && SYMBOLP (function
))
7984 bindings
= Fwhere_is_internal (function
, Voverriding_local_map
,
7990 GCPRO2 (bindings
, value
);
7991 value
= Fcommand_execute (function
, Qt
, Qnil
, Qnil
);
7993 /* If the command has a key binding, print it now. */
7994 if (!NILP (bindings
)
7995 && ! (VECTORP (bindings
) && EQ (Faref (bindings
, make_number (0)),
7998 /* But first wait, and skip the message if there is input. */
8000 if (echo_area_glyphs
!= 0)
8001 /* This command displayed something in the echo area;
8002 so wait a few seconds, then display our suggestion message. */
8003 delay_time
= (NUMBERP (Vsuggest_key_bindings
)
8004 ? XINT (Vsuggest_key_bindings
) : 2);
8006 /* This command left the echo area empty,
8007 so display our message immediately. */
8010 if (!NILP (Fsit_for (make_number (delay_time
), Qnil
, Qnil
))
8011 && ! CONSP (Vunread_command_events
))
8013 Lisp_Object binding
;
8015 char *oldmessage
= echo_area_glyphs
;
8016 int oldmessage_len
= echo_area_glyphs_length
;
8017 int oldmultibyte
= message_enable_multibyte
;
8019 binding
= Fkey_description (bindings
);
8022 = (char *) alloca (XSYMBOL (function
)->name
->size
8023 + STRING_BYTES (XSTRING (binding
))
8025 sprintf (newmessage
, "You can run the command `%s' with %s",
8026 XSYMBOL (function
)->name
->data
,
8027 XSTRING (binding
)->data
);
8028 message2_nolog (newmessage
,
8029 strlen (newmessage
),
8030 STRING_MULTIBYTE (binding
));
8031 if (!NILP (Fsit_for ((NUMBERP (Vsuggest_key_bindings
)
8032 ? Vsuggest_key_bindings
: make_number (2)),
8034 message2_nolog (oldmessage
, oldmessage_len
, oldmultibyte
);
8038 RETURN_UNGCPRO (value
);
8041 /* Find the set of keymaps now active.
8042 Store into *MAPS_P a vector holding the various maps
8043 and return the number of them. The vector was malloc'd
8044 and the caller should free it. */
8047 current_active_maps (maps_p
)
8048 Lisp_Object
**maps_p
;
8050 Lisp_Object
*tmaps
, *maps
;
8053 /* Should overriding-terminal-local-map and overriding-local-map apply? */
8054 if (!NILP (Voverriding_local_map_menu_flag
))
8056 /* Yes, use them (if non-nil) as well as the global map. */
8057 maps
= (Lisp_Object
*) xmalloc (3 * sizeof (maps
[0]));
8059 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
8060 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
8061 if (!NILP (Voverriding_local_map
))
8062 maps
[nmaps
++] = Voverriding_local_map
;
8066 /* No, so use major and minor mode keymaps. */
8067 nmaps
= current_minor_maps (NULL
, &tmaps
);
8068 maps
= (Lisp_Object
*) xmalloc ((nmaps
+ 2) * sizeof (maps
[0]));
8069 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
8070 #ifdef USE_TEXT_PROPERTIES
8071 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
8073 maps
[nmaps
++] = current_buffer
->keymap
;
8076 maps
[nmaps
++] = current_global_map
;
8082 /* Return nonzero if input events are pending. */
8085 detect_input_pending ()
8088 get_input_pending (&input_pending
, 0);
8090 return input_pending
;
8093 /* Return nonzero if input events are pending, and run any pending timers. */
8096 detect_input_pending_run_timers (do_display
)
8099 int old_timers_run
= timers_run
;
8102 get_input_pending (&input_pending
, 1);
8104 if (old_timers_run
!= timers_run
&& do_display
)
8105 redisplay_preserve_echo_area ();
8107 return input_pending
;
8110 /* This is called in some cases before a possible quit.
8111 It cases the next call to detect_input_pending to recompute input_pending.
8112 So calling this function unnecessarily can't do any harm. */
8115 clear_input_pending ()
8120 /* Return nonzero if there are pending requeued events.
8121 This isn't used yet. The hope is to make wait_reading_process_input
8122 call it, and return return if it runs Lisp code that unreads something.
8123 The problem is, kbd_buffer_get_event needs to be fixed to know what
8124 to do in that case. It isn't trivial. */
8127 requeued_events_pending_p ()
8129 return (!NILP (Vunread_command_events
) || unread_command_char
!= -1);
8133 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
8134 "T if command input is currently available with no waiting.\n\
8135 Actually, the value is nil only if we can be sure that no input is available.")
8138 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1)
8141 get_input_pending (&input_pending
, 1);
8142 return input_pending
> 0 ? Qt
: Qnil
;
8145 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
8146 "Return vector of last 100 events, not counting those from keyboard macros.")
8149 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
8152 if (total_keys
< NUM_RECENT_KEYS
)
8153 return Fvector (total_keys
, keys
);
8156 val
= Fvector (NUM_RECENT_KEYS
, keys
);
8157 bcopy (keys
+ recent_keys_index
,
8158 XVECTOR (val
)->contents
,
8159 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
8161 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
8162 recent_keys_index
* sizeof (Lisp_Object
));
8167 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
8168 "Return the key sequence that invoked this command.\n\
8169 The value is a string or a vector.")
8172 return make_event_array (this_command_key_count
,
8173 XVECTOR (this_command_keys
)->contents
);
8176 DEFUN ("this-command-keys-vector", Fthis_command_keys_vector
, Sthis_command_keys_vector
, 0, 0, 0,
8177 "Return the key sequence that invoked this command, as a vector.")
8180 return Fvector (this_command_key_count
,
8181 XVECTOR (this_command_keys
)->contents
);
8184 DEFUN ("this-single-command-keys", Fthis_single_command_keys
,
8185 Sthis_single_command_keys
, 0, 0, 0,
8186 "Return the key sequence that invoked this command.\n\
8187 Unlike `this-command-keys', this function's value\n\
8188 does not include prefix arguments.\n\
8189 The value is always a vector.")
8192 return Fvector (this_command_key_count
8193 - this_single_command_key_start
,
8194 (XVECTOR (this_command_keys
)->contents
8195 + this_single_command_key_start
));
8198 DEFUN ("this-single-command-raw-keys", Fthis_single_command_raw_keys
,
8199 Sthis_single_command_raw_keys
, 0, 0, 0,
8200 "Return the raw events that were read for this command.\n\
8201 Unlike `this-single-command-keys', this function's value\n\
8202 shows the events before all translations (except for input methods).\n\
8203 The value is always a vector.")
8206 return Fvector (raw_keybuf_count
,
8207 (XVECTOR (raw_keybuf
)->contents
));
8210 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths
,
8211 Sreset_this_command_lengths
, 0, 0, 0,
8212 "Used for complicated reasons in `universal-argument-other-key'.\n\
8214 `universal-argument-other-key' rereads the event just typed.\n\
8215 It then gets translated through `function-key-map'.\n\
8216 The translated event gets included in the echo area and in\n\
8217 the value of `this-command-keys' in addition to the raw original event.\n\
8218 That is not right.\n\
8220 Calling this function directs the translated event to replace\n\
8221 the original event, so that only one version of the event actually\n\
8222 appears in the echo area and in the value of `this-command-keys.'.")
8225 before_command_restore_flag
= 1;
8226 before_command_key_count_1
= before_command_key_count
;
8227 before_command_echo_length_1
= before_command_echo_length
;
8231 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
8232 "Return the current depth in recursive edits.")
8236 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
8240 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
8241 "FOpen dribble file: ",
8242 "Start writing all keyboard characters to a dribble file called FILE.\n\
8243 If FILE is nil, close any open dribble file.")
8254 file
= Fexpand_file_name (file
, Qnil
);
8255 dribble
= fopen (XSTRING (file
)->data
, "w");
8257 report_file_error ("Opening dribble", Fcons (file
, Qnil
));
8262 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
8263 "Discard the contents of the terminal input buffer.\n\
8264 Also cancel any kbd macro being defined.")
8267 current_kboard
->defining_kbd_macro
= Qnil
;
8268 update_mode_lines
++;
8270 Vunread_command_events
= Qnil
;
8271 unread_command_char
= -1;
8273 discard_tty_input ();
8275 /* Without the cast, GCC complains that this assignment loses the
8276 volatile qualifier of kbd_store_ptr. Is there anything wrong
8278 kbd_fetch_ptr
= (struct input_event
*) kbd_store_ptr
;
8279 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
8285 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
8286 "Stop Emacs and return to superior process. You can resume later.\n\
8287 If `cannot-suspend' is non-nil, or if the system doesn't support job\n\
8288 control, run a subshell instead.\n\n\
8289 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
8290 to be read as terminal input by Emacs's parent, after suspension.\n\
8292 Before suspending, run the normal hook `suspend-hook'.\n\
8293 After resumption run the normal hook `suspend-resume-hook'.\n\
8295 Some operating systems cannot stop the Emacs process and resume it later.\n\
8296 On such systems, Emacs starts a subshell instead of suspending.")
8298 Lisp_Object stuffstring
;
8301 int count
= specpdl_ptr
- specpdl
;
8302 int old_height
, old_width
;
8304 struct gcpro gcpro1
, gcpro2
;
8306 if (!NILP (stuffstring
))
8307 CHECK_STRING (stuffstring
, 0);
8309 /* Run the functions in suspend-hook. */
8310 if (!NILP (Vrun_hooks
))
8311 call1 (Vrun_hooks
, intern ("suspend-hook"));
8313 GCPRO1 (stuffstring
);
8314 get_frame_size (&old_width
, &old_height
);
8316 /* sys_suspend can get an error if it tries to fork a subshell
8317 and the system resources aren't available for that. */
8318 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object
))) init_sys_modes
,
8320 stuff_buffered_input (stuffstring
);
8325 unbind_to (count
, Qnil
);
8327 /* Check if terminal/window size has changed.
8328 Note that this is not useful when we are running directly
8329 with a window system; but suspend should be disabled in that case. */
8330 get_frame_size (&width
, &height
);
8331 if (width
!= old_width
|| height
!= old_height
)
8332 change_frame_size (selected_frame
, height
, width
, 0, 0);
8334 /* Run suspend-resume-hook. */
8335 if (!NILP (Vrun_hooks
))
8336 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
8342 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
8343 Then in any case stuff anything Emacs has read ahead and not used. */
8346 stuff_buffered_input (stuffstring
)
8347 Lisp_Object stuffstring
;
8349 /* stuff_char works only in BSD, versions 4.2 and up. */
8352 register unsigned char *p
;
8354 if (STRINGP (stuffstring
))
8358 p
= XSTRING (stuffstring
)->data
;
8359 count
= STRING_BYTES (XSTRING (stuffstring
));
8364 /* Anything we have read ahead, put back for the shell to read. */
8365 /* ?? What should this do when we have multiple keyboards??
8366 Should we ignore anything that was typed in at the "wrong" kboard? */
8367 for (; kbd_fetch_ptr
!= kbd_store_ptr
; kbd_fetch_ptr
++)
8369 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
8370 kbd_fetch_ptr
= kbd_buffer
;
8371 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
8372 stuff_char (kbd_fetch_ptr
->code
);
8373 kbd_fetch_ptr
->kind
= no_event
;
8374 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_fetch_ptr
8380 #endif /* BSD_SYSTEM and not BSD4_1 */
8384 set_waiting_for_input (time_to_clear
)
8385 EMACS_TIME
*time_to_clear
;
8387 input_available_clear_time
= time_to_clear
;
8389 /* Tell interrupt_signal to throw back to read_char, */
8390 waiting_for_input
= 1;
8392 /* If interrupt_signal was called before and buffered a C-g,
8393 make it run again now, to avoid timing error. */
8394 if (!NILP (Vquit_flag
))
8395 quit_throw_to_read_char ();
8399 clear_waiting_for_input ()
8401 /* Tell interrupt_signal not to throw back to read_char, */
8402 waiting_for_input
= 0;
8403 input_available_clear_time
= 0;
8406 /* This routine is called at interrupt level in response to C-G.
8407 If interrupt_input, this is the handler for SIGINT.
8408 Otherwise, it is called from kbd_buffer_store_event,
8409 in handling SIGIO or SIGTINT.
8411 If `waiting_for_input' is non zero, then unless `echoing' is nonzero,
8412 immediately throw back to read_char.
8414 Otherwise it sets the Lisp variable quit-flag not-nil.
8415 This causes eval to throw, when it gets a chance.
8416 If quit-flag is already non-nil, it stops the job right away. */
8419 interrupt_signal (signalnum
) /* If we don't have an argument, */
8420 int signalnum
; /* some compilers complain in signal calls. */
8423 /* Must preserve main program's value of errno. */
8424 int old_errno
= errno
;
8426 #if defined (USG) && !defined (POSIX_SIGNALS)
8427 if (!read_socket_hook
&& NILP (Vwindow_system
))
8429 /* USG systems forget handlers when they are used;
8430 must reestablish each time */
8431 signal (SIGINT
, interrupt_signal
);
8432 signal (SIGQUIT
, interrupt_signal
);
8438 if (!NILP (Vquit_flag
)
8439 && (FRAME_TERMCAP_P (selected_frame
) || FRAME_MSDOS_P (selected_frame
)))
8441 /* If SIGINT isn't blocked, don't let us be interrupted by
8442 another SIGINT, it might be harmful due to non-reentrancy
8443 in I/O functions. */
8444 sigblock (sigmask (SIGINT
));
8449 #ifdef SIGTSTP /* Support possible in later USG versions */
8451 * On systems which can suspend the current process and return to the original
8452 * shell, this command causes the user to end up back at the shell.
8453 * The "Auto-save" and "Abort" questions are not asked until
8454 * the user elects to return to emacs, at which point he can save the current
8455 * job and either dump core or continue.
8460 if (sys_suspend () == -1)
8462 printf ("Not running as a subprocess;\n");
8463 printf ("you can continue or abort.\n");
8466 /* Perhaps should really fork an inferior shell?
8467 But that would not provide any way to get back
8468 to the original shell, ever. */
8469 printf ("No support for stopping a process on this operating system;\n");
8470 printf ("you can continue or abort.\n");
8471 #endif /* not VMS */
8472 #endif /* not SIGTSTP */
8474 /* We must remain inside the screen area when the internal terminal
8475 is used. Note that [Enter] is not echoed by dos. */
8478 /* It doesn't work to autosave while GC is in progress;
8479 the code used for auto-saving doesn't cope with the mark bit. */
8480 if (!gc_in_progress
)
8482 printf ("Auto-save? (y or n) ");
8484 if (((c
= getchar ()) & ~040) == 'Y')
8486 Fdo_auto_save (Qt
, Qnil
);
8488 printf ("\r\nAuto-save done");
8489 #else /* not MSDOS */
8490 printf ("Auto-save done\n");
8491 #endif /* not MSDOS */
8493 while (c
!= '\n') c
= getchar ();
8497 /* During GC, it must be safe to reenable quitting again. */
8498 Vinhibit_quit
= Qnil
;
8501 #endif /* not MSDOS */
8502 printf ("Garbage collection in progress; cannot auto-save now\r\n");
8503 printf ("but will instead do a real quit after garbage collection ends\r\n");
8508 printf ("\r\nAbort? (y or n) ");
8509 #else /* not MSDOS */
8511 printf ("Abort (and enter debugger)? (y or n) ");
8513 printf ("Abort (and dump core)? (y or n) ");
8514 #endif /* not VMS */
8515 #endif /* not MSDOS */
8517 if (((c
= getchar ()) & ~040) == 'Y')
8519 while (c
!= '\n') c
= getchar ();
8521 printf ("\r\nContinuing...\r\n");
8522 #else /* not MSDOS */
8523 printf ("Continuing...\n");
8524 #endif /* not MSDOS */
8531 /* If executing a function that wants to be interrupted out of
8532 and the user has not deferred quitting by binding `inhibit-quit'
8533 then quit right away. */
8534 if (immediate_quit
&& NILP (Vinhibit_quit
))
8536 struct gl_state_s saved
;
8537 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
8542 GCPRO4 (saved
.object
, saved
.global_code
,
8543 saved
.current_syntax_table
, saved
.old_prop
);
8544 Fsignal (Qquit
, Qnil
);
8549 /* Else request quit when it's safe */
8553 if (waiting_for_input
&& !echoing
)
8554 quit_throw_to_read_char ();
8559 /* Handle a C-g by making read_char return C-g. */
8562 quit_throw_to_read_char ()
8564 quit_error_check ();
8566 /* Prevent another signal from doing this before we finish. */
8567 clear_waiting_for_input ();
8570 Vunread_command_events
= Qnil
;
8571 unread_command_char
= -1;
8573 #if 0 /* Currently, sit_for is called from read_char without turning
8574 off polling. And that can call set_waiting_for_input.
8575 It seems to be harmless. */
8576 #ifdef POLL_FOR_INPUT
8577 /* May be > 1 if in recursive minibuffer. */
8578 if (poll_suppress_count
== 0)
8582 if (FRAMEP (internal_last_event_frame
)
8583 && XFRAME (internal_last_event_frame
) != selected_frame
)
8584 do_switch_frame (make_lispy_switch_frame (internal_last_event_frame
),
8587 _longjmp (getcjmp
, 1);
8590 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
8591 "Set mode of reading keyboard input.\n\
8592 First arg INTERRUPT non-nil means use input interrupts;\n\
8593 nil means use CBREAK mode.\n\
8594 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
8595 (no effect except in CBREAK mode).\n\
8596 Third arg META t means accept 8-bit input (for a Meta key).\n\
8597 META nil means ignore the top bit, on the assumption it is parity.\n\
8598 Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\
8599 Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\
8600 See also `current-input-mode'.")
8601 (interrupt
, flow
, meta
, quit
)
8602 Lisp_Object interrupt
, flow
, meta
, quit
;
8605 && (!INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400))
8606 error ("set-input-mode: QUIT must be an ASCII character");
8608 #ifdef POLL_FOR_INPUT
8613 /* this causes startup screen to be restored and messes with the mouse */
8618 /* Note SIGIO has been undef'd if FIONREAD is missing. */
8619 if (read_socket_hook
)
8621 /* When using X, don't give the user a real choice,
8622 because we haven't implemented the mechanisms to support it. */
8623 #ifdef NO_SOCK_SIGIO
8624 interrupt_input
= 0;
8625 #else /* not NO_SOCK_SIGIO */
8626 interrupt_input
= 1;
8627 #endif /* NO_SOCK_SIGIO */
8630 interrupt_input
= !NILP (interrupt
);
8631 #else /* not SIGIO */
8632 interrupt_input
= 0;
8633 #endif /* not SIGIO */
8635 /* Our VMS input only works by interrupts, as of now. */
8637 interrupt_input
= 1;
8640 flow_control
= !NILP (flow
);
8643 else if (EQ (meta
, Qt
))
8648 /* Don't let this value be out of range. */
8649 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
8655 #ifdef POLL_FOR_INPUT
8656 poll_suppress_count
= 1;
8662 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
8663 "Return information about the way Emacs currently reads keyboard input.\n\
8664 The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
8665 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\
8666 nil, Emacs is using CBREAK mode.\n\
8667 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\
8668 terminal; this does not apply if Emacs uses interrupt-driven input.\n\
8669 META is t if accepting 8-bit input with 8th bit as Meta flag.\n\
8670 META nil means ignoring the top bit, on the assumption it is parity.\n\
8671 META is neither t nor nil if accepting 8-bit input and using\n\
8672 all 8 bits as the character code.\n\
8673 QUIT is the character Emacs currently uses to quit.\n\
8674 The elements of this list correspond to the arguments of\n\
8680 val
[0] = interrupt_input
? Qt
: Qnil
;
8681 val
[1] = flow_control
? Qt
: Qnil
;
8682 val
[2] = meta_key
== 2 ? make_number (0) : meta_key
== 1 ? Qt
: Qnil
;
8683 XSETFASTINT (val
[3], quit_char
);
8685 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
8690 * Set up a new kboard object with reasonable initial values.
8696 kb
->Voverriding_terminal_local_map
= Qnil
;
8697 kb
->Vlast_command
= Qnil
;
8698 kb
->Vreal_last_command
= Qnil
;
8699 kb
->Vprefix_arg
= Qnil
;
8700 kb
->Vlast_prefix_arg
= Qnil
;
8701 kb
->kbd_queue
= Qnil
;
8702 kb
->kbd_queue_has_data
= 0;
8703 kb
->immediate_echo
= 0;
8704 kb
->echoptr
= kb
->echobuf
;
8705 kb
->echo_after_prompt
= -1;
8706 kb
->kbd_macro_buffer
= 0;
8707 kb
->kbd_macro_bufsize
= 0;
8708 kb
->defining_kbd_macro
= Qnil
;
8709 kb
->Vlast_kbd_macro
= Qnil
;
8710 kb
->reference_count
= 0;
8711 kb
->Vsystem_key_alist
= Qnil
;
8712 kb
->system_key_syms
= Qnil
;
8713 kb
->Vdefault_minibuffer_frame
= Qnil
;
8717 * Destroy the contents of a kboard object, but not the object itself.
8718 * We use this just before deleting it, or if we're going to initialize
8725 if (kb
->kbd_macro_buffer
)
8726 xfree (kb
->kbd_macro_buffer
);
8735 for (kbp
= &all_kboards
; *kbp
!= kb
; kbp
= &(*kbp
)->next_kboard
)
8738 *kbp
= kb
->next_kboard
;
8747 /* This is correct before outermost invocation of the editor loop */
8748 command_loop_level
= -1;
8750 quit_char
= Ctl ('g');
8751 Vunread_command_events
= Qnil
;
8752 unread_command_char
= -1;
8753 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
8755 recent_keys_index
= 0;
8756 kbd_fetch_ptr
= kbd_buffer
;
8757 kbd_store_ptr
= kbd_buffer
;
8758 kbd_buffer_frame_or_window
8759 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
8761 do_mouse_tracking
= Qnil
;
8765 /* This means that command_loop_1 won't try to select anything the first
8767 internal_last_event_frame
= Qnil
;
8768 Vlast_event_frame
= internal_last_event_frame
;
8771 current_kboard
= initial_kboard
;
8773 wipe_kboard (current_kboard
);
8774 init_kboard (current_kboard
);
8777 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
8779 kbd_buffer_frame_or_window
8780 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
8781 if (!noninteractive
&& !read_socket_hook
&& NILP (Vwindow_system
))
8783 signal (SIGINT
, interrupt_signal
);
8784 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
8785 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
8786 SIGQUIT and we can't tell which one it will give us. */
8787 signal (SIGQUIT
, interrupt_signal
);
8788 #endif /* HAVE_TERMIO */
8790 /* Note SIGIO has been undef'd if FIONREAD is missing. */
8792 if (!noninteractive
)
8793 signal (SIGIO
, input_available_signal
);
8796 /* Use interrupt input by default, if it works and noninterrupt input
8797 has deficiencies. */
8799 #ifdef INTERRUPT_INPUT
8800 interrupt_input
= 1;
8802 interrupt_input
= 0;
8805 /* Our VMS input only works by interrupts, as of now. */
8807 interrupt_input
= 1;
8813 if (keyboard_init_hook
)
8814 (*keyboard_init_hook
) ();
8816 #ifdef POLL_FOR_INPUT
8817 poll_suppress_count
= 1;
8822 /* This type's only use is in syms_of_keyboard, to initialize the
8823 event header symbols and put properties on them. */
8830 struct event_head head_table
[] = {
8831 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
8832 &Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
,
8833 &Qswitch_frame
, "switch-frame", &Qswitch_frame
,
8834 &Qdelete_frame
, "delete-frame", &Qdelete_frame
,
8835 &Qiconify_frame
, "iconify-frame", &Qiconify_frame
,
8836 &Qmake_frame_visible
, "make-frame-visible", &Qmake_frame_visible
,
8842 staticpro (&item_properties
);
8843 item_properties
= Qnil
;
8845 staticpro (&real_this_command
);
8846 real_this_command
= Qnil
;
8848 Qtimer_event_handler
= intern ("timer-event-handler");
8849 staticpro (&Qtimer_event_handler
);
8851 Qdisabled_command_hook
= intern ("disabled-command-hook");
8852 staticpro (&Qdisabled_command_hook
);
8854 Qself_insert_command
= intern ("self-insert-command");
8855 staticpro (&Qself_insert_command
);
8857 Qforward_char
= intern ("forward-char");
8858 staticpro (&Qforward_char
);
8860 Qbackward_char
= intern ("backward-char");
8861 staticpro (&Qbackward_char
);
8863 Qdisabled
= intern ("disabled");
8864 staticpro (&Qdisabled
);
8866 Qundefined
= intern ("undefined");
8867 staticpro (&Qundefined
);
8869 Qpre_command_hook
= intern ("pre-command-hook");
8870 staticpro (&Qpre_command_hook
);
8872 Qpost_command_hook
= intern ("post-command-hook");
8873 staticpro (&Qpost_command_hook
);
8875 Qpost_command_idle_hook
= intern ("post-command-idle-hook");
8876 staticpro (&Qpost_command_idle_hook
);
8878 Qdeferred_action_function
= intern ("deferred-action-function");
8879 staticpro (&Qdeferred_action_function
);
8881 Qcommand_hook_internal
= intern ("command-hook-internal");
8882 staticpro (&Qcommand_hook_internal
);
8884 Qfunction_key
= intern ("function-key");
8885 staticpro (&Qfunction_key
);
8886 Qmouse_click
= intern ("mouse-click");
8887 staticpro (&Qmouse_click
);
8889 Qmouse_wheel
= intern ("mouse-wheel");
8890 staticpro (&Qmouse_wheel
);
8892 Qdrag_n_drop
= intern ("drag-n-drop");
8893 staticpro (&Qdrag_n_drop
);
8895 Qmenu_enable
= intern ("menu-enable");
8896 staticpro (&Qmenu_enable
);
8897 Qmenu_alias
= intern ("menu-alias");
8898 staticpro (&Qmenu_alias
);
8899 QCenable
= intern (":enable");
8900 staticpro (&QCenable
);
8901 QCvisible
= intern (":visible");
8902 staticpro (&QCvisible
);
8903 QCfilter
= intern (":filter");
8904 staticpro (&QCfilter
);
8905 QCbutton
= intern (":button");
8906 staticpro (&QCbutton
);
8907 QCkeys
= intern (":keys");
8908 staticpro (&QCkeys
);
8909 QCkey_sequence
= intern (":key-sequence");
8910 staticpro (&QCkey_sequence
);
8911 QCtoggle
= intern (":toggle");
8912 staticpro (&QCtoggle
);
8913 QCradio
= intern (":radio");
8914 staticpro (&QCradio
);
8916 Qmode_line
= intern ("mode-line");
8917 staticpro (&Qmode_line
);
8918 Qvertical_line
= intern ("vertical-line");
8919 staticpro (&Qvertical_line
);
8920 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
8921 staticpro (&Qvertical_scroll_bar
);
8922 Qmenu_bar
= intern ("menu-bar");
8923 staticpro (&Qmenu_bar
);
8925 Qabove_handle
= intern ("above-handle");
8926 staticpro (&Qabove_handle
);
8927 Qhandle
= intern ("handle");
8928 staticpro (&Qhandle
);
8929 Qbelow_handle
= intern ("below-handle");
8930 staticpro (&Qbelow_handle
);
8931 Qup
= intern ("up");
8933 Qdown
= intern ("down");
8936 Qevent_kind
= intern ("event-kind");
8937 staticpro (&Qevent_kind
);
8938 Qevent_symbol_elements
= intern ("event-symbol-elements");
8939 staticpro (&Qevent_symbol_elements
);
8940 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
8941 staticpro (&Qevent_symbol_element_mask
);
8942 Qmodifier_cache
= intern ("modifier-cache");
8943 staticpro (&Qmodifier_cache
);
8945 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
8946 staticpro (&Qrecompute_lucid_menubar
);
8947 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
8948 staticpro (&Qactivate_menubar_hook
);
8950 Qpolling_period
= intern ("polling-period");
8951 staticpro (&Qpolling_period
);
8953 Qinput_method_function
= intern ("input-method-function");
8954 staticpro (&Qinput_method_function
);
8956 Qinput_method_exit_on_first_char
= intern ("input-method-exit-on-first-char");
8957 staticpro (&Qinput_method_exit_on_first_char
);
8958 Qinput_method_use_echo_area
= intern ("input-method-use-echo-area");
8959 staticpro (&Qinput_method_use_echo_area
);
8961 Fset (Qinput_method_exit_on_first_char
, Qnil
);
8962 Fset (Qinput_method_use_echo_area
, Qnil
);
8965 struct event_head
*p
;
8967 for (p
= head_table
;
8968 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
8971 *p
->var
= intern (p
->name
);
8973 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
8974 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
8978 button_down_location
= Fmake_vector (make_number (NUM_MOUSE_BUTTONS
), Qnil
);
8979 staticpro (&button_down_location
);
8983 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
8985 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
8986 for (i
= 0; i
< len
; i
++)
8987 if (modifier_names
[i
])
8988 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
8989 staticpro (&modifier_symbols
);
8992 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
8993 staticpro (&recent_keys
);
8995 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
8996 staticpro (&this_command_keys
);
8998 raw_keybuf
= Fmake_vector (make_number (30), Qnil
);
8999 staticpro (&raw_keybuf
);
9001 Qextended_command_history
= intern ("extended-command-history");
9002 Fset (Qextended_command_history
, Qnil
);
9003 staticpro (&Qextended_command_history
);
9005 kbd_buffer_frame_or_window
9006 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
9007 staticpro (&kbd_buffer_frame_or_window
);
9009 accent_key_syms
= Qnil
;
9010 staticpro (&accent_key_syms
);
9012 func_key_syms
= Qnil
;
9013 staticpro (&func_key_syms
);
9016 staticpro (&mouse_syms
);
9019 mouse_wheel_syms
= Qnil
;
9020 staticpro (&mouse_wheel_syms
);
9022 drag_n_drop_syms
= Qnil
;
9023 staticpro (&drag_n_drop_syms
);
9026 unread_switch_frame
= Qnil
;
9027 staticpro (&unread_switch_frame
);
9029 internal_last_event_frame
= Qnil
;
9030 staticpro (&internal_last_event_frame
);
9032 read_key_sequence_cmd
= Qnil
;
9033 staticpro (&read_key_sequence_cmd
);
9035 defsubr (&Sevent_convert_list
);
9036 defsubr (&Sread_key_sequence
);
9037 defsubr (&Sread_key_sequence_vector
);
9038 defsubr (&Srecursive_edit
);
9040 defsubr (&Strack_mouse
);
9042 defsubr (&Sinput_pending_p
);
9043 defsubr (&Scommand_execute
);
9044 defsubr (&Srecent_keys
);
9045 defsubr (&Sthis_command_keys
);
9046 defsubr (&Sthis_command_keys_vector
);
9047 defsubr (&Sthis_single_command_keys
);
9048 defsubr (&Sthis_single_command_raw_keys
);
9049 defsubr (&Sreset_this_command_lengths
);
9050 defsubr (&Ssuspend_emacs
);
9051 defsubr (&Sabort_recursive_edit
);
9052 defsubr (&Sexit_recursive_edit
);
9053 defsubr (&Srecursion_depth
);
9054 defsubr (&Stop_level
);
9055 defsubr (&Sdiscard_input
);
9056 defsubr (&Sopen_dribble_file
);
9057 defsubr (&Sset_input_mode
);
9058 defsubr (&Scurrent_input_mode
);
9059 defsubr (&Sexecute_extended_command
);
9061 DEFVAR_LISP ("last-command-char", &last_command_char
,
9062 "Last input event that was part of a command.");
9064 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char
,
9065 "Last input event that was part of a command.");
9067 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
9068 "Last input event in a command, except for mouse menu events.\n\
9069 Mouse menus give back keys that don't look like mouse events;\n\
9070 this variable holds the actual mouse event that led to the menu,\n\
9071 so that you can determine whether the command was run by mouse or not.");
9073 DEFVAR_LISP ("last-input-char", &last_input_char
,
9074 "Last input event.");
9076 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char
,
9077 "Last input event.");
9079 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
9080 "List of events to be read as the command input.\n\
9081 These events are processed first, before actual keyboard input.");
9082 Vunread_command_events
= Qnil
;
9084 DEFVAR_INT ("unread-command-char", &unread_command_char
,
9085 "If not -1, an object to be read as next command input event.");
9087 DEFVAR_LISP ("unread-post-input-method-events", &Vunread_post_input_method_events
,
9088 "List of events to be processed as input by input methods.\n\
9089 These events are processed after `unread-command-events', but\n\
9090 before actual keyboard input.");
9091 Vunread_post_input_method_events
= Qnil
;
9093 DEFVAR_LISP ("unread-input-method-events", &Vunread_input_method_events
,
9094 "List of events to be processed as input by input methods.\n\
9095 These events are processed after `unread-command-events', but\n\
9096 before actual keyboard input.");
9097 Vunread_input_method_events
= Qnil
;
9099 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
9100 "Meta-prefix character code. Meta-foo as command input\n\
9101 turns into this character followed by foo.");
9102 XSETINT (meta_prefix_char
, 033);
9104 DEFVAR_KBOARD ("last-command", Vlast_command
,
9105 "The last command executed. Normally a symbol with a function definition,\n\
9106 but can be whatever was found in the keymap, or whatever the variable\n\
9107 `this-command' was set to by that command.\n\
9109 The value `mode-exit' is special; it means that the previous command\n\
9110 read an event that told it to exit, and it did so and unread that event.\n\
9111 In other words, the present command is the event that made the previous\n\
9114 The value `kill-region' is special; it means that the previous command\n\
9115 was a kill command.");
9117 DEFVAR_KBOARD ("real-last-command", Vreal_last_command
,
9118 "Same as `last-command', but never altered by Lisp code.");
9120 DEFVAR_LISP ("this-command", &Vthis_command
,
9121 "The command now being executed.\n\
9122 The command can set this variable; whatever is put here\n\
9123 will be in `last-command' during the following command.");
9124 Vthis_command
= Qnil
;
9126 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
9127 "*Number of keyboard input characters between auto-saves.\n\
9128 Zero means disable autosaving due to number of characters typed.");
9129 auto_save_interval
= 300;
9131 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
9132 "*Number of seconds idle time before auto-save.\n\
9133 Zero or nil means disable auto-saving due to idleness.\n\
9134 After auto-saving due to this many seconds of idle time,\n\
9135 Emacs also does a garbage collection if that seems to be warranted.");
9136 XSETFASTINT (Vauto_save_timeout
, 30);
9138 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes
,
9139 "*Nonzero means echo unfinished commands after this many seconds of pause.");
9140 echo_keystrokes
= 1;
9142 DEFVAR_INT ("polling-period", &polling_period
,
9143 "*Interval between polling for input during Lisp execution.\n\
9144 The reason for polling is to make C-g work to stop a running program.\n\
9145 Polling is needed only when using X windows and SIGIO does not work.\n\
9146 Polling is automatically disabled in all other cases.");
9149 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
9150 "*Maximum time between mouse clicks to make a double-click.\n\
9151 Measured in milliseconds. nil means disable double-click recognition;\n\
9152 t means double-clicks have no time limit and are detected\n\
9153 by position only.");
9154 Vdouble_click_time
= make_number (500);
9156 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
9157 "*Non-nil means inhibit local map menu bar menus.");
9158 inhibit_local_menu_bar_menus
= 0;
9160 DEFVAR_INT ("num-input-keys", &num_input_keys
,
9161 "Number of complete key sequences read as input so far.\n\
9162 This includes key sequences read from keyboard macros.\n\
9163 The number is effectively the number of interactive command invocations.");
9166 DEFVAR_INT ("num-nonmacro-input-events", &num_nonmacro_input_events
,
9167 "Number of input events read from the keyboard so far.\n\
9168 This does not include events generated by keyboard macros.");
9169 num_nonmacro_input_events
= 0;
9171 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
9172 "The frame in which the most recently read event occurred.\n\
9173 If the last event came from a keyboard macro, this is set to `macro'.");
9174 Vlast_event_frame
= Qnil
;
9176 /* This variable is set up in sysdep.c. */
9177 DEFVAR_LISP ("tty-erase-char", &Vtty_erase_char
,
9178 "The ERASE character as set by the user with stty.");
9180 DEFVAR_LISP ("help-char", &Vhelp_char
,
9181 "Character to recognize as meaning Help.\n\
9182 When it is read, do `(eval help-form)', and display result if it's a string.\n\
9183 If the value of `help-form' is nil, this char can be read normally.");
9184 XSETINT (Vhelp_char
, Ctl ('H'));
9186 DEFVAR_LISP ("help-event-list", &Vhelp_event_list
,
9187 "List of input events to recognize as meaning Help.\n\
9188 These work just like the value of `help-char' (see that).");
9189 Vhelp_event_list
= Qnil
;
9191 DEFVAR_LISP ("help-form", &Vhelp_form
,
9192 "Form to execute when character `help-char' is read.\n\
9193 If the form returns a string, that string is displayed.\n\
9194 If `help-form' is nil, the help char is not recognized.");
9197 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
9198 "Command to run when `help-char' character follows a prefix key.\n\
9199 This command is used only when there is no actual binding\n\
9200 for that character after that prefix key.");
9201 Vprefix_help_command
= Qnil
;
9203 DEFVAR_LISP ("top-level", &Vtop_level
,
9204 "Form to evaluate when Emacs starts up.\n\
9205 Useful to set before you dump a modified Emacs.");
9208 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
9209 "Translate table for keyboard input, or nil.\n\
9210 Each character is looked up in this string and the contents used instead.\n\
9211 The value may be a string, a vector, or a char-table.\n\
9212 If it is a string or vector of length N,\n\
9213 character codes N and up are untranslated.\n\
9214 In a vector or a char-table, an element which is nil means \"no translation\".");
9215 Vkeyboard_translate_table
= Qnil
;
9217 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
9218 "Non-nil means to always spawn a subshell instead of suspending,\n\
9219 even if the operating system has support for stopping a process.");
9222 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
9223 "Non-nil means prompt with menus when appropriate.\n\
9224 This is done when reading from a keymap that has a prompt string,\n\
9225 for elements that have prompt strings.\n\
9226 The menu is displayed on the screen\n\
9227 if X menus were enabled at configuration\n\
9228 time and the previous event was a mouse click prefix key.\n\
9229 Otherwise, menu prompting uses the echo area.");
9232 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
9233 "Character to see next line of menu prompt.\n\
9234 Type this character while in a menu prompt to rotate around the lines of it.");
9235 XSETINT (menu_prompt_more_char
, ' ');
9237 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
9238 "A mask of additional modifier keys to use with every keyboard character.\n\
9239 Emacs applies the modifiers of the character stored here to each keyboard\n\
9240 character it reads. For example, after evaluating the expression\n\
9241 (setq extra-keyboard-modifiers ?\\C-x)\n\
9242 all input characters will have the control modifier applied to them.\n\
9244 Note that the character ?\\C-@, equivalent to the integer zero, does\n\
9245 not count as a control character; rather, it counts as a character\n\
9246 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\
9247 cancels any modification.");
9248 extra_keyboard_modifiers
= 0;
9250 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
9251 "If an editing command sets this to t, deactivate the mark afterward.\n\
9252 The command loop sets this to nil before each command,\n\
9253 and tests the value when the command returns.\n\
9254 Buffer modification stores t in this variable.");
9255 Vdeactivate_mark
= Qnil
;
9257 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
9258 "Temporary storage of pre-command-hook or post-command-hook.");
9259 Vcommand_hook_internal
= Qnil
;
9261 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
9262 "Normal hook run before each command is executed.\n\
9263 Errors running the hook are caught and ignored.");
9264 Vpre_command_hook
= Qnil
;
9266 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
9267 "Normal hook run after each command is executed.\n\
9268 Errors running the hook are caught and ignored.");
9269 Vpost_command_hook
= Qnil
;
9271 DEFVAR_LISP ("post-command-idle-hook", &Vpost_command_idle_hook
,
9272 "Normal hook run after each command is executed, if idle.\n\
9273 Errors running the hook are caught and ignored.\n\
9274 This feature is obsolete; use idle timers instead. See `etc/NEWS'.");
9275 Vpost_command_idle_hook
= Qnil
;
9277 DEFVAR_INT ("post-command-idle-delay", &post_command_idle_delay
,
9278 "Delay time before running `post-command-idle-hook'.\n\
9279 This is measured in microseconds.");
9280 post_command_idle_delay
= 100000;
9283 DEFVAR_LISP ("echo-area-clear-hook", ...,
9284 "Normal hook run when clearing the echo area.");
9286 Qecho_area_clear_hook
= intern ("echo-area-clear-hook");
9287 XSYMBOL (Qecho_area_clear_hook
)->value
= Qnil
;
9289 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
9290 "t means menu bar, specified Lucid style, needs to be recomputed.");
9291 Vlucid_menu_bar_dirty_flag
= Qnil
;
9293 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
9294 "List of menu bar items to move to the end of the menu bar.\n\
9295 The elements of the list are event types that may have menu bar bindings.");
9296 Vmenu_bar_final_items
= Qnil
;
9298 DEFVAR_KBOARD ("overriding-terminal-local-map",
9299 Voverriding_terminal_local_map
,
9300 "Per-terminal keymap that overrides all other local keymaps.\n\
9301 If this variable is non-nil, it is used as a keymap instead of the\n\
9302 buffer's local map, and the minor mode keymaps and text property keymaps.\n\
9303 This variable is intended to let commands such as `universal-argumemnt'\n\
9304 set up a different keymap for reading the next command.");
9306 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
9307 "Keymap that overrides all other local keymaps.\n\
9308 If this variable is non-nil, it is used as a keymap instead of the\n\
9309 buffer's local map, and the minor mode keymaps and text property keymaps.");
9310 Voverriding_local_map
= Qnil
;
9312 DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag
,
9313 "Non-nil means `overriding-local-map' applies to the menu bar.\n\
9314 Otherwise, the menu bar continues to reflect the buffer's local map\n\
9315 and the minor mode maps regardless of `overriding-local-map'.");
9316 Voverriding_local_map_menu_flag
= Qnil
;
9318 DEFVAR_LISP ("special-event-map", &Vspecial_event_map
,
9319 "Keymap defining bindings for special events to execute at low level.");
9320 Vspecial_event_map
= Fcons (intern ("keymap"), Qnil
);
9322 DEFVAR_LISP ("track-mouse", &do_mouse_tracking
,
9323 "*Non-nil means generate motion events for mouse motion.");
9325 DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist
,
9326 "Alist of system-specific X windows key symbols.\n\
9327 Each element should have the form (N . SYMBOL) where N is the\n\
9328 numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\
9329 and SYMBOL is its name.");
9331 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
9332 "List of deferred actions to be performed at a later time.\n\
9333 The precise format isn't relevant here; we just check whether it is nil.");
9334 Vdeferred_action_list
= Qnil
;
9336 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
9337 "Function to call to handle deferred actions, after each command.\n\
9338 This function is called with no arguments after each command\n\
9339 whenever `deferred-action-list' is non-nil.");
9340 Vdeferred_action_function
= Qnil
;
9342 DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings
,
9343 "*Non-nil means show the equivalent key-binding when M-x command has one.\n\
9344 The value can be a length of time to show the message for.\n\
9345 If the value is non-nil and not a number, we wait 2 seconds.");
9346 Vsuggest_key_bindings
= Qt
;
9348 DEFVAR_LISP ("timer-list", &Vtimer_list
,
9349 "List of active absolute time timers in order of increasing time");
9352 DEFVAR_LISP ("timer-idle-list", &Vtimer_idle_list
,
9353 "List of active idle-time timers in order of increasing time");
9354 Vtimer_idle_list
= Qnil
;
9356 DEFVAR_LISP ("input-method-function", &Vinput_method_function
,
9357 "If non-nil, the function that implements the current input method.\n\
9358 It's called with one argument, a printing character that was just read.\n\
9359 \(That means a character with code 040...0176.)\n\
9360 Typically this function uses `read-event' to read additional events.\n\
9361 When it does so, it should first bind `input-method-function' to nil\n\
9362 so it will not be called recursively.\n\
9364 The function should return a list of zero or more events\n\
9365 to be used as input. If it wants to put back some events\n\
9366 to be reconsidered, separately, by the input method,\n\
9367 it can add them to the beginning of `unread-command-events'.\n\
9369 The input method function can find in `input-method-previous-method'\n\
9370 the previous echo area message.\n\
9372 The input method function should refer to the variables\n\
9373 `input-method-use-echo-area' and `input-method-exit-on-first-char'\n\
9374 for guidance on what to do.");
9375 Vinput_method_function
= Qnil
;
9377 DEFVAR_LISP ("input-method-previous-message",
9378 &Vinput_method_previous_message
,
9379 "When `input-method-function' is called, hold the previous echo area message.\n\
9380 This variable exists because `read-event' clears the echo area\n\
9381 before running the input method. It is nil if there was no message.");
9382 Vinput_method_previous_message
= Qnil
;
9388 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
9389 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
9390 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
9391 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
9392 initial_define_key (meta_map
, 'x', "execute-extended-command");
9394 initial_define_lispy_key (Vspecial_event_map
, "delete-frame",
9395 "handle-delete-frame");
9396 initial_define_lispy_key (Vspecial_event_map
, "iconify-frame",
9398 initial_define_lispy_key (Vspecial_event_map
, "make-frame-visible",