1 /* Keyboard and mouse input; editor command loop.
2 Copyright (C) 1985, 1986, 1987, 1988, 1989, 1992 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 1, 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"
41 #include <sys/ioctl.h>
44 #include "syssignal.h"
51 extern Lisp_Object Vmouse_grabbed
;
53 /* Make all keyboard buffers much bigger when using X windows. */
54 #define KBD_BUFFER_SIZE 4096
55 #else /* No X-windows, character input */
56 #define KBD_BUFFER_SIZE 256
57 #endif /* No X-windows */
59 /* Following definition copied from eval.c */
63 struct backtrace
*next
;
64 Lisp_Object
*function
;
65 Lisp_Object
*args
; /* Points to vector of args. */
66 int nargs
; /* length of vector. If nargs is UNEVALLED,
67 args points to slot holding list of
72 /* Non-nil disable property on a command means
73 do not execute it; call disabled-command-hook's value instead. */
74 Lisp_Object Qdisabled
, Vdisabled_command_hook
;
76 #define NUM_RECENT_KEYS (100)
77 int recent_keys_index
; /* Index for storing next element into recent_keys */
78 int total_keys
; /* Total number of elements stored into recent_keys */
79 Lisp_Object recent_keys
[NUM_RECENT_KEYS
]; /* Holds last 100 keystrokes */
81 /* Buffer holding the key that invoked the current command. */
82 Lisp_Object
*this_command_keys
;
83 int this_command_key_count
; /* Size in use. */
84 int this_command_keys_size
; /* Size allocated. */
86 extern int minbuf_level
;
88 extern struct backtrace
*backtrace_list
;
90 /* Nonzero means do menu prompting. */
91 static int menu_prompting
;
93 /* Character to see next line of menu prompt. */
94 static Lisp_Object menu_prompt_more_char
;
96 /* For longjmp to where kbd input is being done. */
97 static jmp_buf getcjmp
;
99 /* True while doing kbd input. */
100 int waiting_for_input
;
102 /* True while displaying for echoing. Delays C-g throwing. */
105 /* Nonzero means C-G should cause immediate error-signal. */
108 /* Character to recognize as the help char. */
109 Lisp_Object help_char
;
111 /* Form to execute when help char is typed. */
112 Lisp_Object Vhelp_form
;
114 /* Character that causes a quit. Normally C-g.
116 If we are running on an ordinary terminal, this must be an ordinary
117 ASCII char, since we want to make it our interrupt character.
119 If we are not running on an ordinary terminal, it still needs to be
120 an ordinary ASCII char. This character needs to be recognized in
121 the input interrupt handler. At this point, the keystroke is
122 represented as a struct input_event, while the desired quit
123 character is specified as a lispy event. The mapping from struct
124 input_events to lispy events cannot run in an interrupt handler,
125 and the reverse mapping is difficult for anything but ASCII
128 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
132 extern Lisp_Object current_global_map
;
133 extern int minibuf_level
;
135 /* Current depth in recursive edits. */
136 int command_loop_level
;
138 /* Total number of times command_loop has read a key sequence. */
141 /* Last input character read as a command. */
142 Lisp_Object last_command_char
;
144 /* Last input character read for any purpose. */
145 Lisp_Object last_input_char
;
147 /* If not Qnil, an object to be read as the next command input. */
148 Lisp_Object unread_command_char
;
150 /* Char to use as prefix when a meta character is typed in.
151 This is bound on entry to minibuffer in case ESC is changed there. */
153 Lisp_Object meta_prefix_char
;
155 /* Last size recorded for a current buffer which is not a minibuffer. */
156 static int last_non_minibuf_size
;
158 /* Number of idle seconds before an auto-save and garbage collection. */
159 static Lisp_Object Vauto_save_timeout
;
161 /* Total number of times read_char has returned. */
164 /* Auto-save automatically when this many characters have been typed
165 since the last time. */
167 static int auto_save_interval
;
169 /* Value of num_input_chars as of last auto save. */
173 /* Last command executed by the editor command loop, not counting
174 commands that set the prefix argument. */
176 Lisp_Object last_command
;
178 /* The command being executed by the command loop.
179 Commands may set this, and the value set will be copied into last_command
180 instead of the actual command. */
181 Lisp_Object this_command
;
184 /* Window of last mouse click. */
185 extern Lisp_Object Vmouse_window
;
187 /* List containing details of last mouse click. */
188 extern Lisp_Object Vmouse_event
;
189 #endif /* defined HAVE_X11 */
191 /* Hook to call on each mouse event after running its definition. */
192 Lisp_Object Vmouse_event_function
;
194 /* Hook to call when mouse leaves screen. */
195 Lisp_Object Vmouse_left_hook
;
197 /* Hook to call when a screen is mapped. */
198 Lisp_Object Vmap_screen_hook
;
200 /* Hook to call when a screen is unmapped. */
201 Lisp_Object Vunmap_screen_hook
;
203 /* Handler for non-grabbed (no keys depressed) mouse motion. */
204 Lisp_Object Vmouse_motion_handler
;
206 /* The screen in which the last input event occurred.
207 command_loop_1 will select this screen before running the
208 command bound to an event sequence, and read_key_sequence will
209 toss the existing prefix if the user starts typing at a
211 Lisp_Object Vlast_event_screen
;
213 /* X Windows wants this for selection ownership. */
214 unsigned long last_event_timestamp
;
216 Lisp_Object Qself_insert_command
;
217 Lisp_Object Qforward_char
;
218 Lisp_Object Qbackward_char
;
220 /* read_key_sequence stores here the command definition of the
221 key sequence that it reads. */
222 Lisp_Object read_key_sequence_cmd
;
224 /* Form to evaluate (if non-nil) when Emacs is started. */
225 Lisp_Object Vtop_level
;
227 /* User-supplied string to translate input characters through. */
228 Lisp_Object Vkeyboard_translate_table
;
230 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
231 extern Lisp_Object Vfunction_key_map
;
233 /* File in which we write all commands we read. */
236 /* Nonzero if input is available. */
239 /* Nonzero if should obey 0200 bit in input chars as "Meta". */
242 extern char *pending_malloc_warning
;
244 /* Circular buffer for pre-read keyboard input. */
245 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
247 /* Pointer to next available character in kbd_buffer.
248 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
249 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the
250 next available char is in kbd_buffer[0]. */
251 static struct input_event
*kbd_fetch_ptr
;
253 /* Pointer to next place to store character in kbd_buffer. This
254 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
255 character should go in kbd_buffer[0]. */
256 static struct input_event
*kbd_store_ptr
;
258 /* The above pair of variables forms a "queue empty" flag. When we
259 enqueue a non-hook event, we increment kbd_write_count. When we
260 dequeue a non-hook event, we increment kbd_read_count. We say that
261 there is input available iff the two counters are equal.
263 Why not just have a flag set and cleared by the enqueuing and
264 dequeuing functions? Such a flag could be screwed up by interrupts
265 at inopportune times. */
267 /* If this flag is non-zero, mouse movement events will appear in the
268 input stream. If is zero, mouse movement will be ignored. */
269 int do_mouse_tracking
;
271 /* The window system handling code should set this if the mouse has
272 moved since the last call to the mouse_position_hook. Calling that
273 hook should clear this. Code assumes that if this is set, it can
274 call mouse_position_hook to get the promised position, so don't set
275 it unless you're prepared to substantiate the claim! */
278 /* True iff there is an event in kbd_buffer, or if mouse tracking is
279 enabled and there is a new mouse position in the mouse movement
280 buffer. Note that if this is false, that doesn't mean that there
281 is readable input; all the events in the queue might be button-up
282 events, and do_mouse_tracking might be off. */
283 #define EVENT_QUEUES_EMPTY \
284 ((kbd_fetch_ptr == kbd_store_ptr) && (!do_mouse_tracking || !mouse_moved))
287 /* Symbols to head events. */
288 Lisp_Object Qmouse_movement
;
290 Lisp_Object Qvscrollbar_part
;
291 Lisp_Object Qvslider_part
;
292 Lisp_Object Qvthumbup_part
;
293 Lisp_Object Qvthumbdown_part
;
295 Lisp_Object Qhscrollbar_part
;
296 Lisp_Object Qhslider_part
;
297 Lisp_Object Qhthumbleft_part
;
298 Lisp_Object Qhthumbright_part
;
300 /* Symbols to denote kinds of events. */
301 Lisp_Object Qfunction_key
;
302 Lisp_Object Qmouse_click
;
303 /* Lisp_Object Qmouse_movement; - also an event header */
304 Lisp_Object Qscrollbar_click
;
306 /* Properties of event headers. */
307 Lisp_Object Qevent_kind
;
308 Lisp_Object Qevent_unmodified
;
310 /* Symbols to use for non-text mouse positions. */
311 Lisp_Object Qmode_line
;
312 Lisp_Object Qvertical_split
;
315 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
317 EMACS_TIME
*input_available_clear_time
;
319 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
320 Default is 1 if INTERRUPT_INPUT is defined. */
323 /* Nonzero while interrupts are temporarily deferred during redisplay. */
324 int interrupts_deferred
;
326 /* nonzero means use ^S/^Q for flow control. */
329 /* Allow m- file to inhibit use of FIONREAD. */
330 #ifdef BROKEN_FIONREAD
334 /* We are unable to use interrupts if FIONREAD is not available,
335 so flush SIGIO so we won't try. */
342 /* If we support X Windows, and won't get an interrupt when input
343 arrives from the server, poll periodically so we can detect C-g. */
344 #ifdef HAVE_X_WINDOWS
346 #define POLL_FOR_INPUT
350 /* Global variable declarations. */
352 /* Function for init_keyboard to call with no args (if nonzero). */
353 void (*keyboard_init_hook
) ();
355 static int read_avail_input ();
356 static void get_input_pending ();
358 /* > 0 if we are to echo keystrokes. */
359 static int echo_keystrokes
;
361 /* Nonzero means echo each character as typed. */
362 static int immediate_echo
;
364 /* The text we're echoing in the modeline - partial key sequences,
365 usually. '\0'-terminated. */
366 static char echobuf
[100];
368 /* Where to append more text to echobuf if we want to. */
369 static char *echoptr
;
371 #define min(a,b) ((a)<(b)?(a):(b))
372 #define max(a,b) ((a)>(b)?(a):(b))
374 /* Install the string STR as the beginning of the string of echoing,
375 so that it serves as a prompt for the next character.
376 Also start echoing. */
381 int len
= strlen (str
);
382 if (len
> sizeof echobuf
- 4)
383 len
= sizeof echobuf
- 4;
384 bcopy (str
, echobuf
, len
+ 1);
385 echoptr
= echobuf
+ len
;
390 /* Add C to the echo string, if echoing is going on.
391 C can be a character, which is printed prettily ("M-C-x" and all that
392 jazz), or a symbol, whose name is printed. */
397 extern char *push_key_description ();
406 /* If someone has passed us a composite event, use its head symbol. */
407 if (EVENT_HAS_PARAMETERS (c
))
410 if (XTYPE (c
) == Lisp_Int
)
412 if (ptr
- echobuf
> sizeof echobuf
- 6)
415 ptr
= push_key_description (c
, ptr
);
417 else if (XTYPE (c
) == Lisp_Symbol
)
419 struct Lisp_String
*name
= XSYMBOL (c
)->name
;
420 if (((ptr
- echobuf
) + name
->size
+ 4) > sizeof echobuf
)
422 bcopy (name
->data
, ptr
, name
->size
);
426 if (echoptr
== echobuf
&& c
== help_char
)
428 strcpy (ptr
, " (Type ? for further options)");
439 /* Temporarily add a dash to the end of the echo string if it's not
440 empty, so that it serves as a mini-prompt for the very next character. */
444 if (!immediate_echo
&& echoptr
== echobuf
)
447 /* Put a dash at the end of the buffer temporarily,
448 but make it go away when the next character is added. */
455 /* Display the current echo string, and begin echoing if not already
465 for (i
= 0; i
< this_command_key_count
; i
++)
466 echo_char (this_command_keys
[i
]);
474 if (waiting_for_input
&& !NILP (Vquit_flag
))
475 quit_throw_to_read_char ();
478 /* Turn off echoing, for the start of a new command. */
486 /* Return the length of the current echo string. */
491 return echoptr
- echobuf
;
494 /* Truncate the current echo message to its first LEN chars.
495 This and echo_char get used by read_key_sequence when the user
496 switches screens while entering a key sequence. */
503 echoptr
= echobuf
+ strlen (echobuf
);
507 /* Functions for manipulating this_command_keys. */
509 add_command_key (key
)
512 if (this_command_key_count
== this_command_keys_size
)
514 this_command_keys_size
*= 2;
516 = (Lisp_Object
*) xrealloc (this_command_keys
,
517 (this_command_keys_size
518 * sizeof (Lisp_Object
)));
520 this_command_keys
[this_command_key_count
++] = key
;
526 int count
= specpdl_ptr
- specpdl
;
529 if (command_loop_level
> 0)
531 specbind (Qstandard_output
, Qt
);
532 specbind (Qstandard_input
, Qt
);
535 val
= command_loop ();
537 Fsignal (Qquit
, Qnil
);
543 /* When an auto-save happens, record the "time", and don't do again soon. */
546 last_auto_save
= num_input_chars
;
549 Lisp_Object
recursive_edit_unwind (), command_loop ();
551 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
552 "Invoke the editor command loop recursively.\n\
553 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
554 that tells this function to return.\n\
555 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
556 This function is called by the editor initialization to begin editing.")
559 int count
= specpdl_ptr
- specpdl
;
562 command_loop_level
++;
563 update_mode_lines
= 1;
565 record_unwind_protect (recursive_edit_unwind
,
567 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
571 return unbind_to (count
, Qnil
);
575 recursive_edit_unwind (buffer
)
579 Fset_buffer (buffer
);
581 command_loop_level
--;
582 update_mode_lines
= 1;
590 Lisp_Object errmsg
, tail
, errname
, file_error
;
597 Vstandard_output
= Qt
;
598 Vstandard_input
= Qt
;
599 Vexecuting_macro
= Qnil
;
600 echo_area_glyphs
= 0;
602 /* If the window system or terminal screen hasn't been initialized
603 yet, or we're not interactive, it's best to dump this message out
604 to stderr and exit. */
605 if (! SCREEN_MESSAGE_BUF (selected_screen
)
607 stream
= Qexternal_debugging_output
;
615 errname
= Fcar (data
);
617 if (EQ (errname
, Qerror
))
620 if (!CONSP (data
)) data
= Qnil
;
621 errmsg
= Fcar (data
);
626 errmsg
= Fget (errname
, Qerror_message
);
627 file_error
= Fmemq (Qfile_error
,
628 Fget (errname
, Qerror_conditions
));
631 /* Print an error message including the data items.
632 This is done by printing it into a scratch buffer
633 and then making a copy of the text in the buffer. */
635 if (!CONSP (data
)) data
= Qnil
;
639 /* For file-error, make error message by concatenating
640 all the data items. They are all strings. */
641 if (!NILP (file_error
) && !NILP (tail
))
642 errmsg
= XCONS (tail
)->car
, tail
= XCONS (tail
)->cdr
;
644 if (XTYPE (errmsg
) == Lisp_String
)
645 Fprinc (errmsg
, stream
);
647 write_string_1 ("peculiar error", -1, stream
);
649 for (i
= 0; CONSP (tail
); tail
= Fcdr (tail
), i
++)
651 write_string_1 (i
? ", " : ": ", 2, stream
);
652 if (!NILP (file_error
))
653 Fprinc (Fcar (tail
), stream
);
655 Fprin1 (Fcar (tail
), stream
);
659 /* If the window system or terminal screen hasn't been initialized
660 yet, or we're in -batch mode, this error should cause Emacs to exit. */
661 if (! SCREEN_MESSAGE_BUF (selected_screen
)
665 Fkill_emacs (make_number (-1));
670 Vinhibit_quit
= Qnil
;
671 return make_number (0);
674 Lisp_Object
command_loop_1 ();
675 Lisp_Object
command_loop_2 ();
676 Lisp_Object
top_level_1 ();
678 /* Entry to editor-command-loop.
679 This level has the catches for exiting/returning to editor command loop.
680 It returns nil to exit recursive edit, t to abort it. */
685 if (command_loop_level
> 0 || minibuf_level
> 0)
687 return internal_catch (Qexit
, command_loop_2
, Qnil
);
692 internal_catch (Qtop_level
, top_level_1
, Qnil
);
693 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
695 /* End of file in -batch run causes exit here. */
701 /* Here we catch errors in execution of commands within the
702 editing loop, and reenter the editing loop.
703 When there is an error, cmd_error runs and returns a non-nil
704 value to us. A value of nil means that cmd_loop_1 itself
705 returned due to end of file (or end of kbd macro). */
710 register Lisp_Object val
;
713 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
722 return Feval (Vtop_level
);
728 /* On entry to the outer level, run the startup file */
729 if (!NILP (Vtop_level
))
730 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
731 else if (!NILP (Vpurify_flag
))
732 message ("Bare impure Emacs (standard Lisp code not loaded)");
734 message ("Bare Emacs (standard Lisp code not loaded)");
738 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
739 "Exit all recursive editing levels.")
742 Fthrow (Qtop_level
, Qnil
);
745 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
746 "Exit from the innermost recursive edit or minibuffer.")
749 if (command_loop_level
> 0 || minibuf_level
> 0)
750 Fthrow (Qexit
, Qnil
);
752 error ("No recursive edit is in progress");
755 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
756 "Abort the command that requested this recursive edit or minibuffer input.")
759 if (command_loop_level
> 0 || minibuf_level
> 0)
762 error ("No recursive edit is in progress");
765 /* This is the actual command reading loop,
766 sans error-handling encapsulation. */
768 Lisp_Object
Fcommand_execute ();
769 static int read_key_sequence ();
777 Lisp_Object keybuf
[30];
783 waiting_for_input
= 0;
786 /* Don't clear out last_command at the beginning of a macro. */
787 if (XTYPE (Vexecuting_macro
) != Lisp_String
)
792 this_command_key_count
= 0;
796 /* Install chars successfully executed in kbd macro. */
798 if (defining_kbd_macro
&& NILP (Vprefix_arg
))
799 finalize_kbd_macro_chars ();
801 /* Make sure the current window's buffer is selected. */
802 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
803 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
805 /* Display any malloc warning that just came out. Use while because
806 displaying one warning can cause another. */
808 while (pending_malloc_warning
)
809 display_malloc_warning ();
813 /* If minibuffer on and echo area in use,
814 wait 2 sec and redraw minibufer. */
816 if (minibuf_level
&& echo_area_glyphs
)
818 Fsit_for (make_number (2), Qnil
, Qnil
);
819 echo_area_glyphs
= 0;
821 if (!NILP (Vquit_flag
))
824 unread_command_char
= make_number (quit_char
);
829 alloca (0); /* Cause a garbage collection now */
830 /* Since we can free the most stuff here. */
831 #endif /* C_ALLOCA */
833 /* Read next key sequence; i gets its length. */
834 i
= read_key_sequence (keybuf
, (sizeof keybuf
/ sizeof (keybuf
[0])), 0);
839 /* Select the screen that the key sequence came from. */
840 if (XTYPE (Vlast_event_screen
) == Lisp_Screen
841 && XSCREEN (Vlast_event_screen
) != selected_screen
)
842 Fselect_screen (Vlast_event_screen
, Qnil
);
845 /* Now we have read a key sequence of length I,
846 or else I is 0 and we found end of file. */
848 if (i
== 0) /* End of file -- happens only in */
849 return Qnil
; /* a kbd macro, at the end. */
852 #ifdef HAVE_X_WINDOWS
853 if (SCREEN_IS_X (selected_screen
))
855 if (i
== -1) /* Mouse event */
858 if (NILP (Vprefix_arg
) && NILP (Vexecuting_macro
) &&
859 !EQ (minibuf_window
, selected_window
))
862 if (defining_kbd_macro
)
864 /* Be nice if this worked... */
866 Fexecute_mouse_event (read_key_sequence_cmd
);
871 if (i
== -2) /* Lisp Symbol */
874 if (NILP (Vprefix_arg
) && NILP (Vexecuting_macro
) &&
875 !EQ (minibuf_window
, selected_window
))
881 #endif /* HAVE_X_WINDOWS */
884 last_command_char
= keybuf
[i
- 1];
886 cmd
= read_key_sequence_cmd
;
887 if (!NILP (Vexecuting_macro
))
889 if (!NILP (Vquit_flag
))
891 Vexecuting_macro
= Qt
;
892 QUIT
; /* Make some noise. */
893 /* Will return since macro now empty. */
897 /* Do redisplay processing after this command except in special
898 cases identified below that set no_redisplay to 1. */
901 /* Execute the command. */
905 /* nil means key is undefined. */
907 defining_kbd_macro
= 0;
908 update_mode_lines
= 1;
914 if (NILP (Vprefix_arg
) && ! no_direct
)
916 /* Recognize some common commands in common situations and
918 if (EQ (cmd
, Qforward_char
) && point
< ZV
)
920 struct Lisp_Vector
*dp
921 = window_display_table (XWINDOW (selected_window
));
922 lose
= FETCH_CHAR (point
);
924 if (((dp
== 0 && lose
>= 040 && lose
< 0177)
926 (dp
&& (XTYPE (dp
->contents
[lose
]) != Lisp_String
927 || XSTRING (dp
->contents
[lose
])->size
== sizeof (GLYPH
))))
928 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
930 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
932 && !windows_or_buffers_changed
933 && EQ (current_buffer
->selective_display
, Qnil
)
934 && !detect_input_pending ()
935 && NILP (Vexecuting_macro
))
936 no_redisplay
= direct_output_forward_char (1);
939 else if (EQ (cmd
, Qbackward_char
) && point
> BEGV
)
941 struct Lisp_Vector
*dp
942 = window_display_table (XWINDOW (selected_window
));
944 lose
= FETCH_CHAR (point
);
945 if (((dp
== 0 && lose
>= 040 && lose
< 0177)
947 (dp
&& (XTYPE (dp
->contents
[lose
]) != Lisp_String
948 || XSTRING (dp
->contents
[lose
])->size
== sizeof (GLYPH
))))
949 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
951 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
953 && !windows_or_buffers_changed
954 && EQ (current_buffer
->selective_display
, Qnil
)
955 && !detect_input_pending ()
956 && NILP (Vexecuting_macro
))
957 no_redisplay
= direct_output_forward_char (-1);
960 else if (EQ (cmd
, Qself_insert_command
)
961 /* Try this optimization only on ascii keystrokes. */
962 && XTYPE (last_command_char
) == Lisp_Int
)
964 unsigned char c
= XINT (last_command_char
);
966 if (NILP (Vexecuting_macro
) &&
967 !EQ (minibuf_window
, selected_window
))
969 if (!nonundocount
|| nonundocount
>= 20)
976 lose
= (XFASTINT (XWINDOW (selected_window
)->last_modified
)
978 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
980 || MODIFF
<= current_buffer
->save_modified
981 || windows_or_buffers_changed
982 || !EQ (current_buffer
->selective_display
, Qnil
)
983 || detect_input_pending ()
984 || !NILP (Vexecuting_macro
);
985 if (internal_self_insert (c
, 0))
991 (point
== ZV
|| FETCH_CHAR (point
) == '\n'))
993 struct Lisp_Vector
*dp
994 = window_display_table (XWINDOW (selected_window
));
996 if (dp
== 0 || XTYPE (dp
->contents
[c
]) != Lisp_String
)
997 no_redisplay
= direct_output_for_insert (c
);
998 else if (XSTRING (dp
->contents
[c
])->size
1001 direct_output_for_insert (*(GLYPH
*)XSTRING (dp
->contents
[c
])->data
);
1007 /* Here for a command that isn't executed directly */
1010 if (NILP (Vprefix_arg
))
1012 Fcommand_execute (cmd
, Qnil
);
1017 /* If there is a prefix argument,
1018 1) We don't want last_command to be ``universal-argument''
1019 (that would be dumb), so don't set last_command,
1020 2) we want to leave echoing on so that the prefix will be
1021 echoed as part of this key sequence, so don't call
1023 3) we want to leave this_command_key_count non-zero, so that
1024 read_char will realize that it is re-reading a character, and
1025 not echo it a second time. */
1026 if (NILP (Vprefix_arg
))
1028 last_command
= this_command
;
1030 this_command_key_count
= 0;
1035 /* Number of seconds between polling for input. */
1038 /* Nonzero means polling for input is temporarily suppresed. */
1039 int poll_suppress_count
;
1041 #ifdef POLL_FOR_INPUT
1042 int polling_for_input
;
1044 /* Handle an alarm once each second and read pending input
1045 so as to handle a C-g if it comces in. */
1048 input_poll_signal ()
1050 #ifdef HAVE_X_WINDOWS
1051 extern int x_input_blocked
;
1052 if (x_input_blocked
== 0)
1054 if (!waiting_for_input
)
1055 read_avail_input (0);
1056 signal (SIGALRM
, input_poll_signal
);
1057 alarm (polling_period
);
1062 /* Begin signals to poll for input, if they are appropriate.
1063 This function is called unconditionally from various places. */
1067 #ifdef POLL_FOR_INPUT
1068 if (read_socket_hook
)
1070 poll_suppress_count
--;
1071 if (poll_suppress_count
== 0)
1073 signal (SIGALRM
, input_poll_signal
);
1074 polling_for_input
= 1;
1075 alarm (polling_period
);
1081 /* Turn off polling. */
1085 #ifdef POLL_FOR_INPUT
1086 if (read_socket_hook
)
1088 if (poll_suppress_count
== 0)
1090 polling_for_input
= 0;
1093 poll_suppress_count
++;
1098 /* Input of single characters from keyboard */
1100 Lisp_Object
print_help ();
1101 static Lisp_Object
kbd_buffer_get_event ();
1103 /* read a character from the keyboard; call the redisplay if needed */
1104 /* commandflag 0 means do not do auto-saving, but do do redisplay.
1105 -1 means do not do redisplay, but do do autosaving.
1109 read_char (commandflag
)
1112 register Lisp_Object c
;
1116 if (!NILP (unread_command_char
))
1118 c
= unread_command_char
;
1119 unread_command_char
= Qnil
;
1121 #if 0 /* We're not handling mouse keys specially anymore. */
1122 if (!EQ (XTYPE (obj
), Lisp_Int
)) /* Mouse thing */
1125 last_input_char
= 0;
1130 if (this_command_key_count
== 0)
1136 if (!NILP (Vexecuting_macro
))
1138 if (executing_macro_index
>= Flength (Vexecuting_macro
))
1140 XSET (c
, Lisp_Int
, -1);
1144 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
1145 executing_macro_index
++;
1150 /* Save outer setjmp data, in case called recursively. */
1151 save_getcjmp (save_jump
);
1155 if (commandflag
>= 0 && !input_pending
&& !detect_input_pending ())
1158 if (_setjmp (getcjmp
))
1160 XSET (c
, Lisp_Int
, quit_char
);
1162 XSET (Vlast_event_screen
, Lisp_Screen
, selected_screen
);
1168 /* Message turns off echoing unless more keystrokes turn it on again. */
1169 if (echo_area_glyphs
&& *echo_area_glyphs
&& echo_area_glyphs
!= echobuf
)
1172 /* If already echoing, continue. */
1175 /* If in middle of key sequence and minibuffer not active,
1176 start echoing if enough time elapses. */
1177 if (minibuf_level
== 0 && !immediate_echo
&& this_command_key_count
> 0
1178 && echo_keystrokes
> 0
1179 && (echo_area_glyphs
== 0 || *echo_area_glyphs
== 0))
1183 tem0
= sit_for (echo_keystrokes
, 0, 1, 1);
1188 /* Maybe auto save due to number of keystrokes or idle time. */
1190 if (commandflag
!= 0
1191 && auto_save_interval
> 0
1192 && num_input_chars
- last_auto_save
> max (auto_save_interval
, 20)
1193 && !detect_input_pending ())
1196 save_getcjmp (temp
);
1197 Fdo_auto_save (Qnil
, Qnil
);
1198 restore_getcjmp (temp
);
1201 /* Slow down auto saves logarithmically in size of current buffer,
1202 and garbage collect while we're at it. */
1204 int delay_level
, buffer_size
;
1206 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
1207 last_non_minibuf_size
= Z
- BEG
;
1208 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
1210 while (buffer_size
> 64)
1211 delay_level
++, buffer_size
-= buffer_size
>> 2;
1212 if (delay_level
< 4) delay_level
= 4;
1213 /* delay_level is 4 for files under around 50k, 7 at 100k,
1214 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
1216 /* Auto save if enough time goes by without input. */
1217 if (commandflag
!= 0
1218 && num_input_chars
> last_auto_save
1219 && XTYPE (Vauto_save_timeout
) == Lisp_Int
1220 && XINT (Vauto_save_timeout
) > 0)
1223 int delay
= delay_level
* XFASTINT (Vauto_save_timeout
) / 4;
1224 tem0
= sit_for (delay
, 0, 1, 1);
1228 save_getcjmp (temp
);
1229 Fdo_auto_save (Qnil
, Qnil
);
1230 restore_getcjmp (temp
);
1232 /* If we have auto-saved and there is still no input
1233 available, garbage collect if there has been enough
1234 consing going on to make it worthwhile. */
1235 if (!detect_input_pending ()
1236 && consing_since_gc
> gc_cons_threshold
/ 2)
1237 Fgarbage_collect ();
1242 /* Actually read a character, waiting if necessary. */
1243 c
= kbd_buffer_get_event ();
1246 abort (); /* Don't think this can happen. */
1248 #if 0 /* I think that all the different kinds of events should be
1249 handled together now... */
1250 if (XTYPE (c
) != Lisp_Int
)
1258 /* Terminate Emacs in batch mode if at eof. */
1259 if (noninteractive
&& c
< 0)
1260 Fkill_emacs (make_number (1));
1264 restore_getcjmp (save_jump
);
1268 echo_area_glyphs
= 0;
1270 /* Handle things that only apply to characters. */
1271 if (XTYPE (c
) == Lisp_Int
)
1273 /* If kbd_buffer_get_event gave us an EOF, return that. */
1277 /* Strip the high bits, and maybe the meta bit too. */
1278 XSETINT (c
, c
& (meta_key
? 0377 : 0177));
1280 if (XTYPE (Vkeyboard_translate_table
) == Lisp_String
1281 && XSTRING (Vkeyboard_translate_table
)->size
> XINT (c
))
1282 XSETINT (c
, XSTRING (Vkeyboard_translate_table
)->data
[c
]);
1286 recent_keys
[recent_keys_index
] = c
;
1287 if (++recent_keys_index
>= (sizeof (recent_keys
)/sizeof(recent_keys
[0])))
1288 recent_keys_index
= 0;
1290 /* Write c to the dribble file. If c is a lispy event, write
1291 the event's symbol to the dribble file, in <brackets>. Bleaugh.
1292 If you, dear reader, have a better idea, you've got the source. :-) */
1295 if (XTYPE (c
) == Lisp_Int
)
1299 Lisp_Object dribblee
= c
;
1301 /* If it's a structured event, take the event header. */
1302 if (EVENT_HAS_PARAMETERS (dribblee
))
1303 dribblee
= EVENT_HEAD (dribblee
);
1305 if (XTYPE (c
) == Lisp_Symbol
)
1307 putc ('<', dribble
);
1308 fwrite (XSYMBOL (c
)->name
->data
, sizeof (char),
1309 XSYMBOL (c
)->name
->size
,
1311 putc ('>', dribble
);
1318 store_kbd_macro_char (c
);
1324 /* Record this character as part of the current key. */
1325 add_command_key (c
);
1327 /* Re-reading in the middle of a command */
1329 last_input_char
= c
;
1332 /* Process the help character specially if enabled */
1333 if (EQ (c
, help_char
) && !NILP (Vhelp_form
))
1336 count
= specpdl_ptr
- specpdl
;
1338 record_unwind_protect (Fset_window_configuration
,
1339 Fcurrent_window_configuration (Qnil
));
1341 tem0
= Feval (Vhelp_form
);
1342 if (XTYPE (tem0
) == Lisp_String
)
1343 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
1347 /* Remove the help from the screen */
1348 unbind_to (count
, Qnil
);
1350 if (EQ (c
, make_number (040)))
1364 Fprinc (object
, Qnil
);
1368 /* Copy out or in the info on where C-g should throw to.
1369 This is used when running Lisp code from within get_char,
1370 in case get_char is called recursively.
1371 See read_process_output. */
1376 bcopy (getcjmp
, temp
, sizeof getcjmp
);
1379 restore_getcjmp (temp
)
1382 bcopy (temp
, getcjmp
, sizeof getcjmp
);
1386 /* Low level keyboard/mouse input.
1387 kbd_buffer_store_event places events in kbd_buffer, and
1388 kbd_buffer_get_event retrieves them.
1389 mouse_moved indicates when the mouse has moved again, and
1390 *mouse_position_hook provides the mouse position. */
1392 /* Set this for debugging, to have a way to get out */
1395 extern int screen_garbaged
;
1397 /* Return true iff there are any events in the queue that read-char
1398 would return. If this returns false, a read-char would block. */
1402 struct input_event
*ep
;
1404 if (EVENT_QUEUES_EMPTY
)
1407 if (do_mouse_tracking
)
1410 /* Mouse tracking is disabled, so we need to actually scan the
1411 input queue to see if any events are currently readable. */
1412 for (ep
= kbd_fetch_ptr
; ep
!= kbd_store_ptr
; ep
++)
1414 if (ep
== kbd_buffer
+ KBD_BUFFER_SIZE
)
1417 /* Skip button-up events. */
1418 if ((ep
->kind
== mouse_click
|| ep
->kind
== scrollbar_click
)
1419 && (ep
->modifiers
& up_modifier
))
1429 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
1430 of this function. */
1432 tracking_off (old_value
)
1433 Lisp_Object old_value
;
1435 if (! XFASTINT (old_value
))
1437 do_mouse_tracking
= 0;
1439 /* Redisplay may have been preempted because there was input
1440 available, and it assumes it will be called again after the
1441 input has been processed. If the only input available was
1442 the sort that we have just disabled, then we need to call
1444 if (!readable_events ())
1446 redisplay_preserve_echo_area ();
1447 get_input_pending (&input_pending
);
1452 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
1453 "Evaluate BODY with mouse movement and button release events enabled.\n\
1454 Within a `track-mouse', mouse motion and button releases generate input\n\
1455 events that you can read with `read-event'.\n\
1456 Normally, these occurrences don't generate events.")
1460 int count
= specpdl_ptr
- specpdl
;
1463 XSET (val
, Lisp_Int
, do_mouse_tracking
);
1464 record_unwind_protect (tracking_off
, val
);
1466 do_mouse_tracking
= 1;
1468 val
= Fprogn (args
);
1469 return unbind_to (count
, val
);
1472 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
1475 kbd_buffer_store_event (event
)
1476 register struct input_event
*event
;
1478 if (event
->kind
== no_event
)
1481 if (event
->kind
== ascii_keystroke
)
1483 register int c
= XFASTINT (event
->code
) & 0377;
1486 || ((c
== (0200 | quit_char
)) && !meta_key
))
1488 /* If this results in a quit_char being returned to Emacs as
1489 input, set last-event-screen properly. If this doesn't
1490 get returned to Emacs as an event, the next event read
1491 will set Vlast_event_screen again, so this is safe to do. */
1492 extern SIGTYPE
interrupt_signal ();
1493 XSET (Vlast_event_screen
, Lisp_Screen
, event
->screen
);
1494 last_event_timestamp
= event
->timestamp
;
1495 interrupt_signal ();
1499 if (c
&& c
== stop_character
)
1505 XSET (event
->code
, Lisp_Int
, c
);
1508 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
1509 kbd_store_ptr
= kbd_buffer
;
1511 /* Don't let the very last slot in the buffer become full,
1512 since that would make the two pointers equal,
1513 and that is indistinguishable from an empty buffer.
1514 Discard the event if it would fill the last slot. */
1515 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
1517 kbd_store_ptr
->kind
= event
->kind
;
1518 kbd_store_ptr
->code
= event
->code
;
1519 kbd_store_ptr
->part
= event
->part
;
1520 kbd_store_ptr
->screen
= event
->screen
;
1521 kbd_store_ptr
->modifiers
= event
->modifiers
;
1522 kbd_store_ptr
->x
= event
->x
;
1523 kbd_store_ptr
->y
= event
->y
;
1524 kbd_store_ptr
->timestamp
= event
->timestamp
;
1530 static Lisp_Object
make_lispy_event ();
1531 static Lisp_Object
make_lispy_movement ();
1532 static Lisp_Object
modify_event_symbol ();
1535 kbd_buffer_get_event ()
1543 XSET (obj
, Lisp_Int
, c
);
1547 /* Wait until there is input available. */
1551 /* Process or toss any events that we don't want to return as
1552 input. The fact that we remove undesirable events here
1553 allows us to use EVENT_QUEUES_EMPTY in the rest of this loop. */
1554 if (! do_mouse_tracking
)
1555 while (kbd_fetch_ptr
!= kbd_store_ptr
)
1557 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
1558 kbd_fetch_ptr
= kbd_buffer
;
1560 if (kbd_fetch_ptr
->kind
== mouse_click
1561 || kbd_fetch_ptr
->kind
== scrollbar_click
)
1563 if ((kbd_fetch_ptr
->modifiers
& up_modifier
) == 0)
1572 if (!EVENT_QUEUES_EMPTY
)
1575 /* If the quit flag is set, then read_char will return
1576 quit_char, so that counts as "available input." */
1577 if (!NILP (Vquit_flag
))
1578 quit_throw_to_read_char ();
1580 /* One way or another, wait until input is available; then, if
1581 interrupt handlers have not read it, read it now. */
1584 wait_for_kbd_input ();
1586 /* Note SIGIO has been undef'd if FIONREAD is missing. */
1590 if (EVENT_QUEUES_EMPTY
)
1592 Lisp_Object minus_one
;
1594 XSET (minus_one
, Lisp_Int
, -1);
1595 wait_reading_process_input (0, 0, minus_one
, 1);
1597 if (!interrupt_input
&& EVENT_QUEUES_EMPTY
)
1599 read_avail_input (0);
1602 #endif /* not VMS */
1605 /* At this point, we know that there is a readable event available
1606 somewhere. If the event queue is empty, then there must be a
1607 mouse movement enabled and available. */
1608 if (kbd_fetch_ptr
!= kbd_store_ptr
)
1610 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
1611 kbd_fetch_ptr
= kbd_buffer
;
1612 XSET (Vlast_event_screen
, Lisp_Screen
, kbd_fetch_ptr
->screen
);
1613 last_event_timestamp
= XINT (kbd_fetch_ptr
->timestamp
);
1614 obj
= make_lispy_event (kbd_fetch_ptr
);
1615 kbd_fetch_ptr
->kind
= no_event
;
1617 if (XTYPE (obj
) == Lisp_Int
)
1618 XSET (obj
, Lisp_Int
, XINT (obj
) & (meta_key
? 0377 : 0177));
1620 else if (do_mouse_tracking
&& mouse_moved
)
1623 Lisp_Object x
, y
, time
;
1625 (*mouse_position_hook
) (&screen
, &x
, &y
, &time
);
1626 XSET (Vlast_event_screen
, Lisp_Screen
, screen
);
1628 obj
= make_lispy_movement (screen
, x
, y
, time
);
1631 /* We were promised by the above while loop that there was
1632 something for us to read! */
1635 input_pending
= readable_events ();
1640 /* Caches for modify_event_symbol. */
1641 static Lisp_Object func_key_syms
;
1642 static Lisp_Object mouse_syms
;
1644 /* You'll notice that this table is arranged to be conveniently
1645 indexed by X Windows keysym values. */
1646 static char *lispy_function_keys
[] =
1648 /* X Keysym value */
1650 "home", /* 0xff50 */ /* IsCursorKey */
1661 "select", /* 0xff60 */ /* IsMiscFunctionKey */
1672 "break", /* 0xff6b */
1674 /* Here are some keys found mostly on HP keyboards. The X event
1675 handling code will strip bit 29, which flags vendor-specific
1677 "reset", /* 0x1000ff6c */
1686 "kp_backtab", /* 0x1000ff75 */
1688 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff7f */
1689 "kp-space", /* 0xff80 */ /* IsKeypadKey */
1690 0, 0, 0, 0, 0, 0, 0, 0,
1691 "kp-tab", /* 0xff89 */
1693 "kp-enter", /* 0xff8d */
1695 "kp-f1", /* 0xff91 */
1700 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1701 "kp-multiply", /* 0xffaa */
1706 "kp-divide", /* 0xffaf */
1707 "kp-0", /* 0xffb0 */
1708 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
1711 "kp-equal", /* 0xffbd */
1712 "f1", /* 0xffbe */ /* IsFunctionKey */
1714 "f5", "f6", "f7", "f8", "f9", "f10", "f11", "f12",
1715 "f13", "f14", "f15", "f16", "f17", "f18", "f19", "f20",
1716 "f21", "f22", "f23", "f24", "f25", "f26", "f27", "f28",
1717 "f29", "f30", "f31", "f32", "f33", "f34", "f35" /* 0xffe0 */
1720 static char *lispy_mouse_names
[] =
1722 "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5"
1725 /* Given a struct input_event, build the lisp event which represents
1726 it. If EVENT is 0, build a mouse movement event from the mouse
1727 movement buffer, which should have a movement event in it. */
1730 make_lispy_event (event
)
1731 struct input_event
*event
;
1733 #ifdef SWITCH_ENUM_BUG
1734 switch ((int) event
->kind
)
1736 switch (event
->kind
)
1740 /* A simple keystroke. */
1741 case ascii_keystroke
:
1745 /* A function key. The symbol may need to have modifier prefixes
1747 case non_ascii_keystroke
:
1748 return modify_event_symbol (XFASTINT (event
->code
), event
->modifiers
,
1750 lispy_function_keys
, &func_key_syms
,
1751 (sizeof (lispy_function_keys
)
1752 / sizeof (lispy_function_keys
[0])));
1755 /* A mouse click - build a list of the relevant information. */
1759 Lisp_Object window
=
1760 window_from_coordinates (event
->screen
,
1761 XINT (event
->x
), XINT (event
->y
),
1765 if (XTYPE (window
) != Lisp_Window
)
1769 XSETINT (event
->x
, (XINT (event
->x
)
1770 - XINT (XWINDOW (window
)->left
)));
1771 XSETINT (event
->y
, (XINT (event
->y
)
1772 - XINT (XWINDOW (window
)->top
)));
1777 posn
= Qvertical_split
;
1779 XSET (posn
, Lisp_Int
,
1780 buffer_posn_from_coords (XWINDOW (window
),
1785 return Fcons (modify_event_symbol (XFASTINT (event
->code
) - 1,
1788 lispy_mouse_names
, &mouse_syms
,
1789 (sizeof (lispy_mouse_names
)
1790 / sizeof (lispy_mouse_names
[0]))),
1793 Fcons (Fcons (event
->x
, event
->y
),
1794 Fcons (event
->timestamp
,
1798 /* A scrollbar click. Build a list containing the relevant
1800 case scrollbar_click
:
1803 = modify_event_symbol (XFASTINT (event
->code
) - 1,
1806 lispy_mouse_names
, &mouse_syms
,
1807 (sizeof (lispy_mouse_names
)
1808 / sizeof (lispy_mouse_names
[0])));
1809 return Fcons (event
->part
,
1810 Fcons (SCREEN_SELECTED_WINDOW (event
->screen
),
1812 Fcons (Fcons (event
->x
, event
->y
),
1813 Fcons (event
->timestamp
,
1817 /* The 'kind' field of the event is something we don't recognize. */
1824 make_lispy_movement (screen
, x
, y
, time
)
1837 ? window_from_coordinates (screen
, ix
, iy
, &part
)
1839 if (XTYPE (window
) != Lisp_Window
)
1843 ix
-= XINT (XWINDOW (window
)->left
);
1844 iy
-= XINT (XWINDOW (window
)->top
);
1848 posn
= Qvertical_split
;
1850 XSET (posn
, Lisp_Int
, buffer_posn_from_coords (XWINDOW (window
),
1856 return Fcons (Qmouse_movement
,
1859 Fcons (Fcons (x
, y
),
1860 Fcons (time
, Qnil
)))));
1865 /* Place the written representation of MODIFIERS in BUF, '\0'-terminated,
1866 and return its length. */
1869 format_modifiers (modifiers
, buf
)
1875 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
1876 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
1877 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
1878 if (modifiers
& up_modifier
) { *p
++ = 'U'; *p
++ = '-'; }
1885 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
1886 return a symbol with the modifiers placed in the canonical order.
1888 Fdefine_key calls this to make sure that (for example) C-M-foo
1889 and M-C-foo end up being equivalent in the keymap. */
1892 reorder_modifiers (symbol
)
1895 struct Lisp_String
*name
;
1900 CHECK_SYMBOL (symbol
, 1);
1903 name
= XSYMBOL (symbol
)->name
;
1905 /* Special case for things with only one modifier, which is
1906 (hopefully) the vast majority of cases. */
1907 if (! (name
->size
>= 4 && name
->data
[1] == '-' && name
->data
[3] == '-'))
1910 for (i
= 0; i
+ 1 < name
->size
&& name
->data
[i
+ 1] == '-'; i
+= 2)
1911 switch (name
->data
[i
])
1914 not_canonical
|= (modifiers
& (meta_modifier
|ctrl_modifier
1915 |shift_modifier
|up_modifier
));
1916 modifiers
|= meta_modifier
;
1920 not_canonical
|= (modifiers
&
1921 (ctrl_modifier
|shift_modifier
|up_modifier
));
1922 modifiers
|= ctrl_modifier
;
1926 not_canonical
|= (modifiers
& (shift_modifier
|up_modifier
));
1927 modifiers
|= shift_modifier
;
1931 not_canonical
|= (modifiers
& (up_modifier
));
1932 modifiers
|= up_modifier
;
1936 goto no_more_modifiers
;
1943 /* The modifiers were out of order, so find a new symbol with the
1944 mods in order. Since the symbol name could contain nulls, we can't
1945 use intern here; we have to use Fintern, which expects a genuine
1946 Lisp_String, and keeps a reference to it. */
1948 char *new_mods
= (char *) alloca (sizeof ("C-M-S-U-"));
1949 int len
= format_modifiers (modifiers
, new_mods
);
1950 Lisp_Object new_name
= make_uninit_string (len
+ name
->size
- i
);
1952 bcopy (new_mods
, XSTRING (new_name
)->data
, len
);
1953 bcopy (name
->data
+ i
, XSTRING (new_name
)->data
+ len
, name
->size
- i
);
1955 return Fintern (new_name
, Qnil
);
1960 /* For handling events, we often want to produce a symbol whose name
1961 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
1962 to some base, like the name of a function key or mouse button.
1963 modify_event_symbol produces symbols of this sort.
1965 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
1966 is the name of the i'th symbol. TABLE_SIZE is the number of elements
1969 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
1970 persist between calls to modify_event_symbol that it can use to
1971 store a cache of the symbols it's generated for this NAME_TABLE
1974 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
1976 MODIFIERS is a set of modifier bits (as given in struct input_events)
1977 whose prefixes should be applied to the symbol name.
1979 SYMBOL_KIND is the value to be placed in the event_kind property of
1980 the returned symbol. */
1983 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_table
,
1984 symbol_table
, table_size
)
1987 Lisp_Object symbol_kind
;
1989 Lisp_Object
*symbol_table
;
1992 Lisp_Object
*slot
, *unmodified_slot
;
1994 /* Is this a request for a valid symbol? */
1995 if (symbol_num
< 0 || symbol_num
>= table_size
1996 || modifiers
>= NUM_MODIFIER_COMBOS
)
1999 /* If *symbol_table is not a vector of the appropriate size,
2001 if (XTYPE (*symbol_table
) != Lisp_Vector
2002 || XVECTOR (*symbol_table
)->size
!= table_size
)
2003 *symbol_table
= Fmake_vector (make_number (table_size
), Qnil
);
2005 unmodified_slot
= slot
= & XVECTOR (*symbol_table
)->contents
[symbol_num
];
2007 /* If there are modifier keys, there had better be a vector in
2008 this symbol's position of the symbol_table. */
2011 Lisp_Object slot_contents
= *slot
;
2013 /* If there isn't the right sort of vector there, put one in. */
2014 if (XTYPE (slot_contents
) != Lisp_Vector
2015 || XVECTOR (slot_contents
)->size
!= NUM_MODIFIER_COMBOS
)
2017 *slot
= Fmake_vector (make_number (NUM_MODIFIER_COMBOS
), Qnil
);
2019 /* Make sure that the vector has an entry for the unmodified
2020 symbol, so we can put it on the event_unmodified property. */
2021 if (! NILP (slot_contents
))
2022 XVECTOR (*slot
)->contents
[0] = slot_contents
;
2024 XVECTOR (*slot
)->contents
[0] = intern (name_table
[symbol_num
]);
2028 /* If this entry has been filled in with a modified symbol vector,
2029 point to the appropriate slot within that. */
2030 if (XTYPE (*slot
) == Lisp_Vector
)
2032 unmodified_slot
= & XVECTOR (*slot
)->contents
[0];
2033 slot
= & XVECTOR (*slot
)->contents
[modifiers
];
2036 /* Make sure we have an unmodified version of the symbol in its
2038 if (NILP (*unmodified_slot
))
2040 *unmodified_slot
= intern (name_table
[symbol_num
]);
2041 Fput (*unmodified_slot
, Qevent_kind
, symbol_kind
);
2042 Fput (*unmodified_slot
, Qevent_unmodified
, *unmodified_slot
);
2045 /* Have we already created a symbol for this combination of modifiers? */
2048 /* No, let's create one. */
2050 = (char *) alloca (sizeof ("C-M-S-U-")
2051 + strlen (name_table
[symbol_num
]));
2053 strcpy (modified_name
+ format_modifiers (modifiers
, modified_name
),
2054 name_table
[symbol_num
]);
2056 *slot
= intern (modified_name
);
2057 Fput (*slot
, Qevent_kind
, symbol_kind
);
2058 Fput (*slot
, Qevent_unmodified
, *unmodified_slot
);
2064 DEFUN ("mouse-click-p", Fmouse_click_p
, Smouse_click_p
, 1, 1, 0,
2065 "Return non-nil iff OBJECT is a representation of a mouse event.\n\
2066 A mouse event is a list of five elements whose car is a symbol of the\n\
2067 form <MODIFIERS>mouse-<DIGIT>. I hope this is a temporary hack.")
2071 if (EVENT_HAS_PARAMETERS (object
)
2072 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (object
)),
2079 /* Store into *addr a value nonzero if terminal input chars are available.
2080 Serves the purpose of ioctl (0, FIONREAD, addr)
2081 but works even if FIONREAD does not exist.
2082 (In fact, this may actually read some input.) */
2085 get_input_pending (addr
)
2088 /* First of all, have we already counted some input? */
2089 *addr
= !NILP (Vquit_flag
) || readable_events ();
2091 /* If input is being read as it arrives, and we have none, there is none. */
2092 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
2095 /* Try to read some input and see how much we get. */
2097 *addr
= !NILP (Vquit_flag
) || readable_events ();
2100 /* Interface to read_avail_input, blocking SIGIO if necessary. */
2103 gobble_input (expected
)
2108 if (interrupt_input
)
2111 mask
= sigblockx (SIGIO
);
2112 read_avail_input (expected
);
2117 read_avail_input (expected
);
2123 /* Read any terminal input already buffered up by the system
2124 into the kbd_buffer, but do not wait.
2126 EXPECTED should be nonzero if the caller knows there is some input.
2128 Except on VMS, all input is read by this function.
2129 If interrupt_input is nonzero, this function MUST be called
2130 only when SIGIO is blocked.
2132 Returns the number of keyboard chars read, or -1 meaning
2133 this is a bad time to try to read input. */
2136 read_avail_input (expected
)
2139 struct input_event buf
[KBD_BUFFER_SIZE
];
2143 if (read_socket_hook
)
2144 /* No need for FIONREAD or fcntl; just say don't wait. */
2145 nread
= (*read_socket_hook
) (0, buf
, KBD_BUFFER_SIZE
, expected
, expected
);
2148 unsigned char cbuf
[KBD_BUFFER_SIZE
];
2151 /* Find out how much input is available. */
2152 if (ioctl (0, FIONREAD
, &nread
) < 0)
2153 /* Formerly simply reported no input, but that sometimes led to
2154 a failure of Emacs to terminate.
2155 SIGHUP seems appropriate if we can't reach the terminal. */
2156 kill (getpid (), SIGHUP
);
2159 if (nread
> sizeof cbuf
)
2160 nread
= sizeof cbuf
;
2161 #else /* no FIONREAD */
2163 /* Read some input if available, but don't wait. */
2164 nread
= sizeof cbuf
;
2165 fcntl (fileno (stdin
), F_SETFL
, O_NDELAY
);
2171 /* Now read; for one reason or another, this will not block. */
2174 nread
= read (fileno (stdin
), cbuf
, nread
);
2176 /* The kernel sometimes fails to deliver SIGHUP for ptys.
2177 This looks incorrect, but it isn't, because _BSD causes
2178 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
2179 and that causes a value other than 0 when there is no input. */
2183 /* Retry the read if it is interrupted. */
2185 || ! (errno
== EAGAIN
|| errno
== EFAULT
2195 fcntl (fileno (stdin
), F_SETFL
, 0);
2197 #endif /* no FIONREAD */
2198 for (i
= 0; i
< nread
; i
++)
2200 buf
[i
].kind
= ascii_keystroke
;
2201 XSET (buf
[i
].code
, Lisp_Int
, cbuf
[i
]);
2202 buf
[i
].screen
= selected_screen
;
2206 /* Scan the chars for C-g and store them in kbd_buffer. */
2207 for (i
= 0; i
< nread
; i
++)
2209 kbd_buffer_store_event (&buf
[i
]);
2210 /* Don't look at input that follows a C-g too closely.
2211 This reduces lossage due to autorepeat on C-g. */
2212 if (buf
[i
].kind
== ascii_keystroke
2213 && XINT(buf
[i
].code
) == quit_char
)
2219 #endif /* not VMS */
2221 #ifdef SIGIO /* for entire page */
2222 /* Note SIGIO has been undef'd if FIONREAD is missing. */
2224 input_available_signal (signo
)
2227 /* Must preserve main program's value of errno. */
2228 int old_errno
= errno
;
2230 extern int select_alarmed
;
2234 /* USG systems forget handlers when they are used;
2235 must reestablish each time */
2236 signal (signo
, input_available_signal
);
2243 if (input_available_clear_time
)
2244 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
2249 nread
= read_avail_input (1);
2250 /* -1 means it's not ok to read the input now.
2251 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
2252 0 means there was no keyboard input available. */
2257 select_alarmed
= 1; /* Force the select emulator back to life */
2268 /* Return the prompt-string of a sparse keymap.
2269 This is the first element which is a string.
2270 Return nil if there is none. */
2278 register Lisp_Object tem
;
2280 if (XTYPE (tem
) == Lisp_String
)
2287 static int echo_flag
;
2288 static int echo_now
;
2290 /* Read a character like read_char but optionally prompt based on maps
2293 The prompting is done based on the prompt-string of the map
2294 and the strings associated with various map elements. */
2297 read_char_menu_prompt (prompt
, local
, global
)
2299 Lisp_Object local
, global
;
2301 register Lisp_Object rest
, name
;
2304 int width
= SCREEN_WIDTH (selected_screen
) - 4;
2305 char *menu
= (char *) alloca (width
);
2307 /* Use local over global Menu maps */
2310 return read_char (!prompt
);
2312 /* We can't get prompt strings from dense keymaps. */
2314 && EQ (Fcar (local
), Qkeymap
)
2315 && !(CONSP (XCONS (local
)->cdr
)
2316 && XTYPE (XCONS (XCONS (local
)->cdr
)->car
) == Lisp_Vector
))
2318 else if (CONSP (global
)
2319 && EQ (Fcar (global
), Qkeymap
)
2320 && !(CONSP (XCONS (global
)->cdr
)
2321 && XTYPE (XCONS (XCONS (global
)->cdr
)->car
) == Lisp_Vector
))
2324 return read_char (!prompt
);
2326 /* Get the map's prompt string. */
2327 name
= map_prompt (hmap
);
2329 return read_char (!prompt
);
2331 /* Prompt string always starts with map's prompt, and a space. */
2332 strcpy (menu
, XSTRING (name
)->data
);
2333 nlength
= XSTRING (name
)->size
;
2334 menu
[nlength
++] = ' ';
2337 /* Start prompting at start of map. */
2338 rest
= hmap
; /* Current menu item */
2340 /* Present the documented bindings, a line at a time. */
2348 /* If reached end of map, start at beginning. */
2349 if (NILP (Fcdr (rest
))) rest
= hmap
;
2351 /* Loop over elements of map. */
2352 while (!NILP (rest
) && i
< width
)
2356 /* Look for conses whose cadrs are strings. */
2357 s
= Fcar_safe (Fcdr_safe (Fcar_safe (rest
)));
2358 if (XTYPE (s
) != Lisp_String
)
2359 /* Ignore all other elements. */
2361 /* If first such element, or enough room, add string to prompt. */
2362 else if (XSTRING (s
)->size
+ i
< width
2367 /* Punctuate between strings. */
2370 strcpy (menu
+ i
, ", ");
2375 /* Add as much of string as fits. */
2376 thiswidth
= XSTRING (s
)->size
;
2377 if (thiswidth
+ i
> width
)
2378 thiswidth
= width
- i
;
2379 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
2384 /* If some elts don't fit, show there are more. */
2385 strcpy (menu
+ i
, "...");
2389 /* Move past this element. */
2390 rest
= Fcdr_safe (rest
);
2393 /* Prompt with that and read response. */
2395 obj
= read_char (1);
2397 if (XTYPE (obj
) != Lisp_Int
)
2402 if (obj
!= menu_prompt_more_char
2403 && (XTYPE (menu_prompt_more_char
) != Lisp_Int
2404 || obj
!= make_number (Ctl (XINT (menu_prompt_more_char
)))))
2410 /* Reading key sequences. */
2412 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
2413 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
2414 keymap, or nil otherwise. Return the index of the first keymap in
2415 which KEY has any binding, or NMAPS if no map has a binding.
2417 If KEY is a meta ASCII character, treat it like meta-prefix-char
2418 followed by the corresponding non-meta character. Keymaps in
2419 CURRENT with non-prefix bindings for meta-prefix-char become nil in
2422 When KEY is not defined in any of the keymaps, if it is an upper
2423 case letter and there are bindings for the corresponding lower-case
2424 letter, return the bindings for the lower-case letter.
2426 NEXT may == CURRENT. */
2429 follow_key (key
, nmaps
, current
, defs
, next
)
2431 Lisp_Object
*current
, *defs
, *next
;
2434 int i
, first_binding
;
2436 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
2437 followed by the corresponding non-meta character. */
2438 if (XTYPE (key
) == Lisp_Int
2439 && XINT (key
) >= 0200)
2441 for (i
= 0; i
< nmaps
; i
++)
2442 if (! NILP (current
[i
]))
2444 next
[i
] = get_keyelt (access_keymap (current
[i
],
2447 /* Note that since we pass the resulting bindings through
2448 get_keymap_1, non-prefix bindings for meta-prefix-char
2450 next
[i
] = get_keymap_1 (next
[i
], 0);
2456 XSET (key
, Lisp_Int
, XFASTINT (key
) & 0177);
2459 first_binding
= nmaps
;
2460 for (i
= nmaps
- 1; i
>= 0; i
--)
2462 if (! NILP (current
[i
]))
2464 defs
[i
] = get_keyelt (access_keymap (current
[i
], key
));
2465 if (! NILP (defs
[i
]))
2472 /* When KEY is not defined in any of the keymaps, if it is an upper
2473 case letter and there are bindings for the corresponding
2474 lower-case letter, return the bindings for the lower-case letter. */
2475 if (first_binding
== nmaps
2476 && XTYPE (key
) == Lisp_Int
2477 && UPPERCASEP (XINT (key
)))
2479 XSETINT (key
, DOWNCASE (XINT (key
)));
2481 first_binding
= nmaps
;
2482 for (i
= nmaps
- 1; i
>= 0; i
--)
2484 if (! NILP (current
[i
]))
2486 defs
[i
] = get_keyelt (access_keymap (current
[i
], key
));
2487 if (! NILP (defs
[i
]))
2495 /* Given the set of bindings we've found, produce the next set of maps. */
2496 for (i
= 0; i
< nmaps
; i
++)
2497 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0);
2499 return first_binding
;
2502 /* Read a sequence of keys that ends with a non prefix character
2503 according to the keymaps in KEYMAPS[0..nmaps-1]. Keymaps appearing
2504 earlier in KEYMAPS take precidence over those appearing later.
2506 Store the sequence in KEYBUF, a buffer of size BUFSIZE. Prompt
2507 with PROMPT. Echo starting immediately unless `prompt' is 0.
2508 Return the length of the key sequence stored.
2510 If the user switches screens in the midst of a key sequence, we
2511 throw away any prefix we have read so far, and start afresh. For
2512 mouse clicks, we look up the click in the keymap of the buffer
2513 clicked on, throwing away any prefix if it is not the same buffer
2514 we used to be reading from. */
2517 read_key_sequence (keybuf
, bufsize
, prompt
)
2518 Lisp_Object
*keybuf
;
2522 /* How many keys there are in the current key sequence. */
2525 /* The buffer that the most recently read event was typed at. This
2526 helps us read mouse clicks according to the buffer clicked in,
2527 and notice when the mouse has moved from one screen to another. */
2528 struct buffer
*last_event_buffer
= current_buffer
;
2530 /* The length of the echo buffer when we started reading, and
2531 the length of this_command_keys when we started reading. */
2533 int keys_start
= this_command_key_count
;
2535 /* The number of keymaps we're scanning right now, and the number of
2536 keymaps we have allocated space for. */
2538 int nmaps_allocated
= 0;
2540 /* current[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
2541 in the current keymaps, or nil where it is not a prefix. */
2542 Lisp_Object
*current
;
2544 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
2545 the current keymaps. */
2548 /* The lowest i such that defs[i] is non-nil. */
2551 /* If mock_input > t, then KEYBUF[t] should be read as the next
2555 /* If the sequence is unbound in current[], keymap[fkey_start..fkey_end-1]
2556 is a prefix in Vfunction_key_map, and fkey_map is its binding.
2557 These might be > t, indicating that all function key scanning should
2558 hold off until t reaches them. */
2559 int fkey_start
= 0, fkey_end
= 0;
2560 Lisp_Object fkey_map
= Vfunction_key_map
;
2565 echo_prompt (prompt
);
2566 else if (cursor_in_echo_area
)
2567 /* This doesn't put in a dash if the echo buffer is empty, so
2568 you don't always see a dash hanging out in the minibuffer. */
2570 echo_start
= echo_length ();
2573 /* If there is no function key map, turn of function key scanning. */
2574 if (NILP (Fkeymapp (Vfunction_key_map
)))
2575 fkey_start
= fkey_end
= bufsize
+ 1;
2579 this_command_key_count
= keys_start
;
2584 nmaps
= current_minor_maps (0, &maps
) + 2;
2585 if (nmaps
> nmaps_allocated
)
2587 current
= (Lisp_Object
*) alloca (nmaps
* sizeof (current
[0]));
2588 defs
= (Lisp_Object
*) alloca (nmaps
* sizeof (defs
[0]));
2589 nmaps_allocated
= nmaps
;
2591 bcopy (maps
, current
, (nmaps
- 2) * sizeof (current
[0]));
2592 current
[nmaps
-2] = last_event_buffer
->keymap
;
2593 current
[nmaps
-1] = global_map
;
2596 /* Find an accurate initial value for first_binding. */
2597 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
2598 if (! NILP (current
[first_binding
]))
2601 while ((first_binding
< nmaps
&& ! NILP (current
[first_binding
]))
2602 || (first_binding
>= nmaps
&& fkey_start
< t
))
2607 error ("key sequence too long");
2609 /* Are we reading keys stuffed into keybuf? */
2613 add_command_key (key
);
2616 /* Otherwise, we should actually read a character. */
2621 if (!prompt
&& INTERACTIVE
)
2622 key
= read_char_menu_prompt (prompt
, Qnil
, Qnil
);
2624 key
= read_char (!prompt
);
2626 /* The above routines return -1 at the end of a macro.
2627 Emacs 18 handles this by returning immediately with a
2628 zero, so that's what we'll do. */
2629 if (XTYPE (key
) == Lisp_Int
&& XINT (key
) < 0)
2634 /* What buffer was this event typed/moused at? */
2635 if (XTYPE (key
) == Lisp_Int
|| XTYPE (key
) == Lisp_Symbol
)
2638 (SCREEN_SELECTED_WINDOW
2639 (XSCREEN (Vlast_event_screen
)))->buffer
));
2640 else if (EVENT_HAS_PARAMETERS (key
))
2642 Lisp_Object window
= EVENT_WINDOW (key
);
2647 buf
= XBUFFER (XWINDOW (window
)->buffer
);
2652 /* If this event came to a different buffer than the one
2653 we're currently in, switch buffers and start a new key
2654 sequence, starting with key. */
2655 if (buf
!= last_event_buffer
)
2657 last_event_buffer
= buf
;
2658 Fselect_screen (Vlast_event_screen
, Qnil
);
2660 /* Arrange to read key as the next event. */
2664 /* Truncate the key sequence in the echo area. */
2666 echo_truncate (echo_start
);
2672 first_binding
= (follow_key (key
,
2673 nmaps
- first_binding
,
2674 current
+ first_binding
,
2675 defs
+ first_binding
,
2676 current
+ first_binding
)
2680 /* If the sequence is unbound, see if we can hang a function key
2681 off the end of it. Don't reread the expansion of a function key. */
2682 if (first_binding
>= nmaps
2685 Lisp_Object fkey_next
;
2687 /* Scan from fkey_end until we find a bound suffix. */
2688 while (fkey_end
< t
)
2691 get_keyelt (access_keymap (fkey_map
, keybuf
[fkey_end
++]));
2692 /* If keybuf[fkey_start..fkey_next] is bound in the
2693 function key map and it's a suffix of the current
2694 sequence (i.e. fkey_next == t), replace it with
2695 the binding and restart with fkey_start at the end. */
2696 if (XTYPE (fkey_next
) == Lisp_Vector
2699 t
= fkey_start
+ XVECTOR (fkey_next
)->size
;
2701 error ("key sequence too long");
2703 bcopy (XVECTOR (fkey_next
)->contents
,
2704 keybuf
+ fkey_start
,
2705 (t
- fkey_start
) * sizeof (keybuf
[0]));
2708 fkey_start
= fkey_end
= t
;
2710 /* Truncate the key sequence in the echo area. */
2712 echo_truncate (echo_start
);
2717 fkey_map
= get_keymap_1 (fkey_next
, 0);
2719 /* If we no longer have a bound suffix, try a new positions for
2721 if (NILP (fkey_map
))
2723 fkey_end
= ++fkey_start
;
2724 fkey_map
= Vfunction_key_map
;
2730 read_key_sequence_cmd
= (first_binding
< nmaps
2731 ? defs
[first_binding
]
2737 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 2, 0,
2738 "Read a sequence of keystrokes and return as a string or vector.\n\
2739 The sequence is sufficient to specify a non-prefix command in the\n\
2740 current local and global maps.\n\
2742 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
2743 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
2744 as a continuation of the previous key.\n\
2746 If Emacs is running on multiple screens, switching between screens in\n\
2747 the midst of a keystroke will toss any prefix typed so far. A C-g\n\
2748 typed while in this function is treated like any other character, and\n\
2749 `quit-flag' is not set.")
2750 (prompt
, continue_echo
)
2751 Lisp_Object prompt
, continue_echo
;
2753 Lisp_Object keybuf
[30];
2755 struct gcpro gcpro1
, gcpro2
;
2758 CHECK_STRING (prompt
, 0);
2761 bzero (keybuf
, sizeof keybuf
);
2763 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
2765 if (! NILP (continue_echo
))
2766 this_command_key_count
= 0;
2768 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
2769 NILP (prompt
) ? 0 : XSTRING (prompt
)->data
);
2772 return make_array (i
, keybuf
);
2775 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 2, 0,
2776 "Execute CMD as an editor command.\n\
2777 CMD must be a symbol that satisfies the `commandp' predicate.\n\
2778 Optional second arg RECORD-FLAG non-nil\n\
2779 means unconditionally put this command in `command-history'.\n\
2780 Otherwise, that is done only if an arg is read using the minibuffer.")
2782 Lisp_Object cmd
, record
;
2784 register Lisp_Object final
;
2785 register Lisp_Object tem
;
2786 Lisp_Object prefixarg
;
2787 struct backtrace backtrace
;
2788 extern int debug_on_next_call
;
2790 prefixarg
= Vprefix_arg
, Vprefix_arg
= Qnil
;
2791 Vcurrent_prefix_arg
= prefixarg
;
2792 debug_on_next_call
= 0;
2794 if (XTYPE (cmd
) == Lisp_Symbol
)
2796 tem
= Fget (cmd
, Qdisabled
);
2798 return call1 (Vrun_hooks
, Vdisabled_command_hook
);
2803 final
= Findirect_function (cmd
);
2805 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
2806 do_autoload (final
, cmd
);
2811 if (XTYPE (final
) == Lisp_String
2812 || XTYPE (final
) == Lisp_Vector
)
2814 /* If requested, place the macro in the command history. For
2815 other sorts of commands, call-interactively takes care of
2819 = Fcons (Fcons (Qexecute_kbd_macro
,
2820 Fcons (final
, Fcons (prefixarg
, Qnil
))),
2823 return Fexecute_kbd_macro (final
, prefixarg
);
2825 if (CONSP (final
) || XTYPE (final
) == Lisp_Subr
2826 || XTYPE (final
) == Lisp_Compiled
)
2828 backtrace
.next
= backtrace_list
;
2829 backtrace_list
= &backtrace
;
2830 backtrace
.function
= &Qcall_interactively
;
2831 backtrace
.args
= &cmd
;
2832 backtrace
.nargs
= 1;
2833 backtrace
.evalargs
= 0;
2835 tem
= Fcall_interactively (cmd
, record
);
2837 backtrace_list
= backtrace
.next
;
2844 DEFUN ("execute-mouse-event", Fexecute_mouse_event
, Sexecute_mouse_event
,
2846 "Execute the definition of the mouse-click event EVENT.\n\
2847 The handler function is found by looking the event's key sequence up\n\
2848 in the buffer's local mouse map and in `global-mouse-map'.\n\
2850 After running the handler, call the value of `mouse-event-function'\n\
2851 with EVENT as arg.")
2856 Lisp_Object mouse_cmd
;
2857 Lisp_Object keyseq
, window
, screen_part
, pos
, time
;
2860 Vmouse_event
= event
;
2863 if (EQ (event
, Qnil
))
2869 CHECK_CONS (event
, 0);
2871 window
= Fcar (Fcdr (event
));
2872 screen_part
= Fcar (Fcdr (Fcdr (event
)));
2873 keyseq
= Fcar (Fcdr (Fcdr (Fcdr (event
))));
2874 time
= Fcar (Fcdr (Fcdr (Fcdr (Fcdr (event
)))));
2875 CHECK_STRING (keyseq
, 0);
2876 CHECK_WINDOW (window
, 0);
2878 /* Look up KEYSEQ in the buffer's local mouse map, then in global one. */
2882 if (!NILP (XWINDOW (window
)->buffer
))
2884 Lisp_Object local_map
;
2886 local_map
= XBUFFER (XWINDOW (window
)->buffer
)->mouse_map
;
2887 tem
= Fkeymapp (local_map
);
2889 mouse_cmd
= Flookup_key (local_map
, keyseq
);
2890 /* A number as value means the key is too long; treat as undefined. */
2891 if (XTYPE (mouse_cmd
) == Lisp_Int
)
2895 tem
= Fkeymapp (Vglobal_mouse_map
);
2896 if (NILP (mouse_cmd
) && !NILP (tem
))
2897 mouse_cmd
= Flookup_key (Vglobal_mouse_map
, keyseq
);
2898 if (XTYPE (mouse_cmd
) == Lisp_Int
)
2901 if (NILP (mouse_cmd
))
2903 /* This button/shift combination is not defined.
2904 If it is a button-down event, ring the bell. */
2906 if (XSTRING (keyseq
)->data
[XSTRING (keyseq
)->size
- 1] & 0x18 == 0)
2908 if (XSTRING (keyseq
)->data
[XSTRING (keyseq
)->size
- 1] & 4 == 0)
2914 SCREEN_PTR s
= XSCREEN (WINDOW_SCREEN (XWINDOW (window
)));
2917 Vmouse_window
= s
->selected_window
;
2918 #endif /* HAVE_X11 */
2919 /* It's defined; call the definition. */
2921 if (!NILP (screen_part
))
2923 /* For a scroll-bar click, set the prefix arg
2924 to the number of lines down from the top the click was.
2925 Many scroll commands want to scroll by this many lines. */
2926 Lisp_Object position
;
2930 position
= Fcar (pos
);
2931 length
= Fcar (Fcdr (pos
));
2932 offset
= Fcar (Fcdr (Fcdr (pos
)));
2934 if (XINT (length
) != 0)
2935 XSET (Vprefix_arg
, Lisp_Int
,
2936 (SCREEN_HEIGHT (s
) * (XINT (position
) + XINT (offset
))
2937 / (XINT (length
) + 2 * XINT (offset
))));
2939 Fcommand_execute (mouse_cmd
, Qnil
);
2942 if (!NILP (Vmouse_event_function
)) /* Not `event' so no need for GCPRO */
2943 call1 (Vmouse_event_function
, Vmouse_event
);
2948 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
2950 "Read function name, then read its arguments and call it.")
2952 Lisp_Object prefixarg
;
2954 Lisp_Object function
;
2956 Lisp_Object saved_keys
;
2957 struct gcpro gcpro1
;
2959 saved_keys
= Fthis_command_keys ();
2961 GCPRO1 (saved_keys
);
2963 if (EQ (prefixarg
, Qminus
))
2965 else if (CONSP (prefixarg
) && XINT (XCONS (prefixarg
)->car
) == 4)
2966 strcpy (buf
, "C-u ");
2967 else if (CONSP (prefixarg
) && XTYPE (XCONS (prefixarg
)->car
) == Lisp_Int
)
2968 sprintf (buf
, "%d ", XINT (XCONS (prefixarg
)->car
));
2969 else if (XTYPE (prefixarg
) == Lisp_Int
)
2970 sprintf (buf
, "%d ", XINT (prefixarg
));
2972 /* This isn't strictly correct if execute-extended-command
2973 is bound to anything else. Perhaps it should use
2974 this_command_keys? */
2975 strcat (buf
, "M-x ");
2977 /* Prompt with buf, and then read a string, completing from and
2978 restricting to the set of all defined commands. Don't provide
2979 any initial input. The last Qnil says not to perform a
2980 peculiar hack on the initial input. */
2981 function
= Fcompleting_read (build_string (buf
),
2982 Vobarray
, Qcommandp
,
2985 /* Add the text read to this_command_keys. */
2987 struct Lisp_String
*func_str
= XSTRING (function
);
2991 for (i
= 0; i
< func_str
->size
; i
++)
2993 XSET (tem
, Lisp_Int
, func_str
->data
[i
]);
2994 add_command_key (tem
);
3000 function
= Fintern (function
, Vobarray
);
3001 Vprefix_arg
= prefixarg
;
3002 this_command
= function
;
3004 return Fcommand_execute (function
, Qt
);
3008 detect_input_pending ()
3011 get_input_pending (&input_pending
);
3013 return input_pending
;
3016 /* This is called in some cases before a possible quit.
3017 It cases the next call to detect_input_pending to recompute input_pending.
3018 So calling this function unnecessarily can't do any harm. */
3019 clear_input_pending ()
3024 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
3025 "T if command input is currently available with no waiting.\n\
3026 Actually, the value is nil only if we can be sure that no input is available.")
3029 if (!NILP (unread_command_char
))
3032 return detect_input_pending () ? Qt
: Qnil
;
3035 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
3036 "Return vector of last 100 chars read from terminal.")
3041 if (total_keys
< NUM_RECENT_KEYS
)
3042 return Fvector (total_keys
, recent_keys
);
3045 val
= Fvector (NUM_RECENT_KEYS
, recent_keys
);
3046 bcopy (recent_keys
+ recent_keys_index
,
3047 XVECTOR (val
)->contents
,
3048 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
3050 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
3051 recent_keys_index
* sizeof (Lisp_Object
));
3056 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
3057 "Return string of the keystrokes that invoked this command.")
3060 return make_array (this_command_key_count
, this_command_keys
);
3063 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
3064 "Return the current depth in recursive edits.")
3068 XFASTINT (temp
) = command_loop_level
+ minibuf_level
;
3072 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
3073 "FOpen dribble file: ",
3074 "Start writing all keyboard characters to FILE.")
3085 file
= Fexpand_file_name (file
, Qnil
);
3086 dribble
= fopen (XSTRING (file
)->data
, "w");
3091 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
3092 "Discard the contents of the terminal input buffer.\n\
3093 Also cancel any kbd macro being defined.")
3096 defining_kbd_macro
= 0;
3097 update_mode_lines
++;
3100 unread_command_char
= make_number (-1);
3102 unread_command_char
= Qnil
;
3104 discard_tty_input ();
3106 kbd_fetch_ptr
= kbd_store_ptr
;
3112 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
3113 "Stop Emacs and return to superior process. You can resume later.\n\
3114 On systems that don't have job control, run a subshell instead.\n\n\
3115 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
3116 to be read as terminal input by Emacs's superior shell.\n\
3117 Before suspending, if `suspend-hook' is bound and value is non-nil\n\
3118 call the value as a function of no args. Don't suspend if it returns non-nil.\n\
3119 Otherwise, suspend normally and after resumption call\n\
3120 `suspend-resume-hook' if that is bound and non-nil.\n\
3122 Some operating systems cannot stop the Emacs process and resume it later.\n\
3123 On such systems, Emacs will start a subshell and wait for it to exit.")
3125 Lisp_Object stuffstring
;
3127 register Lisp_Object tem
;
3128 int count
= specpdl_ptr
- specpdl
;
3129 int old_height
, old_width
;
3131 struct gcpro gcpro1
;
3132 extern init_sys_modes ();
3134 if (!NILP (stuffstring
))
3135 CHECK_STRING (stuffstring
, 0);
3136 GCPRO1 (stuffstring
);
3138 /* Call value of suspend-hook
3139 if it is bound and value is non-nil. */
3140 if (!NILP (Vrun_hooks
))
3142 tem
= call1 (Vrun_hooks
, intern ("suspend-hook"));
3143 if (!EQ (tem
, Qnil
)) return Qnil
;
3146 get_screen_size (&old_width
, &old_height
);
3148 /* sys_suspend can get an error if it tries to fork a subshell
3149 and the system resources aren't available for that. */
3150 record_unwind_protect (init_sys_modes
, 0);
3151 stuff_buffered_input (stuffstring
);
3153 unbind_to (count
, Qnil
);
3155 /* Check if terminal/window size has changed.
3156 Note that this is not useful when we are running directly
3157 with a window system; but suspend should be disabled in that case. */
3158 get_screen_size (&width
, &height
);
3159 if (width
!= old_width
|| height
!= old_height
)
3160 change_screen_size (height
, width
, 0);
3162 /* Call value of suspend-resume-hook
3163 if it is bound and value is non-nil. */
3164 if (!NILP (Vrun_hooks
))
3165 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
3171 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
3172 Then in any case stuff anthing Emacs has read ahead and not used. */
3174 stuff_buffered_input (stuffstring
)
3175 Lisp_Object stuffstring
;
3177 register unsigned char *p
;
3179 /* stuff_char works only in BSD, versions 4.2 and up. */
3182 if (XTYPE (stuffstring
) == Lisp_String
)
3186 p
= XSTRING (stuffstring
)->data
;
3187 count
= XSTRING (stuffstring
)->size
;
3192 /* Anything we have read ahead, put back for the shell to read. */
3193 while (kbd_fetch_ptr
!= kbd_store_ptr
)
3195 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3196 kbd_fetch_ptr
= kbd_buffer
;
3197 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
3198 stuff_char (XINT (kbd_fetch_ptr
->code
));
3203 #endif /* BSD and not BSD4_1 */
3206 set_waiting_for_input (time_to_clear
)
3207 EMACS_TIME
*time_to_clear
;
3209 input_available_clear_time
= time_to_clear
;
3211 /* Tell interrupt_signal to throw back to read_char, */
3212 waiting_for_input
= 1;
3214 /* If interrupt_signal was called before and buffered a C-g,
3215 make it run again now, to avoid timing error. */
3216 if (!NILP (Vquit_flag
))
3217 quit_throw_to_read_char ();
3219 /* If alarm has gone off already, echo now. */
3227 clear_waiting_for_input ()
3229 /* Tell interrupt_signal not to throw back to read_char, */
3230 waiting_for_input
= 0;
3231 input_available_clear_time
= 0;
3234 /* This routine is called at interrupt level in response to C-G.
3235 If interrupt_input, this is the handler for SIGINT.
3236 Otherwise, it is called from kbd_buffer_store_event,
3237 in handling SIGIO or SIGTINT.
3239 If `waiting_for_input' is non zero, then unless `echoing' is nonzero,
3240 immediately throw back to read_char.
3242 Otherwise it sets the Lisp variable quit-flag not-nil.
3243 This causes eval to throw, when it gets a chance.
3244 If quit-flag is already non-nil, it stops the job right away. */
3250 /* Must preserve main program's value of errno. */
3251 int old_errno
= errno
;
3252 extern Lisp_Object Vwindow_system
;
3255 /* USG systems forget handlers when they are used;
3256 must reestablish each time */
3257 signal (SIGINT
, interrupt_signal
);
3258 signal (SIGQUIT
, interrupt_signal
);
3263 if (!NILP (Vquit_flag
) && SCREEN_IS_TERMCAP (selected_screen
))
3268 #ifdef SIGTSTP /* Support possible in later USG versions */
3270 * On systems which can suspend the current process and return to the original
3271 * shell, this command causes the user to end up back at the shell.
3272 * The "Auto-save" and "Abort" questions are not asked until
3273 * the user elects to return to emacs, at which point he can save the current
3274 * job and either dump core or continue.
3279 if (sys_suspend () == -1)
3281 printf ("Not running as a subprocess;\n");
3282 printf ("you can continue or abort.\n");
3285 /* Perhaps should really fork an inferior shell?
3286 But that would not provide any way to get back
3287 to the original shell, ever. */
3288 printf ("No support for stopping a process on this operating system;\n");
3289 printf ("you can continue or abort.\n");
3290 #endif /* not VMS */
3291 #endif /* not SIGTSTP */
3292 printf ("Auto-save? (y or n) ");
3294 if (((c
= getchar ()) & ~040) == 'Y')
3295 Fdo_auto_save (Qnil
, Qnil
);
3296 while (c
!= '\n') c
= getchar ();
3298 printf ("Abort (and enter debugger)? (y or n) ");
3300 printf ("Abort (and dump core)? (y or n) ");
3301 #endif /* not VMS */
3303 if (((c
= getchar ()) & ~040) == 'Y')
3305 while (c
!= '\n') c
= getchar ();
3306 printf ("Continuing...\n");
3312 /* If executing a function that wants to be interrupted out of
3313 and the user has not deferred quitting by binding `inhibit-quit'
3314 then quit right away. */
3315 if (immediate_quit
&& NILP (Vinhibit_quit
))
3319 Fsignal (Qquit
, Qnil
);
3322 /* Else request quit when it's safe */
3326 if (waiting_for_input
&& !echoing
)
3327 quit_throw_to_read_char ();
3332 /* Handle a C-g by making read_char return C-g. */
3334 quit_throw_to_read_char ()
3336 quit_error_check ();
3338 /* Prevent another signal from doing this before we finish. */
3339 clear_waiting_for_input ();
3343 unread_command_char
= make_number (-1);
3345 unread_command_char
= Qnil
;
3347 _longjmp (getcjmp
, 1);
3350 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
3351 "Set mode of reading keyboard input.\n\
3352 First arg INTERRUPT non-nil means use input interrupts;\n\
3353 nil means use CBREAK mode.\n\
3354 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
3355 (no effect except in CBREAK mode).\n\
3356 Third arg META non-nil means accept 8-bit input (for a Meta key).\n\
3357 Otherwise, the top bit is ignored, on the assumption it is parity.\n\
3358 Optional fourth arg QUIT if non-nil specifies character to use for quitting.")
3359 (interrupt
, flow
, meta
, quit
)
3360 Lisp_Object interrupt
, flow
, meta
, quit
;
3363 && (XTYPE (quit
) != Lisp_Int
3364 || XINT (quit
) < 0 || XINT (quit
) > 0400))
3365 error ("set-input-mode: QUIT must be an ASCII character.");
3369 /* Note SIGIO has been undef'd if FIONREAD is missing. */
3370 #ifdef NO_SOCK_SIGIO
3371 if (read_socket_hook
)
3372 interrupt_input
= 0; /* No interrupts if reading from a socket. */
3374 #endif /* NO_SOCK_SIGIO */
3375 interrupt_input
= !NILP (interrupt
);
3376 #else /* not SIGIO */
3377 interrupt_input
= 0;
3378 #endif /* not SIGIO */
3379 /* Our VMS input only works by interrupts, as of now. */
3381 interrupt_input
= 1;
3383 flow_control
= !NILP (flow
);
3384 meta_key
= !NILP (meta
);
3386 /* Don't let this value be out of range. */
3387 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
3395 this_command_keys_size
= 40;
3397 (Lisp_Object
*) xmalloc (this_command_keys_size
* sizeof (Lisp_Object
));
3399 /* This is correct before outermost invocation of the editor loop */
3400 command_loop_level
= -1;
3402 quit_char
= Ctl ('g');
3403 unread_command_char
= Qnil
;
3404 recent_keys_index
= 0;
3406 kbd_fetch_ptr
= kbd_buffer
;
3407 kbd_store_ptr
= kbd_buffer
;
3408 do_mouse_tracking
= 0;
3411 if (!noninteractive
)
3413 signal (SIGINT
, interrupt_signal
);
3415 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
3416 SIGQUIT and we can't tell which one it will give us. */
3417 signal (SIGQUIT
, interrupt_signal
);
3418 #endif /* HAVE_TERMIO */
3419 /* Note SIGIO has been undef'd if FIONREAD is missing. */
3421 signal (SIGIO
, input_available_signal
);
3425 /* Use interrupt input by default, if it works and noninterrupt input
3426 has deficiencies. */
3428 #ifdef INTERRUPT_INPUT
3429 interrupt_input
= 1;
3431 interrupt_input
= 0;
3434 /* Our VMS input only works by interrupts, as of now. */
3436 interrupt_input
= 1;
3442 if (keyboard_init_hook
)
3443 (*keyboard_init_hook
) ();
3445 #ifdef POLL_FOR_INPUT
3446 poll_suppress_count
= 1;
3451 /* This type's only use is in syms_of_keyboard, to initialize the
3452 event header symbols and put properties on them. */
3459 struct event_head head_table
[] = {
3460 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
3461 &Qvscrollbar_part
, "vscrollbar-part", &Qscrollbar_click
,
3462 &Qvslider_part
, "vslider-part", &Qscrollbar_click
,
3463 &Qvthumbup_part
, "vthumbup-part", &Qscrollbar_click
,
3464 &Qvthumbdown_part
, "vthumbdown-part", &Qscrollbar_click
,
3465 &Qhscrollbar_part
, "hscrollbar-part", &Qscrollbar_click
,
3466 &Qhslider_part
, "hslider-part", &Qscrollbar_click
,
3467 &Qhthumbleft_part
, "hthumbleft-part", &Qscrollbar_click
,
3468 &Qhthumbright_part
,"hthumbright-part", &Qscrollbar_click
3473 Qself_insert_command
= intern ("self-insert-command");
3474 staticpro (&Qself_insert_command
);
3476 Qforward_char
= intern ("forward-char");
3477 staticpro (&Qforward_char
);
3479 Qbackward_char
= intern ("backward-char");
3480 staticpro (&Qbackward_char
);
3482 Qdisabled
= intern ("disabled");
3483 staticpro (&Qdisabled
);
3485 Qfunction_key
= intern ("function-key");
3486 staticpro (&Qfunction_key
);
3487 Qmouse_movement
= intern ("mouse-click");
3488 staticpro (&Qmouse_click
);
3489 Qmouse_movement
= intern ("scrollbar-click");
3490 staticpro (&Qmouse_movement
);
3492 Qmode_line
= intern ("mode-line");
3493 staticpro (&Qmode_line
);
3494 Qvertical_split
= intern ("vertical-split");
3495 staticpro (&Qvertical_split
);
3497 Qevent_kind
= intern ("event-type");
3498 staticpro (&Qevent_kind
);
3499 Qevent_unmodified
= intern ("event-unmodified");
3500 staticpro (&Qevent_unmodified
);
3503 struct event_head
*p
;
3505 for (p
= head_table
;
3506 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
3509 *p
->var
= intern (p
->name
);
3511 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
3512 Fput (*p
->var
, Qevent_unmodified
, *p
->var
);
3516 func_key_syms
= Qnil
;
3517 staticpro (&func_key_syms
);
3520 staticpro (&mouse_syms
);
3522 defsubr (&Sread_key_sequence
);
3523 defsubr (&Srecursive_edit
);
3524 defsubr (&Strack_mouse
);
3525 defsubr (&Smouse_click_p
);
3526 defsubr (&Sinput_pending_p
);
3527 defsubr (&Scommand_execute
);
3528 defsubr (&Srecent_keys
);
3529 defsubr (&Sthis_command_keys
);
3530 defsubr (&Ssuspend_emacs
);
3531 defsubr (&Sabort_recursive_edit
);
3532 defsubr (&Sexit_recursive_edit
);
3533 defsubr (&Srecursion_depth
);
3534 defsubr (&Stop_level
);
3535 defsubr (&Sdiscard_input
);
3536 defsubr (&Sopen_dribble_file
);
3537 defsubr (&Sset_input_mode
);
3538 defsubr (&Sexecute_extended_command
);
3540 DEFVAR_LISP ("disabled-command-hook", &Vdisabled_command_hook
,
3541 "Value is called instead of any command that is disabled\n\
3542 (has a non-nil `disabled' property).");
3544 DEFVAR_LISP ("last-command-char", &last_command_char
,
3545 "Last terminal input key that was part of a command.");
3547 DEFVAR_LISP ("last-input-char", &last_input_char
,
3548 "Last terminal input key.");
3550 DEFVAR_LISP ("unread-command-char", &unread_command_char
,
3551 "Object to be read as next input from input stream, or nil if none.");
3553 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
3554 "Meta-prefix character code. Meta-foo as command input\n\
3555 turns into this character followed by foo.");
3556 XSET (meta_prefix_char
, Lisp_Int
, 033);
3558 DEFVAR_LISP ("last-command", &last_command
,
3559 "The last command executed. Normally a symbol with a function definition,\n\
3560 but can be whatever was found in the keymap, or whatever the variable\n\
3561 `this-command' was set to by that command.");
3562 last_command
= Qnil
;
3564 DEFVAR_LISP ("this-command", &this_command
,
3565 "The command now being executed.\n\
3566 The command can set this variable; whatever is put here\n\
3567 will be in `last-command' during the following command.");
3568 this_command
= Qnil
;
3570 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
3571 "*Number of keyboard input characters between auto-saves.\n\
3572 Zero means disable autosaving due to number of characters typed.");
3573 auto_save_interval
= 300;
3575 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
3576 "*Number of seconds idle time before auto-save.\n\
3577 Zero or nil means disable auto-saving due to idleness.\n\
3578 After auto-saving due to this many seconds of idle time,\n\
3579 Emacs also does a garbage collection if that seems to be warranted.");
3580 XFASTINT (Vauto_save_timeout
) = 30;
3582 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes
,
3583 "*Nonzero means echo unfinished commands after this many seconds of pause.");
3584 echo_keystrokes
= 1;
3586 DEFVAR_INT ("polling-period", &polling_period
,
3587 "*Interval between polling for input during Lisp execution.\n\
3588 The reason for polling is to make C-g work to stop a running program.\n\
3589 Polling is needed only when using X windows and SIGIO does not work.\n\
3590 Polling is automatically disabled in all other cases.");
3593 DEFVAR_INT ("num-input-keys", &num_input_keys
,
3594 "*Number of complete keys read from the keyboard so far.");
3597 DEFVAR_LISP ("last-event-screen", &Vlast_event_screen
,
3598 "*The screen in which the most recently read event occurred.");
3599 Vlast_event_screen
= Qnil
;
3601 DEFVAR_LISP ("help-char", &help_char
,
3602 "Character to recognize as meaning Help.\n\
3603 When it is read, do `(eval help-form)', and display result if it's a string.\n\
3604 If the value of `help-form' is nil, this char can be read normally.");
3605 XSET (help_char
, Lisp_Int
, Ctl ('H'));
3607 DEFVAR_LISP ("help-form", &Vhelp_form
,
3608 "Form to execute when character help-char is read.\n\
3609 If the form returns a string, that string is displayed.\n\
3610 If `help-form' is nil, the help char is not recognized.");
3613 DEFVAR_LISP ("top-level", &Vtop_level
,
3614 "Form to evaluate when Emacs starts up.\n\
3615 Useful to set before you dump a modified Emacs.");
3618 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
3619 "String used as translate table for keyboard input, or nil.\n\
3620 Each character is looked up in this string and the contents used instead.\n\
3621 If string is of length N, character codes N and up are untranslated.");
3622 Vkeyboard_translate_table
= Qnil
;
3624 #ifdef HAVE_X_WINDOWS
3625 DEFVAR_LISP ("mouse-event-function", &Vmouse_event_function
,
3626 "Function to call for each mouse event, after the event's definition.\n\
3627 Called, if non-nil, with one argument, which is the event-list.\n\
3628 See the variable `mouse-event' for the format of this list.");
3629 Vmouse_event_function
= Qnil
;
3631 DEFVAR_LISP ("mouse-left-hook", &Vmouse_left_hook
,
3632 "Function to call when mouse leaves window. No arguments.");
3633 Vmouse_left_hook
= Qnil
;
3635 DEFVAR_LISP ("map-screen-hook", &Vmap_screen_hook
,
3636 "Function to call when screen is mapped. No arguments.");
3637 Vmap_screen_hook
= Qnil
;
3639 DEFVAR_LISP ("unmap-screen-hook", &Vunmap_screen_hook
,
3640 "Function to call when screen is unmapped. No arguments.");
3641 Vunmap_screen_hook
= Qnil
;
3643 DEFVAR_LISP ("mouse-motion-handler", &Vmouse_motion_handler
,
3644 "Handler for motion events. No arguments.");
3645 Vmouse_motion_handler
= Qnil
;
3648 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
3649 "Non-nil means prompt with menus in echo area when appropriate.\n\
3650 This is done when reading from a keymap that has a prompt string,\n\
3651 for elements that have prompt strings.");
3654 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
3655 "Character to see next line of menu prompt.\n\
3656 Type this character while in a menu prompt to rotate around the lines of it.");
3657 XSET (menu_prompt_more_char
, Lisp_Int
, ' ');
3662 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
3663 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
3664 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
3665 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
3666 initial_define_key (meta_map
, 'x', "execute-extended-command");