1 /* Keyboard and mouse input; editor command loop.
2 Copyright (C) 1985,86,87,88,89,93,94,95,96 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 struct backtrace
*backtrace_list
;
149 /* Nonzero means do menu prompting. */
150 static int menu_prompting
;
152 /* Character to see next line of menu prompt. */
153 static Lisp_Object menu_prompt_more_char
;
155 /* For longjmp to where kbd input is being done. */
156 static jmp_buf getcjmp
;
158 /* True while doing kbd input. */
159 int waiting_for_input
;
161 /* True while displaying for echoing. Delays C-g throwing. */
164 /* True means we can start echoing at the next input pause
165 even though there is something in the echo area. */
166 static char *ok_to_echo_at_next_pause
;
168 /* Nonzero means disregard local maps for the menu bar. */
169 static int inhibit_local_menu_bar_menus
;
171 /* Nonzero means C-g should cause immediate error-signal. */
174 /* Character to recognize as the help char. */
175 Lisp_Object Vhelp_char
;
177 /* List of other event types to recognize as meaning "help". */
178 Lisp_Object Vhelp_event_list
;
180 /* Form to execute when help char is typed. */
181 Lisp_Object Vhelp_form
;
183 /* Command to run when the help character follows a prefix key. */
184 Lisp_Object Vprefix_help_command
;
186 /* List of items that should move to the end of the menu bar. */
187 Lisp_Object Vmenu_bar_final_items
;
189 /* Non-nil means show the equivalent key-binding for
190 any M-x command that has one.
191 The value can be a length of time to show the message for.
192 If the value is non-nil and not a number, we wait 2 seconds. */
193 Lisp_Object Vsuggest_key_bindings
;
195 /* Character that causes a quit. Normally C-g.
197 If we are running on an ordinary terminal, this must be an ordinary
198 ASCII char, since we want to make it our interrupt character.
200 If we are not running on an ordinary terminal, it still needs to be
201 an ordinary ASCII char. This character needs to be recognized in
202 the input interrupt handler. At this point, the keystroke is
203 represented as a struct input_event, while the desired quit
204 character is specified as a lispy event. The mapping from struct
205 input_events to lispy events cannot run in an interrupt handler,
206 and the reverse mapping is difficult for anything but ASCII
209 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
213 extern Lisp_Object current_global_map
;
214 extern int minibuf_level
;
216 /* If non-nil, this is a map that overrides all other local maps. */
217 Lisp_Object Voverriding_local_map
;
219 /* If non-nil, Voverriding_local_map applies to the menu bar. */
220 Lisp_Object Voverriding_local_map_menu_flag
;
222 /* Keymap that defines special misc events that should
223 be processed immediately at a low level. */
224 Lisp_Object Vspecial_event_map
;
226 /* Current depth in recursive edits. */
227 int command_loop_level
;
229 /* Total number of times command_loop has read a key sequence. */
232 /* Last input character read as a command. */
233 Lisp_Object last_command_char
;
235 /* Last input character read as a command, not counting menus
236 reached by the mouse. */
237 Lisp_Object last_nonmenu_event
;
239 /* Last input character read for any purpose. */
240 Lisp_Object last_input_char
;
242 /* If not Qnil, a list of objects to be read as subsequent command input. */
243 Lisp_Object Vunread_command_events
;
245 /* If not -1, an event to be read as subsequent command input. */
246 int unread_command_char
;
248 /* If not Qnil, this is a switch-frame event which we decided to put
249 off until the end of a key sequence. This should be read as the
250 next command input, after any unread_command_events.
252 read_key_sequence uses this to delay switch-frame events until the
253 end of the key sequence; Fread_char uses it to put off switch-frame
254 events until a non-ASCII event is acceptable as input. */
255 Lisp_Object unread_switch_frame
;
257 /* A mask of extra modifier bits to put into every keyboard char. */
258 int extra_keyboard_modifiers
;
260 /* Char to use as prefix when a meta character is typed in.
261 This is bound on entry to minibuffer in case ESC is changed there. */
263 Lisp_Object meta_prefix_char
;
265 /* Last size recorded for a current buffer which is not a minibuffer. */
266 static int last_non_minibuf_size
;
268 /* Number of idle seconds before an auto-save and garbage collection. */
269 static Lisp_Object Vauto_save_timeout
;
271 /* Total number of times read_char has returned. */
274 /* Total number of times read_char has returned, outside of macros. */
275 int num_nonmacro_input_chars
;
277 /* Auto-save automatically when this many characters have been typed
278 since the last time. */
280 static int auto_save_interval
;
282 /* Value of num_nonmacro_input_chars as of last auto save. */
286 /* The command being executed by the command loop.
287 Commands may set this, and the value set will be copied into
288 current_kboard->Vlast_command instead of the actual command. */
289 Lisp_Object this_command
;
291 /* The value of point when the last command was executed. */
292 int last_point_position
;
294 /* The buffer that was current when the last command was started. */
295 Lisp_Object last_point_position_buffer
;
297 /* The frame in which the last input event occurred, or Qmacro if the
298 last event came from a macro. We use this to determine when to
299 generate switch-frame events. This may be cleared by functions
300 like Fselect_frame, to make sure that a switch-frame event is
301 generated by the next character. */
302 Lisp_Object internal_last_event_frame
;
304 /* A user-visible version of the above, intended to allow users to
305 figure out where the last event came from, if the event doesn't
306 carry that information itself (i.e. if it was a character). */
307 Lisp_Object Vlast_event_frame
;
309 /* The timestamp of the last input event we received from the X server.
310 X Windows wants this for selection ownership. */
311 unsigned long last_event_timestamp
;
313 Lisp_Object Qself_insert_command
;
314 Lisp_Object Qforward_char
;
315 Lisp_Object Qbackward_char
;
316 Lisp_Object Qundefined
;
318 /* read_key_sequence stores here the command definition of the
319 key sequence that it reads. */
320 Lisp_Object read_key_sequence_cmd
;
322 /* Form to evaluate (if non-nil) when Emacs is started. */
323 Lisp_Object Vtop_level
;
325 /* User-supplied string to translate input characters through. */
326 Lisp_Object Vkeyboard_translate_table
;
328 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
329 extern Lisp_Object Vfunction_key_map
;
331 /* Another keymap that maps key sequences into key sequences.
332 This one takes precedence over ordinary definitions. */
333 extern Lisp_Object Vkey_translation_map
;
335 /* Non-nil means deactivate the mark at end of this command. */
336 Lisp_Object Vdeactivate_mark
;
338 /* Menu bar specified in Lucid Emacs fashion. */
340 Lisp_Object Vlucid_menu_bar_dirty_flag
;
341 Lisp_Object Qrecompute_lucid_menubar
, Qactivate_menubar_hook
;
343 Lisp_Object Qecho_area_clear_hook
;
345 /* Hooks to run before and after each command. */
346 Lisp_Object Qpre_command_hook
, Vpre_command_hook
;
347 Lisp_Object Qpost_command_hook
, Vpost_command_hook
;
348 Lisp_Object Qcommand_hook_internal
, Vcommand_hook_internal
;
349 /* Hook run after a command if there's no more input soon. */
350 Lisp_Object Qpost_command_idle_hook
, Vpost_command_idle_hook
;
352 /* Delay time in microseconds before running post-command-idle-hook. */
353 int post_command_idle_delay
;
355 /* List of deferred actions to be performed at a later time.
356 The precise format isn't relevant here; we just check whether it is nil. */
357 Lisp_Object Vdeferred_action_list
;
359 /* Function to call to handle deferred actions, when there are any. */
360 Lisp_Object Vdeferred_action_function
;
361 Lisp_Object Qdeferred_action_function
;
363 /* File in which we write all commands we read. */
366 /* Nonzero if input is available. */
369 /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
370 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
374 extern char *pending_malloc_warning
;
376 /* Circular buffer for pre-read keyboard input. */
377 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
379 /* Vector to GCPRO the frames and windows mentioned in kbd_buffer.
381 The interrupt-level event handlers will never enqueue an event on a
382 frame which is not in Vframe_list, and once an event is dequeued,
383 internal_last_event_frame or the event itself points to the frame.
386 But while the event is sitting in the queue, it's completely
387 unprotected. Suppose the user types one command which will run for
388 a while and then delete a frame, and then types another event at
389 the frame that will be deleted, before the command gets around to
390 it. Suppose there are no references to this frame elsewhere in
391 Emacs, and a GC occurs before the second event is dequeued. Now we
392 have an event referring to a freed frame, which will crash Emacs
395 Similar things happen when an event on a scroll bar is enqueued; the
396 window may be deleted while the event is in the queue.
398 So, we use this vector to protect the frame_or_window field in the
399 event queue. That way, they'll be dequeued as dead frames or
400 windows, but still valid lisp objects.
402 If kbd_buffer[i].kind != no_event, then
403 (XVECTOR (kbd_buffer_frame_or_window)->contents[i]
404 == kbd_buffer[i].frame_or_window. */
405 static Lisp_Object kbd_buffer_frame_or_window
;
407 /* Pointer to next available character in kbd_buffer.
408 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
409 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the
410 next available char is in kbd_buffer[0]. */
411 static struct input_event
*kbd_fetch_ptr
;
413 /* Pointer to next place to store character in kbd_buffer. This
414 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
415 character should go in kbd_buffer[0]. */
416 static volatile struct input_event
*kbd_store_ptr
;
418 /* The above pair of variables forms a "queue empty" flag. When we
419 enqueue a non-hook event, we increment kbd_store_ptr. When we
420 dequeue a non-hook event, we increment kbd_fetch_ptr. We say that
421 there is input available iff the two pointers are not equal.
423 Why not just have a flag set and cleared by the enqueuing and
424 dequeuing functions? Such a flag could be screwed up by interrupts
425 at inopportune times. */
427 /* If this flag is non-nil, we check mouse_moved to see when the
428 mouse moves, and motion events will appear in the input stream.
429 Otherwise, mouse motion is ignored. */
430 static Lisp_Object do_mouse_tracking
;
432 /* Symbols to head events. */
433 Lisp_Object Qmouse_movement
;
434 Lisp_Object Qscroll_bar_movement
;
435 Lisp_Object Qswitch_frame
;
436 Lisp_Object Qdelete_frame
;
437 Lisp_Object Qiconify_frame
;
438 Lisp_Object Qmake_frame_visible
;
440 /* Symbols to denote kinds of events. */
441 Lisp_Object Qfunction_key
;
442 Lisp_Object Qmouse_click
;
443 Lisp_Object Qtimer_event
;
444 /* Lisp_Object Qmouse_movement; - also an event header */
446 /* Properties of event headers. */
447 Lisp_Object Qevent_kind
;
448 Lisp_Object Qevent_symbol_elements
;
450 Lisp_Object Qmenu_enable
;
452 /* An event header symbol HEAD may have a property named
453 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
454 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
455 mask of modifiers applied to it. If present, this is used to help
456 speed up parse_modifiers. */
457 Lisp_Object Qevent_symbol_element_mask
;
459 /* An unmodified event header BASE may have a property named
460 Qmodifier_cache, which is an alist mapping modifier masks onto
461 modified versions of BASE. If present, this helps speed up
463 Lisp_Object Qmodifier_cache
;
465 /* Symbols to use for parts of windows. */
466 Lisp_Object Qmode_line
;
467 Lisp_Object Qvertical_line
;
468 Lisp_Object Qvertical_scroll_bar
;
469 Lisp_Object Qmenu_bar
;
471 extern Lisp_Object Qmenu_enable
;
473 Lisp_Object
recursive_edit_unwind (), command_loop ();
474 Lisp_Object
Fthis_command_keys ();
475 Lisp_Object Qextended_command_history
;
476 EMACS_TIME
timer_check ();
478 extern char *x_get_keysym_name ();
480 static void record_menu_key ();
482 Lisp_Object Qpolling_period
;
484 /* List of absolute timers. Appears in order of next scheduled event. */
485 Lisp_Object Vtimer_list
;
487 /* List of idle time timers. Appears in order of next scheduled event. */
488 Lisp_Object Vtimer_idle_list
;
490 /* Incremented whenever a timer is run. */
493 extern Lisp_Object Vprint_level
, Vprint_length
;
495 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
497 EMACS_TIME
*input_available_clear_time
;
499 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
500 Default is 1 if INTERRUPT_INPUT is defined. */
503 /* Nonzero while interrupts are temporarily deferred during redisplay. */
504 int interrupts_deferred
;
506 /* Nonzero means use ^S/^Q for flow control. */
509 /* Allow m- file to inhibit use of FIONREAD. */
510 #ifdef BROKEN_FIONREAD
514 /* We are unable to use interrupts if FIONREAD is not available,
515 so flush SIGIO so we won't try. */
522 /* If we support a window system, turn on the code to poll periodically
523 to detect C-g. It isn't actually used when doing interrupt input. */
524 #ifdef HAVE_WINDOW_SYSTEM
525 #define POLL_FOR_INPUT
528 /* Global variable declarations. */
530 /* Function for init_keyboard to call with no args (if nonzero). */
531 void (*keyboard_init_hook
) ();
533 static int read_avail_input ();
534 static void get_input_pending ();
535 static int readable_events ();
536 static Lisp_Object
read_char_x_menu_prompt ();
537 static Lisp_Object
read_char_minibuf_menu_prompt ();
538 static Lisp_Object
make_lispy_event ();
540 static Lisp_Object
make_lispy_movement ();
542 static Lisp_Object
modify_event_symbol ();
543 static Lisp_Object
make_lispy_switch_frame ();
544 static int parse_solitary_modifier ();
546 /* > 0 if we are to echo keystrokes. */
547 static int echo_keystrokes
;
549 /* Nonzero means don't try to suspend even if the operating system seems
551 static int cannot_suspend
;
553 #define min(a,b) ((a)<(b)?(a):(b))
554 #define max(a,b) ((a)>(b)?(a):(b))
556 /* Install the string STR as the beginning of the string of echoing,
557 so that it serves as a prompt for the next character.
558 Also start echoing. */
563 int len
= strlen (str
);
565 if (len
> ECHOBUFSIZE
- 4)
566 len
= ECHOBUFSIZE
- 4;
567 bcopy (str
, current_kboard
->echobuf
, len
);
568 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
569 *current_kboard
->echoptr
= '\0';
571 current_kboard
->echo_after_prompt
= len
;
576 /* Add C to the echo string, if echoing is going on.
577 C can be a character, which is printed prettily ("M-C-x" and all that
578 jazz), or a symbol, whose name is printed. */
583 extern char *push_key_description ();
585 if (current_kboard
->immediate_echo
)
587 char *ptr
= current_kboard
->echoptr
;
589 if (ptr
!= current_kboard
->echobuf
)
592 /* If someone has passed us a composite event, use its head symbol. */
597 if (ptr
- current_kboard
->echobuf
> ECHOBUFSIZE
- 6)
600 ptr
= push_key_description (XINT (c
), ptr
);
602 else if (SYMBOLP (c
))
604 struct Lisp_String
*name
= XSYMBOL (c
)->name
;
605 if ((ptr
- current_kboard
->echobuf
) + name
->size
+ 4 > ECHOBUFSIZE
)
607 bcopy (name
->data
, ptr
, name
->size
);
611 if (current_kboard
->echoptr
== current_kboard
->echobuf
614 strcpy (ptr
, " (Type ? for further options)");
619 current_kboard
->echoptr
= ptr
;
625 /* Temporarily add a dash to the end of the echo string if it's not
626 empty, so that it serves as a mini-prompt for the very next character. */
630 if (!current_kboard
->immediate_echo
631 && current_kboard
->echoptr
== current_kboard
->echobuf
)
633 /* Do nothing if we just printed a prompt. */
634 if (current_kboard
->echo_after_prompt
635 == current_kboard
->echoptr
- current_kboard
->echobuf
)
637 /* Do nothing if not echoing at all. */
638 if (current_kboard
->echoptr
== 0)
641 /* Put a dash at the end of the buffer temporarily,
642 but make it go away when the next character is added. */
643 current_kboard
->echoptr
[0] = '-';
644 current_kboard
->echoptr
[1] = 0;
649 /* Display the current echo string, and begin echoing if not already
654 if (!current_kboard
->immediate_echo
)
657 current_kboard
->immediate_echo
= 1;
659 for (i
= 0; i
< this_command_key_count
; i
++)
662 c
= XVECTOR (this_command_keys
)->contents
[i
];
663 if (! (EVENT_HAS_PARAMETERS (c
)
664 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
671 message1_nolog (current_kboard
->echobuf
);
674 if (waiting_for_input
&& !NILP (Vquit_flag
))
675 quit_throw_to_read_char ();
678 /* Turn off echoing, for the start of a new command. */
682 current_kboard
->immediate_echo
= 0;
683 current_kboard
->echoptr
= current_kboard
->echobuf
;
684 current_kboard
->echo_after_prompt
= -1;
685 ok_to_echo_at_next_pause
= 0;
688 /* Return the length of the current echo string. */
693 return current_kboard
->echoptr
- current_kboard
->echobuf
;
696 /* Truncate the current echo message to its first LEN chars.
697 This and echo_char get used by read_key_sequence when the user
698 switches frames while entering a key sequence. */
704 current_kboard
->echobuf
[len
] = '\0';
705 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
706 truncate_echo_area (len
);
710 /* Functions for manipulating this_command_keys. */
712 add_command_key (key
)
715 int size
= XVECTOR (this_command_keys
)->size
;
717 /* If reset-this-command-length was called recently, obey it now.
718 See the doc string of that function for an explanation of why. */
719 if (before_command_restore_flag
)
721 this_command_key_count
= before_command_key_count_1
;
722 if (this_command_key_count
< this_single_command_key_start
)
723 this_single_command_key_start
= this_command_key_count
;
724 echo_truncate (before_command_echo_length_1
);
725 before_command_restore_flag
= 0;
728 if (this_command_key_count
>= size
)
730 Lisp_Object new_keys
;
732 new_keys
= Fmake_vector (make_number (size
* 2), Qnil
);
733 bcopy (XVECTOR (this_command_keys
)->contents
,
734 XVECTOR (new_keys
)->contents
,
735 size
* sizeof (Lisp_Object
));
737 this_command_keys
= new_keys
;
740 XVECTOR (this_command_keys
)->contents
[this_command_key_count
++] = key
;
746 int count
= specpdl_ptr
- specpdl
;
749 if (command_loop_level
> 0)
751 specbind (Qstandard_output
, Qt
);
752 specbind (Qstandard_input
, Qt
);
755 val
= command_loop ();
757 Fsignal (Qquit
, Qnil
);
758 /* Handle throw from read_minibuf when using minibuffer
759 while it's active but we're in another window. */
761 Fsignal (Qerror
, Fcons (val
, Qnil
));
763 return unbind_to (count
, Qnil
);
766 /* When an auto-save happens, record the "time", and don't do again soon. */
770 last_auto_save
= num_nonmacro_input_chars
;
773 /* Make an auto save happen as soon as possible at command level. */
775 force_auto_save_soon ()
777 last_auto_save
= - auto_save_interval
- 1;
779 record_asynch_buffer_change ();
782 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
783 "Invoke the editor command loop recursively.\n\
784 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
785 that tells this function to return.\n\
786 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
787 This function is called by the editor initialization to begin editing.")
790 int count
= specpdl_ptr
- specpdl
;
793 command_loop_level
++;
794 update_mode_lines
= 1;
796 record_unwind_protect (recursive_edit_unwind
,
798 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
802 return unbind_to (count
, Qnil
);
806 recursive_edit_unwind (buffer
)
810 Fset_buffer (buffer
);
812 command_loop_level
--;
813 update_mode_lines
= 1;
821 #if 0 /* Theory: if there's anything in Vunread_command_events,
822 it will right away be read by read_key_sequence,
823 and then if we do switch KBOARDS, it will go into the side
824 queue then. So we don't need to do anything special here -- rms. */
825 if (CONSP (Vunread_command_events
))
827 current_kboard
->kbd_queue
828 = nconc2 (Vunread_command_events
, current_kboard
->kbd_queue
);
829 current_kboard
->kbd_queue_has_data
= 1;
831 Vunread_command_events
= Qnil
;
837 /* Switch to the single-kboard state, making current_kboard
838 the only KBOARD from which further input is accepted. */
841 single_kboard_state ()
848 /* Maintain a stack of kboards, so other parts of Emacs
849 can switch temporarily to the kboard of a given frame
850 and then revert to the previous status. */
855 struct kboard_stack
*next
;
858 static struct kboard_stack
*kboard_stack
;
861 push_frame_kboard (f
)
865 struct kboard_stack
*p
866 = (struct kboard_stack
*) xmalloc (sizeof (struct kboard_stack
));
868 p
->next
= kboard_stack
;
869 p
->kboard
= current_kboard
;
872 current_kboard
= FRAME_KBOARD (f
);
880 struct kboard_stack
*p
= kboard_stack
;
881 current_kboard
= p
->kboard
;
882 kboard_stack
= p
->next
;
887 /* Handle errors that are not handled at inner levels
888 by printing an error message and returning to the editor command loop. */
894 Lisp_Object old_level
, old_length
;
897 if (!NILP (executing_macro
))
899 if (executing_macro_iterations
== 1)
900 sprintf (macroerror
, "After 1 kbd macro iteration: ");
902 sprintf (macroerror
, "After %d kbd macro iterations: ",
903 executing_macro_iterations
);
908 Vstandard_output
= Qt
;
909 Vstandard_input
= Qt
;
910 Vexecuting_macro
= Qnil
;
911 executing_macro
= Qnil
;
912 current_kboard
->Vprefix_arg
= Qnil
;
915 /* Avoid unquittable loop if data contains a circular list. */
916 old_level
= Vprint_level
;
917 old_length
= Vprint_length
;
918 XSETFASTINT (Vprint_level
, 10);
919 XSETFASTINT (Vprint_length
, 10);
920 cmd_error_internal (data
, macroerror
);
921 Vprint_level
= old_level
;
922 Vprint_length
= old_length
;
926 Vinhibit_quit
= Qnil
;
931 return make_number (0);
934 cmd_error_internal (data
, context
)
942 echo_area_glyphs
= 0;
944 /* If the window system or terminal frame hasn't been initialized
945 yet, or we're not interactive, it's best to dump this message out
946 to stderr and exit. */
947 if (! FRAME_MESSAGE_BUF (selected_frame
)
949 stream
= Qexternal_debugging_output
;
958 write_string_1 (context
, -1, stream
);
960 print_error_message (data
, stream
);
962 /* If the window system or terminal frame hasn't been initialized
963 yet, or we're in -batch mode, this error should cause Emacs to exit. */
964 if (! FRAME_MESSAGE_BUF (selected_frame
)
968 Fkill_emacs (make_number (-1));
972 Lisp_Object
command_loop_1 ();
973 Lisp_Object
command_loop_2 ();
974 Lisp_Object
top_level_1 ();
976 /* Entry to editor-command-loop.
977 This level has the catches for exiting/returning to editor command loop.
978 It returns nil to exit recursive edit, t to abort it. */
983 if (command_loop_level
> 0 || minibuf_level
> 0)
985 return internal_catch (Qexit
, command_loop_2
, Qnil
);
990 internal_catch (Qtop_level
, top_level_1
, Qnil
);
991 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
993 /* End of file in -batch run causes exit here. */
999 /* Here we catch errors in execution of commands within the
1000 editing loop, and reenter the editing loop.
1001 When there is an error, cmd_error runs and returns a non-nil
1002 value to us. A value of nil means that cmd_loop_1 itself
1003 returned due to end of file (or end of kbd macro). */
1008 register Lisp_Object val
;
1011 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
1012 while (!NILP (val
));
1020 return Feval (Vtop_level
);
1026 /* On entry to the outer level, run the startup file */
1027 if (!NILP (Vtop_level
))
1028 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
1029 else if (!NILP (Vpurify_flag
))
1030 message ("Bare impure Emacs (standard Lisp code not loaded)");
1032 message ("Bare Emacs (standard Lisp code not loaded)");
1036 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
1037 "Exit all recursive editing levels.")
1040 Fthrow (Qtop_level
, Qnil
);
1043 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
1044 "Exit from the innermost recursive edit or minibuffer.")
1047 if (command_loop_level
> 0 || minibuf_level
> 0)
1048 Fthrow (Qexit
, Qnil
);
1050 error ("No recursive edit is in progress");
1053 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
1054 "Abort the command that requested this recursive edit or minibuffer input.")
1057 if (command_loop_level
> 0 || minibuf_level
> 0)
1060 error ("No recursive edit is in progress");
1063 /* This is the actual command reading loop,
1064 sans error-handling encapsulation. */
1066 Lisp_Object
Fcommand_execute ();
1067 static int read_key_sequence ();
1068 void safe_run_hooks ();
1073 Lisp_Object cmd
, tem
;
1076 Lisp_Object keybuf
[30];
1081 struct buffer
*prev_buffer
;
1083 int was_locked
= single_kboard
;
1086 current_kboard
->Vprefix_arg
= Qnil
;
1087 Vdeactivate_mark
= Qnil
;
1088 waiting_for_input
= 0;
1093 this_command_key_count
= 0;
1094 this_single_command_key_start
= 0;
1096 /* Make sure this hook runs after commands that get errors and
1097 throw to top level. */
1098 /* Note that the value cell will never directly contain nil
1099 if the symbol is a local variable. */
1100 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1101 safe_run_hooks (Qpost_command_hook
);
1103 if (!NILP (Vdeferred_action_list
))
1104 call0 (Vdeferred_action_function
);
1106 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1108 if (NILP (Vunread_command_events
)
1109 && NILP (Vexecuting_macro
)
1110 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1)))
1111 safe_run_hooks (Qpost_command_idle_hook
);
1114 /* Do this after running Vpost_command_hook, for consistency. */
1115 current_kboard
->Vlast_command
= this_command
;
1119 /* Make sure the current window's buffer is selected. */
1120 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1121 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1123 /* Display any malloc warning that just came out. Use while because
1124 displaying one warning can cause another. */
1126 while (pending_malloc_warning
)
1127 display_malloc_warning ();
1131 Vdeactivate_mark
= Qnil
;
1133 /* If minibuffer on and echo area in use,
1134 wait 2 sec and redraw minibuffer. */
1136 if (minibuf_level
&& echo_area_glyphs
1137 && EQ (minibuf_window
, echo_area_window
))
1139 /* Bind inhibit-quit to t so that C-g gets read in
1140 rather than quitting back to the minibuffer. */
1141 int count
= specpdl_ptr
- specpdl
;
1142 specbind (Qinhibit_quit
, Qt
);
1144 Fsit_for (make_number (2), Qnil
, Qnil
);
1145 /* Clear the echo area. */
1147 safe_run_hooks (Qecho_area_clear_hook
);
1149 unbind_to (count
, Qnil
);
1151 /* If a C-g came in before, treat it as input now. */
1152 if (!NILP (Vquit_flag
))
1155 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1160 alloca (0); /* Cause a garbage collection now */
1161 /* Since we can free the most stuff here. */
1162 #endif /* C_ALLOCA */
1165 /* Select the frame that the last event came from. Usually,
1166 switch-frame events will take care of this, but if some lisp
1167 code swallows a switch-frame event, we'll fix things up here.
1168 Is this a good idea? */
1169 if (FRAMEP (internal_last_event_frame
)
1170 && XFRAME (internal_last_event_frame
) != selected_frame
)
1171 Fselect_frame (internal_last_event_frame
, Qnil
);
1173 /* If it has changed current-menubar from previous value,
1174 really recompute the menubar from the value. */
1175 if (! NILP (Vlucid_menu_bar_dirty_flag
)
1176 && !NILP (Ffboundp (Qrecompute_lucid_menubar
)))
1177 call0 (Qrecompute_lucid_menubar
);
1179 before_command_key_count
= this_command_key_count
;
1180 before_command_echo_length
= echo_length ();
1182 this_command
= Qnil
;
1184 /* Read next key sequence; i gets its length. */
1185 i
= read_key_sequence (keybuf
, sizeof keybuf
/ sizeof keybuf
[0],
1188 /* A filter may have run while we were reading the input. */
1189 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1190 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1194 /* Now we have read a key sequence of length I,
1195 or else I is 0 and we found end of file. */
1197 if (i
== 0) /* End of file -- happens only in */
1198 return Qnil
; /* a kbd macro, at the end. */
1199 /* -1 means read_key_sequence got a menu that was rejected.
1200 Just loop around and read another command. */
1204 this_command_key_count
= 0;
1205 this_single_command_key_start
= 0;
1209 last_command_char
= keybuf
[i
- 1];
1211 /* If the previous command tried to force a specific window-start,
1212 forget about that, in case this command moves point far away
1213 from that position. But also throw away beg_unchanged and
1214 end_unchanged information in that case, so that redisplay will
1215 update the whole window properly. */
1216 if (!NILP (XWINDOW (selected_window
)->force_start
))
1218 XWINDOW (selected_window
)->force_start
= Qnil
;
1219 beg_unchanged
= end_unchanged
= 0;
1222 cmd
= read_key_sequence_cmd
;
1223 if (!NILP (Vexecuting_macro
))
1225 if (!NILP (Vquit_flag
))
1227 Vexecuting_macro
= Qt
;
1228 QUIT
; /* Make some noise. */
1229 /* Will return since macro now empty. */
1233 /* Do redisplay processing after this command except in special
1234 cases identified below that set no_redisplay to 1.
1235 (actually, there's currently no way to prevent the redisplay,
1236 and no_redisplay is ignored.
1237 Perhaps someday we will really implement it.) */
1240 prev_buffer
= current_buffer
;
1241 prev_modiff
= MODIFF
;
1242 last_point_position
= PT
;
1243 XSETBUFFER (last_point_position_buffer
, prev_buffer
);
1245 /* Execute the command. */
1248 /* Note that the value cell will never directly contain nil
1249 if the symbol is a local variable. */
1250 if (!NILP (Vpre_command_hook
) && !NILP (Vrun_hooks
))
1251 safe_run_hooks (Qpre_command_hook
);
1253 if (NILP (this_command
))
1255 /* nil means key is undefined. */
1257 current_kboard
->defining_kbd_macro
= Qnil
;
1258 update_mode_lines
= 1;
1259 current_kboard
->Vprefix_arg
= Qnil
;
1263 if (NILP (current_kboard
->Vprefix_arg
) && ! no_direct
)
1265 /* Recognize some common commands in common situations and
1266 do them directly. */
1267 if (EQ (this_command
, Qforward_char
) && PT
< ZV
)
1269 struct Lisp_Char_Table
*dp
1270 = window_display_table (XWINDOW (selected_window
));
1271 lose
= FETCH_BYTE (PT
);
1272 SET_PT (forward_point (1));
1274 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1275 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1276 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1277 && (lose
>= 0x20 && lose
< 0x7f)))
1278 : (lose
>= 0x20 && lose
< 0x7f))
1279 /* To extract the case of continuation on
1280 wide-column characters. */
1281 && (WIDTH_BY_CHAR_HEAD (FETCH_BYTE (PT
)) == 1)
1282 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1284 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1286 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1288 && !windows_or_buffers_changed
1289 && EQ (current_buffer
->selective_display
, Qnil
)
1290 && !detect_input_pending ()
1291 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1292 && NILP (Vexecuting_macro
))
1293 no_redisplay
= direct_output_forward_char (1);
1296 else if (EQ (this_command
, Qbackward_char
) && PT
> BEGV
)
1298 struct Lisp_Char_Table
*dp
1299 = window_display_table (XWINDOW (selected_window
));
1300 SET_PT (forward_point (-1));
1301 lose
= FETCH_BYTE (PT
);
1303 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1304 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1305 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1306 && (lose
>= 0x20 && lose
< 0x7f)))
1307 : (lose
>= 0x20 && lose
< 0x7f))
1308 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1310 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1312 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1314 && !windows_or_buffers_changed
1315 && EQ (current_buffer
->selective_display
, Qnil
)
1316 && !detect_input_pending ()
1317 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1318 && NILP (Vexecuting_macro
))
1319 no_redisplay
= direct_output_forward_char (-1);
1322 else if (EQ (this_command
, Qself_insert_command
)
1323 /* Try this optimization only on ascii keystrokes. */
1324 && INTEGERP (last_command_char
))
1326 unsigned char c
= XINT (last_command_char
);
1329 if (NILP (Vexecuting_macro
)
1330 && !EQ (minibuf_window
, selected_window
))
1332 if (!nonundocount
|| nonundocount
>= 20)
1339 lose
= ((XFASTINT (XWINDOW (selected_window
)->last_modified
)
1341 || (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1343 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1345 || MODIFF
<= SAVE_MODIFF
1346 || windows_or_buffers_changed
1347 || !EQ (current_buffer
->selective_display
, Qnil
)
1348 || detect_input_pending ()
1349 || !NILP (XWINDOW (selected_window
)->column_number_displayed
)
1350 || !NILP (Vexecuting_macro
));
1351 value
= internal_self_insert (c
, 0);
1358 && (PT
== ZV
|| FETCH_BYTE (PT
) == '\n'))
1360 struct Lisp_Char_Table
*dp
1361 = window_display_table (XWINDOW (selected_window
));
1368 obj
= DISP_CHAR_VECTOR (dp
, lose
);
1371 /* Do it only for char codes
1372 that by default display as themselves. */
1373 if (lose
>= 0x20 && lose
<= 0x7e)
1374 no_redisplay
= direct_output_for_insert (lose
);
1376 else if (VECTORP (obj
)
1377 && XVECTOR (obj
)->size
== 1
1378 && (obj
= XVECTOR (obj
)->contents
[0],
1380 /* Insist face not specified in glyph. */
1381 && (XINT (obj
) & ((-1) << 8)) == 0)
1383 = direct_output_for_insert (XINT (obj
));
1387 if (lose
>= 0x20 && lose
<= 0x7e)
1388 no_redisplay
= direct_output_for_insert (lose
);
1395 /* Here for a command that isn't executed directly */
1398 if (NILP (current_kboard
->Vprefix_arg
))
1400 Fcommand_execute (this_command
, Qnil
, Qnil
, Qnil
);
1405 /* If there is a prefix argument,
1406 1) We don't want Vlast_command to be ``universal-argument''
1407 (that would be dumb), so don't set Vlast_command,
1408 2) we want to leave echoing on so that the prefix will be
1409 echoed as part of this key sequence, so don't call
1411 3) we want to leave this_command_key_count non-zero, so that
1412 read_char will realize that it is re-reading a character, and
1413 not echo it a second time.
1415 If the command didn't actually create a prefix arg,
1416 but is merely a frame event that is transparent to prefix args,
1417 then the above doesn't apply. */
1418 if (NILP (current_kboard
->Vprefix_arg
) || CONSP (last_command_char
))
1420 current_kboard
->Vlast_command
= this_command
;
1422 this_command_key_count
= 0;
1423 this_single_command_key_start
= 0;
1426 /* Note that the value cell will never directly contain nil
1427 if the symbol is a local variable. */
1428 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1429 safe_run_hooks (Qpost_command_hook
);
1431 if (!NILP (Vdeferred_action_list
))
1432 safe_run_hooks (Qdeferred_action_function
);
1434 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1436 if (NILP (Vunread_command_events
)
1437 && NILP (Vexecuting_macro
)
1438 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1)))
1439 safe_run_hooks (Qpost_command_idle_hook
);
1442 if (!NILP (current_buffer
->mark_active
) && !NILP (Vrun_hooks
))
1444 if (!NILP (Vdeactivate_mark
) && !NILP (Vtransient_mark_mode
))
1446 current_buffer
->mark_active
= Qnil
;
1447 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
1449 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
1450 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
1454 /* Install chars successfully executed in kbd macro. */
1456 if (!NILP (current_kboard
->defining_kbd_macro
)
1457 && NILP (current_kboard
->Vprefix_arg
))
1458 finalize_kbd_macro_chars ();
1462 any_kboard_state ();
1467 /* Subroutine for safe_run_hooks: run the hook HOOK. */
1470 safe_run_hooks_1 (hook
)
1473 return call1 (Vrun_hooks
, Vinhibit_quit
);
1476 /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */
1479 safe_run_hooks_error (data
)
1482 Fset (Vinhibit_quit
, Qnil
);
1485 /* If we get an error while running the hook, cause the hook variable
1486 to be nil. Also inhibit quits, so that C-g won't cause the hook
1487 to mysteriously evaporate. */
1490 safe_run_hooks (hook
)
1494 int count
= specpdl_ptr
- specpdl
;
1495 specbind (Qinhibit_quit
, hook
);
1497 internal_condition_case (safe_run_hooks_1
, Qt
, safe_run_hooks_error
);
1499 unbind_to (count
, Qnil
);
1502 /* Number of seconds between polling for input. */
1505 /* Nonzero means polling for input is temporarily suppressed. */
1506 int poll_suppress_count
;
1508 /* Nonzero if polling_for_input is actually being used. */
1509 int polling_for_input
;
1511 #ifdef POLL_FOR_INPUT
1513 /* Handle an alarm once each second and read pending input
1514 so as to handle a C-g if it comces in. */
1517 input_poll_signal (signalnum
) /* If we don't have an argument, */
1518 int signalnum
; /* some compilers complain in signal calls. */
1520 /* This causes the call to start_polling at the end
1521 to do its job. It also arranges for a quit or error
1522 from within read_avail_input to resume polling. */
1523 poll_suppress_count
++;
1524 if (interrupt_input_blocked
== 0
1525 && !waiting_for_input
)
1526 read_avail_input (0);
1527 /* Turn on the SIGALRM handler and request another alarm. */
1533 /* Begin signals to poll for input, if they are appropriate.
1534 This function is called unconditionally from various places. */
1538 #ifdef POLL_FOR_INPUT
1539 if (read_socket_hook
&& !interrupt_input
)
1541 poll_suppress_count
--;
1542 if (poll_suppress_count
== 0)
1544 signal (SIGALRM
, input_poll_signal
);
1545 polling_for_input
= 1;
1546 alarm (polling_period
);
1552 /* Nonzero if we are using polling to handle input asynchronously. */
1555 input_polling_used ()
1557 #ifdef POLL_FOR_INPUT
1558 return read_socket_hook
&& !interrupt_input
;
1564 /* Turn off polling. */
1568 #ifdef POLL_FOR_INPUT
1569 if (read_socket_hook
&& !interrupt_input
)
1571 if (poll_suppress_count
== 0)
1573 polling_for_input
= 0;
1576 poll_suppress_count
++;
1581 /* Set the value of poll_suppress_count to COUNT
1582 and start or stop polling accordingly. */
1585 set_poll_suppress_count (count
)
1588 #ifdef POLL_FOR_INPUT
1589 if (count
== 0 && poll_suppress_count
!= 0)
1591 poll_suppress_count
= 1;
1594 else if (count
!= 0 && poll_suppress_count
== 0)
1598 poll_suppress_count
= count
;
1602 /* Bind polling_period to a value at least N.
1603 But don't decrease it. */
1605 bind_polling_period (n
)
1608 #ifdef POLL_FOR_INPUT
1609 int new = polling_period
;
1615 specbind (Qpolling_period
, make_number (new));
1616 /* Start a new alarm with the new period. */
1621 /* Apply the control modifier to CHARACTER. */
1627 /* Save the upper bits here. */
1628 int upper
= c
& ~0177;
1632 /* Everything in the columns containing the upper-case letters
1633 denotes a control character. */
1634 if (c
>= 0100 && c
< 0140)
1638 /* Set the shift modifier for a control char
1639 made from a shifted letter. But only for letters! */
1640 if (oc
>= 'A' && oc
<= 'Z')
1641 c
|= shift_modifier
;
1644 /* The lower-case letters denote control characters too. */
1645 else if (c
>= 'a' && c
<= 'z')
1648 /* Include the bits for control and shift
1649 only if the basic ASCII code can't indicate them. */
1653 /* Replace the high bits. */
1654 c
|= (upper
& ~ctrl_modifier
);
1661 /* Input of single characters from keyboard */
1663 Lisp_Object
print_help ();
1664 static Lisp_Object
kbd_buffer_get_event ();
1665 static void record_char ();
1668 static jmp_buf wrong_kboard_jmpbuf
;
1671 /* read a character from the keyboard; call the redisplay if needed */
1672 /* commandflag 0 means do not do auto-saving, but do do redisplay.
1673 -1 means do not do redisplay, but do do autosaving.
1676 /* The arguments MAPS and NMAPS are for menu prompting.
1677 MAPS is an array of keymaps; NMAPS is the length of MAPS.
1679 PREV_EVENT is the previous input event, or nil if we are reading
1680 the first event of a key sequence.
1682 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
1683 if we used a mouse menu to read the input, or zero otherwise. If
1684 USED_MOUSE_MENU is null, we don't dereference it.
1686 Value is t if we showed a menu and the user rejected it. */
1689 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
)
1693 Lisp_Object prev_event
;
1694 int *used_mouse_menu
;
1696 register Lisp_Object c
;
1698 jmp_buf local_getcjmp
;
1700 int key_already_recorded
= 0;
1701 Lisp_Object tem
, save
;
1702 Lisp_Object also_record
;
1705 before_command_key_count
= this_command_key_count
;
1706 before_command_echo_length
= echo_length ();
1710 if (CONSP (Vunread_command_events
))
1712 c
= XCONS (Vunread_command_events
)->car
;
1713 Vunread_command_events
= XCONS (Vunread_command_events
)->cdr
;
1715 /* Undo what read_char_x_menu_prompt did when it unread
1716 additional keys returned by Fx_popup_menu. */
1718 && (SYMBOLP (XCONS (c
)->car
) || INTEGERP (XCONS (c
)->car
))
1719 && NILP (XCONS (c
)->cdr
))
1722 if (this_command_key_count
== 0)
1728 if (unread_command_char
!= -1)
1730 XSETINT (c
, unread_command_char
);
1731 unread_command_char
= -1;
1733 if (this_command_key_count
== 0)
1739 /* If there is no function key translated before
1740 reset-this-command-lengths takes effect, forget about it. */
1741 before_command_restore_flag
= 0;
1743 if (!NILP (Vexecuting_macro
))
1745 /* We set this to Qmacro; since that's not a frame, nobody will
1746 try to switch frames on us, and the selected window will
1749 Since this event came from a macro, it would be misleading to
1750 leave internal_last_event_frame set to wherever the last
1751 real event came from. Normally, a switch-frame event selects
1752 internal_last_event_frame after each command is read, but
1753 events read from a macro should never cause a new frame to be
1755 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
1757 /* Exit the macro if we are at the end.
1758 Also, some things replace the macro with t
1759 to force an early exit. */
1760 if (EQ (Vexecuting_macro
, Qt
)
1761 || executing_macro_index
>= XFASTINT (Flength (Vexecuting_macro
)))
1767 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
1768 if (STRINGP (Vexecuting_macro
)
1769 && (XINT (c
) & 0x80))
1770 XSETFASTINT (c
, CHAR_META
| (XINT (c
) & ~0x80));
1772 executing_macro_index
++;
1777 if (!NILP (unread_switch_frame
))
1779 c
= unread_switch_frame
;
1780 unread_switch_frame
= Qnil
;
1782 /* This event should make it into this_command_keys, and get echoed
1783 again, so we go to reread_first, rather than reread. */
1787 if (commandflag
>= 0 && !input_pending
1788 && !detect_input_pending_run_timers (0))
1791 /* Message turns off echoing unless more keystrokes turn it on again. */
1792 if (echo_area_glyphs
&& *echo_area_glyphs
1793 && echo_area_glyphs
!= current_kboard
->echobuf
1794 && ok_to_echo_at_next_pause
!= echo_area_glyphs
)
1797 /* If already echoing, continue. */
1800 /* Try reading a character via menu prompting in the minibuf.
1801 Try this before the sit-for, because the sit-for
1802 would do the wrong thing if we are supposed to do
1803 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
1804 after a mouse event so don't try a minibuf menu. */
1806 if (nmaps
> 0 && INTERACTIVE
1807 && !NILP (prev_event
) && ! EVENT_HAS_PARAMETERS (prev_event
)
1808 /* Don't bring up a menu if we already have another event. */
1809 && NILP (Vunread_command_events
)
1810 && unread_command_char
< 0
1811 && !detect_input_pending_run_timers (0))
1813 c
= read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
);
1816 key_already_recorded
= 1;
1821 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet.
1822 We will do that below, temporarily for short sections of code,
1823 when appropriate. local_getcjmp must be in effect
1824 around any call to sit_for or kbd_buffer_get_event;
1825 it *must not* be in effect when we call redisplay. */
1827 if (_setjmp (local_getcjmp
))
1829 XSETINT (c
, quit_char
);
1830 XSETFRAME (internal_last_event_frame
, selected_frame
);
1831 Vlast_event_frame
= internal_last_event_frame
;
1832 /* If we report the quit char as an event,
1833 don't do so more than once. */
1834 if (!NILP (Vinhibit_quit
))
1839 KBOARD
*kb
= FRAME_KBOARD (selected_frame
);
1840 if (kb
!= current_kboard
)
1842 Lisp_Object
*tailp
= &kb
->kbd_queue
;
1843 /* We shouldn't get here if we were in single-kboard mode! */
1846 while (CONSP (*tailp
))
1847 tailp
= &XCONS (*tailp
)->cdr
;
1850 *tailp
= Fcons (c
, Qnil
);
1851 kb
->kbd_queue_has_data
= 1;
1852 current_kboard
= kb
;
1853 longjmp (wrong_kboard_jmpbuf
, 1);
1860 timer_start_idle ();
1862 /* If in middle of key sequence and minibuffer not active,
1863 start echoing if enough time elapses. */
1865 if (minibuf_level
== 0 && !current_kboard
->immediate_echo
1866 && this_command_key_count
> 0
1868 && echo_keystrokes
> 0
1869 && (echo_area_glyphs
== 0 || *echo_area_glyphs
== 0
1870 || ok_to_echo_at_next_pause
== echo_area_glyphs
))
1874 /* After a mouse event, start echoing right away.
1875 This is because we are probably about to display a menu,
1876 and we don't want to delay before doing so. */
1877 if (EVENT_HAS_PARAMETERS (prev_event
))
1881 save_getcjmp (save_jump
);
1882 restore_getcjmp (local_getcjmp
);
1883 tem0
= sit_for (echo_keystrokes
, 0, 1, 1);
1884 restore_getcjmp (save_jump
);
1890 /* Maybe auto save due to number of keystrokes. */
1892 if (commandflag
!= 0
1893 && auto_save_interval
> 0
1894 && num_nonmacro_input_chars
- last_auto_save
> max (auto_save_interval
, 20)
1895 && !detect_input_pending_run_timers (0))
1897 Fdo_auto_save (Qnil
, Qnil
);
1898 /* Hooks can actually change some buffers in auto save. */
1902 /* Try reading using an X menu.
1903 This is never confused with reading using the minibuf
1904 because the recursive call of read_char in read_char_minibuf_menu_prompt
1905 does not pass on any keymaps. */
1907 if (nmaps
> 0 && INTERACTIVE
1908 && !NILP (prev_event
)
1909 && EVENT_HAS_PARAMETERS (prev_event
)
1910 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
)
1911 /* Don't bring up a menu if we already have another event. */
1912 && NILP (Vunread_command_events
)
1913 && unread_command_char
< 0)
1915 c
= read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
1917 /* Now that we have read an event, Emacs is not idle. */
1923 /* Maybe autosave and/or garbage collect due to idleness. */
1925 if (INTERACTIVE
&& NILP (c
))
1927 int delay_level
, buffer_size
;
1929 /* Slow down auto saves logarithmically in size of current buffer,
1930 and garbage collect while we're at it. */
1931 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
1932 last_non_minibuf_size
= Z
- BEG
;
1933 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
1935 while (buffer_size
> 64)
1936 delay_level
++, buffer_size
-= buffer_size
>> 2;
1937 if (delay_level
< 4) delay_level
= 4;
1938 /* delay_level is 4 for files under around 50k, 7 at 100k,
1939 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
1941 /* Auto save if enough time goes by without input. */
1942 if (commandflag
!= 0
1943 && num_nonmacro_input_chars
> last_auto_save
1944 && INTEGERP (Vauto_save_timeout
)
1945 && XINT (Vauto_save_timeout
) > 0)
1949 save_getcjmp (save_jump
);
1950 restore_getcjmp (local_getcjmp
);
1951 tem0
= sit_for (delay_level
* XFASTINT (Vauto_save_timeout
) / 4,
1953 restore_getcjmp (save_jump
);
1957 Fdo_auto_save (Qnil
, Qnil
);
1959 /* If we have auto-saved and there is still no input
1960 available, garbage collect if there has been enough
1961 consing going on to make it worthwhile. */
1962 if (!detect_input_pending_run_timers (0)
1963 && consing_since_gc
> gc_cons_threshold
/ 2)
1964 Fgarbage_collect ();
1971 /* Read something from current KBOARD's side queue, if possible. */
1975 if (current_kboard
->kbd_queue_has_data
)
1977 if (!CONSP (current_kboard
->kbd_queue
))
1979 c
= XCONS (current_kboard
->kbd_queue
)->car
;
1980 current_kboard
->kbd_queue
1981 = XCONS (current_kboard
->kbd_queue
)->cdr
;
1982 if (NILP (current_kboard
->kbd_queue
))
1983 current_kboard
->kbd_queue_has_data
= 0;
1984 input_pending
= readable_events (0);
1985 if (EVENT_HAS_PARAMETERS (c
)
1986 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qswitch_frame
))
1987 internal_last_event_frame
= XCONS (XCONS (c
)->cdr
)->car
;
1988 Vlast_event_frame
= internal_last_event_frame
;
1993 /* If current_kboard's side queue is empty check the other kboards.
1994 If one of them has data that we have not yet seen here,
1995 switch to it and process the data waiting for it.
1997 Note: if the events queued up for another kboard
1998 have already been seen here, and therefore are not a complete command,
1999 the kbd_queue_has_data field is 0, so we skip that kboard here.
2000 That's to avoid an infinite loop switching between kboards here. */
2001 if (NILP (c
) && !single_kboard
)
2004 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2005 if (kb
->kbd_queue_has_data
)
2007 current_kboard
= kb
;
2008 longjmp (wrong_kboard_jmpbuf
, 1);
2017 /* Finally, we read from the main queue,
2018 and if that gives us something we can't use yet, we put it on the
2019 appropriate side queue and try again. */
2025 /* Actually read a character, waiting if necessary. */
2026 save_getcjmp (save_jump
);
2027 restore_getcjmp (local_getcjmp
);
2028 c
= kbd_buffer_get_event (&kb
, used_mouse_menu
);
2029 restore_getcjmp (save_jump
);
2032 if (! NILP (c
) && (kb
!= current_kboard
))
2034 Lisp_Object
*tailp
= &kb
->kbd_queue
;
2035 while (CONSP (*tailp
))
2036 tailp
= &XCONS (*tailp
)->cdr
;
2039 *tailp
= Fcons (c
, Qnil
);
2040 kb
->kbd_queue_has_data
= 1;
2044 current_kboard
= kb
;
2045 longjmp (wrong_kboard_jmpbuf
, 1);
2050 /* Terminate Emacs in batch mode if at eof. */
2051 if (noninteractive
&& INTEGERP (c
) && XINT (c
) < 0)
2052 Fkill_emacs (make_number (1));
2056 /* Add in any extra modifiers, where appropriate. */
2057 if ((extra_keyboard_modifiers
& CHAR_CTL
)
2058 || ((extra_keyboard_modifiers
& 0177) < ' '
2059 && (extra_keyboard_modifiers
& 0177) != 0))
2060 XSETINT (c
, make_ctrl_char (XINT (c
)));
2062 /* Transfer any other modifier bits directly from
2063 extra_keyboard_modifiers to c. Ignore the actual character code
2064 in the low 16 bits of extra_keyboard_modifiers. */
2065 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
2070 /* Now that we have read an event, Emacs is not idle--
2071 unless the event was a timer event (not used now). */
2072 if (! (CONSP (c
) && EQ (XCONS (c
)->car
, Qtimer_event
)))
2079 if (commandflag
>= 0
2080 && !input_pending
&& !detect_input_pending_run_timers (0))
2088 /* Buffer switch events are only for internal wakeups
2089 so don't show them to the user. */
2093 if (key_already_recorded
)
2096 /* Process special events within read_char
2097 and loop around to read another event. */
2100 tem
= get_keyelt (access_keymap (get_keymap_1 (Vspecial_event_map
, 0, 0),
2106 int was_locked
= single_kboard
;
2108 last_input_char
= c
;
2109 Fcommand_execute (tem
, Qnil
, Fvector (1, &last_input_char
), Qt
);
2111 /* Resume allowing input from any kboard, if that was true before. */
2113 any_kboard_state ();
2118 /* Wipe the echo area. */
2119 if (echo_area_glyphs
)
2120 safe_run_hooks (Qecho_area_clear_hook
);
2121 echo_area_glyphs
= 0;
2123 /* Handle things that only apply to characters. */
2126 /* If kbd_buffer_get_event gave us an EOF, return that. */
2130 if (STRINGP (Vkeyboard_translate_table
)
2131 && XSTRING (Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
2132 XSETINT (c
, XSTRING (Vkeyboard_translate_table
)->data
[XFASTINT (c
)]);
2133 else if ((VECTORP (Vkeyboard_translate_table
)
2134 && XVECTOR (Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
2135 || (CHAR_TABLE_P (Vkeyboard_translate_table
)
2136 && CHAR_TABLE_ORDINARY_SLOTS
> (unsigned) XFASTINT (c
)))
2139 d
= Faref (Vkeyboard_translate_table
, c
);
2140 /* nil in keyboard-translate-table means no translation. */
2146 /* If this event is a mouse click in the menu bar,
2147 return just menu-bar for now. Modify the mouse click event
2148 so we won't do this twice, then queue it up. */
2149 if (EVENT_HAS_PARAMETERS (c
)
2150 && CONSP (XCONS (c
)->cdr
)
2151 && CONSP (EVENT_START (c
))
2152 && CONSP (XCONS (EVENT_START (c
))->cdr
))
2156 posn
= POSN_BUFFER_POSN (EVENT_START (c
));
2157 /* Handle menu-bar events:
2158 insert the dummy prefix event `menu-bar'. */
2159 if (EQ (posn
, Qmenu_bar
))
2161 /* Change menu-bar to (menu-bar) as the event "position". */
2162 POSN_BUFFER_POSN (EVENT_START (c
)) = Fcons (posn
, Qnil
);
2165 Vunread_command_events
= Fcons (c
, Vunread_command_events
);
2171 if (! NILP (also_record
))
2172 record_char (also_record
);
2176 before_command_key_count
= this_command_key_count
;
2177 before_command_echo_length
= echo_length ();
2179 /* Don't echo mouse motion events. */
2181 && ! (EVENT_HAS_PARAMETERS (c
)
2182 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
2185 if (! NILP (also_record
))
2186 echo_char (also_record
);
2187 /* Once we reread a character, echoing can happen
2188 the next time we pause to read a new one. */
2189 ok_to_echo_at_next_pause
= echo_area_glyphs
;
2192 /* Record this character as part of the current key. */
2193 add_command_key (c
);
2194 if (! NILP (also_record
))
2195 add_command_key (also_record
);
2197 /* Re-reading in the middle of a command */
2199 last_input_char
= c
;
2202 /* Process the help character specially if enabled */
2203 if (!NILP (Vhelp_form
) && help_char_p (c
))
2206 count
= specpdl_ptr
- specpdl
;
2208 record_unwind_protect (Fset_window_configuration
,
2209 Fcurrent_window_configuration (Qnil
));
2211 tem0
= Feval (Vhelp_form
);
2213 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
2217 c
= read_char (0, 0, 0, Qnil
, 0);
2218 while (BUFFERP (c
));
2219 /* Remove the help from the frame */
2220 unbind_to (count
, Qnil
);
2223 if (EQ (c
, make_number (040)))
2227 c
= read_char (0, 0, 0, Qnil
, 0);
2228 while (BUFFERP (c
));
2235 /* Record a key that came from a mouse menu.
2236 Record it for echoing, for this-command-keys, and so on. */
2242 /* Wipe the echo area. */
2243 echo_area_glyphs
= 0;
2247 before_command_key_count
= this_command_key_count
;
2248 before_command_echo_length
= echo_length ();
2250 /* Don't echo mouse motion events. */
2251 if (echo_keystrokes
)
2255 /* Once we reread a character, echoing can happen
2256 the next time we pause to read a new one. */
2257 ok_to_echo_at_next_pause
= 0;
2260 /* Record this character as part of the current key. */
2261 add_command_key (c
);
2263 /* Re-reading in the middle of a command */
2264 last_input_char
= c
;
2268 /* Return 1 if should recognize C as "the help character". */
2276 if (EQ (c
, Vhelp_char
))
2278 for (tail
= Vhelp_event_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
2279 if (EQ (c
, XCONS (tail
)->car
))
2284 /* Record the input event C in various ways. */
2291 XVECTOR (recent_keys
)->contents
[recent_keys_index
] = c
;
2292 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
2293 recent_keys_index
= 0;
2295 /* Write c to the dribble file. If c is a lispy event, write
2296 the event's symbol to the dribble file, in <brackets>. Bleaugh.
2297 If you, dear reader, have a better idea, you've got the source. :-) */
2302 if (XUINT (c
) < 0x100)
2303 putc (XINT (c
), dribble
);
2305 fprintf (dribble
, " 0x%x", (int) XUINT (c
));
2309 Lisp_Object dribblee
;
2311 /* If it's a structured event, take the event header. */
2312 dribblee
= EVENT_HEAD (c
);
2314 if (SYMBOLP (dribblee
))
2316 putc ('<', dribble
);
2317 fwrite (XSYMBOL (dribblee
)->name
->data
, sizeof (char),
2318 XSYMBOL (dribblee
)->name
->size
,
2320 putc ('>', dribble
);
2327 store_kbd_macro_char (c
);
2329 num_nonmacro_input_chars
++;
2336 struct buffer
*old
= current_buffer
;
2337 Fprinc (object
, Qnil
);
2338 set_buffer_internal (XBUFFER (Vstandard_output
));
2339 call0 (intern ("help-mode"));
2340 set_buffer_internal (old
);
2344 /* Copy out or in the info on where C-g should throw to.
2345 This is used when running Lisp code from within get_char,
2346 in case get_char is called recursively.
2347 See read_process_output. */
2352 bcopy (getcjmp
, temp
, sizeof getcjmp
);
2355 restore_getcjmp (temp
)
2358 bcopy (temp
, getcjmp
, sizeof getcjmp
);
2363 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
2364 of this function. */
2367 tracking_off (old_value
)
2368 Lisp_Object old_value
;
2370 do_mouse_tracking
= old_value
;
2371 if (NILP (old_value
))
2373 /* Redisplay may have been preempted because there was input
2374 available, and it assumes it will be called again after the
2375 input has been processed. If the only input available was
2376 the sort that we have just disabled, then we need to call
2378 if (!readable_events (1))
2380 redisplay_preserve_echo_area ();
2381 get_input_pending (&input_pending
, 1);
2386 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
2387 "Evaluate BODY with mouse movement events enabled.\n\
2388 Within a `track-mouse' form, mouse motion generates input events that\n\
2389 you can read with `read-event'.\n\
2390 Normally, mouse motion is ignored.")
2394 int count
= specpdl_ptr
- specpdl
;
2397 record_unwind_protect (tracking_off
, do_mouse_tracking
);
2399 do_mouse_tracking
= Qt
;
2401 val
= Fprogn (args
);
2402 return unbind_to (count
, val
);
2405 /* If mouse has moved on some frame, return one of those frames.
2406 Return 0 otherwise. */
2411 Lisp_Object tail
, frame
;
2413 FOR_EACH_FRAME (tail
, frame
)
2415 if (XFRAME (frame
)->mouse_moved
)
2416 return XFRAME (frame
);
2422 #endif /* HAVE_MOUSE */
2424 /* Low level keyboard/mouse input.
2425 kbd_buffer_store_event places events in kbd_buffer, and
2426 kbd_buffer_get_event retrieves them. */
2428 /* Return true iff there are any events in the queue that read-char
2429 would return. If this returns false, a read-char would block. */
2431 readable_events (do_timers_now
)
2435 timer_check (do_timers_now
);
2437 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2440 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2445 if (current_kboard
->kbd_queue_has_data
)
2451 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2452 if (kb
->kbd_queue_has_data
)
2458 /* Set this for debugging, to have a way to get out */
2463 event_to_kboard (event
)
2464 struct input_event
*event
;
2467 frame
= event
->frame_or_window
;
2469 frame
= XCONS (frame
)->car
;
2470 else if (WINDOWP (frame
))
2471 frame
= WINDOW_FRAME (XWINDOW (frame
));
2473 /* There are still some events that don't set this field.
2474 For now, just ignore the problem.
2475 Also ignore dead frames here. */
2476 if (!FRAMEP (frame
) || !FRAME_LIVE_P (XFRAME (frame
)))
2479 return FRAME_KBOARD (XFRAME (frame
));
2483 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
2486 kbd_buffer_store_event (event
)
2487 register struct input_event
*event
;
2489 if (event
->kind
== no_event
)
2492 if (event
->kind
== ascii_keystroke
)
2494 register int c
= event
->code
& 0377;
2496 if (event
->modifiers
& ctrl_modifier
)
2497 c
= make_ctrl_char (c
);
2499 c
|= (event
->modifiers
2500 & (meta_modifier
| alt_modifier
2501 | hyper_modifier
| super_modifier
));
2505 extern SIGTYPE
interrupt_signal ();
2508 struct input_event
*sp
;
2511 && (kb
= FRAME_KBOARD (XFRAME (event
->frame_or_window
)),
2512 kb
!= current_kboard
))
2515 = Fcons (make_lispy_switch_frame (event
->frame_or_window
),
2516 Fcons (make_number (c
), Qnil
));
2517 kb
->kbd_queue_has_data
= 1;
2518 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
2520 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
2523 if (event_to_kboard (sp
) == kb
)
2525 sp
->kind
= no_event
;
2526 sp
->frame_or_window
= Qnil
;
2533 /* If this results in a quit_char being returned to Emacs as
2534 input, set Vlast_event_frame properly. If this doesn't
2535 get returned to Emacs as an event, the next event read
2536 will set Vlast_event_frame again, so this is safe to do. */
2540 focus
= FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
2542 focus
= event
->frame_or_window
;
2543 internal_last_event_frame
= focus
;
2544 Vlast_event_frame
= focus
;
2547 last_event_timestamp
= event
->timestamp
;
2548 interrupt_signal ();
2552 if (c
&& c
== stop_character
)
2558 /* Don't insert two buffer_switch_event's in a row.
2559 Just ignore the second one. */
2560 else if (event
->kind
== buffer_switch_event
2561 && kbd_fetch_ptr
!= kbd_store_ptr
2562 && kbd_store_ptr
->kind
== buffer_switch_event
)
2565 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
2566 kbd_store_ptr
= kbd_buffer
;
2568 /* Don't let the very last slot in the buffer become full,
2569 since that would make the two pointers equal,
2570 and that is indistinguishable from an empty buffer.
2571 Discard the event if it would fill the last slot. */
2572 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
2574 volatile struct input_event
*sp
= kbd_store_ptr
;
2575 sp
->kind
= event
->kind
;
2576 if (event
->kind
== selection_request_event
)
2578 /* We must not use the ordinary copying code for this case,
2579 since `part' is an enum and copying it might not copy enough
2581 bcopy (event
, (char *) sp
, sizeof (*event
));
2585 sp
->code
= event
->code
;
2586 sp
->part
= event
->part
;
2587 sp
->frame_or_window
= event
->frame_or_window
;
2588 sp
->modifiers
= event
->modifiers
;
2591 sp
->timestamp
= event
->timestamp
;
2593 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_store_ptr
2595 = event
->frame_or_window
);
2601 /* Read one event from the event buffer, waiting if necessary.
2602 The value is a Lisp object representing the event.
2603 The value is nil for an event that should be ignored,
2604 or that was handled here.
2605 We always read and discard one event. */
2608 kbd_buffer_get_event (kbp
, used_mouse_menu
)
2610 int *used_mouse_menu
;
2614 EMACS_TIME next_timer_delay
;
2620 *kbp
= current_kboard
;
2624 /* Wait until there is input available. */
2627 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2630 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2634 /* If the quit flag is set, then read_char will return
2635 quit_char, so that counts as "available input." */
2636 if (!NILP (Vquit_flag
))
2637 quit_throw_to_read_char ();
2639 /* One way or another, wait until input is available; then, if
2640 interrupt handlers have not read it, read it now. */
2643 wait_for_kbd_input ();
2645 /* Note SIGIO has been undef'd if FIONREAD is missing. */
2649 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2652 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2656 Lisp_Object minus_one
;
2658 XSETINT (minus_one
, -1);
2659 wait_reading_process_input (0, 0, minus_one
, 1);
2661 if (!interrupt_input
&& kbd_fetch_ptr
== kbd_store_ptr
)
2662 /* Pass 1 for EXPECT since we just waited to have input. */
2663 read_avail_input (1);
2665 #endif /* not VMS */
2668 /* At this point, we know that there is a readable event available
2669 somewhere. If the event queue is empty, then there must be a
2670 mouse movement enabled and available. */
2671 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2673 struct input_event
*event
;
2675 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2679 last_event_timestamp
= event
->timestamp
;
2682 *kbp
= event_to_kboard (event
);
2684 *kbp
= current_kboard
; /* Better than returning null ptr? */
2686 *kbp
= &the_only_kboard
;
2691 /* These two kinds of events get special handling
2692 and don't actually appear to the command loop.
2693 We return nil for them. */
2694 if (event
->kind
== selection_request_event
)
2697 struct input_event copy
;
2699 /* Remove it from the buffer before processing it,
2700 since otherwise swallow_events will see it
2701 and process it again. */
2703 kbd_fetch_ptr
= event
+ 1;
2704 input_pending
= readable_events (0);
2705 x_handle_selection_request (©
);
2707 /* We're getting selection request events, but we don't have
2713 else if (event
->kind
== selection_clear_event
)
2716 struct input_event copy
;
2718 /* Remove it from the buffer before processing it. */
2720 kbd_fetch_ptr
= event
+ 1;
2721 input_pending
= readable_events (0);
2722 x_handle_selection_clear (©
);
2724 /* We're getting selection request events, but we don't have
2729 #if defined (HAVE_X11) || defined (HAVE_NTGUI)
2730 else if (event
->kind
== delete_window_event
)
2732 /* Make an event (delete-frame (FRAME)). */
2733 obj
= Fcons (event
->frame_or_window
, Qnil
);
2734 obj
= Fcons (Qdelete_frame
, Fcons (obj
, Qnil
));
2735 kbd_fetch_ptr
= event
+ 1;
2737 else if (event
->kind
== iconify_event
)
2739 /* Make an event (iconify-frame (FRAME)). */
2740 obj
= Fcons (event
->frame_or_window
, Qnil
);
2741 obj
= Fcons (Qiconify_frame
, Fcons (obj
, Qnil
));
2742 kbd_fetch_ptr
= event
+ 1;
2744 else if (event
->kind
== deiconify_event
)
2746 /* Make an event (make-frame-visible (FRAME)). */
2747 obj
= Fcons (event
->frame_or_window
, Qnil
);
2748 obj
= Fcons (Qmake_frame_visible
, Fcons (obj
, Qnil
));
2749 kbd_fetch_ptr
= event
+ 1;
2752 else if (event
->kind
== buffer_switch_event
)
2754 /* The value doesn't matter here; only the type is tested. */
2755 XSETBUFFER (obj
, current_buffer
);
2756 kbd_fetch_ptr
= event
+ 1;
2758 #ifdef USE_X_TOOLKIT
2759 else if (event
->kind
== menu_bar_activate_event
)
2761 kbd_fetch_ptr
= event
+ 1;
2762 input_pending
= readable_events (0);
2763 if (FRAME_LIVE_P (XFRAME (event
->frame_or_window
)))
2764 x_activate_menubar (XFRAME (event
->frame_or_window
));
2767 /* Just discard these, by returning nil.
2768 With MULTI_KBOARD, these events are used as placeholders
2769 when we need to randomly delete events from the queue.
2770 (They shouldn't otherwise be found in the buffer,
2771 but on some machines it appears they do show up
2772 even without MULTI_KBOARD.) */
2773 else if (event
->kind
== no_event
)
2774 kbd_fetch_ptr
= event
+ 1;
2776 /* If this event is on a different frame, return a switch-frame this
2777 time, and leave the event in the queue for next time. */
2783 frame
= event
->frame_or_window
;
2785 frame
= XCONS (frame
)->car
;
2786 else if (WINDOWP (frame
))
2787 frame
= WINDOW_FRAME (XWINDOW (frame
));
2789 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
2793 if (! EQ (frame
, internal_last_event_frame
)
2794 && XFRAME (frame
) != selected_frame
)
2795 obj
= make_lispy_switch_frame (frame
);
2796 internal_last_event_frame
= frame
;
2798 /* If we didn't decide to make a switch-frame event, go ahead
2799 and build a real event from the queue entry. */
2803 obj
= make_lispy_event (event
);
2804 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
2805 /* If this was a menu selection, then set the flag to inhibit
2806 writing to last_nonmenu_event. Don't do this if the event
2807 we're returning is (menu-bar), though; that indicates the
2808 beginning of the menu sequence, and we might as well leave
2809 that as the `event with parameters' for this selection. */
2810 if (event
->kind
== menu_bar_event
2811 && !(CONSP (obj
) && EQ (XCONS (obj
)->car
, Qmenu_bar
))
2813 *used_mouse_menu
= 1;
2816 /* Wipe out this event, to catch bugs. */
2817 event
->kind
= no_event
;
2818 XVECTOR (kbd_buffer_frame_or_window
)->contents
[event
- kbd_buffer
] = Qnil
;
2820 kbd_fetch_ptr
= event
+ 1;
2825 /* Try generating a mouse motion event. */
2826 else if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2828 FRAME_PTR f
= some_mouse_moved ();
2829 Lisp_Object bar_window
;
2830 enum scroll_bar_part part
;
2834 *kbp
= current_kboard
;
2835 /* Note that this uses F to determine which display to look at.
2836 If there is no valid info, it does not store anything
2837 so x remains nil. */
2839 (*mouse_position_hook
) (&f
, 0, &bar_window
, &part
, &x
, &y
, &time
);
2843 /* Decide if we should generate a switch-frame event. Don't
2844 generate switch-frame events for motion outside of all Emacs
2850 frame
= FRAME_FOCUS_FRAME (f
);
2852 XSETFRAME (frame
, f
);
2854 if (! EQ (frame
, internal_last_event_frame
)
2855 && XFRAME (frame
) != selected_frame
)
2856 obj
= make_lispy_switch_frame (frame
);
2857 internal_last_event_frame
= frame
;
2860 /* If we didn't decide to make a switch-frame event, go ahead and
2861 return a mouse-motion event. */
2862 if (!NILP (x
) && NILP (obj
))
2863 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
2865 #endif /* HAVE_MOUSE */
2867 /* We were promised by the above while loop that there was
2868 something for us to read! */
2871 input_pending
= readable_events (0);
2873 Vlast_event_frame
= internal_last_event_frame
;
2878 /* Process any events that are not user-visible,
2879 then return, without reading any user-visible events. */
2882 swallow_events (do_display
)
2887 while (kbd_fetch_ptr
!= kbd_store_ptr
)
2889 struct input_event
*event
;
2891 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2895 last_event_timestamp
= event
->timestamp
;
2897 /* These two kinds of events get special handling
2898 and don't actually appear to the command loop. */
2899 if (event
->kind
== selection_request_event
)
2902 struct input_event copy
;
2904 /* Remove it from the buffer before processing it,
2905 since otherwise swallow_events called recursively could see it
2906 and process it again. */
2908 kbd_fetch_ptr
= event
+ 1;
2909 input_pending
= readable_events (0);
2910 x_handle_selection_request (©
);
2912 /* We're getting selection request events, but we don't have
2918 else if (event
->kind
== selection_clear_event
)
2921 struct input_event copy
;
2923 /* Remove it from the buffer before processing it, */
2926 kbd_fetch_ptr
= event
+ 1;
2927 input_pending
= readable_events (0);
2928 x_handle_selection_clear (©
);
2930 /* We're getting selection request events, but we don't have
2935 /* Note that timer_event is currently never used. */
2936 else if (event
->kind
== timer_event
)
2938 Lisp_Object tem
, lisp_event
;
2939 int was_locked
= single_kboard
;
2941 tem
= get_keymap_1 (Vspecial_event_map
, 0, 0);
2942 tem
= get_keyelt (access_keymap (tem
, Qtimer_event
, 0, 0),
2944 lisp_event
= Fcons (Qtimer_event
,
2945 Fcons (Fcdr (event
->frame_or_window
), Qnil
));
2946 kbd_fetch_ptr
= event
+ 1;
2947 if (kbd_fetch_ptr
== kbd_store_ptr
)
2949 Fcommand_execute (tem
, Qnil
, Fvector (1, &lisp_event
), Qt
);
2952 redisplay_preserve_echo_area ();
2954 /* Resume allowing input from any kboard, if that was true before. */
2956 any_kboard_state ();
2962 old_timers_run
= timers_run
;
2963 get_input_pending (&input_pending
, 1);
2965 if (timers_run
!= old_timers_run
&& do_display
)
2966 redisplay_preserve_echo_area ();
2969 static EMACS_TIME timer_idleness_start_time
;
2971 /* Record the start of when Emacs is idle,
2972 for the sake of running idle-time timers. */
2978 /* If we are already in the idle state, do nothing. */
2979 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
2982 EMACS_GET_TIME (timer_idleness_start_time
);
2984 /* Mark all idle-time timers as once again candidates for running. */
2985 for (timers
= Vtimer_idle_list
; CONSP (timers
); timers
= XCONS (timers
)->cdr
)
2989 timer
= XCONS (timers
)->car
;
2991 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
2993 XVECTOR (timer
)->contents
[0] = Qnil
;
2997 /* Record that Emacs is no longer idle, so stop running idle-time timers. */
3001 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
3004 /* This is only for debugging. */
3005 struct input_event last_timer_event
;
3007 /* Check whether a timer has fired. To prevent larger problems we simply
3008 disregard elements that are not proper timers. Do not make a circular
3009 timer list for the time being.
3011 Returns the number of seconds to wait until the next timer fires. If a
3012 timer is triggering now, return zero seconds.
3013 If no timer is active, return -1 seconds.
3015 If a timer is ripe, we run it, with quitting turned off.
3017 DO_IT_NOW is now ignored. It used to mean that we should
3018 run the timer directly instead of queueing a timer-event.
3019 Now we always run timers directly. */
3022 timer_check (do_it_now
)
3025 EMACS_TIME nexttime
;
3026 EMACS_TIME now
, idleness_now
;
3027 Lisp_Object timers
, idle_timers
, chosen_timer
;
3028 /* Nonzero if we generate some events. */
3029 int events_generated
= 0;
3030 struct gcpro gcpro1
, gcpro2
, gcpro3
;
3032 EMACS_SET_SECS (nexttime
, -1);
3033 EMACS_SET_USECS (nexttime
, -1);
3035 /* Always consider the ordinary timers. */
3036 timers
= Vtimer_list
;
3037 /* Consider the idle timers only if Emacs is idle. */
3038 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3039 idle_timers
= Vtimer_idle_list
;
3042 chosen_timer
= Qnil
;
3043 GCPRO3 (timers
, idle_timers
, chosen_timer
);
3045 if (CONSP (timers
) || CONSP (idle_timers
))
3047 EMACS_GET_TIME (now
);
3048 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3049 EMACS_SUB_TIME (idleness_now
, now
, timer_idleness_start_time
);
3052 while (CONSP (timers
) || CONSP (idle_timers
))
3054 int triggertime
= EMACS_SECS (now
);
3055 Lisp_Object
*vector
;
3056 Lisp_Object timer
, idle_timer
;
3057 EMACS_TIME timer_time
, idle_timer_time
;
3058 EMACS_TIME difference
, timer_difference
, idle_timer_difference
;
3060 /* Skip past invalid timers and timers already handled. */
3063 timer
= XCONS (timers
)->car
;
3064 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3066 timers
= XCONS (timers
)->cdr
;
3069 vector
= XVECTOR (timer
)->contents
;
3071 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
3072 || !INTEGERP (vector
[3])
3073 || ! NILP (vector
[0]))
3075 timers
= XCONS (timers
)->cdr
;
3079 if (!NILP (idle_timers
))
3081 timer
= XCONS (idle_timers
)->car
;
3082 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3084 idle_timers
= XCONS (idle_timers
)->cdr
;
3087 vector
= XVECTOR (timer
)->contents
;
3089 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
3090 || !INTEGERP (vector
[3])
3091 || ! NILP (vector
[0]))
3093 idle_timers
= XCONS (idle_timers
)->cdr
;
3098 /* Set TIMER, TIMER_TIME and TIMER_DIFFERENCE
3099 based on the next ordinary timer.
3100 TIMER_DIFFERENCE is the distance in time from NOW to when
3101 this timer becomes ripe (negative if it's already ripe). */
3104 timer
= XCONS (timers
)->car
;
3105 vector
= XVECTOR (timer
)->contents
;
3106 EMACS_SET_SECS (timer_time
,
3107 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
3108 EMACS_SET_USECS (timer_time
, XINT (vector
[3]));
3109 EMACS_SUB_TIME (timer_difference
, timer_time
, now
);
3112 /* Set IDLE_TIMER, IDLE_TIMER_TIME and IDLE_TIMER_DIFFERENCE
3113 based on the next idle timer. */
3114 if (!NILP (idle_timers
))
3116 idle_timer
= XCONS (idle_timers
)->car
;
3117 vector
= XVECTOR (idle_timer
)->contents
;
3118 EMACS_SET_SECS (idle_timer_time
,
3119 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
3120 EMACS_SET_USECS (idle_timer_time
, XINT (vector
[3]));
3121 EMACS_SUB_TIME (idle_timer_difference
, idle_timer_time
, idleness_now
);
3124 /* Decide which timer is the next timer,
3125 and set CHOSEN_TIMER, VECTOR and DIFFERENCE accordingly.
3126 Also step down the list where we found that timer. */
3128 if (! NILP (timers
) && ! NILP (idle_timers
))
3131 EMACS_SUB_TIME (temp
, timer_difference
, idle_timer_difference
);
3132 if (EMACS_TIME_NEG_P (temp
))
3134 chosen_timer
= timer
;
3135 timers
= XCONS (timers
)->cdr
;
3136 difference
= timer_difference
;
3140 chosen_timer
= idle_timer
;
3141 idle_timers
= XCONS (idle_timers
)->cdr
;
3142 difference
= idle_timer_difference
;
3145 else if (! NILP (timers
))
3147 chosen_timer
= timer
;
3148 timers
= XCONS (timers
)->cdr
;
3149 difference
= timer_difference
;
3153 chosen_timer
= idle_timer
;
3154 idle_timers
= XCONS (idle_timers
)->cdr
;
3155 difference
= idle_timer_difference
;
3157 vector
= XVECTOR (chosen_timer
)->contents
;
3159 /* If timer is rupe, run it if it hasn't been run. */
3160 if (EMACS_TIME_NEG_P (difference
)
3161 || (EMACS_SECS (difference
) == 0
3162 && EMACS_USECS (difference
) == 0))
3164 if (NILP (vector
[0]))
3166 /* Mark the timer as triggered to prevent problems if the lisp
3167 code fails to reschedule it right. */
3170 /* Run the timer or queue a timer event. */
3173 Lisp_Object tem
, event
;
3174 int was_locked
= single_kboard
;
3175 int count
= specpdl_ptr
- specpdl
;
3177 specbind (Qinhibit_quit
, Qt
);
3179 tem
= get_keymap_1 (Vspecial_event_map
, 0, 0);
3180 tem
= get_keyelt (access_keymap (tem
, Qtimer_event
, 0, 0),
3182 event
= Fcons (Qtimer_event
, Fcons (chosen_timer
, Qnil
));
3183 Fcommand_execute (tem
, Qnil
, Fvector (1, &event
), Qt
);
3186 unbind_to (count
, Qnil
);
3188 /* Resume allowing input from any kboard, if that was true before. */
3190 any_kboard_state ();
3192 /* Since we have handled the event,
3193 we don't need to tell the caller to wake up and do it. */
3198 /* Generate a timer event so the caller will handle it. */
3199 struct input_event event
;
3201 event
.kind
= timer_event
;
3202 event
.modifiers
= 0;
3203 event
.x
= event
.y
= Qnil
;
3204 event
.timestamp
= triggertime
;
3205 /* Store the timer in the frame slot. */
3206 event
.frame_or_window
3207 = Fcons (Fselected_frame (), chosen_timer
);
3208 kbd_buffer_store_event (&event
);
3210 last_timer_event
= event
;
3212 /* Tell caller to handle this event right away. */
3213 events_generated
= 1;
3214 EMACS_SET_SECS (nexttime
, 0);
3215 EMACS_SET_USECS (nexttime
, 0);
3217 /* Don't queue more than one event at once.
3218 When Emacs is ready for another, it will
3219 queue the next one. */
3227 /* When we encounter a timer that is still waiting,
3228 return the amount of time to wait before it is ripe. */
3231 /* But if we generated an event,
3232 tell the caller to handle it now. */
3233 if (events_generated
)
3239 /* No timers are pending in the future. */
3240 /* Return 0 if we generated an event, and -1 if not. */
3245 /* Caches for modify_event_symbol. */
3246 static Lisp_Object accent_key_syms
;
3247 static Lisp_Object func_key_syms
;
3248 static Lisp_Object mouse_syms
;
3250 /* This is a list of keysym codes for special "accent" characters.
3251 It parallels lispy_accent_keys. */
3253 static int lispy_accent_codes
[] =
3255 #ifdef XK_dead_circumflex
3260 #ifdef XK_dead_grave
3265 #ifdef XK_dead_tilde
3270 #ifdef XK_dead_diaeresis
3275 #ifdef XK_dead_macron
3280 #ifdef XK_dead_degree
3285 #ifdef XK_dead_acute
3290 #ifdef XK_dead_cedilla
3295 #ifdef XK_dead_breve
3300 #ifdef XK_dead_ogonek
3305 #ifdef XK_dead_caron
3310 #ifdef XK_dead_doubleacute
3311 XK_dead_doubleacute
,
3315 #ifdef XK_dead_abovedot
3322 /* This is a list of Lisp names for special "accent" characters.
3323 It parallels lispy_accent_codes. */
3325 static char *lispy_accent_keys
[] =
3343 #define FUNCTION_KEY_OFFSET 0x0
3345 char *lispy_function_keys
[] =
3349 0, /* VK_LBUTTON 0x01 */
3350 0, /* VK_RBUTTON 0x02 */
3351 "cancel", /* VK_CANCEL 0x03 */
3352 0, /* VK_MBUTTON 0x04 */
3354 0, 0, 0, /* 0x05 .. 0x07 */
3356 "backspace", /* VK_BACK 0x08 */
3357 "tab", /* VK_TAB 0x09 */
3359 0, 0, /* 0x0A .. 0x0B */
3361 "clear", /* VK_CLEAR 0x0C */
3362 "return", /* VK_RETURN 0x0D */
3364 0, 0, /* 0x0E .. 0x0F */
3366 "shift", /* VK_SHIFT 0x10 */
3367 "control", /* VK_CONTROL 0x11 */
3368 "menu", /* VK_MENU 0x12 */
3369 "pause", /* VK_PAUSE 0x13 */
3370 "capital", /* VK_CAPITAL 0x14 */
3372 0, 0, 0, 0, 0, 0, /* 0x15 .. 0x1A */
3374 0, /* VK_ESCAPE 0x1B */
3376 0, 0, 0, 0, /* 0x1C .. 0x1F */
3378 0, /* VK_SPACE 0x20 */
3379 "prior", /* VK_PRIOR 0x21 */
3380 "next", /* VK_NEXT 0x22 */
3381 "end", /* VK_END 0x23 */
3382 "home", /* VK_HOME 0x24 */
3383 "left", /* VK_LEFT 0x25 */
3384 "up", /* VK_UP 0x26 */
3385 "right", /* VK_RIGHT 0x27 */
3386 "down", /* VK_DOWN 0x28 */
3387 "select", /* VK_SELECT 0x29 */
3388 "print", /* VK_PRINT 0x2A */
3389 "execute", /* VK_EXECUTE 0x2B */
3390 "snapshot", /* VK_SNAPSHOT 0x2C */
3391 "insert", /* VK_INSERT 0x2D */
3392 "delete", /* VK_DELETE 0x2E */
3393 "help", /* VK_HELP 0x2F */
3395 /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
3397 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3399 0, 0, 0, 0, 0, 0, 0, /* 0x3A .. 0x40 */
3401 /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
3403 0, 0, 0, 0, 0, 0, 0, 0, 0,
3404 0, 0, 0, 0, 0, 0, 0, 0, 0,
3405 0, 0, 0, 0, 0, 0, 0, 0,
3407 "lwindow", /* VK_LWIN 0x5B */
3408 "rwindow", /* VK_RWIN 0x5C */
3409 "apps", /* VK_APPS 0x5D */
3411 0, 0, /* 0x5E .. 0x5F */
3413 "kp-0", /* VK_NUMPAD0 0x60 */
3414 "kp-1", /* VK_NUMPAD1 0x61 */
3415 "kp-2", /* VK_NUMPAD2 0x62 */
3416 "kp-3", /* VK_NUMPAD3 0x63 */
3417 "kp-4", /* VK_NUMPAD4 0x64 */
3418 "kp-5", /* VK_NUMPAD5 0x65 */
3419 "kp-6", /* VK_NUMPAD6 0x66 */
3420 "kp-7", /* VK_NUMPAD7 0x67 */
3421 "kp-8", /* VK_NUMPAD8 0x68 */
3422 "kp-9", /* VK_NUMPAD9 0x69 */
3423 "kp-multiply", /* VK_MULTIPLY 0x6A */
3424 "kp-add", /* VK_ADD 0x6B */
3425 "kp-separator", /* VK_SEPARATOR 0x6C */
3426 "kp-subtract", /* VK_SUBTRACT 0x6D */
3427 "kp-decimal", /* VK_DECIMAL 0x6E */
3428 "kp-divide", /* VK_DIVIDE 0x6F */
3429 "f1", /* VK_F1 0x70 */
3430 "f2", /* VK_F2 0x71 */
3431 "f3", /* VK_F3 0x72 */
3432 "f4", /* VK_F4 0x73 */
3433 "f5", /* VK_F5 0x74 */
3434 "f6", /* VK_F6 0x75 */
3435 "f7", /* VK_F7 0x76 */
3436 "f8", /* VK_F8 0x77 */
3437 "f9", /* VK_F9 0x78 */
3438 "f10", /* VK_F10 0x79 */
3439 "f11", /* VK_F11 0x7A */
3440 "f12", /* VK_F12 0x7B */
3441 "f13", /* VK_F13 0x7C */
3442 "f14", /* VK_F14 0x7D */
3443 "f15", /* VK_F15 0x7E */
3444 "f16", /* VK_F16 0x7F */
3445 "f17", /* VK_F17 0x80 */
3446 "f18", /* VK_F18 0x81 */
3447 "f19", /* VK_F19 0x82 */
3448 "f20", /* VK_F20 0x83 */
3449 "f21", /* VK_F21 0x84 */
3450 "f22", /* VK_F22 0x85 */
3451 "f23", /* VK_F23 0x86 */
3452 "f24", /* VK_F24 0x87 */
3454 0, 0, 0, 0, /* 0x88 .. 0x8B */
3455 0, 0, 0, 0, /* 0x8C .. 0x8F */
3457 "kp-numlock", /* VK_NUMLOCK 0x90 */
3458 "scroll", /* VK_SCROLL 0x91 */
3460 "kp-space", /* VK_NUMPAD_CLEAR 0x92 */
3461 "kp-enter", /* VK_NUMPAD_ENTER 0x93 */
3462 "kp-prior", /* VK_NUMPAD_PRIOR 0x94 */
3463 "kp-next", /* VK_NUMPAD_NEXT 0x95 */
3464 "kp-end", /* VK_NUMPAD_END 0x96 */
3465 "kp-home", /* VK_NUMPAD_HOME 0x97 */
3466 "kp-left", /* VK_NUMPAD_LEFT 0x98 */
3467 "kp-up", /* VK_NUMPAD_UP 0x99 */
3468 "kp-right", /* VK_NUMPAD_RIGHT 0x9A */
3469 "kp-down", /* VK_NUMPAD_DOWN 0x9B */
3470 "kp-insert", /* VK_NUMPAD_INSERT 0x9C */
3471 "kp-delete", /* VK_NUMPAD_DELETE 0x9D */
3473 0, 0, /* 0x9E .. 0x9F */
3476 * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
3477 * Used only as parameters to GetAsyncKeyState() and GetKeyState().
3478 * No other API or message will distinguish left and right keys this way.
3482 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3483 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3484 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3485 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3486 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3492 "attn", /* VK_ATTN 0xF6 */
3493 "crsel", /* VK_CRSEL 0xF7 */
3494 "exsel", /* VK_EXSEL 0xF8 */
3495 "ereof", /* VK_EREOF 0xF9 */
3496 "play", /* VK_PLAY 0xFA */
3497 "zoom", /* VK_ZOOM 0xFB */
3498 "noname", /* VK_NONAME 0xFC */
3499 "pa1", /* VK_PA1 0xFD */
3500 "oem_clear", /* VK_OEM_CLEAR 0xFE */
3503 #else /* not HAVE_NTGUI */
3506 static char *lispy_kana_keys
[] =
3508 /* X Keysym value */
3509 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x400 .. 0x40f */
3510 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x410 .. 0x41f */
3511 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x420 .. 0x42f */
3512 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x430 .. 0x43f */
3513 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x440 .. 0x44f */
3514 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x450 .. 0x45f */
3515 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x460 .. 0x46f */
3516 0,0,0,0,0,0,0,0,0,0,0,0,0,0,"overline",0,
3517 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x480 .. 0x48f */
3518 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x490 .. 0x49f */
3519 0, "kana-fullstop", "kana-openingbracket", "kana-closingbracket",
3520 "kana-comma", "kana-conjunctive", "kana-WO", "kana-a",
3521 "kana-i", "kana-u", "kana-e", "kana-o",
3522 "kana-ya", "kana-yu", "kana-yo", "kana-tsu",
3523 "prolongedsound", "kana-A", "kana-I", "kana-U",
3524 "kana-E", "kana-O", "kana-KA", "kana-KI",
3525 "kana-KU", "kana-KE", "kana-KO", "kana-SA",
3526 "kana-SHI", "kana-SU", "kana-SE", "kana-SO",
3527 "kana-TA", "kana-CHI", "kana-TSU", "kana-TE",
3528 "kana-TO", "kana-NA", "kana-NI", "kana-NU",
3529 "kana-NE", "kana-NO", "kana-HA", "kana-HI",
3530 "kana-FU", "kana-HE", "kana-HO", "kana-MA",
3531 "kana-MI", "kana-MU", "kana-ME", "kana-MO",
3532 "kana-YA", "kana-YU", "kana-YO", "kana-RA",
3533 "kana-RI", "kana-RU", "kana-RE", "kana-RO",
3534 "kana-WA", "kana-N", "voicedsound", "semivoicedsound",
3535 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4e0 .. 0x4ef */
3536 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4f0 .. 0x4ff */
3538 #endif /* XK_kana_A */
3540 #define FUNCTION_KEY_OFFSET 0xff00
3542 /* You'll notice that this table is arranged to be conveniently
3543 indexed by X Windows keysym values. */
3544 static char *lispy_function_keys
[] =
3546 /* X Keysym value */
3548 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00 */
3556 0, 0, 0, /* 0xff10 */
3558 0, 0, 0, 0, 0, 0, 0,
3561 0, "kanji", "muhenkan",
3562 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff20...2f */
3563 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff30...3f */
3564 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
3566 "home", /* 0xff50 */ /* IsCursorKey */
3577 "select", /* 0xff60 */ /* IsMiscFunctionKey */
3588 "break", /* 0xff6b */
3590 0, 0, 0, 0, 0, 0, 0, 0, "backtab", 0,
3592 0, 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff7f */
3593 "kp-space", /* 0xff80 */ /* IsKeypadKey */
3594 0, 0, 0, 0, 0, 0, 0, 0,
3595 "kp-tab", /* 0xff89 */
3597 "kp-enter", /* 0xff8d */
3599 "kp-f1", /* 0xff91 */
3603 "kp-home", /* 0xff95 */
3608 "kp-prior", /* kp-page-up */
3609 "kp-next", /* kp-page-down */
3615 0, 0, 0, 0, 0, 0, 0, 0, 0,
3616 "kp-multiply", /* 0xffaa */
3621 "kp-divide", /* 0xffaf */
3622 "kp-0", /* 0xffb0 */
3623 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
3626 "kp-equal", /* 0xffbd */
3627 "f1", /* 0xffbe */ /* IsFunctionKey */
3629 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
3630 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
3631 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
3632 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
3633 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
3634 0, 0, 0, 0, 0, 0, 0, 0,
3635 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
3636 0, 0, 0, 0, 0, 0, 0, "delete"
3639 /* ISO 9995 Function and Modifier Keys; the first byte is 0xFE. */
3640 #define ISO_FUNCTION_KEY_OFFSET 0xfe00
3642 static char *iso_lispy_function_keys
[] =
3644 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe00 */
3645 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe08 */
3646 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe10 */
3647 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe18 */
3648 "iso-lefttab", /* 0xfe20 */
3649 "iso-move-line-up", "iso-move-line-down",
3650 "iso-partial-line-up", "iso-partial-line-down",
3651 "iso-partial-space-left", "iso-partial-space-right",
3652 "iso-set-margin-left", "iso-set-margin-right", /* 0xffe27, 28 */
3653 "iso-release-margin-left", "iso-release-margin-right",
3654 "iso-release-both-margins",
3655 "iso-fast-cursor-left", "iso-fast-cursor-right",
3656 "iso-fast-cursor-up", "iso-fast-cursor-down",
3657 "iso-continuous-underline", "iso-discontinuous-underline", /* 0xfe30, 31 */
3658 "iso-emphasize", "iso-center-object", "iso-enter", /* ... 0xfe34 */
3661 #endif /* not HAVE_NTGUI */
3663 static char *lispy_mouse_names
[] =
3665 "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5"
3668 /* Scroll bar parts. */
3669 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
3670 Lisp_Object Qup
, Qdown
;
3672 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
3673 Lisp_Object
*scroll_bar_parts
[] = {
3674 &Qabove_handle
, &Qhandle
, &Qbelow_handle
,
3679 /* A vector, indexed by button number, giving the down-going location
3680 of currently depressed buttons, both scroll bar and non-scroll bar.
3682 The elements have the form
3683 (BUTTON-NUMBER MODIFIER-MASK . REST)
3684 where REST is the cdr of a position as it would be reported in the event.
3686 The make_lispy_event function stores positions here to tell the
3687 difference between click and drag events, and to store the starting
3688 location to be included in drag events. */
3690 static Lisp_Object button_down_location
;
3692 /* Information about the most recent up-going button event: Which
3693 button, what location, and what time. */
3695 static int last_mouse_button
;
3696 static int last_mouse_x
;
3697 static int last_mouse_y
;
3698 static unsigned long button_down_time
;
3700 /* The maximum time between clicks to make a double-click,
3701 or Qnil to disable double-click detection,
3702 or Qt for no time limit. */
3703 Lisp_Object Vdouble_click_time
;
3705 /* The number of clicks in this multiple-click. */
3707 int double_click_count
;
3709 /* Given a struct input_event, build the lisp event which represents
3710 it. If EVENT is 0, build a mouse movement event from the mouse
3711 movement buffer, which should have a movement event in it.
3713 Note that events must be passed to this function in the order they
3714 are received; this function stores the location of button presses
3715 in order to build drag events when the button is released. */
3718 make_lispy_event (event
)
3719 struct input_event
*event
;
3723 switch (SWITCH_ENUM_CAST (event
->kind
))
3725 /* A simple keystroke. */
3726 case ascii_keystroke
:
3728 Lisp_Object lispy_c
;
3729 int c
= event
->code
& 0377;
3730 /* Turn ASCII characters into control characters
3732 if (event
->modifiers
& ctrl_modifier
)
3733 c
= make_ctrl_char (c
);
3735 /* Add in the other modifier bits. We took care of ctrl_modifier
3736 just above, and the shift key was taken care of by the X code,
3737 and applied to control characters by make_ctrl_char. */
3738 c
|= (event
->modifiers
3739 & (meta_modifier
| alt_modifier
3740 | hyper_modifier
| super_modifier
));
3741 button_down_time
= 0;
3742 XSETFASTINT (lispy_c
, c
);
3746 /* A function key. The symbol may need to have modifier prefixes
3748 case non_ascii_keystroke
:
3749 button_down_time
= 0;
3751 for (i
= 0; i
< sizeof (lispy_accent_codes
) / sizeof (int); i
++)
3752 if (event
->code
== lispy_accent_codes
[i
])
3753 return modify_event_symbol (i
,
3755 Qfunction_key
, Qnil
,
3756 lispy_accent_keys
, &accent_key_syms
,
3757 (sizeof (lispy_accent_keys
)
3758 / sizeof (lispy_accent_keys
[0])));
3760 /* Handle system-specific keysyms. */
3761 if (event
->code
& (1 << 28))
3763 /* We need to use an alist rather than a vector as the cache
3764 since we can't make a vector long enuf. */
3765 if (NILP (current_kboard
->system_key_syms
))
3766 current_kboard
->system_key_syms
= Fcons (Qnil
, Qnil
);
3767 return modify_event_symbol (event
->code
,
3770 current_kboard
->Vsystem_key_alist
,
3771 0, ¤t_kboard
->system_key_syms
,
3776 if (event
->code
>= 0x400 && event
->code
< 0x500)
3777 return modify_event_symbol (event
->code
- 0x400,
3778 event
->modifiers
& ~shift_modifier
,
3779 Qfunction_key
, Qnil
,
3780 lispy_kana_keys
, &func_key_syms
,
3781 (sizeof (lispy_kana_keys
)
3782 / sizeof (lispy_kana_keys
[0])));
3783 #endif /* XK_kana_A */
3785 if (event
->code
< FUNCTION_KEY_OFFSET
3786 && event
->code
>= ISO_FUNCTION_KEY_OFFSET
)
3787 return modify_event_symbol (event
->code
- ISO_FUNCTION_KEY_OFFSET
,
3789 Qfunction_key
, Qnil
,
3790 iso_lispy_function_keys
, &func_key_syms
,
3791 (sizeof (iso_lispy_function_keys
)
3792 / sizeof (iso_lispy_function_keys
[0])));
3794 return modify_event_symbol (event
->code
- FUNCTION_KEY_OFFSET
,
3796 Qfunction_key
, Qnil
,
3797 lispy_function_keys
, &func_key_syms
,
3798 (sizeof (lispy_function_keys
)
3799 / sizeof (lispy_function_keys
[0])));
3801 /* Note that timer_event is currently never used. */
3803 return Fcons (Qtimer_event
, Fcons (Fcdr (event
->frame_or_window
), Qnil
));
3806 /* A mouse click. Figure out where it is, decide whether it's
3807 a press, click or drag, and build the appropriate structure. */
3809 case scroll_bar_click
:
3811 int button
= event
->code
;
3813 Lisp_Object position
;
3814 Lisp_Object
*start_pos_ptr
;
3815 Lisp_Object start_pos
;
3817 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
3820 /* Build the position as appropriate for this mouse click. */
3821 if (event
->kind
== mouse_click
)
3824 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
3829 /* Ignore mouse events that were made on frame that
3830 have been deleted. */
3831 if (! FRAME_LIVE_P (f
))
3834 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
3835 &column
, &row
, NULL
, 1);
3837 #ifndef USE_X_TOOLKIT
3838 /* In the non-toolkit version, clicks on the menu bar
3839 are ordinary button events in the event buffer.
3840 Distinguish them, and invoke the menu.
3842 (In the toolkit version, the toolkit handles the menu bar
3843 and Emacs doesn't know about it until after the user
3844 makes a selection.) */
3845 if (row
>= 0 && row
< FRAME_MENU_BAR_LINES (f
)
3846 && (event
->modifiers
& down_modifier
))
3848 Lisp_Object items
, item
;
3853 /* Activate the menu bar on the down event. If the
3854 up event comes in before the menu code can deal with it,
3856 if (! (event
->modifiers
& down_modifier
))
3861 items
= FRAME_MENU_BAR_ITEMS (f
);
3862 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
3864 Lisp_Object pos
, string
;
3865 string
= XVECTOR (items
)->contents
[i
+ 1];
3866 pos
= XVECTOR (items
)->contents
[i
+ 3];
3869 if (column
>= XINT (pos
)
3870 && column
< XINT (pos
) + XSTRING (string
)->size
)
3872 item
= XVECTOR (items
)->contents
[i
];
3878 = Fcons (event
->frame_or_window
,
3880 Fcons (Fcons (event
->x
, event
->y
),
3881 Fcons (make_number (event
->timestamp
),
3884 return Fcons (item
, Fcons (position
, Qnil
));
3886 #endif /* not USE_X_TOOLKIT */
3888 window
= window_from_coordinates (f
, column
, row
, &part
);
3890 if (!WINDOWP (window
))
3892 window
= event
->frame_or_window
;
3897 int pixcolumn
, pixrow
;
3898 column
-= WINDOW_LEFT_MARGIN (XWINDOW (window
));
3899 row
-= XINT (XWINDOW (window
)->top
);
3900 glyph_to_pixel_coords (f
, column
, row
, &pixcolumn
, &pixrow
);
3901 XSETINT (event
->x
, pixcolumn
);
3902 XSETINT (event
->y
, pixrow
);
3907 posn
= Qvertical_line
;
3910 buffer_posn_from_coords (XWINDOW (window
),
3917 Fcons (Fcons (event
->x
, event
->y
),
3918 Fcons (make_number (event
->timestamp
),
3924 Lisp_Object portion_whole
;
3927 window
= event
->frame_or_window
;
3928 portion_whole
= Fcons (event
->x
, event
->y
);
3929 part
= *scroll_bar_parts
[(int) event
->part
];
3933 Fcons (Qvertical_scroll_bar
,
3934 Fcons (portion_whole
,
3935 Fcons (make_number (event
->timestamp
),
3936 Fcons (part
, Qnil
)))));
3939 start_pos_ptr
= &XVECTOR (button_down_location
)->contents
[button
];
3941 start_pos
= *start_pos_ptr
;
3942 *start_pos_ptr
= Qnil
;
3944 is_double
= (button
== last_mouse_button
3945 && XINT (event
->x
) == last_mouse_x
3946 && XINT (event
->y
) == last_mouse_y
3947 && button_down_time
!= 0
3948 && (EQ (Vdouble_click_time
, Qt
)
3949 || (INTEGERP (Vdouble_click_time
)
3950 && ((int)(event
->timestamp
- button_down_time
)
3951 < XINT (Vdouble_click_time
)))));
3952 last_mouse_button
= button
;
3953 last_mouse_x
= XINT (event
->x
);
3954 last_mouse_y
= XINT (event
->y
);
3956 /* If this is a button press, squirrel away the location, so
3957 we can decide later whether it was a click or a drag. */
3958 if (event
->modifiers
& down_modifier
)
3962 double_click_count
++;
3963 event
->modifiers
|= ((double_click_count
> 2)
3968 double_click_count
= 1;
3969 button_down_time
= event
->timestamp
;
3970 *start_pos_ptr
= Fcopy_alist (position
);
3973 /* Now we're releasing a button - check the co-ordinates to
3974 see if this was a click or a drag. */
3975 else if (event
->modifiers
& up_modifier
)
3977 /* If we did not see a down before this up,
3978 ignore the up. Probably this happened because
3979 the down event chose a menu item.
3980 It would be an annoyance to treat the release
3981 of the button that chose the menu item
3982 as a separate event. */
3984 if (!CONSP (start_pos
))
3987 event
->modifiers
&= ~up_modifier
;
3988 #if 0 /* Formerly we treated an up with no down as a click event. */
3989 if (!CONSP (start_pos
))
3990 event
->modifiers
|= click_modifier
;
3994 /* The third element of every position should be the (x,y)
3998 down
= Fnth (make_number (2), start_pos
);
3999 if (EQ (event
->x
, XCONS (down
)->car
)
4000 && EQ (event
->y
, XCONS (down
)->cdr
))
4002 event
->modifiers
|= click_modifier
;
4006 button_down_time
= 0;
4007 event
->modifiers
|= drag_modifier
;
4009 /* Don't check is_double; treat this as multiple
4010 if the down-event was multiple. */
4011 if (double_click_count
> 1)
4012 event
->modifiers
|= ((double_click_count
> 2)
4018 /* Every mouse event should either have the down_modifier or
4019 the up_modifier set. */
4023 /* Get the symbol we should use for the mouse click. */
4026 head
= modify_event_symbol (button
,
4029 lispy_mouse_names
, &mouse_syms
,
4030 (sizeof (lispy_mouse_names
)
4031 / sizeof (lispy_mouse_names
[0])));
4032 if (event
->modifiers
& drag_modifier
)
4037 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
4040 Fcons (make_number (double_click_count
),
4050 case w32_scroll_bar_click
:
4052 int button
= event
->code
;
4054 Lisp_Object position
;
4055 Lisp_Object
*start_pos_ptr
;
4056 Lisp_Object start_pos
;
4058 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
4063 Lisp_Object portion_whole
;
4066 window
= event
->frame_or_window
;
4067 portion_whole
= Fcons (event
->x
, event
->y
);
4068 part
= *scroll_bar_parts
[(int) event
->part
];
4072 Fcons (Qvertical_scroll_bar
,
4073 Fcons (portion_whole
,
4074 Fcons (make_number (event
->timestamp
),
4075 Fcons (part
, Qnil
)))));
4078 /* Always treat W32 scroll bar events as clicks. */
4079 event
->modifiers
|= click_modifier
;
4082 /* Get the symbol we should use for the mouse click. */
4085 head
= modify_event_symbol (button
,
4088 lispy_mouse_names
, &mouse_syms
,
4089 (sizeof (lispy_mouse_names
)
4090 / sizeof (lispy_mouse_names
[0])));
4098 #endif /* HAVE_MOUSE */
4100 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
4101 case menu_bar_event
:
4102 /* The event value is in the cdr of the frame_or_window slot. */
4103 if (!CONSP (event
->frame_or_window
))
4105 return XCONS (event
->frame_or_window
)->cdr
;
4108 /* The 'kind' field of the event is something we don't recognize. */
4117 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
4119 Lisp_Object bar_window
;
4120 enum scroll_bar_part part
;
4124 /* Is it a scroll bar movement? */
4125 if (frame
&& ! NILP (bar_window
))
4127 Lisp_Object part_sym
;
4129 part_sym
= *scroll_bar_parts
[(int) part
];
4130 return Fcons (Qscroll_bar_movement
,
4131 (Fcons (Fcons (bar_window
,
4132 Fcons (Qvertical_scroll_bar
,
4133 Fcons (Fcons (x
, y
),
4134 Fcons (make_number (time
),
4140 /* Or is it an ordinary mouse movement? */
4150 /* It's in a frame; which window on that frame? */
4151 pixel_to_glyph_coords (frame
, XINT (x
), XINT (y
), &column
, &row
,
4153 window
= window_from_coordinates (frame
, column
, row
, &area
);
4158 if (WINDOWP (window
))
4160 int pixcolumn
, pixrow
;
4161 column
-= WINDOW_LEFT_MARGIN (XWINDOW (window
));
4162 row
-= XINT (XWINDOW (window
)->top
);
4163 glyph_to_pixel_coords (frame
, column
, row
, &pixcolumn
, &pixrow
);
4164 XSETINT (x
, pixcolumn
);
4165 XSETINT (y
, pixrow
);
4170 posn
= Qvertical_line
;
4173 buffer_posn_from_coords (XWINDOW (window
), column
, row
));
4175 else if (frame
!= 0)
4177 XSETFRAME (window
, frame
);
4188 return Fcons (Qmouse_movement
,
4189 Fcons (Fcons (window
,
4191 Fcons (Fcons (x
, y
),
4192 Fcons (make_number (time
),
4198 #endif /* HAVE_MOUSE */
4200 /* Construct a switch frame event. */
4202 make_lispy_switch_frame (frame
)
4205 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
4208 /* Manipulating modifiers. */
4210 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
4212 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
4213 SYMBOL's name of the end of the modifiers; the string from this
4214 position is the unmodified symbol name.
4216 This doesn't use any caches. */
4219 parse_modifiers_uncached (symbol
, modifier_end
)
4223 struct Lisp_String
*name
;
4227 CHECK_SYMBOL (symbol
, 1);
4230 name
= XSYMBOL (symbol
)->name
;
4232 for (i
= 0; i
+2 <= name
->size
; )
4234 int this_mod_end
= 0;
4237 /* See if the name continues with a modifier word.
4238 Check that the word appears, but don't check what follows it.
4239 Set this_mod and this_mod_end to record what we find. */
4241 switch (name
->data
[i
])
4243 #define SINGLE_LETTER_MOD(BIT) \
4244 (this_mod_end = i + 1, this_mod = BIT)
4247 SINGLE_LETTER_MOD (alt_modifier
);
4251 SINGLE_LETTER_MOD (ctrl_modifier
);
4255 SINGLE_LETTER_MOD (hyper_modifier
);
4259 SINGLE_LETTER_MOD (meta_modifier
);
4263 SINGLE_LETTER_MOD (shift_modifier
);
4267 SINGLE_LETTER_MOD (super_modifier
);
4270 #undef SINGLE_LETTER_MOD
4273 /* If we found no modifier, stop looking for them. */
4274 if (this_mod_end
== 0)
4277 /* Check there is a dash after the modifier, so that it
4278 really is a modifier. */
4279 if (this_mod_end
>= name
->size
|| name
->data
[this_mod_end
] != '-')
4282 /* This modifier is real; look for another. */
4283 modifiers
|= this_mod
;
4284 i
= this_mod_end
+ 1;
4287 /* Should we include the `click' modifier? */
4288 if (! (modifiers
& (down_modifier
| drag_modifier
4289 | double_modifier
| triple_modifier
))
4290 && i
+ 7 == name
->size
4291 && strncmp (name
->data
+ i
, "mouse-", 6) == 0
4292 && ('0' <= name
->data
[i
+ 6] && name
->data
[i
+ 6] <= '9'))
4293 modifiers
|= click_modifier
;
4301 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
4302 prepended to the string BASE[0..BASE_LEN-1].
4303 This doesn't use any caches. */
4305 apply_modifiers_uncached (modifiers
, base
, base_len
)
4310 /* Since BASE could contain nulls, we can't use intern here; we have
4311 to use Fintern, which expects a genuine Lisp_String, and keeps a
4314 (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
4320 /* Only the event queue may use the `up' modifier; it should always
4321 be turned into a click or drag event before presented to lisp code. */
4322 if (modifiers
& up_modifier
)
4325 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
4326 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
4327 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
4328 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
4329 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
4330 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
4331 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
4332 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
4333 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
4334 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
4335 /* The click modifier is denoted by the absence of other modifiers. */
4339 mod_len
= p
- new_mods
;
4343 Lisp_Object new_name
;
4345 new_name
= make_uninit_string (mod_len
+ base_len
);
4346 bcopy (new_mods
, XSTRING (new_name
)->data
, mod_len
);
4347 bcopy (base
, XSTRING (new_name
)->data
+ mod_len
, base_len
);
4349 return Fintern (new_name
, Qnil
);
4354 static char *modifier_names
[] =
4356 "up", "down", "drag", "click", "double", "triple", 0, 0,
4357 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4358 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
4360 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
4362 static Lisp_Object modifier_symbols
;
4364 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
4366 lispy_modifier_list (modifiers
)
4369 Lisp_Object modifier_list
;
4372 modifier_list
= Qnil
;
4373 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
4374 if (modifiers
& (1<<i
))
4375 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
4378 return modifier_list
;
4382 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
4383 where UNMODIFIED is the unmodified form of SYMBOL,
4384 MASK is the set of modifiers present in SYMBOL's name.
4385 This is similar to parse_modifiers_uncached, but uses the cache in
4386 SYMBOL's Qevent_symbol_element_mask property, and maintains the
4387 Qevent_symbol_elements property. */
4390 parse_modifiers (symbol
)
4393 Lisp_Object elements
;
4395 elements
= Fget (symbol
, Qevent_symbol_element_mask
);
4396 if (CONSP (elements
))
4401 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
4402 Lisp_Object unmodified
;
4405 unmodified
= Fintern (make_string (XSYMBOL (symbol
)->name
->data
+ end
,
4406 XSYMBOL (symbol
)->name
->size
- end
),
4409 if (modifiers
& ~(((EMACS_INT
)1 << VALBITS
) - 1))
4411 XSETFASTINT (mask
, modifiers
);
4412 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
4414 /* Cache the parsing results on SYMBOL. */
4415 Fput (symbol
, Qevent_symbol_element_mask
,
4417 Fput (symbol
, Qevent_symbol_elements
,
4418 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
4420 /* Since we know that SYMBOL is modifiers applied to unmodified,
4421 it would be nice to put that in unmodified's cache.
4422 But we can't, since we're not sure that parse_modifiers is
4429 /* Apply the modifiers MODIFIERS to the symbol BASE.
4430 BASE must be unmodified.
4432 This is like apply_modifiers_uncached, but uses BASE's
4433 Qmodifier_cache property, if present. It also builds
4434 Qevent_symbol_elements properties, since it has that info anyway.
4436 apply_modifiers copies the value of BASE's Qevent_kind property to
4437 the modified symbol. */
4439 apply_modifiers (modifiers
, base
)
4443 Lisp_Object cache
, index
, entry
, new_symbol
;
4445 /* Mask out upper bits. We don't know where this value's been. */
4446 modifiers
&= ((EMACS_INT
)1 << VALBITS
) - 1;
4448 /* The click modifier never figures into cache indices. */
4449 cache
= Fget (base
, Qmodifier_cache
);
4450 XSETFASTINT (index
, (modifiers
& ~click_modifier
));
4451 entry
= assq_no_quit (index
, cache
);
4454 new_symbol
= XCONS (entry
)->cdr
;
4457 /* We have to create the symbol ourselves. */
4458 new_symbol
= apply_modifiers_uncached (modifiers
,
4459 XSYMBOL (base
)->name
->data
,
4460 XSYMBOL (base
)->name
->size
);
4462 /* Add the new symbol to the base's cache. */
4463 entry
= Fcons (index
, new_symbol
);
4464 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
4466 /* We have the parsing info now for free, so add it to the caches. */
4467 XSETFASTINT (index
, modifiers
);
4468 Fput (new_symbol
, Qevent_symbol_element_mask
,
4469 Fcons (base
, Fcons (index
, Qnil
)));
4470 Fput (new_symbol
, Qevent_symbol_elements
,
4471 Fcons (base
, lispy_modifier_list (modifiers
)));
4474 /* Make sure this symbol is of the same kind as BASE.
4476 You'd think we could just set this once and for all when we
4477 intern the symbol above, but reorder_modifiers may call us when
4478 BASE's property isn't set right; we can't assume that just
4479 because it has a Qmodifier_cache property it must have its
4480 Qevent_kind set right as well. */
4481 if (NILP (Fget (new_symbol
, Qevent_kind
)))
4485 kind
= Fget (base
, Qevent_kind
);
4487 Fput (new_symbol
, Qevent_kind
, kind
);
4494 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
4495 return a symbol with the modifiers placed in the canonical order.
4496 Canonical order is alphabetical, except for down and drag, which
4497 always come last. The 'click' modifier is never written out.
4499 Fdefine_key calls this to make sure that (for example) C-M-foo
4500 and M-C-foo end up being equivalent in the keymap. */
4503 reorder_modifiers (symbol
)
4506 /* It's hopefully okay to write the code this way, since everything
4507 will soon be in caches, and no consing will be done at all. */
4510 parsed
= parse_modifiers (symbol
);
4511 return apply_modifiers ((int) XINT (XCONS (XCONS (parsed
)->cdr
)->car
),
4512 XCONS (parsed
)->car
);
4516 /* For handling events, we often want to produce a symbol whose name
4517 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
4518 to some base, like the name of a function key or mouse button.
4519 modify_event_symbol produces symbols of this sort.
4521 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
4522 is the name of the i'th symbol. TABLE_SIZE is the number of elements
4525 Alternatively, NAME_ALIST is an alist mapping codes into symbol names.
4526 NAME_ALIST is used if it is non-nil; otherwise NAME_TABLE is used.
4528 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
4529 persist between calls to modify_event_symbol that it can use to
4530 store a cache of the symbols it's generated for this NAME_TABLE
4531 before. The object stored there may be a vector or an alist.
4533 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
4535 MODIFIERS is a set of modifier bits (as given in struct input_events)
4536 whose prefixes should be applied to the symbol name.
4538 SYMBOL_KIND is the value to be placed in the event_kind property of
4539 the returned symbol.
4541 The symbols we create are supposed to have an
4542 `event-symbol-elements' property, which lists the modifiers present
4543 in the symbol's name. */
4546 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_alist
,
4547 name_table
, symbol_table
, table_size
)
4550 Lisp_Object symbol_kind
;
4551 Lisp_Object name_alist
;
4553 Lisp_Object
*symbol_table
;
4554 unsigned int table_size
;
4557 Lisp_Object symbol_int
;
4559 /* Get rid of the "vendor-specific" bit here. */
4560 XSETINT (symbol_int
, symbol_num
& 0xffffff);
4562 /* Is this a request for a valid symbol? */
4563 if (symbol_num
< 0 || symbol_num
>= table_size
)
4566 if (CONSP (*symbol_table
))
4567 value
= Fcdr (assq_no_quit (symbol_int
, *symbol_table
));
4569 /* If *symbol_table doesn't seem to be initialized properly, fix that.
4570 *symbol_table should be a lisp vector TABLE_SIZE elements long,
4571 where the Nth element is the symbol for NAME_TABLE[N], or nil if
4572 we've never used that symbol before. */
4575 if (! VECTORP (*symbol_table
)
4576 || XVECTOR (*symbol_table
)->size
!= table_size
)
4580 XSETFASTINT (size
, table_size
);
4581 *symbol_table
= Fmake_vector (size
, Qnil
);
4584 value
= XVECTOR (*symbol_table
)->contents
[symbol_num
];
4587 /* Have we already used this symbol before? */
4590 /* No; let's create it. */
4591 if (!NILP (name_alist
))
4592 value
= Fcdr_safe (Fassq (symbol_int
, name_alist
));
4593 else if (name_table
!= 0 && name_table
[symbol_num
])
4594 value
= intern (name_table
[symbol_num
]);
4596 #ifdef HAVE_WINDOW_SYSTEM
4599 char *name
= x_get_keysym_name (symbol_num
);
4601 value
= intern (name
);
4608 sprintf (buf
, "key-%d", symbol_num
);
4609 value
= intern (buf
);
4612 if (CONSP (*symbol_table
))
4613 *symbol_table
= Fcons (Fcons (symbol_int
, value
), *symbol_table
);
4615 XVECTOR (*symbol_table
)->contents
[symbol_num
] = value
;
4617 /* Fill in the cache entries for this symbol; this also
4618 builds the Qevent_symbol_elements property, which the user
4620 apply_modifiers (modifiers
& click_modifier
, value
);
4621 Fput (value
, Qevent_kind
, symbol_kind
);
4624 /* Apply modifiers to that symbol. */
4625 return apply_modifiers (modifiers
, value
);
4628 /* Convert a list that represents an event type,
4629 such as (ctrl meta backspace), into the usual representation of that
4630 event type as a number or a symbol. */
4632 DEFUN ("event-convert-list", Fevent_convert_list
, Sevent_convert_list
, 1, 1, 0,
4633 "Convert the event description list EVENT-DESC to an event type.\n\
4634 EVENT-DESC should contain one base event type (a character or symbol)\n\
4635 and zero or more modifier names (control, meta, hyper, super, shift, alt,\n\
4636 drag, down, double or triple). The base must be last.\n\
4637 The return value is an event type (a character or symbol) which\n\
4638 has the same base event type and all the specified modifiers.")
4640 Lisp_Object event_desc
;
4648 while (CONSP (rest
))
4653 elt
= XCONS (rest
)->car
;
4654 rest
= XCONS (rest
)->cdr
;
4656 /* Given a symbol, see if it is a modifier name. */
4657 if (SYMBOLP (elt
) && CONSP (rest
))
4658 this = parse_solitary_modifier (elt
);
4662 else if (!NILP (base
))
4663 error ("Two bases given in one event");
4669 /* Let the symbol A refer to the character A. */
4670 if (SYMBOLP (base
) && XSYMBOL (base
)->name
->size
== 1)
4671 XSETINT (base
, XSYMBOL (base
)->name
->data
[0]);
4673 if (INTEGERP (base
))
4675 /* Turn (shift a) into A. */
4676 if ((modifiers
& shift_modifier
) != 0
4677 && (XINT (base
) >= 'a' && XINT (base
) <= 'z'))
4679 XSETINT (base
, XINT (base
) - ('a' - 'A'));
4680 modifiers
&= ~shift_modifier
;
4683 /* Turn (control a) into C-a. */
4684 if (modifiers
& ctrl_modifier
)
4685 return make_number ((modifiers
& ~ctrl_modifier
)
4686 | make_ctrl_char (XINT (base
)));
4688 return make_number (modifiers
| XINT (base
));
4690 else if (SYMBOLP (base
))
4691 return apply_modifiers (modifiers
, base
);
4693 error ("Invalid base event");
4696 /* Try to recognize SYMBOL as a modifier name.
4697 Return the modifier flag bit, or 0 if not recognized. */
4700 parse_solitary_modifier (symbol
)
4703 struct Lisp_String
*name
= XSYMBOL (symbol
)->name
;
4705 switch (name
->data
[0])
4707 #define SINGLE_LETTER_MOD(BIT) \
4708 if (name->size == 1) \
4711 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
4712 if (LEN == name->size \
4713 && ! strncmp (name->data, NAME, LEN)) \
4717 SINGLE_LETTER_MOD (alt_modifier
);
4721 MULTI_LETTER_MOD (alt_modifier
, "alt", 3);
4725 SINGLE_LETTER_MOD (ctrl_modifier
);
4729 MULTI_LETTER_MOD (ctrl_modifier
, "ctrl", 4);
4730 MULTI_LETTER_MOD (ctrl_modifier
, "control", 7);
4734 SINGLE_LETTER_MOD (hyper_modifier
);
4738 MULTI_LETTER_MOD (hyper_modifier
, "hyper", 5);
4742 SINGLE_LETTER_MOD (meta_modifier
);
4746 MULTI_LETTER_MOD (meta_modifier
, "meta", 4);
4750 SINGLE_LETTER_MOD (shift_modifier
);
4754 MULTI_LETTER_MOD (shift_modifier
, "shift", 5);
4755 MULTI_LETTER_MOD (super_modifier
, "super", 5);
4756 SINGLE_LETTER_MOD (super_modifier
);
4760 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
4761 MULTI_LETTER_MOD (down_modifier
, "down", 4);
4762 MULTI_LETTER_MOD (double_modifier
, "double", 6);
4766 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
4769 #undef SINGLE_LETTER_MOD
4770 #undef MULTI_LETTER_MOD
4776 /* Return 1 if EVENT is a list whose elements are all integers or symbols.
4777 Such a list is not valid as an event,
4778 but it can be a Lucid-style event type list. */
4781 lucid_event_type_list_p (object
)
4786 if (! CONSP (object
))
4789 for (tail
= object
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4792 elt
= XCONS (tail
)->car
;
4793 if (! (INTEGERP (elt
) || SYMBOLP (elt
)))
4800 /* Store into *addr a value nonzero if terminal input chars are available.
4801 Serves the purpose of ioctl (0, FIONREAD, addr)
4802 but works even if FIONREAD does not exist.
4803 (In fact, this may actually read some input.)
4805 If DO_TIMERS_NOW is nonzero, actually run timer events that are ripe. */
4808 get_input_pending (addr
, do_timers_now
)
4812 /* First of all, have we already counted some input? */
4813 *addr
= !NILP (Vquit_flag
) || readable_events (do_timers_now
);
4815 /* If input is being read as it arrives, and we have none, there is none. */
4816 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
4819 /* Try to read some input and see how much we get. */
4821 *addr
= !NILP (Vquit_flag
) || readable_events (do_timers_now
);
4824 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
4827 gobble_input (expected
)
4832 if (interrupt_input
)
4835 mask
= sigblock (sigmask (SIGIO
));
4836 read_avail_input (expected
);
4840 #ifdef POLL_FOR_INPUT
4841 if (read_socket_hook
&& !interrupt_input
&& poll_suppress_count
== 0)
4844 mask
= sigblock (sigmask (SIGALRM
));
4845 read_avail_input (expected
);
4851 read_avail_input (expected
);
4855 /* Put a buffer_switch_event in the buffer
4856 so that read_key_sequence will notice the new current buffer. */
4858 record_asynch_buffer_change ()
4860 struct input_event event
;
4863 event
.kind
= buffer_switch_event
;
4864 event
.frame_or_window
= Qnil
;
4867 /* We don't need a buffer-switch event unless Emacs is waiting for input.
4868 The purpose of the event is to make read_key_sequence look up the
4869 keymaps again. If we aren't in read_key_sequence, we don't need one,
4870 and the event could cause trouble by messing up (input-pending-p). */
4871 tem
= Fwaiting_for_user_input_p ();
4875 /* We never need these events if we have no asynchronous subprocesses. */
4879 /* Make sure no interrupt happens while storing the event. */
4881 if (interrupt_input
)
4884 mask
= sigblock (sigmask (SIGIO
));
4885 kbd_buffer_store_event (&event
);
4892 kbd_buffer_store_event (&event
);
4899 /* Read any terminal input already buffered up by the system
4900 into the kbd_buffer, but do not wait.
4902 EXPECTED should be nonzero if the caller knows there is some input.
4904 Except on VMS, all input is read by this function.
4905 If interrupt_input is nonzero, this function MUST be called
4906 only when SIGIO is blocked.
4908 Returns the number of keyboard chars read, or -1 meaning
4909 this is a bad time to try to read input. */
4912 read_avail_input (expected
)
4915 struct input_event buf
[KBD_BUFFER_SIZE
];
4919 if (read_socket_hook
)
4920 /* No need for FIONREAD or fcntl; just say don't wait. */
4921 nread
= (*read_socket_hook
) (input_fd
, buf
, KBD_BUFFER_SIZE
, expected
);
4924 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
4925 the kbd_buffer can really hold. That may prevent loss
4926 of characters on some systems when input is stuffed at us. */
4927 unsigned char cbuf
[KBD_BUFFER_SIZE
- 1];
4930 /* Determine how many characters we should *try* to read. */
4933 #else /* not WINDOWSNT */
4935 n_to_read
= dos_keysns ();
4938 #else /* not MSDOS */
4940 /* Find out how much input is available. */
4941 if (ioctl (input_fd
, FIONREAD
, &n_to_read
) < 0)
4942 /* Formerly simply reported no input, but that sometimes led to
4943 a failure of Emacs to terminate.
4944 SIGHUP seems appropriate if we can't reach the terminal. */
4945 /* ??? Is it really right to send the signal just to this process
4946 rather than to the whole process group?
4947 Perhaps on systems with FIONREAD Emacs is alone in its group. */
4948 kill (getpid (), SIGHUP
);
4951 if (n_to_read
> sizeof cbuf
)
4952 n_to_read
= sizeof cbuf
;
4953 #else /* no FIONREAD */
4954 #if defined (USG) || defined (DGUX)
4955 /* Read some input if available, but don't wait. */
4956 n_to_read
= sizeof cbuf
;
4957 fcntl (input_fd
, F_SETFL
, O_NDELAY
);
4962 #endif /* not MSDOS */
4963 #endif /* not WINDOWSNT */
4965 /* Now read; for one reason or another, this will not block.
4966 NREAD is set to the number of chars read. */
4970 cbuf
[0] = dos_keyread ();
4973 nread
= read (input_fd
, cbuf
, n_to_read
);
4975 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
4976 /* The kernel sometimes fails to deliver SIGHUP for ptys.
4977 This looks incorrect, but it isn't, because _BSD causes
4978 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
4979 and that causes a value other than 0 when there is no input. */
4985 /* We used to retry the read if it was interrupted.
4986 But this does the wrong thing when O_NDELAY causes
4987 an EAGAIN error. Does anybody know of a situation
4988 where a retry is actually needed? */
4990 nread
< 0 && (errno
== EAGAIN
5004 #if defined (USG) || defined (DGUX)
5005 fcntl (input_fd
, F_SETFL
, 0);
5006 #endif /* USG or DGUX */
5007 #endif /* no FIONREAD */
5008 for (i
= 0; i
< nread
; i
++)
5010 buf
[i
].kind
= ascii_keystroke
;
5011 buf
[i
].modifiers
= 0;
5012 if (meta_key
== 1 && (cbuf
[i
] & 0x80))
5013 buf
[i
].modifiers
= meta_modifier
;
5017 buf
[i
].code
= cbuf
[i
];
5018 XSETFRAME (buf
[i
].frame_or_window
, selected_frame
);
5022 /* Scan the chars for C-g and store them in kbd_buffer. */
5023 for (i
= 0; i
< nread
; i
++)
5025 kbd_buffer_store_event (&buf
[i
]);
5026 /* Don't look at input that follows a C-g too closely.
5027 This reduces lossage due to autorepeat on C-g. */
5028 if (buf
[i
].kind
== ascii_keystroke
5029 && buf
[i
].code
== quit_char
)
5035 #endif /* not VMS */
5037 #ifdef SIGIO /* for entire page */
5038 /* Note SIGIO has been undef'd if FIONREAD is missing. */
5041 input_available_signal (signo
)
5044 /* Must preserve main program's value of errno. */
5045 int old_errno
= errno
;
5047 extern int select_alarmed
;
5050 #if defined (USG) && !defined (POSIX_SIGNALS)
5051 /* USG systems forget handlers when they are used;
5052 must reestablish each time */
5053 signal (signo
, input_available_signal
);
5060 if (input_available_clear_time
)
5061 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
5066 nread
= read_avail_input (1);
5067 /* -1 means it's not ok to read the input now.
5068 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
5069 0 means there was no keyboard input available. */
5074 select_alarmed
= 1; /* Force the select emulator back to life */
5085 /* Send ourselves a SIGIO.
5087 This function exists so that the UNBLOCK_INPUT macro in
5088 blockinput.h can have some way to take care of input we put off
5089 dealing with, without assuming that every file which uses
5090 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
5092 reinvoke_input_signal ()
5095 kill (getpid (), SIGIO
);
5101 /* Return the prompt-string of a sparse keymap.
5102 This is the first element which is a string.
5103 Return nil if there is none. */
5111 register Lisp_Object tem
;
5120 static void menu_bar_item ();
5121 static void menu_bar_one_keymap ();
5123 /* These variables hold the vector under construction within
5124 menu_bar_items and its subroutines, and the current index
5125 for storing into that vector. */
5126 static Lisp_Object menu_bar_items_vector
;
5127 static int menu_bar_items_index
;
5129 /* Return a vector of menu items for a menu bar, appropriate
5130 to the current buffer. Each item has three elements in the vector:
5133 OLD is an old vector we can optionally reuse, or nil. */
5136 menu_bar_items (old
)
5139 /* The number of keymaps we're scanning right now, and the number of
5140 keymaps we have allocated space for. */
5143 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
5144 in the current keymaps, or nil where it is not a prefix. */
5147 Lisp_Object def
, tem
, tail
;
5156 struct gcpro gcpro1
;
5158 /* In order to build the menus, we need to call the keymap
5159 accessors. They all call QUIT. But this function is called
5160 during redisplay, during which a quit is fatal. So inhibit
5161 quitting while building the menus.
5162 We do this instead of specbind because (1) errors will clear it anyway
5163 and (2) this avoids risk of specpdl overflow. */
5164 oquit
= Vinhibit_quit
;
5168 menu_bar_items_vector
= old
;
5170 menu_bar_items_vector
= Fmake_vector (make_number (24), Qnil
);
5171 menu_bar_items_index
= 0;
5173 GCPRO1 (menu_bar_items_vector
);
5175 /* Build our list of keymaps.
5176 If we recognize a function key and replace its escape sequence in
5177 keybuf with its symbol, or if the sequence starts with a mouse
5178 click and we need to switch buffers, we jump back here to rebuild
5179 the initial keymaps from the current buffer. */
5183 /* Should overriding-terminal-local-map and overriding-local-map apply? */
5184 if (!NILP (Voverriding_local_map_menu_flag
))
5186 /* Yes, use them (if non-nil) as well as the global map. */
5187 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
5189 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
5190 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
5191 if (!NILP (Voverriding_local_map
))
5192 maps
[nmaps
++] = Voverriding_local_map
;
5196 /* No, so use major and minor mode keymaps. */
5197 nmaps
= current_minor_maps (NULL
, &tmaps
);
5198 maps
= (Lisp_Object
*) alloca ((nmaps
+ 2) * sizeof (maps
[0]));
5199 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
5200 #ifdef USE_TEXT_PROPERTIES
5201 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
5203 maps
[nmaps
++] = current_buffer
->keymap
;
5206 maps
[nmaps
++] = current_global_map
;
5209 /* Look up in each map the dummy prefix key `menu-bar'. */
5213 for (mapno
= nmaps
- 1; mapno
>= 0; mapno
--)
5215 if (! NILP (maps
[mapno
]))
5216 def
= get_keyelt (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0));
5220 tem
= Fkeymapp (def
);
5222 menu_bar_one_keymap (def
);
5225 /* Move to the end those items that should be at the end. */
5227 for (tail
= Vmenu_bar_final_items
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5230 int end
= menu_bar_items_index
;
5232 for (i
= 0; i
< end
; i
+= 4)
5233 if (EQ (XCONS (tail
)->car
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
5235 Lisp_Object tem0
, tem1
, tem2
, tem3
;
5236 /* Move the item at index I to the end,
5237 shifting all the others forward. */
5238 tem0
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 0];
5239 tem1
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 1];
5240 tem2
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
5241 tem3
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3];
5243 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
5244 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
5245 (end
- i
- 4) * sizeof (Lisp_Object
));
5246 XVECTOR (menu_bar_items_vector
)->contents
[end
- 4] = tem0
;
5247 XVECTOR (menu_bar_items_vector
)->contents
[end
- 3] = tem1
;
5248 XVECTOR (menu_bar_items_vector
)->contents
[end
- 2] = tem2
;
5249 XVECTOR (menu_bar_items_vector
)->contents
[end
- 1] = tem3
;
5254 /* Add nil, nil, nil, nil at the end. */
5255 i
= menu_bar_items_index
;
5256 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
5259 int newsize
= 2 * i
;
5260 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
5261 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
5262 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
5263 menu_bar_items_vector
= tem
;
5265 /* Add this item. */
5266 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5267 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5268 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5269 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5270 menu_bar_items_index
= i
;
5272 Vinhibit_quit
= oquit
;
5274 return menu_bar_items_vector
;
5277 /* Scan one map KEYMAP, accumulating any menu items it defines
5278 in menu_bar_items_vector. */
5281 menu_bar_one_keymap (keymap
)
5284 Lisp_Object tail
, item
, key
, binding
, item_string
, table
;
5286 /* Loop over all keymap entries that have menu strings. */
5287 for (tail
= keymap
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5289 item
= XCONS (tail
)->car
;
5292 key
= XCONS (item
)->car
;
5293 binding
= XCONS (item
)->cdr
;
5294 if (CONSP (binding
))
5296 item_string
= XCONS (binding
)->car
;
5297 if (STRINGP (item_string
))
5298 menu_bar_item (key
, item_string
, Fcdr (binding
));
5300 else if (EQ (binding
, Qundefined
))
5301 menu_bar_item (key
, Qnil
, binding
);
5303 else if (VECTORP (item
))
5305 /* Loop over the char values represented in the vector. */
5306 int len
= XVECTOR (item
)->size
;
5308 for (c
= 0; c
< len
; c
++)
5310 Lisp_Object character
;
5311 XSETFASTINT (character
, c
);
5312 binding
= XVECTOR (item
)->contents
[c
];
5313 if (CONSP (binding
))
5315 item_string
= XCONS (binding
)->car
;
5316 if (STRINGP (item_string
))
5317 menu_bar_item (key
, item_string
, Fcdr (binding
));
5319 else if (EQ (binding
, Qundefined
))
5320 menu_bar_item (key
, Qnil
, binding
);
5326 /* This is used as the handler when calling internal_condition_case_1. */
5329 menu_bar_item_1 (arg
)
5335 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
5336 If there's already an item for KEY, add this DEF to it. */
5339 menu_bar_item (key
, item_string
, def
)
5340 Lisp_Object key
, item_string
, def
;
5343 Lisp_Object enabled
;
5346 /* Skip menu-bar equiv keys data. */
5347 if (CONSP (def
) && CONSP (XCONS (def
)->car
))
5348 def
= XCONS (def
)->cdr
;
5350 if (EQ (def
, Qundefined
))
5352 /* If a map has an explicit `undefined' as definition,
5353 discard any previously made menu bar item. */
5355 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
5356 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
5358 if (menu_bar_items_index
> i
+ 4)
5359 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
5360 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
5361 (menu_bar_items_index
- i
- 4) * sizeof (Lisp_Object
));
5362 menu_bar_items_index
-= 4;
5366 /* If there's no definition for this key yet,
5367 just ignore `undefined'. */
5371 /* See if this entry is enabled. */
5376 /* No property, or nil, means enable.
5377 Otherwise, enable if value is not nil. */
5378 tem
= Fget (def
, Qmenu_enable
);
5380 /* (condition-case nil (eval tem)
5382 enabled
= internal_condition_case_1 (Feval
, tem
, Qerror
,
5386 /* Ignore this item if it's not enabled. */
5390 /* Find any existing item for this KEY. */
5391 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
5392 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
5395 /* If we did not find this KEY, add it at the end. */
5396 if (i
== menu_bar_items_index
)
5398 /* If vector is too small, get a bigger one. */
5399 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
5402 int newsize
= 2 * i
;
5403 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
5404 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
5405 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
5406 menu_bar_items_vector
= tem
;
5408 /* Add this item. */
5409 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = key
;
5410 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = item_string
;
5411 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Fcons (def
, Qnil
);
5412 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = make_number (0);
5413 menu_bar_items_index
= i
;
5415 /* We did find an item for this KEY. Add DEF to its list of maps. */
5419 old
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
5420 XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2] = Fcons (def
, old
);
5424 /* Read a character using menus based on maps in the array MAPS.
5425 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
5426 Return t if we displayed a menu but the user rejected it.
5428 PREV_EVENT is the previous input event, or nil if we are reading
5429 the first event of a key sequence.
5431 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
5432 if we used a mouse menu to read the input, or zero otherwise. If
5433 USED_MOUSE_MENU is null, we don't dereference it.
5435 The prompting is done based on the prompt-string of the map
5436 and the strings associated with various map elements.
5438 This can be done with X menus or with menus put in the minibuf.
5439 These are done in different ways, depending on how the input will be read.
5440 Menus using X are done after auto-saving in read-char, getting the input
5441 event from Fx_popup_menu; menus using the minibuf use read_char recursively
5442 and do auto-saving in the inner call of read_char. */
5445 read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
5448 Lisp_Object prev_event
;
5449 int *used_mouse_menu
;
5452 register Lisp_Object name
;
5453 Lisp_Object rest
, vector
;
5455 if (used_mouse_menu
)
5456 *used_mouse_menu
= 0;
5458 /* Use local over global Menu maps */
5460 if (! menu_prompting
)
5463 /* Optionally disregard all but the global map. */
5464 if (inhibit_local_menu_bar_menus
)
5466 maps
+= (nmaps
- 1);
5470 /* Get the menu name from the first map that has one (a prompt string). */
5471 for (mapno
= 0; mapno
< nmaps
; mapno
++)
5473 name
= map_prompt (maps
[mapno
]);
5478 /* If we don't have any menus, just read a character normally. */
5483 /* If we got to this point via a mouse click,
5484 use a real menu for mouse selection. */
5485 if (EVENT_HAS_PARAMETERS (prev_event
)
5486 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
))
5488 /* Display the menu and get the selection. */
5489 Lisp_Object
*realmaps
5490 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
5494 /* Use the maps that are not nil. */
5495 for (mapno
= 0; mapno
< nmaps
; mapno
++)
5496 if (!NILP (maps
[mapno
]))
5497 realmaps
[nmaps1
++] = maps
[mapno
];
5499 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
5504 record_menu_key (XCONS (value
)->car
);
5506 /* If we got multiple events, unread all but
5508 There is no way to prevent those unread events
5509 from showing up later in last_nonmenu_event.
5510 So turn symbol and integer events into lists,
5511 to indicate that they came from a mouse menu,
5512 so that when present in last_nonmenu_event
5513 they won't confuse things. */
5514 for (tem
= XCONS (value
)->cdr
; !NILP (tem
);
5515 tem
= XCONS (tem
)->cdr
)
5517 record_menu_key (XCONS (tem
)->car
);
5518 if (SYMBOLP (XCONS (tem
)->car
)
5519 || INTEGERP (XCONS (tem
)->car
))
5521 = Fcons (XCONS (tem
)->car
, Qnil
);
5524 /* If we got more than one event, put all but the first
5525 onto this list to be read later.
5526 Return just the first event now. */
5527 Vunread_command_events
5528 = nconc2 (XCONS (value
)->cdr
, Vunread_command_events
);
5529 value
= XCONS (value
)->car
;
5531 else if (NILP (value
))
5533 if (used_mouse_menu
)
5534 *used_mouse_menu
= 1;
5537 #endif /* HAVE_MENUS */
5541 /* Buffer in use so far for the minibuf prompts for menu keymaps.
5542 We make this bigger when necessary, and never free it. */
5543 static char *read_char_minibuf_menu_text
;
5544 /* Size of that buffer. */
5545 static int read_char_minibuf_menu_width
;
5548 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
5554 register Lisp_Object name
;
5556 int width
= FRAME_WIDTH (selected_frame
) - 4;
5559 Lisp_Object rest
, vector
;
5562 if (! menu_prompting
)
5565 /* Make sure we have a big enough buffer for the menu text. */
5566 if (read_char_minibuf_menu_text
== 0)
5568 read_char_minibuf_menu_width
= width
+ 4;
5569 read_char_minibuf_menu_text
= (char *) xmalloc (width
+ 4);
5571 else if (width
+ 4 > read_char_minibuf_menu_width
)
5573 read_char_minibuf_menu_width
= width
+ 4;
5574 read_char_minibuf_menu_text
5575 = (char *) xrealloc (read_char_minibuf_menu_text
, width
+ 4);
5577 menu
= read_char_minibuf_menu_text
;
5579 /* Get the menu name from the first map that has one (a prompt string). */
5580 for (mapno
= 0; mapno
< nmaps
; mapno
++)
5582 name
= map_prompt (maps
[mapno
]);
5587 /* If we don't have any menus, just read a character normally. */
5591 /* Prompt string always starts with map's prompt, and a space. */
5592 strcpy (menu
, XSTRING (name
)->data
);
5593 nlength
= XSTRING (name
)->size
;
5594 menu
[nlength
++] = ':';
5595 menu
[nlength
++] = ' ';
5598 /* Start prompting at start of first map. */
5602 /* Present the documented bindings, a line at a time. */
5609 Lisp_Object orig_defn_macro
;
5611 /* Loop over elements of map. */
5616 /* If reached end of map, start at beginning of next map. */
5620 /* At end of last map, wrap around to first map if just starting,
5621 or end this line if already have something on it. */
5625 if (notfirst
|| nobindings
) break;
5630 /* Look at the next element of the map. */
5632 elt
= XVECTOR (vector
)->contents
[idx
];
5634 elt
= Fcar_safe (rest
);
5636 if (idx
< 0 && VECTORP (elt
))
5638 /* If we found a dense table in the keymap,
5639 advanced past it, but start scanning its contents. */
5640 rest
= Fcdr_safe (rest
);
5646 /* An ordinary element. */
5651 s
= Fcar_safe (Fcdr_safe (elt
)); /* alist */
5652 event
= Fcar_safe (elt
);
5656 s
= Fcar_safe (elt
); /* vector */
5657 XSETINT (event
, idx
);
5660 /* Ignore the element if it has no prompt string. */
5661 if (STRINGP (s
) && INTEGERP (event
))
5663 /* 1 if the char to type matches the string. */
5665 Lisp_Object upcased_event
, downcased_event
;
5668 upcased_event
= Fupcase (event
);
5669 downcased_event
= Fdowncase (event
);
5670 char_matches
= (XINT (upcased_event
) == XSTRING (s
)->data
[0]
5671 || XINT (downcased_event
) == XSTRING (s
)->data
[0]);
5673 desc
= Fsingle_key_description (event
);
5675 /* If we have room for the prompt string, add it to this line.
5676 If this is the first on the line, always add it. */
5677 if ((XSTRING (s
)->size
+ i
+ 2
5678 + (char_matches
? 0 : XSTRING (desc
)->size
+ 3))
5684 /* Punctuate between strings. */
5687 strcpy (menu
+ i
, ", ");
5693 /* If the char to type doesn't match the string's
5694 first char, explicitly show what char to type. */
5697 /* Add as much of string as fits. */
5698 thiswidth
= XSTRING (desc
)->size
;
5699 if (thiswidth
+ i
> width
)
5700 thiswidth
= width
- i
;
5701 bcopy (XSTRING (desc
)->data
, menu
+ i
, thiswidth
);
5703 strcpy (menu
+ i
, " = ");
5707 /* Add as much of string as fits. */
5708 thiswidth
= XSTRING (s
)->size
;
5709 if (thiswidth
+ i
> width
)
5710 thiswidth
= width
- i
;
5711 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
5717 /* If this element does not fit, end the line now,
5718 and save the element for the next line. */
5719 strcpy (menu
+ i
, "...");
5724 /* Move past this element. */
5725 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
5726 /* Handle reaching end of dense table. */
5731 rest
= Fcdr_safe (rest
);
5735 /* Prompt with that and read response. */
5738 /* Make believe its not a keyboard macro in case the help char
5739 is pressed. Help characters are not recorded because menu prompting
5740 is not used on replay.
5742 orig_defn_macro
= current_kboard
->defining_kbd_macro
;
5743 current_kboard
->defining_kbd_macro
= Qnil
;
5745 obj
= read_char (commandflag
, 0, 0, Qnil
, 0);
5746 while (BUFFERP (obj
));
5747 current_kboard
->defining_kbd_macro
= orig_defn_macro
;
5749 if (!INTEGERP (obj
))
5754 if (! EQ (obj
, menu_prompt_more_char
)
5755 && (!INTEGERP (menu_prompt_more_char
)
5756 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
5758 if (!NILP (current_kboard
->defining_kbd_macro
))
5759 store_kbd_macro_char (obj
);
5762 /* Help char - go round again */
5766 /* Reading key sequences. */
5768 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
5769 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
5770 keymap, or nil otherwise. Return the index of the first keymap in
5771 which KEY has any binding, or NMAPS if no map has a binding.
5773 If KEY is a meta ASCII character, treat it like meta-prefix-char
5774 followed by the corresponding non-meta character. Keymaps in
5775 CURRENT with non-prefix bindings for meta-prefix-char become nil in
5778 If KEY has no bindings in any of the CURRENT maps, NEXT is left
5781 NEXT may be the same array as CURRENT. */
5784 follow_key (key
, nmaps
, current
, defs
, next
)
5786 Lisp_Object
*current
, *defs
, *next
;
5789 int i
, first_binding
;
5792 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
5793 followed by the corresponding non-meta character.
5794 Put the results into DEFS, since we are going to alter that anyway.
5795 Do not alter CURRENT or NEXT. */
5796 if (INTEGERP (key
) && (XINT (key
) & CHAR_META
))
5798 for (i
= 0; i
< nmaps
; i
++)
5799 if (! NILP (current
[i
]))
5802 def
= get_keyelt (access_keymap (current
[i
],
5803 meta_prefix_char
, 1, 0));
5805 /* Note that since we pass the resulting bindings through
5806 get_keymap_1, non-prefix bindings for meta-prefix-char
5808 defs
[i
] = get_keymap_1 (def
, 0, 1);
5814 XSETINT (key
, XFASTINT (key
) & ~CHAR_META
);
5817 first_binding
= nmaps
;
5818 for (i
= nmaps
- 1; i
>= 0; i
--)
5820 if (! NILP (current
[i
]))
5828 defs
[i
] = get_keyelt (access_keymap (map
, key
, 1, 0));
5829 if (! NILP (defs
[i
]))
5836 /* Given the set of bindings we've found, produce the next set of maps. */
5837 if (first_binding
< nmaps
)
5838 for (i
= 0; i
< nmaps
; i
++)
5839 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0, 1);
5841 return first_binding
;
5844 /* Read a sequence of keys that ends with a non prefix character,
5845 storing it in KEYBUF, a buffer of size BUFSIZE.
5847 Return the length of the key sequence stored.
5848 Return -1 if the user rejected a command menu.
5850 Echo starting immediately unless `prompt' is 0.
5852 Where a key sequence ends depends on the currently active keymaps.
5853 These include any minor mode keymaps active in the current buffer,
5854 the current buffer's local map, and the global map.
5856 If a key sequence has no other bindings, we check Vfunction_key_map
5857 to see if some trailing subsequence might be the beginning of a
5858 function key's sequence. If so, we try to read the whole function
5859 key, and substitute its symbolic name into the key sequence.
5861 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
5862 `double-' events into similar click events, if that would make them
5863 bound. We try to turn `triple-' events first into `double-' events,
5866 If we get a mouse click in a mode line, vertical divider, or other
5867 non-text area, we treat the click as if it were prefixed by the
5868 symbol denoting that area - `mode-line', `vertical-line', or
5871 If the sequence starts with a mouse click, we read the key sequence
5872 with respect to the buffer clicked on, not the current buffer.
5874 If the user switches frames in the midst of a key sequence, we put
5875 off the switch-frame event until later; the next call to
5876 read_char will return it. */
5879 read_key_sequence (keybuf
, bufsize
, prompt
, dont_downcase_last
,
5880 can_return_switch_frame
)
5881 Lisp_Object
*keybuf
;
5884 int dont_downcase_last
;
5885 int can_return_switch_frame
;
5887 int count
= specpdl_ptr
- specpdl
;
5889 /* How many keys there are in the current key sequence. */
5892 /* The length of the echo buffer when we started reading, and
5893 the length of this_command_keys when we started reading. */
5897 /* The number of keymaps we're scanning right now, and the number of
5898 keymaps we have allocated space for. */
5900 int nmaps_allocated
= 0;
5902 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
5903 the current keymaps. */
5906 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
5907 in the current keymaps, or nil where it is not a prefix. */
5908 Lisp_Object
*submaps
;
5910 /* The local map to start out with at start of key sequence. */
5911 Lisp_Object orig_local_map
;
5913 /* 1 if we have already considered switching to the local-map property
5914 of the place where a mouse click occurred. */
5915 int localized_local_map
= 0;
5917 /* The index in defs[] of the first keymap that has a binding for
5918 this key sequence. In other words, the lowest i such that
5919 defs[i] is non-nil. */
5922 /* If t < mock_input, then KEYBUF[t] should be read as the next
5925 We use this to recover after recognizing a function key. Once we
5926 realize that a suffix of the current key sequence is actually a
5927 function key's escape sequence, we replace the suffix with the
5928 function key's binding from Vfunction_key_map. Now keybuf
5929 contains a new and different key sequence, so the echo area,
5930 this_command_keys, and the submaps and defs arrays are wrong. In
5931 this situation, we set mock_input to t, set t to 0, and jump to
5932 restart_sequence; the loop will read keys from keybuf up until
5933 mock_input, thus rebuilding the state; and then it will resume
5934 reading characters from the keyboard. */
5937 /* If the sequence is unbound in submaps[], then
5938 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
5939 and fkey_map is its binding.
5941 These might be > t, indicating that all function key scanning
5942 should hold off until t reaches them. We do this when we've just
5943 recognized a function key, to avoid searching for the function
5944 key's again in Vfunction_key_map. */
5945 int fkey_start
= 0, fkey_end
= 0;
5946 Lisp_Object fkey_map
;
5948 /* Likewise, for key_translation_map. */
5949 int keytran_start
= 0, keytran_end
= 0;
5950 Lisp_Object keytran_map
;
5952 /* If we receive a ``switch-frame'' event in the middle of a key sequence,
5953 we put it off for later. While we're reading, we keep the event here. */
5954 Lisp_Object delayed_switch_frame
;
5956 /* See the comment below... */
5957 #if defined (GOBBLE_FIRST_EVENT)
5958 Lisp_Object first_event
;
5961 Lisp_Object original_uppercase
;
5962 int original_uppercase_position
= -1;
5964 /* Gets around Microsoft compiler limitations. */
5967 struct buffer
*starting_buffer
;
5969 /* Nonzero if we seem to have got the beginning of a binding
5970 in function_key_map. */
5971 int function_key_possible
= 0;
5972 int key_translation_possible
= 0;
5974 /* Save the status of key translation before each step,
5975 so that we can restore this after downcasing. */
5976 Lisp_Object prev_fkey_map
;
5977 Lisp_Object prev_fkey_start
;
5978 Lisp_Object prev_fkey_end
;
5980 Lisp_Object prev_keytran_map
;
5981 Lisp_Object prev_keytran_start
;
5982 Lisp_Object prev_keytran_end
;
5986 last_nonmenu_event
= Qnil
;
5988 delayed_switch_frame
= Qnil
;
5989 fkey_map
= Vfunction_key_map
;
5990 keytran_map
= Vkey_translation_map
;
5992 /* If there is no function-key-map, turn off function key scanning. */
5993 if (NILP (Fkeymapp (Vfunction_key_map
)))
5994 fkey_start
= fkey_end
= bufsize
+ 1;
5996 /* If there is no key-translation-map, turn off scanning. */
5997 if (NILP (Fkeymapp (Vkey_translation_map
)))
5998 keytran_start
= keytran_end
= bufsize
+ 1;
6003 echo_prompt (XSTRING (prompt
)->data
);
6004 else if (cursor_in_echo_area
&& echo_keystrokes
)
6005 /* This doesn't put in a dash if the echo buffer is empty, so
6006 you don't always see a dash hanging out in the minibuffer. */
6010 /* Record the initial state of the echo area and this_command_keys;
6011 we will need to restore them if we replay a key sequence. */
6013 echo_start
= echo_length ();
6014 keys_start
= this_command_key_count
;
6015 this_single_command_key_start
= keys_start
;
6017 #if defined (GOBBLE_FIRST_EVENT)
6018 /* This doesn't quite work, because some of the things that read_char
6019 does cannot safely be bypassed. It seems too risky to try to make
6022 /* Read the first char of the sequence specially, before setting
6023 up any keymaps, in case a filter runs and switches buffers on us. */
6024 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
6026 #endif /* GOBBLE_FIRST_EVENT */
6028 orig_local_map
= get_local_map (PT
, current_buffer
);
6030 /* We jump here when the key sequence has been thoroughly changed, and
6031 we need to rescan it starting from the beginning. When we jump here,
6032 keybuf[0..mock_input] holds the sequence we should reread. */
6035 starting_buffer
= current_buffer
;
6036 function_key_possible
= 0;
6037 key_translation_possible
= 0;
6039 /* Build our list of keymaps.
6040 If we recognize a function key and replace its escape sequence in
6041 keybuf with its symbol, or if the sequence starts with a mouse
6042 click and we need to switch buffers, we jump back here to rebuild
6043 the initial keymaps from the current buffer. */
6047 if (!NILP (current_kboard
->Voverriding_terminal_local_map
)
6048 || !NILP (Voverriding_local_map
))
6050 if (3 > nmaps_allocated
)
6052 submaps
= (Lisp_Object
*) alloca (3 * sizeof (submaps
[0]));
6053 defs
= (Lisp_Object
*) alloca (3 * sizeof (defs
[0]));
6054 nmaps_allocated
= 3;
6057 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
6058 submaps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
6059 if (!NILP (Voverriding_local_map
))
6060 submaps
[nmaps
++] = Voverriding_local_map
;
6064 nmaps
= current_minor_maps (0, &maps
);
6065 if (nmaps
+ 2 > nmaps_allocated
)
6067 submaps
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (submaps
[0]));
6068 defs
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (defs
[0]));
6069 nmaps_allocated
= nmaps
+ 2;
6071 bcopy (maps
, submaps
, nmaps
* sizeof (submaps
[0]));
6072 #ifdef USE_TEXT_PROPERTIES
6073 submaps
[nmaps
++] = orig_local_map
;
6075 submaps
[nmaps
++] = current_buffer
->keymap
;
6078 submaps
[nmaps
++] = current_global_map
;
6081 /* Find an accurate initial value for first_binding. */
6082 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
6083 if (! NILP (submaps
[first_binding
]))
6086 /* Start from the beginning in keybuf. */
6089 /* These are no-ops the first time through, but if we restart, they
6090 revert the echo area and this_command_keys to their original state. */
6091 this_command_key_count
= keys_start
;
6092 if (INTERACTIVE
&& t
< mock_input
)
6093 echo_truncate (echo_start
);
6095 /* If the best binding for the current key sequence is a keymap, or
6096 we may be looking at a function key's escape sequence, keep on
6098 while ((first_binding
< nmaps
&& ! NILP (submaps
[first_binding
]))
6099 || (first_binding
>= nmaps
6101 /* mock input is never part of a function key's sequence. */
6102 && mock_input
<= fkey_start
)
6103 || (first_binding
>= nmaps
6104 && keytran_start
< t
&& key_translation_possible
)
6105 /* Don't return in the middle of a possible function key sequence,
6106 if the only bindings we found were via case conversion.
6107 Thus, if ESC O a has a function-key-map translation
6108 and ESC o has a binding, don't return after ESC O,
6109 so that we can translate ESC O plus the next character. */
6113 int used_mouse_menu
= 0;
6115 /* Where the last real key started. If we need to throw away a
6116 key that has expanded into more than one element of keybuf
6117 (say, a mouse click on the mode line which is being treated
6118 as [mode-line (mouse-...)], then we backtrack to this point
6120 int last_real_key_start
;
6122 /* These variables are analogous to echo_start and keys_start;
6123 while those allow us to restart the entire key sequence,
6124 echo_local_start and keys_local_start allow us to throw away
6126 int echo_local_start
, keys_local_start
, local_first_binding
;
6129 error ("Key sequence too long");
6132 echo_local_start
= echo_length ();
6133 keys_local_start
= this_command_key_count
;
6134 local_first_binding
= first_binding
;
6137 /* These are no-ops, unless we throw away a keystroke below and
6138 jumped back up to replay_key; in that case, these restore the
6139 variables to their original state, allowing us to replay the
6141 if (INTERACTIVE
&& t
< mock_input
)
6142 echo_truncate (echo_local_start
);
6143 this_command_key_count
= keys_local_start
;
6144 first_binding
= local_first_binding
;
6146 /* By default, assume each event is "real". */
6147 last_real_key_start
= t
;
6149 /* Does mock_input indicate that we are re-reading a key sequence? */
6153 add_command_key (key
);
6154 if (echo_keystrokes
)
6158 /* If not, we should actually read a character. */
6161 struct buffer
*buf
= current_buffer
;
6165 KBOARD
*interrupted_kboard
= current_kboard
;
6166 struct frame
*interrupted_frame
= selected_frame
;
6167 if (setjmp (wrong_kboard_jmpbuf
))
6169 if (!NILP (delayed_switch_frame
))
6171 interrupted_kboard
->kbd_queue
6172 = Fcons (delayed_switch_frame
,
6173 interrupted_kboard
->kbd_queue
);
6174 delayed_switch_frame
= Qnil
;
6177 interrupted_kboard
->kbd_queue
6178 = Fcons (keybuf
[--t
], interrupted_kboard
->kbd_queue
);
6180 /* If the side queue is non-empty, ensure it begins with a
6181 switch-frame, so we'll replay it in the right context. */
6182 if (CONSP (interrupted_kboard
->kbd_queue
)
6183 && (key
= XCONS (interrupted_kboard
->kbd_queue
)->car
,
6184 !(EVENT_HAS_PARAMETERS (key
)
6185 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)),
6189 XSETFRAME (frame
, interrupted_frame
);
6190 interrupted_kboard
->kbd_queue
6191 = Fcons (make_lispy_switch_frame (frame
),
6192 interrupted_kboard
->kbd_queue
);
6195 orig_local_map
= get_local_map (PT
, current_buffer
);
6196 goto replay_sequence
;
6199 key
= read_char (NILP (prompt
), nmaps
, submaps
, last_nonmenu_event
,
6203 /* read_char returns t when it shows a menu and the user rejects it.
6208 /* read_char returns -1 at the end of a macro.
6209 Emacs 18 handles this by returning immediately with a
6210 zero, so that's what we'll do. */
6211 if (INTEGERP (key
) && XINT (key
) == -1)
6214 /* The Microsoft C compiler can't handle the goto that
6220 /* If the current buffer has been changed from under us, the
6221 keymap may have changed, so replay the sequence. */
6225 orig_local_map
= get_local_map (PT
, current_buffer
);
6226 goto replay_sequence
;
6229 /* If we have a quit that was typed in another frame, and
6230 quit_throw_to_read_char switched buffers,
6231 replay to get the right keymap. */
6232 if (XINT (key
) == quit_char
&& current_buffer
!= starting_buffer
)
6237 orig_local_map
= get_local_map (PT
, current_buffer
);
6238 goto replay_sequence
;
6244 /* Clicks in non-text areas get prefixed by the symbol
6245 in their CHAR-ADDRESS field. For example, a click on
6246 the mode line is prefixed by the symbol `mode-line'.
6248 Furthermore, key sequences beginning with mouse clicks
6249 are read using the keymaps of the buffer clicked on, not
6250 the current buffer. So we may have to switch the buffer
6253 When we turn one event into two events, we must make sure
6254 that neither of the two looks like the original--so that,
6255 if we replay the events, they won't be expanded again.
6256 If not for this, such reexpansion could happen either here
6257 or when user programs play with this-command-keys. */
6258 if (EVENT_HAS_PARAMETERS (key
))
6262 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
6263 if (EQ (kind
, Qmouse_click
))
6265 Lisp_Object window
, posn
;
6267 window
= POSN_WINDOW (EVENT_START (key
));
6268 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
6271 /* We're looking at the second event of a
6272 sequence which we expanded before. Set
6273 last_real_key_start appropriately. */
6275 last_real_key_start
= t
- 1;
6278 /* Key sequences beginning with mouse clicks are
6279 read using the keymaps in the buffer clicked on,
6280 not the current buffer. If we're at the
6281 beginning of a key sequence, switch buffers. */
6282 if (last_real_key_start
== 0
6284 && BUFFERP (XWINDOW (window
)->buffer
)
6285 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
6290 /* Arrange to go back to the original buffer once we're
6291 done reading the key sequence. Note that we can't
6292 use save_excursion_{save,restore} here, because they
6293 save point as well as the current buffer; we don't
6294 want to save point, because redisplay may change it,
6295 to accommodate a Fset_window_start or something. We
6296 don't want to do this at the top of the function,
6297 because we may get input from a subprocess which
6298 wants to change the selected window and stuff (say,
6300 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
6302 set_buffer_internal (XBUFFER (XWINDOW (window
)->buffer
));
6303 orig_local_map
= get_local_map (PT
, current_buffer
);
6304 goto replay_sequence
;
6306 /* For a mouse click, get the local text-property keymap
6307 of the place clicked on, rather than point. */
6308 if (last_real_key_start
== 0 && CONSP (XCONS (key
)->cdr
)
6309 && ! localized_local_map
)
6311 Lisp_Object map_here
, start
, pos
;
6313 localized_local_map
= 1;
6314 start
= EVENT_START (key
);
6315 if (CONSP (start
) && CONSP (XCONS (start
)->cdr
))
6317 pos
= POSN_BUFFER_POSN (start
);
6319 && XINT (pos
) >= BEG
&& XINT (pos
) <= Z
)
6321 map_here
= get_local_map (XINT (pos
), current_buffer
);
6322 if (!EQ (map_here
, orig_local_map
))
6324 orig_local_map
= map_here
;
6328 goto replay_sequence
;
6334 /* Expand mode-line and scroll-bar events into two events:
6335 use posn as a fake prefix key. */
6338 if (t
+ 1 >= bufsize
)
6339 error ("Key sequence too long");
6344 /* Zap the position in key, so we know that we've
6345 expanded it, and don't try to do so again. */
6346 POSN_BUFFER_POSN (EVENT_START (key
))
6347 = Fcons (posn
, Qnil
);
6351 else if (EQ (kind
, Qswitch_frame
))
6353 /* If we're at the beginning of a key sequence, and the caller
6354 says it's okay, go ahead and return this event. If we're
6355 in the midst of a key sequence, delay it until the end. */
6356 if (t
> 0 || !can_return_switch_frame
)
6358 delayed_switch_frame
= key
;
6362 else if (CONSP (XCONS (key
)->cdr
)
6363 && CONSP (EVENT_START (key
))
6364 && CONSP (XCONS (EVENT_START (key
))->cdr
))
6368 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
6369 /* Handle menu-bar events:
6370 insert the dummy prefix event `menu-bar'. */
6371 if (EQ (posn
, Qmenu_bar
))
6373 if (t
+ 1 >= bufsize
)
6374 error ("Key sequence too long");
6378 /* Zap the position in key, so we know that we've
6379 expanded it, and don't try to do so again. */
6380 POSN_BUFFER_POSN (EVENT_START (key
))
6381 = Fcons (posn
, Qnil
);
6384 goto replay_sequence
;
6386 else if (CONSP (posn
))
6388 /* We're looking at the second event of a
6389 sequence which we expanded before. Set
6390 last_real_key_start appropriately. */
6391 if (last_real_key_start
== t
&& t
> 0)
6392 last_real_key_start
= t
- 1;
6397 /* We have finally decided that KEY is something we might want
6399 first_binding
= (follow_key (key
,
6400 nmaps
- first_binding
,
6401 submaps
+ first_binding
,
6402 defs
+ first_binding
,
6403 submaps
+ first_binding
)
6406 /* If KEY wasn't bound, we'll try some fallbacks. */
6407 if (first_binding
>= nmaps
)
6411 head
= EVENT_HEAD (key
);
6412 if (help_char_p (head
) && t
> 0)
6414 read_key_sequence_cmd
= Vprefix_help_command
;
6416 last_nonmenu_event
= key
;
6417 /* The Microsoft C compiler can't handle the goto that
6425 Lisp_Object breakdown
;
6428 breakdown
= parse_modifiers (head
);
6429 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
6430 /* Attempt to reduce an unbound mouse event to a simpler
6431 event that is bound:
6432 Drags reduce to clicks.
6433 Double-clicks reduce to clicks.
6434 Triple-clicks reduce to double-clicks, then to clicks.
6435 Down-clicks are eliminated.
6436 Double-downs reduce to downs, then are eliminated.
6437 Triple-downs reduce to double-downs, then to downs,
6438 then are eliminated. */
6439 if (modifiers
& (down_modifier
| drag_modifier
6440 | double_modifier
| triple_modifier
))
6442 while (modifiers
& (down_modifier
| drag_modifier
6443 | double_modifier
| triple_modifier
))
6445 Lisp_Object new_head
, new_click
;
6446 if (modifiers
& triple_modifier
)
6447 modifiers
^= (double_modifier
| triple_modifier
);
6448 else if (modifiers
& double_modifier
)
6449 modifiers
&= ~double_modifier
;
6450 else if (modifiers
& drag_modifier
)
6451 modifiers
&= ~drag_modifier
;
6454 /* Dispose of this `down' event by simply jumping
6455 back to replay_key, to get another event.
6457 Note that if this event came from mock input,
6458 then just jumping back to replay_key will just
6459 hand it to us again. So we have to wipe out any
6462 We could delete keybuf[t] and shift everything
6463 after that to the left by one spot, but we'd also
6464 have to fix up any variable that points into
6465 keybuf, and shifting isn't really necessary
6468 Adding prefixes for non-textual mouse clicks
6469 creates two characters of mock input, and both
6470 must be thrown away. If we're only looking at
6471 the prefix now, we can just jump back to
6472 replay_key. On the other hand, if we've already
6473 processed the prefix, and now the actual click
6474 itself is giving us trouble, then we've lost the
6475 state of the keymaps we want to backtrack to, and
6476 we need to replay the whole sequence to rebuild
6479 Beyond that, only function key expansion could
6480 create more than two keys, but that should never
6481 generate mouse events, so it's okay to zero
6482 mock_input in that case too.
6484 Isn't this just the most wonderful code ever? */
6485 if (t
== last_real_key_start
)
6492 mock_input
= last_real_key_start
;
6493 goto replay_sequence
;
6498 = apply_modifiers (modifiers
, XCONS (breakdown
)->car
);
6500 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
6502 /* Look for a binding for this new key. follow_key
6503 promises that it didn't munge submaps the
6504 last time we called it, since key was unbound. */
6506 = (follow_key (new_click
,
6507 nmaps
- local_first_binding
,
6508 submaps
+ local_first_binding
,
6509 defs
+ local_first_binding
,
6510 submaps
+ local_first_binding
)
6511 + local_first_binding
);
6513 /* If that click is bound, go for it. */
6514 if (first_binding
< nmaps
)
6519 /* Otherwise, we'll leave key set to the drag event. */
6526 /* Normally, last_nonmenu_event gets the previous key we read.
6527 But when a mouse popup menu is being used,
6528 we don't update last_nonmenu_event; it continues to hold the mouse
6529 event that preceded the first level of menu. */
6530 if (!used_mouse_menu
)
6531 last_nonmenu_event
= key
;
6533 /* Record what part of this_command_keys is the current key sequence. */
6534 this_single_command_key_start
= this_command_key_count
- t
;
6536 prev_fkey_map
= fkey_map
;
6537 prev_fkey_start
= fkey_start
;
6538 prev_fkey_end
= fkey_end
;
6540 prev_keytran_map
= keytran_map
;
6541 prev_keytran_start
= keytran_start
;
6542 prev_keytran_end
= keytran_end
;
6544 /* If the sequence is unbound, see if we can hang a function key
6545 off the end of it. We only want to scan real keyboard input
6546 for function key sequences, so if mock_input says that we're
6547 re-reading old events, don't examine it. */
6548 if (first_binding
>= nmaps
6551 Lisp_Object fkey_next
;
6553 /* Continue scan from fkey_end until we find a bound suffix.
6554 If we fail, increment fkey_start
6555 and start fkey_end from there. */
6556 while (fkey_end
< t
)
6560 key
= keybuf
[fkey_end
++];
6561 /* Look up meta-characters by prefixing them
6562 with meta_prefix_char. I hate this. */
6563 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
6568 (access_keymap (fkey_map
, meta_prefix_char
, 1, 0)),
6570 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
6573 fkey_next
= fkey_map
;
6576 = get_keyelt (access_keymap (fkey_next
, key
, 1, 0));
6578 #if 0 /* I didn't turn this on, because it might cause trouble
6579 for the mapping of return into C-m and tab into C-i. */
6580 /* Optionally don't map function keys into other things.
6581 This enables the user to redefine kp- keys easily. */
6582 if (SYMBOLP (key
) && !NILP (Vinhibit_function_key_mapping
))
6586 /* If the function key map gives a function, not an
6587 array, then call the function with no args and use
6588 its value instead. */
6589 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
6592 struct gcpro gcpro1
, gcpro2
, gcpro3
;
6596 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
6597 fkey_next
= call1 (fkey_next
, prompt
);
6599 /* If the function returned something invalid,
6600 barf--don't ignore it.
6601 (To ignore it safely, we would need to gcpro a bunch of
6602 other variables.) */
6603 if (! (VECTORP (fkey_next
) || STRINGP (fkey_next
)))
6604 error ("Function in key-translation-map returns invalid key sequence");
6607 function_key_possible
= ! NILP (fkey_next
);
6609 /* If keybuf[fkey_start..fkey_end] is bound in the
6610 function key map and it's a suffix of the current
6611 sequence (i.e. fkey_end == t), replace it with
6612 the binding and restart with fkey_start at the end. */
6613 if ((VECTORP (fkey_next
) || STRINGP (fkey_next
))
6616 int len
= XFASTINT (Flength (fkey_next
));
6618 t
= fkey_start
+ len
;
6620 error ("Key sequence too long");
6622 if (VECTORP (fkey_next
))
6623 bcopy (XVECTOR (fkey_next
)->contents
,
6624 keybuf
+ fkey_start
,
6625 (t
- fkey_start
) * sizeof (keybuf
[0]));
6626 else if (STRINGP (fkey_next
))
6630 for (i
= 0; i
< len
; i
++)
6631 XSETFASTINT (keybuf
[fkey_start
+ i
],
6632 XSTRING (fkey_next
)->data
[i
]);
6636 fkey_start
= fkey_end
= t
;
6637 fkey_map
= Vfunction_key_map
;
6639 /* Do pass the results through key-translation-map. */
6640 keytran_start
= keytran_end
= 0;
6641 keytran_map
= Vkey_translation_map
;
6643 goto replay_sequence
;
6646 fkey_map
= get_keymap_1 (fkey_next
, 0, 1);
6648 /* If we no longer have a bound suffix, try a new positions for
6650 if (NILP (fkey_map
))
6652 fkey_end
= ++fkey_start
;
6653 fkey_map
= Vfunction_key_map
;
6654 function_key_possible
= 0;
6659 /* Look for this sequence in key-translation-map. */
6661 Lisp_Object keytran_next
;
6663 /* Scan from keytran_end until we find a bound suffix. */
6664 while (keytran_end
< t
)
6668 key
= keybuf
[keytran_end
++];
6669 /* Look up meta-characters by prefixing them
6670 with meta_prefix_char. I hate this. */
6671 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
6676 (access_keymap (keytran_map
, meta_prefix_char
, 1, 0)),
6678 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
6681 keytran_next
= keytran_map
;
6684 = get_keyelt (access_keymap (keytran_next
, key
, 1, 0));
6686 /* If the key translation map gives a function, not an
6687 array, then call the function with no args and use
6688 its value instead. */
6689 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
6690 && keytran_end
== t
)
6692 struct gcpro gcpro1
, gcpro2
, gcpro3
;
6696 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
6697 keytran_next
= call1 (keytran_next
, prompt
);
6699 /* If the function returned something invalid,
6700 barf--don't ignore it.
6701 (To ignore it safely, we would need to gcpro a bunch of
6702 other variables.) */
6703 if (! (VECTORP (keytran_next
) || STRINGP (keytran_next
)))
6704 error ("Function in key-translation-map returns invalid key sequence");
6707 key_translation_possible
= ! NILP (keytran_next
);
6709 /* If keybuf[keytran_start..keytran_end] is bound in the
6710 key translation map and it's a suffix of the current
6711 sequence (i.e. keytran_end == t), replace it with
6712 the binding and restart with keytran_start at the end. */
6713 if ((VECTORP (keytran_next
) || STRINGP (keytran_next
))
6714 && keytran_end
== t
)
6716 int len
= XFASTINT (Flength (keytran_next
));
6718 t
= keytran_start
+ len
;
6720 error ("Key sequence too long");
6722 if (VECTORP (keytran_next
))
6723 bcopy (XVECTOR (keytran_next
)->contents
,
6724 keybuf
+ keytran_start
,
6725 (t
- keytran_start
) * sizeof (keybuf
[0]));
6726 else if (STRINGP (keytran_next
))
6730 for (i
= 0; i
< len
; i
++)
6731 XSETFASTINT (keybuf
[keytran_start
+ i
],
6732 XSTRING (keytran_next
)->data
[i
]);
6736 keytran_start
= keytran_end
= t
;
6737 keytran_map
= Vkey_translation_map
;
6739 /* Don't pass the results of key-translation-map
6740 through function-key-map. */
6741 fkey_start
= fkey_end
= t
;
6742 fkey_map
= Vkey_translation_map
;
6744 goto replay_sequence
;
6747 keytran_map
= get_keymap_1 (keytran_next
, 0, 1);
6749 /* If we no longer have a bound suffix, try a new positions for
6751 if (NILP (keytran_map
))
6753 keytran_end
= ++keytran_start
;
6754 keytran_map
= Vkey_translation_map
;
6755 key_translation_possible
= 0;
6760 /* If KEY is not defined in any of the keymaps,
6761 and cannot be part of a function key or translation,
6762 and is an upper case letter
6763 use the corresponding lower-case letter instead. */
6764 if (first_binding
== nmaps
&& ! function_key_possible
6765 && ! key_translation_possible
6767 && ((((XINT (key
) & 0x3ffff)
6768 < XSTRING (current_buffer
->downcase_table
)->size
)
6769 && UPPERCASEP (XINT (key
) & 0x3ffff))
6770 || (XINT (key
) & shift_modifier
)))
6772 Lisp_Object new_key
;
6774 original_uppercase
= key
;
6775 original_uppercase_position
= t
- 1;
6777 if (XINT (key
) & shift_modifier
)
6778 XSETINT (new_key
, XINT (key
) & ~shift_modifier
);
6780 XSETINT (new_key
, (DOWNCASE (XINT (key
) & 0x3ffff)
6781 | (XINT (key
) & ~0x3ffff)));
6783 /* We have to do this unconditionally, regardless of whether
6784 the lower-case char is defined in the keymaps, because they
6785 might get translated through function-key-map. */
6786 keybuf
[t
- 1] = new_key
;
6789 fkey_map
= prev_fkey_map
;
6790 fkey_start
= prev_fkey_start
;
6791 fkey_end
= prev_fkey_end
;
6793 keytran_map
= prev_keytran_map
;
6794 keytran_start
= prev_keytran_start
;
6795 keytran_end
= prev_keytran_end
;
6797 goto replay_sequence
;
6799 /* If KEY is not defined in any of the keymaps,
6800 and cannot be part of a function key or translation,
6801 and is a shifted function key,
6802 use the corresponding unshifted function key instead. */
6803 if (first_binding
== nmaps
&& ! function_key_possible
6804 && ! key_translation_possible
6807 Lisp_Object breakdown
;
6810 breakdown
= parse_modifiers (key
);
6811 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
6812 if (modifiers
& shift_modifier
)
6814 Lisp_Object new_key
;
6816 original_uppercase
= key
;
6817 original_uppercase_position
= t
- 1;
6819 modifiers
&= ~shift_modifier
;
6820 new_key
= apply_modifiers (modifiers
,
6821 XCONS (breakdown
)->car
);
6823 keybuf
[t
- 1] = new_key
;
6826 fkey_map
= prev_fkey_map
;
6827 fkey_start
= prev_fkey_start
;
6828 fkey_end
= prev_fkey_end
;
6830 keytran_map
= prev_keytran_map
;
6831 keytran_start
= prev_keytran_start
;
6832 keytran_end
= prev_keytran_end
;
6834 goto replay_sequence
;
6840 read_key_sequence_cmd
= (first_binding
< nmaps
6841 ? defs
[first_binding
]
6844 unread_switch_frame
= delayed_switch_frame
;
6845 unbind_to (count
, Qnil
);
6847 /* Don't downcase the last character if the caller says don't.
6848 Don't downcase it if the result is undefined, either. */
6849 if ((dont_downcase_last
|| first_binding
>= nmaps
)
6850 && t
- 1 == original_uppercase_position
)
6851 keybuf
[t
- 1] = original_uppercase
;
6853 /* Occasionally we fabricate events, perhaps by expanding something
6854 according to function-key-map, or by adding a prefix symbol to a
6855 mouse click in the scroll bar or modeline. In this cases, return
6856 the entire generated key sequence, even if we hit an unbound
6857 prefix or a definition before the end. This means that you will
6858 be able to push back the event properly, and also means that
6859 read-key-sequence will always return a logical unit.
6862 for (; t
< mock_input
; t
++)
6864 if (echo_keystrokes
)
6865 echo_char (keybuf
[t
]);
6866 add_command_key (keybuf
[t
]);
6872 #if 0 /* This doc string is too long for some compilers.
6873 This commented-out definition serves for DOC. */
6874 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
6875 "Read a sequence of keystrokes and return as a string or vector.\n\
6876 The sequence is sufficient to specify a non-prefix command in the\n\
6877 current local and global maps.\n\
6879 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
6880 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
6881 as a continuation of the previous key.\n\
6883 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not\n\
6884 convert the last event to lower case. (Normally any upper case event\n\
6885 is converted to lower case if the original event is undefined and the lower\n\
6886 case equivalent is defined.) A non-nil value is appropriate for reading\n\
6887 a key sequence to be defined.\n\
6889 A C-g typed while in this function is treated like any other character,\n\
6890 and `quit-flag' is not set.\n\
6892 If the key sequence starts with a mouse click, then the sequence is read\n\
6893 using the keymaps of the buffer of the window clicked in, not the buffer\n\
6894 of the selected window as normal.\n\
6896 `read-key-sequence' drops unbound button-down events, since you normally\n\
6897 only care about the click or drag events which follow them. If a drag\n\
6898 or multi-click event is unbound, but the corresponding click event would\n\
6899 be bound, `read-key-sequence' turns the event into a click event at the\n\
6900 drag's starting position. This means that you don't have to distinguish\n\
6901 between click and drag, double, or triple events unless you want to.\n\
6903 `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\
6904 lines separating windows, and scroll bars with imaginary keys\n\
6905 `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\
6907 Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this\n\
6908 function will process a switch-frame event if the user switches frames\n\
6909 before typing anything. If the user switches frames in the middle of a\n\
6910 key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME\n\
6911 is nil, then the event will be put off until after the current key sequence.\n\
6913 `read-key-sequence' checks `function-key-map' for function key\n\
6914 sequences, where they wouldn't conflict with ordinary bindings. See\n\
6915 `function-key-map' for more details.")
6916 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
)
6919 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
6921 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
)
6922 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
6923 Lisp_Object can_return_switch_frame
;
6925 Lisp_Object keybuf
[30];
6927 struct gcpro gcpro1
, gcpro2
;
6930 CHECK_STRING (prompt
, 0);
6933 bzero (keybuf
, sizeof keybuf
);
6935 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
6937 if (NILP (continue_echo
))
6939 this_command_key_count
= 0;
6940 this_single_command_key_start
= 0;
6943 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
6944 prompt
, ! NILP (dont_downcase_last
),
6945 ! NILP (can_return_switch_frame
));
6953 return make_event_array (i
, keybuf
);
6956 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 4, 0,
6957 "Execute CMD as an editor command.\n\
6958 CMD must be a symbol that satisfies the `commandp' predicate.\n\
6959 Optional second arg RECORD-FLAG non-nil\n\
6960 means unconditionally put this command in `command-history'.\n\
6961 Otherwise, that is done only if an arg is read using the minibuffer.\n\
6962 The argument KEYS specifies the value to use instead of (this-command-keys)\n\
6963 when reading the arguments; if it is nil, (this-command-keys) is used.\n\
6964 The argument SPECIAL, if non-nil, means that this command is executing\n\
6965 a special event, so ignore the prefix argument and don't clear it.")
6966 (cmd
, record_flag
, keys
, special
)
6967 Lisp_Object cmd
, record_flag
, keys
, special
;
6969 register Lisp_Object final
;
6970 register Lisp_Object tem
;
6971 Lisp_Object prefixarg
;
6972 struct backtrace backtrace
;
6973 extern int debug_on_next_call
;
6975 debug_on_next_call
= 0;
6979 prefixarg
= current_kboard
->Vprefix_arg
;
6980 Vcurrent_prefix_arg
= prefixarg
;
6981 current_kboard
->Vprefix_arg
= Qnil
;
6988 tem
= Fget (cmd
, Qdisabled
);
6989 if (!NILP (tem
) && !NILP (Vrun_hooks
))
6991 tem
= Fsymbol_value (Qdisabled_command_hook
);
6993 return call1 (Vrun_hooks
, Qdisabled_command_hook
);
6999 final
= Findirect_function (cmd
);
7001 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
7003 struct gcpro gcpro1
, gcpro2
;
7005 GCPRO2 (cmd
, prefixarg
);
7006 do_autoload (final
, cmd
);
7013 if (STRINGP (final
) || VECTORP (final
))
7015 /* If requested, place the macro in the command history. For
7016 other sorts of commands, call-interactively takes care of
7018 if (!NILP (record_flag
))
7020 = Fcons (Fcons (Qexecute_kbd_macro
,
7021 Fcons (final
, Fcons (prefixarg
, Qnil
))),
7024 return Fexecute_kbd_macro (final
, prefixarg
);
7026 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
7028 backtrace
.next
= backtrace_list
;
7029 backtrace_list
= &backtrace
;
7030 backtrace
.function
= &Qcall_interactively
;
7031 backtrace
.args
= &cmd
;
7032 backtrace
.nargs
= 1;
7033 backtrace
.evalargs
= 0;
7035 tem
= Fcall_interactively (cmd
, record_flag
, keys
);
7037 backtrace_list
= backtrace
.next
;
7043 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
7045 "Read function name, then read its arguments and call it.")
7047 Lisp_Object prefixarg
;
7049 Lisp_Object function
;
7051 Lisp_Object saved_keys
;
7052 Lisp_Object bindings
, value
;
7053 struct gcpro gcpro1
, gcpro2
;
7055 saved_keys
= Fvector (this_command_key_count
,
7056 XVECTOR (this_command_keys
)->contents
);
7058 GCPRO2 (saved_keys
, prefixarg
);
7060 if (EQ (prefixarg
, Qminus
))
7062 else if (CONSP (prefixarg
) && XINT (XCONS (prefixarg
)->car
) == 4)
7063 strcpy (buf
, "C-u ");
7064 else if (CONSP (prefixarg
) && INTEGERP (XCONS (prefixarg
)->car
))
7066 if (sizeof (int) == sizeof (EMACS_INT
))
7067 sprintf (buf
, "%d ", XINT (XCONS (prefixarg
)->car
));
7068 else if (sizeof (long) == sizeof (EMACS_INT
))
7069 sprintf (buf
, "%ld ", XINT (XCONS (prefixarg
)->car
));
7073 else if (INTEGERP (prefixarg
))
7075 if (sizeof (int) == sizeof (EMACS_INT
))
7076 sprintf (buf
, "%d ", XINT (prefixarg
));
7077 else if (sizeof (long) == sizeof (EMACS_INT
))
7078 sprintf (buf
, "%ld ", XINT (prefixarg
));
7083 /* This isn't strictly correct if execute-extended-command
7084 is bound to anything else. Perhaps it should use
7085 this_command_keys? */
7086 strcat (buf
, "M-x ");
7088 /* Prompt with buf, and then read a string, completing from and
7089 restricting to the set of all defined commands. Don't provide
7090 any initial input. Save the command read on the extended-command
7092 function
= Fcompleting_read (build_string (buf
),
7093 Vobarray
, Qcommandp
,
7094 Qt
, Qnil
, Qextended_command_history
);
7096 if (STRINGP (function
) && XSTRING (function
)->size
== 0)
7097 error ("No command name given");
7099 /* Set this_command_keys to the concatenation of saved_keys and
7100 function, followed by a RET. */
7102 struct Lisp_String
*str
;
7107 this_command_key_count
= 0;
7108 this_single_command_key_start
= 0;
7110 keys
= XVECTOR (saved_keys
)->contents
;
7111 for (i
= 0; i
< XVECTOR (saved_keys
)->size
; i
++)
7112 add_command_key (keys
[i
]);
7114 str
= XSTRING (function
);
7115 for (i
= 0; i
< str
->size
; i
++)
7117 XSETFASTINT (tem
, str
->data
[i
]);
7118 add_command_key (tem
);
7121 XSETFASTINT (tem
, '\015');
7122 add_command_key (tem
);
7127 function
= Fintern (function
, Qnil
);
7128 current_kboard
->Vprefix_arg
= prefixarg
;
7129 this_command
= function
;
7131 /* If enabled, show which key runs this command. */
7132 if (!NILP (Vsuggest_key_bindings
)
7133 && NILP (Vexecuting_macro
)
7134 && SYMBOLP (function
))
7135 bindings
= Fwhere_is_internal (function
, Voverriding_local_map
,
7141 GCPRO2 (bindings
, value
);
7142 value
= Fcommand_execute (function
, Qt
, Qnil
, Qnil
);
7144 /* If the command has a key binding, print it now. */
7145 if (!NILP (bindings
))
7147 /* But first wait, and skip the message if there is input. */
7148 if (!NILP (Fsit_for ((NUMBERP (Vsuggest_key_bindings
)
7149 ? Vsuggest_key_bindings
: make_number (2)),
7152 Lisp_Object binding
;
7154 char *oldmessage
= echo_area_glyphs
;
7155 int oldmessage_len
= echo_area_glyphs_length
;
7157 binding
= Fkey_description (bindings
);
7160 = (char *) alloca (XSYMBOL (function
)->name
->size
7161 + XSTRING (binding
)->size
7163 sprintf (newmessage
, "You can run the command `%s' by typing %s",
7164 XSYMBOL (function
)->name
->data
,
7165 XSTRING (binding
)->data
);
7166 message1_nolog (newmessage
);
7167 if (!NILP (Fsit_for ((NUMBERP (Vsuggest_key_bindings
)
7168 ? Vsuggest_key_bindings
: make_number (2)),
7170 message2_nolog (oldmessage
, oldmessage_len
);
7174 RETURN_UNGCPRO (value
);
7177 /* Find the set of keymaps now active.
7178 Store into *MAPS_P a vector holding the various maps
7179 and return the number of them. The vector was malloc'd
7180 and the caller should free it. */
7183 current_active_maps (maps_p
)
7184 Lisp_Object
**maps_p
;
7186 Lisp_Object
*tmaps
, *maps
;
7189 /* Should overriding-terminal-local-map and overriding-local-map apply? */
7190 if (!NILP (Voverriding_local_map_menu_flag
))
7192 /* Yes, use them (if non-nil) as well as the global map. */
7193 maps
= (Lisp_Object
*) xmalloc (3 * sizeof (maps
[0]));
7195 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
7196 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
7197 if (!NILP (Voverriding_local_map
))
7198 maps
[nmaps
++] = Voverriding_local_map
;
7202 /* No, so use major and minor mode keymaps. */
7203 nmaps
= current_minor_maps (NULL
, &tmaps
);
7204 maps
= (Lisp_Object
*) xmalloc ((nmaps
+ 2) * sizeof (maps
[0]));
7205 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
7206 #ifdef USE_TEXT_PROPERTIES
7207 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
7209 maps
[nmaps
++] = current_buffer
->keymap
;
7212 maps
[nmaps
++] = current_global_map
;
7218 /* Return nonzero if input events are pending. */
7220 detect_input_pending ()
7223 get_input_pending (&input_pending
, 0);
7225 return input_pending
;
7228 /* Return nonzero if input events are pending, and run any pending timers. */
7230 detect_input_pending_run_timers (do_display
)
7233 int old_timers_run
= timers_run
;
7236 get_input_pending (&input_pending
, 1);
7238 if (old_timers_run
!= timers_run
&& do_display
)
7239 redisplay_preserve_echo_area ();
7241 return input_pending
;
7244 /* This is called in some cases before a possible quit.
7245 It cases the next call to detect_input_pending to recompute input_pending.
7246 So calling this function unnecessarily can't do any harm. */
7247 clear_input_pending ()
7252 /* Return nonzero if there are pending requeued events.
7253 This isn't used yet. The hope is to make wait_reading_process_input
7254 call it, and return return if it runs Lisp code that unreads something.
7255 The problem is, kbd_buffer_get_event needs to be fixed to know what
7256 to do in that case. It isn't trivial. */
7258 requeued_events_pending_p ()
7260 return (!NILP (Vunread_command_events
) || unread_command_char
!= -1);
7264 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
7265 "T if command input is currently available with no waiting.\n\
7266 Actually, the value is nil only if we can be sure that no input is available.")
7269 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1)
7272 get_input_pending (&input_pending
, 1);
7273 return input_pending
> 0 ? Qt
: Qnil
;
7276 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
7277 "Return vector of last 100 events, not counting those from keyboard macros.")
7280 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
7283 if (total_keys
< NUM_RECENT_KEYS
)
7284 return Fvector (total_keys
, keys
);
7287 val
= Fvector (NUM_RECENT_KEYS
, keys
);
7288 bcopy (keys
+ recent_keys_index
,
7289 XVECTOR (val
)->contents
,
7290 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
7292 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
7293 recent_keys_index
* sizeof (Lisp_Object
));
7298 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
7299 "Return the key sequence that invoked this command.\n\
7300 The value is a string or a vector.")
7303 return make_event_array (this_command_key_count
,
7304 XVECTOR (this_command_keys
)->contents
);
7307 DEFUN ("this-single-command-keys", Fthis_single_command_keys
,
7308 Sthis_single_command_keys
, 0, 0, 0,
7309 "Return the key sequence that invoked this command.\n\
7310 Unlike `this-command-keys', this function's value\n\
7311 does not include prefix arguments.\n\
7312 The value is a string or a vector.")
7315 return make_event_array (this_command_key_count
7316 - this_single_command_key_start
,
7317 (XVECTOR (this_command_keys
)->contents
7318 + this_single_command_key_start
));
7321 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths
,
7322 Sreset_this_command_lengths
, 0, 0, 0,
7323 "Used for complicated reasons in `universal-argument-other-key'.\n\
7325 `universal-argument-other-key' rereads the event just typed.\n\
7326 It then gets translated through `function-key-map'.\n\
7327 The translated event gets included in the echo area and in\n\
7328 the value of `this-command-keys' in addition to the raw original event.\n\
7329 That is not right.\n\
7331 Calling this function directs the translated event to replace\n\
7332 the original event, so that only one version of the event actually\n\
7333 appears in the echo area and in the value of `this-command-keys.'.")
7336 before_command_restore_flag
= 1;
7337 before_command_key_count_1
= before_command_key_count
;
7338 before_command_echo_length_1
= before_command_echo_length
;
7341 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
7342 "Return the current depth in recursive edits.")
7346 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
7350 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
7351 "FOpen dribble file: ",
7352 "Start writing all keyboard characters to a dribble file called FILE.\n\
7353 If FILE is nil, close any open dribble file.")
7364 file
= Fexpand_file_name (file
, Qnil
);
7365 dribble
= fopen (XSTRING (file
)->data
, "w");
7367 report_file_error ("Opening dribble", Fcons (file
, Qnil
));
7372 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
7373 "Discard the contents of the terminal input buffer.\n\
7374 Also cancel any kbd macro being defined.")
7377 current_kboard
->defining_kbd_macro
= Qnil
;
7378 update_mode_lines
++;
7380 Vunread_command_events
= Qnil
;
7381 unread_command_char
= -1;
7383 discard_tty_input ();
7385 /* Without the cast, GCC complains that this assignment loses the
7386 volatile qualifier of kbd_store_ptr. Is there anything wrong
7388 kbd_fetch_ptr
= (struct input_event
*) kbd_store_ptr
;
7389 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
7395 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
7396 "Stop Emacs and return to superior process. You can resume later.\n\
7397 If `cannot-suspend' is non-nil, or if the system doesn't support job\n\
7398 control, run a subshell instead.\n\n\
7399 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
7400 to be read as terminal input by Emacs's parent, after suspension.\n\
7402 Before suspending, run the normal hook `suspend-hook'.\n\
7403 After resumption run the normal hook `suspend-resume-hook'.\n\
7405 Some operating systems cannot stop the Emacs process and resume it later.\n\
7406 On such systems, Emacs starts a subshell instead of suspending.")
7408 Lisp_Object stuffstring
;
7411 int count
= specpdl_ptr
- specpdl
;
7412 int old_height
, old_width
;
7414 struct gcpro gcpro1
, gcpro2
;
7415 extern init_sys_modes ();
7417 if (!NILP (stuffstring
))
7418 CHECK_STRING (stuffstring
, 0);
7420 /* Run the functions in suspend-hook. */
7421 if (!NILP (Vrun_hooks
))
7422 call1 (Vrun_hooks
, intern ("suspend-hook"));
7424 GCPRO1 (stuffstring
);
7425 get_frame_size (&old_width
, &old_height
);
7427 /* sys_suspend can get an error if it tries to fork a subshell
7428 and the system resources aren't available for that. */
7429 record_unwind_protect (init_sys_modes
, 0);
7430 stuff_buffered_input (stuffstring
);
7435 unbind_to (count
, Qnil
);
7437 /* Check if terminal/window size has changed.
7438 Note that this is not useful when we are running directly
7439 with a window system; but suspend should be disabled in that case. */
7440 get_frame_size (&width
, &height
);
7441 if (width
!= old_width
|| height
!= old_height
)
7442 change_frame_size (selected_frame
, height
, width
, 0, 0);
7444 /* Run suspend-resume-hook. */
7445 if (!NILP (Vrun_hooks
))
7446 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
7452 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
7453 Then in any case stuff anything Emacs has read ahead and not used. */
7455 stuff_buffered_input (stuffstring
)
7456 Lisp_Object stuffstring
;
7458 /* stuff_char works only in BSD, versions 4.2 and up. */
7461 register unsigned char *p
;
7463 if (STRINGP (stuffstring
))
7467 p
= XSTRING (stuffstring
)->data
;
7468 count
= XSTRING (stuffstring
)->size
;
7473 /* Anything we have read ahead, put back for the shell to read. */
7474 /* ?? What should this do when we have multiple keyboards??
7475 Should we ignore anything that was typed in at the "wrong" kboard? */
7476 for (; kbd_fetch_ptr
!= kbd_store_ptr
; kbd_fetch_ptr
++)
7478 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
7479 kbd_fetch_ptr
= kbd_buffer
;
7480 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
7481 stuff_char (kbd_fetch_ptr
->code
);
7482 kbd_fetch_ptr
->kind
= no_event
;
7483 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_fetch_ptr
7489 #endif /* BSD_SYSTEM and not BSD4_1 */
7492 set_waiting_for_input (time_to_clear
)
7493 EMACS_TIME
*time_to_clear
;
7495 input_available_clear_time
= time_to_clear
;
7497 /* Tell interrupt_signal to throw back to read_char, */
7498 waiting_for_input
= 1;
7500 /* If interrupt_signal was called before and buffered a C-g,
7501 make it run again now, to avoid timing error. */
7502 if (!NILP (Vquit_flag
))
7503 quit_throw_to_read_char ();
7506 clear_waiting_for_input ()
7508 /* Tell interrupt_signal not to throw back to read_char, */
7509 waiting_for_input
= 0;
7510 input_available_clear_time
= 0;
7513 /* This routine is called at interrupt level in response to C-G.
7514 If interrupt_input, this is the handler for SIGINT.
7515 Otherwise, it is called from kbd_buffer_store_event,
7516 in handling SIGIO or SIGTINT.
7518 If `waiting_for_input' is non zero, then unless `echoing' is nonzero,
7519 immediately throw back to read_char.
7521 Otherwise it sets the Lisp variable quit-flag not-nil.
7522 This causes eval to throw, when it gets a chance.
7523 If quit-flag is already non-nil, it stops the job right away. */
7526 interrupt_signal (signalnum
) /* If we don't have an argument, */
7527 int signalnum
; /* some compilers complain in signal calls. */
7530 /* Must preserve main program's value of errno. */
7531 int old_errno
= errno
;
7533 #if defined (USG) && !defined (POSIX_SIGNALS)
7534 if (!read_socket_hook
&& NILP (Vwindow_system
))
7536 /* USG systems forget handlers when they are used;
7537 must reestablish each time */
7538 signal (SIGINT
, interrupt_signal
);
7539 signal (SIGQUIT
, interrupt_signal
);
7545 if (!NILP (Vquit_flag
)
7546 && (FRAME_TERMCAP_P (selected_frame
) || FRAME_MSDOS_P (selected_frame
)))
7548 /* If SIGINT isn't blocked, don't let us be interrupted by
7549 another SIGINT, it might be harmful due to non-reentrancy
7550 in I/O functions. */
7551 sigblock (sigmask (SIGINT
));
7556 #ifdef SIGTSTP /* Support possible in later USG versions */
7558 * On systems which can suspend the current process and return to the original
7559 * shell, this command causes the user to end up back at the shell.
7560 * The "Auto-save" and "Abort" questions are not asked until
7561 * the user elects to return to emacs, at which point he can save the current
7562 * job and either dump core or continue.
7567 if (sys_suspend () == -1)
7569 printf ("Not running as a subprocess;\n");
7570 printf ("you can continue or abort.\n");
7573 /* Perhaps should really fork an inferior shell?
7574 But that would not provide any way to get back
7575 to the original shell, ever. */
7576 printf ("No support for stopping a process on this operating system;\n");
7577 printf ("you can continue or abort.\n");
7578 #endif /* not VMS */
7579 #endif /* not SIGTSTP */
7581 /* We must remain inside the screen area when the internal terminal
7582 is used. Note that [Enter] is not echoed by dos. */
7585 /* It doesn't work to autosave while GC is in progress;
7586 the code used for auto-saving doesn't cope with the mark bit. */
7587 if (!gc_in_progress
)
7589 printf ("Auto-save? (y or n) ");
7591 if (((c
= getchar ()) & ~040) == 'Y')
7593 Fdo_auto_save (Qt
, Qnil
);
7595 printf ("\r\nAuto-save done");
7596 #else /* not MSDOS */
7597 printf ("Auto-save done\n");
7598 #endif /* not MSDOS */
7600 while (c
!= '\n') c
= getchar ();
7604 /* During GC, it must be safe to reenable quitting again. */
7605 Vinhibit_quit
= Qnil
;
7608 #endif /* not MSDOS */
7609 printf ("Garbage collection in progress; cannot auto-save now\r\n");
7610 printf ("but will instead do a real quit after garbage collection ends\r\n");
7615 printf ("\r\nAbort? (y or n) ");
7616 #else /* not MSDOS */
7618 printf ("Abort (and enter debugger)? (y or n) ");
7620 printf ("Abort (and dump core)? (y or n) ");
7621 #endif /* not VMS */
7622 #endif /* not MSDOS */
7624 if (((c
= getchar ()) & ~040) == 'Y')
7626 while (c
!= '\n') c
= getchar ();
7628 printf ("\r\nContinuing...\r\n");
7629 #else /* not MSDOS */
7630 printf ("Continuing...\n");
7631 #endif /* not MSDOS */
7638 /* If executing a function that wants to be interrupted out of
7639 and the user has not deferred quitting by binding `inhibit-quit'
7640 then quit right away. */
7641 if (immediate_quit
&& NILP (Vinhibit_quit
))
7645 Fsignal (Qquit
, Qnil
);
7648 /* Else request quit when it's safe */
7652 if (waiting_for_input
&& !echoing
)
7653 quit_throw_to_read_char ();
7658 /* Handle a C-g by making read_char return C-g. */
7660 quit_throw_to_read_char ()
7662 quit_error_check ();
7664 /* Prevent another signal from doing this before we finish. */
7665 clear_waiting_for_input ();
7668 Vunread_command_events
= Qnil
;
7669 unread_command_char
= -1;
7671 #if 0 /* Currently, sit_for is called from read_char without turning
7672 off polling. And that can call set_waiting_for_input.
7673 It seems to be harmless. */
7674 #ifdef POLL_FOR_INPUT
7675 /* May be > 1 if in recursive minibuffer. */
7676 if (poll_suppress_count
== 0)
7680 if (FRAMEP (internal_last_event_frame
)
7681 && XFRAME (internal_last_event_frame
) != selected_frame
)
7682 do_switch_frame (make_lispy_switch_frame (internal_last_event_frame
),
7685 _longjmp (getcjmp
, 1);
7688 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
7689 "Set mode of reading keyboard input.\n\
7690 First arg INTERRUPT non-nil means use input interrupts;\n\
7691 nil means use CBREAK mode.\n\
7692 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
7693 (no effect except in CBREAK mode).\n\
7694 Third arg META t means accept 8-bit input (for a Meta key).\n\
7695 META nil means ignore the top bit, on the assumption it is parity.\n\
7696 Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\
7697 Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\
7698 See also `current-input-mode'.")
7699 (interrupt
, flow
, meta
, quit
)
7700 Lisp_Object interrupt
, flow
, meta
, quit
;
7703 && (!INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400))
7704 error ("set-input-mode: QUIT must be an ASCII character");
7706 #ifdef POLL_FOR_INPUT
7711 /* this causes startup screen to be restored and messes with the mouse */
7716 /* Note SIGIO has been undef'd if FIONREAD is missing. */
7717 if (read_socket_hook
)
7719 /* When using X, don't give the user a real choice,
7720 because we haven't implemented the mechanisms to support it. */
7721 #ifdef NO_SOCK_SIGIO
7722 interrupt_input
= 0;
7723 #else /* not NO_SOCK_SIGIO */
7724 interrupt_input
= 1;
7725 #endif /* NO_SOCK_SIGIO */
7728 interrupt_input
= !NILP (interrupt
);
7729 #else /* not SIGIO */
7730 interrupt_input
= 0;
7731 #endif /* not SIGIO */
7733 /* Our VMS input only works by interrupts, as of now. */
7735 interrupt_input
= 1;
7738 flow_control
= !NILP (flow
);
7741 else if (EQ (meta
, Qt
))
7746 /* Don't let this value be out of range. */
7747 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
7753 #ifdef POLL_FOR_INPUT
7754 poll_suppress_count
= 1;
7760 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
7761 "Return information about the way Emacs currently reads keyboard input.\n\
7762 The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
7763 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\
7764 nil, Emacs is using CBREAK mode.\n\
7765 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\
7766 terminal; this does not apply if Emacs uses interrupt-driven input.\n\
7767 META is t if accepting 8-bit input with 8th bit as Meta flag.\n\
7768 META nil means ignoring the top bit, on the assumption it is parity.\n\
7769 META is neither t nor nil if accepting 8-bit input and using\n\
7770 all 8 bits as the character code.\n\
7771 QUIT is the character Emacs currently uses to quit.\n\
7772 The elements of this list correspond to the arguments of\n\
7778 val
[0] = interrupt_input
? Qt
: Qnil
;
7779 val
[1] = flow_control
? Qt
: Qnil
;
7780 val
[2] = meta_key
== 2 ? make_number (0) : meta_key
== 1 ? Qt
: Qnil
;
7781 XSETFASTINT (val
[3], quit_char
);
7783 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
7788 * Set up a new kboard object with reasonable initial values.
7794 kb
->Voverriding_terminal_local_map
= Qnil
;
7795 kb
->Vlast_command
= Qnil
;
7796 kb
->Vprefix_arg
= Qnil
;
7797 kb
->kbd_queue
= Qnil
;
7798 kb
->kbd_queue_has_data
= 0;
7799 kb
->immediate_echo
= 0;
7800 kb
->echoptr
= kb
->echobuf
;
7801 kb
->echo_after_prompt
= -1;
7802 kb
->kbd_macro_buffer
= 0;
7803 kb
->kbd_macro_bufsize
= 0;
7804 kb
->defining_kbd_macro
= Qnil
;
7805 kb
->Vlast_kbd_macro
= Qnil
;
7806 kb
->reference_count
= 0;
7807 kb
->Vsystem_key_alist
= Qnil
;
7808 kb
->system_key_syms
= Qnil
;
7809 kb
->Vdefault_minibuffer_frame
= Qnil
;
7813 * Destroy the contents of a kboard object, but not the object itself.
7814 * We use this just before deleting it, or if we're going to initialize
7821 if (kb
->kbd_macro_buffer
)
7822 xfree (kb
->kbd_macro_buffer
);
7831 for (kbp
= &all_kboards
; *kbp
!= kb
; kbp
= &(*kbp
)->next_kboard
)
7834 *kbp
= kb
->next_kboard
;
7842 /* This is correct before outermost invocation of the editor loop */
7843 command_loop_level
= -1;
7845 quit_char
= Ctl ('g');
7846 Vunread_command_events
= Qnil
;
7847 unread_command_char
= -1;
7848 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
7850 recent_keys_index
= 0;
7851 kbd_fetch_ptr
= kbd_buffer
;
7852 kbd_store_ptr
= kbd_buffer
;
7853 kbd_buffer_frame_or_window
7854 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
7856 do_mouse_tracking
= Qnil
;
7860 /* This means that command_loop_1 won't try to select anything the first
7862 internal_last_event_frame
= Qnil
;
7863 Vlast_event_frame
= internal_last_event_frame
;
7866 current_kboard
= initial_kboard
;
7868 wipe_kboard (current_kboard
);
7869 init_kboard (current_kboard
);
7872 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
7874 kbd_buffer_frame_or_window
7875 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
7876 if (!noninteractive
&& !read_socket_hook
&& NILP (Vwindow_system
))
7878 signal (SIGINT
, interrupt_signal
);
7879 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
7880 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
7881 SIGQUIT and we can't tell which one it will give us. */
7882 signal (SIGQUIT
, interrupt_signal
);
7883 #endif /* HAVE_TERMIO */
7885 /* Note SIGIO has been undef'd if FIONREAD is missing. */
7887 if (!noninteractive
)
7888 signal (SIGIO
, input_available_signal
);
7891 /* Use interrupt input by default, if it works and noninterrupt input
7892 has deficiencies. */
7894 #ifdef INTERRUPT_INPUT
7895 interrupt_input
= 1;
7897 interrupt_input
= 0;
7900 /* Our VMS input only works by interrupts, as of now. */
7902 interrupt_input
= 1;
7908 if (keyboard_init_hook
)
7909 (*keyboard_init_hook
) ();
7911 #ifdef POLL_FOR_INPUT
7912 poll_suppress_count
= 1;
7917 /* This type's only use is in syms_of_keyboard, to initialize the
7918 event header symbols and put properties on them. */
7925 struct event_head head_table
[] = {
7926 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
7927 &Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
,
7928 &Qswitch_frame
, "switch-frame", &Qswitch_frame
,
7929 &Qdelete_frame
, "delete-frame", &Qdelete_frame
,
7930 &Qiconify_frame
, "iconify-frame", &Qiconify_frame
,
7931 &Qmake_frame_visible
, "make-frame-visible", &Qmake_frame_visible
,
7936 Qdisabled_command_hook
= intern ("disabled-command-hook");
7937 staticpro (&Qdisabled_command_hook
);
7939 Qself_insert_command
= intern ("self-insert-command");
7940 staticpro (&Qself_insert_command
);
7942 Qforward_char
= intern ("forward-char");
7943 staticpro (&Qforward_char
);
7945 Qbackward_char
= intern ("backward-char");
7946 staticpro (&Qbackward_char
);
7948 Qdisabled
= intern ("disabled");
7949 staticpro (&Qdisabled
);
7951 Qundefined
= intern ("undefined");
7952 staticpro (&Qundefined
);
7954 Qpre_command_hook
= intern ("pre-command-hook");
7955 staticpro (&Qpre_command_hook
);
7957 Qpost_command_hook
= intern ("post-command-hook");
7958 staticpro (&Qpost_command_hook
);
7960 Qpost_command_idle_hook
= intern ("post-command-idle-hook");
7961 staticpro (&Qpost_command_idle_hook
);
7963 Qdeferred_action_function
= intern ("deferred-action-function");
7964 staticpro (&Qdeferred_action_function
);
7966 Qcommand_hook_internal
= intern ("command-hook-internal");
7967 staticpro (&Qcommand_hook_internal
);
7969 Qfunction_key
= intern ("function-key");
7970 staticpro (&Qfunction_key
);
7971 Qmouse_click
= intern ("mouse-click");
7972 staticpro (&Qmouse_click
);
7973 Qtimer_event
= intern ("timer-event");
7974 staticpro (&Qtimer_event
);
7976 Qmenu_enable
= intern ("menu-enable");
7977 staticpro (&Qmenu_enable
);
7979 Qmode_line
= intern ("mode-line");
7980 staticpro (&Qmode_line
);
7981 Qvertical_line
= intern ("vertical-line");
7982 staticpro (&Qvertical_line
);
7983 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
7984 staticpro (&Qvertical_scroll_bar
);
7985 Qmenu_bar
= intern ("menu-bar");
7986 staticpro (&Qmenu_bar
);
7988 Qabove_handle
= intern ("above-handle");
7989 staticpro (&Qabove_handle
);
7990 Qhandle
= intern ("handle");
7991 staticpro (&Qhandle
);
7992 Qbelow_handle
= intern ("below-handle");
7993 staticpro (&Qbelow_handle
);
7994 Qup
= intern ("up");
7996 Qdown
= intern ("down");
7999 Qevent_kind
= intern ("event-kind");
8000 staticpro (&Qevent_kind
);
8001 Qevent_symbol_elements
= intern ("event-symbol-elements");
8002 staticpro (&Qevent_symbol_elements
);
8003 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
8004 staticpro (&Qevent_symbol_element_mask
);
8005 Qmodifier_cache
= intern ("modifier-cache");
8006 staticpro (&Qmodifier_cache
);
8008 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
8009 staticpro (&Qrecompute_lucid_menubar
);
8010 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
8011 staticpro (&Qactivate_menubar_hook
);
8013 Qpolling_period
= intern ("polling-period");
8014 staticpro (&Qpolling_period
);
8017 struct event_head
*p
;
8019 for (p
= head_table
;
8020 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
8023 *p
->var
= intern (p
->name
);
8025 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
8026 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
8030 button_down_location
= Fmake_vector (make_number (NUM_MOUSE_BUTTONS
), Qnil
);
8031 staticpro (&button_down_location
);
8035 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
8037 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
8038 for (i
= 0; i
< len
; i
++)
8039 if (modifier_names
[i
])
8040 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
8041 staticpro (&modifier_symbols
);
8044 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
8045 staticpro (&recent_keys
);
8047 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
8048 staticpro (&this_command_keys
);
8050 Qextended_command_history
= intern ("extended-command-history");
8051 Fset (Qextended_command_history
, Qnil
);
8052 staticpro (&Qextended_command_history
);
8054 kbd_buffer_frame_or_window
8055 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
8056 staticpro (&kbd_buffer_frame_or_window
);
8058 accent_key_syms
= Qnil
;
8059 staticpro (&accent_key_syms
);
8061 func_key_syms
= Qnil
;
8062 staticpro (&func_key_syms
);
8065 staticpro (&mouse_syms
);
8067 unread_switch_frame
= Qnil
;
8068 staticpro (&unread_switch_frame
);
8070 internal_last_event_frame
= Qnil
;
8071 staticpro (&internal_last_event_frame
);
8073 read_key_sequence_cmd
= Qnil
;
8074 staticpro (&read_key_sequence_cmd
);
8076 defsubr (&Sevent_convert_list
);
8077 defsubr (&Sread_key_sequence
);
8078 defsubr (&Srecursive_edit
);
8080 defsubr (&Strack_mouse
);
8082 defsubr (&Sinput_pending_p
);
8083 defsubr (&Scommand_execute
);
8084 defsubr (&Srecent_keys
);
8085 defsubr (&Sthis_command_keys
);
8086 defsubr (&Sthis_single_command_keys
);
8087 defsubr (&Sreset_this_command_lengths
);
8088 defsubr (&Ssuspend_emacs
);
8089 defsubr (&Sabort_recursive_edit
);
8090 defsubr (&Sexit_recursive_edit
);
8091 defsubr (&Srecursion_depth
);
8092 defsubr (&Stop_level
);
8093 defsubr (&Sdiscard_input
);
8094 defsubr (&Sopen_dribble_file
);
8095 defsubr (&Sset_input_mode
);
8096 defsubr (&Scurrent_input_mode
);
8097 defsubr (&Sexecute_extended_command
);
8099 DEFVAR_LISP ("last-command-char", &last_command_char
,
8100 "Last input event that was part of a command.");
8102 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char
,
8103 "Last input event that was part of a command.");
8105 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
8106 "Last input event in a command, except for mouse menu events.\n\
8107 Mouse menus give back keys that don't look like mouse events;\n\
8108 this variable holds the actual mouse event that led to the menu,\n\
8109 so that you can determine whether the command was run by mouse or not.");
8111 DEFVAR_LISP ("last-input-char", &last_input_char
,
8112 "Last input event.");
8114 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char
,
8115 "Last input event.");
8117 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
8118 "List of objects to be read as next command input events.");
8120 DEFVAR_INT ("unread-command-char", &unread_command_char
,
8121 "If not -1, an object to be read as next command input event.");
8123 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
8124 "Meta-prefix character code. Meta-foo as command input\n\
8125 turns into this character followed by foo.");
8126 XSETINT (meta_prefix_char
, 033);
8128 DEFVAR_KBOARD ("last-command", Vlast_command
,
8129 "The last command executed. Normally a symbol with a function definition,\n\
8130 but can be whatever was found in the keymap, or whatever the variable\n\
8131 `this-command' was set to by that command.\n\
8133 The value `mode-exit' is special; it means that the previous command\n\
8134 read an event that told it to exit, and it did so and unread that event.\n\
8135 In other words, the present command is the event that made the previous\n\
8138 The value `kill-region' is special; it means that the previous command\n\
8139 was a kill command.");
8141 DEFVAR_LISP ("this-command", &this_command
,
8142 "The command now being executed.\n\
8143 The command can set this variable; whatever is put here\n\
8144 will be in `last-command' during the following command.");
8145 this_command
= Qnil
;
8147 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
8148 "*Number of keyboard input characters between auto-saves.\n\
8149 Zero means disable autosaving due to number of characters typed.");
8150 auto_save_interval
= 300;
8152 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
8153 "*Number of seconds idle time before auto-save.\n\
8154 Zero or nil means disable auto-saving due to idleness.\n\
8155 After auto-saving due to this many seconds of idle time,\n\
8156 Emacs also does a garbage collection if that seems to be warranted.");
8157 XSETFASTINT (Vauto_save_timeout
, 30);
8159 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes
,
8160 "*Nonzero means echo unfinished commands after this many seconds of pause.");
8161 echo_keystrokes
= 1;
8163 DEFVAR_INT ("polling-period", &polling_period
,
8164 "*Interval between polling for input during Lisp execution.\n\
8165 The reason for polling is to make C-g work to stop a running program.\n\
8166 Polling is needed only when using X windows and SIGIO does not work.\n\
8167 Polling is automatically disabled in all other cases.");
8170 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
8171 "*Maximum time between mouse clicks to make a double-click.\n\
8172 Measured in milliseconds. nil means disable double-click recognition;\n\
8173 t means double-clicks have no time limit and are detected\n\
8174 by position only.");
8175 Vdouble_click_time
= make_number (500);
8177 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
8178 "*Non-nil means inhibit local map menu bar menus.");
8179 inhibit_local_menu_bar_menus
= 0;
8181 DEFVAR_INT ("num-input-keys", &num_input_keys
,
8182 "Number of complete key sequences read from the keyboard so far.\n\
8183 This includes key sequences read from keyboard macros.\n\
8184 The number is effectively the number of interactive command invocations.");
8187 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
8188 "The frame in which the most recently read event occurred.\n\
8189 If the last event came from a keyboard macro, this is set to `macro'.");
8190 Vlast_event_frame
= Qnil
;
8192 DEFVAR_LISP ("help-char", &Vhelp_char
,
8193 "Character to recognize as meaning Help.\n\
8194 When it is read, do `(eval help-form)', and display result if it's a string.\n\
8195 If the value of `help-form' is nil, this char can be read normally.");
8196 XSETINT (Vhelp_char
, Ctl ('H'));
8198 DEFVAR_LISP ("help-event-list", &Vhelp_event_list
,
8199 "List of input events to recognize as meaning Help.\n\
8200 These work just like the value of `help-char' (see that).");
8201 Vhelp_event_list
= Qnil
;
8203 DEFVAR_LISP ("help-form", &Vhelp_form
,
8204 "Form to execute when character `help-char' is read.\n\
8205 If the form returns a string, that string is displayed.\n\
8206 If `help-form' is nil, the help char is not recognized.");
8209 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
8210 "Command to run when `help-char' character follows a prefix key.\n\
8211 This command is used only when there is no actual binding\n\
8212 for that character after that prefix key.");
8213 Vprefix_help_command
= Qnil
;
8215 DEFVAR_LISP ("top-level", &Vtop_level
,
8216 "Form to evaluate when Emacs starts up.\n\
8217 Useful to set before you dump a modified Emacs.");
8220 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
8221 "Translate table for keyboard input, or nil.\n\
8222 Each character is looked up in this string and the contents used instead.\n\
8223 The value may be a string, a vector, or a char-table.\n\
8224 If it is a string or vector of length N,\n\
8225 character codes N and up are untranslated.\n\
8226 In a vector or a char-table, an element which is nil means \"no translation\".");
8227 Vkeyboard_translate_table
= Qnil
;
8229 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
8230 "Non-nil means to always spawn a subshell instead of suspending,\n\
8231 even if the operating system has support for stopping a process.");
8234 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
8235 "Non-nil means prompt with menus when appropriate.\n\
8236 This is done when reading from a keymap that has a prompt string,\n\
8237 for elements that have prompt strings.\n\
8238 The menu is displayed on the screen\n\
8239 if X menus were enabled at configuration\n\
8240 time and the previous event was a mouse click prefix key.\n\
8241 Otherwise, menu prompting uses the echo area.");
8244 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
8245 "Character to see next line of menu prompt.\n\
8246 Type this character while in a menu prompt to rotate around the lines of it.");
8247 XSETINT (menu_prompt_more_char
, ' ');
8249 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
8250 "A mask of additional modifier keys to use with every keyboard character.\n\
8251 Emacs applies the modifiers of the character stored here to each keyboard\n\
8252 character it reads. For example, after evaluating the expression\n\
8253 (setq extra-keyboard-modifiers ?\\C-x)\n\
8254 all input characters will have the control modifier applied to them.\n\
8256 Note that the character ?\\C-@, equivalent to the integer zero, does\n\
8257 not count as a control character; rather, it counts as a character\n\
8258 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\
8259 cancels any modification.");
8260 extra_keyboard_modifiers
= 0;
8262 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
8263 "If an editing command sets this to t, deactivate the mark afterward.\n\
8264 The command loop sets this to nil before each command,\n\
8265 and tests the value when the command returns.\n\
8266 Buffer modification stores t in this variable.");
8267 Vdeactivate_mark
= Qnil
;
8269 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
8270 "Temporary storage of pre-command-hook or post-command-hook.");
8271 Vcommand_hook_internal
= Qnil
;
8273 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
8274 "Normal hook run before each command is executed.\n\
8275 Errors running the hook are caught and ignored.");
8276 Vpre_command_hook
= Qnil
;
8278 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
8279 "Normal hook run after each command is executed.\n\
8280 Errors running the hook are caught and ignored.");
8281 Vpost_command_hook
= Qnil
;
8283 DEFVAR_LISP ("post-command-idle-hook", &Vpost_command_idle_hook
,
8284 "Normal hook run after each command is executed, if idle.\n\
8285 Errors running the hook are caught and ignored.\n\
8286 This feature is obsolete; use idle timers instead. See `etc/NEWS'.");
8287 Vpost_command_idle_hook
= Qnil
;
8289 DEFVAR_INT ("post-command-idle-delay", &post_command_idle_delay
,
8290 "Delay time before running `post-command-idle-hook'.\n\
8291 This is measured in microseconds.");
8292 post_command_idle_delay
= 100000;
8295 DEFVAR_LISP ("echo-area-clear-hook", ...,
8296 "Normal hook run when clearing the echo area.");
8298 Qecho_area_clear_hook
= intern ("echo-area-clear-hook");
8299 XSYMBOL (Qecho_area_clear_hook
)->value
= Qnil
;
8301 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
8302 "t means menu bar, specified Lucid style, needs to be recomputed.");
8303 Vlucid_menu_bar_dirty_flag
= Qnil
;
8305 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
8306 "List of menu bar items to move to the end of the menu bar.\n\
8307 The elements of the list are event types that may have menu bar bindings.");
8308 Vmenu_bar_final_items
= Qnil
;
8310 DEFVAR_KBOARD ("overriding-terminal-local-map",
8311 Voverriding_terminal_local_map
,
8312 "Keymap that overrides all other local keymaps.\n\
8313 If this variable is non-nil, it is used as a keymap instead of the\n\
8314 buffer's local map, and the minor mode keymaps and text property keymaps.");
8316 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
8317 "Keymap that overrides all other local keymaps.\n\
8318 If this variable is non-nil, it is used as a keymap instead of the\n\
8319 buffer's local map, and the minor mode keymaps and text property keymaps.");
8320 Voverriding_local_map
= Qnil
;
8322 DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag
,
8323 "Non-nil means `overriding-local-map' applies to the menu bar.\n\
8324 Otherwise, the menu bar continues to reflect the buffer's local map\n\
8325 and the minor mode maps regardless of `overriding-local-map'.");
8326 Voverriding_local_map_menu_flag
= Qnil
;
8328 DEFVAR_LISP ("special-event-map", &Vspecial_event_map
,
8329 "Keymap defining bindings for special events to execute at low level.");
8330 Vspecial_event_map
= Fcons (intern ("keymap"), Qnil
);
8332 DEFVAR_LISP ("track-mouse", &do_mouse_tracking
,
8333 "*Non-nil means generate motion events for mouse motion.");
8335 DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist
,
8336 "Alist of system-specific X windows key symbols.\n\
8337 Each element should have the form (N . SYMBOL) where N is the\n\
8338 numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\
8339 and SYMBOL is its name.");
8341 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
8342 "List of deferred actions to be performed at a later time.\n\
8343 The precise format isn't relevant here; we just check whether it is nil.");
8344 Vdeferred_action_list
= Qnil
;
8346 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
8347 "Function to call to handle deferred actions, after each command.\n\
8348 This function is called with no arguments after each command\n\
8349 whenever `deferred-action-list' is non-nil.");
8350 Vdeferred_action_function
= Qnil
;
8352 DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings
,
8353 "Non-nil means show the equivalent key-binding when M-x command has one.\n\
8354 The value can be a length of time to show the message for.\n\
8355 If the value is non-nil and not a number, we wait 2 seconds.");
8356 Vsuggest_key_bindings
= Qt
;
8358 DEFVAR_LISP ("timer-list", &Vtimer_list
,
8359 "List of active absolute time timers in order of increasing time");
8362 DEFVAR_LISP ("timer-idle-list", &Vtimer_idle_list
,
8363 "List of active idle-time timers in order of increasing time");
8364 Vtimer_idle_list
= Qnil
;
8369 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
8370 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
8371 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
8372 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
8373 initial_define_key (meta_map
, 'x', "execute-extended-command");
8375 initial_define_lispy_key (Vspecial_event_map
, "delete-frame",
8376 "handle-delete-frame");
8377 initial_define_lispy_key (Vspecial_event_map
, "iconify-frame",
8379 initial_define_lispy_key (Vspecial_event_map
, "make-frame-visible",