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 frame. */
195 Lisp_Object Vmouse_left_hook
;
197 /* Hook to call when a frame is mapped. */
198 Lisp_Object Vmap_frame_hook
;
200 /* Hook to call when a frame is unmapped. */
201 Lisp_Object Vunmap_frame_hook
;
203 /* Handler for non-grabbed (no keys depressed) mouse motion. */
204 Lisp_Object Vmouse_motion_handler
;
206 /* The frame in which the last input event occurred.
207 command_loop_1 will select this frame 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_frame
;
213 /* The timestamp of the last input event we received from the X server.
214 X Windows wants this for selection ownership. */
215 unsigned long last_event_timestamp
;
217 Lisp_Object Qself_insert_command
;
218 Lisp_Object Qforward_char
;
219 Lisp_Object Qbackward_char
;
221 /* read_key_sequence stores here the command definition of the
222 key sequence that it reads. */
223 Lisp_Object read_key_sequence_cmd
;
225 /* Form to evaluate (if non-nil) when Emacs is started. */
226 Lisp_Object Vtop_level
;
228 /* User-supplied string to translate input characters through. */
229 Lisp_Object Vkeyboard_translate_table
;
231 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
232 extern Lisp_Object Vfunction_key_map
;
234 /* File in which we write all commands we read. */
237 /* Nonzero if input is available. */
240 /* Nonzero if should obey 0200 bit in input chars as "Meta". */
243 extern char *pending_malloc_warning
;
245 /* Circular buffer for pre-read keyboard input. */
246 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
248 /* Pointer to next available character in kbd_buffer.
249 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
250 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the
251 next available char is in kbd_buffer[0]. */
252 static struct input_event
*kbd_fetch_ptr
;
254 /* Pointer to next place to store character in kbd_buffer. This
255 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
256 character should go in kbd_buffer[0]. */
257 static struct input_event
*kbd_store_ptr
;
259 /* The above pair of variables forms a "queue empty" flag. When we
260 enqueue a non-hook event, we increment kbd_write_count. When we
261 dequeue a non-hook event, we increment kbd_read_count. We say that
262 there is input available iff the two counters are equal.
264 Why not just have a flag set and cleared by the enqueuing and
265 dequeuing functions? Such a flag could be screwed up by interrupts
266 at inopportune times. */
268 /* If this flag is non-zero, mouse movement events will appear in the
269 input stream. If is zero, mouse movement will be ignored. */
270 int do_mouse_tracking
;
272 /* The window system handling code should set this if the mouse has
273 moved since the last call to the mouse_position_hook. Calling that
274 hook should clear this. Code assumes that if this is set, it can
275 call mouse_position_hook to get the promised position, so don't set
276 it unless you're prepared to substantiate the claim! */
279 /* True iff there is an event in kbd_buffer, or if mouse tracking is
280 enabled and there is a new mouse position in the mouse movement
281 buffer. Note that if this is false, that doesn't mean that there
282 is readable input; all the events in the queue might be button-up
283 events, and do_mouse_tracking might be off. */
284 #define EVENT_QUEUES_EMPTY \
285 ((kbd_fetch_ptr == kbd_store_ptr) && (!do_mouse_tracking || !mouse_moved))
288 /* Symbols to head events. */
289 Lisp_Object Qmouse_movement
;
291 Lisp_Object Qvscrollbar_part
;
292 Lisp_Object Qvslider_part
;
293 Lisp_Object Qvthumbup_part
;
294 Lisp_Object Qvthumbdown_part
;
296 Lisp_Object Qhscrollbar_part
;
297 Lisp_Object Qhslider_part
;
298 Lisp_Object Qhthumbleft_part
;
299 Lisp_Object Qhthumbright_part
;
301 /* Symbols to denote kinds of events. */
302 Lisp_Object Qfunction_key
;
303 Lisp_Object Qmouse_click
;
304 /* Lisp_Object Qmouse_movement; - also an event header */
305 Lisp_Object Qscrollbar_click
;
307 /* Properties of event headers. */
308 Lisp_Object Qevent_kind
;
309 Lisp_Object Qevent_unmodified
;
311 /* Symbols to use for non-text mouse positions. */
312 Lisp_Object Qmode_line
;
313 Lisp_Object Qvertical_line
;
316 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
318 EMACS_TIME
*input_available_clear_time
;
320 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
321 Default is 1 if INTERRUPT_INPUT is defined. */
324 /* Nonzero while interrupts are temporarily deferred during redisplay. */
325 int interrupts_deferred
;
327 /* nonzero means use ^S/^Q for flow control. */
330 /* Allow m- file to inhibit use of FIONREAD. */
331 #ifdef BROKEN_FIONREAD
335 /* We are unable to use interrupts if FIONREAD is not available,
336 so flush SIGIO so we won't try. */
343 /* If we support X Windows, and won't get an interrupt when input
344 arrives from the server, poll periodically so we can detect C-g. */
345 #ifdef HAVE_X_WINDOWS
347 #define POLL_FOR_INPUT
351 /* Global variable declarations. */
353 /* Function for init_keyboard to call with no args (if nonzero). */
354 void (*keyboard_init_hook
) ();
356 static int read_avail_input ();
357 static void get_input_pending ();
359 /* > 0 if we are to echo keystrokes. */
360 static int echo_keystrokes
;
362 /* Nonzero means echo each character as typed. */
363 static int immediate_echo
;
365 /* The text we're echoing in the modeline - partial key sequences,
366 usually. '\0'-terminated. */
367 static char echobuf
[100];
369 /* Where to append more text to echobuf if we want to. */
370 static char *echoptr
;
372 #define min(a,b) ((a)<(b)?(a):(b))
373 #define max(a,b) ((a)>(b)?(a):(b))
375 /* Install the string STR as the beginning of the string of echoing,
376 so that it serves as a prompt for the next character.
377 Also start echoing. */
382 int len
= strlen (str
);
383 if (len
> sizeof echobuf
- 4)
384 len
= sizeof echobuf
- 4;
385 bcopy (str
, echobuf
, len
+ 1);
386 echoptr
= echobuf
+ len
;
391 /* Add C to the echo string, if echoing is going on.
392 C can be a character, which is printed prettily ("M-C-x" and all that
393 jazz), or a symbol, whose name is printed. */
398 extern char *push_key_description ();
407 /* If someone has passed us a composite event, use its head symbol. */
408 if (EVENT_HAS_PARAMETERS (c
))
411 if (XTYPE (c
) == Lisp_Int
)
413 if (ptr
- echobuf
> sizeof echobuf
- 6)
416 ptr
= push_key_description (c
, ptr
);
418 else if (XTYPE (c
) == Lisp_Symbol
)
420 struct Lisp_String
*name
= XSYMBOL (c
)->name
;
421 if (((ptr
- echobuf
) + name
->size
+ 4) > sizeof echobuf
)
423 bcopy (name
->data
, ptr
, name
->size
);
427 if (echoptr
== echobuf
&& c
== help_char
)
429 strcpy (ptr
, " (Type ? for further options)");
440 /* Temporarily add a dash to the end of the echo string if it's not
441 empty, so that it serves as a mini-prompt for the very next character. */
445 if (!immediate_echo
&& echoptr
== echobuf
)
448 /* Put a dash at the end of the buffer temporarily,
449 but make it go away when the next character is added. */
456 /* Display the current echo string, and begin echoing if not already
466 for (i
= 0; i
< this_command_key_count
; i
++)
467 echo_char (this_command_keys
[i
]);
475 if (waiting_for_input
&& !NILP (Vquit_flag
))
476 quit_throw_to_read_char ();
479 /* Turn off echoing, for the start of a new command. */
487 /* Return the length of the current echo string. */
492 return echoptr
- echobuf
;
495 /* Truncate the current echo message to its first LEN chars.
496 This and echo_char get used by read_key_sequence when the user
497 switches frames while entering a key sequence. */
504 echoptr
= echobuf
+ strlen (echobuf
);
508 /* Functions for manipulating this_command_keys. */
510 add_command_key (key
)
513 if (this_command_key_count
== this_command_keys_size
)
515 this_command_keys_size
*= 2;
517 = (Lisp_Object
*) xrealloc (this_command_keys
,
518 (this_command_keys_size
519 * sizeof (Lisp_Object
)));
521 this_command_keys
[this_command_key_count
++] = key
;
527 int count
= specpdl_ptr
- specpdl
;
530 if (command_loop_level
> 0)
532 specbind (Qstandard_output
, Qt
);
533 specbind (Qstandard_input
, Qt
);
536 val
= command_loop ();
538 Fsignal (Qquit
, Qnil
);
544 /* When an auto-save happens, record the "time", and don't do again soon. */
547 last_auto_save
= num_input_chars
;
550 Lisp_Object
recursive_edit_unwind (), command_loop ();
552 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
553 "Invoke the editor command loop recursively.\n\
554 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
555 that tells this function to return.\n\
556 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
557 This function is called by the editor initialization to begin editing.")
560 int count
= specpdl_ptr
- specpdl
;
563 command_loop_level
++;
564 update_mode_lines
= 1;
566 record_unwind_protect (recursive_edit_unwind
,
568 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
572 return unbind_to (count
, Qnil
);
576 recursive_edit_unwind (buffer
)
580 Fset_buffer (buffer
);
582 command_loop_level
--;
583 update_mode_lines
= 1;
591 Lisp_Object errmsg
, tail
, errname
, file_error
;
598 Vstandard_output
= Qt
;
599 Vstandard_input
= Qt
;
600 Vexecuting_macro
= Qnil
;
601 echo_area_glyphs
= 0;
603 /* If the window system or terminal frame hasn't been initialized
604 yet, or we're not interactive, it's best to dump this message out
605 to stderr and exit. */
606 if (! FRAME_MESSAGE_BUF (selected_frame
)
608 stream
= Qexternal_debugging_output
;
616 errname
= Fcar (data
);
618 if (EQ (errname
, Qerror
))
621 if (!CONSP (data
)) data
= Qnil
;
622 errmsg
= Fcar (data
);
627 errmsg
= Fget (errname
, Qerror_message
);
628 file_error
= Fmemq (Qfile_error
,
629 Fget (errname
, Qerror_conditions
));
632 /* Print an error message including the data items.
633 This is done by printing it into a scratch buffer
634 and then making a copy of the text in the buffer. */
636 if (!CONSP (data
)) data
= Qnil
;
640 /* For file-error, make error message by concatenating
641 all the data items. They are all strings. */
642 if (!NILP (file_error
) && !NILP (tail
))
643 errmsg
= XCONS (tail
)->car
, tail
= XCONS (tail
)->cdr
;
645 if (XTYPE (errmsg
) == Lisp_String
)
646 Fprinc (errmsg
, stream
);
648 write_string_1 ("peculiar error", -1, stream
);
650 for (i
= 0; CONSP (tail
); tail
= Fcdr (tail
), i
++)
652 write_string_1 (i
? ", " : ": ", 2, stream
);
653 if (!NILP (file_error
))
654 Fprinc (Fcar (tail
), stream
);
656 Fprin1 (Fcar (tail
), stream
);
660 /* If the window system or terminal frame hasn't been initialized
661 yet, or we're in -batch mode, this error should cause Emacs to exit. */
662 if (! FRAME_MESSAGE_BUF (selected_frame
)
666 Fkill_emacs (make_number (-1));
671 Vinhibit_quit
= Qnil
;
672 return make_number (0);
675 Lisp_Object
command_loop_1 ();
676 Lisp_Object
command_loop_2 ();
677 Lisp_Object
top_level_1 ();
679 /* Entry to editor-command-loop.
680 This level has the catches for exiting/returning to editor command loop.
681 It returns nil to exit recursive edit, t to abort it. */
686 if (command_loop_level
> 0 || minibuf_level
> 0)
688 return internal_catch (Qexit
, command_loop_2
, Qnil
);
693 internal_catch (Qtop_level
, top_level_1
, Qnil
);
694 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
696 /* End of file in -batch run causes exit here. */
702 /* Here we catch errors in execution of commands within the
703 editing loop, and reenter the editing loop.
704 When there is an error, cmd_error runs and returns a non-nil
705 value to us. A value of nil means that cmd_loop_1 itself
706 returned due to end of file (or end of kbd macro). */
711 register Lisp_Object val
;
714 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
723 return Feval (Vtop_level
);
729 /* On entry to the outer level, run the startup file */
730 if (!NILP (Vtop_level
))
731 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
732 else if (!NILP (Vpurify_flag
))
733 message ("Bare impure Emacs (standard Lisp code not loaded)");
735 message ("Bare Emacs (standard Lisp code not loaded)");
739 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
740 "Exit all recursive editing levels.")
743 Fthrow (Qtop_level
, Qnil
);
746 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
747 "Exit from the innermost recursive edit or minibuffer.")
750 if (command_loop_level
> 0 || minibuf_level
> 0)
751 Fthrow (Qexit
, Qnil
);
753 error ("No recursive edit is in progress");
756 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
757 "Abort the command that requested this recursive edit or minibuffer input.")
760 if (command_loop_level
> 0 || minibuf_level
> 0)
763 error ("No recursive edit is in progress");
766 /* This is the actual command reading loop,
767 sans error-handling encapsulation. */
769 Lisp_Object
Fcommand_execute ();
770 static int read_key_sequence ();
778 Lisp_Object keybuf
[30];
784 waiting_for_input
= 0;
787 /* Don't clear out last_command at the beginning of a macro. */
788 if (XTYPE (Vexecuting_macro
) != Lisp_String
)
793 this_command_key_count
= 0;
797 /* Install chars successfully executed in kbd macro. */
799 if (defining_kbd_macro
&& NILP (Vprefix_arg
))
800 finalize_kbd_macro_chars ();
802 /* Make sure the current window's buffer is selected. */
803 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
804 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
806 /* Display any malloc warning that just came out. Use while because
807 displaying one warning can cause another. */
809 while (pending_malloc_warning
)
810 display_malloc_warning ();
814 /* If minibuffer on and echo area in use,
815 wait 2 sec and redraw minibufer. */
817 if (minibuf_level
&& echo_area_glyphs
)
819 Fsit_for (make_number (2), Qnil
, Qnil
);
820 echo_area_glyphs
= 0;
822 if (!NILP (Vquit_flag
))
825 unread_command_char
= make_number (quit_char
);
830 alloca (0); /* Cause a garbage collection now */
831 /* Since we can free the most stuff here. */
832 #endif /* C_ALLOCA */
834 /* Read next key sequence; i gets its length. */
835 i
= read_key_sequence (keybuf
, (sizeof keybuf
/ sizeof (keybuf
[0])), 0);
840 /* Select the frame that the key sequence came from. */
841 if (XTYPE (Vlast_event_frame
) == Lisp_Frame
842 && XFRAME (Vlast_event_frame
) != selected_frame
)
843 Fselect_frame (Vlast_event_frame
, Qnil
);
846 /* Now we have read a key sequence of length I,
847 or else I is 0 and we found end of file. */
849 if (i
== 0) /* End of file -- happens only in */
850 return Qnil
; /* a kbd macro, at the end. */
853 #ifdef HAVE_X_WINDOWS
854 if (FRAME_IS_X (selected_frame
))
856 if (i
== -1) /* Mouse event */
859 if (NILP (Vprefix_arg
) && NILP (Vexecuting_macro
) &&
860 !EQ (minibuf_window
, selected_window
))
863 if (defining_kbd_macro
)
865 /* Be nice if this worked... */
867 Fexecute_mouse_event (read_key_sequence_cmd
);
872 if (i
== -2) /* Lisp Symbol */
875 if (NILP (Vprefix_arg
) && NILP (Vexecuting_macro
) &&
876 !EQ (minibuf_window
, selected_window
))
882 #endif /* HAVE_X_WINDOWS */
885 last_command_char
= keybuf
[i
- 1];
887 cmd
= read_key_sequence_cmd
;
888 if (!NILP (Vexecuting_macro
))
890 if (!NILP (Vquit_flag
))
892 Vexecuting_macro
= Qt
;
893 QUIT
; /* Make some noise. */
894 /* Will return since macro now empty. */
898 /* Do redisplay processing after this command except in special
899 cases identified below that set no_redisplay to 1. */
902 /* Execute the command. */
906 /* nil means key is undefined. */
908 defining_kbd_macro
= 0;
909 update_mode_lines
= 1;
915 if (NILP (Vprefix_arg
) && ! no_direct
)
917 /* Recognize some common commands in common situations and
919 if (EQ (cmd
, Qforward_char
) && point
< ZV
)
921 struct Lisp_Vector
*dp
922 = window_display_table (XWINDOW (selected_window
));
923 lose
= FETCH_CHAR (point
);
925 if (((dp
== 0 && lose
>= 040 && lose
< 0177)
927 (dp
&& (XTYPE (dp
->contents
[lose
]) != Lisp_String
928 || XSTRING (dp
->contents
[lose
])->size
== sizeof (GLYPH
))))
929 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
931 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
933 && !windows_or_buffers_changed
934 && EQ (current_buffer
->selective_display
, Qnil
)
935 && !detect_input_pending ()
936 && NILP (Vexecuting_macro
))
937 no_redisplay
= direct_output_forward_char (1);
940 else if (EQ (cmd
, Qbackward_char
) && point
> BEGV
)
942 struct Lisp_Vector
*dp
943 = window_display_table (XWINDOW (selected_window
));
945 lose
= FETCH_CHAR (point
);
946 if (((dp
== 0 && lose
>= 040 && lose
< 0177)
948 (dp
&& (XTYPE (dp
->contents
[lose
]) != Lisp_String
949 || XSTRING (dp
->contents
[lose
])->size
== sizeof (GLYPH
))))
950 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
952 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
954 && !windows_or_buffers_changed
955 && EQ (current_buffer
->selective_display
, Qnil
)
956 && !detect_input_pending ()
957 && NILP (Vexecuting_macro
))
958 no_redisplay
= direct_output_forward_char (-1);
961 else if (EQ (cmd
, Qself_insert_command
)
962 /* Try this optimization only on ascii keystrokes. */
963 && XTYPE (last_command_char
) == Lisp_Int
)
965 unsigned char c
= XINT (last_command_char
);
967 if (NILP (Vexecuting_macro
) &&
968 !EQ (minibuf_window
, selected_window
))
970 if (!nonundocount
|| nonundocount
>= 20)
977 lose
= (XFASTINT (XWINDOW (selected_window
)->last_modified
)
979 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
981 || MODIFF
<= current_buffer
->save_modified
982 || windows_or_buffers_changed
983 || !EQ (current_buffer
->selective_display
, Qnil
)
984 || detect_input_pending ()
985 || !NILP (Vexecuting_macro
);
986 if (internal_self_insert (c
, 0))
992 (point
== ZV
|| FETCH_CHAR (point
) == '\n'))
994 struct Lisp_Vector
*dp
995 = window_display_table (XWINDOW (selected_window
));
997 if (dp
== 0 || XTYPE (dp
->contents
[c
]) != Lisp_String
)
998 no_redisplay
= direct_output_for_insert (c
);
999 else if (XSTRING (dp
->contents
[c
])->size
1002 direct_output_for_insert (*(GLYPH
*)XSTRING (dp
->contents
[c
])->data
);
1008 /* Here for a command that isn't executed directly */
1011 if (NILP (Vprefix_arg
))
1013 Fcommand_execute (cmd
, Qnil
);
1018 /* If there is a prefix argument,
1019 1) We don't want last_command to be ``universal-argument''
1020 (that would be dumb), so don't set last_command,
1021 2) we want to leave echoing on so that the prefix will be
1022 echoed as part of this key sequence, so don't call
1024 3) we want to leave this_command_key_count non-zero, so that
1025 read_char will realize that it is re-reading a character, and
1026 not echo it a second time. */
1027 if (NILP (Vprefix_arg
))
1029 last_command
= this_command
;
1031 this_command_key_count
= 0;
1036 /* Number of seconds between polling for input. */
1039 /* Nonzero means polling for input is temporarily suppresed. */
1040 int poll_suppress_count
;
1042 #ifdef POLL_FOR_INPUT
1043 int polling_for_input
;
1045 /* Handle an alarm once each second and read pending input
1046 so as to handle a C-g if it comces in. */
1049 input_poll_signal ()
1051 #ifdef HAVE_X_WINDOWS
1052 extern int x_input_blocked
;
1053 if (x_input_blocked
== 0)
1055 if (!waiting_for_input
)
1056 read_avail_input (0);
1057 signal (SIGALRM
, input_poll_signal
);
1058 alarm (polling_period
);
1063 /* Begin signals to poll for input, if they are appropriate.
1064 This function is called unconditionally from various places. */
1068 #ifdef POLL_FOR_INPUT
1069 if (read_socket_hook
)
1071 poll_suppress_count
--;
1072 if (poll_suppress_count
== 0)
1074 signal (SIGALRM
, input_poll_signal
);
1075 polling_for_input
= 1;
1076 alarm (polling_period
);
1082 /* Turn off polling. */
1086 #ifdef POLL_FOR_INPUT
1087 if (read_socket_hook
)
1089 if (poll_suppress_count
== 0)
1091 polling_for_input
= 0;
1094 poll_suppress_count
++;
1099 /* Input of single characters from keyboard */
1101 Lisp_Object
print_help ();
1102 static Lisp_Object
kbd_buffer_get_event ();
1104 /* read a character from the keyboard; call the redisplay if needed */
1105 /* commandflag 0 means do not do auto-saving, but do do redisplay.
1106 -1 means do not do redisplay, but do do autosaving.
1110 read_char (commandflag
)
1113 register Lisp_Object c
;
1117 if (!NILP (unread_command_char
))
1119 c
= unread_command_char
;
1120 unread_command_char
= Qnil
;
1122 #if 0 /* We're not handling mouse keys specially anymore. */
1123 if (!EQ (XTYPE (obj
), Lisp_Int
)) /* Mouse thing */
1126 last_input_char
= 0;
1131 if (this_command_key_count
== 0)
1137 if (!NILP (Vexecuting_macro
))
1139 if (executing_macro_index
>= Flength (Vexecuting_macro
))
1141 XSET (c
, Lisp_Int
, -1);
1145 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
1146 executing_macro_index
++;
1151 /* Save outer setjmp data, in case called recursively. */
1152 save_getcjmp (save_jump
);
1156 if (commandflag
>= 0 && !input_pending
&& !detect_input_pending ())
1159 if (_setjmp (getcjmp
))
1161 XSET (c
, Lisp_Int
, quit_char
);
1163 XSET (Vlast_event_frame
, Lisp_Frame
, selected_frame
);
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
= sit_for (echo_keystrokes
, 0, 1, 1);
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
= sit_for (delay
, 0, 1, 1);
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 restore_getcjmp (save_jump
);
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 frame */
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 frame_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', mouse motion and button releases generate input\n\
1456 events that you can read with `read-event'.\n\
1457 Normally, these occurrences don't generate events.")
1461 int count
= specpdl_ptr
- specpdl
;
1464 XSET (val
, Lisp_Int
, do_mouse_tracking
);
1465 record_unwind_protect (tracking_off
, val
);
1467 do_mouse_tracking
= 1;
1469 val
= Fprogn (args
);
1470 return unbind_to (count
, val
);
1473 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
1476 kbd_buffer_store_event (event
)
1477 register struct input_event
*event
;
1479 if (event
->kind
== no_event
)
1482 if (event
->kind
== ascii_keystroke
)
1484 register int c
= XFASTINT (event
->code
) & 0377;
1487 || ((c
== (0200 | quit_char
)) && !meta_key
))
1489 /* If this results in a quit_char being returned to Emacs as
1490 input, set last-event-frame properly. If this doesn't
1491 get returned to Emacs as an event, the next event read
1492 will set Vlast_event_frame again, so this is safe to do. */
1493 extern SIGTYPE
interrupt_signal ();
1494 Vlast_event_frame
= FRAME_FOCUS_FRAME (event
->frame
);
1495 last_event_timestamp
= event
->timestamp
;
1496 interrupt_signal ();
1500 if (c
&& c
== stop_character
)
1506 XSET (event
->code
, Lisp_Int
, c
);
1509 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
1510 kbd_store_ptr
= kbd_buffer
;
1512 /* Don't let the very last slot in the buffer become full,
1513 since that would make the two pointers equal,
1514 and that is indistinguishable from an empty buffer.
1515 Discard the event if it would fill the last slot. */
1516 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
1518 kbd_store_ptr
->kind
= event
->kind
;
1519 kbd_store_ptr
->code
= event
->code
;
1520 kbd_store_ptr
->part
= event
->part
;
1521 kbd_store_ptr
->frame
= event
->frame
;
1522 kbd_store_ptr
->modifiers
= event
->modifiers
;
1523 kbd_store_ptr
->x
= event
->x
;
1524 kbd_store_ptr
->y
= event
->y
;
1525 kbd_store_ptr
->timestamp
= event
->timestamp
;
1531 static Lisp_Object
make_lispy_event ();
1532 static Lisp_Object
make_lispy_movement ();
1533 static Lisp_Object
modify_event_symbol ();
1536 kbd_buffer_get_event ()
1544 XSET (obj
, Lisp_Int
, c
);
1548 /* Wait until there is input available. */
1552 /* Process or toss any events that we don't want to return as
1553 input. The fact that we remove undesirable events here
1554 allows us to use EVENT_QUEUES_EMPTY in the rest of this loop. */
1555 if (! do_mouse_tracking
)
1556 while (kbd_fetch_ptr
!= kbd_store_ptr
)
1558 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
1559 kbd_fetch_ptr
= kbd_buffer
;
1561 if (kbd_fetch_ptr
->kind
== mouse_click
1562 || kbd_fetch_ptr
->kind
== scrollbar_click
)
1564 if ((kbd_fetch_ptr
->modifiers
& up_modifier
) == 0)
1573 if (!EVENT_QUEUES_EMPTY
)
1576 /* If the quit flag is set, then read_char will return
1577 quit_char, so that counts as "available input." */
1578 if (!NILP (Vquit_flag
))
1579 quit_throw_to_read_char ();
1581 /* One way or another, wait until input is available; then, if
1582 interrupt handlers have not read it, read it now. */
1585 wait_for_kbd_input ();
1587 /* Note SIGIO has been undef'd if FIONREAD is missing. */
1591 if (EVENT_QUEUES_EMPTY
)
1593 Lisp_Object minus_one
;
1595 XSET (minus_one
, Lisp_Int
, -1);
1596 wait_reading_process_input (0, 0, minus_one
, 1);
1598 if (!interrupt_input
&& EVENT_QUEUES_EMPTY
)
1600 read_avail_input (0);
1603 #endif /* not VMS */
1606 /* At this point, we know that there is a readable event available
1607 somewhere. If the event queue is empty, then there must be a
1608 mouse movement enabled and available. */
1609 if (kbd_fetch_ptr
!= kbd_store_ptr
)
1611 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
1612 kbd_fetch_ptr
= kbd_buffer
;
1613 /* Do the redirection specified by the focus_frame
1614 member now, before we return this event. */
1615 kbd_fetch_ptr
->frame
=
1616 XFRAME (FRAME_FOCUS_FRAME (kbd_fetch_ptr
->frame
));
1617 XSET (Vlast_event_frame
, Lisp_Frame
, kbd_fetch_ptr
->frame
);
1618 last_event_timestamp
= kbd_fetch_ptr
->timestamp
;
1619 obj
= make_lispy_event (kbd_fetch_ptr
);
1620 kbd_fetch_ptr
->kind
= no_event
;
1622 if (XTYPE (obj
) == Lisp_Int
)
1623 XSET (obj
, Lisp_Int
, XINT (obj
) & (meta_key
? 0377 : 0177));
1625 else if (do_mouse_tracking
&& mouse_moved
)
1631 (*mouse_position_hook
) (&frame
, &x
, &y
, &time
);
1632 XSET (Vlast_event_frame
, Lisp_Frame
, frame
);
1634 obj
= make_lispy_movement (frame
, x
, y
, time
);
1637 /* We were promised by the above while loop that there was
1638 something for us to read! */
1641 input_pending
= readable_events ();
1646 /* Caches for modify_event_symbol. */
1647 static Lisp_Object func_key_syms
;
1648 static Lisp_Object mouse_syms
;
1650 /* You'll notice that this table is arranged to be conveniently
1651 indexed by X Windows keysym values. */
1652 static char *lispy_function_keys
[] =
1654 /* X Keysym value */
1656 "home", /* 0xff50 */ /* IsCursorKey */
1667 "select", /* 0xff60 */ /* IsMiscFunctionKey */
1678 "break", /* 0xff6b */
1680 /* Here are some keys found mostly on HP keyboards. The X event
1681 handling code will strip bit 29, which flags vendor-specific
1683 "reset", /* 0x1000ff6c */
1692 "kp_backtab", /* 0x1000ff75 */
1694 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff7f */
1695 "kp-space", /* 0xff80 */ /* IsKeypadKey */
1696 0, 0, 0, 0, 0, 0, 0, 0,
1697 "kp-tab", /* 0xff89 */
1699 "kp-enter", /* 0xff8d */
1701 "kp-f1", /* 0xff91 */
1706 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1707 "kp-multiply", /* 0xffaa */
1712 "kp-divide", /* 0xffaf */
1713 "kp-0", /* 0xffb0 */
1714 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
1717 "kp-equal", /* 0xffbd */
1718 "f1", /* 0xffbe */ /* IsFunctionKey */
1720 "f5", "f6", "f7", "f8", "f9", "f10", "f11", "f12",
1721 "f13", "f14", "f15", "f16", "f17", "f18", "f19", "f20",
1722 "f21", "f22", "f23", "f24", "f25", "f26", "f27", "f28",
1723 "f29", "f30", "f31", "f32", "f33", "f34", "f35" /* 0xffe0 */
1726 static char *lispy_mouse_names
[] =
1728 "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5"
1731 /* Given a struct input_event, build the lisp event which represents
1732 it. If EVENT is 0, build a mouse movement event from the mouse
1733 movement buffer, which should have a movement event in it. */
1736 make_lispy_event (event
)
1737 struct input_event
*event
;
1739 #ifdef SWITCH_ENUM_BUG
1740 switch ((int) event
->kind
)
1742 switch (event
->kind
)
1746 /* A simple keystroke. */
1747 case ascii_keystroke
:
1751 /* A function key. The symbol may need to have modifier prefixes
1753 case non_ascii_keystroke
:
1754 return modify_event_symbol (XFASTINT (event
->code
), event
->modifiers
,
1756 lispy_function_keys
, &func_key_syms
,
1757 (sizeof (lispy_function_keys
)
1758 / sizeof (lispy_function_keys
[0])));
1761 /* A mouse click - build a list of the relevant information. */
1765 Lisp_Object window
=
1766 window_from_coordinates (event
->frame
,
1767 XINT (event
->x
), XINT (event
->y
),
1771 if (XTYPE (window
) != Lisp_Window
)
1775 XSETINT (event
->x
, (XINT (event
->x
)
1776 - XINT (XWINDOW (window
)->left
)));
1777 XSETINT (event
->y
, (XINT (event
->y
)
1778 - XINT (XWINDOW (window
)->top
)));
1783 posn
= Qvertical_line
;
1785 XSET (posn
, Lisp_Int
,
1786 buffer_posn_from_coords (XWINDOW (window
),
1791 return Fcons (modify_event_symbol (XFASTINT (event
->code
) - 1,
1794 lispy_mouse_names
, &mouse_syms
,
1795 (sizeof (lispy_mouse_names
)
1796 / sizeof (lispy_mouse_names
[0]))),
1799 Fcons (Fcons (event
->x
, event
->y
),
1805 /* A scrollbar click. Build a list containing the relevant
1807 case scrollbar_click
:
1810 = modify_event_symbol (XFASTINT (event
->code
) - 1,
1813 lispy_mouse_names
, &mouse_syms
,
1814 (sizeof (lispy_mouse_names
)
1815 / sizeof (lispy_mouse_names
[0])));
1816 return Fcons (event
->part
,
1817 Fcons (FRAME_SELECTED_WINDOW (event
->frame
),
1819 Fcons (Fcons (event
->x
, event
->y
),
1825 /* The 'kind' field of the event is something we don't recognize. */
1832 make_lispy_movement (frame
, x
, y
, time
)
1845 ? window_from_coordinates (frame
, ix
, iy
, &part
)
1847 if (XTYPE (window
) != Lisp_Window
)
1851 ix
-= XINT (XWINDOW (window
)->left
);
1852 iy
-= XINT (XWINDOW (window
)->top
);
1856 posn
= Qvertical_line
;
1858 XSET (posn
, Lisp_Int
, buffer_posn_from_coords (XWINDOW (window
),
1864 return Fcons (Qmouse_movement
,
1867 Fcons (Fcons (x
, y
),
1868 Fcons (make_number (time
), Qnil
)))));
1873 /* Place the written representation of MODIFIERS in BUF, '\0'-terminated,
1874 and return its length. */
1877 format_modifiers (modifiers
, buf
)
1883 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
1884 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
1885 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
1886 if (modifiers
& up_modifier
) { *p
++ = 'U'; *p
++ = '-'; }
1893 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
1894 return a symbol with the modifiers placed in the canonical order.
1896 Fdefine_key calls this to make sure that (for example) C-M-foo
1897 and M-C-foo end up being equivalent in the keymap. */
1900 reorder_modifiers (symbol
)
1903 struct Lisp_String
*name
;
1908 CHECK_SYMBOL (symbol
, 1);
1911 name
= XSYMBOL (symbol
)->name
;
1913 /* Special case for things with only one modifier, which is
1914 (hopefully) the vast majority of cases. */
1915 if (! (name
->size
>= 4 && name
->data
[1] == '-' && name
->data
[3] == '-'))
1918 for (i
= 0; i
+ 1 < name
->size
&& name
->data
[i
+ 1] == '-'; i
+= 2)
1919 switch (name
->data
[i
])
1922 not_canonical
|= (modifiers
& (meta_modifier
|ctrl_modifier
1923 |shift_modifier
|up_modifier
));
1924 modifiers
|= meta_modifier
;
1928 not_canonical
|= (modifiers
&
1929 (ctrl_modifier
|shift_modifier
|up_modifier
));
1930 modifiers
|= ctrl_modifier
;
1934 not_canonical
|= (modifiers
& (shift_modifier
|up_modifier
));
1935 modifiers
|= shift_modifier
;
1939 not_canonical
|= (modifiers
& (up_modifier
));
1940 modifiers
|= up_modifier
;
1944 goto no_more_modifiers
;
1951 /* The modifiers were out of order, so find a new symbol with the
1952 mods in order. Since the symbol name could contain nulls, we can't
1953 use intern here; we have to use Fintern, which expects a genuine
1954 Lisp_String, and keeps a reference to it. */
1956 char *new_mods
= (char *) alloca (sizeof ("C-M-S-U-"));
1957 int len
= format_modifiers (modifiers
, new_mods
);
1958 Lisp_Object new_name
= make_uninit_string (len
+ name
->size
- i
);
1960 bcopy (new_mods
, XSTRING (new_name
)->data
, len
);
1961 bcopy (name
->data
+ i
, XSTRING (new_name
)->data
+ len
, name
->size
- i
);
1963 return Fintern (new_name
, Qnil
);
1968 /* For handling events, we often want to produce a symbol whose name
1969 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
1970 to some base, like the name of a function key or mouse button.
1971 modify_event_symbol produces symbols of this sort.
1973 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
1974 is the name of the i'th symbol. TABLE_SIZE is the number of elements
1977 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
1978 persist between calls to modify_event_symbol that it can use to
1979 store a cache of the symbols it's generated for this NAME_TABLE
1982 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
1984 MODIFIERS is a set of modifier bits (as given in struct input_events)
1985 whose prefixes should be applied to the symbol name.
1987 SYMBOL_KIND is the value to be placed in the event_kind property of
1988 the returned symbol. */
1991 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_table
,
1992 symbol_table
, table_size
)
1995 Lisp_Object symbol_kind
;
1997 Lisp_Object
*symbol_table
;
2000 Lisp_Object
*slot
, *unmodified_slot
;
2002 /* Is this a request for a valid symbol? */
2003 if (symbol_num
< 0 || symbol_num
>= table_size
2004 || modifiers
>= NUM_MODIFIER_COMBOS
)
2007 /* If *symbol_table is not a vector of the appropriate size,
2009 if (XTYPE (*symbol_table
) != Lisp_Vector
2010 || XVECTOR (*symbol_table
)->size
!= table_size
)
2011 *symbol_table
= Fmake_vector (make_number (table_size
), Qnil
);
2013 unmodified_slot
= slot
= & XVECTOR (*symbol_table
)->contents
[symbol_num
];
2015 /* If there are modifier keys, there had better be a vector in
2016 this symbol's position of the symbol_table. */
2019 Lisp_Object slot_contents
= *slot
;
2021 /* If there isn't the right sort of vector there, put one in. */
2022 if (XTYPE (slot_contents
) != Lisp_Vector
2023 || XVECTOR (slot_contents
)->size
!= NUM_MODIFIER_COMBOS
)
2025 *slot
= Fmake_vector (make_number (NUM_MODIFIER_COMBOS
), Qnil
);
2027 /* Make sure that the vector has an entry for the unmodified
2028 symbol, so we can put it on the event_unmodified property. */
2029 if (! NILP (slot_contents
))
2030 XVECTOR (*slot
)->contents
[0] = slot_contents
;
2032 XVECTOR (*slot
)->contents
[0] = intern (name_table
[symbol_num
]);
2036 /* If this entry has been filled in with a modified symbol vector,
2037 point to the appropriate slot within that. */
2038 if (XTYPE (*slot
) == Lisp_Vector
)
2040 unmodified_slot
= & XVECTOR (*slot
)->contents
[0];
2041 slot
= & XVECTOR (*slot
)->contents
[modifiers
];
2044 /* Make sure we have an unmodified version of the symbol in its
2046 if (NILP (*unmodified_slot
))
2048 *unmodified_slot
= intern (name_table
[symbol_num
]);
2049 Fput (*unmodified_slot
, Qevent_kind
, symbol_kind
);
2050 Fput (*unmodified_slot
, Qevent_unmodified
, *unmodified_slot
);
2053 /* Have we already created a symbol for this combination of modifiers? */
2056 /* No, let's create one. */
2058 = (char *) alloca (sizeof ("C-M-S-U-")
2059 + strlen (name_table
[symbol_num
]));
2061 strcpy (modified_name
+ format_modifiers (modifiers
, modified_name
),
2062 name_table
[symbol_num
]);
2064 *slot
= intern (modified_name
);
2065 Fput (*slot
, Qevent_kind
, symbol_kind
);
2066 Fput (*slot
, Qevent_unmodified
, *unmodified_slot
);
2072 DEFUN ("mouse-click-p", Fmouse_click_p
, Smouse_click_p
, 1, 1, 0,
2073 "Return non-nil iff OBJECT is a representation of a mouse event.\n\
2074 A mouse event is a list of five elements whose car is a symbol of the\n\
2075 form <MODIFIERS>mouse-<DIGIT>. I hope this is a temporary hack.")
2079 if (EVENT_HAS_PARAMETERS (object
)
2080 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (object
)),
2087 /* Store into *addr a value nonzero if terminal input chars are available.
2088 Serves the purpose of ioctl (0, FIONREAD, addr)
2089 but works even if FIONREAD does not exist.
2090 (In fact, this may actually read some input.) */
2093 get_input_pending (addr
)
2096 /* First of all, have we already counted some input? */
2097 *addr
= !NILP (Vquit_flag
) || readable_events ();
2099 /* If input is being read as it arrives, and we have none, there is none. */
2100 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
2103 /* Try to read some input and see how much we get. */
2105 *addr
= !NILP (Vquit_flag
) || readable_events ();
2108 /* Interface to read_avail_input, blocking SIGIO if necessary. */
2111 gobble_input (expected
)
2116 if (interrupt_input
)
2119 mask
= sigblockx (SIGIO
);
2120 read_avail_input (expected
);
2125 read_avail_input (expected
);
2131 /* Read any terminal input already buffered up by the system
2132 into the kbd_buffer, but do not wait.
2134 EXPECTED should be nonzero if the caller knows there is some input.
2136 Except on VMS, all input is read by this function.
2137 If interrupt_input is nonzero, this function MUST be called
2138 only when SIGIO is blocked.
2140 Returns the number of keyboard chars read, or -1 meaning
2141 this is a bad time to try to read input. */
2144 read_avail_input (expected
)
2147 struct input_event buf
[KBD_BUFFER_SIZE
];
2151 if (read_socket_hook
)
2152 /* No need for FIONREAD or fcntl; just say don't wait. */
2153 nread
= (*read_socket_hook
) (0, buf
, KBD_BUFFER_SIZE
, expected
, expected
);
2156 unsigned char cbuf
[KBD_BUFFER_SIZE
];
2159 /* Find out how much input is available. */
2160 if (ioctl (0, FIONREAD
, &nread
) < 0)
2161 /* Formerly simply reported no input, but that sometimes led to
2162 a failure of Emacs to terminate.
2163 SIGHUP seems appropriate if we can't reach the terminal. */
2164 kill (getpid (), SIGHUP
);
2167 if (nread
> sizeof cbuf
)
2168 nread
= sizeof cbuf
;
2169 #else /* no FIONREAD */
2171 /* Read some input if available, but don't wait. */
2172 nread
= sizeof cbuf
;
2173 fcntl (fileno (stdin
), F_SETFL
, O_NDELAY
);
2179 /* Now read; for one reason or another, this will not block. */
2182 nread
= read (fileno (stdin
), cbuf
, nread
);
2184 /* The kernel sometimes fails to deliver SIGHUP for ptys.
2185 This looks incorrect, but it isn't, because _BSD causes
2186 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
2187 and that causes a value other than 0 when there is no input. */
2191 /* Retry the read if it is interrupted. */
2193 || ! (errno
== EAGAIN
|| errno
== EFAULT
2203 fcntl (fileno (stdin
), F_SETFL
, 0);
2205 #endif /* no FIONREAD */
2206 for (i
= 0; i
< nread
; i
++)
2208 buf
[i
].kind
= ascii_keystroke
;
2209 XSET (buf
[i
].code
, Lisp_Int
, cbuf
[i
]);
2210 buf
[i
].frame
= selected_frame
;
2214 /* Scan the chars for C-g and store them in kbd_buffer. */
2215 for (i
= 0; i
< nread
; i
++)
2217 kbd_buffer_store_event (&buf
[i
]);
2218 /* Don't look at input that follows a C-g too closely.
2219 This reduces lossage due to autorepeat on C-g. */
2220 if (buf
[i
].kind
== ascii_keystroke
2221 && XINT(buf
[i
].code
) == quit_char
)
2227 #endif /* not VMS */
2229 #ifdef SIGIO /* for entire page */
2230 /* Note SIGIO has been undef'd if FIONREAD is missing. */
2232 input_available_signal (signo
)
2235 /* Must preserve main program's value of errno. */
2236 int old_errno
= errno
;
2238 extern int select_alarmed
;
2242 /* USG systems forget handlers when they are used;
2243 must reestablish each time */
2244 signal (signo
, input_available_signal
);
2251 if (input_available_clear_time
)
2252 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
2257 nread
= read_avail_input (1);
2258 /* -1 means it's not ok to read the input now.
2259 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
2260 0 means there was no keyboard input available. */
2265 select_alarmed
= 1; /* Force the select emulator back to life */
2276 /* Return the prompt-string of a sparse keymap.
2277 This is the first element which is a string.
2278 Return nil if there is none. */
2286 register Lisp_Object tem
;
2288 if (XTYPE (tem
) == Lisp_String
)
2295 static int echo_flag
;
2296 static int echo_now
;
2298 /* Read a character like read_char but optionally prompt based on maps
2301 The prompting is done based on the prompt-string of the map
2302 and the strings associated with various map elements. */
2305 read_char_menu_prompt (prompt
, local
, global
)
2307 Lisp_Object local
, global
;
2309 register Lisp_Object rest
, name
;
2312 int width
= FRAME_WIDTH (selected_frame
) - 4;
2313 char *menu
= (char *) alloca (width
);
2315 /* Use local over global Menu maps */
2318 return read_char (!prompt
);
2320 /* We can't get prompt strings from dense keymaps. */
2322 && EQ (Fcar (local
), Qkeymap
)
2323 && !(CONSP (XCONS (local
)->cdr
)
2324 && XTYPE (XCONS (XCONS (local
)->cdr
)->car
) == Lisp_Vector
))
2326 else if (CONSP (global
)
2327 && EQ (Fcar (global
), Qkeymap
)
2328 && !(CONSP (XCONS (global
)->cdr
)
2329 && XTYPE (XCONS (XCONS (global
)->cdr
)->car
) == Lisp_Vector
))
2332 return read_char (!prompt
);
2334 /* Get the map's prompt string. */
2335 name
= map_prompt (hmap
);
2337 return read_char (!prompt
);
2339 /* Prompt string always starts with map's prompt, and a space. */
2340 strcpy (menu
, XSTRING (name
)->data
);
2341 nlength
= XSTRING (name
)->size
;
2342 menu
[nlength
++] = ' ';
2345 /* Start prompting at start of map. */
2346 rest
= hmap
; /* Current menu item */
2348 /* Present the documented bindings, a line at a time. */
2356 /* If reached end of map, start at beginning. */
2357 if (NILP (Fcdr (rest
))) rest
= hmap
;
2359 /* Loop over elements of map. */
2360 while (!NILP (rest
) && i
< width
)
2364 /* Look for conses whose cadrs are strings. */
2365 s
= Fcar_safe (Fcdr_safe (Fcar_safe (rest
)));
2366 if (XTYPE (s
) != Lisp_String
)
2367 /* Ignore all other elements. */
2369 /* If first such element, or enough room, add string to prompt. */
2370 else if (XSTRING (s
)->size
+ i
< width
2375 /* Punctuate between strings. */
2378 strcpy (menu
+ i
, ", ");
2383 /* Add as much of string as fits. */
2384 thiswidth
= XSTRING (s
)->size
;
2385 if (thiswidth
+ i
> width
)
2386 thiswidth
= width
- i
;
2387 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
2392 /* If some elts don't fit, show there are more. */
2393 strcpy (menu
+ i
, "...");
2397 /* Move past this element. */
2398 rest
= Fcdr_safe (rest
);
2401 /* Prompt with that and read response. */
2403 obj
= read_char (1);
2405 if (XTYPE (obj
) != Lisp_Int
)
2410 if (obj
!= menu_prompt_more_char
2411 && (XTYPE (menu_prompt_more_char
) != Lisp_Int
2412 || obj
!= make_number (Ctl (XINT (menu_prompt_more_char
)))))
2418 /* Reading key sequences. */
2420 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
2421 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
2422 keymap, or nil otherwise. Return the index of the first keymap in
2423 which KEY has any binding, or NMAPS if no map has a binding.
2425 If KEY is a meta ASCII character, treat it like meta-prefix-char
2426 followed by the corresponding non-meta character. Keymaps in
2427 CURRENT with non-prefix bindings for meta-prefix-char become nil in
2430 When KEY is not defined in any of the keymaps, if it is an upper
2431 case letter and there are bindings for the corresponding lower-case
2432 letter, return the bindings for the lower-case letter.
2434 NEXT may == CURRENT. */
2437 follow_key (key
, nmaps
, current
, defs
, next
)
2439 Lisp_Object
*current
, *defs
, *next
;
2442 int i
, first_binding
;
2444 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
2445 followed by the corresponding non-meta character. */
2446 if (XTYPE (key
) == Lisp_Int
2447 && XINT (key
) >= 0200)
2449 for (i
= 0; i
< nmaps
; i
++)
2450 if (! NILP (current
[i
]))
2452 next
[i
] = get_keyelt (access_keymap (current
[i
],
2455 /* Note that since we pass the resulting bindings through
2456 get_keymap_1, non-prefix bindings for meta-prefix-char
2458 next
[i
] = get_keymap_1 (next
[i
], 0);
2464 XSET (key
, Lisp_Int
, XFASTINT (key
) & 0177);
2467 first_binding
= nmaps
;
2468 for (i
= nmaps
- 1; i
>= 0; i
--)
2470 if (! NILP (current
[i
]))
2472 defs
[i
] = get_keyelt (access_keymap (current
[i
], key
));
2473 if (! NILP (defs
[i
]))
2480 /* When KEY is not defined in any of the keymaps, if it is an upper
2481 case letter and there are bindings for the corresponding
2482 lower-case letter, return the bindings for the lower-case letter. */
2483 if (first_binding
== nmaps
2484 && XTYPE (key
) == Lisp_Int
2485 && UPPERCASEP (XINT (key
)))
2487 XSETINT (key
, DOWNCASE (XINT (key
)));
2489 first_binding
= nmaps
;
2490 for (i
= nmaps
- 1; i
>= 0; i
--)
2492 if (! NILP (current
[i
]))
2494 defs
[i
] = get_keyelt (access_keymap (current
[i
], key
));
2495 if (! NILP (defs
[i
]))
2503 /* Given the set of bindings we've found, produce the next set of maps. */
2504 for (i
= 0; i
< nmaps
; i
++)
2505 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0);
2507 return first_binding
;
2510 /* Read a sequence of keys that ends with a non prefix character
2511 according to the keymaps in KEYMAPS[0..nmaps-1]. Keymaps appearing
2512 earlier in KEYMAPS take precidence over those appearing later.
2514 Store the sequence in KEYBUF, a buffer of size BUFSIZE. Prompt
2515 with PROMPT. Echo starting immediately unless `prompt' is 0.
2516 Return the length of the key sequence stored.
2518 If the user switches frames in the midst of a key sequence, we
2519 throw away any prefix we have read so far, and start afresh. For
2520 mouse clicks, we look up the click in the keymap of the buffer
2521 clicked on, throwing away any prefix if it is not the same buffer
2522 we used to be reading from. */
2525 read_key_sequence (keybuf
, bufsize
, prompt
)
2526 Lisp_Object
*keybuf
;
2530 /* How many keys there are in the current key sequence. */
2533 /* The buffer that the most recently read event was typed at. This
2534 helps us read mouse clicks according to the buffer clicked in,
2535 and notice when the mouse has moved from one frame to another. */
2536 struct buffer
*last_event_buffer
= current_buffer
;
2538 /* The length of the echo buffer when we started reading, and
2539 the length of this_command_keys when we started reading. */
2541 int keys_start
= this_command_key_count
;
2543 /* The number of keymaps we're scanning right now, and the number of
2544 keymaps we have allocated space for. */
2546 int nmaps_allocated
= 0;
2548 /* current[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
2549 in the current keymaps, or nil where it is not a prefix. */
2550 Lisp_Object
*current
;
2552 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
2553 the current keymaps. */
2556 /* The lowest i such that defs[i] is non-nil. */
2559 /* If mock_input > t, then KEYBUF[t] should be read as the next
2563 /* If the sequence is unbound in current[], keymap[fkey_start..fkey_end-1]
2564 is a prefix in Vfunction_key_map, and fkey_map is its binding.
2565 These might be > t, indicating that all function key scanning should
2566 hold off until t reaches them. */
2567 int fkey_start
= 0, fkey_end
= 0;
2568 Lisp_Object fkey_map
= Vfunction_key_map
;
2573 echo_prompt (prompt
);
2574 else if (cursor_in_echo_area
)
2575 /* This doesn't put in a dash if the echo buffer is empty, so
2576 you don't always see a dash hanging out in the minibuffer. */
2578 echo_start
= echo_length ();
2581 /* If there is no function key map, turn of function key scanning. */
2582 if (NILP (Fkeymapp (Vfunction_key_map
)))
2583 fkey_start
= fkey_end
= bufsize
+ 1;
2587 this_command_key_count
= keys_start
;
2592 nmaps
= current_minor_maps (0, &maps
) + 2;
2593 if (nmaps
> nmaps_allocated
)
2595 current
= (Lisp_Object
*) alloca (nmaps
* sizeof (current
[0]));
2596 defs
= (Lisp_Object
*) alloca (nmaps
* sizeof (defs
[0]));
2597 nmaps_allocated
= nmaps
;
2599 bcopy (maps
, current
, (nmaps
- 2) * sizeof (current
[0]));
2600 current
[nmaps
-2] = last_event_buffer
->keymap
;
2601 current
[nmaps
-1] = global_map
;
2604 /* Find an accurate initial value for first_binding. */
2605 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
2606 if (! NILP (current
[first_binding
]))
2609 while ((first_binding
< nmaps
&& ! NILP (current
[first_binding
]))
2610 || (first_binding
>= nmaps
&& fkey_start
< t
))
2615 error ("key sequence too long");
2617 /* Are we reading keys stuffed into keybuf? */
2621 add_command_key (key
);
2624 /* Otherwise, we should actually read a character. */
2629 if (!prompt
&& INTERACTIVE
)
2630 key
= read_char_menu_prompt (prompt
, Qnil
, Qnil
);
2632 key
= read_char (!prompt
);
2634 /* The above routines return -1 at the end of a macro.
2635 Emacs 18 handles this by returning immediately with a
2636 zero, so that's what we'll do. */
2637 if (XTYPE (key
) == Lisp_Int
&& XINT (key
) < 0)
2643 /* What buffer was this event typed/moused at? */
2644 if (XTYPE (key
) == Lisp_Int
|| XTYPE (key
) == Lisp_Symbol
)
2647 (FRAME_SELECTED_WINDOW
2648 (XFRAME (Vlast_event_frame
)))->buffer
));
2649 else if (EVENT_HAS_PARAMETERS (key
))
2651 Lisp_Object window
= EVENT_WINDOW (key
);
2656 buf
= XBUFFER (XWINDOW (window
)->buffer
);
2661 /* If this event came to a different buffer than the one
2662 we're currently in, switch buffers and start a new key
2663 sequence, starting with key. */
2664 if (buf
!= last_event_buffer
)
2666 last_event_buffer
= buf
;
2667 Fselect_frame (Vlast_event_frame
, Qnil
);
2669 /* Arrange to read key as the next event. */
2673 /* Truncate the key sequence in the echo area. */
2675 echo_truncate (echo_start
);
2682 first_binding
= (follow_key (key
,
2683 nmaps
- first_binding
,
2684 current
+ first_binding
,
2685 defs
+ first_binding
,
2686 current
+ first_binding
)
2690 /* If the sequence is unbound, see if we can hang a function key
2691 off the end of it. Don't reread the expansion of a function key. */
2692 if (first_binding
>= nmaps
2695 Lisp_Object fkey_next
;
2697 /* Scan from fkey_end until we find a bound suffix. */
2698 while (fkey_end
< t
)
2700 /* Look up meta-characters by prefixing them
2701 with meta_prefix_char. I hate this. */
2702 if (keybuf
[fkey_end
++] & 0x80)
2704 get_keymap_1 (get_keyelt
2705 (access_keymap (fkey_map
, meta_prefix_char
)),
2708 fkey_next
= fkey_map
;
2711 get_keyelt (access_keymap
2712 (fkey_next
, keybuf
[(fkey_end
++) & 0x7f]));
2714 /* If keybuf[fkey_start..fkey_next] is bound in the
2715 function key map and it's a suffix of the current
2716 sequence (i.e. fkey_next == t), replace it with
2717 the binding and restart with fkey_start at the end. */
2718 if (XTYPE (fkey_next
) == Lisp_Vector
2721 t
= fkey_start
+ XVECTOR (fkey_next
)->size
;
2723 error ("key sequence too long");
2725 bcopy (XVECTOR (fkey_next
)->contents
,
2726 keybuf
+ fkey_start
,
2727 (t
- fkey_start
) * sizeof (keybuf
[0]));
2730 fkey_start
= fkey_end
= t
;
2732 /* Truncate the key sequence in the echo area. */
2734 echo_truncate (echo_start
);
2739 fkey_map
= get_keymap_1 (fkey_next
, 0);
2741 /* If we no longer have a bound suffix, try a new positions for
2743 if (NILP (fkey_map
))
2745 fkey_end
= ++fkey_start
;
2746 fkey_map
= Vfunction_key_map
;
2752 read_key_sequence_cmd
= (first_binding
< nmaps
2753 ? defs
[first_binding
]
2759 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 2, 0,
2760 "Read a sequence of keystrokes and return as a string or vector.\n\
2761 The sequence is sufficient to specify a non-prefix command in the\n\
2762 current local and global maps.\n\
2764 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
2765 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
2766 as a continuation of the previous key.\n\
2768 If Emacs is running on multiple frames, switching between frames in\n\
2769 the midst of a keystroke will toss any prefix typed so far. A C-g\n\
2770 typed while in this function is treated like any other character, and\n\
2771 `quit-flag' is not set.")
2772 (prompt
, continue_echo
)
2773 Lisp_Object prompt
, continue_echo
;
2775 Lisp_Object keybuf
[30];
2777 struct gcpro gcpro1
, gcpro2
;
2780 CHECK_STRING (prompt
, 0);
2783 bzero (keybuf
, sizeof keybuf
);
2785 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
2787 if (NILP (continue_echo
))
2788 this_command_key_count
= 0;
2790 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
2791 NILP (prompt
) ? 0 : XSTRING (prompt
)->data
);
2794 return make_array (i
, keybuf
);
2797 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 2, 0,
2798 "Execute CMD as an editor command.\n\
2799 CMD must be a symbol that satisfies the `commandp' predicate.\n\
2800 Optional second arg RECORD-FLAG non-nil\n\
2801 means unconditionally put this command in `command-history'.\n\
2802 Otherwise, that is done only if an arg is read using the minibuffer.")
2804 Lisp_Object cmd
, record
;
2806 register Lisp_Object final
;
2807 register Lisp_Object tem
;
2808 Lisp_Object prefixarg
;
2809 struct backtrace backtrace
;
2810 extern int debug_on_next_call
;
2812 prefixarg
= Vprefix_arg
, Vprefix_arg
= Qnil
;
2813 Vcurrent_prefix_arg
= prefixarg
;
2814 debug_on_next_call
= 0;
2816 if (XTYPE (cmd
) == Lisp_Symbol
)
2818 tem
= Fget (cmd
, Qdisabled
);
2820 return call1 (Vrun_hooks
, Vdisabled_command_hook
);
2825 final
= Findirect_function (cmd
);
2827 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
2828 do_autoload (final
, cmd
);
2833 if (XTYPE (final
) == Lisp_String
2834 || XTYPE (final
) == Lisp_Vector
)
2836 /* If requested, place the macro in the command history. For
2837 other sorts of commands, call-interactively takes care of
2841 = Fcons (Fcons (Qexecute_kbd_macro
,
2842 Fcons (final
, Fcons (prefixarg
, Qnil
))),
2845 return Fexecute_kbd_macro (final
, prefixarg
);
2847 if (CONSP (final
) || XTYPE (final
) == Lisp_Subr
2848 || XTYPE (final
) == Lisp_Compiled
)
2850 backtrace
.next
= backtrace_list
;
2851 backtrace_list
= &backtrace
;
2852 backtrace
.function
= &Qcall_interactively
;
2853 backtrace
.args
= &cmd
;
2854 backtrace
.nargs
= 1;
2855 backtrace
.evalargs
= 0;
2857 tem
= Fcall_interactively (cmd
, record
);
2859 backtrace_list
= backtrace
.next
;
2866 DEFUN ("execute-mouse-event", Fexecute_mouse_event
, Sexecute_mouse_event
,
2868 "Execute the definition of the mouse-click event EVENT.\n\
2869 The handler function is found by looking the event's key sequence up\n\
2870 in the buffer's local mouse map and in `global-mouse-map'.\n\
2872 After running the handler, call the value of `mouse-event-function'\n\
2873 with EVENT as arg.")
2878 Lisp_Object mouse_cmd
;
2879 Lisp_Object keyseq
, window
, frame_part
, pos
, time
;
2882 Vmouse_event
= event
;
2885 if (EQ (event
, Qnil
))
2891 CHECK_CONS (event
, 0);
2893 window
= Fcar (Fcdr (event
));
2894 frame_part
= Fcar (Fcdr (Fcdr (event
)));
2895 keyseq
= Fcar (Fcdr (Fcdr (Fcdr (event
))));
2896 time
= Fcar (Fcdr (Fcdr (Fcdr (Fcdr (event
)))));
2897 CHECK_STRING (keyseq
, 0);
2898 CHECK_WINDOW (window
, 0);
2900 /* Look up KEYSEQ in the buffer's local mouse map, then in global one. */
2904 if (!NILP (XWINDOW (window
)->buffer
))
2906 Lisp_Object local_map
;
2908 local_map
= XBUFFER (XWINDOW (window
)->buffer
)->mouse_map
;
2909 tem
= Fkeymapp (local_map
);
2911 mouse_cmd
= Flookup_key (local_map
, keyseq
);
2912 /* A number as value means the key is too long; treat as undefined. */
2913 if (XTYPE (mouse_cmd
) == Lisp_Int
)
2917 tem
= Fkeymapp (Vglobal_mouse_map
);
2918 if (NILP (mouse_cmd
) && !NILP (tem
))
2919 mouse_cmd
= Flookup_key (Vglobal_mouse_map
, keyseq
);
2920 if (XTYPE (mouse_cmd
) == Lisp_Int
)
2923 if (NILP (mouse_cmd
))
2925 /* This button/shift combination is not defined.
2926 If it is a button-down event, ring the bell. */
2928 if (XSTRING (keyseq
)->data
[XSTRING (keyseq
)->size
- 1] & 0x18 == 0)
2930 if (XSTRING (keyseq
)->data
[XSTRING (keyseq
)->size
- 1] & 4 == 0)
2936 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (window
)));
2939 Vmouse_window
= f
->selected_window
;
2940 #endif /* HAVE_X11 */
2941 /* It's defined; call the definition. */
2943 if (!NILP (frame_part
))
2945 /* For a scroll-bar click, set the prefix arg
2946 to the number of lines down from the top the click was.
2947 Many scroll commands want to scroll by this many lines. */
2948 Lisp_Object position
;
2952 position
= Fcar (pos
);
2953 length
= Fcar (Fcdr (pos
));
2954 offset
= Fcar (Fcdr (Fcdr (pos
)));
2956 if (XINT (length
) != 0)
2957 XSET (Vprefix_arg
, Lisp_Int
,
2958 (FRAME_HEIGHT (f
) * (XINT (position
) + XINT (offset
))
2959 / (XINT (length
) + 2 * XINT (offset
))));
2961 Fcommand_execute (mouse_cmd
, Qnil
);
2964 if (!NILP (Vmouse_event_function
)) /* Not `event' so no need for GCPRO */
2965 call1 (Vmouse_event_function
, Vmouse_event
);
2970 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
2972 "Read function name, then read its arguments and call it.")
2974 Lisp_Object prefixarg
;
2976 Lisp_Object function
;
2978 Lisp_Object saved_keys
;
2979 struct gcpro gcpro1
;
2981 saved_keys
= Fthis_command_keys ();
2983 GCPRO1 (saved_keys
);
2985 if (EQ (prefixarg
, Qminus
))
2987 else if (CONSP (prefixarg
) && XINT (XCONS (prefixarg
)->car
) == 4)
2988 strcpy (buf
, "C-u ");
2989 else if (CONSP (prefixarg
) && XTYPE (XCONS (prefixarg
)->car
) == Lisp_Int
)
2990 sprintf (buf
, "%d ", XINT (XCONS (prefixarg
)->car
));
2991 else if (XTYPE (prefixarg
) == Lisp_Int
)
2992 sprintf (buf
, "%d ", XINT (prefixarg
));
2994 /* This isn't strictly correct if execute-extended-command
2995 is bound to anything else. Perhaps it should use
2996 this_command_keys? */
2997 strcat (buf
, "M-x ");
2999 /* Prompt with buf, and then read a string, completing from and
3000 restricting to the set of all defined commands. Don't provide
3001 any initial input. The last Qnil says not to perform a
3002 peculiar hack on the initial input. */
3003 function
= Fcompleting_read (build_string (buf
),
3004 Vobarray
, Qcommandp
,
3007 /* Set this_command_keys to the concatenation of saved_keys and
3008 function, followed by a RET. */
3010 struct Lisp_String
*str
;
3014 this_command_key_count
= 0;
3016 str
= XSTRING (saved_keys
);
3017 for (i
= 0; i
< str
->size
; i
++)
3019 XFASTINT (tem
) = str
->data
[i
];
3020 add_command_key (tem
);
3023 str
= XSTRING (function
);
3024 for (i
= 0; i
< str
->size
; i
++)
3026 XFASTINT (tem
) = str
->data
[i
];
3027 add_command_key (tem
);
3030 XFASTINT (tem
) = '\015';
3031 add_command_key (tem
);
3036 function
= Fintern (function
, Vobarray
);
3037 Vprefix_arg
= prefixarg
;
3038 this_command
= function
;
3040 return Fcommand_execute (function
, Qt
);
3044 detect_input_pending ()
3047 get_input_pending (&input_pending
);
3049 return input_pending
;
3052 /* This is called in some cases before a possible quit.
3053 It cases the next call to detect_input_pending to recompute input_pending.
3054 So calling this function unnecessarily can't do any harm. */
3055 clear_input_pending ()
3060 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
3061 "T if command input is currently available with no waiting.\n\
3062 Actually, the value is nil only if we can be sure that no input is available.")
3065 if (!NILP (unread_command_char
))
3068 return detect_input_pending () ? Qt
: Qnil
;
3071 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
3072 "Return vector of last 100 chars read from terminal.")
3077 if (total_keys
< NUM_RECENT_KEYS
)
3078 return Fvector (total_keys
, recent_keys
);
3081 val
= Fvector (NUM_RECENT_KEYS
, recent_keys
);
3082 bcopy (recent_keys
+ recent_keys_index
,
3083 XVECTOR (val
)->contents
,
3084 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
3086 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
3087 recent_keys_index
* sizeof (Lisp_Object
));
3092 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
3093 "Return string of the keystrokes that invoked this command.")
3096 return make_array (this_command_key_count
, this_command_keys
);
3099 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
3100 "Return the current depth in recursive edits.")
3104 XFASTINT (temp
) = command_loop_level
+ minibuf_level
;
3108 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
3109 "FOpen dribble file: ",
3110 "Start writing all keyboard characters to FILE.")
3121 file
= Fexpand_file_name (file
, Qnil
);
3122 dribble
= fopen (XSTRING (file
)->data
, "w");
3127 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
3128 "Discard the contents of the terminal input buffer.\n\
3129 Also cancel any kbd macro being defined.")
3132 defining_kbd_macro
= 0;
3133 update_mode_lines
++;
3136 unread_command_char
= make_number (-1);
3138 unread_command_char
= Qnil
;
3140 discard_tty_input ();
3142 kbd_fetch_ptr
= kbd_store_ptr
;
3148 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
3149 "Stop Emacs and return to superior process. You can resume later.\n\
3150 On systems that don't have job control, run a subshell instead.\n\n\
3151 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
3152 to be read as terminal input by Emacs's superior shell.\n\
3153 Before suspending, if `suspend-hook' is bound and value is non-nil\n\
3154 call the value as a function of no args. Don't suspend if it returns non-nil.\n\
3155 Otherwise, suspend normally and after resumption call\n\
3156 `suspend-resume-hook' if that is bound and non-nil.\n\
3158 Some operating systems cannot stop the Emacs process and resume it later.\n\
3159 On such systems, Emacs will start a subshell and wait for it to exit.")
3161 Lisp_Object stuffstring
;
3163 register Lisp_Object tem
;
3164 int count
= specpdl_ptr
- specpdl
;
3165 int old_height
, old_width
;
3167 struct gcpro gcpro1
;
3168 extern init_sys_modes ();
3170 if (!NILP (stuffstring
))
3171 CHECK_STRING (stuffstring
, 0);
3172 GCPRO1 (stuffstring
);
3174 /* Call value of suspend-hook
3175 if it is bound and value is non-nil. */
3176 if (!NILP (Vrun_hooks
))
3178 tem
= call1 (Vrun_hooks
, intern ("suspend-hook"));
3179 if (!EQ (tem
, Qnil
)) return Qnil
;
3182 get_frame_size (&old_width
, &old_height
);
3184 /* sys_suspend can get an error if it tries to fork a subshell
3185 and the system resources aren't available for that. */
3186 record_unwind_protect (init_sys_modes
, 0);
3187 stuff_buffered_input (stuffstring
);
3189 unbind_to (count
, Qnil
);
3191 /* Check if terminal/window size has changed.
3192 Note that this is not useful when we are running directly
3193 with a window system; but suspend should be disabled in that case. */
3194 get_frame_size (&width
, &height
);
3195 if (width
!= old_width
|| height
!= old_height
)
3196 change_frame_size (height
, width
, 0);
3198 /* Call value of suspend-resume-hook
3199 if it is bound and value is non-nil. */
3200 if (!NILP (Vrun_hooks
))
3201 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
3207 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
3208 Then in any case stuff anthing Emacs has read ahead and not used. */
3210 stuff_buffered_input (stuffstring
)
3211 Lisp_Object stuffstring
;
3213 register unsigned char *p
;
3215 /* stuff_char works only in BSD, versions 4.2 and up. */
3218 if (XTYPE (stuffstring
) == Lisp_String
)
3222 p
= XSTRING (stuffstring
)->data
;
3223 count
= XSTRING (stuffstring
)->size
;
3228 /* Anything we have read ahead, put back for the shell to read. */
3229 while (kbd_fetch_ptr
!= kbd_store_ptr
)
3231 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3232 kbd_fetch_ptr
= kbd_buffer
;
3233 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
3234 stuff_char (XINT (kbd_fetch_ptr
->code
));
3239 #endif /* BSD and not BSD4_1 */
3242 set_waiting_for_input (time_to_clear
)
3243 EMACS_TIME
*time_to_clear
;
3245 input_available_clear_time
= time_to_clear
;
3247 /* Tell interrupt_signal to throw back to read_char, */
3248 waiting_for_input
= 1;
3250 /* If interrupt_signal was called before and buffered a C-g,
3251 make it run again now, to avoid timing error. */
3252 if (!NILP (Vquit_flag
))
3253 quit_throw_to_read_char ();
3255 /* If alarm has gone off already, echo now. */
3263 clear_waiting_for_input ()
3265 /* Tell interrupt_signal not to throw back to read_char, */
3266 waiting_for_input
= 0;
3267 input_available_clear_time
= 0;
3270 /* This routine is called at interrupt level in response to C-G.
3271 If interrupt_input, this is the handler for SIGINT.
3272 Otherwise, it is called from kbd_buffer_store_event,
3273 in handling SIGIO or SIGTINT.
3275 If `waiting_for_input' is non zero, then unless `echoing' is nonzero,
3276 immediately throw back to read_char.
3278 Otherwise it sets the Lisp variable quit-flag not-nil.
3279 This causes eval to throw, when it gets a chance.
3280 If quit-flag is already non-nil, it stops the job right away. */
3286 /* Must preserve main program's value of errno. */
3287 int old_errno
= errno
;
3288 extern Lisp_Object Vwindow_system
;
3291 /* USG systems forget handlers when they are used;
3292 must reestablish each time */
3293 signal (SIGINT
, interrupt_signal
);
3294 signal (SIGQUIT
, interrupt_signal
);
3299 if (!NILP (Vquit_flag
) && FRAME_IS_TERMCAP (selected_frame
))
3304 #ifdef SIGTSTP /* Support possible in later USG versions */
3306 * On systems which can suspend the current process and return to the original
3307 * shell, this command causes the user to end up back at the shell.
3308 * The "Auto-save" and "Abort" questions are not asked until
3309 * the user elects to return to emacs, at which point he can save the current
3310 * job and either dump core or continue.
3315 if (sys_suspend () == -1)
3317 printf ("Not running as a subprocess;\n");
3318 printf ("you can continue or abort.\n");
3321 /* Perhaps should really fork an inferior shell?
3322 But that would not provide any way to get back
3323 to the original shell, ever. */
3324 printf ("No support for stopping a process on this operating system;\n");
3325 printf ("you can continue or abort.\n");
3326 #endif /* not VMS */
3327 #endif /* not SIGTSTP */
3328 printf ("Auto-save? (y or n) ");
3330 if (((c
= getchar ()) & ~040) == 'Y')
3331 Fdo_auto_save (Qnil
, Qnil
);
3332 while (c
!= '\n') c
= getchar ();
3334 printf ("Abort (and enter debugger)? (y or n) ");
3336 printf ("Abort (and dump core)? (y or n) ");
3337 #endif /* not VMS */
3339 if (((c
= getchar ()) & ~040) == 'Y')
3341 while (c
!= '\n') c
= getchar ();
3342 printf ("Continuing...\n");
3348 /* If executing a function that wants to be interrupted out of
3349 and the user has not deferred quitting by binding `inhibit-quit'
3350 then quit right away. */
3351 if (immediate_quit
&& NILP (Vinhibit_quit
))
3355 Fsignal (Qquit
, Qnil
);
3358 /* Else request quit when it's safe */
3362 if (waiting_for_input
&& !echoing
)
3363 quit_throw_to_read_char ();
3368 /* Handle a C-g by making read_char return C-g. */
3370 quit_throw_to_read_char ()
3372 quit_error_check ();
3374 /* Prevent another signal from doing this before we finish. */
3375 clear_waiting_for_input ();
3379 unread_command_char
= make_number (-1);
3381 unread_command_char
= Qnil
;
3383 _longjmp (getcjmp
, 1);
3386 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
3387 "Set mode of reading keyboard input.\n\
3388 First arg INTERRUPT non-nil means use input interrupts;\n\
3389 nil means use CBREAK mode.\n\
3390 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
3391 (no effect except in CBREAK mode).\n\
3392 Third arg META non-nil means accept 8-bit input (for a Meta key).\n\
3393 Otherwise, the top bit is ignored, on the assumption it is parity.\n\
3394 Optional fourth arg QUIT if non-nil specifies character to use for quitting.")
3395 (interrupt
, flow
, meta
, quit
)
3396 Lisp_Object interrupt
, flow
, meta
, quit
;
3399 && (XTYPE (quit
) != Lisp_Int
3400 || XINT (quit
) < 0 || XINT (quit
) > 0400))
3401 error ("set-input-mode: QUIT must be an ASCII character.");
3405 /* Note SIGIO has been undef'd if FIONREAD is missing. */
3406 #ifdef NO_SOCK_SIGIO
3407 if (read_socket_hook
)
3408 interrupt_input
= 0; /* No interrupts if reading from a socket. */
3410 #endif /* NO_SOCK_SIGIO */
3411 interrupt_input
= !NILP (interrupt
);
3412 #else /* not SIGIO */
3413 interrupt_input
= 0;
3414 #endif /* not SIGIO */
3415 /* Our VMS input only works by interrupts, as of now. */
3417 interrupt_input
= 1;
3419 flow_control
= !NILP (flow
);
3420 meta_key
= !NILP (meta
);
3422 /* Don't let this value be out of range. */
3423 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
3431 this_command_keys_size
= 40;
3433 (Lisp_Object
*) xmalloc (this_command_keys_size
* sizeof (Lisp_Object
));
3435 /* This is correct before outermost invocation of the editor loop */
3436 command_loop_level
= -1;
3438 quit_char
= Ctl ('g');
3439 unread_command_char
= Qnil
;
3440 recent_keys_index
= 0;
3442 kbd_fetch_ptr
= kbd_buffer
;
3443 kbd_store_ptr
= kbd_buffer
;
3444 do_mouse_tracking
= 0;
3447 if (!noninteractive
)
3449 signal (SIGINT
, interrupt_signal
);
3451 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
3452 SIGQUIT and we can't tell which one it will give us. */
3453 signal (SIGQUIT
, interrupt_signal
);
3454 #endif /* HAVE_TERMIO */
3455 /* Note SIGIO has been undef'd if FIONREAD is missing. */
3457 signal (SIGIO
, input_available_signal
);
3461 /* Use interrupt input by default, if it works and noninterrupt input
3462 has deficiencies. */
3464 #ifdef INTERRUPT_INPUT
3465 interrupt_input
= 1;
3467 interrupt_input
= 0;
3470 /* Our VMS input only works by interrupts, as of now. */
3472 interrupt_input
= 1;
3478 if (keyboard_init_hook
)
3479 (*keyboard_init_hook
) ();
3481 #ifdef POLL_FOR_INPUT
3482 poll_suppress_count
= 1;
3487 /* This type's only use is in syms_of_keyboard, to initialize the
3488 event header symbols and put properties on them. */
3495 struct event_head head_table
[] = {
3496 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
3497 &Qvscrollbar_part
, "vscrollbar-part", &Qscrollbar_click
,
3498 &Qvslider_part
, "vslider-part", &Qscrollbar_click
,
3499 &Qvthumbup_part
, "vthumbup-part", &Qscrollbar_click
,
3500 &Qvthumbdown_part
, "vthumbdown-part", &Qscrollbar_click
,
3501 &Qhscrollbar_part
, "hscrollbar-part", &Qscrollbar_click
,
3502 &Qhslider_part
, "hslider-part", &Qscrollbar_click
,
3503 &Qhthumbleft_part
, "hthumbleft-part", &Qscrollbar_click
,
3504 &Qhthumbright_part
,"hthumbright-part", &Qscrollbar_click
3509 Qself_insert_command
= intern ("self-insert-command");
3510 staticpro (&Qself_insert_command
);
3512 Qforward_char
= intern ("forward-char");
3513 staticpro (&Qforward_char
);
3515 Qbackward_char
= intern ("backward-char");
3516 staticpro (&Qbackward_char
);
3518 Qdisabled
= intern ("disabled");
3519 staticpro (&Qdisabled
);
3521 Qfunction_key
= intern ("function-key");
3522 staticpro (&Qfunction_key
);
3523 Qmouse_movement
= intern ("mouse-click");
3524 staticpro (&Qmouse_click
);
3525 Qmouse_movement
= intern ("scrollbar-click");
3526 staticpro (&Qmouse_movement
);
3528 Qmode_line
= intern ("mode-line");
3529 staticpro (&Qmode_line
);
3530 Qvertical_line
= intern ("vertical-line");
3531 staticpro (&Qvertical_line
);
3533 Qevent_kind
= intern ("event-type");
3534 staticpro (&Qevent_kind
);
3535 Qevent_unmodified
= intern ("event-unmodified");
3536 staticpro (&Qevent_unmodified
);
3539 struct event_head
*p
;
3541 for (p
= head_table
;
3542 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
3545 *p
->var
= intern (p
->name
);
3547 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
3548 Fput (*p
->var
, Qevent_unmodified
, *p
->var
);
3552 func_key_syms
= Qnil
;
3553 staticpro (&func_key_syms
);
3556 staticpro (&mouse_syms
);
3558 defsubr (&Sread_key_sequence
);
3559 defsubr (&Srecursive_edit
);
3560 defsubr (&Strack_mouse
);
3561 defsubr (&Smouse_click_p
);
3562 defsubr (&Sinput_pending_p
);
3563 defsubr (&Scommand_execute
);
3564 defsubr (&Srecent_keys
);
3565 defsubr (&Sthis_command_keys
);
3566 defsubr (&Ssuspend_emacs
);
3567 defsubr (&Sabort_recursive_edit
);
3568 defsubr (&Sexit_recursive_edit
);
3569 defsubr (&Srecursion_depth
);
3570 defsubr (&Stop_level
);
3571 defsubr (&Sdiscard_input
);
3572 defsubr (&Sopen_dribble_file
);
3573 defsubr (&Sset_input_mode
);
3574 defsubr (&Sexecute_extended_command
);
3576 DEFVAR_LISP ("disabled-command-hook", &Vdisabled_command_hook
,
3577 "Value is called instead of any command that is disabled\n\
3578 (has a non-nil `disabled' property).");
3580 DEFVAR_LISP ("last-command-char", &last_command_char
,
3581 "Last terminal input key that was part of a command.");
3583 DEFVAR_LISP ("last-input-char", &last_input_char
,
3584 "Last terminal input key.");
3586 DEFVAR_LISP ("unread-command-char", &unread_command_char
,
3587 "Object to be read as next input from input stream, or nil if none.");
3589 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
3590 "Meta-prefix character code. Meta-foo as command input\n\
3591 turns into this character followed by foo.");
3592 XSET (meta_prefix_char
, Lisp_Int
, 033);
3594 DEFVAR_LISP ("last-command", &last_command
,
3595 "The last command executed. Normally a symbol with a function definition,\n\
3596 but can be whatever was found in the keymap, or whatever the variable\n\
3597 `this-command' was set to by that command.");
3598 last_command
= Qnil
;
3600 DEFVAR_LISP ("this-command", &this_command
,
3601 "The command now being executed.\n\
3602 The command can set this variable; whatever is put here\n\
3603 will be in `last-command' during the following command.");
3604 this_command
= Qnil
;
3606 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
3607 "*Number of keyboard input characters between auto-saves.\n\
3608 Zero means disable autosaving due to number of characters typed.");
3609 auto_save_interval
= 300;
3611 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
3612 "*Number of seconds idle time before auto-save.\n\
3613 Zero or nil means disable auto-saving due to idleness.\n\
3614 After auto-saving due to this many seconds of idle time,\n\
3615 Emacs also does a garbage collection if that seems to be warranted.");
3616 XFASTINT (Vauto_save_timeout
) = 30;
3618 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes
,
3619 "*Nonzero means echo unfinished commands after this many seconds of pause.");
3620 echo_keystrokes
= 1;
3622 DEFVAR_INT ("polling-period", &polling_period
,
3623 "*Interval between polling for input during Lisp execution.\n\
3624 The reason for polling is to make C-g work to stop a running program.\n\
3625 Polling is needed only when using X windows and SIGIO does not work.\n\
3626 Polling is automatically disabled in all other cases.");
3629 DEFVAR_INT ("num-input-keys", &num_input_keys
,
3630 "*Number of complete keys read from the keyboard so far.");
3633 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
3634 "*The frame in which the most recently read event occurred.");
3635 Vlast_event_frame
= Qnil
;
3637 DEFVAR_LISP ("help-char", &help_char
,
3638 "Character to recognize as meaning Help.\n\
3639 When it is read, do `(eval help-form)', and display result if it's a string.\n\
3640 If the value of `help-form' is nil, this char can be read normally.");
3641 XSET (help_char
, Lisp_Int
, Ctl ('H'));
3643 DEFVAR_LISP ("help-form", &Vhelp_form
,
3644 "Form to execute when character help-char is read.\n\
3645 If the form returns a string, that string is displayed.\n\
3646 If `help-form' is nil, the help char is not recognized.");
3649 DEFVAR_LISP ("top-level", &Vtop_level
,
3650 "Form to evaluate when Emacs starts up.\n\
3651 Useful to set before you dump a modified Emacs.");
3654 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
3655 "String used as translate table for keyboard input, or nil.\n\
3656 Each character is looked up in this string and the contents used instead.\n\
3657 If string is of length N, character codes N and up are untranslated.");
3658 Vkeyboard_translate_table
= Qnil
;
3660 #ifdef HAVE_X_WINDOWS
3661 DEFVAR_LISP ("mouse-event-function", &Vmouse_event_function
,
3662 "Function to call for each mouse event, after the event's definition.\n\
3663 Called, if non-nil, with one argument, which is the event-list.\n\
3664 See the variable `mouse-event' for the format of this list.");
3665 Vmouse_event_function
= Qnil
;
3667 DEFVAR_LISP ("mouse-left-hook", &Vmouse_left_hook
,
3668 "Function to call when mouse leaves window. No arguments.");
3669 Vmouse_left_hook
= Qnil
;
3671 DEFVAR_LISP ("map-frame-hook", &Vmap_frame_hook
,
3672 "Function to call when frame is mapped. No arguments.");
3673 Vmap_frame_hook
= Qnil
;
3675 DEFVAR_LISP ("unmap-frame-hook", &Vunmap_frame_hook
,
3676 "Function to call when frame is unmapped. No arguments.");
3677 Vunmap_frame_hook
= Qnil
;
3679 DEFVAR_LISP ("mouse-motion-handler", &Vmouse_motion_handler
,
3680 "Handler for motion events. No arguments.");
3681 Vmouse_motion_handler
= Qnil
;
3684 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
3685 "Non-nil means prompt with menus in echo area when appropriate.\n\
3686 This is done when reading from a keymap that has a prompt string,\n\
3687 for elements that have prompt strings.");
3690 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
3691 "Character to see next line of menu prompt.\n\
3692 Type this character while in a menu prompt to rotate around the lines of it.");
3693 XSET (menu_prompt_more_char
, Lisp_Int
, ' ');
3698 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
3699 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
3700 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
3701 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
3702 initial_define_key (meta_map
, 'x', "execute-extended-command");