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
; /* A vector, holding the 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 as a command, not counting menus
145 reached by the mouse. */
146 Lisp_Object last_nonmenu_event
;
148 /* Last input character read for any purpose. */
149 Lisp_Object last_input_char
;
151 /* If not Qnil, an object to be read as the next command input. */
152 Lisp_Object unread_command_char
;
154 /* Char to use as prefix when a meta character is typed in.
155 This is bound on entry to minibuffer in case ESC is changed there. */
157 Lisp_Object meta_prefix_char
;
159 /* Last size recorded for a current buffer which is not a minibuffer. */
160 static int last_non_minibuf_size
;
162 /* Number of idle seconds before an auto-save and garbage collection. */
163 static Lisp_Object Vauto_save_timeout
;
165 /* Total number of times read_char has returned. */
168 /* Total number of times read_char has returned, outside of macros. */
169 int num_nonmacro_input_chars
;
171 /* Auto-save automatically when this many characters have been typed
172 since the last time. */
174 static int auto_save_interval
;
176 /* Value of num_nonmacro_input_chars as of last auto save. */
180 /* Last command executed by the editor command loop, not counting
181 commands that set the prefix argument. */
183 Lisp_Object last_command
;
185 /* The command being executed by the command loop.
186 Commands may set this, and the value set will be copied into last_command
187 instead of the actual command. */
188 Lisp_Object this_command
;
191 /* The frame in which the last input event occurred, or Qmacro if the
192 last event came from a macro.
193 command_loop_1 will select this frame before running the
194 command bound to an event sequence, and read_key_sequence will
195 toss the existing prefix if the user starts typing at a
197 Lisp_Object Vlast_event_frame
;
200 /* The timestamp of the last input event we received from the X server.
201 X Windows wants this for selection ownership. */
202 unsigned long last_event_timestamp
;
204 Lisp_Object Qself_insert_command
;
205 Lisp_Object Qforward_char
;
206 Lisp_Object Qbackward_char
;
208 /* read_key_sequence stores here the command definition of the
209 key sequence that it reads. */
210 Lisp_Object read_key_sequence_cmd
;
212 /* Form to evaluate (if non-nil) when Emacs is started. */
213 Lisp_Object Vtop_level
;
215 /* User-supplied string to translate input characters through. */
216 Lisp_Object Vkeyboard_translate_table
;
218 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
219 extern Lisp_Object Vfunction_key_map
;
221 /* File in which we write all commands we read. */
224 /* Nonzero if input is available. */
227 /* Nonzero if should obey 0200 bit in input chars as "Meta". */
230 extern char *pending_malloc_warning
;
232 /* Circular buffer for pre-read keyboard input. */
233 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
235 /* Pointer to next available character in kbd_buffer.
236 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
237 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the
238 next available char is in kbd_buffer[0]. */
239 static struct input_event
*kbd_fetch_ptr
;
241 /* Pointer to next place to store character in kbd_buffer. This
242 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
243 character should go in kbd_buffer[0]. */
244 static struct input_event
*kbd_store_ptr
;
246 /* The above pair of variables forms a "queue empty" flag. When we
247 enqueue a non-hook event, we increment kbd_write_count. When we
248 dequeue a non-hook event, we increment kbd_read_count. We say that
249 there is input available iff the two counters are equal.
251 Why not just have a flag set and cleared by the enqueuing and
252 dequeuing functions? Such a flag could be screwed up by interrupts
253 at inopportune times. */
255 /* If this flag is non-zero, mouse movement events will appear in the
256 input stream. If is zero, mouse movement will be ignored. */
257 int do_mouse_tracking
;
259 /* The window system handling code should set this if the mouse has
260 moved since the last call to the mouse_position_hook. Calling that
261 hook should clear this. Code assumes that if this is set, it can
262 call mouse_position_hook to get the promised position, so don't set
263 it unless you're prepared to substantiate the claim! */
266 /* True iff there is an event in kbd_buffer, or if mouse tracking is
267 enabled and there is a new mouse position in the mouse movement
268 buffer. Note that if this is false, that doesn't mean that there
269 is readable input; all the events in the queue might be button-up
270 events, and do_mouse_tracking might be off. */
271 #define EVENT_QUEUES_EMPTY \
272 ((kbd_fetch_ptr == kbd_store_ptr) && (!do_mouse_tracking || !mouse_moved))
275 /* Symbols to head events. */
276 Lisp_Object Qmouse_movement
;
278 Lisp_Object Qvscrollbar_part
;
279 Lisp_Object Qvslider_part
;
280 Lisp_Object Qvthumbup_part
;
281 Lisp_Object Qvthumbdown_part
;
283 Lisp_Object Qhscrollbar_part
;
284 Lisp_Object Qhslider_part
;
285 Lisp_Object Qhthumbleft_part
;
286 Lisp_Object Qhthumbright_part
;
288 /* Symbols to denote kinds of events. */
289 Lisp_Object Qfunction_key
;
290 Lisp_Object Qmouse_click
;
291 /* Lisp_Object Qmouse_movement; - also an event header */
292 Lisp_Object Qscrollbar_click
;
294 /* Properties of event headers. */
295 Lisp_Object Qevent_kind
;
296 Lisp_Object Qevent_unmodified
;
298 /* Symbols to use for non-text mouse positions. */
299 Lisp_Object Qmode_line
;
300 Lisp_Object Qvertical_line
;
303 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
305 EMACS_TIME
*input_available_clear_time
;
307 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
308 Default is 1 if INTERRUPT_INPUT is defined. */
311 /* Nonzero while interrupts are temporarily deferred during redisplay. */
312 int interrupts_deferred
;
314 /* nonzero means use ^S/^Q for flow control. */
317 /* Allow m- file to inhibit use of FIONREAD. */
318 #ifdef BROKEN_FIONREAD
322 /* We are unable to use interrupts if FIONREAD is not available,
323 so flush SIGIO so we won't try. */
330 /* If we support X Windows, and won't get an interrupt when input
331 arrives from the server, poll periodically so we can detect C-g. */
332 #ifdef HAVE_X_WINDOWS
334 #define POLL_FOR_INPUT
338 /* Global variable declarations. */
340 /* Function for init_keyboard to call with no args (if nonzero). */
341 void (*keyboard_init_hook
) ();
343 static int read_avail_input ();
344 static void get_input_pending ();
346 /* > 0 if we are to echo keystrokes. */
347 static int echo_keystrokes
;
349 /* Nonzero means echo each character as typed. */
350 static int immediate_echo
;
352 /* The text we're echoing in the modeline - partial key sequences,
353 usually. '\0'-terminated. */
354 static char echobuf
[100];
356 /* Where to append more text to echobuf if we want to. */
357 static char *echoptr
;
359 #define min(a,b) ((a)<(b)?(a):(b))
360 #define max(a,b) ((a)>(b)?(a):(b))
362 /* Install the string STR as the beginning of the string of echoing,
363 so that it serves as a prompt for the next character.
364 Also start echoing. */
369 int len
= strlen (str
);
370 if (len
> sizeof echobuf
- 4)
371 len
= sizeof echobuf
- 4;
372 bcopy (str
, echobuf
, len
+ 1);
373 echoptr
= echobuf
+ len
;
378 /* Add C to the echo string, if echoing is going on.
379 C can be a character, which is printed prettily ("M-C-x" and all that
380 jazz), or a symbol, whose name is printed. */
385 extern char *push_key_description ();
394 /* If someone has passed us a composite event, use its head symbol. */
395 if (EVENT_HAS_PARAMETERS (c
))
398 if (XTYPE (c
) == Lisp_Int
)
400 if (ptr
- echobuf
> sizeof echobuf
- 6)
403 ptr
= push_key_description (c
, ptr
);
405 else if (XTYPE (c
) == Lisp_Symbol
)
407 struct Lisp_String
*name
= XSYMBOL (c
)->name
;
408 if (((ptr
- echobuf
) + name
->size
+ 4) > sizeof echobuf
)
410 bcopy (name
->data
, ptr
, name
->size
);
414 if (echoptr
== echobuf
&& c
== help_char
)
416 strcpy (ptr
, " (Type ? for further options)");
427 /* Temporarily add a dash to the end of the echo string if it's not
428 empty, so that it serves as a mini-prompt for the very next character. */
432 if (!immediate_echo
&& echoptr
== echobuf
)
435 /* Put a dash at the end of the buffer temporarily,
436 but make it go away when the next character is added. */
443 /* Display the current echo string, and begin echoing if not already
453 for (i
= 0; i
< this_command_key_count
; i
++)
454 echo_char (this_command_keys
[i
]);
462 if (waiting_for_input
&& !NILP (Vquit_flag
))
463 quit_throw_to_read_char ();
466 /* Turn off echoing, for the start of a new command. */
474 /* Return the length of the current echo string. */
479 return echoptr
- echobuf
;
482 /* Truncate the current echo message to its first LEN chars.
483 This and echo_char get used by read_key_sequence when the user
484 switches frames while entering a key sequence. */
491 echoptr
= echobuf
+ strlen (echobuf
);
495 /* Functions for manipulating this_command_keys. */
497 add_command_key (key
)
500 if (this_command_key_count
== this_command_keys_size
)
502 this_command_keys_size
*= 2;
504 = (Lisp_Object
*) xrealloc (this_command_keys
,
505 (this_command_keys_size
506 * sizeof (Lisp_Object
)));
508 this_command_keys
[this_command_key_count
++] = key
;
514 int count
= specpdl_ptr
- specpdl
;
517 if (command_loop_level
> 0)
519 specbind (Qstandard_output
, Qt
);
520 specbind (Qstandard_input
, Qt
);
523 val
= command_loop ();
525 Fsignal (Qquit
, Qnil
);
531 /* When an auto-save happens, record the "time", and don't do again soon. */
534 last_auto_save
= num_nonmacro_input_chars
;
537 Lisp_Object
recursive_edit_unwind (), command_loop ();
539 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
540 "Invoke the editor command loop recursively.\n\
541 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
542 that tells this function to return.\n\
543 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
544 This function is called by the editor initialization to begin editing.")
547 int count
= specpdl_ptr
- specpdl
;
550 command_loop_level
++;
551 update_mode_lines
= 1;
553 record_unwind_protect (recursive_edit_unwind
,
555 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
559 return unbind_to (count
, Qnil
);
563 recursive_edit_unwind (buffer
)
567 Fset_buffer (buffer
);
569 command_loop_level
--;
570 update_mode_lines
= 1;
578 Lisp_Object errmsg
, tail
, errname
, file_error
;
585 Vstandard_output
= Qt
;
586 Vstandard_input
= Qt
;
587 Vexecuting_macro
= Qnil
;
588 echo_area_glyphs
= 0;
590 /* If the window system or terminal frame hasn't been initialized
591 yet, or we're not interactive, it's best to dump this message out
592 to stderr and exit. */
593 if (! FRAME_MESSAGE_BUF (selected_frame
)
595 stream
= Qexternal_debugging_output
;
603 errname
= Fcar (data
);
605 if (EQ (errname
, Qerror
))
608 if (!CONSP (data
)) data
= Qnil
;
609 errmsg
= Fcar (data
);
614 errmsg
= Fget (errname
, Qerror_message
);
615 file_error
= Fmemq (Qfile_error
,
616 Fget (errname
, Qerror_conditions
));
619 /* Print an error message including the data items.
620 This is done by printing it into a scratch buffer
621 and then making a copy of the text in the buffer. */
623 if (!CONSP (data
)) data
= Qnil
;
627 /* For file-error, make error message by concatenating
628 all the data items. They are all strings. */
629 if (!NILP (file_error
) && !NILP (tail
))
630 errmsg
= XCONS (tail
)->car
, tail
= XCONS (tail
)->cdr
;
632 if (XTYPE (errmsg
) == Lisp_String
)
633 Fprinc (errmsg
, stream
);
635 write_string_1 ("peculiar error", -1, stream
);
637 for (i
= 0; CONSP (tail
); tail
= Fcdr (tail
), i
++)
639 write_string_1 (i
? ", " : ": ", 2, stream
);
640 if (!NILP (file_error
))
641 Fprinc (Fcar (tail
), stream
);
643 Fprin1 (Fcar (tail
), stream
);
647 /* If the window system or terminal frame hasn't been initialized
648 yet, or we're in -batch mode, this error should cause Emacs to exit. */
649 if (! FRAME_MESSAGE_BUF (selected_frame
)
653 Fkill_emacs (make_number (-1));
658 Vinhibit_quit
= Qnil
;
659 return make_number (0);
662 Lisp_Object
command_loop_1 ();
663 Lisp_Object
command_loop_2 ();
664 Lisp_Object
top_level_1 ();
666 /* Entry to editor-command-loop.
667 This level has the catches for exiting/returning to editor command loop.
668 It returns nil to exit recursive edit, t to abort it. */
673 if (command_loop_level
> 0 || minibuf_level
> 0)
675 return internal_catch (Qexit
, command_loop_2
, Qnil
);
680 internal_catch (Qtop_level
, top_level_1
, Qnil
);
681 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
683 /* End of file in -batch run causes exit here. */
689 /* Here we catch errors in execution of commands within the
690 editing loop, and reenter the editing loop.
691 When there is an error, cmd_error runs and returns a non-nil
692 value to us. A value of nil means that cmd_loop_1 itself
693 returned due to end of file (or end of kbd macro). */
698 register Lisp_Object val
;
701 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
710 return Feval (Vtop_level
);
716 /* On entry to the outer level, run the startup file */
717 if (!NILP (Vtop_level
))
718 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
719 else if (!NILP (Vpurify_flag
))
720 message ("Bare impure Emacs (standard Lisp code not loaded)");
722 message ("Bare Emacs (standard Lisp code not loaded)");
726 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
727 "Exit all recursive editing levels.")
730 Fthrow (Qtop_level
, Qnil
);
733 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
734 "Exit from the innermost recursive edit or minibuffer.")
737 if (command_loop_level
> 0 || minibuf_level
> 0)
738 Fthrow (Qexit
, Qnil
);
740 error ("No recursive edit is in progress");
743 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
744 "Abort the command that requested this recursive edit or minibuffer input.")
747 if (command_loop_level
> 0 || minibuf_level
> 0)
750 error ("No recursive edit is in progress");
753 /* This is the actual command reading loop,
754 sans error-handling encapsulation. */
756 Lisp_Object
Fcommand_execute ();
757 static int read_key_sequence ();
765 Lisp_Object keybuf
[30];
771 waiting_for_input
= 0;
774 /* Don't clear out last_command at the beginning of a macro. */
775 if (XTYPE (Vexecuting_macro
) != Lisp_String
)
780 this_command_key_count
= 0;
784 /* Install chars successfully executed in kbd macro. */
786 if (defining_kbd_macro
&& NILP (Vprefix_arg
))
787 finalize_kbd_macro_chars ();
789 /* Make sure the current window's buffer is selected. */
790 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
791 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
793 /* Display any malloc warning that just came out. Use while because
794 displaying one warning can cause another. */
796 while (pending_malloc_warning
)
797 display_malloc_warning ();
801 /* If minibuffer on and echo area in use,
802 wait 2 sec and redraw minibufer. */
804 if (minibuf_level
&& echo_area_glyphs
)
806 /* Bind inhibit-quit to t so that C-g gets read in
807 rather than quitting back to the minibuffer. */
808 int count
= specpdl_ptr
- specpdl
;
809 specbind (Qinhibit_quit
, Qt
);
810 Fsit_for (make_number (2), Qnil
, Qnil
);
813 echo_area_glyphs
= 0;
815 if (!NILP (Vquit_flag
))
818 unread_command_char
= make_number (quit_char
);
823 alloca (0); /* Cause a garbage collection now */
824 /* Since we can free the most stuff here. */
825 #endif /* C_ALLOCA */
827 /* Read next key sequence; i gets its length. */
828 i
= read_key_sequence (keybuf
, (sizeof keybuf
/ sizeof (keybuf
[0])), 0);
833 /* Select the frame that the key sequence came from. */
834 if (XTYPE (Vlast_event_frame
) == Lisp_Frame
835 && XFRAME (Vlast_event_frame
) != selected_frame
)
836 Fselect_frame (Vlast_event_frame
, Qnil
);
839 /* Now we have read a key sequence of length I,
840 or else I is 0 and we found end of file. */
842 if (i
== 0) /* End of file -- happens only in */
843 return Qnil
; /* a kbd macro, at the end. */
845 last_command_char
= keybuf
[i
- 1];
847 cmd
= read_key_sequence_cmd
;
848 if (!NILP (Vexecuting_macro
))
850 if (!NILP (Vquit_flag
))
852 Vexecuting_macro
= Qt
;
853 QUIT
; /* Make some noise. */
854 /* Will return since macro now empty. */
858 /* Do redisplay processing after this command except in special
859 cases identified below that set no_redisplay to 1. */
862 /* Execute the command. */
866 /* nil means key is undefined. */
868 defining_kbd_macro
= 0;
869 update_mode_lines
= 1;
875 if (NILP (Vprefix_arg
) && ! no_direct
)
877 /* Recognize some common commands in common situations and
879 if (EQ (cmd
, Qforward_char
) && point
< ZV
)
881 struct Lisp_Vector
*dp
882 = window_display_table (XWINDOW (selected_window
));
883 lose
= FETCH_CHAR (point
);
885 if (((dp
== 0 && lose
>= 040 && lose
< 0177)
887 (dp
&& (XTYPE (dp
->contents
[lose
]) != Lisp_String
888 || XSTRING (dp
->contents
[lose
])->size
== sizeof (GLYPH
))))
889 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
891 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
893 && !windows_or_buffers_changed
894 && EQ (current_buffer
->selective_display
, Qnil
)
895 && !detect_input_pending ()
896 && NILP (Vexecuting_macro
))
897 no_redisplay
= direct_output_forward_char (1);
900 else if (EQ (cmd
, Qbackward_char
) && point
> BEGV
)
902 struct Lisp_Vector
*dp
903 = window_display_table (XWINDOW (selected_window
));
905 lose
= FETCH_CHAR (point
);
906 if (((dp
== 0 && lose
>= 040 && lose
< 0177)
908 (dp
&& (XTYPE (dp
->contents
[lose
]) != Lisp_String
909 || XSTRING (dp
->contents
[lose
])->size
== sizeof (GLYPH
))))
910 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
912 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
914 && !windows_or_buffers_changed
915 && EQ (current_buffer
->selective_display
, Qnil
)
916 && !detect_input_pending ()
917 && NILP (Vexecuting_macro
))
918 no_redisplay
= direct_output_forward_char (-1);
921 else if (EQ (cmd
, Qself_insert_command
)
922 /* Try this optimization only on ascii keystrokes. */
923 && XTYPE (last_command_char
) == Lisp_Int
)
925 unsigned char c
= XINT (last_command_char
);
927 if (NILP (Vexecuting_macro
) &&
928 !EQ (minibuf_window
, selected_window
))
930 if (!nonundocount
|| nonundocount
>= 20)
937 lose
= (XFASTINT (XWINDOW (selected_window
)->last_modified
)
939 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
941 || MODIFF
<= current_buffer
->save_modified
942 || windows_or_buffers_changed
943 || !EQ (current_buffer
->selective_display
, Qnil
)
944 || detect_input_pending ()
945 || !NILP (Vexecuting_macro
);
946 if (internal_self_insert (c
, 0))
952 (point
== ZV
|| FETCH_CHAR (point
) == '\n'))
954 struct Lisp_Vector
*dp
955 = window_display_table (XWINDOW (selected_window
));
957 if (dp
== 0 || XTYPE (dp
->contents
[c
]) != Lisp_String
)
958 no_redisplay
= direct_output_for_insert (c
);
959 else if (XSTRING (dp
->contents
[c
])->size
962 direct_output_for_insert (*(GLYPH
*)XSTRING (dp
->contents
[c
])->data
);
968 /* Here for a command that isn't executed directly */
971 if (NILP (Vprefix_arg
))
973 Fcommand_execute (cmd
, Qnil
);
978 /* If there is a prefix argument,
979 1) We don't want last_command to be ``universal-argument''
980 (that would be dumb), so don't set last_command,
981 2) we want to leave echoing on so that the prefix will be
982 echoed as part of this key sequence, so don't call
984 3) we want to leave this_command_key_count non-zero, so that
985 read_char will realize that it is re-reading a character, and
986 not echo it a second time. */
987 if (NILP (Vprefix_arg
))
989 last_command
= this_command
;
991 this_command_key_count
= 0;
996 /* Number of seconds between polling for input. */
999 /* Nonzero means polling for input is temporarily suppresed. */
1000 int poll_suppress_count
;
1002 #ifdef POLL_FOR_INPUT
1003 int polling_for_input
;
1005 /* Handle an alarm once each second and read pending input
1006 so as to handle a C-g if it comces in. */
1009 input_poll_signal ()
1011 #ifdef HAVE_X_WINDOWS
1012 extern int x_input_blocked
;
1013 if (x_input_blocked
== 0)
1015 if (!waiting_for_input
)
1016 read_avail_input (0);
1017 signal (SIGALRM
, input_poll_signal
);
1018 alarm (polling_period
);
1023 /* Begin signals to poll for input, if they are appropriate.
1024 This function is called unconditionally from various places. */
1028 #ifdef POLL_FOR_INPUT
1029 if (read_socket_hook
)
1031 poll_suppress_count
--;
1032 if (poll_suppress_count
== 0)
1034 signal (SIGALRM
, input_poll_signal
);
1035 polling_for_input
= 1;
1036 alarm (polling_period
);
1042 /* Turn off polling. */
1046 #ifdef POLL_FOR_INPUT
1047 if (read_socket_hook
)
1049 if (poll_suppress_count
== 0)
1051 polling_for_input
= 0;
1054 poll_suppress_count
++;
1059 /* Input of single characters from keyboard */
1061 Lisp_Object
print_help ();
1062 static Lisp_Object
kbd_buffer_get_event ();
1064 /* read a character from the keyboard; call the redisplay if needed */
1065 /* commandflag 0 means do not do auto-saving, but do do redisplay.
1066 -1 means do not do redisplay, but do do autosaving.
1069 /* The arguments MAPS and NMAPS are for menu prompting.
1070 MAPS is an array of keymaps; NMAPS is the length of MAPS.
1072 PREV_EVENT is the previous input event, or nil if we are reading
1073 the first event of a key sequence.
1075 If we use a mouse menu to read the input, we store 1 into *USED_MOUSE_MENU.
1076 Otherwise we store 0 there. */
1079 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
)
1083 Lisp_Object prev_event
;
1084 int *used_mouse_menu
;
1086 register Lisp_Object c
;
1090 if (!NILP (unread_command_char
))
1092 c
= unread_command_char
;
1093 unread_command_char
= Qnil
;
1095 if (this_command_key_count
== 0)
1101 if (!NILP (Vexecuting_macro
))
1103 /* We set this to Qmacro; since that's not a frame, nobody will
1104 try to switch frames on us, and the selected window will
1107 Since this event came from a macro, it would be misleading to
1108 leave Vlast_event_frame set to whereever the last real event
1109 came from. Normally, command_loop_1 selects
1110 Vlast_event_frame after each command is read, but events read
1111 from a macro should never cause a new frame to be selected. */
1112 Vlast_event_frame
= Qmacro
;
1114 if (executing_macro_index
>= Flength (Vexecuting_macro
))
1116 XSET (c
, Lisp_Int
, -1);
1120 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
1121 executing_macro_index
++;
1126 /* Save outer setjmp data, in case called recursively. */
1127 save_getcjmp (save_jump
);
1131 if (commandflag
>= 0 && !input_pending
&& !detect_input_pending ())
1134 if (_setjmp (getcjmp
))
1136 XSET (c
, Lisp_Int
, quit_char
);
1138 XSET (Vlast_event_frame
, Lisp_Frame
, selected_frame
);
1144 /* Message turns off echoing unless more keystrokes turn it on again. */
1145 if (echo_area_glyphs
&& *echo_area_glyphs
&& echo_area_glyphs
!= echobuf
)
1148 /* If already echoing, continue. */
1151 /* If in middle of key sequence and minibuffer not active,
1152 start echoing if enough time elapses. */
1153 if (minibuf_level
== 0 && !immediate_echo
&& this_command_key_count
> 0
1154 && echo_keystrokes
> 0
1155 && (echo_area_glyphs
== 0 || *echo_area_glyphs
== 0))
1159 /* After a mouse event, start echoing right away.
1160 This is because we are probably about to display a menu,
1161 and we don't want to delay before doing so. */
1162 if (XTYPE (prev_event
) == Lisp_Cons
)
1166 tem0
= sit_for (echo_keystrokes
, 0, 1, 1);
1172 /* Maybe auto save due to number of keystrokes or idle time. */
1174 if (commandflag
!= 0
1175 && auto_save_interval
> 0
1176 && num_nonmacro_input_chars
- last_auto_save
> max (auto_save_interval
, 20)
1177 && !detect_input_pending ())
1180 save_getcjmp (temp
);
1181 Fdo_auto_save (Qnil
, Qnil
);
1182 restore_getcjmp (temp
);
1185 /* Try reading a character via menu prompting.
1186 Try this before the sit-for, because the sit-for
1187 would do the wrong thing if we are supposed to do
1190 if (INTERACTIVE
&& !NILP (prev_event
))
1191 c
= read_char_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
1193 /* Slow down auto saves logarithmically in size of current buffer,
1194 and garbage collect while we're at it. */
1197 int delay_level
, buffer_size
;
1199 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
1200 last_non_minibuf_size
= Z
- BEG
;
1201 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
1203 while (buffer_size
> 64)
1204 delay_level
++, buffer_size
-= buffer_size
>> 2;
1205 if (delay_level
< 4) delay_level
= 4;
1206 /* delay_level is 4 for files under around 50k, 7 at 100k,
1207 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
1209 /* Auto save if enough time goes by without input. */
1210 if (commandflag
!= 0
1211 && num_nonmacro_input_chars
> last_auto_save
1212 && XTYPE (Vauto_save_timeout
) == Lisp_Int
1213 && XINT (Vauto_save_timeout
) > 0)
1216 int delay
= delay_level
* XFASTINT (Vauto_save_timeout
) / 4;
1217 tem0
= sit_for (delay
, 0, 1, 1);
1221 save_getcjmp (temp
);
1222 Fdo_auto_save (Qnil
, Qnil
);
1223 restore_getcjmp (temp
);
1225 /* If we have auto-saved and there is still no input
1226 available, garbage collect if there has been enough
1227 consing going on to make it worthwhile. */
1228 if (!detect_input_pending ()
1229 && consing_since_gc
> gc_cons_threshold
/ 2)
1230 Fgarbage_collect ();
1235 /* Actually read a character, waiting if necessary. */
1237 c
= kbd_buffer_get_event ();
1240 abort (); /* Don't think this can happen. */
1242 /* Terminate Emacs in batch mode if at eof. */
1243 if (noninteractive
&& XTYPE (c
) == Lisp_Int
&& XINT (c
) < 0)
1244 Fkill_emacs (make_number (1));
1248 restore_getcjmp (save_jump
);
1252 echo_area_glyphs
= 0;
1254 /* Handle things that only apply to characters. */
1255 if (XTYPE (c
) == Lisp_Int
)
1257 /* If kbd_buffer_get_event gave us an EOF, return that. */
1261 /* Strip the high bits, and maybe the meta bit too. */
1262 XSETINT (c
, c
& (meta_key
? 0377 : 0177));
1264 if (XTYPE (Vkeyboard_translate_table
) == Lisp_String
1265 && XSTRING (Vkeyboard_translate_table
)->size
> XINT (c
))
1266 XSETINT (c
, XSTRING (Vkeyboard_translate_table
)->data
[c
]);
1270 XVECTOR (recent_keys
)->contents
[recent_keys_index
] = c
;
1271 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
1272 recent_keys_index
= 0;
1274 /* Write c to the dribble file. If c is a lispy event, write
1275 the event's symbol to the dribble file, in <brackets>. Bleaugh.
1276 If you, dear reader, have a better idea, you've got the source. :-) */
1279 if (XTYPE (c
) == Lisp_Int
)
1283 Lisp_Object dribblee
= c
;
1285 /* If it's a structured event, take the event header. */
1286 if (EVENT_HAS_PARAMETERS (dribblee
))
1287 dribblee
= EVENT_HEAD (dribblee
);
1289 if (XTYPE (c
) == Lisp_Symbol
)
1291 putc ('<', dribble
);
1292 fwrite (XSYMBOL (c
)->name
->data
, sizeof (char),
1293 XSYMBOL (c
)->name
->size
,
1295 putc ('>', dribble
);
1302 store_kbd_macro_char (c
);
1304 num_nonmacro_input_chars
++;
1310 /* Record this character as part of the current key. */
1311 add_command_key (c
);
1313 /* Re-reading in the middle of a command */
1315 last_input_char
= c
;
1318 /* Process the help character specially if enabled */
1319 if (EQ (c
, help_char
) && !NILP (Vhelp_form
))
1322 count
= specpdl_ptr
- specpdl
;
1324 record_unwind_protect (Fset_window_configuration
,
1325 Fcurrent_window_configuration (Qnil
));
1327 tem0
= Feval (Vhelp_form
);
1328 if (XTYPE (tem0
) == Lisp_String
)
1329 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
1333 /* Remove the help from the frame */
1334 unbind_to (count
, Qnil
);
1336 if (EQ (c
, make_number (040)))
1339 c
= read_char (0, 0, 0, Qnil
, 0);
1350 Fprinc (object
, Qnil
);
1354 /* Copy out or in the info on where C-g should throw to.
1355 This is used when running Lisp code from within get_char,
1356 in case get_char is called recursively.
1357 See read_process_output. */
1362 bcopy (getcjmp
, temp
, sizeof getcjmp
);
1365 restore_getcjmp (temp
)
1368 bcopy (temp
, getcjmp
, sizeof getcjmp
);
1372 /* Low level keyboard/mouse input.
1373 kbd_buffer_store_event places events in kbd_buffer, and
1374 kbd_buffer_get_event retrieves them.
1375 mouse_moved indicates when the mouse has moved again, and
1376 *mouse_position_hook provides the mouse position. */
1378 /* Set this for debugging, to have a way to get out */
1381 extern int frame_garbaged
;
1383 /* Return true iff there are any events in the queue that read-char
1384 would return. If this returns false, a read-char would block. */
1388 struct input_event
*ep
;
1390 if (EVENT_QUEUES_EMPTY
)
1393 if (do_mouse_tracking
)
1396 /* Mouse tracking is disabled, so we need to actually scan the
1397 input queue to see if any events are currently readable. */
1398 for (ep
= kbd_fetch_ptr
; ep
!= kbd_store_ptr
; ep
++)
1400 if (ep
== kbd_buffer
+ KBD_BUFFER_SIZE
)
1403 /* Skip button-up events. */
1404 if ((ep
->kind
== mouse_click
|| ep
->kind
== scrollbar_click
)
1405 && (ep
->modifiers
& up_modifier
))
1415 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
1416 of this function. */
1418 tracking_off (old_value
)
1419 Lisp_Object old_value
;
1421 if (! XFASTINT (old_value
))
1423 do_mouse_tracking
= 0;
1425 /* Redisplay may have been preempted because there was input
1426 available, and it assumes it will be called again after the
1427 input has been processed. If the only input available was
1428 the sort that we have just disabled, then we need to call
1430 if (!readable_events ())
1432 redisplay_preserve_echo_area ();
1433 get_input_pending (&input_pending
);
1438 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
1439 "Evaluate BODY with mouse movement and button release events enabled.\n\
1440 Within a `track-mouse', mouse motion and button releases generate input\n\
1441 events that you can read with `read-event'.\n\
1442 Normally, these occurrences don't generate events.")
1446 int count
= specpdl_ptr
- specpdl
;
1449 XSET (val
, Lisp_Int
, do_mouse_tracking
);
1450 record_unwind_protect (tracking_off
, val
);
1452 do_mouse_tracking
= 1;
1454 val
= Fprogn (args
);
1455 return unbind_to (count
, val
);
1458 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
1461 kbd_buffer_store_event (event
)
1462 register struct input_event
*event
;
1464 if (event
->kind
== no_event
)
1467 if (event
->kind
== ascii_keystroke
)
1469 register int c
= XFASTINT (event
->code
) & 0377;
1472 || ((c
== (0200 | quit_char
)) && !meta_key
))
1474 extern SIGTYPE
interrupt_signal ();
1477 /* If this results in a quit_char being returned to Emacs as
1478 input, set last-event-frame properly. If this doesn't
1479 get returned to Emacs as an event, the next event read
1480 will set Vlast_event_frame again, so this is safe to do. */
1481 Vlast_event_frame
= FRAME_FOCUS_FRAME (event
->frame
);
1484 last_event_timestamp
= event
->timestamp
;
1485 interrupt_signal ();
1489 if (c
&& c
== stop_character
)
1495 XSET (event
->code
, Lisp_Int
, c
);
1498 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
1499 kbd_store_ptr
= kbd_buffer
;
1501 /* Don't let the very last slot in the buffer become full,
1502 since that would make the two pointers equal,
1503 and that is indistinguishable from an empty buffer.
1504 Discard the event if it would fill the last slot. */
1505 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
1507 kbd_store_ptr
->kind
= event
->kind
;
1508 kbd_store_ptr
->code
= event
->code
;
1509 kbd_store_ptr
->part
= event
->part
;
1510 kbd_store_ptr
->frame
= event
->frame
;
1511 kbd_store_ptr
->modifiers
= event
->modifiers
;
1512 kbd_store_ptr
->x
= event
->x
;
1513 kbd_store_ptr
->y
= event
->y
;
1514 kbd_store_ptr
->timestamp
= event
->timestamp
;
1520 static Lisp_Object
make_lispy_event ();
1521 static Lisp_Object
make_lispy_movement ();
1522 static Lisp_Object
modify_event_symbol ();
1525 kbd_buffer_get_event ()
1533 XSET (obj
, Lisp_Int
, c
);
1537 /* Wait until there is input available. */
1541 /* Process or toss any events that we don't want to return as
1542 input. The fact that we remove undesirable events here
1543 allows us to use EVENT_QUEUES_EMPTY in the rest of this loop. */
1544 if (! do_mouse_tracking
)
1545 while (kbd_fetch_ptr
!= kbd_store_ptr
)
1547 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
1548 kbd_fetch_ptr
= kbd_buffer
;
1550 if (kbd_fetch_ptr
->kind
== mouse_click
1551 || kbd_fetch_ptr
->kind
== scrollbar_click
)
1553 if ((kbd_fetch_ptr
->modifiers
& up_modifier
) == 0)
1562 if (!EVENT_QUEUES_EMPTY
)
1565 /* If the quit flag is set, then read_char will return
1566 quit_char, so that counts as "available input." */
1567 if (!NILP (Vquit_flag
))
1568 quit_throw_to_read_char ();
1570 /* One way or another, wait until input is available; then, if
1571 interrupt handlers have not read it, read it now. */
1574 wait_for_kbd_input ();
1576 /* Note SIGIO has been undef'd if FIONREAD is missing. */
1580 if (EVENT_QUEUES_EMPTY
)
1582 Lisp_Object minus_one
;
1584 XSET (minus_one
, Lisp_Int
, -1);
1585 wait_reading_process_input (0, 0, minus_one
, 1);
1587 if (!interrupt_input
&& EVENT_QUEUES_EMPTY
)
1589 read_avail_input (0);
1592 #endif /* not VMS */
1595 /* At this point, we know that there is a readable event available
1596 somewhere. If the event queue is empty, then there must be a
1597 mouse movement enabled and available. */
1598 if (kbd_fetch_ptr
!= kbd_store_ptr
)
1600 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
1601 kbd_fetch_ptr
= kbd_buffer
;
1604 XSET (Vlast_event_frame
, Lisp_Frame
,
1605 XFRAME (FRAME_FOCUS_FRAME (kbd_fetch_ptr
->frame
)));
1608 last_event_timestamp
= kbd_fetch_ptr
->timestamp
;
1609 obj
= make_lispy_event (kbd_fetch_ptr
);
1610 kbd_fetch_ptr
->kind
= no_event
;
1612 if (XTYPE (obj
) == Lisp_Int
)
1613 XSET (obj
, Lisp_Int
, XINT (obj
) & (meta_key
? 0377 : 0177));
1615 else if (do_mouse_tracking
&& mouse_moved
)
1621 (*mouse_position_hook
) (&frame
, &x
, &y
, &time
);
1623 XSET (Vlast_event_frame
, Lisp_Frame
, frame
);
1626 obj
= make_lispy_movement (frame
, x
, y
, time
);
1629 /* We were promised by the above while loop that there was
1630 something for us to read! */
1633 input_pending
= readable_events ();
1638 /* Caches for modify_event_symbol. */
1639 static Lisp_Object func_key_syms
;
1640 static Lisp_Object mouse_syms
;
1642 /* You'll notice that this table is arranged to be conveniently
1643 indexed by X Windows keysym values. */
1644 static char *lispy_function_keys
[] =
1646 /* X Keysym value */
1648 "home", /* 0xff50 */ /* IsCursorKey */
1659 "select", /* 0xff60 */ /* IsMiscFunctionKey */
1670 "break", /* 0xff6b */
1672 /* Here are some keys found mostly on HP keyboards. The X event
1673 handling code will strip bit 29, which flags vendor-specific
1675 "reset", /* 0x1000ff6c */
1684 "kp_backtab", /* 0x1000ff75 */
1686 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff7f */
1687 "kp-space", /* 0xff80 */ /* IsKeypadKey */
1688 0, 0, 0, 0, 0, 0, 0, 0,
1689 "kp-tab", /* 0xff89 */
1691 "kp-enter", /* 0xff8d */
1693 "kp-f1", /* 0xff91 */
1698 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1699 "kp-multiply", /* 0xffaa */
1704 "kp-divide", /* 0xffaf */
1705 "kp-0", /* 0xffb0 */
1706 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
1709 "kp-equal", /* 0xffbd */
1710 "f1", /* 0xffbe */ /* IsFunctionKey */
1712 "f5", "f6", "f7", "f8", "f9", "f10", "f11", "f12",
1713 "f13", "f14", "f15", "f16", "f17", "f18", "f19", "f20",
1714 "f21", "f22", "f23", "f24", "f25", "f26", "f27", "f28",
1715 "f29", "f30", "f31", "f32", "f33", "f34", "f35" /* 0xffe0 */
1718 static char *lispy_mouse_names
[] =
1720 "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5"
1723 /* Given a struct input_event, build the lisp event which represents
1724 it. If EVENT is 0, build a mouse movement event from the mouse
1725 movement buffer, which should have a movement event in it. */
1728 make_lispy_event (event
)
1729 struct input_event
*event
;
1731 #ifdef SWITCH_ENUM_BUG
1732 switch ((int) event
->kind
)
1734 switch (event
->kind
)
1738 /* A simple keystroke. */
1739 case ascii_keystroke
:
1743 /* A function key. The symbol may need to have modifier prefixes
1745 case non_ascii_keystroke
:
1746 return modify_event_symbol (XFASTINT (event
->code
), event
->modifiers
,
1748 lispy_function_keys
, &func_key_syms
,
1749 (sizeof (lispy_function_keys
)
1750 / sizeof (lispy_function_keys
[0])));
1753 /* A mouse click - build a list of the relevant information. */
1757 Lisp_Object window
=
1758 window_from_coordinates (event
->frame
,
1759 XINT (event
->x
), XINT (event
->y
),
1763 if (XTYPE (window
) != Lisp_Window
)
1767 XSETINT (event
->x
, (XINT (event
->x
)
1768 - XINT (XWINDOW (window
)->left
)));
1769 XSETINT (event
->y
, (XINT (event
->y
)
1770 - XINT (XWINDOW (window
)->top
)));
1775 posn
= Qvertical_line
;
1777 XSET (posn
, Lisp_Int
,
1778 buffer_posn_from_coords (XWINDOW (window
),
1783 return Fcons (modify_event_symbol (XFASTINT (event
->code
) - 1,
1786 lispy_mouse_names
, &mouse_syms
,
1787 (sizeof (lispy_mouse_names
)
1788 / sizeof (lispy_mouse_names
[0]))),
1791 Fcons (Fcons (event
->x
, event
->y
),
1797 /* A scrollbar click. Build a list containing the relevant
1799 case scrollbar_click
:
1802 = modify_event_symbol (XFASTINT (event
->code
) - 1,
1805 lispy_mouse_names
, &mouse_syms
,
1806 (sizeof (lispy_mouse_names
)
1807 / sizeof (lispy_mouse_names
[0])));
1808 return Fcons (event
->part
,
1809 Fcons (FRAME_SELECTED_WINDOW (event
->frame
),
1811 Fcons (Fcons (event
->x
, event
->y
),
1817 /* The 'kind' field of the event is something we don't recognize. */
1824 make_lispy_movement (frame
, x
, y
, time
)
1837 ? window_from_coordinates (frame
, ix
, iy
, &part
)
1839 if (XTYPE (window
) != Lisp_Window
)
1843 ix
-= XINT (XWINDOW (window
)->left
);
1844 iy
-= XINT (XWINDOW (window
)->top
);
1848 posn
= Qvertical_line
;
1850 XSET (posn
, Lisp_Int
, buffer_posn_from_coords (XWINDOW (window
),
1856 return Fcons (Qmouse_movement
,
1859 Fcons (Fcons (x
, y
),
1860 Fcons (make_number (time
), Qnil
)))));
1865 /* Place the written representation of MODIFIERS in BUF, '\0'-terminated,
1866 and return its length. */
1869 format_modifiers (modifiers
, buf
)
1875 /* Events with the `up' modifier should always be turned into
1876 click or drag events. */
1877 if (modifiers
& up_modifier
)
1880 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
1881 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
1882 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
1883 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
1884 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
1885 if (modifiers
& super_modifier
) { strcpy (p
, "super-"); p
+= 6; }
1886 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
1887 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
1894 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
1895 return a symbol with the modifiers placed in the canonical order.
1896 Canonical order is alphabetical, except for down and drag, which
1899 Fdefine_key calls this to make sure that (for example) C-M-foo
1900 and M-C-foo end up being equivalent in the keymap. */
1903 reorder_modifiers (symbol
)
1906 struct Lisp_String
*name
;
1911 CHECK_SYMBOL (symbol
, 1);
1914 name
= XSYMBOL (symbol
)->name
;
1916 /* Special case for things with only one modifier, which is
1917 (hopefully) the vast majority of cases. */
1918 if (! (name
->size
>= 4 && name
->data
[1] == '-' && name
->data
[3] == '-'))
1921 for (i
= 0; i
+1 < name
->data
[i
]; )
1922 switch (name
->data
[i
])
1925 if (name
->data
[i
] != '-') goto no_more_modifiers
;
1926 not_canonical
|= (modifiers
& ~(alt_modifier
- 1));
1927 modifiers
|= alt_modifier
;
1932 if (name
->data
[i
] != '-') goto no_more_modifiers
;
1933 not_canonical
|= (modifiers
& ~(ctrl_modifier
- 1));
1934 modifiers
|= ctrl_modifier
;
1939 if (name
->data
[i
] != '-') goto no_more_modifiers
;
1940 not_canonical
|= (modifiers
& ~(hyper_modifier
- 1));
1941 modifiers
|= hyper_modifier
;
1946 if (name
->data
[i
] != '-') goto no_more_modifiers
;
1947 not_canonical
|= (modifiers
& ~(meta_modifier
- 1));
1948 modifiers
|= meta_modifier
;
1953 if (name
->data
[i
] != '-') goto no_more_modifiers
;
1954 not_canonical
|= (modifiers
& ~(shift_modifier
- 1));
1955 modifiers
|= shift_modifier
;
1960 if (i
+ 6 > name
->size
1961 || strncmp (name
->data
+ i
, "super-", 6))
1962 goto no_more_modifiers
;
1963 not_canonical
|= (modifiers
& ~(super_modifier
- 1));
1964 modifiers
|= super_modifier
;
1969 if (i
+ 5 > name
->size
)
1970 goto no_more_modifiers
;
1971 if (! strncmp (name
->data
+ i
, "drag-", 5))
1973 not_canonical
|= (modifiers
& ~(drag_modifier
- 1));
1974 modifiers
|= drag_modifier
;
1977 else if (! strncmp (name
->data
+ i
, "down-", 5))
1979 not_canonical
|= (modifiers
& ~(down_modifier
- 1));
1980 modifiers
|= down_modifier
;
1984 goto no_more_modifiers
;
1988 goto no_more_modifiers
;
1995 /* The modifiers were out of order, so find a new symbol with the
1996 mods in order. Since the symbol name could contain nulls, we can't
1997 use intern here; we have to use Fintern, which expects a genuine
1998 Lisp_String, and keeps a reference to it. */
2000 char *new_mods
= (char *) alloca (sizeof ("A-C-H-M-S-super-U-down-drag-"));
2001 int len
= format_modifiers (modifiers
, new_mods
);
2002 Lisp_Object new_name
= make_uninit_string (len
+ name
->size
- i
);
2004 bcopy (new_mods
, XSTRING (new_name
)->data
, len
);
2005 bcopy (name
->data
+ i
, XSTRING (new_name
)->data
+ len
, name
->size
- i
);
2007 return Fintern (new_name
, Qnil
);
2012 /* For handling events, we often want to produce a symbol whose name
2013 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
2014 to some base, like the name of a function key or mouse button.
2015 modify_event_symbol produces symbols of this sort.
2017 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
2018 is the name of the i'th symbol. TABLE_SIZE is the number of elements
2021 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
2022 persist between calls to modify_event_symbol that it can use to
2023 store a cache of the symbols it's generated for this NAME_TABLE
2026 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
2028 MODIFIERS is a set of modifier bits (as given in struct input_events)
2029 whose prefixes should be applied to the symbol name.
2031 SYMBOL_KIND is the value to be placed in the event_kind property of
2032 the returned symbol. */
2035 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_table
,
2036 symbol_table
, table_size
)
2039 Lisp_Object symbol_kind
;
2041 Lisp_Object
*symbol_table
;
2044 Lisp_Object
*slot
, *unmodified_slot
;
2046 /* Is this a request for a valid symbol? */
2047 if (symbol_num
< 0 || symbol_num
>= table_size
2048 || modifiers
>= NUM_MODIFIER_COMBOS
)
2051 /* If *symbol_table is not a vector of the appropriate size,
2053 if (XTYPE (*symbol_table
) != Lisp_Vector
2054 || XVECTOR (*symbol_table
)->size
!= table_size
)
2055 *symbol_table
= Fmake_vector (make_number (table_size
), Qnil
);
2057 unmodified_slot
= slot
= & XVECTOR (*symbol_table
)->contents
[symbol_num
];
2059 /* If there are modifier keys, there had better be a vector in
2060 this symbol's position of the symbol_table. */
2063 Lisp_Object slot_contents
= *slot
;
2065 /* If there isn't the right sort of vector there, put one in. */
2066 if (XTYPE (slot_contents
) != Lisp_Vector
2067 || XVECTOR (slot_contents
)->size
!= NUM_MODIFIER_COMBOS
)
2069 *slot
= Fmake_vector (make_number (NUM_MODIFIER_COMBOS
), Qnil
);
2071 /* Make sure that the vector has an entry for the unmodified
2072 symbol, so we can put it on the event_unmodified property. */
2073 if (! NILP (slot_contents
))
2074 XVECTOR (*slot
)->contents
[0] = slot_contents
;
2076 XVECTOR (*slot
)->contents
[0] = intern (name_table
[symbol_num
]);
2080 /* If this entry has been filled in with a modified symbol vector,
2081 point to the appropriate slot within that. */
2082 if (XTYPE (*slot
) == Lisp_Vector
)
2084 unmodified_slot
= & XVECTOR (*slot
)->contents
[0];
2085 slot
= & XVECTOR (*slot
)->contents
[modifiers
];
2088 /* Make sure we have an unmodified version of the symbol in its
2090 if (NILP (*unmodified_slot
))
2092 *unmodified_slot
= intern (name_table
[symbol_num
]);
2093 Fput (*unmodified_slot
, Qevent_kind
, symbol_kind
);
2094 Fput (*unmodified_slot
, Qevent_unmodified
, *unmodified_slot
);
2097 /* Have we already created a symbol for this combination of modifiers? */
2100 /* No, let's create one. */
2102 = (char *) alloca (sizeof ("C-M-S-U-")
2103 + strlen (name_table
[symbol_num
]));
2105 strcpy (modified_name
+ format_modifiers (modifiers
, modified_name
),
2106 name_table
[symbol_num
]);
2108 *slot
= intern (modified_name
);
2109 Fput (*slot
, Qevent_kind
, symbol_kind
);
2110 Fput (*slot
, Qevent_unmodified
, *unmodified_slot
);
2116 DEFUN ("mouse-click-p", Fmouse_click_p
, Smouse_click_p
, 1, 1, 0,
2117 "Return non-nil iff OBJECT is a representation of a mouse event.\n\
2118 A mouse event is a list of five elements whose car is a symbol of the\n\
2119 form <MODIFIERS>mouse-<DIGIT>. I hope this is a temporary hack.")
2123 if (EVENT_HAS_PARAMETERS (object
)
2124 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (object
)),
2131 /* Store into *addr a value nonzero if terminal input chars are available.
2132 Serves the purpose of ioctl (0, FIONREAD, addr)
2133 but works even if FIONREAD does not exist.
2134 (In fact, this may actually read some input.) */
2137 get_input_pending (addr
)
2140 /* First of all, have we already counted some input? */
2141 *addr
= !NILP (Vquit_flag
) || readable_events ();
2143 /* If input is being read as it arrives, and we have none, there is none. */
2144 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
2147 /* Try to read some input and see how much we get. */
2149 *addr
= !NILP (Vquit_flag
) || readable_events ();
2152 /* Interface to read_avail_input, blocking SIGIO if necessary. */
2155 gobble_input (expected
)
2160 if (interrupt_input
)
2163 mask
= sigblockx (SIGIO
);
2164 read_avail_input (expected
);
2169 read_avail_input (expected
);
2175 /* Read any terminal input already buffered up by the system
2176 into the kbd_buffer, but do not wait.
2178 EXPECTED should be nonzero if the caller knows there is some input.
2180 Except on VMS, all input is read by this function.
2181 If interrupt_input is nonzero, this function MUST be called
2182 only when SIGIO is blocked.
2184 Returns the number of keyboard chars read, or -1 meaning
2185 this is a bad time to try to read input. */
2188 read_avail_input (expected
)
2191 struct input_event buf
[KBD_BUFFER_SIZE
];
2195 if (read_socket_hook
)
2196 /* No need for FIONREAD or fcntl; just say don't wait. */
2197 nread
= (*read_socket_hook
) (0, buf
, KBD_BUFFER_SIZE
, expected
, expected
);
2200 unsigned char cbuf
[KBD_BUFFER_SIZE
];
2203 /* Find out how much input is available. */
2204 if (ioctl (0, FIONREAD
, &nread
) < 0)
2205 /* Formerly simply reported no input, but that sometimes led to
2206 a failure of Emacs to terminate.
2207 SIGHUP seems appropriate if we can't reach the terminal. */
2208 kill (getpid (), SIGHUP
);
2211 if (nread
> sizeof cbuf
)
2212 nread
= sizeof cbuf
;
2213 #else /* no FIONREAD */
2215 /* Read some input if available, but don't wait. */
2216 nread
= sizeof cbuf
;
2217 fcntl (fileno (stdin
), F_SETFL
, O_NDELAY
);
2223 /* Now read; for one reason or another, this will not block. */
2226 nread
= read (fileno (stdin
), cbuf
, nread
);
2228 /* The kernel sometimes fails to deliver SIGHUP for ptys.
2229 This looks incorrect, but it isn't, because _BSD causes
2230 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
2231 and that causes a value other than 0 when there is no input. */
2235 /* Retry the read if it is interrupted. */
2237 || ! (errno
== EAGAIN
|| errno
== EFAULT
2247 fcntl (fileno (stdin
), F_SETFL
, 0);
2249 #endif /* no FIONREAD */
2250 for (i
= 0; i
< nread
; i
++)
2252 buf
[i
].kind
= ascii_keystroke
;
2253 XSET (buf
[i
].code
, Lisp_Int
, cbuf
[i
]);
2254 buf
[i
].frame
= selected_frame
;
2258 /* Scan the chars for C-g and store them in kbd_buffer. */
2259 for (i
= 0; i
< nread
; i
++)
2261 kbd_buffer_store_event (&buf
[i
]);
2262 /* Don't look at input that follows a C-g too closely.
2263 This reduces lossage due to autorepeat on C-g. */
2264 if (buf
[i
].kind
== ascii_keystroke
2265 && XINT(buf
[i
].code
) == quit_char
)
2271 #endif /* not VMS */
2273 #ifdef SIGIO /* for entire page */
2274 /* Note SIGIO has been undef'd if FIONREAD is missing. */
2277 input_available_signal (signo
)
2280 /* Must preserve main program's value of errno. */
2281 int old_errno
= errno
;
2283 extern int select_alarmed
;
2287 /* USG systems forget handlers when they are used;
2288 must reestablish each time */
2289 signal (signo
, input_available_signal
);
2296 if (input_available_clear_time
)
2297 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
2302 nread
= read_avail_input (1);
2303 /* -1 means it's not ok to read the input now.
2304 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
2305 0 means there was no keyboard input available. */
2310 select_alarmed
= 1; /* Force the select emulator back to life */
2321 /* Return the prompt-string of a sparse keymap.
2322 This is the first element which is a string.
2323 Return nil if there is none. */
2331 register Lisp_Object tem
;
2333 if (XTYPE (tem
) == Lisp_String
)
2340 static int echo_flag
;
2341 static int echo_now
;
2343 /* Read a character like read_char but optionally prompt based on maps
2344 in the array MAPS. NMAPS is the length of MAPS.
2346 PREV_EVENT is the previous input event, or nil if we are reading
2347 the first event of a key sequence.
2349 If we use a mouse menu to read the input, we store 1 into *USED_MOUSE_MENU.
2350 Otherwise we store 0 there.
2352 The prompting is done based on the prompt-string of the map
2353 and the strings associated with various map elements. */
2356 read_char_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
2359 Lisp_Object prev_event
;
2360 int *used_mouse_menu
;
2363 register Lisp_Object name
;
2365 int width
= FRAME_WIDTH (selected_frame
) - 4;
2366 char *menu
= (char *) alloca (width
+ 4);
2368 Lisp_Object rest
, vector
;
2370 *used_mouse_menu
= 0;
2372 /* Use local over global Menu maps */
2374 if (! menu_prompting
)
2377 /* Get the menu name from the first map that has one (a prompt string). */
2378 for (mapno
= 0; mapno
< nmaps
; mapno
++)
2380 name
= map_prompt (maps
[mapno
]);
2385 /* If we don't have any menus, just read a character normally. */
2389 #ifdef HAVE_X_WINDOW
2391 /* If we got to this point via a mouse click,
2392 use a real menu for mouse selection. */
2393 if (XTYPE (prev_event
) == Lisp_Cons
)
2395 /* Display the menu and get the selection. */
2396 Lisp_Object
*realmaps
2397 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
2401 /* Use the maps that are not nil. */
2402 for (mapno
= 0; mapno
< nmaps
; mapno
++)
2403 if (!NILP (maps
[mapno
]))
2404 realmaps
[nmaps1
++] = maps
[mapno
];
2406 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
2408 XSET (value
, Lisp_Int
, quit_char
);
2409 *used_mouse_menu
= 1;
2412 #endif /* not NO_X_MENU */
2413 #endif /* HAVE_X_WINDOW */
2415 /* Prompt string always starts with map's prompt, and a space. */
2416 strcpy (menu
, XSTRING (name
)->data
);
2417 nlength
= XSTRING (name
)->size
;
2418 menu
[nlength
++] = ':';
2419 menu
[nlength
++] = ' ';
2422 /* Start prompting at start of first map. */
2426 /* Present the documented bindings, a line at a time. */
2434 /* Loop over elements of map. */
2439 /* If reached end of map, start at beginning of next map. */
2443 /* At end of last map, wrap around to first map if just starting,
2444 or end this line if already have something on it. */
2455 /* Look at the next element of the map. */
2457 elt
= XVECTOR (vector
)->contents
[idx
];
2459 elt
= Fcar_safe (rest
);
2461 if (idx
< 0 && XTYPE (elt
) == Lisp_Vector
)
2463 /* If we found a dense table in the keymap,
2464 advanced past it, but start scanning its contents. */
2465 rest
= Fcdr_safe (rest
);
2471 /* An ordinary element. */
2472 s
= Fcar_safe (Fcdr_safe (elt
));
2473 if (XTYPE (s
) != Lisp_String
)
2474 /* Ignore the element if it has no prompt string. */
2476 /* If we have room for the prompt string, add it to this line.
2477 If this is the first on the line, always add it. */
2478 else if (XSTRING (s
)->size
+ i
< width
2483 /* Punctuate between strings. */
2486 strcpy (menu
+ i
, ", ");
2491 /* Add as much of string as fits. */
2492 thiswidth
= XSTRING (s
)->size
;
2493 if (thiswidth
+ i
> width
)
2494 thiswidth
= width
- i
;
2495 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
2500 /* If this element does not fit, end the line now,
2501 and save the element for the next line. */
2502 strcpy (menu
+ i
, "...");
2506 /* Move past this element. */
2507 if (idx
>= 0 && idx
+ 1 >= XVECTOR (rest
)->size
)
2508 /* Handle reaching end of dense table. */
2513 rest
= Fcdr_safe (rest
);
2517 /* Prompt with that and read response. */
2519 obj
= read_char (1, 0, 0, Qnil
, 0);
2521 if (XTYPE (obj
) != Lisp_Int
)
2526 if (obj
!= menu_prompt_more_char
2527 && (XTYPE (menu_prompt_more_char
) != Lisp_Int
2528 || obj
!= make_number (Ctl (XINT (menu_prompt_more_char
)))))
2533 /* Reading key sequences. */
2535 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
2536 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
2537 keymap, or nil otherwise. Return the index of the first keymap in
2538 which KEY has any binding, or NMAPS if no map has a binding.
2540 If KEY is a meta ASCII character, treat it like meta-prefix-char
2541 followed by the corresponding non-meta character. Keymaps in
2542 CURRENT with non-prefix bindings for meta-prefix-char become nil in
2545 When KEY is not defined in any of the keymaps, if it is an upper
2546 case letter and there are bindings for the corresponding lower-case
2547 letter, return the bindings for the lower-case letter.
2549 NEXT may == CURRENT. */
2552 follow_key (key
, nmaps
, current
, defs
, next
)
2554 Lisp_Object
*current
, *defs
, *next
;
2557 int i
, first_binding
;
2559 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
2560 followed by the corresponding non-meta character. */
2561 if (XTYPE (key
) == Lisp_Int
2562 && XINT (key
) >= 0200)
2564 for (i
= 0; i
< nmaps
; i
++)
2565 if (! NILP (current
[i
]))
2567 next
[i
] = get_keyelt (access_keymap (current
[i
],
2570 /* Note that since we pass the resulting bindings through
2571 get_keymap_1, non-prefix bindings for meta-prefix-char
2573 next
[i
] = get_keymap_1 (next
[i
], 0);
2579 XSET (key
, Lisp_Int
, XFASTINT (key
) & 0177);
2582 first_binding
= nmaps
;
2583 for (i
= nmaps
- 1; i
>= 0; i
--)
2585 if (! NILP (current
[i
]))
2587 defs
[i
] = get_keyelt (access_keymap (current
[i
], key
));
2588 if (! NILP (defs
[i
]))
2595 /* When KEY is not defined in any of the keymaps, if it is an upper
2596 case letter and there are bindings for the corresponding
2597 lower-case letter, return the bindings for the lower-case letter. */
2598 if (first_binding
== nmaps
2599 && XTYPE (key
) == Lisp_Int
2600 && UPPERCASEP (XINT (key
)))
2602 XSETINT (key
, DOWNCASE (XINT (key
)));
2604 first_binding
= nmaps
;
2605 for (i
= nmaps
- 1; i
>= 0; i
--)
2607 if (! NILP (current
[i
]))
2609 defs
[i
] = get_keyelt (access_keymap (current
[i
], key
));
2610 if (! NILP (defs
[i
]))
2618 /* Given the set of bindings we've found, produce the next set of maps. */
2619 for (i
= 0; i
< nmaps
; i
++)
2620 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0);
2622 return first_binding
;
2625 /* Read a sequence of keys that ends with a non prefix character
2626 according to the keymaps in KEYMAPS[0..nmaps-1]. Keymaps appearing
2627 earlier in KEYMAPS take precidence over those appearing later.
2629 Store the sequence in KEYBUF, a buffer of size BUFSIZE. Prompt
2630 with PROMPT. Echo starting immediately unless `prompt' is 0.
2631 Return the length of the key sequence stored.
2633 If the user switches frames in the midst of a key sequence, we
2634 throw away any prefix we have read so far, and start afresh. For
2635 mouse clicks, we look up the click in the keymap of the buffer
2636 clicked on, throwing away any prefix if it is not the same buffer
2637 we used to be reading from. */
2640 read_key_sequence (keybuf
, bufsize
, prompt
)
2641 Lisp_Object
*keybuf
;
2645 /* How many keys there are in the current key sequence. */
2648 /* The buffer that the most recently read event was typed at. This
2649 helps us read mouse clicks according to the buffer clicked in,
2650 and notice when the mouse has moved from one frame to another. */
2651 struct buffer
*last_event_buffer
= current_buffer
;
2653 /* The length of the echo buffer when we started reading, and
2654 the length of this_command_keys when we started reading. */
2656 int keys_start
= this_command_key_count
;
2658 /* The number of keymaps we're scanning right now, and the number of
2659 keymaps we have allocated space for. */
2661 int nmaps_allocated
= 0;
2663 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
2664 in the current keymaps, or nil where it is not a prefix. */
2665 Lisp_Object
*submaps
;
2667 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
2668 the current keymaps. */
2671 /* The index of the first keymap that has a binding for this key
2672 sequence. In other words, the lowest i such that defs[i] is
2676 /* If mock_input > t, then KEYBUF[t] should be read as the next
2679 We use this to recover after recognizing a function key. Once we
2680 realize that a suffix of the current key sequence is actually a
2681 function key's escape sequence, we replace the suffix with the
2682 function key's binding from Vfunction_key_map. Now keybuf
2683 contains a new and different key sequence, so the echo area and
2684 the submaps and defs arrays are wrong. In this situation, we set
2685 mock_input to t, set t to 0, and jump to restart; the loop will
2686 read keys from keybuf up until mock_input, which rebuilds the
2687 state, and then it will resume reading characters from the keyboard. */
2690 /* If the sequence is unbound in submaps[], then
2691 keymap[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
2692 and fkey_map is its binding. If mock_input is in use, these
2693 might be > t, indicating that all function key scanning should
2694 hold off until t reaches them. */
2696 int fkey_start
= 0, fkey_end
= 0;
2697 Lisp_Object fkey_map
= Vfunction_key_map
;
2699 last_nonmenu_event
= Qnil
;
2704 echo_prompt (prompt
);
2705 else if (cursor_in_echo_area
)
2706 /* This doesn't put in a dash if the echo buffer is empty, so
2707 you don't always see a dash hanging out in the minibuffer. */
2709 echo_start
= echo_length ();
2712 /* If there is no function key map, turn off function key scanning. */
2713 if (NILP (Fkeymapp (Vfunction_key_map
)))
2714 fkey_start
= fkey_end
= bufsize
+ 1;
2718 this_command_key_count
= keys_start
;
2723 nmaps
= current_minor_maps (0, &maps
) + 2;
2724 if (nmaps
> nmaps_allocated
)
2726 submaps
= (Lisp_Object
*) alloca (nmaps
* sizeof (submaps
[0]));
2727 defs
= (Lisp_Object
*) alloca (nmaps
* sizeof (defs
[0]));
2728 nmaps_allocated
= nmaps
;
2730 bcopy (maps
, submaps
, (nmaps
- 2) * sizeof (submaps
[0]));
2731 submaps
[nmaps
-2] = last_event_buffer
->keymap
;
2732 submaps
[nmaps
-1] = global_map
;
2735 /* Find an accurate initial value for first_binding. */
2736 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
2737 if (! NILP (submaps
[first_binding
]))
2740 while ((first_binding
< nmaps
&& ! NILP (submaps
[first_binding
]))
2741 || (first_binding
>= nmaps
&& fkey_start
< t
))
2744 int used_mouse_menu
= 0;
2747 error ("key sequence too long");
2749 /* Are we re-reading a key sequence, as indicated by mock_input? */
2753 add_command_key (key
);
2757 /* If not, we should actually read a character. */
2762 key
= read_char (!prompt
, nmaps
, submaps
, last_nonmenu_event
,
2765 /* The above routines return -1 at the end of a macro.
2766 Emacs 18 handles this by returning immediately with a
2767 zero, so that's what we'll do. */
2768 if (XTYPE (key
) == Lisp_Int
&& XINT (key
) < 0)
2774 /* What buffer was this event typed/moused at? */
2775 if (used_mouse_menu
)
2776 /* Never change last_event_buffer for using a menu. */
2777 buf
= last_event_buffer
;
2778 else if (XTYPE (key
) == Lisp_Int
|| XTYPE (key
) == Lisp_Symbol
)
2780 buf
= ((XTYPE (Vlast_event_frame
) == Lisp_Frame
)
2783 (FRAME_SELECTED_WINDOW
2784 (XFRAME (Vlast_event_frame
)))->buffer
))
2785 : last_event_buffer
);
2787 else if (EVENT_HAS_PARAMETERS (key
))
2789 Lisp_Object window
= EVENT_WINDOW (key
);
2794 buf
= XBUFFER (XWINDOW (window
)->buffer
);
2799 /* If this event came to a different buffer than the one
2800 we're currently in, switch buffers and start a new key
2801 sequence, starting with key. */
2802 if (buf
!= last_event_buffer
)
2804 last_event_buffer
= buf
;
2805 Fselect_frame (Vlast_event_frame
, Qnil
);
2807 /* Arrange to read key as the next event. */
2811 /* Truncate the key sequence in the echo area. */
2813 echo_truncate (echo_start
);
2820 first_binding
= (follow_key (key
,
2821 nmaps
- first_binding
,
2822 submaps
+ first_binding
,
2823 defs
+ first_binding
,
2824 submaps
+ first_binding
)
2827 /* Normally, last_nonmenu_event gets the previous key we read.
2828 But when a mouse popup menu is being used,
2829 we don't update last_nonmenu_event; it continues to hold the mouse
2830 event that preceded the first level of menu. */
2831 if (!used_mouse_menu
)
2832 last_nonmenu_event
= key
;
2834 /* If the sequence is unbound, see if we can hang a function key
2835 off the end of it. We only want to scan real keyboard input
2836 for function key sequences, so if mock_input says that we're
2837 re-scanning after expanding a function key, don't examine it. */
2838 if (first_binding
>= nmaps
2841 Lisp_Object fkey_next
;
2843 /* Scan from fkey_end until we find a bound suffix. */
2844 while (fkey_end
< t
)
2846 /* Look up meta-characters by prefixing them
2847 with meta_prefix_char. I hate this. */
2848 if (keybuf
[fkey_end
] & 0x80)
2850 get_keymap_1 (get_keyelt
2851 (access_keymap (fkey_map
, meta_prefix_char
)),
2854 fkey_next
= fkey_map
;
2857 get_keyelt (access_keymap
2858 (fkey_next
, keybuf
[fkey_end
++] & 0x7f));
2860 /* If keybuf[fkey_start..fkey_end] is bound in the
2861 function key map and it's a suffix of the current
2862 sequence (i.e. fkey_end == t), replace it with
2863 the binding and restart with fkey_start at the end. */
2864 if (XTYPE (fkey_next
) == Lisp_Vector
2867 t
= fkey_start
+ XVECTOR (fkey_next
)->size
;
2869 error ("key sequence too long");
2871 bcopy (XVECTOR (fkey_next
)->contents
,
2872 keybuf
+ fkey_start
,
2873 (t
- fkey_start
) * sizeof (keybuf
[0]));
2876 fkey_start
= fkey_end
= t
;
2878 /* Truncate the key sequence in the echo area. */
2880 echo_truncate (echo_start
);
2885 fkey_map
= get_keymap_1 (fkey_next
, 0);
2887 /* If we no longer have a bound suffix, try a new positions for
2889 if (NILP (fkey_map
))
2891 fkey_end
= ++fkey_start
;
2892 fkey_map
= Vfunction_key_map
;
2898 read_key_sequence_cmd
= (first_binding
< nmaps
2899 ? defs
[first_binding
]
2905 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 2, 0,
2906 "Read a sequence of keystrokes and return as a string or vector.\n\
2907 The sequence is sufficient to specify a non-prefix command in the\n\
2908 current local and global maps.\n\
2910 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
2911 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
2912 as a continuation of the previous key.\n\
2914 If Emacs is running on multiple frames, switching between frames in\n\
2915 the midst of a keystroke will toss any prefix typed so far. A C-g\n\
2916 typed while in this function is treated like any other character, and\n\
2917 `quit-flag' is not set.")
2918 (prompt
, continue_echo
)
2919 Lisp_Object prompt
, continue_echo
;
2921 Lisp_Object keybuf
[30];
2923 struct gcpro gcpro1
, gcpro2
;
2926 CHECK_STRING (prompt
, 0);
2929 bzero (keybuf
, sizeof keybuf
);
2931 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
2933 if (NILP (continue_echo
))
2934 this_command_key_count
= 0;
2936 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
2937 NILP (prompt
) ? 0 : XSTRING (prompt
)->data
);
2940 return make_array (i
, keybuf
);
2943 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 2, 0,
2944 "Execute CMD as an editor command.\n\
2945 CMD must be a symbol that satisfies the `commandp' predicate.\n\
2946 Optional second arg RECORD-FLAG non-nil\n\
2947 means unconditionally put this command in `command-history'.\n\
2948 Otherwise, that is done only if an arg is read using the minibuffer.")
2950 Lisp_Object cmd
, record
;
2952 register Lisp_Object final
;
2953 register Lisp_Object tem
;
2954 Lisp_Object prefixarg
;
2955 struct backtrace backtrace
;
2956 extern int debug_on_next_call
;
2958 prefixarg
= Vprefix_arg
, Vprefix_arg
= Qnil
;
2959 Vcurrent_prefix_arg
= prefixarg
;
2960 debug_on_next_call
= 0;
2962 if (XTYPE (cmd
) == Lisp_Symbol
)
2964 tem
= Fget (cmd
, Qdisabled
);
2966 return call1 (Vrun_hooks
, Vdisabled_command_hook
);
2971 final
= Findirect_function (cmd
);
2973 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
2974 do_autoload (final
, cmd
);
2979 if (XTYPE (final
) == Lisp_String
2980 || XTYPE (final
) == Lisp_Vector
)
2982 /* If requested, place the macro in the command history. For
2983 other sorts of commands, call-interactively takes care of
2987 = Fcons (Fcons (Qexecute_kbd_macro
,
2988 Fcons (final
, Fcons (prefixarg
, Qnil
))),
2991 return Fexecute_kbd_macro (final
, prefixarg
);
2993 if (CONSP (final
) || XTYPE (final
) == Lisp_Subr
2994 || XTYPE (final
) == Lisp_Compiled
)
2996 backtrace
.next
= backtrace_list
;
2997 backtrace_list
= &backtrace
;
2998 backtrace
.function
= &Qcall_interactively
;
2999 backtrace
.args
= &cmd
;
3000 backtrace
.nargs
= 1;
3001 backtrace
.evalargs
= 0;
3003 tem
= Fcall_interactively (cmd
, record
);
3005 backtrace_list
= backtrace
.next
;
3011 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
3013 "Read function name, then read its arguments and call it.")
3015 Lisp_Object prefixarg
;
3017 Lisp_Object function
;
3019 Lisp_Object saved_keys
;
3020 struct gcpro gcpro1
;
3022 saved_keys
= Fthis_command_keys ();
3024 GCPRO1 (saved_keys
);
3026 if (EQ (prefixarg
, Qminus
))
3028 else if (CONSP (prefixarg
) && XINT (XCONS (prefixarg
)->car
) == 4)
3029 strcpy (buf
, "C-u ");
3030 else if (CONSP (prefixarg
) && XTYPE (XCONS (prefixarg
)->car
) == Lisp_Int
)
3031 sprintf (buf
, "%d ", XINT (XCONS (prefixarg
)->car
));
3032 else if (XTYPE (prefixarg
) == Lisp_Int
)
3033 sprintf (buf
, "%d ", XINT (prefixarg
));
3035 /* This isn't strictly correct if execute-extended-command
3036 is bound to anything else. Perhaps it should use
3037 this_command_keys? */
3038 strcat (buf
, "M-x ");
3040 /* Prompt with buf, and then read a string, completing from and
3041 restricting to the set of all defined commands. Don't provide
3042 any initial input. The last Qnil says not to perform a
3043 peculiar hack on the initial input. */
3044 function
= Fcompleting_read (build_string (buf
),
3045 Vobarray
, Qcommandp
,
3048 /* Set this_command_keys to the concatenation of saved_keys and
3049 function, followed by a RET. */
3051 struct Lisp_String
*str
;
3055 this_command_key_count
= 0;
3057 str
= XSTRING (saved_keys
);
3058 for (i
= 0; i
< str
->size
; i
++)
3060 XFASTINT (tem
) = str
->data
[i
];
3061 add_command_key (tem
);
3064 str
= XSTRING (function
);
3065 for (i
= 0; i
< str
->size
; i
++)
3067 XFASTINT (tem
) = str
->data
[i
];
3068 add_command_key (tem
);
3071 XFASTINT (tem
) = '\015';
3072 add_command_key (tem
);
3077 function
= Fintern (function
, Vobarray
);
3078 Vprefix_arg
= prefixarg
;
3079 this_command
= function
;
3081 return Fcommand_execute (function
, Qt
);
3085 detect_input_pending ()
3088 get_input_pending (&input_pending
);
3090 return input_pending
;
3093 /* This is called in some cases before a possible quit.
3094 It cases the next call to detect_input_pending to recompute input_pending.
3095 So calling this function unnecessarily can't do any harm. */
3096 clear_input_pending ()
3101 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
3102 "T if command input is currently available with no waiting.\n\
3103 Actually, the value is nil only if we can be sure that no input is available.")
3106 if (!NILP (unread_command_char
))
3109 return detect_input_pending () ? Qt
: Qnil
;
3112 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
3113 "Return vector of last 100 chars read from terminal.")
3116 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
3119 if (total_keys
< NUM_RECENT_KEYS
)
3120 return Fvector (total_keys
, keys
);
3123 val
= Fvector (NUM_RECENT_KEYS
, keys
);
3124 bcopy (keys
+ recent_keys_index
,
3125 XVECTOR (val
)->contents
,
3126 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
3128 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
3129 recent_keys_index
* sizeof (Lisp_Object
));
3134 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
3135 "Return string of the keystrokes that invoked this command.")
3138 return make_array (this_command_key_count
, this_command_keys
);
3141 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
3142 "Return the current depth in recursive edits.")
3146 XFASTINT (temp
) = command_loop_level
+ minibuf_level
;
3150 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
3151 "FOpen dribble file: ",
3152 "Start writing all keyboard characters to FILE.")
3163 file
= Fexpand_file_name (file
, Qnil
);
3164 dribble
= fopen (XSTRING (file
)->data
, "w");
3169 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
3170 "Discard the contents of the terminal input buffer.\n\
3171 Also cancel any kbd macro being defined.")
3174 defining_kbd_macro
= 0;
3175 update_mode_lines
++;
3177 unread_command_char
= Qnil
;
3179 discard_tty_input ();
3181 kbd_fetch_ptr
= kbd_store_ptr
;
3187 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
3188 "Stop Emacs and return to superior process. You can resume later.\n\
3189 On systems that don't have job control, run a subshell instead.\n\n\
3190 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
3191 to be read as terminal input by Emacs's superior shell.\n\
3192 Before suspending, if `suspend-hook' is bound and value is non-nil\n\
3193 call the value as a function of no args. Don't suspend if it returns non-nil.\n\
3194 Otherwise, suspend normally and after resumption call\n\
3195 `suspend-resume-hook' if that is bound and non-nil.\n\
3197 Some operating systems cannot stop the Emacs process and resume it later.\n\
3198 On such systems, Emacs will start a subshell and wait for it to exit.")
3200 Lisp_Object stuffstring
;
3202 register Lisp_Object tem
;
3203 int count
= specpdl_ptr
- specpdl
;
3204 int old_height
, old_width
;
3206 struct gcpro gcpro1
;
3207 extern init_sys_modes ();
3209 if (!NILP (stuffstring
))
3210 CHECK_STRING (stuffstring
, 0);
3211 GCPRO1 (stuffstring
);
3213 /* Call value of suspend-hook
3214 if it is bound and value is non-nil. */
3215 if (!NILP (Vrun_hooks
))
3217 tem
= call1 (Vrun_hooks
, intern ("suspend-hook"));
3218 if (!EQ (tem
, Qnil
)) return Qnil
;
3221 get_frame_size (&old_width
, &old_height
);
3223 /* sys_suspend can get an error if it tries to fork a subshell
3224 and the system resources aren't available for that. */
3225 record_unwind_protect (init_sys_modes
, 0);
3226 stuff_buffered_input (stuffstring
);
3228 unbind_to (count
, Qnil
);
3230 /* Check if terminal/window size has changed.
3231 Note that this is not useful when we are running directly
3232 with a window system; but suspend should be disabled in that case. */
3233 get_frame_size (&width
, &height
);
3234 if (width
!= old_width
|| height
!= old_height
)
3235 change_frame_size (0, height
, width
, 0, 0);
3237 /* Call value of suspend-resume-hook
3238 if it is bound and value is non-nil. */
3239 if (!NILP (Vrun_hooks
))
3240 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
3246 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
3247 Then in any case stuff anthing Emacs has read ahead and not used. */
3249 stuff_buffered_input (stuffstring
)
3250 Lisp_Object stuffstring
;
3252 register unsigned char *p
;
3254 /* stuff_char works only in BSD, versions 4.2 and up. */
3257 if (XTYPE (stuffstring
) == Lisp_String
)
3261 p
= XSTRING (stuffstring
)->data
;
3262 count
= XSTRING (stuffstring
)->size
;
3267 /* Anything we have read ahead, put back for the shell to read. */
3268 while (kbd_fetch_ptr
!= kbd_store_ptr
)
3270 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
3271 kbd_fetch_ptr
= kbd_buffer
;
3272 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
3273 stuff_char (XINT (kbd_fetch_ptr
->code
));
3278 #endif /* BSD and not BSD4_1 */
3281 set_waiting_for_input (time_to_clear
)
3282 EMACS_TIME
*time_to_clear
;
3284 input_available_clear_time
= time_to_clear
;
3286 /* Tell interrupt_signal to throw back to read_char, */
3287 waiting_for_input
= 1;
3289 /* If interrupt_signal was called before and buffered a C-g,
3290 make it run again now, to avoid timing error. */
3291 if (!NILP (Vquit_flag
))
3292 quit_throw_to_read_char ();
3294 /* If alarm has gone off already, echo now. */
3302 clear_waiting_for_input ()
3304 /* Tell interrupt_signal not to throw back to read_char, */
3305 waiting_for_input
= 0;
3306 input_available_clear_time
= 0;
3309 /* This routine is called at interrupt level in response to C-G.
3310 If interrupt_input, this is the handler for SIGINT.
3311 Otherwise, it is called from kbd_buffer_store_event,
3312 in handling SIGIO or SIGTINT.
3314 If `waiting_for_input' is non zero, then unless `echoing' is nonzero,
3315 immediately throw back to read_char.
3317 Otherwise it sets the Lisp variable quit-flag not-nil.
3318 This causes eval to throw, when it gets a chance.
3319 If quit-flag is already non-nil, it stops the job right away. */
3325 /* Must preserve main program's value of errno. */
3326 int old_errno
= errno
;
3327 extern Lisp_Object Vwindow_system
;
3330 /* USG systems forget handlers when they are used;
3331 must reestablish each time */
3332 signal (SIGINT
, interrupt_signal
);
3333 signal (SIGQUIT
, interrupt_signal
);
3338 if (!NILP (Vquit_flag
) && FRAME_TERMCAP_P (selected_frame
))
3343 #ifdef SIGTSTP /* Support possible in later USG versions */
3345 * On systems which can suspend the current process and return to the original
3346 * shell, this command causes the user to end up back at the shell.
3347 * The "Auto-save" and "Abort" questions are not asked until
3348 * the user elects to return to emacs, at which point he can save the current
3349 * job and either dump core or continue.
3354 if (sys_suspend () == -1)
3356 printf ("Not running as a subprocess;\n");
3357 printf ("you can continue or abort.\n");
3360 /* Perhaps should really fork an inferior shell?
3361 But that would not provide any way to get back
3362 to the original shell, ever. */
3363 printf ("No support for stopping a process on this operating system;\n");
3364 printf ("you can continue or abort.\n");
3365 #endif /* not VMS */
3366 #endif /* not SIGTSTP */
3367 printf ("Auto-save? (y or n) ");
3369 if (((c
= getchar ()) & ~040) == 'Y')
3370 Fdo_auto_save (Qnil
, Qnil
);
3371 while (c
!= '\n') c
= getchar ();
3373 printf ("Abort (and enter debugger)? (y or n) ");
3375 printf ("Abort (and dump core)? (y or n) ");
3376 #endif /* not VMS */
3378 if (((c
= getchar ()) & ~040) == 'Y')
3380 while (c
!= '\n') c
= getchar ();
3381 printf ("Continuing...\n");
3387 /* If executing a function that wants to be interrupted out of
3388 and the user has not deferred quitting by binding `inhibit-quit'
3389 then quit right away. */
3390 if (immediate_quit
&& NILP (Vinhibit_quit
))
3394 Fsignal (Qquit
, Qnil
);
3397 /* Else request quit when it's safe */
3401 if (waiting_for_input
&& !echoing
)
3402 quit_throw_to_read_char ();
3407 /* Handle a C-g by making read_char return C-g. */
3409 quit_throw_to_read_char ()
3411 quit_error_check ();
3413 /* Prevent another signal from doing this before we finish. */
3414 clear_waiting_for_input ();
3417 unread_command_char
= Qnil
;
3419 _longjmp (getcjmp
, 1);
3422 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
3423 "Set mode of reading keyboard input.\n\
3424 First arg INTERRUPT non-nil means use input interrupts;\n\
3425 nil means use CBREAK mode.\n\
3426 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
3427 (no effect except in CBREAK mode).\n\
3428 Third arg META non-nil means accept 8-bit input (for a Meta key).\n\
3429 Otherwise, the top bit is ignored, on the assumption it is parity.\n\
3430 Optional fourth arg QUIT if non-nil specifies character to use for quitting.")
3431 (interrupt
, flow
, meta
, quit
)
3432 Lisp_Object interrupt
, flow
, meta
, quit
;
3435 && (XTYPE (quit
) != Lisp_Int
3436 || XINT (quit
) < 0 || XINT (quit
) > 0400))
3437 error ("set-input-mode: QUIT must be an ASCII character.");
3441 /* Note SIGIO has been undef'd if FIONREAD is missing. */
3442 #ifdef NO_SOCK_SIGIO
3443 if (read_socket_hook
)
3444 interrupt_input
= 0; /* No interrupts if reading from a socket. */
3446 #endif /* NO_SOCK_SIGIO */
3447 interrupt_input
= !NILP (interrupt
);
3448 #else /* not SIGIO */
3449 interrupt_input
= 0;
3450 #endif /* not SIGIO */
3451 /* Our VMS input only works by interrupts, as of now. */
3453 interrupt_input
= 1;
3455 flow_control
= !NILP (flow
);
3456 meta_key
= !NILP (meta
);
3458 /* Don't let this value be out of range. */
3459 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
3467 this_command_keys_size
= 40;
3469 (Lisp_Object
*) xmalloc (this_command_keys_size
* sizeof (Lisp_Object
));
3471 /* This is correct before outermost invocation of the editor loop */
3472 command_loop_level
= -1;
3474 quit_char
= Ctl ('g');
3475 unread_command_char
= Qnil
;
3477 kbd_fetch_ptr
= kbd_buffer
;
3478 kbd_store_ptr
= kbd_buffer
;
3479 do_mouse_tracking
= 0;
3482 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
3483 staticpro (&recent_keys
);
3484 recent_keys_index
= 0;
3486 if (!noninteractive
)
3488 signal (SIGINT
, interrupt_signal
);
3490 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
3491 SIGQUIT and we can't tell which one it will give us. */
3492 signal (SIGQUIT
, interrupt_signal
);
3493 #endif /* HAVE_TERMIO */
3494 /* Note SIGIO has been undef'd if FIONREAD is missing. */
3496 signal (SIGIO
, input_available_signal
);
3500 /* Use interrupt input by default, if it works and noninterrupt input
3501 has deficiencies. */
3503 #ifdef INTERRUPT_INPUT
3504 interrupt_input
= 1;
3506 interrupt_input
= 0;
3509 /* Our VMS input only works by interrupts, as of now. */
3511 interrupt_input
= 1;
3517 if (keyboard_init_hook
)
3518 (*keyboard_init_hook
) ();
3520 #ifdef POLL_FOR_INPUT
3521 poll_suppress_count
= 1;
3526 /* This type's only use is in syms_of_keyboard, to initialize the
3527 event header symbols and put properties on them. */
3534 struct event_head head_table
[] = {
3535 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
3536 &Qvscrollbar_part
, "vscrollbar-part", &Qscrollbar_click
,
3537 &Qvslider_part
, "vslider-part", &Qscrollbar_click
,
3538 &Qvthumbup_part
, "vthumbup-part", &Qscrollbar_click
,
3539 &Qvthumbdown_part
, "vthumbdown-part", &Qscrollbar_click
,
3540 &Qhscrollbar_part
, "hscrollbar-part", &Qscrollbar_click
,
3541 &Qhslider_part
, "hslider-part", &Qscrollbar_click
,
3542 &Qhthumbleft_part
, "hthumbleft-part", &Qscrollbar_click
,
3543 &Qhthumbright_part
,"hthumbright-part", &Qscrollbar_click
3548 Qself_insert_command
= intern ("self-insert-command");
3549 staticpro (&Qself_insert_command
);
3551 Qforward_char
= intern ("forward-char");
3552 staticpro (&Qforward_char
);
3554 Qbackward_char
= intern ("backward-char");
3555 staticpro (&Qbackward_char
);
3557 Qdisabled
= intern ("disabled");
3558 staticpro (&Qdisabled
);
3560 Qfunction_key
= intern ("function-key");
3561 staticpro (&Qfunction_key
);
3562 Qmouse_movement
= intern ("mouse-click");
3563 staticpro (&Qmouse_click
);
3564 Qmouse_movement
= intern ("scrollbar-click");
3565 staticpro (&Qmouse_movement
);
3567 Qmode_line
= intern ("mode-line");
3568 staticpro (&Qmode_line
);
3569 Qvertical_line
= intern ("vertical-line");
3570 staticpro (&Qvertical_line
);
3572 Qevent_kind
= intern ("event-type");
3573 staticpro (&Qevent_kind
);
3574 Qevent_unmodified
= intern ("event-unmodified");
3575 staticpro (&Qevent_unmodified
);
3578 struct event_head
*p
;
3580 for (p
= head_table
;
3581 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
3584 *p
->var
= intern (p
->name
);
3586 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
3587 Fput (*p
->var
, Qevent_unmodified
, *p
->var
);
3591 func_key_syms
= Qnil
;
3592 staticpro (&func_key_syms
);
3595 staticpro (&mouse_syms
);
3597 defsubr (&Sread_key_sequence
);
3598 defsubr (&Srecursive_edit
);
3599 defsubr (&Strack_mouse
);
3600 defsubr (&Smouse_click_p
);
3601 defsubr (&Sinput_pending_p
);
3602 defsubr (&Scommand_execute
);
3603 defsubr (&Srecent_keys
);
3604 defsubr (&Sthis_command_keys
);
3605 defsubr (&Ssuspend_emacs
);
3606 defsubr (&Sabort_recursive_edit
);
3607 defsubr (&Sexit_recursive_edit
);
3608 defsubr (&Srecursion_depth
);
3609 defsubr (&Stop_level
);
3610 defsubr (&Sdiscard_input
);
3611 defsubr (&Sopen_dribble_file
);
3612 defsubr (&Sset_input_mode
);
3613 defsubr (&Sexecute_extended_command
);
3615 DEFVAR_LISP ("disabled-command-hook", &Vdisabled_command_hook
,
3616 "Value is called instead of any command that is disabled\n\
3617 \(has a non-nil `disabled' property).");
3619 DEFVAR_LISP ("last-command-char", &last_command_char
,
3620 "Last terminal input key that was part of a command.");
3622 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
3623 "Last terminal input key in a command, except for mouse menus.\n\
3624 Mouse menus give back keys that don't look like mouse events;\n\
3625 this variable holds the actual mouse event that led to the menu,\n\
3626 so that you can determine whether the command was run by mouse or not.");
3628 DEFVAR_LISP ("last-input-char", &last_input_char
,
3629 "Last terminal input key.");
3631 DEFVAR_LISP ("unread-command-char", &unread_command_char
,
3632 "Object to be read as next input from input stream, or nil if none.");
3634 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
3635 "Meta-prefix character code. Meta-foo as command input\n\
3636 turns into this character followed by foo.");
3637 XSET (meta_prefix_char
, Lisp_Int
, 033);
3639 DEFVAR_LISP ("last-command", &last_command
,
3640 "The last command executed. Normally a symbol with a function definition,\n\
3641 but can be whatever was found in the keymap, or whatever the variable\n\
3642 `this-command' was set to by that command.");
3643 last_command
= Qnil
;
3645 DEFVAR_LISP ("this-command", &this_command
,
3646 "The command now being executed.\n\
3647 The command can set this variable; whatever is put here\n\
3648 will be in `last-command' during the following command.");
3649 this_command
= Qnil
;
3651 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
3652 "*Number of keyboard input characters between auto-saves.\n\
3653 Zero means disable autosaving due to number of characters typed.");
3654 auto_save_interval
= 300;
3656 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
3657 "*Number of seconds idle time before auto-save.\n\
3658 Zero or nil means disable auto-saving due to idleness.\n\
3659 After auto-saving due to this many seconds of idle time,\n\
3660 Emacs also does a garbage collection if that seems to be warranted.");
3661 XFASTINT (Vauto_save_timeout
) = 30;
3663 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes
,
3664 "*Nonzero means echo unfinished commands after this many seconds of pause.");
3665 echo_keystrokes
= 1;
3667 DEFVAR_INT ("polling-period", &polling_period
,
3668 "*Interval between polling for input during Lisp execution.\n\
3669 The reason for polling is to make C-g work to stop a running program.\n\
3670 Polling is needed only when using X windows and SIGIO does not work.\n\
3671 Polling is automatically disabled in all other cases.");
3674 DEFVAR_INT ("num-input-keys", &num_input_keys
,
3675 "*Number of complete keys read from the keyboard so far.");
3679 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
3680 "*The frame in which the most recently read event occurred.\n\
3681 If the last event came from a keyboard macro, this is set to `macro'.");
3682 Vlast_event_frame
= Qnil
;
3685 DEFVAR_LISP ("help-char", &help_char
,
3686 "Character to recognize as meaning Help.\n\
3687 When it is read, do `(eval help-form)', and display result if it's a string.\n\
3688 If the value of `help-form' is nil, this char can be read normally.");
3689 XSET (help_char
, Lisp_Int
, Ctl ('H'));
3691 DEFVAR_LISP ("help-form", &Vhelp_form
,
3692 "Form to execute when character help-char is read.\n\
3693 If the form returns a string, that string is displayed.\n\
3694 If `help-form' is nil, the help char is not recognized.");
3697 DEFVAR_LISP ("top-level", &Vtop_level
,
3698 "Form to evaluate when Emacs starts up.\n\
3699 Useful to set before you dump a modified Emacs.");
3702 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
3703 "String used as translate table for keyboard input, or nil.\n\
3704 Each character is looked up in this string and the contents used instead.\n\
3705 If string is of length N, character codes N and up are untranslated.");
3706 Vkeyboard_translate_table
= Qnil
;
3708 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
3709 "Non-nil means prompt with menus when appropriate.\n\
3710 This is done when reading from a keymap that has a prompt string,\n\
3711 for elements that have prompt strings.\n\
3712 The menu is displayed on the screen\n\
3713 if X menus were enabled at configuration\n\
3714 time and the previous event was a mouse click prefix key.\n\
3715 Otherwise, menu prompting uses the echo area.");
3718 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
3719 "Character to see next line of menu prompt.\n\
3720 Type this character while in a menu prompt to rotate around the lines of it.");
3721 XSET (menu_prompt_more_char
, Lisp_Int
, ' ');
3726 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
3727 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
3728 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
3729 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
3730 initial_define_key (meta_map
, 'x', "execute-extended-command");