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 help_char
;
127 /* Form to execute when help char is typed. */
128 Lisp_Object Vhelp_form
;
130 /* Character that causes a quit. Normally C-g.
132 If we are running on an ordinary terminal, this must be an ordinary
133 ASCII char, since we want to make it our interrupt character.
135 If we are not running on an ordinary terminal, it still needs to be
136 an ordinary ASCII char. This character needs to be recognized in
137 the input interrupt handler. At this point, the keystroke is
138 represented as a struct input_event, while the desired quit
139 character is specified as a lispy event. The mapping from struct
140 input_events to lispy events cannot run in an interrupt handler,
141 and the reverse mapping is difficult for anything but ASCII
144 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
148 extern Lisp_Object current_global_map
;
149 extern int minibuf_level
;
151 /* Current depth in recursive edits. */
152 int command_loop_level
;
154 /* Total number of times command_loop has read a key sequence. */
157 /* Last input character read as a command. */
158 Lisp_Object last_command_char
;
160 /* Last input character read as a command, not counting menus
161 reached by the mouse. */
162 Lisp_Object last_nonmenu_event
;
164 /* Last input character read for any purpose. */
165 Lisp_Object last_input_char
;
167 /* If not Qnil, a list of objects to be read as subsequent command input. */
168 Lisp_Object unread_command_events
;
170 /* If not -1, an event to be read as subsequent command input. */
171 int unread_command_char
;
173 /* If not Qnil, this is a switch-frame event which we decided to put
174 off until the end of a key sequence. This should be read as the
175 next command input, after any unread_command_events.
177 read_key_sequence uses this to delay switch-frame events until the
178 end of the key sequence; Fread_char uses it to put off switch-frame
179 events until a non-ASCII event is acceptable as input. */
180 Lisp_Object unread_switch_frame
;
182 /* A mask of extra modifier bits to put into every keyboard char. */
183 int extra_keyboard_modifiers
;
185 /* Char to use as prefix when a meta character is typed in.
186 This is bound on entry to minibuffer in case ESC is changed there. */
188 Lisp_Object meta_prefix_char
;
190 /* Last size recorded for a current buffer which is not a minibuffer. */
191 static int last_non_minibuf_size
;
193 /* Number of idle seconds before an auto-save and garbage collection. */
194 static Lisp_Object Vauto_save_timeout
;
196 /* Total number of times read_char has returned. */
199 /* Total number of times read_char has returned, outside of macros. */
200 int num_nonmacro_input_chars
;
202 /* Auto-save automatically when this many characters have been typed
203 since the last time. */
205 static int auto_save_interval
;
207 /* Value of num_nonmacro_input_chars as of last auto save. */
211 /* Last command executed by the editor command loop, not counting
212 commands that set the prefix argument. */
214 Lisp_Object last_command
;
216 /* The command being executed by the command loop.
217 Commands may set this, and the value set will be copied into last_command
218 instead of the actual command. */
219 Lisp_Object this_command
;
222 /* The frame in which the last input event occurred, or Qmacro if the
223 last event came from a macro. We use this to determine when to
224 generate switch-frame events. This may be cleared by functions
225 like Fselect_frame, to make sure that a switch-frame event is
226 generated by the next character. */
227 Lisp_Object internal_last_event_frame
;
229 /* A user-visible version of the above, intended to allow users to
230 figure out where the last event came from, if the event doesn't
231 carry that information itself (i.e. if it was a character). */
232 Lisp_Object Vlast_event_frame
;
235 /* The timestamp of the last input event we received from the X server.
236 X Windows wants this for selection ownership. */
237 unsigned long last_event_timestamp
;
239 Lisp_Object Qself_insert_command
;
240 Lisp_Object Qforward_char
;
241 Lisp_Object Qbackward_char
;
243 /* read_key_sequence stores here the command definition of the
244 key sequence that it reads. */
245 Lisp_Object read_key_sequence_cmd
;
247 /* Form to evaluate (if non-nil) when Emacs is started. */
248 Lisp_Object Vtop_level
;
250 /* User-supplied string to translate input characters through. */
251 Lisp_Object Vkeyboard_translate_table
;
253 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
254 extern Lisp_Object Vfunction_key_map
;
256 /* Non-nil means deactivate the mark at end of this command. */
257 Lisp_Object Vdeactivate_mark
;
259 /* Menu bar specified in Lucid Emacs fashion. */
261 Lisp_Object Vlucid_menu_bar_dirty_flag
;
262 Lisp_Object Qrecompute_lucid_menubar
, Qactivate_menubar_hook
;
264 /* Hooks to run before and after each command. */
265 Lisp_Object Qpre_command_hook
, Qpost_command_hook
;
266 Lisp_Object Vpre_command_hook
, Vpost_command_hook
;
268 /* File in which we write all commands we read. */
271 /* Nonzero if input is available. */
274 /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
275 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
279 extern char *pending_malloc_warning
;
281 /* Circular buffer for pre-read keyboard input. */
282 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
284 /* Vector to GCPRO the frames and windows mentioned in kbd_buffer.
286 The interrupt-level event handlers will never enqueue an event on a
287 frame which is not in Vframe_list, and once an event is dequeued,
288 internal_last_event_frame or the event itself points to the frame.
291 But while the event is sitting in the queue, it's completely
292 unprotected. Suppose the user types one command which will run for
293 a while and then delete a frame, and then types another event at
294 the frame that will be deleted, before the command gets around to
295 it. Suppose there are no references to this frame elsewhere in
296 Emacs, and a GC occurs before the second event is dequeued. Now we
297 have an event referring to a freed frame, which will crash Emacs
300 Similar things happen when an event on a scroll bar is enqueued; the
301 window may be deleted while the event is in the queue.
303 So, we use this vector to protect the frame_or_window field in the
304 event queue. That way, they'll be dequeued as dead frames or
305 windows, but still valid lisp objects.
307 If kbd_buffer[i].kind != no_event, then
308 (XVECTOR (kbd_buffer_frame_or_window)->contents[i]
309 == kbd_buffer[i].frame_or_window. */
310 static Lisp_Object kbd_buffer_frame_or_window
;
312 /* Pointer to next available character in kbd_buffer.
313 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
314 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the
315 next available char is in kbd_buffer[0]. */
316 static struct input_event
*kbd_fetch_ptr
;
318 /* Pointer to next place to store character in kbd_buffer. This
319 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
320 character should go in kbd_buffer[0]. */
324 static struct input_event
*kbd_store_ptr
;
326 /* The above pair of variables forms a "queue empty" flag. When we
327 enqueue a non-hook event, we increment kbd_write_count. When we
328 dequeue a non-hook event, we increment kbd_read_count. We say that
329 there is input available iff the two counters are not equal.
331 Why not just have a flag set and cleared by the enqueuing and
332 dequeuing functions? Such a flag could be screwed up by interrupts
333 at inopportune times. */
335 /* If this flag is non-zero, we check mouse_moved to see when the
336 mouse moves, and motion events will appear in the input stream. If
337 it is zero, mouse motion is ignored. */
338 static int do_mouse_tracking
;
340 /* The window system handling code should set this if the mouse has
341 moved since the last call to the mouse_position_hook. Calling that
342 hook should clear this. Code assumes that if this is set, it can
343 call mouse_position_hook to get the promised position, so don't set
344 it unless you're prepared to substantiate the claim! */
347 /* True iff there is an event in kbd_buffer, or if mouse tracking is
348 enabled and there is a new mouse position in the mouse movement
349 buffer. Note that if this is false, that doesn't mean that there
350 is readable input; all the events in the queue might be button-up
351 events, and do_mouse_tracking might be off. */
352 #define EVENT_QUEUES_EMPTY \
353 ((kbd_fetch_ptr == kbd_store_ptr) && (!do_mouse_tracking || !mouse_moved))
356 /* Symbols to head events. */
357 Lisp_Object Qmouse_movement
;
358 Lisp_Object Qscroll_bar_movement
;
359 Lisp_Object Qswitch_frame
;
361 /* Symbols to denote kinds of events. */
362 Lisp_Object Qfunction_key
;
363 Lisp_Object Qmouse_click
;
364 /* Lisp_Object Qmouse_movement; - also an event header */
366 /* Properties of event headers. */
367 Lisp_Object Qevent_kind
;
368 Lisp_Object Qevent_symbol_elements
;
370 Lisp_Object Qmenu_enable
;
372 /* An event header symbol HEAD may have a property named
373 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
374 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
375 mask of modifiers applied to it. If present, this is used to help
376 speed up parse_modifiers. */
377 Lisp_Object Qevent_symbol_element_mask
;
379 /* An unmodified event header BASE may have a property named
380 Qmodifier_cache, which is an alist mapping modifier masks onto
381 modified versions of BASE. If present, this helps speed up
383 Lisp_Object Qmodifier_cache
;
385 /* Symbols to use for parts of windows. */
386 Lisp_Object Qmode_line
;
387 Lisp_Object Qvertical_line
;
388 Lisp_Object Qvertical_scroll_bar
;
389 Lisp_Object Qmenu_bar
;
391 extern Lisp_Object Qmenu_enable
;
393 Lisp_Object
recursive_edit_unwind (), command_loop ();
394 Lisp_Object
Fthis_command_keys ();
396 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
398 EMACS_TIME
*input_available_clear_time
;
400 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
401 Default is 1 if INTERRUPT_INPUT is defined. */
404 /* Nonzero while interrupts are temporarily deferred during redisplay. */
405 int interrupts_deferred
;
407 /* nonzero means use ^S/^Q for flow control. */
410 /* Allow m- file to inhibit use of FIONREAD. */
411 #ifdef BROKEN_FIONREAD
415 /* We are unable to use interrupts if FIONREAD is not available,
416 so flush SIGIO so we won't try. */
423 /* If we support X Windows, and won't get an interrupt when input
424 arrives from the server, poll periodically so we can detect C-g. */
425 #ifdef HAVE_X_WINDOWS
427 #define POLL_FOR_INPUT
431 /* Global variable declarations. */
433 /* Function for init_keyboard to call with no args (if nonzero). */
434 void (*keyboard_init_hook
) ();
436 static int read_avail_input ();
437 static void get_input_pending ();
438 static Lisp_Object
read_char_menu_prompt ();
440 /* > 0 if we are to echo keystrokes. */
441 static int echo_keystrokes
;
443 /* Nonzero means echo each character as typed. */
444 static int immediate_echo
;
446 /* The text we're echoing in the modeline - partial key sequences,
447 usually. '\0'-terminated. This really shouldn't have a fixed size. */
448 static char echobuf
[300];
450 /* Where to append more text to echobuf if we want to. */
451 static char *echoptr
;
453 #define min(a,b) ((a)<(b)?(a):(b))
454 #define max(a,b) ((a)>(b)?(a):(b))
456 /* Install the string STR as the beginning of the string of echoing,
457 so that it serves as a prompt for the next character.
458 Also start echoing. */
463 int len
= strlen (str
);
464 if (len
> sizeof echobuf
- 4)
465 len
= sizeof echobuf
- 4;
466 bcopy (str
, echobuf
, len
);
467 echoptr
= echobuf
+ len
;
473 /* Add C to the echo string, if echoing is going on.
474 C can be a character, which is printed prettily ("M-C-x" and all that
475 jazz), or a symbol, whose name is printed. */
480 extern char *push_key_description ();
489 /* If someone has passed us a composite event, use its head symbol. */
492 if (XTYPE (c
) == Lisp_Int
)
494 if (ptr
- echobuf
> sizeof echobuf
- 6)
497 ptr
= push_key_description (XINT (c
), ptr
);
499 else if (XTYPE (c
) == Lisp_Symbol
)
501 struct Lisp_String
*name
= XSYMBOL (c
)->name
;
502 if (((ptr
- echobuf
) + name
->size
+ 4) > sizeof echobuf
)
504 bcopy (name
->data
, ptr
, name
->size
);
508 if (echoptr
== echobuf
&& EQ (c
, help_char
))
510 strcpy (ptr
, " (Type ? for further options)");
521 /* Temporarily add a dash to the end of the echo string if it's not
522 empty, so that it serves as a mini-prompt for the very next character. */
526 if (!immediate_echo
&& echoptr
== echobuf
)
528 /* Do nothing if not echoing at all. */
532 /* Put a dash at the end of the buffer temporarily,
533 but make it go away when the next character is added. */
540 /* Display the current echo string, and begin echoing if not already
550 for (i
= 0; i
< this_command_key_count
; i
++)
551 echo_char (XVECTOR (this_command_keys
)->contents
[i
]);
559 if (waiting_for_input
&& !NILP (Vquit_flag
))
560 quit_throw_to_read_char ();
563 /* Turn off echoing, for the start of a new command. */
571 /* Return the length of the current echo string. */
576 return echoptr
- echobuf
;
579 /* Truncate the current echo message to its first LEN chars.
580 This and echo_char get used by read_key_sequence when the user
581 switches frames while entering a key sequence. */
588 echoptr
= echobuf
+ len
;
592 /* Functions for manipulating this_command_keys. */
594 add_command_key (key
)
597 int size
= XVECTOR (this_command_keys
)->size
;
599 if (this_command_key_count
>= size
)
601 Lisp_Object new_keys
= Fmake_vector (make_number (size
* 2), Qnil
);
603 bcopy (XVECTOR (this_command_keys
)->contents
,
604 XVECTOR (new_keys
)->contents
,
605 size
* sizeof (Lisp_Object
));
607 this_command_keys
= new_keys
;
610 XVECTOR (this_command_keys
)->contents
[this_command_key_count
++] = key
;
616 int count
= specpdl_ptr
- specpdl
;
619 if (command_loop_level
> 0)
621 specbind (Qstandard_output
, Qt
);
622 specbind (Qstandard_input
, Qt
);
625 val
= command_loop ();
627 Fsignal (Qquit
, Qnil
);
629 return unbind_to (count
, Qnil
);
632 /* When an auto-save happens, record the "time", and don't do again soon. */
635 last_auto_save
= num_nonmacro_input_chars
;
638 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
639 "Invoke the editor command loop recursively.\n\
640 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
641 that tells this function to return.\n\
642 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
643 This function is called by the editor initialization to begin editing.")
646 int count
= specpdl_ptr
- specpdl
;
649 command_loop_level
++;
650 update_mode_lines
= 1;
652 record_unwind_protect (recursive_edit_unwind
,
654 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
658 return unbind_to (count
, Qnil
);
662 recursive_edit_unwind (buffer
)
666 Fset_buffer (buffer
);
668 command_loop_level
--;
669 update_mode_lines
= 1;
677 Lisp_Object errmsg
, tail
, errname
, file_error
;
684 Vstandard_output
= Qt
;
685 Vstandard_input
= Qt
;
686 Vexecuting_macro
= Qnil
;
687 echo_area_glyphs
= 0;
689 /* If the window system or terminal frame hasn't been initialized
690 yet, or we're not interactive, it's best to dump this message out
691 to stderr and exit. */
692 if (! FRAME_MESSAGE_BUF (selected_frame
)
694 stream
= Qexternal_debugging_output
;
702 errname
= Fcar (data
);
704 if (EQ (errname
, Qerror
))
707 if (!CONSP (data
)) data
= Qnil
;
708 errmsg
= Fcar (data
);
713 errmsg
= Fget (errname
, Qerror_message
);
714 file_error
= Fmemq (Qfile_error
,
715 Fget (errname
, Qerror_conditions
));
718 /* Print an error message including the data items.
719 This is done by printing it into a scratch buffer
720 and then making a copy of the text in the buffer. */
722 if (!CONSP (data
)) data
= Qnil
;
726 /* For file-error, make error message by concatenating
727 all the data items. They are all strings. */
728 if (!NILP (file_error
) && !NILP (tail
))
729 errmsg
= XCONS (tail
)->car
, tail
= XCONS (tail
)->cdr
;
731 if (XTYPE (errmsg
) == Lisp_String
)
732 Fprinc (errmsg
, stream
);
734 write_string_1 ("peculiar error", -1, stream
);
736 for (i
= 0; CONSP (tail
); tail
= Fcdr (tail
), i
++)
738 write_string_1 (i
? ", " : ": ", 2, stream
);
739 if (!NILP (file_error
))
740 Fprinc (Fcar (tail
), stream
);
742 Fprin1 (Fcar (tail
), stream
);
746 /* If the window system or terminal frame hasn't been initialized
747 yet, or we're in -batch mode, this error should cause Emacs to exit. */
748 if (! FRAME_MESSAGE_BUF (selected_frame
)
752 Fkill_emacs (make_number (-1));
757 Vinhibit_quit
= Qnil
;
758 return make_number (0);
761 Lisp_Object
command_loop_1 ();
762 Lisp_Object
command_loop_2 ();
763 Lisp_Object
top_level_1 ();
765 /* Entry to editor-command-loop.
766 This level has the catches for exiting/returning to editor command loop.
767 It returns nil to exit recursive edit, t to abort it. */
772 if (command_loop_level
> 0 || minibuf_level
> 0)
774 return internal_catch (Qexit
, command_loop_2
, Qnil
);
779 internal_catch (Qtop_level
, top_level_1
, Qnil
);
780 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
782 /* End of file in -batch run causes exit here. */
788 /* Here we catch errors in execution of commands within the
789 editing loop, and reenter the editing loop.
790 When there is an error, cmd_error runs and returns a non-nil
791 value to us. A value of nil means that cmd_loop_1 itself
792 returned due to end of file (or end of kbd macro). */
797 register Lisp_Object val
;
800 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
809 return Feval (Vtop_level
);
815 /* On entry to the outer level, run the startup file */
816 if (!NILP (Vtop_level
))
817 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
818 else if (!NILP (Vpurify_flag
))
819 message ("Bare impure Emacs (standard Lisp code not loaded)");
821 message ("Bare Emacs (standard Lisp code not loaded)");
825 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
826 "Exit all recursive editing levels.")
829 Fthrow (Qtop_level
, Qnil
);
832 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
833 "Exit from the innermost recursive edit or minibuffer.")
836 if (command_loop_level
> 0 || minibuf_level
> 0)
837 Fthrow (Qexit
, Qnil
);
839 error ("No recursive edit is in progress");
842 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
843 "Abort the command that requested this recursive edit or minibuffer input.")
846 if (command_loop_level
> 0 || minibuf_level
> 0)
849 error ("No recursive edit is in progress");
852 /* This is the actual command reading loop,
853 sans error-handling encapsulation. */
855 Lisp_Object
Fcommand_execute ();
856 static int read_key_sequence ();
861 Lisp_Object cmd
, tem
;
864 Lisp_Object keybuf
[30];
869 struct buffer
*prev_buffer
;
872 Vdeactivate_mark
= Qnil
;
873 waiting_for_input
= 0;
876 /* Don't clear out last_command at the beginning of a macro. */
877 if (XTYPE (Vexecuting_macro
) != Lisp_String
)
882 this_command_key_count
= 0;
886 /* Install chars successfully executed in kbd macro. */
888 if (defining_kbd_macro
&& NILP (Vprefix_arg
))
889 finalize_kbd_macro_chars ();
891 /* Make sure the current window's buffer is selected. */
892 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
893 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
895 /* Display any malloc warning that just came out. Use while because
896 displaying one warning can cause another. */
898 while (pending_malloc_warning
)
899 display_malloc_warning ();
903 Vdeactivate_mark
= Qnil
;
905 /* If minibuffer on and echo area in use,
906 wait 2 sec and redraw minibuffer. */
908 if (minibuf_level
&& echo_area_glyphs
)
910 /* Bind inhibit-quit to t so that C-g gets read in
911 rather than quitting back to the minibuffer. */
912 int count
= specpdl_ptr
- specpdl
;
913 specbind (Qinhibit_quit
, Qt
);
914 Fsit_for (make_number (2), Qnil
, Qnil
);
915 unbind_to (count
, Qnil
);
917 echo_area_glyphs
= 0;
919 if (!NILP (Vquit_flag
))
922 unread_command_events
= Fcons (make_number (quit_char
), Qnil
);
927 alloca (0); /* Cause a garbage collection now */
928 /* Since we can free the most stuff here. */
929 #endif /* C_ALLOCA */
933 /* Select the frame that the last event came from. Usually,
934 switch-frame events will take care of this, but if some lisp
935 code swallows a switch-frame event, we'll fix things up here.
936 Is this a good idea? */
937 if (XTYPE (internal_last_event_frame
) == Lisp_Frame
938 && XFRAME (internal_last_event_frame
) != selected_frame
)
939 Fselect_frame (internal_last_event_frame
, Qnil
);
942 /* If it has changed current-menubar from previous value,
943 really recompute the menubar from the value. */
944 if (! NILP (Vlucid_menu_bar_dirty_flag
))
945 call0 (Qrecompute_lucid_menubar
);
947 #if 0 /* This is done in xdisp.c now. */
949 for (tem
= Vframe_list
; CONSP (tem
); tem
= XCONS (tem
)->cdr
)
951 struct frame
*f
= XFRAME (XCONS (tem
)->car
);
952 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
954 /* If the user has switched buffers or windows, we need to
955 recompute to reflect the new bindings. But we'll
956 recompute when update_mode_lines is set too; that means
957 that people can use force-mode-line-update to request
958 that the menu bar be recomputed. The adverse effect on
959 the rest of the redisplay algorithm is about the same as
960 windows_or_buffers_changed anyway. */
961 if (windows_or_buffers_changed
963 || (XFASTINT (w
->last_modified
) < MODIFF
964 && (XFASTINT (w
->last_modified
)
965 <= XBUFFER (w
->buffer
)->save_modified
)))
967 struct buffer
*prev
= current_buffer
;
968 current_buffer
= XBUFFER (w
->buffer
);
969 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items ();
970 current_buffer
= prev
;
973 #endif /* MULTI_FRAME */
976 /* Read next key sequence; i gets its length. */
977 i
= read_key_sequence (keybuf
, (sizeof keybuf
/ sizeof (keybuf
[0])), 0);
981 /* Now we have read a key sequence of length I,
982 or else I is 0 and we found end of file. */
984 if (i
== 0) /* End of file -- happens only in */
985 return Qnil
; /* a kbd macro, at the end. */
987 last_command_char
= keybuf
[i
- 1];
989 /* If the previous command tried to force a specific window-start,
990 forget about that, in case this command moves point far away
991 from that position. */
992 XWINDOW (selected_window
)->force_start
= Qnil
;
994 cmd
= read_key_sequence_cmd
;
995 if (!NILP (Vexecuting_macro
))
997 if (!NILP (Vquit_flag
))
999 Vexecuting_macro
= Qt
;
1000 QUIT
; /* Make some noise. */
1001 /* Will return since macro now empty. */
1005 /* Do redisplay processing after this command except in special
1006 cases identified below that set no_redisplay to 1. */
1009 prev_buffer
= current_buffer
;
1010 prev_modiff
= MODIFF
;
1012 /* Execute the command. */
1015 if (!NILP (Vpre_command_hook
))
1016 call1 (Vrun_hooks
, Qpre_command_hook
);
1018 if (NILP (this_command
))
1020 /* nil means key is undefined. */
1022 defining_kbd_macro
= 0;
1023 update_mode_lines
= 1;
1029 if (NILP (Vprefix_arg
) && ! no_direct
)
1031 /* Recognize some common commands in common situations and
1032 do them directly. */
1033 if (EQ (this_command
, Qforward_char
) && point
< ZV
)
1035 struct Lisp_Vector
*dp
1036 = window_display_table (XWINDOW (selected_window
));
1037 lose
= FETCH_CHAR (point
);
1040 ? (XTYPE (DISP_CHAR_VECTOR (dp
, lose
)) != Lisp_Vector
1041 && XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1)
1042 : (lose
>= 0x20 && lose
< 0x7f))
1043 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1045 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1047 && !windows_or_buffers_changed
1048 && EQ (current_buffer
->selective_display
, Qnil
)
1049 && !detect_input_pending ()
1050 && NILP (Vexecuting_macro
))
1051 no_redisplay
= direct_output_forward_char (1);
1054 else if (EQ (this_command
, Qbackward_char
) && point
> BEGV
)
1056 struct Lisp_Vector
*dp
1057 = window_display_table (XWINDOW (selected_window
));
1059 lose
= FETCH_CHAR (point
);
1061 ? (XTYPE (DISP_CHAR_VECTOR (dp
, lose
)) != Lisp_Vector
1062 && XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1)
1063 : (lose
>= 0x20 && lose
< 0x7f))
1064 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1066 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1068 && !windows_or_buffers_changed
1069 && EQ (current_buffer
->selective_display
, Qnil
)
1070 && !detect_input_pending ()
1071 && NILP (Vexecuting_macro
))
1072 no_redisplay
= direct_output_forward_char (-1);
1075 else if (EQ (this_command
, Qself_insert_command
)
1076 /* Try this optimization only on ascii keystrokes. */
1077 && XTYPE (last_command_char
) == Lisp_Int
)
1079 unsigned char c
= XINT (last_command_char
);
1081 if (NILP (Vexecuting_macro
) &&
1082 !EQ (minibuf_window
, selected_window
))
1084 if (!nonundocount
|| nonundocount
>= 20)
1091 lose
= (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1093 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1095 || MODIFF
<= current_buffer
->save_modified
1096 || windows_or_buffers_changed
1097 || !EQ (current_buffer
->selective_display
, Qnil
)
1098 || detect_input_pending ()
1099 || !NILP (Vexecuting_macro
);
1100 if (internal_self_insert (c
, 0))
1106 (point
== ZV
|| FETCH_CHAR (point
) == '\n'))
1108 struct Lisp_Vector
*dp
1109 = window_display_table (XWINDOW (selected_window
));
1114 Lisp_Object obj
= DISP_CHAR_VECTOR (dp
, lose
);
1116 if (XTYPE (obj
) == Lisp_Vector
1117 && XVECTOR (obj
)->size
== 1
1118 && (XTYPE (obj
= XVECTOR (obj
)->contents
[0])
1121 direct_output_for_insert (XINT (obj
));
1125 if (lose
>= 0x20 && lose
<= 0x7e)
1126 no_redisplay
= direct_output_for_insert (lose
);
1133 /* Here for a command that isn't executed directly */
1136 if (NILP (Vprefix_arg
))
1138 Fcommand_execute (this_command
, Qnil
);
1143 if (!NILP (Vpost_command_hook
))
1144 call1 (Vrun_hooks
, Qpost_command_hook
);
1146 /* If there is a prefix argument,
1147 1) We don't want last_command to be ``universal-argument''
1148 (that would be dumb), so don't set last_command,
1149 2) we want to leave echoing on so that the prefix will be
1150 echoed as part of this key sequence, so don't call
1152 3) we want to leave this_command_key_count non-zero, so that
1153 read_char will realize that it is re-reading a character, and
1154 not echo it a second time. */
1155 if (NILP (Vprefix_arg
))
1157 last_command
= this_command
;
1159 this_command_key_count
= 0;
1162 if (!NILP (current_buffer
->mark_active
))
1164 if (!NILP (Vdeactivate_mark
) && !NILP (Vtransient_mark_mode
))
1166 current_buffer
->mark_active
= Qnil
;
1167 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
1169 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
1170 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
1175 /* Number of seconds between polling for input. */
1178 /* Nonzero means polling for input is temporarily suppressed. */
1179 int poll_suppress_count
;
1181 #ifdef POLL_FOR_INPUT
1182 int polling_for_input
;
1184 /* Handle an alarm once each second and read pending input
1185 so as to handle a C-g if it comces in. */
1188 input_poll_signal ()
1190 if (interrupt_input_blocked
== 0
1191 && !waiting_for_input
)
1192 read_avail_input (0);
1193 signal (SIGALRM
, input_poll_signal
);
1194 alarm (polling_period
);
1199 /* Begin signals to poll for input, if they are appropriate.
1200 This function is called unconditionally from various places. */
1204 #ifdef POLL_FOR_INPUT
1205 if (read_socket_hook
)
1207 poll_suppress_count
--;
1208 if (poll_suppress_count
== 0)
1210 signal (SIGALRM
, input_poll_signal
);
1211 polling_for_input
= 1;
1212 alarm (polling_period
);
1218 /* Turn off polling. */
1222 #ifdef POLL_FOR_INPUT
1223 if (read_socket_hook
)
1225 if (poll_suppress_count
== 0)
1227 polling_for_input
= 0;
1230 poll_suppress_count
++;
1235 /* Applying the control modifier to CHARACTER. */
1240 /* Save the upper bits here. */
1241 int upper
= c
& ~0177;
1245 /* Everything in the columns containing the upper-case letters
1246 denotes a control character. */
1247 if (c
>= 0100 && c
< 0140)
1251 /* Set the shift modifier for a control char
1252 made from a shifted letter. But only for letters! */
1253 if (oc
>= 'A' && oc
<= 'Z')
1254 c
|= shift_modifier
;
1257 /* The lower-case letters denote control characters too. */
1258 else if (c
>= 'a' && c
<= 'z')
1261 /* Include the bits for control and shift
1262 only if the basic ASCII code can't indicate them. */
1266 /* Replace the high bits. */
1267 c
|= (upper
& ~ctrl_modifier
);
1274 /* Input of single characters from keyboard */
1276 Lisp_Object
print_help ();
1277 static Lisp_Object
kbd_buffer_get_event ();
1279 /* read a character from the keyboard; call the redisplay if needed */
1280 /* commandflag 0 means do not do auto-saving, but do do redisplay.
1281 -1 means do not do redisplay, but do do autosaving.
1284 /* The arguments MAPS and NMAPS are for menu prompting.
1285 MAPS is an array of keymaps; NMAPS is the length of MAPS.
1287 PREV_EVENT is the previous input event, or nil if we are reading
1288 the first event of a key sequence.
1290 If USED_MOUSE_MENU is non-zero, then we set *USED_MOUSE_MENU to 1
1291 if we used a mouse menu to read the input, or zero otherwise. If
1292 USED_MOUSE_MENU is zero, *USED_MOUSE_MENU is left alone. */
1295 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
)
1299 Lisp_Object prev_event
;
1300 int *used_mouse_menu
;
1302 register Lisp_Object c
;
1306 if (CONSP (unread_command_events
))
1308 c
= XCONS (unread_command_events
)->car
;
1309 unread_command_events
= XCONS (unread_command_events
)->cdr
;
1311 if (this_command_key_count
== 0)
1317 if (unread_command_char
!= -1)
1319 XSET (c
, Lisp_Int
, unread_command_char
);
1320 unread_command_char
= -1;
1322 if (this_command_key_count
== 0)
1328 if (!NILP (Vexecuting_macro
))
1331 /* We set this to Qmacro; since that's not a frame, nobody will
1332 try to switch frames on us, and the selected window will
1335 Since this event came from a macro, it would be misleading to
1336 leave internal_last_event_frame set to wherever the last
1337 real event came from. Normally, a switch-frame event selects
1338 internal_last_event_frame after each command is read, but
1339 events read from a macro should never cause a new frame to be
1341 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
1344 /* Exit the macro if we are at the end.
1345 Also, some things replace the macro with t
1346 to force an early exit. */
1347 if (EQ (Vexecuting_macro
, Qt
)
1348 || executing_macro_index
>= XFASTINT (Flength (Vexecuting_macro
)))
1350 XSET (c
, Lisp_Int
, -1);
1354 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
1355 if (XTYPE (Vexecuting_macro
) == Lisp_String
1356 && (XINT (c
) & 0x80))
1357 XFASTINT (c
) = CHAR_META
| (XINT (c
) & ~0x80);
1359 executing_macro_index
++;
1364 if (!NILP (unread_switch_frame
))
1366 c
= unread_switch_frame
;
1367 unread_switch_frame
= Qnil
;
1369 /* This event should make it into this_command_keys, and get echoed
1370 again, so we go to reread_first, rather than reread. */
1374 /* Save outer setjmp data, in case called recursively. */
1375 save_getcjmp (save_jump
);
1379 if (commandflag
>= 0 && !input_pending
&& !detect_input_pending ())
1382 if (_setjmp (getcjmp
))
1384 XSET (c
, Lisp_Int
, quit_char
);
1386 XSET (internal_last_event_frame
, Lisp_Frame
, selected_frame
);
1387 Vlast_event_frame
= internal_last_event_frame
;
1389 /* If we report the quit char as an event,
1390 don't do so more than once. */
1391 if (!NILP (Vinhibit_quit
))
1397 /* Message turns off echoing unless more keystrokes turn it on again. */
1398 if (echo_area_glyphs
&& *echo_area_glyphs
&& echo_area_glyphs
!= echobuf
)
1401 /* If already echoing, continue. */
1404 /* If in middle of key sequence and minibuffer not active,
1405 start echoing if enough time elapses. */
1406 if (minibuf_level
== 0 && !immediate_echo
&& this_command_key_count
> 0
1407 && echo_keystrokes
> 0
1408 && (echo_area_glyphs
== 0 || *echo_area_glyphs
== 0))
1412 /* After a mouse event, start echoing right away.
1413 This is because we are probably about to display a menu,
1414 and we don't want to delay before doing so. */
1415 if (EVENT_HAS_PARAMETERS (prev_event
))
1419 tem0
= sit_for (echo_keystrokes
, 0, 1, 1);
1425 /* Maybe auto save due to number of keystrokes or idle time. */
1427 if (commandflag
!= 0
1428 && auto_save_interval
> 0
1429 && num_nonmacro_input_chars
- last_auto_save
> max (auto_save_interval
, 20)
1430 && !detect_input_pending ())
1433 save_getcjmp (temp
);
1434 Fdo_auto_save (Qnil
, Qnil
);
1435 restore_getcjmp (temp
);
1438 /* Try reading a character via menu prompting.
1439 Try this before the sit-for, because the sit-for
1440 would do the wrong thing if we are supposed to do
1443 if (INTERACTIVE
&& !NILP (prev_event
))
1444 c
= read_char_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
1446 /* Slow down auto saves logarithmically in size of current buffer,
1447 and garbage collect while we're at it. */
1450 int delay_level
, buffer_size
;
1452 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
1453 last_non_minibuf_size
= Z
- BEG
;
1454 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
1456 while (buffer_size
> 64)
1457 delay_level
++, buffer_size
-= buffer_size
>> 2;
1458 if (delay_level
< 4) delay_level
= 4;
1459 /* delay_level is 4 for files under around 50k, 7 at 100k,
1460 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
1462 /* Auto save if enough time goes by without input. */
1463 if (commandflag
!= 0
1464 && num_nonmacro_input_chars
> last_auto_save
1465 && XTYPE (Vauto_save_timeout
) == Lisp_Int
1466 && XINT (Vauto_save_timeout
) > 0)
1469 int delay
= delay_level
* XFASTINT (Vauto_save_timeout
) / 4;
1470 tem0
= sit_for (delay
, 0, 1, 1);
1474 save_getcjmp (temp
);
1475 Fdo_auto_save (Qnil
, Qnil
);
1476 restore_getcjmp (temp
);
1478 /* If we have auto-saved and there is still no input
1479 available, garbage collect if there has been enough
1480 consing going on to make it worthwhile. */
1481 if (!detect_input_pending ()
1482 && consing_since_gc
> gc_cons_threshold
/ 2)
1483 Fgarbage_collect ();
1488 /* Actually read a character, waiting if necessary. */
1491 c
= kbd_buffer_get_event ();
1494 if (commandflag
>= 0 && !input_pending
&& !detect_input_pending ())
1498 /* Terminate Emacs in batch mode if at eof. */
1499 if (noninteractive
&& XTYPE (c
) == Lisp_Int
&& XINT (c
) < 0)
1500 Fkill_emacs (make_number (1));
1502 if (XTYPE (c
) == Lisp_Int
)
1504 /* Add in any extra modifiers, where appropriate. */
1505 if ((extra_keyboard_modifiers
& CHAR_CTL
)
1506 || ((extra_keyboard_modifiers
& 0177) < ' '
1507 && (extra_keyboard_modifiers
& 0177) != 0))
1508 XSETINT (c
, make_ctrl_char (XINT (c
)));
1510 /* Transfer any other modifier bits directly from
1511 extra_keyboard_modifiers to c. Ignore the actual character code
1512 in the low 16 bits of extra_keyboard_modifiers. */
1513 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
1518 restore_getcjmp (save_jump
);
1522 echo_area_glyphs
= 0;
1524 /* Handle things that only apply to characters. */
1525 if (XTYPE (c
) == Lisp_Int
)
1527 /* If kbd_buffer_get_event gave us an EOF, return that. */
1531 if (XTYPE (Vkeyboard_translate_table
) == Lisp_String
1532 && XSTRING (Vkeyboard_translate_table
)->size
> XFASTINT (c
))
1533 XSETINT (c
, XSTRING (Vkeyboard_translate_table
)->data
[XFASTINT (c
)]);
1537 XVECTOR (recent_keys
)->contents
[recent_keys_index
] = c
;
1538 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
1539 recent_keys_index
= 0;
1541 /* Write c to the dribble file. If c is a lispy event, write
1542 the event's symbol to the dribble file, in <brackets>. Bleaugh.
1543 If you, dear reader, have a better idea, you've got the source. :-) */
1546 if (XTYPE (c
) == Lisp_Int
)
1547 putc (XINT (c
), dribble
);
1550 Lisp_Object dribblee
= c
;
1552 /* If it's a structured event, take the event header. */
1553 dribblee
= EVENT_HEAD (dribblee
);
1555 if (XTYPE (dribblee
) == Lisp_Symbol
)
1557 putc ('<', dribble
);
1558 fwrite (XSYMBOL (dribblee
)->name
->data
, sizeof (char),
1559 XSYMBOL (dribblee
)->name
->size
,
1561 putc ('>', dribble
);
1568 store_kbd_macro_char (c
);
1570 num_nonmacro_input_chars
++;
1575 /* Record this character as part of the current key.
1576 Don't record mouse motion; it should never matter. */
1577 if (! (EVENT_HAS_PARAMETERS (c
)
1578 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
1581 add_command_key (c
);
1584 /* Re-reading in the middle of a command */
1586 last_input_char
= c
;
1589 /* Process the help character specially if enabled */
1590 if (EQ (c
, help_char
) && !NILP (Vhelp_form
))
1593 count
= specpdl_ptr
- specpdl
;
1595 record_unwind_protect (Fset_window_configuration
,
1596 Fcurrent_window_configuration (Qnil
));
1598 tem0
= Feval (Vhelp_form
);
1599 if (XTYPE (tem0
) == Lisp_String
)
1600 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
1603 c
= read_char (0, 0, 0, Qnil
, 0);
1604 /* Remove the help from the frame */
1605 unbind_to (count
, Qnil
);
1607 if (EQ (c
, make_number (040)))
1610 c
= read_char (0, 0, 0, Qnil
, 0);
1621 Fprinc (object
, Qnil
);
1625 /* Copy out or in the info on where C-g should throw to.
1626 This is used when running Lisp code from within get_char,
1627 in case get_char is called recursively.
1628 See read_process_output. */
1633 bcopy (getcjmp
, temp
, sizeof getcjmp
);
1636 restore_getcjmp (temp
)
1639 bcopy (temp
, getcjmp
, sizeof getcjmp
);
1643 /* Low level keyboard/mouse input.
1644 kbd_buffer_store_event places events in kbd_buffer, and
1645 kbd_buffer_get_event retrieves them.
1646 mouse_moved indicates when the mouse has moved again, and
1647 *mouse_position_hook provides the mouse position. */
1649 /* Set this for debugging, to have a way to get out */
1652 extern int frame_garbaged
;
1654 /* Return true iff there are any events in the queue that read-char
1655 would return. If this returns false, a read-char would block. */
1659 return ! EVENT_QUEUES_EMPTY
;
1663 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
1664 of this function. */
1666 tracking_off (old_value
)
1667 Lisp_Object old_value
;
1669 if (! XFASTINT (old_value
))
1671 do_mouse_tracking
= 0;
1673 /* Redisplay may have been preempted because there was input
1674 available, and it assumes it will be called again after the
1675 input has been processed. If the only input available was
1676 the sort that we have just disabled, then we need to call
1678 if (!readable_events ())
1680 redisplay_preserve_echo_area ();
1681 get_input_pending (&input_pending
);
1686 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
1687 "Evaluate BODY with mouse movement events enabled.\n\
1688 Within a `track-mouse' form, mouse motion generates input events that\n\
1689 you can read with `read-event'.\n\
1690 Normally, mouse motion is ignored.")
1694 int count
= specpdl_ptr
- specpdl
;
1697 XSET (val
, Lisp_Int
, do_mouse_tracking
);
1698 record_unwind_protect (tracking_off
, val
);
1700 do_mouse_tracking
= 1;
1702 val
= Fprogn (args
);
1703 return unbind_to (count
, val
);
1706 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
1709 kbd_buffer_store_event (event
)
1710 register struct input_event
*event
;
1712 if (event
->kind
== no_event
)
1715 if (event
->kind
== ascii_keystroke
)
1717 register int c
= XFASTINT (event
->code
) & 0377;
1719 if (event
->modifiers
& ctrl_modifier
)
1720 c
= make_ctrl_char (c
);
1724 extern SIGTYPE
interrupt_signal ();
1727 /* If this results in a quit_char being returned to Emacs as
1728 input, set Vlast_event_frame properly. If this doesn't
1729 get returned to Emacs as an event, the next event read
1730 will set Vlast_event_frame again, so this is safe to do. */
1733 FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
1736 internal_last_event_frame
= event
->frame_or_window
;
1738 internal_last_event_frame
= focus
;
1739 Vlast_event_frame
= internal_last_event_frame
;
1743 last_event_timestamp
= event
->timestamp
;
1744 interrupt_signal ();
1748 if (c
&& c
== stop_character
)
1754 XSET (event
->code
, Lisp_Int
, c
);
1757 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
1758 kbd_store_ptr
= kbd_buffer
;
1760 /* Don't let the very last slot in the buffer become full,
1761 since that would make the two pointers equal,
1762 and that is indistinguishable from an empty buffer.
1763 Discard the event if it would fill the last slot. */
1764 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
1766 kbd_store_ptr
->kind
= event
->kind
;
1767 kbd_store_ptr
->code
= event
->code
;
1768 kbd_store_ptr
->part
= event
->part
;
1769 kbd_store_ptr
->frame_or_window
= event
->frame_or_window
;
1770 kbd_store_ptr
->modifiers
= event
->modifiers
;
1771 kbd_store_ptr
->x
= event
->x
;
1772 kbd_store_ptr
->y
= event
->y
;
1773 kbd_store_ptr
->timestamp
= event
->timestamp
;
1774 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_store_ptr
1776 = event
->frame_or_window
);
1782 static Lisp_Object
make_lispy_event ();
1783 static Lisp_Object
make_lispy_movement ();
1784 static Lisp_Object
modify_event_symbol ();
1785 static Lisp_Object
make_lispy_switch_frame ();
1788 kbd_buffer_get_event ()
1796 XSET (obj
, Lisp_Int
, c
);
1801 /* Wait until there is input available. */
1804 if (!EVENT_QUEUES_EMPTY
)
1807 /* If the quit flag is set, then read_char will return
1808 quit_char, so that counts as "available input." */
1809 if (!NILP (Vquit_flag
))
1810 quit_throw_to_read_char ();
1812 /* One way or another, wait until input is available; then, if
1813 interrupt handlers have not read it, read it now. */
1816 wait_for_kbd_input ();
1818 /* Note SIGIO has been undef'd if FIONREAD is missing. */
1822 if (EVENT_QUEUES_EMPTY
)
1824 Lisp_Object minus_one
;
1826 XSET (minus_one
, Lisp_Int
, -1);
1827 wait_reading_process_input (0, 0, minus_one
, 1);
1829 if (!interrupt_input
&& EVENT_QUEUES_EMPTY
)
1831 read_avail_input (0);
1834 #endif /* not VMS */
1837 /* At this point, we know that there is a readable event available
1838 somewhere. If the event queue is empty, then there must be a
1839 mouse movement enabled and available. */
1840 if (kbd_fetch_ptr
!= kbd_store_ptr
)
1842 struct input_event
*event
;
1844 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
1848 last_event_timestamp
= event
->timestamp
;
1852 /* These two kinds of events get special handling
1853 and don't actually appear to the command loop. */
1854 if (event
->kind
== selection_request_event
)
1857 x_handle_selection_request (event
);
1858 kbd_fetch_ptr
= event
+ 1;
1860 /* We're getting selection request events, but we don't have
1866 else if (event
->kind
== selection_clear_event
)
1869 x_handle_selection_clear (event
);
1870 kbd_fetch_ptr
= event
+ 1;
1872 /* We're getting selection request events, but we don't have
1878 /* If this event is on a different frame, return a switch-frame this
1879 time, and leave the event in the queue for next time. */
1883 Lisp_Object frame
= event
->frame_or_window
;
1886 if (XTYPE (frame
) == Lisp_Window
)
1887 frame
= WINDOW_FRAME (XWINDOW (frame
));
1889 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
1893 if (! EQ (frame
, internal_last_event_frame
)
1894 && XFRAME (frame
) != selected_frame
)
1895 obj
= make_lispy_switch_frame (frame
);
1896 internal_last_event_frame
= frame
;
1897 #endif /* MULTI_FRAME */
1899 /* If we didn't decide to make a switch-frame event, go ahead
1900 and build a real event from the queue entry. */
1904 obj
= make_lispy_event (event
);
1906 /* Wipe out this event, to catch bugs. */
1907 event
->kind
= no_event
;
1908 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[event
- kbd_buffer
]
1911 kbd_fetch_ptr
= event
+ 1;
1915 else if (do_mouse_tracking
&& mouse_moved
)
1918 Lisp_Object bar_window
;
1919 enum scroll_bar_part part
;
1923 (*mouse_position_hook
) (&f
, &bar_window
, &part
, &x
, &y
, &time
);
1928 /* Decide if we should generate a switch-frame event. Don't
1929 generate switch-frame events for motion outside of all Emacs
1933 Lisp_Object frame
= FRAME_FOCUS_FRAME (f
);
1936 XSET (frame
, Lisp_Frame
, f
);
1938 if (! EQ (frame
, internal_last_event_frame
)
1939 && XFRAME (frame
) != selected_frame
)
1940 obj
= make_lispy_switch_frame (internal_last_event_frame
);
1941 internal_last_event_frame
= frame
;
1945 /* If we didn't decide to make a switch-frame event, go ahead and
1946 return a mouse-motion event. */
1948 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
1951 /* We were promised by the above while loop that there was
1952 something for us to read! */
1956 /* If something gave back nil as the Lispy event,
1957 it means the event was discarded, so try again. */
1962 input_pending
= readable_events ();
1965 Vlast_event_frame
= internal_last_event_frame
;
1971 /* Process any events that are not user-visible. */
1976 while (kbd_fetch_ptr
!= kbd_store_ptr
)
1978 struct input_event
*event
;
1980 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
1984 last_event_timestamp
= event
->timestamp
;
1986 /* These two kinds of events get special handling
1987 and don't actually appear to the command loop. */
1988 if (event
->kind
== selection_request_event
)
1991 x_handle_selection_request (event
);
1992 kbd_fetch_ptr
= event
+ 1;
1994 /* We're getting selection request events, but we don't have
2000 else if (event
->kind
== selection_clear_event
)
2003 x_handle_selection_clear (event
);
2004 kbd_fetch_ptr
= event
+ 1;
2006 /* We're getting selection request events, but we don't have
2015 get_input_pending (&input_pending
);
2018 /* Caches for modify_event_symbol. */
2019 static Lisp_Object func_key_syms
;
2020 static Lisp_Object mouse_syms
;
2022 /* You'll notice that this table is arranged to be conveniently
2023 indexed by X Windows keysym values. */
2024 static char *lispy_function_keys
[] =
2026 /* X Keysym value */
2028 "remove", 0, 0, 0, 0, 0, 0, 0, /* 0xff00 */
2036 0, 0, 0, /* 0xff10 */
2038 0, 0, 0, 0, 0, 0, 0,
2041 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff20...2f */
2042 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff30...3f */
2043 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
2045 "home", /* 0xff50 */ /* IsCursorKey */
2056 "select", /* 0xff60 */ /* IsMiscFunctionKey */
2067 "break", /* 0xff6b */
2069 /* Here are some keys found mostly on HP keyboards. The X event
2070 handling code will strip bit 29, which flags vendor-specific
2072 "reset", /* 0x1000ff6c */
2081 "kp-backtab", /* 0x1000ff75 */
2083 0, 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff7f */
2084 "kp-space", /* 0xff80 */ /* IsKeypadKey */
2085 0, 0, 0, 0, 0, 0, 0, 0,
2086 "kp-tab", /* 0xff89 */
2088 "kp-enter", /* 0xff8d */
2090 "kp-f1", /* 0xff91 */
2095 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2096 "kp-multiply", /* 0xffaa */
2101 "kp-divide", /* 0xffaf */
2102 "kp-0", /* 0xffb0 */
2103 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
2106 "kp-equal", /* 0xffbd */
2107 "f1", /* 0xffbe */ /* IsFunctionKey */
2109 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
2110 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
2111 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
2112 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
2113 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
2114 0, 0, 0, 0, 0, 0, 0, 0,
2115 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
2116 0, 0, 0, 0, 0, 0, 0, "delete"
2119 static char *lispy_mouse_names
[] =
2121 "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5"
2124 /* Scroll bar parts. */
2125 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
2127 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
2128 Lisp_Object
*scroll_bar_parts
[] = {
2129 &Qabove_handle
, &Qhandle
, &Qbelow_handle
2133 /* A vector, indexed by button number, giving the down-going location
2134 of currently depressed buttons, both scroll bar and non-scroll bar.
2136 The elements have the form
2137 (BUTTON-NUMBER MODIFIER-MASK . REST)
2138 where REST is the cdr of a position as it would be reported in the event.
2140 The make_lispy_event function stores positions here to tell the
2141 difference between click and drag events, and to store the starting
2142 location to be included in drag events. */
2144 static Lisp_Object button_down_location
;
2146 /* Information about the most recent up-going button event: Which
2147 button, what location, and what time. */
2149 static int button_up_button
;
2150 static int button_up_x
;
2151 static int button_up_y
;
2152 static unsigned long button_up_time
;
2154 /* The minimum time between clicks to make a double-click. */
2156 int double_click_time
;
2158 /* The number of clicks in this multiple-click. */
2160 int double_click_count
;
2162 /* Given a struct input_event, build the lisp event which represents
2163 it. If EVENT is 0, build a mouse movement event from the mouse
2164 movement buffer, which should have a movement event in it.
2166 Note that events must be passed to this function in the order they
2167 are received; this function stores the location of button presses
2168 in order to build drag events when the button is released. */
2171 make_lispy_event (event
)
2172 struct input_event
*event
;
2174 #ifdef SWITCH_ENUM_BUG
2175 switch ((int) event
->kind
)
2177 switch (event
->kind
)
2180 /* A simple keystroke. */
2181 case ascii_keystroke
:
2183 int c
= XFASTINT (event
->code
);
2184 /* Turn ASCII characters into control characters
2186 if (event
->modifiers
& ctrl_modifier
)
2187 c
= make_ctrl_char (c
);
2189 /* Add in the other modifier bits. We took care of ctrl_modifier
2190 just above, and the shift key was taken care of by the X code,
2191 and applied to control characters by make_ctrl_char. */
2192 c
|= (event
->modifiers
2193 & (meta_modifier
| alt_modifier
2194 | hyper_modifier
| super_modifier
));
2199 /* A function key. The symbol may need to have modifier prefixes
2201 case non_ascii_keystroke
:
2203 return modify_event_symbol (XFASTINT (event
->code
), event
->modifiers
,
2205 lispy_function_keys
, &func_key_syms
,
2206 (sizeof (lispy_function_keys
)
2207 / sizeof (lispy_function_keys
[0])));
2210 /* A mouse click. Figure out where it is, decide whether it's
2211 a press, click or drag, and build the appropriate structure. */
2213 case scroll_bar_click
:
2215 int button
= XFASTINT (event
->code
);
2216 Lisp_Object position
;
2217 Lisp_Object
*start_pos_ptr
;
2218 Lisp_Object start_pos
;
2220 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
2223 /* Build the position as appropriate for this mouse click. */
2224 if (event
->kind
== mouse_click
)
2227 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
2229 = window_from_coordinates (f
, XINT (event
->x
), XINT (event
->y
),
2233 if (XINT (event
->y
) < FRAME_MENU_BAR_LINES (f
))
2237 items
= FRAME_MENU_BAR_ITEMS (f
);
2238 for (; CONSP (items
); items
= XCONS (items
)->cdr
)
2240 Lisp_Object pos
, string
;
2241 pos
= Fcdr (Fcdr (Fcar (items
)));
2242 string
= Fcar (Fcdr (Fcar (items
)));
2243 if (XINT (event
->x
) >= XINT (pos
)
2244 && XINT (event
->x
) < XINT (pos
) + XSTRING (string
)->size
)
2248 = Fcons (event
->frame_or_window
,
2250 Fcons (Fcons (event
->x
, event
->y
),
2251 Fcons (make_number (event
->timestamp
),
2255 return Fcons (Fcar (Fcar (items
)),
2256 Fcons (position
, Qnil
));
2258 return Fcons (Qnil
, Fcons (position
, Qnil
));
2260 else if (XTYPE (window
) != Lisp_Window
)
2265 (XINT (event
->x
) - XINT (XWINDOW (window
)->left
)));
2267 (XINT (event
->y
) - XINT (XWINDOW (window
)->top
)));
2272 posn
= Qvertical_line
;
2274 XSET (posn
, Lisp_Int
,
2275 buffer_posn_from_coords (XWINDOW (window
),
2283 Fcons (Fcons (event
->x
, event
->y
),
2284 Fcons (make_number (event
->timestamp
),
2289 Lisp_Object window
= event
->frame_or_window
;
2290 Lisp_Object portion_whole
= Fcons (event
->x
, event
->y
);
2291 Lisp_Object part
= *scroll_bar_parts
[(int) event
->part
];
2295 Fcons (Qvertical_scroll_bar
,
2296 Fcons (portion_whole
,
2297 Fcons (make_number (event
->timestamp
),
2302 start_pos_ptr
= &XVECTOR (button_down_location
)->contents
[button
];
2304 start_pos
= *start_pos_ptr
;
2305 *start_pos_ptr
= Qnil
;
2307 /* If this is a button press, squirrel away the location, so
2308 we can decide later whether it was a click or a drag. */
2309 if (event
->modifiers
& down_modifier
)
2310 *start_pos_ptr
= Fcopy_alist (position
);
2312 /* Now we're releasing a button - check the co-ordinates to
2313 see if this was a click or a drag. */
2314 else if (event
->modifiers
& up_modifier
)
2316 /* If we did not see a down before this up,
2317 ignore the up. Probably this happened because
2318 the down event chose a menu item.
2319 It would be an annoyance to treat the release
2320 of the button that chose the menu item
2321 as a separate event. */
2323 if (XTYPE (start_pos
) != Lisp_Cons
)
2326 event
->modifiers
&= ~up_modifier
;
2327 #if 0 /* Formerly we treated an up with no down as a click event. */
2328 if (XTYPE (start_pos
) != Lisp_Cons
)
2329 event
->modifiers
|= click_modifier
;
2333 /* The third element of every position should be the (x,y)
2335 Lisp_Object down
= Fnth (make_number (2), start_pos
);
2337 if (EQ (event
->x
, XCONS (down
)->car
)
2338 && EQ (event
->y
, XCONS (down
)->cdr
))
2340 if (button
== button_up_button
2341 && XINT (event
->x
) == button_up_x
2342 && XINT (event
->y
) == button_up_y
2343 && button_up_time
!= 0
2344 && ((int)(event
->timestamp
- button_up_time
)
2345 < double_click_time
))
2347 double_click_count
++;
2348 event
->modifiers
|= ((double_click_count
> 2)
2354 double_click_count
= 1;
2355 event
->modifiers
|= click_modifier
;
2357 button_up_button
= button
;
2358 button_up_x
= XINT (event
->x
);
2359 button_up_y
= XINT (event
->y
);
2360 button_up_time
= event
->timestamp
;
2365 event
->modifiers
|= drag_modifier
;
2370 /* Every mouse event should either have the down_modifier or
2371 the up_modifier set. */
2375 /* Get the symbol we should use for the mouse click. */
2377 = modify_event_symbol (button
,
2380 lispy_mouse_names
, &mouse_syms
,
2381 (sizeof (lispy_mouse_names
)
2382 / sizeof (lispy_mouse_names
[0])));
2384 if (event
->modifiers
& drag_modifier
)
2389 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
2392 Fcons (make_number (double_click_count
),
2401 /* The 'kind' field of the event is something we don't recognize. */
2408 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
2410 Lisp_Object bar_window
;
2411 enum scroll_bar_part part
;
2415 /* Is it a scroll bar movement? */
2416 if (frame
&& ! NILP (bar_window
))
2418 Lisp_Object part_sym
= *scroll_bar_parts
[(int) part
];
2420 return Fcons (Qscroll_bar_movement
,
2421 (Fcons (Fcons (bar_window
,
2422 Fcons (Qvertical_scroll_bar
,
2423 Fcons (Fcons (x
, y
),
2424 Fcons (make_number (time
),
2430 /* Or is it an ordinary mouse movement? */
2434 Lisp_Object window
=
2436 ? window_from_coordinates (frame
, XINT (x
), XINT (y
), &area
)
2440 if (XTYPE (window
) == Lisp_Window
)
2442 XSETINT (x
, XINT (x
) - XINT (XWINDOW (window
)->left
));
2443 XSETINT (y
, XINT (y
) - XINT (XWINDOW (window
)->top
));
2448 posn
= Qvertical_line
;
2450 XSET (posn
, Lisp_Int
,
2451 buffer_posn_from_coords (XWINDOW (window
),
2452 XINT (x
), XINT (y
)));
2462 return Fcons (Qmouse_movement
,
2463 Fcons (Fcons (window
,
2465 Fcons (Fcons (x
, y
),
2466 Fcons (make_number (time
),
2472 /* Construct a switch frame event. */
2474 make_lispy_switch_frame (frame
)
2477 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
2480 /* Manipulating modifiers. */
2482 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
2484 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
2485 SYMBOL's name of the end of the modifiers; the string from this
2486 position is the unmodified symbol name.
2488 This doesn't use any caches. */
2490 parse_modifiers_uncached (symbol
, modifier_end
)
2494 struct Lisp_String
*name
;
2498 CHECK_SYMBOL (symbol
, 1);
2501 name
= XSYMBOL (symbol
)->name
;
2504 for (i
= 0; i
+2 <= name
->size
; )
2505 switch (name
->data
[i
])
2507 #define SINGLE_LETTER_MOD(bit) \
2508 if (name->data[i+1] != '-') \
2509 goto no_more_modifiers; \
2514 SINGLE_LETTER_MOD (alt_modifier
);
2518 SINGLE_LETTER_MOD (ctrl_modifier
);
2522 SINGLE_LETTER_MOD (hyper_modifier
);
2526 SINGLE_LETTER_MOD (meta_modifier
);
2530 SINGLE_LETTER_MOD (shift_modifier
);
2534 SINGLE_LETTER_MOD (super_modifier
);
2538 if (i
+ 5 > name
->size
)
2539 goto no_more_modifiers
;
2540 if (! strncmp (name
->data
+ i
, "drag-", 5))
2542 modifiers
|= drag_modifier
;
2545 else if (! strncmp (name
->data
+ i
, "down-", 5))
2547 modifiers
|= down_modifier
;
2550 else if (i
+ 7 <= name
->size
2551 && ! strncmp (name
->data
+ i
, "double-", 7))
2553 modifiers
|= double_modifier
;
2557 goto no_more_modifiers
;
2561 if (i
+ 7 > name
->size
)
2562 goto no_more_modifiers
;
2563 if (! strncmp (name
->data
+ i
, "triple-", 7))
2565 modifiers
|= triple_modifier
;
2569 goto no_more_modifiers
;
2573 goto no_more_modifiers
;
2575 #undef SINGLE_LETTER_MOD
2579 /* Should we include the `click' modifier? */
2580 if (! (modifiers
& (down_modifier
| drag_modifier
2581 | double_modifier
| triple_modifier
))
2582 && i
+ 7 == name
->size
2583 && strncmp (name
->data
+ i
, "mouse-", 6) == 0
2584 && ('0' <= name
->data
[i
+ 6] && name
->data
[i
+ 6] <= '9'))
2585 modifiers
|= click_modifier
;
2594 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
2595 prepended to the string BASE[0..BASE_LEN-1].
2596 This doesn't use any caches. */
2598 apply_modifiers_uncached (modifiers
, base
, base_len
)
2603 /* Since BASE could contain nulls, we can't use intern here; we have
2604 to use Fintern, which expects a genuine Lisp_String, and keeps a
2607 (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
2613 /* Only the event queue may use the `up' modifier; it should always
2614 be turned into a click or drag event before presented to lisp code. */
2615 if (modifiers
& up_modifier
)
2618 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
2619 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
2620 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
2621 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
2622 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
2623 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
2624 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
2625 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
2626 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
2627 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
2628 /* The click modifier is denoted by the absence of other modifiers. */
2632 mod_len
= p
- new_mods
;
2636 Lisp_Object new_name
= make_uninit_string (mod_len
+ base_len
);
2638 bcopy (new_mods
, XSTRING (new_name
)->data
, mod_len
);
2639 bcopy (base
, XSTRING (new_name
)->data
+ mod_len
, base_len
);
2641 return Fintern (new_name
, Qnil
);
2646 static char *modifier_names
[] =
2648 "up", "down", "drag", "click", "double", "triple", 0, 0,
2649 0, 0, 0, 0, 0, 0, 0, 0,
2650 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
2652 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
2654 static Lisp_Object modifier_symbols
;
2656 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
2658 lispy_modifier_list (modifiers
)
2661 Lisp_Object modifier_list
;
2664 modifier_list
= Qnil
;
2665 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
2666 if (modifiers
& (1<<i
))
2667 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
2670 return modifier_list
;
2674 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
2675 where UNMODIFIED is the unmodified form of SYMBOL,
2676 MASK is the set of modifiers present in SYMBOL's name.
2677 This is similar to parse_modifiers_uncached, but uses the cache in
2678 SYMBOL's Qevent_symbol_element_mask property, and maintains the
2679 Qevent_symbol_elements property. */
2681 parse_modifiers (symbol
)
2684 Lisp_Object elements
= Fget (symbol
, Qevent_symbol_element_mask
);
2686 if (CONSP (elements
))
2691 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
2692 Lisp_Object unmodified
2693 = Fintern (make_string (XSYMBOL (symbol
)->name
->data
+ end
,
2694 XSYMBOL (symbol
)->name
->size
- end
),
2698 if (modifiers
& ~((1<<VALBITS
) - 1))
2700 XFASTINT (mask
) = modifiers
;
2701 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
2703 /* Cache the parsing results on SYMBOL. */
2704 Fput (symbol
, Qevent_symbol_element_mask
,
2706 Fput (symbol
, Qevent_symbol_elements
,
2707 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
2709 /* Since we know that SYMBOL is modifiers applied to unmodified,
2710 it would be nice to put that in unmodified's cache.
2711 But we can't, since we're not sure that parse_modifiers is
2718 /* Apply the modifiers MODIFIERS to the symbol BASE.
2719 BASE must be unmodified.
2721 This is like apply_modifiers_uncached, but uses BASE's
2722 Qmodifier_cache property, if present. It also builds
2723 Qevent_symbol_elements properties, since it has that info anyway.
2725 apply_modifiers copies the value of BASE's Qevent_kind property to
2726 the modified symbol. */
2728 apply_modifiers (modifiers
, base
)
2732 Lisp_Object cache
, index
, entry
, new_symbol
;
2734 /* Mask out upper bits. We don't know where this value's been. */
2735 modifiers
&= (1<<VALBITS
) - 1;
2737 /* The click modifier never figures into cache indices. */
2738 cache
= Fget (base
, Qmodifier_cache
);
2739 XFASTINT (index
) = (modifiers
& ~click_modifier
);
2740 entry
= Fassq (index
, cache
);
2743 new_symbol
= XCONS (entry
)->cdr
;
2746 /* We have to create the symbol ourselves. */
2747 new_symbol
= apply_modifiers_uncached (modifiers
,
2748 XSYMBOL (base
)->name
->data
,
2749 XSYMBOL (base
)->name
->size
);
2751 /* Add the new symbol to the base's cache. */
2752 entry
= Fcons (index
, new_symbol
);
2753 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
2755 /* We have the parsing info now for free, so add it to the caches. */
2756 XFASTINT (index
) = modifiers
;
2757 Fput (new_symbol
, Qevent_symbol_element_mask
,
2758 Fcons (base
, Fcons (index
, Qnil
)));
2759 Fput (new_symbol
, Qevent_symbol_elements
,
2760 Fcons (base
, lispy_modifier_list (modifiers
)));
2763 /* Make sure this symbol is of the same kind as BASE.
2765 You'd think we could just set this once and for all when we
2766 intern the symbol above, but reorder_modifiers may call us when
2767 BASE's property isn't set right; we can't assume that just
2768 because it has a Qmodifier_cache property it must have its
2769 Qevent_kind set right as well. */
2770 if (NILP (Fget (new_symbol
, Qevent_kind
)))
2772 Lisp_Object kind
= Fget (base
, Qevent_kind
);
2775 Fput (new_symbol
, Qevent_kind
, kind
);
2782 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
2783 return a symbol with the modifiers placed in the canonical order.
2784 Canonical order is alphabetical, except for down and drag, which
2785 always come last. The 'click' modifier is never written out.
2787 Fdefine_key calls this to make sure that (for example) C-M-foo
2788 and M-C-foo end up being equivalent in the keymap. */
2791 reorder_modifiers (symbol
)
2794 /* It's hopefully okay to write the code this way, since everything
2795 will soon be in caches, and no consing will be done at all. */
2796 Lisp_Object parsed
= parse_modifiers (symbol
);
2798 return apply_modifiers (XCONS (XCONS (parsed
)->cdr
)->car
,
2799 XCONS (parsed
)->car
);
2803 /* For handling events, we often want to produce a symbol whose name
2804 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
2805 to some base, like the name of a function key or mouse button.
2806 modify_event_symbol produces symbols of this sort.
2808 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
2809 is the name of the i'th symbol. TABLE_SIZE is the number of elements
2812 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
2813 persist between calls to modify_event_symbol that it can use to
2814 store a cache of the symbols it's generated for this NAME_TABLE
2817 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
2819 MODIFIERS is a set of modifier bits (as given in struct input_events)
2820 whose prefixes should be applied to the symbol name.
2822 SYMBOL_KIND is the value to be placed in the event_kind property of
2823 the returned symbol.
2825 The symbols we create are supposed to have an
2826 `event-symbol-elements' property, which lists the modifiers present
2827 in the symbol's name. */
2830 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_table
,
2831 symbol_table
, table_size
)
2834 Lisp_Object symbol_kind
;
2836 Lisp_Object
*symbol_table
;
2841 /* Is this a request for a valid symbol? */
2842 if (symbol_num
< 0 || symbol_num
>= table_size
)
2845 /* If *symbol_table doesn't seem to be initialized properly, fix that.
2846 *symbol_table should be a lisp vector TABLE_SIZE elements long,
2847 where the Nth element is the symbol for NAME_TABLE[N], or nil if
2848 we've never used that symbol before. */
2849 if (XTYPE (*symbol_table
) != Lisp_Vector
2850 || XVECTOR (*symbol_table
)->size
!= table_size
)
2854 XFASTINT (size
) = table_size
;
2855 *symbol_table
= Fmake_vector (size
, Qnil
);
2858 slot
= & XVECTOR (*symbol_table
)->contents
[symbol_num
];
2860 /* Have we already used this symbol before? */
2863 /* No; let's create it. */
2864 if (name_table
[symbol_num
])
2865 *slot
= intern (name_table
[symbol_num
]);
2869 sprintf (buf
, "key-%d", symbol_num
);
2870 *slot
= intern (buf
);
2873 /* Fill in the cache entries for this symbol; this also
2874 builds the Qevent_symbol_elements property, which the user
2876 apply_modifiers (modifiers
& click_modifier
, *slot
);
2877 Fput (*slot
, Qevent_kind
, symbol_kind
);
2880 /* Apply modifiers to that symbol. */
2881 return apply_modifiers (modifiers
, *slot
);
2885 /* Store into *addr a value nonzero if terminal input chars are available.
2886 Serves the purpose of ioctl (0, FIONREAD, addr)
2887 but works even if FIONREAD does not exist.
2888 (In fact, this may actually read some input.) */
2891 get_input_pending (addr
)
2894 /* First of all, have we already counted some input? */
2895 *addr
= !NILP (Vquit_flag
) || readable_events ();
2897 /* If input is being read as it arrives, and we have none, there is none. */
2898 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
2901 /* Try to read some input and see how much we get. */
2903 *addr
= !NILP (Vquit_flag
) || readable_events ();
2906 /* Interface to read_avail_input, blocking SIGIO if necessary. */
2909 gobble_input (expected
)
2914 if (interrupt_input
)
2917 mask
= sigblockx (SIGIO
);
2918 read_avail_input (expected
);
2923 read_avail_input (expected
);
2929 /* Read any terminal input already buffered up by the system
2930 into the kbd_buffer, but do not wait.
2932 EXPECTED should be nonzero if the caller knows there is some input.
2934 Except on VMS, all input is read by this function.
2935 If interrupt_input is nonzero, this function MUST be called
2936 only when SIGIO is blocked.
2938 Returns the number of keyboard chars read, or -1 meaning
2939 this is a bad time to try to read input. */
2942 read_avail_input (expected
)
2945 struct input_event buf
[KBD_BUFFER_SIZE
];
2949 if (read_socket_hook
)
2950 /* No need for FIONREAD or fcntl; just say don't wait. */
2951 nread
= (*read_socket_hook
) (0, buf
, KBD_BUFFER_SIZE
, expected
, expected
);
2954 unsigned char cbuf
[KBD_BUFFER_SIZE
];
2957 /* Find out how much input is available. */
2958 if (ioctl (0, FIONREAD
, &nread
) < 0)
2959 /* Formerly simply reported no input, but that sometimes led to
2960 a failure of Emacs to terminate.
2961 SIGHUP seems appropriate if we can't reach the terminal. */
2962 /* ??? Is it really right to send the signal just to this process
2963 rather than to the whole process group?
2964 Perhaps on systems with FIONREAD Emacs is alone in its group. */
2965 kill (getpid (), SIGHUP
);
2968 if (nread
> sizeof cbuf
)
2969 nread
= sizeof cbuf
;
2970 #else /* no FIONREAD */
2972 /* Read some input if available, but don't wait. */
2973 nread
= sizeof cbuf
;
2974 fcntl (fileno (stdin
), F_SETFL
, O_NDELAY
);
2980 /* Now read; for one reason or another, this will not block. */
2983 nread
= read (fileno (stdin
), cbuf
, nread
);
2985 /* The kernel sometimes fails to deliver SIGHUP for ptys.
2986 This looks incorrect, but it isn't, because _BSD causes
2987 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
2988 and that causes a value other than 0 when there is no input. */
2992 /* Retry the read if it is interrupted. */
2994 || ! (errno
== EAGAIN
|| errno
== EFAULT
3004 fcntl (fileno (stdin
), F_SETFL
, 0);
3006 #endif /* no FIONREAD */
3007 for (i
= 0; i
< nread
; i
++)
3009 buf
[i
].kind
= ascii_keystroke
;
3010 buf
[i
].modifiers
= 0;
3011 if (meta_key
== 1 && (cbuf
[i
] & 0x80))
3012 buf
[i
].modifiers
= meta_modifier
;
3016 XSET (buf
[i
].code
, Lisp_Int
, cbuf
[i
]);
3018 XSET (buf
[i
].frame_or_window
, Lisp_Frame
, selected_frame
);
3020 buf
[i
].frame_or_window
= Qnil
;
3025 /* Scan the chars for C-g and store them in kbd_buffer. */
3026 for (i
= 0; i
< nread
; i
++)
3028 kbd_buffer_store_event (&buf
[i
]);
3029 /* Don't look at input that follows a C-g too closely.
3030 This reduces lossage due to autorepeat on C-g. */
3031 if (buf
[i
].kind
== ascii_keystroke
3032 && XINT(buf
[i
].code
) == quit_char
)
3038 #endif /* not VMS */
3040 #ifdef SIGIO /* for entire page */
3041 /* Note SIGIO has been undef'd if FIONREAD is missing. */
3044 input_available_signal (signo
)
3047 /* Must preserve main program's value of errno. */
3048 int old_errno
= errno
;
3050 extern int select_alarmed
;
3054 /* USG systems forget handlers when they are used;
3055 must reestablish each time */
3056 signal (signo
, input_available_signal
);
3063 if (input_available_clear_time
)
3064 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
3069 nread
= read_avail_input (1);
3070 /* -1 means it's not ok to read the input now.
3071 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
3072 0 means there was no keyboard input available. */
3077 select_alarmed
= 1; /* Force the select emulator back to life */
3088 /* Send ourselves a SIGIO.
3090 This function exists so that the UNBLOCK_INPUT macro in
3091 blockinput.h can have some way to take care of input we put off
3092 dealing with, without assuming that every file which uses
3093 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
3095 reinvoke_input_signal ()
3104 /* Return the prompt-string of a sparse keymap.
3105 This is the first element which is a string.
3106 Return nil if there is none. */
3114 register Lisp_Object tem
;
3116 if (XTYPE (tem
) == Lisp_String
)
3123 static Lisp_Object
menu_bar_item ();
3124 static Lisp_Object
menu_bar_one_keymap ();
3126 /* Return a list of menu items for a menu bar, appropriate
3127 to the current buffer.
3128 The elements have the form (KEY STRING . nil). */
3133 /* The number of keymaps we're scanning right now, and the number of
3134 keymaps we have allocated space for. */
3137 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
3138 in the current keymaps, or nil where it is not a prefix. */
3141 Lisp_Object def
, tem
;
3148 /* In order to build the menus, we need to call the keymap
3149 accessors. They all call QUIT. But this function is called
3150 during redisplay, during which a quit is fatal. So inhibit
3151 quitting while building the menus.
3152 We do this instead of specbind because (1) errors will clear it anyway
3153 and (2) this avoids risk of specpdl overflow. */
3154 oquit
= Vinhibit_quit
;
3157 /* Build our list of keymaps.
3158 If we recognize a function key and replace its escape sequence in
3159 keybuf with its symbol, or if the sequence starts with a mouse
3160 click and we need to switch buffers, we jump back here to rebuild
3161 the initial keymaps from the current buffer. */
3165 nmaps
= current_minor_maps (0, &tmaps
) + 2;
3166 maps
= (Lisp_Object
*) alloca (nmaps
* sizeof (maps
[0]));
3167 bcopy (tmaps
, maps
, (nmaps
- 2) * sizeof (maps
[0]));
3168 #ifdef USE_TEXT_PROPERTIES
3169 maps
[nmaps
-2] = get_local_map (PT
, current_buffer
);
3171 maps
[nmaps
-2] = current_buffer
->keymap
;
3173 maps
[nmaps
-1] = current_global_map
;
3176 /* Look up in each map the dummy prefix key `menu-bar'. */
3180 for (mapno
= 0; mapno
< nmaps
; mapno
++)
3182 if (! NILP (maps
[mapno
]))
3183 def
= get_keyelt (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0));
3187 tem
= Fkeymapp (def
);
3189 result
= menu_bar_one_keymap (def
, result
);
3192 result
= Fnreverse (result
);
3193 Vinhibit_quit
= oquit
;
3197 /* Scan one map KEYMAP, accumulating any menu items it defines
3198 that have not yet been seen in RESULT. Return the updated RESULT. */
3201 menu_bar_one_keymap (keymap
, result
)
3202 Lisp_Object keymap
, result
;
3204 Lisp_Object tail
, item
, key
, binding
, item_string
, table
;
3206 /* Loop over all keymap entries that have menu strings. */
3207 for (tail
= keymap
; XTYPE (tail
) == Lisp_Cons
; tail
= XCONS (tail
)->cdr
)
3209 item
= XCONS (tail
)->car
;
3210 if (XTYPE (item
) == Lisp_Cons
)
3212 key
= XCONS (item
)->car
;
3213 binding
= XCONS (item
)->cdr
;
3214 if (XTYPE (binding
) == Lisp_Cons
)
3216 item_string
= XCONS (binding
)->car
;
3217 if (XTYPE (item_string
) == Lisp_String
)
3218 result
= menu_bar_item (key
, item_string
,
3219 Fcdr (binding
), result
);
3222 else if (XTYPE (item
) == Lisp_Vector
)
3224 /* Loop over the char values represented in the vector. */
3225 int len
= XVECTOR (item
)->size
;
3227 for (c
= 0; c
< len
; c
++)
3229 Lisp_Object character
;
3230 XFASTINT (character
) = c
;
3231 binding
= XVECTOR (item
)->contents
[c
];
3232 if (XTYPE (binding
) == Lisp_Cons
)
3234 item_string
= XCONS (binding
)->car
;
3235 if (XTYPE (item_string
) == Lisp_String
)
3236 result
= menu_bar_item (key
, item_string
,
3237 Fcdr (binding
), result
);
3247 menu_bar_item (key
, item_string
, def
, result
)
3248 Lisp_Object key
, item_string
, def
, result
;
3250 Lisp_Object tem
, elt
;
3251 Lisp_Object enabled
;
3253 /* See if this entry is enabled. */
3256 if (XTYPE (def
) == Lisp_Symbol
)
3258 /* No property, or nil, means enable.
3259 Otherwise, enable if value is not nil. */
3260 tem
= Fget (def
, Qmenu_enable
);
3262 enabled
= Feval (tem
);
3265 /* Add an entry for this key and string
3266 if there is none yet. */
3267 elt
= Fassq (key
, result
);
3268 if (!NILP (enabled
) && NILP (elt
))
3269 result
= Fcons (Fcons (key
, Fcons (item_string
, Qnil
)), result
);
3274 static int echo_flag
;
3275 static int echo_now
;
3277 /* Read a character like read_char but optionally prompt based on maps
3278 in the array MAPS. NMAPS is the length of MAPS. Return nil if we
3279 decided not to read a character, because there are no menu items in
3282 PREV_EVENT is the previous input event, or nil if we are reading
3283 the first event of a key sequence.
3285 If USED_MOUSE_MENU is non-zero, then we set *USED_MOUSE_MENU to 1
3286 if we used a mouse menu to read the input, or zero otherwise. If
3287 USED_MOUSE_MENU is zero, *USED_MOUSE_MENU is left alone.
3289 The prompting is done based on the prompt-string of the map
3290 and the strings associated with various map elements. */
3293 read_char_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
3296 Lisp_Object prev_event
;
3297 int *used_mouse_menu
;
3300 register Lisp_Object name
;
3302 int width
= FRAME_WIDTH (selected_frame
) - 4;
3303 char *menu
= (char *) alloca (width
+ 4);
3305 Lisp_Object rest
, vector
;
3307 if (used_mouse_menu
)
3308 *used_mouse_menu
= 0;
3310 /* Use local over global Menu maps */
3312 if (! menu_prompting
)
3315 /* Get the menu name from the first map that has one (a prompt string). */
3316 for (mapno
= 0; mapno
< nmaps
; mapno
++)
3318 name
= map_prompt (maps
[mapno
]);
3323 /* If we don't have any menus, just read a character normally. */
3327 #ifdef HAVE_X_WINDOWS
3329 /* If we got to this point via a mouse click,
3330 use a real menu for mouse selection. */
3331 if (EVENT_HAS_PARAMETERS (prev_event
))
3333 /* Display the menu and get the selection. */
3334 Lisp_Object
*realmaps
3335 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
3339 /* Use the maps that are not nil. */
3340 for (mapno
= 0; mapno
< nmaps
; mapno
++)
3341 if (!NILP (maps
[mapno
]))
3342 realmaps
[nmaps1
++] = maps
[mapno
];
3344 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
3347 /* If we got more than one event, put all but the first
3348 onto this list to be read later.
3349 Return just the first event now. */
3350 unread_command_events
3351 = nconc2 (XCONS (value
)->cdr
, unread_command_events
);
3352 value
= XCONS (value
)->car
;
3355 XSET (value
, Lisp_Int
, quit_char
);
3356 if (used_mouse_menu
)
3357 *used_mouse_menu
= 1;
3360 #endif /* HAVE_X_MENU */
3361 #endif /* HAVE_X_WINDOWS */
3363 /* Prompt string always starts with map's prompt, and a space. */
3364 strcpy (menu
, XSTRING (name
)->data
);
3365 nlength
= XSTRING (name
)->size
;
3366 menu
[nlength
++] = ':';
3367 menu
[nlength
++] = ' ';
3370 /* Start prompting at start of first map. */
3374 /* Present the documented bindings, a line at a time. */
3382 /* Loop over elements of map. */
3387 /* If reached end of map, start at beginning of next map. */
3391 /* At end of last map, wrap around to first map if just starting,
3392 or end this line if already have something on it. */
3403 /* Look at the next element of the map. */
3405 elt
= XVECTOR (vector
)->contents
[idx
];
3407 elt
= Fcar_safe (rest
);
3409 if (idx
< 0 && XTYPE (elt
) == Lisp_Vector
)
3411 /* If we found a dense table in the keymap,
3412 advanced past it, but start scanning its contents. */
3413 rest
= Fcdr_safe (rest
);
3419 /* An ordinary element. */
3420 s
= Fcar_safe (Fcdr_safe (elt
));
3421 if (XTYPE (s
) != Lisp_String
)
3422 /* Ignore the element if it has no prompt string. */
3424 /* If we have room for the prompt string, add it to this line.
3425 If this is the first on the line, always add it. */
3426 else if (XSTRING (s
)->size
+ i
< width
3431 /* Punctuate between strings. */
3434 strcpy (menu
+ i
, ", ");
3439 /* Add as much of string as fits. */
3440 thiswidth
= XSTRING (s
)->size
;
3441 if (thiswidth
+ i
> width
)
3442 thiswidth
= width
- i
;
3443 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
3448 /* If this element does not fit, end the line now,
3449 and save the element for the next line. */
3450 strcpy (menu
+ i
, "...");
3454 /* Move past this element. */
3455 if (idx
>= 0 && idx
+ 1 >= XVECTOR (rest
)->size
)
3456 /* Handle reaching end of dense table. */
3461 rest
= Fcdr_safe (rest
);
3465 /* Prompt with that and read response. */
3467 obj
= read_char (1, 0, 0, Qnil
, 0);
3469 if (XTYPE (obj
) != Lisp_Int
)
3474 if (! EQ (obj
, menu_prompt_more_char
)
3475 && (XTYPE (menu_prompt_more_char
) != Lisp_Int
3476 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
3481 /* Reading key sequences. */
3483 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
3484 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
3485 keymap, or nil otherwise. Return the index of the first keymap in
3486 which KEY has any binding, or NMAPS if no map has a binding.
3488 If KEY is a meta ASCII character, treat it like meta-prefix-char
3489 followed by the corresponding non-meta character. Keymaps in
3490 CURRENT with non-prefix bindings for meta-prefix-char become nil in
3493 When KEY is not defined in any of the keymaps, if it is an upper
3494 case letter and there are bindings for the corresponding lower-case
3495 letter, return the bindings for the lower-case letter.
3497 If KEY has no bindings in any of the CURRENT maps, NEXT is left
3500 NEXT may == CURRENT. */
3503 follow_key (key
, nmaps
, current
, defs
, next
)
3505 Lisp_Object
*current
, *defs
, *next
;
3508 int i
, first_binding
;
3510 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
3511 followed by the corresponding non-meta character. */
3512 if (XTYPE (key
) == Lisp_Int
&& (XINT (key
) & CHAR_META
))
3514 for (i
= 0; i
< nmaps
; i
++)
3515 if (! NILP (current
[i
]))
3518 get_keyelt (access_keymap (current
[i
], meta_prefix_char
, 1, 0));
3520 /* Note that since we pass the resulting bindings through
3521 get_keymap_1, non-prefix bindings for meta-prefix-char
3523 next
[i
] = get_keymap_1 (next
[i
], 0, 1);
3529 XSET (key
, Lisp_Int
, XFASTINT (key
) & ~CHAR_META
);
3532 first_binding
= nmaps
;
3533 for (i
= nmaps
- 1; i
>= 0; i
--)
3535 if (! NILP (current
[i
]))
3537 defs
[i
] = get_keyelt (access_keymap (current
[i
], key
, 1, 0));
3538 if (! NILP (defs
[i
]))
3545 /* When KEY is not defined in any of the keymaps, if it is an upper
3546 case letter and there are bindings for the corresponding
3547 lower-case letter, return the bindings for the lower-case letter. */
3548 if (first_binding
== nmaps
3549 && XTYPE (key
) == Lisp_Int
3550 && ((((XINT (key
) & 0x3ffff)
3551 < XSTRING (current_buffer
->downcase_table
)->size
)
3552 && UPPERCASEP (XINT (key
) & 0x3ffff))
3553 || (XINT (key
) & shift_modifier
)))
3555 if (XINT (key
) & shift_modifier
)
3556 XSETINT (key
, XINT (key
) & ~shift_modifier
);
3558 XSETINT (key
, DOWNCASE (XINT (key
)));
3560 first_binding
= nmaps
;
3561 for (i
= nmaps
- 1; i
>= 0; i
--)
3563 if (! NILP (current
[i
]))
3565 defs
[i
] = get_keyelt (access_keymap (current
[i
], key
, 1, 0));
3566 if (! NILP (defs
[i
]))
3574 /* Given the set of bindings we've found, produce the next set of maps. */
3575 if (first_binding
< nmaps
)
3576 for (i
= 0; i
< nmaps
; i
++)
3577 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0, 1);
3579 return first_binding
;
3582 /* Read a sequence of keys that ends with a non prefix character,
3583 storing it in KEYBUF, a buffer of size BUFSIZE.
3585 Return the length of the key sequence stored.
3587 Echo starting immediately unless `prompt' is 0.
3589 Where a key sequence ends depends on the currently active keymaps.
3590 These include any minor mode keymaps active in the current buffer,
3591 the current buffer's local map, and the global map.
3593 If a key sequence has no other bindings, we check Vfunction_key_map
3594 to see if some trailing subsequence might be the beginning of a
3595 function key's sequence. If so, we try to read the whole function
3596 key, and substitute its symbolic name into the key sequence.
3598 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
3599 `double-' events into similar click events, if that would make them
3600 bound. We try to turn `triple-' events first into `double-' events,
3603 If we get a mouse click in a mode line, vertical divider, or other
3604 non-text area, we treat the click as if it were prefixed by the
3605 symbol denoting that area - `mode-line', `vertical-line', or
3608 If the sequence starts with a mouse click, we read the key sequence
3609 with respect to the buffer clicked on, not the current buffer.
3611 If the user switches frames in the midst of a key sequence, we put
3612 off the switch-frame event until later; the next call to
3613 read_char will return it. */
3616 read_key_sequence (keybuf
, bufsize
, prompt
)
3617 Lisp_Object
*keybuf
;
3621 int count
= specpdl_ptr
- specpdl
;
3623 /* How many keys there are in the current key sequence. */
3626 /* The length of the echo buffer when we started reading, and
3627 the length of this_command_keys when we started reading. */
3631 /* The number of keymaps we're scanning right now, and the number of
3632 keymaps we have allocated space for. */
3634 int nmaps_allocated
= 0;
3636 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
3637 the current keymaps. */
3640 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
3641 in the current keymaps, or nil where it is not a prefix. */
3642 Lisp_Object
*submaps
;
3644 /* The index in defs[] of the first keymap that has a binding for
3645 this key sequence. In other words, the lowest i such that
3646 defs[i] is non-nil. */
3649 /* If t < mock_input, then KEYBUF[t] should be read as the next
3652 We use this to recover after recognizing a function key. Once we
3653 realize that a suffix of the current key sequence is actually a
3654 function key's escape sequence, we replace the suffix with the
3655 function key's binding from Vfunction_key_map. Now keybuf
3656 contains a new and different key sequence, so the echo area,
3657 this_command_keys, and the submaps and defs arrays are wrong. In
3658 this situation, we set mock_input to t, set t to 0, and jump to
3659 restart_sequence; the loop will read keys from keybuf up until
3660 mock_input, thus rebuilding the state; and then it will resume
3661 reading characters from the keyboard. */
3664 /* If the sequence is unbound in submaps[], then
3665 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
3666 and fkey_map is its binding.
3668 These might be > t, indicating that all function key scanning
3669 should hold off until t reaches them. We do this when we've just
3670 recognized a function key, to avoid searching for the function
3671 key's again in Vfunction_key_map. */
3672 int fkey_start
= 0, fkey_end
= 0;
3673 Lisp_Object fkey_map
;
3675 /* If we receive a ``switch-frame'' event in the middle of a key sequence,
3676 we put it off for later. While we're reading, we keep the event here. */
3677 Lisp_Object delayed_switch_frame
;
3679 Lisp_Object first_event
;
3683 last_nonmenu_event
= Qnil
;
3685 delayed_switch_frame
= Qnil
;
3686 fkey_map
= Vfunction_key_map
;
3688 /* If there is no function key map, turn off function key scanning. */
3689 if (NILP (Fkeymapp (Vfunction_key_map
)))
3690 fkey_start
= fkey_end
= bufsize
+ 1;
3695 echo_prompt (prompt
);
3696 else if (cursor_in_echo_area
)
3697 /* This doesn't put in a dash if the echo buffer is empty, so
3698 you don't always see a dash hanging out in the minibuffer. */
3702 /* Record the initial state of the echo area and this_command_keys;
3703 we will need to restore them if we replay a key sequence. */
3705 echo_start
= echo_length ();
3706 keys_start
= this_command_key_count
;
3708 #if 0 /* This doesn't quite work, because some of the things
3709 that read_char does cannot safely be bypassed.
3710 It seems too risky to try to make this work right. */
3711 /* Read the first char of the sequence specially, before setting
3712 up any keymaps, in case a filter runs and switches buffers on us. */
3713 first_event
= read_char (!prompt
, 0, submaps
, last_nonmenu_event
,
3717 /* We jump here when the key sequence has been thoroughly changed, and
3718 we need to rescan it starting from the beginning. When we jump here,
3719 keybuf[0..mock_input] holds the sequence we should reread. */
3722 /* Build our list of keymaps.
3723 If we recognize a function key and replace its escape sequence in
3724 keybuf with its symbol, or if the sequence starts with a mouse
3725 click and we need to switch buffers, we jump back here to rebuild
3726 the initial keymaps from the current buffer. */
3730 nmaps
= current_minor_maps (0, &maps
) + 2;
3731 if (nmaps
> nmaps_allocated
)
3733 submaps
= (Lisp_Object
*) alloca (nmaps
* sizeof (submaps
[0]));
3734 defs
= (Lisp_Object
*) alloca (nmaps
* sizeof (defs
[0]));
3735 nmaps_allocated
= nmaps
;
3737 bcopy (maps
, submaps
, (nmaps
- 2) * sizeof (submaps
[0]));
3738 #ifdef USE_TEXT_PROPERTIES
3739 submaps
[nmaps
-2] = get_local_map (PT
, current_buffer
);
3741 submaps
[nmaps
-2] = current_buffer
->keymap
;
3743 submaps
[nmaps
-1] = current_global_map
;
3746 /* Find an accurate initial value for first_binding. */
3747 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
3748 if (! NILP (submaps
[first_binding
]))
3751 /* We jump here when a function key substitution has forced us to
3752 reprocess the current key sequence. keybuf[0..mock_input] is the
3753 sequence we want to reread. */
3756 /* These are no-ops the first time through, but if we restart, they
3757 revert the echo area and this_command_keys to their original state. */
3758 this_command_key_count
= keys_start
;
3760 echo_truncate (echo_start
);
3762 /* If the best binding for the current key sequence is a keymap, or
3763 we may be looking at a function key's escape sequence, keep on
3765 while ((first_binding
< nmaps
&& ! NILP (submaps
[first_binding
]))
3766 || (first_binding
>= nmaps
3768 /* mock input is never part of a function key's sequence. */
3769 && mock_input
<= fkey_start
))
3772 int used_mouse_menu
= 0;
3774 /* Where the last real key started. If we need to throw away a
3775 key that has expanded into more than one element of keybuf
3776 (say, a mouse click on the mode line which is being treated
3777 as [mode-line (mouse-...)], then we backtrack to this point
3779 int last_real_key_start
;
3781 /* These variables are analogous to echo_start and keys_start;
3782 while those allow us to restart the entire key sequence,
3783 echo_local_start and keys_local_start allow us to throw away
3785 int echo_local_start
, keys_local_start
, local_first_binding
;
3788 error ("key sequence too long");
3791 echo_local_start
= echo_length ();
3792 keys_local_start
= this_command_key_count
;
3793 local_first_binding
= first_binding
;
3796 /* These are no-ops, unless we throw away a keystroke below and
3797 jumped back up to replay_key; in that case, these restore the
3798 variables to their original state, allowing us to replay the
3801 echo_truncate (echo_local_start
);
3802 this_command_key_count
= keys_local_start
;
3803 first_binding
= local_first_binding
;
3805 /* Does mock_input indicate that we are re-reading a key sequence? */
3809 add_command_key (key
);
3813 /* If not, we should actually read a character. */
3816 struct buffer
*buf
= current_buffer
;
3818 last_real_key_start
= t
;
3820 key
= read_char (!prompt
, nmaps
, submaps
, last_nonmenu_event
,
3823 /* read_char returns -1 at the end of a macro.
3824 Emacs 18 handles this by returning immediately with a
3825 zero, so that's what we'll do. */
3826 if (XTYPE (key
) == Lisp_Int
&& XINT (key
) == -1)
3834 /* Clicks in non-text areas get prefixed by the symbol
3835 in their CHAR-ADDRESS field. For example, a click on
3836 the mode line is prefixed by the symbol `mode-line'.
3838 Furthermore, key sequences beginning with mouse clicks
3839 are read using the keymaps of the buffer clicked on, not
3840 the current buffer. So we may have to switch the buffer
3843 If the event was obtained from the unread_command_events
3844 queue, then don't expand it; we did that the first time
3846 if (EVENT_HAS_PARAMETERS (key
))
3848 Lisp_Object kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
3850 if (EQ (kind
, Qmouse_click
))
3852 Lisp_Object window
= POSN_WINDOW (EVENT_START (key
));
3853 Lisp_Object posn
= POSN_BUFFER_POSN (EVENT_START (key
));
3855 /* Key sequences beginning with mouse clicks are
3856 read using the keymaps in the buffer clicked on,
3857 not the current buffer. If we're at the
3858 beginning of a key sequence, switch buffers. */
3860 && XTYPE (window
) == Lisp_Window
3861 && XTYPE (XWINDOW (window
)->buffer
) == Lisp_Buffer
3862 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
3867 /* Arrange to go back to the original buffer once we're
3868 done reading the key sequence. Note that we can't
3869 use save_excursion_{save,restore} here, because they
3870 save point as well as the current buffer; we don't
3871 want to save point, because redisplay may change it,
3872 to accommodate a Fset_window_start or something. We
3873 don't want to do this at the top of the function,
3874 because we may get input from a subprocess which
3875 wants to change the selected window and stuff (say,
3877 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
3879 set_buffer_internal (XBUFFER (XWINDOW (window
)->buffer
));
3880 goto replay_sequence
;
3882 else if (XTYPE (posn
) == Lisp_Symbol
)
3884 if (t
+ 1 >= bufsize
)
3885 error ("key sequence too long");
3890 /* Zap the position in key, so we know that we've
3891 expanded it, and don't try to do so again. */
3892 POSN_BUFFER_POSN (EVENT_START (key
))
3893 = Fcons (posn
, Qnil
);
3895 /* If we switched buffers while reading the first event,
3896 replay in case we switched keymaps too. */
3897 if (buf
!= current_buffer
&& t
== 0)
3898 goto replay_sequence
;
3901 else if (XTYPE (posn
) == Lisp_Cons
)
3903 /* We're looking at the second event of a
3904 sequence which we expanded before. Set
3905 last_real_key_start appropriately. */
3906 if (last_real_key_start
== t
&& t
> 0)
3907 last_real_key_start
= t
- 1;
3910 else if (EQ (kind
, Qswitch_frame
))
3912 /* If we're at the beginning of a key sequence, go
3913 ahead and return this event. If we're in the
3914 midst of a key sequence, delay it until the end. */
3917 delayed_switch_frame
= key
;
3923 Lisp_Object posn
= POSN_BUFFER_POSN (EVENT_START (key
));
3925 /* Handle menu-bar events:
3926 insert the dummy prefix char `menu-bar'. */
3927 if (EQ (posn
, Qmenu_bar
))
3929 if (t
+ 1 >= bufsize
)
3930 error ("key sequence too long");
3931 /* Run the Lucid hook. */
3932 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
3933 /* If it has changed current-menubar from previous value,
3934 really recompute the menubar from the value. */
3935 if (! NILP (Vlucid_menu_bar_dirty_flag
))
3936 call0 (Qrecompute_lucid_menubar
);
3940 goto replay_sequence
;
3945 /* If we switched buffers while reading the first event,
3946 replay in case we switched keymaps too. */
3947 if (buf
!= current_buffer
&& t
== 0)
3951 goto replay_sequence
;
3955 /* We have finally decided that KEY is something we might want
3957 first_binding
= (follow_key (key
,
3958 nmaps
- first_binding
,
3959 submaps
+ first_binding
,
3960 defs
+ first_binding
,
3961 submaps
+ first_binding
)
3964 /* If KEY wasn't bound, we'll try some fallbacks. */
3965 if (first_binding
>= nmaps
)
3967 Lisp_Object head
= EVENT_HEAD (key
);
3969 if (XTYPE (head
) == Lisp_Symbol
)
3971 Lisp_Object breakdown
= parse_modifiers (head
);
3972 int modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
3974 /* We drop unbound `down-' events altogether. */
3975 if (modifiers
& down_modifier
)
3977 /* Dispose of this event by simply jumping back to
3978 replay_key, to get another event.
3980 Note that if this event came from mock input,
3981 then just jumping back to replay_key will just
3982 hand it to us again. So we have to wipe out any
3985 We could delete keybuf[t] and shift everything
3986 after that to the left by one spot, but we'd also
3987 have to fix up any variable that points into
3988 keybuf, and shifting isn't really necessary
3991 Adding prefixes for non-textual mouse clicks
3992 creates two characters of mock input, and both
3993 must be thrown away. If we're only looking at
3994 the prefix now, we can just jump back to
3995 replay_key. On the other hand, if we've already
3996 processed the prefix, and now the actual click
3997 itself is giving us trouble, then we've lost the
3998 state of the keymaps we want to backtrack to, and
3999 we need to replay the whole sequence to rebuild
4002 Beyond that, only function key expansion could
4003 create more than two keys, but that should never
4004 generate mouse events, so it's okay to zero
4005 mock_input in that case too.
4007 Isn't this just the most wonderful code ever? */
4008 if (t
== last_real_key_start
)
4015 mock_input
= last_real_key_start
;
4016 goto replay_sequence
;
4020 /* We turn unbound `drag-' events into `click-'
4021 events, if the click would be bound. */
4022 else if (modifiers
& (drag_modifier
| double_modifier
4025 while (modifiers
& (drag_modifier
| double_modifier
4028 Lisp_Object new_head
, new_click
;
4029 if (modifiers
& triple_modifier
)
4030 modifiers
^= (double_modifier
| triple_modifier
);
4032 modifiers
&= ~(drag_modifier
| double_modifier
);
4034 apply_modifiers (modifiers
, XCONS (breakdown
)->car
);
4036 Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
4038 /* Look for a binding for this new key. follow_key
4039 promises that it didn't munge submaps the
4040 last time we called it, since key was unbound. */
4042 (follow_key (new_click
,
4043 nmaps
- local_first_binding
,
4044 submaps
+ local_first_binding
,
4045 defs
+ local_first_binding
,
4046 submaps
+ local_first_binding
)
4047 + local_first_binding
);
4049 /* If that click is bound, go for it. */
4050 if (first_binding
< nmaps
)
4055 /* Otherwise, we'll leave key set to the drag event. */
4062 /* Normally, last_nonmenu_event gets the previous key we read.
4063 But when a mouse popup menu is being used,
4064 we don't update last_nonmenu_event; it continues to hold the mouse
4065 event that preceded the first level of menu. */
4066 if (!used_mouse_menu
)
4067 last_nonmenu_event
= key
;
4069 /* If the sequence is unbound, see if we can hang a function key
4070 off the end of it. We only want to scan real keyboard input
4071 for function key sequences, so if mock_input says that we're
4072 re-reading old events, don't examine it. */
4073 if (first_binding
>= nmaps
4076 Lisp_Object fkey_next
;
4078 /* Scan from fkey_end until we find a bound suffix. */
4079 while (fkey_end
< t
)
4083 key
= keybuf
[fkey_end
++];
4084 /* Look up meta-characters by prefixing them
4085 with meta_prefix_char. I hate this. */
4086 if (XTYPE (key
) == Lisp_Int
&& XINT (key
) & meta_modifier
)
4091 (access_keymap (fkey_map
, meta_prefix_char
, 1, 0)),
4093 XFASTINT (key
) = XFASTINT (key
) & ~meta_modifier
;
4096 fkey_next
= fkey_map
;
4099 = get_keyelt (access_keymap (fkey_next
, key
, 1, 0));
4101 /* If keybuf[fkey_start..fkey_end] is bound in the
4102 function key map and it's a suffix of the current
4103 sequence (i.e. fkey_end == t), replace it with
4104 the binding and restart with fkey_start at the end. */
4105 if (XTYPE (fkey_next
) == Lisp_Vector
4108 t
= fkey_start
+ XVECTOR (fkey_next
)->size
;
4110 error ("key sequence too long");
4112 bcopy (XVECTOR (fkey_next
)->contents
,
4113 keybuf
+ fkey_start
,
4114 (t
- fkey_start
) * sizeof (keybuf
[0]));
4117 fkey_start
= fkey_end
= t
;
4118 fkey_map
= Vfunction_key_map
;
4120 goto replay_sequence
;
4123 fkey_map
= get_keymap_1 (fkey_next
, 0, 1);
4125 /* If we no longer have a bound suffix, try a new positions for
4127 if (NILP (fkey_map
))
4129 fkey_end
= ++fkey_start
;
4130 fkey_map
= Vfunction_key_map
;
4136 read_key_sequence_cmd
= (first_binding
< nmaps
4137 ? defs
[first_binding
]
4141 unread_switch_frame
= delayed_switch_frame
;
4142 unbind_to (count
, Qnil
);
4144 /* Occasionally we fabricate events, perhaps by expanding something
4145 according to function-key-map, or by adding a prefix symbol to a
4146 mouse click in the scroll bar or modeline. In this cases, return
4147 the entire generated key sequence, even if we hit an unbound
4148 prefix or a definition before the end. This means that you will
4149 be able to push back the event properly, and also means that
4150 read-key-sequence will always return a logical unit.
4153 for (; t
< mock_input
; t
++)
4155 echo_char (keybuf
[t
]);
4156 add_command_key (keybuf
[t
]);
4162 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 2, 0,
4163 "Read a sequence of keystrokes and return as a string or vector.\n\
4164 The sequence is sufficient to specify a non-prefix command in the\n\
4165 current local and global maps.\n\
4167 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
4168 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
4169 as a continuation of the previous key.\n\
4171 A C-g typed while in this function is treated like any other character,\n\
4172 and `quit-flag' is not set.\n\
4174 If the key sequence starts with a mouse click, then the sequence is read\n\
4175 using the keymaps of the buffer of the window clicked in, not the buffer\n\
4176 of the selected window as normal.\n\
4178 `read-key-sequence' drops unbound button-down events, since you normally\n\
4179 only care about the click or drag events which follow them. If a drag\n\
4180 or multi-click event is unbound, but the corresponding click event would\n\
4181 be bound, `read-key-sequence' turns the event into a click event at the\n\
4182 drag's starting position. This means that you don't have to distinguish\n\
4183 between click and drag, double, or triple events unless you want to.\n\
4185 `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\
4186 lines separating windows, and scroll bars with imaginary keys\n\
4187 `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\
4189 If the user switches frames in the middle of a key sequence, the\n\
4190 frame-switch event is put off until after the current key sequence.\n\
4192 `read-key-sequence' checks `function-key-map' for function key\n\
4193 sequences, where they wouldn't conflict with ordinary bindings. See\n\
4194 `function-key-map' for more details.")
4195 (prompt
, continue_echo
)
4196 Lisp_Object prompt
, continue_echo
;
4198 Lisp_Object keybuf
[30];
4200 struct gcpro gcpro1
, gcpro2
;
4203 CHECK_STRING (prompt
, 0);
4206 bzero (keybuf
, sizeof keybuf
);
4208 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
4210 if (NILP (continue_echo
))
4211 this_command_key_count
= 0;
4213 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
4214 NILP (prompt
) ? 0 : XSTRING (prompt
)->data
);
4217 return make_event_array (i
, keybuf
);
4220 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 2, 0,
4221 "Execute CMD as an editor command.\n\
4222 CMD must be a symbol that satisfies the `commandp' predicate.\n\
4223 Optional second arg RECORD-FLAG non-nil\n\
4224 means unconditionally put this command in `command-history'.\n\
4225 Otherwise, that is done only if an arg is read using the minibuffer.")
4227 Lisp_Object cmd
, record
;
4229 register Lisp_Object final
;
4230 register Lisp_Object tem
;
4231 Lisp_Object prefixarg
;
4232 struct backtrace backtrace
;
4233 extern int debug_on_next_call
;
4235 prefixarg
= Vprefix_arg
, Vprefix_arg
= Qnil
;
4236 Vcurrent_prefix_arg
= prefixarg
;
4237 debug_on_next_call
= 0;
4239 if (XTYPE (cmd
) == Lisp_Symbol
)
4241 tem
= Fget (cmd
, Qdisabled
);
4243 return call1 (Vrun_hooks
, Vdisabled_command_hook
);
4248 final
= Findirect_function (cmd
);
4250 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
4251 do_autoload (final
, cmd
);
4256 if (XTYPE (final
) == Lisp_String
4257 || XTYPE (final
) == Lisp_Vector
)
4259 /* If requested, place the macro in the command history. For
4260 other sorts of commands, call-interactively takes care of
4264 = Fcons (Fcons (Qexecute_kbd_macro
,
4265 Fcons (final
, Fcons (prefixarg
, Qnil
))),
4268 return Fexecute_kbd_macro (final
, prefixarg
);
4270 if (CONSP (final
) || XTYPE (final
) == Lisp_Subr
4271 || XTYPE (final
) == Lisp_Compiled
)
4273 backtrace
.next
= backtrace_list
;
4274 backtrace_list
= &backtrace
;
4275 backtrace
.function
= &Qcall_interactively
;
4276 backtrace
.args
= &cmd
;
4277 backtrace
.nargs
= 1;
4278 backtrace
.evalargs
= 0;
4280 tem
= Fcall_interactively (cmd
, record
);
4282 backtrace_list
= backtrace
.next
;
4288 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
4290 "Read function name, then read its arguments and call it.")
4292 Lisp_Object prefixarg
;
4294 Lisp_Object function
;
4296 Lisp_Object saved_keys
;
4297 struct gcpro gcpro1
;
4299 saved_keys
= Fthis_command_keys ();
4301 GCPRO1 (saved_keys
);
4303 if (EQ (prefixarg
, Qminus
))
4305 else if (CONSP (prefixarg
) && XINT (XCONS (prefixarg
)->car
) == 4)
4306 strcpy (buf
, "C-u ");
4307 else if (CONSP (prefixarg
) && XTYPE (XCONS (prefixarg
)->car
) == Lisp_Int
)
4308 sprintf (buf
, "%d ", XINT (XCONS (prefixarg
)->car
));
4309 else if (XTYPE (prefixarg
) == Lisp_Int
)
4310 sprintf (buf
, "%d ", XINT (prefixarg
));
4312 /* This isn't strictly correct if execute-extended-command
4313 is bound to anything else. Perhaps it should use
4314 this_command_keys? */
4315 strcat (buf
, "M-x ");
4317 /* Prompt with buf, and then read a string, completing from and
4318 restricting to the set of all defined commands. Don't provide
4319 any initial input. The last Qnil says not to perform a
4320 peculiar hack on the initial input. */
4321 function
= Fcompleting_read (build_string (buf
),
4322 Vobarray
, Qcommandp
,
4325 /* Set this_command_keys to the concatenation of saved_keys and
4326 function, followed by a RET. */
4328 struct Lisp_String
*str
;
4332 this_command_key_count
= 0;
4334 str
= XSTRING (saved_keys
);
4335 for (i
= 0; i
< str
->size
; i
++)
4337 XFASTINT (tem
) = str
->data
[i
];
4338 add_command_key (tem
);
4341 str
= XSTRING (function
);
4342 for (i
= 0; i
< str
->size
; i
++)
4344 XFASTINT (tem
) = str
->data
[i
];
4345 add_command_key (tem
);
4348 XFASTINT (tem
) = '\015';
4349 add_command_key (tem
);
4354 function
= Fintern (function
, Qnil
);
4355 Vprefix_arg
= prefixarg
;
4356 this_command
= function
;
4358 return Fcommand_execute (function
, Qt
);
4362 detect_input_pending ()
4365 get_input_pending (&input_pending
);
4367 return input_pending
;
4370 /* This is called in some cases before a possible quit.
4371 It cases the next call to detect_input_pending to recompute input_pending.
4372 So calling this function unnecessarily can't do any harm. */
4373 clear_input_pending ()
4378 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
4379 "T if command input is currently available with no waiting.\n\
4380 Actually, the value is nil only if we can be sure that no input is available.")
4383 if (!NILP (unread_command_events
) || unread_command_char
!= -1)
4386 return detect_input_pending () ? Qt
: Qnil
;
4389 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
4390 "Return vector of last 100 events, not counting those from keyboard macros.")
4393 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
4396 if (total_keys
< NUM_RECENT_KEYS
)
4397 return Fvector (total_keys
, keys
);
4400 val
= Fvector (NUM_RECENT_KEYS
, keys
);
4401 bcopy (keys
+ recent_keys_index
,
4402 XVECTOR (val
)->contents
,
4403 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
4405 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
4406 recent_keys_index
* sizeof (Lisp_Object
));
4411 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
4412 "Return the key sequence that invoked this command.\n\
4413 The value is a string or a vector.")
4416 return make_event_array (this_command_key_count
,
4417 XVECTOR (this_command_keys
)->contents
);
4420 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
4421 "Return the current depth in recursive edits.")
4425 XFASTINT (temp
) = command_loop_level
+ minibuf_level
;
4429 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
4430 "FOpen dribble file: ",
4431 "Start writing all keyboard characters to a dribble file called FILE.\n\
4432 If FILE is nil, close any open dribble file.")
4443 file
= Fexpand_file_name (file
, Qnil
);
4444 dribble
= fopen (XSTRING (file
)->data
, "w");
4449 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
4450 "Discard the contents of the terminal input buffer.\n\
4451 Also cancel any kbd macro being defined.")
4454 defining_kbd_macro
= 0;
4455 update_mode_lines
++;
4457 unread_command_events
= Qnil
;
4458 unread_command_char
= -1;
4460 discard_tty_input ();
4462 /* Without the cast, GCC complains that this assignment loses the
4463 volatile qualifier of kbd_store_ptr. Is there anything wrong
4465 kbd_fetch_ptr
= (struct input_event
*) kbd_store_ptr
;
4466 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
4472 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
4473 "Stop Emacs and return to superior process. You can resume later.\n\
4474 On systems that don't have job control, run a subshell instead.\n\n\
4475 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
4476 to be read as terminal input by Emacs's parent, after suspension.\n\
4478 Before suspending, call the functions in `suspend-hook' with no args.\n\
4479 If any of them returns nil, don't call the rest and don't suspend.\n\
4480 Otherwise, suspend normally and after resumption run the normal hook\n\
4481 `suspend-resume-hook' if that is bound and non-nil.\n\
4483 Some operating systems cannot stop the Emacs process and resume it later.\n\
4484 On such systems, Emacs starts a subshell instead of suspending.")
4486 Lisp_Object stuffstring
;
4489 int count
= specpdl_ptr
- specpdl
;
4490 int old_height
, old_width
;
4492 struct gcpro gcpro1
, gcpro2
;
4493 extern init_sys_modes ();
4495 if (!NILP (stuffstring
))
4496 CHECK_STRING (stuffstring
, 0);
4498 /* Run the functions in suspend-hook. */
4499 if (!NILP (Vrun_hooks
))
4500 call1 (Vrun_hooks
, intern ("suspend-hook"));
4502 GCPRO1 (stuffstring
);
4503 get_frame_size (&old_width
, &old_height
);
4505 /* sys_suspend can get an error if it tries to fork a subshell
4506 and the system resources aren't available for that. */
4507 record_unwind_protect (init_sys_modes
, 0);
4508 stuff_buffered_input (stuffstring
);
4510 unbind_to (count
, Qnil
);
4512 /* Check if terminal/window size has changed.
4513 Note that this is not useful when we are running directly
4514 with a window system; but suspend should be disabled in that case. */
4515 get_frame_size (&width
, &height
);
4516 if (width
!= old_width
|| height
!= old_height
)
4517 change_frame_size (0, height
, width
, 0, 0);
4519 /* Run suspend-resume-hook. */
4520 if (!NILP (Vrun_hooks
))
4521 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
4527 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
4528 Then in any case stuff anything Emacs has read ahead and not used. */
4530 stuff_buffered_input (stuffstring
)
4531 Lisp_Object stuffstring
;
4533 register unsigned char *p
;
4535 /* stuff_char works only in BSD, versions 4.2 and up. */
4538 if (XTYPE (stuffstring
) == Lisp_String
)
4542 p
= XSTRING (stuffstring
)->data
;
4543 count
= XSTRING (stuffstring
)->size
;
4548 /* Anything we have read ahead, put back for the shell to read. */
4549 while (kbd_fetch_ptr
!= kbd_store_ptr
)
4551 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
4552 kbd_fetch_ptr
= kbd_buffer
;
4553 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
4554 stuff_char (XINT (kbd_fetch_ptr
->code
));
4555 kbd_fetch_ptr
->kind
= no_event
;
4556 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_fetch_ptr
4563 #endif /* BSD and not BSD4_1 */
4566 set_waiting_for_input (time_to_clear
)
4567 EMACS_TIME
*time_to_clear
;
4569 input_available_clear_time
= time_to_clear
;
4571 /* Tell interrupt_signal to throw back to read_char, */
4572 waiting_for_input
= 1;
4574 /* If interrupt_signal was called before and buffered a C-g,
4575 make it run again now, to avoid timing error. */
4576 if (!NILP (Vquit_flag
))
4577 quit_throw_to_read_char ();
4579 /* If alarm has gone off already, echo now. */
4587 clear_waiting_for_input ()
4589 /* Tell interrupt_signal not to throw back to read_char, */
4590 waiting_for_input
= 0;
4591 input_available_clear_time
= 0;
4594 /* This routine is called at interrupt level in response to C-G.
4595 If interrupt_input, this is the handler for SIGINT.
4596 Otherwise, it is called from kbd_buffer_store_event,
4597 in handling SIGIO or SIGTINT.
4599 If `waiting_for_input' is non zero, then unless `echoing' is nonzero,
4600 immediately throw back to read_char.
4602 Otherwise it sets the Lisp variable quit-flag not-nil.
4603 This causes eval to throw, when it gets a chance.
4604 If quit-flag is already non-nil, it stops the job right away. */
4610 /* Must preserve main program's value of errno. */
4611 int old_errno
= errno
;
4614 /* USG systems forget handlers when they are used;
4615 must reestablish each time */
4616 signal (SIGINT
, interrupt_signal
);
4617 signal (SIGQUIT
, interrupt_signal
);
4622 if (!NILP (Vquit_flag
) && FRAME_TERMCAP_P (selected_frame
))
4627 #ifdef SIGTSTP /* Support possible in later USG versions */
4629 * On systems which can suspend the current process and return to the original
4630 * shell, this command causes the user to end up back at the shell.
4631 * The "Auto-save" and "Abort" questions are not asked until
4632 * the user elects to return to emacs, at which point he can save the current
4633 * job and either dump core or continue.
4638 if (sys_suspend () == -1)
4640 printf ("Not running as a subprocess;\n");
4641 printf ("you can continue or abort.\n");
4644 /* Perhaps should really fork an inferior shell?
4645 But that would not provide any way to get back
4646 to the original shell, ever. */
4647 printf ("No support for stopping a process on this operating system;\n");
4648 printf ("you can continue or abort.\n");
4649 #endif /* not VMS */
4650 #endif /* not SIGTSTP */
4651 printf ("Auto-save? (y or n) ");
4653 if (((c
= getchar ()) & ~040) == 'Y')
4654 Fdo_auto_save (Qnil
, Qnil
);
4655 while (c
!= '\n') c
= getchar ();
4657 printf ("Abort (and enter debugger)? (y or n) ");
4659 printf ("Abort (and dump core)? (y or n) ");
4660 #endif /* not VMS */
4662 if (((c
= getchar ()) & ~040) == 'Y')
4664 while (c
!= '\n') c
= getchar ();
4665 printf ("Continuing...\n");
4671 /* If executing a function that wants to be interrupted out of
4672 and the user has not deferred quitting by binding `inhibit-quit'
4673 then quit right away. */
4674 if (immediate_quit
&& NILP (Vinhibit_quit
))
4678 Fsignal (Qquit
, Qnil
);
4681 /* Else request quit when it's safe */
4685 if (waiting_for_input
&& !echoing
)
4686 quit_throw_to_read_char ();
4691 /* Handle a C-g by making read_char return C-g. */
4693 quit_throw_to_read_char ()
4695 quit_error_check ();
4697 /* Prevent another signal from doing this before we finish. */
4698 clear_waiting_for_input ();
4701 unread_command_events
= Qnil
;
4702 unread_command_char
= -1;
4704 #ifdef POLL_FOR_INPUT
4705 /* May be > 1 if in recursive minibuffer. */
4706 if (poll_suppress_count
== 0)
4710 _longjmp (getcjmp
, 1);
4713 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
4714 "Set mode of reading keyboard input.\n\
4715 First arg INTERRUPT non-nil means use input interrupts;\n\
4716 nil means use CBREAK mode.\n\
4717 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
4718 (no effect except in CBREAK mode).\n\
4719 Third arg META t means accept 8-bit input (for a Meta key).\n\
4720 META nil means ignore the top bit, on the assumption it is parity.\n\
4721 Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\
4722 Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\
4723 See also `current-input-mode'.")
4724 (interrupt
, flow
, meta
, quit
)
4725 Lisp_Object interrupt
, flow
, meta
, quit
;
4728 && (XTYPE (quit
) != Lisp_Int
4729 || XINT (quit
) < 0 || XINT (quit
) > 0400))
4730 error ("set-input-mode: QUIT must be an ASCII character.");
4734 /* Note SIGIO has been undef'd if FIONREAD is missing. */
4735 #ifdef NO_SOCK_SIGIO
4736 if (read_socket_hook
)
4737 interrupt_input
= 0; /* No interrupts if reading from a socket. */
4739 #endif /* NO_SOCK_SIGIO */
4740 interrupt_input
= !NILP (interrupt
);
4741 #else /* not SIGIO */
4742 interrupt_input
= 0;
4743 #endif /* not SIGIO */
4744 /* Our VMS input only works by interrupts, as of now. */
4746 interrupt_input
= 1;
4748 flow_control
= !NILP (flow
);
4751 else if (EQ (meta
, Qt
))
4756 /* Don't let this value be out of range. */
4757 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
4763 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
4764 "Return information about the way Emacs currently reads keyboard input.\n\
4765 The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
4766 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\
4767 nil, Emacs is using CBREAK mode.\n\
4768 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\
4769 terminal; this does not apply if Emacs uses interrupt-driven input.\n\
4770 META is t if accepting 8-bit input with 8th bit as Meta flag.\n\
4771 META nil means ignoring the top bit, on the assumption it is parity.\n\
4772 META is neither t nor nil if accepting 8-bit input and using\n\
4773 all 8 bits as the character code.\n\
4774 QUIT is the character Emacs currently uses to quit.\n\
4775 The elements of this list correspond to the arguments of\n\
4781 val
[0] = interrupt_input
? Qt
: Qnil
;
4782 val
[1] = flow_control
? Qt
: Qnil
;
4783 val
[2] = meta_key
== 2 ? make_number (0) : meta_key
== 1 ? Qt
: Qnil
;
4784 XFASTINT (val
[3]) = quit_char
;
4786 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
4792 /* This is correct before outermost invocation of the editor loop */
4793 command_loop_level
= -1;
4795 quit_char
= Ctl ('g');
4796 unread_command_events
= Qnil
;
4797 unread_command_char
= -1;
4799 recent_keys_index
= 0;
4800 kbd_fetch_ptr
= kbd_buffer
;
4801 kbd_store_ptr
= kbd_buffer
;
4802 do_mouse_tracking
= 0;
4806 /* This means that command_loop_1 won't try to select anything the first
4808 internal_last_event_frame
= Qnil
;
4809 Vlast_event_frame
= internal_last_event_frame
;
4812 /* If we're running a dumped Emacs, we need to clear out
4813 kbd_buffer_frame_or_window, in case some events got into it
4816 If we're running an undumped Emacs, it hasn't been initialized by
4817 syms_of_keyboard yet. */
4819 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
4821 if (!noninteractive
)
4823 signal (SIGINT
, interrupt_signal
);
4824 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
4825 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
4826 SIGQUIT and we can't tell which one it will give us. */
4827 signal (SIGQUIT
, interrupt_signal
);
4828 #endif /* HAVE_TERMIO */
4829 /* Note SIGIO has been undef'd if FIONREAD is missing. */
4831 signal (SIGIO
, input_available_signal
);
4835 /* Use interrupt input by default, if it works and noninterrupt input
4836 has deficiencies. */
4838 #ifdef INTERRUPT_INPUT
4839 interrupt_input
= 1;
4841 interrupt_input
= 0;
4844 /* Our VMS input only works by interrupts, as of now. */
4846 interrupt_input
= 1;
4852 if (keyboard_init_hook
)
4853 (*keyboard_init_hook
) ();
4855 #ifdef POLL_FOR_INPUT
4856 poll_suppress_count
= 1;
4861 /* This type's only use is in syms_of_keyboard, to initialize the
4862 event header symbols and put properties on them. */
4869 struct event_head head_table
[] = {
4870 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
4871 &Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
,
4872 &Qswitch_frame
, "switch-frame", &Qswitch_frame
,
4877 Qself_insert_command
= intern ("self-insert-command");
4878 staticpro (&Qself_insert_command
);
4880 Qforward_char
= intern ("forward-char");
4881 staticpro (&Qforward_char
);
4883 Qbackward_char
= intern ("backward-char");
4884 staticpro (&Qbackward_char
);
4886 Qdisabled
= intern ("disabled");
4887 staticpro (&Qdisabled
);
4889 Qpre_command_hook
= intern ("pre-command-hook");
4890 staticpro (&Qpre_command_hook
);
4892 Qpost_command_hook
= intern ("post-command-hook");
4893 staticpro (&Qpost_command_hook
);
4895 Qfunction_key
= intern ("function-key");
4896 staticpro (&Qfunction_key
);
4897 Qmouse_click
= intern ("mouse-click");
4898 staticpro (&Qmouse_click
);
4900 Qmenu_enable
= intern ("menu-enable");
4901 staticpro (&Qmenu_enable
);
4903 Qmode_line
= intern ("mode-line");
4904 staticpro (&Qmode_line
);
4905 Qvertical_line
= intern ("vertical-line");
4906 staticpro (&Qvertical_line
);
4907 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
4908 staticpro (&Qvertical_scroll_bar
);
4909 Qmenu_bar
= intern ("menu-bar");
4910 staticpro (&Qmenu_bar
);
4912 Qabove_handle
= intern ("above-handle");
4913 staticpro (&Qabove_handle
);
4914 Qhandle
= intern ("handle");
4915 staticpro (&Qhandle
);
4916 Qbelow_handle
= intern ("below-handle");
4917 staticpro (&Qbelow_handle
);
4919 Qevent_kind
= intern ("event-kind");
4920 staticpro (&Qevent_kind
);
4921 Qevent_symbol_elements
= intern ("event-symbol-elements");
4922 staticpro (&Qevent_symbol_elements
);
4923 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
4924 staticpro (&Qevent_symbol_element_mask
);
4925 Qmodifier_cache
= intern ("modifier-cache");
4926 staticpro (&Qmodifier_cache
);
4928 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
4929 staticpro (&Qrecompute_lucid_menubar
);
4930 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
4931 staticpro (&Qactivate_menubar_hook
);
4934 struct event_head
*p
;
4936 for (p
= head_table
;
4937 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
4940 *p
->var
= intern (p
->name
);
4942 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
4943 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
4947 button_down_location
= Fmake_vector (make_number (NUM_MOUSE_BUTTONS
), Qnil
);
4948 staticpro (&button_down_location
);
4952 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
4954 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
4955 for (i
= 0; i
< len
; i
++)
4956 if (modifier_names
[i
])
4957 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
4958 staticpro (&modifier_symbols
);
4961 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
4962 staticpro (&recent_keys
);
4964 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
4965 staticpro (&this_command_keys
);
4967 kbd_buffer_frame_or_window
4968 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
4969 staticpro (&kbd_buffer_frame_or_window
);
4971 func_key_syms
= Qnil
;
4972 staticpro (&func_key_syms
);
4975 staticpro (&mouse_syms
);
4977 unread_switch_frame
= Qnil
;
4978 staticpro (&unread_switch_frame
);
4980 defsubr (&Sread_key_sequence
);
4981 defsubr (&Srecursive_edit
);
4982 defsubr (&Strack_mouse
);
4983 defsubr (&Sinput_pending_p
);
4984 defsubr (&Scommand_execute
);
4985 defsubr (&Srecent_keys
);
4986 defsubr (&Sthis_command_keys
);
4987 defsubr (&Ssuspend_emacs
);
4988 defsubr (&Sabort_recursive_edit
);
4989 defsubr (&Sexit_recursive_edit
);
4990 defsubr (&Srecursion_depth
);
4991 defsubr (&Stop_level
);
4992 defsubr (&Sdiscard_input
);
4993 defsubr (&Sopen_dribble_file
);
4994 defsubr (&Sset_input_mode
);
4995 defsubr (&Scurrent_input_mode
);
4996 defsubr (&Sexecute_extended_command
);
4998 DEFVAR_LISP ("disabled-command-hook", &Vdisabled_command_hook
,
4999 "Value is called instead of any command that is disabled\n\
5000 \(has a non-nil `disabled' property).");
5002 DEFVAR_LISP ("last-command-char", &last_command_char
,
5003 "Last input event that was part of a command.");
5005 DEFVAR_LISP ("last-command-event", &last_command_char
,
5006 "Last input event that was part of a command.");
5008 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
5009 "Last input event in a command, except for mouse menu events.\n\
5010 Mouse menus give back keys that don't look like mouse events;\n\
5011 this variable holds the actual mouse event that led to the menu,\n\
5012 so that you can determine whether the command was run by mouse or not.");
5014 DEFVAR_LISP ("last-input-char", &last_input_char
,
5015 "Last input event.");
5017 DEFVAR_LISP ("last-input-event", &last_input_char
,
5018 "Last input event.");
5020 DEFVAR_LISP ("unread-command-events", &unread_command_events
,
5021 "List of objects to be read as next command input events.");
5023 DEFVAR_INT ("unread-command-char", &unread_command_char
,
5024 "If not -1, an object to be read as next command input event.");
5026 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
5027 "Meta-prefix character code. Meta-foo as command input\n\
5028 turns into this character followed by foo.");
5029 XSET (meta_prefix_char
, Lisp_Int
, 033);
5031 DEFVAR_LISP ("last-command", &last_command
,
5032 "The last command executed. Normally a symbol with a function definition,\n\
5033 but can be whatever was found in the keymap, or whatever the variable\n\
5034 `this-command' was set to by that command.");
5035 last_command
= Qnil
;
5037 DEFVAR_LISP ("this-command", &this_command
,
5038 "The command now being executed.\n\
5039 The command can set this variable; whatever is put here\n\
5040 will be in `last-command' during the following command.");
5041 this_command
= Qnil
;
5043 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
5044 "*Number of keyboard input characters between auto-saves.\n\
5045 Zero means disable autosaving due to number of characters typed.");
5046 auto_save_interval
= 300;
5048 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
5049 "*Number of seconds idle time before auto-save.\n\
5050 Zero or nil means disable auto-saving due to idleness.\n\
5051 After auto-saving due to this many seconds of idle time,\n\
5052 Emacs also does a garbage collection if that seems to be warranted.");
5053 XFASTINT (Vauto_save_timeout
) = 30;
5055 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes
,
5056 "*Nonzero means echo unfinished commands after this many seconds of pause.");
5057 echo_keystrokes
= 1;
5059 DEFVAR_INT ("polling-period", &polling_period
,
5060 "*Interval between polling for input during Lisp execution.\n\
5061 The reason for polling is to make C-g work to stop a running program.\n\
5062 Polling is needed only when using X windows and SIGIO does not work.\n\
5063 Polling is automatically disabled in all other cases.");
5066 DEFVAR_INT ("double-click-time", &double_click_time
,
5067 "*Maximum time between mouse clicks to make a double-click.\n\
5068 Measured in milliseconds. Zero means disable double-click recognition;\n\
5069 a large number means double-clicks have no time limit and are detected\n\
5070 by position only.");
5071 double_click_time
= 500;
5073 DEFVAR_INT ("num-input-keys", &num_input_keys
,
5074 "*Number of complete keys read from the keyboard so far.");
5078 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
5079 "*The frame in which the most recently read event occurred.\n\
5080 If the last event came from a keyboard macro, this is set to `macro'.");
5081 Vlast_event_frame
= Qnil
;
5084 DEFVAR_LISP ("help-char", &help_char
,
5085 "Character to recognize as meaning Help.\n\
5086 When it is read, do `(eval help-form)', and display result if it's a string.\n\
5087 If the value of `help-form' is nil, this char can be read normally.");
5088 XSET (help_char
, Lisp_Int
, Ctl ('H'));
5090 DEFVAR_LISP ("help-form", &Vhelp_form
,
5091 "Form to execute when character help-char is read.\n\
5092 If the form returns a string, that string is displayed.\n\
5093 If `help-form' is nil, the help char is not recognized.");
5096 DEFVAR_LISP ("top-level", &Vtop_level
,
5097 "Form to evaluate when Emacs starts up.\n\
5098 Useful to set before you dump a modified Emacs.");
5101 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
5102 "String used as translate table for keyboard input, or nil.\n\
5103 Each character is looked up in this string and the contents used instead.\n\
5104 If string is of length N, character codes N and up are untranslated.");
5105 Vkeyboard_translate_table
= Qnil
;
5107 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
5108 "Non-nil means prompt with menus when appropriate.\n\
5109 This is done when reading from a keymap that has a prompt string,\n\
5110 for elements that have prompt strings.\n\
5111 The menu is displayed on the screen\n\
5112 if X menus were enabled at configuration\n\
5113 time and the previous event was a mouse click prefix key.\n\
5114 Otherwise, menu prompting uses the echo area.");
5117 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
5118 "Character to see next line of menu prompt.\n\
5119 Type this character while in a menu prompt to rotate around the lines of it.");
5120 XSET (menu_prompt_more_char
, Lisp_Int
, ' ');
5122 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
5123 "A mask of additional modifier keys to use with every keyboard character.\n\
5124 Emacs applies the modifiers of the character stored here to each keyboard\n\
5125 character it reads. For example, after evaluating the expression\n\
5126 (setq extra-keyboard-modifiers ?\C-x)\n\
5127 all input characters will have the control modifier applied to them.\n\
5129 Note that the character ?\C-@, equivalent to the integer zero, does\n\
5130 not count as a control character; rather, it counts as a character\n\
5131 with no modifiers; thus, setting extra_keyboard_modifiers to zero\n\
5132 cancels any modification.");
5133 extra_keyboard_modifiers
= 0;
5135 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
5136 "If an editing command sets this to t, deactivate the mark afterward.\n\
5137 The command loop sets this to nil before each command,\n\
5138 and tests the value when the command returns.\n\
5139 Buffer modification stores t in this variable.");
5140 Vdeactivate_mark
= Qnil
;
5142 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
5143 "Normal hook run before each command is executed.");
5144 Vpre_command_hook
= Qnil
;
5146 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
5147 "Normal hook run before each command is executed.");
5148 Vpost_command_hook
= Qnil
;
5150 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
5151 "t means menu bar, specified Lucid style, needs to be recomputed.");
5152 Vlucid_menu_bar_dirty_flag
= Qnil
;
5157 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
5158 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
5159 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
5160 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
5161 initial_define_key (meta_map
, 'x', "execute-extended-command");