1 /* Keyboard and mouse input; editor command loop.
2 Copyright (C) 1985,86,87,88,89,93,94,95,96,97 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Allow config.h to undefine symbols found here. */
29 #include "termhooks.h"
37 #include "dispextern.h"
39 #include "intervals.h"
40 #include "blockinput.h"
49 #include <sys/ioctl.h>
51 #endif /* not MSDOS */
53 #include "syssignal.h"
56 /* This is to get the definitions of the XK_ symbols. */
63 #endif /* HAVE_NTGUI */
65 /* Include systime.h after xterm.h to avoid double inclusion of time.h. */
70 /* Variables for blockinput.h: */
72 /* Non-zero if interrupt input is blocked right now. */
73 int interrupt_input_blocked
;
75 /* Nonzero means an input interrupt has arrived
76 during the current critical section. */
77 int interrupt_input_pending
;
80 /* File descriptor to use for input. */
83 #ifdef HAVE_WINDOW_SYSTEM
84 /* Make all keyboard buffers much bigger when using X windows. */
85 #define KBD_BUFFER_SIZE 4096
86 #else /* No X-windows, character input */
87 #define KBD_BUFFER_SIZE 256
88 #endif /* No X-windows */
90 /* Following definition copied from eval.c */
94 struct backtrace
*next
;
95 Lisp_Object
*function
;
96 Lisp_Object
*args
; /* Points to vector of args. */
97 int nargs
; /* length of vector. If nargs is UNEVALLED,
98 args points to slot holding list of
104 KBOARD
*initial_kboard
;
105 KBOARD
*current_kboard
;
109 KBOARD the_only_kboard
;
112 /* Non-nil disable property on a command means
113 do not execute it; call disabled-command-hook's value instead. */
114 Lisp_Object Qdisabled
, Qdisabled_command_hook
;
116 #define NUM_RECENT_KEYS (100)
117 int recent_keys_index
; /* Index for storing next element into recent_keys */
118 int total_keys
; /* Total number of elements stored into recent_keys */
119 Lisp_Object recent_keys
; /* A vector, holding the last 100 keystrokes */
121 /* Vector holding the key sequence that invoked the current command.
122 It is reused for each command, and it may be longer than the current
123 sequence; this_command_key_count indicates how many elements
124 actually mean something.
125 It's easier to staticpro a single Lisp_Object than an array. */
126 Lisp_Object this_command_keys
;
127 int this_command_key_count
;
129 /* Number of elements of this_command_keys
130 that precede this key sequence. */
131 int this_single_command_key_start
;
133 /* Record values of this_command_key_count and echo_length ()
134 before this command was read. */
135 static int before_command_key_count
;
136 static int before_command_echo_length
;
137 /* Values of before_command_key_count and before_command_echo_length
138 saved by reset-this-command-lengths. */
139 static int before_command_key_count_1
;
140 static int before_command_echo_length_1
;
141 /* Flag set by reset-this-command-lengths,
142 saying to reset the lengths when add_command_key is called. */
143 static int before_command_restore_flag
;
145 extern int minbuf_level
;
147 extern int message_enable_multibyte
;
149 extern struct backtrace
*backtrace_list
;
151 /* Nonzero means do menu prompting. */
152 static int menu_prompting
;
154 /* Character to see next line of menu prompt. */
155 static Lisp_Object menu_prompt_more_char
;
157 /* For longjmp to where kbd input is being done. */
158 static jmp_buf getcjmp
;
160 /* True while doing kbd input. */
161 int waiting_for_input
;
163 /* True while displaying for echoing. Delays C-g throwing. */
166 /* True means we can start echoing at the next input pause
167 even though there is something in the echo area. */
168 static char *ok_to_echo_at_next_pause
;
170 /* Nonzero means disregard local maps for the menu bar. */
171 static int inhibit_local_menu_bar_menus
;
173 /* Nonzero means C-g should cause immediate error-signal. */
176 /* The user's ERASE setting. */
177 Lisp_Object Vtty_erase_char
;
179 /* Character to recognize as the help char. */
180 Lisp_Object Vhelp_char
;
182 /* List of other event types to recognize as meaning "help". */
183 Lisp_Object Vhelp_event_list
;
185 /* Form to execute when help char is typed. */
186 Lisp_Object Vhelp_form
;
188 /* Command to run when the help character follows a prefix key. */
189 Lisp_Object Vprefix_help_command
;
191 /* List of items that should move to the end of the menu bar. */
192 Lisp_Object Vmenu_bar_final_items
;
194 /* Non-nil means show the equivalent key-binding for
195 any M-x command that has one.
196 The value can be a length of time to show the message for.
197 If the value is non-nil and not a number, we wait 2 seconds. */
198 Lisp_Object Vsuggest_key_bindings
;
200 /* Character that causes a quit. Normally C-g.
202 If we are running on an ordinary terminal, this must be an ordinary
203 ASCII char, since we want to make it our interrupt character.
205 If we are not running on an ordinary terminal, it still needs to be
206 an ordinary ASCII char. This character needs to be recognized in
207 the input interrupt handler. At this point, the keystroke is
208 represented as a struct input_event, while the desired quit
209 character is specified as a lispy event. The mapping from struct
210 input_events to lispy events cannot run in an interrupt handler,
211 and the reverse mapping is difficult for anything but ASCII
214 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
218 extern Lisp_Object current_global_map
;
219 extern int minibuf_level
;
221 /* If non-nil, this is a map that overrides all other local maps. */
222 Lisp_Object Voverriding_local_map
;
224 /* If non-nil, Voverriding_local_map applies to the menu bar. */
225 Lisp_Object Voverriding_local_map_menu_flag
;
227 /* Keymap that defines special misc events that should
228 be processed immediately at a low level. */
229 Lisp_Object Vspecial_event_map
;
231 /* Current depth in recursive edits. */
232 int command_loop_level
;
234 /* Total number of times command_loop has read a key sequence. */
237 /* Last input character read as a command. */
238 Lisp_Object last_command_char
;
240 /* Last input character read as a command, not counting menus
241 reached by the mouse. */
242 Lisp_Object last_nonmenu_event
;
244 /* Last input character read for any purpose. */
245 Lisp_Object last_input_char
;
247 /* If not Qnil, a list of objects to be read as subsequent command input. */
248 Lisp_Object Vunread_command_events
;
250 /* If not -1, an event to be read as subsequent command input. */
251 int unread_command_char
;
253 /* If not Qnil, this is a switch-frame event which we decided to put
254 off until the end of a key sequence. This should be read as the
255 next command input, after any unread_command_events.
257 read_key_sequence uses this to delay switch-frame events until the
258 end of the key sequence; Fread_char uses it to put off switch-frame
259 events until a non-ASCII event is acceptable as input. */
260 Lisp_Object unread_switch_frame
;
262 /* A mask of extra modifier bits to put into every keyboard char. */
263 int extra_keyboard_modifiers
;
265 /* Char to use as prefix when a meta character is typed in.
266 This is bound on entry to minibuffer in case ESC is changed there. */
268 Lisp_Object meta_prefix_char
;
270 /* Last size recorded for a current buffer which is not a minibuffer. */
271 static int last_non_minibuf_size
;
273 /* Number of idle seconds before an auto-save and garbage collection. */
274 static Lisp_Object Vauto_save_timeout
;
276 /* Total number of times read_char has returned. */
277 int num_input_events
;
279 /* Total number of times read_char has returned, outside of macros. */
280 int num_nonmacro_input_events
;
282 /* Auto-save automatically when this many characters have been typed
283 since the last time. */
285 static int auto_save_interval
;
287 /* Value of num_nonmacro_input_events as of last auto save. */
291 /* The command being executed by the command loop.
292 Commands may set this, and the value set will be copied into
293 current_kboard->Vlast_command instead of the actual command. */
294 Lisp_Object this_command
;
296 /* The value of point when the last command was executed. */
297 int last_point_position
;
299 /* The buffer that was current when the last command was started. */
300 Lisp_Object last_point_position_buffer
;
302 /* The frame in which the last input event occurred, or Qmacro if the
303 last event came from a macro. We use this to determine when to
304 generate switch-frame events. This may be cleared by functions
305 like Fselect_frame, to make sure that a switch-frame event is
306 generated by the next character. */
307 Lisp_Object internal_last_event_frame
;
309 /* A user-visible version of the above, intended to allow users to
310 figure out where the last event came from, if the event doesn't
311 carry that information itself (i.e. if it was a character). */
312 Lisp_Object Vlast_event_frame
;
314 /* The timestamp of the last input event we received from the X server.
315 X Windows wants this for selection ownership. */
316 unsigned long last_event_timestamp
;
318 Lisp_Object Qself_insert_command
;
319 Lisp_Object Qforward_char
;
320 Lisp_Object Qbackward_char
;
321 Lisp_Object Qundefined
;
322 Lisp_Object Qtimer_event_handler
;
324 /* read_key_sequence stores here the command definition of the
325 key sequence that it reads. */
326 Lisp_Object read_key_sequence_cmd
;
328 /* Form to evaluate (if non-nil) when Emacs is started. */
329 Lisp_Object Vtop_level
;
331 /* User-supplied string to translate input characters through. */
332 Lisp_Object Vkeyboard_translate_table
;
334 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
335 extern Lisp_Object Vfunction_key_map
;
337 /* Another keymap that maps key sequences into key sequences.
338 This one takes precedence over ordinary definitions. */
339 extern Lisp_Object Vkey_translation_map
;
341 /* Non-nil means deactivate the mark at end of this command. */
342 Lisp_Object Vdeactivate_mark
;
344 /* Menu bar specified in Lucid Emacs fashion. */
346 Lisp_Object Vlucid_menu_bar_dirty_flag
;
347 Lisp_Object Qrecompute_lucid_menubar
, Qactivate_menubar_hook
;
349 Lisp_Object Qecho_area_clear_hook
;
351 /* Hooks to run before and after each command. */
352 Lisp_Object Qpre_command_hook
, Vpre_command_hook
;
353 Lisp_Object Qpost_command_hook
, Vpost_command_hook
;
354 Lisp_Object Qcommand_hook_internal
, Vcommand_hook_internal
;
355 /* Hook run after a command if there's no more input soon. */
356 Lisp_Object Qpost_command_idle_hook
, Vpost_command_idle_hook
;
358 /* Delay time in microseconds before running post-command-idle-hook. */
359 int post_command_idle_delay
;
361 /* List of deferred actions to be performed at a later time.
362 The precise format isn't relevant here; we just check whether it is nil. */
363 Lisp_Object Vdeferred_action_list
;
365 /* Function to call to handle deferred actions, when there are any. */
366 Lisp_Object Vdeferred_action_function
;
367 Lisp_Object Qdeferred_action_function
;
369 /* File in which we write all commands we read. */
372 /* Nonzero if input is available. */
375 /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
376 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
380 extern char *pending_malloc_warning
;
382 /* Circular buffer for pre-read keyboard input. */
383 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
385 /* Vector to GCPRO the frames and windows mentioned in kbd_buffer.
387 The interrupt-level event handlers will never enqueue an event on a
388 frame which is not in Vframe_list, and once an event is dequeued,
389 internal_last_event_frame or the event itself points to the frame.
392 But while the event is sitting in the queue, it's completely
393 unprotected. Suppose the user types one command which will run for
394 a while and then delete a frame, and then types another event at
395 the frame that will be deleted, before the command gets around to
396 it. Suppose there are no references to this frame elsewhere in
397 Emacs, and a GC occurs before the second event is dequeued. Now we
398 have an event referring to a freed frame, which will crash Emacs
401 Similar things happen when an event on a scroll bar is enqueued; the
402 window may be deleted while the event is in the queue.
404 So, we use this vector to protect the frame_or_window field in the
405 event queue. That way, they'll be dequeued as dead frames or
406 windows, but still valid lisp objects.
408 If kbd_buffer[i].kind != no_event, then
409 (XVECTOR (kbd_buffer_frame_or_window)->contents[i]
410 == kbd_buffer[i].frame_or_window. */
411 static Lisp_Object kbd_buffer_frame_or_window
;
413 /* Pointer to next available character in kbd_buffer.
414 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
415 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the
416 next available char is in kbd_buffer[0]. */
417 static struct input_event
*kbd_fetch_ptr
;
419 /* Pointer to next place to store character in kbd_buffer. This
420 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
421 character should go in kbd_buffer[0]. */
422 static volatile struct input_event
*kbd_store_ptr
;
424 /* The above pair of variables forms a "queue empty" flag. When we
425 enqueue a non-hook event, we increment kbd_store_ptr. When we
426 dequeue a non-hook event, we increment kbd_fetch_ptr. We say that
427 there is input available iff the two pointers are not equal.
429 Why not just have a flag set and cleared by the enqueuing and
430 dequeuing functions? Such a flag could be screwed up by interrupts
431 at inopportune times. */
433 /* If this flag is non-nil, we check mouse_moved to see when the
434 mouse moves, and motion events will appear in the input stream.
435 Otherwise, mouse motion is ignored. */
436 static Lisp_Object do_mouse_tracking
;
438 /* Symbols to head events. */
439 Lisp_Object Qmouse_movement
;
440 Lisp_Object Qscroll_bar_movement
;
441 Lisp_Object Qswitch_frame
;
442 Lisp_Object Qdelete_frame
;
443 Lisp_Object Qiconify_frame
;
444 Lisp_Object Qmake_frame_visible
;
446 /* Symbols to denote kinds of events. */
447 Lisp_Object Qfunction_key
;
448 Lisp_Object Qmouse_click
;
450 Lisp_Object Qmouse_wheel
;
452 /* Lisp_Object Qmouse_movement; - also an event header */
454 /* Properties of event headers. */
455 Lisp_Object Qevent_kind
;
456 Lisp_Object Qevent_symbol_elements
;
458 Lisp_Object Qmenu_enable
;
460 /* An event header symbol HEAD may have a property named
461 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
462 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
463 mask of modifiers applied to it. If present, this is used to help
464 speed up parse_modifiers. */
465 Lisp_Object Qevent_symbol_element_mask
;
467 /* An unmodified event header BASE may have a property named
468 Qmodifier_cache, which is an alist mapping modifier masks onto
469 modified versions of BASE. If present, this helps speed up
471 Lisp_Object Qmodifier_cache
;
473 /* Symbols to use for parts of windows. */
474 Lisp_Object Qmode_line
;
475 Lisp_Object Qvertical_line
;
476 Lisp_Object Qvertical_scroll_bar
;
477 Lisp_Object Qmenu_bar
;
479 extern Lisp_Object Qmenu_enable
;
481 Lisp_Object
recursive_edit_unwind (), command_loop ();
482 Lisp_Object
Fthis_command_keys ();
483 Lisp_Object Qextended_command_history
;
484 EMACS_TIME
timer_check ();
486 extern char *x_get_keysym_name ();
488 static void record_menu_key ();
490 void swallow_events ();
492 Lisp_Object Qpolling_period
;
494 /* List of absolute timers. Appears in order of next scheduled event. */
495 Lisp_Object Vtimer_list
;
497 /* List of idle time timers. Appears in order of next scheduled event. */
498 Lisp_Object Vtimer_idle_list
;
500 /* Incremented whenever a timer is run. */
503 extern Lisp_Object Vprint_level
, Vprint_length
;
505 extern nonascii_insert_offset
;
507 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
509 EMACS_TIME
*input_available_clear_time
;
511 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
512 Default is 1 if INTERRUPT_INPUT is defined. */
515 /* Nonzero while interrupts are temporarily deferred during redisplay. */
516 int interrupts_deferred
;
518 /* Nonzero means use ^S/^Q for flow control. */
521 /* Allow m- file to inhibit use of FIONREAD. */
522 #ifdef BROKEN_FIONREAD
526 /* We are unable to use interrupts if FIONREAD is not available,
527 so flush SIGIO so we won't try. */
534 /* If we support a window system, turn on the code to poll periodically
535 to detect C-g. It isn't actually used when doing interrupt input. */
536 #ifdef HAVE_WINDOW_SYSTEM
537 #define POLL_FOR_INPUT
540 /* Global variable declarations. */
542 /* Function for init_keyboard to call with no args (if nonzero). */
543 void (*keyboard_init_hook
) ();
545 static int read_avail_input ();
546 static void get_input_pending ();
547 static int readable_events ();
548 static Lisp_Object
read_char_x_menu_prompt ();
549 static Lisp_Object
read_char_minibuf_menu_prompt ();
550 static Lisp_Object
make_lispy_event ();
552 static Lisp_Object
make_lispy_movement ();
554 static Lisp_Object
modify_event_symbol ();
555 static Lisp_Object
make_lispy_switch_frame ();
556 static int parse_solitary_modifier ();
558 /* > 0 if we are to echo keystrokes. */
559 static int echo_keystrokes
;
561 /* Nonzero means don't try to suspend even if the operating system seems
563 static int cannot_suspend
;
565 #define min(a,b) ((a)<(b)?(a):(b))
566 #define max(a,b) ((a)>(b)?(a):(b))
568 /* Install the string STR as the beginning of the string of echoing,
569 so that it serves as a prompt for the next character.
570 Also start echoing. */
575 int len
= strlen (str
);
577 if (len
> ECHOBUFSIZE
- 4)
578 len
= ECHOBUFSIZE
- 4;
579 bcopy (str
, current_kboard
->echobuf
, len
);
580 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
581 *current_kboard
->echoptr
= '\0';
583 current_kboard
->echo_after_prompt
= len
;
588 /* Add C to the echo string, if echoing is going on.
589 C can be a character, which is printed prettily ("M-C-x" and all that
590 jazz), or a symbol, whose name is printed. */
595 extern char *push_key_description ();
597 if (current_kboard
->immediate_echo
)
599 char *ptr
= current_kboard
->echoptr
;
601 if (ptr
!= current_kboard
->echobuf
)
604 /* If someone has passed us a composite event, use its head symbol. */
609 if (ptr
- current_kboard
->echobuf
> ECHOBUFSIZE
- 6)
612 ptr
= push_key_description (XINT (c
), ptr
);
614 else if (SYMBOLP (c
))
616 struct Lisp_String
*name
= XSYMBOL (c
)->name
;
617 if ((ptr
- current_kboard
->echobuf
) + name
->size
+ 4 > ECHOBUFSIZE
)
619 bcopy (name
->data
, ptr
, name
->size
);
623 if (current_kboard
->echoptr
== current_kboard
->echobuf
626 strcpy (ptr
, " (Type ? for further options)");
631 current_kboard
->echoptr
= ptr
;
637 /* Temporarily add a dash to the end of the echo string if it's not
638 empty, so that it serves as a mini-prompt for the very next character. */
642 if (!current_kboard
->immediate_echo
643 && current_kboard
->echoptr
== current_kboard
->echobuf
)
645 /* Do nothing if we just printed a prompt. */
646 if (current_kboard
->echo_after_prompt
647 == current_kboard
->echoptr
- current_kboard
->echobuf
)
649 /* Do nothing if not echoing at all. */
650 if (current_kboard
->echoptr
== 0)
653 /* Put a dash at the end of the buffer temporarily,
654 but make it go away when the next character is added. */
655 current_kboard
->echoptr
[0] = '-';
656 current_kboard
->echoptr
[1] = 0;
661 /* Display the current echo string, and begin echoing if not already
667 if (!current_kboard
->immediate_echo
)
670 current_kboard
->immediate_echo
= 1;
672 for (i
= 0; i
< this_command_key_count
; i
++)
675 c
= XVECTOR (this_command_keys
)->contents
[i
];
676 if (! (EVENT_HAS_PARAMETERS (c
)
677 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
684 message1_nolog (current_kboard
->echobuf
);
687 if (waiting_for_input
&& !NILP (Vquit_flag
))
688 quit_throw_to_read_char ();
691 /* Turn off echoing, for the start of a new command. */
695 current_kboard
->immediate_echo
= 0;
696 current_kboard
->echoptr
= current_kboard
->echobuf
;
697 current_kboard
->echo_after_prompt
= -1;
698 ok_to_echo_at_next_pause
= 0;
701 /* Return the length of the current echo string. */
706 return current_kboard
->echoptr
- current_kboard
->echobuf
;
709 /* Truncate the current echo message to its first LEN chars.
710 This and echo_char get used by read_key_sequence when the user
711 switches frames while entering a key sequence. */
717 current_kboard
->echobuf
[len
] = '\0';
718 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
719 truncate_echo_area (len
);
723 /* Functions for manipulating this_command_keys. */
725 add_command_key (key
)
728 int size
= XVECTOR (this_command_keys
)->size
;
730 /* If reset-this-command-length was called recently, obey it now.
731 See the doc string of that function for an explanation of why. */
732 if (before_command_restore_flag
)
734 this_command_key_count
= before_command_key_count_1
;
735 if (this_command_key_count
< this_single_command_key_start
)
736 this_single_command_key_start
= this_command_key_count
;
737 echo_truncate (before_command_echo_length_1
);
738 before_command_restore_flag
= 0;
741 if (this_command_key_count
>= size
)
743 Lisp_Object new_keys
;
745 new_keys
= Fmake_vector (make_number (size
* 2), Qnil
);
746 bcopy (XVECTOR (this_command_keys
)->contents
,
747 XVECTOR (new_keys
)->contents
,
748 size
* sizeof (Lisp_Object
));
750 this_command_keys
= new_keys
;
753 XVECTOR (this_command_keys
)->contents
[this_command_key_count
++] = key
;
759 int count
= specpdl_ptr
- specpdl
;
762 if (command_loop_level
> 0)
764 specbind (Qstandard_output
, Qt
);
765 specbind (Qstandard_input
, Qt
);
768 val
= command_loop ();
770 Fsignal (Qquit
, Qnil
);
771 /* Handle throw from read_minibuf when using minibuffer
772 while it's active but we're in another window. */
774 Fsignal (Qerror
, Fcons (val
, Qnil
));
776 return unbind_to (count
, Qnil
);
779 /* When an auto-save happens, record the "time", and don't do again soon. */
784 last_auto_save
= num_nonmacro_input_events
;
787 /* Make an auto save happen as soon as possible at command level. */
789 force_auto_save_soon ()
791 last_auto_save
= - auto_save_interval
- 1;
793 record_asynch_buffer_change ();
796 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
797 "Invoke the editor command loop recursively.\n\
798 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
799 that tells this function to return.\n\
800 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
801 This function is called by the editor initialization to begin editing.")
804 int count
= specpdl_ptr
- specpdl
;
807 command_loop_level
++;
808 update_mode_lines
= 1;
810 record_unwind_protect (recursive_edit_unwind
,
812 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
816 return unbind_to (count
, Qnil
);
820 recursive_edit_unwind (buffer
)
824 Fset_buffer (buffer
);
826 command_loop_level
--;
827 update_mode_lines
= 1;
835 #if 0 /* Theory: if there's anything in Vunread_command_events,
836 it will right away be read by read_key_sequence,
837 and then if we do switch KBOARDS, it will go into the side
838 queue then. So we don't need to do anything special here -- rms. */
839 if (CONSP (Vunread_command_events
))
841 current_kboard
->kbd_queue
842 = nconc2 (Vunread_command_events
, current_kboard
->kbd_queue
);
843 current_kboard
->kbd_queue_has_data
= 1;
845 Vunread_command_events
= Qnil
;
851 /* Switch to the single-kboard state, making current_kboard
852 the only KBOARD from which further input is accepted. */
855 single_kboard_state ()
862 /* Maintain a stack of kboards, so other parts of Emacs
863 can switch temporarily to the kboard of a given frame
864 and then revert to the previous status. */
869 struct kboard_stack
*next
;
872 static struct kboard_stack
*kboard_stack
;
875 push_frame_kboard (f
)
879 struct kboard_stack
*p
880 = (struct kboard_stack
*) xmalloc (sizeof (struct kboard_stack
));
882 p
->next
= kboard_stack
;
883 p
->kboard
= current_kboard
;
886 current_kboard
= FRAME_KBOARD (f
);
894 struct kboard_stack
*p
= kboard_stack
;
895 current_kboard
= p
->kboard
;
896 kboard_stack
= p
->next
;
901 /* Handle errors that are not handled at inner levels
902 by printing an error message and returning to the editor command loop. */
908 Lisp_Object old_level
, old_length
;
911 if (!NILP (executing_macro
))
913 if (executing_macro_iterations
== 1)
914 sprintf (macroerror
, "After 1 kbd macro iteration: ");
916 sprintf (macroerror
, "After %d kbd macro iterations: ",
917 executing_macro_iterations
);
922 Vstandard_output
= Qt
;
923 Vstandard_input
= Qt
;
924 Vexecuting_macro
= Qnil
;
925 executing_macro
= Qnil
;
926 current_kboard
->Vprefix_arg
= Qnil
;
929 /* Avoid unquittable loop if data contains a circular list. */
930 old_level
= Vprint_level
;
931 old_length
= Vprint_length
;
932 XSETFASTINT (Vprint_level
, 10);
933 XSETFASTINT (Vprint_length
, 10);
934 cmd_error_internal (data
, macroerror
);
935 Vprint_level
= old_level
;
936 Vprint_length
= old_length
;
940 Vinhibit_quit
= Qnil
;
945 return make_number (0);
949 cmd_error_internal (data
, context
)
957 echo_area_glyphs
= 0;
959 /* If the window system or terminal frame hasn't been initialized
960 yet, or we're not interactive, it's best to dump this message out
961 to stderr and exit. */
962 if (! FRAME_MESSAGE_BUF (selected_frame
)
964 stream
= Qexternal_debugging_output
;
973 write_string_1 (context
, -1, stream
);
975 print_error_message (data
, stream
);
977 /* If the window system or terminal frame hasn't been initialized
978 yet, or we're in -batch mode, this error should cause Emacs to exit. */
979 if (! FRAME_MESSAGE_BUF (selected_frame
)
983 Fkill_emacs (make_number (-1));
987 Lisp_Object
command_loop_1 ();
988 Lisp_Object
command_loop_2 ();
989 Lisp_Object
top_level_1 ();
991 /* Entry to editor-command-loop.
992 This level has the catches for exiting/returning to editor command loop.
993 It returns nil to exit recursive edit, t to abort it. */
998 if (command_loop_level
> 0 || minibuf_level
> 0)
1000 return internal_catch (Qexit
, command_loop_2
, Qnil
);
1005 internal_catch (Qtop_level
, top_level_1
, Qnil
);
1006 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
1008 /* End of file in -batch run causes exit here. */
1014 /* Here we catch errors in execution of commands within the
1015 editing loop, and reenter the editing loop.
1016 When there is an error, cmd_error runs and returns a non-nil
1017 value to us. A value of nil means that cmd_loop_1 itself
1018 returned due to end of file (or end of kbd macro). */
1023 register Lisp_Object val
;
1026 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
1027 while (!NILP (val
));
1035 return Feval (Vtop_level
);
1041 /* On entry to the outer level, run the startup file */
1042 if (!NILP (Vtop_level
))
1043 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
1044 else if (!NILP (Vpurify_flag
))
1045 message ("Bare impure Emacs (standard Lisp code not loaded)");
1047 message ("Bare Emacs (standard Lisp code not loaded)");
1051 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
1052 "Exit all recursive editing levels.")
1055 Fthrow (Qtop_level
, Qnil
);
1058 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
1059 "Exit from the innermost recursive edit or minibuffer.")
1062 if (command_loop_level
> 0 || minibuf_level
> 0)
1063 Fthrow (Qexit
, Qnil
);
1065 error ("No recursive edit is in progress");
1068 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
1069 "Abort the command that requested this recursive edit or minibuffer input.")
1072 if (command_loop_level
> 0 || minibuf_level
> 0)
1075 error ("No recursive edit is in progress");
1078 /* This is the actual command reading loop,
1079 sans error-handling encapsulation. */
1081 Lisp_Object
Fcommand_execute ();
1082 static int read_key_sequence ();
1083 void safe_run_hooks ();
1088 Lisp_Object cmd
, tem
;
1091 Lisp_Object keybuf
[30];
1096 struct buffer
*prev_buffer
;
1098 int was_locked
= single_kboard
;
1101 current_kboard
->Vprefix_arg
= Qnil
;
1102 Vdeactivate_mark
= Qnil
;
1103 waiting_for_input
= 0;
1108 this_command_key_count
= 0;
1109 this_single_command_key_start
= 0;
1111 /* Make sure this hook runs after commands that get errors and
1112 throw to top level. */
1113 /* Note that the value cell will never directly contain nil
1114 if the symbol is a local variable. */
1115 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1116 safe_run_hooks (Qpost_command_hook
);
1118 if (!NILP (Vdeferred_action_list
))
1119 call0 (Vdeferred_action_function
);
1121 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1123 if (NILP (Vunread_command_events
)
1124 && NILP (Vexecuting_macro
)
1125 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1, 1)))
1126 safe_run_hooks (Qpost_command_idle_hook
);
1129 /* Do this after running Vpost_command_hook, for consistency. */
1130 current_kboard
->Vlast_command
= this_command
;
1134 /* Make sure the current window's buffer is selected. */
1135 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1136 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1138 /* Display any malloc warning that just came out. Use while because
1139 displaying one warning can cause another. */
1141 while (pending_malloc_warning
)
1142 display_malloc_warning ();
1146 Vdeactivate_mark
= Qnil
;
1148 /* If minibuffer on and echo area in use,
1149 wait 2 sec and redraw minibuffer. */
1151 if (minibuf_level
&& echo_area_glyphs
1152 && EQ (minibuf_window
, echo_area_window
))
1154 /* Bind inhibit-quit to t so that C-g gets read in
1155 rather than quitting back to the minibuffer. */
1156 int count
= specpdl_ptr
- specpdl
;
1157 specbind (Qinhibit_quit
, Qt
);
1159 Fsit_for (make_number (2), Qnil
, Qnil
);
1160 /* Clear the echo area. */
1162 safe_run_hooks (Qecho_area_clear_hook
);
1164 unbind_to (count
, Qnil
);
1166 /* If a C-g came in before, treat it as input now. */
1167 if (!NILP (Vquit_flag
))
1170 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1175 alloca (0); /* Cause a garbage collection now */
1176 /* Since we can free the most stuff here. */
1177 #endif /* C_ALLOCA */
1180 /* Select the frame that the last event came from. Usually,
1181 switch-frame events will take care of this, but if some lisp
1182 code swallows a switch-frame event, we'll fix things up here.
1183 Is this a good idea? */
1184 if (FRAMEP (internal_last_event_frame
)
1185 && XFRAME (internal_last_event_frame
) != selected_frame
)
1186 Fselect_frame (internal_last_event_frame
, Qnil
);
1188 /* If it has changed current-menubar from previous value,
1189 really recompute the menubar from the value. */
1190 if (! NILP (Vlucid_menu_bar_dirty_flag
)
1191 && !NILP (Ffboundp (Qrecompute_lucid_menubar
)))
1192 call0 (Qrecompute_lucid_menubar
);
1194 before_command_key_count
= this_command_key_count
;
1195 before_command_echo_length
= echo_length ();
1197 this_command
= Qnil
;
1199 /* Read next key sequence; i gets its length. */
1200 i
= read_key_sequence (keybuf
, sizeof keybuf
/ sizeof keybuf
[0],
1203 /* A filter may have run while we were reading the input. */
1204 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1205 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1209 /* Now we have read a key sequence of length I,
1210 or else I is 0 and we found end of file. */
1212 if (i
== 0) /* End of file -- happens only in */
1213 return Qnil
; /* a kbd macro, at the end. */
1214 /* -1 means read_key_sequence got a menu that was rejected.
1215 Just loop around and read another command. */
1219 this_command_key_count
= 0;
1220 this_single_command_key_start
= 0;
1224 last_command_char
= keybuf
[i
- 1];
1226 /* If the previous command tried to force a specific window-start,
1227 forget about that, in case this command moves point far away
1228 from that position. But also throw away beg_unchanged and
1229 end_unchanged information in that case, so that redisplay will
1230 update the whole window properly. */
1231 if (!NILP (XWINDOW (selected_window
)->force_start
))
1233 XWINDOW (selected_window
)->force_start
= Qnil
;
1234 beg_unchanged
= end_unchanged
= 0;
1237 cmd
= read_key_sequence_cmd
;
1238 if (!NILP (Vexecuting_macro
))
1240 if (!NILP (Vquit_flag
))
1242 Vexecuting_macro
= Qt
;
1243 QUIT
; /* Make some noise. */
1244 /* Will return since macro now empty. */
1248 /* Do redisplay processing after this command except in special
1249 cases identified below that set no_redisplay to 1.
1250 (actually, there's currently no way to prevent the redisplay,
1251 and no_redisplay is ignored.
1252 Perhaps someday we will really implement it.) */
1255 prev_buffer
= current_buffer
;
1256 prev_modiff
= MODIFF
;
1257 last_point_position
= PT
;
1258 XSETBUFFER (last_point_position_buffer
, prev_buffer
);
1260 /* Execute the command. */
1263 /* Note that the value cell will never directly contain nil
1264 if the symbol is a local variable. */
1265 if (!NILP (Vpre_command_hook
) && !NILP (Vrun_hooks
))
1266 safe_run_hooks (Qpre_command_hook
);
1268 if (NILP (this_command
))
1270 /* nil means key is undefined. */
1272 current_kboard
->defining_kbd_macro
= Qnil
;
1273 update_mode_lines
= 1;
1274 current_kboard
->Vprefix_arg
= Qnil
;
1278 if (NILP (current_kboard
->Vprefix_arg
) && ! no_direct
)
1280 /* Recognize some common commands in common situations and
1281 do them directly. */
1282 if (EQ (this_command
, Qforward_char
) && PT
< ZV
)
1284 struct Lisp_Char_Table
*dp
1285 = window_display_table (XWINDOW (selected_window
));
1286 lose
= FETCH_BYTE (PT
);
1287 SET_PT (forward_point (1));
1289 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1290 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1291 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1292 && (lose
>= 0x20 && lose
< 0x7f)))
1293 : (lose
>= 0x20 && lose
< 0x7f))
1294 /* To extract the case of continuation on
1295 wide-column characters. */
1296 && (WIDTH_BY_CHAR_HEAD (FETCH_BYTE (PT
)) == 1)
1297 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1299 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1301 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1303 && !windows_or_buffers_changed
1304 && EQ (current_buffer
->selective_display
, Qnil
)
1305 && !detect_input_pending ()
1306 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1307 && NILP (Vexecuting_macro
))
1308 no_redisplay
= direct_output_forward_char (1);
1311 else if (EQ (this_command
, Qbackward_char
) && PT
> BEGV
)
1313 struct Lisp_Char_Table
*dp
1314 = window_display_table (XWINDOW (selected_window
));
1315 SET_PT (forward_point (-1));
1316 lose
= FETCH_BYTE (PT
);
1318 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1319 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1320 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1321 && (lose
>= 0x20 && lose
< 0x7f)))
1322 : (lose
>= 0x20 && lose
< 0x7f))
1323 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1325 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1327 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1329 && !windows_or_buffers_changed
1330 && EQ (current_buffer
->selective_display
, Qnil
)
1331 && !detect_input_pending ()
1332 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1333 && NILP (Vexecuting_macro
))
1334 no_redisplay
= direct_output_forward_char (-1);
1337 else if (EQ (this_command
, Qself_insert_command
)
1338 /* Try this optimization only on ascii keystrokes. */
1339 && INTEGERP (last_command_char
))
1341 unsigned int c
= XINT (last_command_char
);
1344 if (NILP (Vexecuting_macro
)
1345 && !EQ (minibuf_window
, selected_window
))
1347 if (!nonundocount
|| nonundocount
>= 20)
1354 lose
= ((XFASTINT (XWINDOW (selected_window
)->last_modified
)
1356 || (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1358 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1360 || MODIFF
<= SAVE_MODIFF
1361 || windows_or_buffers_changed
1362 || !EQ (current_buffer
->selective_display
, Qnil
)
1363 || detect_input_pending ()
1364 || !NILP (XWINDOW (selected_window
)->column_number_displayed
)
1365 || !NILP (Vexecuting_macro
));
1366 value
= internal_self_insert (c
, 0);
1373 && (PT
== ZV
|| FETCH_BYTE (PT
) == '\n'))
1375 struct Lisp_Char_Table
*dp
1376 = window_display_table (XWINDOW (selected_window
));
1379 /* Add the offset to the character, for Finsert_char.
1380 We pass internal_self_insert the unmodified character
1381 because it itself does this offsetting. */
1382 if (lose
>= 0200 && lose
<= 0377
1383 && ! NILP (current_buffer
->enable_multibyte_characters
))
1384 lose
+= nonascii_insert_offset
;
1390 obj
= DISP_CHAR_VECTOR (dp
, lose
);
1393 /* Do it only for char codes
1394 that by default display as themselves. */
1395 if (lose
>= 0x20 && lose
<= 0x7e)
1396 no_redisplay
= direct_output_for_insert (lose
);
1398 else if (VECTORP (obj
)
1399 && XVECTOR (obj
)->size
== 1
1400 && (obj
= XVECTOR (obj
)->contents
[0],
1402 /* Insist face not specified in glyph. */
1403 && (XINT (obj
) & ((-1) << 8)) == 0)
1405 = direct_output_for_insert (XINT (obj
));
1409 if (lose
>= 0x20 && lose
<= 0x7e)
1410 no_redisplay
= direct_output_for_insert (lose
);
1417 /* Here for a command that isn't executed directly */
1420 if (NILP (current_kboard
->Vprefix_arg
))
1422 Fcommand_execute (this_command
, Qnil
, Qnil
, Qnil
);
1427 /* If there is a prefix argument,
1428 1) We don't want Vlast_command to be ``universal-argument''
1429 (that would be dumb), so don't set Vlast_command,
1430 2) we want to leave echoing on so that the prefix will be
1431 echoed as part of this key sequence, so don't call
1433 3) we want to leave this_command_key_count non-zero, so that
1434 read_char will realize that it is re-reading a character, and
1435 not echo it a second time.
1437 If the command didn't actually create a prefix arg,
1438 but is merely a frame event that is transparent to prefix args,
1439 then the above doesn't apply. */
1440 if (NILP (current_kboard
->Vprefix_arg
) || CONSP (last_command_char
))
1442 current_kboard
->Vlast_command
= this_command
;
1444 this_command_key_count
= 0;
1445 this_single_command_key_start
= 0;
1448 /* Note that the value cell will never directly contain nil
1449 if the symbol is a local variable. */
1450 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1451 safe_run_hooks (Qpost_command_hook
);
1453 if (!NILP (Vdeferred_action_list
))
1454 safe_run_hooks (Qdeferred_action_function
);
1456 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1458 if (NILP (Vunread_command_events
)
1459 && NILP (Vexecuting_macro
)
1460 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1, 1)))
1461 safe_run_hooks (Qpost_command_idle_hook
);
1464 if (!NILP (current_buffer
->mark_active
) && !NILP (Vrun_hooks
))
1466 if (!NILP (Vdeactivate_mark
) && !NILP (Vtransient_mark_mode
))
1468 current_buffer
->mark_active
= Qnil
;
1469 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
1471 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
1472 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
1476 /* Install chars successfully executed in kbd macro. */
1478 if (!NILP (current_kboard
->defining_kbd_macro
)
1479 && NILP (current_kboard
->Vprefix_arg
))
1480 finalize_kbd_macro_chars ();
1484 any_kboard_state ();
1489 /* Subroutine for safe_run_hooks: run the hook HOOK. */
1492 safe_run_hooks_1 (hook
)
1495 return call1 (Vrun_hooks
, Vinhibit_quit
);
1498 /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */
1501 safe_run_hooks_error (data
)
1504 Fset (Vinhibit_quit
, Qnil
);
1507 /* If we get an error while running the hook, cause the hook variable
1508 to be nil. Also inhibit quits, so that C-g won't cause the hook
1509 to mysteriously evaporate. */
1512 safe_run_hooks (hook
)
1516 int count
= specpdl_ptr
- specpdl
;
1517 specbind (Qinhibit_quit
, hook
);
1519 internal_condition_case (safe_run_hooks_1
, Qt
, safe_run_hooks_error
);
1521 unbind_to (count
, Qnil
);
1524 /* Number of seconds between polling for input. */
1527 /* Nonzero means polling for input is temporarily suppressed. */
1528 int poll_suppress_count
;
1530 /* Nonzero if polling_for_input is actually being used. */
1531 int polling_for_input
;
1533 #ifdef POLL_FOR_INPUT
1535 /* Handle an alarm once each second and read pending input
1536 so as to handle a C-g if it comces in. */
1539 input_poll_signal (signalnum
) /* If we don't have an argument, */
1540 int signalnum
; /* some compilers complain in signal calls. */
1542 /* This causes the call to start_polling at the end
1543 to do its job. It also arranges for a quit or error
1544 from within read_avail_input to resume polling. */
1545 poll_suppress_count
++;
1546 if (interrupt_input_blocked
== 0
1547 && !waiting_for_input
)
1548 read_avail_input (0);
1549 /* Turn on the SIGALRM handler and request another alarm. */
1555 /* Begin signals to poll for input, if they are appropriate.
1556 This function is called unconditionally from various places. */
1561 #ifdef POLL_FOR_INPUT
1562 if (read_socket_hook
&& !interrupt_input
)
1564 poll_suppress_count
--;
1565 if (poll_suppress_count
== 0)
1567 signal (SIGALRM
, input_poll_signal
);
1568 polling_for_input
= 1;
1569 alarm (polling_period
);
1575 /* Nonzero if we are using polling to handle input asynchronously. */
1578 input_polling_used ()
1580 #ifdef POLL_FOR_INPUT
1581 return read_socket_hook
&& !interrupt_input
;
1587 /* Turn off polling. */
1592 #ifdef POLL_FOR_INPUT
1593 if (read_socket_hook
&& !interrupt_input
)
1595 if (poll_suppress_count
== 0)
1597 polling_for_input
= 0;
1600 poll_suppress_count
++;
1605 /* Set the value of poll_suppress_count to COUNT
1606 and start or stop polling accordingly. */
1609 set_poll_suppress_count (count
)
1612 #ifdef POLL_FOR_INPUT
1613 if (count
== 0 && poll_suppress_count
!= 0)
1615 poll_suppress_count
= 1;
1618 else if (count
!= 0 && poll_suppress_count
== 0)
1622 poll_suppress_count
= count
;
1626 /* Bind polling_period to a value at least N.
1627 But don't decrease it. */
1630 bind_polling_period (n
)
1633 #ifdef POLL_FOR_INPUT
1634 int new = polling_period
;
1640 specbind (Qpolling_period
, make_number (new));
1641 /* Start a new alarm with the new period. */
1646 /* Apply the control modifier to CHARACTER. */
1652 /* Save the upper bits here. */
1653 int upper
= c
& ~0177;
1657 /* Everything in the columns containing the upper-case letters
1658 denotes a control character. */
1659 if (c
>= 0100 && c
< 0140)
1663 /* Set the shift modifier for a control char
1664 made from a shifted letter. But only for letters! */
1665 if (oc
>= 'A' && oc
<= 'Z')
1666 c
|= shift_modifier
;
1669 /* The lower-case letters denote control characters too. */
1670 else if (c
>= 'a' && c
<= 'z')
1673 /* Include the bits for control and shift
1674 only if the basic ASCII code can't indicate them. */
1678 /* Replace the high bits. */
1679 c
|= (upper
& ~ctrl_modifier
);
1686 /* Input of single characters from keyboard */
1688 Lisp_Object
print_help ();
1689 static Lisp_Object
kbd_buffer_get_event ();
1690 static void record_char ();
1693 static jmp_buf wrong_kboard_jmpbuf
;
1696 /* read a character from the keyboard; call the redisplay if needed */
1697 /* commandflag 0 means do not do auto-saving, but do do redisplay.
1698 -1 means do not do redisplay, but do do autosaving.
1701 /* The arguments MAPS and NMAPS are for menu prompting.
1702 MAPS is an array of keymaps; NMAPS is the length of MAPS.
1704 PREV_EVENT is the previous input event, or nil if we are reading
1705 the first event of a key sequence.
1707 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
1708 if we used a mouse menu to read the input, or zero otherwise. If
1709 USED_MOUSE_MENU is null, we don't dereference it.
1711 Value is t if we showed a menu and the user rejected it. */
1714 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
)
1718 Lisp_Object prev_event
;
1719 int *used_mouse_menu
;
1723 jmp_buf local_getcjmp
;
1725 int key_already_recorded
= 0;
1726 Lisp_Object tem
, save
;
1727 Lisp_Object also_record
;
1728 struct gcpro gcpro1
;
1732 before_command_key_count
= this_command_key_count
;
1733 before_command_echo_length
= echo_length ();
1740 if (CONSP (Vunread_command_events
))
1742 c
= XCONS (Vunread_command_events
)->car
;
1743 Vunread_command_events
= XCONS (Vunread_command_events
)->cdr
;
1745 /* Undo what read_char_x_menu_prompt did when it unread
1746 additional keys returned by Fx_popup_menu. */
1748 && (SYMBOLP (XCONS (c
)->car
) || INTEGERP (XCONS (c
)->car
))
1749 && NILP (XCONS (c
)->cdr
))
1752 if (this_command_key_count
== 0)
1758 if (unread_command_char
!= -1)
1760 XSETINT (c
, unread_command_char
);
1761 unread_command_char
= -1;
1763 if (this_command_key_count
== 0)
1769 /* If there is no function key translated before
1770 reset-this-command-lengths takes effect, forget about it. */
1771 before_command_restore_flag
= 0;
1773 if (!NILP (Vexecuting_macro
))
1775 /* We set this to Qmacro; since that's not a frame, nobody will
1776 try to switch frames on us, and the selected window will
1779 Since this event came from a macro, it would be misleading to
1780 leave internal_last_event_frame set to wherever the last
1781 real event came from. Normally, a switch-frame event selects
1782 internal_last_event_frame after each command is read, but
1783 events read from a macro should never cause a new frame to be
1785 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
1787 /* Exit the macro if we are at the end.
1788 Also, some things replace the macro with t
1789 to force an early exit. */
1790 if (EQ (Vexecuting_macro
, Qt
)
1791 || executing_macro_index
>= XFASTINT (Flength (Vexecuting_macro
)))
1797 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
1798 if (STRINGP (Vexecuting_macro
)
1799 && (XINT (c
) & 0x80))
1800 XSETFASTINT (c
, CHAR_META
| (XINT (c
) & ~0x80));
1802 executing_macro_index
++;
1807 if (!NILP (unread_switch_frame
))
1809 c
= unread_switch_frame
;
1810 unread_switch_frame
= Qnil
;
1812 /* This event should make it into this_command_keys, and get echoed
1813 again, so we go to reread_first, rather than reread. */
1817 if (commandflag
>= 0)
1820 || detect_input_pending_run_timers (0))
1827 /* Message turns off echoing unless more keystrokes turn it on again. */
1828 if (echo_area_glyphs
&& *echo_area_glyphs
1829 && echo_area_glyphs
!= current_kboard
->echobuf
1830 && ok_to_echo_at_next_pause
!= echo_area_glyphs
)
1833 /* If already echoing, continue. */
1836 /* Try reading a character via menu prompting in the minibuf.
1837 Try this before the sit-for, because the sit-for
1838 would do the wrong thing if we are supposed to do
1839 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
1840 after a mouse event so don't try a minibuf menu. */
1842 if (nmaps
> 0 && INTERACTIVE
1843 && !NILP (prev_event
) && ! EVENT_HAS_PARAMETERS (prev_event
)
1844 /* Don't bring up a menu if we already have another event. */
1845 && NILP (Vunread_command_events
)
1846 && unread_command_char
< 0
1847 && !detect_input_pending_run_timers (0))
1849 c
= read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
);
1852 key_already_recorded
= 1;
1857 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet.
1858 We will do that below, temporarily for short sections of code,
1859 when appropriate. local_getcjmp must be in effect
1860 around any call to sit_for or kbd_buffer_get_event;
1861 it *must not* be in effect when we call redisplay. */
1863 if (_setjmp (local_getcjmp
))
1865 XSETINT (c
, quit_char
);
1866 XSETFRAME (internal_last_event_frame
, selected_frame
);
1867 Vlast_event_frame
= internal_last_event_frame
;
1868 /* If we report the quit char as an event,
1869 don't do so more than once. */
1870 if (!NILP (Vinhibit_quit
))
1875 KBOARD
*kb
= FRAME_KBOARD (selected_frame
);
1876 if (kb
!= current_kboard
)
1878 Lisp_Object
*tailp
= &kb
->kbd_queue
;
1879 /* We shouldn't get here if we were in single-kboard mode! */
1882 while (CONSP (*tailp
))
1883 tailp
= &XCONS (*tailp
)->cdr
;
1886 *tailp
= Fcons (c
, Qnil
);
1887 kb
->kbd_queue_has_data
= 1;
1888 current_kboard
= kb
;
1889 /* This is going to exit from read_char
1890 so we had better get rid of this frame's stuff. */
1892 longjmp (wrong_kboard_jmpbuf
, 1);
1899 timer_start_idle ();
1901 /* If in middle of key sequence and minibuffer not active,
1902 start echoing if enough time elapses. */
1904 if (minibuf_level
== 0 && !current_kboard
->immediate_echo
1905 && this_command_key_count
> 0
1907 && echo_keystrokes
> 0
1908 && (echo_area_glyphs
== 0 || *echo_area_glyphs
== 0
1909 || ok_to_echo_at_next_pause
== echo_area_glyphs
))
1913 /* After a mouse event, start echoing right away.
1914 This is because we are probably about to display a menu,
1915 and we don't want to delay before doing so. */
1916 if (EVENT_HAS_PARAMETERS (prev_event
))
1920 save_getcjmp (save_jump
);
1921 restore_getcjmp (local_getcjmp
);
1922 tem0
= sit_for (echo_keystrokes
, 0, 1, 1, 0);
1923 restore_getcjmp (save_jump
);
1925 && ! CONSP (Vunread_command_events
))
1930 /* Maybe auto save due to number of keystrokes. */
1932 if (commandflag
!= 0
1933 && auto_save_interval
> 0
1934 && num_nonmacro_input_events
- last_auto_save
> max (auto_save_interval
, 20)
1935 && !detect_input_pending_run_timers (0))
1937 Fdo_auto_save (Qnil
, Qnil
);
1938 /* Hooks can actually change some buffers in auto save. */
1942 /* Try reading using an X menu.
1943 This is never confused with reading using the minibuf
1944 because the recursive call of read_char in read_char_minibuf_menu_prompt
1945 does not pass on any keymaps. */
1947 if (nmaps
> 0 && INTERACTIVE
1948 && !NILP (prev_event
)
1949 && EVENT_HAS_PARAMETERS (prev_event
)
1950 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
)
1951 /* Don't bring up a menu if we already have another event. */
1952 && NILP (Vunread_command_events
)
1953 && unread_command_char
< 0)
1955 c
= read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
1957 /* Now that we have read an event, Emacs is not idle. */
1963 /* Maybe autosave and/or garbage collect due to idleness. */
1965 if (INTERACTIVE
&& NILP (c
))
1967 int delay_level
, buffer_size
;
1969 /* Slow down auto saves logarithmically in size of current buffer,
1970 and garbage collect while we're at it. */
1971 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
1972 last_non_minibuf_size
= Z
- BEG
;
1973 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
1975 while (buffer_size
> 64)
1976 delay_level
++, buffer_size
-= buffer_size
>> 2;
1977 if (delay_level
< 4) delay_level
= 4;
1978 /* delay_level is 4 for files under around 50k, 7 at 100k,
1979 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
1981 /* Auto save if enough time goes by without input. */
1982 if (commandflag
!= 0
1983 && num_nonmacro_input_events
> last_auto_save
1984 && INTEGERP (Vauto_save_timeout
)
1985 && XINT (Vauto_save_timeout
) > 0)
1989 save_getcjmp (save_jump
);
1990 restore_getcjmp (local_getcjmp
);
1991 tem0
= sit_for (delay_level
* XFASTINT (Vauto_save_timeout
) / 4,
1993 restore_getcjmp (save_jump
);
1996 && ! CONSP (Vunread_command_events
))
1998 Fdo_auto_save (Qnil
, Qnil
);
2000 /* If we have auto-saved and there is still no input
2001 available, garbage collect if there has been enough
2002 consing going on to make it worthwhile. */
2003 if (!detect_input_pending_run_timers (0)
2004 && consing_since_gc
> gc_cons_threshold
/ 2)
2005 Fgarbage_collect ();
2012 /* If this has become non-nil here, it has been set by a timer
2013 or sentinel or filter. */
2014 if (CONSP (Vunread_command_events
))
2016 c
= XCONS (Vunread_command_events
)->car
;
2017 Vunread_command_events
= XCONS (Vunread_command_events
)->cdr
;
2020 /* Read something from current KBOARD's side queue, if possible. */
2024 if (current_kboard
->kbd_queue_has_data
)
2026 if (!CONSP (current_kboard
->kbd_queue
))
2028 c
= XCONS (current_kboard
->kbd_queue
)->car
;
2029 current_kboard
->kbd_queue
2030 = XCONS (current_kboard
->kbd_queue
)->cdr
;
2031 if (NILP (current_kboard
->kbd_queue
))
2032 current_kboard
->kbd_queue_has_data
= 0;
2033 input_pending
= readable_events (0);
2034 if (EVENT_HAS_PARAMETERS (c
)
2035 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qswitch_frame
))
2036 internal_last_event_frame
= XCONS (XCONS (c
)->cdr
)->car
;
2037 Vlast_event_frame
= internal_last_event_frame
;
2042 /* If current_kboard's side queue is empty check the other kboards.
2043 If one of them has data that we have not yet seen here,
2044 switch to it and process the data waiting for it.
2046 Note: if the events queued up for another kboard
2047 have already been seen here, and therefore are not a complete command,
2048 the kbd_queue_has_data field is 0, so we skip that kboard here.
2049 That's to avoid an infinite loop switching between kboards here. */
2050 if (NILP (c
) && !single_kboard
)
2053 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2054 if (kb
->kbd_queue_has_data
)
2056 current_kboard
= kb
;
2057 /* This is going to exit from read_char
2058 so we had better get rid of this frame's stuff. */
2060 longjmp (wrong_kboard_jmpbuf
, 1);
2069 /* Finally, we read from the main queue,
2070 and if that gives us something we can't use yet, we put it on the
2071 appropriate side queue and try again. */
2077 /* Actually read a character, waiting if necessary. */
2078 save_getcjmp (save_jump
);
2079 restore_getcjmp (local_getcjmp
);
2080 c
= kbd_buffer_get_event (&kb
, used_mouse_menu
);
2081 restore_getcjmp (save_jump
);
2084 if (! NILP (c
) && (kb
!= current_kboard
))
2086 Lisp_Object
*tailp
= &kb
->kbd_queue
;
2087 while (CONSP (*tailp
))
2088 tailp
= &XCONS (*tailp
)->cdr
;
2091 *tailp
= Fcons (c
, Qnil
);
2092 kb
->kbd_queue_has_data
= 1;
2096 current_kboard
= kb
;
2097 /* This is going to exit from read_char
2098 so we had better get rid of this frame's stuff. */
2100 longjmp (wrong_kboard_jmpbuf
, 1);
2105 /* Terminate Emacs in batch mode if at eof. */
2106 if (noninteractive
&& INTEGERP (c
) && XINT (c
) < 0)
2107 Fkill_emacs (make_number (1));
2111 /* Add in any extra modifiers, where appropriate. */
2112 if ((extra_keyboard_modifiers
& CHAR_CTL
)
2113 || ((extra_keyboard_modifiers
& 0177) < ' '
2114 && (extra_keyboard_modifiers
& 0177) != 0))
2115 XSETINT (c
, make_ctrl_char (XINT (c
)));
2117 /* Transfer any other modifier bits directly from
2118 extra_keyboard_modifiers to c. Ignore the actual character code
2119 in the low 16 bits of extra_keyboard_modifiers. */
2120 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
2131 if (commandflag
>= 0
2132 && !input_pending
&& !detect_input_pending_run_timers (0))
2140 /* Buffer switch events are only for internal wakeups
2141 so don't show them to the user.
2142 Also, don't record a key if we already did. */
2143 if (BUFFERP (c
) || key_already_recorded
)
2146 /* Process special events within read_char
2147 and loop around to read another event. */
2150 tem
= get_keyelt (access_keymap (get_keymap_1 (Vspecial_event_map
, 0, 0),
2156 int was_locked
= single_kboard
;
2158 last_input_char
= c
;
2159 Fcommand_execute (tem
, Qnil
, Fvector (1, &last_input_char
), Qt
);
2161 /* Resume allowing input from any kboard, if that was true before. */
2163 any_kboard_state ();
2168 /* Wipe the echo area. */
2169 if (echo_area_glyphs
)
2170 safe_run_hooks (Qecho_area_clear_hook
);
2171 echo_area_glyphs
= 0;
2173 /* Handle things that only apply to characters. */
2176 /* If kbd_buffer_get_event gave us an EOF, return that. */
2180 if (STRINGP (Vkeyboard_translate_table
)
2181 && XSTRING (Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
2182 XSETINT (c
, XSTRING (Vkeyboard_translate_table
)->data
[XFASTINT (c
)]);
2183 else if ((VECTORP (Vkeyboard_translate_table
)
2184 && XVECTOR (Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
2185 || (CHAR_TABLE_P (Vkeyboard_translate_table
)
2186 && CHAR_TABLE_ORDINARY_SLOTS
> (unsigned) XFASTINT (c
)))
2189 d
= Faref (Vkeyboard_translate_table
, c
);
2190 /* nil in keyboard-translate-table means no translation. */
2196 /* If this event is a mouse click in the menu bar,
2197 return just menu-bar for now. Modify the mouse click event
2198 so we won't do this twice, then queue it up. */
2199 if (EVENT_HAS_PARAMETERS (c
)
2200 && CONSP (XCONS (c
)->cdr
)
2201 && CONSP (EVENT_START (c
))
2202 && CONSP (XCONS (EVENT_START (c
))->cdr
))
2206 posn
= POSN_BUFFER_POSN (EVENT_START (c
));
2207 /* Handle menu-bar events:
2208 insert the dummy prefix event `menu-bar'. */
2209 if (EQ (posn
, Qmenu_bar
))
2211 /* Change menu-bar to (menu-bar) as the event "position". */
2212 POSN_BUFFER_POSN (EVENT_START (c
)) = Fcons (posn
, Qnil
);
2215 Vunread_command_events
= Fcons (c
, Vunread_command_events
);
2221 if (! NILP (also_record
))
2222 record_char (also_record
);
2227 before_command_key_count
= this_command_key_count
;
2228 before_command_echo_length
= echo_length ();
2230 /* Don't echo mouse motion events. */
2232 && ! (EVENT_HAS_PARAMETERS (c
)
2233 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
2236 if (! NILP (also_record
))
2237 echo_char (also_record
);
2238 /* Once we reread a character, echoing can happen
2239 the next time we pause to read a new one. */
2240 ok_to_echo_at_next_pause
= echo_area_glyphs
;
2243 /* Record this character as part of the current key. */
2244 add_command_key (c
);
2245 if (! NILP (also_record
))
2246 add_command_key (also_record
);
2248 /* Re-reading in the middle of a command */
2250 last_input_char
= c
;
2253 /* Process the help character specially if enabled */
2254 if (!NILP (Vhelp_form
) && help_char_p (c
))
2257 count
= specpdl_ptr
- specpdl
;
2259 record_unwind_protect (Fset_window_configuration
,
2260 Fcurrent_window_configuration (Qnil
));
2262 tem0
= Feval (Vhelp_form
);
2264 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
2268 c
= read_char (0, 0, 0, Qnil
, 0);
2269 while (BUFFERP (c
));
2270 /* Remove the help from the frame */
2271 unbind_to (count
, Qnil
);
2274 if (EQ (c
, make_number (040)))
2278 c
= read_char (0, 0, 0, Qnil
, 0);
2279 while (BUFFERP (c
));
2286 /* Record a key that came from a mouse menu.
2287 Record it for echoing, for this-command-keys, and so on. */
2293 /* Wipe the echo area. */
2294 echo_area_glyphs
= 0;
2298 before_command_key_count
= this_command_key_count
;
2299 before_command_echo_length
= echo_length ();
2301 /* Don't echo mouse motion events. */
2302 if (echo_keystrokes
)
2306 /* Once we reread a character, echoing can happen
2307 the next time we pause to read a new one. */
2308 ok_to_echo_at_next_pause
= 0;
2311 /* Record this character as part of the current key. */
2312 add_command_key (c
);
2314 /* Re-reading in the middle of a command */
2315 last_input_char
= c
;
2319 /* Return 1 if should recognize C as "the help character". */
2327 if (EQ (c
, Vhelp_char
))
2329 for (tail
= Vhelp_event_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
2330 if (EQ (c
, XCONS (tail
)->car
))
2335 /* Record the input event C in various ways. */
2342 XVECTOR (recent_keys
)->contents
[recent_keys_index
] = c
;
2343 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
2344 recent_keys_index
= 0;
2346 /* Write c to the dribble file. If c is a lispy event, write
2347 the event's symbol to the dribble file, in <brackets>. Bleaugh.
2348 If you, dear reader, have a better idea, you've got the source. :-) */
2353 if (XUINT (c
) < 0x100)
2354 putc (XINT (c
), dribble
);
2356 fprintf (dribble
, " 0x%x", (int) XUINT (c
));
2360 Lisp_Object dribblee
;
2362 /* If it's a structured event, take the event header. */
2363 dribblee
= EVENT_HEAD (c
);
2365 if (SYMBOLP (dribblee
))
2367 putc ('<', dribble
);
2368 fwrite (XSYMBOL (dribblee
)->name
->data
, sizeof (char),
2369 XSYMBOL (dribblee
)->name
->size
,
2371 putc ('>', dribble
);
2378 store_kbd_macro_char (c
);
2380 num_nonmacro_input_events
++;
2387 struct buffer
*old
= current_buffer
;
2388 Fprinc (object
, Qnil
);
2389 set_buffer_internal (XBUFFER (Vstandard_output
));
2390 call0 (intern ("help-mode"));
2391 set_buffer_internal (old
);
2395 /* Copy out or in the info on where C-g should throw to.
2396 This is used when running Lisp code from within get_char,
2397 in case get_char is called recursively.
2398 See read_process_output. */
2403 bcopy (getcjmp
, temp
, sizeof getcjmp
);
2406 restore_getcjmp (temp
)
2409 bcopy (temp
, getcjmp
, sizeof getcjmp
);
2414 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
2415 of this function. */
2418 tracking_off (old_value
)
2419 Lisp_Object old_value
;
2421 do_mouse_tracking
= old_value
;
2422 if (NILP (old_value
))
2424 /* Redisplay may have been preempted because there was input
2425 available, and it assumes it will be called again after the
2426 input has been processed. If the only input available was
2427 the sort that we have just disabled, then we need to call
2429 if (!readable_events (1))
2431 redisplay_preserve_echo_area ();
2432 get_input_pending (&input_pending
, 1);
2437 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
2438 "Evaluate BODY with mouse movement events enabled.\n\
2439 Within a `track-mouse' form, mouse motion generates input events that\n\
2440 you can read with `read-event'.\n\
2441 Normally, mouse motion is ignored.")
2445 int count
= specpdl_ptr
- specpdl
;
2448 record_unwind_protect (tracking_off
, do_mouse_tracking
);
2450 do_mouse_tracking
= Qt
;
2452 val
= Fprogn (args
);
2453 return unbind_to (count
, val
);
2456 /* If mouse has moved on some frame, return one of those frames.
2457 Return 0 otherwise. */
2462 Lisp_Object tail
, frame
;
2464 FOR_EACH_FRAME (tail
, frame
)
2466 if (XFRAME (frame
)->mouse_moved
)
2467 return XFRAME (frame
);
2473 #endif /* HAVE_MOUSE */
2475 /* Low level keyboard/mouse input.
2476 kbd_buffer_store_event places events in kbd_buffer, and
2477 kbd_buffer_get_event retrieves them. */
2479 /* Return true iff there are any events in the queue that read-char
2480 would return. If this returns false, a read-char would block. */
2482 readable_events (do_timers_now
)
2486 timer_check (do_timers_now
);
2488 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2491 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2496 if (current_kboard
->kbd_queue_has_data
)
2502 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2503 if (kb
->kbd_queue_has_data
)
2509 /* Set this for debugging, to have a way to get out */
2514 event_to_kboard (event
)
2515 struct input_event
*event
;
2518 frame
= event
->frame_or_window
;
2520 frame
= XCONS (frame
)->car
;
2521 else if (WINDOWP (frame
))
2522 frame
= WINDOW_FRAME (XWINDOW (frame
));
2524 /* There are still some events that don't set this field.
2525 For now, just ignore the problem.
2526 Also ignore dead frames here. */
2527 if (!FRAMEP (frame
) || !FRAME_LIVE_P (XFRAME (frame
)))
2530 return FRAME_KBOARD (XFRAME (frame
));
2534 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
2537 kbd_buffer_store_event (event
)
2538 register struct input_event
*event
;
2540 if (event
->kind
== no_event
)
2543 if (event
->kind
== ascii_keystroke
)
2545 register int c
= event
->code
& 0377;
2547 if (event
->modifiers
& ctrl_modifier
)
2548 c
= make_ctrl_char (c
);
2550 c
|= (event
->modifiers
2551 & (meta_modifier
| alt_modifier
2552 | hyper_modifier
| super_modifier
));
2556 extern SIGTYPE
interrupt_signal ();
2559 struct input_event
*sp
;
2562 && (kb
= FRAME_KBOARD (XFRAME (event
->frame_or_window
)),
2563 kb
!= current_kboard
))
2566 = Fcons (make_lispy_switch_frame (event
->frame_or_window
),
2567 Fcons (make_number (c
), Qnil
));
2568 kb
->kbd_queue_has_data
= 1;
2569 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
2571 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
2574 if (event_to_kboard (sp
) == kb
)
2576 sp
->kind
= no_event
;
2577 sp
->frame_or_window
= Qnil
;
2584 /* If this results in a quit_char being returned to Emacs as
2585 input, set Vlast_event_frame properly. If this doesn't
2586 get returned to Emacs as an event, the next event read
2587 will set Vlast_event_frame again, so this is safe to do. */
2591 focus
= FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
2593 focus
= event
->frame_or_window
;
2594 internal_last_event_frame
= focus
;
2595 Vlast_event_frame
= focus
;
2598 last_event_timestamp
= event
->timestamp
;
2599 interrupt_signal ();
2603 if (c
&& c
== stop_character
)
2609 /* Don't insert two buffer_switch_event's in a row.
2610 Just ignore the second one. */
2611 else if (event
->kind
== buffer_switch_event
2612 && kbd_fetch_ptr
!= kbd_store_ptr
2613 && kbd_store_ptr
->kind
== buffer_switch_event
)
2616 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
2617 kbd_store_ptr
= kbd_buffer
;
2619 /* Don't let the very last slot in the buffer become full,
2620 since that would make the two pointers equal,
2621 and that is indistinguishable from an empty buffer.
2622 Discard the event if it would fill the last slot. */
2623 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
2625 volatile struct input_event
*sp
= kbd_store_ptr
;
2626 sp
->kind
= event
->kind
;
2627 if (event
->kind
== selection_request_event
)
2629 /* We must not use the ordinary copying code for this case,
2630 since `part' is an enum and copying it might not copy enough
2632 bcopy (event
, (char *) sp
, sizeof (*event
));
2636 sp
->code
= event
->code
;
2637 sp
->part
= event
->part
;
2638 sp
->frame_or_window
= event
->frame_or_window
;
2639 sp
->modifiers
= event
->modifiers
;
2642 sp
->timestamp
= event
->timestamp
;
2644 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_store_ptr
2646 = event
->frame_or_window
);
2652 /* Discard any mouse events in the event buffer by setting them to
2655 discard_mouse_events ()
2657 struct input_event
*sp
;
2658 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
2660 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
2663 if (sp
->kind
== mouse_click
2665 || sp
->kind
== w32_scroll_bar_click
2667 || sp
->kind
== scroll_bar_click
)
2669 sp
->kind
= no_event
;
2674 /* Read one event from the event buffer, waiting if necessary.
2675 The value is a Lisp object representing the event.
2676 The value is nil for an event that should be ignored,
2677 or that was handled here.
2678 We always read and discard one event. */
2681 kbd_buffer_get_event (kbp
, used_mouse_menu
)
2683 int *used_mouse_menu
;
2687 EMACS_TIME next_timer_delay
;
2693 *kbp
= current_kboard
;
2697 /* Wait until there is input available. */
2700 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2703 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2707 /* If the quit flag is set, then read_char will return
2708 quit_char, so that counts as "available input." */
2709 if (!NILP (Vquit_flag
))
2710 quit_throw_to_read_char ();
2712 /* One way or another, wait until input is available; then, if
2713 interrupt handlers have not read it, read it now. */
2716 wait_for_kbd_input ();
2718 /* Note SIGIO has been undef'd if FIONREAD is missing. */
2722 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2725 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2729 Lisp_Object minus_one
;
2731 XSETINT (minus_one
, -1);
2732 wait_reading_process_input (0, 0, minus_one
, 1);
2734 if (!interrupt_input
&& kbd_fetch_ptr
== kbd_store_ptr
)
2735 /* Pass 1 for EXPECT since we just waited to have input. */
2736 read_avail_input (1);
2738 #endif /* not VMS */
2741 if (CONSP (Vunread_command_events
))
2744 first
= XCONS (Vunread_command_events
)->car
;
2745 Vunread_command_events
= XCONS (Vunread_command_events
)->cdr
;
2746 *kbp
= current_kboard
;
2750 /* At this point, we know that there is a readable event available
2751 somewhere. If the event queue is empty, then there must be a
2752 mouse movement enabled and available. */
2753 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2755 struct input_event
*event
;
2757 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2761 last_event_timestamp
= event
->timestamp
;
2764 *kbp
= event_to_kboard (event
);
2766 *kbp
= current_kboard
; /* Better than returning null ptr? */
2768 *kbp
= &the_only_kboard
;
2773 /* These two kinds of events get special handling
2774 and don't actually appear to the command loop.
2775 We return nil for them. */
2776 if (event
->kind
== selection_request_event
)
2779 struct input_event copy
;
2781 /* Remove it from the buffer before processing it,
2782 since otherwise swallow_events will see it
2783 and process it again. */
2785 kbd_fetch_ptr
= event
+ 1;
2786 input_pending
= readable_events (0);
2787 x_handle_selection_request (©
);
2789 /* We're getting selection request events, but we don't have
2795 else if (event
->kind
== selection_clear_event
)
2798 struct input_event copy
;
2800 /* Remove it from the buffer before processing it. */
2802 kbd_fetch_ptr
= event
+ 1;
2803 input_pending
= readable_events (0);
2804 x_handle_selection_clear (©
);
2806 /* We're getting selection request events, but we don't have
2811 #if defined (HAVE_X11) || defined (HAVE_NTGUI)
2812 else if (event
->kind
== delete_window_event
)
2814 /* Make an event (delete-frame (FRAME)). */
2815 obj
= Fcons (event
->frame_or_window
, Qnil
);
2816 obj
= Fcons (Qdelete_frame
, Fcons (obj
, Qnil
));
2817 kbd_fetch_ptr
= event
+ 1;
2819 else if (event
->kind
== iconify_event
)
2821 /* Make an event (iconify-frame (FRAME)). */
2822 obj
= Fcons (event
->frame_or_window
, Qnil
);
2823 obj
= Fcons (Qiconify_frame
, Fcons (obj
, Qnil
));
2824 kbd_fetch_ptr
= event
+ 1;
2826 else if (event
->kind
== deiconify_event
)
2828 /* Make an event (make-frame-visible (FRAME)). */
2829 obj
= Fcons (event
->frame_or_window
, Qnil
);
2830 obj
= Fcons (Qmake_frame_visible
, Fcons (obj
, Qnil
));
2831 kbd_fetch_ptr
= event
+ 1;
2834 else if (event
->kind
== buffer_switch_event
)
2836 /* The value doesn't matter here; only the type is tested. */
2837 XSETBUFFER (obj
, current_buffer
);
2838 kbd_fetch_ptr
= event
+ 1;
2840 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
2841 else if (event
->kind
== menu_bar_activate_event
)
2843 kbd_fetch_ptr
= event
+ 1;
2844 input_pending
= readable_events (0);
2845 if (FRAME_LIVE_P (XFRAME (event
->frame_or_window
)))
2846 x_activate_menubar (XFRAME (event
->frame_or_window
));
2849 /* Just discard these, by returning nil.
2850 With MULTI_KBOARD, these events are used as placeholders
2851 when we need to randomly delete events from the queue.
2852 (They shouldn't otherwise be found in the buffer,
2853 but on some machines it appears they do show up
2854 even without MULTI_KBOARD.) */
2855 /* On Windows NT/9X, no_event is used to delete extraneous
2856 mouse events during a popup-menu call. */
2857 else if (event
->kind
== no_event
)
2858 kbd_fetch_ptr
= event
+ 1;
2860 /* If this event is on a different frame, return a switch-frame this
2861 time, and leave the event in the queue for next time. */
2867 frame
= event
->frame_or_window
;
2869 frame
= XCONS (frame
)->car
;
2870 else if (WINDOWP (frame
))
2871 frame
= WINDOW_FRAME (XWINDOW (frame
));
2873 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
2877 if (! EQ (frame
, internal_last_event_frame
)
2878 && XFRAME (frame
) != selected_frame
)
2879 obj
= make_lispy_switch_frame (frame
);
2880 internal_last_event_frame
= frame
;
2882 /* If we didn't decide to make a switch-frame event, go ahead
2883 and build a real event from the queue entry. */
2887 obj
= make_lispy_event (event
);
2888 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
2889 /* If this was a menu selection, then set the flag to inhibit
2890 writing to last_nonmenu_event. Don't do this if the event
2891 we're returning is (menu-bar), though; that indicates the
2892 beginning of the menu sequence, and we might as well leave
2893 that as the `event with parameters' for this selection. */
2894 if (event
->kind
== menu_bar_event
2895 && !(CONSP (obj
) && EQ (XCONS (obj
)->car
, Qmenu_bar
))
2897 *used_mouse_menu
= 1;
2900 /* Wipe out this event, to catch bugs. */
2901 event
->kind
= no_event
;
2902 XVECTOR (kbd_buffer_frame_or_window
)->contents
[event
- kbd_buffer
] = Qnil
;
2904 kbd_fetch_ptr
= event
+ 1;
2909 /* Try generating a mouse motion event. */
2910 else if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2912 FRAME_PTR f
= some_mouse_moved ();
2913 Lisp_Object bar_window
;
2914 enum scroll_bar_part part
;
2918 *kbp
= current_kboard
;
2919 /* Note that this uses F to determine which display to look at.
2920 If there is no valid info, it does not store anything
2921 so x remains nil. */
2923 (*mouse_position_hook
) (&f
, 0, &bar_window
, &part
, &x
, &y
, &time
);
2927 /* Decide if we should generate a switch-frame event. Don't
2928 generate switch-frame events for motion outside of all Emacs
2934 frame
= FRAME_FOCUS_FRAME (f
);
2936 XSETFRAME (frame
, f
);
2938 if (! EQ (frame
, internal_last_event_frame
)
2939 && XFRAME (frame
) != selected_frame
)
2940 obj
= make_lispy_switch_frame (frame
);
2941 internal_last_event_frame
= frame
;
2944 /* If we didn't decide to make a switch-frame event, go ahead and
2945 return a mouse-motion event. */
2946 if (!NILP (x
) && NILP (obj
))
2947 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
2949 #endif /* HAVE_MOUSE */
2951 /* We were promised by the above while loop that there was
2952 something for us to read! */
2955 input_pending
= readable_events (0);
2957 Vlast_event_frame
= internal_last_event_frame
;
2962 /* Process any events that are not user-visible,
2963 then return, without reading any user-visible events. */
2966 swallow_events (do_display
)
2971 while (kbd_fetch_ptr
!= kbd_store_ptr
)
2973 struct input_event
*event
;
2975 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2979 last_event_timestamp
= event
->timestamp
;
2981 /* These two kinds of events get special handling
2982 and don't actually appear to the command loop. */
2983 if (event
->kind
== selection_request_event
)
2986 struct input_event copy
;
2988 /* Remove it from the buffer before processing it,
2989 since otherwise swallow_events called recursively could see it
2990 and process it again. */
2992 kbd_fetch_ptr
= event
+ 1;
2993 input_pending
= readable_events (0);
2994 x_handle_selection_request (©
);
2996 /* We're getting selection request events, but we don't have
3002 else if (event
->kind
== selection_clear_event
)
3005 struct input_event copy
;
3007 /* Remove it from the buffer before processing it, */
3010 kbd_fetch_ptr
= event
+ 1;
3011 input_pending
= readable_events (0);
3012 x_handle_selection_clear (©
);
3014 /* We're getting selection request events, but we don't have
3023 old_timers_run
= timers_run
;
3024 get_input_pending (&input_pending
, 1);
3026 if (timers_run
!= old_timers_run
&& do_display
)
3027 redisplay_preserve_echo_area ();
3030 static EMACS_TIME timer_idleness_start_time
;
3032 /* Record the start of when Emacs is idle,
3033 for the sake of running idle-time timers. */
3040 /* If we are already in the idle state, do nothing. */
3041 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3044 EMACS_GET_TIME (timer_idleness_start_time
);
3046 /* Mark all idle-time timers as once again candidates for running. */
3047 for (timers
= Vtimer_idle_list
; CONSP (timers
); timers
= XCONS (timers
)->cdr
)
3051 timer
= XCONS (timers
)->car
;
3053 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3055 XVECTOR (timer
)->contents
[0] = Qnil
;
3059 /* Record that Emacs is no longer idle, so stop running idle-time timers. */
3064 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
3067 /* This is only for debugging. */
3068 struct input_event last_timer_event
;
3070 /* Check whether a timer has fired. To prevent larger problems we simply
3071 disregard elements that are not proper timers. Do not make a circular
3072 timer list for the time being.
3074 Returns the number of seconds to wait until the next timer fires. If a
3075 timer is triggering now, return zero seconds.
3076 If no timer is active, return -1 seconds.
3078 If a timer is ripe, we run it, with quitting turned off.
3080 DO_IT_NOW is now ignored. It used to mean that we should
3081 run the timer directly instead of queueing a timer-event.
3082 Now we always run timers directly. */
3085 timer_check (do_it_now
)
3088 EMACS_TIME nexttime
;
3089 EMACS_TIME now
, idleness_now
;
3090 Lisp_Object timers
, idle_timers
, chosen_timer
;
3091 struct gcpro gcpro1
, gcpro2
, gcpro3
;
3093 EMACS_SET_SECS (nexttime
, -1);
3094 EMACS_SET_USECS (nexttime
, -1);
3096 /* Always consider the ordinary timers. */
3097 timers
= Vtimer_list
;
3098 /* Consider the idle timers only if Emacs is idle. */
3099 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3100 idle_timers
= Vtimer_idle_list
;
3103 chosen_timer
= Qnil
;
3104 GCPRO3 (timers
, idle_timers
, chosen_timer
);
3106 if (CONSP (timers
) || CONSP (idle_timers
))
3108 EMACS_GET_TIME (now
);
3109 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3110 EMACS_SUB_TIME (idleness_now
, now
, timer_idleness_start_time
);
3113 while (CONSP (timers
) || CONSP (idle_timers
))
3115 int triggertime
= EMACS_SECS (now
);
3116 Lisp_Object
*vector
;
3117 Lisp_Object timer
, idle_timer
;
3118 EMACS_TIME timer_time
, idle_timer_time
;
3119 EMACS_TIME difference
, timer_difference
, idle_timer_difference
;
3121 /* Skip past invalid timers and timers already handled. */
3124 timer
= XCONS (timers
)->car
;
3125 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3127 timers
= XCONS (timers
)->cdr
;
3130 vector
= XVECTOR (timer
)->contents
;
3132 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
3133 || !INTEGERP (vector
[3])
3134 || ! NILP (vector
[0]))
3136 timers
= XCONS (timers
)->cdr
;
3140 if (!NILP (idle_timers
))
3142 timer
= XCONS (idle_timers
)->car
;
3143 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3145 idle_timers
= XCONS (idle_timers
)->cdr
;
3148 vector
= XVECTOR (timer
)->contents
;
3150 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
3151 || !INTEGERP (vector
[3])
3152 || ! NILP (vector
[0]))
3154 idle_timers
= XCONS (idle_timers
)->cdr
;
3159 /* Set TIMER, TIMER_TIME and TIMER_DIFFERENCE
3160 based on the next ordinary timer.
3161 TIMER_DIFFERENCE is the distance in time from NOW to when
3162 this timer becomes ripe (negative if it's already ripe). */
3165 timer
= XCONS (timers
)->car
;
3166 vector
= XVECTOR (timer
)->contents
;
3167 EMACS_SET_SECS (timer_time
,
3168 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
3169 EMACS_SET_USECS (timer_time
, XINT (vector
[3]));
3170 EMACS_SUB_TIME (timer_difference
, timer_time
, now
);
3173 /* Set IDLE_TIMER, IDLE_TIMER_TIME and IDLE_TIMER_DIFFERENCE
3174 based on the next idle timer. */
3175 if (!NILP (idle_timers
))
3177 idle_timer
= XCONS (idle_timers
)->car
;
3178 vector
= XVECTOR (idle_timer
)->contents
;
3179 EMACS_SET_SECS (idle_timer_time
,
3180 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
3181 EMACS_SET_USECS (idle_timer_time
, XINT (vector
[3]));
3182 EMACS_SUB_TIME (idle_timer_difference
, idle_timer_time
, idleness_now
);
3185 /* Decide which timer is the next timer,
3186 and set CHOSEN_TIMER, VECTOR and DIFFERENCE accordingly.
3187 Also step down the list where we found that timer. */
3189 if (! NILP (timers
) && ! NILP (idle_timers
))
3192 EMACS_SUB_TIME (temp
, timer_difference
, idle_timer_difference
);
3193 if (EMACS_TIME_NEG_P (temp
))
3195 chosen_timer
= timer
;
3196 timers
= XCONS (timers
)->cdr
;
3197 difference
= timer_difference
;
3201 chosen_timer
= idle_timer
;
3202 idle_timers
= XCONS (idle_timers
)->cdr
;
3203 difference
= idle_timer_difference
;
3206 else if (! NILP (timers
))
3208 chosen_timer
= timer
;
3209 timers
= XCONS (timers
)->cdr
;
3210 difference
= timer_difference
;
3214 chosen_timer
= idle_timer
;
3215 idle_timers
= XCONS (idle_timers
)->cdr
;
3216 difference
= idle_timer_difference
;
3218 vector
= XVECTOR (chosen_timer
)->contents
;
3220 /* If timer is rupe, run it if it hasn't been run. */
3221 if (EMACS_TIME_NEG_P (difference
)
3222 || (EMACS_SECS (difference
) == 0
3223 && EMACS_USECS (difference
) == 0))
3225 if (NILP (vector
[0]))
3228 int was_locked
= single_kboard
;
3229 int count
= specpdl_ptr
- specpdl
;
3231 /* Mark the timer as triggered to prevent problems if the lisp
3232 code fails to reschedule it right. */
3235 specbind (Qinhibit_quit
, Qt
);
3237 call1 (Qtimer_event_handler
, chosen_timer
);
3240 unbind_to (count
, Qnil
);
3242 /* Resume allowing input from any kboard, if that was true before. */
3244 any_kboard_state ();
3246 /* Since we have handled the event,
3247 we don't need to tell the caller to wake up and do it. */
3251 /* When we encounter a timer that is still waiting,
3252 return the amount of time to wait before it is ripe. */
3259 /* No timers are pending in the future. */
3260 /* Return 0 if we generated an event, and -1 if not. */
3265 /* Caches for modify_event_symbol. */
3266 static Lisp_Object accent_key_syms
;
3267 static Lisp_Object func_key_syms
;
3268 static Lisp_Object mouse_syms
;
3270 static Lisp_Object mouse_wheel_syms
;
3273 /* This is a list of keysym codes for special "accent" characters.
3274 It parallels lispy_accent_keys. */
3276 static int lispy_accent_codes
[] =
3278 #ifdef XK_dead_circumflex
3283 #ifdef XK_dead_grave
3288 #ifdef XK_dead_tilde
3293 #ifdef XK_dead_diaeresis
3298 #ifdef XK_dead_macron
3303 #ifdef XK_dead_degree
3308 #ifdef XK_dead_acute
3313 #ifdef XK_dead_cedilla
3318 #ifdef XK_dead_breve
3323 #ifdef XK_dead_ogonek
3328 #ifdef XK_dead_caron
3333 #ifdef XK_dead_doubleacute
3334 XK_dead_doubleacute
,
3338 #ifdef XK_dead_abovedot
3345 /* This is a list of Lisp names for special "accent" characters.
3346 It parallels lispy_accent_codes. */
3348 static char *lispy_accent_keys
[] =
3366 #define FUNCTION_KEY_OFFSET 0x0
3368 char *lispy_function_keys
[] =
3372 0, /* VK_LBUTTON 0x01 */
3373 0, /* VK_RBUTTON 0x02 */
3374 "cancel", /* VK_CANCEL 0x03 */
3375 0, /* VK_MBUTTON 0x04 */
3377 0, 0, 0, /* 0x05 .. 0x07 */
3379 "backspace", /* VK_BACK 0x08 */
3380 "tab", /* VK_TAB 0x09 */
3382 0, 0, /* 0x0A .. 0x0B */
3384 "clear", /* VK_CLEAR 0x0C */
3385 "return", /* VK_RETURN 0x0D */
3387 0, 0, /* 0x0E .. 0x0F */
3389 "shift", /* VK_SHIFT 0x10 */
3390 "control", /* VK_CONTROL 0x11 */
3391 "menu", /* VK_MENU 0x12 */
3392 "pause", /* VK_PAUSE 0x13 */
3393 "capital", /* VK_CAPITAL 0x14 */
3395 0, 0, 0, 0, 0, 0, /* 0x15 .. 0x1A */
3397 0, /* VK_ESCAPE 0x1B */
3399 0, 0, 0, 0, /* 0x1C .. 0x1F */
3401 0, /* VK_SPACE 0x20 */
3402 "prior", /* VK_PRIOR 0x21 */
3403 "next", /* VK_NEXT 0x22 */
3404 "end", /* VK_END 0x23 */
3405 "home", /* VK_HOME 0x24 */
3406 "left", /* VK_LEFT 0x25 */
3407 "up", /* VK_UP 0x26 */
3408 "right", /* VK_RIGHT 0x27 */
3409 "down", /* VK_DOWN 0x28 */
3410 "select", /* VK_SELECT 0x29 */
3411 "print", /* VK_PRINT 0x2A */
3412 "execute", /* VK_EXECUTE 0x2B */
3413 "snapshot", /* VK_SNAPSHOT 0x2C */
3414 "insert", /* VK_INSERT 0x2D */
3415 "delete", /* VK_DELETE 0x2E */
3416 "help", /* VK_HELP 0x2F */
3418 /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
3420 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3422 0, 0, 0, 0, 0, 0, 0, /* 0x3A .. 0x40 */
3424 /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
3426 0, 0, 0, 0, 0, 0, 0, 0, 0,
3427 0, 0, 0, 0, 0, 0, 0, 0, 0,
3428 0, 0, 0, 0, 0, 0, 0, 0,
3430 "lwindow", /* VK_LWIN 0x5B */
3431 "rwindow", /* VK_RWIN 0x5C */
3432 "apps", /* VK_APPS 0x5D */
3434 0, 0, /* 0x5E .. 0x5F */
3436 "kp-0", /* VK_NUMPAD0 0x60 */
3437 "kp-1", /* VK_NUMPAD1 0x61 */
3438 "kp-2", /* VK_NUMPAD2 0x62 */
3439 "kp-3", /* VK_NUMPAD3 0x63 */
3440 "kp-4", /* VK_NUMPAD4 0x64 */
3441 "kp-5", /* VK_NUMPAD5 0x65 */
3442 "kp-6", /* VK_NUMPAD6 0x66 */
3443 "kp-7", /* VK_NUMPAD7 0x67 */
3444 "kp-8", /* VK_NUMPAD8 0x68 */
3445 "kp-9", /* VK_NUMPAD9 0x69 */
3446 "kp-multiply", /* VK_MULTIPLY 0x6A */
3447 "kp-add", /* VK_ADD 0x6B */
3448 "kp-separator", /* VK_SEPARATOR 0x6C */
3449 "kp-subtract", /* VK_SUBTRACT 0x6D */
3450 "kp-decimal", /* VK_DECIMAL 0x6E */
3451 "kp-divide", /* VK_DIVIDE 0x6F */
3452 "f1", /* VK_F1 0x70 */
3453 "f2", /* VK_F2 0x71 */
3454 "f3", /* VK_F3 0x72 */
3455 "f4", /* VK_F4 0x73 */
3456 "f5", /* VK_F5 0x74 */
3457 "f6", /* VK_F6 0x75 */
3458 "f7", /* VK_F7 0x76 */
3459 "f8", /* VK_F8 0x77 */
3460 "f9", /* VK_F9 0x78 */
3461 "f10", /* VK_F10 0x79 */
3462 "f11", /* VK_F11 0x7A */
3463 "f12", /* VK_F12 0x7B */
3464 "f13", /* VK_F13 0x7C */
3465 "f14", /* VK_F14 0x7D */
3466 "f15", /* VK_F15 0x7E */
3467 "f16", /* VK_F16 0x7F */
3468 "f17", /* VK_F17 0x80 */
3469 "f18", /* VK_F18 0x81 */
3470 "f19", /* VK_F19 0x82 */
3471 "f20", /* VK_F20 0x83 */
3472 "f21", /* VK_F21 0x84 */
3473 "f22", /* VK_F22 0x85 */
3474 "f23", /* VK_F23 0x86 */
3475 "f24", /* VK_F24 0x87 */
3477 0, 0, 0, 0, /* 0x88 .. 0x8B */
3478 0, 0, 0, 0, /* 0x8C .. 0x8F */
3480 "kp-numlock", /* VK_NUMLOCK 0x90 */
3481 "scroll", /* VK_SCROLL 0x91 */
3483 "kp-space", /* VK_NUMPAD_CLEAR 0x92 */
3484 "kp-enter", /* VK_NUMPAD_ENTER 0x93 */
3485 "kp-prior", /* VK_NUMPAD_PRIOR 0x94 */
3486 "kp-next", /* VK_NUMPAD_NEXT 0x95 */
3487 "kp-end", /* VK_NUMPAD_END 0x96 */
3488 "kp-home", /* VK_NUMPAD_HOME 0x97 */
3489 "kp-left", /* VK_NUMPAD_LEFT 0x98 */
3490 "kp-up", /* VK_NUMPAD_UP 0x99 */
3491 "kp-right", /* VK_NUMPAD_RIGHT 0x9A */
3492 "kp-down", /* VK_NUMPAD_DOWN 0x9B */
3493 "kp-insert", /* VK_NUMPAD_INSERT 0x9C */
3494 "kp-delete", /* VK_NUMPAD_DELETE 0x9D */
3496 0, 0, /* 0x9E .. 0x9F */
3499 * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
3500 * Used only as parameters to GetAsyncKeyState() and GetKeyState().
3501 * No other API or message will distinguish left and right keys this way.
3505 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3506 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3507 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3508 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3509 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3515 "attn", /* VK_ATTN 0xF6 */
3516 "crsel", /* VK_CRSEL 0xF7 */
3517 "exsel", /* VK_EXSEL 0xF8 */
3518 "ereof", /* VK_EREOF 0xF9 */
3519 "play", /* VK_PLAY 0xFA */
3520 "zoom", /* VK_ZOOM 0xFB */
3521 "noname", /* VK_NONAME 0xFC */
3522 "pa1", /* VK_PA1 0xFD */
3523 "oem_clear", /* VK_OEM_CLEAR 0xFE */
3526 #else /* not HAVE_NTGUI */
3529 static char *lispy_kana_keys
[] =
3531 /* X Keysym value */
3532 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x400 .. 0x40f */
3533 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x410 .. 0x41f */
3534 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x420 .. 0x42f */
3535 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x430 .. 0x43f */
3536 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x440 .. 0x44f */
3537 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x450 .. 0x45f */
3538 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x460 .. 0x46f */
3539 0,0,0,0,0,0,0,0,0,0,0,0,0,0,"overline",0,
3540 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x480 .. 0x48f */
3541 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x490 .. 0x49f */
3542 0, "kana-fullstop", "kana-openingbracket", "kana-closingbracket",
3543 "kana-comma", "kana-conjunctive", "kana-WO", "kana-a",
3544 "kana-i", "kana-u", "kana-e", "kana-o",
3545 "kana-ya", "kana-yu", "kana-yo", "kana-tsu",
3546 "prolongedsound", "kana-A", "kana-I", "kana-U",
3547 "kana-E", "kana-O", "kana-KA", "kana-KI",
3548 "kana-KU", "kana-KE", "kana-KO", "kana-SA",
3549 "kana-SHI", "kana-SU", "kana-SE", "kana-SO",
3550 "kana-TA", "kana-CHI", "kana-TSU", "kana-TE",
3551 "kana-TO", "kana-NA", "kana-NI", "kana-NU",
3552 "kana-NE", "kana-NO", "kana-HA", "kana-HI",
3553 "kana-FU", "kana-HE", "kana-HO", "kana-MA",
3554 "kana-MI", "kana-MU", "kana-ME", "kana-MO",
3555 "kana-YA", "kana-YU", "kana-YO", "kana-RA",
3556 "kana-RI", "kana-RU", "kana-RE", "kana-RO",
3557 "kana-WA", "kana-N", "voicedsound", "semivoicedsound",
3558 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4e0 .. 0x4ef */
3559 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4f0 .. 0x4ff */
3561 #endif /* XK_kana_A */
3563 #define FUNCTION_KEY_OFFSET 0xff00
3565 /* You'll notice that this table is arranged to be conveniently
3566 indexed by X Windows keysym values. */
3567 static char *lispy_function_keys
[] =
3569 /* X Keysym value */
3571 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00 */
3579 0, 0, 0, /* 0xff10 */
3581 0, 0, 0, 0, 0, 0, 0,
3584 0, "kanji", "muhenkan",
3585 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff20...2f */
3586 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff30...3f */
3587 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
3589 "home", /* 0xff50 */ /* IsCursorKey */
3600 "select", /* 0xff60 */ /* IsMiscFunctionKey */
3611 "break", /* 0xff6b */
3613 0, 0, 0, 0, 0, 0, 0, 0, "backtab", 0,
3615 0, 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff7f */
3616 "kp-space", /* 0xff80 */ /* IsKeypadKey */
3617 0, 0, 0, 0, 0, 0, 0, 0,
3618 "kp-tab", /* 0xff89 */
3620 "kp-enter", /* 0xff8d */
3622 "kp-f1", /* 0xff91 */
3626 "kp-home", /* 0xff95 */
3631 "kp-prior", /* kp-page-up */
3632 "kp-next", /* kp-page-down */
3638 0, 0, 0, 0, 0, 0, 0, 0, 0,
3639 "kp-multiply", /* 0xffaa */
3644 "kp-divide", /* 0xffaf */
3645 "kp-0", /* 0xffb0 */
3646 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
3649 "kp-equal", /* 0xffbd */
3650 "f1", /* 0xffbe */ /* IsFunctionKey */
3652 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
3653 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
3654 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
3655 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
3656 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
3657 0, 0, 0, 0, 0, 0, 0, 0,
3658 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
3659 0, 0, 0, 0, 0, 0, 0, "delete"
3662 /* ISO 9995 Function and Modifier Keys; the first byte is 0xFE. */
3663 #define ISO_FUNCTION_KEY_OFFSET 0xfe00
3665 static char *iso_lispy_function_keys
[] =
3667 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe00 */
3668 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe08 */
3669 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe10 */
3670 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe18 */
3671 "iso-lefttab", /* 0xfe20 */
3672 "iso-move-line-up", "iso-move-line-down",
3673 "iso-partial-line-up", "iso-partial-line-down",
3674 "iso-partial-space-left", "iso-partial-space-right",
3675 "iso-set-margin-left", "iso-set-margin-right", /* 0xffe27, 28 */
3676 "iso-release-margin-left", "iso-release-margin-right",
3677 "iso-release-both-margins",
3678 "iso-fast-cursor-left", "iso-fast-cursor-right",
3679 "iso-fast-cursor-up", "iso-fast-cursor-down",
3680 "iso-continuous-underline", "iso-discontinuous-underline", /* 0xfe30, 31 */
3681 "iso-emphasize", "iso-center-object", "iso-enter", /* ... 0xfe34 */
3684 #endif /* not HAVE_NTGUI */
3686 static char *lispy_mouse_names
[] =
3688 "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5"
3692 /* mouse-wheel events are generated by the wheel on devices such as
3693 the MS Intellimouse. The wheel sits in between the left and right
3694 mouse buttons, and is typically used to scroll or zoom the window
3695 underneath the pointer. mouse-wheel events specify the object on
3696 which they operate, and a delta corresponding to the amount and
3697 direction that the wheel is rotated. Clicking the mouse-wheel
3698 generates a mouse-2 event. */
3699 static char *lispy_mouse_wheel_names
[] =
3703 #endif /* WINDOWSNT */
3705 /* Scroll bar parts. */
3706 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
3707 Lisp_Object Qup
, Qdown
;
3709 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
3710 Lisp_Object
*scroll_bar_parts
[] = {
3711 &Qabove_handle
, &Qhandle
, &Qbelow_handle
,
3716 /* A vector, indexed by button number, giving the down-going location
3717 of currently depressed buttons, both scroll bar and non-scroll bar.
3719 The elements have the form
3720 (BUTTON-NUMBER MODIFIER-MASK . REST)
3721 where REST is the cdr of a position as it would be reported in the event.
3723 The make_lispy_event function stores positions here to tell the
3724 difference between click and drag events, and to store the starting
3725 location to be included in drag events. */
3727 static Lisp_Object button_down_location
;
3729 /* Information about the most recent up-going button event: Which
3730 button, what location, and what time. */
3732 static int last_mouse_button
;
3733 static int last_mouse_x
;
3734 static int last_mouse_y
;
3735 static unsigned long button_down_time
;
3737 /* The maximum time between clicks to make a double-click,
3738 or Qnil to disable double-click detection,
3739 or Qt for no time limit. */
3740 Lisp_Object Vdouble_click_time
;
3742 /* The number of clicks in this multiple-click. */
3744 int double_click_count
;
3746 /* Given a struct input_event, build the lisp event which represents
3747 it. If EVENT is 0, build a mouse movement event from the mouse
3748 movement buffer, which should have a movement event in it.
3750 Note that events must be passed to this function in the order they
3751 are received; this function stores the location of button presses
3752 in order to build drag events when the button is released. */
3755 make_lispy_event (event
)
3756 struct input_event
*event
;
3760 switch (SWITCH_ENUM_CAST (event
->kind
))
3762 /* A simple keystroke. */
3763 case ascii_keystroke
:
3765 Lisp_Object lispy_c
;
3766 int c
= event
->code
& 0377;
3767 /* Turn ASCII characters into control characters
3769 if (event
->modifiers
& ctrl_modifier
)
3770 c
= make_ctrl_char (c
);
3772 /* Add in the other modifier bits. We took care of ctrl_modifier
3773 just above, and the shift key was taken care of by the X code,
3774 and applied to control characters by make_ctrl_char. */
3775 c
|= (event
->modifiers
3776 & (meta_modifier
| alt_modifier
3777 | hyper_modifier
| super_modifier
));
3778 /* Distinguish Shift-SPC from SPC. */
3779 if ((event
->code
& 0377) == 040
3780 && event
->modifiers
& shift_modifier
)
3781 c
|= shift_modifier
;
3782 button_down_time
= 0;
3783 XSETFASTINT (lispy_c
, c
);
3787 /* A function key. The symbol may need to have modifier prefixes
3789 case non_ascii_keystroke
:
3790 button_down_time
= 0;
3792 for (i
= 0; i
< sizeof (lispy_accent_codes
) / sizeof (int); i
++)
3793 if (event
->code
== lispy_accent_codes
[i
])
3794 return modify_event_symbol (i
,
3796 Qfunction_key
, Qnil
,
3797 lispy_accent_keys
, &accent_key_syms
,
3798 (sizeof (lispy_accent_keys
)
3799 / sizeof (lispy_accent_keys
[0])));
3801 /* Handle system-specific keysyms. */
3802 if (event
->code
& (1 << 28))
3804 /* We need to use an alist rather than a vector as the cache
3805 since we can't make a vector long enuf. */
3806 if (NILP (current_kboard
->system_key_syms
))
3807 current_kboard
->system_key_syms
= Fcons (Qnil
, Qnil
);
3808 return modify_event_symbol (event
->code
,
3811 current_kboard
->Vsystem_key_alist
,
3812 0, ¤t_kboard
->system_key_syms
,
3817 if (event
->code
>= 0x400 && event
->code
< 0x500)
3818 return modify_event_symbol (event
->code
- 0x400,
3819 event
->modifiers
& ~shift_modifier
,
3820 Qfunction_key
, Qnil
,
3821 lispy_kana_keys
, &func_key_syms
,
3822 (sizeof (lispy_kana_keys
)
3823 / sizeof (lispy_kana_keys
[0])));
3824 #endif /* XK_kana_A */
3826 #ifdef ISO_FUNCTION_KEY_OFFSET
3827 if (event
->code
< FUNCTION_KEY_OFFSET
3828 && event
->code
>= ISO_FUNCTION_KEY_OFFSET
)
3829 return modify_event_symbol (event
->code
- ISO_FUNCTION_KEY_OFFSET
,
3831 Qfunction_key
, Qnil
,
3832 iso_lispy_function_keys
, &func_key_syms
,
3833 (sizeof (iso_lispy_function_keys
)
3834 / sizeof (iso_lispy_function_keys
[0])));
3837 return modify_event_symbol (event
->code
- FUNCTION_KEY_OFFSET
,
3839 Qfunction_key
, Qnil
,
3840 lispy_function_keys
, &func_key_syms
,
3841 (sizeof (lispy_function_keys
)
3842 / sizeof (lispy_function_keys
[0])));
3845 /* A mouse click. Figure out where it is, decide whether it's
3846 a press, click or drag, and build the appropriate structure. */
3848 case scroll_bar_click
:
3850 int button
= event
->code
;
3852 Lisp_Object position
;
3853 Lisp_Object
*start_pos_ptr
;
3854 Lisp_Object start_pos
;
3856 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
3859 /* Build the position as appropriate for this mouse click. */
3860 if (event
->kind
== mouse_click
)
3863 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
3868 /* Ignore mouse events that were made on frame that
3869 have been deleted. */
3870 if (! FRAME_LIVE_P (f
))
3873 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
3874 &column
, &row
, NULL
, 1);
3876 #ifndef USE_X_TOOLKIT
3877 /* In the non-toolkit version, clicks on the menu bar
3878 are ordinary button events in the event buffer.
3879 Distinguish them, and invoke the menu.
3881 (In the toolkit version, the toolkit handles the menu bar
3882 and Emacs doesn't know about it until after the user
3883 makes a selection.) */
3884 if (row
>= 0 && row
< FRAME_MENU_BAR_LINES (f
)
3885 && (event
->modifiers
& down_modifier
))
3887 Lisp_Object items
, item
;
3892 /* Activate the menu bar on the down event. If the
3893 up event comes in before the menu code can deal with it,
3895 if (! (event
->modifiers
& down_modifier
))
3900 items
= FRAME_MENU_BAR_ITEMS (f
);
3901 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
3903 Lisp_Object pos
, string
;
3904 string
= XVECTOR (items
)->contents
[i
+ 1];
3905 pos
= XVECTOR (items
)->contents
[i
+ 3];
3908 if (column
>= XINT (pos
)
3909 && column
< XINT (pos
) + XSTRING (string
)->size
)
3911 item
= XVECTOR (items
)->contents
[i
];
3917 = Fcons (event
->frame_or_window
,
3919 Fcons (Fcons (event
->x
, event
->y
),
3920 Fcons (make_number (event
->timestamp
),
3923 return Fcons (item
, Fcons (position
, Qnil
));
3925 #endif /* not USE_X_TOOLKIT */
3927 window
= window_from_coordinates (f
, column
, row
, &part
);
3929 if (!WINDOWP (window
))
3931 window
= event
->frame_or_window
;
3936 int pixcolumn
, pixrow
;
3937 column
-= WINDOW_LEFT_MARGIN (XWINDOW (window
));
3938 row
-= XINT (XWINDOW (window
)->top
);
3939 glyph_to_pixel_coords (f
, column
, row
, &pixcolumn
, &pixrow
);
3940 XSETINT (event
->x
, pixcolumn
);
3941 XSETINT (event
->y
, pixrow
);
3946 posn
= Qvertical_line
;
3949 buffer_posn_from_coords (XWINDOW (window
),
3956 Fcons (Fcons (event
->x
, event
->y
),
3957 Fcons (make_number (event
->timestamp
),
3963 Lisp_Object portion_whole
;
3966 window
= event
->frame_or_window
;
3967 portion_whole
= Fcons (event
->x
, event
->y
);
3968 part
= *scroll_bar_parts
[(int) event
->part
];
3972 Fcons (Qvertical_scroll_bar
,
3973 Fcons (portion_whole
,
3974 Fcons (make_number (event
->timestamp
),
3975 Fcons (part
, Qnil
)))));
3978 start_pos_ptr
= &XVECTOR (button_down_location
)->contents
[button
];
3980 start_pos
= *start_pos_ptr
;
3981 *start_pos_ptr
= Qnil
;
3983 is_double
= (button
== last_mouse_button
3984 && XINT (event
->x
) == last_mouse_x
3985 && XINT (event
->y
) == last_mouse_y
3986 && button_down_time
!= 0
3987 && (EQ (Vdouble_click_time
, Qt
)
3988 || (INTEGERP (Vdouble_click_time
)
3989 && ((int)(event
->timestamp
- button_down_time
)
3990 < XINT (Vdouble_click_time
)))));
3991 last_mouse_button
= button
;
3992 last_mouse_x
= XINT (event
->x
);
3993 last_mouse_y
= XINT (event
->y
);
3995 /* If this is a button press, squirrel away the location, so
3996 we can decide later whether it was a click or a drag. */
3997 if (event
->modifiers
& down_modifier
)
4001 double_click_count
++;
4002 event
->modifiers
|= ((double_click_count
> 2)
4007 double_click_count
= 1;
4008 button_down_time
= event
->timestamp
;
4009 *start_pos_ptr
= Fcopy_alist (position
);
4012 /* Now we're releasing a button - check the co-ordinates to
4013 see if this was a click or a drag. */
4014 else if (event
->modifiers
& up_modifier
)
4016 /* If we did not see a down before this up,
4017 ignore the up. Probably this happened because
4018 the down event chose a menu item.
4019 It would be an annoyance to treat the release
4020 of the button that chose the menu item
4021 as a separate event. */
4023 if (!CONSP (start_pos
))
4026 event
->modifiers
&= ~up_modifier
;
4027 #if 0 /* Formerly we treated an up with no down as a click event. */
4028 if (!CONSP (start_pos
))
4029 event
->modifiers
|= click_modifier
;
4033 /* The third element of every position should be the (x,y)
4037 down
= Fnth (make_number (2), start_pos
);
4038 if (EQ (event
->x
, XCONS (down
)->car
)
4039 && EQ (event
->y
, XCONS (down
)->cdr
))
4041 event
->modifiers
|= click_modifier
;
4045 button_down_time
= 0;
4046 event
->modifiers
|= drag_modifier
;
4048 /* Don't check is_double; treat this as multiple
4049 if the down-event was multiple. */
4050 if (double_click_count
> 1)
4051 event
->modifiers
|= ((double_click_count
> 2)
4057 /* Every mouse event should either have the down_modifier or
4058 the up_modifier set. */
4062 /* Get the symbol we should use for the mouse click. */
4065 head
= modify_event_symbol (button
,
4068 lispy_mouse_names
, &mouse_syms
,
4069 (sizeof (lispy_mouse_names
)
4070 / sizeof (lispy_mouse_names
[0])));
4071 if (event
->modifiers
& drag_modifier
)
4076 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
4079 Fcons (make_number (double_click_count
),
4089 case w32_scroll_bar_click
:
4091 int button
= event
->code
;
4093 Lisp_Object position
;
4094 Lisp_Object
*start_pos_ptr
;
4095 Lisp_Object start_pos
;
4097 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
4102 Lisp_Object portion_whole
;
4105 window
= event
->frame_or_window
;
4106 portion_whole
= Fcons (event
->x
, event
->y
);
4107 part
= *scroll_bar_parts
[(int) event
->part
];
4111 Fcons (Qvertical_scroll_bar
,
4112 Fcons (portion_whole
,
4113 Fcons (make_number (event
->timestamp
),
4114 Fcons (part
, Qnil
)))));
4117 /* Always treat W32 scroll bar events as clicks. */
4118 event
->modifiers
|= click_modifier
;
4121 /* Get the symbol we should use for the mouse click. */
4124 head
= modify_event_symbol (button
,
4127 lispy_mouse_names
, &mouse_syms
,
4128 (sizeof (lispy_mouse_names
)
4129 / sizeof (lispy_mouse_names
[0])));
4138 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
4141 Lisp_Object head
, position
;
4144 /* Ignore mouse events that were made on frame that
4145 have been deleted. */
4146 if (! FRAME_LIVE_P (f
))
4148 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4149 &column
, &row
, NULL
, 1);
4150 window
= window_from_coordinates (f
, column
, row
, &part
);
4152 if (!WINDOWP (window
))
4154 window
= event
->frame_or_window
;
4159 int pixcolumn
, pixrow
;
4160 column
-= XINT (XWINDOW (window
)->left
);
4161 row
-= XINT (XWINDOW (window
)->top
);
4162 glyph_to_pixel_coords (f
, column
, row
, &pixcolumn
, &pixrow
);
4163 XSETINT (event
->x
, pixcolumn
);
4164 XSETINT (event
->y
, pixrow
);
4169 posn
= Qvertical_line
;
4172 buffer_posn_from_coords (XWINDOW (window
),
4177 Lisp_Object head
, position
;
4182 Fcons (Fcons (event
->x
, event
->y
),
4183 Fcons (make_number (event
->timestamp
),
4186 head
= modify_event_symbol (0, event
->modifiers
,
4188 lispy_mouse_wheel_names
,
4189 &mouse_wheel_syms
, 1);
4192 Fcons (make_number (event
->code
),
4196 #endif /* WINDOWSNT */
4197 #endif /* HAVE_MOUSE */
4199 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
4200 case menu_bar_event
:
4201 /* The event value is in the cdr of the frame_or_window slot. */
4202 if (!CONSP (event
->frame_or_window
))
4204 return XCONS (event
->frame_or_window
)->cdr
;
4207 /* The 'kind' field of the event is something we don't recognize. */
4216 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
4218 Lisp_Object bar_window
;
4219 enum scroll_bar_part part
;
4223 /* Is it a scroll bar movement? */
4224 if (frame
&& ! NILP (bar_window
))
4226 Lisp_Object part_sym
;
4228 part_sym
= *scroll_bar_parts
[(int) part
];
4229 return Fcons (Qscroll_bar_movement
,
4230 (Fcons (Fcons (bar_window
,
4231 Fcons (Qvertical_scroll_bar
,
4232 Fcons (Fcons (x
, y
),
4233 Fcons (make_number (time
),
4239 /* Or is it an ordinary mouse movement? */
4249 /* It's in a frame; which window on that frame? */
4250 pixel_to_glyph_coords (frame
, XINT (x
), XINT (y
), &column
, &row
,
4252 window
= window_from_coordinates (frame
, column
, row
, &area
);
4257 if (WINDOWP (window
))
4259 int pixcolumn
, pixrow
;
4260 column
-= WINDOW_LEFT_MARGIN (XWINDOW (window
));
4261 row
-= XINT (XWINDOW (window
)->top
);
4262 glyph_to_pixel_coords (frame
, column
, row
, &pixcolumn
, &pixrow
);
4263 XSETINT (x
, pixcolumn
);
4264 XSETINT (y
, pixrow
);
4269 posn
= Qvertical_line
;
4272 buffer_posn_from_coords (XWINDOW (window
), column
, row
));
4274 else if (frame
!= 0)
4276 XSETFRAME (window
, frame
);
4287 return Fcons (Qmouse_movement
,
4288 Fcons (Fcons (window
,
4290 Fcons (Fcons (x
, y
),
4291 Fcons (make_number (time
),
4297 #endif /* HAVE_MOUSE */
4299 /* Construct a switch frame event. */
4301 make_lispy_switch_frame (frame
)
4304 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
4307 /* Manipulating modifiers. */
4309 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
4311 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
4312 SYMBOL's name of the end of the modifiers; the string from this
4313 position is the unmodified symbol name.
4315 This doesn't use any caches. */
4318 parse_modifiers_uncached (symbol
, modifier_end
)
4322 struct Lisp_String
*name
;
4326 CHECK_SYMBOL (symbol
, 1);
4329 name
= XSYMBOL (symbol
)->name
;
4331 for (i
= 0; i
+2 <= name
->size
; )
4333 int this_mod_end
= 0;
4336 /* See if the name continues with a modifier word.
4337 Check that the word appears, but don't check what follows it.
4338 Set this_mod and this_mod_end to record what we find. */
4340 switch (name
->data
[i
])
4342 #define SINGLE_LETTER_MOD(BIT) \
4343 (this_mod_end = i + 1, this_mod = BIT)
4346 SINGLE_LETTER_MOD (alt_modifier
);
4350 SINGLE_LETTER_MOD (ctrl_modifier
);
4354 SINGLE_LETTER_MOD (hyper_modifier
);
4358 SINGLE_LETTER_MOD (meta_modifier
);
4362 SINGLE_LETTER_MOD (shift_modifier
);
4366 SINGLE_LETTER_MOD (super_modifier
);
4369 #undef SINGLE_LETTER_MOD
4372 /* If we found no modifier, stop looking for them. */
4373 if (this_mod_end
== 0)
4376 /* Check there is a dash after the modifier, so that it
4377 really is a modifier. */
4378 if (this_mod_end
>= name
->size
|| name
->data
[this_mod_end
] != '-')
4381 /* This modifier is real; look for another. */
4382 modifiers
|= this_mod
;
4383 i
= this_mod_end
+ 1;
4386 /* Should we include the `click' modifier? */
4387 if (! (modifiers
& (down_modifier
| drag_modifier
4388 | double_modifier
| triple_modifier
))
4389 && i
+ 7 == name
->size
4390 && strncmp (name
->data
+ i
, "mouse-", 6) == 0
4391 && ('0' <= name
->data
[i
+ 6] && name
->data
[i
+ 6] <= '9'))
4392 modifiers
|= click_modifier
;
4400 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
4401 prepended to the string BASE[0..BASE_LEN-1].
4402 This doesn't use any caches. */
4404 apply_modifiers_uncached (modifiers
, base
, base_len
)
4409 /* Since BASE could contain nulls, we can't use intern here; we have
4410 to use Fintern, which expects a genuine Lisp_String, and keeps a
4413 (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
4419 /* Only the event queue may use the `up' modifier; it should always
4420 be turned into a click or drag event before presented to lisp code. */
4421 if (modifiers
& up_modifier
)
4424 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
4425 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
4426 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
4427 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
4428 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
4429 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
4430 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
4431 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
4432 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
4433 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
4434 /* The click modifier is denoted by the absence of other modifiers. */
4438 mod_len
= p
- new_mods
;
4442 Lisp_Object new_name
;
4444 new_name
= make_uninit_string (mod_len
+ base_len
);
4445 bcopy (new_mods
, XSTRING (new_name
)->data
, mod_len
);
4446 bcopy (base
, XSTRING (new_name
)->data
+ mod_len
, base_len
);
4448 return Fintern (new_name
, Qnil
);
4453 static char *modifier_names
[] =
4455 "up", "down", "drag", "click", "double", "triple", 0, 0,
4456 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4457 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
4459 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
4461 static Lisp_Object modifier_symbols
;
4463 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
4465 lispy_modifier_list (modifiers
)
4468 Lisp_Object modifier_list
;
4471 modifier_list
= Qnil
;
4472 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
4473 if (modifiers
& (1<<i
))
4474 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
4477 return modifier_list
;
4481 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
4482 where UNMODIFIED is the unmodified form of SYMBOL,
4483 MASK is the set of modifiers present in SYMBOL's name.
4484 This is similar to parse_modifiers_uncached, but uses the cache in
4485 SYMBOL's Qevent_symbol_element_mask property, and maintains the
4486 Qevent_symbol_elements property. */
4489 parse_modifiers (symbol
)
4492 Lisp_Object elements
;
4494 elements
= Fget (symbol
, Qevent_symbol_element_mask
);
4495 if (CONSP (elements
))
4500 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
4501 Lisp_Object unmodified
;
4504 unmodified
= Fintern (make_string (XSYMBOL (symbol
)->name
->data
+ end
,
4505 XSYMBOL (symbol
)->name
->size
- end
),
4508 if (modifiers
& ~(((EMACS_INT
)1 << VALBITS
) - 1))
4510 XSETFASTINT (mask
, modifiers
);
4511 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
4513 /* Cache the parsing results on SYMBOL. */
4514 Fput (symbol
, Qevent_symbol_element_mask
,
4516 Fput (symbol
, Qevent_symbol_elements
,
4517 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
4519 /* Since we know that SYMBOL is modifiers applied to unmodified,
4520 it would be nice to put that in unmodified's cache.
4521 But we can't, since we're not sure that parse_modifiers is
4528 /* Apply the modifiers MODIFIERS to the symbol BASE.
4529 BASE must be unmodified.
4531 This is like apply_modifiers_uncached, but uses BASE's
4532 Qmodifier_cache property, if present. It also builds
4533 Qevent_symbol_elements properties, since it has that info anyway.
4535 apply_modifiers copies the value of BASE's Qevent_kind property to
4536 the modified symbol. */
4538 apply_modifiers (modifiers
, base
)
4542 Lisp_Object cache
, index
, entry
, new_symbol
;
4544 /* Mask out upper bits. We don't know where this value's been. */
4545 modifiers
&= ((EMACS_INT
)1 << VALBITS
) - 1;
4547 /* The click modifier never figures into cache indices. */
4548 cache
= Fget (base
, Qmodifier_cache
);
4549 XSETFASTINT (index
, (modifiers
& ~click_modifier
));
4550 entry
= assq_no_quit (index
, cache
);
4553 new_symbol
= XCONS (entry
)->cdr
;
4556 /* We have to create the symbol ourselves. */
4557 new_symbol
= apply_modifiers_uncached (modifiers
,
4558 XSYMBOL (base
)->name
->data
,
4559 XSYMBOL (base
)->name
->size
);
4561 /* Add the new symbol to the base's cache. */
4562 entry
= Fcons (index
, new_symbol
);
4563 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
4565 /* We have the parsing info now for free, so add it to the caches. */
4566 XSETFASTINT (index
, modifiers
);
4567 Fput (new_symbol
, Qevent_symbol_element_mask
,
4568 Fcons (base
, Fcons (index
, Qnil
)));
4569 Fput (new_symbol
, Qevent_symbol_elements
,
4570 Fcons (base
, lispy_modifier_list (modifiers
)));
4573 /* Make sure this symbol is of the same kind as BASE.
4575 You'd think we could just set this once and for all when we
4576 intern the symbol above, but reorder_modifiers may call us when
4577 BASE's property isn't set right; we can't assume that just
4578 because it has a Qmodifier_cache property it must have its
4579 Qevent_kind set right as well. */
4580 if (NILP (Fget (new_symbol
, Qevent_kind
)))
4584 kind
= Fget (base
, Qevent_kind
);
4586 Fput (new_symbol
, Qevent_kind
, kind
);
4593 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
4594 return a symbol with the modifiers placed in the canonical order.
4595 Canonical order is alphabetical, except for down and drag, which
4596 always come last. The 'click' modifier is never written out.
4598 Fdefine_key calls this to make sure that (for example) C-M-foo
4599 and M-C-foo end up being equivalent in the keymap. */
4602 reorder_modifiers (symbol
)
4605 /* It's hopefully okay to write the code this way, since everything
4606 will soon be in caches, and no consing will be done at all. */
4609 parsed
= parse_modifiers (symbol
);
4610 return apply_modifiers ((int) XINT (XCONS (XCONS (parsed
)->cdr
)->car
),
4611 XCONS (parsed
)->car
);
4615 /* For handling events, we often want to produce a symbol whose name
4616 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
4617 to some base, like the name of a function key or mouse button.
4618 modify_event_symbol produces symbols of this sort.
4620 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
4621 is the name of the i'th symbol. TABLE_SIZE is the number of elements
4624 Alternatively, NAME_ALIST is an alist mapping codes into symbol names.
4625 NAME_ALIST is used if it is non-nil; otherwise NAME_TABLE is used.
4627 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
4628 persist between calls to modify_event_symbol that it can use to
4629 store a cache of the symbols it's generated for this NAME_TABLE
4630 before. The object stored there may be a vector or an alist.
4632 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
4634 MODIFIERS is a set of modifier bits (as given in struct input_events)
4635 whose prefixes should be applied to the symbol name.
4637 SYMBOL_KIND is the value to be placed in the event_kind property of
4638 the returned symbol.
4640 The symbols we create are supposed to have an
4641 `event-symbol-elements' property, which lists the modifiers present
4642 in the symbol's name. */
4645 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_alist
,
4646 name_table
, symbol_table
, table_size
)
4649 Lisp_Object symbol_kind
;
4650 Lisp_Object name_alist
;
4652 Lisp_Object
*symbol_table
;
4653 unsigned int table_size
;
4656 Lisp_Object symbol_int
;
4658 /* Get rid of the "vendor-specific" bit here. */
4659 XSETINT (symbol_int
, symbol_num
& 0xffffff);
4661 /* Is this a request for a valid symbol? */
4662 if (symbol_num
< 0 || symbol_num
>= table_size
)
4665 if (CONSP (*symbol_table
))
4666 value
= Fcdr (assq_no_quit (symbol_int
, *symbol_table
));
4668 /* If *symbol_table doesn't seem to be initialized properly, fix that.
4669 *symbol_table should be a lisp vector TABLE_SIZE elements long,
4670 where the Nth element is the symbol for NAME_TABLE[N], or nil if
4671 we've never used that symbol before. */
4674 if (! VECTORP (*symbol_table
)
4675 || XVECTOR (*symbol_table
)->size
!= table_size
)
4679 XSETFASTINT (size
, table_size
);
4680 *symbol_table
= Fmake_vector (size
, Qnil
);
4683 value
= XVECTOR (*symbol_table
)->contents
[symbol_num
];
4686 /* Have we already used this symbol before? */
4689 /* No; let's create it. */
4690 if (!NILP (name_alist
))
4691 value
= Fcdr_safe (Fassq (symbol_int
, name_alist
));
4692 else if (name_table
!= 0 && name_table
[symbol_num
])
4693 value
= intern (name_table
[symbol_num
]);
4695 #ifdef HAVE_WINDOW_SYSTEM
4698 char *name
= x_get_keysym_name (symbol_num
);
4700 value
= intern (name
);
4707 sprintf (buf
, "key-%d", symbol_num
);
4708 value
= intern (buf
);
4711 if (CONSP (*symbol_table
))
4712 *symbol_table
= Fcons (Fcons (symbol_int
, value
), *symbol_table
);
4714 XVECTOR (*symbol_table
)->contents
[symbol_num
] = value
;
4716 /* Fill in the cache entries for this symbol; this also
4717 builds the Qevent_symbol_elements property, which the user
4719 apply_modifiers (modifiers
& click_modifier
, value
);
4720 Fput (value
, Qevent_kind
, symbol_kind
);
4723 /* Apply modifiers to that symbol. */
4724 return apply_modifiers (modifiers
, value
);
4727 /* Convert a list that represents an event type,
4728 such as (ctrl meta backspace), into the usual representation of that
4729 event type as a number or a symbol. */
4731 DEFUN ("event-convert-list", Fevent_convert_list
, Sevent_convert_list
, 1, 1, 0,
4732 "Convert the event description list EVENT-DESC to an event type.\n\
4733 EVENT-DESC should contain one base event type (a character or symbol)\n\
4734 and zero or more modifier names (control, meta, hyper, super, shift, alt,\n\
4735 drag, down, double or triple). The base must be last.\n\
4736 The return value is an event type (a character or symbol) which\n\
4737 has the same base event type and all the specified modifiers.")
4739 Lisp_Object event_desc
;
4747 while (CONSP (rest
))
4752 elt
= XCONS (rest
)->car
;
4753 rest
= XCONS (rest
)->cdr
;
4755 /* Given a symbol, see if it is a modifier name. */
4756 if (SYMBOLP (elt
) && CONSP (rest
))
4757 this = parse_solitary_modifier (elt
);
4761 else if (!NILP (base
))
4762 error ("Two bases given in one event");
4768 /* Let the symbol A refer to the character A. */
4769 if (SYMBOLP (base
) && XSYMBOL (base
)->name
->size
== 1)
4770 XSETINT (base
, XSYMBOL (base
)->name
->data
[0]);
4772 if (INTEGERP (base
))
4774 /* Turn (shift a) into A. */
4775 if ((modifiers
& shift_modifier
) != 0
4776 && (XINT (base
) >= 'a' && XINT (base
) <= 'z'))
4778 XSETINT (base
, XINT (base
) - ('a' - 'A'));
4779 modifiers
&= ~shift_modifier
;
4782 /* Turn (control a) into C-a. */
4783 if (modifiers
& ctrl_modifier
)
4784 return make_number ((modifiers
& ~ctrl_modifier
)
4785 | make_ctrl_char (XINT (base
)));
4787 return make_number (modifiers
| XINT (base
));
4789 else if (SYMBOLP (base
))
4790 return apply_modifiers (modifiers
, base
);
4792 error ("Invalid base event");
4795 /* Try to recognize SYMBOL as a modifier name.
4796 Return the modifier flag bit, or 0 if not recognized. */
4799 parse_solitary_modifier (symbol
)
4802 struct Lisp_String
*name
= XSYMBOL (symbol
)->name
;
4804 switch (name
->data
[0])
4806 #define SINGLE_LETTER_MOD(BIT) \
4807 if (name->size == 1) \
4810 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
4811 if (LEN == name->size \
4812 && ! strncmp (name->data, NAME, LEN)) \
4816 SINGLE_LETTER_MOD (alt_modifier
);
4820 MULTI_LETTER_MOD (alt_modifier
, "alt", 3);
4824 SINGLE_LETTER_MOD (ctrl_modifier
);
4828 MULTI_LETTER_MOD (ctrl_modifier
, "ctrl", 4);
4829 MULTI_LETTER_MOD (ctrl_modifier
, "control", 7);
4833 SINGLE_LETTER_MOD (hyper_modifier
);
4837 MULTI_LETTER_MOD (hyper_modifier
, "hyper", 5);
4841 SINGLE_LETTER_MOD (meta_modifier
);
4845 MULTI_LETTER_MOD (meta_modifier
, "meta", 4);
4849 SINGLE_LETTER_MOD (shift_modifier
);
4853 MULTI_LETTER_MOD (shift_modifier
, "shift", 5);
4854 MULTI_LETTER_MOD (super_modifier
, "super", 5);
4855 SINGLE_LETTER_MOD (super_modifier
);
4859 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
4860 MULTI_LETTER_MOD (down_modifier
, "down", 4);
4861 MULTI_LETTER_MOD (double_modifier
, "double", 6);
4865 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
4868 #undef SINGLE_LETTER_MOD
4869 #undef MULTI_LETTER_MOD
4875 /* Return 1 if EVENT is a list whose elements are all integers or symbols.
4876 Such a list is not valid as an event,
4877 but it can be a Lucid-style event type list. */
4880 lucid_event_type_list_p (object
)
4885 if (! CONSP (object
))
4888 for (tail
= object
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4891 elt
= XCONS (tail
)->car
;
4892 if (! (INTEGERP (elt
) || SYMBOLP (elt
)))
4899 /* Store into *addr a value nonzero if terminal input chars are available.
4900 Serves the purpose of ioctl (0, FIONREAD, addr)
4901 but works even if FIONREAD does not exist.
4902 (In fact, this may actually read some input.)
4904 If DO_TIMERS_NOW is nonzero, actually run timer events that are ripe. */
4907 get_input_pending (addr
, do_timers_now
)
4911 /* First of all, have we already counted some input? */
4912 *addr
= !NILP (Vquit_flag
) || readable_events (do_timers_now
);
4914 /* If input is being read as it arrives, and we have none, there is none. */
4915 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
4918 /* Try to read some input and see how much we get. */
4920 *addr
= !NILP (Vquit_flag
) || readable_events (do_timers_now
);
4923 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
4926 gobble_input (expected
)
4931 if (interrupt_input
)
4934 mask
= sigblock (sigmask (SIGIO
));
4935 read_avail_input (expected
);
4939 #ifdef POLL_FOR_INPUT
4940 if (read_socket_hook
&& !interrupt_input
&& poll_suppress_count
== 0)
4943 mask
= sigblock (sigmask (SIGALRM
));
4944 read_avail_input (expected
);
4950 read_avail_input (expected
);
4954 /* Put a buffer_switch_event in the buffer
4955 so that read_key_sequence will notice the new current buffer. */
4958 record_asynch_buffer_change ()
4960 struct input_event event
;
4963 event
.kind
= buffer_switch_event
;
4964 event
.frame_or_window
= Qnil
;
4967 /* We don't need a buffer-switch event unless Emacs is waiting for input.
4968 The purpose of the event is to make read_key_sequence look up the
4969 keymaps again. If we aren't in read_key_sequence, we don't need one,
4970 and the event could cause trouble by messing up (input-pending-p). */
4971 tem
= Fwaiting_for_user_input_p ();
4975 /* We never need these events if we have no asynchronous subprocesses. */
4979 /* Make sure no interrupt happens while storing the event. */
4981 if (interrupt_input
)
4984 mask
= sigblock (sigmask (SIGIO
));
4985 kbd_buffer_store_event (&event
);
4992 kbd_buffer_store_event (&event
);
4999 /* Read any terminal input already buffered up by the system
5000 into the kbd_buffer, but do not wait.
5002 EXPECTED should be nonzero if the caller knows there is some input.
5004 Except on VMS, all input is read by this function.
5005 If interrupt_input is nonzero, this function MUST be called
5006 only when SIGIO is blocked.
5008 Returns the number of keyboard chars read, or -1 meaning
5009 this is a bad time to try to read input. */
5012 read_avail_input (expected
)
5015 struct input_event buf
[KBD_BUFFER_SIZE
];
5019 if (read_socket_hook
)
5020 /* No need for FIONREAD or fcntl; just say don't wait. */
5021 nread
= (*read_socket_hook
) (input_fd
, buf
, KBD_BUFFER_SIZE
, expected
);
5024 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
5025 the kbd_buffer can really hold. That may prevent loss
5026 of characters on some systems when input is stuffed at us. */
5027 unsigned char cbuf
[KBD_BUFFER_SIZE
- 1];
5030 /* Determine how many characters we should *try* to read. */
5033 #else /* not WINDOWSNT */
5035 n_to_read
= dos_keysns ();
5038 #else /* not MSDOS */
5040 /* Find out how much input is available. */
5041 if (ioctl (input_fd
, FIONREAD
, &n_to_read
) < 0)
5042 /* Formerly simply reported no input, but that sometimes led to
5043 a failure of Emacs to terminate.
5044 SIGHUP seems appropriate if we can't reach the terminal. */
5045 /* ??? Is it really right to send the signal just to this process
5046 rather than to the whole process group?
5047 Perhaps on systems with FIONREAD Emacs is alone in its group. */
5048 kill (getpid (), SIGHUP
);
5051 if (n_to_read
> sizeof cbuf
)
5052 n_to_read
= sizeof cbuf
;
5053 #else /* no FIONREAD */
5054 #if defined (USG) || defined (DGUX)
5055 /* Read some input if available, but don't wait. */
5056 n_to_read
= sizeof cbuf
;
5057 fcntl (input_fd
, F_SETFL
, O_NDELAY
);
5062 #endif /* not MSDOS */
5063 #endif /* not WINDOWSNT */
5065 /* Now read; for one reason or another, this will not block.
5066 NREAD is set to the number of chars read. */
5070 cbuf
[0] = dos_keyread ();
5073 nread
= read (input_fd
, cbuf
, n_to_read
);
5075 /* POSIX infers that processes which are not in the session leader's
5076 process group won't get SIGHUP's at logout time. BSDI adheres to
5077 this part standard and returns -1 from read(0) with errno==EIO
5078 when the control tty is taken away.
5079 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
5080 if (nread
== -1 && errno
== EIO
)
5082 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
5083 /* The kernel sometimes fails to deliver SIGHUP for ptys.
5084 This looks incorrect, but it isn't, because _BSD causes
5085 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
5086 and that causes a value other than 0 when there is no input. */
5092 /* We used to retry the read if it was interrupted.
5093 But this does the wrong thing when O_NDELAY causes
5094 an EAGAIN error. Does anybody know of a situation
5095 where a retry is actually needed? */
5097 nread
< 0 && (errno
== EAGAIN
5111 #if defined (USG) || defined (DGUX)
5112 fcntl (input_fd
, F_SETFL
, 0);
5113 #endif /* USG or DGUX */
5114 #endif /* no FIONREAD */
5115 for (i
= 0; i
< nread
; i
++)
5117 buf
[i
].kind
= ascii_keystroke
;
5118 buf
[i
].modifiers
= 0;
5119 if (meta_key
== 1 && (cbuf
[i
] & 0x80))
5120 buf
[i
].modifiers
= meta_modifier
;
5124 buf
[i
].code
= cbuf
[i
];
5125 XSETFRAME (buf
[i
].frame_or_window
, selected_frame
);
5129 /* Scan the chars for C-g and store them in kbd_buffer. */
5130 for (i
= 0; i
< nread
; i
++)
5132 kbd_buffer_store_event (&buf
[i
]);
5133 /* Don't look at input that follows a C-g too closely.
5134 This reduces lossage due to autorepeat on C-g. */
5135 if (buf
[i
].kind
== ascii_keystroke
5136 && buf
[i
].code
== quit_char
)
5142 #endif /* not VMS */
5144 #ifdef SIGIO /* for entire page */
5145 /* Note SIGIO has been undef'd if FIONREAD is missing. */
5148 input_available_signal (signo
)
5151 /* Must preserve main program's value of errno. */
5152 int old_errno
= errno
;
5154 extern int select_alarmed
;
5157 #if defined (USG) && !defined (POSIX_SIGNALS)
5158 /* USG systems forget handlers when they are used;
5159 must reestablish each time */
5160 signal (signo
, input_available_signal
);
5167 if (input_available_clear_time
)
5168 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
5173 nread
= read_avail_input (1);
5174 /* -1 means it's not ok to read the input now.
5175 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
5176 0 means there was no keyboard input available. */
5181 select_alarmed
= 1; /* Force the select emulator back to life */
5192 /* Send ourselves a SIGIO.
5194 This function exists so that the UNBLOCK_INPUT macro in
5195 blockinput.h can have some way to take care of input we put off
5196 dealing with, without assuming that every file which uses
5197 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
5199 reinvoke_input_signal ()
5202 kill (getpid (), SIGIO
);
5208 /* Return the prompt-string of a sparse keymap.
5209 This is the first element which is a string.
5210 Return nil if there is none. */
5218 register Lisp_Object tem
;
5227 static void menu_bar_item ();
5228 static void menu_bar_one_keymap ();
5230 /* These variables hold the vector under construction within
5231 menu_bar_items and its subroutines, and the current index
5232 for storing into that vector. */
5233 static Lisp_Object menu_bar_items_vector
;
5234 static int menu_bar_items_index
;
5236 /* Return a vector of menu items for a menu bar, appropriate
5237 to the current buffer. Each item has three elements in the vector:
5240 OLD is an old vector we can optionally reuse, or nil. */
5243 menu_bar_items (old
)
5246 /* The number of keymaps we're scanning right now, and the number of
5247 keymaps we have allocated space for. */
5250 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
5251 in the current keymaps, or nil where it is not a prefix. */
5254 Lisp_Object def
, tem
, tail
;
5263 struct gcpro gcpro1
;
5265 /* In order to build the menus, we need to call the keymap
5266 accessors. They all call QUIT. But this function is called
5267 during redisplay, during which a quit is fatal. So inhibit
5268 quitting while building the menus.
5269 We do this instead of specbind because (1) errors will clear it anyway
5270 and (2) this avoids risk of specpdl overflow. */
5271 oquit
= Vinhibit_quit
;
5275 menu_bar_items_vector
= old
;
5277 menu_bar_items_vector
= Fmake_vector (make_number (24), Qnil
);
5278 menu_bar_items_index
= 0;
5280 GCPRO1 (menu_bar_items_vector
);
5282 /* Build our list of keymaps.
5283 If we recognize a function key and replace its escape sequence in
5284 keybuf with its symbol, or if the sequence starts with a mouse
5285 click and we need to switch buffers, we jump back here to rebuild
5286 the initial keymaps from the current buffer. */
5290 /* Should overriding-terminal-local-map and overriding-local-map apply? */
5291 if (!NILP (Voverriding_local_map_menu_flag
))
5293 /* Yes, use them (if non-nil) as well as the global map. */
5294 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
5296 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
5297 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
5298 if (!NILP (Voverriding_local_map
))
5299 maps
[nmaps
++] = Voverriding_local_map
;
5303 /* No, so use major and minor mode keymaps. */
5304 nmaps
= current_minor_maps (NULL
, &tmaps
);
5305 maps
= (Lisp_Object
*) alloca ((nmaps
+ 2) * sizeof (maps
[0]));
5306 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
5307 #ifdef USE_TEXT_PROPERTIES
5308 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
5310 maps
[nmaps
++] = current_buffer
->keymap
;
5313 maps
[nmaps
++] = current_global_map
;
5316 /* Look up in each map the dummy prefix key `menu-bar'. */
5320 for (mapno
= nmaps
- 1; mapno
>= 0; mapno
--)
5322 if (! NILP (maps
[mapno
]))
5323 def
= get_keyelt (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0), 0);
5327 tem
= Fkeymapp (def
);
5329 menu_bar_one_keymap (def
);
5332 /* Move to the end those items that should be at the end. */
5334 for (tail
= Vmenu_bar_final_items
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5337 int end
= menu_bar_items_index
;
5339 for (i
= 0; i
< end
; i
+= 4)
5340 if (EQ (XCONS (tail
)->car
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
5342 Lisp_Object tem0
, tem1
, tem2
, tem3
;
5343 /* Move the item at index I to the end,
5344 shifting all the others forward. */
5345 tem0
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 0];
5346 tem1
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 1];
5347 tem2
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
5348 tem3
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3];
5350 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
5351 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
5352 (end
- i
- 4) * sizeof (Lisp_Object
));
5353 XVECTOR (menu_bar_items_vector
)->contents
[end
- 4] = tem0
;
5354 XVECTOR (menu_bar_items_vector
)->contents
[end
- 3] = tem1
;
5355 XVECTOR (menu_bar_items_vector
)->contents
[end
- 2] = tem2
;
5356 XVECTOR (menu_bar_items_vector
)->contents
[end
- 1] = tem3
;
5361 /* Add nil, nil, nil, nil at the end. */
5362 i
= menu_bar_items_index
;
5363 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
5366 int newsize
= 2 * i
;
5367 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
5368 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
5369 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
5370 menu_bar_items_vector
= tem
;
5372 /* Add this item. */
5373 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5374 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5375 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5376 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5377 menu_bar_items_index
= i
;
5379 Vinhibit_quit
= oquit
;
5381 return menu_bar_items_vector
;
5384 /* Scan one map KEYMAP, accumulating any menu items it defines
5385 in menu_bar_items_vector. */
5388 menu_bar_one_keymap (keymap
)
5391 Lisp_Object tail
, item
, key
, binding
, item_string
, table
;
5393 /* Loop over all keymap entries that have menu strings. */
5394 for (tail
= keymap
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5396 item
= XCONS (tail
)->car
;
5399 key
= XCONS (item
)->car
;
5400 binding
= XCONS (item
)->cdr
;
5401 if (CONSP (binding
))
5403 item_string
= XCONS (binding
)->car
;
5404 if (STRINGP (item_string
))
5405 menu_bar_item (key
, item_string
, Fcdr (binding
));
5407 else if (EQ (binding
, Qundefined
))
5408 menu_bar_item (key
, Qnil
, binding
);
5410 else if (VECTORP (item
))
5412 /* Loop over the char values represented in the vector. */
5413 int len
= XVECTOR (item
)->size
;
5415 for (c
= 0; c
< len
; c
++)
5417 Lisp_Object character
;
5418 XSETFASTINT (character
, c
);
5419 binding
= XVECTOR (item
)->contents
[c
];
5420 if (CONSP (binding
))
5422 item_string
= XCONS (binding
)->car
;
5423 if (STRINGP (item_string
))
5424 menu_bar_item (key
, item_string
, Fcdr (binding
));
5426 else if (EQ (binding
, Qundefined
))
5427 menu_bar_item (key
, Qnil
, binding
);
5433 /* This is used as the handler when calling internal_condition_case_1. */
5436 menu_bar_item_1 (arg
)
5442 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
5443 If there's already an item for KEY, add this DEF to it. */
5446 menu_bar_item (key
, item_string
, def
)
5447 Lisp_Object key
, item_string
, def
;
5450 Lisp_Object enabled
;
5453 /* Skip menu-bar equiv keys data. */
5454 if (CONSP (def
) && CONSP (XCONS (def
)->car
))
5455 def
= XCONS (def
)->cdr
;
5457 if (EQ (def
, Qundefined
))
5459 /* If a map has an explicit `undefined' as definition,
5460 discard any previously made menu bar item. */
5462 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
5463 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
5465 if (menu_bar_items_index
> i
+ 4)
5466 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
5467 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
5468 (menu_bar_items_index
- i
- 4) * sizeof (Lisp_Object
));
5469 menu_bar_items_index
-= 4;
5473 /* If there's no definition for this key yet,
5474 just ignore `undefined'. */
5478 /* See if this entry is enabled. */
5483 /* No property, or nil, means enable.
5484 Otherwise, enable if value is not nil. */
5485 tem
= Fget (def
, Qmenu_enable
);
5487 /* (condition-case nil (eval tem)
5489 enabled
= internal_condition_case_1 (Feval
, tem
, Qerror
,
5493 /* Ignore this item if it's not enabled. */
5497 /* Find any existing item for this KEY. */
5498 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
5499 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
5502 /* If we did not find this KEY, add it at the end. */
5503 if (i
== menu_bar_items_index
)
5505 /* If vector is too small, get a bigger one. */
5506 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
5509 int newsize
= 2 * i
;
5510 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
5511 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
5512 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
5513 menu_bar_items_vector
= tem
;
5515 /* Add this item. */
5516 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = key
;
5517 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = item_string
;
5518 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Fcons (def
, Qnil
);
5519 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = make_number (0);
5520 menu_bar_items_index
= i
;
5522 /* We did find an item for this KEY. Add DEF to its list of maps. */
5526 old
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
5527 XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2] = Fcons (def
, old
);
5531 /* Read a character using menus based on maps in the array MAPS.
5532 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
5533 Return t if we displayed a menu but the user rejected it.
5535 PREV_EVENT is the previous input event, or nil if we are reading
5536 the first event of a key sequence.
5538 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
5539 if we used a mouse menu to read the input, or zero otherwise. If
5540 USED_MOUSE_MENU is null, we don't dereference it.
5542 The prompting is done based on the prompt-string of the map
5543 and the strings associated with various map elements.
5545 This can be done with X menus or with menus put in the minibuf.
5546 These are done in different ways, depending on how the input will be read.
5547 Menus using X are done after auto-saving in read-char, getting the input
5548 event from Fx_popup_menu; menus using the minibuf use read_char recursively
5549 and do auto-saving in the inner call of read_char. */
5552 read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
5555 Lisp_Object prev_event
;
5556 int *used_mouse_menu
;
5559 register Lisp_Object name
;
5560 Lisp_Object rest
, vector
;
5562 if (used_mouse_menu
)
5563 *used_mouse_menu
= 0;
5565 /* Use local over global Menu maps */
5567 if (! menu_prompting
)
5570 /* Optionally disregard all but the global map. */
5571 if (inhibit_local_menu_bar_menus
)
5573 maps
+= (nmaps
- 1);
5577 /* Get the menu name from the first map that has one (a prompt string). */
5578 for (mapno
= 0; mapno
< nmaps
; mapno
++)
5580 name
= map_prompt (maps
[mapno
]);
5585 /* If we don't have any menus, just read a character normally. */
5590 /* If we got to this point via a mouse click,
5591 use a real menu for mouse selection. */
5592 if (EVENT_HAS_PARAMETERS (prev_event
)
5593 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
))
5595 /* Display the menu and get the selection. */
5596 Lisp_Object
*realmaps
5597 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
5601 /* Use the maps that are not nil. */
5602 for (mapno
= 0; mapno
< nmaps
; mapno
++)
5603 if (!NILP (maps
[mapno
]))
5604 realmaps
[nmaps1
++] = maps
[mapno
];
5606 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
5611 record_menu_key (XCONS (value
)->car
);
5613 /* If we got multiple events, unread all but
5615 There is no way to prevent those unread events
5616 from showing up later in last_nonmenu_event.
5617 So turn symbol and integer events into lists,
5618 to indicate that they came from a mouse menu,
5619 so that when present in last_nonmenu_event
5620 they won't confuse things. */
5621 for (tem
= XCONS (value
)->cdr
; !NILP (tem
);
5622 tem
= XCONS (tem
)->cdr
)
5624 record_menu_key (XCONS (tem
)->car
);
5625 if (SYMBOLP (XCONS (tem
)->car
)
5626 || INTEGERP (XCONS (tem
)->car
))
5628 = Fcons (XCONS (tem
)->car
, Qnil
);
5631 /* If we got more than one event, put all but the first
5632 onto this list to be read later.
5633 Return just the first event now. */
5634 Vunread_command_events
5635 = nconc2 (XCONS (value
)->cdr
, Vunread_command_events
);
5636 value
= XCONS (value
)->car
;
5638 else if (NILP (value
))
5640 if (used_mouse_menu
)
5641 *used_mouse_menu
= 1;
5644 #endif /* HAVE_MENUS */
5648 /* Buffer in use so far for the minibuf prompts for menu keymaps.
5649 We make this bigger when necessary, and never free it. */
5650 static char *read_char_minibuf_menu_text
;
5651 /* Size of that buffer. */
5652 static int read_char_minibuf_menu_width
;
5655 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
5661 register Lisp_Object name
;
5663 int width
= FRAME_WIDTH (selected_frame
) - 4;
5666 Lisp_Object rest
, vector
;
5669 if (! menu_prompting
)
5672 /* Make sure we have a big enough buffer for the menu text. */
5673 if (read_char_minibuf_menu_text
== 0)
5675 read_char_minibuf_menu_width
= width
+ 4;
5676 read_char_minibuf_menu_text
= (char *) xmalloc (width
+ 4);
5678 else if (width
+ 4 > read_char_minibuf_menu_width
)
5680 read_char_minibuf_menu_width
= width
+ 4;
5681 read_char_minibuf_menu_text
5682 = (char *) xrealloc (read_char_minibuf_menu_text
, width
+ 4);
5684 menu
= read_char_minibuf_menu_text
;
5686 /* Get the menu name from the first map that has one (a prompt string). */
5687 for (mapno
= 0; mapno
< nmaps
; mapno
++)
5689 name
= map_prompt (maps
[mapno
]);
5694 /* If we don't have any menus, just read a character normally. */
5698 /* Prompt string always starts with map's prompt, and a space. */
5699 strcpy (menu
, XSTRING (name
)->data
);
5700 nlength
= XSTRING (name
)->size
;
5701 menu
[nlength
++] = ':';
5702 menu
[nlength
++] = ' ';
5705 /* Start prompting at start of first map. */
5709 /* Present the documented bindings, a line at a time. */
5716 Lisp_Object orig_defn_macro
;
5718 /* Loop over elements of map. */
5723 /* If reached end of map, start at beginning of next map. */
5727 /* At end of last map, wrap around to first map if just starting,
5728 or end this line if already have something on it. */
5732 if (notfirst
|| nobindings
) break;
5737 /* Look at the next element of the map. */
5739 elt
= XVECTOR (vector
)->contents
[idx
];
5741 elt
= Fcar_safe (rest
);
5743 if (idx
< 0 && VECTORP (elt
))
5745 /* If we found a dense table in the keymap,
5746 advanced past it, but start scanning its contents. */
5747 rest
= Fcdr_safe (rest
);
5753 /* An ordinary element. */
5758 s
= Fcar_safe (Fcdr_safe (elt
)); /* alist */
5759 event
= Fcar_safe (elt
);
5763 s
= Fcar_safe (elt
); /* vector */
5764 XSETINT (event
, idx
);
5767 /* Ignore the element if it has no prompt string. */
5768 if (STRINGP (s
) && INTEGERP (event
))
5770 /* 1 if the char to type matches the string. */
5772 Lisp_Object upcased_event
, downcased_event
;
5775 upcased_event
= Fupcase (event
);
5776 downcased_event
= Fdowncase (event
);
5777 char_matches
= (XINT (upcased_event
) == XSTRING (s
)->data
[0]
5778 || XINT (downcased_event
) == XSTRING (s
)->data
[0]);
5780 desc
= Fsingle_key_description (event
);
5782 /* If we have room for the prompt string, add it to this line.
5783 If this is the first on the line, always add it. */
5784 if ((XSTRING (s
)->size
+ i
+ 2
5785 + (char_matches
? 0 : XSTRING (desc
)->size
+ 3))
5791 /* Punctuate between strings. */
5794 strcpy (menu
+ i
, ", ");
5800 /* If the char to type doesn't match the string's
5801 first char, explicitly show what char to type. */
5804 /* Add as much of string as fits. */
5805 thiswidth
= XSTRING (desc
)->size
;
5806 if (thiswidth
+ i
> width
)
5807 thiswidth
= width
- i
;
5808 bcopy (XSTRING (desc
)->data
, menu
+ i
, thiswidth
);
5810 strcpy (menu
+ i
, " = ");
5814 /* Add as much of string as fits. */
5815 thiswidth
= XSTRING (s
)->size
;
5816 if (thiswidth
+ i
> width
)
5817 thiswidth
= width
- i
;
5818 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
5824 /* If this element does not fit, end the line now,
5825 and save the element for the next line. */
5826 strcpy (menu
+ i
, "...");
5831 /* Move past this element. */
5832 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
5833 /* Handle reaching end of dense table. */
5838 rest
= Fcdr_safe (rest
);
5842 /* Prompt with that and read response. */
5845 /* Make believe its not a keyboard macro in case the help char
5846 is pressed. Help characters are not recorded because menu prompting
5847 is not used on replay.
5849 orig_defn_macro
= current_kboard
->defining_kbd_macro
;
5850 current_kboard
->defining_kbd_macro
= Qnil
;
5852 obj
= read_char (commandflag
, 0, 0, Qnil
, 0);
5853 while (BUFFERP (obj
));
5854 current_kboard
->defining_kbd_macro
= orig_defn_macro
;
5856 if (!INTEGERP (obj
))
5861 if (! EQ (obj
, menu_prompt_more_char
)
5862 && (!INTEGERP (menu_prompt_more_char
)
5863 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
5865 if (!NILP (current_kboard
->defining_kbd_macro
))
5866 store_kbd_macro_char (obj
);
5869 /* Help char - go round again */
5873 /* Reading key sequences. */
5875 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
5876 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
5877 keymap, or nil otherwise. Return the index of the first keymap in
5878 which KEY has any binding, or NMAPS if no map has a binding.
5880 If KEY is a meta ASCII character, treat it like meta-prefix-char
5881 followed by the corresponding non-meta character. Keymaps in
5882 CURRENT with non-prefix bindings for meta-prefix-char become nil in
5885 If KEY has no bindings in any of the CURRENT maps, NEXT is left
5888 NEXT may be the same array as CURRENT. */
5891 follow_key (key
, nmaps
, current
, defs
, next
)
5893 Lisp_Object
*current
, *defs
, *next
;
5896 int i
, first_binding
;
5899 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
5900 followed by the corresponding non-meta character.
5901 Put the results into DEFS, since we are going to alter that anyway.
5902 Do not alter CURRENT or NEXT. */
5903 if (INTEGERP (key
) && (XINT (key
) & CHAR_META
))
5905 for (i
= 0; i
< nmaps
; i
++)
5906 if (! NILP (current
[i
]))
5909 def
= get_keyelt (access_keymap (current
[i
],
5910 meta_prefix_char
, 1, 0), 0);
5912 /* Note that since we pass the resulting bindings through
5913 get_keymap_1, non-prefix bindings for meta-prefix-char
5915 defs
[i
] = get_keymap_1 (def
, 0, 1);
5921 XSETINT (key
, XFASTINT (key
) & ~CHAR_META
);
5924 first_binding
= nmaps
;
5925 for (i
= nmaps
- 1; i
>= 0; i
--)
5927 if (! NILP (current
[i
]))
5935 defs
[i
] = get_keyelt (access_keymap (map
, key
, 1, 0), 0);
5936 if (! NILP (defs
[i
]))
5943 /* Given the set of bindings we've found, produce the next set of maps. */
5944 if (first_binding
< nmaps
)
5945 for (i
= 0; i
< nmaps
; i
++)
5946 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0, 1);
5948 return first_binding
;
5951 /* Read a sequence of keys that ends with a non prefix character,
5952 storing it in KEYBUF, a buffer of size BUFSIZE.
5954 Return the length of the key sequence stored.
5955 Return -1 if the user rejected a command menu.
5957 Echo starting immediately unless `prompt' is 0.
5959 Where a key sequence ends depends on the currently active keymaps.
5960 These include any minor mode keymaps active in the current buffer,
5961 the current buffer's local map, and the global map.
5963 If a key sequence has no other bindings, we check Vfunction_key_map
5964 to see if some trailing subsequence might be the beginning of a
5965 function key's sequence. If so, we try to read the whole function
5966 key, and substitute its symbolic name into the key sequence.
5968 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
5969 `double-' events into similar click events, if that would make them
5970 bound. We try to turn `triple-' events first into `double-' events,
5973 If we get a mouse click in a mode line, vertical divider, or other
5974 non-text area, we treat the click as if it were prefixed by the
5975 symbol denoting that area - `mode-line', `vertical-line', or
5978 If the sequence starts with a mouse click, we read the key sequence
5979 with respect to the buffer clicked on, not the current buffer.
5981 If the user switches frames in the midst of a key sequence, we put
5982 off the switch-frame event until later; the next call to
5983 read_char will return it.
5985 If FIX_CURRENT_BUFFER is nonzero, we restore current_buffer
5986 from the selected window's buffer. */
5989 read_key_sequence (keybuf
, bufsize
, prompt
, dont_downcase_last
,
5990 can_return_switch_frame
, fix_current_buffer
)
5991 Lisp_Object
*keybuf
;
5994 int dont_downcase_last
;
5995 int can_return_switch_frame
;
5996 int fix_current_buffer
;
5998 int count
= specpdl_ptr
- specpdl
;
6000 /* How many keys there are in the current key sequence. */
6003 /* The length of the echo buffer when we started reading, and
6004 the length of this_command_keys when we started reading. */
6008 /* The number of keymaps we're scanning right now, and the number of
6009 keymaps we have allocated space for. */
6011 int nmaps_allocated
= 0;
6013 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
6014 the current keymaps. */
6017 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
6018 in the current keymaps, or nil where it is not a prefix. */
6019 Lisp_Object
*submaps
;
6021 /* The local map to start out with at start of key sequence. */
6022 Lisp_Object orig_local_map
;
6024 /* 1 if we have already considered switching to the local-map property
6025 of the place where a mouse click occurred. */
6026 int localized_local_map
= 0;
6028 /* The index in defs[] of the first keymap that has a binding for
6029 this key sequence. In other words, the lowest i such that
6030 defs[i] is non-nil. */
6033 /* If t < mock_input, then KEYBUF[t] should be read as the next
6036 We use this to recover after recognizing a function key. Once we
6037 realize that a suffix of the current key sequence is actually a
6038 function key's escape sequence, we replace the suffix with the
6039 function key's binding from Vfunction_key_map. Now keybuf
6040 contains a new and different key sequence, so the echo area,
6041 this_command_keys, and the submaps and defs arrays are wrong. In
6042 this situation, we set mock_input to t, set t to 0, and jump to
6043 restart_sequence; the loop will read keys from keybuf up until
6044 mock_input, thus rebuilding the state; and then it will resume
6045 reading characters from the keyboard. */
6048 /* If the sequence is unbound in submaps[], then
6049 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
6050 and fkey_map is its binding.
6052 These might be > t, indicating that all function key scanning
6053 should hold off until t reaches them. We do this when we've just
6054 recognized a function key, to avoid searching for the function
6055 key's again in Vfunction_key_map. */
6056 int fkey_start
= 0, fkey_end
= 0;
6057 Lisp_Object fkey_map
;
6059 /* Likewise, for key_translation_map. */
6060 int keytran_start
= 0, keytran_end
= 0;
6061 Lisp_Object keytran_map
;
6063 /* If we receive a ``switch-frame'' event in the middle of a key sequence,
6064 we put it off for later. While we're reading, we keep the event here. */
6065 Lisp_Object delayed_switch_frame
;
6067 /* See the comment below... */
6068 #if defined (GOBBLE_FIRST_EVENT)
6069 Lisp_Object first_event
;
6072 Lisp_Object original_uppercase
;
6073 int original_uppercase_position
= -1;
6075 /* Gets around Microsoft compiler limitations. */
6078 struct buffer
*starting_buffer
;
6080 /* Nonzero if we seem to have got the beginning of a binding
6081 in function_key_map. */
6082 int function_key_possible
= 0;
6083 int key_translation_possible
= 0;
6085 /* Save the status of key translation before each step,
6086 so that we can restore this after downcasing. */
6087 Lisp_Object prev_fkey_map
;
6088 int prev_fkey_start
;
6091 Lisp_Object prev_keytran_map
;
6092 int prev_keytran_start
;
6093 int prev_keytran_end
;
6097 last_nonmenu_event
= Qnil
;
6099 delayed_switch_frame
= Qnil
;
6100 fkey_map
= Vfunction_key_map
;
6101 keytran_map
= Vkey_translation_map
;
6103 /* If there is no function-key-map, turn off function key scanning. */
6104 if (NILP (Fkeymapp (Vfunction_key_map
)))
6105 fkey_start
= fkey_end
= bufsize
+ 1;
6107 /* If there is no key-translation-map, turn off scanning. */
6108 if (NILP (Fkeymapp (Vkey_translation_map
)))
6109 keytran_start
= keytran_end
= bufsize
+ 1;
6114 echo_prompt (XSTRING (prompt
)->data
);
6115 else if (cursor_in_echo_area
&& echo_keystrokes
)
6116 /* This doesn't put in a dash if the echo buffer is empty, so
6117 you don't always see a dash hanging out in the minibuffer. */
6121 /* Record the initial state of the echo area and this_command_keys;
6122 we will need to restore them if we replay a key sequence. */
6124 echo_start
= echo_length ();
6125 keys_start
= this_command_key_count
;
6126 this_single_command_key_start
= keys_start
;
6128 #if defined (GOBBLE_FIRST_EVENT)
6129 /* This doesn't quite work, because some of the things that read_char
6130 does cannot safely be bypassed. It seems too risky to try to make
6133 /* Read the first char of the sequence specially, before setting
6134 up any keymaps, in case a filter runs and switches buffers on us. */
6135 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
6137 #endif /* GOBBLE_FIRST_EVENT */
6139 orig_local_map
= get_local_map (PT
, current_buffer
);
6141 /* We jump here when the key sequence has been thoroughly changed, and
6142 we need to rescan it starting from the beginning. When we jump here,
6143 keybuf[0..mock_input] holds the sequence we should reread. */
6146 starting_buffer
= current_buffer
;
6147 function_key_possible
= 0;
6148 key_translation_possible
= 0;
6150 /* Build our list of keymaps.
6151 If we recognize a function key and replace its escape sequence in
6152 keybuf with its symbol, or if the sequence starts with a mouse
6153 click and we need to switch buffers, we jump back here to rebuild
6154 the initial keymaps from the current buffer. */
6158 if (!NILP (current_kboard
->Voverriding_terminal_local_map
)
6159 || !NILP (Voverriding_local_map
))
6161 if (3 > nmaps_allocated
)
6163 submaps
= (Lisp_Object
*) alloca (3 * sizeof (submaps
[0]));
6164 defs
= (Lisp_Object
*) alloca (3 * sizeof (defs
[0]));
6165 nmaps_allocated
= 3;
6168 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
6169 submaps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
6170 if (!NILP (Voverriding_local_map
))
6171 submaps
[nmaps
++] = Voverriding_local_map
;
6175 nmaps
= current_minor_maps (0, &maps
);
6176 if (nmaps
+ 2 > nmaps_allocated
)
6178 submaps
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (submaps
[0]));
6179 defs
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (defs
[0]));
6180 nmaps_allocated
= nmaps
+ 2;
6182 bcopy (maps
, submaps
, nmaps
* sizeof (submaps
[0]));
6183 #ifdef USE_TEXT_PROPERTIES
6184 submaps
[nmaps
++] = orig_local_map
;
6186 submaps
[nmaps
++] = current_buffer
->keymap
;
6189 submaps
[nmaps
++] = current_global_map
;
6192 /* Find an accurate initial value for first_binding. */
6193 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
6194 if (! NILP (submaps
[first_binding
]))
6197 /* Start from the beginning in keybuf. */
6200 /* These are no-ops the first time through, but if we restart, they
6201 revert the echo area and this_command_keys to their original state. */
6202 this_command_key_count
= keys_start
;
6203 if (INTERACTIVE
&& t
< mock_input
)
6204 echo_truncate (echo_start
);
6206 /* If the best binding for the current key sequence is a keymap, or
6207 we may be looking at a function key's escape sequence, keep on
6209 while ((first_binding
< nmaps
&& ! NILP (submaps
[first_binding
]))
6210 || (first_binding
>= nmaps
6212 /* mock input is never part of a function key's sequence. */
6213 && mock_input
<= fkey_start
)
6214 || (first_binding
>= nmaps
6215 && keytran_start
< t
&& key_translation_possible
)
6216 /* Don't return in the middle of a possible function key sequence,
6217 if the only bindings we found were via case conversion.
6218 Thus, if ESC O a has a function-key-map translation
6219 and ESC o has a binding, don't return after ESC O,
6220 so that we can translate ESC O plus the next character. */
6224 int used_mouse_menu
= 0;
6226 /* Where the last real key started. If we need to throw away a
6227 key that has expanded into more than one element of keybuf
6228 (say, a mouse click on the mode line which is being treated
6229 as [mode-line (mouse-...)], then we backtrack to this point
6231 int last_real_key_start
;
6233 /* These variables are analogous to echo_start and keys_start;
6234 while those allow us to restart the entire key sequence,
6235 echo_local_start and keys_local_start allow us to throw away
6237 int echo_local_start
, keys_local_start
, local_first_binding
;
6240 error ("Key sequence too long");
6243 echo_local_start
= echo_length ();
6244 keys_local_start
= this_command_key_count
;
6245 local_first_binding
= first_binding
;
6248 /* These are no-ops, unless we throw away a keystroke below and
6249 jumped back up to replay_key; in that case, these restore the
6250 variables to their original state, allowing us to replay the
6252 if (INTERACTIVE
&& t
< mock_input
)
6253 echo_truncate (echo_local_start
);
6254 this_command_key_count
= keys_local_start
;
6255 first_binding
= local_first_binding
;
6257 /* By default, assume each event is "real". */
6258 last_real_key_start
= t
;
6260 /* Does mock_input indicate that we are re-reading a key sequence? */
6264 add_command_key (key
);
6265 if (echo_keystrokes
)
6269 /* If not, we should actually read a character. */
6272 struct buffer
*buf
= current_buffer
;
6276 KBOARD
*interrupted_kboard
= current_kboard
;
6277 struct frame
*interrupted_frame
= selected_frame
;
6278 if (setjmp (wrong_kboard_jmpbuf
))
6280 if (!NILP (delayed_switch_frame
))
6282 interrupted_kboard
->kbd_queue
6283 = Fcons (delayed_switch_frame
,
6284 interrupted_kboard
->kbd_queue
);
6285 delayed_switch_frame
= Qnil
;
6288 interrupted_kboard
->kbd_queue
6289 = Fcons (keybuf
[--t
], interrupted_kboard
->kbd_queue
);
6291 /* If the side queue is non-empty, ensure it begins with a
6292 switch-frame, so we'll replay it in the right context. */
6293 if (CONSP (interrupted_kboard
->kbd_queue
)
6294 && (key
= XCONS (interrupted_kboard
->kbd_queue
)->car
,
6295 !(EVENT_HAS_PARAMETERS (key
)
6296 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)),
6300 XSETFRAME (frame
, interrupted_frame
);
6301 interrupted_kboard
->kbd_queue
6302 = Fcons (make_lispy_switch_frame (frame
),
6303 interrupted_kboard
->kbd_queue
);
6306 orig_local_map
= get_local_map (PT
, current_buffer
);
6307 goto replay_sequence
;
6310 key
= read_char (NILP (prompt
), nmaps
, submaps
, last_nonmenu_event
,
6314 /* read_char returns t when it shows a menu and the user rejects it.
6319 /* read_char returns -1 at the end of a macro.
6320 Emacs 18 handles this by returning immediately with a
6321 zero, so that's what we'll do. */
6322 if (INTEGERP (key
) && XINT (key
) == -1)
6325 /* The Microsoft C compiler can't handle the goto that
6331 /* If the current buffer has been changed from under us, the
6332 keymap may have changed, so replay the sequence. */
6336 /* Reset the current buffer from the selected window
6337 in case something changed the former and not the latter.
6338 This is to be more consistent with the behavior
6339 of the command_loop_1. */
6340 if (fix_current_buffer
)
6341 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
6342 Fset_buffer (XWINDOW (selected_window
)->buffer
);
6344 orig_local_map
= get_local_map (PT
, current_buffer
);
6345 goto replay_sequence
;
6348 /* If we have a quit that was typed in another frame, and
6349 quit_throw_to_read_char switched buffers,
6350 replay to get the right keymap. */
6351 if (XINT (key
) == quit_char
&& current_buffer
!= starting_buffer
)
6356 orig_local_map
= get_local_map (PT
, current_buffer
);
6357 goto replay_sequence
;
6363 /* Clicks in non-text areas get prefixed by the symbol
6364 in their CHAR-ADDRESS field. For example, a click on
6365 the mode line is prefixed by the symbol `mode-line'.
6367 Furthermore, key sequences beginning with mouse clicks
6368 are read using the keymaps of the buffer clicked on, not
6369 the current buffer. So we may have to switch the buffer
6372 When we turn one event into two events, we must make sure
6373 that neither of the two looks like the original--so that,
6374 if we replay the events, they won't be expanded again.
6375 If not for this, such reexpansion could happen either here
6376 or when user programs play with this-command-keys. */
6377 if (EVENT_HAS_PARAMETERS (key
))
6381 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
6382 if (EQ (kind
, Qmouse_click
))
6384 Lisp_Object window
, posn
;
6386 window
= POSN_WINDOW (EVENT_START (key
));
6387 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
6390 /* We're looking at the second event of a
6391 sequence which we expanded before. Set
6392 last_real_key_start appropriately. */
6394 last_real_key_start
= t
- 1;
6397 /* Key sequences beginning with mouse clicks are
6398 read using the keymaps in the buffer clicked on,
6399 not the current buffer. If we're at the
6400 beginning of a key sequence, switch buffers. */
6401 if (last_real_key_start
== 0
6403 && BUFFERP (XWINDOW (window
)->buffer
)
6404 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
6409 /* Arrange to go back to the original buffer once we're
6410 done reading the key sequence. Note that we can't
6411 use save_excursion_{save,restore} here, because they
6412 save point as well as the current buffer; we don't
6413 want to save point, because redisplay may change it,
6414 to accommodate a Fset_window_start or something. We
6415 don't want to do this at the top of the function,
6416 because we may get input from a subprocess which
6417 wants to change the selected window and stuff (say,
6419 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
6421 set_buffer_internal (XBUFFER (XWINDOW (window
)->buffer
));
6422 orig_local_map
= get_local_map (PT
, current_buffer
);
6423 goto replay_sequence
;
6425 /* For a mouse click, get the local text-property keymap
6426 of the place clicked on, rather than point. */
6427 if (last_real_key_start
== 0 && CONSP (XCONS (key
)->cdr
)
6428 && ! localized_local_map
)
6430 Lisp_Object map_here
, start
, pos
;
6432 localized_local_map
= 1;
6433 start
= EVENT_START (key
);
6434 if (CONSP (start
) && CONSP (XCONS (start
)->cdr
))
6436 pos
= POSN_BUFFER_POSN (start
);
6438 && XINT (pos
) >= BEG
&& XINT (pos
) <= Z
)
6440 map_here
= get_local_map (XINT (pos
), current_buffer
);
6441 if (!EQ (map_here
, orig_local_map
))
6443 orig_local_map
= map_here
;
6447 goto replay_sequence
;
6453 /* Expand mode-line and scroll-bar events into two events:
6454 use posn as a fake prefix key. */
6457 if (t
+ 1 >= bufsize
)
6458 error ("Key sequence too long");
6463 /* Zap the position in key, so we know that we've
6464 expanded it, and don't try to do so again. */
6465 POSN_BUFFER_POSN (EVENT_START (key
))
6466 = Fcons (posn
, Qnil
);
6470 else if (EQ (kind
, Qswitch_frame
))
6472 /* If we're at the beginning of a key sequence, and the caller
6473 says it's okay, go ahead and return this event. If we're
6474 in the midst of a key sequence, delay it until the end. */
6475 if (t
> 0 || !can_return_switch_frame
)
6477 delayed_switch_frame
= key
;
6481 else if (CONSP (XCONS (key
)->cdr
)
6482 && CONSP (EVENT_START (key
))
6483 && CONSP (XCONS (EVENT_START (key
))->cdr
))
6487 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
6488 /* Handle menu-bar events:
6489 insert the dummy prefix event `menu-bar'. */
6490 if (EQ (posn
, Qmenu_bar
))
6492 if (t
+ 1 >= bufsize
)
6493 error ("Key sequence too long");
6497 /* Zap the position in key, so we know that we've
6498 expanded it, and don't try to do so again. */
6499 POSN_BUFFER_POSN (EVENT_START (key
))
6500 = Fcons (posn
, Qnil
);
6503 goto replay_sequence
;
6505 else if (CONSP (posn
))
6507 /* We're looking at the second event of a
6508 sequence which we expanded before. Set
6509 last_real_key_start appropriately. */
6510 if (last_real_key_start
== t
&& t
> 0)
6511 last_real_key_start
= t
- 1;
6516 /* We have finally decided that KEY is something we might want
6518 first_binding
= (follow_key (key
,
6519 nmaps
- first_binding
,
6520 submaps
+ first_binding
,
6521 defs
+ first_binding
,
6522 submaps
+ first_binding
)
6525 /* If KEY wasn't bound, we'll try some fallbacks. */
6526 if (first_binding
>= nmaps
)
6530 head
= EVENT_HEAD (key
);
6531 if (help_char_p (head
) && t
> 0)
6533 read_key_sequence_cmd
= Vprefix_help_command
;
6535 last_nonmenu_event
= key
;
6536 /* The Microsoft C compiler can't handle the goto that
6544 Lisp_Object breakdown
;
6547 breakdown
= parse_modifiers (head
);
6548 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
6549 /* Attempt to reduce an unbound mouse event to a simpler
6550 event that is bound:
6551 Drags reduce to clicks.
6552 Double-clicks reduce to clicks.
6553 Triple-clicks reduce to double-clicks, then to clicks.
6554 Down-clicks are eliminated.
6555 Double-downs reduce to downs, then are eliminated.
6556 Triple-downs reduce to double-downs, then to downs,
6557 then are eliminated. */
6558 if (modifiers
& (down_modifier
| drag_modifier
6559 | double_modifier
| triple_modifier
))
6561 while (modifiers
& (down_modifier
| drag_modifier
6562 | double_modifier
| triple_modifier
))
6564 Lisp_Object new_head
, new_click
;
6565 if (modifiers
& triple_modifier
)
6566 modifiers
^= (double_modifier
| triple_modifier
);
6567 else if (modifiers
& double_modifier
)
6568 modifiers
&= ~double_modifier
;
6569 else if (modifiers
& drag_modifier
)
6570 modifiers
&= ~drag_modifier
;
6573 /* Dispose of this `down' event by simply jumping
6574 back to replay_key, to get another event.
6576 Note that if this event came from mock input,
6577 then just jumping back to replay_key will just
6578 hand it to us again. So we have to wipe out any
6581 We could delete keybuf[t] and shift everything
6582 after that to the left by one spot, but we'd also
6583 have to fix up any variable that points into
6584 keybuf, and shifting isn't really necessary
6587 Adding prefixes for non-textual mouse clicks
6588 creates two characters of mock input, and both
6589 must be thrown away. If we're only looking at
6590 the prefix now, we can just jump back to
6591 replay_key. On the other hand, if we've already
6592 processed the prefix, and now the actual click
6593 itself is giving us trouble, then we've lost the
6594 state of the keymaps we want to backtrack to, and
6595 we need to replay the whole sequence to rebuild
6598 Beyond that, only function key expansion could
6599 create more than two keys, but that should never
6600 generate mouse events, so it's okay to zero
6601 mock_input in that case too.
6603 Isn't this just the most wonderful code ever? */
6604 if (t
== last_real_key_start
)
6611 mock_input
= last_real_key_start
;
6612 goto replay_sequence
;
6617 = apply_modifiers (modifiers
, XCONS (breakdown
)->car
);
6619 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
6621 /* Look for a binding for this new key. follow_key
6622 promises that it didn't munge submaps the
6623 last time we called it, since key was unbound. */
6625 = (follow_key (new_click
,
6626 nmaps
- local_first_binding
,
6627 submaps
+ local_first_binding
,
6628 defs
+ local_first_binding
,
6629 submaps
+ local_first_binding
)
6630 + local_first_binding
);
6632 /* If that click is bound, go for it. */
6633 if (first_binding
< nmaps
)
6638 /* Otherwise, we'll leave key set to the drag event. */
6645 /* Normally, last_nonmenu_event gets the previous key we read.
6646 But when a mouse popup menu is being used,
6647 we don't update last_nonmenu_event; it continues to hold the mouse
6648 event that preceded the first level of menu. */
6649 if (!used_mouse_menu
)
6650 last_nonmenu_event
= key
;
6652 /* Record what part of this_command_keys is the current key sequence. */
6653 this_single_command_key_start
= this_command_key_count
- t
;
6655 prev_fkey_map
= fkey_map
;
6656 prev_fkey_start
= fkey_start
;
6657 prev_fkey_end
= fkey_end
;
6659 prev_keytran_map
= keytran_map
;
6660 prev_keytran_start
= keytran_start
;
6661 prev_keytran_end
= keytran_end
;
6663 /* If the sequence is unbound, see if we can hang a function key
6664 off the end of it. We only want to scan real keyboard input
6665 for function key sequences, so if mock_input says that we're
6666 re-reading old events, don't examine it. */
6667 if (first_binding
>= nmaps
6670 Lisp_Object fkey_next
;
6672 /* Continue scan from fkey_end until we find a bound suffix.
6673 If we fail, increment fkey_start
6674 and start fkey_end from there. */
6675 while (fkey_end
< t
)
6679 key
= keybuf
[fkey_end
++];
6680 /* Look up meta-characters by prefixing them
6681 with meta_prefix_char. I hate this. */
6682 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
6687 (access_keymap (fkey_map
, meta_prefix_char
, 1, 0), 0),
6689 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
6692 fkey_next
= fkey_map
;
6695 = get_keyelt (access_keymap (fkey_next
, key
, 1, 0), 0);
6697 #if 0 /* I didn't turn this on, because it might cause trouble
6698 for the mapping of return into C-m and tab into C-i. */
6699 /* Optionally don't map function keys into other things.
6700 This enables the user to redefine kp- keys easily. */
6701 if (SYMBOLP (key
) && !NILP (Vinhibit_function_key_mapping
))
6705 /* If the function key map gives a function, not an
6706 array, then call the function with no args and use
6707 its value instead. */
6708 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
6711 struct gcpro gcpro1
, gcpro2
, gcpro3
;
6715 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
6716 fkey_next
= call1 (fkey_next
, prompt
);
6718 /* If the function returned something invalid,
6719 barf--don't ignore it.
6720 (To ignore it safely, we would need to gcpro a bunch of
6721 other variables.) */
6722 if (! (VECTORP (fkey_next
) || STRINGP (fkey_next
)))
6723 error ("Function in key-translation-map returns invalid key sequence");
6726 function_key_possible
= ! NILP (fkey_next
);
6728 /* If keybuf[fkey_start..fkey_end] is bound in the
6729 function key map and it's a suffix of the current
6730 sequence (i.e. fkey_end == t), replace it with
6731 the binding and restart with fkey_start at the end. */
6732 if ((VECTORP (fkey_next
) || STRINGP (fkey_next
))
6735 int len
= XFASTINT (Flength (fkey_next
));
6737 t
= fkey_start
+ len
;
6739 error ("Key sequence too long");
6741 if (VECTORP (fkey_next
))
6742 bcopy (XVECTOR (fkey_next
)->contents
,
6743 keybuf
+ fkey_start
,
6744 (t
- fkey_start
) * sizeof (keybuf
[0]));
6745 else if (STRINGP (fkey_next
))
6749 for (i
= 0; i
< len
; i
++)
6750 XSETFASTINT (keybuf
[fkey_start
+ i
],
6751 XSTRING (fkey_next
)->data
[i
]);
6755 fkey_start
= fkey_end
= t
;
6756 fkey_map
= Vfunction_key_map
;
6758 /* Do pass the results through key-translation-map. */
6759 keytran_start
= keytran_end
= 0;
6760 keytran_map
= Vkey_translation_map
;
6762 goto replay_sequence
;
6765 fkey_map
= get_keymap_1 (fkey_next
, 0, 1);
6767 /* If we no longer have a bound suffix, try a new positions for
6769 if (NILP (fkey_map
))
6771 fkey_end
= ++fkey_start
;
6772 fkey_map
= Vfunction_key_map
;
6773 function_key_possible
= 0;
6778 /* Look for this sequence in key-translation-map. */
6780 Lisp_Object keytran_next
;
6782 /* Scan from keytran_end until we find a bound suffix. */
6783 while (keytran_end
< t
)
6787 key
= keybuf
[keytran_end
++];
6788 /* Look up meta-characters by prefixing them
6789 with meta_prefix_char. I hate this. */
6790 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
6795 (access_keymap (keytran_map
, meta_prefix_char
, 1, 0), 0),
6797 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
6800 keytran_next
= keytran_map
;
6803 = get_keyelt (access_keymap (keytran_next
, key
, 1, 0), 0);
6805 /* If the key translation map gives a function, not an
6806 array, then call the function with no args and use
6807 its value instead. */
6808 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
6809 && keytran_end
== t
)
6811 struct gcpro gcpro1
, gcpro2
, gcpro3
;
6815 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
6816 keytran_next
= call1 (keytran_next
, prompt
);
6818 /* If the function returned something invalid,
6819 barf--don't ignore it.
6820 (To ignore it safely, we would need to gcpro a bunch of
6821 other variables.) */
6822 if (! (VECTORP (keytran_next
) || STRINGP (keytran_next
)))
6823 error ("Function in key-translation-map returns invalid key sequence");
6826 key_translation_possible
= ! NILP (keytran_next
);
6828 /* If keybuf[keytran_start..keytran_end] is bound in the
6829 key translation map and it's a suffix of the current
6830 sequence (i.e. keytran_end == t), replace it with
6831 the binding and restart with keytran_start at the end. */
6832 if ((VECTORP (keytran_next
) || STRINGP (keytran_next
))
6833 && keytran_end
== t
)
6835 int len
= XFASTINT (Flength (keytran_next
));
6837 t
= keytran_start
+ len
;
6839 error ("Key sequence too long");
6841 if (VECTORP (keytran_next
))
6842 bcopy (XVECTOR (keytran_next
)->contents
,
6843 keybuf
+ keytran_start
,
6844 (t
- keytran_start
) * sizeof (keybuf
[0]));
6845 else if (STRINGP (keytran_next
))
6849 for (i
= 0; i
< len
; i
++)
6850 XSETFASTINT (keybuf
[keytran_start
+ i
],
6851 XSTRING (keytran_next
)->data
[i
]);
6855 keytran_start
= keytran_end
= t
;
6856 keytran_map
= Vkey_translation_map
;
6858 /* Don't pass the results of key-translation-map
6859 through function-key-map. */
6860 fkey_start
= fkey_end
= t
;
6861 fkey_map
= Vkey_translation_map
;
6863 goto replay_sequence
;
6866 keytran_map
= get_keymap_1 (keytran_next
, 0, 1);
6868 /* If we no longer have a bound suffix, try a new positions for
6870 if (NILP (keytran_map
))
6872 keytran_end
= ++keytran_start
;
6873 keytran_map
= Vkey_translation_map
;
6874 key_translation_possible
= 0;
6879 /* If KEY is not defined in any of the keymaps,
6880 and cannot be part of a function key or translation,
6881 and is an upper case letter
6882 use the corresponding lower-case letter instead. */
6883 if (first_binding
== nmaps
&& ! function_key_possible
6884 && ! key_translation_possible
6886 && ((((XINT (key
) & 0x3ffff)
6887 < XSTRING (current_buffer
->downcase_table
)->size
)
6888 && UPPERCASEP (XINT (key
) & 0x3ffff))
6889 || (XINT (key
) & shift_modifier
)))
6891 Lisp_Object new_key
;
6893 original_uppercase
= key
;
6894 original_uppercase_position
= t
- 1;
6896 if (XINT (key
) & shift_modifier
)
6897 XSETINT (new_key
, XINT (key
) & ~shift_modifier
);
6899 XSETINT (new_key
, (DOWNCASE (XINT (key
) & 0x3ffff)
6900 | (XINT (key
) & ~0x3ffff)));
6902 /* We have to do this unconditionally, regardless of whether
6903 the lower-case char is defined in the keymaps, because they
6904 might get translated through function-key-map. */
6905 keybuf
[t
- 1] = new_key
;
6908 fkey_map
= prev_fkey_map
;
6909 fkey_start
= prev_fkey_start
;
6910 fkey_end
= prev_fkey_end
;
6912 keytran_map
= prev_keytran_map
;
6913 keytran_start
= prev_keytran_start
;
6914 keytran_end
= prev_keytran_end
;
6916 goto replay_sequence
;
6918 /* If KEY is not defined in any of the keymaps,
6919 and cannot be part of a function key or translation,
6920 and is a shifted function key,
6921 use the corresponding unshifted function key instead. */
6922 if (first_binding
== nmaps
&& ! function_key_possible
6923 && ! key_translation_possible
6926 Lisp_Object breakdown
;
6929 breakdown
= parse_modifiers (key
);
6930 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
6931 if (modifiers
& shift_modifier
)
6933 Lisp_Object new_key
;
6935 original_uppercase
= key
;
6936 original_uppercase_position
= t
- 1;
6938 modifiers
&= ~shift_modifier
;
6939 new_key
= apply_modifiers (modifiers
,
6940 XCONS (breakdown
)->car
);
6942 keybuf
[t
- 1] = new_key
;
6945 fkey_map
= prev_fkey_map
;
6946 fkey_start
= prev_fkey_start
;
6947 fkey_end
= prev_fkey_end
;
6949 keytran_map
= prev_keytran_map
;
6950 keytran_start
= prev_keytran_start
;
6951 keytran_end
= prev_keytran_end
;
6953 goto replay_sequence
;
6959 read_key_sequence_cmd
= (first_binding
< nmaps
6960 ? defs
[first_binding
]
6963 unread_switch_frame
= delayed_switch_frame
;
6964 unbind_to (count
, Qnil
);
6966 /* Don't downcase the last character if the caller says don't.
6967 Don't downcase it if the result is undefined, either. */
6968 if ((dont_downcase_last
|| first_binding
>= nmaps
)
6969 && t
- 1 == original_uppercase_position
)
6970 keybuf
[t
- 1] = original_uppercase
;
6972 /* Occasionally we fabricate events, perhaps by expanding something
6973 according to function-key-map, or by adding a prefix symbol to a
6974 mouse click in the scroll bar or modeline. In this cases, return
6975 the entire generated key sequence, even if we hit an unbound
6976 prefix or a definition before the end. This means that you will
6977 be able to push back the event properly, and also means that
6978 read-key-sequence will always return a logical unit.
6981 for (; t
< mock_input
; t
++)
6983 if (echo_keystrokes
)
6984 echo_char (keybuf
[t
]);
6985 add_command_key (keybuf
[t
]);
6991 #if 0 /* This doc string is too long for some compilers.
6992 This commented-out definition serves for DOC. */
6993 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
6994 "Read a sequence of keystrokes and return as a string or vector.\n\
6995 The sequence is sufficient to specify a non-prefix command in the\n\
6996 current local and global maps.\n\
6998 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
6999 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
7000 as a continuation of the previous key.\n\
7002 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not\n\
7003 convert the last event to lower case. (Normally any upper case event\n\
7004 is converted to lower case if the original event is undefined and the lower\n\
7005 case equivalent is defined.) A non-nil value is appropriate for reading\n\
7006 a key sequence to be defined.\n\
7008 A C-g typed while in this function is treated like any other character,\n\
7009 and `quit-flag' is not set.\n\
7011 If the key sequence starts with a mouse click, then the sequence is read\n\
7012 using the keymaps of the buffer of the window clicked in, not the buffer\n\
7013 of the selected window as normal.\n\
7015 `read-key-sequence' drops unbound button-down events, since you normally\n\
7016 only care about the click or drag events which follow them. If a drag\n\
7017 or multi-click event is unbound, but the corresponding click event would\n\
7018 be bound, `read-key-sequence' turns the event into a click event at the\n\
7019 drag's starting position. This means that you don't have to distinguish\n\
7020 between click and drag, double, or triple events unless you want to.\n\
7022 `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\
7023 lines separating windows, and scroll bars with imaginary keys\n\
7024 `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\
7026 Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this\n\
7027 function will process a switch-frame event if the user switches frames\n\
7028 before typing anything. If the user switches frames in the middle of a\n\
7029 key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME\n\
7030 is nil, then the event will be put off until after the current key sequence.\n\
7032 `read-key-sequence' checks `function-key-map' for function key\n\
7033 sequences, where they wouldn't conflict with ordinary bindings. See\n\
7034 `function-key-map' for more details.")
7035 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
)
7038 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
7040 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
)
7041 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
7042 Lisp_Object can_return_switch_frame
;
7044 Lisp_Object keybuf
[30];
7046 struct gcpro gcpro1
, gcpro2
;
7049 CHECK_STRING (prompt
, 0);
7052 bzero (keybuf
, sizeof keybuf
);
7054 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
7056 if (NILP (continue_echo
))
7058 this_command_key_count
= 0;
7059 this_single_command_key_start
= 0;
7062 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
7063 prompt
, ! NILP (dont_downcase_last
),
7064 ! NILP (can_return_switch_frame
), 0);
7072 return make_event_array (i
, keybuf
);
7075 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 4, 0,
7076 "Execute CMD as an editor command.\n\
7077 CMD must be a symbol that satisfies the `commandp' predicate.\n\
7078 Optional second arg RECORD-FLAG non-nil\n\
7079 means unconditionally put this command in `command-history'.\n\
7080 Otherwise, that is done only if an arg is read using the minibuffer.\n\
7081 The argument KEYS specifies the value to use instead of (this-command-keys)\n\
7082 when reading the arguments; if it is nil, (this-command-keys) is used.\n\
7083 The argument SPECIAL, if non-nil, means that this command is executing\n\
7084 a special event, so ignore the prefix argument and don't clear it.")
7085 (cmd
, record_flag
, keys
, special
)
7086 Lisp_Object cmd
, record_flag
, keys
, special
;
7088 register Lisp_Object final
;
7089 register Lisp_Object tem
;
7090 Lisp_Object prefixarg
;
7091 struct backtrace backtrace
;
7092 extern int debug_on_next_call
;
7094 debug_on_next_call
= 0;
7098 prefixarg
= current_kboard
->Vprefix_arg
;
7099 Vcurrent_prefix_arg
= prefixarg
;
7100 current_kboard
->Vprefix_arg
= Qnil
;
7107 tem
= Fget (cmd
, Qdisabled
);
7108 if (!NILP (tem
) && !NILP (Vrun_hooks
))
7110 tem
= Fsymbol_value (Qdisabled_command_hook
);
7112 return call1 (Vrun_hooks
, Qdisabled_command_hook
);
7118 final
= Findirect_function (cmd
);
7120 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
7122 struct gcpro gcpro1
, gcpro2
;
7124 GCPRO2 (cmd
, prefixarg
);
7125 do_autoload (final
, cmd
);
7132 if (STRINGP (final
) || VECTORP (final
))
7134 /* If requested, place the macro in the command history. For
7135 other sorts of commands, call-interactively takes care of
7137 if (!NILP (record_flag
))
7139 = Fcons (Fcons (Qexecute_kbd_macro
,
7140 Fcons (final
, Fcons (prefixarg
, Qnil
))),
7143 return Fexecute_kbd_macro (final
, prefixarg
);
7145 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
7147 backtrace
.next
= backtrace_list
;
7148 backtrace_list
= &backtrace
;
7149 backtrace
.function
= &Qcall_interactively
;
7150 backtrace
.args
= &cmd
;
7151 backtrace
.nargs
= 1;
7152 backtrace
.evalargs
= 0;
7154 tem
= Fcall_interactively (cmd
, record_flag
, keys
);
7156 backtrace_list
= backtrace
.next
;
7162 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
7164 "Read function name, then read its arguments and call it.")
7166 Lisp_Object prefixarg
;
7168 Lisp_Object function
;
7170 Lisp_Object saved_keys
;
7171 Lisp_Object bindings
, value
;
7172 struct gcpro gcpro1
, gcpro2
;
7174 saved_keys
= Fvector (this_command_key_count
,
7175 XVECTOR (this_command_keys
)->contents
);
7177 GCPRO2 (saved_keys
, prefixarg
);
7179 if (EQ (prefixarg
, Qminus
))
7181 else if (CONSP (prefixarg
) && XINT (XCONS (prefixarg
)->car
) == 4)
7182 strcpy (buf
, "C-u ");
7183 else if (CONSP (prefixarg
) && INTEGERP (XCONS (prefixarg
)->car
))
7185 if (sizeof (int) == sizeof (EMACS_INT
))
7186 sprintf (buf
, "%d ", XINT (XCONS (prefixarg
)->car
));
7187 else if (sizeof (long) == sizeof (EMACS_INT
))
7188 sprintf (buf
, "%ld ", XINT (XCONS (prefixarg
)->car
));
7192 else if (INTEGERP (prefixarg
))
7194 if (sizeof (int) == sizeof (EMACS_INT
))
7195 sprintf (buf
, "%d ", XINT (prefixarg
));
7196 else if (sizeof (long) == sizeof (EMACS_INT
))
7197 sprintf (buf
, "%ld ", XINT (prefixarg
));
7202 /* This isn't strictly correct if execute-extended-command
7203 is bound to anything else. Perhaps it should use
7204 this_command_keys? */
7205 strcat (buf
, "M-x ");
7207 /* Prompt with buf, and then read a string, completing from and
7208 restricting to the set of all defined commands. Don't provide
7209 any initial input. Save the command read on the extended-command
7211 function
= Fcompleting_read (build_string (buf
),
7212 Vobarray
, Qcommandp
,
7213 Qt
, Qnil
, Qextended_command_history
, Qnil
,
7216 if (STRINGP (function
) && XSTRING (function
)->size
== 0)
7217 error ("No command name given");
7219 /* Set this_command_keys to the concatenation of saved_keys and
7220 function, followed by a RET. */
7222 struct Lisp_String
*str
;
7227 this_command_key_count
= 0;
7228 this_single_command_key_start
= 0;
7230 keys
= XVECTOR (saved_keys
)->contents
;
7231 for (i
= 0; i
< XVECTOR (saved_keys
)->size
; i
++)
7232 add_command_key (keys
[i
]);
7234 str
= XSTRING (function
);
7235 for (i
= 0; i
< str
->size
; i
++)
7237 XSETFASTINT (tem
, str
->data
[i
]);
7238 add_command_key (tem
);
7241 XSETFASTINT (tem
, '\015');
7242 add_command_key (tem
);
7247 function
= Fintern (function
, Qnil
);
7248 current_kboard
->Vprefix_arg
= prefixarg
;
7249 this_command
= function
;
7251 /* If enabled, show which key runs this command. */
7252 if (!NILP (Vsuggest_key_bindings
)
7253 && NILP (Vexecuting_macro
)
7254 && SYMBOLP (function
))
7255 bindings
= Fwhere_is_internal (function
, Voverriding_local_map
,
7261 GCPRO2 (bindings
, value
);
7262 value
= Fcommand_execute (function
, Qt
, Qnil
, Qnil
);
7264 /* If the command has a key binding, print it now. */
7265 if (!NILP (bindings
)
7266 && ! (VECTORP (bindings
) && EQ (Faref (bindings
, make_number (0)),
7269 /* But first wait, and skip the message if there is input. */
7270 if (!NILP (Fsit_for ((NUMBERP (Vsuggest_key_bindings
)
7271 ? Vsuggest_key_bindings
: make_number (2)),
7273 && ! CONSP (Vunread_command_events
))
7275 Lisp_Object binding
;
7277 char *oldmessage
= echo_area_glyphs
;
7278 int oldmessage_len
= echo_area_glyphs_length
;
7279 int oldmultibyte
= message_enable_multibyte
;
7281 binding
= Fkey_description (bindings
);
7284 = (char *) alloca (XSYMBOL (function
)->name
->size
7285 + XSTRING (binding
)->size
7287 sprintf (newmessage
, "You can run the command `%s' with %s",
7288 XSYMBOL (function
)->name
->data
,
7289 XSTRING (binding
)->data
);
7290 message1_nolog (newmessage
);
7291 if (!NILP (Fsit_for ((NUMBERP (Vsuggest_key_bindings
)
7292 ? Vsuggest_key_bindings
: make_number (2)),
7294 message2_nolog (oldmessage
, oldmessage_len
, oldmultibyte
);
7298 RETURN_UNGCPRO (value
);
7301 /* Find the set of keymaps now active.
7302 Store into *MAPS_P a vector holding the various maps
7303 and return the number of them. The vector was malloc'd
7304 and the caller should free it. */
7307 current_active_maps (maps_p
)
7308 Lisp_Object
**maps_p
;
7310 Lisp_Object
*tmaps
, *maps
;
7313 /* Should overriding-terminal-local-map and overriding-local-map apply? */
7314 if (!NILP (Voverriding_local_map_menu_flag
))
7316 /* Yes, use them (if non-nil) as well as the global map. */
7317 maps
= (Lisp_Object
*) xmalloc (3 * sizeof (maps
[0]));
7319 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
7320 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
7321 if (!NILP (Voverriding_local_map
))
7322 maps
[nmaps
++] = Voverriding_local_map
;
7326 /* No, so use major and minor mode keymaps. */
7327 nmaps
= current_minor_maps (NULL
, &tmaps
);
7328 maps
= (Lisp_Object
*) xmalloc ((nmaps
+ 2) * sizeof (maps
[0]));
7329 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
7330 #ifdef USE_TEXT_PROPERTIES
7331 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
7333 maps
[nmaps
++] = current_buffer
->keymap
;
7336 maps
[nmaps
++] = current_global_map
;
7342 /* Return nonzero if input events are pending. */
7344 detect_input_pending ()
7347 get_input_pending (&input_pending
, 0);
7349 return input_pending
;
7352 /* Return nonzero if input events are pending, and run any pending timers. */
7354 detect_input_pending_run_timers (do_display
)
7357 int old_timers_run
= timers_run
;
7360 get_input_pending (&input_pending
, 1);
7362 if (old_timers_run
!= timers_run
&& do_display
)
7363 redisplay_preserve_echo_area ();
7365 return input_pending
;
7368 /* This is called in some cases before a possible quit.
7369 It cases the next call to detect_input_pending to recompute input_pending.
7370 So calling this function unnecessarily can't do any harm. */
7373 clear_input_pending ()
7378 /* Return nonzero if there are pending requeued events.
7379 This isn't used yet. The hope is to make wait_reading_process_input
7380 call it, and return return if it runs Lisp code that unreads something.
7381 The problem is, kbd_buffer_get_event needs to be fixed to know what
7382 to do in that case. It isn't trivial. */
7384 requeued_events_pending_p ()
7386 return (!NILP (Vunread_command_events
) || unread_command_char
!= -1);
7390 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
7391 "T if command input is currently available with no waiting.\n\
7392 Actually, the value is nil only if we can be sure that no input is available.")
7395 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1)
7398 get_input_pending (&input_pending
, 1);
7399 return input_pending
> 0 ? Qt
: Qnil
;
7402 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
7403 "Return vector of last 100 events, not counting those from keyboard macros.")
7406 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
7409 if (total_keys
< NUM_RECENT_KEYS
)
7410 return Fvector (total_keys
, keys
);
7413 val
= Fvector (NUM_RECENT_KEYS
, keys
);
7414 bcopy (keys
+ recent_keys_index
,
7415 XVECTOR (val
)->contents
,
7416 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
7418 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
7419 recent_keys_index
* sizeof (Lisp_Object
));
7424 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
7425 "Return the key sequence that invoked this command.\n\
7426 The value is a string or a vector.")
7429 return make_event_array (this_command_key_count
,
7430 XVECTOR (this_command_keys
)->contents
);
7433 DEFUN ("this-single-command-keys", Fthis_single_command_keys
,
7434 Sthis_single_command_keys
, 0, 0, 0,
7435 "Return the key sequence that invoked this command.\n\
7436 Unlike `this-command-keys', this function's value\n\
7437 does not include prefix arguments.\n\
7438 The value is a string or a vector.")
7441 return make_event_array (this_command_key_count
7442 - this_single_command_key_start
,
7443 (XVECTOR (this_command_keys
)->contents
7444 + this_single_command_key_start
));
7447 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths
,
7448 Sreset_this_command_lengths
, 0, 0, 0,
7449 "Used for complicated reasons in `universal-argument-other-key'.\n\
7451 `universal-argument-other-key' rereads the event just typed.\n\
7452 It then gets translated through `function-key-map'.\n\
7453 The translated event gets included in the echo area and in\n\
7454 the value of `this-command-keys' in addition to the raw original event.\n\
7455 That is not right.\n\
7457 Calling this function directs the translated event to replace\n\
7458 the original event, so that only one version of the event actually\n\
7459 appears in the echo area and in the value of `this-command-keys.'.")
7462 before_command_restore_flag
= 1;
7463 before_command_key_count_1
= before_command_key_count
;
7464 before_command_echo_length_1
= before_command_echo_length
;
7467 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
7468 "Return the current depth in recursive edits.")
7472 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
7476 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
7477 "FOpen dribble file: ",
7478 "Start writing all keyboard characters to a dribble file called FILE.\n\
7479 If FILE is nil, close any open dribble file.")
7490 file
= Fexpand_file_name (file
, Qnil
);
7491 dribble
= fopen (XSTRING (file
)->data
, "w");
7493 report_file_error ("Opening dribble", Fcons (file
, Qnil
));
7498 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
7499 "Discard the contents of the terminal input buffer.\n\
7500 Also cancel any kbd macro being defined.")
7503 current_kboard
->defining_kbd_macro
= Qnil
;
7504 update_mode_lines
++;
7506 Vunread_command_events
= Qnil
;
7507 unread_command_char
= -1;
7509 discard_tty_input ();
7511 /* Without the cast, GCC complains that this assignment loses the
7512 volatile qualifier of kbd_store_ptr. Is there anything wrong
7514 kbd_fetch_ptr
= (struct input_event
*) kbd_store_ptr
;
7515 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
7521 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
7522 "Stop Emacs and return to superior process. You can resume later.\n\
7523 If `cannot-suspend' is non-nil, or if the system doesn't support job\n\
7524 control, run a subshell instead.\n\n\
7525 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
7526 to be read as terminal input by Emacs's parent, after suspension.\n\
7528 Before suspending, run the normal hook `suspend-hook'.\n\
7529 After resumption run the normal hook `suspend-resume-hook'.\n\
7531 Some operating systems cannot stop the Emacs process and resume it later.\n\
7532 On such systems, Emacs starts a subshell instead of suspending.")
7534 Lisp_Object stuffstring
;
7537 int count
= specpdl_ptr
- specpdl
;
7538 int old_height
, old_width
;
7540 struct gcpro gcpro1
, gcpro2
;
7542 if (!NILP (stuffstring
))
7543 CHECK_STRING (stuffstring
, 0);
7545 /* Run the functions in suspend-hook. */
7546 if (!NILP (Vrun_hooks
))
7547 call1 (Vrun_hooks
, intern ("suspend-hook"));
7549 GCPRO1 (stuffstring
);
7550 get_frame_size (&old_width
, &old_height
);
7552 /* sys_suspend can get an error if it tries to fork a subshell
7553 and the system resources aren't available for that. */
7554 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object
))) init_sys_modes
,
7556 stuff_buffered_input (stuffstring
);
7561 unbind_to (count
, Qnil
);
7563 /* Check if terminal/window size has changed.
7564 Note that this is not useful when we are running directly
7565 with a window system; but suspend should be disabled in that case. */
7566 get_frame_size (&width
, &height
);
7567 if (width
!= old_width
|| height
!= old_height
)
7568 change_frame_size (selected_frame
, height
, width
, 0, 0);
7570 /* Run suspend-resume-hook. */
7571 if (!NILP (Vrun_hooks
))
7572 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
7578 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
7579 Then in any case stuff anything Emacs has read ahead and not used. */
7582 stuff_buffered_input (stuffstring
)
7583 Lisp_Object stuffstring
;
7585 /* stuff_char works only in BSD, versions 4.2 and up. */
7588 register unsigned char *p
;
7590 if (STRINGP (stuffstring
))
7594 p
= XSTRING (stuffstring
)->data
;
7595 count
= XSTRING (stuffstring
)->size
;
7600 /* Anything we have read ahead, put back for the shell to read. */
7601 /* ?? What should this do when we have multiple keyboards??
7602 Should we ignore anything that was typed in at the "wrong" kboard? */
7603 for (; kbd_fetch_ptr
!= kbd_store_ptr
; kbd_fetch_ptr
++)
7605 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
7606 kbd_fetch_ptr
= kbd_buffer
;
7607 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
7608 stuff_char (kbd_fetch_ptr
->code
);
7609 kbd_fetch_ptr
->kind
= no_event
;
7610 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_fetch_ptr
7616 #endif /* BSD_SYSTEM and not BSD4_1 */
7619 set_waiting_for_input (time_to_clear
)
7620 EMACS_TIME
*time_to_clear
;
7622 input_available_clear_time
= time_to_clear
;
7624 /* Tell interrupt_signal to throw back to read_char, */
7625 waiting_for_input
= 1;
7627 /* If interrupt_signal was called before and buffered a C-g,
7628 make it run again now, to avoid timing error. */
7629 if (!NILP (Vquit_flag
))
7630 quit_throw_to_read_char ();
7634 clear_waiting_for_input ()
7636 /* Tell interrupt_signal not to throw back to read_char, */
7637 waiting_for_input
= 0;
7638 input_available_clear_time
= 0;
7641 /* This routine is called at interrupt level in response to C-G.
7642 If interrupt_input, this is the handler for SIGINT.
7643 Otherwise, it is called from kbd_buffer_store_event,
7644 in handling SIGIO or SIGTINT.
7646 If `waiting_for_input' is non zero, then unless `echoing' is nonzero,
7647 immediately throw back to read_char.
7649 Otherwise it sets the Lisp variable quit-flag not-nil.
7650 This causes eval to throw, when it gets a chance.
7651 If quit-flag is already non-nil, it stops the job right away. */
7654 interrupt_signal (signalnum
) /* If we don't have an argument, */
7655 int signalnum
; /* some compilers complain in signal calls. */
7658 /* Must preserve main program's value of errno. */
7659 int old_errno
= errno
;
7661 #if defined (USG) && !defined (POSIX_SIGNALS)
7662 if (!read_socket_hook
&& NILP (Vwindow_system
))
7664 /* USG systems forget handlers when they are used;
7665 must reestablish each time */
7666 signal (SIGINT
, interrupt_signal
);
7667 signal (SIGQUIT
, interrupt_signal
);
7673 if (!NILP (Vquit_flag
)
7674 && (FRAME_TERMCAP_P (selected_frame
) || FRAME_MSDOS_P (selected_frame
)))
7676 /* If SIGINT isn't blocked, don't let us be interrupted by
7677 another SIGINT, it might be harmful due to non-reentrancy
7678 in I/O functions. */
7679 sigblock (sigmask (SIGINT
));
7684 #ifdef SIGTSTP /* Support possible in later USG versions */
7686 * On systems which can suspend the current process and return to the original
7687 * shell, this command causes the user to end up back at the shell.
7688 * The "Auto-save" and "Abort" questions are not asked until
7689 * the user elects to return to emacs, at which point he can save the current
7690 * job and either dump core or continue.
7695 if (sys_suspend () == -1)
7697 printf ("Not running as a subprocess;\n");
7698 printf ("you can continue or abort.\n");
7701 /* Perhaps should really fork an inferior shell?
7702 But that would not provide any way to get back
7703 to the original shell, ever. */
7704 printf ("No support for stopping a process on this operating system;\n");
7705 printf ("you can continue or abort.\n");
7706 #endif /* not VMS */
7707 #endif /* not SIGTSTP */
7709 /* We must remain inside the screen area when the internal terminal
7710 is used. Note that [Enter] is not echoed by dos. */
7713 /* It doesn't work to autosave while GC is in progress;
7714 the code used for auto-saving doesn't cope with the mark bit. */
7715 if (!gc_in_progress
)
7717 printf ("Auto-save? (y or n) ");
7719 if (((c
= getchar ()) & ~040) == 'Y')
7721 Fdo_auto_save (Qt
, Qnil
);
7723 printf ("\r\nAuto-save done");
7724 #else /* not MSDOS */
7725 printf ("Auto-save done\n");
7726 #endif /* not MSDOS */
7728 while (c
!= '\n') c
= getchar ();
7732 /* During GC, it must be safe to reenable quitting again. */
7733 Vinhibit_quit
= Qnil
;
7736 #endif /* not MSDOS */
7737 printf ("Garbage collection in progress; cannot auto-save now\r\n");
7738 printf ("but will instead do a real quit after garbage collection ends\r\n");
7743 printf ("\r\nAbort? (y or n) ");
7744 #else /* not MSDOS */
7746 printf ("Abort (and enter debugger)? (y or n) ");
7748 printf ("Abort (and dump core)? (y or n) ");
7749 #endif /* not VMS */
7750 #endif /* not MSDOS */
7752 if (((c
= getchar ()) & ~040) == 'Y')
7754 while (c
!= '\n') c
= getchar ();
7756 printf ("\r\nContinuing...\r\n");
7757 #else /* not MSDOS */
7758 printf ("Continuing...\n");
7759 #endif /* not MSDOS */
7766 /* If executing a function that wants to be interrupted out of
7767 and the user has not deferred quitting by binding `inhibit-quit'
7768 then quit right away. */
7769 if (immediate_quit
&& NILP (Vinhibit_quit
))
7773 Fsignal (Qquit
, Qnil
);
7776 /* Else request quit when it's safe */
7780 if (waiting_for_input
&& !echoing
)
7781 quit_throw_to_read_char ();
7786 /* Handle a C-g by making read_char return C-g. */
7789 quit_throw_to_read_char ()
7791 quit_error_check ();
7793 /* Prevent another signal from doing this before we finish. */
7794 clear_waiting_for_input ();
7797 Vunread_command_events
= Qnil
;
7798 unread_command_char
= -1;
7800 #if 0 /* Currently, sit_for is called from read_char without turning
7801 off polling. And that can call set_waiting_for_input.
7802 It seems to be harmless. */
7803 #ifdef POLL_FOR_INPUT
7804 /* May be > 1 if in recursive minibuffer. */
7805 if (poll_suppress_count
== 0)
7809 if (FRAMEP (internal_last_event_frame
)
7810 && XFRAME (internal_last_event_frame
) != selected_frame
)
7811 do_switch_frame (make_lispy_switch_frame (internal_last_event_frame
),
7814 _longjmp (getcjmp
, 1);
7817 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
7818 "Set mode of reading keyboard input.\n\
7819 First arg INTERRUPT non-nil means use input interrupts;\n\
7820 nil means use CBREAK mode.\n\
7821 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
7822 (no effect except in CBREAK mode).\n\
7823 Third arg META t means accept 8-bit input (for a Meta key).\n\
7824 META nil means ignore the top bit, on the assumption it is parity.\n\
7825 Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\
7826 Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\
7827 See also `current-input-mode'.")
7828 (interrupt
, flow
, meta
, quit
)
7829 Lisp_Object interrupt
, flow
, meta
, quit
;
7832 && (!INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400))
7833 error ("set-input-mode: QUIT must be an ASCII character");
7835 #ifdef POLL_FOR_INPUT
7840 /* this causes startup screen to be restored and messes with the mouse */
7845 /* Note SIGIO has been undef'd if FIONREAD is missing. */
7846 if (read_socket_hook
)
7848 /* When using X, don't give the user a real choice,
7849 because we haven't implemented the mechanisms to support it. */
7850 #ifdef NO_SOCK_SIGIO
7851 interrupt_input
= 0;
7852 #else /* not NO_SOCK_SIGIO */
7853 interrupt_input
= 1;
7854 #endif /* NO_SOCK_SIGIO */
7857 interrupt_input
= !NILP (interrupt
);
7858 #else /* not SIGIO */
7859 interrupt_input
= 0;
7860 #endif /* not SIGIO */
7862 /* Our VMS input only works by interrupts, as of now. */
7864 interrupt_input
= 1;
7867 flow_control
= !NILP (flow
);
7870 else if (EQ (meta
, Qt
))
7875 /* Don't let this value be out of range. */
7876 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
7882 #ifdef POLL_FOR_INPUT
7883 poll_suppress_count
= 1;
7889 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
7890 "Return information about the way Emacs currently reads keyboard input.\n\
7891 The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
7892 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\
7893 nil, Emacs is using CBREAK mode.\n\
7894 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\
7895 terminal; this does not apply if Emacs uses interrupt-driven input.\n\
7896 META is t if accepting 8-bit input with 8th bit as Meta flag.\n\
7897 META nil means ignoring the top bit, on the assumption it is parity.\n\
7898 META is neither t nor nil if accepting 8-bit input and using\n\
7899 all 8 bits as the character code.\n\
7900 QUIT is the character Emacs currently uses to quit.\n\
7901 The elements of this list correspond to the arguments of\n\
7907 val
[0] = interrupt_input
? Qt
: Qnil
;
7908 val
[1] = flow_control
? Qt
: Qnil
;
7909 val
[2] = meta_key
== 2 ? make_number (0) : meta_key
== 1 ? Qt
: Qnil
;
7910 XSETFASTINT (val
[3], quit_char
);
7912 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
7917 * Set up a new kboard object with reasonable initial values.
7923 kb
->Voverriding_terminal_local_map
= Qnil
;
7924 kb
->Vlast_command
= Qnil
;
7925 kb
->Vprefix_arg
= Qnil
;
7926 kb
->kbd_queue
= Qnil
;
7927 kb
->kbd_queue_has_data
= 0;
7928 kb
->immediate_echo
= 0;
7929 kb
->echoptr
= kb
->echobuf
;
7930 kb
->echo_after_prompt
= -1;
7931 kb
->kbd_macro_buffer
= 0;
7932 kb
->kbd_macro_bufsize
= 0;
7933 kb
->defining_kbd_macro
= Qnil
;
7934 kb
->Vlast_kbd_macro
= Qnil
;
7935 kb
->reference_count
= 0;
7936 kb
->Vsystem_key_alist
= Qnil
;
7937 kb
->system_key_syms
= Qnil
;
7938 kb
->Vdefault_minibuffer_frame
= Qnil
;
7942 * Destroy the contents of a kboard object, but not the object itself.
7943 * We use this just before deleting it, or if we're going to initialize
7950 if (kb
->kbd_macro_buffer
)
7951 xfree (kb
->kbd_macro_buffer
);
7960 for (kbp
= &all_kboards
; *kbp
!= kb
; kbp
= &(*kbp
)->next_kboard
)
7963 *kbp
= kb
->next_kboard
;
7971 /* This is correct before outermost invocation of the editor loop */
7972 command_loop_level
= -1;
7974 quit_char
= Ctl ('g');
7975 Vunread_command_events
= Qnil
;
7976 unread_command_char
= -1;
7977 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
7979 recent_keys_index
= 0;
7980 kbd_fetch_ptr
= kbd_buffer
;
7981 kbd_store_ptr
= kbd_buffer
;
7982 kbd_buffer_frame_or_window
7983 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
7985 do_mouse_tracking
= Qnil
;
7989 /* This means that command_loop_1 won't try to select anything the first
7991 internal_last_event_frame
= Qnil
;
7992 Vlast_event_frame
= internal_last_event_frame
;
7995 current_kboard
= initial_kboard
;
7997 wipe_kboard (current_kboard
);
7998 init_kboard (current_kboard
);
8001 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
8003 kbd_buffer_frame_or_window
8004 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
8005 if (!noninteractive
&& !read_socket_hook
&& NILP (Vwindow_system
))
8007 signal (SIGINT
, interrupt_signal
);
8008 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
8009 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
8010 SIGQUIT and we can't tell which one it will give us. */
8011 signal (SIGQUIT
, interrupt_signal
);
8012 #endif /* HAVE_TERMIO */
8014 /* Note SIGIO has been undef'd if FIONREAD is missing. */
8016 if (!noninteractive
)
8017 signal (SIGIO
, input_available_signal
);
8020 /* Use interrupt input by default, if it works and noninterrupt input
8021 has deficiencies. */
8023 #ifdef INTERRUPT_INPUT
8024 interrupt_input
= 1;
8026 interrupt_input
= 0;
8029 /* Our VMS input only works by interrupts, as of now. */
8031 interrupt_input
= 1;
8037 if (keyboard_init_hook
)
8038 (*keyboard_init_hook
) ();
8040 #ifdef POLL_FOR_INPUT
8041 poll_suppress_count
= 1;
8046 /* This type's only use is in syms_of_keyboard, to initialize the
8047 event header symbols and put properties on them. */
8054 struct event_head head_table
[] = {
8055 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
8056 &Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
,
8057 &Qswitch_frame
, "switch-frame", &Qswitch_frame
,
8058 &Qdelete_frame
, "delete-frame", &Qdelete_frame
,
8059 &Qiconify_frame
, "iconify-frame", &Qiconify_frame
,
8060 &Qmake_frame_visible
, "make-frame-visible", &Qmake_frame_visible
,
8065 Qtimer_event_handler
= intern ("timer-event-handler");
8066 staticpro (&Qtimer_event_handler
);
8068 Qdisabled_command_hook
= intern ("disabled-command-hook");
8069 staticpro (&Qdisabled_command_hook
);
8071 Qself_insert_command
= intern ("self-insert-command");
8072 staticpro (&Qself_insert_command
);
8074 Qforward_char
= intern ("forward-char");
8075 staticpro (&Qforward_char
);
8077 Qbackward_char
= intern ("backward-char");
8078 staticpro (&Qbackward_char
);
8080 Qdisabled
= intern ("disabled");
8081 staticpro (&Qdisabled
);
8083 Qundefined
= intern ("undefined");
8084 staticpro (&Qundefined
);
8086 Qpre_command_hook
= intern ("pre-command-hook");
8087 staticpro (&Qpre_command_hook
);
8089 Qpost_command_hook
= intern ("post-command-hook");
8090 staticpro (&Qpost_command_hook
);
8092 Qpost_command_idle_hook
= intern ("post-command-idle-hook");
8093 staticpro (&Qpost_command_idle_hook
);
8095 Qdeferred_action_function
= intern ("deferred-action-function");
8096 staticpro (&Qdeferred_action_function
);
8098 Qcommand_hook_internal
= intern ("command-hook-internal");
8099 staticpro (&Qcommand_hook_internal
);
8101 Qfunction_key
= intern ("function-key");
8102 staticpro (&Qfunction_key
);
8103 Qmouse_click
= intern ("mouse-click");
8104 staticpro (&Qmouse_click
);
8106 Qmouse_wheel
= intern ("mouse-wheel");
8107 staticpro (&Qmouse_wheel
);
8110 Qmenu_enable
= intern ("menu-enable");
8111 staticpro (&Qmenu_enable
);
8113 Qmode_line
= intern ("mode-line");
8114 staticpro (&Qmode_line
);
8115 Qvertical_line
= intern ("vertical-line");
8116 staticpro (&Qvertical_line
);
8117 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
8118 staticpro (&Qvertical_scroll_bar
);
8119 Qmenu_bar
= intern ("menu-bar");
8120 staticpro (&Qmenu_bar
);
8122 Qabove_handle
= intern ("above-handle");
8123 staticpro (&Qabove_handle
);
8124 Qhandle
= intern ("handle");
8125 staticpro (&Qhandle
);
8126 Qbelow_handle
= intern ("below-handle");
8127 staticpro (&Qbelow_handle
);
8128 Qup
= intern ("up");
8130 Qdown
= intern ("down");
8133 Qevent_kind
= intern ("event-kind");
8134 staticpro (&Qevent_kind
);
8135 Qevent_symbol_elements
= intern ("event-symbol-elements");
8136 staticpro (&Qevent_symbol_elements
);
8137 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
8138 staticpro (&Qevent_symbol_element_mask
);
8139 Qmodifier_cache
= intern ("modifier-cache");
8140 staticpro (&Qmodifier_cache
);
8142 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
8143 staticpro (&Qrecompute_lucid_menubar
);
8144 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
8145 staticpro (&Qactivate_menubar_hook
);
8147 Qpolling_period
= intern ("polling-period");
8148 staticpro (&Qpolling_period
);
8151 struct event_head
*p
;
8153 for (p
= head_table
;
8154 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
8157 *p
->var
= intern (p
->name
);
8159 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
8160 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
8164 button_down_location
= Fmake_vector (make_number (NUM_MOUSE_BUTTONS
), Qnil
);
8165 staticpro (&button_down_location
);
8169 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
8171 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
8172 for (i
= 0; i
< len
; i
++)
8173 if (modifier_names
[i
])
8174 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
8175 staticpro (&modifier_symbols
);
8178 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
8179 staticpro (&recent_keys
);
8181 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
8182 staticpro (&this_command_keys
);
8184 Qextended_command_history
= intern ("extended-command-history");
8185 Fset (Qextended_command_history
, Qnil
);
8186 staticpro (&Qextended_command_history
);
8188 kbd_buffer_frame_or_window
8189 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
8190 staticpro (&kbd_buffer_frame_or_window
);
8192 accent_key_syms
= Qnil
;
8193 staticpro (&accent_key_syms
);
8195 func_key_syms
= Qnil
;
8196 staticpro (&func_key_syms
);
8199 staticpro (&mouse_syms
);
8202 mouse_wheel_syms
= Qnil
;
8203 staticpro (&mouse_wheel_syms
);
8206 unread_switch_frame
= Qnil
;
8207 staticpro (&unread_switch_frame
);
8209 internal_last_event_frame
= Qnil
;
8210 staticpro (&internal_last_event_frame
);
8212 read_key_sequence_cmd
= Qnil
;
8213 staticpro (&read_key_sequence_cmd
);
8215 defsubr (&Sevent_convert_list
);
8216 defsubr (&Sread_key_sequence
);
8217 defsubr (&Srecursive_edit
);
8219 defsubr (&Strack_mouse
);
8221 defsubr (&Sinput_pending_p
);
8222 defsubr (&Scommand_execute
);
8223 defsubr (&Srecent_keys
);
8224 defsubr (&Sthis_command_keys
);
8225 defsubr (&Sthis_single_command_keys
);
8226 defsubr (&Sreset_this_command_lengths
);
8227 defsubr (&Ssuspend_emacs
);
8228 defsubr (&Sabort_recursive_edit
);
8229 defsubr (&Sexit_recursive_edit
);
8230 defsubr (&Srecursion_depth
);
8231 defsubr (&Stop_level
);
8232 defsubr (&Sdiscard_input
);
8233 defsubr (&Sopen_dribble_file
);
8234 defsubr (&Sset_input_mode
);
8235 defsubr (&Scurrent_input_mode
);
8236 defsubr (&Sexecute_extended_command
);
8238 DEFVAR_LISP ("last-command-char", &last_command_char
,
8239 "Last input event that was part of a command.");
8241 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char
,
8242 "Last input event that was part of a command.");
8244 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
8245 "Last input event in a command, except for mouse menu events.\n\
8246 Mouse menus give back keys that don't look like mouse events;\n\
8247 this variable holds the actual mouse event that led to the menu,\n\
8248 so that you can determine whether the command was run by mouse or not.");
8250 DEFVAR_LISP ("last-input-char", &last_input_char
,
8251 "Last input event.");
8253 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char
,
8254 "Last input event.");
8256 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
8257 "List of objects to be read as next command input events.");
8259 DEFVAR_INT ("unread-command-char", &unread_command_char
,
8260 "If not -1, an object to be read as next command input event.");
8262 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
8263 "Meta-prefix character code. Meta-foo as command input\n\
8264 turns into this character followed by foo.");
8265 XSETINT (meta_prefix_char
, 033);
8267 DEFVAR_KBOARD ("last-command", Vlast_command
,
8268 "The last command executed. Normally a symbol with a function definition,\n\
8269 but can be whatever was found in the keymap, or whatever the variable\n\
8270 `this-command' was set to by that command.\n\
8272 The value `mode-exit' is special; it means that the previous command\n\
8273 read an event that told it to exit, and it did so and unread that event.\n\
8274 In other words, the present command is the event that made the previous\n\
8277 The value `kill-region' is special; it means that the previous command\n\
8278 was a kill command.");
8280 DEFVAR_LISP ("this-command", &this_command
,
8281 "The command now being executed.\n\
8282 The command can set this variable; whatever is put here\n\
8283 will be in `last-command' during the following command.");
8284 this_command
= Qnil
;
8286 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
8287 "*Number of keyboard input characters between auto-saves.\n\
8288 Zero means disable autosaving due to number of characters typed.");
8289 auto_save_interval
= 300;
8291 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
8292 "*Number of seconds idle time before auto-save.\n\
8293 Zero or nil means disable auto-saving due to idleness.\n\
8294 After auto-saving due to this many seconds of idle time,\n\
8295 Emacs also does a garbage collection if that seems to be warranted.");
8296 XSETFASTINT (Vauto_save_timeout
, 30);
8298 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes
,
8299 "*Nonzero means echo unfinished commands after this many seconds of pause.");
8300 echo_keystrokes
= 1;
8302 DEFVAR_INT ("polling-period", &polling_period
,
8303 "*Interval between polling for input during Lisp execution.\n\
8304 The reason for polling is to make C-g work to stop a running program.\n\
8305 Polling is needed only when using X windows and SIGIO does not work.\n\
8306 Polling is automatically disabled in all other cases.");
8309 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
8310 "*Maximum time between mouse clicks to make a double-click.\n\
8311 Measured in milliseconds. nil means disable double-click recognition;\n\
8312 t means double-clicks have no time limit and are detected\n\
8313 by position only.");
8314 Vdouble_click_time
= make_number (500);
8316 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
8317 "*Non-nil means inhibit local map menu bar menus.");
8318 inhibit_local_menu_bar_menus
= 0;
8320 DEFVAR_INT ("num-input-keys", &num_input_keys
,
8321 "Number of complete key sequences read as input so far.\n\
8322 This includes key sequences read from keyboard macros.\n\
8323 The number is effectively the number of interactive command invocations.");
8326 DEFVAR_INT ("num-nonmacro-input-events", &num_nonmacro_input_events
,
8327 "Number of input events read from the keyboard so far.\n\
8328 This does not include events generated by keyboard macros.");
8329 num_nonmacro_input_events
= 0;
8331 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
8332 "The frame in which the most recently read event occurred.\n\
8333 If the last event came from a keyboard macro, this is set to `macro'.");
8334 Vlast_event_frame
= Qnil
;
8336 /* This variable is set up in sysdep.c. */
8337 DEFVAR_LISP ("tty-erase-char", &Vtty_erase_char
,
8338 "The ERASE character as set by the user with stty.");
8340 DEFVAR_LISP ("help-char", &Vhelp_char
,
8341 "Character to recognize as meaning Help.\n\
8342 When it is read, do `(eval help-form)', and display result if it's a string.\n\
8343 If the value of `help-form' is nil, this char can be read normally.");
8344 XSETINT (Vhelp_char
, Ctl ('H'));
8346 DEFVAR_LISP ("help-event-list", &Vhelp_event_list
,
8347 "List of input events to recognize as meaning Help.\n\
8348 These work just like the value of `help-char' (see that).");
8349 Vhelp_event_list
= Qnil
;
8351 DEFVAR_LISP ("help-form", &Vhelp_form
,
8352 "Form to execute when character `help-char' is read.\n\
8353 If the form returns a string, that string is displayed.\n\
8354 If `help-form' is nil, the help char is not recognized.");
8357 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
8358 "Command to run when `help-char' character follows a prefix key.\n\
8359 This command is used only when there is no actual binding\n\
8360 for that character after that prefix key.");
8361 Vprefix_help_command
= Qnil
;
8363 DEFVAR_LISP ("top-level", &Vtop_level
,
8364 "Form to evaluate when Emacs starts up.\n\
8365 Useful to set before you dump a modified Emacs.");
8368 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
8369 "Translate table for keyboard input, or nil.\n\
8370 Each character is looked up in this string and the contents used instead.\n\
8371 The value may be a string, a vector, or a char-table.\n\
8372 If it is a string or vector of length N,\n\
8373 character codes N and up are untranslated.\n\
8374 In a vector or a char-table, an element which is nil means \"no translation\".");
8375 Vkeyboard_translate_table
= Qnil
;
8377 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
8378 "Non-nil means to always spawn a subshell instead of suspending,\n\
8379 even if the operating system has support for stopping a process.");
8382 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
8383 "Non-nil means prompt with menus when appropriate.\n\
8384 This is done when reading from a keymap that has a prompt string,\n\
8385 for elements that have prompt strings.\n\
8386 The menu is displayed on the screen\n\
8387 if X menus were enabled at configuration\n\
8388 time and the previous event was a mouse click prefix key.\n\
8389 Otherwise, menu prompting uses the echo area.");
8392 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
8393 "Character to see next line of menu prompt.\n\
8394 Type this character while in a menu prompt to rotate around the lines of it.");
8395 XSETINT (menu_prompt_more_char
, ' ');
8397 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
8398 "A mask of additional modifier keys to use with every keyboard character.\n\
8399 Emacs applies the modifiers of the character stored here to each keyboard\n\
8400 character it reads. For example, after evaluating the expression\n\
8401 (setq extra-keyboard-modifiers ?\\C-x)\n\
8402 all input characters will have the control modifier applied to them.\n\
8404 Note that the character ?\\C-@, equivalent to the integer zero, does\n\
8405 not count as a control character; rather, it counts as a character\n\
8406 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\
8407 cancels any modification.");
8408 extra_keyboard_modifiers
= 0;
8410 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
8411 "If an editing command sets this to t, deactivate the mark afterward.\n\
8412 The command loop sets this to nil before each command,\n\
8413 and tests the value when the command returns.\n\
8414 Buffer modification stores t in this variable.");
8415 Vdeactivate_mark
= Qnil
;
8417 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
8418 "Temporary storage of pre-command-hook or post-command-hook.");
8419 Vcommand_hook_internal
= Qnil
;
8421 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
8422 "Normal hook run before each command is executed.\n\
8423 Errors running the hook are caught and ignored.");
8424 Vpre_command_hook
= Qnil
;
8426 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
8427 "Normal hook run after each command is executed.\n\
8428 Errors running the hook are caught and ignored.");
8429 Vpost_command_hook
= Qnil
;
8431 DEFVAR_LISP ("post-command-idle-hook", &Vpost_command_idle_hook
,
8432 "Normal hook run after each command is executed, if idle.\n\
8433 Errors running the hook are caught and ignored.\n\
8434 This feature is obsolete; use idle timers instead. See `etc/NEWS'.");
8435 Vpost_command_idle_hook
= Qnil
;
8437 DEFVAR_INT ("post-command-idle-delay", &post_command_idle_delay
,
8438 "Delay time before running `post-command-idle-hook'.\n\
8439 This is measured in microseconds.");
8440 post_command_idle_delay
= 100000;
8443 DEFVAR_LISP ("echo-area-clear-hook", ...,
8444 "Normal hook run when clearing the echo area.");
8446 Qecho_area_clear_hook
= intern ("echo-area-clear-hook");
8447 XSYMBOL (Qecho_area_clear_hook
)->value
= Qnil
;
8449 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
8450 "t means menu bar, specified Lucid style, needs to be recomputed.");
8451 Vlucid_menu_bar_dirty_flag
= Qnil
;
8453 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
8454 "List of menu bar items to move to the end of the menu bar.\n\
8455 The elements of the list are event types that may have menu bar bindings.");
8456 Vmenu_bar_final_items
= Qnil
;
8458 DEFVAR_KBOARD ("overriding-terminal-local-map",
8459 Voverriding_terminal_local_map
,
8460 "Per-terminal keymap that overrides all other local keymaps.\n\
8461 If this variable is non-nil, it is used as a keymap instead of the\n\
8462 buffer's local map, and the minor mode keymaps and text property keymaps.\n\
8463 This variable is intended to let commands such as `universal-argumemnt'\n\
8464 set up a different keymap for reading the next command.");
8466 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
8467 "Keymap that overrides all other local keymaps.\n\
8468 If this variable is non-nil, it is used as a keymap instead of the\n\
8469 buffer's local map, and the minor mode keymaps and text property keymaps.");
8470 Voverriding_local_map
= Qnil
;
8472 DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag
,
8473 "Non-nil means `overriding-local-map' applies to the menu bar.\n\
8474 Otherwise, the menu bar continues to reflect the buffer's local map\n\
8475 and the minor mode maps regardless of `overriding-local-map'.");
8476 Voverriding_local_map_menu_flag
= Qnil
;
8478 DEFVAR_LISP ("special-event-map", &Vspecial_event_map
,
8479 "Keymap defining bindings for special events to execute at low level.");
8480 Vspecial_event_map
= Fcons (intern ("keymap"), Qnil
);
8482 DEFVAR_LISP ("track-mouse", &do_mouse_tracking
,
8483 "*Non-nil means generate motion events for mouse motion.");
8485 DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist
,
8486 "Alist of system-specific X windows key symbols.\n\
8487 Each element should have the form (N . SYMBOL) where N is the\n\
8488 numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\
8489 and SYMBOL is its name.");
8491 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
8492 "List of deferred actions to be performed at a later time.\n\
8493 The precise format isn't relevant here; we just check whether it is nil.");
8494 Vdeferred_action_list
= Qnil
;
8496 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
8497 "Function to call to handle deferred actions, after each command.\n\
8498 This function is called with no arguments after each command\n\
8499 whenever `deferred-action-list' is non-nil.");
8500 Vdeferred_action_function
= Qnil
;
8502 DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings
,
8503 "Non-nil means show the equivalent key-binding when M-x command has one.\n\
8504 The value can be a length of time to show the message for.\n\
8505 If the value is non-nil and not a number, we wait 2 seconds.");
8506 Vsuggest_key_bindings
= Qt
;
8508 DEFVAR_LISP ("timer-list", &Vtimer_list
,
8509 "List of active absolute time timers in order of increasing time");
8512 DEFVAR_LISP ("timer-idle-list", &Vtimer_idle_list
,
8513 "List of active idle-time timers in order of increasing time");
8514 Vtimer_idle_list
= Qnil
;
8519 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
8520 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
8521 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
8522 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
8523 initial_define_key (meta_map
, 'x', "execute-extended-command");
8525 initial_define_lispy_key (Vspecial_event_map
, "delete-frame",
8526 "handle-delete-frame");
8527 initial_define_lispy_key (Vspecial_event_map
, "iconify-frame",
8529 initial_define_lispy_key (Vspecial_event_map
, "make-frame-visible",