1 /* Keyboard and mouse input; editor command loop.
2 Copyright (C) 1985,86,87,88,89,93,94,95 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* Allow config.h to undefine symbols found here. */
28 #include "termhooks.h"
35 #include "dispextern.h"
37 #include "intervals.h"
38 #include "blockinput.h"
47 #include <sys/ioctl.h>
49 #endif /* not MSDOS */
51 #include "syssignal.h"
54 /* This is to get the definitions of the XK_ symbols. */
59 /* Include systime.h after xterm.h to avoid double inclusion of time.h. */
64 /* Variables for blockinput.h: */
66 /* Non-zero if interrupt input is blocked right now. */
67 int interrupt_input_blocked
;
69 /* Nonzero means an input interrupt has arrived
70 during the current critical section. */
71 int interrupt_input_pending
;
74 /* File descriptor to use for input. */
78 /* Make all keyboard buffers much bigger when using X windows. */
79 #define KBD_BUFFER_SIZE 4096
80 #else /* No X-windows, character input */
81 #define KBD_BUFFER_SIZE 256
82 #endif /* No X-windows */
84 /* Following definition copied from eval.c */
88 struct backtrace
*next
;
89 Lisp_Object
*function
;
90 Lisp_Object
*args
; /* Points to vector of args. */
91 int nargs
; /* length of vector. If nargs is UNEVALLED,
92 args points to slot holding list of
98 KBOARD
*initial_kboard
;
99 KBOARD
*current_kboard
;
103 KBOARD the_only_kboard
;
106 /* Non-nil disable property on a command means
107 do not execute it; call disabled-command-hook's value instead. */
108 Lisp_Object Qdisabled
, Qdisabled_command_hook
;
110 #define NUM_RECENT_KEYS (100)
111 int recent_keys_index
; /* Index for storing next element into recent_keys */
112 int total_keys
; /* Total number of elements stored into recent_keys */
113 Lisp_Object recent_keys
; /* A vector, holding the last 100 keystrokes */
115 /* Vector holding the key sequence that invoked the current command.
116 It is reused for each command, and it may be longer than the current
117 sequence; this_command_key_count indicates how many elements
118 actually mean something.
119 It's easier to staticpro a single Lisp_Object than an array. */
120 Lisp_Object this_command_keys
;
121 int this_command_key_count
;
123 /* Record values of this_command_key_count and echo_length ()
124 before this command was read. */
125 static int before_command_key_count
;
126 static int before_command_echo_length
;
127 /* Values of before_command_key_count and before_command_echo_length
128 saved by reset-this-command-lengths. */
129 static int before_command_key_count_1
;
130 static int before_command_echo_length_1
;
131 /* Flag set by reset-this-command-lengths,
132 saying to reset the lengths when add_command_key is called. */
133 static int before_command_restore_flag
;
135 extern int minbuf_level
;
137 extern struct backtrace
*backtrace_list
;
139 /* Nonzero means do menu prompting. */
140 static int menu_prompting
;
142 /* Character to see next line of menu prompt. */
143 static Lisp_Object menu_prompt_more_char
;
145 /* For longjmp to where kbd input is being done. */
146 static jmp_buf getcjmp
;
148 /* True while doing kbd input. */
149 int waiting_for_input
;
151 /* True while displaying for echoing. Delays C-g throwing. */
154 /* Nonzero means disregard local maps for the menu bar. */
155 static int inhibit_local_menu_bar_menus
;
157 /* Nonzero means C-g should cause immediate error-signal. */
160 /* Character to recognize as the help char. */
161 Lisp_Object Vhelp_char
;
163 /* List of other event types to recognize as meaning "help". */
164 Lisp_Object Vhelp_event_list
;
166 /* Form to execute when help char is typed. */
167 Lisp_Object Vhelp_form
;
169 /* Command to run when the help character follows a prefix key. */
170 Lisp_Object Vprefix_help_command
;
172 /* List of items that should move to the end of the menu bar. */
173 Lisp_Object Vmenu_bar_final_items
;
175 /* Non-nil means show the equivalent key-binding for
176 any M-x command that has one.
177 The value can be a length of time to show the message for.
178 If the value is non-nil and not a number, we wait 2 seconds. */
179 Lisp_Object Vsuggest_key_bindings
;
181 /* Character that causes a quit. Normally C-g.
183 If we are running on an ordinary terminal, this must be an ordinary
184 ASCII char, since we want to make it our interrupt character.
186 If we are not running on an ordinary terminal, it still needs to be
187 an ordinary ASCII char. This character needs to be recognized in
188 the input interrupt handler. At this point, the keystroke is
189 represented as a struct input_event, while the desired quit
190 character is specified as a lispy event. The mapping from struct
191 input_events to lispy events cannot run in an interrupt handler,
192 and the reverse mapping is difficult for anything but ASCII
195 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
199 extern Lisp_Object current_global_map
;
200 extern int minibuf_level
;
202 /* If non-nil, this is a map that overrides all other local maps. */
203 Lisp_Object Voverriding_local_map
;
205 /* If non-nil, Voverriding_local_map applies to the menu bar. */
206 Lisp_Object Voverriding_local_map_menu_flag
;
208 /* Keymap that defines special misc events that should
209 be processed immediately at a low level. */
210 Lisp_Object Vspecial_event_map
;
212 /* Current depth in recursive edits. */
213 int command_loop_level
;
215 /* Total number of times command_loop has read a key sequence. */
218 /* Last input character read as a command. */
219 Lisp_Object last_command_char
;
221 /* Last input character read as a command, not counting menus
222 reached by the mouse. */
223 Lisp_Object last_nonmenu_event
;
225 /* Last input character read for any purpose. */
226 Lisp_Object last_input_char
;
228 /* If not Qnil, a list of objects to be read as subsequent command input. */
229 Lisp_Object Vunread_command_events
;
231 /* If not -1, an event to be read as subsequent command input. */
232 int unread_command_char
;
234 /* If not Qnil, this is a switch-frame event which we decided to put
235 off until the end of a key sequence. This should be read as the
236 next command input, after any unread_command_events.
238 read_key_sequence uses this to delay switch-frame events until the
239 end of the key sequence; Fread_char uses it to put off switch-frame
240 events until a non-ASCII event is acceptable as input. */
241 Lisp_Object unread_switch_frame
;
243 /* A mask of extra modifier bits to put into every keyboard char. */
244 int extra_keyboard_modifiers
;
246 /* Char to use as prefix when a meta character is typed in.
247 This is bound on entry to minibuffer in case ESC is changed there. */
249 Lisp_Object meta_prefix_char
;
251 /* Last size recorded for a current buffer which is not a minibuffer. */
252 static int last_non_minibuf_size
;
254 /* Number of idle seconds before an auto-save and garbage collection. */
255 static Lisp_Object Vauto_save_timeout
;
257 /* Total number of times read_char has returned. */
260 /* Total number of times read_char has returned, outside of macros. */
261 int num_nonmacro_input_chars
;
263 /* Auto-save automatically when this many characters have been typed
264 since the last time. */
266 static int auto_save_interval
;
268 /* Value of num_nonmacro_input_chars as of last auto save. */
272 /* The command being executed by the command loop.
273 Commands may set this, and the value set will be copied into
274 current_kboard->Vlast_command instead of the actual command. */
275 Lisp_Object this_command
;
277 /* The value of point when the last command was executed. */
278 int last_point_position
;
280 /* The buffer that was current when the last command was started. */
281 Lisp_Object last_point_position_buffer
;
284 /* The frame in which the last input event occurred, or Qmacro if the
285 last event came from a macro. We use this to determine when to
286 generate switch-frame events. This may be cleared by functions
287 like Fselect_frame, to make sure that a switch-frame event is
288 generated by the next character. */
289 Lisp_Object internal_last_event_frame
;
292 /* A user-visible version of the above, intended to allow users to
293 figure out where the last event came from, if the event doesn't
294 carry that information itself (i.e. if it was a character). */
295 Lisp_Object Vlast_event_frame
;
297 /* The timestamp of the last input event we received from the X server.
298 X Windows wants this for selection ownership. */
299 unsigned long last_event_timestamp
;
301 Lisp_Object Qself_insert_command
;
302 Lisp_Object Qforward_char
;
303 Lisp_Object Qbackward_char
;
304 Lisp_Object Qundefined
;
306 /* read_key_sequence stores here the command definition of the
307 key sequence that it reads. */
308 Lisp_Object read_key_sequence_cmd
;
310 /* Form to evaluate (if non-nil) when Emacs is started. */
311 Lisp_Object Vtop_level
;
313 /* User-supplied string to translate input characters through. */
314 Lisp_Object Vkeyboard_translate_table
;
316 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
317 extern Lisp_Object Vfunction_key_map
;
319 /* Another keymap that maps key sequences into key sequences.
320 This one takes precedence over ordinary definitions. */
321 extern Lisp_Object Vkey_translation_map
;
323 /* Non-nil means deactivate the mark at end of this command. */
324 Lisp_Object Vdeactivate_mark
;
326 /* Menu bar specified in Lucid Emacs fashion. */
328 Lisp_Object Vlucid_menu_bar_dirty_flag
;
329 Lisp_Object Qrecompute_lucid_menubar
, Qactivate_menubar_hook
;
331 /* Hooks to run before and after each command. */
332 Lisp_Object Qpre_command_hook
, Vpre_command_hook
;
333 Lisp_Object Qpost_command_hook
, Vpost_command_hook
;
334 Lisp_Object Qcommand_hook_internal
, Vcommand_hook_internal
;
335 /* Hook run after a command if there's no more input soon. */
336 Lisp_Object Qpost_command_idle_hook
, Vpost_command_idle_hook
;
338 /* Delay time in microseconds before running post-command-idle-hook. */
339 int post_command_idle_delay
;
341 /* List of deferred actions to be performed at a later time.
342 The precise format isn't relevant here; we just check whether it is nil. */
343 Lisp_Object Vdeferred_action_list
;
345 /* Function to call to handle deferred actions, when there are any. */
346 Lisp_Object Vdeferred_action_function
;
347 Lisp_Object Qdeferred_action_function
;
349 /* File in which we write all commands we read. */
352 /* Nonzero if input is available. */
355 /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
356 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
360 extern char *pending_malloc_warning
;
362 /* Circular buffer for pre-read keyboard input. */
363 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
365 /* Vector to GCPRO the frames and windows mentioned in kbd_buffer.
367 The interrupt-level event handlers will never enqueue an event on a
368 frame which is not in Vframe_list, and once an event is dequeued,
369 internal_last_event_frame or the event itself points to the frame.
372 But while the event is sitting in the queue, it's completely
373 unprotected. Suppose the user types one command which will run for
374 a while and then delete a frame, and then types another event at
375 the frame that will be deleted, before the command gets around to
376 it. Suppose there are no references to this frame elsewhere in
377 Emacs, and a GC occurs before the second event is dequeued. Now we
378 have an event referring to a freed frame, which will crash Emacs
381 Similar things happen when an event on a scroll bar is enqueued; the
382 window may be deleted while the event is in the queue.
384 So, we use this vector to protect the frame_or_window field in the
385 event queue. That way, they'll be dequeued as dead frames or
386 windows, but still valid lisp objects.
388 If kbd_buffer[i].kind != no_event, then
389 (XVECTOR (kbd_buffer_frame_or_window)->contents[i]
390 == kbd_buffer[i].frame_or_window. */
391 static Lisp_Object kbd_buffer_frame_or_window
;
393 /* Pointer to next available character in kbd_buffer.
394 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
395 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the
396 next available char is in kbd_buffer[0]. */
397 static struct input_event
*kbd_fetch_ptr
;
399 /* Pointer to next place to store character in kbd_buffer. This
400 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
401 character should go in kbd_buffer[0]. */
402 static volatile struct input_event
*kbd_store_ptr
;
404 /* The above pair of variables forms a "queue empty" flag. When we
405 enqueue a non-hook event, we increment kbd_store_ptr. When we
406 dequeue a non-hook event, we increment kbd_fetch_ptr. We say that
407 there is input available iff the two pointers are not equal.
409 Why not just have a flag set and cleared by the enqueuing and
410 dequeuing functions? Such a flag could be screwed up by interrupts
411 at inopportune times. */
413 /* If this flag is non-nil, we check mouse_moved to see when the
414 mouse moves, and motion events will appear in the input stream.
415 Otherwise, mouse motion is ignored. */
416 static Lisp_Object do_mouse_tracking
;
418 /* Symbols to head events. */
419 Lisp_Object Qmouse_movement
;
420 Lisp_Object Qscroll_bar_movement
;
421 Lisp_Object Qswitch_frame
;
422 Lisp_Object Qdelete_frame
;
423 Lisp_Object Qiconify_frame
;
424 Lisp_Object Qmake_frame_visible
;
426 /* Symbols to denote kinds of events. */
427 Lisp_Object Qfunction_key
;
428 Lisp_Object Qmouse_click
;
429 /* Lisp_Object Qmouse_movement; - also an event header */
431 /* Properties of event headers. */
432 Lisp_Object Qevent_kind
;
433 Lisp_Object Qevent_symbol_elements
;
435 Lisp_Object Qmenu_enable
;
437 /* An event header symbol HEAD may have a property named
438 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
439 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
440 mask of modifiers applied to it. If present, this is used to help
441 speed up parse_modifiers. */
442 Lisp_Object Qevent_symbol_element_mask
;
444 /* An unmodified event header BASE may have a property named
445 Qmodifier_cache, which is an alist mapping modifier masks onto
446 modified versions of BASE. If present, this helps speed up
448 Lisp_Object Qmodifier_cache
;
450 /* Symbols to use for parts of windows. */
451 Lisp_Object Qmode_line
;
452 Lisp_Object Qvertical_line
;
453 Lisp_Object Qvertical_scroll_bar
;
454 Lisp_Object Qmenu_bar
;
456 extern Lisp_Object Qmenu_enable
;
458 Lisp_Object
recursive_edit_unwind (), command_loop ();
459 Lisp_Object
Fthis_command_keys ();
460 Lisp_Object Qextended_command_history
;
462 extern char *x_get_keysym_name ();
464 Lisp_Object Qpolling_period
;
466 extern Lisp_Object Vprint_level
, Vprint_length
;
468 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
470 EMACS_TIME
*input_available_clear_time
;
472 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
473 Default is 1 if INTERRUPT_INPUT is defined. */
476 /* Nonzero while interrupts are temporarily deferred during redisplay. */
477 int interrupts_deferred
;
479 /* nonzero means use ^S/^Q for flow control. */
482 /* Allow m- file to inhibit use of FIONREAD. */
483 #ifdef BROKEN_FIONREAD
487 /* We are unable to use interrupts if FIONREAD is not available,
488 so flush SIGIO so we won't try. */
495 /* If we support X Windows, turn on the code to poll periodically
496 to detect C-g. It isn't actually used when doing interrupt input. */
497 #ifdef HAVE_X_WINDOWS
498 #define POLL_FOR_INPUT
501 /* Global variable declarations. */
503 /* Function for init_keyboard to call with no args (if nonzero). */
504 void (*keyboard_init_hook
) ();
506 static int read_avail_input ();
507 static void get_input_pending ();
508 static int readable_events ();
509 static Lisp_Object
read_char_x_menu_prompt ();
510 static Lisp_Object
read_char_minibuf_menu_prompt ();
511 static Lisp_Object
make_lispy_event ();
513 static Lisp_Object
make_lispy_movement ();
515 static Lisp_Object
modify_event_symbol ();
516 static Lisp_Object
make_lispy_switch_frame ();
517 static int parse_solitary_modifier ();
519 /* > 0 if we are to echo keystrokes. */
520 static int echo_keystrokes
;
522 /* Nonzero means don't try to suspend even if the operating system seems
524 static int cannot_suspend
;
526 #define min(a,b) ((a)<(b)?(a):(b))
527 #define max(a,b) ((a)>(b)?(a):(b))
529 /* Install the string STR as the beginning of the string of echoing,
530 so that it serves as a prompt for the next character.
531 Also start echoing. */
536 int len
= strlen (str
);
538 if (len
> ECHOBUFSIZE
- 4)
539 len
= ECHOBUFSIZE
- 4;
540 bcopy (str
, current_kboard
->echobuf
, len
);
541 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
542 *current_kboard
->echoptr
= '\0';
544 current_kboard
->echo_after_prompt
= len
;
549 /* Add C to the echo string, if echoing is going on.
550 C can be a character, which is printed prettily ("M-C-x" and all that
551 jazz), or a symbol, whose name is printed. */
556 extern char *push_key_description ();
558 if (current_kboard
->immediate_echo
)
560 char *ptr
= current_kboard
->echoptr
;
562 if (ptr
!= current_kboard
->echobuf
)
565 /* If someone has passed us a composite event, use its head symbol. */
570 if (ptr
- current_kboard
->echobuf
> ECHOBUFSIZE
- 6)
573 ptr
= push_key_description (XINT (c
), ptr
);
575 else if (SYMBOLP (c
))
577 struct Lisp_String
*name
= XSYMBOL (c
)->name
;
578 if ((ptr
- current_kboard
->echobuf
) + name
->size
+ 4 > ECHOBUFSIZE
)
580 bcopy (name
->data
, ptr
, name
->size
);
584 if (current_kboard
->echoptr
== current_kboard
->echobuf
587 strcpy (ptr
, " (Type ? for further options)");
592 current_kboard
->echoptr
= ptr
;
598 /* Temporarily add a dash to the end of the echo string if it's not
599 empty, so that it serves as a mini-prompt for the very next character. */
603 if (!current_kboard
->immediate_echo
604 && current_kboard
->echoptr
== current_kboard
->echobuf
)
606 /* Do nothing if we just printed a prompt. */
607 if (current_kboard
->echo_after_prompt
608 == current_kboard
->echoptr
- current_kboard
->echobuf
)
610 /* Do nothing if not echoing at all. */
611 if (current_kboard
->echoptr
== 0)
614 /* Put a dash at the end of the buffer temporarily,
615 but make it go away when the next character is added. */
616 current_kboard
->echoptr
[0] = '-';
617 current_kboard
->echoptr
[1] = 0;
622 /* Display the current echo string, and begin echoing if not already
627 if (!current_kboard
->immediate_echo
)
630 current_kboard
->immediate_echo
= 1;
632 for (i
= 0; i
< this_command_key_count
; i
++)
635 c
= XVECTOR (this_command_keys
)->contents
[i
];
636 if (! (EVENT_HAS_PARAMETERS (c
)
637 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
644 message1_nolog (current_kboard
->echobuf
);
647 if (waiting_for_input
&& !NILP (Vquit_flag
))
648 quit_throw_to_read_char ();
651 /* Turn off echoing, for the start of a new command. */
655 current_kboard
->immediate_echo
= 0;
656 current_kboard
->echoptr
= current_kboard
->echobuf
;
657 current_kboard
->echo_after_prompt
= -1;
660 /* Return the length of the current echo string. */
665 return current_kboard
->echoptr
- current_kboard
->echobuf
;
668 /* Truncate the current echo message to its first LEN chars.
669 This and echo_char get used by read_key_sequence when the user
670 switches frames while entering a key sequence. */
676 current_kboard
->echobuf
[len
] = '\0';
677 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
678 truncate_echo_area (len
);
682 /* Functions for manipulating this_command_keys. */
684 add_command_key (key
)
687 int size
= XVECTOR (this_command_keys
)->size
;
689 /* If reset-this-command-length was called recently, obey it now.
690 See the doc string of that function for an explanation of why. */
691 if (before_command_restore_flag
)
693 this_command_key_count
= before_command_key_count_1
;
694 echo_truncate (before_command_echo_length_1
);
695 before_command_restore_flag
= 0;
698 if (this_command_key_count
>= size
)
700 Lisp_Object new_keys
;
702 new_keys
= Fmake_vector (make_number (size
* 2), Qnil
);
703 bcopy (XVECTOR (this_command_keys
)->contents
,
704 XVECTOR (new_keys
)->contents
,
705 size
* sizeof (Lisp_Object
));
707 this_command_keys
= new_keys
;
710 XVECTOR (this_command_keys
)->contents
[this_command_key_count
++] = key
;
716 int count
= specpdl_ptr
- specpdl
;
719 if (command_loop_level
> 0)
721 specbind (Qstandard_output
, Qt
);
722 specbind (Qstandard_input
, Qt
);
725 val
= command_loop ();
727 Fsignal (Qquit
, Qnil
);
729 return unbind_to (count
, Qnil
);
732 /* When an auto-save happens, record the "time", and don't do again soon. */
736 last_auto_save
= num_nonmacro_input_chars
;
739 /* Make an auto save happen as soon as possible at command level. */
741 force_auto_save_soon ()
743 last_auto_save
= - auto_save_interval
- 1;
745 record_asynch_buffer_change ();
748 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
749 "Invoke the editor command loop recursively.\n\
750 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
751 that tells this function to return.\n\
752 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
753 This function is called by the editor initialization to begin editing.")
756 int count
= specpdl_ptr
- specpdl
;
759 command_loop_level
++;
760 update_mode_lines
= 1;
762 record_unwind_protect (recursive_edit_unwind
,
764 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
768 return unbind_to (count
, Qnil
);
772 recursive_edit_unwind (buffer
)
776 Fset_buffer (buffer
);
778 command_loop_level
--;
779 update_mode_lines
= 1;
787 #if 0 /* Theory: if there's anything in Vunread_command_events,
788 it will right away be read by read_key_sequence,
789 and then if we do switch KBOARDS, it will go into the side
790 queue then. So we don't need to do anything special here -- rms. */
791 if (CONSP (Vunread_command_events
))
793 current_kboard
->kbd_queue
794 = nconc2 (Vunread_command_events
, current_kboard
->kbd_queue
);
795 current_kboard
->kbd_queue_has_data
= 1;
797 Vunread_command_events
= Qnil
;
803 /* Switch to the single-kboard state, making current_kboard
804 the only KBOARD from which further input is accepted. */
807 single_kboard_state ()
814 /* Maintain a stack of kboards, so other parts of Emacs
815 can switch temporarily to the kboard of a given frame
816 and then revert to the previous status. */
821 struct kboard_stack
*next
;
824 static struct kboard_stack
*kboard_stack
;
827 push_frame_kboard (f
)
831 struct kboard_stack
*p
832 = (struct kboard_stack
*) xmalloc (sizeof (struct kboard_stack
));
834 p
->next
= kboard_stack
;
835 p
->kboard
= current_kboard
;
838 current_kboard
= FRAME_KBOARD (f
);
846 struct kboard_stack
*p
= kboard_stack
;
847 current_kboard
= p
->kboard
;
848 kboard_stack
= p
->next
;
853 /* Handle errors that are not handled at inner levels
854 by printing an error message and returning to the editor command loop. */
860 Lisp_Object old_level
, old_length
;
862 Vstandard_output
= Qt
;
863 Vstandard_input
= Qt
;
864 Vexecuting_macro
= Qnil
;
865 current_kboard
->Vprefix_arg
= Qnil
;
868 /* Avoid unquittable loop if data contains a circular list. */
869 old_level
= Vprint_level
;
870 old_length
= Vprint_length
;
871 XSETFASTINT(Vprint_level
, 10);
872 XSETFASTINT(Vprint_length
, 10);
873 cmd_error_internal (data
, NULL
);
874 Vprint_level
= old_level
;
875 Vprint_length
= old_length
;
879 Vinhibit_quit
= Qnil
;
884 return make_number (0);
887 cmd_error_internal (data
, context
)
891 Lisp_Object errmsg
, tail
, errname
, file_error
;
898 echo_area_glyphs
= 0;
900 /* If the window system or terminal frame hasn't been initialized
901 yet, or we're not interactive, it's best to dump this message out
902 to stderr and exit. */
903 if (! FRAME_MESSAGE_BUF (selected_frame
)
905 stream
= Qexternal_debugging_output
;
914 write_string_1 (context
, -1, stream
);
916 errname
= Fcar (data
);
918 if (EQ (errname
, Qerror
))
921 if (!CONSP (data
)) data
= Qnil
;
922 errmsg
= Fcar (data
);
927 errmsg
= Fget (errname
, Qerror_message
);
928 file_error
= Fmemq (Qfile_error
,
929 Fget (errname
, Qerror_conditions
));
932 /* Print an error message including the data items.
933 This is done by printing it into a scratch buffer
934 and then making a copy of the text in the buffer. */
936 if (!CONSP (data
)) data
= Qnil
;
940 /* For file-error, make error message by concatenating
941 all the data items. They are all strings. */
942 if (!NILP (file_error
) && !NILP (tail
))
943 errmsg
= XCONS (tail
)->car
, tail
= XCONS (tail
)->cdr
;
945 if (STRINGP (errmsg
))
946 Fprinc (errmsg
, stream
);
948 write_string_1 ("peculiar error", -1, stream
);
950 for (i
= 0; CONSP (tail
); tail
= Fcdr (tail
), i
++)
952 write_string_1 (i
? ", " : ": ", 2, stream
);
953 if (!NILP (file_error
))
954 Fprinc (Fcar (tail
), stream
);
956 Fprin1 (Fcar (tail
), stream
);
960 /* If the window system or terminal frame hasn't been initialized
961 yet, or we're in -batch mode, this error should cause Emacs to exit. */
962 if (! FRAME_MESSAGE_BUF (selected_frame
)
966 Fkill_emacs (make_number (-1));
970 Lisp_Object
command_loop_1 ();
971 Lisp_Object
command_loop_2 ();
972 Lisp_Object
top_level_1 ();
974 /* Entry to editor-command-loop.
975 This level has the catches for exiting/returning to editor command loop.
976 It returns nil to exit recursive edit, t to abort it. */
981 if (command_loop_level
> 0 || minibuf_level
> 0)
983 return internal_catch (Qexit
, command_loop_2
, Qnil
);
988 internal_catch (Qtop_level
, top_level_1
, Qnil
);
989 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
991 /* End of file in -batch run causes exit here. */
997 /* Here we catch errors in execution of commands within the
998 editing loop, and reenter the editing loop.
999 When there is an error, cmd_error runs and returns a non-nil
1000 value to us. A value of nil means that cmd_loop_1 itself
1001 returned due to end of file (or end of kbd macro). */
1006 register Lisp_Object val
;
1009 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
1010 while (!NILP (val
));
1018 return Feval (Vtop_level
);
1024 /* On entry to the outer level, run the startup file */
1025 if (!NILP (Vtop_level
))
1026 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
1027 else if (!NILP (Vpurify_flag
))
1028 message ("Bare impure Emacs (standard Lisp code not loaded)");
1030 message ("Bare Emacs (standard Lisp code not loaded)");
1034 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
1035 "Exit all recursive editing levels.")
1038 Fthrow (Qtop_level
, Qnil
);
1041 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
1042 "Exit from the innermost recursive edit or minibuffer.")
1045 if (command_loop_level
> 0 || minibuf_level
> 0)
1046 Fthrow (Qexit
, Qnil
);
1048 error ("No recursive edit is in progress");
1051 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
1052 "Abort the command that requested this recursive edit or minibuffer input.")
1055 if (command_loop_level
> 0 || minibuf_level
> 0)
1058 error ("No recursive edit is in progress");
1061 /* This is the actual command reading loop,
1062 sans error-handling encapsulation. */
1064 Lisp_Object
Fcommand_execute ();
1065 static int read_key_sequence ();
1066 void safe_run_hooks ();
1071 Lisp_Object cmd
, tem
;
1074 Lisp_Object keybuf
[30];
1079 struct buffer
*prev_buffer
;
1081 int was_locked
= single_kboard
;
1084 current_kboard
->Vprefix_arg
= Qnil
;
1085 Vdeactivate_mark
= Qnil
;
1086 waiting_for_input
= 0;
1091 this_command_key_count
= 0;
1093 /* Make sure this hook runs after commands that get errors and
1094 throw to top level. */
1095 /* Note that the value cell will never directly contain nil
1096 if the symbol is a local variable. */
1097 if (!NILP (XSYMBOL (Qpost_command_hook
)->value
) && !NILP (Vrun_hooks
))
1098 safe_run_hooks (Qpost_command_hook
);
1100 if (!NILP (Vdeferred_action_list
))
1101 call0 (Vdeferred_action_function
);
1103 if (!NILP (XSYMBOL (Qpost_command_idle_hook
)->value
) && !NILP (Vrun_hooks
))
1105 if (NILP (Vunread_command_events
)
1106 && NILP (Vexecuting_macro
)
1107 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1)))
1108 safe_run_hooks (Qpost_command_idle_hook
);
1111 /* Do this after running Vpost_command_hook, for consistency. */
1112 current_kboard
->Vlast_command
= this_command
;
1116 /* Make sure the current window's buffer is selected. */
1117 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1118 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1120 /* Display any malloc warning that just came out. Use while because
1121 displaying one warning can cause another. */
1123 while (pending_malloc_warning
)
1124 display_malloc_warning ();
1128 Vdeactivate_mark
= Qnil
;
1130 /* If minibuffer on and echo area in use,
1131 wait 2 sec and redraw minibuffer. */
1133 if (minibuf_level
&& echo_area_glyphs
1134 && EQ (minibuf_window
, echo_area_window
))
1136 /* Bind inhibit-quit to t so that C-g gets read in
1137 rather than quitting back to the minibuffer. */
1138 int count
= specpdl_ptr
- specpdl
;
1139 specbind (Qinhibit_quit
, Qt
);
1140 Fsit_for (make_number (2), Qnil
, Qnil
);
1141 unbind_to (count
, Qnil
);
1143 echo_area_glyphs
= 0;
1145 if (!NILP (Vquit_flag
))
1148 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1153 alloca (0); /* Cause a garbage collection now */
1154 /* Since we can free the most stuff here. */
1155 #endif /* C_ALLOCA */
1159 /* Select the frame that the last event came from. Usually,
1160 switch-frame events will take care of this, but if some lisp
1161 code swallows a switch-frame event, we'll fix things up here.
1162 Is this a good idea? */
1163 if (FRAMEP (internal_last_event_frame
)
1164 && XFRAME (internal_last_event_frame
) != selected_frame
)
1165 Fselect_frame (internal_last_event_frame
, Qnil
);
1168 /* If it has changed current-menubar from previous value,
1169 really recompute the menubar from the value. */
1170 if (! NILP (Vlucid_menu_bar_dirty_flag
)
1171 && !NILP (Ffboundp (Qrecompute_lucid_menubar
)))
1172 call0 (Qrecompute_lucid_menubar
);
1174 before_command_key_count
= this_command_key_count
;
1175 before_command_echo_length
= echo_length ();
1177 this_command
= Qnil
;
1179 /* Read next key sequence; i gets its length. */
1180 i
= read_key_sequence (keybuf
, sizeof keybuf
/ sizeof keybuf
[0],
1185 /* Now we have read a key sequence of length I,
1186 or else I is 0 and we found end of file. */
1188 if (i
== 0) /* End of file -- happens only in */
1189 return Qnil
; /* a kbd macro, at the end. */
1190 /* -1 means read_key_sequence got a menu that was rejected.
1191 Just loop around and read another command. */
1195 this_command_key_count
= 0;
1199 last_command_char
= keybuf
[i
- 1];
1201 /* If the previous command tried to force a specific window-start,
1202 forget about that, in case this command moves point far away
1203 from that position. But also throw away beg_unchanged and
1204 end_unchanged information in that case, so that redisplay will
1205 update the whole window properly. */
1206 if (!NILP (XWINDOW (selected_window
)->force_start
))
1208 XWINDOW (selected_window
)->force_start
= Qnil
;
1209 beg_unchanged
= end_unchanged
= 0;
1212 cmd
= read_key_sequence_cmd
;
1213 if (!NILP (Vexecuting_macro
))
1215 if (!NILP (Vquit_flag
))
1217 Vexecuting_macro
= Qt
;
1218 QUIT
; /* Make some noise. */
1219 /* Will return since macro now empty. */
1223 /* Do redisplay processing after this command except in special
1224 cases identified below that set no_redisplay to 1.
1225 (actually, there's currently no way to prevent the redisplay,
1226 and no_redisplay is ignored.
1227 Perhaps someday we will really implement it.) */
1230 prev_buffer
= current_buffer
;
1231 prev_modiff
= MODIFF
;
1232 last_point_position
= PT
;
1233 XSETBUFFER (last_point_position_buffer
, prev_buffer
);
1235 /* Execute the command. */
1238 /* Note that the value cell will never directly contain nil
1239 if the symbol is a local variable. */
1240 if (!NILP (XSYMBOL (Qpre_command_hook
)->value
) && !NILP (Vrun_hooks
))
1241 safe_run_hooks (Qpre_command_hook
);
1243 if (NILP (this_command
))
1245 /* nil means key is undefined. */
1247 current_kboard
->defining_kbd_macro
= Qnil
;
1248 update_mode_lines
= 1;
1249 current_kboard
->Vprefix_arg
= Qnil
;
1253 if (NILP (current_kboard
->Vprefix_arg
) && ! no_direct
)
1255 /* Recognize some common commands in common situations and
1256 do them directly. */
1257 if (EQ (this_command
, Qforward_char
) && PT
< ZV
)
1259 struct Lisp_Char_Table
*dp
1260 = window_display_table (XWINDOW (selected_window
));
1261 lose
= FETCH_CHAR (PT
);
1264 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1265 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1266 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1267 && (lose
>= 0x20 && lose
< 0x7f)))
1268 : (lose
>= 0x20 && lose
< 0x7f))
1269 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1271 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1273 && !windows_or_buffers_changed
1274 && EQ (current_buffer
->selective_display
, Qnil
)
1275 && !detect_input_pending ()
1276 && NILP (Vexecuting_macro
))
1277 no_redisplay
= direct_output_forward_char (1);
1280 else if (EQ (this_command
, Qbackward_char
) && PT
> BEGV
)
1282 struct Lisp_Char_Table
*dp
1283 = window_display_table (XWINDOW (selected_window
));
1285 lose
= FETCH_CHAR (PT
);
1287 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1288 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1289 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1290 && (lose
>= 0x20 && lose
< 0x7f)))
1291 : (lose
>= 0x20 && lose
< 0x7f))
1292 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1294 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1296 && !windows_or_buffers_changed
1297 && EQ (current_buffer
->selective_display
, Qnil
)
1298 && !detect_input_pending ()
1299 && NILP (Vexecuting_macro
))
1300 no_redisplay
= direct_output_forward_char (-1);
1303 else if (EQ (this_command
, Qself_insert_command
)
1304 /* Try this optimization only on ascii keystrokes. */
1305 && INTEGERP (last_command_char
))
1307 unsigned char c
= XINT (last_command_char
);
1310 if (NILP (Vexecuting_macro
)
1311 && !EQ (minibuf_window
, selected_window
))
1313 if (!nonundocount
|| nonundocount
>= 20)
1320 lose
= ((XFASTINT (XWINDOW (selected_window
)->last_modified
)
1322 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1324 || MODIFF
<= SAVE_MODIFF
1325 || windows_or_buffers_changed
1326 || !EQ (current_buffer
->selective_display
, Qnil
)
1327 || detect_input_pending ()
1328 || !NILP (Vexecuting_macro
));
1329 value
= internal_self_insert (c
, 0);
1336 && (PT
== ZV
|| FETCH_CHAR (PT
) == '\n'))
1338 struct Lisp_Char_Table
*dp
1339 = window_display_table (XWINDOW (selected_window
));
1346 obj
= DISP_CHAR_VECTOR (dp
, lose
);
1349 /* Do it only for char codes
1350 that by default display as themselves. */
1351 if (lose
>= 0x20 && lose
<= 0x7e)
1352 no_redisplay
= direct_output_for_insert (lose
);
1354 else if (VECTORP (obj
)
1355 && XVECTOR (obj
)->size
== 1
1356 && (obj
= XVECTOR (obj
)->contents
[0],
1358 /* Insist face not specified in glyph. */
1359 && (XINT (obj
) & ((-1) << 8)) == 0)
1361 = direct_output_for_insert (XINT (obj
));
1365 if (lose
>= 0x20 && lose
<= 0x7e)
1366 no_redisplay
= direct_output_for_insert (lose
);
1373 /* Here for a command that isn't executed directly */
1376 if (NILP (current_kboard
->Vprefix_arg
))
1378 Fcommand_execute (this_command
, Qnil
);
1383 /* Note that the value cell will never directly contain nil
1384 if the symbol is a local variable. */
1385 if (!NILP (XSYMBOL (Qpost_command_hook
)->value
) && !NILP (Vrun_hooks
))
1386 safe_run_hooks (Qpost_command_hook
);
1388 if (!NILP (Vdeferred_action_list
))
1389 safe_run_hooks (Qdeferred_action_function
);
1391 if (!NILP (XSYMBOL (Qpost_command_idle_hook
)->value
)
1392 && !NILP (Vrun_hooks
))
1394 if (NILP (Vunread_command_events
)
1395 && NILP (Vexecuting_macro
)
1396 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1)))
1397 safe_run_hooks (Qpost_command_idle_hook
);
1400 /* If there is a prefix argument,
1401 1) We don't want Vlast_command to be ``universal-argument''
1402 (that would be dumb), so don't set Vlast_command,
1403 2) we want to leave echoing on so that the prefix will be
1404 echoed as part of this key sequence, so don't call
1406 3) we want to leave this_command_key_count non-zero, so that
1407 read_char will realize that it is re-reading a character, and
1408 not echo it a second time.
1410 If the command didn't actually create a prefix arg,
1411 but is merely a frame event that is transparent to prefix args,
1412 then the above doesn't apply. */
1413 if (NILP (current_kboard
->Vprefix_arg
) || CONSP (last_command_char
))
1415 current_kboard
->Vlast_command
= this_command
;
1417 this_command_key_count
= 0;
1420 if (!NILP (current_buffer
->mark_active
) && !NILP (Vrun_hooks
))
1422 if (!NILP (Vdeactivate_mark
) && !NILP (Vtransient_mark_mode
))
1424 current_buffer
->mark_active
= Qnil
;
1425 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
1427 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
1428 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
1432 /* Install chars successfully executed in kbd macro. */
1434 if (!NILP (current_kboard
->defining_kbd_macro
)
1435 && NILP (current_kboard
->Vprefix_arg
))
1436 finalize_kbd_macro_chars ();
1440 any_kboard_state ();
1445 /* Subroutine for safe_run_hooks: run the hook HOOK. */
1448 safe_run_hooks_1 (hook
)
1451 return call1 (Vrun_hooks
, Vinhibit_quit
);
1454 /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */
1457 safe_run_hooks_error (data
)
1460 Fset (Vinhibit_quit
, Qnil
);
1463 /* If we get an error while running the hook, cause the hook variable
1464 to be nil. Also inhibit quits, so that C-g won't cause the hook
1465 to mysteriously evaporate. */
1468 safe_run_hooks (hook
)
1472 int count
= specpdl_ptr
- specpdl
;
1473 specbind (Qinhibit_quit
, hook
);
1475 internal_condition_case (safe_run_hooks_1
, Qerror
, safe_run_hooks_error
);
1477 unbind_to (count
, Qnil
);
1480 /* Number of seconds between polling for input. */
1483 /* Nonzero means polling for input is temporarily suppressed. */
1484 int poll_suppress_count
;
1486 /* Nonzero if polling_for_input is actually being used. */
1487 int polling_for_input
;
1489 #ifdef POLL_FOR_INPUT
1491 /* Handle an alarm once each second and read pending input
1492 so as to handle a C-g if it comces in. */
1495 input_poll_signal (signalnum
) /* If we don't have an argument, */
1496 int signalnum
; /* some compilers complain in signal calls. */
1498 if (interrupt_input_blocked
== 0
1499 && !waiting_for_input
)
1500 read_avail_input (0);
1501 signal (SIGALRM
, input_poll_signal
);
1502 alarm (polling_period
);
1507 /* Begin signals to poll for input, if they are appropriate.
1508 This function is called unconditionally from various places. */
1512 #ifdef POLL_FOR_INPUT
1513 if (read_socket_hook
&& !interrupt_input
)
1515 poll_suppress_count
--;
1516 if (poll_suppress_count
== 0)
1518 signal (SIGALRM
, input_poll_signal
);
1519 polling_for_input
= 1;
1520 alarm (polling_period
);
1526 /* Nonzero if we are using polling to handle input asynchronously. */
1529 input_polling_used ()
1531 #ifdef POLL_FOR_INPUT
1532 return read_socket_hook
&& !interrupt_input
;
1538 /* Turn off polling. */
1542 #ifdef POLL_FOR_INPUT
1543 if (read_socket_hook
&& !interrupt_input
)
1545 if (poll_suppress_count
== 0)
1547 polling_for_input
= 0;
1550 poll_suppress_count
++;
1555 /* Set the value of poll_suppress_count to COUNT
1556 and start or stop polling accordingly. */
1559 set_poll_suppress_count (count
)
1562 #ifdef POLL_FOR_INPUT
1563 if (count
== 0 && poll_suppress_count
!= 0)
1565 poll_suppress_count
= 1;
1568 else if (count
!= 0 && poll_suppress_count
== 0)
1572 poll_suppress_count
= count
;
1576 /* Bind polling_period to a value at least N.
1577 But don't decrease it. */
1579 bind_polling_period (n
)
1582 #ifdef POLL_FOR_INPUT
1583 int new = polling_period
;
1589 specbind (Qpolling_period
, make_number (new));
1590 /* Start a new alarm with the new period. */
1595 /* Apply the control modifier to CHARACTER. */
1601 /* Save the upper bits here. */
1602 int upper
= c
& ~0177;
1606 /* Everything in the columns containing the upper-case letters
1607 denotes a control character. */
1608 if (c
>= 0100 && c
< 0140)
1612 /* Set the shift modifier for a control char
1613 made from a shifted letter. But only for letters! */
1614 if (oc
>= 'A' && oc
<= 'Z')
1615 c
|= shift_modifier
;
1618 /* The lower-case letters denote control characters too. */
1619 else if (c
>= 'a' && c
<= 'z')
1622 /* Include the bits for control and shift
1623 only if the basic ASCII code can't indicate them. */
1627 /* Replace the high bits. */
1628 c
|= (upper
& ~ctrl_modifier
);
1635 /* Input of single characters from keyboard */
1637 Lisp_Object
print_help ();
1638 static Lisp_Object
kbd_buffer_get_event ();
1639 static void record_char ();
1642 static jmp_buf wrong_kboard_jmpbuf
;
1645 /* read a character from the keyboard; call the redisplay if needed */
1646 /* commandflag 0 means do not do auto-saving, but do do redisplay.
1647 -1 means do not do redisplay, but do do autosaving.
1650 /* The arguments MAPS and NMAPS are for menu prompting.
1651 MAPS is an array of keymaps; NMAPS is the length of MAPS.
1653 PREV_EVENT is the previous input event, or nil if we are reading
1654 the first event of a key sequence.
1656 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
1657 if we used a mouse menu to read the input, or zero otherwise. If
1658 USED_MOUSE_MENU is null, we don't dereference it.
1660 Value is t if we showed a menu and the user rejected it. */
1663 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
)
1667 Lisp_Object prev_event
;
1668 int *used_mouse_menu
;
1670 register Lisp_Object c
;
1672 jmp_buf local_getcjmp
;
1674 int key_already_recorded
= 0;
1675 Lisp_Object tem
, save
;
1676 Lisp_Object also_record
;
1679 before_command_key_count
= this_command_key_count
;
1680 before_command_echo_length
= echo_length ();
1684 if (CONSP (Vunread_command_events
))
1686 c
= XCONS (Vunread_command_events
)->car
;
1687 Vunread_command_events
= XCONS (Vunread_command_events
)->cdr
;
1689 if (this_command_key_count
== 0)
1695 if (unread_command_char
!= -1)
1697 XSETINT (c
, unread_command_char
);
1698 unread_command_char
= -1;
1700 if (this_command_key_count
== 0)
1706 /* If there is no function key translated before
1707 reset-this-command-lengths takes effect, forget about it. */
1708 before_command_restore_flag
= 0;
1710 if (!NILP (Vexecuting_macro
))
1713 /* We set this to Qmacro; since that's not a frame, nobody will
1714 try to switch frames on us, and the selected window will
1717 Since this event came from a macro, it would be misleading to
1718 leave internal_last_event_frame set to wherever the last
1719 real event came from. Normally, a switch-frame event selects
1720 internal_last_event_frame after each command is read, but
1721 events read from a macro should never cause a new frame to be
1723 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
1726 /* Exit the macro if we are at the end.
1727 Also, some things replace the macro with t
1728 to force an early exit. */
1729 if (EQ (Vexecuting_macro
, Qt
)
1730 || executing_macro_index
>= XFASTINT (Flength (Vexecuting_macro
)))
1736 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
1737 if (STRINGP (Vexecuting_macro
)
1738 && (XINT (c
) & 0x80))
1739 XSETFASTINT (c
, CHAR_META
| (XINT (c
) & ~0x80));
1741 executing_macro_index
++;
1746 if (!NILP (unread_switch_frame
))
1748 c
= unread_switch_frame
;
1749 unread_switch_frame
= Qnil
;
1751 /* This event should make it into this_command_keys, and get echoed
1752 again, so we go to reread_first, rather than reread. */
1756 if (commandflag
>= 0 && !input_pending
&& !detect_input_pending ())
1759 /* Message turns off echoing unless more keystrokes turn it on again. */
1760 if (echo_area_glyphs
&& *echo_area_glyphs
1761 && echo_area_glyphs
!= current_kboard
->echobuf
)
1764 /* If already echoing, continue. */
1767 /* Try reading a character via menu prompting in the minibuf.
1768 Try this before the sit-for, because the sit-for
1769 would do the wrong thing if we are supposed to do
1770 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
1771 after a mouse event so don't try a minibuf menu. */
1773 if (nmaps
> 0 && INTERACTIVE
1774 && !NILP (prev_event
) && ! EVENT_HAS_PARAMETERS (prev_event
)
1775 /* Don't bring up a menu if we already have another event. */
1776 && NILP (Vunread_command_events
)
1777 && unread_command_char
< 0
1778 && !detect_input_pending ())
1780 c
= read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
);
1783 key_already_recorded
= 1;
1788 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet.
1789 We will do that below, temporarily for short sections of code,
1790 when appropriate. local_getcjmp must be in effect
1791 around any call to sit_for or kbd_buffer_get_event;
1792 it *must not* be in effect when we call redisplay. */
1794 if (_setjmp (local_getcjmp
))
1796 XSETINT (c
, quit_char
);
1798 XSETFRAME (internal_last_event_frame
, selected_frame
);
1799 Vlast_event_frame
= internal_last_event_frame
;
1801 /* If we report the quit char as an event,
1802 don't do so more than once. */
1803 if (!NILP (Vinhibit_quit
))
1808 KBOARD
*kb
= FRAME_KBOARD (selected_frame
);
1809 if (kb
!= current_kboard
)
1811 Lisp_Object
*tailp
= &kb
->kbd_queue
;
1812 /* We shouldn't get here if we were in single-kboard mode! */
1815 while (CONSP (*tailp
))
1816 tailp
= &XCONS (*tailp
)->cdr
;
1819 *tailp
= Fcons (c
, Qnil
);
1820 kb
->kbd_queue_has_data
= 1;
1821 current_kboard
= kb
;
1822 longjmp (wrong_kboard_jmpbuf
, 1);
1829 /* If in middle of key sequence and minibuffer not active,
1830 start echoing if enough time elapses. */
1832 if (minibuf_level
== 0 && !current_kboard
->immediate_echo
1833 && this_command_key_count
> 0
1835 && echo_keystrokes
> 0
1836 && (echo_area_glyphs
== 0 || *echo_area_glyphs
== 0))
1840 /* After a mouse event, start echoing right away.
1841 This is because we are probably about to display a menu,
1842 and we don't want to delay before doing so. */
1843 if (EVENT_HAS_PARAMETERS (prev_event
))
1847 save_getcjmp (save_jump
);
1848 restore_getcjmp (local_getcjmp
);
1849 tem0
= sit_for (echo_keystrokes
, 0, 1, 1);
1850 restore_getcjmp (save_jump
);
1856 /* Maybe auto save due to number of keystrokes. */
1858 if (commandflag
!= 0
1859 && auto_save_interval
> 0
1860 && num_nonmacro_input_chars
- last_auto_save
> max (auto_save_interval
, 20)
1861 && !detect_input_pending ())
1863 Fdo_auto_save (Qnil
, Qnil
);
1864 /* Hooks can actually change some buffers in auto save. */
1868 /* Try reading using an X menu.
1869 This is never confused with reading using the minibuf
1870 because the recursive call of read_char in read_char_minibuf_menu_prompt
1871 does not pass on any keymaps. */
1873 if (nmaps
> 0 && INTERACTIVE
1874 && !NILP (prev_event
)
1875 && EVENT_HAS_PARAMETERS (prev_event
)
1876 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
)
1877 /* Don't bring up a menu if we already have another event. */
1878 && NILP (Vunread_command_events
)
1879 && unread_command_char
< 0)
1880 c
= read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
1882 /* Maybe autosave and/or garbage collect due to idleness. */
1884 if (INTERACTIVE
&& NILP (c
))
1886 int delay_level
, buffer_size
;
1888 /* Slow down auto saves logarithmically in size of current buffer,
1889 and garbage collect while we're at it. */
1890 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
1891 last_non_minibuf_size
= Z
- BEG
;
1892 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
1894 while (buffer_size
> 64)
1895 delay_level
++, buffer_size
-= buffer_size
>> 2;
1896 if (delay_level
< 4) delay_level
= 4;
1897 /* delay_level is 4 for files under around 50k, 7 at 100k,
1898 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
1900 /* Auto save if enough time goes by without input. */
1901 if (commandflag
!= 0
1902 && num_nonmacro_input_chars
> last_auto_save
1903 && INTEGERP (Vauto_save_timeout
)
1904 && XINT (Vauto_save_timeout
) > 0)
1907 int delay
= delay_level
* XFASTINT (Vauto_save_timeout
) / 4;
1909 save_getcjmp (save_jump
);
1910 restore_getcjmp (local_getcjmp
);
1911 tem0
= sit_for (delay
, 0, 1, 1);
1912 restore_getcjmp (save_jump
);
1916 Fdo_auto_save (Qnil
, Qnil
);
1918 /* If we have auto-saved and there is still no input
1919 available, garbage collect if there has been enough
1920 consing going on to make it worthwhile. */
1921 if (!detect_input_pending ()
1922 && consing_since_gc
> gc_cons_threshold
/ 2)
1923 Fgarbage_collect ();
1930 /* Read something from current KBOARD's side queue, if possible. */
1934 if (current_kboard
->kbd_queue_has_data
)
1936 if (!CONSP (current_kboard
->kbd_queue
))
1938 c
= XCONS (current_kboard
->kbd_queue
)->car
;
1939 current_kboard
->kbd_queue
1940 = XCONS (current_kboard
->kbd_queue
)->cdr
;
1941 if (NILP (current_kboard
->kbd_queue
))
1942 current_kboard
->kbd_queue_has_data
= 0;
1943 input_pending
= readable_events ();
1945 if (EVENT_HAS_PARAMETERS (c
)
1946 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qswitch_frame
))
1947 internal_last_event_frame
= XCONS (XCONS (c
)->cdr
)->car
;
1948 Vlast_event_frame
= internal_last_event_frame
;
1954 /* If current_kboard's side queue is empty check the other kboards.
1955 If one of them has data that we have not yet seen here,
1956 switch to it and process the data waiting for it.
1958 Note: if the events queued up for another kboard
1959 have already been seen here, and therefore are not a complete command,
1960 the kbd_queue_has_data field is 0, so we skip that kboard here.
1961 That's to avoid an infinite loop switching between kboards here. */
1962 if (NILP (c
) && !single_kboard
)
1965 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
1966 if (kb
->kbd_queue_has_data
)
1968 current_kboard
= kb
;
1969 longjmp (wrong_kboard_jmpbuf
, 1);
1978 /* Finally, we read from the main queue,
1979 and if that gives us something we can't use yet, we put it on the
1980 appropriate side queue and try again. */
1986 /* Actually read a character, waiting if necessary. */
1987 save_getcjmp (save_jump
);
1988 restore_getcjmp (local_getcjmp
);
1989 c
= kbd_buffer_get_event (&kb
, used_mouse_menu
);
1990 restore_getcjmp (save_jump
);
1993 if (! NILP (c
) && (kb
!= current_kboard
))
1995 Lisp_Object
*tailp
= &kb
->kbd_queue
;
1996 while (CONSP (*tailp
))
1997 tailp
= &XCONS (*tailp
)->cdr
;
2000 *tailp
= Fcons (c
, Qnil
);
2001 kb
->kbd_queue_has_data
= 1;
2005 current_kboard
= kb
;
2006 longjmp (wrong_kboard_jmpbuf
, 1);
2011 /* Terminate Emacs in batch mode if at eof. */
2012 if (noninteractive
&& INTEGERP (c
) && XINT (c
) < 0)
2013 Fkill_emacs (make_number (1));
2017 /* Add in any extra modifiers, where appropriate. */
2018 if ((extra_keyboard_modifiers
& CHAR_CTL
)
2019 || ((extra_keyboard_modifiers
& 0177) < ' '
2020 && (extra_keyboard_modifiers
& 0177) != 0))
2021 XSETINT (c
, make_ctrl_char (XINT (c
)));
2023 /* Transfer any other modifier bits directly from
2024 extra_keyboard_modifiers to c. Ignore the actual character code
2025 in the low 16 bits of extra_keyboard_modifiers. */
2026 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
2035 if (commandflag
>= 0
2036 && !input_pending
&& !detect_input_pending ())
2044 /* Buffer switch events are only for internal wakeups
2045 so don't show them to the user. */
2049 if (key_already_recorded
)
2052 /* Process special events within read_char
2053 and loop around to read another event. */
2056 tem
= get_keyelt (access_keymap (get_keymap_1 (Vspecial_event_map
, 0, 0),
2062 last_input_char
= c
;
2063 Fcommand_execute (tem
, Qnil
);
2067 /* Wipe the echo area. */
2068 echo_area_glyphs
= 0;
2070 /* Handle things that only apply to characters. */
2073 /* If kbd_buffer_get_event gave us an EOF, return that. */
2077 if (STRINGP (Vkeyboard_translate_table
)
2078 && XSTRING (Vkeyboard_translate_table
)->size
> XFASTINT (c
))
2079 XSETINT (c
, XSTRING (Vkeyboard_translate_table
)->data
[XFASTINT (c
)]);
2082 /* If this event is a mouse click in the menu bar,
2083 return just menu-bar for now. Modify the mouse click event
2084 so we won't do this twice, then queue it up. */
2085 if (EVENT_HAS_PARAMETERS (c
)
2086 && CONSP (XCONS (c
)->cdr
)
2087 && CONSP (EVENT_START (c
))
2088 && CONSP (XCONS (EVENT_START (c
))->cdr
))
2092 posn
= POSN_BUFFER_POSN (EVENT_START (c
));
2093 /* Handle menu-bar events:
2094 insert the dummy prefix event `menu-bar'. */
2095 if (EQ (posn
, Qmenu_bar
))
2097 /* Change menu-bar to (menu-bar) as the event "position". */
2098 POSN_BUFFER_POSN (EVENT_START (c
)) = Fcons (posn
, Qnil
);
2101 Vunread_command_events
= Fcons (c
, Vunread_command_events
);
2107 if (! NILP (also_record
))
2108 record_char (also_record
);
2112 before_command_key_count
= this_command_key_count
;
2113 before_command_echo_length
= echo_length ();
2115 /* Don't echo mouse motion events. */
2117 && ! (EVENT_HAS_PARAMETERS (c
)
2118 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
2121 if (! NILP (also_record
))
2122 echo_char (also_record
);
2125 /* Record this character as part of the current key. */
2126 add_command_key (c
);
2127 if (! NILP (also_record
))
2128 add_command_key (also_record
);
2130 /* Re-reading in the middle of a command */
2132 last_input_char
= c
;
2135 /* Process the help character specially if enabled */
2136 if (!NILP (Vhelp_form
) && help_char_p (c
))
2139 count
= specpdl_ptr
- specpdl
;
2141 record_unwind_protect (Fset_window_configuration
,
2142 Fcurrent_window_configuration (Qnil
));
2144 tem0
= Feval (Vhelp_form
);
2146 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
2150 c
= read_char (0, 0, 0, Qnil
, 0);
2151 while (BUFFERP (c
));
2152 /* Remove the help from the frame */
2153 unbind_to (count
, Qnil
);
2156 if (EQ (c
, make_number (040)))
2160 c
= read_char (0, 0, 0, Qnil
, 0);
2161 while (BUFFERP (c
));
2168 /* Return 1 if should recognize C as "the help character". */
2176 if (EQ (c
, Vhelp_char
))
2178 for (tail
= Vhelp_event_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
2179 if (EQ (c
, XCONS (tail
)->car
))
2184 /* Record the input event C in various ways. */
2191 XVECTOR (recent_keys
)->contents
[recent_keys_index
] = c
;
2192 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
2193 recent_keys_index
= 0;
2195 /* Write c to the dribble file. If c is a lispy event, write
2196 the event's symbol to the dribble file, in <brackets>. Bleaugh.
2197 If you, dear reader, have a better idea, you've got the source. :-) */
2202 if (XUINT (c
) < 0x100)
2203 putc (XINT (c
), dribble
);
2205 fprintf (dribble
, " 0x%x", (int) XUINT (c
));
2209 Lisp_Object dribblee
;
2211 /* If it's a structured event, take the event header. */
2212 dribblee
= EVENT_HEAD (c
);
2214 if (SYMBOLP (dribblee
))
2216 putc ('<', dribble
);
2217 fwrite (XSYMBOL (dribblee
)->name
->data
, sizeof (char),
2218 XSYMBOL (dribblee
)->name
->size
,
2220 putc ('>', dribble
);
2227 store_kbd_macro_char (c
);
2229 num_nonmacro_input_chars
++;
2236 struct buffer
*old
= current_buffer
;
2237 Fprinc (object
, Qnil
);
2238 set_buffer_internal (XBUFFER (Vstandard_output
));
2239 call0 (intern ("help-mode"));
2240 set_buffer_internal (old
);
2244 /* Copy out or in the info on where C-g should throw to.
2245 This is used when running Lisp code from within get_char,
2246 in case get_char is called recursively.
2247 See read_process_output. */
2252 bcopy (getcjmp
, temp
, sizeof getcjmp
);
2255 restore_getcjmp (temp
)
2258 bcopy (temp
, getcjmp
, sizeof getcjmp
);
2263 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
2264 of this function. */
2267 tracking_off (old_value
)
2268 Lisp_Object old_value
;
2270 do_mouse_tracking
= old_value
;
2271 if (NILP (old_value
))
2273 /* Redisplay may have been preempted because there was input
2274 available, and it assumes it will be called again after the
2275 input has been processed. If the only input available was
2276 the sort that we have just disabled, then we need to call
2278 if (!readable_events ())
2280 redisplay_preserve_echo_area ();
2281 get_input_pending (&input_pending
);
2286 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
2287 "Evaluate BODY with mouse movement events enabled.\n\
2288 Within a `track-mouse' form, mouse motion generates input events that\n\
2289 you can read with `read-event'.\n\
2290 Normally, mouse motion is ignored.")
2294 int count
= specpdl_ptr
- specpdl
;
2297 record_unwind_protect (tracking_off
, do_mouse_tracking
);
2299 do_mouse_tracking
= Qt
;
2301 val
= Fprogn (args
);
2302 return unbind_to (count
, val
);
2305 /* If mouse has moved on some frame, return one of those frames.
2306 Return 0 otherwise. */
2311 Lisp_Object tail
, frame
;
2313 FOR_EACH_FRAME (tail
, frame
)
2315 if (XFRAME (frame
)->mouse_moved
)
2316 return XFRAME (frame
);
2322 #endif /* HAVE_MOUSE */
2324 /* Low level keyboard/mouse input.
2325 kbd_buffer_store_event places events in kbd_buffer, and
2326 kbd_buffer_get_event retrieves them.
2327 mouse_moved indicates when the mouse has moved again, and
2328 *mouse_position_hook provides the mouse position. */
2330 /* Return true iff there are any events in the queue that read-char
2331 would return. If this returns false, a read-char would block. */
2335 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2338 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2343 if (current_kboard
->kbd_queue_has_data
)
2349 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2350 if (kb
->kbd_queue_has_data
)
2356 /* Set this for debugging, to have a way to get out */
2361 event_to_kboard (event
)
2362 struct input_event
*event
;
2365 frame
= event
->frame_or_window
;
2367 frame
= XCONS (frame
)->car
;
2368 else if (WINDOWP (frame
))
2369 frame
= WINDOW_FRAME (XWINDOW (frame
));
2371 /* There are still some events that don't set this field.
2372 For now, just ignore the problem.
2373 Also ignore dead frames here. */
2374 if (!FRAMEP (frame
) || !FRAME_LIVE_P (XFRAME (frame
)))
2377 return FRAME_KBOARD (XFRAME (frame
));
2381 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
2384 kbd_buffer_store_event (event
)
2385 register struct input_event
*event
;
2387 if (event
->kind
== no_event
)
2390 if (event
->kind
== ascii_keystroke
)
2392 register int c
= event
->code
& 0377;
2394 if (event
->modifiers
& ctrl_modifier
)
2395 c
= make_ctrl_char (c
);
2397 c
|= (event
->modifiers
2398 & (meta_modifier
| alt_modifier
2399 | hyper_modifier
| super_modifier
));
2403 extern SIGTYPE
interrupt_signal ();
2406 struct input_event
*sp
;
2409 && (kb
= FRAME_KBOARD (XFRAME (event
->frame_or_window
)),
2410 kb
!= current_kboard
))
2413 = Fcons (make_lispy_switch_frame (event
->frame_or_window
),
2414 Fcons (make_number (c
), Qnil
));
2415 kb
->kbd_queue_has_data
= 1;
2416 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
2418 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
2421 if (event_to_kboard (sp
) == kb
)
2423 sp
->kind
= no_event
;
2424 sp
->frame_or_window
= Qnil
;
2432 /* If this results in a quit_char being returned to Emacs as
2433 input, set Vlast_event_frame properly. If this doesn't
2434 get returned to Emacs as an event, the next event read
2435 will set Vlast_event_frame again, so this is safe to do. */
2439 focus
= FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
2441 focus
= event
->frame_or_window
;
2442 internal_last_event_frame
= focus
;
2443 Vlast_event_frame
= focus
;
2447 last_event_timestamp
= event
->timestamp
;
2448 interrupt_signal ();
2452 if (c
&& c
== stop_character
)
2458 /* Don't insert two buffer_switch_event's in a row.
2459 Just ignore the second one. */
2460 else if (event
->kind
== buffer_switch_event
2461 && kbd_fetch_ptr
!= kbd_store_ptr
2462 && kbd_store_ptr
->kind
== buffer_switch_event
)
2465 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
2466 kbd_store_ptr
= kbd_buffer
;
2468 /* Don't let the very last slot in the buffer become full,
2469 since that would make the two pointers equal,
2470 and that is indistinguishable from an empty buffer.
2471 Discard the event if it would fill the last slot. */
2472 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
2474 volatile struct input_event
*sp
= kbd_store_ptr
;
2475 sp
->kind
= event
->kind
;
2476 if (event
->kind
== selection_request_event
)
2478 /* We must not use the ordinary copying code for this case,
2479 since `part' is an enum and copying it might not copy enough
2481 bcopy (event
, (char *) sp
, sizeof (*event
));
2485 sp
->code
= event
->code
;
2486 sp
->part
= event
->part
;
2487 sp
->frame_or_window
= event
->frame_or_window
;
2488 sp
->modifiers
= event
->modifiers
;
2491 sp
->timestamp
= event
->timestamp
;
2493 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_store_ptr
2495 = event
->frame_or_window
);
2501 /* Read one event from the event buffer, waiting if necessary.
2502 The value is a Lisp object representing the event.
2503 The value is nil for an event that should be ignored,
2504 or that was handled here.
2505 We always read and discard one event. */
2508 kbd_buffer_get_event (kbp
, used_mouse_menu
)
2510 int *used_mouse_menu
;
2519 *kbp
= current_kboard
;
2523 /* Wait until there is input available. */
2526 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2529 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2533 /* If the quit flag is set, then read_char will return
2534 quit_char, so that counts as "available input." */
2535 if (!NILP (Vquit_flag
))
2536 quit_throw_to_read_char ();
2538 /* One way or another, wait until input is available; then, if
2539 interrupt handlers have not read it, read it now. */
2542 wait_for_kbd_input ();
2544 /* Note SIGIO has been undef'd if FIONREAD is missing. */
2548 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2551 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2555 Lisp_Object minus_one
;
2557 XSETINT (minus_one
, -1);
2558 wait_reading_process_input (0, 0, minus_one
, 1);
2560 if (!interrupt_input
&& kbd_fetch_ptr
== kbd_store_ptr
)
2561 /* Pass 1 for EXPECT since we just waited to have input. */
2562 read_avail_input (1);
2564 #endif /* not VMS */
2567 /* At this point, we know that there is a readable event available
2568 somewhere. If the event queue is empty, then there must be a
2569 mouse movement enabled and available. */
2570 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2572 struct input_event
*event
;
2574 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2578 last_event_timestamp
= event
->timestamp
;
2581 *kbp
= event_to_kboard (event
);
2583 *kbp
= current_kboard
; /* Better than returning null ptr? */
2585 *kbp
= &the_only_kboard
;
2590 /* These two kinds of events get special handling
2591 and don't actually appear to the command loop.
2592 We return nil for them. */
2593 if (event
->kind
== selection_request_event
)
2596 struct input_event copy
;
2598 /* Remove it from the buffer before processing it,
2599 since otherwise swallow_events will see it
2600 and process it again. */
2602 kbd_fetch_ptr
= event
+ 1;
2603 input_pending
= readable_events ();
2604 x_handle_selection_request (©
);
2606 /* We're getting selection request events, but we don't have
2612 else if (event
->kind
== selection_clear_event
)
2615 struct input_event copy
;
2617 /* Remove it from the buffer before processing it. */
2619 kbd_fetch_ptr
= event
+ 1;
2620 input_pending
= readable_events ();
2621 x_handle_selection_clear (©
);
2623 /* We're getting selection request events, but we don't have
2629 else if (event
->kind
== delete_window_event
)
2631 /* Make an event (delete-frame (FRAME)). */
2632 obj
= Fcons (event
->frame_or_window
, Qnil
);
2633 obj
= Fcons (Qdelete_frame
, Fcons (obj
, Qnil
));
2634 kbd_fetch_ptr
= event
+ 1;
2636 else if (event
->kind
== iconify_event
)
2638 /* Make an event (iconify-frame (FRAME)). */
2639 obj
= Fcons (event
->frame_or_window
, Qnil
);
2640 obj
= Fcons (Qiconify_frame
, Fcons (obj
, Qnil
));
2641 kbd_fetch_ptr
= event
+ 1;
2643 else if (event
->kind
== deiconify_event
)
2645 /* Make an event (make-frame-visible (FRAME)). */
2646 obj
= Fcons (event
->frame_or_window
, Qnil
);
2647 obj
= Fcons (Qmake_frame_visible
, Fcons (obj
, Qnil
));
2648 kbd_fetch_ptr
= event
+ 1;
2651 else if (event
->kind
== buffer_switch_event
)
2653 /* The value doesn't matter here; only the type is tested. */
2654 XSETBUFFER (obj
, current_buffer
);
2655 kbd_fetch_ptr
= event
+ 1;
2657 #ifdef USE_X_TOOLKIT
2658 else if (event
->kind
== menu_bar_activate_event
)
2660 kbd_fetch_ptr
= event
+ 1;
2661 input_pending
= readable_events ();
2662 x_activate_menubar (XFRAME (event
->frame_or_window
));
2665 /* Just discard these, by returning nil.
2666 With MULTI_KBOARD, these events are used as placeholders
2667 when we need to randomly delete events from the queue.
2668 (They shouldn't otherwise be found in the buffer,
2669 but on some machines it appears they do show up
2670 even without MULTI_KBOARD.) */
2671 else if (event
->kind
== no_event
)
2672 kbd_fetch_ptr
= event
+ 1;
2674 /* If this event is on a different frame, return a switch-frame this
2675 time, and leave the event in the queue for next time. */
2682 frame
= event
->frame_or_window
;
2684 frame
= XCONS (frame
)->car
;
2685 else if (WINDOWP (frame
))
2686 frame
= WINDOW_FRAME (XWINDOW (frame
));
2688 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
2692 if (! EQ (frame
, internal_last_event_frame
)
2693 && XFRAME (frame
) != selected_frame
)
2694 obj
= make_lispy_switch_frame (frame
);
2695 internal_last_event_frame
= frame
;
2696 #endif /* MULTI_FRAME */
2698 /* If we didn't decide to make a switch-frame event, go ahead
2699 and build a real event from the queue entry. */
2703 obj
= make_lispy_event (event
);
2704 #ifdef USE_X_TOOLKIT
2705 /* If this was a menu selection, then set the flag to inhibit
2706 writing to last_nonmenu_event. Don't do this if the event
2707 we're returning is (menu-bar), though; that indicates the
2708 beginning of the menu sequence, and we might as well leave
2709 that as the `event with parameters' for this selection. */
2710 if (event
->kind
== menu_bar_event
2711 && !(CONSP (obj
) && EQ (XCONS (obj
)->car
, Qmenu_bar
))
2713 *used_mouse_menu
= 1;
2716 /* Wipe out this event, to catch bugs. */
2717 event
->kind
= no_event
;
2718 XVECTOR (kbd_buffer_frame_or_window
)->contents
[event
- kbd_buffer
] = Qnil
;
2720 kbd_fetch_ptr
= event
+ 1;
2725 /* Try generating a mouse motion event. */
2726 else if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2728 FRAME_PTR f
= some_mouse_moved ();
2729 Lisp_Object bar_window
;
2730 enum scroll_bar_part part
;
2734 *kbp
= current_kboard
;
2735 /* Note that this uses F to determine which display to look at.
2736 If there is no valid info, it does not store anything
2737 so x remains nil. */
2739 (*mouse_position_hook
) (&f
, 0, &bar_window
, &part
, &x
, &y
, &time
);
2744 /* Decide if we should generate a switch-frame event. Don't
2745 generate switch-frame events for motion outside of all Emacs
2751 frame
= FRAME_FOCUS_FRAME (f
);
2753 XSETFRAME (frame
, f
);
2755 if (! EQ (frame
, internal_last_event_frame
)
2756 && XFRAME (frame
) != selected_frame
)
2757 obj
= make_lispy_switch_frame (frame
);
2758 internal_last_event_frame
= frame
;
2762 /* If we didn't decide to make a switch-frame event, go ahead and
2763 return a mouse-motion event. */
2764 if (!NILP (x
) && NILP (obj
))
2765 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
2767 #endif /* HAVE_MOUSE */
2769 /* We were promised by the above while loop that there was
2770 something for us to read! */
2773 input_pending
= readable_events ();
2776 Vlast_event_frame
= internal_last_event_frame
;
2782 /* Process any events that are not user-visible,
2783 then return, without reading any user-visible events. */
2788 while (kbd_fetch_ptr
!= kbd_store_ptr
)
2790 struct input_event
*event
;
2792 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2796 last_event_timestamp
= event
->timestamp
;
2798 /* These two kinds of events get special handling
2799 and don't actually appear to the command loop. */
2800 if (event
->kind
== selection_request_event
)
2803 struct input_event copy
;
2805 /* Remove it from the buffer before processing it,
2806 since otherwise swallow_events called recursively could see it
2807 and process it again. */
2809 kbd_fetch_ptr
= event
+ 1;
2810 input_pending
= readable_events ();
2811 x_handle_selection_request (©
);
2813 /* We're getting selection request events, but we don't have
2819 else if (event
->kind
== selection_clear_event
)
2822 struct input_event copy
;
2824 /* Remove it from the buffer before processing it, */
2827 kbd_fetch_ptr
= event
+ 1;
2828 input_pending
= readable_events ();
2829 x_handle_selection_clear (©
);
2831 /* We're getting selection request events, but we don't have
2840 get_input_pending (&input_pending
);
2843 /* Caches for modify_event_symbol. */
2844 static Lisp_Object accent_key_syms
;
2845 static Lisp_Object func_key_syms
;
2846 static Lisp_Object mouse_syms
;
2848 /* This is a list of keysym codes for special "accent" characters.
2849 It parallels lispy_accent_keys. */
2851 static int lispy_accent_codes
[] =
2853 #ifdef XK_dead_circumflex
2858 #ifdef XK_dead_grave
2863 #ifdef XK_dead_tilde
2868 #ifdef XK_dead_diaeresis
2873 #ifdef XK_dead_macron
2878 #ifdef XK_dead_degree
2883 #ifdef XK_dead_acute
2888 #ifdef XK_dead_cedilla
2893 #ifdef XK_dead_breve
2898 #ifdef XK_dead_ogonek
2903 #ifdef XK_dead_caron
2908 #ifdef XK_dead_doubleacute
2909 XK_dead_doubleacute
,
2913 #ifdef XK_dead_abovedot
2920 /* This is a list of Lisp names for special "accent" characters.
2921 It parallels lispy_accent_codes. */
2923 static char *lispy_accent_keys
[] =
2940 /* You'll notice that this table is arranged to be conveniently
2941 indexed by X Windows keysym values. */
2942 static char *lispy_function_keys
[] =
2944 /* X Keysym value */
2946 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00 */
2954 0, 0, 0, /* 0xff10 */
2956 0, 0, 0, 0, 0, 0, 0,
2959 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff20...2f */
2960 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff30...3f */
2961 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
2963 "home", /* 0xff50 */ /* IsCursorKey */
2974 "select", /* 0xff60 */ /* IsMiscFunctionKey */
2985 "break", /* 0xff6b */
2987 0, 0, 0, 0, 0, 0, 0, 0, "backtab", 0,
2989 0, 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff7f */
2990 "kp-space", /* 0xff80 */ /* IsKeypadKey */
2991 0, 0, 0, 0, 0, 0, 0, 0,
2992 "kp-tab", /* 0xff89 */
2994 "kp-enter", /* 0xff8d */
2996 "kp-f1", /* 0xff91 */
3000 "kp-home", /* 0xff95 */
3005 "kp-prior", /* kp-page-up */
3006 "kp-next", /* kp-page-down */
3012 0, 0, 0, 0, 0, 0, 0, 0, 0,
3013 "kp-multiply", /* 0xffaa */
3018 "kp-divide", /* 0xffaf */
3019 "kp-0", /* 0xffb0 */
3020 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
3023 "kp-equal", /* 0xffbd */
3024 "f1", /* 0xffbe */ /* IsFunctionKey */
3026 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
3027 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
3028 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
3029 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
3030 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
3031 0, 0, 0, 0, 0, 0, 0, 0,
3032 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
3033 0, 0, 0, 0, 0, 0, 0, "delete"
3036 static char *lispy_mouse_names
[] =
3038 "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5"
3041 /* Scroll bar parts. */
3042 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
3044 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
3045 Lisp_Object
*scroll_bar_parts
[] = {
3046 &Qabove_handle
, &Qhandle
, &Qbelow_handle
3050 /* A vector, indexed by button number, giving the down-going location
3051 of currently depressed buttons, both scroll bar and non-scroll bar.
3053 The elements have the form
3054 (BUTTON-NUMBER MODIFIER-MASK . REST)
3055 where REST is the cdr of a position as it would be reported in the event.
3057 The make_lispy_event function stores positions here to tell the
3058 difference between click and drag events, and to store the starting
3059 location to be included in drag events. */
3061 static Lisp_Object button_down_location
;
3063 /* Information about the most recent up-going button event: Which
3064 button, what location, and what time. */
3066 static int last_mouse_button
;
3067 static int last_mouse_x
;
3068 static int last_mouse_y
;
3069 static unsigned long button_down_time
;
3071 /* The maximum time between clicks to make a double-click,
3072 or Qnil to disable double-click detection,
3073 or Qt for no time limit. */
3074 Lisp_Object Vdouble_click_time
;
3076 /* The number of clicks in this multiple-click. */
3078 int double_click_count
;
3080 /* Given a struct input_event, build the lisp event which represents
3081 it. If EVENT is 0, build a mouse movement event from the mouse
3082 movement buffer, which should have a movement event in it.
3084 Note that events must be passed to this function in the order they
3085 are received; this function stores the location of button presses
3086 in order to build drag events when the button is released. */
3089 make_lispy_event (event
)
3090 struct input_event
*event
;
3094 switch (SWITCH_ENUM_CAST (event
->kind
))
3096 /* A simple keystroke. */
3097 case ascii_keystroke
:
3099 Lisp_Object lispy_c
;
3100 int c
= event
->code
& 0377;
3101 /* Turn ASCII characters into control characters
3103 if (event
->modifiers
& ctrl_modifier
)
3104 c
= make_ctrl_char (c
);
3106 /* Add in the other modifier bits. We took care of ctrl_modifier
3107 just above, and the shift key was taken care of by the X code,
3108 and applied to control characters by make_ctrl_char. */
3109 c
|= (event
->modifiers
3110 & (meta_modifier
| alt_modifier
3111 | hyper_modifier
| super_modifier
));
3112 button_down_time
= 0;
3113 XSETFASTINT (lispy_c
, c
);
3117 /* A function key. The symbol may need to have modifier prefixes
3119 case non_ascii_keystroke
:
3120 button_down_time
= 0;
3122 for (i
= 0; i
< sizeof (lispy_accent_codes
) / sizeof (int); i
++)
3123 if (event
->code
== lispy_accent_codes
[i
])
3124 return modify_event_symbol (i
,
3126 Qfunction_key
, Qnil
,
3127 lispy_accent_keys
, &accent_key_syms
,
3128 (sizeof (lispy_accent_keys
)
3129 / sizeof (lispy_accent_keys
[0])));
3131 /* Handle system-specific keysyms. */
3132 if (event
->code
& (1 << 28))
3134 /* We need to use an alist rather than a vector as the cache
3135 since we can't make a vector long enuf. */
3136 if (NILP (current_kboard
->system_key_syms
))
3137 current_kboard
->system_key_syms
= Fcons (Qnil
, Qnil
);
3138 return modify_event_symbol (event
->code
,
3141 current_kboard
->Vsystem_key_alist
,
3142 0, ¤t_kboard
->system_key_syms
,
3146 return modify_event_symbol (event
->code
- 0xff00,
3148 Qfunction_key
, Qnil
,
3149 lispy_function_keys
, &func_key_syms
,
3150 (sizeof (lispy_function_keys
)
3151 / sizeof (lispy_function_keys
[0])));
3155 /* A mouse click. Figure out where it is, decide whether it's
3156 a press, click or drag, and build the appropriate structure. */
3158 case scroll_bar_click
:
3160 int button
= event
->code
;
3162 Lisp_Object position
;
3163 Lisp_Object
*start_pos_ptr
;
3164 Lisp_Object start_pos
;
3166 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
3169 /* Build the position as appropriate for this mouse click. */
3170 if (event
->kind
== mouse_click
)
3173 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
3178 /* Ignore mouse events that were made on frame that
3179 have been deleted. */
3180 if (! FRAME_LIVE_P (f
))
3183 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
3184 &column
, &row
, NULL
, 1);
3186 #ifndef USE_X_TOOLKIT
3187 /* In the non-toolkit version, clicks on the menu bar
3188 are ordinary button events in the event buffer.
3189 Distinguish them, and invoke the menu.
3191 (In the toolkit version, the toolkit handles the menu bar
3192 and Emacs doesn't know about it until after the user
3193 makes a selection.) */
3194 if (row
>= 0 && row
< FRAME_MENU_BAR_LINES (f
)
3195 && (event
->modifiers
& down_modifier
))
3197 Lisp_Object items
, item
;
3202 /* Activate the menu bar on the down event. If the
3203 up event comes in before the menu code can deal with it,
3205 if (! (event
->modifiers
& down_modifier
))
3210 items
= FRAME_MENU_BAR_ITEMS (f
);
3211 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 3)
3213 Lisp_Object pos
, string
;
3214 string
= XVECTOR (items
)->contents
[i
+ 1];
3215 pos
= XVECTOR (items
)->contents
[i
+ 2];
3218 if (column
>= XINT (pos
)
3219 && column
< XINT (pos
) + XSTRING (string
)->size
)
3221 item
= XVECTOR (items
)->contents
[i
];
3227 = Fcons (event
->frame_or_window
,
3229 Fcons (Fcons (event
->x
, event
->y
),
3230 Fcons (make_number (event
->timestamp
),
3233 return Fcons (item
, Fcons (position
, Qnil
));
3235 #endif /* not USE_X_TOOLKIT */
3237 window
= window_from_coordinates (f
, column
, row
, &part
);
3239 if (!WINDOWP (window
))
3241 window
= event
->frame_or_window
;
3246 int pixcolumn
, pixrow
;
3247 column
-= XINT (XWINDOW (window
)->left
);
3248 row
-= XINT (XWINDOW (window
)->top
);
3249 glyph_to_pixel_coords (f
, column
, row
, &pixcolumn
, &pixrow
);
3250 XSETINT (event
->x
, pixcolumn
);
3251 XSETINT (event
->y
, pixrow
);
3256 posn
= Qvertical_line
;
3259 buffer_posn_from_coords (XWINDOW (window
),
3266 Fcons (Fcons (event
->x
, event
->y
),
3267 Fcons (make_number (event
->timestamp
),
3273 Lisp_Object portion_whole
;
3276 window
= event
->frame_or_window
;
3277 portion_whole
= Fcons (event
->x
, event
->y
);
3278 part
= *scroll_bar_parts
[(int) event
->part
];
3282 Fcons (Qvertical_scroll_bar
,
3283 Fcons (portion_whole
,
3284 Fcons (make_number (event
->timestamp
),
3285 Fcons (part
, Qnil
)))));
3288 start_pos_ptr
= &XVECTOR (button_down_location
)->contents
[button
];
3290 start_pos
= *start_pos_ptr
;
3291 *start_pos_ptr
= Qnil
;
3293 is_double
= (button
== last_mouse_button
3294 && XINT (event
->x
) == last_mouse_x
3295 && XINT (event
->y
) == last_mouse_y
3296 && button_down_time
!= 0
3297 && (EQ (Vdouble_click_time
, Qt
)
3298 || (INTEGERP (Vdouble_click_time
)
3299 && ((int)(event
->timestamp
- button_down_time
)
3300 < XINT (Vdouble_click_time
)))));
3301 last_mouse_button
= button
;
3302 last_mouse_x
= XINT (event
->x
);
3303 last_mouse_y
= XINT (event
->y
);
3305 /* If this is a button press, squirrel away the location, so
3306 we can decide later whether it was a click or a drag. */
3307 if (event
->modifiers
& down_modifier
)
3311 double_click_count
++;
3312 event
->modifiers
|= ((double_click_count
> 2)
3317 double_click_count
= 1;
3318 button_down_time
= event
->timestamp
;
3319 *start_pos_ptr
= Fcopy_alist (position
);
3322 /* Now we're releasing a button - check the co-ordinates to
3323 see if this was a click or a drag. */
3324 else if (event
->modifiers
& up_modifier
)
3326 /* If we did not see a down before this up,
3327 ignore the up. Probably this happened because
3328 the down event chose a menu item.
3329 It would be an annoyance to treat the release
3330 of the button that chose the menu item
3331 as a separate event. */
3333 if (!CONSP (start_pos
))
3336 event
->modifiers
&= ~up_modifier
;
3337 #if 0 /* Formerly we treated an up with no down as a click event. */
3338 if (!CONSP (start_pos
))
3339 event
->modifiers
|= click_modifier
;
3343 /* The third element of every position should be the (x,y)
3347 down
= Fnth (make_number (2), start_pos
);
3348 if (EQ (event
->x
, XCONS (down
)->car
)
3349 && EQ (event
->y
, XCONS (down
)->cdr
))
3351 event
->modifiers
|= click_modifier
;
3355 button_down_time
= 0;
3356 event
->modifiers
|= drag_modifier
;
3358 /* Don't check is_double; treat this as multiple
3359 if the down-event was multiple. */
3360 if (double_click_count
> 1)
3361 event
->modifiers
|= ((double_click_count
> 2)
3367 /* Every mouse event should either have the down_modifier or
3368 the up_modifier set. */
3372 /* Get the symbol we should use for the mouse click. */
3375 head
= modify_event_symbol (button
,
3378 lispy_mouse_names
, &mouse_syms
,
3379 (sizeof (lispy_mouse_names
)
3380 / sizeof (lispy_mouse_names
[0])));
3381 if (event
->modifiers
& drag_modifier
)
3386 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
3389 Fcons (make_number (double_click_count
),
3397 #endif /* HAVE_MOUSE */
3399 #ifdef USE_X_TOOLKIT
3400 case menu_bar_event
:
3401 /* The event value is in the cdr of the frame_or_window slot. */
3402 if (!CONSP (event
->frame_or_window
))
3404 return XCONS (event
->frame_or_window
)->cdr
;
3407 /* The 'kind' field of the event is something we don't recognize. */
3416 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
3418 Lisp_Object bar_window
;
3419 enum scroll_bar_part part
;
3424 /* Is it a scroll bar movement? */
3425 if (frame
&& ! NILP (bar_window
))
3427 Lisp_Object part_sym
;
3429 part_sym
= *scroll_bar_parts
[(int) part
];
3430 return Fcons (Qscroll_bar_movement
,
3431 (Fcons (Fcons (bar_window
,
3432 Fcons (Qvertical_scroll_bar
,
3433 Fcons (Fcons (x
, y
),
3434 Fcons (make_number (time
),
3440 /* Or is it an ordinary mouse movement? */
3442 #endif /* MULTI_FRAME */
3455 /* It's in a frame; which window on that frame? */
3456 pixel_to_glyph_coords (frame
, XINT (x
), XINT (y
), &column
, &row
,
3458 window
= window_from_coordinates (frame
, column
, row
, &area
);
3463 if (WINDOWP (window
))
3465 int pixcolumn
, pixrow
;
3466 column
-= XINT (XWINDOW (window
)->left
);
3467 row
-= XINT (XWINDOW (window
)->top
);
3468 glyph_to_pixel_coords (frame
, column
, row
, &pixcolumn
, &pixrow
);
3469 XSETINT (x
, pixcolumn
);
3470 XSETINT (y
, pixrow
);
3475 posn
= Qvertical_line
;
3478 buffer_posn_from_coords (XWINDOW (window
), column
, row
));
3481 else if (frame
!= 0)
3483 XSETFRAME (window
, frame
);
3495 return Fcons (Qmouse_movement
,
3496 Fcons (Fcons (window
,
3498 Fcons (Fcons (x
, y
),
3499 Fcons (make_number (time
),
3505 #endif /* HAVE_MOUSE */
3507 /* Construct a switch frame event. */
3509 make_lispy_switch_frame (frame
)
3512 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
3515 /* Manipulating modifiers. */
3517 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
3519 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
3520 SYMBOL's name of the end of the modifiers; the string from this
3521 position is the unmodified symbol name.
3523 This doesn't use any caches. */
3526 parse_modifiers_uncached (symbol
, modifier_end
)
3530 struct Lisp_String
*name
;
3534 CHECK_SYMBOL (symbol
, 1);
3537 name
= XSYMBOL (symbol
)->name
;
3539 for (i
= 0; i
+2 <= name
->size
; )
3541 int this_mod_end
= 0;
3544 /* See if the name continues with a modifier word.
3545 Check that the word appears, but don't check what follows it.
3546 Set this_mod and this_mod_end to record what we find. */
3548 switch (name
->data
[i
])
3550 #define SINGLE_LETTER_MOD(BIT) \
3551 (this_mod_end = i + 1, this_mod = BIT)
3554 SINGLE_LETTER_MOD (alt_modifier
);
3558 SINGLE_LETTER_MOD (ctrl_modifier
);
3562 SINGLE_LETTER_MOD (hyper_modifier
);
3566 SINGLE_LETTER_MOD (meta_modifier
);
3570 SINGLE_LETTER_MOD (shift_modifier
);
3574 SINGLE_LETTER_MOD (super_modifier
);
3577 #undef SINGLE_LETTER_MOD
3580 /* If we found no modifier, stop looking for them. */
3581 if (this_mod_end
== 0)
3584 /* Check there is a dash after the modifier, so that it
3585 really is a modifier. */
3586 if (this_mod_end
>= name
->size
|| name
->data
[this_mod_end
] != '-')
3589 /* This modifier is real; look for another. */
3590 modifiers
|= this_mod
;
3591 i
= this_mod_end
+ 1;
3594 /* Should we include the `click' modifier? */
3595 if (! (modifiers
& (down_modifier
| drag_modifier
3596 | double_modifier
| triple_modifier
))
3597 && i
+ 7 == name
->size
3598 && strncmp (name
->data
+ i
, "mouse-", 6) == 0
3599 && ('0' <= name
->data
[i
+ 6] && name
->data
[i
+ 6] <= '9'))
3600 modifiers
|= click_modifier
;
3608 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
3609 prepended to the string BASE[0..BASE_LEN-1].
3610 This doesn't use any caches. */
3612 apply_modifiers_uncached (modifiers
, base
, base_len
)
3617 /* Since BASE could contain nulls, we can't use intern here; we have
3618 to use Fintern, which expects a genuine Lisp_String, and keeps a
3621 (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
3627 /* Only the event queue may use the `up' modifier; it should always
3628 be turned into a click or drag event before presented to lisp code. */
3629 if (modifiers
& up_modifier
)
3632 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
3633 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
3634 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
3635 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
3636 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
3637 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
3638 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
3639 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
3640 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
3641 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
3642 /* The click modifier is denoted by the absence of other modifiers. */
3646 mod_len
= p
- new_mods
;
3650 Lisp_Object new_name
;
3652 new_name
= make_uninit_string (mod_len
+ base_len
);
3653 bcopy (new_mods
, XSTRING (new_name
)->data
, mod_len
);
3654 bcopy (base
, XSTRING (new_name
)->data
+ mod_len
, base_len
);
3656 return Fintern (new_name
, Qnil
);
3661 static char *modifier_names
[] =
3663 "up", "down", "drag", "click", "double", "triple", 0, 0,
3664 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3665 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
3667 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
3669 static Lisp_Object modifier_symbols
;
3671 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
3673 lispy_modifier_list (modifiers
)
3676 Lisp_Object modifier_list
;
3679 modifier_list
= Qnil
;
3680 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
3681 if (modifiers
& (1<<i
))
3682 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
3685 return modifier_list
;
3689 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
3690 where UNMODIFIED is the unmodified form of SYMBOL,
3691 MASK is the set of modifiers present in SYMBOL's name.
3692 This is similar to parse_modifiers_uncached, but uses the cache in
3693 SYMBOL's Qevent_symbol_element_mask property, and maintains the
3694 Qevent_symbol_elements property. */
3697 parse_modifiers (symbol
)
3700 Lisp_Object elements
;
3702 elements
= Fget (symbol
, Qevent_symbol_element_mask
);
3703 if (CONSP (elements
))
3708 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
3709 Lisp_Object unmodified
;
3712 unmodified
= Fintern (make_string (XSYMBOL (symbol
)->name
->data
+ end
,
3713 XSYMBOL (symbol
)->name
->size
- end
),
3716 if (modifiers
& ~(((EMACS_INT
)1 << VALBITS
) - 1))
3718 XSETFASTINT (mask
, modifiers
);
3719 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
3721 /* Cache the parsing results on SYMBOL. */
3722 Fput (symbol
, Qevent_symbol_element_mask
,
3724 Fput (symbol
, Qevent_symbol_elements
,
3725 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
3727 /* Since we know that SYMBOL is modifiers applied to unmodified,
3728 it would be nice to put that in unmodified's cache.
3729 But we can't, since we're not sure that parse_modifiers is
3736 /* Apply the modifiers MODIFIERS to the symbol BASE.
3737 BASE must be unmodified.
3739 This is like apply_modifiers_uncached, but uses BASE's
3740 Qmodifier_cache property, if present. It also builds
3741 Qevent_symbol_elements properties, since it has that info anyway.
3743 apply_modifiers copies the value of BASE's Qevent_kind property to
3744 the modified symbol. */
3746 apply_modifiers (modifiers
, base
)
3750 Lisp_Object cache
, index
, entry
, new_symbol
;
3752 /* Mask out upper bits. We don't know where this value's been. */
3753 modifiers
&= ((EMACS_INT
)1 << VALBITS
) - 1;
3755 /* The click modifier never figures into cache indices. */
3756 cache
= Fget (base
, Qmodifier_cache
);
3757 XSETFASTINT (index
, (modifiers
& ~click_modifier
));
3758 entry
= assq_no_quit (index
, cache
);
3761 new_symbol
= XCONS (entry
)->cdr
;
3764 /* We have to create the symbol ourselves. */
3765 new_symbol
= apply_modifiers_uncached (modifiers
,
3766 XSYMBOL (base
)->name
->data
,
3767 XSYMBOL (base
)->name
->size
);
3769 /* Add the new symbol to the base's cache. */
3770 entry
= Fcons (index
, new_symbol
);
3771 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
3773 /* We have the parsing info now for free, so add it to the caches. */
3774 XSETFASTINT (index
, modifiers
);
3775 Fput (new_symbol
, Qevent_symbol_element_mask
,
3776 Fcons (base
, Fcons (index
, Qnil
)));
3777 Fput (new_symbol
, Qevent_symbol_elements
,
3778 Fcons (base
, lispy_modifier_list (modifiers
)));
3781 /* Make sure this symbol is of the same kind as BASE.
3783 You'd think we could just set this once and for all when we
3784 intern the symbol above, but reorder_modifiers may call us when
3785 BASE's property isn't set right; we can't assume that just
3786 because it has a Qmodifier_cache property it must have its
3787 Qevent_kind set right as well. */
3788 if (NILP (Fget (new_symbol
, Qevent_kind
)))
3792 kind
= Fget (base
, Qevent_kind
);
3794 Fput (new_symbol
, Qevent_kind
, kind
);
3801 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
3802 return a symbol with the modifiers placed in the canonical order.
3803 Canonical order is alphabetical, except for down and drag, which
3804 always come last. The 'click' modifier is never written out.
3806 Fdefine_key calls this to make sure that (for example) C-M-foo
3807 and M-C-foo end up being equivalent in the keymap. */
3810 reorder_modifiers (symbol
)
3813 /* It's hopefully okay to write the code this way, since everything
3814 will soon be in caches, and no consing will be done at all. */
3817 parsed
= parse_modifiers (symbol
);
3818 return apply_modifiers ((int) XINT (XCONS (XCONS (parsed
)->cdr
)->car
),
3819 XCONS (parsed
)->car
);
3823 /* For handling events, we often want to produce a symbol whose name
3824 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
3825 to some base, like the name of a function key or mouse button.
3826 modify_event_symbol produces symbols of this sort.
3828 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
3829 is the name of the i'th symbol. TABLE_SIZE is the number of elements
3832 Alternatively, NAME_ALIST is an alist mapping codes into symbol names.
3833 NAME_ALIST is used if it is non-nil; otherwise NAME_TABLE is used.
3835 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
3836 persist between calls to modify_event_symbol that it can use to
3837 store a cache of the symbols it's generated for this NAME_TABLE
3838 before. The object stored there may be a vector or an alist.
3840 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
3842 MODIFIERS is a set of modifier bits (as given in struct input_events)
3843 whose prefixes should be applied to the symbol name.
3845 SYMBOL_KIND is the value to be placed in the event_kind property of
3846 the returned symbol.
3848 The symbols we create are supposed to have an
3849 `event-symbol-elements' property, which lists the modifiers present
3850 in the symbol's name. */
3853 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_alist
,
3854 name_table
, symbol_table
, table_size
)
3857 Lisp_Object symbol_kind
;
3858 Lisp_Object name_alist
;
3860 Lisp_Object
*symbol_table
;
3861 unsigned int table_size
;
3864 Lisp_Object symbol_int
;
3866 /* Get rid of the "vendor-specific" bit here. */
3867 XSETINT (symbol_int
, symbol_num
& 0xffffff);
3869 /* Is this a request for a valid symbol? */
3870 if (symbol_num
< 0 || symbol_num
>= table_size
)
3873 if (CONSP (*symbol_table
))
3874 value
= Fcdr (assq_no_quit (symbol_int
, *symbol_table
));
3876 /* If *symbol_table doesn't seem to be initialized properly, fix that.
3877 *symbol_table should be a lisp vector TABLE_SIZE elements long,
3878 where the Nth element is the symbol for NAME_TABLE[N], or nil if
3879 we've never used that symbol before. */
3882 if (! VECTORP (*symbol_table
)
3883 || XVECTOR (*symbol_table
)->size
!= table_size
)
3887 XSETFASTINT (size
, table_size
);
3888 *symbol_table
= Fmake_vector (size
, Qnil
);
3891 value
= XVECTOR (*symbol_table
)->contents
[symbol_num
];
3894 /* Have we already used this symbol before? */
3897 /* No; let's create it. */
3898 if (!NILP (name_alist
))
3899 value
= Fcdr_safe (Fassq (symbol_int
, name_alist
));
3900 else if (name_table
[symbol_num
])
3901 value
= intern (name_table
[symbol_num
]);
3903 #ifdef HAVE_X_WINDOWS
3906 char *name
= x_get_keysym_name (symbol_num
);
3908 value
= intern (name
);
3915 sprintf (buf
, "key-%d", symbol_num
);
3916 value
= intern (buf
);
3919 if (CONSP (*symbol_table
))
3920 *symbol_table
= Fcons (value
, *symbol_table
);
3922 XVECTOR (*symbol_table
)->contents
[symbol_num
] = value
;
3924 /* Fill in the cache entries for this symbol; this also
3925 builds the Qevent_symbol_elements property, which the user
3927 apply_modifiers (modifiers
& click_modifier
, value
);
3928 Fput (value
, Qevent_kind
, symbol_kind
);
3931 /* Apply modifiers to that symbol. */
3932 return apply_modifiers (modifiers
, value
);
3935 /* Convert a list that represents an event type,
3936 such as (ctrl meta backspace), into the usual representation of that
3937 event type as a number or a symbol. */
3939 DEFUN ("event-convert-list", Fevent_convert_list
, Sevent_convert_list
, 1, 1, 0,
3940 "Convert the event description LIST to an event type.\n\
3941 LIST should contain one base event type (a character or symbol)\n\
3942 and zero or more modifier names (control, meta, hyper, super, shift, alt,\n\
3943 drag, down, double or triple).\n\
3944 The return value is an event type (a character or symbol) which\n\
3945 has the same base event type and all the specified modifiers.")
3955 while (CONSP (rest
))
3960 elt
= XCONS (rest
)->car
;
3962 /* Given a symbol, see if it is a modifier name. */
3964 this = parse_solitary_modifier (elt
);
3968 else if (!NILP (base
))
3969 error ("Two bases given in one event");
3973 rest
= XCONS (rest
)->cdr
;
3976 /* Let the symbol A refer to the character A. */
3977 if (SYMBOLP (base
) && XSYMBOL (base
)->name
->size
== 1)
3978 XSETINT (base
, XSYMBOL (base
)->name
->data
[0]);
3980 if (INTEGERP (base
))
3982 /* Turn (shift a) into A. */
3983 if ((modifiers
& shift_modifier
) != 0
3984 && (XINT (base
) >= 'a' && XINT (base
) <= 'z'))
3986 XSETINT (base
, XINT (base
) - ('a' - 'A'));
3987 modifiers
&= ~shift_modifier
;
3990 /* Turn (control a) into C-a. */
3991 if (modifiers
& ctrl_modifier
)
3992 return make_number ((modifiers
& ~ctrl_modifier
)
3993 | make_ctrl_char (XINT (base
)));
3995 return make_number (modifiers
| XINT (base
));
3997 else if (SYMBOLP (base
))
3998 return apply_modifiers (modifiers
, base
);
4000 error ("Invalid base event");
4003 /* Try to recognize SYMBOL as a modifier name.
4004 Return the modifier flag bit, or 0 if not recognized. */
4007 parse_solitary_modifier (symbol
)
4010 struct Lisp_String
*name
= XSYMBOL (symbol
)->name
;
4012 switch (name
->data
[0])
4014 #define SINGLE_LETTER_MOD(BIT) \
4015 if (name->size == 1) \
4018 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
4019 if (LEN == name->size \
4020 && ! strncmp (name->data, NAME, LEN)) \
4024 SINGLE_LETTER_MOD (alt_modifier
);
4028 MULTI_LETTER_MOD (alt_modifier
, "alt", 3);
4032 SINGLE_LETTER_MOD (ctrl_modifier
);
4036 MULTI_LETTER_MOD (ctrl_modifier
, "ctrl", 4);
4037 MULTI_LETTER_MOD (ctrl_modifier
, "control", 7);
4041 SINGLE_LETTER_MOD (hyper_modifier
);
4045 MULTI_LETTER_MOD (hyper_modifier
, "hyper", 5);
4049 SINGLE_LETTER_MOD (meta_modifier
);
4053 MULTI_LETTER_MOD (meta_modifier
, "meta", 4);
4057 SINGLE_LETTER_MOD (shift_modifier
);
4061 MULTI_LETTER_MOD (shift_modifier
, "shift", 5);
4062 MULTI_LETTER_MOD (super_modifier
, "super", 5);
4063 SINGLE_LETTER_MOD (super_modifier
);
4067 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
4068 MULTI_LETTER_MOD (down_modifier
, "down", 4);
4069 MULTI_LETTER_MOD (double_modifier
, "double", 6);
4073 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
4076 #undef SINGLE_LETTER_MOD
4077 #undef MULTI_LETTER_MOD
4083 /* Return 1 if EVENT is a list whose elements are all integers or symbols.
4084 Such a list is not valid as an event,
4085 but it can be a Lucid-style event type list. */
4088 lucid_event_type_list_p (object
)
4093 if (! CONSP (object
))
4096 for (tail
= object
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4099 elt
= XCONS (tail
)->car
;
4100 if (! (INTEGERP (elt
) || SYMBOLP (elt
)))
4107 /* Store into *addr a value nonzero if terminal input chars are available.
4108 Serves the purpose of ioctl (0, FIONREAD, addr)
4109 but works even if FIONREAD does not exist.
4110 (In fact, this may actually read some input.) */
4113 get_input_pending (addr
)
4116 /* First of all, have we already counted some input? */
4117 *addr
= !NILP (Vquit_flag
) || readable_events ();
4119 /* If input is being read as it arrives, and we have none, there is none. */
4120 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
4123 /* Try to read some input and see how much we get. */
4125 *addr
= !NILP (Vquit_flag
) || readable_events ();
4128 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
4131 gobble_input (expected
)
4136 if (interrupt_input
)
4139 mask
= sigblockx (SIGIO
);
4140 read_avail_input (expected
);
4144 #ifdef POLL_FOR_INPUT
4145 if (read_socket_hook
&& !interrupt_input
&& poll_suppress_count
== 0)
4148 mask
= sigblockx (SIGALRM
);
4149 read_avail_input (expected
);
4155 read_avail_input (expected
);
4159 /* Put a buffer_switch_event in the buffer
4160 so that read_key_sequence will notice the new current buffer. */
4162 record_asynch_buffer_change ()
4164 struct input_event event
;
4167 event
.kind
= buffer_switch_event
;
4168 event
.frame_or_window
= Qnil
;
4171 /* We don't need a buffer-switch event unless Emacs is waiting for input.
4172 The purpose of the event is to make read_key_sequence look up the
4173 keymaps again. If we aren't in read_key_sequence, we don't need one,
4174 and the event could cause trouble by messing up (input-pending-p). */
4175 tem
= Fwaiting_for_user_input_p ();
4179 /* We never need these events if we have no asynchronous subprocesses. */
4183 /* Make sure no interrupt happens while storing the event. */
4185 if (interrupt_input
)
4188 mask
= sigblockx (SIGIO
);
4189 kbd_buffer_store_event (&event
);
4196 kbd_buffer_store_event (&event
);
4203 /* Read any terminal input already buffered up by the system
4204 into the kbd_buffer, but do not wait.
4206 EXPECTED should be nonzero if the caller knows there is some input.
4208 Except on VMS, all input is read by this function.
4209 If interrupt_input is nonzero, this function MUST be called
4210 only when SIGIO is blocked.
4212 Returns the number of keyboard chars read, or -1 meaning
4213 this is a bad time to try to read input. */
4216 read_avail_input (expected
)
4219 struct input_event buf
[KBD_BUFFER_SIZE
];
4223 if (read_socket_hook
)
4224 /* No need for FIONREAD or fcntl; just say don't wait. */
4225 nread
= (*read_socket_hook
) (input_fd
, buf
, KBD_BUFFER_SIZE
,
4226 expected
, expected
);
4229 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
4230 the kbd_buffer can really hold. That may prevent loss
4231 of characters on some systems when input is stuffed at us. */
4232 unsigned char cbuf
[KBD_BUFFER_SIZE
- 1];
4235 /* Determine how many characters we should *try* to read. */
4238 #else /* not WINDOWSNT */
4240 n_to_read
= dos_keysns ();
4243 #else /* not MSDOS */
4245 /* Find out how much input is available. */
4246 if (ioctl (input_fd
, FIONREAD
, &n_to_read
) < 0)
4247 /* Formerly simply reported no input, but that sometimes led to
4248 a failure of Emacs to terminate.
4249 SIGHUP seems appropriate if we can't reach the terminal. */
4250 /* ??? Is it really right to send the signal just to this process
4251 rather than to the whole process group?
4252 Perhaps on systems with FIONREAD Emacs is alone in its group. */
4253 kill (getpid (), SIGHUP
);
4256 if (n_to_read
> sizeof cbuf
)
4257 n_to_read
= sizeof cbuf
;
4258 #else /* no FIONREAD */
4259 #if defined(USG) || defined(DGUX)
4260 /* Read some input if available, but don't wait. */
4261 n_to_read
= sizeof cbuf
;
4262 fcntl (input_fd
, F_SETFL
, O_NDELAY
);
4267 #endif /* not MSDOS */
4268 #endif /* not WINDOWSNT */
4270 /* Now read; for one reason or another, this will not block.
4271 NREAD is set to the number of chars read. */
4275 cbuf
[0] = dos_keyread();
4278 nread
= read (input_fd
, cbuf
, n_to_read
);
4280 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
4281 /* The kernel sometimes fails to deliver SIGHUP for ptys.
4282 This looks incorrect, but it isn't, because _BSD causes
4283 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
4284 and that causes a value other than 0 when there is no input. */
4290 /* We used to retry the read if it was interrupted.
4291 But this does the wrong thing when O_NDELAY causes
4292 an EAGAIN error. Does anybody know of a situation
4293 where a retry is actually needed? */
4295 nread
< 0 && (errno
== EAGAIN
4309 #if defined (USG) || defined (DGUX)
4310 fcntl (input_fd
, F_SETFL
, 0);
4311 #endif /* USG or DGUX */
4312 #endif /* no FIONREAD */
4313 for (i
= 0; i
< nread
; i
++)
4315 buf
[i
].kind
= ascii_keystroke
;
4316 buf
[i
].modifiers
= 0;
4317 if (meta_key
== 1 && (cbuf
[i
] & 0x80))
4318 buf
[i
].modifiers
= meta_modifier
;
4322 buf
[i
].code
= cbuf
[i
];
4324 XSETFRAME (buf
[i
].frame_or_window
, selected_frame
);
4326 buf
[i
].frame_or_window
= Qnil
;
4331 /* Scan the chars for C-g and store them in kbd_buffer. */
4332 for (i
= 0; i
< nread
; i
++)
4334 kbd_buffer_store_event (&buf
[i
]);
4335 /* Don't look at input that follows a C-g too closely.
4336 This reduces lossage due to autorepeat on C-g. */
4337 if (buf
[i
].kind
== ascii_keystroke
4338 && buf
[i
].code
== quit_char
)
4344 #endif /* not VMS */
4346 #ifdef SIGIO /* for entire page */
4347 /* Note SIGIO has been undef'd if FIONREAD is missing. */
4350 input_available_signal (signo
)
4353 /* Must preserve main program's value of errno. */
4354 int old_errno
= errno
;
4356 extern int select_alarmed
;
4360 /* USG systems forget handlers when they are used;
4361 must reestablish each time */
4362 signal (signo
, input_available_signal
);
4369 if (input_available_clear_time
)
4370 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
4375 nread
= read_avail_input (1);
4376 /* -1 means it's not ok to read the input now.
4377 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
4378 0 means there was no keyboard input available. */
4383 select_alarmed
= 1; /* Force the select emulator back to life */
4394 /* Send ourselves a SIGIO.
4396 This function exists so that the UNBLOCK_INPUT macro in
4397 blockinput.h can have some way to take care of input we put off
4398 dealing with, without assuming that every file which uses
4399 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
4401 reinvoke_input_signal ()
4410 /* Return the prompt-string of a sparse keymap.
4411 This is the first element which is a string.
4412 Return nil if there is none. */
4420 register Lisp_Object tem
;
4429 static void menu_bar_item ();
4430 static void menu_bar_one_keymap ();
4432 /* These variables hold the vector under construction within
4433 menu_bar_items and its subroutines, and the current index
4434 for storing into that vector. */
4435 static Lisp_Object menu_bar_items_vector
;
4436 static int menu_bar_items_index
;
4438 /* Return a vector of menu items for a menu bar, appropriate
4439 to the current buffer. Each item has three elements in the vector:
4442 OLD is an old vector we can optionally reuse, or nil. */
4445 menu_bar_items (old
)
4448 /* The number of keymaps we're scanning right now, and the number of
4449 keymaps we have allocated space for. */
4452 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
4453 in the current keymaps, or nil where it is not a prefix. */
4456 Lisp_Object def
, tem
, tail
;
4465 struct gcpro gcpro1
;
4467 /* In order to build the menus, we need to call the keymap
4468 accessors. They all call QUIT. But this function is called
4469 during redisplay, during which a quit is fatal. So inhibit
4470 quitting while building the menus.
4471 We do this instead of specbind because (1) errors will clear it anyway
4472 and (2) this avoids risk of specpdl overflow. */
4473 oquit
= Vinhibit_quit
;
4477 menu_bar_items_vector
= old
;
4479 menu_bar_items_vector
= Fmake_vector (make_number (24), Qnil
);
4480 menu_bar_items_index
= 0;
4482 GCPRO1 (menu_bar_items_vector
);
4484 /* Build our list of keymaps.
4485 If we recognize a function key and replace its escape sequence in
4486 keybuf with its symbol, or if the sequence starts with a mouse
4487 click and we need to switch buffers, we jump back here to rebuild
4488 the initial keymaps from the current buffer. */
4492 /* Should overriding-terminal-local-map and overriding-local-map apply? */
4493 if (!NILP (Voverriding_local_map_menu_flag
))
4495 /* Yes, use them (if non-nil) as well as the global map. */
4496 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
4498 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
4499 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
4500 if (!NILP (Voverriding_local_map
))
4501 maps
[nmaps
++] = Voverriding_local_map
;
4505 /* No, so use major and minor mode keymaps. */
4506 nmaps
= current_minor_maps (NULL
, &tmaps
);
4507 maps
= (Lisp_Object
*) alloca ((nmaps
+ 2) * sizeof (maps
[0]));
4508 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
4509 #ifdef USE_TEXT_PROPERTIES
4510 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
4512 maps
[nmaps
++] = current_buffer
->keymap
;
4515 maps
[nmaps
++] = current_global_map
;
4518 /* Look up in each map the dummy prefix key `menu-bar'. */
4522 for (mapno
= nmaps
- 1; mapno
>= 0; mapno
--)
4524 if (! NILP (maps
[mapno
]))
4525 def
= get_keyelt (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0));
4529 tem
= Fkeymapp (def
);
4531 menu_bar_one_keymap (def
);
4534 /* Move to the end those items that should be at the end. */
4536 for (tail
= Vmenu_bar_final_items
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4539 int end
= menu_bar_items_index
;
4541 for (i
= 0; i
< end
; i
+= 3)
4542 if (EQ (XCONS (tail
)->car
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
4544 Lisp_Object tem0
, tem1
, tem2
;
4545 /* Move the item at index I to the end,
4546 shifting all the others forward. */
4547 tem0
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 0];
4548 tem1
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 1];
4549 tem2
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
4551 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3],
4552 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
4553 (end
- i
- 3) * sizeof (Lisp_Object
));
4554 XVECTOR (menu_bar_items_vector
)->contents
[end
- 3] = tem0
;
4555 XVECTOR (menu_bar_items_vector
)->contents
[end
- 2] = tem1
;
4556 XVECTOR (menu_bar_items_vector
)->contents
[end
- 1] = tem2
;
4561 /* Add nil, nil, nil at the end. */
4562 i
= menu_bar_items_index
;
4563 if (i
+ 3 > XVECTOR (menu_bar_items_vector
)->size
)
4566 int newsize
= 2 * i
;
4567 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
4568 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
4569 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
4570 menu_bar_items_vector
= tem
;
4572 /* Add this item. */
4573 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
4574 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
4575 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
4576 menu_bar_items_index
= i
;
4578 Vinhibit_quit
= oquit
;
4580 return menu_bar_items_vector
;
4583 /* Scan one map KEYMAP, accumulating any menu items it defines
4584 in menu_bar_items_vector. */
4587 menu_bar_one_keymap (keymap
)
4590 Lisp_Object tail
, item
, key
, binding
, item_string
, table
;
4592 /* Loop over all keymap entries that have menu strings. */
4593 for (tail
= keymap
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4595 item
= XCONS (tail
)->car
;
4598 key
= XCONS (item
)->car
;
4599 binding
= XCONS (item
)->cdr
;
4600 if (CONSP (binding
))
4602 item_string
= XCONS (binding
)->car
;
4603 if (STRINGP (item_string
))
4604 menu_bar_item (key
, item_string
, Fcdr (binding
));
4606 else if (EQ (binding
, Qundefined
))
4607 menu_bar_item (key
, Qnil
, binding
);
4609 else if (VECTORP (item
))
4611 /* Loop over the char values represented in the vector. */
4612 int len
= XVECTOR (item
)->size
;
4614 for (c
= 0; c
< len
; c
++)
4616 Lisp_Object character
;
4617 XSETFASTINT (character
, c
);
4618 binding
= XVECTOR (item
)->contents
[c
];
4619 if (CONSP (binding
))
4621 item_string
= XCONS (binding
)->car
;
4622 if (STRINGP (item_string
))
4623 menu_bar_item (key
, item_string
, Fcdr (binding
));
4625 else if (EQ (binding
, Qundefined
))
4626 menu_bar_item (key
, Qnil
, binding
);
4632 /* This is used as the handler when calling internal_condition_case_1. */
4635 menu_bar_item_1 (arg
)
4641 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
4642 If there's already an item for KEY, add this DEF to it. */
4645 menu_bar_item (key
, item_string
, def
)
4646 Lisp_Object key
, item_string
, def
;
4649 Lisp_Object enabled
;
4652 if (EQ (def
, Qundefined
))
4654 /* If a map has an explicit `undefined' as definition,
4655 discard any previously made menu bar item. */
4657 for (i
= 0; i
< menu_bar_items_index
; i
+= 3)
4658 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
4660 if (menu_bar_items_index
> i
+ 3)
4661 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3],
4662 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
4663 (menu_bar_items_index
- i
- 3) * sizeof (Lisp_Object
));
4664 menu_bar_items_index
-= 3;
4668 /* If there's no definition for this key yet,
4669 just ignore `undefined'. */
4673 /* See if this entry is enabled. */
4678 /* No property, or nil, means enable.
4679 Otherwise, enable if value is not nil. */
4680 tem
= Fget (def
, Qmenu_enable
);
4682 /* (condition-case nil (eval tem)
4684 enabled
= internal_condition_case_1 (Feval
, tem
, Qerror
,
4688 /* Ignore this item if it's not enabled. */
4692 /* Find any existing item for this KEY. */
4693 for (i
= 0; i
< menu_bar_items_index
; i
+= 3)
4694 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
4697 /* If we did not find this KEY, add it at the end. */
4698 if (i
== menu_bar_items_index
)
4700 /* If vector is too small, get a bigger one. */
4701 if (i
+ 3 > XVECTOR (menu_bar_items_vector
)->size
)
4704 int newsize
= 2 * i
;
4705 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
4706 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
4707 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
4708 menu_bar_items_vector
= tem
;
4710 /* Add this item. */
4711 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = key
;
4712 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = item_string
;
4713 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Fcons (def
, Qnil
);
4714 menu_bar_items_index
= i
;
4716 /* We did find an item for this KEY. Add DEF to its list of maps. */
4720 old
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
4721 XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2] = Fcons (def
, old
);
4725 /* Read a character using menus based on maps in the array MAPS.
4726 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
4727 Return t if we displayed a menu but the user rejected it.
4729 PREV_EVENT is the previous input event, or nil if we are reading
4730 the first event of a key sequence.
4732 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
4733 if we used a mouse menu to read the input, or zero otherwise. If
4734 USED_MOUSE_MENU is null, we don't dereference it.
4736 The prompting is done based on the prompt-string of the map
4737 and the strings associated with various map elements.
4739 This can be done with X menus or with menus put in the minibuf.
4740 These are done in different ways, depending on how the input will be read.
4741 Menus using X are done after auto-saving in read-char, getting the input
4742 event from Fx_popup_menu; menus using the minibuf use read_char recursively
4743 and do auto-saving in the inner call of read_char. */
4746 read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
4749 Lisp_Object prev_event
;
4750 int *used_mouse_menu
;
4753 register Lisp_Object name
;
4754 Lisp_Object rest
, vector
;
4756 if (used_mouse_menu
)
4757 *used_mouse_menu
= 0;
4759 /* Use local over global Menu maps */
4761 if (! menu_prompting
)
4764 /* Optionally disregard all but the global map. */
4765 if (inhibit_local_menu_bar_menus
)
4767 maps
+= (nmaps
- 1);
4771 /* Get the menu name from the first map that has one (a prompt string). */
4772 for (mapno
= 0; mapno
< nmaps
; mapno
++)
4774 name
= map_prompt (maps
[mapno
]);
4779 /* If we don't have any menus, just read a character normally. */
4783 #if (defined (HAVE_X_WINDOWS) && defined (HAVE_X_MENU)) || defined (MSDOS)
4784 /* If we got to this point via a mouse click,
4785 use a real menu for mouse selection. */
4786 if (EVENT_HAS_PARAMETERS (prev_event
)
4787 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
))
4789 /* Display the menu and get the selection. */
4790 Lisp_Object
*realmaps
4791 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
4795 /* Use the maps that are not nil. */
4796 for (mapno
= 0; mapno
< nmaps
; mapno
++)
4797 if (!NILP (maps
[mapno
]))
4798 realmaps
[nmaps1
++] = maps
[mapno
];
4800 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
4805 /* If we got multiple events, unread all but
4807 There is no way to prevent those unread events
4808 from showing up later in last_nonmenu_event.
4809 So turn symbol and integer events into lists,
4810 to indicate that they came from a mouse menu,
4811 so that when present in last_nonmenu_event
4812 they won't confuse things. */
4813 for (tem
= XCONS (value
)->cdr
; !NILP (tem
);
4814 tem
= XCONS (tem
)->cdr
)
4815 if (SYMBOLP (XCONS (tem
)->car
)
4816 || INTEGERP (XCONS (tem
)->car
))
4818 = Fcons (XCONS (tem
)->car
, Qnil
);
4820 /* If we got more than one event, put all but the first
4821 onto this list to be read later.
4822 Return just the first event now. */
4823 Vunread_command_events
4824 = nconc2 (XCONS (value
)->cdr
, Vunread_command_events
);
4825 value
= XCONS (value
)->car
;
4827 else if (NILP (value
))
4829 if (used_mouse_menu
)
4830 *used_mouse_menu
= 1;
4833 #endif /* (HAVE_X_WINDOWS && HAVE_X_MENU) || MSDOS */
4838 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
4844 register Lisp_Object name
;
4846 int width
= FRAME_WIDTH (selected_frame
) - 4;
4847 char *menu
= (char *) alloca (width
+ 4);
4850 Lisp_Object rest
, vector
;
4852 if (! menu_prompting
)
4855 /* Get the menu name from the first map that has one (a prompt string). */
4856 for (mapno
= 0; mapno
< nmaps
; mapno
++)
4858 name
= map_prompt (maps
[mapno
]);
4863 /* If we don't have any menus, just read a character normally. */
4867 /* Prompt string always starts with map's prompt, and a space. */
4868 strcpy (menu
, XSTRING (name
)->data
);
4869 nlength
= XSTRING (name
)->size
;
4870 menu
[nlength
++] = ':';
4871 menu
[nlength
++] = ' ';
4874 /* Start prompting at start of first map. */
4878 /* Present the documented bindings, a line at a time. */
4885 Lisp_Object orig_defn_macro
;
4887 /* Loop over elements of map. */
4892 /* If reached end of map, start at beginning of next map. */
4896 /* At end of last map, wrap around to first map if just starting,
4897 or end this line if already have something on it. */
4901 if (notfirst
|| nobindings
) break;
4906 /* Look at the next element of the map. */
4908 elt
= XVECTOR (vector
)->contents
[idx
];
4910 elt
= Fcar_safe (rest
);
4912 if (idx
< 0 && VECTORP (elt
))
4914 /* If we found a dense table in the keymap,
4915 advanced past it, but start scanning its contents. */
4916 rest
= Fcdr_safe (rest
);
4922 /* An ordinary element. */
4927 s
= Fcar_safe (Fcdr_safe (elt
)); /* alist */
4928 event
= Fcar_safe (elt
);
4932 s
= Fcar_safe (elt
); /* vector */
4933 XSETINT (event
, idx
);
4936 /* Ignore the element if it has no prompt string. */
4937 if (STRINGP (s
) && INTEGERP (event
))
4939 /* 1 if the char to type matches the string. */
4941 Lisp_Object upcased_event
, downcased_event
;
4944 upcased_event
= Fupcase (event
);
4945 downcased_event
= Fdowncase (event
);
4946 char_matches
= (XINT (upcased_event
) == XSTRING (s
)->data
[0]
4947 || XINT (downcased_event
) == XSTRING (s
)->data
[0]);
4949 desc
= Fsingle_key_description (event
);
4951 /* If we have room for the prompt string, add it to this line.
4952 If this is the first on the line, always add it. */
4953 if ((XSTRING (s
)->size
+ i
+ 2
4954 + (char_matches
? 0 : XSTRING (desc
)->size
+ 3))
4960 /* Punctuate between strings. */
4963 strcpy (menu
+ i
, ", ");
4969 /* If the char to type doesn't match the string's
4970 first char, explicitly show what char to type. */
4973 /* Add as much of string as fits. */
4974 thiswidth
= XSTRING (desc
)->size
;
4975 if (thiswidth
+ i
> width
)
4976 thiswidth
= width
- i
;
4977 bcopy (XSTRING (desc
)->data
, menu
+ i
, thiswidth
);
4979 strcpy (menu
+ i
, " = ");
4983 /* Add as much of string as fits. */
4984 thiswidth
= XSTRING (s
)->size
;
4985 if (thiswidth
+ i
> width
)
4986 thiswidth
= width
- i
;
4987 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
4993 /* If this element does not fit, end the line now,
4994 and save the element for the next line. */
4995 strcpy (menu
+ i
, "...");
5000 /* Move past this element. */
5001 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
5002 /* Handle reaching end of dense table. */
5007 rest
= Fcdr_safe (rest
);
5011 /* Prompt with that and read response. */
5014 /* Make believe its not a keyboard macro in case the help char
5015 is pressed. Help characters are not recorded because menu prompting
5016 is not used on replay.
5018 orig_defn_macro
= current_kboard
->defining_kbd_macro
;
5019 current_kboard
->defining_kbd_macro
= Qnil
;
5021 obj
= read_char (commandflag
, 0, 0, Qnil
, 0);
5022 while (BUFFERP (obj
));
5023 current_kboard
->defining_kbd_macro
= orig_defn_macro
;
5025 if (!INTEGERP (obj
))
5030 if (! EQ (obj
, menu_prompt_more_char
)
5031 && (!INTEGERP (menu_prompt_more_char
)
5032 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
5034 if (!NILP (current_kboard
->defining_kbd_macro
))
5035 store_kbd_macro_char (obj
);
5038 /* Help char - go round again */
5042 /* Reading key sequences. */
5044 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
5045 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
5046 keymap, or nil otherwise. Return the index of the first keymap in
5047 which KEY has any binding, or NMAPS if no map has a binding.
5049 If KEY is a meta ASCII character, treat it like meta-prefix-char
5050 followed by the corresponding non-meta character. Keymaps in
5051 CURRENT with non-prefix bindings for meta-prefix-char become nil in
5054 If KEY has no bindings in any of the CURRENT maps, NEXT is left
5057 NEXT may be the same array as CURRENT. */
5060 follow_key (key
, nmaps
, current
, defs
, next
)
5062 Lisp_Object
*current
, *defs
, *next
;
5065 int i
, first_binding
;
5068 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
5069 followed by the corresponding non-meta character.
5070 Put the results into DEFS, since we are going to alter that anyway.
5071 Do not alter CURRENT or NEXT. */
5072 if (INTEGERP (key
) && (XINT (key
) & CHAR_META
))
5074 for (i
= 0; i
< nmaps
; i
++)
5075 if (! NILP (current
[i
]))
5078 def
= get_keyelt (access_keymap (current
[i
],
5079 meta_prefix_char
, 1, 0));
5081 /* Note that since we pass the resulting bindings through
5082 get_keymap_1, non-prefix bindings for meta-prefix-char
5084 defs
[i
] = get_keymap_1 (def
, 0, 1);
5090 XSETINT (key
, XFASTINT (key
) & ~CHAR_META
);
5093 first_binding
= nmaps
;
5094 for (i
= nmaps
- 1; i
>= 0; i
--)
5096 if (! NILP (current
[i
]))
5104 defs
[i
] = get_keyelt (access_keymap (map
, key
, 1, 0));
5105 if (! NILP (defs
[i
]))
5112 /* Given the set of bindings we've found, produce the next set of maps. */
5113 if (first_binding
< nmaps
)
5114 for (i
= 0; i
< nmaps
; i
++)
5115 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0, 1);
5117 return first_binding
;
5120 /* Read a sequence of keys that ends with a non prefix character,
5121 storing it in KEYBUF, a buffer of size BUFSIZE.
5123 Return the length of the key sequence stored.
5124 Return -1 if the user rejected a command menu.
5126 Echo starting immediately unless `prompt' is 0.
5128 Where a key sequence ends depends on the currently active keymaps.
5129 These include any minor mode keymaps active in the current buffer,
5130 the current buffer's local map, and the global map.
5132 If a key sequence has no other bindings, we check Vfunction_key_map
5133 to see if some trailing subsequence might be the beginning of a
5134 function key's sequence. If so, we try to read the whole function
5135 key, and substitute its symbolic name into the key sequence.
5137 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
5138 `double-' events into similar click events, if that would make them
5139 bound. We try to turn `triple-' events first into `double-' events,
5142 If we get a mouse click in a mode line, vertical divider, or other
5143 non-text area, we treat the click as if it were prefixed by the
5144 symbol denoting that area - `mode-line', `vertical-line', or
5147 If the sequence starts with a mouse click, we read the key sequence
5148 with respect to the buffer clicked on, not the current buffer.
5150 If the user switches frames in the midst of a key sequence, we put
5151 off the switch-frame event until later; the next call to
5152 read_char will return it. */
5155 read_key_sequence (keybuf
, bufsize
, prompt
, dont_downcase_last
,
5156 can_return_switch_frame
)
5157 Lisp_Object
*keybuf
;
5160 int dont_downcase_last
;
5161 int can_return_switch_frame
;
5163 int count
= specpdl_ptr
- specpdl
;
5165 /* How many keys there are in the current key sequence. */
5168 /* The length of the echo buffer when we started reading, and
5169 the length of this_command_keys when we started reading. */
5173 /* The number of keymaps we're scanning right now, and the number of
5174 keymaps we have allocated space for. */
5176 int nmaps_allocated
= 0;
5178 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
5179 the current keymaps. */
5182 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
5183 in the current keymaps, or nil where it is not a prefix. */
5184 Lisp_Object
*submaps
;
5186 /* The local map to start out with at start of key sequence. */
5187 Lisp_Object orig_local_map
;
5189 /* 1 if we have already considered switching to the local-map property
5190 of the place where a mouse click occurred. */
5191 int localized_local_map
= 0;
5193 /* The index in defs[] of the first keymap that has a binding for
5194 this key sequence. In other words, the lowest i such that
5195 defs[i] is non-nil. */
5198 /* If t < mock_input, then KEYBUF[t] should be read as the next
5201 We use this to recover after recognizing a function key. Once we
5202 realize that a suffix of the current key sequence is actually a
5203 function key's escape sequence, we replace the suffix with the
5204 function key's binding from Vfunction_key_map. Now keybuf
5205 contains a new and different key sequence, so the echo area,
5206 this_command_keys, and the submaps and defs arrays are wrong. In
5207 this situation, we set mock_input to t, set t to 0, and jump to
5208 restart_sequence; the loop will read keys from keybuf up until
5209 mock_input, thus rebuilding the state; and then it will resume
5210 reading characters from the keyboard. */
5213 /* If the sequence is unbound in submaps[], then
5214 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
5215 and fkey_map is its binding.
5217 These might be > t, indicating that all function key scanning
5218 should hold off until t reaches them. We do this when we've just
5219 recognized a function key, to avoid searching for the function
5220 key's again in Vfunction_key_map. */
5221 int fkey_start
= 0, fkey_end
= 0;
5222 Lisp_Object fkey_map
;
5224 /* Likewise, for key_translation_map. */
5225 int keytran_start
= 0, keytran_end
= 0;
5226 Lisp_Object keytran_map
;
5228 /* If we receive a ``switch-frame'' event in the middle of a key sequence,
5229 we put it off for later. While we're reading, we keep the event here. */
5230 Lisp_Object delayed_switch_frame
;
5232 /* See the comment below... */
5233 #if defined (GOBBLE_FIRST_EVENT)
5234 Lisp_Object first_event
;
5237 Lisp_Object original_uppercase
;
5238 int original_uppercase_position
= -1;
5240 /* Gets around Microsoft compiler limitations. */
5243 struct buffer
*starting_buffer
;
5245 /* Nonzero if we seem to have got the beginning of a binding
5246 in function_key_map. */
5247 int function_key_possible
= 0;
5248 int key_translation_possible
= 0;
5250 /* Save the status of key translation before each step,
5251 so that we can restore this after downcasing. */
5252 Lisp_Object prev_fkey_map
;
5253 Lisp_Object prev_fkey_start
;
5254 Lisp_Object prev_fkey_end
;
5256 Lisp_Object prev_keytran_map
;
5257 Lisp_Object prev_keytran_start
;
5258 Lisp_Object prev_keytran_end
;
5262 last_nonmenu_event
= Qnil
;
5264 delayed_switch_frame
= Qnil
;
5265 fkey_map
= Vfunction_key_map
;
5266 keytran_map
= Vkey_translation_map
;
5268 /* If there is no function-key-map, turn off function key scanning. */
5269 if (NILP (Fkeymapp (Vfunction_key_map
)))
5270 fkey_start
= fkey_end
= bufsize
+ 1;
5272 /* If there is no key-translation-map, turn off scanning. */
5273 if (NILP (Fkeymapp (Vkey_translation_map
)))
5274 keytran_start
= keytran_end
= bufsize
+ 1;
5279 echo_prompt (XSTRING (prompt
)->data
);
5280 else if (cursor_in_echo_area
&& echo_keystrokes
)
5281 /* This doesn't put in a dash if the echo buffer is empty, so
5282 you don't always see a dash hanging out in the minibuffer. */
5286 /* Record the initial state of the echo area and this_command_keys;
5287 we will need to restore them if we replay a key sequence. */
5289 echo_start
= echo_length ();
5290 keys_start
= this_command_key_count
;
5292 #if defined (GOBBLE_FIRST_EVENT)
5293 /* This doesn't quite work, because some of the things that read_char
5294 does cannot safely be bypassed. It seems too risky to try to make
5297 /* Read the first char of the sequence specially, before setting
5298 up any keymaps, in case a filter runs and switches buffers on us. */
5299 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
5301 #endif /* GOBBLE_FIRST_EVENT */
5303 orig_local_map
= get_local_map (PT
, current_buffer
);
5305 /* We jump here when the key sequence has been thoroughly changed, and
5306 we need to rescan it starting from the beginning. When we jump here,
5307 keybuf[0..mock_input] holds the sequence we should reread. */
5310 starting_buffer
= current_buffer
;
5311 function_key_possible
= 0;
5312 key_translation_possible
= 0;
5314 /* Build our list of keymaps.
5315 If we recognize a function key and replace its escape sequence in
5316 keybuf with its symbol, or if the sequence starts with a mouse
5317 click and we need to switch buffers, we jump back here to rebuild
5318 the initial keymaps from the current buffer. */
5322 if (!NILP (current_kboard
->Voverriding_terminal_local_map
)
5323 || !NILP (Voverriding_local_map
))
5325 if (3 > nmaps_allocated
)
5327 submaps
= (Lisp_Object
*) alloca (3 * sizeof (submaps
[0]));
5328 defs
= (Lisp_Object
*) alloca (3 * sizeof (defs
[0]));
5329 nmaps_allocated
= 3;
5332 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
5333 submaps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
5334 if (!NILP (Voverriding_local_map
))
5335 submaps
[nmaps
++] = Voverriding_local_map
;
5339 nmaps
= current_minor_maps (0, &maps
);
5340 if (nmaps
+ 2 > nmaps_allocated
)
5342 submaps
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (submaps
[0]));
5343 defs
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (defs
[0]));
5344 nmaps_allocated
= nmaps
+ 2;
5346 bcopy (maps
, submaps
, nmaps
* sizeof (submaps
[0]));
5347 #ifdef USE_TEXT_PROPERTIES
5348 submaps
[nmaps
++] = orig_local_map
;
5350 submaps
[nmaps
++] = current_buffer
->keymap
;
5353 submaps
[nmaps
++] = current_global_map
;
5356 /* Find an accurate initial value for first_binding. */
5357 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
5358 if (! NILP (submaps
[first_binding
]))
5361 /* Start from the beginning in keybuf. */
5364 /* These are no-ops the first time through, but if we restart, they
5365 revert the echo area and this_command_keys to their original state. */
5366 this_command_key_count
= keys_start
;
5367 if (INTERACTIVE
&& t
< mock_input
)
5368 echo_truncate (echo_start
);
5370 /* If the best binding for the current key sequence is a keymap, or
5371 we may be looking at a function key's escape sequence, keep on
5373 while ((first_binding
< nmaps
&& ! NILP (submaps
[first_binding
]))
5374 || (first_binding
>= nmaps
5376 /* mock input is never part of a function key's sequence. */
5377 && mock_input
<= fkey_start
)
5378 || (first_binding
>= nmaps
5379 && keytran_start
< t
&& key_translation_possible
)
5380 /* Don't return in the middle of a possible function key sequence,
5381 if the only bindings we found were via case conversion.
5382 Thus, if ESC O a has a function-key-map translation
5383 and ESC o has a binding, don't return after ESC O,
5384 so that we can translate ESC O plus the next character. */
5388 int used_mouse_menu
= 0;
5390 /* Where the last real key started. If we need to throw away a
5391 key that has expanded into more than one element of keybuf
5392 (say, a mouse click on the mode line which is being treated
5393 as [mode-line (mouse-...)], then we backtrack to this point
5395 int last_real_key_start
;
5397 /* These variables are analogous to echo_start and keys_start;
5398 while those allow us to restart the entire key sequence,
5399 echo_local_start and keys_local_start allow us to throw away
5401 int echo_local_start
, keys_local_start
, local_first_binding
;
5404 error ("Key sequence too long");
5407 echo_local_start
= echo_length ();
5408 keys_local_start
= this_command_key_count
;
5409 local_first_binding
= first_binding
;
5412 /* These are no-ops, unless we throw away a keystroke below and
5413 jumped back up to replay_key; in that case, these restore the
5414 variables to their original state, allowing us to replay the
5416 if (INTERACTIVE
&& t
< mock_input
)
5417 echo_truncate (echo_local_start
);
5418 this_command_key_count
= keys_local_start
;
5419 first_binding
= local_first_binding
;
5421 /* By default, assume each event is "real". */
5422 last_real_key_start
= t
;
5424 /* Does mock_input indicate that we are re-reading a key sequence? */
5428 add_command_key (key
);
5429 if (echo_keystrokes
)
5433 /* If not, we should actually read a character. */
5436 struct buffer
*buf
= current_buffer
;
5440 KBOARD
*interrupted_kboard
= current_kboard
;
5441 struct frame
*interrupted_frame
= selected_frame
;
5442 if (setjmp (wrong_kboard_jmpbuf
))
5444 if (!NILP (delayed_switch_frame
))
5446 interrupted_kboard
->kbd_queue
5447 = Fcons (delayed_switch_frame
,
5448 interrupted_kboard
->kbd_queue
);
5449 delayed_switch_frame
= Qnil
;
5452 interrupted_kboard
->kbd_queue
5453 = Fcons (keybuf
[--t
], interrupted_kboard
->kbd_queue
);
5455 /* If the side queue is non-empty, ensure it begins with a
5456 switch-frame, so we'll replay it in the right context. */
5457 if (CONSP (interrupted_kboard
->kbd_queue
)
5458 && (key
= XCONS (interrupted_kboard
->kbd_queue
)->car
,
5459 !(EVENT_HAS_PARAMETERS (key
)
5460 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)),
5464 XSETFRAME (frame
, interrupted_frame
);
5465 interrupted_kboard
->kbd_queue
5466 = Fcons (make_lispy_switch_frame (frame
),
5467 interrupted_kboard
->kbd_queue
);
5470 orig_local_map
= get_local_map (PT
, current_buffer
);
5471 goto replay_sequence
;
5474 key
= read_char (NILP (prompt
), nmaps
, submaps
, last_nonmenu_event
,
5478 /* read_char returns t when it shows a menu and the user rejects it.
5483 /* read_char returns -1 at the end of a macro.
5484 Emacs 18 handles this by returning immediately with a
5485 zero, so that's what we'll do. */
5486 if (INTEGERP (key
) && XINT (key
) == -1)
5489 /* The Microsoft C compiler can't handle the goto that
5495 /* If the current buffer has been changed from under us, the
5496 keymap may have changed, so replay the sequence. */
5500 orig_local_map
= get_local_map (PT
, current_buffer
);
5501 goto replay_sequence
;
5504 /* If we have a quit that was typed in another frame, and
5505 quit_throw_to_read_char switched buffers,
5506 replay to get the right keymap. */
5507 if (XINT (key
) == quit_char
&& current_buffer
!= starting_buffer
)
5512 orig_local_map
= get_local_map (PT
, current_buffer
);
5513 goto replay_sequence
;
5519 /* Clicks in non-text areas get prefixed by the symbol
5520 in their CHAR-ADDRESS field. For example, a click on
5521 the mode line is prefixed by the symbol `mode-line'.
5523 Furthermore, key sequences beginning with mouse clicks
5524 are read using the keymaps of the buffer clicked on, not
5525 the current buffer. So we may have to switch the buffer
5528 When we turn one event into two events, we must make sure
5529 that neither of the two looks like the original--so that,
5530 if we replay the events, they won't be expanded again.
5531 If not for this, such reexpansion could happen either here
5532 or when user programs play with this-command-keys. */
5533 if (EVENT_HAS_PARAMETERS (key
))
5537 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
5538 if (EQ (kind
, Qmouse_click
))
5540 Lisp_Object window
, posn
;
5542 window
= POSN_WINDOW (EVENT_START (key
));
5543 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
5546 /* We're looking at the second event of a
5547 sequence which we expanded before. Set
5548 last_real_key_start appropriately. */
5550 last_real_key_start
= t
- 1;
5553 /* Key sequences beginning with mouse clicks are
5554 read using the keymaps in the buffer clicked on,
5555 not the current buffer. If we're at the
5556 beginning of a key sequence, switch buffers. */
5557 if (last_real_key_start
== 0
5559 && BUFFERP (XWINDOW (window
)->buffer
)
5560 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
5565 /* Arrange to go back to the original buffer once we're
5566 done reading the key sequence. Note that we can't
5567 use save_excursion_{save,restore} here, because they
5568 save point as well as the current buffer; we don't
5569 want to save point, because redisplay may change it,
5570 to accommodate a Fset_window_start or something. We
5571 don't want to do this at the top of the function,
5572 because we may get input from a subprocess which
5573 wants to change the selected window and stuff (say,
5575 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
5577 set_buffer_internal (XBUFFER (XWINDOW (window
)->buffer
));
5578 orig_local_map
= get_local_map (PT
, current_buffer
);
5579 goto replay_sequence
;
5581 /* For a mouse click, get the local text-property keymap
5582 of the place clicked on, rather than point. */
5583 if (last_real_key_start
== 0 && CONSP (XCONS (key
)->cdr
)
5584 && ! localized_local_map
)
5586 Lisp_Object map_here
, start
, pos
;
5588 localized_local_map
= 1;
5589 start
= EVENT_START (key
);
5590 if (CONSP (start
) && CONSP (XCONS (start
)->cdr
))
5592 pos
= POSN_BUFFER_POSN (start
);
5594 && XINT (pos
) >= BEG
&& XINT (pos
) <= Z
)
5596 map_here
= get_local_map (XINT (pos
), current_buffer
);
5597 if (!EQ (map_here
, orig_local_map
))
5599 orig_local_map
= map_here
;
5603 goto replay_sequence
;
5609 /* Expand mode-line and scroll-bar events into two events:
5610 use posn as a fake prefix key. */
5613 if (t
+ 1 >= bufsize
)
5614 error ("Key sequence too long");
5619 /* Zap the position in key, so we know that we've
5620 expanded it, and don't try to do so again. */
5621 POSN_BUFFER_POSN (EVENT_START (key
))
5622 = Fcons (posn
, Qnil
);
5626 else if (EQ (kind
, Qswitch_frame
))
5628 /* If we're at the beginning of a key sequence, and the caller
5629 says it's okay, go ahead and return this event. If we're
5630 in the midst of a key sequence, delay it until the end. */
5631 if (t
> 0 || !can_return_switch_frame
)
5633 delayed_switch_frame
= key
;
5637 else if (CONSP (XCONS (key
)->cdr
)
5638 && CONSP (EVENT_START (key
))
5639 && CONSP (XCONS (EVENT_START (key
))->cdr
))
5643 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
5644 /* Handle menu-bar events:
5645 insert the dummy prefix event `menu-bar'. */
5646 if (EQ (posn
, Qmenu_bar
))
5648 if (t
+ 1 >= bufsize
)
5649 error ("Key sequence too long");
5653 /* Zap the position in key, so we know that we've
5654 expanded it, and don't try to do so again. */
5655 POSN_BUFFER_POSN (EVENT_START (key
))
5656 = Fcons (posn
, Qnil
);
5659 goto replay_sequence
;
5661 else if (CONSP (posn
))
5663 /* We're looking at the second event of a
5664 sequence which we expanded before. Set
5665 last_real_key_start appropriately. */
5666 if (last_real_key_start
== t
&& t
> 0)
5667 last_real_key_start
= t
- 1;
5672 /* We have finally decided that KEY is something we might want
5674 first_binding
= (follow_key (key
,
5675 nmaps
- first_binding
,
5676 submaps
+ first_binding
,
5677 defs
+ first_binding
,
5678 submaps
+ first_binding
)
5681 /* If KEY wasn't bound, we'll try some fallbacks. */
5682 if (first_binding
>= nmaps
)
5686 head
= EVENT_HEAD (key
);
5687 if (help_char_p (head
) && t
> 0)
5689 read_key_sequence_cmd
= Vprefix_help_command
;
5691 last_nonmenu_event
= key
;
5692 /* The Microsoft C compiler can't handle the goto that
5700 Lisp_Object breakdown
;
5703 breakdown
= parse_modifiers (head
);
5704 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
5705 /* Attempt to reduce an unbound mouse event to a simpler
5706 event that is bound:
5707 Drags reduce to clicks.
5708 Double-clicks reduce to clicks.
5709 Triple-clicks reduce to double-clicks, then to clicks.
5710 Down-clicks are eliminated.
5711 Double-downs reduce to downs, then are eliminated.
5712 Triple-downs reduce to double-downs, then to downs,
5713 then are eliminated. */
5714 if (modifiers
& (down_modifier
| drag_modifier
5715 | double_modifier
| triple_modifier
))
5717 while (modifiers
& (down_modifier
| drag_modifier
5718 | double_modifier
| triple_modifier
))
5720 Lisp_Object new_head
, new_click
;
5721 if (modifiers
& triple_modifier
)
5722 modifiers
^= (double_modifier
| triple_modifier
);
5723 else if (modifiers
& double_modifier
)
5724 modifiers
&= ~double_modifier
;
5725 else if (modifiers
& drag_modifier
)
5726 modifiers
&= ~drag_modifier
;
5729 /* Dispose of this `down' event by simply jumping
5730 back to replay_key, to get another event.
5732 Note that if this event came from mock input,
5733 then just jumping back to replay_key will just
5734 hand it to us again. So we have to wipe out any
5737 We could delete keybuf[t] and shift everything
5738 after that to the left by one spot, but we'd also
5739 have to fix up any variable that points into
5740 keybuf, and shifting isn't really necessary
5743 Adding prefixes for non-textual mouse clicks
5744 creates two characters of mock input, and both
5745 must be thrown away. If we're only looking at
5746 the prefix now, we can just jump back to
5747 replay_key. On the other hand, if we've already
5748 processed the prefix, and now the actual click
5749 itself is giving us trouble, then we've lost the
5750 state of the keymaps we want to backtrack to, and
5751 we need to replay the whole sequence to rebuild
5754 Beyond that, only function key expansion could
5755 create more than two keys, but that should never
5756 generate mouse events, so it's okay to zero
5757 mock_input in that case too.
5759 Isn't this just the most wonderful code ever? */
5760 if (t
== last_real_key_start
)
5767 mock_input
= last_real_key_start
;
5768 goto replay_sequence
;
5773 = apply_modifiers (modifiers
, XCONS (breakdown
)->car
);
5775 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
5777 /* Look for a binding for this new key. follow_key
5778 promises that it didn't munge submaps the
5779 last time we called it, since key was unbound. */
5781 = (follow_key (new_click
,
5782 nmaps
- local_first_binding
,
5783 submaps
+ local_first_binding
,
5784 defs
+ local_first_binding
,
5785 submaps
+ local_first_binding
)
5786 + local_first_binding
);
5788 /* If that click is bound, go for it. */
5789 if (first_binding
< nmaps
)
5794 /* Otherwise, we'll leave key set to the drag event. */
5801 /* Normally, last_nonmenu_event gets the previous key we read.
5802 But when a mouse popup menu is being used,
5803 we don't update last_nonmenu_event; it continues to hold the mouse
5804 event that preceded the first level of menu. */
5805 if (!used_mouse_menu
)
5806 last_nonmenu_event
= key
;
5808 prev_fkey_map
= fkey_map
;
5809 prev_fkey_start
= fkey_start
;
5810 prev_fkey_end
= fkey_end
;
5812 prev_keytran_map
= keytran_map
;
5813 prev_keytran_start
= keytran_start
;
5814 prev_keytran_end
= keytran_end
;
5816 /* If the sequence is unbound, see if we can hang a function key
5817 off the end of it. We only want to scan real keyboard input
5818 for function key sequences, so if mock_input says that we're
5819 re-reading old events, don't examine it. */
5820 if (first_binding
>= nmaps
5823 Lisp_Object fkey_next
;
5825 /* Continue scan from fkey_end until we find a bound suffix.
5826 If we fail, increment fkey_start
5827 and start fkey_end from there. */
5828 while (fkey_end
< t
)
5832 key
= keybuf
[fkey_end
++];
5833 /* Look up meta-characters by prefixing them
5834 with meta_prefix_char. I hate this. */
5835 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
5840 (access_keymap (fkey_map
, meta_prefix_char
, 1, 0)),
5842 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
5845 fkey_next
= fkey_map
;
5848 = get_keyelt (access_keymap (fkey_next
, key
, 1, 0));
5850 #if 0 /* I didn't turn this on, because it might cause trouble
5851 for the mapping of return into C-m and tab into C-i. */
5852 /* Optionally don't map function keys into other things.
5853 This enables the user to redefine kp- keys easily. */
5854 if (SYMBOLP (key
) && !NILP (Vinhibit_function_key_mapping
))
5858 /* If the function key map gives a function, not an
5859 array, then call the function with no args and use
5860 its value instead. */
5861 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
5864 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5868 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
5869 fkey_next
= call1 (fkey_next
, prompt
);
5871 /* If the function returned something invalid,
5872 barf--don't ignore it.
5873 (To ignore it safely, we would need to gcpro a bunch of
5874 other variables.) */
5875 if (! (VECTORP (fkey_next
) || STRINGP (fkey_next
)))
5876 error ("Function in function-key-map returns invalid key sequence");
5879 function_key_possible
= ! NILP (fkey_next
);
5881 /* If keybuf[fkey_start..fkey_end] is bound in the
5882 function key map and it's a suffix of the current
5883 sequence (i.e. fkey_end == t), replace it with
5884 the binding and restart with fkey_start at the end. */
5885 if ((VECTORP (fkey_next
) || STRINGP (fkey_next
))
5888 int len
= XFASTINT (Flength (fkey_next
));
5890 t
= fkey_start
+ len
;
5892 error ("Key sequence too long");
5894 if (VECTORP (fkey_next
))
5895 bcopy (XVECTOR (fkey_next
)->contents
,
5896 keybuf
+ fkey_start
,
5897 (t
- fkey_start
) * sizeof (keybuf
[0]));
5898 else if (STRINGP (fkey_next
))
5902 for (i
= 0; i
< len
; i
++)
5903 XSETFASTINT (keybuf
[fkey_start
+ i
],
5904 XSTRING (fkey_next
)->data
[i
]);
5908 fkey_start
= fkey_end
= t
;
5909 fkey_map
= Vfunction_key_map
;
5911 /* Do pass the results through key-translation-map. */
5912 keytran_start
= keytran_end
= 0;
5913 keytran_map
= Vkey_translation_map
;
5915 goto replay_sequence
;
5918 fkey_map
= get_keymap_1 (fkey_next
, 0, 1);
5920 /* If we no longer have a bound suffix, try a new positions for
5922 if (NILP (fkey_map
))
5924 fkey_end
= ++fkey_start
;
5925 fkey_map
= Vfunction_key_map
;
5926 function_key_possible
= 0;
5931 /* Look for this sequence in key-translation-map. */
5933 Lisp_Object keytran_next
;
5935 /* Scan from keytran_end until we find a bound suffix. */
5936 while (keytran_end
< t
)
5940 key
= keybuf
[keytran_end
++];
5941 /* Look up meta-characters by prefixing them
5942 with meta_prefix_char. I hate this. */
5943 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
5948 (access_keymap (keytran_map
, meta_prefix_char
, 1, 0)),
5950 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
5953 keytran_next
= keytran_map
;
5956 = get_keyelt (access_keymap (keytran_next
, key
, 1, 0));
5958 /* If the key translation map gives a function, not an
5959 array, then call the function with no args and use
5960 its value instead. */
5961 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
5962 && keytran_end
== t
)
5964 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5968 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
5969 keytran_next
= call1 (keytran_next
, prompt
);
5971 /* If the function returned something invalid,
5972 barf--don't ignore it.
5973 (To ignore it safely, we would need to gcpro a bunch of
5974 other variables.) */
5975 if (! (VECTORP (keytran_next
) || STRINGP (keytran_next
)))
5976 error ("Function in key-translation-map returns invalid key sequence");
5979 key_translation_possible
= ! NILP (keytran_next
);
5981 /* If keybuf[keytran_start..keytran_end] is bound in the
5982 key translation map and it's a suffix of the current
5983 sequence (i.e. keytran_end == t), replace it with
5984 the binding and restart with keytran_start at the end. */
5985 if ((VECTORP (keytran_next
) || STRINGP (keytran_next
))
5986 && keytran_end
== t
)
5988 int len
= XFASTINT (Flength (keytran_next
));
5990 t
= keytran_start
+ len
;
5992 error ("Key sequence too long");
5994 if (VECTORP (keytran_next
))
5995 bcopy (XVECTOR (keytran_next
)->contents
,
5996 keybuf
+ keytran_start
,
5997 (t
- keytran_start
) * sizeof (keybuf
[0]));
5998 else if (STRINGP (keytran_next
))
6002 for (i
= 0; i
< len
; i
++)
6003 XSETFASTINT (keybuf
[keytran_start
+ i
],
6004 XSTRING (keytran_next
)->data
[i
]);
6008 keytran_start
= keytran_end
= t
;
6009 keytran_map
= Vkey_translation_map
;
6011 /* Don't pass the results of key-translation-map
6012 through function-key-map. */
6013 fkey_start
= fkey_end
= t
;
6014 fkey_map
= Vkey_translation_map
;
6016 goto replay_sequence
;
6019 keytran_map
= get_keymap_1 (keytran_next
, 0, 1);
6021 /* If we no longer have a bound suffix, try a new positions for
6023 if (NILP (keytran_map
))
6025 keytran_end
= ++keytran_start
;
6026 keytran_map
= Vkey_translation_map
;
6027 key_translation_possible
= 0;
6032 /* If KEY is not defined in any of the keymaps,
6033 and cannot be part of a function key or translation,
6034 and is an upper case letter
6035 use the corresponding lower-case letter instead. */
6036 if (first_binding
== nmaps
&& ! function_key_possible
6037 && ! key_translation_possible
6039 && ((((XINT (key
) & 0x3ffff)
6040 < XSTRING (current_buffer
->downcase_table
)->size
)
6041 && UPPERCASEP (XINT (key
) & 0x3ffff))
6042 || (XINT (key
) & shift_modifier
)))
6044 Lisp_Object new_key
;
6046 original_uppercase
= key
;
6047 original_uppercase_position
= t
- 1;
6049 if (XINT (new_key
) & shift_modifier
)
6050 XSETINT (new_key
, XINT (key
) & ~shift_modifier
);
6052 XSETINT (new_key
, (DOWNCASE (XINT (key
) & 0x3ffff)
6053 | (XINT (key
) & ~0x3ffff)));
6055 /* We have to do this unconditionally, regardless of whether
6056 the lower-case char is defined in the keymaps, because they
6057 might get translated through function-key-map. */
6058 keybuf
[t
- 1] = new_key
;
6061 fkey_map
= prev_fkey_map
;
6062 fkey_start
= prev_fkey_start
;
6063 fkey_end
= prev_fkey_end
;
6065 keytran_map
= prev_keytran_map
;
6066 keytran_start
= prev_keytran_start
;
6067 keytran_end
= prev_keytran_end
;
6069 goto replay_sequence
;
6071 /* If KEY is not defined in any of the keymaps,
6072 and cannot be part of a function key or translation,
6073 and is a shifted function key,
6074 use the corresponding unshifted function key instead. */
6075 if (first_binding
== nmaps
&& ! function_key_possible
6076 && ! key_translation_possible
6079 Lisp_Object breakdown
;
6082 breakdown
= parse_modifiers (key
);
6083 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
6084 if (modifiers
& shift_modifier
)
6086 Lisp_Object new_key
;
6088 original_uppercase
= key
;
6089 original_uppercase_position
= t
- 1;
6091 modifiers
&= ~shift_modifier
;
6092 new_key
= apply_modifiers (modifiers
,
6093 XCONS (breakdown
)->car
);
6095 keybuf
[t
- 1] = new_key
;
6098 fkey_map
= prev_fkey_map
;
6099 fkey_start
= prev_fkey_start
;
6100 fkey_end
= prev_fkey_end
;
6102 keytran_map
= prev_keytran_map
;
6103 keytran_start
= prev_keytran_start
;
6104 keytran_end
= prev_keytran_end
;
6106 goto replay_sequence
;
6112 read_key_sequence_cmd
= (first_binding
< nmaps
6113 ? defs
[first_binding
]
6116 unread_switch_frame
= delayed_switch_frame
;
6117 unbind_to (count
, Qnil
);
6119 /* Don't downcase the last character if the caller says don't.
6120 Don't downcase it if the result is undefined, either. */
6121 if ((dont_downcase_last
|| first_binding
>= nmaps
)
6122 && t
- 1 == original_uppercase_position
)
6123 keybuf
[t
- 1] = original_uppercase
;
6125 /* Occasionally we fabricate events, perhaps by expanding something
6126 according to function-key-map, or by adding a prefix symbol to a
6127 mouse click in the scroll bar or modeline. In this cases, return
6128 the entire generated key sequence, even if we hit an unbound
6129 prefix or a definition before the end. This means that you will
6130 be able to push back the event properly, and also means that
6131 read-key-sequence will always return a logical unit.
6134 for (; t
< mock_input
; t
++)
6136 if (echo_keystrokes
)
6137 echo_char (keybuf
[t
]);
6138 add_command_key (keybuf
[t
]);
6144 #if 0 /* This doc string is too long for some compilers.
6145 This commented-out definition serves for DOC. */
6146 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
6147 "Read a sequence of keystrokes and return as a string or vector.\n\
6148 The sequence is sufficient to specify a non-prefix command in the\n\
6149 current local and global maps.\n\
6151 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
6152 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
6153 as a continuation of the previous key.\n\
6155 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not\n\
6156 convert the last event to lower case. (Normally any upper case event\n\
6157 is converted to lower case if the original event is undefined and the lower\n\
6158 case equivalent is defined.) A non-nil value is appropriate for reading\n\
6159 a key sequence to be defined.\n\
6161 A C-g typed while in this function is treated like any other character,\n\
6162 and `quit-flag' is not set.\n\
6164 If the key sequence starts with a mouse click, then the sequence is read\n\
6165 using the keymaps of the buffer of the window clicked in, not the buffer\n\
6166 of the selected window as normal.\n\
6168 `read-key-sequence' drops unbound button-down events, since you normally\n\
6169 only care about the click or drag events which follow them. If a drag\n\
6170 or multi-click event is unbound, but the corresponding click event would\n\
6171 be bound, `read-key-sequence' turns the event into a click event at the\n\
6172 drag's starting position. This means that you don't have to distinguish\n\
6173 between click and drag, double, or triple events unless you want to.\n\
6175 `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\
6176 lines separating windows, and scroll bars with imaginary keys\n\
6177 `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\
6179 Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this\n\
6180 function will process a switch-frame event if the user switches frames\n\
6181 before typing anything. If the user switches frames in the middle of a\n\
6182 key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME\n\
6183 is nil, then the event will be put off until after the current key sequence.\n\
6185 `read-key-sequence' checks `function-key-map' for function key\n\
6186 sequences, where they wouldn't conflict with ordinary bindings. See\n\
6187 `function-key-map' for more details.")
6188 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
)
6191 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
6193 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
)
6194 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
6195 Lisp_Object can_return_switch_frame
;
6197 Lisp_Object keybuf
[30];
6199 struct gcpro gcpro1
, gcpro2
;
6202 CHECK_STRING (prompt
, 0);
6205 bzero (keybuf
, sizeof keybuf
);
6207 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
6209 if (NILP (continue_echo
))
6210 this_command_key_count
= 0;
6212 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
6213 prompt
, ! NILP (dont_downcase_last
),
6214 ! NILP (can_return_switch_frame
));
6222 return make_event_array (i
, keybuf
);
6225 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 2, 0,
6226 "Execute CMD as an editor command.\n\
6227 CMD must be a symbol that satisfies the `commandp' predicate.\n\
6228 Optional second arg RECORD-FLAG non-nil\n\
6229 means unconditionally put this command in `command-history'.\n\
6230 Otherwise, that is done only if an arg is read using the minibuffer.")
6232 Lisp_Object cmd
, record
;
6234 register Lisp_Object final
;
6235 register Lisp_Object tem
;
6236 Lisp_Object prefixarg
;
6237 struct backtrace backtrace
;
6238 extern int debug_on_next_call
;
6240 prefixarg
= current_kboard
->Vprefix_arg
;
6241 current_kboard
->Vprefix_arg
= Qnil
;
6242 Vcurrent_prefix_arg
= prefixarg
;
6243 debug_on_next_call
= 0;
6247 tem
= Fget (cmd
, Qdisabled
);
6248 if (!NILP (tem
) && !NILP (Vrun_hooks
))
6250 tem
= Fsymbol_value (Qdisabled_command_hook
);
6252 return call1 (Vrun_hooks
, Qdisabled_command_hook
);
6258 final
= Findirect_function (cmd
);
6260 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
6261 do_autoload (final
, cmd
);
6266 if (STRINGP (final
) || VECTORP (final
))
6268 /* If requested, place the macro in the command history. For
6269 other sorts of commands, call-interactively takes care of
6273 = Fcons (Fcons (Qexecute_kbd_macro
,
6274 Fcons (final
, Fcons (prefixarg
, Qnil
))),
6277 return Fexecute_kbd_macro (final
, prefixarg
);
6279 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
6281 backtrace
.next
= backtrace_list
;
6282 backtrace_list
= &backtrace
;
6283 backtrace
.function
= &Qcall_interactively
;
6284 backtrace
.args
= &cmd
;
6285 backtrace
.nargs
= 1;
6286 backtrace
.evalargs
= 0;
6288 tem
= Fcall_interactively (cmd
, record
);
6290 backtrace_list
= backtrace
.next
;
6296 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
6298 "Read function name, then read its arguments and call it.")
6300 Lisp_Object prefixarg
;
6302 Lisp_Object function
;
6304 Lisp_Object saved_keys
;
6305 struct gcpro gcpro1
;
6307 saved_keys
= Fvector (this_command_key_count
,
6308 XVECTOR (this_command_keys
)->contents
);
6310 GCPRO1 (saved_keys
);
6312 if (EQ (prefixarg
, Qminus
))
6314 else if (CONSP (prefixarg
) && XINT (XCONS (prefixarg
)->car
) == 4)
6315 strcpy (buf
, "C-u ");
6316 else if (CONSP (prefixarg
) && INTEGERP (XCONS (prefixarg
)->car
))
6318 if (sizeof (int) == sizeof (EMACS_INT
))
6319 sprintf (buf
, "%d ", XINT (XCONS (prefixarg
)->car
));
6320 else if (sizeof (long) == sizeof (EMACS_INT
))
6321 sprintf (buf
, "%ld ", XINT (XCONS (prefixarg
)->car
));
6325 else if (INTEGERP (prefixarg
))
6327 if (sizeof (int) == sizeof (EMACS_INT
))
6328 sprintf (buf
, "%d ", XINT (prefixarg
));
6329 else if (sizeof (long) == sizeof (EMACS_INT
))
6330 sprintf (buf
, "%ld ", XINT (prefixarg
));
6335 /* This isn't strictly correct if execute-extended-command
6336 is bound to anything else. Perhaps it should use
6337 this_command_keys? */
6338 strcat (buf
, "M-x ");
6340 /* Prompt with buf, and then read a string, completing from and
6341 restricting to the set of all defined commands. Don't provide
6342 any initial input. Save the command read on the extended-command
6344 function
= Fcompleting_read (build_string (buf
),
6345 Vobarray
, Qcommandp
,
6346 Qt
, Qnil
, Qextended_command_history
);
6348 /* Set this_command_keys to the concatenation of saved_keys and
6349 function, followed by a RET. */
6351 struct Lisp_String
*str
;
6356 this_command_key_count
= 0;
6358 keys
= XVECTOR (saved_keys
)->contents
;
6359 for (i
= 0; i
< XVECTOR (saved_keys
)->size
; i
++)
6360 add_command_key (keys
[i
]);
6362 str
= XSTRING (function
);
6363 for (i
= 0; i
< str
->size
; i
++)
6365 XSETFASTINT (tem
, str
->data
[i
]);
6366 add_command_key (tem
);
6369 XSETFASTINT (tem
, '\015');
6370 add_command_key (tem
);
6375 function
= Fintern (function
, Qnil
);
6376 current_kboard
->Vprefix_arg
= prefixarg
;
6377 this_command
= function
;
6379 /* If enabled, show which key runs this command. */
6380 if (!NILP (Vsuggest_key_bindings
)
6381 && SYMBOLP (function
))
6383 Lisp_Object
*maps
, bindings
;
6387 nmaps
= current_active_maps (&maps
);
6389 for (i
= 0; i
< nmaps
&& NILP (bindings
); i
++)
6390 bindings
= Fwhere_is_internal (function
, maps
[i
], Qt
, Qnil
);
6394 if (!NILP (bindings
))
6396 message ("You can run the command `%s' by typing %s",
6397 XSYMBOL (function
)->name
->data
,
6398 XSTRING (Fkey_description (bindings
))->data
);
6399 Fsit_for ((NUMBERP (Vsuggest_key_bindings
)
6400 ? Vsuggest_key_bindings
: make_number (2)),
6405 return Fcommand_execute (function
, Qt
);
6408 /* Find the set of keymaps now active.
6409 Store into *MAPS_P a vector holding the various maps
6410 and return the number of them. The vector was malloc'd
6411 and the caller should free it. */
6414 current_active_maps (maps_p
)
6415 Lisp_Object
**maps_p
;
6417 Lisp_Object
*tmaps
, *maps
;
6420 /* Should overriding-terminal-local-map and overriding-local-map apply? */
6421 if (!NILP (Voverriding_local_map_menu_flag
))
6423 /* Yes, use them (if non-nil) as well as the global map. */
6424 maps
= (Lisp_Object
*) xmalloc (3 * sizeof (maps
[0]));
6426 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
6427 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
6428 if (!NILP (Voverriding_local_map
))
6429 maps
[nmaps
++] = Voverriding_local_map
;
6433 /* No, so use major and minor mode keymaps. */
6434 nmaps
= current_minor_maps (NULL
, &tmaps
);
6435 maps
= (Lisp_Object
*) xmalloc ((nmaps
+ 2) * sizeof (maps
[0]));
6436 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
6437 #ifdef USE_TEXT_PROPERTIES
6438 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
6440 maps
[nmaps
++] = current_buffer
->keymap
;
6443 maps
[nmaps
++] = current_global_map
;
6450 detect_input_pending ()
6453 get_input_pending (&input_pending
);
6455 return input_pending
;
6458 /* This is called in some cases before a possible quit.
6459 It cases the next call to detect_input_pending to recompute input_pending.
6460 So calling this function unnecessarily can't do any harm. */
6461 clear_input_pending ()
6466 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
6467 "T if command input is currently available with no waiting.\n\
6468 Actually, the value is nil only if we can be sure that no input is available.")
6471 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1)
6474 return detect_input_pending () ? Qt
: Qnil
;
6477 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
6478 "Return vector of last 100 events, not counting those from keyboard macros.")
6481 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
6484 if (total_keys
< NUM_RECENT_KEYS
)
6485 return Fvector (total_keys
, keys
);
6488 val
= Fvector (NUM_RECENT_KEYS
, keys
);
6489 bcopy (keys
+ recent_keys_index
,
6490 XVECTOR (val
)->contents
,
6491 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
6493 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
6494 recent_keys_index
* sizeof (Lisp_Object
));
6499 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
6500 "Return the key sequence that invoked this command.\n\
6501 The value is a string or a vector.")
6504 return make_event_array (this_command_key_count
,
6505 XVECTOR (this_command_keys
)->contents
);
6508 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths
,
6509 Sreset_this_command_lengths
, 0, 0, 0,
6510 "Used for complicated reasons in `universal-argument-other-key'.\n\
6512 `universal-argument-other-key' rereads the event just typed.\n\
6513 It then gets translated through `function-key-map'.\n\
6514 The translated event gets included in the echo area and in\n\
6515 the value of `this-command-keys' in addition to the raw original event.\n\
6516 That is not right.\n\
6518 Calling this function directs the translated event to replace\n\
6519 the original event, so that only one version of the event actually\n\
6520 appears in the echo area and in the value of `this-command-keys.'.")
6523 before_command_restore_flag
= 1;
6524 before_command_key_count_1
= before_command_key_count
;
6525 before_command_echo_length_1
= before_command_echo_length
;
6528 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
6529 "Return the current depth in recursive edits.")
6533 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
6537 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
6538 "FOpen dribble file: ",
6539 "Start writing all keyboard characters to a dribble file called FILE.\n\
6540 If FILE is nil, close any open dribble file.")
6554 file
= Fexpand_file_name (file
, Qnil
);
6555 dribble
= fopen (XSTRING (file
)->data
, "w");
6560 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
6561 "Discard the contents of the terminal input buffer.\n\
6562 Also cancel any kbd macro being defined.")
6565 current_kboard
->defining_kbd_macro
= Qnil
;
6566 update_mode_lines
++;
6568 Vunread_command_events
= Qnil
;
6569 unread_command_char
= -1;
6571 discard_tty_input ();
6573 /* Without the cast, GCC complains that this assignment loses the
6574 volatile qualifier of kbd_store_ptr. Is there anything wrong
6576 kbd_fetch_ptr
= (struct input_event
*) kbd_store_ptr
;
6577 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
6583 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
6584 "Stop Emacs and return to superior process. You can resume later.\n\
6585 If `cannot-suspend' is non-nil, or if the system doesn't support job\n\
6586 control, run a subshell instead.\n\n\
6587 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
6588 to be read as terminal input by Emacs's parent, after suspension.\n\
6590 Before suspending, run the normal hook `suspend-hook'.\n\
6591 After resumption run the normal hook `suspend-resume-hook'.\n\
6593 Some operating systems cannot stop the Emacs process and resume it later.\n\
6594 On such systems, Emacs starts a subshell instead of suspending.")
6596 Lisp_Object stuffstring
;
6599 int count
= specpdl_ptr
- specpdl
;
6600 int old_height
, old_width
;
6602 struct gcpro gcpro1
, gcpro2
;
6603 extern init_sys_modes ();
6605 if (!NILP (stuffstring
))
6606 CHECK_STRING (stuffstring
, 0);
6608 /* Run the functions in suspend-hook. */
6609 if (!NILP (Vrun_hooks
))
6610 call1 (Vrun_hooks
, intern ("suspend-hook"));
6612 GCPRO1 (stuffstring
);
6613 get_frame_size (&old_width
, &old_height
);
6615 /* sys_suspend can get an error if it tries to fork a subshell
6616 and the system resources aren't available for that. */
6617 record_unwind_protect (init_sys_modes
, 0);
6618 stuff_buffered_input (stuffstring
);
6623 unbind_to (count
, Qnil
);
6625 /* Check if terminal/window size has changed.
6626 Note that this is not useful when we are running directly
6627 with a window system; but suspend should be disabled in that case. */
6628 get_frame_size (&width
, &height
);
6629 if (width
!= old_width
|| height
!= old_height
)
6630 change_frame_size (selected_frame
, height
, width
, 0, 0);
6632 /* Run suspend-resume-hook. */
6633 if (!NILP (Vrun_hooks
))
6634 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
6640 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
6641 Then in any case stuff anything Emacs has read ahead and not used. */
6643 stuff_buffered_input (stuffstring
)
6644 Lisp_Object stuffstring
;
6646 /* stuff_char works only in BSD, versions 4.2 and up. */
6649 register unsigned char *p
;
6651 if (STRINGP (stuffstring
))
6655 p
= XSTRING (stuffstring
)->data
;
6656 count
= XSTRING (stuffstring
)->size
;
6661 /* Anything we have read ahead, put back for the shell to read. */
6662 /* ?? What should this do when we have multiple keyboards??
6663 Should we ignore anything that was typed in at the "wrong" kboard? */
6664 for (; kbd_fetch_ptr
!= kbd_store_ptr
; kbd_fetch_ptr
++)
6666 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
6667 kbd_fetch_ptr
= kbd_buffer
;
6668 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
6669 stuff_char (kbd_fetch_ptr
->code
);
6670 kbd_fetch_ptr
->kind
= no_event
;
6671 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_fetch_ptr
6677 #endif /* BSD and not BSD4_1 */
6680 set_waiting_for_input (time_to_clear
)
6681 EMACS_TIME
*time_to_clear
;
6683 input_available_clear_time
= time_to_clear
;
6685 /* Tell interrupt_signal to throw back to read_char, */
6686 waiting_for_input
= 1;
6688 /* If interrupt_signal was called before and buffered a C-g,
6689 make it run again now, to avoid timing error. */
6690 if (!NILP (Vquit_flag
))
6691 quit_throw_to_read_char ();
6694 clear_waiting_for_input ()
6696 /* Tell interrupt_signal not to throw back to read_char, */
6697 waiting_for_input
= 0;
6698 input_available_clear_time
= 0;
6701 /* This routine is called at interrupt level in response to C-G.
6702 If interrupt_input, this is the handler for SIGINT.
6703 Otherwise, it is called from kbd_buffer_store_event,
6704 in handling SIGIO or SIGTINT.
6706 If `waiting_for_input' is non zero, then unless `echoing' is nonzero,
6707 immediately throw back to read_char.
6709 Otherwise it sets the Lisp variable quit-flag not-nil.
6710 This causes eval to throw, when it gets a chance.
6711 If quit-flag is already non-nil, it stops the job right away. */
6714 interrupt_signal (signalnum
) /* If we don't have an argument, */
6715 int signalnum
; /* some compilers complain in signal calls. */
6718 /* Must preserve main program's value of errno. */
6719 int old_errno
= errno
;
6722 if (!read_socket_hook
&& NILP (Vwindow_system
))
6724 /* USG systems forget handlers when they are used;
6725 must reestablish each time */
6726 signal (SIGINT
, interrupt_signal
);
6727 signal (SIGQUIT
, interrupt_signal
);
6733 if (!NILP (Vquit_flag
) && FRAME_TERMCAP_P (selected_frame
))
6738 #ifdef SIGTSTP /* Support possible in later USG versions */
6740 * On systems which can suspend the current process and return to the original
6741 * shell, this command causes the user to end up back at the shell.
6742 * The "Auto-save" and "Abort" questions are not asked until
6743 * the user elects to return to emacs, at which point he can save the current
6744 * job and either dump core or continue.
6749 if (sys_suspend () == -1)
6751 printf ("Not running as a subprocess;\n");
6752 printf ("you can continue or abort.\n");
6755 /* Perhaps should really fork an inferior shell?
6756 But that would not provide any way to get back
6757 to the original shell, ever. */
6758 printf ("No support for stopping a process on this operating system;\n");
6759 printf ("you can continue or abort.\n");
6760 #endif /* not VMS */
6761 #endif /* not SIGTSTP */
6763 /* We must remain inside the screen area when the internal terminal
6764 is used. Note that [Enter] is not echoed by dos. */
6767 printf ("Auto-save? (y or n) ");
6769 if (((c
= getchar ()) & ~040) == 'Y')
6771 Fdo_auto_save (Qt
, Qnil
);
6773 printf ("\r\nAuto-save done");
6774 #else /* not MSDOS */
6775 printf ("Auto-save done\n");
6776 #endif /* not MSDOS */
6778 while (c
!= '\n') c
= getchar ();
6780 printf ("\r\nAbort? (y or n) ");
6781 #else /* not MSDOS */
6783 printf ("Abort (and enter debugger)? (y or n) ");
6785 printf ("Abort (and dump core)? (y or n) ");
6786 #endif /* not VMS */
6787 #endif /* not MSDOS */
6789 if (((c
= getchar ()) & ~040) == 'Y')
6791 while (c
!= '\n') c
= getchar ();
6793 printf ("\r\nContinuing...\r\n");
6794 #else /* not MSDOS */
6795 printf ("Continuing...\n");
6796 #endif /* not MSDOS */
6802 /* If executing a function that wants to be interrupted out of
6803 and the user has not deferred quitting by binding `inhibit-quit'
6804 then quit right away. */
6805 if (immediate_quit
&& NILP (Vinhibit_quit
))
6809 Fsignal (Qquit
, Qnil
);
6812 /* Else request quit when it's safe */
6816 if (waiting_for_input
&& !echoing
)
6817 quit_throw_to_read_char ();
6822 /* Handle a C-g by making read_char return C-g. */
6824 quit_throw_to_read_char ()
6826 quit_error_check ();
6828 /* Prevent another signal from doing this before we finish. */
6829 clear_waiting_for_input ();
6832 Vunread_command_events
= Qnil
;
6833 unread_command_char
= -1;
6835 #if 0 /* Currently, sit_for is called from read_char without turning
6836 off polling. And that can call set_waiting_for_input.
6837 It seems to be harmless. */
6838 #ifdef POLL_FOR_INPUT
6839 /* May be > 1 if in recursive minibuffer. */
6840 if (poll_suppress_count
== 0)
6845 if (FRAMEP (internal_last_event_frame
)
6846 && XFRAME (internal_last_event_frame
) != selected_frame
)
6847 do_switch_frame (make_lispy_switch_frame (internal_last_event_frame
),
6851 _longjmp (getcjmp
, 1);
6854 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
6855 "Set mode of reading keyboard input.\n\
6856 First arg INTERRUPT non-nil means use input interrupts;\n\
6857 nil means use CBREAK mode.\n\
6858 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
6859 (no effect except in CBREAK mode).\n\
6860 Third arg META t means accept 8-bit input (for a Meta key).\n\
6861 META nil means ignore the top bit, on the assumption it is parity.\n\
6862 Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\
6863 Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\
6864 See also `current-input-mode'.")
6865 (interrupt
, flow
, meta
, quit
)
6866 Lisp_Object interrupt
, flow
, meta
, quit
;
6869 && (!INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400))
6870 error ("set-input-mode: QUIT must be an ASCII character");
6872 #ifdef POLL_FOR_INPUT
6877 /* this causes startup screen to be restored and messes with the mouse */
6882 /* Note SIGIO has been undef'd if FIONREAD is missing. */
6883 if (read_socket_hook
)
6885 /* When using X, don't give the user a real choice,
6886 because we haven't implemented the mechanisms to support it. */
6887 #ifdef NO_SOCK_SIGIO
6888 interrupt_input
= 0;
6889 #else /* not NO_SOCK_SIGIO */
6890 interrupt_input
= 1;
6891 #endif /* NO_SOCK_SIGIO */
6894 interrupt_input
= !NILP (interrupt
);
6895 #else /* not SIGIO */
6896 interrupt_input
= 0;
6897 #endif /* not SIGIO */
6899 /* Our VMS input only works by interrupts, as of now. */
6901 interrupt_input
= 1;
6904 flow_control
= !NILP (flow
);
6907 else if (EQ (meta
, Qt
))
6912 /* Don't let this value be out of range. */
6913 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
6919 #ifdef POLL_FOR_INPUT
6920 poll_suppress_count
= 1;
6926 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
6927 "Return information about the way Emacs currently reads keyboard input.\n\
6928 The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
6929 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\
6930 nil, Emacs is using CBREAK mode.\n\
6931 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\
6932 terminal; this does not apply if Emacs uses interrupt-driven input.\n\
6933 META is t if accepting 8-bit input with 8th bit as Meta flag.\n\
6934 META nil means ignoring the top bit, on the assumption it is parity.\n\
6935 META is neither t nor nil if accepting 8-bit input and using\n\
6936 all 8 bits as the character code.\n\
6937 QUIT is the character Emacs currently uses to quit.\n\
6938 The elements of this list correspond to the arguments of\n\
6944 val
[0] = interrupt_input
? Qt
: Qnil
;
6945 val
[1] = flow_control
? Qt
: Qnil
;
6946 val
[2] = meta_key
== 2 ? make_number (0) : meta_key
== 1 ? Qt
: Qnil
;
6947 XSETFASTINT (val
[3], quit_char
);
6949 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
6954 * Set up a new kboard object with reasonable initial values.
6960 kb
->Voverriding_terminal_local_map
= Qnil
;
6961 kb
->Vlast_command
= Qnil
;
6962 kb
->Vprefix_arg
= Qnil
;
6963 kb
->kbd_queue
= Qnil
;
6964 kb
->kbd_queue_has_data
= 0;
6965 kb
->immediate_echo
= 0;
6966 kb
->echoptr
= kb
->echobuf
;
6967 kb
->echo_after_prompt
= -1;
6968 kb
->kbd_macro_buffer
= 0;
6969 kb
->kbd_macro_bufsize
= 0;
6970 kb
->defining_kbd_macro
= Qnil
;
6971 kb
->Vlast_kbd_macro
= Qnil
;
6972 kb
->reference_count
= 0;
6973 kb
->Vsystem_key_alist
= Qnil
;
6974 kb
->system_key_syms
= Qnil
;
6975 kb
->Vdefault_minibuffer_frame
= Qnil
;
6979 * Destroy the contents of a kboard object, but not the object itself.
6980 * We use this just before deleteing it, or if we're going to initialize
6987 if (kb
->kbd_macro_buffer
)
6988 xfree (kb
->kbd_macro_buffer
);
6997 for (kbp
= &all_kboards
; *kbp
!= kb
; kbp
= &(*kbp
)->next_kboard
)
7000 *kbp
= kb
->next_kboard
;
7008 /* This is correct before outermost invocation of the editor loop */
7009 command_loop_level
= -1;
7011 quit_char
= Ctl ('g');
7012 Vunread_command_events
= Qnil
;
7013 unread_command_char
= -1;
7015 recent_keys_index
= 0;
7016 kbd_fetch_ptr
= kbd_buffer
;
7017 kbd_store_ptr
= kbd_buffer
;
7018 kbd_buffer_frame_or_window
7019 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
7021 do_mouse_tracking
= Qnil
;
7026 /* This means that command_loop_1 won't try to select anything the first
7028 internal_last_event_frame
= Qnil
;
7029 Vlast_event_frame
= internal_last_event_frame
;
7033 current_kboard
= initial_kboard
;
7035 wipe_kboard (current_kboard
);
7036 init_kboard (current_kboard
);
7039 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
7041 kbd_buffer_frame_or_window
7042 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
7043 if (!noninteractive
&& !read_socket_hook
&& NILP (Vwindow_system
))
7045 signal (SIGINT
, interrupt_signal
);
7046 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
7047 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
7048 SIGQUIT and we can't tell which one it will give us. */
7049 signal (SIGQUIT
, interrupt_signal
);
7050 #endif /* HAVE_TERMIO */
7052 /* Note SIGIO has been undef'd if FIONREAD is missing. */
7054 if (!noninteractive
)
7055 signal (SIGIO
, input_available_signal
);
7058 /* Use interrupt input by default, if it works and noninterrupt input
7059 has deficiencies. */
7061 #ifdef INTERRUPT_INPUT
7062 interrupt_input
= 1;
7064 interrupt_input
= 0;
7067 /* Our VMS input only works by interrupts, as of now. */
7069 interrupt_input
= 1;
7075 if (keyboard_init_hook
)
7076 (*keyboard_init_hook
) ();
7078 #ifdef POLL_FOR_INPUT
7079 poll_suppress_count
= 1;
7084 /* This type's only use is in syms_of_keyboard, to initialize the
7085 event header symbols and put properties on them. */
7092 struct event_head head_table
[] = {
7093 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
7094 &Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
,
7095 &Qswitch_frame
, "switch-frame", &Qswitch_frame
,
7096 &Qdelete_frame
, "delete-frame", &Qdelete_frame
,
7097 &Qiconify_frame
, "iconify-frame", &Qiconify_frame
,
7098 &Qmake_frame_visible
, "make-frame-visible", &Qmake_frame_visible
,
7103 Qdisabled_command_hook
= intern ("disabled-command-hook");
7104 staticpro (&Qdisabled_command_hook
);
7106 Qself_insert_command
= intern ("self-insert-command");
7107 staticpro (&Qself_insert_command
);
7109 Qforward_char
= intern ("forward-char");
7110 staticpro (&Qforward_char
);
7112 Qbackward_char
= intern ("backward-char");
7113 staticpro (&Qbackward_char
);
7115 Qdisabled
= intern ("disabled");
7116 staticpro (&Qdisabled
);
7118 Qundefined
= intern ("undefined");
7119 staticpro (&Qundefined
);
7121 Qpre_command_hook
= intern ("pre-command-hook");
7122 staticpro (&Qpre_command_hook
);
7124 Qpost_command_hook
= intern ("post-command-hook");
7125 staticpro (&Qpost_command_hook
);
7127 Qpost_command_idle_hook
= intern ("post-command-idle-hook");
7128 staticpro (&Qpost_command_idle_hook
);
7130 Qdeferred_action_function
= intern ("deferred-action-function");
7131 staticpro (&Qdeferred_action_function
);
7133 Qcommand_hook_internal
= intern ("command-hook-internal");
7134 staticpro (&Qcommand_hook_internal
);
7136 Qfunction_key
= intern ("function-key");
7137 staticpro (&Qfunction_key
);
7138 Qmouse_click
= intern ("mouse-click");
7139 staticpro (&Qmouse_click
);
7141 Qmenu_enable
= intern ("menu-enable");
7142 staticpro (&Qmenu_enable
);
7144 Qmode_line
= intern ("mode-line");
7145 staticpro (&Qmode_line
);
7146 Qvertical_line
= intern ("vertical-line");
7147 staticpro (&Qvertical_line
);
7148 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
7149 staticpro (&Qvertical_scroll_bar
);
7150 Qmenu_bar
= intern ("menu-bar");
7151 staticpro (&Qmenu_bar
);
7153 Qabove_handle
= intern ("above-handle");
7154 staticpro (&Qabove_handle
);
7155 Qhandle
= intern ("handle");
7156 staticpro (&Qhandle
);
7157 Qbelow_handle
= intern ("below-handle");
7158 staticpro (&Qbelow_handle
);
7160 Qevent_kind
= intern ("event-kind");
7161 staticpro (&Qevent_kind
);
7162 Qevent_symbol_elements
= intern ("event-symbol-elements");
7163 staticpro (&Qevent_symbol_elements
);
7164 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
7165 staticpro (&Qevent_symbol_element_mask
);
7166 Qmodifier_cache
= intern ("modifier-cache");
7167 staticpro (&Qmodifier_cache
);
7169 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
7170 staticpro (&Qrecompute_lucid_menubar
);
7171 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
7172 staticpro (&Qactivate_menubar_hook
);
7174 Qpolling_period
= intern ("polling-period");
7175 staticpro (&Qpolling_period
);
7178 struct event_head
*p
;
7180 for (p
= head_table
;
7181 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
7184 *p
->var
= intern (p
->name
);
7186 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
7187 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
7191 button_down_location
= Fmake_vector (make_number (NUM_MOUSE_BUTTONS
), Qnil
);
7192 staticpro (&button_down_location
);
7196 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
7198 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
7199 for (i
= 0; i
< len
; i
++)
7200 if (modifier_names
[i
])
7201 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
7202 staticpro (&modifier_symbols
);
7205 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
7206 staticpro (&recent_keys
);
7208 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
7209 staticpro (&this_command_keys
);
7211 Qextended_command_history
= intern ("extended-command-history");
7212 Fset (Qextended_command_history
, Qnil
);
7213 staticpro (&Qextended_command_history
);
7215 kbd_buffer_frame_or_window
7216 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
7217 staticpro (&kbd_buffer_frame_or_window
);
7219 accent_key_syms
= Qnil
;
7220 staticpro (&accent_key_syms
);
7222 func_key_syms
= Qnil
;
7223 staticpro (&func_key_syms
);
7226 staticpro (&mouse_syms
);
7228 unread_switch_frame
= Qnil
;
7229 staticpro (&unread_switch_frame
);
7231 defsubr (&Sevent_convert_list
);
7232 defsubr (&Sread_key_sequence
);
7233 defsubr (&Srecursive_edit
);
7235 defsubr (&Strack_mouse
);
7237 defsubr (&Sinput_pending_p
);
7238 defsubr (&Scommand_execute
);
7239 defsubr (&Srecent_keys
);
7240 defsubr (&Sthis_command_keys
);
7241 defsubr (&Sreset_this_command_lengths
);
7242 defsubr (&Ssuspend_emacs
);
7243 defsubr (&Sabort_recursive_edit
);
7244 defsubr (&Sexit_recursive_edit
);
7245 defsubr (&Srecursion_depth
);
7246 defsubr (&Stop_level
);
7247 defsubr (&Sdiscard_input
);
7248 defsubr (&Sopen_dribble_file
);
7249 defsubr (&Sset_input_mode
);
7250 defsubr (&Scurrent_input_mode
);
7251 defsubr (&Sexecute_extended_command
);
7253 DEFVAR_LISP ("last-command-char", &last_command_char
,
7254 "Last input event that was part of a command.");
7256 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char
,
7257 "Last input event that was part of a command.");
7259 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
7260 "Last input event in a command, except for mouse menu events.\n\
7261 Mouse menus give back keys that don't look like mouse events;\n\
7262 this variable holds the actual mouse event that led to the menu,\n\
7263 so that you can determine whether the command was run by mouse or not.");
7265 DEFVAR_LISP ("last-input-char", &last_input_char
,
7266 "Last input event.");
7268 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char
,
7269 "Last input event.");
7271 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
7272 "List of objects to be read as next command input events.");
7274 DEFVAR_INT ("unread-command-char", &unread_command_char
,
7275 "If not -1, an object to be read as next command input event.");
7277 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
7278 "Meta-prefix character code. Meta-foo as command input\n\
7279 turns into this character followed by foo.");
7280 XSETINT (meta_prefix_char
, 033);
7282 DEFVAR_KBOARD ("last-command", Vlast_command
,
7283 "The last command executed. Normally a symbol with a function definition,\n\
7284 but can be whatever was found in the keymap, or whatever the variable\n\
7285 `this-command' was set to by that command.\n\
7287 The value `mode-exit' is special; it means that the previous command\n\
7288 read an event that told it to exit, and it did so and unread that event.\n\
7289 In other words, the present command is the event that made the previous\n\
7292 The value `kill-region' is special; it means that the previous command\n\
7293 was a kill command.");
7295 DEFVAR_LISP ("this-command", &this_command
,
7296 "The command now being executed.\n\
7297 The command can set this variable; whatever is put here\n\
7298 will be in `last-command' during the following command.");
7299 this_command
= Qnil
;
7301 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
7302 "*Number of keyboard input characters between auto-saves.\n\
7303 Zero means disable autosaving due to number of characters typed.");
7304 auto_save_interval
= 300;
7306 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
7307 "*Number of seconds idle time before auto-save.\n\
7308 Zero or nil means disable auto-saving due to idleness.\n\
7309 After auto-saving due to this many seconds of idle time,\n\
7310 Emacs also does a garbage collection if that seems to be warranted.");
7311 XSETFASTINT (Vauto_save_timeout
, 30);
7313 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes
,
7314 "*Nonzero means echo unfinished commands after this many seconds of pause.");
7315 echo_keystrokes
= 1;
7317 DEFVAR_INT ("polling-period", &polling_period
,
7318 "*Interval between polling for input during Lisp execution.\n\
7319 The reason for polling is to make C-g work to stop a running program.\n\
7320 Polling is needed only when using X windows and SIGIO does not work.\n\
7321 Polling is automatically disabled in all other cases.");
7324 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
7325 "*Maximum time between mouse clicks to make a double-click.\n\
7326 Measured in milliseconds. nil means disable double-click recognition;\n\
7327 t means double-clicks have no time limit and are detected\n\
7328 by position only.");
7329 Vdouble_click_time
= make_number (500);
7331 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
7332 "*Non-nil means inhibit local map menu bar menus.");
7333 inhibit_local_menu_bar_menus
= 0;
7335 DEFVAR_INT ("num-input-keys", &num_input_keys
,
7336 "Number of complete keys read from the keyboard so far.");
7339 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
7340 "The frame in which the most recently read event occurred.\n\
7341 If the last event came from a keyboard macro, this is set to `macro'.");
7342 Vlast_event_frame
= Qnil
;
7344 DEFVAR_LISP ("help-char", &Vhelp_char
,
7345 "Character to recognize as meaning Help.\n\
7346 When it is read, do `(eval help-form)', and display result if it's a string.\n\
7347 If the value of `help-form' is nil, this char can be read normally.");
7348 XSETINT (Vhelp_char
, Ctl ('H'));
7350 DEFVAR_LISP ("help-event-list", &Vhelp_event_list
,
7351 "List of input events to recognize as meaning Help.\n\
7352 These work just like the value of `help-char' (see that).");
7353 Vhelp_event_list
= Qnil
;
7355 DEFVAR_LISP ("help-form", &Vhelp_form
,
7356 "Form to execute when character `help-char' is read.\n\
7357 If the form returns a string, that string is displayed.\n\
7358 If `help-form' is nil, the help char is not recognized.");
7361 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
7362 "Command to run when `help-char' character follows a prefix key.\n\
7363 This command is used only when there is no actual binding\n\
7364 for that character after that prefix key.");
7365 Vprefix_help_command
= Qnil
;
7367 DEFVAR_LISP ("top-level", &Vtop_level
,
7368 "Form to evaluate when Emacs starts up.\n\
7369 Useful to set before you dump a modified Emacs.");
7372 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
7373 "String used as translate table for keyboard input, or nil.\n\
7374 Each character is looked up in this string and the contents used instead.\n\
7375 If string is of length N, character codes N and up are untranslated.");
7376 Vkeyboard_translate_table
= Qnil
;
7378 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
7379 "Non-nil means to always spawn a subshell instead of suspending,\n\
7380 even if the operating system has support for stopping a process.");
7383 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
7384 "Non-nil means prompt with menus when appropriate.\n\
7385 This is done when reading from a keymap that has a prompt string,\n\
7386 for elements that have prompt strings.\n\
7387 The menu is displayed on the screen\n\
7388 if X menus were enabled at configuration\n\
7389 time and the previous event was a mouse click prefix key.\n\
7390 Otherwise, menu prompting uses the echo area.");
7393 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
7394 "Character to see next line of menu prompt.\n\
7395 Type this character while in a menu prompt to rotate around the lines of it.");
7396 XSETINT (menu_prompt_more_char
, ' ');
7398 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
7399 "A mask of additional modifier keys to use with every keyboard character.\n\
7400 Emacs applies the modifiers of the character stored here to each keyboard\n\
7401 character it reads. For example, after evaluating the expression\n\
7402 (setq extra-keyboard-modifiers ?\\C-x)\n\
7403 all input characters will have the control modifier applied to them.\n\
7405 Note that the character ?\\C-@, equivalent to the integer zero, does\n\
7406 not count as a control character; rather, it counts as a character\n\
7407 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\
7408 cancels any modification.");
7409 extra_keyboard_modifiers
= 0;
7411 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
7412 "If an editing command sets this to t, deactivate the mark afterward.\n\
7413 The command loop sets this to nil before each command,\n\
7414 and tests the value when the command returns.\n\
7415 Buffer modification stores t in this variable.");
7416 Vdeactivate_mark
= Qnil
;
7418 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
7419 "Temporary storage of pre-command-hook or post-command-hook.");
7420 Vcommand_hook_internal
= Qnil
;
7422 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
7423 "Normal hook run before each command is executed.\n\
7424 Errors running the hook are caught and ignored.");
7425 Vpre_command_hook
= Qnil
;
7427 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
7428 "Normal hook run after each command is executed.\n\
7429 Errors running the hook are caught and ignored.");
7430 Vpost_command_hook
= Qnil
;
7432 DEFVAR_LISP ("post-command-idle-hook", &Vpost_command_idle_hook
,
7433 "Normal hook run after each command is executed, if idle.\n\
7434 Errors running the hook are caught and ignored.");
7435 Vpost_command_idle_hook
= Qnil
;
7437 DEFVAR_INT ("post-command-idle-delay", &post_command_idle_delay
,
7438 "Delay time before running `post-command-idle-delay'.\n\
7439 This is measured in microseconds.");
7440 post_command_idle_delay
= 100000;
7442 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
7443 "t means menu bar, specified Lucid style, needs to be recomputed.");
7444 Vlucid_menu_bar_dirty_flag
= Qnil
;
7446 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
7447 "List of menu bar items to move to the end of the menu bar.\n\
7448 The elements of the list are event types that may have menu bar bindings.");
7449 Vmenu_bar_final_items
= Qnil
;
7451 DEFVAR_KBOARD ("overriding-terminal-local-map",
7452 Voverriding_terminal_local_map
,
7453 "Keymap that overrides all other local keymaps.\n\
7454 If this variable is non-nil, it is used as a keymap instead of the\n\
7455 buffer's local map, and the minor mode keymaps and text property keymaps.");
7457 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
7458 "Keymap that overrides all other local keymaps.\n\
7459 If this variable is non-nil, it is used as a keymap instead of the\n\
7460 buffer's local map, and the minor mode keymaps and text property keymaps.");
7461 Voverriding_local_map
= Qnil
;
7463 DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag
,
7464 "Non-nil means `overriding-local-map' applies to the menu bar.\n\
7465 Otherwise, the menu bar continues to reflect the buffer's local map\n\
7466 and the minor mode maps regardless of `overriding-local-map'.");
7467 Voverriding_local_map_menu_flag
= Qnil
;
7469 DEFVAR_LISP ("special-event-map", &Vspecial_event_map
,
7470 "Keymap defining bindings for special events to execute at low level.");
7471 Vspecial_event_map
= Fcons (intern ("keymap"), Qnil
);
7473 DEFVAR_LISP ("track-mouse", &do_mouse_tracking
,
7474 "*Non-nil means generate motion events for mouse motion.");
7476 DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist
,
7477 "Alist of system-specific X windows key symbols.\n\
7478 Each element should have the form (N . SYMBOL) where N is the\n\
7479 numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\
7480 and SYMBOL is its name.");
7482 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
7483 "List of deferred actions to be performed at a later time.\n\
7484 The precise format isn't relevant here; we just check whether it is nil.");
7485 Vdeferred_action_list
= Qnil
;
7487 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
7488 "Function to call to handle deferred actions, after each command.\n\
7489 This function is called with no arguments after each command\n\
7490 whenever `deferred-action-list' is non-nil.");
7491 Vdeferred_action_function
= Qnil
;
7493 DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings
,
7494 "Non-nil means show the equivalent key-binding when M-x command has one.\n\
7495 The value can be a length of time to show the message for.\n\
7496 If the value is non-nil and not a number, we wait 2 seconds.");
7497 Vsuggest_key_bindings
= Qt
;
7502 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
7503 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
7504 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
7505 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
7506 initial_define_key (meta_map
, 'x', "execute-extended-command");
7508 initial_define_lispy_key (Vspecial_event_map
, "delete-frame",
7509 "handle-delete-frame");
7510 initial_define_lispy_key (Vspecial_event_map
, "iconify-frame",
7512 initial_define_lispy_key (Vspecial_event_map
, "make-frame-visible",