1 /* Keyboard and mouse input; editor command loop.
2 Copyright (C) 1985,86,87,88,89,93,94,95 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* Allow config.h to undefine symbols found here. */
28 #include "termhooks.h"
35 #include "dispextern.h"
37 #include "intervals.h"
38 #include "blockinput.h"
47 #include <sys/ioctl.h>
49 #endif /* not MSDOS */
51 #include "syssignal.h"
54 /* This is to get the definitions of the XK_ symbols. */
59 /* Include systime.h after xterm.h to avoid double inclusion of time.h. */
64 /* Variables for blockinput.h: */
66 /* Non-zero if interrupt input is blocked right now. */
67 int interrupt_input_blocked
;
69 /* Nonzero means an input interrupt has arrived
70 during the current critical section. */
71 int interrupt_input_pending
;
74 /* File descriptor to use for input. */
78 /* Make all keyboard buffers much bigger when using X windows. */
79 #define KBD_BUFFER_SIZE 4096
80 #else /* No X-windows, character input */
81 #define KBD_BUFFER_SIZE 256
82 #endif /* No X-windows */
84 /* Following definition copied from eval.c */
88 struct backtrace
*next
;
89 Lisp_Object
*function
;
90 Lisp_Object
*args
; /* Points to vector of args. */
91 int nargs
; /* length of vector. If nargs is UNEVALLED,
92 args points to slot holding list of
98 KBOARD
*initial_kboard
;
99 KBOARD
*current_kboard
;
103 KBOARD the_only_kboard
;
106 /* Non-nil disable property on a command means
107 do not execute it; call disabled-command-hook's value instead. */
108 Lisp_Object Qdisabled
, Qdisabled_command_hook
;
110 #define NUM_RECENT_KEYS (100)
111 int recent_keys_index
; /* Index for storing next element into recent_keys */
112 int total_keys
; /* Total number of elements stored into recent_keys */
113 Lisp_Object recent_keys
; /* A vector, holding the last 100 keystrokes */
115 /* Vector holding the key sequence that invoked the current command.
116 It is reused for each command, and it may be longer than the current
117 sequence; this_command_key_count indicates how many elements
118 actually mean something.
119 It's easier to staticpro a single Lisp_Object than an array. */
120 Lisp_Object this_command_keys
;
121 int this_command_key_count
;
123 extern int minbuf_level
;
125 extern struct backtrace
*backtrace_list
;
127 /* Nonzero means do menu prompting. */
128 static int menu_prompting
;
130 /* Character to see next line of menu prompt. */
131 static Lisp_Object menu_prompt_more_char
;
133 /* For longjmp to where kbd input is being done. */
134 static jmp_buf getcjmp
;
136 /* True while doing kbd input. */
137 int waiting_for_input
;
139 /* True while displaying for echoing. Delays C-g throwing. */
142 /* Nonzero means disregard local maps for the menu bar. */
143 static int inhibit_local_menu_bar_menus
;
145 /* Nonzero means C-g should cause immediate error-signal. */
148 /* Character to recognize as the help char. */
149 Lisp_Object Vhelp_char
;
151 /* Form to execute when help char is typed. */
152 Lisp_Object Vhelp_form
;
154 /* Command to run when the help character follows a prefix key. */
155 Lisp_Object Vprefix_help_command
;
157 /* List of items that should move to the end of the menu bar. */
158 Lisp_Object Vmenu_bar_final_items
;
160 /* Character that causes a quit. Normally C-g.
162 If we are running on an ordinary terminal, this must be an ordinary
163 ASCII char, since we want to make it our interrupt character.
165 If we are not running on an ordinary terminal, it still needs to be
166 an ordinary ASCII char. This character needs to be recognized in
167 the input interrupt handler. At this point, the keystroke is
168 represented as a struct input_event, while the desired quit
169 character is specified as a lispy event. The mapping from struct
170 input_events to lispy events cannot run in an interrupt handler,
171 and the reverse mapping is difficult for anything but ASCII
174 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
178 extern Lisp_Object current_global_map
;
179 extern int minibuf_level
;
181 /* If non-nil, this is a map that overrides all other local maps. */
182 Lisp_Object Voverriding_local_map
;
184 /* If non-nil, Voverriding_local_map applies to the menu bar. */
185 Lisp_Object Voverriding_local_map_menu_flag
;
187 /* Current depth in recursive edits. */
188 int command_loop_level
;
190 /* Total number of times command_loop has read a key sequence. */
193 /* Last input character read as a command. */
194 Lisp_Object last_command_char
;
196 /* Last input character read as a command, not counting menus
197 reached by the mouse. */
198 Lisp_Object last_nonmenu_event
;
200 /* Last input character read for any purpose. */
201 Lisp_Object last_input_char
;
203 /* If not Qnil, a list of objects to be read as subsequent command input. */
204 Lisp_Object Vunread_command_events
;
206 /* If not -1, an event to be read as subsequent command input. */
207 int unread_command_char
;
209 /* If not Qnil, this is a switch-frame event which we decided to put
210 off until the end of a key sequence. This should be read as the
211 next command input, after any unread_command_events.
213 read_key_sequence uses this to delay switch-frame events until the
214 end of the key sequence; Fread_char uses it to put off switch-frame
215 events until a non-ASCII event is acceptable as input. */
216 Lisp_Object unread_switch_frame
;
218 /* A mask of extra modifier bits to put into every keyboard char. */
219 int extra_keyboard_modifiers
;
221 /* Char to use as prefix when a meta character is typed in.
222 This is bound on entry to minibuffer in case ESC is changed there. */
224 Lisp_Object meta_prefix_char
;
226 /* Last size recorded for a current buffer which is not a minibuffer. */
227 static int last_non_minibuf_size
;
229 /* Number of idle seconds before an auto-save and garbage collection. */
230 static Lisp_Object Vauto_save_timeout
;
232 /* Total number of times read_char has returned. */
235 /* Total number of times read_char has returned, outside of macros. */
236 int num_nonmacro_input_chars
;
238 /* Auto-save automatically when this many characters have been typed
239 since the last time. */
241 static int auto_save_interval
;
243 /* Value of num_nonmacro_input_chars as of last auto save. */
247 /* Last command executed by the editor command loop, not counting
248 commands that set the prefix argument. */
250 Lisp_Object last_command
;
252 /* The command being executed by the command loop.
253 Commands may set this, and the value set will be copied into last_command
254 instead of the actual command. */
255 Lisp_Object this_command
;
257 /* The value of point when the last command was executed. */
258 int last_point_position
;
260 /* The buffer that was current when the last command was started. */
261 Lisp_Object last_point_position_buffer
;
264 /* The frame in which the last input event occurred, or Qmacro if the
265 last event came from a macro. We use this to determine when to
266 generate switch-frame events. This may be cleared by functions
267 like Fselect_frame, to make sure that a switch-frame event is
268 generated by the next character. */
269 Lisp_Object internal_last_event_frame
;
272 /* A user-visible version of the above, intended to allow users to
273 figure out where the last event came from, if the event doesn't
274 carry that information itself (i.e. if it was a character). */
275 Lisp_Object Vlast_event_frame
;
277 /* The timestamp of the last input event we received from the X server.
278 X Windows wants this for selection ownership. */
279 unsigned long last_event_timestamp
;
281 Lisp_Object Qself_insert_command
;
282 Lisp_Object Qforward_char
;
283 Lisp_Object Qbackward_char
;
284 Lisp_Object Qundefined
;
285 Lisp_Object Qdigit_argument
, Qnegative_argument
;
287 /* read_key_sequence stores here the command definition of the
288 key sequence that it reads. */
289 Lisp_Object read_key_sequence_cmd
;
291 /* Form to evaluate (if non-nil) when Emacs is started. */
292 Lisp_Object Vtop_level
;
294 /* User-supplied string to translate input characters through. */
295 Lisp_Object Vkeyboard_translate_table
;
297 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
298 extern Lisp_Object Vfunction_key_map
;
300 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
301 Lisp_Object Vkey_translation_map
;
303 /* Non-nil means deactivate the mark at end of this command. */
304 Lisp_Object Vdeactivate_mark
;
306 /* Menu bar specified in Lucid Emacs fashion. */
308 Lisp_Object Vlucid_menu_bar_dirty_flag
;
309 Lisp_Object Qrecompute_lucid_menubar
, Qactivate_menubar_hook
;
311 /* Hooks to run before and after each command. */
312 Lisp_Object Qpre_command_hook
, Qpost_command_hook
;
313 Lisp_Object Vpre_command_hook
, Vpost_command_hook
;
314 Lisp_Object Qcommand_hook_internal
, Vcommand_hook_internal
;
316 /* List of deferred actions to be performed at a later time.
317 The precise format isn't relevant here; we just check whether it is nil. */
318 Lisp_Object Vdeferred_action_list
;
320 /* Function to call to handle deferred actions, when there are any. */
321 Lisp_Object Vdeferred_action_function
;
322 Lisp_Object Qdeferred_action_function
;
324 /* File in which we write all commands we read. */
327 /* Nonzero if input is available. */
330 /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
331 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
335 extern char *pending_malloc_warning
;
337 /* Circular buffer for pre-read keyboard input. */
338 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
340 /* Vector to GCPRO the frames and windows mentioned in kbd_buffer.
342 The interrupt-level event handlers will never enqueue an event on a
343 frame which is not in Vframe_list, and once an event is dequeued,
344 internal_last_event_frame or the event itself points to the frame.
347 But while the event is sitting in the queue, it's completely
348 unprotected. Suppose the user types one command which will run for
349 a while and then delete a frame, and then types another event at
350 the frame that will be deleted, before the command gets around to
351 it. Suppose there are no references to this frame elsewhere in
352 Emacs, and a GC occurs before the second event is dequeued. Now we
353 have an event referring to a freed frame, which will crash Emacs
356 Similar things happen when an event on a scroll bar is enqueued; the
357 window may be deleted while the event is in the queue.
359 So, we use this vector to protect the frame_or_window field in the
360 event queue. That way, they'll be dequeued as dead frames or
361 windows, but still valid lisp objects.
363 If kbd_buffer[i].kind != no_event, then
364 (XVECTOR (kbd_buffer_frame_or_window)->contents[i]
365 == kbd_buffer[i].frame_or_window. */
366 static Lisp_Object kbd_buffer_frame_or_window
;
368 /* Pointer to next available character in kbd_buffer.
369 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
370 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the
371 next available char is in kbd_buffer[0]. */
372 static struct input_event
*kbd_fetch_ptr
;
374 /* Pointer to next place to store character in kbd_buffer. This
375 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
376 character should go in kbd_buffer[0]. */
377 static volatile struct input_event
*kbd_store_ptr
;
379 /* The above pair of variables forms a "queue empty" flag. When we
380 enqueue a non-hook event, we increment kbd_store_ptr. When we
381 dequeue a non-hook event, we increment kbd_fetch_ptr. We say that
382 there is input available iff the two pointers are not equal.
384 Why not just have a flag set and cleared by the enqueuing and
385 dequeuing functions? Such a flag could be screwed up by interrupts
386 at inopportune times. */
389 /* If this flag is a frame, we check mouse_moved to see when the
390 mouse moves, and motion events will appear in the input stream.
391 Otherwise, mouse motion is ignored. */
392 static Lisp_Object do_mouse_tracking
;
394 /* The window system handling code should set this if the mouse has
395 moved since the last call to the mouse_position_hook. Calling that
396 hook should clear this. Code assumes that if this is set, it can
397 call mouse_position_hook to get the promised position, so don't set
398 it unless you're prepared to substantiate the claim! */
400 #endif /* HAVE_MOUSE. */
402 /* Symbols to head events. */
403 Lisp_Object Qmouse_movement
;
404 Lisp_Object Qscroll_bar_movement
;
405 Lisp_Object Qswitch_frame
;
406 Lisp_Object Qdelete_frame
;
407 Lisp_Object Qiconify_frame
;
408 Lisp_Object Qmake_frame_visible
;
410 /* Symbols to denote kinds of events. */
411 Lisp_Object Qfunction_key
;
412 Lisp_Object Qmouse_click
;
413 /* Lisp_Object Qmouse_movement; - also an event header */
415 /* Properties of event headers. */
416 Lisp_Object Qevent_kind
;
417 Lisp_Object Qevent_symbol_elements
;
419 Lisp_Object Qmenu_enable
;
421 /* An event header symbol HEAD may have a property named
422 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
423 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
424 mask of modifiers applied to it. If present, this is used to help
425 speed up parse_modifiers. */
426 Lisp_Object Qevent_symbol_element_mask
;
428 /* An unmodified event header BASE may have a property named
429 Qmodifier_cache, which is an alist mapping modifier masks onto
430 modified versions of BASE. If present, this helps speed up
432 Lisp_Object Qmodifier_cache
;
434 /* Symbols to use for parts of windows. */
435 Lisp_Object Qmode_line
;
436 Lisp_Object Qvertical_line
;
437 Lisp_Object Qvertical_scroll_bar
;
438 Lisp_Object Qmenu_bar
;
440 extern Lisp_Object Qmenu_enable
;
442 Lisp_Object
recursive_edit_unwind (), command_loop ();
443 Lisp_Object
Fthis_command_keys ();
444 Lisp_Object Qextended_command_history
;
446 Lisp_Object Qpolling_period
;
448 extern Lisp_Object Vprint_level
, Vprint_length
;
450 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
452 EMACS_TIME
*input_available_clear_time
;
454 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
455 Default is 1 if INTERRUPT_INPUT is defined. */
458 /* Nonzero while interrupts are temporarily deferred during redisplay. */
459 int interrupts_deferred
;
461 /* nonzero means use ^S/^Q for flow control. */
464 /* Allow m- file to inhibit use of FIONREAD. */
465 #ifdef BROKEN_FIONREAD
469 /* We are unable to use interrupts if FIONREAD is not available,
470 so flush SIGIO so we won't try. */
477 /* If we support X Windows, turn on the code to poll periodically
478 to detect C-g. It isn't actually used when doing interrupt input. */
479 #ifdef HAVE_X_WINDOWS
480 #define POLL_FOR_INPUT
483 /* Global variable declarations. */
485 /* Function for init_keyboard to call with no args (if nonzero). */
486 void (*keyboard_init_hook
) ();
488 static int read_avail_input ();
489 static void get_input_pending ();
490 static int readable_events ();
491 static Lisp_Object
read_char_x_menu_prompt ();
492 static Lisp_Object
read_char_minibuf_menu_prompt ();
493 static Lisp_Object
make_lispy_event ();
495 static Lisp_Object
make_lispy_movement ();
497 static Lisp_Object
modify_event_symbol ();
498 static Lisp_Object
make_lispy_switch_frame ();
499 static int parse_solitary_modifier ();
501 /* > 0 if we are to echo keystrokes. */
502 static int echo_keystrokes
;
504 /* Nonzero means don't try to suspend even if the operating system seems
506 static int cannot_suspend
;
508 #define min(a,b) ((a)<(b)?(a):(b))
509 #define max(a,b) ((a)>(b)?(a):(b))
511 /* Install the string STR as the beginning of the string of echoing,
512 so that it serves as a prompt for the next character.
513 Also start echoing. */
518 int len
= strlen (str
);
520 if (len
> ECHOBUFSIZE
- 4)
521 len
= ECHOBUFSIZE
- 4;
522 bcopy (str
, current_kboard
->echobuf
, len
);
523 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
524 *current_kboard
->echoptr
= '\0';
526 current_kboard
->echo_after_prompt
= len
;
531 /* Add C to the echo string, if echoing is going on.
532 C can be a character, which is printed prettily ("M-C-x" and all that
533 jazz), or a symbol, whose name is printed. */
538 extern char *push_key_description ();
540 if (current_kboard
->immediate_echo
)
542 char *ptr
= current_kboard
->echoptr
;
544 if (ptr
!= current_kboard
->echobuf
)
547 /* If someone has passed us a composite event, use its head symbol. */
552 if (ptr
- current_kboard
->echobuf
> ECHOBUFSIZE
- 6)
555 ptr
= push_key_description (XINT (c
), ptr
);
557 else if (SYMBOLP (c
))
559 struct Lisp_String
*name
= XSYMBOL (c
)->name
;
560 if ((ptr
- current_kboard
->echobuf
) + name
->size
+ 4 > ECHOBUFSIZE
)
562 bcopy (name
->data
, ptr
, name
->size
);
566 if (current_kboard
->echoptr
== current_kboard
->echobuf
567 && EQ (c
, Vhelp_char
))
569 strcpy (ptr
, " (Type ? for further options)");
574 current_kboard
->echoptr
= ptr
;
580 /* Temporarily add a dash to the end of the echo string if it's not
581 empty, so that it serves as a mini-prompt for the very next character. */
585 if (!current_kboard
->immediate_echo
586 && current_kboard
->echoptr
== current_kboard
->echobuf
)
588 /* Do nothing if we just printed a prompt. */
589 if (current_kboard
->echo_after_prompt
590 == current_kboard
->echoptr
- current_kboard
->echobuf
)
592 /* Do nothing if not echoing at all. */
593 if (current_kboard
->echoptr
== 0)
596 /* Put a dash at the end of the buffer temporarily,
597 but make it go away when the next character is added. */
598 current_kboard
->echoptr
[0] = '-';
599 current_kboard
->echoptr
[1] = 0;
604 /* Display the current echo string, and begin echoing if not already
609 if (!current_kboard
->immediate_echo
)
612 current_kboard
->immediate_echo
= 1;
614 for (i
= 0; i
< this_command_key_count
; i
++)
617 c
= XVECTOR (this_command_keys
)->contents
[i
];
618 if (! (EVENT_HAS_PARAMETERS (c
)
619 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
626 message1_nolog (current_kboard
->echobuf
);
629 if (waiting_for_input
&& !NILP (Vquit_flag
))
630 quit_throw_to_read_char ();
633 /* Turn off echoing, for the start of a new command. */
637 current_kboard
->immediate_echo
= 0;
638 current_kboard
->echoptr
= current_kboard
->echobuf
;
639 current_kboard
->echo_after_prompt
= -1;
642 /* Return the length of the current echo string. */
647 return current_kboard
->echoptr
- current_kboard
->echobuf
;
650 /* Truncate the current echo message to its first LEN chars.
651 This and echo_char get used by read_key_sequence when the user
652 switches frames while entering a key sequence. */
658 current_kboard
->echobuf
[len
] = '\0';
659 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
660 truncate_echo_area (len
);
664 /* Functions for manipulating this_command_keys. */
666 add_command_key (key
)
669 int size
= XVECTOR (this_command_keys
)->size
;
671 if (this_command_key_count
>= size
)
673 Lisp_Object new_keys
;
675 new_keys
= Fmake_vector (make_number (size
* 2), Qnil
);
676 bcopy (XVECTOR (this_command_keys
)->contents
,
677 XVECTOR (new_keys
)->contents
,
678 size
* sizeof (Lisp_Object
));
680 this_command_keys
= new_keys
;
683 XVECTOR (this_command_keys
)->contents
[this_command_key_count
++] = key
;
689 int count
= specpdl_ptr
- specpdl
;
692 if (command_loop_level
> 0)
694 specbind (Qstandard_output
, Qt
);
695 specbind (Qstandard_input
, Qt
);
698 val
= command_loop ();
700 Fsignal (Qquit
, Qnil
);
702 return unbind_to (count
, Qnil
);
705 /* When an auto-save happens, record the "time", and don't do again soon. */
709 last_auto_save
= num_nonmacro_input_chars
;
712 /* Make an auto save happen as soon as possible at command level. */
714 force_auto_save_soon ()
716 last_auto_save
= - auto_save_interval
- 1;
718 record_asynch_buffer_change ();
721 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
722 "Invoke the editor command loop recursively.\n\
723 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
724 that tells this function to return.\n\
725 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
726 This function is called by the editor initialization to begin editing.")
729 int count
= specpdl_ptr
- specpdl
;
732 command_loop_level
++;
733 update_mode_lines
= 1;
735 record_unwind_protect (recursive_edit_unwind
,
737 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
741 return unbind_to (count
, Qnil
);
745 recursive_edit_unwind (buffer
)
749 Fset_buffer (buffer
);
751 command_loop_level
--;
752 update_mode_lines
= 1;
760 if (CONSP (Vunread_command_events
))
762 current_kboard
->kbd_queue
763 = nconc2 (Vunread_command_events
, current_kboard
->kbd_queue
);
764 current_kboard
->kbd_queue_has_data
= 1;
766 Vunread_command_events
= Qnil
;
775 Lisp_Object old_level
, old_length
;
777 Vstandard_output
= Qt
;
778 Vstandard_input
= Qt
;
779 Vexecuting_macro
= Qnil
;
783 /* Avoid unquittable loop if data contains a circular list. */
784 old_level
= Vprint_level
;
785 old_length
= Vprint_length
;
786 XSETFASTINT(Vprint_level
, 10);
787 XSETFASTINT(Vprint_length
, 10);
788 cmd_error_internal (data
, 0);
789 Vprint_level
= old_level
;
790 Vprint_length
= old_length
;
794 Vinhibit_quit
= Qnil
;
799 return make_number (0);
802 cmd_error_internal (data
, context
)
806 Lisp_Object errmsg
, tail
, errname
, file_error
;
813 echo_area_glyphs
= 0;
815 /* If the window system or terminal frame hasn't been initialized
816 yet, or we're not interactive, it's best to dump this message out
817 to stderr and exit. */
818 if (! FRAME_MESSAGE_BUF (selected_frame
)
820 stream
= Qexternal_debugging_output
;
829 write_string_1 (context
, -1, stream
);
831 errname
= Fcar (data
);
833 if (EQ (errname
, Qerror
))
836 if (!CONSP (data
)) data
= Qnil
;
837 errmsg
= Fcar (data
);
842 errmsg
= Fget (errname
, Qerror_message
);
843 file_error
= Fmemq (Qfile_error
,
844 Fget (errname
, Qerror_conditions
));
847 /* Print an error message including the data items.
848 This is done by printing it into a scratch buffer
849 and then making a copy of the text in the buffer. */
851 if (!CONSP (data
)) data
= Qnil
;
855 /* For file-error, make error message by concatenating
856 all the data items. They are all strings. */
857 if (!NILP (file_error
) && !NILP (tail
))
858 errmsg
= XCONS (tail
)->car
, tail
= XCONS (tail
)->cdr
;
860 if (STRINGP (errmsg
))
861 Fprinc (errmsg
, stream
);
863 write_string_1 ("peculiar error", -1, stream
);
865 for (i
= 0; CONSP (tail
); tail
= Fcdr (tail
), i
++)
867 write_string_1 (i
? ", " : ": ", 2, stream
);
868 if (!NILP (file_error
))
869 Fprinc (Fcar (tail
), stream
);
871 Fprin1 (Fcar (tail
), stream
);
875 /* If the window system or terminal frame hasn't been initialized
876 yet, or we're in -batch mode, this error should cause Emacs to exit. */
877 if (! FRAME_MESSAGE_BUF (selected_frame
)
881 Fkill_emacs (make_number (-1));
885 Lisp_Object
command_loop_1 ();
886 Lisp_Object
command_loop_2 ();
887 Lisp_Object
top_level_1 ();
889 /* Entry to editor-command-loop.
890 This level has the catches for exiting/returning to editor command loop.
891 It returns nil to exit recursive edit, t to abort it. */
896 if (command_loop_level
> 0 || minibuf_level
> 0)
898 return internal_catch (Qexit
, command_loop_2
, Qnil
);
903 internal_catch (Qtop_level
, top_level_1
, Qnil
);
904 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
906 /* End of file in -batch run causes exit here. */
912 /* Here we catch errors in execution of commands within the
913 editing loop, and reenter the editing loop.
914 When there is an error, cmd_error runs and returns a non-nil
915 value to us. A value of nil means that cmd_loop_1 itself
916 returned due to end of file (or end of kbd macro). */
921 register Lisp_Object val
;
924 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
933 return Feval (Vtop_level
);
939 /* On entry to the outer level, run the startup file */
940 if (!NILP (Vtop_level
))
941 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
942 else if (!NILP (Vpurify_flag
))
943 message ("Bare impure Emacs (standard Lisp code not loaded)");
945 message ("Bare Emacs (standard Lisp code not loaded)");
949 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
950 "Exit all recursive editing levels.")
953 Fthrow (Qtop_level
, Qnil
);
956 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
957 "Exit from the innermost recursive edit or minibuffer.")
960 if (command_loop_level
> 0 || minibuf_level
> 0)
961 Fthrow (Qexit
, Qnil
);
963 error ("No recursive edit is in progress");
966 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
967 "Abort the command that requested this recursive edit or minibuffer input.")
970 if (command_loop_level
> 0 || minibuf_level
> 0)
973 error ("No recursive edit is in progress");
976 /* This is the actual command reading loop,
977 sans error-handling encapsulation. */
979 Lisp_Object
Fcommand_execute ();
980 static int read_key_sequence ();
981 static void safe_run_hooks ();
986 Lisp_Object cmd
, tem
;
989 Lisp_Object keybuf
[30];
994 struct buffer
*prev_buffer
;
996 int was_locked
= kboard_locked
;
999 Vdeactivate_mark
= Qnil
;
1000 waiting_for_input
= 0;
1005 this_command_key_count
= 0;
1007 /* Make sure this hook runs after commands that get errors and
1008 throw to top level. */
1009 /* Note that the value cell will never directly contain nil
1010 if the symbol is a local variable. */
1011 if (!NILP (XSYMBOL (Qpost_command_hook
)->value
) && !NILP (Vrun_hooks
))
1012 safe_run_hooks (Qpost_command_hook
);
1014 if (!NILP (Vdeferred_action_list
))
1015 call0 (Vdeferred_action_function
);
1017 /* Do this after running Vpost_command_hook, for consistency. */
1018 last_command
= this_command
;
1022 /* Make sure the current window's buffer is selected. */
1023 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1024 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1026 /* Display any malloc warning that just came out. Use while because
1027 displaying one warning can cause another. */
1029 while (pending_malloc_warning
)
1030 display_malloc_warning ();
1034 Vdeactivate_mark
= Qnil
;
1036 /* If minibuffer on and echo area in use,
1037 wait 2 sec and redraw minibuffer. */
1039 if (minibuf_level
&& echo_area_glyphs
)
1041 /* Bind inhibit-quit to t so that C-g gets read in
1042 rather than quitting back to the minibuffer. */
1043 int count
= specpdl_ptr
- specpdl
;
1044 specbind (Qinhibit_quit
, Qt
);
1045 Fsit_for (make_number (2), Qnil
, Qnil
);
1046 unbind_to (count
, Qnil
);
1048 echo_area_glyphs
= 0;
1050 if (!NILP (Vquit_flag
))
1053 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1058 alloca (0); /* Cause a garbage collection now */
1059 /* Since we can free the most stuff here. */
1060 #endif /* C_ALLOCA */
1064 /* Select the frame that the last event came from. Usually,
1065 switch-frame events will take care of this, but if some lisp
1066 code swallows a switch-frame event, we'll fix things up here.
1067 Is this a good idea? */
1068 if (FRAMEP (internal_last_event_frame
)
1069 && XFRAME (internal_last_event_frame
) != selected_frame
)
1070 Fselect_frame (internal_last_event_frame
, Qnil
);
1073 /* If it has changed current-menubar from previous value,
1074 really recompute the menubar from the value. */
1075 if (! NILP (Vlucid_menu_bar_dirty_flag
)
1076 && !NILP (Ffboundp (Qrecompute_lucid_menubar
)))
1077 call0 (Qrecompute_lucid_menubar
);
1079 /* Read next key sequence; i gets its length. */
1080 i
= read_key_sequence (keybuf
, sizeof keybuf
/ sizeof keybuf
[0],
1085 /* Now we have read a key sequence of length I,
1086 or else I is 0 and we found end of file. */
1088 if (i
== 0) /* End of file -- happens only in */
1089 return Qnil
; /* a kbd macro, at the end. */
1090 /* -1 means read_key_sequence got a menu that was rejected.
1091 Just loop around and read another command. */
1095 this_command_key_count
= 0;
1099 last_command_char
= keybuf
[i
- 1];
1101 /* If the previous command tried to force a specific window-start,
1102 forget about that, in case this command moves point far away
1103 from that position. */
1104 XWINDOW (selected_window
)->force_start
= Qnil
;
1106 cmd
= read_key_sequence_cmd
;
1107 if (!NILP (Vexecuting_macro
))
1109 if (!NILP (Vquit_flag
))
1111 Vexecuting_macro
= Qt
;
1112 QUIT
; /* Make some noise. */
1113 /* Will return since macro now empty. */
1117 /* Do redisplay processing after this command except in special
1118 cases identified below that set no_redisplay to 1.
1119 (actually, there's currently no way to prevent the redisplay,
1120 and no_redisplay is ignored.
1121 Perhaps someday we will really implement it.) */
1124 prev_buffer
= current_buffer
;
1125 prev_modiff
= MODIFF
;
1126 last_point_position
= PT
;
1127 XSETBUFFER (last_point_position_buffer
, prev_buffer
);
1129 /* If we're building a prefix argument, override minus and digits. */
1130 if (current_kboard
->prefix_partial
&& i
== 1 && NATNUMP (keybuf
[0]))
1132 if (XFASTINT (keybuf
[0]) == '-'
1133 && NILP (current_kboard
->prefix_value
))
1134 cmd
= Qnegative_argument
;
1135 else if (XFASTINT (keybuf
[0]) >= '0' && XFASTINT (keybuf
[0]) <= '9')
1136 cmd
= Qdigit_argument
;
1139 /* Execute the command. */
1142 /* Note that the value cell will never directly contain nil
1143 if the symbol is a local variable. */
1144 if (!NILP (XSYMBOL (Qpre_command_hook
)->value
) && !NILP (Vrun_hooks
))
1145 safe_run_hooks (Qpre_command_hook
);
1147 if (NILP (this_command
))
1149 /* nil means key is undefined. */
1151 current_kboard
->defining_kbd_macro
= Qnil
;
1152 update_mode_lines
= 1;
1153 clear_prefix_arg ();
1157 current_prefix_partial
= current_kboard
->prefix_partial
;
1158 if (current_kboard
->prefix_partial
)
1159 finalize_prefix_arg ();
1161 if (NILP (Vprefix_arg
) && ! no_direct
)
1163 /* Recognize some common commands in common situations and
1164 do them directly. */
1165 if (EQ (this_command
, Qforward_char
) && PT
< ZV
)
1167 struct Lisp_Vector
*dp
1168 = window_display_table (XWINDOW (selected_window
));
1169 lose
= FETCH_CHAR (PT
);
1172 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1173 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1174 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1175 && (lose
>= 0x20 && lose
< 0x7f)))
1176 : (lose
>= 0x20 && lose
< 0x7f))
1177 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1179 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1181 && !windows_or_buffers_changed
1182 && EQ (current_buffer
->selective_display
, Qnil
)
1183 && !detect_input_pending ()
1184 && NILP (Vexecuting_macro
))
1185 no_redisplay
= direct_output_forward_char (1);
1188 else if (EQ (this_command
, Qbackward_char
) && PT
> BEGV
)
1190 struct Lisp_Vector
*dp
1191 = window_display_table (XWINDOW (selected_window
));
1193 lose
= FETCH_CHAR (PT
);
1195 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1196 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1197 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1198 && (lose
>= 0x20 && lose
< 0x7f)))
1199 : (lose
>= 0x20 && lose
< 0x7f))
1200 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1202 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1204 && !windows_or_buffers_changed
1205 && EQ (current_buffer
->selective_display
, Qnil
)
1206 && !detect_input_pending ()
1207 && NILP (Vexecuting_macro
))
1208 no_redisplay
= direct_output_forward_char (-1);
1211 else if (EQ (this_command
, Qself_insert_command
)
1212 /* Try this optimization only on ascii keystrokes. */
1213 && INTEGERP (last_command_char
))
1215 unsigned char c
= XINT (last_command_char
);
1218 if (NILP (Vexecuting_macro
)
1219 && !EQ (minibuf_window
, selected_window
))
1221 if (!nonundocount
|| nonundocount
>= 20)
1228 lose
= ((XFASTINT (XWINDOW (selected_window
)->last_modified
)
1230 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1232 || MODIFF
<= SAVE_MODIFF
1233 || windows_or_buffers_changed
1234 || !EQ (current_buffer
->selective_display
, Qnil
)
1235 || detect_input_pending ()
1236 || !NILP (Vexecuting_macro
));
1237 value
= internal_self_insert (c
, 0);
1244 && (PT
== ZV
|| FETCH_CHAR (PT
) == '\n'))
1246 struct Lisp_Vector
*dp
1247 = window_display_table (XWINDOW (selected_window
));
1254 obj
= DISP_CHAR_VECTOR (dp
, lose
);
1257 /* Do it only for char codes
1258 that by default display as themselves. */
1259 if (lose
>= 0x20 && lose
<= 0x7e)
1260 no_redisplay
= direct_output_for_insert (lose
);
1262 else if (VECTORP (obj
)
1263 && XVECTOR (obj
)->size
== 1
1264 && (obj
= XVECTOR (obj
)->contents
[0],
1266 /* Insist face not specified in glyph. */
1267 && (XINT (obj
) & ((-1) << 8)) == 0)
1269 = direct_output_for_insert (XINT (obj
));
1273 if (lose
>= 0x20 && lose
<= 0x7e)
1274 no_redisplay
= direct_output_for_insert (lose
);
1281 /* Here for a command that isn't executed directly */
1284 if (NILP (Vprefix_arg
))
1286 Fcommand_execute (this_command
, Qnil
);
1291 /* Note that the value cell will never directly contain nil
1292 if the symbol is a local variable. */
1293 if (!NILP (XSYMBOL (Qpost_command_hook
)->value
) && !NILP (Vrun_hooks
))
1294 safe_run_hooks (Qpost_command_hook
);
1296 if (!NILP (Vdeferred_action_list
))
1297 safe_run_hooks (Qdeferred_action_function
);
1299 /* If there is a prefix argument,
1300 1) We don't want last_command to be ``universal-argument''
1301 (that would be dumb), so don't set last_command,
1302 2) we want to leave echoing on so that the prefix will be
1303 echoed as part of this key sequence, so don't call
1305 3) we want to leave this_command_key_count non-zero, so that
1306 read_char will realize that it is re-reading a character, and
1307 not echo it a second time. */
1308 if (NILP (Vprefix_arg
) && !current_kboard
->prefix_partial
)
1310 last_command
= this_command
;
1312 this_command_key_count
= 0;
1315 if (!NILP (current_buffer
->mark_active
) && !NILP (Vrun_hooks
))
1317 if (!NILP (Vdeactivate_mark
) && !NILP (Vtransient_mark_mode
))
1319 current_buffer
->mark_active
= Qnil
;
1320 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
1322 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
1323 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
1327 /* Install chars successfully executed in kbd macro. */
1329 if (!NILP (current_kboard
->defining_kbd_macro
) && NILP (Vprefix_arg
)
1330 && !current_kboard
->prefix_partial
)
1331 finalize_kbd_macro_chars ();
1340 /* If we get an error while running the hook, cause the hook variable
1341 to be nil. Also inhibit quits, so that C-g won't cause the hook
1342 to mysteriously evaporate. */
1344 safe_run_hooks (hook
)
1348 int count
= specpdl_ptr
- specpdl
;
1349 specbind (Qinhibit_quit
, Qt
);
1351 /* We read and set the variable with functions,
1352 in case it's buffer-local. */
1353 value
= Vcommand_hook_internal
= Fsymbol_value (hook
);
1355 call1 (Vrun_hooks
, Qcommand_hook_internal
);
1358 unbind_to (count
, Qnil
);
1361 /* Number of seconds between polling for input. */
1364 /* Nonzero means polling for input is temporarily suppressed. */
1365 int poll_suppress_count
;
1367 /* Nonzero if polling_for_input is actually being used. */
1368 int polling_for_input
;
1370 #ifdef POLL_FOR_INPUT
1372 /* Handle an alarm once each second and read pending input
1373 so as to handle a C-g if it comces in. */
1376 input_poll_signal (signalnum
) /* If we don't have an argument, */
1377 int signalnum
; /* some compilers complain in signal calls. */
1379 if (interrupt_input_blocked
== 0
1380 && !waiting_for_input
)
1381 read_avail_input (0);
1382 signal (SIGALRM
, input_poll_signal
);
1383 alarm (polling_period
);
1388 /* Begin signals to poll for input, if they are appropriate.
1389 This function is called unconditionally from various places. */
1393 #ifdef POLL_FOR_INPUT
1394 if (read_socket_hook
&& !interrupt_input
)
1396 poll_suppress_count
--;
1397 if (poll_suppress_count
== 0)
1399 signal (SIGALRM
, input_poll_signal
);
1400 polling_for_input
= 1;
1401 alarm (polling_period
);
1407 /* Nonzero if we are using polling to handle input asynchronously. */
1410 input_polling_used ()
1412 #ifdef POLL_FOR_INPUT
1413 return read_socket_hook
&& !interrupt_input
;
1419 /* Turn off polling. */
1423 #ifdef POLL_FOR_INPUT
1424 if (read_socket_hook
&& !interrupt_input
)
1426 if (poll_suppress_count
== 0)
1428 polling_for_input
= 0;
1431 poll_suppress_count
++;
1436 /* Set the value of poll_suppress_count to COUNT
1437 and start or stop polling accordingly. */
1440 set_poll_suppress_count (count
)
1443 #ifdef POLL_FOR_INPUT
1444 if (count
== 0 && poll_suppress_count
!= 0)
1446 poll_suppress_count
= 1;
1449 else if (count
!= 0 && poll_suppress_count
== 0)
1453 poll_suppress_count
= count
;
1457 /* Bind polling_period to a value at least N.
1458 But don't decrease it. */
1460 bind_polling_period (n
)
1463 #ifdef POLL_FOR_INPUT
1464 int new = polling_period
;
1470 specbind (Qpolling_period
, make_number (new));
1471 /* Start a new alarm with the new period. */
1476 /* Apply the control modifier to CHARACTER. */
1482 /* Save the upper bits here. */
1483 int upper
= c
& ~0177;
1487 /* Everything in the columns containing the upper-case letters
1488 denotes a control character. */
1489 if (c
>= 0100 && c
< 0140)
1493 /* Set the shift modifier for a control char
1494 made from a shifted letter. But only for letters! */
1495 if (oc
>= 'A' && oc
<= 'Z')
1496 c
|= shift_modifier
;
1499 /* The lower-case letters denote control characters too. */
1500 else if (c
>= 'a' && c
<= 'z')
1503 /* Include the bits for control and shift
1504 only if the basic ASCII code can't indicate them. */
1508 /* Replace the high bits. */
1509 c
|= (upper
& ~ctrl_modifier
);
1516 /* Input of single characters from keyboard */
1518 Lisp_Object
print_help ();
1519 static Lisp_Object
kbd_buffer_get_event ();
1520 static void record_char ();
1523 static jmp_buf wrong_kboard_jmpbuf
;
1526 /* read a character from the keyboard; call the redisplay if needed */
1527 /* commandflag 0 means do not do auto-saving, but do do redisplay.
1528 -1 means do not do redisplay, but do do autosaving.
1531 /* The arguments MAPS and NMAPS are for menu prompting.
1532 MAPS is an array of keymaps; NMAPS is the length of MAPS.
1534 PREV_EVENT is the previous input event, or nil if we are reading
1535 the first event of a key sequence.
1537 If USED_MOUSE_MENU is non-zero, then we set *USED_MOUSE_MENU to 1
1538 if we used a mouse menu to read the input, or zero otherwise. If
1539 USED_MOUSE_MENU is zero, *USED_MOUSE_MENU is left alone.
1541 Value is t if we showed a menu and the user rejected it. */
1544 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
)
1548 Lisp_Object prev_event
;
1549 int *used_mouse_menu
;
1551 register Lisp_Object c
;
1554 int key_already_recorded
= 0;
1555 Lisp_Object also_record
;
1558 if (CONSP (Vunread_command_events
))
1560 c
= XCONS (Vunread_command_events
)->car
;
1561 Vunread_command_events
= XCONS (Vunread_command_events
)->cdr
;
1563 if (this_command_key_count
== 0)
1569 if (unread_command_char
!= -1)
1571 XSETINT (c
, unread_command_char
);
1572 unread_command_char
= -1;
1574 if (this_command_key_count
== 0)
1580 if (!NILP (Vexecuting_macro
))
1583 /* We set this to Qmacro; since that's not a frame, nobody will
1584 try to switch frames on us, and the selected window will
1587 Since this event came from a macro, it would be misleading to
1588 leave internal_last_event_frame set to wherever the last
1589 real event came from. Normally, a switch-frame event selects
1590 internal_last_event_frame after each command is read, but
1591 events read from a macro should never cause a new frame to be
1593 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
1596 /* Exit the macro if we are at the end.
1597 Also, some things replace the macro with t
1598 to force an early exit. */
1599 if (EQ (Vexecuting_macro
, Qt
)
1600 || executing_macro_index
>= XFASTINT (Flength (Vexecuting_macro
)))
1606 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
1607 if (STRINGP (Vexecuting_macro
)
1608 && (XINT (c
) & 0x80))
1609 XSETFASTINT (c
, CHAR_META
| (XINT (c
) & ~0x80));
1611 executing_macro_index
++;
1616 if (!NILP (unread_switch_frame
))
1618 c
= unread_switch_frame
;
1619 unread_switch_frame
= Qnil
;
1621 /* This event should make it into this_command_keys, and get echoed
1622 again, so we go to reread_first, rather than reread. */
1626 /* Don't bother updating menu bars while doing mouse tracking.
1627 We get events very rapidly then, and the menu bar won't be changing.
1628 We do update the menu bar once on entry to Ftrack_mouse. */
1629 if (commandflag
> 0 && !input_pending
&& !detect_input_pending ())
1630 prepare_menu_bars ();
1632 /* Save outer setjmp data, in case called recursively. */
1633 save_getcjmp (save_jump
);
1637 if (commandflag
>= 0 && !input_pending
&& !detect_input_pending ())
1640 if (_setjmp (getcjmp
))
1642 XSETINT (c
, quit_char
);
1644 XSETFRAME (internal_last_event_frame
, selected_frame
);
1645 Vlast_event_frame
= internal_last_event_frame
;
1647 /* If we report the quit char as an event,
1648 don't do so more than once. */
1649 if (!NILP (Vinhibit_quit
))
1654 KBOARD
*kb
= FRAME_KBOARD (selected_frame
);
1655 if (kb
!= current_kboard
)
1657 Lisp_Object
*tailp
= &kb
->kbd_queue
;
1658 /* We shouldn't get here if we were locked onto one kboard! */
1661 while (CONSP (*tailp
))
1662 tailp
= &XCONS (*tailp
)->cdr
;
1665 *tailp
= Fcons (c
, Qnil
);
1666 kb
->kbd_queue_has_data
= 1;
1667 current_kboard
= kb
;
1668 longjmp (wrong_kboard_jmpbuf
, 1);
1675 /* Message turns off echoing unless more keystrokes turn it on again. */
1676 if (echo_area_glyphs
&& *echo_area_glyphs
1677 && echo_area_glyphs
!= current_kboard
->echobuf
)
1680 /* If already echoing, continue. */
1683 /* Try reading a character via menu prompting in the minibuf.
1684 Try this before the sit-for, because the sit-for
1685 would do the wrong thing if we are supposed to do
1686 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
1687 after a mouse event so don't try a minibuf menu. */
1689 if (nmaps
> 0 && INTERACTIVE
1690 && !NILP (prev_event
) && ! EVENT_HAS_PARAMETERS (prev_event
)
1691 /* Don't bring up a menu if we already have another event. */
1692 && NILP (Vunread_command_events
)
1693 && unread_command_char
< 0
1694 && !detect_input_pending ())
1696 c
= read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
);
1699 key_already_recorded
= 1;
1704 /* If in middle of key sequence and minibuffer not active,
1705 start echoing if enough time elapses. */
1706 if (minibuf_level
== 0 && !current_kboard
->immediate_echo
1707 && this_command_key_count
> 0
1709 && echo_keystrokes
> 0
1710 && (echo_area_glyphs
== 0 || *echo_area_glyphs
== 0))
1714 /* After a mouse event, start echoing right away.
1715 This is because we are probably about to display a menu,
1716 and we don't want to delay before doing so. */
1717 if (EVENT_HAS_PARAMETERS (prev_event
))
1721 tem0
= sit_for (echo_keystrokes
, 0, 1, 1);
1727 /* Maybe auto save due to number of keystrokes or idle time. */
1729 if (commandflag
!= 0
1730 && auto_save_interval
> 0
1731 && num_nonmacro_input_chars
- last_auto_save
> max (auto_save_interval
, 20)
1732 && !detect_input_pending ())
1735 save_getcjmp (temp
);
1736 Fdo_auto_save (Qnil
, Qnil
);
1737 /* Hooks can actually change some buffers in auto save. */
1739 restore_getcjmp (temp
);
1742 /* Try reading using an X menu.
1743 This is never confused with reading using the minibuf
1744 because the recursive call of read_char in read_char_minibuf_menu_prompt
1745 does not pass on any keymaps. */
1746 if (nmaps
> 0 && INTERACTIVE
1747 && !NILP (prev_event
) && EVENT_HAS_PARAMETERS (prev_event
)
1748 /* Don't bring up a menu if we already have another event. */
1749 && NILP (Vunread_command_events
)
1750 && unread_command_char
< 0)
1751 c
= read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
1753 /* Slow down auto saves logarithmically in size of current buffer,
1754 and garbage collect while we're at it. */
1755 if (INTERACTIVE
&& NILP (c
))
1757 int delay_level
, buffer_size
;
1759 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
1760 last_non_minibuf_size
= Z
- BEG
;
1761 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
1763 while (buffer_size
> 64)
1764 delay_level
++, buffer_size
-= buffer_size
>> 2;
1765 if (delay_level
< 4) delay_level
= 4;
1766 /* delay_level is 4 for files under around 50k, 7 at 100k,
1767 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
1769 /* Auto save if enough time goes by without input. */
1770 if (commandflag
!= 0
1771 && num_nonmacro_input_chars
> last_auto_save
1772 && INTEGERP (Vauto_save_timeout
)
1773 && XINT (Vauto_save_timeout
) > 0)
1776 int delay
= delay_level
* XFASTINT (Vauto_save_timeout
) / 4;
1777 tem0
= sit_for (delay
, 0, 1, 1);
1781 save_getcjmp (temp
);
1782 Fdo_auto_save (Qnil
, Qnil
);
1783 restore_getcjmp (temp
);
1785 /* If we have auto-saved and there is still no input
1786 available, garbage collect if there has been enough
1787 consing going on to make it worthwhile. */
1788 if (!detect_input_pending ()
1789 && consing_since_gc
> gc_cons_threshold
/ 2)
1790 Fgarbage_collect ();
1791 /* prepare_menu_bars isn't safe here, but it should
1792 also be unnecessary. */
1800 /* Primary consideration goes to current_kboard's side queue.
1801 If that's empty, then we check the other side queues and throw
1802 if we find something there. Finally, we read from the main queue,
1803 and if that gives us something we can't use yet, we put it on the
1804 appropriate side queue and try again. */
1805 if (current_kboard
->kbd_queue_has_data
)
1807 if (!CONSP (current_kboard
->kbd_queue
))
1809 c
= XCONS (current_kboard
->kbd_queue
)->car
;
1810 current_kboard
->kbd_queue
1811 = XCONS (current_kboard
->kbd_queue
)->cdr
;
1812 if (NILP (current_kboard
->kbd_queue
))
1813 current_kboard
->kbd_queue_has_data
= 0;
1814 input_pending
= readable_events ();
1816 if (EVENT_HAS_PARAMETERS (c
)
1817 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qswitch_frame
))
1818 internal_last_event_frame
= XCONS (XCONS (c
)->cdr
)->car
;
1819 Vlast_event_frame
= internal_last_event_frame
;
1828 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
1829 if (kb
->kbd_queue_has_data
)
1831 current_kboard
= kb
;
1832 longjmp (wrong_kboard_jmpbuf
, 1);
1838 /* Actually read a character, waiting if necessary. */
1839 while (c
= kbd_buffer_get_event (&kb
), NILP (c
))
1841 if (commandflag
>= 0
1842 && !input_pending
&& !detect_input_pending ())
1844 prepare_menu_bars ();
1849 if (kb
!= current_kboard
)
1851 Lisp_Object
*tailp
= &kb
->kbd_queue
;
1852 while (CONSP (*tailp
))
1853 tailp
= &XCONS (*tailp
)->cdr
;
1856 *tailp
= Fcons (c
, Qnil
);
1857 kb
->kbd_queue_has_data
= 1;
1860 current_kboard
= kb
;
1861 longjmp (wrong_kboard_jmpbuf
, 1);
1866 /* Terminate Emacs in batch mode if at eof. */
1867 if (noninteractive
&& INTEGERP (c
) && XINT (c
) < 0)
1868 Fkill_emacs (make_number (1));
1872 /* Add in any extra modifiers, where appropriate. */
1873 if ((extra_keyboard_modifiers
& CHAR_CTL
)
1874 || ((extra_keyboard_modifiers
& 0177) < ' '
1875 && (extra_keyboard_modifiers
& 0177) != 0))
1876 XSETINT (c
, make_ctrl_char (XINT (c
)));
1878 /* Transfer any other modifier bits directly from
1879 extra_keyboard_modifiers to c. Ignore the actual character code
1880 in the low 16 bits of extra_keyboard_modifiers. */
1881 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
1886 restore_getcjmp (save_jump
);
1890 /* Buffer switch events are only for internal wakeups
1891 so don't show them to the user. */
1895 if (key_already_recorded
)
1898 /* Wipe the echo area. */
1899 echo_area_glyphs
= 0;
1901 /* Handle things that only apply to characters. */
1904 /* If kbd_buffer_get_event gave us an EOF, return that. */
1908 if (STRINGP (Vkeyboard_translate_table
)
1909 && XSTRING (Vkeyboard_translate_table
)->size
> XFASTINT (c
))
1910 XSETINT (c
, XSTRING (Vkeyboard_translate_table
)->data
[XFASTINT (c
)]);
1913 /* If this event is a mouse click in the menu bar,
1914 return just menu-bar for now. Modify the mouse click event
1915 so we won't do this twice, then queue it up. */
1916 if (EVENT_HAS_PARAMETERS (c
)
1917 && CONSP (XCONS (c
)->cdr
)
1918 && CONSP (EVENT_START (c
))
1919 && CONSP (XCONS (EVENT_START (c
))->cdr
))
1923 posn
= POSN_BUFFER_POSN (EVENT_START (c
));
1924 /* Handle menu-bar events:
1925 insert the dummy prefix event `menu-bar'. */
1926 if (EQ (posn
, Qmenu_bar
))
1928 /* Change menu-bar to (menu-bar) as the event "position". */
1929 POSN_BUFFER_POSN (EVENT_START (c
)) = Fcons (posn
, Qnil
);
1932 Vunread_command_events
= Fcons (c
, Vunread_command_events
);
1938 if (! NILP (also_record
))
1939 record_char (also_record
);
1944 /* Don't echo mouse motion events. */
1946 && ! (EVENT_HAS_PARAMETERS (c
)
1947 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
1950 if (! NILP (also_record
))
1951 echo_char (also_record
);
1954 /* Record this character as part of the current key. */
1955 add_command_key (c
);
1956 if (! NILP (also_record
))
1957 add_command_key (also_record
);
1959 /* Re-reading in the middle of a command */
1961 last_input_char
= c
;
1964 /* Process the help character specially if enabled */
1965 if (EQ (c
, Vhelp_char
) && !NILP (Vhelp_form
))
1968 count
= specpdl_ptr
- specpdl
;
1970 record_unwind_protect (Fset_window_configuration
,
1971 Fcurrent_window_configuration (Qnil
));
1973 tem0
= Feval (Vhelp_form
);
1975 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
1979 c
= read_char (0, 0, 0, Qnil
, 0);
1980 while (BUFFERP (c
));
1981 /* Remove the help from the frame */
1982 unbind_to (count
, Qnil
);
1983 prepare_menu_bars ();
1985 if (EQ (c
, make_number (040)))
1989 c
= read_char (0, 0, 0, Qnil
, 0);
1990 while (BUFFERP (c
));
1997 /* Record the input event C in various ways. */
2004 XVECTOR (recent_keys
)->contents
[recent_keys_index
] = c
;
2005 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
2006 recent_keys_index
= 0;
2008 /* Write c to the dribble file. If c is a lispy event, write
2009 the event's symbol to the dribble file, in <brackets>. Bleaugh.
2010 If you, dear reader, have a better idea, you've got the source. :-) */
2015 if (XUINT (c
) < 0x100)
2016 putc (XINT (c
), dribble
);
2018 fprintf (dribble
, " 0x%x", XUINT (c
));
2022 Lisp_Object dribblee
;
2024 /* If it's a structured event, take the event header. */
2025 dribblee
= EVENT_HEAD (c
);
2027 if (SYMBOLP (dribblee
))
2029 putc ('<', dribble
);
2030 fwrite (XSYMBOL (dribblee
)->name
->data
, sizeof (char),
2031 XSYMBOL (dribblee
)->name
->size
,
2033 putc ('>', dribble
);
2040 store_kbd_macro_char (c
);
2042 num_nonmacro_input_chars
++;
2049 struct buffer
*old
= current_buffer
;
2050 Fprinc (object
, Qnil
);
2051 set_buffer_internal (XBUFFER (Vstandard_output
));
2052 call0 (intern ("help-mode"));
2053 set_buffer_internal (old
);
2057 /* Copy out or in the info on where C-g should throw to.
2058 This is used when running Lisp code from within get_char,
2059 in case get_char is called recursively.
2060 See read_process_output. */
2065 bcopy (getcjmp
, temp
, sizeof getcjmp
);
2068 restore_getcjmp (temp
)
2071 bcopy (temp
, getcjmp
, sizeof getcjmp
);
2077 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
2078 of this function. */
2081 tracking_off (old_value
)
2082 Lisp_Object old_value
;
2084 do_mouse_tracking
= old_value
;
2085 if (NILP (old_value
))
2087 /* Redisplay may have been preempted because there was input
2088 available, and it assumes it will be called again after the
2089 input has been processed. If the only input available was
2090 the sort that we have just disabled, then we need to call
2092 if (!readable_events ())
2094 prepare_menu_bars ();
2095 redisplay_preserve_echo_area ();
2096 get_input_pending (&input_pending
);
2101 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
2102 "Evaluate BODY with mouse movement events enabled.\n\
2103 Within a `track-mouse' form, mouse motion generates input events that\n\
2104 you can read with `read-event'.\n\
2105 Normally, mouse motion is ignored.")
2109 int count
= specpdl_ptr
- specpdl
;
2112 record_unwind_protect (tracking_off
, do_mouse_tracking
);
2114 if (!input_pending
&& !detect_input_pending ())
2115 prepare_menu_bars ();
2117 XSETFRAME (do_mouse_tracking
, selected_frame
);
2119 val
= Fprogn (args
);
2120 return unbind_to (count
, val
);
2123 #endif /* HAVE_MOUSE */
2125 /* Low level keyboard/mouse input.
2126 kbd_buffer_store_event places events in kbd_buffer, and
2127 kbd_buffer_get_event retrieves them.
2128 mouse_moved indicates when the mouse has moved again, and
2129 *mouse_position_hook provides the mouse position. */
2131 /* Return true iff there are any events in the queue that read-char
2132 would return. If this returns false, a read-char would block. */
2136 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2139 if (FRAMEP (do_mouse_tracking
) && mouse_moved
)
2144 if (current_kboard
->kbd_queue_has_data
)
2150 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2151 if (kb
->kbd_queue_has_data
)
2157 /* Set this for debugging, to have a way to get out */
2162 event_to_kboard (event
)
2163 struct input_event
*event
;
2166 frame
= event
->frame_or_window
;
2168 frame
= XCONS (frame
)->car
;
2169 else if (WINDOWP (frame
))
2170 frame
= WINDOW_FRAME (XWINDOW (frame
));
2172 /* There are still some events that don't set this field.
2173 For now, just ignore the problem. */
2174 if (!FRAMEP (frame
))
2177 return FRAME_KBOARD (XFRAME (frame
));
2181 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
2184 kbd_buffer_store_event (event
)
2185 register struct input_event
*event
;
2187 if (event
->kind
== no_event
)
2190 if (event
->kind
== ascii_keystroke
)
2192 register int c
= event
->code
& 0377;
2194 if (event
->modifiers
& ctrl_modifier
)
2195 c
= make_ctrl_char (c
);
2197 c
|= (event
->modifiers
2198 & (meta_modifier
| alt_modifier
2199 | hyper_modifier
| super_modifier
));
2203 extern SIGTYPE
interrupt_signal ();
2206 struct input_event
*sp
;
2209 && (kb
= FRAME_KBOARD (XFRAME (event
->frame_or_window
)),
2210 kb
!= current_kboard
))
2213 = Fcons (make_lispy_switch_frame (event
->frame_or_window
),
2214 Fcons (make_number (c
), Qnil
));
2215 kb
->kbd_queue_has_data
= 1;
2216 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
2218 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
2221 if (event_to_kboard (sp
) == kb
)
2223 sp
->kind
= no_event
;
2224 sp
->frame_or_window
= Qnil
;
2232 /* If this results in a quit_char being returned to Emacs as
2233 input, set Vlast_event_frame properly. If this doesn't
2234 get returned to Emacs as an event, the next event read
2235 will set Vlast_event_frame again, so this is safe to do. */
2239 focus
= FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
2241 focus
= event
->frame_or_window
;
2242 internal_last_event_frame
= focus
;
2243 Vlast_event_frame
= focus
;
2247 last_event_timestamp
= event
->timestamp
;
2248 interrupt_signal ();
2252 if (c
&& c
== stop_character
)
2259 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
2260 kbd_store_ptr
= kbd_buffer
;
2262 /* Don't let the very last slot in the buffer become full,
2263 since that would make the two pointers equal,
2264 and that is indistinguishable from an empty buffer.
2265 Discard the event if it would fill the last slot. */
2266 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
2268 volatile struct input_event
*sp
= kbd_store_ptr
;
2269 sp
->kind
= event
->kind
;
2270 if (event
->kind
== selection_request_event
)
2272 /* We must not use the ordinary copying code for this case,
2273 since `part' is an enum and copying it might not copy enough
2275 bcopy (event
, (char *) sp
, sizeof (*event
));
2279 sp
->code
= event
->code
;
2280 sp
->part
= event
->part
;
2281 sp
->frame_or_window
= event
->frame_or_window
;
2282 sp
->modifiers
= event
->modifiers
;
2285 sp
->timestamp
= event
->timestamp
;
2287 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_store_ptr
2289 = event
->frame_or_window
);
2295 /* Read one event from the event buffer, waiting if necessary.
2296 The value is a Lisp object representing the event.
2297 The value is nil for an event that should be ignored,
2298 or that was handled here.
2299 We always read and discard one event. */
2302 kbd_buffer_get_event (KBOARD
**kbp
)
2311 *kbp
= all_kboards
; /* There'd better be exactly one! */
2315 /* Wait until there is input available. */
2318 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2321 if (FRAMEP (do_mouse_tracking
) && mouse_moved
)
2325 /* If the quit flag is set, then read_char will return
2326 quit_char, so that counts as "available input." */
2327 if (!NILP (Vquit_flag
))
2328 quit_throw_to_read_char ();
2330 /* One way or another, wait until input is available; then, if
2331 interrupt handlers have not read it, read it now. */
2334 wait_for_kbd_input ();
2336 /* Note SIGIO has been undef'd if FIONREAD is missing. */
2340 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2343 if (FRAMEP (do_mouse_tracking
) && mouse_moved
)
2347 Lisp_Object minus_one
;
2349 XSETINT (minus_one
, -1);
2350 wait_reading_process_input (0, 0, minus_one
, 1);
2352 if (!interrupt_input
&& kbd_fetch_ptr
== kbd_store_ptr
)
2353 /* Pass 1 for EXPECT since we just waited to have input. */
2354 read_avail_input (1);
2356 #endif /* not VMS */
2359 /* At this point, we know that there is a readable event available
2360 somewhere. If the event queue is empty, then there must be a
2361 mouse movement enabled and available. */
2362 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2364 struct input_event
*event
;
2366 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2370 last_event_timestamp
= event
->timestamp
;
2373 *kbp
= event_to_kboard (event
);
2375 *kbp
= current_kboard
; /* Better than returning null ptr? */
2377 *kbp
= &the_only_kboard
;
2382 /* These two kinds of events get special handling
2383 and don't actually appear to the command loop.
2384 We return nil for them. */
2385 if (event
->kind
== selection_request_event
)
2388 struct input_event copy
= *event
;
2389 /* Remove it from the buffer before processing it,
2390 since otherwise swallow_events will see it
2391 and process it again. */
2392 kbd_fetch_ptr
= event
+ 1;
2393 x_handle_selection_request (©
);
2395 /* We're getting selection request events, but we don't have
2401 else if (event
->kind
== selection_clear_event
)
2404 x_handle_selection_clear (event
);
2405 kbd_fetch_ptr
= event
+ 1;
2407 /* We're getting selection request events, but we don't have
2413 else if (event
->kind
== delete_window_event
)
2415 /* Make an event (delete-frame (FRAME)). */
2416 obj
= Fcons (event
->frame_or_window
, Qnil
);
2417 obj
= Fcons (Qdelete_frame
, Fcons (obj
, Qnil
));
2418 kbd_fetch_ptr
= event
+ 1;
2420 else if (event
->kind
== iconify_event
)
2422 /* Make an event (iconify-frame (FRAME)). */
2423 obj
= Fcons (event
->frame_or_window
, Qnil
);
2424 obj
= Fcons (Qiconify_frame
, Fcons (obj
, Qnil
));
2425 kbd_fetch_ptr
= event
+ 1;
2427 else if (event
->kind
== deiconify_event
)
2429 /* Make an event (make-frame-visible (FRAME)). */
2430 obj
= Fcons (event
->frame_or_window
, Qnil
);
2431 obj
= Fcons (Qmake_frame_visible
, Fcons (obj
, Qnil
));
2432 kbd_fetch_ptr
= event
+ 1;
2435 else if (event
->kind
== menu_bar_event
)
2437 /* The event value is in the cdr of the frame_or_window slot. */
2438 if (!CONSP (event
->frame_or_window
))
2440 obj
= XCONS (event
->frame_or_window
)->cdr
;
2441 kbd_fetch_ptr
= event
+ 1;
2443 else if (event
->kind
== buffer_switch_event
)
2445 /* The value doesn't matter here; only the type is tested. */
2446 XSETBUFFER (obj
, current_buffer
);
2447 kbd_fetch_ptr
= event
+ 1;
2449 /* Just discard these, by returning nil.
2450 With MULTI_KBOARD, these events are used as placeholders
2451 when we need to randomly delete events from the queue.
2452 (They shouldn't otherwise be found in the buffer,
2453 but on some machines it appears they do show up
2454 even without MULTI_KBOARD.) */
2455 else if (event
->kind
== no_event
)
2456 kbd_fetch_ptr
= event
+ 1;
2458 /* If this event is on a different frame, return a switch-frame this
2459 time, and leave the event in the queue for next time. */
2466 frame
= event
->frame_or_window
;
2467 if (WINDOWP (frame
))
2468 frame
= WINDOW_FRAME (XWINDOW (frame
));
2470 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
2474 if (! EQ (frame
, internal_last_event_frame
)
2475 && XFRAME (frame
) != selected_frame
)
2476 obj
= make_lispy_switch_frame (frame
);
2477 internal_last_event_frame
= frame
;
2478 #endif /* MULTI_FRAME */
2480 /* If we didn't decide to make a switch-frame event, go ahead
2481 and build a real event from the queue entry. */
2485 obj
= make_lispy_event (event
);
2487 /* Wipe out this event, to catch bugs. */
2488 event
->kind
= no_event
;
2489 XVECTOR (kbd_buffer_frame_or_window
)->contents
[event
- kbd_buffer
] = Qnil
;
2491 kbd_fetch_ptr
= event
+ 1;
2496 /* Try generating a mouse motion event. */
2497 else if (FRAMEP (do_mouse_tracking
) && mouse_moved
)
2499 FRAME_PTR f
= XFRAME (do_mouse_tracking
);
2500 Lisp_Object bar_window
;
2501 enum scroll_bar_part part
;
2505 *kbp
= current_kboard
;
2506 /* Note that this uses F to determine which display to look at.
2507 If there is no valid info, it does not store anything
2508 so x remains nil. */
2510 (*mouse_position_hook
) (&f
, &bar_window
, &part
, &x
, &y
, &time
);
2515 /* Decide if we should generate a switch-frame event. Don't
2516 generate switch-frame events for motion outside of all Emacs
2522 frame
= FRAME_FOCUS_FRAME (f
);
2524 XSETFRAME (frame
, f
);
2526 if (! EQ (frame
, internal_last_event_frame
)
2527 && XFRAME (frame
) != selected_frame
)
2528 obj
= make_lispy_switch_frame (frame
);
2529 internal_last_event_frame
= frame
;
2533 /* If we didn't decide to make a switch-frame event, go ahead and
2534 return a mouse-motion event. */
2535 if (!NILP (x
) && NILP (obj
))
2536 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
2538 #endif /* HAVE_MOUSE */
2540 /* We were promised by the above while loop that there was
2541 something for us to read! */
2544 input_pending
= readable_events ();
2547 Vlast_event_frame
= internal_last_event_frame
;
2553 /* Process any events that are not user-visible,
2554 then return, without reading any user-visible events. */
2559 while (kbd_fetch_ptr
!= kbd_store_ptr
)
2561 struct input_event
*event
;
2563 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2567 last_event_timestamp
= event
->timestamp
;
2569 /* These two kinds of events get special handling
2570 and don't actually appear to the command loop. */
2571 if (event
->kind
== selection_request_event
)
2574 struct input_event copy
;
2576 kbd_fetch_ptr
= event
+ 1;
2577 x_handle_selection_request (©
);
2579 /* We're getting selection request events, but we don't have
2585 else if (event
->kind
== selection_clear_event
)
2588 x_handle_selection_clear (event
);
2589 kbd_fetch_ptr
= event
+ 1;
2591 /* We're getting selection request events, but we don't have
2600 get_input_pending (&input_pending
);
2603 /* Caches for modify_event_symbol. */
2604 static Lisp_Object accent_key_syms
;
2605 static Lisp_Object system_key_syms
;
2606 static Lisp_Object func_key_syms
;
2607 static Lisp_Object mouse_syms
;
2609 Lisp_Object Vsystem_key_alist
;
2611 /* This is a list of keysym codes for special "accent" characters.
2612 It parallels lispy_accent_keys. */
2614 static int lispy_accent_codes
[] =
2616 #ifdef XK_dead_circumflex
2621 #ifdef XK_dead_grave
2626 #ifdef XK_dead_tilde
2631 #ifdef XK_dead_diaeresis
2636 #ifdef XK_dead_macron
2641 #ifdef XK_dead_degree
2646 #ifdef XK_dead_acute
2651 #ifdef XK_dead_cedilla
2656 #ifdef XK_dead_breve
2661 #ifdef XK_dead_ogonek
2666 #ifdef XK_dead_caron
2671 #ifdef XK_dead_doubleacute
2672 XK_dead_doubleacute
,
2676 #ifdef XK_dead_abovedot
2683 /* This is a list of Lisp names for special "accent" characters.
2684 It parallels lispy_accent_codes. */
2686 static char *lispy_accent_keys
[] =
2703 /* You'll notice that this table is arranged to be conveniently
2704 indexed by X Windows keysym values. */
2705 static char *lispy_function_keys
[] =
2707 /* X Keysym value */
2709 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00 */
2717 0, 0, 0, /* 0xff10 */
2719 0, 0, 0, 0, 0, 0, 0,
2722 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff20...2f */
2723 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff30...3f */
2724 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
2726 "home", /* 0xff50 */ /* IsCursorKey */
2737 "select", /* 0xff60 */ /* IsMiscFunctionKey */
2748 "break", /* 0xff6b */
2750 0, 0, 0, 0, 0, 0, 0, 0, "backtab", 0,
2752 0, 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff7f */
2753 "kp-space", /* 0xff80 */ /* IsKeypadKey */
2754 0, 0, 0, 0, 0, 0, 0, 0,
2755 "kp-tab", /* 0xff89 */
2757 "kp-enter", /* 0xff8d */
2759 "kp-f1", /* 0xff91 */
2763 "kp-home", /* 0xff95 */
2768 "kp-prior", /* kp-page-up */
2769 "kp-next", /* kp-page-down */
2775 0, 0, 0, 0, 0, 0, 0, 0, 0,
2776 "kp-multiply", /* 0xffaa */
2781 "kp-divide", /* 0xffaf */
2782 "kp-0", /* 0xffb0 */
2783 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
2786 "kp-equal", /* 0xffbd */
2787 "f1", /* 0xffbe */ /* IsFunctionKey */
2789 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
2790 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
2791 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
2792 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
2793 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
2794 0, 0, 0, 0, 0, 0, 0, 0,
2795 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
2796 0, 0, 0, 0, 0, 0, 0, "delete"
2799 static char *lispy_mouse_names
[] =
2801 "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5"
2804 /* Scroll bar parts. */
2805 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
2807 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
2808 Lisp_Object
*scroll_bar_parts
[] = {
2809 &Qabove_handle
, &Qhandle
, &Qbelow_handle
2813 /* A vector, indexed by button number, giving the down-going location
2814 of currently depressed buttons, both scroll bar and non-scroll bar.
2816 The elements have the form
2817 (BUTTON-NUMBER MODIFIER-MASK . REST)
2818 where REST is the cdr of a position as it would be reported in the event.
2820 The make_lispy_event function stores positions here to tell the
2821 difference between click and drag events, and to store the starting
2822 location to be included in drag events. */
2824 static Lisp_Object button_down_location
;
2826 /* Information about the most recent up-going button event: Which
2827 button, what location, and what time. */
2829 static int last_mouse_button
;
2830 static int last_mouse_x
;
2831 static int last_mouse_y
;
2832 static unsigned long button_down_time
;
2834 /* The maximum time between clicks to make a double-click,
2835 or Qnil to disable double-click detection,
2836 or Qt for no time limit. */
2837 Lisp_Object Vdouble_click_time
;
2839 /* The number of clicks in this multiple-click. */
2841 int double_click_count
;
2843 #ifdef USE_X_TOOLKIT
2844 extern Lisp_Object
map_event_to_object ();
2845 #endif /* USE_X_TOOLKIT */
2847 /* Given a struct input_event, build the lisp event which represents
2848 it. If EVENT is 0, build a mouse movement event from the mouse
2849 movement buffer, which should have a movement event in it.
2851 Note that events must be passed to this function in the order they
2852 are received; this function stores the location of button presses
2853 in order to build drag events when the button is released. */
2856 make_lispy_event (event
)
2857 struct input_event
*event
;
2861 switch (SWITCH_ENUM_CAST (event
->kind
))
2863 /* A simple keystroke. */
2864 case ascii_keystroke
:
2866 Lisp_Object lispy_c
;
2867 int c
= event
->code
& 0377;
2868 /* Turn ASCII characters into control characters
2870 if (event
->modifiers
& ctrl_modifier
)
2871 c
= make_ctrl_char (c
);
2873 /* Add in the other modifier bits. We took care of ctrl_modifier
2874 just above, and the shift key was taken care of by the X code,
2875 and applied to control characters by make_ctrl_char. */
2876 c
|= (event
->modifiers
2877 & (meta_modifier
| alt_modifier
2878 | hyper_modifier
| super_modifier
));
2879 button_down_time
= 0;
2880 XSETFASTINT (lispy_c
, c
);
2884 /* A function key. The symbol may need to have modifier prefixes
2886 case non_ascii_keystroke
:
2887 button_down_time
= 0;
2889 for (i
= 0; i
< sizeof (lispy_accent_codes
) / sizeof (int); i
++)
2890 if (event
->code
== lispy_accent_codes
[i
])
2891 return modify_event_symbol (i
,
2893 Qfunction_key
, Qnil
,
2894 lispy_accent_keys
, &accent_key_syms
,
2895 (sizeof (lispy_accent_keys
)
2896 / sizeof (lispy_accent_keys
[0])));
2898 /* Handle system-specific keysyms. */
2899 if (event
->code
& (1 << 28))
2901 /* We need to use an alist rather than a vector as the cache
2902 since we can't make a vector long enuf. */
2903 if (NILP (system_key_syms
))
2904 system_key_syms
= Fcons (Qnil
, Qnil
);
2905 return modify_event_symbol (event
->code
& 0xffffff,
2907 Qfunction_key
, Vsystem_key_alist
,
2908 0, &system_key_syms
, 0xffffff);
2911 return modify_event_symbol (event
->code
- 0xff00,
2913 Qfunction_key
, Qnil
,
2914 lispy_function_keys
, &func_key_syms
,
2915 (sizeof (lispy_function_keys
)
2916 / sizeof (lispy_function_keys
[0])));
2920 /* A mouse click. Figure out where it is, decide whether it's
2921 a press, click or drag, and build the appropriate structure. */
2923 case scroll_bar_click
:
2925 int button
= event
->code
;
2927 Lisp_Object position
;
2928 Lisp_Object
*start_pos_ptr
;
2929 Lisp_Object start_pos
;
2931 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
2934 /* Build the position as appropriate for this mouse click. */
2935 if (event
->kind
== mouse_click
)
2938 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
2943 /* Ignore mouse events that were made on frame that
2944 have been deleted. */
2945 if (! FRAME_LIVE_P (f
))
2948 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
2949 &column
, &row
, 0, 1);
2951 #ifndef USE_X_TOOLKIT
2952 /* In the non-toolkit version, clicks on the menu bar
2953 are ordinary button events in the event buffer.
2954 Distinguish them, and invoke the menu.
2956 (In the toolkit version, the toolkit handles the menu bar
2957 and Emacs doesn't know about it until after the user
2958 makes a selection.) */
2959 if (row
>= 0 && row
< FRAME_MENU_BAR_LINES (f
))
2961 Lisp_Object items
, item
;
2965 /* Activate the menu bar on the down event. If the
2966 up event comes in before the menu code can deal with it,
2968 if (! (event
->modifiers
& down_modifier
))
2972 items
= FRAME_MENU_BAR_ITEMS (f
);
2973 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 3)
2975 Lisp_Object pos
, string
;
2976 string
= XVECTOR (items
)->contents
[i
+ 1];
2977 pos
= XVECTOR (items
)->contents
[i
+ 2];
2980 if (column
>= XINT (pos
)
2981 && column
< XINT (pos
) + XSTRING (string
)->size
)
2983 item
= XVECTOR (items
)->contents
[i
];
2989 = Fcons (event
->frame_or_window
,
2991 Fcons (Fcons (event
->x
, event
->y
),
2992 Fcons (make_number (event
->timestamp
),
2995 return Fcons (item
, Fcons (position
, Qnil
));
2997 #endif /* not USE_X_TOOLKIT */
2999 window
= window_from_coordinates (f
, column
, row
, &part
);
3001 if (!WINDOWP (window
))
3003 window
= event
->frame_or_window
;
3008 int pixcolumn
, pixrow
;
3009 column
-= XINT (XWINDOW (window
)->left
);
3010 row
-= XINT (XWINDOW (window
)->top
);
3011 glyph_to_pixel_coords (f
, column
, row
, &pixcolumn
, &pixrow
);
3012 XSETINT (event
->x
, pixcolumn
);
3013 XSETINT (event
->y
, pixrow
);
3018 posn
= Qvertical_line
;
3021 buffer_posn_from_coords (XWINDOW (window
),
3028 Fcons (Fcons (event
->x
, event
->y
),
3029 Fcons (make_number (event
->timestamp
),
3035 Lisp_Object portion_whole
;
3038 window
= event
->frame_or_window
;
3039 portion_whole
= Fcons (event
->x
, event
->y
);
3040 part
= *scroll_bar_parts
[(int) event
->part
];
3044 Fcons (Qvertical_scroll_bar
,
3045 Fcons (portion_whole
,
3046 Fcons (make_number (event
->timestamp
),
3047 Fcons (part
, Qnil
)))));
3050 start_pos_ptr
= &XVECTOR (button_down_location
)->contents
[button
];
3052 start_pos
= *start_pos_ptr
;
3053 *start_pos_ptr
= Qnil
;
3055 is_double
= (button
== last_mouse_button
3056 && XINT (event
->x
) == last_mouse_x
3057 && XINT (event
->y
) == last_mouse_y
3058 && button_down_time
!= 0
3059 && (EQ (Vdouble_click_time
, Qt
)
3060 || (INTEGERP (Vdouble_click_time
)
3061 && ((int)(event
->timestamp
- button_down_time
)
3062 < XINT (Vdouble_click_time
)))));
3063 last_mouse_button
= button
;
3064 last_mouse_x
= XINT (event
->x
);
3065 last_mouse_y
= XINT (event
->y
);
3067 /* If this is a button press, squirrel away the location, so
3068 we can decide later whether it was a click or a drag. */
3069 if (event
->modifiers
& down_modifier
)
3073 double_click_count
++;
3074 event
->modifiers
|= ((double_click_count
> 2)
3079 double_click_count
= 1;
3080 button_down_time
= event
->timestamp
;
3081 *start_pos_ptr
= Fcopy_alist (position
);
3084 /* Now we're releasing a button - check the co-ordinates to
3085 see if this was a click or a drag. */
3086 else if (event
->modifiers
& up_modifier
)
3088 /* If we did not see a down before this up,
3089 ignore the up. Probably this happened because
3090 the down event chose a menu item.
3091 It would be an annoyance to treat the release
3092 of the button that chose the menu item
3093 as a separate event. */
3095 if (!CONSP (start_pos
))
3098 event
->modifiers
&= ~up_modifier
;
3099 #if 0 /* Formerly we treated an up with no down as a click event. */
3100 if (!CONSP (start_pos
))
3101 event
->modifiers
|= click_modifier
;
3105 /* The third element of every position should be the (x,y)
3109 down
= Fnth (make_number (2), start_pos
);
3110 if (EQ (event
->x
, XCONS (down
)->car
)
3111 && EQ (event
->y
, XCONS (down
)->cdr
))
3113 event
->modifiers
|= click_modifier
;
3117 button_down_time
= 0;
3118 event
->modifiers
|= drag_modifier
;
3120 /* Don't check is_double; treat this as multiple
3121 if the down-event was multiple. */
3122 if (double_click_count
> 1)
3123 event
->modifiers
|= ((double_click_count
> 2)
3129 /* Every mouse event should either have the down_modifier or
3130 the up_modifier set. */
3134 /* Get the symbol we should use for the mouse click. */
3137 head
= modify_event_symbol (button
,
3140 lispy_mouse_names
, &mouse_syms
,
3141 (sizeof (lispy_mouse_names
)
3142 / sizeof (lispy_mouse_names
[0])));
3143 if (event
->modifiers
& drag_modifier
)
3148 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
3151 Fcons (make_number (double_click_count
),
3159 #endif /* HAVE_MOUSE */
3161 /* The 'kind' field of the event is something we don't recognize. */
3170 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
3172 Lisp_Object bar_window
;
3173 enum scroll_bar_part part
;
3178 /* Is it a scroll bar movement? */
3179 if (frame
&& ! NILP (bar_window
))
3181 Lisp_Object part_sym
;
3183 part_sym
= *scroll_bar_parts
[(int) part
];
3184 return Fcons (Qscroll_bar_movement
,
3185 (Fcons (Fcons (bar_window
,
3186 Fcons (Qvertical_scroll_bar
,
3187 Fcons (Fcons (x
, y
),
3188 Fcons (make_number (time
),
3194 /* Or is it an ordinary mouse movement? */
3196 #endif /* MULTI_FRAME */
3209 /* It's in a frame; which window on that frame? */
3210 pixel_to_glyph_coords (frame
, XINT (x
), XINT (y
), &column
, &row
, 0, 1);
3211 window
= window_from_coordinates (frame
, column
, row
, &area
);
3216 if (WINDOWP (window
))
3218 int pixcolumn
, pixrow
;
3219 column
-= XINT (XWINDOW (window
)->left
);
3220 row
-= XINT (XWINDOW (window
)->top
);
3221 glyph_to_pixel_coords (frame
, column
, row
, &pixcolumn
, &pixrow
);
3222 XSETINT (x
, pixcolumn
);
3223 XSETINT (y
, pixrow
);
3228 posn
= Qvertical_line
;
3231 buffer_posn_from_coords (XWINDOW (window
), column
, row
));
3234 else if (frame
!= 0)
3236 XSETFRAME (window
, frame
);
3248 return Fcons (Qmouse_movement
,
3249 Fcons (Fcons (window
,
3251 Fcons (Fcons (x
, y
),
3252 Fcons (make_number (time
),
3258 #endif /* HAVE_MOUSE */
3260 /* Construct a switch frame event. */
3262 make_lispy_switch_frame (frame
)
3265 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
3268 /* Manipulating modifiers. */
3270 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
3272 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
3273 SYMBOL's name of the end of the modifiers; the string from this
3274 position is the unmodified symbol name.
3276 This doesn't use any caches. */
3279 parse_modifiers_uncached (symbol
, modifier_end
)
3283 struct Lisp_String
*name
;
3287 CHECK_SYMBOL (symbol
, 1);
3290 name
= XSYMBOL (symbol
)->name
;
3292 for (i
= 0; i
+2 <= name
->size
; )
3294 int this_mod_end
= 0;
3297 /* See if the name continues with a modifier word.
3298 Check that the word appears, but don't check what follows it.
3299 Set this_mod and this_mod_end to record what we find. */
3301 switch (name
->data
[i
])
3303 #define SINGLE_LETTER_MOD(BIT) \
3304 (this_mod_end = i + 1, this_mod = BIT)
3307 SINGLE_LETTER_MOD (alt_modifier
);
3311 SINGLE_LETTER_MOD (ctrl_modifier
);
3315 SINGLE_LETTER_MOD (hyper_modifier
);
3319 SINGLE_LETTER_MOD (meta_modifier
);
3323 SINGLE_LETTER_MOD (shift_modifier
);
3327 SINGLE_LETTER_MOD (super_modifier
);
3330 #undef SINGLE_LETTER_MOD
3333 /* If we found no modifier, stop looking for them. */
3334 if (this_mod_end
== 0)
3337 /* Check there is a dash after the modifier, so that it
3338 really is a modifier. */
3339 if (this_mod_end
>= name
->size
|| name
->data
[this_mod_end
] != '-')
3342 /* This modifier is real; look for another. */
3343 modifiers
|= this_mod
;
3344 i
= this_mod_end
+ 1;
3347 /* Should we include the `click' modifier? */
3348 if (! (modifiers
& (down_modifier
| drag_modifier
3349 | double_modifier
| triple_modifier
))
3350 && i
+ 7 == name
->size
3351 && strncmp (name
->data
+ i
, "mouse-", 6) == 0
3352 && ('0' <= name
->data
[i
+ 6] && name
->data
[i
+ 6] <= '9'))
3353 modifiers
|= click_modifier
;
3361 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
3362 prepended to the string BASE[0..BASE_LEN-1].
3363 This doesn't use any caches. */
3365 apply_modifiers_uncached (modifiers
, base
, base_len
)
3370 /* Since BASE could contain nulls, we can't use intern here; we have
3371 to use Fintern, which expects a genuine Lisp_String, and keeps a
3374 (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
3380 /* Only the event queue may use the `up' modifier; it should always
3381 be turned into a click or drag event before presented to lisp code. */
3382 if (modifiers
& up_modifier
)
3385 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
3386 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
3387 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
3388 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
3389 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
3390 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
3391 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
3392 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
3393 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
3394 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
3395 /* The click modifier is denoted by the absence of other modifiers. */
3399 mod_len
= p
- new_mods
;
3403 Lisp_Object new_name
;
3405 new_name
= make_uninit_string (mod_len
+ base_len
);
3406 bcopy (new_mods
, XSTRING (new_name
)->data
, mod_len
);
3407 bcopy (base
, XSTRING (new_name
)->data
+ mod_len
, base_len
);
3409 return Fintern (new_name
, Qnil
);
3414 static char *modifier_names
[] =
3416 "up", "down", "drag", "click", "double", "triple", 0, 0,
3417 0, 0, 0, 0, 0, 0, 0, 0,
3418 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
3420 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
3422 static Lisp_Object modifier_symbols
;
3424 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
3426 lispy_modifier_list (modifiers
)
3429 Lisp_Object modifier_list
;
3432 modifier_list
= Qnil
;
3433 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
3434 if (modifiers
& (1<<i
))
3435 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
3438 return modifier_list
;
3442 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
3443 where UNMODIFIED is the unmodified form of SYMBOL,
3444 MASK is the set of modifiers present in SYMBOL's name.
3445 This is similar to parse_modifiers_uncached, but uses the cache in
3446 SYMBOL's Qevent_symbol_element_mask property, and maintains the
3447 Qevent_symbol_elements property. */
3450 parse_modifiers (symbol
)
3453 Lisp_Object elements
;
3455 elements
= Fget (symbol
, Qevent_symbol_element_mask
);
3456 if (CONSP (elements
))
3461 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
3462 Lisp_Object unmodified
;
3465 unmodified
= Fintern (make_string (XSYMBOL (symbol
)->name
->data
+ end
,
3466 XSYMBOL (symbol
)->name
->size
- end
),
3469 if (modifiers
& ~((1<<VALBITS
) - 1))
3471 XSETFASTINT (mask
, modifiers
);
3472 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
3474 /* Cache the parsing results on SYMBOL. */
3475 Fput (symbol
, Qevent_symbol_element_mask
,
3477 Fput (symbol
, Qevent_symbol_elements
,
3478 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
3480 /* Since we know that SYMBOL is modifiers applied to unmodified,
3481 it would be nice to put that in unmodified's cache.
3482 But we can't, since we're not sure that parse_modifiers is
3489 /* Apply the modifiers MODIFIERS to the symbol BASE.
3490 BASE must be unmodified.
3492 This is like apply_modifiers_uncached, but uses BASE's
3493 Qmodifier_cache property, if present. It also builds
3494 Qevent_symbol_elements properties, since it has that info anyway.
3496 apply_modifiers copies the value of BASE's Qevent_kind property to
3497 the modified symbol. */
3499 apply_modifiers (modifiers
, base
)
3503 Lisp_Object cache
, index
, entry
, new_symbol
;
3505 /* Mask out upper bits. We don't know where this value's been. */
3506 modifiers
&= (1<<VALBITS
) - 1;
3508 /* The click modifier never figures into cache indices. */
3509 cache
= Fget (base
, Qmodifier_cache
);
3510 XSETFASTINT (index
, (modifiers
& ~click_modifier
));
3511 entry
= assq_no_quit (index
, cache
);
3514 new_symbol
= XCONS (entry
)->cdr
;
3517 /* We have to create the symbol ourselves. */
3518 new_symbol
= apply_modifiers_uncached (modifiers
,
3519 XSYMBOL (base
)->name
->data
,
3520 XSYMBOL (base
)->name
->size
);
3522 /* Add the new symbol to the base's cache. */
3523 entry
= Fcons (index
, new_symbol
);
3524 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
3526 /* We have the parsing info now for free, so add it to the caches. */
3527 XSETFASTINT (index
, modifiers
);
3528 Fput (new_symbol
, Qevent_symbol_element_mask
,
3529 Fcons (base
, Fcons (index
, Qnil
)));
3530 Fput (new_symbol
, Qevent_symbol_elements
,
3531 Fcons (base
, lispy_modifier_list (modifiers
)));
3534 /* Make sure this symbol is of the same kind as BASE.
3536 You'd think we could just set this once and for all when we
3537 intern the symbol above, but reorder_modifiers may call us when
3538 BASE's property isn't set right; we can't assume that just
3539 because it has a Qmodifier_cache property it must have its
3540 Qevent_kind set right as well. */
3541 if (NILP (Fget (new_symbol
, Qevent_kind
)))
3545 kind
= Fget (base
, Qevent_kind
);
3547 Fput (new_symbol
, Qevent_kind
, kind
);
3554 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
3555 return a symbol with the modifiers placed in the canonical order.
3556 Canonical order is alphabetical, except for down and drag, which
3557 always come last. The 'click' modifier is never written out.
3559 Fdefine_key calls this to make sure that (for example) C-M-foo
3560 and M-C-foo end up being equivalent in the keymap. */
3563 reorder_modifiers (symbol
)
3566 /* It's hopefully okay to write the code this way, since everything
3567 will soon be in caches, and no consing will be done at all. */
3570 parsed
= parse_modifiers (symbol
);
3571 return apply_modifiers (XCONS (XCONS (parsed
)->cdr
)->car
,
3572 XCONS (parsed
)->car
);
3576 /* For handling events, we often want to produce a symbol whose name
3577 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
3578 to some base, like the name of a function key or mouse button.
3579 modify_event_symbol produces symbols of this sort.
3581 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
3582 is the name of the i'th symbol. TABLE_SIZE is the number of elements
3585 Alternatively, NAME_ALIST is an alist mapping codes into symbol names.
3586 NAME_ALIST is used if it is non-nil; otherwise NAME_TABLE is used.
3588 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
3589 persist between calls to modify_event_symbol that it can use to
3590 store a cache of the symbols it's generated for this NAME_TABLE
3591 before. The object stored there may be a vector or an alist.
3593 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
3595 MODIFIERS is a set of modifier bits (as given in struct input_events)
3596 whose prefixes should be applied to the symbol name.
3598 SYMBOL_KIND is the value to be placed in the event_kind property of
3599 the returned symbol.
3601 The symbols we create are supposed to have an
3602 `event-symbol-elements' property, which lists the modifiers present
3603 in the symbol's name. */
3606 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_alist
,
3607 name_table
, symbol_table
, table_size
)
3610 Lisp_Object symbol_kind
;
3611 Lisp_Object name_alist
;
3613 Lisp_Object
*symbol_table
;
3617 Lisp_Object symbol_int
;
3619 XSETINT (symbol_int
, symbol_num
);
3621 /* Is this a request for a valid symbol? */
3622 if (symbol_num
< 0 || symbol_num
>= table_size
)
3625 if (CONSP (*symbol_table
))
3626 value
= Fcdr (assq_no_quit (symbol_int
, *symbol_table
));
3628 /* If *symbol_table doesn't seem to be initialized properly, fix that.
3629 *symbol_table should be a lisp vector TABLE_SIZE elements long,
3630 where the Nth element is the symbol for NAME_TABLE[N], or nil if
3631 we've never used that symbol before. */
3634 if (! VECTORP (*symbol_table
)
3635 || XVECTOR (*symbol_table
)->size
!= table_size
)
3639 XSETFASTINT (size
, table_size
);
3640 *symbol_table
= Fmake_vector (size
, Qnil
);
3643 value
= XVECTOR (*symbol_table
)->contents
[symbol_num
];
3646 /* Have we already used this symbol before? */
3649 /* No; let's create it. */
3650 if (!NILP (name_alist
))
3651 value
= Fcdr_safe (Fassq (symbol_int
, name_alist
));
3652 else if (name_table
[symbol_num
])
3653 value
= intern (name_table
[symbol_num
]);
3658 sprintf (buf
, "key-%d", symbol_num
);
3659 value
= intern (buf
);
3662 if (CONSP (*symbol_table
))
3663 *symbol_table
= Fcons (value
, *symbol_table
);
3665 XVECTOR (*symbol_table
)->contents
[symbol_num
] = value
;
3667 /* Fill in the cache entries for this symbol; this also
3668 builds the Qevent_symbol_elements property, which the user
3670 apply_modifiers (modifiers
& click_modifier
, value
);
3671 Fput (value
, Qevent_kind
, symbol_kind
);
3674 /* Apply modifiers to that symbol. */
3675 return apply_modifiers (modifiers
, value
);
3678 /* Convert a list that represents an event type,
3679 such as (ctrl meta backspace), into the usual representation of that
3680 event type as a number or a symbol. */
3683 convert_event_type_list (event
)
3692 while (CONSP (rest
))
3697 elt
= XCONS (rest
)->car
;
3699 /* Given a symbol, see if it is a modifier name. */
3701 this = parse_solitary_modifier (elt
);
3705 else if (!NILP (base
))
3706 error ("Two bases given in one event");
3710 rest
= XCONS (rest
)->cdr
;
3713 /* Let the symbol A refer to the character A. */
3714 if (SYMBOLP (base
) && XSYMBOL (base
)->name
->size
== 1)
3715 XSETINT (base
, XSYMBOL (base
)->name
->data
[0]);
3717 if (INTEGERP (base
))
3719 /* Turn (shift a) into A. */
3720 if ((modifiers
& shift_modifier
) != 0
3721 && (XINT (base
) >= 'a' && XINT (base
) <= 'z'))
3723 XSETINT (base
, XINT (base
) - ('a' - 'A'));
3724 modifiers
&= ~shift_modifier
;
3727 /* Turn (control a) into C-a. */
3728 if (modifiers
& ctrl_modifier
)
3729 return make_number ((modifiers
& ~ctrl_modifier
)
3730 | make_ctrl_char (XINT (base
)));
3732 return make_number (modifiers
| XINT (base
));
3734 else if (SYMBOLP (base
))
3735 return apply_modifiers (modifiers
, base
);
3737 error ("Invalid base event");
3740 /* Try to recognize SYMBOL as a modifier name.
3741 Return the modifier flag bit, or 0 if not recognized. */
3744 parse_solitary_modifier (symbol
)
3747 struct Lisp_String
*name
= XSYMBOL (symbol
)->name
;
3749 switch (name
->data
[0])
3751 #define SINGLE_LETTER_MOD(BIT) \
3752 if (name->size == 1) \
3755 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
3756 if (LEN == name->size \
3757 && ! strncmp (name->data, NAME, LEN)) \
3761 SINGLE_LETTER_MOD (alt_modifier
);
3765 MULTI_LETTER_MOD (alt_modifier
, "alt", 3);
3769 SINGLE_LETTER_MOD (ctrl_modifier
);
3773 MULTI_LETTER_MOD (ctrl_modifier
, "ctrl", 4);
3774 MULTI_LETTER_MOD (ctrl_modifier
, "control", 7);
3778 SINGLE_LETTER_MOD (hyper_modifier
);
3782 MULTI_LETTER_MOD (hyper_modifier
, "hyper", 5);
3786 SINGLE_LETTER_MOD (meta_modifier
);
3790 MULTI_LETTER_MOD (meta_modifier
, "meta", 4);
3794 SINGLE_LETTER_MOD (shift_modifier
);
3798 MULTI_LETTER_MOD (shift_modifier
, "shift", 5);
3799 MULTI_LETTER_MOD (super_modifier
, "super", 5);
3800 SINGLE_LETTER_MOD (super_modifier
);
3804 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
3805 MULTI_LETTER_MOD (down_modifier
, "down", 4);
3806 MULTI_LETTER_MOD (double_modifier
, "double", 6);
3810 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
3813 #undef SINGLE_LETTER_MOD
3814 #undef MULTI_LETTER_MOD
3820 /* Return 1 if EVENT is a list whose elements are all integers or symbols.
3821 Such a list is not valid as an event,
3822 but it can be a Lucid-style event type list. */
3825 lucid_event_type_list_p (object
)
3830 if (! CONSP (object
))
3833 for (tail
= object
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
3836 elt
= XCONS (tail
)->car
;
3837 if (! (INTEGERP (elt
) || SYMBOLP (elt
)))
3844 /* Store into *addr a value nonzero if terminal input chars are available.
3845 Serves the purpose of ioctl (0, FIONREAD, addr)
3846 but works even if FIONREAD does not exist.
3847 (In fact, this may actually read some input.) */
3850 get_input_pending (addr
)
3853 /* First of all, have we already counted some input? */
3854 *addr
= !NILP (Vquit_flag
) || readable_events ();
3856 /* If input is being read as it arrives, and we have none, there is none. */
3857 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
3860 /* Try to read some input and see how much we get. */
3862 *addr
= !NILP (Vquit_flag
) || readable_events ();
3865 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
3868 gobble_input (expected
)
3873 if (interrupt_input
)
3876 mask
= sigblockx (SIGIO
);
3877 read_avail_input (expected
);
3881 #ifdef POLL_FOR_INPUT
3882 if (read_socket_hook
&& !interrupt_input
&& poll_suppress_count
== 0)
3885 mask
= sigblockx (SIGALRM
);
3886 read_avail_input (expected
);
3892 read_avail_input (expected
);
3896 /* Put a buffer_switch_event in the buffer
3897 so that read_key_sequence will notice the new current buffer. */
3899 record_asynch_buffer_change ()
3901 struct input_event event
;
3904 event
.kind
= buffer_switch_event
;
3905 event
.frame_or_window
= Qnil
;
3908 /* We don't need a buffer-switch event unless Emacs is waiting for input.
3909 The purpose of the event is to make read_key_sequence look up the
3910 keymaps again. If we aren't in read_key_sequence, we don't need one,
3911 and the event could cause trouble by messing up (input-pending-p). */
3912 tem
= Fwaiting_for_user_input_p ();
3916 /* We never need these events if we have no asynchronous subprocesses. */
3920 /* Make sure no interrupt happens while storing the event. */
3922 if (interrupt_input
)
3925 mask
= sigblockx (SIGIO
);
3926 kbd_buffer_store_event (&event
);
3933 kbd_buffer_store_event (&event
);
3940 /* Read any terminal input already buffered up by the system
3941 into the kbd_buffer, but do not wait.
3943 EXPECTED should be nonzero if the caller knows there is some input.
3945 Except on VMS, all input is read by this function.
3946 If interrupt_input is nonzero, this function MUST be called
3947 only when SIGIO is blocked.
3949 Returns the number of keyboard chars read, or -1 meaning
3950 this is a bad time to try to read input. */
3953 read_avail_input (expected
)
3956 struct input_event buf
[KBD_BUFFER_SIZE
];
3960 if (read_socket_hook
)
3961 /* No need for FIONREAD or fcntl; just say don't wait. */
3962 nread
= (*read_socket_hook
) (input_fd
, buf
, KBD_BUFFER_SIZE
,
3963 expected
, expected
);
3966 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
3967 the kbd_buffer can really hold. That may prevent loss
3968 of characters on some systems when input is stuffed at us. */
3969 unsigned char cbuf
[KBD_BUFFER_SIZE
- 1];
3972 /* Determine how many characters we should *try* to read. */
3975 #else /* not WINDOWSNT */
3977 n_to_read
= dos_keysns ();
3980 #else /* not MSDOS */
3982 /* Find out how much input is available. */
3983 if (ioctl (input_fd
, FIONREAD
, &n_to_read
) < 0)
3984 /* Formerly simply reported no input, but that sometimes led to
3985 a failure of Emacs to terminate.
3986 SIGHUP seems appropriate if we can't reach the terminal. */
3987 /* ??? Is it really right to send the signal just to this process
3988 rather than to the whole process group?
3989 Perhaps on systems with FIONREAD Emacs is alone in its group. */
3990 kill (getpid (), SIGHUP
);
3993 if (n_to_read
> sizeof cbuf
)
3994 n_to_read
= sizeof cbuf
;
3995 #else /* no FIONREAD */
3996 #if defined(USG) || defined(DGUX)
3997 /* Read some input if available, but don't wait. */
3998 n_to_read
= sizeof cbuf
;
3999 fcntl (input_fd
, F_SETFL
, O_NDELAY
);
4004 #endif /* not MSDOS */
4005 #endif /* not WINDOWSNT */
4007 /* Now read; for one reason or another, this will not block.
4008 NREAD is set to the number of chars read. */
4012 cbuf
[0] = dos_keyread();
4015 nread
= read (input_fd
, cbuf
, n_to_read
);
4017 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
4018 /* The kernel sometimes fails to deliver SIGHUP for ptys.
4019 This looks incorrect, but it isn't, because _BSD causes
4020 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
4021 and that causes a value other than 0 when there is no input. */
4027 /* We used to retry the read if it was interrupted.
4028 But this does the wrong thing when O_NDELAY causes
4029 an EAGAIN error. Does anybody know of a situation
4030 where a retry is actually needed? */
4032 nread
< 0 && (errno
== EAGAIN
4046 #if defined (USG) || defined (DGUX)
4047 fcntl (input_fd
, F_SETFL
, 0);
4048 #endif /* USG or DGUX */
4049 #endif /* no FIONREAD */
4050 for (i
= 0; i
< nread
; i
++)
4052 buf
[i
].kind
= ascii_keystroke
;
4053 buf
[i
].modifiers
= 0;
4054 if (meta_key
== 1 && (cbuf
[i
] & 0x80))
4055 buf
[i
].modifiers
= meta_modifier
;
4059 buf
[i
].code
= cbuf
[i
];
4061 XSETFRAME (buf
[i
].frame_or_window
, selected_frame
);
4063 buf
[i
].frame_or_window
= Qnil
;
4068 /* Scan the chars for C-g and store them in kbd_buffer. */
4069 for (i
= 0; i
< nread
; i
++)
4071 kbd_buffer_store_event (&buf
[i
]);
4072 /* Don't look at input that follows a C-g too closely.
4073 This reduces lossage due to autorepeat on C-g. */
4074 if (buf
[i
].kind
== ascii_keystroke
4075 && buf
[i
].code
== quit_char
)
4081 #endif /* not VMS */
4083 #ifdef SIGIO /* for entire page */
4084 /* Note SIGIO has been undef'd if FIONREAD is missing. */
4087 input_available_signal (signo
)
4090 /* Must preserve main program's value of errno. */
4091 int old_errno
= errno
;
4093 extern int select_alarmed
;
4097 /* USG systems forget handlers when they are used;
4098 must reestablish each time */
4099 signal (signo
, input_available_signal
);
4106 if (input_available_clear_time
)
4107 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
4112 nread
= read_avail_input (1);
4113 /* -1 means it's not ok to read the input now.
4114 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
4115 0 means there was no keyboard input available. */
4120 select_alarmed
= 1; /* Force the select emulator back to life */
4131 /* Send ourselves a SIGIO.
4133 This function exists so that the UNBLOCK_INPUT macro in
4134 blockinput.h can have some way to take care of input we put off
4135 dealing with, without assuming that every file which uses
4136 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
4138 reinvoke_input_signal ()
4147 /* Return the prompt-string of a sparse keymap.
4148 This is the first element which is a string.
4149 Return nil if there is none. */
4157 register Lisp_Object tem
;
4166 static void menu_bar_item ();
4167 static void menu_bar_one_keymap ();
4169 /* These variables hold the vector under construction within
4170 menu_bar_items and its subroutines, and the current index
4171 for storing into that vector. */
4172 static Lisp_Object menu_bar_items_vector
;
4173 static int menu_bar_items_index
;
4175 /* Return a vector of menu items for a menu bar, appropriate
4176 to the current buffer. Each item has three elements in the vector:
4179 OLD is an old vector we can optionally reuse, or nil. */
4182 menu_bar_items (old
)
4185 /* The number of keymaps we're scanning right now, and the number of
4186 keymaps we have allocated space for. */
4189 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
4190 in the current keymaps, or nil where it is not a prefix. */
4193 Lisp_Object def
, tem
, tail
;
4202 struct gcpro gcpro1
;
4204 /* In order to build the menus, we need to call the keymap
4205 accessors. They all call QUIT. But this function is called
4206 during redisplay, during which a quit is fatal. So inhibit
4207 quitting while building the menus.
4208 We do this instead of specbind because (1) errors will clear it anyway
4209 and (2) this avoids risk of specpdl overflow. */
4210 oquit
= Vinhibit_quit
;
4214 menu_bar_items_vector
= old
;
4216 menu_bar_items_vector
= Fmake_vector (make_number (24), Qnil
);
4217 menu_bar_items_index
= 0;
4219 GCPRO1 (menu_bar_items_vector
);
4221 /* Build our list of keymaps.
4222 If we recognize a function key and replace its escape sequence in
4223 keybuf with its symbol, or if the sequence starts with a mouse
4224 click and we need to switch buffers, we jump back here to rebuild
4225 the initial keymaps from the current buffer. */
4229 /* Should overriding-local-map apply, here? */
4230 if (!NILP (Voverriding_local_map_menu_flag
))
4232 if (NILP (Voverriding_local_map
))
4234 /* Yes, and it is nil. Use just global map. */
4236 maps
= (Lisp_Object
*) alloca (nmaps
* sizeof (maps
[0]));
4240 /* Yes, and it is non-nil. Use it and the global map. */
4242 maps
= (Lisp_Object
*) alloca (nmaps
* sizeof (maps
[0]));
4243 maps
[0] = Voverriding_local_map
;
4248 /* No, so use major and minor mode keymaps. */
4249 nmaps
= current_minor_maps (0, &tmaps
) + 2;
4250 maps
= (Lisp_Object
*) alloca (nmaps
* sizeof (maps
[0]));
4251 bcopy (tmaps
, maps
, (nmaps
- 2) * sizeof (maps
[0]));
4252 #ifdef USE_TEXT_PROPERTIES
4253 maps
[nmaps
-2] = get_local_map (PT
, current_buffer
);
4255 maps
[nmaps
-2] = current_buffer
->keymap
;
4258 maps
[nmaps
-1] = current_global_map
;
4261 /* Look up in each map the dummy prefix key `menu-bar'. */
4265 for (mapno
= nmaps
- 1; mapno
>= 0; mapno
--)
4267 if (! NILP (maps
[mapno
]))
4268 def
= get_keyelt (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0));
4272 tem
= Fkeymapp (def
);
4274 menu_bar_one_keymap (def
);
4277 /* Move to the end those items that should be at the end. */
4279 for (tail
= Vmenu_bar_final_items
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4282 int end
= menu_bar_items_index
;
4284 for (i
= 0; i
< end
; i
+= 3)
4285 if (EQ (XCONS (tail
)->car
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
4287 Lisp_Object tem0
, tem1
, tem2
;
4288 /* Move the item at index I to the end,
4289 shifting all the others forward. */
4290 tem0
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 0];
4291 tem1
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 1];
4292 tem2
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
4294 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3],
4295 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
4296 (end
- i
- 3) * sizeof (Lisp_Object
));
4297 XVECTOR (menu_bar_items_vector
)->contents
[end
- 3] = tem0
;
4298 XVECTOR (menu_bar_items_vector
)->contents
[end
- 2] = tem1
;
4299 XVECTOR (menu_bar_items_vector
)->contents
[end
- 1] = tem2
;
4304 /* Add nil, nil, nil at the end. */
4305 i
= menu_bar_items_index
;
4306 if (i
+ 3 > XVECTOR (menu_bar_items_vector
)->size
)
4309 int newsize
= 2 * i
;
4310 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
4311 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
4312 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
4313 menu_bar_items_vector
= tem
;
4315 /* Add this item. */
4316 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
4317 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
4318 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
4319 menu_bar_items_index
= i
;
4321 Vinhibit_quit
= oquit
;
4323 return menu_bar_items_vector
;
4326 /* Scan one map KEYMAP, accumulating any menu items it defines
4327 in menu_bar_items_vector. */
4330 menu_bar_one_keymap (keymap
)
4333 Lisp_Object tail
, item
, key
, binding
, item_string
, table
;
4335 /* Loop over all keymap entries that have menu strings. */
4336 for (tail
= keymap
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4338 item
= XCONS (tail
)->car
;
4341 key
= XCONS (item
)->car
;
4342 binding
= XCONS (item
)->cdr
;
4343 if (CONSP (binding
))
4345 item_string
= XCONS (binding
)->car
;
4346 if (STRINGP (item_string
))
4347 menu_bar_item (key
, item_string
, Fcdr (binding
));
4349 else if (EQ (binding
, Qundefined
))
4350 menu_bar_item (key
, Qnil
, binding
);
4352 else if (VECTORP (item
))
4354 /* Loop over the char values represented in the vector. */
4355 int len
= XVECTOR (item
)->size
;
4357 for (c
= 0; c
< len
; c
++)
4359 Lisp_Object character
;
4360 XSETFASTINT (character
, c
);
4361 binding
= XVECTOR (item
)->contents
[c
];
4362 if (CONSP (binding
))
4364 item_string
= XCONS (binding
)->car
;
4365 if (STRINGP (item_string
))
4366 menu_bar_item (key
, item_string
, Fcdr (binding
));
4368 else if (EQ (binding
, Qundefined
))
4369 menu_bar_item (key
, Qnil
, binding
);
4375 /* This is used as the handler when calling internal_condition_case_1. */
4378 menu_bar_item_1 (arg
)
4384 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
4385 If there's already an item for KEY, add this DEF to it. */
4388 menu_bar_item (key
, item_string
, def
)
4389 Lisp_Object key
, item_string
, def
;
4392 Lisp_Object enabled
;
4395 if (EQ (def
, Qundefined
))
4397 /* If a map has an explicit `undefined' as definition,
4398 discard any previously made menu bar item. */
4400 for (i
= 0; i
< menu_bar_items_index
; i
+= 3)
4401 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
4403 if (menu_bar_items_index
> i
+ 3)
4404 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3],
4405 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
4406 (menu_bar_items_index
- i
- 3) * sizeof (Lisp_Object
));
4407 menu_bar_items_index
-= 3;
4411 /* If there's no definition for this key yet,
4412 just ignore `undefined'. */
4416 /* See if this entry is enabled. */
4421 /* No property, or nil, means enable.
4422 Otherwise, enable if value is not nil. */
4423 tem
= Fget (def
, Qmenu_enable
);
4425 /* (condition-case nil (eval tem)
4427 enabled
= internal_condition_case_1 (Feval
, tem
, Qerror
,
4431 /* Ignore this item if it's not enabled. */
4435 /* Find any existing item for this KEY. */
4436 for (i
= 0; i
< menu_bar_items_index
; i
+= 3)
4437 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
4440 /* If we did not find this KEY, add it at the end. */
4441 if (i
== menu_bar_items_index
)
4443 /* If vector is too small, get a bigger one. */
4444 if (i
+ 3 > XVECTOR (menu_bar_items_vector
)->size
)
4447 int newsize
= 2 * i
;
4448 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
4449 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
4450 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
4451 menu_bar_items_vector
= tem
;
4453 /* Add this item. */
4454 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = key
;
4455 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = item_string
;
4456 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Fcons (def
, Qnil
);
4457 menu_bar_items_index
= i
;
4459 /* We did find an item for this KEY. Add DEF to its list of maps. */
4463 old
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
4464 XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2] = Fcons (def
, old
);
4468 /* Read a character using menus based on maps in the array MAPS.
4469 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
4470 Return t if we displayed a menu but the user rejected it.
4472 PREV_EVENT is the previous input event, or nil if we are reading
4473 the first event of a key sequence.
4475 If USED_MOUSE_MENU is non-zero, then we set *USED_MOUSE_MENU to 1
4476 if we used a mouse menu to read the input, or zero otherwise. If
4477 USED_MOUSE_MENU is zero, *USED_MOUSE_MENU is left alone.
4479 The prompting is done based on the prompt-string of the map
4480 and the strings associated with various map elements.
4482 This can be done with X menus or with menus put in the minibuf.
4483 These are done in different ways, depending on how the input will be read.
4484 Menus using X are done after auto-saving in read-char, getting the input
4485 event from Fx_popup_menu; menus using the minibuf use read_char recursively
4486 and do auto-saving in the inner call of read_char. */
4489 read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
4492 Lisp_Object prev_event
;
4493 int *used_mouse_menu
;
4496 register Lisp_Object name
;
4497 Lisp_Object rest
, vector
;
4499 if (used_mouse_menu
)
4500 *used_mouse_menu
= 0;
4502 /* Use local over global Menu maps */
4504 if (! menu_prompting
)
4507 /* Optionally disregard all but the global map. */
4508 if (inhibit_local_menu_bar_menus
)
4510 maps
+= (nmaps
- 1);
4514 /* Get the menu name from the first map that has one (a prompt string). */
4515 for (mapno
= 0; mapno
< nmaps
; mapno
++)
4517 name
= map_prompt (maps
[mapno
]);
4522 /* If we don't have any menus, just read a character normally. */
4526 #if (defined (HAVE_X_WINDOWS) && defined (HAVE_X_MENU)) || defined (MSDOS)
4527 /* If we got to this point via a mouse click,
4528 use a real menu for mouse selection. */
4529 if (EVENT_HAS_PARAMETERS (prev_event
))
4531 /* Display the menu and get the selection. */
4532 Lisp_Object
*realmaps
4533 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
4537 /* Use the maps that are not nil. */
4538 for (mapno
= 0; mapno
< nmaps
; mapno
++)
4539 if (!NILP (maps
[mapno
]))
4540 realmaps
[nmaps1
++] = maps
[mapno
];
4542 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
4545 /* If we got more than one event, put all but the first
4546 onto this list to be read later.
4547 Return just the first event now. */
4548 Vunread_command_events
4549 = nconc2 (XCONS (value
)->cdr
, Vunread_command_events
);
4550 value
= XCONS (value
)->car
;
4552 else if (NILP (value
))
4554 if (used_mouse_menu
)
4555 *used_mouse_menu
= 1;
4558 #endif /* (HAVE_X_WINDOWS && HAVE_X_MENU) || MSDOS */
4563 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
4569 register Lisp_Object name
;
4571 int width
= FRAME_WIDTH (selected_frame
) - 4;
4572 char *menu
= (char *) alloca (width
+ 4);
4575 Lisp_Object rest
, vector
;
4577 if (! menu_prompting
)
4580 /* Get the menu name from the first map that has one (a prompt string). */
4581 for (mapno
= 0; mapno
< nmaps
; mapno
++)
4583 name
= map_prompt (maps
[mapno
]);
4588 /* If we don't have any menus, just read a character normally. */
4592 /* Prompt string always starts with map's prompt, and a space. */
4593 strcpy (menu
, XSTRING (name
)->data
);
4594 nlength
= XSTRING (name
)->size
;
4595 menu
[nlength
++] = ':';
4596 menu
[nlength
++] = ' ';
4599 /* Start prompting at start of first map. */
4603 /* Present the documented bindings, a line at a time. */
4610 Lisp_Object orig_defn_macro
;
4612 /* Loop over elements of map. */
4617 /* If reached end of map, start at beginning of next map. */
4621 /* At end of last map, wrap around to first map if just starting,
4622 or end this line if already have something on it. */
4626 if (notfirst
|| nobindings
) break;
4631 /* Look at the next element of the map. */
4633 elt
= XVECTOR (vector
)->contents
[idx
];
4635 elt
= Fcar_safe (rest
);
4637 if (idx
< 0 && VECTORP (elt
))
4639 /* If we found a dense table in the keymap,
4640 advanced past it, but start scanning its contents. */
4641 rest
= Fcdr_safe (rest
);
4647 /* An ordinary element. */
4649 s
= Fcar_safe (Fcdr_safe (elt
)); /* alist */
4651 s
= Fcar_safe(elt
); /* vector */
4653 /* Ignore the element if it has no prompt string. */
4655 /* If we have room for the prompt string, add it to this line.
4656 If this is the first on the line, always add it. */
4657 else if (XSTRING (s
)->size
+ i
+ 2 < width
4662 /* Punctuate between strings. */
4665 strcpy (menu
+ i
, ", ");
4671 /* Add as much of string as fits. */
4672 thiswidth
= XSTRING (s
)->size
;
4673 if (thiswidth
+ i
> width
)
4674 thiswidth
= width
- i
;
4675 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
4681 /* If this element does not fit, end the line now,
4682 and save the element for the next line. */
4683 strcpy (menu
+ i
, "...");
4687 /* Move past this element. */
4688 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
4689 /* Handle reaching end of dense table. */
4694 rest
= Fcdr_safe (rest
);
4698 /* Prompt with that and read response. */
4701 /* Make believe its not a keyboard macro in case the help char
4702 is pressed. Help characters are not recorded because menu prompting
4703 is not used on replay.
4705 orig_defn_macro
= current_kboard
->defining_kbd_macro
;
4706 current_kboard
->defining_kbd_macro
= Qnil
;
4708 obj
= read_char (commandflag
, 0, 0, Qnil
, 0);
4709 while (BUFFERP (obj
));
4710 current_kboard
->defining_kbd_macro
= orig_defn_macro
;
4712 if (!INTEGERP (obj
))
4717 if (! EQ (obj
, menu_prompt_more_char
)
4718 && (!INTEGERP (menu_prompt_more_char
)
4719 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
4721 if (!NILP (current_kboard
->defining_kbd_macro
))
4722 store_kbd_macro_char (obj
);
4725 /* Help char - go round again */
4729 /* Reading key sequences. */
4731 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
4732 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
4733 keymap, or nil otherwise. Return the index of the first keymap in
4734 which KEY has any binding, or NMAPS if no map has a binding.
4736 If KEY is a meta ASCII character, treat it like meta-prefix-char
4737 followed by the corresponding non-meta character. Keymaps in
4738 CURRENT with non-prefix bindings for meta-prefix-char become nil in
4741 If KEY has no bindings in any of the CURRENT maps, NEXT is left
4744 NEXT may == CURRENT. */
4747 follow_key (key
, nmaps
, current
, defs
, next
)
4749 Lisp_Object
*current
, *defs
, *next
;
4752 int i
, first_binding
;
4754 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
4755 followed by the corresponding non-meta character. */
4756 if (INTEGERP (key
) && (XINT (key
) & CHAR_META
))
4758 for (i
= 0; i
< nmaps
; i
++)
4759 if (! NILP (current
[i
]))
4762 get_keyelt (access_keymap (current
[i
], meta_prefix_char
, 1, 0));
4764 /* Note that since we pass the resulting bindings through
4765 get_keymap_1, non-prefix bindings for meta-prefix-char
4767 next
[i
] = get_keymap_1 (next
[i
], 0, 1);
4773 XSETINT (key
, XFASTINT (key
) & ~CHAR_META
);
4776 first_binding
= nmaps
;
4777 for (i
= nmaps
- 1; i
>= 0; i
--)
4779 if (! NILP (current
[i
]))
4781 defs
[i
] = get_keyelt (access_keymap (current
[i
], key
, 1, 0));
4782 if (! NILP (defs
[i
]))
4789 /* Given the set of bindings we've found, produce the next set of maps. */
4790 if (first_binding
< nmaps
)
4791 for (i
= 0; i
< nmaps
; i
++)
4792 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0, 1);
4794 return first_binding
;
4797 /* Read a sequence of keys that ends with a non prefix character,
4798 storing it in KEYBUF, a buffer of size BUFSIZE.
4800 Return the length of the key sequence stored.
4801 Return -1 if the user rejected a command menu.
4803 Echo starting immediately unless `prompt' is 0.
4805 Where a key sequence ends depends on the currently active keymaps.
4806 These include any minor mode keymaps active in the current buffer,
4807 the current buffer's local map, and the global map.
4809 If a key sequence has no other bindings, we check Vfunction_key_map
4810 to see if some trailing subsequence might be the beginning of a
4811 function key's sequence. If so, we try to read the whole function
4812 key, and substitute its symbolic name into the key sequence.
4814 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
4815 `double-' events into similar click events, if that would make them
4816 bound. We try to turn `triple-' events first into `double-' events,
4819 If we get a mouse click in a mode line, vertical divider, or other
4820 non-text area, we treat the click as if it were prefixed by the
4821 symbol denoting that area - `mode-line', `vertical-line', or
4824 If the sequence starts with a mouse click, we read the key sequence
4825 with respect to the buffer clicked on, not the current buffer.
4827 If the user switches frames in the midst of a key sequence, we put
4828 off the switch-frame event until later; the next call to
4829 read_char will return it. */
4832 read_key_sequence (keybuf
, bufsize
, prompt
, dont_downcase_last
,
4833 can_return_switch_frame
)
4834 Lisp_Object
*keybuf
;
4837 int dont_downcase_last
;
4838 int can_return_switch_frame
;
4840 int count
= specpdl_ptr
- specpdl
;
4842 /* How many keys there are in the current key sequence. */
4845 /* The length of the echo buffer when we started reading, and
4846 the length of this_command_keys when we started reading. */
4850 /* The number of keymaps we're scanning right now, and the number of
4851 keymaps we have allocated space for. */
4853 int nmaps_allocated
= 0;
4855 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
4856 the current keymaps. */
4859 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
4860 in the current keymaps, or nil where it is not a prefix. */
4861 Lisp_Object
*submaps
;
4863 /* The local map to start out with at start of key sequence. */
4864 Lisp_Object orig_local_map
;
4866 /* 1 if we have already considered switching to the local-map property
4867 of the place where a mouse click occurred. */
4868 int localized_local_map
= 0;
4870 /* The index in defs[] of the first keymap that has a binding for
4871 this key sequence. In other words, the lowest i such that
4872 defs[i] is non-nil. */
4875 /* If t < mock_input, then KEYBUF[t] should be read as the next
4878 We use this to recover after recognizing a function key. Once we
4879 realize that a suffix of the current key sequence is actually a
4880 function key's escape sequence, we replace the suffix with the
4881 function key's binding from Vfunction_key_map. Now keybuf
4882 contains a new and different key sequence, so the echo area,
4883 this_command_keys, and the submaps and defs arrays are wrong. In
4884 this situation, we set mock_input to t, set t to 0, and jump to
4885 restart_sequence; the loop will read keys from keybuf up until
4886 mock_input, thus rebuilding the state; and then it will resume
4887 reading characters from the keyboard. */
4890 /* If the sequence is unbound in submaps[], then
4891 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
4892 and fkey_map is its binding.
4894 These might be > t, indicating that all function key scanning
4895 should hold off until t reaches them. We do this when we've just
4896 recognized a function key, to avoid searching for the function
4897 key's again in Vfunction_key_map. */
4898 int fkey_start
= 0, fkey_end
= 0;
4899 Lisp_Object fkey_map
;
4901 /* Likewise, for key_translation_map. */
4902 int keytran_start
= 0, keytran_end
= 0;
4903 Lisp_Object keytran_map
;
4905 /* If we receive a ``switch-frame'' event in the middle of a key sequence,
4906 we put it off for later. While we're reading, we keep the event here. */
4907 Lisp_Object delayed_switch_frame
;
4909 /* See the comment below... */
4910 #if defined (GOBBLE_FIRST_EVENT)
4911 Lisp_Object first_event
;
4914 Lisp_Object original_uppercase
;
4915 int original_uppercase_position
= -1;
4917 /* Gets around Microsoft compiler limitations. */
4920 struct buffer
*starting_buffer
;
4922 /* Nonzero if we seem to have got the beginning of a binding
4923 in function_key_map. */
4924 int function_key_possible
= 0;
4925 int key_translation_possible
= 0;
4929 last_nonmenu_event
= Qnil
;
4931 delayed_switch_frame
= Qnil
;
4932 fkey_map
= Vfunction_key_map
;
4933 keytran_map
= Vkey_translation_map
;
4935 /* If there is no function-key-map, turn off function key scanning. */
4936 if (NILP (Fkeymapp (Vfunction_key_map
)))
4937 fkey_start
= fkey_end
= bufsize
+ 1;
4939 /* If there is no key-translation-map, turn off scanning. */
4940 if (NILP (Fkeymapp (Vkey_translation_map
)))
4941 keytran_start
= keytran_end
= bufsize
+ 1;
4946 echo_prompt (XSTRING (prompt
)->data
);
4947 else if (cursor_in_echo_area
&& echo_keystrokes
)
4948 /* This doesn't put in a dash if the echo buffer is empty, so
4949 you don't always see a dash hanging out in the minibuffer. */
4953 /* Record the initial state of the echo area and this_command_keys;
4954 we will need to restore them if we replay a key sequence. */
4956 echo_start
= echo_length ();
4957 keys_start
= this_command_key_count
;
4959 #if defined (GOBBLE_FIRST_EVENT)
4960 /* This doesn't quite work, because some of the things that read_char
4961 does cannot safely be bypassed. It seems too risky to try to make
4964 /* Read the first char of the sequence specially, before setting
4965 up any keymaps, in case a filter runs and switches buffers on us. */
4966 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
4968 #endif /* GOBBLE_FIRST_EVENT */
4970 orig_local_map
= get_local_map (PT
, current_buffer
);
4972 /* We jump here when the key sequence has been thoroughly changed, and
4973 we need to rescan it starting from the beginning. When we jump here,
4974 keybuf[0..mock_input] holds the sequence we should reread. */
4977 starting_buffer
= current_buffer
;
4978 function_key_possible
= 0;
4979 key_translation_possible
= 0;
4981 /* Build our list of keymaps.
4982 If we recognize a function key and replace its escape sequence in
4983 keybuf with its symbol, or if the sequence starts with a mouse
4984 click and we need to switch buffers, we jump back here to rebuild
4985 the initial keymaps from the current buffer. */
4989 if (!NILP (Voverriding_local_map
))
4992 if (nmaps
> nmaps_allocated
)
4994 submaps
= (Lisp_Object
*) alloca (nmaps
* sizeof (submaps
[0]));
4995 defs
= (Lisp_Object
*) alloca (nmaps
* sizeof (defs
[0]));
4996 nmaps_allocated
= nmaps
;
4998 submaps
[0] = Voverriding_local_map
;
5002 nmaps
= current_minor_maps (0, &maps
) + 2;
5003 if (nmaps
> nmaps_allocated
)
5005 submaps
= (Lisp_Object
*) alloca (nmaps
* sizeof (submaps
[0]));
5006 defs
= (Lisp_Object
*) alloca (nmaps
* sizeof (defs
[0]));
5007 nmaps_allocated
= nmaps
;
5009 bcopy (maps
, submaps
, (nmaps
- 2) * sizeof (submaps
[0]));
5010 #ifdef USE_TEXT_PROPERTIES
5011 submaps
[nmaps
-2] = orig_local_map
;
5013 submaps
[nmaps
-2] = current_buffer
->keymap
;
5016 submaps
[nmaps
-1] = current_global_map
;
5019 /* Find an accurate initial value for first_binding. */
5020 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
5021 if (! NILP (submaps
[first_binding
]))
5024 /* Start from the beginning in keybuf. */
5027 /* These are no-ops the first time through, but if we restart, they
5028 revert the echo area and this_command_keys to their original state. */
5029 this_command_key_count
= keys_start
;
5030 if (INTERACTIVE
&& t
< mock_input
)
5031 echo_truncate (echo_start
);
5033 /* If the best binding for the current key sequence is a keymap, or
5034 we may be looking at a function key's escape sequence, keep on
5036 while ((first_binding
< nmaps
&& ! NILP (submaps
[first_binding
]))
5037 || (first_binding
>= nmaps
5039 /* mock input is never part of a function key's sequence. */
5040 && mock_input
<= fkey_start
)
5041 || (first_binding
>= nmaps
5042 && keytran_start
< t
&& key_translation_possible
)
5043 /* Don't return in the middle of a possible function key sequence,
5044 if the only bindings we found were via case conversion.
5045 Thus, if ESC O a has a function-key-map translation
5046 and ESC o has a binding, don't return after ESC O,
5047 so that we can translate ESC O plus the next character. */
5051 int used_mouse_menu
= 0;
5053 /* Where the last real key started. If we need to throw away a
5054 key that has expanded into more than one element of keybuf
5055 (say, a mouse click on the mode line which is being treated
5056 as [mode-line (mouse-...)], then we backtrack to this point
5058 int last_real_key_start
;
5060 /* These variables are analogous to echo_start and keys_start;
5061 while those allow us to restart the entire key sequence,
5062 echo_local_start and keys_local_start allow us to throw away
5064 int echo_local_start
, keys_local_start
, local_first_binding
;
5067 error ("key sequence too long");
5070 echo_local_start
= echo_length ();
5071 keys_local_start
= this_command_key_count
;
5072 local_first_binding
= first_binding
;
5075 /* These are no-ops, unless we throw away a keystroke below and
5076 jumped back up to replay_key; in that case, these restore the
5077 variables to their original state, allowing us to replay the
5079 if (INTERACTIVE
&& t
< mock_input
)
5080 echo_truncate (echo_local_start
);
5081 this_command_key_count
= keys_local_start
;
5082 first_binding
= local_first_binding
;
5084 /* By default, assume each event is "real". */
5085 last_real_key_start
= t
;
5087 /* Does mock_input indicate that we are re-reading a key sequence? */
5091 add_command_key (key
);
5092 if (echo_keystrokes
)
5096 /* If not, we should actually read a character. */
5099 struct buffer
*buf
= current_buffer
;
5103 KBOARD
*interrupted_kboard
= current_kboard
;
5104 struct frame
*interrupted_frame
= selected_frame
;
5105 if (setjmp (wrong_kboard_jmpbuf
))
5107 if (!NILP (delayed_switch_frame
))
5109 interrupted_kboard
->kbd_queue
5110 = Fcons (delayed_switch_frame
,
5111 interrupted_kboard
->kbd_queue
);
5112 delayed_switch_frame
= Qnil
;
5115 interrupted_kboard
->kbd_queue
5116 = Fcons (keybuf
[--t
], interrupted_kboard
->kbd_queue
);
5118 /* If the side queue is non-empty, ensure it begins with a
5119 switch-frame, so we'll replay it in the right context. */
5120 if (CONSP (interrupted_kboard
->kbd_queue
)
5121 && (key
= XCONS (interrupted_kboard
->kbd_queue
)->car
,
5122 !(EVENT_HAS_PARAMETERS (key
)
5123 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)),
5127 XSETFRAME (frame
, interrupted_frame
);
5128 interrupted_kboard
->kbd_queue
5129 = Fcons (make_lispy_switch_frame (frame
),
5130 interrupted_kboard
->kbd_queue
);
5133 orig_local_map
= get_local_map (PT
, current_buffer
);
5134 goto replay_sequence
;
5137 key
= read_char (NILP (prompt
), nmaps
, submaps
, last_nonmenu_event
,
5141 /* read_char returns t when it shows a menu and the user rejects it.
5146 /* read_char returns -1 at the end of a macro.
5147 Emacs 18 handles this by returning immediately with a
5148 zero, so that's what we'll do. */
5149 if (INTEGERP (key
) && XINT (key
) == -1)
5152 /* The Microsoft C compiler can't handle the goto that
5158 /* If the current buffer has been changed from under us, the
5159 keymap may have changed, so replay the sequence. */
5163 orig_local_map
= get_local_map (PT
, current_buffer
);
5164 goto replay_sequence
;
5167 /* If we have a quit that was typed in another frame, and
5168 quit_throw_to_read_char switched buffers,
5169 replay to get the right keymap. */
5170 if (XINT (key
) == quit_char
&& current_buffer
!= starting_buffer
)
5175 orig_local_map
= get_local_map (PT
, current_buffer
);
5176 goto replay_sequence
;
5182 /* Clicks in non-text areas get prefixed by the symbol
5183 in their CHAR-ADDRESS field. For example, a click on
5184 the mode line is prefixed by the symbol `mode-line'.
5186 Furthermore, key sequences beginning with mouse clicks
5187 are read using the keymaps of the buffer clicked on, not
5188 the current buffer. So we may have to switch the buffer
5191 When we turn one event into two events, we must make sure
5192 that neither of the two looks like the original--so that,
5193 if we replay the events, they won't be expanded again.
5194 If not for this, such reexpansion could happen either here
5195 or when user programs play with this-command-keys. */
5196 if (EVENT_HAS_PARAMETERS (key
))
5200 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
5201 if (EQ (kind
, Qmouse_click
))
5203 Lisp_Object window
, posn
;
5205 window
= POSN_WINDOW (EVENT_START (key
));
5206 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
5209 /* We're looking at the second event of a
5210 sequence which we expanded before. Set
5211 last_real_key_start appropriately. */
5213 last_real_key_start
= t
- 1;
5216 /* Key sequences beginning with mouse clicks are
5217 read using the keymaps in the buffer clicked on,
5218 not the current buffer. If we're at the
5219 beginning of a key sequence, switch buffers. */
5220 if (last_real_key_start
== 0
5222 && BUFFERP (XWINDOW (window
)->buffer
)
5223 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
5228 /* Arrange to go back to the original buffer once we're
5229 done reading the key sequence. Note that we can't
5230 use save_excursion_{save,restore} here, because they
5231 save point as well as the current buffer; we don't
5232 want to save point, because redisplay may change it,
5233 to accommodate a Fset_window_start or something. We
5234 don't want to do this at the top of the function,
5235 because we may get input from a subprocess which
5236 wants to change the selected window and stuff (say,
5238 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
5240 set_buffer_internal (XBUFFER (XWINDOW (window
)->buffer
));
5241 orig_local_map
= get_local_map (PT
, current_buffer
);
5242 goto replay_sequence
;
5244 /* For a mouse click, get the local text-property keymap
5245 of the place clicked on, rather than point. */
5246 if (last_real_key_start
== 0 && CONSP (XCONS (key
)->cdr
)
5247 && ! localized_local_map
)
5249 Lisp_Object map_here
, start
, pos
;
5251 localized_local_map
= 1;
5252 start
= EVENT_START (key
);
5253 if (CONSP (start
) && CONSP (XCONS (start
)->cdr
))
5255 pos
= POSN_BUFFER_POSN (start
);
5258 map_here
= get_local_map (XINT (pos
), current_buffer
);
5259 if (!EQ (map_here
, orig_local_map
))
5261 orig_local_map
= map_here
;
5265 goto replay_sequence
;
5271 /* Expand mode-line and scroll-bar events into two events:
5272 use posn as a fake prefix key. */
5275 if (t
+ 1 >= bufsize
)
5276 error ("key sequence too long");
5281 /* Zap the position in key, so we know that we've
5282 expanded it, and don't try to do so again. */
5283 POSN_BUFFER_POSN (EVENT_START (key
))
5284 = Fcons (posn
, Qnil
);
5288 else if (EQ (kind
, Qswitch_frame
))
5290 /* If we're at the beginning of a key sequence, and the caller
5291 says it's okay, go ahead and return this event. If we're
5292 in the midst of a key sequence, delay it until the end. */
5293 if (t
> 0 || !can_return_switch_frame
)
5295 delayed_switch_frame
= key
;
5299 else if (CONSP (XCONS (key
)->cdr
)
5300 && CONSP (EVENT_START (key
))
5301 && CONSP (XCONS (EVENT_START (key
))->cdr
))
5305 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
5306 /* Handle menu-bar events:
5307 insert the dummy prefix event `menu-bar'. */
5308 if (EQ (posn
, Qmenu_bar
))
5310 if (t
+ 1 >= bufsize
)
5311 error ("key sequence too long");
5312 /* Run the Lucid hook. */
5313 if (!NILP (Vrun_hooks
))
5314 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
5315 /* If it has changed current-menubar from previous value,
5316 really recompute the menubar from the value. */
5317 if (! NILP (Vlucid_menu_bar_dirty_flag
))
5318 call0 (Qrecompute_lucid_menubar
);
5322 /* Zap the position in key, so we know that we've
5323 expanded it, and don't try to do so again. */
5324 POSN_BUFFER_POSN (EVENT_START (key
))
5325 = Fcons (posn
, Qnil
);
5328 goto replay_sequence
;
5330 else if (CONSP (posn
))
5332 /* We're looking at the second event of a
5333 sequence which we expanded before. Set
5334 last_real_key_start appropriately. */
5335 if (last_real_key_start
== t
&& t
> 0)
5336 last_real_key_start
= t
- 1;
5341 /* We have finally decided that KEY is something we might want
5343 first_binding
= (follow_key (key
,
5344 nmaps
- first_binding
,
5345 submaps
+ first_binding
,
5346 defs
+ first_binding
,
5347 submaps
+ first_binding
)
5350 /* If KEY wasn't bound, we'll try some fallbacks. */
5351 if (first_binding
>= nmaps
)
5355 head
= EVENT_HEAD (key
);
5356 if (EQ (head
, Vhelp_char
))
5358 read_key_sequence_cmd
= Vprefix_help_command
;
5360 last_nonmenu_event
= key
;
5361 /* The Microsoft C compiler can't handle the goto that
5369 Lisp_Object breakdown
;
5372 breakdown
= parse_modifiers (head
);
5373 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
5374 /* Attempt to reduce an unbound mouse event to a simpler
5375 event that is bound:
5376 Drags reduce to clicks.
5377 Double-clicks reduce to clicks.
5378 Triple-clicks reduce to double-clicks, then to clicks.
5379 Down-clicks are eliminated.
5380 Double-downs reduce to downs, then are eliminated.
5381 Triple-downs reduce to double-downs, then to downs,
5382 then are eliminated. */
5383 if (modifiers
& (down_modifier
| drag_modifier
5384 | double_modifier
| triple_modifier
))
5386 while (modifiers
& (down_modifier
| drag_modifier
5387 | double_modifier
| triple_modifier
))
5389 Lisp_Object new_head
, new_click
;
5390 if (modifiers
& triple_modifier
)
5391 modifiers
^= (double_modifier
| triple_modifier
);
5392 else if (modifiers
& double_modifier
)
5393 modifiers
&= ~double_modifier
;
5394 else if (modifiers
& drag_modifier
)
5395 modifiers
&= ~drag_modifier
;
5398 /* Dispose of this `down' event by simply jumping
5399 back to replay_key, to get another event.
5401 Note that if this event came from mock input,
5402 then just jumping back to replay_key will just
5403 hand it to us again. So we have to wipe out any
5406 We could delete keybuf[t] and shift everything
5407 after that to the left by one spot, but we'd also
5408 have to fix up any variable that points into
5409 keybuf, and shifting isn't really necessary
5412 Adding prefixes for non-textual mouse clicks
5413 creates two characters of mock input, and both
5414 must be thrown away. If we're only looking at
5415 the prefix now, we can just jump back to
5416 replay_key. On the other hand, if we've already
5417 processed the prefix, and now the actual click
5418 itself is giving us trouble, then we've lost the
5419 state of the keymaps we want to backtrack to, and
5420 we need to replay the whole sequence to rebuild
5423 Beyond that, only function key expansion could
5424 create more than two keys, but that should never
5425 generate mouse events, so it's okay to zero
5426 mock_input in that case too.
5428 Isn't this just the most wonderful code ever? */
5429 if (t
== last_real_key_start
)
5436 mock_input
= last_real_key_start
;
5437 goto replay_sequence
;
5442 = apply_modifiers (modifiers
, XCONS (breakdown
)->car
);
5444 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
5446 /* Look for a binding for this new key. follow_key
5447 promises that it didn't munge submaps the
5448 last time we called it, since key was unbound. */
5450 = (follow_key (new_click
,
5451 nmaps
- local_first_binding
,
5452 submaps
+ local_first_binding
,
5453 defs
+ local_first_binding
,
5454 submaps
+ local_first_binding
)
5455 + local_first_binding
);
5457 /* If that click is bound, go for it. */
5458 if (first_binding
< nmaps
)
5463 /* Otherwise, we'll leave key set to the drag event. */
5470 /* Normally, last_nonmenu_event gets the previous key we read.
5471 But when a mouse popup menu is being used,
5472 we don't update last_nonmenu_event; it continues to hold the mouse
5473 event that preceded the first level of menu. */
5474 if (!used_mouse_menu
)
5475 last_nonmenu_event
= key
;
5477 /* If the sequence is unbound, see if we can hang a function key
5478 off the end of it. We only want to scan real keyboard input
5479 for function key sequences, so if mock_input says that we're
5480 re-reading old events, don't examine it. */
5481 if (first_binding
>= nmaps
5484 Lisp_Object fkey_next
;
5486 /* Continue scan from fkey_end until we find a bound suffix.
5487 If we fail, increment fkey_start
5488 and start fkey_end from there. */
5489 while (fkey_end
< t
)
5493 key
= keybuf
[fkey_end
++];
5494 /* Look up meta-characters by prefixing them
5495 with meta_prefix_char. I hate this. */
5496 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
5501 (access_keymap (fkey_map
, meta_prefix_char
, 1, 0)),
5503 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
5506 fkey_next
= fkey_map
;
5509 = get_keyelt (access_keymap (fkey_next
, key
, 1, 0));
5511 #if 0 /* I didn't turn this on, because it might cause trouble
5512 for the mapping of return into C-m and tab into C-i. */
5513 /* Optionally don't map function keys into other things.
5514 This enables the user to redefine kp- keys easily. */
5515 if (SYMBOLP (key
) && !NILP (Vinhibit_function_key_mapping
))
5519 /* If the function key map gives a function, not an
5520 array, then call the function with no args and use
5521 its value instead. */
5522 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
5525 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5529 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
5530 fkey_next
= call1 (fkey_next
, prompt
);
5532 /* If the function returned something invalid,
5533 barf--don't ignore it.
5534 (To ignore it safely, we would need to gcpro a bunch of
5535 other variables.) */
5536 if (! (VECTORP (fkey_next
) || STRINGP (fkey_next
)))
5537 error ("Function in function-key-map returns invalid key sequence");
5540 function_key_possible
= ! NILP (fkey_next
);
5542 /* If keybuf[fkey_start..fkey_end] is bound in the
5543 function key map and it's a suffix of the current
5544 sequence (i.e. fkey_end == t), replace it with
5545 the binding and restart with fkey_start at the end. */
5546 if ((VECTORP (fkey_next
) || STRINGP (fkey_next
))
5549 int len
= XFASTINT (Flength (fkey_next
));
5551 t
= fkey_start
+ len
;
5553 error ("key sequence too long");
5555 if (VECTORP (fkey_next
))
5556 bcopy (XVECTOR (fkey_next
)->contents
,
5557 keybuf
+ fkey_start
,
5558 (t
- fkey_start
) * sizeof (keybuf
[0]));
5559 else if (STRINGP (fkey_next
))
5563 for (i
= 0; i
< len
; i
++)
5564 XSETFASTINT (keybuf
[fkey_start
+ i
],
5565 XSTRING (fkey_next
)->data
[i
]);
5569 fkey_start
= fkey_end
= t
;
5570 fkey_map
= Vfunction_key_map
;
5572 /* Do pass the results through key-translation-map. */
5573 keytran_start
= keytran_end
= 0;
5574 keytran_map
= Vkey_translation_map
;
5576 goto replay_sequence
;
5579 fkey_map
= get_keymap_1 (fkey_next
, 0, 1);
5581 /* If we no longer have a bound suffix, try a new positions for
5583 if (NILP (fkey_map
))
5585 fkey_end
= ++fkey_start
;
5586 fkey_map
= Vfunction_key_map
;
5587 function_key_possible
= 0;
5592 /* Look for this sequence in key-translation-map. */
5594 Lisp_Object keytran_next
;
5596 /* Scan from keytran_end until we find a bound suffix. */
5597 while (keytran_end
< t
)
5601 key
= keybuf
[keytran_end
++];
5602 /* Look up meta-characters by prefixing them
5603 with meta_prefix_char. I hate this. */
5604 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
5609 (access_keymap (keytran_map
, meta_prefix_char
, 1, 0)),
5611 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
5614 keytran_next
= keytran_map
;
5617 = get_keyelt (access_keymap (keytran_next
, key
, 1, 0));
5619 /* If the key translation map gives a function, not an
5620 array, then call the function with no args and use
5621 its value instead. */
5622 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
5623 && keytran_end
== t
)
5625 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5629 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
5630 keytran_next
= call1 (keytran_next
, prompt
);
5632 /* If the function returned something invalid,
5633 barf--don't ignore it.
5634 (To ignore it safely, we would need to gcpro a bunch of
5635 other variables.) */
5636 if (! (VECTORP (keytran_next
) || STRINGP (keytran_next
)))
5637 error ("Function in key-translation-map returns invalid key sequence");
5640 key_translation_possible
= ! NILP (keytran_next
);
5642 /* If keybuf[keytran_start..keytran_end] is bound in the
5643 key translation map and it's a suffix of the current
5644 sequence (i.e. keytran_end == t), replace it with
5645 the binding and restart with keytran_start at the end. */
5646 if ((VECTORP (keytran_next
) || STRINGP (keytran_next
))
5647 && keytran_end
== t
)
5649 int len
= XFASTINT (Flength (keytran_next
));
5651 t
= keytran_start
+ len
;
5653 error ("key sequence too long");
5655 if (VECTORP (keytran_next
))
5656 bcopy (XVECTOR (keytran_next
)->contents
,
5657 keybuf
+ keytran_start
,
5658 (t
- keytran_start
) * sizeof (keybuf
[0]));
5659 else if (STRINGP (keytran_next
))
5663 for (i
= 0; i
< len
; i
++)
5664 XSETFASTINT (keybuf
[keytran_start
+ i
],
5665 XSTRING (keytran_next
)->data
[i
]);
5669 keytran_start
= keytran_end
= t
;
5670 keytran_map
= Vkey_translation_map
;
5672 /* Don't pass the results of key-translation-map
5673 through function-key-map. */
5674 fkey_start
= fkey_end
= t
;
5675 fkey_map
= Vkey_translation_map
;
5677 goto replay_sequence
;
5680 keytran_map
= get_keymap_1 (keytran_next
, 0, 1);
5682 /* If we no longer have a bound suffix, try a new positions for
5684 if (NILP (keytran_map
))
5686 keytran_end
= ++keytran_start
;
5687 keytran_map
= Vkey_translation_map
;
5688 key_translation_possible
= 0;
5693 /* If KEY is not defined in any of the keymaps,
5694 and cannot be part of a function key or translation,
5695 and is an upper case letter
5696 use the corresponding lower-case letter instead. */
5697 if (first_binding
== nmaps
&& ! function_key_possible
5698 && ! key_translation_possible
5700 && ((((XINT (key
) & 0x3ffff)
5701 < XSTRING (current_buffer
->downcase_table
)->size
)
5702 && UPPERCASEP (XINT (key
) & 0x3ffff))
5703 || (XINT (key
) & shift_modifier
)))
5705 original_uppercase
= key
;
5706 original_uppercase_position
= t
- 1;
5708 if (XINT (key
) & shift_modifier
)
5709 XSETINT (key
, XINT (key
) & ~shift_modifier
);
5711 XSETINT (key
, (DOWNCASE (XINT (key
) & 0x3ffff)
5712 | (XINT (key
) & ~0x3ffff)));
5714 keybuf
[t
- 1] = key
;
5716 goto replay_sequence
;
5718 /* If KEY is not defined in any of the keymaps,
5719 and cannot be part of a function key or translation,
5720 and is a shifted function key,
5721 use the corresponding unshifted function key instead. */
5722 if (first_binding
== nmaps
&& ! function_key_possible
5723 && ! key_translation_possible
5726 Lisp_Object breakdown
;
5729 original_uppercase
= key
;
5730 original_uppercase_position
= t
- 1;
5732 breakdown
= parse_modifiers (key
);
5733 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
5734 if (modifiers
& shift_modifier
)
5736 modifiers
&= ~shift_modifier
;
5737 key
= apply_modifiers (make_number (modifiers
),
5738 XCONS (breakdown
)->car
);
5740 keybuf
[t
- 1] = key
;
5742 goto replay_sequence
;
5748 read_key_sequence_cmd
= (first_binding
< nmaps
5749 ? defs
[first_binding
]
5752 unread_switch_frame
= delayed_switch_frame
;
5753 unbind_to (count
, Qnil
);
5755 if (dont_downcase_last
&& t
- 1 == original_uppercase_position
)
5756 keybuf
[t
- 1] = original_uppercase
;
5758 /* Occasionally we fabricate events, perhaps by expanding something
5759 according to function-key-map, or by adding a prefix symbol to a
5760 mouse click in the scroll bar or modeline. In this cases, return
5761 the entire generated key sequence, even if we hit an unbound
5762 prefix or a definition before the end. This means that you will
5763 be able to push back the event properly, and also means that
5764 read-key-sequence will always return a logical unit.
5767 for (; t
< mock_input
; t
++)
5769 if (echo_keystrokes
)
5770 echo_char (keybuf
[t
]);
5771 add_command_key (keybuf
[t
]);
5777 #if 0 /* This doc string is too long for some compilers.
5778 This commented-out definition serves for DOC. */
5779 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
5780 "Read a sequence of keystrokes and return as a string or vector.\n\
5781 The sequence is sufficient to specify a non-prefix command in the\n\
5782 current local and global maps.\n\
5784 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
5785 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
5786 as a continuation of the previous key.\n\
5788 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not\n\
5789 convert the last event to lower case. (Normally any upper case event\n\
5790 is converted to lower case if the original event is undefined and the lower\n\
5791 case equivalent is defined.) A non-nil value is appropriate for reading\n\
5792 a key sequence to be defined.\n\
5794 A C-g typed while in this function is treated like any other character,\n\
5795 and `quit-flag' is not set.\n\
5797 If the key sequence starts with a mouse click, then the sequence is read\n\
5798 using the keymaps of the buffer of the window clicked in, not the buffer\n\
5799 of the selected window as normal.\n\
5801 `read-key-sequence' drops unbound button-down events, since you normally\n\
5802 only care about the click or drag events which follow them. If a drag\n\
5803 or multi-click event is unbound, but the corresponding click event would\n\
5804 be bound, `read-key-sequence' turns the event into a click event at the\n\
5805 drag's starting position. This means that you don't have to distinguish\n\
5806 between click and drag, double, or triple events unless you want to.\n\
5808 `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\
5809 lines separating windows, and scroll bars with imaginary keys\n\
5810 `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\
5812 Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this\n\
5813 function will process a switch-frame event if the user switches frames\n\
5814 before typing anything. If the user switches frames in the middle of a\n\
5815 key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME\n\
5816 is nil, then the event will be put off until after the current key sequence.\n\
5818 `read-key-sequence' checks `function-key-map' for function key\n\
5819 sequences, where they wouldn't conflict with ordinary bindings. See\n\
5820 `function-key-map' for more details.")
5821 (prompt
, continue_echo
)
5824 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
5826 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
)
5827 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
5828 Lisp_Object can_return_switch_frame
;
5830 Lisp_Object keybuf
[30];
5832 struct gcpro gcpro1
, gcpro2
;
5835 CHECK_STRING (prompt
, 0);
5838 bzero (keybuf
, sizeof keybuf
);
5840 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
5842 if (NILP (continue_echo
))
5843 this_command_key_count
= 0;
5845 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
5846 prompt
, ! NILP (dont_downcase_last
),
5847 ! NILP (can_return_switch_frame
));
5855 return make_event_array (i
, keybuf
);
5858 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 2, 0,
5859 "Execute CMD as an editor command.\n\
5860 CMD must be a symbol that satisfies the `commandp' predicate.\n\
5861 Optional second arg RECORD-FLAG non-nil\n\
5862 means unconditionally put this command in `command-history'.\n\
5863 Otherwise, that is done only if an arg is read using the minibuffer.")
5865 Lisp_Object cmd
, record
;
5867 register Lisp_Object final
;
5868 register Lisp_Object tem
;
5869 Lisp_Object prefixarg
;
5870 struct backtrace backtrace
;
5871 extern int debug_on_next_call
;
5873 prefixarg
= Vprefix_arg
;
5874 clear_prefix_arg ();
5875 Vcurrent_prefix_arg
= prefixarg
;
5876 debug_on_next_call
= 0;
5880 tem
= Fget (cmd
, Qdisabled
);
5881 if (!NILP (tem
) && !NILP (Vrun_hooks
))
5882 return call1 (Vrun_hooks
, Qdisabled_command_hook
);
5887 final
= Findirect_function (cmd
);
5889 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
5890 do_autoload (final
, cmd
);
5895 if (STRINGP (final
) || VECTORP (final
))
5897 /* If requested, place the macro in the command history. For
5898 other sorts of commands, call-interactively takes care of
5902 = Fcons (Fcons (Qexecute_kbd_macro
,
5903 Fcons (final
, Fcons (prefixarg
, Qnil
))),
5906 return Fexecute_kbd_macro (final
, prefixarg
);
5908 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
5910 backtrace
.next
= backtrace_list
;
5911 backtrace_list
= &backtrace
;
5912 backtrace
.function
= &Qcall_interactively
;
5913 backtrace
.args
= &cmd
;
5914 backtrace
.nargs
= 1;
5915 backtrace
.evalargs
= 0;
5917 tem
= Fcall_interactively (cmd
, record
);
5919 backtrace_list
= backtrace
.next
;
5925 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
5927 "Read function name, then read its arguments and call it.")
5929 Lisp_Object prefixarg
;
5931 Lisp_Object function
;
5933 Lisp_Object saved_keys
;
5934 struct gcpro gcpro1
;
5936 saved_keys
= Fvector (this_command_key_count
,
5937 XVECTOR (this_command_keys
)->contents
);
5939 GCPRO1 (saved_keys
);
5941 if (EQ (prefixarg
, Qminus
))
5943 else if (CONSP (prefixarg
) && XINT (XCONS (prefixarg
)->car
) == 4)
5944 strcpy (buf
, "C-u ");
5945 else if (CONSP (prefixarg
) && INTEGERP (XCONS (prefixarg
)->car
))
5946 sprintf (buf
, "%d ", XINT (XCONS (prefixarg
)->car
));
5947 else if (INTEGERP (prefixarg
))
5948 sprintf (buf
, "%d ", XINT (prefixarg
));
5950 /* This isn't strictly correct if execute-extended-command
5951 is bound to anything else. Perhaps it should use
5952 this_command_keys? */
5953 strcat (buf
, "M-x ");
5955 /* Prompt with buf, and then read a string, completing from and
5956 restricting to the set of all defined commands. Don't provide
5957 any initial input. Save the command read on the extended-command
5959 function
= Fcompleting_read (build_string (buf
),
5960 Vobarray
, Qcommandp
,
5961 Qt
, Qnil
, Qextended_command_history
);
5963 /* Set this_command_keys to the concatenation of saved_keys and
5964 function, followed by a RET. */
5966 struct Lisp_String
*str
;
5971 this_command_key_count
= 0;
5973 keys
= XVECTOR (saved_keys
)->contents
;
5974 for (i
= 0; i
< XVECTOR (saved_keys
)->size
; i
++)
5975 add_command_key (keys
[i
]);
5977 str
= XSTRING (function
);
5978 for (i
= 0; i
< str
->size
; i
++)
5980 XSETFASTINT (tem
, str
->data
[i
]);
5981 add_command_key (tem
);
5984 XSETFASTINT (tem
, '\015');
5985 add_command_key (tem
);
5990 function
= Fintern (function
, Qnil
);
5991 Vprefix_arg
= prefixarg
;
5992 this_command
= function
;
5994 return Fcommand_execute (function
, Qt
);
5998 detect_input_pending ()
6001 get_input_pending (&input_pending
);
6003 return input_pending
;
6006 /* This is called in some cases before a possible quit.
6007 It cases the next call to detect_input_pending to recompute input_pending.
6008 So calling this function unnecessarily can't do any harm. */
6009 clear_input_pending ()
6014 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
6015 "T if command input is currently available with no waiting.\n\
6016 Actually, the value is nil only if we can be sure that no input is available.")
6019 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1)
6022 return detect_input_pending () ? Qt
: Qnil
;
6025 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
6026 "Return vector of last 100 events, not counting those from keyboard macros.")
6029 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
6032 if (total_keys
< NUM_RECENT_KEYS
)
6033 return Fvector (total_keys
, keys
);
6036 val
= Fvector (NUM_RECENT_KEYS
, keys
);
6037 bcopy (keys
+ recent_keys_index
,
6038 XVECTOR (val
)->contents
,
6039 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
6041 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
6042 recent_keys_index
* sizeof (Lisp_Object
));
6047 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
6048 "Return the key sequence that invoked this command.\n\
6049 The value is a string or a vector.")
6052 return make_event_array (this_command_key_count
,
6053 XVECTOR (this_command_keys
)->contents
);
6056 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
6057 "Return the current depth in recursive edits.")
6061 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
6065 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
6066 "FOpen dribble file: ",
6067 "Start writing all keyboard characters to a dribble file called FILE.\n\
6068 If FILE is nil, close any open dribble file.")
6082 file
= Fexpand_file_name (file
, Qnil
);
6083 dribble
= fopen (XSTRING (file
)->data
, "w");
6088 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
6089 "Discard the contents of the terminal input buffer.\n\
6090 Also cancel any kbd macro being defined.")
6093 current_kboard
->defining_kbd_macro
= Qnil
;
6094 update_mode_lines
++;
6096 Vunread_command_events
= Qnil
;
6097 unread_command_char
= -1;
6099 discard_tty_input ();
6101 /* Without the cast, GCC complains that this assignment loses the
6102 volatile qualifier of kbd_store_ptr. Is there anything wrong
6104 kbd_fetch_ptr
= (struct input_event
*) kbd_store_ptr
;
6105 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
6111 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
6112 "Stop Emacs and return to superior process. You can resume later.\n\
6113 If `cannot-suspend' is non-nil, or if the system doesn't support job\n\
6114 control, run a subshell instead.\n\n\
6115 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
6116 to be read as terminal input by Emacs's parent, after suspension.\n\
6118 Before suspending, run the normal hook `suspend-hook'.\n\
6119 After resumption run the normal hook `suspend-resume-hook'.\n\
6121 Some operating systems cannot stop the Emacs process and resume it later.\n\
6122 On such systems, Emacs starts a subshell instead of suspending.")
6124 Lisp_Object stuffstring
;
6127 int count
= specpdl_ptr
- specpdl
;
6128 int old_height
, old_width
;
6130 struct gcpro gcpro1
, gcpro2
;
6131 extern init_sys_modes ();
6133 if (!NILP (stuffstring
))
6134 CHECK_STRING (stuffstring
, 0);
6136 /* Run the functions in suspend-hook. */
6137 if (!NILP (Vrun_hooks
))
6138 call1 (Vrun_hooks
, intern ("suspend-hook"));
6140 GCPRO1 (stuffstring
);
6141 get_frame_size (&old_width
, &old_height
);
6143 /* sys_suspend can get an error if it tries to fork a subshell
6144 and the system resources aren't available for that. */
6145 record_unwind_protect (init_sys_modes
, 0);
6146 stuff_buffered_input (stuffstring
);
6151 unbind_to (count
, Qnil
);
6153 /* Check if terminal/window size has changed.
6154 Note that this is not useful when we are running directly
6155 with a window system; but suspend should be disabled in that case. */
6156 get_frame_size (&width
, &height
);
6157 if (width
!= old_width
|| height
!= old_height
)
6158 change_frame_size (selected_frame
, height
, width
, 0, 0);
6160 /* Run suspend-resume-hook. */
6161 if (!NILP (Vrun_hooks
))
6162 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
6168 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
6169 Then in any case stuff anything Emacs has read ahead and not used. */
6171 stuff_buffered_input (stuffstring
)
6172 Lisp_Object stuffstring
;
6174 /* stuff_char works only in BSD, versions 4.2 and up. */
6177 register unsigned char *p
;
6179 if (STRINGP (stuffstring
))
6183 p
= XSTRING (stuffstring
)->data
;
6184 count
= XSTRING (stuffstring
)->size
;
6189 /* Anything we have read ahead, put back for the shell to read. */
6190 /* ?? What should this do when we have multiple keyboards??
6191 Should we ignore anything that was typed in at the "wrong" kboard? */
6192 for (; kbd_fetch_ptr
!= kbd_store_ptr
; kbd_fetch_ptr
++)
6194 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
6195 kbd_fetch_ptr
= kbd_buffer
;
6196 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
6197 stuff_char (kbd_fetch_ptr
->code
);
6198 kbd_fetch_ptr
->kind
= no_event
;
6199 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_fetch_ptr
6205 #endif /* BSD and not BSD4_1 */
6208 set_waiting_for_input (time_to_clear
)
6209 EMACS_TIME
*time_to_clear
;
6211 input_available_clear_time
= time_to_clear
;
6213 /* Tell interrupt_signal to throw back to read_char, */
6214 waiting_for_input
= 1;
6216 /* If interrupt_signal was called before and buffered a C-g,
6217 make it run again now, to avoid timing error. */
6218 if (!NILP (Vquit_flag
))
6219 quit_throw_to_read_char ();
6222 clear_waiting_for_input ()
6224 /* Tell interrupt_signal not to throw back to read_char, */
6225 waiting_for_input
= 0;
6226 input_available_clear_time
= 0;
6229 /* This routine is called at interrupt level in response to C-G.
6230 If interrupt_input, this is the handler for SIGINT.
6231 Otherwise, it is called from kbd_buffer_store_event,
6232 in handling SIGIO or SIGTINT.
6234 If `waiting_for_input' is non zero, then unless `echoing' is nonzero,
6235 immediately throw back to read_char.
6237 Otherwise it sets the Lisp variable quit-flag not-nil.
6238 This causes eval to throw, when it gets a chance.
6239 If quit-flag is already non-nil, it stops the job right away. */
6242 interrupt_signal (signalnum
) /* If we don't have an argument, */
6243 int signalnum
; /* some compilers complain in signal calls. */
6246 /* Must preserve main program's value of errno. */
6247 int old_errno
= errno
;
6250 if (!read_socket_hook
&& NILP (Vwindow_system
))
6252 /* USG systems forget handlers when they are used;
6253 must reestablish each time */
6254 signal (SIGINT
, interrupt_signal
);
6255 signal (SIGQUIT
, interrupt_signal
);
6261 if (!NILP (Vquit_flag
) && FRAME_TERMCAP_P (selected_frame
))
6266 #ifdef SIGTSTP /* Support possible in later USG versions */
6268 * On systems which can suspend the current process and return to the original
6269 * shell, this command causes the user to end up back at the shell.
6270 * The "Auto-save" and "Abort" questions are not asked until
6271 * the user elects to return to emacs, at which point he can save the current
6272 * job and either dump core or continue.
6277 if (sys_suspend () == -1)
6279 printf ("Not running as a subprocess;\n");
6280 printf ("you can continue or abort.\n");
6283 /* Perhaps should really fork an inferior shell?
6284 But that would not provide any way to get back
6285 to the original shell, ever. */
6286 printf ("No support for stopping a process on this operating system;\n");
6287 printf ("you can continue or abort.\n");
6288 #endif /* not VMS */
6289 #endif /* not SIGTSTP */
6291 /* We must remain inside the screen area when the internal terminal
6292 is used. Note that [Enter] is not echoed by dos. */
6295 printf ("Auto-save? (y or n) ");
6297 if (((c
= getchar ()) & ~040) == 'Y')
6299 Fdo_auto_save (Qt
, Qnil
);
6301 printf ("\r\nAuto-save done");
6302 #else /* not MSDOS */
6303 printf ("Auto-save done\n");
6304 #endif /* not MSDOS */
6306 while (c
!= '\n') c
= getchar ();
6308 printf ("\r\nAbort? (y or n) ");
6309 #else /* not MSDOS */
6311 printf ("Abort (and enter debugger)? (y or n) ");
6313 printf ("Abort (and dump core)? (y or n) ");
6314 #endif /* not VMS */
6315 #endif /* not MSDOS */
6317 if (((c
= getchar ()) & ~040) == 'Y')
6319 while (c
!= '\n') c
= getchar ();
6321 printf ("\r\nContinuing...\r\n");
6322 #else /* not MSDOS */
6323 printf ("Continuing...\n");
6324 #endif /* not MSDOS */
6330 /* If executing a function that wants to be interrupted out of
6331 and the user has not deferred quitting by binding `inhibit-quit'
6332 then quit right away. */
6333 if (immediate_quit
&& NILP (Vinhibit_quit
))
6337 Fsignal (Qquit
, Qnil
);
6340 /* Else request quit when it's safe */
6344 if (waiting_for_input
&& !echoing
)
6345 quit_throw_to_read_char ();
6350 /* Handle a C-g by making read_char return C-g. */
6352 quit_throw_to_read_char ()
6354 quit_error_check ();
6356 /* Prevent another signal from doing this before we finish. */
6357 clear_waiting_for_input ();
6360 Vunread_command_events
= Qnil
;
6361 unread_command_char
= -1;
6363 #ifdef POLL_FOR_INPUT
6364 /* May be > 1 if in recursive minibuffer. */
6365 if (poll_suppress_count
== 0)
6369 if (FRAMEP (internal_last_event_frame
)
6370 && XFRAME (internal_last_event_frame
) != selected_frame
)
6371 Fhandle_switch_frame (make_lispy_switch_frame (internal_last_event_frame
));
6374 _longjmp (getcjmp
, 1);
6377 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
6378 "Set mode of reading keyboard input.\n\
6379 First arg INTERRUPT non-nil means use input interrupts;\n\
6380 nil means use CBREAK mode.\n\
6381 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
6382 (no effect except in CBREAK mode).\n\
6383 Third arg META t means accept 8-bit input (for a Meta key).\n\
6384 META nil means ignore the top bit, on the assumption it is parity.\n\
6385 Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\
6386 Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\
6387 See also `current-input-mode'.")
6388 (interrupt
, flow
, meta
, quit
)
6389 Lisp_Object interrupt
, flow
, meta
, quit
;
6392 && (!INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400))
6393 error ("set-input-mode: QUIT must be an ASCII character");
6395 #ifdef POLL_FOR_INPUT
6401 /* Note SIGIO has been undef'd if FIONREAD is missing. */
6402 #ifdef NO_SOCK_SIGIO
6403 if (read_socket_hook
)
6404 interrupt_input
= 0; /* No interrupts if reading from a socket. */
6406 #endif /* NO_SOCK_SIGIO */
6407 interrupt_input
= !NILP (interrupt
);
6408 #else /* not SIGIO */
6409 interrupt_input
= 0;
6410 #endif /* not SIGIO */
6411 /* Our VMS input only works by interrupts, as of now. */
6413 interrupt_input
= 1;
6415 flow_control
= !NILP (flow
);
6418 else if (EQ (meta
, Qt
))
6423 /* Don't let this value be out of range. */
6424 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
6428 #ifdef POLL_FOR_INPUT
6429 poll_suppress_count
= 1;
6435 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
6436 "Return information about the way Emacs currently reads keyboard input.\n\
6437 The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
6438 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\
6439 nil, Emacs is using CBREAK mode.\n\
6440 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\
6441 terminal; this does not apply if Emacs uses interrupt-driven input.\n\
6442 META is t if accepting 8-bit input with 8th bit as Meta flag.\n\
6443 META nil means ignoring the top bit, on the assumption it is parity.\n\
6444 META is neither t nor nil if accepting 8-bit input and using\n\
6445 all 8 bits as the character code.\n\
6446 QUIT is the character Emacs currently uses to quit.\n\
6447 The elements of this list correspond to the arguments of\n\
6453 val
[0] = interrupt_input
? Qt
: Qnil
;
6454 val
[1] = flow_control
? Qt
: Qnil
;
6455 val
[2] = meta_key
== 2 ? make_number (0) : meta_key
== 1 ? Qt
: Qnil
;
6456 XSETFASTINT (val
[3], quit_char
);
6458 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
6463 * Set up a new kboard object with reasonable initial values.
6469 kb
->prefix_factor
= Qnil
;
6470 kb
->prefix_value
= Qnil
;
6471 kb
->prefix_sign
= 1;
6472 kb
->prefix_partial
= 0;
6473 kb
->kbd_queue
= Qnil
;
6474 kb
->kbd_queue_has_data
= 0;
6475 kb
->immediate_echo
= 0;
6476 kb
->echoptr
= kb
->echobuf
;
6477 kb
->echo_after_prompt
= -1;
6478 kb
->kbd_macro_buffer
= 0;
6479 kb
->kbd_macro_bufsize
= 0;
6480 kb
->defining_kbd_macro
= Qnil
;
6481 kb
->Vlast_kbd_macro
= Qnil
;
6482 kb
->reference_count
= 0;
6486 * Destroy the contents of a kboard object, but not the object itself.
6487 * We use this just before deleteing it, or if we're going to initialize
6494 if (kb
->kbd_macro_buffer
)
6495 xfree (kb
->kbd_macro_buffer
);
6500 /* This is correct before outermost invocation of the editor loop */
6501 command_loop_level
= -1;
6503 quit_char
= Ctl ('g');
6504 Vunread_command_events
= Qnil
;
6505 unread_command_char
= -1;
6507 recent_keys_index
= 0;
6508 kbd_fetch_ptr
= kbd_buffer
;
6509 kbd_store_ptr
= kbd_buffer
;
6510 kbd_buffer_frame_or_window
6511 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
6513 do_mouse_tracking
= Qnil
;
6518 /* This means that command_loop_1 won't try to select anything the first
6520 internal_last_event_frame
= Qnil
;
6521 Vlast_event_frame
= internal_last_event_frame
;
6527 current_kboard
= (KBOARD
*)xmalloc (sizeof (KBOARD
));
6528 all_kboards
= current_kboard
;
6530 current_kboard
->next_kboard
= 0;
6533 wipe_kboard (current_kboard
);
6534 init_kboard (current_kboard
);
6537 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
6539 kbd_buffer_frame_or_window
6540 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
6541 if (!noninteractive
&& !read_socket_hook
&& NILP (Vwindow_system
))
6543 signal (SIGINT
, interrupt_signal
);
6544 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
6545 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
6546 SIGQUIT and we can't tell which one it will give us. */
6547 signal (SIGQUIT
, interrupt_signal
);
6548 #endif /* HAVE_TERMIO */
6550 /* Note SIGIO has been undef'd if FIONREAD is missing. */
6552 if (!noninteractive
)
6553 signal (SIGIO
, input_available_signal
);
6556 /* Use interrupt input by default, if it works and noninterrupt input
6557 has deficiencies. */
6559 #ifdef INTERRUPT_INPUT
6560 interrupt_input
= 1;
6562 interrupt_input
= 0;
6565 /* Our VMS input only works by interrupts, as of now. */
6567 interrupt_input
= 1;
6573 if (keyboard_init_hook
)
6574 (*keyboard_init_hook
) ();
6576 #ifdef POLL_FOR_INPUT
6577 poll_suppress_count
= 1;
6582 /* This type's only use is in syms_of_keyboard, to initialize the
6583 event header symbols and put properties on them. */
6590 struct event_head head_table
[] = {
6591 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
6592 &Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
,
6593 &Qswitch_frame
, "switch-frame", &Qswitch_frame
,
6594 &Qdelete_frame
, "delete-frame", &Qdelete_frame
,
6595 &Qiconify_frame
, "iconify-frame", &Qiconify_frame
,
6596 &Qmake_frame_visible
, "make-frame-visible", &Qmake_frame_visible
,
6601 Qdisabled_command_hook
= intern ("disabled-command-hook");
6602 staticpro (&Qdisabled_command_hook
);
6604 Qself_insert_command
= intern ("self-insert-command");
6605 staticpro (&Qself_insert_command
);
6607 Qforward_char
= intern ("forward-char");
6608 staticpro (&Qforward_char
);
6610 Qbackward_char
= intern ("backward-char");
6611 staticpro (&Qbackward_char
);
6613 Qdisabled
= intern ("disabled");
6614 staticpro (&Qdisabled
);
6616 Qundefined
= intern ("undefined");
6617 staticpro (&Qundefined
);
6619 Qdigit_argument
= intern ("digit-argument");
6620 staticpro (&Qdigit_argument
);
6622 Qnegative_argument
= intern ("negative-argument");
6623 staticpro (&Qnegative_argument
);
6625 Qpre_command_hook
= intern ("pre-command-hook");
6626 staticpro (&Qpre_command_hook
);
6628 Qpost_command_hook
= intern ("post-command-hook");
6629 staticpro (&Qpost_command_hook
);
6631 Qdeferred_action_function
= intern ("deferred-action-function");
6632 staticpro (&Qdeferred_action_function
);
6634 Qcommand_hook_internal
= intern ("command-hook-internal");
6635 staticpro (&Qcommand_hook_internal
);
6637 Qfunction_key
= intern ("function-key");
6638 staticpro (&Qfunction_key
);
6639 Qmouse_click
= intern ("mouse-click");
6640 staticpro (&Qmouse_click
);
6642 Qmenu_enable
= intern ("menu-enable");
6643 staticpro (&Qmenu_enable
);
6645 Qmode_line
= intern ("mode-line");
6646 staticpro (&Qmode_line
);
6647 Qvertical_line
= intern ("vertical-line");
6648 staticpro (&Qvertical_line
);
6649 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
6650 staticpro (&Qvertical_scroll_bar
);
6651 Qmenu_bar
= intern ("menu-bar");
6652 staticpro (&Qmenu_bar
);
6654 Qabove_handle
= intern ("above-handle");
6655 staticpro (&Qabove_handle
);
6656 Qhandle
= intern ("handle");
6657 staticpro (&Qhandle
);
6658 Qbelow_handle
= intern ("below-handle");
6659 staticpro (&Qbelow_handle
);
6661 Qevent_kind
= intern ("event-kind");
6662 staticpro (&Qevent_kind
);
6663 Qevent_symbol_elements
= intern ("event-symbol-elements");
6664 staticpro (&Qevent_symbol_elements
);
6665 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
6666 staticpro (&Qevent_symbol_element_mask
);
6667 Qmodifier_cache
= intern ("modifier-cache");
6668 staticpro (&Qmodifier_cache
);
6670 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
6671 staticpro (&Qrecompute_lucid_menubar
);
6672 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
6673 staticpro (&Qactivate_menubar_hook
);
6675 Qpolling_period
= intern ("polling-period");
6676 staticpro (&Qpolling_period
);
6679 struct event_head
*p
;
6681 for (p
= head_table
;
6682 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
6685 *p
->var
= intern (p
->name
);
6687 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
6688 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
6692 button_down_location
= Fmake_vector (make_number (NUM_MOUSE_BUTTONS
), Qnil
);
6693 staticpro (&button_down_location
);
6697 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
6699 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
6700 for (i
= 0; i
< len
; i
++)
6701 if (modifier_names
[i
])
6702 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
6703 staticpro (&modifier_symbols
);
6706 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
6707 staticpro (&recent_keys
);
6709 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
6710 staticpro (&this_command_keys
);
6712 Qextended_command_history
= intern ("extended-command-history");
6713 Fset (Qextended_command_history
, Qnil
);
6714 staticpro (&Qextended_command_history
);
6716 kbd_buffer_frame_or_window
6717 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
6718 staticpro (&kbd_buffer_frame_or_window
);
6720 accent_key_syms
= Qnil
;
6721 staticpro (&accent_key_syms
);
6723 func_key_syms
= Qnil
;
6724 staticpro (&func_key_syms
);
6726 system_key_syms
= Qnil
;
6727 staticpro (&system_key_syms
);
6730 staticpro (&mouse_syms
);
6732 unread_switch_frame
= Qnil
;
6733 staticpro (&unread_switch_frame
);
6735 defsubr (&Sread_key_sequence
);
6736 defsubr (&Srecursive_edit
);
6738 defsubr (&Strack_mouse
);
6740 defsubr (&Sinput_pending_p
);
6741 defsubr (&Scommand_execute
);
6742 defsubr (&Srecent_keys
);
6743 defsubr (&Sthis_command_keys
);
6744 defsubr (&Ssuspend_emacs
);
6745 defsubr (&Sabort_recursive_edit
);
6746 defsubr (&Sexit_recursive_edit
);
6747 defsubr (&Srecursion_depth
);
6748 defsubr (&Stop_level
);
6749 defsubr (&Sdiscard_input
);
6750 defsubr (&Sopen_dribble_file
);
6751 defsubr (&Sset_input_mode
);
6752 defsubr (&Scurrent_input_mode
);
6753 defsubr (&Sexecute_extended_command
);
6755 DEFVAR_LISP ("last-command-char", &last_command_char
,
6756 "Last input event that was part of a command.");
6758 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char
,
6759 "Last input event that was part of a command.");
6761 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
6762 "Last input event in a command, except for mouse menu events.\n\
6763 Mouse menus give back keys that don't look like mouse events;\n\
6764 this variable holds the actual mouse event that led to the menu,\n\
6765 so that you can determine whether the command was run by mouse or not.");
6767 DEFVAR_LISP ("last-input-char", &last_input_char
,
6768 "Last input event.");
6770 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char
,
6771 "Last input event.");
6773 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
6774 "List of objects to be read as next command input events.");
6776 DEFVAR_INT ("unread-command-char", &unread_command_char
,
6777 "If not -1, an object to be read as next command input event.");
6779 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
6780 "Meta-prefix character code. Meta-foo as command input\n\
6781 turns into this character followed by foo.");
6782 XSETINT (meta_prefix_char
, 033);
6784 DEFVAR_LISP ("last-command", &last_command
,
6785 "The last command executed. Normally a symbol with a function definition,\n\
6786 but can be whatever was found in the keymap, or whatever the variable\n\
6787 `this-command' was set to by that command.\n\
6789 The value `mode-exit' is special; it means that the previous command\n\
6790 read an event that told it to exit, and it did so and unread that event.\n\
6791 In other words, the present command is the event that made the previous\n\
6794 The value `kill-region' is special; it means that the previous command\n\
6795 was a kill command.");
6796 last_command
= Qnil
;
6798 DEFVAR_LISP ("this-command", &this_command
,
6799 "The command now being executed.\n\
6800 The command can set this variable; whatever is put here\n\
6801 will be in `last-command' during the following command.");
6802 this_command
= Qnil
;
6804 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
6805 "*Number of keyboard input characters between auto-saves.\n\
6806 Zero means disable autosaving due to number of characters typed.");
6807 auto_save_interval
= 300;
6809 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
6810 "*Number of seconds idle time before auto-save.\n\
6811 Zero or nil means disable auto-saving due to idleness.\n\
6812 After auto-saving due to this many seconds of idle time,\n\
6813 Emacs also does a garbage collection if that seems to be warranted.");
6814 XSETFASTINT (Vauto_save_timeout
, 30);
6816 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes
,
6817 "*Nonzero means echo unfinished commands after this many seconds of pause.");
6818 echo_keystrokes
= 1;
6820 DEFVAR_INT ("polling-period", &polling_period
,
6821 "*Interval between polling for input during Lisp execution.\n\
6822 The reason for polling is to make C-g work to stop a running program.\n\
6823 Polling is needed only when using X windows and SIGIO does not work.\n\
6824 Polling is automatically disabled in all other cases.");
6827 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
6828 "*Maximum time between mouse clicks to make a double-click.\n\
6829 Measured in milliseconds. nil means disable double-click recognition;\n\
6830 t means double-clicks have no time limit and are detected\n\
6831 by position only.");
6832 Vdouble_click_time
= make_number (500);
6834 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
6835 "*Non-nil means inhibit local map menu bar menus.");
6836 inhibit_local_menu_bar_menus
= 0;
6838 DEFVAR_INT ("num-input-keys", &num_input_keys
,
6839 "Number of complete keys read from the keyboard so far.");
6842 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
6843 "The frame in which the most recently read event occurred.\n\
6844 If the last event came from a keyboard macro, this is set to `macro'.");
6845 Vlast_event_frame
= Qnil
;
6847 DEFVAR_LISP ("help-char", &Vhelp_char
,
6848 "Character to recognize as meaning Help.\n\
6849 When it is read, do `(eval help-form)', and display result if it's a string.\n\
6850 If the value of `help-form' is nil, this char can be read normally.");
6851 XSETINT (Vhelp_char
, Ctl ('H'));
6853 DEFVAR_LISP ("help-form", &Vhelp_form
,
6854 "Form to execute when character `help-char' is read.\n\
6855 If the form returns a string, that string is displayed.\n\
6856 If `help-form' is nil, the help char is not recognized.");
6859 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
6860 "Command to run when `help-char' character follows a prefix key.\n\
6861 This command is used only when there is no actual binding\n\
6862 for that character after that prefix key.");
6863 Vprefix_help_command
= Qnil
;
6865 DEFVAR_LISP ("top-level", &Vtop_level
,
6866 "Form to evaluate when Emacs starts up.\n\
6867 Useful to set before you dump a modified Emacs.");
6870 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
6871 "String used as translate table for keyboard input, or nil.\n\
6872 Each character is looked up in this string and the contents used instead.\n\
6873 If string is of length N, character codes N and up are untranslated.");
6874 Vkeyboard_translate_table
= Qnil
;
6876 DEFVAR_LISP ("key-translation-map", &Vkey_translation_map
,
6877 "Keymap of key translations that can override keymaps.\n\
6878 This keymap works like `function-key-map', but comes after that,\n\
6879 and applies even for keys that have ordinary bindings.");
6880 Vkey_translation_map
= Qnil
;
6882 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
6883 "Non-nil means to always spawn a subshell instead of suspending,\n\
6884 even if the operating system has support for stopping a process.");
6887 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
6888 "Non-nil means prompt with menus when appropriate.\n\
6889 This is done when reading from a keymap that has a prompt string,\n\
6890 for elements that have prompt strings.\n\
6891 The menu is displayed on the screen\n\
6892 if X menus were enabled at configuration\n\
6893 time and the previous event was a mouse click prefix key.\n\
6894 Otherwise, menu prompting uses the echo area.");
6897 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
6898 "Character to see next line of menu prompt.\n\
6899 Type this character while in a menu prompt to rotate around the lines of it.");
6900 XSETINT (menu_prompt_more_char
, ' ');
6902 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
6903 "A mask of additional modifier keys to use with every keyboard character.\n\
6904 Emacs applies the modifiers of the character stored here to each keyboard\n\
6905 character it reads. For example, after evaluating the expression\n\
6906 (setq extra-keyboard-modifiers ?\\C-x)\n\
6907 all input characters will have the control modifier applied to them.\n\
6909 Note that the character ?\\C-@, equivalent to the integer zero, does\n\
6910 not count as a control character; rather, it counts as a character\n\
6911 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\
6912 cancels any modification.");
6913 extra_keyboard_modifiers
= 0;
6915 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
6916 "If an editing command sets this to t, deactivate the mark afterward.\n\
6917 The command loop sets this to nil before each command,\n\
6918 and tests the value when the command returns.\n\
6919 Buffer modification stores t in this variable.");
6920 Vdeactivate_mark
= Qnil
;
6922 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
6923 "Temporary storage of pre-command-hook or post-command-hook.");
6924 Vcommand_hook_internal
= Qnil
;
6926 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
6927 "Normal hook run before each command is executed.\n\
6928 While the hook is run, its value is temporarily set to nil\n\
6929 to avoid an unbreakable infinite loop if a hook function gets an error.\n\
6930 As a result, a hook function cannot straightforwardly alter the value of\n\
6931 `pre-command-hook'. See the Emacs Lisp manual for a way of\n\
6932 implementing hook functions that alter the set of hook functions.");
6933 Vpre_command_hook
= Qnil
;
6935 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
6936 "Normal hook run after each command is executed.\n\
6937 While the hook is run, its value is temporarily set to nil\n\
6938 to avoid an unbreakable infinite loop if a hook function gets an error.\n\
6939 As a result, a hook function cannot straightforwardly alter the value of\n\
6940 `post-command-hook'. See the Emacs Lisp manual for a way of\n\
6941 implementing hook functions that alter the set of hook functions.");
6942 Vpost_command_hook
= Qnil
;
6944 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
6945 "t means menu bar, specified Lucid style, needs to be recomputed.");
6946 Vlucid_menu_bar_dirty_flag
= Qnil
;
6948 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
6949 "List of menu bar items to move to the end of the menu bar.\n\
6950 The elements of the list are event types that may have menu bar bindings.");
6951 Vmenu_bar_final_items
= Qnil
;
6953 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
6954 "Keymap that overrides all other local keymaps.\n\
6955 If this variable is non-nil, it is used as a keymap instead of the\n\
6956 buffer's local map, and the minor mode keymaps and text property keymaps.");
6957 Voverriding_local_map
= Qnil
;
6959 DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag
,
6960 "Non-nil means `overriding-local-map' applies to the menu bar.\n\
6961 Otherwise, the menu bar continues to reflect the buffer's local map\n\
6962 and the minor mode maps regardless of `overriding-local-map'.");
6963 Voverriding_local_map_menu_flag
= Qnil
;
6966 DEFVAR_LISP ("track-mouse", &do_mouse_tracking
,
6967 "*Non-nil means generate motion events for mouse motion.");
6970 DEFVAR_LISP ("system-key-alist", &Vsystem_key_alist
,
6971 "Alist of system-specific X windows key symbols.\n\
6972 Each element should have the form (N . SYMBOL) where N is the\n\
6973 numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\
6974 and SYMBOL is its name.");
6975 Vsystem_key_alist
= Qnil
;
6977 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
6978 "List of deferred actions to be performed at a later time.\n\
6979 The precise format isn't relevant here; we just check whether it is nil.");
6980 Vdeferred_action_list
= Qnil
;
6982 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
6983 "Function to call to handle deferred actions, after each command.\n\
6984 This function is called with no arguments after each command\n\
6985 whenever `deferred-action-list' is non-nil.");
6986 Vdeferred_action_function
= Qnil
;
6991 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
6992 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
6993 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
6994 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
6995 initial_define_key (meta_map
, 'x', "execute-extended-command");