1 /* Keyboard and mouse input; editor command loop.
2 Copyright (C) 1985,86,87,88,89,93,94,95,96,97 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Allow config.h to undefine symbols found here. */
29 #include "termhooks.h"
37 #include "dispextern.h"
40 #include "intervals.h"
41 #include "blockinput.h"
51 #include <sys/ioctl.h>
53 #endif /* not MSDOS */
55 #include "syssignal.h"
58 /* This is to get the definitions of the XK_ symbols. */
65 #endif /* HAVE_NTGUI */
67 /* Include systime.h after xterm.h to avoid double inclusion of time.h. */
72 /* Variables for blockinput.h: */
74 /* Non-zero if interrupt input is blocked right now. */
75 int interrupt_input_blocked
;
77 /* Nonzero means an input interrupt has arrived
78 during the current critical section. */
79 int interrupt_input_pending
;
82 /* File descriptor to use for input. */
85 #ifdef HAVE_WINDOW_SYSTEM
86 /* Make all keyboard buffers much bigger when using X windows. */
87 #define KBD_BUFFER_SIZE 4096
88 #else /* No X-windows, character input */
89 #define KBD_BUFFER_SIZE 256
90 #endif /* No X-windows */
92 /* Following definition copied from eval.c */
96 struct backtrace
*next
;
97 Lisp_Object
*function
;
98 Lisp_Object
*args
; /* Points to vector of args. */
99 int nargs
; /* length of vector. If nargs is UNEVALLED,
100 args points to slot holding list of
106 KBOARD
*initial_kboard
;
107 KBOARD
*current_kboard
;
111 KBOARD the_only_kboard
;
114 /* Non-nil disable property on a command means
115 do not execute it; call disabled-command-hook's value instead. */
116 Lisp_Object Qdisabled
, Qdisabled_command_hook
;
118 #define NUM_RECENT_KEYS (100)
119 int recent_keys_index
; /* Index for storing next element into recent_keys */
120 int total_keys
; /* Total number of elements stored into recent_keys */
121 Lisp_Object recent_keys
; /* A vector, holding the last 100 keystrokes */
123 /* Vector holding the key sequence that invoked the current command.
124 It is reused for each command, and it may be longer than the current
125 sequence; this_command_key_count indicates how many elements
126 actually mean something.
127 It's easier to staticpro a single Lisp_Object than an array. */
128 Lisp_Object this_command_keys
;
129 int this_command_key_count
;
131 /* Number of elements of this_command_keys
132 that precede this key sequence. */
133 int this_single_command_key_start
;
135 /* Record values of this_command_key_count and echo_length ()
136 before this command was read. */
137 static int before_command_key_count
;
138 static int before_command_echo_length
;
139 /* Values of before_command_key_count and before_command_echo_length
140 saved by reset-this-command-lengths. */
141 static int before_command_key_count_1
;
142 static int before_command_echo_length_1
;
143 /* Flag set by reset-this-command-lengths,
144 saying to reset the lengths when add_command_key is called. */
145 static int before_command_restore_flag
;
147 extern int minbuf_level
;
149 extern int message_enable_multibyte
;
151 extern struct backtrace
*backtrace_list
;
153 /* Nonzero means do menu prompting. */
154 static int menu_prompting
;
156 /* Character to see next line of menu prompt. */
157 static Lisp_Object menu_prompt_more_char
;
159 /* For longjmp to where kbd input is being done. */
160 static jmp_buf getcjmp
;
162 /* True while doing kbd input. */
163 int waiting_for_input
;
165 /* True while displaying for echoing. Delays C-g throwing. */
168 /* True means we can start echoing at the next input pause
169 even though there is something in the echo area. */
170 static char *ok_to_echo_at_next_pause
;
172 /* Nonzero means disregard local maps for the menu bar. */
173 static int inhibit_local_menu_bar_menus
;
175 /* Nonzero means C-g should cause immediate error-signal. */
178 /* The user's ERASE setting. */
179 Lisp_Object Vtty_erase_char
;
181 /* Character to recognize as the help char. */
182 Lisp_Object Vhelp_char
;
184 /* List of other event types to recognize as meaning "help". */
185 Lisp_Object Vhelp_event_list
;
187 /* Form to execute when help char is typed. */
188 Lisp_Object Vhelp_form
;
190 /* Command to run when the help character follows a prefix key. */
191 Lisp_Object Vprefix_help_command
;
193 /* List of items that should move to the end of the menu bar. */
194 Lisp_Object Vmenu_bar_final_items
;
196 /* Non-nil means show the equivalent key-binding for
197 any M-x command that has one.
198 The value can be a length of time to show the message for.
199 If the value is non-nil and not a number, we wait 2 seconds. */
200 Lisp_Object Vsuggest_key_bindings
;
202 /* Character that causes a quit. Normally C-g.
204 If we are running on an ordinary terminal, this must be an ordinary
205 ASCII char, since we want to make it our interrupt character.
207 If we are not running on an ordinary terminal, it still needs to be
208 an ordinary ASCII char. This character needs to be recognized in
209 the input interrupt handler. At this point, the keystroke is
210 represented as a struct input_event, while the desired quit
211 character is specified as a lispy event. The mapping from struct
212 input_events to lispy events cannot run in an interrupt handler,
213 and the reverse mapping is difficult for anything but ASCII
216 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
220 extern Lisp_Object current_global_map
;
221 extern int minibuf_level
;
223 /* If non-nil, this is a map that overrides all other local maps. */
224 Lisp_Object Voverriding_local_map
;
226 /* If non-nil, Voverriding_local_map applies to the menu bar. */
227 Lisp_Object Voverriding_local_map_menu_flag
;
229 /* Keymap that defines special misc events that should
230 be processed immediately at a low level. */
231 Lisp_Object Vspecial_event_map
;
233 /* Current depth in recursive edits. */
234 int command_loop_level
;
236 /* Total number of times command_loop has read a key sequence. */
239 /* Last input character read as a command. */
240 Lisp_Object last_command_char
;
242 /* Last input character read as a command, not counting menus
243 reached by the mouse. */
244 Lisp_Object last_nonmenu_event
;
246 /* Last input character read for any purpose. */
247 Lisp_Object last_input_char
;
249 /* If not Qnil, a list of objects to be read as subsequent command input. */
250 Lisp_Object Vunread_command_events
;
252 /* If not -1, an event to be read as subsequent command input. */
253 int unread_command_char
;
255 /* If not Qnil, this is a switch-frame event which we decided to put
256 off until the end of a key sequence. This should be read as the
257 next command input, after any unread_command_events.
259 read_key_sequence uses this to delay switch-frame events until the
260 end of the key sequence; Fread_char uses it to put off switch-frame
261 events until a non-ASCII event is acceptable as input. */
262 Lisp_Object unread_switch_frame
;
264 /* A mask of extra modifier bits to put into every keyboard char. */
265 int extra_keyboard_modifiers
;
267 /* Char to use as prefix when a meta character is typed in.
268 This is bound on entry to minibuffer in case ESC is changed there. */
270 Lisp_Object meta_prefix_char
;
272 /* Last size recorded for a current buffer which is not a minibuffer. */
273 static int last_non_minibuf_size
;
275 /* Number of idle seconds before an auto-save and garbage collection. */
276 static Lisp_Object Vauto_save_timeout
;
278 /* Total number of times read_char has returned. */
279 int num_input_events
;
281 /* Total number of times read_char has returned, outside of macros. */
282 int num_nonmacro_input_events
;
284 /* Auto-save automatically when this many characters have been typed
285 since the last time. */
287 static int auto_save_interval
;
289 /* Value of num_nonmacro_input_events as of last auto save. */
293 /* The command being executed by the command loop.
294 Commands may set this, and the value set will be copied into
295 current_kboard->Vlast_command instead of the actual command. */
296 Lisp_Object this_command
;
298 /* The value of point when the last command was executed. */
299 int last_point_position
;
301 /* The buffer that was current when the last command was started. */
302 Lisp_Object last_point_position_buffer
;
304 /* The frame in which the last input event occurred, or Qmacro if the
305 last event came from a macro. We use this to determine when to
306 generate switch-frame events. This may be cleared by functions
307 like Fselect_frame, to make sure that a switch-frame event is
308 generated by the next character. */
309 Lisp_Object internal_last_event_frame
;
311 /* A user-visible version of the above, intended to allow users to
312 figure out where the last event came from, if the event doesn't
313 carry that information itself (i.e. if it was a character). */
314 Lisp_Object Vlast_event_frame
;
316 /* The timestamp of the last input event we received from the X server.
317 X Windows wants this for selection ownership. */
318 unsigned long last_event_timestamp
;
320 Lisp_Object Qself_insert_command
;
321 Lisp_Object Qforward_char
;
322 Lisp_Object Qbackward_char
;
323 Lisp_Object Qundefined
;
324 Lisp_Object Qtimer_event_handler
;
326 /* read_key_sequence stores here the command definition of the
327 key sequence that it reads. */
328 Lisp_Object read_key_sequence_cmd
;
330 /* Form to evaluate (if non-nil) when Emacs is started. */
331 Lisp_Object Vtop_level
;
333 /* User-supplied string to translate input characters through. */
334 Lisp_Object Vkeyboard_translate_table
;
336 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
337 extern Lisp_Object Vfunction_key_map
;
339 /* Another keymap that maps key sequences into key sequences.
340 This one takes precedence over ordinary definitions. */
341 extern Lisp_Object Vkey_translation_map
;
343 /* Non-nil means deactivate the mark at end of this command. */
344 Lisp_Object Vdeactivate_mark
;
346 /* Menu bar specified in Lucid Emacs fashion. */
348 Lisp_Object Vlucid_menu_bar_dirty_flag
;
349 Lisp_Object Qrecompute_lucid_menubar
, Qactivate_menubar_hook
;
351 Lisp_Object Qecho_area_clear_hook
;
353 /* Hooks to run before and after each command. */
354 Lisp_Object Qpre_command_hook
, Vpre_command_hook
;
355 Lisp_Object Qpost_command_hook
, Vpost_command_hook
;
356 Lisp_Object Qcommand_hook_internal
, Vcommand_hook_internal
;
357 /* Hook run after a command if there's no more input soon. */
358 Lisp_Object Qpost_command_idle_hook
, Vpost_command_idle_hook
;
360 /* Delay time in microseconds before running post-command-idle-hook. */
361 int post_command_idle_delay
;
363 /* List of deferred actions to be performed at a later time.
364 The precise format isn't relevant here; we just check whether it is nil. */
365 Lisp_Object Vdeferred_action_list
;
367 /* Function to call to handle deferred actions, when there are any. */
368 Lisp_Object Vdeferred_action_function
;
369 Lisp_Object Qdeferred_action_function
;
371 /* File in which we write all commands we read. */
374 /* Nonzero if input is available. */
377 /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
378 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
382 extern char *pending_malloc_warning
;
384 /* Circular buffer for pre-read keyboard input. */
385 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
387 /* Vector to GCPRO the frames and windows mentioned in kbd_buffer.
389 The interrupt-level event handlers will never enqueue an event on a
390 frame which is not in Vframe_list, and once an event is dequeued,
391 internal_last_event_frame or the event itself points to the frame.
394 But while the event is sitting in the queue, it's completely
395 unprotected. Suppose the user types one command which will run for
396 a while and then delete a frame, and then types another event at
397 the frame that will be deleted, before the command gets around to
398 it. Suppose there are no references to this frame elsewhere in
399 Emacs, and a GC occurs before the second event is dequeued. Now we
400 have an event referring to a freed frame, which will crash Emacs
403 Similar things happen when an event on a scroll bar is enqueued; the
404 window may be deleted while the event is in the queue.
406 So, we use this vector to protect the frame_or_window field in the
407 event queue. That way, they'll be dequeued as dead frames or
408 windows, but still valid lisp objects.
410 If kbd_buffer[i].kind != no_event, then
411 (XVECTOR (kbd_buffer_frame_or_window)->contents[i]
412 == kbd_buffer[i].frame_or_window. */
413 static Lisp_Object kbd_buffer_frame_or_window
;
415 /* Pointer to next available character in kbd_buffer.
416 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
417 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the
418 next available char is in kbd_buffer[0]. */
419 static struct input_event
*kbd_fetch_ptr
;
421 /* Pointer to next place to store character in kbd_buffer. This
422 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
423 character should go in kbd_buffer[0]. */
424 static volatile struct input_event
*kbd_store_ptr
;
426 /* The above pair of variables forms a "queue empty" flag. When we
427 enqueue a non-hook event, we increment kbd_store_ptr. When we
428 dequeue a non-hook event, we increment kbd_fetch_ptr. We say that
429 there is input available iff the two pointers are not equal.
431 Why not just have a flag set and cleared by the enqueuing and
432 dequeuing functions? Such a flag could be screwed up by interrupts
433 at inopportune times. */
435 /* If this flag is non-nil, we check mouse_moved to see when the
436 mouse moves, and motion events will appear in the input stream.
437 Otherwise, mouse motion is ignored. */
438 static Lisp_Object do_mouse_tracking
;
440 /* Symbols to head events. */
441 Lisp_Object Qmouse_movement
;
442 Lisp_Object Qscroll_bar_movement
;
443 Lisp_Object Qswitch_frame
;
444 Lisp_Object Qdelete_frame
;
445 Lisp_Object Qiconify_frame
;
446 Lisp_Object Qmake_frame_visible
;
448 /* Symbols to denote kinds of events. */
449 Lisp_Object Qfunction_key
;
450 Lisp_Object Qmouse_click
;
452 Lisp_Object Qmouse_wheel
;
454 /* Lisp_Object Qmouse_movement; - also an event header */
456 /* Properties of event headers. */
457 Lisp_Object Qevent_kind
;
458 Lisp_Object Qevent_symbol_elements
;
460 /* menu item parts */
461 Lisp_Object Qmenu_alias
;
462 Lisp_Object Qmenu_enable
;
463 Lisp_Object QCenable
, QCvisible
, QChelp
, QCfilter
, QCbutton
, QCtoggle
, QCradio
;
464 extern Lisp_Object Vdefine_key_rebound_commands
;
465 extern Lisp_Object Qmenu_item
;
467 /* An event header symbol HEAD may have a property named
468 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
469 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
470 mask of modifiers applied to it. If present, this is used to help
471 speed up parse_modifiers. */
472 Lisp_Object Qevent_symbol_element_mask
;
474 /* An unmodified event header BASE may have a property named
475 Qmodifier_cache, which is an alist mapping modifier masks onto
476 modified versions of BASE. If present, this helps speed up
478 Lisp_Object Qmodifier_cache
;
480 /* Symbols to use for parts of windows. */
481 Lisp_Object Qmode_line
;
482 Lisp_Object Qvertical_line
;
483 Lisp_Object Qvertical_scroll_bar
;
484 Lisp_Object Qmenu_bar
;
486 Lisp_Object
recursive_edit_unwind (), command_loop ();
487 Lisp_Object
Fthis_command_keys ();
488 Lisp_Object Qextended_command_history
;
489 EMACS_TIME
timer_check ();
491 extern char *x_get_keysym_name ();
493 static void record_menu_key ();
495 void swallow_events ();
497 Lisp_Object Qpolling_period
;
499 /* List of absolute timers. Appears in order of next scheduled event. */
500 Lisp_Object Vtimer_list
;
502 /* List of idle time timers. Appears in order of next scheduled event. */
503 Lisp_Object Vtimer_idle_list
;
505 /* Incremented whenever a timer is run. */
508 extern Lisp_Object Vprint_level
, Vprint_length
;
510 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
512 EMACS_TIME
*input_available_clear_time
;
514 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
515 Default is 1 if INTERRUPT_INPUT is defined. */
518 /* Nonzero while interrupts are temporarily deferred during redisplay. */
519 int interrupts_deferred
;
521 /* Nonzero means use ^S/^Q for flow control. */
524 /* Allow m- file to inhibit use of FIONREAD. */
525 #ifdef BROKEN_FIONREAD
529 /* We are unable to use interrupts if FIONREAD is not available,
530 so flush SIGIO so we won't try. */
537 /* If we support a window system, turn on the code to poll periodically
538 to detect C-g. It isn't actually used when doing interrupt input. */
539 #ifdef HAVE_WINDOW_SYSTEM
540 #define POLL_FOR_INPUT
543 /* Global variable declarations. */
545 /* Function for init_keyboard to call with no args (if nonzero). */
546 void (*keyboard_init_hook
) ();
548 static int read_avail_input ();
549 static void get_input_pending ();
550 static int readable_events ();
551 static Lisp_Object
read_char_x_menu_prompt ();
552 static Lisp_Object
read_char_minibuf_menu_prompt ();
553 static Lisp_Object
make_lispy_event ();
555 static Lisp_Object
make_lispy_movement ();
557 static Lisp_Object
modify_event_symbol ();
558 static Lisp_Object
make_lispy_switch_frame ();
559 static int parse_solitary_modifier ();
561 /* > 0 if we are to echo keystrokes. */
562 static int echo_keystrokes
;
564 /* Nonzero means don't try to suspend even if the operating system seems
566 static int cannot_suspend
;
568 #define min(a,b) ((a)<(b)?(a):(b))
569 #define max(a,b) ((a)>(b)?(a):(b))
571 /* Install the string STR as the beginning of the string of echoing,
572 so that it serves as a prompt for the next character.
573 Also start echoing. */
578 int len
= strlen (str
);
580 if (len
> ECHOBUFSIZE
- 4)
581 len
= ECHOBUFSIZE
- 4;
582 bcopy (str
, current_kboard
->echobuf
, len
);
583 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
584 *current_kboard
->echoptr
= '\0';
586 current_kboard
->echo_after_prompt
= len
;
591 /* Add C to the echo string, if echoing is going on.
592 C can be a character, which is printed prettily ("M-C-x" and all that
593 jazz), or a symbol, whose name is printed. */
598 extern char *push_key_description ();
600 if (current_kboard
->immediate_echo
)
602 char *ptr
= current_kboard
->echoptr
;
604 if (ptr
!= current_kboard
->echobuf
)
607 /* If someone has passed us a composite event, use its head symbol. */
612 if (ptr
- current_kboard
->echobuf
> ECHOBUFSIZE
- 6)
615 ptr
= push_key_description (XINT (c
), ptr
);
617 else if (SYMBOLP (c
))
619 struct Lisp_String
*name
= XSYMBOL (c
)->name
;
620 if ((ptr
- current_kboard
->echobuf
) + STRING_BYTES (name
) + 4
623 bcopy (name
->data
, ptr
, STRING_BYTES (name
));
624 ptr
+= STRING_BYTES (name
);
627 if (current_kboard
->echoptr
== current_kboard
->echobuf
630 strcpy (ptr
, " (Type ? for further options)");
635 current_kboard
->echoptr
= ptr
;
641 /* Temporarily add a dash to the end of the echo string if it's not
642 empty, so that it serves as a mini-prompt for the very next character. */
646 if (!current_kboard
->immediate_echo
647 && current_kboard
->echoptr
== current_kboard
->echobuf
)
649 /* Do nothing if we just printed a prompt. */
650 if (current_kboard
->echo_after_prompt
651 == current_kboard
->echoptr
- current_kboard
->echobuf
)
653 /* Do nothing if not echoing at all. */
654 if (current_kboard
->echoptr
== 0)
657 /* Put a dash at the end of the buffer temporarily,
658 but make it go away when the next character is added. */
659 current_kboard
->echoptr
[0] = '-';
660 current_kboard
->echoptr
[1] = 0;
665 /* Display the current echo string, and begin echoing if not already
671 if (!current_kboard
->immediate_echo
)
674 current_kboard
->immediate_echo
= 1;
676 for (i
= 0; i
< this_command_key_count
; i
++)
679 c
= XVECTOR (this_command_keys
)->contents
[i
];
680 if (! (EVENT_HAS_PARAMETERS (c
)
681 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
688 message2_nolog (current_kboard
->echobuf
, strlen (current_kboard
->echobuf
),
689 ! NILP (current_buffer
->enable_multibyte_characters
));
693 if (waiting_for_input
&& !NILP (Vquit_flag
))
694 quit_throw_to_read_char ();
697 /* Turn off echoing, for the start of a new command. */
701 current_kboard
->immediate_echo
= 0;
702 current_kboard
->echoptr
= current_kboard
->echobuf
;
703 current_kboard
->echo_after_prompt
= -1;
704 ok_to_echo_at_next_pause
= 0;
707 /* Return the length of the current echo string. */
712 return current_kboard
->echoptr
- current_kboard
->echobuf
;
715 /* Truncate the current echo message to its first LEN chars.
716 This and echo_char get used by read_key_sequence when the user
717 switches frames while entering a key sequence. */
723 current_kboard
->echobuf
[len
] = '\0';
724 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
725 truncate_echo_area (len
);
729 /* Functions for manipulating this_command_keys. */
731 add_command_key (key
)
734 int size
= XVECTOR (this_command_keys
)->size
;
736 /* If reset-this-command-length was called recently, obey it now.
737 See the doc string of that function for an explanation of why. */
738 if (before_command_restore_flag
)
740 this_command_key_count
= before_command_key_count_1
;
741 if (this_command_key_count
< this_single_command_key_start
)
742 this_single_command_key_start
= this_command_key_count
;
743 echo_truncate (before_command_echo_length_1
);
744 before_command_restore_flag
= 0;
747 if (this_command_key_count
>= size
)
749 Lisp_Object new_keys
;
751 new_keys
= Fmake_vector (make_number (size
* 2), Qnil
);
752 bcopy (XVECTOR (this_command_keys
)->contents
,
753 XVECTOR (new_keys
)->contents
,
754 size
* sizeof (Lisp_Object
));
756 this_command_keys
= new_keys
;
759 XVECTOR (this_command_keys
)->contents
[this_command_key_count
++] = key
;
765 int count
= specpdl_ptr
- specpdl
;
768 if (command_loop_level
> 0)
770 specbind (Qstandard_output
, Qt
);
771 specbind (Qstandard_input
, Qt
);
774 val
= command_loop ();
776 Fsignal (Qquit
, Qnil
);
777 /* Handle throw from read_minibuf when using minibuffer
778 while it's active but we're in another window. */
780 Fsignal (Qerror
, Fcons (val
, Qnil
));
782 return unbind_to (count
, Qnil
);
785 /* When an auto-save happens, record the "time", and don't do again soon. */
790 last_auto_save
= num_nonmacro_input_events
;
793 /* Make an auto save happen as soon as possible at command level. */
795 force_auto_save_soon ()
797 last_auto_save
= - auto_save_interval
- 1;
799 record_asynch_buffer_change ();
802 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
803 "Invoke the editor command loop recursively.\n\
804 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
805 that tells this function to return.\n\
806 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
807 This function is called by the editor initialization to begin editing.")
810 int count
= specpdl_ptr
- specpdl
;
813 command_loop_level
++;
814 update_mode_lines
= 1;
816 record_unwind_protect (recursive_edit_unwind
,
818 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
822 return unbind_to (count
, Qnil
);
826 recursive_edit_unwind (buffer
)
830 Fset_buffer (buffer
);
832 command_loop_level
--;
833 update_mode_lines
= 1;
841 #if 0 /* Theory: if there's anything in Vunread_command_events,
842 it will right away be read by read_key_sequence,
843 and then if we do switch KBOARDS, it will go into the side
844 queue then. So we don't need to do anything special here -- rms. */
845 if (CONSP (Vunread_command_events
))
847 current_kboard
->kbd_queue
848 = nconc2 (Vunread_command_events
, current_kboard
->kbd_queue
);
849 current_kboard
->kbd_queue_has_data
= 1;
851 Vunread_command_events
= Qnil
;
857 /* Switch to the single-kboard state, making current_kboard
858 the only KBOARD from which further input is accepted. */
861 single_kboard_state ()
868 /* Maintain a stack of kboards, so other parts of Emacs
869 can switch temporarily to the kboard of a given frame
870 and then revert to the previous status. */
875 struct kboard_stack
*next
;
878 static struct kboard_stack
*kboard_stack
;
881 push_frame_kboard (f
)
885 struct kboard_stack
*p
886 = (struct kboard_stack
*) xmalloc (sizeof (struct kboard_stack
));
888 p
->next
= kboard_stack
;
889 p
->kboard
= current_kboard
;
892 current_kboard
= FRAME_KBOARD (f
);
900 struct kboard_stack
*p
= kboard_stack
;
901 current_kboard
= p
->kboard
;
902 kboard_stack
= p
->next
;
907 /* Handle errors that are not handled at inner levels
908 by printing an error message and returning to the editor command loop. */
914 Lisp_Object old_level
, old_length
;
917 if (!NILP (executing_macro
))
919 if (executing_macro_iterations
== 1)
920 sprintf (macroerror
, "After 1 kbd macro iteration: ");
922 sprintf (macroerror
, "After %d kbd macro iterations: ",
923 executing_macro_iterations
);
928 Vstandard_output
= Qt
;
929 Vstandard_input
= Qt
;
930 Vexecuting_macro
= Qnil
;
931 executing_macro
= Qnil
;
932 current_kboard
->Vprefix_arg
= Qnil
;
935 /* Avoid unquittable loop if data contains a circular list. */
936 old_level
= Vprint_level
;
937 old_length
= Vprint_length
;
938 XSETFASTINT (Vprint_level
, 10);
939 XSETFASTINT (Vprint_length
, 10);
940 cmd_error_internal (data
, macroerror
);
941 Vprint_level
= old_level
;
942 Vprint_length
= old_length
;
946 Vinhibit_quit
= Qnil
;
951 return make_number (0);
954 /* Take actions on handling an error. DATA is the data that describes
957 CONTEXT is a C-string containing ASCII characters only which
958 describes the context in which the error happened. If we need to
959 generalize CONTEXT to allow multibyte characters, make it a Lisp
963 cmd_error_internal (data
, context
)
971 echo_area_glyphs
= 0;
973 /* If the window system or terminal frame hasn't been initialized
974 yet, or we're not interactive, it's best to dump this message out
975 to stderr and exit. */
976 if (! FRAME_MESSAGE_BUF (selected_frame
)
978 stream
= Qexternal_debugging_output
;
987 write_string_1 (context
, -1, stream
);
989 print_error_message (data
, stream
);
991 /* If the window system or terminal frame hasn't been initialized
992 yet, or we're in -batch mode, this error should cause Emacs to exit. */
993 if (! FRAME_MESSAGE_BUF (selected_frame
)
997 Fkill_emacs (make_number (-1));
1001 Lisp_Object
command_loop_1 ();
1002 Lisp_Object
command_loop_2 ();
1003 Lisp_Object
top_level_1 ();
1005 /* Entry to editor-command-loop.
1006 This level has the catches for exiting/returning to editor command loop.
1007 It returns nil to exit recursive edit, t to abort it. */
1012 if (command_loop_level
> 0 || minibuf_level
> 0)
1014 return internal_catch (Qexit
, command_loop_2
, Qnil
);
1019 internal_catch (Qtop_level
, top_level_1
, Qnil
);
1020 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
1022 /* End of file in -batch run causes exit here. */
1028 /* Here we catch errors in execution of commands within the
1029 editing loop, and reenter the editing loop.
1030 When there is an error, cmd_error runs and returns a non-nil
1031 value to us. A value of nil means that cmd_loop_1 itself
1032 returned due to end of file (or end of kbd macro). */
1037 register Lisp_Object val
;
1040 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
1041 while (!NILP (val
));
1049 return Feval (Vtop_level
);
1055 /* On entry to the outer level, run the startup file */
1056 if (!NILP (Vtop_level
))
1057 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
1058 else if (!NILP (Vpurify_flag
))
1059 message ("Bare impure Emacs (standard Lisp code not loaded)");
1061 message ("Bare Emacs (standard Lisp code not loaded)");
1065 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
1066 "Exit all recursive editing levels.")
1069 Fthrow (Qtop_level
, Qnil
);
1072 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
1073 "Exit from the innermost recursive edit or minibuffer.")
1076 if (command_loop_level
> 0 || minibuf_level
> 0)
1077 Fthrow (Qexit
, Qnil
);
1079 error ("No recursive edit is in progress");
1082 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
1083 "Abort the command that requested this recursive edit or minibuffer input.")
1086 if (command_loop_level
> 0 || minibuf_level
> 0)
1089 error ("No recursive edit is in progress");
1092 /* This is the actual command reading loop,
1093 sans error-handling encapsulation. */
1095 Lisp_Object
Fcommand_execute ();
1096 static int read_key_sequence ();
1097 void safe_run_hooks ();
1102 Lisp_Object cmd
, tem
;
1105 Lisp_Object keybuf
[30];
1110 struct buffer
*prev_buffer
;
1112 int was_locked
= single_kboard
;
1115 current_kboard
->Vprefix_arg
= Qnil
;
1116 Vdeactivate_mark
= Qnil
;
1117 waiting_for_input
= 0;
1122 this_command_key_count
= 0;
1123 this_single_command_key_start
= 0;
1125 /* Make sure this hook runs after commands that get errors and
1126 throw to top level. */
1127 /* Note that the value cell will never directly contain nil
1128 if the symbol is a local variable. */
1129 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1130 safe_run_hooks (Qpost_command_hook
);
1132 if (!NILP (Vdeferred_action_list
))
1133 call0 (Vdeferred_action_function
);
1135 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1137 if (NILP (Vunread_command_events
)
1138 && NILP (Vexecuting_macro
)
1139 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1, 1)))
1140 safe_run_hooks (Qpost_command_idle_hook
);
1143 /* Do this after running Vpost_command_hook, for consistency. */
1144 current_kboard
->Vlast_command
= this_command
;
1148 /* Make sure the current window's buffer is selected. */
1149 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1150 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1152 /* Display any malloc warning that just came out. Use while because
1153 displaying one warning can cause another. */
1155 while (pending_malloc_warning
)
1156 display_malloc_warning ();
1160 Vdeactivate_mark
= Qnil
;
1162 /* If minibuffer on and echo area in use,
1163 wait 2 sec and redraw minibuffer. */
1165 if (minibuf_level
&& echo_area_glyphs
1166 && EQ (minibuf_window
, echo_area_window
))
1168 /* Bind inhibit-quit to t so that C-g gets read in
1169 rather than quitting back to the minibuffer. */
1170 int count
= specpdl_ptr
- specpdl
;
1171 specbind (Qinhibit_quit
, Qt
);
1173 Fsit_for (make_number (2), Qnil
, Qnil
);
1174 /* Clear the echo area. */
1176 safe_run_hooks (Qecho_area_clear_hook
);
1178 unbind_to (count
, Qnil
);
1180 /* If a C-g came in before, treat it as input now. */
1181 if (!NILP (Vquit_flag
))
1184 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1189 alloca (0); /* Cause a garbage collection now */
1190 /* Since we can free the most stuff here. */
1191 #endif /* C_ALLOCA */
1194 /* Select the frame that the last event came from. Usually,
1195 switch-frame events will take care of this, but if some lisp
1196 code swallows a switch-frame event, we'll fix things up here.
1197 Is this a good idea? */
1198 if (FRAMEP (internal_last_event_frame
)
1199 && XFRAME (internal_last_event_frame
) != selected_frame
)
1200 Fselect_frame (internal_last_event_frame
, Qnil
);
1202 /* If it has changed current-menubar from previous value,
1203 really recompute the menubar from the value. */
1204 if (! NILP (Vlucid_menu_bar_dirty_flag
)
1205 && !NILP (Ffboundp (Qrecompute_lucid_menubar
)))
1206 call0 (Qrecompute_lucid_menubar
);
1208 before_command_key_count
= this_command_key_count
;
1209 before_command_echo_length
= echo_length ();
1211 this_command
= Qnil
;
1213 /* Read next key sequence; i gets its length. */
1214 i
= read_key_sequence (keybuf
, sizeof keybuf
/ sizeof keybuf
[0],
1217 /* A filter may have run while we were reading the input. */
1218 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1219 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1223 /* Now we have read a key sequence of length I,
1224 or else I is 0 and we found end of file. */
1226 if (i
== 0) /* End of file -- happens only in */
1227 return Qnil
; /* a kbd macro, at the end. */
1228 /* -1 means read_key_sequence got a menu that was rejected.
1229 Just loop around and read another command. */
1233 this_command_key_count
= 0;
1234 this_single_command_key_start
= 0;
1238 last_command_char
= keybuf
[i
- 1];
1240 /* If the previous command tried to force a specific window-start,
1241 forget about that, in case this command moves point far away
1242 from that position. But also throw away beg_unchanged and
1243 end_unchanged information in that case, so that redisplay will
1244 update the whole window properly. */
1245 if (!NILP (XWINDOW (selected_window
)->force_start
))
1247 XWINDOW (selected_window
)->force_start
= Qnil
;
1248 beg_unchanged
= end_unchanged
= 0;
1251 cmd
= read_key_sequence_cmd
;
1252 if (!NILP (Vexecuting_macro
))
1254 if (!NILP (Vquit_flag
))
1256 Vexecuting_macro
= Qt
;
1257 QUIT
; /* Make some noise. */
1258 /* Will return since macro now empty. */
1262 /* Do redisplay processing after this command except in special
1263 cases identified below that set no_redisplay to 1.
1264 (actually, there's currently no way to prevent the redisplay,
1265 and no_redisplay is ignored.
1266 Perhaps someday we will really implement it.) */
1269 prev_buffer
= current_buffer
;
1270 prev_modiff
= MODIFF
;
1271 last_point_position
= PT
;
1272 XSETBUFFER (last_point_position_buffer
, prev_buffer
);
1274 /* Execute the command. */
1277 /* Note that the value cell will never directly contain nil
1278 if the symbol is a local variable. */
1279 if (!NILP (Vpre_command_hook
) && !NILP (Vrun_hooks
))
1280 safe_run_hooks (Qpre_command_hook
);
1282 if (NILP (this_command
))
1284 /* nil means key is undefined. */
1286 current_kboard
->defining_kbd_macro
= Qnil
;
1287 update_mode_lines
= 1;
1288 current_kboard
->Vprefix_arg
= Qnil
;
1292 if (NILP (current_kboard
->Vprefix_arg
) && ! no_direct
)
1294 /* Recognize some common commands in common situations and
1295 do them directly. */
1296 if (EQ (this_command
, Qforward_char
) && PT
< ZV
)
1298 struct Lisp_Char_Table
*dp
1299 = window_display_table (XWINDOW (selected_window
));
1300 lose
= FETCH_BYTE (PT_BYTE
);
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 /* To extract the case of continuation on
1309 wide-column characters. */
1310 && (WIDTH_BY_CHAR_HEAD (FETCH_BYTE (PT_BYTE
)) == 1)
1311 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1313 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1315 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1317 && !windows_or_buffers_changed
1318 && EQ (current_buffer
->selective_display
, Qnil
)
1319 && !detect_input_pending ()
1320 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1321 && NILP (Vexecuting_macro
))
1322 no_redisplay
= direct_output_forward_char (1);
1325 else if (EQ (this_command
, Qbackward_char
) && PT
> BEGV
)
1327 struct Lisp_Char_Table
*dp
1328 = window_display_table (XWINDOW (selected_window
));
1330 lose
= FETCH_BYTE (PT_BYTE
);
1332 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1333 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1334 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1335 && (lose
>= 0x20 && lose
< 0x7f)))
1336 : (lose
>= 0x20 && lose
< 0x7f))
1337 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1339 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1341 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1343 && !windows_or_buffers_changed
1344 && EQ (current_buffer
->selective_display
, Qnil
)
1345 && !detect_input_pending ()
1346 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1347 && NILP (Vexecuting_macro
))
1348 no_redisplay
= direct_output_forward_char (-1);
1351 else if (EQ (this_command
, Qself_insert_command
)
1352 /* Try this optimization only on ascii keystrokes. */
1353 && INTEGERP (last_command_char
))
1355 unsigned int c
= XINT (last_command_char
);
1358 if (NILP (Vexecuting_macro
)
1359 && !EQ (minibuf_window
, selected_window
))
1361 if (!nonundocount
|| nonundocount
>= 20)
1368 lose
= ((XFASTINT (XWINDOW (selected_window
)->last_modified
)
1370 || (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1372 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1374 || MODIFF
<= SAVE_MODIFF
1375 || windows_or_buffers_changed
1376 || !EQ (current_buffer
->selective_display
, Qnil
)
1377 || detect_input_pending ()
1378 || !NILP (XWINDOW (selected_window
)->column_number_displayed
)
1379 || !NILP (Vexecuting_macro
));
1380 value
= internal_self_insert (c
, 0);
1387 && (PT
== ZV
|| FETCH_BYTE (PT_BYTE
) == '\n'))
1389 struct Lisp_Char_Table
*dp
1390 = window_display_table (XWINDOW (selected_window
));
1393 /* Add the offset to the character, for Finsert_char.
1394 We pass internal_self_insert the unmodified character
1395 because it itself does this offsetting. */
1396 if (! NILP (current_buffer
->enable_multibyte_characters
))
1397 lose
= unibyte_char_to_multibyte (lose
);
1403 obj
= DISP_CHAR_VECTOR (dp
, lose
);
1406 /* Do it only for char codes
1407 that by default display as themselves. */
1408 if (lose
>= 0x20 && lose
<= 0x7e)
1409 no_redisplay
= direct_output_for_insert (lose
);
1411 else if (VECTORP (obj
)
1412 && XVECTOR (obj
)->size
== 1
1413 && (obj
= XVECTOR (obj
)->contents
[0],
1415 /* Insist face not specified in glyph. */
1416 && (XINT (obj
) & ((-1) << 8)) == 0)
1418 = direct_output_for_insert (XINT (obj
));
1422 if (lose
>= 0x20 && lose
<= 0x7e)
1423 no_redisplay
= direct_output_for_insert (lose
);
1430 /* Here for a command that isn't executed directly */
1433 if (NILP (current_kboard
->Vprefix_arg
))
1435 Fcommand_execute (this_command
, Qnil
, Qnil
, Qnil
);
1440 /* Note that the value cell will never directly contain nil
1441 if the symbol is a local variable. */
1442 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1443 safe_run_hooks (Qpost_command_hook
);
1445 if (!NILP (Vdeferred_action_list
))
1446 safe_run_hooks (Qdeferred_action_function
);
1448 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1450 if (NILP (Vunread_command_events
)
1451 && NILP (Vexecuting_macro
)
1452 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1, 1)))
1453 safe_run_hooks (Qpost_command_idle_hook
);
1456 /* If there is a prefix argument,
1457 1) We don't want Vlast_command to be ``universal-argument''
1458 (that would be dumb), so don't set Vlast_command,
1459 2) we want to leave echoing on so that the prefix will be
1460 echoed as part of this key sequence, so don't call
1462 3) we want to leave this_command_key_count non-zero, so that
1463 read_char will realize that it is re-reading a character, and
1464 not echo it a second time.
1466 If the command didn't actually create a prefix arg,
1467 but is merely a frame event that is transparent to prefix args,
1468 then the above doesn't apply. */
1469 if (NILP (current_kboard
->Vprefix_arg
) || CONSP (last_command_char
))
1471 current_kboard
->Vlast_command
= this_command
;
1473 this_command_key_count
= 0;
1474 this_single_command_key_start
= 0;
1477 if (!NILP (current_buffer
->mark_active
) && !NILP (Vrun_hooks
))
1479 if (!NILP (Vdeactivate_mark
) && !NILP (Vtransient_mark_mode
))
1481 current_buffer
->mark_active
= Qnil
;
1482 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
1484 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
1485 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
1489 /* Install chars successfully executed in kbd macro. */
1491 if (!NILP (current_kboard
->defining_kbd_macro
)
1492 && NILP (current_kboard
->Vprefix_arg
))
1493 finalize_kbd_macro_chars ();
1497 any_kboard_state ();
1502 /* Subroutine for safe_run_hooks: run the hook HOOK. */
1505 safe_run_hooks_1 (hook
)
1508 return call1 (Vrun_hooks
, Vinhibit_quit
);
1511 /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */
1514 safe_run_hooks_error (data
)
1517 Fset (Vinhibit_quit
, Qnil
);
1520 /* If we get an error while running the hook, cause the hook variable
1521 to be nil. Also inhibit quits, so that C-g won't cause the hook
1522 to mysteriously evaporate. */
1525 safe_run_hooks (hook
)
1529 int count
= specpdl_ptr
- specpdl
;
1530 specbind (Qinhibit_quit
, hook
);
1532 internal_condition_case (safe_run_hooks_1
, Qt
, safe_run_hooks_error
);
1534 unbind_to (count
, Qnil
);
1537 /* Number of seconds between polling for input. */
1540 /* Nonzero means polling for input is temporarily suppressed. */
1541 int poll_suppress_count
;
1543 /* Nonzero if polling_for_input is actually being used. */
1544 int polling_for_input
;
1546 #ifdef POLL_FOR_INPUT
1548 /* Handle an alarm once each second and read pending input
1549 so as to handle a C-g if it comces in. */
1552 input_poll_signal (signalnum
) /* If we don't have an argument, */
1553 int signalnum
; /* some compilers complain in signal calls. */
1555 /* This causes the call to start_polling at the end
1556 to do its job. It also arranges for a quit or error
1557 from within read_avail_input to resume polling. */
1558 poll_suppress_count
++;
1559 if (interrupt_input_blocked
== 0
1560 && !waiting_for_input
)
1561 read_avail_input (0);
1562 /* Turn on the SIGALRM handler and request another alarm. */
1568 /* Begin signals to poll for input, if they are appropriate.
1569 This function is called unconditionally from various places. */
1574 #ifdef POLL_FOR_INPUT
1575 if (read_socket_hook
&& !interrupt_input
)
1577 poll_suppress_count
--;
1578 if (poll_suppress_count
== 0)
1580 signal (SIGALRM
, input_poll_signal
);
1581 polling_for_input
= 1;
1582 alarm (polling_period
);
1588 /* Nonzero if we are using polling to handle input asynchronously. */
1591 input_polling_used ()
1593 #ifdef POLL_FOR_INPUT
1594 return read_socket_hook
&& !interrupt_input
;
1600 /* Turn off polling. */
1605 #ifdef POLL_FOR_INPUT
1606 if (read_socket_hook
&& !interrupt_input
)
1608 if (poll_suppress_count
== 0)
1610 polling_for_input
= 0;
1613 poll_suppress_count
++;
1618 /* Set the value of poll_suppress_count to COUNT
1619 and start or stop polling accordingly. */
1622 set_poll_suppress_count (count
)
1625 #ifdef POLL_FOR_INPUT
1626 if (count
== 0 && poll_suppress_count
!= 0)
1628 poll_suppress_count
= 1;
1631 else if (count
!= 0 && poll_suppress_count
== 0)
1635 poll_suppress_count
= count
;
1639 /* Bind polling_period to a value at least N.
1640 But don't decrease it. */
1643 bind_polling_period (n
)
1646 #ifdef POLL_FOR_INPUT
1647 int new = polling_period
;
1653 specbind (Qpolling_period
, make_number (new));
1654 /* Start a new alarm with the new period. */
1659 /* Apply the control modifier to CHARACTER. */
1665 /* Save the upper bits here. */
1666 int upper
= c
& ~0177;
1670 /* Everything in the columns containing the upper-case letters
1671 denotes a control character. */
1672 if (c
>= 0100 && c
< 0140)
1676 /* Set the shift modifier for a control char
1677 made from a shifted letter. But only for letters! */
1678 if (oc
>= 'A' && oc
<= 'Z')
1679 c
|= shift_modifier
;
1682 /* The lower-case letters denote control characters too. */
1683 else if (c
>= 'a' && c
<= 'z')
1686 /* Include the bits for control and shift
1687 only if the basic ASCII code can't indicate them. */
1691 /* Replace the high bits. */
1692 c
|= (upper
& ~ctrl_modifier
);
1699 /* Input of single characters from keyboard */
1701 Lisp_Object
print_help ();
1702 static Lisp_Object
kbd_buffer_get_event ();
1703 static void record_char ();
1706 static jmp_buf wrong_kboard_jmpbuf
;
1709 /* read a character from the keyboard; call the redisplay if needed */
1710 /* commandflag 0 means do not do auto-saving, but do do redisplay.
1711 -1 means do not do redisplay, but do do autosaving.
1714 /* The arguments MAPS and NMAPS are for menu prompting.
1715 MAPS is an array of keymaps; NMAPS is the length of MAPS.
1717 PREV_EVENT is the previous input event, or nil if we are reading
1718 the first event of a key sequence.
1720 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
1721 if we used a mouse menu to read the input, or zero otherwise. If
1722 USED_MOUSE_MENU is null, we don't dereference it.
1724 Value is t if we showed a menu and the user rejected it. */
1727 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
)
1731 Lisp_Object prev_event
;
1732 int *used_mouse_menu
;
1736 jmp_buf local_getcjmp
;
1738 int key_already_recorded
= 0;
1739 Lisp_Object tem
, save
;
1740 Lisp_Object also_record
;
1741 struct gcpro gcpro1
;
1745 before_command_key_count
= this_command_key_count
;
1746 before_command_echo_length
= echo_length ();
1753 if (CONSP (Vunread_command_events
))
1755 c
= XCONS (Vunread_command_events
)->car
;
1756 Vunread_command_events
= XCONS (Vunread_command_events
)->cdr
;
1758 /* Undo what read_char_x_menu_prompt did when it unread
1759 additional keys returned by Fx_popup_menu. */
1761 && (SYMBOLP (XCONS (c
)->car
) || INTEGERP (XCONS (c
)->car
))
1762 && NILP (XCONS (c
)->cdr
))
1765 if (this_command_key_count
== 0)
1771 if (unread_command_char
!= -1)
1773 XSETINT (c
, unread_command_char
);
1774 unread_command_char
= -1;
1776 if (this_command_key_count
== 0)
1782 /* If there is no function key translated before
1783 reset-this-command-lengths takes effect, forget about it. */
1784 before_command_restore_flag
= 0;
1786 if (!NILP (Vexecuting_macro
))
1788 /* We set this to Qmacro; since that's not a frame, nobody will
1789 try to switch frames on us, and the selected window will
1792 Since this event came from a macro, it would be misleading to
1793 leave internal_last_event_frame set to wherever the last
1794 real event came from. Normally, a switch-frame event selects
1795 internal_last_event_frame after each command is read, but
1796 events read from a macro should never cause a new frame to be
1798 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
1800 /* Exit the macro if we are at the end.
1801 Also, some things replace the macro with t
1802 to force an early exit. */
1803 if (EQ (Vexecuting_macro
, Qt
)
1804 || executing_macro_index
>= XFASTINT (Flength (Vexecuting_macro
)))
1810 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
1811 if (STRINGP (Vexecuting_macro
)
1812 && (XINT (c
) & 0x80))
1813 XSETFASTINT (c
, CHAR_META
| (XINT (c
) & ~0x80));
1815 executing_macro_index
++;
1820 if (!NILP (unread_switch_frame
))
1822 c
= unread_switch_frame
;
1823 unread_switch_frame
= Qnil
;
1825 /* This event should make it into this_command_keys, and get echoed
1826 again, so we go to reread_first, rather than reread. */
1830 if (commandflag
>= 0)
1833 || detect_input_pending_run_timers (0))
1840 /* Message turns off echoing unless more keystrokes turn it on again. */
1841 if (echo_area_glyphs
&& *echo_area_glyphs
1842 && echo_area_glyphs
!= current_kboard
->echobuf
1843 && ok_to_echo_at_next_pause
!= echo_area_glyphs
)
1846 /* If already echoing, continue. */
1849 /* Try reading a character via menu prompting in the minibuf.
1850 Try this before the sit-for, because the sit-for
1851 would do the wrong thing if we are supposed to do
1852 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
1853 after a mouse event so don't try a minibuf menu. */
1855 if (nmaps
> 0 && INTERACTIVE
1856 && !NILP (prev_event
) && ! EVENT_HAS_PARAMETERS (prev_event
)
1857 /* Don't bring up a menu if we already have another event. */
1858 && NILP (Vunread_command_events
)
1859 && unread_command_char
< 0
1860 && !detect_input_pending_run_timers (0))
1862 c
= read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
);
1865 key_already_recorded
= 1;
1870 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet.
1871 We will do that below, temporarily for short sections of code,
1872 when appropriate. local_getcjmp must be in effect
1873 around any call to sit_for or kbd_buffer_get_event;
1874 it *must not* be in effect when we call redisplay. */
1876 if (_setjmp (local_getcjmp
))
1878 XSETINT (c
, quit_char
);
1879 XSETFRAME (internal_last_event_frame
, selected_frame
);
1880 Vlast_event_frame
= internal_last_event_frame
;
1881 /* If we report the quit char as an event,
1882 don't do so more than once. */
1883 if (!NILP (Vinhibit_quit
))
1888 KBOARD
*kb
= FRAME_KBOARD (selected_frame
);
1889 if (kb
!= current_kboard
)
1891 Lisp_Object
*tailp
= &kb
->kbd_queue
;
1892 /* We shouldn't get here if we were in single-kboard mode! */
1895 while (CONSP (*tailp
))
1896 tailp
= &XCONS (*tailp
)->cdr
;
1899 *tailp
= Fcons (c
, Qnil
);
1900 kb
->kbd_queue_has_data
= 1;
1901 current_kboard
= kb
;
1902 /* This is going to exit from read_char
1903 so we had better get rid of this frame's stuff. */
1905 longjmp (wrong_kboard_jmpbuf
, 1);
1912 timer_start_idle ();
1914 /* If in middle of key sequence and minibuffer not active,
1915 start echoing if enough time elapses. */
1917 if (minibuf_level
== 0 && !current_kboard
->immediate_echo
1918 && this_command_key_count
> 0
1920 && echo_keystrokes
> 0
1921 && (echo_area_glyphs
== 0 || *echo_area_glyphs
== 0
1922 || ok_to_echo_at_next_pause
== echo_area_glyphs
))
1926 /* After a mouse event, start echoing right away.
1927 This is because we are probably about to display a menu,
1928 and we don't want to delay before doing so. */
1929 if (EVENT_HAS_PARAMETERS (prev_event
))
1933 save_getcjmp (save_jump
);
1934 restore_getcjmp (local_getcjmp
);
1935 tem0
= sit_for (echo_keystrokes
, 0, 1, 1, 0);
1936 restore_getcjmp (save_jump
);
1938 && ! CONSP (Vunread_command_events
))
1943 /* Maybe auto save due to number of keystrokes. */
1945 if (commandflag
!= 0
1946 && auto_save_interval
> 0
1947 && num_nonmacro_input_events
- last_auto_save
> max (auto_save_interval
, 20)
1948 && !detect_input_pending_run_timers (0))
1950 Fdo_auto_save (Qnil
, Qnil
);
1951 /* Hooks can actually change some buffers in auto save. */
1955 /* Try reading using an X menu.
1956 This is never confused with reading using the minibuf
1957 because the recursive call of read_char in read_char_minibuf_menu_prompt
1958 does not pass on any keymaps. */
1960 if (nmaps
> 0 && INTERACTIVE
1961 && !NILP (prev_event
)
1962 && EVENT_HAS_PARAMETERS (prev_event
)
1963 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
)
1964 /* Don't bring up a menu if we already have another event. */
1965 && NILP (Vunread_command_events
)
1966 && unread_command_char
< 0)
1968 c
= read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
1970 /* Now that we have read an event, Emacs is not idle. */
1976 /* Maybe autosave and/or garbage collect due to idleness. */
1978 if (INTERACTIVE
&& NILP (c
))
1980 int delay_level
, buffer_size
;
1982 /* Slow down auto saves logarithmically in size of current buffer,
1983 and garbage collect while we're at it. */
1984 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
1985 last_non_minibuf_size
= Z
- BEG
;
1986 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
1988 while (buffer_size
> 64)
1989 delay_level
++, buffer_size
-= buffer_size
>> 2;
1990 if (delay_level
< 4) delay_level
= 4;
1991 /* delay_level is 4 for files under around 50k, 7 at 100k,
1992 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
1994 /* Auto save if enough time goes by without input. */
1995 if (commandflag
!= 0
1996 && num_nonmacro_input_events
> last_auto_save
1997 && INTEGERP (Vauto_save_timeout
)
1998 && XINT (Vauto_save_timeout
) > 0)
2002 save_getcjmp (save_jump
);
2003 restore_getcjmp (local_getcjmp
);
2004 tem0
= sit_for (delay_level
* XFASTINT (Vauto_save_timeout
) / 4,
2006 restore_getcjmp (save_jump
);
2009 && ! CONSP (Vunread_command_events
))
2011 Fdo_auto_save (Qnil
, Qnil
);
2013 /* If we have auto-saved and there is still no input
2014 available, garbage collect if there has been enough
2015 consing going on to make it worthwhile. */
2016 if (!detect_input_pending_run_timers (0)
2017 && consing_since_gc
> gc_cons_threshold
/ 2)
2018 Fgarbage_collect ();
2025 /* If this has become non-nil here, it has been set by a timer
2026 or sentinel or filter. */
2027 if (CONSP (Vunread_command_events
))
2029 c
= XCONS (Vunread_command_events
)->car
;
2030 Vunread_command_events
= XCONS (Vunread_command_events
)->cdr
;
2033 /* Read something from current KBOARD's side queue, if possible. */
2037 if (current_kboard
->kbd_queue_has_data
)
2039 if (!CONSP (current_kboard
->kbd_queue
))
2041 c
= XCONS (current_kboard
->kbd_queue
)->car
;
2042 current_kboard
->kbd_queue
2043 = XCONS (current_kboard
->kbd_queue
)->cdr
;
2044 if (NILP (current_kboard
->kbd_queue
))
2045 current_kboard
->kbd_queue_has_data
= 0;
2046 input_pending
= readable_events (0);
2047 if (EVENT_HAS_PARAMETERS (c
)
2048 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qswitch_frame
))
2049 internal_last_event_frame
= XCONS (XCONS (c
)->cdr
)->car
;
2050 Vlast_event_frame
= internal_last_event_frame
;
2055 /* If current_kboard's side queue is empty check the other kboards.
2056 If one of them has data that we have not yet seen here,
2057 switch to it and process the data waiting for it.
2059 Note: if the events queued up for another kboard
2060 have already been seen here, and therefore are not a complete command,
2061 the kbd_queue_has_data field is 0, so we skip that kboard here.
2062 That's to avoid an infinite loop switching between kboards here. */
2063 if (NILP (c
) && !single_kboard
)
2066 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2067 if (kb
->kbd_queue_has_data
)
2069 current_kboard
= kb
;
2070 /* This is going to exit from read_char
2071 so we had better get rid of this frame's stuff. */
2073 longjmp (wrong_kboard_jmpbuf
, 1);
2082 /* Finally, we read from the main queue,
2083 and if that gives us something we can't use yet, we put it on the
2084 appropriate side queue and try again. */
2090 /* Actually read a character, waiting if necessary. */
2091 save_getcjmp (save_jump
);
2092 restore_getcjmp (local_getcjmp
);
2093 c
= kbd_buffer_get_event (&kb
, used_mouse_menu
);
2094 restore_getcjmp (save_jump
);
2097 if (! NILP (c
) && (kb
!= current_kboard
))
2099 Lisp_Object
*tailp
= &kb
->kbd_queue
;
2100 while (CONSP (*tailp
))
2101 tailp
= &XCONS (*tailp
)->cdr
;
2104 *tailp
= Fcons (c
, Qnil
);
2105 kb
->kbd_queue_has_data
= 1;
2109 current_kboard
= kb
;
2110 /* This is going to exit from read_char
2111 so we had better get rid of this frame's stuff. */
2113 longjmp (wrong_kboard_jmpbuf
, 1);
2118 /* Terminate Emacs in batch mode if at eof. */
2119 if (noninteractive
&& INTEGERP (c
) && XINT (c
) < 0)
2120 Fkill_emacs (make_number (1));
2124 /* Add in any extra modifiers, where appropriate. */
2125 if ((extra_keyboard_modifiers
& CHAR_CTL
)
2126 || ((extra_keyboard_modifiers
& 0177) < ' '
2127 && (extra_keyboard_modifiers
& 0177) != 0))
2128 XSETINT (c
, make_ctrl_char (XINT (c
)));
2130 /* Transfer any other modifier bits directly from
2131 extra_keyboard_modifiers to c. Ignore the actual character code
2132 in the low 16 bits of extra_keyboard_modifiers. */
2133 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
2144 if (commandflag
>= 0
2145 && !input_pending
&& !detect_input_pending_run_timers (0))
2153 /* Buffer switch events are only for internal wakeups
2154 so don't show them to the user.
2155 Also, don't record a key if we already did. */
2156 if (BUFFERP (c
) || key_already_recorded
)
2159 /* Process special events within read_char
2160 and loop around to read another event. */
2163 tem
= get_keyelt (access_keymap (get_keymap_1 (Vspecial_event_map
, 0, 0),
2169 int was_locked
= single_kboard
;
2171 last_input_char
= c
;
2172 Fcommand_execute (tem
, Qnil
, Fvector (1, &last_input_char
), Qt
);
2174 /* Resume allowing input from any kboard, if that was true before. */
2176 any_kboard_state ();
2181 /* Wipe the echo area. */
2182 if (echo_area_glyphs
)
2183 safe_run_hooks (Qecho_area_clear_hook
);
2184 echo_area_glyphs
= 0;
2186 /* Handle things that only apply to characters. */
2189 /* If kbd_buffer_get_event gave us an EOF, return that. */
2193 if ((STRINGP (Vkeyboard_translate_table
)
2194 && XSTRING (Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
2195 || (VECTORP (Vkeyboard_translate_table
)
2196 && XVECTOR (Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
2197 || (CHAR_TABLE_P (Vkeyboard_translate_table
)
2198 && CHAR_TABLE_ORDINARY_SLOTS
> (unsigned) XFASTINT (c
)))
2201 d
= Faref (Vkeyboard_translate_table
, c
);
2202 /* nil in keyboard-translate-table means no translation. */
2208 /* If this event is a mouse click in the menu bar,
2209 return just menu-bar for now. Modify the mouse click event
2210 so we won't do this twice, then queue it up. */
2211 if (EVENT_HAS_PARAMETERS (c
)
2212 && CONSP (XCONS (c
)->cdr
)
2213 && CONSP (EVENT_START (c
))
2214 && CONSP (XCONS (EVENT_START (c
))->cdr
))
2218 posn
= POSN_BUFFER_POSN (EVENT_START (c
));
2219 /* Handle menu-bar events:
2220 insert the dummy prefix event `menu-bar'. */
2221 if (EQ (posn
, Qmenu_bar
))
2223 /* Change menu-bar to (menu-bar) as the event "position". */
2224 POSN_BUFFER_POSN (EVENT_START (c
)) = Fcons (posn
, Qnil
);
2227 Vunread_command_events
= Fcons (c
, Vunread_command_events
);
2233 if (! NILP (also_record
))
2234 record_char (also_record
);
2239 before_command_key_count
= this_command_key_count
;
2240 before_command_echo_length
= echo_length ();
2242 /* Don't echo mouse motion events. */
2244 && ! (EVENT_HAS_PARAMETERS (c
)
2245 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
2248 if (! NILP (also_record
))
2249 echo_char (also_record
);
2250 /* Once we reread a character, echoing can happen
2251 the next time we pause to read a new one. */
2252 ok_to_echo_at_next_pause
= echo_area_glyphs
;
2255 /* Record this character as part of the current key. */
2256 add_command_key (c
);
2257 if (! NILP (also_record
))
2258 add_command_key (also_record
);
2260 /* Re-reading in the middle of a command */
2262 last_input_char
= c
;
2265 /* Process the help character specially if enabled */
2266 if (!NILP (Vhelp_form
) && help_char_p (c
))
2269 count
= specpdl_ptr
- specpdl
;
2271 record_unwind_protect (Fset_window_configuration
,
2272 Fcurrent_window_configuration (Qnil
));
2274 tem0
= Feval (Vhelp_form
);
2276 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
2280 c
= read_char (0, 0, 0, Qnil
, 0);
2281 while (BUFFERP (c
));
2282 /* Remove the help from the frame */
2283 unbind_to (count
, Qnil
);
2286 if (EQ (c
, make_number (040)))
2290 c
= read_char (0, 0, 0, Qnil
, 0);
2291 while (BUFFERP (c
));
2298 /* Record a key that came from a mouse menu.
2299 Record it for echoing, for this-command-keys, and so on. */
2305 /* Wipe the echo area. */
2306 echo_area_glyphs
= 0;
2310 before_command_key_count
= this_command_key_count
;
2311 before_command_echo_length
= echo_length ();
2313 /* Don't echo mouse motion events. */
2314 if (echo_keystrokes
)
2318 /* Once we reread a character, echoing can happen
2319 the next time we pause to read a new one. */
2320 ok_to_echo_at_next_pause
= 0;
2323 /* Record this character as part of the current key. */
2324 add_command_key (c
);
2326 /* Re-reading in the middle of a command */
2327 last_input_char
= c
;
2331 /* Return 1 if should recognize C as "the help character". */
2339 if (EQ (c
, Vhelp_char
))
2341 for (tail
= Vhelp_event_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
2342 if (EQ (c
, XCONS (tail
)->car
))
2347 /* Record the input event C in various ways. */
2354 XVECTOR (recent_keys
)->contents
[recent_keys_index
] = c
;
2355 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
2356 recent_keys_index
= 0;
2358 /* Write c to the dribble file. If c is a lispy event, write
2359 the event's symbol to the dribble file, in <brackets>. Bleaugh.
2360 If you, dear reader, have a better idea, you've got the source. :-) */
2365 if (XUINT (c
) < 0x100)
2366 putc (XINT (c
), dribble
);
2368 fprintf (dribble
, " 0x%x", (int) XUINT (c
));
2372 Lisp_Object dribblee
;
2374 /* If it's a structured event, take the event header. */
2375 dribblee
= EVENT_HEAD (c
);
2377 if (SYMBOLP (dribblee
))
2379 putc ('<', dribble
);
2380 fwrite (XSYMBOL (dribblee
)->name
->data
, sizeof (char),
2381 STRING_BYTES (XSYMBOL (dribblee
)->name
),
2383 putc ('>', dribble
);
2390 store_kbd_macro_char (c
);
2392 num_nonmacro_input_events
++;
2399 struct buffer
*old
= current_buffer
;
2400 Fprinc (object
, Qnil
);
2401 set_buffer_internal (XBUFFER (Vstandard_output
));
2402 call0 (intern ("help-mode"));
2403 set_buffer_internal (old
);
2407 /* Copy out or in the info on where C-g should throw to.
2408 This is used when running Lisp code from within get_char,
2409 in case get_char is called recursively.
2410 See read_process_output. */
2415 bcopy (getcjmp
, temp
, sizeof getcjmp
);
2418 restore_getcjmp (temp
)
2421 bcopy (temp
, getcjmp
, sizeof getcjmp
);
2426 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
2427 of this function. */
2430 tracking_off (old_value
)
2431 Lisp_Object old_value
;
2433 do_mouse_tracking
= old_value
;
2434 if (NILP (old_value
))
2436 /* Redisplay may have been preempted because there was input
2437 available, and it assumes it will be called again after the
2438 input has been processed. If the only input available was
2439 the sort that we have just disabled, then we need to call
2441 if (!readable_events (1))
2443 redisplay_preserve_echo_area ();
2444 get_input_pending (&input_pending
, 1);
2449 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
2450 "Evaluate BODY with mouse movement events enabled.\n\
2451 Within a `track-mouse' form, mouse motion generates input events that\n\
2452 you can read with `read-event'.\n\
2453 Normally, mouse motion is ignored.")
2457 int count
= specpdl_ptr
- specpdl
;
2460 record_unwind_protect (tracking_off
, do_mouse_tracking
);
2462 do_mouse_tracking
= Qt
;
2464 val
= Fprogn (args
);
2465 return unbind_to (count
, val
);
2468 /* If mouse has moved on some frame, return one of those frames.
2469 Return 0 otherwise. */
2474 Lisp_Object tail
, frame
;
2476 FOR_EACH_FRAME (tail
, frame
)
2478 if (XFRAME (frame
)->mouse_moved
)
2479 return XFRAME (frame
);
2485 #endif /* HAVE_MOUSE */
2487 /* Low level keyboard/mouse input.
2488 kbd_buffer_store_event places events in kbd_buffer, and
2489 kbd_buffer_get_event retrieves them. */
2491 /* Return true iff there are any events in the queue that read-char
2492 would return. If this returns false, a read-char would block. */
2494 readable_events (do_timers_now
)
2498 timer_check (do_timers_now
);
2500 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2503 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2508 if (current_kboard
->kbd_queue_has_data
)
2514 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2515 if (kb
->kbd_queue_has_data
)
2521 /* Set this for debugging, to have a way to get out */
2526 event_to_kboard (event
)
2527 struct input_event
*event
;
2530 frame
= event
->frame_or_window
;
2532 frame
= XCONS (frame
)->car
;
2533 else if (WINDOWP (frame
))
2534 frame
= WINDOW_FRAME (XWINDOW (frame
));
2536 /* There are still some events that don't set this field.
2537 For now, just ignore the problem.
2538 Also ignore dead frames here. */
2539 if (!FRAMEP (frame
) || !FRAME_LIVE_P (XFRAME (frame
)))
2542 return FRAME_KBOARD (XFRAME (frame
));
2546 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
2549 kbd_buffer_store_event (event
)
2550 register struct input_event
*event
;
2552 if (event
->kind
== no_event
)
2555 if (event
->kind
== ascii_keystroke
)
2557 register int c
= event
->code
& 0377;
2559 if (event
->modifiers
& ctrl_modifier
)
2560 c
= make_ctrl_char (c
);
2562 c
|= (event
->modifiers
2563 & (meta_modifier
| alt_modifier
2564 | hyper_modifier
| super_modifier
));
2568 extern SIGTYPE
interrupt_signal ();
2571 struct input_event
*sp
;
2574 && (kb
= FRAME_KBOARD (XFRAME (event
->frame_or_window
)),
2575 kb
!= current_kboard
))
2578 = Fcons (make_lispy_switch_frame (event
->frame_or_window
),
2579 Fcons (make_number (c
), Qnil
));
2580 kb
->kbd_queue_has_data
= 1;
2581 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
2583 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
2586 if (event_to_kboard (sp
) == kb
)
2588 sp
->kind
= no_event
;
2589 sp
->frame_or_window
= Qnil
;
2596 /* If this results in a quit_char being returned to Emacs as
2597 input, set Vlast_event_frame properly. If this doesn't
2598 get returned to Emacs as an event, the next event read
2599 will set Vlast_event_frame again, so this is safe to do. */
2603 focus
= FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
2605 focus
= event
->frame_or_window
;
2606 internal_last_event_frame
= focus
;
2607 Vlast_event_frame
= focus
;
2610 last_event_timestamp
= event
->timestamp
;
2611 interrupt_signal ();
2615 if (c
&& c
== stop_character
)
2621 /* Don't insert two buffer_switch_event's in a row.
2622 Just ignore the second one. */
2623 else if (event
->kind
== buffer_switch_event
2624 && kbd_fetch_ptr
!= kbd_store_ptr
2625 && kbd_store_ptr
->kind
== buffer_switch_event
)
2628 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
2629 kbd_store_ptr
= kbd_buffer
;
2631 /* Don't let the very last slot in the buffer become full,
2632 since that would make the two pointers equal,
2633 and that is indistinguishable from an empty buffer.
2634 Discard the event if it would fill the last slot. */
2635 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
2637 volatile struct input_event
*sp
= kbd_store_ptr
;
2638 sp
->kind
= event
->kind
;
2639 if (event
->kind
== selection_request_event
)
2641 /* We must not use the ordinary copying code for this case,
2642 since `part' is an enum and copying it might not copy enough
2644 bcopy (event
, (char *) sp
, sizeof (*event
));
2648 sp
->code
= event
->code
;
2649 sp
->part
= event
->part
;
2650 sp
->frame_or_window
= event
->frame_or_window
;
2651 sp
->modifiers
= event
->modifiers
;
2654 sp
->timestamp
= event
->timestamp
;
2656 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_store_ptr
2658 = event
->frame_or_window
);
2664 /* Discard any mouse events in the event buffer by setting them to
2667 discard_mouse_events ()
2669 struct input_event
*sp
;
2670 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
2672 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
2675 if (sp
->kind
== mouse_click
2677 || sp
->kind
== w32_scroll_bar_click
2679 || sp
->kind
== scroll_bar_click
)
2681 sp
->kind
= no_event
;
2686 /* Read one event from the event buffer, waiting if necessary.
2687 The value is a Lisp object representing the event.
2688 The value is nil for an event that should be ignored,
2689 or that was handled here.
2690 We always read and discard one event. */
2693 kbd_buffer_get_event (kbp
, used_mouse_menu
)
2695 int *used_mouse_menu
;
2699 EMACS_TIME next_timer_delay
;
2705 *kbp
= current_kboard
;
2709 /* Wait until there is input available. */
2712 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2715 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2719 /* If the quit flag is set, then read_char will return
2720 quit_char, so that counts as "available input." */
2721 if (!NILP (Vquit_flag
))
2722 quit_throw_to_read_char ();
2724 /* One way or another, wait until input is available; then, if
2725 interrupt handlers have not read it, read it now. */
2728 wait_for_kbd_input ();
2730 /* Note SIGIO has been undef'd if FIONREAD is missing. */
2734 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2737 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2741 Lisp_Object minus_one
;
2743 XSETINT (minus_one
, -1);
2744 wait_reading_process_input (0, 0, minus_one
, 1);
2746 if (!interrupt_input
&& kbd_fetch_ptr
== kbd_store_ptr
)
2747 /* Pass 1 for EXPECT since we just waited to have input. */
2748 read_avail_input (1);
2750 #endif /* not VMS */
2753 if (CONSP (Vunread_command_events
))
2756 first
= XCONS (Vunread_command_events
)->car
;
2757 Vunread_command_events
= XCONS (Vunread_command_events
)->cdr
;
2758 *kbp
= current_kboard
;
2762 /* At this point, we know that there is a readable event available
2763 somewhere. If the event queue is empty, then there must be a
2764 mouse movement enabled and available. */
2765 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2767 struct input_event
*event
;
2769 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2773 last_event_timestamp
= event
->timestamp
;
2776 *kbp
= event_to_kboard (event
);
2778 *kbp
= current_kboard
; /* Better than returning null ptr? */
2780 *kbp
= &the_only_kboard
;
2785 /* These two kinds of events get special handling
2786 and don't actually appear to the command loop.
2787 We return nil for them. */
2788 if (event
->kind
== selection_request_event
)
2791 struct input_event copy
;
2793 /* Remove it from the buffer before processing it,
2794 since otherwise swallow_events will see it
2795 and process it again. */
2797 kbd_fetch_ptr
= event
+ 1;
2798 input_pending
= readable_events (0);
2799 x_handle_selection_request (©
);
2801 /* We're getting selection request events, but we don't have
2807 else if (event
->kind
== selection_clear_event
)
2810 struct input_event copy
;
2812 /* Remove it from the buffer before processing it. */
2814 kbd_fetch_ptr
= event
+ 1;
2815 input_pending
= readable_events (0);
2816 x_handle_selection_clear (©
);
2818 /* We're getting selection request events, but we don't have
2823 #if defined (HAVE_X11) || defined (HAVE_NTGUI)
2824 else if (event
->kind
== delete_window_event
)
2826 /* Make an event (delete-frame (FRAME)). */
2827 obj
= Fcons (event
->frame_or_window
, Qnil
);
2828 obj
= Fcons (Qdelete_frame
, Fcons (obj
, Qnil
));
2829 kbd_fetch_ptr
= event
+ 1;
2831 else if (event
->kind
== iconify_event
)
2833 /* Make an event (iconify-frame (FRAME)). */
2834 obj
= Fcons (event
->frame_or_window
, Qnil
);
2835 obj
= Fcons (Qiconify_frame
, Fcons (obj
, Qnil
));
2836 kbd_fetch_ptr
= event
+ 1;
2838 else if (event
->kind
== deiconify_event
)
2840 /* Make an event (make-frame-visible (FRAME)). */
2841 obj
= Fcons (event
->frame_or_window
, Qnil
);
2842 obj
= Fcons (Qmake_frame_visible
, Fcons (obj
, Qnil
));
2843 kbd_fetch_ptr
= event
+ 1;
2846 else if (event
->kind
== buffer_switch_event
)
2848 /* The value doesn't matter here; only the type is tested. */
2849 XSETBUFFER (obj
, current_buffer
);
2850 kbd_fetch_ptr
= event
+ 1;
2852 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
2853 else if (event
->kind
== menu_bar_activate_event
)
2855 kbd_fetch_ptr
= event
+ 1;
2856 input_pending
= readable_events (0);
2857 if (FRAME_LIVE_P (XFRAME (event
->frame_or_window
)))
2858 x_activate_menubar (XFRAME (event
->frame_or_window
));
2861 /* Just discard these, by returning nil.
2862 With MULTI_KBOARD, these events are used as placeholders
2863 when we need to randomly delete events from the queue.
2864 (They shouldn't otherwise be found in the buffer,
2865 but on some machines it appears they do show up
2866 even without MULTI_KBOARD.) */
2867 /* On Windows NT/9X, no_event is used to delete extraneous
2868 mouse events during a popup-menu call. */
2869 else if (event
->kind
== no_event
)
2870 kbd_fetch_ptr
= event
+ 1;
2872 /* If this event is on a different frame, return a switch-frame this
2873 time, and leave the event in the queue for next time. */
2879 frame
= event
->frame_or_window
;
2881 frame
= XCONS (frame
)->car
;
2882 else if (WINDOWP (frame
))
2883 frame
= WINDOW_FRAME (XWINDOW (frame
));
2885 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
2889 if (! EQ (frame
, internal_last_event_frame
)
2890 && XFRAME (frame
) != selected_frame
)
2891 obj
= make_lispy_switch_frame (frame
);
2892 internal_last_event_frame
= frame
;
2894 /* If we didn't decide to make a switch-frame event, go ahead
2895 and build a real event from the queue entry. */
2899 obj
= make_lispy_event (event
);
2900 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
2901 /* If this was a menu selection, then set the flag to inhibit
2902 writing to last_nonmenu_event. Don't do this if the event
2903 we're returning is (menu-bar), though; that indicates the
2904 beginning of the menu sequence, and we might as well leave
2905 that as the `event with parameters' for this selection. */
2906 if (event
->kind
== menu_bar_event
2907 && !(CONSP (obj
) && EQ (XCONS (obj
)->car
, Qmenu_bar
))
2909 *used_mouse_menu
= 1;
2912 /* Wipe out this event, to catch bugs. */
2913 event
->kind
= no_event
;
2914 XVECTOR (kbd_buffer_frame_or_window
)->contents
[event
- kbd_buffer
] = Qnil
;
2916 kbd_fetch_ptr
= event
+ 1;
2921 /* Try generating a mouse motion event. */
2922 else if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2924 FRAME_PTR f
= some_mouse_moved ();
2925 Lisp_Object bar_window
;
2926 enum scroll_bar_part part
;
2930 *kbp
= current_kboard
;
2931 /* Note that this uses F to determine which display to look at.
2932 If there is no valid info, it does not store anything
2933 so x remains nil. */
2935 (*mouse_position_hook
) (&f
, 0, &bar_window
, &part
, &x
, &y
, &time
);
2939 /* Decide if we should generate a switch-frame event. Don't
2940 generate switch-frame events for motion outside of all Emacs
2946 frame
= FRAME_FOCUS_FRAME (f
);
2948 XSETFRAME (frame
, f
);
2950 if (! EQ (frame
, internal_last_event_frame
)
2951 && XFRAME (frame
) != selected_frame
)
2952 obj
= make_lispy_switch_frame (frame
);
2953 internal_last_event_frame
= frame
;
2956 /* If we didn't decide to make a switch-frame event, go ahead and
2957 return a mouse-motion event. */
2958 if (!NILP (x
) && NILP (obj
))
2959 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
2961 #endif /* HAVE_MOUSE */
2963 /* We were promised by the above while loop that there was
2964 something for us to read! */
2967 input_pending
= readable_events (0);
2969 Vlast_event_frame
= internal_last_event_frame
;
2974 /* Process any events that are not user-visible,
2975 then return, without reading any user-visible events. */
2978 swallow_events (do_display
)
2983 while (kbd_fetch_ptr
!= kbd_store_ptr
)
2985 struct input_event
*event
;
2987 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2991 last_event_timestamp
= event
->timestamp
;
2993 /* These two kinds of events get special handling
2994 and don't actually appear to the command loop. */
2995 if (event
->kind
== selection_request_event
)
2998 struct input_event copy
;
3000 /* Remove it from the buffer before processing it,
3001 since otherwise swallow_events called recursively could see it
3002 and process it again. */
3004 kbd_fetch_ptr
= event
+ 1;
3005 input_pending
= readable_events (0);
3006 x_handle_selection_request (©
);
3008 /* We're getting selection request events, but we don't have
3014 else if (event
->kind
== selection_clear_event
)
3017 struct input_event copy
;
3019 /* Remove it from the buffer before processing it, */
3022 kbd_fetch_ptr
= event
+ 1;
3023 input_pending
= readable_events (0);
3024 x_handle_selection_clear (©
);
3026 /* We're getting selection request events, but we don't have
3035 old_timers_run
= timers_run
;
3036 get_input_pending (&input_pending
, 1);
3038 if (timers_run
!= old_timers_run
&& do_display
)
3039 redisplay_preserve_echo_area ();
3042 static EMACS_TIME timer_idleness_start_time
;
3044 /* Record the start of when Emacs is idle,
3045 for the sake of running idle-time timers. */
3052 /* If we are already in the idle state, do nothing. */
3053 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3056 EMACS_GET_TIME (timer_idleness_start_time
);
3058 /* Mark all idle-time timers as once again candidates for running. */
3059 for (timers
= Vtimer_idle_list
; CONSP (timers
); timers
= XCONS (timers
)->cdr
)
3063 timer
= XCONS (timers
)->car
;
3065 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3067 XVECTOR (timer
)->contents
[0] = Qnil
;
3071 /* Record that Emacs is no longer idle, so stop running idle-time timers. */
3076 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
3079 /* This is only for debugging. */
3080 struct input_event last_timer_event
;
3082 /* Check whether a timer has fired. To prevent larger problems we simply
3083 disregard elements that are not proper timers. Do not make a circular
3084 timer list for the time being.
3086 Returns the number of seconds to wait until the next timer fires. If a
3087 timer is triggering now, return zero seconds.
3088 If no timer is active, return -1 seconds.
3090 If a timer is ripe, we run it, with quitting turned off.
3092 DO_IT_NOW is now ignored. It used to mean that we should
3093 run the timer directly instead of queueing a timer-event.
3094 Now we always run timers directly. */
3097 timer_check (do_it_now
)
3100 EMACS_TIME nexttime
;
3101 EMACS_TIME now
, idleness_now
;
3102 Lisp_Object timers
, idle_timers
, chosen_timer
;
3103 struct gcpro gcpro1
, gcpro2
, gcpro3
;
3105 EMACS_SET_SECS (nexttime
, -1);
3106 EMACS_SET_USECS (nexttime
, -1);
3108 /* Always consider the ordinary timers. */
3109 timers
= Vtimer_list
;
3110 /* Consider the idle timers only if Emacs is idle. */
3111 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3112 idle_timers
= Vtimer_idle_list
;
3115 chosen_timer
= Qnil
;
3116 GCPRO3 (timers
, idle_timers
, chosen_timer
);
3118 if (CONSP (timers
) || CONSP (idle_timers
))
3120 EMACS_GET_TIME (now
);
3121 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3122 EMACS_SUB_TIME (idleness_now
, now
, timer_idleness_start_time
);
3125 while (CONSP (timers
) || CONSP (idle_timers
))
3127 int triggertime
= EMACS_SECS (now
);
3128 Lisp_Object
*vector
;
3129 Lisp_Object timer
, idle_timer
;
3130 EMACS_TIME timer_time
, idle_timer_time
;
3131 EMACS_TIME difference
, timer_difference
, idle_timer_difference
;
3133 /* Skip past invalid timers and timers already handled. */
3136 timer
= XCONS (timers
)->car
;
3137 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3139 timers
= XCONS (timers
)->cdr
;
3142 vector
= XVECTOR (timer
)->contents
;
3144 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
3145 || !INTEGERP (vector
[3])
3146 || ! NILP (vector
[0]))
3148 timers
= XCONS (timers
)->cdr
;
3152 if (!NILP (idle_timers
))
3154 timer
= XCONS (idle_timers
)->car
;
3155 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3157 idle_timers
= XCONS (idle_timers
)->cdr
;
3160 vector
= XVECTOR (timer
)->contents
;
3162 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
3163 || !INTEGERP (vector
[3])
3164 || ! NILP (vector
[0]))
3166 idle_timers
= XCONS (idle_timers
)->cdr
;
3171 /* Set TIMER, TIMER_TIME and TIMER_DIFFERENCE
3172 based on the next ordinary timer.
3173 TIMER_DIFFERENCE is the distance in time from NOW to when
3174 this timer becomes ripe (negative if it's already ripe). */
3177 timer
= XCONS (timers
)->car
;
3178 vector
= XVECTOR (timer
)->contents
;
3179 EMACS_SET_SECS (timer_time
,
3180 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
3181 EMACS_SET_USECS (timer_time
, XINT (vector
[3]));
3182 EMACS_SUB_TIME (timer_difference
, timer_time
, now
);
3185 /* Set IDLE_TIMER, IDLE_TIMER_TIME and IDLE_TIMER_DIFFERENCE
3186 based on the next idle timer. */
3187 if (!NILP (idle_timers
))
3189 idle_timer
= XCONS (idle_timers
)->car
;
3190 vector
= XVECTOR (idle_timer
)->contents
;
3191 EMACS_SET_SECS (idle_timer_time
,
3192 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
3193 EMACS_SET_USECS (idle_timer_time
, XINT (vector
[3]));
3194 EMACS_SUB_TIME (idle_timer_difference
, idle_timer_time
, idleness_now
);
3197 /* Decide which timer is the next timer,
3198 and set CHOSEN_TIMER, VECTOR and DIFFERENCE accordingly.
3199 Also step down the list where we found that timer. */
3201 if (! NILP (timers
) && ! NILP (idle_timers
))
3204 EMACS_SUB_TIME (temp
, timer_difference
, idle_timer_difference
);
3205 if (EMACS_TIME_NEG_P (temp
))
3207 chosen_timer
= timer
;
3208 timers
= XCONS (timers
)->cdr
;
3209 difference
= timer_difference
;
3213 chosen_timer
= idle_timer
;
3214 idle_timers
= XCONS (idle_timers
)->cdr
;
3215 difference
= idle_timer_difference
;
3218 else if (! NILP (timers
))
3220 chosen_timer
= timer
;
3221 timers
= XCONS (timers
)->cdr
;
3222 difference
= timer_difference
;
3226 chosen_timer
= idle_timer
;
3227 idle_timers
= XCONS (idle_timers
)->cdr
;
3228 difference
= idle_timer_difference
;
3230 vector
= XVECTOR (chosen_timer
)->contents
;
3232 /* If timer is rupe, run it if it hasn't been run. */
3233 if (EMACS_TIME_NEG_P (difference
)
3234 || (EMACS_SECS (difference
) == 0
3235 && EMACS_USECS (difference
) == 0))
3237 if (NILP (vector
[0]))
3240 int was_locked
= single_kboard
;
3241 int count
= specpdl_ptr
- specpdl
;
3243 /* Mark the timer as triggered to prevent problems if the lisp
3244 code fails to reschedule it right. */
3247 specbind (Qinhibit_quit
, Qt
);
3249 call1 (Qtimer_event_handler
, chosen_timer
);
3252 unbind_to (count
, Qnil
);
3254 /* Resume allowing input from any kboard, if that was true before. */
3256 any_kboard_state ();
3258 /* Since we have handled the event,
3259 we don't need to tell the caller to wake up and do it. */
3263 /* When we encounter a timer that is still waiting,
3264 return the amount of time to wait before it is ripe. */
3271 /* No timers are pending in the future. */
3272 /* Return 0 if we generated an event, and -1 if not. */
3277 /* Caches for modify_event_symbol. */
3278 static Lisp_Object accent_key_syms
;
3279 static Lisp_Object func_key_syms
;
3280 static Lisp_Object mouse_syms
;
3282 static Lisp_Object mouse_wheel_syms
;
3285 /* This is a list of keysym codes for special "accent" characters.
3286 It parallels lispy_accent_keys. */
3288 static int lispy_accent_codes
[] =
3290 #ifdef XK_dead_circumflex
3295 #ifdef XK_dead_grave
3300 #ifdef XK_dead_tilde
3305 #ifdef XK_dead_diaeresis
3310 #ifdef XK_dead_macron
3315 #ifdef XK_dead_degree
3320 #ifdef XK_dead_acute
3325 #ifdef XK_dead_cedilla
3330 #ifdef XK_dead_breve
3335 #ifdef XK_dead_ogonek
3340 #ifdef XK_dead_caron
3345 #ifdef XK_dead_doubleacute
3346 XK_dead_doubleacute
,
3350 #ifdef XK_dead_abovedot
3357 /* This is a list of Lisp names for special "accent" characters.
3358 It parallels lispy_accent_codes. */
3360 static char *lispy_accent_keys
[] =
3378 #define FUNCTION_KEY_OFFSET 0x0
3380 char *lispy_function_keys
[] =
3384 0, /* VK_LBUTTON 0x01 */
3385 0, /* VK_RBUTTON 0x02 */
3386 "cancel", /* VK_CANCEL 0x03 */
3387 0, /* VK_MBUTTON 0x04 */
3389 0, 0, 0, /* 0x05 .. 0x07 */
3391 "backspace", /* VK_BACK 0x08 */
3392 "tab", /* VK_TAB 0x09 */
3394 0, 0, /* 0x0A .. 0x0B */
3396 "clear", /* VK_CLEAR 0x0C */
3397 "return", /* VK_RETURN 0x0D */
3399 0, 0, /* 0x0E .. 0x0F */
3401 "shift", /* VK_SHIFT 0x10 */
3402 "control", /* VK_CONTROL 0x11 */
3403 "menu", /* VK_MENU 0x12 */
3404 "pause", /* VK_PAUSE 0x13 */
3405 "capital", /* VK_CAPITAL 0x14 */
3407 0, 0, 0, 0, 0, 0, /* 0x15 .. 0x1A */
3409 0, /* VK_ESCAPE 0x1B */
3411 0, 0, 0, 0, /* 0x1C .. 0x1F */
3413 0, /* VK_SPACE 0x20 */
3414 "prior", /* VK_PRIOR 0x21 */
3415 "next", /* VK_NEXT 0x22 */
3416 "end", /* VK_END 0x23 */
3417 "home", /* VK_HOME 0x24 */
3418 "left", /* VK_LEFT 0x25 */
3419 "up", /* VK_UP 0x26 */
3420 "right", /* VK_RIGHT 0x27 */
3421 "down", /* VK_DOWN 0x28 */
3422 "select", /* VK_SELECT 0x29 */
3423 "print", /* VK_PRINT 0x2A */
3424 "execute", /* VK_EXECUTE 0x2B */
3425 "snapshot", /* VK_SNAPSHOT 0x2C */
3426 "insert", /* VK_INSERT 0x2D */
3427 "delete", /* VK_DELETE 0x2E */
3428 "help", /* VK_HELP 0x2F */
3430 /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
3432 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3434 0, 0, 0, 0, 0, 0, 0, /* 0x3A .. 0x40 */
3436 /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
3438 0, 0, 0, 0, 0, 0, 0, 0, 0,
3439 0, 0, 0, 0, 0, 0, 0, 0, 0,
3440 0, 0, 0, 0, 0, 0, 0, 0,
3442 "lwindow", /* VK_LWIN 0x5B */
3443 "rwindow", /* VK_RWIN 0x5C */
3444 "apps", /* VK_APPS 0x5D */
3446 0, 0, /* 0x5E .. 0x5F */
3448 "kp-0", /* VK_NUMPAD0 0x60 */
3449 "kp-1", /* VK_NUMPAD1 0x61 */
3450 "kp-2", /* VK_NUMPAD2 0x62 */
3451 "kp-3", /* VK_NUMPAD3 0x63 */
3452 "kp-4", /* VK_NUMPAD4 0x64 */
3453 "kp-5", /* VK_NUMPAD5 0x65 */
3454 "kp-6", /* VK_NUMPAD6 0x66 */
3455 "kp-7", /* VK_NUMPAD7 0x67 */
3456 "kp-8", /* VK_NUMPAD8 0x68 */
3457 "kp-9", /* VK_NUMPAD9 0x69 */
3458 "kp-multiply", /* VK_MULTIPLY 0x6A */
3459 "kp-add", /* VK_ADD 0x6B */
3460 "kp-separator", /* VK_SEPARATOR 0x6C */
3461 "kp-subtract", /* VK_SUBTRACT 0x6D */
3462 "kp-decimal", /* VK_DECIMAL 0x6E */
3463 "kp-divide", /* VK_DIVIDE 0x6F */
3464 "f1", /* VK_F1 0x70 */
3465 "f2", /* VK_F2 0x71 */
3466 "f3", /* VK_F3 0x72 */
3467 "f4", /* VK_F4 0x73 */
3468 "f5", /* VK_F5 0x74 */
3469 "f6", /* VK_F6 0x75 */
3470 "f7", /* VK_F7 0x76 */
3471 "f8", /* VK_F8 0x77 */
3472 "f9", /* VK_F9 0x78 */
3473 "f10", /* VK_F10 0x79 */
3474 "f11", /* VK_F11 0x7A */
3475 "f12", /* VK_F12 0x7B */
3476 "f13", /* VK_F13 0x7C */
3477 "f14", /* VK_F14 0x7D */
3478 "f15", /* VK_F15 0x7E */
3479 "f16", /* VK_F16 0x7F */
3480 "f17", /* VK_F17 0x80 */
3481 "f18", /* VK_F18 0x81 */
3482 "f19", /* VK_F19 0x82 */
3483 "f20", /* VK_F20 0x83 */
3484 "f21", /* VK_F21 0x84 */
3485 "f22", /* VK_F22 0x85 */
3486 "f23", /* VK_F23 0x86 */
3487 "f24", /* VK_F24 0x87 */
3489 0, 0, 0, 0, /* 0x88 .. 0x8B */
3490 0, 0, 0, 0, /* 0x8C .. 0x8F */
3492 "kp-numlock", /* VK_NUMLOCK 0x90 */
3493 "scroll", /* VK_SCROLL 0x91 */
3495 "kp-space", /* VK_NUMPAD_CLEAR 0x92 */
3496 "kp-enter", /* VK_NUMPAD_ENTER 0x93 */
3497 "kp-prior", /* VK_NUMPAD_PRIOR 0x94 */
3498 "kp-next", /* VK_NUMPAD_NEXT 0x95 */
3499 "kp-end", /* VK_NUMPAD_END 0x96 */
3500 "kp-home", /* VK_NUMPAD_HOME 0x97 */
3501 "kp-left", /* VK_NUMPAD_LEFT 0x98 */
3502 "kp-up", /* VK_NUMPAD_UP 0x99 */
3503 "kp-right", /* VK_NUMPAD_RIGHT 0x9A */
3504 "kp-down", /* VK_NUMPAD_DOWN 0x9B */
3505 "kp-insert", /* VK_NUMPAD_INSERT 0x9C */
3506 "kp-delete", /* VK_NUMPAD_DELETE 0x9D */
3508 0, 0, /* 0x9E .. 0x9F */
3511 * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
3512 * Used only as parameters to GetAsyncKeyState and GetKeyState.
3513 * No other API or message will distinguish left and right keys this way.
3517 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3518 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3519 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3520 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3521 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3527 "attn", /* VK_ATTN 0xF6 */
3528 "crsel", /* VK_CRSEL 0xF7 */
3529 "exsel", /* VK_EXSEL 0xF8 */
3530 "ereof", /* VK_EREOF 0xF9 */
3531 "play", /* VK_PLAY 0xFA */
3532 "zoom", /* VK_ZOOM 0xFB */
3533 "noname", /* VK_NONAME 0xFC */
3534 "pa1", /* VK_PA1 0xFD */
3535 "oem_clear", /* VK_OEM_CLEAR 0xFE */
3538 #else /* not HAVE_NTGUI */
3541 static char *lispy_kana_keys
[] =
3543 /* X Keysym value */
3544 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x400 .. 0x40f */
3545 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x410 .. 0x41f */
3546 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x420 .. 0x42f */
3547 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x430 .. 0x43f */
3548 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x440 .. 0x44f */
3549 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x450 .. 0x45f */
3550 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x460 .. 0x46f */
3551 0,0,0,0,0,0,0,0,0,0,0,0,0,0,"overline",0,
3552 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x480 .. 0x48f */
3553 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x490 .. 0x49f */
3554 0, "kana-fullstop", "kana-openingbracket", "kana-closingbracket",
3555 "kana-comma", "kana-conjunctive", "kana-WO", "kana-a",
3556 "kana-i", "kana-u", "kana-e", "kana-o",
3557 "kana-ya", "kana-yu", "kana-yo", "kana-tsu",
3558 "prolongedsound", "kana-A", "kana-I", "kana-U",
3559 "kana-E", "kana-O", "kana-KA", "kana-KI",
3560 "kana-KU", "kana-KE", "kana-KO", "kana-SA",
3561 "kana-SHI", "kana-SU", "kana-SE", "kana-SO",
3562 "kana-TA", "kana-CHI", "kana-TSU", "kana-TE",
3563 "kana-TO", "kana-NA", "kana-NI", "kana-NU",
3564 "kana-NE", "kana-NO", "kana-HA", "kana-HI",
3565 "kana-FU", "kana-HE", "kana-HO", "kana-MA",
3566 "kana-MI", "kana-MU", "kana-ME", "kana-MO",
3567 "kana-YA", "kana-YU", "kana-YO", "kana-RA",
3568 "kana-RI", "kana-RU", "kana-RE", "kana-RO",
3569 "kana-WA", "kana-N", "voicedsound", "semivoicedsound",
3570 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4e0 .. 0x4ef */
3571 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4f0 .. 0x4ff */
3573 #endif /* XK_kana_A */
3575 #define FUNCTION_KEY_OFFSET 0xff00
3577 /* You'll notice that this table is arranged to be conveniently
3578 indexed by X Windows keysym values. */
3579 static char *lispy_function_keys
[] =
3581 /* X Keysym value */
3583 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00 */
3591 0, 0, 0, /* 0xff10 */
3593 0, 0, 0, 0, 0, 0, 0,
3596 0, "kanji", "muhenkan",
3597 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff20...2f */
3598 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff30...3f */
3599 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
3601 "home", /* 0xff50 */ /* IsCursorKey */
3612 "select", /* 0xff60 */ /* IsMiscFunctionKey */
3623 "break", /* 0xff6b */
3625 0, 0, 0, 0, 0, 0, 0, 0, "backtab", 0,
3627 0, 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff7f */
3628 "kp-space", /* 0xff80 */ /* IsKeypadKey */
3629 0, 0, 0, 0, 0, 0, 0, 0,
3630 "kp-tab", /* 0xff89 */
3632 "kp-enter", /* 0xff8d */
3634 "kp-f1", /* 0xff91 */
3638 "kp-home", /* 0xff95 */
3643 "kp-prior", /* kp-page-up */
3644 "kp-next", /* kp-page-down */
3650 0, 0, 0, 0, 0, 0, 0, 0, 0,
3651 "kp-multiply", /* 0xffaa */
3656 "kp-divide", /* 0xffaf */
3657 "kp-0", /* 0xffb0 */
3658 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
3661 "kp-equal", /* 0xffbd */
3662 "f1", /* 0xffbe */ /* IsFunctionKey */
3664 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
3665 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
3666 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
3667 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
3668 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
3669 0, 0, 0, 0, 0, 0, 0, 0,
3670 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
3671 0, 0, 0, 0, 0, 0, 0, "delete"
3674 /* ISO 9995 Function and Modifier Keys; the first byte is 0xFE. */
3675 #define ISO_FUNCTION_KEY_OFFSET 0xfe00
3677 static char *iso_lispy_function_keys
[] =
3679 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe00 */
3680 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe08 */
3681 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe10 */
3682 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe18 */
3683 "iso-lefttab", /* 0xfe20 */
3684 "iso-move-line-up", "iso-move-line-down",
3685 "iso-partial-line-up", "iso-partial-line-down",
3686 "iso-partial-space-left", "iso-partial-space-right",
3687 "iso-set-margin-left", "iso-set-margin-right", /* 0xffe27, 28 */
3688 "iso-release-margin-left", "iso-release-margin-right",
3689 "iso-release-both-margins",
3690 "iso-fast-cursor-left", "iso-fast-cursor-right",
3691 "iso-fast-cursor-up", "iso-fast-cursor-down",
3692 "iso-continuous-underline", "iso-discontinuous-underline", /* 0xfe30, 31 */
3693 "iso-emphasize", "iso-center-object", "iso-enter", /* ... 0xfe34 */
3696 #endif /* not HAVE_NTGUI */
3698 static char *lispy_mouse_names
[] =
3700 "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5"
3704 /* mouse-wheel events are generated by the wheel on devices such as
3705 the MS Intellimouse. The wheel sits in between the left and right
3706 mouse buttons, and is typically used to scroll or zoom the window
3707 underneath the pointer. mouse-wheel events specify the object on
3708 which they operate, and a delta corresponding to the amount and
3709 direction that the wheel is rotated. Clicking the mouse-wheel
3710 generates a mouse-2 event. */
3711 static char *lispy_mouse_wheel_names
[] =
3715 #endif /* WINDOWSNT */
3717 /* Scroll bar parts. */
3718 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
3719 Lisp_Object Qup
, Qdown
;
3721 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
3722 Lisp_Object
*scroll_bar_parts
[] = {
3723 &Qabove_handle
, &Qhandle
, &Qbelow_handle
,
3728 /* A vector, indexed by button number, giving the down-going location
3729 of currently depressed buttons, both scroll bar and non-scroll bar.
3731 The elements have the form
3732 (BUTTON-NUMBER MODIFIER-MASK . REST)
3733 where REST is the cdr of a position as it would be reported in the event.
3735 The make_lispy_event function stores positions here to tell the
3736 difference between click and drag events, and to store the starting
3737 location to be included in drag events. */
3739 static Lisp_Object button_down_location
;
3741 /* Information about the most recent up-going button event: Which
3742 button, what location, and what time. */
3744 static int last_mouse_button
;
3745 static int last_mouse_x
;
3746 static int last_mouse_y
;
3747 static unsigned long button_down_time
;
3749 /* The maximum time between clicks to make a double-click,
3750 or Qnil to disable double-click detection,
3751 or Qt for no time limit. */
3752 Lisp_Object Vdouble_click_time
;
3754 /* The number of clicks in this multiple-click. */
3756 int double_click_count
;
3758 /* Given a struct input_event, build the lisp event which represents
3759 it. If EVENT is 0, build a mouse movement event from the mouse
3760 movement buffer, which should have a movement event in it.
3762 Note that events must be passed to this function in the order they
3763 are received; this function stores the location of button presses
3764 in order to build drag events when the button is released. */
3767 make_lispy_event (event
)
3768 struct input_event
*event
;
3772 switch (SWITCH_ENUM_CAST (event
->kind
))
3774 /* A simple keystroke. */
3775 case ascii_keystroke
:
3777 Lisp_Object lispy_c
;
3778 int c
= event
->code
& 0377;
3779 /* Turn ASCII characters into control characters
3781 if (event
->modifiers
& ctrl_modifier
)
3782 c
= make_ctrl_char (c
);
3784 /* Add in the other modifier bits. We took care of ctrl_modifier
3785 just above, and the shift key was taken care of by the X code,
3786 and applied to control characters by make_ctrl_char. */
3787 c
|= (event
->modifiers
3788 & (meta_modifier
| alt_modifier
3789 | hyper_modifier
| super_modifier
));
3790 /* Distinguish Shift-SPC from SPC. */
3791 if ((event
->code
& 0377) == 040
3792 && event
->modifiers
& shift_modifier
)
3793 c
|= shift_modifier
;
3794 button_down_time
= 0;
3795 XSETFASTINT (lispy_c
, c
);
3799 /* A function key. The symbol may need to have modifier prefixes
3801 case non_ascii_keystroke
:
3802 button_down_time
= 0;
3804 for (i
= 0; i
< sizeof (lispy_accent_codes
) / sizeof (int); i
++)
3805 if (event
->code
== lispy_accent_codes
[i
])
3806 return modify_event_symbol (i
,
3808 Qfunction_key
, Qnil
,
3809 lispy_accent_keys
, &accent_key_syms
,
3810 (sizeof (lispy_accent_keys
)
3811 / sizeof (lispy_accent_keys
[0])));
3813 /* Handle system-specific keysyms. */
3814 if (event
->code
& (1 << 28))
3816 /* We need to use an alist rather than a vector as the cache
3817 since we can't make a vector long enuf. */
3818 if (NILP (current_kboard
->system_key_syms
))
3819 current_kboard
->system_key_syms
= Fcons (Qnil
, Qnil
);
3820 return modify_event_symbol (event
->code
,
3823 current_kboard
->Vsystem_key_alist
,
3824 0, ¤t_kboard
->system_key_syms
,
3829 if (event
->code
>= 0x400 && event
->code
< 0x500)
3830 return modify_event_symbol (event
->code
- 0x400,
3831 event
->modifiers
& ~shift_modifier
,
3832 Qfunction_key
, Qnil
,
3833 lispy_kana_keys
, &func_key_syms
,
3834 (sizeof (lispy_kana_keys
)
3835 / sizeof (lispy_kana_keys
[0])));
3836 #endif /* XK_kana_A */
3838 #ifdef ISO_FUNCTION_KEY_OFFSET
3839 if (event
->code
< FUNCTION_KEY_OFFSET
3840 && event
->code
>= ISO_FUNCTION_KEY_OFFSET
)
3841 return modify_event_symbol (event
->code
- ISO_FUNCTION_KEY_OFFSET
,
3843 Qfunction_key
, Qnil
,
3844 iso_lispy_function_keys
, &func_key_syms
,
3845 (sizeof (iso_lispy_function_keys
)
3846 / sizeof (iso_lispy_function_keys
[0])));
3849 return modify_event_symbol (event
->code
- FUNCTION_KEY_OFFSET
,
3851 Qfunction_key
, Qnil
,
3852 lispy_function_keys
, &func_key_syms
,
3853 (sizeof (lispy_function_keys
)
3854 / sizeof (lispy_function_keys
[0])));
3857 /* A mouse click. Figure out where it is, decide whether it's
3858 a press, click or drag, and build the appropriate structure. */
3860 case scroll_bar_click
:
3862 int button
= event
->code
;
3864 Lisp_Object position
;
3865 Lisp_Object
*start_pos_ptr
;
3866 Lisp_Object start_pos
;
3868 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
3871 /* Build the position as appropriate for this mouse click. */
3872 if (event
->kind
== mouse_click
)
3875 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
3880 /* Ignore mouse events that were made on frame that
3881 have been deleted. */
3882 if (! FRAME_LIVE_P (f
))
3885 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
3886 &column
, &row
, NULL
, 1);
3888 #ifndef USE_X_TOOLKIT
3889 /* In the non-toolkit version, clicks on the menu bar
3890 are ordinary button events in the event buffer.
3891 Distinguish them, and invoke the menu.
3893 (In the toolkit version, the toolkit handles the menu bar
3894 and Emacs doesn't know about it until after the user
3895 makes a selection.) */
3896 if (row
>= 0 && row
< FRAME_MENU_BAR_LINES (f
)
3897 && (event
->modifiers
& down_modifier
))
3899 Lisp_Object items
, item
;
3904 /* Activate the menu bar on the down event. If the
3905 up event comes in before the menu code can deal with it,
3907 if (! (event
->modifiers
& down_modifier
))
3912 items
= FRAME_MENU_BAR_ITEMS (f
);
3913 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
3915 Lisp_Object pos
, string
;
3916 string
= XVECTOR (items
)->contents
[i
+ 1];
3917 pos
= XVECTOR (items
)->contents
[i
+ 3];
3920 if (column
>= XINT (pos
)
3921 && column
< XINT (pos
) + XSTRING (string
)->size
)
3923 item
= XVECTOR (items
)->contents
[i
];
3929 = Fcons (event
->frame_or_window
,
3931 Fcons (Fcons (event
->x
, event
->y
),
3932 Fcons (make_number (event
->timestamp
),
3935 return Fcons (item
, Fcons (position
, Qnil
));
3937 #endif /* not USE_X_TOOLKIT */
3939 window
= window_from_coordinates (f
, column
, row
, &part
);
3941 if (!WINDOWP (window
))
3943 window
= event
->frame_or_window
;
3948 int pixcolumn
, pixrow
;
3949 column
-= WINDOW_LEFT_MARGIN (XWINDOW (window
));
3950 row
-= XINT (XWINDOW (window
)->top
);
3951 glyph_to_pixel_coords (f
, column
, row
, &pixcolumn
, &pixrow
);
3952 XSETINT (event
->x
, pixcolumn
);
3953 XSETINT (event
->y
, pixrow
);
3958 posn
= Qvertical_line
;
3961 buffer_posn_from_coords (XWINDOW (window
),
3968 Fcons (Fcons (event
->x
, event
->y
),
3969 Fcons (make_number (event
->timestamp
),
3975 Lisp_Object portion_whole
;
3978 window
= event
->frame_or_window
;
3979 portion_whole
= Fcons (event
->x
, event
->y
);
3980 part
= *scroll_bar_parts
[(int) event
->part
];
3984 Fcons (Qvertical_scroll_bar
,
3985 Fcons (portion_whole
,
3986 Fcons (make_number (event
->timestamp
),
3987 Fcons (part
, Qnil
)))));
3990 start_pos_ptr
= &XVECTOR (button_down_location
)->contents
[button
];
3992 start_pos
= *start_pos_ptr
;
3993 *start_pos_ptr
= Qnil
;
3995 is_double
= (button
== last_mouse_button
3996 && XINT (event
->x
) == last_mouse_x
3997 && XINT (event
->y
) == last_mouse_y
3998 && button_down_time
!= 0
3999 && (EQ (Vdouble_click_time
, Qt
)
4000 || (INTEGERP (Vdouble_click_time
)
4001 && ((int)(event
->timestamp
- button_down_time
)
4002 < XINT (Vdouble_click_time
)))));
4003 last_mouse_button
= button
;
4004 last_mouse_x
= XINT (event
->x
);
4005 last_mouse_y
= XINT (event
->y
);
4007 /* If this is a button press, squirrel away the location, so
4008 we can decide later whether it was a click or a drag. */
4009 if (event
->modifiers
& down_modifier
)
4013 double_click_count
++;
4014 event
->modifiers
|= ((double_click_count
> 2)
4019 double_click_count
= 1;
4020 button_down_time
= event
->timestamp
;
4021 *start_pos_ptr
= Fcopy_alist (position
);
4024 /* Now we're releasing a button - check the co-ordinates to
4025 see if this was a click or a drag. */
4026 else if (event
->modifiers
& up_modifier
)
4028 /* If we did not see a down before this up,
4029 ignore the up. Probably this happened because
4030 the down event chose a menu item.
4031 It would be an annoyance to treat the release
4032 of the button that chose the menu item
4033 as a separate event. */
4035 if (!CONSP (start_pos
))
4038 event
->modifiers
&= ~up_modifier
;
4039 #if 0 /* Formerly we treated an up with no down as a click event. */
4040 if (!CONSP (start_pos
))
4041 event
->modifiers
|= click_modifier
;
4045 /* The third element of every position should be the (x,y)
4049 down
= Fnth (make_number (2), start_pos
);
4050 if (EQ (event
->x
, XCONS (down
)->car
)
4051 && EQ (event
->y
, XCONS (down
)->cdr
))
4053 event
->modifiers
|= click_modifier
;
4057 button_down_time
= 0;
4058 event
->modifiers
|= drag_modifier
;
4060 /* Don't check is_double; treat this as multiple
4061 if the down-event was multiple. */
4062 if (double_click_count
> 1)
4063 event
->modifiers
|= ((double_click_count
> 2)
4069 /* Every mouse event should either have the down_modifier or
4070 the up_modifier set. */
4074 /* Get the symbol we should use for the mouse click. */
4077 head
= modify_event_symbol (button
,
4080 lispy_mouse_names
, &mouse_syms
,
4081 (sizeof (lispy_mouse_names
)
4082 / sizeof (lispy_mouse_names
[0])));
4083 if (event
->modifiers
& drag_modifier
)
4088 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
4091 Fcons (make_number (double_click_count
),
4101 case w32_scroll_bar_click
:
4103 int button
= event
->code
;
4105 Lisp_Object position
;
4106 Lisp_Object
*start_pos_ptr
;
4107 Lisp_Object start_pos
;
4109 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
4114 Lisp_Object portion_whole
;
4117 window
= event
->frame_or_window
;
4118 portion_whole
= Fcons (event
->x
, event
->y
);
4119 part
= *scroll_bar_parts
[(int) event
->part
];
4123 Fcons (Qvertical_scroll_bar
,
4124 Fcons (portion_whole
,
4125 Fcons (make_number (event
->timestamp
),
4126 Fcons (part
, Qnil
)))));
4129 /* Always treat W32 scroll bar events as clicks. */
4130 event
->modifiers
|= click_modifier
;
4133 /* Get the symbol we should use for the mouse click. */
4136 head
= modify_event_symbol (button
,
4139 lispy_mouse_names
, &mouse_syms
,
4140 (sizeof (lispy_mouse_names
)
4141 / sizeof (lispy_mouse_names
[0])));
4150 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
4153 Lisp_Object head
, position
;
4156 /* Ignore mouse events that were made on frame that
4157 have been deleted. */
4158 if (! FRAME_LIVE_P (f
))
4160 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4161 &column
, &row
, NULL
, 1);
4162 window
= window_from_coordinates (f
, column
, row
, &part
);
4164 if (!WINDOWP (window
))
4166 window
= event
->frame_or_window
;
4171 int pixcolumn
, pixrow
;
4172 column
-= XINT (XWINDOW (window
)->left
);
4173 row
-= XINT (XWINDOW (window
)->top
);
4174 glyph_to_pixel_coords (f
, column
, row
, &pixcolumn
, &pixrow
);
4175 XSETINT (event
->x
, pixcolumn
);
4176 XSETINT (event
->y
, pixrow
);
4181 posn
= Qvertical_line
;
4184 buffer_posn_from_coords (XWINDOW (window
),
4189 Lisp_Object head
, position
;
4194 Fcons (Fcons (event
->x
, event
->y
),
4195 Fcons (make_number (event
->timestamp
),
4198 head
= modify_event_symbol (0, event
->modifiers
,
4200 lispy_mouse_wheel_names
,
4201 &mouse_wheel_syms
, 1);
4204 Fcons (make_number (event
->code
),
4208 #endif /* WINDOWSNT */
4209 #endif /* HAVE_MOUSE */
4211 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
4212 case menu_bar_event
:
4213 /* The event value is in the cdr of the frame_or_window slot. */
4214 if (!CONSP (event
->frame_or_window
))
4216 return XCONS (event
->frame_or_window
)->cdr
;
4219 /* The 'kind' field of the event is something we don't recognize. */
4228 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
4230 Lisp_Object bar_window
;
4231 enum scroll_bar_part part
;
4235 /* Is it a scroll bar movement? */
4236 if (frame
&& ! NILP (bar_window
))
4238 Lisp_Object part_sym
;
4240 part_sym
= *scroll_bar_parts
[(int) part
];
4241 return Fcons (Qscroll_bar_movement
,
4242 (Fcons (Fcons (bar_window
,
4243 Fcons (Qvertical_scroll_bar
,
4244 Fcons (Fcons (x
, y
),
4245 Fcons (make_number (time
),
4251 /* Or is it an ordinary mouse movement? */
4261 /* It's in a frame; which window on that frame? */
4262 pixel_to_glyph_coords (frame
, XINT (x
), XINT (y
), &column
, &row
,
4264 window
= window_from_coordinates (frame
, column
, row
, &area
);
4269 if (WINDOWP (window
))
4271 int pixcolumn
, pixrow
;
4272 column
-= WINDOW_LEFT_MARGIN (XWINDOW (window
));
4273 row
-= XINT (XWINDOW (window
)->top
);
4274 glyph_to_pixel_coords (frame
, column
, row
, &pixcolumn
, &pixrow
);
4275 XSETINT (x
, pixcolumn
);
4276 XSETINT (y
, pixrow
);
4281 posn
= Qvertical_line
;
4284 buffer_posn_from_coords (XWINDOW (window
), column
, row
));
4286 else if (frame
!= 0)
4288 XSETFRAME (window
, frame
);
4299 return Fcons (Qmouse_movement
,
4300 Fcons (Fcons (window
,
4302 Fcons (Fcons (x
, y
),
4303 Fcons (make_number (time
),
4309 #endif /* HAVE_MOUSE */
4311 /* Construct a switch frame event. */
4313 make_lispy_switch_frame (frame
)
4316 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
4319 /* Manipulating modifiers. */
4321 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
4323 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
4324 SYMBOL's name of the end of the modifiers; the string from this
4325 position is the unmodified symbol name.
4327 This doesn't use any caches. */
4330 parse_modifiers_uncached (symbol
, modifier_end
)
4334 struct Lisp_String
*name
;
4338 CHECK_SYMBOL (symbol
, 1);
4341 name
= XSYMBOL (symbol
)->name
;
4343 for (i
= 0; i
+2 <= STRING_BYTES (name
); )
4345 int this_mod_end
= 0;
4348 /* See if the name continues with a modifier word.
4349 Check that the word appears, but don't check what follows it.
4350 Set this_mod and this_mod_end to record what we find. */
4352 switch (name
->data
[i
])
4354 #define SINGLE_LETTER_MOD(BIT) \
4355 (this_mod_end = i + 1, this_mod = BIT)
4358 SINGLE_LETTER_MOD (alt_modifier
);
4362 SINGLE_LETTER_MOD (ctrl_modifier
);
4366 SINGLE_LETTER_MOD (hyper_modifier
);
4370 SINGLE_LETTER_MOD (meta_modifier
);
4374 SINGLE_LETTER_MOD (shift_modifier
);
4378 SINGLE_LETTER_MOD (super_modifier
);
4381 #undef SINGLE_LETTER_MOD
4384 /* If we found no modifier, stop looking for them. */
4385 if (this_mod_end
== 0)
4388 /* Check there is a dash after the modifier, so that it
4389 really is a modifier. */
4390 if (this_mod_end
>= STRING_BYTES (name
)
4391 || name
->data
[this_mod_end
] != '-')
4394 /* This modifier is real; look for another. */
4395 modifiers
|= this_mod
;
4396 i
= this_mod_end
+ 1;
4399 /* Should we include the `click' modifier? */
4400 if (! (modifiers
& (down_modifier
| drag_modifier
4401 | double_modifier
| triple_modifier
))
4402 && i
+ 7 == STRING_BYTES (name
)
4403 && strncmp (name
->data
+ i
, "mouse-", 6) == 0
4404 && ('0' <= name
->data
[i
+ 6] && name
->data
[i
+ 6] <= '9'))
4405 modifiers
|= click_modifier
;
4413 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
4414 prepended to the string BASE[0..BASE_LEN-1].
4415 This doesn't use any caches. */
4417 apply_modifiers_uncached (modifiers
, base
, base_len
, base_len_byte
)
4420 int base_len
, base_len_byte
;
4422 /* Since BASE could contain nulls, we can't use intern here; we have
4423 to use Fintern, which expects a genuine Lisp_String, and keeps a
4426 = (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
4432 /* Only the event queue may use the `up' modifier; it should always
4433 be turned into a click or drag event before presented to lisp code. */
4434 if (modifiers
& up_modifier
)
4437 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
4438 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
4439 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
4440 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
4441 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
4442 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
4443 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
4444 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
4445 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
4446 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
4447 /* The click modifier is denoted by the absence of other modifiers. */
4451 mod_len
= p
- new_mods
;
4455 Lisp_Object new_name
;
4457 new_name
= make_uninit_multibyte_string (mod_len
+ base_len
,
4458 mod_len
+ base_len_byte
);
4459 bcopy (new_mods
, XSTRING (new_name
)->data
, mod_len
);
4460 bcopy (base
, XSTRING (new_name
)->data
+ mod_len
, base_len_byte
);
4462 return Fintern (new_name
, Qnil
);
4467 static char *modifier_names
[] =
4469 "up", "down", "drag", "click", "double", "triple", 0, 0,
4470 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4471 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
4473 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
4475 static Lisp_Object modifier_symbols
;
4477 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
4479 lispy_modifier_list (modifiers
)
4482 Lisp_Object modifier_list
;
4485 modifier_list
= Qnil
;
4486 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
4487 if (modifiers
& (1<<i
))
4488 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
4491 return modifier_list
;
4495 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
4496 where UNMODIFIED is the unmodified form of SYMBOL,
4497 MASK is the set of modifiers present in SYMBOL's name.
4498 This is similar to parse_modifiers_uncached, but uses the cache in
4499 SYMBOL's Qevent_symbol_element_mask property, and maintains the
4500 Qevent_symbol_elements property. */
4503 parse_modifiers (symbol
)
4506 Lisp_Object elements
;
4508 elements
= Fget (symbol
, Qevent_symbol_element_mask
);
4509 if (CONSP (elements
))
4514 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
4515 Lisp_Object unmodified
;
4518 unmodified
= Fintern (make_string (XSYMBOL (symbol
)->name
->data
+ end
,
4519 STRING_BYTES (XSYMBOL (symbol
)->name
) - end
),
4522 if (modifiers
& ~(((EMACS_INT
)1 << VALBITS
) - 1))
4524 XSETFASTINT (mask
, modifiers
);
4525 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
4527 /* Cache the parsing results on SYMBOL. */
4528 Fput (symbol
, Qevent_symbol_element_mask
,
4530 Fput (symbol
, Qevent_symbol_elements
,
4531 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
4533 /* Since we know that SYMBOL is modifiers applied to unmodified,
4534 it would be nice to put that in unmodified's cache.
4535 But we can't, since we're not sure that parse_modifiers is
4542 /* Apply the modifiers MODIFIERS to the symbol BASE.
4543 BASE must be unmodified.
4545 This is like apply_modifiers_uncached, but uses BASE's
4546 Qmodifier_cache property, if present. It also builds
4547 Qevent_symbol_elements properties, since it has that info anyway.
4549 apply_modifiers copies the value of BASE's Qevent_kind property to
4550 the modified symbol. */
4552 apply_modifiers (modifiers
, base
)
4556 Lisp_Object cache
, index
, entry
, new_symbol
;
4558 /* Mask out upper bits. We don't know where this value's been. */
4559 modifiers
&= ((EMACS_INT
)1 << VALBITS
) - 1;
4561 /* The click modifier never figures into cache indices. */
4562 cache
= Fget (base
, Qmodifier_cache
);
4563 XSETFASTINT (index
, (modifiers
& ~click_modifier
));
4564 entry
= assq_no_quit (index
, cache
);
4567 new_symbol
= XCONS (entry
)->cdr
;
4570 /* We have to create the symbol ourselves. */
4571 new_symbol
= apply_modifiers_uncached (modifiers
,
4572 XSYMBOL (base
)->name
->data
,
4573 XSYMBOL (base
)->name
->size
,
4574 STRING_BYTES (XSYMBOL (base
)->name
));
4576 /* Add the new symbol to the base's cache. */
4577 entry
= Fcons (index
, new_symbol
);
4578 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
4580 /* We have the parsing info now for free, so add it to the caches. */
4581 XSETFASTINT (index
, modifiers
);
4582 Fput (new_symbol
, Qevent_symbol_element_mask
,
4583 Fcons (base
, Fcons (index
, Qnil
)));
4584 Fput (new_symbol
, Qevent_symbol_elements
,
4585 Fcons (base
, lispy_modifier_list (modifiers
)));
4588 /* Make sure this symbol is of the same kind as BASE.
4590 You'd think we could just set this once and for all when we
4591 intern the symbol above, but reorder_modifiers may call us when
4592 BASE's property isn't set right; we can't assume that just
4593 because it has a Qmodifier_cache property it must have its
4594 Qevent_kind set right as well. */
4595 if (NILP (Fget (new_symbol
, Qevent_kind
)))
4599 kind
= Fget (base
, Qevent_kind
);
4601 Fput (new_symbol
, Qevent_kind
, kind
);
4608 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
4609 return a symbol with the modifiers placed in the canonical order.
4610 Canonical order is alphabetical, except for down and drag, which
4611 always come last. The 'click' modifier is never written out.
4613 Fdefine_key calls this to make sure that (for example) C-M-foo
4614 and M-C-foo end up being equivalent in the keymap. */
4617 reorder_modifiers (symbol
)
4620 /* It's hopefully okay to write the code this way, since everything
4621 will soon be in caches, and no consing will be done at all. */
4624 parsed
= parse_modifiers (symbol
);
4625 return apply_modifiers ((int) XINT (XCONS (XCONS (parsed
)->cdr
)->car
),
4626 XCONS (parsed
)->car
);
4630 /* For handling events, we often want to produce a symbol whose name
4631 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
4632 to some base, like the name of a function key or mouse button.
4633 modify_event_symbol produces symbols of this sort.
4635 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
4636 is the name of the i'th symbol. TABLE_SIZE is the number of elements
4639 Alternatively, NAME_ALIST is an alist mapping codes into symbol names.
4640 NAME_ALIST is used if it is non-nil; otherwise NAME_TABLE is used.
4642 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
4643 persist between calls to modify_event_symbol that it can use to
4644 store a cache of the symbols it's generated for this NAME_TABLE
4645 before. The object stored there may be a vector or an alist.
4647 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
4649 MODIFIERS is a set of modifier bits (as given in struct input_events)
4650 whose prefixes should be applied to the symbol name.
4652 SYMBOL_KIND is the value to be placed in the event_kind property of
4653 the returned symbol.
4655 The symbols we create are supposed to have an
4656 `event-symbol-elements' property, which lists the modifiers present
4657 in the symbol's name. */
4660 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_alist
,
4661 name_table
, symbol_table
, table_size
)
4664 Lisp_Object symbol_kind
;
4665 Lisp_Object name_alist
;
4667 Lisp_Object
*symbol_table
;
4668 unsigned int table_size
;
4671 Lisp_Object symbol_int
;
4673 /* Get rid of the "vendor-specific" bit here. */
4674 XSETINT (symbol_int
, symbol_num
& 0xffffff);
4676 /* Is this a request for a valid symbol? */
4677 if (symbol_num
< 0 || symbol_num
>= table_size
)
4680 if (CONSP (*symbol_table
))
4681 value
= Fcdr (assq_no_quit (symbol_int
, *symbol_table
));
4683 /* If *symbol_table doesn't seem to be initialized properly, fix that.
4684 *symbol_table should be a lisp vector TABLE_SIZE elements long,
4685 where the Nth element is the symbol for NAME_TABLE[N], or nil if
4686 we've never used that symbol before. */
4689 if (! VECTORP (*symbol_table
)
4690 || XVECTOR (*symbol_table
)->size
!= table_size
)
4694 XSETFASTINT (size
, table_size
);
4695 *symbol_table
= Fmake_vector (size
, Qnil
);
4698 value
= XVECTOR (*symbol_table
)->contents
[symbol_num
];
4701 /* Have we already used this symbol before? */
4704 /* No; let's create it. */
4705 if (!NILP (name_alist
))
4706 value
= Fcdr_safe (Fassq (symbol_int
, name_alist
));
4707 else if (name_table
!= 0 && name_table
[symbol_num
])
4708 value
= intern (name_table
[symbol_num
]);
4710 #ifdef HAVE_WINDOW_SYSTEM
4713 char *name
= x_get_keysym_name (symbol_num
);
4715 value
= intern (name
);
4722 sprintf (buf
, "key-%d", symbol_num
);
4723 value
= intern (buf
);
4726 if (CONSP (*symbol_table
))
4727 *symbol_table
= Fcons (Fcons (symbol_int
, value
), *symbol_table
);
4729 XVECTOR (*symbol_table
)->contents
[symbol_num
] = value
;
4731 /* Fill in the cache entries for this symbol; this also
4732 builds the Qevent_symbol_elements property, which the user
4734 apply_modifiers (modifiers
& click_modifier
, value
);
4735 Fput (value
, Qevent_kind
, symbol_kind
);
4738 /* Apply modifiers to that symbol. */
4739 return apply_modifiers (modifiers
, value
);
4742 /* Convert a list that represents an event type,
4743 such as (ctrl meta backspace), into the usual representation of that
4744 event type as a number or a symbol. */
4746 DEFUN ("event-convert-list", Fevent_convert_list
, Sevent_convert_list
, 1, 1, 0,
4747 "Convert the event description list EVENT-DESC to an event type.\n\
4748 EVENT-DESC should contain one base event type (a character or symbol)\n\
4749 and zero or more modifier names (control, meta, hyper, super, shift, alt,\n\
4750 drag, down, double or triple). The base must be last.\n\
4751 The return value is an event type (a character or symbol) which\n\
4752 has the same base event type and all the specified modifiers.")
4754 Lisp_Object event_desc
;
4762 while (CONSP (rest
))
4767 elt
= XCONS (rest
)->car
;
4768 rest
= XCONS (rest
)->cdr
;
4770 /* Given a symbol, see if it is a modifier name. */
4771 if (SYMBOLP (elt
) && CONSP (rest
))
4772 this = parse_solitary_modifier (elt
);
4776 else if (!NILP (base
))
4777 error ("Two bases given in one event");
4783 /* Let the symbol A refer to the character A. */
4784 if (SYMBOLP (base
) && XSYMBOL (base
)->name
->size
== 1)
4785 XSETINT (base
, XSYMBOL (base
)->name
->data
[0]);
4787 if (INTEGERP (base
))
4789 /* Turn (shift a) into A. */
4790 if ((modifiers
& shift_modifier
) != 0
4791 && (XINT (base
) >= 'a' && XINT (base
) <= 'z'))
4793 XSETINT (base
, XINT (base
) - ('a' - 'A'));
4794 modifiers
&= ~shift_modifier
;
4797 /* Turn (control a) into C-a. */
4798 if (modifiers
& ctrl_modifier
)
4799 return make_number ((modifiers
& ~ctrl_modifier
)
4800 | make_ctrl_char (XINT (base
)));
4802 return make_number (modifiers
| XINT (base
));
4804 else if (SYMBOLP (base
))
4805 return apply_modifiers (modifiers
, base
);
4807 error ("Invalid base event");
4810 /* Try to recognize SYMBOL as a modifier name.
4811 Return the modifier flag bit, or 0 if not recognized. */
4814 parse_solitary_modifier (symbol
)
4817 struct Lisp_String
*name
= XSYMBOL (symbol
)->name
;
4819 switch (name
->data
[0])
4821 #define SINGLE_LETTER_MOD(BIT) \
4822 if (STRING_BYTES (name) == 1) \
4825 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
4826 if (LEN == STRING_BYTES (name) \
4827 && ! strncmp (name->data, NAME, LEN)) \
4831 SINGLE_LETTER_MOD (alt_modifier
);
4835 MULTI_LETTER_MOD (alt_modifier
, "alt", 3);
4839 SINGLE_LETTER_MOD (ctrl_modifier
);
4843 MULTI_LETTER_MOD (ctrl_modifier
, "ctrl", 4);
4844 MULTI_LETTER_MOD (ctrl_modifier
, "control", 7);
4848 SINGLE_LETTER_MOD (hyper_modifier
);
4852 MULTI_LETTER_MOD (hyper_modifier
, "hyper", 5);
4856 SINGLE_LETTER_MOD (meta_modifier
);
4860 MULTI_LETTER_MOD (meta_modifier
, "meta", 4);
4864 SINGLE_LETTER_MOD (shift_modifier
);
4868 MULTI_LETTER_MOD (shift_modifier
, "shift", 5);
4869 MULTI_LETTER_MOD (super_modifier
, "super", 5);
4870 SINGLE_LETTER_MOD (super_modifier
);
4874 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
4875 MULTI_LETTER_MOD (down_modifier
, "down", 4);
4876 MULTI_LETTER_MOD (double_modifier
, "double", 6);
4880 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
4883 #undef SINGLE_LETTER_MOD
4884 #undef MULTI_LETTER_MOD
4890 /* Return 1 if EVENT is a list whose elements are all integers or symbols.
4891 Such a list is not valid as an event,
4892 but it can be a Lucid-style event type list. */
4895 lucid_event_type_list_p (object
)
4900 if (! CONSP (object
))
4903 for (tail
= object
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4906 elt
= XCONS (tail
)->car
;
4907 if (! (INTEGERP (elt
) || SYMBOLP (elt
)))
4914 /* Store into *addr a value nonzero if terminal input chars are available.
4915 Serves the purpose of ioctl (0, FIONREAD, addr)
4916 but works even if FIONREAD does not exist.
4917 (In fact, this may actually read some input.)
4919 If DO_TIMERS_NOW is nonzero, actually run timer events that are ripe. */
4922 get_input_pending (addr
, do_timers_now
)
4926 /* First of all, have we already counted some input? */
4927 *addr
= !NILP (Vquit_flag
) || readable_events (do_timers_now
);
4929 /* If input is being read as it arrives, and we have none, there is none. */
4930 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
4933 /* Try to read some input and see how much we get. */
4935 *addr
= !NILP (Vquit_flag
) || readable_events (do_timers_now
);
4938 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
4941 gobble_input (expected
)
4946 if (interrupt_input
)
4949 mask
= sigblock (sigmask (SIGIO
));
4950 read_avail_input (expected
);
4954 #ifdef POLL_FOR_INPUT
4955 if (read_socket_hook
&& !interrupt_input
&& poll_suppress_count
== 0)
4958 mask
= sigblock (sigmask (SIGALRM
));
4959 read_avail_input (expected
);
4965 read_avail_input (expected
);
4969 /* Put a buffer_switch_event in the buffer
4970 so that read_key_sequence will notice the new current buffer. */
4973 record_asynch_buffer_change ()
4975 struct input_event event
;
4978 event
.kind
= buffer_switch_event
;
4979 event
.frame_or_window
= Qnil
;
4982 /* We don't need a buffer-switch event unless Emacs is waiting for input.
4983 The purpose of the event is to make read_key_sequence look up the
4984 keymaps again. If we aren't in read_key_sequence, we don't need one,
4985 and the event could cause trouble by messing up (input-pending-p). */
4986 tem
= Fwaiting_for_user_input_p ();
4990 /* We never need these events if we have no asynchronous subprocesses. */
4994 /* Make sure no interrupt happens while storing the event. */
4996 if (interrupt_input
)
4999 mask
= sigblock (sigmask (SIGIO
));
5000 kbd_buffer_store_event (&event
);
5007 kbd_buffer_store_event (&event
);
5014 /* Read any terminal input already buffered up by the system
5015 into the kbd_buffer, but do not wait.
5017 EXPECTED should be nonzero if the caller knows there is some input.
5019 Except on VMS, all input is read by this function.
5020 If interrupt_input is nonzero, this function MUST be called
5021 only when SIGIO is blocked.
5023 Returns the number of keyboard chars read, or -1 meaning
5024 this is a bad time to try to read input. */
5027 read_avail_input (expected
)
5030 struct input_event buf
[KBD_BUFFER_SIZE
];
5034 if (read_socket_hook
)
5035 /* No need for FIONREAD or fcntl; just say don't wait. */
5036 nread
= (*read_socket_hook
) (input_fd
, buf
, KBD_BUFFER_SIZE
, expected
);
5039 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
5040 the kbd_buffer can really hold. That may prevent loss
5041 of characters on some systems when input is stuffed at us. */
5042 unsigned char cbuf
[KBD_BUFFER_SIZE
- 1];
5045 /* Determine how many characters we should *try* to read. */
5048 #else /* not WINDOWSNT */
5050 n_to_read
= dos_keysns ();
5053 #else /* not MSDOS */
5055 /* Find out how much input is available. */
5056 if (ioctl (input_fd
, FIONREAD
, &n_to_read
) < 0)
5057 /* Formerly simply reported no input, but that sometimes led to
5058 a failure of Emacs to terminate.
5059 SIGHUP seems appropriate if we can't reach the terminal. */
5060 /* ??? Is it really right to send the signal just to this process
5061 rather than to the whole process group?
5062 Perhaps on systems with FIONREAD Emacs is alone in its group. */
5063 kill (getpid (), SIGHUP
);
5066 if (n_to_read
> sizeof cbuf
)
5067 n_to_read
= sizeof cbuf
;
5068 #else /* no FIONREAD */
5069 #if defined (USG) || defined (DGUX)
5070 /* Read some input if available, but don't wait. */
5071 n_to_read
= sizeof cbuf
;
5072 fcntl (input_fd
, F_SETFL
, O_NDELAY
);
5077 #endif /* not MSDOS */
5078 #endif /* not WINDOWSNT */
5080 /* Now read; for one reason or another, this will not block.
5081 NREAD is set to the number of chars read. */
5085 cbuf
[0] = dos_keyread ();
5088 nread
= read (input_fd
, cbuf
, n_to_read
);
5090 /* POSIX infers that processes which are not in the session leader's
5091 process group won't get SIGHUP's at logout time. BSDI adheres to
5092 this part standard and returns -1 from read (0) with errno==EIO
5093 when the control tty is taken away.
5094 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
5095 if (nread
== -1 && errno
== EIO
)
5097 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
5098 /* The kernel sometimes fails to deliver SIGHUP for ptys.
5099 This looks incorrect, but it isn't, because _BSD causes
5100 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
5101 and that causes a value other than 0 when there is no input. */
5107 /* We used to retry the read if it was interrupted.
5108 But this does the wrong thing when O_NDELAY causes
5109 an EAGAIN error. Does anybody know of a situation
5110 where a retry is actually needed? */
5112 nread
< 0 && (errno
== EAGAIN
5126 #if defined (USG) || defined (DGUX)
5127 fcntl (input_fd
, F_SETFL
, 0);
5128 #endif /* USG or DGUX */
5129 #endif /* no FIONREAD */
5130 for (i
= 0; i
< nread
; i
++)
5132 buf
[i
].kind
= ascii_keystroke
;
5133 buf
[i
].modifiers
= 0;
5134 if (meta_key
== 1 && (cbuf
[i
] & 0x80))
5135 buf
[i
].modifiers
= meta_modifier
;
5139 buf
[i
].code
= cbuf
[i
];
5140 XSETFRAME (buf
[i
].frame_or_window
, selected_frame
);
5144 /* Scan the chars for C-g and store them in kbd_buffer. */
5145 for (i
= 0; i
< nread
; i
++)
5147 kbd_buffer_store_event (&buf
[i
]);
5148 /* Don't look at input that follows a C-g too closely.
5149 This reduces lossage due to autorepeat on C-g. */
5150 if (buf
[i
].kind
== ascii_keystroke
5151 && buf
[i
].code
== quit_char
)
5157 #endif /* not VMS */
5159 #ifdef SIGIO /* for entire page */
5160 /* Note SIGIO has been undef'd if FIONREAD is missing. */
5163 input_available_signal (signo
)
5166 /* Must preserve main program's value of errno. */
5167 int old_errno
= errno
;
5169 extern int select_alarmed
;
5172 #if defined (USG) && !defined (POSIX_SIGNALS)
5173 /* USG systems forget handlers when they are used;
5174 must reestablish each time */
5175 signal (signo
, input_available_signal
);
5182 if (input_available_clear_time
)
5183 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
5188 nread
= read_avail_input (1);
5189 /* -1 means it's not ok to read the input now.
5190 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
5191 0 means there was no keyboard input available. */
5196 select_alarmed
= 1; /* Force the select emulator back to life */
5207 /* Send ourselves a SIGIO.
5209 This function exists so that the UNBLOCK_INPUT macro in
5210 blockinput.h can have some way to take care of input we put off
5211 dealing with, without assuming that every file which uses
5212 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
5214 reinvoke_input_signal ()
5217 kill (getpid (), SIGIO
);
5223 /* Return the prompt-string of a sparse keymap.
5224 This is the first element which is a string.
5225 Return nil if there is none. */
5233 register Lisp_Object tem
;
5242 static void menu_bar_item ();
5243 static void menu_bar_one_keymap ();
5245 /* These variables hold the vector under construction within
5246 menu_bar_items and its subroutines, and the current index
5247 for storing into that vector. */
5248 static Lisp_Object menu_bar_items_vector
;
5249 static int menu_bar_items_index
;
5251 /* Return a vector of menu items for a menu bar, appropriate
5252 to the current buffer. Each item has three elements in the vector:
5255 OLD is an old vector we can optionally reuse, or nil. */
5258 menu_bar_items (old
)
5261 /* The number of keymaps we're scanning right now, and the number of
5262 keymaps we have allocated space for. */
5265 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
5266 in the current keymaps, or nil where it is not a prefix. */
5269 Lisp_Object def
, tem
, tail
;
5278 struct gcpro gcpro1
;
5280 /* In order to build the menus, we need to call the keymap
5281 accessors. They all call QUIT. But this function is called
5282 during redisplay, during which a quit is fatal. So inhibit
5283 quitting while building the menus.
5284 We do this instead of specbind because (1) errors will clear it anyway
5285 and (2) this avoids risk of specpdl overflow. */
5286 oquit
= Vinhibit_quit
;
5290 menu_bar_items_vector
= old
;
5292 menu_bar_items_vector
= Fmake_vector (make_number (24), Qnil
);
5293 menu_bar_items_index
= 0;
5295 GCPRO1 (menu_bar_items_vector
);
5297 /* Build our list of keymaps.
5298 If we recognize a function key and replace its escape sequence in
5299 keybuf with its symbol, or if the sequence starts with a mouse
5300 click and we need to switch buffers, we jump back here to rebuild
5301 the initial keymaps from the current buffer. */
5305 /* Should overriding-terminal-local-map and overriding-local-map apply? */
5306 if (!NILP (Voverriding_local_map_menu_flag
))
5308 /* Yes, use them (if non-nil) as well as the global map. */
5309 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
5311 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
5312 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
5313 if (!NILP (Voverriding_local_map
))
5314 maps
[nmaps
++] = Voverriding_local_map
;
5318 /* No, so use major and minor mode keymaps. */
5319 nmaps
= current_minor_maps (NULL
, &tmaps
);
5320 maps
= (Lisp_Object
*) alloca ((nmaps
+ 2) * sizeof (maps
[0]));
5321 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
5322 #ifdef USE_TEXT_PROPERTIES
5323 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
5325 maps
[nmaps
++] = current_buffer
->keymap
;
5328 maps
[nmaps
++] = current_global_map
;
5331 /* Look up in each map the dummy prefix key `menu-bar'. */
5335 for (mapno
= nmaps
- 1; mapno
>= 0; mapno
--)
5337 if (! NILP (maps
[mapno
]))
5338 def
= get_keyelt (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0), 0);
5342 tem
= Fkeymapp (def
);
5344 menu_bar_one_keymap (def
);
5347 /* Move to the end those items that should be at the end. */
5349 for (tail
= Vmenu_bar_final_items
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5352 int end
= menu_bar_items_index
;
5354 for (i
= 0; i
< end
; i
+= 4)
5355 if (EQ (XCONS (tail
)->car
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
5357 Lisp_Object tem0
, tem1
, tem2
, tem3
;
5358 /* Move the item at index I to the end,
5359 shifting all the others forward. */
5360 tem0
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 0];
5361 tem1
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 1];
5362 tem2
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
5363 tem3
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3];
5365 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
5366 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
5367 (end
- i
- 4) * sizeof (Lisp_Object
));
5368 XVECTOR (menu_bar_items_vector
)->contents
[end
- 4] = tem0
;
5369 XVECTOR (menu_bar_items_vector
)->contents
[end
- 3] = tem1
;
5370 XVECTOR (menu_bar_items_vector
)->contents
[end
- 2] = tem2
;
5371 XVECTOR (menu_bar_items_vector
)->contents
[end
- 1] = tem3
;
5376 /* Add nil, nil, nil, nil at the end. */
5377 i
= menu_bar_items_index
;
5378 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
5381 int newsize
= 2 * i
;
5382 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
5383 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
5384 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
5385 menu_bar_items_vector
= tem
;
5387 /* Add this item. */
5388 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5389 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5390 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5391 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5392 menu_bar_items_index
= i
;
5394 Vinhibit_quit
= oquit
;
5396 return menu_bar_items_vector
;
5399 /* Scan one map KEYMAP, accumulating any menu items it defines
5400 in menu_bar_items_vector. */
5403 menu_bar_one_keymap (keymap
)
5406 Lisp_Object tail
, item
, table
;
5408 /* Loop over all keymap entries that have menu strings. */
5409 for (tail
= keymap
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5411 item
= XCONS (tail
)->car
;
5413 menu_bar_item (XCONS (item
)->car
, XCONS (item
)->cdr
);
5414 else if (VECTORP (item
))
5416 /* Loop over the char values represented in the vector. */
5417 int len
= XVECTOR (item
)->size
;
5419 for (c
= 0; c
< len
; c
++)
5421 Lisp_Object character
;
5422 XSETFASTINT (character
, c
);
5423 menu_bar_item (character
, XVECTOR (item
)->contents
[c
]);
5429 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
5430 If there's already an item for KEY, add this DEF to it. */
5432 Lisp_Object item_properties
;
5435 menu_bar_item (key
, item
)
5436 Lisp_Object key
, item
;
5438 struct gcpro gcpro1
;
5441 if (EQ (item
, Qundefined
))
5443 /* If a map has an explicit `undefined' as definition,
5444 discard any previously made menu bar item. */
5446 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
5447 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
5449 if (menu_bar_items_index
> i
+ 4)
5450 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
5451 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
5452 (menu_bar_items_index
- i
- 4) * sizeof (Lisp_Object
));
5453 menu_bar_items_index
-= 4;
5457 /* If there's no definition for this key yet,
5458 just ignore `undefined'. */
5462 GCPRO1 (key
); /* Is this necessary? */
5463 i
= parse_menu_item (item
, 0, 1);
5468 item
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
5470 /* Find any existing item for this KEY. */
5471 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
5472 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
5475 /* If we did not find this KEY, add it at the end. */
5476 if (i
== menu_bar_items_index
)
5478 /* If vector is too small, get a bigger one. */
5479 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
5482 int newsize
= 2 * i
;
5483 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
5484 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
5485 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
5486 menu_bar_items_vector
= tem
;
5489 /* Add this item. */
5490 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = key
;
5491 XVECTOR (menu_bar_items_vector
)->contents
[i
++]
5492 = XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
5493 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Fcons (item
, Qnil
);
5494 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = make_number (0);
5495 menu_bar_items_index
= i
;
5497 /* We did find an item for this KEY. Add ITEM to its list of maps. */
5501 old
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
5502 XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2] = Fcons (item
, old
);
5506 /* This is used as the handler when calling menu_item_eval_property. */
5508 menu_item_eval_property_1 (arg
)
5511 /* If we got a quit from within the menu computation,
5512 quit all the way out of it. This takes care of C-] in the debugger. */
5513 if (CONSP (arg
) && EQ (XCONS (arg
)->car
, Qquit
))
5514 Fsignal (Qquit
, Qnil
);
5519 /* Evaluate an expression and return the result (or nil if something
5520 went wrong). Used to evaluate dynamic parts of menu items. */
5522 menu_item_eval_property (sexpr
)
5526 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
,
5527 menu_item_eval_property_1
);
5531 /* This function parses a menu item and leaves the result in the
5532 vector item_properties.
5533 ITEM is a key binding, a possible menu item.
5534 If NOTREAL is nonzero, only check for equivalent key bindings, don't
5535 evaluate dynamic expressions in the menu item.
5536 INMENUBAR is true when this is considered for an entry in a menu bar
5538 parse_menu_item returns true if the item is a menu item and false
5542 parse_menu_item (item
, notreal
, inmenubar
)
5544 int notreal
, inmenubar
;
5546 Lisp_Object def
, tem
;
5548 Lisp_Object type
= Qnil
;
5549 Lisp_Object cachelist
= Qnil
;
5550 Lisp_Object filter
= Qnil
;
5551 Lisp_Object item_string
, start
;
5553 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5566 GCPRO3 (item
, notreal
, inmenubar
);
5568 /* Create item_properties vector if necessary. */
5569 if (NILP (item_properties
))
5571 = Fmake_vector (make_number (ITEM_PROPERTY_ENABLE
+ 1), Qnil
);
5573 /* Initialize optional entries. */
5574 for (i
= ITEM_PROPERTY_DEF
; i
< ITEM_PROPERTY_ENABLE
; i
++)
5575 XVECTOR (item_properties
)->contents
[i
] = Qnil
;
5576 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
] = Qt
;
5578 /* Save the item here to protect it from GC. */
5579 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ITEM
] = item
;
5581 item_string
= XCONS (item
)->car
;
5584 item
= XCONS (item
)->cdr
;
5585 if (STRINGP (item_string
))
5587 /* Old format menu item. */
5588 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
] = item_string
;
5590 /* Maybe help string. */
5591 if (CONSP (item
) && STRINGP (XCONS (item
)->car
))
5593 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_HELP
]
5594 = XCONS (item
)->car
;
5596 item
= XCONS (item
)->cdr
;
5599 /* Maybee key binding cache. */
5600 if (CONSP (item
) && CONSP (XCONS (item
)->car
)
5601 && (NILP (XCONS (XCONS (item
)->car
)->car
)
5602 || VECTORP (XCONS (XCONS (item
)->car
)->car
)))
5604 cachelist
= XCONS (item
)->car
;
5605 item
= XCONS (item
)->cdr
;
5608 /* This is the real definition--the function to run. */
5609 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
] = item
;
5611 /* Get enable property, if any. */
5614 tem
= Fget (item
, Qmenu_enable
);
5616 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
] = tem
;
5619 else if (EQ (item_string
, Qmenu_item
) && CONSP (item
))
5621 /* New format menu item. */
5622 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
]
5623 = XCONS (item
)->car
;
5624 start
= XCONS (item
)->cdr
;
5627 /* We have a real binding. */
5628 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
]
5629 = XCONS (start
)->car
;
5631 item
= XCONS (start
)->cdr
;
5632 /* Is there a cache list with key equivalences. */
5633 if (CONSP (item
) && CONSP (XCONS (item
)->car
))
5635 cachelist
= XCONS (item
)->car
;
5636 item
= XCONS (item
)->cdr
;
5639 /* Parse properties. */
5640 while (CONSP (item
) && CONSP (XCONS (item
)->cdr
))
5642 tem
= XCONS (item
)->car
;
5643 item
= XCONS (item
)->cdr
;
5645 if (EQ (tem
, QCenable
))
5646 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
]
5647 = XCONS (item
)->car
;
5648 else if (EQ (tem
, QCvisible
) && !notreal
)
5650 /* If got a visible property and that evaluates to nil
5651 then ignore this item. */
5652 tem
= menu_item_eval_property (XCONS (item
)->car
);
5656 else if (EQ (tem
, QChelp
))
5657 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_HELP
]
5658 = XCONS (item
)->car
;
5659 else if (EQ (tem
, QCfilter
))
5660 filter
= XCONS (item
)->car
;
5661 else if (EQ (tem
, QCbutton
) && CONSP (XCONS (item
)->car
))
5663 tem
= XCONS (item
)->car
;
5664 type
= XCONS (tem
)->car
;
5665 if (EQ (type
, QCtoggle
) || EQ (type
, QCradio
))
5667 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
]
5669 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_TYPE
]
5673 item
= XCONS (item
)->cdr
;
5676 else if (inmenubar
|| !NILP (start
))
5682 /* If item string is not a string, evaluate it to get string.
5683 If we don't get a string, skip this item. */
5684 item_string
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
5685 if (!(STRINGP (item_string
) || notreal
))
5687 item_string
= menu_item_eval_property (item_string
);
5688 if (!STRINGP (item_string
))
5690 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
] = item_string
;
5693 /* If got a filter apply it on definition. */
5694 def
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
];
5697 def
= menu_item_eval_property (Fcons (filter
, Fcons (def
, Qnil
)));
5698 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
] = def
;
5701 /* If we got no definition, this item is just unselectable text which
5702 is ok when in a submenu and if there is an item string. */
5703 item_string
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_NAME
];
5707 return (!inmenubar
&& STRINGP (item_string
) ? 1 : 0);
5710 /* Enable or disable selection of item. */
5711 tem
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
];
5717 tem
= menu_item_eval_property (tem
);
5718 if (inmenubar
&& NILP (tem
))
5719 RET0
; /* Ignore disabled items in menu bar. */
5720 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_ENABLE
] = tem
;
5723 /* See if this is a separate pane or a submenu. */
5724 tem
= get_keymap_1 (def
, 0, 1);
5727 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_MAP
] = tem
;
5728 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_DEF
] = tem
;
5733 RET0
; /* Entries in menu bar must be submenus. */
5735 /* This is a command. See if there is an equivalent key binding. */
5736 if (NILP (cachelist
))
5738 /* We have to create a cachelist. */
5739 CHECK_IMPURE (start
);
5740 XCONS (start
)->cdr
= Fcons (Fcons (Qnil
, Qnil
), XCONS (start
)->cdr
);
5741 cachelist
= XCONS (XCONS (start
)->cdr
)->car
;
5742 /* We have not checked this before so check it now. */
5745 else if (VECTORP (XCONS (cachelist
)->car
)) /* Saved key */
5747 tem
= Fkey_binding (XCONS (cachelist
)->car
, Qnil
);
5749 /* If the command is an alias for another
5750 (such as easymenu.el and lmenu.el set it up),
5751 check if the original command matches the cached command. */
5752 || (SYMBOLP (def
) && EQ (tem
, XSYMBOL (def
)->function
)))
5753 tem
= Qnil
; /* Don't need to recompute key binding. */
5757 /* If something had no key binding before, don't recheck it
5758 because that is too slow--except if we have a list of rebound
5759 commands in Vdefine_key_rebound_commands, do recheck any command
5760 that appears in that list. */
5761 else if (!NILP (XCONS (cachelist
)->car
))
5762 tem
= def
; /* Should signal an error here. */
5764 /* Should we check everything when precomputing key bindings? */
5766 CONSP (Vdefine_key_rebound_commands
)
5767 && !NILP (Fmemq (def
, Vdefine_key_rebound_commands
)))
5774 /* Recompute equivalent key binding.
5775 If the command is an alias for another
5776 (such as easymenu.el and lmenu.el set it up),
5777 see if the original command name has equivalent keys.
5778 Otherwise look up the specified command itself.
5779 We don't try both, because that makes easymenu menus slow. */
5780 if (SYMBOLP (def
) && SYMBOLP (XSYMBOL (def
)->function
)
5781 && ! NILP (Fget (def
, Qmenu_alias
)))
5782 tem
= XSYMBOL (def
)->function
;
5783 tem
= Fwhere_is_internal (tem
, Qnil
, Qt
, Qnil
);
5784 XCONS (cachelist
)->car
= tem
;
5785 XCONS (cachelist
)->cdr
5786 = (NILP (tem
) ? Qnil
5788 concat2 (build_string (" ("),
5789 concat2 (Fkey_description (tem
), build_string (")"))));
5792 /* If we only want to precompute equivalent key bindings, stop here. */
5799 /* If we have an equivalent key binding, use that. */
5800 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_KEYEQ
]
5801 = XCONS (cachelist
)->cdr
;
5803 /* Include this when menu help is implemented.
5804 tem = XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP];
5805 if (!(NILP (tem) || STRINGP (tem)))
5807 tem = menu_item_eval_property (tem);
5810 XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP] = tem;
5814 /* Handle radio buttons or toggle boxes. */
5815 tem
= XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
];
5817 XVECTOR (item_properties
)->contents
[ITEM_PROPERTY_SELECTED
]
5818 = menu_item_eval_property (tem
);
5824 /* Read a character using menus based on maps in the array MAPS.
5825 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
5826 Return t if we displayed a menu but the user rejected it.
5828 PREV_EVENT is the previous input event, or nil if we are reading
5829 the first event of a key sequence.
5831 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
5832 if we used a mouse menu to read the input, or zero otherwise. If
5833 USED_MOUSE_MENU is null, we don't dereference it.
5835 The prompting is done based on the prompt-string of the map
5836 and the strings associated with various map elements.
5838 This can be done with X menus or with menus put in the minibuf.
5839 These are done in different ways, depending on how the input will be read.
5840 Menus using X are done after auto-saving in read-char, getting the input
5841 event from Fx_popup_menu; menus using the minibuf use read_char recursively
5842 and do auto-saving in the inner call of read_char. */
5845 read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
5848 Lisp_Object prev_event
;
5849 int *used_mouse_menu
;
5852 register Lisp_Object name
;
5853 Lisp_Object rest
, vector
;
5855 if (used_mouse_menu
)
5856 *used_mouse_menu
= 0;
5858 /* Use local over global Menu maps */
5860 if (! menu_prompting
)
5863 /* Optionally disregard all but the global map. */
5864 if (inhibit_local_menu_bar_menus
)
5866 maps
+= (nmaps
- 1);
5870 /* Get the menu name from the first map that has one (a prompt string). */
5871 for (mapno
= 0; mapno
< nmaps
; mapno
++)
5873 name
= map_prompt (maps
[mapno
]);
5878 /* If we don't have any menus, just read a character normally. */
5883 /* If we got to this point via a mouse click,
5884 use a real menu for mouse selection. */
5885 if (EVENT_HAS_PARAMETERS (prev_event
)
5886 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
))
5888 /* Display the menu and get the selection. */
5889 Lisp_Object
*realmaps
5890 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
5894 /* Use the maps that are not nil. */
5895 for (mapno
= 0; mapno
< nmaps
; mapno
++)
5896 if (!NILP (maps
[mapno
]))
5897 realmaps
[nmaps1
++] = maps
[mapno
];
5899 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
5904 record_menu_key (XCONS (value
)->car
);
5906 /* If we got multiple events, unread all but
5908 There is no way to prevent those unread events
5909 from showing up later in last_nonmenu_event.
5910 So turn symbol and integer events into lists,
5911 to indicate that they came from a mouse menu,
5912 so that when present in last_nonmenu_event
5913 they won't confuse things. */
5914 for (tem
= XCONS (value
)->cdr
; !NILP (tem
);
5915 tem
= XCONS (tem
)->cdr
)
5917 record_menu_key (XCONS (tem
)->car
);
5918 if (SYMBOLP (XCONS (tem
)->car
)
5919 || INTEGERP (XCONS (tem
)->car
))
5921 = Fcons (XCONS (tem
)->car
, Qnil
);
5924 /* If we got more than one event, put all but the first
5925 onto this list to be read later.
5926 Return just the first event now. */
5927 Vunread_command_events
5928 = nconc2 (XCONS (value
)->cdr
, Vunread_command_events
);
5929 value
= XCONS (value
)->car
;
5931 else if (NILP (value
))
5933 if (used_mouse_menu
)
5934 *used_mouse_menu
= 1;
5937 #endif /* HAVE_MENUS */
5941 /* Buffer in use so far for the minibuf prompts for menu keymaps.
5942 We make this bigger when necessary, and never free it. */
5943 static char *read_char_minibuf_menu_text
;
5944 /* Size of that buffer. */
5945 static int read_char_minibuf_menu_width
;
5948 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
5954 register Lisp_Object name
;
5956 int width
= FRAME_WIDTH (selected_frame
) - 4;
5959 Lisp_Object rest
, vector
;
5962 if (! menu_prompting
)
5965 /* Make sure we have a big enough buffer for the menu text. */
5966 if (read_char_minibuf_menu_text
== 0)
5968 read_char_minibuf_menu_width
= width
+ 4;
5969 read_char_minibuf_menu_text
= (char *) xmalloc (width
+ 4);
5971 else if (width
+ 4 > read_char_minibuf_menu_width
)
5973 read_char_minibuf_menu_width
= width
+ 4;
5974 read_char_minibuf_menu_text
5975 = (char *) xrealloc (read_char_minibuf_menu_text
, width
+ 4);
5977 menu
= read_char_minibuf_menu_text
;
5979 /* Get the menu name from the first map that has one (a prompt string). */
5980 for (mapno
= 0; mapno
< nmaps
; mapno
++)
5982 name
= map_prompt (maps
[mapno
]);
5987 /* If we don't have any menus, just read a character normally. */
5991 /* Prompt string always starts with map's prompt, and a space. */
5992 strcpy (menu
, XSTRING (name
)->data
);
5993 nlength
= STRING_BYTES (XSTRING (name
));
5994 menu
[nlength
++] = ':';
5995 menu
[nlength
++] = ' ';
5998 /* Start prompting at start of first map. */
6002 /* Present the documented bindings, a line at a time. */
6009 Lisp_Object orig_defn_macro
;
6011 /* Loop over elements of map. */
6016 /* If reached end of map, start at beginning of next map. */
6020 /* At end of last map, wrap around to first map if just starting,
6021 or end this line if already have something on it. */
6025 if (notfirst
|| nobindings
) break;
6030 /* Look at the next element of the map. */
6032 elt
= XVECTOR (vector
)->contents
[idx
];
6034 elt
= Fcar_safe (rest
);
6036 if (idx
< 0 && VECTORP (elt
))
6038 /* If we found a dense table in the keymap,
6039 advanced past it, but start scanning its contents. */
6040 rest
= Fcdr_safe (rest
);
6046 /* An ordinary element. */
6051 s
= Fcar_safe (Fcdr_safe (elt
)); /* alist */
6052 event
= Fcar_safe (elt
);
6056 s
= Fcar_safe (elt
); /* vector */
6057 XSETINT (event
, idx
);
6060 /* Ignore the element if it has no prompt string. */
6061 if (STRINGP (s
) && INTEGERP (event
))
6063 /* 1 if the char to type matches the string. */
6065 Lisp_Object upcased_event
, downcased_event
;
6068 upcased_event
= Fupcase (event
);
6069 downcased_event
= Fdowncase (event
);
6070 char_matches
= (XINT (upcased_event
) == XSTRING (s
)->data
[0]
6071 || XINT (downcased_event
) == XSTRING (s
)->data
[0]);
6073 desc
= Fsingle_key_description (event
);
6075 /* If we have room for the prompt string, add it to this line.
6076 If this is the first on the line, always add it. */
6077 if ((XSTRING (s
)->size
+ i
+ 2
6078 + (char_matches
? 0 : XSTRING (desc
)->size
+ 3))
6084 /* Punctuate between strings. */
6087 strcpy (menu
+ i
, ", ");
6093 /* If the char to type doesn't match the string's
6094 first char, explicitly show what char to type. */
6097 /* Add as much of string as fits. */
6098 thiswidth
= XSTRING (desc
)->size
;
6099 if (thiswidth
+ i
> width
)
6100 thiswidth
= width
- i
;
6101 bcopy (XSTRING (desc
)->data
, menu
+ i
, thiswidth
);
6103 strcpy (menu
+ i
, " = ");
6107 /* Add as much of string as fits. */
6108 thiswidth
= XSTRING (s
)->size
;
6109 if (thiswidth
+ i
> width
)
6110 thiswidth
= width
- i
;
6111 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
6117 /* If this element does not fit, end the line now,
6118 and save the element for the next line. */
6119 strcpy (menu
+ i
, "...");
6124 /* Move past this element. */
6125 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
6126 /* Handle reaching end of dense table. */
6131 rest
= Fcdr_safe (rest
);
6135 /* Prompt with that and read response. */
6136 message2_nolog (menu
, strlen (menu
),
6137 ! NILP (current_buffer
->enable_multibyte_characters
));
6139 /* Make believe its not a keyboard macro in case the help char
6140 is pressed. Help characters are not recorded because menu prompting
6141 is not used on replay.
6143 orig_defn_macro
= current_kboard
->defining_kbd_macro
;
6144 current_kboard
->defining_kbd_macro
= Qnil
;
6146 obj
= read_char (commandflag
, 0, 0, Qnil
, 0);
6147 while (BUFFERP (obj
));
6148 current_kboard
->defining_kbd_macro
= orig_defn_macro
;
6150 if (!INTEGERP (obj
))
6155 if (! EQ (obj
, menu_prompt_more_char
)
6156 && (!INTEGERP (menu_prompt_more_char
)
6157 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
6159 if (!NILP (current_kboard
->defining_kbd_macro
))
6160 store_kbd_macro_char (obj
);
6163 /* Help char - go round again */
6167 /* Reading key sequences. */
6169 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
6170 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
6171 keymap, or nil otherwise. Return the index of the first keymap in
6172 which KEY has any binding, or NMAPS if no map has a binding.
6174 If KEY is a meta ASCII character, treat it like meta-prefix-char
6175 followed by the corresponding non-meta character. Keymaps in
6176 CURRENT with non-prefix bindings for meta-prefix-char become nil in
6179 If KEY has no bindings in any of the CURRENT maps, NEXT is left
6182 NEXT may be the same array as CURRENT. */
6185 follow_key (key
, nmaps
, current
, defs
, next
)
6187 Lisp_Object
*current
, *defs
, *next
;
6190 int i
, first_binding
;
6193 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
6194 followed by the corresponding non-meta character.
6195 Put the results into DEFS, since we are going to alter that anyway.
6196 Do not alter CURRENT or NEXT. */
6197 if (INTEGERP (key
) && (XINT (key
) & CHAR_META
))
6199 for (i
= 0; i
< nmaps
; i
++)
6200 if (! NILP (current
[i
]))
6203 def
= get_keyelt (access_keymap (current
[i
],
6204 meta_prefix_char
, 1, 0), 0);
6206 /* Note that since we pass the resulting bindings through
6207 get_keymap_1, non-prefix bindings for meta-prefix-char
6209 defs
[i
] = get_keymap_1 (def
, 0, 1);
6215 XSETINT (key
, XFASTINT (key
) & ~CHAR_META
);
6218 first_binding
= nmaps
;
6219 for (i
= nmaps
- 1; i
>= 0; i
--)
6221 if (! NILP (current
[i
]))
6229 defs
[i
] = get_keyelt (access_keymap (map
, key
, 1, 0), 0);
6230 if (! NILP (defs
[i
]))
6237 /* Given the set of bindings we've found, produce the next set of maps. */
6238 if (first_binding
< nmaps
)
6239 for (i
= 0; i
< nmaps
; i
++)
6240 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0, 1);
6242 return first_binding
;
6245 /* Read a sequence of keys that ends with a non prefix character,
6246 storing it in KEYBUF, a buffer of size BUFSIZE.
6248 Return the length of the key sequence stored.
6249 Return -1 if the user rejected a command menu.
6251 Echo starting immediately unless `prompt' is 0.
6253 Where a key sequence ends depends on the currently active keymaps.
6254 These include any minor mode keymaps active in the current buffer,
6255 the current buffer's local map, and the global map.
6257 If a key sequence has no other bindings, we check Vfunction_key_map
6258 to see if some trailing subsequence might be the beginning of a
6259 function key's sequence. If so, we try to read the whole function
6260 key, and substitute its symbolic name into the key sequence.
6262 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
6263 `double-' events into similar click events, if that would make them
6264 bound. We try to turn `triple-' events first into `double-' events,
6267 If we get a mouse click in a mode line, vertical divider, or other
6268 non-text area, we treat the click as if it were prefixed by the
6269 symbol denoting that area - `mode-line', `vertical-line', or
6272 If the sequence starts with a mouse click, we read the key sequence
6273 with respect to the buffer clicked on, not the current buffer.
6275 If the user switches frames in the midst of a key sequence, we put
6276 off the switch-frame event until later; the next call to
6277 read_char will return it.
6279 If FIX_CURRENT_BUFFER is nonzero, we restore current_buffer
6280 from the selected window's buffer. */
6283 read_key_sequence (keybuf
, bufsize
, prompt
, dont_downcase_last
,
6284 can_return_switch_frame
, fix_current_buffer
)
6285 Lisp_Object
*keybuf
;
6288 int dont_downcase_last
;
6289 int can_return_switch_frame
;
6290 int fix_current_buffer
;
6292 int count
= specpdl_ptr
- specpdl
;
6294 /* How many keys there are in the current key sequence. */
6297 /* The length of the echo buffer when we started reading, and
6298 the length of this_command_keys when we started reading. */
6302 /* The number of keymaps we're scanning right now, and the number of
6303 keymaps we have allocated space for. */
6305 int nmaps_allocated
= 0;
6307 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
6308 the current keymaps. */
6311 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
6312 in the current keymaps, or nil where it is not a prefix. */
6313 Lisp_Object
*submaps
;
6315 /* The local map to start out with at start of key sequence. */
6316 Lisp_Object orig_local_map
;
6318 /* 1 if we have already considered switching to the local-map property
6319 of the place where a mouse click occurred. */
6320 int localized_local_map
= 0;
6322 /* The index in defs[] of the first keymap that has a binding for
6323 this key sequence. In other words, the lowest i such that
6324 defs[i] is non-nil. */
6327 /* If t < mock_input, then KEYBUF[t] should be read as the next
6330 We use this to recover after recognizing a function key. Once we
6331 realize that a suffix of the current key sequence is actually a
6332 function key's escape sequence, we replace the suffix with the
6333 function key's binding from Vfunction_key_map. Now keybuf
6334 contains a new and different key sequence, so the echo area,
6335 this_command_keys, and the submaps and defs arrays are wrong. In
6336 this situation, we set mock_input to t, set t to 0, and jump to
6337 restart_sequence; the loop will read keys from keybuf up until
6338 mock_input, thus rebuilding the state; and then it will resume
6339 reading characters from the keyboard. */
6342 /* If the sequence is unbound in submaps[], then
6343 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
6344 and fkey_map is its binding.
6346 These might be > t, indicating that all function key scanning
6347 should hold off until t reaches them. We do this when we've just
6348 recognized a function key, to avoid searching for the function
6349 key's again in Vfunction_key_map. */
6350 int fkey_start
= 0, fkey_end
= 0;
6351 Lisp_Object fkey_map
;
6353 /* Likewise, for key_translation_map. */
6354 int keytran_start
= 0, keytran_end
= 0;
6355 Lisp_Object keytran_map
;
6357 /* If we receive a ``switch-frame'' event in the middle of a key sequence,
6358 we put it off for later. While we're reading, we keep the event here. */
6359 Lisp_Object delayed_switch_frame
;
6361 /* See the comment below... */
6362 #if defined (GOBBLE_FIRST_EVENT)
6363 Lisp_Object first_event
;
6366 Lisp_Object original_uppercase
;
6367 int original_uppercase_position
= -1;
6369 /* Gets around Microsoft compiler limitations. */
6372 struct buffer
*starting_buffer
;
6374 /* Nonzero if we seem to have got the beginning of a binding
6375 in function_key_map. */
6376 int function_key_possible
= 0;
6377 int key_translation_possible
= 0;
6379 /* Save the status of key translation before each step,
6380 so that we can restore this after downcasing. */
6381 Lisp_Object prev_fkey_map
;
6382 int prev_fkey_start
;
6385 Lisp_Object prev_keytran_map
;
6386 int prev_keytran_start
;
6387 int prev_keytran_end
;
6391 last_nonmenu_event
= Qnil
;
6393 delayed_switch_frame
= Qnil
;
6394 fkey_map
= Vfunction_key_map
;
6395 keytran_map
= Vkey_translation_map
;
6397 /* If there is no function-key-map, turn off function key scanning. */
6398 if (NILP (Fkeymapp (Vfunction_key_map
)))
6399 fkey_start
= fkey_end
= bufsize
+ 1;
6401 /* If there is no key-translation-map, turn off scanning. */
6402 if (NILP (Fkeymapp (Vkey_translation_map
)))
6403 keytran_start
= keytran_end
= bufsize
+ 1;
6408 echo_prompt (XSTRING (prompt
)->data
);
6409 else if (cursor_in_echo_area
&& echo_keystrokes
)
6410 /* This doesn't put in a dash if the echo buffer is empty, so
6411 you don't always see a dash hanging out in the minibuffer. */
6415 /* Record the initial state of the echo area and this_command_keys;
6416 we will need to restore them if we replay a key sequence. */
6418 echo_start
= echo_length ();
6419 keys_start
= this_command_key_count
;
6420 this_single_command_key_start
= keys_start
;
6422 #if defined (GOBBLE_FIRST_EVENT)
6423 /* This doesn't quite work, because some of the things that read_char
6424 does cannot safely be bypassed. It seems too risky to try to make
6427 /* Read the first char of the sequence specially, before setting
6428 up any keymaps, in case a filter runs and switches buffers on us. */
6429 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
6431 #endif /* GOBBLE_FIRST_EVENT */
6433 orig_local_map
= get_local_map (PT
, current_buffer
);
6435 /* We jump here when the key sequence has been thoroughly changed, and
6436 we need to rescan it starting from the beginning. When we jump here,
6437 keybuf[0..mock_input] holds the sequence we should reread. */
6440 starting_buffer
= current_buffer
;
6441 function_key_possible
= 0;
6442 key_translation_possible
= 0;
6444 /* Build our list of keymaps.
6445 If we recognize a function key and replace its escape sequence in
6446 keybuf with its symbol, or if the sequence starts with a mouse
6447 click and we need to switch buffers, we jump back here to rebuild
6448 the initial keymaps from the current buffer. */
6452 if (!NILP (current_kboard
->Voverriding_terminal_local_map
)
6453 || !NILP (Voverriding_local_map
))
6455 if (3 > nmaps_allocated
)
6457 submaps
= (Lisp_Object
*) alloca (3 * sizeof (submaps
[0]));
6458 defs
= (Lisp_Object
*) alloca (3 * sizeof (defs
[0]));
6459 nmaps_allocated
= 3;
6462 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
6463 submaps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
6464 if (!NILP (Voverriding_local_map
))
6465 submaps
[nmaps
++] = Voverriding_local_map
;
6469 nmaps
= current_minor_maps (0, &maps
);
6470 if (nmaps
+ 2 > nmaps_allocated
)
6472 submaps
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (submaps
[0]));
6473 defs
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (defs
[0]));
6474 nmaps_allocated
= nmaps
+ 2;
6476 bcopy (maps
, submaps
, nmaps
* sizeof (submaps
[0]));
6477 #ifdef USE_TEXT_PROPERTIES
6478 submaps
[nmaps
++] = orig_local_map
;
6480 submaps
[nmaps
++] = current_buffer
->keymap
;
6483 submaps
[nmaps
++] = current_global_map
;
6486 /* Find an accurate initial value for first_binding. */
6487 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
6488 if (! NILP (submaps
[first_binding
]))
6491 /* Start from the beginning in keybuf. */
6494 /* These are no-ops the first time through, but if we restart, they
6495 revert the echo area and this_command_keys to their original state. */
6496 this_command_key_count
= keys_start
;
6497 if (INTERACTIVE
&& t
< mock_input
)
6498 echo_truncate (echo_start
);
6500 /* If the best binding for the current key sequence is a keymap, or
6501 we may be looking at a function key's escape sequence, keep on
6503 while ((first_binding
< nmaps
&& ! NILP (submaps
[first_binding
]))
6504 || (first_binding
>= nmaps
6506 /* mock input is never part of a function key's sequence. */
6507 && mock_input
<= fkey_start
)
6508 || (first_binding
>= nmaps
6509 && keytran_start
< t
&& key_translation_possible
)
6510 /* Don't return in the middle of a possible function key sequence,
6511 if the only bindings we found were via case conversion.
6512 Thus, if ESC O a has a function-key-map translation
6513 and ESC o has a binding, don't return after ESC O,
6514 so that we can translate ESC O plus the next character. */
6518 int used_mouse_menu
= 0;
6520 /* Where the last real key started. If we need to throw away a
6521 key that has expanded into more than one element of keybuf
6522 (say, a mouse click on the mode line which is being treated
6523 as [mode-line (mouse-...)], then we backtrack to this point
6525 int last_real_key_start
;
6527 /* These variables are analogous to echo_start and keys_start;
6528 while those allow us to restart the entire key sequence,
6529 echo_local_start and keys_local_start allow us to throw away
6531 int echo_local_start
, keys_local_start
, local_first_binding
;
6534 error ("Key sequence too long");
6537 echo_local_start
= echo_length ();
6538 keys_local_start
= this_command_key_count
;
6539 local_first_binding
= first_binding
;
6542 /* These are no-ops, unless we throw away a keystroke below and
6543 jumped back up to replay_key; in that case, these restore the
6544 variables to their original state, allowing us to replay the
6546 if (INTERACTIVE
&& t
< mock_input
)
6547 echo_truncate (echo_local_start
);
6548 this_command_key_count
= keys_local_start
;
6549 first_binding
= local_first_binding
;
6551 /* By default, assume each event is "real". */
6552 last_real_key_start
= t
;
6554 /* Does mock_input indicate that we are re-reading a key sequence? */
6558 add_command_key (key
);
6559 if (echo_keystrokes
)
6563 /* If not, we should actually read a character. */
6566 struct buffer
*buf
= current_buffer
;
6570 KBOARD
*interrupted_kboard
= current_kboard
;
6571 struct frame
*interrupted_frame
= selected_frame
;
6572 if (setjmp (wrong_kboard_jmpbuf
))
6574 if (!NILP (delayed_switch_frame
))
6576 interrupted_kboard
->kbd_queue
6577 = Fcons (delayed_switch_frame
,
6578 interrupted_kboard
->kbd_queue
);
6579 delayed_switch_frame
= Qnil
;
6582 interrupted_kboard
->kbd_queue
6583 = Fcons (keybuf
[--t
], interrupted_kboard
->kbd_queue
);
6585 /* If the side queue is non-empty, ensure it begins with a
6586 switch-frame, so we'll replay it in the right context. */
6587 if (CONSP (interrupted_kboard
->kbd_queue
)
6588 && (key
= XCONS (interrupted_kboard
->kbd_queue
)->car
,
6589 !(EVENT_HAS_PARAMETERS (key
)
6590 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)),
6594 XSETFRAME (frame
, interrupted_frame
);
6595 interrupted_kboard
->kbd_queue
6596 = Fcons (make_lispy_switch_frame (frame
),
6597 interrupted_kboard
->kbd_queue
);
6600 orig_local_map
= get_local_map (PT
, current_buffer
);
6601 goto replay_sequence
;
6604 key
= read_char (NILP (prompt
), nmaps
, submaps
, last_nonmenu_event
,
6608 /* read_char returns t when it shows a menu and the user rejects it.
6613 /* read_char returns -1 at the end of a macro.
6614 Emacs 18 handles this by returning immediately with a
6615 zero, so that's what we'll do. */
6616 if (INTEGERP (key
) && XINT (key
) == -1)
6619 /* The Microsoft C compiler can't handle the goto that
6625 /* If the current buffer has been changed from under us, the
6626 keymap may have changed, so replay the sequence. */
6630 /* Reset the current buffer from the selected window
6631 in case something changed the former and not the latter.
6632 This is to be more consistent with the behavior
6633 of the command_loop_1. */
6634 if (fix_current_buffer
)
6635 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
6636 Fset_buffer (XWINDOW (selected_window
)->buffer
);
6638 orig_local_map
= get_local_map (PT
, current_buffer
);
6639 goto replay_sequence
;
6642 /* If we have a quit that was typed in another frame, and
6643 quit_throw_to_read_char switched buffers,
6644 replay to get the right keymap. */
6645 if (XINT (key
) == quit_char
&& current_buffer
!= starting_buffer
)
6650 orig_local_map
= get_local_map (PT
, current_buffer
);
6651 goto replay_sequence
;
6657 /* Clicks in non-text areas get prefixed by the symbol
6658 in their CHAR-ADDRESS field. For example, a click on
6659 the mode line is prefixed by the symbol `mode-line'.
6661 Furthermore, key sequences beginning with mouse clicks
6662 are read using the keymaps of the buffer clicked on, not
6663 the current buffer. So we may have to switch the buffer
6666 When we turn one event into two events, we must make sure
6667 that neither of the two looks like the original--so that,
6668 if we replay the events, they won't be expanded again.
6669 If not for this, such reexpansion could happen either here
6670 or when user programs play with this-command-keys. */
6671 if (EVENT_HAS_PARAMETERS (key
))
6675 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
6676 if (EQ (kind
, Qmouse_click
))
6678 Lisp_Object window
, posn
;
6680 window
= POSN_WINDOW (EVENT_START (key
));
6681 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
6684 /* We're looking at the second event of a
6685 sequence which we expanded before. Set
6686 last_real_key_start appropriately. */
6688 last_real_key_start
= t
- 1;
6691 /* Key sequences beginning with mouse clicks are
6692 read using the keymaps in the buffer clicked on,
6693 not the current buffer. If we're at the
6694 beginning of a key sequence, switch buffers. */
6695 if (last_real_key_start
== 0
6697 && BUFFERP (XWINDOW (window
)->buffer
)
6698 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
6703 /* Arrange to go back to the original buffer once we're
6704 done reading the key sequence. Note that we can't
6705 use save_excursion_{save,restore} here, because they
6706 save point as well as the current buffer; we don't
6707 want to save point, because redisplay may change it,
6708 to accommodate a Fset_window_start or something. We
6709 don't want to do this at the top of the function,
6710 because we may get input from a subprocess which
6711 wants to change the selected window and stuff (say,
6713 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
6715 set_buffer_internal (XBUFFER (XWINDOW (window
)->buffer
));
6716 orig_local_map
= get_local_map (PT
, current_buffer
);
6717 goto replay_sequence
;
6719 /* For a mouse click, get the local text-property keymap
6720 of the place clicked on, rather than point. */
6721 if (last_real_key_start
== 0 && CONSP (XCONS (key
)->cdr
)
6722 && ! localized_local_map
)
6724 Lisp_Object map_here
, start
, pos
;
6726 localized_local_map
= 1;
6727 start
= EVENT_START (key
);
6728 if (CONSP (start
) && CONSP (XCONS (start
)->cdr
))
6730 pos
= POSN_BUFFER_POSN (start
);
6732 && XINT (pos
) >= BEG
&& XINT (pos
) <= Z
)
6734 map_here
= get_local_map (XINT (pos
), current_buffer
);
6735 if (!EQ (map_here
, orig_local_map
))
6737 orig_local_map
= map_here
;
6741 goto replay_sequence
;
6747 /* Expand mode-line and scroll-bar events into two events:
6748 use posn as a fake prefix key. */
6751 if (t
+ 1 >= bufsize
)
6752 error ("Key sequence too long");
6757 /* Zap the position in key, so we know that we've
6758 expanded it, and don't try to do so again. */
6759 POSN_BUFFER_POSN (EVENT_START (key
))
6760 = Fcons (posn
, Qnil
);
6764 else if (EQ (kind
, Qswitch_frame
))
6766 /* If we're at the beginning of a key sequence, and the caller
6767 says it's okay, go ahead and return this event. If we're
6768 in the midst of a key sequence, delay it until the end. */
6769 if (t
> 0 || !can_return_switch_frame
)
6771 delayed_switch_frame
= key
;
6775 else if (CONSP (XCONS (key
)->cdr
)
6776 && CONSP (EVENT_START (key
))
6777 && CONSP (XCONS (EVENT_START (key
))->cdr
))
6781 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
6782 /* Handle menu-bar events:
6783 insert the dummy prefix event `menu-bar'. */
6784 if (EQ (posn
, Qmenu_bar
))
6786 if (t
+ 1 >= bufsize
)
6787 error ("Key sequence too long");
6791 /* Zap the position in key, so we know that we've
6792 expanded it, and don't try to do so again. */
6793 POSN_BUFFER_POSN (EVENT_START (key
))
6794 = Fcons (posn
, Qnil
);
6797 goto replay_sequence
;
6799 else if (CONSP (posn
))
6801 /* We're looking at the second event of a
6802 sequence which we expanded before. Set
6803 last_real_key_start appropriately. */
6804 if (last_real_key_start
== t
&& t
> 0)
6805 last_real_key_start
= t
- 1;
6810 /* We have finally decided that KEY is something we might want
6812 first_binding
= (follow_key (key
,
6813 nmaps
- first_binding
,
6814 submaps
+ first_binding
,
6815 defs
+ first_binding
,
6816 submaps
+ first_binding
)
6819 /* If KEY wasn't bound, we'll try some fallbacks. */
6820 if (first_binding
>= nmaps
)
6824 head
= EVENT_HEAD (key
);
6825 if (help_char_p (head
) && t
> 0)
6827 read_key_sequence_cmd
= Vprefix_help_command
;
6829 last_nonmenu_event
= key
;
6830 /* The Microsoft C compiler can't handle the goto that
6838 Lisp_Object breakdown
;
6841 breakdown
= parse_modifiers (head
);
6842 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
6843 /* Attempt to reduce an unbound mouse event to a simpler
6844 event that is bound:
6845 Drags reduce to clicks.
6846 Double-clicks reduce to clicks.
6847 Triple-clicks reduce to double-clicks, then to clicks.
6848 Down-clicks are eliminated.
6849 Double-downs reduce to downs, then are eliminated.
6850 Triple-downs reduce to double-downs, then to downs,
6851 then are eliminated. */
6852 if (modifiers
& (down_modifier
| drag_modifier
6853 | double_modifier
| triple_modifier
))
6855 while (modifiers
& (down_modifier
| drag_modifier
6856 | double_modifier
| triple_modifier
))
6858 Lisp_Object new_head
, new_click
;
6859 if (modifiers
& triple_modifier
)
6860 modifiers
^= (double_modifier
| triple_modifier
);
6861 else if (modifiers
& double_modifier
)
6862 modifiers
&= ~double_modifier
;
6863 else if (modifiers
& drag_modifier
)
6864 modifiers
&= ~drag_modifier
;
6867 /* Dispose of this `down' event by simply jumping
6868 back to replay_key, to get another event.
6870 Note that if this event came from mock input,
6871 then just jumping back to replay_key will just
6872 hand it to us again. So we have to wipe out any
6875 We could delete keybuf[t] and shift everything
6876 after that to the left by one spot, but we'd also
6877 have to fix up any variable that points into
6878 keybuf, and shifting isn't really necessary
6881 Adding prefixes for non-textual mouse clicks
6882 creates two characters of mock input, and both
6883 must be thrown away. If we're only looking at
6884 the prefix now, we can just jump back to
6885 replay_key. On the other hand, if we've already
6886 processed the prefix, and now the actual click
6887 itself is giving us trouble, then we've lost the
6888 state of the keymaps we want to backtrack to, and
6889 we need to replay the whole sequence to rebuild
6892 Beyond that, only function key expansion could
6893 create more than two keys, but that should never
6894 generate mouse events, so it's okay to zero
6895 mock_input in that case too.
6897 Isn't this just the most wonderful code ever? */
6898 if (t
== last_real_key_start
)
6905 mock_input
= last_real_key_start
;
6906 goto replay_sequence
;
6911 = apply_modifiers (modifiers
, XCONS (breakdown
)->car
);
6913 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
6915 /* Look for a binding for this new key. follow_key
6916 promises that it didn't munge submaps the
6917 last time we called it, since key was unbound. */
6919 = (follow_key (new_click
,
6920 nmaps
- local_first_binding
,
6921 submaps
+ local_first_binding
,
6922 defs
+ local_first_binding
,
6923 submaps
+ local_first_binding
)
6924 + local_first_binding
);
6926 /* If that click is bound, go for it. */
6927 if (first_binding
< nmaps
)
6932 /* Otherwise, we'll leave key set to the drag event. */
6939 /* Normally, last_nonmenu_event gets the previous key we read.
6940 But when a mouse popup menu is being used,
6941 we don't update last_nonmenu_event; it continues to hold the mouse
6942 event that preceded the first level of menu. */
6943 if (!used_mouse_menu
)
6944 last_nonmenu_event
= key
;
6946 /* Record what part of this_command_keys is the current key sequence. */
6947 this_single_command_key_start
= this_command_key_count
- t
;
6949 prev_fkey_map
= fkey_map
;
6950 prev_fkey_start
= fkey_start
;
6951 prev_fkey_end
= fkey_end
;
6953 prev_keytran_map
= keytran_map
;
6954 prev_keytran_start
= keytran_start
;
6955 prev_keytran_end
= keytran_end
;
6957 /* If the sequence is unbound, see if we can hang a function key
6958 off the end of it. We only want to scan real keyboard input
6959 for function key sequences, so if mock_input says that we're
6960 re-reading old events, don't examine it. */
6961 if (first_binding
>= nmaps
6964 Lisp_Object fkey_next
;
6966 /* Continue scan from fkey_end until we find a bound suffix.
6967 If we fail, increment fkey_start
6968 and start fkey_end from there. */
6969 while (fkey_end
< t
)
6973 key
= keybuf
[fkey_end
++];
6974 /* Look up meta-characters by prefixing them
6975 with meta_prefix_char. I hate this. */
6976 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
6981 (access_keymap (fkey_map
, meta_prefix_char
, 1, 0), 0),
6983 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
6986 fkey_next
= fkey_map
;
6989 = get_keyelt (access_keymap (fkey_next
, key
, 1, 0), 0);
6991 #if 0 /* I didn't turn this on, because it might cause trouble
6992 for the mapping of return into C-m and tab into C-i. */
6993 /* Optionally don't map function keys into other things.
6994 This enables the user to redefine kp- keys easily. */
6995 if (SYMBOLP (key
) && !NILP (Vinhibit_function_key_mapping
))
6999 /* If the function key map gives a function, not an
7000 array, then call the function with no args and use
7001 its value instead. */
7002 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
7005 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7009 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
7010 fkey_next
= call1 (fkey_next
, prompt
);
7012 /* If the function returned something invalid,
7013 barf--don't ignore it.
7014 (To ignore it safely, we would need to gcpro a bunch of
7015 other variables.) */
7016 if (! (VECTORP (fkey_next
) || STRINGP (fkey_next
)))
7017 error ("Function in key-translation-map returns invalid key sequence");
7020 function_key_possible
= ! NILP (fkey_next
);
7022 /* If keybuf[fkey_start..fkey_end] is bound in the
7023 function key map and it's a suffix of the current
7024 sequence (i.e. fkey_end == t), replace it with
7025 the binding and restart with fkey_start at the end. */
7026 if ((VECTORP (fkey_next
) || STRINGP (fkey_next
))
7029 int len
= XFASTINT (Flength (fkey_next
));
7031 t
= fkey_start
+ len
;
7033 error ("Key sequence too long");
7035 if (VECTORP (fkey_next
))
7036 bcopy (XVECTOR (fkey_next
)->contents
,
7037 keybuf
+ fkey_start
,
7038 (t
- fkey_start
) * sizeof (keybuf
[0]));
7039 else if (STRINGP (fkey_next
))
7043 for (i
= 0; i
< len
; i
++)
7044 XSETFASTINT (keybuf
[fkey_start
+ i
],
7045 XSTRING (fkey_next
)->data
[i
]);
7049 fkey_start
= fkey_end
= t
;
7050 fkey_map
= Vfunction_key_map
;
7052 /* Do pass the results through key-translation-map. */
7053 keytran_start
= keytran_end
= 0;
7054 keytran_map
= Vkey_translation_map
;
7056 goto replay_sequence
;
7059 fkey_map
= get_keymap_1 (fkey_next
, 0, 1);
7061 /* If we no longer have a bound suffix, try a new positions for
7063 if (NILP (fkey_map
))
7065 fkey_end
= ++fkey_start
;
7066 fkey_map
= Vfunction_key_map
;
7067 function_key_possible
= 0;
7072 /* Look for this sequence in key-translation-map. */
7074 Lisp_Object keytran_next
;
7076 /* Scan from keytran_end until we find a bound suffix. */
7077 while (keytran_end
< t
)
7081 key
= keybuf
[keytran_end
++];
7082 /* Look up meta-characters by prefixing them
7083 with meta_prefix_char. I hate this. */
7084 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
7089 (access_keymap (keytran_map
, meta_prefix_char
, 1, 0), 0),
7091 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
7094 keytran_next
= keytran_map
;
7097 = get_keyelt (access_keymap (keytran_next
, key
, 1, 0), 0);
7099 /* If the key translation map gives a function, not an
7100 array, then call the function with no args and use
7101 its value instead. */
7102 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
7103 && keytran_end
== t
)
7105 struct gcpro gcpro1
, gcpro2
, gcpro3
;
7109 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
7110 keytran_next
= call1 (keytran_next
, prompt
);
7112 /* If the function returned something invalid,
7113 barf--don't ignore it.
7114 (To ignore it safely, we would need to gcpro a bunch of
7115 other variables.) */
7116 if (! (VECTORP (keytran_next
) || STRINGP (keytran_next
)))
7117 error ("Function in key-translation-map returns invalid key sequence");
7120 key_translation_possible
= ! NILP (keytran_next
);
7122 /* If keybuf[keytran_start..keytran_end] is bound in the
7123 key translation map and it's a suffix of the current
7124 sequence (i.e. keytran_end == t), replace it with
7125 the binding and restart with keytran_start at the end. */
7126 if ((VECTORP (keytran_next
) || STRINGP (keytran_next
))
7127 && keytran_end
== t
)
7129 int len
= XFASTINT (Flength (keytran_next
));
7131 t
= keytran_start
+ len
;
7133 error ("Key sequence too long");
7135 if (VECTORP (keytran_next
))
7136 bcopy (XVECTOR (keytran_next
)->contents
,
7137 keybuf
+ keytran_start
,
7138 (t
- keytran_start
) * sizeof (keybuf
[0]));
7139 else if (STRINGP (keytran_next
))
7143 for (i
= 0; i
< len
; i
++)
7144 XSETFASTINT (keybuf
[keytran_start
+ i
],
7145 XSTRING (keytran_next
)->data
[i
]);
7149 keytran_start
= keytran_end
= t
;
7150 keytran_map
= Vkey_translation_map
;
7152 /* Don't pass the results of key-translation-map
7153 through function-key-map. */
7154 fkey_start
= fkey_end
= t
;
7155 fkey_map
= Vkey_translation_map
;
7157 goto replay_sequence
;
7160 keytran_map
= get_keymap_1 (keytran_next
, 0, 1);
7162 /* If we no longer have a bound suffix, try a new positions for
7164 if (NILP (keytran_map
))
7166 keytran_end
= ++keytran_start
;
7167 keytran_map
= Vkey_translation_map
;
7168 key_translation_possible
= 0;
7173 /* If KEY is not defined in any of the keymaps,
7174 and cannot be part of a function key or translation,
7175 and is an upper case letter
7176 use the corresponding lower-case letter instead. */
7177 if (first_binding
== nmaps
&& ! function_key_possible
7178 && ! key_translation_possible
7180 && ((((XINT (key
) & 0x3ffff)
7181 < XCHAR_TABLE (current_buffer
->downcase_table
)->size
)
7182 && UPPERCASEP (XINT (key
) & 0x3ffff))
7183 || (XINT (key
) & shift_modifier
)))
7185 Lisp_Object new_key
;
7187 original_uppercase
= key
;
7188 original_uppercase_position
= t
- 1;
7190 if (XINT (key
) & shift_modifier
)
7191 XSETINT (new_key
, XINT (key
) & ~shift_modifier
);
7193 XSETINT (new_key
, (DOWNCASE (XINT (key
) & 0x3ffff)
7194 | (XINT (key
) & ~0x3ffff)));
7196 /* We have to do this unconditionally, regardless of whether
7197 the lower-case char is defined in the keymaps, because they
7198 might get translated through function-key-map. */
7199 keybuf
[t
- 1] = new_key
;
7202 fkey_map
= prev_fkey_map
;
7203 fkey_start
= prev_fkey_start
;
7204 fkey_end
= prev_fkey_end
;
7206 keytran_map
= prev_keytran_map
;
7207 keytran_start
= prev_keytran_start
;
7208 keytran_end
= prev_keytran_end
;
7210 goto replay_sequence
;
7212 /* If KEY is not defined in any of the keymaps,
7213 and cannot be part of a function key or translation,
7214 and is a shifted function key,
7215 use the corresponding unshifted function key instead. */
7216 if (first_binding
== nmaps
&& ! function_key_possible
7217 && ! key_translation_possible
7220 Lisp_Object breakdown
;
7223 breakdown
= parse_modifiers (key
);
7224 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
7225 if (modifiers
& shift_modifier
)
7227 Lisp_Object new_key
;
7229 original_uppercase
= key
;
7230 original_uppercase_position
= t
- 1;
7232 modifiers
&= ~shift_modifier
;
7233 new_key
= apply_modifiers (modifiers
,
7234 XCONS (breakdown
)->car
);
7236 keybuf
[t
- 1] = new_key
;
7239 fkey_map
= prev_fkey_map
;
7240 fkey_start
= prev_fkey_start
;
7241 fkey_end
= prev_fkey_end
;
7243 keytran_map
= prev_keytran_map
;
7244 keytran_start
= prev_keytran_start
;
7245 keytran_end
= prev_keytran_end
;
7247 goto replay_sequence
;
7253 read_key_sequence_cmd
= (first_binding
< nmaps
7254 ? defs
[first_binding
]
7257 unread_switch_frame
= delayed_switch_frame
;
7258 unbind_to (count
, Qnil
);
7260 /* Don't downcase the last character if the caller says don't.
7261 Don't downcase it if the result is undefined, either. */
7262 if ((dont_downcase_last
|| first_binding
>= nmaps
)
7263 && t
- 1 == original_uppercase_position
)
7264 keybuf
[t
- 1] = original_uppercase
;
7266 /* Occasionally we fabricate events, perhaps by expanding something
7267 according to function-key-map, or by adding a prefix symbol to a
7268 mouse click in the scroll bar or modeline. In this cases, return
7269 the entire generated key sequence, even if we hit an unbound
7270 prefix or a definition before the end. This means that you will
7271 be able to push back the event properly, and also means that
7272 read-key-sequence will always return a logical unit.
7275 for (; t
< mock_input
; t
++)
7277 if (echo_keystrokes
)
7278 echo_char (keybuf
[t
]);
7279 add_command_key (keybuf
[t
]);
7285 #if 0 /* This doc string is too long for some compilers.
7286 This commented-out definition serves for DOC. */
7287 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
7288 "Read a sequence of keystrokes and return as a string or vector.\n\
7289 The sequence is sufficient to specify a non-prefix command in the\n\
7290 current local and global maps.\n\
7292 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
7293 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
7294 as a continuation of the previous key.\n\
7296 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not\n\
7297 convert the last event to lower case. (Normally any upper case event\n\
7298 is converted to lower case if the original event is undefined and the lower\n\
7299 case equivalent is defined.) A non-nil value is appropriate for reading\n\
7300 a key sequence to be defined.\n\
7302 A C-g typed while in this function is treated like any other character,\n\
7303 and `quit-flag' is not set.\n\
7305 If the key sequence starts with a mouse click, then the sequence is read\n\
7306 using the keymaps of the buffer of the window clicked in, not the buffer\n\
7307 of the selected window as normal.\n\
7309 `read-key-sequence' drops unbound button-down events, since you normally\n\
7310 only care about the click or drag events which follow them. If a drag\n\
7311 or multi-click event is unbound, but the corresponding click event would\n\
7312 be bound, `read-key-sequence' turns the event into a click event at the\n\
7313 drag's starting position. This means that you don't have to distinguish\n\
7314 between click and drag, double, or triple events unless you want to.\n\
7316 `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\
7317 lines separating windows, and scroll bars with imaginary keys\n\
7318 `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\
7320 Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this\n\
7321 function will process a switch-frame event if the user switches frames\n\
7322 before typing anything. If the user switches frames in the middle of a\n\
7323 key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME\n\
7324 is nil, then the event will be put off until after the current key sequence.\n\
7326 `read-key-sequence' checks `function-key-map' for function key\n\
7327 sequences, where they wouldn't conflict with ordinary bindings. See\n\
7328 `function-key-map' for more details.")
7329 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
)
7332 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
7334 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
)
7335 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
7336 Lisp_Object can_return_switch_frame
;
7338 Lisp_Object keybuf
[30];
7340 struct gcpro gcpro1
, gcpro2
;
7343 CHECK_STRING (prompt
, 0);
7346 bzero (keybuf
, sizeof keybuf
);
7348 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
7350 if (NILP (continue_echo
))
7352 this_command_key_count
= 0;
7353 this_single_command_key_start
= 0;
7356 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
7357 prompt
, ! NILP (dont_downcase_last
),
7358 ! NILP (can_return_switch_frame
), 0);
7366 return make_event_array (i
, keybuf
);
7369 DEFUN ("read-key-sequence-vector", Fread_key_sequence_vector
,
7370 Sread_key_sequence_vector
, 1, 4, 0,
7371 "Like `read-key-sequence' but always return a vector.")
7372 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
)
7373 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
7374 Lisp_Object can_return_switch_frame
;
7376 Lisp_Object keybuf
[30];
7378 struct gcpro gcpro1
, gcpro2
;
7381 CHECK_STRING (prompt
, 0);
7384 bzero (keybuf
, sizeof keybuf
);
7386 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
7388 if (NILP (continue_echo
))
7390 this_command_key_count
= 0;
7391 this_single_command_key_start
= 0;
7394 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
7395 prompt
, ! NILP (dont_downcase_last
),
7396 ! NILP (can_return_switch_frame
), 0);
7404 return Fvector (i
, keybuf
);
7407 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 4, 0,
7408 "Execute CMD as an editor command.\n\
7409 CMD must be a symbol that satisfies the `commandp' predicate.\n\
7410 Optional second arg RECORD-FLAG non-nil\n\
7411 means unconditionally put this command in `command-history'.\n\
7412 Otherwise, that is done only if an arg is read using the minibuffer.\n\
7413 The argument KEYS specifies the value to use instead of (this-command-keys)\n\
7414 when reading the arguments; if it is nil, (this-command-keys) is used.\n\
7415 The argument SPECIAL, if non-nil, means that this command is executing\n\
7416 a special event, so ignore the prefix argument and don't clear it.")
7417 (cmd
, record_flag
, keys
, special
)
7418 Lisp_Object cmd
, record_flag
, keys
, special
;
7420 register Lisp_Object final
;
7421 register Lisp_Object tem
;
7422 Lisp_Object prefixarg
;
7423 struct backtrace backtrace
;
7424 extern int debug_on_next_call
;
7426 debug_on_next_call
= 0;
7430 prefixarg
= current_kboard
->Vprefix_arg
;
7431 Vcurrent_prefix_arg
= prefixarg
;
7432 current_kboard
->Vprefix_arg
= Qnil
;
7439 tem
= Fget (cmd
, Qdisabled
);
7440 if (!NILP (tem
) && !NILP (Vrun_hooks
))
7442 tem
= Fsymbol_value (Qdisabled_command_hook
);
7444 return call1 (Vrun_hooks
, Qdisabled_command_hook
);
7450 final
= Findirect_function (cmd
);
7452 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
7454 struct gcpro gcpro1
, gcpro2
;
7456 GCPRO2 (cmd
, prefixarg
);
7457 do_autoload (final
, cmd
);
7464 if (STRINGP (final
) || VECTORP (final
))
7466 /* If requested, place the macro in the command history. For
7467 other sorts of commands, call-interactively takes care of
7469 if (!NILP (record_flag
))
7471 = Fcons (Fcons (Qexecute_kbd_macro
,
7472 Fcons (final
, Fcons (prefixarg
, Qnil
))),
7475 return Fexecute_kbd_macro (final
, prefixarg
);
7477 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
7479 backtrace
.next
= backtrace_list
;
7480 backtrace_list
= &backtrace
;
7481 backtrace
.function
= &Qcall_interactively
;
7482 backtrace
.args
= &cmd
;
7483 backtrace
.nargs
= 1;
7484 backtrace
.evalargs
= 0;
7486 tem
= Fcall_interactively (cmd
, record_flag
, keys
);
7488 backtrace_list
= backtrace
.next
;
7494 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
7496 "Read function name, then read its arguments and call it.")
7498 Lisp_Object prefixarg
;
7500 Lisp_Object function
;
7502 Lisp_Object saved_keys
;
7503 Lisp_Object bindings
, value
;
7504 struct gcpro gcpro1
, gcpro2
;
7506 saved_keys
= Fvector (this_command_key_count
,
7507 XVECTOR (this_command_keys
)->contents
);
7509 GCPRO2 (saved_keys
, prefixarg
);
7511 if (EQ (prefixarg
, Qminus
))
7513 else if (CONSP (prefixarg
) && XINT (XCONS (prefixarg
)->car
) == 4)
7514 strcpy (buf
, "C-u ");
7515 else if (CONSP (prefixarg
) && INTEGERP (XCONS (prefixarg
)->car
))
7517 if (sizeof (int) == sizeof (EMACS_INT
))
7518 sprintf (buf
, "%d ", XINT (XCONS (prefixarg
)->car
));
7519 else if (sizeof (long) == sizeof (EMACS_INT
))
7520 sprintf (buf
, "%ld ", XINT (XCONS (prefixarg
)->car
));
7524 else if (INTEGERP (prefixarg
))
7526 if (sizeof (int) == sizeof (EMACS_INT
))
7527 sprintf (buf
, "%d ", XINT (prefixarg
));
7528 else if (sizeof (long) == sizeof (EMACS_INT
))
7529 sprintf (buf
, "%ld ", XINT (prefixarg
));
7534 /* This isn't strictly correct if execute-extended-command
7535 is bound to anything else. Perhaps it should use
7536 this_command_keys? */
7537 strcat (buf
, "M-x ");
7539 /* Prompt with buf, and then read a string, completing from and
7540 restricting to the set of all defined commands. Don't provide
7541 any initial input. Save the command read on the extended-command
7543 function
= Fcompleting_read (build_string (buf
),
7544 Vobarray
, Qcommandp
,
7545 Qt
, Qnil
, Qextended_command_history
, Qnil
,
7548 if (STRINGP (function
) && XSTRING (function
)->size
== 0)
7549 error ("No command name given");
7551 /* Set this_command_keys to the concatenation of saved_keys and
7552 function, followed by a RET. */
7554 struct Lisp_String
*str
;
7558 this_command_key_count
= 0;
7559 this_single_command_key_start
= 0;
7561 keys
= XVECTOR (saved_keys
)->contents
;
7562 for (i
= 0; i
< XVECTOR (saved_keys
)->size
; i
++)
7563 add_command_key (keys
[i
]);
7565 str
= XSTRING (function
);
7566 for (i
= 0; i
< str
->size
; i
++)
7567 add_command_key (Faref (function
, make_number (i
)));
7569 add_command_key (make_number ('\015'));
7574 function
= Fintern (function
, Qnil
);
7575 current_kboard
->Vprefix_arg
= prefixarg
;
7576 this_command
= function
;
7578 /* If enabled, show which key runs this command. */
7579 if (!NILP (Vsuggest_key_bindings
)
7580 && NILP (Vexecuting_macro
)
7581 && SYMBOLP (function
))
7582 bindings
= Fwhere_is_internal (function
, Voverriding_local_map
,
7588 GCPRO2 (bindings
, value
);
7589 value
= Fcommand_execute (function
, Qt
, Qnil
, Qnil
);
7591 /* If the command has a key binding, print it now. */
7592 if (!NILP (bindings
)
7593 && ! (VECTORP (bindings
) && EQ (Faref (bindings
, make_number (0)),
7596 /* But first wait, and skip the message if there is input. */
7597 if (!NILP (Fsit_for ((NUMBERP (Vsuggest_key_bindings
)
7598 ? Vsuggest_key_bindings
: make_number (2)),
7600 && ! CONSP (Vunread_command_events
))
7602 Lisp_Object binding
;
7604 char *oldmessage
= echo_area_glyphs
;
7605 int oldmessage_len
= echo_area_glyphs_length
;
7606 int oldmultibyte
= message_enable_multibyte
;
7608 binding
= Fkey_description (bindings
);
7611 = (char *) alloca (XSYMBOL (function
)->name
->size
7612 + STRING_BYTES (XSTRING (binding
))
7614 sprintf (newmessage
, "You can run the command `%s' with %s",
7615 XSYMBOL (function
)->name
->data
,
7616 XSTRING (binding
)->data
);
7617 message2_nolog (newmessage
,
7618 strlen (newmessage
),
7619 STRING_MULTIBYTE (binding
));
7620 if (!NILP (Fsit_for ((NUMBERP (Vsuggest_key_bindings
)
7621 ? Vsuggest_key_bindings
: make_number (2)),
7623 message2_nolog (oldmessage
, oldmessage_len
, oldmultibyte
);
7627 RETURN_UNGCPRO (value
);
7630 /* Find the set of keymaps now active.
7631 Store into *MAPS_P a vector holding the various maps
7632 and return the number of them. The vector was malloc'd
7633 and the caller should free it. */
7636 current_active_maps (maps_p
)
7637 Lisp_Object
**maps_p
;
7639 Lisp_Object
*tmaps
, *maps
;
7642 /* Should overriding-terminal-local-map and overriding-local-map apply? */
7643 if (!NILP (Voverriding_local_map_menu_flag
))
7645 /* Yes, use them (if non-nil) as well as the global map. */
7646 maps
= (Lisp_Object
*) xmalloc (3 * sizeof (maps
[0]));
7648 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
7649 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
7650 if (!NILP (Voverriding_local_map
))
7651 maps
[nmaps
++] = Voverriding_local_map
;
7655 /* No, so use major and minor mode keymaps. */
7656 nmaps
= current_minor_maps (NULL
, &tmaps
);
7657 maps
= (Lisp_Object
*) xmalloc ((nmaps
+ 2) * sizeof (maps
[0]));
7658 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
7659 #ifdef USE_TEXT_PROPERTIES
7660 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
7662 maps
[nmaps
++] = current_buffer
->keymap
;
7665 maps
[nmaps
++] = current_global_map
;
7671 /* Return nonzero if input events are pending. */
7673 detect_input_pending ()
7676 get_input_pending (&input_pending
, 0);
7678 return input_pending
;
7681 /* Return nonzero if input events are pending, and run any pending timers. */
7683 detect_input_pending_run_timers (do_display
)
7686 int old_timers_run
= timers_run
;
7689 get_input_pending (&input_pending
, 1);
7691 if (old_timers_run
!= timers_run
&& do_display
)
7692 redisplay_preserve_echo_area ();
7694 return input_pending
;
7697 /* This is called in some cases before a possible quit.
7698 It cases the next call to detect_input_pending to recompute input_pending.
7699 So calling this function unnecessarily can't do any harm. */
7702 clear_input_pending ()
7707 /* Return nonzero if there are pending requeued events.
7708 This isn't used yet. The hope is to make wait_reading_process_input
7709 call it, and return return if it runs Lisp code that unreads something.
7710 The problem is, kbd_buffer_get_event needs to be fixed to know what
7711 to do in that case. It isn't trivial. */
7713 requeued_events_pending_p ()
7715 return (!NILP (Vunread_command_events
) || unread_command_char
!= -1);
7719 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
7720 "T if command input is currently available with no waiting.\n\
7721 Actually, the value is nil only if we can be sure that no input is available.")
7724 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1)
7727 get_input_pending (&input_pending
, 1);
7728 return input_pending
> 0 ? Qt
: Qnil
;
7731 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
7732 "Return vector of last 100 events, not counting those from keyboard macros.")
7735 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
7738 if (total_keys
< NUM_RECENT_KEYS
)
7739 return Fvector (total_keys
, keys
);
7742 val
= Fvector (NUM_RECENT_KEYS
, keys
);
7743 bcopy (keys
+ recent_keys_index
,
7744 XVECTOR (val
)->contents
,
7745 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
7747 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
7748 recent_keys_index
* sizeof (Lisp_Object
));
7753 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
7754 "Return the key sequence that invoked this command.\n\
7755 The value is a string or a vector.")
7758 return make_event_array (this_command_key_count
,
7759 XVECTOR (this_command_keys
)->contents
);
7762 DEFUN ("this-command-keys-vector", Fthis_command_keys_vector
, Sthis_command_keys_vector
, 0, 0, 0,
7763 "Return the key sequence that invoked this command, as a vector.")
7766 return Fvector (this_command_key_count
,
7767 XVECTOR (this_command_keys
)->contents
);
7770 DEFUN ("this-single-command-keys", Fthis_single_command_keys
,
7771 Sthis_single_command_keys
, 0, 0, 0,
7772 "Return the key sequence that invoked this command.\n\
7773 Unlike `this-command-keys', this function's value\n\
7774 does not include prefix arguments.\n\
7775 The value is always a vector.")
7778 return Fvector (this_command_key_count
7779 - this_single_command_key_start
,
7780 (XVECTOR (this_command_keys
)->contents
7781 + this_single_command_key_start
));
7784 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths
,
7785 Sreset_this_command_lengths
, 0, 0, 0,
7786 "Used for complicated reasons in `universal-argument-other-key'.\n\
7788 `universal-argument-other-key' rereads the event just typed.\n\
7789 It then gets translated through `function-key-map'.\n\
7790 The translated event gets included in the echo area and in\n\
7791 the value of `this-command-keys' in addition to the raw original event.\n\
7792 That is not right.\n\
7794 Calling this function directs the translated event to replace\n\
7795 the original event, so that only one version of the event actually\n\
7796 appears in the echo area and in the value of `this-command-keys.'.")
7799 before_command_restore_flag
= 1;
7800 before_command_key_count_1
= before_command_key_count
;
7801 before_command_echo_length_1
= before_command_echo_length
;
7804 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
7805 "Return the current depth in recursive edits.")
7809 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
7813 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
7814 "FOpen dribble file: ",
7815 "Start writing all keyboard characters to a dribble file called FILE.\n\
7816 If FILE is nil, close any open dribble file.")
7827 file
= Fexpand_file_name (file
, Qnil
);
7828 dribble
= fopen (XSTRING (file
)->data
, "w");
7830 report_file_error ("Opening dribble", Fcons (file
, Qnil
));
7835 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
7836 "Discard the contents of the terminal input buffer.\n\
7837 Also cancel any kbd macro being defined.")
7840 current_kboard
->defining_kbd_macro
= Qnil
;
7841 update_mode_lines
++;
7843 Vunread_command_events
= Qnil
;
7844 unread_command_char
= -1;
7846 discard_tty_input ();
7848 /* Without the cast, GCC complains that this assignment loses the
7849 volatile qualifier of kbd_store_ptr. Is there anything wrong
7851 kbd_fetch_ptr
= (struct input_event
*) kbd_store_ptr
;
7852 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
7858 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
7859 "Stop Emacs and return to superior process. You can resume later.\n\
7860 If `cannot-suspend' is non-nil, or if the system doesn't support job\n\
7861 control, run a subshell instead.\n\n\
7862 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
7863 to be read as terminal input by Emacs's parent, after suspension.\n\
7865 Before suspending, run the normal hook `suspend-hook'.\n\
7866 After resumption run the normal hook `suspend-resume-hook'.\n\
7868 Some operating systems cannot stop the Emacs process and resume it later.\n\
7869 On such systems, Emacs starts a subshell instead of suspending.")
7871 Lisp_Object stuffstring
;
7874 int count
= specpdl_ptr
- specpdl
;
7875 int old_height
, old_width
;
7877 struct gcpro gcpro1
, gcpro2
;
7879 if (!NILP (stuffstring
))
7880 CHECK_STRING (stuffstring
, 0);
7882 /* Run the functions in suspend-hook. */
7883 if (!NILP (Vrun_hooks
))
7884 call1 (Vrun_hooks
, intern ("suspend-hook"));
7886 GCPRO1 (stuffstring
);
7887 get_frame_size (&old_width
, &old_height
);
7889 /* sys_suspend can get an error if it tries to fork a subshell
7890 and the system resources aren't available for that. */
7891 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object
))) init_sys_modes
,
7893 stuff_buffered_input (stuffstring
);
7898 unbind_to (count
, Qnil
);
7900 /* Check if terminal/window size has changed.
7901 Note that this is not useful when we are running directly
7902 with a window system; but suspend should be disabled in that case. */
7903 get_frame_size (&width
, &height
);
7904 if (width
!= old_width
|| height
!= old_height
)
7905 change_frame_size (selected_frame
, height
, width
, 0, 0);
7907 /* Run suspend-resume-hook. */
7908 if (!NILP (Vrun_hooks
))
7909 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
7915 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
7916 Then in any case stuff anything Emacs has read ahead and not used. */
7919 stuff_buffered_input (stuffstring
)
7920 Lisp_Object stuffstring
;
7922 /* stuff_char works only in BSD, versions 4.2 and up. */
7925 register unsigned char *p
;
7927 if (STRINGP (stuffstring
))
7931 p
= XSTRING (stuffstring
)->data
;
7932 count
= STRING_BYTES (XSTRING (stuffstring
));
7937 /* Anything we have read ahead, put back for the shell to read. */
7938 /* ?? What should this do when we have multiple keyboards??
7939 Should we ignore anything that was typed in at the "wrong" kboard? */
7940 for (; kbd_fetch_ptr
!= kbd_store_ptr
; kbd_fetch_ptr
++)
7942 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
7943 kbd_fetch_ptr
= kbd_buffer
;
7944 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
7945 stuff_char (kbd_fetch_ptr
->code
);
7946 kbd_fetch_ptr
->kind
= no_event
;
7947 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_fetch_ptr
7953 #endif /* BSD_SYSTEM and not BSD4_1 */
7956 set_waiting_for_input (time_to_clear
)
7957 EMACS_TIME
*time_to_clear
;
7959 input_available_clear_time
= time_to_clear
;
7961 /* Tell interrupt_signal to throw back to read_char, */
7962 waiting_for_input
= 1;
7964 /* If interrupt_signal was called before and buffered a C-g,
7965 make it run again now, to avoid timing error. */
7966 if (!NILP (Vquit_flag
))
7967 quit_throw_to_read_char ();
7971 clear_waiting_for_input ()
7973 /* Tell interrupt_signal not to throw back to read_char, */
7974 waiting_for_input
= 0;
7975 input_available_clear_time
= 0;
7978 /* This routine is called at interrupt level in response to C-G.
7979 If interrupt_input, this is the handler for SIGINT.
7980 Otherwise, it is called from kbd_buffer_store_event,
7981 in handling SIGIO or SIGTINT.
7983 If `waiting_for_input' is non zero, then unless `echoing' is nonzero,
7984 immediately throw back to read_char.
7986 Otherwise it sets the Lisp variable quit-flag not-nil.
7987 This causes eval to throw, when it gets a chance.
7988 If quit-flag is already non-nil, it stops the job right away. */
7991 interrupt_signal (signalnum
) /* If we don't have an argument, */
7992 int signalnum
; /* some compilers complain in signal calls. */
7995 /* Must preserve main program's value of errno. */
7996 int old_errno
= errno
;
7998 #if defined (USG) && !defined (POSIX_SIGNALS)
7999 if (!read_socket_hook
&& NILP (Vwindow_system
))
8001 /* USG systems forget handlers when they are used;
8002 must reestablish each time */
8003 signal (SIGINT
, interrupt_signal
);
8004 signal (SIGQUIT
, interrupt_signal
);
8010 if (!NILP (Vquit_flag
)
8011 && (FRAME_TERMCAP_P (selected_frame
) || FRAME_MSDOS_P (selected_frame
)))
8013 /* If SIGINT isn't blocked, don't let us be interrupted by
8014 another SIGINT, it might be harmful due to non-reentrancy
8015 in I/O functions. */
8016 sigblock (sigmask (SIGINT
));
8021 #ifdef SIGTSTP /* Support possible in later USG versions */
8023 * On systems which can suspend the current process and return to the original
8024 * shell, this command causes the user to end up back at the shell.
8025 * The "Auto-save" and "Abort" questions are not asked until
8026 * the user elects to return to emacs, at which point he can save the current
8027 * job and either dump core or continue.
8032 if (sys_suspend () == -1)
8034 printf ("Not running as a subprocess;\n");
8035 printf ("you can continue or abort.\n");
8038 /* Perhaps should really fork an inferior shell?
8039 But that would not provide any way to get back
8040 to the original shell, ever. */
8041 printf ("No support for stopping a process on this operating system;\n");
8042 printf ("you can continue or abort.\n");
8043 #endif /* not VMS */
8044 #endif /* not SIGTSTP */
8046 /* We must remain inside the screen area when the internal terminal
8047 is used. Note that [Enter] is not echoed by dos. */
8050 /* It doesn't work to autosave while GC is in progress;
8051 the code used for auto-saving doesn't cope with the mark bit. */
8052 if (!gc_in_progress
)
8054 printf ("Auto-save? (y or n) ");
8056 if (((c
= getchar ()) & ~040) == 'Y')
8058 Fdo_auto_save (Qt
, Qnil
);
8060 printf ("\r\nAuto-save done");
8061 #else /* not MSDOS */
8062 printf ("Auto-save done\n");
8063 #endif /* not MSDOS */
8065 while (c
!= '\n') c
= getchar ();
8069 /* During GC, it must be safe to reenable quitting again. */
8070 Vinhibit_quit
= Qnil
;
8073 #endif /* not MSDOS */
8074 printf ("Garbage collection in progress; cannot auto-save now\r\n");
8075 printf ("but will instead do a real quit after garbage collection ends\r\n");
8080 printf ("\r\nAbort? (y or n) ");
8081 #else /* not MSDOS */
8083 printf ("Abort (and enter debugger)? (y or n) ");
8085 printf ("Abort (and dump core)? (y or n) ");
8086 #endif /* not VMS */
8087 #endif /* not MSDOS */
8089 if (((c
= getchar ()) & ~040) == 'Y')
8091 while (c
!= '\n') c
= getchar ();
8093 printf ("\r\nContinuing...\r\n");
8094 #else /* not MSDOS */
8095 printf ("Continuing...\n");
8096 #endif /* not MSDOS */
8103 /* If executing a function that wants to be interrupted out of
8104 and the user has not deferred quitting by binding `inhibit-quit'
8105 then quit right away. */
8106 if (immediate_quit
&& NILP (Vinhibit_quit
))
8108 struct gl_state_s saved
;
8109 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
8114 GCPRO4 (saved
.object
, saved
.global_code
,
8115 saved
.current_syntax_table
, saved
.old_prop
);
8116 Fsignal (Qquit
, Qnil
);
8121 /* Else request quit when it's safe */
8125 if (waiting_for_input
&& !echoing
)
8126 quit_throw_to_read_char ();
8131 /* Handle a C-g by making read_char return C-g. */
8134 quit_throw_to_read_char ()
8136 quit_error_check ();
8138 /* Prevent another signal from doing this before we finish. */
8139 clear_waiting_for_input ();
8142 Vunread_command_events
= Qnil
;
8143 unread_command_char
= -1;
8145 #if 0 /* Currently, sit_for is called from read_char without turning
8146 off polling. And that can call set_waiting_for_input.
8147 It seems to be harmless. */
8148 #ifdef POLL_FOR_INPUT
8149 /* May be > 1 if in recursive minibuffer. */
8150 if (poll_suppress_count
== 0)
8154 if (FRAMEP (internal_last_event_frame
)
8155 && XFRAME (internal_last_event_frame
) != selected_frame
)
8156 do_switch_frame (make_lispy_switch_frame (internal_last_event_frame
),
8159 _longjmp (getcjmp
, 1);
8162 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
8163 "Set mode of reading keyboard input.\n\
8164 First arg INTERRUPT non-nil means use input interrupts;\n\
8165 nil means use CBREAK mode.\n\
8166 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
8167 (no effect except in CBREAK mode).\n\
8168 Third arg META t means accept 8-bit input (for a Meta key).\n\
8169 META nil means ignore the top bit, on the assumption it is parity.\n\
8170 Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\
8171 Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\
8172 See also `current-input-mode'.")
8173 (interrupt
, flow
, meta
, quit
)
8174 Lisp_Object interrupt
, flow
, meta
, quit
;
8177 && (!INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400))
8178 error ("set-input-mode: QUIT must be an ASCII character");
8180 #ifdef POLL_FOR_INPUT
8185 /* this causes startup screen to be restored and messes with the mouse */
8190 /* Note SIGIO has been undef'd if FIONREAD is missing. */
8191 if (read_socket_hook
)
8193 /* When using X, don't give the user a real choice,
8194 because we haven't implemented the mechanisms to support it. */
8195 #ifdef NO_SOCK_SIGIO
8196 interrupt_input
= 0;
8197 #else /* not NO_SOCK_SIGIO */
8198 interrupt_input
= 1;
8199 #endif /* NO_SOCK_SIGIO */
8202 interrupt_input
= !NILP (interrupt
);
8203 #else /* not SIGIO */
8204 interrupt_input
= 0;
8205 #endif /* not SIGIO */
8207 /* Our VMS input only works by interrupts, as of now. */
8209 interrupt_input
= 1;
8212 flow_control
= !NILP (flow
);
8215 else if (EQ (meta
, Qt
))
8220 /* Don't let this value be out of range. */
8221 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
8227 #ifdef POLL_FOR_INPUT
8228 poll_suppress_count
= 1;
8234 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
8235 "Return information about the way Emacs currently reads keyboard input.\n\
8236 The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
8237 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\
8238 nil, Emacs is using CBREAK mode.\n\
8239 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\
8240 terminal; this does not apply if Emacs uses interrupt-driven input.\n\
8241 META is t if accepting 8-bit input with 8th bit as Meta flag.\n\
8242 META nil means ignoring the top bit, on the assumption it is parity.\n\
8243 META is neither t nor nil if accepting 8-bit input and using\n\
8244 all 8 bits as the character code.\n\
8245 QUIT is the character Emacs currently uses to quit.\n\
8246 The elements of this list correspond to the arguments of\n\
8252 val
[0] = interrupt_input
? Qt
: Qnil
;
8253 val
[1] = flow_control
? Qt
: Qnil
;
8254 val
[2] = meta_key
== 2 ? make_number (0) : meta_key
== 1 ? Qt
: Qnil
;
8255 XSETFASTINT (val
[3], quit_char
);
8257 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
8262 * Set up a new kboard object with reasonable initial values.
8268 kb
->Voverriding_terminal_local_map
= Qnil
;
8269 kb
->Vlast_command
= Qnil
;
8270 kb
->Vprefix_arg
= Qnil
;
8271 kb
->kbd_queue
= Qnil
;
8272 kb
->kbd_queue_has_data
= 0;
8273 kb
->immediate_echo
= 0;
8274 kb
->echoptr
= kb
->echobuf
;
8275 kb
->echo_after_prompt
= -1;
8276 kb
->kbd_macro_buffer
= 0;
8277 kb
->kbd_macro_bufsize
= 0;
8278 kb
->defining_kbd_macro
= Qnil
;
8279 kb
->Vlast_kbd_macro
= Qnil
;
8280 kb
->reference_count
= 0;
8281 kb
->Vsystem_key_alist
= Qnil
;
8282 kb
->system_key_syms
= Qnil
;
8283 kb
->Vdefault_minibuffer_frame
= Qnil
;
8287 * Destroy the contents of a kboard object, but not the object itself.
8288 * We use this just before deleting it, or if we're going to initialize
8295 if (kb
->kbd_macro_buffer
)
8296 xfree (kb
->kbd_macro_buffer
);
8305 for (kbp
= &all_kboards
; *kbp
!= kb
; kbp
= &(*kbp
)->next_kboard
)
8308 *kbp
= kb
->next_kboard
;
8316 /* This is correct before outermost invocation of the editor loop */
8317 command_loop_level
= -1;
8319 quit_char
= Ctl ('g');
8320 Vunread_command_events
= Qnil
;
8321 unread_command_char
= -1;
8322 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
8324 recent_keys_index
= 0;
8325 kbd_fetch_ptr
= kbd_buffer
;
8326 kbd_store_ptr
= kbd_buffer
;
8327 kbd_buffer_frame_or_window
8328 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
8330 do_mouse_tracking
= Qnil
;
8334 /* This means that command_loop_1 won't try to select anything the first
8336 internal_last_event_frame
= Qnil
;
8337 Vlast_event_frame
= internal_last_event_frame
;
8340 current_kboard
= initial_kboard
;
8342 wipe_kboard (current_kboard
);
8343 init_kboard (current_kboard
);
8346 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
8348 kbd_buffer_frame_or_window
8349 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
8350 if (!noninteractive
&& !read_socket_hook
&& NILP (Vwindow_system
))
8352 signal (SIGINT
, interrupt_signal
);
8353 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
8354 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
8355 SIGQUIT and we can't tell which one it will give us. */
8356 signal (SIGQUIT
, interrupt_signal
);
8357 #endif /* HAVE_TERMIO */
8359 /* Note SIGIO has been undef'd if FIONREAD is missing. */
8361 if (!noninteractive
)
8362 signal (SIGIO
, input_available_signal
);
8365 /* Use interrupt input by default, if it works and noninterrupt input
8366 has deficiencies. */
8368 #ifdef INTERRUPT_INPUT
8369 interrupt_input
= 1;
8371 interrupt_input
= 0;
8374 /* Our VMS input only works by interrupts, as of now. */
8376 interrupt_input
= 1;
8382 if (keyboard_init_hook
)
8383 (*keyboard_init_hook
) ();
8385 #ifdef POLL_FOR_INPUT
8386 poll_suppress_count
= 1;
8391 /* This type's only use is in syms_of_keyboard, to initialize the
8392 event header symbols and put properties on them. */
8399 struct event_head head_table
[] = {
8400 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
8401 &Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
,
8402 &Qswitch_frame
, "switch-frame", &Qswitch_frame
,
8403 &Qdelete_frame
, "delete-frame", &Qdelete_frame
,
8404 &Qiconify_frame
, "iconify-frame", &Qiconify_frame
,
8405 &Qmake_frame_visible
, "make-frame-visible", &Qmake_frame_visible
,
8410 staticpro (&item_properties
);
8411 item_properties
= Qnil
;
8413 Qtimer_event_handler
= intern ("timer-event-handler");
8414 staticpro (&Qtimer_event_handler
);
8416 Qdisabled_command_hook
= intern ("disabled-command-hook");
8417 staticpro (&Qdisabled_command_hook
);
8419 Qself_insert_command
= intern ("self-insert-command");
8420 staticpro (&Qself_insert_command
);
8422 Qforward_char
= intern ("forward-char");
8423 staticpro (&Qforward_char
);
8425 Qbackward_char
= intern ("backward-char");
8426 staticpro (&Qbackward_char
);
8428 Qdisabled
= intern ("disabled");
8429 staticpro (&Qdisabled
);
8431 Qundefined
= intern ("undefined");
8432 staticpro (&Qundefined
);
8434 Qpre_command_hook
= intern ("pre-command-hook");
8435 staticpro (&Qpre_command_hook
);
8437 Qpost_command_hook
= intern ("post-command-hook");
8438 staticpro (&Qpost_command_hook
);
8440 Qpost_command_idle_hook
= intern ("post-command-idle-hook");
8441 staticpro (&Qpost_command_idle_hook
);
8443 Qdeferred_action_function
= intern ("deferred-action-function");
8444 staticpro (&Qdeferred_action_function
);
8446 Qcommand_hook_internal
= intern ("command-hook-internal");
8447 staticpro (&Qcommand_hook_internal
);
8449 Qfunction_key
= intern ("function-key");
8450 staticpro (&Qfunction_key
);
8451 Qmouse_click
= intern ("mouse-click");
8452 staticpro (&Qmouse_click
);
8454 Qmouse_wheel
= intern ("mouse-wheel");
8455 staticpro (&Qmouse_wheel
);
8458 Qmenu_enable
= intern ("menu-enable");
8459 staticpro (&Qmenu_enable
);
8460 Qmenu_alias
= intern ("menu-alias");
8461 staticpro (&Qmenu_alias
);
8462 QCenable
= intern (":enable");
8463 staticpro (&QCenable
);
8464 QCvisible
= intern (":visible");
8465 staticpro (&QCvisible
);
8466 QCfilter
= intern (":filter");
8467 staticpro (&QCfilter
);
8468 QCbutton
= intern (":button");
8469 staticpro (&QCbutton
);
8470 QCtoggle
= intern (":toggle");
8471 staticpro (&QCtoggle
);
8472 QCradio
= intern (":radio");
8473 staticpro (&QCradio
);
8475 Qmode_line
= intern ("mode-line");
8476 staticpro (&Qmode_line
);
8477 Qvertical_line
= intern ("vertical-line");
8478 staticpro (&Qvertical_line
);
8479 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
8480 staticpro (&Qvertical_scroll_bar
);
8481 Qmenu_bar
= intern ("menu-bar");
8482 staticpro (&Qmenu_bar
);
8484 Qabove_handle
= intern ("above-handle");
8485 staticpro (&Qabove_handle
);
8486 Qhandle
= intern ("handle");
8487 staticpro (&Qhandle
);
8488 Qbelow_handle
= intern ("below-handle");
8489 staticpro (&Qbelow_handle
);
8490 Qup
= intern ("up");
8492 Qdown
= intern ("down");
8495 Qevent_kind
= intern ("event-kind");
8496 staticpro (&Qevent_kind
);
8497 Qevent_symbol_elements
= intern ("event-symbol-elements");
8498 staticpro (&Qevent_symbol_elements
);
8499 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
8500 staticpro (&Qevent_symbol_element_mask
);
8501 Qmodifier_cache
= intern ("modifier-cache");
8502 staticpro (&Qmodifier_cache
);
8504 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
8505 staticpro (&Qrecompute_lucid_menubar
);
8506 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
8507 staticpro (&Qactivate_menubar_hook
);
8509 Qpolling_period
= intern ("polling-period");
8510 staticpro (&Qpolling_period
);
8513 struct event_head
*p
;
8515 for (p
= head_table
;
8516 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
8519 *p
->var
= intern (p
->name
);
8521 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
8522 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
8526 button_down_location
= Fmake_vector (make_number (NUM_MOUSE_BUTTONS
), Qnil
);
8527 staticpro (&button_down_location
);
8531 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
8533 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
8534 for (i
= 0; i
< len
; i
++)
8535 if (modifier_names
[i
])
8536 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
8537 staticpro (&modifier_symbols
);
8540 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
8541 staticpro (&recent_keys
);
8543 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
8544 staticpro (&this_command_keys
);
8546 Qextended_command_history
= intern ("extended-command-history");
8547 Fset (Qextended_command_history
, Qnil
);
8548 staticpro (&Qextended_command_history
);
8550 kbd_buffer_frame_or_window
8551 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
8552 staticpro (&kbd_buffer_frame_or_window
);
8554 accent_key_syms
= Qnil
;
8555 staticpro (&accent_key_syms
);
8557 func_key_syms
= Qnil
;
8558 staticpro (&func_key_syms
);
8561 staticpro (&mouse_syms
);
8564 mouse_wheel_syms
= Qnil
;
8565 staticpro (&mouse_wheel_syms
);
8568 unread_switch_frame
= Qnil
;
8569 staticpro (&unread_switch_frame
);
8571 internal_last_event_frame
= Qnil
;
8572 staticpro (&internal_last_event_frame
);
8574 read_key_sequence_cmd
= Qnil
;
8575 staticpro (&read_key_sequence_cmd
);
8577 defsubr (&Sevent_convert_list
);
8578 defsubr (&Sread_key_sequence
);
8579 defsubr (&Sread_key_sequence_vector
);
8580 defsubr (&Srecursive_edit
);
8582 defsubr (&Strack_mouse
);
8584 defsubr (&Sinput_pending_p
);
8585 defsubr (&Scommand_execute
);
8586 defsubr (&Srecent_keys
);
8587 defsubr (&Sthis_command_keys
);
8588 defsubr (&Sthis_command_keys_vector
);
8589 defsubr (&Sthis_single_command_keys
);
8590 defsubr (&Sreset_this_command_lengths
);
8591 defsubr (&Ssuspend_emacs
);
8592 defsubr (&Sabort_recursive_edit
);
8593 defsubr (&Sexit_recursive_edit
);
8594 defsubr (&Srecursion_depth
);
8595 defsubr (&Stop_level
);
8596 defsubr (&Sdiscard_input
);
8597 defsubr (&Sopen_dribble_file
);
8598 defsubr (&Sset_input_mode
);
8599 defsubr (&Scurrent_input_mode
);
8600 defsubr (&Sexecute_extended_command
);
8602 DEFVAR_LISP ("last-command-char", &last_command_char
,
8603 "Last input event that was part of a command.");
8605 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char
,
8606 "Last input event that was part of a command.");
8608 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
8609 "Last input event in a command, except for mouse menu events.\n\
8610 Mouse menus give back keys that don't look like mouse events;\n\
8611 this variable holds the actual mouse event that led to the menu,\n\
8612 so that you can determine whether the command was run by mouse or not.");
8614 DEFVAR_LISP ("last-input-char", &last_input_char
,
8615 "Last input event.");
8617 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char
,
8618 "Last input event.");
8620 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
8621 "List of objects to be read as next command input events.");
8623 DEFVAR_INT ("unread-command-char", &unread_command_char
,
8624 "If not -1, an object to be read as next command input event.");
8626 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
8627 "Meta-prefix character code. Meta-foo as command input\n\
8628 turns into this character followed by foo.");
8629 XSETINT (meta_prefix_char
, 033);
8631 DEFVAR_KBOARD ("last-command", Vlast_command
,
8632 "The last command executed. Normally a symbol with a function definition,\n\
8633 but can be whatever was found in the keymap, or whatever the variable\n\
8634 `this-command' was set to by that command.\n\
8636 The value `mode-exit' is special; it means that the previous command\n\
8637 read an event that told it to exit, and it did so and unread that event.\n\
8638 In other words, the present command is the event that made the previous\n\
8641 The value `kill-region' is special; it means that the previous command\n\
8642 was a kill command.");
8644 DEFVAR_LISP ("this-command", &this_command
,
8645 "The command now being executed.\n\
8646 The command can set this variable; whatever is put here\n\
8647 will be in `last-command' during the following command.");
8648 this_command
= Qnil
;
8650 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
8651 "*Number of keyboard input characters between auto-saves.\n\
8652 Zero means disable autosaving due to number of characters typed.");
8653 auto_save_interval
= 300;
8655 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
8656 "*Number of seconds idle time before auto-save.\n\
8657 Zero or nil means disable auto-saving due to idleness.\n\
8658 After auto-saving due to this many seconds of idle time,\n\
8659 Emacs also does a garbage collection if that seems to be warranted.");
8660 XSETFASTINT (Vauto_save_timeout
, 30);
8662 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes
,
8663 "*Nonzero means echo unfinished commands after this many seconds of pause.");
8664 echo_keystrokes
= 1;
8666 DEFVAR_INT ("polling-period", &polling_period
,
8667 "*Interval between polling for input during Lisp execution.\n\
8668 The reason for polling is to make C-g work to stop a running program.\n\
8669 Polling is needed only when using X windows and SIGIO does not work.\n\
8670 Polling is automatically disabled in all other cases.");
8673 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
8674 "*Maximum time between mouse clicks to make a double-click.\n\
8675 Measured in milliseconds. nil means disable double-click recognition;\n\
8676 t means double-clicks have no time limit and are detected\n\
8677 by position only.");
8678 Vdouble_click_time
= make_number (500);
8680 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
8681 "*Non-nil means inhibit local map menu bar menus.");
8682 inhibit_local_menu_bar_menus
= 0;
8684 DEFVAR_INT ("num-input-keys", &num_input_keys
,
8685 "Number of complete key sequences read as input so far.\n\
8686 This includes key sequences read from keyboard macros.\n\
8687 The number is effectively the number of interactive command invocations.");
8690 DEFVAR_INT ("num-nonmacro-input-events", &num_nonmacro_input_events
,
8691 "Number of input events read from the keyboard so far.\n\
8692 This does not include events generated by keyboard macros.");
8693 num_nonmacro_input_events
= 0;
8695 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
8696 "The frame in which the most recently read event occurred.\n\
8697 If the last event came from a keyboard macro, this is set to `macro'.");
8698 Vlast_event_frame
= Qnil
;
8700 /* This variable is set up in sysdep.c. */
8701 DEFVAR_LISP ("tty-erase-char", &Vtty_erase_char
,
8702 "The ERASE character as set by the user with stty.");
8704 DEFVAR_LISP ("help-char", &Vhelp_char
,
8705 "Character to recognize as meaning Help.\n\
8706 When it is read, do `(eval help-form)', and display result if it's a string.\n\
8707 If the value of `help-form' is nil, this char can be read normally.");
8708 XSETINT (Vhelp_char
, Ctl ('H'));
8710 DEFVAR_LISP ("help-event-list", &Vhelp_event_list
,
8711 "List of input events to recognize as meaning Help.\n\
8712 These work just like the value of `help-char' (see that).");
8713 Vhelp_event_list
= Qnil
;
8715 DEFVAR_LISP ("help-form", &Vhelp_form
,
8716 "Form to execute when character `help-char' is read.\n\
8717 If the form returns a string, that string is displayed.\n\
8718 If `help-form' is nil, the help char is not recognized.");
8721 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
8722 "Command to run when `help-char' character follows a prefix key.\n\
8723 This command is used only when there is no actual binding\n\
8724 for that character after that prefix key.");
8725 Vprefix_help_command
= Qnil
;
8727 DEFVAR_LISP ("top-level", &Vtop_level
,
8728 "Form to evaluate when Emacs starts up.\n\
8729 Useful to set before you dump a modified Emacs.");
8732 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
8733 "Translate table for keyboard input, or nil.\n\
8734 Each character is looked up in this string and the contents used instead.\n\
8735 The value may be a string, a vector, or a char-table.\n\
8736 If it is a string or vector of length N,\n\
8737 character codes N and up are untranslated.\n\
8738 In a vector or a char-table, an element which is nil means \"no translation\".");
8739 Vkeyboard_translate_table
= Qnil
;
8741 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
8742 "Non-nil means to always spawn a subshell instead of suspending,\n\
8743 even if the operating system has support for stopping a process.");
8746 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
8747 "Non-nil means prompt with menus when appropriate.\n\
8748 This is done when reading from a keymap that has a prompt string,\n\
8749 for elements that have prompt strings.\n\
8750 The menu is displayed on the screen\n\
8751 if X menus were enabled at configuration\n\
8752 time and the previous event was a mouse click prefix key.\n\
8753 Otherwise, menu prompting uses the echo area.");
8756 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
8757 "Character to see next line of menu prompt.\n\
8758 Type this character while in a menu prompt to rotate around the lines of it.");
8759 XSETINT (menu_prompt_more_char
, ' ');
8761 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
8762 "A mask of additional modifier keys to use with every keyboard character.\n\
8763 Emacs applies the modifiers of the character stored here to each keyboard\n\
8764 character it reads. For example, after evaluating the expression\n\
8765 (setq extra-keyboard-modifiers ?\\C-x)\n\
8766 all input characters will have the control modifier applied to them.\n\
8768 Note that the character ?\\C-@, equivalent to the integer zero, does\n\
8769 not count as a control character; rather, it counts as a character\n\
8770 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\
8771 cancels any modification.");
8772 extra_keyboard_modifiers
= 0;
8774 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
8775 "If an editing command sets this to t, deactivate the mark afterward.\n\
8776 The command loop sets this to nil before each command,\n\
8777 and tests the value when the command returns.\n\
8778 Buffer modification stores t in this variable.");
8779 Vdeactivate_mark
= Qnil
;
8781 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
8782 "Temporary storage of pre-command-hook or post-command-hook.");
8783 Vcommand_hook_internal
= Qnil
;
8785 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
8786 "Normal hook run before each command is executed.\n\
8787 Errors running the hook are caught and ignored.");
8788 Vpre_command_hook
= Qnil
;
8790 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
8791 "Normal hook run after each command is executed.\n\
8792 Errors running the hook are caught and ignored.");
8793 Vpost_command_hook
= Qnil
;
8795 DEFVAR_LISP ("post-command-idle-hook", &Vpost_command_idle_hook
,
8796 "Normal hook run after each command is executed, if idle.\n\
8797 Errors running the hook are caught and ignored.\n\
8798 This feature is obsolete; use idle timers instead. See `etc/NEWS'.");
8799 Vpost_command_idle_hook
= Qnil
;
8801 DEFVAR_INT ("post-command-idle-delay", &post_command_idle_delay
,
8802 "Delay time before running `post-command-idle-hook'.\n\
8803 This is measured in microseconds.");
8804 post_command_idle_delay
= 100000;
8807 DEFVAR_LISP ("echo-area-clear-hook", ...,
8808 "Normal hook run when clearing the echo area.");
8810 Qecho_area_clear_hook
= intern ("echo-area-clear-hook");
8811 XSYMBOL (Qecho_area_clear_hook
)->value
= Qnil
;
8813 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
8814 "t means menu bar, specified Lucid style, needs to be recomputed.");
8815 Vlucid_menu_bar_dirty_flag
= Qnil
;
8817 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
8818 "List of menu bar items to move to the end of the menu bar.\n\
8819 The elements of the list are event types that may have menu bar bindings.");
8820 Vmenu_bar_final_items
= Qnil
;
8822 DEFVAR_KBOARD ("overriding-terminal-local-map",
8823 Voverriding_terminal_local_map
,
8824 "Per-terminal keymap that overrides all other local keymaps.\n\
8825 If this variable is non-nil, it is used as a keymap instead of the\n\
8826 buffer's local map, and the minor mode keymaps and text property keymaps.\n\
8827 This variable is intended to let commands such as `universal-argumemnt'\n\
8828 set up a different keymap for reading the next command.");
8830 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
8831 "Keymap that overrides all other local keymaps.\n\
8832 If this variable is non-nil, it is used as a keymap instead of the\n\
8833 buffer's local map, and the minor mode keymaps and text property keymaps.");
8834 Voverriding_local_map
= Qnil
;
8836 DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag
,
8837 "Non-nil means `overriding-local-map' applies to the menu bar.\n\
8838 Otherwise, the menu bar continues to reflect the buffer's local map\n\
8839 and the minor mode maps regardless of `overriding-local-map'.");
8840 Voverriding_local_map_menu_flag
= Qnil
;
8842 DEFVAR_LISP ("special-event-map", &Vspecial_event_map
,
8843 "Keymap defining bindings for special events to execute at low level.");
8844 Vspecial_event_map
= Fcons (intern ("keymap"), Qnil
);
8846 DEFVAR_LISP ("track-mouse", &do_mouse_tracking
,
8847 "*Non-nil means generate motion events for mouse motion.");
8849 DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist
,
8850 "Alist of system-specific X windows key symbols.\n\
8851 Each element should have the form (N . SYMBOL) where N is the\n\
8852 numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\
8853 and SYMBOL is its name.");
8855 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
8856 "List of deferred actions to be performed at a later time.\n\
8857 The precise format isn't relevant here; we just check whether it is nil.");
8858 Vdeferred_action_list
= Qnil
;
8860 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
8861 "Function to call to handle deferred actions, after each command.\n\
8862 This function is called with no arguments after each command\n\
8863 whenever `deferred-action-list' is non-nil.");
8864 Vdeferred_action_function
= Qnil
;
8866 DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings
,
8867 "Non-nil means show the equivalent key-binding when M-x command has one.\n\
8868 The value can be a length of time to show the message for.\n\
8869 If the value is non-nil and not a number, we wait 2 seconds.");
8870 Vsuggest_key_bindings
= Qt
;
8872 DEFVAR_LISP ("timer-list", &Vtimer_list
,
8873 "List of active absolute time timers in order of increasing time");
8876 DEFVAR_LISP ("timer-idle-list", &Vtimer_idle_list
,
8877 "List of active idle-time timers in order of increasing time");
8878 Vtimer_idle_list
= Qnil
;
8883 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
8884 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
8885 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
8886 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
8887 initial_define_key (meta_map
, 'x', "execute-extended-command");
8889 initial_define_lispy_key (Vspecial_event_map
, "delete-frame",
8890 "handle-delete-frame");
8891 initial_define_lispy_key (Vspecial_event_map
, "iconify-frame",
8893 initial_define_lispy_key (Vspecial_event_map
, "make-frame-visible",