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"
50 extern Lisp_Object Vmouse_grabbed
;
52 /* Make all keyboard buffers much bigger when using X windows. */
53 #define KBD_BUFFER_SIZE 4096
54 #else /* No X-windows, character input */
55 #define KBD_BUFFER_SIZE 256
56 #endif /* No X-windows */
58 /* Following definition copied from eval.c */
62 struct backtrace
*next
;
63 Lisp_Object
*function
;
64 Lisp_Object
*args
; /* Points to vector of args. */
65 int nargs
; /* length of vector. If nargs is UNEVALLED,
66 args points to slot holding list of
71 /* Non-nil disable property on a command means
72 do not execute it; call disabled-command-hook's value instead. */
73 Lisp_Object Qdisabled
, Vdisabled_command_hook
;
75 #define NUM_RECENT_KEYS (100)
76 int recent_keys_index
; /* Index for storing next element into recent_keys */
77 int total_keys
; /* Total number of elements stored into recent_keys */
78 Lisp_Object recent_keys
[NUM_RECENT_KEYS
]; /* Holds last 100 keystrokes */
80 /* Buffer holding the key that invoked the current command. */
81 Lisp_Object
*this_command_keys
;
82 int this_command_key_count
; /* Size in use. */
83 int this_command_keys_size
; /* Size allocated. */
85 extern int minbuf_level
;
87 extern struct backtrace
*backtrace_list
;
89 /* Nonzero means do menu prompting. */
90 static int menu_prompting
;
92 /* Character to see next line of menu prompt. */
93 static Lisp_Object menu_prompt_more_char
;
95 /* For longjmp to where kbd input is being done. */
96 static jmp_buf getcjmp
;
98 /* True while doing kbd input. */
99 int waiting_for_input
;
101 /* True while displaying for echoing. Delays C-g throwing. */
104 /* Nonzero means C-G should cause immediate error-signal. */
107 /* Character to recognize as the help char. */
108 Lisp_Object help_char
;
110 /* Form to execute when help char is typed. */
111 Lisp_Object Vhelp_form
;
113 /* Character that causes a quit. Normally C-g.
115 If we are running on an ordinary terminal, this must be an ordinary
116 ASCII char, since we want to make it our interrupt character.
118 If we are not running on an ordinary terminal, it still needs to be
119 an ordinary ASCII char. This character needs to be recognized in
120 the input interrupt handler. At this point, the keystroke is
121 represented as a struct input_event, while the desired quit
122 character is specified as a lispy event. The mapping from struct
123 input_events to lispy events cannot run in an interrupt handler,
124 and the reverse mapping is difficult for anything but ASCII
127 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
131 extern Lisp_Object current_global_map
;
132 extern int minibuf_level
;
134 /* Current depth in recursive edits. */
135 int command_loop_level
;
137 /* Total number of times command_loop has read a key sequence. */
140 /* Last input character read as a command. */
141 Lisp_Object last_command_char
;
143 /* Last input character read for any purpose. */
144 Lisp_Object last_input_char
;
146 /* If not Qnil, an object to be read as the next command input. */
147 Lisp_Object unread_command_char
;
149 /* Char to use as prefix when a meta character is typed in.
150 This is bound on entry to minibuffer in case ESC is changed there. */
152 Lisp_Object meta_prefix_char
;
154 /* Last size recorded for a current buffer which is not a minibuffer. */
155 static int last_non_minibuf_size
;
157 /* Number of idle seconds before an auto-save. */
158 static Lisp_Object Vauto_save_timeout
;
160 /* Total number of times read_char has returned. */
163 /* Auto-save automatically when this many characters have been typed
164 since the last time. */
166 static int auto_save_interval
;
168 /* Value of num_input_chars as of last auto save. */
172 /* Last command executed by the editor command loop, not counting
173 commands that set the prefix argument. */
175 Lisp_Object last_command
;
177 /* The command being executed by the command loop.
178 Commands may set this, and the value set will be copied into last_command
179 instead of the actual command. */
180 Lisp_Object this_command
;
183 /* Window of last mouse click. */
184 extern Lisp_Object Vmouse_window
;
186 /* List containing details of last mouse click. */
187 extern Lisp_Object Vmouse_event
;
188 #endif /* defined HAVE_X11 */
190 /* Hook to call on each mouse event after running its definition. */
191 Lisp_Object Vmouse_event_function
;
193 /* Hook to call when mouse leaves screen. */
194 Lisp_Object Vmouse_left_hook
;
196 /* Hook to call when a screen is mapped. */
197 Lisp_Object Vmap_screen_hook
;
199 /* Hook to call when a screen is unmapped. */
200 Lisp_Object Vunmap_screen_hook
;
202 /* Handler for non-grabbed (no keys depressed) mouse motion. */
203 Lisp_Object Vmouse_motion_handler
;
205 /* The screen in which the last input event occurred.
206 command_loop_1 will select this screen before running the
207 command bound to an event sequence, and read_key_sequence will
208 toss the existing prefix if the user starts typing at a
210 Lisp_Object Vlast_event_screen
;
212 /* X Windows wants this for selection ownership. */
213 unsigned long last_event_timestamp
;
215 Lisp_Object Qself_insert_command
;
216 Lisp_Object Qforward_char
;
217 Lisp_Object Qbackward_char
;
219 /* read_key_sequence stores here the command definition of the
220 key sequence that it reads. */
221 Lisp_Object read_key_sequence_cmd
;
223 /* Form to evaluate (if non-nil) when Emacs is started. */
224 Lisp_Object Vtop_level
;
226 /* User-supplied string to translate input characters through. */
227 Lisp_Object Vkeyboard_translate_table
;
229 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
230 extern Lisp_Object Vfunction_key_map
;
232 /* File in which we write all commands we read. */
235 /* Nonzero if input is available. */
238 /* Nonzero if should obey 0200 bit in input chars as "Meta". */
241 extern char *pending_malloc_warning
;
243 /* Circular buffer for pre-read keyboard input. */
244 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
246 /* Pointer to next available character in kbd_buffer.
247 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
248 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the
249 next available char is in kbd_buffer[0]. */
250 static struct input_event
*kbd_fetch_ptr
;
252 /* Pointer to next place to store character in kbd_buffer. This
253 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
254 character should go in kbd_buffer[0]. */
255 static struct input_event
*kbd_store_ptr
;
257 /* The above pair of variables forms a "queue empty" flag. When we
258 enqueue a non-hook event, we increment kbd_write_count. When we
259 dequeue a non-hook event, we increment kbd_read_count. We say that
260 there is input available iff the two counters are equal.
262 Why not just have a flag set and cleared by the enqueuing and
263 dequeuing functions? Such a flag could be screwed up by interrupts
264 at inopportune times. */
266 /* If this flag is non-zero, mouse movement events will appear in the
267 input stream. If is zero, mouse movement will be ignored. */
268 int do_mouse_tracking
;
270 /* The window system handling code should set this if the mouse has
271 moved since the last call to the mouse_position_hook. Calling that
272 hook should clear this. Code assumes that if this is set, it can
273 call mouse_position_hook to get the promised position, so don't set
274 it unless you're prepared to substantiate the claim! */
277 /* True iff there is an event in kbd_buffer, or if mouse tracking is
278 enabled and there is a new mouse position in the mouse movement
279 buffer. Note that if this is false, that doesn't mean that there
280 is readable input; all the events in the queue might be button-up
281 events, and do_mouse_tracking might be off. */
282 #define EVENT_QUEUES_EMPTY \
283 ((kbd_fetch_ptr == kbd_store_ptr) && (!do_mouse_tracking || !mouse_moved))
286 /* Symbols to head events. */
287 Lisp_Object Qmouse_movement
;
289 Lisp_Object Qvscrollbar_part
;
290 Lisp_Object Qvslider_part
;
291 Lisp_Object Qvthumbup_part
;
292 Lisp_Object Qvthumbdown_part
;
294 Lisp_Object Qhscrollbar_part
;
295 Lisp_Object Qhslider_part
;
296 Lisp_Object Qhthumbleft_part
;
297 Lisp_Object Qhthumbright_part
;
299 /* Symbols to denote kinds of events. */
300 Lisp_Object Qfunction_key
;
301 Lisp_Object Qmouse_click
;
302 /* Lisp_Object Qmouse_movement; - also an event header */
303 Lisp_Object Qscrollbar_click
;
305 /* Properties of event headers. */
306 Lisp_Object Qevent_kind
;
307 Lisp_Object Qevent_unmodified
;
309 /* Symbols to use for non-text mouse positions. */
310 Lisp_Object Qmode_line
;
311 Lisp_Object Qvertical_split
;
314 /* Address (if not 0) of word to zero out if a SIGIO interrupt happens. */
315 long *input_available_clear_word
;
317 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
318 Default is 1 if INTERRUPT_INPUT is defined. */
321 /* Nonzero while interrupts are temporarily deferred during redisplay. */
322 int interrupts_deferred
;
324 /* nonzero means use ^S/^Q for flow control. */
327 /* Allow m- file to inhibit use of FIONREAD. */
328 #ifdef BROKEN_FIONREAD
332 /* We are unable to use interrupts if FIONREAD is not available,
333 so flush SIGIO so we won't try. */
340 /* If we support X Windows, and won't get an interrupt when input
341 arrives from the server, poll periodically so we can detect C-g. */
342 #ifdef HAVE_X_WINDOWS
344 #define POLL_FOR_INPUT
348 /* Global variable declarations. */
350 /* Function for init_keyboard to call with no args (if nonzero). */
351 void (*keyboard_init_hook
) ();
353 static int read_avail_input ();
354 static void get_input_pending ();
356 /* > 0 if we are to echo keystrokes. */
357 static int echo_keystrokes
;
359 /* Nonzero means echo each character as typed. */
360 static int immediate_echo
;
362 /* The text we're echoing in the modeline - partial key sequences,
363 usually. '\0'-terminated. */
364 static char echobuf
[100];
366 /* Where to append more text to echobuf if we want to. */
367 static char *echoptr
;
369 #define min(a,b) ((a)<(b)?(a):(b))
370 #define max(a,b) ((a)>(b)?(a):(b))
372 /* Install the string STR as the beginning of the string of echoing,
373 so that it serves as a prompt for the next character.
374 Also start echoing. */
379 int len
= strlen (str
);
380 if (len
> sizeof echobuf
- 4)
381 len
= sizeof echobuf
- 4;
382 bcopy (str
, echobuf
, len
+ 1);
383 echoptr
= echobuf
+ len
;
388 /* Add C to the echo string, if echoing is going on.
389 C can be a character, which is printed prettily ("M-C-x" and all that
390 jazz), or a symbol, whose name is printed. */
395 extern char *push_key_description ();
404 /* If someone has passed us a composite event, use its head symbol. */
405 if (EVENT_HAS_PARAMETERS (c
))
408 if (XTYPE (c
) == Lisp_Int
)
410 if (ptr
- echobuf
> sizeof echobuf
- 6)
413 ptr
= push_key_description (c
, ptr
);
415 else if (XTYPE (c
) == Lisp_Symbol
)
417 struct Lisp_String
*name
= XSYMBOL (c
)->name
;
418 if (((ptr
- echobuf
) + name
->size
+ 4) > sizeof echobuf
)
420 bcopy (name
->data
, ptr
, name
->size
);
424 if (echoptr
== echobuf
&& c
== help_char
)
426 strcpy (ptr
, " (Type ? for further options)");
437 /* Temporarily add a dash to the end of the echo string if it's not
438 empty, so that it serves as a mini-prompt for the very next character. */
442 if (!immediate_echo
&& echoptr
== echobuf
)
445 /* Put a dash at the end of the buffer temporarily,
446 but make it go away when the next character is added. */
453 /* Display the current echo string, and begin echoing if not already
463 for (i
= 0; i
< this_command_key_count
; i
++)
464 echo_char (this_command_keys
[i
]);
472 if (waiting_for_input
&& !NILP (Vquit_flag
))
473 quit_throw_to_read_char ();
476 /* Turn off echoing, for the start of a new command. */
484 /* Return the length of the current echo string. */
489 return echoptr
- echobuf
;
492 /* Truncate the current echo message to its first LEN chars.
493 This and echo_char get used by read_key_sequence when the user
494 switches screens while entering a key sequence. */
501 echoptr
= echobuf
+ strlen (echobuf
);
505 /* Functions for manipulating this_command_keys. */
507 add_command_key (key
)
510 if (this_command_key_count
== this_command_keys_size
)
512 this_command_keys_size
*= 2;
514 = (Lisp_Object
*) xrealloc (this_command_keys
,
515 (this_command_keys_size
516 * sizeof (Lisp_Object
)));
518 this_command_keys
[this_command_key_count
++] = key
;
524 int count
= specpdl_ptr
- specpdl
;
527 if (command_loop_level
> 0)
529 specbind (Qstandard_output
, Qt
);
530 specbind (Qstandard_input
, Qt
);
533 val
= command_loop ();
535 Fsignal (Qquit
, Qnil
);
541 /* When an auto-save happens, record the "time", and don't do again soon. */
544 last_auto_save
= num_input_chars
;
547 Lisp_Object
recursive_edit_unwind (), command_loop ();
549 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
550 "Invoke the editor command loop recursively.\n\
551 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
552 that tells this function to return.\n\
553 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
554 This function is called by the editor initialization to begin editing.")
557 int count
= specpdl_ptr
- specpdl
;
560 command_loop_level
++;
561 update_mode_lines
= 1;
563 record_unwind_protect (recursive_edit_unwind
,
565 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
569 return unbind_to (count
, Qnil
);
573 recursive_edit_unwind (buffer
)
577 Fset_buffer (buffer
);
579 command_loop_level
--;
580 update_mode_lines
= 1;
588 Lisp_Object errmsg
, tail
, errname
, file_error
;
595 Vstandard_output
= Qt
;
596 Vstandard_input
= Qt
;
597 Vexecuting_macro
= Qnil
;
598 echo_area_glyphs
= 0;
600 /* If the window system or terminal screen hasn't been initialized
601 yet, or we're not interactive, it's best to dump this message out
602 to stderr and exit. */
603 if (! SCREEN_MESSAGE_BUF (selected_screen
)
605 stream
= Qexternal_debugging_output
;
613 errname
= Fcar (data
);
615 if (EQ (errname
, Qerror
))
618 if (!CONSP (data
)) data
= Qnil
;
619 errmsg
= Fcar (data
);
624 errmsg
= Fget (errname
, Qerror_message
);
625 file_error
= Fmemq (Qfile_error
,
626 Fget (errname
, Qerror_conditions
));
629 /* Print an error message including the data items.
630 This is done by printing it into a scratch buffer
631 and then making a copy of the text in the buffer. */
633 if (!CONSP (data
)) data
= Qnil
;
637 /* For file-error, make error message by concatenating
638 all the data items. They are all strings. */
639 if (!NILP (file_error
) && !NILP (tail
))
640 errmsg
= XCONS (tail
)->car
, tail
= XCONS (tail
)->cdr
;
642 if (XTYPE (errmsg
) == Lisp_String
)
643 Fprinc (errmsg
, stream
);
645 write_string_1 ("peculiar error", -1, stream
);
647 for (i
= 0; CONSP (tail
); tail
= Fcdr (tail
), i
++)
649 write_string_1 (i
? ", " : ": ", 2, stream
);
650 if (!NILP (file_error
))
651 Fprinc (Fcar (tail
), stream
);
653 Fprin1 (Fcar (tail
), stream
);
657 /* If the window system or terminal screen hasn't been initialized
658 yet, or we're in -batch mode, this error should cause Emacs to exit. */
659 if (! SCREEN_MESSAGE_BUF (selected_screen
)
663 Fkill_emacs (make_number (-1));
668 Vinhibit_quit
= Qnil
;
669 return make_number (0);
672 Lisp_Object
command_loop_1 ();
673 Lisp_Object
command_loop_2 ();
674 Lisp_Object
top_level_1 ();
676 /* Entry to editor-command-loop.
677 This level has the catches for exiting/returning to editor command loop.
678 It returns nil to exit recursive edit, t to abort it. */
683 if (command_loop_level
> 0 || minibuf_level
> 0)
685 return internal_catch (Qexit
, command_loop_2
, Qnil
);
690 internal_catch (Qtop_level
, top_level_1
, Qnil
);
691 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
693 /* End of file in -batch run causes exit here. */
699 /* Here we catch errors in execution of commands within the
700 editing loop, and reenter the editing loop.
701 When there is an error, cmd_error runs and returns a non-nil
702 value to us. A value of nil means that cmd_loop_1 itself
703 returned due to end of file (or end of kbd macro). */
708 register Lisp_Object val
;
711 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
720 return Feval (Vtop_level
);
726 /* On entry to the outer level, run the startup file */
727 if (!NILP (Vtop_level
))
728 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
729 else if (!NILP (Vpurify_flag
))
730 message ("Bare impure Emacs (standard Lisp code not loaded)");
732 message ("Bare Emacs (standard Lisp code not loaded)");
736 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
737 "Exit all recursive editing levels.")
740 Fthrow (Qtop_level
, Qnil
);
743 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
744 "Exit from the innermost recursive edit or minibuffer.")
747 if (command_loop_level
> 0 || minibuf_level
> 0)
748 Fthrow (Qexit
, Qnil
);
750 error ("No recursive edit is in progress");
753 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
754 "Abort the command that requested this recursive edit or minibuffer input.")
757 if (command_loop_level
> 0 || minibuf_level
> 0)
760 error ("No recursive edit is in progress");
763 /* This is the actual command reading loop,
764 sans error-handling encapsulation. */
766 Lisp_Object
Fcommand_execute ();
767 static int read_key_sequence ();
775 Lisp_Object keybuf
[30];
781 waiting_for_input
= 0;
784 /* Don't clear out last_command at the beginning of a macro. */
785 if (XTYPE (Vexecuting_macro
) != Lisp_String
)
790 this_command_key_count
= 0;
794 /* Install chars successfully executed in kbd macro. */
796 if (defining_kbd_macro
&& NILP (Vprefix_arg
))
797 finalize_kbd_macro_chars ();
799 /* Make sure the current window's buffer is selected. */
800 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
801 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
803 /* Display any malloc warning that just came out. Use while because
804 displaying one warning can cause another. */
806 while (pending_malloc_warning
)
807 display_malloc_warning ();
811 /* If minibuffer on and echo area in use,
812 wait 2 sec and redraw minibufer. */
814 if (minibuf_level
&& echo_area_glyphs
)
816 Fsit_for (make_number (2), Qnil
, Qnil
);
817 echo_area_glyphs
= 0;
819 if (!NILP (Vquit_flag
))
822 unread_command_char
= make_number (quit_char
);
827 alloca (0); /* Cause a garbage collection now */
828 /* Since we can free the most stuff here. */
829 #endif /* C_ALLOCA */
831 /* Read next key sequence; i gets its length. */
832 i
= read_key_sequence (keybuf
, (sizeof keybuf
/ sizeof (keybuf
[0])), 0);
837 /* Select the screen that the key sequence came from. */
838 if (XTYPE (Vlast_event_screen
) == Lisp_Screen
839 && XSCREEN (Vlast_event_screen
) != selected_screen
)
840 Fselect_screen (Vlast_event_screen
, Qnil
);
843 /* Now we have read a key sequence of length I,
844 or else I is 0 and we found end of file. */
846 if (i
== 0) /* End of file -- happens only in */
847 return Qnil
; /* a kbd macro, at the end. */
850 #ifdef HAVE_X_WINDOWS
851 if (SCREEN_IS_X (selected_screen
))
853 if (i
== -1) /* Mouse event */
856 if (NILP (Vprefix_arg
) && NILP (Vexecuting_macro
) &&
857 !EQ (minibuf_window
, selected_window
))
860 if (defining_kbd_macro
)
862 /* Be nice if this worked... */
864 Fexecute_mouse_event (read_key_sequence_cmd
);
869 if (i
== -2) /* Lisp Symbol */
872 if (NILP (Vprefix_arg
) && NILP (Vexecuting_macro
) &&
873 !EQ (minibuf_window
, selected_window
))
879 #endif /* HAVE_X_WINDOWS */
882 last_command_char
= keybuf
[i
- 1];
884 cmd
= read_key_sequence_cmd
;
885 if (!NILP (Vexecuting_macro
))
887 if (!NILP (Vquit_flag
))
889 Vexecuting_macro
= Qt
;
890 QUIT
; /* Make some noise. */
891 /* Will return since macro now empty. */
895 /* Do redisplay processing after this command except in special
896 cases identified below that set no_redisplay to 1. */
899 /* Execute the command. */
903 /* nil means key is undefined. */
905 defining_kbd_macro
= 0;
906 update_mode_lines
= 1;
912 if (NILP (Vprefix_arg
) && ! no_direct
)
914 /* Recognize some common commands in common situations and
916 if (EQ (cmd
, Qforward_char
) && point
< ZV
)
918 struct Lisp_Vector
*dp
919 = window_display_table (XWINDOW (selected_window
));
920 lose
= FETCH_CHAR (point
);
922 if (((dp
== 0 && lose
>= 040 && lose
< 0177)
924 (dp
&& (XTYPE (dp
->contents
[lose
]) != Lisp_String
925 || XSTRING (dp
->contents
[lose
])->size
== sizeof (GLYPH
))))
926 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
928 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
930 && !windows_or_buffers_changed
931 && EQ (current_buffer
->selective_display
, Qnil
)
932 && !detect_input_pending ()
933 && NILP (Vexecuting_macro
))
934 no_redisplay
= direct_output_forward_char (1);
937 else if (EQ (cmd
, Qbackward_char
) && point
> BEGV
)
939 struct Lisp_Vector
*dp
940 = window_display_table (XWINDOW (selected_window
));
942 lose
= FETCH_CHAR (point
);
943 if (((dp
== 0 && lose
>= 040 && lose
< 0177)
945 (dp
&& (XTYPE (dp
->contents
[lose
]) != Lisp_String
946 || XSTRING (dp
->contents
[lose
])->size
== sizeof (GLYPH
))))
947 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
949 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
951 && !windows_or_buffers_changed
952 && EQ (current_buffer
->selective_display
, Qnil
)
953 && !detect_input_pending ()
954 && NILP (Vexecuting_macro
))
955 no_redisplay
= direct_output_forward_char (-1);
958 else if (EQ (cmd
, Qself_insert_command
)
959 /* Try this optimization only on ascii keystrokes. */
960 && XTYPE (last_command_char
) == Lisp_Int
)
962 unsigned char c
= XINT (last_command_char
);
964 if (NILP (Vexecuting_macro
) &&
965 !EQ (minibuf_window
, selected_window
))
967 if (!nonundocount
|| nonundocount
>= 20)
974 lose
= (XFASTINT (XWINDOW (selected_window
)->last_modified
)
976 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
978 || MODIFF
<= current_buffer
->save_modified
979 || windows_or_buffers_changed
980 || !EQ (current_buffer
->selective_display
, Qnil
)
981 || detect_input_pending ()
982 || !NILP (Vexecuting_macro
);
983 if (internal_self_insert (c
, 0))
989 (point
== ZV
|| FETCH_CHAR (point
) == '\n'))
991 struct Lisp_Vector
*dp
992 = window_display_table (XWINDOW (selected_window
));
994 if (dp
== 0 || XTYPE (dp
->contents
[c
]) != Lisp_String
)
995 no_redisplay
= direct_output_for_insert (c
);
996 else if (XSTRING (dp
->contents
[c
])->size
999 direct_output_for_insert (*(GLYPH
*)XSTRING (dp
->contents
[c
])->data
);
1005 /* Here for a command that isn't executed directly */
1008 if (NILP (Vprefix_arg
))
1010 Fcommand_execute (cmd
, Qnil
);
1015 /* If there is a prefix argument,
1016 1) We don't want last_command to be ``universal-argument''
1017 (that would be dumb), so don't set last_command,
1018 2) we want to leave echoing on so that the prefix will be
1019 echoed as part of this key sequence, so don't call
1021 3) we want to leave this_command_key_count non-zero, so that
1022 read_char will realize that it is re-reading a character, and
1023 not echo it a second time. */
1024 if (NILP (Vprefix_arg
))
1026 last_command
= this_command
;
1028 this_command_key_count
= 0;
1033 /* Number of seconds between polling for input. */
1036 /* Nonzero means polling for input is temporarily suppresed. */
1037 int poll_suppress_count
;
1039 #ifdef POLL_FOR_INPUT
1040 int polling_for_input
;
1042 /* Handle an alarm once each second and read pending input
1043 so as to handle a C-g if it comces in. */
1046 input_poll_signal ()
1048 #ifdef HAVE_X_WINDOWS
1049 extern int x_input_blocked
;
1050 if (x_input_blocked
== 0)
1052 if (!waiting_for_input
)
1053 read_avail_input (0);
1054 signal (SIGALRM
, input_poll_signal
);
1055 alarm (polling_period
);
1060 /* Begin signals to poll for input, if they are appropriate.
1061 This function is called unconditionally from various places. */
1065 #ifdef POLL_FOR_INPUT
1066 if (read_socket_hook
)
1068 poll_suppress_count
--;
1069 if (poll_suppress_count
== 0)
1071 signal (SIGALRM
, input_poll_signal
);
1072 polling_for_input
= 1;
1073 alarm (polling_period
);
1079 /* Turn off polling. */
1083 #ifdef POLL_FOR_INPUT
1084 if (read_socket_hook
)
1086 if (poll_suppress_count
== 0)
1088 polling_for_input
= 0;
1091 poll_suppress_count
++;
1096 /* Input of single characters from keyboard */
1098 Lisp_Object
print_help ();
1099 static Lisp_Object
kbd_buffer_get_event ();
1101 /* read a character from the keyboard; call the redisplay if needed */
1102 /* commandflag 0 means do not do auto-saving, but do do redisplay.
1103 -1 means do not do redisplay, but do do autosaving.
1107 read_char (commandflag
)
1110 register Lisp_Object c
;
1114 if (!NILP (unread_command_char
))
1116 c
= unread_command_char
;
1117 unread_command_char
= Qnil
;
1119 #if 0 /* We're not handling mouse keys specially anymore. */
1120 if (!EQ (XTYPE (obj
), Lisp_Int
)) /* Mouse thing */
1123 last_input_char
= 0;
1128 if (this_command_key_count
== 0)
1134 if (!NILP (Vexecuting_macro
))
1136 if (executing_macro_index
>= Flength (Vexecuting_macro
))
1138 XSET (c
, Lisp_Int
, -1);
1142 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
1143 executing_macro_index
++;
1148 /* Save outer setjmp data, in case called recursively. */
1149 bcopy (getcjmp
, save_jump
, sizeof getcjmp
);
1153 if (commandflag
>= 0 && !input_pending
&& !detect_input_pending ())
1156 if (_setjmp (getcjmp
))
1158 XSET (c
, Lisp_Int
, quit_char
);
1160 XSET (Vlast_event_screen
, Lisp_Screen
, selected_screen
);
1163 waiting_for_input
= 0;
1164 input_available_clear_word
= 0;
1169 /* Message turns off echoing unless more keystrokes turn it on again. */
1170 if (echo_area_glyphs
&& *echo_area_glyphs
&& echo_area_glyphs
!= echobuf
)
1173 /* If already echoing, continue. */
1176 /* If in middle of key sequence and minibuffer not active,
1177 start echoing if enough time elapses. */
1178 if (minibuf_level
== 0 && !immediate_echo
&& this_command_key_count
> 0
1179 && echo_keystrokes
> 0
1180 && (echo_area_glyphs
== 0 || *echo_area_glyphs
== 0))
1184 tem0
= Fsit_for (make_number (echo_keystrokes
), Qnil
, Qt
);
1189 /* Maybe auto save due to number of keystrokes or idle time. */
1191 if (commandflag
!= 0
1192 && auto_save_interval
> 0
1193 && num_input_chars
- last_auto_save
> max (auto_save_interval
, 20)
1194 && !detect_input_pending ())
1197 save_getcjmp (temp
);
1198 Fdo_auto_save (Qnil
, Qnil
);
1199 restore_getcjmp (temp
);
1202 /* Slow down auto saves logarithmically in size of current buffer,
1203 and garbage collect while we're at it. */
1205 int delay_level
, buffer_size
;
1207 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
1208 last_non_minibuf_size
= Z
- BEG
;
1209 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
1211 while (buffer_size
> 64)
1212 delay_level
++, buffer_size
-= buffer_size
>> 2;
1213 if (delay_level
< 4) delay_level
= 4;
1214 /* delay_level is 4 for files under around 50k, 7 at 100k,
1215 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
1217 /* Auto save if enough time goes by without input. */
1218 if (commandflag
!= 0
1219 && num_input_chars
> last_auto_save
1220 && XTYPE (Vauto_save_timeout
) == Lisp_Int
1221 && XINT (Vauto_save_timeout
) > 0)
1224 int delay
= delay_level
* XFASTINT (Vauto_save_timeout
) / 4;
1225 tem0
= Fsit_for (make_number (delay
), Qnil
, Qt
);
1229 save_getcjmp (temp
);
1230 Fdo_auto_save (Qnil
, Qnil
);
1231 restore_getcjmp (temp
);
1233 /* If we have auto-saved and there is still no input
1234 available, garbage collect if there has been enough
1235 consing going on to make it worthwhile. */
1236 if (!detect_input_pending ()
1237 && consing_since_gc
> gc_cons_threshold
/ 2)
1238 Fgarbage_collect ();
1243 /* Actually read a character, waiting if necessary. */
1244 c
= kbd_buffer_get_event ();
1247 abort (); /* Don't think this can happen. */
1249 #if 0 /* I think that all the different kinds of events should be
1250 handled together now... */
1251 if (XTYPE (c
) != Lisp_Int
)
1259 /* Terminate Emacs in batch mode if at eof. */
1260 if (noninteractive
&& c
< 0)
1261 Fkill_emacs (make_number (1));
1265 bcopy (save_jump
, getcjmp
, sizeof getcjmp
);
1269 echo_area_glyphs
= 0;
1271 /* Handle things that only apply to characters. */
1272 if (XTYPE (c
) == Lisp_Int
)
1274 /* If kbd_buffer_get_event gave us an EOF, return that. */
1278 /* Strip the high bits, and maybe the meta bit too. */
1279 XSETINT (c
, c
& (meta_key
? 0377 : 0177));
1281 if (XTYPE (Vkeyboard_translate_table
) == Lisp_String
1282 && XSTRING (Vkeyboard_translate_table
)->size
> XINT (c
))
1283 XSETINT (c
, XSTRING (Vkeyboard_translate_table
)->data
[c
]);
1287 recent_keys
[recent_keys_index
] = c
;
1288 if (++recent_keys_index
>= (sizeof (recent_keys
)/sizeof(recent_keys
[0])))
1289 recent_keys_index
= 0;
1291 /* Write c to the dribble file. If c is a lispy event, write
1292 the event's symbol to the dribble file, in <brackets>. Bleaugh.
1293 If you, dear reader, have a better idea, you've got the source. :-) */
1296 if (XTYPE (c
) == Lisp_Int
)
1300 Lisp_Object dribblee
= c
;
1302 /* If it's a structured event, take the event header. */
1303 if (EVENT_HAS_PARAMETERS (dribblee
))
1304 dribblee
= EVENT_HEAD (dribblee
);
1306 if (XTYPE (c
) == Lisp_Symbol
)
1308 putc ('<', dribble
);
1309 fwrite (XSYMBOL (c
)->name
->data
, sizeof (char),
1310 XSYMBOL (c
)->name
->size
,
1312 putc ('>', dribble
);
1319 store_kbd_macro_char (c
);
1325 /* Record this character as part of the current key. */
1326 add_command_key (c
);
1328 /* Re-reading in the middle of a command */
1330 last_input_char
= c
;
1333 /* Process the help character specially if enabled */
1334 if (EQ (c
, help_char
) && !NILP (Vhelp_form
))
1337 count
= specpdl_ptr
- specpdl
;
1339 record_unwind_protect (Fset_window_configuration
,
1340 Fcurrent_window_configuration (Qnil
));
1342 tem0
= Feval (Vhelp_form
);
1343 if (XTYPE (tem0
) == Lisp_String
)
1344 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
1348 /* Remove the help from the screen */
1349 unbind_to (count
, Qnil
);
1351 if (EQ (c
, make_number (040)))
1365 Fprinc (object
, Qnil
);
1369 /* Copy out or in the info on where C-g should throw to.
1370 This is used when running Lisp code from within get_char,
1371 in case get_char is called recursively.
1372 See read_process_output. */
1377 bcopy (getcjmp
, temp
, sizeof getcjmp
);
1380 restore_getcjmp (temp
)
1383 bcopy (temp
, getcjmp
, sizeof getcjmp
);
1387 /* Low level keyboard/mouse input.
1388 kbd_buffer_store_event places events in kbd_buffer, and
1389 kbd_buffer_get_event retrieves them.
1390 mouse_moved indicates when the mouse has moved again, and
1391 *mouse_position_hook provides the mouse position. */
1393 /* Set this for debugging, to have a way to get out */
1396 extern int screen_garbaged
;
1398 /* Return true iff there are any events in the queue that read-char
1399 would return. If this returns false, a read-char would block. */
1403 struct input_event
*ep
;
1405 if (EVENT_QUEUES_EMPTY
)
1408 if (do_mouse_tracking
)
1411 /* Mouse tracking is disabled, so we need to actually scan the
1412 input queue to see if any events are currently readable. */
1413 for (ep
= kbd_fetch_ptr
; ep
!= kbd_store_ptr
; ep
++)
1415 if (ep
== kbd_buffer
+ KBD_BUFFER_SIZE
)
1418 /* Skip button-up events. */
1419 if ((ep
->kind
== mouse_click
|| ep
->kind
== scrollbar_click
)
1420 && (ep
->modifiers
& up_modifier
))
1430 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
1431 of this function. */
1433 tracking_off (old_value
)
1434 Lisp_Object old_value
;
1436 if (! XFASTINT (old_value
))
1438 do_mouse_tracking
= 0;
1440 /* Redisplay may have been preempted because there was input
1441 available, and it assumes it will be called again after the
1442 input has been processed. If the only input available was
1443 the sort that we have just disabled, then we need to call
1445 if (!readable_events ())
1447 redisplay_preserve_echo_area ();
1448 get_input_pending (&input_pending
);
1453 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
1454 "Evaluate BODY with mouse movement and button release events enabled.\n\
1455 Within a track-mouse, read-event reports mouse movement and button releases;\n\
1456 otherwise, they are ignored.")
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
= XINT (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 wait_reading_process_input (0, 0, -1, 1);
1594 if (!interrupt_input
&& EVENT_QUEUES_EMPTY
)
1596 read_avail_input (0);
1599 #endif /* not VMS */
1602 /* At this point, we know that there is a readable event available
1603 somewhere. If the event queue is empty, then there must be a
1604 mouse movement enabled and available. */
1605 if (kbd_fetch_ptr
!= kbd_store_ptr
)
1607 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
1608 kbd_fetch_ptr
= kbd_buffer
;
1609 XSET (Vlast_event_screen
, Lisp_Screen
, kbd_fetch_ptr
->screen
);
1610 last_event_timestamp
= XINT (kbd_fetch_ptr
->timestamp
);
1611 obj
= make_lispy_event (kbd_fetch_ptr
);
1612 kbd_fetch_ptr
->kind
= no_event
;
1614 if (XTYPE (obj
) == Lisp_Int
)
1615 XSET (obj
, Lisp_Int
, XINT (obj
) & (meta_key
? 0377 : 0177));
1617 else if (do_mouse_tracking
&& mouse_moved
)
1620 Lisp_Object x
, y
, time
;
1622 (*mouse_position_hook
) (&screen
, &x
, &y
, &time
);
1623 XSET (Vlast_event_screen
, Lisp_Screen
, screen
);
1625 obj
= make_lispy_movement (screen
, x
, y
, time
);
1628 /* We were promised by the above while loop that there was
1629 something for us to read! */
1632 input_pending
= readable_events ();
1637 /* Caches for modify_event_symbol. */
1638 static Lisp_Object func_key_syms
;
1639 static Lisp_Object mouse_syms
;
1641 /* You'll notice that this table is arranged to be conveniently
1642 indexed by X Windows keysym values. */
1643 static char *lispy_function_keys
[] =
1645 /* X Keysym value */
1647 "home", /* 0xff50 */ /* IsCursorKey */
1658 "select", /* 0xff60 */ /* IsMiscFunctionKey */
1669 "break", /* 0xff6b */
1671 /* Here are some keys found mostly on HP keyboards. The X event
1672 handling code will strip bit 29, which flags vendor-specific
1674 "reset", /* 0x1000ff6c */
1683 "kp_backtab", /* 0x1000ff75 */
1685 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff7f */
1686 "kp-space", /* 0xff80 */ /* IsKeypadKey */
1687 0, 0, 0, 0, 0, 0, 0, 0,
1688 "kp-tab", /* 0xff89 */
1690 "kp-enter", /* 0xff8d */
1692 "kp-f1", /* 0xff91 */
1697 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1698 "kp-multiply", /* 0xffaa */
1703 "kp-divide", /* 0xffaf */
1704 "kp-0", /* 0xffb0 */
1705 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
1708 "kp-equal", /* 0xffbd */
1709 "f1", /* 0xffbe */ /* IsFunctionKey */
1711 "f5", "f6", "f7", "f8", "f9", "f10", "f11", "f12",
1712 "f13", "f14", "f15", "f16", "f17", "f18", "f19", "f20",
1713 "f21", "f22", "f23", "f24", "f25", "f26", "f27", "f28",
1714 "f29", "f30", "f31", "f32", "f33", "f34", "f35" /* 0xffe0 */
1717 static char *lispy_mouse_names
[] =
1719 "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5"
1722 /* Given a struct input_event, build the lisp event which represents
1723 it. If EVENT is 0, build a mouse movement event from the mouse
1724 movement buffer, which should have a movement event in it. */
1727 make_lispy_event (event
)
1728 struct input_event
*event
;
1730 #ifdef SWITCH_ENUM_BUG
1731 switch ((int) event
->kind
)
1733 switch (event
->kind
)
1737 /* A simple keystroke. */
1738 case ascii_keystroke
:
1742 /* A function key. The symbol may need to have modifier prefixes
1744 case non_ascii_keystroke
:
1745 return modify_event_symbol (XFASTINT (event
->code
), event
->modifiers
,
1747 lispy_function_keys
, &func_key_syms
,
1748 (sizeof (lispy_function_keys
)
1749 / sizeof (lispy_function_keys
[0])));
1752 /* A mouse click - build a list of the relevant information. */
1756 Lisp_Object window
=
1757 window_from_coordinates (event
->screen
,
1758 XINT (event
->x
), XINT (event
->y
),
1762 if (XTYPE (window
) != Lisp_Window
)
1766 XSETINT (event
->x
, (XINT (event
->x
)
1767 - XINT (XWINDOW (window
)->left
)));
1768 XSETINT (event
->y
, (XINT (event
->y
)
1769 - XINT (XWINDOW (window
)->top
)));
1774 posn
= Qvertical_split
;
1776 XSET (posn
, Lisp_Int
,
1777 buffer_posn_from_coords (XWINDOW (window
),
1782 return Fcons (modify_event_symbol (XFASTINT (event
->code
) - 1,
1785 lispy_mouse_names
, &mouse_syms
,
1786 (sizeof (lispy_mouse_names
)
1787 / sizeof (lispy_mouse_names
[0]))),
1790 Fcons (Fcons (event
->x
, event
->y
),
1791 Fcons (event
->timestamp
,
1795 /* A scrollbar click. Build a list containing the relevant
1797 case scrollbar_click
:
1800 = modify_event_symbol (XFASTINT (event
->code
) - 1,
1803 lispy_mouse_names
, &mouse_syms
,
1804 (sizeof (lispy_mouse_names
)
1805 / sizeof (lispy_mouse_names
[0])));
1806 return Fcons (event
->part
,
1807 Fcons (SCREEN_SELECTED_WINDOW (event
->screen
),
1809 Fcons (Fcons (event
->x
, event
->y
),
1810 Fcons (event
->timestamp
,
1814 /* The 'kind' field of the event is something we don't recognize. */
1821 make_lispy_movement (screen
, x
, y
, time
)
1834 ? window_from_coordinates (screen
, ix
, iy
, &part
)
1836 if (XTYPE (window
) != Lisp_Window
)
1840 ix
-= XINT (XWINDOW (window
)->left
);
1841 iy
-= XINT (XWINDOW (window
)->top
);
1845 posn
= Qvertical_split
;
1847 XSET (posn
, Lisp_Int
, buffer_posn_from_coords (XWINDOW (window
),
1853 return Fcons (Qmouse_movement
,
1856 Fcons (Fcons (x
, y
),
1857 Fcons (time
, Qnil
)))));
1862 /* Place the written representation of MODIFIERS in BUF, '\0'-terminated,
1863 and return its length. */
1866 format_modifiers (modifiers
, buf
)
1872 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
1873 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
1874 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
1875 if (modifiers
& up_modifier
) { *p
++ = 'U'; *p
++ = '-'; }
1882 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
1883 return a symbol with the modifiers placed in the canonical order.
1885 Fdefine_key calls this to make sure that (for example) C-M-foo
1886 and M-C-foo end up being equivalent in the keymap. */
1889 reorder_modifiers (symbol
)
1892 struct Lisp_String
*name
;
1897 CHECK_SYMBOL (symbol
, 1);
1900 name
= XSYMBOL (symbol
)->name
;
1902 /* Special case for things with only one modifier, which is
1903 (hopefully) the vast majority of cases. */
1904 if (! (name
->size
>= 4 && name
->data
[1] == '-' && name
->data
[3] == '-'))
1907 for (i
= 0; i
+ 1 < name
->size
&& name
->data
[i
+ 1] == '-'; i
+= 2)
1908 switch (name
->data
[i
])
1911 not_canonical
|= (modifiers
& (meta_modifier
|ctrl_modifier
1912 |shift_modifier
|up_modifier
));
1913 modifiers
|= meta_modifier
;
1917 not_canonical
|= (modifiers
&
1918 (ctrl_modifier
|shift_modifier
|up_modifier
));
1919 modifiers
|= ctrl_modifier
;
1923 not_canonical
|= (modifiers
& (shift_modifier
|up_modifier
));
1924 modifiers
|= shift_modifier
;
1928 not_canonical
|= (modifiers
& (up_modifier
));
1929 modifiers
|= up_modifier
;
1933 goto no_more_modifiers
;
1940 /* The modifiers were out of order, so find a new symbol with the
1941 mods in order. Since the symbol name could contain nulls, we can't
1942 use intern here; we have to use Fintern, which expects a genuine
1943 Lisp_String, and keeps a reference to it. */
1945 char *new_mods
= (char *) alloca (sizeof ("C-M-S-U-"));
1946 int len
= format_modifiers (modifiers
, new_mods
);
1947 Lisp_Object new_name
= make_uninit_string (len
+ name
->size
- i
);
1949 bcopy (new_mods
, XSTRING (new_name
)->data
, len
);
1950 bcopy (name
->data
+ i
, XSTRING (new_name
)->data
+ len
, name
->size
- i
);
1952 return Fintern (new_name
, Qnil
);
1957 /* For handling events, we often want to produce a symbol whose name
1958 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
1959 to some base, like the name of a function key or mouse button.
1960 modify_event_symbol produces symbols of this sort.
1962 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
1963 is the name of the i'th symbol. TABLE_SIZE is the number of elements
1966 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
1967 persist between calls to modify_event_symbol that it can use to
1968 store a cache of the symbols it's generated for this NAME_TABLE
1971 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
1973 MODIFIERS is a set of modifier bits (as given in struct input_events)
1974 whose prefixes should be applied to the symbol name.
1976 SYMBOL_KIND is the value to be placed in the event_kind property of
1977 the returned symbol. */
1980 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_table
,
1981 symbol_table
, table_size
)
1984 Lisp_Object symbol_kind
;
1986 Lisp_Object
*symbol_table
;
1989 Lisp_Object
*slot
, *unmodified_slot
;
1991 /* Is this a request for a valid symbol? */
1992 if (symbol_num
< 0 || symbol_num
>= table_size
1993 || modifiers
>= NUM_MODIFIER_COMBOS
)
1996 /* If *symbol_table is not a vector of the appropriate size,
1998 if (XTYPE (*symbol_table
) != Lisp_Vector
1999 || XVECTOR (*symbol_table
)->size
!= table_size
)
2000 *symbol_table
= Fmake_vector (make_number (table_size
), Qnil
);
2002 unmodified_slot
= slot
= & XVECTOR (*symbol_table
)->contents
[symbol_num
];
2004 /* If there are modifier keys, there had better be a vector in
2005 this symbol's position of the symbol_table. */
2008 Lisp_Object slot_contents
= *slot
;
2010 /* If there isn't the right sort of vector there, put one in. */
2011 if (XTYPE (slot_contents
) != Lisp_Vector
2012 || XVECTOR (slot_contents
)->size
!= NUM_MODIFIER_COMBOS
)
2014 *slot
= Fmake_vector (make_number (NUM_MODIFIER_COMBOS
), Qnil
);
2016 /* Make sure that the vector has an entry for the unmodified
2017 symbol, so we can put it on the event_unmodified property. */
2018 if (! NILP (slot_contents
))
2019 XVECTOR (*slot
)->contents
[0] = slot_contents
;
2021 XVECTOR (*slot
)->contents
[0] = intern (name_table
[symbol_num
]);
2025 /* If this entry has been filled in with a modified symbol vector,
2026 point to the appropriate slot within that. */
2027 if (XTYPE (*slot
) == Lisp_Vector
)
2029 unmodified_slot
= & XVECTOR (*slot
)->contents
[0];
2030 slot
= & XVECTOR (*slot
)->contents
[modifiers
];
2033 /* Make sure we have an unmodified version of the symbol in its
2035 if (NILP (*unmodified_slot
))
2037 *unmodified_slot
= intern (name_table
[symbol_num
]);
2038 Fput (*unmodified_slot
, Qevent_kind
, symbol_kind
);
2039 Fput (*unmodified_slot
, Qevent_unmodified
, *unmodified_slot
);
2042 /* Have we already created a symbol for this combination of modifiers? */
2045 /* No, let's create one. */
2047 = (char *) alloca (sizeof ("C-M-S-U-")
2048 + strlen (name_table
[symbol_num
]));
2050 strcpy (modified_name
+ format_modifiers (modifiers
, modified_name
),
2051 name_table
[symbol_num
]);
2053 *slot
= intern (modified_name
);
2054 Fput (*slot
, Qevent_kind
, symbol_kind
);
2055 Fput (*slot
, Qevent_unmodified
, *unmodified_slot
);
2061 DEFUN ("mouse-click-p", Fmouse_click_p
, Smouse_click_p
, 1, 1, 0,
2062 "Return non-nil iff OBJECT is a representation of a mouse event.\n\
2063 A mouse event is a list of five elements whose car is a symbol of the\n\
2064 form <MODIFIERS>mouse-<DIGIT>. I hope this is a temporary hack.")
2068 if (EVENT_HAS_PARAMETERS (object
)
2069 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (object
)),
2076 /* Store into *addr a value nonzero if terminal input chars are available.
2077 Serves the purpose of ioctl (0, FIONREAD, addr)
2078 but works even if FIONREAD does not exist.
2079 (In fact, this may actually read some input.) */
2082 get_input_pending (addr
)
2085 /* First of all, have we already counted some input? */
2086 *addr
= !NILP (Vquit_flag
) || readable_events ();
2088 /* If input is being read as it arrives, and we have none, there is none. */
2089 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
2092 /* Try to read some input and see how much we get. */
2094 *addr
= !NILP (Vquit_flag
) || readable_events ();
2097 /* Interface to read_avail_input, blocking SIGIO if necessary. */
2100 gobble_input (expected
)
2105 if (interrupt_input
)
2107 SIGMASKTYPE mask
= sigblockx (SIGIO
);
2108 read_avail_input (expected
);
2113 read_avail_input (expected
);
2119 /* Read any terminal input already buffered up by the system
2120 into the kbd_buffer, but do not wait.
2122 EXPECTED should be nonzero if the caller knows there is some input.
2124 Except on VMS, all input is read by this function.
2125 If interrupt_input is nonzero, this function MUST be called
2126 only when SIGIO is blocked.
2128 Returns the number of keyboard chars read, or -1 meaning
2129 this is a bad time to try to read input. */
2132 read_avail_input (expected
)
2135 struct input_event buf
[KBD_BUFFER_SIZE
];
2139 if (read_socket_hook
)
2140 /* No need for FIONREAD or fcntl; just say don't wait. */
2141 nread
= (*read_socket_hook
) (0, buf
, KBD_BUFFER_SIZE
, expected
, expected
);
2144 unsigned char cbuf
[KBD_BUFFER_SIZE
];
2147 /* Find out how much input is available. */
2148 if (ioctl (0, FIONREAD
, &nread
) < 0)
2149 /* Formerly simply reported no input, but that sometimes led to
2150 a failure of Emacs to terminate.
2151 SIGHUP seems appropriate if we can't reach the terminal. */
2152 kill (getpid (), SIGHUP
);
2155 if (nread
> sizeof cbuf
)
2156 nread
= sizeof cbuf
;
2157 #else /* no FIONREAD */
2159 /* Read some input if available, but don't wait. */
2160 nread
= sizeof cbuf
;
2161 fcntl (fileno (stdin
), F_SETFL
, O_NDELAY
);
2167 /* Now read; for one reason or another, this will not block. */
2170 nread
= read (fileno (stdin
), cbuf
, nread
);
2172 /* The kernel sometimes fails to deliver SIGHUP for ptys.
2173 This looks incorrect, but it isn't, because _BSD causes
2174 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
2175 and that causes a value other than 0 when there is no input. */
2179 /* Retry the read if it is interrupted. */
2181 || ! (errno
== EAGAIN
|| errno
== EFAULT
2191 fcntl (fileno (stdin
), F_SETFL
, 0);
2193 #endif /* no FIONREAD */
2194 for (i
= 0; i
< nread
; i
++)
2196 buf
[i
].kind
= ascii_keystroke
;
2197 XSET (buf
[i
].code
, Lisp_Int
, cbuf
[i
]);
2198 buf
[i
].screen
= selected_screen
;
2202 /* Scan the chars for C-g and store them in kbd_buffer. */
2203 for (i
= 0; i
< nread
; i
++)
2205 kbd_buffer_store_event (&buf
[i
]);
2206 /* Don't look at input that follows a C-g too closely.
2207 This reduces lossage due to autorepeat on C-g. */
2208 if (buf
[i
].kind
== ascii_keystroke
2209 && XINT(buf
[i
].code
) == quit_char
)
2215 #endif /* not VMS */
2217 #ifdef SIGIO /* for entire page */
2218 /* Note SIGIO has been undef'd if FIONREAD is missing. */
2220 input_available_signal (signo
)
2223 /* Must preserve main program's value of errno. */
2224 int old_errno
= errno
;
2226 extern int select_alarmed
;
2230 /* USG systems forget handlers when they are used;
2231 must reestablish each time */
2232 signal (signo
, input_available_signal
);
2239 if (input_available_clear_word
)
2240 *input_available_clear_word
= 0;
2245 nread
= read_avail_input (1);
2246 /* -1 means it's not ok to read the input now.
2247 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
2248 0 means there was no keyboard input available. */
2253 select_alarmed
= 1; /* Force the select emulator back to life */
2264 /* Return the prompt-string of a sparse keymap.
2265 This is the first element which is a string.
2266 Return nil if there is none. */
2274 register Lisp_Object tem
;
2276 if (XTYPE (tem
) == Lisp_String
)
2283 static int echo_flag
;
2284 static int echo_now
;
2286 /* Read a character like read_char but optionally prompt based on maps
2289 The prompting is done based on the prompt-string of the map
2290 and the strings associated with various map elements. */
2293 read_char_menu_prompt (prompt
, local
, global
)
2295 Lisp_Object local
, global
;
2297 register Lisp_Object rest
, name
;
2300 int width
= SCREEN_WIDTH (selected_screen
) - 4;
2301 char *menu
= (char *) alloca (width
);
2303 /* Use local over global Menu maps */
2306 return read_char (!prompt
);
2308 /* We can't get prompt strings from dense keymaps. */
2310 && EQ (Fcar (local
), Qkeymap
)
2311 && !(CONSP (XCONS (local
)->cdr
)
2312 && XTYPE (XCONS (XCONS (local
)->cdr
)->car
) == Lisp_Vector
))
2314 else if (CONSP (global
)
2315 && EQ (Fcar (global
), Qkeymap
)
2316 && !(CONSP (XCONS (global
)->cdr
)
2317 && XTYPE (XCONS (XCONS (global
)->cdr
)->car
) == Lisp_Vector
))
2320 return read_char (!prompt
);
2322 /* Get the map's prompt string. */
2323 name
= map_prompt (hmap
);
2325 return read_char (!prompt
);
2327 /* Prompt string always starts with map's prompt, and a space. */
2328 strcpy (menu
, XSTRING (name
)->data
);
2329 nlength
= XSTRING (name
)->size
;
2330 menu
[nlength
++] = ' ';
2333 /* Start prompting at start of map. */
2334 rest
= hmap
; /* Current menu item */
2336 /* Present the documented bindings, a line at a time. */
2344 /* If reached end of map, start at beginning. */
2345 if (NILP (Fcdr (rest
))) rest
= hmap
;
2347 /* Loop over elements of map. */
2348 while (!NILP (rest
) && i
< width
)
2352 /* Look for conses whose cadrs are strings. */
2353 s
= Fcar_safe (Fcdr_safe (Fcar_safe (rest
)));
2354 if (XTYPE (s
) != Lisp_String
)
2355 /* Ignore all other elements. */
2357 /* If first such element, or enough room, add string to prompt. */
2358 else if (XSTRING (s
)->size
+ i
< width
2363 /* Punctuate between strings. */
2366 strcpy (menu
+ i
, ", ");
2371 /* Add as much of string as fits. */
2372 thiswidth
= XSTRING (s
)->size
;
2373 if (thiswidth
+ i
> width
)
2374 thiswidth
= width
- i
;
2375 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
2380 /* If some elts don't fit, show there are more. */
2381 strcpy (menu
+ i
, "...");
2385 /* Move past this element. */
2386 rest
= Fcdr_safe (rest
);
2389 /* Prompt with that and read response. */
2391 obj
= read_char (1);
2393 if (XTYPE (obj
) != Lisp_Int
)
2398 if (obj
!= menu_prompt_more_char
2399 && (XTYPE (menu_prompt_more_char
) != Lisp_Int
2400 || obj
!= make_number (Ctl (XINT (menu_prompt_more_char
)))))
2406 /* Reading key sequences. */
2408 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
2409 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
2410 keymap, or nil otherwise. Return the index of the first keymap in
2411 which KEY has any binding, or NMAPS if no map has a binding.
2413 If KEY is a meta ASCII character, treat it like meta-prefix-char
2414 followed by the corresponding non-meta character. Keymaps in
2415 CURRENT with non-prefix bindings for meta-prefix-char become nil in
2418 When KEY is not defined in any of the keymaps, if it is an upper
2419 case letter and there are bindings for the corresponding lower-case
2420 letter, return the bindings for the lower-case letter.
2422 NEXT may == CURRENT. */
2425 follow_key (key
, nmaps
, current
, defs
, next
)
2427 Lisp_Object
*current
, *defs
, *next
;
2430 int i
, first_binding
;
2432 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
2433 followed by the corresponding non-meta character. */
2434 if (XTYPE (key
) == Lisp_Int
2435 && XINT (key
) >= 0200)
2437 for (i
= 0; i
< nmaps
; i
++)
2438 if (! NILP (current
[i
]))
2440 next
[i
] = get_keyelt (access_keymap (current
[i
],
2443 /* Note that since we pass the resulting bindings through
2444 get_keymap_1, non-prefix bindings for meta-prefix-char
2446 next
[i
] = get_keymap_1 (next
[i
], 0);
2452 XSET (key
, Lisp_Int
, XFASTINT (key
) & 0177);
2455 first_binding
= nmaps
;
2456 for (i
= nmaps
- 1; i
>= 0; i
--)
2458 if (! NILP (current
[i
]))
2460 defs
[i
] = get_keyelt (access_keymap (current
[i
], key
));
2461 if (! NILP (defs
[i
]))
2468 /* When KEY is not defined in any of the keymaps, if it is an upper
2469 case letter and there are bindings for the corresponding
2470 lower-case letter, return the bindings for the lower-case letter. */
2471 if (first_binding
== nmaps
2472 && XTYPE (key
) == Lisp_Int
2473 && UPPERCASEP (XINT (key
)))
2475 XSETINT (key
, DOWNCASE (XINT (key
)));
2477 first_binding
= nmaps
;
2478 for (i
= nmaps
- 1; i
>= 0; i
--)
2480 if (! NILP (current
[i
]))
2482 defs
[i
] = get_keyelt (access_keymap (current
[i
], key
));
2483 if (! NILP (defs
[i
]))
2491 /* Given the set of bindings we've found, produce the next set of maps. */
2492 for (i
= 0; i
< nmaps
; i
++)
2493 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0);
2495 return first_binding
;
2498 /* Read a sequence of keys that ends with a non prefix character
2499 according to the keymaps in KEYMAPS[0..nmaps-1]. Keymaps appearing
2500 earlier in KEYMAPS take precidence over those appearing later.
2502 Store the sequence in KEYBUF, a buffer of size BUFSIZE. Prompt
2503 with PROMPT. Echo starting immediately unless `prompt' is 0.
2504 Return the length of the key sequence stored.
2506 If the user switches screens in the midst of a key sequence, we
2507 throw away any prefix we have read so far, and start afresh. For
2508 mouse clicks, we look up the click in the keymap of the buffer
2509 clicked on, throwing away any prefix if it is not the same buffer
2510 we used to be reading from. */
2513 read_key_sequence (keybuf
, bufsize
, prompt
)
2514 Lisp_Object
*keybuf
;
2518 /* How many keys there are in the current key sequence. */
2521 /* The buffer that the most recently read event was typed at. This
2522 helps us read mouse clicks according to the buffer clicked in,
2523 and notice when the mouse has moved from one screen to another. */
2524 struct buffer
*last_event_buffer
= current_buffer
;
2526 /* The length of the echo buffer when we started reading, and
2527 the length of this_command_keys when we started reading. */
2529 int keys_start
= this_command_key_count
;
2531 /* The number of keymaps we're scanning right now, and the number of
2532 keymaps we have allocated space for. */
2534 int nmaps_allocated
= 0;
2536 /* current[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
2537 in the current keymaps, or nil where it is not a prefix. */
2538 Lisp_Object
*current
;
2540 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
2541 the current keymaps. */
2544 /* The lowest i such that defs[i] is non-nil. */
2547 /* If mock_input > t, then KEYBUF[t] should be read as the next
2551 /* If the sequence is unbound in current[], keymap[fkey_start..fkey_end-1]
2552 is a prefix in Vfunction_key_map, and fkey_map is its binding.
2553 These might be > t, indicating that all function key scanning should
2554 hold off until t reaches them. */
2555 int fkey_start
= 0, fkey_end
= 0;
2556 Lisp_Object fkey_map
= Vfunction_key_map
;
2561 echo_prompt (prompt
);
2562 else if (cursor_in_echo_area
)
2563 /* This doesn't put in a dash if the echo buffer is empty, so
2564 you don't always see a dash hanging out in the minibuffer. */
2566 echo_start
= echo_length ();
2569 /* If there is no function key map, turn of function key scanning. */
2570 if (NILP (Fkeymapp (Vfunction_key_map
)))
2571 fkey_start
= fkey_end
= bufsize
+ 1;
2575 this_command_key_count
= keys_start
;
2580 nmaps
= current_minor_maps (0, &maps
) + 2;
2581 if (nmaps
> nmaps_allocated
)
2583 current
= (Lisp_Object
*) alloca (nmaps
* sizeof (current
[0]));
2584 defs
= (Lisp_Object
*) alloca (nmaps
* sizeof (defs
[0]));
2585 nmaps_allocated
= nmaps
;
2587 bcopy (maps
, current
, (nmaps
- 2) * sizeof (current
[0]));
2588 current
[nmaps
-2] = last_event_buffer
->keymap
;
2589 current
[nmaps
-1] = global_map
;
2592 /* Find an accurate initial value for first_binding. */
2593 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
2594 if (! NILP (current
[first_binding
]))
2597 while ((first_binding
< nmaps
&& ! NILP (current
[first_binding
]))
2598 || (first_binding
>= nmaps
&& fkey_start
< t
))
2603 error ("key sequence too long");
2605 /* Are we reading keys stuffed into keybuf? */
2609 add_command_key (key
);
2612 /* Otherwise, we should actually read a character. */
2617 if (!prompt
&& INTERACTIVE
)
2618 key
= read_char_menu_prompt (prompt
, Qnil
, Qnil
);
2620 key
= read_char (!prompt
);
2622 /* The above routines return -1 at the end of a macro.
2623 Emacs 18 handles this by returning immediately with a
2624 zero, so that's what we'll do. */
2625 if (XTYPE (key
) == Lisp_Int
&& XINT (key
) < 0)
2630 /* What buffer was this event typed/moused at? */
2631 if (XTYPE (key
) == Lisp_Int
|| XTYPE (key
) == Lisp_Symbol
)
2634 (SCREEN_SELECTED_WINDOW
2635 (XSCREEN (Vlast_event_screen
)))->buffer
));
2636 else if (EVENT_HAS_PARAMETERS (key
))
2638 Lisp_Object window
= EVENT_WINDOW (key
);
2643 buf
= XBUFFER (XWINDOW (window
)->buffer
);
2648 /* If this event came to a different buffer than the one
2649 we're currently in, switch buffers and start a new key
2650 sequence, starting with key. */
2651 if (buf
!= last_event_buffer
)
2653 last_event_buffer
= buf
;
2654 Fselect_screen (Vlast_event_screen
, Qnil
);
2656 /* Arrange to read key as the next event. */
2660 /* Truncate the key sequence in the echo area. */
2662 echo_truncate (echo_start
);
2668 first_binding
= (follow_key (key
,
2669 nmaps
- first_binding
,
2670 current
+ first_binding
,
2671 defs
+ first_binding
,
2672 current
+ first_binding
)
2676 /* If the sequence is unbound, see if we can hang a function key
2677 off the end of it. Don't reread the expansion of a function key. */
2678 if (first_binding
>= nmaps
2681 Lisp_Object fkey_next
;
2683 /* Scan from fkey_end until we find a bound suffix. */
2684 while (fkey_end
< t
)
2687 get_keyelt (access_keymap (fkey_map
, keybuf
[fkey_end
++]));
2688 /* If keybuf[fkey_start..fkey_next] is bound in the
2689 function key map and it's a suffix of the current
2690 sequence (i.e. fkey_next == t), replace it with
2691 the binding and restart with fkey_start at the end. */
2692 if (XTYPE (fkey_next
) == Lisp_Vector
2695 t
= fkey_start
+ XVECTOR (fkey_next
)->size
;
2697 error ("key sequence too long");
2699 bcopy (XVECTOR (fkey_next
)->contents
,
2700 keybuf
+ fkey_start
,
2701 (t
- fkey_start
) * sizeof (keybuf
[0]));
2704 fkey_start
= fkey_end
= t
;
2706 /* Truncate the key sequence in the echo area. */
2708 echo_truncate (echo_start
);
2713 fkey_map
= get_keymap_1 (fkey_next
, 0);
2715 /* If we no longer have a bound suffix, try a new positions for
2717 if (NILP (fkey_map
))
2719 fkey_end
= ++fkey_start
;
2720 fkey_map
= Vfunction_key_map
;
2726 read_key_sequence_cmd
= (first_binding
< nmaps
2727 ? defs
[first_binding
]
2733 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 1, 0,
2734 "Read a sequence of keystrokes and return as a string or vector.\n\
2735 The sequence is sufficient to specify a non-prefix command in the\n\
2736 current local and global maps.\n\
2738 Arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
2740 If Emacs is running on multiple screens, switching between screens in\n\
2741 the midst of a keystroke will toss any prefix typed so far. A C-g\n\
2742 typed while in this function is treated like any other character, and\n\
2743 `quit-flag' is not set.")
2747 Lisp_Object keybuf
[30];
2749 struct gcpro gcpro1
, gcpro2
;
2752 CHECK_STRING (prompt
, 0);
2755 bzero (keybuf
, sizeof keybuf
);
2757 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
2759 this_command_key_count
= 0;
2760 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
2761 NILP (prompt
) ? 0 : XSTRING (prompt
)->data
);
2764 return make_array (i
, keybuf
);
2767 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 2, 0,
2768 "Execute CMD as an editor command.\n\
2769 CMD must be a symbol that satisfies the `commandp' predicate.\n\
2770 Optional second arg RECORD-FLAG non-nil\n\
2771 means unconditionally put this command in `command-history'.\n\
2772 Otherwise, that is done only if an arg is read using the minibuffer.")
2774 Lisp_Object cmd
, record
;
2776 register Lisp_Object final
;
2777 register Lisp_Object tem
;
2778 Lisp_Object prefixarg
;
2779 struct backtrace backtrace
;
2780 extern int debug_on_next_call
;
2782 prefixarg
= Vprefix_arg
, Vprefix_arg
= Qnil
;
2783 Vcurrent_prefix_arg
= prefixarg
;
2784 debug_on_next_call
= 0;
2786 if (XTYPE (cmd
) == Lisp_Symbol
)
2788 tem
= Fget (cmd
, Qdisabled
);
2790 return call1 (Vrun_hooks
, Vdisabled_command_hook
);
2796 while (XTYPE (final
) == Lisp_Symbol
)
2798 if (EQ (Qunbound
, XSYMBOL (final
)->function
))
2799 Fsymbol_function (final
); /* Get an error! */
2800 final
= XSYMBOL (final
)->function
;
2803 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
2804 do_autoload (final
, cmd
);
2809 if (XTYPE (final
) == Lisp_String
2810 || XTYPE (final
) == Lisp_Vector
)
2812 /* If requested, place the macro in the command history. For
2813 other sorts of commands, call-interactively takes care of
2817 = Fcons (Fcons (Qexecute_kbd_macro
,
2818 Fcons (final
, Fcons (prefixarg
, Qnil
))),
2821 return Fexecute_kbd_macro (final
, prefixarg
);
2823 if (CONSP (final
) || XTYPE (final
) == Lisp_Subr
2824 || XTYPE (final
) == Lisp_Compiled
)
2826 backtrace
.next
= backtrace_list
;
2827 backtrace_list
= &backtrace
;
2828 backtrace
.function
= &Qcall_interactively
;
2829 backtrace
.args
= &cmd
;
2830 backtrace
.nargs
= 1;
2831 backtrace
.evalargs
= 0;
2833 tem
= Fcall_interactively (cmd
, record
);
2835 backtrace_list
= backtrace
.next
;
2842 DEFUN ("execute-mouse-event", Fexecute_mouse_event
, Sexecute_mouse_event
,
2844 "Execute the definition of the mouse-click event EVENT.\n\
2845 The handler function is found by looking the event's key sequence up\n\
2846 in the buffer's local mouse map and in `global-mouse-map'.\n\
2848 After running the handler, call the value of `mouse-event-function'\n\
2849 with EVENT as arg.")
2854 Lisp_Object mouse_cmd
;
2855 Lisp_Object keyseq
, window
, screen_part
, pos
, time
;
2858 Vmouse_event
= event
;
2861 if (EQ (event
, Qnil
))
2867 CHECK_CONS (event
, 0);
2869 window
= Fcar (Fcdr (event
));
2870 screen_part
= Fcar (Fcdr (Fcdr (event
)));
2871 keyseq
= Fcar (Fcdr (Fcdr (Fcdr (event
))));
2872 time
= Fcar (Fcdr (Fcdr (Fcdr (Fcdr (event
)))));
2873 CHECK_STRING (keyseq
, 0);
2874 CHECK_WINDOW (window
, 0);
2876 /* Look up KEYSEQ in the buffer's local mouse map, then in global one. */
2880 if (!NILP (XWINDOW (window
)->buffer
))
2882 Lisp_Object local_map
;
2884 local_map
= XBUFFER (XWINDOW (window
)->buffer
)->mouse_map
;
2885 tem
= Fkeymapp (local_map
);
2887 mouse_cmd
= Flookup_key (local_map
, keyseq
);
2888 /* A number as value means the key is too long; treat as undefined. */
2889 if (XTYPE (mouse_cmd
) == Lisp_Int
)
2893 tem
= Fkeymapp (Vglobal_mouse_map
);
2894 if (NILP (mouse_cmd
) && !NILP (tem
))
2895 mouse_cmd
= Flookup_key (Vglobal_mouse_map
, keyseq
);
2896 if (XTYPE (mouse_cmd
) == Lisp_Int
)
2899 if (NILP (mouse_cmd
))
2901 /* This button/shift combination is not defined.
2902 If it is a button-down event, ring the bell. */
2904 if (XSTRING (keyseq
)->data
[XSTRING (keyseq
)->size
- 1] & 0x18 == 0)
2906 if (XSTRING (keyseq
)->data
[XSTRING (keyseq
)->size
- 1] & 4 == 0)
2912 SCREEN_PTR s
= XSCREEN (WINDOW_SCREEN (XWINDOW (window
)));
2915 Vmouse_window
= s
->selected_window
;
2916 #endif /* HAVE_X11 */
2917 /* It's defined; call the definition. */
2919 if (!NILP (screen_part
))
2921 /* For a scroll-bar click, set the prefix arg
2922 to the number of lines down from the top the click was.
2923 Many scroll commands want to scroll by this many lines. */
2924 Lisp_Object position
;
2928 position
= Fcar (pos
);
2929 length
= Fcar (Fcdr (pos
));
2930 offset
= Fcar (Fcdr (Fcdr (pos
)));
2932 if (XINT (length
) != 0)
2933 XSET (Vprefix_arg
, Lisp_Int
,
2934 (SCREEN_HEIGHT (s
) * (XINT (position
) + XINT (offset
))
2935 / (XINT (length
) + 2 * XINT (offset
))));
2937 Fcommand_execute (mouse_cmd
, Qnil
);
2940 if (!NILP (Vmouse_event_function
)) /* Not `event' so no need for GCPRO */
2941 call1 (Vmouse_event_function
, Vmouse_event
);
2946 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
2948 "Read function name, then read its arguments and call it.")
2950 Lisp_Object prefixarg
;
2952 Lisp_Object function
;
2954 Lisp_Object saved_keys
;
2955 struct gcpro gcpro1
;
2957 saved_keys
= Fthis_command_keys ();
2959 GCPRO1 (saved_keys
);
2961 if (EQ (prefixarg
, Qminus
))
2963 else if (CONSP (prefixarg
) && XINT (XCONS (prefixarg
)->car
) == 4)
2964 strcpy (buf
, "C-u ");
2965 else if (CONSP (prefixarg
) && XTYPE (XCONS (prefixarg
)->car
) == Lisp_Int
)
2966 sprintf (buf
, "%d ", XINT (XCONS (prefixarg
)->car
));
2967 else if (XTYPE (prefixarg
) == Lisp_Int
)
2968 sprintf (buf
, "%d ", XINT (prefixarg
));
2970 /* This isn't strictly correct if execute-extended-command
2971 is bound to anything else. Perhaps it should use
2972 this_command_keys? */
2973 strcat (buf
, "M-x ");
2975 /* Prompt with buf, and then read a string, completing from and
2976 restricting to the set of all defined commands. Don't provide
2977 any initial input. The last Qnil says not to perform a
2978 peculiar hack on the initial input. */
2979 function
= Fcompleting_read (build_string (buf
),
2980 Vobarray
, Qcommandp
,
2983 /* Add the text read to this_command_keys. */
2985 struct Lisp_String
*func_str
= XSTRING (function
);
2989 for (i
= 0; i
< func_str
->size
; i
++)
2991 XSET (tem
, Lisp_Int
, func_str
->data
[i
]);
2992 add_command_key (tem
);
2998 function
= Fintern (function
, Vobarray
);
2999 Vprefix_arg
= prefixarg
;
3000 this_command
= function
;
3002 return Fcommand_execute (function
, Qt
);
3006 detect_input_pending ()
3009 get_input_pending (&input_pending
);
3011 return input_pending
;
3014 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
3015 "T if command input is currently available with no waiting.\n\
3016 Actually, the value is nil only if we can be sure that no input is available.")
3019 if (!NILP (unread_command_char
))
3022 return detect_input_pending () ? Qt
: Qnil
;
3025 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
3026 "Return vector of last 100 chars read from terminal.")
3031 if (total_keys
< NUM_RECENT_KEYS
)
3032 return Fvector (total_keys
, recent_keys
);
3035 val
= Fvector (NUM_RECENT_KEYS
, recent_keys
);
3036 bcopy (recent_keys
+ recent_keys_index
,
3037 XVECTOR (val
)->contents
,
3038 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
3040 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
3041 recent_keys_index
* sizeof (Lisp_Object
));
3046 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
3047 "Return string of the keystrokes that invoked this command.")
3050 return make_array (this_command_key_count
, this_command_keys
);
3053 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
3054 "Return the current depth in recursive edits.")
3058 XFASTINT (temp
) = command_loop_level
+ minibuf_level
;
3062 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
3063 "FOpen dribble file: ",
3064 "Start writing all keyboard characters to FILE.")
3075 file
= Fexpand_file_name (file
, Qnil
);
3076 dribble
= fopen (XSTRING (file
)->data
, "w");
3081 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
3082 "Discard the contents of the terminal input buffer.\n\
3083 Also cancel any kbd macro being defined.")
3086 defining_kbd_macro
= 0;
3087 update_mode_lines
++;
3090 unread_command_char
= make_number (-1);
3092 unread_command_char
= Qnil
;
3094 discard_tty_input ();
3096 kbd_fetch_ptr
= kbd_store_ptr
;
3102 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
3103 "Stop Emacs and return to superior process. You can resume later.\n\
3104 On systems that don't have job control, run a subshell instead.\n\n\
3105 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
3106 to be read as terminal input by Emacs's superior shell.\n\
3107 Before suspending, if `suspend-hook' is bound and value is non-nil\n\
3108 call the value as a function of no args. Don't suspend if it returns non-nil.\n\
3109 Otherwise, suspend normally and after resumption call\n\
3110 `suspend-resume-hook' if that is bound and non-nil.\n\
3112 Some operating systems cannot stop the Emacs process and resume it later.\n\
3113 On such systems, Emacs will start a subshell and wait for it to exit.")
3115 Lisp_Object stuffstring
;
3117 register Lisp_Object tem
;
3118 int count
= specpdl_ptr
- specpdl
;
3119 int old_height
, old_width
;
3121 struct gcpro gcpro1
;
3122 extern init_sys_modes ();
3124 if (!NILP (stuffstring
))
3125 CHECK_STRING (stuffstring
, 0);
3126 GCPRO1 (stuffstring
);
3128 /* Call value of suspend-hook
3129 if it is bound and value is non-nil. */
3130 if (!NILP (Vrun_hooks
))
3132 tem
= call1 (Vrun_hooks
, intern ("suspend-hook"));
3133 if (!EQ (tem
, Qnil
)) return Qnil
;
3136 get_screen_size (&old_width
, &old_height
);
3138 /* sys_suspend can get an error if it tries to fork a subshell
3139 and the system resources aren't available for that. */
3140 record_unwind_protect (init_sys_modes
, 0);
3141 stuff_buffered_input (stuffstring
);
3143 unbind_to (count
, Qnil
);
3145 /* Check if terminal/window size has changed.
3146 Note that this is not useful when we are running directly
3147 with a window system; but suspend should be disabled in that case. */
3148 get_screen_size (&width
, &height
);
3149 if (width
!= old_width
|| height
!= old_height
)
3150 change_screen_size (height
, width
, 0);
3152 /* Call value of suspend-resume-hook
3153 if it is bound and value is non-nil. */
3154 if (!NILP (Vrun_hooks
))
3155 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
3161 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
3162 Then in any case stuff anthing Emacs has read ahead and not used. */
3164 stuff_buffered_input (stuffstring
)
3165 Lisp_Object stuffstring
;
3167 register unsigned char *p
;
3169 /* stuff_char works only in BSD, versions 4.2 and up. */
3172 if (XTYPE (stuffstring
) == Lisp_String
)
3176 p
= XSTRING (stuffstring
)->data
;
3177 count
= XSTRING (stuffstring
)->size
;
3182 /* Anything we have read ahead, put back for the shell to read. */
3183 while (kbd_fetch_ptr
!= kbd_store_ptr
)
3185 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3186 kbd_fetch_ptr
= kbd_buffer
;
3187 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
3188 stuff_char (XINT (kbd_fetch_ptr
->code
));
3193 #endif /* BSD and not BSD4_1 */
3196 set_waiting_for_input (word_to_clear
)
3197 long *word_to_clear
;
3199 input_available_clear_word
= word_to_clear
;
3201 /* Tell interrupt_signal to throw back to read_char, */
3202 waiting_for_input
= 1;
3204 /* If interrupt_signal was called before and buffered a C-g,
3205 make it run again now, to avoid timing error. */
3206 if (!NILP (Vquit_flag
))
3207 quit_throw_to_read_char ();
3209 /* If alarm has gone off already, echo now. */
3217 clear_waiting_for_input ()
3219 /* Tell interrupt_signal not to throw back to read_char, */
3220 waiting_for_input
= 0;
3221 input_available_clear_word
= 0;
3224 /* This routine is called at interrupt level in response to C-G.
3225 If interrupt_input, this is the handler for SIGINT.
3226 Otherwise, it is called from kbd_buffer_store_event,
3227 in handling SIGIO or SIGTINT.
3229 If `waiting_for_input' is non zero, then unless `echoing' is nonzero,
3230 immediately throw back to read_char.
3232 Otherwise it sets the Lisp variable quit-flag not-nil.
3233 This causes eval to throw, when it gets a chance.
3234 If quit-flag is already non-nil, it stops the job right away. */
3240 /* Must preserve main program's value of errno. */
3241 int old_errno
= errno
;
3242 extern Lisp_Object Vwindow_system
;
3245 /* USG systems forget handlers when they are used;
3246 must reestablish each time */
3247 signal (SIGINT
, interrupt_signal
);
3248 signal (SIGQUIT
, interrupt_signal
);
3253 if (!NILP (Vquit_flag
) && SCREEN_IS_TERMCAP (selected_screen
))
3258 #ifdef SIGTSTP /* Support possible in later USG versions */
3260 * On systems which can suspend the current process and return to the original
3261 * shell, this command causes the user to end up back at the shell.
3262 * The "Auto-save" and "Abort" questions are not asked until
3263 * the user elects to return to emacs, at which point he can save the current
3264 * job and either dump core or continue.
3269 if (sys_suspend () == -1)
3271 printf ("Not running as a subprocess;\n");
3272 printf ("you can continue or abort.\n");
3275 /* Perhaps should really fork an inferior shell?
3276 But that would not provide any way to get back
3277 to the original shell, ever. */
3278 printf ("No support for stopping a process on this operating system;\n");
3279 printf ("you can continue or abort.\n");
3280 #endif /* not VMS */
3281 #endif /* not SIGTSTP */
3282 printf ("Auto-save? (y or n) ");
3284 if (((c
= getchar ()) & ~040) == 'Y')
3285 Fdo_auto_save (Qnil
, Qnil
);
3286 while (c
!= '\n') c
= getchar ();
3288 printf ("Abort (and enter debugger)? (y or n) ");
3290 printf ("Abort (and dump core)? (y or n) ");
3291 #endif /* not VMS */
3293 if (((c
= getchar ()) & ~040) == 'Y')
3295 while (c
!= '\n') c
= getchar ();
3296 printf ("Continuing...\n");
3302 /* If executing a function that wants to be interrupted out of
3303 and the user has not deferred quitting by binding `inhibit-quit'
3304 then quit right away. */
3305 if (immediate_quit
&& NILP (Vinhibit_quit
))
3309 Fsignal (Qquit
, Qnil
);
3312 /* Else request quit when it's safe */
3316 if (waiting_for_input
&& !echoing
)
3317 quit_throw_to_read_char ();
3322 /* Handle a C-g by making read_char return C-g. */
3324 quit_throw_to_read_char ()
3326 quit_error_check ();
3328 /* Prevent another signal from doing this before we finish. */
3329 waiting_for_input
= 0;
3333 unread_command_char
= make_number (-1);
3335 unread_command_char
= Qnil
;
3337 _longjmp (getcjmp
, 1);
3340 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
3341 "Set mode of reading keyboard input.\n\
3342 First arg non-nil means use input interrupts; nil means use CBREAK mode.\n\
3343 Second arg non-nil means use ^S/^Q flow control for output to terminal\n\
3344 (no effect except in CBREAK mode).\n\
3345 Third arg non-nil means accept 8-bit input (for a Meta key).\n\
3346 Otherwise, the top bit is ignored, on the assumption it is parity.\n\
3347 Optional fourth arg non-nil specifies character to use for quitting.")
3348 (interrupt
, flow
, meta
, quit
)
3349 Lisp_Object interrupt
, flow
, meta
, quit
;
3352 && (XTYPE (quit
) != Lisp_Int
3353 || XINT (quit
) < 0 || XINT (quit
) > 0400))
3354 error ("set-input-mode: QUIT must be an ASCII character.");
3358 /* Note SIGIO has been undef'd if FIONREAD is missing. */
3359 #ifdef NO_SOCK_SIGIO
3360 if (read_socket_hook
)
3361 interrupt_input
= 0; /* No interrupts if reading from a socket. */
3363 #endif /* NO_SOCK_SIGIO */
3364 interrupt_input
= !NILP (interrupt
);
3365 #else /* not SIGIO */
3366 interrupt_input
= 0;
3367 #endif /* not SIGIO */
3368 /* Our VMS input only works by interrupts, as of now. */
3370 interrupt_input
= 1;
3372 flow_control
= !NILP (flow
);
3373 meta_key
= !NILP (meta
);
3375 /* Don't let this value be out of range. */
3376 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
3384 this_command_keys_size
= 40;
3386 (Lisp_Object
*) xmalloc (this_command_keys_size
* sizeof (Lisp_Object
));
3388 /* This is correct before outermost invocation of the editor loop */
3389 command_loop_level
= -1;
3391 quit_char
= Ctl ('g');
3392 unread_command_char
= Qnil
;
3393 recent_keys_index
= 0;
3395 kbd_fetch_ptr
= kbd_buffer
;
3396 kbd_store_ptr
= kbd_buffer
;
3397 do_mouse_tracking
= 0;
3400 if (!noninteractive
)
3402 signal (SIGINT
, interrupt_signal
);
3404 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
3405 SIGQUIT and we can't tell which one it will give us. */
3406 signal (SIGQUIT
, interrupt_signal
);
3407 #endif /* HAVE_TERMIO */
3408 /* Note SIGIO has been undef'd if FIONREAD is missing. */
3410 signal (SIGIO
, input_available_signal
);
3414 /* Use interrupt input by default, if it works and noninterrupt input
3415 has deficiencies. */
3417 #ifdef INTERRUPT_INPUT
3418 interrupt_input
= 1;
3420 interrupt_input
= 0;
3423 /* Our VMS input only works by interrupts, as of now. */
3425 interrupt_input
= 1;
3431 if (keyboard_init_hook
)
3432 (*keyboard_init_hook
) ();
3434 #ifdef POLL_FOR_INPUT
3435 poll_suppress_count
= 1;
3440 /* This type's only use is in syms_of_keyboard, to initialize the
3441 event header symbols and put properties on them. */
3448 struct event_head head_table
[] = {
3449 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
3450 &Qvscrollbar_part
, "vscrollbar-part", &Qscrollbar_click
,
3451 &Qvslider_part
, "vslider-part", &Qscrollbar_click
,
3452 &Qvthumbup_part
, "vthumbup-part", &Qscrollbar_click
,
3453 &Qvthumbdown_part
, "vthumbdown-part", &Qscrollbar_click
,
3454 &Qhscrollbar_part
, "hscrollbar-part", &Qscrollbar_click
,
3455 &Qhslider_part
, "hslider-part", &Qscrollbar_click
,
3456 &Qhthumbleft_part
, "hthumbleft-part", &Qscrollbar_click
,
3457 &Qhthumbright_part
,"hthumbright-part", &Qscrollbar_click
3462 Qself_insert_command
= intern ("self-insert-command");
3463 staticpro (&Qself_insert_command
);
3465 Qforward_char
= intern ("forward-char");
3466 staticpro (&Qforward_char
);
3468 Qbackward_char
= intern ("backward-char");
3469 staticpro (&Qbackward_char
);
3471 Qdisabled
= intern ("disabled");
3472 staticpro (&Qdisabled
);
3474 Qfunction_key
= intern ("function-key");
3475 staticpro (&Qfunction_key
);
3476 Qmouse_movement
= intern ("mouse-click");
3477 staticpro (&Qmouse_click
);
3478 Qmouse_movement
= intern ("scrollbar-click");
3479 staticpro (&Qmouse_movement
);
3481 Qmode_line
= intern ("mode-line");
3482 staticpro (&Qmode_line
);
3483 Qvertical_split
= intern ("vertical-split");
3484 staticpro (&Qvertical_split
);
3486 Qevent_kind
= intern ("event-type");
3487 staticpro (&Qevent_kind
);
3488 Qevent_unmodified
= intern ("event-unmodified");
3489 staticpro (&Qevent_unmodified
);
3492 struct event_head
*p
;
3494 for (p
= head_table
;
3495 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
3498 *p
->var
= intern (p
->name
);
3500 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
3501 Fput (*p
->var
, Qevent_unmodified
, *p
->var
);
3505 func_key_syms
= Qnil
;
3506 staticpro (&func_key_syms
);
3509 staticpro (&mouse_syms
);
3511 defsubr (&Sread_key_sequence
);
3512 defsubr (&Srecursive_edit
);
3513 defsubr (&Strack_mouse
);
3514 defsubr (&Smouse_click_p
);
3515 defsubr (&Sinput_pending_p
);
3516 defsubr (&Scommand_execute
);
3517 defsubr (&Srecent_keys
);
3518 defsubr (&Sthis_command_keys
);
3519 defsubr (&Ssuspend_emacs
);
3520 defsubr (&Sabort_recursive_edit
);
3521 defsubr (&Sexit_recursive_edit
);
3522 defsubr (&Srecursion_depth
);
3523 defsubr (&Stop_level
);
3524 defsubr (&Sdiscard_input
);
3525 defsubr (&Sopen_dribble_file
);
3526 defsubr (&Sset_input_mode
);
3527 defsubr (&Sexecute_extended_command
);
3529 DEFVAR_LISP ("disabled-command-hook", &Vdisabled_command_hook
,
3530 "Value is called instead of any command that is disabled\n\
3531 (has a non-nil `disabled' property).");
3533 DEFVAR_LISP ("last-command-char", &last_command_char
,
3534 "Last terminal input key that was part of a command.");
3536 DEFVAR_LISP ("last-input-char", &last_input_char
,
3537 "Last terminal input key.");
3539 DEFVAR_LISP ("unread-command-char", &unread_command_char
,
3540 "Object to be read as next input from input stream, or nil if none.");
3542 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
3543 "Meta-prefix character code. Meta-foo as command input\n\
3544 turns into this character followed by foo.");
3545 XSET (meta_prefix_char
, Lisp_Int
, 033);
3547 DEFVAR_LISP ("last-command", &last_command
,
3548 "The last command executed. Normally a symbol with a function definition,\n\
3549 but can be whatever was found in the keymap, or whatever the variable\n\
3550 `this-command' was set to by that command.");
3551 last_command
= Qnil
;
3553 DEFVAR_LISP ("this-command", &this_command
,
3554 "The command now being executed.\n\
3555 The command can set this variable; whatever is put here\n\
3556 will be in `last-command' during the following command.");
3557 this_command
= Qnil
;
3559 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
3560 "*Number of keyboard input characters between auto-saves.\n\
3561 Zero means disable autosaving due to number of characters typed.");
3562 auto_save_interval
= 300;
3564 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
3565 "*Number of seconds idle time before auto-save.\n\
3566 Zero or nil means disable auto-saving due to idleness.");
3567 XFASTINT (Vauto_save_timeout
) = 30;
3569 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes
,
3570 "*Nonzero means echo unfinished commands after this many seconds of pause.");
3571 echo_keystrokes
= 1;
3573 DEFVAR_INT ("polling-period", &polling_period
,
3574 "*Interval between polling for input during Lisp execution.\n\
3575 The reason for polling is to make C-g work to stop a running program.\n\
3576 Polling is needed only when using X windows and SIGIO does not work.\n\
3577 Polling is automatically disabled in all other cases.");
3580 DEFVAR_INT ("num-input-keys", &num_input_keys
,
3581 "*Number of complete keys read from the keyboard so far.");
3584 DEFVAR_LISP ("last-event-screen", &Vlast_event_screen
,
3585 "*The screen in which the most recently read event occurred.");
3586 Vlast_event_screen
= Qnil
;
3588 DEFVAR_LISP ("help-char", &help_char
,
3589 "Character to recognize as meaning Help.\n\
3590 When it is read, do `(eval help-form)', and display result if it's a string.\n\
3591 If the value of `help-form' is nil, this char can be read normally.");
3592 XSET (help_char
, Lisp_Int
, Ctl ('H'));
3594 DEFVAR_LISP ("help-form", &Vhelp_form
,
3595 "Form to execute when character help-char is read.\n\
3596 If the form returns a string, that string is displayed.\n\
3597 If `help-form' is nil, the help char is not recognized.");
3600 DEFVAR_LISP ("top-level", &Vtop_level
,
3601 "Form to evaluate when Emacs starts up.\n\
3602 Useful to set before you dump a modified Emacs.");
3605 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
3606 "String used as translate table for keyboard input, or nil.\n\
3607 Each character is looked up in this string and the contents used instead.\n\
3608 If string is of length N, character codes N and up are untranslated.");
3609 Vkeyboard_translate_table
= Qnil
;
3611 #ifdef HAVE_X_WINDOWS
3612 DEFVAR_LISP ("mouse-event-function", &Vmouse_event_function
,
3613 "Function to call for each mouse event, after the event's definition.\n\
3614 Called, if non-nil, with one argument, which is the event-list.\n\
3615 See the variable `mouse-event' for the format of this list.");
3616 Vmouse_event_function
= Qnil
;
3618 DEFVAR_LISP ("mouse-left-hook", &Vmouse_left_hook
,
3619 "Function to call when mouse leaves window. No arguments.");
3620 Vmouse_left_hook
= Qnil
;
3622 DEFVAR_LISP ("map-screen-hook", &Vmap_screen_hook
,
3623 "Function to call when screen is mapped. No arguments.");
3624 Vmap_screen_hook
= Qnil
;
3626 DEFVAR_LISP ("unmap-screen-hook", &Vunmap_screen_hook
,
3627 "Function to call when screen is unmapped. No arguments.");
3628 Vunmap_screen_hook
= Qnil
;
3630 DEFVAR_LISP ("mouse-motion-handler", &Vmouse_motion_handler
,
3631 "Handler for motion events. No arguments.");
3632 Vmouse_motion_handler
= Qnil
;
3635 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
3636 "Non-nil means prompt with menus in echo area when appropriate.\n\
3637 This is done when reading from a keymap that has a prompt string,\n\
3638 for elements that have prompt strings.");
3641 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
3642 "Character to see next line of menu prompt.\n\
3643 Type this character while in a menu prompt to rotate around the lines of it.");
3644 XSET (menu_prompt_more_char
, Lisp_Int
, ' ');
3649 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
3650 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
3651 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
3652 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
3653 initial_define_key (meta_map
, 'x', "execute-extended-command");