1 /* Keyboard and mouse input; editor command loop.
2 Copyright (C) 1985,86,87,88,89,93,94,95,96,97 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Allow config.h to undefine symbols found here. */
29 #include "termhooks.h"
37 #include "dispextern.h"
40 #include "intervals.h"
41 #include "blockinput.h"
51 #include <sys/ioctl.h>
53 #endif /* not MSDOS */
55 #include "syssignal.h"
58 /* This is to get the definitions of the XK_ symbols. */
65 #endif /* HAVE_NTGUI */
67 /* Include systime.h after xterm.h to avoid double inclusion of time.h. */
72 /* Variables for blockinput.h: */
74 /* Non-zero if interrupt input is blocked right now. */
75 int interrupt_input_blocked
;
77 /* Nonzero means an input interrupt has arrived
78 during the current critical section. */
79 int interrupt_input_pending
;
82 /* File descriptor to use for input. */
85 #ifdef HAVE_WINDOW_SYSTEM
86 /* Make all keyboard buffers much bigger when using X windows. */
87 #define KBD_BUFFER_SIZE 4096
88 #else /* No X-windows, character input */
89 #define KBD_BUFFER_SIZE 256
90 #endif /* No X-windows */
92 /* Following definition copied from eval.c */
96 struct backtrace
*next
;
97 Lisp_Object
*function
;
98 Lisp_Object
*args
; /* Points to vector of args. */
99 int nargs
; /* length of vector. If nargs is UNEVALLED,
100 args points to slot holding list of
106 KBOARD
*initial_kboard
;
107 KBOARD
*current_kboard
;
111 KBOARD the_only_kboard
;
114 /* Non-nil disable property on a command means
115 do not execute it; call disabled-command-hook's value instead. */
116 Lisp_Object Qdisabled
, Qdisabled_command_hook
;
118 #define NUM_RECENT_KEYS (100)
119 int recent_keys_index
; /* Index for storing next element into recent_keys */
120 int total_keys
; /* Total number of elements stored into recent_keys */
121 Lisp_Object recent_keys
; /* A vector, holding the last 100 keystrokes */
123 /* Vector holding the key sequence that invoked the current command.
124 It is reused for each command, and it may be longer than the current
125 sequence; this_command_key_count indicates how many elements
126 actually mean something.
127 It's easier to staticpro a single Lisp_Object than an array. */
128 Lisp_Object this_command_keys
;
129 int this_command_key_count
;
131 /* This vector is used as a buffer to record the events that were actually read
132 by read_key_sequence. */
133 Lisp_Object raw_keybuf
;
134 int raw_keybuf_count
;
136 #define GROW_RAW_KEYBUF \
137 if (raw_keybuf_count == XVECTOR (raw_keybuf)->size) \
139 int newsize = 2 * XVECTOR (raw_keybuf)->size; \
141 new = Fmake_vector (make_number (newsize), Qnil); \
142 bcopy (XVECTOR (raw_keybuf)->contents, XVECTOR (new)->contents, \
143 raw_keybuf_count * sizeof (Lisp_Object)); \
147 /* Number of elements of this_command_keys
148 that precede this key sequence. */
149 int this_single_command_key_start
;
151 /* Record values of this_command_key_count and echo_length ()
152 before this command was read. */
153 static int before_command_key_count
;
154 static int before_command_echo_length
;
155 /* Values of before_command_key_count and before_command_echo_length
156 saved by reset-this-command-lengths. */
157 static int before_command_key_count_1
;
158 static int before_command_echo_length_1
;
159 /* Flag set by reset-this-command-lengths,
160 saying to reset the lengths when add_command_key is called. */
161 static int before_command_restore_flag
;
163 extern int minbuf_level
;
165 extern int message_enable_multibyte
;
167 extern struct backtrace
*backtrace_list
;
169 /* Nonzero means do menu prompting. */
170 static int menu_prompting
;
172 /* Character to see next line of menu prompt. */
173 static Lisp_Object menu_prompt_more_char
;
175 /* For longjmp to where kbd input is being done. */
176 static jmp_buf getcjmp
;
178 /* True while doing kbd input. */
179 int waiting_for_input
;
181 /* True while displaying for echoing. Delays C-g throwing. */
184 /* True means we can start echoing at the next input pause
185 even though there is something in the echo area. */
186 static char *ok_to_echo_at_next_pause
;
188 /* Nonzero means disregard local maps for the menu bar. */
189 static int inhibit_local_menu_bar_menus
;
191 /* Nonzero means C-g should cause immediate error-signal. */
194 /* The user's ERASE setting. */
195 Lisp_Object Vtty_erase_char
;
197 /* Character to recognize as the help char. */
198 Lisp_Object Vhelp_char
;
200 /* List of other event types to recognize as meaning "help". */
201 Lisp_Object Vhelp_event_list
;
203 /* Form to execute when help char is typed. */
204 Lisp_Object Vhelp_form
;
206 /* Command to run when the help character follows a prefix key. */
207 Lisp_Object Vprefix_help_command
;
209 /* List of items that should move to the end of the menu bar. */
210 Lisp_Object Vmenu_bar_final_items
;
212 /* Non-nil means show the equivalent key-binding for
213 any M-x command that has one.
214 The value can be a length of time to show the message for.
215 If the value is non-nil and not a number, we wait 2 seconds. */
216 Lisp_Object Vsuggest_key_bindings
;
218 /* Character that causes a quit. Normally C-g.
220 If we are running on an ordinary terminal, this must be an ordinary
221 ASCII char, since we want to make it our interrupt character.
223 If we are not running on an ordinary terminal, it still needs to be
224 an ordinary ASCII char. This character needs to be recognized in
225 the input interrupt handler. At this point, the keystroke is
226 represented as a struct input_event, while the desired quit
227 character is specified as a lispy event. The mapping from struct
228 input_events to lispy events cannot run in an interrupt handler,
229 and the reverse mapping is difficult for anything but ASCII
232 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
236 extern Lisp_Object current_global_map
;
237 extern int minibuf_level
;
239 /* If non-nil, this is a map that overrides all other local maps. */
240 Lisp_Object Voverriding_local_map
;
242 /* If non-nil, Voverriding_local_map applies to the menu bar. */
243 Lisp_Object Voverriding_local_map_menu_flag
;
245 /* Keymap that defines special misc events that should
246 be processed immediately at a low level. */
247 Lisp_Object Vspecial_event_map
;
249 /* Current depth in recursive edits. */
250 int command_loop_level
;
252 /* Total number of times command_loop has read a key sequence. */
255 /* Last input character read as a command. */
256 Lisp_Object last_command_char
;
258 /* Last input character read as a command, not counting menus
259 reached by the mouse. */
260 Lisp_Object last_nonmenu_event
;
262 /* Last input character read for any purpose. */
263 Lisp_Object last_input_char
;
265 /* If not Qnil, a list of objects to be read as subsequent command input. */
266 Lisp_Object Vunread_command_events
;
268 /* If not Qnil, a list of objects to be read as subsequent command input
269 including input method processing. */
270 Lisp_Object Vunread_input_method_events
;
272 /* If not Qnil, a list of objects to be read as subsequent command input
273 but NOT including input method processing. */
274 Lisp_Object Vunread_post_input_method_events
;
276 /* If not -1, an event to be read as subsequent command input. */
277 int unread_command_char
;
279 /* If not Qnil, this is a switch-frame event which we decided to put
280 off until the end of a key sequence. This should be read as the
281 next command input, after any unread_command_events.
283 read_key_sequence uses this to delay switch-frame events until the
284 end of the key sequence; Fread_char uses it to put off switch-frame
285 events until a non-ASCII event is acceptable as input. */
286 Lisp_Object unread_switch_frame
;
288 /* A mask of extra modifier bits to put into every keyboard char. */
289 int extra_keyboard_modifiers
;
291 /* Char to use as prefix when a meta character is typed in.
292 This is bound on entry to minibuffer in case ESC is changed there. */
294 Lisp_Object meta_prefix_char
;
296 /* Last size recorded for a current buffer which is not a minibuffer. */
297 static int last_non_minibuf_size
;
299 /* Number of idle seconds before an auto-save and garbage collection. */
300 static Lisp_Object Vauto_save_timeout
;
302 /* Total number of times read_char has returned. */
303 int num_input_events
;
305 /* Total number of times read_char has returned, outside of macros. */
306 int num_nonmacro_input_events
;
308 /* Auto-save automatically when this many characters have been typed
309 since the last time. */
311 static int auto_save_interval
;
313 /* Value of num_nonmacro_input_events as of last auto save. */
317 /* The command being executed by the command loop.
318 Commands may set this, and the value set will be copied into
319 current_kboard->Vlast_command instead of the actual command. */
320 Lisp_Object Vthis_command
;
322 /* This is like Vthis_command, except that commands never set it. */
323 Lisp_Object real_this_command
;
325 /* The value of point when the last command was executed. */
326 int last_point_position
;
328 /* The buffer that was current when the last command was started. */
329 Lisp_Object last_point_position_buffer
;
331 /* The frame in which the last input event occurred, or Qmacro if the
332 last event came from a macro. We use this to determine when to
333 generate switch-frame events. This may be cleared by functions
334 like Fselect_frame, to make sure that a switch-frame event is
335 generated by the next character. */
336 Lisp_Object internal_last_event_frame
;
338 /* A user-visible version of the above, intended to allow users to
339 figure out where the last event came from, if the event doesn't
340 carry that information itself (i.e. if it was a character). */
341 Lisp_Object Vlast_event_frame
;
343 /* The timestamp of the last input event we received from the X server.
344 X Windows wants this for selection ownership. */
345 unsigned long last_event_timestamp
;
347 Lisp_Object Qself_insert_command
;
348 Lisp_Object Qforward_char
;
349 Lisp_Object Qbackward_char
;
350 Lisp_Object Qundefined
;
351 Lisp_Object Qtimer_event_handler
;
353 /* read_key_sequence stores here the command definition of the
354 key sequence that it reads. */
355 Lisp_Object read_key_sequence_cmd
;
357 /* Form to evaluate (if non-nil) when Emacs is started. */
358 Lisp_Object Vtop_level
;
360 /* User-supplied string to translate input characters through. */
361 Lisp_Object Vkeyboard_translate_table
;
363 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
364 extern Lisp_Object Vfunction_key_map
;
366 /* Another keymap that maps key sequences into key sequences.
367 This one takes precedence over ordinary definitions. */
368 extern Lisp_Object Vkey_translation_map
;
370 /* If non-nil, this implements the current input method. */
371 Lisp_Object Vinput_method_function
;
372 Lisp_Object Qinput_method_function
;
374 /* When we call Vinput_method_function,
375 this holds the echo area message that was just erased. */
376 Lisp_Object Vinput_method_previous_message
;
378 /* Non-nil means deactivate the mark at end of this command. */
379 Lisp_Object Vdeactivate_mark
;
381 /* Menu bar specified in Lucid Emacs fashion. */
383 Lisp_Object Vlucid_menu_bar_dirty_flag
;
384 Lisp_Object Qrecompute_lucid_menubar
, Qactivate_menubar_hook
;
386 Lisp_Object Qecho_area_clear_hook
;
388 /* Hooks to run before and after each command. */
389 Lisp_Object Qpre_command_hook
, Vpre_command_hook
;
390 Lisp_Object Qpost_command_hook
, Vpost_command_hook
;
391 Lisp_Object Qcommand_hook_internal
, Vcommand_hook_internal
;
392 /* Hook run after a command if there's no more input soon. */
393 Lisp_Object Qpost_command_idle_hook
, Vpost_command_idle_hook
;
395 /* Delay time in microseconds before running post-command-idle-hook. */
396 int post_command_idle_delay
;
398 /* List of deferred actions to be performed at a later time.
399 The precise format isn't relevant here; we just check whether it is nil. */
400 Lisp_Object Vdeferred_action_list
;
402 /* Function to call to handle deferred actions, when there are any. */
403 Lisp_Object Vdeferred_action_function
;
404 Lisp_Object Qdeferred_action_function
;
406 Lisp_Object Qinput_method_exit_on_first_char
;
407 Lisp_Object Qinput_method_use_echo_area
;
409 /* File in which we write all commands we read. */
412 /* Nonzero if input is available. */
415 /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
416 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
420 extern char *pending_malloc_warning
;
422 /* Circular buffer for pre-read keyboard input. */
423 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
425 /* Vector to GCPRO the frames and windows mentioned in kbd_buffer.
427 The interrupt-level event handlers will never enqueue an event on a
428 frame which is not in Vframe_list, and once an event is dequeued,
429 internal_last_event_frame or the event itself points to the frame.
432 But while the event is sitting in the queue, it's completely
433 unprotected. Suppose the user types one command which will run for
434 a while and then delete a frame, and then types another event at
435 the frame that will be deleted, before the command gets around to
436 it. Suppose there are no references to this frame elsewhere in
437 Emacs, and a GC occurs before the second event is dequeued. Now we
438 have an event referring to a freed frame, which will crash Emacs
441 Similar things happen when an event on a scroll bar is enqueued; the
442 window may be deleted while the event is in the queue.
444 So, we use this vector to protect the frame_or_window field in the
445 event queue. That way, they'll be dequeued as dead frames or
446 windows, but still valid lisp objects.
448 If kbd_buffer[i].kind != no_event, then
449 (XVECTOR (kbd_buffer_frame_or_window)->contents[i]
450 == kbd_buffer[i].frame_or_window. */
451 static Lisp_Object kbd_buffer_frame_or_window
;
453 /* Pointer to next available character in kbd_buffer.
454 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
455 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the
456 next available char is in kbd_buffer[0]. */
457 static struct input_event
*kbd_fetch_ptr
;
459 /* Pointer to next place to store character in kbd_buffer. This
460 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
461 character should go in kbd_buffer[0]. */
462 static volatile struct input_event
*kbd_store_ptr
;
464 /* The above pair of variables forms a "queue empty" flag. When we
465 enqueue a non-hook event, we increment kbd_store_ptr. When we
466 dequeue a non-hook event, we increment kbd_fetch_ptr. We say that
467 there is input available iff the two pointers are not equal.
469 Why not just have a flag set and cleared by the enqueuing and
470 dequeuing functions? Such a flag could be screwed up by interrupts
471 at inopportune times. */
473 /* If this flag is non-nil, we check mouse_moved to see when the
474 mouse moves, and motion events will appear in the input stream.
475 Otherwise, mouse motion is ignored. */
476 static Lisp_Object do_mouse_tracking
;
478 /* Symbols to head events. */
479 Lisp_Object Qmouse_movement
;
480 Lisp_Object Qscroll_bar_movement
;
481 Lisp_Object Qswitch_frame
;
482 Lisp_Object Qdelete_frame
;
483 Lisp_Object Qiconify_frame
;
484 Lisp_Object Qmake_frame_visible
;
486 /* Symbols to denote kinds of events. */
487 Lisp_Object Qfunction_key
;
488 Lisp_Object Qmouse_click
;
490 Lisp_Object Qmouse_wheel
;
492 Lisp_Object Qdrag_n_drop
;
493 /* Lisp_Object Qmouse_movement; - also an event header */
495 /* Properties of event headers. */
496 Lisp_Object Qevent_kind
;
497 Lisp_Object Qevent_symbol_elements
;
499 /* menu item parts */
500 Lisp_Object Qmenu_alias
;
501 Lisp_Object Qmenu_enable
;
502 Lisp_Object QCenable
, QCvisible
, QChelp
, QCfilter
, QCkeys
, QCkey_sequence
;
503 Lisp_Object QCbutton
, QCtoggle
, QCradio
;
504 extern Lisp_Object Vdefine_key_rebound_commands
;
505 extern Lisp_Object Qmenu_item
;
507 /* An event header symbol HEAD may have a property named
508 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
509 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
510 mask of modifiers applied to it. If present, this is used to help
511 speed up parse_modifiers. */
512 Lisp_Object Qevent_symbol_element_mask
;
514 /* An unmodified event header BASE may have a property named
515 Qmodifier_cache, which is an alist mapping modifier masks onto
516 modified versions of BASE. If present, this helps speed up
518 Lisp_Object Qmodifier_cache
;
520 /* Symbols to use for parts of windows. */
521 Lisp_Object Qmode_line
;
522 Lisp_Object Qvertical_line
;
523 Lisp_Object Qvertical_scroll_bar
;
524 Lisp_Object Qmenu_bar
;
526 Lisp_Object
recursive_edit_unwind (), command_loop ();
527 Lisp_Object
Fthis_command_keys ();
528 Lisp_Object Qextended_command_history
;
529 EMACS_TIME
timer_check ();
531 extern Lisp_Object Vhistory_length
;
533 extern char *x_get_keysym_name ();
535 static void record_menu_key ();
537 Lisp_Object Qpolling_period
;
539 /* List of absolute timers. Appears in order of next scheduled event. */
540 Lisp_Object Vtimer_list
;
542 /* List of idle time timers. Appears in order of next scheduled event. */
543 Lisp_Object Vtimer_idle_list
;
545 /* Incremented whenever a timer is run. */
548 extern Lisp_Object Vprint_level
, Vprint_length
;
550 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
552 EMACS_TIME
*input_available_clear_time
;
554 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
555 Default is 1 if INTERRUPT_INPUT is defined. */
558 /* Nonzero while interrupts are temporarily deferred during redisplay. */
559 int interrupts_deferred
;
561 /* Nonzero means use ^S/^Q for flow control. */
564 /* Allow m- file to inhibit use of FIONREAD. */
565 #ifdef BROKEN_FIONREAD
569 /* We are unable to use interrupts if FIONREAD is not available,
570 so flush SIGIO so we won't try. */
577 /* If we support a window system, turn on the code to poll periodically
578 to detect C-g. It isn't actually used when doing interrupt input. */
579 #ifdef HAVE_WINDOW_SYSTEM
580 #define POLL_FOR_INPUT
583 /* Global variable declarations. */
585 /* Function for init_keyboard to call with no args (if nonzero). */
586 void (*keyboard_init_hook
) ();
588 static int read_avail_input ();
589 static void get_input_pending ();
590 static int readable_events ();
591 static Lisp_Object
read_char_x_menu_prompt ();
592 static Lisp_Object
read_char_minibuf_menu_prompt ();
593 static Lisp_Object
make_lispy_event ();
595 static Lisp_Object
make_lispy_movement ();
597 static Lisp_Object
modify_event_symbol ();
598 static Lisp_Object
make_lispy_switch_frame ();
599 static int parse_solitary_modifier ();
600 static void save_getcjmp ();
601 static void restore_getcjmp ();
603 /* > 0 if we are to echo keystrokes. */
604 static int echo_keystrokes
;
606 /* Nonzero means don't try to suspend even if the operating system seems
608 static int cannot_suspend
;
610 #define min(a,b) ((a)<(b)?(a):(b))
611 #define max(a,b) ((a)>(b)?(a):(b))
613 /* Install the string STR as the beginning of the string of echoing,
614 so that it serves as a prompt for the next character.
615 Also start echoing. */
621 int len
= strlen (str
);
623 if (len
> ECHOBUFSIZE
- 4)
624 len
= ECHOBUFSIZE
- 4;
625 bcopy (str
, current_kboard
->echobuf
, len
);
626 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
627 *current_kboard
->echoptr
= '\0';
629 current_kboard
->echo_after_prompt
= len
;
634 /* Add C to the echo string, if echoing is going on.
635 C can be a character, which is printed prettily ("M-C-x" and all that
636 jazz), or a symbol, whose name is printed. */
642 extern char *push_key_description ();
644 if (current_kboard
->immediate_echo
)
646 char *ptr
= current_kboard
->echoptr
;
648 if (ptr
!= current_kboard
->echobuf
)
651 /* If someone has passed us a composite event, use its head symbol. */
656 if (ptr
- current_kboard
->echobuf
> ECHOBUFSIZE
- 6)
659 ptr
= push_key_description (XINT (c
), ptr
);
661 else if (SYMBOLP (c
))
663 struct Lisp_String
*name
= XSYMBOL (c
)->name
;
664 if ((ptr
- current_kboard
->echobuf
) + STRING_BYTES (name
) + 4
667 bcopy (name
->data
, ptr
, STRING_BYTES (name
));
668 ptr
+= STRING_BYTES (name
);
671 if (current_kboard
->echoptr
== current_kboard
->echobuf
674 strcpy (ptr
, " (Type ? for further options)");
679 current_kboard
->echoptr
= ptr
;
685 /* Temporarily add a dash to the end of the echo string if it's not
686 empty, so that it serves as a mini-prompt for the very next character. */
691 if (!current_kboard
->immediate_echo
692 && current_kboard
->echoptr
== current_kboard
->echobuf
)
694 /* Do nothing if we just printed a prompt. */
695 if (current_kboard
->echo_after_prompt
696 == current_kboard
->echoptr
- current_kboard
->echobuf
)
698 /* Do nothing if not echoing at all. */
699 if (current_kboard
->echoptr
== 0)
702 /* Put a dash at the end of the buffer temporarily,
703 but make it go away when the next character is added. */
704 current_kboard
->echoptr
[0] = '-';
705 current_kboard
->echoptr
[1] = 0;
710 /* Display the current echo string, and begin echoing if not already
716 if (!current_kboard
->immediate_echo
)
719 current_kboard
->immediate_echo
= 1;
721 for (i
= 0; i
< this_command_key_count
; i
++)
724 c
= XVECTOR (this_command_keys
)->contents
[i
];
725 if (! (EVENT_HAS_PARAMETERS (c
)
726 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
733 message2_nolog (current_kboard
->echobuf
, strlen (current_kboard
->echobuf
),
734 ! NILP (current_buffer
->enable_multibyte_characters
));
738 if (waiting_for_input
&& !NILP (Vquit_flag
))
739 quit_throw_to_read_char ();
742 /* Turn off echoing, for the start of a new command. */
747 current_kboard
->immediate_echo
= 0;
748 current_kboard
->echoptr
= current_kboard
->echobuf
;
749 current_kboard
->echo_after_prompt
= -1;
750 ok_to_echo_at_next_pause
= 0;
753 /* Return the length of the current echo string. */
758 return current_kboard
->echoptr
- current_kboard
->echobuf
;
761 /* Truncate the current echo message to its first LEN chars.
762 This and echo_char get used by read_key_sequence when the user
763 switches frames while entering a key sequence. */
769 current_kboard
->echobuf
[len
] = '\0';
770 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
771 truncate_echo_area (len
);
775 /* Functions for manipulating this_command_keys. */
777 add_command_key (key
)
780 int size
= XVECTOR (this_command_keys
)->size
;
782 /* If reset-this-command-length was called recently, obey it now.
783 See the doc string of that function for an explanation of why. */
784 if (before_command_restore_flag
)
786 this_command_key_count
= before_command_key_count_1
;
787 if (this_command_key_count
< this_single_command_key_start
)
788 this_single_command_key_start
= this_command_key_count
;
789 echo_truncate (before_command_echo_length_1
);
790 before_command_restore_flag
= 0;
793 if (this_command_key_count
>= size
)
795 Lisp_Object new_keys
;
797 new_keys
= Fmake_vector (make_number (size
* 2), Qnil
);
798 bcopy (XVECTOR (this_command_keys
)->contents
,
799 XVECTOR (new_keys
)->contents
,
800 size
* sizeof (Lisp_Object
));
802 this_command_keys
= new_keys
;
805 XVECTOR (this_command_keys
)->contents
[this_command_key_count
++] = key
;
811 int count
= specpdl_ptr
- specpdl
;
814 if (command_loop_level
> 0)
816 specbind (Qstandard_output
, Qt
);
817 specbind (Qstandard_input
, Qt
);
820 val
= command_loop ();
822 Fsignal (Qquit
, Qnil
);
823 /* Handle throw from read_minibuf when using minibuffer
824 while it's active but we're in another window. */
826 Fsignal (Qerror
, Fcons (val
, Qnil
));
828 return unbind_to (count
, Qnil
);
831 /* When an auto-save happens, record the "time", and don't do again soon. */
836 last_auto_save
= num_nonmacro_input_events
;
839 /* Make an auto save happen as soon as possible at command level. */
842 force_auto_save_soon ()
844 last_auto_save
= - auto_save_interval
- 1;
846 record_asynch_buffer_change ();
849 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
850 "Invoke the editor command loop recursively.\n\
851 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
852 that tells this function to return.\n\
853 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
854 This function is called by the editor initialization to begin editing.")
857 int count
= specpdl_ptr
- specpdl
;
860 command_loop_level
++;
861 update_mode_lines
= 1;
863 record_unwind_protect (recursive_edit_unwind
,
865 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
869 return unbind_to (count
, Qnil
);
873 recursive_edit_unwind (buffer
)
877 Fset_buffer (buffer
);
879 command_loop_level
--;
880 update_mode_lines
= 1;
888 #if 0 /* Theory: if there's anything in Vunread_command_events,
889 it will right away be read by read_key_sequence,
890 and then if we do switch KBOARDS, it will go into the side
891 queue then. So we don't need to do anything special here -- rms. */
892 if (CONSP (Vunread_command_events
))
894 current_kboard
->kbd_queue
895 = nconc2 (Vunread_command_events
, current_kboard
->kbd_queue
);
896 current_kboard
->kbd_queue_has_data
= 1;
898 Vunread_command_events
= Qnil
;
904 /* Switch to the single-kboard state, making current_kboard
905 the only KBOARD from which further input is accepted. */
908 single_kboard_state ()
915 /* Maintain a stack of kboards, so other parts of Emacs
916 can switch temporarily to the kboard of a given frame
917 and then revert to the previous status. */
922 struct kboard_stack
*next
;
925 static struct kboard_stack
*kboard_stack
;
928 push_frame_kboard (f
)
932 struct kboard_stack
*p
933 = (struct kboard_stack
*) xmalloc (sizeof (struct kboard_stack
));
935 p
->next
= kboard_stack
;
936 p
->kboard
= current_kboard
;
939 current_kboard
= FRAME_KBOARD (f
);
947 struct kboard_stack
*p
= kboard_stack
;
948 current_kboard
= p
->kboard
;
949 kboard_stack
= p
->next
;
954 /* Handle errors that are not handled at inner levels
955 by printing an error message and returning to the editor command loop. */
961 Lisp_Object old_level
, old_length
;
964 if (!NILP (executing_macro
))
966 if (executing_macro_iterations
== 1)
967 sprintf (macroerror
, "After 1 kbd macro iteration: ");
969 sprintf (macroerror
, "After %d kbd macro iterations: ",
970 executing_macro_iterations
);
975 Vstandard_output
= Qt
;
976 Vstandard_input
= Qt
;
977 Vexecuting_macro
= Qnil
;
978 executing_macro
= Qnil
;
979 current_kboard
->Vprefix_arg
= Qnil
;
980 current_kboard
->Vlast_prefix_arg
= Qnil
;
983 /* Avoid unquittable loop if data contains a circular list. */
984 old_level
= Vprint_level
;
985 old_length
= Vprint_length
;
986 XSETFASTINT (Vprint_level
, 10);
987 XSETFASTINT (Vprint_length
, 10);
988 cmd_error_internal (data
, macroerror
);
989 Vprint_level
= old_level
;
990 Vprint_length
= old_length
;
994 Vinhibit_quit
= Qnil
;
999 return make_number (0);
1002 /* Take actions on handling an error. DATA is the data that describes
1005 CONTEXT is a C-string containing ASCII characters only which
1006 describes the context in which the error happened. If we need to
1007 generalize CONTEXT to allow multibyte characters, make it a Lisp
1011 cmd_error_internal (data
, context
)
1019 echo_area_glyphs
= 0;
1021 /* If the window system or terminal frame hasn't been initialized
1022 yet, or we're not interactive, it's best to dump this message out
1023 to stderr and exit. */
1024 if (! FRAME_MESSAGE_BUF (selected_frame
)
1026 stream
= Qexternal_debugging_output
;
1035 write_string_1 (context
, -1, stream
);
1037 print_error_message (data
, stream
);
1039 /* If the window system or terminal frame hasn't been initialized
1040 yet, or we're in -batch mode, this error should cause Emacs to exit. */
1041 if (! FRAME_MESSAGE_BUF (selected_frame
)
1045 Fkill_emacs (make_number (-1));
1049 Lisp_Object
command_loop_1 ();
1050 Lisp_Object
command_loop_2 ();
1051 Lisp_Object
top_level_1 ();
1053 /* Entry to editor-command-loop.
1054 This level has the catches for exiting/returning to editor command loop.
1055 It returns nil to exit recursive edit, t to abort it. */
1060 if (command_loop_level
> 0 || minibuf_level
> 0)
1062 Lisp_Object val
= internal_catch (Qexit
, command_loop_2
, Qnil
);
1063 executing_macro
= Qnil
;
1069 internal_catch (Qtop_level
, top_level_1
, Qnil
);
1070 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
1071 executing_macro
= Qnil
;
1073 /* End of file in -batch run causes exit here. */
1079 /* Here we catch errors in execution of commands within the
1080 editing loop, and reenter the editing loop.
1081 When there is an error, cmd_error runs and returns a non-nil
1082 value to us. A value of nil means that cmd_loop_1 itself
1083 returned due to end of file (or end of kbd macro). */
1088 register Lisp_Object val
;
1091 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
1092 while (!NILP (val
));
1100 return Feval (Vtop_level
);
1106 /* On entry to the outer level, run the startup file */
1107 if (!NILP (Vtop_level
))
1108 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
1109 else if (!NILP (Vpurify_flag
))
1110 message ("Bare impure Emacs (standard Lisp code not loaded)");
1112 message ("Bare Emacs (standard Lisp code not loaded)");
1116 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
1117 "Exit all recursive editing levels.")
1120 Fthrow (Qtop_level
, Qnil
);
1123 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
1124 "Exit from the innermost recursive edit or minibuffer.")
1127 if (command_loop_level
> 0 || minibuf_level
> 0)
1128 Fthrow (Qexit
, Qnil
);
1130 error ("No recursive edit is in progress");
1133 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
1134 "Abort the command that requested this recursive edit or minibuffer input.")
1137 if (command_loop_level
> 0 || minibuf_level
> 0)
1140 error ("No recursive edit is in progress");
1143 /* This is the actual command reading loop,
1144 sans error-handling encapsulation. */
1146 Lisp_Object
Fcommand_execute ();
1147 static int read_key_sequence ();
1148 void safe_run_hooks ();
1153 Lisp_Object cmd
, tem
;
1156 Lisp_Object keybuf
[30];
1161 struct buffer
*prev_buffer
;
1163 int was_locked
= single_kboard
;
1166 current_kboard
->Vprefix_arg
= Qnil
;
1167 current_kboard
->Vlast_prefix_arg
= Qnil
;
1168 Vdeactivate_mark
= Qnil
;
1169 waiting_for_input
= 0;
1174 this_command_key_count
= 0;
1175 this_single_command_key_start
= 0;
1177 /* Make sure this hook runs after commands that get errors and
1178 throw to top level. */
1179 /* Note that the value cell will never directly contain nil
1180 if the symbol is a local variable. */
1181 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1182 safe_run_hooks (Qpost_command_hook
);
1184 if (!NILP (Vdeferred_action_list
))
1185 call0 (Vdeferred_action_function
);
1187 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1189 if (NILP (Vunread_command_events
)
1190 && NILP (Vunread_input_method_events
)
1191 && NILP (Vunread_post_input_method_events
)
1192 && NILP (Vexecuting_macro
)
1193 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1, 1)))
1194 safe_run_hooks (Qpost_command_idle_hook
);
1197 /* Do this after running Vpost_command_hook, for consistency. */
1198 current_kboard
->Vlast_command
= Vthis_command
;
1199 current_kboard
->Vreal_last_command
= real_this_command
;
1203 /* Make sure the current window's buffer is selected. */
1204 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1205 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1207 /* Display any malloc warning that just came out. Use while because
1208 displaying one warning can cause another. */
1210 while (pending_malloc_warning
)
1211 display_malloc_warning ();
1215 Vdeactivate_mark
= Qnil
;
1217 /* If minibuffer on and echo area in use,
1218 wait 2 sec and redraw minibuffer. */
1220 if (minibuf_level
&& echo_area_glyphs
1221 && EQ (minibuf_window
, echo_area_window
))
1223 /* Bind inhibit-quit to t so that C-g gets read in
1224 rather than quitting back to the minibuffer. */
1225 int count
= specpdl_ptr
- specpdl
;
1226 specbind (Qinhibit_quit
, Qt
);
1228 Fsit_for (make_number (2), Qnil
, Qnil
);
1229 /* Clear the echo area. */
1231 safe_run_hooks (Qecho_area_clear_hook
);
1233 unbind_to (count
, Qnil
);
1235 /* If a C-g came in before, treat it as input now. */
1236 if (!NILP (Vquit_flag
))
1239 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1244 alloca (0); /* Cause a garbage collection now */
1245 /* Since we can free the most stuff here. */
1246 #endif /* C_ALLOCA */
1249 /* Select the frame that the last event came from. Usually,
1250 switch-frame events will take care of this, but if some lisp
1251 code swallows a switch-frame event, we'll fix things up here.
1252 Is this a good idea? */
1253 if (FRAMEP (internal_last_event_frame
)
1254 && XFRAME (internal_last_event_frame
) != selected_frame
)
1255 Fselect_frame (internal_last_event_frame
, Qnil
);
1257 /* If it has changed current-menubar from previous value,
1258 really recompute the menubar from the value. */
1259 if (! NILP (Vlucid_menu_bar_dirty_flag
)
1260 && !NILP (Ffboundp (Qrecompute_lucid_menubar
)))
1261 call0 (Qrecompute_lucid_menubar
);
1263 before_command_key_count
= this_command_key_count
;
1264 before_command_echo_length
= echo_length ();
1266 Vthis_command
= Qnil
;
1267 real_this_command
= Qnil
;
1269 /* Read next key sequence; i gets its length. */
1270 i
= read_key_sequence (keybuf
, sizeof keybuf
/ sizeof keybuf
[0],
1273 /* A filter may have run while we were reading the input. */
1274 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1275 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1279 /* Now we have read a key sequence of length I,
1280 or else I is 0 and we found end of file. */
1282 if (i
== 0) /* End of file -- happens only in */
1283 return Qnil
; /* a kbd macro, at the end. */
1284 /* -1 means read_key_sequence got a menu that was rejected.
1285 Just loop around and read another command. */
1289 this_command_key_count
= 0;
1290 this_single_command_key_start
= 0;
1294 last_command_char
= keybuf
[i
- 1];
1296 /* If the previous command tried to force a specific window-start,
1297 forget about that, in case this command moves point far away
1298 from that position. But also throw away beg_unchanged and
1299 end_unchanged information in that case, so that redisplay will
1300 update the whole window properly. */
1301 if (!NILP (XWINDOW (selected_window
)->force_start
))
1303 XWINDOW (selected_window
)->force_start
= Qnil
;
1304 beg_unchanged
= end_unchanged
= 0;
1307 cmd
= read_key_sequence_cmd
;
1308 if (!NILP (Vexecuting_macro
))
1310 if (!NILP (Vquit_flag
))
1312 Vexecuting_macro
= Qt
;
1313 QUIT
; /* Make some noise. */
1314 /* Will return since macro now empty. */
1318 /* Do redisplay processing after this command except in special
1319 cases identified below that set no_redisplay to 1.
1320 (actually, there's currently no way to prevent the redisplay,
1321 and no_redisplay is ignored.
1322 Perhaps someday we will really implement it.) */
1325 prev_buffer
= current_buffer
;
1326 prev_modiff
= MODIFF
;
1327 last_point_position
= PT
;
1328 XSETBUFFER (last_point_position_buffer
, prev_buffer
);
1330 /* Execute the command. */
1332 Vthis_command
= cmd
;
1333 real_this_command
= cmd
;
1334 /* Note that the value cell will never directly contain nil
1335 if the symbol is a local variable. */
1336 if (!NILP (Vpre_command_hook
) && !NILP (Vrun_hooks
))
1337 safe_run_hooks (Qpre_command_hook
);
1339 if (NILP (Vthis_command
))
1341 /* nil means key is undefined. */
1343 current_kboard
->defining_kbd_macro
= Qnil
;
1344 update_mode_lines
= 1;
1345 current_kboard
->Vprefix_arg
= Qnil
;
1349 if (NILP (current_kboard
->Vprefix_arg
) && ! no_direct
)
1351 /* In case we jump to directly_done. */
1352 Vcurrent_prefix_arg
= current_kboard
->Vprefix_arg
;
1354 /* Recognize some common commands in common situations and
1355 do them directly. */
1356 if (EQ (Vthis_command
, Qforward_char
) && PT
< ZV
)
1358 struct Lisp_Char_Table
*dp
1359 = window_display_table (XWINDOW (selected_window
));
1360 lose
= FETCH_CHAR (PT_BYTE
);
1363 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1364 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1365 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1366 && (lose
>= 0x20 && lose
< 0x7f)))
1367 : (lose
>= 0x20 && lose
< 0x7f))
1368 /* To extract the case of continuation on
1369 wide-column characters. */
1370 && (WIDTH_BY_CHAR_HEAD (FETCH_BYTE (PT_BYTE
)) == 1)
1371 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1373 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1375 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1377 && !windows_or_buffers_changed
1378 && EQ (current_buffer
->selective_display
, Qnil
)
1379 && !detect_input_pending ()
1380 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1381 && NILP (Vexecuting_macro
))
1382 no_redisplay
= direct_output_forward_char (1);
1385 else if (EQ (Vthis_command
, Qbackward_char
) && PT
> BEGV
)
1387 struct Lisp_Char_Table
*dp
1388 = window_display_table (XWINDOW (selected_window
));
1390 lose
= FETCH_CHAR (PT_BYTE
);
1392 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1393 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1394 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1395 && (lose
>= 0x20 && lose
< 0x7f)))
1396 : (lose
>= 0x20 && lose
< 0x7f))
1397 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1399 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1401 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1403 && !windows_or_buffers_changed
1404 && EQ (current_buffer
->selective_display
, Qnil
)
1405 && !detect_input_pending ()
1406 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1407 && NILP (Vexecuting_macro
))
1408 no_redisplay
= direct_output_forward_char (-1);
1411 else if (EQ (Vthis_command
, Qself_insert_command
)
1412 /* Try this optimization only on ascii keystrokes. */
1413 && INTEGERP (last_command_char
))
1415 unsigned int c
= XINT (last_command_char
);
1418 if (NILP (Vexecuting_macro
)
1419 && !EQ (minibuf_window
, selected_window
))
1421 if (!nonundocount
|| nonundocount
>= 20)
1428 lose
= ((XFASTINT (XWINDOW (selected_window
)->last_modified
)
1430 || (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1432 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1434 || MODIFF
<= SAVE_MODIFF
1435 || windows_or_buffers_changed
1436 || !EQ (current_buffer
->selective_display
, Qnil
)
1437 || detect_input_pending ()
1438 || !NILP (XWINDOW (selected_window
)->column_number_displayed
)
1439 || !NILP (Vexecuting_macro
));
1440 value
= internal_self_insert (c
, 0);
1447 && (PT
== ZV
|| FETCH_BYTE (PT_BYTE
) == '\n'))
1449 struct Lisp_Char_Table
*dp
1450 = window_display_table (XWINDOW (selected_window
));
1453 /* Add the offset to the character, for Finsert_char.
1454 We pass internal_self_insert the unmodified character
1455 because it itself does this offsetting. */
1456 if (! NILP (current_buffer
->enable_multibyte_characters
))
1457 lose
= unibyte_char_to_multibyte (lose
);
1463 obj
= DISP_CHAR_VECTOR (dp
, lose
);
1466 /* Do it only for char codes
1467 that by default display as themselves. */
1468 if (lose
>= 0x20 && lose
<= 0x7e)
1469 no_redisplay
= direct_output_for_insert (lose
);
1471 else if (VECTORP (obj
)
1472 && XVECTOR (obj
)->size
== 1
1473 && (obj
= XVECTOR (obj
)->contents
[0],
1475 /* Insist face not specified in glyph. */
1476 && (XINT (obj
) & ((-1) << 8)) == 0)
1478 = direct_output_for_insert (XINT (obj
));
1482 if (lose
>= 0x20 && lose
<= 0x7e)
1483 no_redisplay
= direct_output_for_insert (lose
);
1490 /* Here for a command that isn't executed directly */
1493 if (NILP (current_kboard
->Vprefix_arg
))
1495 Fcommand_execute (Vthis_command
, Qnil
, Qnil
, Qnil
);
1498 current_kboard
->Vlast_prefix_arg
= Vcurrent_prefix_arg
;
1500 /* Note that the value cell will never directly contain nil
1501 if the symbol is a local variable. */
1502 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1503 safe_run_hooks (Qpost_command_hook
);
1505 if (!NILP (Vdeferred_action_list
))
1506 safe_run_hooks (Qdeferred_action_function
);
1508 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1510 if (NILP (Vunread_command_events
)
1511 && NILP (Vunread_input_method_events
)
1512 && NILP (Vunread_post_input_method_events
)
1513 && NILP (Vexecuting_macro
)
1514 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1, 1)))
1515 safe_run_hooks (Qpost_command_idle_hook
);
1518 /* If there is a prefix argument,
1519 1) We don't want Vlast_command to be ``universal-argument''
1520 (that would be dumb), so don't set Vlast_command,
1521 2) we want to leave echoing on so that the prefix will be
1522 echoed as part of this key sequence, so don't call
1524 3) we want to leave this_command_key_count non-zero, so that
1525 read_char will realize that it is re-reading a character, and
1526 not echo it a second time.
1528 If the command didn't actually create a prefix arg,
1529 but is merely a frame event that is transparent to prefix args,
1530 then the above doesn't apply. */
1531 if (NILP (current_kboard
->Vprefix_arg
) || CONSP (last_command_char
))
1533 current_kboard
->Vlast_command
= Vthis_command
;
1534 current_kboard
->Vreal_last_command
= real_this_command
;
1536 this_command_key_count
= 0;
1537 this_single_command_key_start
= 0;
1540 if (!NILP (current_buffer
->mark_active
) && !NILP (Vrun_hooks
))
1542 if (!NILP (Vdeactivate_mark
) && !NILP (Vtransient_mark_mode
))
1544 current_buffer
->mark_active
= Qnil
;
1545 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
1547 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
1548 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
1552 /* Install chars successfully executed in kbd macro. */
1554 if (!NILP (current_kboard
->defining_kbd_macro
)
1555 && NILP (current_kboard
->Vprefix_arg
))
1556 finalize_kbd_macro_chars ();
1560 any_kboard_state ();
1565 /* Subroutine for safe_run_hooks: run the hook HOOK. */
1568 safe_run_hooks_1 (hook
)
1571 return call1 (Vrun_hooks
, Vinhibit_quit
);
1574 /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */
1577 safe_run_hooks_error (data
)
1580 Fset (Vinhibit_quit
, Qnil
);
1583 /* If we get an error while running the hook, cause the hook variable
1584 to be nil. Also inhibit quits, so that C-g won't cause the hook
1585 to mysteriously evaporate. */
1588 safe_run_hooks (hook
)
1592 int count
= specpdl_ptr
- specpdl
;
1593 specbind (Qinhibit_quit
, hook
);
1595 internal_condition_case (safe_run_hooks_1
, Qt
, safe_run_hooks_error
);
1597 unbind_to (count
, Qnil
);
1600 /* Number of seconds between polling for input. */
1603 /* Nonzero means polling for input is temporarily suppressed. */
1604 int poll_suppress_count
;
1606 /* Nonzero if polling_for_input is actually being used. */
1607 int polling_for_input
;
1609 #ifdef POLL_FOR_INPUT
1611 /* Handle an alarm once each second and read pending input
1612 so as to handle a C-g if it comces in. */
1615 input_poll_signal (signalnum
) /* If we don't have an argument, */
1616 int signalnum
; /* some compilers complain in signal calls. */
1618 /* This causes the call to start_polling at the end
1619 to do its job. It also arranges for a quit or error
1620 from within read_avail_input to resume polling. */
1621 poll_suppress_count
++;
1622 if (interrupt_input_blocked
== 0
1623 && !waiting_for_input
)
1624 read_avail_input (0);
1625 /* Turn on the SIGALRM handler and request another alarm. */
1631 /* Begin signals to poll for input, if they are appropriate.
1632 This function is called unconditionally from various places. */
1637 #ifdef POLL_FOR_INPUT
1638 if (read_socket_hook
&& !interrupt_input
)
1640 poll_suppress_count
--;
1641 if (poll_suppress_count
== 0)
1643 signal (SIGALRM
, input_poll_signal
);
1644 polling_for_input
= 1;
1645 alarm (polling_period
);
1651 /* Nonzero if we are using polling to handle input asynchronously. */
1654 input_polling_used ()
1656 #ifdef POLL_FOR_INPUT
1657 return read_socket_hook
&& !interrupt_input
;
1663 /* Turn off polling. */
1668 #ifdef POLL_FOR_INPUT
1669 if (read_socket_hook
&& !interrupt_input
)
1671 if (poll_suppress_count
== 0)
1673 polling_for_input
= 0;
1676 poll_suppress_count
++;
1681 /* Set the value of poll_suppress_count to COUNT
1682 and start or stop polling accordingly. */
1685 set_poll_suppress_count (count
)
1688 #ifdef POLL_FOR_INPUT
1689 if (count
== 0 && poll_suppress_count
!= 0)
1691 poll_suppress_count
= 1;
1694 else if (count
!= 0 && poll_suppress_count
== 0)
1698 poll_suppress_count
= count
;
1702 /* Bind polling_period to a value at least N.
1703 But don't decrease it. */
1706 bind_polling_period (n
)
1709 #ifdef POLL_FOR_INPUT
1710 int new = polling_period
;
1716 specbind (Qpolling_period
, make_number (new));
1717 /* Start a new alarm with the new period. */
1722 /* Apply the control modifier to CHARACTER. */
1728 /* Save the upper bits here. */
1729 int upper
= c
& ~0177;
1733 /* Everything in the columns containing the upper-case letters
1734 denotes a control character. */
1735 if (c
>= 0100 && c
< 0140)
1739 /* Set the shift modifier for a control char
1740 made from a shifted letter. But only for letters! */
1741 if (oc
>= 'A' && oc
<= 'Z')
1742 c
|= shift_modifier
;
1745 /* The lower-case letters denote control characters too. */
1746 else if (c
>= 'a' && c
<= 'z')
1749 /* Include the bits for control and shift
1750 only if the basic ASCII code can't indicate them. */
1754 /* Replace the high bits. */
1755 c
|= (upper
& ~ctrl_modifier
);
1762 /* Input of single characters from keyboard */
1764 Lisp_Object
print_help ();
1765 static Lisp_Object
kbd_buffer_get_event ();
1766 static void record_char ();
1769 static jmp_buf wrong_kboard_jmpbuf
;
1772 /* read a character from the keyboard; call the redisplay if needed */
1773 /* commandflag 0 means do not do auto-saving, but do do redisplay.
1774 -1 means do not do redisplay, but do do autosaving.
1777 /* The arguments MAPS and NMAPS are for menu prompting.
1778 MAPS is an array of keymaps; NMAPS is the length of MAPS.
1780 PREV_EVENT is the previous input event, or nil if we are reading
1781 the first event of a key sequence.
1783 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
1784 if we used a mouse menu to read the input, or zero otherwise. If
1785 USED_MOUSE_MENU is null, we don't dereference it.
1787 Value is t if we showed a menu and the user rejected it. */
1790 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
)
1794 Lisp_Object prev_event
;
1795 int *used_mouse_menu
;
1799 jmp_buf local_getcjmp
;
1801 int key_already_recorded
= 0;
1802 Lisp_Object tem
, save
;
1803 Lisp_Object echo_area_message
;
1804 Lisp_Object also_record
;
1806 struct gcpro gcpro1
, gcpro2
;
1810 before_command_key_count
= this_command_key_count
;
1811 before_command_echo_length
= echo_length ();
1813 echo_area_message
= Qnil
;
1815 GCPRO2 (c
, echo_area_message
);
1820 if (CONSP (Vunread_post_input_method_events
))
1822 c
= XCONS (Vunread_post_input_method_events
)->car
;
1823 Vunread_post_input_method_events
1824 = XCONS (Vunread_post_input_method_events
)->cdr
;
1826 /* Undo what read_char_x_menu_prompt did when it unread
1827 additional keys returned by Fx_popup_menu. */
1829 && (SYMBOLP (XCONS (c
)->car
) || INTEGERP (XCONS (c
)->car
))
1830 && NILP (XCONS (c
)->cdr
))
1837 if (unread_command_char
!= -1)
1839 XSETINT (c
, unread_command_char
);
1840 unread_command_char
= -1;
1846 if (CONSP (Vunread_command_events
))
1848 c
= XCONS (Vunread_command_events
)->car
;
1849 Vunread_command_events
= XCONS (Vunread_command_events
)->cdr
;
1851 /* Undo what read_char_x_menu_prompt did when it unread
1852 additional keys returned by Fx_popup_menu. */
1854 && (SYMBOLP (XCONS (c
)->car
) || INTEGERP (XCONS (c
)->car
))
1855 && NILP (XCONS (c
)->cdr
))
1859 goto reread_for_input_method
;
1862 if (CONSP (Vunread_input_method_events
))
1864 c
= XCONS (Vunread_input_method_events
)->car
;
1865 Vunread_input_method_events
= XCONS (Vunread_input_method_events
)->cdr
;
1867 /* Undo what read_char_x_menu_prompt did when it unread
1868 additional keys returned by Fx_popup_menu. */
1870 && (SYMBOLP (XCONS (c
)->car
) || INTEGERP (XCONS (c
)->car
))
1871 && NILP (XCONS (c
)->cdr
))
1874 goto reread_for_input_method
;
1877 /* If there is no function key translated before
1878 reset-this-command-lengths takes effect, forget about it. */
1879 before_command_restore_flag
= 0;
1881 if (!NILP (Vexecuting_macro
))
1883 /* We set this to Qmacro; since that's not a frame, nobody will
1884 try to switch frames on us, and the selected window will
1887 Since this event came from a macro, it would be misleading to
1888 leave internal_last_event_frame set to wherever the last
1889 real event came from. Normally, a switch-frame event selects
1890 internal_last_event_frame after each command is read, but
1891 events read from a macro should never cause a new frame to be
1893 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
1895 /* Exit the macro if we are at the end.
1896 Also, some things replace the macro with t
1897 to force an early exit. */
1898 if (EQ (Vexecuting_macro
, Qt
)
1899 || executing_macro_index
>= XFASTINT (Flength (Vexecuting_macro
)))
1905 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
1906 if (STRINGP (Vexecuting_macro
)
1907 && (XINT (c
) & 0x80))
1908 XSETFASTINT (c
, CHAR_META
| (XINT (c
) & ~0x80));
1910 executing_macro_index
++;
1915 if (!NILP (unread_switch_frame
))
1917 c
= unread_switch_frame
;
1918 unread_switch_frame
= Qnil
;
1920 /* This event should make it into this_command_keys, and get echoed
1921 again, so we do not set `reread'. */
1925 /* if redisplay was requested */
1926 if (commandflag
>= 0)
1928 /* If there is pending input, process any events which are not
1929 user-visible, such as X selection_request events. */
1931 || detect_input_pending_run_timers (0))
1932 swallow_events (0); /* may clear input_pending */
1934 /* Redisplay if no pending input. */
1935 while (!input_pending
)
1940 /* Normal case: no input arrived during redisplay. */
1943 /* Input arrived and pre-empted redisplay.
1944 Process any events which are not user-visible. */
1946 /* If that cleared input_pending, try again to redisplay. */
1950 /* Message turns off echoing unless more keystrokes turn it on again. */
1951 if (echo_area_glyphs
&& *echo_area_glyphs
1952 && echo_area_glyphs
!= current_kboard
->echobuf
1953 && ok_to_echo_at_next_pause
!= echo_area_glyphs
)
1956 /* If already echoing, continue. */
1959 /* Try reading a character via menu prompting in the minibuf.
1960 Try this before the sit-for, because the sit-for
1961 would do the wrong thing if we are supposed to do
1962 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
1963 after a mouse event so don't try a minibuf menu. */
1965 if (nmaps
> 0 && INTERACTIVE
1966 && !NILP (prev_event
) && ! EVENT_HAS_PARAMETERS (prev_event
)
1967 /* Don't bring up a menu if we already have another event. */
1968 && NILP (Vunread_command_events
)
1969 && unread_command_char
< 0
1970 && !detect_input_pending_run_timers (0))
1972 c
= read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
);
1975 key_already_recorded
= 1;
1980 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet.
1981 We will do that below, temporarily for short sections of code,
1982 when appropriate. local_getcjmp must be in effect
1983 around any call to sit_for or kbd_buffer_get_event;
1984 it *must not* be in effect when we call redisplay. */
1986 if (_setjmp (local_getcjmp
))
1988 XSETINT (c
, quit_char
);
1989 XSETFRAME (internal_last_event_frame
, selected_frame
);
1990 Vlast_event_frame
= internal_last_event_frame
;
1991 /* If we report the quit char as an event,
1992 don't do so more than once. */
1993 if (!NILP (Vinhibit_quit
))
1998 KBOARD
*kb
= FRAME_KBOARD (selected_frame
);
1999 if (kb
!= current_kboard
)
2001 Lisp_Object
*tailp
= &kb
->kbd_queue
;
2002 /* We shouldn't get here if we were in single-kboard mode! */
2005 while (CONSP (*tailp
))
2006 tailp
= &XCONS (*tailp
)->cdr
;
2009 *tailp
= Fcons (c
, Qnil
);
2010 kb
->kbd_queue_has_data
= 1;
2011 current_kboard
= kb
;
2012 /* This is going to exit from read_char
2013 so we had better get rid of this frame's stuff. */
2015 longjmp (wrong_kboard_jmpbuf
, 1);
2022 timer_start_idle ();
2024 /* If in middle of key sequence and minibuffer not active,
2025 start echoing if enough time elapses. */
2027 if (minibuf_level
== 0 && !current_kboard
->immediate_echo
2028 && this_command_key_count
> 0
2030 && echo_keystrokes
> 0
2031 && (echo_area_glyphs
== 0 || *echo_area_glyphs
== 0
2032 || ok_to_echo_at_next_pause
== echo_area_glyphs
))
2036 /* After a mouse event, start echoing right away.
2037 This is because we are probably about to display a menu,
2038 and we don't want to delay before doing so. */
2039 if (EVENT_HAS_PARAMETERS (prev_event
))
2043 save_getcjmp (save_jump
);
2044 restore_getcjmp (local_getcjmp
);
2045 tem0
= sit_for (echo_keystrokes
, 0, 1, 1, 0);
2046 restore_getcjmp (save_jump
);
2048 && ! CONSP (Vunread_command_events
))
2053 /* Maybe auto save due to number of keystrokes. */
2055 if (commandflag
!= 0
2056 && auto_save_interval
> 0
2057 && num_nonmacro_input_events
- last_auto_save
> max (auto_save_interval
, 20)
2058 && !detect_input_pending_run_timers (0))
2060 Fdo_auto_save (Qnil
, Qnil
);
2061 /* Hooks can actually change some buffers in auto save. */
2065 /* Try reading using an X menu.
2066 This is never confused with reading using the minibuf
2067 because the recursive call of read_char in read_char_minibuf_menu_prompt
2068 does not pass on any keymaps. */
2070 if (nmaps
> 0 && INTERACTIVE
2071 && !NILP (prev_event
)
2072 && EVENT_HAS_PARAMETERS (prev_event
)
2073 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
)
2074 /* Don't bring up a menu if we already have another event. */
2075 && NILP (Vunread_command_events
)
2076 && unread_command_char
< 0)
2078 c
= read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
2080 /* Now that we have read an event, Emacs is not idle. */
2086 /* Maybe autosave and/or garbage collect due to idleness. */
2088 if (INTERACTIVE
&& NILP (c
))
2090 int delay_level
, buffer_size
;
2092 /* Slow down auto saves logarithmically in size of current buffer,
2093 and garbage collect while we're at it. */
2094 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
2095 last_non_minibuf_size
= Z
- BEG
;
2096 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
2098 while (buffer_size
> 64)
2099 delay_level
++, buffer_size
-= buffer_size
>> 2;
2100 if (delay_level
< 4) delay_level
= 4;
2101 /* delay_level is 4 for files under around 50k, 7 at 100k,
2102 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
2104 /* Auto save if enough time goes by without input. */
2105 if (commandflag
!= 0
2106 && num_nonmacro_input_events
> last_auto_save
2107 && INTEGERP (Vauto_save_timeout
)
2108 && XINT (Vauto_save_timeout
) > 0)
2112 save_getcjmp (save_jump
);
2113 restore_getcjmp (local_getcjmp
);
2114 tem0
= sit_for (delay_level
* XFASTINT (Vauto_save_timeout
) / 4,
2116 restore_getcjmp (save_jump
);
2119 && ! CONSP (Vunread_command_events
))
2121 Fdo_auto_save (Qnil
, Qnil
);
2123 /* If we have auto-saved and there is still no input
2124 available, garbage collect if there has been enough
2125 consing going on to make it worthwhile. */
2126 if (!detect_input_pending_run_timers (0)
2127 && consing_since_gc
> gc_cons_threshold
/ 2)
2128 Fgarbage_collect ();
2135 /* If this has become non-nil here, it has been set by a timer
2136 or sentinel or filter. */
2137 if (CONSP (Vunread_command_events
))
2139 c
= XCONS (Vunread_command_events
)->car
;
2140 Vunread_command_events
= XCONS (Vunread_command_events
)->cdr
;
2143 /* Read something from current KBOARD's side queue, if possible. */
2147 if (current_kboard
->kbd_queue_has_data
)
2149 if (!CONSP (current_kboard
->kbd_queue
))
2151 c
= XCONS (current_kboard
->kbd_queue
)->car
;
2152 current_kboard
->kbd_queue
2153 = XCONS (current_kboard
->kbd_queue
)->cdr
;
2154 if (NILP (current_kboard
->kbd_queue
))
2155 current_kboard
->kbd_queue_has_data
= 0;
2156 input_pending
= readable_events (0);
2157 if (EVENT_HAS_PARAMETERS (c
)
2158 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qswitch_frame
))
2159 internal_last_event_frame
= XCONS (XCONS (c
)->cdr
)->car
;
2160 Vlast_event_frame
= internal_last_event_frame
;
2165 /* If current_kboard's side queue is empty check the other kboards.
2166 If one of them has data that we have not yet seen here,
2167 switch to it and process the data waiting for it.
2169 Note: if the events queued up for another kboard
2170 have already been seen here, and therefore are not a complete command,
2171 the kbd_queue_has_data field is 0, so we skip that kboard here.
2172 That's to avoid an infinite loop switching between kboards here. */
2173 if (NILP (c
) && !single_kboard
)
2176 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2177 if (kb
->kbd_queue_has_data
)
2179 current_kboard
= kb
;
2180 /* This is going to exit from read_char
2181 so we had better get rid of this frame's stuff. */
2183 longjmp (wrong_kboard_jmpbuf
, 1);
2192 /* Finally, we read from the main queue,
2193 and if that gives us something we can't use yet, we put it on the
2194 appropriate side queue and try again. */
2200 /* Actually read a character, waiting if necessary. */
2201 save_getcjmp (save_jump
);
2202 restore_getcjmp (local_getcjmp
);
2203 c
= kbd_buffer_get_event (&kb
, used_mouse_menu
);
2204 restore_getcjmp (save_jump
);
2207 if (! NILP (c
) && (kb
!= current_kboard
))
2209 Lisp_Object
*tailp
= &kb
->kbd_queue
;
2210 while (CONSP (*tailp
))
2211 tailp
= &XCONS (*tailp
)->cdr
;
2214 *tailp
= Fcons (c
, Qnil
);
2215 kb
->kbd_queue_has_data
= 1;
2219 current_kboard
= kb
;
2220 /* This is going to exit from read_char
2221 so we had better get rid of this frame's stuff. */
2223 longjmp (wrong_kboard_jmpbuf
, 1);
2228 /* Terminate Emacs in batch mode if at eof. */
2229 if (noninteractive
&& INTEGERP (c
) && XINT (c
) < 0)
2230 Fkill_emacs (make_number (1));
2234 /* Add in any extra modifiers, where appropriate. */
2235 if ((extra_keyboard_modifiers
& CHAR_CTL
)
2236 || ((extra_keyboard_modifiers
& 0177) < ' '
2237 && (extra_keyboard_modifiers
& 0177) != 0))
2238 XSETINT (c
, make_ctrl_char (XINT (c
)));
2240 /* Transfer any other modifier bits directly from
2241 extra_keyboard_modifiers to c. Ignore the actual character code
2242 in the low 16 bits of extra_keyboard_modifiers. */
2243 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
2254 if (commandflag
>= 0
2255 && !input_pending
&& !detect_input_pending_run_timers (0))
2263 /* Buffer switch events are only for internal wakeups
2264 so don't show them to the user.
2265 Also, don't record a key if we already did. */
2266 if (BUFFERP (c
) || key_already_recorded
)
2269 /* Process special events within read_char
2270 and loop around to read another event. */
2273 tem
= get_keyelt (access_keymap (get_keymap_1 (Vspecial_event_map
, 0, 0),
2279 int was_locked
= single_kboard
;
2281 last_input_char
= c
;
2282 Fcommand_execute (tem
, Qnil
, Fvector (1, &last_input_char
), Qt
);
2284 /* Resume allowing input from any kboard, if that was true before. */
2286 any_kboard_state ();
2291 /* Handle things that only apply to characters. */
2294 /* If kbd_buffer_get_event gave us an EOF, return that. */
2298 if ((STRINGP (Vkeyboard_translate_table
)
2299 && XSTRING (Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
2300 || (VECTORP (Vkeyboard_translate_table
)
2301 && XVECTOR (Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
2302 || (CHAR_TABLE_P (Vkeyboard_translate_table
)
2303 && CHAR_TABLE_ORDINARY_SLOTS
> (unsigned) XFASTINT (c
)))
2306 d
= Faref (Vkeyboard_translate_table
, c
);
2307 /* nil in keyboard-translate-table means no translation. */
2313 /* If this event is a mouse click in the menu bar,
2314 return just menu-bar for now. Modify the mouse click event
2315 so we won't do this twice, then queue it up. */
2316 if (EVENT_HAS_PARAMETERS (c
)
2317 && CONSP (XCONS (c
)->cdr
)
2318 && CONSP (EVENT_START (c
))
2319 && CONSP (XCONS (EVENT_START (c
))->cdr
))
2323 posn
= POSN_BUFFER_POSN (EVENT_START (c
));
2324 /* Handle menu-bar events:
2325 insert the dummy prefix event `menu-bar'. */
2326 if (EQ (posn
, Qmenu_bar
))
2328 /* Change menu-bar to (menu-bar) as the event "position". */
2329 POSN_BUFFER_POSN (EVENT_START (c
)) = Fcons (posn
, Qnil
);
2332 Vunread_command_events
= Fcons (c
, Vunread_command_events
);
2337 /* Store these characters into recent_keys, the dribble file if any,
2338 and the keyboard macro being defined, if any. */
2340 if (! NILP (also_record
))
2341 record_char (also_record
);
2343 /* Wipe the echo area.
2344 But first, if we are about to use an input method,
2345 save the echo area contents for it to refer to. */
2347 && ! NILP (Vinput_method_function
)
2348 && (unsigned) XINT (c
) >= ' '
2349 && (unsigned) XINT (c
) < 127)
2350 Vinput_method_previous_message
= echo_area_message
= Fcurrent_message ();
2352 /* Now wipe the echo area. */
2353 if (echo_area_glyphs
)
2354 safe_run_hooks (Qecho_area_clear_hook
);
2355 echo_area_glyphs
= 0;
2357 reread_for_input_method
:
2359 /* Pass this to the input method, if appropriate. */
2361 && ! NILP (Vinput_method_function
)
2362 && (unsigned) XINT (c
) >= ' '
2363 && (unsigned) XINT (c
) < 127)
2366 int key_count
= this_command_key_count
;
2367 int saved
= current_kboard
->immediate_echo
;
2368 struct gcpro gcpro1
;
2370 keys
= Fcopy_sequence (this_command_keys
);
2372 tem
= call1 (Vinput_method_function
, c
);
2374 current_kboard
->immediate_echo
= saved
;
2375 /* The input method can return no events. */
2378 /* Bring back the previous message, if any. */
2379 if (! NILP (Vinput_method_previous_message
))
2380 message_with_string ("%s", echo_area_message
, 0);
2381 this_command_keys
= keys
;
2382 this_command_key_count
= key_count
;
2386 /* It returned one event or more. */
2387 c
= XCONS (tem
)->car
;
2388 Vunread_post_input_method_events
2389 = nconc2 (XCONS (tem
)->cdr
, Vunread_post_input_method_events
);
2394 if (this_command_key_count
== 0 || ! reread
)
2396 before_command_key_count
= this_command_key_count
;
2397 before_command_echo_length
= echo_length ();
2399 /* Don't echo mouse motion events. */
2401 && ! (EVENT_HAS_PARAMETERS (c
)
2402 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
2405 if (! NILP (also_record
))
2406 echo_char (also_record
);
2407 /* Once we reread a character, echoing can happen
2408 the next time we pause to read a new one. */
2409 ok_to_echo_at_next_pause
= echo_area_glyphs
;
2412 /* Record this character as part of the current key. */
2413 add_command_key (c
);
2414 if (! NILP (also_record
))
2415 add_command_key (also_record
);
2418 last_input_char
= c
;
2421 /* Process the help character specially if enabled */
2422 if (!NILP (Vhelp_form
) && help_char_p (c
))
2425 count
= specpdl_ptr
- specpdl
;
2427 record_unwind_protect (Fset_window_configuration
,
2428 Fcurrent_window_configuration (Qnil
));
2430 tem0
= Feval (Vhelp_form
);
2432 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
2436 c
= read_char (0, 0, 0, Qnil
, 0);
2437 while (BUFFERP (c
));
2438 /* Remove the help from the frame */
2439 unbind_to (count
, Qnil
);
2442 if (EQ (c
, make_number (040)))
2446 c
= read_char (0, 0, 0, Qnil
, 0);
2447 while (BUFFERP (c
));
2454 /* Record a key that came from a mouse menu.
2455 Record it for echoing, for this-command-keys, and so on. */
2461 /* Wipe the echo area. */
2462 echo_area_glyphs
= 0;
2466 before_command_key_count
= this_command_key_count
;
2467 before_command_echo_length
= echo_length ();
2469 /* Don't echo mouse motion events. */
2470 if (echo_keystrokes
)
2474 /* Once we reread a character, echoing can happen
2475 the next time we pause to read a new one. */
2476 ok_to_echo_at_next_pause
= 0;
2479 /* Record this character as part of the current key. */
2480 add_command_key (c
);
2482 /* Re-reading in the middle of a command */
2483 last_input_char
= c
;
2487 /* Return 1 if should recognize C as "the help character". */
2495 if (EQ (c
, Vhelp_char
))
2497 for (tail
= Vhelp_event_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
2498 if (EQ (c
, XCONS (tail
)->car
))
2503 /* Record the input event C in various ways. */
2510 XVECTOR (recent_keys
)->contents
[recent_keys_index
] = c
;
2511 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
2512 recent_keys_index
= 0;
2514 /* Write c to the dribble file. If c is a lispy event, write
2515 the event's symbol to the dribble file, in <brackets>. Bleaugh.
2516 If you, dear reader, have a better idea, you've got the source. :-) */
2521 if (XUINT (c
) < 0x100)
2522 putc (XINT (c
), dribble
);
2524 fprintf (dribble
, " 0x%x", (int) XUINT (c
));
2528 Lisp_Object dribblee
;
2530 /* If it's a structured event, take the event header. */
2531 dribblee
= EVENT_HEAD (c
);
2533 if (SYMBOLP (dribblee
))
2535 putc ('<', dribble
);
2536 fwrite (XSYMBOL (dribblee
)->name
->data
, sizeof (char),
2537 STRING_BYTES (XSYMBOL (dribblee
)->name
),
2539 putc ('>', dribble
);
2546 store_kbd_macro_char (c
);
2548 num_nonmacro_input_events
++;
2555 struct buffer
*old
= current_buffer
;
2556 Fprinc (object
, Qnil
);
2557 set_buffer_internal (XBUFFER (Vstandard_output
));
2558 call0 (intern ("help-mode"));
2559 set_buffer_internal (old
);
2563 /* Copy out or in the info on where C-g should throw to.
2564 This is used when running Lisp code from within get_char,
2565 in case get_char is called recursively.
2566 See read_process_output. */
2572 bcopy (getcjmp
, temp
, sizeof getcjmp
);
2576 restore_getcjmp (temp
)
2579 bcopy (temp
, getcjmp
, sizeof getcjmp
);
2584 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
2585 of this function. */
2588 tracking_off (old_value
)
2589 Lisp_Object old_value
;
2591 do_mouse_tracking
= old_value
;
2592 if (NILP (old_value
))
2594 /* Redisplay may have been preempted because there was input
2595 available, and it assumes it will be called again after the
2596 input has been processed. If the only input available was
2597 the sort that we have just disabled, then we need to call
2599 if (!readable_events (1))
2601 redisplay_preserve_echo_area ();
2602 get_input_pending (&input_pending
, 1);
2607 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
2608 "Evaluate BODY with mouse movement events enabled.\n\
2609 Within a `track-mouse' form, mouse motion generates input events that\n\
2610 you can read with `read-event'.\n\
2611 Normally, mouse motion is ignored.")
2615 int count
= specpdl_ptr
- specpdl
;
2618 record_unwind_protect (tracking_off
, do_mouse_tracking
);
2620 do_mouse_tracking
= Qt
;
2622 val
= Fprogn (args
);
2623 return unbind_to (count
, val
);
2626 /* If mouse has moved on some frame, return one of those frames.
2627 Return 0 otherwise. */
2632 Lisp_Object tail
, frame
;
2634 FOR_EACH_FRAME (tail
, frame
)
2636 if (XFRAME (frame
)->mouse_moved
)
2637 return XFRAME (frame
);
2643 #endif /* HAVE_MOUSE */
2645 /* Low level keyboard/mouse input.
2646 kbd_buffer_store_event places events in kbd_buffer, and
2647 kbd_buffer_get_event retrieves them. */
2649 /* Return true iff there are any events in the queue that read-char
2650 would return. If this returns false, a read-char would block. */
2652 readable_events (do_timers_now
)
2656 timer_check (do_timers_now
);
2658 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2661 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2666 if (current_kboard
->kbd_queue_has_data
)
2672 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2673 if (kb
->kbd_queue_has_data
)
2679 /* Set this for debugging, to have a way to get out */
2684 event_to_kboard (event
)
2685 struct input_event
*event
;
2688 frame
= event
->frame_or_window
;
2690 frame
= XCONS (frame
)->car
;
2691 else if (WINDOWP (frame
))
2692 frame
= WINDOW_FRAME (XWINDOW (frame
));
2694 /* There are still some events that don't set this field.
2695 For now, just ignore the problem.
2696 Also ignore dead frames here. */
2697 if (!FRAMEP (frame
) || !FRAME_LIVE_P (XFRAME (frame
)))
2700 return FRAME_KBOARD (XFRAME (frame
));
2704 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
2707 kbd_buffer_store_event (event
)
2708 register struct input_event
*event
;
2710 if (event
->kind
== no_event
)
2713 if (event
->kind
== ascii_keystroke
)
2715 register int c
= event
->code
& 0377;
2717 if (event
->modifiers
& ctrl_modifier
)
2718 c
= make_ctrl_char (c
);
2720 c
|= (event
->modifiers
2721 & (meta_modifier
| alt_modifier
2722 | hyper_modifier
| super_modifier
));
2726 extern SIGTYPE
interrupt_signal ();
2729 struct input_event
*sp
;
2732 && (kb
= FRAME_KBOARD (XFRAME (event
->frame_or_window
)),
2733 kb
!= current_kboard
))
2736 = Fcons (make_lispy_switch_frame (event
->frame_or_window
),
2737 Fcons (make_number (c
), Qnil
));
2738 kb
->kbd_queue_has_data
= 1;
2739 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
2741 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
2744 if (event_to_kboard (sp
) == kb
)
2746 sp
->kind
= no_event
;
2747 sp
->frame_or_window
= Qnil
;
2754 /* If this results in a quit_char being returned to Emacs as
2755 input, set Vlast_event_frame properly. If this doesn't
2756 get returned to Emacs as an event, the next event read
2757 will set Vlast_event_frame again, so this is safe to do. */
2761 focus
= FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
2763 focus
= event
->frame_or_window
;
2764 internal_last_event_frame
= focus
;
2765 Vlast_event_frame
= focus
;
2768 last_event_timestamp
= event
->timestamp
;
2769 interrupt_signal ();
2773 if (c
&& c
== stop_character
)
2779 /* Don't insert two buffer_switch_event's in a row.
2780 Just ignore the second one. */
2781 else if (event
->kind
== buffer_switch_event
2782 && kbd_fetch_ptr
!= kbd_store_ptr
2783 && kbd_store_ptr
->kind
== buffer_switch_event
)
2786 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
2787 kbd_store_ptr
= kbd_buffer
;
2789 /* Don't let the very last slot in the buffer become full,
2790 since that would make the two pointers equal,
2791 and that is indistinguishable from an empty buffer.
2792 Discard the event if it would fill the last slot. */
2793 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
2795 volatile struct input_event
*sp
= kbd_store_ptr
;
2796 sp
->kind
= event
->kind
;
2797 if (event
->kind
== selection_request_event
)
2799 /* We must not use the ordinary copying code for this case,
2800 since `part' is an enum and copying it might not copy enough
2802 bcopy (event
, (char *) sp
, sizeof (*event
));
2806 sp
->code
= event
->code
;
2807 sp
->part
= event
->part
;
2808 sp
->frame_or_window
= event
->frame_or_window
;
2809 sp
->modifiers
= event
->modifiers
;
2812 sp
->timestamp
= event
->timestamp
;
2814 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_store_ptr
2816 = event
->frame_or_window
);
2822 /* Discard any mouse events in the event buffer by setting them to
2825 discard_mouse_events ()
2827 struct input_event
*sp
;
2828 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
2830 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
2833 if (sp
->kind
== mouse_click
2835 || sp
->kind
== w32_scroll_bar_click
2837 || sp
->kind
== scroll_bar_click
)
2839 sp
->kind
= no_event
;
2844 /* Read one event from the event buffer, waiting if necessary.
2845 The value is a Lisp object representing the event.
2846 The value is nil for an event that should be ignored,
2847 or that was handled here.
2848 We always read and discard one event. */
2851 kbd_buffer_get_event (kbp
, used_mouse_menu
)
2853 int *used_mouse_menu
;
2857 EMACS_TIME next_timer_delay
;
2863 *kbp
= current_kboard
;
2867 /* Wait until there is input available. */
2870 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2873 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2877 /* If the quit flag is set, then read_char will return
2878 quit_char, so that counts as "available input." */
2879 if (!NILP (Vquit_flag
))
2880 quit_throw_to_read_char ();
2882 /* One way or another, wait until input is available; then, if
2883 interrupt handlers have not read it, read it now. */
2886 wait_for_kbd_input ();
2888 /* Note SIGIO has been undef'd if FIONREAD is missing. */
2892 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2895 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2899 Lisp_Object minus_one
;
2901 XSETINT (minus_one
, -1);
2902 wait_reading_process_input (0, 0, minus_one
, 1);
2904 if (!interrupt_input
&& kbd_fetch_ptr
== kbd_store_ptr
)
2905 /* Pass 1 for EXPECT since we just waited to have input. */
2906 read_avail_input (1);
2908 #endif /* not VMS */
2911 if (CONSP (Vunread_command_events
))
2914 first
= XCONS (Vunread_command_events
)->car
;
2915 Vunread_command_events
= XCONS (Vunread_command_events
)->cdr
;
2916 *kbp
= current_kboard
;
2920 /* At this point, we know that there is a readable event available
2921 somewhere. If the event queue is empty, then there must be a
2922 mouse movement enabled and available. */
2923 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2925 struct input_event
*event
;
2927 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2931 last_event_timestamp
= event
->timestamp
;
2934 *kbp
= event_to_kboard (event
);
2936 *kbp
= current_kboard
; /* Better than returning null ptr? */
2938 *kbp
= &the_only_kboard
;
2943 /* These two kinds of events get special handling
2944 and don't actually appear to the command loop.
2945 We return nil for them. */
2946 if (event
->kind
== selection_request_event
)
2949 struct input_event copy
;
2951 /* Remove it from the buffer before processing it,
2952 since otherwise swallow_events will see it
2953 and process it again. */
2955 kbd_fetch_ptr
= event
+ 1;
2956 input_pending
= readable_events (0);
2957 x_handle_selection_request (©
);
2959 /* We're getting selection request events, but we don't have
2965 else if (event
->kind
== selection_clear_event
)
2968 struct input_event copy
;
2970 /* Remove it from the buffer before processing it. */
2972 kbd_fetch_ptr
= event
+ 1;
2973 input_pending
= readable_events (0);
2974 x_handle_selection_clear (©
);
2976 /* We're getting selection request events, but we don't have
2981 #if defined (HAVE_X11) || defined (HAVE_NTGUI)
2982 else if (event
->kind
== delete_window_event
)
2984 /* Make an event (delete-frame (FRAME)). */
2985 obj
= Fcons (event
->frame_or_window
, Qnil
);
2986 obj
= Fcons (Qdelete_frame
, Fcons (obj
, Qnil
));
2987 kbd_fetch_ptr
= event
+ 1;
2989 else if (event
->kind
== iconify_event
)
2991 /* Make an event (iconify-frame (FRAME)). */
2992 obj
= Fcons (event
->frame_or_window
, Qnil
);
2993 obj
= Fcons (Qiconify_frame
, Fcons (obj
, Qnil
));
2994 kbd_fetch_ptr
= event
+ 1;
2996 else if (event
->kind
== deiconify_event
)
2998 /* Make an event (make-frame-visible (FRAME)). */
2999 obj
= Fcons (event
->frame_or_window
, Qnil
);
3000 obj
= Fcons (Qmake_frame_visible
, Fcons (obj
, Qnil
));
3001 kbd_fetch_ptr
= event
+ 1;
3004 else if (event
->kind
== buffer_switch_event
)
3006 /* The value doesn't matter here; only the type is tested. */
3007 XSETBUFFER (obj
, current_buffer
);
3008 kbd_fetch_ptr
= event
+ 1;
3010 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
3011 else if (event
->kind
== menu_bar_activate_event
)
3013 kbd_fetch_ptr
= event
+ 1;
3014 input_pending
= readable_events (0);
3015 if (FRAME_LIVE_P (XFRAME (event
->frame_or_window
)))
3016 x_activate_menubar (XFRAME (event
->frame_or_window
));
3019 /* Just discard these, by returning nil.
3020 With MULTI_KBOARD, these events are used as placeholders
3021 when we need to randomly delete events from the queue.
3022 (They shouldn't otherwise be found in the buffer,
3023 but on some machines it appears they do show up
3024 even without MULTI_KBOARD.) */
3025 /* On Windows NT/9X, no_event is used to delete extraneous
3026 mouse events during a popup-menu call. */
3027 else if (event
->kind
== no_event
)
3028 kbd_fetch_ptr
= event
+ 1;
3030 /* If this event is on a different frame, return a switch-frame this
3031 time, and leave the event in the queue for next time. */
3037 frame
= event
->frame_or_window
;
3039 frame
= XCONS (frame
)->car
;
3040 else if (WINDOWP (frame
))
3041 frame
= WINDOW_FRAME (XWINDOW (frame
));
3043 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
3047 if (! EQ (frame
, internal_last_event_frame
)
3048 && XFRAME (frame
) != selected_frame
)
3049 obj
= make_lispy_switch_frame (frame
);
3050 internal_last_event_frame
= frame
;
3052 /* If we didn't decide to make a switch-frame event, go ahead
3053 and build a real event from the queue entry. */
3057 obj
= make_lispy_event (event
);
3058 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
3059 /* If this was a menu selection, then set the flag to inhibit
3060 writing to last_nonmenu_event. Don't do this if the event
3061 we're returning is (menu-bar), though; that indicates the
3062 beginning of the menu sequence, and we might as well leave
3063 that as the `event with parameters' for this selection. */
3064 if (event
->kind
== menu_bar_event
3065 && !(CONSP (obj
) && EQ (XCONS (obj
)->car
, Qmenu_bar
))
3067 *used_mouse_menu
= 1;
3070 /* Wipe out this event, to catch bugs. */
3071 event
->kind
= no_event
;
3072 XVECTOR (kbd_buffer_frame_or_window
)->contents
[event
- kbd_buffer
] = Qnil
;
3074 kbd_fetch_ptr
= event
+ 1;
3079 /* Try generating a mouse motion event. */
3080 else if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
3082 FRAME_PTR f
= some_mouse_moved ();
3083 Lisp_Object bar_window
;
3084 enum scroll_bar_part part
;
3088 *kbp
= current_kboard
;
3089 /* Note that this uses F to determine which display to look at.
3090 If there is no valid info, it does not store anything
3091 so x remains nil. */
3093 (*mouse_position_hook
) (&f
, 0, &bar_window
, &part
, &x
, &y
, &time
);
3097 /* Decide if we should generate a switch-frame event. Don't
3098 generate switch-frame events for motion outside of all Emacs
3104 frame
= FRAME_FOCUS_FRAME (f
);
3106 XSETFRAME (frame
, f
);
3108 if (! EQ (frame
, internal_last_event_frame
)
3109 && XFRAME (frame
) != selected_frame
)
3110 obj
= make_lispy_switch_frame (frame
);
3111 internal_last_event_frame
= frame
;
3114 /* If we didn't decide to make a switch-frame event, go ahead and
3115 return a mouse-motion event. */
3116 if (!NILP (x
) && NILP (obj
))
3117 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
3119 #endif /* HAVE_MOUSE */
3121 /* We were promised by the above while loop that there was
3122 something for us to read! */
3125 input_pending
= readable_events (0);
3127 Vlast_event_frame
= internal_last_event_frame
;
3132 /* Process any events that are not user-visible,
3133 then return, without reading any user-visible events. */
3136 swallow_events (do_display
)
3141 while (kbd_fetch_ptr
!= kbd_store_ptr
)
3143 struct input_event
*event
;
3145 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
3149 last_event_timestamp
= event
->timestamp
;
3151 /* These two kinds of events get special handling
3152 and don't actually appear to the command loop. */
3153 if (event
->kind
== selection_request_event
)
3156 struct input_event copy
;
3158 /* Remove it from the buffer before processing it,
3159 since otherwise swallow_events called recursively could see it
3160 and process it again. */
3162 kbd_fetch_ptr
= event
+ 1;
3163 input_pending
= readable_events (0);
3164 x_handle_selection_request (©
);
3166 /* We're getting selection request events, but we don't have
3172 else if (event
->kind
== selection_clear_event
)
3175 struct input_event copy
;
3177 /* Remove it from the buffer before processing it, */
3180 kbd_fetch_ptr
= event
+ 1;
3181 input_pending
= readable_events (0);
3182 x_handle_selection_clear (©
);
3184 /* We're getting selection request events, but we don't have
3193 old_timers_run
= timers_run
;
3194 get_input_pending (&input_pending
, 1);
3196 if (timers_run
!= old_timers_run
&& do_display
)
3197 redisplay_preserve_echo_area ();
3200 static EMACS_TIME timer_idleness_start_time
;
3202 /* Record the start of when Emacs is idle,
3203 for the sake of running idle-time timers. */
3210 /* If we are already in the idle state, do nothing. */
3211 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3214 EMACS_GET_TIME (timer_idleness_start_time
);
3216 /* Mark all idle-time timers as once again candidates for running. */
3217 for (timers
= Vtimer_idle_list
; CONSP (timers
); timers
= XCONS (timers
)->cdr
)
3221 timer
= XCONS (timers
)->car
;
3223 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3225 XVECTOR (timer
)->contents
[0] = Qnil
;
3229 /* Record that Emacs is no longer idle, so stop running idle-time timers. */
3234 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
3237 /* This is only for debugging. */
3238 struct input_event last_timer_event
;
3240 /* Check whether a timer has fired. To prevent larger problems we simply
3241 disregard elements that are not proper timers. Do not make a circular
3242 timer list for the time being.
3244 Returns the number of seconds to wait until the next timer fires. If a
3245 timer is triggering now, return zero seconds.
3246 If no timer is active, return -1 seconds.
3248 If a timer is ripe, we run it, with quitting turned off.
3250 DO_IT_NOW is now ignored. It used to mean that we should
3251 run the timer directly instead of queueing a timer-event.
3252 Now we always run timers directly. */
3255 timer_check (do_it_now
)
3258 EMACS_TIME nexttime
;
3259 EMACS_TIME now
, idleness_now
;
3260 Lisp_Object timers
, idle_timers
, chosen_timer
;
3261 struct gcpro gcpro1
, gcpro2
, gcpro3
;
3263 EMACS_SET_SECS (nexttime
, -1);
3264 EMACS_SET_USECS (nexttime
, -1);
3266 /* Always consider the ordinary timers. */
3267 timers
= Vtimer_list
;
3268 /* Consider the idle timers only if Emacs is idle. */
3269 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3270 idle_timers
= Vtimer_idle_list
;
3273 chosen_timer
= Qnil
;
3274 GCPRO3 (timers
, idle_timers
, chosen_timer
);
3276 if (CONSP (timers
) || CONSP (idle_timers
))
3278 EMACS_GET_TIME (now
);
3279 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3280 EMACS_SUB_TIME (idleness_now
, now
, timer_idleness_start_time
);
3283 while (CONSP (timers
) || CONSP (idle_timers
))
3285 int triggertime
= EMACS_SECS (now
);
3286 Lisp_Object
*vector
;
3287 Lisp_Object timer
, idle_timer
;
3288 EMACS_TIME timer_time
, idle_timer_time
;
3289 EMACS_TIME difference
, timer_difference
, idle_timer_difference
;
3291 /* Skip past invalid timers and timers already handled. */
3294 timer
= XCONS (timers
)->car
;
3295 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3297 timers
= XCONS (timers
)->cdr
;
3300 vector
= XVECTOR (timer
)->contents
;
3302 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
3303 || !INTEGERP (vector
[3])
3304 || ! NILP (vector
[0]))
3306 timers
= XCONS (timers
)->cdr
;
3310 if (!NILP (idle_timers
))
3312 timer
= XCONS (idle_timers
)->car
;
3313 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3315 idle_timers
= XCONS (idle_timers
)->cdr
;
3318 vector
= XVECTOR (timer
)->contents
;
3320 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
3321 || !INTEGERP (vector
[3])
3322 || ! NILP (vector
[0]))
3324 idle_timers
= XCONS (idle_timers
)->cdr
;
3329 /* Set TIMER, TIMER_TIME and TIMER_DIFFERENCE
3330 based on the next ordinary timer.
3331 TIMER_DIFFERENCE is the distance in time from NOW to when
3332 this timer becomes ripe (negative if it's already ripe). */
3335 timer
= XCONS (timers
)->car
;
3336 vector
= XVECTOR (timer
)->contents
;
3337 EMACS_SET_SECS (timer_time
,
3338 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
3339 EMACS_SET_USECS (timer_time
, XINT (vector
[3]));
3340 EMACS_SUB_TIME (timer_difference
, timer_time
, now
);
3343 /* Set IDLE_TIMER, IDLE_TIMER_TIME and IDLE_TIMER_DIFFERENCE
3344 based on the next idle timer. */
3345 if (!NILP (idle_timers
))
3347 idle_timer
= XCONS (idle_timers
)->car
;
3348 vector
= XVECTOR (idle_timer
)->contents
;
3349 EMACS_SET_SECS (idle_timer_time
,
3350 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
3351 EMACS_SET_USECS (idle_timer_time
, XINT (vector
[3]));
3352 EMACS_SUB_TIME (idle_timer_difference
, idle_timer_time
, idleness_now
);
3355 /* Decide which timer is the next timer,
3356 and set CHOSEN_TIMER, VECTOR and DIFFERENCE accordingly.
3357 Also step down the list where we found that timer. */
3359 if (! NILP (timers
) && ! NILP (idle_timers
))
3362 EMACS_SUB_TIME (temp
, timer_difference
, idle_timer_difference
);
3363 if (EMACS_TIME_NEG_P (temp
))
3365 chosen_timer
= timer
;
3366 timers
= XCONS (timers
)->cdr
;
3367 difference
= timer_difference
;
3371 chosen_timer
= idle_timer
;
3372 idle_timers
= XCONS (idle_timers
)->cdr
;
3373 difference
= idle_timer_difference
;
3376 else if (! NILP (timers
))
3378 chosen_timer
= timer
;
3379 timers
= XCONS (timers
)->cdr
;
3380 difference
= timer_difference
;
3384 chosen_timer
= idle_timer
;
3385 idle_timers
= XCONS (idle_timers
)->cdr
;
3386 difference
= idle_timer_difference
;
3388 vector
= XVECTOR (chosen_timer
)->contents
;
3390 /* If timer is rupe, run it if it hasn't been run. */
3391 if (EMACS_TIME_NEG_P (difference
)
3392 || (EMACS_SECS (difference
) == 0
3393 && EMACS_USECS (difference
) == 0))
3395 if (NILP (vector
[0]))
3398 int was_locked
= single_kboard
;
3399 int count
= specpdl_ptr
- specpdl
;
3401 /* Mark the timer as triggered to prevent problems if the lisp
3402 code fails to reschedule it right. */
3405 specbind (Qinhibit_quit
, Qt
);
3407 call1 (Qtimer_event_handler
, chosen_timer
);
3410 unbind_to (count
, Qnil
);
3412 /* Resume allowing input from any kboard, if that was true before. */
3414 any_kboard_state ();
3416 /* Since we have handled the event,
3417 we don't need to tell the caller to wake up and do it. */
3421 /* When we encounter a timer that is still waiting,
3422 return the amount of time to wait before it is ripe. */
3429 /* No timers are pending in the future. */
3430 /* Return 0 if we generated an event, and -1 if not. */
3435 /* Caches for modify_event_symbol. */
3436 static Lisp_Object accent_key_syms
;
3437 static Lisp_Object func_key_syms
;
3438 static Lisp_Object mouse_syms
;
3440 static Lisp_Object mouse_wheel_syms
;
3442 static Lisp_Object drag_n_drop_syms
;
3444 /* This is a list of keysym codes for special "accent" characters.
3445 It parallels lispy_accent_keys. */
3447 static int lispy_accent_codes
[] =
3449 #ifdef XK_dead_circumflex
3454 #ifdef XK_dead_grave
3459 #ifdef XK_dead_tilde
3464 #ifdef XK_dead_diaeresis
3469 #ifdef XK_dead_macron
3474 #ifdef XK_dead_degree
3479 #ifdef XK_dead_acute
3484 #ifdef XK_dead_cedilla
3489 #ifdef XK_dead_breve
3494 #ifdef XK_dead_ogonek
3499 #ifdef XK_dead_caron
3504 #ifdef XK_dead_doubleacute
3505 XK_dead_doubleacute
,
3509 #ifdef XK_dead_abovedot
3516 /* This is a list of Lisp names for special "accent" characters.
3517 It parallels lispy_accent_codes. */
3519 static char *lispy_accent_keys
[] =
3537 #define FUNCTION_KEY_OFFSET 0x0
3539 char *lispy_function_keys
[] =
3543 0, /* VK_LBUTTON 0x01 */
3544 0, /* VK_RBUTTON 0x02 */
3545 "cancel", /* VK_CANCEL 0x03 */
3546 0, /* VK_MBUTTON 0x04 */
3548 0, 0, 0, /* 0x05 .. 0x07 */
3550 "backspace", /* VK_BACK 0x08 */
3551 "tab", /* VK_TAB 0x09 */
3553 0, 0, /* 0x0A .. 0x0B */
3555 "clear", /* VK_CLEAR 0x0C */
3556 "return", /* VK_RETURN 0x0D */
3558 0, 0, /* 0x0E .. 0x0F */
3560 "shift", /* VK_SHIFT 0x10 */
3561 "control", /* VK_CONTROL 0x11 */
3562 "menu", /* VK_MENU 0x12 */
3563 "pause", /* VK_PAUSE 0x13 */
3564 "capital", /* VK_CAPITAL 0x14 */
3566 0, 0, 0, 0, 0, 0, /* 0x15 .. 0x1A */
3568 0, /* VK_ESCAPE 0x1B */
3570 0, 0, 0, 0, /* 0x1C .. 0x1F */
3572 0, /* VK_SPACE 0x20 */
3573 "prior", /* VK_PRIOR 0x21 */
3574 "next", /* VK_NEXT 0x22 */
3575 "end", /* VK_END 0x23 */
3576 "home", /* VK_HOME 0x24 */
3577 "left", /* VK_LEFT 0x25 */
3578 "up", /* VK_UP 0x26 */
3579 "right", /* VK_RIGHT 0x27 */
3580 "down", /* VK_DOWN 0x28 */
3581 "select", /* VK_SELECT 0x29 */
3582 "print", /* VK_PRINT 0x2A */
3583 "execute", /* VK_EXECUTE 0x2B */
3584 "snapshot", /* VK_SNAPSHOT 0x2C */
3585 "insert", /* VK_INSERT 0x2D */
3586 "delete", /* VK_DELETE 0x2E */
3587 "help", /* VK_HELP 0x2F */
3589 /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
3591 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3593 0, 0, 0, 0, 0, 0, 0, /* 0x3A .. 0x40 */
3595 /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
3597 0, 0, 0, 0, 0, 0, 0, 0, 0,
3598 0, 0, 0, 0, 0, 0, 0, 0, 0,
3599 0, 0, 0, 0, 0, 0, 0, 0,
3601 "lwindow", /* VK_LWIN 0x5B */
3602 "rwindow", /* VK_RWIN 0x5C */
3603 "apps", /* VK_APPS 0x5D */
3605 0, 0, /* 0x5E .. 0x5F */
3607 "kp-0", /* VK_NUMPAD0 0x60 */
3608 "kp-1", /* VK_NUMPAD1 0x61 */
3609 "kp-2", /* VK_NUMPAD2 0x62 */
3610 "kp-3", /* VK_NUMPAD3 0x63 */
3611 "kp-4", /* VK_NUMPAD4 0x64 */
3612 "kp-5", /* VK_NUMPAD5 0x65 */
3613 "kp-6", /* VK_NUMPAD6 0x66 */
3614 "kp-7", /* VK_NUMPAD7 0x67 */
3615 "kp-8", /* VK_NUMPAD8 0x68 */
3616 "kp-9", /* VK_NUMPAD9 0x69 */
3617 "kp-multiply", /* VK_MULTIPLY 0x6A */
3618 "kp-add", /* VK_ADD 0x6B */
3619 "kp-separator", /* VK_SEPARATOR 0x6C */
3620 "kp-subtract", /* VK_SUBTRACT 0x6D */
3621 "kp-decimal", /* VK_DECIMAL 0x6E */
3622 "kp-divide", /* VK_DIVIDE 0x6F */
3623 "f1", /* VK_F1 0x70 */
3624 "f2", /* VK_F2 0x71 */
3625 "f3", /* VK_F3 0x72 */
3626 "f4", /* VK_F4 0x73 */
3627 "f5", /* VK_F5 0x74 */
3628 "f6", /* VK_F6 0x75 */
3629 "f7", /* VK_F7 0x76 */
3630 "f8", /* VK_F8 0x77 */
3631 "f9", /* VK_F9 0x78 */
3632 "f10", /* VK_F10 0x79 */
3633 "f11", /* VK_F11 0x7A */
3634 "f12", /* VK_F12 0x7B */
3635 "f13", /* VK_F13 0x7C */
3636 "f14", /* VK_F14 0x7D */
3637 "f15", /* VK_F15 0x7E */
3638 "f16", /* VK_F16 0x7F */
3639 "f17", /* VK_F17 0x80 */
3640 "f18", /* VK_F18 0x81 */
3641 "f19", /* VK_F19 0x82 */
3642 "f20", /* VK_F20 0x83 */
3643 "f21", /* VK_F21 0x84 */
3644 "f22", /* VK_F22 0x85 */
3645 "f23", /* VK_F23 0x86 */
3646 "f24", /* VK_F24 0x87 */
3648 0, 0, 0, 0, /* 0x88 .. 0x8B */
3649 0, 0, 0, 0, /* 0x8C .. 0x8F */
3651 "kp-numlock", /* VK_NUMLOCK 0x90 */
3652 "scroll", /* VK_SCROLL 0x91 */
3654 "kp-space", /* VK_NUMPAD_CLEAR 0x92 */
3655 "kp-enter", /* VK_NUMPAD_ENTER 0x93 */
3656 "kp-prior", /* VK_NUMPAD_PRIOR 0x94 */
3657 "kp-next", /* VK_NUMPAD_NEXT 0x95 */
3658 "kp-end", /* VK_NUMPAD_END 0x96 */
3659 "kp-home", /* VK_NUMPAD_HOME 0x97 */
3660 "kp-left", /* VK_NUMPAD_LEFT 0x98 */
3661 "kp-up", /* VK_NUMPAD_UP 0x99 */
3662 "kp-right", /* VK_NUMPAD_RIGHT 0x9A */
3663 "kp-down", /* VK_NUMPAD_DOWN 0x9B */
3664 "kp-insert", /* VK_NUMPAD_INSERT 0x9C */
3665 "kp-delete", /* VK_NUMPAD_DELETE 0x9D */
3667 0, 0, /* 0x9E .. 0x9F */
3670 * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
3671 * Used only as parameters to GetAsyncKeyState and GetKeyState.
3672 * No other API or message will distinguish left and right keys this way.
3676 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3677 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3678 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3679 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3680 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3686 "attn", /* VK_ATTN 0xF6 */
3687 "crsel", /* VK_CRSEL 0xF7 */
3688 "exsel", /* VK_EXSEL 0xF8 */
3689 "ereof", /* VK_EREOF 0xF9 */
3690 "play", /* VK_PLAY 0xFA */
3691 "zoom", /* VK_ZOOM 0xFB */
3692 "noname", /* VK_NONAME 0xFC */
3693 "pa1", /* VK_PA1 0xFD */
3694 "oem_clear", /* VK_OEM_CLEAR 0xFE */
3697 #else /* not HAVE_NTGUI */
3700 static char *lispy_kana_keys
[] =
3702 /* X Keysym value */
3703 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x400 .. 0x40f */
3704 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x410 .. 0x41f */
3705 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x420 .. 0x42f */
3706 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x430 .. 0x43f */
3707 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x440 .. 0x44f */
3708 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x450 .. 0x45f */
3709 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x460 .. 0x46f */
3710 0,0,0,0,0,0,0,0,0,0,0,0,0,0,"overline",0,
3711 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x480 .. 0x48f */
3712 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x490 .. 0x49f */
3713 0, "kana-fullstop", "kana-openingbracket", "kana-closingbracket",
3714 "kana-comma", "kana-conjunctive", "kana-WO", "kana-a",
3715 "kana-i", "kana-u", "kana-e", "kana-o",
3716 "kana-ya", "kana-yu", "kana-yo", "kana-tsu",
3717 "prolongedsound", "kana-A", "kana-I", "kana-U",
3718 "kana-E", "kana-O", "kana-KA", "kana-KI",
3719 "kana-KU", "kana-KE", "kana-KO", "kana-SA",
3720 "kana-SHI", "kana-SU", "kana-SE", "kana-SO",
3721 "kana-TA", "kana-CHI", "kana-TSU", "kana-TE",
3722 "kana-TO", "kana-NA", "kana-NI", "kana-NU",
3723 "kana-NE", "kana-NO", "kana-HA", "kana-HI",
3724 "kana-FU", "kana-HE", "kana-HO", "kana-MA",
3725 "kana-MI", "kana-MU", "kana-ME", "kana-MO",
3726 "kana-YA", "kana-YU", "kana-YO", "kana-RA",
3727 "kana-RI", "kana-RU", "kana-RE", "kana-RO",
3728 "kana-WA", "kana-N", "voicedsound", "semivoicedsound",
3729 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4e0 .. 0x4ef */
3730 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4f0 .. 0x4ff */
3732 #endif /* XK_kana_A */
3734 #define FUNCTION_KEY_OFFSET 0xff00
3736 /* You'll notice that this table is arranged to be conveniently
3737 indexed by X Windows keysym values. */
3738 static char *lispy_function_keys
[] =
3740 /* X Keysym value */
3742 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00...0f */
3743 "backspace", "tab", "linefeed", "clear",
3745 0, 0, 0, "pause", /* 0xff10...1f */
3746 0, 0, 0, 0, 0, 0, 0, "escape",
3748 0, "kanji", "muhenkan", "henkan", /* 0xff20...2f */
3749 "romaji", "hiragana", "katakana", "hiragana-katakana",
3750 "zenkaku", "hankaku", "zenkaku-hankaku", "touroku",
3751 "massyo", "kana-lock", "kana-shift", "eisu-shift",
3752 "eisu-toggle", /* 0xff30...3f */
3753 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3754 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
3756 "home", "left", "up", "right", /* 0xff50 */ /* IsCursorKey */
3757 "down", "prior", "next", "end",
3758 "begin", 0, 0, 0, 0, 0, 0, 0,
3759 "select", /* 0xff60 */ /* IsMiscFunctionKey */
3770 "break", /* 0xff6b */
3773 0, 0, 0, 0, "backtab", 0, 0, 0, /* 0xff70... */
3774 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff78... */
3775 "kp-space", /* 0xff80 */ /* IsKeypadKey */
3776 0, 0, 0, 0, 0, 0, 0, 0,
3777 "kp-tab", /* 0xff89 */
3779 "kp-enter", /* 0xff8d */
3781 "kp-f1", /* 0xff91 */
3785 "kp-home", /* 0xff95 */
3790 "kp-prior", /* kp-page-up */
3791 "kp-next", /* kp-page-down */
3797 0, 0, 0, 0, 0, 0, 0, 0, 0,
3798 "kp-multiply", /* 0xffaa */
3803 "kp-divide", /* 0xffaf */
3804 "kp-0", /* 0xffb0 */
3805 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
3808 "kp-equal", /* 0xffbd */
3809 "f1", /* 0xffbe */ /* IsFunctionKey */
3811 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
3812 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
3813 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
3814 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
3815 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
3816 0, 0, 0, 0, 0, 0, 0, 0,
3817 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
3818 0, 0, 0, 0, 0, 0, 0, "delete"
3821 /* ISO 9995 Function and Modifier Keys; the first byte is 0xFE. */
3822 #define ISO_FUNCTION_KEY_OFFSET 0xfe00
3824 static char *iso_lispy_function_keys
[] =
3826 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe00 */
3827 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe08 */
3828 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe10 */
3829 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe18 */
3830 "iso-lefttab", /* 0xfe20 */
3831 "iso-move-line-up", "iso-move-line-down",
3832 "iso-partial-line-up", "iso-partial-line-down",
3833 "iso-partial-space-left", "iso-partial-space-right",
3834 "iso-set-margin-left", "iso-set-margin-right", /* 0xffe27, 28 */
3835 "iso-release-margin-left", "iso-release-margin-right",
3836 "iso-release-both-margins",
3837 "iso-fast-cursor-left", "iso-fast-cursor-right",
3838 "iso-fast-cursor-up", "iso-fast-cursor-down",
3839 "iso-continuous-underline", "iso-discontinuous-underline", /* 0xfe30, 31 */
3840 "iso-emphasize", "iso-center-object", "iso-enter", /* ... 0xfe34 */
3843 #endif /* not HAVE_NTGUI */
3845 static char *lispy_mouse_names
[] =
3847 "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5"
3851 /* mouse-wheel events are generated by the wheel on devices such as
3852 the MS Intellimouse. The wheel sits in between the left and right
3853 mouse buttons, and is typically used to scroll or zoom the window
3854 underneath the pointer. mouse-wheel events specify the object on
3855 which they operate, and a delta corresponding to the amount and
3856 direction that the wheel is rotated. Clicking the mouse-wheel
3857 generates a mouse-2 event. */
3858 static char *lispy_mouse_wheel_names
[] =
3863 #endif /* WINDOWSNT */
3865 /* drag-n-drop events are generated when a set of selected files are
3866 dragged from another application and dropped onto an Emacs window. */
3867 static char *lispy_drag_n_drop_names
[] =
3872 /* Scroll bar parts. */
3873 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
3874 Lisp_Object Qup
, Qdown
;
3876 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
3877 Lisp_Object
*scroll_bar_parts
[] = {
3878 &Qabove_handle
, &Qhandle
, &Qbelow_handle
,
3883 /* A vector, indexed by button number, giving the down-going location
3884 of currently depressed buttons, both scroll bar and non-scroll bar.
3886 The elements have the form
3887 (BUTTON-NUMBER MODIFIER-MASK . REST)
3888 where REST is the cdr of a position as it would be reported in the event.
3890 The make_lispy_event function stores positions here to tell the
3891 difference between click and drag events, and to store the starting
3892 location to be included in drag events. */
3894 static Lisp_Object button_down_location
;
3896 /* Information about the most recent up-going button event: Which
3897 button, what location, and what time. */
3899 static int last_mouse_button
;
3900 static int last_mouse_x
;
3901 static int last_mouse_y
;
3902 static unsigned long button_down_time
;
3904 /* The maximum time between clicks to make a double-click,
3905 or Qnil to disable double-click detection,
3906 or Qt for no time limit. */
3907 Lisp_Object Vdouble_click_time
;
3909 /* The number of clicks in this multiple-click. */
3911 int double_click_count
;
3913 /* Given a struct input_event, build the lisp event which represents
3914 it. If EVENT is 0, build a mouse movement event from the mouse
3915 movement buffer, which should have a movement event in it.
3917 Note that events must be passed to this function in the order they
3918 are received; this function stores the location of button presses
3919 in order to build drag events when the button is released. */
3922 make_lispy_event (event
)
3923 struct input_event
*event
;
3927 switch (SWITCH_ENUM_CAST (event
->kind
))
3929 /* A simple keystroke. */
3930 case ascii_keystroke
:
3932 Lisp_Object lispy_c
;
3933 int c
= event
->code
& 0377;
3934 /* Turn ASCII characters into control characters
3936 if (event
->modifiers
& ctrl_modifier
)
3937 c
= make_ctrl_char (c
);
3939 /* Add in the other modifier bits. We took care of ctrl_modifier
3940 just above, and the shift key was taken care of by the X code,
3941 and applied to control characters by make_ctrl_char. */
3942 c
|= (event
->modifiers
3943 & (meta_modifier
| alt_modifier
3944 | hyper_modifier
| super_modifier
));
3945 /* Distinguish Shift-SPC from SPC. */
3946 if ((event
->code
& 0377) == 040
3947 && event
->modifiers
& shift_modifier
)
3948 c
|= shift_modifier
;
3949 button_down_time
= 0;
3950 XSETFASTINT (lispy_c
, c
);
3954 /* A function key. The symbol may need to have modifier prefixes
3956 case non_ascii_keystroke
:
3957 button_down_time
= 0;
3959 for (i
= 0; i
< sizeof (lispy_accent_codes
) / sizeof (int); i
++)
3960 if (event
->code
== lispy_accent_codes
[i
])
3961 return modify_event_symbol (i
,
3963 Qfunction_key
, Qnil
,
3964 lispy_accent_keys
, &accent_key_syms
,
3965 (sizeof (lispy_accent_keys
)
3966 / sizeof (lispy_accent_keys
[0])));
3968 /* Handle system-specific keysyms. */
3969 if (event
->code
& (1 << 28))
3971 /* We need to use an alist rather than a vector as the cache
3972 since we can't make a vector long enuf. */
3973 if (NILP (current_kboard
->system_key_syms
))
3974 current_kboard
->system_key_syms
= Fcons (Qnil
, Qnil
);
3975 return modify_event_symbol (event
->code
,
3978 current_kboard
->Vsystem_key_alist
,
3979 0, ¤t_kboard
->system_key_syms
,
3984 if (event
->code
>= 0x400 && event
->code
< 0x500)
3985 return modify_event_symbol (event
->code
- 0x400,
3986 event
->modifiers
& ~shift_modifier
,
3987 Qfunction_key
, Qnil
,
3988 lispy_kana_keys
, &func_key_syms
,
3989 (sizeof (lispy_kana_keys
)
3990 / sizeof (lispy_kana_keys
[0])));
3991 #endif /* XK_kana_A */
3993 #ifdef ISO_FUNCTION_KEY_OFFSET
3994 if (event
->code
< FUNCTION_KEY_OFFSET
3995 && event
->code
>= ISO_FUNCTION_KEY_OFFSET
)
3996 return modify_event_symbol (event
->code
- ISO_FUNCTION_KEY_OFFSET
,
3998 Qfunction_key
, Qnil
,
3999 iso_lispy_function_keys
, &func_key_syms
,
4000 (sizeof (iso_lispy_function_keys
)
4001 / sizeof (iso_lispy_function_keys
[0])));
4004 return modify_event_symbol (event
->code
- FUNCTION_KEY_OFFSET
,
4006 Qfunction_key
, Qnil
,
4007 lispy_function_keys
, &func_key_syms
,
4008 (sizeof (lispy_function_keys
)
4009 / sizeof (lispy_function_keys
[0])));
4012 /* A mouse click. Figure out where it is, decide whether it's
4013 a press, click or drag, and build the appropriate structure. */
4015 case scroll_bar_click
:
4017 int button
= event
->code
;
4019 Lisp_Object position
;
4020 Lisp_Object
*start_pos_ptr
;
4021 Lisp_Object start_pos
;
4023 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
4026 /* Build the position as appropriate for this mouse click. */
4027 if (event
->kind
== mouse_click
)
4030 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
4035 /* Ignore mouse events that were made on frame that
4036 have been deleted. */
4037 if (! FRAME_LIVE_P (f
))
4040 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4041 &column
, &row
, NULL
, 1);
4043 #ifndef USE_X_TOOLKIT
4044 /* In the non-toolkit version, clicks on the menu bar
4045 are ordinary button events in the event buffer.
4046 Distinguish them, and invoke the menu.
4048 (In the toolkit version, the toolkit handles the menu bar
4049 and Emacs doesn't know about it until after the user
4050 makes a selection.) */
4051 if (row
>= 0 && row
< FRAME_MENU_BAR_LINES (f
)
4052 && (event
->modifiers
& down_modifier
))
4054 Lisp_Object items
, item
;
4059 /* Activate the menu bar on the down event. If the
4060 up event comes in before the menu code can deal with it,
4062 if (! (event
->modifiers
& down_modifier
))
4067 items
= FRAME_MENU_BAR_ITEMS (f
);
4068 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
4070 Lisp_Object pos
, string
;
4071 string
= XVECTOR (items
)->contents
[i
+ 1];
4072 pos
= XVECTOR (items
)->contents
[i
+ 3];
4075 if (column
>= XINT (pos
)
4076 && column
< XINT (pos
) + XSTRING (string
)->size
)
4078 item
= XVECTOR (items
)->contents
[i
];
4084 = Fcons (event
->frame_or_window
,
4086 Fcons (Fcons (event
->x
, event
->y
),
4087 Fcons (make_number (event
->timestamp
),
4090 return Fcons (item
, Fcons (position
, Qnil
));
4092 #endif /* not USE_X_TOOLKIT */
4094 window
= window_from_coordinates (f
, column
, row
, &part
);
4096 if (!WINDOWP (window
))
4098 window
= event
->frame_or_window
;
4103 int pixcolumn
, pixrow
;
4104 column
-= WINDOW_LEFT_MARGIN (XWINDOW (window
));
4105 row
-= XINT (XWINDOW (window
)->top
);
4106 glyph_to_pixel_coords (f
, column
, row
, &pixcolumn
, &pixrow
);
4107 XSETINT (event
->x
, pixcolumn
);
4108 XSETINT (event
->y
, pixrow
);
4113 posn
= Qvertical_line
;
4116 buffer_posn_from_coords (XWINDOW (window
),
4123 Fcons (Fcons (event
->x
, event
->y
),
4124 Fcons (make_number (event
->timestamp
),
4130 Lisp_Object portion_whole
;
4133 window
= event
->frame_or_window
;
4134 portion_whole
= Fcons (event
->x
, event
->y
);
4135 part
= *scroll_bar_parts
[(int) event
->part
];
4139 Fcons (Qvertical_scroll_bar
,
4140 Fcons (portion_whole
,
4141 Fcons (make_number (event
->timestamp
),
4142 Fcons (part
, Qnil
)))));
4145 start_pos_ptr
= &XVECTOR (button_down_location
)->contents
[button
];
4147 start_pos
= *start_pos_ptr
;
4148 *start_pos_ptr
= Qnil
;
4150 is_double
= (button
== last_mouse_button
4151 && XINT (event
->x
) == last_mouse_x
4152 && XINT (event
->y
) == last_mouse_y
4153 && button_down_time
!= 0
4154 && (EQ (Vdouble_click_time
, Qt
)
4155 || (INTEGERP (Vdouble_click_time
)
4156 && ((int)(event
->timestamp
- button_down_time
)
4157 < XINT (Vdouble_click_time
)))));
4158 last_mouse_button
= button
;
4159 last_mouse_x
= XINT (event
->x
);
4160 last_mouse_y
= XINT (event
->y
);
4162 /* If this is a button press, squirrel away the location, so
4163 we can decide later whether it was a click or a drag. */
4164 if (event
->modifiers
& down_modifier
)
4168 double_click_count
++;
4169 event
->modifiers
|= ((double_click_count
> 2)
4174 double_click_count
= 1;
4175 button_down_time
= event
->timestamp
;
4176 *start_pos_ptr
= Fcopy_alist (position
);
4179 /* Now we're releasing a button - check the co-ordinates to
4180 see if this was a click or a drag. */
4181 else if (event
->modifiers
& up_modifier
)
4183 /* If we did not see a down before this up,
4184 ignore the up. Probably this happened because
4185 the down event chose a menu item.
4186 It would be an annoyance to treat the release
4187 of the button that chose the menu item
4188 as a separate event. */
4190 if (!CONSP (start_pos
))
4193 event
->modifiers
&= ~up_modifier
;
4194 #if 0 /* Formerly we treated an up with no down as a click event. */
4195 if (!CONSP (start_pos
))
4196 event
->modifiers
|= click_modifier
;
4200 /* The third element of every position should be the (x,y)
4204 down
= Fnth (make_number (2), start_pos
);
4205 if (EQ (event
->x
, XCONS (down
)->car
)
4206 && EQ (event
->y
, XCONS (down
)->cdr
))
4208 event
->modifiers
|= click_modifier
;
4212 button_down_time
= 0;
4213 event
->modifiers
|= drag_modifier
;
4215 /* Don't check is_double; treat this as multiple
4216 if the down-event was multiple. */
4217 if (double_click_count
> 1)
4218 event
->modifiers
|= ((double_click_count
> 2)
4224 /* Every mouse event should either have the down_modifier or
4225 the up_modifier set. */
4229 /* Get the symbol we should use for the mouse click. */
4232 head
= modify_event_symbol (button
,
4235 lispy_mouse_names
, &mouse_syms
,
4236 (sizeof (lispy_mouse_names
)
4237 / sizeof (lispy_mouse_names
[0])));
4238 if (event
->modifiers
& drag_modifier
)
4243 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
4246 Fcons (make_number (double_click_count
),
4256 case w32_scroll_bar_click
:
4258 int button
= event
->code
;
4260 Lisp_Object position
;
4261 Lisp_Object
*start_pos_ptr
;
4262 Lisp_Object start_pos
;
4264 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
4269 Lisp_Object portion_whole
;
4272 window
= event
->frame_or_window
;
4273 portion_whole
= Fcons (event
->x
, event
->y
);
4274 part
= *scroll_bar_parts
[(int) event
->part
];
4278 Fcons (Qvertical_scroll_bar
,
4279 Fcons (portion_whole
,
4280 Fcons (make_number (event
->timestamp
),
4281 Fcons (part
, Qnil
)))));
4284 /* Always treat W32 scroll bar events as clicks. */
4285 event
->modifiers
|= click_modifier
;
4288 /* Get the symbol we should use for the mouse click. */
4291 head
= modify_event_symbol (button
,
4294 lispy_mouse_names
, &mouse_syms
,
4295 (sizeof (lispy_mouse_names
)
4296 / sizeof (lispy_mouse_names
[0])));
4305 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
4308 Lisp_Object head
, position
;
4311 /* Ignore mouse events that were made on frame that
4312 have been deleted. */
4313 if (! FRAME_LIVE_P (f
))
4315 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4316 &column
, &row
, NULL
, 1);
4317 window
= window_from_coordinates (f
, column
, row
, &part
);
4319 if (!WINDOWP (window
))
4321 window
= event
->frame_or_window
;
4326 int pixcolumn
, pixrow
;
4327 column
-= XINT (XWINDOW (window
)->left
);
4328 row
-= XINT (XWINDOW (window
)->top
);
4329 glyph_to_pixel_coords (f
, column
, row
, &pixcolumn
, &pixrow
);
4330 XSETINT (event
->x
, pixcolumn
);
4331 XSETINT (event
->y
, pixrow
);
4336 posn
= Qvertical_line
;
4339 buffer_posn_from_coords (XWINDOW (window
),
4344 Lisp_Object head
, position
;
4349 Fcons (Fcons (event
->x
, event
->y
),
4350 Fcons (make_number (event
->timestamp
),
4353 head
= modify_event_symbol (0, event
->modifiers
,
4355 lispy_mouse_wheel_names
,
4356 &mouse_wheel_syms
, 1);
4359 Fcons (make_number (event
->code
),
4363 #endif /* WINDOWSNT */
4371 Lisp_Object head
, position
;
4375 /* The frame_or_window field should be a cons of the frame in
4376 which the event occurred and a list of the filenames
4378 if (! CONSP (event
->frame_or_window
))
4381 f
= XFRAME (XCONS (event
->frame_or_window
)->car
);
4382 files
= XCONS (event
->frame_or_window
)->cdr
;
4384 /* Ignore mouse events that were made on frames that
4385 have been deleted. */
4386 if (! FRAME_LIVE_P (f
))
4388 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4389 &column
, &row
, NULL
, 1);
4390 window
= window_from_coordinates (f
, column
, row
, &part
);
4392 if (!WINDOWP (window
))
4394 window
= XCONS (event
->frame_or_window
)->car
;
4399 int pixcolumn
, pixrow
;
4400 column
-= XINT (XWINDOW (window
)->left
);
4401 row
-= XINT (XWINDOW (window
)->top
);
4402 glyph_to_pixel_coords (f
, column
, row
, &pixcolumn
, &pixrow
);
4403 XSETINT (event
->x
, pixcolumn
);
4404 XSETINT (event
->y
, pixrow
);
4409 posn
= Qvertical_line
;
4412 buffer_posn_from_coords (XWINDOW (window
),
4417 Lisp_Object head
, position
;
4422 Fcons (Fcons (event
->x
, event
->y
),
4423 Fcons (make_number (event
->timestamp
),
4426 head
= modify_event_symbol (0, event
->modifiers
,
4428 lispy_drag_n_drop_names
,
4429 &drag_n_drop_syms
, 1);
4436 #endif /* HAVE_MOUSE */
4438 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
4439 case menu_bar_event
:
4440 /* The event value is in the cdr of the frame_or_window slot. */
4441 if (!CONSP (event
->frame_or_window
))
4443 return XCONS (event
->frame_or_window
)->cdr
;
4446 /* The 'kind' field of the event is something we don't recognize. */
4455 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
4457 Lisp_Object bar_window
;
4458 enum scroll_bar_part part
;
4462 /* Is it a scroll bar movement? */
4463 if (frame
&& ! NILP (bar_window
))
4465 Lisp_Object part_sym
;
4467 part_sym
= *scroll_bar_parts
[(int) part
];
4468 return Fcons (Qscroll_bar_movement
,
4469 (Fcons (Fcons (bar_window
,
4470 Fcons (Qvertical_scroll_bar
,
4471 Fcons (Fcons (x
, y
),
4472 Fcons (make_number (time
),
4478 /* Or is it an ordinary mouse movement? */
4488 /* It's in a frame; which window on that frame? */
4489 pixel_to_glyph_coords (frame
, XINT (x
), XINT (y
), &column
, &row
,
4491 window
= window_from_coordinates (frame
, column
, row
, &area
);
4496 if (WINDOWP (window
))
4498 int pixcolumn
, pixrow
;
4499 column
-= WINDOW_LEFT_MARGIN (XWINDOW (window
));
4500 row
-= XINT (XWINDOW (window
)->top
);
4501 glyph_to_pixel_coords (frame
, column
, row
, &pixcolumn
, &pixrow
);
4502 XSETINT (x
, pixcolumn
);
4503 XSETINT (y
, pixrow
);
4508 posn
= Qvertical_line
;
4511 buffer_posn_from_coords (XWINDOW (window
), column
, row
));
4513 else if (frame
!= 0)
4515 XSETFRAME (window
, frame
);
4526 return Fcons (Qmouse_movement
,
4527 Fcons (Fcons (window
,
4529 Fcons (Fcons (x
, y
),
4530 Fcons (make_number (time
),
4536 #endif /* HAVE_MOUSE */
4538 /* Construct a switch frame event. */
4540 make_lispy_switch_frame (frame
)
4543 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
4546 /* Manipulating modifiers. */
4548 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
4550 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
4551 SYMBOL's name of the end of the modifiers; the string from this
4552 position is the unmodified symbol name.
4554 This doesn't use any caches. */
4557 parse_modifiers_uncached (symbol
, modifier_end
)
4561 struct Lisp_String
*name
;
4565 CHECK_SYMBOL (symbol
, 1);
4568 name
= XSYMBOL (symbol
)->name
;
4570 for (i
= 0; i
+2 <= STRING_BYTES (name
); )
4572 int this_mod_end
= 0;
4575 /* See if the name continues with a modifier word.
4576 Check that the word appears, but don't check what follows it.
4577 Set this_mod and this_mod_end to record what we find. */
4579 switch (name
->data
[i
])
4581 #define SINGLE_LETTER_MOD(BIT) \
4582 (this_mod_end = i + 1, this_mod = BIT)
4585 SINGLE_LETTER_MOD (alt_modifier
);
4589 SINGLE_LETTER_MOD (ctrl_modifier
);
4593 SINGLE_LETTER_MOD (hyper_modifier
);
4597 SINGLE_LETTER_MOD (meta_modifier
);
4601 SINGLE_LETTER_MOD (shift_modifier
);
4605 SINGLE_LETTER_MOD (super_modifier
);
4608 #undef SINGLE_LETTER_MOD
4611 /* If we found no modifier, stop looking for them. */
4612 if (this_mod_end
== 0)
4615 /* Check there is a dash after the modifier, so that it
4616 really is a modifier. */
4617 if (this_mod_end
>= STRING_BYTES (name
)
4618 || name
->data
[this_mod_end
] != '-')
4621 /* This modifier is real; look for another. */
4622 modifiers
|= this_mod
;
4623 i
= this_mod_end
+ 1;
4626 /* Should we include the `click' modifier? */
4627 if (! (modifiers
& (down_modifier
| drag_modifier
4628 | double_modifier
| triple_modifier
))
4629 && i
+ 7 == STRING_BYTES (name
)
4630 && strncmp (name
->data
+ i
, "mouse-", 6) == 0
4631 && ('0' <= name
->data
[i
+ 6] && name
->data
[i
+ 6] <= '9'))
4632 modifiers
|= click_modifier
;
4640 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
4641 prepended to the string BASE[0..BASE_LEN-1].
4642 This doesn't use any caches. */
4644 apply_modifiers_uncached (modifiers
, base
, base_len
, base_len_byte
)
4647 int base_len
, base_len_byte
;
4649 /* Since BASE could contain nulls, we can't use intern here; we have
4650 to use Fintern, which expects a genuine Lisp_String, and keeps a
4653 = (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
4659 /* Only the event queue may use the `up' modifier; it should always
4660 be turned into a click or drag event before presented to lisp code. */
4661 if (modifiers
& up_modifier
)
4664 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
4665 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
4666 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
4667 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
4668 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
4669 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
4670 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
4671 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
4672 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
4673 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
4674 /* The click modifier is denoted by the absence of other modifiers. */
4678 mod_len
= p
- new_mods
;
4682 Lisp_Object new_name
;
4684 new_name
= make_uninit_multibyte_string (mod_len
+ base_len
,
4685 mod_len
+ base_len_byte
);
4686 bcopy (new_mods
, XSTRING (new_name
)->data
, mod_len
);
4687 bcopy (base
, XSTRING (new_name
)->data
+ mod_len
, base_len_byte
);
4689 return Fintern (new_name
, Qnil
);
4694 static char *modifier_names
[] =
4696 "up", "down", "drag", "click", "double", "triple", 0, 0,
4697 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4698 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
4700 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
4702 static Lisp_Object modifier_symbols
;
4704 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
4706 lispy_modifier_list (modifiers
)
4709 Lisp_Object modifier_list
;
4712 modifier_list
= Qnil
;
4713 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
4714 if (modifiers
& (1<<i
))
4715 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
4718 return modifier_list
;
4722 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
4723 where UNMODIFIED is the unmodified form of SYMBOL,
4724 MASK is the set of modifiers present in SYMBOL's name.
4725 This is similar to parse_modifiers_uncached, but uses the cache in
4726 SYMBOL's Qevent_symbol_element_mask property, and maintains the
4727 Qevent_symbol_elements property. */
4730 parse_modifiers (symbol
)
4733 Lisp_Object elements
;
4735 elements
= Fget (symbol
, Qevent_symbol_element_mask
);
4736 if (CONSP (elements
))
4741 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
4742 Lisp_Object unmodified
;
4745 unmodified
= Fintern (make_string (XSYMBOL (symbol
)->name
->data
+ end
,
4746 STRING_BYTES (XSYMBOL (symbol
)->name
) - end
),
4749 if (modifiers
& ~(((EMACS_INT
)1 << VALBITS
) - 1))
4751 XSETFASTINT (mask
, modifiers
);
4752 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
4754 /* Cache the parsing results on SYMBOL. */
4755 Fput (symbol
, Qevent_symbol_element_mask
,
4757 Fput (symbol
, Qevent_symbol_elements
,
4758 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
4760 /* Since we know that SYMBOL is modifiers applied to unmodified,
4761 it would be nice to put that in unmodified's cache.
4762 But we can't, since we're not sure that parse_modifiers is
4769 /* Apply the modifiers MODIFIERS to the symbol BASE.
4770 BASE must be unmodified.
4772 This is like apply_modifiers_uncached, but uses BASE's
4773 Qmodifier_cache property, if present. It also builds
4774 Qevent_symbol_elements properties, since it has that info anyway.
4776 apply_modifiers copies the value of BASE's Qevent_kind property to
4777 the modified symbol. */
4779 apply_modifiers (modifiers
, base
)
4783 Lisp_Object cache
, index
, entry
, new_symbol
;
4785 /* Mask out upper bits. We don't know where this value's been. */
4786 modifiers
&= ((EMACS_INT
)1 << VALBITS
) - 1;
4788 /* The click modifier never figures into cache indices. */
4789 cache
= Fget (base
, Qmodifier_cache
);
4790 XSETFASTINT (index
, (modifiers
& ~click_modifier
));
4791 entry
= assq_no_quit (index
, cache
);
4794 new_symbol
= XCONS (entry
)->cdr
;
4797 /* We have to create the symbol ourselves. */
4798 new_symbol
= apply_modifiers_uncached (modifiers
,
4799 XSYMBOL (base
)->name
->data
,
4800 XSYMBOL (base
)->name
->size
,
4801 STRING_BYTES (XSYMBOL (base
)->name
));
4803 /* Add the new symbol to the base's cache. */
4804 entry
= Fcons (index
, new_symbol
);
4805 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
4807 /* We have the parsing info now for free, so add it to the caches. */
4808 XSETFASTINT (index
, modifiers
);
4809 Fput (new_symbol
, Qevent_symbol_element_mask
,
4810 Fcons (base
, Fcons (index
, Qnil
)));
4811 Fput (new_symbol
, Qevent_symbol_elements
,
4812 Fcons (base
, lispy_modifier_list (modifiers
)));
4815 /* Make sure this symbol is of the same kind as BASE.
4817 You'd think we could just set this once and for all when we
4818 intern the symbol above, but reorder_modifiers may call us when
4819 BASE's property isn't set right; we can't assume that just
4820 because it has a Qmodifier_cache property it must have its
4821 Qevent_kind set right as well. */
4822 if (NILP (Fget (new_symbol
, Qevent_kind
)))
4826 kind
= Fget (base
, Qevent_kind
);
4828 Fput (new_symbol
, Qevent_kind
, kind
);
4835 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
4836 return a symbol with the modifiers placed in the canonical order.
4837 Canonical order is alphabetical, except for down and drag, which
4838 always come last. The 'click' modifier is never written out.
4840 Fdefine_key calls this to make sure that (for example) C-M-foo
4841 and M-C-foo end up being equivalent in the keymap. */
4844 reorder_modifiers (symbol
)
4847 /* It's hopefully okay to write the code this way, since everything
4848 will soon be in caches, and no consing will be done at all. */
4851 parsed
= parse_modifiers (symbol
);
4852 return apply_modifiers ((int) XINT (XCONS (XCONS (parsed
)->cdr
)->car
),
4853 XCONS (parsed
)->car
);
4857 /* For handling events, we often want to produce a symbol whose name
4858 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
4859 to some base, like the name of a function key or mouse button.
4860 modify_event_symbol produces symbols of this sort.
4862 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
4863 is the name of the i'th symbol. TABLE_SIZE is the number of elements
4866 Alternatively, NAME_ALIST is an alist mapping codes into symbol names.
4867 NAME_ALIST is used if it is non-nil; otherwise NAME_TABLE is used.
4869 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
4870 persist between calls to modify_event_symbol that it can use to
4871 store a cache of the symbols it's generated for this NAME_TABLE
4872 before. The object stored there may be a vector or an alist.
4874 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
4876 MODIFIERS is a set of modifier bits (as given in struct input_events)
4877 whose prefixes should be applied to the symbol name.
4879 SYMBOL_KIND is the value to be placed in the event_kind property of
4880 the returned symbol.
4882 The symbols we create are supposed to have an
4883 `event-symbol-elements' property, which lists the modifiers present
4884 in the symbol's name. */
4887 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_alist
,
4888 name_table
, symbol_table
, table_size
)
4891 Lisp_Object symbol_kind
;
4892 Lisp_Object name_alist
;
4894 Lisp_Object
*symbol_table
;
4895 unsigned int table_size
;
4898 Lisp_Object symbol_int
;
4900 /* Get rid of the "vendor-specific" bit here. */
4901 XSETINT (symbol_int
, symbol_num
& 0xffffff);
4903 /* Is this a request for a valid symbol? */
4904 if (symbol_num
< 0 || symbol_num
>= table_size
)
4907 if (CONSP (*symbol_table
))
4908 value
= Fcdr (assq_no_quit (symbol_int
, *symbol_table
));
4910 /* If *symbol_table doesn't seem to be initialized properly, fix that.
4911 *symbol_table should be a lisp vector TABLE_SIZE elements long,
4912 where the Nth element is the symbol for NAME_TABLE[N], or nil if
4913 we've never used that symbol before. */
4916 if (! VECTORP (*symbol_table
)
4917 || XVECTOR (*symbol_table
)->size
!= table_size
)
4921 XSETFASTINT (size
, table_size
);
4922 *symbol_table
= Fmake_vector (size
, Qnil
);
4925 value
= XVECTOR (*symbol_table
)->contents
[symbol_num
];
4928 /* Have we already used this symbol before? */
4931 /* No; let's create it. */
4932 if (!NILP (name_alist
))
4933 value
= Fcdr_safe (Fassq (symbol_int
, name_alist
));
4934 else if (name_table
!= 0 && name_table
[symbol_num
])
4935 value
= intern (name_table
[symbol_num
]);
4937 #ifdef HAVE_WINDOW_SYSTEM
4940 char *name
= x_get_keysym_name (symbol_num
);
4942 value
= intern (name
);
4949 sprintf (buf
, "key-%d", symbol_num
);
4950 value
= intern (buf
);
4953 if (CONSP (*symbol_table
))
4954 *symbol_table
= Fcons (Fcons (symbol_int
, value
), *symbol_table
);
4956 XVECTOR (*symbol_table
)->contents
[symbol_num
] = value
;
4958 /* Fill in the cache entries for this symbol; this also
4959 builds the Qevent_symbol_elements property, which the user
4961 apply_modifiers (modifiers
& click_modifier
, value
);
4962 Fput (value
, Qevent_kind
, symbol_kind
);
4965 /* Apply modifiers to that symbol. */
4966 return apply_modifiers (modifiers
, value
);
4969 /* Convert a list that represents an event type,
4970 such as (ctrl meta backspace), into the usual representation of that
4971 event type as a number or a symbol. */
4973 DEFUN ("event-convert-list", Fevent_convert_list
, Sevent_convert_list
, 1, 1, 0,
4974 "Convert the event description list EVENT-DESC to an event type.\n\
4975 EVENT-DESC should contain one base event type (a character or symbol)\n\
4976 and zero or more modifier names (control, meta, hyper, super, shift, alt,\n\
4977 drag, down, double or triple). The base must be last.\n\
4978 The return value is an event type (a character or symbol) which\n\
4979 has the same base event type and all the specified modifiers.")
4981 Lisp_Object event_desc
;
4989 while (CONSP (rest
))
4994 elt
= XCONS (rest
)->car
;
4995 rest
= XCONS (rest
)->cdr
;
4997 /* Given a symbol, see if it is a modifier name. */
4998 if (SYMBOLP (elt
) && CONSP (rest
))
4999 this = parse_solitary_modifier (elt
);
5003 else if (!NILP (base
))
5004 error ("Two bases given in one event");
5010 /* Let the symbol A refer to the character A. */
5011 if (SYMBOLP (base
) && XSYMBOL (base
)->name
->size
== 1)
5012 XSETINT (base
, XSYMBOL (base
)->name
->data
[0]);
5014 if (INTEGERP (base
))
5016 /* Turn (shift a) into A. */
5017 if ((modifiers
& shift_modifier
) != 0
5018 && (XINT (base
) >= 'a' && XINT (base
) <= 'z'))
5020 XSETINT (base
, XINT (base
) - ('a' - 'A'));
5021 modifiers
&= ~shift_modifier
;
5024 /* Turn (control a) into C-a. */
5025 if (modifiers
& ctrl_modifier
)
5026 return make_number ((modifiers
& ~ctrl_modifier
)
5027 | make_ctrl_char (XINT (base
)));
5029 return make_number (modifiers
| XINT (base
));
5031 else if (SYMBOLP (base
))
5032 return apply_modifiers (modifiers
, base
);
5034 error ("Invalid base event");
5037 /* Try to recognize SYMBOL as a modifier name.
5038 Return the modifier flag bit, or 0 if not recognized. */
5041 parse_solitary_modifier (symbol
)
5044 struct Lisp_String
*name
= XSYMBOL (symbol
)->name
;
5046 switch (name
->data
[0])
5048 #define SINGLE_LETTER_MOD(BIT) \
5049 if (STRING_BYTES (name) == 1) \
5052 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
5053 if (LEN == STRING_BYTES (name) \
5054 && ! strncmp (name->data, NAME, LEN)) \
5058 SINGLE_LETTER_MOD (alt_modifier
);
5062 MULTI_LETTER_MOD (alt_modifier
, "alt", 3);
5066 SINGLE_LETTER_MOD (ctrl_modifier
);
5070 MULTI_LETTER_MOD (ctrl_modifier
, "ctrl", 4);
5071 MULTI_LETTER_MOD (ctrl_modifier
, "control", 7);
5075 SINGLE_LETTER_MOD (hyper_modifier
);
5079 MULTI_LETTER_MOD (hyper_modifier
, "hyper", 5);
5083 SINGLE_LETTER_MOD (meta_modifier
);
5087 MULTI_LETTER_MOD (meta_modifier
, "meta", 4);
5091 SINGLE_LETTER_MOD (shift_modifier
);
5095 MULTI_LETTER_MOD (shift_modifier
, "shift", 5);
5096 MULTI_LETTER_MOD (super_modifier
, "super", 5);
5097 SINGLE_LETTER_MOD (super_modifier
);
5101 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
5102 MULTI_LETTER_MOD (down_modifier
, "down", 4);
5103 MULTI_LETTER_MOD (double_modifier
, "double", 6);
5107 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
5110 #undef SINGLE_LETTER_MOD
5111 #undef MULTI_LETTER_MOD
5117 /* Return 1 if EVENT is a list whose elements are all integers or symbols.
5118 Such a list is not valid as an event,
5119 but it can be a Lucid-style event type list. */
5122 lucid_event_type_list_p (object
)
5127 if (! CONSP (object
))
5130 for (tail
= object
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5133 elt
= XCONS (tail
)->car
;
5134 if (! (INTEGERP (elt
) || SYMBOLP (elt
)))
5141 /* Store into *addr a value nonzero if terminal input chars are available.
5142 Serves the purpose of ioctl (0, FIONREAD, addr)
5143 but works even if FIONREAD does not exist.
5144 (In fact, this may actually read some input.)
5146 If DO_TIMERS_NOW is nonzero, actually run timer events that are ripe. */
5149 get_input_pending (addr
, do_timers_now
)
5153 /* First of all, have we already counted some input? */
5154 *addr
= !NILP (Vquit_flag
) || readable_events (do_timers_now
);
5156 /* If input is being read as it arrives, and we have none, there is none. */
5157 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
5160 /* Try to read some input and see how much we get. */
5162 *addr
= !NILP (Vquit_flag
) || readable_events (do_timers_now
);
5165 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
5168 gobble_input (expected
)
5173 if (interrupt_input
)
5176 mask
= sigblock (sigmask (SIGIO
));
5177 read_avail_input (expected
);
5181 #ifdef POLL_FOR_INPUT
5182 if (read_socket_hook
&& !interrupt_input
&& poll_suppress_count
== 0)
5185 mask
= sigblock (sigmask (SIGALRM
));
5186 read_avail_input (expected
);
5192 read_avail_input (expected
);
5196 /* Put a buffer_switch_event in the buffer
5197 so that read_key_sequence will notice the new current buffer. */
5200 record_asynch_buffer_change ()
5202 struct input_event event
;
5205 event
.kind
= buffer_switch_event
;
5206 event
.frame_or_window
= Qnil
;
5209 /* We don't need a buffer-switch event unless Emacs is waiting for input.
5210 The purpose of the event is to make read_key_sequence look up the
5211 keymaps again. If we aren't in read_key_sequence, we don't need one,
5212 and the event could cause trouble by messing up (input-pending-p). */
5213 tem
= Fwaiting_for_user_input_p ();
5217 /* We never need these events if we have no asynchronous subprocesses. */
5221 /* Make sure no interrupt happens while storing the event. */
5223 if (interrupt_input
)
5226 mask
= sigblock (sigmask (SIGIO
));
5227 kbd_buffer_store_event (&event
);
5234 kbd_buffer_store_event (&event
);
5241 /* Read any terminal input already buffered up by the system
5242 into the kbd_buffer, but do not wait.
5244 EXPECTED should be nonzero if the caller knows there is some input.
5246 Except on VMS, all input is read by this function.
5247 If interrupt_input is nonzero, this function MUST be called
5248 only when SIGIO is blocked.
5250 Returns the number of keyboard chars read, or -1 meaning
5251 this is a bad time to try to read input. */
5254 read_avail_input (expected
)
5257 struct input_event buf
[KBD_BUFFER_SIZE
];
5261 if (read_socket_hook
)
5262 /* No need for FIONREAD or fcntl; just say don't wait. */
5263 nread
= (*read_socket_hook
) (input_fd
, buf
, KBD_BUFFER_SIZE
, expected
);
5266 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
5267 the kbd_buffer can really hold. That may prevent loss
5268 of characters on some systems when input is stuffed at us. */
5269 unsigned char cbuf
[KBD_BUFFER_SIZE
- 1];
5272 /* Determine how many characters we should *try* to read. */
5275 #else /* not WINDOWSNT */
5277 n_to_read
= dos_keysns ();
5280 #else /* not MSDOS */
5282 /* Find out how much input is available. */
5283 if (ioctl (input_fd
, FIONREAD
, &n_to_read
) < 0)
5284 /* Formerly simply reported no input, but that sometimes led to
5285 a failure of Emacs to terminate.
5286 SIGHUP seems appropriate if we can't reach the terminal. */
5287 /* ??? Is it really right to send the signal just to this process
5288 rather than to the whole process group?
5289 Perhaps on systems with FIONREAD Emacs is alone in its group. */
5290 kill (getpid (), SIGHUP
);
5293 if (n_to_read
> sizeof cbuf
)
5294 n_to_read
= sizeof cbuf
;
5295 #else /* no FIONREAD */
5296 #if defined (USG) || defined (DGUX)
5297 /* Read some input if available, but don't wait. */
5298 n_to_read
= sizeof cbuf
;
5299 fcntl (input_fd
, F_SETFL
, O_NDELAY
);
5304 #endif /* not MSDOS */
5305 #endif /* not WINDOWSNT */
5307 /* Now read; for one reason or another, this will not block.
5308 NREAD is set to the number of chars read. */
5312 cbuf
[0] = dos_keyread ();
5315 nread
= read (input_fd
, cbuf
, n_to_read
);
5317 /* POSIX infers that processes which are not in the session leader's
5318 process group won't get SIGHUP's at logout time. BSDI adheres to
5319 this part standard and returns -1 from read (0) with errno==EIO
5320 when the control tty is taken away.
5321 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
5322 if (nread
== -1 && errno
== EIO
)
5324 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
5325 /* The kernel sometimes fails to deliver SIGHUP for ptys.
5326 This looks incorrect, but it isn't, because _BSD causes
5327 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
5328 and that causes a value other than 0 when there is no input. */
5334 /* We used to retry the read if it was interrupted.
5335 But this does the wrong thing when O_NDELAY causes
5336 an EAGAIN error. Does anybody know of a situation
5337 where a retry is actually needed? */
5339 nread
< 0 && (errno
== EAGAIN
5353 #if defined (USG) || defined (DGUX)
5354 fcntl (input_fd
, F_SETFL
, 0);
5355 #endif /* USG or DGUX */
5356 #endif /* no FIONREAD */
5357 for (i
= 0; i
< nread
; i
++)
5359 buf
[i
].kind
= ascii_keystroke
;
5360 buf
[i
].modifiers
= 0;
5361 if (meta_key
== 1 && (cbuf
[i
] & 0x80))
5362 buf
[i
].modifiers
= meta_modifier
;
5366 buf
[i
].code
= cbuf
[i
];
5367 XSETFRAME (buf
[i
].frame_or_window
, selected_frame
);
5371 /* Scan the chars for C-g and store them in kbd_buffer. */
5372 for (i
= 0; i
< nread
; i
++)
5374 kbd_buffer_store_event (&buf
[i
]);
5375 /* Don't look at input that follows a C-g too closely.
5376 This reduces lossage due to autorepeat on C-g. */
5377 if (buf
[i
].kind
== ascii_keystroke
5378 && buf
[i
].code
== quit_char
)
5384 #endif /* not VMS */
5386 #ifdef SIGIO /* for entire page */
5387 /* Note SIGIO has been undef'd if FIONREAD is missing. */
5390 input_available_signal (signo
)
5393 /* Must preserve main program's value of errno. */
5394 int old_errno
= errno
;
5396 extern int select_alarmed
;
5399 #if defined (USG) && !defined (POSIX_SIGNALS)
5400 /* USG systems forget handlers when they are used;
5401 must reestablish each time */
5402 signal (signo
, input_available_signal
);
5409 if (input_available_clear_time
)
5410 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
5415 nread
= read_avail_input (1);
5416 /* -1 means it's not ok to read the input now.
5417 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
5418 0 means there was no keyboard input available. */
5423 select_alarmed
= 1; /* Force the select emulator back to life */
5434 /* Send ourselves a SIGIO.
5436 This function exists so that the UNBLOCK_INPUT macro in
5437 blockinput.h can have some way to take care of input we put off
5438 dealing with, without assuming that every file which uses
5439 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
5441 reinvoke_input_signal ()
5444 kill (getpid (), SIGIO
);
5450 /* Return the prompt-string of a sparse keymap.
5451 This is the first element which is a string.
5452 Return nil if there is none. */
5460 register Lisp_Object tem
;
5469 static void menu_bar_item ();
5470 static void menu_bar_one_keymap ();
5472 /* These variables hold the vector under construction within
5473 menu_bar_items and its subroutines, and the current index
5474 for storing into that vector. */
5475 static Lisp_Object menu_bar_items_vector
;
5476 static int menu_bar_items_index
;
5478 /* Return a vector of menu items for a menu bar, appropriate
5479 to the current buffer. Each item has three elements in the vector:
5482 OLD is an old vector we can optionally reuse, or nil. */
5485 menu_bar_items (old
)
5488 /* The number of keymaps we're scanning right now, and the number of
5489 keymaps we have allocated space for. */
5492 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
5493 in the current keymaps, or nil where it is not a prefix. */
5496 Lisp_Object def
, tem
, tail
;
5505 struct gcpro gcpro1
;
5507 /* In order to build the menus, we need to call the keymap
5508 accessors. They all call QUIT. But this function is called
5509 during redisplay, during which a quit is fatal. So inhibit
5510 quitting while building the menus.
5511 We do this instead of specbind because (1) errors will clear it anyway
5512 and (2) this avoids risk of specpdl overflow. */
5513 oquit
= Vinhibit_quit
;
5517 menu_bar_items_vector
= old
;
5519 menu_bar_items_vector
= Fmake_vector (make_number (24), Qnil
);
5520 menu_bar_items_index
= 0;
5522 GCPRO1 (menu_bar_items_vector
);
5524 /* Build our list of keymaps.
5525 If we recognize a function key and replace its escape sequence in
5526 keybuf with its symbol, or if the sequence starts with a mouse
5527 click and we need to switch buffers, we jump back here to rebuild
5528 the initial keymaps from the current buffer. */
5532 /* Should overriding-terminal-local-map and overriding-local-map apply? */
5533 if (!NILP (Voverriding_local_map_menu_flag
))
5535 /* Yes, use them (if non-nil) as well as the global map. */
5536 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
5538 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
5539 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
5540 if (!NILP (Voverriding_local_map
))
5541 maps
[nmaps
++] = Voverriding_local_map
;
5545 /* No, so use major and minor mode keymaps. */
5546 nmaps
= current_minor_maps (NULL
, &tmaps
);
5547 maps
= (Lisp_Object
*) alloca ((nmaps
+ 2) * sizeof (maps
[0]));
5548 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
5549 #ifdef USE_TEXT_PROPERTIES
5550 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
5552 maps
[nmaps
++] = current_buffer
->keymap
;
5555 maps
[nmaps
++] = current_global_map
;
5558 /* Look up in each map the dummy prefix key `menu-bar'. */
5562 for (mapno
= nmaps
- 1; mapno
>= 0; mapno
--)
5564 if (! NILP (maps
[mapno
]))
5565 def
= get_keyelt (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0), 0);
5569 tem
= Fkeymapp (def
);
5571 menu_bar_one_keymap (def
);
5574 /* Move to the end those items that should be at the end. */
5576 for (tail
= Vmenu_bar_final_items
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5579 int end
= menu_bar_items_index
;
5581 for (i
= 0; i
< end
; i
+= 4)
5582 if (EQ (XCONS (tail
)->car
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
5584 Lisp_Object tem0
, tem1
, tem2
, tem3
;
5585 /* Move the item at index I to the end,
5586 shifting all the others forward. */
5587 tem0
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 0];
5588 tem1
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 1];
5589 tem2
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
5590 tem3
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3];
5592 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
5593 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
5594 (end
- i
- 4) * sizeof (Lisp_Object
));
5595 XVECTOR (menu_bar_items_vector
)->contents
[end
- 4] = tem0
;
5596 XVECTOR (menu_bar_items_vector
)->contents
[end
- 3] = tem1
;
5597 XVECTOR (menu_bar_items_vector
)->contents
[end
- 2] = tem2
;
5598 XVECTOR (menu_bar_items_vector
)->contents
[end
- 1] = tem3
;
5603 /* Add nil, nil, nil, nil at the end. */
5604 i
= menu_bar_items_index
;
5605 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
5608 int newsize
= 2 * i
;
5609 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
5610 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
5611 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
5612 menu_bar_items_vector
= tem
;
5614 /* Add this item. */
5615 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5616 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5617 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5618 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5619 menu_bar_items_index
= i
;
5621 Vinhibit_quit
= oquit
;
5623 return menu_bar_items_vector
;
5626 /* Scan one map KEYMAP, accumulating any menu items it defines
5627 in menu_bar_items_vector. */
5630 menu_bar_one_keymap (keymap
)
5633 Lisp_Object tail
, item
, table
;
5635 /* Loop over all keymap entries that have menu strings. */
5636 for (tail
= keymap
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5638 item
= XCONS (tail
)->car
;
5640 menu_bar_item (XCONS (item
)->car
, XCONS (item
)->cdr
);
5641 else if (VECTORP (item
))
5643 /* Loop over the char values represented in the vector. */
5644 int len
= XVECTOR (item
)->size
;
5646 for (c
= 0; c
< len
; c
++)
5648 Lisp_Object character
;
5649 XSETFASTINT (character
, c
);
5650 menu_bar_item (character
, XVECTOR (item
)->contents
[c
]);
5656 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
5657 If there's already an item for KEY, add this DEF to it. */
5659 Lisp_Object item_properties
;
5662 menu_bar_item (key
, item
)
5663 Lisp_Object key
, item
;
5665 struct gcpro gcpro1
;
5668 if (EQ (item
, Qundefined
))
5670 /* If a map has an explicit `undefined' as definition,
5671 discard any previously made menu bar item. */
5673 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
5674 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
5676 if (menu_bar_items_index
> i
+ 4)
5677 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
5678 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
5679 (menu_bar_items_index
- i
- 4) * sizeof (Lisp_Object
));
5680 menu_bar_items_index
-= 4;
5684 /* If there's no definition for this key yet,
5685 just ignore `undefined'. */
5689 GCPRO1 (key
); /* Is this necessary? */
5690 i
= parse_menu_item (item
, 0, 1);
5695 item
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
5697 /* Find any existing item for this KEY. */
5698 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
5699 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
5702 /* If we did not find this KEY, add it at the end. */
5703 if (i
== menu_bar_items_index
)
5705 /* If vector is too small, get a bigger one. */
5706 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
5709 int newsize
= 2 * i
;
5710 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
5711 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
5712 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
5713 menu_bar_items_vector
= tem
;
5716 /* Add this item. */
5717 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = key
;
5718 XVECTOR (menu_bar_items_vector
)->contents
[i
++]
5719 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
5720 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Fcons (item
, Qnil
);
5721 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = make_number (0);
5722 menu_bar_items_index
= i
;
5724 /* We did find an item for this KEY. Add ITEM to its list of maps. */
5728 old
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
5729 XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2] = Fcons (item
, old
);
5733 /* This is used as the handler when calling menu_item_eval_property. */
5735 menu_item_eval_property_1 (arg
)
5738 /* If we got a quit from within the menu computation,
5739 quit all the way out of it. This takes care of C-] in the debugger. */
5740 if (CONSP (arg
) && EQ (XCONS (arg
)->car
, Qquit
))
5741 Fsignal (Qquit
, Qnil
);
5746 /* Evaluate an expression and return the result (or nil if something
5747 went wrong). Used to evaluate dynamic parts of menu items. */
5749 menu_item_eval_property (sexpr
)
5752 int count
= specpdl_ptr
- specpdl
;
5754 specbind (Qinhibit_redisplay
, Qt
);
5755 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
,
5756 menu_item_eval_property_1
);
5757 return unbind_to (count
, val
);
5760 /* This function parses a menu item and leaves the result in the
5761 vector item_properties.
5762 ITEM is a key binding, a possible menu item.
5763 If NOTREAL is nonzero, only check for equivalent key bindings, don't
5764 evaluate dynamic expressions in the menu item.
5765 INMENUBAR is > 0 when this is considered for an entry in a menu bar
5767 INMENUBAR is < 0 when this is considered for an entry in a keyboard menu.
5768 parse_menu_item returns true if the item is a menu item and false
5772 parse_menu_item (item
, notreal
, inmenubar
)
5774 int notreal
, inmenubar
;
5776 Lisp_Object def
, tem
, item_string
, start
;
5777 Lisp_Object cachelist
= Qnil
;
5778 Lisp_Object filter
= Qnil
;
5779 Lisp_Object keyhint
= Qnil
;
5786 /* Create item_properties vector if necessary. */
5787 if (NILP (item_properties
))
5789 = Fmake_vector (make_number (ITEM_PROPERTY_ENABLE
+ 1), Qnil
);
5791 /* Initialize optional entries. */
5792 for (i
= ITEM_PROPERTY_DEF
; i
< ITEM_PROPERTY_ENABLE
; i
++)
5793 XVECTOR (item_properties
)->contents
[i
] = Qnil
;
5794 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
] = Qt
;
5796 /* Save the item here to protect it from GC. */
5797 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ITEM
] = item
;
5799 item_string
= XCONS (item
)->car
;
5802 item
= XCONS (item
)->cdr
;
5803 if (STRINGP (item_string
))
5805 /* Old format menu item. */
5806 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
] = item_string
;
5808 /* Maybe help string. */
5809 if (CONSP (item
) && STRINGP (XCONS (item
)->car
))
5811 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_HELP
]
5812 = XCONS (item
)->car
;
5814 item
= XCONS (item
)->cdr
;
5817 /* Maybee key binding cache. */
5818 if (CONSP (item
) && CONSP (XCONS (item
)->car
)
5819 && (NILP (XCONS (XCONS (item
)->car
)->car
)
5820 || VECTORP (XCONS (XCONS (item
)->car
)->car
)))
5822 cachelist
= XCONS (item
)->car
;
5823 item
= XCONS (item
)->cdr
;
5826 /* This is the real definition--the function to run. */
5827 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
] = item
;
5829 /* Get enable property, if any. */
5832 tem
= Fget (item
, Qmenu_enable
);
5834 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
] = tem
;
5837 else if (EQ (item_string
, Qmenu_item
) && CONSP (item
))
5839 /* New format menu item. */
5840 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
]
5841 = XCONS (item
)->car
;
5842 start
= XCONS (item
)->cdr
;
5845 /* We have a real binding. */
5846 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
]
5847 = XCONS (start
)->car
;
5849 item
= XCONS (start
)->cdr
;
5850 /* Is there a cache list with key equivalences. */
5851 if (CONSP (item
) && CONSP (XCONS (item
)->car
))
5853 cachelist
= XCONS (item
)->car
;
5854 item
= XCONS (item
)->cdr
;
5857 /* Parse properties. */
5858 while (CONSP (item
) && CONSP (XCONS (item
)->cdr
))
5860 tem
= XCONS (item
)->car
;
5861 item
= XCONS (item
)->cdr
;
5863 if (EQ (tem
, QCenable
))
5864 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
]
5865 = XCONS (item
)->car
;
5866 else if (EQ (tem
, QCvisible
) && !notreal
)
5868 /* If got a visible property and that evaluates to nil
5869 then ignore this item. */
5870 tem
= menu_item_eval_property (XCONS (item
)->car
);
5874 else if (EQ (tem
, QChelp
))
5875 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_HELP
]
5876 = XCONS (item
)->car
;
5877 else if (EQ (tem
, QCfilter
))
5879 else if (EQ (tem
, QCkey_sequence
))
5881 tem
= XCONS (item
)->car
;
5882 if (NILP (cachelist
)
5883 && (SYMBOLP (tem
) || STRINGP (tem
) || VECTORP (tem
)))
5884 /* Be GC protected. Set keyhint to item instead of tem. */
5887 else if (EQ (tem
, QCkeys
))
5889 tem
= XCONS (item
)->car
;
5890 if (CONSP (tem
) || STRINGP (tem
) && NILP (cachelist
))
5891 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
]
5894 else if (EQ (tem
, QCbutton
) && CONSP (XCONS (item
)->car
))
5897 tem
= XCONS (item
)->car
;
5898 type
= XCONS (tem
)->car
;
5899 if (EQ (type
, QCtoggle
) || EQ (type
, QCradio
))
5901 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
]
5903 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_TYPE
]
5907 item
= XCONS (item
)->cdr
;
5910 else if (inmenubar
|| !NILP (start
))
5914 return 0; /* not a menu item */
5916 /* If item string is not a string, evaluate it to get string.
5917 If we don't get a string, skip this item. */
5918 item_string
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
5919 if (!(STRINGP (item_string
) || notreal
))
5921 item_string
= menu_item_eval_property (item_string
);
5922 if (!STRINGP (item_string
))
5924 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
] = item_string
;
5927 /* If got a filter apply it on definition. */
5928 def
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
5931 def
= menu_item_eval_property (list2 (XCONS (filter
)->car
,
5932 list2 (Qquote
, def
)));
5934 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
] = def
;
5937 /* If we got no definition, this item is just unselectable text which
5938 is OK in a submenu but not in the menubar. */
5940 return (inmenubar
? 0 : 1);
5942 /* Enable or disable selection of item. */
5943 tem
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
];
5949 tem
= menu_item_eval_property (tem
);
5950 if (inmenubar
&& NILP (tem
))
5951 return 0; /* Ignore disabled items in menu bar. */
5952 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
] = tem
;
5955 /* See if this is a separate pane or a submenu. */
5956 def
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
5957 tem
= get_keymap_1 (def
, 0, 1);
5960 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_MAP
] = tem
;
5961 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
] = tem
;
5964 else if (inmenubar
> 0)
5965 return 0; /* Entries in menu bar must be submenus. */
5967 /* This is a command. See if there is an equivalent key binding. */
5968 if (NILP (cachelist
))
5970 /* We have to create a cachelist. */
5971 CHECK_IMPURE (start
);
5972 XCONS (start
)->cdr
= Fcons (Fcons (Qnil
, Qnil
), XCONS (start
)->cdr
);
5973 cachelist
= XCONS (XCONS (start
)->cdr
)->car
;
5975 tem
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
5976 if (!NILP (keyhint
))
5978 XCONS (cachelist
)->car
= XCONS (keyhint
)->car
;
5981 else if (STRINGP (tem
))
5983 XCONS (cachelist
)->cdr
= Fsubstitute_command_keys (tem
);
5984 XCONS (cachelist
)->car
= Qt
;
5987 tem
= XCONS (cachelist
)->car
;
5994 tem
= Fkey_binding (tem
, Qnil
);
5996 prefix
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
5999 def
= XCONS (prefix
)->car
;
6000 prefix
= XCONS (prefix
)->cdr
;
6003 def
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
6005 if (NILP (XCONS (cachelist
)->car
)) /* Have no saved key. */
6007 if (newcache
/* Always check first time. */
6008 /* Should we check everything when precomputing key
6011 /* If something had no key binding before, don't recheck it
6012 because that is too slow--except if we have a list of
6013 rebound commands in Vdefine_key_rebound_commands, do
6014 recheck any command that appears in that list. */
6015 || (CONSP (Vdefine_key_rebound_commands
)
6016 && !NILP (Fmemq (def
, Vdefine_key_rebound_commands
))))
6019 /* We had a saved key. Is it still bound to the command? */
6022 /* If the command is an alias for another
6023 (such as lmenu.el set it up), check if the
6024 original command matches the cached command. */
6025 && !(SYMBOLP (def
) && EQ (tem
, XSYMBOL (def
)->function
)))
6026 chkcache
= 1; /* Need to recompute key binding. */
6030 /* Recompute equivalent key binding. If the command is an alias
6031 for another (such as lmenu.el set it up), see if the original
6032 command name has equivalent keys. Otherwise look up the
6033 specified command itself. We don't try both, because that
6034 makes lmenu menus slow. */
6035 if (SYMBOLP (def
) && SYMBOLP (XSYMBOL (def
)->function
)
6036 && ! NILP (Fget (def
, Qmenu_alias
)))
6037 def
= XSYMBOL (def
)->function
;
6038 tem
= Fwhere_is_internal (def
, Qnil
, Qt
, Qnil
);
6039 XCONS (cachelist
)->car
= tem
;
6042 XCONS (cachelist
)->cdr
= Qnil
;
6046 else if (!NILP (keyhint
) && !NILP (XCONS (cachelist
)->car
))
6048 tem
= XCONS (cachelist
)->car
;
6052 newcache
= chkcache
;
6055 tem
= Fkey_description (tem
);
6058 if (STRINGP (XCONS (prefix
)->car
))
6059 tem
= concat2 (XCONS (prefix
)->car
, tem
);
6060 if (STRINGP (XCONS (prefix
)->cdr
))
6061 tem
= concat2 (tem
, XCONS (prefix
)->cdr
);
6063 XCONS (cachelist
)->cdr
= tem
;
6067 tem
= XCONS (cachelist
)->cdr
;
6068 if (newcache
&& !NILP (tem
))
6070 tem
= concat3 (build_string (" ("), tem
, build_string (")"));
6071 XCONS (cachelist
)->cdr
= tem
;
6074 /* If we only want to precompute equivalent key bindings, stop here. */
6078 /* If we have an equivalent key binding, use that. */
6079 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
] = tem
;
6081 /* Include this when menu help is implemented.
6082 tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP];
6083 if (!(NILP (tem) || STRINGP (tem)))
6085 tem = menu_item_eval_property (tem);
6088 XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP] = tem;
6092 /* Handle radio buttons or toggle boxes. */
6093 tem
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
];
6095 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
]
6096 = menu_item_eval_property (tem
);
6101 /* Read a character using menus based on maps in the array MAPS.
6102 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
6103 Return t if we displayed a menu but the user rejected it.
6105 PREV_EVENT is the previous input event, or nil if we are reading
6106 the first event of a key sequence.
6108 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
6109 if we used a mouse menu to read the input, or zero otherwise. If
6110 USED_MOUSE_MENU is null, we don't dereference it.
6112 The prompting is done based on the prompt-string of the map
6113 and the strings associated with various map elements.
6115 This can be done with X menus or with menus put in the minibuf.
6116 These are done in different ways, depending on how the input will be read.
6117 Menus using X are done after auto-saving in read-char, getting the input
6118 event from Fx_popup_menu; menus using the minibuf use read_char recursively
6119 and do auto-saving in the inner call of read_char. */
6122 read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
6125 Lisp_Object prev_event
;
6126 int *used_mouse_menu
;
6129 register Lisp_Object name
;
6130 Lisp_Object rest
, vector
;
6132 if (used_mouse_menu
)
6133 *used_mouse_menu
= 0;
6135 /* Use local over global Menu maps */
6137 if (! menu_prompting
)
6140 /* Optionally disregard all but the global map. */
6141 if (inhibit_local_menu_bar_menus
)
6143 maps
+= (nmaps
- 1);
6147 /* Get the menu name from the first map that has one (a prompt string). */
6148 for (mapno
= 0; mapno
< nmaps
; mapno
++)
6150 name
= map_prompt (maps
[mapno
]);
6155 /* If we don't have any menus, just read a character normally. */
6160 /* If we got to this point via a mouse click,
6161 use a real menu for mouse selection. */
6162 if (EVENT_HAS_PARAMETERS (prev_event
)
6163 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
))
6165 /* Display the menu and get the selection. */
6166 Lisp_Object
*realmaps
6167 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
6171 /* Use the maps that are not nil. */
6172 for (mapno
= 0; mapno
< nmaps
; mapno
++)
6173 if (!NILP (maps
[mapno
]))
6174 realmaps
[nmaps1
++] = maps
[mapno
];
6176 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
6181 record_menu_key (XCONS (value
)->car
);
6183 /* If we got multiple events, unread all but
6185 There is no way to prevent those unread events
6186 from showing up later in last_nonmenu_event.
6187 So turn symbol and integer events into lists,
6188 to indicate that they came from a mouse menu,
6189 so that when present in last_nonmenu_event
6190 they won't confuse things. */
6191 for (tem
= XCONS (value
)->cdr
; !NILP (tem
);
6192 tem
= XCONS (tem
)->cdr
)
6194 record_menu_key (XCONS (tem
)->car
);
6195 if (SYMBOLP (XCONS (tem
)->car
)
6196 || INTEGERP (XCONS (tem
)->car
))
6198 = Fcons (XCONS (tem
)->car
, Qnil
);
6201 /* If we got more than one event, put all but the first
6202 onto this list to be read later.
6203 Return just the first event now. */
6204 Vunread_command_events
6205 = nconc2 (XCONS (value
)->cdr
, Vunread_command_events
);
6206 value
= XCONS (value
)->car
;
6208 else if (NILP (value
))
6210 if (used_mouse_menu
)
6211 *used_mouse_menu
= 1;
6214 #endif /* HAVE_MENUS */
6218 /* Buffer in use so far for the minibuf prompts for menu keymaps.
6219 We make this bigger when necessary, and never free it. */
6220 static char *read_char_minibuf_menu_text
;
6221 /* Size of that buffer. */
6222 static int read_char_minibuf_menu_width
;
6225 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
6231 register Lisp_Object name
;
6233 int width
= FRAME_WIDTH (selected_frame
) - 4;
6236 Lisp_Object rest
, vector
;
6239 if (! menu_prompting
)
6242 /* Make sure we have a big enough buffer for the menu text. */
6243 if (read_char_minibuf_menu_text
== 0)
6245 read_char_minibuf_menu_width
= width
+ 4;
6246 read_char_minibuf_menu_text
= (char *) xmalloc (width
+ 4);
6248 else if (width
+ 4 > read_char_minibuf_menu_width
)
6250 read_char_minibuf_menu_width
= width
+ 4;
6251 read_char_minibuf_menu_text
6252 = (char *) xrealloc (read_char_minibuf_menu_text
, width
+ 4);
6254 menu
= read_char_minibuf_menu_text
;
6256 /* Get the menu name from the first map that has one (a prompt string). */
6257 for (mapno
= 0; mapno
< nmaps
; mapno
++)
6259 name
= map_prompt (maps
[mapno
]);
6264 /* If we don't have any menus, just read a character normally. */
6268 /* Prompt string always starts with map's prompt, and a space. */
6269 strcpy (menu
, XSTRING (name
)->data
);
6270 nlength
= STRING_BYTES (XSTRING (name
));
6271 menu
[nlength
++] = ':';
6272 menu
[nlength
++] = ' ';
6275 /* Start prompting at start of first map. */
6279 /* Present the documented bindings, a line at a time. */
6286 Lisp_Object orig_defn_macro
;
6288 /* Loop over elements of map. */
6293 /* If reached end of map, start at beginning of next map. */
6297 /* At end of last map, wrap around to first map if just starting,
6298 or end this line if already have something on it. */
6302 if (notfirst
|| nobindings
) break;
6307 /* Look at the next element of the map. */
6309 elt
= XVECTOR (vector
)->contents
[idx
];
6311 elt
= Fcar_safe (rest
);
6313 if (idx
< 0 && VECTORP (elt
))
6315 /* If we found a dense table in the keymap,
6316 advanced past it, but start scanning its contents. */
6317 rest
= Fcdr_safe (rest
);
6323 /* An ordinary element. */
6324 Lisp_Object event
, tem
;
6328 event
= Fcar_safe (elt
); /* alist */
6329 elt
= Fcdr_safe (elt
);
6333 XSETINT (event
, idx
); /* vector */
6336 /* Ignore the element if it has no prompt string. */
6337 if (INTEGERP (event
) && parse_menu_item (elt
, 0, -1))
6339 /* 1 if the char to type matches the string. */
6341 Lisp_Object upcased_event
, downcased_event
;
6344 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
6346 upcased_event
= Fupcase (event
);
6347 downcased_event
= Fdowncase (event
);
6348 char_matches
= (XINT (upcased_event
) == XSTRING (s
)->data
[0]
6349 || XINT (downcased_event
) == XSTRING (s
)->data
[0]);
6351 desc
= Fsingle_key_description (event
);
6354 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
6356 /* Insert equivalent keybinding. */
6357 s
= concat2 (s
, tem
);
6360 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_TYPE
];
6361 if (EQ (tem
, QCradio
) || EQ (tem
, QCtoggle
))
6363 /* Insert button prefix. */
6364 Lisp_Object selected
6365 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
];
6366 if (EQ (tem
, QCradio
))
6367 tem
= build_string (NILP (selected
) ? "(*) " : "( ) ");
6369 tem
= build_string (NILP (selected
) ? "[X] " : "[ ] ");
6370 s
= concat2 (tem
, s
);
6374 /* If we have room for the prompt string, add it to this line.
6375 If this is the first on the line, always add it. */
6376 if ((XSTRING (s
)->size
+ i
+ 2
6377 + (char_matches
? 0 : XSTRING (desc
)->size
+ 3))
6383 /* Punctuate between strings. */
6386 strcpy (menu
+ i
, ", ");
6392 /* If the char to type doesn't match the string's
6393 first char, explicitly show what char to type. */
6396 /* Add as much of string as fits. */
6397 thiswidth
= XSTRING (desc
)->size
;
6398 if (thiswidth
+ i
> width
)
6399 thiswidth
= width
- i
;
6400 bcopy (XSTRING (desc
)->data
, menu
+ i
, thiswidth
);
6402 strcpy (menu
+ i
, " = ");
6406 /* Add as much of string as fits. */
6407 thiswidth
= XSTRING (s
)->size
;
6408 if (thiswidth
+ i
> width
)
6409 thiswidth
= width
- i
;
6410 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
6416 /* If this element does not fit, end the line now,
6417 and save the element for the next line. */
6418 strcpy (menu
+ i
, "...");
6423 /* Move past this element. */
6424 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
6425 /* Handle reaching end of dense table. */
6430 rest
= Fcdr_safe (rest
);
6434 /* Prompt with that and read response. */
6435 message2_nolog (menu
, strlen (menu
),
6436 ! NILP (current_buffer
->enable_multibyte_characters
));
6438 /* Make believe its not a keyboard macro in case the help char
6439 is pressed. Help characters are not recorded because menu prompting
6440 is not used on replay.
6442 orig_defn_macro
= current_kboard
->defining_kbd_macro
;
6443 current_kboard
->defining_kbd_macro
= Qnil
;
6445 obj
= read_char (commandflag
, 0, 0, Qnil
, 0);
6446 while (BUFFERP (obj
));
6447 current_kboard
->defining_kbd_macro
= orig_defn_macro
;
6449 if (!INTEGERP (obj
))
6454 if (! EQ (obj
, menu_prompt_more_char
)
6455 && (!INTEGERP (menu_prompt_more_char
)
6456 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
6458 if (!NILP (current_kboard
->defining_kbd_macro
))
6459 store_kbd_macro_char (obj
);
6462 /* Help char - go round again */
6466 /* Reading key sequences. */
6468 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
6469 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
6470 keymap, or nil otherwise. Return the index of the first keymap in
6471 which KEY has any binding, or NMAPS if no map has a binding.
6473 If KEY is a meta ASCII character, treat it like meta-prefix-char
6474 followed by the corresponding non-meta character. Keymaps in
6475 CURRENT with non-prefix bindings for meta-prefix-char become nil in
6478 If KEY has no bindings in any of the CURRENT maps, NEXT is left
6481 NEXT may be the same array as CURRENT. */
6484 follow_key (key
, nmaps
, current
, defs
, next
)
6486 Lisp_Object
*current
, *defs
, *next
;
6489 int i
, first_binding
;
6492 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
6493 followed by the corresponding non-meta character.
6494 Put the results into DEFS, since we are going to alter that anyway.
6495 Do not alter CURRENT or NEXT. */
6496 if (INTEGERP (key
) && (XINT (key
) & CHAR_META
))
6498 for (i
= 0; i
< nmaps
; i
++)
6499 if (! NILP (current
[i
]))
6502 def
= get_keyelt (access_keymap (current
[i
],
6503 meta_prefix_char
, 1, 0), 0);
6505 /* Note that since we pass the resulting bindings through
6506 get_keymap_1, non-prefix bindings for meta-prefix-char
6508 defs
[i
] = get_keymap_1 (def
, 0, 1);
6514 XSETINT (key
, XFASTINT (key
) & ~CHAR_META
);
6517 first_binding
= nmaps
;
6518 for (i
= nmaps
- 1; i
>= 0; i
--)
6520 if (! NILP (current
[i
]))
6528 defs
[i
] = get_keyelt (access_keymap (map
, key
, 1, 0), 0);
6529 if (! NILP (defs
[i
]))
6536 /* Given the set of bindings we've found, produce the next set of maps. */
6537 if (first_binding
< nmaps
)
6538 for (i
= 0; i
< nmaps
; i
++)
6539 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0, 1);
6541 return first_binding
;
6544 /* Read a sequence of keys that ends with a non prefix character,
6545 storing it in KEYBUF, a buffer of size BUFSIZE.
6547 Return the length of the key sequence stored.
6548 Return -1 if the user rejected a command menu.
6550 Echo starting immediately unless `prompt' is 0.
6552 Where a key sequence ends depends on the currently active keymaps.
6553 These include any minor mode keymaps active in the current buffer,
6554 the current buffer's local map, and the global map.
6556 If a key sequence has no other bindings, we check Vfunction_key_map
6557 to see if some trailing subsequence might be the beginning of a
6558 function key's sequence. If so, we try to read the whole function
6559 key, and substitute its symbolic name into the key sequence.
6561 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
6562 `double-' events into similar click events, if that would make them
6563 bound. We try to turn `triple-' events first into `double-' events,
6566 If we get a mouse click in a mode line, vertical divider, or other
6567 non-text area, we treat the click as if it were prefixed by the
6568 symbol denoting that area - `mode-line', `vertical-line', or
6571 If the sequence starts with a mouse click, we read the key sequence
6572 with respect to the buffer clicked on, not the current buffer.
6574 If the user switches frames in the midst of a key sequence, we put
6575 off the switch-frame event until later; the next call to
6576 read_char will return it.
6578 If FIX_CURRENT_BUFFER is nonzero, we restore current_buffer
6579 from the selected window's buffer. */
6582 read_key_sequence (keybuf
, bufsize
, prompt
, dont_downcase_last
,
6583 can_return_switch_frame
, fix_current_buffer
)
6584 Lisp_Object
*keybuf
;
6587 int dont_downcase_last
;
6588 int can_return_switch_frame
;
6589 int fix_current_buffer
;
6591 int count
= specpdl_ptr
- specpdl
;
6593 /* How many keys there are in the current key sequence. */
6596 /* The length of the echo buffer when we started reading, and
6597 the length of this_command_keys when we started reading. */
6601 /* The number of keymaps we're scanning right now, and the number of
6602 keymaps we have allocated space for. */
6604 int nmaps_allocated
= 0;
6606 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
6607 the current keymaps. */
6610 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
6611 in the current keymaps, or nil where it is not a prefix. */
6612 Lisp_Object
*submaps
;
6614 /* The local map to start out with at start of key sequence. */
6615 Lisp_Object orig_local_map
;
6617 /* 1 if we have already considered switching to the local-map property
6618 of the place where a mouse click occurred. */
6619 int localized_local_map
= 0;
6621 /* The index in defs[] of the first keymap that has a binding for
6622 this key sequence. In other words, the lowest i such that
6623 defs[i] is non-nil. */
6626 /* If t < mock_input, then KEYBUF[t] should be read as the next
6629 We use this to recover after recognizing a function key. Once we
6630 realize that a suffix of the current key sequence is actually a
6631 function key's escape sequence, we replace the suffix with the
6632 function key's binding from Vfunction_key_map. Now keybuf
6633 contains a new and different key sequence, so the echo area,
6634 this_command_keys, and the submaps and defs arrays are wrong. In
6635 this situation, we set mock_input to t, set t to 0, and jump to
6636 restart_sequence; the loop will read keys from keybuf up until
6637 mock_input, thus rebuilding the state; and then it will resume
6638 reading characters from the keyboard. */
6641 /* If the sequence is unbound in submaps[], then
6642 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
6643 and fkey_map is its binding.
6645 These might be > t, indicating that all function key scanning
6646 should hold off until t reaches them. We do this when we've just
6647 recognized a function key, to avoid searching for the function
6648 key's again in Vfunction_key_map. */
6649 int fkey_start
= 0, fkey_end
= 0;
6650 Lisp_Object fkey_map
;
6652 /* Likewise, for key_translation_map. */
6653 int keytran_start
= 0, keytran_end
= 0;
6654 Lisp_Object keytran_map
;
6656 /* If we receive a ``switch-frame'' event in the middle of a key sequence,
6657 we put it off for later. While we're reading, we keep the event here. */
6658 Lisp_Object delayed_switch_frame
;
6660 /* See the comment below... */
6661 #if defined (GOBBLE_FIRST_EVENT)
6662 Lisp_Object first_event
;
6665 Lisp_Object original_uppercase
;
6666 int original_uppercase_position
= -1;
6668 /* Gets around Microsoft compiler limitations. */
6671 struct buffer
*starting_buffer
;
6673 /* Nonzero if we seem to have got the beginning of a binding
6674 in function_key_map. */
6675 int function_key_possible
= 0;
6676 int key_translation_possible
= 0;
6678 /* Save the status of key translation before each step,
6679 so that we can restore this after downcasing. */
6680 Lisp_Object prev_fkey_map
;
6681 int prev_fkey_start
;
6684 Lisp_Object prev_keytran_map
;
6685 int prev_keytran_start
;
6686 int prev_keytran_end
;
6690 raw_keybuf_count
= 0;
6692 last_nonmenu_event
= Qnil
;
6694 delayed_switch_frame
= Qnil
;
6695 fkey_map
= Vfunction_key_map
;
6696 keytran_map
= Vkey_translation_map
;
6698 /* If there is no function-key-map, turn off function key scanning. */
6699 if (NILP (Fkeymapp (Vfunction_key_map
)))
6700 fkey_start
= fkey_end
= bufsize
+ 1;
6702 /* If there is no key-translation-map, turn off scanning. */
6703 if (NILP (Fkeymapp (Vkey_translation_map
)))
6704 keytran_start
= keytran_end
= bufsize
+ 1;
6709 echo_prompt (XSTRING (prompt
)->data
);
6710 else if (cursor_in_echo_area
&& echo_keystrokes
)
6711 /* This doesn't put in a dash if the echo buffer is empty, so
6712 you don't always see a dash hanging out in the minibuffer. */
6716 /* Record the initial state of the echo area and this_command_keys;
6717 we will need to restore them if we replay a key sequence. */
6719 echo_start
= echo_length ();
6720 keys_start
= this_command_key_count
;
6721 this_single_command_key_start
= keys_start
;
6723 #if defined (GOBBLE_FIRST_EVENT)
6724 /* This doesn't quite work, because some of the things that read_char
6725 does cannot safely be bypassed. It seems too risky to try to make
6728 /* Read the first char of the sequence specially, before setting
6729 up any keymaps, in case a filter runs and switches buffers on us. */
6730 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
6732 #endif /* GOBBLE_FIRST_EVENT */
6734 orig_local_map
= get_local_map (PT
, current_buffer
);
6736 /* Bind input-method-function so that we can set it to nil
6737 temporarily after the first input event. */
6738 specbind (Qinput_method_function
, Vinput_method_function
);
6740 /* We jump here when the key sequence has been thoroughly changed, and
6741 we need to rescan it starting from the beginning. When we jump here,
6742 keybuf[0..mock_input] holds the sequence we should reread. */
6745 starting_buffer
= current_buffer
;
6746 function_key_possible
= 0;
6747 key_translation_possible
= 0;
6749 /* Build our list of keymaps.
6750 If we recognize a function key and replace its escape sequence in
6751 keybuf with its symbol, or if the sequence starts with a mouse
6752 click and we need to switch buffers, we jump back here to rebuild
6753 the initial keymaps from the current buffer. */
6757 if (!NILP (current_kboard
->Voverriding_terminal_local_map
)
6758 || !NILP (Voverriding_local_map
))
6760 if (3 > nmaps_allocated
)
6762 submaps
= (Lisp_Object
*) alloca (3 * sizeof (submaps
[0]));
6763 defs
= (Lisp_Object
*) alloca (3 * sizeof (defs
[0]));
6764 nmaps_allocated
= 3;
6767 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
6768 submaps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
6769 if (!NILP (Voverriding_local_map
))
6770 submaps
[nmaps
++] = Voverriding_local_map
;
6774 nmaps
= current_minor_maps (0, &maps
);
6775 if (nmaps
+ 2 > nmaps_allocated
)
6777 submaps
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (submaps
[0]));
6778 defs
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (defs
[0]));
6779 nmaps_allocated
= nmaps
+ 2;
6781 bcopy (maps
, submaps
, nmaps
* sizeof (submaps
[0]));
6782 #ifdef USE_TEXT_PROPERTIES
6783 submaps
[nmaps
++] = orig_local_map
;
6785 submaps
[nmaps
++] = current_buffer
->keymap
;
6788 submaps
[nmaps
++] = current_global_map
;
6791 /* Find an accurate initial value for first_binding. */
6792 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
6793 if (! NILP (submaps
[first_binding
]))
6796 /* Start from the beginning in keybuf. */
6799 /* These are no-ops the first time through, but if we restart, they
6800 revert the echo area and this_command_keys to their original state. */
6801 this_command_key_count
= keys_start
;
6802 if (INTERACTIVE
&& t
< mock_input
)
6803 echo_truncate (echo_start
);
6805 /* If the best binding for the current key sequence is a keymap, or
6806 we may be looking at a function key's escape sequence, keep on
6808 while ((first_binding
< nmaps
&& ! NILP (submaps
[first_binding
]))
6809 || (first_binding
>= nmaps
6811 /* mock input is never part of a function key's sequence. */
6812 && mock_input
<= fkey_start
)
6813 || (first_binding
>= nmaps
6814 && keytran_start
< t
&& key_translation_possible
)
6815 /* Don't return in the middle of a possible function key sequence,
6816 if the only bindings we found were via case conversion.
6817 Thus, if ESC O a has a function-key-map translation
6818 and ESC o has a binding, don't return after ESC O,
6819 so that we can translate ESC O plus the next character. */
6823 int used_mouse_menu
= 0;
6825 /* Where the last real key started. If we need to throw away a
6826 key that has expanded into more than one element of keybuf
6827 (say, a mouse click on the mode line which is being treated
6828 as [mode-line (mouse-...)], then we backtrack to this point
6830 int last_real_key_start
;
6832 /* These variables are analogous to echo_start and keys_start;
6833 while those allow us to restart the entire key sequence,
6834 echo_local_start and keys_local_start allow us to throw away
6836 int echo_local_start
, keys_local_start
, local_first_binding
;
6839 error ("Key sequence too long");
6842 echo_local_start
= echo_length ();
6843 keys_local_start
= this_command_key_count
;
6844 local_first_binding
= first_binding
;
6847 /* These are no-ops, unless we throw away a keystroke below and
6848 jumped back up to replay_key; in that case, these restore the
6849 variables to their original state, allowing us to replay the
6851 if (INTERACTIVE
&& t
< mock_input
)
6852 echo_truncate (echo_local_start
);
6853 this_command_key_count
= keys_local_start
;
6854 first_binding
= local_first_binding
;
6856 /* By default, assume each event is "real". */
6857 last_real_key_start
= t
;
6859 /* Does mock_input indicate that we are re-reading a key sequence? */
6863 add_command_key (key
);
6864 if (echo_keystrokes
)
6868 /* If not, we should actually read a character. */
6871 struct buffer
*buf
= current_buffer
;
6875 KBOARD
*interrupted_kboard
= current_kboard
;
6876 struct frame
*interrupted_frame
= selected_frame
;
6877 if (setjmp (wrong_kboard_jmpbuf
))
6879 if (!NILP (delayed_switch_frame
))
6881 interrupted_kboard
->kbd_queue
6882 = Fcons (delayed_switch_frame
,
6883 interrupted_kboard
->kbd_queue
);
6884 delayed_switch_frame
= Qnil
;
6887 interrupted_kboard
->kbd_queue
6888 = Fcons (keybuf
[--t
], interrupted_kboard
->kbd_queue
);
6890 /* If the side queue is non-empty, ensure it begins with a
6891 switch-frame, so we'll replay it in the right context. */
6892 if (CONSP (interrupted_kboard
->kbd_queue
)
6893 && (key
= XCONS (interrupted_kboard
->kbd_queue
)->car
,
6894 !(EVENT_HAS_PARAMETERS (key
)
6895 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)),
6899 XSETFRAME (frame
, interrupted_frame
);
6900 interrupted_kboard
->kbd_queue
6901 = Fcons (make_lispy_switch_frame (frame
),
6902 interrupted_kboard
->kbd_queue
);
6905 orig_local_map
= get_local_map (PT
, current_buffer
);
6906 goto replay_sequence
;
6909 key
= read_char (NILP (prompt
), nmaps
, submaps
, last_nonmenu_event
,
6912 /* Turn off input methods after a prefix character. */
6913 Vinput_method_function
= Qnil
;
6916 /* read_char returns t when it shows a menu and the user rejects it.
6920 unbind_to (count
, Qnil
);
6924 /* read_char returns -1 at the end of a macro.
6925 Emacs 18 handles this by returning immediately with a
6926 zero, so that's what we'll do. */
6927 if (INTEGERP (key
) && XINT (key
) == -1)
6930 /* The Microsoft C compiler can't handle the goto that
6936 /* If the current buffer has been changed from under us, the
6937 keymap may have changed, so replay the sequence. */
6941 /* Reset the current buffer from the selected window
6942 in case something changed the former and not the latter.
6943 This is to be more consistent with the behavior
6944 of the command_loop_1. */
6945 if (fix_current_buffer
)
6946 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
6947 Fset_buffer (XWINDOW (selected_window
)->buffer
);
6949 orig_local_map
= get_local_map (PT
, current_buffer
);
6950 goto replay_sequence
;
6953 /* If we have a quit that was typed in another frame, and
6954 quit_throw_to_read_char switched buffers,
6955 replay to get the right keymap. */
6956 if (XINT (key
) == quit_char
&& current_buffer
!= starting_buffer
)
6959 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
6963 orig_local_map
= get_local_map (PT
, current_buffer
);
6964 goto replay_sequence
;
6969 if (EVENT_HAS_PARAMETERS (key
)
6970 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)), Qswitch_frame
))
6972 /* If we're at the beginning of a key sequence, and the caller
6973 says it's okay, go ahead and return this event. If we're
6974 in the midst of a key sequence, delay it until the end. */
6975 if (t
> 0 || !can_return_switch_frame
)
6977 delayed_switch_frame
= key
;
6983 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
6986 /* Clicks in non-text areas get prefixed by the symbol
6987 in their CHAR-ADDRESS field. For example, a click on
6988 the mode line is prefixed by the symbol `mode-line'.
6990 Furthermore, key sequences beginning with mouse clicks
6991 are read using the keymaps of the buffer clicked on, not
6992 the current buffer. So we may have to switch the buffer
6995 When we turn one event into two events, we must make sure
6996 that neither of the two looks like the original--so that,
6997 if we replay the events, they won't be expanded again.
6998 If not for this, such reexpansion could happen either here
6999 or when user programs play with this-command-keys. */
7000 if (EVENT_HAS_PARAMETERS (key
))
7004 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
7005 if (EQ (kind
, Qmouse_click
))
7007 Lisp_Object window
, posn
;
7009 window
= POSN_WINDOW (EVENT_START (key
));
7010 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
7013 /* We're looking at the second event of a
7014 sequence which we expanded before. Set
7015 last_real_key_start appropriately. */
7017 last_real_key_start
= t
- 1;
7020 /* Key sequences beginning with mouse clicks are
7021 read using the keymaps in the buffer clicked on,
7022 not the current buffer. If we're at the
7023 beginning of a key sequence, switch buffers. */
7024 if (last_real_key_start
== 0
7026 && BUFFERP (XWINDOW (window
)->buffer
)
7027 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
7029 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
7033 /* Arrange to go back to the original buffer once we're
7034 done reading the key sequence. Note that we can't
7035 use save_excursion_{save,restore} here, because they
7036 save point as well as the current buffer; we don't
7037 want to save point, because redisplay may change it,
7038 to accommodate a Fset_window_start or something. We
7039 don't want to do this at the top of the function,
7040 because we may get input from a subprocess which
7041 wants to change the selected window and stuff (say,
7043 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
7045 set_buffer_internal (XBUFFER (XWINDOW (window
)->buffer
));
7046 orig_local_map
= get_local_map (PT
, current_buffer
);
7047 goto replay_sequence
;
7049 /* For a mouse click, get the local text-property keymap
7050 of the place clicked on, rather than point. */
7051 if (last_real_key_start
== 0 && CONSP (XCONS (key
)->cdr
)
7052 && ! localized_local_map
)
7054 Lisp_Object map_here
, start
, pos
;
7056 localized_local_map
= 1;
7057 start
= EVENT_START (key
);
7058 if (CONSP (start
) && CONSP (XCONS (start
)->cdr
))
7060 pos
= POSN_BUFFER_POSN (start
);
7062 && XINT (pos
) >= BEG
&& XINT (pos
) <= Z
)
7064 map_here
= get_local_map (XINT (pos
), current_buffer
);
7065 if (!EQ (map_here
, orig_local_map
))
7067 orig_local_map
= map_here
;
7071 goto replay_sequence
;
7077 /* Expand mode-line and scroll-bar events into two events:
7078 use posn as a fake prefix key. */
7081 if (t
+ 1 >= bufsize
)
7082 error ("Key sequence too long");
7087 /* Zap the position in key, so we know that we've
7088 expanded it, and don't try to do so again. */
7089 POSN_BUFFER_POSN (EVENT_START (key
))
7090 = Fcons (posn
, Qnil
);
7094 else if (CONSP (XCONS (key
)->cdr
)
7095 && CONSP (EVENT_START (key
))
7096 && CONSP (XCONS (EVENT_START (key
))->cdr
))
7100 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
7101 /* Handle menu-bar events:
7102 insert the dummy prefix event `menu-bar'. */
7103 if (EQ (posn
, Qmenu_bar
))
7105 if (t
+ 1 >= bufsize
)
7106 error ("Key sequence too long");
7110 /* Zap the position in key, so we know that we've
7111 expanded it, and don't try to do so again. */
7112 POSN_BUFFER_POSN (EVENT_START (key
))
7113 = Fcons (posn
, Qnil
);
7116 goto replay_sequence
;
7118 else if (CONSP (posn
))
7120 /* We're looking at the second event of a
7121 sequence which we expanded before. Set
7122 last_real_key_start appropriately. */
7123 if (last_real_key_start
== t
&& t
> 0)
7124 last_real_key_start
= t
- 1;
7129 /* We have finally decided that KEY is something we might want
7131 first_binding
= (follow_key (key
,
7132 nmaps
- first_binding
,
7133 submaps
+ first_binding
,
7134 defs
+ first_binding
,
7135 submaps
+ first_binding
)
7138 /* If KEY wasn't bound, we'll try some fallbacks. */
7139 if (first_binding
>= nmaps
)
7143 head
= EVENT_HEAD (key
);
7144 if (help_char_p (head
) && t
> 0)
7146 read_key_sequence_cmd
= Vprefix_help_command
;
7148 last_nonmenu_event
= key
;
7149 /* The Microsoft C compiler can't handle the goto that
7157 Lisp_Object breakdown
;
7160 breakdown
= parse_modifiers (head
);
7161 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
7162 /* Attempt to reduce an unbound mouse event to a simpler
7163 event that is bound:
7164 Drags reduce to clicks.
7165 Double-clicks reduce to clicks.
7166 Triple-clicks reduce to double-clicks, then to clicks.
7167 Down-clicks are eliminated.
7168 Double-downs reduce to downs, then are eliminated.
7169 Triple-downs reduce to double-downs, then to downs,
7170 then are eliminated. */
7171 if (modifiers
& (down_modifier
| drag_modifier
7172 | double_modifier
| triple_modifier
))
7174 while (modifiers
& (down_modifier
| drag_modifier
7175 | double_modifier
| triple_modifier
))
7177 Lisp_Object new_head
, new_click
;
7178 if (modifiers
& triple_modifier
)
7179 modifiers
^= (double_modifier
| triple_modifier
);
7180 else if (modifiers
& double_modifier
)
7181 modifiers
&= ~double_modifier
;
7182 else if (modifiers
& drag_modifier
)
7183 modifiers
&= ~drag_modifier
;
7186 /* Dispose of this `down' event by simply jumping
7187 back to replay_key, to get another event.
7189 Note that if this event came from mock input,
7190 then just jumping back to replay_key will just
7191 hand it to us again. So we have to wipe out any
7194 We could delete keybuf[t] and shift everything
7195 after that to the left by one spot, but we'd also
7196 have to fix up any variable that points into
7197 keybuf, and shifting isn't really necessary
7200 Adding prefixes for non-textual mouse clicks
7201 creates two characters of mock input, and both
7202 must be thrown away. If we're only looking at
7203 the prefix now, we can just jump back to
7204 replay_key. On the other hand, if we've already
7205 processed the prefix, and now the actual click
7206 itself is giving us trouble, then we've lost the
7207 state of the keymaps we want to backtrack to, and
7208 we need to replay the whole sequence to rebuild
7211 Beyond that, only function key expansion could
7212 create more than two keys, but that should never
7213 generate mouse events, so it's okay to zero
7214 mock_input in that case too.
7216 Isn't this just the most wonderful code ever? */
7217 if (t
== last_real_key_start
)
7224 mock_input
= last_real_key_start
;
7225 goto replay_sequence
;
7230 = apply_modifiers (modifiers
, XCONS (breakdown
)->car
);
7232 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
7234 /* Look for a binding for this new key. follow_key
7235 promises that it didn't munge submaps the
7236 last time we called it, since key was unbound. */
7238 = (follow_key (new_click
,
7239 nmaps
- local_first_binding
,
7240 submaps
+ local_first_binding
,
7241 defs
+ local_first_binding
,
7242 submaps
+ local_first_binding
)
7243 + local_first_binding
);
7245 /* If that click is bound, go for it. */
7246 if (first_binding
< nmaps
)
7251 /* Otherwise, we'll leave key set to the drag event. */
7258 /* Normally, last_nonmenu_event gets the previous key we read.
7259 But when a mouse popup menu is being used,
7260 we don't update last_nonmenu_event; it continues to hold the mouse
7261 event that preceded the first level of menu. */
7262 if (!used_mouse_menu
)
7263 last_nonmenu_event
= key
;
7265 /* Record what part of this_command_keys is the current key sequence. */
7266 this_single_command_key_start
= this_command_key_count
- t
;
7268 prev_fkey_map
= fkey_map
;
7269 prev_fkey_start
= fkey_start
;
7270 prev_fkey_end
= fkey_end
;
7272 prev_keytran_map
= keytran_map
;
7273 prev_keytran_start
= keytran_start
;
7274 prev_keytran_end
= keytran_end
;
7276 /* If the sequence is unbound, see if we can hang a function key
7277 off the end of it. We only want to scan real keyboard input
7278 for function key sequences, so if mock_input says that we're
7279 re-reading old events, don't examine it. */
7280 if (first_binding
>= nmaps
7283 Lisp_Object fkey_next
;
7285 /* Continue scan from fkey_end until we find a bound suffix.
7286 If we fail, increment fkey_start
7287 and start fkey_end from there. */
7288 while (fkey_end
< t
)
7292 key
= keybuf
[fkey_end
++];
7293 /* Look up meta-characters by prefixing them
7294 with meta_prefix_char. I hate this. */
7295 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
7300 (access_keymap (fkey_map
, meta_prefix_char
, 1, 0), 0),
7302 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
7305 fkey_next
= fkey_map
;
7308 = get_keyelt (access_keymap (fkey_next
, key
, 1, 0), 0);
7310 #if 0 /* I didn't turn this on, because it might cause trouble
7311 for the mapping of return into C-m and tab into C-i. */
7312 /* Optionally don't map function keys into other things.
7313 This enables the user to redefine kp- keys easily. */
7314 if (SYMBOLP (key
) && !NILP (Vinhibit_function_key_mapping
))
7318 /* If the function key map gives a function, not an
7319 array, then call the function with no args and use
7320 its value instead. */
7321 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
7324 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7328 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
7329 fkey_next
= call1 (fkey_next
, prompt
);
7331 /* If the function returned something invalid,
7332 barf--don't ignore it.
7333 (To ignore it safely, we would need to gcpro a bunch of
7334 other variables.) */
7335 if (! (VECTORP (fkey_next
) || STRINGP (fkey_next
)))
7336 error ("Function in key-translation-map returns invalid key sequence");
7339 function_key_possible
= ! NILP (fkey_next
);
7341 /* If keybuf[fkey_start..fkey_end] is bound in the
7342 function key map and it's a suffix of the current
7343 sequence (i.e. fkey_end == t), replace it with
7344 the binding and restart with fkey_start at the end. */
7345 if ((VECTORP (fkey_next
) || STRINGP (fkey_next
))
7348 int len
= XFASTINT (Flength (fkey_next
));
7350 t
= fkey_start
+ len
;
7352 error ("Key sequence too long");
7354 if (VECTORP (fkey_next
))
7355 bcopy (XVECTOR (fkey_next
)->contents
,
7356 keybuf
+ fkey_start
,
7357 (t
- fkey_start
) * sizeof (keybuf
[0]));
7358 else if (STRINGP (fkey_next
))
7362 for (i
= 0; i
< len
; i
++)
7363 XSETFASTINT (keybuf
[fkey_start
+ i
],
7364 XSTRING (fkey_next
)->data
[i
]);
7368 fkey_start
= fkey_end
= t
;
7369 fkey_map
= Vfunction_key_map
;
7371 /* Do pass the results through key-translation-map. */
7372 keytran_start
= keytran_end
= 0;
7373 keytran_map
= Vkey_translation_map
;
7375 goto replay_sequence
;
7378 fkey_map
= get_keymap_1 (fkey_next
, 0, 1);
7380 /* If we no longer have a bound suffix, try a new positions for
7382 if (NILP (fkey_map
))
7384 fkey_end
= ++fkey_start
;
7385 fkey_map
= Vfunction_key_map
;
7386 function_key_possible
= 0;
7391 /* Look for this sequence in key-translation-map. */
7393 Lisp_Object keytran_next
;
7395 /* Scan from keytran_end until we find a bound suffix. */
7396 while (keytran_end
< t
)
7400 key
= keybuf
[keytran_end
++];
7401 /* Look up meta-characters by prefixing them
7402 with meta_prefix_char. I hate this. */
7403 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
7408 (access_keymap (keytran_map
, meta_prefix_char
, 1, 0), 0),
7410 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
7413 keytran_next
= keytran_map
;
7416 = get_keyelt (access_keymap (keytran_next
, key
, 1, 0), 0);
7418 /* If the key translation map gives a function, not an
7419 array, then call the function with no args and use
7420 its value instead. */
7421 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
7422 && keytran_end
== t
)
7424 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7428 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
7429 keytran_next
= call1 (keytran_next
, prompt
);
7431 /* If the function returned something invalid,
7432 barf--don't ignore it.
7433 (To ignore it safely, we would need to gcpro a bunch of
7434 other variables.) */
7435 if (! (VECTORP (keytran_next
) || STRINGP (keytran_next
)))
7436 error ("Function in key-translation-map returns invalid key sequence");
7439 key_translation_possible
= ! NILP (keytran_next
);
7441 /* If keybuf[keytran_start..keytran_end] is bound in the
7442 key translation map and it's a suffix of the current
7443 sequence (i.e. keytran_end == t), replace it with
7444 the binding and restart with keytran_start at the end. */
7445 if ((VECTORP (keytran_next
) || STRINGP (keytran_next
))
7446 && keytran_end
== t
)
7448 int len
= XFASTINT (Flength (keytran_next
));
7450 t
= keytran_start
+ len
;
7452 error ("Key sequence too long");
7454 if (VECTORP (keytran_next
))
7455 bcopy (XVECTOR (keytran_next
)->contents
,
7456 keybuf
+ keytran_start
,
7457 (t
- keytran_start
) * sizeof (keybuf
[0]));
7458 else if (STRINGP (keytran_next
))
7462 for (i
= 0; i
< len
; i
++)
7463 XSETFASTINT (keybuf
[keytran_start
+ i
],
7464 XSTRING (keytran_next
)->data
[i
]);
7468 keytran_start
= keytran_end
= t
;
7469 keytran_map
= Vkey_translation_map
;
7471 /* Don't pass the results of key-translation-map
7472 through function-key-map. */
7473 fkey_start
= fkey_end
= t
;
7474 fkey_map
= Vkey_translation_map
;
7476 goto replay_sequence
;
7479 keytran_map
= get_keymap_1 (keytran_next
, 0, 1);
7481 /* If we no longer have a bound suffix, try a new positions for
7483 if (NILP (keytran_map
))
7485 keytran_end
= ++keytran_start
;
7486 keytran_map
= Vkey_translation_map
;
7487 key_translation_possible
= 0;
7492 /* If KEY is not defined in any of the keymaps,
7493 and cannot be part of a function key or translation,
7494 and is an upper case letter
7495 use the corresponding lower-case letter instead. */
7496 if (first_binding
== nmaps
&& ! function_key_possible
7497 && ! key_translation_possible
7499 && ((((XINT (key
) & 0x3ffff)
7500 < XCHAR_TABLE (current_buffer
->downcase_table
)->size
)
7501 && UPPERCASEP (XINT (key
) & 0x3ffff))
7502 || (XINT (key
) & shift_modifier
)))
7504 Lisp_Object new_key
;
7506 original_uppercase
= key
;
7507 original_uppercase_position
= t
- 1;
7509 if (XINT (key
) & shift_modifier
)
7510 XSETINT (new_key
, XINT (key
) & ~shift_modifier
);
7512 XSETINT (new_key
, (DOWNCASE (XINT (key
) & 0x3ffff)
7513 | (XINT (key
) & ~0x3ffff)));
7515 /* We have to do this unconditionally, regardless of whether
7516 the lower-case char is defined in the keymaps, because they
7517 might get translated through function-key-map. */
7518 keybuf
[t
- 1] = new_key
;
7521 fkey_map
= prev_fkey_map
;
7522 fkey_start
= prev_fkey_start
;
7523 fkey_end
= prev_fkey_end
;
7525 keytran_map
= prev_keytran_map
;
7526 keytran_start
= prev_keytran_start
;
7527 keytran_end
= prev_keytran_end
;
7529 goto replay_sequence
;
7531 /* If KEY is not defined in any of the keymaps,
7532 and cannot be part of a function key or translation,
7533 and is a shifted function key,
7534 use the corresponding unshifted function key instead. */
7535 if (first_binding
== nmaps
&& ! function_key_possible
7536 && ! key_translation_possible
7539 Lisp_Object breakdown
;
7542 breakdown
= parse_modifiers (key
);
7543 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
7544 if (modifiers
& shift_modifier
)
7546 Lisp_Object new_key
;
7548 original_uppercase
= key
;
7549 original_uppercase_position
= t
- 1;
7551 modifiers
&= ~shift_modifier
;
7552 new_key
= apply_modifiers (modifiers
,
7553 XCONS (breakdown
)->car
);
7555 keybuf
[t
- 1] = new_key
;
7558 fkey_map
= prev_fkey_map
;
7559 fkey_start
= prev_fkey_start
;
7560 fkey_end
= prev_fkey_end
;
7562 keytran_map
= prev_keytran_map
;
7563 keytran_start
= prev_keytran_start
;
7564 keytran_end
= prev_keytran_end
;
7566 goto replay_sequence
;
7572 read_key_sequence_cmd
= (first_binding
< nmaps
7573 ? defs
[first_binding
]
7576 unread_switch_frame
= delayed_switch_frame
;
7577 unbind_to (count
, Qnil
);
7579 /* Don't downcase the last character if the caller says don't.
7580 Don't downcase it if the result is undefined, either. */
7581 if ((dont_downcase_last
|| first_binding
>= nmaps
)
7582 && t
- 1 == original_uppercase_position
)
7583 keybuf
[t
- 1] = original_uppercase
;
7585 /* Occasionally we fabricate events, perhaps by expanding something
7586 according to function-key-map, or by adding a prefix symbol to a
7587 mouse click in the scroll bar or modeline. In this cases, return
7588 the entire generated key sequence, even if we hit an unbound
7589 prefix or a definition before the end. This means that you will
7590 be able to push back the event properly, and also means that
7591 read-key-sequence will always return a logical unit.
7594 for (; t
< mock_input
; t
++)
7596 if (echo_keystrokes
)
7597 echo_char (keybuf
[t
]);
7598 add_command_key (keybuf
[t
]);
7606 #if 0 /* This doc string is too long for some compilers.
7607 This commented-out definition serves for DOC. */
7608 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
7609 "Read a sequence of keystrokes and return as a string or vector.\n\
7610 The sequence is sufficient to specify a non-prefix command in the\n\
7611 current local and global maps.\n\
7613 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
7614 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
7615 as a continuation of the previous key.\n\
7617 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not\n\
7618 convert the last event to lower case. (Normally any upper case event\n\
7619 is converted to lower case if the original event is undefined and the lower\n\
7620 case equivalent is defined.) A non-nil value is appropriate for reading\n\
7621 a key sequence to be defined.\n\
7623 A C-g typed while in this function is treated like any other character,\n\
7624 and `quit-flag' is not set.\n\
7626 If the key sequence starts with a mouse click, then the sequence is read\n\
7627 using the keymaps of the buffer of the window clicked in, not the buffer\n\
7628 of the selected window as normal.\n\
7630 `read-key-sequence' drops unbound button-down events, since you normally\n\
7631 only care about the click or drag events which follow them. If a drag\n\
7632 or multi-click event is unbound, but the corresponding click event would\n\
7633 be bound, `read-key-sequence' turns the event into a click event at the\n\
7634 drag's starting position. This means that you don't have to distinguish\n\
7635 between click and drag, double, or triple events unless you want to.\n\
7637 `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\
7638 lines separating windows, and scroll bars with imaginary keys\n\
7639 `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\
7641 Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this\n\
7642 function will process a switch-frame event if the user switches frames\n\
7643 before typing anything. If the user switches frames in the middle of a\n\
7644 key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME\n\
7645 is nil, then the event will be put off until after the current key sequence.\n\
7647 `read-key-sequence' checks `function-key-map' for function key\n\
7648 sequences, where they wouldn't conflict with ordinary bindings. See\n\
7649 `function-key-map' for more details.\n\
7651 The optional fifth argument COMMAND-LOOP, if non-nil, means\n\
7652 that this key sequence is being read by something that will\n\
7653 read commands one after another. It should be nil if the caller\n\
7654 will read just one key sequence.")
7655 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
)
7658 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 5, 0,
7660 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
7662 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
7663 Lisp_Object can_return_switch_frame
, command_loop
;
7665 Lisp_Object keybuf
[30];
7667 struct gcpro gcpro1
, gcpro2
;
7668 int count
= specpdl_ptr
- specpdl
;
7671 CHECK_STRING (prompt
, 0);
7674 specbind (Qinput_method_exit_on_first_char
,
7675 (NILP (command_loop
) ? Qt
: Qnil
));
7676 specbind (Qinput_method_use_echo_area
,
7677 (NILP (command_loop
) ? Qt
: Qnil
));
7679 bzero (keybuf
, sizeof keybuf
);
7681 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
7683 if (NILP (continue_echo
))
7685 this_command_key_count
= 0;
7686 this_single_command_key_start
= 0;
7689 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
7690 prompt
, ! NILP (dont_downcase_last
),
7691 ! NILP (can_return_switch_frame
), 0);
7699 return unbind_to (count
, make_event_array (i
, keybuf
));
7702 DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector
,
7703 Sread_key_sequence_vector
, 1, 5, 0,
7704 "Like `read-key-sequence' but always return a vector.")
7705 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
7707 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
7708 Lisp_Object can_return_switch_frame
, command_loop
;
7710 Lisp_Object keybuf
[30];
7712 struct gcpro gcpro1
, gcpro2
;
7713 int count
= specpdl_ptr
- specpdl
;
7716 CHECK_STRING (prompt
, 0);
7719 specbind (Qinput_method_exit_on_first_char
,
7720 (NILP (command_loop
) ? Qt
: Qnil
));
7721 specbind (Qinput_method_use_echo_area
,
7722 (NILP (command_loop
) ? Qt
: Qnil
));
7724 bzero (keybuf
, sizeof keybuf
);
7726 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
7728 if (NILP (continue_echo
))
7730 this_command_key_count
= 0;
7731 this_single_command_key_start
= 0;
7734 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
7735 prompt
, ! NILP (dont_downcase_last
),
7736 ! NILP (can_return_switch_frame
), 0);
7744 return unbind_to (count
, Fvector (i
, keybuf
));
7747 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 4, 0,
7748 "Execute CMD as an editor command.\n\
7749 CMD must be a symbol that satisfies the `commandp' predicate.\n\
7750 Optional second arg RECORD-FLAG non-nil\n\
7751 means unconditionally put this command in `command-history'.\n\
7752 Otherwise, that is done only if an arg is read using the minibuffer.\n\
7753 The argument KEYS specifies the value to use instead of (this-command-keys)\n\
7754 when reading the arguments; if it is nil, (this-command-keys) is used.\n\
7755 The argument SPECIAL, if non-nil, means that this command is executing\n\
7756 a special event, so ignore the prefix argument and don't clear it.")
7757 (cmd
, record_flag
, keys
, special
)
7758 Lisp_Object cmd
, record_flag
, keys
, special
;
7760 register Lisp_Object final
;
7761 register Lisp_Object tem
;
7762 Lisp_Object prefixarg
;
7763 struct backtrace backtrace
;
7764 extern int debug_on_next_call
;
7766 debug_on_next_call
= 0;
7770 prefixarg
= current_kboard
->Vprefix_arg
;
7771 Vcurrent_prefix_arg
= prefixarg
;
7772 current_kboard
->Vprefix_arg
= Qnil
;
7779 tem
= Fget (cmd
, Qdisabled
);
7780 if (!NILP (tem
) && !NILP (Vrun_hooks
))
7782 tem
= Fsymbol_value (Qdisabled_command_hook
);
7784 return call1 (Vrun_hooks
, Qdisabled_command_hook
);
7790 final
= Findirect_function (cmd
);
7792 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
7794 struct gcpro gcpro1
, gcpro2
;
7796 GCPRO2 (cmd
, prefixarg
);
7797 do_autoload (final
, cmd
);
7804 if (STRINGP (final
) || VECTORP (final
))
7806 /* If requested, place the macro in the command history. For
7807 other sorts of commands, call-interactively takes care of
7809 if (!NILP (record_flag
))
7812 = Fcons (Fcons (Qexecute_kbd_macro
,
7813 Fcons (final
, Fcons (prefixarg
, Qnil
))),
7816 /* Don't keep command history around forever. */
7817 if (NUMBERP (Vhistory_length
) && XINT (Vhistory_length
) > 0)
7819 tem
= Fnthcdr (Vhistory_length
, Vcommand_history
);
7821 XCONS (tem
)->cdr
= Qnil
;
7825 return Fexecute_kbd_macro (final
, prefixarg
);
7828 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
7830 backtrace
.next
= backtrace_list
;
7831 backtrace_list
= &backtrace
;
7832 backtrace
.function
= &Qcall_interactively
;
7833 backtrace
.args
= &cmd
;
7834 backtrace
.nargs
= 1;
7835 backtrace
.evalargs
= 0;
7837 tem
= Fcall_interactively (cmd
, record_flag
, keys
);
7839 backtrace_list
= backtrace
.next
;
7845 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
7847 "Read function name, then read its arguments and call it.")
7849 Lisp_Object prefixarg
;
7851 Lisp_Object function
;
7853 Lisp_Object saved_keys
;
7854 Lisp_Object bindings
, value
;
7855 struct gcpro gcpro1
, gcpro2
;
7857 saved_keys
= Fvector (this_command_key_count
,
7858 XVECTOR (this_command_keys
)->contents
);
7860 GCPRO2 (saved_keys
, prefixarg
);
7862 if (EQ (prefixarg
, Qminus
))
7864 else if (CONSP (prefixarg
) && XINT (XCONS (prefixarg
)->car
) == 4)
7865 strcpy (buf
, "C-u ");
7866 else if (CONSP (prefixarg
) && INTEGERP (XCONS (prefixarg
)->car
))
7868 if (sizeof (int) == sizeof (EMACS_INT
))
7869 sprintf (buf
, "%d ", XINT (XCONS (prefixarg
)->car
));
7870 else if (sizeof (long) == sizeof (EMACS_INT
))
7871 sprintf (buf
, "%ld ", XINT (XCONS (prefixarg
)->car
));
7875 else if (INTEGERP (prefixarg
))
7877 if (sizeof (int) == sizeof (EMACS_INT
))
7878 sprintf (buf
, "%d ", XINT (prefixarg
));
7879 else if (sizeof (long) == sizeof (EMACS_INT
))
7880 sprintf (buf
, "%ld ", XINT (prefixarg
));
7885 /* This isn't strictly correct if execute-extended-command
7886 is bound to anything else. Perhaps it should use
7887 this_command_keys? */
7888 strcat (buf
, "M-x ");
7890 /* Prompt with buf, and then read a string, completing from and
7891 restricting to the set of all defined commands. Don't provide
7892 any initial input. Save the command read on the extended-command
7894 function
= Fcompleting_read (build_string (buf
),
7895 Vobarray
, Qcommandp
,
7896 Qt
, Qnil
, Qextended_command_history
, Qnil
,
7899 if (STRINGP (function
) && XSTRING (function
)->size
== 0)
7900 error ("No command name given");
7902 /* Set this_command_keys to the concatenation of saved_keys and
7903 function, followed by a RET. */
7905 struct Lisp_String
*str
;
7909 this_command_key_count
= 0;
7910 this_single_command_key_start
= 0;
7912 keys
= XVECTOR (saved_keys
)->contents
;
7913 for (i
= 0; i
< XVECTOR (saved_keys
)->size
; i
++)
7914 add_command_key (keys
[i
]);
7916 str
= XSTRING (function
);
7917 for (i
= 0; i
< str
->size
; i
++)
7918 add_command_key (Faref (function
, make_number (i
)));
7920 add_command_key (make_number ('\015'));
7925 function
= Fintern (function
, Qnil
);
7926 current_kboard
->Vprefix_arg
= prefixarg
;
7927 Vthis_command
= function
;
7928 real_this_command
= function
;
7930 /* If enabled, show which key runs this command. */
7931 if (!NILP (Vsuggest_key_bindings
)
7932 && NILP (Vexecuting_macro
)
7933 && SYMBOLP (function
))
7934 bindings
= Fwhere_is_internal (function
, Voverriding_local_map
,
7940 GCPRO2 (bindings
, value
);
7941 value
= Fcommand_execute (function
, Qt
, Qnil
, Qnil
);
7943 /* If the command has a key binding, print it now. */
7944 if (!NILP (bindings
)
7945 && ! (VECTORP (bindings
) && EQ (Faref (bindings
, make_number (0)),
7948 /* But first wait, and skip the message if there is input. */
7950 if (echo_area_glyphs
!= 0)
7951 /* This command displayed something in the echo area;
7952 so wait a few seconds, then display our suggestion message. */
7953 delay_time
= (NUMBERP (Vsuggest_key_bindings
)
7954 ? XINT (Vsuggest_key_bindings
) : 2);
7956 /* This command left the echo area empty,
7957 so display our message immediately. */
7960 if (!NILP (Fsit_for (make_number (delay_time
), Qnil
, Qnil
))
7961 && ! CONSP (Vunread_command_events
))
7963 Lisp_Object binding
;
7965 char *oldmessage
= echo_area_glyphs
;
7966 int oldmessage_len
= echo_area_glyphs_length
;
7967 int oldmultibyte
= message_enable_multibyte
;
7969 binding
= Fkey_description (bindings
);
7972 = (char *) alloca (XSYMBOL (function
)->name
->size
7973 + STRING_BYTES (XSTRING (binding
))
7975 sprintf (newmessage
, "You can run the command `%s' with %s",
7976 XSYMBOL (function
)->name
->data
,
7977 XSTRING (binding
)->data
);
7978 message2_nolog (newmessage
,
7979 strlen (newmessage
),
7980 STRING_MULTIBYTE (binding
));
7981 if (!NILP (Fsit_for ((NUMBERP (Vsuggest_key_bindings
)
7982 ? Vsuggest_key_bindings
: make_number (2)),
7984 message2_nolog (oldmessage
, oldmessage_len
, oldmultibyte
);
7988 RETURN_UNGCPRO (value
);
7991 /* Find the set of keymaps now active.
7992 Store into *MAPS_P a vector holding the various maps
7993 and return the number of them. The vector was malloc'd
7994 and the caller should free it. */
7997 current_active_maps (maps_p
)
7998 Lisp_Object
**maps_p
;
8000 Lisp_Object
*tmaps
, *maps
;
8003 /* Should overriding-terminal-local-map and overriding-local-map apply? */
8004 if (!NILP (Voverriding_local_map_menu_flag
))
8006 /* Yes, use them (if non-nil) as well as the global map. */
8007 maps
= (Lisp_Object
*) xmalloc (3 * sizeof (maps
[0]));
8009 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
8010 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
8011 if (!NILP (Voverriding_local_map
))
8012 maps
[nmaps
++] = Voverriding_local_map
;
8016 /* No, so use major and minor mode keymaps. */
8017 nmaps
= current_minor_maps (NULL
, &tmaps
);
8018 maps
= (Lisp_Object
*) xmalloc ((nmaps
+ 2) * sizeof (maps
[0]));
8019 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
8020 #ifdef USE_TEXT_PROPERTIES
8021 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
8023 maps
[nmaps
++] = current_buffer
->keymap
;
8026 maps
[nmaps
++] = current_global_map
;
8032 /* Return nonzero if input events are pending. */
8035 detect_input_pending ()
8038 get_input_pending (&input_pending
, 0);
8040 return input_pending
;
8043 /* Return nonzero if input events are pending, and run any pending timers. */
8046 detect_input_pending_run_timers (do_display
)
8049 int old_timers_run
= timers_run
;
8052 get_input_pending (&input_pending
, 1);
8054 if (old_timers_run
!= timers_run
&& do_display
)
8055 redisplay_preserve_echo_area ();
8057 return input_pending
;
8060 /* This is called in some cases before a possible quit.
8061 It cases the next call to detect_input_pending to recompute input_pending.
8062 So calling this function unnecessarily can't do any harm. */
8065 clear_input_pending ()
8070 /* Return nonzero if there are pending requeued events.
8071 This isn't used yet. The hope is to make wait_reading_process_input
8072 call it, and return return if it runs Lisp code that unreads something.
8073 The problem is, kbd_buffer_get_event needs to be fixed to know what
8074 to do in that case. It isn't trivial. */
8077 requeued_events_pending_p ()
8079 return (!NILP (Vunread_command_events
) || unread_command_char
!= -1);
8083 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
8084 "T if command input is currently available with no waiting.\n\
8085 Actually, the value is nil only if we can be sure that no input is available.")
8088 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1)
8091 get_input_pending (&input_pending
, 1);
8092 return input_pending
> 0 ? Qt
: Qnil
;
8095 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
8096 "Return vector of last 100 events, not counting those from keyboard macros.")
8099 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
8102 if (total_keys
< NUM_RECENT_KEYS
)
8103 return Fvector (total_keys
, keys
);
8106 val
= Fvector (NUM_RECENT_KEYS
, keys
);
8107 bcopy (keys
+ recent_keys_index
,
8108 XVECTOR (val
)->contents
,
8109 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
8111 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
8112 recent_keys_index
* sizeof (Lisp_Object
));
8117 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
8118 "Return the key sequence that invoked this command.\n\
8119 The value is a string or a vector.")
8122 return make_event_array (this_command_key_count
,
8123 XVECTOR (this_command_keys
)->contents
);
8126 DEFUN ("this-command-keys-vector", Fthis_command_keys_vector
, Sthis_command_keys_vector
, 0, 0, 0,
8127 "Return the key sequence that invoked this command, as a vector.")
8130 return Fvector (this_command_key_count
,
8131 XVECTOR (this_command_keys
)->contents
);
8134 DEFUN ("this-single-command-keys", Fthis_single_command_keys
,
8135 Sthis_single_command_keys
, 0, 0, 0,
8136 "Return the key sequence that invoked this command.\n\
8137 Unlike `this-command-keys', this function's value\n\
8138 does not include prefix arguments.\n\
8139 The value is always a vector.")
8142 return Fvector (this_command_key_count
8143 - this_single_command_key_start
,
8144 (XVECTOR (this_command_keys
)->contents
8145 + this_single_command_key_start
));
8148 DEFUN ("this-single-command-raw-keys", Fthis_single_command_raw_keys
,
8149 Sthis_single_command_raw_keys
, 0, 0, 0,
8150 "Return the raw events that were read for this command.\n\
8151 Unlike `this-single-command-keys', this function's value\n\
8152 shows the events before all translations (except for input methods).\n\
8153 The value is always a vector.")
8156 return Fvector (raw_keybuf_count
,
8157 (XVECTOR (raw_keybuf
)->contents
));
8160 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths
,
8161 Sreset_this_command_lengths
, 0, 0, 0,
8162 "Used for complicated reasons in `universal-argument-other-key'.\n\
8164 `universal-argument-other-key' rereads the event just typed.\n\
8165 It then gets translated through `function-key-map'.\n\
8166 The translated event gets included in the echo area and in\n\
8167 the value of `this-command-keys' in addition to the raw original event.\n\
8168 That is not right.\n\
8170 Calling this function directs the translated event to replace\n\
8171 the original event, so that only one version of the event actually\n\
8172 appears in the echo area and in the value of `this-command-keys.'.")
8175 before_command_restore_flag
= 1;
8176 before_command_key_count_1
= before_command_key_count
;
8177 before_command_echo_length_1
= before_command_echo_length
;
8180 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
8181 "Return the current depth in recursive edits.")
8185 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
8189 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
8190 "FOpen dribble file: ",
8191 "Start writing all keyboard characters to a dribble file called FILE.\n\
8192 If FILE is nil, close any open dribble file.")
8203 file
= Fexpand_file_name (file
, Qnil
);
8204 dribble
= fopen (XSTRING (file
)->data
, "w");
8206 report_file_error ("Opening dribble", Fcons (file
, Qnil
));
8211 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
8212 "Discard the contents of the terminal input buffer.\n\
8213 Also cancel any kbd macro being defined.")
8216 current_kboard
->defining_kbd_macro
= Qnil
;
8217 update_mode_lines
++;
8219 Vunread_command_events
= Qnil
;
8220 unread_command_char
= -1;
8222 discard_tty_input ();
8224 /* Without the cast, GCC complains that this assignment loses the
8225 volatile qualifier of kbd_store_ptr. Is there anything wrong
8227 kbd_fetch_ptr
= (struct input_event
*) kbd_store_ptr
;
8228 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
8234 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
8235 "Stop Emacs and return to superior process. You can resume later.\n\
8236 If `cannot-suspend' is non-nil, or if the system doesn't support job\n\
8237 control, run a subshell instead.\n\n\
8238 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
8239 to be read as terminal input by Emacs's parent, after suspension.\n\
8241 Before suspending, run the normal hook `suspend-hook'.\n\
8242 After resumption run the normal hook `suspend-resume-hook'.\n\
8244 Some operating systems cannot stop the Emacs process and resume it later.\n\
8245 On such systems, Emacs starts a subshell instead of suspending.")
8247 Lisp_Object stuffstring
;
8250 int count
= specpdl_ptr
- specpdl
;
8251 int old_height
, old_width
;
8253 struct gcpro gcpro1
, gcpro2
;
8255 if (!NILP (stuffstring
))
8256 CHECK_STRING (stuffstring
, 0);
8258 /* Run the functions in suspend-hook. */
8259 if (!NILP (Vrun_hooks
))
8260 call1 (Vrun_hooks
, intern ("suspend-hook"));
8262 GCPRO1 (stuffstring
);
8263 get_frame_size (&old_width
, &old_height
);
8265 /* sys_suspend can get an error if it tries to fork a subshell
8266 and the system resources aren't available for that. */
8267 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object
))) init_sys_modes
,
8269 stuff_buffered_input (stuffstring
);
8274 unbind_to (count
, Qnil
);
8276 /* Check if terminal/window size has changed.
8277 Note that this is not useful when we are running directly
8278 with a window system; but suspend should be disabled in that case. */
8279 get_frame_size (&width
, &height
);
8280 if (width
!= old_width
|| height
!= old_height
)
8281 change_frame_size (selected_frame
, height
, width
, 0, 0);
8283 /* Run suspend-resume-hook. */
8284 if (!NILP (Vrun_hooks
))
8285 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
8291 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
8292 Then in any case stuff anything Emacs has read ahead and not used. */
8295 stuff_buffered_input (stuffstring
)
8296 Lisp_Object stuffstring
;
8298 /* stuff_char works only in BSD, versions 4.2 and up. */
8301 register unsigned char *p
;
8303 if (STRINGP (stuffstring
))
8307 p
= XSTRING (stuffstring
)->data
;
8308 count
= STRING_BYTES (XSTRING (stuffstring
));
8313 /* Anything we have read ahead, put back for the shell to read. */
8314 /* ?? What should this do when we have multiple keyboards??
8315 Should we ignore anything that was typed in at the "wrong" kboard? */
8316 for (; kbd_fetch_ptr
!= kbd_store_ptr
; kbd_fetch_ptr
++)
8318 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
8319 kbd_fetch_ptr
= kbd_buffer
;
8320 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
8321 stuff_char (kbd_fetch_ptr
->code
);
8322 kbd_fetch_ptr
->kind
= no_event
;
8323 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_fetch_ptr
8329 #endif /* BSD_SYSTEM and not BSD4_1 */
8333 set_waiting_for_input (time_to_clear
)
8334 EMACS_TIME
*time_to_clear
;
8336 input_available_clear_time
= time_to_clear
;
8338 /* Tell interrupt_signal to throw back to read_char, */
8339 waiting_for_input
= 1;
8341 /* If interrupt_signal was called before and buffered a C-g,
8342 make it run again now, to avoid timing error. */
8343 if (!NILP (Vquit_flag
))
8344 quit_throw_to_read_char ();
8348 clear_waiting_for_input ()
8350 /* Tell interrupt_signal not to throw back to read_char, */
8351 waiting_for_input
= 0;
8352 input_available_clear_time
= 0;
8355 /* This routine is called at interrupt level in response to C-G.
8356 If interrupt_input, this is the handler for SIGINT.
8357 Otherwise, it is called from kbd_buffer_store_event,
8358 in handling SIGIO or SIGTINT.
8360 If `waiting_for_input' is non zero, then unless `echoing' is nonzero,
8361 immediately throw back to read_char.
8363 Otherwise it sets the Lisp variable quit-flag not-nil.
8364 This causes eval to throw, when it gets a chance.
8365 If quit-flag is already non-nil, it stops the job right away. */
8368 interrupt_signal (signalnum
) /* If we don't have an argument, */
8369 int signalnum
; /* some compilers complain in signal calls. */
8372 /* Must preserve main program's value of errno. */
8373 int old_errno
= errno
;
8375 #if defined (USG) && !defined (POSIX_SIGNALS)
8376 if (!read_socket_hook
&& NILP (Vwindow_system
))
8378 /* USG systems forget handlers when they are used;
8379 must reestablish each time */
8380 signal (SIGINT
, interrupt_signal
);
8381 signal (SIGQUIT
, interrupt_signal
);
8387 if (!NILP (Vquit_flag
)
8388 && (FRAME_TERMCAP_P (selected_frame
) || FRAME_MSDOS_P (selected_frame
)))
8390 /* If SIGINT isn't blocked, don't let us be interrupted by
8391 another SIGINT, it might be harmful due to non-reentrancy
8392 in I/O functions. */
8393 sigblock (sigmask (SIGINT
));
8398 #ifdef SIGTSTP /* Support possible in later USG versions */
8400 * On systems which can suspend the current process and return to the original
8401 * shell, this command causes the user to end up back at the shell.
8402 * The "Auto-save" and "Abort" questions are not asked until
8403 * the user elects to return to emacs, at which point he can save the current
8404 * job and either dump core or continue.
8409 if (sys_suspend () == -1)
8411 printf ("Not running as a subprocess;\n");
8412 printf ("you can continue or abort.\n");
8415 /* Perhaps should really fork an inferior shell?
8416 But that would not provide any way to get back
8417 to the original shell, ever. */
8418 printf ("No support for stopping a process on this operating system;\n");
8419 printf ("you can continue or abort.\n");
8420 #endif /* not VMS */
8421 #endif /* not SIGTSTP */
8423 /* We must remain inside the screen area when the internal terminal
8424 is used. Note that [Enter] is not echoed by dos. */
8427 /* It doesn't work to autosave while GC is in progress;
8428 the code used for auto-saving doesn't cope with the mark bit. */
8429 if (!gc_in_progress
)
8431 printf ("Auto-save? (y or n) ");
8433 if (((c
= getchar ()) & ~040) == 'Y')
8435 Fdo_auto_save (Qt
, Qnil
);
8437 printf ("\r\nAuto-save done");
8438 #else /* not MSDOS */
8439 printf ("Auto-save done\n");
8440 #endif /* not MSDOS */
8442 while (c
!= '\n') c
= getchar ();
8446 /* During GC, it must be safe to reenable quitting again. */
8447 Vinhibit_quit
= Qnil
;
8450 #endif /* not MSDOS */
8451 printf ("Garbage collection in progress; cannot auto-save now\r\n");
8452 printf ("but will instead do a real quit after garbage collection ends\r\n");
8457 printf ("\r\nAbort? (y or n) ");
8458 #else /* not MSDOS */
8460 printf ("Abort (and enter debugger)? (y or n) ");
8462 printf ("Abort (and dump core)? (y or n) ");
8463 #endif /* not VMS */
8464 #endif /* not MSDOS */
8466 if (((c
= getchar ()) & ~040) == 'Y')
8468 while (c
!= '\n') c
= getchar ();
8470 printf ("\r\nContinuing...\r\n");
8471 #else /* not MSDOS */
8472 printf ("Continuing...\n");
8473 #endif /* not MSDOS */
8480 /* If executing a function that wants to be interrupted out of
8481 and the user has not deferred quitting by binding `inhibit-quit'
8482 then quit right away. */
8483 if (immediate_quit
&& NILP (Vinhibit_quit
))
8485 struct gl_state_s saved
;
8486 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
8491 GCPRO4 (saved
.object
, saved
.global_code
,
8492 saved
.current_syntax_table
, saved
.old_prop
);
8493 Fsignal (Qquit
, Qnil
);
8498 /* Else request quit when it's safe */
8502 if (waiting_for_input
&& !echoing
)
8503 quit_throw_to_read_char ();
8508 /* Handle a C-g by making read_char return C-g. */
8511 quit_throw_to_read_char ()
8513 quit_error_check ();
8515 /* Prevent another signal from doing this before we finish. */
8516 clear_waiting_for_input ();
8519 Vunread_command_events
= Qnil
;
8520 unread_command_char
= -1;
8522 #if 0 /* Currently, sit_for is called from read_char without turning
8523 off polling. And that can call set_waiting_for_input.
8524 It seems to be harmless. */
8525 #ifdef POLL_FOR_INPUT
8526 /* May be > 1 if in recursive minibuffer. */
8527 if (poll_suppress_count
== 0)
8531 if (FRAMEP (internal_last_event_frame
)
8532 && XFRAME (internal_last_event_frame
) != selected_frame
)
8533 do_switch_frame (make_lispy_switch_frame (internal_last_event_frame
),
8536 _longjmp (getcjmp
, 1);
8539 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
8540 "Set mode of reading keyboard input.\n\
8541 First arg INTERRUPT non-nil means use input interrupts;\n\
8542 nil means use CBREAK mode.\n\
8543 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
8544 (no effect except in CBREAK mode).\n\
8545 Third arg META t means accept 8-bit input (for a Meta key).\n\
8546 META nil means ignore the top bit, on the assumption it is parity.\n\
8547 Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\
8548 Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\
8549 See also `current-input-mode'.")
8550 (interrupt
, flow
, meta
, quit
)
8551 Lisp_Object interrupt
, flow
, meta
, quit
;
8554 && (!INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400))
8555 error ("set-input-mode: QUIT must be an ASCII character");
8557 #ifdef POLL_FOR_INPUT
8562 /* this causes startup screen to be restored and messes with the mouse */
8567 /* Note SIGIO has been undef'd if FIONREAD is missing. */
8568 if (read_socket_hook
)
8570 /* When using X, don't give the user a real choice,
8571 because we haven't implemented the mechanisms to support it. */
8572 #ifdef NO_SOCK_SIGIO
8573 interrupt_input
= 0;
8574 #else /* not NO_SOCK_SIGIO */
8575 interrupt_input
= 1;
8576 #endif /* NO_SOCK_SIGIO */
8579 interrupt_input
= !NILP (interrupt
);
8580 #else /* not SIGIO */
8581 interrupt_input
= 0;
8582 #endif /* not SIGIO */
8584 /* Our VMS input only works by interrupts, as of now. */
8586 interrupt_input
= 1;
8589 flow_control
= !NILP (flow
);
8592 else if (EQ (meta
, Qt
))
8597 /* Don't let this value be out of range. */
8598 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
8604 #ifdef POLL_FOR_INPUT
8605 poll_suppress_count
= 1;
8611 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
8612 "Return information about the way Emacs currently reads keyboard input.\n\
8613 The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
8614 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\
8615 nil, Emacs is using CBREAK mode.\n\
8616 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\
8617 terminal; this does not apply if Emacs uses interrupt-driven input.\n\
8618 META is t if accepting 8-bit input with 8th bit as Meta flag.\n\
8619 META nil means ignoring the top bit, on the assumption it is parity.\n\
8620 META is neither t nor nil if accepting 8-bit input and using\n\
8621 all 8 bits as the character code.\n\
8622 QUIT is the character Emacs currently uses to quit.\n\
8623 The elements of this list correspond to the arguments of\n\
8629 val
[0] = interrupt_input
? Qt
: Qnil
;
8630 val
[1] = flow_control
? Qt
: Qnil
;
8631 val
[2] = meta_key
== 2 ? make_number (0) : meta_key
== 1 ? Qt
: Qnil
;
8632 XSETFASTINT (val
[3], quit_char
);
8634 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
8639 * Set up a new kboard object with reasonable initial values.
8645 kb
->Voverriding_terminal_local_map
= Qnil
;
8646 kb
->Vlast_command
= Qnil
;
8647 kb
->Vreal_last_command
= Qnil
;
8648 kb
->Vprefix_arg
= Qnil
;
8649 kb
->Vlast_prefix_arg
= Qnil
;
8650 kb
->kbd_queue
= Qnil
;
8651 kb
->kbd_queue_has_data
= 0;
8652 kb
->immediate_echo
= 0;
8653 kb
->echoptr
= kb
->echobuf
;
8654 kb
->echo_after_prompt
= -1;
8655 kb
->kbd_macro_buffer
= 0;
8656 kb
->kbd_macro_bufsize
= 0;
8657 kb
->defining_kbd_macro
= Qnil
;
8658 kb
->Vlast_kbd_macro
= Qnil
;
8659 kb
->reference_count
= 0;
8660 kb
->Vsystem_key_alist
= Qnil
;
8661 kb
->system_key_syms
= Qnil
;
8662 kb
->Vdefault_minibuffer_frame
= Qnil
;
8666 * Destroy the contents of a kboard object, but not the object itself.
8667 * We use this just before deleting it, or if we're going to initialize
8674 if (kb
->kbd_macro_buffer
)
8675 xfree (kb
->kbd_macro_buffer
);
8684 for (kbp
= &all_kboards
; *kbp
!= kb
; kbp
= &(*kbp
)->next_kboard
)
8687 *kbp
= kb
->next_kboard
;
8696 /* This is correct before outermost invocation of the editor loop */
8697 command_loop_level
= -1;
8699 quit_char
= Ctl ('g');
8700 Vunread_command_events
= Qnil
;
8701 unread_command_char
= -1;
8702 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
8704 recent_keys_index
= 0;
8705 kbd_fetch_ptr
= kbd_buffer
;
8706 kbd_store_ptr
= kbd_buffer
;
8707 kbd_buffer_frame_or_window
8708 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
8710 do_mouse_tracking
= Qnil
;
8714 /* This means that command_loop_1 won't try to select anything the first
8716 internal_last_event_frame
= Qnil
;
8717 Vlast_event_frame
= internal_last_event_frame
;
8720 current_kboard
= initial_kboard
;
8722 wipe_kboard (current_kboard
);
8723 init_kboard (current_kboard
);
8726 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
8728 kbd_buffer_frame_or_window
8729 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
8730 if (!noninteractive
&& !read_socket_hook
&& NILP (Vwindow_system
))
8732 signal (SIGINT
, interrupt_signal
);
8733 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
8734 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
8735 SIGQUIT and we can't tell which one it will give us. */
8736 signal (SIGQUIT
, interrupt_signal
);
8737 #endif /* HAVE_TERMIO */
8739 /* Note SIGIO has been undef'd if FIONREAD is missing. */
8741 if (!noninteractive
)
8742 signal (SIGIO
, input_available_signal
);
8745 /* Use interrupt input by default, if it works and noninterrupt input
8746 has deficiencies. */
8748 #ifdef INTERRUPT_INPUT
8749 interrupt_input
= 1;
8751 interrupt_input
= 0;
8754 /* Our VMS input only works by interrupts, as of now. */
8756 interrupt_input
= 1;
8762 if (keyboard_init_hook
)
8763 (*keyboard_init_hook
) ();
8765 #ifdef POLL_FOR_INPUT
8766 poll_suppress_count
= 1;
8771 /* This type's only use is in syms_of_keyboard, to initialize the
8772 event header symbols and put properties on them. */
8779 struct event_head head_table
[] = {
8780 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
8781 &Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
,
8782 &Qswitch_frame
, "switch-frame", &Qswitch_frame
,
8783 &Qdelete_frame
, "delete-frame", &Qdelete_frame
,
8784 &Qiconify_frame
, "iconify-frame", &Qiconify_frame
,
8785 &Qmake_frame_visible
, "make-frame-visible", &Qmake_frame_visible
,
8791 staticpro (&item_properties
);
8792 item_properties
= Qnil
;
8794 staticpro (&real_this_command
);
8795 real_this_command
= Qnil
;
8797 Qtimer_event_handler
= intern ("timer-event-handler");
8798 staticpro (&Qtimer_event_handler
);
8800 Qdisabled_command_hook
= intern ("disabled-command-hook");
8801 staticpro (&Qdisabled_command_hook
);
8803 Qself_insert_command
= intern ("self-insert-command");
8804 staticpro (&Qself_insert_command
);
8806 Qforward_char
= intern ("forward-char");
8807 staticpro (&Qforward_char
);
8809 Qbackward_char
= intern ("backward-char");
8810 staticpro (&Qbackward_char
);
8812 Qdisabled
= intern ("disabled");
8813 staticpro (&Qdisabled
);
8815 Qundefined
= intern ("undefined");
8816 staticpro (&Qundefined
);
8818 Qpre_command_hook
= intern ("pre-command-hook");
8819 staticpro (&Qpre_command_hook
);
8821 Qpost_command_hook
= intern ("post-command-hook");
8822 staticpro (&Qpost_command_hook
);
8824 Qpost_command_idle_hook
= intern ("post-command-idle-hook");
8825 staticpro (&Qpost_command_idle_hook
);
8827 Qdeferred_action_function
= intern ("deferred-action-function");
8828 staticpro (&Qdeferred_action_function
);
8830 Qcommand_hook_internal
= intern ("command-hook-internal");
8831 staticpro (&Qcommand_hook_internal
);
8833 Qfunction_key
= intern ("function-key");
8834 staticpro (&Qfunction_key
);
8835 Qmouse_click
= intern ("mouse-click");
8836 staticpro (&Qmouse_click
);
8838 Qmouse_wheel
= intern ("mouse-wheel");
8839 staticpro (&Qmouse_wheel
);
8841 Qdrag_n_drop
= intern ("drag-n-drop");
8842 staticpro (&Qdrag_n_drop
);
8844 Qmenu_enable
= intern ("menu-enable");
8845 staticpro (&Qmenu_enable
);
8846 Qmenu_alias
= intern ("menu-alias");
8847 staticpro (&Qmenu_alias
);
8848 QCenable
= intern (":enable");
8849 staticpro (&QCenable
);
8850 QCvisible
= intern (":visible");
8851 staticpro (&QCvisible
);
8852 QCfilter
= intern (":filter");
8853 staticpro (&QCfilter
);
8854 QCbutton
= intern (":button");
8855 staticpro (&QCbutton
);
8856 QCkeys
= intern (":keys");
8857 staticpro (&QCkeys
);
8858 QCkey_sequence
= intern (":key-sequence");
8859 staticpro (&QCkey_sequence
);
8860 QCtoggle
= intern (":toggle");
8861 staticpro (&QCtoggle
);
8862 QCradio
= intern (":radio");
8863 staticpro (&QCradio
);
8865 Qmode_line
= intern ("mode-line");
8866 staticpro (&Qmode_line
);
8867 Qvertical_line
= intern ("vertical-line");
8868 staticpro (&Qvertical_line
);
8869 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
8870 staticpro (&Qvertical_scroll_bar
);
8871 Qmenu_bar
= intern ("menu-bar");
8872 staticpro (&Qmenu_bar
);
8874 Qabove_handle
= intern ("above-handle");
8875 staticpro (&Qabove_handle
);
8876 Qhandle
= intern ("handle");
8877 staticpro (&Qhandle
);
8878 Qbelow_handle
= intern ("below-handle");
8879 staticpro (&Qbelow_handle
);
8880 Qup
= intern ("up");
8882 Qdown
= intern ("down");
8885 Qevent_kind
= intern ("event-kind");
8886 staticpro (&Qevent_kind
);
8887 Qevent_symbol_elements
= intern ("event-symbol-elements");
8888 staticpro (&Qevent_symbol_elements
);
8889 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
8890 staticpro (&Qevent_symbol_element_mask
);
8891 Qmodifier_cache
= intern ("modifier-cache");
8892 staticpro (&Qmodifier_cache
);
8894 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
8895 staticpro (&Qrecompute_lucid_menubar
);
8896 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
8897 staticpro (&Qactivate_menubar_hook
);
8899 Qpolling_period
= intern ("polling-period");
8900 staticpro (&Qpolling_period
);
8902 Qinput_method_function
= intern ("input-method-function");
8903 staticpro (&Qinput_method_function
);
8905 Qinput_method_exit_on_first_char
= intern ("input-method-exit-on-first-char");
8906 staticpro (&Qinput_method_exit_on_first_char
);
8907 Qinput_method_use_echo_area
= intern ("input-method-use-echo-area");
8908 staticpro (&Qinput_method_use_echo_area
);
8910 Fset (Qinput_method_exit_on_first_char
, Qnil
);
8911 Fset (Qinput_method_use_echo_area
, Qnil
);
8914 struct event_head
*p
;
8916 for (p
= head_table
;
8917 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
8920 *p
->var
= intern (p
->name
);
8922 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
8923 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
8927 button_down_location
= Fmake_vector (make_number (NUM_MOUSE_BUTTONS
), Qnil
);
8928 staticpro (&button_down_location
);
8932 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
8934 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
8935 for (i
= 0; i
< len
; i
++)
8936 if (modifier_names
[i
])
8937 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
8938 staticpro (&modifier_symbols
);
8941 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
8942 staticpro (&recent_keys
);
8944 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
8945 staticpro (&this_command_keys
);
8947 raw_keybuf
= Fmake_vector (make_number (30), Qnil
);
8948 staticpro (&raw_keybuf
);
8950 Qextended_command_history
= intern ("extended-command-history");
8951 Fset (Qextended_command_history
, Qnil
);
8952 staticpro (&Qextended_command_history
);
8954 kbd_buffer_frame_or_window
8955 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
8956 staticpro (&kbd_buffer_frame_or_window
);
8958 accent_key_syms
= Qnil
;
8959 staticpro (&accent_key_syms
);
8961 func_key_syms
= Qnil
;
8962 staticpro (&func_key_syms
);
8965 staticpro (&mouse_syms
);
8968 mouse_wheel_syms
= Qnil
;
8969 staticpro (&mouse_wheel_syms
);
8971 drag_n_drop_syms
= Qnil
;
8972 staticpro (&drag_n_drop_syms
);
8975 unread_switch_frame
= Qnil
;
8976 staticpro (&unread_switch_frame
);
8978 internal_last_event_frame
= Qnil
;
8979 staticpro (&internal_last_event_frame
);
8981 read_key_sequence_cmd
= Qnil
;
8982 staticpro (&read_key_sequence_cmd
);
8984 defsubr (&Sevent_convert_list
);
8985 defsubr (&Sread_key_sequence
);
8986 defsubr (&Sread_key_sequence_vector
);
8987 defsubr (&Srecursive_edit
);
8989 defsubr (&Strack_mouse
);
8991 defsubr (&Sinput_pending_p
);
8992 defsubr (&Scommand_execute
);
8993 defsubr (&Srecent_keys
);
8994 defsubr (&Sthis_command_keys
);
8995 defsubr (&Sthis_command_keys_vector
);
8996 defsubr (&Sthis_single_command_keys
);
8997 defsubr (&Sthis_single_command_raw_keys
);
8998 defsubr (&Sreset_this_command_lengths
);
8999 defsubr (&Ssuspend_emacs
);
9000 defsubr (&Sabort_recursive_edit
);
9001 defsubr (&Sexit_recursive_edit
);
9002 defsubr (&Srecursion_depth
);
9003 defsubr (&Stop_level
);
9004 defsubr (&Sdiscard_input
);
9005 defsubr (&Sopen_dribble_file
);
9006 defsubr (&Sset_input_mode
);
9007 defsubr (&Scurrent_input_mode
);
9008 defsubr (&Sexecute_extended_command
);
9010 DEFVAR_LISP ("last-command-char", &last_command_char
,
9011 "Last input event that was part of a command.");
9013 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char
,
9014 "Last input event that was part of a command.");
9016 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
9017 "Last input event in a command, except for mouse menu events.\n\
9018 Mouse menus give back keys that don't look like mouse events;\n\
9019 this variable holds the actual mouse event that led to the menu,\n\
9020 so that you can determine whether the command was run by mouse or not.");
9022 DEFVAR_LISP ("last-input-char", &last_input_char
,
9023 "Last input event.");
9025 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char
,
9026 "Last input event.");
9028 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
9029 "List of events to be read as the command input.\n\
9030 These events are processed first, before actual keyboard input.");
9031 Vunread_command_events
= Qnil
;
9033 DEFVAR_INT ("unread-command-char", &unread_command_char
,
9034 "If not -1, an object to be read as next command input event.");
9036 DEFVAR_LISP ("unread-post-input-method-events", &Vunread_post_input_method_events
,
9037 "List of events to be processed as input by input methods.\n\
9038 These events are processed after `unread-command-events', but\n\
9039 before actual keyboard input.");
9040 Vunread_post_input_method_events
= Qnil
;
9042 DEFVAR_LISP ("unread-input-method-events", &Vunread_input_method_events
,
9043 "List of events to be processed as input by input methods.\n\
9044 These events are processed after `unread-command-events', but\n\
9045 before actual keyboard input.");
9046 Vunread_input_method_events
= Qnil
;
9048 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
9049 "Meta-prefix character code. Meta-foo as command input\n\
9050 turns into this character followed by foo.");
9051 XSETINT (meta_prefix_char
, 033);
9053 DEFVAR_KBOARD ("last-command", Vlast_command
,
9054 "The last command executed. Normally a symbol with a function definition,\n\
9055 but can be whatever was found in the keymap, or whatever the variable\n\
9056 `this-command' was set to by that command.\n\
9058 The value `mode-exit' is special; it means that the previous command\n\
9059 read an event that told it to exit, and it did so and unread that event.\n\
9060 In other words, the present command is the event that made the previous\n\
9063 The value `kill-region' is special; it means that the previous command\n\
9064 was a kill command.");
9066 DEFVAR_KBOARD ("real-last-command", Vreal_last_command
,
9067 "Same as `last-command', but never altered by Lisp code.");
9069 DEFVAR_LISP ("this-command", &Vthis_command
,
9070 "The command now being executed.\n\
9071 The command can set this variable; whatever is put here\n\
9072 will be in `last-command' during the following command.");
9073 Vthis_command
= Qnil
;
9075 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
9076 "*Number of keyboard input characters between auto-saves.\n\
9077 Zero means disable autosaving due to number of characters typed.");
9078 auto_save_interval
= 300;
9080 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
9081 "*Number of seconds idle time before auto-save.\n\
9082 Zero or nil means disable auto-saving due to idleness.\n\
9083 After auto-saving due to this many seconds of idle time,\n\
9084 Emacs also does a garbage collection if that seems to be warranted.");
9085 XSETFASTINT (Vauto_save_timeout
, 30);
9087 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes
,
9088 "*Nonzero means echo unfinished commands after this many seconds of pause.");
9089 echo_keystrokes
= 1;
9091 DEFVAR_INT ("polling-period", &polling_period
,
9092 "*Interval between polling for input during Lisp execution.\n\
9093 The reason for polling is to make C-g work to stop a running program.\n\
9094 Polling is needed only when using X windows and SIGIO does not work.\n\
9095 Polling is automatically disabled in all other cases.");
9098 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
9099 "*Maximum time between mouse clicks to make a double-click.\n\
9100 Measured in milliseconds. nil means disable double-click recognition;\n\
9101 t means double-clicks have no time limit and are detected\n\
9102 by position only.");
9103 Vdouble_click_time
= make_number (500);
9105 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
9106 "*Non-nil means inhibit local map menu bar menus.");
9107 inhibit_local_menu_bar_menus
= 0;
9109 DEFVAR_INT ("num-input-keys", &num_input_keys
,
9110 "Number of complete key sequences read as input so far.\n\
9111 This includes key sequences read from keyboard macros.\n\
9112 The number is effectively the number of interactive command invocations.");
9115 DEFVAR_INT ("num-nonmacro-input-events", &num_nonmacro_input_events
,
9116 "Number of input events read from the keyboard so far.\n\
9117 This does not include events generated by keyboard macros.");
9118 num_nonmacro_input_events
= 0;
9120 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
9121 "The frame in which the most recently read event occurred.\n\
9122 If the last event came from a keyboard macro, this is set to `macro'.");
9123 Vlast_event_frame
= Qnil
;
9125 /* This variable is set up in sysdep.c. */
9126 DEFVAR_LISP ("tty-erase-char", &Vtty_erase_char
,
9127 "The ERASE character as set by the user with stty.");
9129 DEFVAR_LISP ("help-char", &Vhelp_char
,
9130 "Character to recognize as meaning Help.\n\
9131 When it is read, do `(eval help-form)', and display result if it's a string.\n\
9132 If the value of `help-form' is nil, this char can be read normally.");
9133 XSETINT (Vhelp_char
, Ctl ('H'));
9135 DEFVAR_LISP ("help-event-list", &Vhelp_event_list
,
9136 "List of input events to recognize as meaning Help.\n\
9137 These work just like the value of `help-char' (see that).");
9138 Vhelp_event_list
= Qnil
;
9140 DEFVAR_LISP ("help-form", &Vhelp_form
,
9141 "Form to execute when character `help-char' is read.\n\
9142 If the form returns a string, that string is displayed.\n\
9143 If `help-form' is nil, the help char is not recognized.");
9146 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
9147 "Command to run when `help-char' character follows a prefix key.\n\
9148 This command is used only when there is no actual binding\n\
9149 for that character after that prefix key.");
9150 Vprefix_help_command
= Qnil
;
9152 DEFVAR_LISP ("top-level", &Vtop_level
,
9153 "Form to evaluate when Emacs starts up.\n\
9154 Useful to set before you dump a modified Emacs.");
9157 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
9158 "Translate table for keyboard input, or nil.\n\
9159 Each character is looked up in this string and the contents used instead.\n\
9160 The value may be a string, a vector, or a char-table.\n\
9161 If it is a string or vector of length N,\n\
9162 character codes N and up are untranslated.\n\
9163 In a vector or a char-table, an element which is nil means \"no translation\".");
9164 Vkeyboard_translate_table
= Qnil
;
9166 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
9167 "Non-nil means to always spawn a subshell instead of suspending,\n\
9168 even if the operating system has support for stopping a process.");
9171 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
9172 "Non-nil means prompt with menus when appropriate.\n\
9173 This is done when reading from a keymap that has a prompt string,\n\
9174 for elements that have prompt strings.\n\
9175 The menu is displayed on the screen\n\
9176 if X menus were enabled at configuration\n\
9177 time and the previous event was a mouse click prefix key.\n\
9178 Otherwise, menu prompting uses the echo area.");
9181 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
9182 "Character to see next line of menu prompt.\n\
9183 Type this character while in a menu prompt to rotate around the lines of it.");
9184 XSETINT (menu_prompt_more_char
, ' ');
9186 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
9187 "A mask of additional modifier keys to use with every keyboard character.\n\
9188 Emacs applies the modifiers of the character stored here to each keyboard\n\
9189 character it reads. For example, after evaluating the expression\n\
9190 (setq extra-keyboard-modifiers ?\\C-x)\n\
9191 all input characters will have the control modifier applied to them.\n\
9193 Note that the character ?\\C-@, equivalent to the integer zero, does\n\
9194 not count as a control character; rather, it counts as a character\n\
9195 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\
9196 cancels any modification.");
9197 extra_keyboard_modifiers
= 0;
9199 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
9200 "If an editing command sets this to t, deactivate the mark afterward.\n\
9201 The command loop sets this to nil before each command,\n\
9202 and tests the value when the command returns.\n\
9203 Buffer modification stores t in this variable.");
9204 Vdeactivate_mark
= Qnil
;
9206 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
9207 "Temporary storage of pre-command-hook or post-command-hook.");
9208 Vcommand_hook_internal
= Qnil
;
9210 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
9211 "Normal hook run before each command is executed.\n\
9212 Errors running the hook are caught and ignored.");
9213 Vpre_command_hook
= Qnil
;
9215 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
9216 "Normal hook run after each command is executed.\n\
9217 Errors running the hook are caught and ignored.");
9218 Vpost_command_hook
= Qnil
;
9220 DEFVAR_LISP ("post-command-idle-hook", &Vpost_command_idle_hook
,
9221 "Normal hook run after each command is executed, if idle.\n\
9222 Errors running the hook are caught and ignored.\n\
9223 This feature is obsolete; use idle timers instead. See `etc/NEWS'.");
9224 Vpost_command_idle_hook
= Qnil
;
9226 DEFVAR_INT ("post-command-idle-delay", &post_command_idle_delay
,
9227 "Delay time before running `post-command-idle-hook'.\n\
9228 This is measured in microseconds.");
9229 post_command_idle_delay
= 100000;
9232 DEFVAR_LISP ("echo-area-clear-hook", ...,
9233 "Normal hook run when clearing the echo area.");
9235 Qecho_area_clear_hook
= intern ("echo-area-clear-hook");
9236 XSYMBOL (Qecho_area_clear_hook
)->value
= Qnil
;
9238 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
9239 "t means menu bar, specified Lucid style, needs to be recomputed.");
9240 Vlucid_menu_bar_dirty_flag
= Qnil
;
9242 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
9243 "List of menu bar items to move to the end of the menu bar.\n\
9244 The elements of the list are event types that may have menu bar bindings.");
9245 Vmenu_bar_final_items
= Qnil
;
9247 DEFVAR_KBOARD ("overriding-terminal-local-map",
9248 Voverriding_terminal_local_map
,
9249 "Per-terminal keymap that overrides all other local keymaps.\n\
9250 If this variable is non-nil, it is used as a keymap instead of the\n\
9251 buffer's local map, and the minor mode keymaps and text property keymaps.\n\
9252 This variable is intended to let commands such as `universal-argumemnt'\n\
9253 set up a different keymap for reading the next command.");
9255 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
9256 "Keymap that overrides all other local keymaps.\n\
9257 If this variable is non-nil, it is used as a keymap instead of the\n\
9258 buffer's local map, and the minor mode keymaps and text property keymaps.");
9259 Voverriding_local_map
= Qnil
;
9261 DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag
,
9262 "Non-nil means `overriding-local-map' applies to the menu bar.\n\
9263 Otherwise, the menu bar continues to reflect the buffer's local map\n\
9264 and the minor mode maps regardless of `overriding-local-map'.");
9265 Voverriding_local_map_menu_flag
= Qnil
;
9267 DEFVAR_LISP ("special-event-map", &Vspecial_event_map
,
9268 "Keymap defining bindings for special events to execute at low level.");
9269 Vspecial_event_map
= Fcons (intern ("keymap"), Qnil
);
9271 DEFVAR_LISP ("track-mouse", &do_mouse_tracking
,
9272 "*Non-nil means generate motion events for mouse motion.");
9274 DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist
,
9275 "Alist of system-specific X windows key symbols.\n\
9276 Each element should have the form (N . SYMBOL) where N is the\n\
9277 numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\
9278 and SYMBOL is its name.");
9280 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
9281 "List of deferred actions to be performed at a later time.\n\
9282 The precise format isn't relevant here; we just check whether it is nil.");
9283 Vdeferred_action_list
= Qnil
;
9285 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
9286 "Function to call to handle deferred actions, after each command.\n\
9287 This function is called with no arguments after each command\n\
9288 whenever `deferred-action-list' is non-nil.");
9289 Vdeferred_action_function
= Qnil
;
9291 DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings
,
9292 "*Non-nil means show the equivalent key-binding when M-x command has one.\n\
9293 The value can be a length of time to show the message for.\n\
9294 If the value is non-nil and not a number, we wait 2 seconds.");
9295 Vsuggest_key_bindings
= Qt
;
9297 DEFVAR_LISP ("timer-list", &Vtimer_list
,
9298 "List of active absolute time timers in order of increasing time");
9301 DEFVAR_LISP ("timer-idle-list", &Vtimer_idle_list
,
9302 "List of active idle-time timers in order of increasing time");
9303 Vtimer_idle_list
= Qnil
;
9305 DEFVAR_LISP ("input-method-function", &Vinput_method_function
,
9306 "If non-nil, the function that implements the current input method.\n\
9307 It's called with one argument, a printing character that was just read.\n\
9308 \(That means a character with code 040...0176.)\n\
9309 Typically this function uses `read-event' to read additional events.\n\
9310 When it does so, it should first bind `input-method-function' to nil\n\
9311 so it will not be called recursively.\n\
9313 The function should return a list of zero or more events\n\
9314 to be used as input. If it wants to put back some events\n\
9315 to be reconsidered, separately, by the input method,\n\
9316 it can add them to the beginning of `unread-command-events'.\n\
9318 The input method function can find in `input-method-previous-method'\n\
9319 the previous echo area message.\n\
9321 The input method function should refer to the variables\n\
9322 `input-method-use-echo-area' and `input-method-exit-on-first-char'\n\
9323 for guidance on what to do.");
9324 Vinput_method_function
= Qnil
;
9326 DEFVAR_LISP ("input-method-previous-message",
9327 &Vinput_method_previous_message
,
9328 "When `input-mehod-function' is called, hold the previous echo area message.\n\
9329 This variable exists because `read-event' clears the echo area\n\
9330 before running the input method. It is nil if there was no message.");
9331 Vinput_method_previous_message
= Qnil
;
9337 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
9338 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
9339 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
9340 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
9341 initial_define_key (meta_map
, 'x', "execute-extended-command");
9343 initial_define_lispy_key (Vspecial_event_map
, "delete-frame",
9344 "handle-delete-frame");
9345 initial_define_lispy_key (Vspecial_event_map
, "iconify-frame",
9347 initial_define_lispy_key (Vspecial_event_map
, "make-frame-visible",