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
);
3434 #ifdef POLL_FOR_INPUT
3435 if (read_socket_hook
&& !interrupt_input
&& poll_suppress_count
== 0)
3438 mask
= sigblockx (SIGALRM
);
3439 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 #ifdef HAVE_X_WINDOWS
4063 /* If we got to this point via a mouse click,
4064 use a real menu for mouse selection. */
4065 if (EVENT_HAS_PARAMETERS (prev_event
))
4067 /* Display the menu and get the selection. */
4068 Lisp_Object
*realmaps
4069 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
4073 /* Use the maps that are not nil. */
4074 for (mapno
= 0; mapno
< nmaps
; mapno
++)
4075 if (!NILP (maps
[mapno
]))
4076 realmaps
[nmaps1
++] = maps
[mapno
];
4078 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
4081 /* If we got more than one event, put all but the first
4082 onto this list to be read later.
4083 Return just the first event now. */
4084 Vunread_command_events
4085 = nconc2 (XCONS (value
)->cdr
, Vunread_command_events
);
4086 value
= XCONS (value
)->car
;
4088 else if (NILP (value
))
4090 if (used_mouse_menu
)
4091 *used_mouse_menu
= 1;
4094 #endif /* HAVE_X_MENU */
4095 #endif /* HAVE_X_WINDOWS */
4100 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
4106 register Lisp_Object name
;
4108 int width
= FRAME_WIDTH (selected_frame
) - 4;
4109 char *menu
= (char *) alloca (width
+ 4);
4112 Lisp_Object rest
, vector
;
4114 if (! menu_prompting
)
4117 /* Get the menu name from the first map that has one (a prompt string). */
4118 for (mapno
= 0; mapno
< nmaps
; mapno
++)
4120 name
= map_prompt (maps
[mapno
]);
4125 /* If we don't have any menus, just read a character normally. */
4129 /* Prompt string always starts with map's prompt, and a space. */
4130 strcpy (menu
, XSTRING (name
)->data
);
4131 nlength
= XSTRING (name
)->size
;
4132 menu
[nlength
++] = ':';
4133 menu
[nlength
++] = ' ';
4136 /* Start prompting at start of first map. */
4140 /* Present the documented bindings, a line at a time. */
4147 int orig_defn_macro
;
4149 /* Loop over elements of map. */
4154 /* If reached end of map, start at beginning of next map. */
4158 /* At end of last map, wrap around to first map if just starting,
4159 or end this line if already have something on it. */
4163 if (notfirst
|| nobindings
) break;
4168 /* Look at the next element of the map. */
4170 elt
= XVECTOR (vector
)->contents
[idx
];
4172 elt
= Fcar_safe (rest
);
4174 if (idx
< 0 && VECTORP (elt
))
4176 /* If we found a dense table in the keymap,
4177 advanced past it, but start scanning its contents. */
4178 rest
= Fcdr_safe (rest
);
4184 /* An ordinary element. */
4186 s
= Fcar_safe (Fcdr_safe (elt
)); /* alist */
4188 s
= Fcar_safe(elt
); /* vector */
4190 /* Ignore the element if it has no prompt string. */
4192 /* If we have room for the prompt string, add it to this line.
4193 If this is the first on the line, always add it. */
4194 else if (XSTRING (s
)->size
+ i
+ 2 < width
4199 /* Punctuate between strings. */
4202 strcpy (menu
+ i
, ", ");
4208 /* Add as much of string as fits. */
4209 thiswidth
= XSTRING (s
)->size
;
4210 if (thiswidth
+ i
> width
)
4211 thiswidth
= width
- i
;
4212 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
4218 /* If this element does not fit, end the line now,
4219 and save the element for the next line. */
4220 strcpy (menu
+ i
, "...");
4224 /* Move past this element. */
4225 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
4226 /* Handle reaching end of dense table. */
4231 rest
= Fcdr_safe (rest
);
4235 /* Prompt with that and read response. */
4238 /* Make believe its not a keyboard macro in case the help char
4239 is pressed. Help characters are not recorded because menu prompting
4240 is not used on replay.
4242 orig_defn_macro
= defining_kbd_macro
;
4243 defining_kbd_macro
= 0 ;
4245 obj
= read_char (commandflag
, 0, 0, Qnil
, 0);
4246 while (BUFFERP (obj
));
4247 defining_kbd_macro
= orig_defn_macro
;
4249 if (!INTEGERP (obj
))
4254 if (! EQ (obj
, menu_prompt_more_char
)
4255 && (!INTEGERP (menu_prompt_more_char
)
4256 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
4258 if ( defining_kbd_macro
)
4259 store_kbd_macro_char(obj
) ;
4262 /* Help char - go round again */
4266 /* Reading key sequences. */
4268 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
4269 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
4270 keymap, or nil otherwise. Return the index of the first keymap in
4271 which KEY has any binding, or NMAPS if no map has a binding.
4273 If KEY is a meta ASCII character, treat it like meta-prefix-char
4274 followed by the corresponding non-meta character. Keymaps in
4275 CURRENT with non-prefix bindings for meta-prefix-char become nil in
4278 If KEY has no bindings in any of the CURRENT maps, NEXT is left
4281 NEXT may == CURRENT. */
4284 follow_key (key
, nmaps
, current
, defs
, next
)
4286 Lisp_Object
*current
, *defs
, *next
;
4289 int i
, first_binding
;
4291 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
4292 followed by the corresponding non-meta character. */
4293 if (INTEGERP (key
) && (XINT (key
) & CHAR_META
))
4295 for (i
= 0; i
< nmaps
; i
++)
4296 if (! NILP (current
[i
]))
4299 get_keyelt (access_keymap (current
[i
], meta_prefix_char
, 1, 0));
4301 /* Note that since we pass the resulting bindings through
4302 get_keymap_1, non-prefix bindings for meta-prefix-char
4304 next
[i
] = get_keymap_1 (next
[i
], 0, 1);
4310 XSETINT (key
, XFASTINT (key
) & ~CHAR_META
);
4313 first_binding
= nmaps
;
4314 for (i
= nmaps
- 1; i
>= 0; i
--)
4316 if (! NILP (current
[i
]))
4318 defs
[i
] = get_keyelt (access_keymap (current
[i
], key
, 1, 0));
4319 if (! NILP (defs
[i
]))
4326 /* Given the set of bindings we've found, produce the next set of maps. */
4327 if (first_binding
< nmaps
)
4328 for (i
= 0; i
< nmaps
; i
++)
4329 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0, 1);
4331 return first_binding
;
4334 /* Read a sequence of keys that ends with a non prefix character,
4335 storing it in KEYBUF, a buffer of size BUFSIZE.
4337 Return the length of the key sequence stored.
4338 Return -1 if the user rejected a command menu.
4340 Echo starting immediately unless `prompt' is 0.
4342 Where a key sequence ends depends on the currently active keymaps.
4343 These include any minor mode keymaps active in the current buffer,
4344 the current buffer's local map, and the global map.
4346 If a key sequence has no other bindings, we check Vfunction_key_map
4347 to see if some trailing subsequence might be the beginning of a
4348 function key's sequence. If so, we try to read the whole function
4349 key, and substitute its symbolic name into the key sequence.
4351 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
4352 `double-' events into similar click events, if that would make them
4353 bound. We try to turn `triple-' events first into `double-' events,
4356 If we get a mouse click in a mode line, vertical divider, or other
4357 non-text area, we treat the click as if it were prefixed by the
4358 symbol denoting that area - `mode-line', `vertical-line', or
4361 If the sequence starts with a mouse click, we read the key sequence
4362 with respect to the buffer clicked on, not the current buffer.
4364 If the user switches frames in the midst of a key sequence, we put
4365 off the switch-frame event until later; the next call to
4366 read_char will return it. */
4369 read_key_sequence (keybuf
, bufsize
, prompt
)
4370 Lisp_Object
*keybuf
;
4374 int count
= specpdl_ptr
- specpdl
;
4376 /* How many keys there are in the current key sequence. */
4379 /* The length of the echo buffer when we started reading, and
4380 the length of this_command_keys when we started reading. */
4384 /* The number of keymaps we're scanning right now, and the number of
4385 keymaps we have allocated space for. */
4387 int nmaps_allocated
= 0;
4389 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
4390 the current keymaps. */
4393 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
4394 in the current keymaps, or nil where it is not a prefix. */
4395 Lisp_Object
*submaps
;
4397 /* The index in defs[] of the first keymap that has a binding for
4398 this key sequence. In other words, the lowest i such that
4399 defs[i] is non-nil. */
4402 /* If t < mock_input, then KEYBUF[t] should be read as the next
4405 We use this to recover after recognizing a function key. Once we
4406 realize that a suffix of the current key sequence is actually a
4407 function key's escape sequence, we replace the suffix with the
4408 function key's binding from Vfunction_key_map. Now keybuf
4409 contains a new and different key sequence, so the echo area,
4410 this_command_keys, and the submaps and defs arrays are wrong. In
4411 this situation, we set mock_input to t, set t to 0, and jump to
4412 restart_sequence; the loop will read keys from keybuf up until
4413 mock_input, thus rebuilding the state; and then it will resume
4414 reading characters from the keyboard. */
4417 /* If the sequence is unbound in submaps[], then
4418 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
4419 and fkey_map is its binding.
4421 These might be > t, indicating that all function key scanning
4422 should hold off until t reaches them. We do this when we've just
4423 recognized a function key, to avoid searching for the function
4424 key's again in Vfunction_key_map. */
4425 int fkey_start
= 0, fkey_end
= 0;
4426 Lisp_Object fkey_map
;
4428 /* Likewise, for key_translation_map. */
4429 int keytran_start
= 0, keytran_end
= 0;
4430 Lisp_Object keytran_map
;
4432 /* If we receive a ``switch-frame'' event in the middle of a key sequence,
4433 we put it off for later. While we're reading, we keep the event here. */
4434 Lisp_Object delayed_switch_frame
;
4436 /* See the comment below... */
4437 #if defined (GOBBLE_FIRST_EVENT)
4438 Lisp_Object first_event
;
4441 struct buffer
*starting_buffer
;
4443 /* Nonzero if we seem to have got the beginning of a binding
4444 in function_key_map. */
4445 int function_key_possible
= 0;
4446 int key_translation_possible
= 0;
4450 last_nonmenu_event
= Qnil
;
4452 delayed_switch_frame
= Qnil
;
4453 fkey_map
= Vfunction_key_map
;
4454 keytran_map
= Vkey_translation_map
;
4456 /* If there is no function-key-map, turn off function key scanning. */
4457 if (NILP (Fkeymapp (Vfunction_key_map
)))
4458 fkey_start
= fkey_end
= bufsize
+ 1;
4460 /* If there is no key-translation-map, turn off scanning. */
4461 if (NILP (Fkeymapp (Vkey_translation_map
)))
4462 keytran_start
= keytran_end
= bufsize
+ 1;
4467 echo_prompt (XSTRING (prompt
)->data
);
4468 else if (cursor_in_echo_area
&& echo_keystrokes
)
4469 /* This doesn't put in a dash if the echo buffer is empty, so
4470 you don't always see a dash hanging out in the minibuffer. */
4474 /* Record the initial state of the echo area and this_command_keys;
4475 we will need to restore them if we replay a key sequence. */
4477 echo_start
= echo_length ();
4478 keys_start
= this_command_key_count
;
4480 #if defined (GOBBLE_FIRST_EVENT)
4481 /* This doesn't quite work, because some of the things that read_char
4482 does cannot safely be bypassed. It seems too risky to try to make
4485 /* Read the first char of the sequence specially, before setting
4486 up any keymaps, in case a filter runs and switches buffers on us. */
4487 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
4489 #endif /* GOBBLE_FIRST_EVENT */
4491 /* We jump here when the key sequence has been thoroughly changed, and
4492 we need to rescan it starting from the beginning. When we jump here,
4493 keybuf[0..mock_input] holds the sequence we should reread. */
4496 starting_buffer
= current_buffer
;
4497 function_key_possible
= 0;
4498 key_translation_possible
= 0;
4500 /* Build our list of keymaps.
4501 If we recognize a function key and replace its escape sequence in
4502 keybuf with its symbol, or if the sequence starts with a mouse
4503 click and we need to switch buffers, we jump back here to rebuild
4504 the initial keymaps from the current buffer. */
4508 if (!NILP (Voverriding_local_map
))
4511 if (nmaps
> nmaps_allocated
)
4513 submaps
= (Lisp_Object
*) alloca (nmaps
* sizeof (submaps
[0]));
4514 defs
= (Lisp_Object
*) alloca (nmaps
* sizeof (defs
[0]));
4515 nmaps_allocated
= nmaps
;
4517 submaps
[0] = Voverriding_local_map
;
4521 nmaps
= current_minor_maps (0, &maps
) + 2;
4522 if (nmaps
> nmaps_allocated
)
4524 submaps
= (Lisp_Object
*) alloca (nmaps
* sizeof (submaps
[0]));
4525 defs
= (Lisp_Object
*) alloca (nmaps
* sizeof (defs
[0]));
4526 nmaps_allocated
= nmaps
;
4528 bcopy (maps
, submaps
, (nmaps
- 2) * sizeof (submaps
[0]));
4529 #ifdef USE_TEXT_PROPERTIES
4530 submaps
[nmaps
-2] = get_local_map (PT
, current_buffer
);
4532 submaps
[nmaps
-2] = current_buffer
->keymap
;
4535 submaps
[nmaps
-1] = current_global_map
;
4538 /* Find an accurate initial value for first_binding. */
4539 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
4540 if (! NILP (submaps
[first_binding
]))
4543 /* Start from the beginning in keybuf. */
4546 /* These are no-ops the first time through, but if we restart, they
4547 revert the echo area and this_command_keys to their original state. */
4548 this_command_key_count
= keys_start
;
4549 if (INTERACTIVE
&& t
< mock_input
)
4550 echo_truncate (echo_start
);
4552 /* If the best binding for the current key sequence is a keymap, or
4553 we may be looking at a function key's escape sequence, keep on
4555 while ((first_binding
< nmaps
&& ! NILP (submaps
[first_binding
]))
4556 || (first_binding
>= nmaps
4558 /* mock input is never part of a function key's sequence. */
4559 && mock_input
<= fkey_start
)
4560 || (keytran_start
< t
&& key_translation_possible
)
4561 /* Don't return in the middle of a possible function key sequence,
4562 if the only bindings we found were via case conversion.
4563 Thus, if ESC O a has a function-key-map translation
4564 and ESC o has a binding, don't return after ESC O,
4565 so that we can translate ESC O plus the next character. */
4569 int used_mouse_menu
= 0;
4571 /* Where the last real key started. If we need to throw away a
4572 key that has expanded into more than one element of keybuf
4573 (say, a mouse click on the mode line which is being treated
4574 as [mode-line (mouse-...)], then we backtrack to this point
4576 int last_real_key_start
;
4578 /* These variables are analogous to echo_start and keys_start;
4579 while those allow us to restart the entire key sequence,
4580 echo_local_start and keys_local_start allow us to throw away
4582 int echo_local_start
, keys_local_start
, local_first_binding
;
4585 error ("key sequence too long");
4588 echo_local_start
= echo_length ();
4589 keys_local_start
= this_command_key_count
;
4590 local_first_binding
= first_binding
;
4593 /* These are no-ops, unless we throw away a keystroke below and
4594 jumped back up to replay_key; in that case, these restore the
4595 variables to their original state, allowing us to replay the
4597 if (INTERACTIVE
&& t
< mock_input
)
4598 echo_truncate (echo_local_start
);
4599 this_command_key_count
= keys_local_start
;
4600 first_binding
= local_first_binding
;
4602 /* By default, assume each event is "real". */
4603 last_real_key_start
= t
;
4605 /* Does mock_input indicate that we are re-reading a key sequence? */
4609 add_command_key (key
);
4610 if (echo_keystrokes
)
4614 /* If not, we should actually read a character. */
4617 struct buffer
*buf
= current_buffer
;
4619 key
= read_char (NILP (prompt
), nmaps
, submaps
, last_nonmenu_event
,
4622 /* read_char returns t when it shows a menu and the user rejects it.
4627 /* read_char returns -1 at the end of a macro.
4628 Emacs 18 handles this by returning immediately with a
4629 zero, so that's what we'll do. */
4630 if (INTEGERP (key
) && XINT (key
) == -1)
4636 /* If the current buffer has been changed from under us, the
4637 keymap may have changed, so replay the sequence. */
4641 goto replay_sequence
;
4644 /* If we have a quit that was typed in another frame, and
4645 quit_throw_to_read_char switched buffers,
4646 replay to get the right keymap. */
4647 if (XINT (key
) == quit_char
&& current_buffer
!= starting_buffer
)
4652 goto replay_sequence
;
4658 /* Clicks in non-text areas get prefixed by the symbol
4659 in their CHAR-ADDRESS field. For example, a click on
4660 the mode line is prefixed by the symbol `mode-line'.
4662 Furthermore, key sequences beginning with mouse clicks
4663 are read using the keymaps of the buffer clicked on, not
4664 the current buffer. So we may have to switch the buffer
4667 When we turn one event into two events, we must make sure
4668 that neither of the two looks like the original--so that,
4669 if we replay the events, they won't be expanded again.
4670 If not for this, such reexpansion could happen either here
4671 or when user programs play with this-command-keys. */
4672 if (EVENT_HAS_PARAMETERS (key
))
4676 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
4677 if (EQ (kind
, Qmouse_click
))
4679 Lisp_Object window
, posn
;
4681 window
= POSN_WINDOW (EVENT_START (key
));
4682 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
4685 /* We're looking at the second event of a
4686 sequence which we expanded before. Set
4687 last_real_key_start appropriately. */
4689 last_real_key_start
= t
- 1;
4692 /* Key sequences beginning with mouse clicks are
4693 read using the keymaps in the buffer clicked on,
4694 not the current buffer. If we're at the
4695 beginning of a key sequence, switch buffers. */
4696 if (last_real_key_start
== 0
4698 && BUFFERP (XWINDOW (window
)->buffer
)
4699 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
4704 /* Arrange to go back to the original buffer once we're
4705 done reading the key sequence. Note that we can't
4706 use save_excursion_{save,restore} here, because they
4707 save point as well as the current buffer; we don't
4708 want to save point, because redisplay may change it,
4709 to accommodate a Fset_window_start or something. We
4710 don't want to do this at the top of the function,
4711 because we may get input from a subprocess which
4712 wants to change the selected window and stuff (say,
4714 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
4716 set_buffer_internal (XBUFFER (XWINDOW (window
)->buffer
));
4717 goto replay_sequence
;
4719 else if (SYMBOLP (posn
))
4721 /* Expand mode-line and scroll-bar events into two events:
4722 use posn as a fake prefix key. */
4724 if (t
+ 1 >= bufsize
)
4725 error ("key sequence too long");
4730 /* Zap the position in key, so we know that we've
4731 expanded it, and don't try to do so again. */
4732 POSN_BUFFER_POSN (EVENT_START (key
))
4733 = Fcons (posn
, Qnil
);
4737 else if (EQ (kind
, Qswitch_frame
))
4739 /* If we're at the beginning of a key sequence, go
4740 ahead and return this event. If we're in the
4741 midst of a key sequence, delay it until the end. */
4744 delayed_switch_frame
= key
;
4748 else if (CONSP (XCONS (key
)->cdr
)
4749 && CONSP (EVENT_START (key
))
4750 && CONSP (XCONS (EVENT_START (key
))->cdr
))
4754 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
4755 /* Handle menu-bar events:
4756 insert the dummy prefix event `menu-bar'. */
4757 if (EQ (posn
, Qmenu_bar
))
4759 if (t
+ 1 >= bufsize
)
4760 error ("key sequence too long");
4761 /* Run the Lucid hook. */
4762 if (!NILP (Vrun_hooks
))
4763 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
4764 /* If it has changed current-menubar from previous value,
4765 really recompute the menubar from the value. */
4766 if (! NILP (Vlucid_menu_bar_dirty_flag
))
4767 call0 (Qrecompute_lucid_menubar
);
4771 /* Zap the position in key, so we know that we've
4772 expanded it, and don't try to do so again. */
4773 POSN_BUFFER_POSN (EVENT_START (key
))
4774 = Fcons (posn
, Qnil
);
4777 goto replay_sequence
;
4779 else if (CONSP (posn
))
4781 /* We're looking at the second event of a
4782 sequence which we expanded before. Set
4783 last_real_key_start appropriately. */
4784 if (last_real_key_start
== t
&& t
> 0)
4785 last_real_key_start
= t
- 1;
4790 /* We have finally decided that KEY is something we might want
4792 first_binding
= (follow_key (key
,
4793 nmaps
- first_binding
,
4794 submaps
+ first_binding
,
4795 defs
+ first_binding
,
4796 submaps
+ first_binding
)
4799 /* If KEY wasn't bound, we'll try some fallbacks. */
4800 if (first_binding
>= nmaps
)
4804 head
= EVENT_HEAD (key
);
4805 if (EQ (head
, Vhelp_char
))
4807 read_key_sequence_cmd
= Vprefix_help_command
;
4809 last_nonmenu_event
= key
;
4815 Lisp_Object breakdown
;
4818 breakdown
= parse_modifiers (head
);
4819 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
4820 /* Attempt to reduce an unbound mouse event to a simpler
4821 event that is bound:
4822 Drags reduce to clicks.
4823 Double-clicks reduce to clicks.
4824 Triple-clicks reduce to double-clicks, then to clicks.
4825 Down-clicks are eliminated.
4826 Double-downs reduce to downs, then are eliminated.
4827 Triple-downs reduce to double-downs, then to downs,
4828 then are eliminated. */
4829 if (modifiers
& (down_modifier
| drag_modifier
4830 | double_modifier
| triple_modifier
))
4832 while (modifiers
& (down_modifier
| drag_modifier
4833 | double_modifier
| triple_modifier
))
4835 Lisp_Object new_head
, new_click
;
4836 if (modifiers
& triple_modifier
)
4837 modifiers
^= (double_modifier
| triple_modifier
);
4838 else if (modifiers
& (drag_modifier
| double_modifier
))
4839 modifiers
&= ~(drag_modifier
| double_modifier
);
4842 /* Dispose of this `down' event by simply jumping
4843 back to replay_key, to get another event.
4845 Note that if this event came from mock input,
4846 then just jumping back to replay_key will just
4847 hand it to us again. So we have to wipe out any
4850 We could delete keybuf[t] and shift everything
4851 after that to the left by one spot, but we'd also
4852 have to fix up any variable that points into
4853 keybuf, and shifting isn't really necessary
4856 Adding prefixes for non-textual mouse clicks
4857 creates two characters of mock input, and both
4858 must be thrown away. If we're only looking at
4859 the prefix now, we can just jump back to
4860 replay_key. On the other hand, if we've already
4861 processed the prefix, and now the actual click
4862 itself is giving us trouble, then we've lost the
4863 state of the keymaps we want to backtrack to, and
4864 we need to replay the whole sequence to rebuild
4867 Beyond that, only function key expansion could
4868 create more than two keys, but that should never
4869 generate mouse events, so it's okay to zero
4870 mock_input in that case too.
4872 Isn't this just the most wonderful code ever? */
4873 if (t
== last_real_key_start
)
4880 mock_input
= last_real_key_start
;
4881 goto replay_sequence
;
4886 = apply_modifiers (modifiers
, XCONS (breakdown
)->car
);
4888 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
4890 /* Look for a binding for this new key. follow_key
4891 promises that it didn't munge submaps the
4892 last time we called it, since key was unbound. */
4894 = (follow_key (new_click
,
4895 nmaps
- local_first_binding
,
4896 submaps
+ local_first_binding
,
4897 defs
+ local_first_binding
,
4898 submaps
+ local_first_binding
)
4899 + local_first_binding
);
4901 /* If that click is bound, go for it. */
4902 if (first_binding
< nmaps
)
4907 /* Otherwise, we'll leave key set to the drag event. */
4914 /* Normally, last_nonmenu_event gets the previous key we read.
4915 But when a mouse popup menu is being used,
4916 we don't update last_nonmenu_event; it continues to hold the mouse
4917 event that preceded the first level of menu. */
4918 if (!used_mouse_menu
)
4919 last_nonmenu_event
= key
;
4921 /* If the sequence is unbound, see if we can hang a function key
4922 off the end of it. We only want to scan real keyboard input
4923 for function key sequences, so if mock_input says that we're
4924 re-reading old events, don't examine it. */
4925 if (first_binding
>= nmaps
4928 Lisp_Object fkey_next
;
4930 /* Continue scan from fkey_end until we find a bound suffix.
4931 If we fail, increment fkey_start
4932 and start fkey_end from there. */
4933 while (fkey_end
< t
)
4937 key
= keybuf
[fkey_end
++];
4938 /* Look up meta-characters by prefixing them
4939 with meta_prefix_char. I hate this. */
4940 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
4945 (access_keymap (fkey_map
, meta_prefix_char
, 1, 0)),
4947 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
4950 fkey_next
= fkey_map
;
4953 = get_keyelt (access_keymap (fkey_next
, key
, 1, 0));
4955 #if 0 /* I didn't turn this on, because it might cause trouble
4956 for the mapping of return into C-m and tab into C-i. */
4957 /* Optionally don't map function keys into other things.
4958 This enables the user to redefine kp- keys easily. */
4959 if (SYMBOLP (key
) && !NILP (Vinhibit_function_key_mapping
))
4963 /* If the function key map gives a function, not an
4964 array, then call the function with no args and use
4965 its value instead. */
4966 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
4969 struct gcpro gcpro1
, gcpro2
, gcpro3
;
4973 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
4974 fkey_next
= call1 (fkey_next
, prompt
);
4976 /* If the function returned something invalid,
4977 barf--don't ignore it.
4978 (To ignore it safely, we would need to gcpro a bunch of
4979 other variables.) */
4980 if (! (VECTORP (fkey_next
) || STRINGP (fkey_next
)))
4981 error ("Function in function-key-map returns invalid key sequence");
4984 function_key_possible
= ! NILP (fkey_next
);
4986 /* If keybuf[fkey_start..fkey_end] is bound in the
4987 function key map and it's a suffix of the current
4988 sequence (i.e. fkey_end == t), replace it with
4989 the binding and restart with fkey_start at the end. */
4990 if ((VECTORP (fkey_next
) || STRINGP (fkey_next
))
4993 int len
= XFASTINT (Flength (fkey_next
));
4995 t
= fkey_start
+ len
;
4997 error ("key sequence too long");
4999 if (VECTORP (fkey_next
))
5000 bcopy (XVECTOR (fkey_next
)->contents
,
5001 keybuf
+ fkey_start
,
5002 (t
- fkey_start
) * sizeof (keybuf
[0]));
5003 else if (STRINGP (fkey_next
))
5007 for (i
= 0; i
< len
; i
++)
5008 XSETFASTINT (keybuf
[fkey_start
+ i
],
5009 XSTRING (fkey_next
)->data
[i
]);
5013 fkey_start
= fkey_end
= t
;
5014 fkey_map
= Vfunction_key_map
;
5016 /* Do pass the results through key-translation-map. */
5017 keytran_start
= keytran_end
= 0;
5018 keytran_map
= Vkey_translation_map
;
5020 goto replay_sequence
;
5023 fkey_map
= get_keymap_1 (fkey_next
, 0, 1);
5025 /* If we no longer have a bound suffix, try a new positions for
5027 if (NILP (fkey_map
))
5029 fkey_end
= ++fkey_start
;
5030 fkey_map
= Vfunction_key_map
;
5031 function_key_possible
= 0;
5036 /* Look for this sequence in key-translation-map. */
5038 Lisp_Object keytran_next
;
5040 /* Scan from keytran_end until we find a bound suffix. */
5041 while (keytran_end
< t
)
5045 key
= keybuf
[keytran_end
++];
5046 /* Look up meta-characters by prefixing them
5047 with meta_prefix_char. I hate this. */
5048 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
5053 (access_keymap (keytran_map
, meta_prefix_char
, 1, 0)),
5055 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
5058 keytran_next
= keytran_map
;
5061 = get_keyelt (access_keymap (keytran_next
, key
, 1, 0));
5063 /* If the key translation map gives a function, not an
5064 array, then call the function with no args and use
5065 its value instead. */
5066 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
5067 && keytran_end
== t
)
5069 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5073 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
5074 keytran_next
= call1 (keytran_next
, prompt
);
5076 /* If the function returned something invalid,
5077 barf--don't ignore it.
5078 (To ignore it safely, we would need to gcpro a bunch of
5079 other variables.) */
5080 if (! (VECTORP (keytran_next
) || STRINGP (keytran_next
)))
5081 error ("Function in key-translation-map returns invalid key sequence");
5084 key_translation_possible
= ! NILP (keytran_next
);
5086 /* If keybuf[keytran_start..keytran_end] is bound in the
5087 key translation map and it's a suffix of the current
5088 sequence (i.e. keytran_end == t), replace it with
5089 the binding and restart with keytran_start at the end. */
5090 if ((VECTORP (keytran_next
) || STRINGP (keytran_next
))
5091 && keytran_end
== t
)
5093 int len
= XFASTINT (Flength (keytran_next
));
5095 t
= keytran_start
+ len
;
5097 error ("key sequence too long");
5099 if (VECTORP (keytran_next
))
5100 bcopy (XVECTOR (keytran_next
)->contents
,
5101 keybuf
+ keytran_start
,
5102 (t
- keytran_start
) * sizeof (keybuf
[0]));
5103 else if (STRINGP (keytran_next
))
5107 for (i
= 0; i
< len
; i
++)
5108 XSETFASTINT (keybuf
[keytran_start
+ i
],
5109 XSTRING (keytran_next
)->data
[i
]);
5113 keytran_start
= keytran_end
= t
;
5114 keytran_map
= Vkey_translation_map
;
5116 /* Don't pass the results of key-translation-map
5117 through function-key-map. */
5118 fkey_start
= fkey_end
= t
;
5119 fkey_map
= Vkey_translation_map
;
5121 goto replay_sequence
;
5124 keytran_map
= get_keymap_1 (keytran_next
, 0, 1);
5126 /* If we no longer have a bound suffix, try a new positions for
5128 if (NILP (keytran_map
))
5130 keytran_end
= ++keytran_start
;
5131 keytran_map
= Vkey_translation_map
;
5132 key_translation_possible
= 0;
5137 /* If KEY is not defined in any of the keymaps,
5138 and cannot be part of a function key or translation,
5139 and is an upper case letter
5140 use the corresponding lower-case letter instead. */
5141 if (first_binding
== nmaps
&& ! function_key_possible
5142 && ! key_translation_possible
5144 && ((((XINT (key
) & 0x3ffff)
5145 < XSTRING (current_buffer
->downcase_table
)->size
)
5146 && UPPERCASEP (XINT (key
) & 0x3ffff))
5147 || (XINT (key
) & shift_modifier
)))
5149 if (XINT (key
) & shift_modifier
)
5150 XSETINT (key
, XINT (key
) & ~shift_modifier
);
5152 XSETINT (key
, (DOWNCASE (XINT (key
) & 0x3ffff)
5153 | (XINT (key
) & ~0x3ffff)));
5155 keybuf
[t
- 1] = key
;
5157 goto replay_sequence
;
5161 read_key_sequence_cmd
= (first_binding
< nmaps
5162 ? defs
[first_binding
]
5166 unread_switch_frame
= delayed_switch_frame
;
5167 unbind_to (count
, Qnil
);
5169 /* Occasionally we fabricate events, perhaps by expanding something
5170 according to function-key-map, or by adding a prefix symbol to a
5171 mouse click in the scroll bar or modeline. In this cases, return
5172 the entire generated key sequence, even if we hit an unbound
5173 prefix or a definition before the end. This means that you will
5174 be able to push back the event properly, and also means that
5175 read-key-sequence will always return a logical unit.
5178 for (; t
< mock_input
; t
++)
5180 if (echo_keystrokes
)
5181 echo_char (keybuf
[t
]);
5182 add_command_key (keybuf
[t
]);
5188 #if 0 /* This doc string is too long for some compilers.
5189 This commented-out definition serves for DOC. */
5190 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 2, 0,
5191 "Read a sequence of keystrokes and return as a string or vector.\n\
5192 The sequence is sufficient to specify a non-prefix command in the\n\
5193 current local and global maps.\n\
5195 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
5196 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
5197 as a continuation of the previous key.\n\
5199 A C-g typed while in this function is treated like any other character,\n\
5200 and `quit-flag' is not set.\n\
5202 If the key sequence starts with a mouse click, then the sequence is read\n\
5203 using the keymaps of the buffer of the window clicked in, not the buffer\n\
5204 of the selected window as normal.\n\
5206 `read-key-sequence' drops unbound button-down events, since you normally\n\
5207 only care about the click or drag events which follow them. If a drag\n\
5208 or multi-click event is unbound, but the corresponding click event would\n\
5209 be bound, `read-key-sequence' turns the event into a click event at the\n\
5210 drag's starting position. This means that you don't have to distinguish\n\
5211 between click and drag, double, or triple events unless you want to.\n\
5213 `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\
5214 lines separating windows, and scroll bars with imaginary keys\n\
5215 `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\
5217 If the user switches frames in the middle of a key sequence, the\n\
5218 frame-switch event is put off until after the current key sequence.\n\
5220 `read-key-sequence' checks `function-key-map' for function key\n\
5221 sequences, where they wouldn't conflict with ordinary bindings. See\n\
5222 `function-key-map' for more details.")
5223 (prompt
, continue_echo
)
5226 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 2, 0,
5228 (prompt
, continue_echo
)
5229 Lisp_Object prompt
, continue_echo
;
5231 Lisp_Object keybuf
[30];
5233 struct gcpro gcpro1
, gcpro2
;
5236 CHECK_STRING (prompt
, 0);
5239 bzero (keybuf
, sizeof keybuf
);
5241 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
5243 if (NILP (continue_echo
))
5244 this_command_key_count
= 0;
5246 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])), prompt
);
5254 return make_event_array (i
, keybuf
);
5257 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 2, 0,
5258 "Execute CMD as an editor command.\n\
5259 CMD must be a symbol that satisfies the `commandp' predicate.\n\
5260 Optional second arg RECORD-FLAG non-nil\n\
5261 means unconditionally put this command in `command-history'.\n\
5262 Otherwise, that is done only if an arg is read using the minibuffer.")
5264 Lisp_Object cmd
, record
;
5266 register Lisp_Object final
;
5267 register Lisp_Object tem
;
5268 Lisp_Object prefixarg
;
5269 struct backtrace backtrace
;
5270 extern int debug_on_next_call
;
5272 prefixarg
= Vprefix_arg
, Vprefix_arg
= Qnil
;
5273 Vcurrent_prefix_arg
= prefixarg
;
5274 debug_on_next_call
= 0;
5278 tem
= Fget (cmd
, Qdisabled
);
5279 if (!NILP (tem
) && !NILP (Vrun_hooks
))
5280 return call1 (Vrun_hooks
, Qdisabled_command_hook
);
5285 final
= Findirect_function (cmd
);
5287 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
5288 do_autoload (final
, cmd
);
5293 if (STRINGP (final
) || VECTORP (final
))
5295 /* If requested, place the macro in the command history. For
5296 other sorts of commands, call-interactively takes care of
5300 = Fcons (Fcons (Qexecute_kbd_macro
,
5301 Fcons (final
, Fcons (prefixarg
, Qnil
))),
5304 return Fexecute_kbd_macro (final
, prefixarg
);
5306 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
5308 backtrace
.next
= backtrace_list
;
5309 backtrace_list
= &backtrace
;
5310 backtrace
.function
= &Qcall_interactively
;
5311 backtrace
.args
= &cmd
;
5312 backtrace
.nargs
= 1;
5313 backtrace
.evalargs
= 0;
5315 tem
= Fcall_interactively (cmd
, record
);
5317 backtrace_list
= backtrace
.next
;
5323 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
5325 "Read function name, then read its arguments and call it.")
5327 Lisp_Object prefixarg
;
5329 Lisp_Object function
;
5331 Lisp_Object saved_keys
;
5332 struct gcpro gcpro1
;
5334 saved_keys
= Fvector (this_command_key_count
,
5335 XVECTOR (this_command_keys
)->contents
);
5337 GCPRO1 (saved_keys
);
5339 if (EQ (prefixarg
, Qminus
))
5341 else if (CONSP (prefixarg
) && XINT (XCONS (prefixarg
)->car
) == 4)
5342 strcpy (buf
, "C-u ");
5343 else if (CONSP (prefixarg
) && INTEGERP (XCONS (prefixarg
)->car
))
5344 sprintf (buf
, "%d ", XINT (XCONS (prefixarg
)->car
));
5345 else if (INTEGERP (prefixarg
))
5346 sprintf (buf
, "%d ", XINT (prefixarg
));
5348 /* This isn't strictly correct if execute-extended-command
5349 is bound to anything else. Perhaps it should use
5350 this_command_keys? */
5351 strcat (buf
, "M-x ");
5353 /* Prompt with buf, and then read a string, completing from and
5354 restricting to the set of all defined commands. Don't provide
5355 any initial input. Save the command read on the extended-command
5357 function
= Fcompleting_read (build_string (buf
),
5358 Vobarray
, Qcommandp
,
5359 Qt
, Qnil
, Qextended_command_history
);
5361 /* Set this_command_keys to the concatenation of saved_keys and
5362 function, followed by a RET. */
5364 struct Lisp_String
*str
;
5369 this_command_key_count
= 0;
5371 keys
= XVECTOR (saved_keys
)->contents
;
5372 for (i
= 0; i
< XVECTOR (saved_keys
)->size
; i
++)
5373 add_command_key (keys
[i
]);
5375 str
= XSTRING (function
);
5376 for (i
= 0; i
< str
->size
; i
++)
5378 XSETFASTINT (tem
, str
->data
[i
]);
5379 add_command_key (tem
);
5382 XSETFASTINT (tem
, '\015');
5383 add_command_key (tem
);
5388 function
= Fintern (function
, Qnil
);
5389 Vprefix_arg
= prefixarg
;
5390 this_command
= function
;
5392 return Fcommand_execute (function
, Qt
);
5396 detect_input_pending ()
5399 get_input_pending (&input_pending
);
5401 return input_pending
;
5404 /* This is called in some cases before a possible quit.
5405 It cases the next call to detect_input_pending to recompute input_pending.
5406 So calling this function unnecessarily can't do any harm. */
5407 clear_input_pending ()
5412 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
5413 "T if command input is currently available with no waiting.\n\
5414 Actually, the value is nil only if we can be sure that no input is available.")
5417 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1)
5420 return detect_input_pending () ? Qt
: Qnil
;
5423 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
5424 "Return vector of last 100 events, not counting those from keyboard macros.")
5427 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
5430 if (total_keys
< NUM_RECENT_KEYS
)
5431 return Fvector (total_keys
, keys
);
5434 val
= Fvector (NUM_RECENT_KEYS
, keys
);
5435 bcopy (keys
+ recent_keys_index
,
5436 XVECTOR (val
)->contents
,
5437 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
5439 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
5440 recent_keys_index
* sizeof (Lisp_Object
));
5445 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
5446 "Return the key sequence that invoked this command.\n\
5447 The value is a string or a vector.")
5450 return make_event_array (this_command_key_count
,
5451 XVECTOR (this_command_keys
)->contents
);
5454 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
5455 "Return the current depth in recursive edits.")
5459 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
5463 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
5464 "FOpen dribble file: ",
5465 "Start writing all keyboard characters to a dribble file called FILE.\n\
5466 If FILE is nil, close any open dribble file.")
5477 file
= Fexpand_file_name (file
, Qnil
);
5478 dribble
= fopen (XSTRING (file
)->data
, "w");
5483 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
5484 "Discard the contents of the terminal input buffer.\n\
5485 Also cancel any kbd macro being defined.")
5488 defining_kbd_macro
= 0;
5489 update_mode_lines
++;
5491 Vunread_command_events
= Qnil
;
5492 unread_command_char
= -1;
5494 discard_tty_input ();
5496 /* Without the cast, GCC complains that this assignment loses the
5497 volatile qualifier of kbd_store_ptr. Is there anything wrong
5499 kbd_fetch_ptr
= (struct input_event
*) kbd_store_ptr
;
5500 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
5506 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
5507 "Stop Emacs and return to superior process. You can resume later.\n\
5508 If `cannot-suspend' is non-nil, or if the system doesn't support job\n\
5509 control, run a subshell instead.\n\n\
5510 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
5511 to be read as terminal input by Emacs's parent, after suspension.\n\
5513 Before suspending, run the normal hook `suspend-hook'.\n\
5514 After resumption run the normal hook `suspend-resume-hook'.\n\
5516 Some operating systems cannot stop the Emacs process and resume it later.\n\
5517 On such systems, Emacs starts a subshell instead of suspending.")
5519 Lisp_Object stuffstring
;
5522 int count
= specpdl_ptr
- specpdl
;
5523 int old_height
, old_width
;
5525 struct gcpro gcpro1
, gcpro2
;
5526 extern init_sys_modes ();
5528 if (!NILP (stuffstring
))
5529 CHECK_STRING (stuffstring
, 0);
5531 /* Run the functions in suspend-hook. */
5532 if (!NILP (Vrun_hooks
))
5533 call1 (Vrun_hooks
, intern ("suspend-hook"));
5535 GCPRO1 (stuffstring
);
5536 get_frame_size (&old_width
, &old_height
);
5538 /* sys_suspend can get an error if it tries to fork a subshell
5539 and the system resources aren't available for that. */
5540 record_unwind_protect (init_sys_modes
, 0);
5541 stuff_buffered_input (stuffstring
);
5546 unbind_to (count
, Qnil
);
5548 /* Check if terminal/window size has changed.
5549 Note that this is not useful when we are running directly
5550 with a window system; but suspend should be disabled in that case. */
5551 get_frame_size (&width
, &height
);
5552 if (width
!= old_width
|| height
!= old_height
)
5553 change_frame_size (selected_frame
, height
, width
, 0, 0);
5555 /* Run suspend-resume-hook. */
5556 if (!NILP (Vrun_hooks
))
5557 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
5563 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
5564 Then in any case stuff anything Emacs has read ahead and not used. */
5566 stuff_buffered_input (stuffstring
)
5567 Lisp_Object stuffstring
;
5569 register unsigned char *p
;
5571 /* stuff_char works only in BSD, versions 4.2 and up. */
5574 if (STRINGP (stuffstring
))
5578 p
= XSTRING (stuffstring
)->data
;
5579 count
= XSTRING (stuffstring
)->size
;
5584 /* Anything we have read ahead, put back for the shell to read. */
5585 while (kbd_fetch_ptr
!= kbd_store_ptr
)
5587 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
5588 kbd_fetch_ptr
= kbd_buffer
;
5589 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
5590 stuff_char (kbd_fetch_ptr
->code
);
5591 kbd_fetch_ptr
->kind
= no_event
;
5592 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_fetch_ptr
5599 #endif /* BSD and not BSD4_1 */
5602 set_waiting_for_input (time_to_clear
)
5603 EMACS_TIME
*time_to_clear
;
5605 input_available_clear_time
= time_to_clear
;
5607 /* Tell interrupt_signal to throw back to read_char, */
5608 waiting_for_input
= 1;
5610 /* If interrupt_signal was called before and buffered a C-g,
5611 make it run again now, to avoid timing error. */
5612 if (!NILP (Vquit_flag
))
5613 quit_throw_to_read_char ();
5616 clear_waiting_for_input ()
5618 /* Tell interrupt_signal not to throw back to read_char, */
5619 waiting_for_input
= 0;
5620 input_available_clear_time
= 0;
5623 /* This routine is called at interrupt level in response to C-G.
5624 If interrupt_input, this is the handler for SIGINT.
5625 Otherwise, it is called from kbd_buffer_store_event,
5626 in handling SIGIO or SIGTINT.
5628 If `waiting_for_input' is non zero, then unless `echoing' is nonzero,
5629 immediately throw back to read_char.
5631 Otherwise it sets the Lisp variable quit-flag not-nil.
5632 This causes eval to throw, when it gets a chance.
5633 If quit-flag is already non-nil, it stops the job right away. */
5639 /* Must preserve main program's value of errno. */
5640 int old_errno
= errno
;
5643 if (!read_socket_hook
&& NILP (Vwindow_system
))
5645 /* USG systems forget handlers when they are used;
5646 must reestablish each time */
5647 signal (SIGINT
, interrupt_signal
);
5648 signal (SIGQUIT
, interrupt_signal
);
5654 if (!NILP (Vquit_flag
) && FRAME_TERMCAP_P (selected_frame
))
5659 #ifdef SIGTSTP /* Support possible in later USG versions */
5661 * On systems which can suspend the current process and return to the original
5662 * shell, this command causes the user to end up back at the shell.
5663 * The "Auto-save" and "Abort" questions are not asked until
5664 * the user elects to return to emacs, at which point he can save the current
5665 * job and either dump core or continue.
5670 if (sys_suspend () == -1)
5672 printf ("Not running as a subprocess;\n");
5673 printf ("you can continue or abort.\n");
5676 /* Perhaps should really fork an inferior shell?
5677 But that would not provide any way to get back
5678 to the original shell, ever. */
5679 printf ("No support for stopping a process on this operating system;\n");
5680 printf ("you can continue or abort.\n");
5681 #endif /* not VMS */
5682 #endif /* not SIGTSTP */
5684 /* We must remain inside the screen area when the internal terminal
5685 is used. Note that [Enter] is not echoed by dos. */
5688 printf ("Auto-save? (y or n) ");
5690 if (((c
= getchar ()) & ~040) == 'Y')
5692 Fdo_auto_save (Qt
, Qnil
);
5694 printf ("\r\nAuto-save done");
5695 #else /* not MSDOS */
5696 printf ("Auto-save done\n");
5697 #endif /* not MSDOS */
5699 while (c
!= '\n') c
= getchar ();
5701 printf ("\r\nAbort? (y or n) ");
5702 #else /* not MSDOS */
5704 printf ("Abort (and enter debugger)? (y or n) ");
5706 printf ("Abort (and dump core)? (y or n) ");
5707 #endif /* not VMS */
5708 #endif /* not MSDOS */
5710 if (((c
= getchar ()) & ~040) == 'Y')
5712 while (c
!= '\n') c
= getchar ();
5714 printf ("\r\nContinuing...\r\n");
5715 #else /* not MSDOS */
5716 printf ("Continuing...\n");
5717 #endif /* not MSDOS */
5723 /* If executing a function that wants to be interrupted out of
5724 and the user has not deferred quitting by binding `inhibit-quit'
5725 then quit right away. */
5726 if (immediate_quit
&& NILP (Vinhibit_quit
))
5730 Fsignal (Qquit
, Qnil
);
5733 /* Else request quit when it's safe */
5737 if (waiting_for_input
&& !echoing
)
5738 quit_throw_to_read_char ();
5743 /* Handle a C-g by making read_char return C-g. */
5745 quit_throw_to_read_char ()
5747 quit_error_check ();
5749 /* Prevent another signal from doing this before we finish. */
5750 clear_waiting_for_input ();
5753 Vunread_command_events
= Qnil
;
5754 unread_command_char
= -1;
5756 #ifdef POLL_FOR_INPUT
5757 /* May be > 1 if in recursive minibuffer. */
5758 if (poll_suppress_count
== 0)
5762 if (FRAMEP (internal_last_event_frame
)
5763 && XFRAME (internal_last_event_frame
) != selected_frame
)
5764 Fhandle_switch_frame (make_lispy_switch_frame (internal_last_event_frame
));
5767 _longjmp (getcjmp
, 1);
5770 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
5771 "Set mode of reading keyboard input.\n\
5772 First arg INTERRUPT non-nil means use input interrupts;\n\
5773 nil means use CBREAK mode.\n\
5774 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
5775 (no effect except in CBREAK mode).\n\
5776 Third arg META t means accept 8-bit input (for a Meta key).\n\
5777 META nil means ignore the top bit, on the assumption it is parity.\n\
5778 Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\
5779 Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\
5780 See also `current-input-mode'.")
5781 (interrupt
, flow
, meta
, quit
)
5782 Lisp_Object interrupt
, flow
, meta
, quit
;
5785 && (!INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400))
5786 error ("set-input-mode: QUIT must be an ASCII character");
5788 #ifdef POLL_FOR_INPUT
5794 /* Note SIGIO has been undef'd if FIONREAD is missing. */
5795 #ifdef NO_SOCK_SIGIO
5796 if (read_socket_hook
)
5797 interrupt_input
= 0; /* No interrupts if reading from a socket. */
5799 #endif /* NO_SOCK_SIGIO */
5800 interrupt_input
= !NILP (interrupt
);
5801 #else /* not SIGIO */
5802 interrupt_input
= 0;
5803 #endif /* not SIGIO */
5804 /* Our VMS input only works by interrupts, as of now. */
5806 interrupt_input
= 1;
5808 flow_control
= !NILP (flow
);
5811 else if (EQ (meta
, Qt
))
5816 /* Don't let this value be out of range. */
5817 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
5821 #ifdef POLL_FOR_INPUT
5822 poll_suppress_count
= 1;
5828 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
5829 "Return information about the way Emacs currently reads keyboard input.\n\
5830 The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
5831 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\
5832 nil, Emacs is using CBREAK mode.\n\
5833 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\
5834 terminal; this does not apply if Emacs uses interrupt-driven input.\n\
5835 META is t if accepting 8-bit input with 8th bit as Meta flag.\n\
5836 META nil means ignoring the top bit, on the assumption it is parity.\n\
5837 META is neither t nor nil if accepting 8-bit input and using\n\
5838 all 8 bits as the character code.\n\
5839 QUIT is the character Emacs currently uses to quit.\n\
5840 The elements of this list correspond to the arguments of\n\
5846 val
[0] = interrupt_input
? Qt
: Qnil
;
5847 val
[1] = flow_control
? Qt
: Qnil
;
5848 val
[2] = meta_key
== 2 ? make_number (0) : meta_key
== 1 ? Qt
: Qnil
;
5849 XSETFASTINT (val
[3], quit_char
);
5851 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
5857 /* This is correct before outermost invocation of the editor loop */
5858 command_loop_level
= -1;
5860 quit_char
= Ctl ('g');
5861 Vunread_command_events
= Qnil
;
5862 unread_command_char
= -1;
5864 recent_keys_index
= 0;
5865 kbd_fetch_ptr
= kbd_buffer
;
5866 kbd_store_ptr
= kbd_buffer
;
5867 do_mouse_tracking
= 0;
5871 /* This means that command_loop_1 won't try to select anything the first
5873 internal_last_event_frame
= Qnil
;
5874 Vlast_event_frame
= internal_last_event_frame
;
5877 /* If we're running a dumped Emacs, we need to clear out
5878 kbd_buffer_frame_or_window, in case some events got into it
5881 If we're running an undumped Emacs, it hasn't been initialized by
5882 syms_of_keyboard yet. */
5884 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
5886 if (!noninteractive
&& !read_socket_hook
&& NILP (Vwindow_system
))
5888 signal (SIGINT
, interrupt_signal
);
5889 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
5890 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
5891 SIGQUIT and we can't tell which one it will give us. */
5892 signal (SIGQUIT
, interrupt_signal
);
5893 #endif /* HAVE_TERMIO */
5895 /* Note SIGIO has been undef'd if FIONREAD is missing. */
5897 if (!noninteractive
)
5898 signal (SIGIO
, input_available_signal
);
5901 /* Use interrupt input by default, if it works and noninterrupt input
5902 has deficiencies. */
5904 #ifdef INTERRUPT_INPUT
5905 interrupt_input
= 1;
5907 interrupt_input
= 0;
5910 /* Our VMS input only works by interrupts, as of now. */
5912 interrupt_input
= 1;
5918 if (keyboard_init_hook
)
5919 (*keyboard_init_hook
) ();
5921 #ifdef POLL_FOR_INPUT
5922 poll_suppress_count
= 1;
5927 /* This type's only use is in syms_of_keyboard, to initialize the
5928 event header symbols and put properties on them. */
5935 struct event_head head_table
[] = {
5936 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
5937 &Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
,
5938 &Qswitch_frame
, "switch-frame", &Qswitch_frame
,
5939 &Qdelete_frame
, "delete-frame", &Qdelete_frame
,
5944 Qdisabled_command_hook
= intern ("disabled-command-hook");
5945 staticpro (&Qdisabled_command_hook
);
5947 Qself_insert_command
= intern ("self-insert-command");
5948 staticpro (&Qself_insert_command
);
5950 Qforward_char
= intern ("forward-char");
5951 staticpro (&Qforward_char
);
5953 Qbackward_char
= intern ("backward-char");
5954 staticpro (&Qbackward_char
);
5956 Qdisabled
= intern ("disabled");
5957 staticpro (&Qdisabled
);
5959 Qundefined
= intern ("undefined");
5960 staticpro (&Qundefined
);
5962 Qpre_command_hook
= intern ("pre-command-hook");
5963 staticpro (&Qpre_command_hook
);
5965 Qpost_command_hook
= intern ("post-command-hook");
5966 staticpro (&Qpost_command_hook
);
5968 Qcommand_hook_internal
= intern ("command-hook-internal");
5969 staticpro (&Qcommand_hook_internal
);
5971 Qfunction_key
= intern ("function-key");
5972 staticpro (&Qfunction_key
);
5973 Qmouse_click
= intern ("mouse-click");
5974 staticpro (&Qmouse_click
);
5976 Qmenu_enable
= intern ("menu-enable");
5977 staticpro (&Qmenu_enable
);
5979 Qmode_line
= intern ("mode-line");
5980 staticpro (&Qmode_line
);
5981 Qvertical_line
= intern ("vertical-line");
5982 staticpro (&Qvertical_line
);
5983 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
5984 staticpro (&Qvertical_scroll_bar
);
5985 Qmenu_bar
= intern ("menu-bar");
5986 staticpro (&Qmenu_bar
);
5988 Qabove_handle
= intern ("above-handle");
5989 staticpro (&Qabove_handle
);
5990 Qhandle
= intern ("handle");
5991 staticpro (&Qhandle
);
5992 Qbelow_handle
= intern ("below-handle");
5993 staticpro (&Qbelow_handle
);
5995 Qevent_kind
= intern ("event-kind");
5996 staticpro (&Qevent_kind
);
5997 Qevent_symbol_elements
= intern ("event-symbol-elements");
5998 staticpro (&Qevent_symbol_elements
);
5999 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
6000 staticpro (&Qevent_symbol_element_mask
);
6001 Qmodifier_cache
= intern ("modifier-cache");
6002 staticpro (&Qmodifier_cache
);
6004 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
6005 staticpro (&Qrecompute_lucid_menubar
);
6006 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
6007 staticpro (&Qactivate_menubar_hook
);
6009 Qpolling_period
= intern ("polling-period");
6010 staticpro (&Qpolling_period
);
6013 struct event_head
*p
;
6015 for (p
= head_table
;
6016 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
6019 *p
->var
= intern (p
->name
);
6021 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
6022 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
6026 button_down_location
= Fmake_vector (make_number (NUM_MOUSE_BUTTONS
), Qnil
);
6027 staticpro (&button_down_location
);
6031 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
6033 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
6034 for (i
= 0; i
< len
; i
++)
6035 if (modifier_names
[i
])
6036 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
6037 staticpro (&modifier_symbols
);
6040 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
6041 staticpro (&recent_keys
);
6043 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
6044 staticpro (&this_command_keys
);
6046 Qextended_command_history
= intern ("extended-command-history");
6047 Fset (Qextended_command_history
, Qnil
);
6048 staticpro (&Qextended_command_history
);
6050 kbd_buffer_frame_or_window
6051 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
6052 staticpro (&kbd_buffer_frame_or_window
);
6054 accent_key_syms
= Qnil
;
6055 staticpro (&accent_key_syms
);
6057 func_key_syms
= Qnil
;
6058 staticpro (&func_key_syms
);
6060 system_key_syms
= Qnil
;
6061 staticpro (&system_key_syms
);
6064 staticpro (&mouse_syms
);
6066 unread_switch_frame
= Qnil
;
6067 staticpro (&unread_switch_frame
);
6069 defsubr (&Sread_key_sequence
);
6070 defsubr (&Srecursive_edit
);
6071 defsubr (&Strack_mouse
);
6072 defsubr (&Sinput_pending_p
);
6073 defsubr (&Scommand_execute
);
6074 defsubr (&Srecent_keys
);
6075 defsubr (&Sthis_command_keys
);
6076 defsubr (&Ssuspend_emacs
);
6077 defsubr (&Sabort_recursive_edit
);
6078 defsubr (&Sexit_recursive_edit
);
6079 defsubr (&Srecursion_depth
);
6080 defsubr (&Stop_level
);
6081 defsubr (&Sdiscard_input
);
6082 defsubr (&Sopen_dribble_file
);
6083 defsubr (&Sset_input_mode
);
6084 defsubr (&Scurrent_input_mode
);
6085 defsubr (&Sexecute_extended_command
);
6087 DEFVAR_LISP ("last-command-char", &last_command_char
,
6088 "Last input event that was part of a command.");
6090 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char
,
6091 "Last input event that was part of a command.");
6093 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
6094 "Last input event in a command, except for mouse menu events.\n\
6095 Mouse menus give back keys that don't look like mouse events;\n\
6096 this variable holds the actual mouse event that led to the menu,\n\
6097 so that you can determine whether the command was run by mouse or not.");
6099 DEFVAR_LISP ("last-input-char", &last_input_char
,
6100 "Last input event.");
6102 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char
,
6103 "Last input event.");
6105 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
6106 "List of objects to be read as next command input events.");
6108 DEFVAR_INT ("unread-command-char", &unread_command_char
,
6109 "If not -1, an object to be read as next command input event.");
6111 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
6112 "Meta-prefix character code. Meta-foo as command input\n\
6113 turns into this character followed by foo.");
6114 XSETINT (meta_prefix_char
, 033);
6116 DEFVAR_LISP ("last-command", &last_command
,
6117 "The last command executed. Normally a symbol with a function definition,\n\
6118 but can be whatever was found in the keymap, or whatever the variable\n\
6119 `this-command' was set to by that command.");
6120 last_command
= Qnil
;
6122 DEFVAR_LISP ("this-command", &this_command
,
6123 "The command now being executed.\n\
6124 The command can set this variable; whatever is put here\n\
6125 will be in `last-command' during the following command.");
6126 this_command
= Qnil
;
6128 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
6129 "*Number of keyboard input characters between auto-saves.\n\
6130 Zero means disable autosaving due to number of characters typed.");
6131 auto_save_interval
= 300;
6133 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
6134 "*Number of seconds idle time before auto-save.\n\
6135 Zero or nil means disable auto-saving due to idleness.\n\
6136 After auto-saving due to this many seconds of idle time,\n\
6137 Emacs also does a garbage collection if that seems to be warranted.");
6138 XSETFASTINT (Vauto_save_timeout
, 30);
6140 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes
,
6141 "*Nonzero means echo unfinished commands after this many seconds of pause.");
6142 echo_keystrokes
= 1;
6144 DEFVAR_INT ("polling-period", &polling_period
,
6145 "*Interval between polling for input during Lisp execution.\n\
6146 The reason for polling is to make C-g work to stop a running program.\n\
6147 Polling is needed only when using X windows and SIGIO does not work.\n\
6148 Polling is automatically disabled in all other cases.");
6151 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
6152 "*Maximum time between mouse clicks to make a double-click.\n\
6153 Measured in milliseconds. nil means disable double-click recognition;\n\
6154 t means double-clicks have no time limit and are detected\n\
6155 by position only.");
6156 Vdouble_click_time
= make_number (500);
6158 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
6159 "*Non-nil means inhibit local map menu bar menus.");
6160 inhibit_local_menu_bar_menus
= 0;
6162 DEFVAR_INT ("num-input-keys", &num_input_keys
,
6163 "*Number of complete keys read from the keyboard so far.");
6166 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
6167 "*The frame in which the most recently read event occurred.\n\
6168 If the last event came from a keyboard macro, this is set to `macro'.");
6169 Vlast_event_frame
= Qnil
;
6171 DEFVAR_LISP ("help-char", &Vhelp_char
,
6172 "Character to recognize as meaning Help.\n\
6173 When it is read, do `(eval help-form)', and display result if it's a string.\n\
6174 If the value of `help-form' is nil, this char can be read normally.");
6175 XSETINT (Vhelp_char
, Ctl ('H'));
6177 DEFVAR_LISP ("help-form", &Vhelp_form
,
6178 "Form to execute when character `help-char' is read.\n\
6179 If the form returns a string, that string is displayed.\n\
6180 If `help-form' is nil, the help char is not recognized.");
6183 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
6184 "Command to run when `help-char' character follows a prefix key.\n\
6185 This command is used only when there is no actual binding\n\
6186 for that character after that prefix key.");
6187 Vprefix_help_command
= Qnil
;
6189 DEFVAR_LISP ("top-level", &Vtop_level
,
6190 "Form to evaluate when Emacs starts up.\n\
6191 Useful to set before you dump a modified Emacs.");
6194 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
6195 "String used as translate table for keyboard input, or nil.\n\
6196 Each character is looked up in this string and the contents used instead.\n\
6197 If string is of length N, character codes N and up are untranslated.");
6198 Vkeyboard_translate_table
= Qnil
;
6200 DEFVAR_LISP ("key-translation-map", &Vkey_translation_map
,
6201 "Keymap of key translations that can override keymaps.\n\
6202 This keymap works like `function-key-map', but comes after that,\n\
6203 and applies even for keys that have ordinary bindings.");
6204 Vkey_translation_map
= Qnil
;
6206 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
6207 "Non-nil means to always spawn a subshell instead of suspending,\n\
6208 even if the operating system has support for stopping a process.");
6211 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
6212 "Non-nil means prompt with menus when appropriate.\n\
6213 This is done when reading from a keymap that has a prompt string,\n\
6214 for elements that have prompt strings.\n\
6215 The menu is displayed on the screen\n\
6216 if X menus were enabled at configuration\n\
6217 time and the previous event was a mouse click prefix key.\n\
6218 Otherwise, menu prompting uses the echo area.");
6221 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
6222 "Character to see next line of menu prompt.\n\
6223 Type this character while in a menu prompt to rotate around the lines of it.");
6224 XSETINT (menu_prompt_more_char
, ' ');
6226 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
6227 "A mask of additional modifier keys to use with every keyboard character.\n\
6228 Emacs applies the modifiers of the character stored here to each keyboard\n\
6229 character it reads. For example, after evaluating the expression\n\
6230 (setq extra-keyboard-modifiers ?\C-x)\n\
6231 all input characters will have the control modifier applied to them.\n\
6233 Note that the character ?\C-@, equivalent to the integer zero, does\n\
6234 not count as a control character; rather, it counts as a character\n\
6235 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\
6236 cancels any modification.");
6237 extra_keyboard_modifiers
= 0;
6239 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
6240 "If an editing command sets this to t, deactivate the mark afterward.\n\
6241 The command loop sets this to nil before each command,\n\
6242 and tests the value when the command returns.\n\
6243 Buffer modification stores t in this variable.");
6244 Vdeactivate_mark
= Qnil
;
6246 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
6247 "Temporary storage of pre-command-hook or post-command-hook.");
6248 Vcommand_hook_internal
= Qnil
;
6250 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
6251 "Normal hook run before each command is executed.\n\
6252 While the hook is run, its value is temporarily set to nil\n\
6253 to avoid an unbreakable infinite loop if a hook function gets an error.\n\
6254 As a result, a hook function cannot straightforwardly alter the value of\n\
6255 `pre-command-hook'. See the Emacs Lisp manual for a way of\n\
6256 implementing hook functions that alter the set of hook functions.");
6257 Vpre_command_hook
= Qnil
;
6259 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
6260 "Normal hook run after each command is executed.\n\
6261 While the hook is run, its value is temporarily set to nil\n\
6262 to avoid an unbreakable infinite loop if a hook function gets an error.\n\
6263 As a result, a hook function cannot straightforwardly alter the value of\n\
6264 `post-command-hook'. See the Emacs Lisp manual for a way of\n\
6265 implementing hook functions that alter the set of hook functions.");
6266 Vpost_command_hook
= Qnil
;
6268 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
6269 "t means menu bar, specified Lucid style, needs to be recomputed.");
6270 Vlucid_menu_bar_dirty_flag
= Qnil
;
6272 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
6273 "List of menu bar items to move to the end of the menu bar.\n\
6274 The elements of the list are event types that may have menu bar bindings.");
6275 Vmenu_bar_final_items
= Qnil
;
6277 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
6278 "Keymap that overrides all other local keymaps.\n\
6279 If this variable is non-nil, it is used as a keymap instead of the\n\
6280 buffer's local map, and the minor mode keymaps and text property keymaps.");
6281 Voverriding_local_map
= Qnil
;
6283 DEFVAR_BOOL ("track-mouse", &do_mouse_tracking
,
6284 "*Non-nil means generate motion events for mouse motion.");
6286 DEFVAR_LISP ("system-key-alist", &Vsystem_key_alist
,
6287 "Alist of system-specific X windows key symbols.\n\
6288 Each element should have the form (N . SYMBOL) where N is the\n\
6289 numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\
6290 and SYMBOL is its name.");
6291 Vsystem_key_alist
= Qnil
;
6293 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
6294 "List of deferred actions to be performed at a later time.\n\
6295 The precise format isn't relevant here; we just check whether it is nil.");
6296 Vdeferred_action_list
= Qnil
;
6298 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
6299 "Function to call to handle deferred actions, after each command.\n\
6300 This function is called with no arguments after each command\n\
6301 whenever `deferred-action-list' is non-nil.");
6302 Vdeferred_action_function
= Qnil
;
6307 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
6308 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
6309 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
6310 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
6311 initial_define_key (meta_map
, 'x', "execute-extended-command");