(List Motion): Note optional args.
[emacs.git] / src / keyboard.c
blob97687aad09f1dd1dc139ded0892ad609423db7d9
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)
10 any later version.
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. */
22 #include <config.h>
23 #include <signal.h>
24 #include <stdio.h>
25 #include "termchar.h"
26 #include "termopts.h"
27 #include "lisp.h"
28 #include "termhooks.h"
29 #include "macros.h"
30 #include "frame.h"
31 #include "window.h"
32 #include "commands.h"
33 #include "buffer.h"
34 #include "charset.h"
35 #include "disptab.h"
36 #include "dispextern.h"
37 #include "keyboard.h"
38 #include "syntax.h"
39 #include "intervals.h"
40 #include "blockinput.h"
41 #include "puresize.h"
42 #include "systime.h"
43 #include "atimer.h"
44 #include <setjmp.h>
45 #include <errno.h>
47 #ifdef MSDOS
48 #include "msdos.h"
49 #include <time.h>
50 #else /* not MSDOS */
51 #ifndef VMS
52 #include <sys/ioctl.h>
53 #endif
54 #endif /* not MSDOS */
56 #include "syssignal.h"
57 #include "systty.h"
59 #include <sys/types.h>
60 #ifdef HAVE_UNISTD_H
61 #include <unistd.h>
62 #endif
64 /* This is to get the definitions of the XK_ symbols. */
65 #ifdef HAVE_X_WINDOWS
66 #include "xterm.h"
67 #endif
69 #ifdef HAVE_NTGUI
70 #include "w32term.h"
71 #endif /* HAVE_NTGUI */
73 /* Include systime.h after xterm.h to avoid double inclusion of time.h. */
74 #include "systime.h"
76 extern int errno;
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. */
89 extern int input_fd;
91 #ifdef HAVE_WINDOW_SYSTEM
92 /* Make all keyboard buffers much bigger when using X windows. */
93 #ifdef macintosh
94 /* But not too big (local data > 32K error) if on macintosh */
95 #define KBD_BUFFER_SIZE 512
96 #else
97 #define KBD_BUFFER_SIZE 4096
98 #endif
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 */
105 struct backtrace
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
112 unevalled args */
113 char evalargs;
116 #ifdef MULTI_KBOARD
117 KBOARD *initial_kboard;
118 KBOARD *current_kboard;
119 KBOARD *all_kboards;
120 int single_kboard;
121 #else
122 KBOARD the_only_kboard;
123 #endif
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; \
151 Lisp_Object new; \
152 new = Fmake_vector (make_number (newsize), Qnil); \
153 bcopy (XVECTOR (raw_keybuf)->contents, XVECTOR (new)->contents, \
154 raw_keybuf_count * sizeof (Lisp_Object)); \
155 raw_keybuf = new; \
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. */
199 static int echoing;
201 /* Non-null means we can start echoing at the next input pause even
202 though there is something in the echo area. */
204 static struct kboard *ok_to_echo_at_next_pause;
206 /* The kboard last echoing, or null for none. Reset to 0 in
207 cancel_echoing. If non-null, and a current echo area message
208 exists, and echo_message_buffer is eq to the current message
209 buffer, we know that the message comes from echo_kboard. */
211 static struct kboard *echo_kboard;
213 /* The buffer used for echoing. Set in echo_now, reset in
214 cancel_echoing. */
216 static Lisp_Object echo_message_buffer;
218 /* Nonzero means disregard local maps for the menu bar. */
219 static int inhibit_local_menu_bar_menus;
221 /* Nonzero means C-g should cause immediate error-signal. */
222 int immediate_quit;
224 /* The user's ERASE setting. */
225 Lisp_Object Vtty_erase_char;
227 /* Character to recognize as the help char. */
228 Lisp_Object Vhelp_char;
230 /* List of other event types to recognize as meaning "help". */
231 Lisp_Object Vhelp_event_list;
233 /* Form to execute when help char is typed. */
234 Lisp_Object Vhelp_form;
236 /* Command to run when the help character follows a prefix key. */
237 Lisp_Object Vprefix_help_command;
239 /* List of items that should move to the end of the menu bar. */
240 Lisp_Object Vmenu_bar_final_items;
242 /* Non-nil means show the equivalent key-binding for
243 any M-x command that has one.
244 The value can be a length of time to show the message for.
245 If the value is non-nil and not a number, we wait 2 seconds. */
246 Lisp_Object Vsuggest_key_bindings;
248 /* Character that causes a quit. Normally C-g.
250 If we are running on an ordinary terminal, this must be an ordinary
251 ASCII char, since we want to make it our interrupt character.
253 If we are not running on an ordinary terminal, it still needs to be
254 an ordinary ASCII char. This character needs to be recognized in
255 the input interrupt handler. At this point, the keystroke is
256 represented as a struct input_event, while the desired quit
257 character is specified as a lispy event. The mapping from struct
258 input_events to lispy events cannot run in an interrupt handler,
259 and the reverse mapping is difficult for anything but ASCII
260 keystrokes.
262 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
263 ASCII character. */
264 int quit_char;
266 extern Lisp_Object current_global_map;
267 extern int minibuf_level;
269 /* If non-nil, this is a map that overrides all other local maps. */
270 Lisp_Object Voverriding_local_map;
272 /* If non-nil, Voverriding_local_map applies to the menu bar. */
273 Lisp_Object Voverriding_local_map_menu_flag;
275 /* Keymap that defines special misc events that should
276 be processed immediately at a low level. */
277 Lisp_Object Vspecial_event_map;
279 /* Current depth in recursive edits. */
280 int command_loop_level;
282 /* Total number of times command_loop has read a key sequence. */
283 int num_input_keys;
285 /* Last input character read as a command. */
286 Lisp_Object last_command_char;
288 /* Last input character read as a command, not counting menus
289 reached by the mouse. */
290 Lisp_Object last_nonmenu_event;
292 /* Last input character read for any purpose. */
293 Lisp_Object last_input_char;
295 /* If not Qnil, a list of objects to be read as subsequent command input. */
296 Lisp_Object Vunread_command_events;
298 /* If not Qnil, a list of objects to be read as subsequent command input
299 including input method processing. */
300 Lisp_Object Vunread_input_method_events;
302 /* If not Qnil, a list of objects to be read as subsequent command input
303 but NOT including input method processing. */
304 Lisp_Object Vunread_post_input_method_events;
306 /* If not -1, an event to be read as subsequent command input. */
307 int unread_command_char;
309 /* If not Qnil, this is a switch-frame event which we decided to put
310 off until the end of a key sequence. This should be read as the
311 next command input, after any unread_command_events.
313 read_key_sequence uses this to delay switch-frame events until the
314 end of the key sequence; Fread_char uses it to put off switch-frame
315 events until a non-ASCII event is acceptable as input. */
316 Lisp_Object unread_switch_frame;
318 /* A mask of extra modifier bits to put into every keyboard char. */
319 int extra_keyboard_modifiers;
321 /* Char to use as prefix when a meta character is typed in.
322 This is bound on entry to minibuffer in case ESC is changed there. */
324 Lisp_Object meta_prefix_char;
326 /* Last size recorded for a current buffer which is not a minibuffer. */
327 static int last_non_minibuf_size;
329 /* Number of idle seconds before an auto-save and garbage collection. */
330 static Lisp_Object Vauto_save_timeout;
332 /* Total number of times read_char has returned. */
333 int num_input_events;
335 /* Total number of times read_char has returned, outside of macros. */
336 int num_nonmacro_input_events;
338 /* Auto-save automatically when this many characters have been typed
339 since the last time. */
341 static int auto_save_interval;
343 /* Value of num_nonmacro_input_events as of last auto save. */
345 int last_auto_save;
347 /* The command being executed by the command loop.
348 Commands may set this, and the value set will be copied into
349 current_kboard->Vlast_command instead of the actual command. */
350 Lisp_Object Vthis_command;
352 /* This is like Vthis_command, except that commands never set it. */
353 Lisp_Object real_this_command;
355 /* The value of point when the last command was executed. */
356 int last_point_position;
358 /* The buffer that was current when the last command was started. */
359 Lisp_Object last_point_position_buffer;
361 /* The frame in which the last input event occurred, or Qmacro if the
362 last event came from a macro. We use this to determine when to
363 generate switch-frame events. This may be cleared by functions
364 like Fselect_frame, to make sure that a switch-frame event is
365 generated by the next character. */
366 Lisp_Object internal_last_event_frame;
368 /* A user-visible version of the above, intended to allow users to
369 figure out where the last event came from, if the event doesn't
370 carry that information itself (i.e. if it was a character). */
371 Lisp_Object Vlast_event_frame;
373 /* The timestamp of the last input event we received from the X server.
374 X Windows wants this for selection ownership. */
375 unsigned long last_event_timestamp;
377 Lisp_Object Qself_insert_command;
378 Lisp_Object Qforward_char;
379 Lisp_Object Qbackward_char;
380 Lisp_Object Qundefined;
381 Lisp_Object Qtimer_event_handler;
383 /* read_key_sequence stores here the command definition of the
384 key sequence that it reads. */
385 Lisp_Object read_key_sequence_cmd;
387 /* Echo unfinished commands after this many seconds of pause. */
388 Lisp_Object Vecho_keystrokes;
390 /* Form to evaluate (if non-nil) when Emacs is started. */
391 Lisp_Object Vtop_level;
393 /* User-supplied string to translate input characters through. */
394 Lisp_Object Vkeyboard_translate_table;
396 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
397 extern Lisp_Object Vfunction_key_map;
399 /* Another keymap that maps key sequences into key sequences.
400 This one takes precedence over ordinary definitions. */
401 extern Lisp_Object Vkey_translation_map;
403 /* If non-nil, this implements the current input method. */
404 Lisp_Object Vinput_method_function;
405 Lisp_Object Qinput_method_function;
407 /* When we call Vinput_method_function,
408 this holds the echo area message that was just erased. */
409 Lisp_Object Vinput_method_previous_message;
411 /* Non-nil means deactivate the mark at end of this command. */
412 Lisp_Object Vdeactivate_mark;
414 /* Menu bar specified in Lucid Emacs fashion. */
416 Lisp_Object Vlucid_menu_bar_dirty_flag;
417 Lisp_Object Qrecompute_lucid_menubar, Qactivate_menubar_hook;
419 Lisp_Object Qecho_area_clear_hook;
421 /* Hooks to run before and after each command. */
422 Lisp_Object Qpre_command_hook, Vpre_command_hook;
423 Lisp_Object Qpost_command_hook, Vpost_command_hook;
424 Lisp_Object Qcommand_hook_internal, Vcommand_hook_internal;
425 /* Hook run after a command if there's no more input soon. */
426 Lisp_Object Qpost_command_idle_hook, Vpost_command_idle_hook;
428 /* Delay time in microseconds before running post-command-idle-hook. */
429 int post_command_idle_delay;
431 /* List of deferred actions to be performed at a later time.
432 The precise format isn't relevant here; we just check whether it is nil. */
433 Lisp_Object Vdeferred_action_list;
435 /* Function to call to handle deferred actions, when there are any. */
436 Lisp_Object Vdeferred_action_function;
437 Lisp_Object Qdeferred_action_function;
439 Lisp_Object Qinput_method_exit_on_first_char;
440 Lisp_Object Qinput_method_use_echo_area;
442 /* File in which we write all commands we read. */
443 FILE *dribble;
445 /* Nonzero if input is available. */
446 int input_pending;
448 /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
449 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
451 int meta_key;
453 extern char *pending_malloc_warning;
455 /* Circular buffer for pre-read keyboard input. */
457 static struct input_event kbd_buffer[KBD_BUFFER_SIZE];
459 /* Vector to GCPRO the Lisp objects referenced from kbd_buffer.
461 The interrupt-level event handlers will never enqueue an event on a
462 frame which is not in Vframe_list, and once an event is dequeued,
463 internal_last_event_frame or the event itself points to the frame.
464 So that's all fine.
466 But while the event is sitting in the queue, it's completely
467 unprotected. Suppose the user types one command which will run for
468 a while and then delete a frame, and then types another event at
469 the frame that will be deleted, before the command gets around to
470 it. Suppose there are no references to this frame elsewhere in
471 Emacs, and a GC occurs before the second event is dequeued. Now we
472 have an event referring to a freed frame, which will crash Emacs
473 when it is dequeued.
475 Similar things happen when an event on a scroll bar is enqueued; the
476 window may be deleted while the event is in the queue.
478 So, we use this vector to protect the Lisp_Objects in the event
479 queue. That way, they'll be dequeued as dead frames or windows,
480 but still valid Lisp objects.
482 If kbd_buffer[i].kind != no_event, then
484 AREF (kbd_buffer_gcpro, 2 * i) == kbd_buffer[i].frame_or_window.
485 AREF (kbd_buffer_gcpro, 2 * i + 1) == kbd_buffer[i].arg. */
487 static Lisp_Object kbd_buffer_gcpro;
489 /* Pointer to next available character in kbd_buffer.
490 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
491 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the
492 next available char is in kbd_buffer[0]. */
493 static struct input_event *kbd_fetch_ptr;
495 /* Pointer to next place to store character in kbd_buffer. This
496 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
497 character should go in kbd_buffer[0]. */
498 static struct input_event * volatile kbd_store_ptr;
500 /* The above pair of variables forms a "queue empty" flag. When we
501 enqueue a non-hook event, we increment kbd_store_ptr. When we
502 dequeue a non-hook event, we increment kbd_fetch_ptr. We say that
503 there is input available iff the two pointers are not equal.
505 Why not just have a flag set and cleared by the enqueuing and
506 dequeuing functions? Such a flag could be screwed up by interrupts
507 at inopportune times. */
509 /* If this flag is non-nil, we check mouse_moved to see when the
510 mouse moves, and motion events will appear in the input stream.
511 Otherwise, mouse motion is ignored. */
512 static Lisp_Object do_mouse_tracking;
514 /* Symbols to head events. */
515 Lisp_Object Qmouse_movement;
516 Lisp_Object Qscroll_bar_movement;
517 Lisp_Object Qswitch_frame;
518 Lisp_Object Qdelete_frame;
519 Lisp_Object Qiconify_frame;
520 Lisp_Object Qmake_frame_visible;
521 Lisp_Object Qhelp_echo;
523 /* Symbols to denote kinds of events. */
524 Lisp_Object Qfunction_key;
525 Lisp_Object Qmouse_click;
526 #ifdef WINDOWSNT
527 Lisp_Object Qmouse_wheel;
528 Lisp_Object Qlanguage_change;
529 #endif
530 Lisp_Object Qdrag_n_drop;
531 /* Lisp_Object Qmouse_movement; - also an event header */
533 /* Properties of event headers. */
534 Lisp_Object Qevent_kind;
535 Lisp_Object Qevent_symbol_elements;
537 /* menu item parts */
538 Lisp_Object Qmenu_alias;
539 Lisp_Object Qmenu_enable;
540 Lisp_Object QCenable, QCvisible, QChelp, QCfilter, QCkeys, QCkey_sequence;
541 Lisp_Object QCbutton, QCtoggle, QCradio;
542 extern Lisp_Object Vdefine_key_rebound_commands;
543 extern Lisp_Object Qmenu_item;
545 /* An event header symbol HEAD may have a property named
546 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
547 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
548 mask of modifiers applied to it. If present, this is used to help
549 speed up parse_modifiers. */
550 Lisp_Object Qevent_symbol_element_mask;
552 /* An unmodified event header BASE may have a property named
553 Qmodifier_cache, which is an alist mapping modifier masks onto
554 modified versions of BASE. If present, this helps speed up
555 apply_modifiers. */
556 Lisp_Object Qmodifier_cache;
558 /* Symbols to use for parts of windows. */
559 Lisp_Object Qmode_line;
560 Lisp_Object Qvertical_line;
561 Lisp_Object Qvertical_scroll_bar;
562 Lisp_Object Qmenu_bar;
564 Lisp_Object recursive_edit_unwind (), command_loop ();
565 Lisp_Object Fthis_command_keys ();
566 Lisp_Object Qextended_command_history;
567 EMACS_TIME timer_check ();
569 extern Lisp_Object Vhistory_length;
571 extern char *x_get_keysym_name ();
573 static void record_menu_key ();
575 Lisp_Object Qpolling_period;
577 /* List of absolute timers. Appears in order of next scheduled event. */
578 Lisp_Object Vtimer_list;
580 /* List of idle time timers. Appears in order of next scheduled event. */
581 Lisp_Object Vtimer_idle_list;
583 /* Incremented whenever a timer is run. */
584 int timers_run;
586 extern Lisp_Object Vprint_level, Vprint_length;
588 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
589 happens. */
590 EMACS_TIME *input_available_clear_time;
592 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
593 Default is 1 if INTERRUPT_INPUT is defined. */
594 int interrupt_input;
596 /* Nonzero while interrupts are temporarily deferred during redisplay. */
597 int interrupts_deferred;
599 /* Nonzero means use ^S/^Q for flow control. */
600 int flow_control;
602 /* Allow m- file to inhibit use of FIONREAD. */
603 #ifdef BROKEN_FIONREAD
604 #undef FIONREAD
605 #endif
607 /* We are unable to use interrupts if FIONREAD is not available,
608 so flush SIGIO so we won't try. */
609 #ifndef FIONREAD
610 #ifdef SIGIO
611 #undef SIGIO
612 #endif
613 #endif
615 /* If we support a window system, turn on the code to poll periodically
616 to detect C-g. It isn't actually used when doing interrupt input. */
617 #ifdef HAVE_WINDOW_SYSTEM
618 #define POLL_FOR_INPUT
619 #endif
621 /* After a command is executed, if point is moved into a region that
622 has specific properties (e.g. composition, display), we adjust
623 point to the boundary of the region. But, if a command sets this
624 valiable to non-nil, we suppress this point adjustment. This
625 variable is set to nil before reading a command. */
627 Lisp_Object Vdisable_point_adjustment;
629 /* If non-nil, always disable point adjustment. */
631 Lisp_Object Vglobal_disable_point_adjustment;
634 /* Global variable declarations. */
636 /* Function for init_keyboard to call with no args (if nonzero). */
637 void (*keyboard_init_hook) ();
639 static int read_avail_input ();
640 static void get_input_pending ();
641 static int readable_events ();
642 static Lisp_Object read_char_x_menu_prompt ();
643 static Lisp_Object read_char_minibuf_menu_prompt ();
644 static Lisp_Object make_lispy_event ();
645 #ifdef HAVE_MOUSE
646 static Lisp_Object make_lispy_movement ();
647 #endif
648 static Lisp_Object modify_event_symbol ();
649 static Lisp_Object make_lispy_switch_frame ();
650 static int parse_solitary_modifier ();
651 static void save_getcjmp ();
652 static void restore_getcjmp ();
653 static Lisp_Object apply_modifiers P_ ((int, Lisp_Object));
655 /* Nonzero means don't try to suspend even if the operating system seems
656 to support it. */
657 static int cannot_suspend;
659 #define min(a,b) ((a)<(b)?(a):(b))
660 #define max(a,b) ((a)>(b)?(a):(b))
662 /* Install the string STR as the beginning of the string of echoing,
663 so that it serves as a prompt for the next character.
664 Also start echoing. */
666 void
667 echo_prompt (str)
668 char *str;
670 int len = strlen (str);
672 if (len > ECHOBUFSIZE - 4)
673 len = ECHOBUFSIZE - 4;
674 bcopy (str, current_kboard->echobuf, len);
675 current_kboard->echoptr = current_kboard->echobuf + len;
676 *current_kboard->echoptr = '\0';
678 current_kboard->echo_after_prompt = len;
680 echo_now ();
683 /* Add C to the echo string, if echoing is going on.
684 C can be a character, which is printed prettily ("M-C-x" and all that
685 jazz), or a symbol, whose name is printed. */
687 void
688 echo_char (c)
689 Lisp_Object c;
691 extern char *push_key_description ();
693 if (current_kboard->immediate_echo)
695 char *ptr = current_kboard->echoptr;
697 if (ptr != current_kboard->echobuf)
698 *ptr++ = ' ';
700 /* If someone has passed us a composite event, use its head symbol. */
701 c = EVENT_HEAD (c);
703 if (INTEGERP (c))
705 if (ptr - current_kboard->echobuf
706 > ECHOBUFSIZE - KEY_DESCRIPTION_SIZE)
707 return;
709 ptr = push_key_description (XINT (c), ptr);
711 else if (SYMBOLP (c))
713 struct Lisp_String *name = XSYMBOL (c)->name;
714 if ((ptr - current_kboard->echobuf) + STRING_BYTES (name) + 4
715 > ECHOBUFSIZE)
716 return;
717 bcopy (name->data, ptr, STRING_BYTES (name));
718 ptr += STRING_BYTES (name);
721 if (current_kboard->echoptr == current_kboard->echobuf
722 && help_char_p (c))
724 strcpy (ptr, " (Type ? for further options)");
725 ptr += strlen (ptr);
728 *ptr = 0;
729 current_kboard->echoptr = ptr;
731 echo_now ();
735 /* Temporarily add a dash to the end of the echo string if it's not
736 empty, so that it serves as a mini-prompt for the very next character. */
738 void
739 echo_dash ()
741 if (!current_kboard->immediate_echo
742 && current_kboard->echoptr == current_kboard->echobuf)
743 return;
744 /* Do nothing if we just printed a prompt. */
745 if (current_kboard->echo_after_prompt
746 == current_kboard->echoptr - current_kboard->echobuf)
747 return;
748 /* Do nothing if not echoing at all. */
749 if (current_kboard->echoptr == 0)
750 return;
752 /* Put a dash at the end of the buffer temporarily,
753 but make it go away when the next character is added. */
754 current_kboard->echoptr[0] = '-';
755 current_kboard->echoptr[1] = 0;
757 echo_now ();
760 /* Display the current echo string, and begin echoing if not already
761 doing so. */
763 void
764 echo_now ()
766 if (!current_kboard->immediate_echo)
768 int i;
769 current_kboard->immediate_echo = 1;
771 for (i = 0; i < this_command_key_count; i++)
773 Lisp_Object c;
774 c = XVECTOR (this_command_keys)->contents[i];
775 if (! (EVENT_HAS_PARAMETERS (c)
776 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c)), Qmouse_movement)))
777 echo_char (c);
779 echo_dash ();
782 echoing = 1;
783 message2_nolog (current_kboard->echobuf, strlen (current_kboard->echobuf),
784 ! NILP (current_buffer->enable_multibyte_characters));
785 echoing = 0;
787 /* Record in what buffer we echoed, and from which kboard. */
788 echo_message_buffer = echo_area_buffer[0];
789 echo_kboard = current_kboard;
791 if (waiting_for_input && !NILP (Vquit_flag))
792 quit_throw_to_read_char ();
795 /* Turn off echoing, for the start of a new command. */
797 void
798 cancel_echoing ()
800 current_kboard->immediate_echo = 0;
801 current_kboard->echoptr = current_kboard->echobuf;
802 current_kboard->echo_after_prompt = -1;
803 ok_to_echo_at_next_pause = NULL;
804 echo_kboard = NULL;
805 echo_message_buffer = Qnil;
808 /* Return the length of the current echo string. */
810 static int
811 echo_length ()
813 return current_kboard->echoptr - current_kboard->echobuf;
816 /* Truncate the current echo message to its first LEN chars.
817 This and echo_char get used by read_key_sequence when the user
818 switches frames while entering a key sequence. */
820 static void
821 echo_truncate (len)
822 int len;
824 current_kboard->echobuf[len] = '\0';
825 current_kboard->echoptr = current_kboard->echobuf + len;
826 truncate_echo_area (len);
830 /* Functions for manipulating this_command_keys. */
831 static void
832 add_command_key (key)
833 Lisp_Object key;
835 int size = XVECTOR (this_command_keys)->size;
837 /* If reset-this-command-length was called recently, obey it now.
838 See the doc string of that function for an explanation of why. */
839 if (before_command_restore_flag)
841 this_command_key_count = before_command_key_count_1;
842 if (this_command_key_count < this_single_command_key_start)
843 this_single_command_key_start = this_command_key_count;
844 echo_truncate (before_command_echo_length_1);
845 before_command_restore_flag = 0;
848 if (this_command_key_count >= size)
850 Lisp_Object new_keys;
852 new_keys = Fmake_vector (make_number (size * 2), Qnil);
853 bcopy (XVECTOR (this_command_keys)->contents,
854 XVECTOR (new_keys)->contents,
855 size * sizeof (Lisp_Object));
857 this_command_keys = new_keys;
860 XVECTOR (this_command_keys)->contents[this_command_key_count++] = key;
863 Lisp_Object
864 recursive_edit_1 ()
866 int count = specpdl_ptr - specpdl;
867 Lisp_Object val;
869 if (command_loop_level > 0)
871 specbind (Qstandard_output, Qt);
872 specbind (Qstandard_input, Qt);
875 #ifdef HAVE_X_WINDOWS
876 /* The command loop has started a busy-cursor timer, so we have to
877 cancel it here, otherwise it will fire because the recursive edit
878 can take some time. */
879 if (display_busy_cursor_p)
880 cancel_busy_cursor ();
881 #endif
883 val = command_loop ();
884 if (EQ (val, Qt))
885 Fsignal (Qquit, Qnil);
886 /* Handle throw from read_minibuf when using minibuffer
887 while it's active but we're in another window. */
888 if (STRINGP (val))
889 Fsignal (Qerror, Fcons (val, Qnil));
891 return unbind_to (count, Qnil);
894 /* When an auto-save happens, record the "time", and don't do again soon. */
896 void
897 record_auto_save ()
899 last_auto_save = num_nonmacro_input_events;
902 /* Make an auto save happen as soon as possible at command level. */
904 void
905 force_auto_save_soon ()
907 last_auto_save = - auto_save_interval - 1;
909 record_asynch_buffer_change ();
912 DEFUN ("recursive-edit", Frecursive_edit, Srecursive_edit, 0, 0, "",
913 "Invoke the editor command loop recursively.\n\
914 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
915 that tells this function to return.\n\
916 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
917 This function is called by the editor initialization to begin editing.")
920 int count = specpdl_ptr - specpdl;
922 command_loop_level++;
923 update_mode_lines = 1;
925 record_unwind_protect (recursive_edit_unwind,
926 (command_loop_level
927 && current_buffer != XBUFFER (XWINDOW (selected_window)->buffer))
928 ? Fcurrent_buffer ()
929 : Qnil);
930 recursive_edit_1 ();
931 return unbind_to (count, Qnil);
934 Lisp_Object
935 recursive_edit_unwind (buffer)
936 Lisp_Object buffer;
938 if (!NILP (buffer))
939 Fset_buffer (buffer);
941 command_loop_level--;
942 update_mode_lines = 1;
943 return Qnil;
946 static void
947 any_kboard_state ()
949 #ifdef MULTI_KBOARD
950 #if 0 /* Theory: if there's anything in Vunread_command_events,
951 it will right away be read by read_key_sequence,
952 and then if we do switch KBOARDS, it will go into the side
953 queue then. So we don't need to do anything special here -- rms. */
954 if (CONSP (Vunread_command_events))
956 current_kboard->kbd_queue
957 = nconc2 (Vunread_command_events, current_kboard->kbd_queue);
958 current_kboard->kbd_queue_has_data = 1;
960 Vunread_command_events = Qnil;
961 #endif
962 single_kboard = 0;
963 #endif
966 /* Switch to the single-kboard state, making current_kboard
967 the only KBOARD from which further input is accepted. */
969 void
970 single_kboard_state ()
972 #ifdef MULTI_KBOARD
973 single_kboard = 1;
974 #endif
977 /* Maintain a stack of kboards, so other parts of Emacs
978 can switch temporarily to the kboard of a given frame
979 and then revert to the previous status. */
981 struct kboard_stack
983 KBOARD *kboard;
984 struct kboard_stack *next;
987 static struct kboard_stack *kboard_stack;
989 void
990 push_frame_kboard (f)
991 FRAME_PTR f;
993 #ifdef MULTI_KBOARD
994 struct kboard_stack *p
995 = (struct kboard_stack *) xmalloc (sizeof (struct kboard_stack));
997 p->next = kboard_stack;
998 p->kboard = current_kboard;
999 kboard_stack = p;
1001 current_kboard = FRAME_KBOARD (f);
1002 #endif
1005 void
1006 pop_frame_kboard ()
1008 #ifdef MULTI_KBOARD
1009 struct kboard_stack *p = kboard_stack;
1010 current_kboard = p->kboard;
1011 kboard_stack = p->next;
1012 xfree (p);
1013 #endif
1016 /* Handle errors that are not handled at inner levels
1017 by printing an error message and returning to the editor command loop. */
1019 Lisp_Object
1020 cmd_error (data)
1021 Lisp_Object data;
1023 Lisp_Object old_level, old_length;
1024 char macroerror[50];
1026 if (!NILP (executing_macro))
1028 if (executing_macro_iterations == 1)
1029 sprintf (macroerror, "After 1 kbd macro iteration: ");
1030 else
1031 sprintf (macroerror, "After %d kbd macro iterations: ",
1032 executing_macro_iterations);
1034 else
1035 *macroerror = 0;
1037 Vstandard_output = Qt;
1038 Vstandard_input = Qt;
1039 Vexecuting_macro = Qnil;
1040 executing_macro = Qnil;
1041 current_kboard->Vprefix_arg = Qnil;
1042 current_kboard->Vlast_prefix_arg = Qnil;
1043 cancel_echoing ();
1045 /* Avoid unquittable loop if data contains a circular list. */
1046 old_level = Vprint_level;
1047 old_length = Vprint_length;
1048 XSETFASTINT (Vprint_level, 10);
1049 XSETFASTINT (Vprint_length, 10);
1050 cmd_error_internal (data, macroerror);
1051 Vprint_level = old_level;
1052 Vprint_length = old_length;
1054 Vquit_flag = Qnil;
1056 Vinhibit_quit = Qnil;
1057 #ifdef MULTI_KBOARD
1058 any_kboard_state ();
1059 #endif
1061 return make_number (0);
1064 /* Take actions on handling an error. DATA is the data that describes
1065 the error.
1067 CONTEXT is a C-string containing ASCII characters only which
1068 describes the context in which the error happened. If we need to
1069 generalize CONTEXT to allow multibyte characters, make it a Lisp
1070 string. */
1072 void
1073 cmd_error_internal (data, context)
1074 Lisp_Object data;
1075 char *context;
1077 Lisp_Object stream;
1078 int kill_emacs_p = 0;
1079 struct frame *sf = SELECTED_FRAME ();
1081 Vquit_flag = Qnil;
1082 Vinhibit_quit = Qt;
1083 clear_message (1, 0);
1085 /* If the window system or terminal frame hasn't been initialized
1086 yet, or we're not interactive, it's best to dump this message out
1087 to stderr and exit. */
1088 if (!sf->glyphs_initialized_p
1089 /* This is the case of the frame dumped with Emacs, when we're
1090 running under a window system. */
1091 || (!NILP (Vwindow_system)
1092 && !inhibit_window_system
1093 && FRAME_TERMCAP_P (sf))
1094 || noninteractive)
1096 stream = Qexternal_debugging_output;
1097 kill_emacs_p = 1;
1099 else
1101 Fdiscard_input ();
1102 bitch_at_user ();
1103 stream = Qt;
1106 if (context != 0)
1107 write_string_1 (context, -1, stream);
1109 print_error_message (data, stream);
1111 /* If the window system or terminal frame hasn't been initialized
1112 yet, or we're in -batch mode, this error should cause Emacs to exit. */
1113 if (kill_emacs_p)
1115 Fterpri (stream);
1116 Fkill_emacs (make_number (-1));
1120 Lisp_Object command_loop_1 ();
1121 Lisp_Object command_loop_2 ();
1122 Lisp_Object top_level_1 ();
1124 /* Entry to editor-command-loop.
1125 This level has the catches for exiting/returning to editor command loop.
1126 It returns nil to exit recursive edit, t to abort it. */
1128 Lisp_Object
1129 command_loop ()
1131 if (command_loop_level > 0 || minibuf_level > 0)
1133 Lisp_Object val;
1134 val = internal_catch (Qexit, command_loop_2, Qnil);
1135 executing_macro = Qnil;
1136 return val;
1138 else
1139 while (1)
1141 internal_catch (Qtop_level, top_level_1, Qnil);
1142 internal_catch (Qtop_level, command_loop_2, Qnil);
1143 executing_macro = Qnil;
1145 /* End of file in -batch run causes exit here. */
1146 if (noninteractive)
1147 Fkill_emacs (Qt);
1151 /* Here we catch errors in execution of commands within the
1152 editing loop, and reenter the editing loop.
1153 When there is an error, cmd_error runs and returns a non-nil
1154 value to us. A value of nil means that cmd_loop_1 itself
1155 returned due to end of file (or end of kbd macro). */
1157 Lisp_Object
1158 command_loop_2 ()
1160 register Lisp_Object val;
1163 val = internal_condition_case (command_loop_1, Qerror, cmd_error);
1164 while (!NILP (val));
1166 return Qnil;
1169 Lisp_Object
1170 top_level_2 ()
1172 return Feval (Vtop_level);
1175 Lisp_Object
1176 top_level_1 ()
1178 /* On entry to the outer level, run the startup file */
1179 if (!NILP (Vtop_level))
1180 internal_condition_case (top_level_2, Qerror, cmd_error);
1181 else if (!NILP (Vpurify_flag))
1182 message ("Bare impure Emacs (standard Lisp code not loaded)");
1183 else
1184 message ("Bare Emacs (standard Lisp code not loaded)");
1185 return Qnil;
1188 DEFUN ("top-level", Ftop_level, Stop_level, 0, 0, "",
1189 "Exit all recursive editing levels.")
1192 #ifdef HAVE_X_WINDOWS
1193 if (display_busy_cursor_p)
1194 cancel_busy_cursor ();
1195 #endif
1196 Fthrow (Qtop_level, Qnil);
1199 DEFUN ("exit-recursive-edit", Fexit_recursive_edit, Sexit_recursive_edit, 0, 0, "",
1200 "Exit from the innermost recursive edit or minibuffer.")
1203 if (command_loop_level > 0 || minibuf_level > 0)
1204 Fthrow (Qexit, Qnil);
1206 error ("No recursive edit is in progress");
1209 DEFUN ("abort-recursive-edit", Fabort_recursive_edit, Sabort_recursive_edit, 0, 0, "",
1210 "Abort the command that requested this recursive edit or minibuffer input.")
1213 if (command_loop_level > 0 || minibuf_level > 0)
1214 Fthrow (Qexit, Qt);
1216 error ("No recursive edit is in progress");
1219 /* This is the actual command reading loop,
1220 sans error-handling encapsulation. */
1222 Lisp_Object Fcommand_execute ();
1223 static int read_key_sequence ();
1224 void safe_run_hooks ();
1225 static void adjust_point_for_property ();
1227 Lisp_Object
1228 command_loop_1 ()
1230 Lisp_Object cmd;
1231 int lose;
1232 int nonundocount;
1233 Lisp_Object keybuf[30];
1234 int i;
1235 int no_direct;
1236 int prev_modiff;
1237 struct buffer *prev_buffer;
1238 #ifdef MULTI_KBOARD
1239 int was_locked = single_kboard;
1240 #endif
1242 current_kboard->Vprefix_arg = Qnil;
1243 current_kboard->Vlast_prefix_arg = Qnil;
1244 Vdeactivate_mark = Qnil;
1245 waiting_for_input = 0;
1246 cancel_echoing ();
1248 nonundocount = 0;
1249 this_command_key_count = 0;
1250 this_single_command_key_start = 0;
1252 /* Make sure this hook runs after commands that get errors and
1253 throw to top level. */
1254 /* Note that the value cell will never directly contain nil
1255 if the symbol is a local variable. */
1256 if (!NILP (Vpost_command_hook) && !NILP (Vrun_hooks))
1257 safe_run_hooks (Qpost_command_hook);
1259 /* If displaying a message, resize the echo area window to fit
1260 that message's size exactly. */
1261 if (!NILP (echo_area_buffer[0]))
1262 resize_echo_area_axactly ();
1264 if (!NILP (Vdeferred_action_list))
1265 call0 (Vdeferred_action_function);
1267 if (!NILP (Vpost_command_idle_hook) && !NILP (Vrun_hooks))
1269 if (NILP (Vunread_command_events)
1270 && NILP (Vunread_input_method_events)
1271 && NILP (Vunread_post_input_method_events)
1272 && NILP (Vexecuting_macro)
1273 && !NILP (sit_for (0, post_command_idle_delay, 0, 1, 1)))
1274 safe_run_hooks (Qpost_command_idle_hook);
1277 /* Do this after running Vpost_command_hook, for consistency. */
1278 current_kboard->Vlast_command = Vthis_command;
1279 current_kboard->Vreal_last_command = real_this_command;
1281 while (1)
1283 if (! FRAME_LIVE_P (XFRAME (selected_frame)))
1284 Fkill_emacs (Qnil);
1286 /* Make sure the current window's buffer is selected. */
1287 if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer)
1288 set_buffer_internal (XBUFFER (XWINDOW (selected_window)->buffer));
1290 /* Display any malloc warning that just came out. Use while because
1291 displaying one warning can cause another. */
1293 while (pending_malloc_warning)
1294 display_malloc_warning ();
1296 no_direct = 0;
1298 Vdeactivate_mark = Qnil;
1300 /* If minibuffer on and echo area in use,
1301 wait 2 sec and redraw minibuffer. */
1303 if (minibuf_level
1304 && !NILP (echo_area_buffer[0])
1305 && EQ (minibuf_window, echo_area_window))
1307 /* Bind inhibit-quit to t so that C-g gets read in
1308 rather than quitting back to the minibuffer. */
1309 int count = specpdl_ptr - specpdl;
1310 specbind (Qinhibit_quit, Qt);
1312 Fsit_for (make_number (2), Qnil, Qnil);
1313 /* Clear the echo area. */
1314 message2 (0, 0, 0);
1315 safe_run_hooks (Qecho_area_clear_hook);
1317 unbind_to (count, Qnil);
1319 /* If a C-g came in before, treat it as input now. */
1320 if (!NILP (Vquit_flag))
1322 Vquit_flag = Qnil;
1323 Vunread_command_events = Fcons (make_number (quit_char), Qnil);
1327 #ifdef C_ALLOCA
1328 alloca (0); /* Cause a garbage collection now */
1329 /* Since we can free the most stuff here. */
1330 #endif /* C_ALLOCA */
1332 #if 0
1333 /* Select the frame that the last event came from. Usually,
1334 switch-frame events will take care of this, but if some lisp
1335 code swallows a switch-frame event, we'll fix things up here.
1336 Is this a good idea? */
1337 if (FRAMEP (internal_last_event_frame)
1338 && !EQ (internal_last_event_frame, selected_frame))
1339 Fselect_frame (internal_last_event_frame, Qnil);
1340 #endif
1341 /* If it has changed current-menubar from previous value,
1342 really recompute the menubar from the value. */
1343 if (! NILP (Vlucid_menu_bar_dirty_flag)
1344 && !NILP (Ffboundp (Qrecompute_lucid_menubar)))
1345 call0 (Qrecompute_lucid_menubar);
1347 before_command_key_count = this_command_key_count;
1348 before_command_echo_length = echo_length ();
1350 Vthis_command = Qnil;
1351 real_this_command = Qnil;
1353 /* Read next key sequence; i gets its length. */
1354 i = read_key_sequence (keybuf, sizeof keybuf / sizeof keybuf[0],
1355 Qnil, 0, 1, 1);
1357 /* A filter may have run while we were reading the input. */
1358 if (! FRAME_LIVE_P (XFRAME (selected_frame)))
1359 Fkill_emacs (Qnil);
1360 if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer)
1361 set_buffer_internal (XBUFFER (XWINDOW (selected_window)->buffer));
1363 ++num_input_keys;
1365 /* Now we have read a key sequence of length I,
1366 or else I is 0 and we found end of file. */
1368 if (i == 0) /* End of file -- happens only in */
1369 return Qnil; /* a kbd macro, at the end. */
1370 /* -1 means read_key_sequence got a menu that was rejected.
1371 Just loop around and read another command. */
1372 if (i == -1)
1374 cancel_echoing ();
1375 this_command_key_count = 0;
1376 this_single_command_key_start = 0;
1377 goto finalize;
1380 last_command_char = keybuf[i - 1];
1382 /* If the previous command tried to force a specific window-start,
1383 forget about that, in case this command moves point far away
1384 from that position. But also throw away beg_unchanged and
1385 end_unchanged information in that case, so that redisplay will
1386 update the whole window properly. */
1387 if (!NILP (XWINDOW (selected_window)->force_start))
1389 struct buffer *b;
1390 XWINDOW (selected_window)->force_start = Qnil;
1391 b = XBUFFER (XWINDOW (selected_window)->buffer);
1392 BUF_BEG_UNCHANGED (b) = BUF_END_UNCHANGED (b) = 0;
1395 cmd = read_key_sequence_cmd;
1396 if (!NILP (Vexecuting_macro))
1398 if (!NILP (Vquit_flag))
1400 Vexecuting_macro = Qt;
1401 QUIT; /* Make some noise. */
1402 /* Will return since macro now empty. */
1406 /* Do redisplay processing after this command except in special
1407 cases identified below. */
1408 prev_buffer = current_buffer;
1409 prev_modiff = MODIFF;
1410 last_point_position = PT;
1411 XSETBUFFER (last_point_position_buffer, prev_buffer);
1413 /* By default, we adjust point to a boundary of a region that
1414 has such a property that should be treated intangible
1415 (e.g. composition, display). But, some commands will set
1416 this variable differently. */
1417 Vdisable_point_adjustment = Qnil;
1419 /* Execute the command. */
1421 Vthis_command = cmd;
1422 real_this_command = cmd;
1423 /* Note that the value cell will never directly contain nil
1424 if the symbol is a local variable. */
1425 if (!NILP (Vpre_command_hook) && !NILP (Vrun_hooks))
1426 safe_run_hooks (Qpre_command_hook);
1428 if (NILP (Vthis_command))
1430 /* nil means key is undefined. */
1431 bitch_at_user ();
1432 current_kboard->defining_kbd_macro = Qnil;
1433 update_mode_lines = 1;
1434 current_kboard->Vprefix_arg = Qnil;
1436 else
1438 if (NILP (current_kboard->Vprefix_arg) && ! no_direct)
1440 /* In case we jump to directly_done. */
1441 Vcurrent_prefix_arg = current_kboard->Vprefix_arg;
1443 /* Recognize some common commands in common situations and
1444 do them directly. */
1445 if (EQ (Vthis_command, Qforward_char) && PT < ZV)
1447 struct Lisp_Char_Table *dp
1448 = window_display_table (XWINDOW (selected_window));
1449 lose = FETCH_CHAR (PT_BYTE);
1450 SET_PT (PT + 1);
1451 if ((dp
1452 ? (VECTORP (DISP_CHAR_VECTOR (dp, lose))
1453 ? XVECTOR (DISP_CHAR_VECTOR (dp, lose))->size == 1
1454 : (NILP (DISP_CHAR_VECTOR (dp, lose))
1455 && (lose >= 0x20 && lose < 0x7f)))
1456 : (lose >= 0x20 && lose < 0x7f))
1457 /* To extract the case of continuation on
1458 wide-column characters. */
1459 && (WIDTH_BY_CHAR_HEAD (FETCH_BYTE (PT_BYTE)) == 1)
1460 && (XFASTINT (XWINDOW (selected_window)->last_modified)
1461 >= MODIFF)
1462 && (XFASTINT (XWINDOW (selected_window)->last_overlay_modified)
1463 >= OVERLAY_MODIFF)
1464 && (XFASTINT (XWINDOW (selected_window)->last_point)
1465 == PT - 1)
1466 && !windows_or_buffers_changed
1467 && EQ (current_buffer->selective_display, Qnil)
1468 && !detect_input_pending ()
1469 && NILP (XWINDOW (selected_window)->column_number_displayed)
1470 && NILP (Vexecuting_macro))
1471 direct_output_forward_char (1);
1472 goto directly_done;
1474 else if (EQ (Vthis_command, Qbackward_char) && PT > BEGV)
1476 struct Lisp_Char_Table *dp
1477 = window_display_table (XWINDOW (selected_window));
1478 SET_PT (PT - 1);
1479 lose = FETCH_CHAR (PT_BYTE);
1480 if ((dp
1481 ? (VECTORP (DISP_CHAR_VECTOR (dp, lose))
1482 ? XVECTOR (DISP_CHAR_VECTOR (dp, lose))->size == 1
1483 : (NILP (DISP_CHAR_VECTOR (dp, lose))
1484 && (lose >= 0x20 && lose < 0x7f)))
1485 : (lose >= 0x20 && lose < 0x7f))
1486 && (XFASTINT (XWINDOW (selected_window)->last_modified)
1487 >= MODIFF)
1488 && (XFASTINT (XWINDOW (selected_window)->last_overlay_modified)
1489 >= OVERLAY_MODIFF)
1490 && (XFASTINT (XWINDOW (selected_window)->last_point)
1491 == PT + 1)
1492 && !windows_or_buffers_changed
1493 && EQ (current_buffer->selective_display, Qnil)
1494 && !detect_input_pending ()
1495 && NILP (XWINDOW (selected_window)->column_number_displayed)
1496 && NILP (Vexecuting_macro))
1497 direct_output_forward_char (-1);
1498 goto directly_done;
1500 else if (EQ (Vthis_command, Qself_insert_command)
1501 /* Try this optimization only on ascii keystrokes. */
1502 && INTEGERP (last_command_char))
1504 unsigned int c = XINT (last_command_char);
1505 int value;
1506 if (NILP (Vexecuting_macro)
1507 && !EQ (minibuf_window, selected_window))
1509 if (!nonundocount || nonundocount >= 20)
1511 Fundo_boundary ();
1512 nonundocount = 0;
1514 nonundocount++;
1517 lose = ((XFASTINT (XWINDOW (selected_window)->last_modified)
1518 < MODIFF)
1519 || (XFASTINT (XWINDOW (selected_window)->last_overlay_modified)
1520 < OVERLAY_MODIFF)
1521 || (XFASTINT (XWINDOW (selected_window)->last_point)
1522 != PT)
1523 || MODIFF <= SAVE_MODIFF
1524 || windows_or_buffers_changed
1525 || !EQ (current_buffer->selective_display, Qnil)
1526 || detect_input_pending ()
1527 || !NILP (XWINDOW (selected_window)->column_number_displayed)
1528 || !NILP (Vexecuting_macro));
1530 value = internal_self_insert (c, 0);
1532 if (value == 2)
1533 nonundocount = 0;
1535 /* VALUE == 1 when AFTER-CHANGE functions are
1536 installed which is the case most of the time
1537 because FONT-LOCK installs one. */
1538 if (!lose && !value)
1539 direct_output_for_insert (c);
1540 goto directly_done;
1544 /* Here for a command that isn't executed directly */
1546 #ifdef HAVE_X_WINDOWS
1547 if (display_busy_cursor_p)
1548 start_busy_cursor ();
1549 #endif
1551 nonundocount = 0;
1552 if (NILP (current_kboard->Vprefix_arg))
1553 Fundo_boundary ();
1554 Fcommand_execute (Vthis_command, Qnil, Qnil, Qnil);
1556 #ifdef HAVE_X_WINDOWS
1557 if (display_busy_cursor_p)
1558 cancel_busy_cursor ();
1559 #endif
1561 directly_done: ;
1562 current_kboard->Vlast_prefix_arg = Vcurrent_prefix_arg;
1564 /* Note that the value cell will never directly contain nil
1565 if the symbol is a local variable. */
1566 if (!NILP (Vpost_command_hook) && !NILP (Vrun_hooks))
1567 safe_run_hooks (Qpost_command_hook);
1569 /* If displaying a message, resize the echo area window to fit
1570 that message's size exactly. */
1571 if (!NILP (echo_area_buffer[0]))
1572 resize_echo_area_axactly ();
1574 if (!NILP (Vdeferred_action_list))
1575 safe_run_hooks (Qdeferred_action_function);
1577 if (!NILP (Vpost_command_idle_hook) && !NILP (Vrun_hooks))
1579 if (NILP (Vunread_command_events)
1580 && NILP (Vunread_input_method_events)
1581 && NILP (Vunread_post_input_method_events)
1582 && NILP (Vexecuting_macro)
1583 && !NILP (sit_for (0, post_command_idle_delay, 0, 1, 1)))
1584 safe_run_hooks (Qpost_command_idle_hook);
1587 /* If there is a prefix argument,
1588 1) We don't want Vlast_command to be ``universal-argument''
1589 (that would be dumb), so don't set Vlast_command,
1590 2) we want to leave echoing on so that the prefix will be
1591 echoed as part of this key sequence, so don't call
1592 cancel_echoing, and
1593 3) we want to leave this_command_key_count non-zero, so that
1594 read_char will realize that it is re-reading a character, and
1595 not echo it a second time.
1597 If the command didn't actually create a prefix arg,
1598 but is merely a frame event that is transparent to prefix args,
1599 then the above doesn't apply. */
1600 if (NILP (current_kboard->Vprefix_arg) || CONSP (last_command_char))
1602 current_kboard->Vlast_command = Vthis_command;
1603 current_kboard->Vreal_last_command = real_this_command;
1604 cancel_echoing ();
1605 this_command_key_count = 0;
1606 this_single_command_key_start = 0;
1609 if (!NILP (current_buffer->mark_active) && !NILP (Vrun_hooks))
1611 if (!NILP (Vdeactivate_mark) && !NILP (Vtransient_mark_mode))
1613 current_buffer->mark_active = Qnil;
1614 call1 (Vrun_hooks, intern ("deactivate-mark-hook"));
1616 else if (current_buffer != prev_buffer || MODIFF != prev_modiff)
1617 call1 (Vrun_hooks, intern ("activate-mark-hook"));
1620 finalize:
1622 if (current_buffer == prev_buffer
1623 && last_point_position != PT
1624 && NILP (Vdisable_point_adjustment)
1625 && NILP (Vglobal_disable_point_adjustment))
1626 adjust_point_for_property (last_point_position);
1628 /* Install chars successfully executed in kbd macro. */
1630 if (!NILP (current_kboard->defining_kbd_macro)
1631 && NILP (current_kboard->Vprefix_arg))
1632 finalize_kbd_macro_chars ();
1634 #ifdef MULTI_KBOARD
1635 if (!was_locked)
1636 any_kboard_state ();
1637 #endif
1641 extern Lisp_Object Qcomposition, Qdisplay;
1643 /* Adjust point to a boundary of a region that has such a property
1644 that should be treated intangible. For the moment, we check
1645 `composition' and `display' property. LAST_PT is the last position
1646 of point. */
1648 static void
1649 adjust_point_for_property (last_pt)
1650 int last_pt;
1652 int start, end;
1653 Lisp_Object val;
1654 int check_composition = 1, check_display = 1;
1656 while (check_composition || check_display)
1658 if (check_composition
1659 && PT > BEGV && PT < ZV
1660 && get_property_and_range (PT, Qcomposition, &val, &start, &end, Qnil)
1661 && COMPOSITION_VALID_P (start, end, val)
1662 && start < PT && end > PT
1663 && (last_pt <= start || last_pt >= end))
1665 if (PT < last_pt)
1666 SET_PT (start);
1667 else
1668 SET_PT (end);
1669 check_display = 1;
1671 check_composition = 0;
1672 if (check_display
1673 && PT > BEGV && PT < ZV
1674 && get_property_and_range (PT, Qdisplay, &val, &start, &end, Qnil)
1675 && display_prop_intangible_p (val)
1676 && start < PT && end > PT
1677 && (last_pt <= start || last_pt >= end))
1679 if (PT < last_pt)
1680 SET_PT (start);
1681 else
1682 SET_PT (end);
1683 check_composition = 1;
1685 check_display = 0;
1689 /* Subroutine for safe_run_hooks: run the hook HOOK. */
1691 static Lisp_Object
1692 safe_run_hooks_1 (hook)
1693 Lisp_Object hook;
1695 return call1 (Vrun_hooks, Vinhibit_quit);
1698 /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */
1700 static Lisp_Object
1701 safe_run_hooks_error (data)
1702 Lisp_Object data;
1704 return Fset (Vinhibit_quit, Qnil);
1707 /* If we get an error while running the hook, cause the hook variable
1708 to be nil. Also inhibit quits, so that C-g won't cause the hook
1709 to mysteriously evaporate. */
1711 void
1712 safe_run_hooks (hook)
1713 Lisp_Object hook;
1715 int count = specpdl_ptr - specpdl;
1716 specbind (Qinhibit_quit, hook);
1718 internal_condition_case (safe_run_hooks_1, Qt, safe_run_hooks_error);
1720 unbind_to (count, Qnil);
1724 /* Number of seconds between polling for input. This is a Lisp
1725 variable that can be bound. */
1727 int polling_period;
1729 /* Nonzero means polling for input is temporarily suppressed. */
1731 int poll_suppress_count;
1733 /* Asynchronous timer for polling. */
1735 struct atimer *poll_timer;
1738 #ifdef POLL_FOR_INPUT
1740 /* Poll for input, so what we catch a C-g if it comes in. This
1741 function is called from x_make_frame_visible, see comment
1742 there. */
1744 void
1745 poll_for_input_1 ()
1747 if (interrupt_input_blocked == 0
1748 && !waiting_for_input)
1749 read_avail_input (0);
1752 /* Timer callback function for poll_timer. TIMER is equal to
1753 poll_timer. */
1755 void
1756 poll_for_input (timer)
1757 struct atimer *timer;
1759 if (poll_suppress_count == 0)
1760 poll_for_input_1 ();
1763 #endif /* POLL_FOR_INPUT */
1765 /* Begin signals to poll for input, if they are appropriate.
1766 This function is called unconditionally from various places. */
1768 void
1769 start_polling ()
1771 #ifdef POLL_FOR_INPUT
1772 if (read_socket_hook && !interrupt_input)
1774 /* Turn alarm handling on unconditionally. It might have
1775 been turned off in process.c. */
1776 turn_on_atimers (1);
1778 /* If poll timer doesn't exist, are we need one with
1779 a different interval, start a new one. */
1780 if (poll_timer == NULL
1781 || EMACS_SECS (poll_timer->interval) != polling_period)
1783 EMACS_TIME interval;
1785 if (poll_timer)
1786 cancel_atimer (poll_timer);
1788 EMACS_SET_SECS_USECS (interval, polling_period, 0);
1789 poll_timer = start_atimer (ATIMER_CONTINUOUS, interval,
1790 poll_for_input, NULL);
1793 /* Let the timer's callback function poll for input
1794 if this becomes zero. */
1795 --poll_suppress_count;
1797 #endif
1800 /* Nonzero if we are using polling to handle input asynchronously. */
1803 input_polling_used ()
1805 #ifdef POLL_FOR_INPUT
1806 return read_socket_hook && !interrupt_input;
1807 #else
1808 return 0;
1809 #endif
1812 /* Turn off polling. */
1814 void
1815 stop_polling ()
1817 #ifdef POLL_FOR_INPUT
1818 if (read_socket_hook && !interrupt_input)
1819 ++poll_suppress_count;
1820 #endif
1823 /* Set the value of poll_suppress_count to COUNT
1824 and start or stop polling accordingly. */
1826 void
1827 set_poll_suppress_count (count)
1828 int count;
1830 #ifdef POLL_FOR_INPUT
1831 if (count == 0 && poll_suppress_count != 0)
1833 poll_suppress_count = 1;
1834 start_polling ();
1836 else if (count != 0 && poll_suppress_count == 0)
1838 stop_polling ();
1840 poll_suppress_count = count;
1841 #endif
1844 /* Bind polling_period to a value at least N.
1845 But don't decrease it. */
1847 void
1848 bind_polling_period (n)
1849 int n;
1851 #ifdef POLL_FOR_INPUT
1852 int new = polling_period;
1854 if (n > new)
1855 new = n;
1857 stop_other_atimers (poll_timer);
1858 stop_polling ();
1859 specbind (Qpolling_period, make_number (new));
1860 /* Start a new alarm with the new period. */
1861 start_polling ();
1862 #endif
1865 /* Apply the control modifier to CHARACTER. */
1868 make_ctrl_char (c)
1869 int c;
1871 /* Save the upper bits here. */
1872 int upper = c & ~0177;
1874 c &= 0177;
1876 /* Everything in the columns containing the upper-case letters
1877 denotes a control character. */
1878 if (c >= 0100 && c < 0140)
1880 int oc = c;
1881 c &= ~0140;
1882 /* Set the shift modifier for a control char
1883 made from a shifted letter. But only for letters! */
1884 if (oc >= 'A' && oc <= 'Z')
1885 c |= shift_modifier;
1888 /* The lower-case letters denote control characters too. */
1889 else if (c >= 'a' && c <= 'z')
1890 c &= ~0140;
1892 /* Include the bits for control and shift
1893 only if the basic ASCII code can't indicate them. */
1894 else if (c >= ' ')
1895 c |= ctrl_modifier;
1897 /* Replace the high bits. */
1898 c |= (upper & ~ctrl_modifier);
1900 return c;
1903 /* Display help echo in the echo area.
1905 HELP a string means display that string, HELP nil means clear the
1906 help echo. If HELP is a function, call it with OBJECT and POS as
1907 arguments; the function should return a help string or nil for
1908 none. For all other types of HELP evaluate it to obtain a string.
1910 WINDOW is the window in which the help was generated, if any.
1911 It is nil if not in a window.
1913 If OBJECT is a buffer, POS is the position in the buffer where the
1914 `help-echo' text property was found.
1916 If OBJECT is an overlay, that overlay has a `help-echo' property,
1917 and POS is the position in the overlay's buffer under the mouse.
1919 If OBJECT is a string (an overlay string or a string displayed with
1920 the `display' property). POS is the position in that string under
1921 the mouse.
1923 OK_TO_IVERWRITE_KEYSTROKE_ECHO non-zero means it's okay if the help
1924 echo overwrites a keystroke echo currently displayed in the echo
1925 area.
1927 Note: this function may only be called with HELP nil or a string
1928 from X code running asynchronously. */
1930 void
1931 show_help_echo (help, window, object, pos, ok_to_overwrite_keystroke_echo)
1932 Lisp_Object help, window, object, pos;
1933 int ok_to_overwrite_keystroke_echo;
1935 if (!NILP (help) && !STRINGP (help))
1937 if (FUNCTIONP (help))
1939 Lisp_Object args[4];
1940 args[0] = help;
1941 args[1] = window;
1942 args[2] = object;
1943 args[3] = pos;
1944 help = call_function (4, args);
1946 else
1947 help = eval_form (help);
1949 if (!STRINGP (help))
1950 return;
1953 if (STRINGP (help) || NILP (help))
1955 if (!NILP (Vshow_help_function))
1956 call1 (Vshow_help_function, help);
1957 else if (/* Don't overwrite minibuffer contents. */
1958 !MINI_WINDOW_P (XWINDOW (selected_window))
1959 /* Don't overwrite a keystroke echo. */
1960 && (NILP (echo_message_buffer)
1961 || ok_to_overwrite_keystroke_echo)
1962 /* Don't overwrite a prompt. */
1963 && !cursor_in_echo_area)
1965 if (STRINGP (help))
1967 int count = specpdl_ptr - specpdl;
1968 specbind (Qmessage_truncate_lines, Qt);
1969 message3_nolog (help, XSTRING (help)->size,
1970 STRING_MULTIBYTE (help));
1971 unbind_to (count, Qnil);
1973 else
1974 message (0);
1981 /* Input of single characters from keyboard */
1983 Lisp_Object print_help ();
1984 static Lisp_Object kbd_buffer_get_event ();
1985 static void record_char ();
1987 #ifdef MULTI_KBOARD
1988 static jmp_buf wrong_kboard_jmpbuf;
1989 #endif
1991 /* read a character from the keyboard; call the redisplay if needed */
1992 /* commandflag 0 means do not do auto-saving, but do do redisplay.
1993 -1 means do not do redisplay, but do do autosaving.
1994 1 means do both. */
1996 /* The arguments MAPS and NMAPS are for menu prompting.
1997 MAPS is an array of keymaps; NMAPS is the length of MAPS.
1999 PREV_EVENT is the previous input event, or nil if we are reading
2000 the first event of a key sequence (or not reading a key sequence).
2001 If PREV_EVENT is t, that is a "magic" value that says
2002 not to run input methods, but in other respects to act as if
2003 not reading a key sequence.
2005 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
2006 if we used a mouse menu to read the input, or zero otherwise. If
2007 USED_MOUSE_MENU is null, we don't dereference it.
2009 Value is t if we showed a menu and the user rejected it. */
2011 Lisp_Object
2012 read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu)
2013 int commandflag;
2014 int nmaps;
2015 Lisp_Object *maps;
2016 Lisp_Object prev_event;
2017 int *used_mouse_menu;
2019 Lisp_Object c;
2020 int count;
2021 jmp_buf local_getcjmp;
2022 jmp_buf save_jump;
2023 int key_already_recorded = 0;
2024 Lisp_Object tem, save;
2025 Lisp_Object previous_echo_area_message;
2026 Lisp_Object also_record;
2027 int reread;
2028 struct gcpro gcpro1, gcpro2;
2030 also_record = Qnil;
2032 before_command_key_count = this_command_key_count;
2033 before_command_echo_length = echo_length ();
2034 c = Qnil;
2035 previous_echo_area_message = Qnil;
2037 GCPRO2 (c, previous_echo_area_message);
2039 retry:
2041 reread = 0;
2042 if (CONSP (Vunread_post_input_method_events))
2044 c = XCAR (Vunread_post_input_method_events);
2045 Vunread_post_input_method_events
2046 = XCDR (Vunread_post_input_method_events);
2048 /* Undo what read_char_x_menu_prompt did when it unread
2049 additional keys returned by Fx_popup_menu. */
2050 if (CONSP (c)
2051 && (SYMBOLP (XCAR (c)) || INTEGERP (XCAR (c)))
2052 && NILP (XCDR (c)))
2053 c = XCAR (c);
2055 reread = 1;
2056 goto reread_first;
2059 if (unread_command_char != -1)
2061 XSETINT (c, unread_command_char);
2062 unread_command_char = -1;
2064 reread = 1;
2065 goto reread_first;
2068 if (CONSP (Vunread_command_events))
2070 c = XCAR (Vunread_command_events);
2071 Vunread_command_events = XCDR (Vunread_command_events);
2073 /* Undo what read_char_x_menu_prompt did when it unread
2074 additional keys returned by Fx_popup_menu. */
2075 if (CONSP (c)
2076 && (SYMBOLP (XCAR (c)) || INTEGERP (XCAR (c)))
2077 && NILP (XCDR (c)))
2078 c = XCAR (c);
2080 reread = 1;
2081 goto reread_for_input_method;
2084 if (CONSP (Vunread_input_method_events))
2086 c = XCAR (Vunread_input_method_events);
2087 Vunread_input_method_events = XCDR (Vunread_input_method_events);
2089 /* Undo what read_char_x_menu_prompt did when it unread
2090 additional keys returned by Fx_popup_menu. */
2091 if (CONSP (c)
2092 && (SYMBOLP (XCAR (c)) || INTEGERP (XCAR (c)))
2093 && NILP (XCDR (c)))
2094 c = XCAR (c);
2095 reread = 1;
2096 goto reread_for_input_method;
2099 /* If there is no function key translated before
2100 reset-this-command-lengths takes effect, forget about it. */
2101 before_command_restore_flag = 0;
2103 if (!NILP (Vexecuting_macro))
2105 /* We set this to Qmacro; since that's not a frame, nobody will
2106 try to switch frames on us, and the selected window will
2107 remain unchanged.
2109 Since this event came from a macro, it would be misleading to
2110 leave internal_last_event_frame set to wherever the last
2111 real event came from. Normally, a switch-frame event selects
2112 internal_last_event_frame after each command is read, but
2113 events read from a macro should never cause a new frame to be
2114 selected. */
2115 Vlast_event_frame = internal_last_event_frame = Qmacro;
2117 /* Exit the macro if we are at the end.
2118 Also, some things replace the macro with t
2119 to force an early exit. */
2120 if (EQ (Vexecuting_macro, Qt)
2121 || executing_macro_index >= XFASTINT (Flength (Vexecuting_macro)))
2123 XSETINT (c, -1);
2124 RETURN_UNGCPRO (c);
2127 c = Faref (Vexecuting_macro, make_number (executing_macro_index));
2128 if (STRINGP (Vexecuting_macro)
2129 && (XINT (c) & 0x80))
2130 XSETFASTINT (c, CHAR_META | (XINT (c) & ~0x80));
2132 executing_macro_index++;
2134 goto from_macro;
2137 if (!NILP (unread_switch_frame))
2139 c = unread_switch_frame;
2140 unread_switch_frame = Qnil;
2142 /* This event should make it into this_command_keys, and get echoed
2143 again, so we do not set `reread'. */
2144 goto reread_first;
2147 /* if redisplay was requested */
2148 if (commandflag >= 0)
2150 /* If there is pending input, process any events which are not
2151 user-visible, such as X selection_request events. */
2152 if (input_pending
2153 || detect_input_pending_run_timers (0))
2154 swallow_events (0); /* may clear input_pending */
2156 /* Redisplay if no pending input. */
2157 while (!input_pending)
2159 redisplay ();
2161 if (!input_pending)
2162 /* Normal case: no input arrived during redisplay. */
2163 break;
2165 /* Input arrived and pre-empted redisplay.
2166 Process any events which are not user-visible. */
2167 swallow_events (0);
2168 /* If that cleared input_pending, try again to redisplay. */
2172 /* Message turns off echoing unless more keystrokes turn it on again.
2174 The code in 20.x for the condition was
2176 1. echo_area_glyphs && *echo_area_glyphs
2177 2. && echo_area_glyphs != current_kboard->echobuf
2178 3. && ok_to_echo_at_next_pause != echo_area_glyphs
2180 (1) means there's a current message displayed
2182 (2) means it's not the message from echoing from the current
2183 kboard.
2185 (3) There's only one place in 20.x where ok_to_echo_at_next_pause
2186 is set to a non-null value. This is done in read_char and it is
2187 set to echo_area_glyphs after a call to echo_char. That means
2188 ok_to_echo_at_next_pause is either null or
2189 current_kboard->echobuf with the appropriate current_kboard at
2190 that time.
2192 So, condition (3) means in clear text ok_to_echo_at_next_pause
2193 must be either null, or the current message isn't from echoing at
2194 all, or it's from echoing from a different kboard than the
2195 current one. */
2197 if (/* There currently something in the echo area */
2198 !NILP (echo_area_buffer[0])
2199 && (/* And it's either not from echoing. */
2200 !EQ (echo_area_buffer[0], echo_message_buffer)
2201 /* Or it's an echo from a different kboard. */
2202 || echo_kboard != current_kboard
2203 /* Or we explicitly allow overwriting whatever there is. */
2204 || ok_to_echo_at_next_pause == NULL))
2205 cancel_echoing ();
2206 else
2207 echo_dash ();
2209 /* Try reading a character via menu prompting in the minibuf.
2210 Try this before the sit-for, because the sit-for
2211 would do the wrong thing if we are supposed to do
2212 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
2213 after a mouse event so don't try a minibuf menu. */
2214 c = Qnil;
2215 if (nmaps > 0 && INTERACTIVE
2216 && !NILP (prev_event) && ! EVENT_HAS_PARAMETERS (prev_event)
2217 /* Don't bring up a menu if we already have another event. */
2218 && NILP (Vunread_command_events)
2219 && unread_command_char < 0
2220 && !detect_input_pending_run_timers (0))
2222 c = read_char_minibuf_menu_prompt (commandflag, nmaps, maps);
2223 if (! NILP (c))
2225 key_already_recorded = 1;
2226 goto non_reread_1;
2230 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet.
2231 We will do that below, temporarily for short sections of code,
2232 when appropriate. local_getcjmp must be in effect
2233 around any call to sit_for or kbd_buffer_get_event;
2234 it *must not* be in effect when we call redisplay. */
2236 if (_setjmp (local_getcjmp))
2238 XSETINT (c, quit_char);
2239 internal_last_event_frame = selected_frame;
2240 Vlast_event_frame = internal_last_event_frame;
2241 /* If we report the quit char as an event,
2242 don't do so more than once. */
2243 if (!NILP (Vinhibit_quit))
2244 Vquit_flag = Qnil;
2246 #ifdef MULTI_KBOARD
2248 KBOARD *kb = FRAME_KBOARD (XFRAME (selected_frame));
2249 if (kb != current_kboard)
2251 Lisp_Object *tailp = &kb->kbd_queue;
2252 /* We shouldn't get here if we were in single-kboard mode! */
2253 if (single_kboard)
2254 abort ();
2255 while (CONSP (*tailp))
2256 tailp = &XCDR (*tailp);
2257 if (!NILP (*tailp))
2258 abort ();
2259 *tailp = Fcons (c, Qnil);
2260 kb->kbd_queue_has_data = 1;
2261 current_kboard = kb;
2262 /* This is going to exit from read_char
2263 so we had better get rid of this frame's stuff. */
2264 UNGCPRO;
2265 longjmp (wrong_kboard_jmpbuf, 1);
2268 #endif
2269 goto non_reread;
2272 timer_start_idle ();
2274 /* If in middle of key sequence and minibuffer not active,
2275 start echoing if enough time elapses. */
2277 if (minibuf_level == 0
2278 && !current_kboard->immediate_echo
2279 && this_command_key_count > 0
2280 && ! noninteractive
2281 && (FLOATP (Vecho_keystrokes) || INTEGERP (Vecho_keystrokes))
2282 && NILP (Fzerop (Vecho_keystrokes))
2283 && (/* No message. */
2284 NILP (echo_area_buffer[0])
2285 /* Or empty message. */
2286 || (BUF_BEG (XBUFFER (echo_area_buffer[0]))
2287 == BUF_Z (XBUFFER (echo_area_buffer[0])))
2288 /* Or already echoing from same kboard. */
2289 || (echo_kboard && ok_to_echo_at_next_pause == echo_kboard)
2290 /* Or not echoing before and echoing allowed. */
2291 || (!echo_kboard && ok_to_echo_at_next_pause)))
2293 Lisp_Object tem0;
2295 /* After a mouse event, start echoing right away.
2296 This is because we are probably about to display a menu,
2297 and we don't want to delay before doing so. */
2298 if (EVENT_HAS_PARAMETERS (prev_event))
2299 echo_now ();
2300 else
2302 int sec, usec;
2303 double duration = extract_float (Vecho_keystrokes);
2304 sec = (int) duration;
2305 usec = (duration - sec) * 1000000;
2306 save_getcjmp (save_jump);
2307 restore_getcjmp (local_getcjmp);
2308 tem0 = sit_for (sec, usec, 1, 1, 0);
2309 restore_getcjmp (save_jump);
2310 if (EQ (tem0, Qt)
2311 && ! CONSP (Vunread_command_events))
2312 echo_now ();
2316 /* Maybe auto save due to number of keystrokes. */
2318 if (commandflag != 0
2319 && auto_save_interval > 0
2320 && num_nonmacro_input_events - last_auto_save > max (auto_save_interval, 20)
2321 && !detect_input_pending_run_timers (0))
2323 Fdo_auto_save (Qnil, Qnil);
2324 /* Hooks can actually change some buffers in auto save. */
2325 redisplay ();
2328 /* Try reading using an X menu.
2329 This is never confused with reading using the minibuf
2330 because the recursive call of read_char in read_char_minibuf_menu_prompt
2331 does not pass on any keymaps. */
2333 if (nmaps > 0 && INTERACTIVE
2334 && !NILP (prev_event)
2335 && EVENT_HAS_PARAMETERS (prev_event)
2336 && !EQ (XCAR (prev_event), Qmenu_bar)
2337 && !EQ (XCAR (prev_event), Qtool_bar)
2338 /* Don't bring up a menu if we already have another event. */
2339 && NILP (Vunread_command_events)
2340 && unread_command_char < 0)
2342 c = read_char_x_menu_prompt (nmaps, maps, prev_event, used_mouse_menu);
2344 /* Now that we have read an event, Emacs is not idle. */
2345 timer_stop_idle ();
2347 RETURN_UNGCPRO (c);
2350 /* Maybe autosave and/or garbage collect due to idleness. */
2352 if (INTERACTIVE && NILP (c))
2354 int delay_level, buffer_size;
2356 /* Slow down auto saves logarithmically in size of current buffer,
2357 and garbage collect while we're at it. */
2358 if (! MINI_WINDOW_P (XWINDOW (selected_window)))
2359 last_non_minibuf_size = Z - BEG;
2360 buffer_size = (last_non_minibuf_size >> 8) + 1;
2361 delay_level = 0;
2362 while (buffer_size > 64)
2363 delay_level++, buffer_size -= buffer_size >> 2;
2364 if (delay_level < 4) delay_level = 4;
2365 /* delay_level is 4 for files under around 50k, 7 at 100k,
2366 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
2368 /* Auto save if enough time goes by without input. */
2369 if (commandflag != 0
2370 && num_nonmacro_input_events > last_auto_save
2371 && INTEGERP (Vauto_save_timeout)
2372 && XINT (Vauto_save_timeout) > 0)
2374 Lisp_Object tem0;
2376 save_getcjmp (save_jump);
2377 restore_getcjmp (local_getcjmp);
2378 tem0 = sit_for (delay_level * XFASTINT (Vauto_save_timeout) / 4,
2379 0, 1, 1, 0);
2380 restore_getcjmp (save_jump);
2382 if (EQ (tem0, Qt)
2383 && ! CONSP (Vunread_command_events))
2385 Fdo_auto_save (Qnil, Qnil);
2387 /* If we have auto-saved and there is still no input
2388 available, garbage collect if there has been enough
2389 consing going on to make it worthwhile. */
2390 if (!detect_input_pending_run_timers (0)
2391 && consing_since_gc > gc_cons_threshold / 2)
2392 Fgarbage_collect ();
2394 redisplay ();
2399 /* If this has become non-nil here, it has been set by a timer
2400 or sentinel or filter. */
2401 if (CONSP (Vunread_command_events))
2403 c = XCAR (Vunread_command_events);
2404 Vunread_command_events = XCDR (Vunread_command_events);
2407 /* Read something from current KBOARD's side queue, if possible. */
2409 if (NILP (c))
2411 if (current_kboard->kbd_queue_has_data)
2413 if (!CONSP (current_kboard->kbd_queue))
2414 abort ();
2415 c = XCAR (current_kboard->kbd_queue);
2416 current_kboard->kbd_queue
2417 = XCDR (current_kboard->kbd_queue);
2418 if (NILP (current_kboard->kbd_queue))
2419 current_kboard->kbd_queue_has_data = 0;
2420 input_pending = readable_events (0);
2421 if (EVENT_HAS_PARAMETERS (c)
2422 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c)), Qswitch_frame))
2423 internal_last_event_frame = XCAR (XCDR (c));
2424 Vlast_event_frame = internal_last_event_frame;
2428 #ifdef MULTI_KBOARD
2429 /* If current_kboard's side queue is empty check the other kboards.
2430 If one of them has data that we have not yet seen here,
2431 switch to it and process the data waiting for it.
2433 Note: if the events queued up for another kboard
2434 have already been seen here, and therefore are not a complete command,
2435 the kbd_queue_has_data field is 0, so we skip that kboard here.
2436 That's to avoid an infinite loop switching between kboards here. */
2437 if (NILP (c) && !single_kboard)
2439 KBOARD *kb;
2440 for (kb = all_kboards; kb; kb = kb->next_kboard)
2441 if (kb->kbd_queue_has_data)
2443 current_kboard = kb;
2444 /* This is going to exit from read_char
2445 so we had better get rid of this frame's stuff. */
2446 UNGCPRO;
2447 longjmp (wrong_kboard_jmpbuf, 1);
2450 #endif
2452 wrong_kboard:
2454 stop_polling ();
2456 /* Finally, we read from the main queue,
2457 and if that gives us something we can't use yet, we put it on the
2458 appropriate side queue and try again. */
2460 if (NILP (c))
2462 KBOARD *kb;
2464 /* Actually read a character, waiting if necessary. */
2465 save_getcjmp (save_jump);
2466 restore_getcjmp (local_getcjmp);
2467 c = kbd_buffer_get_event (&kb, used_mouse_menu);
2468 restore_getcjmp (save_jump);
2470 #ifdef MULTI_KBOARD
2471 if (! NILP (c) && (kb != current_kboard))
2473 Lisp_Object *tailp = &kb->kbd_queue;
2474 while (CONSP (*tailp))
2475 tailp = &XCDR (*tailp);
2476 if (!NILP (*tailp))
2477 abort ();
2478 *tailp = Fcons (c, Qnil);
2479 kb->kbd_queue_has_data = 1;
2480 c = Qnil;
2481 if (single_kboard)
2482 goto wrong_kboard;
2483 current_kboard = kb;
2484 /* This is going to exit from read_char
2485 so we had better get rid of this frame's stuff. */
2486 UNGCPRO;
2487 longjmp (wrong_kboard_jmpbuf, 1);
2489 #endif
2492 /* Terminate Emacs in batch mode if at eof. */
2493 if (noninteractive && INTEGERP (c) && XINT (c) < 0)
2494 Fkill_emacs (make_number (1));
2496 if (INTEGERP (c))
2498 /* Add in any extra modifiers, where appropriate. */
2499 if ((extra_keyboard_modifiers & CHAR_CTL)
2500 || ((extra_keyboard_modifiers & 0177) < ' '
2501 && (extra_keyboard_modifiers & 0177) != 0))
2502 XSETINT (c, make_ctrl_char (XINT (c)));
2504 /* Transfer any other modifier bits directly from
2505 extra_keyboard_modifiers to c. Ignore the actual character code
2506 in the low 16 bits of extra_keyboard_modifiers. */
2507 XSETINT (c, XINT (c) | (extra_keyboard_modifiers & ~0xff7f & ~CHAR_CTL));
2510 non_reread:
2512 timer_stop_idle ();
2514 start_polling ();
2516 if (NILP (c))
2518 if (commandflag >= 0
2519 && !input_pending && !detect_input_pending_run_timers (0))
2520 redisplay ();
2522 goto wrong_kboard;
2525 non_reread_1:
2527 /* Buffer switch events are only for internal wakeups
2528 so don't show them to the user.
2529 Also, don't record a key if we already did. */
2530 if (BUFFERP (c) || key_already_recorded)
2531 RETURN_UNGCPRO (c);
2533 /* Process special events within read_char
2534 and loop around to read another event. */
2535 save = Vquit_flag;
2536 Vquit_flag = Qnil;
2537 tem = get_keyelt (access_keymap (get_keymap_1 (Vspecial_event_map, 0, 0),
2538 c, 0, 0), 1);
2539 Vquit_flag = save;
2541 if (!NILP (tem))
2543 int was_locked = single_kboard;
2545 last_input_char = c;
2546 Fcommand_execute (tem, Qnil, Fvector (1, &last_input_char), Qt);
2548 /* Resume allowing input from any kboard, if that was true before. */
2549 if (!was_locked)
2550 any_kboard_state ();
2552 goto retry;
2555 /* Handle things that only apply to characters. */
2556 if (INTEGERP (c))
2558 /* If kbd_buffer_get_event gave us an EOF, return that. */
2559 if (XINT (c) == -1)
2560 RETURN_UNGCPRO (c);
2562 if ((STRINGP (Vkeyboard_translate_table)
2563 && XSTRING (Vkeyboard_translate_table)->size > (unsigned) XFASTINT (c))
2564 || (VECTORP (Vkeyboard_translate_table)
2565 && XVECTOR (Vkeyboard_translate_table)->size > (unsigned) XFASTINT (c))
2566 || (CHAR_TABLE_P (Vkeyboard_translate_table)
2567 && CHAR_TABLE_ORDINARY_SLOTS > (unsigned) XFASTINT (c)))
2569 Lisp_Object d;
2570 d = Faref (Vkeyboard_translate_table, c);
2571 /* nil in keyboard-translate-table means no translation. */
2572 if (!NILP (d))
2573 c = d;
2577 /* If this event is a mouse click in the menu bar,
2578 return just menu-bar for now. Modify the mouse click event
2579 so we won't do this twice, then queue it up. */
2580 if (EVENT_HAS_PARAMETERS (c)
2581 && CONSP (XCDR (c))
2582 && CONSP (EVENT_START (c))
2583 && CONSP (XCDR (EVENT_START (c))))
2585 Lisp_Object posn;
2587 posn = POSN_BUFFER_POSN (EVENT_START (c));
2588 /* Handle menu-bar events:
2589 insert the dummy prefix event `menu-bar'. */
2590 if (EQ (posn, Qmenu_bar) || EQ (posn, Qtool_bar))
2592 /* Change menu-bar to (menu-bar) as the event "position". */
2593 POSN_BUFFER_POSN (EVENT_START (c)) = Fcons (posn, Qnil);
2595 also_record = c;
2596 Vunread_command_events = Fcons (c, Vunread_command_events);
2597 c = posn;
2601 /* Store these characters into recent_keys, the dribble file if any,
2602 and the keyboard macro being defined, if any. */
2603 record_char (c);
2604 if (! NILP (also_record))
2605 record_char (also_record);
2607 /* Wipe the echo area.
2608 But first, if we are about to use an input method,
2609 save the echo area contents for it to refer to. */
2610 if (INTEGERP (c)
2611 && ! NILP (Vinput_method_function)
2612 && (unsigned) XINT (c) >= ' '
2613 && (unsigned) XINT (c) != 127
2614 && (unsigned) XINT (c) < 256)
2616 previous_echo_area_message = Fcurrent_message ();
2617 Vinput_method_previous_message = previous_echo_area_message;
2620 /* Now wipe the echo area, except for help events which do their
2621 own stuff with the echo area. */
2622 if (!CONSP (c) || !(EQ (Qhelp_echo, XCAR (c))))
2624 if (!NILP (echo_area_buffer[0]))
2625 safe_run_hooks (Qecho_area_clear_hook);
2626 clear_message (1, 0);
2629 reread_for_input_method:
2630 from_macro:
2631 /* Pass this to the input method, if appropriate. */
2632 if (INTEGERP (c)
2633 && ! NILP (Vinput_method_function)
2634 /* Don't run the input method within a key sequence,
2635 after the first event of the key sequence. */
2636 && NILP (prev_event)
2637 && (unsigned) XINT (c) >= ' '
2638 && (unsigned) XINT (c) != 127
2639 && (unsigned) XINT (c) < 256)
2641 Lisp_Object keys;
2642 int key_count;
2643 struct gcpro gcpro1;
2644 int count = specpdl_ptr - specpdl;
2646 /* Save the echo status. */
2647 int saved_immediate_echo = current_kboard->immediate_echo;
2648 struct kboard *saved_ok_to_echo = ok_to_echo_at_next_pause;
2649 int saved_echo_after_prompt = current_kboard->echo_after_prompt;
2651 if (before_command_restore_flag)
2653 this_command_key_count = before_command_key_count_1;
2654 if (this_command_key_count < this_single_command_key_start)
2655 this_single_command_key_start = this_command_key_count;
2656 echo_truncate (before_command_echo_length_1);
2657 before_command_restore_flag = 0;
2660 /* Save the this_command_keys status. */
2661 key_count = this_command_key_count;
2663 if (key_count > 0)
2664 keys = Fcopy_sequence (this_command_keys);
2665 else
2666 keys = Qnil;
2667 GCPRO1 (keys);
2669 /* Clear out this_command_keys. */
2670 this_command_key_count = 0;
2672 /* Now wipe the echo area. */
2673 if (!NILP (echo_area_buffer[0]))
2674 safe_run_hooks (Qecho_area_clear_hook);
2675 clear_message (1, 0);
2676 echo_truncate (0);
2678 /* If we are not reading a key sequence,
2679 never use the echo area. */
2680 if (maps == 0)
2682 specbind (Qinput_method_use_echo_area, Qt);
2685 /* Call the input method. */
2686 tem = call1 (Vinput_method_function, c);
2688 tem = unbind_to (count, tem);
2690 /* Restore the saved echoing state
2691 and this_command_keys state. */
2692 this_command_key_count = key_count;
2693 if (key_count > 0)
2694 this_command_keys = keys;
2696 cancel_echoing ();
2697 ok_to_echo_at_next_pause = saved_ok_to_echo;
2698 current_kboard->echo_after_prompt = saved_echo_after_prompt;
2699 if (saved_immediate_echo)
2700 echo_now ();
2702 UNGCPRO;
2704 /* The input method can return no events. */
2705 if (! CONSP (tem))
2707 /* Bring back the previous message, if any. */
2708 if (! NILP (previous_echo_area_message))
2709 message_with_string ("%s", previous_echo_area_message, 0);
2710 goto retry;
2712 /* It returned one event or more. */
2713 c = XCAR (tem);
2714 Vunread_post_input_method_events
2715 = nconc2 (XCDR (tem), Vunread_post_input_method_events);
2718 reread_first:
2720 /* Display help if not echoing. */
2721 if (CONSP (c) && EQ (XCAR (c), Qhelp_echo))
2723 /* (help-echo FRAME HELP WINDOW OBJECT POS). */
2724 Lisp_Object help, object, position, window;
2725 help = Fnth (make_number (2), c);
2726 window = Fnth (make_number (3), c);
2727 object = Fnth (make_number (4), c);
2728 position = Fnth (make_number (5), c);
2729 show_help_echo (help, window, object, position, 0);
2730 goto retry;
2733 if (this_command_key_count == 0 || ! reread)
2735 before_command_key_count = this_command_key_count;
2736 before_command_echo_length = echo_length ();
2738 /* Don't echo mouse motion events. */
2739 if ((FLOATP (Vecho_keystrokes) || INTEGERP (Vecho_keystrokes))
2740 && NILP (Fzerop (Vecho_keystrokes))
2741 && ! (EVENT_HAS_PARAMETERS (c)
2742 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c)), Qmouse_movement)))
2744 echo_char (c);
2745 if (! NILP (also_record))
2746 echo_char (also_record);
2747 /* Once we reread a character, echoing can happen
2748 the next time we pause to read a new one. */
2749 ok_to_echo_at_next_pause = current_kboard;
2752 /* Record this character as part of the current key. */
2753 add_command_key (c);
2754 if (! NILP (also_record))
2755 add_command_key (also_record);
2758 last_input_char = c;
2759 num_input_events++;
2761 /* Process the help character specially if enabled */
2762 if (!NILP (Vhelp_form) && help_char_p (c))
2764 Lisp_Object tem0;
2765 count = specpdl_ptr - specpdl;
2767 record_unwind_protect (Fset_window_configuration,
2768 Fcurrent_window_configuration (Qnil));
2770 tem0 = Feval (Vhelp_form);
2771 if (STRINGP (tem0))
2772 internal_with_output_to_temp_buffer ("*Help*", print_help, tem0);
2774 cancel_echoing ();
2776 c = read_char (0, 0, 0, Qnil, 0);
2777 while (BUFFERP (c));
2778 /* Remove the help from the frame */
2779 unbind_to (count, Qnil);
2781 redisplay ();
2782 if (EQ (c, make_number (040)))
2784 cancel_echoing ();
2786 c = read_char (0, 0, 0, Qnil, 0);
2787 while (BUFFERP (c));
2791 RETURN_UNGCPRO (c);
2794 /* Record a key that came from a mouse menu.
2795 Record it for echoing, for this-command-keys, and so on. */
2797 static void
2798 record_menu_key (c)
2799 Lisp_Object c;
2801 /* Wipe the echo area. */
2802 clear_message (1, 0);
2804 record_char (c);
2806 before_command_key_count = this_command_key_count;
2807 before_command_echo_length = echo_length ();
2809 /* Don't echo mouse motion events. */
2810 if ((FLOATP (Vecho_keystrokes) || INTEGERP (Vecho_keystrokes))
2811 && NILP (Fzerop (Vecho_keystrokes)))
2813 echo_char (c);
2815 /* Once we reread a character, echoing can happen
2816 the next time we pause to read a new one. */
2817 ok_to_echo_at_next_pause = 0;
2820 /* Record this character as part of the current key. */
2821 add_command_key (c);
2823 /* Re-reading in the middle of a command */
2824 last_input_char = c;
2825 num_input_events++;
2828 /* Return 1 if should recognize C as "the help character". */
2831 help_char_p (c)
2832 Lisp_Object c;
2834 Lisp_Object tail;
2836 if (EQ (c, Vhelp_char))
2837 return 1;
2838 for (tail = Vhelp_event_list; CONSP (tail); tail = XCDR (tail))
2839 if (EQ (c, XCAR (tail)))
2840 return 1;
2841 return 0;
2844 /* Record the input event C in various ways. */
2846 static void
2847 record_char (c)
2848 Lisp_Object c;
2850 total_keys++;
2851 XVECTOR (recent_keys)->contents[recent_keys_index] = c;
2852 if (++recent_keys_index >= NUM_RECENT_KEYS)
2853 recent_keys_index = 0;
2855 /* Write c to the dribble file. If c is a lispy event, write
2856 the event's symbol to the dribble file, in <brackets>. Bleaugh.
2857 If you, dear reader, have a better idea, you've got the source. :-) */
2858 if (dribble)
2860 if (INTEGERP (c))
2862 if (XUINT (c) < 0x100)
2863 putc (XINT (c), dribble);
2864 else
2865 fprintf (dribble, " 0x%x", (int) XUINT (c));
2867 else
2869 Lisp_Object dribblee;
2871 /* If it's a structured event, take the event header. */
2872 dribblee = EVENT_HEAD (c);
2874 if (SYMBOLP (dribblee))
2876 putc ('<', dribble);
2877 fwrite (XSYMBOL (dribblee)->name->data, sizeof (char),
2878 STRING_BYTES (XSYMBOL (dribblee)->name),
2879 dribble);
2880 putc ('>', dribble);
2884 fflush (dribble);
2887 store_kbd_macro_char (c);
2889 num_nonmacro_input_events++;
2892 Lisp_Object
2893 print_help (object)
2894 Lisp_Object object;
2896 struct buffer *old = current_buffer;
2897 Fprinc (object, Qnil);
2898 set_buffer_internal (XBUFFER (Vstandard_output));
2899 call0 (intern ("help-mode"));
2900 set_buffer_internal (old);
2901 return Qnil;
2904 /* Copy out or in the info on where C-g should throw to.
2905 This is used when running Lisp code from within get_char,
2906 in case get_char is called recursively.
2907 See read_process_output. */
2909 static void
2910 save_getcjmp (temp)
2911 jmp_buf temp;
2913 bcopy (getcjmp, temp, sizeof getcjmp);
2916 static void
2917 restore_getcjmp (temp)
2918 jmp_buf temp;
2920 bcopy (temp, getcjmp, sizeof getcjmp);
2923 #ifdef HAVE_MOUSE
2925 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
2926 of this function. */
2928 static Lisp_Object
2929 tracking_off (old_value)
2930 Lisp_Object old_value;
2932 do_mouse_tracking = old_value;
2933 if (NILP (old_value))
2935 /* Redisplay may have been preempted because there was input
2936 available, and it assumes it will be called again after the
2937 input has been processed. If the only input available was
2938 the sort that we have just disabled, then we need to call
2939 redisplay. */
2940 if (!readable_events (1))
2942 redisplay_preserve_echo_area ();
2943 get_input_pending (&input_pending, 1);
2946 return Qnil;
2949 DEFUN ("track-mouse", Ftrack_mouse, Strack_mouse, 0, UNEVALLED, 0,
2950 "Evaluate BODY with mouse movement events enabled.\n\
2951 Within a `track-mouse' form, mouse motion generates input events that\n\
2952 you can read with `read-event'.\n\
2953 Normally, mouse motion is ignored.")
2954 (args)
2955 Lisp_Object args;
2957 int count = specpdl_ptr - specpdl;
2958 Lisp_Object val;
2960 record_unwind_protect (tracking_off, do_mouse_tracking);
2962 do_mouse_tracking = Qt;
2964 val = Fprogn (args);
2965 return unbind_to (count, val);
2968 /* If mouse has moved on some frame, return one of those frames.
2969 Return 0 otherwise. */
2971 static FRAME_PTR
2972 some_mouse_moved ()
2974 Lisp_Object tail, frame;
2976 FOR_EACH_FRAME (tail, frame)
2978 if (XFRAME (frame)->mouse_moved)
2979 return XFRAME (frame);
2982 return 0;
2985 #endif /* HAVE_MOUSE */
2987 /* Low level keyboard/mouse input.
2988 kbd_buffer_store_event places events in kbd_buffer, and
2989 kbd_buffer_get_event retrieves them. */
2991 /* Return true iff there are any events in the queue that read-char
2992 would return. If this returns false, a read-char would block. */
2993 static int
2994 readable_events (do_timers_now)
2995 int do_timers_now;
2997 if (do_timers_now)
2998 timer_check (do_timers_now);
3000 if (kbd_fetch_ptr != kbd_store_ptr)
3001 return 1;
3002 #ifdef HAVE_MOUSE
3003 if (!NILP (do_mouse_tracking) && some_mouse_moved ())
3004 return 1;
3005 #endif
3006 if (single_kboard)
3008 if (current_kboard->kbd_queue_has_data)
3009 return 1;
3011 else
3013 KBOARD *kb;
3014 for (kb = all_kboards; kb; kb = kb->next_kboard)
3015 if (kb->kbd_queue_has_data)
3016 return 1;
3018 return 0;
3021 /* Set this for debugging, to have a way to get out */
3022 int stop_character;
3024 #ifdef MULTI_KBOARD
3025 static KBOARD *
3026 event_to_kboard (event)
3027 struct input_event *event;
3029 Lisp_Object frame;
3030 frame = event->frame_or_window;
3031 if (CONSP (frame))
3032 frame = XCAR (frame);
3033 else if (WINDOWP (frame))
3034 frame = WINDOW_FRAME (XWINDOW (frame));
3036 /* There are still some events that don't set this field.
3037 For now, just ignore the problem.
3038 Also ignore dead frames here. */
3039 if (!FRAMEP (frame) || !FRAME_LIVE_P (XFRAME (frame)))
3040 return 0;
3041 else
3042 return FRAME_KBOARD (XFRAME (frame));
3044 #endif
3046 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
3048 void
3049 kbd_buffer_store_event (event)
3050 register struct input_event *event;
3052 if (event->kind == no_event)
3053 abort ();
3055 if (event->kind == ascii_keystroke)
3057 register int c = event->code & 0377;
3059 if (event->modifiers & ctrl_modifier)
3060 c = make_ctrl_char (c);
3062 c |= (event->modifiers
3063 & (meta_modifier | alt_modifier
3064 | hyper_modifier | super_modifier));
3066 if (c == quit_char)
3068 extern SIGTYPE interrupt_signal ();
3069 #ifdef MULTI_KBOARD
3070 KBOARD *kb;
3071 struct input_event *sp;
3073 if (single_kboard
3074 && (kb = FRAME_KBOARD (XFRAME (event->frame_or_window)),
3075 kb != current_kboard))
3077 kb->kbd_queue
3078 = Fcons (make_lispy_switch_frame (event->frame_or_window),
3079 Fcons (make_number (c), Qnil));
3080 kb->kbd_queue_has_data = 1;
3081 for (sp = kbd_fetch_ptr; sp != kbd_store_ptr; sp++)
3083 if (sp == kbd_buffer + KBD_BUFFER_SIZE)
3084 sp = kbd_buffer;
3086 if (event_to_kboard (sp) == kb)
3088 sp->kind = no_event;
3089 sp->frame_or_window = Qnil;
3090 sp->arg = Qnil;
3093 return;
3095 #endif
3097 /* If this results in a quit_char being returned to Emacs as
3098 input, set Vlast_event_frame properly. If this doesn't
3099 get returned to Emacs as an event, the next event read
3100 will set Vlast_event_frame again, so this is safe to do. */
3102 Lisp_Object focus;
3104 focus = FRAME_FOCUS_FRAME (XFRAME (event->frame_or_window));
3105 if (NILP (focus))
3106 focus = event->frame_or_window;
3107 internal_last_event_frame = focus;
3108 Vlast_event_frame = focus;
3111 last_event_timestamp = event->timestamp;
3112 interrupt_signal ();
3113 return;
3116 if (c && c == stop_character)
3118 sys_suspend ();
3119 return;
3122 /* Don't insert two buffer_switch_event's in a row.
3123 Just ignore the second one. */
3124 else if (event->kind == buffer_switch_event
3125 && kbd_fetch_ptr != kbd_store_ptr
3126 && kbd_store_ptr->kind == buffer_switch_event)
3127 return;
3129 if (kbd_store_ptr - kbd_buffer == KBD_BUFFER_SIZE)
3130 kbd_store_ptr = kbd_buffer;
3132 /* Don't let the very last slot in the buffer become full,
3133 since that would make the two pointers equal,
3134 and that is indistinguishable from an empty buffer.
3135 Discard the event if it would fill the last slot. */
3136 if (kbd_fetch_ptr - 1 != kbd_store_ptr)
3138 int idx;
3140 #if 0 /* The selection_request_event case looks bogus, and it's error
3141 prone to assign individual members for other events, in case
3142 the input_event structure is changed. --2000-07-13, gerd. */
3143 struct input_event *sp = kbd_store_ptr;
3144 sp->kind = event->kind;
3145 if (event->kind == selection_request_event)
3147 /* We must not use the ordinary copying code for this case,
3148 since `part' is an enum and copying it might not copy enough
3149 in this case. */
3150 bcopy (event, (char *) sp, sizeof (*event));
3152 else
3155 sp->code = event->code;
3156 sp->part = event->part;
3157 sp->frame_or_window = event->frame_or_window;
3158 sp->arg = event->arg;
3159 sp->modifiers = event->modifiers;
3160 sp->x = event->x;
3161 sp->y = event->y;
3162 sp->timestamp = event->timestamp;
3164 #else
3165 *kbd_store_ptr = *event;
3166 #endif
3168 idx = 2 * (kbd_store_ptr - kbd_buffer);
3169 ASET (kbd_buffer_gcpro, idx, event->frame_or_window);
3170 ASET (kbd_buffer_gcpro, idx + 1, event->arg);
3171 ++kbd_store_ptr;
3176 /* Generate HELP_EVENT input_events in BUFP.
3178 HELP is the help form.
3180 FRAME is the frame on which the help is generated. OBJECT is the
3181 Lisp object where the help was found (a buffer, a string, an
3182 overlay, or nil if neither from a string nor from a buffer. POS is
3183 the position within OBJECT where the help was found.
3185 Value is the number of input_events generated. */
3188 gen_help_event (bufp, help, frame, window, object, pos)
3189 struct input_event *bufp;
3190 Lisp_Object help, frame, object, window;
3191 int pos;
3193 bufp->kind = HELP_EVENT;
3194 bufp->frame_or_window = frame;
3195 bufp->arg = object;
3196 bufp->x = make_number (pos);
3197 bufp->code = 0;
3199 ++bufp;
3200 bufp->kind = HELP_EVENT;
3201 bufp->frame_or_window = WINDOWP (window) ? window : frame;
3202 bufp->arg = help;
3203 bufp->code = 1;
3205 return 2;
3209 /* Store HELP_EVENTs for HELP on FRAME in the input queue. */
3211 void
3212 kbd_buffer_store_help_event (frame, help)
3213 Lisp_Object frame, help;
3215 struct input_event event;
3217 event.kind = HELP_EVENT;
3218 event.frame_or_window = frame;
3219 event.arg = Qnil;
3220 event.x = make_number (0);
3221 event.code = 0;
3222 kbd_buffer_store_event (&event);
3224 event.kind = HELP_EVENT;
3225 event.frame_or_window = frame;
3226 event.arg = help;
3227 event.x = make_number (0);
3228 event.code = 1;
3229 kbd_buffer_store_event (&event);
3233 /* Discard any mouse events in the event buffer by setting them to
3234 no_event. */
3235 void
3236 discard_mouse_events ()
3238 struct input_event *sp;
3239 for (sp = kbd_fetch_ptr; sp != kbd_store_ptr; sp++)
3241 if (sp == kbd_buffer + KBD_BUFFER_SIZE)
3242 sp = kbd_buffer;
3244 if (sp->kind == mouse_click
3245 #ifdef WINDOWSNT
3246 || sp->kind == w32_scroll_bar_click
3247 #endif
3248 || sp->kind == scroll_bar_click)
3250 sp->kind = no_event;
3255 /* Return non-zero if there are any events waiting in the event buffer
3256 whose .kind is not no_event. If DISCARD is non-zero, discard all
3257 no_event placeholders up to the first real event. If there are no
3258 real events waiting and DISCARD is non-zero, this function makes
3259 the event buffer empty as side effect. */
3261 kbd_buffer_events_waiting (discard)
3262 int discard;
3264 struct input_event *sp;
3265 for (sp = kbd_fetch_ptr; sp != kbd_store_ptr; sp++)
3267 if (sp == kbd_buffer + KBD_BUFFER_SIZE)
3268 sp = kbd_buffer;
3270 if (sp->kind != no_event)
3271 return 1;
3272 if (discard)
3273 kbd_fetch_ptr = sp;
3275 if (discard)
3276 kbd_fetch_ptr = sp;
3277 return 0;
3280 /* Read one event from the event buffer, waiting if necessary.
3281 The value is a Lisp object representing the event.
3282 The value is nil for an event that should be ignored,
3283 or that was handled here.
3284 We always read and discard one event. */
3286 static Lisp_Object
3287 kbd_buffer_get_event (kbp, used_mouse_menu)
3288 KBOARD **kbp;
3289 int *used_mouse_menu;
3291 register int c;
3292 Lisp_Object obj;
3294 if (noninteractive)
3296 c = getchar ();
3297 XSETINT (obj, c);
3298 *kbp = current_kboard;
3299 return obj;
3302 /* Wait until there is input available. */
3303 for (;;)
3305 if (kbd_fetch_ptr != kbd_store_ptr)
3306 break;
3307 #ifdef HAVE_MOUSE
3308 if (!NILP (do_mouse_tracking) && some_mouse_moved ())
3309 break;
3310 #endif
3312 /* If the quit flag is set, then read_char will return
3313 quit_char, so that counts as "available input." */
3314 if (!NILP (Vquit_flag))
3315 quit_throw_to_read_char ();
3317 /* One way or another, wait until input is available; then, if
3318 interrupt handlers have not read it, read it now. */
3320 #ifdef OLDVMS
3321 wait_for_kbd_input ();
3322 #else
3323 /* Note SIGIO has been undef'd if FIONREAD is missing. */
3324 #ifdef SIGIO
3325 gobble_input (0);
3326 #endif /* SIGIO */
3327 if (kbd_fetch_ptr != kbd_store_ptr)
3328 break;
3329 #ifdef HAVE_MOUSE
3330 if (!NILP (do_mouse_tracking) && some_mouse_moved ())
3331 break;
3332 #endif
3334 Lisp_Object minus_one;
3336 XSETINT (minus_one, -1);
3337 wait_reading_process_input (0, 0, minus_one, 1);
3339 if (!interrupt_input && kbd_fetch_ptr == kbd_store_ptr)
3340 /* Pass 1 for EXPECT since we just waited to have input. */
3341 read_avail_input (1);
3343 #endif /* not VMS */
3346 if (CONSP (Vunread_command_events))
3348 Lisp_Object first;
3349 first = XCAR (Vunread_command_events);
3350 Vunread_command_events = XCDR (Vunread_command_events);
3351 *kbp = current_kboard;
3352 return first;
3355 /* At this point, we know that there is a readable event available
3356 somewhere. If the event queue is empty, then there must be a
3357 mouse movement enabled and available. */
3358 if (kbd_fetch_ptr != kbd_store_ptr)
3360 struct input_event *event;
3362 event = ((kbd_fetch_ptr < kbd_buffer + KBD_BUFFER_SIZE)
3363 ? kbd_fetch_ptr
3364 : kbd_buffer);
3366 last_event_timestamp = event->timestamp;
3368 #ifdef MULTI_KBOARD
3369 *kbp = event_to_kboard (event);
3370 if (*kbp == 0)
3371 *kbp = current_kboard; /* Better than returning null ptr? */
3372 #else
3373 *kbp = &the_only_kboard;
3374 #endif
3376 obj = Qnil;
3378 /* These two kinds of events get special handling
3379 and don't actually appear to the command loop.
3380 We return nil for them. */
3381 if (event->kind == selection_request_event)
3383 #ifdef HAVE_X11
3384 struct input_event copy;
3386 /* Remove it from the buffer before processing it,
3387 since otherwise swallow_events will see it
3388 and process it again. */
3389 copy = *event;
3390 kbd_fetch_ptr = event + 1;
3391 input_pending = readable_events (0);
3392 x_handle_selection_request (&copy);
3393 #else
3394 /* We're getting selection request events, but we don't have
3395 a window system. */
3396 abort ();
3397 #endif
3400 else if (event->kind == selection_clear_event)
3402 #ifdef HAVE_X11
3403 struct input_event copy;
3405 /* Remove it from the buffer before processing it. */
3406 copy = *event;
3407 kbd_fetch_ptr = event + 1;
3408 input_pending = readable_events (0);
3409 x_handle_selection_clear (&copy);
3410 #else
3411 /* We're getting selection request events, but we don't have
3412 a window system. */
3413 abort ();
3414 #endif
3416 #if defined (HAVE_X11) || defined (HAVE_NTGUI)
3417 else if (event->kind == delete_window_event)
3419 /* Make an event (delete-frame (FRAME)). */
3420 obj = Fcons (event->frame_or_window, Qnil);
3421 obj = Fcons (Qdelete_frame, Fcons (obj, Qnil));
3422 kbd_fetch_ptr = event + 1;
3424 else if (event->kind == iconify_event)
3426 /* Make an event (iconify-frame (FRAME)). */
3427 obj = Fcons (event->frame_or_window, Qnil);
3428 obj = Fcons (Qiconify_frame, Fcons (obj, Qnil));
3429 kbd_fetch_ptr = event + 1;
3431 else if (event->kind == deiconify_event)
3433 /* Make an event (make-frame-visible (FRAME)). */
3434 obj = Fcons (event->frame_or_window, Qnil);
3435 obj = Fcons (Qmake_frame_visible, Fcons (obj, Qnil));
3436 kbd_fetch_ptr = event + 1;
3438 #endif
3439 else if (event->kind == buffer_switch_event)
3441 /* The value doesn't matter here; only the type is tested. */
3442 XSETBUFFER (obj, current_buffer);
3443 kbd_fetch_ptr = event + 1;
3445 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
3446 else if (event->kind == menu_bar_activate_event)
3448 kbd_fetch_ptr = event + 1;
3449 input_pending = readable_events (0);
3450 if (FRAME_LIVE_P (XFRAME (event->frame_or_window)))
3451 x_activate_menubar (XFRAME (event->frame_or_window));
3453 #endif
3454 #ifdef WINDOWSNT
3455 else if (event->kind == language_change_event)
3457 /* Make an event (language-change (FRAME CHARSET LCID)). */
3458 obj = Fcons (event->modifiers, Qnil);
3459 obj = Fcons (event->code, Qnil);
3460 obj = Fcons (event->frame_or_window, obj);
3461 obj = Fcons (Qlanguage_change, Fcons (obj, Qnil));
3462 kbd_fetch_ptr = event + 1;
3464 #endif
3465 /* Just discard these, by returning nil.
3466 With MULTI_KBOARD, these events are used as placeholders
3467 when we need to randomly delete events from the queue.
3468 (They shouldn't otherwise be found in the buffer,
3469 but on some machines it appears they do show up
3470 even without MULTI_KBOARD.) */
3471 /* On Windows NT/9X, no_event is used to delete extraneous
3472 mouse events during a popup-menu call. */
3473 else if (event->kind == no_event)
3474 kbd_fetch_ptr = event + 1;
3475 else if (event->kind == HELP_EVENT)
3477 /* There are always two HELP_EVENTs in the input queue. */
3478 Lisp_Object object, position, help, frame, window;
3480 xassert (event->code == 0);
3481 frame = event->frame_or_window;
3482 object = event->arg;
3483 position = event->x;
3485 kbd_fetch_ptr = event + 1;
3486 event = ((kbd_fetch_ptr < kbd_buffer + KBD_BUFFER_SIZE)
3487 ? kbd_fetch_ptr
3488 : kbd_buffer);
3489 xassert (event->code == 1);
3490 help = event->arg;
3491 window = event->frame_or_window;
3492 if (!WINDOWP (window))
3493 window = Qnil;
3494 obj = Fcons (Qhelp_echo,
3495 list5 (frame, help, window, object, position));
3496 kbd_fetch_ptr = event + 1;
3498 else if (event->kind == FOCUS_IN_EVENT)
3500 /* Notification of a FocusIn event. The frame receiving the
3501 focus is in event->frame_or_window. Generate a
3502 switch-frame event if necessary. */
3503 Lisp_Object frame, focus;
3505 frame = event->frame_or_window;
3506 focus = FRAME_FOCUS_FRAME (XFRAME (frame));
3507 if (FRAMEP (focus))
3508 frame = focus;
3510 if (!EQ (frame, internal_last_event_frame)
3511 && !EQ (frame, selected_frame))
3512 obj = make_lispy_switch_frame (frame);
3513 internal_last_event_frame = frame;
3514 kbd_fetch_ptr = event + 1;
3516 else
3518 /* If this event is on a different frame, return a switch-frame this
3519 time, and leave the event in the queue for next time. */
3520 Lisp_Object frame;
3521 Lisp_Object focus;
3523 frame = event->frame_or_window;
3524 if (CONSP (frame))
3525 frame = XCAR (frame);
3526 else if (WINDOWP (frame))
3527 frame = WINDOW_FRAME (XWINDOW (frame));
3529 focus = FRAME_FOCUS_FRAME (XFRAME (frame));
3530 if (! NILP (focus))
3531 frame = focus;
3533 if (! EQ (frame, internal_last_event_frame)
3534 && !EQ (frame, selected_frame))
3535 obj = make_lispy_switch_frame (frame);
3536 internal_last_event_frame = frame;
3538 /* If we didn't decide to make a switch-frame event, go ahead
3539 and build a real event from the queue entry. */
3541 if (NILP (obj))
3543 int idx;
3545 obj = make_lispy_event (event);
3547 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
3548 /* If this was a menu selection, then set the flag to inhibit
3549 writing to last_nonmenu_event. Don't do this if the event
3550 we're returning is (menu-bar), though; that indicates the
3551 beginning of the menu sequence, and we might as well leave
3552 that as the `event with parameters' for this selection. */
3553 if (used_mouse_menu
3554 && !EQ (event->frame_or_window, event->arg)
3555 && (event->kind == MENU_BAR_EVENT
3556 || event->kind == TOOL_BAR_EVENT))
3557 *used_mouse_menu = 1;
3558 #endif
3560 /* Wipe out this event, to catch bugs. */
3561 event->kind = no_event;
3562 idx = 2 * (event - kbd_buffer);
3563 ASET (kbd_buffer_gcpro, idx, Qnil);
3564 ASET (kbd_buffer_gcpro, idx + 1, Qnil);
3566 kbd_fetch_ptr = event + 1;
3570 #ifdef HAVE_MOUSE
3571 /* Try generating a mouse motion event. */
3572 else if (!NILP (do_mouse_tracking) && some_mouse_moved ())
3574 FRAME_PTR f = some_mouse_moved ();
3575 Lisp_Object bar_window;
3576 enum scroll_bar_part part;
3577 Lisp_Object x, y;
3578 unsigned long time;
3580 *kbp = current_kboard;
3581 /* Note that this uses F to determine which display to look at.
3582 If there is no valid info, it does not store anything
3583 so x remains nil. */
3584 x = Qnil;
3585 (*mouse_position_hook) (&f, 0, &bar_window, &part, &x, &y, &time);
3587 obj = Qnil;
3589 /* Decide if we should generate a switch-frame event. Don't
3590 generate switch-frame events for motion outside of all Emacs
3591 frames. */
3592 if (!NILP (x) && f)
3594 Lisp_Object frame;
3596 frame = FRAME_FOCUS_FRAME (f);
3597 if (NILP (frame))
3598 XSETFRAME (frame, f);
3600 if (! EQ (frame, internal_last_event_frame)
3601 && !EQ (frame, selected_frame))
3602 obj = make_lispy_switch_frame (frame);
3603 internal_last_event_frame = frame;
3606 /* If we didn't decide to make a switch-frame event, go ahead and
3607 return a mouse-motion event. */
3608 if (!NILP (x) && NILP (obj))
3609 obj = make_lispy_movement (f, bar_window, part, x, y, time);
3611 #endif /* HAVE_MOUSE */
3612 else
3613 /* We were promised by the above while loop that there was
3614 something for us to read! */
3615 abort ();
3617 input_pending = readable_events (0);
3619 Vlast_event_frame = internal_last_event_frame;
3621 return (obj);
3624 /* Process any events that are not user-visible,
3625 then return, without reading any user-visible events. */
3627 void
3628 swallow_events (do_display)
3629 int do_display;
3631 int old_timers_run;
3633 while (kbd_fetch_ptr != kbd_store_ptr)
3635 struct input_event *event;
3637 event = ((kbd_fetch_ptr < kbd_buffer + KBD_BUFFER_SIZE)
3638 ? kbd_fetch_ptr
3639 : kbd_buffer);
3641 last_event_timestamp = event->timestamp;
3643 /* These two kinds of events get special handling
3644 and don't actually appear to the command loop. */
3645 if (event->kind == selection_request_event)
3647 #ifdef HAVE_X11
3648 struct input_event copy;
3650 /* Remove it from the buffer before processing it,
3651 since otherwise swallow_events called recursively could see it
3652 and process it again. */
3653 copy = *event;
3654 kbd_fetch_ptr = event + 1;
3655 input_pending = readable_events (0);
3656 x_handle_selection_request (&copy);
3657 #else
3658 /* We're getting selection request events, but we don't have
3659 a window system. */
3660 abort ();
3661 #endif
3664 else if (event->kind == selection_clear_event)
3666 #ifdef HAVE_X11
3667 struct input_event copy;
3669 /* Remove it from the buffer before processing it, */
3670 copy = *event;
3672 kbd_fetch_ptr = event + 1;
3673 input_pending = readable_events (0);
3674 x_handle_selection_clear (&copy);
3675 #else
3676 /* We're getting selection request events, but we don't have
3677 a window system. */
3678 abort ();
3679 #endif
3681 else
3682 break;
3685 old_timers_run = timers_run;
3686 get_input_pending (&input_pending, 1);
3688 if (timers_run != old_timers_run && do_display)
3689 redisplay_preserve_echo_area ();
3692 static EMACS_TIME timer_idleness_start_time;
3694 /* Record the start of when Emacs is idle,
3695 for the sake of running idle-time timers. */
3697 void
3698 timer_start_idle ()
3700 Lisp_Object timers;
3702 /* If we are already in the idle state, do nothing. */
3703 if (! EMACS_TIME_NEG_P (timer_idleness_start_time))
3704 return;
3706 EMACS_GET_TIME (timer_idleness_start_time);
3708 /* Mark all idle-time timers as once again candidates for running. */
3709 for (timers = Vtimer_idle_list; CONSP (timers); timers = XCDR (timers))
3711 Lisp_Object timer;
3713 timer = XCAR (timers);
3715 if (!VECTORP (timer) || XVECTOR (timer)->size != 8)
3716 continue;
3717 XVECTOR (timer)->contents[0] = Qnil;
3721 /* Record that Emacs is no longer idle, so stop running idle-time timers. */
3723 void
3724 timer_stop_idle ()
3726 EMACS_SET_SECS_USECS (timer_idleness_start_time, -1, -1);
3729 /* This is only for debugging. */
3730 struct input_event last_timer_event;
3732 /* Check whether a timer has fired. To prevent larger problems we simply
3733 disregard elements that are not proper timers. Do not make a circular
3734 timer list for the time being.
3736 Returns the number of seconds to wait until the next timer fires. If a
3737 timer is triggering now, return zero seconds.
3738 If no timer is active, return -1 seconds.
3740 If a timer is ripe, we run it, with quitting turned off.
3742 DO_IT_NOW is now ignored. It used to mean that we should
3743 run the timer directly instead of queueing a timer-event.
3744 Now we always run timers directly. */
3746 EMACS_TIME
3747 timer_check (do_it_now)
3748 int do_it_now;
3750 EMACS_TIME nexttime;
3751 EMACS_TIME now, idleness_now;
3752 Lisp_Object timers, idle_timers, chosen_timer;
3753 struct gcpro gcpro1, gcpro2, gcpro3;
3755 EMACS_SET_SECS (nexttime, -1);
3756 EMACS_SET_USECS (nexttime, -1);
3758 /* Always consider the ordinary timers. */
3759 timers = Vtimer_list;
3760 /* Consider the idle timers only if Emacs is idle. */
3761 if (! EMACS_TIME_NEG_P (timer_idleness_start_time))
3762 idle_timers = Vtimer_idle_list;
3763 else
3764 idle_timers = Qnil;
3765 chosen_timer = Qnil;
3766 GCPRO3 (timers, idle_timers, chosen_timer);
3768 if (CONSP (timers) || CONSP (idle_timers))
3770 EMACS_GET_TIME (now);
3771 if (! EMACS_TIME_NEG_P (timer_idleness_start_time))
3772 EMACS_SUB_TIME (idleness_now, now, timer_idleness_start_time);
3775 while (CONSP (timers) || CONSP (idle_timers))
3777 Lisp_Object *vector;
3778 Lisp_Object timer, idle_timer;
3779 EMACS_TIME timer_time, idle_timer_time;
3780 EMACS_TIME difference, timer_difference, idle_timer_difference;
3782 /* Skip past invalid timers and timers already handled. */
3783 if (!NILP (timers))
3785 timer = XCAR (timers);
3786 if (!VECTORP (timer) || XVECTOR (timer)->size != 8)
3788 timers = XCDR (timers);
3789 continue;
3791 vector = XVECTOR (timer)->contents;
3793 if (!INTEGERP (vector[1]) || !INTEGERP (vector[2])
3794 || !INTEGERP (vector[3])
3795 || ! NILP (vector[0]))
3797 timers = XCDR (timers);
3798 continue;
3801 if (!NILP (idle_timers))
3803 timer = XCAR (idle_timers);
3804 if (!VECTORP (timer) || XVECTOR (timer)->size != 8)
3806 idle_timers = XCDR (idle_timers);
3807 continue;
3809 vector = XVECTOR (timer)->contents;
3811 if (!INTEGERP (vector[1]) || !INTEGERP (vector[2])
3812 || !INTEGERP (vector[3])
3813 || ! NILP (vector[0]))
3815 idle_timers = XCDR (idle_timers);
3816 continue;
3820 /* Set TIMER, TIMER_TIME and TIMER_DIFFERENCE
3821 based on the next ordinary timer.
3822 TIMER_DIFFERENCE is the distance in time from NOW to when
3823 this timer becomes ripe (negative if it's already ripe). */
3824 if (!NILP (timers))
3826 timer = XCAR (timers);
3827 vector = XVECTOR (timer)->contents;
3828 EMACS_SET_SECS (timer_time,
3829 (XINT (vector[1]) << 16) | (XINT (vector[2])));
3830 EMACS_SET_USECS (timer_time, XINT (vector[3]));
3831 EMACS_SUB_TIME (timer_difference, timer_time, now);
3834 /* Set IDLE_TIMER, IDLE_TIMER_TIME and IDLE_TIMER_DIFFERENCE
3835 based on the next idle timer. */
3836 if (!NILP (idle_timers))
3838 idle_timer = XCAR (idle_timers);
3839 vector = XVECTOR (idle_timer)->contents;
3840 EMACS_SET_SECS (idle_timer_time,
3841 (XINT (vector[1]) << 16) | (XINT (vector[2])));
3842 EMACS_SET_USECS (idle_timer_time, XINT (vector[3]));
3843 EMACS_SUB_TIME (idle_timer_difference, idle_timer_time, idleness_now);
3846 /* Decide which timer is the next timer,
3847 and set CHOSEN_TIMER, VECTOR and DIFFERENCE accordingly.
3848 Also step down the list where we found that timer. */
3850 if (! NILP (timers) && ! NILP (idle_timers))
3852 EMACS_TIME temp;
3853 EMACS_SUB_TIME (temp, timer_difference, idle_timer_difference);
3854 if (EMACS_TIME_NEG_P (temp))
3856 chosen_timer = timer;
3857 timers = XCDR (timers);
3858 difference = timer_difference;
3860 else
3862 chosen_timer = idle_timer;
3863 idle_timers = XCDR (idle_timers);
3864 difference = idle_timer_difference;
3867 else if (! NILP (timers))
3869 chosen_timer = timer;
3870 timers = XCDR (timers);
3871 difference = timer_difference;
3873 else
3875 chosen_timer = idle_timer;
3876 idle_timers = XCDR (idle_timers);
3877 difference = idle_timer_difference;
3879 vector = XVECTOR (chosen_timer)->contents;
3881 /* If timer is ripe, run it if it hasn't been run. */
3882 if (EMACS_TIME_NEG_P (difference)
3883 || (EMACS_SECS (difference) == 0
3884 && EMACS_USECS (difference) == 0))
3886 if (NILP (vector[0]))
3888 int was_locked = single_kboard;
3889 int count = specpdl_ptr - specpdl;
3891 /* Mark the timer as triggered to prevent problems if the lisp
3892 code fails to reschedule it right. */
3893 vector[0] = Qt;
3895 specbind (Qinhibit_quit, Qt);
3897 call1 (Qtimer_event_handler, chosen_timer);
3898 timers_run++;
3900 unbind_to (count, Qnil);
3902 /* Resume allowing input from any kboard, if that was true before. */
3903 if (!was_locked)
3904 any_kboard_state ();
3906 /* Since we have handled the event,
3907 we don't need to tell the caller to wake up and do it. */
3910 else
3911 /* When we encounter a timer that is still waiting,
3912 return the amount of time to wait before it is ripe. */
3914 UNGCPRO;
3915 return difference;
3919 /* No timers are pending in the future. */
3920 /* Return 0 if we generated an event, and -1 if not. */
3921 UNGCPRO;
3922 return nexttime;
3925 /* Caches for modify_event_symbol. */
3926 static Lisp_Object accent_key_syms;
3927 static Lisp_Object func_key_syms;
3928 static Lisp_Object mouse_syms;
3929 #ifdef WINDOWSNT
3930 static Lisp_Object mouse_wheel_syms;
3931 #endif
3932 static Lisp_Object drag_n_drop_syms;
3934 /* This is a list of keysym codes for special "accent" characters.
3935 It parallels lispy_accent_keys. */
3937 static int lispy_accent_codes[] =
3939 #ifdef XK_dead_circumflex
3940 XK_dead_circumflex,
3941 #else
3943 #endif
3944 #ifdef XK_dead_grave
3945 XK_dead_grave,
3946 #else
3948 #endif
3949 #ifdef XK_dead_tilde
3950 XK_dead_tilde,
3951 #else
3953 #endif
3954 #ifdef XK_dead_diaeresis
3955 XK_dead_diaeresis,
3956 #else
3958 #endif
3959 #ifdef XK_dead_macron
3960 XK_dead_macron,
3961 #else
3963 #endif
3964 #ifdef XK_dead_degree
3965 XK_dead_degree,
3966 #else
3968 #endif
3969 #ifdef XK_dead_acute
3970 XK_dead_acute,
3971 #else
3973 #endif
3974 #ifdef XK_dead_cedilla
3975 XK_dead_cedilla,
3976 #else
3978 #endif
3979 #ifdef XK_dead_breve
3980 XK_dead_breve,
3981 #else
3983 #endif
3984 #ifdef XK_dead_ogonek
3985 XK_dead_ogonek,
3986 #else
3988 #endif
3989 #ifdef XK_dead_caron
3990 XK_dead_caron,
3991 #else
3993 #endif
3994 #ifdef XK_dead_doubleacute
3995 XK_dead_doubleacute,
3996 #else
3998 #endif
3999 #ifdef XK_dead_abovedot
4000 XK_dead_abovedot,
4001 #else
4003 #endif
4006 /* This is a list of Lisp names for special "accent" characters.
4007 It parallels lispy_accent_codes. */
4009 static char *lispy_accent_keys[] =
4011 "dead-circumflex",
4012 "dead-grave",
4013 "dead-tilde",
4014 "dead-diaeresis",
4015 "dead-macron",
4016 "dead-degree",
4017 "dead-acute",
4018 "dead-cedilla",
4019 "dead-breve",
4020 "dead-ogonek",
4021 "dead-caron",
4022 "dead-doubleacute",
4023 "dead-abovedot",
4026 #ifdef HAVE_NTGUI
4027 #define FUNCTION_KEY_OFFSET 0x0
4029 char *lispy_function_keys[] =
4031 0, /* 0 */
4033 0, /* VK_LBUTTON 0x01 */
4034 0, /* VK_RBUTTON 0x02 */
4035 "cancel", /* VK_CANCEL 0x03 */
4036 0, /* VK_MBUTTON 0x04 */
4038 0, 0, 0, /* 0x05 .. 0x07 */
4040 "backspace", /* VK_BACK 0x08 */
4041 "tab", /* VK_TAB 0x09 */
4043 0, 0, /* 0x0A .. 0x0B */
4045 "clear", /* VK_CLEAR 0x0C */
4046 "return", /* VK_RETURN 0x0D */
4048 0, 0, /* 0x0E .. 0x0F */
4050 0, /* VK_SHIFT 0x10 */
4051 0, /* VK_CONTROL 0x11 */
4052 0, /* VK_MENU 0x12 */
4053 "pause", /* VK_PAUSE 0x13 */
4054 "capslock", /* VK_CAPITAL 0x14 */
4056 0, 0, 0, 0, 0, 0, /* 0x15 .. 0x1A */
4058 "escape", /* VK_ESCAPE 0x1B */
4060 0, 0, 0, 0, /* 0x1C .. 0x1F */
4062 0, /* VK_SPACE 0x20 */
4063 "prior", /* VK_PRIOR 0x21 */
4064 "next", /* VK_NEXT 0x22 */
4065 "end", /* VK_END 0x23 */
4066 "home", /* VK_HOME 0x24 */
4067 "left", /* VK_LEFT 0x25 */
4068 "up", /* VK_UP 0x26 */
4069 "right", /* VK_RIGHT 0x27 */
4070 "down", /* VK_DOWN 0x28 */
4071 "select", /* VK_SELECT 0x29 */
4072 "print", /* VK_PRINT 0x2A */
4073 "execute", /* VK_EXECUTE 0x2B */
4074 "snapshot", /* VK_SNAPSHOT 0x2C */
4075 "insert", /* VK_INSERT 0x2D */
4076 "delete", /* VK_DELETE 0x2E */
4077 "help", /* VK_HELP 0x2F */
4079 /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
4081 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4083 0, 0, 0, 0, 0, 0, 0, /* 0x3A .. 0x40 */
4085 /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
4087 0, 0, 0, 0, 0, 0, 0, 0, 0,
4088 0, 0, 0, 0, 0, 0, 0, 0, 0,
4089 0, 0, 0, 0, 0, 0, 0, 0,
4091 "lwindow", /* VK_LWIN 0x5B */
4092 "rwindow", /* VK_RWIN 0x5C */
4093 "apps", /* VK_APPS 0x5D */
4095 0, 0, /* 0x5E .. 0x5F */
4097 "kp-0", /* VK_NUMPAD0 0x60 */
4098 "kp-1", /* VK_NUMPAD1 0x61 */
4099 "kp-2", /* VK_NUMPAD2 0x62 */
4100 "kp-3", /* VK_NUMPAD3 0x63 */
4101 "kp-4", /* VK_NUMPAD4 0x64 */
4102 "kp-5", /* VK_NUMPAD5 0x65 */
4103 "kp-6", /* VK_NUMPAD6 0x66 */
4104 "kp-7", /* VK_NUMPAD7 0x67 */
4105 "kp-8", /* VK_NUMPAD8 0x68 */
4106 "kp-9", /* VK_NUMPAD9 0x69 */
4107 "kp-multiply", /* VK_MULTIPLY 0x6A */
4108 "kp-add", /* VK_ADD 0x6B */
4109 "kp-separator", /* VK_SEPARATOR 0x6C */
4110 "kp-subtract", /* VK_SUBTRACT 0x6D */
4111 "kp-decimal", /* VK_DECIMAL 0x6E */
4112 "kp-divide", /* VK_DIVIDE 0x6F */
4113 "f1", /* VK_F1 0x70 */
4114 "f2", /* VK_F2 0x71 */
4115 "f3", /* VK_F3 0x72 */
4116 "f4", /* VK_F4 0x73 */
4117 "f5", /* VK_F5 0x74 */
4118 "f6", /* VK_F6 0x75 */
4119 "f7", /* VK_F7 0x76 */
4120 "f8", /* VK_F8 0x77 */
4121 "f9", /* VK_F9 0x78 */
4122 "f10", /* VK_F10 0x79 */
4123 "f11", /* VK_F11 0x7A */
4124 "f12", /* VK_F12 0x7B */
4125 "f13", /* VK_F13 0x7C */
4126 "f14", /* VK_F14 0x7D */
4127 "f15", /* VK_F15 0x7E */
4128 "f16", /* VK_F16 0x7F */
4129 "f17", /* VK_F17 0x80 */
4130 "f18", /* VK_F18 0x81 */
4131 "f19", /* VK_F19 0x82 */
4132 "f20", /* VK_F20 0x83 */
4133 "f21", /* VK_F21 0x84 */
4134 "f22", /* VK_F22 0x85 */
4135 "f23", /* VK_F23 0x86 */
4136 "f24", /* VK_F24 0x87 */
4138 0, 0, 0, 0, /* 0x88 .. 0x8B */
4139 0, 0, 0, 0, /* 0x8C .. 0x8F */
4141 "kp-numlock", /* VK_NUMLOCK 0x90 */
4142 "scroll", /* VK_SCROLL 0x91 */
4144 "kp-space", /* VK_NUMPAD_CLEAR 0x92 */
4145 "kp-enter", /* VK_NUMPAD_ENTER 0x93 */
4146 "kp-prior", /* VK_NUMPAD_PRIOR 0x94 */
4147 "kp-next", /* VK_NUMPAD_NEXT 0x95 */
4148 "kp-end", /* VK_NUMPAD_END 0x96 */
4149 "kp-home", /* VK_NUMPAD_HOME 0x97 */
4150 "kp-left", /* VK_NUMPAD_LEFT 0x98 */
4151 "kp-up", /* VK_NUMPAD_UP 0x99 */
4152 "kp-right", /* VK_NUMPAD_RIGHT 0x9A */
4153 "kp-down", /* VK_NUMPAD_DOWN 0x9B */
4154 "kp-insert", /* VK_NUMPAD_INSERT 0x9C */
4155 "kp-delete", /* VK_NUMPAD_DELETE 0x9D */
4157 0, 0, /* 0x9E .. 0x9F */
4160 * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
4161 * Used only as parameters to GetAsyncKeyState and GetKeyState.
4162 * No other API or message will distinguish left and right keys this way.
4164 /* 0xA0 .. 0xEF */
4166 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4167 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4168 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4169 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4170 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4172 /* 0xF0 .. 0xF5 */
4174 0, 0, 0, 0, 0, 0,
4176 "attn", /* VK_ATTN 0xF6 */
4177 "crsel", /* VK_CRSEL 0xF7 */
4178 "exsel", /* VK_EXSEL 0xF8 */
4179 "ereof", /* VK_EREOF 0xF9 */
4180 "play", /* VK_PLAY 0xFA */
4181 "zoom", /* VK_ZOOM 0xFB */
4182 "noname", /* VK_NONAME 0xFC */
4183 "pa1", /* VK_PA1 0xFD */
4184 "oem_clear", /* VK_OEM_CLEAR 0xFE */
4185 0 /* 0xFF */
4188 #else /* not HAVE_NTGUI */
4190 #ifdef XK_kana_A
4191 static char *lispy_kana_keys[] =
4193 /* X Keysym value */
4194 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x400 .. 0x40f */
4195 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x410 .. 0x41f */
4196 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x420 .. 0x42f */
4197 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x430 .. 0x43f */
4198 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x440 .. 0x44f */
4199 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x450 .. 0x45f */
4200 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x460 .. 0x46f */
4201 0,0,0,0,0,0,0,0,0,0,0,0,0,0,"overline",0,
4202 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x480 .. 0x48f */
4203 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x490 .. 0x49f */
4204 0, "kana-fullstop", "kana-openingbracket", "kana-closingbracket",
4205 "kana-comma", "kana-conjunctive", "kana-WO", "kana-a",
4206 "kana-i", "kana-u", "kana-e", "kana-o",
4207 "kana-ya", "kana-yu", "kana-yo", "kana-tsu",
4208 "prolongedsound", "kana-A", "kana-I", "kana-U",
4209 "kana-E", "kana-O", "kana-KA", "kana-KI",
4210 "kana-KU", "kana-KE", "kana-KO", "kana-SA",
4211 "kana-SHI", "kana-SU", "kana-SE", "kana-SO",
4212 "kana-TA", "kana-CHI", "kana-TSU", "kana-TE",
4213 "kana-TO", "kana-NA", "kana-NI", "kana-NU",
4214 "kana-NE", "kana-NO", "kana-HA", "kana-HI",
4215 "kana-FU", "kana-HE", "kana-HO", "kana-MA",
4216 "kana-MI", "kana-MU", "kana-ME", "kana-MO",
4217 "kana-YA", "kana-YU", "kana-YO", "kana-RA",
4218 "kana-RI", "kana-RU", "kana-RE", "kana-RO",
4219 "kana-WA", "kana-N", "voicedsound", "semivoicedsound",
4220 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4e0 .. 0x4ef */
4221 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4f0 .. 0x4ff */
4223 #endif /* XK_kana_A */
4225 #define FUNCTION_KEY_OFFSET 0xff00
4227 /* You'll notice that this table is arranged to be conveniently
4228 indexed by X Windows keysym values. */
4229 static char *lispy_function_keys[] =
4231 /* X Keysym value */
4233 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00...0f */
4234 "backspace", "tab", "linefeed", "clear",
4235 0, "return", 0, 0,
4236 0, 0, 0, "pause", /* 0xff10...1f */
4237 0, 0, 0, 0, 0, 0, 0, "escape",
4238 0, 0, 0, 0,
4239 0, "kanji", "muhenkan", "henkan", /* 0xff20...2f */
4240 "romaji", "hiragana", "katakana", "hiragana-katakana",
4241 "zenkaku", "hankaku", "zenkaku-hankaku", "touroku",
4242 "massyo", "kana-lock", "kana-shift", "eisu-shift",
4243 "eisu-toggle", /* 0xff30...3f */
4244 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4245 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
4247 "home", "left", "up", "right", /* 0xff50 */ /* IsCursorKey */
4248 "down", "prior", "next", "end",
4249 "begin", 0, 0, 0, 0, 0, 0, 0,
4250 "select", /* 0xff60 */ /* IsMiscFunctionKey */
4251 "print",
4252 "execute",
4253 "insert",
4254 0, /* 0xff64 */
4255 "undo",
4256 "redo",
4257 "menu",
4258 "find",
4259 "cancel",
4260 "help",
4261 "break", /* 0xff6b */
4263 0, 0, 0, 0,
4264 0, 0, 0, 0, "backtab", 0, 0, 0, /* 0xff70... */
4265 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff78... */
4266 "kp-space", /* 0xff80 */ /* IsKeypadKey */
4267 0, 0, 0, 0, 0, 0, 0, 0,
4268 "kp-tab", /* 0xff89 */
4269 0, 0, 0,
4270 "kp-enter", /* 0xff8d */
4271 0, 0, 0,
4272 "kp-f1", /* 0xff91 */
4273 "kp-f2",
4274 "kp-f3",
4275 "kp-f4",
4276 "kp-home", /* 0xff95 */
4277 "kp-left",
4278 "kp-up",
4279 "kp-right",
4280 "kp-down",
4281 "kp-prior", /* kp-page-up */
4282 "kp-next", /* kp-page-down */
4283 "kp-end",
4284 "kp-begin",
4285 "kp-insert",
4286 "kp-delete",
4287 0, /* 0xffa0 */
4288 0, 0, 0, 0, 0, 0, 0, 0, 0,
4289 "kp-multiply", /* 0xffaa */
4290 "kp-add",
4291 "kp-separator",
4292 "kp-subtract",
4293 "kp-decimal",
4294 "kp-divide", /* 0xffaf */
4295 "kp-0", /* 0xffb0 */
4296 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
4297 0, /* 0xffba */
4298 0, 0,
4299 "kp-equal", /* 0xffbd */
4300 "f1", /* 0xffbe */ /* IsFunctionKey */
4301 "f2",
4302 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
4303 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
4304 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
4305 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
4306 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
4307 0, 0, 0, 0, 0, 0, 0, 0,
4308 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
4309 0, 0, 0, 0, 0, 0, 0, "delete"
4312 /* ISO 9995 Function and Modifier Keys; the first byte is 0xFE. */
4313 #define ISO_FUNCTION_KEY_OFFSET 0xfe00
4315 static char *iso_lispy_function_keys[] =
4317 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe00 */
4318 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe08 */
4319 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe10 */
4320 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe18 */
4321 "iso-lefttab", /* 0xfe20 */
4322 "iso-move-line-up", "iso-move-line-down",
4323 "iso-partial-line-up", "iso-partial-line-down",
4324 "iso-partial-space-left", "iso-partial-space-right",
4325 "iso-set-margin-left", "iso-set-margin-right", /* 0xffe27, 28 */
4326 "iso-release-margin-left", "iso-release-margin-right",
4327 "iso-release-both-margins",
4328 "iso-fast-cursor-left", "iso-fast-cursor-right",
4329 "iso-fast-cursor-up", "iso-fast-cursor-down",
4330 "iso-continuous-underline", "iso-discontinuous-underline", /* 0xfe30, 31 */
4331 "iso-emphasize", "iso-center-object", "iso-enter", /* ... 0xfe34 */
4334 #endif /* not HAVE_NTGUI */
4336 Lisp_Object Vlispy_mouse_stem;
4338 #ifdef WINDOWSNT
4339 /* mouse-wheel events are generated by the wheel on devices such as
4340 the MS Intellimouse. The wheel sits in between the left and right
4341 mouse buttons, and is typically used to scroll or zoom the window
4342 underneath the pointer. mouse-wheel events specify the object on
4343 which they operate, and a delta corresponding to the amount and
4344 direction that the wheel is rotated. Clicking the mouse-wheel
4345 generates a mouse-2 event. */
4346 static char *lispy_mouse_wheel_names[] =
4348 "mouse-wheel"
4351 #endif /* WINDOWSNT */
4353 /* drag-n-drop events are generated when a set of selected files are
4354 dragged from another application and dropped onto an Emacs window. */
4355 static char *lispy_drag_n_drop_names[] =
4357 "drag-n-drop"
4360 /* Scroll bar parts. */
4361 Lisp_Object Qabove_handle, Qhandle, Qbelow_handle;
4362 Lisp_Object Qup, Qdown, Qbottom, Qend_scroll;
4363 Lisp_Object Qtop, Qratio;
4365 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
4366 Lisp_Object *scroll_bar_parts[] = {
4367 &Qabove_handle, &Qhandle, &Qbelow_handle,
4368 &Qup, &Qdown, &Qtop, &Qbottom, &Qend_scroll, &Qratio
4371 /* User signal events. */
4372 Lisp_Object Qusr1_signal, Qusr2_signal;
4374 Lisp_Object *lispy_user_signals[] =
4376 &Qusr1_signal, &Qusr2_signal
4380 /* A vector, indexed by button number, giving the down-going location
4381 of currently depressed buttons, both scroll bar and non-scroll bar.
4383 The elements have the form
4384 (BUTTON-NUMBER MODIFIER-MASK . REST)
4385 where REST is the cdr of a position as it would be reported in the event.
4387 The make_lispy_event function stores positions here to tell the
4388 difference between click and drag events, and to store the starting
4389 location to be included in drag events. */
4391 static Lisp_Object button_down_location;
4393 /* Information about the most recent up-going button event: Which
4394 button, what location, and what time. */
4396 static int last_mouse_button;
4397 static int last_mouse_x;
4398 static int last_mouse_y;
4399 static unsigned long button_down_time;
4401 /* The maximum time between clicks to make a double-click,
4402 or Qnil to disable double-click detection,
4403 or Qt for no time limit. */
4404 Lisp_Object Vdouble_click_time;
4406 /* The number of clicks in this multiple-click. */
4408 int double_click_count;
4410 /* Given a struct input_event, build the lisp event which represents
4411 it. If EVENT is 0, build a mouse movement event from the mouse
4412 movement buffer, which should have a movement event in it.
4414 Note that events must be passed to this function in the order they
4415 are received; this function stores the location of button presses
4416 in order to build drag events when the button is released. */
4418 static Lisp_Object
4419 make_lispy_event (event)
4420 struct input_event *event;
4422 int i;
4424 switch (SWITCH_ENUM_CAST (event->kind))
4426 /* A simple keystroke. */
4427 case ascii_keystroke:
4429 Lisp_Object lispy_c;
4430 int c = event->code & 0377;
4431 /* Turn ASCII characters into control characters
4432 when proper. */
4433 if (event->modifiers & ctrl_modifier)
4434 c = make_ctrl_char (c);
4436 /* Add in the other modifier bits. We took care of ctrl_modifier
4437 just above, and the shift key was taken care of by the X code,
4438 and applied to control characters by make_ctrl_char. */
4439 c |= (event->modifiers
4440 & (meta_modifier | alt_modifier
4441 | hyper_modifier | super_modifier));
4442 /* Distinguish Shift-SPC from SPC. */
4443 if ((event->code & 0377) == 040
4444 && event->modifiers & shift_modifier)
4445 c |= shift_modifier;
4446 button_down_time = 0;
4447 XSETFASTINT (lispy_c, c);
4448 return lispy_c;
4451 case multibyte_char_keystroke:
4453 Lisp_Object lispy_c;
4455 XSETFASTINT (lispy_c, event->code);
4456 return lispy_c;
4459 /* A function key. The symbol may need to have modifier prefixes
4460 tacked onto it. */
4461 case non_ascii_keystroke:
4462 button_down_time = 0;
4464 for (i = 0; i < sizeof (lispy_accent_codes) / sizeof (int); i++)
4465 if (event->code == lispy_accent_codes[i])
4466 return modify_event_symbol (i,
4467 event->modifiers,
4468 Qfunction_key, Qnil,
4469 lispy_accent_keys, &accent_key_syms,
4470 (sizeof (lispy_accent_keys)
4471 / sizeof (lispy_accent_keys[0])));
4473 /* Handle system-specific keysyms. */
4474 if (event->code & (1 << 28))
4476 /* We need to use an alist rather than a vector as the cache
4477 since we can't make a vector long enuf. */
4478 if (NILP (current_kboard->system_key_syms))
4479 current_kboard->system_key_syms = Fcons (Qnil, Qnil);
4480 return modify_event_symbol (event->code,
4481 event->modifiers,
4482 Qfunction_key,
4483 current_kboard->Vsystem_key_alist,
4484 0, &current_kboard->system_key_syms,
4485 (unsigned)-1);
4488 #ifdef XK_kana_A
4489 if (event->code >= 0x400 && event->code < 0x500)
4490 return modify_event_symbol (event->code - 0x400,
4491 event->modifiers & ~shift_modifier,
4492 Qfunction_key, Qnil,
4493 lispy_kana_keys, &func_key_syms,
4494 (sizeof (lispy_kana_keys)
4495 / sizeof (lispy_kana_keys[0])));
4496 #endif /* XK_kana_A */
4498 #ifdef ISO_FUNCTION_KEY_OFFSET
4499 if (event->code < FUNCTION_KEY_OFFSET
4500 && event->code >= ISO_FUNCTION_KEY_OFFSET)
4501 return modify_event_symbol (event->code - ISO_FUNCTION_KEY_OFFSET,
4502 event->modifiers,
4503 Qfunction_key, Qnil,
4504 iso_lispy_function_keys, &func_key_syms,
4505 (sizeof (iso_lispy_function_keys)
4506 / sizeof (iso_lispy_function_keys[0])));
4507 else
4508 #endif
4509 return modify_event_symbol (event->code - FUNCTION_KEY_OFFSET,
4510 event->modifiers,
4511 Qfunction_key, Qnil,
4512 lispy_function_keys, &func_key_syms,
4513 (sizeof (lispy_function_keys)
4514 / sizeof (lispy_function_keys[0])));
4516 #ifdef HAVE_MOUSE
4517 /* A mouse click. Figure out where it is, decide whether it's
4518 a press, click or drag, and build the appropriate structure. */
4519 case mouse_click:
4520 #ifndef USE_TOOLKIT_SCROLL_BARS
4521 case scroll_bar_click:
4522 #endif
4524 int button = event->code;
4525 int is_double;
4526 Lisp_Object position;
4527 Lisp_Object *start_pos_ptr;
4528 Lisp_Object start_pos;
4530 /* Build the position as appropriate for this mouse click. */
4531 if (event->kind == mouse_click)
4533 int part;
4534 FRAME_PTR f = XFRAME (event->frame_or_window);
4535 Lisp_Object window;
4536 Lisp_Object posn;
4537 Lisp_Object string_info = Qnil;
4538 int row, column;
4540 /* Ignore mouse events that were made on frame that
4541 have been deleted. */
4542 if (! FRAME_LIVE_P (f))
4543 return Qnil;
4545 /* EVENT->x and EVENT->y are frame-relative pixel
4546 coordinates at this place. Under old redisplay, COLUMN
4547 and ROW are set to frame relative glyph coordinates
4548 which are then used to determine whether this click is
4549 in a menu (non-toolkit version). */
4550 pixel_to_glyph_coords (f, XINT (event->x), XINT (event->y),
4551 &column, &row, NULL, 1);
4553 #ifndef USE_X_TOOLKIT
4554 /* In the non-toolkit version, clicks on the menu bar
4555 are ordinary button events in the event buffer.
4556 Distinguish them, and invoke the menu.
4558 (In the toolkit version, the toolkit handles the menu bar
4559 and Emacs doesn't know about it until after the user
4560 makes a selection.) */
4561 if (row >= 0 && row < FRAME_MENU_BAR_LINES (f)
4562 && (event->modifiers & down_modifier))
4564 Lisp_Object items, item;
4565 int hpos;
4566 int i;
4568 #if 0
4569 /* Activate the menu bar on the down event. If the
4570 up event comes in before the menu code can deal with it,
4571 just ignore it. */
4572 if (! (event->modifiers & down_modifier))
4573 return Qnil;
4574 #endif
4576 /* Find the menu bar item under `column'. */
4577 item = Qnil;
4578 items = FRAME_MENU_BAR_ITEMS (f);
4579 for (i = 0; i < XVECTOR (items)->size; i += 4)
4581 Lisp_Object pos, string;
4582 string = XVECTOR (items)->contents[i + 1];
4583 pos = XVECTOR (items)->contents[i + 3];
4584 if (NILP (string))
4585 break;
4586 if (column >= XINT (pos)
4587 && column < XINT (pos) + XSTRING (string)->size)
4589 item = XVECTOR (items)->contents[i];
4590 break;
4594 /* ELisp manual 2.4b says (x y) are window relative but
4595 code says they are frame-relative. */
4596 position
4597 = Fcons (event->frame_or_window,
4598 Fcons (Qmenu_bar,
4599 Fcons (Fcons (event->x, event->y),
4600 Fcons (make_number (event->timestamp),
4601 Qnil))));
4603 return Fcons (item, Fcons (position, Qnil));
4605 #endif /* not USE_X_TOOLKIT */
4607 /* Set `window' to the window under frame pixel coordinates
4608 event->x/event->y. */
4609 window = window_from_coordinates (f, XINT (event->x),
4610 XINT (event->y), &part, 0);
4612 if (!WINDOWP (window))
4614 window = event->frame_or_window;
4615 posn = Qnil;
4617 else
4619 /* It's a click in window window at frame coordinates
4620 event->x/ event->y. */
4621 struct window *w = XWINDOW (window);
4623 /* Get window relative coordinates. Original code
4624 `rounded' this to glyph boundaries. */
4625 int wx = FRAME_TO_WINDOW_PIXEL_X (w, XINT (event->x));
4626 int wy = FRAME_TO_WINDOW_PIXEL_Y (w, XINT (event->y));
4628 /* Set event coordinates to window-relative coordinates
4629 for constructing the Lisp event below. */
4630 XSETINT (event->x, wx);
4631 XSETINT (event->y, wy);
4633 if (part == 1 || part == 3)
4635 /* Mode line or top line. Look for a string under
4636 the mouse that may have a `local-map' property. */
4637 Lisp_Object string;
4638 int charpos;
4640 posn = part == 1 ? Qmode_line : Qheader_line;
4641 string = mode_line_string (w, wx, wy, part == 1, &charpos);
4642 if (STRINGP (string))
4643 string_info = Fcons (string, make_number (charpos));
4645 else if (part == 2)
4646 posn = Qvertical_line;
4647 else
4648 XSETINT (posn, buffer_posn_from_coords (w, &wx, &wy));
4651 position
4652 = Fcons (window,
4653 Fcons (posn,
4654 Fcons (Fcons (event->x, event->y),
4655 Fcons (make_number (event->timestamp),
4656 (NILP (string_info)
4657 ? Qnil
4658 : Fcons (string_info, Qnil))))));
4660 #ifndef USE_TOOLKIT_SCROLL_BARS
4661 else
4663 /* It's a scrollbar click. */
4664 Lisp_Object window;
4665 Lisp_Object portion_whole;
4666 Lisp_Object part;
4668 window = event->frame_or_window;
4669 portion_whole = Fcons (event->x, event->y);
4670 part = *scroll_bar_parts[(int) event->part];
4672 position
4673 = Fcons (window,
4674 Fcons (Qvertical_scroll_bar,
4675 Fcons (portion_whole,
4676 Fcons (make_number (event->timestamp),
4677 Fcons (part, Qnil)))));
4679 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4681 if (button >= XVECTOR (button_down_location)->size)
4683 button_down_location = larger_vector (button_down_location,
4684 button + 1, Qnil);
4685 mouse_syms = larger_vector (mouse_syms, button + 1, Qnil);
4688 start_pos_ptr = &XVECTOR (button_down_location)->contents[button];
4690 start_pos = *start_pos_ptr;
4691 *start_pos_ptr = Qnil;
4693 is_double = (button == last_mouse_button
4694 && XINT (event->x) == last_mouse_x
4695 && XINT (event->y) == last_mouse_y
4696 && button_down_time != 0
4697 && (EQ (Vdouble_click_time, Qt)
4698 || (INTEGERP (Vdouble_click_time)
4699 && ((int)(event->timestamp - button_down_time)
4700 < XINT (Vdouble_click_time)))));
4701 last_mouse_button = button;
4702 last_mouse_x = XINT (event->x);
4703 last_mouse_y = XINT (event->y);
4705 /* If this is a button press, squirrel away the location, so
4706 we can decide later whether it was a click or a drag. */
4707 if (event->modifiers & down_modifier)
4709 if (is_double)
4711 double_click_count++;
4712 event->modifiers |= ((double_click_count > 2)
4713 ? triple_modifier
4714 : double_modifier);
4716 else
4717 double_click_count = 1;
4718 button_down_time = event->timestamp;
4719 *start_pos_ptr = Fcopy_alist (position);
4722 /* Now we're releasing a button - check the co-ordinates to
4723 see if this was a click or a drag. */
4724 else if (event->modifiers & up_modifier)
4726 /* If we did not see a down before this up,
4727 ignore the up. Probably this happened because
4728 the down event chose a menu item.
4729 It would be an annoyance to treat the release
4730 of the button that chose the menu item
4731 as a separate event. */
4733 if (!CONSP (start_pos))
4734 return Qnil;
4736 event->modifiers &= ~up_modifier;
4737 #if 0 /* Formerly we treated an up with no down as a click event. */
4738 if (!CONSP (start_pos))
4739 event->modifiers |= click_modifier;
4740 else
4741 #endif
4743 /* The third element of every position should be the (x,y)
4744 pair. */
4745 Lisp_Object down;
4747 down = Fnth (make_number (2), start_pos);
4748 if (EQ (event->x, XCAR (down))
4749 && EQ (event->y, XCDR (down)))
4751 event->modifiers |= click_modifier;
4753 else
4755 button_down_time = 0;
4756 event->modifiers |= drag_modifier;
4758 /* Don't check is_double; treat this as multiple
4759 if the down-event was multiple. */
4760 if (double_click_count > 1)
4761 event->modifiers |= ((double_click_count > 2)
4762 ? triple_modifier
4763 : double_modifier);
4766 else
4767 /* Every mouse event should either have the down_modifier or
4768 the up_modifier set. */
4769 abort ();
4772 /* Get the symbol we should use for the mouse click. */
4773 Lisp_Object head;
4775 head = modify_event_symbol (button,
4776 event->modifiers,
4777 Qmouse_click, Vlispy_mouse_stem,
4778 NULL,
4779 &mouse_syms,
4780 XVECTOR (mouse_syms)->size);
4781 if (event->modifiers & drag_modifier)
4782 return Fcons (head,
4783 Fcons (start_pos,
4784 Fcons (position,
4785 Qnil)));
4786 else if (event->modifiers & (double_modifier | triple_modifier))
4787 return Fcons (head,
4788 Fcons (position,
4789 Fcons (make_number (double_click_count),
4790 Qnil)));
4791 else
4792 return Fcons (head,
4793 Fcons (position,
4794 Qnil));
4798 #if USE_TOOLKIT_SCROLL_BARS
4800 /* We don't have down and up events if using toolkit scroll bars,
4801 so make this always a click event. Store in the `part' of
4802 the Lisp event a symbol which maps to the following actions:
4804 `above_handle' page up
4805 `below_handle' page down
4806 `up' line up
4807 `down' line down
4808 `top' top of buffer
4809 `bottom' bottom of buffer
4810 `handle' thumb has been dragged.
4811 `end-scroll' end of interaction with scroll bar
4813 The incoming input_event contains in its `part' member an
4814 index of type `enum scroll_bar_part' which we can use as an
4815 index in scroll_bar_parts to get the appropriate symbol. */
4817 case scroll_bar_click:
4819 Lisp_Object position, head, window, portion_whole, part;
4821 window = event->frame_or_window;
4822 portion_whole = Fcons (event->x, event->y);
4823 part = *scroll_bar_parts[(int) event->part];
4825 position
4826 = Fcons (window,
4827 Fcons (Qvertical_scroll_bar,
4828 Fcons (portion_whole,
4829 Fcons (make_number (event->timestamp),
4830 Fcons (part, Qnil)))));
4832 /* Always treat scroll bar events as clicks. */
4833 event->modifiers |= click_modifier;
4835 /* Get the symbol we should use for the mouse click. */
4836 head = modify_event_symbol (event->code,
4837 event->modifiers,
4838 Qmouse_click,
4839 Vlispy_mouse_stem,
4840 NULL, &mouse_syms,
4841 XVECTOR (mouse_syms)->size);
4842 return Fcons (head, Fcons (position, Qnil));
4845 #endif /* USE_TOOLKIT_SCROLL_BARS */
4847 #ifdef WINDOWSNT
4848 case w32_scroll_bar_click:
4850 int button = event->code;
4851 int is_double;
4852 Lisp_Object position;
4853 Lisp_Object *start_pos_ptr;
4854 Lisp_Object start_pos;
4857 Lisp_Object window;
4858 Lisp_Object portion_whole;
4859 Lisp_Object part;
4861 window = event->frame_or_window;
4862 portion_whole = Fcons (event->x, event->y);
4863 part = *scroll_bar_parts[(int) event->part];
4865 position
4866 = Fcons (window,
4867 Fcons (Qvertical_scroll_bar,
4868 Fcons (portion_whole,
4869 Fcons (make_number (event->timestamp),
4870 Fcons (part, Qnil)))));
4873 /* Always treat W32 scroll bar events as clicks. */
4874 event->modifiers |= click_modifier;
4877 /* Get the symbol we should use for the mouse click. */
4878 Lisp_Object head;
4880 head = modify_event_symbol (button,
4881 event->modifiers,
4882 Qmouse_click,
4883 Vlispy_mouse_stem,
4884 NULL, &mouse_syms,
4885 XVECTOR (mouse_syms)->size);
4886 return Fcons (head,
4887 Fcons (position,
4888 Qnil));
4891 case mouse_wheel:
4893 int part;
4894 FRAME_PTR f = XFRAME (event->frame_or_window);
4895 Lisp_Object window;
4896 Lisp_Object posn;
4897 Lisp_Object head, position;
4898 int row, column;
4900 /* Ignore mouse events that were made on frame that
4901 have been deleted. */
4902 if (! FRAME_LIVE_P (f))
4903 return Qnil;
4904 pixel_to_glyph_coords (f, XINT (event->x), XINT (event->y),
4905 &column, &row, NULL, 1);
4906 window = window_from_coordinates (f, column, row, &part, 0);
4908 if (!WINDOWP (window))
4910 window = event->frame_or_window;
4911 posn = Qnil;
4913 else
4915 int pixcolumn, pixrow;
4916 column -= XINT (XWINDOW (window)->left);
4917 row -= XINT (XWINDOW (window)->top);
4918 glyph_to_pixel_coords (XWINDOW(window), column, row,
4919 &pixcolumn, &pixrow);
4920 XSETINT (event->x, pixcolumn);
4921 XSETINT (event->y, pixrow);
4923 if (part == 1)
4924 posn = Qmode_line;
4925 else if (part == 2)
4926 posn = Qvertical_line;
4927 else if (part == 3)
4928 posn = Qheader_line;
4929 else
4930 XSETINT (posn,
4931 buffer_posn_from_coords (XWINDOW (window),
4932 &column, &row));
4936 Lisp_Object head, position;
4938 position
4939 = Fcons (window,
4940 Fcons (posn,
4941 Fcons (Fcons (event->x, event->y),
4942 Fcons (make_number (event->timestamp),
4943 Qnil))));
4945 head = modify_event_symbol (0, event->modifiers,
4946 Qmouse_wheel, Qnil,
4947 lispy_mouse_wheel_names,
4948 &mouse_wheel_syms, 1);
4949 return Fcons (head,
4950 Fcons (position,
4951 Fcons (make_number (event->code),
4952 Qnil)));
4955 #endif /* WINDOWSNT */
4957 case drag_n_drop:
4959 int part;
4960 FRAME_PTR f;
4961 Lisp_Object window;
4962 Lisp_Object posn;
4963 Lisp_Object files;
4964 int row, column;
4966 /* The frame_or_window field should be a cons of the frame in
4967 which the event occurred and a list of the filenames
4968 dropped. */
4969 if (! CONSP (event->frame_or_window))
4970 abort ();
4972 f = XFRAME (XCAR (event->frame_or_window));
4973 files = XCDR (event->frame_or_window);
4975 /* Ignore mouse events that were made on frames that
4976 have been deleted. */
4977 if (! FRAME_LIVE_P (f))
4978 return Qnil;
4979 pixel_to_glyph_coords (f, XINT (event->x), XINT (event->y),
4980 &column, &row, NULL, 1);
4981 window = window_from_coordinates (f, column, row, &part, 0);
4983 if (!WINDOWP (window))
4985 window = XCAR (event->frame_or_window);
4986 posn = Qnil;
4988 else
4990 /* It's an event in window `window' at frame coordinates
4991 event->x/ event->y. */
4992 struct window *w = XWINDOW (window);
4994 /* Get window relative coordinates. */
4995 int wx = FRAME_TO_WINDOW_PIXEL_X (w, XINT (event->x));
4996 int wy = FRAME_TO_WINDOW_PIXEL_Y (w, XINT (event->y));
4998 /* Set event coordinates to window-relative coordinates
4999 for constructing the Lisp event below. */
5000 XSETINT (event->x, wx);
5001 XSETINT (event->y, wy);
5003 if (part == 1)
5004 posn = Qmode_line;
5005 else if (part == 2)
5006 posn = Qvertical_line;
5007 else if (part == 3)
5008 posn = Qheader_line;
5009 else
5010 XSETINT (posn, buffer_posn_from_coords (w, &wx, &wy));
5014 Lisp_Object head, position;
5016 position
5017 = Fcons (window,
5018 Fcons (posn,
5019 Fcons (Fcons (event->x, event->y),
5020 Fcons (make_number (event->timestamp),
5021 Qnil))));
5023 head = modify_event_symbol (0, event->modifiers,
5024 Qdrag_n_drop, Qnil,
5025 lispy_drag_n_drop_names,
5026 &drag_n_drop_syms, 1);
5027 return Fcons (head,
5028 Fcons (position,
5029 Fcons (files,
5030 Qnil)));
5033 #endif /* HAVE_MOUSE */
5035 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
5036 case MENU_BAR_EVENT:
5037 if (EQ (event->arg, event->frame_or_window))
5038 /* This is the prefix key. We translate this to
5039 `(menu_bar)' because the code in keyboard.c for menu
5040 events, which we use, relies on this. */
5041 return Fcons (Qmenu_bar, Qnil);
5042 return event->arg;
5043 #endif
5045 case TOOL_BAR_EVENT:
5046 if (EQ (event->arg, event->frame_or_window))
5047 /* This is the prefix key. We translate this to
5048 `(tool_bar)' because the code in keyboard.c for menu
5049 events, which we use, relies on this. */
5050 return Fcons (Qtool_bar, Qnil);
5051 else if (SYMBOLP (event->arg))
5052 return apply_modifiers (event->modifiers, event->arg);
5053 return event->arg;
5055 case USER_SIGNAL_EVENT:
5056 /* A user signal. */
5057 return *lispy_user_signals[event->code];
5059 /* The 'kind' field of the event is something we don't recognize. */
5060 default:
5061 abort ();
5065 #ifdef HAVE_MOUSE
5067 static Lisp_Object
5068 make_lispy_movement (frame, bar_window, part, x, y, time)
5069 FRAME_PTR frame;
5070 Lisp_Object bar_window;
5071 enum scroll_bar_part part;
5072 Lisp_Object x, y;
5073 unsigned long time;
5075 /* Is it a scroll bar movement? */
5076 if (frame && ! NILP (bar_window))
5078 Lisp_Object part_sym;
5080 part_sym = *scroll_bar_parts[(int) part];
5081 return Fcons (Qscroll_bar_movement,
5082 (Fcons (Fcons (bar_window,
5083 Fcons (Qvertical_scroll_bar,
5084 Fcons (Fcons (x, y),
5085 Fcons (make_number (time),
5086 Fcons (part_sym,
5087 Qnil))))),
5088 Qnil)));
5091 /* Or is it an ordinary mouse movement? */
5092 else
5094 int area;
5095 Lisp_Object window;
5096 Lisp_Object posn;
5098 if (frame)
5099 /* It's in a frame; which window on that frame? */
5100 window = window_from_coordinates (frame, XINT (x), XINT (y), &area, 0);
5101 else
5102 window = Qnil;
5104 if (WINDOWP (window))
5106 struct window *w = XWINDOW (window);
5107 int wx, wy;
5109 /* Get window relative coordinates. */
5110 wx = FRAME_TO_WINDOW_PIXEL_X (w, XINT (x));
5111 wy = FRAME_TO_WINDOW_PIXEL_Y (w, XINT (y));
5112 XSETINT (x, wx);
5113 XSETINT (y, wy);
5115 if (area == 1)
5116 posn = Qmode_line;
5117 else if (area == 2)
5118 posn = Qvertical_line;
5119 else if (area == 3)
5120 posn = Qheader_line;
5121 else
5122 XSETINT (posn, buffer_posn_from_coords (w, &wx, &wy));
5124 else if (frame != 0)
5126 XSETFRAME (window, frame);
5127 posn = Qnil;
5129 else
5131 window = Qnil;
5132 posn = Qnil;
5133 XSETFASTINT (x, 0);
5134 XSETFASTINT (y, 0);
5137 return Fcons (Qmouse_movement,
5138 Fcons (Fcons (window,
5139 Fcons (posn,
5140 Fcons (Fcons (x, y),
5141 Fcons (make_number (time),
5142 Qnil)))),
5143 Qnil));
5147 #endif /* HAVE_MOUSE */
5149 /* Construct a switch frame event. */
5150 static Lisp_Object
5151 make_lispy_switch_frame (frame)
5152 Lisp_Object frame;
5154 return Fcons (Qswitch_frame, Fcons (frame, Qnil));
5157 /* Manipulating modifiers. */
5159 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
5161 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
5162 SYMBOL's name of the end of the modifiers; the string from this
5163 position is the unmodified symbol name.
5165 This doesn't use any caches. */
5167 static int
5168 parse_modifiers_uncached (symbol, modifier_end)
5169 Lisp_Object symbol;
5170 int *modifier_end;
5172 struct Lisp_String *name;
5173 int i;
5174 int modifiers;
5176 CHECK_SYMBOL (symbol, 1);
5178 modifiers = 0;
5179 name = XSYMBOL (symbol)->name;
5181 for (i = 0; i+2 <= STRING_BYTES (name); )
5183 int this_mod_end = 0;
5184 int this_mod = 0;
5186 /* See if the name continues with a modifier word.
5187 Check that the word appears, but don't check what follows it.
5188 Set this_mod and this_mod_end to record what we find. */
5190 switch (name->data[i])
5192 #define SINGLE_LETTER_MOD(BIT) \
5193 (this_mod_end = i + 1, this_mod = BIT)
5195 case 'A':
5196 SINGLE_LETTER_MOD (alt_modifier);
5197 break;
5199 case 'C':
5200 SINGLE_LETTER_MOD (ctrl_modifier);
5201 break;
5203 case 'H':
5204 SINGLE_LETTER_MOD (hyper_modifier);
5205 break;
5207 case 'M':
5208 SINGLE_LETTER_MOD (meta_modifier);
5209 break;
5211 case 'S':
5212 SINGLE_LETTER_MOD (shift_modifier);
5213 break;
5215 case 's':
5216 SINGLE_LETTER_MOD (super_modifier);
5217 break;
5219 #undef SINGLE_LETTER_MOD
5222 /* If we found no modifier, stop looking for them. */
5223 if (this_mod_end == 0)
5224 break;
5226 /* Check there is a dash after the modifier, so that it
5227 really is a modifier. */
5228 if (this_mod_end >= STRING_BYTES (name)
5229 || name->data[this_mod_end] != '-')
5230 break;
5232 /* This modifier is real; look for another. */
5233 modifiers |= this_mod;
5234 i = this_mod_end + 1;
5237 /* Should we include the `click' modifier? */
5238 if (! (modifiers & (down_modifier | drag_modifier
5239 | double_modifier | triple_modifier))
5240 && i + 7 == STRING_BYTES (name)
5241 && strncmp (name->data + i, "mouse-", 6) == 0
5242 && ('0' <= name->data[i + 6] && name->data[i + 6] <= '9'))
5243 modifiers |= click_modifier;
5245 if (modifier_end)
5246 *modifier_end = i;
5248 return modifiers;
5251 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
5252 prepended to the string BASE[0..BASE_LEN-1].
5253 This doesn't use any caches. */
5254 static Lisp_Object
5255 apply_modifiers_uncached (modifiers, base, base_len, base_len_byte)
5256 int modifiers;
5257 char *base;
5258 int base_len, base_len_byte;
5260 /* Since BASE could contain nulls, we can't use intern here; we have
5261 to use Fintern, which expects a genuine Lisp_String, and keeps a
5262 reference to it. */
5263 char *new_mods
5264 = (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
5265 int mod_len;
5268 char *p = new_mods;
5270 /* Only the event queue may use the `up' modifier; it should always
5271 be turned into a click or drag event before presented to lisp code. */
5272 if (modifiers & up_modifier)
5273 abort ();
5275 if (modifiers & alt_modifier) { *p++ = 'A'; *p++ = '-'; }
5276 if (modifiers & ctrl_modifier) { *p++ = 'C'; *p++ = '-'; }
5277 if (modifiers & hyper_modifier) { *p++ = 'H'; *p++ = '-'; }
5278 if (modifiers & meta_modifier) { *p++ = 'M'; *p++ = '-'; }
5279 if (modifiers & shift_modifier) { *p++ = 'S'; *p++ = '-'; }
5280 if (modifiers & super_modifier) { *p++ = 's'; *p++ = '-'; }
5281 if (modifiers & double_modifier) { strcpy (p, "double-"); p += 7; }
5282 if (modifiers & triple_modifier) { strcpy (p, "triple-"); p += 7; }
5283 if (modifiers & down_modifier) { strcpy (p, "down-"); p += 5; }
5284 if (modifiers & drag_modifier) { strcpy (p, "drag-"); p += 5; }
5285 /* The click modifier is denoted by the absence of other modifiers. */
5287 *p = '\0';
5289 mod_len = p - new_mods;
5293 Lisp_Object new_name;
5295 new_name = make_uninit_multibyte_string (mod_len + base_len,
5296 mod_len + base_len_byte);
5297 bcopy (new_mods, XSTRING (new_name)->data, mod_len);
5298 bcopy (base, XSTRING (new_name)->data + mod_len, base_len_byte);
5300 return Fintern (new_name, Qnil);
5305 static char *modifier_names[] =
5307 "up", "down", "drag", "click", "double", "triple", 0, 0,
5308 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5309 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
5311 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
5313 static Lisp_Object modifier_symbols;
5315 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
5316 static Lisp_Object
5317 lispy_modifier_list (modifiers)
5318 int modifiers;
5320 Lisp_Object modifier_list;
5321 int i;
5323 modifier_list = Qnil;
5324 for (i = 0; (1<<i) <= modifiers && i < NUM_MOD_NAMES; i++)
5325 if (modifiers & (1<<i))
5326 modifier_list = Fcons (XVECTOR (modifier_symbols)->contents[i],
5327 modifier_list);
5329 return modifier_list;
5333 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
5334 where UNMODIFIED is the unmodified form of SYMBOL,
5335 MASK is the set of modifiers present in SYMBOL's name.
5336 This is similar to parse_modifiers_uncached, but uses the cache in
5337 SYMBOL's Qevent_symbol_element_mask property, and maintains the
5338 Qevent_symbol_elements property. */
5340 Lisp_Object
5341 parse_modifiers (symbol)
5342 Lisp_Object symbol;
5344 Lisp_Object elements;
5346 elements = Fget (symbol, Qevent_symbol_element_mask);
5347 if (CONSP (elements))
5348 return elements;
5349 else
5351 int end;
5352 int modifiers = parse_modifiers_uncached (symbol, &end);
5353 Lisp_Object unmodified;
5354 Lisp_Object mask;
5356 unmodified = Fintern (make_string (XSYMBOL (symbol)->name->data + end,
5357 STRING_BYTES (XSYMBOL (symbol)->name) - end),
5358 Qnil);
5360 if (modifiers & ~(((EMACS_INT)1 << VALBITS) - 1))
5361 abort ();
5362 XSETFASTINT (mask, modifiers);
5363 elements = Fcons (unmodified, Fcons (mask, Qnil));
5365 /* Cache the parsing results on SYMBOL. */
5366 Fput (symbol, Qevent_symbol_element_mask,
5367 elements);
5368 Fput (symbol, Qevent_symbol_elements,
5369 Fcons (unmodified, lispy_modifier_list (modifiers)));
5371 /* Since we know that SYMBOL is modifiers applied to unmodified,
5372 it would be nice to put that in unmodified's cache.
5373 But we can't, since we're not sure that parse_modifiers is
5374 canonical. */
5376 return elements;
5380 /* Apply the modifiers MODIFIERS to the symbol BASE.
5381 BASE must be unmodified.
5383 This is like apply_modifiers_uncached, but uses BASE's
5384 Qmodifier_cache property, if present. It also builds
5385 Qevent_symbol_elements properties, since it has that info anyway.
5387 apply_modifiers copies the value of BASE's Qevent_kind property to
5388 the modified symbol. */
5389 static Lisp_Object
5390 apply_modifiers (modifiers, base)
5391 int modifiers;
5392 Lisp_Object base;
5394 Lisp_Object cache, index, entry, new_symbol;
5396 /* Mask out upper bits. We don't know where this value's been. */
5397 modifiers &= ((EMACS_INT)1 << VALBITS) - 1;
5399 /* The click modifier never figures into cache indices. */
5400 cache = Fget (base, Qmodifier_cache);
5401 XSETFASTINT (index, (modifiers & ~click_modifier));
5402 entry = assq_no_quit (index, cache);
5404 if (CONSP (entry))
5405 new_symbol = XCDR (entry);
5406 else
5408 /* We have to create the symbol ourselves. */
5409 new_symbol = apply_modifiers_uncached (modifiers,
5410 XSYMBOL (base)->name->data,
5411 XSYMBOL (base)->name->size,
5412 STRING_BYTES (XSYMBOL (base)->name));
5414 /* Add the new symbol to the base's cache. */
5415 entry = Fcons (index, new_symbol);
5416 Fput (base, Qmodifier_cache, Fcons (entry, cache));
5418 /* We have the parsing info now for free, so add it to the caches. */
5419 XSETFASTINT (index, modifiers);
5420 Fput (new_symbol, Qevent_symbol_element_mask,
5421 Fcons (base, Fcons (index, Qnil)));
5422 Fput (new_symbol, Qevent_symbol_elements,
5423 Fcons (base, lispy_modifier_list (modifiers)));
5426 /* Make sure this symbol is of the same kind as BASE.
5428 You'd think we could just set this once and for all when we
5429 intern the symbol above, but reorder_modifiers may call us when
5430 BASE's property isn't set right; we can't assume that just
5431 because it has a Qmodifier_cache property it must have its
5432 Qevent_kind set right as well. */
5433 if (NILP (Fget (new_symbol, Qevent_kind)))
5435 Lisp_Object kind;
5437 kind = Fget (base, Qevent_kind);
5438 if (! NILP (kind))
5439 Fput (new_symbol, Qevent_kind, kind);
5442 return new_symbol;
5446 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
5447 return a symbol with the modifiers placed in the canonical order.
5448 Canonical order is alphabetical, except for down and drag, which
5449 always come last. The 'click' modifier is never written out.
5451 Fdefine_key calls this to make sure that (for example) C-M-foo
5452 and M-C-foo end up being equivalent in the keymap. */
5454 Lisp_Object
5455 reorder_modifiers (symbol)
5456 Lisp_Object symbol;
5458 /* It's hopefully okay to write the code this way, since everything
5459 will soon be in caches, and no consing will be done at all. */
5460 Lisp_Object parsed;
5462 parsed = parse_modifiers (symbol);
5463 return apply_modifiers ((int) XINT (XCAR (XCDR (parsed))),
5464 XCAR (parsed));
5468 /* For handling events, we often want to produce a symbol whose name
5469 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
5470 to some base, like the name of a function key or mouse button.
5471 modify_event_symbol produces symbols of this sort.
5473 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
5474 is the name of the i'th symbol. TABLE_SIZE is the number of elements
5475 in the table.
5477 Alternatively, NAME_ALIST_OR_STEM is either an alist mapping codes
5478 into symbol names, or a string specifying a name stem used to
5479 construct a symbol name or the form `STEM-N', where N is the decimal
5480 representation of SYMBOL_NUM. NAME_ALIST_OR_STEM is used if it is
5481 non-nil; otherwise NAME_TABLE is used.
5483 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
5484 persist between calls to modify_event_symbol that it can use to
5485 store a cache of the symbols it's generated for this NAME_TABLE
5486 before. The object stored there may be a vector or an alist.
5488 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
5490 MODIFIERS is a set of modifier bits (as given in struct input_events)
5491 whose prefixes should be applied to the symbol name.
5493 SYMBOL_KIND is the value to be placed in the event_kind property of
5494 the returned symbol.
5496 The symbols we create are supposed to have an
5497 `event-symbol-elements' property, which lists the modifiers present
5498 in the symbol's name. */
5500 static Lisp_Object
5501 modify_event_symbol (symbol_num, modifiers, symbol_kind, name_alist_or_stem,
5502 name_table, symbol_table, table_size)
5503 int symbol_num;
5504 unsigned modifiers;
5505 Lisp_Object symbol_kind;
5506 Lisp_Object name_alist_or_stem;
5507 char **name_table;
5508 Lisp_Object *symbol_table;
5509 unsigned int table_size;
5511 Lisp_Object value;
5512 Lisp_Object symbol_int;
5514 /* Get rid of the "vendor-specific" bit here. */
5515 XSETINT (symbol_int, symbol_num & 0xffffff);
5517 /* Is this a request for a valid symbol? */
5518 if (symbol_num < 0 || symbol_num >= table_size)
5519 return Qnil;
5521 if (CONSP (*symbol_table))
5522 value = Fcdr (assq_no_quit (symbol_int, *symbol_table));
5524 /* If *symbol_table doesn't seem to be initialized properly, fix that.
5525 *symbol_table should be a lisp vector TABLE_SIZE elements long,
5526 where the Nth element is the symbol for NAME_TABLE[N], or nil if
5527 we've never used that symbol before. */
5528 else
5530 if (! VECTORP (*symbol_table)
5531 || XVECTOR (*symbol_table)->size != table_size)
5533 Lisp_Object size;
5535 XSETFASTINT (size, table_size);
5536 *symbol_table = Fmake_vector (size, Qnil);
5539 value = XVECTOR (*symbol_table)->contents[symbol_num];
5542 /* Have we already used this symbol before? */
5543 if (NILP (value))
5545 /* No; let's create it. */
5546 if (CONSP (name_alist_or_stem))
5547 value = Fcdr_safe (Fassq (symbol_int, name_alist_or_stem));
5548 else if (STRINGP (name_alist_or_stem))
5550 int len = STRING_BYTES (XSTRING (name_alist_or_stem));
5551 char *buf = (char *) alloca (len + 50);
5552 sprintf (buf, "%s-%d", XSTRING (name_alist_or_stem)->data,
5553 XINT (symbol_int) + 1);
5554 value = intern (buf);
5556 else if (name_table != 0 && name_table[symbol_num])
5557 value = intern (name_table[symbol_num]);
5559 #ifdef HAVE_WINDOW_SYSTEM
5560 if (NILP (value))
5562 char *name = x_get_keysym_name (symbol_num);
5563 if (name)
5564 value = intern (name);
5566 #endif
5568 if (NILP (value))
5570 char buf[20];
5571 sprintf (buf, "key-%d", symbol_num);
5572 value = intern (buf);
5575 if (CONSP (*symbol_table))
5576 *symbol_table = Fcons (Fcons (symbol_int, value), *symbol_table);
5577 else
5578 XVECTOR (*symbol_table)->contents[symbol_num] = value;
5580 /* Fill in the cache entries for this symbol; this also
5581 builds the Qevent_symbol_elements property, which the user
5582 cares about. */
5583 apply_modifiers (modifiers & click_modifier, value);
5584 Fput (value, Qevent_kind, symbol_kind);
5587 /* Apply modifiers to that symbol. */
5588 return apply_modifiers (modifiers, value);
5591 /* Convert a list that represents an event type,
5592 such as (ctrl meta backspace), into the usual representation of that
5593 event type as a number or a symbol. */
5595 DEFUN ("event-convert-list", Fevent_convert_list, Sevent_convert_list, 1, 1, 0,
5596 "Convert the event description list EVENT-DESC to an event type.\n\
5597 EVENT-DESC should contain one base event type (a character or symbol)\n\
5598 and zero or more modifier names (control, meta, hyper, super, shift, alt,\n\
5599 drag, down, double or triple). The base must be last.\n\
5600 The return value is an event type (a character or symbol) which\n\
5601 has the same base event type and all the specified modifiers.")
5602 (event_desc)
5603 Lisp_Object event_desc;
5605 Lisp_Object base;
5606 int modifiers = 0;
5607 Lisp_Object rest;
5609 base = Qnil;
5610 rest = event_desc;
5611 while (CONSP (rest))
5613 Lisp_Object elt;
5614 int this = 0;
5616 elt = XCAR (rest);
5617 rest = XCDR (rest);
5619 /* Given a symbol, see if it is a modifier name. */
5620 if (SYMBOLP (elt) && CONSP (rest))
5621 this = parse_solitary_modifier (elt);
5623 if (this != 0)
5624 modifiers |= this;
5625 else if (!NILP (base))
5626 error ("Two bases given in one event");
5627 else
5628 base = elt;
5632 /* Let the symbol A refer to the character A. */
5633 if (SYMBOLP (base) && XSYMBOL (base)->name->size == 1)
5634 XSETINT (base, XSYMBOL (base)->name->data[0]);
5636 if (INTEGERP (base))
5638 /* Turn (shift a) into A. */
5639 if ((modifiers & shift_modifier) != 0
5640 && (XINT (base) >= 'a' && XINT (base) <= 'z'))
5642 XSETINT (base, XINT (base) - ('a' - 'A'));
5643 modifiers &= ~shift_modifier;
5646 /* Turn (control a) into C-a. */
5647 if (modifiers & ctrl_modifier)
5648 return make_number ((modifiers & ~ctrl_modifier)
5649 | make_ctrl_char (XINT (base)));
5650 else
5651 return make_number (modifiers | XINT (base));
5653 else if (SYMBOLP (base))
5654 return apply_modifiers (modifiers, base);
5655 else
5656 error ("Invalid base event");
5659 /* Try to recognize SYMBOL as a modifier name.
5660 Return the modifier flag bit, or 0 if not recognized. */
5662 static int
5663 parse_solitary_modifier (symbol)
5664 Lisp_Object symbol;
5666 struct Lisp_String *name = XSYMBOL (symbol)->name;
5668 switch (name->data[0])
5670 #define SINGLE_LETTER_MOD(BIT) \
5671 if (STRING_BYTES (name) == 1) \
5672 return BIT;
5674 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
5675 if (LEN == STRING_BYTES (name) \
5676 && ! strncmp (name->data, NAME, LEN)) \
5677 return BIT;
5679 case 'A':
5680 SINGLE_LETTER_MOD (alt_modifier);
5681 break;
5683 case 'a':
5684 MULTI_LETTER_MOD (alt_modifier, "alt", 3);
5685 break;
5687 case 'C':
5688 SINGLE_LETTER_MOD (ctrl_modifier);
5689 break;
5691 case 'c':
5692 MULTI_LETTER_MOD (ctrl_modifier, "ctrl", 4);
5693 MULTI_LETTER_MOD (ctrl_modifier, "control", 7);
5694 break;
5696 case 'H':
5697 SINGLE_LETTER_MOD (hyper_modifier);
5698 break;
5700 case 'h':
5701 MULTI_LETTER_MOD (hyper_modifier, "hyper", 5);
5702 break;
5704 case 'M':
5705 SINGLE_LETTER_MOD (meta_modifier);
5706 break;
5708 case 'm':
5709 MULTI_LETTER_MOD (meta_modifier, "meta", 4);
5710 break;
5712 case 'S':
5713 SINGLE_LETTER_MOD (shift_modifier);
5714 break;
5716 case 's':
5717 MULTI_LETTER_MOD (shift_modifier, "shift", 5);
5718 MULTI_LETTER_MOD (super_modifier, "super", 5);
5719 SINGLE_LETTER_MOD (super_modifier);
5720 break;
5722 case 'd':
5723 MULTI_LETTER_MOD (drag_modifier, "drag", 4);
5724 MULTI_LETTER_MOD (down_modifier, "down", 4);
5725 MULTI_LETTER_MOD (double_modifier, "double", 6);
5726 break;
5728 case 't':
5729 MULTI_LETTER_MOD (triple_modifier, "triple", 6);
5730 break;
5732 #undef SINGLE_LETTER_MOD
5733 #undef MULTI_LETTER_MOD
5736 return 0;
5739 /* Return 1 if EVENT is a list whose elements are all integers or symbols.
5740 Such a list is not valid as an event,
5741 but it can be a Lucid-style event type list. */
5744 lucid_event_type_list_p (object)
5745 Lisp_Object object;
5747 Lisp_Object tail;
5749 if (! CONSP (object))
5750 return 0;
5752 for (tail = object; CONSP (tail); tail = XCDR (tail))
5754 Lisp_Object elt;
5755 elt = XCAR (tail);
5756 if (! (INTEGERP (elt) || SYMBOLP (elt)))
5757 return 0;
5760 return NILP (tail);
5763 /* Store into *addr a value nonzero if terminal input chars are available.
5764 Serves the purpose of ioctl (0, FIONREAD, addr)
5765 but works even if FIONREAD does not exist.
5766 (In fact, this may actually read some input.)
5768 If DO_TIMERS_NOW is nonzero, actually run timer events that are ripe. */
5770 static void
5771 get_input_pending (addr, do_timers_now)
5772 int *addr;
5773 int do_timers_now;
5775 /* First of all, have we already counted some input? */
5776 *addr = !NILP (Vquit_flag) || readable_events (do_timers_now);
5778 /* If input is being read as it arrives, and we have none, there is none. */
5779 if (*addr > 0 || (interrupt_input && ! interrupts_deferred))
5780 return;
5782 /* Try to read some input and see how much we get. */
5783 gobble_input (0);
5784 *addr = !NILP (Vquit_flag) || readable_events (do_timers_now);
5787 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
5789 void
5790 gobble_input (expected)
5791 int expected;
5793 #ifndef VMS
5794 #ifdef SIGIO
5795 if (interrupt_input)
5797 SIGMASKTYPE mask;
5798 mask = sigblock (sigmask (SIGIO));
5799 read_avail_input (expected);
5800 sigsetmask (mask);
5802 else
5803 #ifdef POLL_FOR_INPUT
5804 if (read_socket_hook && !interrupt_input && poll_suppress_count == 0)
5806 SIGMASKTYPE mask;
5807 mask = sigblock (sigmask (SIGALRM));
5808 read_avail_input (expected);
5809 sigsetmask (mask);
5811 else
5812 #endif
5813 #endif
5814 read_avail_input (expected);
5815 #endif
5818 /* Put a buffer_switch_event in the buffer
5819 so that read_key_sequence will notice the new current buffer. */
5821 void
5822 record_asynch_buffer_change ()
5824 struct input_event event;
5825 Lisp_Object tem;
5827 event.kind = buffer_switch_event;
5828 event.frame_or_window = Qnil;
5829 event.arg = Qnil;
5831 #ifdef subprocesses
5832 /* We don't need a buffer-switch event unless Emacs is waiting for input.
5833 The purpose of the event is to make read_key_sequence look up the
5834 keymaps again. If we aren't in read_key_sequence, we don't need one,
5835 and the event could cause trouble by messing up (input-pending-p). */
5836 tem = Fwaiting_for_user_input_p ();
5837 if (NILP (tem))
5838 return;
5839 #else
5840 /* We never need these events if we have no asynchronous subprocesses. */
5841 return;
5842 #endif
5844 /* Make sure no interrupt happens while storing the event. */
5845 #ifdef SIGIO
5846 if (interrupt_input)
5848 SIGMASKTYPE mask;
5849 mask = sigblock (sigmask (SIGIO));
5850 kbd_buffer_store_event (&event);
5851 sigsetmask (mask);
5853 else
5854 #endif
5856 stop_polling ();
5857 kbd_buffer_store_event (&event);
5858 start_polling ();
5862 #ifndef VMS
5864 /* Read any terminal input already buffered up by the system
5865 into the kbd_buffer, but do not wait.
5867 EXPECTED should be nonzero if the caller knows there is some input.
5869 Except on VMS, all input is read by this function.
5870 If interrupt_input is nonzero, this function MUST be called
5871 only when SIGIO is blocked.
5873 Returns the number of keyboard chars read, or -1 meaning
5874 this is a bad time to try to read input. */
5876 static int
5877 read_avail_input (expected)
5878 int expected;
5880 struct input_event buf[KBD_BUFFER_SIZE];
5881 register int i;
5882 int nread;
5884 if (read_socket_hook)
5885 /* No need for FIONREAD or fcntl; just say don't wait. */
5886 nread = (*read_socket_hook) (input_fd, buf, KBD_BUFFER_SIZE, expected);
5887 else
5889 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
5890 the kbd_buffer can really hold. That may prevent loss
5891 of characters on some systems when input is stuffed at us. */
5892 unsigned char cbuf[KBD_BUFFER_SIZE - 1];
5893 int n_to_read;
5895 /* Determine how many characters we should *try* to read. */
5896 #ifdef WINDOWSNT
5897 return 0;
5898 #else /* not WINDOWSNT */
5899 #ifdef MSDOS
5900 n_to_read = dos_keysns ();
5901 if (n_to_read == 0)
5902 return 0;
5903 #else /* not MSDOS */
5904 #ifdef FIONREAD
5905 /* Find out how much input is available. */
5906 if (ioctl (input_fd, FIONREAD, &n_to_read) < 0)
5907 /* Formerly simply reported no input, but that sometimes led to
5908 a failure of Emacs to terminate.
5909 SIGHUP seems appropriate if we can't reach the terminal. */
5910 /* ??? Is it really right to send the signal just to this process
5911 rather than to the whole process group?
5912 Perhaps on systems with FIONREAD Emacs is alone in its group. */
5913 kill (getpid (), SIGHUP);
5914 if (n_to_read == 0)
5915 return 0;
5916 if (n_to_read > sizeof cbuf)
5917 n_to_read = sizeof cbuf;
5918 #else /* no FIONREAD */
5919 #if defined (USG) || defined (DGUX)
5920 /* Read some input if available, but don't wait. */
5921 n_to_read = sizeof cbuf;
5922 fcntl (input_fd, F_SETFL, O_NDELAY);
5923 #else
5924 you lose;
5925 #endif
5926 #endif
5927 #endif /* not MSDOS */
5928 #endif /* not WINDOWSNT */
5930 /* Now read; for one reason or another, this will not block.
5931 NREAD is set to the number of chars read. */
5934 #ifdef MSDOS
5935 cbuf[0] = dos_keyread ();
5936 nread = 1;
5937 #else
5938 nread = emacs_read (input_fd, cbuf, n_to_read);
5939 #endif
5940 /* POSIX infers that processes which are not in the session leader's
5941 process group won't get SIGHUP's at logout time. BSDI adheres to
5942 this part standard and returns -1 from read (0) with errno==EIO
5943 when the control tty is taken away.
5944 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
5945 if (nread == -1 && errno == EIO)
5946 kill (0, SIGHUP);
5947 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
5948 /* The kernel sometimes fails to deliver SIGHUP for ptys.
5949 This looks incorrect, but it isn't, because _BSD causes
5950 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
5951 and that causes a value other than 0 when there is no input. */
5952 if (nread == 0)
5953 kill (0, SIGHUP);
5954 #endif
5956 while (
5957 /* We used to retry the read if it was interrupted.
5958 But this does the wrong thing when O_NDELAY causes
5959 an EAGAIN error. Does anybody know of a situation
5960 where a retry is actually needed? */
5961 #if 0
5962 nread < 0 && (errno == EAGAIN
5963 #ifdef EFAULT
5964 || errno == EFAULT
5965 #endif
5966 #ifdef EBADSLT
5967 || errno == EBADSLT
5968 #endif
5970 #else
5972 #endif
5975 #ifndef FIONREAD
5976 #if defined (USG) || defined (DGUX)
5977 fcntl (input_fd, F_SETFL, 0);
5978 #endif /* USG or DGUX */
5979 #endif /* no FIONREAD */
5980 for (i = 0; i < nread; i++)
5982 buf[i].kind = ascii_keystroke;
5983 buf[i].modifiers = 0;
5984 if (meta_key == 1 && (cbuf[i] & 0x80))
5985 buf[i].modifiers = meta_modifier;
5986 if (meta_key != 2)
5987 cbuf[i] &= ~0x80;
5989 buf[i].code = cbuf[i];
5990 buf[i].frame_or_window = selected_frame;
5991 buf[i].arg = Qnil;
5995 /* Scan the chars for C-g and store them in kbd_buffer. */
5996 for (i = 0; i < nread; i++)
5998 kbd_buffer_store_event (&buf[i]);
5999 /* Don't look at input that follows a C-g too closely.
6000 This reduces lossage due to autorepeat on C-g. */
6001 if (buf[i].kind == ascii_keystroke
6002 && buf[i].code == quit_char)
6003 break;
6006 return nread;
6008 #endif /* not VMS */
6010 #ifdef SIGIO /* for entire page */
6011 /* Note SIGIO has been undef'd if FIONREAD is missing. */
6013 SIGTYPE
6014 input_available_signal (signo)
6015 int signo;
6017 /* Must preserve main program's value of errno. */
6018 int old_errno = errno;
6019 #ifdef BSD4_1
6020 extern int select_alarmed;
6021 #endif
6023 #if defined (USG) && !defined (POSIX_SIGNALS)
6024 /* USG systems forget handlers when they are used;
6025 must reestablish each time */
6026 signal (signo, input_available_signal);
6027 #endif /* USG */
6029 #ifdef BSD4_1
6030 sigisheld (SIGIO);
6031 #endif
6033 if (input_available_clear_time)
6034 EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0);
6036 while (1)
6038 int nread;
6039 nread = read_avail_input (1);
6040 /* -1 means it's not ok to read the input now.
6041 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
6042 0 means there was no keyboard input available. */
6043 if (nread <= 0)
6044 break;
6046 #ifdef BSD4_1
6047 select_alarmed = 1; /* Force the select emulator back to life */
6048 #endif
6051 #ifdef BSD4_1
6052 sigfree ();
6053 #endif
6054 errno = old_errno;
6056 #endif /* SIGIO */
6058 /* Send ourselves a SIGIO.
6060 This function exists so that the UNBLOCK_INPUT macro in
6061 blockinput.h can have some way to take care of input we put off
6062 dealing with, without assuming that every file which uses
6063 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
6064 void
6065 reinvoke_input_signal ()
6067 #ifdef SIGIO
6068 kill (getpid (), SIGIO);
6069 #endif
6074 /* Return the prompt-string of a sparse keymap.
6075 This is the first element which is a string.
6076 Return nil if there is none. */
6078 Lisp_Object
6079 map_prompt (map)
6080 Lisp_Object map;
6082 while (CONSP (map))
6084 register Lisp_Object tem;
6085 tem = Fcar (map);
6086 if (STRINGP (tem))
6087 return tem;
6088 map = Fcdr (map);
6090 return Qnil;
6093 static void menu_bar_item ();
6094 static void menu_bar_one_keymap ();
6096 /* These variables hold the vector under construction within
6097 menu_bar_items and its subroutines, and the current index
6098 for storing into that vector. */
6099 static Lisp_Object menu_bar_items_vector;
6100 static int menu_bar_items_index;
6102 /* Return a vector of menu items for a menu bar, appropriate
6103 to the current buffer. Each item has three elements in the vector:
6104 KEY STRING MAPLIST.
6106 OLD is an old vector we can optionally reuse, or nil. */
6108 Lisp_Object
6109 menu_bar_items (old)
6110 Lisp_Object old;
6112 /* The number of keymaps we're scanning right now, and the number of
6113 keymaps we have allocated space for. */
6114 int nmaps;
6116 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
6117 in the current keymaps, or nil where it is not a prefix. */
6118 Lisp_Object *maps;
6120 Lisp_Object def, tem, tail;
6122 Lisp_Object result;
6124 int mapno;
6125 Lisp_Object oquit;
6127 int i;
6129 struct gcpro gcpro1;
6131 /* In order to build the menus, we need to call the keymap
6132 accessors. They all call QUIT. But this function is called
6133 during redisplay, during which a quit is fatal. So inhibit
6134 quitting while building the menus.
6135 We do this instead of specbind because (1) errors will clear it anyway
6136 and (2) this avoids risk of specpdl overflow. */
6137 oquit = Vinhibit_quit;
6138 Vinhibit_quit = Qt;
6140 if (!NILP (old))
6141 menu_bar_items_vector = old;
6142 else
6143 menu_bar_items_vector = Fmake_vector (make_number (24), Qnil);
6144 menu_bar_items_index = 0;
6146 GCPRO1 (menu_bar_items_vector);
6148 /* Build our list of keymaps.
6149 If we recognize a function key and replace its escape sequence in
6150 keybuf with its symbol, or if the sequence starts with a mouse
6151 click and we need to switch buffers, we jump back here to rebuild
6152 the initial keymaps from the current buffer. */
6154 Lisp_Object *tmaps;
6156 /* Should overriding-terminal-local-map and overriding-local-map apply? */
6157 if (!NILP (Voverriding_local_map_menu_flag))
6159 /* Yes, use them (if non-nil) as well as the global map. */
6160 maps = (Lisp_Object *) alloca (3 * sizeof (maps[0]));
6161 nmaps = 0;
6162 if (!NILP (current_kboard->Voverriding_terminal_local_map))
6163 maps[nmaps++] = current_kboard->Voverriding_terminal_local_map;
6164 if (!NILP (Voverriding_local_map))
6165 maps[nmaps++] = Voverriding_local_map;
6167 else
6169 /* No, so use major and minor mode keymaps and keymap property. */
6170 int extra_maps = 2;
6171 Lisp_Object map = get_local_map (PT, current_buffer, keymap);
6172 if (!NILP (map))
6173 extra_maps = 3;
6174 nmaps = current_minor_maps (NULL, &tmaps);
6175 maps = (Lisp_Object *) alloca ((nmaps + extra_maps)
6176 * sizeof (maps[0]));
6177 bcopy (tmaps, maps, nmaps * sizeof (maps[0]));
6178 if (!NILP (map))
6179 maps[nmaps++] = get_local_map (PT, current_buffer, keymap);
6180 maps[nmaps++] = get_local_map (PT, current_buffer, local_map);
6182 maps[nmaps++] = current_global_map;
6185 /* Look up in each map the dummy prefix key `menu-bar'. */
6187 result = Qnil;
6189 for (mapno = nmaps - 1; mapno >= 0; mapno--)
6191 if (! NILP (maps[mapno]))
6192 def = get_keyelt (access_keymap (maps[mapno], Qmenu_bar, 1, 0), 0);
6193 else
6194 def = Qnil;
6196 tem = Fkeymapp (def);
6197 if (!NILP (tem))
6198 menu_bar_one_keymap (def);
6201 /* Move to the end those items that should be at the end. */
6203 for (tail = Vmenu_bar_final_items; CONSP (tail); tail = XCDR (tail))
6205 int i;
6206 int end = menu_bar_items_index;
6208 for (i = 0; i < end; i += 4)
6209 if (EQ (XCAR (tail), XVECTOR (menu_bar_items_vector)->contents[i]))
6211 Lisp_Object tem0, tem1, tem2, tem3;
6212 /* Move the item at index I to the end,
6213 shifting all the others forward. */
6214 tem0 = XVECTOR (menu_bar_items_vector)->contents[i + 0];
6215 tem1 = XVECTOR (menu_bar_items_vector)->contents[i + 1];
6216 tem2 = XVECTOR (menu_bar_items_vector)->contents[i + 2];
6217 tem3 = XVECTOR (menu_bar_items_vector)->contents[i + 3];
6218 if (end > i + 4)
6219 bcopy (&XVECTOR (menu_bar_items_vector)->contents[i + 4],
6220 &XVECTOR (menu_bar_items_vector)->contents[i],
6221 (end - i - 4) * sizeof (Lisp_Object));
6222 XVECTOR (menu_bar_items_vector)->contents[end - 4] = tem0;
6223 XVECTOR (menu_bar_items_vector)->contents[end - 3] = tem1;
6224 XVECTOR (menu_bar_items_vector)->contents[end - 2] = tem2;
6225 XVECTOR (menu_bar_items_vector)->contents[end - 1] = tem3;
6226 break;
6230 /* Add nil, nil, nil, nil at the end. */
6231 i = menu_bar_items_index;
6232 if (i + 4 > XVECTOR (menu_bar_items_vector)->size)
6234 Lisp_Object tem;
6235 tem = Fmake_vector (make_number (2 * i), Qnil);
6236 bcopy (XVECTOR (menu_bar_items_vector)->contents,
6237 XVECTOR (tem)->contents, i * sizeof (Lisp_Object));
6238 menu_bar_items_vector = tem;
6240 /* Add this item. */
6241 XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil;
6242 XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil;
6243 XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil;
6244 XVECTOR (menu_bar_items_vector)->contents[i++] = Qnil;
6245 menu_bar_items_index = i;
6247 Vinhibit_quit = oquit;
6248 UNGCPRO;
6249 return menu_bar_items_vector;
6252 /* Scan one map KEYMAP, accumulating any menu items it defines
6253 in menu_bar_items_vector. */
6255 static Lisp_Object menu_bar_one_keymap_changed_items;
6257 static void
6258 menu_bar_one_keymap (keymap)
6259 Lisp_Object keymap;
6261 Lisp_Object tail, item;
6263 menu_bar_one_keymap_changed_items = Qnil;
6265 /* Loop over all keymap entries that have menu strings. */
6266 for (tail = keymap; CONSP (tail); tail = XCDR (tail))
6268 item = XCAR (tail);
6269 if (CONSP (item))
6270 menu_bar_item (XCAR (item), XCDR (item));
6271 else if (VECTORP (item))
6273 /* Loop over the char values represented in the vector. */
6274 int len = XVECTOR (item)->size;
6275 int c;
6276 for (c = 0; c < len; c++)
6278 Lisp_Object character;
6279 XSETFASTINT (character, c);
6280 menu_bar_item (character, XVECTOR (item)->contents[c]);
6286 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
6287 If there's already an item for KEY, add this DEF to it. */
6289 Lisp_Object item_properties;
6291 static void
6292 menu_bar_item (key, item)
6293 Lisp_Object key, item;
6295 struct gcpro gcpro1;
6296 int i;
6297 Lisp_Object tem;
6299 if (EQ (item, Qundefined))
6301 /* If a map has an explicit `undefined' as definition,
6302 discard any previously made menu bar item. */
6304 for (i = 0; i < menu_bar_items_index; i += 4)
6305 if (EQ (key, XVECTOR (menu_bar_items_vector)->contents[i]))
6307 if (menu_bar_items_index > i + 4)
6308 bcopy (&XVECTOR (menu_bar_items_vector)->contents[i + 4],
6309 &XVECTOR (menu_bar_items_vector)->contents[i],
6310 (menu_bar_items_index - i - 4) * sizeof (Lisp_Object));
6311 menu_bar_items_index -= 4;
6312 return;
6315 /* If there's no definition for this key yet,
6316 just ignore `undefined'. */
6317 return;
6320 GCPRO1 (key); /* Is this necessary? */
6321 i = parse_menu_item (item, 0, 1);
6322 UNGCPRO;
6323 if (!i)
6324 return;
6326 /* If this keymap has already contributed to this KEY,
6327 don't contribute to it a second time. */
6328 tem = Fmemq (key, menu_bar_one_keymap_changed_items);
6329 if (!NILP (tem))
6330 return;
6332 menu_bar_one_keymap_changed_items
6333 = Fcons (key, menu_bar_one_keymap_changed_items);
6335 item = XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF];
6337 /* Find any existing item for this KEY. */
6338 for (i = 0; i < menu_bar_items_index; i += 4)
6339 if (EQ (key, XVECTOR (menu_bar_items_vector)->contents[i]))
6340 break;
6342 /* If we did not find this KEY, add it at the end. */
6343 if (i == menu_bar_items_index)
6345 /* If vector is too small, get a bigger one. */
6346 if (i + 4 > XVECTOR (menu_bar_items_vector)->size)
6348 Lisp_Object tem;
6349 tem = Fmake_vector (make_number (2 * i), Qnil);
6350 bcopy (XVECTOR (menu_bar_items_vector)->contents,
6351 XVECTOR (tem)->contents, i * sizeof (Lisp_Object));
6352 menu_bar_items_vector = tem;
6355 /* Add this item. */
6356 XVECTOR (menu_bar_items_vector)->contents[i++] = key;
6357 XVECTOR (menu_bar_items_vector)->contents[i++]
6358 = XVECTOR (item_properties)->contents[ITEM_PROPERTY_NAME];
6359 XVECTOR (menu_bar_items_vector)->contents[i++] = Fcons (item, Qnil);
6360 XVECTOR (menu_bar_items_vector)->contents[i++] = make_number (0);
6361 menu_bar_items_index = i;
6363 /* We did find an item for this KEY. Add ITEM to its list of maps. */
6364 else
6366 Lisp_Object old;
6367 old = XVECTOR (menu_bar_items_vector)->contents[i + 2];
6368 XVECTOR (menu_bar_items_vector)->contents[i + 2] = Fcons (item, old);
6372 /* This is used as the handler when calling menu_item_eval_property. */
6373 static Lisp_Object
6374 menu_item_eval_property_1 (arg)
6375 Lisp_Object arg;
6377 /* If we got a quit from within the menu computation,
6378 quit all the way out of it. This takes care of C-] in the debugger. */
6379 if (CONSP (arg) && EQ (XCAR (arg), Qquit))
6380 Fsignal (Qquit, Qnil);
6382 return Qnil;
6385 /* Evaluate an expression and return the result (or nil if something
6386 went wrong). Used to evaluate dynamic parts of menu items. */
6387 Lisp_Object
6388 menu_item_eval_property (sexpr)
6389 Lisp_Object sexpr;
6391 int count = specpdl_ptr - specpdl;
6392 Lisp_Object val;
6393 specbind (Qinhibit_redisplay, Qt);
6394 val = internal_condition_case_1 (Feval, sexpr, Qerror,
6395 menu_item_eval_property_1);
6396 return unbind_to (count, val);
6399 /* This function parses a menu item and leaves the result in the
6400 vector item_properties.
6401 ITEM is a key binding, a possible menu item.
6402 If NOTREAL is nonzero, only check for equivalent key bindings, don't
6403 evaluate dynamic expressions in the menu item.
6404 INMENUBAR is > 0 when this is considered for an entry in a menu bar
6405 top level.
6406 INMENUBAR is < 0 when this is considered for an entry in a keyboard menu.
6407 parse_menu_item returns true if the item is a menu item and false
6408 otherwise. */
6411 parse_menu_item (item, notreal, inmenubar)
6412 Lisp_Object item;
6413 int notreal, inmenubar;
6415 Lisp_Object def, tem, item_string, start;
6416 Lisp_Object cachelist;
6417 Lisp_Object filter;
6418 Lisp_Object keyhint;
6419 int i;
6420 int newcache = 0;
6422 cachelist = Qnil;
6423 filter = Qnil;
6424 keyhint = Qnil;
6426 if (!CONSP (item))
6427 return 0;
6429 /* Create item_properties vector if necessary. */
6430 if (NILP (item_properties))
6431 item_properties
6432 = Fmake_vector (make_number (ITEM_PROPERTY_ENABLE + 1), Qnil);
6434 /* Initialize optional entries. */
6435 for (i = ITEM_PROPERTY_DEF; i < ITEM_PROPERTY_ENABLE; i++)
6436 XVECTOR (item_properties)->contents[i] = Qnil;
6437 XVECTOR (item_properties)->contents[ITEM_PROPERTY_ENABLE] = Qt;
6439 /* Save the item here to protect it from GC. */
6440 XVECTOR (item_properties)->contents[ITEM_PROPERTY_ITEM] = item;
6442 item_string = XCAR (item);
6444 start = item;
6445 item = XCDR (item);
6446 if (STRINGP (item_string))
6448 /* Old format menu item. */
6449 XVECTOR (item_properties)->contents[ITEM_PROPERTY_NAME] = item_string;
6451 /* Maybe help string. */
6452 if (CONSP (item) && STRINGP (XCAR (item)))
6454 XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP]
6455 = XCAR (item);
6456 start = item;
6457 item = XCDR (item);
6460 /* Maybe key binding cache. */
6461 if (CONSP (item) && CONSP (XCAR (item))
6462 && (NILP (XCAR (XCAR (item)))
6463 || VECTORP (XCAR (XCAR (item)))))
6465 cachelist = XCAR (item);
6466 item = XCDR (item);
6469 /* This is the real definition--the function to run. */
6470 XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF] = item;
6472 /* Get enable property, if any. */
6473 if (SYMBOLP (item))
6475 tem = Fget (item, Qmenu_enable);
6476 if (!NILP (tem))
6477 XVECTOR (item_properties)->contents[ITEM_PROPERTY_ENABLE] = tem;
6480 else if (EQ (item_string, Qmenu_item) && CONSP (item))
6482 /* New format menu item. */
6483 XVECTOR (item_properties)->contents[ITEM_PROPERTY_NAME]
6484 = XCAR (item);
6485 start = XCDR (item);
6486 if (CONSP (start))
6488 /* We have a real binding. */
6489 XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF]
6490 = XCAR (start);
6492 item = XCDR (start);
6493 /* Is there a cache list with key equivalences. */
6494 if (CONSP (item) && CONSP (XCAR (item)))
6496 cachelist = XCAR (item);
6497 item = XCDR (item);
6500 /* Parse properties. */
6501 while (CONSP (item) && CONSP (XCDR (item)))
6503 tem = XCAR (item);
6504 item = XCDR (item);
6506 if (EQ (tem, QCenable))
6507 XVECTOR (item_properties)->contents[ITEM_PROPERTY_ENABLE]
6508 = XCAR (item);
6509 else if (EQ (tem, QCvisible) && !notreal)
6511 /* If got a visible property and that evaluates to nil
6512 then ignore this item. */
6513 tem = menu_item_eval_property (XCAR (item));
6514 if (NILP (tem))
6515 return 0;
6517 else if (EQ (tem, QChelp))
6518 XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP]
6519 = XCAR (item);
6520 else if (EQ (tem, QCfilter))
6521 filter = item;
6522 else if (EQ (tem, QCkey_sequence))
6524 tem = XCAR (item);
6525 if (NILP (cachelist)
6526 && (SYMBOLP (tem) || STRINGP (tem) || VECTORP (tem)))
6527 /* Be GC protected. Set keyhint to item instead of tem. */
6528 keyhint = item;
6530 else if (EQ (tem, QCkeys))
6532 tem = XCAR (item);
6533 if (CONSP (tem) || (STRINGP (tem) && NILP (cachelist)))
6534 XVECTOR (item_properties)->contents[ITEM_PROPERTY_KEYEQ]
6535 = tem;
6537 else if (EQ (tem, QCbutton) && CONSP (XCAR (item)))
6539 Lisp_Object type;
6540 tem = XCAR (item);
6541 type = XCAR (tem);
6542 if (EQ (type, QCtoggle) || EQ (type, QCradio))
6544 XVECTOR (item_properties)->contents[ITEM_PROPERTY_SELECTED]
6545 = XCDR (tem);
6546 XVECTOR (item_properties)->contents[ITEM_PROPERTY_TYPE]
6547 = type;
6550 item = XCDR (item);
6553 else if (inmenubar || !NILP (start))
6554 return 0;
6556 else
6557 return 0; /* not a menu item */
6559 /* If item string is not a string, evaluate it to get string.
6560 If we don't get a string, skip this item. */
6561 item_string = XVECTOR (item_properties)->contents[ITEM_PROPERTY_NAME];
6562 if (!(STRINGP (item_string) || notreal))
6564 item_string = menu_item_eval_property (item_string);
6565 if (!STRINGP (item_string))
6566 return 0;
6567 XVECTOR (item_properties)->contents[ITEM_PROPERTY_NAME] = item_string;
6570 /* If got a filter apply it on definition. */
6571 def = XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF];
6572 if (!NILP (filter))
6574 def = menu_item_eval_property (list2 (XCAR (filter),
6575 list2 (Qquote, def)));
6577 XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF] = def;
6580 /* If we got no definition, this item is just unselectable text which
6581 is OK in a submenu but not in the menubar. */
6582 if (NILP (def))
6583 return (inmenubar ? 0 : 1);
6585 /* Enable or disable selection of item. */
6586 tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_ENABLE];
6587 if (!EQ (tem, Qt))
6589 if (notreal)
6590 tem = Qt;
6591 else
6592 tem = menu_item_eval_property (tem);
6593 if (inmenubar && NILP (tem))
6594 return 0; /* Ignore disabled items in menu bar. */
6595 XVECTOR (item_properties)->contents[ITEM_PROPERTY_ENABLE] = tem;
6598 /* See if this is a separate pane or a submenu. */
6599 def = XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF];
6600 tem = get_keymap_1 (def, 0, 1);
6601 /* For a subkeymap, just record its details and exit. */
6602 if (!NILP (tem))
6604 XVECTOR (item_properties)->contents[ITEM_PROPERTY_MAP] = tem;
6605 XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF] = tem;
6606 return 1;
6608 /* At the top level in the menu bar, do likewise for commands also.
6609 The menu bar does not display equivalent key bindings anyway.
6610 ITEM_PROPERTY_DEF is already set up properly. */
6611 if (inmenubar > 0)
6612 return 1;
6614 /* This is a command. See if there is an equivalent key binding. */
6615 if (NILP (cachelist))
6617 /* We have to create a cachelist. */
6618 CHECK_IMPURE (start);
6619 XCDR (start) = Fcons (Fcons (Qnil, Qnil), XCDR (start));
6620 cachelist = XCAR (XCDR (start));
6621 newcache = 1;
6622 tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_KEYEQ];
6623 if (!NILP (keyhint))
6625 XCAR (cachelist) = XCAR (keyhint);
6626 newcache = 0;
6628 else if (STRINGP (tem))
6630 XCDR (cachelist) = Fsubstitute_command_keys (tem);
6631 XCAR (cachelist) = Qt;
6634 tem = XCAR (cachelist);
6635 if (!EQ (tem, Qt))
6637 int chkcache = 0;
6638 Lisp_Object prefix;
6640 if (!NILP (tem))
6641 tem = Fkey_binding (tem, Qnil);
6643 prefix = XVECTOR (item_properties)->contents[ITEM_PROPERTY_KEYEQ];
6644 if (CONSP (prefix))
6646 def = XCAR (prefix);
6647 prefix = XCDR (prefix);
6649 else
6650 def = XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF];
6652 if (NILP (XCAR (cachelist))) /* Have no saved key. */
6654 if (newcache /* Always check first time. */
6655 /* Should we check everything when precomputing key
6656 bindings? */
6657 /* || notreal */
6658 /* If something had no key binding before, don't recheck it
6659 because that is too slow--except if we have a list of
6660 rebound commands in Vdefine_key_rebound_commands, do
6661 recheck any command that appears in that list. */
6662 || (CONSP (Vdefine_key_rebound_commands)
6663 && !NILP (Fmemq (def, Vdefine_key_rebound_commands))))
6664 chkcache = 1;
6666 /* We had a saved key. Is it still bound to the command? */
6667 else if (NILP (tem)
6668 || (!EQ (tem, def)
6669 /* If the command is an alias for another
6670 (such as lmenu.el set it up), check if the
6671 original command matches the cached command. */
6672 && !(SYMBOLP (def) && EQ (tem, XSYMBOL (def)->function))))
6673 chkcache = 1; /* Need to recompute key binding. */
6675 if (chkcache)
6677 /* Recompute equivalent key binding. If the command is an alias
6678 for another (such as lmenu.el set it up), see if the original
6679 command name has equivalent keys. Otherwise look up the
6680 specified command itself. We don't try both, because that
6681 makes lmenu menus slow. */
6682 if (SYMBOLP (def) && SYMBOLP (XSYMBOL (def)->function)
6683 && ! NILP (Fget (def, Qmenu_alias)))
6684 def = XSYMBOL (def)->function;
6685 tem = Fwhere_is_internal (def, Qnil, Qt, Qnil);
6686 XCAR (cachelist) = tem;
6687 if (NILP (tem))
6689 XCDR (cachelist) = Qnil;
6690 chkcache = 0;
6693 else if (!NILP (keyhint) && !NILP (XCAR (cachelist)))
6695 tem = XCAR (cachelist);
6696 chkcache = 1;
6699 newcache = chkcache;
6700 if (chkcache)
6702 tem = Fkey_description (tem);
6703 if (CONSP (prefix))
6705 if (STRINGP (XCAR (prefix)))
6706 tem = concat2 (XCAR (prefix), tem);
6707 if (STRINGP (XCDR (prefix)))
6708 tem = concat2 (tem, XCDR (prefix));
6710 XCDR (cachelist) = tem;
6714 tem = XCDR (cachelist);
6715 if (newcache && !NILP (tem))
6717 tem = concat3 (build_string (" ("), tem, build_string (")"));
6718 XCDR (cachelist) = tem;
6721 /* If we only want to precompute equivalent key bindings, stop here. */
6722 if (notreal)
6723 return 1;
6725 /* If we have an equivalent key binding, use that. */
6726 XVECTOR (item_properties)->contents[ITEM_PROPERTY_KEYEQ] = tem;
6728 /* Include this when menu help is implemented.
6729 tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP];
6730 if (!(NILP (tem) || STRINGP (tem)))
6732 tem = menu_item_eval_property (tem);
6733 if (!STRINGP (tem))
6734 tem = Qnil;
6735 XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP] = tem;
6739 /* Handle radio buttons or toggle boxes. */
6740 tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_SELECTED];
6741 if (!NILP (tem))
6742 XVECTOR (item_properties)->contents[ITEM_PROPERTY_SELECTED]
6743 = menu_item_eval_property (tem);
6745 return 1;
6750 /***********************************************************************
6751 Tool-bars
6752 ***********************************************************************/
6754 /* A vector holding tool bar items while they are parsed in function
6755 tool_bar_items runs Each item occupies TOOL_BAR_ITEM_NSCLOTS elements
6756 in the vector. */
6758 static Lisp_Object tool_bar_items_vector;
6760 /* A vector holding the result of parse_tool_bar_item. Layout is like
6761 the one for a single item in tool_bar_items_vector. */
6763 static Lisp_Object tool_bar_item_properties;
6765 /* Next free index in tool_bar_items_vector. */
6767 static int ntool_bar_items;
6769 /* The symbols `tool-bar', and `:image'. */
6771 extern Lisp_Object Qtool_bar;
6772 Lisp_Object QCimage;
6774 /* Function prototypes. */
6776 static void init_tool_bar_items P_ ((Lisp_Object));
6777 static void process_tool_bar_item P_ ((Lisp_Object, Lisp_Object));
6778 static int parse_tool_bar_item P_ ((Lisp_Object, Lisp_Object));
6779 static void append_tool_bar_item P_ ((void));
6782 /* Return a vector of tool bar items for keymaps currently in effect.
6783 Reuse vector REUSE if non-nil. Return in *NITEMS the number of
6784 tool bar items found. */
6786 Lisp_Object
6787 tool_bar_items (reuse, nitems)
6788 Lisp_Object reuse;
6789 int *nitems;
6791 Lisp_Object *maps;
6792 int nmaps, i;
6793 Lisp_Object oquit;
6794 Lisp_Object *tmaps;
6795 extern Lisp_Object Voverriding_local_map_menu_flag;
6796 extern Lisp_Object Voverriding_local_map;
6798 *nitems = 0;
6800 /* In order to build the menus, we need to call the keymap
6801 accessors. They all call QUIT. But this function is called
6802 during redisplay, during which a quit is fatal. So inhibit
6803 quitting while building the menus. We do this instead of
6804 specbind because (1) errors will clear it anyway and (2) this
6805 avoids risk of specpdl overflow. */
6806 oquit = Vinhibit_quit;
6807 Vinhibit_quit = Qt;
6809 /* Initialize tool_bar_items_vector and protect it from GC. */
6810 init_tool_bar_items (reuse);
6812 /* Build list of keymaps in maps. Set nmaps to the number of maps
6813 to process. */
6815 /* Should overriding-terminal-local-map and overriding-local-map apply? */
6816 if (!NILP (Voverriding_local_map_menu_flag))
6818 /* Yes, use them (if non-nil) as well as the global map. */
6819 maps = (Lisp_Object *) alloca (3 * sizeof (maps[0]));
6820 nmaps = 0;
6821 if (!NILP (current_kboard->Voverriding_terminal_local_map))
6822 maps[nmaps++] = current_kboard->Voverriding_terminal_local_map;
6823 if (!NILP (Voverriding_local_map))
6824 maps[nmaps++] = Voverriding_local_map;
6826 else
6828 /* No, so use major and minor mode keymaps and keymap property. */
6829 int extra_maps = 2;
6830 Lisp_Object map = get_local_map (PT, current_buffer, keymap);
6831 if (!NILP (map))
6832 extra_maps = 3;
6833 nmaps = current_minor_maps (NULL, &tmaps);
6834 maps = (Lisp_Object *) alloca ((nmaps + extra_maps)
6835 * sizeof (maps[0]));
6836 bcopy (tmaps, maps, nmaps * sizeof (maps[0]));
6837 if (!NILP (map))
6838 maps[nmaps++] = get_local_map (PT, current_buffer, keymap);
6839 maps[nmaps++] = get_local_map (PT, current_buffer, local_map);
6842 /* Add global keymap at the end. */
6843 maps[nmaps++] = current_global_map;
6845 /* Process maps in reverse order and look up in each map the prefix
6846 key `tool-bar'. */
6847 for (i = nmaps - 1; i >= 0; --i)
6848 if (!NILP (maps[i]))
6850 Lisp_Object keymap;
6852 keymap = get_keyelt (access_keymap (maps[i], Qtool_bar, 1, 1), 0);
6853 if (!NILP (Fkeymapp (keymap)))
6855 Lisp_Object tail;
6857 /* KEYMAP is a list `(keymap (KEY . BINDING) ...)'. */
6858 for (tail = keymap; CONSP (tail); tail = XCDR (tail))
6860 Lisp_Object keydef = XCAR (tail);
6861 if (CONSP (keydef))
6862 process_tool_bar_item (XCAR (keydef), XCDR (keydef));
6867 Vinhibit_quit = oquit;
6868 *nitems = ntool_bar_items / TOOL_BAR_ITEM_NSLOTS;
6869 return tool_bar_items_vector;
6873 /* Process the definition of KEY which is DEF. */
6875 static void
6876 process_tool_bar_item (key, def)
6877 Lisp_Object key, def;
6879 int i;
6880 extern Lisp_Object Qundefined;
6881 struct gcpro gcpro1, gcpro2;
6883 /* Protect KEY and DEF from GC because parse_tool_bar_item may call
6884 eval. */
6885 GCPRO2 (key, def);
6887 if (EQ (def, Qundefined))
6889 /* If a map has an explicit `undefined' as definition,
6890 discard any previously made item. */
6891 for (i = 0; i < ntool_bar_items; i += TOOL_BAR_ITEM_NSLOTS)
6893 Lisp_Object *v = XVECTOR (tool_bar_items_vector)->contents + i;
6895 if (EQ (key, v[TOOL_BAR_ITEM_KEY]))
6897 if (ntool_bar_items > i + TOOL_BAR_ITEM_NSLOTS)
6898 bcopy (v + TOOL_BAR_ITEM_NSLOTS, v,
6899 ((ntool_bar_items - i - TOOL_BAR_ITEM_NSLOTS)
6900 * sizeof (Lisp_Object)));
6901 ntool_bar_items -= TOOL_BAR_ITEM_NSLOTS;
6902 break;
6906 else if (parse_tool_bar_item (key, def))
6907 /* Append a new tool bar item to tool_bar_items_vector. Accept
6908 more than one definition for the same key. */
6909 append_tool_bar_item ();
6911 UNGCPRO;
6915 /* Parse a tool bar item specification ITEM for key KEY and return the
6916 result in tool_bar_item_properties. Value is zero if ITEM is
6917 invalid.
6919 ITEM is a list `(menu-item CAPTION BINDING PROPS...)'.
6921 CAPTION is the caption of the item, If it's not a string, it is
6922 evaluated to get a string.
6924 BINDING is the tool bar item's binding. Tool-bar items with keymaps
6925 as binding are currently ignored.
6927 The following properties are recognized:
6929 - `:enable FORM'.
6931 FORM is evaluated and specifies whether the tool bar item is
6932 enabled or disabled.
6934 - `:visible FORM'
6936 FORM is evaluated and specifies whether the tool bar item is visible.
6938 - `:filter FUNCTION'
6940 FUNCTION is invoked with one parameter `(quote BINDING)'. Its
6941 result is stored as the new binding.
6943 - `:button (TYPE SELECTED)'
6945 TYPE must be one of `:radio' or `:toggle'. SELECTED is evaluated
6946 and specifies whether the button is selected (pressed) or not.
6948 - `:image IMAGES'
6950 IMAGES is either a single image specification or a vector of four
6951 image specifications. See enum tool_bar_item_images.
6953 - `:help HELP-STRING'.
6955 Gives a help string to display for the tool bar item. */
6957 static int
6958 parse_tool_bar_item (key, item)
6959 Lisp_Object key, item;
6961 /* Access slot with index IDX of vector tool_bar_item_properties. */
6962 #define PROP(IDX) XVECTOR (tool_bar_item_properties)->contents[IDX]
6964 Lisp_Object filter = Qnil;
6965 Lisp_Object caption;
6966 extern Lisp_Object QCenable, QCvisible, QChelp, QCfilter;
6967 extern Lisp_Object QCbutton, QCtoggle, QCradio;
6968 int i;
6970 /* Defininition looks like `(tool-bar-item CAPTION BINDING
6971 PROPS...)'. Rule out items that aren't lists, don't start with
6972 `tool-bar-item' or whose rest following `tool-bar-item' is not a
6973 list. */
6974 if (!CONSP (item)
6975 || !EQ (XCAR (item), Qmenu_item)
6976 || (item = XCDR (item),
6977 !CONSP (item)))
6978 return 0;
6980 /* Create tool_bar_item_properties vector if necessary. Reset it to
6981 defaults. */
6982 if (VECTORP (tool_bar_item_properties))
6984 for (i = 0; i < TOOL_BAR_ITEM_NSLOTS; ++i)
6985 PROP (i) = Qnil;
6987 else
6988 tool_bar_item_properties
6989 = Fmake_vector (make_number (TOOL_BAR_ITEM_NSLOTS), Qnil);
6991 /* Set defaults. */
6992 PROP (TOOL_BAR_ITEM_KEY) = key;
6993 PROP (TOOL_BAR_ITEM_ENABLED_P) = Qt;
6995 /* Get the caption of the item. If the caption is not a string,
6996 evaluate it to get a string. If we don't get a string, skip this
6997 item. */
6998 caption = XCAR (item);
6999 if (!STRINGP (caption))
7001 caption = menu_item_eval_property (caption);
7002 if (!STRINGP (caption))
7003 return 0;
7005 PROP (TOOL_BAR_ITEM_CAPTION) = caption;
7007 /* Give up if rest following the caption is not a list. */
7008 item = XCDR (item);
7009 if (!CONSP (item))
7010 return 0;
7012 /* Store the binding. */
7013 PROP (TOOL_BAR_ITEM_BINDING) = XCAR (item);
7014 item = XCDR (item);
7016 /* Process the rest of the properties. */
7017 for (; CONSP (item) && CONSP (XCDR (item)); item = XCDR (XCDR (item)))
7019 Lisp_Object key, value;
7021 key = XCAR (item);
7022 value = XCAR (XCDR (item));
7024 if (EQ (key, QCenable))
7025 /* `:enable FORM'. */
7026 PROP (TOOL_BAR_ITEM_ENABLED_P) = value;
7027 else if (EQ (key, QCvisible))
7029 /* `:visible FORM'. If got a visible property and that
7030 evaluates to nil then ignore this item. */
7031 if (NILP (menu_item_eval_property (value)))
7032 return 0;
7034 else if (EQ (key, QChelp))
7035 /* `:help HELP-STRING'. */
7036 PROP (TOOL_BAR_ITEM_HELP) = value;
7037 else if (EQ (key, QCfilter))
7038 /* ':filter FORM'. */
7039 filter = value;
7040 else if (EQ (key, QCbutton) && CONSP (value))
7042 /* `:button (TYPE . SELECTED)'. */
7043 Lisp_Object type, selected;
7045 type = XCAR (value);
7046 selected = XCDR (value);
7047 if (EQ (type, QCtoggle) || EQ (type, QCradio))
7049 PROP (TOOL_BAR_ITEM_SELECTED_P) = selected;
7050 PROP (TOOL_BAR_ITEM_TYPE) = type;
7053 else if (EQ (key, QCimage)
7054 && (CONSP (value)
7055 || (VECTORP (value) && XVECTOR (value)->size == 4)))
7056 /* Value is either a single image specification or a vector
7057 of 4 such specifications for the different buttion states. */
7058 PROP (TOOL_BAR_ITEM_IMAGES) = value;
7061 /* If got a filter apply it on binding. */
7062 if (!NILP (filter))
7063 PROP (TOOL_BAR_ITEM_BINDING)
7064 = menu_item_eval_property (list2 (filter,
7065 list2 (Qquote,
7066 PROP (TOOL_BAR_ITEM_BINDING))));
7068 /* See if the binding is a keymap. Give up if it is. */
7069 if (!NILP (get_keymap_1 (PROP (TOOL_BAR_ITEM_BINDING), 0, 1)))
7070 return 0;
7072 /* Enable or disable selection of item. */
7073 if (!EQ (PROP (TOOL_BAR_ITEM_ENABLED_P), Qt))
7074 PROP (TOOL_BAR_ITEM_ENABLED_P)
7075 = menu_item_eval_property (PROP (TOOL_BAR_ITEM_ENABLED_P));
7077 /* Handle radio buttons or toggle boxes. */
7078 if (!NILP (PROP (TOOL_BAR_ITEM_SELECTED_P)))
7079 PROP (TOOL_BAR_ITEM_SELECTED_P)
7080 = menu_item_eval_property (PROP (TOOL_BAR_ITEM_SELECTED_P));
7082 return 1;
7084 #undef PROP
7088 /* Initialize tool_bar_items_vector. REUSE, if non-nil, is a vector
7089 that can be reused. */
7091 static void
7092 init_tool_bar_items (reuse)
7093 Lisp_Object reuse;
7095 if (VECTORP (reuse))
7096 tool_bar_items_vector = reuse;
7097 else
7098 tool_bar_items_vector = Fmake_vector (make_number (64), Qnil);
7099 ntool_bar_items = 0;
7103 /* Append parsed tool bar item properties from
7104 tool_bar_item_properties */
7106 static void
7107 append_tool_bar_item ()
7109 Lisp_Object *to, *from;
7111 /* Enlarge tool_bar_items_vector if necessary. */
7112 if (ntool_bar_items + TOOL_BAR_ITEM_NSLOTS
7113 >= XVECTOR (tool_bar_items_vector)->size)
7115 Lisp_Object new_vector;
7116 int old_size = XVECTOR (tool_bar_items_vector)->size;
7118 new_vector = Fmake_vector (make_number (2 * old_size), Qnil);
7119 bcopy (XVECTOR (tool_bar_items_vector)->contents,
7120 XVECTOR (new_vector)->contents,
7121 old_size * sizeof (Lisp_Object));
7122 tool_bar_items_vector = new_vector;
7125 /* Append entries from tool_bar_item_properties to the end of
7126 tool_bar_items_vector. */
7127 to = XVECTOR (tool_bar_items_vector)->contents + ntool_bar_items;
7128 from = XVECTOR (tool_bar_item_properties)->contents;
7129 bcopy (from, to, TOOL_BAR_ITEM_NSLOTS * sizeof *to);
7130 ntool_bar_items += TOOL_BAR_ITEM_NSLOTS;
7137 /* Read a character using menus based on maps in the array MAPS.
7138 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
7139 Return t if we displayed a menu but the user rejected it.
7141 PREV_EVENT is the previous input event, or nil if we are reading
7142 the first event of a key sequence.
7144 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
7145 if we used a mouse menu to read the input, or zero otherwise. If
7146 USED_MOUSE_MENU is null, we don't dereference it.
7148 The prompting is done based on the prompt-string of the map
7149 and the strings associated with various map elements.
7151 This can be done with X menus or with menus put in the minibuf.
7152 These are done in different ways, depending on how the input will be read.
7153 Menus using X are done after auto-saving in read-char, getting the input
7154 event from Fx_popup_menu; menus using the minibuf use read_char recursively
7155 and do auto-saving in the inner call of read_char. */
7157 static Lisp_Object
7158 read_char_x_menu_prompt (nmaps, maps, prev_event, used_mouse_menu)
7159 int nmaps;
7160 Lisp_Object *maps;
7161 Lisp_Object prev_event;
7162 int *used_mouse_menu;
7164 int mapno;
7165 register Lisp_Object name;
7167 if (used_mouse_menu)
7168 *used_mouse_menu = 0;
7170 /* Use local over global Menu maps */
7172 if (! menu_prompting)
7173 return Qnil;
7175 /* Optionally disregard all but the global map. */
7176 if (inhibit_local_menu_bar_menus)
7178 maps += (nmaps - 1);
7179 nmaps = 1;
7182 /* Get the menu name from the first map that has one (a prompt string). */
7183 for (mapno = 0; mapno < nmaps; mapno++)
7185 name = map_prompt (maps[mapno]);
7186 if (!NILP (name))
7187 break;
7190 /* If we don't have any menus, just read a character normally. */
7191 if (mapno >= nmaps)
7192 return Qnil;
7194 #ifdef HAVE_MENUS
7195 /* If we got to this point via a mouse click,
7196 use a real menu for mouse selection. */
7197 if (EVENT_HAS_PARAMETERS (prev_event)
7198 && !EQ (XCAR (prev_event), Qmenu_bar)
7199 && !EQ (XCAR (prev_event), Qtool_bar))
7201 /* Display the menu and get the selection. */
7202 Lisp_Object *realmaps
7203 = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object));
7204 Lisp_Object value;
7205 int nmaps1 = 0;
7207 /* Use the maps that are not nil. */
7208 for (mapno = 0; mapno < nmaps; mapno++)
7209 if (!NILP (maps[mapno]))
7210 realmaps[nmaps1++] = maps[mapno];
7212 value = Fx_popup_menu (prev_event, Flist (nmaps1, realmaps));
7213 if (CONSP (value))
7215 Lisp_Object tem;
7217 record_menu_key (XCAR (value));
7219 /* If we got multiple events, unread all but
7220 the first.
7221 There is no way to prevent those unread events
7222 from showing up later in last_nonmenu_event.
7223 So turn symbol and integer events into lists,
7224 to indicate that they came from a mouse menu,
7225 so that when present in last_nonmenu_event
7226 they won't confuse things. */
7227 for (tem = XCDR (value); !NILP (tem);
7228 tem = XCDR (tem))
7230 record_menu_key (XCAR (tem));
7231 if (SYMBOLP (XCAR (tem))
7232 || INTEGERP (XCAR (tem)))
7233 XCAR (tem)
7234 = Fcons (XCAR (tem), Qnil);
7237 /* If we got more than one event, put all but the first
7238 onto this list to be read later.
7239 Return just the first event now. */
7240 Vunread_command_events
7241 = nconc2 (XCDR (value), Vunread_command_events);
7242 value = XCAR (value);
7244 else if (NILP (value))
7245 value = Qt;
7246 if (used_mouse_menu)
7247 *used_mouse_menu = 1;
7248 return value;
7250 #endif /* HAVE_MENUS */
7251 return Qnil ;
7254 /* Buffer in use so far for the minibuf prompts for menu keymaps.
7255 We make this bigger when necessary, and never free it. */
7256 static char *read_char_minibuf_menu_text;
7257 /* Size of that buffer. */
7258 static int read_char_minibuf_menu_width;
7260 static Lisp_Object
7261 read_char_minibuf_menu_prompt (commandflag, nmaps, maps)
7262 int commandflag ;
7263 int nmaps;
7264 Lisp_Object *maps;
7266 int mapno;
7267 register Lisp_Object name;
7268 int nlength;
7269 int width = FRAME_WIDTH (SELECTED_FRAME ()) - 4;
7270 int idx = -1;
7271 int nobindings = 1;
7272 Lisp_Object rest, vector;
7273 char *menu;
7275 if (! menu_prompting)
7276 return Qnil;
7278 /* Make sure we have a big enough buffer for the menu text. */
7279 if (read_char_minibuf_menu_text == 0)
7281 read_char_minibuf_menu_width = width + 4;
7282 read_char_minibuf_menu_text = (char *) xmalloc (width + 4);
7284 else if (width + 4 > read_char_minibuf_menu_width)
7286 read_char_minibuf_menu_width = width + 4;
7287 read_char_minibuf_menu_text
7288 = (char *) xrealloc (read_char_minibuf_menu_text, width + 4);
7290 menu = read_char_minibuf_menu_text;
7292 /* Get the menu name from the first map that has one (a prompt string). */
7293 for (mapno = 0; mapno < nmaps; mapno++)
7295 name = map_prompt (maps[mapno]);
7296 if (!NILP (name))
7297 break;
7300 /* If we don't have any menus, just read a character normally. */
7301 if (mapno >= nmaps)
7302 return Qnil;
7304 /* Prompt string always starts with map's prompt, and a space. */
7305 strcpy (menu, XSTRING (name)->data);
7306 nlength = STRING_BYTES (XSTRING (name));
7307 menu[nlength++] = ':';
7308 menu[nlength++] = ' ';
7309 menu[nlength] = 0;
7311 /* Start prompting at start of first map. */
7312 mapno = 0;
7313 rest = maps[mapno];
7315 /* Present the documented bindings, a line at a time. */
7316 while (1)
7318 int notfirst = 0;
7319 int i = nlength;
7320 Lisp_Object obj;
7321 int ch;
7322 Lisp_Object orig_defn_macro;
7324 /* Loop over elements of map. */
7325 while (i < width)
7327 Lisp_Object elt;
7329 /* If reached end of map, start at beginning of next map. */
7330 if (NILP (rest))
7332 mapno++;
7333 /* At end of last map, wrap around to first map if just starting,
7334 or end this line if already have something on it. */
7335 if (mapno == nmaps)
7337 mapno = 0;
7338 if (notfirst || nobindings) break;
7340 rest = maps[mapno];
7343 /* Look at the next element of the map. */
7344 if (idx >= 0)
7345 elt = XVECTOR (vector)->contents[idx];
7346 else
7347 elt = Fcar_safe (rest);
7349 if (idx < 0 && VECTORP (elt))
7351 /* If we found a dense table in the keymap,
7352 advanced past it, but start scanning its contents. */
7353 rest = Fcdr_safe (rest);
7354 vector = elt;
7355 idx = 0;
7357 else
7359 /* An ordinary element. */
7360 Lisp_Object event, tem;
7362 if (idx < 0)
7364 event = Fcar_safe (elt); /* alist */
7365 elt = Fcdr_safe (elt);
7367 else
7369 XSETINT (event, idx); /* vector */
7372 /* Ignore the element if it has no prompt string. */
7373 if (INTEGERP (event) && parse_menu_item (elt, 0, -1))
7375 /* 1 if the char to type matches the string. */
7376 int char_matches;
7377 Lisp_Object upcased_event, downcased_event;
7378 Lisp_Object desc;
7379 Lisp_Object s
7380 = XVECTOR (item_properties)->contents[ITEM_PROPERTY_NAME];
7382 upcased_event = Fupcase (event);
7383 downcased_event = Fdowncase (event);
7384 char_matches = (XINT (upcased_event) == XSTRING (s)->data[0]
7385 || XINT (downcased_event) == XSTRING (s)->data[0]);
7386 if (! char_matches)
7387 desc = Fsingle_key_description (event, Qnil);
7390 = XVECTOR (item_properties)->contents[ITEM_PROPERTY_KEYEQ];
7391 if (!NILP (tem))
7392 /* Insert equivalent keybinding. */
7393 s = concat2 (s, tem);
7396 = XVECTOR (item_properties)->contents[ITEM_PROPERTY_TYPE];
7397 if (EQ (tem, QCradio) || EQ (tem, QCtoggle))
7399 /* Insert button prefix. */
7400 Lisp_Object selected
7401 = XVECTOR (item_properties)->contents[ITEM_PROPERTY_SELECTED];
7402 if (EQ (tem, QCradio))
7403 tem = build_string (NILP (selected) ? "(*) " : "( ) ");
7404 else
7405 tem = build_string (NILP (selected) ? "[X] " : "[ ] ");
7406 s = concat2 (tem, s);
7410 /* If we have room for the prompt string, add it to this line.
7411 If this is the first on the line, always add it. */
7412 if ((XSTRING (s)->size + i + 2
7413 + (char_matches ? 0 : XSTRING (desc)->size + 3))
7414 < width
7415 || !notfirst)
7417 int thiswidth;
7419 /* Punctuate between strings. */
7420 if (notfirst)
7422 strcpy (menu + i, ", ");
7423 i += 2;
7425 notfirst = 1;
7426 nobindings = 0 ;
7428 /* If the char to type doesn't match the string's
7429 first char, explicitly show what char to type. */
7430 if (! char_matches)
7432 /* Add as much of string as fits. */
7433 thiswidth = XSTRING (desc)->size;
7434 if (thiswidth + i > width)
7435 thiswidth = width - i;
7436 bcopy (XSTRING (desc)->data, menu + i, thiswidth);
7437 i += thiswidth;
7438 strcpy (menu + i, " = ");
7439 i += 3;
7442 /* Add as much of string as fits. */
7443 thiswidth = XSTRING (s)->size;
7444 if (thiswidth + i > width)
7445 thiswidth = width - i;
7446 bcopy (XSTRING (s)->data, menu + i, thiswidth);
7447 i += thiswidth;
7448 menu[i] = 0;
7450 else
7452 /* If this element does not fit, end the line now,
7453 and save the element for the next line. */
7454 strcpy (menu + i, "...");
7455 break;
7459 /* Move past this element. */
7460 if (idx >= 0 && idx + 1 >= XVECTOR (vector)->size)
7461 /* Handle reaching end of dense table. */
7462 idx = -1;
7463 if (idx >= 0)
7464 idx++;
7465 else
7466 rest = Fcdr_safe (rest);
7470 /* Prompt with that and read response. */
7471 message2_nolog (menu, strlen (menu),
7472 ! NILP (current_buffer->enable_multibyte_characters));
7474 /* Make believe its not a keyboard macro in case the help char
7475 is pressed. Help characters are not recorded because menu prompting
7476 is not used on replay.
7478 orig_defn_macro = current_kboard->defining_kbd_macro;
7479 current_kboard->defining_kbd_macro = Qnil;
7481 obj = read_char (commandflag, 0, 0, Qnil, 0);
7482 while (BUFFERP (obj));
7483 current_kboard->defining_kbd_macro = orig_defn_macro;
7485 if (!INTEGERP (obj))
7486 return obj;
7487 else
7488 ch = XINT (obj);
7490 if (! EQ (obj, menu_prompt_more_char)
7491 && (!INTEGERP (menu_prompt_more_char)
7492 || ! EQ (obj, make_number (Ctl (XINT (menu_prompt_more_char))))))
7494 if (!NILP (current_kboard->defining_kbd_macro))
7495 store_kbd_macro_char (obj);
7496 return obj;
7498 /* Help char - go round again */
7502 /* Reading key sequences. */
7504 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
7505 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
7506 keymap, or nil otherwise. Return the index of the first keymap in
7507 which KEY has any binding, or NMAPS if no map has a binding.
7509 If KEY is a meta ASCII character, treat it like meta-prefix-char
7510 followed by the corresponding non-meta character. Keymaps in
7511 CURRENT with non-prefix bindings for meta-prefix-char become nil in
7512 NEXT.
7514 If KEY has no bindings in any of the CURRENT maps, NEXT is left
7515 unmodified.
7517 NEXT may be the same array as CURRENT. */
7519 static int
7520 follow_key (key, nmaps, current, defs, next)
7521 Lisp_Object key;
7522 Lisp_Object *current, *defs, *next;
7523 int nmaps;
7525 int i, first_binding;
7526 int did_meta = 0;
7528 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
7529 followed by the corresponding non-meta character.
7530 Put the results into DEFS, since we are going to alter that anyway.
7531 Do not alter CURRENT or NEXT. */
7532 if (INTEGERP (key) && (XUINT (key) & CHAR_META))
7534 for (i = 0; i < nmaps; i++)
7535 if (! NILP (current[i]))
7537 Lisp_Object def;
7538 def = get_keyelt (access_keymap (current[i],
7539 meta_prefix_char, 1, 0), 0);
7541 /* Note that since we pass the resulting bindings through
7542 get_keymap_1, non-prefix bindings for meta-prefix-char
7543 disappear. */
7544 defs[i] = get_keymap_1 (def, 0, 1);
7546 else
7547 defs[i] = Qnil;
7549 did_meta = 1;
7550 XSETINT (key, XFASTINT (key) & ~CHAR_META);
7553 first_binding = nmaps;
7554 for (i = nmaps - 1; i >= 0; i--)
7556 if (! NILP (current[i]))
7558 Lisp_Object map;
7559 if (did_meta)
7560 map = defs[i];
7561 else
7562 map = current[i];
7564 defs[i] = get_keyelt (access_keymap (map, key, 1, 0), 1);
7565 if (! NILP (defs[i]))
7566 first_binding = i;
7568 else
7569 defs[i] = Qnil;
7572 /* Given the set of bindings we've found, produce the next set of maps. */
7573 if (first_binding < nmaps)
7574 for (i = 0; i < nmaps; i++)
7575 next[i] = NILP (defs[i]) ? Qnil : get_keymap_1 (defs[i], 0, 1);
7577 return first_binding;
7580 /* Read a sequence of keys that ends with a non prefix character,
7581 storing it in KEYBUF, a buffer of size BUFSIZE.
7582 Prompt with PROMPT.
7583 Return the length of the key sequence stored.
7584 Return -1 if the user rejected a command menu.
7586 Echo starting immediately unless `prompt' is 0.
7588 Where a key sequence ends depends on the currently active keymaps.
7589 These include any minor mode keymaps active in the current buffer,
7590 the current buffer's local map, and the global map.
7592 If a key sequence has no other bindings, we check Vfunction_key_map
7593 to see if some trailing subsequence might be the beginning of a
7594 function key's sequence. If so, we try to read the whole function
7595 key, and substitute its symbolic name into the key sequence.
7597 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
7598 `double-' events into similar click events, if that would make them
7599 bound. We try to turn `triple-' events first into `double-' events,
7600 then into clicks.
7602 If we get a mouse click in a mode line, vertical divider, or other
7603 non-text area, we treat the click as if it were prefixed by the
7604 symbol denoting that area - `mode-line', `vertical-line', or
7605 whatever.
7607 If the sequence starts with a mouse click, we read the key sequence
7608 with respect to the buffer clicked on, not the current buffer.
7610 If the user switches frames in the midst of a key sequence, we put
7611 off the switch-frame event until later; the next call to
7612 read_char will return it.
7614 If FIX_CURRENT_BUFFER is nonzero, we restore current_buffer
7615 from the selected window's buffer. */
7617 static int
7618 read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
7619 can_return_switch_frame, fix_current_buffer)
7620 Lisp_Object *keybuf;
7621 int bufsize;
7622 Lisp_Object prompt;
7623 int dont_downcase_last;
7624 int can_return_switch_frame;
7625 int fix_current_buffer;
7627 int count = specpdl_ptr - specpdl;
7629 /* How many keys there are in the current key sequence. */
7630 int t;
7632 /* The length of the echo buffer when we started reading, and
7633 the length of this_command_keys when we started reading. */
7634 int echo_start;
7635 int keys_start;
7637 /* The number of keymaps we're scanning right now, and the number of
7638 keymaps we have allocated space for. */
7639 int nmaps;
7640 int nmaps_allocated = 0;
7642 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
7643 the current keymaps. */
7644 Lisp_Object *defs;
7646 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
7647 in the current keymaps, or nil where it is not a prefix. */
7648 Lisp_Object *submaps;
7650 /* The local map to start out with at start of key sequence. */
7651 Lisp_Object orig_local_map;
7653 /* The map from the `keymap' property to start out with at start of
7654 key sequence. */
7655 Lisp_Object orig_keymap;
7657 /* 1 if we have already considered switching to the local-map property
7658 of the place where a mouse click occurred. */
7659 int localized_local_map = 0;
7661 /* The index in defs[] of the first keymap that has a binding for
7662 this key sequence. In other words, the lowest i such that
7663 defs[i] is non-nil. */
7664 int first_binding;
7666 /* If t < mock_input, then KEYBUF[t] should be read as the next
7667 input key.
7669 We use this to recover after recognizing a function key. Once we
7670 realize that a suffix of the current key sequence is actually a
7671 function key's escape sequence, we replace the suffix with the
7672 function key's binding from Vfunction_key_map. Now keybuf
7673 contains a new and different key sequence, so the echo area,
7674 this_command_keys, and the submaps and defs arrays are wrong. In
7675 this situation, we set mock_input to t, set t to 0, and jump to
7676 restart_sequence; the loop will read keys from keybuf up until
7677 mock_input, thus rebuilding the state; and then it will resume
7678 reading characters from the keyboard. */
7679 int mock_input = 0;
7681 /* If the sequence is unbound in submaps[], then
7682 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
7683 and fkey_map is its binding.
7685 These might be > t, indicating that all function key scanning
7686 should hold off until t reaches them. We do this when we've just
7687 recognized a function key, to avoid searching for the function
7688 key's again in Vfunction_key_map. */
7689 int fkey_start = 0, fkey_end = 0;
7690 Lisp_Object fkey_map;
7692 /* Likewise, for key_translation_map. */
7693 int keytran_start = 0, keytran_end = 0;
7694 Lisp_Object keytran_map;
7696 /* If we receive a ``switch-frame'' event in the middle of a key sequence,
7697 we put it off for later. While we're reading, we keep the event here. */
7698 Lisp_Object delayed_switch_frame;
7700 /* See the comment below... */
7701 #if defined (GOBBLE_FIRST_EVENT)
7702 Lisp_Object first_event;
7703 #endif
7705 Lisp_Object original_uppercase;
7706 int original_uppercase_position = -1;
7708 /* Gets around Microsoft compiler limitations. */
7709 int dummyflag = 0;
7711 struct buffer *starting_buffer;
7713 /* Nonzero if we seem to have got the beginning of a binding
7714 in function_key_map. */
7715 int function_key_possible = 0;
7716 int key_translation_possible = 0;
7718 /* Save the status of key translation before each step,
7719 so that we can restore this after downcasing. */
7720 Lisp_Object prev_fkey_map;
7721 int prev_fkey_start;
7722 int prev_fkey_end;
7724 Lisp_Object prev_keytran_map;
7725 int prev_keytran_start;
7726 int prev_keytran_end;
7728 #if defined (GOBBLE_FIRST_EVENT)
7729 int junk;
7730 #endif
7732 raw_keybuf_count = 0;
7734 last_nonmenu_event = Qnil;
7736 delayed_switch_frame = Qnil;
7737 fkey_map = Vfunction_key_map;
7738 keytran_map = Vkey_translation_map;
7740 /* If there is no function-key-map, turn off function key scanning. */
7741 if (NILP (Fkeymapp (Vfunction_key_map)))
7742 fkey_start = fkey_end = bufsize + 1;
7744 /* If there is no key-translation-map, turn off scanning. */
7745 if (NILP (Fkeymapp (Vkey_translation_map)))
7746 keytran_start = keytran_end = bufsize + 1;
7748 if (INTERACTIVE)
7750 if (!NILP (prompt))
7751 echo_prompt (XSTRING (prompt)->data);
7752 else if (cursor_in_echo_area
7753 && (FLOATP (Vecho_keystrokes) || INTEGERP (Vecho_keystrokes))
7754 && NILP (Fzerop (Vecho_keystrokes)))
7755 /* This doesn't put in a dash if the echo buffer is empty, so
7756 you don't always see a dash hanging out in the minibuffer. */
7757 echo_dash ();
7760 /* Record the initial state of the echo area and this_command_keys;
7761 we will need to restore them if we replay a key sequence. */
7762 if (INTERACTIVE)
7763 echo_start = echo_length ();
7764 keys_start = this_command_key_count;
7765 this_single_command_key_start = keys_start;
7767 #if defined (GOBBLE_FIRST_EVENT)
7768 /* This doesn't quite work, because some of the things that read_char
7769 does cannot safely be bypassed. It seems too risky to try to make
7770 this work right. */
7772 /* Read the first char of the sequence specially, before setting
7773 up any keymaps, in case a filter runs and switches buffers on us. */
7774 first_event = read_char (NILP (prompt), 0, submaps, last_nonmenu_event,
7775 &junk);
7776 #endif /* GOBBLE_FIRST_EVENT */
7778 orig_local_map = get_local_map (PT, current_buffer, local_map);
7779 orig_keymap = get_local_map (PT, current_buffer, keymap);
7781 /* We jump here when the key sequence has been thoroughly changed, and
7782 we need to rescan it starting from the beginning. When we jump here,
7783 keybuf[0..mock_input] holds the sequence we should reread. */
7784 replay_sequence:
7786 starting_buffer = current_buffer;
7787 function_key_possible = 0;
7788 key_translation_possible = 0;
7790 /* Build our list of keymaps.
7791 If we recognize a function key and replace its escape sequence in
7792 keybuf with its symbol, or if the sequence starts with a mouse
7793 click and we need to switch buffers, we jump back here to rebuild
7794 the initial keymaps from the current buffer. */
7796 Lisp_Object *maps;
7798 if (!NILP (current_kboard->Voverriding_terminal_local_map)
7799 || !NILP (Voverriding_local_map))
7801 if (3 > nmaps_allocated)
7803 submaps = (Lisp_Object *) alloca (3 * sizeof (submaps[0]));
7804 defs = (Lisp_Object *) alloca (3 * sizeof (defs[0]));
7805 nmaps_allocated = 3;
7807 nmaps = 0;
7808 if (!NILP (current_kboard->Voverriding_terminal_local_map))
7809 submaps[nmaps++] = current_kboard->Voverriding_terminal_local_map;
7810 if (!NILP (Voverriding_local_map))
7811 submaps[nmaps++] = Voverriding_local_map;
7813 else
7815 int extra_maps = 2;
7816 nmaps = current_minor_maps (0, &maps);
7817 if (!NILP (orig_keymap))
7818 extra_maps = 3;
7819 if (nmaps + extra_maps > nmaps_allocated)
7821 submaps = (Lisp_Object *) alloca ((nmaps+extra_maps)
7822 * sizeof (submaps[0]));
7823 defs = (Lisp_Object *) alloca ((nmaps+extra_maps)
7824 * sizeof (defs[0]));
7825 nmaps_allocated = nmaps + extra_maps;
7827 bcopy (maps, submaps, nmaps * sizeof (submaps[0]));
7828 if (!NILP (orig_keymap))
7829 submaps[nmaps++] = orig_keymap;
7830 submaps[nmaps++] = orig_local_map;
7832 submaps[nmaps++] = current_global_map;
7835 /* Find an accurate initial value for first_binding. */
7836 for (first_binding = 0; first_binding < nmaps; first_binding++)
7837 if (! NILP (submaps[first_binding]))
7838 break;
7840 /* Start from the beginning in keybuf. */
7841 t = 0;
7843 /* These are no-ops the first time through, but if we restart, they
7844 revert the echo area and this_command_keys to their original state. */
7845 this_command_key_count = keys_start;
7846 if (INTERACTIVE && t < mock_input)
7847 echo_truncate (echo_start);
7849 /* If the best binding for the current key sequence is a keymap, or
7850 we may be looking at a function key's escape sequence, keep on
7851 reading. */
7852 while ((first_binding < nmaps && ! NILP (submaps[first_binding]))
7853 || (first_binding >= nmaps
7854 && fkey_start < t
7855 /* mock input is never part of a function key's sequence. */
7856 && mock_input <= fkey_start)
7857 || (first_binding >= nmaps
7858 && keytran_start < t && key_translation_possible)
7859 /* Don't return in the middle of a possible function key sequence,
7860 if the only bindings we found were via case conversion.
7861 Thus, if ESC O a has a function-key-map translation
7862 and ESC o has a binding, don't return after ESC O,
7863 so that we can translate ESC O plus the next character. */
7866 Lisp_Object key;
7867 int used_mouse_menu = 0;
7869 /* Where the last real key started. If we need to throw away a
7870 key that has expanded into more than one element of keybuf
7871 (say, a mouse click on the mode line which is being treated
7872 as [mode-line (mouse-...)], then we backtrack to this point
7873 of keybuf. */
7874 int last_real_key_start;
7876 /* These variables are analogous to echo_start and keys_start;
7877 while those allow us to restart the entire key sequence,
7878 echo_local_start and keys_local_start allow us to throw away
7879 just one key. */
7880 int echo_local_start, keys_local_start, local_first_binding;
7882 if (t >= bufsize)
7883 error ("Key sequence too long");
7885 if (INTERACTIVE)
7886 echo_local_start = echo_length ();
7887 keys_local_start = this_command_key_count;
7888 local_first_binding = first_binding;
7890 replay_key:
7891 /* These are no-ops, unless we throw away a keystroke below and
7892 jumped back up to replay_key; in that case, these restore the
7893 variables to their original state, allowing us to replay the
7894 loop. */
7895 if (INTERACTIVE && t < mock_input)
7896 echo_truncate (echo_local_start);
7897 this_command_key_count = keys_local_start;
7898 first_binding = local_first_binding;
7900 /* By default, assume each event is "real". */
7901 last_real_key_start = t;
7903 /* Does mock_input indicate that we are re-reading a key sequence? */
7904 if (t < mock_input)
7906 key = keybuf[t];
7907 add_command_key (key);
7908 if ((FLOATP (Vecho_keystrokes) || INTEGERP (Vecho_keystrokes))
7909 && NILP (Fzerop (Vecho_keystrokes)))
7910 echo_char (key);
7913 /* If not, we should actually read a character. */
7914 else
7917 #ifdef MULTI_KBOARD
7918 KBOARD *interrupted_kboard = current_kboard;
7919 struct frame *interrupted_frame = SELECTED_FRAME ();
7920 if (setjmp (wrong_kboard_jmpbuf))
7922 if (!NILP (delayed_switch_frame))
7924 interrupted_kboard->kbd_queue
7925 = Fcons (delayed_switch_frame,
7926 interrupted_kboard->kbd_queue);
7927 delayed_switch_frame = Qnil;
7929 while (t > 0)
7930 interrupted_kboard->kbd_queue
7931 = Fcons (keybuf[--t], interrupted_kboard->kbd_queue);
7933 /* If the side queue is non-empty, ensure it begins with a
7934 switch-frame, so we'll replay it in the right context. */
7935 if (CONSP (interrupted_kboard->kbd_queue)
7936 && (key = XCAR (interrupted_kboard->kbd_queue),
7937 !(EVENT_HAS_PARAMETERS (key)
7938 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key)),
7939 Qswitch_frame))))
7941 Lisp_Object frame;
7942 XSETFRAME (frame, interrupted_frame);
7943 interrupted_kboard->kbd_queue
7944 = Fcons (make_lispy_switch_frame (frame),
7945 interrupted_kboard->kbd_queue);
7947 mock_input = 0;
7948 orig_local_map = get_local_map (PT, current_buffer, local_map);
7949 orig_keymap = get_local_map (PT, current_buffer, keymap);
7950 goto replay_sequence;
7952 #endif
7953 key = read_char (NILP (prompt), nmaps, submaps, last_nonmenu_event,
7954 &used_mouse_menu);
7957 /* read_char returns t when it shows a menu and the user rejects it.
7958 Just return -1. */
7959 if (EQ (key, Qt))
7961 unbind_to (count, Qnil);
7962 return -1;
7965 /* read_char returns -1 at the end of a macro.
7966 Emacs 18 handles this by returning immediately with a
7967 zero, so that's what we'll do. */
7968 if (INTEGERP (key) && XINT (key) == -1)
7970 t = 0;
7971 /* The Microsoft C compiler can't handle the goto that
7972 would go here. */
7973 dummyflag = 1;
7974 break;
7977 /* If the current buffer has been changed from under us, the
7978 keymap may have changed, so replay the sequence. */
7979 if (BUFFERP (key))
7981 mock_input = t;
7982 /* Reset the current buffer from the selected window
7983 in case something changed the former and not the latter.
7984 This is to be more consistent with the behavior
7985 of the command_loop_1. */
7986 if (fix_current_buffer)
7988 if (! FRAME_LIVE_P (XFRAME (selected_frame)))
7989 Fkill_emacs (Qnil);
7990 if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer)
7991 Fset_buffer (XWINDOW (selected_window)->buffer);
7994 orig_local_map = get_local_map (PT, current_buffer, local_map);
7995 orig_keymap = get_local_map (PT, current_buffer, keymap);
7996 goto replay_sequence;
7999 /* If we have a quit that was typed in another frame, and
8000 quit_throw_to_read_char switched buffers,
8001 replay to get the right keymap. */
8002 if (XINT (key) == quit_char && current_buffer != starting_buffer)
8004 GROW_RAW_KEYBUF;
8005 XVECTOR (raw_keybuf)->contents[raw_keybuf_count++] = key;
8006 keybuf[t++] = key;
8007 mock_input = t;
8008 Vquit_flag = Qnil;
8009 orig_local_map = get_local_map (PT, current_buffer, local_map);
8010 orig_keymap = get_local_map (PT, current_buffer, keymap);
8011 goto replay_sequence;
8014 Vquit_flag = Qnil;
8016 if (EVENT_HAS_PARAMETERS (key)
8017 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key)), Qswitch_frame))
8019 /* If we're at the beginning of a key sequence, and the caller
8020 says it's okay, go ahead and return this event. If we're
8021 in the midst of a key sequence, delay it until the end. */
8022 if (t > 0 || !can_return_switch_frame)
8024 delayed_switch_frame = key;
8025 goto replay_key;
8029 GROW_RAW_KEYBUF;
8030 XVECTOR (raw_keybuf)->contents[raw_keybuf_count++] = key;
8033 /* Clicks in non-text areas get prefixed by the symbol
8034 in their CHAR-ADDRESS field. For example, a click on
8035 the mode line is prefixed by the symbol `mode-line'.
8037 Furthermore, key sequences beginning with mouse clicks
8038 are read using the keymaps of the buffer clicked on, not
8039 the current buffer. So we may have to switch the buffer
8040 here.
8042 When we turn one event into two events, we must make sure
8043 that neither of the two looks like the original--so that,
8044 if we replay the events, they won't be expanded again.
8045 If not for this, such reexpansion could happen either here
8046 or when user programs play with this-command-keys. */
8047 if (EVENT_HAS_PARAMETERS (key))
8049 Lisp_Object kind;
8051 kind = EVENT_HEAD_KIND (EVENT_HEAD (key));
8052 if (EQ (kind, Qmouse_click))
8054 Lisp_Object window, posn;
8056 window = POSN_WINDOW (EVENT_START (key));
8057 posn = POSN_BUFFER_POSN (EVENT_START (key));
8059 if (CONSP (posn))
8061 /* We're looking at the second event of a
8062 sequence which we expanded before. Set
8063 last_real_key_start appropriately. */
8064 if (t > 0)
8065 last_real_key_start = t - 1;
8068 /* Key sequences beginning with mouse clicks are
8069 read using the keymaps in the buffer clicked on,
8070 not the current buffer. If we're at the
8071 beginning of a key sequence, switch buffers. */
8072 if (last_real_key_start == 0
8073 && WINDOWP (window)
8074 && BUFFERP (XWINDOW (window)->buffer)
8075 && XBUFFER (XWINDOW (window)->buffer) != current_buffer)
8077 XVECTOR (raw_keybuf)->contents[raw_keybuf_count++] = key;
8078 keybuf[t] = key;
8079 mock_input = t + 1;
8081 /* Arrange to go back to the original buffer once we're
8082 done reading the key sequence. Note that we can't
8083 use save_excursion_{save,restore} here, because they
8084 save point as well as the current buffer; we don't
8085 want to save point, because redisplay may change it,
8086 to accommodate a Fset_window_start or something. We
8087 don't want to do this at the top of the function,
8088 because we may get input from a subprocess which
8089 wants to change the selected window and stuff (say,
8090 emacsclient). */
8091 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
8093 if (! FRAME_LIVE_P (XFRAME (selected_frame)))
8094 Fkill_emacs (Qnil);
8095 set_buffer_internal (XBUFFER (XWINDOW
8096 (window)->buffer)
8098 orig_local_map = get_local_map (PT, current_buffer,
8099 local_map);
8100 orig_keymap = get_local_map (PT, current_buffer, keymap);
8101 goto replay_sequence;
8104 /* For a mouse click, get the local text-property keymap
8105 of the place clicked on, rather than point. */
8106 if (last_real_key_start == 0
8107 && CONSP (XCDR (key))
8108 && ! localized_local_map)
8110 Lisp_Object map_here, start, pos;
8112 localized_local_map = 1;
8113 start = EVENT_START (key);
8115 if (CONSP (start) && CONSP (XCDR (start)))
8117 pos = POSN_BUFFER_POSN (start);
8118 if (INTEGERP (pos)
8119 && XINT (pos) >= BEG && XINT (pos) <= Z)
8121 map_here = get_local_map (XINT (pos),
8122 current_buffer, local_map);
8123 if (!EQ (map_here, orig_local_map))
8125 orig_local_map = map_here;
8126 keybuf[t] = key;
8127 mock_input = t + 1;
8129 goto replay_sequence;
8131 map_here = get_local_map (XINT (pos),
8132 current_buffer, keymap);
8133 if (!EQ (map_here, orig_keymap))
8135 orig_keymap = map_here;
8136 keybuf[t] = key;
8137 mock_input = t + 1;
8139 goto replay_sequence;
8145 /* Expand mode-line and scroll-bar events into two events:
8146 use posn as a fake prefix key. */
8147 if (SYMBOLP (posn))
8149 if (t + 1 >= bufsize)
8150 error ("Key sequence too long");
8151 keybuf[t] = posn;
8152 keybuf[t+1] = key;
8153 mock_input = t + 2;
8155 /* Zap the position in key, so we know that we've
8156 expanded it, and don't try to do so again. */
8157 POSN_BUFFER_POSN (EVENT_START (key))
8158 = Fcons (posn, Qnil);
8160 /* If on a mode line string with a local keymap,
8161 reconsider the key sequence with that keymap. */
8162 if (CONSP (POSN_STRING (EVENT_START (key))))
8164 Lisp_Object string, pos, map, map2;
8166 string = POSN_STRING (EVENT_START (key));
8167 pos = XCDR (string);
8168 string = XCAR (string);
8169 if (XINT (pos) >= 0
8170 && XINT (pos) < XSTRING (string)->size)
8172 map = Fget_text_property (pos, Qlocal_map, string);
8173 if (!NILP (map))
8174 orig_local_map = map;
8175 map2 = Fget_text_property (pos, Qkeymap, string);
8176 if (!NILP (map2))
8177 orig_keymap = map2;
8178 if (!NILP (map) || !NILP (map2))
8179 goto replay_sequence;
8183 goto replay_key;
8186 else if (CONSP (XCDR (key))
8187 && CONSP (EVENT_START (key))
8188 && CONSP (XCDR (EVENT_START (key))))
8190 Lisp_Object posn;
8192 posn = POSN_BUFFER_POSN (EVENT_START (key));
8193 /* Handle menu-bar events:
8194 insert the dummy prefix event `menu-bar'. */
8195 if (EQ (posn, Qmenu_bar) || EQ (posn, Qtool_bar))
8197 if (t + 1 >= bufsize)
8198 error ("Key sequence too long");
8199 keybuf[t] = posn;
8200 keybuf[t+1] = key;
8202 /* Zap the position in key, so we know that we've
8203 expanded it, and don't try to do so again. */
8204 POSN_BUFFER_POSN (EVENT_START (key))
8205 = Fcons (posn, Qnil);
8207 mock_input = t + 2;
8208 goto replay_sequence;
8210 else if (CONSP (posn))
8212 /* We're looking at the second event of a
8213 sequence which we expanded before. Set
8214 last_real_key_start appropriately. */
8215 if (last_real_key_start == t && t > 0)
8216 last_real_key_start = t - 1;
8221 /* We have finally decided that KEY is something we might want
8222 to look up. */
8223 first_binding = (follow_key (key,
8224 nmaps - first_binding,
8225 submaps + first_binding,
8226 defs + first_binding,
8227 submaps + first_binding)
8228 + first_binding);
8230 /* If KEY wasn't bound, we'll try some fallbacks. */
8231 if (first_binding >= nmaps)
8233 Lisp_Object head;
8235 head = EVENT_HEAD (key);
8236 if (help_char_p (head) && t > 0)
8238 read_key_sequence_cmd = Vprefix_help_command;
8239 keybuf[t++] = key;
8240 last_nonmenu_event = key;
8241 /* The Microsoft C compiler can't handle the goto that
8242 would go here. */
8243 dummyflag = 1;
8244 break;
8247 if (SYMBOLP (head))
8249 Lisp_Object breakdown;
8250 int modifiers;
8252 breakdown = parse_modifiers (head);
8253 modifiers = XINT (XCAR (XCDR (breakdown)));
8254 /* Attempt to reduce an unbound mouse event to a simpler
8255 event that is bound:
8256 Drags reduce to clicks.
8257 Double-clicks reduce to clicks.
8258 Triple-clicks reduce to double-clicks, then to clicks.
8259 Down-clicks are eliminated.
8260 Double-downs reduce to downs, then are eliminated.
8261 Triple-downs reduce to double-downs, then to downs,
8262 then are eliminated. */
8263 if (modifiers & (down_modifier | drag_modifier
8264 | double_modifier | triple_modifier))
8266 while (modifiers & (down_modifier | drag_modifier
8267 | double_modifier | triple_modifier))
8269 Lisp_Object new_head, new_click;
8270 if (modifiers & triple_modifier)
8271 modifiers ^= (double_modifier | triple_modifier);
8272 else if (modifiers & double_modifier)
8273 modifiers &= ~double_modifier;
8274 else if (modifiers & drag_modifier)
8275 modifiers &= ~drag_modifier;
8276 else
8278 /* Dispose of this `down' event by simply jumping
8279 back to replay_key, to get another event.
8281 Note that if this event came from mock input,
8282 then just jumping back to replay_key will just
8283 hand it to us again. So we have to wipe out any
8284 mock input.
8286 We could delete keybuf[t] and shift everything
8287 after that to the left by one spot, but we'd also
8288 have to fix up any variable that points into
8289 keybuf, and shifting isn't really necessary
8290 anyway.
8292 Adding prefixes for non-textual mouse clicks
8293 creates two characters of mock input, and both
8294 must be thrown away. If we're only looking at
8295 the prefix now, we can just jump back to
8296 replay_key. On the other hand, if we've already
8297 processed the prefix, and now the actual click
8298 itself is giving us trouble, then we've lost the
8299 state of the keymaps we want to backtrack to, and
8300 we need to replay the whole sequence to rebuild
8303 Beyond that, only function key expansion could
8304 create more than two keys, but that should never
8305 generate mouse events, so it's okay to zero
8306 mock_input in that case too.
8308 Isn't this just the most wonderful code ever? */
8309 if (t == last_real_key_start)
8311 mock_input = 0;
8312 goto replay_key;
8314 else
8316 mock_input = last_real_key_start;
8317 goto replay_sequence;
8321 new_head
8322 = apply_modifiers (modifiers, XCAR (breakdown));
8323 new_click
8324 = Fcons (new_head, Fcons (EVENT_START (key), Qnil));
8326 /* Look for a binding for this new key. follow_key
8327 promises that it didn't munge submaps the
8328 last time we called it, since key was unbound. */
8329 first_binding
8330 = (follow_key (new_click,
8331 nmaps - local_first_binding,
8332 submaps + local_first_binding,
8333 defs + local_first_binding,
8334 submaps + local_first_binding)
8335 + local_first_binding);
8337 /* If that click is bound, go for it. */
8338 if (first_binding < nmaps)
8340 key = new_click;
8341 break;
8343 /* Otherwise, we'll leave key set to the drag event. */
8349 keybuf[t++] = key;
8350 /* Normally, last_nonmenu_event gets the previous key we read.
8351 But when a mouse popup menu is being used,
8352 we don't update last_nonmenu_event; it continues to hold the mouse
8353 event that preceded the first level of menu. */
8354 if (!used_mouse_menu)
8355 last_nonmenu_event = key;
8357 /* Record what part of this_command_keys is the current key sequence. */
8358 this_single_command_key_start = this_command_key_count - t;
8360 prev_fkey_map = fkey_map;
8361 prev_fkey_start = fkey_start;
8362 prev_fkey_end = fkey_end;
8364 prev_keytran_map = keytran_map;
8365 prev_keytran_start = keytran_start;
8366 prev_keytran_end = keytran_end;
8368 /* If the sequence is unbound, see if we can hang a function key
8369 off the end of it. We only want to scan real keyboard input
8370 for function key sequences, so if mock_input says that we're
8371 re-reading old events, don't examine it. */
8372 if (first_binding >= nmaps
8373 && t >= mock_input)
8375 Lisp_Object fkey_next;
8377 /* Continue scan from fkey_end until we find a bound suffix.
8378 If we fail, increment fkey_start
8379 and start fkey_end from there. */
8380 while (fkey_end < t)
8382 Lisp_Object key;
8384 key = keybuf[fkey_end++];
8385 /* Look up meta-characters by prefixing them
8386 with meta_prefix_char. I hate this. */
8387 if (INTEGERP (key) && XUINT (key) & meta_modifier)
8389 fkey_next
8390 = get_keymap_1
8391 (get_keyelt
8392 (access_keymap (fkey_map, meta_prefix_char, 1, 0), 0),
8393 0, 1);
8394 XSETFASTINT (key, XFASTINT (key) & ~meta_modifier);
8396 else
8397 fkey_next = fkey_map;
8399 fkey_next
8400 = get_keyelt (access_keymap (fkey_next, key, 1, 0), 1);
8402 /* Handle symbol with autoload definition. */
8403 if (SYMBOLP (fkey_next) && ! NILP (Ffboundp (fkey_next))
8404 && CONSP (XSYMBOL (fkey_next)->function)
8405 && EQ (XCAR (XSYMBOL (fkey_next)->function), Qautoload))
8406 do_autoload (XSYMBOL (fkey_next)->function,
8407 fkey_next);
8409 /* Handle a symbol whose function definition is a keymap
8410 or an array. */
8411 if (SYMBOLP (fkey_next) && ! NILP (Ffboundp (fkey_next))
8412 && (!NILP (Farrayp (XSYMBOL (fkey_next)->function))
8413 || !NILP (Fkeymapp (XSYMBOL (fkey_next)->function))))
8414 fkey_next = XSYMBOL (fkey_next)->function;
8416 #if 0 /* I didn't turn this on, because it might cause trouble
8417 for the mapping of return into C-m and tab into C-i. */
8418 /* Optionally don't map function keys into other things.
8419 This enables the user to redefine kp- keys easily. */
8420 if (SYMBOLP (key) && !NILP (Vinhibit_function_key_mapping))
8421 fkey_next = Qnil;
8422 #endif
8424 /* If the function key map gives a function, not an
8425 array, then call the function with no args and use
8426 its value instead. */
8427 if (SYMBOLP (fkey_next) && ! NILP (Ffboundp (fkey_next))
8428 && fkey_end == t)
8430 struct gcpro gcpro1, gcpro2, gcpro3;
8431 Lisp_Object tem;
8432 tem = fkey_next;
8434 GCPRO3 (fkey_map, keytran_map, delayed_switch_frame);
8435 fkey_next = call1 (fkey_next, prompt);
8436 UNGCPRO;
8437 /* If the function returned something invalid,
8438 barf--don't ignore it.
8439 (To ignore it safely, we would need to gcpro a bunch of
8440 other variables.) */
8441 if (! (VECTORP (fkey_next) || STRINGP (fkey_next)))
8442 error ("Function in key-translation-map returns invalid key sequence");
8445 function_key_possible = ! NILP (fkey_next);
8447 /* If keybuf[fkey_start..fkey_end] is bound in the
8448 function key map and it's a suffix of the current
8449 sequence (i.e. fkey_end == t), replace it with
8450 the binding and restart with fkey_start at the end. */
8451 if ((VECTORP (fkey_next) || STRINGP (fkey_next))
8452 && fkey_end == t)
8454 int len = XFASTINT (Flength (fkey_next));
8456 t = fkey_start + len;
8457 if (t >= bufsize)
8458 error ("Key sequence too long");
8460 if (VECTORP (fkey_next))
8461 bcopy (XVECTOR (fkey_next)->contents,
8462 keybuf + fkey_start,
8463 (t - fkey_start) * sizeof (keybuf[0]));
8464 else if (STRINGP (fkey_next))
8466 int i;
8468 for (i = 0; i < len; i++)
8469 XSETFASTINT (keybuf[fkey_start + i],
8470 XSTRING (fkey_next)->data[i]);
8473 mock_input = t;
8474 fkey_start = fkey_end = t;
8475 fkey_map = Vfunction_key_map;
8477 /* Do pass the results through key-translation-map.
8478 But don't retranslate what key-translation-map
8479 has already translated. */
8480 keytran_end = keytran_start;
8481 keytran_map = Vkey_translation_map;
8483 goto replay_sequence;
8486 fkey_map = get_keymap_1 (fkey_next, 0, 1);
8488 /* If we no longer have a bound suffix, try a new positions for
8489 fkey_start. */
8490 if (NILP (fkey_map))
8492 fkey_end = ++fkey_start;
8493 fkey_map = Vfunction_key_map;
8494 function_key_possible = 0;
8499 /* Look for this sequence in key-translation-map. */
8501 Lisp_Object keytran_next;
8503 /* Scan from keytran_end until we find a bound suffix. */
8504 while (keytran_end < t)
8506 Lisp_Object key;
8508 key = keybuf[keytran_end++];
8509 /* Look up meta-characters by prefixing them
8510 with meta_prefix_char. I hate this. */
8511 if (INTEGERP (key) && XUINT (key) & meta_modifier)
8513 keytran_next
8514 = get_keymap_1
8515 (get_keyelt
8516 (access_keymap (keytran_map, meta_prefix_char, 1, 0), 0),
8517 0, 1);
8518 XSETFASTINT (key, XFASTINT (key) & ~meta_modifier);
8520 else
8521 keytran_next = keytran_map;
8523 keytran_next
8524 = get_keyelt (access_keymap (keytran_next, key, 1, 0), 1);
8526 /* Handle symbol with autoload definition. */
8527 if (SYMBOLP (keytran_next) && ! NILP (Ffboundp (keytran_next))
8528 && CONSP (XSYMBOL (keytran_next)->function)
8529 && EQ (XCAR (XSYMBOL (keytran_next)->function), Qautoload))
8530 do_autoload (XSYMBOL (keytran_next)->function,
8531 keytran_next);
8533 /* Handle a symbol whose function definition is a keymap
8534 or an array. */
8535 if (SYMBOLP (keytran_next) && ! NILP (Ffboundp (keytran_next))
8536 && (!NILP (Farrayp (XSYMBOL (keytran_next)->function))
8537 || !NILP (Fkeymapp (XSYMBOL (keytran_next)->function))))
8538 keytran_next = XSYMBOL (keytran_next)->function;
8540 /* If the key translation map gives a function, not an
8541 array, then call the function with one arg and use
8542 its value instead. */
8543 if (SYMBOLP (keytran_next) && ! NILP (Ffboundp (keytran_next))
8544 && keytran_end == t)
8546 struct gcpro gcpro1, gcpro2, gcpro3;
8547 Lisp_Object tem;
8548 tem = keytran_next;
8550 GCPRO3 (fkey_map, keytran_map, delayed_switch_frame);
8551 keytran_next = call1 (keytran_next, prompt);
8552 UNGCPRO;
8553 /* If the function returned something invalid,
8554 barf--don't ignore it.
8555 (To ignore it safely, we would need to gcpro a bunch of
8556 other variables.) */
8557 if (! (VECTORP (keytran_next) || STRINGP (keytran_next)))
8558 error ("Function in key-translation-map returns invalid key sequence");
8561 key_translation_possible = ! NILP (keytran_next);
8563 /* If keybuf[keytran_start..keytran_end] is bound in the
8564 key translation map and it's a suffix of the current
8565 sequence (i.e. keytran_end == t), replace it with
8566 the binding and restart with keytran_start at the end. */
8567 if ((VECTORP (keytran_next) || STRINGP (keytran_next))
8568 && keytran_end == t)
8570 int len = XFASTINT (Flength (keytran_next));
8572 t = keytran_start + len;
8573 if (t >= bufsize)
8574 error ("Key sequence too long");
8576 if (VECTORP (keytran_next))
8577 bcopy (XVECTOR (keytran_next)->contents,
8578 keybuf + keytran_start,
8579 (t - keytran_start) * sizeof (keybuf[0]));
8580 else if (STRINGP (keytran_next))
8582 int i;
8584 for (i = 0; i < len; i++)
8585 XSETFASTINT (keybuf[keytran_start + i],
8586 XSTRING (keytran_next)->data[i]);
8589 mock_input = t;
8590 keytran_start = keytran_end = t;
8591 keytran_map = Vkey_translation_map;
8593 /* Don't pass the results of key-translation-map
8594 through function-key-map. */
8595 fkey_start = fkey_end = t;
8596 fkey_map = Vfunction_key_map;
8598 goto replay_sequence;
8601 keytran_map = get_keymap_1 (keytran_next, 0, 1);
8603 /* If we no longer have a bound suffix, try a new positions for
8604 keytran_start. */
8605 if (NILP (keytran_map))
8607 keytran_end = ++keytran_start;
8608 keytran_map = Vkey_translation_map;
8609 key_translation_possible = 0;
8614 /* If KEY is not defined in any of the keymaps,
8615 and cannot be part of a function key or translation,
8616 and is an upper case letter
8617 use the corresponding lower-case letter instead. */
8618 if (first_binding == nmaps && ! function_key_possible
8619 && ! key_translation_possible
8620 && INTEGERP (key)
8621 && ((((XINT (key) & 0x3ffff)
8622 < XCHAR_TABLE (current_buffer->downcase_table)->size)
8623 && UPPERCASEP (XINT (key) & 0x3ffff))
8624 || (XINT (key) & shift_modifier)))
8626 Lisp_Object new_key;
8628 original_uppercase = key;
8629 original_uppercase_position = t - 1;
8631 if (XINT (key) & shift_modifier)
8632 XSETINT (new_key, XINT (key) & ~shift_modifier);
8633 else
8634 XSETINT (new_key, (DOWNCASE (XINT (key) & 0x3ffff)
8635 | (XINT (key) & ~0x3ffff)));
8637 /* We have to do this unconditionally, regardless of whether
8638 the lower-case char is defined in the keymaps, because they
8639 might get translated through function-key-map. */
8640 keybuf[t - 1] = new_key;
8641 mock_input = t;
8643 fkey_map = prev_fkey_map;
8644 fkey_start = prev_fkey_start;
8645 fkey_end = prev_fkey_end;
8647 keytran_map = prev_keytran_map;
8648 keytran_start = prev_keytran_start;
8649 keytran_end = prev_keytran_end;
8651 goto replay_sequence;
8653 /* If KEY is not defined in any of the keymaps,
8654 and cannot be part of a function key or translation,
8655 and is a shifted function key,
8656 use the corresponding unshifted function key instead. */
8657 if (first_binding == nmaps && ! function_key_possible
8658 && ! key_translation_possible
8659 && SYMBOLP (key))
8661 Lisp_Object breakdown;
8662 int modifiers;
8664 breakdown = parse_modifiers (key);
8665 modifiers = XINT (XCAR (XCDR (breakdown)));
8666 if (modifiers & shift_modifier)
8668 Lisp_Object new_key;
8670 original_uppercase = key;
8671 original_uppercase_position = t - 1;
8673 modifiers &= ~shift_modifier;
8674 new_key = apply_modifiers (modifiers,
8675 XCAR (breakdown));
8677 keybuf[t - 1] = new_key;
8678 mock_input = t;
8680 fkey_map = prev_fkey_map;
8681 fkey_start = prev_fkey_start;
8682 fkey_end = prev_fkey_end;
8684 keytran_map = prev_keytran_map;
8685 keytran_start = prev_keytran_start;
8686 keytran_end = prev_keytran_end;
8688 goto replay_sequence;
8693 if (!dummyflag)
8694 read_key_sequence_cmd = (first_binding < nmaps
8695 ? defs[first_binding]
8696 : Qnil);
8698 unread_switch_frame = delayed_switch_frame;
8699 unbind_to (count, Qnil);
8701 /* Don't downcase the last character if the caller says don't.
8702 Don't downcase it if the result is undefined, either. */
8703 if ((dont_downcase_last || first_binding >= nmaps)
8704 && t - 1 == original_uppercase_position)
8705 keybuf[t - 1] = original_uppercase;
8707 /* Occasionally we fabricate events, perhaps by expanding something
8708 according to function-key-map, or by adding a prefix symbol to a
8709 mouse click in the scroll bar or modeline. In this cases, return
8710 the entire generated key sequence, even if we hit an unbound
8711 prefix or a definition before the end. This means that you will
8712 be able to push back the event properly, and also means that
8713 read-key-sequence will always return a logical unit.
8715 Better ideas? */
8716 for (; t < mock_input; t++)
8718 if ((FLOATP (Vecho_keystrokes) || INTEGERP (Vecho_keystrokes))
8719 && NILP (Fzerop (Vecho_keystrokes)))
8720 echo_char (keybuf[t]);
8721 add_command_key (keybuf[t]);
8726 return t;
8729 #if 0 /* This doc string is too long for some compilers.
8730 This commented-out definition serves for DOC. */
8731 DEFUN ("read-key-sequence", Fread_key_sequence, Sread_key_sequence, 1, 4, 0,
8732 "Read a sequence of keystrokes and return as a string or vector.\n\
8733 The sequence is sufficient to specify a non-prefix command in the\n\
8734 current local and global maps.\n\
8736 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
8737 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
8738 as a continuation of the previous key.\n\
8740 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not\n\
8741 convert the last event to lower case. (Normally any upper case event\n\
8742 is converted to lower case if the original event is undefined and the lower\n\
8743 case equivalent is defined.) A non-nil value is appropriate for reading\n\
8744 a key sequence to be defined.\n\
8746 A C-g typed while in this function is treated like any other character,\n\
8747 and `quit-flag' is not set.\n\
8749 If the key sequence starts with a mouse click, then the sequence is read\n\
8750 using the keymaps of the buffer of the window clicked in, not the buffer\n\
8751 of the selected window as normal.\n\
8752 ""\n\
8753 `read-key-sequence' drops unbound button-down events, since you normally\n\
8754 only care about the click or drag events which follow them. If a drag\n\
8755 or multi-click event is unbound, but the corresponding click event would\n\
8756 be bound, `read-key-sequence' turns the event into a click event at the\n\
8757 drag's starting position. This means that you don't have to distinguish\n\
8758 between click and drag, double, or triple events unless you want to.\n\
8760 `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\
8761 lines separating windows, and scroll bars with imaginary keys\n\
8762 `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\
8764 Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this\n\
8765 function will process a switch-frame event if the user switches frames\n\
8766 before typing anything. If the user switches frames in the middle of a\n\
8767 key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME\n\
8768 is nil, then the event will be put off until after the current key sequence.\n\
8770 `read-key-sequence' checks `function-key-map' for function key\n\
8771 sequences, where they wouldn't conflict with ordinary bindings. See\n\
8772 `function-key-map' for more details.\n\
8774 The optional fifth argument COMMAND-LOOP, if non-nil, means\n\
8775 that this key sequence is being read by something that will\n\
8776 read commands one after another. It should be nil if the caller\n\
8777 will read just one key sequence.")
8778 (prompt, continue_echo, dont_downcase_last, can_return_switch_frame, command-loop)
8779 #endif
8781 DEFUN ("read-key-sequence", Fread_key_sequence, Sread_key_sequence, 1, 5, 0,
8783 (prompt, continue_echo, dont_downcase_last, can_return_switch_frame,
8784 command_loop)
8785 Lisp_Object prompt, continue_echo, dont_downcase_last;
8786 Lisp_Object can_return_switch_frame, command_loop;
8788 Lisp_Object keybuf[30];
8789 register int i;
8790 struct gcpro gcpro1;
8791 int count = specpdl_ptr - specpdl;
8793 if (!NILP (prompt))
8794 CHECK_STRING (prompt, 0);
8795 QUIT;
8797 specbind (Qinput_method_exit_on_first_char,
8798 (NILP (command_loop) ? Qt : Qnil));
8799 specbind (Qinput_method_use_echo_area,
8800 (NILP (command_loop) ? Qt : Qnil));
8802 bzero (keybuf, sizeof keybuf);
8803 GCPRO1 (keybuf[0]);
8804 gcpro1.nvars = (sizeof keybuf/sizeof (keybuf[0]));
8806 if (NILP (continue_echo))
8808 this_command_key_count = 0;
8809 this_single_command_key_start = 0;
8812 #ifdef HAVE_X_WINDOWS
8813 if (display_busy_cursor_p)
8814 cancel_busy_cursor ();
8815 #endif
8817 i = read_key_sequence (keybuf, (sizeof keybuf/sizeof (keybuf[0])),
8818 prompt, ! NILP (dont_downcase_last),
8819 ! NILP (can_return_switch_frame), 0);
8821 #ifdef HAVE_X_WINDOWS
8822 if (display_busy_cursor_p)
8823 start_busy_cursor ();
8824 #endif
8826 if (i == -1)
8828 Vquit_flag = Qt;
8829 QUIT;
8831 UNGCPRO;
8832 return unbind_to (count, make_event_array (i, keybuf));
8835 DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector,
8836 Sread_key_sequence_vector, 1, 5, 0,
8837 "Like `read-key-sequence' but always return a vector.")
8838 (prompt, continue_echo, dont_downcase_last, can_return_switch_frame,
8839 command_loop)
8840 Lisp_Object prompt, continue_echo, dont_downcase_last;
8841 Lisp_Object can_return_switch_frame, command_loop;
8843 Lisp_Object keybuf[30];
8844 register int i;
8845 struct gcpro gcpro1;
8846 int count = specpdl_ptr - specpdl;
8848 if (!NILP (prompt))
8849 CHECK_STRING (prompt, 0);
8850 QUIT;
8852 specbind (Qinput_method_exit_on_first_char,
8853 (NILP (command_loop) ? Qt : Qnil));
8854 specbind (Qinput_method_use_echo_area,
8855 (NILP (command_loop) ? Qt : Qnil));
8857 bzero (keybuf, sizeof keybuf);
8858 GCPRO1 (keybuf[0]);
8859 gcpro1.nvars = (sizeof keybuf/sizeof (keybuf[0]));
8861 if (NILP (continue_echo))
8863 this_command_key_count = 0;
8864 this_single_command_key_start = 0;
8867 #ifdef HAVE_X_WINDOWS
8868 if (display_busy_cursor_p)
8869 cancel_busy_cursor ();
8870 #endif
8872 i = read_key_sequence (keybuf, (sizeof keybuf/sizeof (keybuf[0])),
8873 prompt, ! NILP (dont_downcase_last),
8874 ! NILP (can_return_switch_frame), 0);
8876 #ifdef HAVE_X_WINDOWS
8877 if (display_busy_cursor_p)
8878 start_busy_cursor ();
8879 #endif
8881 if (i == -1)
8883 Vquit_flag = Qt;
8884 QUIT;
8886 UNGCPRO;
8887 return unbind_to (count, Fvector (i, keybuf));
8890 DEFUN ("command-execute", Fcommand_execute, Scommand_execute, 1, 4, 0,
8891 "Execute CMD as an editor command.\n\
8892 CMD must be a symbol that satisfies the `commandp' predicate.\n\
8893 Optional second arg RECORD-FLAG non-nil\n\
8894 means unconditionally put this command in `command-history'.\n\
8895 Otherwise, that is done only if an arg is read using the minibuffer.\n\
8896 The argument KEYS specifies the value to use instead of (this-command-keys)\n\
8897 when reading the arguments; if it is nil, (this-command-keys) is used.\n\
8898 The argument SPECIAL, if non-nil, means that this command is executing\n\
8899 a special event, so ignore the prefix argument and don't clear it.")
8900 (cmd, record_flag, keys, special)
8901 Lisp_Object cmd, record_flag, keys, special;
8903 register Lisp_Object final;
8904 register Lisp_Object tem;
8905 Lisp_Object prefixarg;
8906 struct backtrace backtrace;
8907 extern int debug_on_next_call;
8909 debug_on_next_call = 0;
8911 if (NILP (special))
8913 prefixarg = current_kboard->Vprefix_arg;
8914 Vcurrent_prefix_arg = prefixarg;
8915 current_kboard->Vprefix_arg = Qnil;
8917 else
8918 prefixarg = Qnil;
8920 if (SYMBOLP (cmd))
8922 tem = Fget (cmd, Qdisabled);
8923 if (!NILP (tem) && !NILP (Vrun_hooks))
8925 tem = Fsymbol_value (Qdisabled_command_hook);
8926 if (!NILP (tem))
8927 return call1 (Vrun_hooks, Qdisabled_command_hook);
8931 while (1)
8933 final = Findirect_function (cmd);
8935 if (CONSP (final) && (tem = Fcar (final), EQ (tem, Qautoload)))
8937 struct gcpro gcpro1, gcpro2;
8939 GCPRO2 (cmd, prefixarg);
8940 do_autoload (final, cmd);
8941 UNGCPRO;
8943 else
8944 break;
8947 if (STRINGP (final) || VECTORP (final))
8949 /* If requested, place the macro in the command history. For
8950 other sorts of commands, call-interactively takes care of
8951 this. */
8952 if (!NILP (record_flag))
8954 Vcommand_history
8955 = Fcons (Fcons (Qexecute_kbd_macro,
8956 Fcons (final, Fcons (prefixarg, Qnil))),
8957 Vcommand_history);
8959 /* Don't keep command history around forever. */
8960 if (NUMBERP (Vhistory_length) && XINT (Vhistory_length) > 0)
8962 tem = Fnthcdr (Vhistory_length, Vcommand_history);
8963 if (CONSP (tem))
8964 XCDR (tem) = Qnil;
8968 return Fexecute_kbd_macro (final, prefixarg);
8971 if (CONSP (final) || SUBRP (final) || COMPILEDP (final))
8973 backtrace.next = backtrace_list;
8974 backtrace_list = &backtrace;
8975 backtrace.function = &Qcall_interactively;
8976 backtrace.args = &cmd;
8977 backtrace.nargs = 1;
8978 backtrace.evalargs = 0;
8980 tem = Fcall_interactively (cmd, record_flag, keys);
8982 backtrace_list = backtrace.next;
8983 return tem;
8985 return Qnil;
8988 DEFUN ("execute-extended-command", Fexecute_extended_command, Sexecute_extended_command,
8989 1, 1, "P",
8990 "Read function name, then read its arguments and call it.")
8991 (prefixarg)
8992 Lisp_Object prefixarg;
8994 Lisp_Object function;
8995 char buf[40];
8996 Lisp_Object saved_keys;
8997 Lisp_Object bindings, value;
8998 struct gcpro gcpro1, gcpro2;
9000 saved_keys = Fvector (this_command_key_count,
9001 XVECTOR (this_command_keys)->contents);
9002 buf[0] = 0;
9003 GCPRO2 (saved_keys, prefixarg);
9005 if (EQ (prefixarg, Qminus))
9006 strcpy (buf, "- ");
9007 else if (CONSP (prefixarg) && XINT (XCAR (prefixarg)) == 4)
9008 strcpy (buf, "C-u ");
9009 else if (CONSP (prefixarg) && INTEGERP (XCAR (prefixarg)))
9011 if (sizeof (int) == sizeof (EMACS_INT))
9012 sprintf (buf, "%d ", XINT (XCAR (prefixarg)));
9013 else if (sizeof (long) == sizeof (EMACS_INT))
9014 sprintf (buf, "%ld ", (long) XINT (XCAR (prefixarg)));
9015 else
9016 abort ();
9018 else if (INTEGERP (prefixarg))
9020 if (sizeof (int) == sizeof (EMACS_INT))
9021 sprintf (buf, "%d ", XINT (prefixarg));
9022 else if (sizeof (long) == sizeof (EMACS_INT))
9023 sprintf (buf, "%ld ", (long) XINT (prefixarg));
9024 else
9025 abort ();
9028 /* This isn't strictly correct if execute-extended-command
9029 is bound to anything else. Perhaps it should use
9030 this_command_keys? */
9031 strcat (buf, "M-x ");
9033 /* Prompt with buf, and then read a string, completing from and
9034 restricting to the set of all defined commands. Don't provide
9035 any initial input. Save the command read on the extended-command
9036 history list. */
9037 function = Fcompleting_read (build_string (buf),
9038 Vobarray, Qcommandp,
9039 Qt, Qnil, Qextended_command_history, Qnil,
9040 Qnil);
9042 if (STRINGP (function) && XSTRING (function)->size == 0)
9043 error ("No command name given");
9045 /* Set this_command_keys to the concatenation of saved_keys and
9046 function, followed by a RET. */
9048 struct Lisp_String *str;
9049 Lisp_Object *keys;
9050 int i;
9052 this_command_key_count = 0;
9053 this_single_command_key_start = 0;
9055 keys = XVECTOR (saved_keys)->contents;
9056 for (i = 0; i < XVECTOR (saved_keys)->size; i++)
9057 add_command_key (keys[i]);
9059 str = XSTRING (function);
9060 for (i = 0; i < str->size; i++)
9061 add_command_key (Faref (function, make_number (i)));
9063 add_command_key (make_number ('\015'));
9066 UNGCPRO;
9068 function = Fintern (function, Qnil);
9069 current_kboard->Vprefix_arg = prefixarg;
9070 Vthis_command = function;
9071 real_this_command = function;
9073 /* If enabled, show which key runs this command. */
9074 if (!NILP (Vsuggest_key_bindings)
9075 && NILP (Vexecuting_macro)
9076 && SYMBOLP (function))
9077 bindings = Fwhere_is_internal (function, Voverriding_local_map,
9078 Qt, Qnil);
9079 else
9080 bindings = Qnil;
9082 value = Qnil;
9083 GCPRO2 (bindings, value);
9084 value = Fcommand_execute (function, Qt, Qnil, Qnil);
9086 /* If the command has a key binding, print it now. */
9087 if (!NILP (bindings)
9088 && ! (VECTORP (bindings) && EQ (Faref (bindings, make_number (0)),
9089 Qmouse_movement)))
9091 /* But first wait, and skip the message if there is input. */
9092 int delay_time;
9093 if (!NILP (echo_area_buffer[0]))
9094 /* This command displayed something in the echo area;
9095 so wait a few seconds, then display our suggestion message. */
9096 delay_time = (NUMBERP (Vsuggest_key_bindings)
9097 ? XINT (Vsuggest_key_bindings) : 2);
9098 else
9099 /* This command left the echo area empty,
9100 so display our message immediately. */
9101 delay_time = 0;
9103 if (!NILP (Fsit_for (make_number (delay_time), Qnil, Qnil))
9104 && ! CONSP (Vunread_command_events))
9106 Lisp_Object binding;
9107 char *newmessage;
9108 int message_p = push_message ();
9110 binding = Fkey_description (bindings);
9112 newmessage
9113 = (char *) alloca (XSYMBOL (function)->name->size
9114 + STRING_BYTES (XSTRING (binding))
9115 + 100);
9116 sprintf (newmessage, "You can run the command `%s' with %s",
9117 XSYMBOL (function)->name->data,
9118 XSTRING (binding)->data);
9119 message2_nolog (newmessage,
9120 strlen (newmessage),
9121 STRING_MULTIBYTE (binding));
9122 if (!NILP (Fsit_for ((NUMBERP (Vsuggest_key_bindings)
9123 ? Vsuggest_key_bindings : make_number (2)),
9124 Qnil, Qnil))
9125 && message_p)
9126 restore_message ();
9128 pop_message ();
9132 RETURN_UNGCPRO (value);
9135 /* Find the set of keymaps now active.
9136 Store into *MAPS_P a vector holding the various maps
9137 and return the number of them. The vector was malloc'd
9138 and the caller should free it. */
9141 current_active_maps (maps_p)
9142 Lisp_Object **maps_p;
9144 Lisp_Object *tmaps, *maps;
9145 int nmaps;
9147 /* Should overriding-terminal-local-map and overriding-local-map apply? */
9148 if (!NILP (Voverriding_local_map_menu_flag))
9150 /* Yes, use them (if non-nil) as well as the global map. */
9151 maps = (Lisp_Object *) xmalloc (3 * sizeof (maps[0]));
9152 nmaps = 0;
9153 if (!NILP (current_kboard->Voverriding_terminal_local_map))
9154 maps[nmaps++] = current_kboard->Voverriding_terminal_local_map;
9155 if (!NILP (Voverriding_local_map))
9156 maps[nmaps++] = Voverriding_local_map;
9158 else
9160 /* No, so use major and minor mode keymaps and keymap property. */
9161 int extra_maps = 2;
9162 Lisp_Object map = get_local_map (PT, current_buffer, keymap);
9163 if (!NILP (map))
9164 extra_maps = 3;
9165 nmaps = current_minor_maps (NULL, &tmaps);
9166 maps = (Lisp_Object *) alloca ((nmaps + extra_maps)
9167 * sizeof (maps[0]));
9168 bcopy (tmaps, maps, nmaps * sizeof (maps[0]));
9169 if (!NILP (map))
9170 maps[nmaps++] = get_local_map (PT, current_buffer, keymap);
9171 maps[nmaps++] = get_local_map (PT, current_buffer, local_map);
9173 maps[nmaps++] = current_global_map;
9175 *maps_p = maps;
9176 return nmaps;
9179 /* Return nonzero if input events are pending. */
9182 detect_input_pending ()
9184 if (!input_pending)
9185 get_input_pending (&input_pending, 0);
9187 return input_pending;
9190 /* Return nonzero if input events are pending, and run any pending timers. */
9193 detect_input_pending_run_timers (do_display)
9194 int do_display;
9196 int old_timers_run = timers_run;
9198 if (!input_pending)
9199 get_input_pending (&input_pending, 1);
9201 if (old_timers_run != timers_run && do_display)
9203 redisplay_preserve_echo_area ();
9204 /* The following fixes a bug when using lazy-lock with
9205 lazy-lock-defer-on-the-fly set to t, i.e. when fontifying
9206 from an idle timer function. The symptom of the bug is that
9207 the cursor sometimes doesn't become visible until the next X
9208 event is processed. --gerd. */
9209 if (rif)
9210 rif->flush_display (NULL);
9213 return input_pending;
9216 /* This is called in some cases before a possible quit.
9217 It cases the next call to detect_input_pending to recompute input_pending.
9218 So calling this function unnecessarily can't do any harm. */
9220 void
9221 clear_input_pending ()
9223 input_pending = 0;
9226 /* Return nonzero if there are pending requeued events.
9227 This isn't used yet. The hope is to make wait_reading_process_input
9228 call it, and return return if it runs Lisp code that unreads something.
9229 The problem is, kbd_buffer_get_event needs to be fixed to know what
9230 to do in that case. It isn't trivial. */
9233 requeued_events_pending_p ()
9235 return (!NILP (Vunread_command_events) || unread_command_char != -1);
9239 DEFUN ("input-pending-p", Finput_pending_p, Sinput_pending_p, 0, 0, 0,
9240 "T if command input is currently available with no waiting.\n\
9241 Actually, the value is nil only if we can be sure that no input is available.")
9244 if (!NILP (Vunread_command_events) || unread_command_char != -1)
9245 return (Qt);
9247 get_input_pending (&input_pending, 1);
9248 return input_pending > 0 ? Qt : Qnil;
9251 DEFUN ("recent-keys", Frecent_keys, Srecent_keys, 0, 0, 0,
9252 "Return vector of last 100 events, not counting those from keyboard macros.")
9255 Lisp_Object *keys = XVECTOR (recent_keys)->contents;
9256 Lisp_Object val;
9258 if (total_keys < NUM_RECENT_KEYS)
9259 return Fvector (total_keys, keys);
9260 else
9262 val = Fvector (NUM_RECENT_KEYS, keys);
9263 bcopy (keys + recent_keys_index,
9264 XVECTOR (val)->contents,
9265 (NUM_RECENT_KEYS - recent_keys_index) * sizeof (Lisp_Object));
9266 bcopy (keys,
9267 XVECTOR (val)->contents + NUM_RECENT_KEYS - recent_keys_index,
9268 recent_keys_index * sizeof (Lisp_Object));
9269 return val;
9273 DEFUN ("this-command-keys", Fthis_command_keys, Sthis_command_keys, 0, 0, 0,
9274 "Return the key sequence that invoked this command.\n\
9275 The value is a string or a vector.")
9278 return make_event_array (this_command_key_count,
9279 XVECTOR (this_command_keys)->contents);
9282 DEFUN ("this-command-keys-vector", Fthis_command_keys_vector, Sthis_command_keys_vector, 0, 0, 0,
9283 "Return the key sequence that invoked this command, as a vector.")
9286 return Fvector (this_command_key_count,
9287 XVECTOR (this_command_keys)->contents);
9290 DEFUN ("this-single-command-keys", Fthis_single_command_keys,
9291 Sthis_single_command_keys, 0, 0, 0,
9292 "Return the key sequence that invoked this command.\n\
9293 Unlike `this-command-keys', this function's value\n\
9294 does not include prefix arguments.\n\
9295 The value is always a vector.")
9298 return Fvector (this_command_key_count
9299 - this_single_command_key_start,
9300 (XVECTOR (this_command_keys)->contents
9301 + this_single_command_key_start));
9304 DEFUN ("this-single-command-raw-keys", Fthis_single_command_raw_keys,
9305 Sthis_single_command_raw_keys, 0, 0, 0,
9306 "Return the raw events that were read for this command.\n\
9307 Unlike `this-single-command-keys', this function's value\n\
9308 shows the events before all translations (except for input methods).\n\
9309 The value is always a vector.")
9312 return Fvector (raw_keybuf_count,
9313 (XVECTOR (raw_keybuf)->contents));
9316 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths,
9317 Sreset_this_command_lengths, 0, 0, 0,
9318 "Used for complicated reasons in `universal-argument-other-key'.\n\
9320 `universal-argument-other-key' rereads the event just typed.\n\
9321 It then gets translated through `function-key-map'.\n\
9322 The translated event gets included in the echo area and in\n\
9323 the value of `this-command-keys' in addition to the raw original event.\n\
9324 That is not right.\n\
9326 Calling this function directs the translated event to replace\n\
9327 the original event, so that only one version of the event actually\n\
9328 appears in the echo area and in the value of `this-command-keys.'.")
9331 before_command_restore_flag = 1;
9332 before_command_key_count_1 = before_command_key_count;
9333 before_command_echo_length_1 = before_command_echo_length;
9334 return Qnil;
9337 DEFUN ("clear-this-command-keys", Fclear_this_command_keys,
9338 Sclear_this_command_keys, 0, 0, 0,
9339 "Clear out the vector that `this-command-keys' returns.\n\
9340 Clear vector containing last 100 events.")
9343 int i;
9345 this_command_key_count = 0;
9347 for (i = 0; i < XVECTOR (recent_keys)->size; ++i)
9348 XVECTOR (recent_keys)->contents[i] = Qnil;
9349 total_keys = 0;
9350 recent_keys_index = 0;
9351 return Qnil;
9354 DEFUN ("recursion-depth", Frecursion_depth, Srecursion_depth, 0, 0, 0,
9355 "Return the current depth in recursive edits.")
9358 Lisp_Object temp;
9359 XSETFASTINT (temp, command_loop_level + minibuf_level);
9360 return temp;
9363 DEFUN ("open-dribble-file", Fopen_dribble_file, Sopen_dribble_file, 1, 1,
9364 "FOpen dribble file: ",
9365 "Start writing all keyboard characters to a dribble file called FILE.\n\
9366 If FILE is nil, close any open dribble file.")
9367 (file)
9368 Lisp_Object file;
9370 if (dribble)
9372 fclose (dribble);
9373 dribble = 0;
9375 if (!NILP (file))
9377 file = Fexpand_file_name (file, Qnil);
9378 dribble = fopen (XSTRING (file)->data, "w");
9379 if (dribble == 0)
9380 report_file_error ("Opening dribble", Fcons (file, Qnil));
9382 return Qnil;
9385 DEFUN ("discard-input", Fdiscard_input, Sdiscard_input, 0, 0, 0,
9386 "Discard the contents of the terminal input buffer.\n\
9387 Also cancel any kbd macro being defined.")
9390 current_kboard->defining_kbd_macro = Qnil;
9391 update_mode_lines++;
9393 Vunread_command_events = Qnil;
9394 unread_command_char = -1;
9396 discard_tty_input ();
9398 kbd_fetch_ptr = kbd_store_ptr;
9399 Ffillarray (kbd_buffer_gcpro, Qnil);
9400 input_pending = 0;
9402 return Qnil;
9405 DEFUN ("suspend-emacs", Fsuspend_emacs, Ssuspend_emacs, 0, 1, "",
9406 "Stop Emacs and return to superior process. You can resume later.\n\
9407 If `cannot-suspend' is non-nil, or if the system doesn't support job\n\
9408 control, run a subshell instead.\n\n\
9409 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
9410 to be read as terminal input by Emacs's parent, after suspension.\n\
9412 Before suspending, run the normal hook `suspend-hook'.\n\
9413 After resumption run the normal hook `suspend-resume-hook'.\n\
9415 Some operating systems cannot stop the Emacs process and resume it later.\n\
9416 On such systems, Emacs starts a subshell instead of suspending.")
9417 (stuffstring)
9418 Lisp_Object stuffstring;
9420 int count = specpdl_ptr - specpdl;
9421 int old_height, old_width;
9422 int width, height;
9423 struct gcpro gcpro1;
9425 if (!NILP (stuffstring))
9426 CHECK_STRING (stuffstring, 0);
9428 /* Run the functions in suspend-hook. */
9429 if (!NILP (Vrun_hooks))
9430 call1 (Vrun_hooks, intern ("suspend-hook"));
9432 GCPRO1 (stuffstring);
9433 get_frame_size (&old_width, &old_height);
9434 reset_sys_modes ();
9435 /* sys_suspend can get an error if it tries to fork a subshell
9436 and the system resources aren't available for that. */
9437 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object))) init_sys_modes,
9438 Qnil);
9439 stuff_buffered_input (stuffstring);
9440 if (cannot_suspend)
9441 sys_subshell ();
9442 else
9443 sys_suspend ();
9444 unbind_to (count, Qnil);
9446 /* Check if terminal/window size has changed.
9447 Note that this is not useful when we are running directly
9448 with a window system; but suspend should be disabled in that case. */
9449 get_frame_size (&width, &height);
9450 if (width != old_width || height != old_height)
9451 change_frame_size (SELECTED_FRAME (), height, width, 0, 0, 0);
9453 /* Run suspend-resume-hook. */
9454 if (!NILP (Vrun_hooks))
9455 call1 (Vrun_hooks, intern ("suspend-resume-hook"));
9457 UNGCPRO;
9458 return Qnil;
9461 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
9462 Then in any case stuff anything Emacs has read ahead and not used. */
9464 void
9465 stuff_buffered_input (stuffstring)
9466 Lisp_Object stuffstring;
9468 /* stuff_char works only in BSD, versions 4.2 and up. */
9469 #ifdef BSD_SYSTEM
9470 #ifndef BSD4_1
9471 register unsigned char *p;
9473 if (STRINGP (stuffstring))
9475 register int count;
9477 p = XSTRING (stuffstring)->data;
9478 count = STRING_BYTES (XSTRING (stuffstring));
9479 while (count-- > 0)
9480 stuff_char (*p++);
9481 stuff_char ('\n');
9484 /* Anything we have read ahead, put back for the shell to read. */
9485 /* ?? What should this do when we have multiple keyboards??
9486 Should we ignore anything that was typed in at the "wrong" kboard? */
9487 for (; kbd_fetch_ptr != kbd_store_ptr; kbd_fetch_ptr++)
9489 int idx;
9491 if (kbd_fetch_ptr == kbd_buffer + KBD_BUFFER_SIZE)
9492 kbd_fetch_ptr = kbd_buffer;
9493 if (kbd_fetch_ptr->kind == ascii_keystroke)
9494 stuff_char (kbd_fetch_ptr->code);
9496 kbd_fetch_ptr->kind = no_event;
9497 idx = 2 * (kbd_fetch_ptr - kbd_buffer);
9498 ASET (kbd_buffer_gcpro, idx, Qnil);
9499 ASET (kbd_buffer_gcpro, idx + 1, Qnil);
9502 input_pending = 0;
9503 #endif
9504 #endif /* BSD_SYSTEM and not BSD4_1 */
9507 void
9508 set_waiting_for_input (time_to_clear)
9509 EMACS_TIME *time_to_clear;
9511 input_available_clear_time = time_to_clear;
9513 /* Tell interrupt_signal to throw back to read_char, */
9514 waiting_for_input = 1;
9516 /* If interrupt_signal was called before and buffered a C-g,
9517 make it run again now, to avoid timing error. */
9518 if (!NILP (Vquit_flag))
9519 quit_throw_to_read_char ();
9522 void
9523 clear_waiting_for_input ()
9525 /* Tell interrupt_signal not to throw back to read_char, */
9526 waiting_for_input = 0;
9527 input_available_clear_time = 0;
9530 /* This routine is called at interrupt level in response to C-G.
9532 If interrupt_input, this is the handler for SIGINT. Otherwise, it
9533 is called from kbd_buffer_store_event, in handling SIGIO or
9534 SIGTINT.
9536 If `waiting_for_input' is non zero, then unless `echoing' is
9537 nonzero, immediately throw back to read_char.
9539 Otherwise it sets the Lisp variable quit-flag not-nil. This causes
9540 eval to throw, when it gets a chance. If quit-flag is already
9541 non-nil, it stops the job right away. */
9543 SIGTYPE
9544 interrupt_signal (signalnum) /* If we don't have an argument, */
9545 int signalnum; /* some compilers complain in signal calls. */
9547 char c;
9548 /* Must preserve main program's value of errno. */
9549 int old_errno = errno;
9550 struct frame *sf = SELECTED_FRAME ();
9552 #if defined (USG) && !defined (POSIX_SIGNALS)
9553 if (!read_socket_hook && NILP (Vwindow_system))
9555 /* USG systems forget handlers when they are used;
9556 must reestablish each time */
9557 signal (SIGINT, interrupt_signal);
9558 signal (SIGQUIT, interrupt_signal);
9560 #endif /* USG */
9562 cancel_echoing ();
9564 if (!NILP (Vquit_flag)
9565 && (FRAME_TERMCAP_P (sf) || FRAME_MSDOS_P (sf)))
9567 /* If SIGINT isn't blocked, don't let us be interrupted by
9568 another SIGINT, it might be harmful due to non-reentrancy
9569 in I/O functions. */
9570 sigblock (sigmask (SIGINT));
9572 fflush (stdout);
9573 reset_sys_modes ();
9575 #ifdef SIGTSTP /* Support possible in later USG versions */
9577 * On systems which can suspend the current process and return to the original
9578 * shell, this command causes the user to end up back at the shell.
9579 * The "Auto-save" and "Abort" questions are not asked until
9580 * the user elects to return to emacs, at which point he can save the current
9581 * job and either dump core or continue.
9583 sys_suspend ();
9584 #else
9585 #ifdef VMS
9586 if (sys_suspend () == -1)
9588 printf ("Not running as a subprocess;\n");
9589 printf ("you can continue or abort.\n");
9591 #else /* not VMS */
9592 /* Perhaps should really fork an inferior shell?
9593 But that would not provide any way to get back
9594 to the original shell, ever. */
9595 printf ("No support for stopping a process on this operating system;\n");
9596 printf ("you can continue or abort.\n");
9597 #endif /* not VMS */
9598 #endif /* not SIGTSTP */
9599 #ifdef MSDOS
9600 /* We must remain inside the screen area when the internal terminal
9601 is used. Note that [Enter] is not echoed by dos. */
9602 cursor_to (0, 0);
9603 #endif
9604 /* It doesn't work to autosave while GC is in progress;
9605 the code used for auto-saving doesn't cope with the mark bit. */
9606 if (!gc_in_progress)
9608 printf ("Auto-save? (y or n) ");
9609 fflush (stdout);
9610 if (((c = getchar ()) & ~040) == 'Y')
9612 Fdo_auto_save (Qt, Qnil);
9613 #ifdef MSDOS
9614 printf ("\r\nAuto-save done");
9615 #else /* not MSDOS */
9616 printf ("Auto-save done\n");
9617 #endif /* not MSDOS */
9619 while (c != '\n') c = getchar ();
9621 else
9623 /* During GC, it must be safe to reenable quitting again. */
9624 Vinhibit_quit = Qnil;
9625 #ifdef MSDOS
9626 printf ("\r\n");
9627 #endif /* not MSDOS */
9628 printf ("Garbage collection in progress; cannot auto-save now\r\n");
9629 printf ("but will instead do a real quit after garbage collection ends\r\n");
9630 fflush (stdout);
9633 #ifdef MSDOS
9634 printf ("\r\nAbort? (y or n) ");
9635 #else /* not MSDOS */
9636 #ifdef VMS
9637 printf ("Abort (and enter debugger)? (y or n) ");
9638 #else /* not VMS */
9639 printf ("Abort (and dump core)? (y or n) ");
9640 #endif /* not VMS */
9641 #endif /* not MSDOS */
9642 fflush (stdout);
9643 if (((c = getchar ()) & ~040) == 'Y')
9644 abort ();
9645 while (c != '\n') c = getchar ();
9646 #ifdef MSDOS
9647 printf ("\r\nContinuing...\r\n");
9648 #else /* not MSDOS */
9649 printf ("Continuing...\n");
9650 #endif /* not MSDOS */
9651 fflush (stdout);
9652 init_sys_modes ();
9653 sigfree ();
9655 else
9657 /* If executing a function that wants to be interrupted out of
9658 and the user has not deferred quitting by binding `inhibit-quit'
9659 then quit right away. */
9660 if (immediate_quit && NILP (Vinhibit_quit))
9662 struct gl_state_s saved;
9663 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
9665 immediate_quit = 0;
9666 sigfree ();
9667 saved = gl_state;
9668 GCPRO4 (saved.object, saved.global_code,
9669 saved.current_syntax_table, saved.old_prop);
9670 Fsignal (Qquit, Qnil);
9671 gl_state = saved;
9672 UNGCPRO;
9674 else
9675 /* Else request quit when it's safe */
9676 Vquit_flag = Qt;
9679 if (waiting_for_input && !echoing)
9680 quit_throw_to_read_char ();
9682 errno = old_errno;
9685 /* Handle a C-g by making read_char return C-g. */
9687 void
9688 quit_throw_to_read_char ()
9690 sigfree ();
9691 /* Prevent another signal from doing this before we finish. */
9692 clear_waiting_for_input ();
9693 input_pending = 0;
9695 Vunread_command_events = Qnil;
9696 unread_command_char = -1;
9698 #if 0 /* Currently, sit_for is called from read_char without turning
9699 off polling. And that can call set_waiting_for_input.
9700 It seems to be harmless. */
9701 #ifdef POLL_FOR_INPUT
9702 /* May be > 1 if in recursive minibuffer. */
9703 if (poll_suppress_count == 0)
9704 abort ();
9705 #endif
9706 #endif
9707 if (FRAMEP (internal_last_event_frame)
9708 && !EQ (internal_last_event_frame, selected_frame))
9709 do_switch_frame (make_lispy_switch_frame (internal_last_event_frame),
9710 Qnil, 0);
9712 _longjmp (getcjmp, 1);
9715 DEFUN ("set-input-mode", Fset_input_mode, Sset_input_mode, 3, 4, 0,
9716 "Set mode of reading keyboard input.\n\
9717 First arg INTERRUPT non-nil means use input interrupts;\n\
9718 nil means use CBREAK mode.\n\
9719 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
9720 (no effect except in CBREAK mode).\n\
9721 Third arg META t means accept 8-bit input (for a Meta key).\n\
9722 META nil means ignore the top bit, on the assumption it is parity.\n\
9723 Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\
9724 Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\
9725 See also `current-input-mode'.")
9726 (interrupt, flow, meta, quit)
9727 Lisp_Object interrupt, flow, meta, quit;
9729 if (!NILP (quit)
9730 && (!INTEGERP (quit) || XINT (quit) < 0 || XINT (quit) > 0400))
9731 error ("set-input-mode: QUIT must be an ASCII character");
9733 #ifdef POLL_FOR_INPUT
9734 stop_polling ();
9735 #endif
9737 #ifndef DOS_NT
9738 /* this causes startup screen to be restored and messes with the mouse */
9739 reset_sys_modes ();
9740 #endif
9742 #ifdef SIGIO
9743 /* Note SIGIO has been undef'd if FIONREAD is missing. */
9744 if (read_socket_hook)
9746 /* When using X, don't give the user a real choice,
9747 because we haven't implemented the mechanisms to support it. */
9748 #ifdef NO_SOCK_SIGIO
9749 interrupt_input = 0;
9750 #else /* not NO_SOCK_SIGIO */
9751 interrupt_input = 1;
9752 #endif /* NO_SOCK_SIGIO */
9754 else
9755 interrupt_input = !NILP (interrupt);
9756 #else /* not SIGIO */
9757 interrupt_input = 0;
9758 #endif /* not SIGIO */
9760 /* Our VMS input only works by interrupts, as of now. */
9761 #ifdef VMS
9762 interrupt_input = 1;
9763 #endif
9765 flow_control = !NILP (flow);
9766 if (NILP (meta))
9767 meta_key = 0;
9768 else if (EQ (meta, Qt))
9769 meta_key = 1;
9770 else
9771 meta_key = 2;
9772 if (!NILP (quit))
9773 /* Don't let this value be out of range. */
9774 quit_char = XINT (quit) & (meta_key ? 0377 : 0177);
9776 #ifndef DOS_NT
9777 init_sys_modes ();
9778 #endif
9780 #ifdef POLL_FOR_INPUT
9781 poll_suppress_count = 1;
9782 start_polling ();
9783 #endif
9784 return Qnil;
9787 DEFUN ("current-input-mode", Fcurrent_input_mode, Scurrent_input_mode, 0, 0, 0,
9788 "Return information about the way Emacs currently reads keyboard input.\n\
9789 The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
9790 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\
9791 nil, Emacs is using CBREAK mode.\n\
9792 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\
9793 terminal; this does not apply if Emacs uses interrupt-driven input.\n\
9794 META is t if accepting 8-bit input with 8th bit as Meta flag.\n\
9795 META nil means ignoring the top bit, on the assumption it is parity.\n\
9796 META is neither t nor nil if accepting 8-bit input and using\n\
9797 all 8 bits as the character code.\n\
9798 QUIT is the character Emacs currently uses to quit.\n\
9799 The elements of this list correspond to the arguments of\n\
9800 `set-input-mode'.")
9803 Lisp_Object val[4];
9805 val[0] = interrupt_input ? Qt : Qnil;
9806 val[1] = flow_control ? Qt : Qnil;
9807 val[2] = meta_key == 2 ? make_number (0) : meta_key == 1 ? Qt : Qnil;
9808 XSETFASTINT (val[3], quit_char);
9810 return Flist (sizeof (val) / sizeof (val[0]), val);
9815 * Set up a new kboard object with reasonable initial values.
9817 void
9818 init_kboard (kb)
9819 KBOARD *kb;
9821 kb->Voverriding_terminal_local_map = Qnil;
9822 kb->Vlast_command = Qnil;
9823 kb->Vreal_last_command = Qnil;
9824 kb->Vprefix_arg = Qnil;
9825 kb->Vlast_prefix_arg = Qnil;
9826 kb->kbd_queue = Qnil;
9827 kb->kbd_queue_has_data = 0;
9828 kb->immediate_echo = 0;
9829 kb->echoptr = kb->echobuf;
9830 kb->echo_after_prompt = -1;
9831 kb->kbd_macro_buffer = 0;
9832 kb->kbd_macro_bufsize = 0;
9833 kb->defining_kbd_macro = Qnil;
9834 kb->Vlast_kbd_macro = Qnil;
9835 kb->reference_count = 0;
9836 kb->Vsystem_key_alist = Qnil;
9837 kb->system_key_syms = Qnil;
9838 kb->Vdefault_minibuffer_frame = Qnil;
9842 * Destroy the contents of a kboard object, but not the object itself.
9843 * We use this just before deleting it, or if we're going to initialize
9844 * it a second time.
9846 static void
9847 wipe_kboard (kb)
9848 KBOARD *kb;
9850 if (kb->kbd_macro_buffer)
9851 xfree (kb->kbd_macro_buffer);
9854 #ifdef MULTI_KBOARD
9855 void
9856 delete_kboard (kb)
9857 KBOARD *kb;
9859 KBOARD **kbp;
9860 for (kbp = &all_kboards; *kbp != kb; kbp = &(*kbp)->next_kboard)
9861 if (*kbp == NULL)
9862 abort ();
9863 *kbp = kb->next_kboard;
9864 wipe_kboard (kb);
9865 xfree (kb);
9867 #endif
9869 void
9870 init_keyboard ()
9872 /* This is correct before outermost invocation of the editor loop */
9873 command_loop_level = -1;
9874 immediate_quit = 0;
9875 quit_char = Ctl ('g');
9876 Vunread_command_events = Qnil;
9877 unread_command_char = -1;
9878 EMACS_SET_SECS_USECS (timer_idleness_start_time, -1, -1);
9879 total_keys = 0;
9880 recent_keys_index = 0;
9881 kbd_fetch_ptr = kbd_buffer;
9882 kbd_store_ptr = kbd_buffer;
9883 kbd_buffer_gcpro = Fmake_vector (make_number (2 * KBD_BUFFER_SIZE), Qnil);
9884 #ifdef HAVE_MOUSE
9885 do_mouse_tracking = Qnil;
9886 #endif
9887 input_pending = 0;
9889 /* This means that command_loop_1 won't try to select anything the first
9890 time through. */
9891 internal_last_event_frame = Qnil;
9892 Vlast_event_frame = internal_last_event_frame;
9894 #ifdef MULTI_KBOARD
9895 current_kboard = initial_kboard;
9896 #endif
9897 wipe_kboard (current_kboard);
9898 init_kboard (current_kboard);
9900 if (initialized)
9901 Ffillarray (kbd_buffer_gcpro, Qnil);
9903 kbd_buffer_gcpro = Fmake_vector (make_number (2 * KBD_BUFFER_SIZE), Qnil);
9904 if (!noninteractive && !read_socket_hook && NILP (Vwindow_system))
9906 signal (SIGINT, interrupt_signal);
9907 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
9908 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
9909 SIGQUIT and we can't tell which one it will give us. */
9910 signal (SIGQUIT, interrupt_signal);
9911 #endif /* HAVE_TERMIO */
9913 /* Note SIGIO has been undef'd if FIONREAD is missing. */
9914 #ifdef SIGIO
9915 if (!noninteractive)
9916 signal (SIGIO, input_available_signal);
9917 #endif /* SIGIO */
9919 /* Use interrupt input by default, if it works and noninterrupt input
9920 has deficiencies. */
9922 #ifdef INTERRUPT_INPUT
9923 interrupt_input = 1;
9924 #else
9925 interrupt_input = 0;
9926 #endif
9928 /* Our VMS input only works by interrupts, as of now. */
9929 #ifdef VMS
9930 interrupt_input = 1;
9931 #endif
9933 sigfree ();
9934 dribble = 0;
9936 if (keyboard_init_hook)
9937 (*keyboard_init_hook) ();
9939 #ifdef POLL_FOR_INPUT
9940 poll_suppress_count = 1;
9941 start_polling ();
9942 #endif
9945 /* This type's only use is in syms_of_keyboard, to initialize the
9946 event header symbols and put properties on them. */
9947 struct event_head {
9948 Lisp_Object *var;
9949 char *name;
9950 Lisp_Object *kind;
9953 struct event_head head_table[] = {
9954 &Qmouse_movement, "mouse-movement", &Qmouse_movement,
9955 &Qscroll_bar_movement, "scroll-bar-movement", &Qmouse_movement,
9956 &Qswitch_frame, "switch-frame", &Qswitch_frame,
9957 &Qdelete_frame, "delete-frame", &Qdelete_frame,
9958 &Qiconify_frame, "iconify-frame", &Qiconify_frame,
9959 &Qmake_frame_visible, "make-frame-visible", &Qmake_frame_visible,
9962 void
9963 syms_of_keyboard ()
9965 Vlispy_mouse_stem = build_string ("mouse");
9966 staticpro (&Vlispy_mouse_stem);
9968 /* Tool-bars. */
9969 QCimage = intern (":image");
9970 staticpro (&QCimage);
9972 staticpro (&Qhelp_echo);
9973 Qhelp_echo = intern ("help-echo");
9975 staticpro (&item_properties);
9976 item_properties = Qnil;
9978 staticpro (&tool_bar_item_properties);
9979 tool_bar_item_properties = Qnil;
9980 staticpro (&tool_bar_items_vector);
9981 tool_bar_items_vector = Qnil;
9983 staticpro (&real_this_command);
9984 real_this_command = Qnil;
9986 Qtimer_event_handler = intern ("timer-event-handler");
9987 staticpro (&Qtimer_event_handler);
9989 Qdisabled_command_hook = intern ("disabled-command-hook");
9990 staticpro (&Qdisabled_command_hook);
9992 Qself_insert_command = intern ("self-insert-command");
9993 staticpro (&Qself_insert_command);
9995 Qforward_char = intern ("forward-char");
9996 staticpro (&Qforward_char);
9998 Qbackward_char = intern ("backward-char");
9999 staticpro (&Qbackward_char);
10001 Qdisabled = intern ("disabled");
10002 staticpro (&Qdisabled);
10004 Qundefined = intern ("undefined");
10005 staticpro (&Qundefined);
10007 Qpre_command_hook = intern ("pre-command-hook");
10008 staticpro (&Qpre_command_hook);
10010 Qpost_command_hook = intern ("post-command-hook");
10011 staticpro (&Qpost_command_hook);
10013 Qpost_command_idle_hook = intern ("post-command-idle-hook");
10014 staticpro (&Qpost_command_idle_hook);
10016 Qdeferred_action_function = intern ("deferred-action-function");
10017 staticpro (&Qdeferred_action_function);
10019 Qcommand_hook_internal = intern ("command-hook-internal");
10020 staticpro (&Qcommand_hook_internal);
10022 Qfunction_key = intern ("function-key");
10023 staticpro (&Qfunction_key);
10024 Qmouse_click = intern ("mouse-click");
10025 staticpro (&Qmouse_click);
10026 #ifdef WINDOWSNT
10027 Qmouse_wheel = intern ("mouse-wheel");
10028 staticpro (&Qmouse_wheel);
10029 Qlanguage_change = intern ("language-change");
10030 staticpro (&Qlanguage_change);
10031 #endif
10032 Qdrag_n_drop = intern ("drag-n-drop");
10033 staticpro (&Qdrag_n_drop);
10035 Qusr1_signal = intern ("usr1-signal");
10036 staticpro (&Qusr1_signal);
10037 Qusr2_signal = intern ("usr2-signal");
10038 staticpro (&Qusr2_signal);
10040 Qmenu_enable = intern ("menu-enable");
10041 staticpro (&Qmenu_enable);
10042 Qmenu_alias = intern ("menu-alias");
10043 staticpro (&Qmenu_alias);
10044 QCenable = intern (":enable");
10045 staticpro (&QCenable);
10046 QCvisible = intern (":visible");
10047 staticpro (&QCvisible);
10048 QChelp = intern (":help");
10049 staticpro (&QChelp);
10050 QCfilter = intern (":filter");
10051 staticpro (&QCfilter);
10052 QCbutton = intern (":button");
10053 staticpro (&QCbutton);
10054 QCkeys = intern (":keys");
10055 staticpro (&QCkeys);
10056 QCkey_sequence = intern (":key-sequence");
10057 staticpro (&QCkey_sequence);
10058 QCtoggle = intern (":toggle");
10059 staticpro (&QCtoggle);
10060 QCradio = intern (":radio");
10061 staticpro (&QCradio);
10063 Qmode_line = intern ("mode-line");
10064 staticpro (&Qmode_line);
10065 Qvertical_line = intern ("vertical-line");
10066 staticpro (&Qvertical_line);
10067 Qvertical_scroll_bar = intern ("vertical-scroll-bar");
10068 staticpro (&Qvertical_scroll_bar);
10069 Qmenu_bar = intern ("menu-bar");
10070 staticpro (&Qmenu_bar);
10072 Qabove_handle = intern ("above-handle");
10073 staticpro (&Qabove_handle);
10074 Qhandle = intern ("handle");
10075 staticpro (&Qhandle);
10076 Qbelow_handle = intern ("below-handle");
10077 staticpro (&Qbelow_handle);
10078 Qup = intern ("up");
10079 staticpro (&Qup);
10080 Qdown = intern ("down");
10081 staticpro (&Qdown);
10082 Qtop = intern ("top");
10083 staticpro (&Qtop);
10084 Qbottom = intern ("bottom");
10085 staticpro (&Qbottom);
10086 Qend_scroll = intern ("end-scroll");
10087 staticpro (&Qend_scroll);
10088 Qratio = intern ("ratio");
10089 staticpro (&Qratio);
10091 Qevent_kind = intern ("event-kind");
10092 staticpro (&Qevent_kind);
10093 Qevent_symbol_elements = intern ("event-symbol-elements");
10094 staticpro (&Qevent_symbol_elements);
10095 Qevent_symbol_element_mask = intern ("event-symbol-element-mask");
10096 staticpro (&Qevent_symbol_element_mask);
10097 Qmodifier_cache = intern ("modifier-cache");
10098 staticpro (&Qmodifier_cache);
10100 Qrecompute_lucid_menubar = intern ("recompute-lucid-menubar");
10101 staticpro (&Qrecompute_lucid_menubar);
10102 Qactivate_menubar_hook = intern ("activate-menubar-hook");
10103 staticpro (&Qactivate_menubar_hook);
10105 Qpolling_period = intern ("polling-period");
10106 staticpro (&Qpolling_period);
10108 Qinput_method_function = intern ("input-method-function");
10109 staticpro (&Qinput_method_function);
10111 Qinput_method_exit_on_first_char = intern ("input-method-exit-on-first-char");
10112 staticpro (&Qinput_method_exit_on_first_char);
10113 Qinput_method_use_echo_area = intern ("input-method-use-echo-area");
10114 staticpro (&Qinput_method_use_echo_area);
10116 Fset (Qinput_method_exit_on_first_char, Qnil);
10117 Fset (Qinput_method_use_echo_area, Qnil);
10119 last_point_position_buffer = Qnil;
10122 struct event_head *p;
10124 for (p = head_table;
10125 p < head_table + (sizeof (head_table) / sizeof (head_table[0]));
10126 p++)
10128 *p->var = intern (p->name);
10129 staticpro (p->var);
10130 Fput (*p->var, Qevent_kind, *p->kind);
10131 Fput (*p->var, Qevent_symbol_elements, Fcons (*p->var, Qnil));
10135 button_down_location = Fmake_vector (make_number (1), Qnil);
10136 staticpro (&button_down_location);
10137 mouse_syms = Fmake_vector (make_number (1), Qnil);
10138 staticpro (&mouse_syms);
10141 int i;
10142 int len = sizeof (modifier_names) / sizeof (modifier_names[0]);
10144 modifier_symbols = Fmake_vector (make_number (len), Qnil);
10145 for (i = 0; i < len; i++)
10146 if (modifier_names[i])
10147 XVECTOR (modifier_symbols)->contents[i] = intern (modifier_names[i]);
10148 staticpro (&modifier_symbols);
10151 recent_keys = Fmake_vector (make_number (NUM_RECENT_KEYS), Qnil);
10152 staticpro (&recent_keys);
10154 this_command_keys = Fmake_vector (make_number (40), Qnil);
10155 staticpro (&this_command_keys);
10157 raw_keybuf = Fmake_vector (make_number (30), Qnil);
10158 staticpro (&raw_keybuf);
10160 Qextended_command_history = intern ("extended-command-history");
10161 Fset (Qextended_command_history, Qnil);
10162 staticpro (&Qextended_command_history);
10164 kbd_buffer_gcpro = Fmake_vector (make_number (2 * KBD_BUFFER_SIZE), Qnil);
10165 staticpro (&kbd_buffer_gcpro);
10167 accent_key_syms = Qnil;
10168 staticpro (&accent_key_syms);
10170 func_key_syms = Qnil;
10171 staticpro (&func_key_syms);
10173 #ifdef WINDOWSNT
10174 mouse_wheel_syms = Qnil;
10175 staticpro (&mouse_wheel_syms);
10177 drag_n_drop_syms = Qnil;
10178 staticpro (&drag_n_drop_syms);
10179 #endif
10181 unread_switch_frame = Qnil;
10182 staticpro (&unread_switch_frame);
10184 internal_last_event_frame = Qnil;
10185 staticpro (&internal_last_event_frame);
10187 read_key_sequence_cmd = Qnil;
10188 staticpro (&read_key_sequence_cmd);
10190 menu_bar_one_keymap_changed_items = Qnil;
10191 staticpro (&menu_bar_one_keymap_changed_items);
10193 defsubr (&Sevent_convert_list);
10194 defsubr (&Sread_key_sequence);
10195 defsubr (&Sread_key_sequence_vector);
10196 defsubr (&Srecursive_edit);
10197 #ifdef HAVE_MOUSE
10198 defsubr (&Strack_mouse);
10199 #endif
10200 defsubr (&Sinput_pending_p);
10201 defsubr (&Scommand_execute);
10202 defsubr (&Srecent_keys);
10203 defsubr (&Sthis_command_keys);
10204 defsubr (&Sthis_command_keys_vector);
10205 defsubr (&Sthis_single_command_keys);
10206 defsubr (&Sthis_single_command_raw_keys);
10207 defsubr (&Sreset_this_command_lengths);
10208 defsubr (&Sclear_this_command_keys);
10209 defsubr (&Ssuspend_emacs);
10210 defsubr (&Sabort_recursive_edit);
10211 defsubr (&Sexit_recursive_edit);
10212 defsubr (&Srecursion_depth);
10213 defsubr (&Stop_level);
10214 defsubr (&Sdiscard_input);
10215 defsubr (&Sopen_dribble_file);
10216 defsubr (&Sset_input_mode);
10217 defsubr (&Scurrent_input_mode);
10218 defsubr (&Sexecute_extended_command);
10220 DEFVAR_LISP ("last-command-char", &last_command_char,
10221 "Last input event that was part of a command.");
10223 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char,
10224 "Last input event that was part of a command.");
10226 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event,
10227 "Last input event in a command, except for mouse menu events.\n\
10228 Mouse menus give back keys that don't look like mouse events;\n\
10229 this variable holds the actual mouse event that led to the menu,\n\
10230 so that you can determine whether the command was run by mouse or not.");
10232 DEFVAR_LISP ("last-input-char", &last_input_char,
10233 "Last input event.");
10235 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char,
10236 "Last input event.");
10238 DEFVAR_LISP ("unread-command-events", &Vunread_command_events,
10239 "List of events to be read as the command input.\n\
10240 These events are processed first, before actual keyboard input.");
10241 Vunread_command_events = Qnil;
10243 DEFVAR_INT ("unread-command-char", &unread_command_char,
10244 "If not -1, an object to be read as next command input event.");
10246 DEFVAR_LISP ("unread-post-input-method-events", &Vunread_post_input_method_events,
10247 "List of events to be processed as input by input methods.\n\
10248 These events are processed after `unread-command-events', but\n\
10249 before actual keyboard input.");
10250 Vunread_post_input_method_events = Qnil;
10252 DEFVAR_LISP ("unread-input-method-events", &Vunread_input_method_events,
10253 "List of events to be processed as input by input methods.\n\
10254 These events are processed after `unread-command-events', but\n\
10255 before actual keyboard input.");
10256 Vunread_input_method_events = Qnil;
10258 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char,
10259 "Meta-prefix character code.\n\
10260 Meta-foo as command input turns into this character followed by foo.");
10261 XSETINT (meta_prefix_char, 033);
10263 DEFVAR_KBOARD ("last-command", Vlast_command,
10264 "The last command executed.\n\
10265 Normally a symbol with a function definition, but can be whatever was found\n\
10266 in the keymap, or whatever the variable `this-command' was set to by that\n\
10267 command.\n\
10269 The value `mode-exit' is special; it means that the previous command\n\
10270 read an event that told it to exit, and it did so and unread that event.\n\
10271 In other words, the present command is the event that made the previous\n\
10272 command exit.\n\
10274 The value `kill-region' is special; it means that the previous command\n\
10275 was a kill command.");
10277 DEFVAR_KBOARD ("real-last-command", Vreal_last_command,
10278 "Same as `last-command', but never altered by Lisp code.");
10280 DEFVAR_LISP ("this-command", &Vthis_command,
10281 "The command now being executed.\n\
10282 The command can set this variable; whatever is put here\n\
10283 will be in `last-command' during the following command.");
10284 Vthis_command = Qnil;
10286 DEFVAR_INT ("auto-save-interval", &auto_save_interval,
10287 "*Number of input events between auto-saves.\n\
10288 Zero means disable autosaving due to number of characters typed.");
10289 auto_save_interval = 300;
10291 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout,
10292 "*Number of seconds idle time before auto-save.\n\
10293 Zero or nil means disable auto-saving due to idleness.\n\
10294 After auto-saving due to this many seconds of idle time,\n\
10295 Emacs also does a garbage collection if that seems to be warranted.");
10296 XSETFASTINT (Vauto_save_timeout, 30);
10298 DEFVAR_LISP ("echo-keystrokes", &Vecho_keystrokes,
10299 "*Nonzero means echo unfinished commands after this many seconds of pause.\n\
10300 The value may be integer or floating point.");
10301 Vecho_keystrokes = make_number (1);
10303 DEFVAR_INT ("polling-period", &polling_period,
10304 "*Interval between polling for input during Lisp execution.\n\
10305 The reason for polling is to make C-g work to stop a running program.\n\
10306 Polling is needed only when using X windows and SIGIO does not work.\n\
10307 Polling is automatically disabled in all other cases.");
10308 polling_period = 2;
10310 DEFVAR_LISP ("double-click-time", &Vdouble_click_time,
10311 "*Maximum time between mouse clicks to make a double-click.\n\
10312 Measured in milliseconds. nil means disable double-click recognition;\n\
10313 t means double-clicks have no time limit and are detected\n\
10314 by position only.");
10315 Vdouble_click_time = make_number (500);
10317 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus,
10318 "*Non-nil means inhibit local map menu bar menus.");
10319 inhibit_local_menu_bar_menus = 0;
10321 DEFVAR_INT ("num-input-keys", &num_input_keys,
10322 "Number of complete key sequences read as input so far.\n\
10323 This includes key sequences read from keyboard macros.\n\
10324 The number is effectively the number of interactive command invocations.");
10325 num_input_keys = 0;
10327 DEFVAR_INT ("num-nonmacro-input-events", &num_nonmacro_input_events,
10328 "Number of input events read from the keyboard so far.\n\
10329 This does not include events generated by keyboard macros.");
10330 num_nonmacro_input_events = 0;
10332 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame,
10333 "The frame in which the most recently read event occurred.\n\
10334 If the last event came from a keyboard macro, this is set to `macro'.");
10335 Vlast_event_frame = Qnil;
10337 /* This variable is set up in sysdep.c. */
10338 DEFVAR_LISP ("tty-erase-char", &Vtty_erase_char,
10339 "The ERASE character as set by the user with stty.");
10341 DEFVAR_LISP ("help-char", &Vhelp_char,
10342 "Character to recognize as meaning Help.\n\
10343 When it is read, do `(eval help-form)', and display result if it's a string.\n\
10344 If the value of `help-form' is nil, this char can be read normally.");
10345 XSETINT (Vhelp_char, Ctl ('H'));
10347 DEFVAR_LISP ("help-event-list", &Vhelp_event_list,
10348 "List of input events to recognize as meaning Help.\n\
10349 These work just like the value of `help-char' (see that).");
10350 Vhelp_event_list = Qnil;
10352 DEFVAR_LISP ("help-form", &Vhelp_form,
10353 "Form to execute when character `help-char' is read.\n\
10354 If the form returns a string, that string is displayed.\n\
10355 If `help-form' is nil, the help char is not recognized.");
10356 Vhelp_form = Qnil;
10358 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command,
10359 "Command to run when `help-char' character follows a prefix key.\n\
10360 This command is used only when there is no actual binding\n\
10361 for that character after that prefix key.");
10362 Vprefix_help_command = Qnil;
10364 DEFVAR_LISP ("top-level", &Vtop_level,
10365 "Form to evaluate when Emacs starts up.\n\
10366 Useful to set before you dump a modified Emacs.");
10367 Vtop_level = Qnil;
10369 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table,
10370 "Translate table for keyboard input, or nil.\n\
10371 Each character is looked up in this string and the contents used instead.\n\
10372 The value may be a string, a vector, or a char-table.\n\
10373 If it is a string or vector of length N,\n\
10374 character codes N and up are untranslated.\n\
10375 In a vector or a char-table, an element which is nil means \"no translation\".");
10376 Vkeyboard_translate_table = Qnil;
10378 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend,
10379 "Non-nil means to always spawn a subshell instead of suspending.\n\
10380 \(Even if the operating system has support for stopping a process.\)");
10381 cannot_suspend = 0;
10383 DEFVAR_BOOL ("menu-prompting", &menu_prompting,
10384 "Non-nil means prompt with menus when appropriate.\n\
10385 This is done when reading from a keymap that has a prompt string,\n\
10386 for elements that have prompt strings.\n\
10387 The menu is displayed on the screen\n\
10388 if X menus were enabled at configuration\n\
10389 time and the previous event was a mouse click prefix key.\n\
10390 Otherwise, menu prompting uses the echo area.");
10391 menu_prompting = 1;
10393 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char,
10394 "Character to see next line of menu prompt.\n\
10395 Type this character while in a menu prompt to rotate around the lines of it.");
10396 XSETINT (menu_prompt_more_char, ' ');
10398 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers,
10399 "A mask of additional modifier keys to use with every keyboard character.\n\
10400 Emacs applies the modifiers of the character stored here to each keyboard\n\
10401 character it reads. For example, after evaluating the expression\n\
10402 (setq extra-keyboard-modifiers ?\\C-x)\n\
10403 all input characters will have the control modifier applied to them.\n\
10405 Note that the character ?\\C-@, equivalent to the integer zero, does\n\
10406 not count as a control character; rather, it counts as a character\n\
10407 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\
10408 cancels any modification.");
10409 extra_keyboard_modifiers = 0;
10411 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark,
10412 "If an editing command sets this to t, deactivate the mark afterward.\n\
10413 The command loop sets this to nil before each command,\n\
10414 and tests the value when the command returns.\n\
10415 Buffer modification stores t in this variable.");
10416 Vdeactivate_mark = Qnil;
10418 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal,
10419 "Temporary storage of pre-command-hook or post-command-hook.");
10420 Vcommand_hook_internal = Qnil;
10422 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook,
10423 "Normal hook run before each command is executed.\n\
10424 If an unhandled error happens in running this hook,\n\
10425 the hook value is set to nil, since otherwise the error\n\
10426 might happen repeatedly and make Emacs nonfunctional.");
10427 Vpre_command_hook = Qnil;
10429 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook,
10430 "Normal hook run after each command is executed.\n\
10431 If an unhandled error happens in running this hook,\n\
10432 the hook value is set to nil, since otherwise the error\n\
10433 might happen repeatedly and make Emacs nonfunctional.");
10434 Vpost_command_hook = Qnil;
10436 DEFVAR_LISP ("post-command-idle-hook", &Vpost_command_idle_hook,
10437 "Normal hook run after each command is executed, if idle.\n\
10438 Errors running the hook are caught and ignored.\n\
10439 This feature is obsolete; use idle timers instead. See `etc/NEWS'.");
10440 Vpost_command_idle_hook = Qnil;
10442 DEFVAR_INT ("post-command-idle-delay", &post_command_idle_delay,
10443 "Delay time before running `post-command-idle-hook'.\n\
10444 This is measured in microseconds.");
10445 post_command_idle_delay = 100000;
10447 #if 0
10448 DEFVAR_LISP ("echo-area-clear-hook", ...,
10449 "Normal hook run when clearing the echo area.");
10450 #endif
10451 Qecho_area_clear_hook = intern ("echo-area-clear-hook");
10452 XSYMBOL (Qecho_area_clear_hook)->value = Qnil;
10454 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag,
10455 "t means menu bar, specified Lucid style, needs to be recomputed.");
10456 Vlucid_menu_bar_dirty_flag = Qnil;
10458 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items,
10459 "List of menu bar items to move to the end of the menu bar.\n\
10460 The elements of the list are event types that may have menu bar bindings.");
10461 Vmenu_bar_final_items = Qnil;
10463 DEFVAR_KBOARD ("overriding-terminal-local-map",
10464 Voverriding_terminal_local_map,
10465 "Per-terminal keymap that overrides all other local keymaps.\n\
10466 If this variable is non-nil, it is used as a keymap instead of the\n\
10467 buffer's local map, and the minor mode keymaps and text property keymaps.\n\
10468 This variable is intended to let commands such as `universal-argumemnt'\n\
10469 set up a different keymap for reading the next command.");
10471 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map,
10472 "Keymap that overrides all other local keymaps.\n\
10473 If this variable is non-nil, it is used as a keymap instead of the\n\
10474 buffer's local map, and the minor mode keymaps and text property keymaps.");
10475 Voverriding_local_map = Qnil;
10477 DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag,
10478 "Non-nil means `overriding-local-map' applies to the menu bar.\n\
10479 Otherwise, the menu bar continues to reflect the buffer's local map\n\
10480 and the minor mode maps regardless of `overriding-local-map'.");
10481 Voverriding_local_map_menu_flag = Qnil;
10483 DEFVAR_LISP ("special-event-map", &Vspecial_event_map,
10484 "Keymap defining bindings for special events to execute at low level.");
10485 Vspecial_event_map = Fcons (intern ("keymap"), Qnil);
10487 DEFVAR_LISP ("track-mouse", &do_mouse_tracking,
10488 "*Non-nil means generate motion events for mouse motion.");
10490 DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist,
10491 "Alist of system-specific X windows key symbols.\n\
10492 Each element should have the form (N . SYMBOL) where N is the\n\
10493 numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\
10494 and SYMBOL is its name.");
10496 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list,
10497 "List of deferred actions to be performed at a later time.\n\
10498 The precise format isn't relevant here; we just check whether it is nil.");
10499 Vdeferred_action_list = Qnil;
10501 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function,
10502 "Function to call to handle deferred actions, after each command.\n\
10503 This function is called with no arguments after each command\n\
10504 whenever `deferred-action-list' is non-nil.");
10505 Vdeferred_action_function = Qnil;
10507 DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings,
10508 "*Non-nil means show the equivalent key-binding when M-x command has one.\n\
10509 The value can be a length of time to show the message for.\n\
10510 If the value is non-nil and not a number, we wait 2 seconds.");
10511 Vsuggest_key_bindings = Qt;
10513 DEFVAR_LISP ("timer-list", &Vtimer_list,
10514 "List of active absolute time timers in order of increasing time");
10515 Vtimer_list = Qnil;
10517 DEFVAR_LISP ("timer-idle-list", &Vtimer_idle_list,
10518 "List of active idle-time timers in order of increasing time");
10519 Vtimer_idle_list = Qnil;
10521 DEFVAR_LISP ("input-method-function", &Vinput_method_function,
10522 "If non-nil, the function that implements the current input method.\n\
10523 It's called with one argument, a printing character that was just read.\n\
10524 \(That means a character with code 040...0176.)\n\
10525 Typically this function uses `read-event' to read additional events.\n\
10526 When it does so, it should first bind `input-method-function' to nil\n\
10527 so it will not be called recursively.\n\
10529 The function should return a list of zero or more events\n\
10530 to be used as input. If it wants to put back some events\n\
10531 to be reconsidered, separately, by the input method,\n\
10532 it can add them to the beginning of `unread-command-events'.\n\
10534 The input method function can find in `input-method-previous-method'\n\
10535 the previous echo area message.\n\
10537 The input method function should refer to the variables\n\
10538 `input-method-use-echo-area' and `input-method-exit-on-first-char'\n\
10539 for guidance on what to do.");
10540 Vinput_method_function = Qnil;
10542 DEFVAR_LISP ("input-method-previous-message",
10543 &Vinput_method_previous_message,
10544 "When `input-method-function' is called, hold the previous echo area message.\n\
10545 This variable exists because `read-event' clears the echo area\n\
10546 before running the input method. It is nil if there was no message.");
10547 Vinput_method_previous_message = Qnil;
10549 DEFVAR_LISP ("show-help-function", &Vshow_help_function,
10550 "If non-nil, the function that implements the display of help.\n\
10551 It's called with one argument, the help string to display.");
10552 Vshow_help_function = Qnil;
10554 DEFVAR_LISP ("disable-point-adjustment", &Vdisable_point_adjustment,
10555 "If non-nil, suppress point adjustment after executing a command.\n\
10557 After a command is executed, if point is moved into a region that has\n\
10558 special properties (e.g. composition, display), we adjust point to\n\
10559 the boundary of the region. But, several special commands sets this\n\
10560 variable to non-nil, then we suppress the point adjustment.\n\
10562 This variable is set to nil before reading a command, and is checked\n\
10563 just after executing the command");
10564 Vdisable_point_adjustment = Qnil;
10566 DEFVAR_LISP ("global-disable-point-adjustment",
10567 &Vglobal_disable_point_adjustment,
10568 "*If non-nil, always suppress point adjustment.\n\
10570 The default value is nil, in which case, point adjustment are\n\
10571 suppressed only after special commands that set\n\
10572 `disable-point-adjustment' (which see) to non-nil.");
10573 Vglobal_disable_point_adjustment = Qnil;
10576 void
10577 keys_of_keyboard ()
10579 initial_define_key (global_map, Ctl ('Z'), "suspend-emacs");
10580 initial_define_key (control_x_map, Ctl ('Z'), "suspend-emacs");
10581 initial_define_key (meta_map, Ctl ('C'), "exit-recursive-edit");
10582 initial_define_key (global_map, Ctl (']'), "abort-recursive-edit");
10583 initial_define_key (meta_map, 'x', "execute-extended-command");
10585 initial_define_lispy_key (Vspecial_event_map, "delete-frame",
10586 "handle-delete-frame");
10587 initial_define_lispy_key (Vspecial_event_map, "iconify-frame",
10588 "ignore-event");
10589 initial_define_lispy_key (Vspecial_event_map, "make-frame-visible",
10590 "ignore-event");