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 currently echoing, or null for none. Set in echo_now to
207 the kboard echoing. Reset to 0 in cancel_echoing. If non-null,
208 and a current echo area message exists, we know that it comes from
211 static struct kboard
*echo_kboard
;
213 /* Nonzero means disregard local maps for the menu bar. */
214 static int inhibit_local_menu_bar_menus
;
216 /* Nonzero means C-g should cause immediate error-signal. */
219 /* The user's ERASE setting. */
220 Lisp_Object Vtty_erase_char
;
222 /* Character to recognize as the help char. */
223 Lisp_Object Vhelp_char
;
225 /* List of other event types to recognize as meaning "help". */
226 Lisp_Object Vhelp_event_list
;
228 /* Form to execute when help char is typed. */
229 Lisp_Object Vhelp_form
;
231 /* Command to run when the help character follows a prefix key. */
232 Lisp_Object Vprefix_help_command
;
234 /* List of items that should move to the end of the menu bar. */
235 Lisp_Object Vmenu_bar_final_items
;
237 /* Non-nil means show the equivalent key-binding for
238 any M-x command that has one.
239 The value can be a length of time to show the message for.
240 If the value is non-nil and not a number, we wait 2 seconds. */
241 Lisp_Object Vsuggest_key_bindings
;
243 /* Character that causes a quit. Normally C-g.
245 If we are running on an ordinary terminal, this must be an ordinary
246 ASCII char, since we want to make it our interrupt character.
248 If we are not running on an ordinary terminal, it still needs to be
249 an ordinary ASCII char. This character needs to be recognized in
250 the input interrupt handler. At this point, the keystroke is
251 represented as a struct input_event, while the desired quit
252 character is specified as a lispy event. The mapping from struct
253 input_events to lispy events cannot run in an interrupt handler,
254 and the reverse mapping is difficult for anything but ASCII
257 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
261 extern Lisp_Object current_global_map
;
262 extern int minibuf_level
;
264 /* If non-nil, this is a map that overrides all other local maps. */
265 Lisp_Object Voverriding_local_map
;
267 /* If non-nil, Voverriding_local_map applies to the menu bar. */
268 Lisp_Object Voverriding_local_map_menu_flag
;
270 /* Keymap that defines special misc events that should
271 be processed immediately at a low level. */
272 Lisp_Object Vspecial_event_map
;
274 /* Current depth in recursive edits. */
275 int command_loop_level
;
277 /* Total number of times command_loop has read a key sequence. */
280 /* Last input character read as a command. */
281 Lisp_Object last_command_char
;
283 /* Last input character read as a command, not counting menus
284 reached by the mouse. */
285 Lisp_Object last_nonmenu_event
;
287 /* Last input character read for any purpose. */
288 Lisp_Object last_input_char
;
290 /* If not Qnil, a list of objects to be read as subsequent command input. */
291 Lisp_Object Vunread_command_events
;
293 /* If not Qnil, a list of objects to be read as subsequent command input
294 including input method processing. */
295 Lisp_Object Vunread_input_method_events
;
297 /* If not Qnil, a list of objects to be read as subsequent command input
298 but NOT including input method processing. */
299 Lisp_Object Vunread_post_input_method_events
;
301 /* If not -1, an event to be read as subsequent command input. */
302 int unread_command_char
;
304 /* If not Qnil, this is a switch-frame event which we decided to put
305 off until the end of a key sequence. This should be read as the
306 next command input, after any unread_command_events.
308 read_key_sequence uses this to delay switch-frame events until the
309 end of the key sequence; Fread_char uses it to put off switch-frame
310 events until a non-ASCII event is acceptable as input. */
311 Lisp_Object unread_switch_frame
;
313 /* A mask of extra modifier bits to put into every keyboard char. */
314 int extra_keyboard_modifiers
;
316 /* Char to use as prefix when a meta character is typed in.
317 This is bound on entry to minibuffer in case ESC is changed there. */
319 Lisp_Object meta_prefix_char
;
321 /* Last size recorded for a current buffer which is not a minibuffer. */
322 static int last_non_minibuf_size
;
324 /* Number of idle seconds before an auto-save and garbage collection. */
325 static Lisp_Object Vauto_save_timeout
;
327 /* Total number of times read_char has returned. */
328 int num_input_events
;
330 /* Total number of times read_char has returned, outside of macros. */
331 int num_nonmacro_input_events
;
333 /* Auto-save automatically when this many characters have been typed
334 since the last time. */
336 static int auto_save_interval
;
338 /* Value of num_nonmacro_input_events as of last auto save. */
342 /* The command being executed by the command loop.
343 Commands may set this, and the value set will be copied into
344 current_kboard->Vlast_command instead of the actual command. */
345 Lisp_Object Vthis_command
;
347 /* This is like Vthis_command, except that commands never set it. */
348 Lisp_Object real_this_command
;
350 /* The value of point when the last command was executed. */
351 int last_point_position
;
353 /* The buffer that was current when the last command was started. */
354 Lisp_Object last_point_position_buffer
;
356 /* The frame in which the last input event occurred, or Qmacro if the
357 last event came from a macro. We use this to determine when to
358 generate switch-frame events. This may be cleared by functions
359 like Fselect_frame, to make sure that a switch-frame event is
360 generated by the next character. */
361 Lisp_Object internal_last_event_frame
;
363 /* A user-visible version of the above, intended to allow users to
364 figure out where the last event came from, if the event doesn't
365 carry that information itself (i.e. if it was a character). */
366 Lisp_Object Vlast_event_frame
;
368 /* The timestamp of the last input event we received from the X server.
369 X Windows wants this for selection ownership. */
370 unsigned long last_event_timestamp
;
372 Lisp_Object Qself_insert_command
;
373 Lisp_Object Qforward_char
;
374 Lisp_Object Qbackward_char
;
375 Lisp_Object Qundefined
;
376 Lisp_Object Qtimer_event_handler
;
378 /* read_key_sequence stores here the command definition of the
379 key sequence that it reads. */
380 Lisp_Object read_key_sequence_cmd
;
382 /* Echo unfinished commands after this many seconds of pause. */
383 Lisp_Object Vecho_keystrokes
;
385 /* Form to evaluate (if non-nil) when Emacs is started. */
386 Lisp_Object Vtop_level
;
388 /* User-supplied string to translate input characters through. */
389 Lisp_Object Vkeyboard_translate_table
;
391 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
392 extern Lisp_Object Vfunction_key_map
;
394 /* Another keymap that maps key sequences into key sequences.
395 This one takes precedence over ordinary definitions. */
396 extern Lisp_Object Vkey_translation_map
;
398 /* If non-nil, this implements the current input method. */
399 Lisp_Object Vinput_method_function
;
400 Lisp_Object Qinput_method_function
;
402 /* When we call Vinput_method_function,
403 this holds the echo area message that was just erased. */
404 Lisp_Object Vinput_method_previous_message
;
406 /* Non-nil means deactivate the mark at end of this command. */
407 Lisp_Object Vdeactivate_mark
;
409 /* Menu bar specified in Lucid Emacs fashion. */
411 Lisp_Object Vlucid_menu_bar_dirty_flag
;
412 Lisp_Object Qrecompute_lucid_menubar
, Qactivate_menubar_hook
;
414 Lisp_Object Qecho_area_clear_hook
;
416 /* Hooks to run before and after each command. */
417 Lisp_Object Qpre_command_hook
, Vpre_command_hook
;
418 Lisp_Object Qpost_command_hook
, Vpost_command_hook
;
419 Lisp_Object Qcommand_hook_internal
, Vcommand_hook_internal
;
420 /* Hook run after a command if there's no more input soon. */
421 Lisp_Object Qpost_command_idle_hook
, Vpost_command_idle_hook
;
423 /* Delay time in microseconds before running post-command-idle-hook. */
424 int post_command_idle_delay
;
426 /* List of deferred actions to be performed at a later time.
427 The precise format isn't relevant here; we just check whether it is nil. */
428 Lisp_Object Vdeferred_action_list
;
430 /* Function to call to handle deferred actions, when there are any. */
431 Lisp_Object Vdeferred_action_function
;
432 Lisp_Object Qdeferred_action_function
;
434 Lisp_Object Qinput_method_exit_on_first_char
;
435 Lisp_Object Qinput_method_use_echo_area
;
437 /* File in which we write all commands we read. */
440 /* Nonzero if input is available. */
443 /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
444 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
448 extern char *pending_malloc_warning
;
450 /* Circular buffer for pre-read keyboard input. */
451 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
453 /* Vector to GCPRO the frames and windows mentioned in kbd_buffer.
455 The interrupt-level event handlers will never enqueue an event on a
456 frame which is not in Vframe_list, and once an event is dequeued,
457 internal_last_event_frame or the event itself points to the frame.
460 But while the event is sitting in the queue, it's completely
461 unprotected. Suppose the user types one command which will run for
462 a while and then delete a frame, and then types another event at
463 the frame that will be deleted, before the command gets around to
464 it. Suppose there are no references to this frame elsewhere in
465 Emacs, and a GC occurs before the second event is dequeued. Now we
466 have an event referring to a freed frame, which will crash Emacs
469 Similar things happen when an event on a scroll bar is enqueued; the
470 window may be deleted while the event is in the queue.
472 So, we use this vector to protect the frame_or_window field in the
473 event queue. That way, they'll be dequeued as dead frames or
474 windows, but still valid lisp objects.
476 If kbd_buffer[i].kind != no_event, then
477 (XVECTOR (kbd_buffer_frame_or_window)->contents[i]
478 == kbd_buffer[i].frame_or_window. */
479 static Lisp_Object kbd_buffer_frame_or_window
;
481 /* Pointer to next available character in kbd_buffer.
482 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
483 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the
484 next available char is in kbd_buffer[0]. */
485 static struct input_event
*kbd_fetch_ptr
;
487 /* Pointer to next place to store character in kbd_buffer. This
488 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
489 character should go in kbd_buffer[0]. */
490 static struct input_event
* volatile kbd_store_ptr
;
492 /* The above pair of variables forms a "queue empty" flag. When we
493 enqueue a non-hook event, we increment kbd_store_ptr. When we
494 dequeue a non-hook event, we increment kbd_fetch_ptr. We say that
495 there is input available iff the two pointers are not equal.
497 Why not just have a flag set and cleared by the enqueuing and
498 dequeuing functions? Such a flag could be screwed up by interrupts
499 at inopportune times. */
501 /* If this flag is non-nil, we check mouse_moved to see when the
502 mouse moves, and motion events will appear in the input stream.
503 Otherwise, mouse motion is ignored. */
504 static Lisp_Object do_mouse_tracking
;
506 /* Symbols to head events. */
507 Lisp_Object Qmouse_movement
;
508 Lisp_Object Qscroll_bar_movement
;
509 Lisp_Object Qswitch_frame
;
510 Lisp_Object Qdelete_frame
;
511 Lisp_Object Qiconify_frame
;
512 Lisp_Object Qmake_frame_visible
;
513 Lisp_Object Qhelp_echo
;
515 /* Symbols to denote kinds of events. */
516 Lisp_Object Qfunction_key
;
517 Lisp_Object Qmouse_click
;
519 Lisp_Object Qmouse_wheel
;
520 Lisp_Object Qlanguage_change
;
522 Lisp_Object Qdrag_n_drop
;
523 /* Lisp_Object Qmouse_movement; - also an event header */
525 /* Properties of event headers. */
526 Lisp_Object Qevent_kind
;
527 Lisp_Object Qevent_symbol_elements
;
529 /* menu item parts */
530 Lisp_Object Qmenu_alias
;
531 Lisp_Object Qmenu_enable
;
532 Lisp_Object QCenable
, QCvisible
, QChelp
, QCfilter
, QCkeys
, QCkey_sequence
;
533 Lisp_Object QCbutton
, QCtoggle
, QCradio
;
534 extern Lisp_Object Vdefine_key_rebound_commands
;
535 extern Lisp_Object Qmenu_item
;
537 /* An event header symbol HEAD may have a property named
538 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
539 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
540 mask of modifiers applied to it. If present, this is used to help
541 speed up parse_modifiers. */
542 Lisp_Object Qevent_symbol_element_mask
;
544 /* An unmodified event header BASE may have a property named
545 Qmodifier_cache, which is an alist mapping modifier masks onto
546 modified versions of BASE. If present, this helps speed up
548 Lisp_Object Qmodifier_cache
;
550 /* Symbols to use for parts of windows. */
551 Lisp_Object Qmode_line
;
552 Lisp_Object Qvertical_line
;
553 Lisp_Object Qvertical_scroll_bar
;
554 Lisp_Object Qmenu_bar
;
556 Lisp_Object
recursive_edit_unwind (), command_loop ();
557 Lisp_Object
Fthis_command_keys ();
558 Lisp_Object Qextended_command_history
;
559 EMACS_TIME
timer_check ();
561 extern Lisp_Object Vhistory_length
;
563 extern char *x_get_keysym_name ();
565 static void record_menu_key ();
567 Lisp_Object Qpolling_period
;
569 /* List of absolute timers. Appears in order of next scheduled event. */
570 Lisp_Object Vtimer_list
;
572 /* List of idle time timers. Appears in order of next scheduled event. */
573 Lisp_Object Vtimer_idle_list
;
575 /* Incremented whenever a timer is run. */
578 extern Lisp_Object Vprint_level
, Vprint_length
;
580 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
582 EMACS_TIME
*input_available_clear_time
;
584 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
585 Default is 1 if INTERRUPT_INPUT is defined. */
588 /* Nonzero while interrupts are temporarily deferred during redisplay. */
589 int interrupts_deferred
;
591 /* Nonzero means use ^S/^Q for flow control. */
594 /* Allow m- file to inhibit use of FIONREAD. */
595 #ifdef BROKEN_FIONREAD
599 /* We are unable to use interrupts if FIONREAD is not available,
600 so flush SIGIO so we won't try. */
607 /* If we support a window system, turn on the code to poll periodically
608 to detect C-g. It isn't actually used when doing interrupt input. */
609 #ifdef HAVE_WINDOW_SYSTEM
610 #define POLL_FOR_INPUT
613 /* After a command is executed, if point is moved into a region that
614 has specific properties (e.g. composition, display), we adjust
615 point to the boundary of the region. But, if a command sets this
616 valiable to non-nil, we suppress this point adjustment. This
617 variable is set to nil before reading a command. */
618 Lisp_Object Vdisable_point_adjustment
;
620 /* If non-nil, always disable point adjustment. */
621 Lisp_Object Vglobal_disable_point_adjustment
;
624 /* Global variable declarations. */
626 /* Function for init_keyboard to call with no args (if nonzero). */
627 void (*keyboard_init_hook
) ();
629 static int read_avail_input ();
630 static void get_input_pending ();
631 static int readable_events ();
632 static Lisp_Object
read_char_x_menu_prompt ();
633 static Lisp_Object
read_char_minibuf_menu_prompt ();
634 static Lisp_Object
make_lispy_event ();
636 static Lisp_Object
make_lispy_movement ();
638 static Lisp_Object
modify_event_symbol ();
639 static Lisp_Object
make_lispy_switch_frame ();
640 static int parse_solitary_modifier ();
641 static void save_getcjmp ();
642 static void restore_getcjmp ();
643 static Lisp_Object apply_modifiers
P_ ((int, Lisp_Object
));
645 /* Nonzero means don't try to suspend even if the operating system seems
647 static int cannot_suspend
;
649 #define min(a,b) ((a)<(b)?(a):(b))
650 #define max(a,b) ((a)>(b)?(a):(b))
652 /* Install the string STR as the beginning of the string of echoing,
653 so that it serves as a prompt for the next character.
654 Also start echoing. */
660 int len
= strlen (str
);
662 if (len
> ECHOBUFSIZE
- 4)
663 len
= ECHOBUFSIZE
- 4;
664 bcopy (str
, current_kboard
->echobuf
, len
);
665 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
666 *current_kboard
->echoptr
= '\0';
668 current_kboard
->echo_after_prompt
= len
;
673 /* Add C to the echo string, if echoing is going on.
674 C can be a character, which is printed prettily ("M-C-x" and all that
675 jazz), or a symbol, whose name is printed. */
681 extern char *push_key_description ();
683 if (current_kboard
->immediate_echo
)
685 char *ptr
= current_kboard
->echoptr
;
687 if (ptr
!= current_kboard
->echobuf
)
690 /* If someone has passed us a composite event, use its head symbol. */
695 if (ptr
- current_kboard
->echobuf
696 > ECHOBUFSIZE
- KEY_DESCRIPTION_SIZE
)
699 ptr
= push_key_description (XINT (c
), ptr
);
701 else if (SYMBOLP (c
))
703 struct Lisp_String
*name
= XSYMBOL (c
)->name
;
704 if ((ptr
- current_kboard
->echobuf
) + STRING_BYTES (name
) + 4
707 bcopy (name
->data
, ptr
, STRING_BYTES (name
));
708 ptr
+= STRING_BYTES (name
);
711 if (current_kboard
->echoptr
== current_kboard
->echobuf
714 strcpy (ptr
, " (Type ? for further options)");
719 current_kboard
->echoptr
= ptr
;
725 /* Temporarily add a dash to the end of the echo string if it's not
726 empty, so that it serves as a mini-prompt for the very next character. */
731 if (!current_kboard
->immediate_echo
732 && current_kboard
->echoptr
== current_kboard
->echobuf
)
734 /* Do nothing if we just printed a prompt. */
735 if (current_kboard
->echo_after_prompt
736 == current_kboard
->echoptr
- current_kboard
->echobuf
)
738 /* Do nothing if not echoing at all. */
739 if (current_kboard
->echoptr
== 0)
742 /* Put a dash at the end of the buffer temporarily,
743 but make it go away when the next character is added. */
744 current_kboard
->echoptr
[0] = '-';
745 current_kboard
->echoptr
[1] = 0;
750 /* Display the current echo string, and begin echoing if not already
756 if (!current_kboard
->immediate_echo
)
759 current_kboard
->immediate_echo
= 1;
761 for (i
= 0; i
< this_command_key_count
; i
++)
764 c
= XVECTOR (this_command_keys
)->contents
[i
];
765 if (! (EVENT_HAS_PARAMETERS (c
)
766 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
773 echo_kboard
= current_kboard
;
774 message2_nolog (current_kboard
->echobuf
, strlen (current_kboard
->echobuf
),
775 ! NILP (current_buffer
->enable_multibyte_characters
));
778 if (waiting_for_input
&& !NILP (Vquit_flag
))
779 quit_throw_to_read_char ();
782 /* Turn off echoing, for the start of a new command. */
787 current_kboard
->immediate_echo
= 0;
788 current_kboard
->echoptr
= current_kboard
->echobuf
;
789 current_kboard
->echo_after_prompt
= -1;
790 ok_to_echo_at_next_pause
= 0;
794 /* Return the length of the current echo string. */
799 return current_kboard
->echoptr
- current_kboard
->echobuf
;
802 /* Truncate the current echo message to its first LEN chars.
803 This and echo_char get used by read_key_sequence when the user
804 switches frames while entering a key sequence. */
810 current_kboard
->echobuf
[len
] = '\0';
811 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
812 truncate_echo_area (len
);
816 /* Functions for manipulating this_command_keys. */
818 add_command_key (key
)
821 int size
= XVECTOR (this_command_keys
)->size
;
823 /* If reset-this-command-length was called recently, obey it now.
824 See the doc string of that function for an explanation of why. */
825 if (before_command_restore_flag
)
827 this_command_key_count
= before_command_key_count_1
;
828 if (this_command_key_count
< this_single_command_key_start
)
829 this_single_command_key_start
= this_command_key_count
;
830 echo_truncate (before_command_echo_length_1
);
831 before_command_restore_flag
= 0;
834 if (this_command_key_count
>= size
)
836 Lisp_Object new_keys
;
838 new_keys
= Fmake_vector (make_number (size
* 2), Qnil
);
839 bcopy (XVECTOR (this_command_keys
)->contents
,
840 XVECTOR (new_keys
)->contents
,
841 size
* sizeof (Lisp_Object
));
843 this_command_keys
= new_keys
;
846 XVECTOR (this_command_keys
)->contents
[this_command_key_count
++] = key
;
852 int count
= specpdl_ptr
- specpdl
;
855 if (command_loop_level
> 0)
857 specbind (Qstandard_output
, Qt
);
858 specbind (Qstandard_input
, Qt
);
861 #ifdef HAVE_X_WINDOWS
862 /* The command loop has started a busy-cursor timer, so we have to
863 cancel it here, otherwise it will fire because the recursive edit
864 can take some time. */
865 if (display_busy_cursor_p
)
866 cancel_busy_cursor ();
869 val
= command_loop ();
871 Fsignal (Qquit
, Qnil
);
872 /* Handle throw from read_minibuf when using minibuffer
873 while it's active but we're in another window. */
875 Fsignal (Qerror
, Fcons (val
, Qnil
));
877 return unbind_to (count
, Qnil
);
880 /* When an auto-save happens, record the "time", and don't do again soon. */
885 last_auto_save
= num_nonmacro_input_events
;
888 /* Make an auto save happen as soon as possible at command level. */
891 force_auto_save_soon ()
893 last_auto_save
= - auto_save_interval
- 1;
895 record_asynch_buffer_change ();
898 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
899 "Invoke the editor command loop recursively.\n\
900 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
901 that tells this function to return.\n\
902 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
903 This function is called by the editor initialization to begin editing.")
906 int count
= specpdl_ptr
- specpdl
;
908 command_loop_level
++;
909 update_mode_lines
= 1;
911 record_unwind_protect (recursive_edit_unwind
,
913 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
917 return unbind_to (count
, Qnil
);
921 recursive_edit_unwind (buffer
)
925 Fset_buffer (buffer
);
927 command_loop_level
--;
928 update_mode_lines
= 1;
936 #if 0 /* Theory: if there's anything in Vunread_command_events,
937 it will right away be read by read_key_sequence,
938 and then if we do switch KBOARDS, it will go into the side
939 queue then. So we don't need to do anything special here -- rms. */
940 if (CONSP (Vunread_command_events
))
942 current_kboard
->kbd_queue
943 = nconc2 (Vunread_command_events
, current_kboard
->kbd_queue
);
944 current_kboard
->kbd_queue_has_data
= 1;
946 Vunread_command_events
= Qnil
;
952 /* Switch to the single-kboard state, making current_kboard
953 the only KBOARD from which further input is accepted. */
956 single_kboard_state ()
963 /* Maintain a stack of kboards, so other parts of Emacs
964 can switch temporarily to the kboard of a given frame
965 and then revert to the previous status. */
970 struct kboard_stack
*next
;
973 static struct kboard_stack
*kboard_stack
;
976 push_frame_kboard (f
)
980 struct kboard_stack
*p
981 = (struct kboard_stack
*) xmalloc (sizeof (struct kboard_stack
));
983 p
->next
= kboard_stack
;
984 p
->kboard
= current_kboard
;
987 current_kboard
= FRAME_KBOARD (f
);
995 struct kboard_stack
*p
= kboard_stack
;
996 current_kboard
= p
->kboard
;
997 kboard_stack
= p
->next
;
1002 /* Handle errors that are not handled at inner levels
1003 by printing an error message and returning to the editor command loop. */
1009 Lisp_Object old_level
, old_length
;
1010 char macroerror
[50];
1012 if (!NILP (executing_macro
))
1014 if (executing_macro_iterations
== 1)
1015 sprintf (macroerror
, "After 1 kbd macro iteration: ");
1017 sprintf (macroerror
, "After %d kbd macro iterations: ",
1018 executing_macro_iterations
);
1023 Vstandard_output
= Qt
;
1024 Vstandard_input
= Qt
;
1025 Vexecuting_macro
= Qnil
;
1026 executing_macro
= Qnil
;
1027 current_kboard
->Vprefix_arg
= Qnil
;
1028 current_kboard
->Vlast_prefix_arg
= Qnil
;
1031 /* Avoid unquittable loop if data contains a circular list. */
1032 old_level
= Vprint_level
;
1033 old_length
= Vprint_length
;
1034 XSETFASTINT (Vprint_level
, 10);
1035 XSETFASTINT (Vprint_length
, 10);
1036 cmd_error_internal (data
, macroerror
);
1037 Vprint_level
= old_level
;
1038 Vprint_length
= old_length
;
1042 Vinhibit_quit
= Qnil
;
1044 any_kboard_state ();
1047 return make_number (0);
1050 /* Take actions on handling an error. DATA is the data that describes
1053 CONTEXT is a C-string containing ASCII characters only which
1054 describes the context in which the error happened. If we need to
1055 generalize CONTEXT to allow multibyte characters, make it a Lisp
1059 cmd_error_internal (data
, context
)
1064 int kill_emacs_p
= 0;
1065 struct frame
*sf
= SELECTED_FRAME ();
1069 clear_message (1, 0);
1071 /* If the window system or terminal frame hasn't been initialized
1072 yet, or we're not interactive, it's best to dump this message out
1073 to stderr and exit. */
1074 if (!sf
->glyphs_initialized_p
1075 /* This is the case of the frame dumped with Emacs, when we're
1076 running under a window system. */
1077 || (!NILP (Vwindow_system
)
1078 && !inhibit_window_system
1079 && FRAME_TERMCAP_P (sf
))
1082 stream
= Qexternal_debugging_output
;
1093 write_string_1 (context
, -1, stream
);
1095 print_error_message (data
, stream
);
1097 /* If the window system or terminal frame hasn't been initialized
1098 yet, or we're in -batch mode, this error should cause Emacs to exit. */
1102 Fkill_emacs (make_number (-1));
1106 Lisp_Object
command_loop_1 ();
1107 Lisp_Object
command_loop_2 ();
1108 Lisp_Object
top_level_1 ();
1110 /* Entry to editor-command-loop.
1111 This level has the catches for exiting/returning to editor command loop.
1112 It returns nil to exit recursive edit, t to abort it. */
1117 if (command_loop_level
> 0 || minibuf_level
> 0)
1120 val
= internal_catch (Qexit
, command_loop_2
, Qnil
);
1121 executing_macro
= Qnil
;
1127 internal_catch (Qtop_level
, top_level_1
, Qnil
);
1128 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
1129 executing_macro
= Qnil
;
1131 /* End of file in -batch run causes exit here. */
1137 /* Here we catch errors in execution of commands within the
1138 editing loop, and reenter the editing loop.
1139 When there is an error, cmd_error runs and returns a non-nil
1140 value to us. A value of nil means that cmd_loop_1 itself
1141 returned due to end of file (or end of kbd macro). */
1146 register Lisp_Object val
;
1149 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
1150 while (!NILP (val
));
1158 return Feval (Vtop_level
);
1164 /* On entry to the outer level, run the startup file */
1165 if (!NILP (Vtop_level
))
1166 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
1167 else if (!NILP (Vpurify_flag
))
1168 message ("Bare impure Emacs (standard Lisp code not loaded)");
1170 message ("Bare Emacs (standard Lisp code not loaded)");
1174 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
1175 "Exit all recursive editing levels.")
1178 Fthrow (Qtop_level
, Qnil
);
1181 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
1182 "Exit from the innermost recursive edit or minibuffer.")
1185 if (command_loop_level
> 0 || minibuf_level
> 0)
1186 Fthrow (Qexit
, Qnil
);
1188 error ("No recursive edit is in progress");
1191 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
1192 "Abort the command that requested this recursive edit or minibuffer input.")
1195 if (command_loop_level
> 0 || minibuf_level
> 0)
1198 error ("No recursive edit is in progress");
1201 /* This is the actual command reading loop,
1202 sans error-handling encapsulation. */
1204 Lisp_Object
Fcommand_execute ();
1205 static int read_key_sequence ();
1206 void safe_run_hooks ();
1207 static void adjust_point_for_property ();
1215 Lisp_Object keybuf
[30];
1219 struct buffer
*prev_buffer
;
1221 int was_locked
= single_kboard
;
1224 current_kboard
->Vprefix_arg
= Qnil
;
1225 current_kboard
->Vlast_prefix_arg
= Qnil
;
1226 Vdeactivate_mark
= Qnil
;
1227 waiting_for_input
= 0;
1231 this_command_key_count
= 0;
1232 this_single_command_key_start
= 0;
1234 /* Make sure this hook runs after commands that get errors and
1235 throw to top level. */
1236 /* Note that the value cell will never directly contain nil
1237 if the symbol is a local variable. */
1238 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1239 safe_run_hooks (Qpost_command_hook
);
1241 /* If displaying a message, resize the echo area window to fit
1242 that message's size exactly. */
1243 if (!NILP (echo_area_buffer
[0]))
1244 resize_echo_area_axactly ();
1246 if (!NILP (Vdeferred_action_list
))
1247 call0 (Vdeferred_action_function
);
1249 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1251 if (NILP (Vunread_command_events
)
1252 && NILP (Vunread_input_method_events
)
1253 && NILP (Vunread_post_input_method_events
)
1254 && NILP (Vexecuting_macro
)
1255 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1, 1)))
1256 safe_run_hooks (Qpost_command_idle_hook
);
1259 /* Do this after running Vpost_command_hook, for consistency. */
1260 current_kboard
->Vlast_command
= Vthis_command
;
1261 current_kboard
->Vreal_last_command
= real_this_command
;
1265 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
1268 /* Make sure the current window's buffer is selected. */
1269 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1270 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1272 /* Display any malloc warning that just came out. Use while because
1273 displaying one warning can cause another. */
1275 while (pending_malloc_warning
)
1276 display_malloc_warning ();
1280 Vdeactivate_mark
= Qnil
;
1282 /* If minibuffer on and echo area in use,
1283 wait 2 sec and redraw minibuffer. */
1286 && !NILP (echo_area_buffer
[0])
1287 && EQ (minibuf_window
, echo_area_window
))
1289 /* Bind inhibit-quit to t so that C-g gets read in
1290 rather than quitting back to the minibuffer. */
1291 int count
= specpdl_ptr
- specpdl
;
1292 specbind (Qinhibit_quit
, Qt
);
1294 Fsit_for (make_number (2), Qnil
, Qnil
);
1295 /* Clear the echo area. */
1297 safe_run_hooks (Qecho_area_clear_hook
);
1299 unbind_to (count
, Qnil
);
1301 /* If a C-g came in before, treat it as input now. */
1302 if (!NILP (Vquit_flag
))
1305 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1310 alloca (0); /* Cause a garbage collection now */
1311 /* Since we can free the most stuff here. */
1312 #endif /* C_ALLOCA */
1315 /* Select the frame that the last event came from. Usually,
1316 switch-frame events will take care of this, but if some lisp
1317 code swallows a switch-frame event, we'll fix things up here.
1318 Is this a good idea? */
1319 if (FRAMEP (internal_last_event_frame
)
1320 && !EQ (internal_last_event_frame
, selected_frame
))
1321 Fselect_frame (internal_last_event_frame
, Qnil
);
1323 /* If it has changed current-menubar from previous value,
1324 really recompute the menubar from the value. */
1325 if (! NILP (Vlucid_menu_bar_dirty_flag
)
1326 && !NILP (Ffboundp (Qrecompute_lucid_menubar
)))
1327 call0 (Qrecompute_lucid_menubar
);
1329 before_command_key_count
= this_command_key_count
;
1330 before_command_echo_length
= echo_length ();
1332 Vthis_command
= Qnil
;
1333 real_this_command
= Qnil
;
1335 /* Read next key sequence; i gets its length. */
1336 i
= read_key_sequence (keybuf
, sizeof keybuf
/ sizeof keybuf
[0],
1339 /* A filter may have run while we were reading the input. */
1340 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
1342 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1343 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1347 /* Now we have read a key sequence of length I,
1348 or else I is 0 and we found end of file. */
1350 if (i
== 0) /* End of file -- happens only in */
1351 return Qnil
; /* a kbd macro, at the end. */
1352 /* -1 means read_key_sequence got a menu that was rejected.
1353 Just loop around and read another command. */
1357 this_command_key_count
= 0;
1358 this_single_command_key_start
= 0;
1362 last_command_char
= keybuf
[i
- 1];
1364 /* If the previous command tried to force a specific window-start,
1365 forget about that, in case this command moves point far away
1366 from that position. But also throw away beg_unchanged and
1367 end_unchanged information in that case, so that redisplay will
1368 update the whole window properly. */
1369 if (!NILP (XWINDOW (selected_window
)->force_start
))
1372 XWINDOW (selected_window
)->force_start
= Qnil
;
1373 b
= XBUFFER (XWINDOW (selected_window
)->buffer
);
1374 BUF_BEG_UNCHANGED (b
) = BUF_END_UNCHANGED (b
) = 0;
1377 cmd
= read_key_sequence_cmd
;
1378 if (!NILP (Vexecuting_macro
))
1380 if (!NILP (Vquit_flag
))
1382 Vexecuting_macro
= Qt
;
1383 QUIT
; /* Make some noise. */
1384 /* Will return since macro now empty. */
1388 /* Do redisplay processing after this command except in special
1389 cases identified below. */
1390 prev_buffer
= current_buffer
;
1391 prev_modiff
= MODIFF
;
1392 last_point_position
= PT
;
1393 XSETBUFFER (last_point_position_buffer
, prev_buffer
);
1395 /* By default, we adjust point to a boundary of a region that
1396 has such a property that should be treated intangible
1397 (e.g. composition, display). But, some commands will set
1398 this variable differently. */
1399 Vdisable_point_adjustment
= Qnil
;
1401 /* Execute the command. */
1403 Vthis_command
= cmd
;
1404 real_this_command
= cmd
;
1405 /* Note that the value cell will never directly contain nil
1406 if the symbol is a local variable. */
1407 if (!NILP (Vpre_command_hook
) && !NILP (Vrun_hooks
))
1408 safe_run_hooks (Qpre_command_hook
);
1410 if (NILP (Vthis_command
))
1412 /* nil means key is undefined. */
1414 current_kboard
->defining_kbd_macro
= Qnil
;
1415 update_mode_lines
= 1;
1416 current_kboard
->Vprefix_arg
= Qnil
;
1420 if (NILP (current_kboard
->Vprefix_arg
) && ! no_direct
)
1422 /* In case we jump to directly_done. */
1423 Vcurrent_prefix_arg
= current_kboard
->Vprefix_arg
;
1425 /* Recognize some common commands in common situations and
1426 do them directly. */
1427 if (EQ (Vthis_command
, Qforward_char
) && PT
< ZV
)
1429 struct Lisp_Char_Table
*dp
1430 = window_display_table (XWINDOW (selected_window
));
1431 lose
= FETCH_CHAR (PT_BYTE
);
1434 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1435 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1436 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1437 && (lose
>= 0x20 && lose
< 0x7f)))
1438 : (lose
>= 0x20 && lose
< 0x7f))
1439 /* To extract the case of continuation on
1440 wide-column characters. */
1441 && (WIDTH_BY_CHAR_HEAD (FETCH_BYTE (PT_BYTE
)) == 1)
1442 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1444 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1446 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1448 && !windows_or_buffers_changed
1449 && EQ (current_buffer
->selective_display
, Qnil
)
1450 && !detect_input_pending ()
1451 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1452 && NILP (Vexecuting_macro
))
1453 direct_output_forward_char (1);
1456 else if (EQ (Vthis_command
, Qbackward_char
) && PT
> BEGV
)
1458 struct Lisp_Char_Table
*dp
1459 = window_display_table (XWINDOW (selected_window
));
1461 lose
= FETCH_CHAR (PT_BYTE
);
1463 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1464 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1465 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1466 && (lose
>= 0x20 && lose
< 0x7f)))
1467 : (lose
>= 0x20 && lose
< 0x7f))
1468 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1470 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1472 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1474 && !windows_or_buffers_changed
1475 && EQ (current_buffer
->selective_display
, Qnil
)
1476 && !detect_input_pending ()
1477 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1478 && NILP (Vexecuting_macro
))
1479 direct_output_forward_char (-1);
1482 else if (EQ (Vthis_command
, Qself_insert_command
)
1483 /* Try this optimization only on ascii keystrokes. */
1484 && INTEGERP (last_command_char
))
1486 unsigned int c
= XINT (last_command_char
);
1488 if (NILP (Vexecuting_macro
)
1489 && !EQ (minibuf_window
, selected_window
))
1491 if (!nonundocount
|| nonundocount
>= 20)
1499 lose
= ((XFASTINT (XWINDOW (selected_window
)->last_modified
)
1501 || (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1503 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1505 || MODIFF
<= SAVE_MODIFF
1506 || windows_or_buffers_changed
1507 || !EQ (current_buffer
->selective_display
, Qnil
)
1508 || detect_input_pending ()
1509 || !NILP (XWINDOW (selected_window
)->column_number_displayed
)
1510 || !NILP (Vexecuting_macro
));
1512 value
= internal_self_insert (c
, 0);
1517 /* VALUE == 1 when AFTER-CHANGE functions are
1518 installed which is the case most of the time
1519 because FONT-LOCK installs one. */
1520 if (!lose
&& !value
)
1521 direct_output_for_insert (c
);
1526 /* Here for a command that isn't executed directly */
1528 #ifdef HAVE_X_WINDOWS
1529 if (display_busy_cursor_p
)
1530 start_busy_cursor ();
1534 if (NILP (current_kboard
->Vprefix_arg
))
1536 Fcommand_execute (Vthis_command
, Qnil
, Qnil
, Qnil
);
1538 #ifdef HAVE_X_WINDOWS
1539 if (display_busy_cursor_p
)
1540 cancel_busy_cursor ();
1544 current_kboard
->Vlast_prefix_arg
= Vcurrent_prefix_arg
;
1546 /* Note that the value cell will never directly contain nil
1547 if the symbol is a local variable. */
1548 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1549 safe_run_hooks (Qpost_command_hook
);
1551 /* If displaying a message, resize the echo area window to fit
1552 that message's size exactly. */
1553 if (!NILP (echo_area_buffer
[0]))
1554 resize_echo_area_axactly ();
1556 if (!NILP (Vdeferred_action_list
))
1557 safe_run_hooks (Qdeferred_action_function
);
1559 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1561 if (NILP (Vunread_command_events
)
1562 && NILP (Vunread_input_method_events
)
1563 && NILP (Vunread_post_input_method_events
)
1564 && NILP (Vexecuting_macro
)
1565 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1, 1)))
1566 safe_run_hooks (Qpost_command_idle_hook
);
1569 /* If there is a prefix argument,
1570 1) We don't want Vlast_command to be ``universal-argument''
1571 (that would be dumb), so don't set Vlast_command,
1572 2) we want to leave echoing on so that the prefix will be
1573 echoed as part of this key sequence, so don't call
1575 3) we want to leave this_command_key_count non-zero, so that
1576 read_char will realize that it is re-reading a character, and
1577 not echo it a second time.
1579 If the command didn't actually create a prefix arg,
1580 but is merely a frame event that is transparent to prefix args,
1581 then the above doesn't apply. */
1582 if (NILP (current_kboard
->Vprefix_arg
) || CONSP (last_command_char
))
1584 current_kboard
->Vlast_command
= Vthis_command
;
1585 current_kboard
->Vreal_last_command
= real_this_command
;
1587 this_command_key_count
= 0;
1588 this_single_command_key_start
= 0;
1591 if (!NILP (current_buffer
->mark_active
) && !NILP (Vrun_hooks
))
1593 if (!NILP (Vdeactivate_mark
) && !NILP (Vtransient_mark_mode
))
1595 current_buffer
->mark_active
= Qnil
;
1596 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
1598 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
1599 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
1604 if (current_buffer
== prev_buffer
1605 && last_point_position
!= PT
1606 && NILP (Vdisable_point_adjustment
)
1607 && NILP (Vglobal_disable_point_adjustment
))
1608 adjust_point_for_property (last_point_position
);
1610 /* Install chars successfully executed in kbd macro. */
1612 if (!NILP (current_kboard
->defining_kbd_macro
)
1613 && NILP (current_kboard
->Vprefix_arg
))
1614 finalize_kbd_macro_chars ();
1618 any_kboard_state ();
1623 extern Lisp_Object Qcomposition
, Qdisplay
;
1625 /* Adjust point to a boundary of a region that has such a property
1626 that should be treated intangible. For the moment, we check
1627 `composition' and `display' property. LAST_PT is the last position
1631 adjust_point_for_property (last_pt
)
1636 int check_composition
= 1, check_display
= 1;
1638 while (check_composition
|| check_display
)
1640 if (check_composition
1641 && PT
> BEGV
&& PT
< ZV
1642 && get_property_and_range (PT
, Qcomposition
, &val
, &start
, &end
, Qnil
)
1643 && COMPOSITION_VALID_P (start
, end
, val
)
1644 && start
< PT
&& end
> PT
1645 && (last_pt
<= start
|| last_pt
>= end
))
1653 check_composition
= 0;
1655 && PT
> BEGV
&& PT
< ZV
1656 && get_property_and_range (PT
, Qdisplay
, &val
, &start
, &end
, Qnil
)
1657 && start
< PT
&& end
> PT
1658 && (last_pt
<= start
|| last_pt
>= end
))
1664 check_composition
= 1;
1670 /* Subroutine for safe_run_hooks: run the hook HOOK. */
1673 safe_run_hooks_1 (hook
)
1676 return call1 (Vrun_hooks
, Vinhibit_quit
);
1679 /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */
1682 safe_run_hooks_error (data
)
1685 Fset (Vinhibit_quit
, Qnil
);
1688 /* If we get an error while running the hook, cause the hook variable
1689 to be nil. Also inhibit quits, so that C-g won't cause the hook
1690 to mysteriously evaporate. */
1693 safe_run_hooks (hook
)
1696 int count
= specpdl_ptr
- specpdl
;
1697 specbind (Qinhibit_quit
, hook
);
1699 internal_condition_case (safe_run_hooks_1
, Qt
, safe_run_hooks_error
);
1701 unbind_to (count
, Qnil
);
1705 /* Number of seconds between polling for input. This is a Lisp
1706 variable that can be bound. */
1710 /* Nonzero means polling for input is temporarily suppressed. */
1712 int poll_suppress_count
;
1714 /* Asynchronous timer for polling. */
1716 struct atimer
*poll_timer
;
1719 #ifdef POLL_FOR_INPUT
1721 /* Poll for input, so what we catch a C-g if it comes in. This
1722 function is called from x_make_frame_visible, see comment
1728 if (interrupt_input_blocked
== 0
1729 && !waiting_for_input
)
1730 read_avail_input (0);
1733 /* Timer callback function for poll_timer. TIMER is equal to
1737 poll_for_input (timer
)
1738 struct atimer
*timer
;
1740 if (poll_suppress_count
== 0)
1741 poll_for_input_1 ();
1744 #endif /* POLL_FOR_INPUT */
1746 /* Begin signals to poll for input, if they are appropriate.
1747 This function is called unconditionally from various places. */
1752 #ifdef POLL_FOR_INPUT
1753 if (read_socket_hook
&& !interrupt_input
)
1755 /* Turn alarm handling on unconditionally. It might have
1756 been turned off in process.c. */
1757 turn_on_atimers (1);
1759 /* If poll timer doesn't exist, are we need one with
1760 a different interval, start a new one. */
1761 if (poll_timer
== NULL
1762 || EMACS_SECS (poll_timer
->interval
) != polling_period
)
1764 EMACS_TIME interval
;
1767 cancel_atimer (poll_timer
);
1769 EMACS_SET_SECS_USECS (interval
, polling_period
, 0);
1770 poll_timer
= start_atimer (ATIMER_CONTINUOUS
, interval
,
1771 poll_for_input
, NULL
);
1774 /* Let the timer's callback function poll for input
1775 if this becomes zero. */
1776 --poll_suppress_count
;
1781 /* Nonzero if we are using polling to handle input asynchronously. */
1784 input_polling_used ()
1786 #ifdef POLL_FOR_INPUT
1787 return read_socket_hook
&& !interrupt_input
;
1793 /* Turn off polling. */
1798 #ifdef POLL_FOR_INPUT
1799 if (read_socket_hook
&& !interrupt_input
)
1800 ++poll_suppress_count
;
1804 /* Set the value of poll_suppress_count to COUNT
1805 and start or stop polling accordingly. */
1808 set_poll_suppress_count (count
)
1811 #ifdef POLL_FOR_INPUT
1812 if (count
== 0 && poll_suppress_count
!= 0)
1814 poll_suppress_count
= 1;
1817 else if (count
!= 0 && poll_suppress_count
== 0)
1821 poll_suppress_count
= count
;
1825 /* Bind polling_period to a value at least N.
1826 But don't decrease it. */
1829 bind_polling_period (n
)
1832 #ifdef POLL_FOR_INPUT
1833 int new = polling_period
;
1838 stop_other_atimers (poll_timer
);
1840 specbind (Qpolling_period
, make_number (new));
1841 /* Start a new alarm with the new period. */
1846 /* Apply the control modifier to CHARACTER. */
1852 /* Save the upper bits here. */
1853 int upper
= c
& ~0177;
1857 /* Everything in the columns containing the upper-case letters
1858 denotes a control character. */
1859 if (c
>= 0100 && c
< 0140)
1863 /* Set the shift modifier for a control char
1864 made from a shifted letter. But only for letters! */
1865 if (oc
>= 'A' && oc
<= 'Z')
1866 c
|= shift_modifier
;
1869 /* The lower-case letters denote control characters too. */
1870 else if (c
>= 'a' && c
<= 'z')
1873 /* Include the bits for control and shift
1874 only if the basic ASCII code can't indicate them. */
1878 /* Replace the high bits. */
1879 c
|= (upper
& ~ctrl_modifier
);
1886 /* Input of single characters from keyboard */
1888 Lisp_Object
print_help ();
1889 static Lisp_Object
kbd_buffer_get_event ();
1890 static void record_char ();
1893 static jmp_buf wrong_kboard_jmpbuf
;
1896 /* read a character from the keyboard; call the redisplay if needed */
1897 /* commandflag 0 means do not do auto-saving, but do do redisplay.
1898 -1 means do not do redisplay, but do do autosaving.
1901 /* The arguments MAPS and NMAPS are for menu prompting.
1902 MAPS is an array of keymaps; NMAPS is the length of MAPS.
1904 PREV_EVENT is the previous input event, or nil if we are reading
1905 the first event of a key sequence (or not reading a key sequence).
1906 If PREV_EVENT is t, that is a "magic" value that says
1907 not to run input methods, but in other respects to act as if
1908 not reading a key sequence.
1910 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
1911 if we used a mouse menu to read the input, or zero otherwise. If
1912 USED_MOUSE_MENU is null, we don't dereference it.
1914 Value is t if we showed a menu and the user rejected it. */
1917 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
)
1921 Lisp_Object prev_event
;
1922 int *used_mouse_menu
;
1926 jmp_buf local_getcjmp
;
1928 int key_already_recorded
= 0;
1929 Lisp_Object tem
, save
;
1930 Lisp_Object previous_echo_area_message
;
1931 Lisp_Object also_record
;
1933 struct gcpro gcpro1
, gcpro2
;
1937 before_command_key_count
= this_command_key_count
;
1938 before_command_echo_length
= echo_length ();
1940 previous_echo_area_message
= Qnil
;
1942 GCPRO2 (c
, previous_echo_area_message
);
1947 if (CONSP (Vunread_post_input_method_events
))
1949 c
= XCAR (Vunread_post_input_method_events
);
1950 Vunread_post_input_method_events
1951 = XCDR (Vunread_post_input_method_events
);
1953 /* Undo what read_char_x_menu_prompt did when it unread
1954 additional keys returned by Fx_popup_menu. */
1956 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
)))
1964 if (unread_command_char
!= -1)
1966 XSETINT (c
, unread_command_char
);
1967 unread_command_char
= -1;
1973 if (CONSP (Vunread_command_events
))
1975 c
= XCAR (Vunread_command_events
);
1976 Vunread_command_events
= XCDR (Vunread_command_events
);
1978 /* Undo what read_char_x_menu_prompt did when it unread
1979 additional keys returned by Fx_popup_menu. */
1981 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
)))
1986 goto reread_for_input_method
;
1989 if (CONSP (Vunread_input_method_events
))
1991 c
= XCAR (Vunread_input_method_events
);
1992 Vunread_input_method_events
= XCDR (Vunread_input_method_events
);
1994 /* Undo what read_char_x_menu_prompt did when it unread
1995 additional keys returned by Fx_popup_menu. */
1997 && (SYMBOLP (XCAR (c
)) || INTEGERP (XCAR (c
)))
2001 goto reread_for_input_method
;
2004 /* If there is no function key translated before
2005 reset-this-command-lengths takes effect, forget about it. */
2006 before_command_restore_flag
= 0;
2008 if (!NILP (Vexecuting_macro
))
2010 /* We set this to Qmacro; since that's not a frame, nobody will
2011 try to switch frames on us, and the selected window will
2014 Since this event came from a macro, it would be misleading to
2015 leave internal_last_event_frame set to wherever the last
2016 real event came from. Normally, a switch-frame event selects
2017 internal_last_event_frame after each command is read, but
2018 events read from a macro should never cause a new frame to be
2020 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
2022 /* Exit the macro if we are at the end.
2023 Also, some things replace the macro with t
2024 to force an early exit. */
2025 if (EQ (Vexecuting_macro
, Qt
)
2026 || executing_macro_index
>= XFASTINT (Flength (Vexecuting_macro
)))
2032 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
2033 if (STRINGP (Vexecuting_macro
)
2034 && (XINT (c
) & 0x80))
2035 XSETFASTINT (c
, CHAR_META
| (XINT (c
) & ~0x80));
2037 executing_macro_index
++;
2042 if (!NILP (unread_switch_frame
))
2044 c
= unread_switch_frame
;
2045 unread_switch_frame
= Qnil
;
2047 /* This event should make it into this_command_keys, and get echoed
2048 again, so we do not set `reread'. */
2052 /* if redisplay was requested */
2053 if (commandflag
>= 0)
2055 /* If there is pending input, process any events which are not
2056 user-visible, such as X selection_request events. */
2058 || detect_input_pending_run_timers (0))
2059 swallow_events (0); /* may clear input_pending */
2061 /* Redisplay if no pending input. */
2062 while (!input_pending
)
2067 /* Normal case: no input arrived during redisplay. */
2070 /* Input arrived and pre-empted redisplay.
2071 Process any events which are not user-visible. */
2073 /* If that cleared input_pending, try again to redisplay. */
2077 /* Message turns off echoing unless more keystrokes turn it on again. */
2078 if (/* There is a current message. */
2079 !NILP (echo_area_buffer
[0])
2080 /* And we're not echoing from this kboard. */
2081 && echo_kboard
!= current_kboard
2082 /* And it's either not ok to echo (ok_to_echo == NULL), or the
2083 last char echoed was from a different kboard. */
2084 && ok_to_echo_at_next_pause
!= echo_kboard
)
2087 /* If already echoing, continue. */
2090 /* Try reading a character via menu prompting in the minibuf.
2091 Try this before the sit-for, because the sit-for
2092 would do the wrong thing if we are supposed to do
2093 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
2094 after a mouse event so don't try a minibuf menu. */
2096 if (nmaps
> 0 && INTERACTIVE
2097 && !NILP (prev_event
) && ! EVENT_HAS_PARAMETERS (prev_event
)
2098 /* Don't bring up a menu if we already have another event. */
2099 && NILP (Vunread_command_events
)
2100 && unread_command_char
< 0
2101 && !detect_input_pending_run_timers (0))
2103 c
= read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
);
2106 key_already_recorded
= 1;
2111 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet.
2112 We will do that below, temporarily for short sections of code,
2113 when appropriate. local_getcjmp must be in effect
2114 around any call to sit_for or kbd_buffer_get_event;
2115 it *must not* be in effect when we call redisplay. */
2117 if (_setjmp (local_getcjmp
))
2119 XSETINT (c
, quit_char
);
2120 internal_last_event_frame
= selected_frame
;
2121 Vlast_event_frame
= internal_last_event_frame
;
2122 /* If we report the quit char as an event,
2123 don't do so more than once. */
2124 if (!NILP (Vinhibit_quit
))
2129 KBOARD
*kb
= FRAME_KBOARD (XFRAME (selected_frame
));
2130 if (kb
!= current_kboard
)
2132 Lisp_Object
*tailp
= &kb
->kbd_queue
;
2133 /* We shouldn't get here if we were in single-kboard mode! */
2136 while (CONSP (*tailp
))
2137 tailp
= &XCDR (*tailp
);
2140 *tailp
= Fcons (c
, Qnil
);
2141 kb
->kbd_queue_has_data
= 1;
2142 current_kboard
= kb
;
2143 /* This is going to exit from read_char
2144 so we had better get rid of this frame's stuff. */
2146 longjmp (wrong_kboard_jmpbuf
, 1);
2153 timer_start_idle ();
2155 /* If in middle of key sequence and minibuffer not active,
2156 start echoing if enough time elapses. */
2158 if (minibuf_level
== 0
2159 && !current_kboard
->immediate_echo
2160 && this_command_key_count
> 0
2162 && (FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
2163 && NILP (Fzerop (Vecho_keystrokes
))
2164 && (/* No message. */
2165 NILP (echo_area_buffer
[0])
2166 /* Or empty message. */
2167 || (BUF_BEG (XBUFFER (echo_area_buffer
[0]))
2168 == BUF_Z (XBUFFER (echo_area_buffer
[0])))
2169 /* Or already echoing from same kboard. */
2170 || (echo_kboard
&& ok_to_echo_at_next_pause
== echo_kboard
)
2171 /* Or not echoing before and echoing allowed. */
2172 || (!echo_kboard
&& ok_to_echo_at_next_pause
)))
2176 /* After a mouse event, start echoing right away.
2177 This is because we are probably about to display a menu,
2178 and we don't want to delay before doing so. */
2179 if (EVENT_HAS_PARAMETERS (prev_event
))
2184 double duration
= extract_float (Vecho_keystrokes
);
2185 sec
= (int) duration
;
2186 usec
= (duration
- sec
) * 1000000;
2187 save_getcjmp (save_jump
);
2188 restore_getcjmp (local_getcjmp
);
2189 tem0
= sit_for (sec
, usec
, 1, 1, 0);
2190 restore_getcjmp (save_jump
);
2192 && ! CONSP (Vunread_command_events
))
2197 /* Maybe auto save due to number of keystrokes. */
2199 if (commandflag
!= 0
2200 && auto_save_interval
> 0
2201 && num_nonmacro_input_events
- last_auto_save
> max (auto_save_interval
, 20)
2202 && !detect_input_pending_run_timers (0))
2204 Fdo_auto_save (Qnil
, Qnil
);
2205 /* Hooks can actually change some buffers in auto save. */
2209 /* Try reading using an X menu.
2210 This is never confused with reading using the minibuf
2211 because the recursive call of read_char in read_char_minibuf_menu_prompt
2212 does not pass on any keymaps. */
2214 if (nmaps
> 0 && INTERACTIVE
2215 && !NILP (prev_event
)
2216 && EVENT_HAS_PARAMETERS (prev_event
)
2217 && !EQ (XCAR (prev_event
), Qmenu_bar
)
2218 && !EQ (XCAR (prev_event
), Qtool_bar
)
2219 /* Don't bring up a menu if we already have another event. */
2220 && NILP (Vunread_command_events
)
2221 && unread_command_char
< 0)
2223 c
= read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
2225 /* Now that we have read an event, Emacs is not idle. */
2231 /* Maybe autosave and/or garbage collect due to idleness. */
2233 if (INTERACTIVE
&& NILP (c
))
2235 int delay_level
, buffer_size
;
2237 /* Slow down auto saves logarithmically in size of current buffer,
2238 and garbage collect while we're at it. */
2239 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
2240 last_non_minibuf_size
= Z
- BEG
;
2241 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
2243 while (buffer_size
> 64)
2244 delay_level
++, buffer_size
-= buffer_size
>> 2;
2245 if (delay_level
< 4) delay_level
= 4;
2246 /* delay_level is 4 for files under around 50k, 7 at 100k,
2247 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
2249 /* Auto save if enough time goes by without input. */
2250 if (commandflag
!= 0
2251 && num_nonmacro_input_events
> last_auto_save
2252 && INTEGERP (Vauto_save_timeout
)
2253 && XINT (Vauto_save_timeout
) > 0)
2257 save_getcjmp (save_jump
);
2258 restore_getcjmp (local_getcjmp
);
2259 tem0
= sit_for (delay_level
* XFASTINT (Vauto_save_timeout
) / 4,
2261 restore_getcjmp (save_jump
);
2264 && ! CONSP (Vunread_command_events
))
2266 Fdo_auto_save (Qnil
, Qnil
);
2268 /* If we have auto-saved and there is still no input
2269 available, garbage collect if there has been enough
2270 consing going on to make it worthwhile. */
2271 if (!detect_input_pending_run_timers (0)
2272 && consing_since_gc
> gc_cons_threshold
/ 2)
2273 Fgarbage_collect ();
2280 /* If this has become non-nil here, it has been set by a timer
2281 or sentinel or filter. */
2282 if (CONSP (Vunread_command_events
))
2284 c
= XCAR (Vunread_command_events
);
2285 Vunread_command_events
= XCDR (Vunread_command_events
);
2288 /* Read something from current KBOARD's side queue, if possible. */
2292 if (current_kboard
->kbd_queue_has_data
)
2294 if (!CONSP (current_kboard
->kbd_queue
))
2296 c
= XCAR (current_kboard
->kbd_queue
);
2297 current_kboard
->kbd_queue
2298 = XCDR (current_kboard
->kbd_queue
);
2299 if (NILP (current_kboard
->kbd_queue
))
2300 current_kboard
->kbd_queue_has_data
= 0;
2301 input_pending
= readable_events (0);
2302 if (EVENT_HAS_PARAMETERS (c
)
2303 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qswitch_frame
))
2304 internal_last_event_frame
= XCAR (XCDR (c
));
2305 Vlast_event_frame
= internal_last_event_frame
;
2310 /* If current_kboard's side queue is empty check the other kboards.
2311 If one of them has data that we have not yet seen here,
2312 switch to it and process the data waiting for it.
2314 Note: if the events queued up for another kboard
2315 have already been seen here, and therefore are not a complete command,
2316 the kbd_queue_has_data field is 0, so we skip that kboard here.
2317 That's to avoid an infinite loop switching between kboards here. */
2318 if (NILP (c
) && !single_kboard
)
2321 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2322 if (kb
->kbd_queue_has_data
)
2324 current_kboard
= kb
;
2325 /* This is going to exit from read_char
2326 so we had better get rid of this frame's stuff. */
2328 longjmp (wrong_kboard_jmpbuf
, 1);
2337 /* Finally, we read from the main queue,
2338 and if that gives us something we can't use yet, we put it on the
2339 appropriate side queue and try again. */
2345 /* Actually read a character, waiting if necessary. */
2346 save_getcjmp (save_jump
);
2347 restore_getcjmp (local_getcjmp
);
2348 c
= kbd_buffer_get_event (&kb
, used_mouse_menu
);
2349 restore_getcjmp (save_jump
);
2352 if (! NILP (c
) && (kb
!= current_kboard
))
2354 Lisp_Object
*tailp
= &kb
->kbd_queue
;
2355 while (CONSP (*tailp
))
2356 tailp
= &XCDR (*tailp
);
2359 *tailp
= Fcons (c
, Qnil
);
2360 kb
->kbd_queue_has_data
= 1;
2364 current_kboard
= kb
;
2365 /* This is going to exit from read_char
2366 so we had better get rid of this frame's stuff. */
2368 longjmp (wrong_kboard_jmpbuf
, 1);
2373 /* Terminate Emacs in batch mode if at eof. */
2374 if (noninteractive
&& INTEGERP (c
) && XINT (c
) < 0)
2375 Fkill_emacs (make_number (1));
2379 /* Add in any extra modifiers, where appropriate. */
2380 if ((extra_keyboard_modifiers
& CHAR_CTL
)
2381 || ((extra_keyboard_modifiers
& 0177) < ' '
2382 && (extra_keyboard_modifiers
& 0177) != 0))
2383 XSETINT (c
, make_ctrl_char (XINT (c
)));
2385 /* Transfer any other modifier bits directly from
2386 extra_keyboard_modifiers to c. Ignore the actual character code
2387 in the low 16 bits of extra_keyboard_modifiers. */
2388 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
2399 if (commandflag
>= 0
2400 && !input_pending
&& !detect_input_pending_run_timers (0))
2408 /* Buffer switch events are only for internal wakeups
2409 so don't show them to the user.
2410 Also, don't record a key if we already did. */
2411 if (BUFFERP (c
) || key_already_recorded
)
2414 /* Process special events within read_char
2415 and loop around to read another event. */
2418 tem
= get_keyelt (access_keymap (get_keymap_1 (Vspecial_event_map
, 0, 0),
2424 int was_locked
= single_kboard
;
2426 last_input_char
= c
;
2427 Fcommand_execute (tem
, Qnil
, Fvector (1, &last_input_char
), Qt
);
2429 /* Resume allowing input from any kboard, if that was true before. */
2431 any_kboard_state ();
2436 /* Handle things that only apply to characters. */
2439 /* If kbd_buffer_get_event gave us an EOF, return that. */
2443 if ((STRINGP (Vkeyboard_translate_table
)
2444 && XSTRING (Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
2445 || (VECTORP (Vkeyboard_translate_table
)
2446 && XVECTOR (Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
2447 || (CHAR_TABLE_P (Vkeyboard_translate_table
)
2448 && CHAR_TABLE_ORDINARY_SLOTS
> (unsigned) XFASTINT (c
)))
2451 d
= Faref (Vkeyboard_translate_table
, c
);
2452 /* nil in keyboard-translate-table means no translation. */
2458 /* If this event is a mouse click in the menu bar,
2459 return just menu-bar for now. Modify the mouse click event
2460 so we won't do this twice, then queue it up. */
2461 if (EVENT_HAS_PARAMETERS (c
)
2463 && CONSP (EVENT_START (c
))
2464 && CONSP (XCDR (EVENT_START (c
))))
2468 posn
= POSN_BUFFER_POSN (EVENT_START (c
));
2469 /* Handle menu-bar events:
2470 insert the dummy prefix event `menu-bar'. */
2471 if (EQ (posn
, Qmenu_bar
) || EQ (posn
, Qtool_bar
))
2473 /* Change menu-bar to (menu-bar) as the event "position". */
2474 POSN_BUFFER_POSN (EVENT_START (c
)) = Fcons (posn
, Qnil
);
2477 Vunread_command_events
= Fcons (c
, Vunread_command_events
);
2482 /* Store these characters into recent_keys, the dribble file if any,
2483 and the keyboard macro being defined, if any. */
2485 if (! NILP (also_record
))
2486 record_char (also_record
);
2488 /* Wipe the echo area.
2489 But first, if we are about to use an input method,
2490 save the echo area contents for it to refer to. */
2492 && ! NILP (Vinput_method_function
)
2493 && (unsigned) XINT (c
) >= ' '
2494 && (unsigned) XINT (c
) < 127)
2496 previous_echo_area_message
= Fcurrent_message ();
2497 Vinput_method_previous_message
= previous_echo_area_message
;
2500 /* Now wipe the echo area. */
2501 if (!NILP (echo_area_buffer
[0]))
2502 safe_run_hooks (Qecho_area_clear_hook
);
2503 clear_message (1, 0);
2505 reread_for_input_method
:
2507 /* Pass this to the input method, if appropriate. */
2509 && ! NILP (Vinput_method_function
)
2510 /* Don't run the input method within a key sequence,
2511 after the first event of the key sequence. */
2512 && NILP (prev_event
)
2513 && (unsigned) XINT (c
) >= ' '
2514 && (unsigned) XINT (c
) < 127)
2518 struct gcpro gcpro1
;
2519 int count
= specpdl_ptr
- specpdl
;
2521 /* Save the echo status. */
2522 int saved_immediate_echo
= current_kboard
->immediate_echo
;
2523 struct kboard
*saved_ok_to_echo
= ok_to_echo_at_next_pause
;
2524 int saved_echo_after_prompt
= current_kboard
->echo_after_prompt
;
2526 if (before_command_restore_flag
)
2528 this_command_key_count
= before_command_key_count_1
;
2529 if (this_command_key_count
< this_single_command_key_start
)
2530 this_single_command_key_start
= this_command_key_count
;
2531 echo_truncate (before_command_echo_length_1
);
2532 before_command_restore_flag
= 0;
2535 /* Save the this_command_keys status. */
2536 key_count
= this_command_key_count
;
2539 keys
= Fcopy_sequence (this_command_keys
);
2544 /* Clear out this_command_keys. */
2545 this_command_key_count
= 0;
2547 /* Now wipe the echo area. */
2548 if (!NILP (echo_area_buffer
[0]))
2549 safe_run_hooks (Qecho_area_clear_hook
);
2550 clear_message (1, 0);
2553 /* If we are not reading a key sequence,
2554 never use the echo area. */
2557 specbind (Qinput_method_use_echo_area
, Qt
);
2560 /* Call the input method. */
2561 tem
= call1 (Vinput_method_function
, c
);
2563 tem
= unbind_to (count
, tem
);
2565 /* Restore the saved echoing state
2566 and this_command_keys state. */
2567 this_command_key_count
= key_count
;
2569 this_command_keys
= keys
;
2572 ok_to_echo_at_next_pause
= saved_ok_to_echo
;
2573 current_kboard
->echo_after_prompt
= saved_echo_after_prompt
;
2574 if (saved_immediate_echo
)
2579 /* The input method can return no events. */
2582 /* Bring back the previous message, if any. */
2583 if (! NILP (previous_echo_area_message
))
2584 message_with_string ("%s", previous_echo_area_message
, 0);
2587 /* It returned one event or more. */
2589 Vunread_post_input_method_events
2590 = nconc2 (XCDR (tem
), Vunread_post_input_method_events
);
2595 /* Display help if not echoing. */
2597 && EQ (XCAR (c
), Qhelp_echo
))
2599 Lisp_Object msg
= XCDR (XCDR (c
));
2601 if (!NILP (Vshow_help_function
))
2602 call1 (Vshow_help_function
, msg
);
2603 else if (!echoing
&& !MINI_WINDOW_P (XWINDOW (selected_window
)))
2606 message3_nolog (msg
, XSTRING (msg
)->size
, STRING_MULTIBYTE (msg
));
2614 if (this_command_key_count
== 0 || ! reread
)
2616 before_command_key_count
= this_command_key_count
;
2617 before_command_echo_length
= echo_length ();
2619 /* Don't echo mouse motion events. */
2620 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
2621 && NILP (Fzerop (Vecho_keystrokes
))
2622 && ! (EVENT_HAS_PARAMETERS (c
)
2623 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
2626 if (! NILP (also_record
))
2627 echo_char (also_record
);
2628 /* Once we reread a character, echoing can happen
2629 the next time we pause to read a new one. */
2630 ok_to_echo_at_next_pause
= current_kboard
;
2633 /* Record this character as part of the current key. */
2634 add_command_key (c
);
2635 if (! NILP (also_record
))
2636 add_command_key (also_record
);
2639 last_input_char
= c
;
2642 /* Process the help character specially if enabled */
2643 if (!NILP (Vhelp_form
) && help_char_p (c
))
2646 count
= specpdl_ptr
- specpdl
;
2648 record_unwind_protect (Fset_window_configuration
,
2649 Fcurrent_window_configuration (Qnil
));
2651 tem0
= Feval (Vhelp_form
);
2653 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
2657 c
= read_char (0, 0, 0, Qnil
, 0);
2658 while (BUFFERP (c
));
2659 /* Remove the help from the frame */
2660 unbind_to (count
, Qnil
);
2663 if (EQ (c
, make_number (040)))
2667 c
= read_char (0, 0, 0, Qnil
, 0);
2668 while (BUFFERP (c
));
2675 /* Record a key that came from a mouse menu.
2676 Record it for echoing, for this-command-keys, and so on. */
2682 /* Wipe the echo area. */
2683 clear_message (1, 0);
2687 before_command_key_count
= this_command_key_count
;
2688 before_command_echo_length
= echo_length ();
2690 /* Don't echo mouse motion events. */
2691 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
2692 && NILP (Fzerop (Vecho_keystrokes
)))
2696 /* Once we reread a character, echoing can happen
2697 the next time we pause to read a new one. */
2698 ok_to_echo_at_next_pause
= 0;
2701 /* Record this character as part of the current key. */
2702 add_command_key (c
);
2704 /* Re-reading in the middle of a command */
2705 last_input_char
= c
;
2709 /* Return 1 if should recognize C as "the help character". */
2717 if (EQ (c
, Vhelp_char
))
2719 for (tail
= Vhelp_event_list
; CONSP (tail
); tail
= XCDR (tail
))
2720 if (EQ (c
, XCAR (tail
)))
2725 /* Record the input event C in various ways. */
2732 XVECTOR (recent_keys
)->contents
[recent_keys_index
] = c
;
2733 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
2734 recent_keys_index
= 0;
2736 /* Write c to the dribble file. If c is a lispy event, write
2737 the event's symbol to the dribble file, in <brackets>. Bleaugh.
2738 If you, dear reader, have a better idea, you've got the source. :-) */
2743 if (XUINT (c
) < 0x100)
2744 putc (XINT (c
), dribble
);
2746 fprintf (dribble
, " 0x%x", (int) XUINT (c
));
2750 Lisp_Object dribblee
;
2752 /* If it's a structured event, take the event header. */
2753 dribblee
= EVENT_HEAD (c
);
2755 if (SYMBOLP (dribblee
))
2757 putc ('<', dribble
);
2758 fwrite (XSYMBOL (dribblee
)->name
->data
, sizeof (char),
2759 STRING_BYTES (XSYMBOL (dribblee
)->name
),
2761 putc ('>', dribble
);
2768 store_kbd_macro_char (c
);
2770 num_nonmacro_input_events
++;
2777 struct buffer
*old
= current_buffer
;
2778 Fprinc (object
, Qnil
);
2779 set_buffer_internal (XBUFFER (Vstandard_output
));
2780 call0 (intern ("help-mode"));
2781 set_buffer_internal (old
);
2785 /* Copy out or in the info on where C-g should throw to.
2786 This is used when running Lisp code from within get_char,
2787 in case get_char is called recursively.
2788 See read_process_output. */
2794 bcopy (getcjmp
, temp
, sizeof getcjmp
);
2798 restore_getcjmp (temp
)
2801 bcopy (temp
, getcjmp
, sizeof getcjmp
);
2806 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
2807 of this function. */
2810 tracking_off (old_value
)
2811 Lisp_Object old_value
;
2813 do_mouse_tracking
= old_value
;
2814 if (NILP (old_value
))
2816 /* Redisplay may have been preempted because there was input
2817 available, and it assumes it will be called again after the
2818 input has been processed. If the only input available was
2819 the sort that we have just disabled, then we need to call
2821 if (!readable_events (1))
2823 redisplay_preserve_echo_area ();
2824 get_input_pending (&input_pending
, 1);
2829 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
2830 "Evaluate BODY with mouse movement events enabled.\n\
2831 Within a `track-mouse' form, mouse motion generates input events that\n\
2832 you can read with `read-event'.\n\
2833 Normally, mouse motion is ignored.")
2837 int count
= specpdl_ptr
- specpdl
;
2840 record_unwind_protect (tracking_off
, do_mouse_tracking
);
2842 do_mouse_tracking
= Qt
;
2844 val
= Fprogn (args
);
2845 return unbind_to (count
, val
);
2848 /* If mouse has moved on some frame, return one of those frames.
2849 Return 0 otherwise. */
2854 Lisp_Object tail
, frame
;
2856 FOR_EACH_FRAME (tail
, frame
)
2858 if (XFRAME (frame
)->mouse_moved
)
2859 return XFRAME (frame
);
2865 #endif /* HAVE_MOUSE */
2867 /* Low level keyboard/mouse input.
2868 kbd_buffer_store_event places events in kbd_buffer, and
2869 kbd_buffer_get_event retrieves them. */
2871 /* Return true iff there are any events in the queue that read-char
2872 would return. If this returns false, a read-char would block. */
2874 readable_events (do_timers_now
)
2878 timer_check (do_timers_now
);
2880 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2883 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2888 if (current_kboard
->kbd_queue_has_data
)
2894 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2895 if (kb
->kbd_queue_has_data
)
2901 /* Set this for debugging, to have a way to get out */
2906 event_to_kboard (event
)
2907 struct input_event
*event
;
2910 frame
= event
->frame_or_window
;
2912 frame
= XCAR (frame
);
2913 else if (WINDOWP (frame
))
2914 frame
= WINDOW_FRAME (XWINDOW (frame
));
2916 /* There are still some events that don't set this field.
2917 For now, just ignore the problem.
2918 Also ignore dead frames here. */
2919 if (!FRAMEP (frame
) || !FRAME_LIVE_P (XFRAME (frame
)))
2922 return FRAME_KBOARD (XFRAME (frame
));
2926 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
2929 kbd_buffer_store_event (event
)
2930 register struct input_event
*event
;
2932 if (event
->kind
== no_event
)
2935 if (event
->kind
== ascii_keystroke
)
2937 register int c
= event
->code
& 0377;
2939 if (event
->modifiers
& ctrl_modifier
)
2940 c
= make_ctrl_char (c
);
2942 c
|= (event
->modifiers
2943 & (meta_modifier
| alt_modifier
2944 | hyper_modifier
| super_modifier
));
2948 extern SIGTYPE
interrupt_signal ();
2951 struct input_event
*sp
;
2954 && (kb
= FRAME_KBOARD (XFRAME (event
->frame_or_window
)),
2955 kb
!= current_kboard
))
2958 = Fcons (make_lispy_switch_frame (event
->frame_or_window
),
2959 Fcons (make_number (c
), Qnil
));
2960 kb
->kbd_queue_has_data
= 1;
2961 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
2963 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
2966 if (event_to_kboard (sp
) == kb
)
2968 sp
->kind
= no_event
;
2969 sp
->frame_or_window
= Qnil
;
2976 /* If this results in a quit_char being returned to Emacs as
2977 input, set Vlast_event_frame properly. If this doesn't
2978 get returned to Emacs as an event, the next event read
2979 will set Vlast_event_frame again, so this is safe to do. */
2983 focus
= FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
2985 focus
= event
->frame_or_window
;
2986 internal_last_event_frame
= focus
;
2987 Vlast_event_frame
= focus
;
2990 last_event_timestamp
= event
->timestamp
;
2991 interrupt_signal ();
2995 if (c
&& c
== stop_character
)
3001 /* Don't insert two buffer_switch_event's in a row.
3002 Just ignore the second one. */
3003 else if (event
->kind
== buffer_switch_event
3004 && kbd_fetch_ptr
!= kbd_store_ptr
3005 && kbd_store_ptr
->kind
== buffer_switch_event
)
3008 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
3009 kbd_store_ptr
= kbd_buffer
;
3011 /* Don't let the very last slot in the buffer become full,
3012 since that would make the two pointers equal,
3013 and that is indistinguishable from an empty buffer.
3014 Discard the event if it would fill the last slot. */
3015 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
3017 struct input_event
*sp
= kbd_store_ptr
;
3018 sp
->kind
= event
->kind
;
3019 if (event
->kind
== selection_request_event
)
3021 /* We must not use the ordinary copying code for this case,
3022 since `part' is an enum and copying it might not copy enough
3024 bcopy (event
, (char *) sp
, sizeof (*event
));
3028 sp
->code
= event
->code
;
3029 sp
->part
= event
->part
;
3030 sp
->frame_or_window
= event
->frame_or_window
;
3031 sp
->modifiers
= event
->modifiers
;
3034 sp
->timestamp
= event
->timestamp
;
3036 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_store_ptr
3038 = event
->frame_or_window
);
3044 /* Discard any mouse events in the event buffer by setting them to
3047 discard_mouse_events ()
3049 struct input_event
*sp
;
3050 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
3052 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3055 if (sp
->kind
== mouse_click
3057 || sp
->kind
== w32_scroll_bar_click
3059 || sp
->kind
== scroll_bar_click
)
3061 sp
->kind
= no_event
;
3066 /* Read one event from the event buffer, waiting if necessary.
3067 The value is a Lisp object representing the event.
3068 The value is nil for an event that should be ignored,
3069 or that was handled here.
3070 We always read and discard one event. */
3073 kbd_buffer_get_event (kbp
, used_mouse_menu
)
3075 int *used_mouse_menu
;
3084 *kbp
= current_kboard
;
3088 /* Wait until there is input available. */
3091 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3094 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
3098 /* If the quit flag is set, then read_char will return
3099 quit_char, so that counts as "available input." */
3100 if (!NILP (Vquit_flag
))
3101 quit_throw_to_read_char ();
3103 /* One way or another, wait until input is available; then, if
3104 interrupt handlers have not read it, read it now. */
3107 wait_for_kbd_input ();
3109 /* Note SIGIO has been undef'd if FIONREAD is missing. */
3113 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3116 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
3120 Lisp_Object minus_one
;
3122 XSETINT (minus_one
, -1);
3123 wait_reading_process_input (0, 0, minus_one
, 1);
3125 if (!interrupt_input
&& kbd_fetch_ptr
== kbd_store_ptr
)
3126 /* Pass 1 for EXPECT since we just waited to have input. */
3127 read_avail_input (1);
3129 #endif /* not VMS */
3132 if (CONSP (Vunread_command_events
))
3135 first
= XCAR (Vunread_command_events
);
3136 Vunread_command_events
= XCDR (Vunread_command_events
);
3137 *kbp
= current_kboard
;
3141 /* At this point, we know that there is a readable event available
3142 somewhere. If the event queue is empty, then there must be a
3143 mouse movement enabled and available. */
3144 if (kbd_fetch_ptr
!= kbd_store_ptr
)
3146 struct input_event
*event
;
3148 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
3152 last_event_timestamp
= event
->timestamp
;
3155 *kbp
= event_to_kboard (event
);
3157 *kbp
= current_kboard
; /* Better than returning null ptr? */
3159 *kbp
= &the_only_kboard
;
3164 /* These two kinds of events get special handling
3165 and don't actually appear to the command loop.
3166 We return nil for them. */
3167 if (event
->kind
== selection_request_event
)
3170 struct input_event copy
;
3172 /* Remove it from the buffer before processing it,
3173 since otherwise swallow_events will see it
3174 and process it again. */
3176 kbd_fetch_ptr
= event
+ 1;
3177 input_pending
= readable_events (0);
3178 x_handle_selection_request (©
);
3180 /* We're getting selection request events, but we don't have
3186 else if (event
->kind
== selection_clear_event
)
3189 struct input_event copy
;
3191 /* Remove it from the buffer before processing it. */
3193 kbd_fetch_ptr
= event
+ 1;
3194 input_pending
= readable_events (0);
3195 x_handle_selection_clear (©
);
3197 /* We're getting selection request events, but we don't have
3202 #if defined (HAVE_X11) || defined (HAVE_NTGUI)
3203 else if (event
->kind
== delete_window_event
)
3205 /* Make an event (delete-frame (FRAME)). */
3206 obj
= Fcons (event
->frame_or_window
, Qnil
);
3207 obj
= Fcons (Qdelete_frame
, Fcons (obj
, Qnil
));
3208 kbd_fetch_ptr
= event
+ 1;
3210 else if (event
->kind
== iconify_event
)
3212 /* Make an event (iconify-frame (FRAME)). */
3213 obj
= Fcons (event
->frame_or_window
, Qnil
);
3214 obj
= Fcons (Qiconify_frame
, Fcons (obj
, Qnil
));
3215 kbd_fetch_ptr
= event
+ 1;
3217 else if (event
->kind
== deiconify_event
)
3219 /* Make an event (make-frame-visible (FRAME)). */
3220 obj
= Fcons (event
->frame_or_window
, Qnil
);
3221 obj
= Fcons (Qmake_frame_visible
, Fcons (obj
, Qnil
));
3222 kbd_fetch_ptr
= event
+ 1;
3225 else if (event
->kind
== buffer_switch_event
)
3227 /* The value doesn't matter here; only the type is tested. */
3228 XSETBUFFER (obj
, current_buffer
);
3229 kbd_fetch_ptr
= event
+ 1;
3231 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
3232 else if (event
->kind
== menu_bar_activate_event
)
3234 kbd_fetch_ptr
= event
+ 1;
3235 input_pending
= readable_events (0);
3236 if (FRAME_LIVE_P (XFRAME (event
->frame_or_window
)))
3237 x_activate_menubar (XFRAME (event
->frame_or_window
));
3241 else if (event
->kind
== language_change_event
)
3243 /* Make an event (language-change (FRAME CHARSET LCID)). */
3244 obj
= Fcons (event
->modifiers
, Qnil
);
3245 obj
= Fcons (event
->code
, Qnil
);
3246 obj
= Fcons (event
->frame_or_window
, obj
);
3247 obj
= Fcons (Qlanguage_change
, Fcons (obj
, Qnil
));
3248 kbd_fetch_ptr
= event
+ 1;
3251 /* Just discard these, by returning nil.
3252 With MULTI_KBOARD, these events are used as placeholders
3253 when we need to randomly delete events from the queue.
3254 (They shouldn't otherwise be found in the buffer,
3255 but on some machines it appears they do show up
3256 even without MULTI_KBOARD.) */
3257 /* On Windows NT/9X, no_event is used to delete extraneous
3258 mouse events during a popup-menu call. */
3259 else if (event
->kind
== no_event
)
3260 kbd_fetch_ptr
= event
+ 1;
3261 else if (event
->kind
== HELP_EVENT
)
3263 /* The car of event->frame_or_window is a frame,
3264 the cdr is the help to display. */
3265 obj
= Fcons (Qhelp_echo
, event
->frame_or_window
);
3266 kbd_fetch_ptr
= event
+ 1;
3268 /* If this event is on a different frame, return a switch-frame this
3269 time, and leave the event in the queue for next time. */
3275 frame
= event
->frame_or_window
;
3277 frame
= XCAR (frame
);
3278 else if (WINDOWP (frame
))
3279 frame
= WINDOW_FRAME (XWINDOW (frame
));
3281 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
3285 if (! EQ (frame
, internal_last_event_frame
)
3286 && !EQ (frame
, selected_frame
))
3287 obj
= make_lispy_switch_frame (frame
);
3288 internal_last_event_frame
= frame
;
3290 /* If we didn't decide to make a switch-frame event, go ahead
3291 and build a real event from the queue entry. */
3295 obj
= make_lispy_event (event
);
3296 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
3297 /* If this was a menu selection, then set the flag to inhibit
3298 writing to last_nonmenu_event. Don't do this if the event
3299 we're returning is (menu-bar), though; that indicates the
3300 beginning of the menu sequence, and we might as well leave
3301 that as the `event with parameters' for this selection. */
3302 if ((event
->kind
== menu_bar_event
3303 || event
->kind
== TOOL_BAR_EVENT
)
3304 && !(CONSP (obj
) && EQ (XCAR (obj
), Qmenu_bar
))
3305 && !(CONSP (obj
) && EQ (XCAR (obj
), Qtool_bar
))
3307 *used_mouse_menu
= 1;
3310 /* Wipe out this event, to catch bugs. */
3311 event
->kind
= no_event
;
3312 XVECTOR (kbd_buffer_frame_or_window
)->contents
[event
- kbd_buffer
] = Qnil
;
3314 kbd_fetch_ptr
= event
+ 1;
3319 /* Try generating a mouse motion event. */
3320 else if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
3322 FRAME_PTR f
= some_mouse_moved ();
3323 Lisp_Object bar_window
;
3324 enum scroll_bar_part part
;
3328 *kbp
= current_kboard
;
3329 /* Note that this uses F to determine which display to look at.
3330 If there is no valid info, it does not store anything
3331 so x remains nil. */
3333 (*mouse_position_hook
) (&f
, 0, &bar_window
, &part
, &x
, &y
, &time
);
3337 /* Decide if we should generate a switch-frame event. Don't
3338 generate switch-frame events for motion outside of all Emacs
3344 frame
= FRAME_FOCUS_FRAME (f
);
3346 XSETFRAME (frame
, f
);
3348 if (! EQ (frame
, internal_last_event_frame
)
3349 && !EQ (frame
, selected_frame
))
3350 obj
= make_lispy_switch_frame (frame
);
3351 internal_last_event_frame
= frame
;
3354 /* If we didn't decide to make a switch-frame event, go ahead and
3355 return a mouse-motion event. */
3356 if (!NILP (x
) && NILP (obj
))
3357 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
3359 #endif /* HAVE_MOUSE */
3361 /* We were promised by the above while loop that there was
3362 something for us to read! */
3365 input_pending
= readable_events (0);
3367 Vlast_event_frame
= internal_last_event_frame
;
3372 /* Process any events that are not user-visible,
3373 then return, without reading any user-visible events. */
3376 swallow_events (do_display
)
3381 while (kbd_fetch_ptr
!= kbd_store_ptr
)
3383 struct input_event
*event
;
3385 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
3389 last_event_timestamp
= event
->timestamp
;
3391 /* These two kinds of events get special handling
3392 and don't actually appear to the command loop. */
3393 if (event
->kind
== selection_request_event
)
3396 struct input_event copy
;
3398 /* Remove it from the buffer before processing it,
3399 since otherwise swallow_events called recursively could see it
3400 and process it again. */
3402 kbd_fetch_ptr
= event
+ 1;
3403 input_pending
= readable_events (0);
3404 x_handle_selection_request (©
);
3406 /* We're getting selection request events, but we don't have
3412 else if (event
->kind
== selection_clear_event
)
3415 struct input_event copy
;
3417 /* Remove it from the buffer before processing it, */
3420 kbd_fetch_ptr
= event
+ 1;
3421 input_pending
= readable_events (0);
3422 x_handle_selection_clear (©
);
3424 /* We're getting selection request events, but we don't have
3433 old_timers_run
= timers_run
;
3434 get_input_pending (&input_pending
, 1);
3436 if (timers_run
!= old_timers_run
&& do_display
)
3437 redisplay_preserve_echo_area ();
3440 static EMACS_TIME timer_idleness_start_time
;
3442 /* Record the start of when Emacs is idle,
3443 for the sake of running idle-time timers. */
3450 /* If we are already in the idle state, do nothing. */
3451 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3454 EMACS_GET_TIME (timer_idleness_start_time
);
3456 /* Mark all idle-time timers as once again candidates for running. */
3457 for (timers
= Vtimer_idle_list
; CONSP (timers
); timers
= XCDR (timers
))
3461 timer
= XCAR (timers
);
3463 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3465 XVECTOR (timer
)->contents
[0] = Qnil
;
3469 /* Record that Emacs is no longer idle, so stop running idle-time timers. */
3474 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
3477 /* This is only for debugging. */
3478 struct input_event last_timer_event
;
3480 /* Check whether a timer has fired. To prevent larger problems we simply
3481 disregard elements that are not proper timers. Do not make a circular
3482 timer list for the time being.
3484 Returns the number of seconds to wait until the next timer fires. If a
3485 timer is triggering now, return zero seconds.
3486 If no timer is active, return -1 seconds.
3488 If a timer is ripe, we run it, with quitting turned off.
3490 DO_IT_NOW is now ignored. It used to mean that we should
3491 run the timer directly instead of queueing a timer-event.
3492 Now we always run timers directly. */
3495 timer_check (do_it_now
)
3498 EMACS_TIME nexttime
;
3499 EMACS_TIME now
, idleness_now
;
3500 Lisp_Object timers
, idle_timers
, chosen_timer
;
3501 struct gcpro gcpro1
, gcpro2
, gcpro3
;
3503 EMACS_SET_SECS (nexttime
, -1);
3504 EMACS_SET_USECS (nexttime
, -1);
3506 /* Always consider the ordinary timers. */
3507 timers
= Vtimer_list
;
3508 /* Consider the idle timers only if Emacs is idle. */
3509 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3510 idle_timers
= Vtimer_idle_list
;
3513 chosen_timer
= Qnil
;
3514 GCPRO3 (timers
, idle_timers
, chosen_timer
);
3516 if (CONSP (timers
) || CONSP (idle_timers
))
3518 EMACS_GET_TIME (now
);
3519 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3520 EMACS_SUB_TIME (idleness_now
, now
, timer_idleness_start_time
);
3523 while (CONSP (timers
) || CONSP (idle_timers
))
3525 Lisp_Object
*vector
;
3526 Lisp_Object timer
, idle_timer
;
3527 EMACS_TIME timer_time
, idle_timer_time
;
3528 EMACS_TIME difference
, timer_difference
, idle_timer_difference
;
3530 /* Skip past invalid timers and timers already handled. */
3533 timer
= XCAR (timers
);
3534 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3536 timers
= XCDR (timers
);
3539 vector
= XVECTOR (timer
)->contents
;
3541 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
3542 || !INTEGERP (vector
[3])
3543 || ! NILP (vector
[0]))
3545 timers
= XCDR (timers
);
3549 if (!NILP (idle_timers
))
3551 timer
= XCAR (idle_timers
);
3552 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3554 idle_timers
= XCDR (idle_timers
);
3557 vector
= XVECTOR (timer
)->contents
;
3559 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
3560 || !INTEGERP (vector
[3])
3561 || ! NILP (vector
[0]))
3563 idle_timers
= XCDR (idle_timers
);
3568 /* Set TIMER, TIMER_TIME and TIMER_DIFFERENCE
3569 based on the next ordinary timer.
3570 TIMER_DIFFERENCE is the distance in time from NOW to when
3571 this timer becomes ripe (negative if it's already ripe). */
3574 timer
= XCAR (timers
);
3575 vector
= XVECTOR (timer
)->contents
;
3576 EMACS_SET_SECS (timer_time
,
3577 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
3578 EMACS_SET_USECS (timer_time
, XINT (vector
[3]));
3579 EMACS_SUB_TIME (timer_difference
, timer_time
, now
);
3582 /* Set IDLE_TIMER, IDLE_TIMER_TIME and IDLE_TIMER_DIFFERENCE
3583 based on the next idle timer. */
3584 if (!NILP (idle_timers
))
3586 idle_timer
= XCAR (idle_timers
);
3587 vector
= XVECTOR (idle_timer
)->contents
;
3588 EMACS_SET_SECS (idle_timer_time
,
3589 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
3590 EMACS_SET_USECS (idle_timer_time
, XINT (vector
[3]));
3591 EMACS_SUB_TIME (idle_timer_difference
, idle_timer_time
, idleness_now
);
3594 /* Decide which timer is the next timer,
3595 and set CHOSEN_TIMER, VECTOR and DIFFERENCE accordingly.
3596 Also step down the list where we found that timer. */
3598 if (! NILP (timers
) && ! NILP (idle_timers
))
3601 EMACS_SUB_TIME (temp
, timer_difference
, idle_timer_difference
);
3602 if (EMACS_TIME_NEG_P (temp
))
3604 chosen_timer
= timer
;
3605 timers
= XCDR (timers
);
3606 difference
= timer_difference
;
3610 chosen_timer
= idle_timer
;
3611 idle_timers
= XCDR (idle_timers
);
3612 difference
= idle_timer_difference
;
3615 else if (! NILP (timers
))
3617 chosen_timer
= timer
;
3618 timers
= XCDR (timers
);
3619 difference
= timer_difference
;
3623 chosen_timer
= idle_timer
;
3624 idle_timers
= XCDR (idle_timers
);
3625 difference
= idle_timer_difference
;
3627 vector
= XVECTOR (chosen_timer
)->contents
;
3629 /* If timer is rupe, run it if it hasn't been run. */
3630 if (EMACS_TIME_NEG_P (difference
)
3631 || (EMACS_SECS (difference
) == 0
3632 && EMACS_USECS (difference
) == 0))
3634 if (NILP (vector
[0]))
3636 int was_locked
= single_kboard
;
3637 int count
= specpdl_ptr
- specpdl
;
3639 /* Mark the timer as triggered to prevent problems if the lisp
3640 code fails to reschedule it right. */
3643 specbind (Qinhibit_quit
, Qt
);
3645 call1 (Qtimer_event_handler
, chosen_timer
);
3648 unbind_to (count
, Qnil
);
3650 /* Resume allowing input from any kboard, if that was true before. */
3652 any_kboard_state ();
3654 /* Since we have handled the event,
3655 we don't need to tell the caller to wake up and do it. */
3659 /* When we encounter a timer that is still waiting,
3660 return the amount of time to wait before it is ripe. */
3667 /* No timers are pending in the future. */
3668 /* Return 0 if we generated an event, and -1 if not. */
3673 /* Caches for modify_event_symbol. */
3674 static Lisp_Object accent_key_syms
;
3675 static Lisp_Object func_key_syms
;
3676 static Lisp_Object mouse_syms
;
3678 static Lisp_Object mouse_wheel_syms
;
3680 static Lisp_Object drag_n_drop_syms
;
3682 /* This is a list of keysym codes for special "accent" characters.
3683 It parallels lispy_accent_keys. */
3685 static int lispy_accent_codes
[] =
3687 #ifdef XK_dead_circumflex
3692 #ifdef XK_dead_grave
3697 #ifdef XK_dead_tilde
3702 #ifdef XK_dead_diaeresis
3707 #ifdef XK_dead_macron
3712 #ifdef XK_dead_degree
3717 #ifdef XK_dead_acute
3722 #ifdef XK_dead_cedilla
3727 #ifdef XK_dead_breve
3732 #ifdef XK_dead_ogonek
3737 #ifdef XK_dead_caron
3742 #ifdef XK_dead_doubleacute
3743 XK_dead_doubleacute
,
3747 #ifdef XK_dead_abovedot
3754 /* This is a list of Lisp names for special "accent" characters.
3755 It parallels lispy_accent_codes. */
3757 static char *lispy_accent_keys
[] =
3775 #define FUNCTION_KEY_OFFSET 0x0
3777 char *lispy_function_keys
[] =
3781 0, /* VK_LBUTTON 0x01 */
3782 0, /* VK_RBUTTON 0x02 */
3783 "cancel", /* VK_CANCEL 0x03 */
3784 0, /* VK_MBUTTON 0x04 */
3786 0, 0, 0, /* 0x05 .. 0x07 */
3788 "backspace", /* VK_BACK 0x08 */
3789 "tab", /* VK_TAB 0x09 */
3791 0, 0, /* 0x0A .. 0x0B */
3793 "clear", /* VK_CLEAR 0x0C */
3794 "return", /* VK_RETURN 0x0D */
3796 0, 0, /* 0x0E .. 0x0F */
3798 0, /* VK_SHIFT 0x10 */
3799 0, /* VK_CONTROL 0x11 */
3800 0, /* VK_MENU 0x12 */
3801 "pause", /* VK_PAUSE 0x13 */
3802 "capslock", /* VK_CAPITAL 0x14 */
3804 0, 0, 0, 0, 0, 0, /* 0x15 .. 0x1A */
3806 "escape", /* VK_ESCAPE 0x1B */
3808 0, 0, 0, 0, /* 0x1C .. 0x1F */
3810 0, /* VK_SPACE 0x20 */
3811 "prior", /* VK_PRIOR 0x21 */
3812 "next", /* VK_NEXT 0x22 */
3813 "end", /* VK_END 0x23 */
3814 "home", /* VK_HOME 0x24 */
3815 "left", /* VK_LEFT 0x25 */
3816 "up", /* VK_UP 0x26 */
3817 "right", /* VK_RIGHT 0x27 */
3818 "down", /* VK_DOWN 0x28 */
3819 "select", /* VK_SELECT 0x29 */
3820 "print", /* VK_PRINT 0x2A */
3821 "execute", /* VK_EXECUTE 0x2B */
3822 "snapshot", /* VK_SNAPSHOT 0x2C */
3823 "insert", /* VK_INSERT 0x2D */
3824 "delete", /* VK_DELETE 0x2E */
3825 "help", /* VK_HELP 0x2F */
3827 /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
3829 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3831 0, 0, 0, 0, 0, 0, 0, /* 0x3A .. 0x40 */
3833 /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
3835 0, 0, 0, 0, 0, 0, 0, 0, 0,
3836 0, 0, 0, 0, 0, 0, 0, 0, 0,
3837 0, 0, 0, 0, 0, 0, 0, 0,
3839 "lwindow", /* VK_LWIN 0x5B */
3840 "rwindow", /* VK_RWIN 0x5C */
3841 "apps", /* VK_APPS 0x5D */
3843 0, 0, /* 0x5E .. 0x5F */
3845 "kp-0", /* VK_NUMPAD0 0x60 */
3846 "kp-1", /* VK_NUMPAD1 0x61 */
3847 "kp-2", /* VK_NUMPAD2 0x62 */
3848 "kp-3", /* VK_NUMPAD3 0x63 */
3849 "kp-4", /* VK_NUMPAD4 0x64 */
3850 "kp-5", /* VK_NUMPAD5 0x65 */
3851 "kp-6", /* VK_NUMPAD6 0x66 */
3852 "kp-7", /* VK_NUMPAD7 0x67 */
3853 "kp-8", /* VK_NUMPAD8 0x68 */
3854 "kp-9", /* VK_NUMPAD9 0x69 */
3855 "kp-multiply", /* VK_MULTIPLY 0x6A */
3856 "kp-add", /* VK_ADD 0x6B */
3857 "kp-separator", /* VK_SEPARATOR 0x6C */
3858 "kp-subtract", /* VK_SUBTRACT 0x6D */
3859 "kp-decimal", /* VK_DECIMAL 0x6E */
3860 "kp-divide", /* VK_DIVIDE 0x6F */
3861 "f1", /* VK_F1 0x70 */
3862 "f2", /* VK_F2 0x71 */
3863 "f3", /* VK_F3 0x72 */
3864 "f4", /* VK_F4 0x73 */
3865 "f5", /* VK_F5 0x74 */
3866 "f6", /* VK_F6 0x75 */
3867 "f7", /* VK_F7 0x76 */
3868 "f8", /* VK_F8 0x77 */
3869 "f9", /* VK_F9 0x78 */
3870 "f10", /* VK_F10 0x79 */
3871 "f11", /* VK_F11 0x7A */
3872 "f12", /* VK_F12 0x7B */
3873 "f13", /* VK_F13 0x7C */
3874 "f14", /* VK_F14 0x7D */
3875 "f15", /* VK_F15 0x7E */
3876 "f16", /* VK_F16 0x7F */
3877 "f17", /* VK_F17 0x80 */
3878 "f18", /* VK_F18 0x81 */
3879 "f19", /* VK_F19 0x82 */
3880 "f20", /* VK_F20 0x83 */
3881 "f21", /* VK_F21 0x84 */
3882 "f22", /* VK_F22 0x85 */
3883 "f23", /* VK_F23 0x86 */
3884 "f24", /* VK_F24 0x87 */
3886 0, 0, 0, 0, /* 0x88 .. 0x8B */
3887 0, 0, 0, 0, /* 0x8C .. 0x8F */
3889 "kp-numlock", /* VK_NUMLOCK 0x90 */
3890 "scroll", /* VK_SCROLL 0x91 */
3892 "kp-space", /* VK_NUMPAD_CLEAR 0x92 */
3893 "kp-enter", /* VK_NUMPAD_ENTER 0x93 */
3894 "kp-prior", /* VK_NUMPAD_PRIOR 0x94 */
3895 "kp-next", /* VK_NUMPAD_NEXT 0x95 */
3896 "kp-end", /* VK_NUMPAD_END 0x96 */
3897 "kp-home", /* VK_NUMPAD_HOME 0x97 */
3898 "kp-left", /* VK_NUMPAD_LEFT 0x98 */
3899 "kp-up", /* VK_NUMPAD_UP 0x99 */
3900 "kp-right", /* VK_NUMPAD_RIGHT 0x9A */
3901 "kp-down", /* VK_NUMPAD_DOWN 0x9B */
3902 "kp-insert", /* VK_NUMPAD_INSERT 0x9C */
3903 "kp-delete", /* VK_NUMPAD_DELETE 0x9D */
3905 0, 0, /* 0x9E .. 0x9F */
3908 * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
3909 * Used only as parameters to GetAsyncKeyState and GetKeyState.
3910 * No other API or message will distinguish left and right keys this way.
3914 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3915 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3916 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3917 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3918 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3924 "attn", /* VK_ATTN 0xF6 */
3925 "crsel", /* VK_CRSEL 0xF7 */
3926 "exsel", /* VK_EXSEL 0xF8 */
3927 "ereof", /* VK_EREOF 0xF9 */
3928 "play", /* VK_PLAY 0xFA */
3929 "zoom", /* VK_ZOOM 0xFB */
3930 "noname", /* VK_NONAME 0xFC */
3931 "pa1", /* VK_PA1 0xFD */
3932 "oem_clear", /* VK_OEM_CLEAR 0xFE */
3936 #else /* not HAVE_NTGUI */
3939 static char *lispy_kana_keys
[] =
3941 /* X Keysym value */
3942 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x400 .. 0x40f */
3943 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x410 .. 0x41f */
3944 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x420 .. 0x42f */
3945 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x430 .. 0x43f */
3946 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x440 .. 0x44f */
3947 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x450 .. 0x45f */
3948 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x460 .. 0x46f */
3949 0,0,0,0,0,0,0,0,0,0,0,0,0,0,"overline",0,
3950 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x480 .. 0x48f */
3951 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x490 .. 0x49f */
3952 0, "kana-fullstop", "kana-openingbracket", "kana-closingbracket",
3953 "kana-comma", "kana-conjunctive", "kana-WO", "kana-a",
3954 "kana-i", "kana-u", "kana-e", "kana-o",
3955 "kana-ya", "kana-yu", "kana-yo", "kana-tsu",
3956 "prolongedsound", "kana-A", "kana-I", "kana-U",
3957 "kana-E", "kana-O", "kana-KA", "kana-KI",
3958 "kana-KU", "kana-KE", "kana-KO", "kana-SA",
3959 "kana-SHI", "kana-SU", "kana-SE", "kana-SO",
3960 "kana-TA", "kana-CHI", "kana-TSU", "kana-TE",
3961 "kana-TO", "kana-NA", "kana-NI", "kana-NU",
3962 "kana-NE", "kana-NO", "kana-HA", "kana-HI",
3963 "kana-FU", "kana-HE", "kana-HO", "kana-MA",
3964 "kana-MI", "kana-MU", "kana-ME", "kana-MO",
3965 "kana-YA", "kana-YU", "kana-YO", "kana-RA",
3966 "kana-RI", "kana-RU", "kana-RE", "kana-RO",
3967 "kana-WA", "kana-N", "voicedsound", "semivoicedsound",
3968 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4e0 .. 0x4ef */
3969 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4f0 .. 0x4ff */
3971 #endif /* XK_kana_A */
3973 #define FUNCTION_KEY_OFFSET 0xff00
3975 /* You'll notice that this table is arranged to be conveniently
3976 indexed by X Windows keysym values. */
3977 static char *lispy_function_keys
[] =
3979 /* X Keysym value */
3981 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00...0f */
3982 "backspace", "tab", "linefeed", "clear",
3984 0, 0, 0, "pause", /* 0xff10...1f */
3985 0, 0, 0, 0, 0, 0, 0, "escape",
3987 0, "kanji", "muhenkan", "henkan", /* 0xff20...2f */
3988 "romaji", "hiragana", "katakana", "hiragana-katakana",
3989 "zenkaku", "hankaku", "zenkaku-hankaku", "touroku",
3990 "massyo", "kana-lock", "kana-shift", "eisu-shift",
3991 "eisu-toggle", /* 0xff30...3f */
3992 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3993 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
3995 "home", "left", "up", "right", /* 0xff50 */ /* IsCursorKey */
3996 "down", "prior", "next", "end",
3997 "begin", 0, 0, 0, 0, 0, 0, 0,
3998 "select", /* 0xff60 */ /* IsMiscFunctionKey */
4009 "break", /* 0xff6b */
4012 0, 0, 0, 0, "backtab", 0, 0, 0, /* 0xff70... */
4013 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff78... */
4014 "kp-space", /* 0xff80 */ /* IsKeypadKey */
4015 0, 0, 0, 0, 0, 0, 0, 0,
4016 "kp-tab", /* 0xff89 */
4018 "kp-enter", /* 0xff8d */
4020 "kp-f1", /* 0xff91 */
4024 "kp-home", /* 0xff95 */
4029 "kp-prior", /* kp-page-up */
4030 "kp-next", /* kp-page-down */
4036 0, 0, 0, 0, 0, 0, 0, 0, 0,
4037 "kp-multiply", /* 0xffaa */
4042 "kp-divide", /* 0xffaf */
4043 "kp-0", /* 0xffb0 */
4044 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
4047 "kp-equal", /* 0xffbd */
4048 "f1", /* 0xffbe */ /* IsFunctionKey */
4050 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
4051 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
4052 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
4053 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
4054 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
4055 0, 0, 0, 0, 0, 0, 0, 0,
4056 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
4057 0, 0, 0, 0, 0, 0, 0, "delete"
4060 /* ISO 9995 Function and Modifier Keys; the first byte is 0xFE. */
4061 #define ISO_FUNCTION_KEY_OFFSET 0xfe00
4063 static char *iso_lispy_function_keys
[] =
4065 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe00 */
4066 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe08 */
4067 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe10 */
4068 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe18 */
4069 "iso-lefttab", /* 0xfe20 */
4070 "iso-move-line-up", "iso-move-line-down",
4071 "iso-partial-line-up", "iso-partial-line-down",
4072 "iso-partial-space-left", "iso-partial-space-right",
4073 "iso-set-margin-left", "iso-set-margin-right", /* 0xffe27, 28 */
4074 "iso-release-margin-left", "iso-release-margin-right",
4075 "iso-release-both-margins",
4076 "iso-fast-cursor-left", "iso-fast-cursor-right",
4077 "iso-fast-cursor-up", "iso-fast-cursor-down",
4078 "iso-continuous-underline", "iso-discontinuous-underline", /* 0xfe30, 31 */
4079 "iso-emphasize", "iso-center-object", "iso-enter", /* ... 0xfe34 */
4082 #endif /* not HAVE_NTGUI */
4084 static char *lispy_mouse_names
[] =
4086 "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5"
4090 /* mouse-wheel events are generated by the wheel on devices such as
4091 the MS Intellimouse. The wheel sits in between the left and right
4092 mouse buttons, and is typically used to scroll or zoom the window
4093 underneath the pointer. mouse-wheel events specify the object on
4094 which they operate, and a delta corresponding to the amount and
4095 direction that the wheel is rotated. Clicking the mouse-wheel
4096 generates a mouse-2 event. */
4097 static char *lispy_mouse_wheel_names
[] =
4102 #endif /* WINDOWSNT */
4104 /* drag-n-drop events are generated when a set of selected files are
4105 dragged from another application and dropped onto an Emacs window. */
4106 static char *lispy_drag_n_drop_names
[] =
4111 /* Scroll bar parts. */
4112 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
4113 Lisp_Object Qup
, Qdown
, Qbottom
, Qend_scroll
;
4114 Lisp_Object Qtop
, Qratio
;
4116 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
4117 Lisp_Object
*scroll_bar_parts
[] = {
4118 &Qabove_handle
, &Qhandle
, &Qbelow_handle
,
4119 &Qup
, &Qdown
, &Qtop
, &Qbottom
, &Qend_scroll
, &Qratio
4122 /* User signal events. */
4123 Lisp_Object Qusr1_signal
, Qusr2_signal
;
4125 Lisp_Object
*lispy_user_signals
[] =
4127 &Qusr1_signal
, &Qusr2_signal
4131 /* A vector, indexed by button number, giving the down-going location
4132 of currently depressed buttons, both scroll bar and non-scroll bar.
4134 The elements have the form
4135 (BUTTON-NUMBER MODIFIER-MASK . REST)
4136 where REST is the cdr of a position as it would be reported in the event.
4138 The make_lispy_event function stores positions here to tell the
4139 difference between click and drag events, and to store the starting
4140 location to be included in drag events. */
4142 static Lisp_Object button_down_location
;
4144 /* Information about the most recent up-going button event: Which
4145 button, what location, and what time. */
4147 static int last_mouse_button
;
4148 static int last_mouse_x
;
4149 static int last_mouse_y
;
4150 static unsigned long button_down_time
;
4152 /* The maximum time between clicks to make a double-click,
4153 or Qnil to disable double-click detection,
4154 or Qt for no time limit. */
4155 Lisp_Object Vdouble_click_time
;
4157 /* The number of clicks in this multiple-click. */
4159 int double_click_count
;
4161 /* Given a struct input_event, build the lisp event which represents
4162 it. If EVENT is 0, build a mouse movement event from the mouse
4163 movement buffer, which should have a movement event in it.
4165 Note that events must be passed to this function in the order they
4166 are received; this function stores the location of button presses
4167 in order to build drag events when the button is released. */
4170 make_lispy_event (event
)
4171 struct input_event
*event
;
4175 switch (SWITCH_ENUM_CAST (event
->kind
))
4177 /* A simple keystroke. */
4178 case ascii_keystroke
:
4180 Lisp_Object lispy_c
;
4181 int c
= event
->code
& 0377;
4182 /* Turn ASCII characters into control characters
4184 if (event
->modifiers
& ctrl_modifier
)
4185 c
= make_ctrl_char (c
);
4187 /* Add in the other modifier bits. We took care of ctrl_modifier
4188 just above, and the shift key was taken care of by the X code,
4189 and applied to control characters by make_ctrl_char. */
4190 c
|= (event
->modifiers
4191 & (meta_modifier
| alt_modifier
4192 | hyper_modifier
| super_modifier
));
4193 /* Distinguish Shift-SPC from SPC. */
4194 if ((event
->code
& 0377) == 040
4195 && event
->modifiers
& shift_modifier
)
4196 c
|= shift_modifier
;
4197 button_down_time
= 0;
4198 XSETFASTINT (lispy_c
, c
);
4202 /* A function key. The symbol may need to have modifier prefixes
4204 case non_ascii_keystroke
:
4205 button_down_time
= 0;
4207 for (i
= 0; i
< sizeof (lispy_accent_codes
) / sizeof (int); i
++)
4208 if (event
->code
== lispy_accent_codes
[i
])
4209 return modify_event_symbol (i
,
4211 Qfunction_key
, Qnil
,
4212 lispy_accent_keys
, &accent_key_syms
,
4213 (sizeof (lispy_accent_keys
)
4214 / sizeof (lispy_accent_keys
[0])));
4216 /* Handle system-specific keysyms. */
4217 if (event
->code
& (1 << 28))
4219 /* We need to use an alist rather than a vector as the cache
4220 since we can't make a vector long enuf. */
4221 if (NILP (current_kboard
->system_key_syms
))
4222 current_kboard
->system_key_syms
= Fcons (Qnil
, Qnil
);
4223 return modify_event_symbol (event
->code
,
4226 current_kboard
->Vsystem_key_alist
,
4227 0, ¤t_kboard
->system_key_syms
,
4232 if (event
->code
>= 0x400 && event
->code
< 0x500)
4233 return modify_event_symbol (event
->code
- 0x400,
4234 event
->modifiers
& ~shift_modifier
,
4235 Qfunction_key
, Qnil
,
4236 lispy_kana_keys
, &func_key_syms
,
4237 (sizeof (lispy_kana_keys
)
4238 / sizeof (lispy_kana_keys
[0])));
4239 #endif /* XK_kana_A */
4241 #ifdef ISO_FUNCTION_KEY_OFFSET
4242 if (event
->code
< FUNCTION_KEY_OFFSET
4243 && event
->code
>= ISO_FUNCTION_KEY_OFFSET
)
4244 return modify_event_symbol (event
->code
- ISO_FUNCTION_KEY_OFFSET
,
4246 Qfunction_key
, Qnil
,
4247 iso_lispy_function_keys
, &func_key_syms
,
4248 (sizeof (iso_lispy_function_keys
)
4249 / sizeof (iso_lispy_function_keys
[0])));
4252 return modify_event_symbol (event
->code
- FUNCTION_KEY_OFFSET
,
4254 Qfunction_key
, Qnil
,
4255 lispy_function_keys
, &func_key_syms
,
4256 (sizeof (lispy_function_keys
)
4257 / sizeof (lispy_function_keys
[0])));
4260 /* A mouse click. Figure out where it is, decide whether it's
4261 a press, click or drag, and build the appropriate structure. */
4263 #ifndef USE_TOOLKIT_SCROLL_BARS
4264 case scroll_bar_click
:
4267 int button
= event
->code
;
4269 Lisp_Object position
;
4270 Lisp_Object
*start_pos_ptr
;
4271 Lisp_Object start_pos
;
4273 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
4276 /* Build the position as appropriate for this mouse click. */
4277 if (event
->kind
== mouse_click
)
4280 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
4283 Lisp_Object string_info
= Qnil
;
4286 /* Ignore mouse events that were made on frame that
4287 have been deleted. */
4288 if (! FRAME_LIVE_P (f
))
4291 /* EVENT->x and EVENT->y are frame-relative pixel
4292 coordinates at this place. Under old redisplay, COLUMN
4293 and ROW are set to frame relative glyph coordinates
4294 which are then used to determine whether this click is
4295 in a menu (non-toolkit version). */
4296 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4297 &column
, &row
, NULL
, 1);
4299 #ifndef USE_X_TOOLKIT
4300 /* In the non-toolkit version, clicks on the menu bar
4301 are ordinary button events in the event buffer.
4302 Distinguish them, and invoke the menu.
4304 (In the toolkit version, the toolkit handles the menu bar
4305 and Emacs doesn't know about it until after the user
4306 makes a selection.) */
4307 if (row
>= 0 && row
< FRAME_MENU_BAR_LINES (f
)
4308 && (event
->modifiers
& down_modifier
))
4310 Lisp_Object items
, item
;
4315 /* Activate the menu bar on the down event. If the
4316 up event comes in before the menu code can deal with it,
4318 if (! (event
->modifiers
& down_modifier
))
4322 /* Find the menu bar item under `column'. */
4324 items
= FRAME_MENU_BAR_ITEMS (f
);
4325 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
4327 Lisp_Object pos
, string
;
4328 string
= XVECTOR (items
)->contents
[i
+ 1];
4329 pos
= XVECTOR (items
)->contents
[i
+ 3];
4332 if (column
>= XINT (pos
)
4333 && column
< XINT (pos
) + XSTRING (string
)->size
)
4335 item
= XVECTOR (items
)->contents
[i
];
4340 /* ELisp manual 2.4b says (x y) are window relative but
4341 code says they are frame-relative. */
4343 = Fcons (event
->frame_or_window
,
4345 Fcons (Fcons (event
->x
, event
->y
),
4346 Fcons (make_number (event
->timestamp
),
4349 return Fcons (item
, Fcons (position
, Qnil
));
4351 #endif /* not USE_X_TOOLKIT */
4353 /* Set `window' to the window under frame pixel coordinates
4354 event->x/event->y. */
4355 window
= window_from_coordinates (f
, XINT (event
->x
),
4356 XINT (event
->y
), &part
, 0);
4358 if (!WINDOWP (window
))
4360 window
= event
->frame_or_window
;
4365 /* It's a click in window window at frame coordinates
4366 event->x/ event->y. */
4367 struct window
*w
= XWINDOW (window
);
4369 /* Get window relative coordinates. Original code
4370 `rounded' this to glyph boundaries. */
4371 int wx
= FRAME_TO_WINDOW_PIXEL_X (w
, XINT (event
->x
));
4372 int wy
= FRAME_TO_WINDOW_PIXEL_Y (w
, XINT (event
->y
));
4374 /* Set event coordinates to window-relative coordinates
4375 for constructing the Lisp event below. */
4376 XSETINT (event
->x
, wx
);
4377 XSETINT (event
->y
, wy
);
4379 if (part
== 1 || part
== 3)
4381 /* Mode line or top line. Look for a string under
4382 the mouse that may have a `local-map' property. */
4386 posn
= part
== 1 ? Qmode_line
: Qheader_line
;
4387 string
= mode_line_string (w
, wx
, wy
, part
== 1, &charpos
);
4388 if (STRINGP (string
))
4389 string_info
= Fcons (string
, make_number (charpos
));
4392 posn
= Qvertical_line
;
4394 XSETINT (posn
, buffer_posn_from_coords (w
, &wx
, &wy
));
4400 Fcons (Fcons (event
->x
, event
->y
),
4401 Fcons (make_number (event
->timestamp
),
4404 : Fcons (string_info
, Qnil
))))));
4406 #ifndef USE_TOOLKIT_SCROLL_BARS
4409 /* It's a scrollbar click. */
4411 Lisp_Object portion_whole
;
4414 window
= event
->frame_or_window
;
4415 portion_whole
= Fcons (event
->x
, event
->y
);
4416 part
= *scroll_bar_parts
[(int) event
->part
];
4420 Fcons (Qvertical_scroll_bar
,
4421 Fcons (portion_whole
,
4422 Fcons (make_number (event
->timestamp
),
4423 Fcons (part
, Qnil
)))));
4425 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4427 start_pos_ptr
= &XVECTOR (button_down_location
)->contents
[button
];
4429 start_pos
= *start_pos_ptr
;
4430 *start_pos_ptr
= Qnil
;
4432 is_double
= (button
== last_mouse_button
4433 && XINT (event
->x
) == last_mouse_x
4434 && XINT (event
->y
) == last_mouse_y
4435 && button_down_time
!= 0
4436 && (EQ (Vdouble_click_time
, Qt
)
4437 || (INTEGERP (Vdouble_click_time
)
4438 && ((int)(event
->timestamp
- button_down_time
)
4439 < XINT (Vdouble_click_time
)))));
4440 last_mouse_button
= button
;
4441 last_mouse_x
= XINT (event
->x
);
4442 last_mouse_y
= XINT (event
->y
);
4444 /* If this is a button press, squirrel away the location, so
4445 we can decide later whether it was a click or a drag. */
4446 if (event
->modifiers
& down_modifier
)
4450 double_click_count
++;
4451 event
->modifiers
|= ((double_click_count
> 2)
4456 double_click_count
= 1;
4457 button_down_time
= event
->timestamp
;
4458 *start_pos_ptr
= Fcopy_alist (position
);
4461 /* Now we're releasing a button - check the co-ordinates to
4462 see if this was a click or a drag. */
4463 else if (event
->modifiers
& up_modifier
)
4465 /* If we did not see a down before this up,
4466 ignore the up. Probably this happened because
4467 the down event chose a menu item.
4468 It would be an annoyance to treat the release
4469 of the button that chose the menu item
4470 as a separate event. */
4472 if (!CONSP (start_pos
))
4475 event
->modifiers
&= ~up_modifier
;
4476 #if 0 /* Formerly we treated an up with no down as a click event. */
4477 if (!CONSP (start_pos
))
4478 event
->modifiers
|= click_modifier
;
4482 /* The third element of every position should be the (x,y)
4486 down
= Fnth (make_number (2), start_pos
);
4487 if (EQ (event
->x
, XCAR (down
))
4488 && EQ (event
->y
, XCDR (down
)))
4490 event
->modifiers
|= click_modifier
;
4494 button_down_time
= 0;
4495 event
->modifiers
|= drag_modifier
;
4497 /* Don't check is_double; treat this as multiple
4498 if the down-event was multiple. */
4499 if (double_click_count
> 1)
4500 event
->modifiers
|= ((double_click_count
> 2)
4506 /* Every mouse event should either have the down_modifier or
4507 the up_modifier set. */
4511 /* Get the symbol we should use for the mouse click. */
4514 head
= modify_event_symbol (button
,
4517 lispy_mouse_names
, &mouse_syms
,
4518 (sizeof (lispy_mouse_names
)
4519 / sizeof (lispy_mouse_names
[0])));
4520 if (event
->modifiers
& drag_modifier
)
4525 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
4528 Fcons (make_number (double_click_count
),
4537 #if USE_TOOLKIT_SCROLL_BARS
4539 /* We don't have down and up events if using toolkit scroll bars,
4540 so make this always a click event. Store in the `part' of
4541 the Lisp event a symbol which maps to the following actions:
4543 `above_handle' page up
4544 `below_handle' page down
4548 `bottom' bottom of buffer
4549 `handle' thumb has been dragged.
4550 `end-scroll' end of interaction with scroll bar
4552 The incoming input_event contains in its `part' member an
4553 index of type `enum scroll_bar_part' which we can use as an
4554 index in scroll_bar_parts to get the appropriate symbol. */
4556 case scroll_bar_click
:
4558 Lisp_Object position
, head
, window
, portion_whole
, part
;
4560 window
= event
->frame_or_window
;
4561 portion_whole
= Fcons (event
->x
, event
->y
);
4562 part
= *scroll_bar_parts
[(int) event
->part
];
4566 Fcons (Qvertical_scroll_bar
,
4567 Fcons (portion_whole
,
4568 Fcons (make_number (event
->timestamp
),
4569 Fcons (part
, Qnil
)))));
4571 /* Always treat scroll bar events as clicks. */
4572 event
->modifiers
|= click_modifier
;
4574 /* Get the symbol we should use for the mouse click. */
4575 head
= modify_event_symbol (event
->code
,
4578 lispy_mouse_names
, &mouse_syms
,
4579 (sizeof (lispy_mouse_names
)
4580 / sizeof (lispy_mouse_names
[0])));
4581 return Fcons (head
, Fcons (position
, Qnil
));
4584 #endif /* USE_TOOLKIT_SCROLL_BARS */
4587 case w32_scroll_bar_click
:
4589 int button
= event
->code
;
4591 Lisp_Object position
;
4592 Lisp_Object
*start_pos_ptr
;
4593 Lisp_Object start_pos
;
4595 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
4600 Lisp_Object portion_whole
;
4603 window
= event
->frame_or_window
;
4604 portion_whole
= Fcons (event
->x
, event
->y
);
4605 part
= *scroll_bar_parts
[(int) event
->part
];
4609 Fcons (Qvertical_scroll_bar
,
4610 Fcons (portion_whole
,
4611 Fcons (make_number (event
->timestamp
),
4612 Fcons (part
, Qnil
)))));
4615 /* Always treat W32 scroll bar events as clicks. */
4616 event
->modifiers
|= click_modifier
;
4619 /* Get the symbol we should use for the mouse click. */
4622 head
= modify_event_symbol (button
,
4625 lispy_mouse_names
, &mouse_syms
,
4626 (sizeof (lispy_mouse_names
)
4627 / sizeof (lispy_mouse_names
[0])));
4636 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
4639 Lisp_Object head
, position
;
4642 /* Ignore mouse events that were made on frame that
4643 have been deleted. */
4644 if (! FRAME_LIVE_P (f
))
4646 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4647 &column
, &row
, NULL
, 1);
4648 window
= window_from_coordinates (f
, column
, row
, &part
, 0);
4650 if (!WINDOWP (window
))
4652 window
= event
->frame_or_window
;
4657 int pixcolumn
, pixrow
;
4658 column
-= XINT (XWINDOW (window
)->left
);
4659 row
-= XINT (XWINDOW (window
)->top
);
4660 glyph_to_pixel_coords (f
, column
, row
, &pixcolumn
, &pixrow
);
4661 XSETINT (event
->x
, pixcolumn
);
4662 XSETINT (event
->y
, pixrow
);
4667 posn
= Qvertical_line
;
4669 posn
= Qheader_line
;
4672 buffer_posn_from_coords (XWINDOW (window
),
4677 Lisp_Object head
, position
;
4682 Fcons (Fcons (event
->x
, event
->y
),
4683 Fcons (make_number (event
->timestamp
),
4686 head
= modify_event_symbol (0, event
->modifiers
,
4688 lispy_mouse_wheel_names
,
4689 &mouse_wheel_syms
, 1);
4692 Fcons (make_number (event
->code
),
4696 #endif /* WINDOWSNT */
4707 /* The frame_or_window field should be a cons of the frame in
4708 which the event occurred and a list of the filenames
4710 if (! CONSP (event
->frame_or_window
))
4713 f
= XFRAME (XCAR (event
->frame_or_window
));
4714 files
= XCDR (event
->frame_or_window
);
4716 /* Ignore mouse events that were made on frames that
4717 have been deleted. */
4718 if (! FRAME_LIVE_P (f
))
4720 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4721 &column
, &row
, NULL
, 1);
4722 window
= window_from_coordinates (f
, column
, row
, &part
, 0);
4724 if (!WINDOWP (window
))
4726 window
= XCAR (event
->frame_or_window
);
4731 /* It's an event in window `window' at frame coordinates
4732 event->x/ event->y. */
4733 struct window
*w
= XWINDOW (window
);
4735 /* Get window relative coordinates. */
4736 int wx
= FRAME_TO_WINDOW_PIXEL_X (w
, XINT (event
->x
));
4737 int wy
= FRAME_TO_WINDOW_PIXEL_Y (w
, XINT (event
->y
));
4739 /* Set event coordinates to window-relative coordinates
4740 for constructing the Lisp event below. */
4741 XSETINT (event
->x
, wx
);
4742 XSETINT (event
->y
, wy
);
4747 posn
= Qvertical_line
;
4749 posn
= Qheader_line
;
4751 XSETINT (posn
, buffer_posn_from_coords (w
, &wx
, &wy
));
4755 Lisp_Object head
, position
;
4760 Fcons (Fcons (event
->x
, event
->y
),
4761 Fcons (make_number (event
->timestamp
),
4764 head
= modify_event_symbol (0, event
->modifiers
,
4766 lispy_drag_n_drop_names
,
4767 &drag_n_drop_syms
, 1);
4774 #endif /* HAVE_MOUSE */
4776 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
4777 case menu_bar_event
:
4778 /* The event value is in the cdr of the frame_or_window slot. */
4779 if (!CONSP (event
->frame_or_window
))
4781 return XCDR (event
->frame_or_window
);
4784 case TOOL_BAR_EVENT
:
4787 if (!CONSP (event
->frame_or_window
))
4789 key
= XCDR (event
->frame_or_window
);
4791 key
= apply_modifiers (event
->modifiers
, key
);
4796 /* A user signal. */
4797 return *lispy_user_signals
[event
->code
];
4799 /* The 'kind' field of the event is something we don't recognize. */
4808 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
4810 Lisp_Object bar_window
;
4811 enum scroll_bar_part part
;
4815 /* Is it a scroll bar movement? */
4816 if (frame
&& ! NILP (bar_window
))
4818 Lisp_Object part_sym
;
4820 part_sym
= *scroll_bar_parts
[(int) part
];
4821 return Fcons (Qscroll_bar_movement
,
4822 (Fcons (Fcons (bar_window
,
4823 Fcons (Qvertical_scroll_bar
,
4824 Fcons (Fcons (x
, y
),
4825 Fcons (make_number (time
),
4831 /* Or is it an ordinary mouse movement? */
4839 /* It's in a frame; which window on that frame? */
4840 window
= window_from_coordinates (frame
, XINT (x
), XINT (y
), &area
, 0);
4844 if (WINDOWP (window
))
4846 struct window
*w
= XWINDOW (window
);
4849 /* Get window relative coordinates. */
4850 wx
= FRAME_TO_WINDOW_PIXEL_X (w
, XINT (x
));
4851 wy
= FRAME_TO_WINDOW_PIXEL_Y (w
, XINT (y
));
4858 posn
= Qvertical_line
;
4860 posn
= Qheader_line
;
4862 XSETINT (posn
, buffer_posn_from_coords (w
, &wx
, &wy
));
4864 else if (frame
!= 0)
4866 XSETFRAME (window
, frame
);
4877 return Fcons (Qmouse_movement
,
4878 Fcons (Fcons (window
,
4880 Fcons (Fcons (x
, y
),
4881 Fcons (make_number (time
),
4887 #endif /* HAVE_MOUSE */
4889 /* Construct a switch frame event. */
4891 make_lispy_switch_frame (frame
)
4894 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
4897 /* Manipulating modifiers. */
4899 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
4901 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
4902 SYMBOL's name of the end of the modifiers; the string from this
4903 position is the unmodified symbol name.
4905 This doesn't use any caches. */
4908 parse_modifiers_uncached (symbol
, modifier_end
)
4912 struct Lisp_String
*name
;
4916 CHECK_SYMBOL (symbol
, 1);
4919 name
= XSYMBOL (symbol
)->name
;
4921 for (i
= 0; i
+2 <= STRING_BYTES (name
); )
4923 int this_mod_end
= 0;
4926 /* See if the name continues with a modifier word.
4927 Check that the word appears, but don't check what follows it.
4928 Set this_mod and this_mod_end to record what we find. */
4930 switch (name
->data
[i
])
4932 #define SINGLE_LETTER_MOD(BIT) \
4933 (this_mod_end = i + 1, this_mod = BIT)
4936 SINGLE_LETTER_MOD (alt_modifier
);
4940 SINGLE_LETTER_MOD (ctrl_modifier
);
4944 SINGLE_LETTER_MOD (hyper_modifier
);
4948 SINGLE_LETTER_MOD (meta_modifier
);
4952 SINGLE_LETTER_MOD (shift_modifier
);
4956 SINGLE_LETTER_MOD (super_modifier
);
4959 #undef SINGLE_LETTER_MOD
4962 /* If we found no modifier, stop looking for them. */
4963 if (this_mod_end
== 0)
4966 /* Check there is a dash after the modifier, so that it
4967 really is a modifier. */
4968 if (this_mod_end
>= STRING_BYTES (name
)
4969 || name
->data
[this_mod_end
] != '-')
4972 /* This modifier is real; look for another. */
4973 modifiers
|= this_mod
;
4974 i
= this_mod_end
+ 1;
4977 /* Should we include the `click' modifier? */
4978 if (! (modifiers
& (down_modifier
| drag_modifier
4979 | double_modifier
| triple_modifier
))
4980 && i
+ 7 == STRING_BYTES (name
)
4981 && strncmp (name
->data
+ i
, "mouse-", 6) == 0
4982 && ('0' <= name
->data
[i
+ 6] && name
->data
[i
+ 6] <= '9'))
4983 modifiers
|= click_modifier
;
4991 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
4992 prepended to the string BASE[0..BASE_LEN-1].
4993 This doesn't use any caches. */
4995 apply_modifiers_uncached (modifiers
, base
, base_len
, base_len_byte
)
4998 int base_len
, base_len_byte
;
5000 /* Since BASE could contain nulls, we can't use intern here; we have
5001 to use Fintern, which expects a genuine Lisp_String, and keeps a
5004 = (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
5010 /* Only the event queue may use the `up' modifier; it should always
5011 be turned into a click or drag event before presented to lisp code. */
5012 if (modifiers
& up_modifier
)
5015 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
5016 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
5017 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
5018 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
5019 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
5020 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
5021 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
5022 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
5023 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
5024 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
5025 /* The click modifier is denoted by the absence of other modifiers. */
5029 mod_len
= p
- new_mods
;
5033 Lisp_Object new_name
;
5035 new_name
= make_uninit_multibyte_string (mod_len
+ base_len
,
5036 mod_len
+ base_len_byte
);
5037 bcopy (new_mods
, XSTRING (new_name
)->data
, mod_len
);
5038 bcopy (base
, XSTRING (new_name
)->data
+ mod_len
, base_len_byte
);
5040 return Fintern (new_name
, Qnil
);
5045 static char *modifier_names
[] =
5047 "up", "down", "drag", "click", "double", "triple", 0, 0,
5048 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5049 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
5051 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
5053 static Lisp_Object modifier_symbols
;
5055 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
5057 lispy_modifier_list (modifiers
)
5060 Lisp_Object modifier_list
;
5063 modifier_list
= Qnil
;
5064 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
5065 if (modifiers
& (1<<i
))
5066 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
5069 return modifier_list
;
5073 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
5074 where UNMODIFIED is the unmodified form of SYMBOL,
5075 MASK is the set of modifiers present in SYMBOL's name.
5076 This is similar to parse_modifiers_uncached, but uses the cache in
5077 SYMBOL's Qevent_symbol_element_mask property, and maintains the
5078 Qevent_symbol_elements property. */
5081 parse_modifiers (symbol
)
5084 Lisp_Object elements
;
5086 elements
= Fget (symbol
, Qevent_symbol_element_mask
);
5087 if (CONSP (elements
))
5092 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
5093 Lisp_Object unmodified
;
5096 unmodified
= Fintern (make_string (XSYMBOL (symbol
)->name
->data
+ end
,
5097 STRING_BYTES (XSYMBOL (symbol
)->name
) - end
),
5100 if (modifiers
& ~(((EMACS_INT
)1 << VALBITS
) - 1))
5102 XSETFASTINT (mask
, modifiers
);
5103 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
5105 /* Cache the parsing results on SYMBOL. */
5106 Fput (symbol
, Qevent_symbol_element_mask
,
5108 Fput (symbol
, Qevent_symbol_elements
,
5109 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
5111 /* Since we know that SYMBOL is modifiers applied to unmodified,
5112 it would be nice to put that in unmodified's cache.
5113 But we can't, since we're not sure that parse_modifiers is
5120 /* Apply the modifiers MODIFIERS to the symbol BASE.
5121 BASE must be unmodified.
5123 This is like apply_modifiers_uncached, but uses BASE's
5124 Qmodifier_cache property, if present. It also builds
5125 Qevent_symbol_elements properties, since it has that info anyway.
5127 apply_modifiers copies the value of BASE's Qevent_kind property to
5128 the modified symbol. */
5130 apply_modifiers (modifiers
, base
)
5134 Lisp_Object cache
, index
, entry
, new_symbol
;
5136 /* Mask out upper bits. We don't know where this value's been. */
5137 modifiers
&= ((EMACS_INT
)1 << VALBITS
) - 1;
5139 /* The click modifier never figures into cache indices. */
5140 cache
= Fget (base
, Qmodifier_cache
);
5141 XSETFASTINT (index
, (modifiers
& ~click_modifier
));
5142 entry
= assq_no_quit (index
, cache
);
5145 new_symbol
= XCDR (entry
);
5148 /* We have to create the symbol ourselves. */
5149 new_symbol
= apply_modifiers_uncached (modifiers
,
5150 XSYMBOL (base
)->name
->data
,
5151 XSYMBOL (base
)->name
->size
,
5152 STRING_BYTES (XSYMBOL (base
)->name
));
5154 /* Add the new symbol to the base's cache. */
5155 entry
= Fcons (index
, new_symbol
);
5156 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
5158 /* We have the parsing info now for free, so add it to the caches. */
5159 XSETFASTINT (index
, modifiers
);
5160 Fput (new_symbol
, Qevent_symbol_element_mask
,
5161 Fcons (base
, Fcons (index
, Qnil
)));
5162 Fput (new_symbol
, Qevent_symbol_elements
,
5163 Fcons (base
, lispy_modifier_list (modifiers
)));
5166 /* Make sure this symbol is of the same kind as BASE.
5168 You'd think we could just set this once and for all when we
5169 intern the symbol above, but reorder_modifiers may call us when
5170 BASE's property isn't set right; we can't assume that just
5171 because it has a Qmodifier_cache property it must have its
5172 Qevent_kind set right as well. */
5173 if (NILP (Fget (new_symbol
, Qevent_kind
)))
5177 kind
= Fget (base
, Qevent_kind
);
5179 Fput (new_symbol
, Qevent_kind
, kind
);
5186 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
5187 return a symbol with the modifiers placed in the canonical order.
5188 Canonical order is alphabetical, except for down and drag, which
5189 always come last. The 'click' modifier is never written out.
5191 Fdefine_key calls this to make sure that (for example) C-M-foo
5192 and M-C-foo end up being equivalent in the keymap. */
5195 reorder_modifiers (symbol
)
5198 /* It's hopefully okay to write the code this way, since everything
5199 will soon be in caches, and no consing will be done at all. */
5202 parsed
= parse_modifiers (symbol
);
5203 return apply_modifiers ((int) XINT (XCAR (XCDR (parsed
))),
5208 /* For handling events, we often want to produce a symbol whose name
5209 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
5210 to some base, like the name of a function key or mouse button.
5211 modify_event_symbol produces symbols of this sort.
5213 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
5214 is the name of the i'th symbol. TABLE_SIZE is the number of elements
5217 Alternatively, NAME_ALIST is an alist mapping codes into symbol names.
5218 NAME_ALIST is used if it is non-nil; otherwise NAME_TABLE is used.
5220 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
5221 persist between calls to modify_event_symbol that it can use to
5222 store a cache of the symbols it's generated for this NAME_TABLE
5223 before. The object stored there may be a vector or an alist.
5225 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
5227 MODIFIERS is a set of modifier bits (as given in struct input_events)
5228 whose prefixes should be applied to the symbol name.
5230 SYMBOL_KIND is the value to be placed in the event_kind property of
5231 the returned symbol.
5233 The symbols we create are supposed to have an
5234 `event-symbol-elements' property, which lists the modifiers present
5235 in the symbol's name. */
5238 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_alist
,
5239 name_table
, symbol_table
, table_size
)
5242 Lisp_Object symbol_kind
;
5243 Lisp_Object name_alist
;
5245 Lisp_Object
*symbol_table
;
5246 unsigned int table_size
;
5249 Lisp_Object symbol_int
;
5251 /* Get rid of the "vendor-specific" bit here. */
5252 XSETINT (symbol_int
, symbol_num
& 0xffffff);
5254 /* Is this a request for a valid symbol? */
5255 if (symbol_num
< 0 || symbol_num
>= table_size
)
5258 if (CONSP (*symbol_table
))
5259 value
= Fcdr (assq_no_quit (symbol_int
, *symbol_table
));
5261 /* If *symbol_table doesn't seem to be initialized properly, fix that.
5262 *symbol_table should be a lisp vector TABLE_SIZE elements long,
5263 where the Nth element is the symbol for NAME_TABLE[N], or nil if
5264 we've never used that symbol before. */
5267 if (! VECTORP (*symbol_table
)
5268 || XVECTOR (*symbol_table
)->size
!= table_size
)
5272 XSETFASTINT (size
, table_size
);
5273 *symbol_table
= Fmake_vector (size
, Qnil
);
5276 value
= XVECTOR (*symbol_table
)->contents
[symbol_num
];
5279 /* Have we already used this symbol before? */
5282 /* No; let's create it. */
5283 if (!NILP (name_alist
))
5284 value
= Fcdr_safe (Fassq (symbol_int
, name_alist
));
5285 else if (name_table
!= 0 && name_table
[symbol_num
])
5286 value
= intern (name_table
[symbol_num
]);
5288 #ifdef HAVE_WINDOW_SYSTEM
5291 char *name
= x_get_keysym_name (symbol_num
);
5293 value
= intern (name
);
5300 sprintf (buf
, "key-%d", symbol_num
);
5301 value
= intern (buf
);
5304 if (CONSP (*symbol_table
))
5305 *symbol_table
= Fcons (Fcons (symbol_int
, value
), *symbol_table
);
5307 XVECTOR (*symbol_table
)->contents
[symbol_num
] = value
;
5309 /* Fill in the cache entries for this symbol; this also
5310 builds the Qevent_symbol_elements property, which the user
5312 apply_modifiers (modifiers
& click_modifier
, value
);
5313 Fput (value
, Qevent_kind
, symbol_kind
);
5316 /* Apply modifiers to that symbol. */
5317 return apply_modifiers (modifiers
, value
);
5320 /* Convert a list that represents an event type,
5321 such as (ctrl meta backspace), into the usual representation of that
5322 event type as a number or a symbol. */
5324 DEFUN ("event-convert-list", Fevent_convert_list
, Sevent_convert_list
, 1, 1, 0,
5325 "Convert the event description list EVENT-DESC to an event type.\n\
5326 EVENT-DESC should contain one base event type (a character or symbol)\n\
5327 and zero or more modifier names (control, meta, hyper, super, shift, alt,\n\
5328 drag, down, double or triple). The base must be last.\n\
5329 The return value is an event type (a character or symbol) which\n\
5330 has the same base event type and all the specified modifiers.")
5332 Lisp_Object event_desc
;
5340 while (CONSP (rest
))
5348 /* Given a symbol, see if it is a modifier name. */
5349 if (SYMBOLP (elt
) && CONSP (rest
))
5350 this = parse_solitary_modifier (elt
);
5354 else if (!NILP (base
))
5355 error ("Two bases given in one event");
5361 /* Let the symbol A refer to the character A. */
5362 if (SYMBOLP (base
) && XSYMBOL (base
)->name
->size
== 1)
5363 XSETINT (base
, XSYMBOL (base
)->name
->data
[0]);
5365 if (INTEGERP (base
))
5367 /* Turn (shift a) into A. */
5368 if ((modifiers
& shift_modifier
) != 0
5369 && (XINT (base
) >= 'a' && XINT (base
) <= 'z'))
5371 XSETINT (base
, XINT (base
) - ('a' - 'A'));
5372 modifiers
&= ~shift_modifier
;
5375 /* Turn (control a) into C-a. */
5376 if (modifiers
& ctrl_modifier
)
5377 return make_number ((modifiers
& ~ctrl_modifier
)
5378 | make_ctrl_char (XINT (base
)));
5380 return make_number (modifiers
| XINT (base
));
5382 else if (SYMBOLP (base
))
5383 return apply_modifiers (modifiers
, base
);
5385 error ("Invalid base event");
5388 /* Try to recognize SYMBOL as a modifier name.
5389 Return the modifier flag bit, or 0 if not recognized. */
5392 parse_solitary_modifier (symbol
)
5395 struct Lisp_String
*name
= XSYMBOL (symbol
)->name
;
5397 switch (name
->data
[0])
5399 #define SINGLE_LETTER_MOD(BIT) \
5400 if (STRING_BYTES (name) == 1) \
5403 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
5404 if (LEN == STRING_BYTES (name) \
5405 && ! strncmp (name->data, NAME, LEN)) \
5409 SINGLE_LETTER_MOD (alt_modifier
);
5413 MULTI_LETTER_MOD (alt_modifier
, "alt", 3);
5417 SINGLE_LETTER_MOD (ctrl_modifier
);
5421 MULTI_LETTER_MOD (ctrl_modifier
, "ctrl", 4);
5422 MULTI_LETTER_MOD (ctrl_modifier
, "control", 7);
5426 SINGLE_LETTER_MOD (hyper_modifier
);
5430 MULTI_LETTER_MOD (hyper_modifier
, "hyper", 5);
5434 SINGLE_LETTER_MOD (meta_modifier
);
5438 MULTI_LETTER_MOD (meta_modifier
, "meta", 4);
5442 SINGLE_LETTER_MOD (shift_modifier
);
5446 MULTI_LETTER_MOD (shift_modifier
, "shift", 5);
5447 MULTI_LETTER_MOD (super_modifier
, "super", 5);
5448 SINGLE_LETTER_MOD (super_modifier
);
5452 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
5453 MULTI_LETTER_MOD (down_modifier
, "down", 4);
5454 MULTI_LETTER_MOD (double_modifier
, "double", 6);
5458 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
5461 #undef SINGLE_LETTER_MOD
5462 #undef MULTI_LETTER_MOD
5468 /* Return 1 if EVENT is a list whose elements are all integers or symbols.
5469 Such a list is not valid as an event,
5470 but it can be a Lucid-style event type list. */
5473 lucid_event_type_list_p (object
)
5478 if (! CONSP (object
))
5481 for (tail
= object
; CONSP (tail
); tail
= XCDR (tail
))
5485 if (! (INTEGERP (elt
) || SYMBOLP (elt
)))
5492 /* Store into *addr a value nonzero if terminal input chars are available.
5493 Serves the purpose of ioctl (0, FIONREAD, addr)
5494 but works even if FIONREAD does not exist.
5495 (In fact, this may actually read some input.)
5497 If DO_TIMERS_NOW is nonzero, actually run timer events that are ripe. */
5500 get_input_pending (addr
, do_timers_now
)
5504 /* First of all, have we already counted some input? */
5505 *addr
= !NILP (Vquit_flag
) || readable_events (do_timers_now
);
5507 /* If input is being read as it arrives, and we have none, there is none. */
5508 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
5511 /* Try to read some input and see how much we get. */
5513 *addr
= !NILP (Vquit_flag
) || readable_events (do_timers_now
);
5516 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
5519 gobble_input (expected
)
5524 if (interrupt_input
)
5527 mask
= sigblock (sigmask (SIGIO
));
5528 read_avail_input (expected
);
5532 #ifdef POLL_FOR_INPUT
5533 if (read_socket_hook
&& !interrupt_input
&& poll_suppress_count
== 0)
5536 mask
= sigblock (sigmask (SIGALRM
));
5537 read_avail_input (expected
);
5543 read_avail_input (expected
);
5547 /* Put a buffer_switch_event in the buffer
5548 so that read_key_sequence will notice the new current buffer. */
5551 record_asynch_buffer_change ()
5553 struct input_event event
;
5556 event
.kind
= buffer_switch_event
;
5557 event
.frame_or_window
= Qnil
;
5560 /* We don't need a buffer-switch event unless Emacs is waiting for input.
5561 The purpose of the event is to make read_key_sequence look up the
5562 keymaps again. If we aren't in read_key_sequence, we don't need one,
5563 and the event could cause trouble by messing up (input-pending-p). */
5564 tem
= Fwaiting_for_user_input_p ();
5568 /* We never need these events if we have no asynchronous subprocesses. */
5572 /* Make sure no interrupt happens while storing the event. */
5574 if (interrupt_input
)
5577 mask
= sigblock (sigmask (SIGIO
));
5578 kbd_buffer_store_event (&event
);
5585 kbd_buffer_store_event (&event
);
5592 /* Read any terminal input already buffered up by the system
5593 into the kbd_buffer, but do not wait.
5595 EXPECTED should be nonzero if the caller knows there is some input.
5597 Except on VMS, all input is read by this function.
5598 If interrupt_input is nonzero, this function MUST be called
5599 only when SIGIO is blocked.
5601 Returns the number of keyboard chars read, or -1 meaning
5602 this is a bad time to try to read input. */
5605 read_avail_input (expected
)
5608 struct input_event buf
[KBD_BUFFER_SIZE
];
5612 if (read_socket_hook
)
5613 /* No need for FIONREAD or fcntl; just say don't wait. */
5614 nread
= (*read_socket_hook
) (input_fd
, buf
, KBD_BUFFER_SIZE
, expected
);
5617 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
5618 the kbd_buffer can really hold. That may prevent loss
5619 of characters on some systems when input is stuffed at us. */
5620 unsigned char cbuf
[KBD_BUFFER_SIZE
- 1];
5623 /* Determine how many characters we should *try* to read. */
5626 #else /* not WINDOWSNT */
5628 n_to_read
= dos_keysns ();
5631 #else /* not MSDOS */
5633 /* Find out how much input is available. */
5634 if (ioctl (input_fd
, FIONREAD
, &n_to_read
) < 0)
5635 /* Formerly simply reported no input, but that sometimes led to
5636 a failure of Emacs to terminate.
5637 SIGHUP seems appropriate if we can't reach the terminal. */
5638 /* ??? Is it really right to send the signal just to this process
5639 rather than to the whole process group?
5640 Perhaps on systems with FIONREAD Emacs is alone in its group. */
5641 kill (getpid (), SIGHUP
);
5644 if (n_to_read
> sizeof cbuf
)
5645 n_to_read
= sizeof cbuf
;
5646 #else /* no FIONREAD */
5647 #if defined (USG) || defined (DGUX)
5648 /* Read some input if available, but don't wait. */
5649 n_to_read
= sizeof cbuf
;
5650 fcntl (input_fd
, F_SETFL
, O_NDELAY
);
5655 #endif /* not MSDOS */
5656 #endif /* not WINDOWSNT */
5658 /* Now read; for one reason or another, this will not block.
5659 NREAD is set to the number of chars read. */
5663 cbuf
[0] = dos_keyread ();
5666 nread
= emacs_read (input_fd
, cbuf
, n_to_read
);
5668 /* POSIX infers that processes which are not in the session leader's
5669 process group won't get SIGHUP's at logout time. BSDI adheres to
5670 this part standard and returns -1 from read (0) with errno==EIO
5671 when the control tty is taken away.
5672 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
5673 if (nread
== -1 && errno
== EIO
)
5675 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
5676 /* The kernel sometimes fails to deliver SIGHUP for ptys.
5677 This looks incorrect, but it isn't, because _BSD causes
5678 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
5679 and that causes a value other than 0 when there is no input. */
5685 /* We used to retry the read if it was interrupted.
5686 But this does the wrong thing when O_NDELAY causes
5687 an EAGAIN error. Does anybody know of a situation
5688 where a retry is actually needed? */
5690 nread
< 0 && (errno
== EAGAIN
5704 #if defined (USG) || defined (DGUX)
5705 fcntl (input_fd
, F_SETFL
, 0);
5706 #endif /* USG or DGUX */
5707 #endif /* no FIONREAD */
5708 for (i
= 0; i
< nread
; i
++)
5710 buf
[i
].kind
= ascii_keystroke
;
5711 buf
[i
].modifiers
= 0;
5712 if (meta_key
== 1 && (cbuf
[i
] & 0x80))
5713 buf
[i
].modifiers
= meta_modifier
;
5717 buf
[i
].code
= cbuf
[i
];
5718 buf
[i
].frame_or_window
= selected_frame
;
5722 /* Scan the chars for C-g and store them in kbd_buffer. */
5723 for (i
= 0; i
< nread
; i
++)
5725 kbd_buffer_store_event (&buf
[i
]);
5726 /* Don't look at input that follows a C-g too closely.
5727 This reduces lossage due to autorepeat on C-g. */
5728 if (buf
[i
].kind
== ascii_keystroke
5729 && buf
[i
].code
== quit_char
)
5735 #endif /* not VMS */
5737 #ifdef SIGIO /* for entire page */
5738 /* Note SIGIO has been undef'd if FIONREAD is missing. */
5741 input_available_signal (signo
)
5744 /* Must preserve main program's value of errno. */
5745 int old_errno
= errno
;
5747 extern int select_alarmed
;
5750 #if defined (USG) && !defined (POSIX_SIGNALS)
5751 /* USG systems forget handlers when they are used;
5752 must reestablish each time */
5753 signal (signo
, input_available_signal
);
5760 if (input_available_clear_time
)
5761 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
5766 nread
= read_avail_input (1);
5767 /* -1 means it's not ok to read the input now.
5768 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
5769 0 means there was no keyboard input available. */
5774 select_alarmed
= 1; /* Force the select emulator back to life */
5785 /* Send ourselves a SIGIO.
5787 This function exists so that the UNBLOCK_INPUT macro in
5788 blockinput.h can have some way to take care of input we put off
5789 dealing with, without assuming that every file which uses
5790 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
5792 reinvoke_input_signal ()
5795 kill (getpid (), SIGIO
);
5801 /* Return the prompt-string of a sparse keymap.
5802 This is the first element which is a string.
5803 Return nil if there is none. */
5811 register Lisp_Object tem
;
5820 static void menu_bar_item ();
5821 static void menu_bar_one_keymap ();
5823 /* These variables hold the vector under construction within
5824 menu_bar_items and its subroutines, and the current index
5825 for storing into that vector. */
5826 static Lisp_Object menu_bar_items_vector
;
5827 static int menu_bar_items_index
;
5829 /* Return a vector of menu items for a menu bar, appropriate
5830 to the current buffer. Each item has three elements in the vector:
5833 OLD is an old vector we can optionally reuse, or nil. */
5836 menu_bar_items (old
)
5839 /* The number of keymaps we're scanning right now, and the number of
5840 keymaps we have allocated space for. */
5843 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
5844 in the current keymaps, or nil where it is not a prefix. */
5847 Lisp_Object def
, tem
, tail
;
5856 struct gcpro gcpro1
;
5858 /* In order to build the menus, we need to call the keymap
5859 accessors. They all call QUIT. But this function is called
5860 during redisplay, during which a quit is fatal. So inhibit
5861 quitting while building the menus.
5862 We do this instead of specbind because (1) errors will clear it anyway
5863 and (2) this avoids risk of specpdl overflow. */
5864 oquit
= Vinhibit_quit
;
5868 menu_bar_items_vector
= old
;
5870 menu_bar_items_vector
= Fmake_vector (make_number (24), Qnil
);
5871 menu_bar_items_index
= 0;
5873 GCPRO1 (menu_bar_items_vector
);
5875 /* Build our list of keymaps.
5876 If we recognize a function key and replace its escape sequence in
5877 keybuf with its symbol, or if the sequence starts with a mouse
5878 click and we need to switch buffers, we jump back here to rebuild
5879 the initial keymaps from the current buffer. */
5883 /* Should overriding-terminal-local-map and overriding-local-map apply? */
5884 if (!NILP (Voverriding_local_map_menu_flag
))
5886 /* Yes, use them (if non-nil) as well as the global map. */
5887 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
5889 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
5890 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
5891 if (!NILP (Voverriding_local_map
))
5892 maps
[nmaps
++] = Voverriding_local_map
;
5896 /* No, so use major and minor mode keymaps. */
5897 nmaps
= current_minor_maps (NULL
, &tmaps
);
5898 maps
= (Lisp_Object
*) alloca ((nmaps
+ 2) * sizeof (maps
[0]));
5899 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
5900 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
5902 maps
[nmaps
++] = current_global_map
;
5905 /* Look up in each map the dummy prefix key `menu-bar'. */
5909 for (mapno
= nmaps
- 1; mapno
>= 0; mapno
--)
5911 if (! NILP (maps
[mapno
]))
5912 def
= get_keyelt (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0), 0);
5916 tem
= Fkeymapp (def
);
5918 menu_bar_one_keymap (def
);
5921 /* Move to the end those items that should be at the end. */
5923 for (tail
= Vmenu_bar_final_items
; CONSP (tail
); tail
= XCDR (tail
))
5926 int end
= menu_bar_items_index
;
5928 for (i
= 0; i
< end
; i
+= 4)
5929 if (EQ (XCAR (tail
), XVECTOR (menu_bar_items_vector
)->contents
[i
]))
5931 Lisp_Object tem0
, tem1
, tem2
, tem3
;
5932 /* Move the item at index I to the end,
5933 shifting all the others forward. */
5934 tem0
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 0];
5935 tem1
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 1];
5936 tem2
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
5937 tem3
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3];
5939 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
5940 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
5941 (end
- i
- 4) * sizeof (Lisp_Object
));
5942 XVECTOR (menu_bar_items_vector
)->contents
[end
- 4] = tem0
;
5943 XVECTOR (menu_bar_items_vector
)->contents
[end
- 3] = tem1
;
5944 XVECTOR (menu_bar_items_vector
)->contents
[end
- 2] = tem2
;
5945 XVECTOR (menu_bar_items_vector
)->contents
[end
- 1] = tem3
;
5950 /* Add nil, nil, nil, nil at the end. */
5951 i
= menu_bar_items_index
;
5952 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
5955 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
5956 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
5957 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
5958 menu_bar_items_vector
= tem
;
5960 /* Add this item. */
5961 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5962 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5963 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5964 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5965 menu_bar_items_index
= i
;
5967 Vinhibit_quit
= oquit
;
5969 return menu_bar_items_vector
;
5972 /* Scan one map KEYMAP, accumulating any menu items it defines
5973 in menu_bar_items_vector. */
5975 static Lisp_Object menu_bar_one_keymap_changed_items
;
5978 menu_bar_one_keymap (keymap
)
5981 Lisp_Object tail
, item
;
5983 menu_bar_one_keymap_changed_items
= Qnil
;
5985 /* Loop over all keymap entries that have menu strings. */
5986 for (tail
= keymap
; CONSP (tail
); tail
= XCDR (tail
))
5990 menu_bar_item (XCAR (item
), XCDR (item
));
5991 else if (VECTORP (item
))
5993 /* Loop over the char values represented in the vector. */
5994 int len
= XVECTOR (item
)->size
;
5996 for (c
= 0; c
< len
; c
++)
5998 Lisp_Object character
;
5999 XSETFASTINT (character
, c
);
6000 menu_bar_item (character
, XVECTOR (item
)->contents
[c
]);
6006 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
6007 If there's already an item for KEY, add this DEF to it. */
6009 Lisp_Object item_properties
;
6012 menu_bar_item (key
, item
)
6013 Lisp_Object key
, item
;
6015 struct gcpro gcpro1
;
6019 if (EQ (item
, Qundefined
))
6021 /* If a map has an explicit `undefined' as definition,
6022 discard any previously made menu bar item. */
6024 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
6025 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
6027 if (menu_bar_items_index
> i
+ 4)
6028 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
6029 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
6030 (menu_bar_items_index
- i
- 4) * sizeof (Lisp_Object
));
6031 menu_bar_items_index
-= 4;
6035 /* If there's no definition for this key yet,
6036 just ignore `undefined'. */
6040 GCPRO1 (key
); /* Is this necessary? */
6041 i
= parse_menu_item (item
, 0, 1);
6046 /* If this keymap has already contributed to this KEY,
6047 don't contribute to it a second time. */
6048 tem
= Fmemq (key
, menu_bar_one_keymap_changed_items
);
6052 menu_bar_one_keymap_changed_items
6053 = Fcons (key
, menu_bar_one_keymap_changed_items
);
6055 item
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
6057 /* Find any existing item for this KEY. */
6058 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
6059 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
6062 /* If we did not find this KEY, add it at the end. */
6063 if (i
== menu_bar_items_index
)
6065 /* If vector is too small, get a bigger one. */
6066 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
6069 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
6070 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
6071 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
6072 menu_bar_items_vector
= tem
;
6075 /* Add this item. */
6076 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = key
;
6077 XVECTOR (menu_bar_items_vector
)->contents
[i
++]
6078 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
6079 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Fcons (item
, Qnil
);
6080 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = make_number (0);
6081 menu_bar_items_index
= i
;
6083 /* We did find an item for this KEY. Add ITEM to its list of maps. */
6087 old
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
6088 XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2] = Fcons (item
, old
);
6092 /* This is used as the handler when calling menu_item_eval_property. */
6094 menu_item_eval_property_1 (arg
)
6097 /* If we got a quit from within the menu computation,
6098 quit all the way out of it. This takes care of C-] in the debugger. */
6099 if (CONSP (arg
) && EQ (XCAR (arg
), Qquit
))
6100 Fsignal (Qquit
, Qnil
);
6105 /* Evaluate an expression and return the result (or nil if something
6106 went wrong). Used to evaluate dynamic parts of menu items. */
6108 menu_item_eval_property (sexpr
)
6111 int count
= specpdl_ptr
- specpdl
;
6113 specbind (Qinhibit_redisplay
, Qt
);
6114 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
,
6115 menu_item_eval_property_1
);
6116 return unbind_to (count
, val
);
6119 /* This function parses a menu item and leaves the result in the
6120 vector item_properties.
6121 ITEM is a key binding, a possible menu item.
6122 If NOTREAL is nonzero, only check for equivalent key bindings, don't
6123 evaluate dynamic expressions in the menu item.
6124 INMENUBAR is > 0 when this is considered for an entry in a menu bar
6126 INMENUBAR is < 0 when this is considered for an entry in a keyboard menu.
6127 parse_menu_item returns true if the item is a menu item and false
6131 parse_menu_item (item
, notreal
, inmenubar
)
6133 int notreal
, inmenubar
;
6135 Lisp_Object def
, tem
, item_string
, start
;
6136 Lisp_Object cachelist
;
6138 Lisp_Object keyhint
;
6149 /* Create item_properties vector if necessary. */
6150 if (NILP (item_properties
))
6152 = Fmake_vector (make_number (ITEM_PROPERTY_ENABLE
+ 1), Qnil
);
6154 /* Initialize optional entries. */
6155 for (i
= ITEM_PROPERTY_DEF
; i
< ITEM_PROPERTY_ENABLE
; i
++)
6156 XVECTOR (item_properties
)->contents
[i
] = Qnil
;
6157 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
] = Qt
;
6159 /* Save the item here to protect it from GC. */
6160 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ITEM
] = item
;
6162 item_string
= XCAR (item
);
6166 if (STRINGP (item_string
))
6168 /* Old format menu item. */
6169 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
] = item_string
;
6171 /* Maybe help string. */
6172 if (CONSP (item
) && STRINGP (XCAR (item
)))
6174 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_HELP
]
6180 /* Maybee key binding cache. */
6181 if (CONSP (item
) && CONSP (XCAR (item
))
6182 && (NILP (XCAR (XCAR (item
)))
6183 || VECTORP (XCAR (XCAR (item
)))))
6185 cachelist
= XCAR (item
);
6189 /* This is the real definition--the function to run. */
6190 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
] = item
;
6192 /* Get enable property, if any. */
6195 tem
= Fget (item
, Qmenu_enable
);
6197 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
] = tem
;
6200 else if (EQ (item_string
, Qmenu_item
) && CONSP (item
))
6202 /* New format menu item. */
6203 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
]
6205 start
= XCDR (item
);
6208 /* We have a real binding. */
6209 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
]
6212 item
= XCDR (start
);
6213 /* Is there a cache list with key equivalences. */
6214 if (CONSP (item
) && CONSP (XCAR (item
)))
6216 cachelist
= XCAR (item
);
6220 /* Parse properties. */
6221 while (CONSP (item
) && CONSP (XCDR (item
)))
6226 if (EQ (tem
, QCenable
))
6227 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
]
6229 else if (EQ (tem
, QCvisible
) && !notreal
)
6231 /* If got a visible property and that evaluates to nil
6232 then ignore this item. */
6233 tem
= menu_item_eval_property (XCAR (item
));
6237 else if (EQ (tem
, QChelp
))
6238 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_HELP
]
6240 else if (EQ (tem
, QCfilter
))
6242 else if (EQ (tem
, QCkey_sequence
))
6245 if (NILP (cachelist
)
6246 && (SYMBOLP (tem
) || STRINGP (tem
) || VECTORP (tem
)))
6247 /* Be GC protected. Set keyhint to item instead of tem. */
6250 else if (EQ (tem
, QCkeys
))
6253 if (CONSP (tem
) || (STRINGP (tem
) && NILP (cachelist
)))
6254 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
]
6257 else if (EQ (tem
, QCbutton
) && CONSP (XCAR (item
)))
6262 if (EQ (type
, QCtoggle
) || EQ (type
, QCradio
))
6264 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
]
6266 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_TYPE
]
6273 else if (inmenubar
|| !NILP (start
))
6277 return 0; /* not a menu item */
6279 /* If item string is not a string, evaluate it to get string.
6280 If we don't get a string, skip this item. */
6281 item_string
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
6282 if (!(STRINGP (item_string
) || notreal
))
6284 item_string
= menu_item_eval_property (item_string
);
6285 if (!STRINGP (item_string
))
6287 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
] = item_string
;
6290 /* If got a filter apply it on definition. */
6291 def
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
6294 def
= menu_item_eval_property (list2 (XCAR (filter
),
6295 list2 (Qquote
, def
)));
6297 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
] = def
;
6300 /* If we got no definition, this item is just unselectable text which
6301 is OK in a submenu but not in the menubar. */
6303 return (inmenubar
? 0 : 1);
6305 /* Enable or disable selection of item. */
6306 tem
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
];
6312 tem
= menu_item_eval_property (tem
);
6313 if (inmenubar
&& NILP (tem
))
6314 return 0; /* Ignore disabled items in menu bar. */
6315 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
] = tem
;
6318 /* See if this is a separate pane or a submenu. */
6319 def
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
6320 tem
= get_keymap_1 (def
, 0, 1);
6321 /* For a subkeymap, just record its details and exit. */
6324 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_MAP
] = tem
;
6325 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
] = tem
;
6328 /* At the top level in the menu bar, do likewise for commands also.
6329 The menu bar does not display equivalent key bindings anyway.
6330 ITEM_PROPERTY_DEF is already set up properly. */
6334 /* This is a command. See if there is an equivalent key binding. */
6335 if (NILP (cachelist
))
6337 /* We have to create a cachelist. */
6338 CHECK_IMPURE (start
);
6339 XCDR (start
) = Fcons (Fcons (Qnil
, Qnil
), XCDR (start
));
6340 cachelist
= XCAR (XCDR (start
));
6342 tem
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
6343 if (!NILP (keyhint
))
6345 XCAR (cachelist
) = XCAR (keyhint
);
6348 else if (STRINGP (tem
))
6350 XCDR (cachelist
) = Fsubstitute_command_keys (tem
);
6351 XCAR (cachelist
) = Qt
;
6354 tem
= XCAR (cachelist
);
6361 tem
= Fkey_binding (tem
, Qnil
);
6363 prefix
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
6366 def
= XCAR (prefix
);
6367 prefix
= XCDR (prefix
);
6370 def
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
6372 if (NILP (XCAR (cachelist
))) /* Have no saved key. */
6374 if (newcache
/* Always check first time. */
6375 /* Should we check everything when precomputing key
6378 /* If something had no key binding before, don't recheck it
6379 because that is too slow--except if we have a list of
6380 rebound commands in Vdefine_key_rebound_commands, do
6381 recheck any command that appears in that list. */
6382 || (CONSP (Vdefine_key_rebound_commands
)
6383 && !NILP (Fmemq (def
, Vdefine_key_rebound_commands
))))
6386 /* We had a saved key. Is it still bound to the command? */
6389 /* If the command is an alias for another
6390 (such as lmenu.el set it up), check if the
6391 original command matches the cached command. */
6392 && !(SYMBOLP (def
) && EQ (tem
, XSYMBOL (def
)->function
))))
6393 chkcache
= 1; /* Need to recompute key binding. */
6397 /* Recompute equivalent key binding. If the command is an alias
6398 for another (such as lmenu.el set it up), see if the original
6399 command name has equivalent keys. Otherwise look up the
6400 specified command itself. We don't try both, because that
6401 makes lmenu menus slow. */
6402 if (SYMBOLP (def
) && SYMBOLP (XSYMBOL (def
)->function
)
6403 && ! NILP (Fget (def
, Qmenu_alias
)))
6404 def
= XSYMBOL (def
)->function
;
6405 tem
= Fwhere_is_internal (def
, Qnil
, Qt
, Qnil
);
6406 XCAR (cachelist
) = tem
;
6409 XCDR (cachelist
) = Qnil
;
6413 else if (!NILP (keyhint
) && !NILP (XCAR (cachelist
)))
6415 tem
= XCAR (cachelist
);
6419 newcache
= chkcache
;
6422 tem
= Fkey_description (tem
);
6425 if (STRINGP (XCAR (prefix
)))
6426 tem
= concat2 (XCAR (prefix
), tem
);
6427 if (STRINGP (XCDR (prefix
)))
6428 tem
= concat2 (tem
, XCDR (prefix
));
6430 XCDR (cachelist
) = tem
;
6434 tem
= XCDR (cachelist
);
6435 if (newcache
&& !NILP (tem
))
6437 tem
= concat3 (build_string (" ("), tem
, build_string (")"));
6438 XCDR (cachelist
) = tem
;
6441 /* If we only want to precompute equivalent key bindings, stop here. */
6445 /* If we have an equivalent key binding, use that. */
6446 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
] = tem
;
6448 /* Include this when menu help is implemented.
6449 tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP];
6450 if (!(NILP (tem) || STRINGP (tem)))
6452 tem = menu_item_eval_property (tem);
6455 XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP] = tem;
6459 /* Handle radio buttons or toggle boxes. */
6460 tem
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
];
6462 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
]
6463 = menu_item_eval_property (tem
);
6470 /***********************************************************************
6472 ***********************************************************************/
6474 /* A vector holding tool bar items while they are parsed in function
6475 tool_bar_items runs Each item occupies TOOL_BAR_ITEM_NSCLOTS elements
6478 static Lisp_Object tool_bar_items_vector
;
6480 /* A vector holding the result of parse_tool_bar_item. Layout is like
6481 the one for a single item in tool_bar_items_vector. */
6483 static Lisp_Object tool_bar_item_properties
;
6485 /* Next free index in tool_bar_items_vector. */
6487 static int ntool_bar_items
;
6489 /* The symbols `tool-bar', and `:image'. */
6491 extern Lisp_Object Qtool_bar
;
6492 Lisp_Object QCimage
;
6494 /* Function prototypes. */
6496 static void init_tool_bar_items
P_ ((Lisp_Object
));
6497 static void process_tool_bar_item
P_ ((Lisp_Object
, Lisp_Object
));
6498 static int parse_tool_bar_item
P_ ((Lisp_Object
, Lisp_Object
));
6499 static void append_tool_bar_item
P_ ((void));
6502 /* Return a vector of tool bar items for keymaps currently in effect.
6503 Reuse vector REUSE if non-nil. Return in *NITEMS the number of
6504 tool bar items found. */
6507 tool_bar_items (reuse
, nitems
)
6515 extern Lisp_Object Voverriding_local_map_menu_flag
;
6516 extern Lisp_Object Voverriding_local_map
;
6520 /* In order to build the menus, we need to call the keymap
6521 accessors. They all call QUIT. But this function is called
6522 during redisplay, during which a quit is fatal. So inhibit
6523 quitting while building the menus. We do this instead of
6524 specbind because (1) errors will clear it anyway and (2) this
6525 avoids risk of specpdl overflow. */
6526 oquit
= Vinhibit_quit
;
6529 /* Initialize tool_bar_items_vector and protect it from GC. */
6530 init_tool_bar_items (reuse
);
6532 /* Build list of keymaps in maps. Set nmaps to the number of maps
6535 /* Should overriding-terminal-local-map and overriding-local-map apply? */
6536 if (!NILP (Voverriding_local_map_menu_flag
))
6538 /* Yes, use them (if non-nil) as well as the global map. */
6539 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
6541 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
6542 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
6543 if (!NILP (Voverriding_local_map
))
6544 maps
[nmaps
++] = Voverriding_local_map
;
6548 /* No, so use major and minor mode keymaps. */
6549 nmaps
= current_minor_maps (NULL
, &tmaps
);
6550 maps
= (Lisp_Object
*) alloca ((nmaps
+ 2) * sizeof (maps
[0]));
6551 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
6552 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
6555 /* Add global keymap at the end. */
6556 maps
[nmaps
++] = current_global_map
;
6558 /* Process maps in reverse order and look up in each map the prefix
6560 for (i
= nmaps
- 1; i
>= 0; --i
)
6561 if (!NILP (maps
[i
]))
6565 keymap
= get_keyelt (access_keymap (maps
[i
], Qtool_bar
, 1, 1), 0);
6566 if (!NILP (Fkeymapp (keymap
)))
6570 /* KEYMAP is a list `(keymap (KEY . BINDING) ...)'. */
6571 for (tail
= keymap
; CONSP (tail
); tail
= XCDR (tail
))
6573 Lisp_Object keydef
= XCAR (tail
);
6575 process_tool_bar_item (XCAR (keydef
), XCDR (keydef
));
6580 Vinhibit_quit
= oquit
;
6581 *nitems
= ntool_bar_items
/ TOOL_BAR_ITEM_NSLOTS
;
6582 return tool_bar_items_vector
;
6586 /* Process the definition of KEY which is DEF. */
6589 process_tool_bar_item (key
, def
)
6590 Lisp_Object key
, def
;
6593 extern Lisp_Object Qundefined
;
6594 struct gcpro gcpro1
, gcpro2
;
6596 /* Protect KEY and DEF from GC because parse_tool_bar_item may call
6600 if (EQ (def
, Qundefined
))
6602 /* If a map has an explicit `undefined' as definition,
6603 discard any previously made item. */
6604 for (i
= 0; i
< ntool_bar_items
; i
+= TOOL_BAR_ITEM_NSLOTS
)
6606 Lisp_Object
*v
= XVECTOR (tool_bar_items_vector
)->contents
+ i
;
6608 if (EQ (key
, v
[TOOL_BAR_ITEM_KEY
]))
6610 if (ntool_bar_items
> i
+ TOOL_BAR_ITEM_NSLOTS
)
6611 bcopy (v
+ TOOL_BAR_ITEM_NSLOTS
, v
,
6612 ((ntool_bar_items
- i
- TOOL_BAR_ITEM_NSLOTS
)
6613 * sizeof (Lisp_Object
)));
6614 ntool_bar_items
-= TOOL_BAR_ITEM_NSLOTS
;
6619 else if (parse_tool_bar_item (key
, def
))
6620 /* Append a new tool bar item to tool_bar_items_vector. Accept
6621 more than one definition for the same key. */
6622 append_tool_bar_item ();
6628 /* Parse a tool bar item specification ITEM for key KEY and return the
6629 result in tool_bar_item_properties. Value is zero if ITEM is
6632 ITEM is a list `(menu-item CAPTION BINDING PROPS...)'.
6634 CAPTION is the caption of the item, If it's not a string, it is
6635 evaluated to get a string.
6637 BINDING is the tool bar item's binding. Tool-bar items with keymaps
6638 as binding are currently ignored.
6640 The following properties are recognized:
6644 FORM is evaluated and specifies whether the tool bar item is
6645 enabled or disabled.
6649 FORM is evaluated and specifies whether the tool bar item is visible.
6651 - `:filter FUNCTION'
6653 FUNCTION is invoked with one parameter `(quote BINDING)'. Its
6654 result is stored as the new binding.
6656 - `:button (TYPE SELECTED)'
6658 TYPE must be one of `:radio' or `:toggle'. SELECTED is evaluated
6659 and specifies whether the button is selected (pressed) or not.
6663 IMAGES is either a single image specification or a vector of four
6664 image specifications. See enum tool_bar_item_images.
6666 - `:help HELP-STRING'.
6668 Gives a help string to display for the tool bar item. */
6671 parse_tool_bar_item (key
, item
)
6672 Lisp_Object key
, item
;
6674 /* Access slot with index IDX of vector tool_bar_item_properties. */
6675 #define PROP(IDX) XVECTOR (tool_bar_item_properties)->contents[IDX]
6677 Lisp_Object filter
= Qnil
;
6678 Lisp_Object caption
;
6679 extern Lisp_Object QCenable
, QCvisible
, QChelp
, QCfilter
;
6680 extern Lisp_Object QCbutton
, QCtoggle
, QCradio
;
6683 /* Defininition looks like `(tool-bar-item CAPTION BINDING
6684 PROPS...)'. Rule out items that aren't lists, don't start with
6685 `tool-bar-item' or whose rest following `tool-bar-item' is not a
6688 || !EQ (XCAR (item
), Qmenu_item
)
6689 || (item
= XCDR (item
),
6693 /* Create tool_bar_item_properties vector if necessary. Reset it to
6695 if (VECTORP (tool_bar_item_properties
))
6697 for (i
= 0; i
< TOOL_BAR_ITEM_NSLOTS
; ++i
)
6701 tool_bar_item_properties
6702 = Fmake_vector (make_number (TOOL_BAR_ITEM_NSLOTS
), Qnil
);
6705 PROP (TOOL_BAR_ITEM_KEY
) = key
;
6706 PROP (TOOL_BAR_ITEM_ENABLED_P
) = Qt
;
6708 /* Get the caption of the item. If the caption is not a string,
6709 evaluate it to get a string. If we don't get a string, skip this
6711 caption
= XCAR (item
);
6712 if (!STRINGP (caption
))
6714 caption
= menu_item_eval_property (caption
);
6715 if (!STRINGP (caption
))
6718 PROP (TOOL_BAR_ITEM_CAPTION
) = caption
;
6720 /* Give up if rest following the caption is not a list. */
6725 /* Store the binding. */
6726 PROP (TOOL_BAR_ITEM_BINDING
) = XCAR (item
);
6729 /* Process the rest of the properties. */
6730 for (; CONSP (item
) && CONSP (XCDR (item
)); item
= XCDR (XCDR (item
)))
6732 Lisp_Object key
, value
;
6735 value
= XCAR (XCDR (item
));
6737 if (EQ (key
, QCenable
))
6738 /* `:enable FORM'. */
6739 PROP (TOOL_BAR_ITEM_ENABLED_P
) = value
;
6740 else if (EQ (key
, QCvisible
))
6742 /* `:visible FORM'. If got a visible property and that
6743 evaluates to nil then ignore this item. */
6744 if (NILP (menu_item_eval_property (value
)))
6747 else if (EQ (key
, QChelp
))
6748 /* `:help HELP-STRING'. */
6749 PROP (TOOL_BAR_ITEM_HELP
) = value
;
6750 else if (EQ (key
, QCfilter
))
6751 /* ':filter FORM'. */
6753 else if (EQ (key
, QCbutton
) && CONSP (value
))
6755 /* `:button (TYPE . SELECTED)'. */
6756 Lisp_Object type
, selected
;
6758 type
= XCAR (value
);
6759 selected
= XCDR (value
);
6760 if (EQ (type
, QCtoggle
) || EQ (type
, QCradio
))
6762 PROP (TOOL_BAR_ITEM_SELECTED_P
) = selected
;
6763 PROP (TOOL_BAR_ITEM_TYPE
) = type
;
6766 else if (EQ (key
, QCimage
)
6768 || (VECTORP (value
) && XVECTOR (value
)->size
== 4)))
6769 /* Value is either a single image specification or a vector
6770 of 4 such specifications for the different buttion states. */
6771 PROP (TOOL_BAR_ITEM_IMAGES
) = value
;
6774 /* If got a filter apply it on binding. */
6776 PROP (TOOL_BAR_ITEM_BINDING
)
6777 = menu_item_eval_property (list2 (filter
,
6779 PROP (TOOL_BAR_ITEM_BINDING
))));
6781 /* See if the binding is a keymap. Give up if it is. */
6782 if (!NILP (get_keymap_1 (PROP (TOOL_BAR_ITEM_BINDING
), 0, 1)))
6785 /* Enable or disable selection of item. */
6786 if (!EQ (PROP (TOOL_BAR_ITEM_ENABLED_P
), Qt
))
6787 PROP (TOOL_BAR_ITEM_ENABLED_P
)
6788 = menu_item_eval_property (PROP (TOOL_BAR_ITEM_ENABLED_P
));
6790 /* Handle radio buttons or toggle boxes. */
6791 if (!NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
)))
6792 PROP (TOOL_BAR_ITEM_SELECTED_P
)
6793 = menu_item_eval_property (PROP (TOOL_BAR_ITEM_SELECTED_P
));
6801 /* Initialize tool_bar_items_vector. REUSE, if non-nil, is a vector
6802 that can be reused. */
6805 init_tool_bar_items (reuse
)
6808 if (VECTORP (reuse
))
6809 tool_bar_items_vector
= reuse
;
6811 tool_bar_items_vector
= Fmake_vector (make_number (64), Qnil
);
6812 ntool_bar_items
= 0;
6816 /* Append parsed tool bar item properties from
6817 tool_bar_item_properties */
6820 append_tool_bar_item ()
6822 Lisp_Object
*to
, *from
;
6824 /* Enlarge tool_bar_items_vector if necessary. */
6825 if (ntool_bar_items
+ TOOL_BAR_ITEM_NSLOTS
6826 >= XVECTOR (tool_bar_items_vector
)->size
)
6828 Lisp_Object new_vector
;
6829 int old_size
= XVECTOR (tool_bar_items_vector
)->size
;
6831 new_vector
= Fmake_vector (make_number (2 * old_size
), Qnil
);
6832 bcopy (XVECTOR (tool_bar_items_vector
)->contents
,
6833 XVECTOR (new_vector
)->contents
,
6834 old_size
* sizeof (Lisp_Object
));
6835 tool_bar_items_vector
= new_vector
;
6838 /* Append entries from tool_bar_item_properties to the end of
6839 tool_bar_items_vector. */
6840 to
= XVECTOR (tool_bar_items_vector
)->contents
+ ntool_bar_items
;
6841 from
= XVECTOR (tool_bar_item_properties
)->contents
;
6842 bcopy (from
, to
, TOOL_BAR_ITEM_NSLOTS
* sizeof *to
);
6843 ntool_bar_items
+= TOOL_BAR_ITEM_NSLOTS
;
6850 /* Read a character using menus based on maps in the array MAPS.
6851 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
6852 Return t if we displayed a menu but the user rejected it.
6854 PREV_EVENT is the previous input event, or nil if we are reading
6855 the first event of a key sequence.
6857 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
6858 if we used a mouse menu to read the input, or zero otherwise. If
6859 USED_MOUSE_MENU is null, we don't dereference it.
6861 The prompting is done based on the prompt-string of the map
6862 and the strings associated with various map elements.
6864 This can be done with X menus or with menus put in the minibuf.
6865 These are done in different ways, depending on how the input will be read.
6866 Menus using X are done after auto-saving in read-char, getting the input
6867 event from Fx_popup_menu; menus using the minibuf use read_char recursively
6868 and do auto-saving in the inner call of read_char. */
6871 read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
6874 Lisp_Object prev_event
;
6875 int *used_mouse_menu
;
6878 register Lisp_Object name
;
6880 if (used_mouse_menu
)
6881 *used_mouse_menu
= 0;
6883 /* Use local over global Menu maps */
6885 if (! menu_prompting
)
6888 /* Optionally disregard all but the global map. */
6889 if (inhibit_local_menu_bar_menus
)
6891 maps
+= (nmaps
- 1);
6895 /* Get the menu name from the first map that has one (a prompt string). */
6896 for (mapno
= 0; mapno
< nmaps
; mapno
++)
6898 name
= map_prompt (maps
[mapno
]);
6903 /* If we don't have any menus, just read a character normally. */
6908 /* If we got to this point via a mouse click,
6909 use a real menu for mouse selection. */
6910 if (EVENT_HAS_PARAMETERS (prev_event
)
6911 && !EQ (XCAR (prev_event
), Qmenu_bar
)
6912 && !EQ (XCAR (prev_event
), Qtool_bar
))
6914 /* Display the menu and get the selection. */
6915 Lisp_Object
*realmaps
6916 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
6920 /* Use the maps that are not nil. */
6921 for (mapno
= 0; mapno
< nmaps
; mapno
++)
6922 if (!NILP (maps
[mapno
]))
6923 realmaps
[nmaps1
++] = maps
[mapno
];
6925 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
6930 record_menu_key (XCAR (value
));
6932 /* If we got multiple events, unread all but
6934 There is no way to prevent those unread events
6935 from showing up later in last_nonmenu_event.
6936 So turn symbol and integer events into lists,
6937 to indicate that they came from a mouse menu,
6938 so that when present in last_nonmenu_event
6939 they won't confuse things. */
6940 for (tem
= XCDR (value
); !NILP (tem
);
6943 record_menu_key (XCAR (tem
));
6944 if (SYMBOLP (XCAR (tem
))
6945 || INTEGERP (XCAR (tem
)))
6947 = Fcons (XCAR (tem
), Qnil
);
6950 /* If we got more than one event, put all but the first
6951 onto this list to be read later.
6952 Return just the first event now. */
6953 Vunread_command_events
6954 = nconc2 (XCDR (value
), Vunread_command_events
);
6955 value
= XCAR (value
);
6957 else if (NILP (value
))
6959 if (used_mouse_menu
)
6960 *used_mouse_menu
= 1;
6963 #endif /* HAVE_MENUS */
6967 /* Buffer in use so far for the minibuf prompts for menu keymaps.
6968 We make this bigger when necessary, and never free it. */
6969 static char *read_char_minibuf_menu_text
;
6970 /* Size of that buffer. */
6971 static int read_char_minibuf_menu_width
;
6974 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
6980 register Lisp_Object name
;
6982 int width
= FRAME_WIDTH (SELECTED_FRAME ()) - 4;
6985 Lisp_Object rest
, vector
;
6988 if (! menu_prompting
)
6991 /* Make sure we have a big enough buffer for the menu text. */
6992 if (read_char_minibuf_menu_text
== 0)
6994 read_char_minibuf_menu_width
= width
+ 4;
6995 read_char_minibuf_menu_text
= (char *) xmalloc (width
+ 4);
6997 else if (width
+ 4 > read_char_minibuf_menu_width
)
6999 read_char_minibuf_menu_width
= width
+ 4;
7000 read_char_minibuf_menu_text
7001 = (char *) xrealloc (read_char_minibuf_menu_text
, width
+ 4);
7003 menu
= read_char_minibuf_menu_text
;
7005 /* Get the menu name from the first map that has one (a prompt string). */
7006 for (mapno
= 0; mapno
< nmaps
; mapno
++)
7008 name
= map_prompt (maps
[mapno
]);
7013 /* If we don't have any menus, just read a character normally. */
7017 /* Prompt string always starts with map's prompt, and a space. */
7018 strcpy (menu
, XSTRING (name
)->data
);
7019 nlength
= STRING_BYTES (XSTRING (name
));
7020 menu
[nlength
++] = ':';
7021 menu
[nlength
++] = ' ';
7024 /* Start prompting at start of first map. */
7028 /* Present the documented bindings, a line at a time. */
7035 Lisp_Object orig_defn_macro
;
7037 /* Loop over elements of map. */
7042 /* If reached end of map, start at beginning of next map. */
7046 /* At end of last map, wrap around to first map if just starting,
7047 or end this line if already have something on it. */
7051 if (notfirst
|| nobindings
) break;
7056 /* Look at the next element of the map. */
7058 elt
= XVECTOR (vector
)->contents
[idx
];
7060 elt
= Fcar_safe (rest
);
7062 if (idx
< 0 && VECTORP (elt
))
7064 /* If we found a dense table in the keymap,
7065 advanced past it, but start scanning its contents. */
7066 rest
= Fcdr_safe (rest
);
7072 /* An ordinary element. */
7073 Lisp_Object event
, tem
;
7077 event
= Fcar_safe (elt
); /* alist */
7078 elt
= Fcdr_safe (elt
);
7082 XSETINT (event
, idx
); /* vector */
7085 /* Ignore the element if it has no prompt string. */
7086 if (INTEGERP (event
) && parse_menu_item (elt
, 0, -1))
7088 /* 1 if the char to type matches the string. */
7090 Lisp_Object upcased_event
, downcased_event
;
7093 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
7095 upcased_event
= Fupcase (event
);
7096 downcased_event
= Fdowncase (event
);
7097 char_matches
= (XINT (upcased_event
) == XSTRING (s
)->data
[0]
7098 || XINT (downcased_event
) == XSTRING (s
)->data
[0]);
7100 desc
= Fsingle_key_description (event
);
7103 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
];
7105 /* Insert equivalent keybinding. */
7106 s
= concat2 (s
, tem
);
7109 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_TYPE
];
7110 if (EQ (tem
, QCradio
) || EQ (tem
, QCtoggle
))
7112 /* Insert button prefix. */
7113 Lisp_Object selected
7114 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
];
7115 if (EQ (tem
, QCradio
))
7116 tem
= build_string (NILP (selected
) ? "(*) " : "( ) ");
7118 tem
= build_string (NILP (selected
) ? "[X] " : "[ ] ");
7119 s
= concat2 (tem
, s
);
7123 /* If we have room for the prompt string, add it to this line.
7124 If this is the first on the line, always add it. */
7125 if ((XSTRING (s
)->size
+ i
+ 2
7126 + (char_matches
? 0 : XSTRING (desc
)->size
+ 3))
7132 /* Punctuate between strings. */
7135 strcpy (menu
+ i
, ", ");
7141 /* If the char to type doesn't match the string's
7142 first char, explicitly show what char to type. */
7145 /* Add as much of string as fits. */
7146 thiswidth
= XSTRING (desc
)->size
;
7147 if (thiswidth
+ i
> width
)
7148 thiswidth
= width
- i
;
7149 bcopy (XSTRING (desc
)->data
, menu
+ i
, thiswidth
);
7151 strcpy (menu
+ i
, " = ");
7155 /* Add as much of string as fits. */
7156 thiswidth
= XSTRING (s
)->size
;
7157 if (thiswidth
+ i
> width
)
7158 thiswidth
= width
- i
;
7159 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
7165 /* If this element does not fit, end the line now,
7166 and save the element for the next line. */
7167 strcpy (menu
+ i
, "...");
7172 /* Move past this element. */
7173 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
7174 /* Handle reaching end of dense table. */
7179 rest
= Fcdr_safe (rest
);
7183 /* Prompt with that and read response. */
7184 message2_nolog (menu
, strlen (menu
),
7185 ! NILP (current_buffer
->enable_multibyte_characters
));
7187 /* Make believe its not a keyboard macro in case the help char
7188 is pressed. Help characters are not recorded because menu prompting
7189 is not used on replay.
7191 orig_defn_macro
= current_kboard
->defining_kbd_macro
;
7192 current_kboard
->defining_kbd_macro
= Qnil
;
7194 obj
= read_char (commandflag
, 0, 0, Qnil
, 0);
7195 while (BUFFERP (obj
));
7196 current_kboard
->defining_kbd_macro
= orig_defn_macro
;
7198 if (!INTEGERP (obj
))
7203 if (! EQ (obj
, menu_prompt_more_char
)
7204 && (!INTEGERP (menu_prompt_more_char
)
7205 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
7207 if (!NILP (current_kboard
->defining_kbd_macro
))
7208 store_kbd_macro_char (obj
);
7211 /* Help char - go round again */
7215 /* Reading key sequences. */
7217 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
7218 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
7219 keymap, or nil otherwise. Return the index of the first keymap in
7220 which KEY has any binding, or NMAPS if no map has a binding.
7222 If KEY is a meta ASCII character, treat it like meta-prefix-char
7223 followed by the corresponding non-meta character. Keymaps in
7224 CURRENT with non-prefix bindings for meta-prefix-char become nil in
7227 If KEY has no bindings in any of the CURRENT maps, NEXT is left
7230 NEXT may be the same array as CURRENT. */
7233 follow_key (key
, nmaps
, current
, defs
, next
)
7235 Lisp_Object
*current
, *defs
, *next
;
7238 int i
, first_binding
;
7241 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
7242 followed by the corresponding non-meta character.
7243 Put the results into DEFS, since we are going to alter that anyway.
7244 Do not alter CURRENT or NEXT. */
7245 if (INTEGERP (key
) && (XINT (key
) & CHAR_META
))
7247 for (i
= 0; i
< nmaps
; i
++)
7248 if (! NILP (current
[i
]))
7251 def
= get_keyelt (access_keymap (current
[i
],
7252 meta_prefix_char
, 1, 0), 0);
7254 /* Note that since we pass the resulting bindings through
7255 get_keymap_1, non-prefix bindings for meta-prefix-char
7257 defs
[i
] = get_keymap_1 (def
, 0, 1);
7263 XSETINT (key
, XFASTINT (key
) & ~CHAR_META
);
7266 first_binding
= nmaps
;
7267 for (i
= nmaps
- 1; i
>= 0; i
--)
7269 if (! NILP (current
[i
]))
7277 defs
[i
] = get_keyelt (access_keymap (map
, key
, 1, 0), 0);
7278 if (! NILP (defs
[i
]))
7285 /* Given the set of bindings we've found, produce the next set of maps. */
7286 if (first_binding
< nmaps
)
7287 for (i
= 0; i
< nmaps
; i
++)
7288 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0, 1);
7290 return first_binding
;
7293 /* Read a sequence of keys that ends with a non prefix character,
7294 storing it in KEYBUF, a buffer of size BUFSIZE.
7296 Return the length of the key sequence stored.
7297 Return -1 if the user rejected a command menu.
7299 Echo starting immediately unless `prompt' is 0.
7301 Where a key sequence ends depends on the currently active keymaps.
7302 These include any minor mode keymaps active in the current buffer,
7303 the current buffer's local map, and the global map.
7305 If a key sequence has no other bindings, we check Vfunction_key_map
7306 to see if some trailing subsequence might be the beginning of a
7307 function key's sequence. If so, we try to read the whole function
7308 key, and substitute its symbolic name into the key sequence.
7310 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
7311 `double-' events into similar click events, if that would make them
7312 bound. We try to turn `triple-' events first into `double-' events,
7315 If we get a mouse click in a mode line, vertical divider, or other
7316 non-text area, we treat the click as if it were prefixed by the
7317 symbol denoting that area - `mode-line', `vertical-line', or
7320 If the sequence starts with a mouse click, we read the key sequence
7321 with respect to the buffer clicked on, not the current buffer.
7323 If the user switches frames in the midst of a key sequence, we put
7324 off the switch-frame event until later; the next call to
7325 read_char will return it.
7327 If FIX_CURRENT_BUFFER is nonzero, we restore current_buffer
7328 from the selected window's buffer. */
7331 read_key_sequence (keybuf
, bufsize
, prompt
, dont_downcase_last
,
7332 can_return_switch_frame
, fix_current_buffer
)
7333 Lisp_Object
*keybuf
;
7336 int dont_downcase_last
;
7337 int can_return_switch_frame
;
7338 int fix_current_buffer
;
7340 int count
= specpdl_ptr
- specpdl
;
7342 /* How many keys there are in the current key sequence. */
7345 /* The length of the echo buffer when we started reading, and
7346 the length of this_command_keys when we started reading. */
7350 /* The number of keymaps we're scanning right now, and the number of
7351 keymaps we have allocated space for. */
7353 int nmaps_allocated
= 0;
7355 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
7356 the current keymaps. */
7359 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
7360 in the current keymaps, or nil where it is not a prefix. */
7361 Lisp_Object
*submaps
;
7363 /* The local map to start out with at start of key sequence. */
7364 Lisp_Object orig_local_map
;
7366 /* 1 if we have already considered switching to the local-map property
7367 of the place where a mouse click occurred. */
7368 int localized_local_map
= 0;
7370 /* The index in defs[] of the first keymap that has a binding for
7371 this key sequence. In other words, the lowest i such that
7372 defs[i] is non-nil. */
7375 /* If t < mock_input, then KEYBUF[t] should be read as the next
7378 We use this to recover after recognizing a function key. Once we
7379 realize that a suffix of the current key sequence is actually a
7380 function key's escape sequence, we replace the suffix with the
7381 function key's binding from Vfunction_key_map. Now keybuf
7382 contains a new and different key sequence, so the echo area,
7383 this_command_keys, and the submaps and defs arrays are wrong. In
7384 this situation, we set mock_input to t, set t to 0, and jump to
7385 restart_sequence; the loop will read keys from keybuf up until
7386 mock_input, thus rebuilding the state; and then it will resume
7387 reading characters from the keyboard. */
7390 /* If the sequence is unbound in submaps[], then
7391 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
7392 and fkey_map is its binding.
7394 These might be > t, indicating that all function key scanning
7395 should hold off until t reaches them. We do this when we've just
7396 recognized a function key, to avoid searching for the function
7397 key's again in Vfunction_key_map. */
7398 int fkey_start
= 0, fkey_end
= 0;
7399 Lisp_Object fkey_map
;
7401 /* Likewise, for key_translation_map. */
7402 int keytran_start
= 0, keytran_end
= 0;
7403 Lisp_Object keytran_map
;
7405 /* If we receive a ``switch-frame'' event in the middle of a key sequence,
7406 we put it off for later. While we're reading, we keep the event here. */
7407 Lisp_Object delayed_switch_frame
;
7409 /* See the comment below... */
7410 #if defined (GOBBLE_FIRST_EVENT)
7411 Lisp_Object first_event
;
7414 Lisp_Object original_uppercase
;
7415 int original_uppercase_position
= -1;
7417 /* Gets around Microsoft compiler limitations. */
7420 struct buffer
*starting_buffer
;
7422 /* Nonzero if we seem to have got the beginning of a binding
7423 in function_key_map. */
7424 int function_key_possible
= 0;
7425 int key_translation_possible
= 0;
7427 /* Save the status of key translation before each step,
7428 so that we can restore this after downcasing. */
7429 Lisp_Object prev_fkey_map
;
7430 int prev_fkey_start
;
7433 Lisp_Object prev_keytran_map
;
7434 int prev_keytran_start
;
7435 int prev_keytran_end
;
7437 #if defined (GOBBLE_FIRST_EVENT)
7441 raw_keybuf_count
= 0;
7443 last_nonmenu_event
= Qnil
;
7445 delayed_switch_frame
= Qnil
;
7446 fkey_map
= Vfunction_key_map
;
7447 keytran_map
= Vkey_translation_map
;
7449 /* If there is no function-key-map, turn off function key scanning. */
7450 if (NILP (Fkeymapp (Vfunction_key_map
)))
7451 fkey_start
= fkey_end
= bufsize
+ 1;
7453 /* If there is no key-translation-map, turn off scanning. */
7454 if (NILP (Fkeymapp (Vkey_translation_map
)))
7455 keytran_start
= keytran_end
= bufsize
+ 1;
7460 echo_prompt (XSTRING (prompt
)->data
);
7461 else if (cursor_in_echo_area
7462 && (FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
7463 && NILP (Fzerop (Vecho_keystrokes
)))
7464 /* This doesn't put in a dash if the echo buffer is empty, so
7465 you don't always see a dash hanging out in the minibuffer. */
7469 /* Record the initial state of the echo area and this_command_keys;
7470 we will need to restore them if we replay a key sequence. */
7472 echo_start
= echo_length ();
7473 keys_start
= this_command_key_count
;
7474 this_single_command_key_start
= keys_start
;
7476 #if defined (GOBBLE_FIRST_EVENT)
7477 /* This doesn't quite work, because some of the things that read_char
7478 does cannot safely be bypassed. It seems too risky to try to make
7481 /* Read the first char of the sequence specially, before setting
7482 up any keymaps, in case a filter runs and switches buffers on us. */
7483 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
7485 #endif /* GOBBLE_FIRST_EVENT */
7487 orig_local_map
= get_local_map (PT
, current_buffer
);
7489 /* We jump here when the key sequence has been thoroughly changed, and
7490 we need to rescan it starting from the beginning. When we jump here,
7491 keybuf[0..mock_input] holds the sequence we should reread. */
7494 starting_buffer
= current_buffer
;
7495 function_key_possible
= 0;
7496 key_translation_possible
= 0;
7498 /* Build our list of keymaps.
7499 If we recognize a function key and replace its escape sequence in
7500 keybuf with its symbol, or if the sequence starts with a mouse
7501 click and we need to switch buffers, we jump back here to rebuild
7502 the initial keymaps from the current buffer. */
7506 if (!NILP (current_kboard
->Voverriding_terminal_local_map
)
7507 || !NILP (Voverriding_local_map
))
7509 if (3 > nmaps_allocated
)
7511 submaps
= (Lisp_Object
*) alloca (3 * sizeof (submaps
[0]));
7512 defs
= (Lisp_Object
*) alloca (3 * sizeof (defs
[0]));
7513 nmaps_allocated
= 3;
7516 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
7517 submaps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
7518 if (!NILP (Voverriding_local_map
))
7519 submaps
[nmaps
++] = Voverriding_local_map
;
7523 nmaps
= current_minor_maps (0, &maps
);
7524 if (nmaps
+ 2 > nmaps_allocated
)
7526 submaps
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (submaps
[0]));
7527 defs
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (defs
[0]));
7528 nmaps_allocated
= nmaps
+ 2;
7530 bcopy (maps
, submaps
, nmaps
* sizeof (submaps
[0]));
7531 submaps
[nmaps
++] = orig_local_map
;
7533 submaps
[nmaps
++] = current_global_map
;
7536 /* Find an accurate initial value for first_binding. */
7537 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
7538 if (! NILP (submaps
[first_binding
]))
7541 /* Start from the beginning in keybuf. */
7544 /* These are no-ops the first time through, but if we restart, they
7545 revert the echo area and this_command_keys to their original state. */
7546 this_command_key_count
= keys_start
;
7547 if (INTERACTIVE
&& t
< mock_input
)
7548 echo_truncate (echo_start
);
7550 /* If the best binding for the current key sequence is a keymap, or
7551 we may be looking at a function key's escape sequence, keep on
7553 while ((first_binding
< nmaps
&& ! NILP (submaps
[first_binding
]))
7554 || (first_binding
>= nmaps
7556 /* mock input is never part of a function key's sequence. */
7557 && mock_input
<= fkey_start
)
7558 || (first_binding
>= nmaps
7559 && keytran_start
< t
&& key_translation_possible
)
7560 /* Don't return in the middle of a possible function key sequence,
7561 if the only bindings we found were via case conversion.
7562 Thus, if ESC O a has a function-key-map translation
7563 and ESC o has a binding, don't return after ESC O,
7564 so that we can translate ESC O plus the next character. */
7568 int used_mouse_menu
= 0;
7570 /* Where the last real key started. If we need to throw away a
7571 key that has expanded into more than one element of keybuf
7572 (say, a mouse click on the mode line which is being treated
7573 as [mode-line (mouse-...)], then we backtrack to this point
7575 int last_real_key_start
;
7577 /* These variables are analogous to echo_start and keys_start;
7578 while those allow us to restart the entire key sequence,
7579 echo_local_start and keys_local_start allow us to throw away
7581 int echo_local_start
, keys_local_start
, local_first_binding
;
7584 error ("Key sequence too long");
7587 echo_local_start
= echo_length ();
7588 keys_local_start
= this_command_key_count
;
7589 local_first_binding
= first_binding
;
7592 /* These are no-ops, unless we throw away a keystroke below and
7593 jumped back up to replay_key; in that case, these restore the
7594 variables to their original state, allowing us to replay the
7596 if (INTERACTIVE
&& t
< mock_input
)
7597 echo_truncate (echo_local_start
);
7598 this_command_key_count
= keys_local_start
;
7599 first_binding
= local_first_binding
;
7601 /* By default, assume each event is "real". */
7602 last_real_key_start
= t
;
7604 /* Does mock_input indicate that we are re-reading a key sequence? */
7608 add_command_key (key
);
7609 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
7610 && NILP (Fzerop (Vecho_keystrokes
)))
7614 /* If not, we should actually read a character. */
7619 KBOARD
*interrupted_kboard
= current_kboard
;
7620 struct frame
*interrupted_frame
= SELECTED_FRAME ();
7621 if (setjmp (wrong_kboard_jmpbuf
))
7623 if (!NILP (delayed_switch_frame
))
7625 interrupted_kboard
->kbd_queue
7626 = Fcons (delayed_switch_frame
,
7627 interrupted_kboard
->kbd_queue
);
7628 delayed_switch_frame
= Qnil
;
7631 interrupted_kboard
->kbd_queue
7632 = Fcons (keybuf
[--t
], interrupted_kboard
->kbd_queue
);
7634 /* If the side queue is non-empty, ensure it begins with a
7635 switch-frame, so we'll replay it in the right context. */
7636 if (CONSP (interrupted_kboard
->kbd_queue
)
7637 && (key
= XCAR (interrupted_kboard
->kbd_queue
),
7638 !(EVENT_HAS_PARAMETERS (key
)
7639 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)),
7643 XSETFRAME (frame
, interrupted_frame
);
7644 interrupted_kboard
->kbd_queue
7645 = Fcons (make_lispy_switch_frame (frame
),
7646 interrupted_kboard
->kbd_queue
);
7649 orig_local_map
= get_local_map (PT
, current_buffer
);
7650 goto replay_sequence
;
7653 key
= read_char (NILP (prompt
), nmaps
, submaps
, last_nonmenu_event
,
7657 /* read_char returns t when it shows a menu and the user rejects it.
7661 unbind_to (count
, Qnil
);
7665 /* read_char returns -1 at the end of a macro.
7666 Emacs 18 handles this by returning immediately with a
7667 zero, so that's what we'll do. */
7668 if (INTEGERP (key
) && XINT (key
) == -1)
7671 /* The Microsoft C compiler can't handle the goto that
7677 /* If the current buffer has been changed from under us, the
7678 keymap may have changed, so replay the sequence. */
7682 /* Reset the current buffer from the selected window
7683 in case something changed the former and not the latter.
7684 This is to be more consistent with the behavior
7685 of the command_loop_1. */
7686 if (fix_current_buffer
)
7688 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7690 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
7691 Fset_buffer (XWINDOW (selected_window
)->buffer
);
7694 orig_local_map
= get_local_map (PT
, current_buffer
);
7695 goto replay_sequence
;
7698 /* If we have a quit that was typed in another frame, and
7699 quit_throw_to_read_char switched buffers,
7700 replay to get the right keymap. */
7701 if (XINT (key
) == quit_char
&& current_buffer
!= starting_buffer
)
7704 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
7708 orig_local_map
= get_local_map (PT
, current_buffer
);
7709 goto replay_sequence
;
7714 if (EVENT_HAS_PARAMETERS (key
)
7715 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)), Qswitch_frame
))
7717 /* If we're at the beginning of a key sequence, and the caller
7718 says it's okay, go ahead and return this event. If we're
7719 in the midst of a key sequence, delay it until the end. */
7720 if (t
> 0 || !can_return_switch_frame
)
7722 delayed_switch_frame
= key
;
7728 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
7731 /* Clicks in non-text areas get prefixed by the symbol
7732 in their CHAR-ADDRESS field. For example, a click on
7733 the mode line is prefixed by the symbol `mode-line'.
7735 Furthermore, key sequences beginning with mouse clicks
7736 are read using the keymaps of the buffer clicked on, not
7737 the current buffer. So we may have to switch the buffer
7740 When we turn one event into two events, we must make sure
7741 that neither of the two looks like the original--so that,
7742 if we replay the events, they won't be expanded again.
7743 If not for this, such reexpansion could happen either here
7744 or when user programs play with this-command-keys. */
7745 if (EVENT_HAS_PARAMETERS (key
))
7749 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
7750 if (EQ (kind
, Qmouse_click
))
7752 Lisp_Object window
, posn
;
7754 window
= POSN_WINDOW (EVENT_START (key
));
7755 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
7759 /* We're looking at the second event of a
7760 sequence which we expanded before. Set
7761 last_real_key_start appropriately. */
7763 last_real_key_start
= t
- 1;
7766 /* Key sequences beginning with mouse clicks are
7767 read using the keymaps in the buffer clicked on,
7768 not the current buffer. If we're at the
7769 beginning of a key sequence, switch buffers. */
7770 if (last_real_key_start
== 0
7772 && BUFFERP (XWINDOW (window
)->buffer
)
7773 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
7775 XVECTOR (raw_keybuf
)->contents
[raw_keybuf_count
++] = key
;
7779 /* Arrange to go back to the original buffer once we're
7780 done reading the key sequence. Note that we can't
7781 use save_excursion_{save,restore} here, because they
7782 save point as well as the current buffer; we don't
7783 want to save point, because redisplay may change it,
7784 to accommodate a Fset_window_start or something. We
7785 don't want to do this at the top of the function,
7786 because we may get input from a subprocess which
7787 wants to change the selected window and stuff (say,
7789 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
7791 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7793 set_buffer_internal (XBUFFER (XWINDOW (window
)->buffer
));
7794 orig_local_map
= get_local_map (PT
, current_buffer
);
7795 goto replay_sequence
;
7798 /* For a mouse click, get the local text-property keymap
7799 of the place clicked on, rather than point. */
7800 if (last_real_key_start
== 0
7801 && CONSP (XCDR (key
))
7802 && ! localized_local_map
)
7804 Lisp_Object map_here
, start
, pos
;
7806 localized_local_map
= 1;
7807 start
= EVENT_START (key
);
7809 if (CONSP (start
) && CONSP (XCDR (start
)))
7811 pos
= POSN_BUFFER_POSN (start
);
7813 && XINT (pos
) >= BEG
&& XINT (pos
) <= Z
)
7815 map_here
= get_local_map (XINT (pos
), current_buffer
);
7816 if (!EQ (map_here
, orig_local_map
))
7818 orig_local_map
= map_here
;
7822 goto replay_sequence
;
7828 /* Expand mode-line and scroll-bar events into two events:
7829 use posn as a fake prefix key. */
7832 if (t
+ 1 >= bufsize
)
7833 error ("Key sequence too long");
7838 /* Zap the position in key, so we know that we've
7839 expanded it, and don't try to do so again. */
7840 POSN_BUFFER_POSN (EVENT_START (key
))
7841 = Fcons (posn
, Qnil
);
7843 /* If on a mode line string with a local keymap,
7844 reconsider the key sequence with that keymap. */
7845 if (CONSP (POSN_STRING (EVENT_START (key
))))
7847 Lisp_Object string
, pos
, map
;
7849 string
= POSN_STRING (EVENT_START (key
));
7850 pos
= XCDR (string
);
7851 string
= XCAR (string
);
7854 && pos
< XSTRING (string
)->size
7855 && (map
= Fget_text_property (pos
, Qlocal_map
,
7859 orig_local_map
= map
;
7860 goto replay_sequence
;
7867 else if (CONSP (XCDR (key
))
7868 && CONSP (EVENT_START (key
))
7869 && CONSP (XCDR (EVENT_START (key
))))
7873 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
7874 /* Handle menu-bar events:
7875 insert the dummy prefix event `menu-bar'. */
7876 if (EQ (posn
, Qmenu_bar
) || EQ (posn
, Qtool_bar
))
7878 if (t
+ 1 >= bufsize
)
7879 error ("Key sequence too long");
7883 /* Zap the position in key, so we know that we've
7884 expanded it, and don't try to do so again. */
7885 POSN_BUFFER_POSN (EVENT_START (key
))
7886 = Fcons (posn
, Qnil
);
7889 goto replay_sequence
;
7891 else if (CONSP (posn
))
7893 /* We're looking at the second event of a
7894 sequence which we expanded before. Set
7895 last_real_key_start appropriately. */
7896 if (last_real_key_start
== t
&& t
> 0)
7897 last_real_key_start
= t
- 1;
7902 /* We have finally decided that KEY is something we might want
7904 first_binding
= (follow_key (key
,
7905 nmaps
- first_binding
,
7906 submaps
+ first_binding
,
7907 defs
+ first_binding
,
7908 submaps
+ first_binding
)
7911 /* If KEY wasn't bound, we'll try some fallbacks. */
7912 if (first_binding
>= nmaps
)
7916 head
= EVENT_HEAD (key
);
7917 if (help_char_p (head
) && t
> 0)
7919 read_key_sequence_cmd
= Vprefix_help_command
;
7921 last_nonmenu_event
= key
;
7922 /* The Microsoft C compiler can't handle the goto that
7930 Lisp_Object breakdown
;
7933 breakdown
= parse_modifiers (head
);
7934 modifiers
= XINT (XCAR (XCDR (breakdown
)));
7935 /* Attempt to reduce an unbound mouse event to a simpler
7936 event that is bound:
7937 Drags reduce to clicks.
7938 Double-clicks reduce to clicks.
7939 Triple-clicks reduce to double-clicks, then to clicks.
7940 Down-clicks are eliminated.
7941 Double-downs reduce to downs, then are eliminated.
7942 Triple-downs reduce to double-downs, then to downs,
7943 then are eliminated. */
7944 if (modifiers
& (down_modifier
| drag_modifier
7945 | double_modifier
| triple_modifier
))
7947 while (modifiers
& (down_modifier
| drag_modifier
7948 | double_modifier
| triple_modifier
))
7950 Lisp_Object new_head
, new_click
;
7951 if (modifiers
& triple_modifier
)
7952 modifiers
^= (double_modifier
| triple_modifier
);
7953 else if (modifiers
& double_modifier
)
7954 modifiers
&= ~double_modifier
;
7955 else if (modifiers
& drag_modifier
)
7956 modifiers
&= ~drag_modifier
;
7959 /* Dispose of this `down' event by simply jumping
7960 back to replay_key, to get another event.
7962 Note that if this event came from mock input,
7963 then just jumping back to replay_key will just
7964 hand it to us again. So we have to wipe out any
7967 We could delete keybuf[t] and shift everything
7968 after that to the left by one spot, but we'd also
7969 have to fix up any variable that points into
7970 keybuf, and shifting isn't really necessary
7973 Adding prefixes for non-textual mouse clicks
7974 creates two characters of mock input, and both
7975 must be thrown away. If we're only looking at
7976 the prefix now, we can just jump back to
7977 replay_key. On the other hand, if we've already
7978 processed the prefix, and now the actual click
7979 itself is giving us trouble, then we've lost the
7980 state of the keymaps we want to backtrack to, and
7981 we need to replay the whole sequence to rebuild
7984 Beyond that, only function key expansion could
7985 create more than two keys, but that should never
7986 generate mouse events, so it's okay to zero
7987 mock_input in that case too.
7989 Isn't this just the most wonderful code ever? */
7990 if (t
== last_real_key_start
)
7997 mock_input
= last_real_key_start
;
7998 goto replay_sequence
;
8003 = apply_modifiers (modifiers
, XCAR (breakdown
));
8005 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
8007 /* Look for a binding for this new key. follow_key
8008 promises that it didn't munge submaps the
8009 last time we called it, since key was unbound. */
8011 = (follow_key (new_click
,
8012 nmaps
- local_first_binding
,
8013 submaps
+ local_first_binding
,
8014 defs
+ local_first_binding
,
8015 submaps
+ local_first_binding
)
8016 + local_first_binding
);
8018 /* If that click is bound, go for it. */
8019 if (first_binding
< nmaps
)
8024 /* Otherwise, we'll leave key set to the drag event. */
8031 /* Normally, last_nonmenu_event gets the previous key we read.
8032 But when a mouse popup menu is being used,
8033 we don't update last_nonmenu_event; it continues to hold the mouse
8034 event that preceded the first level of menu. */
8035 if (!used_mouse_menu
)
8036 last_nonmenu_event
= key
;
8038 /* Record what part of this_command_keys is the current key sequence. */
8039 this_single_command_key_start
= this_command_key_count
- t
;
8041 prev_fkey_map
= fkey_map
;
8042 prev_fkey_start
= fkey_start
;
8043 prev_fkey_end
= fkey_end
;
8045 prev_keytran_map
= keytran_map
;
8046 prev_keytran_start
= keytran_start
;
8047 prev_keytran_end
= keytran_end
;
8049 /* If the sequence is unbound, see if we can hang a function key
8050 off the end of it. We only want to scan real keyboard input
8051 for function key sequences, so if mock_input says that we're
8052 re-reading old events, don't examine it. */
8053 if (first_binding
>= nmaps
8056 Lisp_Object fkey_next
;
8058 /* Continue scan from fkey_end until we find a bound suffix.
8059 If we fail, increment fkey_start
8060 and start fkey_end from there. */
8061 while (fkey_end
< t
)
8065 key
= keybuf
[fkey_end
++];
8066 /* Look up meta-characters by prefixing them
8067 with meta_prefix_char. I hate this. */
8068 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
8073 (access_keymap (fkey_map
, meta_prefix_char
, 1, 0), 0),
8075 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
8078 fkey_next
= fkey_map
;
8081 = get_keyelt (access_keymap (fkey_next
, key
, 1, 0), 1);
8083 /* Handle symbol with autoload definition. */
8084 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
8085 && CONSP (XSYMBOL (fkey_next
)->function
)
8086 && EQ (XCAR (XSYMBOL (fkey_next
)->function
), Qautoload
))
8087 do_autoload (XSYMBOL (fkey_next
)->function
,
8090 /* Handle a symbol whose function definition is a keymap
8092 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
8093 && (!NILP (Farrayp (XSYMBOL (fkey_next
)->function
))
8094 || !NILP (Fkeymapp (XSYMBOL (fkey_next
)->function
))))
8095 fkey_next
= XSYMBOL (fkey_next
)->function
;
8097 #if 0 /* I didn't turn this on, because it might cause trouble
8098 for the mapping of return into C-m and tab into C-i. */
8099 /* Optionally don't map function keys into other things.
8100 This enables the user to redefine kp- keys easily. */
8101 if (SYMBOLP (key
) && !NILP (Vinhibit_function_key_mapping
))
8105 /* If the function key map gives a function, not an
8106 array, then call the function with no args and use
8107 its value instead. */
8108 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
8111 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8115 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
8116 fkey_next
= call1 (fkey_next
, prompt
);
8118 /* If the function returned something invalid,
8119 barf--don't ignore it.
8120 (To ignore it safely, we would need to gcpro a bunch of
8121 other variables.) */
8122 if (! (VECTORP (fkey_next
) || STRINGP (fkey_next
)))
8123 error ("Function in key-translation-map returns invalid key sequence");
8126 function_key_possible
= ! NILP (fkey_next
);
8128 /* If keybuf[fkey_start..fkey_end] is bound in the
8129 function key map and it's a suffix of the current
8130 sequence (i.e. fkey_end == t), replace it with
8131 the binding and restart with fkey_start at the end. */
8132 if ((VECTORP (fkey_next
) || STRINGP (fkey_next
))
8135 int len
= XFASTINT (Flength (fkey_next
));
8137 t
= fkey_start
+ len
;
8139 error ("Key sequence too long");
8141 if (VECTORP (fkey_next
))
8142 bcopy (XVECTOR (fkey_next
)->contents
,
8143 keybuf
+ fkey_start
,
8144 (t
- fkey_start
) * sizeof (keybuf
[0]));
8145 else if (STRINGP (fkey_next
))
8149 for (i
= 0; i
< len
; i
++)
8150 XSETFASTINT (keybuf
[fkey_start
+ i
],
8151 XSTRING (fkey_next
)->data
[i
]);
8155 fkey_start
= fkey_end
= t
;
8156 fkey_map
= Vfunction_key_map
;
8158 /* Do pass the results through key-translation-map.
8159 But don't retranslate what key-translation-map
8160 has already translated. */
8161 keytran_end
= keytran_start
;
8162 keytran_map
= Vkey_translation_map
;
8164 goto replay_sequence
;
8167 fkey_map
= get_keymap_1 (fkey_next
, 0, 1);
8169 /* If we no longer have a bound suffix, try a new positions for
8171 if (NILP (fkey_map
))
8173 fkey_end
= ++fkey_start
;
8174 fkey_map
= Vfunction_key_map
;
8175 function_key_possible
= 0;
8180 /* Look for this sequence in key-translation-map. */
8182 Lisp_Object keytran_next
;
8184 /* Scan from keytran_end until we find a bound suffix. */
8185 while (keytran_end
< t
)
8189 key
= keybuf
[keytran_end
++];
8190 /* Look up meta-characters by prefixing them
8191 with meta_prefix_char. I hate this. */
8192 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
8197 (access_keymap (keytran_map
, meta_prefix_char
, 1, 0), 0),
8199 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
8202 keytran_next
= keytran_map
;
8205 = get_keyelt (access_keymap (keytran_next
, key
, 1, 0), 1);
8207 /* Handle symbol with autoload definition. */
8208 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
8209 && CONSP (XSYMBOL (keytran_next
)->function
)
8210 && EQ (XCAR (XSYMBOL (keytran_next
)->function
), Qautoload
))
8211 do_autoload (XSYMBOL (keytran_next
)->function
,
8214 /* Handle a symbol whose function definition is a keymap
8216 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
8217 && (!NILP (Farrayp (XSYMBOL (keytran_next
)->function
))
8218 || !NILP (Fkeymapp (XSYMBOL (keytran_next
)->function
))))
8219 keytran_next
= XSYMBOL (keytran_next
)->function
;
8221 /* If the key translation map gives a function, not an
8222 array, then call the function with one arg and use
8223 its value instead. */
8224 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
8225 && keytran_end
== t
)
8227 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8231 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
8232 keytran_next
= call1 (keytran_next
, prompt
);
8234 /* If the function returned something invalid,
8235 barf--don't ignore it.
8236 (To ignore it safely, we would need to gcpro a bunch of
8237 other variables.) */
8238 if (! (VECTORP (keytran_next
) || STRINGP (keytran_next
)))
8239 error ("Function in key-translation-map returns invalid key sequence");
8242 key_translation_possible
= ! NILP (keytran_next
);
8244 /* If keybuf[keytran_start..keytran_end] is bound in the
8245 key translation map and it's a suffix of the current
8246 sequence (i.e. keytran_end == t), replace it with
8247 the binding and restart with keytran_start at the end. */
8248 if ((VECTORP (keytran_next
) || STRINGP (keytran_next
))
8249 && keytran_end
== t
)
8251 int len
= XFASTINT (Flength (keytran_next
));
8253 t
= keytran_start
+ len
;
8255 error ("Key sequence too long");
8257 if (VECTORP (keytran_next
))
8258 bcopy (XVECTOR (keytran_next
)->contents
,
8259 keybuf
+ keytran_start
,
8260 (t
- keytran_start
) * sizeof (keybuf
[0]));
8261 else if (STRINGP (keytran_next
))
8265 for (i
= 0; i
< len
; i
++)
8266 XSETFASTINT (keybuf
[keytran_start
+ i
],
8267 XSTRING (keytran_next
)->data
[i
]);
8271 keytran_start
= keytran_end
= t
;
8272 keytran_map
= Vkey_translation_map
;
8274 /* Don't pass the results of key-translation-map
8275 through function-key-map. */
8276 fkey_start
= fkey_end
= t
;
8277 fkey_map
= Vfunction_key_map
;
8279 goto replay_sequence
;
8282 keytran_map
= get_keymap_1 (keytran_next
, 0, 1);
8284 /* If we no longer have a bound suffix, try a new positions for
8286 if (NILP (keytran_map
))
8288 keytran_end
= ++keytran_start
;
8289 keytran_map
= Vkey_translation_map
;
8290 key_translation_possible
= 0;
8295 /* If KEY is not defined in any of the keymaps,
8296 and cannot be part of a function key or translation,
8297 and is an upper case letter
8298 use the corresponding lower-case letter instead. */
8299 if (first_binding
== nmaps
&& ! function_key_possible
8300 && ! key_translation_possible
8302 && ((((XINT (key
) & 0x3ffff)
8303 < XCHAR_TABLE (current_buffer
->downcase_table
)->size
)
8304 && UPPERCASEP (XINT (key
) & 0x3ffff))
8305 || (XINT (key
) & shift_modifier
)))
8307 Lisp_Object new_key
;
8309 original_uppercase
= key
;
8310 original_uppercase_position
= t
- 1;
8312 if (XINT (key
) & shift_modifier
)
8313 XSETINT (new_key
, XINT (key
) & ~shift_modifier
);
8315 XSETINT (new_key
, (DOWNCASE (XINT (key
) & 0x3ffff)
8316 | (XINT (key
) & ~0x3ffff)));
8318 /* We have to do this unconditionally, regardless of whether
8319 the lower-case char is defined in the keymaps, because they
8320 might get translated through function-key-map. */
8321 keybuf
[t
- 1] = new_key
;
8324 fkey_map
= prev_fkey_map
;
8325 fkey_start
= prev_fkey_start
;
8326 fkey_end
= prev_fkey_end
;
8328 keytran_map
= prev_keytran_map
;
8329 keytran_start
= prev_keytran_start
;
8330 keytran_end
= prev_keytran_end
;
8332 goto replay_sequence
;
8334 /* If KEY is not defined in any of the keymaps,
8335 and cannot be part of a function key or translation,
8336 and is a shifted function key,
8337 use the corresponding unshifted function key instead. */
8338 if (first_binding
== nmaps
&& ! function_key_possible
8339 && ! key_translation_possible
8342 Lisp_Object breakdown
;
8345 breakdown
= parse_modifiers (key
);
8346 modifiers
= XINT (XCAR (XCDR (breakdown
)));
8347 if (modifiers
& shift_modifier
)
8349 Lisp_Object new_key
;
8351 original_uppercase
= key
;
8352 original_uppercase_position
= t
- 1;
8354 modifiers
&= ~shift_modifier
;
8355 new_key
= apply_modifiers (modifiers
,
8358 keybuf
[t
- 1] = new_key
;
8361 fkey_map
= prev_fkey_map
;
8362 fkey_start
= prev_fkey_start
;
8363 fkey_end
= prev_fkey_end
;
8365 keytran_map
= prev_keytran_map
;
8366 keytran_start
= prev_keytran_start
;
8367 keytran_end
= prev_keytran_end
;
8369 goto replay_sequence
;
8375 read_key_sequence_cmd
= (first_binding
< nmaps
8376 ? defs
[first_binding
]
8379 unread_switch_frame
= delayed_switch_frame
;
8380 unbind_to (count
, Qnil
);
8382 /* Don't downcase the last character if the caller says don't.
8383 Don't downcase it if the result is undefined, either. */
8384 if ((dont_downcase_last
|| first_binding
>= nmaps
)
8385 && t
- 1 == original_uppercase_position
)
8386 keybuf
[t
- 1] = original_uppercase
;
8388 /* Occasionally we fabricate events, perhaps by expanding something
8389 according to function-key-map, or by adding a prefix symbol to a
8390 mouse click in the scroll bar or modeline. In this cases, return
8391 the entire generated key sequence, even if we hit an unbound
8392 prefix or a definition before the end. This means that you will
8393 be able to push back the event properly, and also means that
8394 read-key-sequence will always return a logical unit.
8397 for (; t
< mock_input
; t
++)
8399 if ((FLOATP (Vecho_keystrokes
) || INTEGERP (Vecho_keystrokes
))
8400 && NILP (Fzerop (Vecho_keystrokes
)))
8401 echo_char (keybuf
[t
]);
8402 add_command_key (keybuf
[t
]);
8410 #if 0 /* This doc string is too long for some compilers.
8411 This commented-out definition serves for DOC. */
8412 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
8413 "Read a sequence of keystrokes and return as a string or vector.\n\
8414 The sequence is sufficient to specify a non-prefix command in the\n\
8415 current local and global maps.\n\
8417 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
8418 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
8419 as a continuation of the previous key.\n\
8421 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not\n\
8422 convert the last event to lower case. (Normally any upper case event\n\
8423 is converted to lower case if the original event is undefined and the lower\n\
8424 case equivalent is defined.) A non-nil value is appropriate for reading\n\
8425 a key sequence to be defined.\n\
8427 A C-g typed while in this function is treated like any other character,\n\
8428 and `quit-flag' is not set.\n\
8430 If the key sequence starts with a mouse click, then the sequence is read\n\
8431 using the keymaps of the buffer of the window clicked in, not the buffer\n\
8432 of the selected window as normal.\n\
8434 `read-key-sequence' drops unbound button-down events, since you normally\n\
8435 only care about the click or drag events which follow them. If a drag\n\
8436 or multi-click event is unbound, but the corresponding click event would\n\
8437 be bound, `read-key-sequence' turns the event into a click event at the\n\
8438 drag's starting position. This means that you don't have to distinguish\n\
8439 between click and drag, double, or triple events unless you want to.\n\
8441 `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\
8442 lines separating windows, and scroll bars with imaginary keys\n\
8443 `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\
8445 Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this\n\
8446 function will process a switch-frame event if the user switches frames\n\
8447 before typing anything. If the user switches frames in the middle of a\n\
8448 key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME\n\
8449 is nil, then the event will be put off until after the current key sequence.\n\
8451 `read-key-sequence' checks `function-key-map' for function key\n\
8452 sequences, where they wouldn't conflict with ordinary bindings. See\n\
8453 `function-key-map' for more details.\n\
8455 The optional fifth argument COMMAND-LOOP, if non-nil, means\n\
8456 that this key sequence is being read by something that will\n\
8457 read commands one after another. It should be nil if the caller\n\
8458 will read just one key sequence.")
8459 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
, command
-loop
)
8462 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 5, 0,
8464 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
8466 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
8467 Lisp_Object can_return_switch_frame
, command_loop
;
8469 Lisp_Object keybuf
[30];
8471 struct gcpro gcpro1
;
8472 int count
= specpdl_ptr
- specpdl
;
8475 CHECK_STRING (prompt
, 0);
8478 specbind (Qinput_method_exit_on_first_char
,
8479 (NILP (command_loop
) ? Qt
: Qnil
));
8480 specbind (Qinput_method_use_echo_area
,
8481 (NILP (command_loop
) ? Qt
: Qnil
));
8483 bzero (keybuf
, sizeof keybuf
);
8485 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
8487 if (NILP (continue_echo
))
8489 this_command_key_count
= 0;
8490 this_single_command_key_start
= 0;
8493 #ifdef HAVE_X_WINDOWS
8494 if (display_busy_cursor_p
)
8495 cancel_busy_cursor ();
8498 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
8499 prompt
, ! NILP (dont_downcase_last
),
8500 ! NILP (can_return_switch_frame
), 0);
8502 #ifdef HAVE_X_WINDOWS
8503 if (display_busy_cursor_p
)
8504 start_busy_cursor ();
8513 return unbind_to (count
, make_event_array (i
, keybuf
));
8516 DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector
,
8517 Sread_key_sequence_vector
, 1, 5, 0,
8518 "Like `read-key-sequence' but always return a vector.")
8519 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
,
8521 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
8522 Lisp_Object can_return_switch_frame
, command_loop
;
8524 Lisp_Object keybuf
[30];
8526 struct gcpro gcpro1
;
8527 int count
= specpdl_ptr
- specpdl
;
8530 CHECK_STRING (prompt
, 0);
8533 specbind (Qinput_method_exit_on_first_char
,
8534 (NILP (command_loop
) ? Qt
: Qnil
));
8535 specbind (Qinput_method_use_echo_area
,
8536 (NILP (command_loop
) ? Qt
: Qnil
));
8538 bzero (keybuf
, sizeof keybuf
);
8540 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
8542 if (NILP (continue_echo
))
8544 this_command_key_count
= 0;
8545 this_single_command_key_start
= 0;
8548 #ifdef HAVE_X_WINDOWS
8549 if (display_busy_cursor_p
)
8550 cancel_busy_cursor ();
8553 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
8554 prompt
, ! NILP (dont_downcase_last
),
8555 ! NILP (can_return_switch_frame
), 0);
8557 #ifdef HAVE_X_WINDOWS
8558 if (display_busy_cursor_p
)
8559 start_busy_cursor ();
8568 return unbind_to (count
, Fvector (i
, keybuf
));
8571 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 4, 0,
8572 "Execute CMD as an editor command.\n\
8573 CMD must be a symbol that satisfies the `commandp' predicate.\n\
8574 Optional second arg RECORD-FLAG non-nil\n\
8575 means unconditionally put this command in `command-history'.\n\
8576 Otherwise, that is done only if an arg is read using the minibuffer.\n\
8577 The argument KEYS specifies the value to use instead of (this-command-keys)\n\
8578 when reading the arguments; if it is nil, (this-command-keys) is used.\n\
8579 The argument SPECIAL, if non-nil, means that this command is executing\n\
8580 a special event, so ignore the prefix argument and don't clear it.")
8581 (cmd
, record_flag
, keys
, special
)
8582 Lisp_Object cmd
, record_flag
, keys
, special
;
8584 register Lisp_Object final
;
8585 register Lisp_Object tem
;
8586 Lisp_Object prefixarg
;
8587 struct backtrace backtrace
;
8588 extern int debug_on_next_call
;
8590 debug_on_next_call
= 0;
8594 prefixarg
= current_kboard
->Vprefix_arg
;
8595 Vcurrent_prefix_arg
= prefixarg
;
8596 current_kboard
->Vprefix_arg
= Qnil
;
8603 tem
= Fget (cmd
, Qdisabled
);
8604 if (!NILP (tem
) && !NILP (Vrun_hooks
))
8606 tem
= Fsymbol_value (Qdisabled_command_hook
);
8608 return call1 (Vrun_hooks
, Qdisabled_command_hook
);
8614 final
= Findirect_function (cmd
);
8616 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
8618 struct gcpro gcpro1
, gcpro2
;
8620 GCPRO2 (cmd
, prefixarg
);
8621 do_autoload (final
, cmd
);
8628 if (STRINGP (final
) || VECTORP (final
))
8630 /* If requested, place the macro in the command history. For
8631 other sorts of commands, call-interactively takes care of
8633 if (!NILP (record_flag
))
8636 = Fcons (Fcons (Qexecute_kbd_macro
,
8637 Fcons (final
, Fcons (prefixarg
, Qnil
))),
8640 /* Don't keep command history around forever. */
8641 if (NUMBERP (Vhistory_length
) && XINT (Vhistory_length
) > 0)
8643 tem
= Fnthcdr (Vhistory_length
, Vcommand_history
);
8649 return Fexecute_kbd_macro (final
, prefixarg
);
8652 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
8654 backtrace
.next
= backtrace_list
;
8655 backtrace_list
= &backtrace
;
8656 backtrace
.function
= &Qcall_interactively
;
8657 backtrace
.args
= &cmd
;
8658 backtrace
.nargs
= 1;
8659 backtrace
.evalargs
= 0;
8661 tem
= Fcall_interactively (cmd
, record_flag
, keys
);
8663 backtrace_list
= backtrace
.next
;
8669 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
8671 "Read function name, then read its arguments and call it.")
8673 Lisp_Object prefixarg
;
8675 Lisp_Object function
;
8677 Lisp_Object saved_keys
;
8678 Lisp_Object bindings
, value
;
8679 struct gcpro gcpro1
, gcpro2
;
8681 saved_keys
= Fvector (this_command_key_count
,
8682 XVECTOR (this_command_keys
)->contents
);
8684 GCPRO2 (saved_keys
, prefixarg
);
8686 if (EQ (prefixarg
, Qminus
))
8688 else if (CONSP (prefixarg
) && XINT (XCAR (prefixarg
)) == 4)
8689 strcpy (buf
, "C-u ");
8690 else if (CONSP (prefixarg
) && INTEGERP (XCAR (prefixarg
)))
8692 if (sizeof (int) == sizeof (EMACS_INT
))
8693 sprintf (buf
, "%d ", XINT (XCAR (prefixarg
)));
8694 else if (sizeof (long) == sizeof (EMACS_INT
))
8695 sprintf (buf
, "%ld ", (long) XINT (XCAR (prefixarg
)));
8699 else if (INTEGERP (prefixarg
))
8701 if (sizeof (int) == sizeof (EMACS_INT
))
8702 sprintf (buf
, "%d ", XINT (prefixarg
));
8703 else if (sizeof (long) == sizeof (EMACS_INT
))
8704 sprintf (buf
, "%ld ", (long) XINT (prefixarg
));
8709 /* This isn't strictly correct if execute-extended-command
8710 is bound to anything else. Perhaps it should use
8711 this_command_keys? */
8712 strcat (buf
, "M-x ");
8714 /* Prompt with buf, and then read a string, completing from and
8715 restricting to the set of all defined commands. Don't provide
8716 any initial input. Save the command read on the extended-command
8718 function
= Fcompleting_read (build_string (buf
),
8719 Vobarray
, Qcommandp
,
8720 Qt
, Qnil
, Qextended_command_history
, Qnil
,
8723 if (STRINGP (function
) && XSTRING (function
)->size
== 0)
8724 error ("No command name given");
8726 /* Set this_command_keys to the concatenation of saved_keys and
8727 function, followed by a RET. */
8729 struct Lisp_String
*str
;
8733 this_command_key_count
= 0;
8734 this_single_command_key_start
= 0;
8736 keys
= XVECTOR (saved_keys
)->contents
;
8737 for (i
= 0; i
< XVECTOR (saved_keys
)->size
; i
++)
8738 add_command_key (keys
[i
]);
8740 str
= XSTRING (function
);
8741 for (i
= 0; i
< str
->size
; i
++)
8742 add_command_key (Faref (function
, make_number (i
)));
8744 add_command_key (make_number ('\015'));
8749 function
= Fintern (function
, Qnil
);
8750 current_kboard
->Vprefix_arg
= prefixarg
;
8751 Vthis_command
= function
;
8752 real_this_command
= function
;
8754 /* If enabled, show which key runs this command. */
8755 if (!NILP (Vsuggest_key_bindings
)
8756 && NILP (Vexecuting_macro
)
8757 && SYMBOLP (function
))
8758 bindings
= Fwhere_is_internal (function
, Voverriding_local_map
,
8764 GCPRO2 (bindings
, value
);
8765 value
= Fcommand_execute (function
, Qt
, Qnil
, Qnil
);
8767 /* If the command has a key binding, print it now. */
8768 if (!NILP (bindings
)
8769 && ! (VECTORP (bindings
) && EQ (Faref (bindings
, make_number (0)),
8772 /* But first wait, and skip the message if there is input. */
8774 if (!NILP (echo_area_buffer
[0]))
8775 /* This command displayed something in the echo area;
8776 so wait a few seconds, then display our suggestion message. */
8777 delay_time
= (NUMBERP (Vsuggest_key_bindings
)
8778 ? XINT (Vsuggest_key_bindings
) : 2);
8780 /* This command left the echo area empty,
8781 so display our message immediately. */
8784 if (!NILP (Fsit_for (make_number (delay_time
), Qnil
, Qnil
))
8785 && ! CONSP (Vunread_command_events
))
8787 Lisp_Object binding
;
8789 int message_p
= push_message ();
8791 binding
= Fkey_description (bindings
);
8794 = (char *) alloca (XSYMBOL (function
)->name
->size
8795 + STRING_BYTES (XSTRING (binding
))
8797 sprintf (newmessage
, "You can run the command `%s' with %s",
8798 XSYMBOL (function
)->name
->data
,
8799 XSTRING (binding
)->data
);
8800 message2_nolog (newmessage
,
8801 strlen (newmessage
),
8802 STRING_MULTIBYTE (binding
));
8803 if (!NILP (Fsit_for ((NUMBERP (Vsuggest_key_bindings
)
8804 ? Vsuggest_key_bindings
: make_number (2)),
8813 RETURN_UNGCPRO (value
);
8816 /* Find the set of keymaps now active.
8817 Store into *MAPS_P a vector holding the various maps
8818 and return the number of them. The vector was malloc'd
8819 and the caller should free it. */
8822 current_active_maps (maps_p
)
8823 Lisp_Object
**maps_p
;
8825 Lisp_Object
*tmaps
, *maps
;
8828 /* Should overriding-terminal-local-map and overriding-local-map apply? */
8829 if (!NILP (Voverriding_local_map_menu_flag
))
8831 /* Yes, use them (if non-nil) as well as the global map. */
8832 maps
= (Lisp_Object
*) xmalloc (3 * sizeof (maps
[0]));
8834 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
8835 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
8836 if (!NILP (Voverriding_local_map
))
8837 maps
[nmaps
++] = Voverriding_local_map
;
8841 /* No, so use major and minor mode keymaps. */
8842 nmaps
= current_minor_maps (NULL
, &tmaps
);
8843 maps
= (Lisp_Object
*) xmalloc ((nmaps
+ 2) * sizeof (maps
[0]));
8844 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
8845 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
8847 maps
[nmaps
++] = current_global_map
;
8853 /* Return nonzero if input events are pending. */
8856 detect_input_pending ()
8859 get_input_pending (&input_pending
, 0);
8861 return input_pending
;
8864 /* Return nonzero if input events are pending, and run any pending timers. */
8867 detect_input_pending_run_timers (do_display
)
8870 int old_timers_run
= timers_run
;
8873 get_input_pending (&input_pending
, 1);
8875 if (old_timers_run
!= timers_run
&& do_display
)
8877 redisplay_preserve_echo_area ();
8878 /* The following fixes a bug when using lazy-lock with
8879 lazy-lock-defer-on-the-fly set to t, i.e. when fontifying
8880 from an idle timer function. The symptom of the bug is that
8881 the cursor sometimes doesn't become visible until the next X
8882 event is processed. --gerd. */
8884 rif
->flush_display (NULL
);
8887 return input_pending
;
8890 /* This is called in some cases before a possible quit.
8891 It cases the next call to detect_input_pending to recompute input_pending.
8892 So calling this function unnecessarily can't do any harm. */
8895 clear_input_pending ()
8900 /* Return nonzero if there are pending requeued events.
8901 This isn't used yet. The hope is to make wait_reading_process_input
8902 call it, and return return if it runs Lisp code that unreads something.
8903 The problem is, kbd_buffer_get_event needs to be fixed to know what
8904 to do in that case. It isn't trivial. */
8907 requeued_events_pending_p ()
8909 return (!NILP (Vunread_command_events
) || unread_command_char
!= -1);
8913 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
8914 "T if command input is currently available with no waiting.\n\
8915 Actually, the value is nil only if we can be sure that no input is available.")
8918 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1)
8921 get_input_pending (&input_pending
, 1);
8922 return input_pending
> 0 ? Qt
: Qnil
;
8925 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
8926 "Return vector of last 100 events, not counting those from keyboard macros.")
8929 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
8932 if (total_keys
< NUM_RECENT_KEYS
)
8933 return Fvector (total_keys
, keys
);
8936 val
= Fvector (NUM_RECENT_KEYS
, keys
);
8937 bcopy (keys
+ recent_keys_index
,
8938 XVECTOR (val
)->contents
,
8939 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
8941 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
8942 recent_keys_index
* sizeof (Lisp_Object
));
8947 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
8948 "Return the key sequence that invoked this command.\n\
8949 The value is a string or a vector.")
8952 return make_event_array (this_command_key_count
,
8953 XVECTOR (this_command_keys
)->contents
);
8956 DEFUN ("this-command-keys-vector", Fthis_command_keys_vector
, Sthis_command_keys_vector
, 0, 0, 0,
8957 "Return the key sequence that invoked this command, as a vector.")
8960 return Fvector (this_command_key_count
,
8961 XVECTOR (this_command_keys
)->contents
);
8964 DEFUN ("this-single-command-keys", Fthis_single_command_keys
,
8965 Sthis_single_command_keys
, 0, 0, 0,
8966 "Return the key sequence that invoked this command.\n\
8967 Unlike `this-command-keys', this function's value\n\
8968 does not include prefix arguments.\n\
8969 The value is always a vector.")
8972 return Fvector (this_command_key_count
8973 - this_single_command_key_start
,
8974 (XVECTOR (this_command_keys
)->contents
8975 + this_single_command_key_start
));
8978 DEFUN ("this-single-command-raw-keys", Fthis_single_command_raw_keys
,
8979 Sthis_single_command_raw_keys
, 0, 0, 0,
8980 "Return the raw events that were read for this command.\n\
8981 Unlike `this-single-command-keys', this function's value\n\
8982 shows the events before all translations (except for input methods).\n\
8983 The value is always a vector.")
8986 return Fvector (raw_keybuf_count
,
8987 (XVECTOR (raw_keybuf
)->contents
));
8990 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths
,
8991 Sreset_this_command_lengths
, 0, 0, 0,
8992 "Used for complicated reasons in `universal-argument-other-key'.\n\
8994 `universal-argument-other-key' rereads the event just typed.\n\
8995 It then gets translated through `function-key-map'.\n\
8996 The translated event gets included in the echo area and in\n\
8997 the value of `this-command-keys' in addition to the raw original event.\n\
8998 That is not right.\n\
9000 Calling this function directs the translated event to replace\n\
9001 the original event, so that only one version of the event actually\n\
9002 appears in the echo area and in the value of `this-command-keys.'.")
9005 before_command_restore_flag
= 1;
9006 before_command_key_count_1
= before_command_key_count
;
9007 before_command_echo_length_1
= before_command_echo_length
;
9011 DEFUN ("clear-this-command-keys", Fclear_this_command_keys
,
9012 Sclear_this_command_keys
, 0, 0, 0,
9013 "Clear out the vector that `this-command-keys' returns.\n\
9014 Clear vector containing last 100 events.")
9019 this_command_key_count
= 0;
9021 for (i
= 0; i
< XVECTOR (recent_keys
)->size
; ++i
)
9022 XVECTOR (recent_keys
)->contents
[i
] = Qnil
;
9024 recent_keys_index
= 0;
9028 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
9029 "Return the current depth in recursive edits.")
9033 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
9037 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
9038 "FOpen dribble file: ",
9039 "Start writing all keyboard characters to a dribble file called FILE.\n\
9040 If FILE is nil, close any open dribble file.")
9051 file
= Fexpand_file_name (file
, Qnil
);
9052 dribble
= fopen (XSTRING (file
)->data
, "w");
9054 report_file_error ("Opening dribble", Fcons (file
, Qnil
));
9059 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
9060 "Discard the contents of the terminal input buffer.\n\
9061 Also cancel any kbd macro being defined.")
9064 current_kboard
->defining_kbd_macro
= Qnil
;
9065 update_mode_lines
++;
9067 Vunread_command_events
= Qnil
;
9068 unread_command_char
= -1;
9070 discard_tty_input ();
9072 kbd_fetch_ptr
= kbd_store_ptr
;
9073 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
9079 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
9080 "Stop Emacs and return to superior process. You can resume later.\n\
9081 If `cannot-suspend' is non-nil, or if the system doesn't support job\n\
9082 control, run a subshell instead.\n\n\
9083 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
9084 to be read as terminal input by Emacs's parent, after suspension.\n\
9086 Before suspending, run the normal hook `suspend-hook'.\n\
9087 After resumption run the normal hook `suspend-resume-hook'.\n\
9089 Some operating systems cannot stop the Emacs process and resume it later.\n\
9090 On such systems, Emacs starts a subshell instead of suspending.")
9092 Lisp_Object stuffstring
;
9094 int count
= specpdl_ptr
- specpdl
;
9095 int old_height
, old_width
;
9097 struct gcpro gcpro1
;
9099 if (!NILP (stuffstring
))
9100 CHECK_STRING (stuffstring
, 0);
9102 /* Run the functions in suspend-hook. */
9103 if (!NILP (Vrun_hooks
))
9104 call1 (Vrun_hooks
, intern ("suspend-hook"));
9106 GCPRO1 (stuffstring
);
9107 get_frame_size (&old_width
, &old_height
);
9109 /* sys_suspend can get an error if it tries to fork a subshell
9110 and the system resources aren't available for that. */
9111 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object
))) init_sys_modes
,
9113 stuff_buffered_input (stuffstring
);
9118 unbind_to (count
, Qnil
);
9120 /* Check if terminal/window size has changed.
9121 Note that this is not useful when we are running directly
9122 with a window system; but suspend should be disabled in that case. */
9123 get_frame_size (&width
, &height
);
9124 if (width
!= old_width
|| height
!= old_height
)
9125 change_frame_size (SELECTED_FRAME (), height
, width
, 0, 0, 0);
9127 /* Run suspend-resume-hook. */
9128 if (!NILP (Vrun_hooks
))
9129 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
9135 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
9136 Then in any case stuff anything Emacs has read ahead and not used. */
9139 stuff_buffered_input (stuffstring
)
9140 Lisp_Object stuffstring
;
9142 /* stuff_char works only in BSD, versions 4.2 and up. */
9145 register unsigned char *p
;
9147 if (STRINGP (stuffstring
))
9151 p
= XSTRING (stuffstring
)->data
;
9152 count
= STRING_BYTES (XSTRING (stuffstring
));
9157 /* Anything we have read ahead, put back for the shell to read. */
9158 /* ?? What should this do when we have multiple keyboards??
9159 Should we ignore anything that was typed in at the "wrong" kboard? */
9160 for (; kbd_fetch_ptr
!= kbd_store_ptr
; kbd_fetch_ptr
++)
9162 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
9163 kbd_fetch_ptr
= kbd_buffer
;
9164 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
9165 stuff_char (kbd_fetch_ptr
->code
);
9166 kbd_fetch_ptr
->kind
= no_event
;
9167 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_fetch_ptr
9173 #endif /* BSD_SYSTEM and not BSD4_1 */
9177 set_waiting_for_input (time_to_clear
)
9178 EMACS_TIME
*time_to_clear
;
9180 input_available_clear_time
= time_to_clear
;
9182 /* Tell interrupt_signal to throw back to read_char, */
9183 waiting_for_input
= 1;
9185 /* If interrupt_signal was called before and buffered a C-g,
9186 make it run again now, to avoid timing error. */
9187 if (!NILP (Vquit_flag
))
9188 quit_throw_to_read_char ();
9192 clear_waiting_for_input ()
9194 /* Tell interrupt_signal not to throw back to read_char, */
9195 waiting_for_input
= 0;
9196 input_available_clear_time
= 0;
9199 /* This routine is called at interrupt level in response to C-G.
9200 If interrupt_input, this is the handler for SIGINT.
9201 Otherwise, it is called from kbd_buffer_store_event,
9202 in handling SIGIO or SIGTINT.
9204 If `waiting_for_input' is non zero, then unless `echoing' is nonzero,
9205 immediately throw back to read_char.
9207 Otherwise it sets the Lisp variable quit-flag not-nil.
9208 This causes eval to throw, when it gets a chance.
9209 If quit-flag is already non-nil, it stops the job right away. */
9212 interrupt_signal (signalnum
) /* If we don't have an argument, */
9213 int signalnum
; /* some compilers complain in signal calls. */
9216 /* Must preserve main program's value of errno. */
9217 int old_errno
= errno
;
9218 struct frame
*sf
= SELECTED_FRAME ();
9220 #if defined (USG) && !defined (POSIX_SIGNALS)
9221 if (!read_socket_hook
&& NILP (Vwindow_system
))
9223 /* USG systems forget handlers when they are used;
9224 must reestablish each time */
9225 signal (SIGINT
, interrupt_signal
);
9226 signal (SIGQUIT
, interrupt_signal
);
9232 if (!NILP (Vquit_flag
)
9233 && (FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
)))
9235 /* If SIGINT isn't blocked, don't let us be interrupted by
9236 another SIGINT, it might be harmful due to non-reentrancy
9237 in I/O functions. */
9238 sigblock (sigmask (SIGINT
));
9243 #ifdef SIGTSTP /* Support possible in later USG versions */
9245 * On systems which can suspend the current process and return to the original
9246 * shell, this command causes the user to end up back at the shell.
9247 * The "Auto-save" and "Abort" questions are not asked until
9248 * the user elects to return to emacs, at which point he can save the current
9249 * job and either dump core or continue.
9254 if (sys_suspend () == -1)
9256 printf ("Not running as a subprocess;\n");
9257 printf ("you can continue or abort.\n");
9260 /* Perhaps should really fork an inferior shell?
9261 But that would not provide any way to get back
9262 to the original shell, ever. */
9263 printf ("No support for stopping a process on this operating system;\n");
9264 printf ("you can continue or abort.\n");
9265 #endif /* not VMS */
9266 #endif /* not SIGTSTP */
9268 /* We must remain inside the screen area when the internal terminal
9269 is used. Note that [Enter] is not echoed by dos. */
9272 /* It doesn't work to autosave while GC is in progress;
9273 the code used for auto-saving doesn't cope with the mark bit. */
9274 if (!gc_in_progress
)
9276 printf ("Auto-save? (y or n) ");
9278 if (((c
= getchar ()) & ~040) == 'Y')
9280 Fdo_auto_save (Qt
, Qnil
);
9282 printf ("\r\nAuto-save done");
9283 #else /* not MSDOS */
9284 printf ("Auto-save done\n");
9285 #endif /* not MSDOS */
9287 while (c
!= '\n') c
= getchar ();
9291 /* During GC, it must be safe to reenable quitting again. */
9292 Vinhibit_quit
= Qnil
;
9295 #endif /* not MSDOS */
9296 printf ("Garbage collection in progress; cannot auto-save now\r\n");
9297 printf ("but will instead do a real quit after garbage collection ends\r\n");
9302 printf ("\r\nAbort? (y or n) ");
9303 #else /* not MSDOS */
9305 printf ("Abort (and enter debugger)? (y or n) ");
9307 printf ("Abort (and dump core)? (y or n) ");
9308 #endif /* not VMS */
9309 #endif /* not MSDOS */
9311 if (((c
= getchar ()) & ~040) == 'Y')
9313 while (c
!= '\n') c
= getchar ();
9315 printf ("\r\nContinuing...\r\n");
9316 #else /* not MSDOS */
9317 printf ("Continuing...\n");
9318 #endif /* not MSDOS */
9325 /* If executing a function that wants to be interrupted out of
9326 and the user has not deferred quitting by binding `inhibit-quit'
9327 then quit right away. */
9328 if (immediate_quit
&& NILP (Vinhibit_quit
))
9330 struct gl_state_s saved
;
9331 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9336 GCPRO4 (saved
.object
, saved
.global_code
,
9337 saved
.current_syntax_table
, saved
.old_prop
);
9338 Fsignal (Qquit
, Qnil
);
9343 /* Else request quit when it's safe */
9347 if (waiting_for_input
&& !echoing
)
9348 quit_throw_to_read_char ();
9353 /* Handle a C-g by making read_char return C-g. */
9356 quit_throw_to_read_char ()
9359 /* Prevent another signal from doing this before we finish. */
9360 clear_waiting_for_input ();
9363 Vunread_command_events
= Qnil
;
9364 unread_command_char
= -1;
9366 #if 0 /* Currently, sit_for is called from read_char without turning
9367 off polling. And that can call set_waiting_for_input.
9368 It seems to be harmless. */
9369 #ifdef POLL_FOR_INPUT
9370 /* May be > 1 if in recursive minibuffer. */
9371 if (poll_suppress_count
== 0)
9375 if (FRAMEP (internal_last_event_frame
)
9376 && !EQ (internal_last_event_frame
, selected_frame
))
9377 do_switch_frame (make_lispy_switch_frame (internal_last_event_frame
),
9380 _longjmp (getcjmp
, 1);
9383 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
9384 "Set mode of reading keyboard input.\n\
9385 First arg INTERRUPT non-nil means use input interrupts;\n\
9386 nil means use CBREAK mode.\n\
9387 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
9388 (no effect except in CBREAK mode).\n\
9389 Third arg META t means accept 8-bit input (for a Meta key).\n\
9390 META nil means ignore the top bit, on the assumption it is parity.\n\
9391 Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\
9392 Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\
9393 See also `current-input-mode'.")
9394 (interrupt
, flow
, meta
, quit
)
9395 Lisp_Object interrupt
, flow
, meta
, quit
;
9398 && (!INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400))
9399 error ("set-input-mode: QUIT must be an ASCII character");
9401 #ifdef POLL_FOR_INPUT
9406 /* this causes startup screen to be restored and messes with the mouse */
9411 /* Note SIGIO has been undef'd if FIONREAD is missing. */
9412 if (read_socket_hook
)
9414 /* When using X, don't give the user a real choice,
9415 because we haven't implemented the mechanisms to support it. */
9416 #ifdef NO_SOCK_SIGIO
9417 interrupt_input
= 0;
9418 #else /* not NO_SOCK_SIGIO */
9419 interrupt_input
= 1;
9420 #endif /* NO_SOCK_SIGIO */
9423 interrupt_input
= !NILP (interrupt
);
9424 #else /* not SIGIO */
9425 interrupt_input
= 0;
9426 #endif /* not SIGIO */
9428 /* Our VMS input only works by interrupts, as of now. */
9430 interrupt_input
= 1;
9433 flow_control
= !NILP (flow
);
9436 else if (EQ (meta
, Qt
))
9441 /* Don't let this value be out of range. */
9442 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
9448 #ifdef POLL_FOR_INPUT
9449 poll_suppress_count
= 1;
9455 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
9456 "Return information about the way Emacs currently reads keyboard input.\n\
9457 The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
9458 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\
9459 nil, Emacs is using CBREAK mode.\n\
9460 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\
9461 terminal; this does not apply if Emacs uses interrupt-driven input.\n\
9462 META is t if accepting 8-bit input with 8th bit as Meta flag.\n\
9463 META nil means ignoring the top bit, on the assumption it is parity.\n\
9464 META is neither t nor nil if accepting 8-bit input and using\n\
9465 all 8 bits as the character code.\n\
9466 QUIT is the character Emacs currently uses to quit.\n\
9467 The elements of this list correspond to the arguments of\n\
9473 val
[0] = interrupt_input
? Qt
: Qnil
;
9474 val
[1] = flow_control
? Qt
: Qnil
;
9475 val
[2] = meta_key
== 2 ? make_number (0) : meta_key
== 1 ? Qt
: Qnil
;
9476 XSETFASTINT (val
[3], quit_char
);
9478 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
9483 * Set up a new kboard object with reasonable initial values.
9489 kb
->Voverriding_terminal_local_map
= Qnil
;
9490 kb
->Vlast_command
= Qnil
;
9491 kb
->Vreal_last_command
= Qnil
;
9492 kb
->Vprefix_arg
= Qnil
;
9493 kb
->Vlast_prefix_arg
= Qnil
;
9494 kb
->kbd_queue
= Qnil
;
9495 kb
->kbd_queue_has_data
= 0;
9496 kb
->immediate_echo
= 0;
9497 kb
->echoptr
= kb
->echobuf
;
9498 kb
->echo_after_prompt
= -1;
9499 kb
->kbd_macro_buffer
= 0;
9500 kb
->kbd_macro_bufsize
= 0;
9501 kb
->defining_kbd_macro
= Qnil
;
9502 kb
->Vlast_kbd_macro
= Qnil
;
9503 kb
->reference_count
= 0;
9504 kb
->Vsystem_key_alist
= Qnil
;
9505 kb
->system_key_syms
= Qnil
;
9506 kb
->Vdefault_minibuffer_frame
= Qnil
;
9510 * Destroy the contents of a kboard object, but not the object itself.
9511 * We use this just before deleting it, or if we're going to initialize
9518 if (kb
->kbd_macro_buffer
)
9519 xfree (kb
->kbd_macro_buffer
);
9528 for (kbp
= &all_kboards
; *kbp
!= kb
; kbp
= &(*kbp
)->next_kboard
)
9531 *kbp
= kb
->next_kboard
;
9540 /* This is correct before outermost invocation of the editor loop */
9541 command_loop_level
= -1;
9543 quit_char
= Ctl ('g');
9544 Vunread_command_events
= Qnil
;
9545 unread_command_char
= -1;
9546 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
9548 recent_keys_index
= 0;
9549 kbd_fetch_ptr
= kbd_buffer
;
9550 kbd_store_ptr
= kbd_buffer
;
9551 kbd_buffer_frame_or_window
9552 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
9554 do_mouse_tracking
= Qnil
;
9558 /* This means that command_loop_1 won't try to select anything the first
9560 internal_last_event_frame
= Qnil
;
9561 Vlast_event_frame
= internal_last_event_frame
;
9564 current_kboard
= initial_kboard
;
9566 wipe_kboard (current_kboard
);
9567 init_kboard (current_kboard
);
9570 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
9572 kbd_buffer_frame_or_window
9573 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
9574 if (!noninteractive
&& !read_socket_hook
&& NILP (Vwindow_system
))
9576 signal (SIGINT
, interrupt_signal
);
9577 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
9578 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
9579 SIGQUIT and we can't tell which one it will give us. */
9580 signal (SIGQUIT
, interrupt_signal
);
9581 #endif /* HAVE_TERMIO */
9583 /* Note SIGIO has been undef'd if FIONREAD is missing. */
9585 if (!noninteractive
)
9586 signal (SIGIO
, input_available_signal
);
9589 /* Use interrupt input by default, if it works and noninterrupt input
9590 has deficiencies. */
9592 #ifdef INTERRUPT_INPUT
9593 interrupt_input
= 1;
9595 interrupt_input
= 0;
9598 /* Our VMS input only works by interrupts, as of now. */
9600 interrupt_input
= 1;
9606 if (keyboard_init_hook
)
9607 (*keyboard_init_hook
) ();
9609 #ifdef POLL_FOR_INPUT
9610 poll_suppress_count
= 1;
9615 /* This type's only use is in syms_of_keyboard, to initialize the
9616 event header symbols and put properties on them. */
9623 struct event_head head_table
[] = {
9624 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
9625 &Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
,
9626 &Qswitch_frame
, "switch-frame", &Qswitch_frame
,
9627 &Qdelete_frame
, "delete-frame", &Qdelete_frame
,
9628 &Qiconify_frame
, "iconify-frame", &Qiconify_frame
,
9629 &Qmake_frame_visible
, "make-frame-visible", &Qmake_frame_visible
,
9636 QCimage
= intern (":image");
9637 staticpro (&QCimage
);
9639 staticpro (&Qhelp_echo
);
9640 Qhelp_echo
= intern ("help-echo");
9642 staticpro (&item_properties
);
9643 item_properties
= Qnil
;
9645 staticpro (&tool_bar_item_properties
);
9646 tool_bar_item_properties
= Qnil
;
9647 staticpro (&tool_bar_items_vector
);
9648 tool_bar_items_vector
= Qnil
;
9650 staticpro (&real_this_command
);
9651 real_this_command
= Qnil
;
9653 Qtimer_event_handler
= intern ("timer-event-handler");
9654 staticpro (&Qtimer_event_handler
);
9656 Qdisabled_command_hook
= intern ("disabled-command-hook");
9657 staticpro (&Qdisabled_command_hook
);
9659 Qself_insert_command
= intern ("self-insert-command");
9660 staticpro (&Qself_insert_command
);
9662 Qforward_char
= intern ("forward-char");
9663 staticpro (&Qforward_char
);
9665 Qbackward_char
= intern ("backward-char");
9666 staticpro (&Qbackward_char
);
9668 Qdisabled
= intern ("disabled");
9669 staticpro (&Qdisabled
);
9671 Qundefined
= intern ("undefined");
9672 staticpro (&Qundefined
);
9674 Qpre_command_hook
= intern ("pre-command-hook");
9675 staticpro (&Qpre_command_hook
);
9677 Qpost_command_hook
= intern ("post-command-hook");
9678 staticpro (&Qpost_command_hook
);
9680 Qpost_command_idle_hook
= intern ("post-command-idle-hook");
9681 staticpro (&Qpost_command_idle_hook
);
9683 Qdeferred_action_function
= intern ("deferred-action-function");
9684 staticpro (&Qdeferred_action_function
);
9686 Qcommand_hook_internal
= intern ("command-hook-internal");
9687 staticpro (&Qcommand_hook_internal
);
9689 Qfunction_key
= intern ("function-key");
9690 staticpro (&Qfunction_key
);
9691 Qmouse_click
= intern ("mouse-click");
9692 staticpro (&Qmouse_click
);
9694 Qmouse_wheel
= intern ("mouse-wheel");
9695 staticpro (&Qmouse_wheel
);
9696 Qlanguage_change
= intern ("language-change");
9697 staticpro (&Qlanguage_change
);
9699 Qdrag_n_drop
= intern ("drag-n-drop");
9700 staticpro (&Qdrag_n_drop
);
9702 Qusr1_signal
= intern ("usr1-signal");
9703 staticpro (&Qusr1_signal
);
9704 Qusr2_signal
= intern ("usr2-signal");
9705 staticpro (&Qusr2_signal
);
9707 Qmenu_enable
= intern ("menu-enable");
9708 staticpro (&Qmenu_enable
);
9709 Qmenu_alias
= intern ("menu-alias");
9710 staticpro (&Qmenu_alias
);
9711 QCenable
= intern (":enable");
9712 staticpro (&QCenable
);
9713 QCvisible
= intern (":visible");
9714 staticpro (&QCvisible
);
9715 QChelp
= intern (":help");
9716 staticpro (&QChelp
);
9717 QCfilter
= intern (":filter");
9718 staticpro (&QCfilter
);
9719 QCbutton
= intern (":button");
9720 staticpro (&QCbutton
);
9721 QCkeys
= intern (":keys");
9722 staticpro (&QCkeys
);
9723 QCkey_sequence
= intern (":key-sequence");
9724 staticpro (&QCkey_sequence
);
9725 QCtoggle
= intern (":toggle");
9726 staticpro (&QCtoggle
);
9727 QCradio
= intern (":radio");
9728 staticpro (&QCradio
);
9730 Qmode_line
= intern ("mode-line");
9731 staticpro (&Qmode_line
);
9732 Qvertical_line
= intern ("vertical-line");
9733 staticpro (&Qvertical_line
);
9734 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
9735 staticpro (&Qvertical_scroll_bar
);
9736 Qmenu_bar
= intern ("menu-bar");
9737 staticpro (&Qmenu_bar
);
9739 Qabove_handle
= intern ("above-handle");
9740 staticpro (&Qabove_handle
);
9741 Qhandle
= intern ("handle");
9742 staticpro (&Qhandle
);
9743 Qbelow_handle
= intern ("below-handle");
9744 staticpro (&Qbelow_handle
);
9745 Qup
= intern ("up");
9747 Qdown
= intern ("down");
9749 Qtop
= intern ("top");
9751 Qbottom
= intern ("bottom");
9752 staticpro (&Qbottom
);
9753 Qend_scroll
= intern ("end-scroll");
9754 staticpro (&Qend_scroll
);
9755 Qratio
= intern ("ratio");
9756 staticpro (&Qratio
);
9758 Qevent_kind
= intern ("event-kind");
9759 staticpro (&Qevent_kind
);
9760 Qevent_symbol_elements
= intern ("event-symbol-elements");
9761 staticpro (&Qevent_symbol_elements
);
9762 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
9763 staticpro (&Qevent_symbol_element_mask
);
9764 Qmodifier_cache
= intern ("modifier-cache");
9765 staticpro (&Qmodifier_cache
);
9767 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
9768 staticpro (&Qrecompute_lucid_menubar
);
9769 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
9770 staticpro (&Qactivate_menubar_hook
);
9772 Qpolling_period
= intern ("polling-period");
9773 staticpro (&Qpolling_period
);
9775 Qinput_method_function
= intern ("input-method-function");
9776 staticpro (&Qinput_method_function
);
9778 Qinput_method_exit_on_first_char
= intern ("input-method-exit-on-first-char");
9779 staticpro (&Qinput_method_exit_on_first_char
);
9780 Qinput_method_use_echo_area
= intern ("input-method-use-echo-area");
9781 staticpro (&Qinput_method_use_echo_area
);
9783 Fset (Qinput_method_exit_on_first_char
, Qnil
);
9784 Fset (Qinput_method_use_echo_area
, Qnil
);
9787 struct event_head
*p
;
9789 for (p
= head_table
;
9790 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
9793 *p
->var
= intern (p
->name
);
9795 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
9796 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
9800 button_down_location
= Fmake_vector (make_number (NUM_MOUSE_BUTTONS
), Qnil
);
9801 staticpro (&button_down_location
);
9805 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
9807 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
9808 for (i
= 0; i
< len
; i
++)
9809 if (modifier_names
[i
])
9810 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
9811 staticpro (&modifier_symbols
);
9814 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
9815 staticpro (&recent_keys
);
9817 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
9818 staticpro (&this_command_keys
);
9820 raw_keybuf
= Fmake_vector (make_number (30), Qnil
);
9821 staticpro (&raw_keybuf
);
9823 Qextended_command_history
= intern ("extended-command-history");
9824 Fset (Qextended_command_history
, Qnil
);
9825 staticpro (&Qextended_command_history
);
9827 kbd_buffer_frame_or_window
9828 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
9829 staticpro (&kbd_buffer_frame_or_window
);
9831 accent_key_syms
= Qnil
;
9832 staticpro (&accent_key_syms
);
9834 func_key_syms
= Qnil
;
9835 staticpro (&func_key_syms
);
9838 staticpro (&mouse_syms
);
9841 mouse_wheel_syms
= Qnil
;
9842 staticpro (&mouse_wheel_syms
);
9844 drag_n_drop_syms
= Qnil
;
9845 staticpro (&drag_n_drop_syms
);
9848 unread_switch_frame
= Qnil
;
9849 staticpro (&unread_switch_frame
);
9851 internal_last_event_frame
= Qnil
;
9852 staticpro (&internal_last_event_frame
);
9854 read_key_sequence_cmd
= Qnil
;
9855 staticpro (&read_key_sequence_cmd
);
9857 menu_bar_one_keymap_changed_items
= Qnil
;
9858 staticpro (&menu_bar_one_keymap_changed_items
);
9860 defsubr (&Sevent_convert_list
);
9861 defsubr (&Sread_key_sequence
);
9862 defsubr (&Sread_key_sequence_vector
);
9863 defsubr (&Srecursive_edit
);
9865 defsubr (&Strack_mouse
);
9867 defsubr (&Sinput_pending_p
);
9868 defsubr (&Scommand_execute
);
9869 defsubr (&Srecent_keys
);
9870 defsubr (&Sthis_command_keys
);
9871 defsubr (&Sthis_command_keys_vector
);
9872 defsubr (&Sthis_single_command_keys
);
9873 defsubr (&Sthis_single_command_raw_keys
);
9874 defsubr (&Sreset_this_command_lengths
);
9875 defsubr (&Sclear_this_command_keys
);
9876 defsubr (&Ssuspend_emacs
);
9877 defsubr (&Sabort_recursive_edit
);
9878 defsubr (&Sexit_recursive_edit
);
9879 defsubr (&Srecursion_depth
);
9880 defsubr (&Stop_level
);
9881 defsubr (&Sdiscard_input
);
9882 defsubr (&Sopen_dribble_file
);
9883 defsubr (&Sset_input_mode
);
9884 defsubr (&Scurrent_input_mode
);
9885 defsubr (&Sexecute_extended_command
);
9887 DEFVAR_LISP ("last-command-char", &last_command_char
,
9888 "Last input event that was part of a command.");
9890 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char
,
9891 "Last input event that was part of a command.");
9893 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
9894 "Last input event in a command, except for mouse menu events.\n\
9895 Mouse menus give back keys that don't look like mouse events;\n\
9896 this variable holds the actual mouse event that led to the menu,\n\
9897 so that you can determine whether the command was run by mouse or not.");
9899 DEFVAR_LISP ("last-input-char", &last_input_char
,
9900 "Last input event.");
9902 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char
,
9903 "Last input event.");
9905 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
9906 "List of events to be read as the command input.\n\
9907 These events are processed first, before actual keyboard input.");
9908 Vunread_command_events
= Qnil
;
9910 DEFVAR_INT ("unread-command-char", &unread_command_char
,
9911 "If not -1, an object to be read as next command input event.");
9913 DEFVAR_LISP ("unread-post-input-method-events", &Vunread_post_input_method_events
,
9914 "List of events to be processed as input by input methods.\n\
9915 These events are processed after `unread-command-events', but\n\
9916 before actual keyboard input.");
9917 Vunread_post_input_method_events
= Qnil
;
9919 DEFVAR_LISP ("unread-input-method-events", &Vunread_input_method_events
,
9920 "List of events to be processed as input by input methods.\n\
9921 These events are processed after `unread-command-events', but\n\
9922 before actual keyboard input.");
9923 Vunread_input_method_events
= Qnil
;
9925 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
9926 "Meta-prefix character code.\n\
9927 Meta-foo as command input turns into this character followed by foo.");
9928 XSETINT (meta_prefix_char
, 033);
9930 DEFVAR_KBOARD ("last-command", Vlast_command
,
9931 "The last command executed.\n\
9932 Normally a symbol with a function definition, but can be whatever was found\n\
9933 in the keymap, or whatever the variable `this-command' was set to by that\n\
9936 The value `mode-exit' is special; it means that the previous command\n\
9937 read an event that told it to exit, and it did so and unread that event.\n\
9938 In other words, the present command is the event that made the previous\n\
9941 The value `kill-region' is special; it means that the previous command\n\
9942 was a kill command.");
9944 DEFVAR_KBOARD ("real-last-command", Vreal_last_command
,
9945 "Same as `last-command', but never altered by Lisp code.");
9947 DEFVAR_LISP ("this-command", &Vthis_command
,
9948 "The command now being executed.\n\
9949 The command can set this variable; whatever is put here\n\
9950 will be in `last-command' during the following command.");
9951 Vthis_command
= Qnil
;
9953 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
9954 "*Number of input events between auto-saves.\n\
9955 Zero means disable autosaving due to number of characters typed.");
9956 auto_save_interval
= 300;
9958 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
9959 "*Number of seconds idle time before auto-save.\n\
9960 Zero or nil means disable auto-saving due to idleness.\n\
9961 After auto-saving due to this many seconds of idle time,\n\
9962 Emacs also does a garbage collection if that seems to be warranted.");
9963 XSETFASTINT (Vauto_save_timeout
, 30);
9965 DEFVAR_LISP ("echo-keystrokes", &Vecho_keystrokes
,
9966 "*Nonzero means echo unfinished commands after this many seconds of pause.\n\
9967 The value may be integer or floating point.");
9968 Vecho_keystrokes
= make_number (1);
9970 DEFVAR_INT ("polling-period", &polling_period
,
9971 "*Interval between polling for input during Lisp execution.\n\
9972 The reason for polling is to make C-g work to stop a running program.\n\
9973 Polling is needed only when using X windows and SIGIO does not work.\n\
9974 Polling is automatically disabled in all other cases.");
9977 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
9978 "*Maximum time between mouse clicks to make a double-click.\n\
9979 Measured in milliseconds. nil means disable double-click recognition;\n\
9980 t means double-clicks have no time limit and are detected\n\
9981 by position only.");
9982 Vdouble_click_time
= make_number (500);
9984 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
9985 "*Non-nil means inhibit local map menu bar menus.");
9986 inhibit_local_menu_bar_menus
= 0;
9988 DEFVAR_INT ("num-input-keys", &num_input_keys
,
9989 "Number of complete key sequences read as input so far.\n\
9990 This includes key sequences read from keyboard macros.\n\
9991 The number is effectively the number of interactive command invocations.");
9994 DEFVAR_INT ("num-nonmacro-input-events", &num_nonmacro_input_events
,
9995 "Number of input events read from the keyboard so far.\n\
9996 This does not include events generated by keyboard macros.");
9997 num_nonmacro_input_events
= 0;
9999 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
10000 "The frame in which the most recently read event occurred.\n\
10001 If the last event came from a keyboard macro, this is set to `macro'.");
10002 Vlast_event_frame
= Qnil
;
10004 /* This variable is set up in sysdep.c. */
10005 DEFVAR_LISP ("tty-erase-char", &Vtty_erase_char
,
10006 "The ERASE character as set by the user with stty.");
10008 DEFVAR_LISP ("help-char", &Vhelp_char
,
10009 "Character to recognize as meaning Help.\n\
10010 When it is read, do `(eval help-form)', and display result if it's a string.\n\
10011 If the value of `help-form' is nil, this char can be read normally.");
10012 XSETINT (Vhelp_char
, Ctl ('H'));
10014 DEFVAR_LISP ("help-event-list", &Vhelp_event_list
,
10015 "List of input events to recognize as meaning Help.\n\
10016 These work just like the value of `help-char' (see that).");
10017 Vhelp_event_list
= Qnil
;
10019 DEFVAR_LISP ("help-form", &Vhelp_form
,
10020 "Form to execute when character `help-char' is read.\n\
10021 If the form returns a string, that string is displayed.\n\
10022 If `help-form' is nil, the help char is not recognized.");
10025 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
10026 "Command to run when `help-char' character follows a prefix key.\n\
10027 This command is used only when there is no actual binding\n\
10028 for that character after that prefix key.");
10029 Vprefix_help_command
= Qnil
;
10031 DEFVAR_LISP ("top-level", &Vtop_level
,
10032 "Form to evaluate when Emacs starts up.\n\
10033 Useful to set before you dump a modified Emacs.");
10036 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
10037 "Translate table for keyboard input, or nil.\n\
10038 Each character is looked up in this string and the contents used instead.\n\
10039 The value may be a string, a vector, or a char-table.\n\
10040 If it is a string or vector of length N,\n\
10041 character codes N and up are untranslated.\n\
10042 In a vector or a char-table, an element which is nil means \"no translation\".");
10043 Vkeyboard_translate_table
= Qnil
;
10045 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
10046 "Non-nil means to always spawn a subshell instead of suspending.\n\
10047 \(Even if the operating system has support for stopping a process.\)");
10048 cannot_suspend
= 0;
10050 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
10051 "Non-nil means prompt with menus when appropriate.\n\
10052 This is done when reading from a keymap that has a prompt string,\n\
10053 for elements that have prompt strings.\n\
10054 The menu is displayed on the screen\n\
10055 if X menus were enabled at configuration\n\
10056 time and the previous event was a mouse click prefix key.\n\
10057 Otherwise, menu prompting uses the echo area.");
10058 menu_prompting
= 1;
10060 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
10061 "Character to see next line of menu prompt.\n\
10062 Type this character while in a menu prompt to rotate around the lines of it.");
10063 XSETINT (menu_prompt_more_char
, ' ');
10065 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
10066 "A mask of additional modifier keys to use with every keyboard character.\n\
10067 Emacs applies the modifiers of the character stored here to each keyboard\n\
10068 character it reads. For example, after evaluating the expression\n\
10069 (setq extra-keyboard-modifiers ?\\C-x)\n\
10070 all input characters will have the control modifier applied to them.\n\
10072 Note that the character ?\\C-@, equivalent to the integer zero, does\n\
10073 not count as a control character; rather, it counts as a character\n\
10074 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\
10075 cancels any modification.");
10076 extra_keyboard_modifiers
= 0;
10078 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
10079 "If an editing command sets this to t, deactivate the mark afterward.\n\
10080 The command loop sets this to nil before each command,\n\
10081 and tests the value when the command returns.\n\
10082 Buffer modification stores t in this variable.");
10083 Vdeactivate_mark
= Qnil
;
10085 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
10086 "Temporary storage of pre-command-hook or post-command-hook.");
10087 Vcommand_hook_internal
= Qnil
;
10089 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
10090 "Normal hook run before each command is executed.\n\
10091 If an unhandled error happens in running this hook,\n\
10092 the hook value is set to nil, since otherwise the error\n\
10093 might happen repeatedly and make Emacs nonfunctional.");
10094 Vpre_command_hook
= Qnil
;
10096 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
10097 "Normal hook run after each command is executed.\n\
10098 If an unhandled error happens in running this hook,\n\
10099 the hook value is set to nil, since otherwise the error\n\
10100 might happen repeatedly and make Emacs nonfunctional.");
10101 Vpost_command_hook
= Qnil
;
10103 DEFVAR_LISP ("post-command-idle-hook", &Vpost_command_idle_hook
,
10104 "Normal hook run after each command is executed, if idle.\n\
10105 Errors running the hook are caught and ignored.\n\
10106 This feature is obsolete; use idle timers instead. See `etc/NEWS'.");
10107 Vpost_command_idle_hook
= Qnil
;
10109 DEFVAR_INT ("post-command-idle-delay", &post_command_idle_delay
,
10110 "Delay time before running `post-command-idle-hook'.\n\
10111 This is measured in microseconds.");
10112 post_command_idle_delay
= 100000;
10115 DEFVAR_LISP ("echo-area-clear-hook", ...,
10116 "Normal hook run when clearing the echo area.");
10118 Qecho_area_clear_hook
= intern ("echo-area-clear-hook");
10119 XSYMBOL (Qecho_area_clear_hook
)->value
= Qnil
;
10121 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
10122 "t means menu bar, specified Lucid style, needs to be recomputed.");
10123 Vlucid_menu_bar_dirty_flag
= Qnil
;
10125 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
10126 "List of menu bar items to move to the end of the menu bar.\n\
10127 The elements of the list are event types that may have menu bar bindings.");
10128 Vmenu_bar_final_items
= Qnil
;
10130 DEFVAR_KBOARD ("overriding-terminal-local-map",
10131 Voverriding_terminal_local_map
,
10132 "Per-terminal keymap that overrides all other local keymaps.\n\
10133 If this variable is non-nil, it is used as a keymap instead of the\n\
10134 buffer's local map, and the minor mode keymaps and text property keymaps.\n\
10135 This variable is intended to let commands such as `universal-argumemnt'\n\
10136 set up a different keymap for reading the next command.");
10138 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
10139 "Keymap that overrides all other local keymaps.\n\
10140 If this variable is non-nil, it is used as a keymap instead of the\n\
10141 buffer's local map, and the minor mode keymaps and text property keymaps.");
10142 Voverriding_local_map
= Qnil
;
10144 DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag
,
10145 "Non-nil means `overriding-local-map' applies to the menu bar.\n\
10146 Otherwise, the menu bar continues to reflect the buffer's local map\n\
10147 and the minor mode maps regardless of `overriding-local-map'.");
10148 Voverriding_local_map_menu_flag
= Qnil
;
10150 DEFVAR_LISP ("special-event-map", &Vspecial_event_map
,
10151 "Keymap defining bindings for special events to execute at low level.");
10152 Vspecial_event_map
= Fcons (intern ("keymap"), Qnil
);
10154 DEFVAR_LISP ("track-mouse", &do_mouse_tracking
,
10155 "*Non-nil means generate motion events for mouse motion.");
10157 DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist
,
10158 "Alist of system-specific X windows key symbols.\n\
10159 Each element should have the form (N . SYMBOL) where N is the\n\
10160 numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\
10161 and SYMBOL is its name.");
10163 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
10164 "List of deferred actions to be performed at a later time.\n\
10165 The precise format isn't relevant here; we just check whether it is nil.");
10166 Vdeferred_action_list
= Qnil
;
10168 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
10169 "Function to call to handle deferred actions, after each command.\n\
10170 This function is called with no arguments after each command\n\
10171 whenever `deferred-action-list' is non-nil.");
10172 Vdeferred_action_function
= Qnil
;
10174 DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings
,
10175 "*Non-nil means show the equivalent key-binding when M-x command has one.\n\
10176 The value can be a length of time to show the message for.\n\
10177 If the value is non-nil and not a number, we wait 2 seconds.");
10178 Vsuggest_key_bindings
= Qt
;
10180 DEFVAR_LISP ("timer-list", &Vtimer_list
,
10181 "List of active absolute time timers in order of increasing time");
10182 Vtimer_list
= Qnil
;
10184 DEFVAR_LISP ("timer-idle-list", &Vtimer_idle_list
,
10185 "List of active idle-time timers in order of increasing time");
10186 Vtimer_idle_list
= Qnil
;
10188 DEFVAR_LISP ("input-method-function", &Vinput_method_function
,
10189 "If non-nil, the function that implements the current input method.\n\
10190 It's called with one argument, a printing character that was just read.\n\
10191 \(That means a character with code 040...0176.)\n\
10192 Typically this function uses `read-event' to read additional events.\n\
10193 When it does so, it should first bind `input-method-function' to nil\n\
10194 so it will not be called recursively.\n\
10196 The function should return a list of zero or more events\n\
10197 to be used as input. If it wants to put back some events\n\
10198 to be reconsidered, separately, by the input method,\n\
10199 it can add them to the beginning of `unread-command-events'.\n\
10201 The input method function can find in `input-method-previous-method'\n\
10202 the previous echo area message.\n\
10204 The input method function should refer to the variables\n\
10205 `input-method-use-echo-area' and `input-method-exit-on-first-char'\n\
10206 for guidance on what to do.");
10207 Vinput_method_function
= Qnil
;
10209 DEFVAR_LISP ("input-method-previous-message",
10210 &Vinput_method_previous_message
,
10211 "When `input-method-function' is called, hold the previous echo area message.\n\
10212 This variable exists because `read-event' clears the echo area\n\
10213 before running the input method. It is nil if there was no message.");
10214 Vinput_method_previous_message
= Qnil
;
10216 DEFVAR_LISP ("show-help-function", &Vshow_help_function
,
10217 "If non-nil, the function that implements the display of help.\n\
10218 It's called with one argument, the help string to display.");
10219 Vshow_help_function
= Qnil
;
10221 DEFVAR_LISP ("disable-point-adjustment", &Vdisable_point_adjustment
,
10222 "If non-nil, suppress point adjustment after executing a command.\n\
10224 After a command is executed, if point is moved into a region that has\n\
10225 special properties (e.g. composition, display), we adjust point to\n\
10226 the boundary of the region. But, several special commands sets this\n\
10227 variable to non-nil, then we suppress the point adjustment.\n\
10229 This variable is set to nil before reading a command, and is checked\n\
10230 just after executing the command");
10231 Vdisable_point_adjustment
= Qnil
;
10233 DEFVAR_LISP ("global-disable-point-adjustment",
10234 &Vglobal_disable_point_adjustment
,
10235 "*If non-nil, always suppress point adjustment.\n\
10237 The default value is nil, in which case, point adjustment are\n\
10238 suppressed only after special commands that set\n\
10239 `disable-point-adjustment' (which see) to non-nil.");
10240 Vglobal_disable_point_adjustment
= Qnil
;
10244 keys_of_keyboard ()
10246 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
10247 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
10248 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
10249 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
10250 initial_define_key (meta_map
, 'x', "execute-extended-command");
10252 initial_define_lispy_key (Vspecial_event_map
, "delete-frame",
10253 "handle-delete-frame");
10254 initial_define_lispy_key (Vspecial_event_map
, "iconify-frame",
10256 initial_define_lispy_key (Vspecial_event_map
, "make-frame-visible",