1 /* Keyboard and mouse input; editor command loop.
2 Copyright (C) 1985,86,87,88,89,93,94 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* Allow config.h to undefine symbols found here. */
29 #include "termhooks.h"
36 #include "dispextern.h"
38 #include "intervals.h"
39 #include "blockinput.h"
48 #include <sys/ioctl.h>
50 #endif /* not MSDOS */
52 #include "syssignal.h"
55 /* This is to get the definitions of the XK_ symbols. */
60 /* Include systime.h after xterm.h to avoid double inclusion of time.h. */
65 /* Variables for blockinput.h: */
67 /* Non-zero if interrupt input is blocked right now. */
68 int interrupt_input_blocked
;
70 /* Nonzero means an input interrupt has arrived
71 during the current critical section. */
72 int interrupt_input_pending
;
76 extern Lisp_Object Vmouse_grabbed
;
78 /* Make all keyboard buffers much bigger when using X windows. */
79 #define KBD_BUFFER_SIZE 4096
80 #else /* No X-windows, character input */
81 #define KBD_BUFFER_SIZE 256
82 #endif /* No X-windows */
84 /* Following definition copied from eval.c */
88 struct backtrace
*next
;
89 Lisp_Object
*function
;
90 Lisp_Object
*args
; /* Points to vector of args. */
91 int nargs
; /* length of vector. If nargs is UNEVALLED,
92 args points to slot holding list of
97 /* Non-nil disable property on a command means
98 do not execute it; call disabled-command-hook's value instead. */
99 Lisp_Object Qdisabled
, Qdisabled_command_hook
;
101 #define NUM_RECENT_KEYS (100)
102 int recent_keys_index
; /* Index for storing next element into recent_keys */
103 int total_keys
; /* Total number of elements stored into recent_keys */
104 Lisp_Object recent_keys
; /* A vector, holding the last 100 keystrokes */
106 /* Vector holding the key sequence that invoked the current command.
107 It is reused for each command, and it may be longer than the current
108 sequence; this_command_key_count indicates how many elements
109 actually mean something.
110 It's easier to staticpro a single Lisp_Object than an array. */
111 Lisp_Object this_command_keys
;
112 int this_command_key_count
;
114 extern int minbuf_level
;
116 extern struct backtrace
*backtrace_list
;
118 /* Nonzero means do menu prompting. */
119 static int menu_prompting
;
121 /* Character to see next line of menu prompt. */
122 static Lisp_Object menu_prompt_more_char
;
124 /* For longjmp to where kbd input is being done. */
125 static jmp_buf getcjmp
;
127 /* True while doing kbd input. */
128 int waiting_for_input
;
130 /* True while displaying for echoing. Delays C-g throwing. */
133 /* Nonzero means disregard local maps for the menu bar. */
134 static int inhibit_local_menu_bar_menus
;
136 /* Nonzero means C-g should cause immediate error-signal. */
139 /* Character to recognize as the help char. */
140 Lisp_Object Vhelp_char
;
142 /* Form to execute when help char is typed. */
143 Lisp_Object Vhelp_form
;
145 /* Command to run when the help character follows a prefix key. */
146 Lisp_Object Vprefix_help_command
;
148 /* List of items that should move to the end of the menu bar. */
149 Lisp_Object Vmenu_bar_final_items
;
151 /* Character that causes a quit. Normally C-g.
153 If we are running on an ordinary terminal, this must be an ordinary
154 ASCII char, since we want to make it our interrupt character.
156 If we are not running on an ordinary terminal, it still needs to be
157 an ordinary ASCII char. This character needs to be recognized in
158 the input interrupt handler. At this point, the keystroke is
159 represented as a struct input_event, while the desired quit
160 character is specified as a lispy event. The mapping from struct
161 input_events to lispy events cannot run in an interrupt handler,
162 and the reverse mapping is difficult for anything but ASCII
165 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
169 extern Lisp_Object current_global_map
;
170 extern int minibuf_level
;
172 /* If non-nil, this is a map that overrides all other local maps. */
173 Lisp_Object Voverriding_local_map
;
175 /* Current depth in recursive edits. */
176 int command_loop_level
;
178 /* Total number of times command_loop has read a key sequence. */
181 /* Last input character read as a command. */
182 Lisp_Object last_command_char
;
184 /* Last input character read as a command, not counting menus
185 reached by the mouse. */
186 Lisp_Object last_nonmenu_event
;
188 /* Last input character read for any purpose. */
189 Lisp_Object last_input_char
;
191 /* If not Qnil, a list of objects to be read as subsequent command input. */
192 Lisp_Object Vunread_command_events
;
194 /* If not -1, an event to be read as subsequent command input. */
195 int unread_command_char
;
197 /* If not Qnil, this is a switch-frame event which we decided to put
198 off until the end of a key sequence. This should be read as the
199 next command input, after any unread_command_events.
201 read_key_sequence uses this to delay switch-frame events until the
202 end of the key sequence; Fread_char uses it to put off switch-frame
203 events until a non-ASCII event is acceptable as input. */
204 Lisp_Object unread_switch_frame
;
206 /* A mask of extra modifier bits to put into every keyboard char. */
207 int extra_keyboard_modifiers
;
209 /* Char to use as prefix when a meta character is typed in.
210 This is bound on entry to minibuffer in case ESC is changed there. */
212 Lisp_Object meta_prefix_char
;
214 /* Last size recorded for a current buffer which is not a minibuffer. */
215 static int last_non_minibuf_size
;
217 /* Number of idle seconds before an auto-save and garbage collection. */
218 static Lisp_Object Vauto_save_timeout
;
220 /* Total number of times read_char has returned. */
223 /* Total number of times read_char has returned, outside of macros. */
224 int num_nonmacro_input_chars
;
226 /* Auto-save automatically when this many characters have been typed
227 since the last time. */
229 static int auto_save_interval
;
231 /* Value of num_nonmacro_input_chars as of last auto save. */
235 /* Last command executed by the editor command loop, not counting
236 commands that set the prefix argument. */
238 Lisp_Object last_command
;
240 /* The command being executed by the command loop.
241 Commands may set this, and the value set will be copied into last_command
242 instead of the actual command. */
243 Lisp_Object this_command
;
245 /* The value of point when the last command was executed. */
246 int last_point_position
;
248 /* The buffer that was current when the last command was started. */
249 Lisp_Object last_point_position_buffer
;
252 /* The frame in which the last input event occurred, or Qmacro if the
253 last event came from a macro. We use this to determine when to
254 generate switch-frame events. This may be cleared by functions
255 like Fselect_frame, to make sure that a switch-frame event is
256 generated by the next character. */
257 Lisp_Object internal_last_event_frame
;
260 /* A user-visible version of the above, intended to allow users to
261 figure out where the last event came from, if the event doesn't
262 carry that information itself (i.e. if it was a character). */
263 Lisp_Object Vlast_event_frame
;
265 /* The timestamp of the last input event we received from the X server.
266 X Windows wants this for selection ownership. */
267 unsigned long last_event_timestamp
;
269 Lisp_Object Qself_insert_command
;
270 Lisp_Object Qforward_char
;
271 Lisp_Object Qbackward_char
;
272 Lisp_Object Qundefined
;
274 /* read_key_sequence stores here the command definition of the
275 key sequence that it reads. */
276 Lisp_Object read_key_sequence_cmd
;
278 /* Form to evaluate (if non-nil) when Emacs is started. */
279 Lisp_Object Vtop_level
;
281 /* User-supplied string to translate input characters through. */
282 Lisp_Object Vkeyboard_translate_table
;
284 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
285 extern Lisp_Object Vfunction_key_map
;
287 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
288 Lisp_Object Vkey_translation_map
;
290 /* Non-nil means deactivate the mark at end of this command. */
291 Lisp_Object Vdeactivate_mark
;
293 /* Menu bar specified in Lucid Emacs fashion. */
295 Lisp_Object Vlucid_menu_bar_dirty_flag
;
296 Lisp_Object Qrecompute_lucid_menubar
, Qactivate_menubar_hook
;
298 /* Hooks to run before and after each command. */
299 Lisp_Object Qpre_command_hook
, Qpost_command_hook
;
300 Lisp_Object Vpre_command_hook
, Vpost_command_hook
;
301 Lisp_Object Qcommand_hook_internal
, Vcommand_hook_internal
;
303 /* List of deferred actions to be performed at a later time.
304 The precise format isn't relevant here; we just check whether it is nil. */
305 Lisp_Object Vdeferred_action_list
;
307 /* Function to call to handle deferred actions, when there are any. */
308 Lisp_Object Vdeferred_action_function
;
310 /* File in which we write all commands we read. */
313 /* Nonzero if input is available. */
316 /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
317 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
321 extern char *pending_malloc_warning
;
323 /* Circular buffer for pre-read keyboard input. */
324 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
326 /* Vector to GCPRO the frames and windows mentioned in kbd_buffer.
328 The interrupt-level event handlers will never enqueue an event on a
329 frame which is not in Vframe_list, and once an event is dequeued,
330 internal_last_event_frame or the event itself points to the frame.
333 But while the event is sitting in the queue, it's completely
334 unprotected. Suppose the user types one command which will run for
335 a while and then delete a frame, and then types another event at
336 the frame that will be deleted, before the command gets around to
337 it. Suppose there are no references to this frame elsewhere in
338 Emacs, and a GC occurs before the second event is dequeued. Now we
339 have an event referring to a freed frame, which will crash Emacs
342 Similar things happen when an event on a scroll bar is enqueued; the
343 window may be deleted while the event is in the queue.
345 So, we use this vector to protect the frame_or_window field in the
346 event queue. That way, they'll be dequeued as dead frames or
347 windows, but still valid lisp objects.
349 If kbd_buffer[i].kind != no_event, then
350 (XVECTOR (kbd_buffer_frame_or_window)->contents[i]
351 == kbd_buffer[i].frame_or_window. */
352 static Lisp_Object kbd_buffer_frame_or_window
;
354 /* Pointer to next available character in kbd_buffer.
355 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
356 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the
357 next available char is in kbd_buffer[0]. */
358 static struct input_event
*kbd_fetch_ptr
;
360 /* Pointer to next place to store character in kbd_buffer. This
361 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
362 character should go in kbd_buffer[0]. */
363 static volatile struct input_event
*kbd_store_ptr
;
365 /* The above pair of variables forms a "queue empty" flag. When we
366 enqueue a non-hook event, we increment kbd_write_count. When we
367 dequeue a non-hook event, we increment kbd_read_count. We say that
368 there is input available iff the two counters are not equal.
370 Why not just have a flag set and cleared by the enqueuing and
371 dequeuing functions? Such a flag could be screwed up by interrupts
372 at inopportune times. */
374 /* If this flag is non-zero, we check mouse_moved to see when the
375 mouse moves, and motion events will appear in the input stream. If
376 it is zero, mouse motion is ignored. */
377 static int do_mouse_tracking
;
379 /* The window system handling code should set this if the mouse has
380 moved since the last call to the mouse_position_hook. Calling that
381 hook should clear this. Code assumes that if this is set, it can
382 call mouse_position_hook to get the promised position, so don't set
383 it unless you're prepared to substantiate the claim! */
386 /* True iff there is an event in kbd_buffer, or if mouse tracking is
387 enabled and there is a new mouse position in the mouse movement
388 buffer. Note that if this is false, that doesn't mean that there
389 is readable input; all the events in the queue might be button-up
390 events, and do_mouse_tracking might be off. */
391 #define EVENT_QUEUES_EMPTY \
392 ((kbd_fetch_ptr == kbd_store_ptr) && (!do_mouse_tracking || !mouse_moved))
395 /* Symbols to head events. */
396 Lisp_Object Qmouse_movement
;
397 Lisp_Object Qscroll_bar_movement
;
398 Lisp_Object Qswitch_frame
;
399 Lisp_Object Qdelete_frame
;
401 /* Symbols to denote kinds of events. */
402 Lisp_Object Qfunction_key
;
403 Lisp_Object Qmouse_click
;
404 /* Lisp_Object Qmouse_movement; - also an event header */
406 /* Properties of event headers. */
407 Lisp_Object Qevent_kind
;
408 Lisp_Object Qevent_symbol_elements
;
410 Lisp_Object Qmenu_enable
;
412 /* An event header symbol HEAD may have a property named
413 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
414 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
415 mask of modifiers applied to it. If present, this is used to help
416 speed up parse_modifiers. */
417 Lisp_Object Qevent_symbol_element_mask
;
419 /* An unmodified event header BASE may have a property named
420 Qmodifier_cache, which is an alist mapping modifier masks onto
421 modified versions of BASE. If present, this helps speed up
423 Lisp_Object Qmodifier_cache
;
425 /* Symbols to use for parts of windows. */
426 Lisp_Object Qmode_line
;
427 Lisp_Object Qvertical_line
;
428 Lisp_Object Qvertical_scroll_bar
;
429 Lisp_Object Qmenu_bar
;
431 extern Lisp_Object Qmenu_enable
;
433 Lisp_Object
recursive_edit_unwind (), command_loop ();
434 Lisp_Object
Fthis_command_keys ();
435 Lisp_Object Qextended_command_history
;
437 Lisp_Object Qpolling_period
;
439 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
441 EMACS_TIME
*input_available_clear_time
;
443 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
444 Default is 1 if INTERRUPT_INPUT is defined. */
447 /* Nonzero while interrupts are temporarily deferred during redisplay. */
448 int interrupts_deferred
;
450 /* nonzero means use ^S/^Q for flow control. */
453 /* Allow m- file to inhibit use of FIONREAD. */
454 #ifdef BROKEN_FIONREAD
458 /* We are unable to use interrupts if FIONREAD is not available,
459 so flush SIGIO so we won't try. */
466 /* If we support X Windows, turn on the code to poll periodically
467 to detect C-g. It isn't actually used when doing interrupt input. */
468 #ifdef HAVE_X_WINDOWS
469 #define POLL_FOR_INPUT
472 /* Global variable declarations. */
474 /* Function for init_keyboard to call with no args (if nonzero). */
475 void (*keyboard_init_hook
) ();
477 static int read_avail_input ();
478 static void get_input_pending ();
479 static int readable_events ();
480 static Lisp_Object
read_char_x_menu_prompt ();
481 static Lisp_Object
read_char_minibuf_menu_prompt ();
482 static Lisp_Object
make_lispy_event ();
483 static Lisp_Object
make_lispy_movement ();
484 static Lisp_Object
modify_event_symbol ();
485 static Lisp_Object
make_lispy_switch_frame ();
487 /* > 0 if we are to echo keystrokes. */
488 static int echo_keystrokes
;
490 /* Nonzero means echo each character as typed. */
491 static int immediate_echo
;
493 /* The text we're echoing in the modeline - partial key sequences,
494 usually. '\0'-terminated. This really shouldn't have a fixed size. */
495 static char echobuf
[300];
497 /* Where to append more text to echobuf if we want to. */
498 static char *echoptr
;
500 /* If we have echoed a prompt string specified by the user,
501 this is its length. Otherwise this is -1. */
502 static int echo_after_prompt
;
504 /* Nonzero means don't try to suspend even if the operating system seems
506 static int cannot_suspend
;
508 #define min(a,b) ((a)<(b)?(a):(b))
509 #define max(a,b) ((a)>(b)?(a):(b))
511 /* Install the string STR as the beginning of the string of echoing,
512 so that it serves as a prompt for the next character.
513 Also start echoing. */
518 int len
= strlen (str
);
520 if (len
> sizeof echobuf
- 4)
521 len
= sizeof echobuf
- 4;
522 bcopy (str
, echobuf
, len
);
523 echoptr
= echobuf
+ len
;
526 echo_after_prompt
= len
;
531 /* Add C to the echo string, if echoing is going on.
532 C can be a character, which is printed prettily ("M-C-x" and all that
533 jazz), or a symbol, whose name is printed. */
538 extern char *push_key_description ();
547 /* If someone has passed us a composite event, use its head symbol. */
552 if (ptr
- echobuf
> sizeof echobuf
- 6)
555 ptr
= push_key_description (XINT (c
), ptr
);
557 else if (SYMBOLP (c
))
559 struct Lisp_String
*name
= XSYMBOL (c
)->name
;
560 if (((ptr
- echobuf
) + name
->size
+ 4) > sizeof echobuf
)
562 bcopy (name
->data
, ptr
, name
->size
);
566 if (echoptr
== echobuf
&& EQ (c
, Vhelp_char
))
568 strcpy (ptr
, " (Type ? for further options)");
579 /* Temporarily add a dash to the end of the echo string if it's not
580 empty, so that it serves as a mini-prompt for the very next character. */
584 if (!immediate_echo
&& echoptr
== echobuf
)
586 /* Do nothing if we just printed a prompt. */
587 if (echo_after_prompt
== echoptr
- echobuf
)
589 /* Do nothing if not echoing at all. */
593 /* Put a dash at the end of the buffer temporarily,
594 but make it go away when the next character is added. */
601 /* Display the current echo string, and begin echoing if not already
611 for (i
= 0; i
< this_command_key_count
; i
++)
614 c
= XVECTOR (this_command_keys
)->contents
[i
];
615 if (! (EVENT_HAS_PARAMETERS (c
)
616 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
626 if (waiting_for_input
&& !NILP (Vquit_flag
))
627 quit_throw_to_read_char ();
630 /* Turn off echoing, for the start of a new command. */
636 echo_after_prompt
= -1;
639 /* Return the length of the current echo string. */
644 return echoptr
- echobuf
;
647 /* Truncate the current echo message to its first LEN chars.
648 This and echo_char get used by read_key_sequence when the user
649 switches frames while entering a key sequence. */
656 echoptr
= echobuf
+ len
;
657 truncate_echo_area (len
);
661 /* Functions for manipulating this_command_keys. */
663 add_command_key (key
)
666 int size
= XVECTOR (this_command_keys
)->size
;
668 if (this_command_key_count
>= size
)
670 Lisp_Object new_keys
;
672 new_keys
= Fmake_vector (make_number (size
* 2), Qnil
);
673 bcopy (XVECTOR (this_command_keys
)->contents
,
674 XVECTOR (new_keys
)->contents
,
675 size
* sizeof (Lisp_Object
));
677 this_command_keys
= new_keys
;
680 XVECTOR (this_command_keys
)->contents
[this_command_key_count
++] = key
;
686 int count
= specpdl_ptr
- specpdl
;
689 if (command_loop_level
> 0)
691 specbind (Qstandard_output
, Qt
);
692 specbind (Qstandard_input
, Qt
);
695 val
= command_loop ();
697 Fsignal (Qquit
, Qnil
);
699 return unbind_to (count
, Qnil
);
702 /* When an auto-save happens, record the "time", and don't do again soon. */
706 last_auto_save
= num_nonmacro_input_chars
;
709 /* Make an auto save happen as soon as possible at command level. */
711 force_auto_save_soon ()
713 last_auto_save
= - auto_save_interval
- 1;
715 record_asynch_buffer_change ();
718 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
719 "Invoke the editor command loop recursively.\n\
720 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
721 that tells this function to return.\n\
722 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
723 This function is called by the editor initialization to begin editing.")
726 int count
= specpdl_ptr
- specpdl
;
729 command_loop_level
++;
730 update_mode_lines
= 1;
732 record_unwind_protect (recursive_edit_unwind
,
734 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
738 return unbind_to (count
, Qnil
);
742 recursive_edit_unwind (buffer
)
746 Fset_buffer (buffer
);
748 command_loop_level
--;
749 update_mode_lines
= 1;
757 Vstandard_output
= Qt
;
758 Vstandard_input
= Qt
;
759 Vexecuting_macro
= Qnil
;
760 cmd_error_internal (data
, 0);
764 Vinhibit_quit
= Qnil
;
766 return make_number (0);
769 cmd_error_internal (data
, context
)
773 Lisp_Object errmsg
, tail
, errname
, file_error
;
780 echo_area_glyphs
= 0;
782 /* If the window system or terminal frame hasn't been initialized
783 yet, or we're not interactive, it's best to dump this message out
784 to stderr and exit. */
785 if (! FRAME_MESSAGE_BUF (selected_frame
)
787 stream
= Qexternal_debugging_output
;
796 write_string_1 (context
, -1, stream
);
798 errname
= Fcar (data
);
800 if (EQ (errname
, Qerror
))
803 if (!CONSP (data
)) data
= Qnil
;
804 errmsg
= Fcar (data
);
809 errmsg
= Fget (errname
, Qerror_message
);
810 file_error
= Fmemq (Qfile_error
,
811 Fget (errname
, Qerror_conditions
));
814 /* Print an error message including the data items.
815 This is done by printing it into a scratch buffer
816 and then making a copy of the text in the buffer. */
818 if (!CONSP (data
)) data
= Qnil
;
822 /* For file-error, make error message by concatenating
823 all the data items. They are all strings. */
824 if (!NILP (file_error
) && !NILP (tail
))
825 errmsg
= XCONS (tail
)->car
, tail
= XCONS (tail
)->cdr
;
827 if (STRINGP (errmsg
))
828 Fprinc (errmsg
, stream
);
830 write_string_1 ("peculiar error", -1, stream
);
832 for (i
= 0; CONSP (tail
); tail
= Fcdr (tail
), i
++)
834 write_string_1 (i
? ", " : ": ", 2, stream
);
835 if (!NILP (file_error
))
836 Fprinc (Fcar (tail
), stream
);
838 Fprin1 (Fcar (tail
), stream
);
842 /* If the window system or terminal frame hasn't been initialized
843 yet, or we're in -batch mode, this error should cause Emacs to exit. */
844 if (! FRAME_MESSAGE_BUF (selected_frame
)
848 Fkill_emacs (make_number (-1));
852 Lisp_Object
command_loop_1 ();
853 Lisp_Object
command_loop_2 ();
854 Lisp_Object
top_level_1 ();
856 /* Entry to editor-command-loop.
857 This level has the catches for exiting/returning to editor command loop.
858 It returns nil to exit recursive edit, t to abort it. */
863 if (command_loop_level
> 0 || minibuf_level
> 0)
865 return internal_catch (Qexit
, command_loop_2
, Qnil
);
870 internal_catch (Qtop_level
, top_level_1
, Qnil
);
871 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
873 /* End of file in -batch run causes exit here. */
879 /* Here we catch errors in execution of commands within the
880 editing loop, and reenter the editing loop.
881 When there is an error, cmd_error runs and returns a non-nil
882 value to us. A value of nil means that cmd_loop_1 itself
883 returned due to end of file (or end of kbd macro). */
888 register Lisp_Object val
;
891 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
900 return Feval (Vtop_level
);
906 /* On entry to the outer level, run the startup file */
907 if (!NILP (Vtop_level
))
908 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
909 else if (!NILP (Vpurify_flag
))
910 message ("Bare impure Emacs (standard Lisp code not loaded)");
912 message ("Bare Emacs (standard Lisp code not loaded)");
916 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
917 "Exit all recursive editing levels.")
920 Fthrow (Qtop_level
, Qnil
);
923 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
924 "Exit from the innermost recursive edit or minibuffer.")
927 if (command_loop_level
> 0 || minibuf_level
> 0)
928 Fthrow (Qexit
, Qnil
);
930 error ("No recursive edit is in progress");
933 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
934 "Abort the command that requested this recursive edit or minibuffer input.")
937 if (command_loop_level
> 0 || minibuf_level
> 0)
940 error ("No recursive edit is in progress");
943 /* This is the actual command reading loop,
944 sans error-handling encapsulation. */
946 Lisp_Object
Fcommand_execute ();
947 static int read_key_sequence ();
948 static void safe_run_hooks ();
953 Lisp_Object cmd
, tem
;
956 Lisp_Object keybuf
[30];
961 struct buffer
*prev_buffer
;
964 Vdeactivate_mark
= Qnil
;
965 waiting_for_input
= 0;
970 this_command_key_count
= 0;
972 /* Make sure this hook runs after commands that get errors and
973 throw to top level. */
974 /* Note that the value cell will never directly contain nil
975 if the symbol is a local variable. */
976 if (!NILP (XSYMBOL (Qpost_command_hook
)->value
) && !NILP (Vrun_hooks
))
977 safe_run_hooks (Qpost_command_hook
);
979 if (!NILP (Vdeferred_action_list
))
980 call0 (Vdeferred_action_function
);
982 /* Do this after running Vpost_command_hook, for consistency. */
983 last_command
= this_command
;
987 /* Install chars successfully executed in kbd macro. */
989 if (defining_kbd_macro
&& NILP (Vprefix_arg
))
990 finalize_kbd_macro_chars ();
992 /* Make sure the current window's buffer is selected. */
993 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
994 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
996 /* Display any malloc warning that just came out. Use while because
997 displaying one warning can cause another. */
999 while (pending_malloc_warning
)
1000 display_malloc_warning ();
1004 Vdeactivate_mark
= Qnil
;
1006 /* If minibuffer on and echo area in use,
1007 wait 2 sec and redraw minibuffer. */
1009 if (minibuf_level
&& echo_area_glyphs
)
1011 /* Bind inhibit-quit to t so that C-g gets read in
1012 rather than quitting back to the minibuffer. */
1013 int count
= specpdl_ptr
- specpdl
;
1014 specbind (Qinhibit_quit
, Qt
);
1015 Fsit_for (make_number (2), Qnil
, Qnil
);
1016 unbind_to (count
, Qnil
);
1018 echo_area_glyphs
= 0;
1020 if (!NILP (Vquit_flag
))
1023 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1028 alloca (0); /* Cause a garbage collection now */
1029 /* Since we can free the most stuff here. */
1030 #endif /* C_ALLOCA */
1034 /* Select the frame that the last event came from. Usually,
1035 switch-frame events will take care of this, but if some lisp
1036 code swallows a switch-frame event, we'll fix things up here.
1037 Is this a good idea? */
1038 if (FRAMEP (internal_last_event_frame
)
1039 && XFRAME (internal_last_event_frame
) != selected_frame
)
1040 Fselect_frame (internal_last_event_frame
, Qnil
);
1043 /* If it has changed current-menubar from previous value,
1044 really recompute the menubar from the value. */
1045 if (! NILP (Vlucid_menu_bar_dirty_flag
)
1046 && !NILP (Ffboundp (Qrecompute_lucid_menubar
)))
1047 call0 (Qrecompute_lucid_menubar
);
1049 /* Read next key sequence; i gets its length. */
1050 i
= read_key_sequence (keybuf
, (sizeof keybuf
/ sizeof (keybuf
[0])), Qnil
);
1054 /* Now we have read a key sequence of length I,
1055 or else I is 0 and we found end of file. */
1057 if (i
== 0) /* End of file -- happens only in */
1058 return Qnil
; /* a kbd macro, at the end. */
1059 /* -1 means read_key_sequence got a menu that was rejected.
1060 Just loop around and read another command. */
1064 this_command_key_count
= 0;
1068 last_command_char
= keybuf
[i
- 1];
1070 /* If the previous command tried to force a specific window-start,
1071 forget about that, in case this command moves point far away
1072 from that position. */
1073 XWINDOW (selected_window
)->force_start
= Qnil
;
1075 cmd
= read_key_sequence_cmd
;
1076 if (!NILP (Vexecuting_macro
))
1078 if (!NILP (Vquit_flag
))
1080 Vexecuting_macro
= Qt
;
1081 QUIT
; /* Make some noise. */
1082 /* Will return since macro now empty. */
1086 /* Do redisplay processing after this command except in special
1087 cases identified below that set no_redisplay to 1.
1088 (actually, there's currently no way to prevent the redisplay,
1089 and no_redisplay is ignored.
1090 Perhaps someday we will really implement it. */
1093 prev_buffer
= current_buffer
;
1094 prev_modiff
= MODIFF
;
1095 last_point_position
= PT
;
1096 XSETBUFFER (last_point_position_buffer
, prev_buffer
);
1098 /* Execute the command. */
1101 /* Note that the value cell will never directly contain nil
1102 if the symbol is a local variable. */
1103 if (!NILP (XSYMBOL (Qpre_command_hook
)->value
) && !NILP (Vrun_hooks
))
1104 safe_run_hooks (Qpre_command_hook
);
1106 if (NILP (this_command
))
1108 /* nil means key is undefined. */
1110 defining_kbd_macro
= 0;
1111 update_mode_lines
= 1;
1117 if (NILP (Vprefix_arg
) && ! no_direct
)
1119 /* Recognize some common commands in common situations and
1120 do them directly. */
1121 if (EQ (this_command
, Qforward_char
) && PT
< ZV
)
1123 struct Lisp_Vector
*dp
1124 = window_display_table (XWINDOW (selected_window
));
1125 lose
= FETCH_CHAR (PT
);
1128 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1129 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1130 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1131 && (lose
>= 0x20 && lose
< 0x7f)))
1132 : (lose
>= 0x20 && lose
< 0x7f))
1133 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1135 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1137 && !windows_or_buffers_changed
1138 && EQ (current_buffer
->selective_display
, Qnil
)
1139 && !detect_input_pending ()
1140 && NILP (Vexecuting_macro
))
1141 no_redisplay
= direct_output_forward_char (1);
1144 else if (EQ (this_command
, Qbackward_char
) && PT
> BEGV
)
1146 struct Lisp_Vector
*dp
1147 = window_display_table (XWINDOW (selected_window
));
1149 lose
= FETCH_CHAR (PT
);
1151 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1152 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1153 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1154 && (lose
>= 0x20 && lose
< 0x7f)))
1155 : (lose
>= 0x20 && lose
< 0x7f))
1156 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1158 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1160 && !windows_or_buffers_changed
1161 && EQ (current_buffer
->selective_display
, Qnil
)
1162 && !detect_input_pending ()
1163 && NILP (Vexecuting_macro
))
1164 no_redisplay
= direct_output_forward_char (-1);
1167 else if (EQ (this_command
, Qself_insert_command
)
1168 /* Try this optimization only on ascii keystrokes. */
1169 && INTEGERP (last_command_char
))
1171 unsigned char c
= XINT (last_command_char
);
1174 if (NILP (Vexecuting_macro
)
1175 && !EQ (minibuf_window
, selected_window
))
1177 if (!nonundocount
|| nonundocount
>= 20)
1184 lose
= ((XFASTINT (XWINDOW (selected_window
)->last_modified
)
1186 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1188 || MODIFF
<= current_buffer
->save_modified
1189 || windows_or_buffers_changed
1190 || !EQ (current_buffer
->selective_display
, Qnil
)
1191 || detect_input_pending ()
1192 || !NILP (Vexecuting_macro
));
1193 value
= internal_self_insert (c
, 0);
1200 && (PT
== ZV
|| FETCH_CHAR (PT
) == '\n'))
1202 struct Lisp_Vector
*dp
1203 = window_display_table (XWINDOW (selected_window
));
1210 obj
= DISP_CHAR_VECTOR (dp
, lose
);
1213 /* Do it only for char codes
1214 that by default display as themselves. */
1215 if (lose
>= 0x20 && lose
<= 0x7e)
1216 no_redisplay
= direct_output_for_insert (lose
);
1218 else if (VECTORP (obj
)
1219 && XVECTOR (obj
)->size
== 1
1220 && (obj
= XVECTOR (obj
)->contents
[0],
1222 /* Insist face not specified in glyph. */
1223 && (XINT (obj
) & ((-1) << 8)) == 0)
1225 = direct_output_for_insert (XINT (obj
));
1229 if (lose
>= 0x20 && lose
<= 0x7e)
1230 no_redisplay
= direct_output_for_insert (lose
);
1237 /* Here for a command that isn't executed directly */
1240 if (NILP (Vprefix_arg
))
1242 Fcommand_execute (this_command
, Qnil
);
1247 /* Note that the value cell will never directly contain nil
1248 if the symbol is a local variable. */
1249 if (!NILP (XSYMBOL (Qpost_command_hook
)->value
) && !NILP (Vrun_hooks
))
1250 safe_run_hooks (Qpost_command_hook
);
1252 if (!NILP (Vdeferred_action_list
))
1253 call0 (Vdeferred_action_function
);
1255 /* If there is a prefix argument,
1256 1) We don't want last_command to be ``universal-argument''
1257 (that would be dumb), so don't set last_command,
1258 2) we want to leave echoing on so that the prefix will be
1259 echoed as part of this key sequence, so don't call
1261 3) we want to leave this_command_key_count non-zero, so that
1262 read_char will realize that it is re-reading a character, and
1263 not echo it a second time. */
1264 if (NILP (Vprefix_arg
))
1266 last_command
= this_command
;
1268 this_command_key_count
= 0;
1271 if (!NILP (current_buffer
->mark_active
) && !NILP (Vrun_hooks
))
1273 if (!NILP (Vdeactivate_mark
) && !NILP (Vtransient_mark_mode
))
1275 current_buffer
->mark_active
= Qnil
;
1276 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
1278 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
1279 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
1284 /* If we get an error while running the hook, cause the hook variable
1285 to be nil. Also inhibit quits, so that C-g won't cause the hook
1286 to mysteriously evaporate. */
1288 safe_run_hooks (hook
)
1292 int count
= specpdl_ptr
- specpdl
;
1293 specbind (Qinhibit_quit
, Qt
);
1295 /* We read and set the variable with functions,
1296 in case it's buffer-local. */
1297 value
= Vcommand_hook_internal
= Fsymbol_value (hook
);
1299 call1 (Vrun_hooks
, Qcommand_hook_internal
);
1302 unbind_to (count
, Qnil
);
1305 /* Number of seconds between polling for input. */
1308 /* Nonzero means polling for input is temporarily suppressed. */
1309 int poll_suppress_count
;
1311 /* Nonzero if polling_for_input is actually being used. */
1312 int polling_for_input
;
1314 #ifdef POLL_FOR_INPUT
1316 /* Handle an alarm once each second and read pending input
1317 so as to handle a C-g if it comces in. */
1320 input_poll_signal ()
1322 if (interrupt_input_blocked
== 0
1323 && !waiting_for_input
)
1324 read_avail_input (0);
1325 signal (SIGALRM
, input_poll_signal
);
1326 alarm (polling_period
);
1331 /* Begin signals to poll for input, if they are appropriate.
1332 This function is called unconditionally from various places. */
1336 #ifdef POLL_FOR_INPUT
1337 if (read_socket_hook
&& !interrupt_input
)
1339 poll_suppress_count
--;
1340 if (poll_suppress_count
== 0)
1342 signal (SIGALRM
, input_poll_signal
);
1343 polling_for_input
= 1;
1344 alarm (polling_period
);
1350 /* Nonzero if we are using polling to handle input asynchronously. */
1353 input_polling_used ()
1355 #ifdef POLL_FOR_INPUT
1356 return read_socket_hook
&& !interrupt_input
;
1362 /* Turn off polling. */
1366 #ifdef POLL_FOR_INPUT
1367 if (read_socket_hook
&& !interrupt_input
)
1369 if (poll_suppress_count
== 0)
1371 polling_for_input
= 0;
1374 poll_suppress_count
++;
1379 /* Set the value of poll_suppress_count to COUNT
1380 and start or stop polling accordingly. */
1383 set_poll_suppress_count (count
)
1386 #ifdef POLL_FOR_INPUT
1387 if (count
== 0 && poll_suppress_count
!= 0)
1389 poll_suppress_count
= 1;
1392 else if (count
!= 0 && poll_suppress_count
== 0)
1396 poll_suppress_count
= count
;
1400 /* Bind polling_period to a value at least N.
1401 But don't decrease it. */
1403 bind_polling_period (n
)
1406 #ifdef POLL_FOR_INPUT
1407 int new = polling_period
;
1413 specbind (Qpolling_period
, make_number (new));
1414 /* Start a new alarm with the new period. */
1419 /* Applying the control modifier to CHARACTER. */
1424 /* Save the upper bits here. */
1425 int upper
= c
& ~0177;
1429 /* Everything in the columns containing the upper-case letters
1430 denotes a control character. */
1431 if (c
>= 0100 && c
< 0140)
1435 /* Set the shift modifier for a control char
1436 made from a shifted letter. But only for letters! */
1437 if (oc
>= 'A' && oc
<= 'Z')
1438 c
|= shift_modifier
;
1441 /* The lower-case letters denote control characters too. */
1442 else if (c
>= 'a' && c
<= 'z')
1445 /* Include the bits for control and shift
1446 only if the basic ASCII code can't indicate them. */
1450 /* Replace the high bits. */
1451 c
|= (upper
& ~ctrl_modifier
);
1458 /* Input of single characters from keyboard */
1460 Lisp_Object
print_help ();
1461 static Lisp_Object
kbd_buffer_get_event ();
1463 /* read a character from the keyboard; call the redisplay if needed */
1464 /* commandflag 0 means do not do auto-saving, but do do redisplay.
1465 -1 means do not do redisplay, but do do autosaving.
1468 /* The arguments MAPS and NMAPS are for menu prompting.
1469 MAPS is an array of keymaps; NMAPS is the length of MAPS.
1471 PREV_EVENT is the previous input event, or nil if we are reading
1472 the first event of a key sequence.
1474 If USED_MOUSE_MENU is non-zero, then we set *USED_MOUSE_MENU to 1
1475 if we used a mouse menu to read the input, or zero otherwise. If
1476 USED_MOUSE_MENU is zero, *USED_MOUSE_MENU is left alone.
1478 Value is t if we showed a menu and the user rejected it. */
1481 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
)
1485 Lisp_Object prev_event
;
1486 int *used_mouse_menu
;
1488 register Lisp_Object c
;
1491 int key_already_recorded
= 0;
1493 if (CONSP (Vunread_command_events
))
1495 c
= XCONS (Vunread_command_events
)->car
;
1496 Vunread_command_events
= XCONS (Vunread_command_events
)->cdr
;
1498 if (this_command_key_count
== 0)
1504 if (unread_command_char
!= -1)
1506 XSETINT (c
, unread_command_char
);
1507 unread_command_char
= -1;
1509 if (this_command_key_count
== 0)
1515 if (!NILP (Vexecuting_macro
))
1518 /* We set this to Qmacro; since that's not a frame, nobody will
1519 try to switch frames on us, and the selected window will
1522 Since this event came from a macro, it would be misleading to
1523 leave internal_last_event_frame set to wherever the last
1524 real event came from. Normally, a switch-frame event selects
1525 internal_last_event_frame after each command is read, but
1526 events read from a macro should never cause a new frame to be
1528 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
1531 /* Exit the macro if we are at the end.
1532 Also, some things replace the macro with t
1533 to force an early exit. */
1534 if (EQ (Vexecuting_macro
, Qt
)
1535 || executing_macro_index
>= XFASTINT (Flength (Vexecuting_macro
)))
1541 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
1542 if (STRINGP (Vexecuting_macro
)
1543 && (XINT (c
) & 0x80))
1544 XSETFASTINT (c
, CHAR_META
| (XINT (c
) & ~0x80));
1546 executing_macro_index
++;
1551 if (!NILP (unread_switch_frame
))
1553 c
= unread_switch_frame
;
1554 unread_switch_frame
= Qnil
;
1556 /* This event should make it into this_command_keys, and get echoed
1557 again, so we go to reread_first, rather than reread. */
1561 /* Don't bother updating menu bars while doing mouse tracking.
1562 We get events very rapidly then, and the menu bar won't be changing.
1563 We do update the menu bar once on entry to Ftrack_mouse. */
1564 if (commandflag
> 0 && !input_pending
&& !detect_input_pending ())
1565 prepare_menu_bars ();
1567 /* Save outer setjmp data, in case called recursively. */
1568 save_getcjmp (save_jump
);
1572 if (commandflag
>= 0 && !input_pending
&& !detect_input_pending ())
1575 if (_setjmp (getcjmp
))
1577 XSETINT (c
, quit_char
);
1579 XSETFRAME (internal_last_event_frame
, selected_frame
);
1580 Vlast_event_frame
= internal_last_event_frame
;
1582 /* If we report the quit char as an event,
1583 don't do so more than once. */
1584 if (!NILP (Vinhibit_quit
))
1590 /* Message turns off echoing unless more keystrokes turn it on again. */
1591 if (echo_area_glyphs
&& *echo_area_glyphs
&& echo_area_glyphs
!= echobuf
)
1594 /* If already echoing, continue. */
1597 /* Try reading a character via menu prompting in the minibuf.
1598 Try this before the sit-for, because the sit-for
1599 would do the wrong thing if we are supposed to do
1600 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
1601 after a mouse event so don't try a minibuf menu. */
1603 if (nmaps
> 0 && INTERACTIVE
1604 && !NILP (prev_event
) && ! EVENT_HAS_PARAMETERS (prev_event
)
1605 /* Don't bring up a menu if we already have another event. */
1606 && NILP (Vunread_command_events
)
1607 && unread_command_char
< 0
1608 && !detect_input_pending ())
1610 c
= read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
);
1613 key_already_recorded
= 1;
1618 /* If in middle of key sequence and minibuffer not active,
1619 start echoing if enough time elapses. */
1620 if (minibuf_level
== 0 && !immediate_echo
&& this_command_key_count
> 0
1622 && echo_keystrokes
> 0
1623 && (echo_area_glyphs
== 0 || *echo_area_glyphs
== 0))
1627 /* After a mouse event, start echoing right away.
1628 This is because we are probably about to display a menu,
1629 and we don't want to delay before doing so. */
1630 if (EVENT_HAS_PARAMETERS (prev_event
))
1634 tem0
= sit_for (echo_keystrokes
, 0, 1, 1);
1640 /* Maybe auto save due to number of keystrokes or idle time. */
1642 if (commandflag
!= 0
1643 && auto_save_interval
> 0
1644 && num_nonmacro_input_chars
- last_auto_save
> max (auto_save_interval
, 20)
1645 && !detect_input_pending ())
1648 save_getcjmp (temp
);
1649 Fdo_auto_save (Qnil
, Qnil
);
1650 restore_getcjmp (temp
);
1653 /* Try reading using an X menu.
1654 This is never confused with reading using the minibuf
1655 because the recursive call of read_char in read_char_minibuf_menu_prompt
1656 does not pass on any keymaps. */
1657 if (nmaps
> 0 && INTERACTIVE
1658 && !NILP (prev_event
) && EVENT_HAS_PARAMETERS (prev_event
)
1659 /* Don't bring up a menu if we already have another event. */
1660 && NILP (Vunread_command_events
)
1661 && unread_command_char
< 0)
1662 c
= read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
1664 /* Slow down auto saves logarithmically in size of current buffer,
1665 and garbage collect while we're at it. */
1666 if (INTERACTIVE
&& NILP (c
))
1668 int delay_level
, buffer_size
;
1670 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
1671 last_non_minibuf_size
= Z
- BEG
;
1672 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
1674 while (buffer_size
> 64)
1675 delay_level
++, buffer_size
-= buffer_size
>> 2;
1676 if (delay_level
< 4) delay_level
= 4;
1677 /* delay_level is 4 for files under around 50k, 7 at 100k,
1678 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
1680 /* Auto save if enough time goes by without input. */
1681 if (commandflag
!= 0
1682 && num_nonmacro_input_chars
> last_auto_save
1683 && INTEGERP (Vauto_save_timeout
)
1684 && XINT (Vauto_save_timeout
) > 0)
1687 int delay
= delay_level
* XFASTINT (Vauto_save_timeout
) / 4;
1688 tem0
= sit_for (delay
, 0, 1, 1);
1692 save_getcjmp (temp
);
1693 Fdo_auto_save (Qnil
, Qnil
);
1694 restore_getcjmp (temp
);
1696 /* If we have auto-saved and there is still no input
1697 available, garbage collect if there has been enough
1698 consing going on to make it worthwhile. */
1699 if (!detect_input_pending ()
1700 && consing_since_gc
> gc_cons_threshold
/ 2)
1702 Fgarbage_collect ();
1703 /* prepare_menu_bars isn't safe here, but it should
1704 also be unnecessary. */
1711 /* Actually read a character, waiting if necessary. */
1714 c
= kbd_buffer_get_event ();
1717 if (commandflag
>= 0 && !input_pending
&& !detect_input_pending ())
1719 prepare_menu_bars ();
1724 /* Terminate Emacs in batch mode if at eof. */
1725 if (noninteractive
&& INTEGERP (c
) && XINT (c
) < 0)
1726 Fkill_emacs (make_number (1));
1730 /* Add in any extra modifiers, where appropriate. */
1731 if ((extra_keyboard_modifiers
& CHAR_CTL
)
1732 || ((extra_keyboard_modifiers
& 0177) < ' '
1733 && (extra_keyboard_modifiers
& 0177) != 0))
1734 XSETINT (c
, make_ctrl_char (XINT (c
)));
1736 /* Transfer any other modifier bits directly from
1737 extra_keyboard_modifiers to c. Ignore the actual character code
1738 in the low 16 bits of extra_keyboard_modifiers. */
1739 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
1744 restore_getcjmp (save_jump
);
1748 /* Buffer switch events are only for internal wakeups
1749 so don't show them to the user. */
1753 if (key_already_recorded
)
1756 /* Wipe the echo area. */
1757 echo_area_glyphs
= 0;
1759 /* Handle things that only apply to characters. */
1762 /* If kbd_buffer_get_event gave us an EOF, return that. */
1766 if (STRINGP (Vkeyboard_translate_table
)
1767 && XSTRING (Vkeyboard_translate_table
)->size
> XFASTINT (c
))
1768 XSETINT (c
, XSTRING (Vkeyboard_translate_table
)->data
[XFASTINT (c
)]);
1772 XVECTOR (recent_keys
)->contents
[recent_keys_index
] = c
;
1773 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
1774 recent_keys_index
= 0;
1776 /* Write c to the dribble file. If c is a lispy event, write
1777 the event's symbol to the dribble file, in <brackets>. Bleaugh.
1778 If you, dear reader, have a better idea, you've got the source. :-) */
1783 if (XUINT (c
) < 0x100)
1784 putc (XINT (c
), dribble
);
1786 fprintf (dribble
, " 0x%x", XUINT (c
));
1790 Lisp_Object dribblee
;
1792 /* If it's a structured event, take the event header. */
1793 dribblee
= EVENT_HEAD (c
);
1795 if (SYMBOLP (dribblee
))
1797 putc ('<', dribble
);
1798 fwrite (XSYMBOL (dribblee
)->name
->data
, sizeof (char),
1799 XSYMBOL (dribblee
)->name
->size
,
1801 putc ('>', dribble
);
1808 store_kbd_macro_char (c
);
1810 num_nonmacro_input_chars
++;
1815 /* Don't echo mouse motion events. */
1816 if (! (EVENT_HAS_PARAMETERS (c
)
1817 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
1820 /* Record this character as part of the current key. */
1821 add_command_key (c
);
1823 /* Re-reading in the middle of a command */
1825 last_input_char
= c
;
1828 /* Process the help character specially if enabled */
1829 if (EQ (c
, Vhelp_char
) && !NILP (Vhelp_form
))
1832 count
= specpdl_ptr
- specpdl
;
1834 record_unwind_protect (Fset_window_configuration
,
1835 Fcurrent_window_configuration (Qnil
));
1837 tem0
= Feval (Vhelp_form
);
1839 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
1843 c
= read_char (0, 0, 0, Qnil
, 0);
1844 while (BUFFERP (c
));
1845 /* Remove the help from the frame */
1846 unbind_to (count
, Qnil
);
1847 prepare_menu_bars ();
1849 if (EQ (c
, make_number (040)))
1853 c
= read_char (0, 0, 0, Qnil
, 0);
1854 while (BUFFERP (c
));
1865 Fprinc (object
, Qnil
);
1869 /* Copy out or in the info on where C-g should throw to.
1870 This is used when running Lisp code from within get_char,
1871 in case get_char is called recursively.
1872 See read_process_output. */
1877 bcopy (getcjmp
, temp
, sizeof getcjmp
);
1880 restore_getcjmp (temp
)
1883 bcopy (temp
, getcjmp
, sizeof getcjmp
);
1887 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
1888 of this function. */
1890 tracking_off (old_value
)
1891 Lisp_Object old_value
;
1893 if (! XFASTINT (old_value
))
1895 do_mouse_tracking
= 0;
1897 /* Redisplay may have been preempted because there was input
1898 available, and it assumes it will be called again after the
1899 input has been processed. If the only input available was
1900 the sort that we have just disabled, then we need to call
1902 if (!readable_events ())
1904 prepare_menu_bars ();
1905 redisplay_preserve_echo_area ();
1906 get_input_pending (&input_pending
);
1911 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
1912 "Evaluate BODY with mouse movement events enabled.\n\
1913 Within a `track-mouse' form, mouse motion generates input events that\n\
1914 you can read with `read-event'.\n\
1915 Normally, mouse motion is ignored.")
1919 int count
= specpdl_ptr
- specpdl
;
1922 XSETINT (val
, do_mouse_tracking
);
1923 record_unwind_protect (tracking_off
, val
);
1925 if (!input_pending
&& !detect_input_pending ())
1926 prepare_menu_bars ();
1928 do_mouse_tracking
= 1;
1930 val
= Fprogn (args
);
1931 return unbind_to (count
, val
);
1934 /* Low level keyboard/mouse input.
1935 kbd_buffer_store_event places events in kbd_buffer, and
1936 kbd_buffer_get_event retrieves them.
1937 mouse_moved indicates when the mouse has moved again, and
1938 *mouse_position_hook provides the mouse position. */
1940 /* Return true iff there are any events in the queue that read-char
1941 would return. If this returns false, a read-char would block. */
1945 return ! EVENT_QUEUES_EMPTY
;
1948 /* Set this for debugging, to have a way to get out */
1951 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
1954 kbd_buffer_store_event (event
)
1955 register struct input_event
*event
;
1957 if (event
->kind
== no_event
)
1960 if (event
->kind
== ascii_keystroke
)
1962 register int c
= event
->code
& 0377;
1964 if (event
->modifiers
& ctrl_modifier
)
1965 c
= make_ctrl_char (c
);
1967 c
|= (event
->modifiers
1968 & (meta_modifier
| alt_modifier
1969 | hyper_modifier
| super_modifier
));
1973 extern SIGTYPE
interrupt_signal ();
1976 /* If this results in a quit_char being returned to Emacs as
1977 input, set Vlast_event_frame properly. If this doesn't
1978 get returned to Emacs as an event, the next event read
1979 will set Vlast_event_frame again, so this is safe to do. */
1983 focus
= FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
1985 internal_last_event_frame
= event
->frame_or_window
;
1987 internal_last_event_frame
= focus
;
1988 Vlast_event_frame
= internal_last_event_frame
;
1992 last_event_timestamp
= event
->timestamp
;
1993 interrupt_signal ();
1997 if (c
&& c
== stop_character
)
2004 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
2005 kbd_store_ptr
= kbd_buffer
;
2007 /* Don't let the very last slot in the buffer become full,
2008 since that would make the two pointers equal,
2009 and that is indistinguishable from an empty buffer.
2010 Discard the event if it would fill the last slot. */
2011 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
2013 kbd_store_ptr
->kind
= event
->kind
;
2014 if (event
->kind
== selection_request_event
)
2016 /* We must not use the ordinary copying code for this case,
2017 since `part' is an enum and copying it might not copy enough
2019 bcopy (event
, kbd_store_ptr
, sizeof (*event
));
2023 kbd_store_ptr
->code
= event
->code
;
2024 kbd_store_ptr
->part
= event
->part
;
2025 kbd_store_ptr
->frame_or_window
= event
->frame_or_window
;
2026 kbd_store_ptr
->modifiers
= event
->modifiers
;
2027 kbd_store_ptr
->x
= event
->x
;
2028 kbd_store_ptr
->y
= event
->y
;
2029 kbd_store_ptr
->timestamp
= event
->timestamp
;
2031 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_store_ptr
2033 = event
->frame_or_window
);
2039 /* Read one event from the event buffer, waiting if necessary.
2040 The value is a Lisp object representing the event.
2041 The value is nil for an event that should be ignored,
2042 or that was handled here.
2043 We always read and discard one event. */
2046 kbd_buffer_get_event ()
2058 /* Wait until there is input available. */
2061 if (!EVENT_QUEUES_EMPTY
)
2064 /* If the quit flag is set, then read_char will return
2065 quit_char, so that counts as "available input." */
2066 if (!NILP (Vquit_flag
))
2067 quit_throw_to_read_char ();
2069 /* One way or another, wait until input is available; then, if
2070 interrupt handlers have not read it, read it now. */
2073 wait_for_kbd_input ();
2075 /* Note SIGIO has been undef'd if FIONREAD is missing. */
2079 if (EVENT_QUEUES_EMPTY
)
2081 Lisp_Object minus_one
;
2083 XSETINT (minus_one
, -1);
2084 wait_reading_process_input (0, 0, minus_one
, 1);
2086 if (!interrupt_input
&& EVENT_QUEUES_EMPTY
)
2087 /* Pass 1 for EXPECT since we just waited to have input. */
2088 read_avail_input (1);
2090 #endif /* not VMS */
2093 /* At this point, we know that there is a readable event available
2094 somewhere. If the event queue is empty, then there must be a
2095 mouse movement enabled and available. */
2096 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2098 struct input_event
*event
;
2100 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2104 last_event_timestamp
= event
->timestamp
;
2108 /* These two kinds of events get special handling
2109 and don't actually appear to the command loop.
2110 We return nil for them. */
2111 if (event
->kind
== selection_request_event
)
2114 x_handle_selection_request (event
);
2115 kbd_fetch_ptr
= event
+ 1;
2117 /* We're getting selection request events, but we don't have
2123 else if (event
->kind
== selection_clear_event
)
2126 x_handle_selection_clear (event
);
2127 kbd_fetch_ptr
= event
+ 1;
2129 /* We're getting selection request events, but we don't have
2135 else if (event
->kind
== delete_window_event
)
2137 /* Make an event (delete-frame (FRAME)). */
2138 obj
= Fcons (event
->frame_or_window
, Qnil
);
2139 obj
= Fcons (intern ("delete-frame"), Fcons (obj
, Qnil
));
2140 kbd_fetch_ptr
= event
+ 1;
2143 else if (event
->kind
== menu_bar_event
)
2145 /* The event value is in the frame_or_window slot. */
2146 obj
= event
->frame_or_window
;
2147 kbd_fetch_ptr
= event
+ 1;
2149 else if (event
->kind
== buffer_switch_event
)
2151 /* The value doesn't matter here; only the type is tested. */
2152 XSETBUFFER (obj
, current_buffer
);
2153 kbd_fetch_ptr
= event
+ 1;
2155 /* Just discard these, by returning nil.
2156 (They shouldn't be found in the buffer,
2157 but on some machines it appears they do show up.) */
2158 else if (event
->kind
== no_event
)
2159 kbd_fetch_ptr
= event
+ 1;
2161 /* If this event is on a different frame, return a switch-frame this
2162 time, and leave the event in the queue for next time. */
2169 frame
= event
->frame_or_window
;
2170 if (WINDOWP (frame
))
2171 frame
= WINDOW_FRAME (XWINDOW (frame
));
2173 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
2177 if (! EQ (frame
, internal_last_event_frame
)
2178 && XFRAME (frame
) != selected_frame
)
2179 obj
= make_lispy_switch_frame (frame
);
2180 internal_last_event_frame
= frame
;
2181 #endif /* MULTI_FRAME */
2183 /* If we didn't decide to make a switch-frame event, go ahead
2184 and build a real event from the queue entry. */
2188 obj
= make_lispy_event (event
);
2190 /* Wipe out this event, to catch bugs. */
2191 event
->kind
= no_event
;
2192 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[event
- kbd_buffer
]
2195 kbd_fetch_ptr
= event
+ 1;
2199 /* Try generating a mouse motion event. */
2200 else if (do_mouse_tracking
&& mouse_moved
)
2203 Lisp_Object bar_window
;
2204 enum scroll_bar_part part
;
2208 (*mouse_position_hook
) (&f
, &bar_window
, &part
, &x
, &y
, &time
);
2213 /* Decide if we should generate a switch-frame event. Don't
2214 generate switch-frame events for motion outside of all Emacs
2220 frame
= FRAME_FOCUS_FRAME (f
);
2222 XSETFRAME (frame
, f
);
2224 if (! EQ (frame
, internal_last_event_frame
)
2225 && XFRAME (frame
) != selected_frame
)
2226 obj
= make_lispy_switch_frame (frame
);
2227 internal_last_event_frame
= frame
;
2231 #if defined (MULTI_FRAME) || defined (HAVE_MOUSE)
2232 /* If we didn't decide to make a switch-frame event, go ahead and
2233 return a mouse-motion event. */
2235 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
2239 /* We were promised by the above while loop that there was
2240 something for us to read! */
2243 input_pending
= readable_events ();
2246 Vlast_event_frame
= internal_last_event_frame
;
2252 /* Process any events that are not user-visible,
2253 then return, without reading any user-visible events. */
2258 while (kbd_fetch_ptr
!= kbd_store_ptr
)
2260 struct input_event
*event
;
2262 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2266 last_event_timestamp
= event
->timestamp
;
2268 /* These two kinds of events get special handling
2269 and don't actually appear to the command loop. */
2270 if (event
->kind
== selection_request_event
)
2273 x_handle_selection_request (event
);
2274 kbd_fetch_ptr
= event
+ 1;
2276 /* We're getting selection request events, but we don't have
2282 else if (event
->kind
== selection_clear_event
)
2285 x_handle_selection_clear (event
);
2286 kbd_fetch_ptr
= event
+ 1;
2288 /* We're getting selection request events, but we don't have
2297 get_input_pending (&input_pending
);
2300 /* Caches for modify_event_symbol. */
2301 static Lisp_Object accent_key_syms
;
2302 static Lisp_Object system_key_syms
;
2303 static Lisp_Object func_key_syms
;
2304 static Lisp_Object mouse_syms
;
2306 Lisp_Object Vsystem_key_alist
;
2308 /* This is a list of keysym codes for special "accent" characters.
2309 It parallels lispy_accent_keys. */
2311 static int lispy_accent_codes
[] =
2313 #ifdef XK_dead_circumflex
2318 #ifdef XK_dead_grave
2323 #ifdef XK_dead_tilde
2328 #ifdef XK_dead_diaeresis
2333 #ifdef XK_dead_macron
2338 #ifdef XK_dead_degree
2343 #ifdef XK_dead_acute
2348 #ifdef XK_dead_cedilla
2353 #ifdef XK_dead_breve
2358 #ifdef XK_dead_ogonek
2363 #ifdef XK_dead_caron
2368 #ifdef XK_dead_doubleacute
2369 XK_dead_doubleacute
,
2373 #ifdef XK_dead_abovedot
2380 /* This is a list of Lisp names for special "accent" characters.
2381 It parallels lispy_accent_codes. */
2383 static char *lispy_accent_keys
[] =
2400 /* You'll notice that this table is arranged to be conveniently
2401 indexed by X Windows keysym values. */
2402 static char *lispy_function_keys
[] =
2404 /* X Keysym value */
2406 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00 */
2414 0, 0, 0, /* 0xff10 */
2416 0, 0, 0, 0, 0, 0, 0,
2419 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff20...2f */
2420 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff30...3f */
2421 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
2423 "home", /* 0xff50 */ /* IsCursorKey */
2434 "select", /* 0xff60 */ /* IsMiscFunctionKey */
2445 "break", /* 0xff6b */
2447 0, 0, 0, 0, 0, 0, 0, 0, "backtab", 0,
2449 0, 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff7f */
2450 "kp-space", /* 0xff80 */ /* IsKeypadKey */
2451 0, 0, 0, 0, 0, 0, 0, 0,
2452 "kp-tab", /* 0xff89 */
2454 "kp-enter", /* 0xff8d */
2456 "kp-f1", /* 0xff91 */
2460 "kp-home", /* 0xff95 */
2465 "kp-prior", /* kp-page-up */
2466 "kp-next", /* kp-page-down */
2472 0, 0, 0, 0, 0, 0, 0, 0, 0,
2473 "kp-multiply", /* 0xffaa */
2478 "kp-divide", /* 0xffaf */
2479 "kp-0", /* 0xffb0 */
2480 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
2483 "kp-equal", /* 0xffbd */
2484 "f1", /* 0xffbe */ /* IsFunctionKey */
2486 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
2487 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
2488 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
2489 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
2490 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
2491 0, 0, 0, 0, 0, 0, 0, 0,
2492 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
2493 0, 0, 0, 0, 0, 0, 0, "delete"
2496 static char *lispy_mouse_names
[] =
2498 "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5"
2501 /* Scroll bar parts. */
2502 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
2504 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
2505 Lisp_Object
*scroll_bar_parts
[] = {
2506 &Qabove_handle
, &Qhandle
, &Qbelow_handle
2510 /* A vector, indexed by button number, giving the down-going location
2511 of currently depressed buttons, both scroll bar and non-scroll bar.
2513 The elements have the form
2514 (BUTTON-NUMBER MODIFIER-MASK . REST)
2515 where REST is the cdr of a position as it would be reported in the event.
2517 The make_lispy_event function stores positions here to tell the
2518 difference between click and drag events, and to store the starting
2519 location to be included in drag events. */
2521 static Lisp_Object button_down_location
;
2523 /* Information about the most recent up-going button event: Which
2524 button, what location, and what time. */
2526 static int last_mouse_button
;
2527 static int last_mouse_x
;
2528 static int last_mouse_y
;
2529 static unsigned long button_down_time
;
2531 /* The maximum time between clicks to make a double-click,
2532 or Qnil to disable double-click detection,
2533 or Qt for no time limit. */
2534 Lisp_Object Vdouble_click_time
;
2536 /* The number of clicks in this multiple-click. */
2538 int double_click_count
;
2540 #ifdef USE_X_TOOLKIT
2541 extern Lisp_Object
map_event_to_object ();
2542 #endif /* USE_X_TOOLKIT */
2544 /* Given a struct input_event, build the lisp event which represents
2545 it. If EVENT is 0, build a mouse movement event from the mouse
2546 movement buffer, which should have a movement event in it.
2548 Note that events must be passed to this function in the order they
2549 are received; this function stores the location of button presses
2550 in order to build drag events when the button is released. */
2553 make_lispy_event (event
)
2554 struct input_event
*event
;
2558 #ifdef SWITCH_ENUM_BUG
2559 switch ((int) event
->kind
)
2561 switch (event
->kind
)
2564 /* A simple keystroke. */
2565 case ascii_keystroke
:
2567 Lisp_Object lispy_c
;
2568 int c
= event
->code
& 0377;
2569 /* Turn ASCII characters into control characters
2571 if (event
->modifiers
& ctrl_modifier
)
2572 c
= make_ctrl_char (c
);
2574 /* Add in the other modifier bits. We took care of ctrl_modifier
2575 just above, and the shift key was taken care of by the X code,
2576 and applied to control characters by make_ctrl_char. */
2577 c
|= (event
->modifiers
2578 & (meta_modifier
| alt_modifier
2579 | hyper_modifier
| super_modifier
));
2580 button_down_time
= 0;
2581 XSETFASTINT (lispy_c
, c
);
2585 /* A function key. The symbol may need to have modifier prefixes
2587 case non_ascii_keystroke
:
2588 button_down_time
= 0;
2590 for (i
= 0; i
< sizeof (lispy_accent_codes
) / sizeof (int); i
++)
2591 if (event
->code
== lispy_accent_codes
[i
])
2592 return modify_event_symbol (i
,
2594 Qfunction_key
, Qnil
,
2595 lispy_accent_keys
, &accent_key_syms
,
2596 (sizeof (lispy_accent_keys
)
2597 / sizeof (lispy_accent_keys
[0])));
2599 /* Handle system-specific keysyms. */
2600 if (event
->code
& (1 << 28))
2602 /* We need to use an alist rather than a vector as the cache
2603 since we can't make a vector long enuf. */
2604 if (NILP (system_key_syms
))
2605 system_key_syms
= Fcons (Qnil
, Qnil
);
2606 return modify_event_symbol (event
->code
& 0xffffff,
2608 Qfunction_key
, Vsystem_key_alist
,
2609 0, &system_key_syms
, 0xffffff);
2612 return modify_event_symbol (event
->code
- 0xff00,
2614 Qfunction_key
, Qnil
,
2615 lispy_function_keys
, &func_key_syms
,
2616 (sizeof (lispy_function_keys
)
2617 / sizeof (lispy_function_keys
[0])));
2620 #if defined (MULTI_FRAME) || defined (HAVE_MOUSE)
2621 /* A mouse click. Figure out where it is, decide whether it's
2622 a press, click or drag, and build the appropriate structure. */
2624 case scroll_bar_click
:
2626 int button
= event
->code
;
2628 Lisp_Object position
;
2629 Lisp_Object
*start_pos_ptr
;
2630 Lisp_Object start_pos
;
2632 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
2635 /* Build the position as appropriate for this mouse click. */
2636 if (event
->kind
== mouse_click
)
2639 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
2644 /* Ignore mouse events that were made on frame that
2645 have been deleted. */
2646 if (! FRAME_LIVE_P (f
))
2649 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
2650 &column
, &row
, 0, 0);
2652 #ifdef USE_X_TOOLKIT
2653 if (FRAME_EXTERNAL_MENU_BAR (f
) && XINT (event
->y
) == -1)
2655 if (row
< FRAME_MENU_BAR_LINES (f
))
2658 Lisp_Object items
, item
;
2662 /* Activate the menu bar on the down event. If the
2663 up event comes in before the menu code can deal with it,
2665 if (! (event
->modifiers
& down_modifier
))
2668 #ifndef USE_X_TOOLKIT
2670 items
= FRAME_MENU_BAR_ITEMS (f
);
2671 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 3)
2673 Lisp_Object pos
, string
;
2674 string
= XVECTOR (items
)->contents
[i
+ 1];
2675 pos
= XVECTOR (items
)->contents
[i
+ 2];
2678 if (column
>= XINT (pos
)
2679 && column
< XINT (pos
) + XSTRING (string
)->size
)
2681 item
= XVECTOR (items
)->contents
[i
];
2685 #endif /* not USE_X_TOOLKIT */
2688 = Fcons (event
->frame_or_window
,
2690 Fcons (Fcons (event
->x
, event
->y
),
2691 Fcons (make_number (event
->timestamp
),
2694 return Fcons (item
, Fcons (position
, Qnil
));
2697 window
= window_from_coordinates (f
, column
, row
, &part
);
2699 if (!WINDOWP (window
))
2701 window
= event
->frame_or_window
;
2706 int pixcolumn
, pixrow
;
2707 column
-= XINT (XWINDOW (window
)->left
);
2708 row
-= XINT (XWINDOW (window
)->top
);
2709 glyph_to_pixel_coords (f
, column
, row
, &pixcolumn
, &pixrow
);
2710 XSETINT (event
->x
, pixcolumn
);
2711 XSETINT (event
->y
, pixrow
);
2716 posn
= Qvertical_line
;
2719 buffer_posn_from_coords (XWINDOW (window
),
2726 Fcons (Fcons (event
->x
, event
->y
),
2727 Fcons (make_number (event
->timestamp
),
2733 Lisp_Object portion_whole
;
2736 window
= event
->frame_or_window
;
2737 portion_whole
= Fcons (event
->x
, event
->y
);
2738 part
= *scroll_bar_parts
[(int) event
->part
];
2742 Fcons (Qvertical_scroll_bar
,
2743 Fcons (portion_whole
,
2744 Fcons (make_number (event
->timestamp
),
2745 Fcons (part
, Qnil
)))));
2748 start_pos_ptr
= &XVECTOR (button_down_location
)->contents
[button
];
2750 start_pos
= *start_pos_ptr
;
2751 *start_pos_ptr
= Qnil
;
2753 is_double
= (button
== last_mouse_button
2754 && XINT (event
->x
) == last_mouse_x
2755 && XINT (event
->y
) == last_mouse_y
2756 && button_down_time
!= 0
2757 && (EQ (Vdouble_click_time
, Qt
)
2758 || (INTEGERP (Vdouble_click_time
)
2759 && ((int)(event
->timestamp
- button_down_time
)
2760 < XINT (Vdouble_click_time
)))));
2761 last_mouse_button
= button
;
2762 last_mouse_x
= XINT (event
->x
);
2763 last_mouse_y
= XINT (event
->y
);
2765 /* If this is a button press, squirrel away the location, so
2766 we can decide later whether it was a click or a drag. */
2767 if (event
->modifiers
& down_modifier
)
2771 double_click_count
++;
2772 event
->modifiers
|= ((double_click_count
> 2)
2777 double_click_count
= 1;
2778 button_down_time
= event
->timestamp
;
2779 *start_pos_ptr
= Fcopy_alist (position
);
2782 /* Now we're releasing a button - check the co-ordinates to
2783 see if this was a click or a drag. */
2784 else if (event
->modifiers
& up_modifier
)
2786 /* If we did not see a down before this up,
2787 ignore the up. Probably this happened because
2788 the down event chose a menu item.
2789 It would be an annoyance to treat the release
2790 of the button that chose the menu item
2791 as a separate event. */
2793 if (!CONSP (start_pos
))
2796 event
->modifiers
&= ~up_modifier
;
2797 #if 0 /* Formerly we treated an up with no down as a click event. */
2798 if (!CONSP (start_pos
))
2799 event
->modifiers
|= click_modifier
;
2803 /* The third element of every position should be the (x,y)
2807 down
= Fnth (make_number (2), start_pos
);
2808 if (EQ (event
->x
, XCONS (down
)->car
)
2809 && EQ (event
->y
, XCONS (down
)->cdr
))
2811 if (is_double
&& double_click_count
> 1)
2812 event
->modifiers
|= ((double_click_count
> 2)
2816 event
->modifiers
|= click_modifier
;
2820 button_down_time
= 0;
2821 event
->modifiers
|= drag_modifier
;
2826 /* Every mouse event should either have the down_modifier or
2827 the up_modifier set. */
2831 /* Get the symbol we should use for the mouse click. */
2834 head
= modify_event_symbol (button
,
2837 lispy_mouse_names
, &mouse_syms
,
2838 (sizeof (lispy_mouse_names
)
2839 / sizeof (lispy_mouse_names
[0])));
2840 if (event
->modifiers
& drag_modifier
)
2845 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
2848 Fcons (make_number (double_click_count
),
2856 #endif /* MULTI_FRAME or HAVE_MOUSE */
2858 /* The 'kind' field of the event is something we don't recognize. */
2864 #if defined (MULTI_FRAME) || defined (HAVE_MOUSE)
2867 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
2869 Lisp_Object bar_window
;
2870 enum scroll_bar_part part
;
2875 /* Is it a scroll bar movement? */
2876 if (frame
&& ! NILP (bar_window
))
2878 Lisp_Object part_sym
;
2880 part_sym
= *scroll_bar_parts
[(int) part
];
2881 return Fcons (Qscroll_bar_movement
,
2882 (Fcons (Fcons (bar_window
,
2883 Fcons (Qvertical_scroll_bar
,
2884 Fcons (Fcons (x
, y
),
2885 Fcons (make_number (time
),
2891 /* Or is it an ordinary mouse movement? */
2893 #endif /* MULTI_FRAME */
2906 /* It's in a frame; which window on that frame? */
2907 pixel_to_glyph_coords (frame
, XINT (x
), XINT (y
), &column
, &row
, 0, 1);
2908 window
= window_from_coordinates (frame
, column
, row
, &area
);
2913 if (WINDOWP (window
))
2915 int pixcolumn
, pixrow
;
2916 column
-= XINT (XWINDOW (window
)->left
);
2917 row
-= XINT (XWINDOW (window
)->top
);
2918 glyph_to_pixel_coords (frame
, column
, row
, &pixcolumn
, &pixrow
);
2919 XSETINT (x
, pixcolumn
);
2920 XSETINT (y
, pixrow
);
2925 posn
= Qvertical_line
;
2928 buffer_posn_from_coords (XWINDOW (window
), column
, row
));
2931 else if (frame
!= 0)
2933 XSETFRAME (window
, frame
);
2945 return Fcons (Qmouse_movement
,
2946 Fcons (Fcons (window
,
2948 Fcons (Fcons (x
, y
),
2949 Fcons (make_number (time
),
2955 #endif /* neither MULTI_FRAME nor HAVE_MOUSE */
2957 /* Construct a switch frame event. */
2959 make_lispy_switch_frame (frame
)
2962 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
2965 /* Manipulating modifiers. */
2967 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
2969 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
2970 SYMBOL's name of the end of the modifiers; the string from this
2971 position is the unmodified symbol name.
2973 This doesn't use any caches. */
2975 parse_modifiers_uncached (symbol
, modifier_end
)
2979 struct Lisp_String
*name
;
2983 CHECK_SYMBOL (symbol
, 1);
2986 name
= XSYMBOL (symbol
)->name
;
2989 for (i
= 0; i
+2 <= name
->size
; )
2990 switch (name
->data
[i
])
2992 #define SINGLE_LETTER_MOD(bit) \
2993 if (name->data[i+1] != '-') \
2994 goto no_more_modifiers; \
2999 SINGLE_LETTER_MOD (alt_modifier
);
3003 SINGLE_LETTER_MOD (ctrl_modifier
);
3007 SINGLE_LETTER_MOD (hyper_modifier
);
3011 SINGLE_LETTER_MOD (meta_modifier
);
3015 SINGLE_LETTER_MOD (shift_modifier
);
3019 SINGLE_LETTER_MOD (super_modifier
);
3023 if (i
+ 5 > name
->size
)
3024 goto no_more_modifiers
;
3025 if (! strncmp (name
->data
+ i
, "drag-", 5))
3027 modifiers
|= drag_modifier
;
3030 else if (! strncmp (name
->data
+ i
, "down-", 5))
3032 modifiers
|= down_modifier
;
3035 else if (i
+ 7 <= name
->size
3036 && ! strncmp (name
->data
+ i
, "double-", 7))
3038 modifiers
|= double_modifier
;
3042 goto no_more_modifiers
;
3046 if (i
+ 7 > name
->size
)
3047 goto no_more_modifiers
;
3048 if (! strncmp (name
->data
+ i
, "triple-", 7))
3050 modifiers
|= triple_modifier
;
3054 goto no_more_modifiers
;
3058 goto no_more_modifiers
;
3060 #undef SINGLE_LETTER_MOD
3064 /* Should we include the `click' modifier? */
3065 if (! (modifiers
& (down_modifier
| drag_modifier
3066 | double_modifier
| triple_modifier
))
3067 && i
+ 7 == name
->size
3068 && strncmp (name
->data
+ i
, "mouse-", 6) == 0
3069 && ('0' <= name
->data
[i
+ 6] && name
->data
[i
+ 6] <= '9'))
3070 modifiers
|= click_modifier
;
3079 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
3080 prepended to the string BASE[0..BASE_LEN-1].
3081 This doesn't use any caches. */
3083 apply_modifiers_uncached (modifiers
, base
, base_len
)
3088 /* Since BASE could contain nulls, we can't use intern here; we have
3089 to use Fintern, which expects a genuine Lisp_String, and keeps a
3092 (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
3098 /* Only the event queue may use the `up' modifier; it should always
3099 be turned into a click or drag event before presented to lisp code. */
3100 if (modifiers
& up_modifier
)
3103 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
3104 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
3105 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
3106 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
3107 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
3108 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
3109 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
3110 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
3111 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
3112 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
3113 /* The click modifier is denoted by the absence of other modifiers. */
3117 mod_len
= p
- new_mods
;
3121 Lisp_Object new_name
;
3123 new_name
= make_uninit_string (mod_len
+ base_len
);
3124 bcopy (new_mods
, XSTRING (new_name
)->data
, mod_len
);
3125 bcopy (base
, XSTRING (new_name
)->data
+ mod_len
, base_len
);
3127 return Fintern (new_name
, Qnil
);
3132 static char *modifier_names
[] =
3134 "up", "down", "drag", "click", "double", "triple", 0, 0,
3135 0, 0, 0, 0, 0, 0, 0, 0,
3136 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
3138 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
3140 static Lisp_Object modifier_symbols
;
3142 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
3144 lispy_modifier_list (modifiers
)
3147 Lisp_Object modifier_list
;
3150 modifier_list
= Qnil
;
3151 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
3152 if (modifiers
& (1<<i
))
3153 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
3156 return modifier_list
;
3160 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
3161 where UNMODIFIED is the unmodified form of SYMBOL,
3162 MASK is the set of modifiers present in SYMBOL's name.
3163 This is similar to parse_modifiers_uncached, but uses the cache in
3164 SYMBOL's Qevent_symbol_element_mask property, and maintains the
3165 Qevent_symbol_elements property. */
3167 parse_modifiers (symbol
)
3170 Lisp_Object elements
;
3172 elements
= Fget (symbol
, Qevent_symbol_element_mask
);
3173 if (CONSP (elements
))
3178 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
3179 Lisp_Object unmodified
;
3182 unmodified
= Fintern (make_string (XSYMBOL (symbol
)->name
->data
+ end
,
3183 XSYMBOL (symbol
)->name
->size
- end
),
3186 if (modifiers
& ~((1<<VALBITS
) - 1))
3188 XSETFASTINT (mask
, modifiers
);
3189 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
3191 /* Cache the parsing results on SYMBOL. */
3192 Fput (symbol
, Qevent_symbol_element_mask
,
3194 Fput (symbol
, Qevent_symbol_elements
,
3195 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
3197 /* Since we know that SYMBOL is modifiers applied to unmodified,
3198 it would be nice to put that in unmodified's cache.
3199 But we can't, since we're not sure that parse_modifiers is
3206 /* Apply the modifiers MODIFIERS to the symbol BASE.
3207 BASE must be unmodified.
3209 This is like apply_modifiers_uncached, but uses BASE's
3210 Qmodifier_cache property, if present. It also builds
3211 Qevent_symbol_elements properties, since it has that info anyway.
3213 apply_modifiers copies the value of BASE's Qevent_kind property to
3214 the modified symbol. */
3216 apply_modifiers (modifiers
, base
)
3220 Lisp_Object cache
, index
, entry
, new_symbol
;
3222 /* Mask out upper bits. We don't know where this value's been. */
3223 modifiers
&= (1<<VALBITS
) - 1;
3225 /* The click modifier never figures into cache indices. */
3226 cache
= Fget (base
, Qmodifier_cache
);
3227 XSETFASTINT (index
, (modifiers
& ~click_modifier
));
3228 entry
= assq_no_quit (index
, cache
);
3231 new_symbol
= XCONS (entry
)->cdr
;
3234 /* We have to create the symbol ourselves. */
3235 new_symbol
= apply_modifiers_uncached (modifiers
,
3236 XSYMBOL (base
)->name
->data
,
3237 XSYMBOL (base
)->name
->size
);
3239 /* Add the new symbol to the base's cache. */
3240 entry
= Fcons (index
, new_symbol
);
3241 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
3243 /* We have the parsing info now for free, so add it to the caches. */
3244 XSETFASTINT (index
, modifiers
);
3245 Fput (new_symbol
, Qevent_symbol_element_mask
,
3246 Fcons (base
, Fcons (index
, Qnil
)));
3247 Fput (new_symbol
, Qevent_symbol_elements
,
3248 Fcons (base
, lispy_modifier_list (modifiers
)));
3251 /* Make sure this symbol is of the same kind as BASE.
3253 You'd think we could just set this once and for all when we
3254 intern the symbol above, but reorder_modifiers may call us when
3255 BASE's property isn't set right; we can't assume that just
3256 because it has a Qmodifier_cache property it must have its
3257 Qevent_kind set right as well. */
3258 if (NILP (Fget (new_symbol
, Qevent_kind
)))
3262 kind
= Fget (base
, Qevent_kind
);
3264 Fput (new_symbol
, Qevent_kind
, kind
);
3271 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
3272 return a symbol with the modifiers placed in the canonical order.
3273 Canonical order is alphabetical, except for down and drag, which
3274 always come last. The 'click' modifier is never written out.
3276 Fdefine_key calls this to make sure that (for example) C-M-foo
3277 and M-C-foo end up being equivalent in the keymap. */
3280 reorder_modifiers (symbol
)
3283 /* It's hopefully okay to write the code this way, since everything
3284 will soon be in caches, and no consing will be done at all. */
3287 parsed
= parse_modifiers (symbol
);
3288 return apply_modifiers (XCONS (XCONS (parsed
)->cdr
)->car
,
3289 XCONS (parsed
)->car
);
3293 /* For handling events, we often want to produce a symbol whose name
3294 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
3295 to some base, like the name of a function key or mouse button.
3296 modify_event_symbol produces symbols of this sort.
3298 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
3299 is the name of the i'th symbol. TABLE_SIZE is the number of elements
3302 Alternatively, NAME_ALIST is an alist mapping codes into symbol names.
3303 NAME_ALIST is used if it is non-nil; otherwise NAME_TABLE is used.
3305 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
3306 persist between calls to modify_event_symbol that it can use to
3307 store a cache of the symbols it's generated for this NAME_TABLE
3308 before. The object stored there may be a vector or an alist.
3310 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
3312 MODIFIERS is a set of modifier bits (as given in struct input_events)
3313 whose prefixes should be applied to the symbol name.
3315 SYMBOL_KIND is the value to be placed in the event_kind property of
3316 the returned symbol.
3318 The symbols we create are supposed to have an
3319 `event-symbol-elements' property, which lists the modifiers present
3320 in the symbol's name. */
3323 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_alist
,
3324 name_table
, symbol_table
, table_size
)
3327 Lisp_Object symbol_kind
;
3328 Lisp_Object name_alist
;
3330 Lisp_Object
*symbol_table
;
3334 Lisp_Object symbol_int
;
3336 XSETINT (symbol_int
, symbol_num
);
3338 /* Is this a request for a valid symbol? */
3339 if (symbol_num
< 0 || symbol_num
>= table_size
)
3342 if (CONSP (*symbol_table
))
3343 value
= Fcdr (assq_no_quit (symbol_int
, *symbol_table
));
3345 /* If *symbol_table doesn't seem to be initialized properly, fix that.
3346 *symbol_table should be a lisp vector TABLE_SIZE elements long,
3347 where the Nth element is the symbol for NAME_TABLE[N], or nil if
3348 we've never used that symbol before. */
3351 if (! VECTORP (*symbol_table
)
3352 || XVECTOR (*symbol_table
)->size
!= table_size
)
3356 XSETFASTINT (size
, table_size
);
3357 *symbol_table
= Fmake_vector (size
, Qnil
);
3360 value
= XVECTOR (*symbol_table
)->contents
[symbol_num
];
3363 /* Have we already used this symbol before? */
3366 /* No; let's create it. */
3367 if (!NILP (name_alist
))
3368 value
= Fcdr_safe (Fassq (symbol_int
, name_alist
));
3369 else if (name_table
[symbol_num
])
3370 value
= intern (name_table
[symbol_num
]);
3375 sprintf (buf
, "key-%d", symbol_num
);
3376 value
= intern (buf
);
3379 if (CONSP (*symbol_table
))
3380 *symbol_table
= Fcons (value
, *symbol_table
);
3382 XVECTOR (*symbol_table
)->contents
[symbol_num
] = value
;
3384 /* Fill in the cache entries for this symbol; this also
3385 builds the Qevent_symbol_elements property, which the user
3387 apply_modifiers (modifiers
& click_modifier
, value
);
3388 Fput (value
, Qevent_kind
, symbol_kind
);
3391 /* Apply modifiers to that symbol. */
3392 return apply_modifiers (modifiers
, value
);
3396 /* Store into *addr a value nonzero if terminal input chars are available.
3397 Serves the purpose of ioctl (0, FIONREAD, addr)
3398 but works even if FIONREAD does not exist.
3399 (In fact, this may actually read some input.) */
3402 get_input_pending (addr
)
3405 /* First of all, have we already counted some input? */
3406 *addr
= !NILP (Vquit_flag
) || readable_events ();
3408 /* If input is being read as it arrives, and we have none, there is none. */
3409 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
3412 /* Try to read some input and see how much we get. */
3414 *addr
= !NILP (Vquit_flag
) || readable_events ();
3417 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
3420 gobble_input (expected
)
3425 if (interrupt_input
)
3428 mask
= sigblockx (SIGIO
);
3429 read_avail_input (expected
);
3433 #ifdef POLL_FOR_INPUT
3434 if (read_socket_hook
&& !interrupt_input
&& poll_suppress_count
== 0)
3437 mask
= sigblockx (SIGALRM
);
3438 read_avail_input (expected
);
3444 read_avail_input (expected
);
3448 /* Put a buffer_switch_event in the buffer
3449 so that read_key_sequence will notice the new current buffer. */
3451 record_asynch_buffer_change ()
3453 struct input_event event
;
3456 event
.kind
= buffer_switch_event
;
3457 event
.frame_or_window
= Qnil
;
3460 /* We don't need a buffer-switch event unless Emacs is waiting for input.
3461 The purpose of the event is to make read_key_sequence look up the
3462 keymaps again. If we aren't in read_key_sequence, we don't need one,
3463 and the event could cause trouble by messing up (input-pending-p). */
3464 tem
= Fwaiting_for_user_input_p ();
3468 /* We never need these events if we have no asynchronous subprocesses. */
3472 /* Make sure no interrupt happens while storing the event. */
3474 if (interrupt_input
)
3477 mask
= sigblockx (SIGIO
);
3478 kbd_buffer_store_event (&event
);
3485 kbd_buffer_store_event (&event
);
3492 /* Read any terminal input already buffered up by the system
3493 into the kbd_buffer, but do not wait.
3495 EXPECTED should be nonzero if the caller knows there is some input.
3497 Except on VMS, all input is read by this function.
3498 If interrupt_input is nonzero, this function MUST be called
3499 only when SIGIO is blocked.
3501 Returns the number of keyboard chars read, or -1 meaning
3502 this is a bad time to try to read input. */
3505 read_avail_input (expected
)
3508 struct input_event buf
[KBD_BUFFER_SIZE
];
3512 if (read_socket_hook
)
3513 /* No need for FIONREAD or fcntl; just say don't wait. */
3514 nread
= (*read_socket_hook
) (0, buf
, KBD_BUFFER_SIZE
, expected
, expected
);
3517 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
3518 the kbd_buffer can really hold. That may prevent loss
3519 of characters on some systems when input is stuffed at us. */
3520 unsigned char cbuf
[KBD_BUFFER_SIZE
- 1];
3523 /* Determine how many characters we should *try* to read. */
3525 n_to_read
= dos_keysns ();
3528 #else /* not MSDOS */
3530 /* Find out how much input is available. */
3531 if (ioctl (0, FIONREAD
, &n_to_read
) < 0)
3532 /* Formerly simply reported no input, but that sometimes led to
3533 a failure of Emacs to terminate.
3534 SIGHUP seems appropriate if we can't reach the terminal. */
3535 /* ??? Is it really right to send the signal just to this process
3536 rather than to the whole process group?
3537 Perhaps on systems with FIONREAD Emacs is alone in its group. */
3538 kill (getpid (), SIGHUP
);
3541 if (n_to_read
> sizeof cbuf
)
3542 n_to_read
= sizeof cbuf
;
3543 #else /* no FIONREAD */
3544 #if defined(USG) || defined(DGUX)
3545 /* Read some input if available, but don't wait. */
3546 n_to_read
= sizeof cbuf
;
3547 fcntl (fileno (stdin
), F_SETFL
, O_NDELAY
);
3552 #endif /* not MSDOS */
3554 /* Now read; for one reason or another, this will not block.
3555 NREAD is set to the number of chars read. */
3559 cbuf
[0] = dos_keyread();
3562 nread
= read (fileno (stdin
), cbuf
, n_to_read
);
3564 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
3565 /* The kernel sometimes fails to deliver SIGHUP for ptys.
3566 This looks incorrect, but it isn't, because _BSD causes
3567 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
3568 and that causes a value other than 0 when there is no input. */
3574 /* We used to retry the read if it was interrupted.
3575 But this does the wrong thing when O_NDELAY causes
3576 an EAGAIN error. Does anybody know of a situation
3577 where a retry is actually needed? */
3579 nread
< 0 && (errno
== EAGAIN
3593 #if defined (USG) || defined (DGUX)
3594 fcntl (fileno (stdin
), F_SETFL
, 0);
3595 #endif /* USG or DGUX */
3596 #endif /* no FIONREAD */
3597 for (i
= 0; i
< nread
; i
++)
3599 buf
[i
].kind
= ascii_keystroke
;
3600 buf
[i
].modifiers
= 0;
3601 if (meta_key
== 1 && (cbuf
[i
] & 0x80))
3602 buf
[i
].modifiers
= meta_modifier
;
3606 XSETINT (buf
[i
].code
, cbuf
[i
]);
3608 XSETFRAME (buf
[i
].frame_or_window
, selected_frame
);
3610 buf
[i
].frame_or_window
= Qnil
;
3615 /* Scan the chars for C-g and store them in kbd_buffer. */
3616 for (i
= 0; i
< nread
; i
++)
3618 kbd_buffer_store_event (&buf
[i
]);
3619 /* Don't look at input that follows a C-g too closely.
3620 This reduces lossage due to autorepeat on C-g. */
3621 if (buf
[i
].kind
== ascii_keystroke
3622 && buf
[i
].code
== quit_char
)
3628 #endif /* not VMS */
3630 #ifdef SIGIO /* for entire page */
3631 /* Note SIGIO has been undef'd if FIONREAD is missing. */
3634 input_available_signal (signo
)
3637 /* Must preserve main program's value of errno. */
3638 int old_errno
= errno
;
3640 extern int select_alarmed
;
3644 /* USG systems forget handlers when they are used;
3645 must reestablish each time */
3646 signal (signo
, input_available_signal
);
3653 if (input_available_clear_time
)
3654 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
3659 nread
= read_avail_input (1);
3660 /* -1 means it's not ok to read the input now.
3661 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
3662 0 means there was no keyboard input available. */
3667 select_alarmed
= 1; /* Force the select emulator back to life */
3678 /* Send ourselves a SIGIO.
3680 This function exists so that the UNBLOCK_INPUT macro in
3681 blockinput.h can have some way to take care of input we put off
3682 dealing with, without assuming that every file which uses
3683 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
3685 reinvoke_input_signal ()
3694 /* Return the prompt-string of a sparse keymap.
3695 This is the first element which is a string.
3696 Return nil if there is none. */
3704 register Lisp_Object tem
;
3713 static void menu_bar_item ();
3714 static void menu_bar_one_keymap ();
3716 /* These variables hold the vector under construction within
3717 menu_bar_items and its subroutines, and the current index
3718 for storing into that vector. */
3719 static Lisp_Object menu_bar_items_vector
;
3720 static int menu_bar_items_index
;
3722 /* Return a vector of menu items for a menu bar, appropriate
3723 to the current buffer. Each item has three elements in the vector:
3726 OLD is an old vector we can optionally reuse, or nil. */
3729 menu_bar_items (old
)
3732 /* The number of keymaps we're scanning right now, and the number of
3733 keymaps we have allocated space for. */
3736 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
3737 in the current keymaps, or nil where it is not a prefix. */
3740 Lisp_Object def
, tem
, tail
;
3749 struct gcpro gcpro1
;
3751 /* In order to build the menus, we need to call the keymap
3752 accessors. They all call QUIT. But this function is called
3753 during redisplay, during which a quit is fatal. So inhibit
3754 quitting while building the menus.
3755 We do this instead of specbind because (1) errors will clear it anyway
3756 and (2) this avoids risk of specpdl overflow. */
3757 oquit
= Vinhibit_quit
;
3761 menu_bar_items_vector
= old
;
3763 menu_bar_items_vector
= Fmake_vector (make_number (24), Qnil
);
3764 menu_bar_items_index
= 0;
3766 GCPRO1 (menu_bar_items_vector
);
3768 /* Build our list of keymaps.
3769 If we recognize a function key and replace its escape sequence in
3770 keybuf with its symbol, or if the sequence starts with a mouse
3771 click and we need to switch buffers, we jump back here to rebuild
3772 the initial keymaps from the current buffer. */
3776 if (!NILP (Voverriding_local_map
))
3779 maps
= (Lisp_Object
*) alloca (nmaps
* sizeof (maps
[0]));
3780 maps
[0] = Voverriding_local_map
;
3784 nmaps
= current_minor_maps (0, &tmaps
) + 2;
3785 maps
= (Lisp_Object
*) alloca (nmaps
* sizeof (maps
[0]));
3786 bcopy (tmaps
, maps
, (nmaps
- 2) * sizeof (maps
[0]));
3787 #ifdef USE_TEXT_PROPERTIES
3788 maps
[nmaps
-2] = get_local_map (PT
, current_buffer
);
3790 maps
[nmaps
-2] = current_buffer
->keymap
;
3793 maps
[nmaps
-1] = current_global_map
;
3796 /* Look up in each map the dummy prefix key `menu-bar'. */
3800 for (mapno
= nmaps
- 1; mapno
>= 0; mapno
--)
3802 if (! NILP (maps
[mapno
]))
3803 def
= get_keyelt (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0));
3807 tem
= Fkeymapp (def
);
3809 menu_bar_one_keymap (def
);
3812 /* Move to the end those items that should be at the end. */
3814 for (tail
= Vmenu_bar_final_items
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
3817 int end
= menu_bar_items_index
;
3819 for (i
= 0; i
< end
; i
+= 3)
3820 if (EQ (XCONS (tail
)->car
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
3822 Lisp_Object tem0
, tem1
, tem2
;
3823 /* Move the item at index I to the end,
3824 shifting all the others forward. */
3825 tem0
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 0];
3826 tem1
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 1];
3827 tem2
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
3829 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3],
3830 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
3831 (end
- i
- 3) * sizeof (Lisp_Object
));
3832 XVECTOR (menu_bar_items_vector
)->contents
[end
- 3] = tem0
;
3833 XVECTOR (menu_bar_items_vector
)->contents
[end
- 2] = tem1
;
3834 XVECTOR (menu_bar_items_vector
)->contents
[end
- 1] = tem2
;
3839 /* Add nil, nil, nil at the end. */
3840 i
= menu_bar_items_index
;
3841 if (i
+ 3 > XVECTOR (menu_bar_items_vector
)->size
)
3844 int newsize
= 2 * i
;
3845 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
3846 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
3847 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
3848 menu_bar_items_vector
= tem
;
3850 /* Add this item. */
3851 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
3852 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
3853 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
3854 menu_bar_items_index
= i
;
3856 Vinhibit_quit
= oquit
;
3858 return menu_bar_items_vector
;
3861 /* Scan one map KEYMAP, accumulating any menu items it defines
3862 in menu_bar_items_vector. */
3865 menu_bar_one_keymap (keymap
)
3868 Lisp_Object tail
, item
, key
, binding
, item_string
, table
;
3870 /* Loop over all keymap entries that have menu strings. */
3871 for (tail
= keymap
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
3873 item
= XCONS (tail
)->car
;
3876 key
= XCONS (item
)->car
;
3877 binding
= XCONS (item
)->cdr
;
3878 if (CONSP (binding
))
3880 item_string
= XCONS (binding
)->car
;
3881 if (STRINGP (item_string
))
3882 menu_bar_item (key
, item_string
, Fcdr (binding
));
3884 else if (EQ (binding
, Qundefined
))
3885 menu_bar_item (key
, Qnil
, binding
);
3887 else if (VECTORP (item
))
3889 /* Loop over the char values represented in the vector. */
3890 int len
= XVECTOR (item
)->size
;
3892 for (c
= 0; c
< len
; c
++)
3894 Lisp_Object character
;
3895 XSETFASTINT (character
, c
);
3896 binding
= XVECTOR (item
)->contents
[c
];
3897 if (CONSP (binding
))
3899 item_string
= XCONS (binding
)->car
;
3900 if (STRINGP (item_string
))
3901 menu_bar_item (key
, item_string
, Fcdr (binding
));
3903 else if (EQ (binding
, Qundefined
))
3904 menu_bar_item (key
, Qnil
, binding
);
3910 /* This is used as the handler when calling internal_condition_case_1. */
3913 menu_bar_item_1 (arg
)
3919 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
3920 If there's already an item for KEY, add this DEF to it. */
3923 menu_bar_item (key
, item_string
, def
)
3924 Lisp_Object key
, item_string
, def
;
3927 Lisp_Object enabled
;
3930 if (EQ (def
, Qundefined
))
3932 /* If a map has an explicit `undefined' as definition,
3933 discard any previously made menu bar item. */
3935 for (i
= 0; i
< menu_bar_items_index
; i
+= 3)
3936 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
3938 if (menu_bar_items_index
> i
+ 3)
3939 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3],
3940 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
3941 (menu_bar_items_index
- i
- 3) * sizeof (Lisp_Object
));
3942 menu_bar_items_index
-= 3;
3946 /* If there's no definition for this key yet,
3947 just ignore `undefined'. */
3951 /* See if this entry is enabled. */
3956 /* No property, or nil, means enable.
3957 Otherwise, enable if value is not nil. */
3958 tem
= Fget (def
, Qmenu_enable
);
3960 /* (condition-case nil (eval tem)
3962 enabled
= internal_condition_case_1 (Feval
, tem
, Qerror
,
3966 /* Ignore this item if it's not enabled. */
3970 /* Find any existing item for this KEY. */
3971 for (i
= 0; i
< menu_bar_items_index
; i
+= 3)
3972 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
3975 /* If we did not find this KEY, add it at the end. */
3976 if (i
== menu_bar_items_index
)
3978 /* If vector is too small, get a bigger one. */
3979 if (i
+ 3 > XVECTOR (menu_bar_items_vector
)->size
)
3982 int newsize
= 2 * i
;
3983 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
3984 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
3985 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
3986 menu_bar_items_vector
= tem
;
3988 /* Add this item. */
3989 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = key
;
3990 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = item_string
;
3991 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Fcons (def
, Qnil
);
3992 menu_bar_items_index
= i
;
3994 /* We did find an item for this KEY. Add DEF to its list of maps. */
3998 old
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
3999 XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2] = Fcons (def
, old
);
4003 /* Read a character using menus based on maps in the array MAPS.
4004 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
4005 Return t if we displayed a menu but the user rejected it.
4007 PREV_EVENT is the previous input event, or nil if we are reading
4008 the first event of a key sequence.
4010 If USED_MOUSE_MENU is non-zero, then we set *USED_MOUSE_MENU to 1
4011 if we used a mouse menu to read the input, or zero otherwise. If
4012 USED_MOUSE_MENU is zero, *USED_MOUSE_MENU is left alone.
4014 The prompting is done based on the prompt-string of the map
4015 and the strings associated with various map elements.
4017 This can be done with X menus or with menus put in the minibuf.
4018 These are done in different ways, depending on how the input will be read.
4019 Menus using X are done after auto-saving in read-char, getting the input
4020 event from Fx_popup_menu; menus using the minibuf use read_char recursively
4021 and do auto-saving in the inner call of read_char. */
4024 read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
4027 Lisp_Object prev_event
;
4028 int *used_mouse_menu
;
4031 register Lisp_Object name
;
4032 Lisp_Object rest
, vector
;
4034 if (used_mouse_menu
)
4035 *used_mouse_menu
= 0;
4037 /* Use local over global Menu maps */
4039 if (! menu_prompting
)
4042 /* Optionally disregard all but the global map. */
4043 if (inhibit_local_menu_bar_menus
)
4045 maps
+= (nmaps
- 1);
4049 /* Get the menu name from the first map that has one (a prompt string). */
4050 for (mapno
= 0; mapno
< nmaps
; mapno
++)
4052 name
= map_prompt (maps
[mapno
]);
4057 /* If we don't have any menus, just read a character normally. */
4061 #if (defined (HAVE_X_WINDOWS) && defined (HAVE_X_MENU)) || defined (MSDOS)
4062 /* If we got to this point via a mouse click,
4063 use a real menu for mouse selection. */
4064 if (EVENT_HAS_PARAMETERS (prev_event
))
4066 /* Display the menu and get the selection. */
4067 Lisp_Object
*realmaps
4068 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
4072 /* Use the maps that are not nil. */
4073 for (mapno
= 0; mapno
< nmaps
; mapno
++)
4074 if (!NILP (maps
[mapno
]))
4075 realmaps
[nmaps1
++] = maps
[mapno
];
4077 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
4080 /* If we got more than one event, put all but the first
4081 onto this list to be read later.
4082 Return just the first event now. */
4083 Vunread_command_events
4084 = nconc2 (XCONS (value
)->cdr
, Vunread_command_events
);
4085 value
= XCONS (value
)->car
;
4087 else if (NILP (value
))
4089 if (used_mouse_menu
)
4090 *used_mouse_menu
= 1;
4093 #endif /* (HAVE_X_WINDOWS && HAVE_X_MENU) || MSDOS */
4098 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
4104 register Lisp_Object name
;
4106 int width
= FRAME_WIDTH (selected_frame
) - 4;
4107 char *menu
= (char *) alloca (width
+ 4);
4110 Lisp_Object rest
, vector
;
4112 if (! menu_prompting
)
4115 /* Get the menu name from the first map that has one (a prompt string). */
4116 for (mapno
= 0; mapno
< nmaps
; mapno
++)
4118 name
= map_prompt (maps
[mapno
]);
4123 /* If we don't have any menus, just read a character normally. */
4127 /* Prompt string always starts with map's prompt, and a space. */
4128 strcpy (menu
, XSTRING (name
)->data
);
4129 nlength
= XSTRING (name
)->size
;
4130 menu
[nlength
++] = ':';
4131 menu
[nlength
++] = ' ';
4134 /* Start prompting at start of first map. */
4138 /* Present the documented bindings, a line at a time. */
4145 int orig_defn_macro
;
4147 /* Loop over elements of map. */
4152 /* If reached end of map, start at beginning of next map. */
4156 /* At end of last map, wrap around to first map if just starting,
4157 or end this line if already have something on it. */
4161 if (notfirst
|| nobindings
) break;
4166 /* Look at the next element of the map. */
4168 elt
= XVECTOR (vector
)->contents
[idx
];
4170 elt
= Fcar_safe (rest
);
4172 if (idx
< 0 && VECTORP (elt
))
4174 /* If we found a dense table in the keymap,
4175 advanced past it, but start scanning its contents. */
4176 rest
= Fcdr_safe (rest
);
4182 /* An ordinary element. */
4184 s
= Fcar_safe (Fcdr_safe (elt
)); /* alist */
4186 s
= Fcar_safe(elt
); /* vector */
4188 /* Ignore the element if it has no prompt string. */
4190 /* If we have room for the prompt string, add it to this line.
4191 If this is the first on the line, always add it. */
4192 else if (XSTRING (s
)->size
+ i
+ 2 < width
4197 /* Punctuate between strings. */
4200 strcpy (menu
+ i
, ", ");
4206 /* Add as much of string as fits. */
4207 thiswidth
= XSTRING (s
)->size
;
4208 if (thiswidth
+ i
> width
)
4209 thiswidth
= width
- i
;
4210 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
4216 /* If this element does not fit, end the line now,
4217 and save the element for the next line. */
4218 strcpy (menu
+ i
, "...");
4222 /* Move past this element. */
4223 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
4224 /* Handle reaching end of dense table. */
4229 rest
= Fcdr_safe (rest
);
4233 /* Prompt with that and read response. */
4236 /* Make believe its not a keyboard macro in case the help char
4237 is pressed. Help characters are not recorded because menu prompting
4238 is not used on replay.
4240 orig_defn_macro
= defining_kbd_macro
;
4241 defining_kbd_macro
= 0 ;
4243 obj
= read_char (commandflag
, 0, 0, Qnil
, 0);
4244 while (BUFFERP (obj
));
4245 defining_kbd_macro
= orig_defn_macro
;
4247 if (!INTEGERP (obj
))
4252 if (! EQ (obj
, menu_prompt_more_char
)
4253 && (!INTEGERP (menu_prompt_more_char
)
4254 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
4256 if ( defining_kbd_macro
)
4257 store_kbd_macro_char(obj
) ;
4260 /* Help char - go round again */
4264 /* Reading key sequences. */
4266 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
4267 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
4268 keymap, or nil otherwise. Return the index of the first keymap in
4269 which KEY has any binding, or NMAPS if no map has a binding.
4271 If KEY is a meta ASCII character, treat it like meta-prefix-char
4272 followed by the corresponding non-meta character. Keymaps in
4273 CURRENT with non-prefix bindings for meta-prefix-char become nil in
4276 If KEY has no bindings in any of the CURRENT maps, NEXT is left
4279 NEXT may == CURRENT. */
4282 follow_key (key
, nmaps
, current
, defs
, next
)
4284 Lisp_Object
*current
, *defs
, *next
;
4287 int i
, first_binding
;
4289 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
4290 followed by the corresponding non-meta character. */
4291 if (INTEGERP (key
) && (XINT (key
) & CHAR_META
))
4293 for (i
= 0; i
< nmaps
; i
++)
4294 if (! NILP (current
[i
]))
4297 get_keyelt (access_keymap (current
[i
], meta_prefix_char
, 1, 0));
4299 /* Note that since we pass the resulting bindings through
4300 get_keymap_1, non-prefix bindings for meta-prefix-char
4302 next
[i
] = get_keymap_1 (next
[i
], 0, 1);
4308 XSETINT (key
, XFASTINT (key
) & ~CHAR_META
);
4311 first_binding
= nmaps
;
4312 for (i
= nmaps
- 1; i
>= 0; i
--)
4314 if (! NILP (current
[i
]))
4316 defs
[i
] = get_keyelt (access_keymap (current
[i
], key
, 1, 0));
4317 if (! NILP (defs
[i
]))
4324 /* Given the set of bindings we've found, produce the next set of maps. */
4325 if (first_binding
< nmaps
)
4326 for (i
= 0; i
< nmaps
; i
++)
4327 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0, 1);
4329 return first_binding
;
4332 /* Read a sequence of keys that ends with a non prefix character,
4333 storing it in KEYBUF, a buffer of size BUFSIZE.
4335 Return the length of the key sequence stored.
4336 Return -1 if the user rejected a command menu.
4338 Echo starting immediately unless `prompt' is 0.
4340 Where a key sequence ends depends on the currently active keymaps.
4341 These include any minor mode keymaps active in the current buffer,
4342 the current buffer's local map, and the global map.
4344 If a key sequence has no other bindings, we check Vfunction_key_map
4345 to see if some trailing subsequence might be the beginning of a
4346 function key's sequence. If so, we try to read the whole function
4347 key, and substitute its symbolic name into the key sequence.
4349 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
4350 `double-' events into similar click events, if that would make them
4351 bound. We try to turn `triple-' events first into `double-' events,
4354 If we get a mouse click in a mode line, vertical divider, or other
4355 non-text area, we treat the click as if it were prefixed by the
4356 symbol denoting that area - `mode-line', `vertical-line', or
4359 If the sequence starts with a mouse click, we read the key sequence
4360 with respect to the buffer clicked on, not the current buffer.
4362 If the user switches frames in the midst of a key sequence, we put
4363 off the switch-frame event until later; the next call to
4364 read_char will return it. */
4367 read_key_sequence (keybuf
, bufsize
, prompt
)
4368 Lisp_Object
*keybuf
;
4372 int count
= specpdl_ptr
- specpdl
;
4374 /* How many keys there are in the current key sequence. */
4377 /* The length of the echo buffer when we started reading, and
4378 the length of this_command_keys when we started reading. */
4382 /* The number of keymaps we're scanning right now, and the number of
4383 keymaps we have allocated space for. */
4385 int nmaps_allocated
= 0;
4387 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
4388 the current keymaps. */
4391 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
4392 in the current keymaps, or nil where it is not a prefix. */
4393 Lisp_Object
*submaps
;
4395 /* The index in defs[] of the first keymap that has a binding for
4396 this key sequence. In other words, the lowest i such that
4397 defs[i] is non-nil. */
4400 /* If t < mock_input, then KEYBUF[t] should be read as the next
4403 We use this to recover after recognizing a function key. Once we
4404 realize that a suffix of the current key sequence is actually a
4405 function key's escape sequence, we replace the suffix with the
4406 function key's binding from Vfunction_key_map. Now keybuf
4407 contains a new and different key sequence, so the echo area,
4408 this_command_keys, and the submaps and defs arrays are wrong. In
4409 this situation, we set mock_input to t, set t to 0, and jump to
4410 restart_sequence; the loop will read keys from keybuf up until
4411 mock_input, thus rebuilding the state; and then it will resume
4412 reading characters from the keyboard. */
4415 /* If the sequence is unbound in submaps[], then
4416 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
4417 and fkey_map is its binding.
4419 These might be > t, indicating that all function key scanning
4420 should hold off until t reaches them. We do this when we've just
4421 recognized a function key, to avoid searching for the function
4422 key's again in Vfunction_key_map. */
4423 int fkey_start
= 0, fkey_end
= 0;
4424 Lisp_Object fkey_map
;
4426 /* Likewise, for key_translation_map. */
4427 int keytran_start
= 0, keytran_end
= 0;
4428 Lisp_Object keytran_map
;
4430 /* If we receive a ``switch-frame'' event in the middle of a key sequence,
4431 we put it off for later. While we're reading, we keep the event here. */
4432 Lisp_Object delayed_switch_frame
;
4434 /* See the comment below... */
4435 #if defined (GOBBLE_FIRST_EVENT)
4436 Lisp_Object first_event
;
4439 struct buffer
*starting_buffer
;
4441 /* Nonzero if we seem to have got the beginning of a binding
4442 in function_key_map. */
4443 int function_key_possible
= 0;
4444 int key_translation_possible
= 0;
4448 last_nonmenu_event
= Qnil
;
4450 delayed_switch_frame
= Qnil
;
4451 fkey_map
= Vfunction_key_map
;
4452 keytran_map
= Vkey_translation_map
;
4454 /* If there is no function-key-map, turn off function key scanning. */
4455 if (NILP (Fkeymapp (Vfunction_key_map
)))
4456 fkey_start
= fkey_end
= bufsize
+ 1;
4458 /* If there is no key-translation-map, turn off scanning. */
4459 if (NILP (Fkeymapp (Vkey_translation_map
)))
4460 keytran_start
= keytran_end
= bufsize
+ 1;
4465 echo_prompt (XSTRING (prompt
)->data
);
4466 else if (cursor_in_echo_area
&& echo_keystrokes
)
4467 /* This doesn't put in a dash if the echo buffer is empty, so
4468 you don't always see a dash hanging out in the minibuffer. */
4472 /* Record the initial state of the echo area and this_command_keys;
4473 we will need to restore them if we replay a key sequence. */
4475 echo_start
= echo_length ();
4476 keys_start
= this_command_key_count
;
4478 #if defined (GOBBLE_FIRST_EVENT)
4479 /* This doesn't quite work, because some of the things that read_char
4480 does cannot safely be bypassed. It seems too risky to try to make
4483 /* Read the first char of the sequence specially, before setting
4484 up any keymaps, in case a filter runs and switches buffers on us. */
4485 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
4487 #endif /* GOBBLE_FIRST_EVENT */
4489 /* We jump here when the key sequence has been thoroughly changed, and
4490 we need to rescan it starting from the beginning. When we jump here,
4491 keybuf[0..mock_input] holds the sequence we should reread. */
4494 starting_buffer
= current_buffer
;
4495 function_key_possible
= 0;
4496 key_translation_possible
= 0;
4498 /* Build our list of keymaps.
4499 If we recognize a function key and replace its escape sequence in
4500 keybuf with its symbol, or if the sequence starts with a mouse
4501 click and we need to switch buffers, we jump back here to rebuild
4502 the initial keymaps from the current buffer. */
4506 if (!NILP (Voverriding_local_map
))
4509 if (nmaps
> nmaps_allocated
)
4511 submaps
= (Lisp_Object
*) alloca (nmaps
* sizeof (submaps
[0]));
4512 defs
= (Lisp_Object
*) alloca (nmaps
* sizeof (defs
[0]));
4513 nmaps_allocated
= nmaps
;
4515 submaps
[0] = Voverriding_local_map
;
4519 nmaps
= current_minor_maps (0, &maps
) + 2;
4520 if (nmaps
> nmaps_allocated
)
4522 submaps
= (Lisp_Object
*) alloca (nmaps
* sizeof (submaps
[0]));
4523 defs
= (Lisp_Object
*) alloca (nmaps
* sizeof (defs
[0]));
4524 nmaps_allocated
= nmaps
;
4526 bcopy (maps
, submaps
, (nmaps
- 2) * sizeof (submaps
[0]));
4527 #ifdef USE_TEXT_PROPERTIES
4528 submaps
[nmaps
-2] = get_local_map (PT
, current_buffer
);
4530 submaps
[nmaps
-2] = current_buffer
->keymap
;
4533 submaps
[nmaps
-1] = current_global_map
;
4536 /* Find an accurate initial value for first_binding. */
4537 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
4538 if (! NILP (submaps
[first_binding
]))
4541 /* Start from the beginning in keybuf. */
4544 /* These are no-ops the first time through, but if we restart, they
4545 revert the echo area and this_command_keys to their original state. */
4546 this_command_key_count
= keys_start
;
4547 if (INTERACTIVE
&& t
< mock_input
)
4548 echo_truncate (echo_start
);
4550 /* If the best binding for the current key sequence is a keymap, or
4551 we may be looking at a function key's escape sequence, keep on
4553 while ((first_binding
< nmaps
&& ! NILP (submaps
[first_binding
]))
4554 || (first_binding
>= nmaps
4556 /* mock input is never part of a function key's sequence. */
4557 && mock_input
<= fkey_start
)
4558 || (keytran_start
< t
&& key_translation_possible
)
4559 /* Don't return in the middle of a possible function key sequence,
4560 if the only bindings we found were via case conversion.
4561 Thus, if ESC O a has a function-key-map translation
4562 and ESC o has a binding, don't return after ESC O,
4563 so that we can translate ESC O plus the next character. */
4567 int used_mouse_menu
= 0;
4569 /* Where the last real key started. If we need to throw away a
4570 key that has expanded into more than one element of keybuf
4571 (say, a mouse click on the mode line which is being treated
4572 as [mode-line (mouse-...)], then we backtrack to this point
4574 int last_real_key_start
;
4576 /* These variables are analogous to echo_start and keys_start;
4577 while those allow us to restart the entire key sequence,
4578 echo_local_start and keys_local_start allow us to throw away
4580 int echo_local_start
, keys_local_start
, local_first_binding
;
4583 error ("key sequence too long");
4586 echo_local_start
= echo_length ();
4587 keys_local_start
= this_command_key_count
;
4588 local_first_binding
= first_binding
;
4591 /* These are no-ops, unless we throw away a keystroke below and
4592 jumped back up to replay_key; in that case, these restore the
4593 variables to their original state, allowing us to replay the
4595 if (INTERACTIVE
&& t
< mock_input
)
4596 echo_truncate (echo_local_start
);
4597 this_command_key_count
= keys_local_start
;
4598 first_binding
= local_first_binding
;
4600 /* By default, assume each event is "real". */
4601 last_real_key_start
= t
;
4603 /* Does mock_input indicate that we are re-reading a key sequence? */
4607 add_command_key (key
);
4608 if (echo_keystrokes
)
4612 /* If not, we should actually read a character. */
4615 struct buffer
*buf
= current_buffer
;
4617 key
= read_char (NILP (prompt
), nmaps
, submaps
, last_nonmenu_event
,
4620 /* read_char returns t when it shows a menu and the user rejects it.
4625 /* read_char returns -1 at the end of a macro.
4626 Emacs 18 handles this by returning immediately with a
4627 zero, so that's what we'll do. */
4628 if (INTEGERP (key
) && XINT (key
) == -1)
4634 /* If the current buffer has been changed from under us, the
4635 keymap may have changed, so replay the sequence. */
4639 goto replay_sequence
;
4642 /* If we have a quit that was typed in another frame, and
4643 quit_throw_to_read_char switched buffers,
4644 replay to get the right keymap. */
4645 if (XINT (key
) == quit_char
&& current_buffer
!= starting_buffer
)
4650 goto replay_sequence
;
4656 /* Clicks in non-text areas get prefixed by the symbol
4657 in their CHAR-ADDRESS field. For example, a click on
4658 the mode line is prefixed by the symbol `mode-line'.
4660 Furthermore, key sequences beginning with mouse clicks
4661 are read using the keymaps of the buffer clicked on, not
4662 the current buffer. So we may have to switch the buffer
4665 When we turn one event into two events, we must make sure
4666 that neither of the two looks like the original--so that,
4667 if we replay the events, they won't be expanded again.
4668 If not for this, such reexpansion could happen either here
4669 or when user programs play with this-command-keys. */
4670 if (EVENT_HAS_PARAMETERS (key
))
4674 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
4675 if (EQ (kind
, Qmouse_click
))
4677 Lisp_Object window
, posn
;
4679 window
= POSN_WINDOW (EVENT_START (key
));
4680 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
4683 /* We're looking at the second event of a
4684 sequence which we expanded before. Set
4685 last_real_key_start appropriately. */
4687 last_real_key_start
= t
- 1;
4690 /* Key sequences beginning with mouse clicks are
4691 read using the keymaps in the buffer clicked on,
4692 not the current buffer. If we're at the
4693 beginning of a key sequence, switch buffers. */
4694 if (last_real_key_start
== 0
4696 && BUFFERP (XWINDOW (window
)->buffer
)
4697 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
4702 /* Arrange to go back to the original buffer once we're
4703 done reading the key sequence. Note that we can't
4704 use save_excursion_{save,restore} here, because they
4705 save point as well as the current buffer; we don't
4706 want to save point, because redisplay may change it,
4707 to accommodate a Fset_window_start or something. We
4708 don't want to do this at the top of the function,
4709 because we may get input from a subprocess which
4710 wants to change the selected window and stuff (say,
4712 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
4714 set_buffer_internal (XBUFFER (XWINDOW (window
)->buffer
));
4715 goto replay_sequence
;
4717 else if (SYMBOLP (posn
))
4719 /* Expand mode-line and scroll-bar events into two events:
4720 use posn as a fake prefix key. */
4722 if (t
+ 1 >= bufsize
)
4723 error ("key sequence too long");
4728 /* Zap the position in key, so we know that we've
4729 expanded it, and don't try to do so again. */
4730 POSN_BUFFER_POSN (EVENT_START (key
))
4731 = Fcons (posn
, Qnil
);
4735 else if (EQ (kind
, Qswitch_frame
))
4737 /* If we're at the beginning of a key sequence, go
4738 ahead and return this event. If we're in the
4739 midst of a key sequence, delay it until the end. */
4742 delayed_switch_frame
= key
;
4746 else if (CONSP (XCONS (key
)->cdr
)
4747 && CONSP (EVENT_START (key
))
4748 && CONSP (XCONS (EVENT_START (key
))->cdr
))
4752 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
4753 /* Handle menu-bar events:
4754 insert the dummy prefix event `menu-bar'. */
4755 if (EQ (posn
, Qmenu_bar
))
4757 if (t
+ 1 >= bufsize
)
4758 error ("key sequence too long");
4759 /* Run the Lucid hook. */
4760 if (!NILP (Vrun_hooks
))
4761 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
4762 /* If it has changed current-menubar from previous value,
4763 really recompute the menubar from the value. */
4764 if (! NILP (Vlucid_menu_bar_dirty_flag
))
4765 call0 (Qrecompute_lucid_menubar
);
4769 /* Zap the position in key, so we know that we've
4770 expanded it, and don't try to do so again. */
4771 POSN_BUFFER_POSN (EVENT_START (key
))
4772 = Fcons (posn
, Qnil
);
4775 goto replay_sequence
;
4777 else if (CONSP (posn
))
4779 /* We're looking at the second event of a
4780 sequence which we expanded before. Set
4781 last_real_key_start appropriately. */
4782 if (last_real_key_start
== t
&& t
> 0)
4783 last_real_key_start
= t
- 1;
4788 /* We have finally decided that KEY is something we might want
4790 first_binding
= (follow_key (key
,
4791 nmaps
- first_binding
,
4792 submaps
+ first_binding
,
4793 defs
+ first_binding
,
4794 submaps
+ first_binding
)
4797 /* If KEY wasn't bound, we'll try some fallbacks. */
4798 if (first_binding
>= nmaps
)
4802 head
= EVENT_HEAD (key
);
4803 if (EQ (head
, Vhelp_char
))
4805 read_key_sequence_cmd
= Vprefix_help_command
;
4807 last_nonmenu_event
= key
;
4813 Lisp_Object breakdown
;
4816 breakdown
= parse_modifiers (head
);
4817 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
4818 /* Attempt to reduce an unbound mouse event to a simpler
4819 event that is bound:
4820 Drags reduce to clicks.
4821 Double-clicks reduce to clicks.
4822 Triple-clicks reduce to double-clicks, then to clicks.
4823 Down-clicks are eliminated.
4824 Double-downs reduce to downs, then are eliminated.
4825 Triple-downs reduce to double-downs, then to downs,
4826 then are eliminated. */
4827 if (modifiers
& (down_modifier
| drag_modifier
4828 | double_modifier
| triple_modifier
))
4830 while (modifiers
& (down_modifier
| drag_modifier
4831 | double_modifier
| triple_modifier
))
4833 Lisp_Object new_head
, new_click
;
4834 if (modifiers
& triple_modifier
)
4835 modifiers
^= (double_modifier
| triple_modifier
);
4836 else if (modifiers
& (drag_modifier
| double_modifier
))
4837 modifiers
&= ~(drag_modifier
| double_modifier
);
4840 /* Dispose of this `down' event by simply jumping
4841 back to replay_key, to get another event.
4843 Note that if this event came from mock input,
4844 then just jumping back to replay_key will just
4845 hand it to us again. So we have to wipe out any
4848 We could delete keybuf[t] and shift everything
4849 after that to the left by one spot, but we'd also
4850 have to fix up any variable that points into
4851 keybuf, and shifting isn't really necessary
4854 Adding prefixes for non-textual mouse clicks
4855 creates two characters of mock input, and both
4856 must be thrown away. If we're only looking at
4857 the prefix now, we can just jump back to
4858 replay_key. On the other hand, if we've already
4859 processed the prefix, and now the actual click
4860 itself is giving us trouble, then we've lost the
4861 state of the keymaps we want to backtrack to, and
4862 we need to replay the whole sequence to rebuild
4865 Beyond that, only function key expansion could
4866 create more than two keys, but that should never
4867 generate mouse events, so it's okay to zero
4868 mock_input in that case too.
4870 Isn't this just the most wonderful code ever? */
4871 if (t
== last_real_key_start
)
4878 mock_input
= last_real_key_start
;
4879 goto replay_sequence
;
4884 = apply_modifiers (modifiers
, XCONS (breakdown
)->car
);
4886 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
4888 /* Look for a binding for this new key. follow_key
4889 promises that it didn't munge submaps the
4890 last time we called it, since key was unbound. */
4892 = (follow_key (new_click
,
4893 nmaps
- local_first_binding
,
4894 submaps
+ local_first_binding
,
4895 defs
+ local_first_binding
,
4896 submaps
+ local_first_binding
)
4897 + local_first_binding
);
4899 /* If that click is bound, go for it. */
4900 if (first_binding
< nmaps
)
4905 /* Otherwise, we'll leave key set to the drag event. */
4912 /* Normally, last_nonmenu_event gets the previous key we read.
4913 But when a mouse popup menu is being used,
4914 we don't update last_nonmenu_event; it continues to hold the mouse
4915 event that preceded the first level of menu. */
4916 if (!used_mouse_menu
)
4917 last_nonmenu_event
= key
;
4919 /* If the sequence is unbound, see if we can hang a function key
4920 off the end of it. We only want to scan real keyboard input
4921 for function key sequences, so if mock_input says that we're
4922 re-reading old events, don't examine it. */
4923 if (first_binding
>= nmaps
4926 Lisp_Object fkey_next
;
4928 /* Continue scan from fkey_end until we find a bound suffix.
4929 If we fail, increment fkey_start
4930 and start fkey_end from there. */
4931 while (fkey_end
< t
)
4935 key
= keybuf
[fkey_end
++];
4936 /* Look up meta-characters by prefixing them
4937 with meta_prefix_char. I hate this. */
4938 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
4943 (access_keymap (fkey_map
, meta_prefix_char
, 1, 0)),
4945 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
4948 fkey_next
= fkey_map
;
4951 = get_keyelt (access_keymap (fkey_next
, key
, 1, 0));
4953 #if 0 /* I didn't turn this on, because it might cause trouble
4954 for the mapping of return into C-m and tab into C-i. */
4955 /* Optionally don't map function keys into other things.
4956 This enables the user to redefine kp- keys easily. */
4957 if (SYMBOLP (key
) && !NILP (Vinhibit_function_key_mapping
))
4961 /* If the function key map gives a function, not an
4962 array, then call the function with no args and use
4963 its value instead. */
4964 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
4967 struct gcpro gcpro1
, gcpro2
, gcpro3
;
4971 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
4972 fkey_next
= call1 (fkey_next
, prompt
);
4974 /* If the function returned something invalid,
4975 barf--don't ignore it.
4976 (To ignore it safely, we would need to gcpro a bunch of
4977 other variables.) */
4978 if (! (VECTORP (fkey_next
) || STRINGP (fkey_next
)))
4979 error ("Function in function-key-map returns invalid key sequence");
4982 function_key_possible
= ! NILP (fkey_next
);
4984 /* If keybuf[fkey_start..fkey_end] is bound in the
4985 function key map and it's a suffix of the current
4986 sequence (i.e. fkey_end == t), replace it with
4987 the binding and restart with fkey_start at the end. */
4988 if ((VECTORP (fkey_next
) || STRINGP (fkey_next
))
4991 int len
= XFASTINT (Flength (fkey_next
));
4993 t
= fkey_start
+ len
;
4995 error ("key sequence too long");
4997 if (VECTORP (fkey_next
))
4998 bcopy (XVECTOR (fkey_next
)->contents
,
4999 keybuf
+ fkey_start
,
5000 (t
- fkey_start
) * sizeof (keybuf
[0]));
5001 else if (STRINGP (fkey_next
))
5005 for (i
= 0; i
< len
; i
++)
5006 XSETFASTINT (keybuf
[fkey_start
+ i
],
5007 XSTRING (fkey_next
)->data
[i
]);
5011 fkey_start
= fkey_end
= t
;
5012 fkey_map
= Vfunction_key_map
;
5014 /* Do pass the results through key-translation-map. */
5015 keytran_start
= keytran_end
= 0;
5016 keytran_map
= Vkey_translation_map
;
5018 goto replay_sequence
;
5021 fkey_map
= get_keymap_1 (fkey_next
, 0, 1);
5023 /* If we no longer have a bound suffix, try a new positions for
5025 if (NILP (fkey_map
))
5027 fkey_end
= ++fkey_start
;
5028 fkey_map
= Vfunction_key_map
;
5029 function_key_possible
= 0;
5034 /* Look for this sequence in key-translation-map. */
5036 Lisp_Object keytran_next
;
5038 /* Scan from keytran_end until we find a bound suffix. */
5039 while (keytran_end
< t
)
5043 key
= keybuf
[keytran_end
++];
5044 /* Look up meta-characters by prefixing them
5045 with meta_prefix_char. I hate this. */
5046 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
5051 (access_keymap (keytran_map
, meta_prefix_char
, 1, 0)),
5053 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
5056 keytran_next
= keytran_map
;
5059 = get_keyelt (access_keymap (keytran_next
, key
, 1, 0));
5061 /* If the key translation map gives a function, not an
5062 array, then call the function with no args and use
5063 its value instead. */
5064 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
5065 && keytran_end
== t
)
5067 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5071 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
5072 keytran_next
= call1 (keytran_next
, prompt
);
5074 /* If the function returned something invalid,
5075 barf--don't ignore it.
5076 (To ignore it safely, we would need to gcpro a bunch of
5077 other variables.) */
5078 if (! (VECTORP (keytran_next
) || STRINGP (keytran_next
)))
5079 error ("Function in key-translation-map returns invalid key sequence");
5082 key_translation_possible
= ! NILP (keytran_next
);
5084 /* If keybuf[keytran_start..keytran_end] is bound in the
5085 key translation map and it's a suffix of the current
5086 sequence (i.e. keytran_end == t), replace it with
5087 the binding and restart with keytran_start at the end. */
5088 if ((VECTORP (keytran_next
) || STRINGP (keytran_next
))
5089 && keytran_end
== t
)
5091 int len
= XFASTINT (Flength (keytran_next
));
5093 t
= keytran_start
+ len
;
5095 error ("key sequence too long");
5097 if (VECTORP (keytran_next
))
5098 bcopy (XVECTOR (keytran_next
)->contents
,
5099 keybuf
+ keytran_start
,
5100 (t
- keytran_start
) * sizeof (keybuf
[0]));
5101 else if (STRINGP (keytran_next
))
5105 for (i
= 0; i
< len
; i
++)
5106 XSETFASTINT (keybuf
[keytran_start
+ i
],
5107 XSTRING (keytran_next
)->data
[i
]);
5111 keytran_start
= keytran_end
= t
;
5112 keytran_map
= Vkey_translation_map
;
5114 /* Don't pass the results of key-translation-map
5115 through function-key-map. */
5116 fkey_start
= fkey_end
= t
;
5117 fkey_map
= Vkey_translation_map
;
5119 goto replay_sequence
;
5122 keytran_map
= get_keymap_1 (keytran_next
, 0, 1);
5124 /* If we no longer have a bound suffix, try a new positions for
5126 if (NILP (keytran_map
))
5128 keytran_end
= ++keytran_start
;
5129 keytran_map
= Vkey_translation_map
;
5130 key_translation_possible
= 0;
5135 /* If KEY is not defined in any of the keymaps,
5136 and cannot be part of a function key or translation,
5137 and is an upper case letter
5138 use the corresponding lower-case letter instead. */
5139 if (first_binding
== nmaps
&& ! function_key_possible
5140 && ! key_translation_possible
5142 && ((((XINT (key
) & 0x3ffff)
5143 < XSTRING (current_buffer
->downcase_table
)->size
)
5144 && UPPERCASEP (XINT (key
) & 0x3ffff))
5145 || (XINT (key
) & shift_modifier
)))
5147 if (XINT (key
) & shift_modifier
)
5148 XSETINT (key
, XINT (key
) & ~shift_modifier
);
5150 XSETINT (key
, (DOWNCASE (XINT (key
) & 0x3ffff)
5151 | (XINT (key
) & ~0x3ffff)));
5153 keybuf
[t
- 1] = key
;
5155 goto replay_sequence
;
5159 read_key_sequence_cmd
= (first_binding
< nmaps
5160 ? defs
[first_binding
]
5164 unread_switch_frame
= delayed_switch_frame
;
5165 unbind_to (count
, Qnil
);
5167 /* Occasionally we fabricate events, perhaps by expanding something
5168 according to function-key-map, or by adding a prefix symbol to a
5169 mouse click in the scroll bar or modeline. In this cases, return
5170 the entire generated key sequence, even if we hit an unbound
5171 prefix or a definition before the end. This means that you will
5172 be able to push back the event properly, and also means that
5173 read-key-sequence will always return a logical unit.
5176 for (; t
< mock_input
; t
++)
5178 if (echo_keystrokes
)
5179 echo_char (keybuf
[t
]);
5180 add_command_key (keybuf
[t
]);
5186 #if 0 /* This doc string is too long for some compilers.
5187 This commented-out definition serves for DOC. */
5188 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 2, 0,
5189 "Read a sequence of keystrokes and return as a string or vector.\n\
5190 The sequence is sufficient to specify a non-prefix command in the\n\
5191 current local and global maps.\n\
5193 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
5194 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
5195 as a continuation of the previous key.\n\
5197 A C-g typed while in this function is treated like any other character,\n\
5198 and `quit-flag' is not set.\n\
5200 If the key sequence starts with a mouse click, then the sequence is read\n\
5201 using the keymaps of the buffer of the window clicked in, not the buffer\n\
5202 of the selected window as normal.\n\
5204 `read-key-sequence' drops unbound button-down events, since you normally\n\
5205 only care about the click or drag events which follow them. If a drag\n\
5206 or multi-click event is unbound, but the corresponding click event would\n\
5207 be bound, `read-key-sequence' turns the event into a click event at the\n\
5208 drag's starting position. This means that you don't have to distinguish\n\
5209 between click and drag, double, or triple events unless you want to.\n\
5211 `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\
5212 lines separating windows, and scroll bars with imaginary keys\n\
5213 `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\
5215 If the user switches frames in the middle of a key sequence, the\n\
5216 frame-switch event is put off until after the current key sequence.\n\
5218 `read-key-sequence' checks `function-key-map' for function key\n\
5219 sequences, where they wouldn't conflict with ordinary bindings. See\n\
5220 `function-key-map' for more details.")
5221 (prompt
, continue_echo
)
5224 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 2, 0,
5226 (prompt
, continue_echo
)
5227 Lisp_Object prompt
, continue_echo
;
5229 Lisp_Object keybuf
[30];
5231 struct gcpro gcpro1
, gcpro2
;
5234 CHECK_STRING (prompt
, 0);
5237 bzero (keybuf
, sizeof keybuf
);
5239 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
5241 if (NILP (continue_echo
))
5242 this_command_key_count
= 0;
5244 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])), prompt
);
5252 return make_event_array (i
, keybuf
);
5255 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 2, 0,
5256 "Execute CMD as an editor command.\n\
5257 CMD must be a symbol that satisfies the `commandp' predicate.\n\
5258 Optional second arg RECORD-FLAG non-nil\n\
5259 means unconditionally put this command in `command-history'.\n\
5260 Otherwise, that is done only if an arg is read using the minibuffer.")
5262 Lisp_Object cmd
, record
;
5264 register Lisp_Object final
;
5265 register Lisp_Object tem
;
5266 Lisp_Object prefixarg
;
5267 struct backtrace backtrace
;
5268 extern int debug_on_next_call
;
5270 prefixarg
= Vprefix_arg
, Vprefix_arg
= Qnil
;
5271 Vcurrent_prefix_arg
= prefixarg
;
5272 debug_on_next_call
= 0;
5276 tem
= Fget (cmd
, Qdisabled
);
5277 if (!NILP (tem
) && !NILP (Vrun_hooks
))
5278 return call1 (Vrun_hooks
, Qdisabled_command_hook
);
5283 final
= Findirect_function (cmd
);
5285 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
5286 do_autoload (final
, cmd
);
5291 if (STRINGP (final
) || VECTORP (final
))
5293 /* If requested, place the macro in the command history. For
5294 other sorts of commands, call-interactively takes care of
5298 = Fcons (Fcons (Qexecute_kbd_macro
,
5299 Fcons (final
, Fcons (prefixarg
, Qnil
))),
5302 return Fexecute_kbd_macro (final
, prefixarg
);
5304 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
5306 backtrace
.next
= backtrace_list
;
5307 backtrace_list
= &backtrace
;
5308 backtrace
.function
= &Qcall_interactively
;
5309 backtrace
.args
= &cmd
;
5310 backtrace
.nargs
= 1;
5311 backtrace
.evalargs
= 0;
5313 tem
= Fcall_interactively (cmd
, record
);
5315 backtrace_list
= backtrace
.next
;
5321 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
5323 "Read function name, then read its arguments and call it.")
5325 Lisp_Object prefixarg
;
5327 Lisp_Object function
;
5329 Lisp_Object saved_keys
;
5330 struct gcpro gcpro1
;
5332 saved_keys
= Fvector (this_command_key_count
,
5333 XVECTOR (this_command_keys
)->contents
);
5335 GCPRO1 (saved_keys
);
5337 if (EQ (prefixarg
, Qminus
))
5339 else if (CONSP (prefixarg
) && XINT (XCONS (prefixarg
)->car
) == 4)
5340 strcpy (buf
, "C-u ");
5341 else if (CONSP (prefixarg
) && INTEGERP (XCONS (prefixarg
)->car
))
5342 sprintf (buf
, "%d ", XINT (XCONS (prefixarg
)->car
));
5343 else if (INTEGERP (prefixarg
))
5344 sprintf (buf
, "%d ", XINT (prefixarg
));
5346 /* This isn't strictly correct if execute-extended-command
5347 is bound to anything else. Perhaps it should use
5348 this_command_keys? */
5349 strcat (buf
, "M-x ");
5351 /* Prompt with buf, and then read a string, completing from and
5352 restricting to the set of all defined commands. Don't provide
5353 any initial input. Save the command read on the extended-command
5355 function
= Fcompleting_read (build_string (buf
),
5356 Vobarray
, Qcommandp
,
5357 Qt
, Qnil
, Qextended_command_history
);
5359 /* Set this_command_keys to the concatenation of saved_keys and
5360 function, followed by a RET. */
5362 struct Lisp_String
*str
;
5367 this_command_key_count
= 0;
5369 keys
= XVECTOR (saved_keys
)->contents
;
5370 for (i
= 0; i
< XVECTOR (saved_keys
)->size
; i
++)
5371 add_command_key (keys
[i
]);
5373 str
= XSTRING (function
);
5374 for (i
= 0; i
< str
->size
; i
++)
5376 XSETFASTINT (tem
, str
->data
[i
]);
5377 add_command_key (tem
);
5380 XSETFASTINT (tem
, '\015');
5381 add_command_key (tem
);
5386 function
= Fintern (function
, Qnil
);
5387 Vprefix_arg
= prefixarg
;
5388 this_command
= function
;
5390 return Fcommand_execute (function
, Qt
);
5394 detect_input_pending ()
5397 get_input_pending (&input_pending
);
5399 return input_pending
;
5402 /* This is called in some cases before a possible quit.
5403 It cases the next call to detect_input_pending to recompute input_pending.
5404 So calling this function unnecessarily can't do any harm. */
5405 clear_input_pending ()
5410 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
5411 "T if command input is currently available with no waiting.\n\
5412 Actually, the value is nil only if we can be sure that no input is available.")
5415 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1)
5418 return detect_input_pending () ? Qt
: Qnil
;
5421 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
5422 "Return vector of last 100 events, not counting those from keyboard macros.")
5425 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
5428 if (total_keys
< NUM_RECENT_KEYS
)
5429 return Fvector (total_keys
, keys
);
5432 val
= Fvector (NUM_RECENT_KEYS
, keys
);
5433 bcopy (keys
+ recent_keys_index
,
5434 XVECTOR (val
)->contents
,
5435 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
5437 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
5438 recent_keys_index
* sizeof (Lisp_Object
));
5443 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
5444 "Return the key sequence that invoked this command.\n\
5445 The value is a string or a vector.")
5448 return make_event_array (this_command_key_count
,
5449 XVECTOR (this_command_keys
)->contents
);
5452 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
5453 "Return the current depth in recursive edits.")
5457 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
5461 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
5462 "FOpen dribble file: ",
5463 "Start writing all keyboard characters to a dribble file called FILE.\n\
5464 If FILE is nil, close any open dribble file.")
5475 file
= Fexpand_file_name (file
, Qnil
);
5476 dribble
= fopen (XSTRING (file
)->data
, "w");
5481 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
5482 "Discard the contents of the terminal input buffer.\n\
5483 Also cancel any kbd macro being defined.")
5486 defining_kbd_macro
= 0;
5487 update_mode_lines
++;
5489 Vunread_command_events
= Qnil
;
5490 unread_command_char
= -1;
5492 discard_tty_input ();
5494 /* Without the cast, GCC complains that this assignment loses the
5495 volatile qualifier of kbd_store_ptr. Is there anything wrong
5497 kbd_fetch_ptr
= (struct input_event
*) kbd_store_ptr
;
5498 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
5504 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
5505 "Stop Emacs and return to superior process. You can resume later.\n\
5506 If `cannot-suspend' is non-nil, or if the system doesn't support job\n\
5507 control, run a subshell instead.\n\n\
5508 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
5509 to be read as terminal input by Emacs's parent, after suspension.\n\
5511 Before suspending, run the normal hook `suspend-hook'.\n\
5512 After resumption run the normal hook `suspend-resume-hook'.\n\
5514 Some operating systems cannot stop the Emacs process and resume it later.\n\
5515 On such systems, Emacs starts a subshell instead of suspending.")
5517 Lisp_Object stuffstring
;
5520 int count
= specpdl_ptr
- specpdl
;
5521 int old_height
, old_width
;
5523 struct gcpro gcpro1
, gcpro2
;
5524 extern init_sys_modes ();
5526 if (!NILP (stuffstring
))
5527 CHECK_STRING (stuffstring
, 0);
5529 /* Run the functions in suspend-hook. */
5530 if (!NILP (Vrun_hooks
))
5531 call1 (Vrun_hooks
, intern ("suspend-hook"));
5533 GCPRO1 (stuffstring
);
5534 get_frame_size (&old_width
, &old_height
);
5536 /* sys_suspend can get an error if it tries to fork a subshell
5537 and the system resources aren't available for that. */
5538 record_unwind_protect (init_sys_modes
, 0);
5539 stuff_buffered_input (stuffstring
);
5544 unbind_to (count
, Qnil
);
5546 /* Check if terminal/window size has changed.
5547 Note that this is not useful when we are running directly
5548 with a window system; but suspend should be disabled in that case. */
5549 get_frame_size (&width
, &height
);
5550 if (width
!= old_width
|| height
!= old_height
)
5551 change_frame_size (selected_frame
, height
, width
, 0, 0);
5553 /* Run suspend-resume-hook. */
5554 if (!NILP (Vrun_hooks
))
5555 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
5561 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
5562 Then in any case stuff anything Emacs has read ahead and not used. */
5564 stuff_buffered_input (stuffstring
)
5565 Lisp_Object stuffstring
;
5567 register unsigned char *p
;
5569 /* stuff_char works only in BSD, versions 4.2 and up. */
5572 if (STRINGP (stuffstring
))
5576 p
= XSTRING (stuffstring
)->data
;
5577 count
= XSTRING (stuffstring
)->size
;
5582 /* Anything we have read ahead, put back for the shell to read. */
5583 while (kbd_fetch_ptr
!= kbd_store_ptr
)
5585 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
5586 kbd_fetch_ptr
= kbd_buffer
;
5587 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
5588 stuff_char (kbd_fetch_ptr
->code
);
5589 kbd_fetch_ptr
->kind
= no_event
;
5590 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_fetch_ptr
5597 #endif /* BSD and not BSD4_1 */
5600 set_waiting_for_input (time_to_clear
)
5601 EMACS_TIME
*time_to_clear
;
5603 input_available_clear_time
= time_to_clear
;
5605 /* Tell interrupt_signal to throw back to read_char, */
5606 waiting_for_input
= 1;
5608 /* If interrupt_signal was called before and buffered a C-g,
5609 make it run again now, to avoid timing error. */
5610 if (!NILP (Vquit_flag
))
5611 quit_throw_to_read_char ();
5614 clear_waiting_for_input ()
5616 /* Tell interrupt_signal not to throw back to read_char, */
5617 waiting_for_input
= 0;
5618 input_available_clear_time
= 0;
5621 /* This routine is called at interrupt level in response to C-G.
5622 If interrupt_input, this is the handler for SIGINT.
5623 Otherwise, it is called from kbd_buffer_store_event,
5624 in handling SIGIO or SIGTINT.
5626 If `waiting_for_input' is non zero, then unless `echoing' is nonzero,
5627 immediately throw back to read_char.
5629 Otherwise it sets the Lisp variable quit-flag not-nil.
5630 This causes eval to throw, when it gets a chance.
5631 If quit-flag is already non-nil, it stops the job right away. */
5637 /* Must preserve main program's value of errno. */
5638 int old_errno
= errno
;
5641 if (!read_socket_hook
&& NILP (Vwindow_system
))
5643 /* USG systems forget handlers when they are used;
5644 must reestablish each time */
5645 signal (SIGINT
, interrupt_signal
);
5646 signal (SIGQUIT
, interrupt_signal
);
5652 if (!NILP (Vquit_flag
) && FRAME_TERMCAP_P (selected_frame
))
5657 #ifdef SIGTSTP /* Support possible in later USG versions */
5659 * On systems which can suspend the current process and return to the original
5660 * shell, this command causes the user to end up back at the shell.
5661 * The "Auto-save" and "Abort" questions are not asked until
5662 * the user elects to return to emacs, at which point he can save the current
5663 * job and either dump core or continue.
5668 if (sys_suspend () == -1)
5670 printf ("Not running as a subprocess;\n");
5671 printf ("you can continue or abort.\n");
5674 /* Perhaps should really fork an inferior shell?
5675 But that would not provide any way to get back
5676 to the original shell, ever. */
5677 printf ("No support for stopping a process on this operating system;\n");
5678 printf ("you can continue or abort.\n");
5679 #endif /* not VMS */
5680 #endif /* not SIGTSTP */
5682 /* We must remain inside the screen area when the internal terminal
5683 is used. Note that [Enter] is not echoed by dos. */
5686 printf ("Auto-save? (y or n) ");
5688 if (((c
= getchar ()) & ~040) == 'Y')
5690 Fdo_auto_save (Qt
, Qnil
);
5692 printf ("\r\nAuto-save done");
5693 #else /* not MSDOS */
5694 printf ("Auto-save done\n");
5695 #endif /* not MSDOS */
5697 while (c
!= '\n') c
= getchar ();
5699 printf ("\r\nAbort? (y or n) ");
5700 #else /* not MSDOS */
5702 printf ("Abort (and enter debugger)? (y or n) ");
5704 printf ("Abort (and dump core)? (y or n) ");
5705 #endif /* not VMS */
5706 #endif /* not MSDOS */
5708 if (((c
= getchar ()) & ~040) == 'Y')
5710 while (c
!= '\n') c
= getchar ();
5712 printf ("\r\nContinuing...\r\n");
5713 #else /* not MSDOS */
5714 printf ("Continuing...\n");
5715 #endif /* not MSDOS */
5721 /* If executing a function that wants to be interrupted out of
5722 and the user has not deferred quitting by binding `inhibit-quit'
5723 then quit right away. */
5724 if (immediate_quit
&& NILP (Vinhibit_quit
))
5728 Fsignal (Qquit
, Qnil
);
5731 /* Else request quit when it's safe */
5735 if (waiting_for_input
&& !echoing
)
5736 quit_throw_to_read_char ();
5741 /* Handle a C-g by making read_char return C-g. */
5743 quit_throw_to_read_char ()
5745 quit_error_check ();
5747 /* Prevent another signal from doing this before we finish. */
5748 clear_waiting_for_input ();
5751 Vunread_command_events
= Qnil
;
5752 unread_command_char
= -1;
5754 #ifdef POLL_FOR_INPUT
5755 /* May be > 1 if in recursive minibuffer. */
5756 if (poll_suppress_count
== 0)
5760 if (FRAMEP (internal_last_event_frame
)
5761 && XFRAME (internal_last_event_frame
) != selected_frame
)
5762 Fhandle_switch_frame (make_lispy_switch_frame (internal_last_event_frame
));
5765 _longjmp (getcjmp
, 1);
5768 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
5769 "Set mode of reading keyboard input.\n\
5770 First arg INTERRUPT non-nil means use input interrupts;\n\
5771 nil means use CBREAK mode.\n\
5772 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
5773 (no effect except in CBREAK mode).\n\
5774 Third arg META t means accept 8-bit input (for a Meta key).\n\
5775 META nil means ignore the top bit, on the assumption it is parity.\n\
5776 Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\
5777 Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\
5778 See also `current-input-mode'.")
5779 (interrupt
, flow
, meta
, quit
)
5780 Lisp_Object interrupt
, flow
, meta
, quit
;
5783 && (!INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400))
5784 error ("set-input-mode: QUIT must be an ASCII character");
5786 #ifdef POLL_FOR_INPUT
5792 /* Note SIGIO has been undef'd if FIONREAD is missing. */
5793 #ifdef NO_SOCK_SIGIO
5794 if (read_socket_hook
)
5795 interrupt_input
= 0; /* No interrupts if reading from a socket. */
5797 #endif /* NO_SOCK_SIGIO */
5798 interrupt_input
= !NILP (interrupt
);
5799 #else /* not SIGIO */
5800 interrupt_input
= 0;
5801 #endif /* not SIGIO */
5802 /* Our VMS input only works by interrupts, as of now. */
5804 interrupt_input
= 1;
5806 flow_control
= !NILP (flow
);
5809 else if (EQ (meta
, Qt
))
5814 /* Don't let this value be out of range. */
5815 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
5819 #ifdef POLL_FOR_INPUT
5820 poll_suppress_count
= 1;
5826 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
5827 "Return information about the way Emacs currently reads keyboard input.\n\
5828 The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
5829 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\
5830 nil, Emacs is using CBREAK mode.\n\
5831 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\
5832 terminal; this does not apply if Emacs uses interrupt-driven input.\n\
5833 META is t if accepting 8-bit input with 8th bit as Meta flag.\n\
5834 META nil means ignoring the top bit, on the assumption it is parity.\n\
5835 META is neither t nor nil if accepting 8-bit input and using\n\
5836 all 8 bits as the character code.\n\
5837 QUIT is the character Emacs currently uses to quit.\n\
5838 The elements of this list correspond to the arguments of\n\
5844 val
[0] = interrupt_input
? Qt
: Qnil
;
5845 val
[1] = flow_control
? Qt
: Qnil
;
5846 val
[2] = meta_key
== 2 ? make_number (0) : meta_key
== 1 ? Qt
: Qnil
;
5847 XSETFASTINT (val
[3], quit_char
);
5849 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
5855 /* This is correct before outermost invocation of the editor loop */
5856 command_loop_level
= -1;
5858 quit_char
= Ctl ('g');
5859 Vunread_command_events
= Qnil
;
5860 unread_command_char
= -1;
5862 recent_keys_index
= 0;
5863 kbd_fetch_ptr
= kbd_buffer
;
5864 kbd_store_ptr
= kbd_buffer
;
5865 do_mouse_tracking
= 0;
5869 /* This means that command_loop_1 won't try to select anything the first
5871 internal_last_event_frame
= Qnil
;
5872 Vlast_event_frame
= internal_last_event_frame
;
5875 /* If we're running a dumped Emacs, we need to clear out
5876 kbd_buffer_frame_or_window, in case some events got into it
5879 If we're running an undumped Emacs, it hasn't been initialized by
5880 syms_of_keyboard yet. */
5882 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
5884 if (!noninteractive
&& !read_socket_hook
&& NILP (Vwindow_system
))
5886 signal (SIGINT
, interrupt_signal
);
5887 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
5888 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
5889 SIGQUIT and we can't tell which one it will give us. */
5890 signal (SIGQUIT
, interrupt_signal
);
5891 #endif /* HAVE_TERMIO */
5893 /* Note SIGIO has been undef'd if FIONREAD is missing. */
5895 if (!noninteractive
)
5896 signal (SIGIO
, input_available_signal
);
5899 /* Use interrupt input by default, if it works and noninterrupt input
5900 has deficiencies. */
5902 #ifdef INTERRUPT_INPUT
5903 interrupt_input
= 1;
5905 interrupt_input
= 0;
5908 /* Our VMS input only works by interrupts, as of now. */
5910 interrupt_input
= 1;
5916 if (keyboard_init_hook
)
5917 (*keyboard_init_hook
) ();
5919 #ifdef POLL_FOR_INPUT
5920 poll_suppress_count
= 1;
5925 /* This type's only use is in syms_of_keyboard, to initialize the
5926 event header symbols and put properties on them. */
5933 struct event_head head_table
[] = {
5934 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
5935 &Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
,
5936 &Qswitch_frame
, "switch-frame", &Qswitch_frame
,
5937 &Qdelete_frame
, "delete-frame", &Qdelete_frame
,
5942 Qdisabled_command_hook
= intern ("disabled-command-hook");
5943 staticpro (&Qdisabled_command_hook
);
5945 Qself_insert_command
= intern ("self-insert-command");
5946 staticpro (&Qself_insert_command
);
5948 Qforward_char
= intern ("forward-char");
5949 staticpro (&Qforward_char
);
5951 Qbackward_char
= intern ("backward-char");
5952 staticpro (&Qbackward_char
);
5954 Qdisabled
= intern ("disabled");
5955 staticpro (&Qdisabled
);
5957 Qundefined
= intern ("undefined");
5958 staticpro (&Qundefined
);
5960 Qpre_command_hook
= intern ("pre-command-hook");
5961 staticpro (&Qpre_command_hook
);
5963 Qpost_command_hook
= intern ("post-command-hook");
5964 staticpro (&Qpost_command_hook
);
5966 Qcommand_hook_internal
= intern ("command-hook-internal");
5967 staticpro (&Qcommand_hook_internal
);
5969 Qfunction_key
= intern ("function-key");
5970 staticpro (&Qfunction_key
);
5971 Qmouse_click
= intern ("mouse-click");
5972 staticpro (&Qmouse_click
);
5974 Qmenu_enable
= intern ("menu-enable");
5975 staticpro (&Qmenu_enable
);
5977 Qmode_line
= intern ("mode-line");
5978 staticpro (&Qmode_line
);
5979 Qvertical_line
= intern ("vertical-line");
5980 staticpro (&Qvertical_line
);
5981 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
5982 staticpro (&Qvertical_scroll_bar
);
5983 Qmenu_bar
= intern ("menu-bar");
5984 staticpro (&Qmenu_bar
);
5986 Qabove_handle
= intern ("above-handle");
5987 staticpro (&Qabove_handle
);
5988 Qhandle
= intern ("handle");
5989 staticpro (&Qhandle
);
5990 Qbelow_handle
= intern ("below-handle");
5991 staticpro (&Qbelow_handle
);
5993 Qevent_kind
= intern ("event-kind");
5994 staticpro (&Qevent_kind
);
5995 Qevent_symbol_elements
= intern ("event-symbol-elements");
5996 staticpro (&Qevent_symbol_elements
);
5997 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
5998 staticpro (&Qevent_symbol_element_mask
);
5999 Qmodifier_cache
= intern ("modifier-cache");
6000 staticpro (&Qmodifier_cache
);
6002 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
6003 staticpro (&Qrecompute_lucid_menubar
);
6004 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
6005 staticpro (&Qactivate_menubar_hook
);
6007 Qpolling_period
= intern ("polling-period");
6008 staticpro (&Qpolling_period
);
6011 struct event_head
*p
;
6013 for (p
= head_table
;
6014 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
6017 *p
->var
= intern (p
->name
);
6019 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
6020 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
6024 button_down_location
= Fmake_vector (make_number (NUM_MOUSE_BUTTONS
), Qnil
);
6025 staticpro (&button_down_location
);
6029 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
6031 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
6032 for (i
= 0; i
< len
; i
++)
6033 if (modifier_names
[i
])
6034 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
6035 staticpro (&modifier_symbols
);
6038 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
6039 staticpro (&recent_keys
);
6041 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
6042 staticpro (&this_command_keys
);
6044 Qextended_command_history
= intern ("extended-command-history");
6045 Fset (Qextended_command_history
, Qnil
);
6046 staticpro (&Qextended_command_history
);
6048 kbd_buffer_frame_or_window
6049 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
6050 staticpro (&kbd_buffer_frame_or_window
);
6052 accent_key_syms
= Qnil
;
6053 staticpro (&accent_key_syms
);
6055 func_key_syms
= Qnil
;
6056 staticpro (&func_key_syms
);
6058 system_key_syms
= Qnil
;
6059 staticpro (&system_key_syms
);
6062 staticpro (&mouse_syms
);
6064 unread_switch_frame
= Qnil
;
6065 staticpro (&unread_switch_frame
);
6067 defsubr (&Sread_key_sequence
);
6068 defsubr (&Srecursive_edit
);
6069 defsubr (&Strack_mouse
);
6070 defsubr (&Sinput_pending_p
);
6071 defsubr (&Scommand_execute
);
6072 defsubr (&Srecent_keys
);
6073 defsubr (&Sthis_command_keys
);
6074 defsubr (&Ssuspend_emacs
);
6075 defsubr (&Sabort_recursive_edit
);
6076 defsubr (&Sexit_recursive_edit
);
6077 defsubr (&Srecursion_depth
);
6078 defsubr (&Stop_level
);
6079 defsubr (&Sdiscard_input
);
6080 defsubr (&Sopen_dribble_file
);
6081 defsubr (&Sset_input_mode
);
6082 defsubr (&Scurrent_input_mode
);
6083 defsubr (&Sexecute_extended_command
);
6085 DEFVAR_LISP ("last-command-char", &last_command_char
,
6086 "Last input event that was part of a command.");
6088 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char
,
6089 "Last input event that was part of a command.");
6091 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
6092 "Last input event in a command, except for mouse menu events.\n\
6093 Mouse menus give back keys that don't look like mouse events;\n\
6094 this variable holds the actual mouse event that led to the menu,\n\
6095 so that you can determine whether the command was run by mouse or not.");
6097 DEFVAR_LISP ("last-input-char", &last_input_char
,
6098 "Last input event.");
6100 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char
,
6101 "Last input event.");
6103 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
6104 "List of objects to be read as next command input events.");
6106 DEFVAR_INT ("unread-command-char", &unread_command_char
,
6107 "If not -1, an object to be read as next command input event.");
6109 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
6110 "Meta-prefix character code. Meta-foo as command input\n\
6111 turns into this character followed by foo.");
6112 XSETINT (meta_prefix_char
, 033);
6114 DEFVAR_LISP ("last-command", &last_command
,
6115 "The last command executed. Normally a symbol with a function definition,\n\
6116 but can be whatever was found in the keymap, or whatever the variable\n\
6117 `this-command' was set to by that command.");
6118 last_command
= Qnil
;
6120 DEFVAR_LISP ("this-command", &this_command
,
6121 "The command now being executed.\n\
6122 The command can set this variable; whatever is put here\n\
6123 will be in `last-command' during the following command.");
6124 this_command
= Qnil
;
6126 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
6127 "*Number of keyboard input characters between auto-saves.\n\
6128 Zero means disable autosaving due to number of characters typed.");
6129 auto_save_interval
= 300;
6131 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
6132 "*Number of seconds idle time before auto-save.\n\
6133 Zero or nil means disable auto-saving due to idleness.\n\
6134 After auto-saving due to this many seconds of idle time,\n\
6135 Emacs also does a garbage collection if that seems to be warranted.");
6136 XSETFASTINT (Vauto_save_timeout
, 30);
6138 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes
,
6139 "*Nonzero means echo unfinished commands after this many seconds of pause.");
6140 echo_keystrokes
= 1;
6142 DEFVAR_INT ("polling-period", &polling_period
,
6143 "*Interval between polling for input during Lisp execution.\n\
6144 The reason for polling is to make C-g work to stop a running program.\n\
6145 Polling is needed only when using X windows and SIGIO does not work.\n\
6146 Polling is automatically disabled in all other cases.");
6149 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
6150 "*Maximum time between mouse clicks to make a double-click.\n\
6151 Measured in milliseconds. nil means disable double-click recognition;\n\
6152 t means double-clicks have no time limit and are detected\n\
6153 by position only.");
6154 Vdouble_click_time
= make_number (500);
6156 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
6157 "*Non-nil means inhibit local map menu bar menus.");
6158 inhibit_local_menu_bar_menus
= 0;
6160 DEFVAR_INT ("num-input-keys", &num_input_keys
,
6161 "*Number of complete keys read from the keyboard so far.");
6164 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
6165 "*The frame in which the most recently read event occurred.\n\
6166 If the last event came from a keyboard macro, this is set to `macro'.");
6167 Vlast_event_frame
= Qnil
;
6169 DEFVAR_LISP ("help-char", &Vhelp_char
,
6170 "Character to recognize as meaning Help.\n\
6171 When it is read, do `(eval help-form)', and display result if it's a string.\n\
6172 If the value of `help-form' is nil, this char can be read normally.");
6173 XSETINT (Vhelp_char
, Ctl ('H'));
6175 DEFVAR_LISP ("help-form", &Vhelp_form
,
6176 "Form to execute when character `help-char' is read.\n\
6177 If the form returns a string, that string is displayed.\n\
6178 If `help-form' is nil, the help char is not recognized.");
6181 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
6182 "Command to run when `help-char' character follows a prefix key.\n\
6183 This command is used only when there is no actual binding\n\
6184 for that character after that prefix key.");
6185 Vprefix_help_command
= Qnil
;
6187 DEFVAR_LISP ("top-level", &Vtop_level
,
6188 "Form to evaluate when Emacs starts up.\n\
6189 Useful to set before you dump a modified Emacs.");
6192 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
6193 "String used as translate table for keyboard input, or nil.\n\
6194 Each character is looked up in this string and the contents used instead.\n\
6195 If string is of length N, character codes N and up are untranslated.");
6196 Vkeyboard_translate_table
= Qnil
;
6198 DEFVAR_LISP ("key-translation-map", &Vkey_translation_map
,
6199 "Keymap of key translations that can override keymaps.\n\
6200 This keymap works like `function-key-map', but comes after that,\n\
6201 and applies even for keys that have ordinary bindings.");
6202 Vkey_translation_map
= Qnil
;
6204 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
6205 "Non-nil means to always spawn a subshell instead of suspending,\n\
6206 even if the operating system has support for stopping a process.");
6209 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
6210 "Non-nil means prompt with menus when appropriate.\n\
6211 This is done when reading from a keymap that has a prompt string,\n\
6212 for elements that have prompt strings.\n\
6213 The menu is displayed on the screen\n\
6214 if X menus were enabled at configuration\n\
6215 time and the previous event was a mouse click prefix key.\n\
6216 Otherwise, menu prompting uses the echo area.");
6219 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
6220 "Character to see next line of menu prompt.\n\
6221 Type this character while in a menu prompt to rotate around the lines of it.");
6222 XSETINT (menu_prompt_more_char
, ' ');
6224 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
6225 "A mask of additional modifier keys to use with every keyboard character.\n\
6226 Emacs applies the modifiers of the character stored here to each keyboard\n\
6227 character it reads. For example, after evaluating the expression\n\
6228 (setq extra-keyboard-modifiers ?\C-x)\n\
6229 all input characters will have the control modifier applied to them.\n\
6231 Note that the character ?\C-@, equivalent to the integer zero, does\n\
6232 not count as a control character; rather, it counts as a character\n\
6233 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\
6234 cancels any modification.");
6235 extra_keyboard_modifiers
= 0;
6237 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
6238 "If an editing command sets this to t, deactivate the mark afterward.\n\
6239 The command loop sets this to nil before each command,\n\
6240 and tests the value when the command returns.\n\
6241 Buffer modification stores t in this variable.");
6242 Vdeactivate_mark
= Qnil
;
6244 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
6245 "Temporary storage of pre-command-hook or post-command-hook.");
6246 Vcommand_hook_internal
= Qnil
;
6248 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
6249 "Normal hook run before each command is executed.\n\
6250 While the hook is run, its value is temporarily set to nil\n\
6251 to avoid an unbreakable infinite loop if a hook function gets an error.\n\
6252 As a result, a hook function cannot straightforwardly alter the value of\n\
6253 `pre-command-hook'. See the Emacs Lisp manual for a way of\n\
6254 implementing hook functions that alter the set of hook functions.");
6255 Vpre_command_hook
= Qnil
;
6257 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
6258 "Normal hook run after each command is executed.\n\
6259 While the hook is run, its value is temporarily set to nil\n\
6260 to avoid an unbreakable infinite loop if a hook function gets an error.\n\
6261 As a result, a hook function cannot straightforwardly alter the value of\n\
6262 `post-command-hook'. See the Emacs Lisp manual for a way of\n\
6263 implementing hook functions that alter the set of hook functions.");
6264 Vpost_command_hook
= Qnil
;
6266 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
6267 "t means menu bar, specified Lucid style, needs to be recomputed.");
6268 Vlucid_menu_bar_dirty_flag
= Qnil
;
6270 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
6271 "List of menu bar items to move to the end of the menu bar.\n\
6272 The elements of the list are event types that may have menu bar bindings.");
6273 Vmenu_bar_final_items
= Qnil
;
6275 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
6276 "Keymap that overrides all other local keymaps.\n\
6277 If this variable is non-nil, it is used as a keymap instead of the\n\
6278 buffer's local map, and the minor mode keymaps and text property keymaps.");
6279 Voverriding_local_map
= Qnil
;
6281 DEFVAR_BOOL ("track-mouse", &do_mouse_tracking
,
6282 "*Non-nil means generate motion events for mouse motion.");
6284 DEFVAR_LISP ("system-key-alist", &Vsystem_key_alist
,
6285 "Alist of system-specific X windows key symbols.\n\
6286 Each element should have the form (N . SYMBOL) where N is the\n\
6287 numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\
6288 and SYMBOL is its name.");
6289 Vsystem_key_alist
= Qnil
;
6291 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
6292 "List of deferred actions to be performed at a later time.\n\
6293 The precise format isn't relevant here; we just check whether it is nil.");
6294 Vdeferred_action_list
= Qnil
;
6296 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
6297 "Function to call to handle deferred actions, after each command.\n\
6298 This function is called with no arguments after each command\n\
6299 whenever `deferred-action-list' is non-nil.");
6300 Vdeferred_action_function
= Qnil
;
6305 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
6306 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
6307 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
6308 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
6309 initial_define_key (meta_map
, 'x', "execute-extended-command");