1 /* Keyboard and mouse input; editor command loop.
2 Copyright (C) 1985,86,87,88,89,93,94,95,96,97 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Allow config.h to undefine symbols found here. */
29 #include "termhooks.h"
37 #include "dispextern.h"
39 #include "intervals.h"
40 #include "blockinput.h"
49 #include <sys/ioctl.h>
51 #endif /* not MSDOS */
53 #include "syssignal.h"
56 /* This is to get the definitions of the XK_ symbols. */
63 #endif /* HAVE_NTGUI */
65 /* Include systime.h after xterm.h to avoid double inclusion of time.h. */
70 /* Variables for blockinput.h: */
72 /* Non-zero if interrupt input is blocked right now. */
73 int interrupt_input_blocked
;
75 /* Nonzero means an input interrupt has arrived
76 during the current critical section. */
77 int interrupt_input_pending
;
80 /* File descriptor to use for input. */
83 #ifdef HAVE_WINDOW_SYSTEM
84 /* Make all keyboard buffers much bigger when using X windows. */
85 #define KBD_BUFFER_SIZE 4096
86 #else /* No X-windows, character input */
87 #define KBD_BUFFER_SIZE 256
88 #endif /* No X-windows */
90 /* Following definition copied from eval.c */
94 struct backtrace
*next
;
95 Lisp_Object
*function
;
96 Lisp_Object
*args
; /* Points to vector of args. */
97 int nargs
; /* length of vector. If nargs is UNEVALLED,
98 args points to slot holding list of
104 KBOARD
*initial_kboard
;
105 KBOARD
*current_kboard
;
109 KBOARD the_only_kboard
;
112 /* Non-nil disable property on a command means
113 do not execute it; call disabled-command-hook's value instead. */
114 Lisp_Object Qdisabled
, Qdisabled_command_hook
;
116 #define NUM_RECENT_KEYS (100)
117 int recent_keys_index
; /* Index for storing next element into recent_keys */
118 int total_keys
; /* Total number of elements stored into recent_keys */
119 Lisp_Object recent_keys
; /* A vector, holding the last 100 keystrokes */
121 /* Vector holding the key sequence that invoked the current command.
122 It is reused for each command, and it may be longer than the current
123 sequence; this_command_key_count indicates how many elements
124 actually mean something.
125 It's easier to staticpro a single Lisp_Object than an array. */
126 Lisp_Object this_command_keys
;
127 int this_command_key_count
;
129 /* Number of elements of this_command_keys
130 that precede this key sequence. */
131 int this_single_command_key_start
;
133 /* Record values of this_command_key_count and echo_length ()
134 before this command was read. */
135 static int before_command_key_count
;
136 static int before_command_echo_length
;
137 /* Values of before_command_key_count and before_command_echo_length
138 saved by reset-this-command-lengths. */
139 static int before_command_key_count_1
;
140 static int before_command_echo_length_1
;
141 /* Flag set by reset-this-command-lengths,
142 saying to reset the lengths when add_command_key is called. */
143 static int before_command_restore_flag
;
145 extern int minbuf_level
;
147 extern int message_enable_multibyte
;
149 extern struct backtrace
*backtrace_list
;
151 /* Nonzero means do menu prompting. */
152 static int menu_prompting
;
154 /* Character to see next line of menu prompt. */
155 static Lisp_Object menu_prompt_more_char
;
157 /* For longjmp to where kbd input is being done. */
158 static jmp_buf getcjmp
;
160 /* True while doing kbd input. */
161 int waiting_for_input
;
163 /* True while displaying for echoing. Delays C-g throwing. */
166 /* True means we can start echoing at the next input pause
167 even though there is something in the echo area. */
168 static char *ok_to_echo_at_next_pause
;
170 /* Nonzero means disregard local maps for the menu bar. */
171 static int inhibit_local_menu_bar_menus
;
173 /* Nonzero means C-g should cause immediate error-signal. */
176 /* The user's ERASE setting. */
177 Lisp_Object Vtty_erase_char
;
179 /* Character to recognize as the help char. */
180 Lisp_Object Vhelp_char
;
182 /* List of other event types to recognize as meaning "help". */
183 Lisp_Object Vhelp_event_list
;
185 /* Form to execute when help char is typed. */
186 Lisp_Object Vhelp_form
;
188 /* Command to run when the help character follows a prefix key. */
189 Lisp_Object Vprefix_help_command
;
191 /* List of items that should move to the end of the menu bar. */
192 Lisp_Object Vmenu_bar_final_items
;
194 /* Non-nil means show the equivalent key-binding for
195 any M-x command that has one.
196 The value can be a length of time to show the message for.
197 If the value is non-nil and not a number, we wait 2 seconds. */
198 Lisp_Object Vsuggest_key_bindings
;
200 /* Character that causes a quit. Normally C-g.
202 If we are running on an ordinary terminal, this must be an ordinary
203 ASCII char, since we want to make it our interrupt character.
205 If we are not running on an ordinary terminal, it still needs to be
206 an ordinary ASCII char. This character needs to be recognized in
207 the input interrupt handler. At this point, the keystroke is
208 represented as a struct input_event, while the desired quit
209 character is specified as a lispy event. The mapping from struct
210 input_events to lispy events cannot run in an interrupt handler,
211 and the reverse mapping is difficult for anything but ASCII
214 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
218 extern Lisp_Object current_global_map
;
219 extern int minibuf_level
;
221 /* If non-nil, this is a map that overrides all other local maps. */
222 Lisp_Object Voverriding_local_map
;
224 /* If non-nil, Voverriding_local_map applies to the menu bar. */
225 Lisp_Object Voverriding_local_map_menu_flag
;
227 /* Keymap that defines special misc events that should
228 be processed immediately at a low level. */
229 Lisp_Object Vspecial_event_map
;
231 /* Current depth in recursive edits. */
232 int command_loop_level
;
234 /* Total number of times command_loop has read a key sequence. */
237 /* Last input character read as a command. */
238 Lisp_Object last_command_char
;
240 /* Last input character read as a command, not counting menus
241 reached by the mouse. */
242 Lisp_Object last_nonmenu_event
;
244 /* Last input character read for any purpose. */
245 Lisp_Object last_input_char
;
247 /* If not Qnil, a list of objects to be read as subsequent command input. */
248 Lisp_Object Vunread_command_events
;
250 /* If not -1, an event to be read as subsequent command input. */
251 int unread_command_char
;
253 /* If not Qnil, this is a switch-frame event which we decided to put
254 off until the end of a key sequence. This should be read as the
255 next command input, after any unread_command_events.
257 read_key_sequence uses this to delay switch-frame events until the
258 end of the key sequence; Fread_char uses it to put off switch-frame
259 events until a non-ASCII event is acceptable as input. */
260 Lisp_Object unread_switch_frame
;
262 /* A mask of extra modifier bits to put into every keyboard char. */
263 int extra_keyboard_modifiers
;
265 /* Char to use as prefix when a meta character is typed in.
266 This is bound on entry to minibuffer in case ESC is changed there. */
268 Lisp_Object meta_prefix_char
;
270 /* Last size recorded for a current buffer which is not a minibuffer. */
271 static int last_non_minibuf_size
;
273 /* Number of idle seconds before an auto-save and garbage collection. */
274 static Lisp_Object Vauto_save_timeout
;
276 /* Total number of times read_char has returned. */
277 int num_input_events
;
279 /* Total number of times read_char has returned, outside of macros. */
280 int num_nonmacro_input_events
;
282 /* Auto-save automatically when this many characters have been typed
283 since the last time. */
285 static int auto_save_interval
;
287 /* Value of num_nonmacro_input_events as of last auto save. */
291 /* The command being executed by the command loop.
292 Commands may set this, and the value set will be copied into
293 current_kboard->Vlast_command instead of the actual command. */
294 Lisp_Object this_command
;
296 /* The value of point when the last command was executed. */
297 int last_point_position
;
299 /* The buffer that was current when the last command was started. */
300 Lisp_Object last_point_position_buffer
;
302 /* The frame in which the last input event occurred, or Qmacro if the
303 last event came from a macro. We use this to determine when to
304 generate switch-frame events. This may be cleared by functions
305 like Fselect_frame, to make sure that a switch-frame event is
306 generated by the next character. */
307 Lisp_Object internal_last_event_frame
;
309 /* A user-visible version of the above, intended to allow users to
310 figure out where the last event came from, if the event doesn't
311 carry that information itself (i.e. if it was a character). */
312 Lisp_Object Vlast_event_frame
;
314 /* The timestamp of the last input event we received from the X server.
315 X Windows wants this for selection ownership. */
316 unsigned long last_event_timestamp
;
318 Lisp_Object Qself_insert_command
;
319 Lisp_Object Qforward_char
;
320 Lisp_Object Qbackward_char
;
321 Lisp_Object Qundefined
;
322 Lisp_Object Qtimer_event_handler
;
324 /* read_key_sequence stores here the command definition of the
325 key sequence that it reads. */
326 Lisp_Object read_key_sequence_cmd
;
328 /* Form to evaluate (if non-nil) when Emacs is started. */
329 Lisp_Object Vtop_level
;
331 /* User-supplied string to translate input characters through. */
332 Lisp_Object Vkeyboard_translate_table
;
334 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
335 extern Lisp_Object Vfunction_key_map
;
337 /* Another keymap that maps key sequences into key sequences.
338 This one takes precedence over ordinary definitions. */
339 extern Lisp_Object Vkey_translation_map
;
341 /* Non-nil means deactivate the mark at end of this command. */
342 Lisp_Object Vdeactivate_mark
;
344 /* Menu bar specified in Lucid Emacs fashion. */
346 Lisp_Object Vlucid_menu_bar_dirty_flag
;
347 Lisp_Object Qrecompute_lucid_menubar
, Qactivate_menubar_hook
;
349 Lisp_Object Qecho_area_clear_hook
;
351 /* Hooks to run before and after each command. */
352 Lisp_Object Qpre_command_hook
, Vpre_command_hook
;
353 Lisp_Object Qpost_command_hook
, Vpost_command_hook
;
354 Lisp_Object Qcommand_hook_internal
, Vcommand_hook_internal
;
355 /* Hook run after a command if there's no more input soon. */
356 Lisp_Object Qpost_command_idle_hook
, Vpost_command_idle_hook
;
358 /* Delay time in microseconds before running post-command-idle-hook. */
359 int post_command_idle_delay
;
361 /* List of deferred actions to be performed at a later time.
362 The precise format isn't relevant here; we just check whether it is nil. */
363 Lisp_Object Vdeferred_action_list
;
365 /* Function to call to handle deferred actions, when there are any. */
366 Lisp_Object Vdeferred_action_function
;
367 Lisp_Object Qdeferred_action_function
;
369 /* File in which we write all commands we read. */
372 /* Nonzero if input is available. */
375 /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
376 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
380 extern char *pending_malloc_warning
;
382 /* Circular buffer for pre-read keyboard input. */
383 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
385 /* Vector to GCPRO the frames and windows mentioned in kbd_buffer.
387 The interrupt-level event handlers will never enqueue an event on a
388 frame which is not in Vframe_list, and once an event is dequeued,
389 internal_last_event_frame or the event itself points to the frame.
392 But while the event is sitting in the queue, it's completely
393 unprotected. Suppose the user types one command which will run for
394 a while and then delete a frame, and then types another event at
395 the frame that will be deleted, before the command gets around to
396 it. Suppose there are no references to this frame elsewhere in
397 Emacs, and a GC occurs before the second event is dequeued. Now we
398 have an event referring to a freed frame, which will crash Emacs
401 Similar things happen when an event on a scroll bar is enqueued; the
402 window may be deleted while the event is in the queue.
404 So, we use this vector to protect the frame_or_window field in the
405 event queue. That way, they'll be dequeued as dead frames or
406 windows, but still valid lisp objects.
408 If kbd_buffer[i].kind != no_event, then
409 (XVECTOR (kbd_buffer_frame_or_window)->contents[i]
410 == kbd_buffer[i].frame_or_window. */
411 static Lisp_Object kbd_buffer_frame_or_window
;
413 /* Pointer to next available character in kbd_buffer.
414 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
415 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the
416 next available char is in kbd_buffer[0]. */
417 static struct input_event
*kbd_fetch_ptr
;
419 /* Pointer to next place to store character in kbd_buffer. This
420 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
421 character should go in kbd_buffer[0]. */
422 static volatile struct input_event
*kbd_store_ptr
;
424 /* The above pair of variables forms a "queue empty" flag. When we
425 enqueue a non-hook event, we increment kbd_store_ptr. When we
426 dequeue a non-hook event, we increment kbd_fetch_ptr. We say that
427 there is input available iff the two pointers are not equal.
429 Why not just have a flag set and cleared by the enqueuing and
430 dequeuing functions? Such a flag could be screwed up by interrupts
431 at inopportune times. */
433 /* If this flag is non-nil, we check mouse_moved to see when the
434 mouse moves, and motion events will appear in the input stream.
435 Otherwise, mouse motion is ignored. */
436 static Lisp_Object do_mouse_tracking
;
438 /* Symbols to head events. */
439 Lisp_Object Qmouse_movement
;
440 Lisp_Object Qscroll_bar_movement
;
441 Lisp_Object Qswitch_frame
;
442 Lisp_Object Qdelete_frame
;
443 Lisp_Object Qiconify_frame
;
444 Lisp_Object Qmake_frame_visible
;
446 /* Symbols to denote kinds of events. */
447 Lisp_Object Qfunction_key
;
448 Lisp_Object Qmouse_click
;
450 Lisp_Object Qmouse_wheel
;
452 /* Lisp_Object Qmouse_movement; - also an event header */
454 /* Properties of event headers. */
455 Lisp_Object Qevent_kind
;
456 Lisp_Object Qevent_symbol_elements
;
458 Lisp_Object Qmenu_enable
;
460 /* An event header symbol HEAD may have a property named
461 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
462 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
463 mask of modifiers applied to it. If present, this is used to help
464 speed up parse_modifiers. */
465 Lisp_Object Qevent_symbol_element_mask
;
467 /* An unmodified event header BASE may have a property named
468 Qmodifier_cache, which is an alist mapping modifier masks onto
469 modified versions of BASE. If present, this helps speed up
471 Lisp_Object Qmodifier_cache
;
473 /* Symbols to use for parts of windows. */
474 Lisp_Object Qmode_line
;
475 Lisp_Object Qvertical_line
;
476 Lisp_Object Qvertical_scroll_bar
;
477 Lisp_Object Qmenu_bar
;
479 extern Lisp_Object Qmenu_enable
;
481 Lisp_Object
recursive_edit_unwind (), command_loop ();
482 Lisp_Object
Fthis_command_keys ();
483 Lisp_Object Qextended_command_history
;
484 EMACS_TIME
timer_check ();
486 extern char *x_get_keysym_name ();
488 static void record_menu_key ();
490 void swallow_events ();
492 Lisp_Object Qpolling_period
;
494 /* List of absolute timers. Appears in order of next scheduled event. */
495 Lisp_Object Vtimer_list
;
497 /* List of idle time timers. Appears in order of next scheduled event. */
498 Lisp_Object Vtimer_idle_list
;
500 /* Incremented whenever a timer is run. */
503 extern Lisp_Object Vprint_level
, Vprint_length
;
505 extern nonascii_insert_offset
;
507 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
509 EMACS_TIME
*input_available_clear_time
;
511 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
512 Default is 1 if INTERRUPT_INPUT is defined. */
515 /* Nonzero while interrupts are temporarily deferred during redisplay. */
516 int interrupts_deferred
;
518 /* Nonzero means use ^S/^Q for flow control. */
521 /* Allow m- file to inhibit use of FIONREAD. */
522 #ifdef BROKEN_FIONREAD
526 /* We are unable to use interrupts if FIONREAD is not available,
527 so flush SIGIO so we won't try. */
534 /* If we support a window system, turn on the code to poll periodically
535 to detect C-g. It isn't actually used when doing interrupt input. */
536 #ifdef HAVE_WINDOW_SYSTEM
537 #define POLL_FOR_INPUT
540 /* Global variable declarations. */
542 /* Function for init_keyboard to call with no args (if nonzero). */
543 void (*keyboard_init_hook
) ();
545 static int read_avail_input ();
546 static void get_input_pending ();
547 static int readable_events ();
548 static Lisp_Object
read_char_x_menu_prompt ();
549 static Lisp_Object
read_char_minibuf_menu_prompt ();
550 static Lisp_Object
make_lispy_event ();
552 static Lisp_Object
make_lispy_movement ();
554 static Lisp_Object
modify_event_symbol ();
555 static Lisp_Object
make_lispy_switch_frame ();
556 static int parse_solitary_modifier ();
558 /* > 0 if we are to echo keystrokes. */
559 static int echo_keystrokes
;
561 /* Nonzero means don't try to suspend even if the operating system seems
563 static int cannot_suspend
;
565 #define min(a,b) ((a)<(b)?(a):(b))
566 #define max(a,b) ((a)>(b)?(a):(b))
568 /* Install the string STR as the beginning of the string of echoing,
569 so that it serves as a prompt for the next character.
570 Also start echoing. */
575 int len
= strlen (str
);
577 if (len
> ECHOBUFSIZE
- 4)
578 len
= ECHOBUFSIZE
- 4;
579 bcopy (str
, current_kboard
->echobuf
, len
);
580 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
581 *current_kboard
->echoptr
= '\0';
583 current_kboard
->echo_after_prompt
= len
;
588 /* Add C to the echo string, if echoing is going on.
589 C can be a character, which is printed prettily ("M-C-x" and all that
590 jazz), or a symbol, whose name is printed. */
595 extern char *push_key_description ();
597 if (current_kboard
->immediate_echo
)
599 char *ptr
= current_kboard
->echoptr
;
601 if (ptr
!= current_kboard
->echobuf
)
604 /* If someone has passed us a composite event, use its head symbol. */
609 if (ptr
- current_kboard
->echobuf
> ECHOBUFSIZE
- 6)
612 ptr
= push_key_description (XINT (c
), ptr
);
614 else if (SYMBOLP (c
))
616 struct Lisp_String
*name
= XSYMBOL (c
)->name
;
617 if ((ptr
- current_kboard
->echobuf
) + name
->size_byte
+ 4
620 bcopy (name
->data
, ptr
, name
->size_byte
);
621 ptr
+= name
->size_byte
;
624 if (current_kboard
->echoptr
== current_kboard
->echobuf
627 strcpy (ptr
, " (Type ? for further options)");
632 current_kboard
->echoptr
= ptr
;
638 /* Temporarily add a dash to the end of the echo string if it's not
639 empty, so that it serves as a mini-prompt for the very next character. */
643 if (!current_kboard
->immediate_echo
644 && current_kboard
->echoptr
== current_kboard
->echobuf
)
646 /* Do nothing if we just printed a prompt. */
647 if (current_kboard
->echo_after_prompt
648 == current_kboard
->echoptr
- current_kboard
->echobuf
)
650 /* Do nothing if not echoing at all. */
651 if (current_kboard
->echoptr
== 0)
654 /* Put a dash at the end of the buffer temporarily,
655 but make it go away when the next character is added. */
656 current_kboard
->echoptr
[0] = '-';
657 current_kboard
->echoptr
[1] = 0;
662 /* Display the current echo string, and begin echoing if not already
668 if (!current_kboard
->immediate_echo
)
671 current_kboard
->immediate_echo
= 1;
673 for (i
= 0; i
< this_command_key_count
; i
++)
676 c
= XVECTOR (this_command_keys
)->contents
[i
];
677 if (! (EVENT_HAS_PARAMETERS (c
)
678 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
685 message2_nolog (current_kboard
->echobuf
, strlen (current_kboard
->echobuf
),
686 ! NILP (current_buffer
->enable_multibyte_characters
));
690 if (waiting_for_input
&& !NILP (Vquit_flag
))
691 quit_throw_to_read_char ();
694 /* Turn off echoing, for the start of a new command. */
698 current_kboard
->immediate_echo
= 0;
699 current_kboard
->echoptr
= current_kboard
->echobuf
;
700 current_kboard
->echo_after_prompt
= -1;
701 ok_to_echo_at_next_pause
= 0;
704 /* Return the length of the current echo string. */
709 return current_kboard
->echoptr
- current_kboard
->echobuf
;
712 /* Truncate the current echo message to its first LEN chars.
713 This and echo_char get used by read_key_sequence when the user
714 switches frames while entering a key sequence. */
720 current_kboard
->echobuf
[len
] = '\0';
721 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
722 truncate_echo_area (len
);
726 /* Functions for manipulating this_command_keys. */
728 add_command_key (key
)
731 int size
= XVECTOR (this_command_keys
)->size
;
733 /* If reset-this-command-length was called recently, obey it now.
734 See the doc string of that function for an explanation of why. */
735 if (before_command_restore_flag
)
737 this_command_key_count
= before_command_key_count_1
;
738 if (this_command_key_count
< this_single_command_key_start
)
739 this_single_command_key_start
= this_command_key_count
;
740 echo_truncate (before_command_echo_length_1
);
741 before_command_restore_flag
= 0;
744 if (this_command_key_count
>= size
)
746 Lisp_Object new_keys
;
748 new_keys
= Fmake_vector (make_number (size
* 2), Qnil
);
749 bcopy (XVECTOR (this_command_keys
)->contents
,
750 XVECTOR (new_keys
)->contents
,
751 size
* sizeof (Lisp_Object
));
753 this_command_keys
= new_keys
;
756 XVECTOR (this_command_keys
)->contents
[this_command_key_count
++] = key
;
762 int count
= specpdl_ptr
- specpdl
;
765 if (command_loop_level
> 0)
767 specbind (Qstandard_output
, Qt
);
768 specbind (Qstandard_input
, Qt
);
771 val
= command_loop ();
773 Fsignal (Qquit
, Qnil
);
774 /* Handle throw from read_minibuf when using minibuffer
775 while it's active but we're in another window. */
777 Fsignal (Qerror
, Fcons (val
, Qnil
));
779 return unbind_to (count
, Qnil
);
782 /* When an auto-save happens, record the "time", and don't do again soon. */
787 last_auto_save
= num_nonmacro_input_events
;
790 /* Make an auto save happen as soon as possible at command level. */
792 force_auto_save_soon ()
794 last_auto_save
= - auto_save_interval
- 1;
796 record_asynch_buffer_change ();
799 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
800 "Invoke the editor command loop recursively.\n\
801 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
802 that tells this function to return.\n\
803 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
804 This function is called by the editor initialization to begin editing.")
807 int count
= specpdl_ptr
- specpdl
;
810 command_loop_level
++;
811 update_mode_lines
= 1;
813 record_unwind_protect (recursive_edit_unwind
,
815 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
819 return unbind_to (count
, Qnil
);
823 recursive_edit_unwind (buffer
)
827 Fset_buffer (buffer
);
829 command_loop_level
--;
830 update_mode_lines
= 1;
838 #if 0 /* Theory: if there's anything in Vunread_command_events,
839 it will right away be read by read_key_sequence,
840 and then if we do switch KBOARDS, it will go into the side
841 queue then. So we don't need to do anything special here -- rms. */
842 if (CONSP (Vunread_command_events
))
844 current_kboard
->kbd_queue
845 = nconc2 (Vunread_command_events
, current_kboard
->kbd_queue
);
846 current_kboard
->kbd_queue_has_data
= 1;
848 Vunread_command_events
= Qnil
;
854 /* Switch to the single-kboard state, making current_kboard
855 the only KBOARD from which further input is accepted. */
858 single_kboard_state ()
865 /* Maintain a stack of kboards, so other parts of Emacs
866 can switch temporarily to the kboard of a given frame
867 and then revert to the previous status. */
872 struct kboard_stack
*next
;
875 static struct kboard_stack
*kboard_stack
;
878 push_frame_kboard (f
)
882 struct kboard_stack
*p
883 = (struct kboard_stack
*) xmalloc (sizeof (struct kboard_stack
));
885 p
->next
= kboard_stack
;
886 p
->kboard
= current_kboard
;
889 current_kboard
= FRAME_KBOARD (f
);
897 struct kboard_stack
*p
= kboard_stack
;
898 current_kboard
= p
->kboard
;
899 kboard_stack
= p
->next
;
904 /* Handle errors that are not handled at inner levels
905 by printing an error message and returning to the editor command loop. */
911 Lisp_Object old_level
, old_length
;
914 if (!NILP (executing_macro
))
916 if (executing_macro_iterations
== 1)
917 sprintf (macroerror
, "After 1 kbd macro iteration: ");
919 sprintf (macroerror
, "After %d kbd macro iterations: ",
920 executing_macro_iterations
);
925 Vstandard_output
= Qt
;
926 Vstandard_input
= Qt
;
927 Vexecuting_macro
= Qnil
;
928 executing_macro
= Qnil
;
929 current_kboard
->Vprefix_arg
= Qnil
;
932 /* Avoid unquittable loop if data contains a circular list. */
933 old_level
= Vprint_level
;
934 old_length
= Vprint_length
;
935 XSETFASTINT (Vprint_level
, 10);
936 XSETFASTINT (Vprint_length
, 10);
937 cmd_error_internal (data
, macroerror
);
938 Vprint_level
= old_level
;
939 Vprint_length
= old_length
;
943 Vinhibit_quit
= Qnil
;
948 return make_number (0);
951 /* Take actions on handling an error. DATA is the data that describes
954 CONTEXT is a C-string containing ASCII characters only which
955 describes the context in which the error happened. If we need to
956 generalize CONTEXT to allow multibyte characters, make it a Lisp
960 cmd_error_internal (data
, context
)
968 echo_area_glyphs
= 0;
970 /* If the window system or terminal frame hasn't been initialized
971 yet, or we're not interactive, it's best to dump this message out
972 to stderr and exit. */
973 if (! FRAME_MESSAGE_BUF (selected_frame
)
975 stream
= Qexternal_debugging_output
;
984 write_string_1 (context
, -1, stream
);
986 print_error_message (data
, stream
);
988 /* If the window system or terminal frame hasn't been initialized
989 yet, or we're in -batch mode, this error should cause Emacs to exit. */
990 if (! FRAME_MESSAGE_BUF (selected_frame
)
994 Fkill_emacs (make_number (-1));
998 Lisp_Object
command_loop_1 ();
999 Lisp_Object
command_loop_2 ();
1000 Lisp_Object
top_level_1 ();
1002 /* Entry to editor-command-loop.
1003 This level has the catches for exiting/returning to editor command loop.
1004 It returns nil to exit recursive edit, t to abort it. */
1009 if (command_loop_level
> 0 || minibuf_level
> 0)
1011 return internal_catch (Qexit
, command_loop_2
, Qnil
);
1016 internal_catch (Qtop_level
, top_level_1
, Qnil
);
1017 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
1019 /* End of file in -batch run causes exit here. */
1025 /* Here we catch errors in execution of commands within the
1026 editing loop, and reenter the editing loop.
1027 When there is an error, cmd_error runs and returns a non-nil
1028 value to us. A value of nil means that cmd_loop_1 itself
1029 returned due to end of file (or end of kbd macro). */
1034 register Lisp_Object val
;
1037 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
1038 while (!NILP (val
));
1046 return Feval (Vtop_level
);
1052 /* On entry to the outer level, run the startup file */
1053 if (!NILP (Vtop_level
))
1054 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
1055 else if (!NILP (Vpurify_flag
))
1056 message ("Bare impure Emacs (standard Lisp code not loaded)");
1058 message ("Bare Emacs (standard Lisp code not loaded)");
1062 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
1063 "Exit all recursive editing levels.")
1066 Fthrow (Qtop_level
, Qnil
);
1069 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
1070 "Exit from the innermost recursive edit or minibuffer.")
1073 if (command_loop_level
> 0 || minibuf_level
> 0)
1074 Fthrow (Qexit
, Qnil
);
1076 error ("No recursive edit is in progress");
1079 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
1080 "Abort the command that requested this recursive edit or minibuffer input.")
1083 if (command_loop_level
> 0 || minibuf_level
> 0)
1086 error ("No recursive edit is in progress");
1089 /* This is the actual command reading loop,
1090 sans error-handling encapsulation. */
1092 Lisp_Object
Fcommand_execute ();
1093 static int read_key_sequence ();
1094 void safe_run_hooks ();
1099 Lisp_Object cmd
, tem
;
1102 Lisp_Object keybuf
[30];
1107 struct buffer
*prev_buffer
;
1109 int was_locked
= single_kboard
;
1112 current_kboard
->Vprefix_arg
= Qnil
;
1113 Vdeactivate_mark
= Qnil
;
1114 waiting_for_input
= 0;
1119 this_command_key_count
= 0;
1120 this_single_command_key_start
= 0;
1122 /* Make sure this hook runs after commands that get errors and
1123 throw to top level. */
1124 /* Note that the value cell will never directly contain nil
1125 if the symbol is a local variable. */
1126 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1127 safe_run_hooks (Qpost_command_hook
);
1129 if (!NILP (Vdeferred_action_list
))
1130 call0 (Vdeferred_action_function
);
1132 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1134 if (NILP (Vunread_command_events
)
1135 && NILP (Vexecuting_macro
)
1136 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1, 1)))
1137 safe_run_hooks (Qpost_command_idle_hook
);
1140 /* Do this after running Vpost_command_hook, for consistency. */
1141 current_kboard
->Vlast_command
= this_command
;
1145 /* Make sure the current window's buffer is selected. */
1146 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1147 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1149 /* Display any malloc warning that just came out. Use while because
1150 displaying one warning can cause another. */
1152 while (pending_malloc_warning
)
1153 display_malloc_warning ();
1157 Vdeactivate_mark
= Qnil
;
1159 /* If minibuffer on and echo area in use,
1160 wait 2 sec and redraw minibuffer. */
1162 if (minibuf_level
&& echo_area_glyphs
1163 && EQ (minibuf_window
, echo_area_window
))
1165 /* Bind inhibit-quit to t so that C-g gets read in
1166 rather than quitting back to the minibuffer. */
1167 int count
= specpdl_ptr
- specpdl
;
1168 specbind (Qinhibit_quit
, Qt
);
1170 Fsit_for (make_number (2), Qnil
, Qnil
);
1171 /* Clear the echo area. */
1173 safe_run_hooks (Qecho_area_clear_hook
);
1175 unbind_to (count
, Qnil
);
1177 /* If a C-g came in before, treat it as input now. */
1178 if (!NILP (Vquit_flag
))
1181 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1186 alloca (0); /* Cause a garbage collection now */
1187 /* Since we can free the most stuff here. */
1188 #endif /* C_ALLOCA */
1191 /* Select the frame that the last event came from. Usually,
1192 switch-frame events will take care of this, but if some lisp
1193 code swallows a switch-frame event, we'll fix things up here.
1194 Is this a good idea? */
1195 if (FRAMEP (internal_last_event_frame
)
1196 && XFRAME (internal_last_event_frame
) != selected_frame
)
1197 Fselect_frame (internal_last_event_frame
, Qnil
);
1199 /* If it has changed current-menubar from previous value,
1200 really recompute the menubar from the value. */
1201 if (! NILP (Vlucid_menu_bar_dirty_flag
)
1202 && !NILP (Ffboundp (Qrecompute_lucid_menubar
)))
1203 call0 (Qrecompute_lucid_menubar
);
1205 before_command_key_count
= this_command_key_count
;
1206 before_command_echo_length
= echo_length ();
1208 this_command
= Qnil
;
1210 /* Read next key sequence; i gets its length. */
1211 i
= read_key_sequence (keybuf
, sizeof keybuf
/ sizeof keybuf
[0],
1214 /* A filter may have run while we were reading the input. */
1215 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1216 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1220 /* Now we have read a key sequence of length I,
1221 or else I is 0 and we found end of file. */
1223 if (i
== 0) /* End of file -- happens only in */
1224 return Qnil
; /* a kbd macro, at the end. */
1225 /* -1 means read_key_sequence got a menu that was rejected.
1226 Just loop around and read another command. */
1230 this_command_key_count
= 0;
1231 this_single_command_key_start
= 0;
1235 last_command_char
= keybuf
[i
- 1];
1237 /* If the previous command tried to force a specific window-start,
1238 forget about that, in case this command moves point far away
1239 from that position. But also throw away beg_unchanged and
1240 end_unchanged information in that case, so that redisplay will
1241 update the whole window properly. */
1242 if (!NILP (XWINDOW (selected_window
)->force_start
))
1244 XWINDOW (selected_window
)->force_start
= Qnil
;
1245 beg_unchanged
= end_unchanged
= 0;
1248 cmd
= read_key_sequence_cmd
;
1249 if (!NILP (Vexecuting_macro
))
1251 if (!NILP (Vquit_flag
))
1253 Vexecuting_macro
= Qt
;
1254 QUIT
; /* Make some noise. */
1255 /* Will return since macro now empty. */
1259 /* Do redisplay processing after this command except in special
1260 cases identified below that set no_redisplay to 1.
1261 (actually, there's currently no way to prevent the redisplay,
1262 and no_redisplay is ignored.
1263 Perhaps someday we will really implement it.) */
1266 prev_buffer
= current_buffer
;
1267 prev_modiff
= MODIFF
;
1268 last_point_position
= PT
;
1269 XSETBUFFER (last_point_position_buffer
, prev_buffer
);
1271 /* Execute the command. */
1274 /* Note that the value cell will never directly contain nil
1275 if the symbol is a local variable. */
1276 if (!NILP (Vpre_command_hook
) && !NILP (Vrun_hooks
))
1277 safe_run_hooks (Qpre_command_hook
);
1279 if (NILP (this_command
))
1281 /* nil means key is undefined. */
1283 current_kboard
->defining_kbd_macro
= Qnil
;
1284 update_mode_lines
= 1;
1285 current_kboard
->Vprefix_arg
= Qnil
;
1289 if (NILP (current_kboard
->Vprefix_arg
) && ! no_direct
)
1291 /* Recognize some common commands in common situations and
1292 do them directly. */
1293 if (EQ (this_command
, Qforward_char
) && PT
< ZV
)
1295 struct Lisp_Char_Table
*dp
1296 = window_display_table (XWINDOW (selected_window
));
1297 lose
= FETCH_BYTE (PT_BYTE
);
1300 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1301 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1302 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1303 && (lose
>= 0x20 && lose
< 0x7f)))
1304 : (lose
>= 0x20 && lose
< 0x7f))
1305 /* To extract the case of continuation on
1306 wide-column characters. */
1307 && (WIDTH_BY_CHAR_HEAD (FETCH_BYTE (PT_BYTE
)) == 1)
1308 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1310 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1312 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1314 && !windows_or_buffers_changed
1315 && EQ (current_buffer
->selective_display
, Qnil
)
1316 && !detect_input_pending ()
1317 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1318 && NILP (Vexecuting_macro
))
1319 no_redisplay
= direct_output_forward_char (1);
1322 else if (EQ (this_command
, Qbackward_char
) && PT
> BEGV
)
1324 struct Lisp_Char_Table
*dp
1325 = window_display_table (XWINDOW (selected_window
));
1327 lose
= FETCH_BYTE (PT_BYTE
);
1329 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1330 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1331 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1332 && (lose
>= 0x20 && lose
< 0x7f)))
1333 : (lose
>= 0x20 && lose
< 0x7f))
1334 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1336 && (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1338 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1340 && !windows_or_buffers_changed
1341 && EQ (current_buffer
->selective_display
, Qnil
)
1342 && !detect_input_pending ()
1343 && NILP (XWINDOW (selected_window
)->column_number_displayed
)
1344 && NILP (Vexecuting_macro
))
1345 no_redisplay
= direct_output_forward_char (-1);
1348 else if (EQ (this_command
, Qself_insert_command
)
1349 /* Try this optimization only on ascii keystrokes. */
1350 && INTEGERP (last_command_char
))
1352 unsigned int c
= XINT (last_command_char
);
1355 if (NILP (Vexecuting_macro
)
1356 && !EQ (minibuf_window
, selected_window
))
1358 if (!nonundocount
|| nonundocount
>= 20)
1365 lose
= ((XFASTINT (XWINDOW (selected_window
)->last_modified
)
1367 || (XFASTINT (XWINDOW (selected_window
)->last_overlay_modified
)
1369 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1371 || MODIFF
<= SAVE_MODIFF
1372 || windows_or_buffers_changed
1373 || !EQ (current_buffer
->selective_display
, Qnil
)
1374 || detect_input_pending ()
1375 || !NILP (XWINDOW (selected_window
)->column_number_displayed
)
1376 || !NILP (Vexecuting_macro
));
1377 value
= internal_self_insert (c
, 0);
1384 && (PT
== ZV
|| FETCH_BYTE (PT_BYTE
) == '\n'))
1386 struct Lisp_Char_Table
*dp
1387 = window_display_table (XWINDOW (selected_window
));
1390 /* Add the offset to the character, for Finsert_char.
1391 We pass internal_self_insert the unmodified character
1392 because it itself does this offsetting. */
1393 if (lose
>= 0200 && lose
<= 0377
1394 && ! NILP (current_buffer
->enable_multibyte_characters
))
1395 lose
+= nonascii_insert_offset
;
1401 obj
= DISP_CHAR_VECTOR (dp
, lose
);
1404 /* Do it only for char codes
1405 that by default display as themselves. */
1406 if (lose
>= 0x20 && lose
<= 0x7e)
1407 no_redisplay
= direct_output_for_insert (lose
);
1409 else if (VECTORP (obj
)
1410 && XVECTOR (obj
)->size
== 1
1411 && (obj
= XVECTOR (obj
)->contents
[0],
1413 /* Insist face not specified in glyph. */
1414 && (XINT (obj
) & ((-1) << 8)) == 0)
1416 = direct_output_for_insert (XINT (obj
));
1420 if (lose
>= 0x20 && lose
<= 0x7e)
1421 no_redisplay
= direct_output_for_insert (lose
);
1428 /* Here for a command that isn't executed directly */
1431 if (NILP (current_kboard
->Vprefix_arg
))
1433 Fcommand_execute (this_command
, Qnil
, Qnil
, Qnil
);
1438 /* If there is a prefix argument,
1439 1) We don't want Vlast_command to be ``universal-argument''
1440 (that would be dumb), so don't set Vlast_command,
1441 2) we want to leave echoing on so that the prefix will be
1442 echoed as part of this key sequence, so don't call
1444 3) we want to leave this_command_key_count non-zero, so that
1445 read_char will realize that it is re-reading a character, and
1446 not echo it a second time.
1448 If the command didn't actually create a prefix arg,
1449 but is merely a frame event that is transparent to prefix args,
1450 then the above doesn't apply. */
1451 if (NILP (current_kboard
->Vprefix_arg
) || CONSP (last_command_char
))
1453 current_kboard
->Vlast_command
= this_command
;
1455 this_command_key_count
= 0;
1456 this_single_command_key_start
= 0;
1459 /* Note that the value cell will never directly contain nil
1460 if the symbol is a local variable. */
1461 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1462 safe_run_hooks (Qpost_command_hook
);
1464 if (!NILP (Vdeferred_action_list
))
1465 safe_run_hooks (Qdeferred_action_function
);
1467 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1469 if (NILP (Vunread_command_events
)
1470 && NILP (Vexecuting_macro
)
1471 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1, 1)))
1472 safe_run_hooks (Qpost_command_idle_hook
);
1475 if (!NILP (current_buffer
->mark_active
) && !NILP (Vrun_hooks
))
1477 if (!NILP (Vdeactivate_mark
) && !NILP (Vtransient_mark_mode
))
1479 current_buffer
->mark_active
= Qnil
;
1480 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
1482 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
1483 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
1487 /* Install chars successfully executed in kbd macro. */
1489 if (!NILP (current_kboard
->defining_kbd_macro
)
1490 && NILP (current_kboard
->Vprefix_arg
))
1491 finalize_kbd_macro_chars ();
1495 any_kboard_state ();
1500 /* Subroutine for safe_run_hooks: run the hook HOOK. */
1503 safe_run_hooks_1 (hook
)
1506 return call1 (Vrun_hooks
, Vinhibit_quit
);
1509 /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */
1512 safe_run_hooks_error (data
)
1515 Fset (Vinhibit_quit
, Qnil
);
1518 /* If we get an error while running the hook, cause the hook variable
1519 to be nil. Also inhibit quits, so that C-g won't cause the hook
1520 to mysteriously evaporate. */
1523 safe_run_hooks (hook
)
1527 int count
= specpdl_ptr
- specpdl
;
1528 specbind (Qinhibit_quit
, hook
);
1530 internal_condition_case (safe_run_hooks_1
, Qt
, safe_run_hooks_error
);
1532 unbind_to (count
, Qnil
);
1535 /* Number of seconds between polling for input. */
1538 /* Nonzero means polling for input is temporarily suppressed. */
1539 int poll_suppress_count
;
1541 /* Nonzero if polling_for_input is actually being used. */
1542 int polling_for_input
;
1544 #ifdef POLL_FOR_INPUT
1546 /* Handle an alarm once each second and read pending input
1547 so as to handle a C-g if it comces in. */
1550 input_poll_signal (signalnum
) /* If we don't have an argument, */
1551 int signalnum
; /* some compilers complain in signal calls. */
1553 /* This causes the call to start_polling at the end
1554 to do its job. It also arranges for a quit or error
1555 from within read_avail_input to resume polling. */
1556 poll_suppress_count
++;
1557 if (interrupt_input_blocked
== 0
1558 && !waiting_for_input
)
1559 read_avail_input (0);
1560 /* Turn on the SIGALRM handler and request another alarm. */
1566 /* Begin signals to poll for input, if they are appropriate.
1567 This function is called unconditionally from various places. */
1572 #ifdef POLL_FOR_INPUT
1573 if (read_socket_hook
&& !interrupt_input
)
1575 poll_suppress_count
--;
1576 if (poll_suppress_count
== 0)
1578 signal (SIGALRM
, input_poll_signal
);
1579 polling_for_input
= 1;
1580 alarm (polling_period
);
1586 /* Nonzero if we are using polling to handle input asynchronously. */
1589 input_polling_used ()
1591 #ifdef POLL_FOR_INPUT
1592 return read_socket_hook
&& !interrupt_input
;
1598 /* Turn off polling. */
1603 #ifdef POLL_FOR_INPUT
1604 if (read_socket_hook
&& !interrupt_input
)
1606 if (poll_suppress_count
== 0)
1608 polling_for_input
= 0;
1611 poll_suppress_count
++;
1616 /* Set the value of poll_suppress_count to COUNT
1617 and start or stop polling accordingly. */
1620 set_poll_suppress_count (count
)
1623 #ifdef POLL_FOR_INPUT
1624 if (count
== 0 && poll_suppress_count
!= 0)
1626 poll_suppress_count
= 1;
1629 else if (count
!= 0 && poll_suppress_count
== 0)
1633 poll_suppress_count
= count
;
1637 /* Bind polling_period to a value at least N.
1638 But don't decrease it. */
1641 bind_polling_period (n
)
1644 #ifdef POLL_FOR_INPUT
1645 int new = polling_period
;
1651 specbind (Qpolling_period
, make_number (new));
1652 /* Start a new alarm with the new period. */
1657 /* Apply the control modifier to CHARACTER. */
1663 /* Save the upper bits here. */
1664 int upper
= c
& ~0177;
1668 /* Everything in the columns containing the upper-case letters
1669 denotes a control character. */
1670 if (c
>= 0100 && c
< 0140)
1674 /* Set the shift modifier for a control char
1675 made from a shifted letter. But only for letters! */
1676 if (oc
>= 'A' && oc
<= 'Z')
1677 c
|= shift_modifier
;
1680 /* The lower-case letters denote control characters too. */
1681 else if (c
>= 'a' && c
<= 'z')
1684 /* Include the bits for control and shift
1685 only if the basic ASCII code can't indicate them. */
1689 /* Replace the high bits. */
1690 c
|= (upper
& ~ctrl_modifier
);
1697 /* Input of single characters from keyboard */
1699 Lisp_Object
print_help ();
1700 static Lisp_Object
kbd_buffer_get_event ();
1701 static void record_char ();
1704 static jmp_buf wrong_kboard_jmpbuf
;
1707 /* read a character from the keyboard; call the redisplay if needed */
1708 /* commandflag 0 means do not do auto-saving, but do do redisplay.
1709 -1 means do not do redisplay, but do do autosaving.
1712 /* The arguments MAPS and NMAPS are for menu prompting.
1713 MAPS is an array of keymaps; NMAPS is the length of MAPS.
1715 PREV_EVENT is the previous input event, or nil if we are reading
1716 the first event of a key sequence.
1718 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
1719 if we used a mouse menu to read the input, or zero otherwise. If
1720 USED_MOUSE_MENU is null, we don't dereference it.
1722 Value is t if we showed a menu and the user rejected it. */
1725 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
)
1729 Lisp_Object prev_event
;
1730 int *used_mouse_menu
;
1734 jmp_buf local_getcjmp
;
1736 int key_already_recorded
= 0;
1737 Lisp_Object tem
, save
;
1738 Lisp_Object also_record
;
1739 struct gcpro gcpro1
;
1743 before_command_key_count
= this_command_key_count
;
1744 before_command_echo_length
= echo_length ();
1751 if (CONSP (Vunread_command_events
))
1753 c
= XCONS (Vunread_command_events
)->car
;
1754 Vunread_command_events
= XCONS (Vunread_command_events
)->cdr
;
1756 /* Undo what read_char_x_menu_prompt did when it unread
1757 additional keys returned by Fx_popup_menu. */
1759 && (SYMBOLP (XCONS (c
)->car
) || INTEGERP (XCONS (c
)->car
))
1760 && NILP (XCONS (c
)->cdr
))
1763 if (this_command_key_count
== 0)
1769 if (unread_command_char
!= -1)
1771 XSETINT (c
, unread_command_char
);
1772 unread_command_char
= -1;
1774 if (this_command_key_count
== 0)
1780 /* If there is no function key translated before
1781 reset-this-command-lengths takes effect, forget about it. */
1782 before_command_restore_flag
= 0;
1784 if (!NILP (Vexecuting_macro
))
1786 /* We set this to Qmacro; since that's not a frame, nobody will
1787 try to switch frames on us, and the selected window will
1790 Since this event came from a macro, it would be misleading to
1791 leave internal_last_event_frame set to wherever the last
1792 real event came from. Normally, a switch-frame event selects
1793 internal_last_event_frame after each command is read, but
1794 events read from a macro should never cause a new frame to be
1796 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
1798 /* Exit the macro if we are at the end.
1799 Also, some things replace the macro with t
1800 to force an early exit. */
1801 if (EQ (Vexecuting_macro
, Qt
)
1802 || executing_macro_index
>= XFASTINT (Flength (Vexecuting_macro
)))
1808 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
1809 if (STRINGP (Vexecuting_macro
)
1810 && (XINT (c
) & 0x80))
1811 XSETFASTINT (c
, CHAR_META
| (XINT (c
) & ~0x80));
1813 executing_macro_index
++;
1818 if (!NILP (unread_switch_frame
))
1820 c
= unread_switch_frame
;
1821 unread_switch_frame
= Qnil
;
1823 /* This event should make it into this_command_keys, and get echoed
1824 again, so we go to reread_first, rather than reread. */
1828 if (commandflag
>= 0)
1831 || detect_input_pending_run_timers (0))
1838 /* Message turns off echoing unless more keystrokes turn it on again. */
1839 if (echo_area_glyphs
&& *echo_area_glyphs
1840 && echo_area_glyphs
!= current_kboard
->echobuf
1841 && ok_to_echo_at_next_pause
!= echo_area_glyphs
)
1844 /* If already echoing, continue. */
1847 /* Try reading a character via menu prompting in the minibuf.
1848 Try this before the sit-for, because the sit-for
1849 would do the wrong thing if we are supposed to do
1850 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
1851 after a mouse event so don't try a minibuf menu. */
1853 if (nmaps
> 0 && INTERACTIVE
1854 && !NILP (prev_event
) && ! EVENT_HAS_PARAMETERS (prev_event
)
1855 /* Don't bring up a menu if we already have another event. */
1856 && NILP (Vunread_command_events
)
1857 && unread_command_char
< 0
1858 && !detect_input_pending_run_timers (0))
1860 c
= read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
);
1863 key_already_recorded
= 1;
1868 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet.
1869 We will do that below, temporarily for short sections of code,
1870 when appropriate. local_getcjmp must be in effect
1871 around any call to sit_for or kbd_buffer_get_event;
1872 it *must not* be in effect when we call redisplay. */
1874 if (_setjmp (local_getcjmp
))
1876 XSETINT (c
, quit_char
);
1877 XSETFRAME (internal_last_event_frame
, selected_frame
);
1878 Vlast_event_frame
= internal_last_event_frame
;
1879 /* If we report the quit char as an event,
1880 don't do so more than once. */
1881 if (!NILP (Vinhibit_quit
))
1886 KBOARD
*kb
= FRAME_KBOARD (selected_frame
);
1887 if (kb
!= current_kboard
)
1889 Lisp_Object
*tailp
= &kb
->kbd_queue
;
1890 /* We shouldn't get here if we were in single-kboard mode! */
1893 while (CONSP (*tailp
))
1894 tailp
= &XCONS (*tailp
)->cdr
;
1897 *tailp
= Fcons (c
, Qnil
);
1898 kb
->kbd_queue_has_data
= 1;
1899 current_kboard
= kb
;
1900 /* This is going to exit from read_char
1901 so we had better get rid of this frame's stuff. */
1903 longjmp (wrong_kboard_jmpbuf
, 1);
1910 timer_start_idle ();
1912 /* If in middle of key sequence and minibuffer not active,
1913 start echoing if enough time elapses. */
1915 if (minibuf_level
== 0 && !current_kboard
->immediate_echo
1916 && this_command_key_count
> 0
1918 && echo_keystrokes
> 0
1919 && (echo_area_glyphs
== 0 || *echo_area_glyphs
== 0
1920 || ok_to_echo_at_next_pause
== echo_area_glyphs
))
1924 /* After a mouse event, start echoing right away.
1925 This is because we are probably about to display a menu,
1926 and we don't want to delay before doing so. */
1927 if (EVENT_HAS_PARAMETERS (prev_event
))
1931 save_getcjmp (save_jump
);
1932 restore_getcjmp (local_getcjmp
);
1933 tem0
= sit_for (echo_keystrokes
, 0, 1, 1, 0);
1934 restore_getcjmp (save_jump
);
1936 && ! CONSP (Vunread_command_events
))
1941 /* Maybe auto save due to number of keystrokes. */
1943 if (commandflag
!= 0
1944 && auto_save_interval
> 0
1945 && num_nonmacro_input_events
- last_auto_save
> max (auto_save_interval
, 20)
1946 && !detect_input_pending_run_timers (0))
1948 Fdo_auto_save (Qnil
, Qnil
);
1949 /* Hooks can actually change some buffers in auto save. */
1953 /* Try reading using an X menu.
1954 This is never confused with reading using the minibuf
1955 because the recursive call of read_char in read_char_minibuf_menu_prompt
1956 does not pass on any keymaps. */
1958 if (nmaps
> 0 && INTERACTIVE
1959 && !NILP (prev_event
)
1960 && EVENT_HAS_PARAMETERS (prev_event
)
1961 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
)
1962 /* Don't bring up a menu if we already have another event. */
1963 && NILP (Vunread_command_events
)
1964 && unread_command_char
< 0)
1966 c
= read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
1968 /* Now that we have read an event, Emacs is not idle. */
1974 /* Maybe autosave and/or garbage collect due to idleness. */
1976 if (INTERACTIVE
&& NILP (c
))
1978 int delay_level
, buffer_size
;
1980 /* Slow down auto saves logarithmically in size of current buffer,
1981 and garbage collect while we're at it. */
1982 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
1983 last_non_minibuf_size
= Z
- BEG
;
1984 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
1986 while (buffer_size
> 64)
1987 delay_level
++, buffer_size
-= buffer_size
>> 2;
1988 if (delay_level
< 4) delay_level
= 4;
1989 /* delay_level is 4 for files under around 50k, 7 at 100k,
1990 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
1992 /* Auto save if enough time goes by without input. */
1993 if (commandflag
!= 0
1994 && num_nonmacro_input_events
> last_auto_save
1995 && INTEGERP (Vauto_save_timeout
)
1996 && XINT (Vauto_save_timeout
) > 0)
2000 save_getcjmp (save_jump
);
2001 restore_getcjmp (local_getcjmp
);
2002 tem0
= sit_for (delay_level
* XFASTINT (Vauto_save_timeout
) / 4,
2004 restore_getcjmp (save_jump
);
2007 && ! CONSP (Vunread_command_events
))
2009 Fdo_auto_save (Qnil
, Qnil
);
2011 /* If we have auto-saved and there is still no input
2012 available, garbage collect if there has been enough
2013 consing going on to make it worthwhile. */
2014 if (!detect_input_pending_run_timers (0)
2015 && consing_since_gc
> gc_cons_threshold
/ 2)
2016 Fgarbage_collect ();
2023 /* If this has become non-nil here, it has been set by a timer
2024 or sentinel or filter. */
2025 if (CONSP (Vunread_command_events
))
2027 c
= XCONS (Vunread_command_events
)->car
;
2028 Vunread_command_events
= XCONS (Vunread_command_events
)->cdr
;
2031 /* Read something from current KBOARD's side queue, if possible. */
2035 if (current_kboard
->kbd_queue_has_data
)
2037 if (!CONSP (current_kboard
->kbd_queue
))
2039 c
= XCONS (current_kboard
->kbd_queue
)->car
;
2040 current_kboard
->kbd_queue
2041 = XCONS (current_kboard
->kbd_queue
)->cdr
;
2042 if (NILP (current_kboard
->kbd_queue
))
2043 current_kboard
->kbd_queue_has_data
= 0;
2044 input_pending
= readable_events (0);
2045 if (EVENT_HAS_PARAMETERS (c
)
2046 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qswitch_frame
))
2047 internal_last_event_frame
= XCONS (XCONS (c
)->cdr
)->car
;
2048 Vlast_event_frame
= internal_last_event_frame
;
2053 /* If current_kboard's side queue is empty check the other kboards.
2054 If one of them has data that we have not yet seen here,
2055 switch to it and process the data waiting for it.
2057 Note: if the events queued up for another kboard
2058 have already been seen here, and therefore are not a complete command,
2059 the kbd_queue_has_data field is 0, so we skip that kboard here.
2060 That's to avoid an infinite loop switching between kboards here. */
2061 if (NILP (c
) && !single_kboard
)
2064 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2065 if (kb
->kbd_queue_has_data
)
2067 current_kboard
= kb
;
2068 /* This is going to exit from read_char
2069 so we had better get rid of this frame's stuff. */
2071 longjmp (wrong_kboard_jmpbuf
, 1);
2080 /* Finally, we read from the main queue,
2081 and if that gives us something we can't use yet, we put it on the
2082 appropriate side queue and try again. */
2088 /* Actually read a character, waiting if necessary. */
2089 save_getcjmp (save_jump
);
2090 restore_getcjmp (local_getcjmp
);
2091 c
= kbd_buffer_get_event (&kb
, used_mouse_menu
);
2092 restore_getcjmp (save_jump
);
2095 if (! NILP (c
) && (kb
!= current_kboard
))
2097 Lisp_Object
*tailp
= &kb
->kbd_queue
;
2098 while (CONSP (*tailp
))
2099 tailp
= &XCONS (*tailp
)->cdr
;
2102 *tailp
= Fcons (c
, Qnil
);
2103 kb
->kbd_queue_has_data
= 1;
2107 current_kboard
= kb
;
2108 /* This is going to exit from read_char
2109 so we had better get rid of this frame's stuff. */
2111 longjmp (wrong_kboard_jmpbuf
, 1);
2116 /* Terminate Emacs in batch mode if at eof. */
2117 if (noninteractive
&& INTEGERP (c
) && XINT (c
) < 0)
2118 Fkill_emacs (make_number (1));
2122 /* Add in any extra modifiers, where appropriate. */
2123 if ((extra_keyboard_modifiers
& CHAR_CTL
)
2124 || ((extra_keyboard_modifiers
& 0177) < ' '
2125 && (extra_keyboard_modifiers
& 0177) != 0))
2126 XSETINT (c
, make_ctrl_char (XINT (c
)));
2128 /* Transfer any other modifier bits directly from
2129 extra_keyboard_modifiers to c. Ignore the actual character code
2130 in the low 16 bits of extra_keyboard_modifiers. */
2131 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
2142 if (commandflag
>= 0
2143 && !input_pending
&& !detect_input_pending_run_timers (0))
2151 /* Buffer switch events are only for internal wakeups
2152 so don't show them to the user.
2153 Also, don't record a key if we already did. */
2154 if (BUFFERP (c
) || key_already_recorded
)
2157 /* Process special events within read_char
2158 and loop around to read another event. */
2161 tem
= get_keyelt (access_keymap (get_keymap_1 (Vspecial_event_map
, 0, 0),
2167 int was_locked
= single_kboard
;
2169 last_input_char
= c
;
2170 Fcommand_execute (tem
, Qnil
, Fvector (1, &last_input_char
), Qt
);
2172 /* Resume allowing input from any kboard, if that was true before. */
2174 any_kboard_state ();
2179 /* Wipe the echo area. */
2180 if (echo_area_glyphs
)
2181 safe_run_hooks (Qecho_area_clear_hook
);
2182 echo_area_glyphs
= 0;
2184 /* Handle things that only apply to characters. */
2187 /* If kbd_buffer_get_event gave us an EOF, return that. */
2191 if ((STRINGP (Vkeyboard_translate_table
)
2192 && XSTRING (Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
2193 || (VECTORP (Vkeyboard_translate_table
)
2194 && XVECTOR (Vkeyboard_translate_table
)->size
> (unsigned) XFASTINT (c
))
2195 || (CHAR_TABLE_P (Vkeyboard_translate_table
)
2196 && CHAR_TABLE_ORDINARY_SLOTS
> (unsigned) XFASTINT (c
)))
2199 d
= Faref (Vkeyboard_translate_table
, c
);
2200 /* nil in keyboard-translate-table means no translation. */
2206 /* If this event is a mouse click in the menu bar,
2207 return just menu-bar for now. Modify the mouse click event
2208 so we won't do this twice, then queue it up. */
2209 if (EVENT_HAS_PARAMETERS (c
)
2210 && CONSP (XCONS (c
)->cdr
)
2211 && CONSP (EVENT_START (c
))
2212 && CONSP (XCONS (EVENT_START (c
))->cdr
))
2216 posn
= POSN_BUFFER_POSN (EVENT_START (c
));
2217 /* Handle menu-bar events:
2218 insert the dummy prefix event `menu-bar'. */
2219 if (EQ (posn
, Qmenu_bar
))
2221 /* Change menu-bar to (menu-bar) as the event "position". */
2222 POSN_BUFFER_POSN (EVENT_START (c
)) = Fcons (posn
, Qnil
);
2225 Vunread_command_events
= Fcons (c
, Vunread_command_events
);
2231 if (! NILP (also_record
))
2232 record_char (also_record
);
2237 before_command_key_count
= this_command_key_count
;
2238 before_command_echo_length
= echo_length ();
2240 /* Don't echo mouse motion events. */
2242 && ! (EVENT_HAS_PARAMETERS (c
)
2243 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
2246 if (! NILP (also_record
))
2247 echo_char (also_record
);
2248 /* Once we reread a character, echoing can happen
2249 the next time we pause to read a new one. */
2250 ok_to_echo_at_next_pause
= echo_area_glyphs
;
2253 /* Record this character as part of the current key. */
2254 add_command_key (c
);
2255 if (! NILP (also_record
))
2256 add_command_key (also_record
);
2258 /* Re-reading in the middle of a command */
2260 last_input_char
= c
;
2263 /* Process the help character specially if enabled */
2264 if (!NILP (Vhelp_form
) && help_char_p (c
))
2267 count
= specpdl_ptr
- specpdl
;
2269 record_unwind_protect (Fset_window_configuration
,
2270 Fcurrent_window_configuration (Qnil
));
2272 tem0
= Feval (Vhelp_form
);
2274 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
2278 c
= read_char (0, 0, 0, Qnil
, 0);
2279 while (BUFFERP (c
));
2280 /* Remove the help from the frame */
2281 unbind_to (count
, Qnil
);
2284 if (EQ (c
, make_number (040)))
2288 c
= read_char (0, 0, 0, Qnil
, 0);
2289 while (BUFFERP (c
));
2296 /* Record a key that came from a mouse menu.
2297 Record it for echoing, for this-command-keys, and so on. */
2303 /* Wipe the echo area. */
2304 echo_area_glyphs
= 0;
2308 before_command_key_count
= this_command_key_count
;
2309 before_command_echo_length
= echo_length ();
2311 /* Don't echo mouse motion events. */
2312 if (echo_keystrokes
)
2316 /* Once we reread a character, echoing can happen
2317 the next time we pause to read a new one. */
2318 ok_to_echo_at_next_pause
= 0;
2321 /* Record this character as part of the current key. */
2322 add_command_key (c
);
2324 /* Re-reading in the middle of a command */
2325 last_input_char
= c
;
2329 /* Return 1 if should recognize C as "the help character". */
2337 if (EQ (c
, Vhelp_char
))
2339 for (tail
= Vhelp_event_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
2340 if (EQ (c
, XCONS (tail
)->car
))
2345 /* Record the input event C in various ways. */
2352 XVECTOR (recent_keys
)->contents
[recent_keys_index
] = c
;
2353 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
2354 recent_keys_index
= 0;
2356 /* Write c to the dribble file. If c is a lispy event, write
2357 the event's symbol to the dribble file, in <brackets>. Bleaugh.
2358 If you, dear reader, have a better idea, you've got the source. :-) */
2363 if (XUINT (c
) < 0x100)
2364 putc (XINT (c
), dribble
);
2366 fprintf (dribble
, " 0x%x", (int) XUINT (c
));
2370 Lisp_Object dribblee
;
2372 /* If it's a structured event, take the event header. */
2373 dribblee
= EVENT_HEAD (c
);
2375 if (SYMBOLP (dribblee
))
2377 putc ('<', dribble
);
2378 fwrite (XSYMBOL (dribblee
)->name
->data
, sizeof (char),
2379 XSYMBOL (dribblee
)->name
->size_byte
,
2381 putc ('>', dribble
);
2388 store_kbd_macro_char (c
);
2390 num_nonmacro_input_events
++;
2397 struct buffer
*old
= current_buffer
;
2398 Fprinc (object
, Qnil
);
2399 set_buffer_internal (XBUFFER (Vstandard_output
));
2400 call0 (intern ("help-mode"));
2401 set_buffer_internal (old
);
2405 /* Copy out or in the info on where C-g should throw to.
2406 This is used when running Lisp code from within get_char,
2407 in case get_char is called recursively.
2408 See read_process_output. */
2413 bcopy (getcjmp
, temp
, sizeof getcjmp
);
2416 restore_getcjmp (temp
)
2419 bcopy (temp
, getcjmp
, sizeof getcjmp
);
2424 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
2425 of this function. */
2428 tracking_off (old_value
)
2429 Lisp_Object old_value
;
2431 do_mouse_tracking
= old_value
;
2432 if (NILP (old_value
))
2434 /* Redisplay may have been preempted because there was input
2435 available, and it assumes it will be called again after the
2436 input has been processed. If the only input available was
2437 the sort that we have just disabled, then we need to call
2439 if (!readable_events (1))
2441 redisplay_preserve_echo_area ();
2442 get_input_pending (&input_pending
, 1);
2447 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
2448 "Evaluate BODY with mouse movement events enabled.\n\
2449 Within a `track-mouse' form, mouse motion generates input events that\n\
2450 you can read with `read-event'.\n\
2451 Normally, mouse motion is ignored.")
2455 int count
= specpdl_ptr
- specpdl
;
2458 record_unwind_protect (tracking_off
, do_mouse_tracking
);
2460 do_mouse_tracking
= Qt
;
2462 val
= Fprogn (args
);
2463 return unbind_to (count
, val
);
2466 /* If mouse has moved on some frame, return one of those frames.
2467 Return 0 otherwise. */
2472 Lisp_Object tail
, frame
;
2474 FOR_EACH_FRAME (tail
, frame
)
2476 if (XFRAME (frame
)->mouse_moved
)
2477 return XFRAME (frame
);
2483 #endif /* HAVE_MOUSE */
2485 /* Low level keyboard/mouse input.
2486 kbd_buffer_store_event places events in kbd_buffer, and
2487 kbd_buffer_get_event retrieves them. */
2489 /* Return true iff there are any events in the queue that read-char
2490 would return. If this returns false, a read-char would block. */
2492 readable_events (do_timers_now
)
2496 timer_check (do_timers_now
);
2498 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2501 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2506 if (current_kboard
->kbd_queue_has_data
)
2512 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2513 if (kb
->kbd_queue_has_data
)
2519 /* Set this for debugging, to have a way to get out */
2524 event_to_kboard (event
)
2525 struct input_event
*event
;
2528 frame
= event
->frame_or_window
;
2530 frame
= XCONS (frame
)->car
;
2531 else if (WINDOWP (frame
))
2532 frame
= WINDOW_FRAME (XWINDOW (frame
));
2534 /* There are still some events that don't set this field.
2535 For now, just ignore the problem.
2536 Also ignore dead frames here. */
2537 if (!FRAMEP (frame
) || !FRAME_LIVE_P (XFRAME (frame
)))
2540 return FRAME_KBOARD (XFRAME (frame
));
2544 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
2547 kbd_buffer_store_event (event
)
2548 register struct input_event
*event
;
2550 if (event
->kind
== no_event
)
2553 if (event
->kind
== ascii_keystroke
)
2555 register int c
= event
->code
& 0377;
2557 if (event
->modifiers
& ctrl_modifier
)
2558 c
= make_ctrl_char (c
);
2560 c
|= (event
->modifiers
2561 & (meta_modifier
| alt_modifier
2562 | hyper_modifier
| super_modifier
));
2566 extern SIGTYPE
interrupt_signal ();
2569 struct input_event
*sp
;
2572 && (kb
= FRAME_KBOARD (XFRAME (event
->frame_or_window
)),
2573 kb
!= current_kboard
))
2576 = Fcons (make_lispy_switch_frame (event
->frame_or_window
),
2577 Fcons (make_number (c
), Qnil
));
2578 kb
->kbd_queue_has_data
= 1;
2579 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
2581 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
2584 if (event_to_kboard (sp
) == kb
)
2586 sp
->kind
= no_event
;
2587 sp
->frame_or_window
= Qnil
;
2594 /* If this results in a quit_char being returned to Emacs as
2595 input, set Vlast_event_frame properly. If this doesn't
2596 get returned to Emacs as an event, the next event read
2597 will set Vlast_event_frame again, so this is safe to do. */
2601 focus
= FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
2603 focus
= event
->frame_or_window
;
2604 internal_last_event_frame
= focus
;
2605 Vlast_event_frame
= focus
;
2608 last_event_timestamp
= event
->timestamp
;
2609 interrupt_signal ();
2613 if (c
&& c
== stop_character
)
2619 /* Don't insert two buffer_switch_event's in a row.
2620 Just ignore the second one. */
2621 else if (event
->kind
== buffer_switch_event
2622 && kbd_fetch_ptr
!= kbd_store_ptr
2623 && kbd_store_ptr
->kind
== buffer_switch_event
)
2626 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
2627 kbd_store_ptr
= kbd_buffer
;
2629 /* Don't let the very last slot in the buffer become full,
2630 since that would make the two pointers equal,
2631 and that is indistinguishable from an empty buffer.
2632 Discard the event if it would fill the last slot. */
2633 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
2635 volatile struct input_event
*sp
= kbd_store_ptr
;
2636 sp
->kind
= event
->kind
;
2637 if (event
->kind
== selection_request_event
)
2639 /* We must not use the ordinary copying code for this case,
2640 since `part' is an enum and copying it might not copy enough
2642 bcopy (event
, (char *) sp
, sizeof (*event
));
2646 sp
->code
= event
->code
;
2647 sp
->part
= event
->part
;
2648 sp
->frame_or_window
= event
->frame_or_window
;
2649 sp
->modifiers
= event
->modifiers
;
2652 sp
->timestamp
= event
->timestamp
;
2654 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_store_ptr
2656 = event
->frame_or_window
);
2662 /* Discard any mouse events in the event buffer by setting them to
2665 discard_mouse_events ()
2667 struct input_event
*sp
;
2668 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
2670 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
2673 if (sp
->kind
== mouse_click
2675 || sp
->kind
== w32_scroll_bar_click
2677 || sp
->kind
== scroll_bar_click
)
2679 sp
->kind
= no_event
;
2684 /* Read one event from the event buffer, waiting if necessary.
2685 The value is a Lisp object representing the event.
2686 The value is nil for an event that should be ignored,
2687 or that was handled here.
2688 We always read and discard one event. */
2691 kbd_buffer_get_event (kbp
, used_mouse_menu
)
2693 int *used_mouse_menu
;
2697 EMACS_TIME next_timer_delay
;
2703 *kbp
= current_kboard
;
2707 /* Wait until there is input available. */
2710 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2713 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2717 /* If the quit flag is set, then read_char will return
2718 quit_char, so that counts as "available input." */
2719 if (!NILP (Vquit_flag
))
2720 quit_throw_to_read_char ();
2722 /* One way or another, wait until input is available; then, if
2723 interrupt handlers have not read it, read it now. */
2726 wait_for_kbd_input ();
2728 /* Note SIGIO has been undef'd if FIONREAD is missing. */
2732 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2735 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2739 Lisp_Object minus_one
;
2741 XSETINT (minus_one
, -1);
2742 wait_reading_process_input (0, 0, minus_one
, 1);
2744 if (!interrupt_input
&& kbd_fetch_ptr
== kbd_store_ptr
)
2745 /* Pass 1 for EXPECT since we just waited to have input. */
2746 read_avail_input (1);
2748 #endif /* not VMS */
2751 if (CONSP (Vunread_command_events
))
2754 first
= XCONS (Vunread_command_events
)->car
;
2755 Vunread_command_events
= XCONS (Vunread_command_events
)->cdr
;
2756 *kbp
= current_kboard
;
2760 /* At this point, we know that there is a readable event available
2761 somewhere. If the event queue is empty, then there must be a
2762 mouse movement enabled and available. */
2763 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2765 struct input_event
*event
;
2767 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2771 last_event_timestamp
= event
->timestamp
;
2774 *kbp
= event_to_kboard (event
);
2776 *kbp
= current_kboard
; /* Better than returning null ptr? */
2778 *kbp
= &the_only_kboard
;
2783 /* These two kinds of events get special handling
2784 and don't actually appear to the command loop.
2785 We return nil for them. */
2786 if (event
->kind
== selection_request_event
)
2789 struct input_event copy
;
2791 /* Remove it from the buffer before processing it,
2792 since otherwise swallow_events will see it
2793 and process it again. */
2795 kbd_fetch_ptr
= event
+ 1;
2796 input_pending
= readable_events (0);
2797 x_handle_selection_request (©
);
2799 /* We're getting selection request events, but we don't have
2805 else if (event
->kind
== selection_clear_event
)
2808 struct input_event copy
;
2810 /* Remove it from the buffer before processing it. */
2812 kbd_fetch_ptr
= event
+ 1;
2813 input_pending
= readable_events (0);
2814 x_handle_selection_clear (©
);
2816 /* We're getting selection request events, but we don't have
2821 #if defined (HAVE_X11) || defined (HAVE_NTGUI)
2822 else if (event
->kind
== delete_window_event
)
2824 /* Make an event (delete-frame (FRAME)). */
2825 obj
= Fcons (event
->frame_or_window
, Qnil
);
2826 obj
= Fcons (Qdelete_frame
, Fcons (obj
, Qnil
));
2827 kbd_fetch_ptr
= event
+ 1;
2829 else if (event
->kind
== iconify_event
)
2831 /* Make an event (iconify-frame (FRAME)). */
2832 obj
= Fcons (event
->frame_or_window
, Qnil
);
2833 obj
= Fcons (Qiconify_frame
, Fcons (obj
, Qnil
));
2834 kbd_fetch_ptr
= event
+ 1;
2836 else if (event
->kind
== deiconify_event
)
2838 /* Make an event (make-frame-visible (FRAME)). */
2839 obj
= Fcons (event
->frame_or_window
, Qnil
);
2840 obj
= Fcons (Qmake_frame_visible
, Fcons (obj
, Qnil
));
2841 kbd_fetch_ptr
= event
+ 1;
2844 else if (event
->kind
== buffer_switch_event
)
2846 /* The value doesn't matter here; only the type is tested. */
2847 XSETBUFFER (obj
, current_buffer
);
2848 kbd_fetch_ptr
= event
+ 1;
2850 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
2851 else if (event
->kind
== menu_bar_activate_event
)
2853 kbd_fetch_ptr
= event
+ 1;
2854 input_pending
= readable_events (0);
2855 if (FRAME_LIVE_P (XFRAME (event
->frame_or_window
)))
2856 x_activate_menubar (XFRAME (event
->frame_or_window
));
2859 /* Just discard these, by returning nil.
2860 With MULTI_KBOARD, these events are used as placeholders
2861 when we need to randomly delete events from the queue.
2862 (They shouldn't otherwise be found in the buffer,
2863 but on some machines it appears they do show up
2864 even without MULTI_KBOARD.) */
2865 /* On Windows NT/9X, no_event is used to delete extraneous
2866 mouse events during a popup-menu call. */
2867 else if (event
->kind
== no_event
)
2868 kbd_fetch_ptr
= event
+ 1;
2870 /* If this event is on a different frame, return a switch-frame this
2871 time, and leave the event in the queue for next time. */
2877 frame
= event
->frame_or_window
;
2879 frame
= XCONS (frame
)->car
;
2880 else if (WINDOWP (frame
))
2881 frame
= WINDOW_FRAME (XWINDOW (frame
));
2883 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
2887 if (! EQ (frame
, internal_last_event_frame
)
2888 && XFRAME (frame
) != selected_frame
)
2889 obj
= make_lispy_switch_frame (frame
);
2890 internal_last_event_frame
= frame
;
2892 /* If we didn't decide to make a switch-frame event, go ahead
2893 and build a real event from the queue entry. */
2897 obj
= make_lispy_event (event
);
2898 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
2899 /* If this was a menu selection, then set the flag to inhibit
2900 writing to last_nonmenu_event. Don't do this if the event
2901 we're returning is (menu-bar), though; that indicates the
2902 beginning of the menu sequence, and we might as well leave
2903 that as the `event with parameters' for this selection. */
2904 if (event
->kind
== menu_bar_event
2905 && !(CONSP (obj
) && EQ (XCONS (obj
)->car
, Qmenu_bar
))
2907 *used_mouse_menu
= 1;
2910 /* Wipe out this event, to catch bugs. */
2911 event
->kind
= no_event
;
2912 XVECTOR (kbd_buffer_frame_or_window
)->contents
[event
- kbd_buffer
] = Qnil
;
2914 kbd_fetch_ptr
= event
+ 1;
2919 /* Try generating a mouse motion event. */
2920 else if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2922 FRAME_PTR f
= some_mouse_moved ();
2923 Lisp_Object bar_window
;
2924 enum scroll_bar_part part
;
2928 *kbp
= current_kboard
;
2929 /* Note that this uses F to determine which display to look at.
2930 If there is no valid info, it does not store anything
2931 so x remains nil. */
2933 (*mouse_position_hook
) (&f
, 0, &bar_window
, &part
, &x
, &y
, &time
);
2937 /* Decide if we should generate a switch-frame event. Don't
2938 generate switch-frame events for motion outside of all Emacs
2944 frame
= FRAME_FOCUS_FRAME (f
);
2946 XSETFRAME (frame
, f
);
2948 if (! EQ (frame
, internal_last_event_frame
)
2949 && XFRAME (frame
) != selected_frame
)
2950 obj
= make_lispy_switch_frame (frame
);
2951 internal_last_event_frame
= frame
;
2954 /* If we didn't decide to make a switch-frame event, go ahead and
2955 return a mouse-motion event. */
2956 if (!NILP (x
) && NILP (obj
))
2957 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
2959 #endif /* HAVE_MOUSE */
2961 /* We were promised by the above while loop that there was
2962 something for us to read! */
2965 input_pending
= readable_events (0);
2967 Vlast_event_frame
= internal_last_event_frame
;
2972 /* Process any events that are not user-visible,
2973 then return, without reading any user-visible events. */
2976 swallow_events (do_display
)
2981 while (kbd_fetch_ptr
!= kbd_store_ptr
)
2983 struct input_event
*event
;
2985 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2989 last_event_timestamp
= event
->timestamp
;
2991 /* These two kinds of events get special handling
2992 and don't actually appear to the command loop. */
2993 if (event
->kind
== selection_request_event
)
2996 struct input_event copy
;
2998 /* Remove it from the buffer before processing it,
2999 since otherwise swallow_events called recursively could see it
3000 and process it again. */
3002 kbd_fetch_ptr
= event
+ 1;
3003 input_pending
= readable_events (0);
3004 x_handle_selection_request (©
);
3006 /* We're getting selection request events, but we don't have
3012 else if (event
->kind
== selection_clear_event
)
3015 struct input_event copy
;
3017 /* Remove it from the buffer before processing it, */
3020 kbd_fetch_ptr
= event
+ 1;
3021 input_pending
= readable_events (0);
3022 x_handle_selection_clear (©
);
3024 /* We're getting selection request events, but we don't have
3033 old_timers_run
= timers_run
;
3034 get_input_pending (&input_pending
, 1);
3036 if (timers_run
!= old_timers_run
&& do_display
)
3037 redisplay_preserve_echo_area ();
3040 static EMACS_TIME timer_idleness_start_time
;
3042 /* Record the start of when Emacs is idle,
3043 for the sake of running idle-time timers. */
3050 /* If we are already in the idle state, do nothing. */
3051 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3054 EMACS_GET_TIME (timer_idleness_start_time
);
3056 /* Mark all idle-time timers as once again candidates for running. */
3057 for (timers
= Vtimer_idle_list
; CONSP (timers
); timers
= XCONS (timers
)->cdr
)
3061 timer
= XCONS (timers
)->car
;
3063 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3065 XVECTOR (timer
)->contents
[0] = Qnil
;
3069 /* Record that Emacs is no longer idle, so stop running idle-time timers. */
3074 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
3077 /* This is only for debugging. */
3078 struct input_event last_timer_event
;
3080 /* Check whether a timer has fired. To prevent larger problems we simply
3081 disregard elements that are not proper timers. Do not make a circular
3082 timer list for the time being.
3084 Returns the number of seconds to wait until the next timer fires. If a
3085 timer is triggering now, return zero seconds.
3086 If no timer is active, return -1 seconds.
3088 If a timer is ripe, we run it, with quitting turned off.
3090 DO_IT_NOW is now ignored. It used to mean that we should
3091 run the timer directly instead of queueing a timer-event.
3092 Now we always run timers directly. */
3095 timer_check (do_it_now
)
3098 EMACS_TIME nexttime
;
3099 EMACS_TIME now
, idleness_now
;
3100 Lisp_Object timers
, idle_timers
, chosen_timer
;
3101 struct gcpro gcpro1
, gcpro2
, gcpro3
;
3103 EMACS_SET_SECS (nexttime
, -1);
3104 EMACS_SET_USECS (nexttime
, -1);
3106 /* Always consider the ordinary timers. */
3107 timers
= Vtimer_list
;
3108 /* Consider the idle timers only if Emacs is idle. */
3109 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3110 idle_timers
= Vtimer_idle_list
;
3113 chosen_timer
= Qnil
;
3114 GCPRO3 (timers
, idle_timers
, chosen_timer
);
3116 if (CONSP (timers
) || CONSP (idle_timers
))
3118 EMACS_GET_TIME (now
);
3119 if (! EMACS_TIME_NEG_P (timer_idleness_start_time
))
3120 EMACS_SUB_TIME (idleness_now
, now
, timer_idleness_start_time
);
3123 while (CONSP (timers
) || CONSP (idle_timers
))
3125 int triggertime
= EMACS_SECS (now
);
3126 Lisp_Object
*vector
;
3127 Lisp_Object timer
, idle_timer
;
3128 EMACS_TIME timer_time
, idle_timer_time
;
3129 EMACS_TIME difference
, timer_difference
, idle_timer_difference
;
3131 /* Skip past invalid timers and timers already handled. */
3134 timer
= XCONS (timers
)->car
;
3135 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3137 timers
= XCONS (timers
)->cdr
;
3140 vector
= XVECTOR (timer
)->contents
;
3142 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
3143 || !INTEGERP (vector
[3])
3144 || ! NILP (vector
[0]))
3146 timers
= XCONS (timers
)->cdr
;
3150 if (!NILP (idle_timers
))
3152 timer
= XCONS (idle_timers
)->car
;
3153 if (!VECTORP (timer
) || XVECTOR (timer
)->size
!= 8)
3155 idle_timers
= XCONS (idle_timers
)->cdr
;
3158 vector
= XVECTOR (timer
)->contents
;
3160 if (!INTEGERP (vector
[1]) || !INTEGERP (vector
[2])
3161 || !INTEGERP (vector
[3])
3162 || ! NILP (vector
[0]))
3164 idle_timers
= XCONS (idle_timers
)->cdr
;
3169 /* Set TIMER, TIMER_TIME and TIMER_DIFFERENCE
3170 based on the next ordinary timer.
3171 TIMER_DIFFERENCE is the distance in time from NOW to when
3172 this timer becomes ripe (negative if it's already ripe). */
3175 timer
= XCONS (timers
)->car
;
3176 vector
= XVECTOR (timer
)->contents
;
3177 EMACS_SET_SECS (timer_time
,
3178 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
3179 EMACS_SET_USECS (timer_time
, XINT (vector
[3]));
3180 EMACS_SUB_TIME (timer_difference
, timer_time
, now
);
3183 /* Set IDLE_TIMER, IDLE_TIMER_TIME and IDLE_TIMER_DIFFERENCE
3184 based on the next idle timer. */
3185 if (!NILP (idle_timers
))
3187 idle_timer
= XCONS (idle_timers
)->car
;
3188 vector
= XVECTOR (idle_timer
)->contents
;
3189 EMACS_SET_SECS (idle_timer_time
,
3190 (XINT (vector
[1]) << 16) | (XINT (vector
[2])));
3191 EMACS_SET_USECS (idle_timer_time
, XINT (vector
[3]));
3192 EMACS_SUB_TIME (idle_timer_difference
, idle_timer_time
, idleness_now
);
3195 /* Decide which timer is the next timer,
3196 and set CHOSEN_TIMER, VECTOR and DIFFERENCE accordingly.
3197 Also step down the list where we found that timer. */
3199 if (! NILP (timers
) && ! NILP (idle_timers
))
3202 EMACS_SUB_TIME (temp
, timer_difference
, idle_timer_difference
);
3203 if (EMACS_TIME_NEG_P (temp
))
3205 chosen_timer
= timer
;
3206 timers
= XCONS (timers
)->cdr
;
3207 difference
= timer_difference
;
3211 chosen_timer
= idle_timer
;
3212 idle_timers
= XCONS (idle_timers
)->cdr
;
3213 difference
= idle_timer_difference
;
3216 else if (! NILP (timers
))
3218 chosen_timer
= timer
;
3219 timers
= XCONS (timers
)->cdr
;
3220 difference
= timer_difference
;
3224 chosen_timer
= idle_timer
;
3225 idle_timers
= XCONS (idle_timers
)->cdr
;
3226 difference
= idle_timer_difference
;
3228 vector
= XVECTOR (chosen_timer
)->contents
;
3230 /* If timer is rupe, run it if it hasn't been run. */
3231 if (EMACS_TIME_NEG_P (difference
)
3232 || (EMACS_SECS (difference
) == 0
3233 && EMACS_USECS (difference
) == 0))
3235 if (NILP (vector
[0]))
3238 int was_locked
= single_kboard
;
3239 int count
= specpdl_ptr
- specpdl
;
3241 /* Mark the timer as triggered to prevent problems if the lisp
3242 code fails to reschedule it right. */
3245 specbind (Qinhibit_quit
, Qt
);
3247 call1 (Qtimer_event_handler
, chosen_timer
);
3250 unbind_to (count
, Qnil
);
3252 /* Resume allowing input from any kboard, if that was true before. */
3254 any_kboard_state ();
3256 /* Since we have handled the event,
3257 we don't need to tell the caller to wake up and do it. */
3261 /* When we encounter a timer that is still waiting,
3262 return the amount of time to wait before it is ripe. */
3269 /* No timers are pending in the future. */
3270 /* Return 0 if we generated an event, and -1 if not. */
3275 /* Caches for modify_event_symbol. */
3276 static Lisp_Object accent_key_syms
;
3277 static Lisp_Object func_key_syms
;
3278 static Lisp_Object mouse_syms
;
3280 static Lisp_Object mouse_wheel_syms
;
3283 /* This is a list of keysym codes for special "accent" characters.
3284 It parallels lispy_accent_keys. */
3286 static int lispy_accent_codes
[] =
3288 #ifdef XK_dead_circumflex
3293 #ifdef XK_dead_grave
3298 #ifdef XK_dead_tilde
3303 #ifdef XK_dead_diaeresis
3308 #ifdef XK_dead_macron
3313 #ifdef XK_dead_degree
3318 #ifdef XK_dead_acute
3323 #ifdef XK_dead_cedilla
3328 #ifdef XK_dead_breve
3333 #ifdef XK_dead_ogonek
3338 #ifdef XK_dead_caron
3343 #ifdef XK_dead_doubleacute
3344 XK_dead_doubleacute
,
3348 #ifdef XK_dead_abovedot
3355 /* This is a list of Lisp names for special "accent" characters.
3356 It parallels lispy_accent_codes. */
3358 static char *lispy_accent_keys
[] =
3376 #define FUNCTION_KEY_OFFSET 0x0
3378 char *lispy_function_keys
[] =
3382 0, /* VK_LBUTTON 0x01 */
3383 0, /* VK_RBUTTON 0x02 */
3384 "cancel", /* VK_CANCEL 0x03 */
3385 0, /* VK_MBUTTON 0x04 */
3387 0, 0, 0, /* 0x05 .. 0x07 */
3389 "backspace", /* VK_BACK 0x08 */
3390 "tab", /* VK_TAB 0x09 */
3392 0, 0, /* 0x0A .. 0x0B */
3394 "clear", /* VK_CLEAR 0x0C */
3395 "return", /* VK_RETURN 0x0D */
3397 0, 0, /* 0x0E .. 0x0F */
3399 "shift", /* VK_SHIFT 0x10 */
3400 "control", /* VK_CONTROL 0x11 */
3401 "menu", /* VK_MENU 0x12 */
3402 "pause", /* VK_PAUSE 0x13 */
3403 "capital", /* VK_CAPITAL 0x14 */
3405 0, 0, 0, 0, 0, 0, /* 0x15 .. 0x1A */
3407 0, /* VK_ESCAPE 0x1B */
3409 0, 0, 0, 0, /* 0x1C .. 0x1F */
3411 0, /* VK_SPACE 0x20 */
3412 "prior", /* VK_PRIOR 0x21 */
3413 "next", /* VK_NEXT 0x22 */
3414 "end", /* VK_END 0x23 */
3415 "home", /* VK_HOME 0x24 */
3416 "left", /* VK_LEFT 0x25 */
3417 "up", /* VK_UP 0x26 */
3418 "right", /* VK_RIGHT 0x27 */
3419 "down", /* VK_DOWN 0x28 */
3420 "select", /* VK_SELECT 0x29 */
3421 "print", /* VK_PRINT 0x2A */
3422 "execute", /* VK_EXECUTE 0x2B */
3423 "snapshot", /* VK_SNAPSHOT 0x2C */
3424 "insert", /* VK_INSERT 0x2D */
3425 "delete", /* VK_DELETE 0x2E */
3426 "help", /* VK_HELP 0x2F */
3428 /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
3430 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3432 0, 0, 0, 0, 0, 0, 0, /* 0x3A .. 0x40 */
3434 /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
3436 0, 0, 0, 0, 0, 0, 0, 0, 0,
3437 0, 0, 0, 0, 0, 0, 0, 0, 0,
3438 0, 0, 0, 0, 0, 0, 0, 0,
3440 "lwindow", /* VK_LWIN 0x5B */
3441 "rwindow", /* VK_RWIN 0x5C */
3442 "apps", /* VK_APPS 0x5D */
3444 0, 0, /* 0x5E .. 0x5F */
3446 "kp-0", /* VK_NUMPAD0 0x60 */
3447 "kp-1", /* VK_NUMPAD1 0x61 */
3448 "kp-2", /* VK_NUMPAD2 0x62 */
3449 "kp-3", /* VK_NUMPAD3 0x63 */
3450 "kp-4", /* VK_NUMPAD4 0x64 */
3451 "kp-5", /* VK_NUMPAD5 0x65 */
3452 "kp-6", /* VK_NUMPAD6 0x66 */
3453 "kp-7", /* VK_NUMPAD7 0x67 */
3454 "kp-8", /* VK_NUMPAD8 0x68 */
3455 "kp-9", /* VK_NUMPAD9 0x69 */
3456 "kp-multiply", /* VK_MULTIPLY 0x6A */
3457 "kp-add", /* VK_ADD 0x6B */
3458 "kp-separator", /* VK_SEPARATOR 0x6C */
3459 "kp-subtract", /* VK_SUBTRACT 0x6D */
3460 "kp-decimal", /* VK_DECIMAL 0x6E */
3461 "kp-divide", /* VK_DIVIDE 0x6F */
3462 "f1", /* VK_F1 0x70 */
3463 "f2", /* VK_F2 0x71 */
3464 "f3", /* VK_F3 0x72 */
3465 "f4", /* VK_F4 0x73 */
3466 "f5", /* VK_F5 0x74 */
3467 "f6", /* VK_F6 0x75 */
3468 "f7", /* VK_F7 0x76 */
3469 "f8", /* VK_F8 0x77 */
3470 "f9", /* VK_F9 0x78 */
3471 "f10", /* VK_F10 0x79 */
3472 "f11", /* VK_F11 0x7A */
3473 "f12", /* VK_F12 0x7B */
3474 "f13", /* VK_F13 0x7C */
3475 "f14", /* VK_F14 0x7D */
3476 "f15", /* VK_F15 0x7E */
3477 "f16", /* VK_F16 0x7F */
3478 "f17", /* VK_F17 0x80 */
3479 "f18", /* VK_F18 0x81 */
3480 "f19", /* VK_F19 0x82 */
3481 "f20", /* VK_F20 0x83 */
3482 "f21", /* VK_F21 0x84 */
3483 "f22", /* VK_F22 0x85 */
3484 "f23", /* VK_F23 0x86 */
3485 "f24", /* VK_F24 0x87 */
3487 0, 0, 0, 0, /* 0x88 .. 0x8B */
3488 0, 0, 0, 0, /* 0x8C .. 0x8F */
3490 "kp-numlock", /* VK_NUMLOCK 0x90 */
3491 "scroll", /* VK_SCROLL 0x91 */
3493 "kp-space", /* VK_NUMPAD_CLEAR 0x92 */
3494 "kp-enter", /* VK_NUMPAD_ENTER 0x93 */
3495 "kp-prior", /* VK_NUMPAD_PRIOR 0x94 */
3496 "kp-next", /* VK_NUMPAD_NEXT 0x95 */
3497 "kp-end", /* VK_NUMPAD_END 0x96 */
3498 "kp-home", /* VK_NUMPAD_HOME 0x97 */
3499 "kp-left", /* VK_NUMPAD_LEFT 0x98 */
3500 "kp-up", /* VK_NUMPAD_UP 0x99 */
3501 "kp-right", /* VK_NUMPAD_RIGHT 0x9A */
3502 "kp-down", /* VK_NUMPAD_DOWN 0x9B */
3503 "kp-insert", /* VK_NUMPAD_INSERT 0x9C */
3504 "kp-delete", /* VK_NUMPAD_DELETE 0x9D */
3506 0, 0, /* 0x9E .. 0x9F */
3509 * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
3510 * Used only as parameters to GetAsyncKeyState() and GetKeyState().
3511 * No other API or message will distinguish left and right keys this way.
3515 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3516 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
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,
3525 "attn", /* VK_ATTN 0xF6 */
3526 "crsel", /* VK_CRSEL 0xF7 */
3527 "exsel", /* VK_EXSEL 0xF8 */
3528 "ereof", /* VK_EREOF 0xF9 */
3529 "play", /* VK_PLAY 0xFA */
3530 "zoom", /* VK_ZOOM 0xFB */
3531 "noname", /* VK_NONAME 0xFC */
3532 "pa1", /* VK_PA1 0xFD */
3533 "oem_clear", /* VK_OEM_CLEAR 0xFE */
3536 #else /* not HAVE_NTGUI */
3539 static char *lispy_kana_keys
[] =
3541 /* X Keysym value */
3542 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x400 .. 0x40f */
3543 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x410 .. 0x41f */
3544 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x420 .. 0x42f */
3545 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x430 .. 0x43f */
3546 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x440 .. 0x44f */
3547 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x450 .. 0x45f */
3548 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x460 .. 0x46f */
3549 0,0,0,0,0,0,0,0,0,0,0,0,0,0,"overline",0,
3550 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x480 .. 0x48f */
3551 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x490 .. 0x49f */
3552 0, "kana-fullstop", "kana-openingbracket", "kana-closingbracket",
3553 "kana-comma", "kana-conjunctive", "kana-WO", "kana-a",
3554 "kana-i", "kana-u", "kana-e", "kana-o",
3555 "kana-ya", "kana-yu", "kana-yo", "kana-tsu",
3556 "prolongedsound", "kana-A", "kana-I", "kana-U",
3557 "kana-E", "kana-O", "kana-KA", "kana-KI",
3558 "kana-KU", "kana-KE", "kana-KO", "kana-SA",
3559 "kana-SHI", "kana-SU", "kana-SE", "kana-SO",
3560 "kana-TA", "kana-CHI", "kana-TSU", "kana-TE",
3561 "kana-TO", "kana-NA", "kana-NI", "kana-NU",
3562 "kana-NE", "kana-NO", "kana-HA", "kana-HI",
3563 "kana-FU", "kana-HE", "kana-HO", "kana-MA",
3564 "kana-MI", "kana-MU", "kana-ME", "kana-MO",
3565 "kana-YA", "kana-YU", "kana-YO", "kana-RA",
3566 "kana-RI", "kana-RU", "kana-RE", "kana-RO",
3567 "kana-WA", "kana-N", "voicedsound", "semivoicedsound",
3568 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4e0 .. 0x4ef */
3569 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x4f0 .. 0x4ff */
3571 #endif /* XK_kana_A */
3573 #define FUNCTION_KEY_OFFSET 0xff00
3575 /* You'll notice that this table is arranged to be conveniently
3576 indexed by X Windows keysym values. */
3577 static char *lispy_function_keys
[] =
3579 /* X Keysym value */
3581 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00 */
3589 0, 0, 0, /* 0xff10 */
3591 0, 0, 0, 0, 0, 0, 0,
3594 0, "kanji", "muhenkan",
3595 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff20...2f */
3596 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff30...3f */
3597 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
3599 "home", /* 0xff50 */ /* IsCursorKey */
3610 "select", /* 0xff60 */ /* IsMiscFunctionKey */
3621 "break", /* 0xff6b */
3623 0, 0, 0, 0, 0, 0, 0, 0, "backtab", 0,
3625 0, 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff7f */
3626 "kp-space", /* 0xff80 */ /* IsKeypadKey */
3627 0, 0, 0, 0, 0, 0, 0, 0,
3628 "kp-tab", /* 0xff89 */
3630 "kp-enter", /* 0xff8d */
3632 "kp-f1", /* 0xff91 */
3636 "kp-home", /* 0xff95 */
3641 "kp-prior", /* kp-page-up */
3642 "kp-next", /* kp-page-down */
3648 0, 0, 0, 0, 0, 0, 0, 0, 0,
3649 "kp-multiply", /* 0xffaa */
3654 "kp-divide", /* 0xffaf */
3655 "kp-0", /* 0xffb0 */
3656 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
3659 "kp-equal", /* 0xffbd */
3660 "f1", /* 0xffbe */ /* IsFunctionKey */
3662 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
3663 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
3664 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
3665 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
3666 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
3667 0, 0, 0, 0, 0, 0, 0, 0,
3668 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
3669 0, 0, 0, 0, 0, 0, 0, "delete"
3672 /* ISO 9995 Function and Modifier Keys; the first byte is 0xFE. */
3673 #define ISO_FUNCTION_KEY_OFFSET 0xfe00
3675 static char *iso_lispy_function_keys
[] =
3677 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe00 */
3678 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe08 */
3679 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe10 */
3680 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfe18 */
3681 "iso-lefttab", /* 0xfe20 */
3682 "iso-move-line-up", "iso-move-line-down",
3683 "iso-partial-line-up", "iso-partial-line-down",
3684 "iso-partial-space-left", "iso-partial-space-right",
3685 "iso-set-margin-left", "iso-set-margin-right", /* 0xffe27, 28 */
3686 "iso-release-margin-left", "iso-release-margin-right",
3687 "iso-release-both-margins",
3688 "iso-fast-cursor-left", "iso-fast-cursor-right",
3689 "iso-fast-cursor-up", "iso-fast-cursor-down",
3690 "iso-continuous-underline", "iso-discontinuous-underline", /* 0xfe30, 31 */
3691 "iso-emphasize", "iso-center-object", "iso-enter", /* ... 0xfe34 */
3694 #endif /* not HAVE_NTGUI */
3696 static char *lispy_mouse_names
[] =
3698 "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5"
3702 /* mouse-wheel events are generated by the wheel on devices such as
3703 the MS Intellimouse. The wheel sits in between the left and right
3704 mouse buttons, and is typically used to scroll or zoom the window
3705 underneath the pointer. mouse-wheel events specify the object on
3706 which they operate, and a delta corresponding to the amount and
3707 direction that the wheel is rotated. Clicking the mouse-wheel
3708 generates a mouse-2 event. */
3709 static char *lispy_mouse_wheel_names
[] =
3713 #endif /* WINDOWSNT */
3715 /* Scroll bar parts. */
3716 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
3717 Lisp_Object Qup
, Qdown
;
3719 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
3720 Lisp_Object
*scroll_bar_parts
[] = {
3721 &Qabove_handle
, &Qhandle
, &Qbelow_handle
,
3726 /* A vector, indexed by button number, giving the down-going location
3727 of currently depressed buttons, both scroll bar and non-scroll bar.
3729 The elements have the form
3730 (BUTTON-NUMBER MODIFIER-MASK . REST)
3731 where REST is the cdr of a position as it would be reported in the event.
3733 The make_lispy_event function stores positions here to tell the
3734 difference between click and drag events, and to store the starting
3735 location to be included in drag events. */
3737 static Lisp_Object button_down_location
;
3739 /* Information about the most recent up-going button event: Which
3740 button, what location, and what time. */
3742 static int last_mouse_button
;
3743 static int last_mouse_x
;
3744 static int last_mouse_y
;
3745 static unsigned long button_down_time
;
3747 /* The maximum time between clicks to make a double-click,
3748 or Qnil to disable double-click detection,
3749 or Qt for no time limit. */
3750 Lisp_Object Vdouble_click_time
;
3752 /* The number of clicks in this multiple-click. */
3754 int double_click_count
;
3756 /* Given a struct input_event, build the lisp event which represents
3757 it. If EVENT is 0, build a mouse movement event from the mouse
3758 movement buffer, which should have a movement event in it.
3760 Note that events must be passed to this function in the order they
3761 are received; this function stores the location of button presses
3762 in order to build drag events when the button is released. */
3765 make_lispy_event (event
)
3766 struct input_event
*event
;
3770 switch (SWITCH_ENUM_CAST (event
->kind
))
3772 /* A simple keystroke. */
3773 case ascii_keystroke
:
3775 Lisp_Object lispy_c
;
3776 int c
= event
->code
& 0377;
3777 /* Turn ASCII characters into control characters
3779 if (event
->modifiers
& ctrl_modifier
)
3780 c
= make_ctrl_char (c
);
3782 /* Add in the other modifier bits. We took care of ctrl_modifier
3783 just above, and the shift key was taken care of by the X code,
3784 and applied to control characters by make_ctrl_char. */
3785 c
|= (event
->modifiers
3786 & (meta_modifier
| alt_modifier
3787 | hyper_modifier
| super_modifier
));
3788 /* Distinguish Shift-SPC from SPC. */
3789 if ((event
->code
& 0377) == 040
3790 && event
->modifiers
& shift_modifier
)
3791 c
|= shift_modifier
;
3792 button_down_time
= 0;
3793 XSETFASTINT (lispy_c
, c
);
3797 /* A function key. The symbol may need to have modifier prefixes
3799 case non_ascii_keystroke
:
3800 button_down_time
= 0;
3802 for (i
= 0; i
< sizeof (lispy_accent_codes
) / sizeof (int); i
++)
3803 if (event
->code
== lispy_accent_codes
[i
])
3804 return modify_event_symbol (i
,
3806 Qfunction_key
, Qnil
,
3807 lispy_accent_keys
, &accent_key_syms
,
3808 (sizeof (lispy_accent_keys
)
3809 / sizeof (lispy_accent_keys
[0])));
3811 /* Handle system-specific keysyms. */
3812 if (event
->code
& (1 << 28))
3814 /* We need to use an alist rather than a vector as the cache
3815 since we can't make a vector long enuf. */
3816 if (NILP (current_kboard
->system_key_syms
))
3817 current_kboard
->system_key_syms
= Fcons (Qnil
, Qnil
);
3818 return modify_event_symbol (event
->code
,
3821 current_kboard
->Vsystem_key_alist
,
3822 0, ¤t_kboard
->system_key_syms
,
3827 if (event
->code
>= 0x400 && event
->code
< 0x500)
3828 return modify_event_symbol (event
->code
- 0x400,
3829 event
->modifiers
& ~shift_modifier
,
3830 Qfunction_key
, Qnil
,
3831 lispy_kana_keys
, &func_key_syms
,
3832 (sizeof (lispy_kana_keys
)
3833 / sizeof (lispy_kana_keys
[0])));
3834 #endif /* XK_kana_A */
3836 #ifdef ISO_FUNCTION_KEY_OFFSET
3837 if (event
->code
< FUNCTION_KEY_OFFSET
3838 && event
->code
>= ISO_FUNCTION_KEY_OFFSET
)
3839 return modify_event_symbol (event
->code
- ISO_FUNCTION_KEY_OFFSET
,
3841 Qfunction_key
, Qnil
,
3842 iso_lispy_function_keys
, &func_key_syms
,
3843 (sizeof (iso_lispy_function_keys
)
3844 / sizeof (iso_lispy_function_keys
[0])));
3847 return modify_event_symbol (event
->code
- FUNCTION_KEY_OFFSET
,
3849 Qfunction_key
, Qnil
,
3850 lispy_function_keys
, &func_key_syms
,
3851 (sizeof (lispy_function_keys
)
3852 / sizeof (lispy_function_keys
[0])));
3855 /* A mouse click. Figure out where it is, decide whether it's
3856 a press, click or drag, and build the appropriate structure. */
3858 case scroll_bar_click
:
3860 int button
= event
->code
;
3862 Lisp_Object position
;
3863 Lisp_Object
*start_pos_ptr
;
3864 Lisp_Object start_pos
;
3866 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
3869 /* Build the position as appropriate for this mouse click. */
3870 if (event
->kind
== mouse_click
)
3873 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
3878 /* Ignore mouse events that were made on frame that
3879 have been deleted. */
3880 if (! FRAME_LIVE_P (f
))
3883 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
3884 &column
, &row
, NULL
, 1);
3886 #ifndef USE_X_TOOLKIT
3887 /* In the non-toolkit version, clicks on the menu bar
3888 are ordinary button events in the event buffer.
3889 Distinguish them, and invoke the menu.
3891 (In the toolkit version, the toolkit handles the menu bar
3892 and Emacs doesn't know about it until after the user
3893 makes a selection.) */
3894 if (row
>= 0 && row
< FRAME_MENU_BAR_LINES (f
)
3895 && (event
->modifiers
& down_modifier
))
3897 Lisp_Object items
, item
;
3902 /* Activate the menu bar on the down event. If the
3903 up event comes in before the menu code can deal with it,
3905 if (! (event
->modifiers
& down_modifier
))
3910 items
= FRAME_MENU_BAR_ITEMS (f
);
3911 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
3913 Lisp_Object pos
, string
;
3914 string
= XVECTOR (items
)->contents
[i
+ 1];
3915 pos
= XVECTOR (items
)->contents
[i
+ 3];
3918 if (column
>= XINT (pos
)
3919 && column
< XINT (pos
) + XSTRING (string
)->size
)
3921 item
= XVECTOR (items
)->contents
[i
];
3927 = Fcons (event
->frame_or_window
,
3929 Fcons (Fcons (event
->x
, event
->y
),
3930 Fcons (make_number (event
->timestamp
),
3933 return Fcons (item
, Fcons (position
, Qnil
));
3935 #endif /* not USE_X_TOOLKIT */
3937 window
= window_from_coordinates (f
, column
, row
, &part
);
3939 if (!WINDOWP (window
))
3941 window
= event
->frame_or_window
;
3946 int pixcolumn
, pixrow
;
3947 column
-= WINDOW_LEFT_MARGIN (XWINDOW (window
));
3948 row
-= XINT (XWINDOW (window
)->top
);
3949 glyph_to_pixel_coords (f
, column
, row
, &pixcolumn
, &pixrow
);
3950 XSETINT (event
->x
, pixcolumn
);
3951 XSETINT (event
->y
, pixrow
);
3956 posn
= Qvertical_line
;
3959 buffer_posn_from_coords (XWINDOW (window
),
3966 Fcons (Fcons (event
->x
, event
->y
),
3967 Fcons (make_number (event
->timestamp
),
3973 Lisp_Object portion_whole
;
3976 window
= event
->frame_or_window
;
3977 portion_whole
= Fcons (event
->x
, event
->y
);
3978 part
= *scroll_bar_parts
[(int) event
->part
];
3982 Fcons (Qvertical_scroll_bar
,
3983 Fcons (portion_whole
,
3984 Fcons (make_number (event
->timestamp
),
3985 Fcons (part
, Qnil
)))));
3988 start_pos_ptr
= &XVECTOR (button_down_location
)->contents
[button
];
3990 start_pos
= *start_pos_ptr
;
3991 *start_pos_ptr
= Qnil
;
3993 is_double
= (button
== last_mouse_button
3994 && XINT (event
->x
) == last_mouse_x
3995 && XINT (event
->y
) == last_mouse_y
3996 && button_down_time
!= 0
3997 && (EQ (Vdouble_click_time
, Qt
)
3998 || (INTEGERP (Vdouble_click_time
)
3999 && ((int)(event
->timestamp
- button_down_time
)
4000 < XINT (Vdouble_click_time
)))));
4001 last_mouse_button
= button
;
4002 last_mouse_x
= XINT (event
->x
);
4003 last_mouse_y
= XINT (event
->y
);
4005 /* If this is a button press, squirrel away the location, so
4006 we can decide later whether it was a click or a drag. */
4007 if (event
->modifiers
& down_modifier
)
4011 double_click_count
++;
4012 event
->modifiers
|= ((double_click_count
> 2)
4017 double_click_count
= 1;
4018 button_down_time
= event
->timestamp
;
4019 *start_pos_ptr
= Fcopy_alist (position
);
4022 /* Now we're releasing a button - check the co-ordinates to
4023 see if this was a click or a drag. */
4024 else if (event
->modifiers
& up_modifier
)
4026 /* If we did not see a down before this up,
4027 ignore the up. Probably this happened because
4028 the down event chose a menu item.
4029 It would be an annoyance to treat the release
4030 of the button that chose the menu item
4031 as a separate event. */
4033 if (!CONSP (start_pos
))
4036 event
->modifiers
&= ~up_modifier
;
4037 #if 0 /* Formerly we treated an up with no down as a click event. */
4038 if (!CONSP (start_pos
))
4039 event
->modifiers
|= click_modifier
;
4043 /* The third element of every position should be the (x,y)
4047 down
= Fnth (make_number (2), start_pos
);
4048 if (EQ (event
->x
, XCONS (down
)->car
)
4049 && EQ (event
->y
, XCONS (down
)->cdr
))
4051 event
->modifiers
|= click_modifier
;
4055 button_down_time
= 0;
4056 event
->modifiers
|= drag_modifier
;
4058 /* Don't check is_double; treat this as multiple
4059 if the down-event was multiple. */
4060 if (double_click_count
> 1)
4061 event
->modifiers
|= ((double_click_count
> 2)
4067 /* Every mouse event should either have the down_modifier or
4068 the up_modifier set. */
4072 /* Get the symbol we should use for the mouse click. */
4075 head
= modify_event_symbol (button
,
4078 lispy_mouse_names
, &mouse_syms
,
4079 (sizeof (lispy_mouse_names
)
4080 / sizeof (lispy_mouse_names
[0])));
4081 if (event
->modifiers
& drag_modifier
)
4086 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
4089 Fcons (make_number (double_click_count
),
4099 case w32_scroll_bar_click
:
4101 int button
= event
->code
;
4103 Lisp_Object position
;
4104 Lisp_Object
*start_pos_ptr
;
4105 Lisp_Object start_pos
;
4107 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
4112 Lisp_Object portion_whole
;
4115 window
= event
->frame_or_window
;
4116 portion_whole
= Fcons (event
->x
, event
->y
);
4117 part
= *scroll_bar_parts
[(int) event
->part
];
4121 Fcons (Qvertical_scroll_bar
,
4122 Fcons (portion_whole
,
4123 Fcons (make_number (event
->timestamp
),
4124 Fcons (part
, Qnil
)))));
4127 /* Always treat W32 scroll bar events as clicks. */
4128 event
->modifiers
|= click_modifier
;
4131 /* Get the symbol we should use for the mouse click. */
4134 head
= modify_event_symbol (button
,
4137 lispy_mouse_names
, &mouse_syms
,
4138 (sizeof (lispy_mouse_names
)
4139 / sizeof (lispy_mouse_names
[0])));
4148 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
4151 Lisp_Object head
, position
;
4154 /* Ignore mouse events that were made on frame that
4155 have been deleted. */
4156 if (! FRAME_LIVE_P (f
))
4158 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
4159 &column
, &row
, NULL
, 1);
4160 window
= window_from_coordinates (f
, column
, row
, &part
);
4162 if (!WINDOWP (window
))
4164 window
= event
->frame_or_window
;
4169 int pixcolumn
, pixrow
;
4170 column
-= XINT (XWINDOW (window
)->left
);
4171 row
-= XINT (XWINDOW (window
)->top
);
4172 glyph_to_pixel_coords (f
, column
, row
, &pixcolumn
, &pixrow
);
4173 XSETINT (event
->x
, pixcolumn
);
4174 XSETINT (event
->y
, pixrow
);
4179 posn
= Qvertical_line
;
4182 buffer_posn_from_coords (XWINDOW (window
),
4187 Lisp_Object head
, position
;
4192 Fcons (Fcons (event
->x
, event
->y
),
4193 Fcons (make_number (event
->timestamp
),
4196 head
= modify_event_symbol (0, event
->modifiers
,
4198 lispy_mouse_wheel_names
,
4199 &mouse_wheel_syms
, 1);
4202 Fcons (make_number (event
->code
),
4206 #endif /* WINDOWSNT */
4207 #endif /* HAVE_MOUSE */
4209 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
4210 case menu_bar_event
:
4211 /* The event value is in the cdr of the frame_or_window slot. */
4212 if (!CONSP (event
->frame_or_window
))
4214 return XCONS (event
->frame_or_window
)->cdr
;
4217 /* The 'kind' field of the event is something we don't recognize. */
4226 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
4228 Lisp_Object bar_window
;
4229 enum scroll_bar_part part
;
4233 /* Is it a scroll bar movement? */
4234 if (frame
&& ! NILP (bar_window
))
4236 Lisp_Object part_sym
;
4238 part_sym
= *scroll_bar_parts
[(int) part
];
4239 return Fcons (Qscroll_bar_movement
,
4240 (Fcons (Fcons (bar_window
,
4241 Fcons (Qvertical_scroll_bar
,
4242 Fcons (Fcons (x
, y
),
4243 Fcons (make_number (time
),
4249 /* Or is it an ordinary mouse movement? */
4259 /* It's in a frame; which window on that frame? */
4260 pixel_to_glyph_coords (frame
, XINT (x
), XINT (y
), &column
, &row
,
4262 window
= window_from_coordinates (frame
, column
, row
, &area
);
4267 if (WINDOWP (window
))
4269 int pixcolumn
, pixrow
;
4270 column
-= WINDOW_LEFT_MARGIN (XWINDOW (window
));
4271 row
-= XINT (XWINDOW (window
)->top
);
4272 glyph_to_pixel_coords (frame
, column
, row
, &pixcolumn
, &pixrow
);
4273 XSETINT (x
, pixcolumn
);
4274 XSETINT (y
, pixrow
);
4279 posn
= Qvertical_line
;
4282 buffer_posn_from_coords (XWINDOW (window
), column
, row
));
4284 else if (frame
!= 0)
4286 XSETFRAME (window
, frame
);
4297 return Fcons (Qmouse_movement
,
4298 Fcons (Fcons (window
,
4300 Fcons (Fcons (x
, y
),
4301 Fcons (make_number (time
),
4307 #endif /* HAVE_MOUSE */
4309 /* Construct a switch frame event. */
4311 make_lispy_switch_frame (frame
)
4314 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
4317 /* Manipulating modifiers. */
4319 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
4321 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
4322 SYMBOL's name of the end of the modifiers; the string from this
4323 position is the unmodified symbol name.
4325 This doesn't use any caches. */
4328 parse_modifiers_uncached (symbol
, modifier_end
)
4332 struct Lisp_String
*name
;
4336 CHECK_SYMBOL (symbol
, 1);
4339 name
= XSYMBOL (symbol
)->name
;
4341 for (i
= 0; i
+2 <= name
->size_byte
; )
4343 int this_mod_end
= 0;
4346 /* See if the name continues with a modifier word.
4347 Check that the word appears, but don't check what follows it.
4348 Set this_mod and this_mod_end to record what we find. */
4350 switch (name
->data
[i
])
4352 #define SINGLE_LETTER_MOD(BIT) \
4353 (this_mod_end = i + 1, this_mod = BIT)
4356 SINGLE_LETTER_MOD (alt_modifier
);
4360 SINGLE_LETTER_MOD (ctrl_modifier
);
4364 SINGLE_LETTER_MOD (hyper_modifier
);
4368 SINGLE_LETTER_MOD (meta_modifier
);
4372 SINGLE_LETTER_MOD (shift_modifier
);
4376 SINGLE_LETTER_MOD (super_modifier
);
4379 #undef SINGLE_LETTER_MOD
4382 /* If we found no modifier, stop looking for them. */
4383 if (this_mod_end
== 0)
4386 /* Check there is a dash after the modifier, so that it
4387 really is a modifier. */
4388 if (this_mod_end
>= name
->size_byte
|| name
->data
[this_mod_end
] != '-')
4391 /* This modifier is real; look for another. */
4392 modifiers
|= this_mod
;
4393 i
= this_mod_end
+ 1;
4396 /* Should we include the `click' modifier? */
4397 if (! (modifiers
& (down_modifier
| drag_modifier
4398 | double_modifier
| triple_modifier
))
4399 && i
+ 7 == name
->size_byte
4400 && strncmp (name
->data
+ i
, "mouse-", 6) == 0
4401 && ('0' <= name
->data
[i
+ 6] && name
->data
[i
+ 6] <= '9'))
4402 modifiers
|= click_modifier
;
4410 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
4411 prepended to the string BASE[0..BASE_LEN-1].
4412 This doesn't use any caches. */
4414 apply_modifiers_uncached (modifiers
, base
, base_len
, base_len_byte
)
4417 int base_len
, base_len_byte
;
4419 /* Since BASE could contain nulls, we can't use intern here; we have
4420 to use Fintern, which expects a genuine Lisp_String, and keeps a
4423 = (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
4429 /* Only the event queue may use the `up' modifier; it should always
4430 be turned into a click or drag event before presented to lisp code. */
4431 if (modifiers
& up_modifier
)
4434 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
4435 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
4436 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
4437 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
4438 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
4439 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
4440 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
4441 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
4442 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
4443 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
4444 /* The click modifier is denoted by the absence of other modifiers. */
4448 mod_len
= p
- new_mods
;
4452 Lisp_Object new_name
;
4454 new_name
= make_uninit_multibyte_string (mod_len
+ base_len
,
4455 mod_len
+ base_len_byte
);
4456 bcopy (new_mods
, XSTRING (new_name
)->data
, mod_len
);
4457 bcopy (base
, XSTRING (new_name
)->data
+ mod_len
, base_len_byte
);
4459 return Fintern (new_name
, Qnil
);
4464 static char *modifier_names
[] =
4466 "up", "down", "drag", "click", "double", "triple", 0, 0,
4467 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4468 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
4470 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
4472 static Lisp_Object modifier_symbols
;
4474 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
4476 lispy_modifier_list (modifiers
)
4479 Lisp_Object modifier_list
;
4482 modifier_list
= Qnil
;
4483 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
4484 if (modifiers
& (1<<i
))
4485 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
4488 return modifier_list
;
4492 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
4493 where UNMODIFIED is the unmodified form of SYMBOL,
4494 MASK is the set of modifiers present in SYMBOL's name.
4495 This is similar to parse_modifiers_uncached, but uses the cache in
4496 SYMBOL's Qevent_symbol_element_mask property, and maintains the
4497 Qevent_symbol_elements property. */
4500 parse_modifiers (symbol
)
4503 Lisp_Object elements
;
4505 elements
= Fget (symbol
, Qevent_symbol_element_mask
);
4506 if (CONSP (elements
))
4511 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
4512 Lisp_Object unmodified
;
4515 unmodified
= Fintern (make_string (XSYMBOL (symbol
)->name
->data
+ end
,
4516 XSYMBOL (symbol
)->name
->size_byte
- end
),
4519 if (modifiers
& ~(((EMACS_INT
)1 << VALBITS
) - 1))
4521 XSETFASTINT (mask
, modifiers
);
4522 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
4524 /* Cache the parsing results on SYMBOL. */
4525 Fput (symbol
, Qevent_symbol_element_mask
,
4527 Fput (symbol
, Qevent_symbol_elements
,
4528 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
4530 /* Since we know that SYMBOL is modifiers applied to unmodified,
4531 it would be nice to put that in unmodified's cache.
4532 But we can't, since we're not sure that parse_modifiers is
4539 /* Apply the modifiers MODIFIERS to the symbol BASE.
4540 BASE must be unmodified.
4542 This is like apply_modifiers_uncached, but uses BASE's
4543 Qmodifier_cache property, if present. It also builds
4544 Qevent_symbol_elements properties, since it has that info anyway.
4546 apply_modifiers copies the value of BASE's Qevent_kind property to
4547 the modified symbol. */
4549 apply_modifiers (modifiers
, base
)
4553 Lisp_Object cache
, index
, entry
, new_symbol
;
4555 /* Mask out upper bits. We don't know where this value's been. */
4556 modifiers
&= ((EMACS_INT
)1 << VALBITS
) - 1;
4558 /* The click modifier never figures into cache indices. */
4559 cache
= Fget (base
, Qmodifier_cache
);
4560 XSETFASTINT (index
, (modifiers
& ~click_modifier
));
4561 entry
= assq_no_quit (index
, cache
);
4564 new_symbol
= XCONS (entry
)->cdr
;
4567 /* We have to create the symbol ourselves. */
4568 new_symbol
= apply_modifiers_uncached (modifiers
,
4569 XSYMBOL (base
)->name
->data
,
4570 XSYMBOL (base
)->name
->size
,
4571 XSYMBOL (base
)->name
->size_byte
);
4573 /* Add the new symbol to the base's cache. */
4574 entry
= Fcons (index
, new_symbol
);
4575 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
4577 /* We have the parsing info now for free, so add it to the caches. */
4578 XSETFASTINT (index
, modifiers
);
4579 Fput (new_symbol
, Qevent_symbol_element_mask
,
4580 Fcons (base
, Fcons (index
, Qnil
)));
4581 Fput (new_symbol
, Qevent_symbol_elements
,
4582 Fcons (base
, lispy_modifier_list (modifiers
)));
4585 /* Make sure this symbol is of the same kind as BASE.
4587 You'd think we could just set this once and for all when we
4588 intern the symbol above, but reorder_modifiers may call us when
4589 BASE's property isn't set right; we can't assume that just
4590 because it has a Qmodifier_cache property it must have its
4591 Qevent_kind set right as well. */
4592 if (NILP (Fget (new_symbol
, Qevent_kind
)))
4596 kind
= Fget (base
, Qevent_kind
);
4598 Fput (new_symbol
, Qevent_kind
, kind
);
4605 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
4606 return a symbol with the modifiers placed in the canonical order.
4607 Canonical order is alphabetical, except for down and drag, which
4608 always come last. The 'click' modifier is never written out.
4610 Fdefine_key calls this to make sure that (for example) C-M-foo
4611 and M-C-foo end up being equivalent in the keymap. */
4614 reorder_modifiers (symbol
)
4617 /* It's hopefully okay to write the code this way, since everything
4618 will soon be in caches, and no consing will be done at all. */
4621 parsed
= parse_modifiers (symbol
);
4622 return apply_modifiers ((int) XINT (XCONS (XCONS (parsed
)->cdr
)->car
),
4623 XCONS (parsed
)->car
);
4627 /* For handling events, we often want to produce a symbol whose name
4628 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
4629 to some base, like the name of a function key or mouse button.
4630 modify_event_symbol produces symbols of this sort.
4632 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
4633 is the name of the i'th symbol. TABLE_SIZE is the number of elements
4636 Alternatively, NAME_ALIST is an alist mapping codes into symbol names.
4637 NAME_ALIST is used if it is non-nil; otherwise NAME_TABLE is used.
4639 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
4640 persist between calls to modify_event_symbol that it can use to
4641 store a cache of the symbols it's generated for this NAME_TABLE
4642 before. The object stored there may be a vector or an alist.
4644 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
4646 MODIFIERS is a set of modifier bits (as given in struct input_events)
4647 whose prefixes should be applied to the symbol name.
4649 SYMBOL_KIND is the value to be placed in the event_kind property of
4650 the returned symbol.
4652 The symbols we create are supposed to have an
4653 `event-symbol-elements' property, which lists the modifiers present
4654 in the symbol's name. */
4657 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_alist
,
4658 name_table
, symbol_table
, table_size
)
4661 Lisp_Object symbol_kind
;
4662 Lisp_Object name_alist
;
4664 Lisp_Object
*symbol_table
;
4665 unsigned int table_size
;
4668 Lisp_Object symbol_int
;
4670 /* Get rid of the "vendor-specific" bit here. */
4671 XSETINT (symbol_int
, symbol_num
& 0xffffff);
4673 /* Is this a request for a valid symbol? */
4674 if (symbol_num
< 0 || symbol_num
>= table_size
)
4677 if (CONSP (*symbol_table
))
4678 value
= Fcdr (assq_no_quit (symbol_int
, *symbol_table
));
4680 /* If *symbol_table doesn't seem to be initialized properly, fix that.
4681 *symbol_table should be a lisp vector TABLE_SIZE elements long,
4682 where the Nth element is the symbol for NAME_TABLE[N], or nil if
4683 we've never used that symbol before. */
4686 if (! VECTORP (*symbol_table
)
4687 || XVECTOR (*symbol_table
)->size
!= table_size
)
4691 XSETFASTINT (size
, table_size
);
4692 *symbol_table
= Fmake_vector (size
, Qnil
);
4695 value
= XVECTOR (*symbol_table
)->contents
[symbol_num
];
4698 /* Have we already used this symbol before? */
4701 /* No; let's create it. */
4702 if (!NILP (name_alist
))
4703 value
= Fcdr_safe (Fassq (symbol_int
, name_alist
));
4704 else if (name_table
!= 0 && name_table
[symbol_num
])
4705 value
= intern (name_table
[symbol_num
]);
4707 #ifdef HAVE_WINDOW_SYSTEM
4710 char *name
= x_get_keysym_name (symbol_num
);
4712 value
= intern (name
);
4719 sprintf (buf
, "key-%d", symbol_num
);
4720 value
= intern (buf
);
4723 if (CONSP (*symbol_table
))
4724 *symbol_table
= Fcons (Fcons (symbol_int
, value
), *symbol_table
);
4726 XVECTOR (*symbol_table
)->contents
[symbol_num
] = value
;
4728 /* Fill in the cache entries for this symbol; this also
4729 builds the Qevent_symbol_elements property, which the user
4731 apply_modifiers (modifiers
& click_modifier
, value
);
4732 Fput (value
, Qevent_kind
, symbol_kind
);
4735 /* Apply modifiers to that symbol. */
4736 return apply_modifiers (modifiers
, value
);
4739 /* Convert a list that represents an event type,
4740 such as (ctrl meta backspace), into the usual representation of that
4741 event type as a number or a symbol. */
4743 DEFUN ("event-convert-list", Fevent_convert_list
, Sevent_convert_list
, 1, 1, 0,
4744 "Convert the event description list EVENT-DESC to an event type.\n\
4745 EVENT-DESC should contain one base event type (a character or symbol)\n\
4746 and zero or more modifier names (control, meta, hyper, super, shift, alt,\n\
4747 drag, down, double or triple). The base must be last.\n\
4748 The return value is an event type (a character or symbol) which\n\
4749 has the same base event type and all the specified modifiers.")
4751 Lisp_Object event_desc
;
4759 while (CONSP (rest
))
4764 elt
= XCONS (rest
)->car
;
4765 rest
= XCONS (rest
)->cdr
;
4767 /* Given a symbol, see if it is a modifier name. */
4768 if (SYMBOLP (elt
) && CONSP (rest
))
4769 this = parse_solitary_modifier (elt
);
4773 else if (!NILP (base
))
4774 error ("Two bases given in one event");
4780 /* Let the symbol A refer to the character A. */
4781 if (SYMBOLP (base
) && XSYMBOL (base
)->name
->size
== 1)
4782 XSETINT (base
, XSYMBOL (base
)->name
->data
[0]);
4784 if (INTEGERP (base
))
4786 /* Turn (shift a) into A. */
4787 if ((modifiers
& shift_modifier
) != 0
4788 && (XINT (base
) >= 'a' && XINT (base
) <= 'z'))
4790 XSETINT (base
, XINT (base
) - ('a' - 'A'));
4791 modifiers
&= ~shift_modifier
;
4794 /* Turn (control a) into C-a. */
4795 if (modifiers
& ctrl_modifier
)
4796 return make_number ((modifiers
& ~ctrl_modifier
)
4797 | make_ctrl_char (XINT (base
)));
4799 return make_number (modifiers
| XINT (base
));
4801 else if (SYMBOLP (base
))
4802 return apply_modifiers (modifiers
, base
);
4804 error ("Invalid base event");
4807 /* Try to recognize SYMBOL as a modifier name.
4808 Return the modifier flag bit, or 0 if not recognized. */
4811 parse_solitary_modifier (symbol
)
4814 struct Lisp_String
*name
= XSYMBOL (symbol
)->name
;
4816 switch (name
->data
[0])
4818 #define SINGLE_LETTER_MOD(BIT) \
4819 if (name->size_byte == 1) \
4822 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
4823 if (LEN == name->size_byte \
4824 && ! strncmp (name->data, NAME, LEN)) \
4828 SINGLE_LETTER_MOD (alt_modifier
);
4832 MULTI_LETTER_MOD (alt_modifier
, "alt", 3);
4836 SINGLE_LETTER_MOD (ctrl_modifier
);
4840 MULTI_LETTER_MOD (ctrl_modifier
, "ctrl", 4);
4841 MULTI_LETTER_MOD (ctrl_modifier
, "control", 7);
4845 SINGLE_LETTER_MOD (hyper_modifier
);
4849 MULTI_LETTER_MOD (hyper_modifier
, "hyper", 5);
4853 SINGLE_LETTER_MOD (meta_modifier
);
4857 MULTI_LETTER_MOD (meta_modifier
, "meta", 4);
4861 SINGLE_LETTER_MOD (shift_modifier
);
4865 MULTI_LETTER_MOD (shift_modifier
, "shift", 5);
4866 MULTI_LETTER_MOD (super_modifier
, "super", 5);
4867 SINGLE_LETTER_MOD (super_modifier
);
4871 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
4872 MULTI_LETTER_MOD (down_modifier
, "down", 4);
4873 MULTI_LETTER_MOD (double_modifier
, "double", 6);
4877 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
4880 #undef SINGLE_LETTER_MOD
4881 #undef MULTI_LETTER_MOD
4887 /* Return 1 if EVENT is a list whose elements are all integers or symbols.
4888 Such a list is not valid as an event,
4889 but it can be a Lucid-style event type list. */
4892 lucid_event_type_list_p (object
)
4897 if (! CONSP (object
))
4900 for (tail
= object
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4903 elt
= XCONS (tail
)->car
;
4904 if (! (INTEGERP (elt
) || SYMBOLP (elt
)))
4911 /* Store into *addr a value nonzero if terminal input chars are available.
4912 Serves the purpose of ioctl (0, FIONREAD, addr)
4913 but works even if FIONREAD does not exist.
4914 (In fact, this may actually read some input.)
4916 If DO_TIMERS_NOW is nonzero, actually run timer events that are ripe. */
4919 get_input_pending (addr
, do_timers_now
)
4923 /* First of all, have we already counted some input? */
4924 *addr
= !NILP (Vquit_flag
) || readable_events (do_timers_now
);
4926 /* If input is being read as it arrives, and we have none, there is none. */
4927 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
4930 /* Try to read some input and see how much we get. */
4932 *addr
= !NILP (Vquit_flag
) || readable_events (do_timers_now
);
4935 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
4938 gobble_input (expected
)
4943 if (interrupt_input
)
4946 mask
= sigblock (sigmask (SIGIO
));
4947 read_avail_input (expected
);
4951 #ifdef POLL_FOR_INPUT
4952 if (read_socket_hook
&& !interrupt_input
&& poll_suppress_count
== 0)
4955 mask
= sigblock (sigmask (SIGALRM
));
4956 read_avail_input (expected
);
4962 read_avail_input (expected
);
4966 /* Put a buffer_switch_event in the buffer
4967 so that read_key_sequence will notice the new current buffer. */
4970 record_asynch_buffer_change ()
4972 struct input_event event
;
4975 event
.kind
= buffer_switch_event
;
4976 event
.frame_or_window
= Qnil
;
4979 /* We don't need a buffer-switch event unless Emacs is waiting for input.
4980 The purpose of the event is to make read_key_sequence look up the
4981 keymaps again. If we aren't in read_key_sequence, we don't need one,
4982 and the event could cause trouble by messing up (input-pending-p). */
4983 tem
= Fwaiting_for_user_input_p ();
4987 /* We never need these events if we have no asynchronous subprocesses. */
4991 /* Make sure no interrupt happens while storing the event. */
4993 if (interrupt_input
)
4996 mask
= sigblock (sigmask (SIGIO
));
4997 kbd_buffer_store_event (&event
);
5004 kbd_buffer_store_event (&event
);
5011 /* Read any terminal input already buffered up by the system
5012 into the kbd_buffer, but do not wait.
5014 EXPECTED should be nonzero if the caller knows there is some input.
5016 Except on VMS, all input is read by this function.
5017 If interrupt_input is nonzero, this function MUST be called
5018 only when SIGIO is blocked.
5020 Returns the number of keyboard chars read, or -1 meaning
5021 this is a bad time to try to read input. */
5024 read_avail_input (expected
)
5027 struct input_event buf
[KBD_BUFFER_SIZE
];
5031 if (read_socket_hook
)
5032 /* No need for FIONREAD or fcntl; just say don't wait. */
5033 nread
= (*read_socket_hook
) (input_fd
, buf
, KBD_BUFFER_SIZE
, expected
);
5036 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
5037 the kbd_buffer can really hold. That may prevent loss
5038 of characters on some systems when input is stuffed at us. */
5039 unsigned char cbuf
[KBD_BUFFER_SIZE
- 1];
5042 /* Determine how many characters we should *try* to read. */
5045 #else /* not WINDOWSNT */
5047 n_to_read
= dos_keysns ();
5050 #else /* not MSDOS */
5052 /* Find out how much input is available. */
5053 if (ioctl (input_fd
, FIONREAD
, &n_to_read
) < 0)
5054 /* Formerly simply reported no input, but that sometimes led to
5055 a failure of Emacs to terminate.
5056 SIGHUP seems appropriate if we can't reach the terminal. */
5057 /* ??? Is it really right to send the signal just to this process
5058 rather than to the whole process group?
5059 Perhaps on systems with FIONREAD Emacs is alone in its group. */
5060 kill (getpid (), SIGHUP
);
5063 if (n_to_read
> sizeof cbuf
)
5064 n_to_read
= sizeof cbuf
;
5065 #else /* no FIONREAD */
5066 #if defined (USG) || defined (DGUX)
5067 /* Read some input if available, but don't wait. */
5068 n_to_read
= sizeof cbuf
;
5069 fcntl (input_fd
, F_SETFL
, O_NDELAY
);
5074 #endif /* not MSDOS */
5075 #endif /* not WINDOWSNT */
5077 /* Now read; for one reason or another, this will not block.
5078 NREAD is set to the number of chars read. */
5082 cbuf
[0] = dos_keyread ();
5085 nread
= read (input_fd
, cbuf
, n_to_read
);
5087 /* POSIX infers that processes which are not in the session leader's
5088 process group won't get SIGHUP's at logout time. BSDI adheres to
5089 this part standard and returns -1 from read(0) with errno==EIO
5090 when the control tty is taken away.
5091 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
5092 if (nread
== -1 && errno
== EIO
)
5094 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
5095 /* The kernel sometimes fails to deliver SIGHUP for ptys.
5096 This looks incorrect, but it isn't, because _BSD causes
5097 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
5098 and that causes a value other than 0 when there is no input. */
5104 /* We used to retry the read if it was interrupted.
5105 But this does the wrong thing when O_NDELAY causes
5106 an EAGAIN error. Does anybody know of a situation
5107 where a retry is actually needed? */
5109 nread
< 0 && (errno
== EAGAIN
5123 #if defined (USG) || defined (DGUX)
5124 fcntl (input_fd
, F_SETFL
, 0);
5125 #endif /* USG or DGUX */
5126 #endif /* no FIONREAD */
5127 for (i
= 0; i
< nread
; i
++)
5129 buf
[i
].kind
= ascii_keystroke
;
5130 buf
[i
].modifiers
= 0;
5131 if (meta_key
== 1 && (cbuf
[i
] & 0x80))
5132 buf
[i
].modifiers
= meta_modifier
;
5136 buf
[i
].code
= cbuf
[i
];
5137 XSETFRAME (buf
[i
].frame_or_window
, selected_frame
);
5141 /* Scan the chars for C-g and store them in kbd_buffer. */
5142 for (i
= 0; i
< nread
; i
++)
5144 kbd_buffer_store_event (&buf
[i
]);
5145 /* Don't look at input that follows a C-g too closely.
5146 This reduces lossage due to autorepeat on C-g. */
5147 if (buf
[i
].kind
== ascii_keystroke
5148 && buf
[i
].code
== quit_char
)
5154 #endif /* not VMS */
5156 #ifdef SIGIO /* for entire page */
5157 /* Note SIGIO has been undef'd if FIONREAD is missing. */
5160 input_available_signal (signo
)
5163 /* Must preserve main program's value of errno. */
5164 int old_errno
= errno
;
5166 extern int select_alarmed
;
5169 #if defined (USG) && !defined (POSIX_SIGNALS)
5170 /* USG systems forget handlers when they are used;
5171 must reestablish each time */
5172 signal (signo
, input_available_signal
);
5179 if (input_available_clear_time
)
5180 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
5185 nread
= read_avail_input (1);
5186 /* -1 means it's not ok to read the input now.
5187 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
5188 0 means there was no keyboard input available. */
5193 select_alarmed
= 1; /* Force the select emulator back to life */
5204 /* Send ourselves a SIGIO.
5206 This function exists so that the UNBLOCK_INPUT macro in
5207 blockinput.h can have some way to take care of input we put off
5208 dealing with, without assuming that every file which uses
5209 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
5211 reinvoke_input_signal ()
5214 kill (getpid (), SIGIO
);
5220 /* Return the prompt-string of a sparse keymap.
5221 This is the first element which is a string.
5222 Return nil if there is none. */
5230 register Lisp_Object tem
;
5239 static void menu_bar_item ();
5240 static void menu_bar_one_keymap ();
5242 /* These variables hold the vector under construction within
5243 menu_bar_items and its subroutines, and the current index
5244 for storing into that vector. */
5245 static Lisp_Object menu_bar_items_vector
;
5246 static int menu_bar_items_index
;
5248 /* Return a vector of menu items for a menu bar, appropriate
5249 to the current buffer. Each item has three elements in the vector:
5252 OLD is an old vector we can optionally reuse, or nil. */
5255 menu_bar_items (old
)
5258 /* The number of keymaps we're scanning right now, and the number of
5259 keymaps we have allocated space for. */
5262 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
5263 in the current keymaps, or nil where it is not a prefix. */
5266 Lisp_Object def
, tem
, tail
;
5275 struct gcpro gcpro1
;
5277 /* In order to build the menus, we need to call the keymap
5278 accessors. They all call QUIT. But this function is called
5279 during redisplay, during which a quit is fatal. So inhibit
5280 quitting while building the menus.
5281 We do this instead of specbind because (1) errors will clear it anyway
5282 and (2) this avoids risk of specpdl overflow. */
5283 oquit
= Vinhibit_quit
;
5287 menu_bar_items_vector
= old
;
5289 menu_bar_items_vector
= Fmake_vector (make_number (24), Qnil
);
5290 menu_bar_items_index
= 0;
5292 GCPRO1 (menu_bar_items_vector
);
5294 /* Build our list of keymaps.
5295 If we recognize a function key and replace its escape sequence in
5296 keybuf with its symbol, or if the sequence starts with a mouse
5297 click and we need to switch buffers, we jump back here to rebuild
5298 the initial keymaps from the current buffer. */
5302 /* Should overriding-terminal-local-map and overriding-local-map apply? */
5303 if (!NILP (Voverriding_local_map_menu_flag
))
5305 /* Yes, use them (if non-nil) as well as the global map. */
5306 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
5308 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
5309 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
5310 if (!NILP (Voverriding_local_map
))
5311 maps
[nmaps
++] = Voverriding_local_map
;
5315 /* No, so use major and minor mode keymaps. */
5316 nmaps
= current_minor_maps (NULL
, &tmaps
);
5317 maps
= (Lisp_Object
*) alloca ((nmaps
+ 2) * sizeof (maps
[0]));
5318 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
5319 #ifdef USE_TEXT_PROPERTIES
5320 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
5322 maps
[nmaps
++] = current_buffer
->keymap
;
5325 maps
[nmaps
++] = current_global_map
;
5328 /* Look up in each map the dummy prefix key `menu-bar'. */
5332 for (mapno
= nmaps
- 1; mapno
>= 0; mapno
--)
5334 if (! NILP (maps
[mapno
]))
5335 def
= get_keyelt (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0), 0);
5339 tem
= Fkeymapp (def
);
5341 menu_bar_one_keymap (def
);
5344 /* Move to the end those items that should be at the end. */
5346 for (tail
= Vmenu_bar_final_items
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5349 int end
= menu_bar_items_index
;
5351 for (i
= 0; i
< end
; i
+= 4)
5352 if (EQ (XCONS (tail
)->car
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
5354 Lisp_Object tem0
, tem1
, tem2
, tem3
;
5355 /* Move the item at index I to the end,
5356 shifting all the others forward. */
5357 tem0
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 0];
5358 tem1
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 1];
5359 tem2
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
5360 tem3
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3];
5362 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
5363 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
5364 (end
- i
- 4) * sizeof (Lisp_Object
));
5365 XVECTOR (menu_bar_items_vector
)->contents
[end
- 4] = tem0
;
5366 XVECTOR (menu_bar_items_vector
)->contents
[end
- 3] = tem1
;
5367 XVECTOR (menu_bar_items_vector
)->contents
[end
- 2] = tem2
;
5368 XVECTOR (menu_bar_items_vector
)->contents
[end
- 1] = tem3
;
5373 /* Add nil, nil, nil, nil at the end. */
5374 i
= menu_bar_items_index
;
5375 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
5378 int newsize
= 2 * i
;
5379 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
5380 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
5381 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
5382 menu_bar_items_vector
= tem
;
5384 /* Add this item. */
5385 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5386 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5387 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5388 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
5389 menu_bar_items_index
= i
;
5391 Vinhibit_quit
= oquit
;
5393 return menu_bar_items_vector
;
5396 /* Scan one map KEYMAP, accumulating any menu items it defines
5397 in menu_bar_items_vector. */
5400 menu_bar_one_keymap (keymap
)
5403 Lisp_Object tail
, item
, key
, binding
, item_string
, table
;
5405 /* Loop over all keymap entries that have menu strings. */
5406 for (tail
= keymap
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
5408 item
= XCONS (tail
)->car
;
5411 key
= XCONS (item
)->car
;
5412 binding
= XCONS (item
)->cdr
;
5413 if (CONSP (binding
))
5415 item_string
= XCONS (binding
)->car
;
5416 if (STRINGP (item_string
))
5417 menu_bar_item (key
, item_string
, Fcdr (binding
));
5419 else if (EQ (binding
, Qundefined
))
5420 menu_bar_item (key
, Qnil
, binding
);
5422 else if (VECTORP (item
))
5424 /* Loop over the char values represented in the vector. */
5425 int len
= XVECTOR (item
)->size
;
5427 for (c
= 0; c
< len
; c
++)
5429 Lisp_Object character
;
5430 XSETFASTINT (character
, c
);
5431 binding
= XVECTOR (item
)->contents
[c
];
5432 if (CONSP (binding
))
5434 item_string
= XCONS (binding
)->car
;
5435 if (STRINGP (item_string
))
5436 menu_bar_item (key
, item_string
, Fcdr (binding
));
5438 else if (EQ (binding
, Qundefined
))
5439 menu_bar_item (key
, Qnil
, binding
);
5445 /* This is used as the handler when calling internal_condition_case_1. */
5448 menu_bar_item_1 (arg
)
5454 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
5455 If there's already an item for KEY, add this DEF to it. */
5458 menu_bar_item (key
, item_string
, def
)
5459 Lisp_Object key
, item_string
, def
;
5462 Lisp_Object enabled
;
5465 /* Skip menu-bar equiv keys data. */
5466 if (CONSP (def
) && CONSP (XCONS (def
)->car
))
5467 def
= XCONS (def
)->cdr
;
5469 if (EQ (def
, Qundefined
))
5471 /* If a map has an explicit `undefined' as definition,
5472 discard any previously made menu bar item. */
5474 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
5475 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
5477 if (menu_bar_items_index
> i
+ 4)
5478 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 4],
5479 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
5480 (menu_bar_items_index
- i
- 4) * sizeof (Lisp_Object
));
5481 menu_bar_items_index
-= 4;
5485 /* If there's no definition for this key yet,
5486 just ignore `undefined'. */
5490 /* See if this entry is enabled. */
5495 /* No property, or nil, means enable.
5496 Otherwise, enable if value is not nil. */
5497 tem
= Fget (def
, Qmenu_enable
);
5499 /* (condition-case nil (eval tem)
5501 enabled
= internal_condition_case_1 (Feval
, tem
, Qerror
,
5505 /* Ignore this item if it's not enabled. */
5509 /* Find any existing item for this KEY. */
5510 for (i
= 0; i
< menu_bar_items_index
; i
+= 4)
5511 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
5514 /* If we did not find this KEY, add it at the end. */
5515 if (i
== menu_bar_items_index
)
5517 /* If vector is too small, get a bigger one. */
5518 if (i
+ 4 > XVECTOR (menu_bar_items_vector
)->size
)
5521 int newsize
= 2 * i
;
5522 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
5523 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
5524 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
5525 menu_bar_items_vector
= tem
;
5527 /* Add this item. */
5528 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = key
;
5529 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = item_string
;
5530 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Fcons (def
, Qnil
);
5531 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = make_number (0);
5532 menu_bar_items_index
= i
;
5534 /* We did find an item for this KEY. Add DEF to its list of maps. */
5538 old
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
5539 XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2] = Fcons (def
, old
);
5543 /* Read a character using menus based on maps in the array MAPS.
5544 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
5545 Return t if we displayed a menu but the user rejected it.
5547 PREV_EVENT is the previous input event, or nil if we are reading
5548 the first event of a key sequence.
5550 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
5551 if we used a mouse menu to read the input, or zero otherwise. If
5552 USED_MOUSE_MENU is null, we don't dereference it.
5554 The prompting is done based on the prompt-string of the map
5555 and the strings associated with various map elements.
5557 This can be done with X menus or with menus put in the minibuf.
5558 These are done in different ways, depending on how the input will be read.
5559 Menus using X are done after auto-saving in read-char, getting the input
5560 event from Fx_popup_menu; menus using the minibuf use read_char recursively
5561 and do auto-saving in the inner call of read_char. */
5564 read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
5567 Lisp_Object prev_event
;
5568 int *used_mouse_menu
;
5571 register Lisp_Object name
;
5572 Lisp_Object rest
, vector
;
5574 if (used_mouse_menu
)
5575 *used_mouse_menu
= 0;
5577 /* Use local over global Menu maps */
5579 if (! menu_prompting
)
5582 /* Optionally disregard all but the global map. */
5583 if (inhibit_local_menu_bar_menus
)
5585 maps
+= (nmaps
- 1);
5589 /* Get the menu name from the first map that has one (a prompt string). */
5590 for (mapno
= 0; mapno
< nmaps
; mapno
++)
5592 name
= map_prompt (maps
[mapno
]);
5597 /* If we don't have any menus, just read a character normally. */
5602 /* If we got to this point via a mouse click,
5603 use a real menu for mouse selection. */
5604 if (EVENT_HAS_PARAMETERS (prev_event
)
5605 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
))
5607 /* Display the menu and get the selection. */
5608 Lisp_Object
*realmaps
5609 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
5613 /* Use the maps that are not nil. */
5614 for (mapno
= 0; mapno
< nmaps
; mapno
++)
5615 if (!NILP (maps
[mapno
]))
5616 realmaps
[nmaps1
++] = maps
[mapno
];
5618 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
5623 record_menu_key (XCONS (value
)->car
);
5625 /* If we got multiple events, unread all but
5627 There is no way to prevent those unread events
5628 from showing up later in last_nonmenu_event.
5629 So turn symbol and integer events into lists,
5630 to indicate that they came from a mouse menu,
5631 so that when present in last_nonmenu_event
5632 they won't confuse things. */
5633 for (tem
= XCONS (value
)->cdr
; !NILP (tem
);
5634 tem
= XCONS (tem
)->cdr
)
5636 record_menu_key (XCONS (tem
)->car
);
5637 if (SYMBOLP (XCONS (tem
)->car
)
5638 || INTEGERP (XCONS (tem
)->car
))
5640 = Fcons (XCONS (tem
)->car
, Qnil
);
5643 /* If we got more than one event, put all but the first
5644 onto this list to be read later.
5645 Return just the first event now. */
5646 Vunread_command_events
5647 = nconc2 (XCONS (value
)->cdr
, Vunread_command_events
);
5648 value
= XCONS (value
)->car
;
5650 else if (NILP (value
))
5652 if (used_mouse_menu
)
5653 *used_mouse_menu
= 1;
5656 #endif /* HAVE_MENUS */
5660 /* Buffer in use so far for the minibuf prompts for menu keymaps.
5661 We make this bigger when necessary, and never free it. */
5662 static char *read_char_minibuf_menu_text
;
5663 /* Size of that buffer. */
5664 static int read_char_minibuf_menu_width
;
5667 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
5673 register Lisp_Object name
;
5675 int width
= FRAME_WIDTH (selected_frame
) - 4;
5678 Lisp_Object rest
, vector
;
5681 if (! menu_prompting
)
5684 /* Make sure we have a big enough buffer for the menu text. */
5685 if (read_char_minibuf_menu_text
== 0)
5687 read_char_minibuf_menu_width
= width
+ 4;
5688 read_char_minibuf_menu_text
= (char *) xmalloc (width
+ 4);
5690 else if (width
+ 4 > read_char_minibuf_menu_width
)
5692 read_char_minibuf_menu_width
= width
+ 4;
5693 read_char_minibuf_menu_text
5694 = (char *) xrealloc (read_char_minibuf_menu_text
, width
+ 4);
5696 menu
= read_char_minibuf_menu_text
;
5698 /* Get the menu name from the first map that has one (a prompt string). */
5699 for (mapno
= 0; mapno
< nmaps
; mapno
++)
5701 name
= map_prompt (maps
[mapno
]);
5706 /* If we don't have any menus, just read a character normally. */
5710 /* Prompt string always starts with map's prompt, and a space. */
5711 strcpy (menu
, XSTRING (name
)->data
);
5712 nlength
= XSTRING (name
)->size_byte
;
5713 menu
[nlength
++] = ':';
5714 menu
[nlength
++] = ' ';
5717 /* Start prompting at start of first map. */
5721 /* Present the documented bindings, a line at a time. */
5728 Lisp_Object orig_defn_macro
;
5730 /* Loop over elements of map. */
5735 /* If reached end of map, start at beginning of next map. */
5739 /* At end of last map, wrap around to first map if just starting,
5740 or end this line if already have something on it. */
5744 if (notfirst
|| nobindings
) break;
5749 /* Look at the next element of the map. */
5751 elt
= XVECTOR (vector
)->contents
[idx
];
5753 elt
= Fcar_safe (rest
);
5755 if (idx
< 0 && VECTORP (elt
))
5757 /* If we found a dense table in the keymap,
5758 advanced past it, but start scanning its contents. */
5759 rest
= Fcdr_safe (rest
);
5765 /* An ordinary element. */
5770 s
= Fcar_safe (Fcdr_safe (elt
)); /* alist */
5771 event
= Fcar_safe (elt
);
5775 s
= Fcar_safe (elt
); /* vector */
5776 XSETINT (event
, idx
);
5779 /* Ignore the element if it has no prompt string. */
5780 if (STRINGP (s
) && INTEGERP (event
))
5782 /* 1 if the char to type matches the string. */
5784 Lisp_Object upcased_event
, downcased_event
;
5787 upcased_event
= Fupcase (event
);
5788 downcased_event
= Fdowncase (event
);
5789 char_matches
= (XINT (upcased_event
) == XSTRING (s
)->data
[0]
5790 || XINT (downcased_event
) == XSTRING (s
)->data
[0]);
5792 desc
= Fsingle_key_description (event
);
5794 /* If we have room for the prompt string, add it to this line.
5795 If this is the first on the line, always add it. */
5796 if ((XSTRING (s
)->size
+ i
+ 2
5797 + (char_matches
? 0 : XSTRING (desc
)->size
+ 3))
5803 /* Punctuate between strings. */
5806 strcpy (menu
+ i
, ", ");
5812 /* If the char to type doesn't match the string's
5813 first char, explicitly show what char to type. */
5816 /* Add as much of string as fits. */
5817 thiswidth
= XSTRING (desc
)->size
;
5818 if (thiswidth
+ i
> width
)
5819 thiswidth
= width
- i
;
5820 bcopy (XSTRING (desc
)->data
, menu
+ i
, thiswidth
);
5822 strcpy (menu
+ i
, " = ");
5826 /* Add as much of string as fits. */
5827 thiswidth
= XSTRING (s
)->size
;
5828 if (thiswidth
+ i
> width
)
5829 thiswidth
= width
- i
;
5830 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
5836 /* If this element does not fit, end the line now,
5837 and save the element for the next line. */
5838 strcpy (menu
+ i
, "...");
5843 /* Move past this element. */
5844 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
5845 /* Handle reaching end of dense table. */
5850 rest
= Fcdr_safe (rest
);
5854 /* Prompt with that and read response. */
5855 message2_nolog (menu
, strlen (menu
),
5856 ! NILP (current_buffer
->enable_multibyte_characters
));
5858 /* Make believe its not a keyboard macro in case the help char
5859 is pressed. Help characters are not recorded because menu prompting
5860 is not used on replay.
5862 orig_defn_macro
= current_kboard
->defining_kbd_macro
;
5863 current_kboard
->defining_kbd_macro
= Qnil
;
5865 obj
= read_char (commandflag
, 0, 0, Qnil
, 0);
5866 while (BUFFERP (obj
));
5867 current_kboard
->defining_kbd_macro
= orig_defn_macro
;
5869 if (!INTEGERP (obj
))
5874 if (! EQ (obj
, menu_prompt_more_char
)
5875 && (!INTEGERP (menu_prompt_more_char
)
5876 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
5878 if (!NILP (current_kboard
->defining_kbd_macro
))
5879 store_kbd_macro_char (obj
);
5882 /* Help char - go round again */
5886 /* Reading key sequences. */
5888 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
5889 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
5890 keymap, or nil otherwise. Return the index of the first keymap in
5891 which KEY has any binding, or NMAPS if no map has a binding.
5893 If KEY is a meta ASCII character, treat it like meta-prefix-char
5894 followed by the corresponding non-meta character. Keymaps in
5895 CURRENT with non-prefix bindings for meta-prefix-char become nil in
5898 If KEY has no bindings in any of the CURRENT maps, NEXT is left
5901 NEXT may be the same array as CURRENT. */
5904 follow_key (key
, nmaps
, current
, defs
, next
)
5906 Lisp_Object
*current
, *defs
, *next
;
5909 int i
, first_binding
;
5912 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
5913 followed by the corresponding non-meta character.
5914 Put the results into DEFS, since we are going to alter that anyway.
5915 Do not alter CURRENT or NEXT. */
5916 if (INTEGERP (key
) && (XINT (key
) & CHAR_META
))
5918 for (i
= 0; i
< nmaps
; i
++)
5919 if (! NILP (current
[i
]))
5922 def
= get_keyelt (access_keymap (current
[i
],
5923 meta_prefix_char
, 1, 0), 0);
5925 /* Note that since we pass the resulting bindings through
5926 get_keymap_1, non-prefix bindings for meta-prefix-char
5928 defs
[i
] = get_keymap_1 (def
, 0, 1);
5934 XSETINT (key
, XFASTINT (key
) & ~CHAR_META
);
5937 first_binding
= nmaps
;
5938 for (i
= nmaps
- 1; i
>= 0; i
--)
5940 if (! NILP (current
[i
]))
5948 defs
[i
] = get_keyelt (access_keymap (map
, key
, 1, 0), 0);
5949 if (! NILP (defs
[i
]))
5956 /* Given the set of bindings we've found, produce the next set of maps. */
5957 if (first_binding
< nmaps
)
5958 for (i
= 0; i
< nmaps
; i
++)
5959 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0, 1);
5961 return first_binding
;
5964 /* Read a sequence of keys that ends with a non prefix character,
5965 storing it in KEYBUF, a buffer of size BUFSIZE.
5967 Return the length of the key sequence stored.
5968 Return -1 if the user rejected a command menu.
5970 Echo starting immediately unless `prompt' is 0.
5972 Where a key sequence ends depends on the currently active keymaps.
5973 These include any minor mode keymaps active in the current buffer,
5974 the current buffer's local map, and the global map.
5976 If a key sequence has no other bindings, we check Vfunction_key_map
5977 to see if some trailing subsequence might be the beginning of a
5978 function key's sequence. If so, we try to read the whole function
5979 key, and substitute its symbolic name into the key sequence.
5981 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
5982 `double-' events into similar click events, if that would make them
5983 bound. We try to turn `triple-' events first into `double-' events,
5986 If we get a mouse click in a mode line, vertical divider, or other
5987 non-text area, we treat the click as if it were prefixed by the
5988 symbol denoting that area - `mode-line', `vertical-line', or
5991 If the sequence starts with a mouse click, we read the key sequence
5992 with respect to the buffer clicked on, not the current buffer.
5994 If the user switches frames in the midst of a key sequence, we put
5995 off the switch-frame event until later; the next call to
5996 read_char will return it.
5998 If FIX_CURRENT_BUFFER is nonzero, we restore current_buffer
5999 from the selected window's buffer. */
6002 read_key_sequence (keybuf
, bufsize
, prompt
, dont_downcase_last
,
6003 can_return_switch_frame
, fix_current_buffer
)
6004 Lisp_Object
*keybuf
;
6007 int dont_downcase_last
;
6008 int can_return_switch_frame
;
6009 int fix_current_buffer
;
6011 int count
= specpdl_ptr
- specpdl
;
6013 /* How many keys there are in the current key sequence. */
6016 /* The length of the echo buffer when we started reading, and
6017 the length of this_command_keys when we started reading. */
6021 /* The number of keymaps we're scanning right now, and the number of
6022 keymaps we have allocated space for. */
6024 int nmaps_allocated
= 0;
6026 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
6027 the current keymaps. */
6030 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
6031 in the current keymaps, or nil where it is not a prefix. */
6032 Lisp_Object
*submaps
;
6034 /* The local map to start out with at start of key sequence. */
6035 Lisp_Object orig_local_map
;
6037 /* 1 if we have already considered switching to the local-map property
6038 of the place where a mouse click occurred. */
6039 int localized_local_map
= 0;
6041 /* The index in defs[] of the first keymap that has a binding for
6042 this key sequence. In other words, the lowest i such that
6043 defs[i] is non-nil. */
6046 /* If t < mock_input, then KEYBUF[t] should be read as the next
6049 We use this to recover after recognizing a function key. Once we
6050 realize that a suffix of the current key sequence is actually a
6051 function key's escape sequence, we replace the suffix with the
6052 function key's binding from Vfunction_key_map. Now keybuf
6053 contains a new and different key sequence, so the echo area,
6054 this_command_keys, and the submaps and defs arrays are wrong. In
6055 this situation, we set mock_input to t, set t to 0, and jump to
6056 restart_sequence; the loop will read keys from keybuf up until
6057 mock_input, thus rebuilding the state; and then it will resume
6058 reading characters from the keyboard. */
6061 /* If the sequence is unbound in submaps[], then
6062 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
6063 and fkey_map is its binding.
6065 These might be > t, indicating that all function key scanning
6066 should hold off until t reaches them. We do this when we've just
6067 recognized a function key, to avoid searching for the function
6068 key's again in Vfunction_key_map. */
6069 int fkey_start
= 0, fkey_end
= 0;
6070 Lisp_Object fkey_map
;
6072 /* Likewise, for key_translation_map. */
6073 int keytran_start
= 0, keytran_end
= 0;
6074 Lisp_Object keytran_map
;
6076 /* If we receive a ``switch-frame'' event in the middle of a key sequence,
6077 we put it off for later. While we're reading, we keep the event here. */
6078 Lisp_Object delayed_switch_frame
;
6080 /* See the comment below... */
6081 #if defined (GOBBLE_FIRST_EVENT)
6082 Lisp_Object first_event
;
6085 Lisp_Object original_uppercase
;
6086 int original_uppercase_position
= -1;
6088 /* Gets around Microsoft compiler limitations. */
6091 struct buffer
*starting_buffer
;
6093 /* Nonzero if we seem to have got the beginning of a binding
6094 in function_key_map. */
6095 int function_key_possible
= 0;
6096 int key_translation_possible
= 0;
6098 /* Save the status of key translation before each step,
6099 so that we can restore this after downcasing. */
6100 Lisp_Object prev_fkey_map
;
6101 int prev_fkey_start
;
6104 Lisp_Object prev_keytran_map
;
6105 int prev_keytran_start
;
6106 int prev_keytran_end
;
6110 last_nonmenu_event
= Qnil
;
6112 delayed_switch_frame
= Qnil
;
6113 fkey_map
= Vfunction_key_map
;
6114 keytran_map
= Vkey_translation_map
;
6116 /* If there is no function-key-map, turn off function key scanning. */
6117 if (NILP (Fkeymapp (Vfunction_key_map
)))
6118 fkey_start
= fkey_end
= bufsize
+ 1;
6120 /* If there is no key-translation-map, turn off scanning. */
6121 if (NILP (Fkeymapp (Vkey_translation_map
)))
6122 keytran_start
= keytran_end
= bufsize
+ 1;
6127 echo_prompt (XSTRING (prompt
)->data
);
6128 else if (cursor_in_echo_area
&& echo_keystrokes
)
6129 /* This doesn't put in a dash if the echo buffer is empty, so
6130 you don't always see a dash hanging out in the minibuffer. */
6134 /* Record the initial state of the echo area and this_command_keys;
6135 we will need to restore them if we replay a key sequence. */
6137 echo_start
= echo_length ();
6138 keys_start
= this_command_key_count
;
6139 this_single_command_key_start
= keys_start
;
6141 #if defined (GOBBLE_FIRST_EVENT)
6142 /* This doesn't quite work, because some of the things that read_char
6143 does cannot safely be bypassed. It seems too risky to try to make
6146 /* Read the first char of the sequence specially, before setting
6147 up any keymaps, in case a filter runs and switches buffers on us. */
6148 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
6150 #endif /* GOBBLE_FIRST_EVENT */
6152 orig_local_map
= get_local_map (PT
, current_buffer
);
6154 /* We jump here when the key sequence has been thoroughly changed, and
6155 we need to rescan it starting from the beginning. When we jump here,
6156 keybuf[0..mock_input] holds the sequence we should reread. */
6159 starting_buffer
= current_buffer
;
6160 function_key_possible
= 0;
6161 key_translation_possible
= 0;
6163 /* Build our list of keymaps.
6164 If we recognize a function key and replace its escape sequence in
6165 keybuf with its symbol, or if the sequence starts with a mouse
6166 click and we need to switch buffers, we jump back here to rebuild
6167 the initial keymaps from the current buffer. */
6171 if (!NILP (current_kboard
->Voverriding_terminal_local_map
)
6172 || !NILP (Voverriding_local_map
))
6174 if (3 > nmaps_allocated
)
6176 submaps
= (Lisp_Object
*) alloca (3 * sizeof (submaps
[0]));
6177 defs
= (Lisp_Object
*) alloca (3 * sizeof (defs
[0]));
6178 nmaps_allocated
= 3;
6181 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
6182 submaps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
6183 if (!NILP (Voverriding_local_map
))
6184 submaps
[nmaps
++] = Voverriding_local_map
;
6188 nmaps
= current_minor_maps (0, &maps
);
6189 if (nmaps
+ 2 > nmaps_allocated
)
6191 submaps
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (submaps
[0]));
6192 defs
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (defs
[0]));
6193 nmaps_allocated
= nmaps
+ 2;
6195 bcopy (maps
, submaps
, nmaps
* sizeof (submaps
[0]));
6196 #ifdef USE_TEXT_PROPERTIES
6197 submaps
[nmaps
++] = orig_local_map
;
6199 submaps
[nmaps
++] = current_buffer
->keymap
;
6202 submaps
[nmaps
++] = current_global_map
;
6205 /* Find an accurate initial value for first_binding. */
6206 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
6207 if (! NILP (submaps
[first_binding
]))
6210 /* Start from the beginning in keybuf. */
6213 /* These are no-ops the first time through, but if we restart, they
6214 revert the echo area and this_command_keys to their original state. */
6215 this_command_key_count
= keys_start
;
6216 if (INTERACTIVE
&& t
< mock_input
)
6217 echo_truncate (echo_start
);
6219 /* If the best binding for the current key sequence is a keymap, or
6220 we may be looking at a function key's escape sequence, keep on
6222 while ((first_binding
< nmaps
&& ! NILP (submaps
[first_binding
]))
6223 || (first_binding
>= nmaps
6225 /* mock input is never part of a function key's sequence. */
6226 && mock_input
<= fkey_start
)
6227 || (first_binding
>= nmaps
6228 && keytran_start
< t
&& key_translation_possible
)
6229 /* Don't return in the middle of a possible function key sequence,
6230 if the only bindings we found were via case conversion.
6231 Thus, if ESC O a has a function-key-map translation
6232 and ESC o has a binding, don't return after ESC O,
6233 so that we can translate ESC O plus the next character. */
6237 int used_mouse_menu
= 0;
6239 /* Where the last real key started. If we need to throw away a
6240 key that has expanded into more than one element of keybuf
6241 (say, a mouse click on the mode line which is being treated
6242 as [mode-line (mouse-...)], then we backtrack to this point
6244 int last_real_key_start
;
6246 /* These variables are analogous to echo_start and keys_start;
6247 while those allow us to restart the entire key sequence,
6248 echo_local_start and keys_local_start allow us to throw away
6250 int echo_local_start
, keys_local_start
, local_first_binding
;
6253 error ("Key sequence too long");
6256 echo_local_start
= echo_length ();
6257 keys_local_start
= this_command_key_count
;
6258 local_first_binding
= first_binding
;
6261 /* These are no-ops, unless we throw away a keystroke below and
6262 jumped back up to replay_key; in that case, these restore the
6263 variables to their original state, allowing us to replay the
6265 if (INTERACTIVE
&& t
< mock_input
)
6266 echo_truncate (echo_local_start
);
6267 this_command_key_count
= keys_local_start
;
6268 first_binding
= local_first_binding
;
6270 /* By default, assume each event is "real". */
6271 last_real_key_start
= t
;
6273 /* Does mock_input indicate that we are re-reading a key sequence? */
6277 add_command_key (key
);
6278 if (echo_keystrokes
)
6282 /* If not, we should actually read a character. */
6285 struct buffer
*buf
= current_buffer
;
6289 KBOARD
*interrupted_kboard
= current_kboard
;
6290 struct frame
*interrupted_frame
= selected_frame
;
6291 if (setjmp (wrong_kboard_jmpbuf
))
6293 if (!NILP (delayed_switch_frame
))
6295 interrupted_kboard
->kbd_queue
6296 = Fcons (delayed_switch_frame
,
6297 interrupted_kboard
->kbd_queue
);
6298 delayed_switch_frame
= Qnil
;
6301 interrupted_kboard
->kbd_queue
6302 = Fcons (keybuf
[--t
], interrupted_kboard
->kbd_queue
);
6304 /* If the side queue is non-empty, ensure it begins with a
6305 switch-frame, so we'll replay it in the right context. */
6306 if (CONSP (interrupted_kboard
->kbd_queue
)
6307 && (key
= XCONS (interrupted_kboard
->kbd_queue
)->car
,
6308 !(EVENT_HAS_PARAMETERS (key
)
6309 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)),
6313 XSETFRAME (frame
, interrupted_frame
);
6314 interrupted_kboard
->kbd_queue
6315 = Fcons (make_lispy_switch_frame (frame
),
6316 interrupted_kboard
->kbd_queue
);
6319 orig_local_map
= get_local_map (PT
, current_buffer
);
6320 goto replay_sequence
;
6323 key
= read_char (NILP (prompt
), nmaps
, submaps
, last_nonmenu_event
,
6327 /* read_char returns t when it shows a menu and the user rejects it.
6332 /* read_char returns -1 at the end of a macro.
6333 Emacs 18 handles this by returning immediately with a
6334 zero, so that's what we'll do. */
6335 if (INTEGERP (key
) && XINT (key
) == -1)
6338 /* The Microsoft C compiler can't handle the goto that
6344 /* If the current buffer has been changed from under us, the
6345 keymap may have changed, so replay the sequence. */
6349 /* Reset the current buffer from the selected window
6350 in case something changed the former and not the latter.
6351 This is to be more consistent with the behavior
6352 of the command_loop_1. */
6353 if (fix_current_buffer
)
6354 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
6355 Fset_buffer (XWINDOW (selected_window
)->buffer
);
6357 orig_local_map
= get_local_map (PT
, current_buffer
);
6358 goto replay_sequence
;
6361 /* If we have a quit that was typed in another frame, and
6362 quit_throw_to_read_char switched buffers,
6363 replay to get the right keymap. */
6364 if (XINT (key
) == quit_char
&& current_buffer
!= starting_buffer
)
6369 orig_local_map
= get_local_map (PT
, current_buffer
);
6370 goto replay_sequence
;
6376 /* Clicks in non-text areas get prefixed by the symbol
6377 in their CHAR-ADDRESS field. For example, a click on
6378 the mode line is prefixed by the symbol `mode-line'.
6380 Furthermore, key sequences beginning with mouse clicks
6381 are read using the keymaps of the buffer clicked on, not
6382 the current buffer. So we may have to switch the buffer
6385 When we turn one event into two events, we must make sure
6386 that neither of the two looks like the original--so that,
6387 if we replay the events, they won't be expanded again.
6388 If not for this, such reexpansion could happen either here
6389 or when user programs play with this-command-keys. */
6390 if (EVENT_HAS_PARAMETERS (key
))
6394 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
6395 if (EQ (kind
, Qmouse_click
))
6397 Lisp_Object window
, posn
;
6399 window
= POSN_WINDOW (EVENT_START (key
));
6400 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
6403 /* We're looking at the second event of a
6404 sequence which we expanded before. Set
6405 last_real_key_start appropriately. */
6407 last_real_key_start
= t
- 1;
6410 /* Key sequences beginning with mouse clicks are
6411 read using the keymaps in the buffer clicked on,
6412 not the current buffer. If we're at the
6413 beginning of a key sequence, switch buffers. */
6414 if (last_real_key_start
== 0
6416 && BUFFERP (XWINDOW (window
)->buffer
)
6417 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
6422 /* Arrange to go back to the original buffer once we're
6423 done reading the key sequence. Note that we can't
6424 use save_excursion_{save,restore} here, because they
6425 save point as well as the current buffer; we don't
6426 want to save point, because redisplay may change it,
6427 to accommodate a Fset_window_start or something. We
6428 don't want to do this at the top of the function,
6429 because we may get input from a subprocess which
6430 wants to change the selected window and stuff (say,
6432 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
6434 set_buffer_internal (XBUFFER (XWINDOW (window
)->buffer
));
6435 orig_local_map
= get_local_map (PT
, current_buffer
);
6436 goto replay_sequence
;
6438 /* For a mouse click, get the local text-property keymap
6439 of the place clicked on, rather than point. */
6440 if (last_real_key_start
== 0 && CONSP (XCONS (key
)->cdr
)
6441 && ! localized_local_map
)
6443 Lisp_Object map_here
, start
, pos
;
6445 localized_local_map
= 1;
6446 start
= EVENT_START (key
);
6447 if (CONSP (start
) && CONSP (XCONS (start
)->cdr
))
6449 pos
= POSN_BUFFER_POSN (start
);
6451 && XINT (pos
) >= BEG
&& XINT (pos
) <= Z
)
6453 map_here
= get_local_map (XINT (pos
), current_buffer
);
6454 if (!EQ (map_here
, orig_local_map
))
6456 orig_local_map
= map_here
;
6460 goto replay_sequence
;
6466 /* Expand mode-line and scroll-bar events into two events:
6467 use posn as a fake prefix key. */
6470 if (t
+ 1 >= bufsize
)
6471 error ("Key sequence too long");
6476 /* Zap the position in key, so we know that we've
6477 expanded it, and don't try to do so again. */
6478 POSN_BUFFER_POSN (EVENT_START (key
))
6479 = Fcons (posn
, Qnil
);
6483 else if (EQ (kind
, Qswitch_frame
))
6485 /* If we're at the beginning of a key sequence, and the caller
6486 says it's okay, go ahead and return this event. If we're
6487 in the midst of a key sequence, delay it until the end. */
6488 if (t
> 0 || !can_return_switch_frame
)
6490 delayed_switch_frame
= key
;
6494 else if (CONSP (XCONS (key
)->cdr
)
6495 && CONSP (EVENT_START (key
))
6496 && CONSP (XCONS (EVENT_START (key
))->cdr
))
6500 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
6501 /* Handle menu-bar events:
6502 insert the dummy prefix event `menu-bar'. */
6503 if (EQ (posn
, Qmenu_bar
))
6505 if (t
+ 1 >= bufsize
)
6506 error ("Key sequence too long");
6510 /* Zap the position in key, so we know that we've
6511 expanded it, and don't try to do so again. */
6512 POSN_BUFFER_POSN (EVENT_START (key
))
6513 = Fcons (posn
, Qnil
);
6516 goto replay_sequence
;
6518 else if (CONSP (posn
))
6520 /* We're looking at the second event of a
6521 sequence which we expanded before. Set
6522 last_real_key_start appropriately. */
6523 if (last_real_key_start
== t
&& t
> 0)
6524 last_real_key_start
= t
- 1;
6529 /* We have finally decided that KEY is something we might want
6531 first_binding
= (follow_key (key
,
6532 nmaps
- first_binding
,
6533 submaps
+ first_binding
,
6534 defs
+ first_binding
,
6535 submaps
+ first_binding
)
6538 /* If KEY wasn't bound, we'll try some fallbacks. */
6539 if (first_binding
>= nmaps
)
6543 head
= EVENT_HEAD (key
);
6544 if (help_char_p (head
) && t
> 0)
6546 read_key_sequence_cmd
= Vprefix_help_command
;
6548 last_nonmenu_event
= key
;
6549 /* The Microsoft C compiler can't handle the goto that
6557 Lisp_Object breakdown
;
6560 breakdown
= parse_modifiers (head
);
6561 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
6562 /* Attempt to reduce an unbound mouse event to a simpler
6563 event that is bound:
6564 Drags reduce to clicks.
6565 Double-clicks reduce to clicks.
6566 Triple-clicks reduce to double-clicks, then to clicks.
6567 Down-clicks are eliminated.
6568 Double-downs reduce to downs, then are eliminated.
6569 Triple-downs reduce to double-downs, then to downs,
6570 then are eliminated. */
6571 if (modifiers
& (down_modifier
| drag_modifier
6572 | double_modifier
| triple_modifier
))
6574 while (modifiers
& (down_modifier
| drag_modifier
6575 | double_modifier
| triple_modifier
))
6577 Lisp_Object new_head
, new_click
;
6578 if (modifiers
& triple_modifier
)
6579 modifiers
^= (double_modifier
| triple_modifier
);
6580 else if (modifiers
& double_modifier
)
6581 modifiers
&= ~double_modifier
;
6582 else if (modifiers
& drag_modifier
)
6583 modifiers
&= ~drag_modifier
;
6586 /* Dispose of this `down' event by simply jumping
6587 back to replay_key, to get another event.
6589 Note that if this event came from mock input,
6590 then just jumping back to replay_key will just
6591 hand it to us again. So we have to wipe out any
6594 We could delete keybuf[t] and shift everything
6595 after that to the left by one spot, but we'd also
6596 have to fix up any variable that points into
6597 keybuf, and shifting isn't really necessary
6600 Adding prefixes for non-textual mouse clicks
6601 creates two characters of mock input, and both
6602 must be thrown away. If we're only looking at
6603 the prefix now, we can just jump back to
6604 replay_key. On the other hand, if we've already
6605 processed the prefix, and now the actual click
6606 itself is giving us trouble, then we've lost the
6607 state of the keymaps we want to backtrack to, and
6608 we need to replay the whole sequence to rebuild
6611 Beyond that, only function key expansion could
6612 create more than two keys, but that should never
6613 generate mouse events, so it's okay to zero
6614 mock_input in that case too.
6616 Isn't this just the most wonderful code ever? */
6617 if (t
== last_real_key_start
)
6624 mock_input
= last_real_key_start
;
6625 goto replay_sequence
;
6630 = apply_modifiers (modifiers
, XCONS (breakdown
)->car
);
6632 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
6634 /* Look for a binding for this new key. follow_key
6635 promises that it didn't munge submaps the
6636 last time we called it, since key was unbound. */
6638 = (follow_key (new_click
,
6639 nmaps
- local_first_binding
,
6640 submaps
+ local_first_binding
,
6641 defs
+ local_first_binding
,
6642 submaps
+ local_first_binding
)
6643 + local_first_binding
);
6645 /* If that click is bound, go for it. */
6646 if (first_binding
< nmaps
)
6651 /* Otherwise, we'll leave key set to the drag event. */
6658 /* Normally, last_nonmenu_event gets the previous key we read.
6659 But when a mouse popup menu is being used,
6660 we don't update last_nonmenu_event; it continues to hold the mouse
6661 event that preceded the first level of menu. */
6662 if (!used_mouse_menu
)
6663 last_nonmenu_event
= key
;
6665 /* Record what part of this_command_keys is the current key sequence. */
6666 this_single_command_key_start
= this_command_key_count
- t
;
6668 prev_fkey_map
= fkey_map
;
6669 prev_fkey_start
= fkey_start
;
6670 prev_fkey_end
= fkey_end
;
6672 prev_keytran_map
= keytran_map
;
6673 prev_keytran_start
= keytran_start
;
6674 prev_keytran_end
= keytran_end
;
6676 /* If the sequence is unbound, see if we can hang a function key
6677 off the end of it. We only want to scan real keyboard input
6678 for function key sequences, so if mock_input says that we're
6679 re-reading old events, don't examine it. */
6680 if (first_binding
>= nmaps
6683 Lisp_Object fkey_next
;
6685 /* Continue scan from fkey_end until we find a bound suffix.
6686 If we fail, increment fkey_start
6687 and start fkey_end from there. */
6688 while (fkey_end
< t
)
6692 key
= keybuf
[fkey_end
++];
6693 /* Look up meta-characters by prefixing them
6694 with meta_prefix_char. I hate this. */
6695 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
6700 (access_keymap (fkey_map
, meta_prefix_char
, 1, 0), 0),
6702 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
6705 fkey_next
= fkey_map
;
6708 = get_keyelt (access_keymap (fkey_next
, key
, 1, 0), 0);
6710 #if 0 /* I didn't turn this on, because it might cause trouble
6711 for the mapping of return into C-m and tab into C-i. */
6712 /* Optionally don't map function keys into other things.
6713 This enables the user to redefine kp- keys easily. */
6714 if (SYMBOLP (key
) && !NILP (Vinhibit_function_key_mapping
))
6718 /* If the function key map gives a function, not an
6719 array, then call the function with no args and use
6720 its value instead. */
6721 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
6724 struct gcpro gcpro1
, gcpro2
, gcpro3
;
6728 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
6729 fkey_next
= call1 (fkey_next
, prompt
);
6731 /* If the function returned something invalid,
6732 barf--don't ignore it.
6733 (To ignore it safely, we would need to gcpro a bunch of
6734 other variables.) */
6735 if (! (VECTORP (fkey_next
) || STRINGP (fkey_next
)))
6736 error ("Function in key-translation-map returns invalid key sequence");
6739 function_key_possible
= ! NILP (fkey_next
);
6741 /* If keybuf[fkey_start..fkey_end] is bound in the
6742 function key map and it's a suffix of the current
6743 sequence (i.e. fkey_end == t), replace it with
6744 the binding and restart with fkey_start at the end. */
6745 if ((VECTORP (fkey_next
) || STRINGP (fkey_next
))
6748 int len
= XFASTINT (Flength (fkey_next
));
6750 t
= fkey_start
+ len
;
6752 error ("Key sequence too long");
6754 if (VECTORP (fkey_next
))
6755 bcopy (XVECTOR (fkey_next
)->contents
,
6756 keybuf
+ fkey_start
,
6757 (t
- fkey_start
) * sizeof (keybuf
[0]));
6758 else if (STRINGP (fkey_next
))
6762 for (i
= 0; i
< len
; i
++)
6763 XSETFASTINT (keybuf
[fkey_start
+ i
],
6764 XSTRING (fkey_next
)->data
[i
]);
6768 fkey_start
= fkey_end
= t
;
6769 fkey_map
= Vfunction_key_map
;
6771 /* Do pass the results through key-translation-map. */
6772 keytran_start
= keytran_end
= 0;
6773 keytran_map
= Vkey_translation_map
;
6775 goto replay_sequence
;
6778 fkey_map
= get_keymap_1 (fkey_next
, 0, 1);
6780 /* If we no longer have a bound suffix, try a new positions for
6782 if (NILP (fkey_map
))
6784 fkey_end
= ++fkey_start
;
6785 fkey_map
= Vfunction_key_map
;
6786 function_key_possible
= 0;
6791 /* Look for this sequence in key-translation-map. */
6793 Lisp_Object keytran_next
;
6795 /* Scan from keytran_end until we find a bound suffix. */
6796 while (keytran_end
< t
)
6800 key
= keybuf
[keytran_end
++];
6801 /* Look up meta-characters by prefixing them
6802 with meta_prefix_char. I hate this. */
6803 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
6808 (access_keymap (keytran_map
, meta_prefix_char
, 1, 0), 0),
6810 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
6813 keytran_next
= keytran_map
;
6816 = get_keyelt (access_keymap (keytran_next
, key
, 1, 0), 0);
6818 /* If the key translation map gives a function, not an
6819 array, then call the function with no args and use
6820 its value instead. */
6821 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
6822 && keytran_end
== t
)
6824 struct gcpro gcpro1
, gcpro2
, gcpro3
;
6828 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
6829 keytran_next
= call1 (keytran_next
, prompt
);
6831 /* If the function returned something invalid,
6832 barf--don't ignore it.
6833 (To ignore it safely, we would need to gcpro a bunch of
6834 other variables.) */
6835 if (! (VECTORP (keytran_next
) || STRINGP (keytran_next
)))
6836 error ("Function in key-translation-map returns invalid key sequence");
6839 key_translation_possible
= ! NILP (keytran_next
);
6841 /* If keybuf[keytran_start..keytran_end] is bound in the
6842 key translation map and it's a suffix of the current
6843 sequence (i.e. keytran_end == t), replace it with
6844 the binding and restart with keytran_start at the end. */
6845 if ((VECTORP (keytran_next
) || STRINGP (keytran_next
))
6846 && keytran_end
== t
)
6848 int len
= XFASTINT (Flength (keytran_next
));
6850 t
= keytran_start
+ len
;
6852 error ("Key sequence too long");
6854 if (VECTORP (keytran_next
))
6855 bcopy (XVECTOR (keytran_next
)->contents
,
6856 keybuf
+ keytran_start
,
6857 (t
- keytran_start
) * sizeof (keybuf
[0]));
6858 else if (STRINGP (keytran_next
))
6862 for (i
= 0; i
< len
; i
++)
6863 XSETFASTINT (keybuf
[keytran_start
+ i
],
6864 XSTRING (keytran_next
)->data
[i
]);
6868 keytran_start
= keytran_end
= t
;
6869 keytran_map
= Vkey_translation_map
;
6871 /* Don't pass the results of key-translation-map
6872 through function-key-map. */
6873 fkey_start
= fkey_end
= t
;
6874 fkey_map
= Vkey_translation_map
;
6876 goto replay_sequence
;
6879 keytran_map
= get_keymap_1 (keytran_next
, 0, 1);
6881 /* If we no longer have a bound suffix, try a new positions for
6883 if (NILP (keytran_map
))
6885 keytran_end
= ++keytran_start
;
6886 keytran_map
= Vkey_translation_map
;
6887 key_translation_possible
= 0;
6892 /* If KEY is not defined in any of the keymaps,
6893 and cannot be part of a function key or translation,
6894 and is an upper case letter
6895 use the corresponding lower-case letter instead. */
6896 if (first_binding
== nmaps
&& ! function_key_possible
6897 && ! key_translation_possible
6899 && ((((XINT (key
) & 0x3ffff)
6900 < XCHAR_TABLE (current_buffer
->downcase_table
)->size
)
6901 && UPPERCASEP (XINT (key
) & 0x3ffff))
6902 || (XINT (key
) & shift_modifier
)))
6904 Lisp_Object new_key
;
6906 original_uppercase
= key
;
6907 original_uppercase_position
= t
- 1;
6909 if (XINT (key
) & shift_modifier
)
6910 XSETINT (new_key
, XINT (key
) & ~shift_modifier
);
6912 XSETINT (new_key
, (DOWNCASE (XINT (key
) & 0x3ffff)
6913 | (XINT (key
) & ~0x3ffff)));
6915 /* We have to do this unconditionally, regardless of whether
6916 the lower-case char is defined in the keymaps, because they
6917 might get translated through function-key-map. */
6918 keybuf
[t
- 1] = new_key
;
6921 fkey_map
= prev_fkey_map
;
6922 fkey_start
= prev_fkey_start
;
6923 fkey_end
= prev_fkey_end
;
6925 keytran_map
= prev_keytran_map
;
6926 keytran_start
= prev_keytran_start
;
6927 keytran_end
= prev_keytran_end
;
6929 goto replay_sequence
;
6931 /* If KEY is not defined in any of the keymaps,
6932 and cannot be part of a function key or translation,
6933 and is a shifted function key,
6934 use the corresponding unshifted function key instead. */
6935 if (first_binding
== nmaps
&& ! function_key_possible
6936 && ! key_translation_possible
6939 Lisp_Object breakdown
;
6942 breakdown
= parse_modifiers (key
);
6943 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
6944 if (modifiers
& shift_modifier
)
6946 Lisp_Object new_key
;
6948 original_uppercase
= key
;
6949 original_uppercase_position
= t
- 1;
6951 modifiers
&= ~shift_modifier
;
6952 new_key
= apply_modifiers (modifiers
,
6953 XCONS (breakdown
)->car
);
6955 keybuf
[t
- 1] = new_key
;
6958 fkey_map
= prev_fkey_map
;
6959 fkey_start
= prev_fkey_start
;
6960 fkey_end
= prev_fkey_end
;
6962 keytran_map
= prev_keytran_map
;
6963 keytran_start
= prev_keytran_start
;
6964 keytran_end
= prev_keytran_end
;
6966 goto replay_sequence
;
6972 read_key_sequence_cmd
= (first_binding
< nmaps
6973 ? defs
[first_binding
]
6976 unread_switch_frame
= delayed_switch_frame
;
6977 unbind_to (count
, Qnil
);
6979 /* Don't downcase the last character if the caller says don't.
6980 Don't downcase it if the result is undefined, either. */
6981 if ((dont_downcase_last
|| first_binding
>= nmaps
)
6982 && t
- 1 == original_uppercase_position
)
6983 keybuf
[t
- 1] = original_uppercase
;
6985 /* Occasionally we fabricate events, perhaps by expanding something
6986 according to function-key-map, or by adding a prefix symbol to a
6987 mouse click in the scroll bar or modeline. In this cases, return
6988 the entire generated key sequence, even if we hit an unbound
6989 prefix or a definition before the end. This means that you will
6990 be able to push back the event properly, and also means that
6991 read-key-sequence will always return a logical unit.
6994 for (; t
< mock_input
; t
++)
6996 if (echo_keystrokes
)
6997 echo_char (keybuf
[t
]);
6998 add_command_key (keybuf
[t
]);
7004 #if 0 /* This doc string is too long for some compilers.
7005 This commented-out definition serves for DOC. */
7006 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
7007 "Read a sequence of keystrokes and return as a string or vector.\n\
7008 The sequence is sufficient to specify a non-prefix command in the\n\
7009 current local and global maps.\n\
7011 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
7012 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
7013 as a continuation of the previous key.\n\
7015 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not\n\
7016 convert the last event to lower case. (Normally any upper case event\n\
7017 is converted to lower case if the original event is undefined and the lower\n\
7018 case equivalent is defined.) A non-nil value is appropriate for reading\n\
7019 a key sequence to be defined.\n\
7021 A C-g typed while in this function is treated like any other character,\n\
7022 and `quit-flag' is not set.\n\
7024 If the key sequence starts with a mouse click, then the sequence is read\n\
7025 using the keymaps of the buffer of the window clicked in, not the buffer\n\
7026 of the selected window as normal.\n\
7028 `read-key-sequence' drops unbound button-down events, since you normally\n\
7029 only care about the click or drag events which follow them. If a drag\n\
7030 or multi-click event is unbound, but the corresponding click event would\n\
7031 be bound, `read-key-sequence' turns the event into a click event at the\n\
7032 drag's starting position. This means that you don't have to distinguish\n\
7033 between click and drag, double, or triple events unless you want to.\n\
7035 `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\
7036 lines separating windows, and scroll bars with imaginary keys\n\
7037 `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\
7039 Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this\n\
7040 function will process a switch-frame event if the user switches frames\n\
7041 before typing anything. If the user switches frames in the middle of a\n\
7042 key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME\n\
7043 is nil, then the event will be put off until after the current key sequence.\n\
7045 `read-key-sequence' checks `function-key-map' for function key\n\
7046 sequences, where they wouldn't conflict with ordinary bindings. See\n\
7047 `function-key-map' for more details.")
7048 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
)
7051 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
7053 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
)
7054 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
7055 Lisp_Object can_return_switch_frame
;
7057 Lisp_Object keybuf
[30];
7059 struct gcpro gcpro1
, gcpro2
;
7062 CHECK_STRING (prompt
, 0);
7065 bzero (keybuf
, sizeof keybuf
);
7067 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
7069 if (NILP (continue_echo
))
7071 this_command_key_count
= 0;
7072 this_single_command_key_start
= 0;
7075 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
7076 prompt
, ! NILP (dont_downcase_last
),
7077 ! NILP (can_return_switch_frame
), 0);
7085 return make_event_array (i
, keybuf
);
7088 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 4, 0,
7089 "Execute CMD as an editor command.\n\
7090 CMD must be a symbol that satisfies the `commandp' predicate.\n\
7091 Optional second arg RECORD-FLAG non-nil\n\
7092 means unconditionally put this command in `command-history'.\n\
7093 Otherwise, that is done only if an arg is read using the minibuffer.\n\
7094 The argument KEYS specifies the value to use instead of (this-command-keys)\n\
7095 when reading the arguments; if it is nil, (this-command-keys) is used.\n\
7096 The argument SPECIAL, if non-nil, means that this command is executing\n\
7097 a special event, so ignore the prefix argument and don't clear it.")
7098 (cmd
, record_flag
, keys
, special
)
7099 Lisp_Object cmd
, record_flag
, keys
, special
;
7101 register Lisp_Object final
;
7102 register Lisp_Object tem
;
7103 Lisp_Object prefixarg
;
7104 struct backtrace backtrace
;
7105 extern int debug_on_next_call
;
7107 debug_on_next_call
= 0;
7111 prefixarg
= current_kboard
->Vprefix_arg
;
7112 Vcurrent_prefix_arg
= prefixarg
;
7113 current_kboard
->Vprefix_arg
= Qnil
;
7120 tem
= Fget (cmd
, Qdisabled
);
7121 if (!NILP (tem
) && !NILP (Vrun_hooks
))
7123 tem
= Fsymbol_value (Qdisabled_command_hook
);
7125 return call1 (Vrun_hooks
, Qdisabled_command_hook
);
7131 final
= Findirect_function (cmd
);
7133 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
7135 struct gcpro gcpro1
, gcpro2
;
7137 GCPRO2 (cmd
, prefixarg
);
7138 do_autoload (final
, cmd
);
7145 if (STRINGP (final
) || VECTORP (final
))
7147 /* If requested, place the macro in the command history. For
7148 other sorts of commands, call-interactively takes care of
7150 if (!NILP (record_flag
))
7152 = Fcons (Fcons (Qexecute_kbd_macro
,
7153 Fcons (final
, Fcons (prefixarg
, Qnil
))),
7156 return Fexecute_kbd_macro (final
, prefixarg
);
7158 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
7160 backtrace
.next
= backtrace_list
;
7161 backtrace_list
= &backtrace
;
7162 backtrace
.function
= &Qcall_interactively
;
7163 backtrace
.args
= &cmd
;
7164 backtrace
.nargs
= 1;
7165 backtrace
.evalargs
= 0;
7167 tem
= Fcall_interactively (cmd
, record_flag
, keys
);
7169 backtrace_list
= backtrace
.next
;
7175 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
7177 "Read function name, then read its arguments and call it.")
7179 Lisp_Object prefixarg
;
7181 Lisp_Object function
;
7183 Lisp_Object saved_keys
;
7184 Lisp_Object bindings
, value
;
7185 struct gcpro gcpro1
, gcpro2
;
7187 saved_keys
= Fvector (this_command_key_count
,
7188 XVECTOR (this_command_keys
)->contents
);
7190 GCPRO2 (saved_keys
, prefixarg
);
7192 if (EQ (prefixarg
, Qminus
))
7194 else if (CONSP (prefixarg
) && XINT (XCONS (prefixarg
)->car
) == 4)
7195 strcpy (buf
, "C-u ");
7196 else if (CONSP (prefixarg
) && INTEGERP (XCONS (prefixarg
)->car
))
7198 if (sizeof (int) == sizeof (EMACS_INT
))
7199 sprintf (buf
, "%d ", XINT (XCONS (prefixarg
)->car
));
7200 else if (sizeof (long) == sizeof (EMACS_INT
))
7201 sprintf (buf
, "%ld ", XINT (XCONS (prefixarg
)->car
));
7205 else if (INTEGERP (prefixarg
))
7207 if (sizeof (int) == sizeof (EMACS_INT
))
7208 sprintf (buf
, "%d ", XINT (prefixarg
));
7209 else if (sizeof (long) == sizeof (EMACS_INT
))
7210 sprintf (buf
, "%ld ", XINT (prefixarg
));
7215 /* This isn't strictly correct if execute-extended-command
7216 is bound to anything else. Perhaps it should use
7217 this_command_keys? */
7218 strcat (buf
, "M-x ");
7220 /* Prompt with buf, and then read a string, completing from and
7221 restricting to the set of all defined commands. Don't provide
7222 any initial input. Save the command read on the extended-command
7224 function
= Fcompleting_read (build_string (buf
),
7225 Vobarray
, Qcommandp
,
7226 Qt
, Qnil
, Qextended_command_history
, Qnil
,
7229 if (STRINGP (function
) && XSTRING (function
)->size
== 0)
7230 error ("No command name given");
7232 /* Set this_command_keys to the concatenation of saved_keys and
7233 function, followed by a RET. */
7235 struct Lisp_String
*str
;
7239 this_command_key_count
= 0;
7240 this_single_command_key_start
= 0;
7242 keys
= XVECTOR (saved_keys
)->contents
;
7243 for (i
= 0; i
< XVECTOR (saved_keys
)->size
; i
++)
7244 add_command_key (keys
[i
]);
7246 str
= XSTRING (function
);
7247 for (i
= 0; i
< str
->size
; i
++)
7248 add_command_key (Faref (function
, make_number (i
)));
7250 add_command_key (make_number ('\015'));
7255 function
= Fintern (function
, Qnil
);
7256 current_kboard
->Vprefix_arg
= prefixarg
;
7257 this_command
= function
;
7259 /* If enabled, show which key runs this command. */
7260 if (!NILP (Vsuggest_key_bindings
)
7261 && NILP (Vexecuting_macro
)
7262 && SYMBOLP (function
))
7263 bindings
= Fwhere_is_internal (function
, Voverriding_local_map
,
7269 GCPRO2 (bindings
, value
);
7270 value
= Fcommand_execute (function
, Qt
, Qnil
, Qnil
);
7272 /* If the command has a key binding, print it now. */
7273 if (!NILP (bindings
)
7274 && ! (VECTORP (bindings
) && EQ (Faref (bindings
, make_number (0)),
7277 /* But first wait, and skip the message if there is input. */
7278 if (!NILP (Fsit_for ((NUMBERP (Vsuggest_key_bindings
)
7279 ? Vsuggest_key_bindings
: make_number (2)),
7281 && ! CONSP (Vunread_command_events
))
7283 Lisp_Object binding
;
7285 char *oldmessage
= echo_area_glyphs
;
7286 int oldmessage_len
= echo_area_glyphs_length
;
7287 int oldmultibyte
= message_enable_multibyte
;
7289 binding
= Fkey_description (bindings
);
7292 = (char *) alloca (XSYMBOL (function
)->name
->size
7293 + XSTRING (binding
)->size_byte
7295 sprintf (newmessage
, "You can run the command `%s' with %s",
7296 XSYMBOL (function
)->name
->data
,
7297 XSTRING (binding
)->data
);
7298 message2_nolog (newmessage
,
7299 strlen (newmessage
),
7300 STRING_MULTIBYTE (binding
));
7301 if (!NILP (Fsit_for ((NUMBERP (Vsuggest_key_bindings
)
7302 ? Vsuggest_key_bindings
: make_number (2)),
7304 message2_nolog (oldmessage
, oldmessage_len
, oldmultibyte
);
7308 RETURN_UNGCPRO (value
);
7311 /* Find the set of keymaps now active.
7312 Store into *MAPS_P a vector holding the various maps
7313 and return the number of them. The vector was malloc'd
7314 and the caller should free it. */
7317 current_active_maps (maps_p
)
7318 Lisp_Object
**maps_p
;
7320 Lisp_Object
*tmaps
, *maps
;
7323 /* Should overriding-terminal-local-map and overriding-local-map apply? */
7324 if (!NILP (Voverriding_local_map_menu_flag
))
7326 /* Yes, use them (if non-nil) as well as the global map. */
7327 maps
= (Lisp_Object
*) xmalloc (3 * sizeof (maps
[0]));
7329 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
7330 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
7331 if (!NILP (Voverriding_local_map
))
7332 maps
[nmaps
++] = Voverriding_local_map
;
7336 /* No, so use major and minor mode keymaps. */
7337 nmaps
= current_minor_maps (NULL
, &tmaps
);
7338 maps
= (Lisp_Object
*) xmalloc ((nmaps
+ 2) * sizeof (maps
[0]));
7339 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
7340 #ifdef USE_TEXT_PROPERTIES
7341 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
7343 maps
[nmaps
++] = current_buffer
->keymap
;
7346 maps
[nmaps
++] = current_global_map
;
7352 /* Return nonzero if input events are pending. */
7354 detect_input_pending ()
7357 get_input_pending (&input_pending
, 0);
7359 return input_pending
;
7362 /* Return nonzero if input events are pending, and run any pending timers. */
7364 detect_input_pending_run_timers (do_display
)
7367 int old_timers_run
= timers_run
;
7370 get_input_pending (&input_pending
, 1);
7372 if (old_timers_run
!= timers_run
&& do_display
)
7373 redisplay_preserve_echo_area ();
7375 return input_pending
;
7378 /* This is called in some cases before a possible quit.
7379 It cases the next call to detect_input_pending to recompute input_pending.
7380 So calling this function unnecessarily can't do any harm. */
7383 clear_input_pending ()
7388 /* Return nonzero if there are pending requeued events.
7389 This isn't used yet. The hope is to make wait_reading_process_input
7390 call it, and return return if it runs Lisp code that unreads something.
7391 The problem is, kbd_buffer_get_event needs to be fixed to know what
7392 to do in that case. It isn't trivial. */
7394 requeued_events_pending_p ()
7396 return (!NILP (Vunread_command_events
) || unread_command_char
!= -1);
7400 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
7401 "T if command input is currently available with no waiting.\n\
7402 Actually, the value is nil only if we can be sure that no input is available.")
7405 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1)
7408 get_input_pending (&input_pending
, 1);
7409 return input_pending
> 0 ? Qt
: Qnil
;
7412 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
7413 "Return vector of last 100 events, not counting those from keyboard macros.")
7416 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
7419 if (total_keys
< NUM_RECENT_KEYS
)
7420 return Fvector (total_keys
, keys
);
7423 val
= Fvector (NUM_RECENT_KEYS
, keys
);
7424 bcopy (keys
+ recent_keys_index
,
7425 XVECTOR (val
)->contents
,
7426 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
7428 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
7429 recent_keys_index
* sizeof (Lisp_Object
));
7434 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
7435 "Return the key sequence that invoked this command.\n\
7436 The value is a string or a vector.")
7439 return make_event_array (this_command_key_count
,
7440 XVECTOR (this_command_keys
)->contents
);
7443 DEFUN ("this-single-command-keys", Fthis_single_command_keys
,
7444 Sthis_single_command_keys
, 0, 0, 0,
7445 "Return the key sequence that invoked this command.\n\
7446 Unlike `this-command-keys', this function's value\n\
7447 does not include prefix arguments.\n\
7448 The value is a string or a vector.")
7451 return make_event_array (this_command_key_count
7452 - this_single_command_key_start
,
7453 (XVECTOR (this_command_keys
)->contents
7454 + this_single_command_key_start
));
7457 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths
,
7458 Sreset_this_command_lengths
, 0, 0, 0,
7459 "Used for complicated reasons in `universal-argument-other-key'.\n\
7461 `universal-argument-other-key' rereads the event just typed.\n\
7462 It then gets translated through `function-key-map'.\n\
7463 The translated event gets included in the echo area and in\n\
7464 the value of `this-command-keys' in addition to the raw original event.\n\
7465 That is not right.\n\
7467 Calling this function directs the translated event to replace\n\
7468 the original event, so that only one version of the event actually\n\
7469 appears in the echo area and in the value of `this-command-keys.'.")
7472 before_command_restore_flag
= 1;
7473 before_command_key_count_1
= before_command_key_count
;
7474 before_command_echo_length_1
= before_command_echo_length
;
7477 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
7478 "Return the current depth in recursive edits.")
7482 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
7486 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
7487 "FOpen dribble file: ",
7488 "Start writing all keyboard characters to a dribble file called FILE.\n\
7489 If FILE is nil, close any open dribble file.")
7500 file
= Fexpand_file_name (file
, Qnil
);
7501 dribble
= fopen (XSTRING (file
)->data
, "w");
7503 report_file_error ("Opening dribble", Fcons (file
, Qnil
));
7508 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
7509 "Discard the contents of the terminal input buffer.\n\
7510 Also cancel any kbd macro being defined.")
7513 current_kboard
->defining_kbd_macro
= Qnil
;
7514 update_mode_lines
++;
7516 Vunread_command_events
= Qnil
;
7517 unread_command_char
= -1;
7519 discard_tty_input ();
7521 /* Without the cast, GCC complains that this assignment loses the
7522 volatile qualifier of kbd_store_ptr. Is there anything wrong
7524 kbd_fetch_ptr
= (struct input_event
*) kbd_store_ptr
;
7525 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
7531 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
7532 "Stop Emacs and return to superior process. You can resume later.\n\
7533 If `cannot-suspend' is non-nil, or if the system doesn't support job\n\
7534 control, run a subshell instead.\n\n\
7535 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
7536 to be read as terminal input by Emacs's parent, after suspension.\n\
7538 Before suspending, run the normal hook `suspend-hook'.\n\
7539 After resumption run the normal hook `suspend-resume-hook'.\n\
7541 Some operating systems cannot stop the Emacs process and resume it later.\n\
7542 On such systems, Emacs starts a subshell instead of suspending.")
7544 Lisp_Object stuffstring
;
7547 int count
= specpdl_ptr
- specpdl
;
7548 int old_height
, old_width
;
7550 struct gcpro gcpro1
, gcpro2
;
7552 if (!NILP (stuffstring
))
7553 CHECK_STRING (stuffstring
, 0);
7555 /* Run the functions in suspend-hook. */
7556 if (!NILP (Vrun_hooks
))
7557 call1 (Vrun_hooks
, intern ("suspend-hook"));
7559 GCPRO1 (stuffstring
);
7560 get_frame_size (&old_width
, &old_height
);
7562 /* sys_suspend can get an error if it tries to fork a subshell
7563 and the system resources aren't available for that. */
7564 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object
))) init_sys_modes
,
7566 stuff_buffered_input (stuffstring
);
7571 unbind_to (count
, Qnil
);
7573 /* Check if terminal/window size has changed.
7574 Note that this is not useful when we are running directly
7575 with a window system; but suspend should be disabled in that case. */
7576 get_frame_size (&width
, &height
);
7577 if (width
!= old_width
|| height
!= old_height
)
7578 change_frame_size (selected_frame
, height
, width
, 0, 0);
7580 /* Run suspend-resume-hook. */
7581 if (!NILP (Vrun_hooks
))
7582 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
7588 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
7589 Then in any case stuff anything Emacs has read ahead and not used. */
7592 stuff_buffered_input (stuffstring
)
7593 Lisp_Object stuffstring
;
7595 /* stuff_char works only in BSD, versions 4.2 and up. */
7598 register unsigned char *p
;
7600 if (STRINGP (stuffstring
))
7604 p
= XSTRING (stuffstring
)->data
;
7605 count
= XSTRING (stuffstring
)->size_byte
;
7610 /* Anything we have read ahead, put back for the shell to read. */
7611 /* ?? What should this do when we have multiple keyboards??
7612 Should we ignore anything that was typed in at the "wrong" kboard? */
7613 for (; kbd_fetch_ptr
!= kbd_store_ptr
; kbd_fetch_ptr
++)
7615 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
7616 kbd_fetch_ptr
= kbd_buffer
;
7617 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
7618 stuff_char (kbd_fetch_ptr
->code
);
7619 kbd_fetch_ptr
->kind
= no_event
;
7620 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_fetch_ptr
7626 #endif /* BSD_SYSTEM and not BSD4_1 */
7629 set_waiting_for_input (time_to_clear
)
7630 EMACS_TIME
*time_to_clear
;
7632 input_available_clear_time
= time_to_clear
;
7634 /* Tell interrupt_signal to throw back to read_char, */
7635 waiting_for_input
= 1;
7637 /* If interrupt_signal was called before and buffered a C-g,
7638 make it run again now, to avoid timing error. */
7639 if (!NILP (Vquit_flag
))
7640 quit_throw_to_read_char ();
7644 clear_waiting_for_input ()
7646 /* Tell interrupt_signal not to throw back to read_char, */
7647 waiting_for_input
= 0;
7648 input_available_clear_time
= 0;
7651 /* This routine is called at interrupt level in response to C-G.
7652 If interrupt_input, this is the handler for SIGINT.
7653 Otherwise, it is called from kbd_buffer_store_event,
7654 in handling SIGIO or SIGTINT.
7656 If `waiting_for_input' is non zero, then unless `echoing' is nonzero,
7657 immediately throw back to read_char.
7659 Otherwise it sets the Lisp variable quit-flag not-nil.
7660 This causes eval to throw, when it gets a chance.
7661 If quit-flag is already non-nil, it stops the job right away. */
7664 interrupt_signal (signalnum
) /* If we don't have an argument, */
7665 int signalnum
; /* some compilers complain in signal calls. */
7668 /* Must preserve main program's value of errno. */
7669 int old_errno
= errno
;
7671 #if defined (USG) && !defined (POSIX_SIGNALS)
7672 if (!read_socket_hook
&& NILP (Vwindow_system
))
7674 /* USG systems forget handlers when they are used;
7675 must reestablish each time */
7676 signal (SIGINT
, interrupt_signal
);
7677 signal (SIGQUIT
, interrupt_signal
);
7683 if (!NILP (Vquit_flag
)
7684 && (FRAME_TERMCAP_P (selected_frame
) || FRAME_MSDOS_P (selected_frame
)))
7686 /* If SIGINT isn't blocked, don't let us be interrupted by
7687 another SIGINT, it might be harmful due to non-reentrancy
7688 in I/O functions. */
7689 sigblock (sigmask (SIGINT
));
7694 #ifdef SIGTSTP /* Support possible in later USG versions */
7696 * On systems which can suspend the current process and return to the original
7697 * shell, this command causes the user to end up back at the shell.
7698 * The "Auto-save" and "Abort" questions are not asked until
7699 * the user elects to return to emacs, at which point he can save the current
7700 * job and either dump core or continue.
7705 if (sys_suspend () == -1)
7707 printf ("Not running as a subprocess;\n");
7708 printf ("you can continue or abort.\n");
7711 /* Perhaps should really fork an inferior shell?
7712 But that would not provide any way to get back
7713 to the original shell, ever. */
7714 printf ("No support for stopping a process on this operating system;\n");
7715 printf ("you can continue or abort.\n");
7716 #endif /* not VMS */
7717 #endif /* not SIGTSTP */
7719 /* We must remain inside the screen area when the internal terminal
7720 is used. Note that [Enter] is not echoed by dos. */
7723 /* It doesn't work to autosave while GC is in progress;
7724 the code used for auto-saving doesn't cope with the mark bit. */
7725 if (!gc_in_progress
)
7727 printf ("Auto-save? (y or n) ");
7729 if (((c
= getchar ()) & ~040) == 'Y')
7731 Fdo_auto_save (Qt
, Qnil
);
7733 printf ("\r\nAuto-save done");
7734 #else /* not MSDOS */
7735 printf ("Auto-save done\n");
7736 #endif /* not MSDOS */
7738 while (c
!= '\n') c
= getchar ();
7742 /* During GC, it must be safe to reenable quitting again. */
7743 Vinhibit_quit
= Qnil
;
7746 #endif /* not MSDOS */
7747 printf ("Garbage collection in progress; cannot auto-save now\r\n");
7748 printf ("but will instead do a real quit after garbage collection ends\r\n");
7753 printf ("\r\nAbort? (y or n) ");
7754 #else /* not MSDOS */
7756 printf ("Abort (and enter debugger)? (y or n) ");
7758 printf ("Abort (and dump core)? (y or n) ");
7759 #endif /* not VMS */
7760 #endif /* not MSDOS */
7762 if (((c
= getchar ()) & ~040) == 'Y')
7764 while (c
!= '\n') c
= getchar ();
7766 printf ("\r\nContinuing...\r\n");
7767 #else /* not MSDOS */
7768 printf ("Continuing...\n");
7769 #endif /* not MSDOS */
7776 /* If executing a function that wants to be interrupted out of
7777 and the user has not deferred quitting by binding `inhibit-quit'
7778 then quit right away. */
7779 if (immediate_quit
&& NILP (Vinhibit_quit
))
7783 Fsignal (Qquit
, Qnil
);
7786 /* Else request quit when it's safe */
7790 if (waiting_for_input
&& !echoing
)
7791 quit_throw_to_read_char ();
7796 /* Handle a C-g by making read_char return C-g. */
7799 quit_throw_to_read_char ()
7801 quit_error_check ();
7803 /* Prevent another signal from doing this before we finish. */
7804 clear_waiting_for_input ();
7807 Vunread_command_events
= Qnil
;
7808 unread_command_char
= -1;
7810 #if 0 /* Currently, sit_for is called from read_char without turning
7811 off polling. And that can call set_waiting_for_input.
7812 It seems to be harmless. */
7813 #ifdef POLL_FOR_INPUT
7814 /* May be > 1 if in recursive minibuffer. */
7815 if (poll_suppress_count
== 0)
7819 if (FRAMEP (internal_last_event_frame
)
7820 && XFRAME (internal_last_event_frame
) != selected_frame
)
7821 do_switch_frame (make_lispy_switch_frame (internal_last_event_frame
),
7824 _longjmp (getcjmp
, 1);
7827 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
7828 "Set mode of reading keyboard input.\n\
7829 First arg INTERRUPT non-nil means use input interrupts;\n\
7830 nil means use CBREAK mode.\n\
7831 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
7832 (no effect except in CBREAK mode).\n\
7833 Third arg META t means accept 8-bit input (for a Meta key).\n\
7834 META nil means ignore the top bit, on the assumption it is parity.\n\
7835 Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\
7836 Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\
7837 See also `current-input-mode'.")
7838 (interrupt
, flow
, meta
, quit
)
7839 Lisp_Object interrupt
, flow
, meta
, quit
;
7842 && (!INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400))
7843 error ("set-input-mode: QUIT must be an ASCII character");
7845 #ifdef POLL_FOR_INPUT
7850 /* this causes startup screen to be restored and messes with the mouse */
7855 /* Note SIGIO has been undef'd if FIONREAD is missing. */
7856 if (read_socket_hook
)
7858 /* When using X, don't give the user a real choice,
7859 because we haven't implemented the mechanisms to support it. */
7860 #ifdef NO_SOCK_SIGIO
7861 interrupt_input
= 0;
7862 #else /* not NO_SOCK_SIGIO */
7863 interrupt_input
= 1;
7864 #endif /* NO_SOCK_SIGIO */
7867 interrupt_input
= !NILP (interrupt
);
7868 #else /* not SIGIO */
7869 interrupt_input
= 0;
7870 #endif /* not SIGIO */
7872 /* Our VMS input only works by interrupts, as of now. */
7874 interrupt_input
= 1;
7877 flow_control
= !NILP (flow
);
7880 else if (EQ (meta
, Qt
))
7885 /* Don't let this value be out of range. */
7886 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
7892 #ifdef POLL_FOR_INPUT
7893 poll_suppress_count
= 1;
7899 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
7900 "Return information about the way Emacs currently reads keyboard input.\n\
7901 The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
7902 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\
7903 nil, Emacs is using CBREAK mode.\n\
7904 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\
7905 terminal; this does not apply if Emacs uses interrupt-driven input.\n\
7906 META is t if accepting 8-bit input with 8th bit as Meta flag.\n\
7907 META nil means ignoring the top bit, on the assumption it is parity.\n\
7908 META is neither t nor nil if accepting 8-bit input and using\n\
7909 all 8 bits as the character code.\n\
7910 QUIT is the character Emacs currently uses to quit.\n\
7911 The elements of this list correspond to the arguments of\n\
7917 val
[0] = interrupt_input
? Qt
: Qnil
;
7918 val
[1] = flow_control
? Qt
: Qnil
;
7919 val
[2] = meta_key
== 2 ? make_number (0) : meta_key
== 1 ? Qt
: Qnil
;
7920 XSETFASTINT (val
[3], quit_char
);
7922 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
7927 * Set up a new kboard object with reasonable initial values.
7933 kb
->Voverriding_terminal_local_map
= Qnil
;
7934 kb
->Vlast_command
= Qnil
;
7935 kb
->Vprefix_arg
= Qnil
;
7936 kb
->kbd_queue
= Qnil
;
7937 kb
->kbd_queue_has_data
= 0;
7938 kb
->immediate_echo
= 0;
7939 kb
->echoptr
= kb
->echobuf
;
7940 kb
->echo_after_prompt
= -1;
7941 kb
->kbd_macro_buffer
= 0;
7942 kb
->kbd_macro_bufsize
= 0;
7943 kb
->defining_kbd_macro
= Qnil
;
7944 kb
->Vlast_kbd_macro
= Qnil
;
7945 kb
->reference_count
= 0;
7946 kb
->Vsystem_key_alist
= Qnil
;
7947 kb
->system_key_syms
= Qnil
;
7948 kb
->Vdefault_minibuffer_frame
= Qnil
;
7952 * Destroy the contents of a kboard object, but not the object itself.
7953 * We use this just before deleting it, or if we're going to initialize
7960 if (kb
->kbd_macro_buffer
)
7961 xfree (kb
->kbd_macro_buffer
);
7970 for (kbp
= &all_kboards
; *kbp
!= kb
; kbp
= &(*kbp
)->next_kboard
)
7973 *kbp
= kb
->next_kboard
;
7981 /* This is correct before outermost invocation of the editor loop */
7982 command_loop_level
= -1;
7984 quit_char
= Ctl ('g');
7985 Vunread_command_events
= Qnil
;
7986 unread_command_char
= -1;
7987 EMACS_SET_SECS_USECS (timer_idleness_start_time
, -1, -1);
7989 recent_keys_index
= 0;
7990 kbd_fetch_ptr
= kbd_buffer
;
7991 kbd_store_ptr
= kbd_buffer
;
7992 kbd_buffer_frame_or_window
7993 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
7995 do_mouse_tracking
= Qnil
;
7999 /* This means that command_loop_1 won't try to select anything the first
8001 internal_last_event_frame
= Qnil
;
8002 Vlast_event_frame
= internal_last_event_frame
;
8005 current_kboard
= initial_kboard
;
8007 wipe_kboard (current_kboard
);
8008 init_kboard (current_kboard
);
8011 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
8013 kbd_buffer_frame_or_window
8014 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
8015 if (!noninteractive
&& !read_socket_hook
&& NILP (Vwindow_system
))
8017 signal (SIGINT
, interrupt_signal
);
8018 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
8019 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
8020 SIGQUIT and we can't tell which one it will give us. */
8021 signal (SIGQUIT
, interrupt_signal
);
8022 #endif /* HAVE_TERMIO */
8024 /* Note SIGIO has been undef'd if FIONREAD is missing. */
8026 if (!noninteractive
)
8027 signal (SIGIO
, input_available_signal
);
8030 /* Use interrupt input by default, if it works and noninterrupt input
8031 has deficiencies. */
8033 #ifdef INTERRUPT_INPUT
8034 interrupt_input
= 1;
8036 interrupt_input
= 0;
8039 /* Our VMS input only works by interrupts, as of now. */
8041 interrupt_input
= 1;
8047 if (keyboard_init_hook
)
8048 (*keyboard_init_hook
) ();
8050 #ifdef POLL_FOR_INPUT
8051 poll_suppress_count
= 1;
8056 /* This type's only use is in syms_of_keyboard, to initialize the
8057 event header symbols and put properties on them. */
8064 struct event_head head_table
[] = {
8065 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
8066 &Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
,
8067 &Qswitch_frame
, "switch-frame", &Qswitch_frame
,
8068 &Qdelete_frame
, "delete-frame", &Qdelete_frame
,
8069 &Qiconify_frame
, "iconify-frame", &Qiconify_frame
,
8070 &Qmake_frame_visible
, "make-frame-visible", &Qmake_frame_visible
,
8075 Qtimer_event_handler
= intern ("timer-event-handler");
8076 staticpro (&Qtimer_event_handler
);
8078 Qdisabled_command_hook
= intern ("disabled-command-hook");
8079 staticpro (&Qdisabled_command_hook
);
8081 Qself_insert_command
= intern ("self-insert-command");
8082 staticpro (&Qself_insert_command
);
8084 Qforward_char
= intern ("forward-char");
8085 staticpro (&Qforward_char
);
8087 Qbackward_char
= intern ("backward-char");
8088 staticpro (&Qbackward_char
);
8090 Qdisabled
= intern ("disabled");
8091 staticpro (&Qdisabled
);
8093 Qundefined
= intern ("undefined");
8094 staticpro (&Qundefined
);
8096 Qpre_command_hook
= intern ("pre-command-hook");
8097 staticpro (&Qpre_command_hook
);
8099 Qpost_command_hook
= intern ("post-command-hook");
8100 staticpro (&Qpost_command_hook
);
8102 Qpost_command_idle_hook
= intern ("post-command-idle-hook");
8103 staticpro (&Qpost_command_idle_hook
);
8105 Qdeferred_action_function
= intern ("deferred-action-function");
8106 staticpro (&Qdeferred_action_function
);
8108 Qcommand_hook_internal
= intern ("command-hook-internal");
8109 staticpro (&Qcommand_hook_internal
);
8111 Qfunction_key
= intern ("function-key");
8112 staticpro (&Qfunction_key
);
8113 Qmouse_click
= intern ("mouse-click");
8114 staticpro (&Qmouse_click
);
8116 Qmouse_wheel
= intern ("mouse-wheel");
8117 staticpro (&Qmouse_wheel
);
8120 Qmenu_enable
= intern ("menu-enable");
8121 staticpro (&Qmenu_enable
);
8123 Qmode_line
= intern ("mode-line");
8124 staticpro (&Qmode_line
);
8125 Qvertical_line
= intern ("vertical-line");
8126 staticpro (&Qvertical_line
);
8127 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
8128 staticpro (&Qvertical_scroll_bar
);
8129 Qmenu_bar
= intern ("menu-bar");
8130 staticpro (&Qmenu_bar
);
8132 Qabove_handle
= intern ("above-handle");
8133 staticpro (&Qabove_handle
);
8134 Qhandle
= intern ("handle");
8135 staticpro (&Qhandle
);
8136 Qbelow_handle
= intern ("below-handle");
8137 staticpro (&Qbelow_handle
);
8138 Qup
= intern ("up");
8140 Qdown
= intern ("down");
8143 Qevent_kind
= intern ("event-kind");
8144 staticpro (&Qevent_kind
);
8145 Qevent_symbol_elements
= intern ("event-symbol-elements");
8146 staticpro (&Qevent_symbol_elements
);
8147 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
8148 staticpro (&Qevent_symbol_element_mask
);
8149 Qmodifier_cache
= intern ("modifier-cache");
8150 staticpro (&Qmodifier_cache
);
8152 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
8153 staticpro (&Qrecompute_lucid_menubar
);
8154 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
8155 staticpro (&Qactivate_menubar_hook
);
8157 Qpolling_period
= intern ("polling-period");
8158 staticpro (&Qpolling_period
);
8161 struct event_head
*p
;
8163 for (p
= head_table
;
8164 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
8167 *p
->var
= intern (p
->name
);
8169 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
8170 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
8174 button_down_location
= Fmake_vector (make_number (NUM_MOUSE_BUTTONS
), Qnil
);
8175 staticpro (&button_down_location
);
8179 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
8181 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
8182 for (i
= 0; i
< len
; i
++)
8183 if (modifier_names
[i
])
8184 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
8185 staticpro (&modifier_symbols
);
8188 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
8189 staticpro (&recent_keys
);
8191 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
8192 staticpro (&this_command_keys
);
8194 Qextended_command_history
= intern ("extended-command-history");
8195 Fset (Qextended_command_history
, Qnil
);
8196 staticpro (&Qextended_command_history
);
8198 kbd_buffer_frame_or_window
8199 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
8200 staticpro (&kbd_buffer_frame_or_window
);
8202 accent_key_syms
= Qnil
;
8203 staticpro (&accent_key_syms
);
8205 func_key_syms
= Qnil
;
8206 staticpro (&func_key_syms
);
8209 staticpro (&mouse_syms
);
8212 mouse_wheel_syms
= Qnil
;
8213 staticpro (&mouse_wheel_syms
);
8216 unread_switch_frame
= Qnil
;
8217 staticpro (&unread_switch_frame
);
8219 internal_last_event_frame
= Qnil
;
8220 staticpro (&internal_last_event_frame
);
8222 read_key_sequence_cmd
= Qnil
;
8223 staticpro (&read_key_sequence_cmd
);
8225 defsubr (&Sevent_convert_list
);
8226 defsubr (&Sread_key_sequence
);
8227 defsubr (&Srecursive_edit
);
8229 defsubr (&Strack_mouse
);
8231 defsubr (&Sinput_pending_p
);
8232 defsubr (&Scommand_execute
);
8233 defsubr (&Srecent_keys
);
8234 defsubr (&Sthis_command_keys
);
8235 defsubr (&Sthis_single_command_keys
);
8236 defsubr (&Sreset_this_command_lengths
);
8237 defsubr (&Ssuspend_emacs
);
8238 defsubr (&Sabort_recursive_edit
);
8239 defsubr (&Sexit_recursive_edit
);
8240 defsubr (&Srecursion_depth
);
8241 defsubr (&Stop_level
);
8242 defsubr (&Sdiscard_input
);
8243 defsubr (&Sopen_dribble_file
);
8244 defsubr (&Sset_input_mode
);
8245 defsubr (&Scurrent_input_mode
);
8246 defsubr (&Sexecute_extended_command
);
8248 DEFVAR_LISP ("last-command-char", &last_command_char
,
8249 "Last input event that was part of a command.");
8251 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char
,
8252 "Last input event that was part of a command.");
8254 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
8255 "Last input event in a command, except for mouse menu events.\n\
8256 Mouse menus give back keys that don't look like mouse events;\n\
8257 this variable holds the actual mouse event that led to the menu,\n\
8258 so that you can determine whether the command was run by mouse or not.");
8260 DEFVAR_LISP ("last-input-char", &last_input_char
,
8261 "Last input event.");
8263 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char
,
8264 "Last input event.");
8266 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
8267 "List of objects to be read as next command input events.");
8269 DEFVAR_INT ("unread-command-char", &unread_command_char
,
8270 "If not -1, an object to be read as next command input event.");
8272 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
8273 "Meta-prefix character code. Meta-foo as command input\n\
8274 turns into this character followed by foo.");
8275 XSETINT (meta_prefix_char
, 033);
8277 DEFVAR_KBOARD ("last-command", Vlast_command
,
8278 "The last command executed. Normally a symbol with a function definition,\n\
8279 but can be whatever was found in the keymap, or whatever the variable\n\
8280 `this-command' was set to by that command.\n\
8282 The value `mode-exit' is special; it means that the previous command\n\
8283 read an event that told it to exit, and it did so and unread that event.\n\
8284 In other words, the present command is the event that made the previous\n\
8287 The value `kill-region' is special; it means that the previous command\n\
8288 was a kill command.");
8290 DEFVAR_LISP ("this-command", &this_command
,
8291 "The command now being executed.\n\
8292 The command can set this variable; whatever is put here\n\
8293 will be in `last-command' during the following command.");
8294 this_command
= Qnil
;
8296 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
8297 "*Number of keyboard input characters between auto-saves.\n\
8298 Zero means disable autosaving due to number of characters typed.");
8299 auto_save_interval
= 300;
8301 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
8302 "*Number of seconds idle time before auto-save.\n\
8303 Zero or nil means disable auto-saving due to idleness.\n\
8304 After auto-saving due to this many seconds of idle time,\n\
8305 Emacs also does a garbage collection if that seems to be warranted.");
8306 XSETFASTINT (Vauto_save_timeout
, 30);
8308 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes
,
8309 "*Nonzero means echo unfinished commands after this many seconds of pause.");
8310 echo_keystrokes
= 1;
8312 DEFVAR_INT ("polling-period", &polling_period
,
8313 "*Interval between polling for input during Lisp execution.\n\
8314 The reason for polling is to make C-g work to stop a running program.\n\
8315 Polling is needed only when using X windows and SIGIO does not work.\n\
8316 Polling is automatically disabled in all other cases.");
8319 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
8320 "*Maximum time between mouse clicks to make a double-click.\n\
8321 Measured in milliseconds. nil means disable double-click recognition;\n\
8322 t means double-clicks have no time limit and are detected\n\
8323 by position only.");
8324 Vdouble_click_time
= make_number (500);
8326 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
8327 "*Non-nil means inhibit local map menu bar menus.");
8328 inhibit_local_menu_bar_menus
= 0;
8330 DEFVAR_INT ("num-input-keys", &num_input_keys
,
8331 "Number of complete key sequences read as input so far.\n\
8332 This includes key sequences read from keyboard macros.\n\
8333 The number is effectively the number of interactive command invocations.");
8336 DEFVAR_INT ("num-nonmacro-input-events", &num_nonmacro_input_events
,
8337 "Number of input events read from the keyboard so far.\n\
8338 This does not include events generated by keyboard macros.");
8339 num_nonmacro_input_events
= 0;
8341 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
8342 "The frame in which the most recently read event occurred.\n\
8343 If the last event came from a keyboard macro, this is set to `macro'.");
8344 Vlast_event_frame
= Qnil
;
8346 /* This variable is set up in sysdep.c. */
8347 DEFVAR_LISP ("tty-erase-char", &Vtty_erase_char
,
8348 "The ERASE character as set by the user with stty.");
8350 DEFVAR_LISP ("help-char", &Vhelp_char
,
8351 "Character to recognize as meaning Help.\n\
8352 When it is read, do `(eval help-form)', and display result if it's a string.\n\
8353 If the value of `help-form' is nil, this char can be read normally.");
8354 XSETINT (Vhelp_char
, Ctl ('H'));
8356 DEFVAR_LISP ("help-event-list", &Vhelp_event_list
,
8357 "List of input events to recognize as meaning Help.\n\
8358 These work just like the value of `help-char' (see that).");
8359 Vhelp_event_list
= Qnil
;
8361 DEFVAR_LISP ("help-form", &Vhelp_form
,
8362 "Form to execute when character `help-char' is read.\n\
8363 If the form returns a string, that string is displayed.\n\
8364 If `help-form' is nil, the help char is not recognized.");
8367 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
8368 "Command to run when `help-char' character follows a prefix key.\n\
8369 This command is used only when there is no actual binding\n\
8370 for that character after that prefix key.");
8371 Vprefix_help_command
= Qnil
;
8373 DEFVAR_LISP ("top-level", &Vtop_level
,
8374 "Form to evaluate when Emacs starts up.\n\
8375 Useful to set before you dump a modified Emacs.");
8378 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
8379 "Translate table for keyboard input, or nil.\n\
8380 Each character is looked up in this string and the contents used instead.\n\
8381 The value may be a string, a vector, or a char-table.\n\
8382 If it is a string or vector of length N,\n\
8383 character codes N and up are untranslated.\n\
8384 In a vector or a char-table, an element which is nil means \"no translation\".");
8385 Vkeyboard_translate_table
= Qnil
;
8387 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
8388 "Non-nil means to always spawn a subshell instead of suspending,\n\
8389 even if the operating system has support for stopping a process.");
8392 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
8393 "Non-nil means prompt with menus when appropriate.\n\
8394 This is done when reading from a keymap that has a prompt string,\n\
8395 for elements that have prompt strings.\n\
8396 The menu is displayed on the screen\n\
8397 if X menus were enabled at configuration\n\
8398 time and the previous event was a mouse click prefix key.\n\
8399 Otherwise, menu prompting uses the echo area.");
8402 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
8403 "Character to see next line of menu prompt.\n\
8404 Type this character while in a menu prompt to rotate around the lines of it.");
8405 XSETINT (menu_prompt_more_char
, ' ');
8407 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
8408 "A mask of additional modifier keys to use with every keyboard character.\n\
8409 Emacs applies the modifiers of the character stored here to each keyboard\n\
8410 character it reads. For example, after evaluating the expression\n\
8411 (setq extra-keyboard-modifiers ?\\C-x)\n\
8412 all input characters will have the control modifier applied to them.\n\
8414 Note that the character ?\\C-@, equivalent to the integer zero, does\n\
8415 not count as a control character; rather, it counts as a character\n\
8416 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\
8417 cancels any modification.");
8418 extra_keyboard_modifiers
= 0;
8420 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
8421 "If an editing command sets this to t, deactivate the mark afterward.\n\
8422 The command loop sets this to nil before each command,\n\
8423 and tests the value when the command returns.\n\
8424 Buffer modification stores t in this variable.");
8425 Vdeactivate_mark
= Qnil
;
8427 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
8428 "Temporary storage of pre-command-hook or post-command-hook.");
8429 Vcommand_hook_internal
= Qnil
;
8431 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
8432 "Normal hook run before each command is executed.\n\
8433 Errors running the hook are caught and ignored.");
8434 Vpre_command_hook
= Qnil
;
8436 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
8437 "Normal hook run after each command is executed.\n\
8438 Errors running the hook are caught and ignored.");
8439 Vpost_command_hook
= Qnil
;
8441 DEFVAR_LISP ("post-command-idle-hook", &Vpost_command_idle_hook
,
8442 "Normal hook run after each command is executed, if idle.\n\
8443 Errors running the hook are caught and ignored.\n\
8444 This feature is obsolete; use idle timers instead. See `etc/NEWS'.");
8445 Vpost_command_idle_hook
= Qnil
;
8447 DEFVAR_INT ("post-command-idle-delay", &post_command_idle_delay
,
8448 "Delay time before running `post-command-idle-hook'.\n\
8449 This is measured in microseconds.");
8450 post_command_idle_delay
= 100000;
8453 DEFVAR_LISP ("echo-area-clear-hook", ...,
8454 "Normal hook run when clearing the echo area.");
8456 Qecho_area_clear_hook
= intern ("echo-area-clear-hook");
8457 XSYMBOL (Qecho_area_clear_hook
)->value
= Qnil
;
8459 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
8460 "t means menu bar, specified Lucid style, needs to be recomputed.");
8461 Vlucid_menu_bar_dirty_flag
= Qnil
;
8463 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
8464 "List of menu bar items to move to the end of the menu bar.\n\
8465 The elements of the list are event types that may have menu bar bindings.");
8466 Vmenu_bar_final_items
= Qnil
;
8468 DEFVAR_KBOARD ("overriding-terminal-local-map",
8469 Voverriding_terminal_local_map
,
8470 "Per-terminal keymap that overrides all other local keymaps.\n\
8471 If this variable is non-nil, it is used as a keymap instead of the\n\
8472 buffer's local map, and the minor mode keymaps and text property keymaps.\n\
8473 This variable is intended to let commands such as `universal-argumemnt'\n\
8474 set up a different keymap for reading the next command.");
8476 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
8477 "Keymap that overrides all other local keymaps.\n\
8478 If this variable is non-nil, it is used as a keymap instead of the\n\
8479 buffer's local map, and the minor mode keymaps and text property keymaps.");
8480 Voverriding_local_map
= Qnil
;
8482 DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag
,
8483 "Non-nil means `overriding-local-map' applies to the menu bar.\n\
8484 Otherwise, the menu bar continues to reflect the buffer's local map\n\
8485 and the minor mode maps regardless of `overriding-local-map'.");
8486 Voverriding_local_map_menu_flag
= Qnil
;
8488 DEFVAR_LISP ("special-event-map", &Vspecial_event_map
,
8489 "Keymap defining bindings for special events to execute at low level.");
8490 Vspecial_event_map
= Fcons (intern ("keymap"), Qnil
);
8492 DEFVAR_LISP ("track-mouse", &do_mouse_tracking
,
8493 "*Non-nil means generate motion events for mouse motion.");
8495 DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist
,
8496 "Alist of system-specific X windows key symbols.\n\
8497 Each element should have the form (N . SYMBOL) where N is the\n\
8498 numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\
8499 and SYMBOL is its name.");
8501 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
8502 "List of deferred actions to be performed at a later time.\n\
8503 The precise format isn't relevant here; we just check whether it is nil.");
8504 Vdeferred_action_list
= Qnil
;
8506 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
8507 "Function to call to handle deferred actions, after each command.\n\
8508 This function is called with no arguments after each command\n\
8509 whenever `deferred-action-list' is non-nil.");
8510 Vdeferred_action_function
= Qnil
;
8512 DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings
,
8513 "Non-nil means show the equivalent key-binding when M-x command has one.\n\
8514 The value can be a length of time to show the message for.\n\
8515 If the value is non-nil and not a number, we wait 2 seconds.");
8516 Vsuggest_key_bindings
= Qt
;
8518 DEFVAR_LISP ("timer-list", &Vtimer_list
,
8519 "List of active absolute time timers in order of increasing time");
8522 DEFVAR_LISP ("timer-idle-list", &Vtimer_idle_list
,
8523 "List of active idle-time timers in order of increasing time");
8524 Vtimer_idle_list
= Qnil
;
8529 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
8530 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
8531 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
8532 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
8533 initial_define_key (meta_map
, 'x', "execute-extended-command");
8535 initial_define_lispy_key (Vspecial_event_map
, "delete-frame",
8536 "handle-delete-frame");
8537 initial_define_lispy_key (Vspecial_event_map
, "iconify-frame",
8539 initial_define_lispy_key (Vspecial_event_map
, "make-frame-visible",