1 /* Keyboard and mouse input; editor command loop.
2 Copyright (C) 1985, 1986, 1987, 1988, 1989, 1993 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"
44 #include <sys/ioctl.h>
47 #include "syssignal.h"
53 /* Variables for blockinput.h: */
55 /* Non-zero if interrupt input is blocked right now. */
56 int interrupt_input_blocked
;
58 /* Nonzero means an input interrupt has arrived
59 during the current critical section. */
60 int interrupt_input_pending
;
64 extern Lisp_Object Vmouse_grabbed
;
66 /* Make all keyboard buffers much bigger when using X windows. */
67 #define KBD_BUFFER_SIZE 4096
68 #else /* No X-windows, character input */
69 #define KBD_BUFFER_SIZE 256
70 #endif /* No X-windows */
72 /* Following definition copied from eval.c */
76 struct backtrace
*next
;
77 Lisp_Object
*function
;
78 Lisp_Object
*args
; /* Points to vector of args. */
79 int nargs
; /* length of vector. If nargs is UNEVALLED,
80 args points to slot holding list of
85 /* Non-nil disable property on a command means
86 do not execute it; call disabled-command-hook's value instead. */
87 Lisp_Object Qdisabled
, Vdisabled_command_hook
;
89 #define NUM_RECENT_KEYS (100)
90 int recent_keys_index
; /* Index for storing next element into recent_keys */
91 int total_keys
; /* Total number of elements stored into recent_keys */
92 Lisp_Object recent_keys
; /* A vector, holding the last 100 keystrokes */
94 /* Vector holding the key sequence that invoked the current command.
95 It is reused for each command, and it may be longer than the current
96 sequence; this_command_key_count indicates how many elements
97 actually mean something.
98 It's easier to staticpro a single Lisp_Object than an array. */
99 Lisp_Object this_command_keys
;
100 int this_command_key_count
;
102 extern int minbuf_level
;
104 extern struct backtrace
*backtrace_list
;
106 /* Nonzero means do menu prompting. */
107 static int menu_prompting
;
109 /* Character to see next line of menu prompt. */
110 static Lisp_Object menu_prompt_more_char
;
112 /* For longjmp to where kbd input is being done. */
113 static jmp_buf getcjmp
;
115 /* True while doing kbd input. */
116 int waiting_for_input
;
118 /* True while displaying for echoing. Delays C-g throwing. */
121 /* Nonzero means C-G should cause immediate error-signal. */
124 /* Character to recognize as the help char. */
125 Lisp_Object Vhelp_char
;
127 /* Form to execute when help char is typed. */
128 Lisp_Object Vhelp_form
;
130 /* Command to run when the help character follows a prefix key. */
131 Lisp_Object Vprefix_help_command
;
133 /* Character that causes a quit. Normally C-g.
135 If we are running on an ordinary terminal, this must be an ordinary
136 ASCII char, since we want to make it our interrupt character.
138 If we are not running on an ordinary terminal, it still needs to be
139 an ordinary ASCII char. This character needs to be recognized in
140 the input interrupt handler. At this point, the keystroke is
141 represented as a struct input_event, while the desired quit
142 character is specified as a lispy event. The mapping from struct
143 input_events to lispy events cannot run in an interrupt handler,
144 and the reverse mapping is difficult for anything but ASCII
147 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
151 extern Lisp_Object current_global_map
;
152 extern int minibuf_level
;
154 /* Current depth in recursive edits. */
155 int command_loop_level
;
157 /* Total number of times command_loop has read a key sequence. */
160 /* Last input character read as a command. */
161 Lisp_Object last_command_char
;
163 /* Last input character read as a command, not counting menus
164 reached by the mouse. */
165 Lisp_Object last_nonmenu_event
;
167 /* Last input character read for any purpose. */
168 Lisp_Object last_input_char
;
170 /* If not Qnil, a list of objects to be read as subsequent command input. */
171 Lisp_Object unread_command_events
;
173 /* If not -1, an event to be read as subsequent command input. */
174 int unread_command_char
;
176 /* If not Qnil, this is a switch-frame event which we decided to put
177 off until the end of a key sequence. This should be read as the
178 next command input, after any unread_command_events.
180 read_key_sequence uses this to delay switch-frame events until the
181 end of the key sequence; Fread_char uses it to put off switch-frame
182 events until a non-ASCII event is acceptable as input. */
183 Lisp_Object unread_switch_frame
;
185 /* A mask of extra modifier bits to put into every keyboard char. */
186 int extra_keyboard_modifiers
;
188 /* Char to use as prefix when a meta character is typed in.
189 This is bound on entry to minibuffer in case ESC is changed there. */
191 Lisp_Object meta_prefix_char
;
193 /* Last size recorded for a current buffer which is not a minibuffer. */
194 static int last_non_minibuf_size
;
196 /* Number of idle seconds before an auto-save and garbage collection. */
197 static Lisp_Object Vauto_save_timeout
;
199 /* Total number of times read_char has returned. */
202 /* Total number of times read_char has returned, outside of macros. */
203 int num_nonmacro_input_chars
;
205 /* Auto-save automatically when this many characters have been typed
206 since the last time. */
208 static int auto_save_interval
;
210 /* Value of num_nonmacro_input_chars as of last auto save. */
214 /* Last command executed by the editor command loop, not counting
215 commands that set the prefix argument. */
217 Lisp_Object last_command
;
219 /* The command being executed by the command loop.
220 Commands may set this, and the value set will be copied into last_command
221 instead of the actual command. */
222 Lisp_Object this_command
;
225 /* The frame in which the last input event occurred, or Qmacro if the
226 last event came from a macro. We use this to determine when to
227 generate switch-frame events. This may be cleared by functions
228 like Fselect_frame, to make sure that a switch-frame event is
229 generated by the next character. */
230 Lisp_Object internal_last_event_frame
;
232 /* A user-visible version of the above, intended to allow users to
233 figure out where the last event came from, if the event doesn't
234 carry that information itself (i.e. if it was a character). */
235 Lisp_Object Vlast_event_frame
;
238 /* The timestamp of the last input event we received from the X server.
239 X Windows wants this for selection ownership. */
240 unsigned long last_event_timestamp
;
242 Lisp_Object Qself_insert_command
;
243 Lisp_Object Qforward_char
;
244 Lisp_Object Qbackward_char
;
246 /* read_key_sequence stores here the command definition of the
247 key sequence that it reads. */
248 Lisp_Object read_key_sequence_cmd
;
250 /* Form to evaluate (if non-nil) when Emacs is started. */
251 Lisp_Object Vtop_level
;
253 /* User-supplied string to translate input characters through. */
254 Lisp_Object Vkeyboard_translate_table
;
256 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
257 extern Lisp_Object Vfunction_key_map
;
259 /* Non-nil means deactivate the mark at end of this command. */
260 Lisp_Object Vdeactivate_mark
;
262 /* Menu bar specified in Lucid Emacs fashion. */
264 Lisp_Object Vlucid_menu_bar_dirty_flag
;
265 Lisp_Object Qrecompute_lucid_menubar
, Qactivate_menubar_hook
;
267 /* Hooks to run before and after each command. */
268 Lisp_Object Qpre_command_hook
, Qpost_command_hook
;
269 Lisp_Object Vpre_command_hook
, Vpost_command_hook
;
271 /* File in which we write all commands we read. */
274 /* Nonzero if input is available. */
277 /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
278 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
282 extern char *pending_malloc_warning
;
284 /* Circular buffer for pre-read keyboard input. */
285 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
287 /* Vector to GCPRO the frames and windows mentioned in kbd_buffer.
289 The interrupt-level event handlers will never enqueue an event on a
290 frame which is not in Vframe_list, and once an event is dequeued,
291 internal_last_event_frame or the event itself points to the frame.
294 But while the event is sitting in the queue, it's completely
295 unprotected. Suppose the user types one command which will run for
296 a while and then delete a frame, and then types another event at
297 the frame that will be deleted, before the command gets around to
298 it. Suppose there are no references to this frame elsewhere in
299 Emacs, and a GC occurs before the second event is dequeued. Now we
300 have an event referring to a freed frame, which will crash Emacs
303 Similar things happen when an event on a scroll bar is enqueued; the
304 window may be deleted while the event is in the queue.
306 So, we use this vector to protect the frame_or_window field in the
307 event queue. That way, they'll be dequeued as dead frames or
308 windows, but still valid lisp objects.
310 If kbd_buffer[i].kind != no_event, then
311 (XVECTOR (kbd_buffer_frame_or_window)->contents[i]
312 == kbd_buffer[i].frame_or_window. */
313 static Lisp_Object kbd_buffer_frame_or_window
;
315 /* Pointer to next available character in kbd_buffer.
316 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
317 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the
318 next available char is in kbd_buffer[0]. */
319 static struct input_event
*kbd_fetch_ptr
;
321 /* Pointer to next place to store character in kbd_buffer. This
322 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
323 character should go in kbd_buffer[0]. */
327 static struct input_event
*kbd_store_ptr
;
329 /* The above pair of variables forms a "queue empty" flag. When we
330 enqueue a non-hook event, we increment kbd_write_count. When we
331 dequeue a non-hook event, we increment kbd_read_count. We say that
332 there is input available iff the two counters are not equal.
334 Why not just have a flag set and cleared by the enqueuing and
335 dequeuing functions? Such a flag could be screwed up by interrupts
336 at inopportune times. */
338 /* If this flag is non-zero, we check mouse_moved to see when the
339 mouse moves, and motion events will appear in the input stream. If
340 it is zero, mouse motion is ignored. */
341 static int do_mouse_tracking
;
343 /* The window system handling code should set this if the mouse has
344 moved since the last call to the mouse_position_hook. Calling that
345 hook should clear this. Code assumes that if this is set, it can
346 call mouse_position_hook to get the promised position, so don't set
347 it unless you're prepared to substantiate the claim! */
350 /* True iff there is an event in kbd_buffer, or if mouse tracking is
351 enabled and there is a new mouse position in the mouse movement
352 buffer. Note that if this is false, that doesn't mean that there
353 is readable input; all the events in the queue might be button-up
354 events, and do_mouse_tracking might be off. */
355 #define EVENT_QUEUES_EMPTY \
356 ((kbd_fetch_ptr == kbd_store_ptr) && (!do_mouse_tracking || !mouse_moved))
359 /* Symbols to head events. */
360 Lisp_Object Qmouse_movement
;
361 Lisp_Object Qscroll_bar_movement
;
362 Lisp_Object Qswitch_frame
;
364 /* Symbols to denote kinds of events. */
365 Lisp_Object Qfunction_key
;
366 Lisp_Object Qmouse_click
;
367 /* Lisp_Object Qmouse_movement; - also an event header */
369 /* Properties of event headers. */
370 Lisp_Object Qevent_kind
;
371 Lisp_Object Qevent_symbol_elements
;
373 Lisp_Object Qmenu_enable
;
375 /* An event header symbol HEAD may have a property named
376 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
377 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
378 mask of modifiers applied to it. If present, this is used to help
379 speed up parse_modifiers. */
380 Lisp_Object Qevent_symbol_element_mask
;
382 /* An unmodified event header BASE may have a property named
383 Qmodifier_cache, which is an alist mapping modifier masks onto
384 modified versions of BASE. If present, this helps speed up
386 Lisp_Object Qmodifier_cache
;
388 /* Symbols to use for parts of windows. */
389 Lisp_Object Qmode_line
;
390 Lisp_Object Qvertical_line
;
391 Lisp_Object Qvertical_scroll_bar
;
392 Lisp_Object Qmenu_bar
;
394 extern Lisp_Object Qmenu_enable
;
396 Lisp_Object
recursive_edit_unwind (), command_loop ();
397 Lisp_Object
Fthis_command_keys ();
399 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
401 EMACS_TIME
*input_available_clear_time
;
403 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
404 Default is 1 if INTERRUPT_INPUT is defined. */
407 /* Nonzero while interrupts are temporarily deferred during redisplay. */
408 int interrupts_deferred
;
410 /* nonzero means use ^S/^Q for flow control. */
413 /* Allow m- file to inhibit use of FIONREAD. */
414 #ifdef BROKEN_FIONREAD
418 /* We are unable to use interrupts if FIONREAD is not available,
419 so flush SIGIO so we won't try. */
426 /* If we support X Windows, and won't get an interrupt when input
427 arrives from the server, poll periodically so we can detect C-g. */
428 #ifdef HAVE_X_WINDOWS
430 #define POLL_FOR_INPUT
434 /* Global variable declarations. */
436 /* Function for init_keyboard to call with no args (if nonzero). */
437 void (*keyboard_init_hook
) ();
439 static int read_avail_input ();
440 static void get_input_pending ();
441 static Lisp_Object
read_char_menu_prompt ();
443 /* > 0 if we are to echo keystrokes. */
444 static int echo_keystrokes
;
446 /* Nonzero means echo each character as typed. */
447 static int immediate_echo
;
449 /* The text we're echoing in the modeline - partial key sequences,
450 usually. '\0'-terminated. This really shouldn't have a fixed size. */
451 static char echobuf
[300];
453 /* Where to append more text to echobuf if we want to. */
454 static char *echoptr
;
456 #define min(a,b) ((a)<(b)?(a):(b))
457 #define max(a,b) ((a)>(b)?(a):(b))
459 /* Install the string STR as the beginning of the string of echoing,
460 so that it serves as a prompt for the next character.
461 Also start echoing. */
466 int len
= strlen (str
);
467 if (len
> sizeof echobuf
- 4)
468 len
= sizeof echobuf
- 4;
469 bcopy (str
, echobuf
, len
);
470 echoptr
= echobuf
+ len
;
476 /* Add C to the echo string, if echoing is going on.
477 C can be a character, which is printed prettily ("M-C-x" and all that
478 jazz), or a symbol, whose name is printed. */
483 extern char *push_key_description ();
492 /* If someone has passed us a composite event, use its head symbol. */
495 if (XTYPE (c
) == Lisp_Int
)
497 if (ptr
- echobuf
> sizeof echobuf
- 6)
500 ptr
= push_key_description (XINT (c
), ptr
);
502 else if (XTYPE (c
) == Lisp_Symbol
)
504 struct Lisp_String
*name
= XSYMBOL (c
)->name
;
505 if (((ptr
- echobuf
) + name
->size
+ 4) > sizeof echobuf
)
507 bcopy (name
->data
, ptr
, name
->size
);
511 if (echoptr
== echobuf
&& EQ (c
, Vhelp_char
))
513 strcpy (ptr
, " (Type ? for further options)");
524 /* Temporarily add a dash to the end of the echo string if it's not
525 empty, so that it serves as a mini-prompt for the very next character. */
529 if (!immediate_echo
&& echoptr
== echobuf
)
531 /* Do nothing if not echoing at all. */
535 /* Put a dash at the end of the buffer temporarily,
536 but make it go away when the next character is added. */
543 /* Display the current echo string, and begin echoing if not already
553 for (i
= 0; i
< this_command_key_count
; i
++)
554 echo_char (XVECTOR (this_command_keys
)->contents
[i
]);
562 if (waiting_for_input
&& !NILP (Vquit_flag
))
563 quit_throw_to_read_char ();
566 /* Turn off echoing, for the start of a new command. */
574 /* Return the length of the current echo string. */
579 return echoptr
- echobuf
;
582 /* Truncate the current echo message to its first LEN chars.
583 This and echo_char get used by read_key_sequence when the user
584 switches frames while entering a key sequence. */
591 echoptr
= echobuf
+ len
;
595 /* Functions for manipulating this_command_keys. */
597 add_command_key (key
)
600 int size
= XVECTOR (this_command_keys
)->size
;
602 if (this_command_key_count
>= size
)
604 Lisp_Object new_keys
= Fmake_vector (make_number (size
* 2), Qnil
);
606 bcopy (XVECTOR (this_command_keys
)->contents
,
607 XVECTOR (new_keys
)->contents
,
608 size
* sizeof (Lisp_Object
));
610 this_command_keys
= new_keys
;
613 XVECTOR (this_command_keys
)->contents
[this_command_key_count
++] = key
;
619 int count
= specpdl_ptr
- specpdl
;
622 if (command_loop_level
> 0)
624 specbind (Qstandard_output
, Qt
);
625 specbind (Qstandard_input
, Qt
);
628 val
= command_loop ();
630 Fsignal (Qquit
, Qnil
);
632 return unbind_to (count
, Qnil
);
635 /* When an auto-save happens, record the "time", and don't do again soon. */
638 last_auto_save
= num_nonmacro_input_chars
;
641 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
642 "Invoke the editor command loop recursively.\n\
643 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
644 that tells this function to return.\n\
645 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
646 This function is called by the editor initialization to begin editing.")
649 int count
= specpdl_ptr
- specpdl
;
652 command_loop_level
++;
653 update_mode_lines
= 1;
655 record_unwind_protect (recursive_edit_unwind
,
657 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
661 return unbind_to (count
, Qnil
);
665 recursive_edit_unwind (buffer
)
669 Fset_buffer (buffer
);
671 command_loop_level
--;
672 update_mode_lines
= 1;
680 Lisp_Object errmsg
, tail
, errname
, file_error
;
687 Vstandard_output
= Qt
;
688 Vstandard_input
= Qt
;
689 Vexecuting_macro
= Qnil
;
690 echo_area_glyphs
= 0;
692 /* If the window system or terminal frame hasn't been initialized
693 yet, or we're not interactive, it's best to dump this message out
694 to stderr and exit. */
695 if (! FRAME_MESSAGE_BUF (selected_frame
)
697 stream
= Qexternal_debugging_output
;
705 errname
= Fcar (data
);
707 if (EQ (errname
, Qerror
))
710 if (!CONSP (data
)) data
= Qnil
;
711 errmsg
= Fcar (data
);
716 errmsg
= Fget (errname
, Qerror_message
);
717 file_error
= Fmemq (Qfile_error
,
718 Fget (errname
, Qerror_conditions
));
721 /* Print an error message including the data items.
722 This is done by printing it into a scratch buffer
723 and then making a copy of the text in the buffer. */
725 if (!CONSP (data
)) data
= Qnil
;
729 /* For file-error, make error message by concatenating
730 all the data items. They are all strings. */
731 if (!NILP (file_error
) && !NILP (tail
))
732 errmsg
= XCONS (tail
)->car
, tail
= XCONS (tail
)->cdr
;
734 if (XTYPE (errmsg
) == Lisp_String
)
735 Fprinc (errmsg
, stream
);
737 write_string_1 ("peculiar error", -1, stream
);
739 for (i
= 0; CONSP (tail
); tail
= Fcdr (tail
), i
++)
741 write_string_1 (i
? ", " : ": ", 2, stream
);
742 if (!NILP (file_error
))
743 Fprinc (Fcar (tail
), stream
);
745 Fprin1 (Fcar (tail
), stream
);
749 /* If the window system or terminal frame hasn't been initialized
750 yet, or we're in -batch mode, this error should cause Emacs to exit. */
751 if (! FRAME_MESSAGE_BUF (selected_frame
)
755 Fkill_emacs (make_number (-1));
760 Vinhibit_quit
= Qnil
;
761 return make_number (0);
764 Lisp_Object
command_loop_1 ();
765 Lisp_Object
command_loop_2 ();
766 Lisp_Object
top_level_1 ();
768 /* Entry to editor-command-loop.
769 This level has the catches for exiting/returning to editor command loop.
770 It returns nil to exit recursive edit, t to abort it. */
775 if (command_loop_level
> 0 || minibuf_level
> 0)
777 return internal_catch (Qexit
, command_loop_2
, Qnil
);
782 internal_catch (Qtop_level
, top_level_1
, Qnil
);
783 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
785 /* End of file in -batch run causes exit here. */
791 /* Here we catch errors in execution of commands within the
792 editing loop, and reenter the editing loop.
793 When there is an error, cmd_error runs and returns a non-nil
794 value to us. A value of nil means that cmd_loop_1 itself
795 returned due to end of file (or end of kbd macro). */
800 register Lisp_Object val
;
803 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
812 return Feval (Vtop_level
);
818 /* On entry to the outer level, run the startup file */
819 if (!NILP (Vtop_level
))
820 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
821 else if (!NILP (Vpurify_flag
))
822 message ("Bare impure Emacs (standard Lisp code not loaded)");
824 message ("Bare Emacs (standard Lisp code not loaded)");
828 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
829 "Exit all recursive editing levels.")
832 Fthrow (Qtop_level
, Qnil
);
835 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
836 "Exit from the innermost recursive edit or minibuffer.")
839 if (command_loop_level
> 0 || minibuf_level
> 0)
840 Fthrow (Qexit
, Qnil
);
842 error ("No recursive edit is in progress");
845 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
846 "Abort the command that requested this recursive edit or minibuffer input.")
849 if (command_loop_level
> 0 || minibuf_level
> 0)
852 error ("No recursive edit is in progress");
855 /* This is the actual command reading loop,
856 sans error-handling encapsulation. */
858 Lisp_Object
Fcommand_execute ();
859 static int read_key_sequence ();
864 Lisp_Object cmd
, tem
;
867 Lisp_Object keybuf
[30];
872 struct buffer
*prev_buffer
;
875 Vdeactivate_mark
= Qnil
;
876 waiting_for_input
= 0;
879 /* Don't clear out last_command at the beginning of a macro. */
880 if (XTYPE (Vexecuting_macro
) != Lisp_String
)
885 this_command_key_count
= 0;
889 /* Install chars successfully executed in kbd macro. */
891 if (defining_kbd_macro
&& NILP (Vprefix_arg
))
892 finalize_kbd_macro_chars ();
894 /* Make sure the current window's buffer is selected. */
895 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
896 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
898 /* Display any malloc warning that just came out. Use while because
899 displaying one warning can cause another. */
901 while (pending_malloc_warning
)
902 display_malloc_warning ();
906 Vdeactivate_mark
= Qnil
;
908 /* If minibuffer on and echo area in use,
909 wait 2 sec and redraw minibuffer. */
911 if (minibuf_level
&& echo_area_glyphs
)
913 /* Bind inhibit-quit to t so that C-g gets read in
914 rather than quitting back to the minibuffer. */
915 int count
= specpdl_ptr
- specpdl
;
916 specbind (Qinhibit_quit
, Qt
);
917 Fsit_for (make_number (2), Qnil
, Qnil
);
918 unbind_to (count
, Qnil
);
920 echo_area_glyphs
= 0;
922 if (!NILP (Vquit_flag
))
925 unread_command_events
= Fcons (make_number (quit_char
), Qnil
);
930 alloca (0); /* Cause a garbage collection now */
931 /* Since we can free the most stuff here. */
932 #endif /* C_ALLOCA */
936 /* Select the frame that the last event came from. Usually,
937 switch-frame events will take care of this, but if some lisp
938 code swallows a switch-frame event, we'll fix things up here.
939 Is this a good idea? */
940 if (XTYPE (internal_last_event_frame
) == Lisp_Frame
941 && XFRAME (internal_last_event_frame
) != selected_frame
)
942 Fselect_frame (internal_last_event_frame
, Qnil
);
945 /* If it has changed current-menubar from previous value,
946 really recompute the menubar from the value. */
947 if (! NILP (Vlucid_menu_bar_dirty_flag
))
948 call0 (Qrecompute_lucid_menubar
);
950 #if 0 /* This is done in xdisp.c now. */
952 for (tem
= Vframe_list
; CONSP (tem
); tem
= XCONS (tem
)->cdr
)
954 struct frame
*f
= XFRAME (XCONS (tem
)->car
);
955 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
957 /* If the user has switched buffers or windows, we need to
958 recompute to reflect the new bindings. But we'll
959 recompute when update_mode_lines is set too; that means
960 that people can use force-mode-line-update to request
961 that the menu bar be recomputed. The adverse effect on
962 the rest of the redisplay algorithm is about the same as
963 windows_or_buffers_changed anyway. */
964 if (windows_or_buffers_changed
966 || (XFASTINT (w
->last_modified
) < MODIFF
967 && (XFASTINT (w
->last_modified
)
968 <= XBUFFER (w
->buffer
)->save_modified
)))
970 struct buffer
*prev
= current_buffer
;
971 current_buffer
= XBUFFER (w
->buffer
);
972 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items ();
973 current_buffer
= prev
;
976 #endif /* MULTI_FRAME */
979 /* Read next key sequence; i gets its length. */
980 i
= read_key_sequence (keybuf
, (sizeof keybuf
/ sizeof (keybuf
[0])), 0);
984 /* Now we have read a key sequence of length I,
985 or else I is 0 and we found end of file. */
987 if (i
== 0) /* End of file -- happens only in */
988 return Qnil
; /* a kbd macro, at the end. */
990 last_command_char
= keybuf
[i
- 1];
992 /* If the previous command tried to force a specific window-start,
993 forget about that, in case this command moves point far away
994 from that position. */
995 XWINDOW (selected_window
)->force_start
= Qnil
;
997 cmd
= read_key_sequence_cmd
;
998 if (!NILP (Vexecuting_macro
))
1000 if (!NILP (Vquit_flag
))
1002 Vexecuting_macro
= Qt
;
1003 QUIT
; /* Make some noise. */
1004 /* Will return since macro now empty. */
1008 /* Do redisplay processing after this command except in special
1009 cases identified below that set no_redisplay to 1. */
1012 prev_buffer
= current_buffer
;
1013 prev_modiff
= MODIFF
;
1015 /* Execute the command. */
1018 if (!NILP (Vpre_command_hook
))
1019 call1 (Vrun_hooks
, Qpre_command_hook
);
1021 if (NILP (this_command
))
1023 /* nil means key is undefined. */
1025 defining_kbd_macro
= 0;
1026 update_mode_lines
= 1;
1032 if (NILP (Vprefix_arg
) && ! no_direct
)
1034 /* Recognize some common commands in common situations and
1035 do them directly. */
1036 if (EQ (this_command
, Qforward_char
) && point
< ZV
)
1038 struct Lisp_Vector
*dp
1039 = window_display_table (XWINDOW (selected_window
));
1040 lose
= FETCH_CHAR (point
);
1043 ? (XTYPE (DISP_CHAR_VECTOR (dp
, lose
)) != Lisp_Vector
1044 && XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1)
1045 : (lose
>= 0x20 && lose
< 0x7f))
1046 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1048 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1050 && !windows_or_buffers_changed
1051 && EQ (current_buffer
->selective_display
, Qnil
)
1052 && !detect_input_pending ()
1053 && NILP (Vexecuting_macro
))
1054 no_redisplay
= direct_output_forward_char (1);
1057 else if (EQ (this_command
, Qbackward_char
) && point
> BEGV
)
1059 struct Lisp_Vector
*dp
1060 = window_display_table (XWINDOW (selected_window
));
1062 lose
= FETCH_CHAR (point
);
1064 ? (XTYPE (DISP_CHAR_VECTOR (dp
, lose
)) != Lisp_Vector
1065 && XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1)
1066 : (lose
>= 0x20 && lose
< 0x7f))
1067 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1069 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1071 && !windows_or_buffers_changed
1072 && EQ (current_buffer
->selective_display
, Qnil
)
1073 && !detect_input_pending ()
1074 && NILP (Vexecuting_macro
))
1075 no_redisplay
= direct_output_forward_char (-1);
1078 else if (EQ (this_command
, Qself_insert_command
)
1079 /* Try this optimization only on ascii keystrokes. */
1080 && XTYPE (last_command_char
) == Lisp_Int
)
1082 unsigned char c
= XINT (last_command_char
);
1084 if (NILP (Vexecuting_macro
) &&
1085 !EQ (minibuf_window
, selected_window
))
1087 if (!nonundocount
|| nonundocount
>= 20)
1094 lose
= (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1096 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1098 || MODIFF
<= current_buffer
->save_modified
1099 || windows_or_buffers_changed
1100 || !EQ (current_buffer
->selective_display
, Qnil
)
1101 || detect_input_pending ()
1102 || !NILP (Vexecuting_macro
);
1103 if (internal_self_insert (c
, 0))
1109 (point
== ZV
|| FETCH_CHAR (point
) == '\n'))
1111 struct Lisp_Vector
*dp
1112 = window_display_table (XWINDOW (selected_window
));
1117 Lisp_Object obj
= DISP_CHAR_VECTOR (dp
, lose
);
1119 if (XTYPE (obj
) == Lisp_Vector
1120 && XVECTOR (obj
)->size
== 1
1121 && (XTYPE (obj
= XVECTOR (obj
)->contents
[0])
1124 direct_output_for_insert (XINT (obj
));
1128 if (lose
>= 0x20 && lose
<= 0x7e)
1129 no_redisplay
= direct_output_for_insert (lose
);
1136 /* Here for a command that isn't executed directly */
1139 if (NILP (Vprefix_arg
))
1141 Fcommand_execute (this_command
, Qnil
);
1146 if (!NILP (Vpost_command_hook
))
1147 call1 (Vrun_hooks
, Qpost_command_hook
);
1149 /* If there is a prefix argument,
1150 1) We don't want last_command to be ``universal-argument''
1151 (that would be dumb), so don't set last_command,
1152 2) we want to leave echoing on so that the prefix will be
1153 echoed as part of this key sequence, so don't call
1155 3) we want to leave this_command_key_count non-zero, so that
1156 read_char will realize that it is re-reading a character, and
1157 not echo it a second time. */
1158 if (NILP (Vprefix_arg
))
1160 last_command
= this_command
;
1162 this_command_key_count
= 0;
1165 if (!NILP (current_buffer
->mark_active
))
1167 if (!NILP (Vdeactivate_mark
) && !NILP (Vtransient_mark_mode
))
1169 current_buffer
->mark_active
= Qnil
;
1170 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
1172 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
1173 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
1178 /* Number of seconds between polling for input. */
1181 /* Nonzero means polling for input is temporarily suppressed. */
1182 int poll_suppress_count
;
1184 #ifdef POLL_FOR_INPUT
1185 int polling_for_input
;
1187 /* Handle an alarm once each second and read pending input
1188 so as to handle a C-g if it comces in. */
1191 input_poll_signal ()
1193 if (interrupt_input_blocked
== 0
1194 && !waiting_for_input
)
1195 read_avail_input (0);
1196 signal (SIGALRM
, input_poll_signal
);
1197 alarm (polling_period
);
1202 /* Begin signals to poll for input, if they are appropriate.
1203 This function is called unconditionally from various places. */
1207 #ifdef POLL_FOR_INPUT
1208 if (read_socket_hook
)
1210 poll_suppress_count
--;
1211 if (poll_suppress_count
== 0)
1213 signal (SIGALRM
, input_poll_signal
);
1214 polling_for_input
= 1;
1215 alarm (polling_period
);
1221 /* Turn off polling. */
1225 #ifdef POLL_FOR_INPUT
1226 if (read_socket_hook
)
1228 if (poll_suppress_count
== 0)
1230 polling_for_input
= 0;
1233 poll_suppress_count
++;
1238 /* Applying the control modifier to CHARACTER. */
1243 /* Save the upper bits here. */
1244 int upper
= c
& ~0177;
1248 /* Everything in the columns containing the upper-case letters
1249 denotes a control character. */
1250 if (c
>= 0100 && c
< 0140)
1254 /* Set the shift modifier for a control char
1255 made from a shifted letter. But only for letters! */
1256 if (oc
>= 'A' && oc
<= 'Z')
1257 c
|= shift_modifier
;
1260 /* The lower-case letters denote control characters too. */
1261 else if (c
>= 'a' && c
<= 'z')
1264 /* Include the bits for control and shift
1265 only if the basic ASCII code can't indicate them. */
1269 /* Replace the high bits. */
1270 c
|= (upper
& ~ctrl_modifier
);
1277 /* Input of single characters from keyboard */
1279 Lisp_Object
print_help ();
1280 static Lisp_Object
kbd_buffer_get_event ();
1282 /* read a character from the keyboard; call the redisplay if needed */
1283 /* commandflag 0 means do not do auto-saving, but do do redisplay.
1284 -1 means do not do redisplay, but do do autosaving.
1287 /* The arguments MAPS and NMAPS are for menu prompting.
1288 MAPS is an array of keymaps; NMAPS is the length of MAPS.
1290 PREV_EVENT is the previous input event, or nil if we are reading
1291 the first event of a key sequence.
1293 If USED_MOUSE_MENU is non-zero, then we set *USED_MOUSE_MENU to 1
1294 if we used a mouse menu to read the input, or zero otherwise. If
1295 USED_MOUSE_MENU is zero, *USED_MOUSE_MENU is left alone. */
1298 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
)
1302 Lisp_Object prev_event
;
1303 int *used_mouse_menu
;
1305 register Lisp_Object c
;
1309 if (CONSP (unread_command_events
))
1311 c
= XCONS (unread_command_events
)->car
;
1312 unread_command_events
= XCONS (unread_command_events
)->cdr
;
1314 if (this_command_key_count
== 0)
1320 if (unread_command_char
!= -1)
1322 XSET (c
, Lisp_Int
, unread_command_char
);
1323 unread_command_char
= -1;
1325 if (this_command_key_count
== 0)
1331 if (!NILP (Vexecuting_macro
))
1334 /* We set this to Qmacro; since that's not a frame, nobody will
1335 try to switch frames on us, and the selected window will
1338 Since this event came from a macro, it would be misleading to
1339 leave internal_last_event_frame set to wherever the last
1340 real event came from. Normally, a switch-frame event selects
1341 internal_last_event_frame after each command is read, but
1342 events read from a macro should never cause a new frame to be
1344 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
1347 /* Exit the macro if we are at the end.
1348 Also, some things replace the macro with t
1349 to force an early exit. */
1350 if (EQ (Vexecuting_macro
, Qt
)
1351 || executing_macro_index
>= XFASTINT (Flength (Vexecuting_macro
)))
1353 XSET (c
, Lisp_Int
, -1);
1357 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
1358 if (XTYPE (Vexecuting_macro
) == Lisp_String
1359 && (XINT (c
) & 0x80))
1360 XFASTINT (c
) = CHAR_META
| (XINT (c
) & ~0x80);
1362 executing_macro_index
++;
1367 if (!NILP (unread_switch_frame
))
1369 c
= unread_switch_frame
;
1370 unread_switch_frame
= Qnil
;
1372 /* This event should make it into this_command_keys, and get echoed
1373 again, so we go to reread_first, rather than reread. */
1377 /* Save outer setjmp data, in case called recursively. */
1378 save_getcjmp (save_jump
);
1382 if (commandflag
>= 0 && !input_pending
&& !detect_input_pending ())
1385 if (_setjmp (getcjmp
))
1387 XSET (c
, Lisp_Int
, quit_char
);
1389 XSET (internal_last_event_frame
, Lisp_Frame
, selected_frame
);
1390 Vlast_event_frame
= internal_last_event_frame
;
1392 /* If we report the quit char as an event,
1393 don't do so more than once. */
1394 if (!NILP (Vinhibit_quit
))
1400 /* Message turns off echoing unless more keystrokes turn it on again. */
1401 if (echo_area_glyphs
&& *echo_area_glyphs
&& echo_area_glyphs
!= echobuf
)
1404 /* If already echoing, continue. */
1407 /* If in middle of key sequence and minibuffer not active,
1408 start echoing if enough time elapses. */
1409 if (minibuf_level
== 0 && !immediate_echo
&& this_command_key_count
> 0
1410 && echo_keystrokes
> 0
1411 && (echo_area_glyphs
== 0 || *echo_area_glyphs
== 0))
1415 /* After a mouse event, start echoing right away.
1416 This is because we are probably about to display a menu,
1417 and we don't want to delay before doing so. */
1418 if (EVENT_HAS_PARAMETERS (prev_event
))
1422 tem0
= sit_for (echo_keystrokes
, 0, 1, 1);
1428 /* Maybe auto save due to number of keystrokes or idle time. */
1430 if (commandflag
!= 0
1431 && auto_save_interval
> 0
1432 && num_nonmacro_input_chars
- last_auto_save
> max (auto_save_interval
, 20)
1433 && !detect_input_pending ())
1436 save_getcjmp (temp
);
1437 Fdo_auto_save (Qnil
, Qnil
);
1438 restore_getcjmp (temp
);
1441 /* Try reading a character via menu prompting.
1442 Try this before the sit-for, because the sit-for
1443 would do the wrong thing if we are supposed to do
1446 if (INTERACTIVE
&& !NILP (prev_event
))
1447 c
= read_char_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
1449 /* Slow down auto saves logarithmically in size of current buffer,
1450 and garbage collect while we're at it. */
1451 if (INTERACTIVE
&& NILP (c
))
1453 int delay_level
, buffer_size
;
1455 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
1456 last_non_minibuf_size
= Z
- BEG
;
1457 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
1459 while (buffer_size
> 64)
1460 delay_level
++, buffer_size
-= buffer_size
>> 2;
1461 if (delay_level
< 4) delay_level
= 4;
1462 /* delay_level is 4 for files under around 50k, 7 at 100k,
1463 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
1465 /* Auto save if enough time goes by without input. */
1466 if (commandflag
!= 0
1467 && num_nonmacro_input_chars
> last_auto_save
1468 && XTYPE (Vauto_save_timeout
) == Lisp_Int
1469 && XINT (Vauto_save_timeout
) > 0)
1472 int delay
= delay_level
* XFASTINT (Vauto_save_timeout
) / 4;
1473 tem0
= sit_for (delay
, 0, 1, 1);
1477 save_getcjmp (temp
);
1478 Fdo_auto_save (Qnil
, Qnil
);
1479 restore_getcjmp (temp
);
1481 /* If we have auto-saved and there is still no input
1482 available, garbage collect if there has been enough
1483 consing going on to make it worthwhile. */
1484 if (!detect_input_pending ()
1485 && consing_since_gc
> gc_cons_threshold
/ 2)
1487 Fgarbage_collect ();
1494 /* Actually read a character, waiting if necessary. */
1497 c
= kbd_buffer_get_event ();
1500 if (commandflag
>= 0 && !input_pending
&& !detect_input_pending ())
1504 /* Terminate Emacs in batch mode if at eof. */
1505 if (noninteractive
&& XTYPE (c
) == Lisp_Int
&& XINT (c
) < 0)
1506 Fkill_emacs (make_number (1));
1508 if (XTYPE (c
) == Lisp_Int
)
1510 /* Add in any extra modifiers, where appropriate. */
1511 if ((extra_keyboard_modifiers
& CHAR_CTL
)
1512 || ((extra_keyboard_modifiers
& 0177) < ' '
1513 && (extra_keyboard_modifiers
& 0177) != 0))
1514 XSETINT (c
, make_ctrl_char (XINT (c
)));
1516 /* Transfer any other modifier bits directly from
1517 extra_keyboard_modifiers to c. Ignore the actual character code
1518 in the low 16 bits of extra_keyboard_modifiers. */
1519 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
1524 restore_getcjmp (save_jump
);
1528 echo_area_glyphs
= 0;
1530 /* Handle things that only apply to characters. */
1531 if (XTYPE (c
) == Lisp_Int
)
1533 /* If kbd_buffer_get_event gave us an EOF, return that. */
1537 if (XTYPE (Vkeyboard_translate_table
) == Lisp_String
1538 && XSTRING (Vkeyboard_translate_table
)->size
> XFASTINT (c
))
1539 XSETINT (c
, XSTRING (Vkeyboard_translate_table
)->data
[XFASTINT (c
)]);
1543 XVECTOR (recent_keys
)->contents
[recent_keys_index
] = c
;
1544 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
1545 recent_keys_index
= 0;
1547 /* Write c to the dribble file. If c is a lispy event, write
1548 the event's symbol to the dribble file, in <brackets>. Bleaugh.
1549 If you, dear reader, have a better idea, you've got the source. :-) */
1552 if (XTYPE (c
) == Lisp_Int
)
1553 putc (XINT (c
), dribble
);
1556 Lisp_Object dribblee
= c
;
1558 /* If it's a structured event, take the event header. */
1559 dribblee
= EVENT_HEAD (dribblee
);
1561 if (XTYPE (dribblee
) == Lisp_Symbol
)
1563 putc ('<', dribble
);
1564 fwrite (XSYMBOL (dribblee
)->name
->data
, sizeof (char),
1565 XSYMBOL (dribblee
)->name
->size
,
1567 putc ('>', dribble
);
1574 store_kbd_macro_char (c
);
1576 num_nonmacro_input_chars
++;
1581 /* Record this character as part of the current key.
1582 Don't record mouse motion; it should never matter. */
1583 if (! (EVENT_HAS_PARAMETERS (c
)
1584 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
1587 add_command_key (c
);
1590 /* Re-reading in the middle of a command */
1592 last_input_char
= c
;
1595 /* Process the help character specially if enabled */
1596 if (EQ (c
, Vhelp_char
) && !NILP (Vhelp_form
))
1599 count
= specpdl_ptr
- specpdl
;
1601 record_unwind_protect (Fset_window_configuration
,
1602 Fcurrent_window_configuration (Qnil
));
1604 tem0
= Feval (Vhelp_form
);
1605 if (XTYPE (tem0
) == Lisp_String
)
1606 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
1609 c
= read_char (0, 0, 0, Qnil
, 0);
1610 /* Remove the help from the frame */
1611 unbind_to (count
, Qnil
);
1613 if (EQ (c
, make_number (040)))
1616 c
= read_char (0, 0, 0, Qnil
, 0);
1627 Fprinc (object
, Qnil
);
1631 /* Copy out or in the info on where C-g should throw to.
1632 This is used when running Lisp code from within get_char,
1633 in case get_char is called recursively.
1634 See read_process_output. */
1639 bcopy (getcjmp
, temp
, sizeof getcjmp
);
1642 restore_getcjmp (temp
)
1645 bcopy (temp
, getcjmp
, sizeof getcjmp
);
1649 /* Low level keyboard/mouse input.
1650 kbd_buffer_store_event places events in kbd_buffer, and
1651 kbd_buffer_get_event retrieves them.
1652 mouse_moved indicates when the mouse has moved again, and
1653 *mouse_position_hook provides the mouse position. */
1655 /* Set this for debugging, to have a way to get out */
1658 extern int frame_garbaged
;
1660 /* Return true iff there are any events in the queue that read-char
1661 would return. If this returns false, a read-char would block. */
1665 return ! EVENT_QUEUES_EMPTY
;
1669 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
1670 of this function. */
1672 tracking_off (old_value
)
1673 Lisp_Object old_value
;
1675 if (! XFASTINT (old_value
))
1677 do_mouse_tracking
= 0;
1679 /* Redisplay may have been preempted because there was input
1680 available, and it assumes it will be called again after the
1681 input has been processed. If the only input available was
1682 the sort that we have just disabled, then we need to call
1684 if (!readable_events ())
1686 redisplay_preserve_echo_area ();
1687 get_input_pending (&input_pending
);
1692 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
1693 "Evaluate BODY with mouse movement events enabled.\n\
1694 Within a `track-mouse' form, mouse motion generates input events that\n\
1695 you can read with `read-event'.\n\
1696 Normally, mouse motion is ignored.")
1700 int count
= specpdl_ptr
- specpdl
;
1703 XSET (val
, Lisp_Int
, do_mouse_tracking
);
1704 record_unwind_protect (tracking_off
, val
);
1706 do_mouse_tracking
= 1;
1708 val
= Fprogn (args
);
1709 return unbind_to (count
, val
);
1712 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
1715 kbd_buffer_store_event (event
)
1716 register struct input_event
*event
;
1718 if (event
->kind
== no_event
)
1721 if (event
->kind
== ascii_keystroke
)
1723 register int c
= XFASTINT (event
->code
) & 0377;
1725 if (event
->modifiers
& ctrl_modifier
)
1726 c
= make_ctrl_char (c
);
1730 extern SIGTYPE
interrupt_signal ();
1733 /* If this results in a quit_char being returned to Emacs as
1734 input, set Vlast_event_frame properly. If this doesn't
1735 get returned to Emacs as an event, the next event read
1736 will set Vlast_event_frame again, so this is safe to do. */
1739 FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
1742 internal_last_event_frame
= event
->frame_or_window
;
1744 internal_last_event_frame
= focus
;
1745 Vlast_event_frame
= internal_last_event_frame
;
1749 last_event_timestamp
= event
->timestamp
;
1750 interrupt_signal ();
1754 if (c
&& c
== stop_character
)
1760 XSET (event
->code
, Lisp_Int
, c
);
1763 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
1764 kbd_store_ptr
= kbd_buffer
;
1766 /* Don't let the very last slot in the buffer become full,
1767 since that would make the two pointers equal,
1768 and that is indistinguishable from an empty buffer.
1769 Discard the event if it would fill the last slot. */
1770 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
1772 kbd_store_ptr
->kind
= event
->kind
;
1773 kbd_store_ptr
->code
= event
->code
;
1774 kbd_store_ptr
->part
= event
->part
;
1775 kbd_store_ptr
->frame_or_window
= event
->frame_or_window
;
1776 kbd_store_ptr
->modifiers
= event
->modifiers
;
1777 kbd_store_ptr
->x
= event
->x
;
1778 kbd_store_ptr
->y
= event
->y
;
1779 kbd_store_ptr
->timestamp
= event
->timestamp
;
1780 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_store_ptr
1782 = event
->frame_or_window
);
1788 static Lisp_Object
make_lispy_event ();
1789 static Lisp_Object
make_lispy_movement ();
1790 static Lisp_Object
modify_event_symbol ();
1791 static Lisp_Object
make_lispy_switch_frame ();
1794 kbd_buffer_get_event ()
1802 XSET (obj
, Lisp_Int
, c
);
1807 /* Wait until there is input available. */
1810 if (!EVENT_QUEUES_EMPTY
)
1813 /* If the quit flag is set, then read_char will return
1814 quit_char, so that counts as "available input." */
1815 if (!NILP (Vquit_flag
))
1816 quit_throw_to_read_char ();
1818 /* One way or another, wait until input is available; then, if
1819 interrupt handlers have not read it, read it now. */
1822 wait_for_kbd_input ();
1824 /* Note SIGIO has been undef'd if FIONREAD is missing. */
1828 if (EVENT_QUEUES_EMPTY
)
1830 Lisp_Object minus_one
;
1832 XSET (minus_one
, Lisp_Int
, -1);
1833 wait_reading_process_input (0, 0, minus_one
, 1);
1835 if (!interrupt_input
&& EVENT_QUEUES_EMPTY
)
1837 read_avail_input (0);
1840 #endif /* not VMS */
1843 /* At this point, we know that there is a readable event available
1844 somewhere. If the event queue is empty, then there must be a
1845 mouse movement enabled and available. */
1846 if (kbd_fetch_ptr
!= kbd_store_ptr
)
1848 struct input_event
*event
;
1850 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
1854 last_event_timestamp
= event
->timestamp
;
1858 /* These two kinds of events get special handling
1859 and don't actually appear to the command loop. */
1860 if (event
->kind
== selection_request_event
)
1863 x_handle_selection_request (event
);
1864 kbd_fetch_ptr
= event
+ 1;
1866 /* We're getting selection request events, but we don't have
1872 else if (event
->kind
== selection_clear_event
)
1875 x_handle_selection_clear (event
);
1876 kbd_fetch_ptr
= event
+ 1;
1878 /* We're getting selection request events, but we don't have
1884 /* If this event is on a different frame, return a switch-frame this
1885 time, and leave the event in the queue for next time. */
1889 Lisp_Object frame
= event
->frame_or_window
;
1892 if (XTYPE (frame
) == Lisp_Window
)
1893 frame
= WINDOW_FRAME (XWINDOW (frame
));
1895 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
1899 if (! EQ (frame
, internal_last_event_frame
)
1900 && XFRAME (frame
) != selected_frame
)
1901 obj
= make_lispy_switch_frame (frame
);
1902 internal_last_event_frame
= frame
;
1903 #endif /* MULTI_FRAME */
1905 /* If we didn't decide to make a switch-frame event, go ahead
1906 and build a real event from the queue entry. */
1910 obj
= make_lispy_event (event
);
1912 /* Wipe out this event, to catch bugs. */
1913 event
->kind
= no_event
;
1914 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[event
- kbd_buffer
]
1917 kbd_fetch_ptr
= event
+ 1;
1921 else if (do_mouse_tracking
&& mouse_moved
)
1924 Lisp_Object bar_window
;
1925 enum scroll_bar_part part
;
1929 (*mouse_position_hook
) (&f
, &bar_window
, &part
, &x
, &y
, &time
);
1934 /* Decide if we should generate a switch-frame event. Don't
1935 generate switch-frame events for motion outside of all Emacs
1939 Lisp_Object frame
= FRAME_FOCUS_FRAME (f
);
1942 XSET (frame
, Lisp_Frame
, f
);
1944 if (! EQ (frame
, internal_last_event_frame
)
1945 && XFRAME (frame
) != selected_frame
)
1946 obj
= make_lispy_switch_frame (frame
);
1947 internal_last_event_frame
= frame
;
1951 /* If we didn't decide to make a switch-frame event, go ahead and
1952 return a mouse-motion event. */
1954 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
1957 /* We were promised by the above while loop that there was
1958 something for us to read! */
1962 /* If something gave back nil as the Lispy event,
1963 it means the event was discarded, so try again. */
1968 input_pending
= readable_events ();
1971 Vlast_event_frame
= internal_last_event_frame
;
1977 /* Process any events that are not user-visible. */
1982 while (kbd_fetch_ptr
!= kbd_store_ptr
)
1984 struct input_event
*event
;
1986 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
1990 last_event_timestamp
= event
->timestamp
;
1992 /* These two kinds of events get special handling
1993 and don't actually appear to the command loop. */
1994 if (event
->kind
== selection_request_event
)
1997 x_handle_selection_request (event
);
1998 kbd_fetch_ptr
= event
+ 1;
2000 /* We're getting selection request events, but we don't have
2006 else if (event
->kind
== selection_clear_event
)
2009 x_handle_selection_clear (event
);
2010 kbd_fetch_ptr
= event
+ 1;
2012 /* We're getting selection request events, but we don't have
2021 get_input_pending (&input_pending
);
2024 /* Caches for modify_event_symbol. */
2025 static Lisp_Object func_key_syms
;
2026 static Lisp_Object mouse_syms
;
2028 /* You'll notice that this table is arranged to be conveniently
2029 indexed by X Windows keysym values. */
2030 static char *lispy_function_keys
[] =
2032 /* X Keysym value */
2034 "remove", 0, 0, 0, 0, 0, 0, 0, /* 0xff00 */
2042 0, 0, 0, /* 0xff10 */
2044 0, 0, 0, 0, 0, 0, 0,
2047 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff20...2f */
2048 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff30...3f */
2049 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
2051 "home", /* 0xff50 */ /* IsCursorKey */
2062 "select", /* 0xff60 */ /* IsMiscFunctionKey */
2073 "break", /* 0xff6b */
2075 /* Here are some keys found mostly on HP keyboards. The X event
2076 handling code will strip bit 29, which flags vendor-specific
2078 "reset", /* 0x1000ff6c */
2087 "kp-backtab", /* 0x1000ff75 */
2089 0, 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff7f */
2090 "kp-space", /* 0xff80 */ /* IsKeypadKey */
2091 0, 0, 0, 0, 0, 0, 0, 0,
2092 "kp-tab", /* 0xff89 */
2094 "kp-enter", /* 0xff8d */
2096 "kp-f1", /* 0xff91 */
2101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2102 "kp-multiply", /* 0xffaa */
2107 "kp-divide", /* 0xffaf */
2108 "kp-0", /* 0xffb0 */
2109 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
2112 "kp-equal", /* 0xffbd */
2113 "f1", /* 0xffbe */ /* IsFunctionKey */
2115 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
2116 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
2117 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
2118 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
2119 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
2120 0, 0, 0, 0, 0, 0, 0, 0,
2121 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
2122 0, 0, 0, 0, 0, 0, 0, "delete"
2125 static char *lispy_mouse_names
[] =
2127 "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5"
2130 /* Scroll bar parts. */
2131 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
2133 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
2134 Lisp_Object
*scroll_bar_parts
[] = {
2135 &Qabove_handle
, &Qhandle
, &Qbelow_handle
2139 /* A vector, indexed by button number, giving the down-going location
2140 of currently depressed buttons, both scroll bar and non-scroll bar.
2142 The elements have the form
2143 (BUTTON-NUMBER MODIFIER-MASK . REST)
2144 where REST is the cdr of a position as it would be reported in the event.
2146 The make_lispy_event function stores positions here to tell the
2147 difference between click and drag events, and to store the starting
2148 location to be included in drag events. */
2150 static Lisp_Object button_down_location
;
2152 /* Information about the most recent up-going button event: Which
2153 button, what location, and what time. */
2155 static int button_up_button
;
2156 static int button_up_x
;
2157 static int button_up_y
;
2158 static unsigned long button_up_time
;
2160 /* The maximum time between clicks to make a double-click,
2161 or Qnil to disable double-click detection,
2162 or Qt for no time limit. */
2163 Lisp_Object Vdouble_click_time
;
2165 /* The number of clicks in this multiple-click. */
2167 int double_click_count
;
2169 /* Given a struct input_event, build the lisp event which represents
2170 it. If EVENT is 0, build a mouse movement event from the mouse
2171 movement buffer, which should have a movement event in it.
2173 Note that events must be passed to this function in the order they
2174 are received; this function stores the location of button presses
2175 in order to build drag events when the button is released. */
2178 make_lispy_event (event
)
2179 struct input_event
*event
;
2181 #ifdef SWITCH_ENUM_BUG
2182 switch ((int) event
->kind
)
2184 switch (event
->kind
)
2187 /* A simple keystroke. */
2188 case ascii_keystroke
:
2190 int c
= XFASTINT (event
->code
);
2191 /* Turn ASCII characters into control characters
2193 if (event
->modifiers
& ctrl_modifier
)
2194 c
= make_ctrl_char (c
);
2196 /* Add in the other modifier bits. We took care of ctrl_modifier
2197 just above, and the shift key was taken care of by the X code,
2198 and applied to control characters by make_ctrl_char. */
2199 c
|= (event
->modifiers
2200 & (meta_modifier
| alt_modifier
2201 | hyper_modifier
| super_modifier
));
2206 /* A function key. The symbol may need to have modifier prefixes
2208 case non_ascii_keystroke
:
2210 return modify_event_symbol (XFASTINT (event
->code
), event
->modifiers
,
2212 lispy_function_keys
, &func_key_syms
,
2213 (sizeof (lispy_function_keys
)
2214 / sizeof (lispy_function_keys
[0])));
2217 /* A mouse click. Figure out where it is, decide whether it's
2218 a press, click or drag, and build the appropriate structure. */
2220 case scroll_bar_click
:
2222 int button
= XFASTINT (event
->code
);
2223 Lisp_Object position
;
2224 Lisp_Object
*start_pos_ptr
;
2225 Lisp_Object start_pos
;
2227 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
2230 /* Build the position as appropriate for this mouse click. */
2231 if (event
->kind
== mouse_click
)
2234 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
2236 = window_from_coordinates (f
, XINT (event
->x
), XINT (event
->y
),
2240 if (XINT (event
->y
) < FRAME_MENU_BAR_LINES (f
))
2244 items
= FRAME_MENU_BAR_ITEMS (f
);
2245 for (; CONSP (items
); items
= XCONS (items
)->cdr
)
2247 Lisp_Object pos
, string
;
2248 pos
= Fcdr (Fcdr (Fcar (items
)));
2249 string
= Fcar (Fcdr (Fcar (items
)));
2250 if (XINT (event
->x
) >= XINT (pos
)
2251 && XINT (event
->x
) < XINT (pos
) + XSTRING (string
)->size
)
2255 = Fcons (event
->frame_or_window
,
2257 Fcons (Fcons (event
->x
, event
->y
),
2258 Fcons (make_number (event
->timestamp
),
2262 return Fcons (Fcar (Fcar (items
)),
2263 Fcons (position
, Qnil
));
2265 return Fcons (Qnil
, Fcons (position
, Qnil
));
2267 else if (XTYPE (window
) != Lisp_Window
)
2272 (XINT (event
->x
) - XINT (XWINDOW (window
)->left
)));
2274 (XINT (event
->y
) - XINT (XWINDOW (window
)->top
)));
2279 posn
= Qvertical_line
;
2281 XSET (posn
, Lisp_Int
,
2282 buffer_posn_from_coords (XWINDOW (window
),
2290 Fcons (Fcons (event
->x
, event
->y
),
2291 Fcons (make_number (event
->timestamp
),
2296 Lisp_Object window
= event
->frame_or_window
;
2297 Lisp_Object portion_whole
= Fcons (event
->x
, event
->y
);
2298 Lisp_Object part
= *scroll_bar_parts
[(int) event
->part
];
2302 Fcons (Qvertical_scroll_bar
,
2303 Fcons (portion_whole
,
2304 Fcons (make_number (event
->timestamp
),
2309 start_pos_ptr
= &XVECTOR (button_down_location
)->contents
[button
];
2311 start_pos
= *start_pos_ptr
;
2312 *start_pos_ptr
= Qnil
;
2314 /* If this is a button press, squirrel away the location, so
2315 we can decide later whether it was a click or a drag. */
2316 if (event
->modifiers
& down_modifier
)
2317 *start_pos_ptr
= Fcopy_alist (position
);
2319 /* Now we're releasing a button - check the co-ordinates to
2320 see if this was a click or a drag. */
2321 else if (event
->modifiers
& up_modifier
)
2323 /* If we did not see a down before this up,
2324 ignore the up. Probably this happened because
2325 the down event chose a menu item.
2326 It would be an annoyance to treat the release
2327 of the button that chose the menu item
2328 as a separate event. */
2330 if (XTYPE (start_pos
) != Lisp_Cons
)
2333 event
->modifiers
&= ~up_modifier
;
2334 #if 0 /* Formerly we treated an up with no down as a click event. */
2335 if (XTYPE (start_pos
) != Lisp_Cons
)
2336 event
->modifiers
|= click_modifier
;
2340 /* The third element of every position should be the (x,y)
2342 Lisp_Object down
= Fnth (make_number (2), start_pos
);
2344 if (EQ (event
->x
, XCONS (down
)->car
)
2345 && EQ (event
->y
, XCONS (down
)->cdr
))
2347 if (button
== button_up_button
2348 && XINT (event
->x
) == button_up_x
2349 && XINT (event
->y
) == button_up_y
2350 && button_up_time
!= 0
2351 && (EQ (Vdouble_click_time
, Qt
)
2352 || (INTEGERP (Vdouble_click_time
)
2353 && ((int)(event
->timestamp
- button_up_time
)
2354 < XINT (Vdouble_click_time
)))))
2356 double_click_count
++;
2357 event
->modifiers
|= ((double_click_count
> 2)
2363 double_click_count
= 1;
2364 event
->modifiers
|= click_modifier
;
2366 button_up_button
= button
;
2367 button_up_x
= XINT (event
->x
);
2368 button_up_y
= XINT (event
->y
);
2369 button_up_time
= event
->timestamp
;
2374 event
->modifiers
|= drag_modifier
;
2379 /* Every mouse event should either have the down_modifier or
2380 the up_modifier set. */
2384 /* Get the symbol we should use for the mouse click. */
2386 = modify_event_symbol (button
,
2389 lispy_mouse_names
, &mouse_syms
,
2390 (sizeof (lispy_mouse_names
)
2391 / sizeof (lispy_mouse_names
[0])));
2393 if (event
->modifiers
& drag_modifier
)
2398 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
2401 Fcons (make_number (double_click_count
),
2410 /* The 'kind' field of the event is something we don't recognize. */
2417 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
2419 Lisp_Object bar_window
;
2420 enum scroll_bar_part part
;
2424 /* Is it a scroll bar movement? */
2425 if (frame
&& ! NILP (bar_window
))
2427 Lisp_Object part_sym
= *scroll_bar_parts
[(int) part
];
2429 return Fcons (Qscroll_bar_movement
,
2430 (Fcons (Fcons (bar_window
,
2431 Fcons (Qvertical_scroll_bar
,
2432 Fcons (Fcons (x
, y
),
2433 Fcons (make_number (time
),
2439 /* Or is it an ordinary mouse movement? */
2443 Lisp_Object window
=
2445 ? window_from_coordinates (frame
, XINT (x
), XINT (y
), &area
)
2449 if (XTYPE (window
) == Lisp_Window
)
2451 XSETINT (x
, XINT (x
) - XINT (XWINDOW (window
)->left
));
2452 XSETINT (y
, XINT (y
) - XINT (XWINDOW (window
)->top
));
2457 posn
= Qvertical_line
;
2459 XSET (posn
, Lisp_Int
,
2460 buffer_posn_from_coords (XWINDOW (window
),
2461 XINT (x
), XINT (y
)));
2471 return Fcons (Qmouse_movement
,
2472 Fcons (Fcons (window
,
2474 Fcons (Fcons (x
, y
),
2475 Fcons (make_number (time
),
2481 /* Construct a switch frame event. */
2483 make_lispy_switch_frame (frame
)
2486 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
2489 /* Manipulating modifiers. */
2491 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
2493 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
2494 SYMBOL's name of the end of the modifiers; the string from this
2495 position is the unmodified symbol name.
2497 This doesn't use any caches. */
2499 parse_modifiers_uncached (symbol
, modifier_end
)
2503 struct Lisp_String
*name
;
2507 CHECK_SYMBOL (symbol
, 1);
2510 name
= XSYMBOL (symbol
)->name
;
2513 for (i
= 0; i
+2 <= name
->size
; )
2514 switch (name
->data
[i
])
2516 #define SINGLE_LETTER_MOD(bit) \
2517 if (name->data[i+1] != '-') \
2518 goto no_more_modifiers; \
2523 SINGLE_LETTER_MOD (alt_modifier
);
2527 SINGLE_LETTER_MOD (ctrl_modifier
);
2531 SINGLE_LETTER_MOD (hyper_modifier
);
2535 SINGLE_LETTER_MOD (meta_modifier
);
2539 SINGLE_LETTER_MOD (shift_modifier
);
2543 SINGLE_LETTER_MOD (super_modifier
);
2547 if (i
+ 5 > name
->size
)
2548 goto no_more_modifiers
;
2549 if (! strncmp (name
->data
+ i
, "drag-", 5))
2551 modifiers
|= drag_modifier
;
2554 else if (! strncmp (name
->data
+ i
, "down-", 5))
2556 modifiers
|= down_modifier
;
2559 else if (i
+ 7 <= name
->size
2560 && ! strncmp (name
->data
+ i
, "double-", 7))
2562 modifiers
|= double_modifier
;
2566 goto no_more_modifiers
;
2570 if (i
+ 7 > name
->size
)
2571 goto no_more_modifiers
;
2572 if (! strncmp (name
->data
+ i
, "triple-", 7))
2574 modifiers
|= triple_modifier
;
2578 goto no_more_modifiers
;
2582 goto no_more_modifiers
;
2584 #undef SINGLE_LETTER_MOD
2588 /* Should we include the `click' modifier? */
2589 if (! (modifiers
& (down_modifier
| drag_modifier
2590 | double_modifier
| triple_modifier
))
2591 && i
+ 7 == name
->size
2592 && strncmp (name
->data
+ i
, "mouse-", 6) == 0
2593 && ('0' <= name
->data
[i
+ 6] && name
->data
[i
+ 6] <= '9'))
2594 modifiers
|= click_modifier
;
2603 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
2604 prepended to the string BASE[0..BASE_LEN-1].
2605 This doesn't use any caches. */
2607 apply_modifiers_uncached (modifiers
, base
, base_len
)
2612 /* Since BASE could contain nulls, we can't use intern here; we have
2613 to use Fintern, which expects a genuine Lisp_String, and keeps a
2616 (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
2622 /* Only the event queue may use the `up' modifier; it should always
2623 be turned into a click or drag event before presented to lisp code. */
2624 if (modifiers
& up_modifier
)
2627 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
2628 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
2629 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
2630 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
2631 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
2632 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
2633 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
2634 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
2635 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
2636 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
2637 /* The click modifier is denoted by the absence of other modifiers. */
2641 mod_len
= p
- new_mods
;
2645 Lisp_Object new_name
= make_uninit_string (mod_len
+ base_len
);
2647 bcopy (new_mods
, XSTRING (new_name
)->data
, mod_len
);
2648 bcopy (base
, XSTRING (new_name
)->data
+ mod_len
, base_len
);
2650 return Fintern (new_name
, Qnil
);
2655 static char *modifier_names
[] =
2657 "up", "down", "drag", "click", "double", "triple", 0, 0,
2658 0, 0, 0, 0, 0, 0, 0, 0,
2659 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
2661 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
2663 static Lisp_Object modifier_symbols
;
2665 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
2667 lispy_modifier_list (modifiers
)
2670 Lisp_Object modifier_list
;
2673 modifier_list
= Qnil
;
2674 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
2675 if (modifiers
& (1<<i
))
2676 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
2679 return modifier_list
;
2683 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
2684 where UNMODIFIED is the unmodified form of SYMBOL,
2685 MASK is the set of modifiers present in SYMBOL's name.
2686 This is similar to parse_modifiers_uncached, but uses the cache in
2687 SYMBOL's Qevent_symbol_element_mask property, and maintains the
2688 Qevent_symbol_elements property. */
2690 parse_modifiers (symbol
)
2693 Lisp_Object elements
= Fget (symbol
, Qevent_symbol_element_mask
);
2695 if (CONSP (elements
))
2700 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
2701 Lisp_Object unmodified
2702 = Fintern (make_string (XSYMBOL (symbol
)->name
->data
+ end
,
2703 XSYMBOL (symbol
)->name
->size
- end
),
2707 if (modifiers
& ~((1<<VALBITS
) - 1))
2709 XFASTINT (mask
) = modifiers
;
2710 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
2712 /* Cache the parsing results on SYMBOL. */
2713 Fput (symbol
, Qevent_symbol_element_mask
,
2715 Fput (symbol
, Qevent_symbol_elements
,
2716 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
2718 /* Since we know that SYMBOL is modifiers applied to unmodified,
2719 it would be nice to put that in unmodified's cache.
2720 But we can't, since we're not sure that parse_modifiers is
2727 /* Apply the modifiers MODIFIERS to the symbol BASE.
2728 BASE must be unmodified.
2730 This is like apply_modifiers_uncached, but uses BASE's
2731 Qmodifier_cache property, if present. It also builds
2732 Qevent_symbol_elements properties, since it has that info anyway.
2734 apply_modifiers copies the value of BASE's Qevent_kind property to
2735 the modified symbol. */
2737 apply_modifiers (modifiers
, base
)
2741 Lisp_Object cache
, index
, entry
, new_symbol
;
2743 /* Mask out upper bits. We don't know where this value's been. */
2744 modifiers
&= (1<<VALBITS
) - 1;
2746 /* The click modifier never figures into cache indices. */
2747 cache
= Fget (base
, Qmodifier_cache
);
2748 XFASTINT (index
) = (modifiers
& ~click_modifier
);
2749 entry
= Fassq (index
, cache
);
2752 new_symbol
= XCONS (entry
)->cdr
;
2755 /* We have to create the symbol ourselves. */
2756 new_symbol
= apply_modifiers_uncached (modifiers
,
2757 XSYMBOL (base
)->name
->data
,
2758 XSYMBOL (base
)->name
->size
);
2760 /* Add the new symbol to the base's cache. */
2761 entry
= Fcons (index
, new_symbol
);
2762 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
2764 /* We have the parsing info now for free, so add it to the caches. */
2765 XFASTINT (index
) = modifiers
;
2766 Fput (new_symbol
, Qevent_symbol_element_mask
,
2767 Fcons (base
, Fcons (index
, Qnil
)));
2768 Fput (new_symbol
, Qevent_symbol_elements
,
2769 Fcons (base
, lispy_modifier_list (modifiers
)));
2772 /* Make sure this symbol is of the same kind as BASE.
2774 You'd think we could just set this once and for all when we
2775 intern the symbol above, but reorder_modifiers may call us when
2776 BASE's property isn't set right; we can't assume that just
2777 because it has a Qmodifier_cache property it must have its
2778 Qevent_kind set right as well. */
2779 if (NILP (Fget (new_symbol
, Qevent_kind
)))
2781 Lisp_Object kind
= Fget (base
, Qevent_kind
);
2784 Fput (new_symbol
, Qevent_kind
, kind
);
2791 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
2792 return a symbol with the modifiers placed in the canonical order.
2793 Canonical order is alphabetical, except for down and drag, which
2794 always come last. The 'click' modifier is never written out.
2796 Fdefine_key calls this to make sure that (for example) C-M-foo
2797 and M-C-foo end up being equivalent in the keymap. */
2800 reorder_modifiers (symbol
)
2803 /* It's hopefully okay to write the code this way, since everything
2804 will soon be in caches, and no consing will be done at all. */
2805 Lisp_Object parsed
= parse_modifiers (symbol
);
2807 return apply_modifiers (XCONS (XCONS (parsed
)->cdr
)->car
,
2808 XCONS (parsed
)->car
);
2812 /* For handling events, we often want to produce a symbol whose name
2813 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
2814 to some base, like the name of a function key or mouse button.
2815 modify_event_symbol produces symbols of this sort.
2817 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
2818 is the name of the i'th symbol. TABLE_SIZE is the number of elements
2821 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
2822 persist between calls to modify_event_symbol that it can use to
2823 store a cache of the symbols it's generated for this NAME_TABLE
2826 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
2828 MODIFIERS is a set of modifier bits (as given in struct input_events)
2829 whose prefixes should be applied to the symbol name.
2831 SYMBOL_KIND is the value to be placed in the event_kind property of
2832 the returned symbol.
2834 The symbols we create are supposed to have an
2835 `event-symbol-elements' property, which lists the modifiers present
2836 in the symbol's name. */
2839 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_table
,
2840 symbol_table
, table_size
)
2843 Lisp_Object symbol_kind
;
2845 Lisp_Object
*symbol_table
;
2850 /* Is this a request for a valid symbol? */
2851 if (symbol_num
< 0 || symbol_num
>= table_size
)
2854 /* If *symbol_table doesn't seem to be initialized properly, fix that.
2855 *symbol_table should be a lisp vector TABLE_SIZE elements long,
2856 where the Nth element is the symbol for NAME_TABLE[N], or nil if
2857 we've never used that symbol before. */
2858 if (XTYPE (*symbol_table
) != Lisp_Vector
2859 || XVECTOR (*symbol_table
)->size
!= table_size
)
2863 XFASTINT (size
) = table_size
;
2864 *symbol_table
= Fmake_vector (size
, Qnil
);
2867 slot
= & XVECTOR (*symbol_table
)->contents
[symbol_num
];
2869 /* Have we already used this symbol before? */
2872 /* No; let's create it. */
2873 if (name_table
[symbol_num
])
2874 *slot
= intern (name_table
[symbol_num
]);
2878 sprintf (buf
, "key-%d", symbol_num
);
2879 *slot
= intern (buf
);
2882 /* Fill in the cache entries for this symbol; this also
2883 builds the Qevent_symbol_elements property, which the user
2885 apply_modifiers (modifiers
& click_modifier
, *slot
);
2886 Fput (*slot
, Qevent_kind
, symbol_kind
);
2889 /* Apply modifiers to that symbol. */
2890 return apply_modifiers (modifiers
, *slot
);
2894 /* Store into *addr a value nonzero if terminal input chars are available.
2895 Serves the purpose of ioctl (0, FIONREAD, addr)
2896 but works even if FIONREAD does not exist.
2897 (In fact, this may actually read some input.) */
2900 get_input_pending (addr
)
2903 /* First of all, have we already counted some input? */
2904 *addr
= !NILP (Vquit_flag
) || readable_events ();
2906 /* If input is being read as it arrives, and we have none, there is none. */
2907 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
2910 /* Try to read some input and see how much we get. */
2912 *addr
= !NILP (Vquit_flag
) || readable_events ();
2915 /* Interface to read_avail_input, blocking SIGIO if necessary. */
2918 gobble_input (expected
)
2923 if (interrupt_input
)
2926 mask
= sigblockx (SIGIO
);
2927 read_avail_input (expected
);
2932 read_avail_input (expected
);
2938 /* Read any terminal input already buffered up by the system
2939 into the kbd_buffer, but do not wait.
2941 EXPECTED should be nonzero if the caller knows there is some input.
2943 Except on VMS, all input is read by this function.
2944 If interrupt_input is nonzero, this function MUST be called
2945 only when SIGIO is blocked.
2947 Returns the number of keyboard chars read, or -1 meaning
2948 this is a bad time to try to read input. */
2951 read_avail_input (expected
)
2954 struct input_event buf
[KBD_BUFFER_SIZE
];
2958 if (read_socket_hook
)
2959 /* No need for FIONREAD or fcntl; just say don't wait. */
2960 nread
= (*read_socket_hook
) (0, buf
, KBD_BUFFER_SIZE
, expected
, expected
);
2963 unsigned char cbuf
[KBD_BUFFER_SIZE
];
2966 /* Find out how much input is available. */
2967 if (ioctl (0, FIONREAD
, &nread
) < 0)
2968 /* Formerly simply reported no input, but that sometimes led to
2969 a failure of Emacs to terminate.
2970 SIGHUP seems appropriate if we can't reach the terminal. */
2971 /* ??? Is it really right to send the signal just to this process
2972 rather than to the whole process group?
2973 Perhaps on systems with FIONREAD Emacs is alone in its group. */
2974 kill (getpid (), SIGHUP
);
2977 if (nread
> sizeof cbuf
)
2978 nread
= sizeof cbuf
;
2979 #else /* no FIONREAD */
2981 /* Read some input if available, but don't wait. */
2982 nread
= sizeof cbuf
;
2983 fcntl (fileno (stdin
), F_SETFL
, O_NDELAY
);
2989 /* Now read; for one reason or another, this will not block. */
2992 nread
= read (fileno (stdin
), cbuf
, nread
);
2994 /* The kernel sometimes fails to deliver SIGHUP for ptys.
2995 This looks incorrect, but it isn't, because _BSD causes
2996 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
2997 and that causes a value other than 0 when there is no input. */
3001 /* Retry the read if it is interrupted. */
3003 || ! (errno
== EAGAIN
|| errno
== EFAULT
3013 fcntl (fileno (stdin
), F_SETFL
, 0);
3015 #endif /* no FIONREAD */
3016 for (i
= 0; i
< nread
; i
++)
3018 buf
[i
].kind
= ascii_keystroke
;
3019 buf
[i
].modifiers
= 0;
3020 if (meta_key
== 1 && (cbuf
[i
] & 0x80))
3021 buf
[i
].modifiers
= meta_modifier
;
3025 XSET (buf
[i
].code
, Lisp_Int
, cbuf
[i
]);
3027 XSET (buf
[i
].frame_or_window
, Lisp_Frame
, selected_frame
);
3029 buf
[i
].frame_or_window
= Qnil
;
3034 /* Scan the chars for C-g and store them in kbd_buffer. */
3035 for (i
= 0; i
< nread
; i
++)
3037 kbd_buffer_store_event (&buf
[i
]);
3038 /* Don't look at input that follows a C-g too closely.
3039 This reduces lossage due to autorepeat on C-g. */
3040 if (buf
[i
].kind
== ascii_keystroke
3041 && XINT(buf
[i
].code
) == quit_char
)
3047 #endif /* not VMS */
3049 #ifdef SIGIO /* for entire page */
3050 /* Note SIGIO has been undef'd if FIONREAD is missing. */
3053 input_available_signal (signo
)
3056 /* Must preserve main program's value of errno. */
3057 int old_errno
= errno
;
3059 extern int select_alarmed
;
3063 /* USG systems forget handlers when they are used;
3064 must reestablish each time */
3065 signal (signo
, input_available_signal
);
3072 if (input_available_clear_time
)
3073 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
3078 nread
= read_avail_input (1);
3079 /* -1 means it's not ok to read the input now.
3080 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
3081 0 means there was no keyboard input available. */
3086 select_alarmed
= 1; /* Force the select emulator back to life */
3097 /* Send ourselves a SIGIO.
3099 This function exists so that the UNBLOCK_INPUT macro in
3100 blockinput.h can have some way to take care of input we put off
3101 dealing with, without assuming that every file which uses
3102 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
3104 reinvoke_input_signal ()
3113 /* Return the prompt-string of a sparse keymap.
3114 This is the first element which is a string.
3115 Return nil if there is none. */
3123 register Lisp_Object tem
;
3125 if (XTYPE (tem
) == Lisp_String
)
3132 static Lisp_Object
menu_bar_item ();
3133 static Lisp_Object
menu_bar_one_keymap ();
3135 /* Return a list of menu items for a menu bar, appropriate
3136 to the current buffer.
3137 The elements have the form (KEY STRING . nil). */
3142 /* The number of keymaps we're scanning right now, and the number of
3143 keymaps we have allocated space for. */
3146 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
3147 in the current keymaps, or nil where it is not a prefix. */
3150 Lisp_Object def
, tem
;
3157 /* In order to build the menus, we need to call the keymap
3158 accessors. They all call QUIT. But this function is called
3159 during redisplay, during which a quit is fatal. So inhibit
3160 quitting while building the menus.
3161 We do this instead of specbind because (1) errors will clear it anyway
3162 and (2) this avoids risk of specpdl overflow. */
3163 oquit
= Vinhibit_quit
;
3166 /* Build our list of keymaps.
3167 If we recognize a function key and replace its escape sequence in
3168 keybuf with its symbol, or if the sequence starts with a mouse
3169 click and we need to switch buffers, we jump back here to rebuild
3170 the initial keymaps from the current buffer. */
3174 nmaps
= current_minor_maps (0, &tmaps
) + 2;
3175 maps
= (Lisp_Object
*) alloca (nmaps
* sizeof (maps
[0]));
3176 bcopy (tmaps
, maps
, (nmaps
- 2) * sizeof (maps
[0]));
3177 #ifdef USE_TEXT_PROPERTIES
3178 maps
[nmaps
-2] = get_local_map (PT
, current_buffer
);
3180 maps
[nmaps
-2] = current_buffer
->keymap
;
3182 maps
[nmaps
-1] = current_global_map
;
3185 /* Look up in each map the dummy prefix key `menu-bar'. */
3189 for (mapno
= 0; mapno
< nmaps
; mapno
++)
3191 if (! NILP (maps
[mapno
]))
3192 def
= get_keyelt (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0));
3196 tem
= Fkeymapp (def
);
3198 result
= menu_bar_one_keymap (def
, result
);
3201 result
= Fnreverse (result
);
3202 Vinhibit_quit
= oquit
;
3206 /* Scan one map KEYMAP, accumulating any menu items it defines
3207 that have not yet been seen in RESULT. Return the updated RESULT. */
3210 menu_bar_one_keymap (keymap
, result
)
3211 Lisp_Object keymap
, result
;
3213 Lisp_Object tail
, item
, key
, binding
, item_string
, table
;
3215 /* Loop over all keymap entries that have menu strings. */
3216 for (tail
= keymap
; XTYPE (tail
) == Lisp_Cons
; tail
= XCONS (tail
)->cdr
)
3218 item
= XCONS (tail
)->car
;
3219 if (XTYPE (item
) == Lisp_Cons
)
3221 key
= XCONS (item
)->car
;
3222 binding
= XCONS (item
)->cdr
;
3223 if (XTYPE (binding
) == Lisp_Cons
)
3225 item_string
= XCONS (binding
)->car
;
3226 if (XTYPE (item_string
) == Lisp_String
)
3227 result
= menu_bar_item (key
, item_string
,
3228 Fcdr (binding
), result
);
3231 else if (XTYPE (item
) == Lisp_Vector
)
3233 /* Loop over the char values represented in the vector. */
3234 int len
= XVECTOR (item
)->size
;
3236 for (c
= 0; c
< len
; c
++)
3238 Lisp_Object character
;
3239 XFASTINT (character
) = c
;
3240 binding
= XVECTOR (item
)->contents
[c
];
3241 if (XTYPE (binding
) == Lisp_Cons
)
3243 item_string
= XCONS (binding
)->car
;
3244 if (XTYPE (item_string
) == Lisp_String
)
3245 result
= menu_bar_item (key
, item_string
,
3246 Fcdr (binding
), result
);
3256 menu_bar_item (key
, item_string
, def
, result
)
3257 Lisp_Object key
, item_string
, def
, result
;
3259 Lisp_Object tem
, elt
;
3260 Lisp_Object enabled
;
3262 /* See if this entry is enabled. */
3265 if (XTYPE (def
) == Lisp_Symbol
)
3267 /* No property, or nil, means enable.
3268 Otherwise, enable if value is not nil. */
3269 tem
= Fget (def
, Qmenu_enable
);
3271 enabled
= Feval (tem
);
3274 /* Add an entry for this key and string
3275 if there is none yet. */
3276 elt
= Fassq (key
, result
);
3277 if (!NILP (enabled
) && NILP (elt
))
3278 result
= Fcons (Fcons (key
, Fcons (item_string
, Qnil
)), result
);
3283 static int echo_flag
;
3284 static int echo_now
;
3286 /* Read a character like read_char but optionally prompt based on maps
3287 in the array MAPS. NMAPS is the length of MAPS. Return nil if we
3288 decided not to read a character, because there are no menu items in
3291 PREV_EVENT is the previous input event, or nil if we are reading
3292 the first event of a key sequence.
3294 If USED_MOUSE_MENU is non-zero, then we set *USED_MOUSE_MENU to 1
3295 if we used a mouse menu to read the input, or zero otherwise. If
3296 USED_MOUSE_MENU is zero, *USED_MOUSE_MENU is left alone.
3298 The prompting is done based on the prompt-string of the map
3299 and the strings associated with various map elements. */
3302 read_char_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
3305 Lisp_Object prev_event
;
3306 int *used_mouse_menu
;
3309 register Lisp_Object name
;
3311 int width
= FRAME_WIDTH (selected_frame
) - 4;
3312 char *menu
= (char *) alloca (width
+ 4);
3314 Lisp_Object rest
, vector
;
3316 if (used_mouse_menu
)
3317 *used_mouse_menu
= 0;
3319 /* Use local over global Menu maps */
3321 if (! menu_prompting
)
3324 /* Get the menu name from the first map that has one (a prompt string). */
3325 for (mapno
= 0; mapno
< nmaps
; mapno
++)
3327 name
= map_prompt (maps
[mapno
]);
3332 /* If we don't have any menus, just read a character normally. */
3336 #ifdef HAVE_X_WINDOWS
3338 /* If we got to this point via a mouse click,
3339 use a real menu for mouse selection. */
3340 if (EVENT_HAS_PARAMETERS (prev_event
))
3342 /* Display the menu and get the selection. */
3343 Lisp_Object
*realmaps
3344 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
3348 /* Use the maps that are not nil. */
3349 for (mapno
= 0; mapno
< nmaps
; mapno
++)
3350 if (!NILP (maps
[mapno
]))
3351 realmaps
[nmaps1
++] = maps
[mapno
];
3353 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
3356 /* If we got more than one event, put all but the first
3357 onto this list to be read later.
3358 Return just the first event now. */
3359 unread_command_events
3360 = nconc2 (XCONS (value
)->cdr
, unread_command_events
);
3361 value
= XCONS (value
)->car
;
3364 XSET (value
, Lisp_Int
, quit_char
);
3365 if (used_mouse_menu
)
3366 *used_mouse_menu
= 1;
3369 #endif /* HAVE_X_MENU */
3370 #endif /* HAVE_X_WINDOWS */
3372 /* Prompt string always starts with map's prompt, and a space. */
3373 strcpy (menu
, XSTRING (name
)->data
);
3374 nlength
= XSTRING (name
)->size
;
3375 menu
[nlength
++] = ':';
3376 menu
[nlength
++] = ' ';
3379 /* Start prompting at start of first map. */
3383 /* Present the documented bindings, a line at a time. */
3391 /* Loop over elements of map. */
3396 /* If reached end of map, start at beginning of next map. */
3400 /* At end of last map, wrap around to first map if just starting,
3401 or end this line if already have something on it. */
3412 /* Look at the next element of the map. */
3414 elt
= XVECTOR (vector
)->contents
[idx
];
3416 elt
= Fcar_safe (rest
);
3418 if (idx
< 0 && XTYPE (elt
) == Lisp_Vector
)
3420 /* If we found a dense table in the keymap,
3421 advanced past it, but start scanning its contents. */
3422 rest
= Fcdr_safe (rest
);
3428 /* An ordinary element. */
3429 s
= Fcar_safe (Fcdr_safe (elt
));
3430 if (XTYPE (s
) != Lisp_String
)
3431 /* Ignore the element if it has no prompt string. */
3433 /* If we have room for the prompt string, add it to this line.
3434 If this is the first on the line, always add it. */
3435 else if (XSTRING (s
)->size
+ i
< width
3440 /* Punctuate between strings. */
3443 strcpy (menu
+ i
, ", ");
3448 /* Add as much of string as fits. */
3449 thiswidth
= XSTRING (s
)->size
;
3450 if (thiswidth
+ i
> width
)
3451 thiswidth
= width
- i
;
3452 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
3457 /* If this element does not fit, end the line now,
3458 and save the element for the next line. */
3459 strcpy (menu
+ i
, "...");
3463 /* Move past this element. */
3464 if (idx
>= 0 && idx
+ 1 >= XVECTOR (rest
)->size
)
3465 /* Handle reaching end of dense table. */
3470 rest
= Fcdr_safe (rest
);
3474 /* Prompt with that and read response. */
3476 obj
= read_char (1, 0, 0, Qnil
, 0);
3478 if (XTYPE (obj
) != Lisp_Int
)
3483 if (! EQ (obj
, menu_prompt_more_char
)
3484 && (XTYPE (menu_prompt_more_char
) != Lisp_Int
3485 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
3490 /* Reading key sequences. */
3492 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
3493 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
3494 keymap, or nil otherwise. Return the index of the first keymap in
3495 which KEY has any binding, or NMAPS if no map has a binding.
3497 If KEY is a meta ASCII character, treat it like meta-prefix-char
3498 followed by the corresponding non-meta character. Keymaps in
3499 CURRENT with non-prefix bindings for meta-prefix-char become nil in
3502 When KEY is not defined in any of the keymaps, if it is an upper
3503 case letter and there are bindings for the corresponding lower-case
3504 letter, return the bindings for the lower-case letter.
3506 If KEY has no bindings in any of the CURRENT maps, NEXT is left
3509 NEXT may == CURRENT. */
3512 follow_key (key
, nmaps
, current
, defs
, next
)
3514 Lisp_Object
*current
, *defs
, *next
;
3517 int i
, first_binding
;
3519 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
3520 followed by the corresponding non-meta character. */
3521 if (XTYPE (key
) == Lisp_Int
&& (XINT (key
) & CHAR_META
))
3523 for (i
= 0; i
< nmaps
; i
++)
3524 if (! NILP (current
[i
]))
3527 get_keyelt (access_keymap (current
[i
], meta_prefix_char
, 1, 0));
3529 /* Note that since we pass the resulting bindings through
3530 get_keymap_1, non-prefix bindings for meta-prefix-char
3532 next
[i
] = get_keymap_1 (next
[i
], 0, 1);
3538 XSET (key
, Lisp_Int
, XFASTINT (key
) & ~CHAR_META
);
3541 first_binding
= nmaps
;
3542 for (i
= nmaps
- 1; i
>= 0; i
--)
3544 if (! NILP (current
[i
]))
3546 defs
[i
] = get_keyelt (access_keymap (current
[i
], key
, 1, 0));
3547 if (! NILP (defs
[i
]))
3554 /* When KEY is not defined in any of the keymaps, if it is an upper
3555 case letter and there are bindings for the corresponding
3556 lower-case letter, return the bindings for the lower-case letter. */
3557 if (first_binding
== nmaps
3558 && XTYPE (key
) == Lisp_Int
3559 && ((((XINT (key
) & 0x3ffff)
3560 < XSTRING (current_buffer
->downcase_table
)->size
)
3561 && UPPERCASEP (XINT (key
) & 0x3ffff))
3562 || (XINT (key
) & shift_modifier
)))
3564 if (XINT (key
) & shift_modifier
)
3565 XSETINT (key
, XINT (key
) & ~shift_modifier
);
3567 XSETINT (key
, DOWNCASE (XINT (key
)));
3569 first_binding
= nmaps
;
3570 for (i
= nmaps
- 1; i
>= 0; i
--)
3572 if (! NILP (current
[i
]))
3574 defs
[i
] = get_keyelt (access_keymap (current
[i
], key
, 1, 0));
3575 if (! NILP (defs
[i
]))
3583 /* Given the set of bindings we've found, produce the next set of maps. */
3584 if (first_binding
< nmaps
)
3585 for (i
= 0; i
< nmaps
; i
++)
3586 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0, 1);
3588 return first_binding
;
3591 /* Read a sequence of keys that ends with a non prefix character,
3592 storing it in KEYBUF, a buffer of size BUFSIZE.
3594 Return the length of the key sequence stored.
3596 Echo starting immediately unless `prompt' is 0.
3598 Where a key sequence ends depends on the currently active keymaps.
3599 These include any minor mode keymaps active in the current buffer,
3600 the current buffer's local map, and the global map.
3602 If a key sequence has no other bindings, we check Vfunction_key_map
3603 to see if some trailing subsequence might be the beginning of a
3604 function key's sequence. If so, we try to read the whole function
3605 key, and substitute its symbolic name into the key sequence.
3607 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
3608 `double-' events into similar click events, if that would make them
3609 bound. We try to turn `triple-' events first into `double-' events,
3612 If we get a mouse click in a mode line, vertical divider, or other
3613 non-text area, we treat the click as if it were prefixed by the
3614 symbol denoting that area - `mode-line', `vertical-line', or
3617 If the sequence starts with a mouse click, we read the key sequence
3618 with respect to the buffer clicked on, not the current buffer.
3620 If the user switches frames in the midst of a key sequence, we put
3621 off the switch-frame event until later; the next call to
3622 read_char will return it. */
3625 read_key_sequence (keybuf
, bufsize
, prompt
)
3626 Lisp_Object
*keybuf
;
3630 int count
= specpdl_ptr
- specpdl
;
3632 /* How many keys there are in the current key sequence. */
3635 /* The length of the echo buffer when we started reading, and
3636 the length of this_command_keys when we started reading. */
3640 /* The number of keymaps we're scanning right now, and the number of
3641 keymaps we have allocated space for. */
3643 int nmaps_allocated
= 0;
3645 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
3646 the current keymaps. */
3649 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
3650 in the current keymaps, or nil where it is not a prefix. */
3651 Lisp_Object
*submaps
;
3653 /* The index in defs[] of the first keymap that has a binding for
3654 this key sequence. In other words, the lowest i such that
3655 defs[i] is non-nil. */
3658 /* If t < mock_input, then KEYBUF[t] should be read as the next
3661 We use this to recover after recognizing a function key. Once we
3662 realize that a suffix of the current key sequence is actually a
3663 function key's escape sequence, we replace the suffix with the
3664 function key's binding from Vfunction_key_map. Now keybuf
3665 contains a new and different key sequence, so the echo area,
3666 this_command_keys, and the submaps and defs arrays are wrong. In
3667 this situation, we set mock_input to t, set t to 0, and jump to
3668 restart_sequence; the loop will read keys from keybuf up until
3669 mock_input, thus rebuilding the state; and then it will resume
3670 reading characters from the keyboard. */
3673 /* If the sequence is unbound in submaps[], then
3674 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
3675 and fkey_map is its binding.
3677 These might be > t, indicating that all function key scanning
3678 should hold off until t reaches them. We do this when we've just
3679 recognized a function key, to avoid searching for the function
3680 key's again in Vfunction_key_map. */
3681 int fkey_start
= 0, fkey_end
= 0;
3682 Lisp_Object fkey_map
;
3684 /* If we receive a ``switch-frame'' event in the middle of a key sequence,
3685 we put it off for later. While we're reading, we keep the event here. */
3686 Lisp_Object delayed_switch_frame
;
3688 Lisp_Object first_event
;
3692 last_nonmenu_event
= Qnil
;
3694 delayed_switch_frame
= Qnil
;
3695 fkey_map
= Vfunction_key_map
;
3697 /* If there is no function key map, turn off function key scanning. */
3698 if (NILP (Fkeymapp (Vfunction_key_map
)))
3699 fkey_start
= fkey_end
= bufsize
+ 1;
3704 echo_prompt (prompt
);
3705 else if (cursor_in_echo_area
)
3706 /* This doesn't put in a dash if the echo buffer is empty, so
3707 you don't always see a dash hanging out in the minibuffer. */
3711 /* Record the initial state of the echo area and this_command_keys;
3712 we will need to restore them if we replay a key sequence. */
3714 echo_start
= echo_length ();
3715 keys_start
= this_command_key_count
;
3717 #if 0 /* This doesn't quite work, because some of the things
3718 that read_char does cannot safely be bypassed.
3719 It seems too risky to try to make this work right. */
3720 /* Read the first char of the sequence specially, before setting
3721 up any keymaps, in case a filter runs and switches buffers on us. */
3722 first_event
= read_char (!prompt
, 0, submaps
, last_nonmenu_event
,
3726 /* We jump here when the key sequence has been thoroughly changed, and
3727 we need to rescan it starting from the beginning. When we jump here,
3728 keybuf[0..mock_input] holds the sequence we should reread. */
3731 /* Build our list of keymaps.
3732 If we recognize a function key and replace its escape sequence in
3733 keybuf with its symbol, or if the sequence starts with a mouse
3734 click and we need to switch buffers, we jump back here to rebuild
3735 the initial keymaps from the current buffer. */
3739 nmaps
= current_minor_maps (0, &maps
) + 2;
3740 if (nmaps
> nmaps_allocated
)
3742 submaps
= (Lisp_Object
*) alloca (nmaps
* sizeof (submaps
[0]));
3743 defs
= (Lisp_Object
*) alloca (nmaps
* sizeof (defs
[0]));
3744 nmaps_allocated
= nmaps
;
3746 bcopy (maps
, submaps
, (nmaps
- 2) * sizeof (submaps
[0]));
3747 #ifdef USE_TEXT_PROPERTIES
3748 submaps
[nmaps
-2] = get_local_map (PT
, current_buffer
);
3750 submaps
[nmaps
-2] = current_buffer
->keymap
;
3752 submaps
[nmaps
-1] = current_global_map
;
3755 /* Find an accurate initial value for first_binding. */
3756 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
3757 if (! NILP (submaps
[first_binding
]))
3760 /* We jump here when a function key substitution has forced us to
3761 reprocess the current key sequence. keybuf[0..mock_input] is the
3762 sequence we want to reread. */
3765 /* These are no-ops the first time through, but if we restart, they
3766 revert the echo area and this_command_keys to their original state. */
3767 this_command_key_count
= keys_start
;
3769 echo_truncate (echo_start
);
3771 /* If the best binding for the current key sequence is a keymap, or
3772 we may be looking at a function key's escape sequence, keep on
3774 while ((first_binding
< nmaps
&& ! NILP (submaps
[first_binding
]))
3775 || (first_binding
>= nmaps
3777 /* mock input is never part of a function key's sequence. */
3778 && mock_input
<= fkey_start
))
3781 int used_mouse_menu
= 0;
3783 /* Where the last real key started. If we need to throw away a
3784 key that has expanded into more than one element of keybuf
3785 (say, a mouse click on the mode line which is being treated
3786 as [mode-line (mouse-...)], then we backtrack to this point
3788 int last_real_key_start
;
3790 /* These variables are analogous to echo_start and keys_start;
3791 while those allow us to restart the entire key sequence,
3792 echo_local_start and keys_local_start allow us to throw away
3794 int echo_local_start
, keys_local_start
, local_first_binding
;
3797 error ("key sequence too long");
3800 echo_local_start
= echo_length ();
3801 keys_local_start
= this_command_key_count
;
3802 local_first_binding
= first_binding
;
3805 /* These are no-ops, unless we throw away a keystroke below and
3806 jumped back up to replay_key; in that case, these restore the
3807 variables to their original state, allowing us to replay the
3810 echo_truncate (echo_local_start
);
3811 this_command_key_count
= keys_local_start
;
3812 first_binding
= local_first_binding
;
3814 /* By default, assume each event is "real". */
3815 last_real_key_start
= t
;
3817 /* Does mock_input indicate that we are re-reading a key sequence? */
3821 add_command_key (key
);
3825 /* If not, we should actually read a character. */
3828 struct buffer
*buf
= current_buffer
;
3830 key
= read_char (!prompt
, nmaps
, submaps
, last_nonmenu_event
,
3833 /* read_char returns -1 at the end of a macro.
3834 Emacs 18 handles this by returning immediately with a
3835 zero, so that's what we'll do. */
3836 if (XTYPE (key
) == Lisp_Int
&& XINT (key
) == -1)
3845 /* Clicks in non-text areas get prefixed by the symbol
3846 in their CHAR-ADDRESS field. For example, a click on
3847 the mode line is prefixed by the symbol `mode-line'.
3849 Furthermore, key sequences beginning with mouse clicks
3850 are read using the keymaps of the buffer clicked on, not
3851 the current buffer. So we may have to switch the buffer
3854 When we turn one event into two events, we must make sure
3855 that neither of the two looks like the original--so that,
3856 if we replay the events, they won't be expanded again.
3857 If not for this, such reexpansion could happen either here
3858 or when user programs play with this-command-keys. */
3859 if (EVENT_HAS_PARAMETERS (key
))
3861 Lisp_Object kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
3863 if (EQ (kind
, Qmouse_click
))
3865 Lisp_Object window
= POSN_WINDOW (EVENT_START (key
));
3866 Lisp_Object posn
= POSN_BUFFER_POSN (EVENT_START (key
));
3868 if (XTYPE (posn
) == Lisp_Cons
)
3870 /* We're looking at the second event of a
3871 sequence which we expanded before. Set
3872 last_real_key_start appropriately. */
3874 last_real_key_start
= t
- 1;
3877 /* Key sequences beginning with mouse clicks are
3878 read using the keymaps in the buffer clicked on,
3879 not the current buffer. If we're at the
3880 beginning of a key sequence, switch buffers. */
3881 if (last_real_key_start
== 0
3882 && XTYPE (window
) == Lisp_Window
3883 && XTYPE (XWINDOW (window
)->buffer
) == Lisp_Buffer
3884 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
3889 /* Arrange to go back to the original buffer once we're
3890 done reading the key sequence. Note that we can't
3891 use save_excursion_{save,restore} here, because they
3892 save point as well as the current buffer; we don't
3893 want to save point, because redisplay may change it,
3894 to accommodate a Fset_window_start or something. We
3895 don't want to do this at the top of the function,
3896 because we may get input from a subprocess which
3897 wants to change the selected window and stuff (say,
3899 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
3901 set_buffer_internal (XBUFFER (XWINDOW (window
)->buffer
));
3902 goto replay_sequence
;
3904 else if (XTYPE (posn
) == Lisp_Symbol
)
3906 /* Expand mode-line and scroll-bar events into two events:
3907 use posn as a fake prefix key. */
3909 if (t
+ 1 >= bufsize
)
3910 error ("key sequence too long");
3915 /* Zap the position in key, so we know that we've
3916 expanded it, and don't try to do so again. */
3917 POSN_BUFFER_POSN (EVENT_START (key
))
3918 = Fcons (posn
, Qnil
);
3922 else if (EQ (kind
, Qswitch_frame
))
3924 /* If we're at the beginning of a key sequence, go
3925 ahead and return this event. If we're in the
3926 midst of a key sequence, delay it until the end. */
3929 delayed_switch_frame
= key
;
3935 Lisp_Object posn
= POSN_BUFFER_POSN (EVENT_START (key
));
3937 /* Handle menu-bar events:
3938 insert the dummy prefix event `menu-bar'. */
3939 if (EQ (posn
, Qmenu_bar
))
3941 if (t
+ 1 >= bufsize
)
3942 error ("key sequence too long");
3943 /* Run the Lucid hook. */
3944 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
3945 /* If it has changed current-menubar from previous value,
3946 really recompute the menubar from the value. */
3947 if (! NILP (Vlucid_menu_bar_dirty_flag
))
3948 call0 (Qrecompute_lucid_menubar
);
3952 /* Zap the position in key, so we know that we've
3953 expanded it, and don't try to do so again. */
3954 POSN_BUFFER_POSN (EVENT_START (key
))
3955 = Fcons (posn
, Qnil
);
3958 goto replay_sequence
;
3960 else if (XTYPE (posn
) == Lisp_Cons
)
3962 /* We're looking at the second event of a
3963 sequence which we expanded before. Set
3964 last_real_key_start appropriately. */
3965 if (last_real_key_start
== t
&& t
> 0)
3966 last_real_key_start
= t
- 1;
3971 /* We have finally decided that KEY is something we might want
3973 first_binding
= (follow_key (key
,
3974 nmaps
- first_binding
,
3975 submaps
+ first_binding
,
3976 defs
+ first_binding
,
3977 submaps
+ first_binding
)
3980 /* If KEY wasn't bound, we'll try some fallbacks. */
3981 if (first_binding
>= nmaps
)
3983 Lisp_Object head
= EVENT_HEAD (key
);
3985 if (EQ (head
, Vhelp_char
))
3987 read_key_sequence_cmd
= Vprefix_help_command
;
3989 last_nonmenu_event
= key
;
3993 if (XTYPE (head
) == Lisp_Symbol
)
3995 Lisp_Object breakdown
= parse_modifiers (head
);
3996 int modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
3998 /* We drop unbound `down-' events altogether. */
3999 if (modifiers
& down_modifier
)
4001 /* Dispose of this event by simply jumping back to
4002 replay_key, to get another event.
4004 Note that if this event came from mock input,
4005 then just jumping back to replay_key will just
4006 hand it to us again. So we have to wipe out any
4009 We could delete keybuf[t] and shift everything
4010 after that to the left by one spot, but we'd also
4011 have to fix up any variable that points into
4012 keybuf, and shifting isn't really necessary
4015 Adding prefixes for non-textual mouse clicks
4016 creates two characters of mock input, and both
4017 must be thrown away. If we're only looking at
4018 the prefix now, we can just jump back to
4019 replay_key. On the other hand, if we've already
4020 processed the prefix, and now the actual click
4021 itself is giving us trouble, then we've lost the
4022 state of the keymaps we want to backtrack to, and
4023 we need to replay the whole sequence to rebuild
4026 Beyond that, only function key expansion could
4027 create more than two keys, but that should never
4028 generate mouse events, so it's okay to zero
4029 mock_input in that case too.
4031 Isn't this just the most wonderful code ever? */
4032 if (t
== last_real_key_start
)
4039 mock_input
= last_real_key_start
;
4040 goto replay_sequence
;
4044 /* We turn unbound `drag-' events into `click-'
4045 events, if the click would be bound. */
4046 else if (modifiers
& (drag_modifier
| double_modifier
4049 while (modifiers
& (drag_modifier
| double_modifier
4052 Lisp_Object new_head
, new_click
;
4053 if (modifiers
& triple_modifier
)
4054 modifiers
^= (double_modifier
| triple_modifier
);
4056 modifiers
&= ~(drag_modifier
| double_modifier
);
4058 apply_modifiers (modifiers
, XCONS (breakdown
)->car
);
4060 Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
4062 /* Look for a binding for this new key. follow_key
4063 promises that it didn't munge submaps the
4064 last time we called it, since key was unbound. */
4066 (follow_key (new_click
,
4067 nmaps
- local_first_binding
,
4068 submaps
+ local_first_binding
,
4069 defs
+ local_first_binding
,
4070 submaps
+ local_first_binding
)
4071 + local_first_binding
);
4073 /* If that click is bound, go for it. */
4074 if (first_binding
< nmaps
)
4079 /* Otherwise, we'll leave key set to the drag event. */
4086 /* Normally, last_nonmenu_event gets the previous key we read.
4087 But when a mouse popup menu is being used,
4088 we don't update last_nonmenu_event; it continues to hold the mouse
4089 event that preceded the first level of menu. */
4090 if (!used_mouse_menu
)
4091 last_nonmenu_event
= key
;
4093 /* If the sequence is unbound, see if we can hang a function key
4094 off the end of it. We only want to scan real keyboard input
4095 for function key sequences, so if mock_input says that we're
4096 re-reading old events, don't examine it. */
4097 if (first_binding
>= nmaps
4100 Lisp_Object fkey_next
;
4102 /* Scan from fkey_end until we find a bound suffix. */
4103 while (fkey_end
< t
)
4107 key
= keybuf
[fkey_end
++];
4108 /* Look up meta-characters by prefixing them
4109 with meta_prefix_char. I hate this. */
4110 if (XTYPE (key
) == Lisp_Int
&& XINT (key
) & meta_modifier
)
4115 (access_keymap (fkey_map
, meta_prefix_char
, 1, 0)),
4117 XFASTINT (key
) = XFASTINT (key
) & ~meta_modifier
;
4120 fkey_next
= fkey_map
;
4123 = get_keyelt (access_keymap (fkey_next
, key
, 1, 0));
4125 /* If keybuf[fkey_start..fkey_end] is bound in the
4126 function key map and it's a suffix of the current
4127 sequence (i.e. fkey_end == t), replace it with
4128 the binding and restart with fkey_start at the end. */
4129 if (XTYPE (fkey_next
) == Lisp_Vector
4132 t
= fkey_start
+ XVECTOR (fkey_next
)->size
;
4134 error ("key sequence too long");
4136 bcopy (XVECTOR (fkey_next
)->contents
,
4137 keybuf
+ fkey_start
,
4138 (t
- fkey_start
) * sizeof (keybuf
[0]));
4141 fkey_start
= fkey_end
= t
;
4142 fkey_map
= Vfunction_key_map
;
4144 goto replay_sequence
;
4147 fkey_map
= get_keymap_1 (fkey_next
, 0, 1);
4149 /* If we no longer have a bound suffix, try a new positions for
4151 if (NILP (fkey_map
))
4153 fkey_end
= ++fkey_start
;
4154 fkey_map
= Vfunction_key_map
;
4160 read_key_sequence_cmd
= (first_binding
< nmaps
4161 ? defs
[first_binding
]
4165 unread_switch_frame
= delayed_switch_frame
;
4166 unbind_to (count
, Qnil
);
4168 /* Occasionally we fabricate events, perhaps by expanding something
4169 according to function-key-map, or by adding a prefix symbol to a
4170 mouse click in the scroll bar or modeline. In this cases, return
4171 the entire generated key sequence, even if we hit an unbound
4172 prefix or a definition before the end. This means that you will
4173 be able to push back the event properly, and also means that
4174 read-key-sequence will always return a logical unit.
4177 for (; t
< mock_input
; t
++)
4179 echo_char (keybuf
[t
]);
4180 add_command_key (keybuf
[t
]);
4186 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 2, 0,
4187 "Read a sequence of keystrokes and return as a string or vector.\n\
4188 The sequence is sufficient to specify a non-prefix command in the\n\
4189 current local and global maps.\n\
4191 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
4192 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
4193 as a continuation of the previous key.\n\
4195 A C-g typed while in this function is treated like any other character,\n\
4196 and `quit-flag' is not set.\n\
4198 If the key sequence starts with a mouse click, then the sequence is read\n\
4199 using the keymaps of the buffer of the window clicked in, not the buffer\n\
4200 of the selected window as normal.\n\
4202 `read-key-sequence' drops unbound button-down events, since you normally\n\
4203 only care about the click or drag events which follow them. If a drag\n\
4204 or multi-click event is unbound, but the corresponding click event would\n\
4205 be bound, `read-key-sequence' turns the event into a click event at the\n\
4206 drag's starting position. This means that you don't have to distinguish\n\
4207 between click and drag, double, or triple events unless you want to.\n\
4209 `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\
4210 lines separating windows, and scroll bars with imaginary keys\n\
4211 `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\
4213 If the user switches frames in the middle of a key sequence, the\n\
4214 frame-switch event is put off until after the current key sequence.\n\
4216 `read-key-sequence' checks `function-key-map' for function key\n\
4217 sequences, where they wouldn't conflict with ordinary bindings. See\n\
4218 `function-key-map' for more details.")
4219 (prompt
, continue_echo
)
4220 Lisp_Object prompt
, continue_echo
;
4222 Lisp_Object keybuf
[30];
4224 struct gcpro gcpro1
, gcpro2
;
4227 CHECK_STRING (prompt
, 0);
4230 bzero (keybuf
, sizeof keybuf
);
4232 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
4234 if (NILP (continue_echo
))
4235 this_command_key_count
= 0;
4237 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
4238 NILP (prompt
) ? 0 : XSTRING (prompt
)->data
);
4241 return make_event_array (i
, keybuf
);
4244 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 2, 0,
4245 "Execute CMD as an editor command.\n\
4246 CMD must be a symbol that satisfies the `commandp' predicate.\n\
4247 Optional second arg RECORD-FLAG non-nil\n\
4248 means unconditionally put this command in `command-history'.\n\
4249 Otherwise, that is done only if an arg is read using the minibuffer.")
4251 Lisp_Object cmd
, record
;
4253 register Lisp_Object final
;
4254 register Lisp_Object tem
;
4255 Lisp_Object prefixarg
;
4256 struct backtrace backtrace
;
4257 extern int debug_on_next_call
;
4259 prefixarg
= Vprefix_arg
, Vprefix_arg
= Qnil
;
4260 Vcurrent_prefix_arg
= prefixarg
;
4261 debug_on_next_call
= 0;
4263 if (XTYPE (cmd
) == Lisp_Symbol
)
4265 tem
= Fget (cmd
, Qdisabled
);
4267 return call1 (Vrun_hooks
, Vdisabled_command_hook
);
4272 final
= Findirect_function (cmd
);
4274 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
4275 do_autoload (final
, cmd
);
4280 if (XTYPE (final
) == Lisp_String
4281 || XTYPE (final
) == Lisp_Vector
)
4283 /* If requested, place the macro in the command history. For
4284 other sorts of commands, call-interactively takes care of
4288 = Fcons (Fcons (Qexecute_kbd_macro
,
4289 Fcons (final
, Fcons (prefixarg
, Qnil
))),
4292 return Fexecute_kbd_macro (final
, prefixarg
);
4294 if (CONSP (final
) || XTYPE (final
) == Lisp_Subr
4295 || XTYPE (final
) == Lisp_Compiled
)
4297 backtrace
.next
= backtrace_list
;
4298 backtrace_list
= &backtrace
;
4299 backtrace
.function
= &Qcall_interactively
;
4300 backtrace
.args
= &cmd
;
4301 backtrace
.nargs
= 1;
4302 backtrace
.evalargs
= 0;
4304 tem
= Fcall_interactively (cmd
, record
);
4306 backtrace_list
= backtrace
.next
;
4312 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
4314 "Read function name, then read its arguments and call it.")
4316 Lisp_Object prefixarg
;
4318 Lisp_Object function
;
4320 Lisp_Object saved_keys
;
4321 struct gcpro gcpro1
;
4323 saved_keys
= Fthis_command_keys ();
4325 GCPRO1 (saved_keys
);
4327 if (EQ (prefixarg
, Qminus
))
4329 else if (CONSP (prefixarg
) && XINT (XCONS (prefixarg
)->car
) == 4)
4330 strcpy (buf
, "C-u ");
4331 else if (CONSP (prefixarg
) && XTYPE (XCONS (prefixarg
)->car
) == Lisp_Int
)
4332 sprintf (buf
, "%d ", XINT (XCONS (prefixarg
)->car
));
4333 else if (XTYPE (prefixarg
) == Lisp_Int
)
4334 sprintf (buf
, "%d ", XINT (prefixarg
));
4336 /* This isn't strictly correct if execute-extended-command
4337 is bound to anything else. Perhaps it should use
4338 this_command_keys? */
4339 strcat (buf
, "M-x ");
4341 /* Prompt with buf, and then read a string, completing from and
4342 restricting to the set of all defined commands. Don't provide
4343 any initial input. The last Qnil says not to perform a
4344 peculiar hack on the initial input. */
4345 function
= Fcompleting_read (build_string (buf
),
4346 Vobarray
, Qcommandp
,
4349 /* Set this_command_keys to the concatenation of saved_keys and
4350 function, followed by a RET. */
4352 struct Lisp_String
*str
;
4356 this_command_key_count
= 0;
4358 str
= XSTRING (saved_keys
);
4359 for (i
= 0; i
< str
->size
; i
++)
4361 XFASTINT (tem
) = str
->data
[i
];
4362 add_command_key (tem
);
4365 str
= XSTRING (function
);
4366 for (i
= 0; i
< str
->size
; i
++)
4368 XFASTINT (tem
) = str
->data
[i
];
4369 add_command_key (tem
);
4372 XFASTINT (tem
) = '\015';
4373 add_command_key (tem
);
4378 function
= Fintern (function
, Qnil
);
4379 Vprefix_arg
= prefixarg
;
4380 this_command
= function
;
4382 return Fcommand_execute (function
, Qt
);
4386 detect_input_pending ()
4389 get_input_pending (&input_pending
);
4391 return input_pending
;
4394 /* This is called in some cases before a possible quit.
4395 It cases the next call to detect_input_pending to recompute input_pending.
4396 So calling this function unnecessarily can't do any harm. */
4397 clear_input_pending ()
4402 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
4403 "T if command input is currently available with no waiting.\n\
4404 Actually, the value is nil only if we can be sure that no input is available.")
4407 if (!NILP (unread_command_events
) || unread_command_char
!= -1)
4410 return detect_input_pending () ? Qt
: Qnil
;
4413 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
4414 "Return vector of last 100 events, not counting those from keyboard macros.")
4417 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
4420 if (total_keys
< NUM_RECENT_KEYS
)
4421 return Fvector (total_keys
, keys
);
4424 val
= Fvector (NUM_RECENT_KEYS
, keys
);
4425 bcopy (keys
+ recent_keys_index
,
4426 XVECTOR (val
)->contents
,
4427 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
4429 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
4430 recent_keys_index
* sizeof (Lisp_Object
));
4435 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
4436 "Return the key sequence that invoked this command.\n\
4437 The value is a string or a vector.")
4440 return make_event_array (this_command_key_count
,
4441 XVECTOR (this_command_keys
)->contents
);
4444 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
4445 "Return the current depth in recursive edits.")
4449 XFASTINT (temp
) = command_loop_level
+ minibuf_level
;
4453 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
4454 "FOpen dribble file: ",
4455 "Start writing all keyboard characters to a dribble file called FILE.\n\
4456 If FILE is nil, close any open dribble file.")
4467 file
= Fexpand_file_name (file
, Qnil
);
4468 dribble
= fopen (XSTRING (file
)->data
, "w");
4473 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
4474 "Discard the contents of the terminal input buffer.\n\
4475 Also cancel any kbd macro being defined.")
4478 defining_kbd_macro
= 0;
4479 update_mode_lines
++;
4481 unread_command_events
= Qnil
;
4482 unread_command_char
= -1;
4484 discard_tty_input ();
4486 /* Without the cast, GCC complains that this assignment loses the
4487 volatile qualifier of kbd_store_ptr. Is there anything wrong
4489 kbd_fetch_ptr
= (struct input_event
*) kbd_store_ptr
;
4490 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
4496 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
4497 "Stop Emacs and return to superior process. You can resume later.\n\
4498 On systems that don't have job control, run a subshell instead.\n\n\
4499 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
4500 to be read as terminal input by Emacs's parent, after suspension.\n\
4502 Before suspending, call the functions in `suspend-hook' with no args.\n\
4503 If any of them returns nil, don't call the rest and don't suspend.\n\
4504 Otherwise, suspend normally and after resumption run the normal hook\n\
4505 `suspend-resume-hook' if that is bound and non-nil.\n\
4507 Some operating systems cannot stop the Emacs process and resume it later.\n\
4508 On such systems, Emacs starts a subshell instead of suspending.")
4510 Lisp_Object stuffstring
;
4513 int count
= specpdl_ptr
- specpdl
;
4514 int old_height
, old_width
;
4516 struct gcpro gcpro1
, gcpro2
;
4517 extern init_sys_modes ();
4519 if (!NILP (stuffstring
))
4520 CHECK_STRING (stuffstring
, 0);
4522 /* Run the functions in suspend-hook. */
4523 if (!NILP (Vrun_hooks
))
4524 call1 (Vrun_hooks
, intern ("suspend-hook"));
4526 GCPRO1 (stuffstring
);
4527 get_frame_size (&old_width
, &old_height
);
4529 /* sys_suspend can get an error if it tries to fork a subshell
4530 and the system resources aren't available for that. */
4531 record_unwind_protect (init_sys_modes
, 0);
4532 stuff_buffered_input (stuffstring
);
4534 unbind_to (count
, Qnil
);
4536 /* Check if terminal/window size has changed.
4537 Note that this is not useful when we are running directly
4538 with a window system; but suspend should be disabled in that case. */
4539 get_frame_size (&width
, &height
);
4540 if (width
!= old_width
|| height
!= old_height
)
4541 change_frame_size (0, height
, width
, 0, 0);
4543 /* Run suspend-resume-hook. */
4544 if (!NILP (Vrun_hooks
))
4545 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
4551 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
4552 Then in any case stuff anything Emacs has read ahead and not used. */
4554 stuff_buffered_input (stuffstring
)
4555 Lisp_Object stuffstring
;
4557 register unsigned char *p
;
4559 /* stuff_char works only in BSD, versions 4.2 and up. */
4562 if (XTYPE (stuffstring
) == Lisp_String
)
4566 p
= XSTRING (stuffstring
)->data
;
4567 count
= XSTRING (stuffstring
)->size
;
4572 /* Anything we have read ahead, put back for the shell to read. */
4573 while (kbd_fetch_ptr
!= kbd_store_ptr
)
4575 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
4576 kbd_fetch_ptr
= kbd_buffer
;
4577 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
4578 stuff_char (XINT (kbd_fetch_ptr
->code
));
4579 kbd_fetch_ptr
->kind
= no_event
;
4580 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_fetch_ptr
4587 #endif /* BSD and not BSD4_1 */
4590 set_waiting_for_input (time_to_clear
)
4591 EMACS_TIME
*time_to_clear
;
4593 input_available_clear_time
= time_to_clear
;
4595 /* Tell interrupt_signal to throw back to read_char, */
4596 waiting_for_input
= 1;
4598 /* If interrupt_signal was called before and buffered a C-g,
4599 make it run again now, to avoid timing error. */
4600 if (!NILP (Vquit_flag
))
4601 quit_throw_to_read_char ();
4603 /* If alarm has gone off already, echo now. */
4611 clear_waiting_for_input ()
4613 /* Tell interrupt_signal not to throw back to read_char, */
4614 waiting_for_input
= 0;
4615 input_available_clear_time
= 0;
4618 /* This routine is called at interrupt level in response to C-G.
4619 If interrupt_input, this is the handler for SIGINT.
4620 Otherwise, it is called from kbd_buffer_store_event,
4621 in handling SIGIO or SIGTINT.
4623 If `waiting_for_input' is non zero, then unless `echoing' is nonzero,
4624 immediately throw back to read_char.
4626 Otherwise it sets the Lisp variable quit-flag not-nil.
4627 This causes eval to throw, when it gets a chance.
4628 If quit-flag is already non-nil, it stops the job right away. */
4634 /* Must preserve main program's value of errno. */
4635 int old_errno
= errno
;
4638 /* USG systems forget handlers when they are used;
4639 must reestablish each time */
4640 signal (SIGINT
, interrupt_signal
);
4641 signal (SIGQUIT
, interrupt_signal
);
4646 if (!NILP (Vquit_flag
) && FRAME_TERMCAP_P (selected_frame
))
4651 #ifdef SIGTSTP /* Support possible in later USG versions */
4653 * On systems which can suspend the current process and return to the original
4654 * shell, this command causes the user to end up back at the shell.
4655 * The "Auto-save" and "Abort" questions are not asked until
4656 * the user elects to return to emacs, at which point he can save the current
4657 * job and either dump core or continue.
4662 if (sys_suspend () == -1)
4664 printf ("Not running as a subprocess;\n");
4665 printf ("you can continue or abort.\n");
4668 /* Perhaps should really fork an inferior shell?
4669 But that would not provide any way to get back
4670 to the original shell, ever. */
4671 printf ("No support for stopping a process on this operating system;\n");
4672 printf ("you can continue or abort.\n");
4673 #endif /* not VMS */
4674 #endif /* not SIGTSTP */
4675 printf ("Auto-save? (y or n) ");
4677 if (((c
= getchar ()) & ~040) == 'Y')
4678 Fdo_auto_save (Qnil
, Qnil
);
4679 while (c
!= '\n') c
= getchar ();
4681 printf ("Abort (and enter debugger)? (y or n) ");
4683 printf ("Abort (and dump core)? (y or n) ");
4684 #endif /* not VMS */
4686 if (((c
= getchar ()) & ~040) == 'Y')
4688 while (c
!= '\n') c
= getchar ();
4689 printf ("Continuing...\n");
4695 /* If executing a function that wants to be interrupted out of
4696 and the user has not deferred quitting by binding `inhibit-quit'
4697 then quit right away. */
4698 if (immediate_quit
&& NILP (Vinhibit_quit
))
4702 Fsignal (Qquit
, Qnil
);
4705 /* Else request quit when it's safe */
4709 if (waiting_for_input
&& !echoing
)
4710 quit_throw_to_read_char ();
4715 /* Handle a C-g by making read_char return C-g. */
4717 quit_throw_to_read_char ()
4719 quit_error_check ();
4721 /* Prevent another signal from doing this before we finish. */
4722 clear_waiting_for_input ();
4725 unread_command_events
= Qnil
;
4726 unread_command_char
= -1;
4728 #ifdef POLL_FOR_INPUT
4729 /* May be > 1 if in recursive minibuffer. */
4730 if (poll_suppress_count
== 0)
4734 _longjmp (getcjmp
, 1);
4737 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
4738 "Set mode of reading keyboard input.\n\
4739 First arg INTERRUPT non-nil means use input interrupts;\n\
4740 nil means use CBREAK mode.\n\
4741 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
4742 (no effect except in CBREAK mode).\n\
4743 Third arg META t means accept 8-bit input (for a Meta key).\n\
4744 META nil means ignore the top bit, on the assumption it is parity.\n\
4745 Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\
4746 Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\
4747 See also `current-input-mode'.")
4748 (interrupt
, flow
, meta
, quit
)
4749 Lisp_Object interrupt
, flow
, meta
, quit
;
4752 && (XTYPE (quit
) != Lisp_Int
4753 || XINT (quit
) < 0 || XINT (quit
) > 0400))
4754 error ("set-input-mode: QUIT must be an ASCII character.");
4758 /* Note SIGIO has been undef'd if FIONREAD is missing. */
4759 #ifdef NO_SOCK_SIGIO
4760 if (read_socket_hook
)
4761 interrupt_input
= 0; /* No interrupts if reading from a socket. */
4763 #endif /* NO_SOCK_SIGIO */
4764 interrupt_input
= !NILP (interrupt
);
4765 #else /* not SIGIO */
4766 interrupt_input
= 0;
4767 #endif /* not SIGIO */
4768 /* Our VMS input only works by interrupts, as of now. */
4770 interrupt_input
= 1;
4772 flow_control
= !NILP (flow
);
4775 else if (EQ (meta
, Qt
))
4780 /* Don't let this value be out of range. */
4781 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
4787 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
4788 "Return information about the way Emacs currently reads keyboard input.\n\
4789 The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
4790 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\
4791 nil, Emacs is using CBREAK mode.\n\
4792 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\
4793 terminal; this does not apply if Emacs uses interrupt-driven input.\n\
4794 META is t if accepting 8-bit input with 8th bit as Meta flag.\n\
4795 META nil means ignoring the top bit, on the assumption it is parity.\n\
4796 META is neither t nor nil if accepting 8-bit input and using\n\
4797 all 8 bits as the character code.\n\
4798 QUIT is the character Emacs currently uses to quit.\n\
4799 The elements of this list correspond to the arguments of\n\
4805 val
[0] = interrupt_input
? Qt
: Qnil
;
4806 val
[1] = flow_control
? Qt
: Qnil
;
4807 val
[2] = meta_key
== 2 ? make_number (0) : meta_key
== 1 ? Qt
: Qnil
;
4808 XFASTINT (val
[3]) = quit_char
;
4810 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
4816 /* This is correct before outermost invocation of the editor loop */
4817 command_loop_level
= -1;
4819 quit_char
= Ctl ('g');
4820 unread_command_events
= Qnil
;
4821 unread_command_char
= -1;
4823 recent_keys_index
= 0;
4824 kbd_fetch_ptr
= kbd_buffer
;
4825 kbd_store_ptr
= kbd_buffer
;
4826 do_mouse_tracking
= 0;
4830 /* This means that command_loop_1 won't try to select anything the first
4832 internal_last_event_frame
= Qnil
;
4833 Vlast_event_frame
= internal_last_event_frame
;
4836 /* If we're running a dumped Emacs, we need to clear out
4837 kbd_buffer_frame_or_window, in case some events got into it
4840 If we're running an undumped Emacs, it hasn't been initialized by
4841 syms_of_keyboard yet. */
4843 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
4845 if (!noninteractive
)
4847 signal (SIGINT
, interrupt_signal
);
4848 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
4849 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
4850 SIGQUIT and we can't tell which one it will give us. */
4851 signal (SIGQUIT
, interrupt_signal
);
4852 #endif /* HAVE_TERMIO */
4853 /* Note SIGIO has been undef'd if FIONREAD is missing. */
4855 signal (SIGIO
, input_available_signal
);
4859 /* Use interrupt input by default, if it works and noninterrupt input
4860 has deficiencies. */
4862 #ifdef INTERRUPT_INPUT
4863 interrupt_input
= 1;
4865 interrupt_input
= 0;
4868 /* Our VMS input only works by interrupts, as of now. */
4870 interrupt_input
= 1;
4876 if (keyboard_init_hook
)
4877 (*keyboard_init_hook
) ();
4879 #ifdef POLL_FOR_INPUT
4880 poll_suppress_count
= 1;
4885 /* This type's only use is in syms_of_keyboard, to initialize the
4886 event header symbols and put properties on them. */
4893 struct event_head head_table
[] = {
4894 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
4895 &Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
,
4896 &Qswitch_frame
, "switch-frame", &Qswitch_frame
,
4901 Qself_insert_command
= intern ("self-insert-command");
4902 staticpro (&Qself_insert_command
);
4904 Qforward_char
= intern ("forward-char");
4905 staticpro (&Qforward_char
);
4907 Qbackward_char
= intern ("backward-char");
4908 staticpro (&Qbackward_char
);
4910 Qdisabled
= intern ("disabled");
4911 staticpro (&Qdisabled
);
4913 Qpre_command_hook
= intern ("pre-command-hook");
4914 staticpro (&Qpre_command_hook
);
4916 Qpost_command_hook
= intern ("post-command-hook");
4917 staticpro (&Qpost_command_hook
);
4919 Qfunction_key
= intern ("function-key");
4920 staticpro (&Qfunction_key
);
4921 Qmouse_click
= intern ("mouse-click");
4922 staticpro (&Qmouse_click
);
4924 Qmenu_enable
= intern ("menu-enable");
4925 staticpro (&Qmenu_enable
);
4927 Qmode_line
= intern ("mode-line");
4928 staticpro (&Qmode_line
);
4929 Qvertical_line
= intern ("vertical-line");
4930 staticpro (&Qvertical_line
);
4931 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
4932 staticpro (&Qvertical_scroll_bar
);
4933 Qmenu_bar
= intern ("menu-bar");
4934 staticpro (&Qmenu_bar
);
4936 Qabove_handle
= intern ("above-handle");
4937 staticpro (&Qabove_handle
);
4938 Qhandle
= intern ("handle");
4939 staticpro (&Qhandle
);
4940 Qbelow_handle
= intern ("below-handle");
4941 staticpro (&Qbelow_handle
);
4943 Qevent_kind
= intern ("event-kind");
4944 staticpro (&Qevent_kind
);
4945 Qevent_symbol_elements
= intern ("event-symbol-elements");
4946 staticpro (&Qevent_symbol_elements
);
4947 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
4948 staticpro (&Qevent_symbol_element_mask
);
4949 Qmodifier_cache
= intern ("modifier-cache");
4950 staticpro (&Qmodifier_cache
);
4952 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
4953 staticpro (&Qrecompute_lucid_menubar
);
4954 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
4955 staticpro (&Qactivate_menubar_hook
);
4958 struct event_head
*p
;
4960 for (p
= head_table
;
4961 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
4964 *p
->var
= intern (p
->name
);
4966 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
4967 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
4971 button_down_location
= Fmake_vector (make_number (NUM_MOUSE_BUTTONS
), Qnil
);
4972 staticpro (&button_down_location
);
4976 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
4978 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
4979 for (i
= 0; i
< len
; i
++)
4980 if (modifier_names
[i
])
4981 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
4982 staticpro (&modifier_symbols
);
4985 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
4986 staticpro (&recent_keys
);
4988 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
4989 staticpro (&this_command_keys
);
4991 kbd_buffer_frame_or_window
4992 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
4993 staticpro (&kbd_buffer_frame_or_window
);
4995 func_key_syms
= Qnil
;
4996 staticpro (&func_key_syms
);
4999 staticpro (&mouse_syms
);
5001 unread_switch_frame
= Qnil
;
5002 staticpro (&unread_switch_frame
);
5004 defsubr (&Sread_key_sequence
);
5005 defsubr (&Srecursive_edit
);
5006 defsubr (&Strack_mouse
);
5007 defsubr (&Sinput_pending_p
);
5008 defsubr (&Scommand_execute
);
5009 defsubr (&Srecent_keys
);
5010 defsubr (&Sthis_command_keys
);
5011 defsubr (&Ssuspend_emacs
);
5012 defsubr (&Sabort_recursive_edit
);
5013 defsubr (&Sexit_recursive_edit
);
5014 defsubr (&Srecursion_depth
);
5015 defsubr (&Stop_level
);
5016 defsubr (&Sdiscard_input
);
5017 defsubr (&Sopen_dribble_file
);
5018 defsubr (&Sset_input_mode
);
5019 defsubr (&Scurrent_input_mode
);
5020 defsubr (&Sexecute_extended_command
);
5022 DEFVAR_LISP ("disabled-command-hook", &Vdisabled_command_hook
,
5023 "Value is called instead of any command that is disabled\n\
5024 \(has a non-nil `disabled' property).");
5026 DEFVAR_LISP ("last-command-char", &last_command_char
,
5027 "Last input event that was part of a command.");
5029 DEFVAR_LISP ("last-command-event", &last_command_char
,
5030 "Last input event that was part of a command.");
5032 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
5033 "Last input event in a command, except for mouse menu events.\n\
5034 Mouse menus give back keys that don't look like mouse events;\n\
5035 this variable holds the actual mouse event that led to the menu,\n\
5036 so that you can determine whether the command was run by mouse or not.");
5038 DEFVAR_LISP ("last-input-char", &last_input_char
,
5039 "Last input event.");
5041 DEFVAR_LISP ("last-input-event", &last_input_char
,
5042 "Last input event.");
5044 DEFVAR_LISP ("unread-command-events", &unread_command_events
,
5045 "List of objects to be read as next command input events.");
5047 DEFVAR_INT ("unread-command-char", &unread_command_char
,
5048 "If not -1, an object to be read as next command input event.");
5050 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
5051 "Meta-prefix character code. Meta-foo as command input\n\
5052 turns into this character followed by foo.");
5053 XSET (meta_prefix_char
, Lisp_Int
, 033);
5055 DEFVAR_LISP ("last-command", &last_command
,
5056 "The last command executed. Normally a symbol with a function definition,\n\
5057 but can be whatever was found in the keymap, or whatever the variable\n\
5058 `this-command' was set to by that command.");
5059 last_command
= Qnil
;
5061 DEFVAR_LISP ("this-command", &this_command
,
5062 "The command now being executed.\n\
5063 The command can set this variable; whatever is put here\n\
5064 will be in `last-command' during the following command.");
5065 this_command
= Qnil
;
5067 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
5068 "*Number of keyboard input characters between auto-saves.\n\
5069 Zero means disable autosaving due to number of characters typed.");
5070 auto_save_interval
= 300;
5072 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
5073 "*Number of seconds idle time before auto-save.\n\
5074 Zero or nil means disable auto-saving due to idleness.\n\
5075 After auto-saving due to this many seconds of idle time,\n\
5076 Emacs also does a garbage collection if that seems to be warranted.");
5077 XFASTINT (Vauto_save_timeout
) = 30;
5079 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes
,
5080 "*Nonzero means echo unfinished commands after this many seconds of pause.");
5081 echo_keystrokes
= 1;
5083 DEFVAR_INT ("polling-period", &polling_period
,
5084 "*Interval between polling for input during Lisp execution.\n\
5085 The reason for polling is to make C-g work to stop a running program.\n\
5086 Polling is needed only when using X windows and SIGIO does not work.\n\
5087 Polling is automatically disabled in all other cases.");
5090 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
5091 "*Maximum time between mouse clicks to make a double-click.\n\
5092 Measured in milliseconds. nil means disable double-click recognition;\n\
5093 t means double-clicks have no time limit and are detected\n\
5094 by position only.");
5095 Vdouble_click_time
= make_number (500);
5097 DEFVAR_INT ("num-input-keys", &num_input_keys
,
5098 "*Number of complete keys read from the keyboard so far.");
5102 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
5103 "*The frame in which the most recently read event occurred.\n\
5104 If the last event came from a keyboard macro, this is set to `macro'.");
5105 Vlast_event_frame
= Qnil
;
5108 DEFVAR_LISP ("help-char", &Vhelp_char
,
5109 "Character to recognize as meaning Help.\n\
5110 When it is read, do `(eval help-form)', and display result if it's a string.\n\
5111 If the value of `help-form' is nil, this char can be read normally.");
5112 XSET (Vhelp_char
, Lisp_Int
, Ctl ('H'));
5114 DEFVAR_LISP ("help-form", &Vhelp_form
,
5115 "Form to execute when character `help-char' is read.\n\
5116 If the form returns a string, that string is displayed.\n\
5117 If `help-form' is nil, the help char is not recognized.");
5120 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
5121 "Command to run when `help-char' character follows a prefix key.\n\
5122 This command is used only when there is no actual binding\n\
5123 for that character after that prefix key.");
5124 Vprefix_help_command
= Qnil
;
5126 DEFVAR_LISP ("top-level", &Vtop_level
,
5127 "Form to evaluate when Emacs starts up.\n\
5128 Useful to set before you dump a modified Emacs.");
5131 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
5132 "String used as translate table for keyboard input, or nil.\n\
5133 Each character is looked up in this string and the contents used instead.\n\
5134 If string is of length N, character codes N and up are untranslated.");
5135 Vkeyboard_translate_table
= Qnil
;
5137 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
5138 "Non-nil means prompt with menus when appropriate.\n\
5139 This is done when reading from a keymap that has a prompt string,\n\
5140 for elements that have prompt strings.\n\
5141 The menu is displayed on the screen\n\
5142 if X menus were enabled at configuration\n\
5143 time and the previous event was a mouse click prefix key.\n\
5144 Otherwise, menu prompting uses the echo area.");
5147 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
5148 "Character to see next line of menu prompt.\n\
5149 Type this character while in a menu prompt to rotate around the lines of it.");
5150 XSET (menu_prompt_more_char
, Lisp_Int
, ' ');
5152 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
5153 "A mask of additional modifier keys to use with every keyboard character.\n\
5154 Emacs applies the modifiers of the character stored here to each keyboard\n\
5155 character it reads. For example, after evaluating the expression\n\
5156 (setq extra-keyboard-modifiers ?\C-x)\n\
5157 all input characters will have the control modifier applied to them.\n\
5159 Note that the character ?\C-@, equivalent to the integer zero, does\n\
5160 not count as a control character; rather, it counts as a character\n\
5161 with no modifiers; thus, setting extra_keyboard_modifiers to zero\n\
5162 cancels any modification.");
5163 extra_keyboard_modifiers
= 0;
5165 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
5166 "If an editing command sets this to t, deactivate the mark afterward.\n\
5167 The command loop sets this to nil before each command,\n\
5168 and tests the value when the command returns.\n\
5169 Buffer modification stores t in this variable.");
5170 Vdeactivate_mark
= Qnil
;
5172 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
5173 "Normal hook run before each command is executed.");
5174 Vpre_command_hook
= Qnil
;
5176 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
5177 "Normal hook run after each command is executed.");
5178 Vpost_command_hook
= Qnil
;
5180 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
5181 "t means menu bar, specified Lucid style, needs to be recomputed.");
5182 Vlucid_menu_bar_dirty_flag
= Qnil
;
5187 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
5188 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
5189 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
5190 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
5191 initial_define_key (meta_map
, 'x', "execute-extended-command");