1 /* Keyboard and mouse input; editor command loop.
2 Copyright (C) 1985,86,87,88,89,93,94,95,96,97,99, 2000
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
28 #include "termhooks.h"
36 #include "dispextern.h"
39 #include "intervals.h"
40 #include "blockinput.h"
52 #include <sys/ioctl.h>
54 #endif /* not MSDOS */
56 #include "syssignal.h"
59 #include <sys/types.h>
64 /* This is to get the definitions of the XK_ symbols. */
71 #endif /* HAVE_NTGUI */
73 /* Include systime.h after xterm.h to avoid double inclusion of time.h. */
78 /* Variables for blockinput.h: */
80 /* Non-zero if interrupt input is blocked right now. */
81 int interrupt_input_blocked
;
83 /* Nonzero means an input interrupt has arrived
84 during the current critical section. */
85 int interrupt_input_pending
;
88 /* File descriptor to use for input. */
91 #ifdef HAVE_WINDOW_SYSTEM
92 /* Make all keyboard buffers much bigger when using X windows. */
94 /* But not too big (local data > 32K error) if on macintosh */
95 #define KBD_BUFFER_SIZE 512
97 #define KBD_BUFFER_SIZE 4096
99 #else /* No X-windows, character input */
100 #define KBD_BUFFER_SIZE 256
101 #endif /* No X-windows */
103 /* Following definition copied from eval.c */
107 struct backtrace
*next
;
108 Lisp_Object
*function
;
109 Lisp_Object
*args
; /* Points to vector of args. */
110 int nargs
; /* length of vector. If nargs is UNEVALLED,
111 args points to slot holding list of
117 KBOARD
*initial_kboard
;
118 KBOARD
*current_kboard
;
122 KBOARD the_only_kboard
;
125 /* Non-nil disable property on a command means
126 do not execute it; call disabled-command-hook's value instead. */
127 Lisp_Object Qdisabled
, Qdisabled_command_hook
;
129 #define NUM_RECENT_KEYS (100)
130 int recent_keys_index
; /* Index for storing next element into recent_keys */
131 int total_keys
; /* Total number of elements stored into recent_keys */
132 Lisp_Object recent_keys
; /* A vector, holding the last 100 keystrokes */
134 /* Vector holding the key sequence that invoked the current command.
135 It is reused for each command, and it may be longer than the current
136 sequence; this_command_key_count indicates how many elements
137 actually mean something.
138 It's easier to staticpro a single Lisp_Object than an array. */
139 Lisp_Object this_command_keys
;
140 int this_command_key_count
;
142 /* This vector is used as a buffer to record the events that were actually read
143 by read_key_sequence. */
144 Lisp_Object raw_keybuf
;
145 int raw_keybuf_count
;
147 #define GROW_RAW_KEYBUF \
148 if (raw_keybuf_count == XVECTOR (raw_keybuf)->size) \
150 int newsize = 2 * XVECTOR (raw_keybuf)->size; \
152 new = Fmake_vector (make_number (newsize), Qnil); \
153 bcopy (XVECTOR (raw_keybuf)->contents, XVECTOR (new)->contents, \
154 raw_keybuf_count * sizeof (Lisp_Object)); \
158 /* Number of elements of this_command_keys
159 that precede this key sequence. */
160 int this_single_command_key_start
;
162 /* Record values of this_command_key_count and echo_length ()
163 before this command was read. */
164 static int before_command_key_count
;
165 static int before_command_echo_length
;
166 /* Values of before_command_key_count and before_command_echo_length
167 saved by reset-this-command-lengths. */
168 static int before_command_key_count_1
;
169 static int before_command_echo_length_1
;
170 /* Flag set by reset-this-command-lengths,
171 saying to reset the lengths when add_command_key is called. */
172 static int before_command_restore_flag
;
174 extern int minbuf_level
;
176 extern int message_enable_multibyte
;
178 extern struct backtrace
*backtrace_list
;
180 /* If non-nil, the function that implements the display of help.
181 It's called with one argument, the help string to display. */
183 Lisp_Object Vshow_help_function
;
185 /* Nonzero means do menu prompting. */
186 static int menu_prompting
;
188 /* Character to see next line of menu prompt. */
189 static Lisp_Object menu_prompt_more_char
;
191 /* For longjmp to where kbd input is being done. */
192 static jmp_buf getcjmp
;
194 /* True while doing kbd input. */
195 int waiting_for_input
;
197 /* True while displaying for echoing. Delays C-g throwing. */
201 /* Non-null means we can start echoing at the next input pause even
202 though there is something in the echo area. */
204 static struct kboard
*ok_to_echo_at_next_pause
;
206 /* The kboard last echoing, or null for none. Reset to 0 in
207 cancel_echoing. If non-null, and a current echo area message
208 exists, and echo_message_buffer is eq to the current message
209 buffer, we know that the message comes from echo_kboard. */
211 static struct kboard
*echo_kboard
;
213 /* The buffer used for echoing. Set in echo_now, reset in
216 static Lisp_Object echo_message_buffer
;
218 /* Nonzero means disregard local maps for the menu bar. */
219 static int inhibit_local_menu_bar_menus
;
221 /* Nonzero means C-g should cause immediate error-signal. */
224 /* The user's ERASE setting. */
225 Lisp_Object Vtty_erase_char
;
227 /* Character to recognize as the help char. */
228 Lisp_Object Vhelp_char
;
230 /* List of other event types to recognize as meaning "help". */
231 Lisp_Object Vhelp_event_list
;
233 /* Form to execute when help char is typed. */
234 Lisp_Object Vhelp_form
;
236 /* Command to run when the help character follows a prefix key. */
237 Lisp_Object Vprefix_help_command
;
239 /* List of items that should move to the end of the menu bar. */
240 Lisp_Object Vmenu_bar_final_items
;
242 /* Non-nil means show the equivalent key-binding for
243 any M-x command that has one.
244 The value can be a length of time to show the message for.
245 If the value is non-nil and not a number, we wait 2 seconds. */
246 Lisp_Object Vsuggest_key_bindings
;
248 /* Character that causes a quit. Normally C-g.
250 If we are running on an ordinary terminal, this must be an ordinary
251 ASCII char, since we want to make it our interrupt character.
253 If we are not running on an ordinary terminal, it still needs to be
254 an ordinary ASCII char. This character needs to be recognized in
255 the input interrupt handler. At this point, the keystroke is
256 represented as a struct input_event, while the desired quit
257 character is specified as a lispy event. The mapping from struct
258 input_events to lispy events cannot run in an interrupt handler,
259 and the reverse mapping is difficult for anything but ASCII
262 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
266 extern Lisp_Object current_global_map
;
267 extern int minibuf_level
;
269 /* If non-nil, this is a map that overrides all other local maps. */
270 Lisp_Object Voverriding_local_map
;
272 /* If non-nil, Voverriding_local_map applies to the menu bar. */
273 Lisp_Object Voverriding_local_map_menu_flag
;
275 /* Keymap that defines special misc events that should
276 be processed immediately at a low level. */
277 Lisp_Object Vspecial_event_map
;
279 /* Current depth in recursive edits. */
280 int command_loop_level
;
282 /* Total number of times command_loop has read a key sequence. */
285 /* Last input character read as a command. */
286 Lisp_Object last_command_char
;
288 /* Last input character read as a command, not counting menus
289 reached by the mouse. */
290 Lisp_Object last_nonmenu_event
;
292 /* Last input character read for any purpose. */
293 Lisp_Object last_input_char
;
295 /* If not Qnil, a list of objects to be read as subsequent command input. */
296 Lisp_Object Vunread_command_events
;
298 /* If not Qnil, a list of objects to be read as subsequent command input
299 including input method processing. */
300 Lisp_Object Vunread_input_method_events
;
302 /* If not Qnil, a list of objects to be read as subsequent command input
303 but NOT including input method processing. */
304 Lisp_Object Vunread_post_input_method_events
;
306 /* If not -1, an event to be read as subsequent command input. */
307 int unread_command_char
;
309 /* If not Qnil, this is a switch-frame event which we decided to put
310 off until the end of a key sequence. This should be read as the
311 next command input, after any unread_command_events.
313 read_key_sequence uses this to delay switch-frame events until the
314 end of the key sequence; Fread_char uses it to put off switch-frame
315 events until a non-ASCII event is acceptable as input. */
316 Lisp_Object unread_switch_frame
;
318 /* A mask of extra modifier bits to put into every keyboard char. */
319 int extra_keyboard_modifiers
;
321 /* Char to use as prefix when a meta character is typed in.
322 This is bound on entry to minibuffer in case ESC is changed there. */
324 Lisp_Object meta_prefix_char
;
326 /* Last size recorded for a current buffer which is not a minibuffer. */
327 static int last_non_minibuf_size
;
329 /* Number of idle seconds before an auto-save and garbage collection. */
330 static Lisp_Object Vauto_save_timeout
;
332 /* Total number of times read_char has returned. */
333 int num_input_events
;
335 /* Total number of times read_char has returned, outside of macros. */
336 int num_nonmacro_input_events
;
338 /* Auto-save automatically when this many characters have been typed
339 since the last time. */
341 static int auto_save_interval
;
343 /* Value of num_nonmacro_input_events as of last auto save. */
347 /* The command being executed by the command loop.
348 Commands may set this, and the value set will be copied into
349 current_kboard->Vlast_command instead of the actual command. */
350 Lisp_Object Vthis_command
;
352 /* This is like Vthis_command, except that commands never set it. */
353 Lisp_Object real_this_command
;
355 /* The value of point when the last command was executed. */
356 int last_point_position
;
358 /* The buffer that was current when the last command was started. */
359 Lisp_Object last_point_position_buffer
;
361 /* The frame in which the last input event occurred, or Qmacro if the
362 last event came from a macro. We use this to determine when to
363 generate switch-frame events. This may be cleared by functions
364 like Fselect_frame, to make sure that a switch-frame event is
365 generated by the next character. */
366 Lisp_Object internal_last_event_frame
;
368 /* A user-visible version of the above, intended to allow users to
369 figure out where the last event came from, if the event doesn't
370 carry that information itself (i.e. if it was a character). */
371 Lisp_Object Vlast_event_frame
;
373 /* The timestamp of the last input event we received from the X server.
374 X Windows wants this for selection ownership. */
375 unsigned long last_event_timestamp
;
377 Lisp_Object Qself_insert_command
;
378 Lisp_Object Qforward_char
;
379 Lisp_Object Qbackward_char
;
380 Lisp_Object Qundefined
;
381 Lisp_Object Qtimer_event_handler
;
383 /* read_key_sequence stores here the command definition of the
384 key sequence that it reads. */
385 Lisp_Object read_key_sequence_cmd
;
387 /* Echo unfinished commands after this many seconds of pause. */
388 Lisp_Object Vecho_keystrokes
;
390 /* Form to evaluate (if non-nil) when Emacs is started. */
391 Lisp_Object Vtop_level
;
393 /* User-supplied string to translate input characters through. */
394 Lisp_Object Vkeyboard_translate_table
;
396 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
397 extern Lisp_Object Vfunction_key_map
;
399 /* Another keymap that maps key sequences into key sequences.
400 This one takes precedence over ordinary definitions. */
401 extern Lisp_Object Vkey_translation_map
;
403 /* If non-nil, this implements the current input method. */
404 Lisp_Object Vinput_method_function
;
405 Lisp_Object Qinput_method_function
;
407 /* When we call Vinput_method_function,
408 this holds the echo area message that was just erased. */
409 Lisp_Object Vinput_method_previous_message
;
411 /* Non-nil means deactivate the mark at end of this command. */
412 Lisp_Object Vdeactivate_mark
;
414 /* Menu bar specified in Lucid Emacs fashion. */
416 Lisp_Object Vlucid_menu_bar_dirty_flag
;
417 Lisp_Object Qrecompute_lucid_menubar
, Qactivate_menubar_hook
;
419 Lisp_Object Qecho_area_clear_hook
;
421 /* Hooks to run before and after each command. */
422 Lisp_Object Qpre_command_hook
, Vpre_command_hook
;
423 Lisp_Object Qpost_command_hook
, Vpost_command_hook
;
424 Lisp_Object Qcommand_hook_internal
, Vcommand_hook_internal
;
425 /* Hook run after a command if there's no more input soon. */
426 Lisp_Object Qpost_command_idle_hook
, Vpost_command_idle_hook
;
428 /* Delay time in microseconds before running post-command-idle-hook. */
429 int post_command_idle_delay
;
431 /* List of deferred actions to be performed at a later time.
432 The precise format isn't relevant here; we just check whether it is nil. */
433 Lisp_Object Vdeferred_action_list
;
435 /* Function to call to handle deferred actions, when there are any. */
436 Lisp_Object Vdeferred_action_function
;
437 Lisp_Object Qdeferred_action_function
;
439 Lisp_Object Qinput_method_exit_on_first_char
;
440 Lisp_Object Qinput_method_use_echo_area
;
442 /* File in which we write all commands we read. */
445 /* Nonzero if input is available. */
448 /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
449 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
453 extern char *pending_malloc_warning
;
455 /* Circular buffer for pre-read keyboard input. */
456 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
458 /* Vector to GCPRO the frames and windows mentioned in kbd_buffer.
460 The interrupt-level event handlers will never enqueue an event on a
461 frame which is not in Vframe_list, and once an event is dequeued,
462 internal_last_event_frame or the event itself points to the frame.
465 But while the event is sitting in the queue, it's completely
466 unprotected. Suppose the user types one command which will run for
467 a while and then delete a frame, and then types another event at
468 the frame that will be deleted, before the command gets around to
469 it. Suppose there are no references to this frame elsewhere in
470 Emacs, and a GC occurs before the second event is dequeued. Now we
471 have an event referring to a freed frame, which will crash Emacs
474 Similar things happen when an event on a scroll bar is enqueued; the
475 window may be deleted while the event is in the queue.
477 So, we use this vector to protect the frame_or_window field in the
478 event queue. That way, they'll be dequeued as dead frames or
479 windows, but still valid lisp objects.
481 If kbd_buffer[i].kind != no_event, then
482 (XVECTOR (kbd_buffer_frame_or_window)->contents[i]
483 == kbd_buffer[i].frame_or_window. */
484 static Lisp_Object kbd_buffer_frame_or_window
;
486 /* Pointer to next available character in kbd_buffer.
487 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
488 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the
489 next available char is in kbd_buffer[0]. */
490 static struct input_event
*kbd_fetch_ptr
;
492 /* Pointer to next place to store character in kbd_buffer. This
493 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
494 character should go in kbd_buffer[0]. */
495 static struct input_event
* volatile kbd_store_ptr
;
497 /* The above pair of variables forms a "queue empty" flag. When we
498 enqueue a non-hook event, we increment kbd_store_ptr. When we
499 dequeue a non-hook event, we increment kbd_fetch_ptr. We say that
500 there is input available iff the two pointers are not equal.
502 Why not just have a flag set and cleared by the enqueuing and
503 dequeuing functions? Such a flag could be screwed up by interrupts
504 at inopportune times. */
506 /* If this flag is non-nil, we check mouse_moved to see when the
507 mouse moves, and motion events will appear in the input stream.
508 Otherwise, mouse motion is ignored. */
509 static Lisp_Object do_mouse_tracking
;
511 /* Symbols to head events. */
512 Lisp_Object Qmouse_movement
;
513 Lisp_Object Qscroll_bar_movement
;
514 Lisp_Object Qswitch_frame
;
515 Lisp_Object Qdelete_frame
;
516 Lisp_Object Qiconify_frame
;
517 Lisp_Object Qmake_frame_visible
;
518 Lisp_Object Qhelp_echo
;
520 /* Symbols to denote kinds of events. */
521 Lisp_Object Qfunction_key
;
522 Lisp_Object Qmouse_click
;
524 Lisp_Object Qmouse_wheel
;
525 Lisp_Object Qlanguage_change
;
527 Lisp_Object Qdrag_n_drop
;
528 /* Lisp_Object Qmouse_movement; - also an event header */
530 /* Properties of event headers. */
531 Lisp_Object Qevent_kind
;
532 Lisp_Object Qevent_symbol_elements
;
534 /* menu item parts */
535 Lisp_Object Qmenu_alias
;
536 Lisp_Object Qmenu_enable
;
537 Lisp_Object QCenable
, QCvisible
, QChelp
, QCfilter
, QCkeys
, QCkey_sequence
;
538 Lisp_Object QCbutton
, QCtoggle
, QCradio
;
539 extern Lisp_Object Vdefine_key_rebound_commands
;
540 extern Lisp_Object Qmenu_item
;
542 /* An event header symbol HEAD may have a property named
543 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
544 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
545 mask of modifiers applied to it. If present, this is used to help
546 speed up parse_modifiers. */
547 Lisp_Object Qevent_symbol_element_mask
;
549 /* An unmodified event header BASE may have a property named
550 Qmodifier_cache, which is an alist mapping modifier masks onto
551 modified versions of BASE. If present, this helps speed up
553 Lisp_Object Qmodifier_cache
;
555 /* Symbols to use for parts of windows. */
556 Lisp_Object Qmode_line
;
557 Lisp_Object Qvertical_line
;
558 Lisp_Object Qvertical_scroll_bar
;
559 Lisp_Object Qmenu_bar
;
561 Lisp_Object
recursive_edit_unwind (), command_loop ();
562 Lisp_Object
Fthis_command_keys ();
563 Lisp_Object Qextended_command_history
;
564 EMACS_TIME
timer_check ();
566 extern Lisp_Object Vhistory_length
;
568 extern char *x_get_keysym_name ();
570 static void record_menu_key ();
572 Lisp_Object Qpolling_period
;
574 /* List of absolute timers. Appears in order of next scheduled event. */
575 Lisp_Object Vtimer_list
;
577 /* List of idle time timers. Appears in order of next scheduled event. */
578 Lisp_Object Vtimer_idle_list
;
580 /* Incremented whenever a timer is run. */
583 extern Lisp_Object Vprint_level
, Vprint_length
;
585 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
587 EMACS_TIME
*input_available_clear_time
;
589 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
590 Default is 1 if INTERRUPT_INPUT is defined. */
593 /* Nonzero while interrupts are temporarily deferred during redisplay. */
594 int interrupts_deferred
;
596 /* Nonzero means use ^S/^Q for flow control. */
599 /* Allow m- file to inhibit use of FIONREAD. */
600 #ifdef BROKEN_FIONREAD
604 /* We are unable to use interrupts if FIONREAD is not available,
605 so flush SIGIO so we won't try. */
612 /* If we support a window system, turn on the code to poll periodically
613 to detect C-g. It isn't actually used when doing interrupt input. */
614 #ifdef HAVE_WINDOW_SYSTEM
615 #define POLL_FOR_INPUT
618 /* After a command is executed, if point is moved into a region that
619 has specific properties (e.g. composition, display), we adjust
620 point to the boundary of the region. But, if a command sets this
621 valiable to non-nil, we suppress this point adjustment. This
622 variable is set to nil before reading a command. */
623 Lisp_Object Vdisable_point_adjustment
;
625 /* If non-nil, always disable point adjustment. */
626 Lisp_Object Vglobal_disable_point_adjustment
;
629 /* Global variable declarations. */
631 /* Function for init_keyboard to call with no args (if nonzero). */
632 void (*keyboard_init_hook
) ();
634 static int read_avail_input ();
635 static void get_input_pending ();
636 static int readable_events ();
637 static Lisp_Object
read_char_x_menu_prompt ();
638 static Lisp_Object
read_char_minibuf_menu_prompt ();
639 static Lisp_Object
make_lispy_event ();
641 static Lisp_Object
make_lispy_movement ();
643 static Lisp_Object
modify_event_symbol ();
644 static Lisp_Object
make_lispy_switch_frame ();
645 static int parse_solitary_modifier ();
646 static void save_getcjmp ();
647 static void restore_getcjmp ();
648 static Lisp_Object apply_modifiers
P_ ((int, Lisp_Object
));
650 /* Nonzero means don't try to suspend even if the operating system seems
652 static int cannot_suspend
;
654 #define min(a,b) ((a)<(b)?(a):(b))
655 #define max(a,b) ((a)>(b)?(a):(b))
657 /* Install the string STR as the beginning of the string of echoing,
658 so that it serves as a prompt for the next character.
659 Also start echoing. */
665 int len
= strlen (str
);
667 if (len
> ECHOBUFSIZE
- 4)
668 len
= ECHOBUFSIZE
- 4;
669 bcopy (str
, current_kboard
->echobuf
, len
);
670 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
671 *current_kboard
->echoptr
= '\0';
673 current_kboard
->echo_after_prompt
= len
;
678 /* Add C to the echo string, if echoing is going on.
679 C can be a character, which is printed prettily ("M-C-x" and all that
680 jazz), or a symbol, whose name is printed. */
686 extern char *push_key_description ();
688 if (current_kboard
->immediate_echo
)
690 char *ptr
= current_kboard
->echoptr
;
692 if (ptr
!= current_kboard
->echobuf
)
695 /* If someone has passed us a composite event, use its head symbol. */
700 if (ptr
- current_kboard
->echobuf
701 > ECHOBUFSIZE
- KEY_DESCRIPTION_SIZE
)
704 ptr
= push_key_description (XINT (c
), ptr
);
706 else if (SYMBOLP (c
))
708 struct Lisp_String
*name
= XSYMBOL (c
)->name
;
709 if ((ptr
- current_kboard
->echobuf
) + STRING_BYTES (name
) + 4
712 bcopy (name
->data
, ptr
, STRING_BYTES (name
));
713 ptr
+= STRING_BYTES (name
);
716 if (current_kboard
->echoptr
== current_kboard
->echobuf
719 strcpy (ptr
, " (Type ? for further options)");
724 current_kboard
->echoptr
= ptr
;
730 /* Temporarily add a dash to the end of the echo string if it's not
731 empty, so that it serves as a mini-prompt for the very next character. */
736 if (!current_kboard
->immediate_echo
737 && current_kboard
->echoptr
== current_kboard
->echobuf
)
739 /* Do nothing if we just printed a prompt. */
740 if (current_kboard
->echo_after_prompt
741 == current_kboard
->echoptr
- current_kboard
->echobuf
)
743 /* Do nothing if not echoing at all. */
744 if (current_kboard
->echoptr
== 0)
747 /* Put a dash at the end of the buffer temporarily,
748 but make it go away when the next character is added. */
749 current_kboard
->echoptr
[0] = '-';
750 current_kboard
->echoptr
[1] = 0;
755 /* Display the current echo string, and begin echoing if not already
761 if (!current_kboard
->immediate_echo
)
764 current_kboard
->immediate_echo
= 1;
766 for (i
= 0; i
< this_command_key_count
; i
++)
769 c
= XVECTOR (this_command_keys
)->contents
[i
];
770 if (! (EVENT_HAS_PARAMETERS (c
)
771 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
778 message2_nolog (current_kboard
->echobuf
, strlen (current_kboard
->echobuf
),
779 ! NILP (current_buffer
->enable_multibyte_characters
));
782 /* Record in what buffer we echoed, and from which kboard. */
783 echo_message_buffer
= echo_area_buffer
[0];
784 echo_kboard
= current_kboard
;
786 if (waiting_for_input
&& !NILP (Vquit_flag
))
787 quit_throw_to_read_char ();
790 /* Turn off echoing, for the start of a new command. */
795 current_kboard
->immediate_echo
= 0;
796 current_kboard
->echoptr
= current_kboard
->echobuf
;
797 current_kboard
->echo_after_prompt
= -1;
798 ok_to_echo_at_next_pause
= NULL
;
800 echo_message_buffer
= Qnil
;
803 /* Return the length of the current echo string. */
808 return current_kboard
->echoptr
- current_kboard
->echobuf
;
811 /* Truncate the current echo message to its first LEN chars.
812 This and echo_char get used by read_key_sequence when the user
813 switches frames while entering a key sequence. */
819 current_kboard
->echobuf
[len
] = '\0';
820 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
821 truncate_echo_area (len
);
825 /* Functions for manipulating this_command_keys. */
827 add_command_key (key
)
830 int size
= XVECTOR (this_command_keys
)->size
;
832 /* If reset-this-command-length was called recently, obey it now.
833 See the doc string of that function for an explanation of why. */
834 if (before_command_restore_flag
)
836 this_command_key_count
= before_command_key_count_1
;
837 if (this_command_key_count
< this_single_command_key_start
)
838 this_single_command_key_start
= this_command_key_count
;
839 echo_truncate (before_command_echo_length_1
);
840 before_command_restore_flag
= 0;
843 if (this_command_key_count
>= size
)
845 Lisp_Object new_keys
;
847 new_keys
= Fmake_vector (make_number (size
* 2), Qnil
);
848 bcopy (XVECTOR (this_command_keys
)->contents
,
849 XVECTOR (new_keys
)->contents
,
850 size
* sizeof (Lisp_Object
));
852 this_command_keys
= new_keys
;
855 XVECTOR (this_command_keys
)->contents
[this_command_key_count
++] = key
;
861 int count
= specpdl_ptr
- specpdl
;
864 if (command_loop_level
> 0)
866 specbind (Qstandard_output
, Qt
);
867 specbind (Qstandard_input
, Qt
);
870 #ifdef HAVE_X_WINDOWS
871 /* The command loop has started a busy-cursor timer, so we have to
872 cancel it here, otherwise it will fire because the recursive edit
873 can take some time. */
874 if (display_busy_cursor_p
)
875 cancel_busy_cursor ();
878 val
= command_loop ();
880 Fsignal (Qquit
, Qnil
);
881 /* Handle throw from read_minibuf when using minibuffer
882 while it's active but we're in another window. */
884 Fsignal (Qerror
, Fcons (val
, Qnil
));
886 return unbind_to (count
, Qnil
);
889 /* When an auto-save happens, record the "time", and don't do again soon. */
894 last_auto_save
= num_nonmacro_input_events
;
897 /* Make an auto save happen as soon as possible at command level. */
900 force_auto_save_soon ()
902 last_auto_save
= - auto_save_interval
- 1;
904 record_asynch_buffer_change ();
907 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
908 "Invoke the editor command loop recursively.\n\
909 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
910 that tells this function to return.\n\
911 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
912 This function is called by the editor initialization to begin editing.")
915 int count
= specpdl_ptr
- specpdl
;
917 command_loop_level
++;
918 update_mode_lines
= 1;
920 record_unwind_protect (recursive_edit_unwind
,
922 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
926 return unbind_to (count
, Qnil
);
930 recursive_edit_unwind (buffer
)
934 Fset_buffer (buffer
);
936 command_loop_level
--;
937 update_mode_lines
= 1;
945 #if 0 /* Theory: if there's anything in Vunread_command_events,
946 it will right away be read by read_key_sequence,
947 and then if we do switch KBOARDS, it will go into the side
948 queue then. So we don't need to do anything special here -- rms. */
949 if (CONSP (Vunread_command_events
))
951 current_kboard
->kbd_queue
952 = nconc2 (Vunread_command_events
, current_kboard
->kbd_queue
);
953 current_kboard
->kbd_queue_has_data
= 1;
955 Vunread_command_events
= Qnil
;
961 /* Switch to the single-kboard state, making current_kboard
962 the only KBOARD from which further input is accepted. */
965 single_kboard_state ()
972 /* Maintain a stack of kboards, so other parts of Emacs
973 can switch temporarily to the kboard of a given frame
974 and then revert to the previous status. */
979 struct kboard_stack
*next
;
982 static struct kboard_stack
*kboard_stack
;
985 push_frame_kboard (f
)
989 struct kboard_stack
*p
990 = (struct kboard_stack
*) xmalloc (sizeof (struct kboard_stack
));
992 p
->next
= kboard_stack
;
993 p
->kboard
= current_kboard
;
996 current_kboard
= FRAME_KBOARD (f
);
1004 struct kboard_stack
*p
= kboard_stack
;
1005 current_kboard
= p
->kboard
;
1006 kboard_stack
= p
->next
;
1011 /* Handle errors that are not handled at inner levels
1012 by printing an error message and returning to the editor command loop. */
1018 Lisp_Object old_level
, old_length
;
1019 char macroerror
[50];
1021 if (!NILP (executing_macro
))
1023 if (executing_macro_iterations
== 1)
1024 sprintf (macroerror
, "After 1 kbd macro iteration: ");
1026 sprintf (macroerror
, "After %d kbd macro iterations: ",
1027 executing_macro_iterations
);
1032 Vstandard_output
= Qt
;
1033 Vstandard_input
= Qt
;
1034 Vexecuting_macro
= Qnil
;
1035 executing_macro
= Qnil
;
1036 current_kboard
->Vprefix_arg
= Qnil
;
1037 current_kboard
->Vlast_prefix_arg
= Qnil
;
1040 /* Avoid unquittable loop if data contains a circular list. */
1041 old_level
= Vprint_level
;
1042 old_length
= Vprint_length
;
1043 XSETFASTINT (Vprint_level
, 10);
1044 XSETFASTINT (Vprint_length
, 10);
1045 cmd_error_internal (data
, macroerror
);
1046 Vprint_level
= old_level
;
1047 Vprint_length
= old_length
;
1051 Vinhibit_quit
= Qnil
;
1053 any_kboard_state ();
1056 return make_number (0);
1059 /* Take actions on handling an error. DATA is the data that describes
1062 CONTEXT is a C-string containing ASCII characters only which
1063 describes the context in which the error happened. If we need to
1064 generalize CONTEXT to allow multibyte characters, make it a Lisp
1068 cmd_error_internal (data
, context
)
1073 int kill_emacs_p
= 0;
1074 struct frame
*sf
= SELECTED_FRAME ();
1078 clear_message (1, 0);
1080 /* If the window system or terminal frame hasn't been initialized
1081 yet, or we're not interactive, it's best to dump this message out
1082 to stderr and exit. */
1083 if (!sf
->glyphs_initialized_p
1084 /* This is the case of the frame dumped with Emacs, when we're
1085 running under a window system. */
1086 || (!NILP (Vwindow_system
)
1087 && !inhibit_window_system
1088 && FRAME_TERMCAP_P (sf
))
1091 stream
= Qexternal_debugging_output
;
1102 write_string_1 (context
, -1, stream
);
1104 print_error_message (data
, stream
);
1106 /* If the window system or terminal frame hasn't been initialized
1107 yet, or we're in -batch mode, this error should cause Emacs to exit. */
1111 Fkill_emacs (make_number (-1));
1115 Lisp_Object
command_loop_1 ();
1116 Lisp_Object
command_loop_2 ();
1117 Lisp_Object
top_level_1 ();
1119 /* Entry to editor-command-loop.
1120 This level has the catches for exiting/returning to editor command loop.
1121 It returns nil to exit recursive edit, t to abort it. */
1126 if (command_loop_level
> 0 || minibuf_level
> 0)
1129 val
= internal_catch (Qexit
, command_loop_2
, Qnil
);
1130 executing_macro
= Qnil
;
1136 internal_catch (Qtop_level
, top_level_1
, Qnil
);
1137 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
1138 executing_macro
= Qnil
;
1140 /* End of file in -batch run causes exit here. */
1146 /* Here we catch errors in execution of commands within the
1147 editing loop, and reenter the editing loop.
1148 When there is an error, cmd_error runs and returns a non-nil
1149 value to us. A value of nil means that cmd_loop_1 itself
1150 returned due to end of file (or end of kbd macro). */
1155 register Lisp_Object val
;
1158 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
1159 while (!NILP (val
));
1167 return Feval (Vtop_level
);
1173 /* On entry to the outer level, run the startup file */
1174 if (!NILP (Vtop_level
))
1175 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
1176 else if (!NILP (Vpurify_flag
))
1177 message ("Bare impure Emacs (standard Lisp code not loaded)");
1179 message ("Bare Emacs (standard Lisp code not loaded)");
1183 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
1184 "Exit all recursive editing levels.")
1187 #ifdef HAVE_X_WINDOWS
1188 if (display_busy_cursor_p
)
1189 cancel_busy_cursor ();
1191 Fthrow (Qtop_level
, Qnil
);
1194 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
1195 "Exit from the innermost recursive edit or minibuffer.")
1198 if (command_loop_level
> 0 || minibuf_level
> 0)
1199 Fthrow (Qexit
, Qnil
);
1201 error ("No recursive edit is in progress");
1204 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
1205 "Abort the command that requested this recursive edit or minibuffer input.")
1208 if (command_loop_level
> 0 || minibuf_level
> 0)
1211 error ("No recursive edit is in progress");
1214 /* This is the actual command reading loop,
1215 sans error-handling encapsulation. */
1217 Lisp_Object
Fcommand_execute ();
1218 static int read_key_sequence ();
1219 void safe_run_hooks ();
1220 static void adjust_point_for_property ();
1228 Lisp_Object keybuf
[30];
1232 struct buffer
*prev_buffer
;
1234 int was_locked
= single_kboard
;
1237 current_kboard
->Vprefix_arg
= Qnil
;
1238 current_kboard
->Vlast_prefix_arg
= Qnil
;
1239 Vdeactivate_mark
= Qnil
;
1240 waiting_for_input
= 0;
1244 this_command_key_count
= 0;
1245 this_single_command_key_start
= 0;
1247 /* Make sure this hook runs after commands that get errors and
1248 throw to top level. */
1249 /* Note that the value cell will never directly contain nil
1250 if the symbol is a local variable. */
1251 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1252 safe_run_hooks (Qpost_command_hook
);
1254 /* If displaying a message, resize the echo area window to fit
1255 that message's size exactly. */
1256 if (!NILP (echo_area_buffer
[0]))
1257 resize_echo_area_axactly ();
1259 if (!NILP (Vdeferred_action_list
))
1260 call0 (Vdeferred_action_function
);
1262 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1264 if (NILP (Vunread_command_events
)
1265 && NILP (Vunread_input_method_events
)
1266 && NILP (Vunread_post_input_method_events
)
1267 && NILP (Vexecuting_macro
)
1268 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1, 1)))
1269 safe_run_hooks (Qpost_command_idle_hook
);
1272 /* Do this after running Vpost_command_hook, for consistency. */
1273 current_kboard
->Vlast_command
= Vthis_command
;
1274 current_kboard
->Vreal_last_command
= real_this_command
;
1278 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
1281 /* Make sure the current window's buffer is selected. */
1282 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1283 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1285 /* Display any malloc warning that just came out. Use while because
1286 displaying one warning can cause another. */
1288 while (pending_malloc_warning
)
1289 display_malloc_warning ();
1293 Vdeactivate_mark
= Qnil
;
1295 /* If minibuffer on and echo area in use,
1296 wait 2 sec and redraw minibuffer. */
1299 && !NILP (echo_area_buffer
[0])
1300 && EQ (minibuf_window
, echo_area_window
))
1302 /* Bind inhibit-quit to t so that C-g gets read in
1303 rather than quitting back to the minibuffer. */
1304 int count
= specpdl_ptr
- specpdl
;
1305 specbind (Qinhibit_quit
, Qt
);
1307 Fsit_for (make_number (2), Qnil
, Qnil
);
1308 /* Clear the echo area. */
1310 safe_run_hooks (Qecho_area_clear_hook
);
1312 unbind_to (count
, Qnil
);
1314 /* If a C-g came in before, treat it as input now. */
1315 if (!NILP (Vquit_flag
))
1318 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1323 alloca (0); /* Cause a garbage collection now */
1324 /* Since we can free the most stuff here. */
1325 #endif /* C_ALLOCA */
1328 /* Select the frame that the last event came from. Usually,
1329 switch-frame events will take care of this, but if some lisp
1330 code swallows a switch-frame event, we'll fix things up here.
1331 Is this a good idea? */
1332 if (FRAMEP (internal_last_event_frame
)
1333 && !EQ (internal_last_event_frame
, selected_frame
))
1334 Fselect_frame (internal_last_event_frame
, Qnil
);
1336 /* If it has changed current-menubar from previous value,
1337 really recompute the menubar from the value. */
1338 if (! NILP (Vlucid_menu_bar_dirty_flag
)
1339 && !NILP (Ffboundp (Qrecompute_lucid_menubar
)))
1340 call0 (Qrecompute_lucid_menubar
);
1342 before_command_key_count
= this_command_key_count
;
1343 before_command_echo_length
= echo_length ();
1345 Vthis_command
= Qnil
;
1346 real_this_command
= Qnil
;
1348 /* Read next key sequence; i gets its length. */
1349 i
= read_key_sequence (keybuf
, sizeof keybuf
/ sizeof keybuf
[0],
1352 /* A filter may have run while we were reading the input. */
1353 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
1355 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1356 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1360 /* Now we have read a key sequence of length I,
1361 or else I is 0 and we found end of file. */
1363 if (i
== 0) /* End of file -- happens only in */
1364 return Qnil
; /* a kbd macro, at the end. */
1365 /* -1 means read_key_sequence got a menu that was rejected.
1366 Just loop around and read another command. */
1370 this_command_key_count
= 0;
1371 this_single_command_key_start
= 0;
1375 last_command_char
= keybuf
[i
- 1];
1377 /* If the previous command tried to force a specific window-start,
1378 forget about that, in case this command moves point far away
1379 from that position. But also throw away beg_unchanged and
1380 end_unchanged information in that case, so that redisplay will
1381 update the whole window properly. */
1382 if (!NILP (XWINDOW (selected_window
)->force_start
))
1385 XWINDOW (selected_window
)->force_start
= Qnil
;
1386 b
= XBUFFER (XWINDOW (selected_window
)->buffer
);
1387 BUF_BEG_UNCHANGED (b
) = BUF_END_UNCHANGED (b
) = 0;
1390 cmd
= read_key_sequence_cmd
;
1391 if (!NILP (Vexecuting_macro
))
1393 if (!NILP (Vquit_flag
))
1395 Vexecuting_macro
= Qt
;
1396 QUIT
; /* Make some noise. */
1397 /* Will return since macro now empty. */
1401 /* Do redisplay processing after this command except in special
1402 cases identified below. */
1403 prev_buffer
= current_buffer
;
1404 prev_modiff
= MODIFF
;
1405 last_point_position
= PT
;
1406 XSETBUFFER (last_point_position_buffer
, prev_buffer
);
1408 /* By default, we adjust point to a boundary of a region that
1409 has such a property that should be treated intangible
1410 (e.g. composition, display). But, some commands will set
1411 this variable differently. */
1412 Vdisable_point_adjustment
= Qnil
;
1414 /* Execute the command. */
1416 Vthis_command
= cmd
;
1417 real_this_command
= cmd
;
1418 /* Note that the value cell will never directly contain nil
1419 if the symbol is a local variable. */
1420 if (!NILP (Vpre_command_hook
) && !NILP (Vrun_hooks
))
1421 safe_run_hooks (Qpre_command_hook
);
1423 if (NILP (Vthis_command
))
1425 /* nil means key is undefined. */
1427 current_kboard
->defining_kbd_macro
= Qnil
;
1428 update_mode_lines
= 1;
1429 current_kboard
->Vprefix_arg
= Qnil
;
1433 if (NILP (current_kboard
->Vprefix_arg
) && ! no_direct
)
1435 /* In case we jump to directly_done. */
1436 Vcurrent_prefix_arg
= current_kboard
->Vprefix_arg
;
1438 /* Recognize some common commands in common situations and
1439 do them directly. */
1440 if (EQ (Vthis_command
, Qforward_char
) && PT
< ZV
)
1442 struct Lisp_Char_Table
*dp
1443 = window_display_table (XWINDOW (selected_window
));
1444 lose
= FETCH_CHAR (PT_BYTE
);
1447 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1448 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1449 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1450 && (lose
>= 0x20 && lose
< 0x7f)))
1451 : (lose
>= 0x20 && lose
< 0x7f))
1452 /* To extract the case of continuation on
1453 wide-column characters. */
1454 && (WIDTH_BY_CHAR_HEAD (FETCH_BYTE (PT_BYTE
)) == 1)
1455 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1457 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1459 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1461 && !windows_or_buffers_changed
1462 && EQ (current_buffer
->selective_display
, Qnil
)
1463 && !detect_input_pending ()
1464 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1465 && NILP (Vexecuting_macro
))
1466 direct_output_forward_char (1);
1469 else if (EQ (Vthis_command
, Qbackward_char
) && PT
> BEGV
)
1471 struct Lisp_Char_Table
*dp
1472 = window_display_table (XWINDOW (selected_window
));
1474 lose
= FETCH_CHAR (PT_BYTE
);
1476 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1477 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1478 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1479 && (lose
>= 0x20 && lose
< 0x7f)))
1480 : (lose
>= 0x20 && lose
< 0x7f))
1481 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1483 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1485 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1487 && !windows_or_buffers_changed
1488 && EQ (current_buffer
->selective_display
, Qnil
)
1489 && !detect_input_pending ()
1490 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1491 && NILP (Vexecuting_macro
))
1492 direct_output_forward_char (-1);
1495 else if (EQ (Vthis_command
, Qself_insert_command
)
1496 /* Try this optimization only on ascii keystrokes. */
1497 && INTEGERP (last_command_char
))
1499 unsigned int c
= XINT (last_command_char
);
1501 if (NILP (Vexecuting_macro
)
1502 && !EQ (minibuf_window
, selected_window
))
1504 if (!nonundocount
|| nonundocount
>= 20)
1512 lose
= ((XFASTINT (XWINDOW (selected_window
)->last_modified
)
1514 || (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1516 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1518 || MODIFF
<= SAVE_MODIFF
1519 || windows_or_buffers_changed
1520 || !EQ (current_buffer
->selective_display
, Qnil
)
1521 || detect_input_pending ()
1522 || !NILP (XWINDOW (selected_window
)->column_number_displayed
)
1523 || !NILP (Vexecuting_macro
));
1525 value
= internal_self_insert (c
, 0);
1530 /* VALUE == 1 when AFTER-CHANGE functions are
1531 installed which is the case most of the time
1532 because FONT-LOCK installs one. */
1533 if (!lose
&& !value
)
1534 direct_output_for_insert (c
);
1539 /* Here for a command that isn't executed directly */
1541 #ifdef HAVE_X_WINDOWS
1542 if (display_busy_cursor_p
)
1543 start_busy_cursor ();
1547 if (NILP (current_kboard
->Vprefix_arg
))
1549 Fcommand_execute (Vthis_command
, Qnil
, Qnil
, Qnil
);
1551 #ifdef HAVE_X_WINDOWS
1552 if (display_busy_cursor_p
)
1553 cancel_busy_cursor ();
1557 current_kboard
->Vlast_prefix_arg
= Vcurrent_prefix_arg
;
1559 /* Note that the value cell will never directly contain nil
1560 if the symbol is a local variable. */
1561 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1562 safe_run_hooks (Qpost_command_hook
);
1564 /* If displaying a message, resize the echo area window to fit
1565 that message's size exactly. */
1566 if (!NILP (echo_area_buffer
[0]))
1567 resize_echo_area_axactly ();
1569 if (!NILP (Vdeferred_action_list
))
1570 safe_run_hooks (Qdeferred_action_function
);
1572 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1574 if (NILP (Vunread_command_events
)
1575 && NILP (Vunread_input_method_events
)
1576 && NILP (Vunread_post_input_method_events
)
1577 && NILP (Vexecuting_macro
)
1578 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1, 1)))
1579 safe_run_hooks (Qpost_command_idle_hook
);
1582 /* If there is a prefix argument,
1583 1) We don't want Vlast_command to be ``universal-argument''
1584 (that would be dumb), so don't set Vlast_command,
1585 2) we want to leave echoing on so that the prefix will be
1586 echoed as part of this key sequence, so don't call
1588 3) we want to leave this_command_key_count non-zero, so that
1589 read_char will realize that it is re-reading a character, and
1590 not echo it a second time.
1592 If the command didn't actually create a prefix arg,
1593 but is merely a frame event that is transparent to prefix args,
1594 then the above doesn't apply. */
1595 if (NILP (current_kboard
->Vprefix_arg
) || CONSP (last_command_char
))
1597 current_kboard
->Vlast_command
= Vthis_command
;
1598 current_kboard
->Vreal_last_command
= real_this_command
;
1600 this_command_key_count
= 0;
1601 this_single_command_key_start
= 0;
1604 if (!NILP (current_buffer
->mark_active
) && !NILP (Vrun_hooks
))
1606 if (!NILP (Vdeactivate_mark
) && !NILP (Vtransient_mark_mode
))
1608 current_buffer
->mark_active
= Qnil
;
1609 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
1611 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
1612 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
1617 if (current_buffer
== prev_buffer
1618 && last_point_position
!= PT
1619 && NILP (Vdisable_point_adjustment
)
1620 && NILP (Vglobal_disable_point_adjustment
))
1621 adjust_point_for_property (last_point_position
);
1623 /* Install chars successfully executed in kbd macro. */
1625 if (!NILP (current_kboard
->defining_kbd_macro
)
1626 && NILP (current_kboard
->Vprefix_arg
))
1627 finalize_kbd_macro_chars ();
1631 any_kboard_state ();
1636 extern Lisp_Object Qcomposition
, Qdisplay
;
1638 /* Adjust point to a boundary of a region that has such a property
1639 that should be treated intangible. For the moment, we check
1640 `composition' and `display' property. LAST_PT is the last position
1644 adjust_point_for_property (last_pt
)
1649 int check_composition
= 1, check_display
= 1;
1651 while (check_composition
|| check_display
)
1653 if (check_composition
1654 && PT
> BEGV
&& PT
< ZV
1655 && get_property_and_range (PT
, Qcomposition
, &val
, &start
, &end
, Qnil
)
1656 && COMPOSITION_VALID_P (start
, end
, val
)
1657 && start
< PT
&& end
> PT
1658 && (last_pt
<= start
|| last_pt
>= end
))
1666 check_composition
= 0;
1668 && PT
> BEGV
&& PT
< ZV
1669 && get_property_and_range (PT
, Qdisplay
, &val
, &start
, &end
, Qnil
)
1670 && start
< PT
&& end
> PT
1671 && (last_pt
<= start
|| last_pt
>= end
))
1677 check_composition
= 1;
1683 /* Subroutine for safe_run_hooks: run the hook HOOK. */
1686 safe_run_hooks_1 (hook
)
1689 return call1 (Vrun_hooks
, Vinhibit_quit
);
1692 /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */
1695 safe_run_hooks_error (data
)
1698 return Fset (Vinhibit_quit
, Qnil
);
1701 /* If we get an error while running the hook, cause the hook variable
1702 to be nil. Also inhibit quits, so that C-g won't cause the hook
1703 to mysteriously evaporate. */
1706 safe_run_hooks (hook
)
1709 int count
= specpdl_ptr
- specpdl
;
1710 specbind (Qinhibit_quit
, hook
);
1712 internal_condition_case (safe_run_hooks_1
, Qt
, safe_run_hooks_error
);
1714 unbind_to (count
, Qnil
);
1718 /* Number of seconds between polling for input. This is a Lisp
1719 variable that can be bound. */
1723 /* Nonzero means polling for input is temporarily suppressed. */
1725 int poll_suppress_count
;
1727 /* Asynchronous timer for polling. */
1729 struct atimer
*poll_timer
;
1732 #ifdef POLL_FOR_INPUT
1734 /* Poll for input, so what we catch a C-g if it comes in. This
1735 function is called from x_make_frame_visible, see comment
1741 if (interrupt_input_blocked
== 0
1742 && !waiting_for_input
)
1743 read_avail_input (0);
1746 /* Timer callback function for poll_timer. TIMER is equal to
1750 poll_for_input (timer
)
1751 struct atimer
*timer
;
1753 if (poll_suppress_count
== 0)
1754 poll_for_input_1 ();
1757 #endif /* POLL_FOR_INPUT */
1759 /* Begin signals to poll for input, if they are appropriate.
1760 This function is called unconditionally from various places. */
1765 #ifdef POLL_FOR_INPUT
1766 if (read_socket_hook
&& !interrupt_input
)
1768 /* Turn alarm handling on unconditionally. It might have
1769 been turned off in process.c. */
1770 turn_on_atimers (1);
1772 /* If poll timer doesn't exist, are we need one with
1773 a different interval, start a new one. */
1774 if (poll_timer
== NULL
1775 || EMACS_SECS (poll_timer
->interval
) != polling_period
)
1777 EMACS_TIME interval
;
1780 cancel_atimer (poll_timer
);
1782 EMACS_SET_SECS_USECS (interval
, polling_period
, 0);
1783 poll_timer
= start_atimer (ATIMER_CONTINUOUS
, interval
,
1784 poll_for_input
, NULL
);
1787 /* Let the timer's callback function poll for input
1788 if this becomes zero. */
1789 --poll_suppress_count
;
1794 /* Nonzero if we are using polling to handle input asynchronously. */
1797 input_polling_used ()
1799 #ifdef POLL_FOR_INPUT
1800 return read_socket_hook
&& !interrupt_input
;
1806 /* Turn off polling. */
1811 #ifdef POLL_FOR_INPUT
1812 if (read_socket_hook
&& !interrupt_input
)
1813 ++poll_suppress_count
;
1817 /* Set the value of poll_suppress_count to COUNT
1818 and start or stop polling accordingly. */
1821 set_poll_suppress_count (count
)
1824 #ifdef POLL_FOR_INPUT
1825 if (count
== 0 && poll_suppress_count
!= 0)
1827 poll_suppress_count
= 1;
1830 else if (count
!= 0 && poll_suppress_count
== 0)
1834 poll_suppress_count
= count
;
1838 /* Bind polling_period to a value at least N.
1839 But don't decrease it. */
1842 bind_polling_period (n
)
1845 #ifdef POLL_FOR_INPUT
1846 int new = polling_period
;
1851 stop_other_atimers (poll_timer
);
1853 specbind (Qpolling_period
, make_number (new));
1854 /* Start a new alarm with the new period. */
1859 /* Apply the control modifier to CHARACTER. */
1865 /* Save the upper bits here. */
1866 int upper
= c
& ~0177;
1870 /* Everything in the columns containing the upper-case letters
1871 denotes a control character. */
1872 if (c
>= 0100 && c
< 0140)
1876 /* Set the shift modifier for a control char
1877 made from a shifted letter. But only for letters! */
1878 if (oc
>= 'A' && oc
<= 'Z')
1879 c
|= shift_modifier
;
1882 /* The lower-case letters denote control characters too. */
1883 else if (c
>= 'a' && c
<= 'z')
1886 /* Include the bits for control and shift
1887 only if the basic ASCII code can't indicate them. */
1891 /* Replace the high bits. */
1892 c
|= (upper
& ~ctrl_modifier
);
1899 /* Input of single characters from keyboard */
1901 Lisp_Object
print_help ();
1902 static Lisp_Object
kbd_buffer_get_event ();
1903 static void record_char ();
1906 static jmp_buf wrong_kboard_jmpbuf
;
1909 /* read a character from the keyboard; call the redisplay if needed */
1910 /* commandflag 0 means do not do auto-saving, but do do redisplay.
1911 -1 means do not do redisplay, but do do autosaving.
1914 /* The arguments MAPS and NMAPS are for menu prompting.
1915 MAPS is an array of keymaps; NMAPS is the length of MAPS.
1917 PREV_EVENT is the previous input event, or nil if we are reading
1918 the first event of a key sequence (or not reading a key sequence).
1919 If PREV_EVENT is t, that is a "magic" value that says
1920 not to run input methods, but in other respects to act as if
1921 not reading a key sequence.
1923 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
1924 if we used a mouse menu to read the input, or zero otherwise. If
1925 USED_MOUSE_MENU is null, we don't dereference it.
1927 Value is t if we showed a menu and the user rejected it. */
1930 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
)
1934 Lisp_Object prev_event
;
1935 int *used_mouse_menu
;
1939 jmp_buf local_getcjmp
;
1941 int key_already_recorded
= 0;
1942 Lisp_Object tem
, save
;
1943 Lisp_Object previous_echo_area_message
;
1944 Lisp_Object also_record
;
1946 struct gcpro gcpro1
, gcpro2
;
1950 before_command_key_count
= this_command_key_count
;
1951 before_command_echo_length
= echo_length ();
1953 previous_echo_area_message
= Qnil
;
1955 GCPRO2 (c
, previous_echo_area_message
);
1960 if (CONSP (Vunread_post_input_method_events
))
1962 c
= XCAR (Vunread_post_input_method_events
);
1963 Vunread_post_input_method_events
1964 = XCDR (Vunread_post_input_method_events
);
1966 /* Undo what read_char_x_menu_prompt did when it unread
1967 additional keys returned by Fx_popup_menu. */
1969 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
)))
1977 if (unread_command_char
!= -1)
1979 XSETINT (c
, unread_command_char
);
1980 unread_command_char
= -1;
1986 if (CONSP (Vunread_command_events
))
1988 c
= XCAR (Vunread_command_events
);
1989 Vunread_command_events
= XCDR (Vunread_command_events
);
1991 /* Undo what read_char_x_menu_prompt did when it unread
1992 additional keys returned by Fx_popup_menu. */
1994 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
)))
1999 goto reread_for_input_method
;
2002 if (CONSP (Vunread_input_method_events
))
2004 c
= XCAR (Vunread_input_method_events
);
2005 Vunread_input_method_events
= XCDR (Vunread_input_method_events
);
2007 /* Undo what read_char_x_menu_prompt did when it unread
2008 additional keys returned by Fx_popup_menu. */
2010 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
)))
2014 goto reread_for_input_method
;
2017 /* If there is no function key translated before
2018 reset-this-command-lengths takes effect, forget about it. */
2019 before_command_restore_flag
= 0;
2021 if (!NILP (Vexecuting_macro
))
2023 /* We set this to Qmacro; since that's not a frame, nobody will
2024 try to switch frames on us, and the selected window will
2027 Since this event came from a macro, it would be misleading to
2028 leave internal_last_event_frame set to wherever the last
2029 real event came from. Normally, a switch-frame event selects
2030 internal_last_event_frame after each command is read, but
2031 events read from a macro should never cause a new frame to be
2033 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
2035 /* Exit the macro if we are at the end.
2036 Also, some things replace the macro with t
2037 to force an early exit. */
2038 if (EQ (Vexecuting_macro
, Qt
)
2039 || executing_macro_index
>= XFASTINT (Flength (Vexecuting_macro
)))
2045 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
2046 if (STRINGP (Vexecuting_macro
)
2047 && (XINT (c
) & 0x80))
2048 XSETFASTINT (c
, CHAR_META
| (XINT (c
) & ~0x80));
2050 executing_macro_index
++;
2055 if (!NILP (unread_switch_frame
))
2057 c
= unread_switch_frame
;
2058 unread_switch_frame
= Qnil
;
2060 /* This event should make it into this_command_keys, and get echoed
2061 again, so we do not set `reread'. */
2065 /* if redisplay was requested */
2066 if (commandflag
>= 0)
2068 /* If there is pending input, process any events which are not
2069 user-visible, such as X selection_request events. */
2071 || detect_input_pending_run_timers (0))
2072 swallow_events (0); /* may clear input_pending */
2074 /* Redisplay if no pending input. */
2075 while (!input_pending
)
2080 /* Normal case: no input arrived during redisplay. */
2083 /* Input arrived and pre-empted redisplay.
2084 Process any events which are not user-visible. */
2086 /* If that cleared input_pending, try again to redisplay. */
2090 /* Message turns off echoing unless more keystrokes turn it on again.
2092 The code in 20.x for the condition was
2094 1. echo_area_glyphs && *echo_area_glyphs
2095 2. && echo_area_glyphs != current_kboard->echobuf
2096 3. && ok_to_echo_at_next_pause != echo_area_glyphs
2098 (1) means there's a current message displayed
2100 (2) means it's not the message from echoing from the current
2103 (3) There's only one place in 20.x where ok_to_echo_at_next_pause
2104 is set to a non-null value. This is done in read_char and it is
2105 set to echo_area_glyphs after a call to echo_char. That means
2106 ok_to_echo_at_next_pause is either null or
2107 current_kboard->echobuf with the appropriate current_kboard at
2110 So, condition (3) means in clear text ok_to_echo_at_next_pause
2111 must be either null, or the current message isn't from echoing at
2112 all, or it's from echoing from a different kboard than the
2115 if (/* There currently something in the echo area */
2116 !NILP (echo_area_buffer
[0])
2117 && (/* And it's either not from echoing. */
2118 !EQ (echo_area_buffer
[0], echo_message_buffer
)
2119 /* Or it's an echo from a different kboard. */
2120 || echo_kboard
!= current_kboard
2121 /* Or we explicitly allow overwriting whatever there is. */
2122 || ok_to_echo_at_next_pause
== NULL
))
2127 /* Try reading a character via menu prompting in the minibuf.
2128 Try this before the sit-for, because the sit-for
2129 would do the wrong thing if we are supposed to do
2130 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
2131 after a mouse event so don't try a minibuf menu. */
2133 if (nmaps
> 0 && INTERACTIVE
2134 && !NILP (prev_event
) && ! EVENT_HAS_PARAMETERS (prev_event
)
2135 /* Don't bring up a menu if we already have another event. */
2136 && NILP (Vunread_command_events
)
2137 && unread_command_char
< 0
2138 && !detect_input_pending_run_timers (0))
2140 c
= read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
);
2143 key_already_recorded
= 1;
2148 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet.
2149 We will do that below, temporarily for short sections of code,
2150 when appropriate. local_getcjmp must be in effect
2151 around any call to sit_for or kbd_buffer_get_event;
2152 it *must not* be in effect when we call redisplay. */
2154 if (_setjmp (local_getcjmp
))
2156 XSETINT (c
, quit_char
);
2157 internal_last_event_frame
= selected_frame
;
2158 Vlast_event_frame
= internal_last_event_frame
;
2159 /* If we report the quit char as an event,
2160 don't do so more than once. */
2161 if (!NILP (Vinhibit_quit
))
2166 KBOARD
*kb
= FRAME_KBOARD (XFRAME (selected_frame
));
2167 if (kb
!= current_kboard
)
2169 Lisp_Object
*tailp
= &kb
->kbd_queue
;
2170 /* We shouldn't get here if we were in single-kboard mode! */
2173 while (CONSP (*tailp
))
2174 tailp
= &XCDR (*tailp
);
2177 *tailp
= Fcons (c
, Qnil
);
2178 kb
->kbd_queue_has_data
= 1;
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);
2190 timer_start_idle ();
2192 /* If in middle of key sequence and minibuffer not active,
2193 start echoing if enough time elapses. */
2195 if (minibuf_level
== 0
2196 && !current_kboard
->immediate_echo
2197 && this_command_key_count
> 0
2199 && (FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
2200 && NILP (Fzerop (Vecho_keystrokes
))
2201 && (/* No message. */
2202 NILP (echo_area_buffer
[0])
2203 /* Or empty message. */
2204 || (BUF_BEG (XBUFFER (echo_area_buffer
[0]))
2205 == BUF_Z (XBUFFER (echo_area_buffer
[0])))
2206 /* Or already echoing from same kboard. */
2207 || (echo_kboard
&& ok_to_echo_at_next_pause
== echo_kboard
)
2208 /* Or not echoing before and echoing allowed. */
2209 || (!echo_kboard
&& ok_to_echo_at_next_pause
)))
2213 /* After a mouse event, start echoing right away.
2214 This is because we are probably about to display a menu,
2215 and we don't want to delay before doing so. */
2216 if (EVENT_HAS_PARAMETERS (prev_event
))
2221 double duration
= extract_float (Vecho_keystrokes
);
2222 sec
= (int) duration
;
2223 usec
= (duration
- sec
) * 1000000;
2224 save_getcjmp (save_jump
);
2225 restore_getcjmp (local_getcjmp
);
2226 tem0
= sit_for (sec
, usec
, 1, 1, 0);
2227 restore_getcjmp (save_jump
);
2229 && ! CONSP (Vunread_command_events
))
2234 /* Maybe auto save due to number of keystrokes. */
2236 if (commandflag
!= 0
2237 && auto_save_interval
> 0
2238 && num_nonmacro_input_events
- last_auto_save
> max (auto_save_interval
, 20)
2239 && !detect_input_pending_run_timers (0))
2241 Fdo_auto_save (Qnil
, Qnil
);
2242 /* Hooks can actually change some buffers in auto save. */
2246 /* Try reading using an X menu.
2247 This is never confused with reading using the minibuf
2248 because the recursive call of read_char in read_char_minibuf_menu_prompt
2249 does not pass on any keymaps. */
2251 if (nmaps
> 0 && INTERACTIVE
2252 && !NILP (prev_event
)
2253 && EVENT_HAS_PARAMETERS (prev_event
)
2254 && !EQ (XCAR (prev_event
), Qmenu_bar
)
2255 && !EQ (XCAR (prev_event
), Qtool_bar
)
2256 /* Don't bring up a menu if we already have another event. */
2257 && NILP (Vunread_command_events
)
2258 && unread_command_char
< 0)
2260 c
= read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
2262 /* Now that we have read an event, Emacs is not idle. */
2268 /* Maybe autosave and/or garbage collect due to idleness. */
2270 if (INTERACTIVE
&& NILP (c
))
2272 int delay_level
, buffer_size
;
2274 /* Slow down auto saves logarithmically in size of current buffer,
2275 and garbage collect while we're at it. */
2276 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
2277 last_non_minibuf_size
= Z
- BEG
;
2278 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
2280 while (buffer_size
> 64)
2281 delay_level
++, buffer_size
-= buffer_size
>> 2;
2282 if (delay_level
< 4) delay_level
= 4;
2283 /* delay_level is 4 for files under around 50k, 7 at 100k,
2284 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
2286 /* Auto save if enough time goes by without input. */
2287 if (commandflag
!= 0
2288 && num_nonmacro_input_events
> last_auto_save
2289 && INTEGERP (Vauto_save_timeout
)
2290 && XINT (Vauto_save_timeout
) > 0)
2294 save_getcjmp (save_jump
);
2295 restore_getcjmp (local_getcjmp
);
2296 tem0
= sit_for (delay_level
* XFASTINT (Vauto_save_timeout
) / 4,
2298 restore_getcjmp (save_jump
);
2301 && ! CONSP (Vunread_command_events
))
2303 Fdo_auto_save (Qnil
, Qnil
);
2305 /* If we have auto-saved and there is still no input
2306 available, garbage collect if there has been enough
2307 consing going on to make it worthwhile. */
2308 if (!detect_input_pending_run_timers (0)
2309 && consing_since_gc
> gc_cons_threshold
/ 2)
2310 Fgarbage_collect ();
2317 /* If this has become non-nil here, it has been set by a timer
2318 or sentinel or filter. */
2319 if (CONSP (Vunread_command_events
))
2321 c
= XCAR (Vunread_command_events
);
2322 Vunread_command_events
= XCDR (Vunread_command_events
);
2325 /* Read something from current KBOARD's side queue, if possible. */
2329 if (current_kboard
->kbd_queue_has_data
)
2331 if (!CONSP (current_kboard
->kbd_queue
))
2333 c
= XCAR (current_kboard
->kbd_queue
);
2334 current_kboard
->kbd_queue
2335 = XCDR (current_kboard
->kbd_queue
);
2336 if (NILP (current_kboard
->kbd_queue
))
2337 current_kboard
->kbd_queue_has_data
= 0;
2338 input_pending
= readable_events (0);
2339 if (EVENT_HAS_PARAMETERS (c
)
2340 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qswitch_frame
))
2341 internal_last_event_frame
= XCAR (XCDR (c
));
2342 Vlast_event_frame
= internal_last_event_frame
;
2347 /* If current_kboard's side queue is empty check the other kboards.
2348 If one of them has data that we have not yet seen here,
2349 switch to it and process the data waiting for it.
2351 Note: if the events queued up for another kboard
2352 have already been seen here, and therefore are not a complete command,
2353 the kbd_queue_has_data field is 0, so we skip that kboard here.
2354 That's to avoid an infinite loop switching between kboards here. */
2355 if (NILP (c
) && !single_kboard
)
2358 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2359 if (kb
->kbd_queue_has_data
)
2361 current_kboard
= kb
;
2362 /* This is going to exit from read_char
2363 so we had better get rid of this frame's stuff. */
2365 longjmp (wrong_kboard_jmpbuf
, 1);
2374 /* Finally, we read from the main queue,
2375 and if that gives us something we can't use yet, we put it on the
2376 appropriate side queue and try again. */
2382 /* Actually read a character, waiting if necessary. */
2383 save_getcjmp (save_jump
);
2384 restore_getcjmp (local_getcjmp
);
2385 c
= kbd_buffer_get_event (&kb
, used_mouse_menu
);
2386 restore_getcjmp (save_jump
);
2389 if (! NILP (c
) && (kb
!= current_kboard
))
2391 Lisp_Object
*tailp
= &kb
->kbd_queue
;
2392 while (CONSP (*tailp
))
2393 tailp
= &XCDR (*tailp
);
2396 *tailp
= Fcons (c
, Qnil
);
2397 kb
->kbd_queue_has_data
= 1;
2401 current_kboard
= kb
;
2402 /* This is going to exit from read_char
2403 so we had better get rid of this frame's stuff. */
2405 longjmp (wrong_kboard_jmpbuf
, 1);
2410 /* Terminate Emacs in batch mode if at eof. */
2411 if (noninteractive
&& INTEGERP (c
) && XINT (c
) < 0)
2412 Fkill_emacs (make_number (1));
2416 /* Add in any extra modifiers, where appropriate. */
2417 if ((extra_keyboard_modifiers
& CHAR_CTL
)
2418 || ((extra_keyboard_modifiers
& 0177) < ' '
2419 && (extra_keyboard_modifiers
& 0177) != 0))
2420 XSETINT (c
, make_ctrl_char (XINT (c
)));
2422 /* Transfer any other modifier bits directly from
2423 extra_keyboard_modifiers to c. Ignore the actual character code
2424 in the low 16 bits of extra_keyboard_modifiers. */
2425 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
2436 if (commandflag
>= 0
2437 && !input_pending
&& !detect_input_pending_run_timers (0))
2445 /* Buffer switch events are only for internal wakeups
2446 so don't show them to the user.
2447 Also, don't record a key if we already did. */
2448 if (BUFFERP (c
) || key_already_recorded
)
2451 /* Process special events within read_char
2452 and loop around to read another event. */
2455 tem
= get_keyelt (access_keymap (get_keymap_1 (Vspecial_event_map
, 0, 0),
2461 int was_locked
= single_kboard
;
2463 last_input_char
= c
;
2464 Fcommand_execute (tem
, Qnil
, Fvector (1, &last_input_char
), Qt
);
2466 /* Resume allowing input from any kboard, if that was true before. */
2468 any_kboard_state ();
2473 /* Handle things that only apply to characters. */
2476 /* If kbd_buffer_get_event gave us an EOF, return that. */
2480 if ((STRINGP (Vkeyboard_translate_table
)
2481 && XSTRING (Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
2482 || (VECTORP (Vkeyboard_translate_table
)
2483 && XVECTOR (Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
2484 || (CHAR_TABLE_P (Vkeyboard_translate_table
)
2485 && CHAR_TABLE_ORDINARY_SLOTS
> (unsigned) XFASTINT (c
)))
2488 d
= Faref (Vkeyboard_translate_table
, c
);
2489 /* nil in keyboard-translate-table means no translation. */
2495 /* If this event is a mouse click in the menu bar,
2496 return just menu-bar for now. Modify the mouse click event
2497 so we won't do this twice, then queue it up. */
2498 if (EVENT_HAS_PARAMETERS (c
)
2500 && CONSP (EVENT_START (c
))
2501 && CONSP (XCDR (EVENT_START (c
))))
2505 posn
= POSN_BUFFER_POSN (EVENT_START (c
));
2506 /* Handle menu-bar events:
2507 insert the dummy prefix event `menu-bar'. */
2508 if (EQ (posn
, Qmenu_bar
) || EQ (posn
, Qtool_bar
))
2510 /* Change menu-bar to (menu-bar) as the event "position". */
2511 POSN_BUFFER_POSN (EVENT_START (c
)) = Fcons (posn
, Qnil
);
2514 Vunread_command_events
= Fcons (c
, Vunread_command_events
);
2519 /* Store these characters into recent_keys, the dribble file if any,
2520 and the keyboard macro being defined, if any. */
2522 if (! NILP (also_record
))
2523 record_char (also_record
);
2525 /* Wipe the echo area.
2526 But first, if we are about to use an input method,
2527 save the echo area contents for it to refer to. */
2529 && ! NILP (Vinput_method_function
)
2530 && (unsigned) XINT (c
) >= ' '
2531 && (unsigned) XINT (c
) != 127
2532 && (unsigned) XINT (c
) < 256)
2534 previous_echo_area_message
= Fcurrent_message ();
2535 Vinput_method_previous_message
= previous_echo_area_message
;
2538 /* Now wipe the echo area, except for help events which do their
2539 own stuff with the echo area. */
2540 if (!CONSP (c
) || !(EQ (Qhelp_echo
, XCAR (c
))))
2542 if (!NILP (echo_area_buffer
[0]))
2543 safe_run_hooks (Qecho_area_clear_hook
);
2544 clear_message (1, 0);
2547 reread_for_input_method
:
2549 /* Pass this to the input method, if appropriate. */
2551 && ! NILP (Vinput_method_function
)
2552 /* Don't run the input method within a key sequence,
2553 after the first event of the key sequence. */
2554 && NILP (prev_event
)
2555 && (unsigned) XINT (c
) >= ' '
2556 && (unsigned) XINT (c
) != 127
2557 && (unsigned) XINT (c
) < 256)
2561 struct gcpro gcpro1
;
2562 int count
= specpdl_ptr
- specpdl
;
2564 /* Save the echo status. */
2565 int saved_immediate_echo
= current_kboard
->immediate_echo
;
2566 struct kboard
*saved_ok_to_echo
= ok_to_echo_at_next_pause
;
2567 int saved_echo_after_prompt
= current_kboard
->echo_after_prompt
;
2569 if (before_command_restore_flag
)
2571 this_command_key_count
= before_command_key_count_1
;
2572 if (this_command_key_count
< this_single_command_key_start
)
2573 this_single_command_key_start
= this_command_key_count
;
2574 echo_truncate (before_command_echo_length_1
);
2575 before_command_restore_flag
= 0;
2578 /* Save the this_command_keys status. */
2579 key_count
= this_command_key_count
;
2582 keys
= Fcopy_sequence (this_command_keys
);
2587 /* Clear out this_command_keys. */
2588 this_command_key_count
= 0;
2590 /* Now wipe the echo area. */
2591 if (!NILP (echo_area_buffer
[0]))
2592 safe_run_hooks (Qecho_area_clear_hook
);
2593 clear_message (1, 0);
2596 /* If we are not reading a key sequence,
2597 never use the echo area. */
2600 specbind (Qinput_method_use_echo_area
, Qt
);
2603 /* Call the input method. */
2604 tem
= call1 (Vinput_method_function
, c
);
2606 tem
= unbind_to (count
, tem
);
2608 /* Restore the saved echoing state
2609 and this_command_keys state. */
2610 this_command_key_count
= key_count
;
2612 this_command_keys
= keys
;
2615 ok_to_echo_at_next_pause
= saved_ok_to_echo
;
2616 current_kboard
->echo_after_prompt
= saved_echo_after_prompt
;
2617 if (saved_immediate_echo
)
2622 /* The input method can return no events. */
2625 /* Bring back the previous message, if any. */
2626 if (! NILP (previous_echo_area_message
))
2627 message_with_string ("%s", previous_echo_area_message
, 0);
2630 /* It returned one event or more. */
2632 Vunread_post_input_method_events
2633 = nconc2 (XCDR (tem
), Vunread_post_input_method_events
);
2638 /* Display help if not echoing. */
2639 if (CONSP (c
) && EQ (XCAR (c
), Qhelp_echo
))
2643 msg
= XCDR (XCDR (c
));
2645 if (!NILP (Vshow_help_function
))
2646 call1 (Vshow_help_function
, msg
);
2647 else if (/* Don't overwrite minibuffer contents. */
2648 !MINI_WINDOW_P (XWINDOW (selected_window
))
2649 /* Don't overwrite a keystroke echo. */
2650 && NILP (echo_message_buffer
)
2651 /* Don't overwrite a prompt. */
2652 && !cursor_in_echo_area
)
2655 message3_nolog (msg
, XSTRING (msg
)->size
, STRING_MULTIBYTE (msg
));
2663 if (this_command_key_count
== 0 || ! reread
)
2665 before_command_key_count
= this_command_key_count
;
2666 before_command_echo_length
= echo_length ();
2668 /* Don't echo mouse motion events. */
2669 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
2670 && NILP (Fzerop (Vecho_keystrokes
))
2671 && ! (EVENT_HAS_PARAMETERS (c
)
2672 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
2675 if (! NILP (also_record
))
2676 echo_char (also_record
);
2677 /* Once we reread a character, echoing can happen
2678 the next time we pause to read a new one. */
2679 ok_to_echo_at_next_pause
= current_kboard
;
2682 /* Record this character as part of the current key. */
2683 add_command_key (c
);
2684 if (! NILP (also_record
))
2685 add_command_key (also_record
);
2688 last_input_char
= c
;
2691 /* Process the help character specially if enabled */
2692 if (!NILP (Vhelp_form
) && help_char_p (c
))
2695 count
= specpdl_ptr
- specpdl
;
2697 record_unwind_protect (Fset_window_configuration
,
2698 Fcurrent_window_configuration (Qnil
));
2700 tem0
= Feval (Vhelp_form
);
2702 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
2706 c
= read_char (0, 0, 0, Qnil
, 0);
2707 while (BUFFERP (c
));
2708 /* Remove the help from the frame */
2709 unbind_to (count
, Qnil
);
2712 if (EQ (c
, make_number (040)))
2716 c
= read_char (0, 0, 0, Qnil
, 0);
2717 while (BUFFERP (c
));
2724 /* Record a key that came from a mouse menu.
2725 Record it for echoing, for this-command-keys, and so on. */
2731 /* Wipe the echo area. */
2732 clear_message (1, 0);
2736 before_command_key_count
= this_command_key_count
;
2737 before_command_echo_length
= echo_length ();
2739 /* Don't echo mouse motion events. */
2740 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
2741 && NILP (Fzerop (Vecho_keystrokes
)))
2745 /* Once we reread a character, echoing can happen
2746 the next time we pause to read a new one. */
2747 ok_to_echo_at_next_pause
= 0;
2750 /* Record this character as part of the current key. */
2751 add_command_key (c
);
2753 /* Re-reading in the middle of a command */
2754 last_input_char
= c
;
2758 /* Return 1 if should recognize C as "the help character". */
2766 if (EQ (c
, Vhelp_char
))
2768 for (tail
= Vhelp_event_list
; CONSP (tail
); tail
= XCDR (tail
))
2769 if (EQ (c
, XCAR (tail
)))
2774 /* Record the input event C in various ways. */
2781 XVECTOR (recent_keys
)->contents
[recent_keys_index
] = c
;
2782 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
2783 recent_keys_index
= 0;
2785 /* Write c to the dribble file. If c is a lispy event, write
2786 the event's symbol to the dribble file, in <brackets>. Bleaugh.
2787 If you, dear reader, have a better idea, you've got the source. :-) */
2792 if (XUINT (c
) < 0x100)
2793 putc (XINT (c
), dribble
);
2795 fprintf (dribble
, " 0x%x", (int) XUINT (c
));
2799 Lisp_Object dribblee
;
2801 /* If it's a structured event, take the event header. */
2802 dribblee
= EVENT_HEAD (c
);
2804 if (SYMBOLP (dribblee
))
2806 putc ('<', dribble
);
2807 fwrite (XSYMBOL (dribblee
)->name
->data
, sizeof (char),
2808 STRING_BYTES (XSYMBOL (dribblee
)->name
),
2810 putc ('>', dribble
);
2817 store_kbd_macro_char (c
);
2819 num_nonmacro_input_events
++;
2826 struct buffer
*old
= current_buffer
;
2827 Fprinc (object
, Qnil
);
2828 set_buffer_internal (XBUFFER (Vstandard_output
));
2829 call0 (intern ("help-mode"));
2830 set_buffer_internal (old
);
2834 /* Copy out or in the info on where C-g should throw to.
2835 This is used when running Lisp code from within get_char,
2836 in case get_char is called recursively.
2837 See read_process_output. */
2843 bcopy (getcjmp
, temp
, sizeof getcjmp
);
2847 restore_getcjmp (temp
)
2850 bcopy (temp
, getcjmp
, sizeof getcjmp
);
2855 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
2856 of this function. */
2859 tracking_off (old_value
)
2860 Lisp_Object old_value
;
2862 do_mouse_tracking
= old_value
;
2863 if (NILP (old_value
))
2865 /* Redisplay may have been preempted because there was input
2866 available, and it assumes it will be called again after the
2867 input has been processed. If the only input available was
2868 the sort that we have just disabled, then we need to call
2870 if (!readable_events (1))
2872 redisplay_preserve_echo_area ();
2873 get_input_pending (&input_pending
, 1);
2879 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
2880 "Evaluate BODY with mouse movement events enabled.\n\
2881 Within a `track-mouse' form, mouse motion generates input events that\n\
2882 you can read with `read-event'.\n\
2883 Normally, mouse motion is ignored.")
2887 int count
= specpdl_ptr
- specpdl
;
2890 record_unwind_protect (tracking_off
, do_mouse_tracking
);
2892 do_mouse_tracking
= Qt
;
2894 val
= Fprogn (args
);
2895 return unbind_to (count
, val
);
2898 /* If mouse has moved on some frame, return one of those frames.
2899 Return 0 otherwise. */
2904 Lisp_Object tail
, frame
;
2906 FOR_EACH_FRAME (tail
, frame
)
2908 if (XFRAME (frame
)->mouse_moved
)
2909 return XFRAME (frame
);
2915 #endif /* HAVE_MOUSE */
2917 /* Low level keyboard/mouse input.
2918 kbd_buffer_store_event places events in kbd_buffer, and
2919 kbd_buffer_get_event retrieves them. */
2921 /* Return true iff there are any events in the queue that read-char
2922 would return. If this returns false, a read-char would block. */
2924 readable_events (do_timers_now
)
2928 timer_check (do_timers_now
);
2930 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2933 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2938 if (current_kboard
->kbd_queue_has_data
)
2944 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2945 if (kb
->kbd_queue_has_data
)
2951 /* Set this for debugging, to have a way to get out */
2956 event_to_kboard (event
)
2957 struct input_event
*event
;
2960 frame
= event
->frame_or_window
;
2962 frame
= XCAR (frame
);
2963 else if (WINDOWP (frame
))
2964 frame
= WINDOW_FRAME (XWINDOW (frame
));
2966 /* There are still some events that don't set this field.
2967 For now, just ignore the problem.
2968 Also ignore dead frames here. */
2969 if (!FRAMEP (frame
) || !FRAME_LIVE_P (XFRAME (frame
)))
2972 return FRAME_KBOARD (XFRAME (frame
));
2976 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
2979 kbd_buffer_store_event (event
)
2980 register struct input_event
*event
;
2982 if (event
->kind
== no_event
)
2985 if (event
->kind
== ascii_keystroke
)
2987 register int c
= event
->code
& 0377;
2989 if (event
->modifiers
& ctrl_modifier
)
2990 c
= make_ctrl_char (c
);
2992 c
|= (event
->modifiers
2993 & (meta_modifier
| alt_modifier
2994 | hyper_modifier
| super_modifier
));
2998 extern SIGTYPE
interrupt_signal ();
3001 struct input_event
*sp
;
3004 && (kb
= FRAME_KBOARD (XFRAME (event
->frame_or_window
)),
3005 kb
!= current_kboard
))
3008 = Fcons (make_lispy_switch_frame (event
->frame_or_window
),
3009 Fcons (make_number (c
), Qnil
));
3010 kb
->kbd_queue_has_data
= 1;
3011 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
3013 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3016 if (event_to_kboard (sp
) == kb
)
3018 sp
->kind
= no_event
;
3019 sp
->frame_or_window
= Qnil
;
3026 /* If this results in a quit_char being returned to Emacs as
3027 input, set Vlast_event_frame properly. If this doesn't
3028 get returned to Emacs as an event, the next event read
3029 will set Vlast_event_frame again, so this is safe to do. */
3033 focus
= FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
3035 focus
= event
->frame_or_window
;
3036 internal_last_event_frame
= focus
;
3037 Vlast_event_frame
= focus
;
3040 last_event_timestamp
= event
->timestamp
;
3041 interrupt_signal ();
3045 if (c
&& c
== stop_character
)
3051 /* Don't insert two buffer_switch_event's in a row.
3052 Just ignore the second one. */
3053 else if (event
->kind
== buffer_switch_event
3054 && kbd_fetch_ptr
!= kbd_store_ptr
3055 && kbd_store_ptr
->kind
== buffer_switch_event
)
3058 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
3059 kbd_store_ptr
= kbd_buffer
;
3061 /* Don't let the very last slot in the buffer become full,
3062 since that would make the two pointers equal,
3063 and that is indistinguishable from an empty buffer.
3064 Discard the event if it would fill the last slot. */
3065 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
3067 struct input_event
*sp
= kbd_store_ptr
;
3068 sp
->kind
= event
->kind
;
3069 if (event
->kind
== selection_request_event
)
3071 /* We must not use the ordinary copying code for this case,
3072 since `part' is an enum and copying it might not copy enough
3074 bcopy (event
, (char *) sp
, sizeof (*event
));
3078 sp
->code
= event
->code
;
3079 sp
->part
= event
->part
;
3080 sp
->frame_or_window
= event
->frame_or_window
;
3081 sp
->modifiers
= event
->modifiers
;
3084 sp
->timestamp
= event
->timestamp
;
3086 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_store_ptr
3088 = event
->frame_or_window
);
3094 /* Discard any mouse events in the event buffer by setting them to
3097 discard_mouse_events ()
3099 struct input_event
*sp
;
3100 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
3102 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3105 if (sp
->kind
== mouse_click
3107 || sp
->kind
== w32_scroll_bar_click
3109 || sp
->kind
== scroll_bar_click
)
3111 sp
->kind
= no_event
;
3116 /* Read one event from the event buffer, waiting if necessary.
3117 The value is a Lisp object representing the event.
3118 The value is nil for an event that should be ignored,
3119 or that was handled here.
3120 We always read and discard one event. */
3123 kbd_buffer_get_event (kbp
, used_mouse_menu
)
3125 int *used_mouse_menu
;
3134 *kbp
= current_kboard
;
3138 /* Wait until there is input available. */
3141 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3144 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
3148 /* If the quit flag is set, then read_char will return
3149 quit_char, so that counts as "available input." */
3150 if (!NILP (Vquit_flag
))
3151 quit_throw_to_read_char ();
3153 /* One way or another, wait until input is available; then, if
3154 interrupt handlers have not read it, read it now. */
3157 wait_for_kbd_input ();
3159 /* Note SIGIO has been undef'd if FIONREAD is missing. */
3163 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3166 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
3170 Lisp_Object minus_one
;
3172 XSETINT (minus_one
, -1);
3173 wait_reading_process_input (0, 0, minus_one
, 1);
3175 if (!interrupt_input
&& kbd_fetch_ptr
== kbd_store_ptr
)
3176 /* Pass 1 for EXPECT since we just waited to have input. */
3177 read_avail_input (1);
3179 #endif /* not VMS */
3182 if (CONSP (Vunread_command_events
))
3185 first
= XCAR (Vunread_command_events
);
3186 Vunread_command_events
= XCDR (Vunread_command_events
);
3187 *kbp
= current_kboard
;
3191 /* At this point, we know that there is a readable event available
3192 somewhere. If the event queue is empty, then there must be a
3193 mouse movement enabled and available. */
3194 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3196 struct input_event
*event
;
3198 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
3202 last_event_timestamp
= event
->timestamp
;
3205 *kbp
= event_to_kboard (event
);
3207 *kbp
= current_kboard
; /* Better than returning null ptr? */
3209 *kbp
= &the_only_kboard
;
3214 /* These two kinds of events get special handling
3215 and don't actually appear to the command loop.
3216 We return nil for them. */
3217 if (event
->kind
== selection_request_event
)
3220 struct input_event copy
;
3222 /* Remove it from the buffer before processing it,
3223 since otherwise swallow_events will see it
3224 and process it again. */
3226 kbd_fetch_ptr
= event
+ 1;
3227 input_pending
= readable_events (0);
3228 x_handle_selection_request (©
);
3230 /* We're getting selection request events, but we don't have
3236 else if (event
->kind
== selection_clear_event
)
3239 struct input_event copy
;
3241 /* Remove it from the buffer before processing it. */
3243 kbd_fetch_ptr
= event
+ 1;
3244 input_pending
= readable_events (0);
3245 x_handle_selection_clear (©
);
3247 /* We're getting selection request events, but we don't have
3252 #if defined (HAVE_X11) || defined (HAVE_NTGUI)
3253 else if (event
->kind
== delete_window_event
)
3255 /* Make an event (delete-frame (FRAME)). */
3256 obj
= Fcons (event
->frame_or_window
, Qnil
);
3257 obj
= Fcons (Qdelete_frame
, Fcons (obj
, Qnil
));
3258 kbd_fetch_ptr
= event
+ 1;
3260 else if (event
->kind
== iconify_event
)
3262 /* Make an event (iconify-frame (FRAME)). */
3263 obj
= Fcons (event
->frame_or_window
, Qnil
);
3264 obj
= Fcons (Qiconify_frame
, Fcons (obj
, Qnil
));
3265 kbd_fetch_ptr
= event
+ 1;
3267 else if (event
->kind
== deiconify_event
)
3269 /* Make an event (make-frame-visible (FRAME)). */
3270 obj
= Fcons (event
->frame_or_window
, Qnil
);
3271 obj
= Fcons (Qmake_frame_visible
, Fcons (obj
, Qnil
));
3272 kbd_fetch_ptr
= event
+ 1;
3275 else if (event
->kind
== buffer_switch_event
)
3277 /* The value doesn't matter here; only the type is tested. */
3278 XSETBUFFER (obj
, current_buffer
);
3279 kbd_fetch_ptr
= event
+ 1;
3281 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
3282 else if (event
->kind
== menu_bar_activate_event
)
3284 kbd_fetch_ptr
= event
+ 1;
3285 input_pending
= readable_events (0);
3286 if (FRAME_LIVE_P (XFRAME (event
->frame_or_window
)))
3287 x_activate_menubar (XFRAME (event
->frame_or_window
));
3291 else if (event
->kind
== language_change_event
)
3293 /* Make an event (language-change (FRAME CHARSET LCID)). */
3294 obj
= Fcons (event
->modifiers
, Qnil
);
3295 obj
= Fcons (event
->code
, Qnil
);
3296 obj
= Fcons (event
->frame_or_window
, obj
);
3297 obj
= Fcons (Qlanguage_change
, Fcons (obj
, Qnil
));
3298 kbd_fetch_ptr
= event
+ 1;
3301 /* Just discard these, by returning nil.
3302 With MULTI_KBOARD, these events are used as placeholders
3303 when we need to randomly delete events from the queue.
3304 (They shouldn't otherwise be found in the buffer,
3305 but on some machines it appears they do show up
3306 even without MULTI_KBOARD.) */
3307 /* On Windows NT/9X, no_event is used to delete extraneous
3308 mouse events during a popup-menu call. */
3309 else if (event
->kind
== no_event
)
3310 kbd_fetch_ptr
= event
+ 1;
3311 else if (event
->kind
== HELP_EVENT
)
3313 /* The car of event->frame_or_window is a frame,
3314 the cdr is the help to display. */
3315 obj
= Fcons (Qhelp_echo
, event
->frame_or_window
);
3316 kbd_fetch_ptr
= event
+ 1;
3318 /* If this event is on a different frame, return a switch-frame this
3319 time, and leave the event in the queue for next time. */
3325 frame
= event
->frame_or_window
;
3327 frame
= XCAR (frame
);
3328 else if (WINDOWP (frame
))
3329 frame
= WINDOW_FRAME (XWINDOW (frame
));
3331 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
3335 if (! EQ (frame
, internal_last_event_frame
)
3336 && !EQ (frame
, selected_frame
))
3337 obj
= make_lispy_switch_frame (frame
);
3338 internal_last_event_frame
= frame
;
3340 /* If we didn't decide to make a switch-frame event, go ahead
3341 and build a real event from the queue entry. */
3345 obj
= make_lispy_event (event
);
3346 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
3347 /* If this was a menu selection, then set the flag to inhibit
3348 writing to last_nonmenu_event. Don't do this if the event
3349 we're returning is (menu-bar), though; that indicates the
3350 beginning of the menu sequence, and we might as well leave
3351 that as the `event with parameters' for this selection. */
3352 if ((event
->kind
== menu_bar_event
3353 || event
->kind
== TOOL_BAR_EVENT
)
3354 && !(CONSP (obj
) && EQ (XCAR (obj
), Qmenu_bar
))
3355 && !(CONSP (obj
) && EQ (XCAR (obj
), Qtool_bar
))
3357 *used_mouse_menu
= 1;
3360 /* Wipe out this event, to catch bugs. */
3361 event
->kind
= no_event
;
3362 XVECTOR (kbd_buffer_frame_or_window
)->contents
[event
- kbd_buffer
] = Qnil
;
3364 kbd_fetch_ptr
= event
+ 1;
3369 /* Try generating a mouse motion event. */
3370 else if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
3372 FRAME_PTR f
= some_mouse_moved ();
3373 Lisp_Object bar_window
;
3374 enum scroll_bar_part part
;
3378 *kbp
= current_kboard
;
3379 /* Note that this uses F to determine which display to look at.
3380 If there is no valid info, it does not store anything
3381 so x remains nil. */
3383 (*mouse_position_hook
) (&f
, 0, &bar_window
, &part
, &x
, &y
, &time
);
3387 /* Decide if we should generate a switch-frame event. Don't
3388 generate switch-frame events for motion outside of all Emacs
3394 frame
= FRAME_FOCUS_FRAME (f
);
3396 XSETFRAME (frame
, f
);
3398 if (! EQ (frame
, internal_last_event_frame
)
3399 && !EQ (frame
, selected_frame
))
3400 obj
= make_lispy_switch_frame (frame
);
3401 internal_last_event_frame
= frame
;
3404 /* If we didn't decide to make a switch-frame event, go ahead and
3405 return a mouse-motion event. */
3406 if (!NILP (x
) && NILP (obj
))
3407 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
3409 #endif /* HAVE_MOUSE */
3411 /* We were promised by the above while loop that there was
3412 something for us to read! */
3415 input_pending
= readable_events (0);
3417 Vlast_event_frame
= internal_last_event_frame
;
3422 /* Process any events that are not user-visible,
3423 then return, without reading any user-visible events. */
3426 swallow_events (do_display
)
3431 while (kbd_fetch_ptr
!= kbd_store_ptr
)
3433 struct input_event
*event
;
3435 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
3439 last_event_timestamp
= event
->timestamp
;
3441 /* These two kinds of events get special handling
3442 and don't actually appear to the command loop. */
3443 if (event
->kind
== selection_request_event
)
3446 struct input_event copy
;
3448 /* Remove it from the buffer before processing it,
3449 since otherwise swallow_events called recursively could see it
3450 and process it again. */
3452 kbd_fetch_ptr
= event
+ 1;
3453 input_pending
= readable_events (0);
3454 x_handle_selection_request (©
);
3456 /* We're getting selection request events, but we don't have
3462 else if (event
->kind
== selection_clear_event
)
3465 struct input_event copy
;
3467 /* Remove it from the buffer before processing it, */
3470 kbd_fetch_ptr
= event
+ 1;
3471 input_pending
= readable_events (0);
3472 x_handle_selection_clear (©
);
3474 /* We're getting selection request events, but we don't have
3483 old_timers_run
= timers_run
;
3484 get_input_pending (&input_pending
, 1);
3486 if (timers_run
!= old_timers_run
&& do_display
)
3487 redisplay_preserve_echo_area ();
3490 static EMACS_TIME timer_idleness_start_time
;
3492 /* Record the start of when Emacs is idle,
3493 for the sake of running idle-time timers. */
3500 /* If we are already in the idle state, do nothing. */
3501 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3504 EMACS_GET_TIME (timer_idleness_start_time
);
3506 /* Mark all idle-time timers as once again candidates for running. */
3507 for (timers
= Vtimer_idle_list
; CONSP (timers
); timers
= XCDR (timers
))
3511 timer
= XCAR (timers
);
3513 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3515 XVECTOR (timer
)->contents
[0] = Qnil
;
3519 /* Record that Emacs is no longer idle, so stop running idle-time timers. */
3524 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
3527 /* This is only for debugging. */
3528 struct input_event last_timer_event
;
3530 /* Check whether a timer has fired. To prevent larger problems we simply
3531 disregard elements that are not proper timers. Do not make a circular
3532 timer list for the time being.
3534 Returns the number of seconds to wait until the next timer fires. If a
3535 timer is triggering now, return zero seconds.
3536 If no timer is active, return -1 seconds.
3538 If a timer is ripe, we run it, with quitting turned off.
3540 DO_IT_NOW is now ignored. It used to mean that we should
3541 run the timer directly instead of queueing a timer-event.
3542 Now we always run timers directly. */
3545 timer_check (do_it_now
)
3548 EMACS_TIME nexttime
;
3549 EMACS_TIME now
, idleness_now
;
3550 Lisp_Object timers
, idle_timers
, chosen_timer
;
3551 struct gcpro gcpro1
, gcpro2
, gcpro3
;
3553 EMACS_SET_SECS (nexttime
, -1);
3554 EMACS_SET_USECS (nexttime
, -1);
3556 /* Always consider the ordinary timers. */
3557 timers
= Vtimer_list
;
3558 /* Consider the idle timers only if Emacs is idle. */
3559 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3560 idle_timers
= Vtimer_idle_list
;
3563 chosen_timer
= Qnil
;
3564 GCPRO3 (timers
, idle_timers
, chosen_timer
);
3566 if (CONSP (timers
) || CONSP (idle_timers
))
3568 EMACS_GET_TIME (now
);
3569 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3570 EMACS_SUB_TIME (idleness_now
, now
, timer_idleness_start_time
);
3573 while (CONSP (timers
) || CONSP (idle_timers
))
3575 Lisp_Object
*vector
;
3576 Lisp_Object timer
, idle_timer
;
3577 EMACS_TIME timer_time
, idle_timer_time
;
3578 EMACS_TIME difference
, timer_difference
, idle_timer_difference
;
3580 /* Skip past invalid timers and timers already handled. */
3583 timer
= XCAR (timers
);
3584 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3586 timers
= XCDR (timers
);
3589 vector
= XVECTOR (timer
)->contents
;
3591 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
3592 || !INTEGERP (vector
[3])
3593 || ! NILP (vector
[0]))
3595 timers
= XCDR (timers
);
3599 if (!NILP (idle_timers
))
3601 timer
= XCAR (idle_timers
);
3602 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3604 idle_timers
= XCDR (idle_timers
);
3607 vector
= XVECTOR (timer
)->contents
;
3609 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
3610 || !INTEGERP (vector
[3])
3611 || ! NILP (vector
[0]))
3613 idle_timers
= XCDR (idle_timers
);
3618 /* Set TIMER, TIMER_TIME and TIMER_DIFFERENCE
3619 based on the next ordinary timer.
3620 TIMER_DIFFERENCE is the distance in time from NOW to when
3621 this timer becomes ripe (negative if it's already ripe). */
3624 timer
= XCAR (timers
);
3625 vector
= XVECTOR (timer
)->contents
;
3626 EMACS_SET_SECS (timer_time
,
3627 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
3628 EMACS_SET_USECS (timer_time
, XINT (vector
[3]));
3629 EMACS_SUB_TIME (timer_difference
, timer_time
, now
);
3632 /* Set IDLE_TIMER, IDLE_TIMER_TIME and IDLE_TIMER_DIFFERENCE
3633 based on the next idle timer. */
3634 if (!NILP (idle_timers
))
3636 idle_timer
= XCAR (idle_timers
);
3637 vector
= XVECTOR (idle_timer
)->contents
;
3638 EMACS_SET_SECS (idle_timer_time
,
3639 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
3640 EMACS_SET_USECS (idle_timer_time
, XINT (vector
[3]));
3641 EMACS_SUB_TIME (idle_timer_difference
, idle_timer_time
, idleness_now
);
3644 /* Decide which timer is the next timer,
3645 and set CHOSEN_TIMER, VECTOR and DIFFERENCE accordingly.
3646 Also step down the list where we found that timer. */
3648 if (! NILP (timers
) && ! NILP (idle_timers
))
3651 EMACS_SUB_TIME (temp
, timer_difference
, idle_timer_difference
);
3652 if (EMACS_TIME_NEG_P (temp
))
3654 chosen_timer
= timer
;
3655 timers
= XCDR (timers
);
3656 difference
= timer_difference
;
3660 chosen_timer
= idle_timer
;
3661 idle_timers
= XCDR (idle_timers
);
3662 difference
= idle_timer_difference
;
3665 else if (! NILP (timers
))
3667 chosen_timer
= timer
;
3668 timers
= XCDR (timers
);
3669 difference
= timer_difference
;
3673 chosen_timer
= idle_timer
;
3674 idle_timers
= XCDR (idle_timers
);
3675 difference
= idle_timer_difference
;
3677 vector
= XVECTOR (chosen_timer
)->contents
;
3679 /* If timer is ripe, run it if it hasn't been run. */
3680 if (EMACS_TIME_NEG_P (difference
)
3681 || (EMACS_SECS (difference
) == 0
3682 && EMACS_USECS (difference
) == 0))
3684 if (NILP (vector
[0]))
3686 int was_locked
= single_kboard
;
3687 int count
= specpdl_ptr
- specpdl
;
3689 /* Mark the timer as triggered to prevent problems if the lisp
3690 code fails to reschedule it right. */
3693 specbind (Qinhibit_quit
, Qt
);
3695 call1 (Qtimer_event_handler
, chosen_timer
);
3698 unbind_to (count
, Qnil
);
3700 /* Resume allowing input from any kboard, if that was true before. */
3702 any_kboard_state ();
3704 /* Since we have handled the event,
3705 we don't need to tell the caller to wake up and do it. */
3709 /* When we encounter a timer that is still waiting,
3710 return the amount of time to wait before it is ripe. */
3717 /* No timers are pending in the future. */
3718 /* Return 0 if we generated an event, and -1 if not. */
3723 /* Caches for modify_event_symbol. */
3724 static Lisp_Object accent_key_syms
;
3725 static Lisp_Object func_key_syms
;
3726 static Lisp_Object mouse_syms
;
3728 static Lisp_Object mouse_wheel_syms
;
3730 static Lisp_Object drag_n_drop_syms
;
3732 /* This is a list of keysym codes for special "accent" characters.
3733 It parallels lispy_accent_keys. */
3735 static int lispy_accent_codes
[] =
3737 #ifdef XK_dead_circumflex
3742 #ifdef XK_dead_grave
3747 #ifdef XK_dead_tilde
3752 #ifdef XK_dead_diaeresis
3757 #ifdef XK_dead_macron
3762 #ifdef XK_dead_degree
3767 #ifdef XK_dead_acute
3772 #ifdef XK_dead_cedilla
3777 #ifdef XK_dead_breve
3782 #ifdef XK_dead_ogonek
3787 #ifdef XK_dead_caron
3792 #ifdef XK_dead_doubleacute
3793 XK_dead_doubleacute
,
3797 #ifdef XK_dead_abovedot
3804 /* This is a list of Lisp names for special "accent" characters.
3805 It parallels lispy_accent_codes. */
3807 static char *lispy_accent_keys
[] =
3825 #define FUNCTION_KEY_OFFSET 0x0
3827 char *lispy_function_keys
[] =
3831 0, /* VK_LBUTTON 0x01 */
3832 0, /* VK_RBUTTON 0x02 */
3833 "cancel", /* VK_CANCEL 0x03 */
3834 0, /* VK_MBUTTON 0x04 */
3836 0, 0, 0, /* 0x05 .. 0x07 */
3838 "backspace", /* VK_BACK 0x08 */
3839 "tab", /* VK_TAB 0x09 */
3841 0, 0, /* 0x0A .. 0x0B */
3843 "clear", /* VK_CLEAR 0x0C */
3844 "return", /* VK_RETURN 0x0D */
3846 0, 0, /* 0x0E .. 0x0F */
3848 0, /* VK_SHIFT 0x10 */
3849 0, /* VK_CONTROL 0x11 */
3850 0, /* VK_MENU 0x12 */
3851 "pause", /* VK_PAUSE 0x13 */
3852 "capslock", /* VK_CAPITAL 0x14 */
3854 0, 0, 0, 0, 0, 0, /* 0x15 .. 0x1A */
3856 "escape", /* VK_ESCAPE 0x1B */
3858 0, 0, 0, 0, /* 0x1C .. 0x1F */
3860 0, /* VK_SPACE 0x20 */
3861 "prior", /* VK_PRIOR 0x21 */
3862 "next", /* VK_NEXT 0x22 */
3863 "end", /* VK_END 0x23 */
3864 "home", /* VK_HOME 0x24 */
3865 "left", /* VK_LEFT 0x25 */
3866 "up", /* VK_UP 0x26 */
3867 "right", /* VK_RIGHT 0x27 */
3868 "down", /* VK_DOWN 0x28 */
3869 "select", /* VK_SELECT 0x29 */
3870 "print", /* VK_PRINT 0x2A */
3871 "execute", /* VK_EXECUTE 0x2B */
3872 "snapshot", /* VK_SNAPSHOT 0x2C */
3873 "insert", /* VK_INSERT 0x2D */
3874 "delete", /* VK_DELETE 0x2E */
3875 "help", /* VK_HELP 0x2F */
3877 /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
3879 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3881 0, 0, 0, 0, 0, 0, 0, /* 0x3A .. 0x40 */
3883 /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
3885 0, 0, 0, 0, 0, 0, 0, 0, 0,
3886 0, 0, 0, 0, 0, 0, 0, 0, 0,
3887 0, 0, 0, 0, 0, 0, 0, 0,
3889 "lwindow", /* VK_LWIN 0x5B */
3890 "rwindow", /* VK_RWIN 0x5C */
3891 "apps", /* VK_APPS 0x5D */
3893 0, 0, /* 0x5E .. 0x5F */
3895 "kp-0", /* VK_NUMPAD0 0x60 */
3896 "kp-1", /* VK_NUMPAD1 0x61 */
3897 "kp-2", /* VK_NUMPAD2 0x62 */
3898 "kp-3", /* VK_NUMPAD3 0x63 */
3899 "kp-4", /* VK_NUMPAD4 0x64 */
3900 "kp-5", /* VK_NUMPAD5 0x65 */
3901 "kp-6", /* VK_NUMPAD6 0x66 */
3902 "kp-7", /* VK_NUMPAD7 0x67 */
3903 "kp-8", /* VK_NUMPAD8 0x68 */
3904 "kp-9", /* VK_NUMPAD9 0x69 */
3905 "kp-multiply", /* VK_MULTIPLY 0x6A */
3906 "kp-add", /* VK_ADD 0x6B */
3907 "kp-separator", /* VK_SEPARATOR 0x6C */
3908 "kp-subtract", /* VK_SUBTRACT 0x6D */
3909 "kp-decimal", /* VK_DECIMAL 0x6E */
3910 "kp-divide", /* VK_DIVIDE 0x6F */
3911 "f1", /* VK_F1 0x70 */
3912 "f2", /* VK_F2 0x71 */
3913 "f3", /* VK_F3 0x72 */
3914 "f4", /* VK_F4 0x73 */
3915 "f5", /* VK_F5 0x74 */
3916 "f6", /* VK_F6 0x75 */
3917 "f7", /* VK_F7 0x76 */
3918 "f8", /* VK_F8 0x77 */
3919 "f9", /* VK_F9 0x78 */
3920 "f10", /* VK_F10 0x79 */
3921 "f11", /* VK_F11 0x7A */
3922 "f12", /* VK_F12 0x7B */
3923 "f13", /* VK_F13 0x7C */
3924 "f14", /* VK_F14 0x7D */
3925 "f15", /* VK_F15 0x7E */
3926 "f16", /* VK_F16 0x7F */
3927 "f17", /* VK_F17 0x80 */
3928 "f18", /* VK_F18 0x81 */
3929 "f19", /* VK_F19 0x82 */
3930 "f20", /* VK_F20 0x83 */
3931 "f21", /* VK_F21 0x84 */
3932 "f22", /* VK_F22 0x85 */
3933 "f23", /* VK_F23 0x86 */
3934 "f24", /* VK_F24 0x87 */
3936 0, 0, 0, 0, /* 0x88 .. 0x8B */
3937 0, 0, 0, 0, /* 0x8C .. 0x8F */
3939 "kp-numlock", /* VK_NUMLOCK 0x90 */
3940 "scroll", /* VK_SCROLL 0x91 */
3942 "kp-space", /* VK_NUMPAD_CLEAR 0x92 */
3943 "kp-enter", /* VK_NUMPAD_ENTER 0x93 */
3944 "kp-prior", /* VK_NUMPAD_PRIOR 0x94 */
3945 "kp-next", /* VK_NUMPAD_NEXT 0x95 */
3946 "kp-end", /* VK_NUMPAD_END 0x96 */
3947 "kp-home", /* VK_NUMPAD_HOME 0x97 */
3948 "kp-left", /* VK_NUMPAD_LEFT 0x98 */
3949 "kp-up", /* VK_NUMPAD_UP 0x99 */
3950 "kp-right", /* VK_NUMPAD_RIGHT 0x9A */
3951 "kp-down", /* VK_NUMPAD_DOWN 0x9B */
3952 "kp-insert", /* VK_NUMPAD_INSERT 0x9C */
3953 "kp-delete", /* VK_NUMPAD_DELETE 0x9D */
3955 0, 0, /* 0x9E .. 0x9F */
3958 * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
3959 * Used only as parameters to GetAsyncKeyState and GetKeyState.
3960 * No other API or message will distinguish left and right keys this way.
3964 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3965 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3966 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3967 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3968 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3974 "attn", /* VK_ATTN 0xF6 */
3975 "crsel", /* VK_CRSEL 0xF7 */
3976 "exsel", /* VK_EXSEL 0xF8 */
3977 "ereof", /* VK_EREOF 0xF9 */
3978 "play", /* VK_PLAY 0xFA */
3979 "zoom", /* VK_ZOOM 0xFB */
3980 "noname", /* VK_NONAME 0xFC */
3981 "pa1", /* VK_PA1 0xFD */
3982 "oem_clear", /* VK_OEM_CLEAR 0xFE */
3986 #else /* not HAVE_NTGUI */
3989 static char *lispy_kana_keys
[] =
3991 /* X Keysym value */
3992 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x400 .. 0x40f */
3993 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x410 .. 0x41f */
3994 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x420 .. 0x42f */
3995 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x430 .. 0x43f */
3996 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x440 .. 0x44f */
3997 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x450 .. 0x45f */
3998 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x460 .. 0x46f */
3999 0,0,0,0,0,0,0,0,0,0,0,0,0,0,"overline",0,
4000 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x480 .. 0x48f */
4001 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x490 .. 0x49f */
4002 0, "kana-fullstop", "kana-openingbracket", "kana-closingbracket",
4003 "kana-comma", "kana-conjunctive", "kana-WO", "kana-a",
4004 "kana-i", "kana-u", "kana-e", "kana-o",
4005 "kana-ya", "kana-yu", "kana-yo", "kana-tsu",
4006 "prolongedsound", "kana-A", "kana-I", "kana-U",
4007 "kana-E", "kana-O", "kana-KA", "kana-KI",
4008 "kana-KU", "kana-KE", "kana-KO", "kana-SA",
4009 "kana-SHI", "kana-SU", "kana-SE", "kana-SO",
4010 "kana-TA", "kana-CHI", "kana-TSU", "kana-TE",
4011 "kana-TO", "kana-NA", "kana-NI", "kana-NU",
4012 "kana-NE", "kana-NO", "kana-HA", "kana-HI",
4013 "kana-FU", "kana-HE", "kana-HO", "kana-MA",
4014 "kana-MI", "kana-MU", "kana-ME", "kana-MO",
4015 "kana-YA", "kana-YU", "kana-YO", "kana-RA",
4016 "kana-RI", "kana-RU", "kana-RE", "kana-RO",
4017 "kana-WA", "kana-N", "voicedsound", "semivoicedsound",
4018 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4e0 .. 0x4ef */
4019 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4f0 .. 0x4ff */
4021 #endif /* XK_kana_A */
4023 #define FUNCTION_KEY_OFFSET 0xff00
4025 /* You'll notice that this table is arranged to be conveniently
4026 indexed by X Windows keysym values. */
4027 static char *lispy_function_keys
[] =
4029 /* X Keysym value */
4031 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00...0f */
4032 "backspace", "tab", "linefeed", "clear",
4034 0, 0, 0, "pause", /* 0xff10...1f */
4035 0, 0, 0, 0, 0, 0, 0, "escape",
4037 0, "kanji", "muhenkan", "henkan", /* 0xff20...2f */
4038 "romaji", "hiragana", "katakana", "hiragana-katakana",
4039 "zenkaku", "hankaku", "zenkaku-hankaku", "touroku",
4040 "massyo", "kana-lock", "kana-shift", "eisu-shift",
4041 "eisu-toggle", /* 0xff30...3f */
4042 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4043 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
4045 "home", "left", "up", "right", /* 0xff50 */ /* IsCursorKey */
4046 "down", "prior", "next", "end",
4047 "begin", 0, 0, 0, 0, 0, 0, 0,
4048 "select", /* 0xff60 */ /* IsMiscFunctionKey */
4059 "break", /* 0xff6b */
4062 0, 0, 0, 0, "backtab", 0, 0, 0, /* 0xff70... */
4063 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff78... */
4064 "kp-space", /* 0xff80 */ /* IsKeypadKey */
4065 0, 0, 0, 0, 0, 0, 0, 0,
4066 "kp-tab", /* 0xff89 */
4068 "kp-enter", /* 0xff8d */
4070 "kp-f1", /* 0xff91 */
4074 "kp-home", /* 0xff95 */
4079 "kp-prior", /* kp-page-up */
4080 "kp-next", /* kp-page-down */
4086 0, 0, 0, 0, 0, 0, 0, 0, 0,
4087 "kp-multiply", /* 0xffaa */
4092 "kp-divide", /* 0xffaf */
4093 "kp-0", /* 0xffb0 */
4094 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
4097 "kp-equal", /* 0xffbd */
4098 "f1", /* 0xffbe */ /* IsFunctionKey */
4100 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
4101 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
4102 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
4103 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
4104 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
4105 0, 0, 0, 0, 0, 0, 0, 0,
4106 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
4107 0, 0, 0, 0, 0, 0, 0, "delete"
4110 /* ISO 9995 Function and Modifier Keys; the first byte is 0xFE. */
4111 #define ISO_FUNCTION_KEY_OFFSET 0xfe00
4113 static char *iso_lispy_function_keys
[] =
4115 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe00 */
4116 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe08 */
4117 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe10 */
4118 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe18 */
4119 "iso-lefttab", /* 0xfe20 */
4120 "iso-move-line-up", "iso-move-line-down",
4121 "iso-partial-line-up", "iso-partial-line-down",
4122 "iso-partial-space-left", "iso-partial-space-right",
4123 "iso-set-margin-left", "iso-set-margin-right", /* 0xffe27, 28 */
4124 "iso-release-margin-left", "iso-release-margin-right",
4125 "iso-release-both-margins",
4126 "iso-fast-cursor-left", "iso-fast-cursor-right",
4127 "iso-fast-cursor-up", "iso-fast-cursor-down",
4128 "iso-continuous-underline", "iso-discontinuous-underline", /* 0xfe30, 31 */
4129 "iso-emphasize", "iso-center-object", "iso-enter", /* ... 0xfe34 */
4132 #endif /* not HAVE_NTGUI */
4134 Lisp_Object Vlispy_mouse_stem
;
4137 /* mouse-wheel events are generated by the wheel on devices such as
4138 the MS Intellimouse. The wheel sits in between the left and right
4139 mouse buttons, and is typically used to scroll or zoom the window
4140 underneath the pointer. mouse-wheel events specify the object on
4141 which they operate, and a delta corresponding to the amount and
4142 direction that the wheel is rotated. Clicking the mouse-wheel
4143 generates a mouse-2 event. */
4144 static char *lispy_mouse_wheel_names
[] =
4149 #endif /* WINDOWSNT */
4151 /* drag-n-drop events are generated when a set of selected files are
4152 dragged from another application and dropped onto an Emacs window. */
4153 static char *lispy_drag_n_drop_names
[] =
4158 /* Scroll bar parts. */
4159 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
4160 Lisp_Object Qup
, Qdown
, Qbottom
, Qend_scroll
;
4161 Lisp_Object Qtop
, Qratio
;
4163 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
4164 Lisp_Object
*scroll_bar_parts
[] = {
4165 &Qabove_handle
, &Qhandle
, &Qbelow_handle
,
4166 &Qup
, &Qdown
, &Qtop
, &Qbottom
, &Qend_scroll
, &Qratio
4169 /* User signal events. */
4170 Lisp_Object Qusr1_signal
, Qusr2_signal
;
4172 Lisp_Object
*lispy_user_signals
[] =
4174 &Qusr1_signal
, &Qusr2_signal
4178 /* A vector, indexed by button number, giving the down-going location
4179 of currently depressed buttons, both scroll bar and non-scroll bar.
4181 The elements have the form
4182 (BUTTON-NUMBER MODIFIER-MASK . REST)
4183 where REST is the cdr of a position as it would be reported in the event.
4185 The make_lispy_event function stores positions here to tell the
4186 difference between click and drag events, and to store the starting
4187 location to be included in drag events. */
4189 static Lisp_Object button_down_location
;
4191 /* Information about the most recent up-going button event: Which
4192 button, what location, and what time. */
4194 static int last_mouse_button
;
4195 static int last_mouse_x
;
4196 static int last_mouse_y
;
4197 static unsigned long button_down_time
;
4199 /* The maximum time between clicks to make a double-click,
4200 or Qnil to disable double-click detection,
4201 or Qt for no time limit. */
4202 Lisp_Object Vdouble_click_time
;
4204 /* The number of clicks in this multiple-click. */
4206 int double_click_count
;
4208 /* Given a struct input_event, build the lisp event which represents
4209 it. If EVENT is 0, build a mouse movement event from the mouse
4210 movement buffer, which should have a movement event in it.
4212 Note that events must be passed to this function in the order they
4213 are received; this function stores the location of button presses
4214 in order to build drag events when the button is released. */
4217 make_lispy_event (event
)
4218 struct input_event
*event
;
4222 switch (SWITCH_ENUM_CAST (event
->kind
))
4224 /* A simple keystroke. */
4225 case ascii_keystroke
:
4227 Lisp_Object lispy_c
;
4228 int c
= event
->code
& 0377;
4229 /* Turn ASCII characters into control characters
4231 if (event
->modifiers
& ctrl_modifier
)
4232 c
= make_ctrl_char (c
);
4234 /* Add in the other modifier bits. We took care of ctrl_modifier
4235 just above, and the shift key was taken care of by the X code,
4236 and applied to control characters by make_ctrl_char. */
4237 c
|= (event
->modifiers
4238 & (meta_modifier
| alt_modifier
4239 | hyper_modifier
| super_modifier
));
4240 /* Distinguish Shift-SPC from SPC. */
4241 if ((event
->code
& 0377) == 040
4242 && event
->modifiers
& shift_modifier
)
4243 c
|= shift_modifier
;
4244 button_down_time
= 0;
4245 XSETFASTINT (lispy_c
, c
);
4249 /* A function key. The symbol may need to have modifier prefixes
4251 case non_ascii_keystroke
:
4252 button_down_time
= 0;
4254 for (i
= 0; i
< sizeof (lispy_accent_codes
) / sizeof (int); i
++)
4255 if (event
->code
== lispy_accent_codes
[i
])
4256 return modify_event_symbol (i
,
4258 Qfunction_key
, Qnil
,
4259 lispy_accent_keys
, &accent_key_syms
,
4260 (sizeof (lispy_accent_keys
)
4261 / sizeof (lispy_accent_keys
[0])));
4263 /* Handle system-specific keysyms. */
4264 if (event
->code
& (1 << 28))
4266 /* We need to use an alist rather than a vector as the cache
4267 since we can't make a vector long enuf. */
4268 if (NILP (current_kboard
->system_key_syms
))
4269 current_kboard
->system_key_syms
= Fcons (Qnil
, Qnil
);
4270 return modify_event_symbol (event
->code
,
4273 current_kboard
->Vsystem_key_alist
,
4274 0, ¤t_kboard
->system_key_syms
,
4279 if (event
->code
>= 0x400 && event
->code
< 0x500)
4280 return modify_event_symbol (event
->code
- 0x400,
4281 event
->modifiers
& ~shift_modifier
,
4282 Qfunction_key
, Qnil
,
4283 lispy_kana_keys
, &func_key_syms
,
4284 (sizeof (lispy_kana_keys
)
4285 / sizeof (lispy_kana_keys
[0])));
4286 #endif /* XK_kana_A */
4288 #ifdef ISO_FUNCTION_KEY_OFFSET
4289 if (event
->code
< FUNCTION_KEY_OFFSET
4290 && event
->code
>= ISO_FUNCTION_KEY_OFFSET
)
4291 return modify_event_symbol (event
->code
- ISO_FUNCTION_KEY_OFFSET
,
4293 Qfunction_key
, Qnil
,
4294 iso_lispy_function_keys
, &func_key_syms
,
4295 (sizeof (iso_lispy_function_keys
)
4296 / sizeof (iso_lispy_function_keys
[0])));
4299 return modify_event_symbol (event
->code
- FUNCTION_KEY_OFFSET
,
4301 Qfunction_key
, Qnil
,
4302 lispy_function_keys
, &func_key_syms
,
4303 (sizeof (lispy_function_keys
)
4304 / sizeof (lispy_function_keys
[0])));
4307 /* A mouse click. Figure out where it is, decide whether it's
4308 a press, click or drag, and build the appropriate structure. */
4310 #ifndef USE_TOOLKIT_SCROLL_BARS
4311 case scroll_bar_click
:
4314 int button
= event
->code
;
4316 Lisp_Object position
;
4317 Lisp_Object
*start_pos_ptr
;
4318 Lisp_Object start_pos
;
4320 /* Build the position as appropriate for this mouse click. */
4321 if (event
->kind
== mouse_click
)
4324 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
4327 Lisp_Object string_info
= Qnil
;
4330 /* Ignore mouse events that were made on frame that
4331 have been deleted. */
4332 if (! FRAME_LIVE_P (f
))
4335 /* EVENT->x and EVENT->y are frame-relative pixel
4336 coordinates at this place. Under old redisplay, COLUMN
4337 and ROW are set to frame relative glyph coordinates
4338 which are then used to determine whether this click is
4339 in a menu (non-toolkit version). */
4340 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4341 &column
, &row
, NULL
, 1);
4343 #ifndef USE_X_TOOLKIT
4344 /* In the non-toolkit version, clicks on the menu bar
4345 are ordinary button events in the event buffer.
4346 Distinguish them, and invoke the menu.
4348 (In the toolkit version, the toolkit handles the menu bar
4349 and Emacs doesn't know about it until after the user
4350 makes a selection.) */
4351 if (row
>= 0 && row
< FRAME_MENU_BAR_LINES (f
)
4352 && (event
->modifiers
& down_modifier
))
4354 Lisp_Object items
, item
;
4359 /* Activate the menu bar on the down event. If the
4360 up event comes in before the menu code can deal with it,
4362 if (! (event
->modifiers
& down_modifier
))
4366 /* Find the menu bar item under `column'. */
4368 items
= FRAME_MENU_BAR_ITEMS (f
);
4369 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
4371 Lisp_Object pos
, string
;
4372 string
= XVECTOR (items
)->contents
[i
+ 1];
4373 pos
= XVECTOR (items
)->contents
[i
+ 3];
4376 if (column
>= XINT (pos
)
4377 && column
< XINT (pos
) + XSTRING (string
)->size
)
4379 item
= XVECTOR (items
)->contents
[i
];
4384 /* ELisp manual 2.4b says (x y) are window relative but
4385 code says they are frame-relative. */
4387 = Fcons (event
->frame_or_window
,
4389 Fcons (Fcons (event
->x
, event
->y
),
4390 Fcons (make_number (event
->timestamp
),
4393 return Fcons (item
, Fcons (position
, Qnil
));
4395 #endif /* not USE_X_TOOLKIT */
4397 /* Set `window' to the window under frame pixel coordinates
4398 event->x/event->y. */
4399 window
= window_from_coordinates (f
, XINT (event
->x
),
4400 XINT (event
->y
), &part
, 0);
4402 if (!WINDOWP (window
))
4404 window
= event
->frame_or_window
;
4409 /* It's a click in window window at frame coordinates
4410 event->x/ event->y. */
4411 struct window
*w
= XWINDOW (window
);
4413 /* Get window relative coordinates. Original code
4414 `rounded' this to glyph boundaries. */
4415 int wx
= FRAME_TO_WINDOW_PIXEL_X (w
, XINT (event
->x
));
4416 int wy
= FRAME_TO_WINDOW_PIXEL_Y (w
, XINT (event
->y
));
4418 /* Set event coordinates to window-relative coordinates
4419 for constructing the Lisp event below. */
4420 XSETINT (event
->x
, wx
);
4421 XSETINT (event
->y
, wy
);
4423 if (part
== 1 || part
== 3)
4425 /* Mode line or top line. Look for a string under
4426 the mouse that may have a `local-map' property. */
4430 posn
= part
== 1 ? Qmode_line
: Qheader_line
;
4431 string
= mode_line_string (w
, wx
, wy
, part
== 1, &charpos
);
4432 if (STRINGP (string
))
4433 string_info
= Fcons (string
, make_number (charpos
));
4436 posn
= Qvertical_line
;
4438 XSETINT (posn
, buffer_posn_from_coords (w
, &wx
, &wy
));
4444 Fcons (Fcons (event
->x
, event
->y
),
4445 Fcons (make_number (event
->timestamp
),
4448 : Fcons (string_info
, Qnil
))))));
4450 #ifndef USE_TOOLKIT_SCROLL_BARS
4453 /* It's a scrollbar click. */
4455 Lisp_Object portion_whole
;
4458 window
= event
->frame_or_window
;
4459 portion_whole
= Fcons (event
->x
, event
->y
);
4460 part
= *scroll_bar_parts
[(int) event
->part
];
4464 Fcons (Qvertical_scroll_bar
,
4465 Fcons (portion_whole
,
4466 Fcons (make_number (event
->timestamp
),
4467 Fcons (part
, Qnil
)))));
4469 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4471 if (button
>= XVECTOR (button_down_location
)->size
)
4473 button_down_location
= larger_vector (button_down_location
,
4475 mouse_syms
= larger_vector (mouse_syms
, button
+ 1, Qnil
);
4478 start_pos_ptr
= &XVECTOR (button_down_location
)->contents
[button
];
4480 start_pos
= *start_pos_ptr
;
4481 *start_pos_ptr
= Qnil
;
4483 is_double
= (button
== last_mouse_button
4484 && XINT (event
->x
) == last_mouse_x
4485 && XINT (event
->y
) == last_mouse_y
4486 && button_down_time
!= 0
4487 && (EQ (Vdouble_click_time
, Qt
)
4488 || (INTEGERP (Vdouble_click_time
)
4489 && ((int)(event
->timestamp
- button_down_time
)
4490 < XINT (Vdouble_click_time
)))));
4491 last_mouse_button
= button
;
4492 last_mouse_x
= XINT (event
->x
);
4493 last_mouse_y
= XINT (event
->y
);
4495 /* If this is a button press, squirrel away the location, so
4496 we can decide later whether it was a click or a drag. */
4497 if (event
->modifiers
& down_modifier
)
4501 double_click_count
++;
4502 event
->modifiers
|= ((double_click_count
> 2)
4507 double_click_count
= 1;
4508 button_down_time
= event
->timestamp
;
4509 *start_pos_ptr
= Fcopy_alist (position
);
4512 /* Now we're releasing a button - check the co-ordinates to
4513 see if this was a click or a drag. */
4514 else if (event
->modifiers
& up_modifier
)
4516 /* If we did not see a down before this up,
4517 ignore the up. Probably this happened because
4518 the down event chose a menu item.
4519 It would be an annoyance to treat the release
4520 of the button that chose the menu item
4521 as a separate event. */
4523 if (!CONSP (start_pos
))
4526 event
->modifiers
&= ~up_modifier
;
4527 #if 0 /* Formerly we treated an up with no down as a click event. */
4528 if (!CONSP (start_pos
))
4529 event
->modifiers
|= click_modifier
;
4533 /* The third element of every position should be the (x,y)
4537 down
= Fnth (make_number (2), start_pos
);
4538 if (EQ (event
->x
, XCAR (down
))
4539 && EQ (event
->y
, XCDR (down
)))
4541 event
->modifiers
|= click_modifier
;
4545 button_down_time
= 0;
4546 event
->modifiers
|= drag_modifier
;
4548 /* Don't check is_double; treat this as multiple
4549 if the down-event was multiple. */
4550 if (double_click_count
> 1)
4551 event
->modifiers
|= ((double_click_count
> 2)
4557 /* Every mouse event should either have the down_modifier or
4558 the up_modifier set. */
4562 /* Get the symbol we should use for the mouse click. */
4565 head
= modify_event_symbol (button
,
4567 Qmouse_click
, Vlispy_mouse_stem
,
4570 XVECTOR (mouse_syms
)->size
);
4571 if (event
->modifiers
& drag_modifier
)
4576 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
4579 Fcons (make_number (double_click_count
),
4588 #if USE_TOOLKIT_SCROLL_BARS
4590 /* We don't have down and up events if using toolkit scroll bars,
4591 so make this always a click event. Store in the `part' of
4592 the Lisp event a symbol which maps to the following actions:
4594 `above_handle' page up
4595 `below_handle' page down
4599 `bottom' bottom of buffer
4600 `handle' thumb has been dragged.
4601 `end-scroll' end of interaction with scroll bar
4603 The incoming input_event contains in its `part' member an
4604 index of type `enum scroll_bar_part' which we can use as an
4605 index in scroll_bar_parts to get the appropriate symbol. */
4607 case scroll_bar_click
:
4609 Lisp_Object position
, head
, window
, portion_whole
, part
;
4611 window
= event
->frame_or_window
;
4612 portion_whole
= Fcons (event
->x
, event
->y
);
4613 part
= *scroll_bar_parts
[(int) event
->part
];
4617 Fcons (Qvertical_scroll_bar
,
4618 Fcons (portion_whole
,
4619 Fcons (make_number (event
->timestamp
),
4620 Fcons (part
, Qnil
)))));
4622 /* Always treat scroll bar events as clicks. */
4623 event
->modifiers
|= click_modifier
;
4625 /* Get the symbol we should use for the mouse click. */
4626 head
= modify_event_symbol (event
->code
,
4631 XVECTOR (mouse_syms
)->size
);
4632 return Fcons (head
, Fcons (position
, Qnil
));
4635 #endif /* USE_TOOLKIT_SCROLL_BARS */
4638 case w32_scroll_bar_click
:
4640 int button
= event
->code
;
4642 Lisp_Object position
;
4643 Lisp_Object
*start_pos_ptr
;
4644 Lisp_Object start_pos
;
4648 Lisp_Object portion_whole
;
4651 window
= event
->frame_or_window
;
4652 portion_whole
= Fcons (event
->x
, event
->y
);
4653 part
= *scroll_bar_parts
[(int) event
->part
];
4657 Fcons (Qvertical_scroll_bar
,
4658 Fcons (portion_whole
,
4659 Fcons (make_number (event
->timestamp
),
4660 Fcons (part
, Qnil
)))));
4663 /* Always treat W32 scroll bar events as clicks. */
4664 event
->modifiers
|= click_modifier
;
4667 /* Get the symbol we should use for the mouse click. */
4670 head
= modify_event_symbol (button
,
4675 XVECTOR (mouse_syms
)->size
);
4684 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
4687 Lisp_Object head
, position
;
4690 /* Ignore mouse events that were made on frame that
4691 have been deleted. */
4692 if (! FRAME_LIVE_P (f
))
4694 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4695 &column
, &row
, NULL
, 1);
4696 window
= window_from_coordinates (f
, column
, row
, &part
, 0);
4698 if (!WINDOWP (window
))
4700 window
= event
->frame_or_window
;
4705 int pixcolumn
, pixrow
;
4706 column
-= XINT (XWINDOW (window
)->left
);
4707 row
-= XINT (XWINDOW (window
)->top
);
4708 glyph_to_pixel_coords (XWINDOW(window
), column
, row
,
4709 &pixcolumn
, &pixrow
);
4710 XSETINT (event
->x
, pixcolumn
);
4711 XSETINT (event
->y
, pixrow
);
4716 posn
= Qvertical_line
;
4718 posn
= Qheader_line
;
4721 buffer_posn_from_coords (XWINDOW (window
),
4726 Lisp_Object head
, position
;
4731 Fcons (Fcons (event
->x
, event
->y
),
4732 Fcons (make_number (event
->timestamp
),
4735 head
= modify_event_symbol (0, event
->modifiers
,
4737 lispy_mouse_wheel_names
,
4738 &mouse_wheel_syms
, 1);
4741 Fcons (make_number (event
->code
),
4745 #endif /* WINDOWSNT */
4756 /* The frame_or_window field should be a cons of the frame in
4757 which the event occurred and a list of the filenames
4759 if (! CONSP (event
->frame_or_window
))
4762 f
= XFRAME (XCAR (event
->frame_or_window
));
4763 files
= XCDR (event
->frame_or_window
);
4765 /* Ignore mouse events that were made on frames that
4766 have been deleted. */
4767 if (! FRAME_LIVE_P (f
))
4769 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4770 &column
, &row
, NULL
, 1);
4771 window
= window_from_coordinates (f
, column
, row
, &part
, 0);
4773 if (!WINDOWP (window
))
4775 window
= XCAR (event
->frame_or_window
);
4780 /* It's an event in window `window' at frame coordinates
4781 event->x/ event->y. */
4782 struct window
*w
= XWINDOW (window
);
4784 /* Get window relative coordinates. */
4785 int wx
= FRAME_TO_WINDOW_PIXEL_X (w
, XINT (event
->x
));
4786 int wy
= FRAME_TO_WINDOW_PIXEL_Y (w
, XINT (event
->y
));
4788 /* Set event coordinates to window-relative coordinates
4789 for constructing the Lisp event below. */
4790 XSETINT (event
->x
, wx
);
4791 XSETINT (event
->y
, wy
);
4796 posn
= Qvertical_line
;
4798 posn
= Qheader_line
;
4800 XSETINT (posn
, buffer_posn_from_coords (w
, &wx
, &wy
));
4804 Lisp_Object head
, position
;
4809 Fcons (Fcons (event
->x
, event
->y
),
4810 Fcons (make_number (event
->timestamp
),
4813 head
= modify_event_symbol (0, event
->modifiers
,
4815 lispy_drag_n_drop_names
,
4816 &drag_n_drop_syms
, 1);
4823 #endif /* HAVE_MOUSE */
4825 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
4826 case menu_bar_event
:
4827 /* The event value is in the cdr of the frame_or_window slot. */
4828 if (!CONSP (event
->frame_or_window
))
4830 return XCDR (event
->frame_or_window
);
4833 case TOOL_BAR_EVENT
:
4836 if (!CONSP (event
->frame_or_window
))
4838 key
= XCDR (event
->frame_or_window
);
4840 key
= apply_modifiers (event
->modifiers
, key
);
4845 /* A user signal. */
4846 return *lispy_user_signals
[event
->code
];
4848 /* The 'kind' field of the event is something we don't recognize. */
4857 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
4859 Lisp_Object bar_window
;
4860 enum scroll_bar_part part
;
4864 /* Is it a scroll bar movement? */
4865 if (frame
&& ! NILP (bar_window
))
4867 Lisp_Object part_sym
;
4869 part_sym
= *scroll_bar_parts
[(int) part
];
4870 return Fcons (Qscroll_bar_movement
,
4871 (Fcons (Fcons (bar_window
,
4872 Fcons (Qvertical_scroll_bar
,
4873 Fcons (Fcons (x
, y
),
4874 Fcons (make_number (time
),
4880 /* Or is it an ordinary mouse movement? */
4888 /* It's in a frame; which window on that frame? */
4889 window
= window_from_coordinates (frame
, XINT (x
), XINT (y
), &area
, 0);
4893 if (WINDOWP (window
))
4895 struct window
*w
= XWINDOW (window
);
4898 /* Get window relative coordinates. */
4899 wx
= FRAME_TO_WINDOW_PIXEL_X (w
, XINT (x
));
4900 wy
= FRAME_TO_WINDOW_PIXEL_Y (w
, XINT (y
));
4907 posn
= Qvertical_line
;
4909 posn
= Qheader_line
;
4911 XSETINT (posn
, buffer_posn_from_coords (w
, &wx
, &wy
));
4913 else if (frame
!= 0)
4915 XSETFRAME (window
, frame
);
4926 return Fcons (Qmouse_movement
,
4927 Fcons (Fcons (window
,
4929 Fcons (Fcons (x
, y
),
4930 Fcons (make_number (time
),
4936 #endif /* HAVE_MOUSE */
4938 /* Construct a switch frame event. */
4940 make_lispy_switch_frame (frame
)
4943 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
4946 /* Manipulating modifiers. */
4948 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
4950 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
4951 SYMBOL's name of the end of the modifiers; the string from this
4952 position is the unmodified symbol name.
4954 This doesn't use any caches. */
4957 parse_modifiers_uncached (symbol
, modifier_end
)
4961 struct Lisp_String
*name
;
4965 CHECK_SYMBOL (symbol
, 1);
4968 name
= XSYMBOL (symbol
)->name
;
4970 for (i
= 0; i
+2 <= STRING_BYTES (name
); )
4972 int this_mod_end
= 0;
4975 /* See if the name continues with a modifier word.
4976 Check that the word appears, but don't check what follows it.
4977 Set this_mod and this_mod_end to record what we find. */
4979 switch (name
->data
[i
])
4981 #define SINGLE_LETTER_MOD(BIT) \
4982 (this_mod_end = i + 1, this_mod = BIT)
4985 SINGLE_LETTER_MOD (alt_modifier
);
4989 SINGLE_LETTER_MOD (ctrl_modifier
);
4993 SINGLE_LETTER_MOD (hyper_modifier
);
4997 SINGLE_LETTER_MOD (meta_modifier
);
5001 SINGLE_LETTER_MOD (shift_modifier
);
5005 SINGLE_LETTER_MOD (super_modifier
);
5008 #undef SINGLE_LETTER_MOD
5011 /* If we found no modifier, stop looking for them. */
5012 if (this_mod_end
== 0)
5015 /* Check there is a dash after the modifier, so that it
5016 really is a modifier. */
5017 if (this_mod_end
>= STRING_BYTES (name
)
5018 || name
->data
[this_mod_end
] != '-')
5021 /* This modifier is real; look for another. */
5022 modifiers
|= this_mod
;
5023 i
= this_mod_end
+ 1;
5026 /* Should we include the `click' modifier? */
5027 if (! (modifiers
& (down_modifier
| drag_modifier
5028 | double_modifier
| triple_modifier
))
5029 && i
+ 7 == STRING_BYTES (name
)
5030 && strncmp (name
->data
+ i
, "mouse-", 6) == 0
5031 && ('0' <= name
->data
[i
+ 6] && name
->data
[i
+ 6] <= '9'))
5032 modifiers
|= click_modifier
;
5040 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
5041 prepended to the string BASE[0..BASE_LEN-1].
5042 This doesn't use any caches. */
5044 apply_modifiers_uncached (modifiers
, base
, base_len
, base_len_byte
)
5047 int base_len
, base_len_byte
;
5049 /* Since BASE could contain nulls, we can't use intern here; we have
5050 to use Fintern, which expects a genuine Lisp_String, and keeps a
5053 = (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
5059 /* Only the event queue may use the `up' modifier; it should always
5060 be turned into a click or drag event before presented to lisp code. */
5061 if (modifiers
& up_modifier
)
5064 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
5065 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
5066 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
5067 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
5068 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
5069 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
5070 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
5071 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
5072 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
5073 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
5074 /* The click modifier is denoted by the absence of other modifiers. */
5078 mod_len
= p
- new_mods
;
5082 Lisp_Object new_name
;
5084 new_name
= make_uninit_multibyte_string (mod_len
+ base_len
,
5085 mod_len
+ base_len_byte
);
5086 bcopy (new_mods
, XSTRING (new_name
)->data
, mod_len
);
5087 bcopy (base
, XSTRING (new_name
)->data
+ mod_len
, base_len_byte
);
5089 return Fintern (new_name
, Qnil
);
5094 static char *modifier_names
[] =
5096 "up", "down", "drag", "click", "double", "triple", 0, 0,
5097 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5098 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
5100 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
5102 static Lisp_Object modifier_symbols
;
5104 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
5106 lispy_modifier_list (modifiers
)
5109 Lisp_Object modifier_list
;
5112 modifier_list
= Qnil
;
5113 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
5114 if (modifiers
& (1<<i
))
5115 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
5118 return modifier_list
;
5122 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
5123 where UNMODIFIED is the unmodified form of SYMBOL,
5124 MASK is the set of modifiers present in SYMBOL's name.
5125 This is similar to parse_modifiers_uncached, but uses the cache in
5126 SYMBOL's Qevent_symbol_element_mask property, and maintains the
5127 Qevent_symbol_elements property. */
5130 parse_modifiers (symbol
)
5133 Lisp_Object elements
;
5135 elements
= Fget (symbol
, Qevent_symbol_element_mask
);
5136 if (CONSP (elements
))
5141 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
5142 Lisp_Object unmodified
;
5145 unmodified
= Fintern (make_string (XSYMBOL (symbol
)->name
->data
+ end
,
5146 STRING_BYTES (XSYMBOL (symbol
)->name
) - end
),
5149 if (modifiers
& ~(((EMACS_INT
)1 << VALBITS
) - 1))
5151 XSETFASTINT (mask
, modifiers
);
5152 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
5154 /* Cache the parsing results on SYMBOL. */
5155 Fput (symbol
, Qevent_symbol_element_mask
,
5157 Fput (symbol
, Qevent_symbol_elements
,
5158 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
5160 /* Since we know that SYMBOL is modifiers applied to unmodified,
5161 it would be nice to put that in unmodified's cache.
5162 But we can't, since we're not sure that parse_modifiers is
5169 /* Apply the modifiers MODIFIERS to the symbol BASE.
5170 BASE must be unmodified.
5172 This is like apply_modifiers_uncached, but uses BASE's
5173 Qmodifier_cache property, if present. It also builds
5174 Qevent_symbol_elements properties, since it has that info anyway.
5176 apply_modifiers copies the value of BASE's Qevent_kind property to
5177 the modified symbol. */
5179 apply_modifiers (modifiers
, base
)
5183 Lisp_Object cache
, index
, entry
, new_symbol
;
5185 /* Mask out upper bits. We don't know where this value's been. */
5186 modifiers
&= ((EMACS_INT
)1 << VALBITS
) - 1;
5188 /* The click modifier never figures into cache indices. */
5189 cache
= Fget (base
, Qmodifier_cache
);
5190 XSETFASTINT (index
, (modifiers
& ~click_modifier
));
5191 entry
= assq_no_quit (index
, cache
);
5194 new_symbol
= XCDR (entry
);
5197 /* We have to create the symbol ourselves. */
5198 new_symbol
= apply_modifiers_uncached (modifiers
,
5199 XSYMBOL (base
)->name
->data
,
5200 XSYMBOL (base
)->name
->size
,
5201 STRING_BYTES (XSYMBOL (base
)->name
));
5203 /* Add the new symbol to the base's cache. */
5204 entry
= Fcons (index
, new_symbol
);
5205 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
5207 /* We have the parsing info now for free, so add it to the caches. */
5208 XSETFASTINT (index
, modifiers
);
5209 Fput (new_symbol
, Qevent_symbol_element_mask
,
5210 Fcons (base
, Fcons (index
, Qnil
)));
5211 Fput (new_symbol
, Qevent_symbol_elements
,
5212 Fcons (base
, lispy_modifier_list (modifiers
)));
5215 /* Make sure this symbol is of the same kind as BASE.
5217 You'd think we could just set this once and for all when we
5218 intern the symbol above, but reorder_modifiers may call us when
5219 BASE's property isn't set right; we can't assume that just
5220 because it has a Qmodifier_cache property it must have its
5221 Qevent_kind set right as well. */
5222 if (NILP (Fget (new_symbol
, Qevent_kind
)))
5226 kind
= Fget (base
, Qevent_kind
);
5228 Fput (new_symbol
, Qevent_kind
, kind
);
5235 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
5236 return a symbol with the modifiers placed in the canonical order.
5237 Canonical order is alphabetical, except for down and drag, which
5238 always come last. The 'click' modifier is never written out.
5240 Fdefine_key calls this to make sure that (for example) C-M-foo
5241 and M-C-foo end up being equivalent in the keymap. */
5244 reorder_modifiers (symbol
)
5247 /* It's hopefully okay to write the code this way, since everything
5248 will soon be in caches, and no consing will be done at all. */
5251 parsed
= parse_modifiers (symbol
);
5252 return apply_modifiers ((int) XINT (XCAR (XCDR (parsed
))),
5257 /* For handling events, we often want to produce a symbol whose name
5258 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
5259 to some base, like the name of a function key or mouse button.
5260 modify_event_symbol produces symbols of this sort.
5262 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
5263 is the name of the i'th symbol. TABLE_SIZE is the number of elements
5266 Alternatively, NAME_ALIST_OR_STEM is either an alist mapping codes
5267 into symbol names, or a string specifying a name stem used to
5268 contruct a symbol name or the form `STEM-N', where N is the decimal
5269 representation of SYMBOL_NUM. NAME_ALIST_OR_STEM is used if it is
5270 non-nil; otherwise NAME_TABLE is used.
5272 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
5273 persist between calls to modify_event_symbol that it can use to
5274 store a cache of the symbols it's generated for this NAME_TABLE
5275 before. The object stored there may be a vector or an alist.
5277 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
5279 MODIFIERS is a set of modifier bits (as given in struct input_events)
5280 whose prefixes should be applied to the symbol name.
5282 SYMBOL_KIND is the value to be placed in the event_kind property of
5283 the returned symbol.
5285 The symbols we create are supposed to have an
5286 `event-symbol-elements' property, which lists the modifiers present
5287 in the symbol's name. */
5290 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_alist_or_stem
,
5291 name_table
, symbol_table
, table_size
)
5294 Lisp_Object symbol_kind
;
5295 Lisp_Object name_alist_or_stem
;
5297 Lisp_Object
*symbol_table
;
5298 unsigned int table_size
;
5301 Lisp_Object symbol_int
;
5303 /* Get rid of the "vendor-specific" bit here. */
5304 XSETINT (symbol_int
, symbol_num
& 0xffffff);
5306 /* Is this a request for a valid symbol? */
5307 if (symbol_num
< 0 || symbol_num
>= table_size
)
5310 if (CONSP (*symbol_table
))
5311 value
= Fcdr (assq_no_quit (symbol_int
, *symbol_table
));
5313 /* If *symbol_table doesn't seem to be initialized properly, fix that.
5314 *symbol_table should be a lisp vector TABLE_SIZE elements long,
5315 where the Nth element is the symbol for NAME_TABLE[N], or nil if
5316 we've never used that symbol before. */
5319 if (! VECTORP (*symbol_table
)
5320 || XVECTOR (*symbol_table
)->size
!= table_size
)
5324 XSETFASTINT (size
, table_size
);
5325 *symbol_table
= Fmake_vector (size
, Qnil
);
5328 value
= XVECTOR (*symbol_table
)->contents
[symbol_num
];
5331 /* Have we already used this symbol before? */
5334 /* No; let's create it. */
5335 if (CONSP (name_alist_or_stem
))
5336 value
= Fcdr_safe (Fassq (symbol_int
, name_alist_or_stem
));
5337 else if (STRINGP (name_alist_or_stem
))
5339 int len
= STRING_BYTES (XSTRING (name_alist_or_stem
));
5340 char *buf
= (char *) alloca (len
+ 50);
5341 sprintf (buf
, "%s-%d", XSTRING (name_alist_or_stem
)->data
,
5342 XINT (symbol_int
) + 1);
5343 value
= intern (buf
);
5345 else if (name_table
!= 0 && name_table
[symbol_num
])
5346 value
= intern (name_table
[symbol_num
]);
5348 #ifdef HAVE_WINDOW_SYSTEM
5351 char *name
= x_get_keysym_name (symbol_num
);
5353 value
= intern (name
);
5360 sprintf (buf
, "key-%d", symbol_num
);
5361 value
= intern (buf
);
5364 if (CONSP (*symbol_table
))
5365 *symbol_table
= Fcons (Fcons (symbol_int
, value
), *symbol_table
);
5367 XVECTOR (*symbol_table
)->contents
[symbol_num
] = value
;
5369 /* Fill in the cache entries for this symbol; this also
5370 builds the Qevent_symbol_elements property, which the user
5372 apply_modifiers (modifiers
& click_modifier
, value
);
5373 Fput (value
, Qevent_kind
, symbol_kind
);
5376 /* Apply modifiers to that symbol. */
5377 return apply_modifiers (modifiers
, value
);
5380 /* Convert a list that represents an event type,
5381 such as (ctrl meta backspace), into the usual representation of that
5382 event type as a number or a symbol. */
5384 DEFUN ("event-convert-list", Fevent_convert_list
, Sevent_convert_list
, 1, 1, 0,
5385 "Convert the event description list EVENT-DESC to an event type.\n\
5386 EVENT-DESC should contain one base event type (a character or symbol)\n\
5387 and zero or more modifier names (control, meta, hyper, super, shift, alt,\n\
5388 drag, down, double or triple). The base must be last.\n\
5389 The return value is an event type (a character or symbol) which\n\
5390 has the same base event type and all the specified modifiers.")
5392 Lisp_Object event_desc
;
5400 while (CONSP (rest
))
5408 /* Given a symbol, see if it is a modifier name. */
5409 if (SYMBOLP (elt
) && CONSP (rest
))
5410 this = parse_solitary_modifier (elt
);
5414 else if (!NILP (base
))
5415 error ("Two bases given in one event");
5421 /* Let the symbol A refer to the character A. */
5422 if (SYMBOLP (base
) && XSYMBOL (base
)->name
->size
== 1)
5423 XSETINT (base
, XSYMBOL (base
)->name
->data
[0]);
5425 if (INTEGERP (base
))
5427 /* Turn (shift a) into A. */
5428 if ((modifiers
& shift_modifier
) != 0
5429 && (XINT (base
) >= 'a' && XINT (base
) <= 'z'))
5431 XSETINT (base
, XINT (base
) - ('a' - 'A'));
5432 modifiers
&= ~shift_modifier
;
5435 /* Turn (control a) into C-a. */
5436 if (modifiers
& ctrl_modifier
)
5437 return make_number ((modifiers
& ~ctrl_modifier
)
5438 | make_ctrl_char (XINT (base
)));
5440 return make_number (modifiers
| XINT (base
));
5442 else if (SYMBOLP (base
))
5443 return apply_modifiers (modifiers
, base
);
5445 error ("Invalid base event");
5448 /* Try to recognize SYMBOL as a modifier name.
5449 Return the modifier flag bit, or 0 if not recognized. */
5452 parse_solitary_modifier (symbol
)
5455 struct Lisp_String
*name
= XSYMBOL (symbol
)->name
;
5457 switch (name
->data
[0])
5459 #define SINGLE_LETTER_MOD(BIT) \
5460 if (STRING_BYTES (name) == 1) \
5463 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
5464 if (LEN == STRING_BYTES (name) \
5465 && ! strncmp (name->data, NAME, LEN)) \
5469 SINGLE_LETTER_MOD (alt_modifier
);
5473 MULTI_LETTER_MOD (alt_modifier
, "alt", 3);
5477 SINGLE_LETTER_MOD (ctrl_modifier
);
5481 MULTI_LETTER_MOD (ctrl_modifier
, "ctrl", 4);
5482 MULTI_LETTER_MOD (ctrl_modifier
, "control", 7);
5486 SINGLE_LETTER_MOD (hyper_modifier
);
5490 MULTI_LETTER_MOD (hyper_modifier
, "hyper", 5);
5494 SINGLE_LETTER_MOD (meta_modifier
);
5498 MULTI_LETTER_MOD (meta_modifier
, "meta", 4);
5502 SINGLE_LETTER_MOD (shift_modifier
);
5506 MULTI_LETTER_MOD (shift_modifier
, "shift", 5);
5507 MULTI_LETTER_MOD (super_modifier
, "super", 5);
5508 SINGLE_LETTER_MOD (super_modifier
);
5512 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
5513 MULTI_LETTER_MOD (down_modifier
, "down", 4);
5514 MULTI_LETTER_MOD (double_modifier
, "double", 6);
5518 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
5521 #undef SINGLE_LETTER_MOD
5522 #undef MULTI_LETTER_MOD
5528 /* Return 1 if EVENT is a list whose elements are all integers or symbols.
5529 Such a list is not valid as an event,
5530 but it can be a Lucid-style event type list. */
5533 lucid_event_type_list_p (object
)
5538 if (! CONSP (object
))
5541 for (tail
= object
; CONSP (tail
); tail
= XCDR (tail
))
5545 if (! (INTEGERP (elt
) || SYMBOLP (elt
)))
5552 /* Store into *addr a value nonzero if terminal input chars are available.
5553 Serves the purpose of ioctl (0, FIONREAD, addr)
5554 but works even if FIONREAD does not exist.
5555 (In fact, this may actually read some input.)
5557 If DO_TIMERS_NOW is nonzero, actually run timer events that are ripe. */
5560 get_input_pending (addr
, do_timers_now
)
5564 /* First of all, have we already counted some input? */
5565 *addr
= !NILP (Vquit_flag
) || readable_events (do_timers_now
);
5567 /* If input is being read as it arrives, and we have none, there is none. */
5568 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
5571 /* Try to read some input and see how much we get. */
5573 *addr
= !NILP (Vquit_flag
) || readable_events (do_timers_now
);
5576 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
5579 gobble_input (expected
)
5584 if (interrupt_input
)
5587 mask
= sigblock (sigmask (SIGIO
));
5588 read_avail_input (expected
);
5592 #ifdef POLL_FOR_INPUT
5593 if (read_socket_hook
&& !interrupt_input
&& poll_suppress_count
== 0)
5596 mask
= sigblock (sigmask (SIGALRM
));
5597 read_avail_input (expected
);
5603 read_avail_input (expected
);
5607 /* Put a buffer_switch_event in the buffer
5608 so that read_key_sequence will notice the new current buffer. */
5611 record_asynch_buffer_change ()
5613 struct input_event event
;
5616 event
.kind
= buffer_switch_event
;
5617 event
.frame_or_window
= Qnil
;
5620 /* We don't need a buffer-switch event unless Emacs is waiting for input.
5621 The purpose of the event is to make read_key_sequence look up the
5622 keymaps again. If we aren't in read_key_sequence, we don't need one,
5623 and the event could cause trouble by messing up (input-pending-p). */
5624 tem
= Fwaiting_for_user_input_p ();
5628 /* We never need these events if we have no asynchronous subprocesses. */
5632 /* Make sure no interrupt happens while storing the event. */
5634 if (interrupt_input
)
5637 mask
= sigblock (sigmask (SIGIO
));
5638 kbd_buffer_store_event (&event
);
5645 kbd_buffer_store_event (&event
);
5652 /* Read any terminal input already buffered up by the system
5653 into the kbd_buffer, but do not wait.
5655 EXPECTED should be nonzero if the caller knows there is some input.
5657 Except on VMS, all input is read by this function.
5658 If interrupt_input is nonzero, this function MUST be called
5659 only when SIGIO is blocked.
5661 Returns the number of keyboard chars read, or -1 meaning
5662 this is a bad time to try to read input. */
5665 read_avail_input (expected
)
5668 struct input_event buf
[KBD_BUFFER_SIZE
];
5672 if (read_socket_hook
)
5673 /* No need for FIONREAD or fcntl; just say don't wait. */
5674 nread
= (*read_socket_hook
) (input_fd
, buf
, KBD_BUFFER_SIZE
, expected
);
5677 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
5678 the kbd_buffer can really hold. That may prevent loss
5679 of characters on some systems when input is stuffed at us. */
5680 unsigned char cbuf
[KBD_BUFFER_SIZE
- 1];
5683 /* Determine how many characters we should *try* to read. */
5686 #else /* not WINDOWSNT */
5688 n_to_read
= dos_keysns ();
5691 #else /* not MSDOS */
5693 /* Find out how much input is available. */
5694 if (ioctl (input_fd
, FIONREAD
, &n_to_read
) < 0)
5695 /* Formerly simply reported no input, but that sometimes led to
5696 a failure of Emacs to terminate.
5697 SIGHUP seems appropriate if we can't reach the terminal. */
5698 /* ??? Is it really right to send the signal just to this process
5699 rather than to the whole process group?
5700 Perhaps on systems with FIONREAD Emacs is alone in its group. */
5701 kill (getpid (), SIGHUP
);
5704 if (n_to_read
> sizeof cbuf
)
5705 n_to_read
= sizeof cbuf
;
5706 #else /* no FIONREAD */
5707 #if defined (USG) || defined (DGUX)
5708 /* Read some input if available, but don't wait. */
5709 n_to_read
= sizeof cbuf
;
5710 fcntl (input_fd
, F_SETFL
, O_NDELAY
);
5715 #endif /* not MSDOS */
5716 #endif /* not WINDOWSNT */
5718 /* Now read; for one reason or another, this will not block.
5719 NREAD is set to the number of chars read. */
5723 cbuf
[0] = dos_keyread ();
5726 nread
= emacs_read (input_fd
, cbuf
, n_to_read
);
5728 /* POSIX infers that processes which are not in the session leader's
5729 process group won't get SIGHUP's at logout time. BSDI adheres to
5730 this part standard and returns -1 from read (0) with errno==EIO
5731 when the control tty is taken away.
5732 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
5733 if (nread
== -1 && errno
== EIO
)
5735 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
5736 /* The kernel sometimes fails to deliver SIGHUP for ptys.
5737 This looks incorrect, but it isn't, because _BSD causes
5738 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
5739 and that causes a value other than 0 when there is no input. */
5745 /* We used to retry the read if it was interrupted.
5746 But this does the wrong thing when O_NDELAY causes
5747 an EAGAIN error. Does anybody know of a situation
5748 where a retry is actually needed? */
5750 nread
< 0 && (errno
== EAGAIN
5764 #if defined (USG) || defined (DGUX)
5765 fcntl (input_fd
, F_SETFL
, 0);
5766 #endif /* USG or DGUX */
5767 #endif /* no FIONREAD */
5768 for (i
= 0; i
< nread
; i
++)
5770 buf
[i
].kind
= ascii_keystroke
;
5771 buf
[i
].modifiers
= 0;
5772 if (meta_key
== 1 && (cbuf
[i
] & 0x80))
5773 buf
[i
].modifiers
= meta_modifier
;
5777 buf
[i
].code
= cbuf
[i
];
5778 buf
[i
].frame_or_window
= selected_frame
;
5782 /* Scan the chars for C-g and store them in kbd_buffer. */
5783 for (i
= 0; i
< nread
; i
++)
5785 kbd_buffer_store_event (&buf
[i
]);
5786 /* Don't look at input that follows a C-g too closely.
5787 This reduces lossage due to autorepeat on C-g. */
5788 if (buf
[i
].kind
== ascii_keystroke
5789 && buf
[i
].code
== quit_char
)
5795 #endif /* not VMS */
5797 #ifdef SIGIO /* for entire page */
5798 /* Note SIGIO has been undef'd if FIONREAD is missing. */
5801 input_available_signal (signo
)
5804 /* Must preserve main program's value of errno. */
5805 int old_errno
= errno
;
5807 extern int select_alarmed
;
5810 #if defined (USG) && !defined (POSIX_SIGNALS)
5811 /* USG systems forget handlers when they are used;
5812 must reestablish each time */
5813 signal (signo
, input_available_signal
);
5820 if (input_available_clear_time
)
5821 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
5826 nread
= read_avail_input (1);
5827 /* -1 means it's not ok to read the input now.
5828 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
5829 0 means there was no keyboard input available. */
5834 select_alarmed
= 1; /* Force the select emulator back to life */
5845 /* Send ourselves a SIGIO.
5847 This function exists so that the UNBLOCK_INPUT macro in
5848 blockinput.h can have some way to take care of input we put off
5849 dealing with, without assuming that every file which uses
5850 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
5852 reinvoke_input_signal ()
5855 kill (getpid (), SIGIO
);
5861 /* Return the prompt-string of a sparse keymap.
5862 This is the first element which is a string.
5863 Return nil if there is none. */
5871 register Lisp_Object tem
;
5880 static void menu_bar_item ();
5881 static void menu_bar_one_keymap ();
5883 /* These variables hold the vector under construction within
5884 menu_bar_items and its subroutines, and the current index
5885 for storing into that vector. */
5886 static Lisp_Object menu_bar_items_vector
;
5887 static int menu_bar_items_index
;
5889 /* Return a vector of menu items for a menu bar, appropriate
5890 to the current buffer. Each item has three elements in the vector:
5893 OLD is an old vector we can optionally reuse, or nil. */
5896 menu_bar_items (old
)
5899 /* The number of keymaps we're scanning right now, and the number of
5900 keymaps we have allocated space for. */
5903 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
5904 in the current keymaps, or nil where it is not a prefix. */
5907 Lisp_Object def
, tem
, tail
;
5916 struct gcpro gcpro1
;
5918 /* In order to build the menus, we need to call the keymap
5919 accessors. They all call QUIT. But this function is called
5920 during redisplay, during which a quit is fatal. So inhibit
5921 quitting while building the menus.
5922 We do this instead of specbind because (1) errors will clear it anyway
5923 and (2) this avoids risk of specpdl overflow. */
5924 oquit
= Vinhibit_quit
;
5928 menu_bar_items_vector
= old
;
5930 menu_bar_items_vector
= Fmake_vector (make_number (24), Qnil
);
5931 menu_bar_items_index
= 0;
5933 GCPRO1 (menu_bar_items_vector
);
5935 /* Build our list of keymaps.
5936 If we recognize a function key and replace its escape sequence in
5937 keybuf with its symbol, or if the sequence starts with a mouse
5938 click and we need to switch buffers, we jump back here to rebuild
5939 the initial keymaps from the current buffer. */
5943 /* Should overriding-terminal-local-map and overriding-local-map apply? */
5944 if (!NILP (Voverriding_local_map_menu_flag
))
5946 /* Yes, use them (if non-nil) as well as the global map. */
5947 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
5949 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
5950 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
5951 if (!NILP (Voverriding_local_map
))
5952 maps
[nmaps
++] = Voverriding_local_map
;
5956 /* No, so use major and minor mode keymaps and keymap property. */
5958 Lisp_Object map
= get_local_map (PT
, current_buffer
, keymap
);
5961 nmaps
= current_minor_maps (NULL
, &tmaps
);
5962 maps
= (Lisp_Object
*) alloca ((nmaps
+ extra_maps
)
5963 * sizeof (maps
[0]));
5964 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
5966 maps
[nmaps
++] = get_local_map (PT
, current_buffer
, keymap
);
5967 maps
[nmaps
++] = get_local_map (PT
, current_buffer
, local_map
);
5969 maps
[nmaps
++] = current_global_map
;
5972 /* Look up in each map the dummy prefix key `menu-bar'. */
5976 for (mapno
= nmaps
- 1; mapno
>= 0; mapno
--)
5978 if (! NILP (maps
[mapno
]))
5979 def
= get_keyelt (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0), 0);
5983 tem
= Fkeymapp (def
);
5985 menu_bar_one_keymap (def
);
5988 /* Move to the end those items that should be at the end. */
5990 for (tail
= Vmenu_bar_final_items
; CONSP (tail
); tail
= XCDR (tail
))
5993 int end
= menu_bar_items_index
;
5995 for (i
= 0; i
< end
; i
+= 4)
5996 if (EQ (XCAR (tail
), XVECTOR (menu_bar_items_vector
)->contents
[i
]))
5998 Lisp_Object tem0
, tem1
, tem2
, tem3
;
5999 /* Move the item at index I to the end,
6000 shifting all the others forward. */
6001 tem0
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 0];
6002 tem1
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 1];
6003 tem2
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
6004 tem3
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3];
6006 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
6007 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
6008 (end
- i
- 4) * sizeof (Lisp_Object
));
6009 XVECTOR (menu_bar_items_vector
)->contents
[end
- 4] = tem0
;
6010 XVECTOR (menu_bar_items_vector
)->contents
[end
- 3] = tem1
;
6011 XVECTOR (menu_bar_items_vector
)->contents
[end
- 2] = tem2
;
6012 XVECTOR (menu_bar_items_vector
)->contents
[end
- 1] = tem3
;
6017 /* Add nil, nil, nil, nil at the end. */
6018 i
= menu_bar_items_index
;
6019 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
6022 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
6023 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
6024 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
6025 menu_bar_items_vector
= tem
;
6027 /* Add this item. */
6028 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
6029 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
6030 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
6031 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
6032 menu_bar_items_index
= i
;
6034 Vinhibit_quit
= oquit
;
6036 return menu_bar_items_vector
;
6039 /* Scan one map KEYMAP, accumulating any menu items it defines
6040 in menu_bar_items_vector. */
6042 static Lisp_Object menu_bar_one_keymap_changed_items
;
6045 menu_bar_one_keymap (keymap
)
6048 Lisp_Object tail
, item
;
6050 menu_bar_one_keymap_changed_items
= Qnil
;
6052 /* Loop over all keymap entries that have menu strings. */
6053 for (tail
= keymap
; CONSP (tail
); tail
= XCDR (tail
))
6057 menu_bar_item (XCAR (item
), XCDR (item
));
6058 else if (VECTORP (item
))
6060 /* Loop over the char values represented in the vector. */
6061 int len
= XVECTOR (item
)->size
;
6063 for (c
= 0; c
< len
; c
++)
6065 Lisp_Object character
;
6066 XSETFASTINT (character
, c
);
6067 menu_bar_item (character
, XVECTOR (item
)->contents
[c
]);
6073 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
6074 If there's already an item for KEY, add this DEF to it. */
6076 Lisp_Object item_properties
;
6079 menu_bar_item (key
, item
)
6080 Lisp_Object key
, item
;
6082 struct gcpro gcpro1
;
6086 if (EQ (item
, Qundefined
))
6088 /* If a map has an explicit `undefined' as definition,
6089 discard any previously made menu bar item. */
6091 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
6092 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
6094 if (menu_bar_items_index
> i
+ 4)
6095 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
6096 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
6097 (menu_bar_items_index
- i
- 4) * sizeof (Lisp_Object
));
6098 menu_bar_items_index
-= 4;
6102 /* If there's no definition for this key yet,
6103 just ignore `undefined'. */
6107 GCPRO1 (key
); /* Is this necessary? */
6108 i
= parse_menu_item (item
, 0, 1);
6113 /* If this keymap has already contributed to this KEY,
6114 don't contribute to it a second time. */
6115 tem
= Fmemq (key
, menu_bar_one_keymap_changed_items
);
6119 menu_bar_one_keymap_changed_items
6120 = Fcons (key
, menu_bar_one_keymap_changed_items
);
6122 item
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
6124 /* Find any existing item for this KEY. */
6125 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
6126 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
6129 /* If we did not find this KEY, add it at the end. */
6130 if (i
== menu_bar_items_index
)
6132 /* If vector is too small, get a bigger one. */
6133 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
6136 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
6137 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
6138 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
6139 menu_bar_items_vector
= tem
;
6142 /* Add this item. */
6143 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = key
;
6144 XVECTOR (menu_bar_items_vector
)->contents
[i
++]
6145 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
6146 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Fcons (item
, Qnil
);
6147 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = make_number (0);
6148 menu_bar_items_index
= i
;
6150 /* We did find an item for this KEY. Add ITEM to its list of maps. */
6154 old
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
6155 XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2] = Fcons (item
, old
);
6159 /* This is used as the handler when calling menu_item_eval_property. */
6161 menu_item_eval_property_1 (arg
)
6164 /* If we got a quit from within the menu computation,
6165 quit all the way out of it. This takes care of C-] in the debugger. */
6166 if (CONSP (arg
) && EQ (XCAR (arg
), Qquit
))
6167 Fsignal (Qquit
, Qnil
);
6172 /* Evaluate an expression and return the result (or nil if something
6173 went wrong). Used to evaluate dynamic parts of menu items. */
6175 menu_item_eval_property (sexpr
)
6178 int count
= specpdl_ptr
- specpdl
;
6180 specbind (Qinhibit_redisplay
, Qt
);
6181 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
,
6182 menu_item_eval_property_1
);
6183 return unbind_to (count
, val
);
6186 /* This function parses a menu item and leaves the result in the
6187 vector item_properties.
6188 ITEM is a key binding, a possible menu item.
6189 If NOTREAL is nonzero, only check for equivalent key bindings, don't
6190 evaluate dynamic expressions in the menu item.
6191 INMENUBAR is > 0 when this is considered for an entry in a menu bar
6193 INMENUBAR is < 0 when this is considered for an entry in a keyboard menu.
6194 parse_menu_item returns true if the item is a menu item and false
6198 parse_menu_item (item
, notreal
, inmenubar
)
6200 int notreal
, inmenubar
;
6202 Lisp_Object def
, tem
, item_string
, start
;
6203 Lisp_Object cachelist
;
6205 Lisp_Object keyhint
;
6216 /* Create item_properties vector if necessary. */
6217 if (NILP (item_properties
))
6219 = Fmake_vector (make_number (ITEM_PROPERTY_ENABLE
+ 1), Qnil
);
6221 /* Initialize optional entries. */
6222 for (i
= ITEM_PROPERTY_DEF
; i
< ITEM_PROPERTY_ENABLE
; i
++)
6223 XVECTOR (item_properties
)->contents
[i
] = Qnil
;
6224 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
] = Qt
;
6226 /* Save the item here to protect it from GC. */
6227 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ITEM
] = item
;
6229 item_string
= XCAR (item
);
6233 if (STRINGP (item_string
))
6235 /* Old format menu item. */
6236 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
] = item_string
;
6238 /* Maybe help string. */
6239 if (CONSP (item
) && STRINGP (XCAR (item
)))
6241 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_HELP
]
6247 /* Maybee key binding cache. */
6248 if (CONSP (item
) && CONSP (XCAR (item
))
6249 && (NILP (XCAR (XCAR (item
)))
6250 || VECTORP (XCAR (XCAR (item
)))))
6252 cachelist
= XCAR (item
);
6256 /* This is the real definition--the function to run. */
6257 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
] = item
;
6259 /* Get enable property, if any. */
6262 tem
= Fget (item
, Qmenu_enable
);
6264 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
] = tem
;
6267 else if (EQ (item_string
, Qmenu_item
) && CONSP (item
))
6269 /* New format menu item. */
6270 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
]
6272 start
= XCDR (item
);
6275 /* We have a real binding. */
6276 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
]
6279 item
= XCDR (start
);
6280 /* Is there a cache list with key equivalences. */
6281 if (CONSP (item
) && CONSP (XCAR (item
)))
6283 cachelist
= XCAR (item
);
6287 /* Parse properties. */
6288 while (CONSP (item
) && CONSP (XCDR (item
)))
6293 if (EQ (tem
, QCenable
))
6294 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
]
6296 else if (EQ (tem
, QCvisible
) && !notreal
)
6298 /* If got a visible property and that evaluates to nil
6299 then ignore this item. */
6300 tem
= menu_item_eval_property (XCAR (item
));
6304 else if (EQ (tem
, QChelp
))
6305 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_HELP
]
6307 else if (EQ (tem
, QCfilter
))
6309 else if (EQ (tem
, QCkey_sequence
))
6312 if (NILP (cachelist
)
6313 && (SYMBOLP (tem
) || STRINGP (tem
) || VECTORP (tem
)))
6314 /* Be GC protected. Set keyhint to item instead of tem. */
6317 else if (EQ (tem
, QCkeys
))
6320 if (CONSP (tem
) || (STRINGP (tem
) && NILP (cachelist
)))
6321 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
]
6324 else if (EQ (tem
, QCbutton
) && CONSP (XCAR (item
)))
6329 if (EQ (type
, QCtoggle
) || EQ (type
, QCradio
))
6331 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
]
6333 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_TYPE
]
6340 else if (inmenubar
|| !NILP (start
))
6344 return 0; /* not a menu item */
6346 /* If item string is not a string, evaluate it to get string.
6347 If we don't get a string, skip this item. */
6348 item_string
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
6349 if (!(STRINGP (item_string
) || notreal
))
6351 item_string
= menu_item_eval_property (item_string
);
6352 if (!STRINGP (item_string
))
6354 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
] = item_string
;
6357 /* If got a filter apply it on definition. */
6358 def
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
6361 def
= menu_item_eval_property (list2 (XCAR (filter
),
6362 list2 (Qquote
, def
)));
6364 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
] = def
;
6367 /* If we got no definition, this item is just unselectable text which
6368 is OK in a submenu but not in the menubar. */
6370 return (inmenubar
? 0 : 1);
6372 /* Enable or disable selection of item. */
6373 tem
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
];
6379 tem
= menu_item_eval_property (tem
);
6380 if (inmenubar
&& NILP (tem
))
6381 return 0; /* Ignore disabled items in menu bar. */
6382 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
] = tem
;
6385 /* See if this is a separate pane or a submenu. */
6386 def
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
6387 tem
= get_keymap_1 (def
, 0, 1);
6388 /* For a subkeymap, just record its details and exit. */
6391 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_MAP
] = tem
;
6392 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
] = tem
;
6395 /* At the top level in the menu bar, do likewise for commands also.
6396 The menu bar does not display equivalent key bindings anyway.
6397 ITEM_PROPERTY_DEF is already set up properly. */
6401 /* This is a command. See if there is an equivalent key binding. */
6402 if (NILP (cachelist
))
6404 /* We have to create a cachelist. */
6405 CHECK_IMPURE (start
);
6406 XCDR (start
) = Fcons (Fcons (Qnil
, Qnil
), XCDR (start
));
6407 cachelist
= XCAR (XCDR (start
));
6409 tem
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
6410 if (!NILP (keyhint
))
6412 XCAR (cachelist
) = XCAR (keyhint
);
6415 else if (STRINGP (tem
))
6417 XCDR (cachelist
) = Fsubstitute_command_keys (tem
);
6418 XCAR (cachelist
) = Qt
;
6421 tem
= XCAR (cachelist
);
6428 tem
= Fkey_binding (tem
, Qnil
);
6430 prefix
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
6433 def
= XCAR (prefix
);
6434 prefix
= XCDR (prefix
);
6437 def
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
6439 if (NILP (XCAR (cachelist
))) /* Have no saved key. */
6441 if (newcache
/* Always check first time. */
6442 /* Should we check everything when precomputing key
6445 /* If something had no key binding before, don't recheck it
6446 because that is too slow--except if we have a list of
6447 rebound commands in Vdefine_key_rebound_commands, do
6448 recheck any command that appears in that list. */
6449 || (CONSP (Vdefine_key_rebound_commands
)
6450 && !NILP (Fmemq (def
, Vdefine_key_rebound_commands
))))
6453 /* We had a saved key. Is it still bound to the command? */
6456 /* If the command is an alias for another
6457 (such as lmenu.el set it up), check if the
6458 original command matches the cached command. */
6459 && !(SYMBOLP (def
) && EQ (tem
, XSYMBOL (def
)->function
))))
6460 chkcache
= 1; /* Need to recompute key binding. */
6464 /* Recompute equivalent key binding. If the command is an alias
6465 for another (such as lmenu.el set it up), see if the original
6466 command name has equivalent keys. Otherwise look up the
6467 specified command itself. We don't try both, because that
6468 makes lmenu menus slow. */
6469 if (SYMBOLP (def
) && SYMBOLP (XSYMBOL (def
)->function
)
6470 && ! NILP (Fget (def
, Qmenu_alias
)))
6471 def
= XSYMBOL (def
)->function
;
6472 tem
= Fwhere_is_internal (def
, Qnil
, Qt
, Qnil
);
6473 XCAR (cachelist
) = tem
;
6476 XCDR (cachelist
) = Qnil
;
6480 else if (!NILP (keyhint
) && !NILP (XCAR (cachelist
)))
6482 tem
= XCAR (cachelist
);
6486 newcache
= chkcache
;
6489 tem
= Fkey_description (tem
);
6492 if (STRINGP (XCAR (prefix
)))
6493 tem
= concat2 (XCAR (prefix
), tem
);
6494 if (STRINGP (XCDR (prefix
)))
6495 tem
= concat2 (tem
, XCDR (prefix
));
6497 XCDR (cachelist
) = tem
;
6501 tem
= XCDR (cachelist
);
6502 if (newcache
&& !NILP (tem
))
6504 tem
= concat3 (build_string (" ("), tem
, build_string (")"));
6505 XCDR (cachelist
) = tem
;
6508 /* If we only want to precompute equivalent key bindings, stop here. */
6512 /* If we have an equivalent key binding, use that. */
6513 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
] = tem
;
6515 /* Include this when menu help is implemented.
6516 tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP];
6517 if (!(NILP (tem) || STRINGP (tem)))
6519 tem = menu_item_eval_property (tem);
6522 XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP] = tem;
6526 /* Handle radio buttons or toggle boxes. */
6527 tem
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
];
6529 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
]
6530 = menu_item_eval_property (tem
);
6537 /***********************************************************************
6539 ***********************************************************************/
6541 /* A vector holding tool bar items while they are parsed in function
6542 tool_bar_items runs Each item occupies TOOL_BAR_ITEM_NSCLOTS elements
6545 static Lisp_Object tool_bar_items_vector
;
6547 /* A vector holding the result of parse_tool_bar_item. Layout is like
6548 the one for a single item in tool_bar_items_vector. */
6550 static Lisp_Object tool_bar_item_properties
;
6552 /* Next free index in tool_bar_items_vector. */
6554 static int ntool_bar_items
;
6556 /* The symbols `tool-bar', and `:image'. */
6558 extern Lisp_Object Qtool_bar
;
6559 Lisp_Object QCimage
;
6561 /* Function prototypes. */
6563 static void init_tool_bar_items
P_ ((Lisp_Object
));
6564 static void process_tool_bar_item
P_ ((Lisp_Object
, Lisp_Object
));
6565 static int parse_tool_bar_item
P_ ((Lisp_Object
, Lisp_Object
));
6566 static void append_tool_bar_item
P_ ((void));
6569 /* Return a vector of tool bar items for keymaps currently in effect.
6570 Reuse vector REUSE if non-nil. Return in *NITEMS the number of
6571 tool bar items found. */
6574 tool_bar_items (reuse
, nitems
)
6582 extern Lisp_Object Voverriding_local_map_menu_flag
;
6583 extern Lisp_Object Voverriding_local_map
;
6587 /* In order to build the menus, we need to call the keymap
6588 accessors. They all call QUIT. But this function is called
6589 during redisplay, during which a quit is fatal. So inhibit
6590 quitting while building the menus. We do this instead of
6591 specbind because (1) errors will clear it anyway and (2) this
6592 avoids risk of specpdl overflow. */
6593 oquit
= Vinhibit_quit
;
6596 /* Initialize tool_bar_items_vector and protect it from GC. */
6597 init_tool_bar_items (reuse
);
6599 /* Build list of keymaps in maps. Set nmaps to the number of maps
6602 /* Should overriding-terminal-local-map and overriding-local-map apply? */
6603 if (!NILP (Voverriding_local_map_menu_flag
))
6605 /* Yes, use them (if non-nil) as well as the global map. */
6606 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
6608 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
6609 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
6610 if (!NILP (Voverriding_local_map
))
6611 maps
[nmaps
++] = Voverriding_local_map
;
6615 /* No, so use major and minor mode keymaps and keymap property. */
6617 Lisp_Object map
= get_local_map (PT
, current_buffer
, keymap
);
6620 nmaps
= current_minor_maps (NULL
, &tmaps
);
6621 maps
= (Lisp_Object
*) alloca ((nmaps
+ extra_maps
)
6622 * sizeof (maps
[0]));
6623 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
6625 maps
[nmaps
++] = get_local_map (PT
, current_buffer
, keymap
);
6626 maps
[nmaps
++] = get_local_map (PT
, current_buffer
, local_map
);
6629 /* Add global keymap at the end. */
6630 maps
[nmaps
++] = current_global_map
;
6632 /* Process maps in reverse order and look up in each map the prefix
6634 for (i
= nmaps
- 1; i
>= 0; --i
)
6635 if (!NILP (maps
[i
]))
6639 keymap
= get_keyelt (access_keymap (maps
[i
], Qtool_bar
, 1, 1), 0);
6640 if (!NILP (Fkeymapp (keymap
)))
6644 /* KEYMAP is a list `(keymap (KEY . BINDING) ...)'. */
6645 for (tail
= keymap
; CONSP (tail
); tail
= XCDR (tail
))
6647 Lisp_Object keydef
= XCAR (tail
);
6649 process_tool_bar_item (XCAR (keydef
), XCDR (keydef
));
6654 Vinhibit_quit
= oquit
;
6655 *nitems
= ntool_bar_items
/ TOOL_BAR_ITEM_NSLOTS
;
6656 return tool_bar_items_vector
;
6660 /* Process the definition of KEY which is DEF. */
6663 process_tool_bar_item (key
, def
)
6664 Lisp_Object key
, def
;
6667 extern Lisp_Object Qundefined
;
6668 struct gcpro gcpro1
, gcpro2
;
6670 /* Protect KEY and DEF from GC because parse_tool_bar_item may call
6674 if (EQ (def
, Qundefined
))
6676 /* If a map has an explicit `undefined' as definition,
6677 discard any previously made item. */
6678 for (i
= 0; i
< ntool_bar_items
; i
+= TOOL_BAR_ITEM_NSLOTS
)
6680 Lisp_Object
*v
= XVECTOR (tool_bar_items_vector
)->contents
+ i
;
6682 if (EQ (key
, v
[TOOL_BAR_ITEM_KEY
]))
6684 if (ntool_bar_items
> i
+ TOOL_BAR_ITEM_NSLOTS
)
6685 bcopy (v
+ TOOL_BAR_ITEM_NSLOTS
, v
,
6686 ((ntool_bar_items
- i
- TOOL_BAR_ITEM_NSLOTS
)
6687 * sizeof (Lisp_Object
)));
6688 ntool_bar_items
-= TOOL_BAR_ITEM_NSLOTS
;
6693 else if (parse_tool_bar_item (key
, def
))
6694 /* Append a new tool bar item to tool_bar_items_vector. Accept
6695 more than one definition for the same key. */
6696 append_tool_bar_item ();
6702 /* Parse a tool bar item specification ITEM for key KEY and return the
6703 result in tool_bar_item_properties. Value is zero if ITEM is
6706 ITEM is a list `(menu-item CAPTION BINDING PROPS...)'.
6708 CAPTION is the caption of the item, If it's not a string, it is
6709 evaluated to get a string.
6711 BINDING is the tool bar item's binding. Tool-bar items with keymaps
6712 as binding are currently ignored.
6714 The following properties are recognized:
6718 FORM is evaluated and specifies whether the tool bar item is
6719 enabled or disabled.
6723 FORM is evaluated and specifies whether the tool bar item is visible.
6725 - `:filter FUNCTION'
6727 FUNCTION is invoked with one parameter `(quote BINDING)'. Its
6728 result is stored as the new binding.
6730 - `:button (TYPE SELECTED)'
6732 TYPE must be one of `:radio' or `:toggle'. SELECTED is evaluated
6733 and specifies whether the button is selected (pressed) or not.
6737 IMAGES is either a single image specification or a vector of four
6738 image specifications. See enum tool_bar_item_images.
6740 - `:help HELP-STRING'.
6742 Gives a help string to display for the tool bar item. */
6745 parse_tool_bar_item (key
, item
)
6746 Lisp_Object key
, item
;
6748 /* Access slot with index IDX of vector tool_bar_item_properties. */
6749 #define PROP(IDX) XVECTOR (tool_bar_item_properties)->contents[IDX]
6751 Lisp_Object filter
= Qnil
;
6752 Lisp_Object caption
;
6753 extern Lisp_Object QCenable
, QCvisible
, QChelp
, QCfilter
;
6754 extern Lisp_Object QCbutton
, QCtoggle
, QCradio
;
6757 /* Defininition looks like `(tool-bar-item CAPTION BINDING
6758 PROPS...)'. Rule out items that aren't lists, don't start with
6759 `tool-bar-item' or whose rest following `tool-bar-item' is not a
6762 || !EQ (XCAR (item
), Qmenu_item
)
6763 || (item
= XCDR (item
),
6767 /* Create tool_bar_item_properties vector if necessary. Reset it to
6769 if (VECTORP (tool_bar_item_properties
))
6771 for (i
= 0; i
< TOOL_BAR_ITEM_NSLOTS
; ++i
)
6775 tool_bar_item_properties
6776 = Fmake_vector (make_number (TOOL_BAR_ITEM_NSLOTS
), Qnil
);
6779 PROP (TOOL_BAR_ITEM_KEY
) = key
;
6780 PROP (TOOL_BAR_ITEM_ENABLED_P
) = Qt
;
6782 /* Get the caption of the item. If the caption is not a string,
6783 evaluate it to get a string. If we don't get a string, skip this
6785 caption
= XCAR (item
);
6786 if (!STRINGP (caption
))
6788 caption
= menu_item_eval_property (caption
);
6789 if (!STRINGP (caption
))
6792 PROP (TOOL_BAR_ITEM_CAPTION
) = caption
;
6794 /* Give up if rest following the caption is not a list. */
6799 /* Store the binding. */
6800 PROP (TOOL_BAR_ITEM_BINDING
) = XCAR (item
);
6803 /* Process the rest of the properties. */
6804 for (; CONSP (item
) && CONSP (XCDR (item
)); item
= XCDR (XCDR (item
)))
6806 Lisp_Object key
, value
;
6809 value
= XCAR (XCDR (item
));
6811 if (EQ (key
, QCenable
))
6812 /* `:enable FORM'. */
6813 PROP (TOOL_BAR_ITEM_ENABLED_P
) = value
;
6814 else if (EQ (key
, QCvisible
))
6816 /* `:visible FORM'. If got a visible property and that
6817 evaluates to nil then ignore this item. */
6818 if (NILP (menu_item_eval_property (value
)))
6821 else if (EQ (key
, QChelp
))
6822 /* `:help HELP-STRING'. */
6823 PROP (TOOL_BAR_ITEM_HELP
) = value
;
6824 else if (EQ (key
, QCfilter
))
6825 /* ':filter FORM'. */
6827 else if (EQ (key
, QCbutton
) && CONSP (value
))
6829 /* `:button (TYPE . SELECTED)'. */
6830 Lisp_Object type
, selected
;
6832 type
= XCAR (value
);
6833 selected
= XCDR (value
);
6834 if (EQ (type
, QCtoggle
) || EQ (type
, QCradio
))
6836 PROP (TOOL_BAR_ITEM_SELECTED_P
) = selected
;
6837 PROP (TOOL_BAR_ITEM_TYPE
) = type
;
6840 else if (EQ (key
, QCimage
)
6842 || (VECTORP (value
) && XVECTOR (value
)->size
== 4)))
6843 /* Value is either a single image specification or a vector
6844 of 4 such specifications for the different buttion states. */
6845 PROP (TOOL_BAR_ITEM_IMAGES
) = value
;
6848 /* If got a filter apply it on binding. */
6850 PROP (TOOL_BAR_ITEM_BINDING
)
6851 = menu_item_eval_property (list2 (filter
,
6853 PROP (TOOL_BAR_ITEM_BINDING
))));
6855 /* See if the binding is a keymap. Give up if it is. */
6856 if (!NILP (get_keymap_1 (PROP (TOOL_BAR_ITEM_BINDING
), 0, 1)))
6859 /* Enable or disable selection of item. */
6860 if (!EQ (PROP (TOOL_BAR_ITEM_ENABLED_P
), Qt
))
6861 PROP (TOOL_BAR_ITEM_ENABLED_P
)
6862 = menu_item_eval_property (PROP (TOOL_BAR_ITEM_ENABLED_P
));
6864 /* Handle radio buttons or toggle boxes. */
6865 if (!NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
)))
6866 PROP (TOOL_BAR_ITEM_SELECTED_P
)
6867 = menu_item_eval_property (PROP (TOOL_BAR_ITEM_SELECTED_P
));
6875 /* Initialize tool_bar_items_vector. REUSE, if non-nil, is a vector
6876 that can be reused. */
6879 init_tool_bar_items (reuse
)
6882 if (VECTORP (reuse
))
6883 tool_bar_items_vector
= reuse
;
6885 tool_bar_items_vector
= Fmake_vector (make_number (64), Qnil
);
6886 ntool_bar_items
= 0;
6890 /* Append parsed tool bar item properties from
6891 tool_bar_item_properties */
6894 append_tool_bar_item ()
6896 Lisp_Object
*to
, *from
;
6898 /* Enlarge tool_bar_items_vector if necessary. */
6899 if (ntool_bar_items
+ TOOL_BAR_ITEM_NSLOTS
6900 >= XVECTOR (tool_bar_items_vector
)->size
)
6902 Lisp_Object new_vector
;
6903 int old_size
= XVECTOR (tool_bar_items_vector
)->size
;
6905 new_vector
= Fmake_vector (make_number (2 * old_size
), Qnil
);
6906 bcopy (XVECTOR (tool_bar_items_vector
)->contents
,
6907 XVECTOR (new_vector
)->contents
,
6908 old_size
* sizeof (Lisp_Object
));
6909 tool_bar_items_vector
= new_vector
;
6912 /* Append entries from tool_bar_item_properties to the end of
6913 tool_bar_items_vector. */
6914 to
= XVECTOR (tool_bar_items_vector
)->contents
+ ntool_bar_items
;
6915 from
= XVECTOR (tool_bar_item_properties
)->contents
;
6916 bcopy (from
, to
, TOOL_BAR_ITEM_NSLOTS
* sizeof *to
);
6917 ntool_bar_items
+= TOOL_BAR_ITEM_NSLOTS
;
6924 /* Read a character using menus based on maps in the array MAPS.
6925 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
6926 Return t if we displayed a menu but the user rejected it.
6928 PREV_EVENT is the previous input event, or nil if we are reading
6929 the first event of a key sequence.
6931 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
6932 if we used a mouse menu to read the input, or zero otherwise. If
6933 USED_MOUSE_MENU is null, we don't dereference it.
6935 The prompting is done based on the prompt-string of the map
6936 and the strings associated with various map elements.
6938 This can be done with X menus or with menus put in the minibuf.
6939 These are done in different ways, depending on how the input will be read.
6940 Menus using X are done after auto-saving in read-char, getting the input
6941 event from Fx_popup_menu; menus using the minibuf use read_char recursively
6942 and do auto-saving in the inner call of read_char. */
6945 read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
6948 Lisp_Object prev_event
;
6949 int *used_mouse_menu
;
6952 register Lisp_Object name
;
6954 if (used_mouse_menu
)
6955 *used_mouse_menu
= 0;
6957 /* Use local over global Menu maps */
6959 if (! menu_prompting
)
6962 /* Optionally disregard all but the global map. */
6963 if (inhibit_local_menu_bar_menus
)
6965 maps
+= (nmaps
- 1);
6969 /* Get the menu name from the first map that has one (a prompt string). */
6970 for (mapno
= 0; mapno
< nmaps
; mapno
++)
6972 name
= map_prompt (maps
[mapno
]);
6977 /* If we don't have any menus, just read a character normally. */
6982 /* If we got to this point via a mouse click,
6983 use a real menu for mouse selection. */
6984 if (EVENT_HAS_PARAMETERS (prev_event
)
6985 && !EQ (XCAR (prev_event
), Qmenu_bar
)
6986 && !EQ (XCAR (prev_event
), Qtool_bar
))
6988 /* Display the menu and get the selection. */
6989 Lisp_Object
*realmaps
6990 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
6994 /* Use the maps that are not nil. */
6995 for (mapno
= 0; mapno
< nmaps
; mapno
++)
6996 if (!NILP (maps
[mapno
]))
6997 realmaps
[nmaps1
++] = maps
[mapno
];
6999 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
7004 record_menu_key (XCAR (value
));
7006 /* If we got multiple events, unread all but
7008 There is no way to prevent those unread events
7009 from showing up later in last_nonmenu_event.
7010 So turn symbol and integer events into lists,
7011 to indicate that they came from a mouse menu,
7012 so that when present in last_nonmenu_event
7013 they won't confuse things. */
7014 for (tem
= XCDR (value
); !NILP (tem
);
7017 record_menu_key (XCAR (tem
));
7018 if (SYMBOLP (XCAR (tem
))
7019 || INTEGERP (XCAR (tem
)))
7021 = Fcons (XCAR (tem
), Qnil
);
7024 /* If we got more than one event, put all but the first
7025 onto this list to be read later.
7026 Return just the first event now. */
7027 Vunread_command_events
7028 = nconc2 (XCDR (value
), Vunread_command_events
);
7029 value
= XCAR (value
);
7031 else if (NILP (value
))
7033 if (used_mouse_menu
)
7034 *used_mouse_menu
= 1;
7037 #endif /* HAVE_MENUS */
7041 /* Buffer in use so far for the minibuf prompts for menu keymaps.
7042 We make this bigger when necessary, and never free it. */
7043 static char *read_char_minibuf_menu_text
;
7044 /* Size of that buffer. */
7045 static int read_char_minibuf_menu_width
;
7048 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
7054 register Lisp_Object name
;
7056 int width
= FRAME_WIDTH (SELECTED_FRAME ()) - 4;
7059 Lisp_Object rest
, vector
;
7062 if (! menu_prompting
)
7065 /* Make sure we have a big enough buffer for the menu text. */
7066 if (read_char_minibuf_menu_text
== 0)
7068 read_char_minibuf_menu_width
= width
+ 4;
7069 read_char_minibuf_menu_text
= (char *) xmalloc (width
+ 4);
7071 else if (width
+ 4 > read_char_minibuf_menu_width
)
7073 read_char_minibuf_menu_width
= width
+ 4;
7074 read_char_minibuf_menu_text
7075 = (char *) xrealloc (read_char_minibuf_menu_text
, width
+ 4);
7077 menu
= read_char_minibuf_menu_text
;
7079 /* Get the menu name from the first map that has one (a prompt string). */
7080 for (mapno
= 0; mapno
< nmaps
; mapno
++)
7082 name
= map_prompt (maps
[mapno
]);
7087 /* If we don't have any menus, just read a character normally. */
7091 /* Prompt string always starts with map's prompt, and a space. */
7092 strcpy (menu
, XSTRING (name
)->data
);
7093 nlength
= STRING_BYTES (XSTRING (name
));
7094 menu
[nlength
++] = ':';
7095 menu
[nlength
++] = ' ';
7098 /* Start prompting at start of first map. */
7102 /* Present the documented bindings, a line at a time. */
7109 Lisp_Object orig_defn_macro
;
7111 /* Loop over elements of map. */
7116 /* If reached end of map, start at beginning of next map. */
7120 /* At end of last map, wrap around to first map if just starting,
7121 or end this line if already have something on it. */
7125 if (notfirst
|| nobindings
) break;
7130 /* Look at the next element of the map. */
7132 elt
= XVECTOR (vector
)->contents
[idx
];
7134 elt
= Fcar_safe (rest
);
7136 if (idx
< 0 && VECTORP (elt
))
7138 /* If we found a dense table in the keymap,
7139 advanced past it, but start scanning its contents. */
7140 rest
= Fcdr_safe (rest
);
7146 /* An ordinary element. */
7147 Lisp_Object event
, tem
;
7151 event
= Fcar_safe (elt
); /* alist */
7152 elt
= Fcdr_safe (elt
);
7156 XSETINT (event
, idx
); /* vector */
7159 /* Ignore the element if it has no prompt string. */
7160 if (INTEGERP (event
) && parse_menu_item (elt
, 0, -1))
7162 /* 1 if the char to type matches the string. */
7164 Lisp_Object upcased_event
, downcased_event
;
7167 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
7169 upcased_event
= Fupcase (event
);
7170 downcased_event
= Fdowncase (event
);
7171 char_matches
= (XINT (upcased_event
) == XSTRING (s
)->data
[0]
7172 || XINT (downcased_event
) == XSTRING (s
)->data
[0]);
7174 desc
= Fsingle_key_description (event
);
7177 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
7179 /* Insert equivalent keybinding. */
7180 s
= concat2 (s
, tem
);
7183 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_TYPE
];
7184 if (EQ (tem
, QCradio
) || EQ (tem
, QCtoggle
))
7186 /* Insert button prefix. */
7187 Lisp_Object selected
7188 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
];
7189 if (EQ (tem
, QCradio
))
7190 tem
= build_string (NILP (selected
) ? "(*) " : "( ) ");
7192 tem
= build_string (NILP (selected
) ? "[X] " : "[ ] ");
7193 s
= concat2 (tem
, s
);
7197 /* If we have room for the prompt string, add it to this line.
7198 If this is the first on the line, always add it. */
7199 if ((XSTRING (s
)->size
+ i
+ 2
7200 + (char_matches
? 0 : XSTRING (desc
)->size
+ 3))
7206 /* Punctuate between strings. */
7209 strcpy (menu
+ i
, ", ");
7215 /* If the char to type doesn't match the string's
7216 first char, explicitly show what char to type. */
7219 /* Add as much of string as fits. */
7220 thiswidth
= XSTRING (desc
)->size
;
7221 if (thiswidth
+ i
> width
)
7222 thiswidth
= width
- i
;
7223 bcopy (XSTRING (desc
)->data
, menu
+ i
, thiswidth
);
7225 strcpy (menu
+ i
, " = ");
7229 /* Add as much of string as fits. */
7230 thiswidth
= XSTRING (s
)->size
;
7231 if (thiswidth
+ i
> width
)
7232 thiswidth
= width
- i
;
7233 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
7239 /* If this element does not fit, end the line now,
7240 and save the element for the next line. */
7241 strcpy (menu
+ i
, "...");
7246 /* Move past this element. */
7247 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
7248 /* Handle reaching end of dense table. */
7253 rest
= Fcdr_safe (rest
);
7257 /* Prompt with that and read response. */
7258 message2_nolog (menu
, strlen (menu
),
7259 ! NILP (current_buffer
->enable_multibyte_characters
));
7261 /* Make believe its not a keyboard macro in case the help char
7262 is pressed. Help characters are not recorded because menu prompting
7263 is not used on replay.
7265 orig_defn_macro
= current_kboard
->defining_kbd_macro
;
7266 current_kboard
->defining_kbd_macro
= Qnil
;
7268 obj
= read_char (commandflag
, 0, 0, Qnil
, 0);
7269 while (BUFFERP (obj
));
7270 current_kboard
->defining_kbd_macro
= orig_defn_macro
;
7272 if (!INTEGERP (obj
))
7277 if (! EQ (obj
, menu_prompt_more_char
)
7278 && (!INTEGERP (menu_prompt_more_char
)
7279 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
7281 if (!NILP (current_kboard
->defining_kbd_macro
))
7282 store_kbd_macro_char (obj
);
7285 /* Help char - go round again */
7289 /* Reading key sequences. */
7291 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
7292 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
7293 keymap, or nil otherwise. Return the index of the first keymap in
7294 which KEY has any binding, or NMAPS if no map has a binding.
7296 If KEY is a meta ASCII character, treat it like meta-prefix-char
7297 followed by the corresponding non-meta character. Keymaps in
7298 CURRENT with non-prefix bindings for meta-prefix-char become nil in
7301 If KEY has no bindings in any of the CURRENT maps, NEXT is left
7304 NEXT may be the same array as CURRENT. */
7307 follow_key (key
, nmaps
, current
, defs
, next
)
7309 Lisp_Object
*current
, *defs
, *next
;
7312 int i
, first_binding
;
7315 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
7316 followed by the corresponding non-meta character.
7317 Put the results into DEFS, since we are going to alter that anyway.
7318 Do not alter CURRENT or NEXT. */
7319 if (INTEGERP (key
) && (XINT (key
) & CHAR_META
))
7321 for (i
= 0; i
< nmaps
; i
++)
7322 if (! NILP (current
[i
]))
7325 def
= get_keyelt (access_keymap (current
[i
],
7326 meta_prefix_char
, 1, 0), 0);
7328 /* Note that since we pass the resulting bindings through
7329 get_keymap_1, non-prefix bindings for meta-prefix-char
7331 defs
[i
] = get_keymap_1 (def
, 0, 1);
7337 XSETINT (key
, XFASTINT (key
) & ~CHAR_META
);
7340 first_binding
= nmaps
;
7341 for (i
= nmaps
- 1; i
>= 0; i
--)
7343 if (! NILP (current
[i
]))
7351 defs
[i
] = get_keyelt (access_keymap (map
, key
, 1, 0), 0);
7352 if (! NILP (defs
[i
]))
7359 /* Given the set of bindings we've found, produce the next set of maps. */
7360 if (first_binding
< nmaps
)
7361 for (i
= 0; i
< nmaps
; i
++)
7362 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0, 1);
7364 return first_binding
;
7367 /* Read a sequence of keys that ends with a non prefix character,
7368 storing it in KEYBUF, a buffer of size BUFSIZE.
7370 Return the length of the key sequence stored.
7371 Return -1 if the user rejected a command menu.
7373 Echo starting immediately unless `prompt' is 0.
7375 Where a key sequence ends depends on the currently active keymaps.
7376 These include any minor mode keymaps active in the current buffer,
7377 the current buffer's local map, and the global map.
7379 If a key sequence has no other bindings, we check Vfunction_key_map
7380 to see if some trailing subsequence might be the beginning of a
7381 function key's sequence. If so, we try to read the whole function
7382 key, and substitute its symbolic name into the key sequence.
7384 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
7385 `double-' events into similar click events, if that would make them
7386 bound. We try to turn `triple-' events first into `double-' events,
7389 If we get a mouse click in a mode line, vertical divider, or other
7390 non-text area, we treat the click as if it were prefixed by the
7391 symbol denoting that area - `mode-line', `vertical-line', or
7394 If the sequence starts with a mouse click, we read the key sequence
7395 with respect to the buffer clicked on, not the current buffer.
7397 If the user switches frames in the midst of a key sequence, we put
7398 off the switch-frame event until later; the next call to
7399 read_char will return it.
7401 If FIX_CURRENT_BUFFER is nonzero, we restore current_buffer
7402 from the selected window's buffer. */
7405 read_key_sequence (keybuf
, bufsize
, prompt
, dont_downcase_last
,
7406 can_return_switch_frame
, fix_current_buffer
)
7407 Lisp_Object
*keybuf
;
7410 int dont_downcase_last
;
7411 int can_return_switch_frame
;
7412 int fix_current_buffer
;
7414 int count
= specpdl_ptr
- specpdl
;
7416 /* How many keys there are in the current key sequence. */
7419 /* The length of the echo buffer when we started reading, and
7420 the length of this_command_keys when we started reading. */
7424 /* The number of keymaps we're scanning right now, and the number of
7425 keymaps we have allocated space for. */
7427 int nmaps_allocated
= 0;
7429 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
7430 the current keymaps. */
7433 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
7434 in the current keymaps, or nil where it is not a prefix. */
7435 Lisp_Object
*submaps
;
7437 /* The local map to start out with at start of key sequence. */
7438 Lisp_Object orig_local_map
;
7440 /* The map from the `keymap' property to start out with at start of
7442 Lisp_Object orig_keymap
;
7444 /* 1 if we have already considered switching to the local-map property
7445 of the place where a mouse click occurred. */
7446 int localized_local_map
= 0;
7448 /* The index in defs[] of the first keymap that has a binding for
7449 this key sequence. In other words, the lowest i such that
7450 defs[i] is non-nil. */
7453 /* If t < mock_input, then KEYBUF[t] should be read as the next
7456 We use this to recover after recognizing a function key. Once we
7457 realize that a suffix of the current key sequence is actually a
7458 function key's escape sequence, we replace the suffix with the
7459 function key's binding from Vfunction_key_map. Now keybuf
7460 contains a new and different key sequence, so the echo area,
7461 this_command_keys, and the submaps and defs arrays are wrong. In
7462 this situation, we set mock_input to t, set t to 0, and jump to
7463 restart_sequence; the loop will read keys from keybuf up until
7464 mock_input, thus rebuilding the state; and then it will resume
7465 reading characters from the keyboard. */
7468 /* If the sequence is unbound in submaps[], then
7469 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
7470 and fkey_map is its binding.
7472 These might be > t, indicating that all function key scanning
7473 should hold off until t reaches them. We do this when we've just
7474 recognized a function key, to avoid searching for the function
7475 key's again in Vfunction_key_map. */
7476 int fkey_start
= 0, fkey_end
= 0;
7477 Lisp_Object fkey_map
;
7479 /* Likewise, for key_translation_map. */
7480 int keytran_start
= 0, keytran_end
= 0;
7481 Lisp_Object keytran_map
;
7483 /* If we receive a ``switch-frame'' event in the middle of a key sequence,
7484 we put it off for later. While we're reading, we keep the event here. */
7485 Lisp_Object delayed_switch_frame
;
7487 /* See the comment below... */
7488 #if defined (GOBBLE_FIRST_EVENT)
7489 Lisp_Object first_event
;
7492 Lisp_Object original_uppercase
;
7493 int original_uppercase_position
= -1;
7495 /* Gets around Microsoft compiler limitations. */
7498 struct buffer
*starting_buffer
;
7500 /* Nonzero if we seem to have got the beginning of a binding
7501 in function_key_map. */
7502 int function_key_possible
= 0;
7503 int key_translation_possible
= 0;
7505 /* Save the status of key translation before each step,
7506 so that we can restore this after downcasing. */
7507 Lisp_Object prev_fkey_map
;
7508 int prev_fkey_start
;
7511 Lisp_Object prev_keytran_map
;
7512 int prev_keytran_start
;
7513 int prev_keytran_end
;
7515 #if defined (GOBBLE_FIRST_EVENT)
7519 raw_keybuf_count
= 0;
7521 last_nonmenu_event
= Qnil
;
7523 delayed_switch_frame
= Qnil
;
7524 fkey_map
= Vfunction_key_map
;
7525 keytran_map
= Vkey_translation_map
;
7527 /* If there is no function-key-map, turn off function key scanning. */
7528 if (NILP (Fkeymapp (Vfunction_key_map
)))
7529 fkey_start
= fkey_end
= bufsize
+ 1;
7531 /* If there is no key-translation-map, turn off scanning. */
7532 if (NILP (Fkeymapp (Vkey_translation_map
)))
7533 keytran_start
= keytran_end
= bufsize
+ 1;
7538 echo_prompt (XSTRING (prompt
)->data
);
7539 else if (cursor_in_echo_area
7540 && (FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
7541 && NILP (Fzerop (Vecho_keystrokes
)))
7542 /* This doesn't put in a dash if the echo buffer is empty, so
7543 you don't always see a dash hanging out in the minibuffer. */
7547 /* Record the initial state of the echo area and this_command_keys;
7548 we will need to restore them if we replay a key sequence. */
7550 echo_start
= echo_length ();
7551 keys_start
= this_command_key_count
;
7552 this_single_command_key_start
= keys_start
;
7554 #if defined (GOBBLE_FIRST_EVENT)
7555 /* This doesn't quite work, because some of the things that read_char
7556 does cannot safely be bypassed. It seems too risky to try to make
7559 /* Read the first char of the sequence specially, before setting
7560 up any keymaps, in case a filter runs and switches buffers on us. */
7561 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
7563 #endif /* GOBBLE_FIRST_EVENT */
7565 orig_local_map
= get_local_map (PT
, current_buffer
, local_map
);
7566 orig_keymap
= get_local_map (PT
, current_buffer
, keymap
);
7568 /* We jump here when the key sequence has been thoroughly changed, and
7569 we need to rescan it starting from the beginning. When we jump here,
7570 keybuf[0..mock_input] holds the sequence we should reread. */
7573 starting_buffer
= current_buffer
;
7574 function_key_possible
= 0;
7575 key_translation_possible
= 0;
7577 /* Build our list of keymaps.
7578 If we recognize a function key and replace its escape sequence in
7579 keybuf with its symbol, or if the sequence starts with a mouse
7580 click and we need to switch buffers, we jump back here to rebuild
7581 the initial keymaps from the current buffer. */
7585 if (!NILP (current_kboard
->Voverriding_terminal_local_map
)
7586 || !NILP (Voverriding_local_map
))
7588 if (3 > nmaps_allocated
)
7590 submaps
= (Lisp_Object
*) alloca (3 * sizeof (submaps
[0]));
7591 defs
= (Lisp_Object
*) alloca (3 * sizeof (defs
[0]));
7592 nmaps_allocated
= 3;
7595 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
7596 submaps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
7597 if (!NILP (Voverriding_local_map
))
7598 submaps
[nmaps
++] = Voverriding_local_map
;
7603 nmaps
= current_minor_maps (0, &maps
);
7604 if (!NILP (orig_keymap
))
7606 if (nmaps
+ extra_maps
> nmaps_allocated
)
7608 submaps
= (Lisp_Object
*) alloca ((nmaps
+extra_maps
)
7609 * sizeof (submaps
[0]));
7610 defs
= (Lisp_Object
*) alloca ((nmaps
+extra_maps
)
7611 * sizeof (defs
[0]));
7612 nmaps_allocated
= nmaps
+ extra_maps
;
7614 bcopy (maps
, submaps
, nmaps
* sizeof (submaps
[0]));
7615 if (!NILP (orig_keymap
))
7616 submaps
[nmaps
++] = orig_keymap
;
7617 submaps
[nmaps
++] = orig_local_map
;
7619 submaps
[nmaps
++] = current_global_map
;
7622 /* Find an accurate initial value for first_binding. */
7623 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
7624 if (! NILP (submaps
[first_binding
]))
7627 /* Start from the beginning in keybuf. */
7630 /* These are no-ops the first time through, but if we restart, they
7631 revert the echo area and this_command_keys to their original state. */
7632 this_command_key_count
= keys_start
;
7633 if (INTERACTIVE
&& t
< mock_input
)
7634 echo_truncate (echo_start
);
7636 /* If the best binding for the current key sequence is a keymap, or
7637 we may be looking at a function key's escape sequence, keep on
7639 while ((first_binding
< nmaps
&& ! NILP (submaps
[first_binding
]))
7640 || (first_binding
>= nmaps
7642 /* mock input is never part of a function key's sequence. */
7643 && mock_input
<= fkey_start
)
7644 || (first_binding
>= nmaps
7645 && keytran_start
< t
&& key_translation_possible
)
7646 /* Don't return in the middle of a possible function key sequence,
7647 if the only bindings we found were via case conversion.
7648 Thus, if ESC O a has a function-key-map translation
7649 and ESC o has a binding, don't return after ESC O,
7650 so that we can translate ESC O plus the next character. */
7654 int used_mouse_menu
= 0;
7656 /* Where the last real key started. If we need to throw away a
7657 key that has expanded into more than one element of keybuf
7658 (say, a mouse click on the mode line which is being treated
7659 as [mode-line (mouse-...)], then we backtrack to this point
7661 int last_real_key_start
;
7663 /* These variables are analogous to echo_start and keys_start;
7664 while those allow us to restart the entire key sequence,
7665 echo_local_start and keys_local_start allow us to throw away
7667 int echo_local_start
, keys_local_start
, local_first_binding
;
7670 error ("Key sequence too long");
7673 echo_local_start
= echo_length ();
7674 keys_local_start
= this_command_key_count
;
7675 local_first_binding
= first_binding
;
7678 /* These are no-ops, unless we throw away a keystroke below and
7679 jumped back up to replay_key; in that case, these restore the
7680 variables to their original state, allowing us to replay the
7682 if (INTERACTIVE
&& t
< mock_input
)
7683 echo_truncate (echo_local_start
);
7684 this_command_key_count
= keys_local_start
;
7685 first_binding
= local_first_binding
;
7687 /* By default, assume each event is "real". */
7688 last_real_key_start
= t
;
7690 /* Does mock_input indicate that we are re-reading a key sequence? */
7694 add_command_key (key
);
7695 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
7696 && NILP (Fzerop (Vecho_keystrokes
)))
7700 /* If not, we should actually read a character. */
7705 KBOARD
*interrupted_kboard
= current_kboard
;
7706 struct frame
*interrupted_frame
= SELECTED_FRAME ();
7707 if (setjmp (wrong_kboard_jmpbuf
))
7709 if (!NILP (delayed_switch_frame
))
7711 interrupted_kboard
->kbd_queue
7712 = Fcons (delayed_switch_frame
,
7713 interrupted_kboard
->kbd_queue
);
7714 delayed_switch_frame
= Qnil
;
7717 interrupted_kboard
->kbd_queue
7718 = Fcons (keybuf
[--t
], interrupted_kboard
->kbd_queue
);
7720 /* If the side queue is non-empty, ensure it begins with a
7721 switch-frame, so we'll replay it in the right context. */
7722 if (CONSP (interrupted_kboard
->kbd_queue
)
7723 && (key
= XCAR (interrupted_kboard
->kbd_queue
),
7724 !(EVENT_HAS_PARAMETERS (key
)
7725 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)),
7729 XSETFRAME (frame
, interrupted_frame
);
7730 interrupted_kboard
->kbd_queue
7731 = Fcons (make_lispy_switch_frame (frame
),
7732 interrupted_kboard
->kbd_queue
);
7735 orig_local_map
= get_local_map (PT
, current_buffer
, local_map
);
7736 orig_keymap
= get_local_map (PT
, current_buffer
, keymap
);
7737 goto replay_sequence
;
7740 key
= read_char (NILP (prompt
), nmaps
, submaps
, last_nonmenu_event
,
7744 /* read_char returns t when it shows a menu and the user rejects it.
7748 unbind_to (count
, Qnil
);
7752 /* read_char returns -1 at the end of a macro.
7753 Emacs 18 handles this by returning immediately with a
7754 zero, so that's what we'll do. */
7755 if (INTEGERP (key
) && XINT (key
) == -1)
7758 /* The Microsoft C compiler can't handle the goto that
7764 /* If the current buffer has been changed from under us, the
7765 keymap may have changed, so replay the sequence. */
7769 /* Reset the current buffer from the selected window
7770 in case something changed the former and not the latter.
7771 This is to be more consistent with the behavior
7772 of the command_loop_1. */
7773 if (fix_current_buffer
)
7775 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7777 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
7778 Fset_buffer (XWINDOW (selected_window
)->buffer
);
7781 orig_local_map
= get_local_map (PT
, current_buffer
, local_map
);
7782 orig_keymap
= get_local_map (PT
, current_buffer
, keymap
);
7783 goto replay_sequence
;
7786 /* If we have a quit that was typed in another frame, and
7787 quit_throw_to_read_char switched buffers,
7788 replay to get the right keymap. */
7789 if (XINT (key
) == quit_char
&& current_buffer
!= starting_buffer
)
7792 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
7796 orig_local_map
= get_local_map (PT
, current_buffer
, local_map
);
7797 orig_keymap
= get_local_map (PT
, current_buffer
, keymap
);
7798 goto replay_sequence
;
7803 if (EVENT_HAS_PARAMETERS (key
)
7804 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)), Qswitch_frame
))
7806 /* If we're at the beginning of a key sequence, and the caller
7807 says it's okay, go ahead and return this event. If we're
7808 in the midst of a key sequence, delay it until the end. */
7809 if (t
> 0 || !can_return_switch_frame
)
7811 delayed_switch_frame
= key
;
7817 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
7820 /* Clicks in non-text areas get prefixed by the symbol
7821 in their CHAR-ADDRESS field. For example, a click on
7822 the mode line is prefixed by the symbol `mode-line'.
7824 Furthermore, key sequences beginning with mouse clicks
7825 are read using the keymaps of the buffer clicked on, not
7826 the current buffer. So we may have to switch the buffer
7829 When we turn one event into two events, we must make sure
7830 that neither of the two looks like the original--so that,
7831 if we replay the events, they won't be expanded again.
7832 If not for this, such reexpansion could happen either here
7833 or when user programs play with this-command-keys. */
7834 if (EVENT_HAS_PARAMETERS (key
))
7838 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
7839 if (EQ (kind
, Qmouse_click
))
7841 Lisp_Object window
, posn
;
7843 window
= POSN_WINDOW (EVENT_START (key
));
7844 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
7848 /* We're looking at the second event of a
7849 sequence which we expanded before. Set
7850 last_real_key_start appropriately. */
7852 last_real_key_start
= t
- 1;
7855 /* Key sequences beginning with mouse clicks are
7856 read using the keymaps in the buffer clicked on,
7857 not the current buffer. If we're at the
7858 beginning of a key sequence, switch buffers. */
7859 if (last_real_key_start
== 0
7861 && BUFFERP (XWINDOW (window
)->buffer
)
7862 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
7864 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
7868 /* Arrange to go back to the original buffer once we're
7869 done reading the key sequence. Note that we can't
7870 use save_excursion_{save,restore} here, because they
7871 save point as well as the current buffer; we don't
7872 want to save point, because redisplay may change it,
7873 to accommodate a Fset_window_start or something. We
7874 don't want to do this at the top of the function,
7875 because we may get input from a subprocess which
7876 wants to change the selected window and stuff (say,
7878 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
7880 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7882 set_buffer_internal (XBUFFER (XWINDOW
7885 orig_local_map
= get_local_map (PT
, current_buffer
,
7887 orig_keymap
= get_local_map (PT
, current_buffer
, keymap
);
7888 goto replay_sequence
;
7891 /* For a mouse click, get the local text-property keymap
7892 of the place clicked on, rather than point. */
7893 if (last_real_key_start
== 0
7894 && CONSP (XCDR (key
))
7895 && ! localized_local_map
)
7897 Lisp_Object map_here
, start
, pos
;
7899 localized_local_map
= 1;
7900 start
= EVENT_START (key
);
7902 if (CONSP (start
) && CONSP (XCDR (start
)))
7904 pos
= POSN_BUFFER_POSN (start
);
7906 && XINT (pos
) >= BEG
&& XINT (pos
) <= Z
)
7908 map_here
= get_local_map (XINT (pos
),
7909 current_buffer
, local_map
);
7910 if (!EQ (map_here
, orig_local_map
))
7912 orig_local_map
= map_here
;
7916 goto replay_sequence
;
7918 map_here
= get_local_map (XINT (pos
),
7919 current_buffer
, keymap
);
7920 if (!EQ (map_here
, orig_keymap
))
7922 orig_keymap
= map_here
;
7926 goto replay_sequence
;
7932 /* Expand mode-line and scroll-bar events into two events:
7933 use posn as a fake prefix key. */
7936 if (t
+ 1 >= bufsize
)
7937 error ("Key sequence too long");
7942 /* Zap the position in key, so we know that we've
7943 expanded it, and don't try to do so again. */
7944 POSN_BUFFER_POSN (EVENT_START (key
))
7945 = Fcons (posn
, Qnil
);
7947 /* If on a mode line string with a local keymap,
7948 reconsider the key sequence with that keymap. */
7949 if (CONSP (POSN_STRING (EVENT_START (key
))))
7951 Lisp_Object string
, pos
, map
, map2
;
7953 string
= POSN_STRING (EVENT_START (key
));
7954 pos
= XCDR (string
);
7955 string
= XCAR (string
);
7956 if (pos
>= 0 && pos
< XSTRING (string
)->size
)
7958 map
= Fget_text_property (pos
, Qlocal_map
, string
);
7960 orig_local_map
= map
;
7961 map2
= Fget_text_property (pos
, Qkeymap
, string
);
7964 if (!NILP (map
) || !NILP (map2
))
7965 goto replay_sequence
;
7972 else if (CONSP (XCDR (key
))
7973 && CONSP (EVENT_START (key
))
7974 && CONSP (XCDR (EVENT_START (key
))))
7978 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
7979 /* Handle menu-bar events:
7980 insert the dummy prefix event `menu-bar'. */
7981 if (EQ (posn
, Qmenu_bar
) || EQ (posn
, Qtool_bar
))
7983 if (t
+ 1 >= bufsize
)
7984 error ("Key sequence too long");
7988 /* Zap the position in key, so we know that we've
7989 expanded it, and don't try to do so again. */
7990 POSN_BUFFER_POSN (EVENT_START (key
))
7991 = Fcons (posn
, Qnil
);
7994 goto replay_sequence
;
7996 else if (CONSP (posn
))
7998 /* We're looking at the second event of a
7999 sequence which we expanded before. Set
8000 last_real_key_start appropriately. */
8001 if (last_real_key_start
== t
&& t
> 0)
8002 last_real_key_start
= t
- 1;
8007 /* We have finally decided that KEY is something we might want
8009 first_binding
= (follow_key (key
,
8010 nmaps
- first_binding
,
8011 submaps
+ first_binding
,
8012 defs
+ first_binding
,
8013 submaps
+ first_binding
)
8016 /* If KEY wasn't bound, we'll try some fallbacks. */
8017 if (first_binding
>= nmaps
)
8021 head
= EVENT_HEAD (key
);
8022 if (help_char_p (head
) && t
> 0)
8024 read_key_sequence_cmd
= Vprefix_help_command
;
8026 last_nonmenu_event
= key
;
8027 /* The Microsoft C compiler can't handle the goto that
8035 Lisp_Object breakdown
;
8038 breakdown
= parse_modifiers (head
);
8039 modifiers
= XINT (XCAR (XCDR (breakdown
)));
8040 /* Attempt to reduce an unbound mouse event to a simpler
8041 event that is bound:
8042 Drags reduce to clicks.
8043 Double-clicks reduce to clicks.
8044 Triple-clicks reduce to double-clicks, then to clicks.
8045 Down-clicks are eliminated.
8046 Double-downs reduce to downs, then are eliminated.
8047 Triple-downs reduce to double-downs, then to downs,
8048 then are eliminated. */
8049 if (modifiers
& (down_modifier
| drag_modifier
8050 | double_modifier
| triple_modifier
))
8052 while (modifiers
& (down_modifier
| drag_modifier
8053 | double_modifier
| triple_modifier
))
8055 Lisp_Object new_head
, new_click
;
8056 if (modifiers
& triple_modifier
)
8057 modifiers
^= (double_modifier
| triple_modifier
);
8058 else if (modifiers
& double_modifier
)
8059 modifiers
&= ~double_modifier
;
8060 else if (modifiers
& drag_modifier
)
8061 modifiers
&= ~drag_modifier
;
8064 /* Dispose of this `down' event by simply jumping
8065 back to replay_key, to get another event.
8067 Note that if this event came from mock input,
8068 then just jumping back to replay_key will just
8069 hand it to us again. So we have to wipe out any
8072 We could delete keybuf[t] and shift everything
8073 after that to the left by one spot, but we'd also
8074 have to fix up any variable that points into
8075 keybuf, and shifting isn't really necessary
8078 Adding prefixes for non-textual mouse clicks
8079 creates two characters of mock input, and both
8080 must be thrown away. If we're only looking at
8081 the prefix now, we can just jump back to
8082 replay_key. On the other hand, if we've already
8083 processed the prefix, and now the actual click
8084 itself is giving us trouble, then we've lost the
8085 state of the keymaps we want to backtrack to, and
8086 we need to replay the whole sequence to rebuild
8089 Beyond that, only function key expansion could
8090 create more than two keys, but that should never
8091 generate mouse events, so it's okay to zero
8092 mock_input in that case too.
8094 Isn't this just the most wonderful code ever? */
8095 if (t
== last_real_key_start
)
8102 mock_input
= last_real_key_start
;
8103 goto replay_sequence
;
8108 = apply_modifiers (modifiers
, XCAR (breakdown
));
8110 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
8112 /* Look for a binding for this new key. follow_key
8113 promises that it didn't munge submaps the
8114 last time we called it, since key was unbound. */
8116 = (follow_key (new_click
,
8117 nmaps
- local_first_binding
,
8118 submaps
+ local_first_binding
,
8119 defs
+ local_first_binding
,
8120 submaps
+ local_first_binding
)
8121 + local_first_binding
);
8123 /* If that click is bound, go for it. */
8124 if (first_binding
< nmaps
)
8129 /* Otherwise, we'll leave key set to the drag event. */
8136 /* Normally, last_nonmenu_event gets the previous key we read.
8137 But when a mouse popup menu is being used,
8138 we don't update last_nonmenu_event; it continues to hold the mouse
8139 event that preceded the first level of menu. */
8140 if (!used_mouse_menu
)
8141 last_nonmenu_event
= key
;
8143 /* Record what part of this_command_keys is the current key sequence. */
8144 this_single_command_key_start
= this_command_key_count
- t
;
8146 prev_fkey_map
= fkey_map
;
8147 prev_fkey_start
= fkey_start
;
8148 prev_fkey_end
= fkey_end
;
8150 prev_keytran_map
= keytran_map
;
8151 prev_keytran_start
= keytran_start
;
8152 prev_keytran_end
= keytran_end
;
8154 /* If the sequence is unbound, see if we can hang a function key
8155 off the end of it. We only want to scan real keyboard input
8156 for function key sequences, so if mock_input says that we're
8157 re-reading old events, don't examine it. */
8158 if (first_binding
>= nmaps
8161 Lisp_Object fkey_next
;
8163 /* Continue scan from fkey_end until we find a bound suffix.
8164 If we fail, increment fkey_start
8165 and start fkey_end from there. */
8166 while (fkey_end
< t
)
8170 key
= keybuf
[fkey_end
++];
8171 /* Look up meta-characters by prefixing them
8172 with meta_prefix_char. I hate this. */
8173 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
8178 (access_keymap (fkey_map
, meta_prefix_char
, 1, 0), 0),
8180 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
8183 fkey_next
= fkey_map
;
8186 = get_keyelt (access_keymap (fkey_next
, key
, 1, 0), 1);
8188 /* Handle symbol with autoload definition. */
8189 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
8190 && CONSP (XSYMBOL (fkey_next
)->function
)
8191 && EQ (XCAR (XSYMBOL (fkey_next
)->function
), Qautoload
))
8192 do_autoload (XSYMBOL (fkey_next
)->function
,
8195 /* Handle a symbol whose function definition is a keymap
8197 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
8198 && (!NILP (Farrayp (XSYMBOL (fkey_next
)->function
))
8199 || !NILP (Fkeymapp (XSYMBOL (fkey_next
)->function
))))
8200 fkey_next
= XSYMBOL (fkey_next
)->function
;
8202 #if 0 /* I didn't turn this on, because it might cause trouble
8203 for the mapping of return into C-m and tab into C-i. */
8204 /* Optionally don't map function keys into other things.
8205 This enables the user to redefine kp- keys easily. */
8206 if (SYMBOLP (key
) && !NILP (Vinhibit_function_key_mapping
))
8210 /* If the function key map gives a function, not an
8211 array, then call the function with no args and use
8212 its value instead. */
8213 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
8216 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8220 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
8221 fkey_next
= call1 (fkey_next
, prompt
);
8223 /* If the function returned something invalid,
8224 barf--don't ignore it.
8225 (To ignore it safely, we would need to gcpro a bunch of
8226 other variables.) */
8227 if (! (VECTORP (fkey_next
) || STRINGP (fkey_next
)))
8228 error ("Function in key-translation-map returns invalid key sequence");
8231 function_key_possible
= ! NILP (fkey_next
);
8233 /* If keybuf[fkey_start..fkey_end] is bound in the
8234 function key map and it's a suffix of the current
8235 sequence (i.e. fkey_end == t), replace it with
8236 the binding and restart with fkey_start at the end. */
8237 if ((VECTORP (fkey_next
) || STRINGP (fkey_next
))
8240 int len
= XFASTINT (Flength (fkey_next
));
8242 t
= fkey_start
+ len
;
8244 error ("Key sequence too long");
8246 if (VECTORP (fkey_next
))
8247 bcopy (XVECTOR (fkey_next
)->contents
,
8248 keybuf
+ fkey_start
,
8249 (t
- fkey_start
) * sizeof (keybuf
[0]));
8250 else if (STRINGP (fkey_next
))
8254 for (i
= 0; i
< len
; i
++)
8255 XSETFASTINT (keybuf
[fkey_start
+ i
],
8256 XSTRING (fkey_next
)->data
[i
]);
8260 fkey_start
= fkey_end
= t
;
8261 fkey_map
= Vfunction_key_map
;
8263 /* Do pass the results through key-translation-map.
8264 But don't retranslate what key-translation-map
8265 has already translated. */
8266 keytran_end
= keytran_start
;
8267 keytran_map
= Vkey_translation_map
;
8269 goto replay_sequence
;
8272 fkey_map
= get_keymap_1 (fkey_next
, 0, 1);
8274 /* If we no longer have a bound suffix, try a new positions for
8276 if (NILP (fkey_map
))
8278 fkey_end
= ++fkey_start
;
8279 fkey_map
= Vfunction_key_map
;
8280 function_key_possible
= 0;
8285 /* Look for this sequence in key-translation-map. */
8287 Lisp_Object keytran_next
;
8289 /* Scan from keytran_end until we find a bound suffix. */
8290 while (keytran_end
< t
)
8294 key
= keybuf
[keytran_end
++];
8295 /* Look up meta-characters by prefixing them
8296 with meta_prefix_char. I hate this. */
8297 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
8302 (access_keymap (keytran_map
, meta_prefix_char
, 1, 0), 0),
8304 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
8307 keytran_next
= keytran_map
;
8310 = get_keyelt (access_keymap (keytran_next
, key
, 1, 0), 1);
8312 /* Handle symbol with autoload definition. */
8313 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
8314 && CONSP (XSYMBOL (keytran_next
)->function
)
8315 && EQ (XCAR (XSYMBOL (keytran_next
)->function
), Qautoload
))
8316 do_autoload (XSYMBOL (keytran_next
)->function
,
8319 /* Handle a symbol whose function definition is a keymap
8321 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
8322 && (!NILP (Farrayp (XSYMBOL (keytran_next
)->function
))
8323 || !NILP (Fkeymapp (XSYMBOL (keytran_next
)->function
))))
8324 keytran_next
= XSYMBOL (keytran_next
)->function
;
8326 /* If the key translation map gives a function, not an
8327 array, then call the function with one arg and use
8328 its value instead. */
8329 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
8330 && keytran_end
== t
)
8332 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8336 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
8337 keytran_next
= call1 (keytran_next
, prompt
);
8339 /* If the function returned something invalid,
8340 barf--don't ignore it.
8341 (To ignore it safely, we would need to gcpro a bunch of
8342 other variables.) */
8343 if (! (VECTORP (keytran_next
) || STRINGP (keytran_next
)))
8344 error ("Function in key-translation-map returns invalid key sequence");
8347 key_translation_possible
= ! NILP (keytran_next
);
8349 /* If keybuf[keytran_start..keytran_end] is bound in the
8350 key translation map and it's a suffix of the current
8351 sequence (i.e. keytran_end == t), replace it with
8352 the binding and restart with keytran_start at the end. */
8353 if ((VECTORP (keytran_next
) || STRINGP (keytran_next
))
8354 && keytran_end
== t
)
8356 int len
= XFASTINT (Flength (keytran_next
));
8358 t
= keytran_start
+ len
;
8360 error ("Key sequence too long");
8362 if (VECTORP (keytran_next
))
8363 bcopy (XVECTOR (keytran_next
)->contents
,
8364 keybuf
+ keytran_start
,
8365 (t
- keytran_start
) * sizeof (keybuf
[0]));
8366 else if (STRINGP (keytran_next
))
8370 for (i
= 0; i
< len
; i
++)
8371 XSETFASTINT (keybuf
[keytran_start
+ i
],
8372 XSTRING (keytran_next
)->data
[i
]);
8376 keytran_start
= keytran_end
= t
;
8377 keytran_map
= Vkey_translation_map
;
8379 /* Don't pass the results of key-translation-map
8380 through function-key-map. */
8381 fkey_start
= fkey_end
= t
;
8382 fkey_map
= Vfunction_key_map
;
8384 goto replay_sequence
;
8387 keytran_map
= get_keymap_1 (keytran_next
, 0, 1);
8389 /* If we no longer have a bound suffix, try a new positions for
8391 if (NILP (keytran_map
))
8393 keytran_end
= ++keytran_start
;
8394 keytran_map
= Vkey_translation_map
;
8395 key_translation_possible
= 0;
8400 /* If KEY is not defined in any of the keymaps,
8401 and cannot be part of a function key or translation,
8402 and is an upper case letter
8403 use the corresponding lower-case letter instead. */
8404 if (first_binding
== nmaps
&& ! function_key_possible
8405 && ! key_translation_possible
8407 && ((((XINT (key
) & 0x3ffff)
8408 < XCHAR_TABLE (current_buffer
->downcase_table
)->size
)
8409 && UPPERCASEP (XINT (key
) & 0x3ffff))
8410 || (XINT (key
) & shift_modifier
)))
8412 Lisp_Object new_key
;
8414 original_uppercase
= key
;
8415 original_uppercase_position
= t
- 1;
8417 if (XINT (key
) & shift_modifier
)
8418 XSETINT (new_key
, XINT (key
) & ~shift_modifier
);
8420 XSETINT (new_key
, (DOWNCASE (XINT (key
) & 0x3ffff)
8421 | (XINT (key
) & ~0x3ffff)));
8423 /* We have to do this unconditionally, regardless of whether
8424 the lower-case char is defined in the keymaps, because they
8425 might get translated through function-key-map. */
8426 keybuf
[t
- 1] = new_key
;
8429 fkey_map
= prev_fkey_map
;
8430 fkey_start
= prev_fkey_start
;
8431 fkey_end
= prev_fkey_end
;
8433 keytran_map
= prev_keytran_map
;
8434 keytran_start
= prev_keytran_start
;
8435 keytran_end
= prev_keytran_end
;
8437 goto replay_sequence
;
8439 /* If KEY is not defined in any of the keymaps,
8440 and cannot be part of a function key or translation,
8441 and is a shifted function key,
8442 use the corresponding unshifted function key instead. */
8443 if (first_binding
== nmaps
&& ! function_key_possible
8444 && ! key_translation_possible
8447 Lisp_Object breakdown
;
8450 breakdown
= parse_modifiers (key
);
8451 modifiers
= XINT (XCAR (XCDR (breakdown
)));
8452 if (modifiers
& shift_modifier
)
8454 Lisp_Object new_key
;
8456 original_uppercase
= key
;
8457 original_uppercase_position
= t
- 1;
8459 modifiers
&= ~shift_modifier
;
8460 new_key
= apply_modifiers (modifiers
,
8463 keybuf
[t
- 1] = new_key
;
8466 fkey_map
= prev_fkey_map
;
8467 fkey_start
= prev_fkey_start
;
8468 fkey_end
= prev_fkey_end
;
8470 keytran_map
= prev_keytran_map
;
8471 keytran_start
= prev_keytran_start
;
8472 keytran_end
= prev_keytran_end
;
8474 goto replay_sequence
;
8480 read_key_sequence_cmd
= (first_binding
< nmaps
8481 ? defs
[first_binding
]
8484 unread_switch_frame
= delayed_switch_frame
;
8485 unbind_to (count
, Qnil
);
8487 /* Don't downcase the last character if the caller says don't.
8488 Don't downcase it if the result is undefined, either. */
8489 if ((dont_downcase_last
|| first_binding
>= nmaps
)
8490 && t
- 1 == original_uppercase_position
)
8491 keybuf
[t
- 1] = original_uppercase
;
8493 /* Occasionally we fabricate events, perhaps by expanding something
8494 according to function-key-map, or by adding a prefix symbol to a
8495 mouse click in the scroll bar or modeline. In this cases, return
8496 the entire generated key sequence, even if we hit an unbound
8497 prefix or a definition before the end. This means that you will
8498 be able to push back the event properly, and also means that
8499 read-key-sequence will always return a logical unit.
8502 for (; t
< mock_input
; t
++)
8504 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
8505 && NILP (Fzerop (Vecho_keystrokes
)))
8506 echo_char (keybuf
[t
]);
8507 add_command_key (keybuf
[t
]);
8515 #if 0 /* This doc string is too long for some compilers.
8516 This commented-out definition serves for DOC. */
8517 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
8518 "Read a sequence of keystrokes and return as a string or vector.\n\
8519 The sequence is sufficient to specify a non-prefix command in the\n\
8520 current local and global maps.\n\
8522 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
8523 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
8524 as a continuation of the previous key.\n\
8526 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not\n\
8527 convert the last event to lower case. (Normally any upper case event\n\
8528 is converted to lower case if the original event is undefined and the lower\n\
8529 case equivalent is defined.) A non-nil value is appropriate for reading\n\
8530 a key sequence to be defined.\n\
8532 A C-g typed while in this function is treated like any other character,\n\
8533 and `quit-flag' is not set.\n\
8535 If the key sequence starts with a mouse click, then the sequence is read\n\
8536 using the keymaps of the buffer of the window clicked in, not the buffer\n\
8537 of the selected window as normal.\n\
8539 `read-key-sequence' drops unbound button-down events, since you normally\n\
8540 only care about the click or drag events which follow them. If a drag\n\
8541 or multi-click event is unbound, but the corresponding click event would\n\
8542 be bound, `read-key-sequence' turns the event into a click event at the\n\
8543 drag's starting position. This means that you don't have to distinguish\n\
8544 between click and drag, double, or triple events unless you want to.\n\
8546 `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\
8547 lines separating windows, and scroll bars with imaginary keys\n\
8548 `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\
8550 Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this\n\
8551 function will process a switch-frame event if the user switches frames\n\
8552 before typing anything. If the user switches frames in the middle of a\n\
8553 key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME\n\
8554 is nil, then the event will be put off until after the current key sequence.\n\
8556 `read-key-sequence' checks `function-key-map' for function key\n\
8557 sequences, where they wouldn't conflict with ordinary bindings. See\n\
8558 `function-key-map' for more details.\n\
8560 The optional fifth argument COMMAND-LOOP, if non-nil, means\n\
8561 that this key sequence is being read by something that will\n\
8562 read commands one after another. It should be nil if the caller\n\
8563 will read just one key sequence.")
8564 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
, command
-loop
)
8567 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 5, 0,
8569 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
8571 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
8572 Lisp_Object can_return_switch_frame
, command_loop
;
8574 Lisp_Object keybuf
[30];
8576 struct gcpro gcpro1
;
8577 int count
= specpdl_ptr
- specpdl
;
8580 CHECK_STRING (prompt
, 0);
8583 specbind (Qinput_method_exit_on_first_char
,
8584 (NILP (command_loop
) ? Qt
: Qnil
));
8585 specbind (Qinput_method_use_echo_area
,
8586 (NILP (command_loop
) ? Qt
: Qnil
));
8588 bzero (keybuf
, sizeof keybuf
);
8590 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
8592 if (NILP (continue_echo
))
8594 this_command_key_count
= 0;
8595 this_single_command_key_start
= 0;
8598 #ifdef HAVE_X_WINDOWS
8599 if (display_busy_cursor_p
)
8600 cancel_busy_cursor ();
8603 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
8604 prompt
, ! NILP (dont_downcase_last
),
8605 ! NILP (can_return_switch_frame
), 0);
8607 #ifdef HAVE_X_WINDOWS
8608 if (display_busy_cursor_p
)
8609 start_busy_cursor ();
8618 return unbind_to (count
, make_event_array (i
, keybuf
));
8621 DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector
,
8622 Sread_key_sequence_vector
, 1, 5, 0,
8623 "Like `read-key-sequence' but always return a vector.")
8624 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
8626 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
8627 Lisp_Object can_return_switch_frame
, command_loop
;
8629 Lisp_Object keybuf
[30];
8631 struct gcpro gcpro1
;
8632 int count
= specpdl_ptr
- specpdl
;
8635 CHECK_STRING (prompt
, 0);
8638 specbind (Qinput_method_exit_on_first_char
,
8639 (NILP (command_loop
) ? Qt
: Qnil
));
8640 specbind (Qinput_method_use_echo_area
,
8641 (NILP (command_loop
) ? Qt
: Qnil
));
8643 bzero (keybuf
, sizeof keybuf
);
8645 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
8647 if (NILP (continue_echo
))
8649 this_command_key_count
= 0;
8650 this_single_command_key_start
= 0;
8653 #ifdef HAVE_X_WINDOWS
8654 if (display_busy_cursor_p
)
8655 cancel_busy_cursor ();
8658 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
8659 prompt
, ! NILP (dont_downcase_last
),
8660 ! NILP (can_return_switch_frame
), 0);
8662 #ifdef HAVE_X_WINDOWS
8663 if (display_busy_cursor_p
)
8664 start_busy_cursor ();
8673 return unbind_to (count
, Fvector (i
, keybuf
));
8676 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 4, 0,
8677 "Execute CMD as an editor command.\n\
8678 CMD must be a symbol that satisfies the `commandp' predicate.\n\
8679 Optional second arg RECORD-FLAG non-nil\n\
8680 means unconditionally put this command in `command-history'.\n\
8681 Otherwise, that is done only if an arg is read using the minibuffer.\n\
8682 The argument KEYS specifies the value to use instead of (this-command-keys)\n\
8683 when reading the arguments; if it is nil, (this-command-keys) is used.\n\
8684 The argument SPECIAL, if non-nil, means that this command is executing\n\
8685 a special event, so ignore the prefix argument and don't clear it.")
8686 (cmd
, record_flag
, keys
, special
)
8687 Lisp_Object cmd
, record_flag
, keys
, special
;
8689 register Lisp_Object final
;
8690 register Lisp_Object tem
;
8691 Lisp_Object prefixarg
;
8692 struct backtrace backtrace
;
8693 extern int debug_on_next_call
;
8695 debug_on_next_call
= 0;
8699 prefixarg
= current_kboard
->Vprefix_arg
;
8700 Vcurrent_prefix_arg
= prefixarg
;
8701 current_kboard
->Vprefix_arg
= Qnil
;
8708 tem
= Fget (cmd
, Qdisabled
);
8709 if (!NILP (tem
) && !NILP (Vrun_hooks
))
8711 tem
= Fsymbol_value (Qdisabled_command_hook
);
8713 return call1 (Vrun_hooks
, Qdisabled_command_hook
);
8719 final
= Findirect_function (cmd
);
8721 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
8723 struct gcpro gcpro1
, gcpro2
;
8725 GCPRO2 (cmd
, prefixarg
);
8726 do_autoload (final
, cmd
);
8733 if (STRINGP (final
) || VECTORP (final
))
8735 /* If requested, place the macro in the command history. For
8736 other sorts of commands, call-interactively takes care of
8738 if (!NILP (record_flag
))
8741 = Fcons (Fcons (Qexecute_kbd_macro
,
8742 Fcons (final
, Fcons (prefixarg
, Qnil
))),
8745 /* Don't keep command history around forever. */
8746 if (NUMBERP (Vhistory_length
) && XINT (Vhistory_length
) > 0)
8748 tem
= Fnthcdr (Vhistory_length
, Vcommand_history
);
8754 return Fexecute_kbd_macro (final
, prefixarg
);
8757 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
8759 backtrace
.next
= backtrace_list
;
8760 backtrace_list
= &backtrace
;
8761 backtrace
.function
= &Qcall_interactively
;
8762 backtrace
.args
= &cmd
;
8763 backtrace
.nargs
= 1;
8764 backtrace
.evalargs
= 0;
8766 tem
= Fcall_interactively (cmd
, record_flag
, keys
);
8768 backtrace_list
= backtrace
.next
;
8774 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
8776 "Read function name, then read its arguments and call it.")
8778 Lisp_Object prefixarg
;
8780 Lisp_Object function
;
8782 Lisp_Object saved_keys
;
8783 Lisp_Object bindings
, value
;
8784 struct gcpro gcpro1
, gcpro2
;
8786 saved_keys
= Fvector (this_command_key_count
,
8787 XVECTOR (this_command_keys
)->contents
);
8789 GCPRO2 (saved_keys
, prefixarg
);
8791 if (EQ (prefixarg
, Qminus
))
8793 else if (CONSP (prefixarg
) && XINT (XCAR (prefixarg
)) == 4)
8794 strcpy (buf
, "C-u ");
8795 else if (CONSP (prefixarg
) && INTEGERP (XCAR (prefixarg
)))
8797 if (sizeof (int) == sizeof (EMACS_INT
))
8798 sprintf (buf
, "%d ", XINT (XCAR (prefixarg
)));
8799 else if (sizeof (long) == sizeof (EMACS_INT
))
8800 sprintf (buf
, "%ld ", (long) XINT (XCAR (prefixarg
)));
8804 else if (INTEGERP (prefixarg
))
8806 if (sizeof (int) == sizeof (EMACS_INT
))
8807 sprintf (buf
, "%d ", XINT (prefixarg
));
8808 else if (sizeof (long) == sizeof (EMACS_INT
))
8809 sprintf (buf
, "%ld ", (long) XINT (prefixarg
));
8814 /* This isn't strictly correct if execute-extended-command
8815 is bound to anything else. Perhaps it should use
8816 this_command_keys? */
8817 strcat (buf
, "M-x ");
8819 /* Prompt with buf, and then read a string, completing from and
8820 restricting to the set of all defined commands. Don't provide
8821 any initial input. Save the command read on the extended-command
8823 function
= Fcompleting_read (build_string (buf
),
8824 Vobarray
, Qcommandp
,
8825 Qt
, Qnil
, Qextended_command_history
, Qnil
,
8828 if (STRINGP (function
) && XSTRING (function
)->size
== 0)
8829 error ("No command name given");
8831 /* Set this_command_keys to the concatenation of saved_keys and
8832 function, followed by a RET. */
8834 struct Lisp_String
*str
;
8838 this_command_key_count
= 0;
8839 this_single_command_key_start
= 0;
8841 keys
= XVECTOR (saved_keys
)->contents
;
8842 for (i
= 0; i
< XVECTOR (saved_keys
)->size
; i
++)
8843 add_command_key (keys
[i
]);
8845 str
= XSTRING (function
);
8846 for (i
= 0; i
< str
->size
; i
++)
8847 add_command_key (Faref (function
, make_number (i
)));
8849 add_command_key (make_number ('\015'));
8854 function
= Fintern (function
, Qnil
);
8855 current_kboard
->Vprefix_arg
= prefixarg
;
8856 Vthis_command
= function
;
8857 real_this_command
= function
;
8859 /* If enabled, show which key runs this command. */
8860 if (!NILP (Vsuggest_key_bindings
)
8861 && NILP (Vexecuting_macro
)
8862 && SYMBOLP (function
))
8863 bindings
= Fwhere_is_internal (function
, Voverriding_local_map
,
8869 GCPRO2 (bindings
, value
);
8870 value
= Fcommand_execute (function
, Qt
, Qnil
, Qnil
);
8872 /* If the command has a key binding, print it now. */
8873 if (!NILP (bindings
)
8874 && ! (VECTORP (bindings
) && EQ (Faref (bindings
, make_number (0)),
8877 /* But first wait, and skip the message if there is input. */
8879 if (!NILP (echo_area_buffer
[0]))
8880 /* This command displayed something in the echo area;
8881 so wait a few seconds, then display our suggestion message. */
8882 delay_time
= (NUMBERP (Vsuggest_key_bindings
)
8883 ? XINT (Vsuggest_key_bindings
) : 2);
8885 /* This command left the echo area empty,
8886 so display our message immediately. */
8889 if (!NILP (Fsit_for (make_number (delay_time
), Qnil
, Qnil
))
8890 && ! CONSP (Vunread_command_events
))
8892 Lisp_Object binding
;
8894 int message_p
= push_message ();
8896 binding
= Fkey_description (bindings
);
8899 = (char *) alloca (XSYMBOL (function
)->name
->size
8900 + STRING_BYTES (XSTRING (binding
))
8902 sprintf (newmessage
, "You can run the command `%s' with %s",
8903 XSYMBOL (function
)->name
->data
,
8904 XSTRING (binding
)->data
);
8905 message2_nolog (newmessage
,
8906 strlen (newmessage
),
8907 STRING_MULTIBYTE (binding
));
8908 if (!NILP (Fsit_for ((NUMBERP (Vsuggest_key_bindings
)
8909 ? Vsuggest_key_bindings
: make_number (2)),
8918 RETURN_UNGCPRO (value
);
8921 /* Find the set of keymaps now active.
8922 Store into *MAPS_P a vector holding the various maps
8923 and return the number of them. The vector was malloc'd
8924 and the caller should free it. */
8927 current_active_maps (maps_p
)
8928 Lisp_Object
**maps_p
;
8930 Lisp_Object
*tmaps
, *maps
;
8933 /* Should overriding-terminal-local-map and overriding-local-map apply? */
8934 if (!NILP (Voverriding_local_map_menu_flag
))
8936 /* Yes, use them (if non-nil) as well as the global map. */
8937 maps
= (Lisp_Object
*) xmalloc (3 * sizeof (maps
[0]));
8939 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
8940 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
8941 if (!NILP (Voverriding_local_map
))
8942 maps
[nmaps
++] = Voverriding_local_map
;
8946 /* No, so use major and minor mode keymaps and keymap property. */
8948 Lisp_Object map
= get_local_map (PT
, current_buffer
, keymap
);
8951 nmaps
= current_minor_maps (NULL
, &tmaps
);
8952 maps
= (Lisp_Object
*) alloca ((nmaps
+ extra_maps
)
8953 * sizeof (maps
[0]));
8954 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
8956 maps
[nmaps
++] = get_local_map (PT
, current_buffer
, keymap
);
8957 maps
[nmaps
++] = get_local_map (PT
, current_buffer
, local_map
);
8959 maps
[nmaps
++] = current_global_map
;
8965 /* Return nonzero if input events are pending. */
8968 detect_input_pending ()
8971 get_input_pending (&input_pending
, 0);
8973 return input_pending
;
8976 /* Return nonzero if input events are pending, and run any pending timers. */
8979 detect_input_pending_run_timers (do_display
)
8982 int old_timers_run
= timers_run
;
8985 get_input_pending (&input_pending
, 1);
8987 if (old_timers_run
!= timers_run
&& do_display
)
8989 redisplay_preserve_echo_area ();
8990 /* The following fixes a bug when using lazy-lock with
8991 lazy-lock-defer-on-the-fly set to t, i.e. when fontifying
8992 from an idle timer function. The symptom of the bug is that
8993 the cursor sometimes doesn't become visible until the next X
8994 event is processed. --gerd. */
8996 rif
->flush_display (NULL
);
8999 return input_pending
;
9002 /* This is called in some cases before a possible quit.
9003 It cases the next call to detect_input_pending to recompute input_pending.
9004 So calling this function unnecessarily can't do any harm. */
9007 clear_input_pending ()
9012 /* Return nonzero if there are pending requeued events.
9013 This isn't used yet. The hope is to make wait_reading_process_input
9014 call it, and return return if it runs Lisp code that unreads something.
9015 The problem is, kbd_buffer_get_event needs to be fixed to know what
9016 to do in that case. It isn't trivial. */
9019 requeued_events_pending_p ()
9021 return (!NILP (Vunread_command_events
) || unread_command_char
!= -1);
9025 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
9026 "T if command input is currently available with no waiting.\n\
9027 Actually, the value is nil only if we can be sure that no input is available.")
9030 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1)
9033 get_input_pending (&input_pending
, 1);
9034 return input_pending
> 0 ? Qt
: Qnil
;
9037 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
9038 "Return vector of last 100 events, not counting those from keyboard macros.")
9041 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
9044 if (total_keys
< NUM_RECENT_KEYS
)
9045 return Fvector (total_keys
, keys
);
9048 val
= Fvector (NUM_RECENT_KEYS
, keys
);
9049 bcopy (keys
+ recent_keys_index
,
9050 XVECTOR (val
)->contents
,
9051 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
9053 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
9054 recent_keys_index
* sizeof (Lisp_Object
));
9059 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
9060 "Return the key sequence that invoked this command.\n\
9061 The value is a string or a vector.")
9064 return make_event_array (this_command_key_count
,
9065 XVECTOR (this_command_keys
)->contents
);
9068 DEFUN ("this-command-keys-vector", Fthis_command_keys_vector
, Sthis_command_keys_vector
, 0, 0, 0,
9069 "Return the key sequence that invoked this command, as a vector.")
9072 return Fvector (this_command_key_count
,
9073 XVECTOR (this_command_keys
)->contents
);
9076 DEFUN ("this-single-command-keys", Fthis_single_command_keys
,
9077 Sthis_single_command_keys
, 0, 0, 0,
9078 "Return the key sequence that invoked this command.\n\
9079 Unlike `this-command-keys', this function's value\n\
9080 does not include prefix arguments.\n\
9081 The value is always a vector.")
9084 return Fvector (this_command_key_count
9085 - this_single_command_key_start
,
9086 (XVECTOR (this_command_keys
)->contents
9087 + this_single_command_key_start
));
9090 DEFUN ("this-single-command-raw-keys", Fthis_single_command_raw_keys
,
9091 Sthis_single_command_raw_keys
, 0, 0, 0,
9092 "Return the raw events that were read for this command.\n\
9093 Unlike `this-single-command-keys', this function's value\n\
9094 shows the events before all translations (except for input methods).\n\
9095 The value is always a vector.")
9098 return Fvector (raw_keybuf_count
,
9099 (XVECTOR (raw_keybuf
)->contents
));
9102 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths
,
9103 Sreset_this_command_lengths
, 0, 0, 0,
9104 "Used for complicated reasons in `universal-argument-other-key'.\n\
9106 `universal-argument-other-key' rereads the event just typed.\n\
9107 It then gets translated through `function-key-map'.\n\
9108 The translated event gets included in the echo area and in\n\
9109 the value of `this-command-keys' in addition to the raw original event.\n\
9110 That is not right.\n\
9112 Calling this function directs the translated event to replace\n\
9113 the original event, so that only one version of the event actually\n\
9114 appears in the echo area and in the value of `this-command-keys.'.")
9117 before_command_restore_flag
= 1;
9118 before_command_key_count_1
= before_command_key_count
;
9119 before_command_echo_length_1
= before_command_echo_length
;
9123 DEFUN ("clear-this-command-keys", Fclear_this_command_keys
,
9124 Sclear_this_command_keys
, 0, 0, 0,
9125 "Clear out the vector that `this-command-keys' returns.\n\
9126 Clear vector containing last 100 events.")
9131 this_command_key_count
= 0;
9133 for (i
= 0; i
< XVECTOR (recent_keys
)->size
; ++i
)
9134 XVECTOR (recent_keys
)->contents
[i
] = Qnil
;
9136 recent_keys_index
= 0;
9140 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
9141 "Return the current depth in recursive edits.")
9145 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
9149 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
9150 "FOpen dribble file: ",
9151 "Start writing all keyboard characters to a dribble file called FILE.\n\
9152 If FILE is nil, close any open dribble file.")
9163 file
= Fexpand_file_name (file
, Qnil
);
9164 dribble
= fopen (XSTRING (file
)->data
, "w");
9166 report_file_error ("Opening dribble", Fcons (file
, Qnil
));
9171 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
9172 "Discard the contents of the terminal input buffer.\n\
9173 Also cancel any kbd macro being defined.")
9176 current_kboard
->defining_kbd_macro
= Qnil
;
9177 update_mode_lines
++;
9179 Vunread_command_events
= Qnil
;
9180 unread_command_char
= -1;
9182 discard_tty_input ();
9184 kbd_fetch_ptr
= kbd_store_ptr
;
9185 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
9191 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
9192 "Stop Emacs and return to superior process. You can resume later.\n\
9193 If `cannot-suspend' is non-nil, or if the system doesn't support job\n\
9194 control, run a subshell instead.\n\n\
9195 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
9196 to be read as terminal input by Emacs's parent, after suspension.\n\
9198 Before suspending, run the normal hook `suspend-hook'.\n\
9199 After resumption run the normal hook `suspend-resume-hook'.\n\
9201 Some operating systems cannot stop the Emacs process and resume it later.\n\
9202 On such systems, Emacs starts a subshell instead of suspending.")
9204 Lisp_Object stuffstring
;
9206 int count
= specpdl_ptr
- specpdl
;
9207 int old_height
, old_width
;
9209 struct gcpro gcpro1
;
9211 if (!NILP (stuffstring
))
9212 CHECK_STRING (stuffstring
, 0);
9214 /* Run the functions in suspend-hook. */
9215 if (!NILP (Vrun_hooks
))
9216 call1 (Vrun_hooks
, intern ("suspend-hook"));
9218 GCPRO1 (stuffstring
);
9219 get_frame_size (&old_width
, &old_height
);
9221 /* sys_suspend can get an error if it tries to fork a subshell
9222 and the system resources aren't available for that. */
9223 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object
))) init_sys_modes
,
9225 stuff_buffered_input (stuffstring
);
9230 unbind_to (count
, Qnil
);
9232 /* Check if terminal/window size has changed.
9233 Note that this is not useful when we are running directly
9234 with a window system; but suspend should be disabled in that case. */
9235 get_frame_size (&width
, &height
);
9236 if (width
!= old_width
|| height
!= old_height
)
9237 change_frame_size (SELECTED_FRAME (), height
, width
, 0, 0, 0);
9239 /* Run suspend-resume-hook. */
9240 if (!NILP (Vrun_hooks
))
9241 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
9247 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
9248 Then in any case stuff anything Emacs has read ahead and not used. */
9251 stuff_buffered_input (stuffstring
)
9252 Lisp_Object stuffstring
;
9254 /* stuff_char works only in BSD, versions 4.2 and up. */
9257 register unsigned char *p
;
9259 if (STRINGP (stuffstring
))
9263 p
= XSTRING (stuffstring
)->data
;
9264 count
= STRING_BYTES (XSTRING (stuffstring
));
9269 /* Anything we have read ahead, put back for the shell to read. */
9270 /* ?? What should this do when we have multiple keyboards??
9271 Should we ignore anything that was typed in at the "wrong" kboard? */
9272 for (; kbd_fetch_ptr
!= kbd_store_ptr
; kbd_fetch_ptr
++)
9274 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
9275 kbd_fetch_ptr
= kbd_buffer
;
9276 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
9277 stuff_char (kbd_fetch_ptr
->code
);
9278 kbd_fetch_ptr
->kind
= no_event
;
9279 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_fetch_ptr
9285 #endif /* BSD_SYSTEM and not BSD4_1 */
9289 set_waiting_for_input (time_to_clear
)
9290 EMACS_TIME
*time_to_clear
;
9292 input_available_clear_time
= time_to_clear
;
9294 /* Tell interrupt_signal to throw back to read_char, */
9295 waiting_for_input
= 1;
9297 /* If interrupt_signal was called before and buffered a C-g,
9298 make it run again now, to avoid timing error. */
9299 if (!NILP (Vquit_flag
))
9300 quit_throw_to_read_char ();
9304 clear_waiting_for_input ()
9306 /* Tell interrupt_signal not to throw back to read_char, */
9307 waiting_for_input
= 0;
9308 input_available_clear_time
= 0;
9311 /* This routine is called at interrupt level in response to C-G.
9312 If interrupt_input, this is the handler for SIGINT.
9313 Otherwise, it is called from kbd_buffer_store_event,
9314 in handling SIGIO or SIGTINT.
9316 If `waiting_for_input' is non zero, then unless `echoing' is nonzero,
9317 immediately throw back to read_char.
9319 Otherwise it sets the Lisp variable quit-flag not-nil.
9320 This causes eval to throw, when it gets a chance.
9321 If quit-flag is already non-nil, it stops the job right away. */
9324 interrupt_signal (signalnum
) /* If we don't have an argument, */
9325 int signalnum
; /* some compilers complain in signal calls. */
9328 /* Must preserve main program's value of errno. */
9329 int old_errno
= errno
;
9330 struct frame
*sf
= SELECTED_FRAME ();
9332 #if defined (USG) && !defined (POSIX_SIGNALS)
9333 if (!read_socket_hook
&& NILP (Vwindow_system
))
9335 /* USG systems forget handlers when they are used;
9336 must reestablish each time */
9337 signal (SIGINT
, interrupt_signal
);
9338 signal (SIGQUIT
, interrupt_signal
);
9344 if (!NILP (Vquit_flag
)
9345 && (FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
)))
9347 /* If SIGINT isn't blocked, don't let us be interrupted by
9348 another SIGINT, it might be harmful due to non-reentrancy
9349 in I/O functions. */
9350 sigblock (sigmask (SIGINT
));
9355 #ifdef SIGTSTP /* Support possible in later USG versions */
9357 * On systems which can suspend the current process and return to the original
9358 * shell, this command causes the user to end up back at the shell.
9359 * The "Auto-save" and "Abort" questions are not asked until
9360 * the user elects to return to emacs, at which point he can save the current
9361 * job and either dump core or continue.
9366 if (sys_suspend () == -1)
9368 printf ("Not running as a subprocess;\n");
9369 printf ("you can continue or abort.\n");
9372 /* Perhaps should really fork an inferior shell?
9373 But that would not provide any way to get back
9374 to the original shell, ever. */
9375 printf ("No support for stopping a process on this operating system;\n");
9376 printf ("you can continue or abort.\n");
9377 #endif /* not VMS */
9378 #endif /* not SIGTSTP */
9380 /* We must remain inside the screen area when the internal terminal
9381 is used. Note that [Enter] is not echoed by dos. */
9384 /* It doesn't work to autosave while GC is in progress;
9385 the code used for auto-saving doesn't cope with the mark bit. */
9386 if (!gc_in_progress
)
9388 printf ("Auto-save? (y or n) ");
9390 if (((c
= getchar ()) & ~040) == 'Y')
9392 Fdo_auto_save (Qt
, Qnil
);
9394 printf ("\r\nAuto-save done");
9395 #else /* not MSDOS */
9396 printf ("Auto-save done\n");
9397 #endif /* not MSDOS */
9399 while (c
!= '\n') c
= getchar ();
9403 /* During GC, it must be safe to reenable quitting again. */
9404 Vinhibit_quit
= Qnil
;
9407 #endif /* not MSDOS */
9408 printf ("Garbage collection in progress; cannot auto-save now\r\n");
9409 printf ("but will instead do a real quit after garbage collection ends\r\n");
9414 printf ("\r\nAbort? (y or n) ");
9415 #else /* not MSDOS */
9417 printf ("Abort (and enter debugger)? (y or n) ");
9419 printf ("Abort (and dump core)? (y or n) ");
9420 #endif /* not VMS */
9421 #endif /* not MSDOS */
9423 if (((c
= getchar ()) & ~040) == 'Y')
9425 while (c
!= '\n') c
= getchar ();
9427 printf ("\r\nContinuing...\r\n");
9428 #else /* not MSDOS */
9429 printf ("Continuing...\n");
9430 #endif /* not MSDOS */
9437 /* If executing a function that wants to be interrupted out of
9438 and the user has not deferred quitting by binding `inhibit-quit'
9439 then quit right away. */
9440 if (immediate_quit
&& NILP (Vinhibit_quit
))
9442 struct gl_state_s saved
;
9443 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9448 GCPRO4 (saved
.object
, saved
.global_code
,
9449 saved
.current_syntax_table
, saved
.old_prop
);
9450 Fsignal (Qquit
, Qnil
);
9455 /* Else request quit when it's safe */
9459 if (waiting_for_input
&& !echoing
)
9460 quit_throw_to_read_char ();
9465 /* Handle a C-g by making read_char return C-g. */
9468 quit_throw_to_read_char ()
9471 /* Prevent another signal from doing this before we finish. */
9472 clear_waiting_for_input ();
9475 Vunread_command_events
= Qnil
;
9476 unread_command_char
= -1;
9478 #if 0 /* Currently, sit_for is called from read_char without turning
9479 off polling. And that can call set_waiting_for_input.
9480 It seems to be harmless. */
9481 #ifdef POLL_FOR_INPUT
9482 /* May be > 1 if in recursive minibuffer. */
9483 if (poll_suppress_count
== 0)
9487 if (FRAMEP (internal_last_event_frame
)
9488 && !EQ (internal_last_event_frame
, selected_frame
))
9489 do_switch_frame (make_lispy_switch_frame (internal_last_event_frame
),
9492 _longjmp (getcjmp
, 1);
9495 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
9496 "Set mode of reading keyboard input.\n\
9497 First arg INTERRUPT non-nil means use input interrupts;\n\
9498 nil means use CBREAK mode.\n\
9499 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
9500 (no effect except in CBREAK mode).\n\
9501 Third arg META t means accept 8-bit input (for a Meta key).\n\
9502 META nil means ignore the top bit, on the assumption it is parity.\n\
9503 Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\
9504 Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\
9505 See also `current-input-mode'.")
9506 (interrupt
, flow
, meta
, quit
)
9507 Lisp_Object interrupt
, flow
, meta
, quit
;
9510 && (!INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400))
9511 error ("set-input-mode: QUIT must be an ASCII character");
9513 #ifdef POLL_FOR_INPUT
9518 /* this causes startup screen to be restored and messes with the mouse */
9523 /* Note SIGIO has been undef'd if FIONREAD is missing. */
9524 if (read_socket_hook
)
9526 /* When using X, don't give the user a real choice,
9527 because we haven't implemented the mechanisms to support it. */
9528 #ifdef NO_SOCK_SIGIO
9529 interrupt_input
= 0;
9530 #else /* not NO_SOCK_SIGIO */
9531 interrupt_input
= 1;
9532 #endif /* NO_SOCK_SIGIO */
9535 interrupt_input
= !NILP (interrupt
);
9536 #else /* not SIGIO */
9537 interrupt_input
= 0;
9538 #endif /* not SIGIO */
9540 /* Our VMS input only works by interrupts, as of now. */
9542 interrupt_input
= 1;
9545 flow_control
= !NILP (flow
);
9548 else if (EQ (meta
, Qt
))
9553 /* Don't let this value be out of range. */
9554 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
9560 #ifdef POLL_FOR_INPUT
9561 poll_suppress_count
= 1;
9567 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
9568 "Return information about the way Emacs currently reads keyboard input.\n\
9569 The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
9570 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\
9571 nil, Emacs is using CBREAK mode.\n\
9572 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\
9573 terminal; this does not apply if Emacs uses interrupt-driven input.\n\
9574 META is t if accepting 8-bit input with 8th bit as Meta flag.\n\
9575 META nil means ignoring the top bit, on the assumption it is parity.\n\
9576 META is neither t nor nil if accepting 8-bit input and using\n\
9577 all 8 bits as the character code.\n\
9578 QUIT is the character Emacs currently uses to quit.\n\
9579 The elements of this list correspond to the arguments of\n\
9585 val
[0] = interrupt_input
? Qt
: Qnil
;
9586 val
[1] = flow_control
? Qt
: Qnil
;
9587 val
[2] = meta_key
== 2 ? make_number (0) : meta_key
== 1 ? Qt
: Qnil
;
9588 XSETFASTINT (val
[3], quit_char
);
9590 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
9595 * Set up a new kboard object with reasonable initial values.
9601 kb
->Voverriding_terminal_local_map
= Qnil
;
9602 kb
->Vlast_command
= Qnil
;
9603 kb
->Vreal_last_command
= Qnil
;
9604 kb
->Vprefix_arg
= Qnil
;
9605 kb
->Vlast_prefix_arg
= Qnil
;
9606 kb
->kbd_queue
= Qnil
;
9607 kb
->kbd_queue_has_data
= 0;
9608 kb
->immediate_echo
= 0;
9609 kb
->echoptr
= kb
->echobuf
;
9610 kb
->echo_after_prompt
= -1;
9611 kb
->kbd_macro_buffer
= 0;
9612 kb
->kbd_macro_bufsize
= 0;
9613 kb
->defining_kbd_macro
= Qnil
;
9614 kb
->Vlast_kbd_macro
= Qnil
;
9615 kb
->reference_count
= 0;
9616 kb
->Vsystem_key_alist
= Qnil
;
9617 kb
->system_key_syms
= Qnil
;
9618 kb
->Vdefault_minibuffer_frame
= Qnil
;
9622 * Destroy the contents of a kboard object, but not the object itself.
9623 * We use this just before deleting it, or if we're going to initialize
9630 if (kb
->kbd_macro_buffer
)
9631 xfree (kb
->kbd_macro_buffer
);
9640 for (kbp
= &all_kboards
; *kbp
!= kb
; kbp
= &(*kbp
)->next_kboard
)
9643 *kbp
= kb
->next_kboard
;
9652 /* This is correct before outermost invocation of the editor loop */
9653 command_loop_level
= -1;
9655 quit_char
= Ctl ('g');
9656 Vunread_command_events
= Qnil
;
9657 unread_command_char
= -1;
9658 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
9660 recent_keys_index
= 0;
9661 kbd_fetch_ptr
= kbd_buffer
;
9662 kbd_store_ptr
= kbd_buffer
;
9663 kbd_buffer_frame_or_window
9664 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
9666 do_mouse_tracking
= Qnil
;
9670 /* This means that command_loop_1 won't try to select anything the first
9672 internal_last_event_frame
= Qnil
;
9673 Vlast_event_frame
= internal_last_event_frame
;
9676 current_kboard
= initial_kboard
;
9678 wipe_kboard (current_kboard
);
9679 init_kboard (current_kboard
);
9682 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
9684 kbd_buffer_frame_or_window
9685 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
9686 if (!noninteractive
&& !read_socket_hook
&& NILP (Vwindow_system
))
9688 signal (SIGINT
, interrupt_signal
);
9689 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
9690 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
9691 SIGQUIT and we can't tell which one it will give us. */
9692 signal (SIGQUIT
, interrupt_signal
);
9693 #endif /* HAVE_TERMIO */
9695 /* Note SIGIO has been undef'd if FIONREAD is missing. */
9697 if (!noninteractive
)
9698 signal (SIGIO
, input_available_signal
);
9701 /* Use interrupt input by default, if it works and noninterrupt input
9702 has deficiencies. */
9704 #ifdef INTERRUPT_INPUT
9705 interrupt_input
= 1;
9707 interrupt_input
= 0;
9710 /* Our VMS input only works by interrupts, as of now. */
9712 interrupt_input
= 1;
9718 if (keyboard_init_hook
)
9719 (*keyboard_init_hook
) ();
9721 #ifdef POLL_FOR_INPUT
9722 poll_suppress_count
= 1;
9727 /* This type's only use is in syms_of_keyboard, to initialize the
9728 event header symbols and put properties on them. */
9735 struct event_head head_table
[] = {
9736 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
9737 &Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
,
9738 &Qswitch_frame
, "switch-frame", &Qswitch_frame
,
9739 &Qdelete_frame
, "delete-frame", &Qdelete_frame
,
9740 &Qiconify_frame
, "iconify-frame", &Qiconify_frame
,
9741 &Qmake_frame_visible
, "make-frame-visible", &Qmake_frame_visible
,
9747 Vlispy_mouse_stem
= build_string ("mouse");
9748 staticpro (&Vlispy_mouse_stem
);
9751 QCimage
= intern (":image");
9752 staticpro (&QCimage
);
9754 staticpro (&Qhelp_echo
);
9755 Qhelp_echo
= intern ("help-echo");
9757 staticpro (&item_properties
);
9758 item_properties
= Qnil
;
9760 staticpro (&tool_bar_item_properties
);
9761 tool_bar_item_properties
= Qnil
;
9762 staticpro (&tool_bar_items_vector
);
9763 tool_bar_items_vector
= Qnil
;
9765 staticpro (&real_this_command
);
9766 real_this_command
= Qnil
;
9768 Qtimer_event_handler
= intern ("timer-event-handler");
9769 staticpro (&Qtimer_event_handler
);
9771 Qdisabled_command_hook
= intern ("disabled-command-hook");
9772 staticpro (&Qdisabled_command_hook
);
9774 Qself_insert_command
= intern ("self-insert-command");
9775 staticpro (&Qself_insert_command
);
9777 Qforward_char
= intern ("forward-char");
9778 staticpro (&Qforward_char
);
9780 Qbackward_char
= intern ("backward-char");
9781 staticpro (&Qbackward_char
);
9783 Qdisabled
= intern ("disabled");
9784 staticpro (&Qdisabled
);
9786 Qundefined
= intern ("undefined");
9787 staticpro (&Qundefined
);
9789 Qpre_command_hook
= intern ("pre-command-hook");
9790 staticpro (&Qpre_command_hook
);
9792 Qpost_command_hook
= intern ("post-command-hook");
9793 staticpro (&Qpost_command_hook
);
9795 Qpost_command_idle_hook
= intern ("post-command-idle-hook");
9796 staticpro (&Qpost_command_idle_hook
);
9798 Qdeferred_action_function
= intern ("deferred-action-function");
9799 staticpro (&Qdeferred_action_function
);
9801 Qcommand_hook_internal
= intern ("command-hook-internal");
9802 staticpro (&Qcommand_hook_internal
);
9804 Qfunction_key
= intern ("function-key");
9805 staticpro (&Qfunction_key
);
9806 Qmouse_click
= intern ("mouse-click");
9807 staticpro (&Qmouse_click
);
9809 Qmouse_wheel
= intern ("mouse-wheel");
9810 staticpro (&Qmouse_wheel
);
9811 Qlanguage_change
= intern ("language-change");
9812 staticpro (&Qlanguage_change
);
9814 Qdrag_n_drop
= intern ("drag-n-drop");
9815 staticpro (&Qdrag_n_drop
);
9817 Qusr1_signal
= intern ("usr1-signal");
9818 staticpro (&Qusr1_signal
);
9819 Qusr2_signal
= intern ("usr2-signal");
9820 staticpro (&Qusr2_signal
);
9822 Qmenu_enable
= intern ("menu-enable");
9823 staticpro (&Qmenu_enable
);
9824 Qmenu_alias
= intern ("menu-alias");
9825 staticpro (&Qmenu_alias
);
9826 QCenable
= intern (":enable");
9827 staticpro (&QCenable
);
9828 QCvisible
= intern (":visible");
9829 staticpro (&QCvisible
);
9830 QChelp
= intern (":help");
9831 staticpro (&QChelp
);
9832 QCfilter
= intern (":filter");
9833 staticpro (&QCfilter
);
9834 QCbutton
= intern (":button");
9835 staticpro (&QCbutton
);
9836 QCkeys
= intern (":keys");
9837 staticpro (&QCkeys
);
9838 QCkey_sequence
= intern (":key-sequence");
9839 staticpro (&QCkey_sequence
);
9840 QCtoggle
= intern (":toggle");
9841 staticpro (&QCtoggle
);
9842 QCradio
= intern (":radio");
9843 staticpro (&QCradio
);
9845 Qmode_line
= intern ("mode-line");
9846 staticpro (&Qmode_line
);
9847 Qvertical_line
= intern ("vertical-line");
9848 staticpro (&Qvertical_line
);
9849 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
9850 staticpro (&Qvertical_scroll_bar
);
9851 Qmenu_bar
= intern ("menu-bar");
9852 staticpro (&Qmenu_bar
);
9854 Qabove_handle
= intern ("above-handle");
9855 staticpro (&Qabove_handle
);
9856 Qhandle
= intern ("handle");
9857 staticpro (&Qhandle
);
9858 Qbelow_handle
= intern ("below-handle");
9859 staticpro (&Qbelow_handle
);
9860 Qup
= intern ("up");
9862 Qdown
= intern ("down");
9864 Qtop
= intern ("top");
9866 Qbottom
= intern ("bottom");
9867 staticpro (&Qbottom
);
9868 Qend_scroll
= intern ("end-scroll");
9869 staticpro (&Qend_scroll
);
9870 Qratio
= intern ("ratio");
9871 staticpro (&Qratio
);
9873 Qevent_kind
= intern ("event-kind");
9874 staticpro (&Qevent_kind
);
9875 Qevent_symbol_elements
= intern ("event-symbol-elements");
9876 staticpro (&Qevent_symbol_elements
);
9877 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
9878 staticpro (&Qevent_symbol_element_mask
);
9879 Qmodifier_cache
= intern ("modifier-cache");
9880 staticpro (&Qmodifier_cache
);
9882 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
9883 staticpro (&Qrecompute_lucid_menubar
);
9884 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
9885 staticpro (&Qactivate_menubar_hook
);
9887 Qpolling_period
= intern ("polling-period");
9888 staticpro (&Qpolling_period
);
9890 Qinput_method_function
= intern ("input-method-function");
9891 staticpro (&Qinput_method_function
);
9893 Qinput_method_exit_on_first_char
= intern ("input-method-exit-on-first-char");
9894 staticpro (&Qinput_method_exit_on_first_char
);
9895 Qinput_method_use_echo_area
= intern ("input-method-use-echo-area");
9896 staticpro (&Qinput_method_use_echo_area
);
9898 Fset (Qinput_method_exit_on_first_char
, Qnil
);
9899 Fset (Qinput_method_use_echo_area
, Qnil
);
9902 struct event_head
*p
;
9904 for (p
= head_table
;
9905 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
9908 *p
->var
= intern (p
->name
);
9910 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
9911 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
9915 button_down_location
= Fmake_vector (make_number (1), Qnil
);
9916 staticpro (&button_down_location
);
9917 mouse_syms
= Fmake_vector (make_number (1), Qnil
);
9918 staticpro (&mouse_syms
);
9922 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
9924 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
9925 for (i
= 0; i
< len
; i
++)
9926 if (modifier_names
[i
])
9927 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
9928 staticpro (&modifier_symbols
);
9931 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
9932 staticpro (&recent_keys
);
9934 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
9935 staticpro (&this_command_keys
);
9937 raw_keybuf
= Fmake_vector (make_number (30), Qnil
);
9938 staticpro (&raw_keybuf
);
9940 Qextended_command_history
= intern ("extended-command-history");
9941 Fset (Qextended_command_history
, Qnil
);
9942 staticpro (&Qextended_command_history
);
9944 kbd_buffer_frame_or_window
9945 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
9946 staticpro (&kbd_buffer_frame_or_window
);
9948 accent_key_syms
= Qnil
;
9949 staticpro (&accent_key_syms
);
9951 func_key_syms
= Qnil
;
9952 staticpro (&func_key_syms
);
9955 mouse_wheel_syms
= Qnil
;
9956 staticpro (&mouse_wheel_syms
);
9958 drag_n_drop_syms
= Qnil
;
9959 staticpro (&drag_n_drop_syms
);
9962 unread_switch_frame
= Qnil
;
9963 staticpro (&unread_switch_frame
);
9965 internal_last_event_frame
= Qnil
;
9966 staticpro (&internal_last_event_frame
);
9968 read_key_sequence_cmd
= Qnil
;
9969 staticpro (&read_key_sequence_cmd
);
9971 menu_bar_one_keymap_changed_items
= Qnil
;
9972 staticpro (&menu_bar_one_keymap_changed_items
);
9974 defsubr (&Sevent_convert_list
);
9975 defsubr (&Sread_key_sequence
);
9976 defsubr (&Sread_key_sequence_vector
);
9977 defsubr (&Srecursive_edit
);
9979 defsubr (&Strack_mouse
);
9981 defsubr (&Sinput_pending_p
);
9982 defsubr (&Scommand_execute
);
9983 defsubr (&Srecent_keys
);
9984 defsubr (&Sthis_command_keys
);
9985 defsubr (&Sthis_command_keys_vector
);
9986 defsubr (&Sthis_single_command_keys
);
9987 defsubr (&Sthis_single_command_raw_keys
);
9988 defsubr (&Sreset_this_command_lengths
);
9989 defsubr (&Sclear_this_command_keys
);
9990 defsubr (&Ssuspend_emacs
);
9991 defsubr (&Sabort_recursive_edit
);
9992 defsubr (&Sexit_recursive_edit
);
9993 defsubr (&Srecursion_depth
);
9994 defsubr (&Stop_level
);
9995 defsubr (&Sdiscard_input
);
9996 defsubr (&Sopen_dribble_file
);
9997 defsubr (&Sset_input_mode
);
9998 defsubr (&Scurrent_input_mode
);
9999 defsubr (&Sexecute_extended_command
);
10001 DEFVAR_LISP ("last-command-char", &last_command_char
,
10002 "Last input event that was part of a command.");
10004 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char
,
10005 "Last input event that was part of a command.");
10007 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
10008 "Last input event in a command, except for mouse menu events.\n\
10009 Mouse menus give back keys that don't look like mouse events;\n\
10010 this variable holds the actual mouse event that led to the menu,\n\
10011 so that you can determine whether the command was run by mouse or not.");
10013 DEFVAR_LISP ("last-input-char", &last_input_char
,
10014 "Last input event.");
10016 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char
,
10017 "Last input event.");
10019 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
10020 "List of events to be read as the command input.\n\
10021 These events are processed first, before actual keyboard input.");
10022 Vunread_command_events
= Qnil
;
10024 DEFVAR_INT ("unread-command-char", &unread_command_char
,
10025 "If not -1, an object to be read as next command input event.");
10027 DEFVAR_LISP ("unread-post-input-method-events", &Vunread_post_input_method_events
,
10028 "List of events to be processed as input by input methods.\n\
10029 These events are processed after `unread-command-events', but\n\
10030 before actual keyboard input.");
10031 Vunread_post_input_method_events
= Qnil
;
10033 DEFVAR_LISP ("unread-input-method-events", &Vunread_input_method_events
,
10034 "List of events to be processed as input by input methods.\n\
10035 These events are processed after `unread-command-events', but\n\
10036 before actual keyboard input.");
10037 Vunread_input_method_events
= Qnil
;
10039 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
10040 "Meta-prefix character code.\n\
10041 Meta-foo as command input turns into this character followed by foo.");
10042 XSETINT (meta_prefix_char
, 033);
10044 DEFVAR_KBOARD ("last-command", Vlast_command
,
10045 "The last command executed.\n\
10046 Normally a symbol with a function definition, but can be whatever was found\n\
10047 in the keymap, or whatever the variable `this-command' was set to by that\n\
10050 The value `mode-exit' is special; it means that the previous command\n\
10051 read an event that told it to exit, and it did so and unread that event.\n\
10052 In other words, the present command is the event that made the previous\n\
10055 The value `kill-region' is special; it means that the previous command\n\
10056 was a kill command.");
10058 DEFVAR_KBOARD ("real-last-command", Vreal_last_command
,
10059 "Same as `last-command', but never altered by Lisp code.");
10061 DEFVAR_LISP ("this-command", &Vthis_command
,
10062 "The command now being executed.\n\
10063 The command can set this variable; whatever is put here\n\
10064 will be in `last-command' during the following command.");
10065 Vthis_command
= Qnil
;
10067 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
10068 "*Number of input events between auto-saves.\n\
10069 Zero means disable autosaving due to number of characters typed.");
10070 auto_save_interval
= 300;
10072 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
10073 "*Number of seconds idle time before auto-save.\n\
10074 Zero or nil means disable auto-saving due to idleness.\n\
10075 After auto-saving due to this many seconds of idle time,\n\
10076 Emacs also does a garbage collection if that seems to be warranted.");
10077 XSETFASTINT (Vauto_save_timeout
, 30);
10079 DEFVAR_LISP ("echo-keystrokes", &Vecho_keystrokes
,
10080 "*Nonzero means echo unfinished commands after this many seconds of pause.\n\
10081 The value may be integer or floating point.");
10082 Vecho_keystrokes
= make_number (1);
10084 DEFVAR_INT ("polling-period", &polling_period
,
10085 "*Interval between polling for input during Lisp execution.\n\
10086 The reason for polling is to make C-g work to stop a running program.\n\
10087 Polling is needed only when using X windows and SIGIO does not work.\n\
10088 Polling is automatically disabled in all other cases.");
10089 polling_period
= 2;
10091 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
10092 "*Maximum time between mouse clicks to make a double-click.\n\
10093 Measured in milliseconds. nil means disable double-click recognition;\n\
10094 t means double-clicks have no time limit and are detected\n\
10095 by position only.");
10096 Vdouble_click_time
= make_number (500);
10098 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
10099 "*Non-nil means inhibit local map menu bar menus.");
10100 inhibit_local_menu_bar_menus
= 0;
10102 DEFVAR_INT ("num-input-keys", &num_input_keys
,
10103 "Number of complete key sequences read as input so far.\n\
10104 This includes key sequences read from keyboard macros.\n\
10105 The number is effectively the number of interactive command invocations.");
10106 num_input_keys
= 0;
10108 DEFVAR_INT ("num-nonmacro-input-events", &num_nonmacro_input_events
,
10109 "Number of input events read from the keyboard so far.\n\
10110 This does not include events generated by keyboard macros.");
10111 num_nonmacro_input_events
= 0;
10113 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
10114 "The frame in which the most recently read event occurred.\n\
10115 If the last event came from a keyboard macro, this is set to `macro'.");
10116 Vlast_event_frame
= Qnil
;
10118 /* This variable is set up in sysdep.c. */
10119 DEFVAR_LISP ("tty-erase-char", &Vtty_erase_char
,
10120 "The ERASE character as set by the user with stty.");
10122 DEFVAR_LISP ("help-char", &Vhelp_char
,
10123 "Character to recognize as meaning Help.\n\
10124 When it is read, do `(eval help-form)', and display result if it's a string.\n\
10125 If the value of `help-form' is nil, this char can be read normally.");
10126 XSETINT (Vhelp_char
, Ctl ('H'));
10128 DEFVAR_LISP ("help-event-list", &Vhelp_event_list
,
10129 "List of input events to recognize as meaning Help.\n\
10130 These work just like the value of `help-char' (see that).");
10131 Vhelp_event_list
= Qnil
;
10133 DEFVAR_LISP ("help-form", &Vhelp_form
,
10134 "Form to execute when character `help-char' is read.\n\
10135 If the form returns a string, that string is displayed.\n\
10136 If `help-form' is nil, the help char is not recognized.");
10139 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
10140 "Command to run when `help-char' character follows a prefix key.\n\
10141 This command is used only when there is no actual binding\n\
10142 for that character after that prefix key.");
10143 Vprefix_help_command
= Qnil
;
10145 DEFVAR_LISP ("top-level", &Vtop_level
,
10146 "Form to evaluate when Emacs starts up.\n\
10147 Useful to set before you dump a modified Emacs.");
10150 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
10151 "Translate table for keyboard input, or nil.\n\
10152 Each character is looked up in this string and the contents used instead.\n\
10153 The value may be a string, a vector, or a char-table.\n\
10154 If it is a string or vector of length N,\n\
10155 character codes N and up are untranslated.\n\
10156 In a vector or a char-table, an element which is nil means \"no translation\".");
10157 Vkeyboard_translate_table
= Qnil
;
10159 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
10160 "Non-nil means to always spawn a subshell instead of suspending.\n\
10161 \(Even if the operating system has support for stopping a process.\)");
10162 cannot_suspend
= 0;
10164 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
10165 "Non-nil means prompt with menus when appropriate.\n\
10166 This is done when reading from a keymap that has a prompt string,\n\
10167 for elements that have prompt strings.\n\
10168 The menu is displayed on the screen\n\
10169 if X menus were enabled at configuration\n\
10170 time and the previous event was a mouse click prefix key.\n\
10171 Otherwise, menu prompting uses the echo area.");
10172 menu_prompting
= 1;
10174 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
10175 "Character to see next line of menu prompt.\n\
10176 Type this character while in a menu prompt to rotate around the lines of it.");
10177 XSETINT (menu_prompt_more_char
, ' ');
10179 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
10180 "A mask of additional modifier keys to use with every keyboard character.\n\
10181 Emacs applies the modifiers of the character stored here to each keyboard\n\
10182 character it reads. For example, after evaluating the expression\n\
10183 (setq extra-keyboard-modifiers ?\\C-x)\n\
10184 all input characters will have the control modifier applied to them.\n\
10186 Note that the character ?\\C-@, equivalent to the integer zero, does\n\
10187 not count as a control character; rather, it counts as a character\n\
10188 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\
10189 cancels any modification.");
10190 extra_keyboard_modifiers
= 0;
10192 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
10193 "If an editing command sets this to t, deactivate the mark afterward.\n\
10194 The command loop sets this to nil before each command,\n\
10195 and tests the value when the command returns.\n\
10196 Buffer modification stores t in this variable.");
10197 Vdeactivate_mark
= Qnil
;
10199 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
10200 "Temporary storage of pre-command-hook or post-command-hook.");
10201 Vcommand_hook_internal
= Qnil
;
10203 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
10204 "Normal hook run before each command is executed.\n\
10205 If an unhandled error happens in running this hook,\n\
10206 the hook value is set to nil, since otherwise the error\n\
10207 might happen repeatedly and make Emacs nonfunctional.");
10208 Vpre_command_hook
= Qnil
;
10210 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
10211 "Normal hook run after each command is executed.\n\
10212 If an unhandled error happens in running this hook,\n\
10213 the hook value is set to nil, since otherwise the error\n\
10214 might happen repeatedly and make Emacs nonfunctional.");
10215 Vpost_command_hook
= Qnil
;
10217 DEFVAR_LISP ("post-command-idle-hook", &Vpost_command_idle_hook
,
10218 "Normal hook run after each command is executed, if idle.\n\
10219 Errors running the hook are caught and ignored.\n\
10220 This feature is obsolete; use idle timers instead. See `etc/NEWS'.");
10221 Vpost_command_idle_hook
= Qnil
;
10223 DEFVAR_INT ("post-command-idle-delay", &post_command_idle_delay
,
10224 "Delay time before running `post-command-idle-hook'.\n\
10225 This is measured in microseconds.");
10226 post_command_idle_delay
= 100000;
10229 DEFVAR_LISP ("echo-area-clear-hook", ...,
10230 "Normal hook run when clearing the echo area.");
10232 Qecho_area_clear_hook
= intern ("echo-area-clear-hook");
10233 XSYMBOL (Qecho_area_clear_hook
)->value
= Qnil
;
10235 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
10236 "t means menu bar, specified Lucid style, needs to be recomputed.");
10237 Vlucid_menu_bar_dirty_flag
= Qnil
;
10239 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
10240 "List of menu bar items to move to the end of the menu bar.\n\
10241 The elements of the list are event types that may have menu bar bindings.");
10242 Vmenu_bar_final_items
= Qnil
;
10244 DEFVAR_KBOARD ("overriding-terminal-local-map",
10245 Voverriding_terminal_local_map
,
10246 "Per-terminal keymap that overrides all other local keymaps.\n\
10247 If this variable is non-nil, it is used as a keymap instead of the\n\
10248 buffer's local map, and the minor mode keymaps and text property keymaps.\n\
10249 This variable is intended to let commands such as `universal-argumemnt'\n\
10250 set up a different keymap for reading the next command.");
10252 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
10253 "Keymap that overrides all other local keymaps.\n\
10254 If this variable is non-nil, it is used as a keymap instead of the\n\
10255 buffer's local map, and the minor mode keymaps and text property keymaps.");
10256 Voverriding_local_map
= Qnil
;
10258 DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag
,
10259 "Non-nil means `overriding-local-map' applies to the menu bar.\n\
10260 Otherwise, the menu bar continues to reflect the buffer's local map\n\
10261 and the minor mode maps regardless of `overriding-local-map'.");
10262 Voverriding_local_map_menu_flag
= Qnil
;
10264 DEFVAR_LISP ("special-event-map", &Vspecial_event_map
,
10265 "Keymap defining bindings for special events to execute at low level.");
10266 Vspecial_event_map
= Fcons (intern ("keymap"), Qnil
);
10268 DEFVAR_LISP ("track-mouse", &do_mouse_tracking
,
10269 "*Non-nil means generate motion events for mouse motion.");
10271 DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist
,
10272 "Alist of system-specific X windows key symbols.\n\
10273 Each element should have the form (N . SYMBOL) where N is the\n\
10274 numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\
10275 and SYMBOL is its name.");
10277 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
10278 "List of deferred actions to be performed at a later time.\n\
10279 The precise format isn't relevant here; we just check whether it is nil.");
10280 Vdeferred_action_list
= Qnil
;
10282 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
10283 "Function to call to handle deferred actions, after each command.\n\
10284 This function is called with no arguments after each command\n\
10285 whenever `deferred-action-list' is non-nil.");
10286 Vdeferred_action_function
= Qnil
;
10288 DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings
,
10289 "*Non-nil means show the equivalent key-binding when M-x command has one.\n\
10290 The value can be a length of time to show the message for.\n\
10291 If the value is non-nil and not a number, we wait 2 seconds.");
10292 Vsuggest_key_bindings
= Qt
;
10294 DEFVAR_LISP ("timer-list", &Vtimer_list
,
10295 "List of active absolute time timers in order of increasing time");
10296 Vtimer_list
= Qnil
;
10298 DEFVAR_LISP ("timer-idle-list", &Vtimer_idle_list
,
10299 "List of active idle-time timers in order of increasing time");
10300 Vtimer_idle_list
= Qnil
;
10302 DEFVAR_LISP ("input-method-function", &Vinput_method_function
,
10303 "If non-nil, the function that implements the current input method.\n\
10304 It's called with one argument, a printing character that was just read.\n\
10305 \(That means a character with code 040...0176.)\n\
10306 Typically this function uses `read-event' to read additional events.\n\
10307 When it does so, it should first bind `input-method-function' to nil\n\
10308 so it will not be called recursively.\n\
10310 The function should return a list of zero or more events\n\
10311 to be used as input. If it wants to put back some events\n\
10312 to be reconsidered, separately, by the input method,\n\
10313 it can add them to the beginning of `unread-command-events'.\n\
10315 The input method function can find in `input-method-previous-method'\n\
10316 the previous echo area message.\n\
10318 The input method function should refer to the variables\n\
10319 `input-method-use-echo-area' and `input-method-exit-on-first-char'\n\
10320 for guidance on what to do.");
10321 Vinput_method_function
= Qnil
;
10323 DEFVAR_LISP ("input-method-previous-message",
10324 &Vinput_method_previous_message
,
10325 "When `input-method-function' is called, hold the previous echo area message.\n\
10326 This variable exists because `read-event' clears the echo area\n\
10327 before running the input method. It is nil if there was no message.");
10328 Vinput_method_previous_message
= Qnil
;
10330 DEFVAR_LISP ("show-help-function", &Vshow_help_function
,
10331 "If non-nil, the function that implements the display of help.\n\
10332 It's called with one argument, the help string to display.");
10333 Vshow_help_function
= Qnil
;
10335 DEFVAR_LISP ("disable-point-adjustment", &Vdisable_point_adjustment
,
10336 "If non-nil, suppress point adjustment after executing a command.\n\
10338 After a command is executed, if point is moved into a region that has\n\
10339 special properties (e.g. composition, display), we adjust point to\n\
10340 the boundary of the region. But, several special commands sets this\n\
10341 variable to non-nil, then we suppress the point adjustment.\n\
10343 This variable is set to nil before reading a command, and is checked\n\
10344 just after executing the command");
10345 Vdisable_point_adjustment
= Qnil
;
10347 DEFVAR_LISP ("global-disable-point-adjustment",
10348 &Vglobal_disable_point_adjustment
,
10349 "*If non-nil, always suppress point adjustment.\n\
10351 The default value is nil, in which case, point adjustment are\n\
10352 suppressed only after special commands that set\n\
10353 `disable-point-adjustment' (which see) to non-nil.");
10354 Vglobal_disable_point_adjustment
= Qnil
;
10358 keys_of_keyboard ()
10360 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
10361 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
10362 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
10363 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
10364 initial_define_key (meta_map
, 'x', "execute-extended-command");
10366 initial_define_lispy_key (Vspecial_event_map
, "delete-frame",
10367 "handle-delete-frame");
10368 initial_define_lispy_key (Vspecial_event_map
, "iconify-frame",
10370 initial_define_lispy_key (Vspecial_event_map
, "make-frame-visible",