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. */
61 #endif /* HAVE_NTGUI */
63 /* Include systime.h after xterm.h to avoid double inclusion of time.h. */
68 /* Variables for blockinput.h: */
70 /* Non-zero if interrupt input is blocked right now. */
71 int interrupt_input_blocked
;
73 /* Nonzero means an input interrupt has arrived
74 during the current critical section. */
75 int interrupt_input_pending
;
78 /* File descriptor to use for input. */
81 #ifdef HAVE_WINDOW_SYSTEM
82 /* Make all keyboard buffers much bigger when using X windows. */
83 #define KBD_BUFFER_SIZE 4096
84 #else /* No X-windows, character input */
85 #define KBD_BUFFER_SIZE 256
86 #endif /* No X-windows */
88 /* Following definition copied from eval.c */
92 struct backtrace
*next
;
93 Lisp_Object
*function
;
94 Lisp_Object
*args
; /* Points to vector of args. */
95 int nargs
; /* length of vector. If nargs is UNEVALLED,
96 args points to slot holding list of
102 KBOARD
*initial_kboard
;
103 KBOARD
*current_kboard
;
107 KBOARD the_only_kboard
;
110 /* Non-nil disable property on a command means
111 do not execute it; call disabled-command-hook's value instead. */
112 Lisp_Object Qdisabled
, Qdisabled_command_hook
;
114 #define NUM_RECENT_KEYS (100)
115 int recent_keys_index
; /* Index for storing next element into recent_keys */
116 int total_keys
; /* Total number of elements stored into recent_keys */
117 Lisp_Object recent_keys
; /* A vector, holding the last 100 keystrokes */
119 /* Vector holding the key sequence that invoked the current command.
120 It is reused for each command, and it may be longer than the current
121 sequence; this_command_key_count indicates how many elements
122 actually mean something.
123 It's easier to staticpro a single Lisp_Object than an array. */
124 Lisp_Object this_command_keys
;
125 int this_command_key_count
;
127 /* Record values of this_command_key_count and echo_length ()
128 before this command was read. */
129 static int before_command_key_count
;
130 static int before_command_echo_length
;
131 /* Values of before_command_key_count and before_command_echo_length
132 saved by reset-this-command-lengths. */
133 static int before_command_key_count_1
;
134 static int before_command_echo_length_1
;
135 /* Flag set by reset-this-command-lengths,
136 saying to reset the lengths when add_command_key is called. */
137 static int before_command_restore_flag
;
139 extern int minbuf_level
;
141 extern struct backtrace
*backtrace_list
;
143 /* Nonzero means do menu prompting. */
144 static int menu_prompting
;
146 /* Character to see next line of menu prompt. */
147 static Lisp_Object menu_prompt_more_char
;
149 /* For longjmp to where kbd input is being done. */
150 static jmp_buf getcjmp
;
152 /* True while doing kbd input. */
153 int waiting_for_input
;
155 /* True while displaying for echoing. Delays C-g throwing. */
158 /* True means we can start echoing at the next input pause
159 even though there is something in the echo area. */
160 static char *ok_to_echo_at_next_pause
;
162 /* Nonzero means disregard local maps for the menu bar. */
163 static int inhibit_local_menu_bar_menus
;
165 /* Nonzero means C-g should cause immediate error-signal. */
168 /* Character to recognize as the help char. */
169 Lisp_Object Vhelp_char
;
171 /* List of other event types to recognize as meaning "help". */
172 Lisp_Object Vhelp_event_list
;
174 /* Form to execute when help char is typed. */
175 Lisp_Object Vhelp_form
;
177 /* Command to run when the help character follows a prefix key. */
178 Lisp_Object Vprefix_help_command
;
180 /* List of items that should move to the end of the menu bar. */
181 Lisp_Object Vmenu_bar_final_items
;
183 /* Non-nil means show the equivalent key-binding for
184 any M-x command that has one.
185 The value can be a length of time to show the message for.
186 If the value is non-nil and not a number, we wait 2 seconds. */
187 Lisp_Object Vsuggest_key_bindings
;
189 /* Character that causes a quit. Normally C-g.
191 If we are running on an ordinary terminal, this must be an ordinary
192 ASCII char, since we want to make it our interrupt character.
194 If we are not running on an ordinary terminal, it still needs to be
195 an ordinary ASCII char. This character needs to be recognized in
196 the input interrupt handler. At this point, the keystroke is
197 represented as a struct input_event, while the desired quit
198 character is specified as a lispy event. The mapping from struct
199 input_events to lispy events cannot run in an interrupt handler,
200 and the reverse mapping is difficult for anything but ASCII
203 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
207 extern Lisp_Object current_global_map
;
208 extern int minibuf_level
;
210 /* If non-nil, this is a map that overrides all other local maps. */
211 Lisp_Object Voverriding_local_map
;
213 /* If non-nil, Voverriding_local_map applies to the menu bar. */
214 Lisp_Object Voverriding_local_map_menu_flag
;
216 /* Keymap that defines special misc events that should
217 be processed immediately at a low level. */
218 Lisp_Object Vspecial_event_map
;
220 /* Current depth in recursive edits. */
221 int command_loop_level
;
223 /* Total number of times command_loop has read a key sequence. */
226 /* Last input character read as a command. */
227 Lisp_Object last_command_char
;
229 /* Last input character read as a command, not counting menus
230 reached by the mouse. */
231 Lisp_Object last_nonmenu_event
;
233 /* Last input character read for any purpose. */
234 Lisp_Object last_input_char
;
236 /* If not Qnil, a list of objects to be read as subsequent command input. */
237 Lisp_Object Vunread_command_events
;
239 /* If not -1, an event to be read as subsequent command input. */
240 int unread_command_char
;
242 /* If not Qnil, this is a switch-frame event which we decided to put
243 off until the end of a key sequence. This should be read as the
244 next command input, after any unread_command_events.
246 read_key_sequence uses this to delay switch-frame events until the
247 end of the key sequence; Fread_char uses it to put off switch-frame
248 events until a non-ASCII event is acceptable as input. */
249 Lisp_Object unread_switch_frame
;
251 /* A mask of extra modifier bits to put into every keyboard char. */
252 int extra_keyboard_modifiers
;
254 /* Char to use as prefix when a meta character is typed in.
255 This is bound on entry to minibuffer in case ESC is changed there. */
257 Lisp_Object meta_prefix_char
;
259 /* Last size recorded for a current buffer which is not a minibuffer. */
260 static int last_non_minibuf_size
;
262 /* Number of idle seconds before an auto-save and garbage collection. */
263 static Lisp_Object Vauto_save_timeout
;
265 /* Total number of times read_char has returned. */
268 /* Total number of times read_char has returned, outside of macros. */
269 int num_nonmacro_input_chars
;
271 /* Auto-save automatically when this many characters have been typed
272 since the last time. */
274 static int auto_save_interval
;
276 /* Value of num_nonmacro_input_chars as of last auto save. */
280 /* The command being executed by the command loop.
281 Commands may set this, and the value set will be copied into
282 current_kboard->Vlast_command instead of the actual command. */
283 Lisp_Object this_command
;
285 /* The value of point when the last command was executed. */
286 int last_point_position
;
288 /* The buffer that was current when the last command was started. */
289 Lisp_Object last_point_position_buffer
;
292 /* The frame in which the last input event occurred, or Qmacro if the
293 last event came from a macro. We use this to determine when to
294 generate switch-frame events. This may be cleared by functions
295 like Fselect_frame, to make sure that a switch-frame event is
296 generated by the next character. */
297 Lisp_Object internal_last_event_frame
;
300 /* A user-visible version of the above, intended to allow users to
301 figure out where the last event came from, if the event doesn't
302 carry that information itself (i.e. if it was a character). */
303 Lisp_Object Vlast_event_frame
;
305 /* The timestamp of the last input event we received from the X server.
306 X Windows wants this for selection ownership. */
307 unsigned long last_event_timestamp
;
309 Lisp_Object Qself_insert_command
;
310 Lisp_Object Qforward_char
;
311 Lisp_Object Qbackward_char
;
312 Lisp_Object Qundefined
;
314 /* read_key_sequence stores here the command definition of the
315 key sequence that it reads. */
316 Lisp_Object read_key_sequence_cmd
;
318 /* Form to evaluate (if non-nil) when Emacs is started. */
319 Lisp_Object Vtop_level
;
321 /* User-supplied string to translate input characters through. */
322 Lisp_Object Vkeyboard_translate_table
;
324 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
325 extern Lisp_Object Vfunction_key_map
;
327 /* Another keymap that maps key sequences into key sequences.
328 This one takes precedence over ordinary definitions. */
329 extern Lisp_Object Vkey_translation_map
;
331 /* Non-nil means deactivate the mark at end of this command. */
332 Lisp_Object Vdeactivate_mark
;
334 /* Menu bar specified in Lucid Emacs fashion. */
336 Lisp_Object Vlucid_menu_bar_dirty_flag
;
337 Lisp_Object Qrecompute_lucid_menubar
, Qactivate_menubar_hook
;
339 /* Hooks to run before and after each command. */
340 Lisp_Object Qpre_command_hook
, Vpre_command_hook
;
341 Lisp_Object Qpost_command_hook
, Vpost_command_hook
;
342 Lisp_Object Qcommand_hook_internal
, Vcommand_hook_internal
;
343 /* Hook run after a command if there's no more input soon. */
344 Lisp_Object Qpost_command_idle_hook
, Vpost_command_idle_hook
;
346 /* Delay time in microseconds before running post-command-idle-hook. */
347 int post_command_idle_delay
;
349 /* List of deferred actions to be performed at a later time.
350 The precise format isn't relevant here; we just check whether it is nil. */
351 Lisp_Object Vdeferred_action_list
;
353 /* Function to call to handle deferred actions, when there are any. */
354 Lisp_Object Vdeferred_action_function
;
355 Lisp_Object Qdeferred_action_function
;
357 /* File in which we write all commands we read. */
360 /* Nonzero if input is available. */
363 /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
364 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
368 extern char *pending_malloc_warning
;
370 /* Circular buffer for pre-read keyboard input. */
371 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
373 /* Vector to GCPRO the frames and windows mentioned in kbd_buffer.
375 The interrupt-level event handlers will never enqueue an event on a
376 frame which is not in Vframe_list, and once an event is dequeued,
377 internal_last_event_frame or the event itself points to the frame.
380 But while the event is sitting in the queue, it's completely
381 unprotected. Suppose the user types one command which will run for
382 a while and then delete a frame, and then types another event at
383 the frame that will be deleted, before the command gets around to
384 it. Suppose there are no references to this frame elsewhere in
385 Emacs, and a GC occurs before the second event is dequeued. Now we
386 have an event referring to a freed frame, which will crash Emacs
389 Similar things happen when an event on a scroll bar is enqueued; the
390 window may be deleted while the event is in the queue.
392 So, we use this vector to protect the frame_or_window field in the
393 event queue. That way, they'll be dequeued as dead frames or
394 windows, but still valid lisp objects.
396 If kbd_buffer[i].kind != no_event, then
397 (XVECTOR (kbd_buffer_frame_or_window)->contents[i]
398 == kbd_buffer[i].frame_or_window. */
399 static Lisp_Object kbd_buffer_frame_or_window
;
401 /* Pointer to next available character in kbd_buffer.
402 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
403 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the
404 next available char is in kbd_buffer[0]. */
405 static struct input_event
*kbd_fetch_ptr
;
407 /* Pointer to next place to store character in kbd_buffer. This
408 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
409 character should go in kbd_buffer[0]. */
410 static volatile struct input_event
*kbd_store_ptr
;
412 /* The above pair of variables forms a "queue empty" flag. When we
413 enqueue a non-hook event, we increment kbd_store_ptr. When we
414 dequeue a non-hook event, we increment kbd_fetch_ptr. We say that
415 there is input available iff the two pointers are not equal.
417 Why not just have a flag set and cleared by the enqueuing and
418 dequeuing functions? Such a flag could be screwed up by interrupts
419 at inopportune times. */
421 /* If this flag is non-nil, we check mouse_moved to see when the
422 mouse moves, and motion events will appear in the input stream.
423 Otherwise, mouse motion is ignored. */
424 static Lisp_Object do_mouse_tracking
;
426 /* Symbols to head events. */
427 Lisp_Object Qmouse_movement
;
428 Lisp_Object Qscroll_bar_movement
;
429 Lisp_Object Qswitch_frame
;
430 Lisp_Object Qdelete_frame
;
431 Lisp_Object Qiconify_frame
;
432 Lisp_Object Qmake_frame_visible
;
434 /* Symbols to denote kinds of events. */
435 Lisp_Object Qfunction_key
;
436 Lisp_Object Qmouse_click
;
437 /* Lisp_Object Qmouse_movement; - also an event header */
439 /* Properties of event headers. */
440 Lisp_Object Qevent_kind
;
441 Lisp_Object Qevent_symbol_elements
;
443 Lisp_Object Qmenu_enable
;
445 /* An event header symbol HEAD may have a property named
446 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
447 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
448 mask of modifiers applied to it. If present, this is used to help
449 speed up parse_modifiers. */
450 Lisp_Object Qevent_symbol_element_mask
;
452 /* An unmodified event header BASE may have a property named
453 Qmodifier_cache, which is an alist mapping modifier masks onto
454 modified versions of BASE. If present, this helps speed up
456 Lisp_Object Qmodifier_cache
;
458 /* Symbols to use for parts of windows. */
459 Lisp_Object Qmode_line
;
460 Lisp_Object Qvertical_line
;
461 Lisp_Object Qvertical_scroll_bar
;
462 Lisp_Object Qmenu_bar
;
464 extern Lisp_Object Qmenu_enable
;
466 Lisp_Object
recursive_edit_unwind (), command_loop ();
467 Lisp_Object
Fthis_command_keys ();
468 Lisp_Object Qextended_command_history
;
470 extern char *x_get_keysym_name ();
472 Lisp_Object Qpolling_period
;
474 extern Lisp_Object Vprint_level
, Vprint_length
;
476 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
478 EMACS_TIME
*input_available_clear_time
;
480 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
481 Default is 1 if INTERRUPT_INPUT is defined. */
484 /* Nonzero while interrupts are temporarily deferred during redisplay. */
485 int interrupts_deferred
;
487 /* nonzero means use ^S/^Q for flow control. */
490 /* Allow m- file to inhibit use of FIONREAD. */
491 #ifdef BROKEN_FIONREAD
495 /* We are unable to use interrupts if FIONREAD is not available,
496 so flush SIGIO so we won't try. */
503 /* If we support a window system, turn on the code to poll periodically
504 to detect C-g. It isn't actually used when doing interrupt input. */
505 #ifdef HAVE_WINDOW_SYSTEM
506 #define POLL_FOR_INPUT
509 /* Non-nil enables Column Number mode. */
510 Lisp_Object Vcolumn_number_mode
;
512 /* Global variable declarations. */
514 /* Function for init_keyboard to call with no args (if nonzero). */
515 void (*keyboard_init_hook
) ();
517 static int read_avail_input ();
518 static void get_input_pending ();
519 static int readable_events ();
520 static Lisp_Object
read_char_x_menu_prompt ();
521 static Lisp_Object
read_char_minibuf_menu_prompt ();
522 static Lisp_Object
make_lispy_event ();
524 static Lisp_Object
make_lispy_movement ();
526 static Lisp_Object
modify_event_symbol ();
527 static Lisp_Object
make_lispy_switch_frame ();
528 static int parse_solitary_modifier ();
530 /* > 0 if we are to echo keystrokes. */
531 static int echo_keystrokes
;
533 /* Nonzero means don't try to suspend even if the operating system seems
535 static int cannot_suspend
;
537 #define min(a,b) ((a)<(b)?(a):(b))
538 #define max(a,b) ((a)>(b)?(a):(b))
540 /* Install the string STR as the beginning of the string of echoing,
541 so that it serves as a prompt for the next character.
542 Also start echoing. */
547 int len
= strlen (str
);
549 if (len
> ECHOBUFSIZE
- 4)
550 len
= ECHOBUFSIZE
- 4;
551 bcopy (str
, current_kboard
->echobuf
, len
);
552 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
553 *current_kboard
->echoptr
= '\0';
555 current_kboard
->echo_after_prompt
= len
;
560 /* Add C to the echo string, if echoing is going on.
561 C can be a character, which is printed prettily ("M-C-x" and all that
562 jazz), or a symbol, whose name is printed. */
567 extern char *push_key_description ();
569 if (current_kboard
->immediate_echo
)
571 char *ptr
= current_kboard
->echoptr
;
573 if (ptr
!= current_kboard
->echobuf
)
576 /* If someone has passed us a composite event, use its head symbol. */
581 if (ptr
- current_kboard
->echobuf
> ECHOBUFSIZE
- 6)
584 ptr
= push_key_description (XINT (c
), ptr
);
586 else if (SYMBOLP (c
))
588 struct Lisp_String
*name
= XSYMBOL (c
)->name
;
589 if ((ptr
- current_kboard
->echobuf
) + name
->size
+ 4 > ECHOBUFSIZE
)
591 bcopy (name
->data
, ptr
, name
->size
);
595 if (current_kboard
->echoptr
== current_kboard
->echobuf
598 strcpy (ptr
, " (Type ? for further options)");
603 current_kboard
->echoptr
= ptr
;
609 /* Temporarily add a dash to the end of the echo string if it's not
610 empty, so that it serves as a mini-prompt for the very next character. */
614 if (!current_kboard
->immediate_echo
615 && current_kboard
->echoptr
== current_kboard
->echobuf
)
617 /* Do nothing if we just printed a prompt. */
618 if (current_kboard
->echo_after_prompt
619 == current_kboard
->echoptr
- current_kboard
->echobuf
)
621 /* Do nothing if not echoing at all. */
622 if (current_kboard
->echoptr
== 0)
625 /* Put a dash at the end of the buffer temporarily,
626 but make it go away when the next character is added. */
627 current_kboard
->echoptr
[0] = '-';
628 current_kboard
->echoptr
[1] = 0;
633 /* Display the current echo string, and begin echoing if not already
638 if (!current_kboard
->immediate_echo
)
641 current_kboard
->immediate_echo
= 1;
643 for (i
= 0; i
< this_command_key_count
; i
++)
646 c
= XVECTOR (this_command_keys
)->contents
[i
];
647 if (! (EVENT_HAS_PARAMETERS (c
)
648 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
655 message1_nolog (current_kboard
->echobuf
);
658 if (waiting_for_input
&& !NILP (Vquit_flag
))
659 quit_throw_to_read_char ();
662 /* Turn off echoing, for the start of a new command. */
666 current_kboard
->immediate_echo
= 0;
667 current_kboard
->echoptr
= current_kboard
->echobuf
;
668 current_kboard
->echo_after_prompt
= -1;
669 ok_to_echo_at_next_pause
= 0;
672 /* Return the length of the current echo string. */
677 return current_kboard
->echoptr
- current_kboard
->echobuf
;
680 /* Truncate the current echo message to its first LEN chars.
681 This and echo_char get used by read_key_sequence when the user
682 switches frames while entering a key sequence. */
688 current_kboard
->echobuf
[len
] = '\0';
689 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
690 truncate_echo_area (len
);
694 /* Functions for manipulating this_command_keys. */
696 add_command_key (key
)
699 int size
= XVECTOR (this_command_keys
)->size
;
701 /* If reset-this-command-length was called recently, obey it now.
702 See the doc string of that function for an explanation of why. */
703 if (before_command_restore_flag
)
705 this_command_key_count
= before_command_key_count_1
;
706 echo_truncate (before_command_echo_length_1
);
707 before_command_restore_flag
= 0;
710 if (this_command_key_count
>= size
)
712 Lisp_Object new_keys
;
714 new_keys
= Fmake_vector (make_number (size
* 2), Qnil
);
715 bcopy (XVECTOR (this_command_keys
)->contents
,
716 XVECTOR (new_keys
)->contents
,
717 size
* sizeof (Lisp_Object
));
719 this_command_keys
= new_keys
;
722 XVECTOR (this_command_keys
)->contents
[this_command_key_count
++] = key
;
728 int count
= specpdl_ptr
- specpdl
;
731 if (command_loop_level
> 0)
733 specbind (Qstandard_output
, Qt
);
734 specbind (Qstandard_input
, Qt
);
737 val
= command_loop ();
739 Fsignal (Qquit
, Qnil
);
741 return unbind_to (count
, Qnil
);
744 /* When an auto-save happens, record the "time", and don't do again soon. */
748 last_auto_save
= num_nonmacro_input_chars
;
751 /* Make an auto save happen as soon as possible at command level. */
753 force_auto_save_soon ()
755 last_auto_save
= - auto_save_interval
- 1;
757 record_asynch_buffer_change ();
760 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
761 "Invoke the editor command loop recursively.\n\
762 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
763 that tells this function to return.\n\
764 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
765 This function is called by the editor initialization to begin editing.")
768 int count
= specpdl_ptr
- specpdl
;
771 command_loop_level
++;
772 update_mode_lines
= 1;
774 record_unwind_protect (recursive_edit_unwind
,
776 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
780 return unbind_to (count
, Qnil
);
784 recursive_edit_unwind (buffer
)
788 Fset_buffer (buffer
);
790 command_loop_level
--;
791 update_mode_lines
= 1;
799 #if 0 /* Theory: if there's anything in Vunread_command_events,
800 it will right away be read by read_key_sequence,
801 and then if we do switch KBOARDS, it will go into the side
802 queue then. So we don't need to do anything special here -- rms. */
803 if (CONSP (Vunread_command_events
))
805 current_kboard
->kbd_queue
806 = nconc2 (Vunread_command_events
, current_kboard
->kbd_queue
);
807 current_kboard
->kbd_queue_has_data
= 1;
809 Vunread_command_events
= Qnil
;
815 /* Switch to the single-kboard state, making current_kboard
816 the only KBOARD from which further input is accepted. */
819 single_kboard_state ()
826 /* Maintain a stack of kboards, so other parts of Emacs
827 can switch temporarily to the kboard of a given frame
828 and then revert to the previous status. */
833 struct kboard_stack
*next
;
836 static struct kboard_stack
*kboard_stack
;
839 push_frame_kboard (f
)
843 struct kboard_stack
*p
844 = (struct kboard_stack
*) xmalloc (sizeof (struct kboard_stack
));
846 p
->next
= kboard_stack
;
847 p
->kboard
= current_kboard
;
850 current_kboard
= FRAME_KBOARD (f
);
858 struct kboard_stack
*p
= kboard_stack
;
859 current_kboard
= p
->kboard
;
860 kboard_stack
= p
->next
;
865 /* Handle errors that are not handled at inner levels
866 by printing an error message and returning to the editor command loop. */
872 Lisp_Object old_level
, old_length
;
874 Vstandard_output
= Qt
;
875 Vstandard_input
= Qt
;
876 Vexecuting_macro
= Qnil
;
877 current_kboard
->Vprefix_arg
= Qnil
;
880 /* Avoid unquittable loop if data contains a circular list. */
881 old_level
= Vprint_level
;
882 old_length
= Vprint_length
;
883 XSETFASTINT (Vprint_level
, 10);
884 XSETFASTINT (Vprint_length
, 10);
885 cmd_error_internal (data
, NULL
);
886 Vprint_level
= old_level
;
887 Vprint_length
= old_length
;
891 Vinhibit_quit
= Qnil
;
896 return make_number (0);
899 cmd_error_internal (data
, context
)
903 Lisp_Object errmsg
, tail
, errname
, file_error
;
910 echo_area_glyphs
= 0;
912 /* If the window system or terminal frame hasn't been initialized
913 yet, or we're not interactive, it's best to dump this message out
914 to stderr and exit. */
915 if (! FRAME_MESSAGE_BUF (selected_frame
)
917 stream
= Qexternal_debugging_output
;
926 write_string_1 (context
, -1, stream
);
928 errname
= Fcar (data
);
930 if (EQ (errname
, Qerror
))
933 if (!CONSP (data
)) data
= Qnil
;
934 errmsg
= Fcar (data
);
939 errmsg
= Fget (errname
, Qerror_message
);
940 file_error
= Fmemq (Qfile_error
,
941 Fget (errname
, Qerror_conditions
));
944 /* Print an error message including the data items.
945 This is done by printing it into a scratch buffer
946 and then making a copy of the text in the buffer. */
948 if (!CONSP (data
)) data
= Qnil
;
952 /* For file-error, make error message by concatenating
953 all the data items. They are all strings. */
954 if (!NILP (file_error
) && !NILP (tail
))
955 errmsg
= XCONS (tail
)->car
, tail
= XCONS (tail
)->cdr
;
957 if (STRINGP (errmsg
))
958 Fprinc (errmsg
, stream
);
960 write_string_1 ("peculiar error", -1, stream
);
962 for (i
= 0; CONSP (tail
); tail
= Fcdr (tail
), i
++)
964 write_string_1 (i
? ", " : ": ", 2, stream
);
965 if (!NILP (file_error
))
966 Fprinc (Fcar (tail
), stream
);
968 Fprin1 (Fcar (tail
), stream
);
972 /* If the window system or terminal frame hasn't been initialized
973 yet, or we're in -batch mode, this error should cause Emacs to exit. */
974 if (! FRAME_MESSAGE_BUF (selected_frame
)
978 Fkill_emacs (make_number (-1));
982 Lisp_Object
command_loop_1 ();
983 Lisp_Object
command_loop_2 ();
984 Lisp_Object
top_level_1 ();
986 /* Entry to editor-command-loop.
987 This level has the catches for exiting/returning to editor command loop.
988 It returns nil to exit recursive edit, t to abort it. */
993 if (command_loop_level
> 0 || minibuf_level
> 0)
995 return internal_catch (Qexit
, command_loop_2
, Qnil
);
1000 internal_catch (Qtop_level
, top_level_1
, Qnil
);
1001 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
1003 /* End of file in -batch run causes exit here. */
1009 /* Here we catch errors in execution of commands within the
1010 editing loop, and reenter the editing loop.
1011 When there is an error, cmd_error runs and returns a non-nil
1012 value to us. A value of nil means that cmd_loop_1 itself
1013 returned due to end of file (or end of kbd macro). */
1018 register Lisp_Object val
;
1021 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
1022 while (!NILP (val
));
1030 return Feval (Vtop_level
);
1036 /* On entry to the outer level, run the startup file */
1037 if (!NILP (Vtop_level
))
1038 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
1039 else if (!NILP (Vpurify_flag
))
1040 message ("Bare impure Emacs (standard Lisp code not loaded)");
1042 message ("Bare Emacs (standard Lisp code not loaded)");
1046 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
1047 "Exit all recursive editing levels.")
1050 Fthrow (Qtop_level
, Qnil
);
1053 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
1054 "Exit from the innermost recursive edit or minibuffer.")
1057 if (command_loop_level
> 0 || minibuf_level
> 0)
1058 Fthrow (Qexit
, Qnil
);
1060 error ("No recursive edit is in progress");
1063 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
1064 "Abort the command that requested this recursive edit or minibuffer input.")
1067 if (command_loop_level
> 0 || minibuf_level
> 0)
1070 error ("No recursive edit is in progress");
1073 /* This is the actual command reading loop,
1074 sans error-handling encapsulation. */
1076 Lisp_Object
Fcommand_execute ();
1077 static int read_key_sequence ();
1078 void safe_run_hooks ();
1083 Lisp_Object cmd
, tem
;
1086 Lisp_Object keybuf
[30];
1091 struct buffer
*prev_buffer
;
1093 int was_locked
= single_kboard
;
1096 current_kboard
->Vprefix_arg
= Qnil
;
1097 Vdeactivate_mark
= Qnil
;
1098 waiting_for_input
= 0;
1103 this_command_key_count
= 0;
1105 /* Make sure this hook runs after commands that get errors and
1106 throw to top level. */
1107 /* Note that the value cell will never directly contain nil
1108 if the symbol is a local variable. */
1109 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1110 safe_run_hooks (Qpost_command_hook
);
1112 if (!NILP (Vdeferred_action_list
))
1113 call0 (Vdeferred_action_function
);
1115 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1117 if (NILP (Vunread_command_events
)
1118 && NILP (Vexecuting_macro
)
1119 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1)))
1120 safe_run_hooks (Qpost_command_idle_hook
);
1123 /* Do this after running Vpost_command_hook, for consistency. */
1124 current_kboard
->Vlast_command
= this_command
;
1128 /* Make sure the current window's buffer is selected. */
1129 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1130 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1132 /* Display any malloc warning that just came out. Use while because
1133 displaying one warning can cause another. */
1135 while (pending_malloc_warning
)
1136 display_malloc_warning ();
1140 Vdeactivate_mark
= Qnil
;
1142 /* If minibuffer on and echo area in use,
1143 wait 2 sec and redraw minibuffer. */
1145 if (minibuf_level
&& echo_area_glyphs
1146 && EQ (minibuf_window
, echo_area_window
))
1148 /* Bind inhibit-quit to t so that C-g gets read in
1149 rather than quitting back to the minibuffer. */
1150 int count
= specpdl_ptr
- specpdl
;
1151 specbind (Qinhibit_quit
, Qt
);
1152 Fsit_for (make_number (2), Qnil
, Qnil
);
1153 unbind_to (count
, Qnil
);
1155 echo_area_glyphs
= 0;
1157 if (!NILP (Vquit_flag
))
1160 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1165 alloca (0); /* Cause a garbage collection now */
1166 /* Since we can free the most stuff here. */
1167 #endif /* C_ALLOCA */
1171 /* Select the frame that the last event came from. Usually,
1172 switch-frame events will take care of this, but if some lisp
1173 code swallows a switch-frame event, we'll fix things up here.
1174 Is this a good idea? */
1175 if (FRAMEP (internal_last_event_frame
)
1176 && XFRAME (internal_last_event_frame
) != selected_frame
)
1177 Fselect_frame (internal_last_event_frame
, Qnil
);
1180 /* If it has changed current-menubar from previous value,
1181 really recompute the menubar from the value. */
1182 if (! NILP (Vlucid_menu_bar_dirty_flag
)
1183 && !NILP (Ffboundp (Qrecompute_lucid_menubar
)))
1184 call0 (Qrecompute_lucid_menubar
);
1186 before_command_key_count
= this_command_key_count
;
1187 before_command_echo_length
= echo_length ();
1189 this_command
= Qnil
;
1191 /* Read next key sequence; i gets its length. */
1192 i
= read_key_sequence (keybuf
, sizeof keybuf
/ sizeof keybuf
[0],
1197 /* Now we have read a key sequence of length I,
1198 or else I is 0 and we found end of file. */
1200 if (i
== 0) /* End of file -- happens only in */
1201 return Qnil
; /* a kbd macro, at the end. */
1202 /* -1 means read_key_sequence got a menu that was rejected.
1203 Just loop around and read another command. */
1207 this_command_key_count
= 0;
1211 last_command_char
= keybuf
[i
- 1];
1213 /* If the previous command tried to force a specific window-start,
1214 forget about that, in case this command moves point far away
1215 from that position. But also throw away beg_unchanged and
1216 end_unchanged information in that case, so that redisplay will
1217 update the whole window properly. */
1218 if (!NILP (XWINDOW (selected_window
)->force_start
))
1220 XWINDOW (selected_window
)->force_start
= Qnil
;
1221 beg_unchanged
= end_unchanged
= 0;
1224 cmd
= read_key_sequence_cmd
;
1225 if (!NILP (Vexecuting_macro
))
1227 if (!NILP (Vquit_flag
))
1229 Vexecuting_macro
= Qt
;
1230 QUIT
; /* Make some noise. */
1231 /* Will return since macro now empty. */
1235 /* Do redisplay processing after this command except in special
1236 cases identified below that set no_redisplay to 1.
1237 (actually, there's currently no way to prevent the redisplay,
1238 and no_redisplay is ignored.
1239 Perhaps someday we will really implement it.) */
1242 prev_buffer
= current_buffer
;
1243 prev_modiff
= MODIFF
;
1244 last_point_position
= PT
;
1245 XSETBUFFER (last_point_position_buffer
, prev_buffer
);
1247 /* Execute the command. */
1250 /* Note that the value cell will never directly contain nil
1251 if the symbol is a local variable. */
1252 if (!NILP (Vpre_command_hook
) && !NILP (Vrun_hooks
))
1253 safe_run_hooks (Qpre_command_hook
);
1255 if (NILP (this_command
))
1257 /* nil means key is undefined. */
1259 current_kboard
->defining_kbd_macro
= Qnil
;
1260 update_mode_lines
= 1;
1261 current_kboard
->Vprefix_arg
= Qnil
;
1265 if (NILP (current_kboard
->Vprefix_arg
) && ! no_direct
)
1267 /* Recognize some common commands in common situations and
1268 do them directly. */
1269 if (EQ (this_command
, Qforward_char
) && PT
< ZV
)
1271 struct Lisp_Char_Table
*dp
1272 = window_display_table (XWINDOW (selected_window
));
1273 lose
= FETCH_CHAR (PT
);
1276 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1277 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1278 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1279 && (lose
>= 0x20 && lose
< 0x7f)))
1280 : (lose
>= 0x20 && lose
< 0x7f))
1281 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1283 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1285 && !windows_or_buffers_changed
1286 && EQ (current_buffer
->selective_display
, Qnil
)
1287 && !detect_input_pending ()
1288 && NILP (Vcolumn_number_mode
)
1289 && NILP (Vexecuting_macro
))
1290 no_redisplay
= direct_output_forward_char (1);
1293 else if (EQ (this_command
, Qbackward_char
) && PT
> BEGV
)
1295 struct Lisp_Char_Table
*dp
1296 = window_display_table (XWINDOW (selected_window
));
1298 lose
= FETCH_CHAR (PT
);
1300 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1301 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1302 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1303 && (lose
>= 0x20 && lose
< 0x7f)))
1304 : (lose
>= 0x20 && lose
< 0x7f))
1305 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1307 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1309 && !windows_or_buffers_changed
1310 && EQ (current_buffer
->selective_display
, Qnil
)
1311 && !detect_input_pending ()
1312 && NILP (Vcolumn_number_mode
)
1313 && NILP (Vexecuting_macro
))
1314 no_redisplay
= direct_output_forward_char (-1);
1317 else if (EQ (this_command
, Qself_insert_command
)
1318 /* Try this optimization only on ascii keystrokes. */
1319 && INTEGERP (last_command_char
))
1321 unsigned char c
= XINT (last_command_char
);
1324 if (NILP (Vexecuting_macro
)
1325 && !EQ (minibuf_window
, selected_window
))
1327 if (!nonundocount
|| nonundocount
>= 20)
1334 lose
= ((XFASTINT (XWINDOW (selected_window
)->last_modified
)
1336 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1338 || MODIFF
<= SAVE_MODIFF
1339 || windows_or_buffers_changed
1340 || !EQ (current_buffer
->selective_display
, Qnil
)
1341 || detect_input_pending ()
1342 || !NILP (Vcolumn_number_mode
)
1343 || !NILP (Vexecuting_macro
));
1344 value
= internal_self_insert (c
, 0);
1351 && (PT
== ZV
|| FETCH_CHAR (PT
) == '\n'))
1353 struct Lisp_Char_Table
*dp
1354 = window_display_table (XWINDOW (selected_window
));
1361 obj
= DISP_CHAR_VECTOR (dp
, lose
);
1364 /* Do it only for char codes
1365 that by default display as themselves. */
1366 if (lose
>= 0x20 && lose
<= 0x7e)
1367 no_redisplay
= direct_output_for_insert (lose
);
1369 else if (VECTORP (obj
)
1370 && XVECTOR (obj
)->size
== 1
1371 && (obj
= XVECTOR (obj
)->contents
[0],
1373 /* Insist face not specified in glyph. */
1374 && (XINT (obj
) & ((-1) << 8)) == 0)
1376 = direct_output_for_insert (XINT (obj
));
1380 if (lose
>= 0x20 && lose
<= 0x7e)
1381 no_redisplay
= direct_output_for_insert (lose
);
1388 /* Here for a command that isn't executed directly */
1391 if (NILP (current_kboard
->Vprefix_arg
))
1393 Fcommand_execute (this_command
, Qnil
, Qnil
);
1398 /* Note that the value cell will never directly contain nil
1399 if the symbol is a local variable. */
1400 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1401 safe_run_hooks (Qpost_command_hook
);
1403 if (!NILP (Vdeferred_action_list
))
1404 safe_run_hooks (Qdeferred_action_function
);
1406 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1408 if (NILP (Vunread_command_events
)
1409 && NILP (Vexecuting_macro
)
1410 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1)))
1411 safe_run_hooks (Qpost_command_idle_hook
);
1414 /* If there is a prefix argument,
1415 1) We don't want Vlast_command to be ``universal-argument''
1416 (that would be dumb), so don't set Vlast_command,
1417 2) we want to leave echoing on so that the prefix will be
1418 echoed as part of this key sequence, so don't call
1420 3) we want to leave this_command_key_count non-zero, so that
1421 read_char will realize that it is re-reading a character, and
1422 not echo it a second time.
1424 If the command didn't actually create a prefix arg,
1425 but is merely a frame event that is transparent to prefix args,
1426 then the above doesn't apply. */
1427 if (NILP (current_kboard
->Vprefix_arg
) || CONSP (last_command_char
))
1429 current_kboard
->Vlast_command
= this_command
;
1431 this_command_key_count
= 0;
1434 if (!NILP (current_buffer
->mark_active
) && !NILP (Vrun_hooks
))
1436 if (!NILP (Vdeactivate_mark
) && !NILP (Vtransient_mark_mode
))
1438 current_buffer
->mark_active
= Qnil
;
1439 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
1441 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
1442 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
1446 /* Install chars successfully executed in kbd macro. */
1448 if (!NILP (current_kboard
->defining_kbd_macro
)
1449 && NILP (current_kboard
->Vprefix_arg
))
1450 finalize_kbd_macro_chars ();
1454 any_kboard_state ();
1459 /* Subroutine for safe_run_hooks: run the hook HOOK. */
1462 safe_run_hooks_1 (hook
)
1465 return call1 (Vrun_hooks
, Vinhibit_quit
);
1468 /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */
1471 safe_run_hooks_error (data
)
1474 Fset (Vinhibit_quit
, Qnil
);
1477 /* If we get an error while running the hook, cause the hook variable
1478 to be nil. Also inhibit quits, so that C-g won't cause the hook
1479 to mysteriously evaporate. */
1482 safe_run_hooks (hook
)
1486 int count
= specpdl_ptr
- specpdl
;
1487 specbind (Qinhibit_quit
, hook
);
1489 internal_condition_case (safe_run_hooks_1
, Qerror
, safe_run_hooks_error
);
1491 unbind_to (count
, Qnil
);
1494 /* Number of seconds between polling for input. */
1497 /* Nonzero means polling for input is temporarily suppressed. */
1498 int poll_suppress_count
;
1500 /* Nonzero if polling_for_input is actually being used. */
1501 int polling_for_input
;
1503 #ifdef POLL_FOR_INPUT
1505 /* Handle an alarm once each second and read pending input
1506 so as to handle a C-g if it comces in. */
1509 input_poll_signal (signalnum
) /* If we don't have an argument, */
1510 int signalnum
; /* some compilers complain in signal calls. */
1512 if (interrupt_input_blocked
== 0
1513 && !waiting_for_input
)
1514 read_avail_input (0);
1515 signal (SIGALRM
, input_poll_signal
);
1516 alarm (polling_period
);
1521 /* Begin signals to poll for input, if they are appropriate.
1522 This function is called unconditionally from various places. */
1526 #ifdef POLL_FOR_INPUT
1527 if (read_socket_hook
&& !interrupt_input
)
1529 poll_suppress_count
--;
1530 if (poll_suppress_count
== 0)
1532 signal (SIGALRM
, input_poll_signal
);
1533 polling_for_input
= 1;
1534 alarm (polling_period
);
1540 /* Nonzero if we are using polling to handle input asynchronously. */
1543 input_polling_used ()
1545 #ifdef POLL_FOR_INPUT
1546 return read_socket_hook
&& !interrupt_input
;
1552 /* Turn off polling. */
1556 #ifdef POLL_FOR_INPUT
1557 if (read_socket_hook
&& !interrupt_input
)
1559 if (poll_suppress_count
== 0)
1561 polling_for_input
= 0;
1564 poll_suppress_count
++;
1569 /* Set the value of poll_suppress_count to COUNT
1570 and start or stop polling accordingly. */
1573 set_poll_suppress_count (count
)
1576 #ifdef POLL_FOR_INPUT
1577 if (count
== 0 && poll_suppress_count
!= 0)
1579 poll_suppress_count
= 1;
1582 else if (count
!= 0 && poll_suppress_count
== 0)
1586 poll_suppress_count
= count
;
1590 /* Bind polling_period to a value at least N.
1591 But don't decrease it. */
1593 bind_polling_period (n
)
1596 #ifdef POLL_FOR_INPUT
1597 int new = polling_period
;
1603 specbind (Qpolling_period
, make_number (new));
1604 /* Start a new alarm with the new period. */
1609 /* Apply the control modifier to CHARACTER. */
1615 /* Save the upper bits here. */
1616 int upper
= c
& ~0177;
1620 /* Everything in the columns containing the upper-case letters
1621 denotes a control character. */
1622 if (c
>= 0100 && c
< 0140)
1626 /* Set the shift modifier for a control char
1627 made from a shifted letter. But only for letters! */
1628 if (oc
>= 'A' && oc
<= 'Z')
1629 c
|= shift_modifier
;
1632 /* The lower-case letters denote control characters too. */
1633 else if (c
>= 'a' && c
<= 'z')
1636 /* Include the bits for control and shift
1637 only if the basic ASCII code can't indicate them. */
1641 /* Replace the high bits. */
1642 c
|= (upper
& ~ctrl_modifier
);
1649 /* Input of single characters from keyboard */
1651 Lisp_Object
print_help ();
1652 static Lisp_Object
kbd_buffer_get_event ();
1653 static void record_char ();
1656 static jmp_buf wrong_kboard_jmpbuf
;
1659 /* read a character from the keyboard; call the redisplay if needed */
1660 /* commandflag 0 means do not do auto-saving, but do do redisplay.
1661 -1 means do not do redisplay, but do do autosaving.
1664 /* The arguments MAPS and NMAPS are for menu prompting.
1665 MAPS is an array of keymaps; NMAPS is the length of MAPS.
1667 PREV_EVENT is the previous input event, or nil if we are reading
1668 the first event of a key sequence.
1670 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
1671 if we used a mouse menu to read the input, or zero otherwise. If
1672 USED_MOUSE_MENU is null, we don't dereference it.
1674 Value is t if we showed a menu and the user rejected it. */
1677 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
)
1681 Lisp_Object prev_event
;
1682 int *used_mouse_menu
;
1684 register Lisp_Object c
;
1686 jmp_buf local_getcjmp
;
1688 int key_already_recorded
= 0;
1689 Lisp_Object tem
, save
;
1690 Lisp_Object also_record
;
1693 before_command_key_count
= this_command_key_count
;
1694 before_command_echo_length
= echo_length ();
1698 if (CONSP (Vunread_command_events
))
1700 c
= XCONS (Vunread_command_events
)->car
;
1701 Vunread_command_events
= XCONS (Vunread_command_events
)->cdr
;
1703 if (this_command_key_count
== 0)
1709 if (unread_command_char
!= -1)
1711 XSETINT (c
, unread_command_char
);
1712 unread_command_char
= -1;
1714 if (this_command_key_count
== 0)
1720 /* If there is no function key translated before
1721 reset-this-command-lengths takes effect, forget about it. */
1722 before_command_restore_flag
= 0;
1724 if (!NILP (Vexecuting_macro
))
1727 /* We set this to Qmacro; since that's not a frame, nobody will
1728 try to switch frames on us, and the selected window will
1731 Since this event came from a macro, it would be misleading to
1732 leave internal_last_event_frame set to wherever the last
1733 real event came from. Normally, a switch-frame event selects
1734 internal_last_event_frame after each command is read, but
1735 events read from a macro should never cause a new frame to be
1737 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
1740 /* Exit the macro if we are at the end.
1741 Also, some things replace the macro with t
1742 to force an early exit. */
1743 if (EQ (Vexecuting_macro
, Qt
)
1744 || executing_macro_index
>= XFASTINT (Flength (Vexecuting_macro
)))
1750 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
1751 if (STRINGP (Vexecuting_macro
)
1752 && (XINT (c
) & 0x80))
1753 XSETFASTINT (c
, CHAR_META
| (XINT (c
) & ~0x80));
1755 executing_macro_index
++;
1760 if (!NILP (unread_switch_frame
))
1762 c
= unread_switch_frame
;
1763 unread_switch_frame
= Qnil
;
1765 /* This event should make it into this_command_keys, and get echoed
1766 again, so we go to reread_first, rather than reread. */
1770 if (commandflag
>= 0 && !input_pending
&& !detect_input_pending ())
1773 /* Message turns off echoing unless more keystrokes turn it on again. */
1774 if (echo_area_glyphs
&& *echo_area_glyphs
1775 && echo_area_glyphs
!= current_kboard
->echobuf
1776 && ok_to_echo_at_next_pause
!= echo_area_glyphs
)
1779 /* If already echoing, continue. */
1782 /* Try reading a character via menu prompting in the minibuf.
1783 Try this before the sit-for, because the sit-for
1784 would do the wrong thing if we are supposed to do
1785 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
1786 after a mouse event so don't try a minibuf menu. */
1788 if (nmaps
> 0 && INTERACTIVE
1789 && !NILP (prev_event
) && ! EVENT_HAS_PARAMETERS (prev_event
)
1790 /* Don't bring up a menu if we already have another event. */
1791 && NILP (Vunread_command_events
)
1792 && unread_command_char
< 0
1793 && !detect_input_pending ())
1795 c
= read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
);
1798 key_already_recorded
= 1;
1803 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet.
1804 We will do that below, temporarily for short sections of code,
1805 when appropriate. local_getcjmp must be in effect
1806 around any call to sit_for or kbd_buffer_get_event;
1807 it *must not* be in effect when we call redisplay. */
1809 if (_setjmp (local_getcjmp
))
1811 XSETINT (c
, quit_char
);
1813 XSETFRAME (internal_last_event_frame
, selected_frame
);
1814 Vlast_event_frame
= internal_last_event_frame
;
1816 /* If we report the quit char as an event,
1817 don't do so more than once. */
1818 if (!NILP (Vinhibit_quit
))
1823 KBOARD
*kb
= FRAME_KBOARD (selected_frame
);
1824 if (kb
!= current_kboard
)
1826 Lisp_Object
*tailp
= &kb
->kbd_queue
;
1827 /* We shouldn't get here if we were in single-kboard mode! */
1830 while (CONSP (*tailp
))
1831 tailp
= &XCONS (*tailp
)->cdr
;
1834 *tailp
= Fcons (c
, Qnil
);
1835 kb
->kbd_queue_has_data
= 1;
1836 current_kboard
= kb
;
1837 longjmp (wrong_kboard_jmpbuf
, 1);
1844 /* If in middle of key sequence and minibuffer not active,
1845 start echoing if enough time elapses. */
1847 if (minibuf_level
== 0 && !current_kboard
->immediate_echo
1848 && this_command_key_count
> 0
1850 && echo_keystrokes
> 0
1851 && (echo_area_glyphs
== 0 || *echo_area_glyphs
== 0
1852 || ok_to_echo_at_next_pause
== echo_area_glyphs
))
1856 /* After a mouse event, start echoing right away.
1857 This is because we are probably about to display a menu,
1858 and we don't want to delay before doing so. */
1859 if (EVENT_HAS_PARAMETERS (prev_event
))
1863 save_getcjmp (save_jump
);
1864 restore_getcjmp (local_getcjmp
);
1865 tem0
= sit_for (echo_keystrokes
, 0, 1, 1);
1866 restore_getcjmp (save_jump
);
1872 /* Maybe auto save due to number of keystrokes. */
1874 if (commandflag
!= 0
1875 && auto_save_interval
> 0
1876 && num_nonmacro_input_chars
- last_auto_save
> max (auto_save_interval
, 20)
1877 && !detect_input_pending ())
1879 Fdo_auto_save (Qnil
, Qnil
);
1880 /* Hooks can actually change some buffers in auto save. */
1884 /* Try reading using an X menu.
1885 This is never confused with reading using the minibuf
1886 because the recursive call of read_char in read_char_minibuf_menu_prompt
1887 does not pass on any keymaps. */
1889 if (nmaps
> 0 && INTERACTIVE
1890 && !NILP (prev_event
)
1891 && EVENT_HAS_PARAMETERS (prev_event
)
1892 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
)
1893 /* Don't bring up a menu if we already have another event. */
1894 && NILP (Vunread_command_events
)
1895 && unread_command_char
< 0)
1896 c
= read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
1898 /* Maybe autosave and/or garbage collect due to idleness. */
1900 if (INTERACTIVE
&& NILP (c
))
1902 int delay_level
, buffer_size
;
1904 /* Slow down auto saves logarithmically in size of current buffer,
1905 and garbage collect while we're at it. */
1906 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
1907 last_non_minibuf_size
= Z
- BEG
;
1908 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
1910 while (buffer_size
> 64)
1911 delay_level
++, buffer_size
-= buffer_size
>> 2;
1912 if (delay_level
< 4) delay_level
= 4;
1913 /* delay_level is 4 for files under around 50k, 7 at 100k,
1914 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
1916 /* Auto save if enough time goes by without input. */
1917 if (commandflag
!= 0
1918 && num_nonmacro_input_chars
> last_auto_save
1919 && INTEGERP (Vauto_save_timeout
)
1920 && XINT (Vauto_save_timeout
) > 0)
1923 int delay
= delay_level
* XFASTINT (Vauto_save_timeout
) / 4;
1925 save_getcjmp (save_jump
);
1926 restore_getcjmp (local_getcjmp
);
1927 tem0
= sit_for (delay
, 0, 1, 1);
1928 restore_getcjmp (save_jump
);
1932 Fdo_auto_save (Qnil
, Qnil
);
1934 /* If we have auto-saved and there is still no input
1935 available, garbage collect if there has been enough
1936 consing going on to make it worthwhile. */
1937 if (!detect_input_pending ()
1938 && consing_since_gc
> gc_cons_threshold
/ 2)
1939 Fgarbage_collect ();
1946 /* Read something from current KBOARD's side queue, if possible. */
1950 if (current_kboard
->kbd_queue_has_data
)
1952 if (!CONSP (current_kboard
->kbd_queue
))
1954 c
= XCONS (current_kboard
->kbd_queue
)->car
;
1955 current_kboard
->kbd_queue
1956 = XCONS (current_kboard
->kbd_queue
)->cdr
;
1957 if (NILP (current_kboard
->kbd_queue
))
1958 current_kboard
->kbd_queue_has_data
= 0;
1959 input_pending
= readable_events ();
1961 if (EVENT_HAS_PARAMETERS (c
)
1962 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qswitch_frame
))
1963 internal_last_event_frame
= XCONS (XCONS (c
)->cdr
)->car
;
1964 Vlast_event_frame
= internal_last_event_frame
;
1970 /* If current_kboard's side queue is empty check the other kboards.
1971 If one of them has data that we have not yet seen here,
1972 switch to it and process the data waiting for it.
1974 Note: if the events queued up for another kboard
1975 have already been seen here, and therefore are not a complete command,
1976 the kbd_queue_has_data field is 0, so we skip that kboard here.
1977 That's to avoid an infinite loop switching between kboards here. */
1978 if (NILP (c
) && !single_kboard
)
1981 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
1982 if (kb
->kbd_queue_has_data
)
1984 current_kboard
= kb
;
1985 longjmp (wrong_kboard_jmpbuf
, 1);
1994 /* Finally, we read from the main queue,
1995 and if that gives us something we can't use yet, we put it on the
1996 appropriate side queue and try again. */
2002 /* Actually read a character, waiting if necessary. */
2003 save_getcjmp (save_jump
);
2004 restore_getcjmp (local_getcjmp
);
2005 c
= kbd_buffer_get_event (&kb
, used_mouse_menu
);
2006 restore_getcjmp (save_jump
);
2009 if (! NILP (c
) && (kb
!= current_kboard
))
2011 Lisp_Object
*tailp
= &kb
->kbd_queue
;
2012 while (CONSP (*tailp
))
2013 tailp
= &XCONS (*tailp
)->cdr
;
2016 *tailp
= Fcons (c
, Qnil
);
2017 kb
->kbd_queue_has_data
= 1;
2021 current_kboard
= kb
;
2022 longjmp (wrong_kboard_jmpbuf
, 1);
2027 /* Terminate Emacs in batch mode if at eof. */
2028 if (noninteractive
&& INTEGERP (c
) && XINT (c
) < 0)
2029 Fkill_emacs (make_number (1));
2033 /* Add in any extra modifiers, where appropriate. */
2034 if ((extra_keyboard_modifiers
& CHAR_CTL
)
2035 || ((extra_keyboard_modifiers
& 0177) < ' '
2036 && (extra_keyboard_modifiers
& 0177) != 0))
2037 XSETINT (c
, make_ctrl_char (XINT (c
)));
2039 /* Transfer any other modifier bits directly from
2040 extra_keyboard_modifiers to c. Ignore the actual character code
2041 in the low 16 bits of extra_keyboard_modifiers. */
2042 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
2051 if (commandflag
>= 0
2052 && !input_pending
&& !detect_input_pending ())
2060 /* Buffer switch events are only for internal wakeups
2061 so don't show them to the user. */
2065 if (key_already_recorded
)
2068 /* Process special events within read_char
2069 and loop around to read another event. */
2072 tem
= get_keyelt (access_keymap (get_keymap_1 (Vspecial_event_map
, 0, 0),
2078 last_input_char
= c
;
2079 Fcommand_execute (tem
, Qnil
, Fvector (1, &last_input_char
));
2083 /* Wipe the echo area. */
2084 echo_area_glyphs
= 0;
2086 /* Handle things that only apply to characters. */
2089 /* If kbd_buffer_get_event gave us an EOF, return that. */
2093 if (STRINGP (Vkeyboard_translate_table
)
2094 && XSTRING (Vkeyboard_translate_table
)->size
> XFASTINT (c
))
2095 XSETINT (c
, XSTRING (Vkeyboard_translate_table
)->data
[XFASTINT (c
)]);
2096 else if ((VECTORP (Vkeyboard_translate_table
)
2097 && XVECTOR (Vkeyboard_translate_table
)->size
> XFASTINT (c
))
2098 || CHAR_TABLE_P (Vkeyboard_translate_table
))
2101 d
= Faref (Vkeyboard_translate_table
, c
);
2102 /* nil in keyboard-translate-table means no translation. */
2108 /* If this event is a mouse click in the menu bar,
2109 return just menu-bar for now. Modify the mouse click event
2110 so we won't do this twice, then queue it up. */
2111 if (EVENT_HAS_PARAMETERS (c
)
2112 && CONSP (XCONS (c
)->cdr
)
2113 && CONSP (EVENT_START (c
))
2114 && CONSP (XCONS (EVENT_START (c
))->cdr
))
2118 posn
= POSN_BUFFER_POSN (EVENT_START (c
));
2119 /* Handle menu-bar events:
2120 insert the dummy prefix event `menu-bar'. */
2121 if (EQ (posn
, Qmenu_bar
))
2123 /* Change menu-bar to (menu-bar) as the event "position". */
2124 POSN_BUFFER_POSN (EVENT_START (c
)) = Fcons (posn
, Qnil
);
2127 Vunread_command_events
= Fcons (c
, Vunread_command_events
);
2133 if (! NILP (also_record
))
2134 record_char (also_record
);
2138 before_command_key_count
= this_command_key_count
;
2139 before_command_echo_length
= echo_length ();
2141 /* Don't echo mouse motion events. */
2143 && ! (EVENT_HAS_PARAMETERS (c
)
2144 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
2147 if (! NILP (also_record
))
2148 echo_char (also_record
);
2149 /* Once we reread a character, echoing can happen
2150 the next time we pause to read a new one. */
2151 ok_to_echo_at_next_pause
= echo_area_glyphs
;
2154 /* Record this character as part of the current key. */
2155 add_command_key (c
);
2156 if (! NILP (also_record
))
2157 add_command_key (also_record
);
2159 /* Re-reading in the middle of a command */
2161 last_input_char
= c
;
2164 /* Process the help character specially if enabled */
2165 if (!NILP (Vhelp_form
) && help_char_p (c
))
2168 count
= specpdl_ptr
- specpdl
;
2170 record_unwind_protect (Fset_window_configuration
,
2171 Fcurrent_window_configuration (Qnil
));
2173 tem0
= Feval (Vhelp_form
);
2175 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
2179 c
= read_char (0, 0, 0, Qnil
, 0);
2180 while (BUFFERP (c
));
2181 /* Remove the help from the frame */
2182 unbind_to (count
, Qnil
);
2185 if (EQ (c
, make_number (040)))
2189 c
= read_char (0, 0, 0, Qnil
, 0);
2190 while (BUFFERP (c
));
2197 /* Return 1 if should recognize C as "the help character". */
2205 if (EQ (c
, Vhelp_char
))
2207 for (tail
= Vhelp_event_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
2208 if (EQ (c
, XCONS (tail
)->car
))
2213 /* Record the input event C in various ways. */
2220 XVECTOR (recent_keys
)->contents
[recent_keys_index
] = c
;
2221 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
2222 recent_keys_index
= 0;
2224 /* Write c to the dribble file. If c is a lispy event, write
2225 the event's symbol to the dribble file, in <brackets>. Bleaugh.
2226 If you, dear reader, have a better idea, you've got the source. :-) */
2231 if (XUINT (c
) < 0x100)
2232 putc (XINT (c
), dribble
);
2234 fprintf (dribble
, " 0x%x", (int) XUINT (c
));
2238 Lisp_Object dribblee
;
2240 /* If it's a structured event, take the event header. */
2241 dribblee
= EVENT_HEAD (c
);
2243 if (SYMBOLP (dribblee
))
2245 putc ('<', dribble
);
2246 fwrite (XSYMBOL (dribblee
)->name
->data
, sizeof (char),
2247 XSYMBOL (dribblee
)->name
->size
,
2249 putc ('>', dribble
);
2256 store_kbd_macro_char (c
);
2258 num_nonmacro_input_chars
++;
2265 struct buffer
*old
= current_buffer
;
2266 Fprinc (object
, Qnil
);
2267 set_buffer_internal (XBUFFER (Vstandard_output
));
2268 call0 (intern ("help-mode"));
2269 set_buffer_internal (old
);
2273 /* Copy out or in the info on where C-g should throw to.
2274 This is used when running Lisp code from within get_char,
2275 in case get_char is called recursively.
2276 See read_process_output. */
2281 bcopy (getcjmp
, temp
, sizeof getcjmp
);
2284 restore_getcjmp (temp
)
2287 bcopy (temp
, getcjmp
, sizeof getcjmp
);
2292 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
2293 of this function. */
2296 tracking_off (old_value
)
2297 Lisp_Object old_value
;
2299 do_mouse_tracking
= old_value
;
2300 if (NILP (old_value
))
2302 /* Redisplay may have been preempted because there was input
2303 available, and it assumes it will be called again after the
2304 input has been processed. If the only input available was
2305 the sort that we have just disabled, then we need to call
2307 if (!readable_events ())
2309 redisplay_preserve_echo_area ();
2310 get_input_pending (&input_pending
);
2315 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
2316 "Evaluate BODY with mouse movement events enabled.\n\
2317 Within a `track-mouse' form, mouse motion generates input events that\n\
2318 you can read with `read-event'.\n\
2319 Normally, mouse motion is ignored.")
2323 int count
= specpdl_ptr
- specpdl
;
2326 record_unwind_protect (tracking_off
, do_mouse_tracking
);
2328 do_mouse_tracking
= Qt
;
2330 val
= Fprogn (args
);
2331 return unbind_to (count
, val
);
2334 /* If mouse has moved on some frame, return one of those frames.
2335 Return 0 otherwise. */
2340 Lisp_Object tail
, frame
;
2342 FOR_EACH_FRAME (tail
, frame
)
2344 if (XFRAME (frame
)->mouse_moved
)
2345 return XFRAME (frame
);
2351 #endif /* HAVE_MOUSE */
2353 /* Low level keyboard/mouse input.
2354 kbd_buffer_store_event places events in kbd_buffer, and
2355 kbd_buffer_get_event retrieves them. */
2357 /* Return true iff there are any events in the queue that read-char
2358 would return. If this returns false, a read-char would block. */
2362 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2365 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2370 if (current_kboard
->kbd_queue_has_data
)
2376 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2377 if (kb
->kbd_queue_has_data
)
2383 /* Set this for debugging, to have a way to get out */
2388 event_to_kboard (event
)
2389 struct input_event
*event
;
2392 frame
= event
->frame_or_window
;
2394 frame
= XCONS (frame
)->car
;
2395 else if (WINDOWP (frame
))
2396 frame
= WINDOW_FRAME (XWINDOW (frame
));
2398 /* There are still some events that don't set this field.
2399 For now, just ignore the problem.
2400 Also ignore dead frames here. */
2401 if (!FRAMEP (frame
) || !FRAME_LIVE_P (XFRAME (frame
)))
2404 return FRAME_KBOARD (XFRAME (frame
));
2408 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
2411 kbd_buffer_store_event (event
)
2412 register struct input_event
*event
;
2414 if (event
->kind
== no_event
)
2417 if (event
->kind
== ascii_keystroke
)
2419 register int c
= event
->code
& 0377;
2421 if (event
->modifiers
& ctrl_modifier
)
2422 c
= make_ctrl_char (c
);
2424 c
|= (event
->modifiers
2425 & (meta_modifier
| alt_modifier
2426 | hyper_modifier
| super_modifier
));
2430 extern SIGTYPE
interrupt_signal ();
2433 struct input_event
*sp
;
2436 && (kb
= FRAME_KBOARD (XFRAME (event
->frame_or_window
)),
2437 kb
!= current_kboard
))
2440 = Fcons (make_lispy_switch_frame (event
->frame_or_window
),
2441 Fcons (make_number (c
), Qnil
));
2442 kb
->kbd_queue_has_data
= 1;
2443 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
2445 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
2448 if (event_to_kboard (sp
) == kb
)
2450 sp
->kind
= no_event
;
2451 sp
->frame_or_window
= Qnil
;
2459 /* If this results in a quit_char being returned to Emacs as
2460 input, set Vlast_event_frame properly. If this doesn't
2461 get returned to Emacs as an event, the next event read
2462 will set Vlast_event_frame again, so this is safe to do. */
2466 focus
= FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
2468 focus
= event
->frame_or_window
;
2469 internal_last_event_frame
= focus
;
2470 Vlast_event_frame
= focus
;
2474 last_event_timestamp
= event
->timestamp
;
2475 interrupt_signal ();
2479 if (c
&& c
== stop_character
)
2485 /* Don't insert two buffer_switch_event's in a row.
2486 Just ignore the second one. */
2487 else if (event
->kind
== buffer_switch_event
2488 && kbd_fetch_ptr
!= kbd_store_ptr
2489 && kbd_store_ptr
->kind
== buffer_switch_event
)
2492 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
2493 kbd_store_ptr
= kbd_buffer
;
2495 /* Don't let the very last slot in the buffer become full,
2496 since that would make the two pointers equal,
2497 and that is indistinguishable from an empty buffer.
2498 Discard the event if it would fill the last slot. */
2499 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
2501 volatile struct input_event
*sp
= kbd_store_ptr
;
2502 sp
->kind
= event
->kind
;
2503 if (event
->kind
== selection_request_event
)
2505 /* We must not use the ordinary copying code for this case,
2506 since `part' is an enum and copying it might not copy enough
2508 bcopy (event
, (char *) sp
, sizeof (*event
));
2512 sp
->code
= event
->code
;
2513 sp
->part
= event
->part
;
2514 sp
->frame_or_window
= event
->frame_or_window
;
2515 sp
->modifiers
= event
->modifiers
;
2518 sp
->timestamp
= event
->timestamp
;
2520 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_store_ptr
2522 = event
->frame_or_window
);
2528 /* Read one event from the event buffer, waiting if necessary.
2529 The value is a Lisp object representing the event.
2530 The value is nil for an event that should be ignored,
2531 or that was handled here.
2532 We always read and discard one event. */
2535 kbd_buffer_get_event (kbp
, used_mouse_menu
)
2537 int *used_mouse_menu
;
2546 *kbp
= current_kboard
;
2550 /* Wait until there is input available. */
2553 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2556 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2560 /* If the quit flag is set, then read_char will return
2561 quit_char, so that counts as "available input." */
2562 if (!NILP (Vquit_flag
))
2563 quit_throw_to_read_char ();
2565 /* One way or another, wait until input is available; then, if
2566 interrupt handlers have not read it, read it now. */
2569 wait_for_kbd_input ();
2571 /* Note SIGIO has been undef'd if FIONREAD is missing. */
2575 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2578 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2582 Lisp_Object minus_one
;
2584 XSETINT (minus_one
, -1);
2585 wait_reading_process_input (0, 0, minus_one
, 1);
2587 if (!interrupt_input
&& kbd_fetch_ptr
== kbd_store_ptr
)
2588 /* Pass 1 for EXPECT since we just waited to have input. */
2589 read_avail_input (1);
2591 #endif /* not VMS */
2594 /* At this point, we know that there is a readable event available
2595 somewhere. If the event queue is empty, then there must be a
2596 mouse movement enabled and available. */
2597 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2599 struct input_event
*event
;
2601 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2605 last_event_timestamp
= event
->timestamp
;
2608 *kbp
= event_to_kboard (event
);
2610 *kbp
= current_kboard
; /* Better than returning null ptr? */
2612 *kbp
= &the_only_kboard
;
2617 /* These two kinds of events get special handling
2618 and don't actually appear to the command loop.
2619 We return nil for them. */
2620 if (event
->kind
== selection_request_event
)
2623 struct input_event copy
;
2625 /* Remove it from the buffer before processing it,
2626 since otherwise swallow_events will see it
2627 and process it again. */
2629 kbd_fetch_ptr
= event
+ 1;
2630 input_pending
= readable_events ();
2631 x_handle_selection_request (©
);
2633 /* We're getting selection request events, but we don't have
2639 else if (event
->kind
== selection_clear_event
)
2642 struct input_event copy
;
2644 /* Remove it from the buffer before processing it. */
2646 kbd_fetch_ptr
= event
+ 1;
2647 input_pending
= readable_events ();
2648 x_handle_selection_clear (©
);
2650 /* We're getting selection request events, but we don't have
2655 #if defined (HAVE_X11) || defined (HAVE_NTGUI)
2656 else if (event
->kind
== delete_window_event
)
2658 /* Make an event (delete-frame (FRAME)). */
2659 obj
= Fcons (event
->frame_or_window
, Qnil
);
2660 obj
= Fcons (Qdelete_frame
, Fcons (obj
, Qnil
));
2661 kbd_fetch_ptr
= event
+ 1;
2663 else if (event
->kind
== iconify_event
)
2665 /* Make an event (iconify-frame (FRAME)). */
2666 obj
= Fcons (event
->frame_or_window
, Qnil
);
2667 obj
= Fcons (Qiconify_frame
, Fcons (obj
, Qnil
));
2668 kbd_fetch_ptr
= event
+ 1;
2670 else if (event
->kind
== deiconify_event
)
2672 /* Make an event (make-frame-visible (FRAME)). */
2673 obj
= Fcons (event
->frame_or_window
, Qnil
);
2674 obj
= Fcons (Qmake_frame_visible
, Fcons (obj
, Qnil
));
2675 kbd_fetch_ptr
= event
+ 1;
2678 else if (event
->kind
== buffer_switch_event
)
2680 /* The value doesn't matter here; only the type is tested. */
2681 XSETBUFFER (obj
, current_buffer
);
2682 kbd_fetch_ptr
= event
+ 1;
2684 #ifdef USE_X_TOOLKIT
2685 else if (event
->kind
== menu_bar_activate_event
)
2687 kbd_fetch_ptr
= event
+ 1;
2688 input_pending
= readable_events ();
2689 x_activate_menubar (XFRAME (event
->frame_or_window
));
2692 /* Just discard these, by returning nil.
2693 With MULTI_KBOARD, these events are used as placeholders
2694 when we need to randomly delete events from the queue.
2695 (They shouldn't otherwise be found in the buffer,
2696 but on some machines it appears they do show up
2697 even without MULTI_KBOARD.) */
2698 else if (event
->kind
== no_event
)
2699 kbd_fetch_ptr
= event
+ 1;
2701 /* If this event is on a different frame, return a switch-frame this
2702 time, and leave the event in the queue for next time. */
2709 frame
= event
->frame_or_window
;
2711 frame
= XCONS (frame
)->car
;
2712 else if (WINDOWP (frame
))
2713 frame
= WINDOW_FRAME (XWINDOW (frame
));
2715 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
2719 if (! EQ (frame
, internal_last_event_frame
)
2720 && XFRAME (frame
) != selected_frame
)
2721 obj
= make_lispy_switch_frame (frame
);
2722 internal_last_event_frame
= frame
;
2723 #endif /* MULTI_FRAME */
2725 /* If we didn't decide to make a switch-frame event, go ahead
2726 and build a real event from the queue entry. */
2730 obj
= make_lispy_event (event
);
2731 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
2732 /* If this was a menu selection, then set the flag to inhibit
2733 writing to last_nonmenu_event. Don't do this if the event
2734 we're returning is (menu-bar), though; that indicates the
2735 beginning of the menu sequence, and we might as well leave
2736 that as the `event with parameters' for this selection. */
2737 if (event
->kind
== menu_bar_event
2738 && !(CONSP (obj
) && EQ (XCONS (obj
)->car
, Qmenu_bar
))
2740 *used_mouse_menu
= 1;
2743 /* Wipe out this event, to catch bugs. */
2744 event
->kind
= no_event
;
2745 XVECTOR (kbd_buffer_frame_or_window
)->contents
[event
- kbd_buffer
] = Qnil
;
2747 kbd_fetch_ptr
= event
+ 1;
2752 /* Try generating a mouse motion event. */
2753 else if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2755 FRAME_PTR f
= some_mouse_moved ();
2756 Lisp_Object bar_window
;
2757 enum scroll_bar_part part
;
2761 *kbp
= current_kboard
;
2762 /* Note that this uses F to determine which display to look at.
2763 If there is no valid info, it does not store anything
2764 so x remains nil. */
2766 (*mouse_position_hook
) (&f
, 0, &bar_window
, &part
, &x
, &y
, &time
);
2771 /* Decide if we should generate a switch-frame event. Don't
2772 generate switch-frame events for motion outside of all Emacs
2778 frame
= FRAME_FOCUS_FRAME (f
);
2780 XSETFRAME (frame
, f
);
2782 if (! EQ (frame
, internal_last_event_frame
)
2783 && XFRAME (frame
) != selected_frame
)
2784 obj
= make_lispy_switch_frame (frame
);
2785 internal_last_event_frame
= frame
;
2789 /* If we didn't decide to make a switch-frame event, go ahead and
2790 return a mouse-motion event. */
2791 if (!NILP (x
) && NILP (obj
))
2792 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
2794 #endif /* HAVE_MOUSE */
2796 /* We were promised by the above while loop that there was
2797 something for us to read! */
2800 input_pending
= readable_events ();
2803 Vlast_event_frame
= internal_last_event_frame
;
2809 /* Process any events that are not user-visible,
2810 then return, without reading any user-visible events. */
2815 while (kbd_fetch_ptr
!= kbd_store_ptr
)
2817 struct input_event
*event
;
2819 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2823 last_event_timestamp
= event
->timestamp
;
2825 /* These two kinds of events get special handling
2826 and don't actually appear to the command loop. */
2827 if (event
->kind
== selection_request_event
)
2830 struct input_event copy
;
2832 /* Remove it from the buffer before processing it,
2833 since otherwise swallow_events called recursively could see it
2834 and process it again. */
2836 kbd_fetch_ptr
= event
+ 1;
2837 input_pending
= readable_events ();
2838 x_handle_selection_request (©
);
2840 /* We're getting selection request events, but we don't have
2846 else if (event
->kind
== selection_clear_event
)
2849 struct input_event copy
;
2851 /* Remove it from the buffer before processing it, */
2854 kbd_fetch_ptr
= event
+ 1;
2855 input_pending
= readable_events ();
2856 x_handle_selection_clear (©
);
2858 /* We're getting selection request events, but we don't have
2867 get_input_pending (&input_pending
);
2870 /* Caches for modify_event_symbol. */
2871 static Lisp_Object accent_key_syms
;
2872 static Lisp_Object func_key_syms
;
2873 static Lisp_Object mouse_syms
;
2875 /* This is a list of keysym codes for special "accent" characters.
2876 It parallels lispy_accent_keys. */
2878 static int lispy_accent_codes
[] =
2880 #ifdef XK_dead_circumflex
2885 #ifdef XK_dead_grave
2890 #ifdef XK_dead_tilde
2895 #ifdef XK_dead_diaeresis
2900 #ifdef XK_dead_macron
2905 #ifdef XK_dead_degree
2910 #ifdef XK_dead_acute
2915 #ifdef XK_dead_cedilla
2920 #ifdef XK_dead_breve
2925 #ifdef XK_dead_ogonek
2930 #ifdef XK_dead_caron
2935 #ifdef XK_dead_doubleacute
2936 XK_dead_doubleacute
,
2940 #ifdef XK_dead_abovedot
2947 /* This is a list of Lisp names for special "accent" characters.
2948 It parallels lispy_accent_codes. */
2950 static char *lispy_accent_keys
[] =
2968 #define FUNCTION_KEY_OFFSET 0x0
2970 char *lispy_function_keys
[] =
2974 0, /* VK_LBUTTON 0x01 */
2975 0, /* VK_RBUTTON 0x02 */
2976 "cancel", /* VK_CANCEL 0x03 */
2977 0, /* VK_MBUTTON 0x04 */
2979 0, 0, 0, /* 0x05 .. 0x07 */
2981 "backspace", /* VK_BACK 0x08 */
2982 "tab", /* VK_TAB 0x09 */
2984 0, 0, /* 0x0A .. 0x0B */
2986 "clear", /* VK_CLEAR 0x0C */
2987 "return", /* VK_RETURN 0x0D */
2989 0, 0, /* 0x0E .. 0x0F */
2991 "shift", /* VK_SHIFT 0x10 */
2992 "control", /* VK_CONTROL 0x11 */
2993 "menu", /* VK_MENU 0x12 */
2994 "pause", /* VK_PAUSE 0x13 */
2995 "capital", /* VK_CAPITAL 0x14 */
2997 0, 0, 0, 0, 0, 0, /* 0x15 .. 0x1A */
2999 0, /* VK_ESCAPE 0x1B */
3001 0, 0, 0, 0, /* 0x1C .. 0x1F */
3003 0, /* VK_SPACE 0x20 */
3004 "prior", /* VK_PRIOR 0x21 */
3005 "next", /* VK_NEXT 0x22 */
3006 "end", /* VK_END 0x23 */
3007 "home", /* VK_HOME 0x24 */
3008 "left", /* VK_LEFT 0x25 */
3009 "up", /* VK_UP 0x26 */
3010 "right", /* VK_RIGHT 0x27 */
3011 "down", /* VK_DOWN 0x28 */
3012 "select", /* VK_SELECT 0x29 */
3013 "print", /* VK_PRINT 0x2A */
3014 "execute", /* VK_EXECUTE 0x2B */
3015 "snapshot", /* VK_SNAPSHOT 0x2C */
3016 "insert", /* VK_INSERT 0x2D */
3017 "delete", /* VK_DELETE 0x2E */
3018 "help", /* VK_HELP 0x2F */
3020 /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
3022 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3024 0, 0, 0, 0, 0, 0, 0, /* 0x3A .. 0x40 */
3026 /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
3028 0, 0, 0, 0, 0, 0, 0, 0, 0,
3029 0, 0, 0, 0, 0, 0, 0, 0, 0,
3030 0, 0, 0, 0, 0, 0, 0, 0,
3032 0, /* VK_LWIN 0x5B */
3033 0, /* VK_RWIN 0x5C */
3034 0, /* VK_APPS 0x5D */
3036 0, 0, /* 0x5E .. 0x5F */
3038 "kp-0", /* VK_NUMPAD0 0x60 */
3039 "kp-1", /* VK_NUMPAD1 0x61 */
3040 "kp-2", /* VK_NUMPAD2 0x62 */
3041 "kp-3", /* VK_NUMPAD3 0x63 */
3042 "kp-4", /* VK_NUMPAD4 0x64 */
3043 "kp-5", /* VK_NUMPAD5 0x65 */
3044 "kp-6", /* VK_NUMPAD6 0x66 */
3045 "kp-7", /* VK_NUMPAD7 0x67 */
3046 "kp-8", /* VK_NUMPAD8 0x68 */
3047 "kp-9", /* VK_NUMPAD9 0x69 */
3048 "kp-multiply", /* VK_MULTIPLY 0x6A */
3049 "kp-add", /* VK_ADD 0x6B */
3050 "kp-separator", /* VK_SEPARATOR 0x6C */
3051 "kp-subtract", /* VK_SUBTRACT 0x6D */
3052 "kp-decimal", /* VK_DECIMAL 0x6E */
3053 "kp-divide", /* VK_DIVIDE 0x6F */
3054 "f1", /* VK_F1 0x70 */
3055 "f2", /* VK_F2 0x71 */
3056 "f3", /* VK_F3 0x72 */
3057 "f4", /* VK_F4 0x73 */
3058 "f5", /* VK_F5 0x74 */
3059 "f6", /* VK_F6 0x75 */
3060 "f7", /* VK_F7 0x76 */
3061 "f8", /* VK_F8 0x77 */
3062 "f9", /* VK_F9 0x78 */
3063 "f10", /* VK_F10 0x79 */
3064 "f11", /* VK_F11 0x7A */
3065 "f12", /* VK_F12 0x7B */
3066 "f13", /* VK_F13 0x7C */
3067 "f14", /* VK_F14 0x7D */
3068 "f15", /* VK_F15 0x7E */
3069 "f16", /* VK_F16 0x7F */
3070 "f17", /* VK_F17 0x80 */
3071 "f18", /* VK_F18 0x81 */
3072 "f19", /* VK_F19 0x82 */
3073 "f20", /* VK_F20 0x83 */
3074 "f21", /* VK_F21 0x84 */
3075 "f22", /* VK_F22 0x85 */
3076 "f23", /* VK_F23 0x86 */
3077 "f24", /* VK_F24 0x87 */
3079 0, 0, 0, 0, /* 0x88 .. 0x8B */
3080 0, 0, 0, 0, /* 0x8C .. 0x8F */
3082 "kp-numlock", /* VK_NUMLOCK 0x90 */
3083 "scroll", /* VK_SCROLL 0x91 */
3085 0, 0, 0, 0, 0, /* 0x92 .. 0x96 */
3086 0, 0, 0, 0, 0, /* 0x97 .. 0x9B */
3087 0, 0, 0, 0, /* 0x9C .. 0x9F */
3090 * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
3091 * Used only as parameters to GetAsyncKeyState() and GetKeyState().
3092 * No other API or message will distinguish left and right keys this way.
3096 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3097 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3098 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3099 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3100 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3106 "attn", /* VK_ATTN 0xF6 */
3107 "crsel", /* VK_CRSEL 0xF7 */
3108 "exsel", /* VK_EXSEL 0xF8 */
3109 "ereof", /* VK_EREOF 0xF9 */
3110 "play", /* VK_PLAY 0xFA */
3111 "zoom", /* VK_ZOOM 0xFB */
3112 "noname", /* VK_NONAME 0xFC */
3113 "pa1", /* VK_PA1 0xFD */
3114 "oem_clear", /* VK_OEM_CLEAR 0xFE */
3119 #define FUNCTION_KEY_OFFSET 0xff00
3121 /* You'll notice that this table is arranged to be conveniently
3122 indexed by X Windows keysym values. */
3123 static char *lispy_function_keys
[] =
3125 /* X Keysym value */
3127 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00 */
3135 0, 0, 0, /* 0xff10 */
3137 0, 0, 0, 0, 0, 0, 0,
3140 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff20...2f */
3141 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff30...3f */
3142 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
3144 "home", /* 0xff50 */ /* IsCursorKey */
3155 "select", /* 0xff60 */ /* IsMiscFunctionKey */
3166 "break", /* 0xff6b */
3168 0, 0, 0, 0, 0, 0, 0, 0, "backtab", 0,
3170 0, 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff7f */
3171 "kp-space", /* 0xff80 */ /* IsKeypadKey */
3172 0, 0, 0, 0, 0, 0, 0, 0,
3173 "kp-tab", /* 0xff89 */
3175 "kp-enter", /* 0xff8d */
3177 "kp-f1", /* 0xff91 */
3181 "kp-home", /* 0xff95 */
3186 "kp-prior", /* kp-page-up */
3187 "kp-next", /* kp-page-down */
3193 0, 0, 0, 0, 0, 0, 0, 0, 0,
3194 "kp-multiply", /* 0xffaa */
3199 "kp-divide", /* 0xffaf */
3200 "kp-0", /* 0xffb0 */
3201 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
3204 "kp-equal", /* 0xffbd */
3205 "f1", /* 0xffbe */ /* IsFunctionKey */
3207 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
3208 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
3209 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
3210 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
3211 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
3212 0, 0, 0, 0, 0, 0, 0, 0,
3213 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
3214 0, 0, 0, 0, 0, 0, 0, "delete"
3217 #endif /* HAVE_NTGUI */
3219 static char *lispy_mouse_names
[] =
3221 "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5"
3224 /* Scroll bar parts. */
3225 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
3227 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
3228 Lisp_Object
*scroll_bar_parts
[] = {
3229 &Qabove_handle
, &Qhandle
, &Qbelow_handle
3233 /* A vector, indexed by button number, giving the down-going location
3234 of currently depressed buttons, both scroll bar and non-scroll bar.
3236 The elements have the form
3237 (BUTTON-NUMBER MODIFIER-MASK . REST)
3238 where REST is the cdr of a position as it would be reported in the event.
3240 The make_lispy_event function stores positions here to tell the
3241 difference between click and drag events, and to store the starting
3242 location to be included in drag events. */
3244 static Lisp_Object button_down_location
;
3246 /* Information about the most recent up-going button event: Which
3247 button, what location, and what time. */
3249 static int last_mouse_button
;
3250 static int last_mouse_x
;
3251 static int last_mouse_y
;
3252 static unsigned long button_down_time
;
3254 /* The maximum time between clicks to make a double-click,
3255 or Qnil to disable double-click detection,
3256 or Qt for no time limit. */
3257 Lisp_Object Vdouble_click_time
;
3259 /* The number of clicks in this multiple-click. */
3261 int double_click_count
;
3263 /* Given a struct input_event, build the lisp event which represents
3264 it. If EVENT is 0, build a mouse movement event from the mouse
3265 movement buffer, which should have a movement event in it.
3267 Note that events must be passed to this function in the order they
3268 are received; this function stores the location of button presses
3269 in order to build drag events when the button is released. */
3272 make_lispy_event (event
)
3273 struct input_event
*event
;
3277 switch (SWITCH_ENUM_CAST (event
->kind
))
3279 /* A simple keystroke. */
3280 case ascii_keystroke
:
3282 Lisp_Object lispy_c
;
3283 int c
= event
->code
& 0377;
3284 /* Turn ASCII characters into control characters
3286 if (event
->modifiers
& ctrl_modifier
)
3287 c
= make_ctrl_char (c
);
3289 /* Add in the other modifier bits. We took care of ctrl_modifier
3290 just above, and the shift key was taken care of by the X code,
3291 and applied to control characters by make_ctrl_char. */
3292 c
|= (event
->modifiers
3293 & (meta_modifier
| alt_modifier
3294 | hyper_modifier
| super_modifier
));
3295 button_down_time
= 0;
3296 XSETFASTINT (lispy_c
, c
);
3300 /* A function key. The symbol may need to have modifier prefixes
3302 case non_ascii_keystroke
:
3303 button_down_time
= 0;
3305 for (i
= 0; i
< sizeof (lispy_accent_codes
) / sizeof (int); i
++)
3306 if (event
->code
== lispy_accent_codes
[i
])
3307 return modify_event_symbol (i
,
3309 Qfunction_key
, Qnil
,
3310 lispy_accent_keys
, &accent_key_syms
,
3311 (sizeof (lispy_accent_keys
)
3312 / sizeof (lispy_accent_keys
[0])));
3314 /* Handle system-specific keysyms. */
3315 if (event
->code
& (1 << 28))
3317 /* We need to use an alist rather than a vector as the cache
3318 since we can't make a vector long enuf. */
3319 if (NILP (current_kboard
->system_key_syms
))
3320 current_kboard
->system_key_syms
= Fcons (Qnil
, Qnil
);
3321 return modify_event_symbol (event
->code
,
3324 current_kboard
->Vsystem_key_alist
,
3325 0, ¤t_kboard
->system_key_syms
,
3329 return modify_event_symbol (event
->code
- FUNCTION_KEY_OFFSET
,
3331 Qfunction_key
, Qnil
,
3332 lispy_function_keys
, &func_key_syms
,
3333 (sizeof (lispy_function_keys
)
3334 / sizeof (lispy_function_keys
[0])));
3338 /* A mouse click. Figure out where it is, decide whether it's
3339 a press, click or drag, and build the appropriate structure. */
3341 case scroll_bar_click
:
3343 int button
= event
->code
;
3345 Lisp_Object position
;
3346 Lisp_Object
*start_pos_ptr
;
3347 Lisp_Object start_pos
;
3349 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
3352 /* Build the position as appropriate for this mouse click. */
3353 if (event
->kind
== mouse_click
)
3356 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
3361 /* Ignore mouse events that were made on frame that
3362 have been deleted. */
3363 if (! FRAME_LIVE_P (f
))
3366 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
3367 &column
, &row
, NULL
, 1);
3369 #ifndef USE_X_TOOLKIT
3370 /* In the non-toolkit version, clicks on the menu bar
3371 are ordinary button events in the event buffer.
3372 Distinguish them, and invoke the menu.
3374 (In the toolkit version, the toolkit handles the menu bar
3375 and Emacs doesn't know about it until after the user
3376 makes a selection.) */
3377 if (row
>= 0 && row
< FRAME_MENU_BAR_LINES (f
)
3378 && (event
->modifiers
& down_modifier
))
3380 Lisp_Object items
, item
;
3385 /* Activate the menu bar on the down event. If the
3386 up event comes in before the menu code can deal with it,
3388 if (! (event
->modifiers
& down_modifier
))
3393 items
= FRAME_MENU_BAR_ITEMS (f
);
3394 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 3)
3396 Lisp_Object pos
, string
;
3397 string
= XVECTOR (items
)->contents
[i
+ 1];
3398 pos
= XVECTOR (items
)->contents
[i
+ 2];
3401 if (column
>= XINT (pos
)
3402 && column
< XINT (pos
) + XSTRING (string
)->size
)
3404 item
= XVECTOR (items
)->contents
[i
];
3410 = Fcons (event
->frame_or_window
,
3412 Fcons (Fcons (event
->x
, event
->y
),
3413 Fcons (make_number (event
->timestamp
),
3416 return Fcons (item
, Fcons (position
, Qnil
));
3418 #endif /* not USE_X_TOOLKIT */
3420 window
= window_from_coordinates (f
, column
, row
, &part
);
3422 if (!WINDOWP (window
))
3424 window
= event
->frame_or_window
;
3429 int pixcolumn
, pixrow
;
3430 column
-= XINT (XWINDOW (window
)->left
);
3431 row
-= XINT (XWINDOW (window
)->top
);
3432 glyph_to_pixel_coords (f
, column
, row
, &pixcolumn
, &pixrow
);
3433 XSETINT (event
->x
, pixcolumn
);
3434 XSETINT (event
->y
, pixrow
);
3439 posn
= Qvertical_line
;
3442 buffer_posn_from_coords (XWINDOW (window
),
3449 Fcons (Fcons (event
->x
, event
->y
),
3450 Fcons (make_number (event
->timestamp
),
3456 Lisp_Object portion_whole
;
3459 window
= event
->frame_or_window
;
3460 portion_whole
= Fcons (event
->x
, event
->y
);
3461 part
= *scroll_bar_parts
[(int) event
->part
];
3465 Fcons (Qvertical_scroll_bar
,
3466 Fcons (portion_whole
,
3467 Fcons (make_number (event
->timestamp
),
3468 Fcons (part
, Qnil
)))));
3471 start_pos_ptr
= &XVECTOR (button_down_location
)->contents
[button
];
3473 start_pos
= *start_pos_ptr
;
3474 *start_pos_ptr
= Qnil
;
3476 is_double
= (button
== last_mouse_button
3477 && XINT (event
->x
) == last_mouse_x
3478 && XINT (event
->y
) == last_mouse_y
3479 && button_down_time
!= 0
3480 && (EQ (Vdouble_click_time
, Qt
)
3481 || (INTEGERP (Vdouble_click_time
)
3482 && ((int)(event
->timestamp
- button_down_time
)
3483 < XINT (Vdouble_click_time
)))));
3484 last_mouse_button
= button
;
3485 last_mouse_x
= XINT (event
->x
);
3486 last_mouse_y
= XINT (event
->y
);
3488 /* If this is a button press, squirrel away the location, so
3489 we can decide later whether it was a click or a drag. */
3490 if (event
->modifiers
& down_modifier
)
3494 double_click_count
++;
3495 event
->modifiers
|= ((double_click_count
> 2)
3500 double_click_count
= 1;
3501 button_down_time
= event
->timestamp
;
3502 *start_pos_ptr
= Fcopy_alist (position
);
3505 /* Now we're releasing a button - check the co-ordinates to
3506 see if this was a click or a drag. */
3507 else if (event
->modifiers
& up_modifier
)
3509 /* If we did not see a down before this up,
3510 ignore the up. Probably this happened because
3511 the down event chose a menu item.
3512 It would be an annoyance to treat the release
3513 of the button that chose the menu item
3514 as a separate event. */
3516 if (!CONSP (start_pos
))
3519 event
->modifiers
&= ~up_modifier
;
3520 #if 0 /* Formerly we treated an up with no down as a click event. */
3521 if (!CONSP (start_pos
))
3522 event
->modifiers
|= click_modifier
;
3526 /* The third element of every position should be the (x,y)
3530 down
= Fnth (make_number (2), start_pos
);
3531 if (EQ (event
->x
, XCONS (down
)->car
)
3532 && EQ (event
->y
, XCONS (down
)->cdr
))
3534 event
->modifiers
|= click_modifier
;
3538 button_down_time
= 0;
3539 event
->modifiers
|= drag_modifier
;
3541 /* Don't check is_double; treat this as multiple
3542 if the down-event was multiple. */
3543 if (double_click_count
> 1)
3544 event
->modifiers
|= ((double_click_count
> 2)
3550 /* Every mouse event should either have the down_modifier or
3551 the up_modifier set. */
3555 /* Get the symbol we should use for the mouse click. */
3558 head
= modify_event_symbol (button
,
3561 lispy_mouse_names
, &mouse_syms
,
3562 (sizeof (lispy_mouse_names
)
3563 / sizeof (lispy_mouse_names
[0])));
3564 if (event
->modifiers
& drag_modifier
)
3569 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
3572 Fcons (make_number (double_click_count
),
3580 #endif /* HAVE_MOUSE */
3582 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
3583 case menu_bar_event
:
3584 /* The event value is in the cdr of the frame_or_window slot. */
3585 if (!CONSP (event
->frame_or_window
))
3587 return XCONS (event
->frame_or_window
)->cdr
;
3590 /* The 'kind' field of the event is something we don't recognize. */
3599 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
3601 Lisp_Object bar_window
;
3602 enum scroll_bar_part part
;
3607 /* Is it a scroll bar movement? */
3608 if (frame
&& ! NILP (bar_window
))
3610 Lisp_Object part_sym
;
3612 part_sym
= *scroll_bar_parts
[(int) part
];
3613 return Fcons (Qscroll_bar_movement
,
3614 (Fcons (Fcons (bar_window
,
3615 Fcons (Qvertical_scroll_bar
,
3616 Fcons (Fcons (x
, y
),
3617 Fcons (make_number (time
),
3623 /* Or is it an ordinary mouse movement? */
3625 #endif /* MULTI_FRAME */
3638 /* It's in a frame; which window on that frame? */
3639 pixel_to_glyph_coords (frame
, XINT (x
), XINT (y
), &column
, &row
,
3641 window
= window_from_coordinates (frame
, column
, row
, &area
);
3646 if (WINDOWP (window
))
3648 int pixcolumn
, pixrow
;
3649 column
-= XINT (XWINDOW (window
)->left
);
3650 row
-= XINT (XWINDOW (window
)->top
);
3651 glyph_to_pixel_coords (frame
, column
, row
, &pixcolumn
, &pixrow
);
3652 XSETINT (x
, pixcolumn
);
3653 XSETINT (y
, pixrow
);
3658 posn
= Qvertical_line
;
3661 buffer_posn_from_coords (XWINDOW (window
), column
, row
));
3664 else if (frame
!= 0)
3666 XSETFRAME (window
, frame
);
3678 return Fcons (Qmouse_movement
,
3679 Fcons (Fcons (window
,
3681 Fcons (Fcons (x
, y
),
3682 Fcons (make_number (time
),
3688 #endif /* HAVE_MOUSE */
3690 /* Construct a switch frame event. */
3692 make_lispy_switch_frame (frame
)
3695 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
3698 /* Manipulating modifiers. */
3700 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
3702 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
3703 SYMBOL's name of the end of the modifiers; the string from this
3704 position is the unmodified symbol name.
3706 This doesn't use any caches. */
3709 parse_modifiers_uncached (symbol
, modifier_end
)
3713 struct Lisp_String
*name
;
3717 CHECK_SYMBOL (symbol
, 1);
3720 name
= XSYMBOL (symbol
)->name
;
3722 for (i
= 0; i
+2 <= name
->size
; )
3724 int this_mod_end
= 0;
3727 /* See if the name continues with a modifier word.
3728 Check that the word appears, but don't check what follows it.
3729 Set this_mod and this_mod_end to record what we find. */
3731 switch (name
->data
[i
])
3733 #define SINGLE_LETTER_MOD(BIT) \
3734 (this_mod_end = i + 1, this_mod = BIT)
3737 SINGLE_LETTER_MOD (alt_modifier
);
3741 SINGLE_LETTER_MOD (ctrl_modifier
);
3745 SINGLE_LETTER_MOD (hyper_modifier
);
3749 SINGLE_LETTER_MOD (meta_modifier
);
3753 SINGLE_LETTER_MOD (shift_modifier
);
3757 SINGLE_LETTER_MOD (super_modifier
);
3760 #undef SINGLE_LETTER_MOD
3763 /* If we found no modifier, stop looking for them. */
3764 if (this_mod_end
== 0)
3767 /* Check there is a dash after the modifier, so that it
3768 really is a modifier. */
3769 if (this_mod_end
>= name
->size
|| name
->data
[this_mod_end
] != '-')
3772 /* This modifier is real; look for another. */
3773 modifiers
|= this_mod
;
3774 i
= this_mod_end
+ 1;
3777 /* Should we include the `click' modifier? */
3778 if (! (modifiers
& (down_modifier
| drag_modifier
3779 | double_modifier
| triple_modifier
))
3780 && i
+ 7 == name
->size
3781 && strncmp (name
->data
+ i
, "mouse-", 6) == 0
3782 && ('0' <= name
->data
[i
+ 6] && name
->data
[i
+ 6] <= '9'))
3783 modifiers
|= click_modifier
;
3791 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
3792 prepended to the string BASE[0..BASE_LEN-1].
3793 This doesn't use any caches. */
3795 apply_modifiers_uncached (modifiers
, base
, base_len
)
3800 /* Since BASE could contain nulls, we can't use intern here; we have
3801 to use Fintern, which expects a genuine Lisp_String, and keeps a
3804 (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
3810 /* Only the event queue may use the `up' modifier; it should always
3811 be turned into a click or drag event before presented to lisp code. */
3812 if (modifiers
& up_modifier
)
3815 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
3816 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
3817 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
3818 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
3819 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
3820 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
3821 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
3822 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
3823 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
3824 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
3825 /* The click modifier is denoted by the absence of other modifiers. */
3829 mod_len
= p
- new_mods
;
3833 Lisp_Object new_name
;
3835 new_name
= make_uninit_string (mod_len
+ base_len
);
3836 bcopy (new_mods
, XSTRING (new_name
)->data
, mod_len
);
3837 bcopy (base
, XSTRING (new_name
)->data
+ mod_len
, base_len
);
3839 return Fintern (new_name
, Qnil
);
3844 static char *modifier_names
[] =
3846 "up", "down", "drag", "click", "double", "triple", 0, 0,
3847 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3848 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
3850 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
3852 static Lisp_Object modifier_symbols
;
3854 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
3856 lispy_modifier_list (modifiers
)
3859 Lisp_Object modifier_list
;
3862 modifier_list
= Qnil
;
3863 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
3864 if (modifiers
& (1<<i
))
3865 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
3868 return modifier_list
;
3872 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
3873 where UNMODIFIED is the unmodified form of SYMBOL,
3874 MASK is the set of modifiers present in SYMBOL's name.
3875 This is similar to parse_modifiers_uncached, but uses the cache in
3876 SYMBOL's Qevent_symbol_element_mask property, and maintains the
3877 Qevent_symbol_elements property. */
3880 parse_modifiers (symbol
)
3883 Lisp_Object elements
;
3885 elements
= Fget (symbol
, Qevent_symbol_element_mask
);
3886 if (CONSP (elements
))
3891 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
3892 Lisp_Object unmodified
;
3895 unmodified
= Fintern (make_string (XSYMBOL (symbol
)->name
->data
+ end
,
3896 XSYMBOL (symbol
)->name
->size
- end
),
3899 if (modifiers
& ~(((EMACS_INT
)1 << VALBITS
) - 1))
3901 XSETFASTINT (mask
, modifiers
);
3902 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
3904 /* Cache the parsing results on SYMBOL. */
3905 Fput (symbol
, Qevent_symbol_element_mask
,
3907 Fput (symbol
, Qevent_symbol_elements
,
3908 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
3910 /* Since we know that SYMBOL is modifiers applied to unmodified,
3911 it would be nice to put that in unmodified's cache.
3912 But we can't, since we're not sure that parse_modifiers is
3919 /* Apply the modifiers MODIFIERS to the symbol BASE.
3920 BASE must be unmodified.
3922 This is like apply_modifiers_uncached, but uses BASE's
3923 Qmodifier_cache property, if present. It also builds
3924 Qevent_symbol_elements properties, since it has that info anyway.
3926 apply_modifiers copies the value of BASE's Qevent_kind property to
3927 the modified symbol. */
3929 apply_modifiers (modifiers
, base
)
3933 Lisp_Object cache
, index
, entry
, new_symbol
;
3935 /* Mask out upper bits. We don't know where this value's been. */
3936 modifiers
&= ((EMACS_INT
)1 << VALBITS
) - 1;
3938 /* The click modifier never figures into cache indices. */
3939 cache
= Fget (base
, Qmodifier_cache
);
3940 XSETFASTINT (index
, (modifiers
& ~click_modifier
));
3941 entry
= assq_no_quit (index
, cache
);
3944 new_symbol
= XCONS (entry
)->cdr
;
3947 /* We have to create the symbol ourselves. */
3948 new_symbol
= apply_modifiers_uncached (modifiers
,
3949 XSYMBOL (base
)->name
->data
,
3950 XSYMBOL (base
)->name
->size
);
3952 /* Add the new symbol to the base's cache. */
3953 entry
= Fcons (index
, new_symbol
);
3954 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
3956 /* We have the parsing info now for free, so add it to the caches. */
3957 XSETFASTINT (index
, modifiers
);
3958 Fput (new_symbol
, Qevent_symbol_element_mask
,
3959 Fcons (base
, Fcons (index
, Qnil
)));
3960 Fput (new_symbol
, Qevent_symbol_elements
,
3961 Fcons (base
, lispy_modifier_list (modifiers
)));
3964 /* Make sure this symbol is of the same kind as BASE.
3966 You'd think we could just set this once and for all when we
3967 intern the symbol above, but reorder_modifiers may call us when
3968 BASE's property isn't set right; we can't assume that just
3969 because it has a Qmodifier_cache property it must have its
3970 Qevent_kind set right as well. */
3971 if (NILP (Fget (new_symbol
, Qevent_kind
)))
3975 kind
= Fget (base
, Qevent_kind
);
3977 Fput (new_symbol
, Qevent_kind
, kind
);
3984 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
3985 return a symbol with the modifiers placed in the canonical order.
3986 Canonical order is alphabetical, except for down and drag, which
3987 always come last. The 'click' modifier is never written out.
3989 Fdefine_key calls this to make sure that (for example) C-M-foo
3990 and M-C-foo end up being equivalent in the keymap. */
3993 reorder_modifiers (symbol
)
3996 /* It's hopefully okay to write the code this way, since everything
3997 will soon be in caches, and no consing will be done at all. */
4000 parsed
= parse_modifiers (symbol
);
4001 return apply_modifiers ((int) XINT (XCONS (XCONS (parsed
)->cdr
)->car
),
4002 XCONS (parsed
)->car
);
4006 /* For handling events, we often want to produce a symbol whose name
4007 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
4008 to some base, like the name of a function key or mouse button.
4009 modify_event_symbol produces symbols of this sort.
4011 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
4012 is the name of the i'th symbol. TABLE_SIZE is the number of elements
4015 Alternatively, NAME_ALIST is an alist mapping codes into symbol names.
4016 NAME_ALIST is used if it is non-nil; otherwise NAME_TABLE is used.
4018 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
4019 persist between calls to modify_event_symbol that it can use to
4020 store a cache of the symbols it's generated for this NAME_TABLE
4021 before. The object stored there may be a vector or an alist.
4023 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
4025 MODIFIERS is a set of modifier bits (as given in struct input_events)
4026 whose prefixes should be applied to the symbol name.
4028 SYMBOL_KIND is the value to be placed in the event_kind property of
4029 the returned symbol.
4031 The symbols we create are supposed to have an
4032 `event-symbol-elements' property, which lists the modifiers present
4033 in the symbol's name. */
4036 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_alist
,
4037 name_table
, symbol_table
, table_size
)
4040 Lisp_Object symbol_kind
;
4041 Lisp_Object name_alist
;
4043 Lisp_Object
*symbol_table
;
4044 unsigned int table_size
;
4047 Lisp_Object symbol_int
;
4049 /* Get rid of the "vendor-specific" bit here. */
4050 XSETINT (symbol_int
, symbol_num
& 0xffffff);
4052 /* Is this a request for a valid symbol? */
4053 if (symbol_num
< 0 || symbol_num
>= table_size
)
4056 if (CONSP (*symbol_table
))
4057 value
= Fcdr (assq_no_quit (symbol_int
, *symbol_table
));
4059 /* If *symbol_table doesn't seem to be initialized properly, fix that.
4060 *symbol_table should be a lisp vector TABLE_SIZE elements long,
4061 where the Nth element is the symbol for NAME_TABLE[N], or nil if
4062 we've never used that symbol before. */
4065 if (! VECTORP (*symbol_table
)
4066 || XVECTOR (*symbol_table
)->size
!= table_size
)
4070 XSETFASTINT (size
, table_size
);
4071 *symbol_table
= Fmake_vector (size
, Qnil
);
4074 value
= XVECTOR (*symbol_table
)->contents
[symbol_num
];
4077 /* Have we already used this symbol before? */
4080 /* No; let's create it. */
4081 if (!NILP (name_alist
))
4082 value
= Fcdr_safe (Fassq (symbol_int
, name_alist
));
4083 else if (name_table
[symbol_num
])
4084 value
= intern (name_table
[symbol_num
]);
4086 #ifdef HAVE_WINDOW_SYSTEM
4089 char *name
= x_get_keysym_name (symbol_num
);
4091 value
= intern (name
);
4098 sprintf (buf
, "key-%d", symbol_num
);
4099 value
= intern (buf
);
4102 if (CONSP (*symbol_table
))
4103 *symbol_table
= Fcons (value
, *symbol_table
);
4105 XVECTOR (*symbol_table
)->contents
[symbol_num
] = value
;
4107 /* Fill in the cache entries for this symbol; this also
4108 builds the Qevent_symbol_elements property, which the user
4110 apply_modifiers (modifiers
& click_modifier
, value
);
4111 Fput (value
, Qevent_kind
, symbol_kind
);
4114 /* Apply modifiers to that symbol. */
4115 return apply_modifiers (modifiers
, value
);
4118 /* Convert a list that represents an event type,
4119 such as (ctrl meta backspace), into the usual representation of that
4120 event type as a number or a symbol. */
4122 DEFUN ("event-convert-list", Fevent_convert_list
, Sevent_convert_list
, 1, 1, 0,
4123 "Convert the event description LIST to an event type.\n\
4124 LIST should contain one base event type (a character or symbol)\n\
4125 and zero or more modifier names (control, meta, hyper, super, shift, alt,\n\
4126 drag, down, double or triple).\n\
4127 The return value is an event type (a character or symbol) which\n\
4128 has the same base event type and all the specified modifiers.")
4138 while (CONSP (rest
))
4143 elt
= XCONS (rest
)->car
;
4145 /* Given a symbol, see if it is a modifier name. */
4147 this = parse_solitary_modifier (elt
);
4151 else if (!NILP (base
))
4152 error ("Two bases given in one event");
4156 rest
= XCONS (rest
)->cdr
;
4159 /* Let the symbol A refer to the character A. */
4160 if (SYMBOLP (base
) && XSYMBOL (base
)->name
->size
== 1)
4161 XSETINT (base
, XSYMBOL (base
)->name
->data
[0]);
4163 if (INTEGERP (base
))
4165 /* Turn (shift a) into A. */
4166 if ((modifiers
& shift_modifier
) != 0
4167 && (XINT (base
) >= 'a' && XINT (base
) <= 'z'))
4169 XSETINT (base
, XINT (base
) - ('a' - 'A'));
4170 modifiers
&= ~shift_modifier
;
4173 /* Turn (control a) into C-a. */
4174 if (modifiers
& ctrl_modifier
)
4175 return make_number ((modifiers
& ~ctrl_modifier
)
4176 | make_ctrl_char (XINT (base
)));
4178 return make_number (modifiers
| XINT (base
));
4180 else if (SYMBOLP (base
))
4181 return apply_modifiers (modifiers
, base
);
4183 error ("Invalid base event");
4186 /* Try to recognize SYMBOL as a modifier name.
4187 Return the modifier flag bit, or 0 if not recognized. */
4190 parse_solitary_modifier (symbol
)
4193 struct Lisp_String
*name
= XSYMBOL (symbol
)->name
;
4195 switch (name
->data
[0])
4197 #define SINGLE_LETTER_MOD(BIT) \
4198 if (name->size == 1) \
4201 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
4202 if (LEN == name->size \
4203 && ! strncmp (name->data, NAME, LEN)) \
4207 SINGLE_LETTER_MOD (alt_modifier
);
4211 MULTI_LETTER_MOD (alt_modifier
, "alt", 3);
4215 SINGLE_LETTER_MOD (ctrl_modifier
);
4219 MULTI_LETTER_MOD (ctrl_modifier
, "ctrl", 4);
4220 MULTI_LETTER_MOD (ctrl_modifier
, "control", 7);
4224 SINGLE_LETTER_MOD (hyper_modifier
);
4228 MULTI_LETTER_MOD (hyper_modifier
, "hyper", 5);
4232 SINGLE_LETTER_MOD (meta_modifier
);
4236 MULTI_LETTER_MOD (meta_modifier
, "meta", 4);
4240 SINGLE_LETTER_MOD (shift_modifier
);
4244 MULTI_LETTER_MOD (shift_modifier
, "shift", 5);
4245 MULTI_LETTER_MOD (super_modifier
, "super", 5);
4246 SINGLE_LETTER_MOD (super_modifier
);
4250 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
4251 MULTI_LETTER_MOD (down_modifier
, "down", 4);
4252 MULTI_LETTER_MOD (double_modifier
, "double", 6);
4256 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
4259 #undef SINGLE_LETTER_MOD
4260 #undef MULTI_LETTER_MOD
4266 /* Return 1 if EVENT is a list whose elements are all integers or symbols.
4267 Such a list is not valid as an event,
4268 but it can be a Lucid-style event type list. */
4271 lucid_event_type_list_p (object
)
4276 if (! CONSP (object
))
4279 for (tail
= object
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4282 elt
= XCONS (tail
)->car
;
4283 if (! (INTEGERP (elt
) || SYMBOLP (elt
)))
4290 /* Store into *addr a value nonzero if terminal input chars are available.
4291 Serves the purpose of ioctl (0, FIONREAD, addr)
4292 but works even if FIONREAD does not exist.
4293 (In fact, this may actually read some input.) */
4296 get_input_pending (addr
)
4299 /* First of all, have we already counted some input? */
4300 *addr
= !NILP (Vquit_flag
) || readable_events ();
4302 /* If input is being read as it arrives, and we have none, there is none. */
4303 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
4306 /* Try to read some input and see how much we get. */
4308 *addr
= !NILP (Vquit_flag
) || readable_events ();
4311 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
4314 gobble_input (expected
)
4319 if (interrupt_input
)
4322 mask
= sigblockx (SIGIO
);
4323 read_avail_input (expected
);
4327 #ifdef POLL_FOR_INPUT
4328 if (read_socket_hook
&& !interrupt_input
&& poll_suppress_count
== 0)
4331 mask
= sigblockx (SIGALRM
);
4332 read_avail_input (expected
);
4338 read_avail_input (expected
);
4342 /* Put a buffer_switch_event in the buffer
4343 so that read_key_sequence will notice the new current buffer. */
4345 record_asynch_buffer_change ()
4347 struct input_event event
;
4350 event
.kind
= buffer_switch_event
;
4351 event
.frame_or_window
= Qnil
;
4354 /* We don't need a buffer-switch event unless Emacs is waiting for input.
4355 The purpose of the event is to make read_key_sequence look up the
4356 keymaps again. If we aren't in read_key_sequence, we don't need one,
4357 and the event could cause trouble by messing up (input-pending-p). */
4358 tem
= Fwaiting_for_user_input_p ();
4362 /* We never need these events if we have no asynchronous subprocesses. */
4366 /* Make sure no interrupt happens while storing the event. */
4368 if (interrupt_input
)
4371 mask
= sigblockx (SIGIO
);
4372 kbd_buffer_store_event (&event
);
4379 kbd_buffer_store_event (&event
);
4386 /* Read any terminal input already buffered up by the system
4387 into the kbd_buffer, but do not wait.
4389 EXPECTED should be nonzero if the caller knows there is some input.
4391 Except on VMS, all input is read by this function.
4392 If interrupt_input is nonzero, this function MUST be called
4393 only when SIGIO is blocked.
4395 Returns the number of keyboard chars read, or -1 meaning
4396 this is a bad time to try to read input. */
4399 read_avail_input (expected
)
4402 struct input_event buf
[KBD_BUFFER_SIZE
];
4406 if (read_socket_hook
)
4407 /* No need for FIONREAD or fcntl; just say don't wait. */
4408 nread
= (*read_socket_hook
) (input_fd
, buf
, KBD_BUFFER_SIZE
,
4409 expected
, expected
);
4412 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
4413 the kbd_buffer can really hold. That may prevent loss
4414 of characters on some systems when input is stuffed at us. */
4415 unsigned char cbuf
[KBD_BUFFER_SIZE
- 1];
4418 /* Determine how many characters we should *try* to read. */
4421 #else /* not WINDOWSNT */
4423 n_to_read
= dos_keysns ();
4426 #else /* not MSDOS */
4428 /* Find out how much input is available. */
4429 if (ioctl (input_fd
, FIONREAD
, &n_to_read
) < 0)
4430 /* Formerly simply reported no input, but that sometimes led to
4431 a failure of Emacs to terminate.
4432 SIGHUP seems appropriate if we can't reach the terminal. */
4433 /* ??? Is it really right to send the signal just to this process
4434 rather than to the whole process group?
4435 Perhaps on systems with FIONREAD Emacs is alone in its group. */
4436 kill (getpid (), SIGHUP
);
4439 if (n_to_read
> sizeof cbuf
)
4440 n_to_read
= sizeof cbuf
;
4441 #else /* no FIONREAD */
4442 #if defined (USG) || defined (DGUX)
4443 /* Read some input if available, but don't wait. */
4444 n_to_read
= sizeof cbuf
;
4445 fcntl (input_fd
, F_SETFL
, O_NDELAY
);
4450 #endif /* not MSDOS */
4451 #endif /* not WINDOWSNT */
4453 /* Now read; for one reason or another, this will not block.
4454 NREAD is set to the number of chars read. */
4458 cbuf
[0] = dos_keyread ();
4461 nread
= read (input_fd
, cbuf
, n_to_read
);
4463 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
4464 /* The kernel sometimes fails to deliver SIGHUP for ptys.
4465 This looks incorrect, but it isn't, because _BSD causes
4466 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
4467 and that causes a value other than 0 when there is no input. */
4473 /* We used to retry the read if it was interrupted.
4474 But this does the wrong thing when O_NDELAY causes
4475 an EAGAIN error. Does anybody know of a situation
4476 where a retry is actually needed? */
4478 nread
< 0 && (errno
== EAGAIN
4492 #if defined (USG) || defined (DGUX)
4493 fcntl (input_fd
, F_SETFL
, 0);
4494 #endif /* USG or DGUX */
4495 #endif /* no FIONREAD */
4496 for (i
= 0; i
< nread
; i
++)
4498 buf
[i
].kind
= ascii_keystroke
;
4499 buf
[i
].modifiers
= 0;
4500 if (meta_key
== 1 && (cbuf
[i
] & 0x80))
4501 buf
[i
].modifiers
= meta_modifier
;
4505 buf
[i
].code
= cbuf
[i
];
4507 XSETFRAME (buf
[i
].frame_or_window
, selected_frame
);
4509 buf
[i
].frame_or_window
= Qnil
;
4514 /* Scan the chars for C-g and store them in kbd_buffer. */
4515 for (i
= 0; i
< nread
; i
++)
4517 kbd_buffer_store_event (&buf
[i
]);
4518 /* Don't look at input that follows a C-g too closely.
4519 This reduces lossage due to autorepeat on C-g. */
4520 if (buf
[i
].kind
== ascii_keystroke
4521 && buf
[i
].code
== quit_char
)
4527 #endif /* not VMS */
4529 #ifdef SIGIO /* for entire page */
4530 /* Note SIGIO has been undef'd if FIONREAD is missing. */
4533 input_available_signal (signo
)
4536 /* Must preserve main program's value of errno. */
4537 int old_errno
= errno
;
4539 extern int select_alarmed
;
4543 /* USG systems forget handlers when they are used;
4544 must reestablish each time */
4545 signal (signo
, input_available_signal
);
4552 if (input_available_clear_time
)
4553 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
4558 nread
= read_avail_input (1);
4559 /* -1 means it's not ok to read the input now.
4560 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
4561 0 means there was no keyboard input available. */
4566 select_alarmed
= 1; /* Force the select emulator back to life */
4577 /* Send ourselves a SIGIO.
4579 This function exists so that the UNBLOCK_INPUT macro in
4580 blockinput.h can have some way to take care of input we put off
4581 dealing with, without assuming that every file which uses
4582 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
4584 reinvoke_input_signal ()
4593 /* Return the prompt-string of a sparse keymap.
4594 This is the first element which is a string.
4595 Return nil if there is none. */
4603 register Lisp_Object tem
;
4612 static void menu_bar_item ();
4613 static void menu_bar_one_keymap ();
4615 /* These variables hold the vector under construction within
4616 menu_bar_items and its subroutines, and the current index
4617 for storing into that vector. */
4618 static Lisp_Object menu_bar_items_vector
;
4619 static int menu_bar_items_index
;
4621 /* Return a vector of menu items for a menu bar, appropriate
4622 to the current buffer. Each item has three elements in the vector:
4625 OLD is an old vector we can optionally reuse, or nil. */
4628 menu_bar_items (old
)
4631 /* The number of keymaps we're scanning right now, and the number of
4632 keymaps we have allocated space for. */
4635 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
4636 in the current keymaps, or nil where it is not a prefix. */
4639 Lisp_Object def
, tem
, tail
;
4648 struct gcpro gcpro1
;
4650 /* In order to build the menus, we need to call the keymap
4651 accessors. They all call QUIT. But this function is called
4652 during redisplay, during which a quit is fatal. So inhibit
4653 quitting while building the menus.
4654 We do this instead of specbind because (1) errors will clear it anyway
4655 and (2) this avoids risk of specpdl overflow. */
4656 oquit
= Vinhibit_quit
;
4660 menu_bar_items_vector
= old
;
4662 menu_bar_items_vector
= Fmake_vector (make_number (24), Qnil
);
4663 menu_bar_items_index
= 0;
4665 GCPRO1 (menu_bar_items_vector
);
4667 /* Build our list of keymaps.
4668 If we recognize a function key and replace its escape sequence in
4669 keybuf with its symbol, or if the sequence starts with a mouse
4670 click and we need to switch buffers, we jump back here to rebuild
4671 the initial keymaps from the current buffer. */
4675 /* Should overriding-terminal-local-map and overriding-local-map apply? */
4676 if (!NILP (Voverriding_local_map_menu_flag
))
4678 /* Yes, use them (if non-nil) as well as the global map. */
4679 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
4681 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
4682 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
4683 if (!NILP (Voverriding_local_map
))
4684 maps
[nmaps
++] = Voverriding_local_map
;
4688 /* No, so use major and minor mode keymaps. */
4689 nmaps
= current_minor_maps (NULL
, &tmaps
);
4690 maps
= (Lisp_Object
*) alloca ((nmaps
+ 2) * sizeof (maps
[0]));
4691 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
4692 #ifdef USE_TEXT_PROPERTIES
4693 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
4695 maps
[nmaps
++] = current_buffer
->keymap
;
4698 maps
[nmaps
++] = current_global_map
;
4701 /* Look up in each map the dummy prefix key `menu-bar'. */
4705 for (mapno
= nmaps
- 1; mapno
>= 0; mapno
--)
4707 if (! NILP (maps
[mapno
]))
4708 def
= get_keyelt (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0));
4712 tem
= Fkeymapp (def
);
4714 menu_bar_one_keymap (def
);
4717 /* Move to the end those items that should be at the end. */
4719 for (tail
= Vmenu_bar_final_items
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4722 int end
= menu_bar_items_index
;
4724 for (i
= 0; i
< end
; i
+= 3)
4725 if (EQ (XCONS (tail
)->car
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
4727 Lisp_Object tem0
, tem1
, tem2
;
4728 /* Move the item at index I to the end,
4729 shifting all the others forward. */
4730 tem0
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 0];
4731 tem1
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 1];
4732 tem2
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
4734 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3],
4735 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
4736 (end
- i
- 3) * sizeof (Lisp_Object
));
4737 XVECTOR (menu_bar_items_vector
)->contents
[end
- 3] = tem0
;
4738 XVECTOR (menu_bar_items_vector
)->contents
[end
- 2] = tem1
;
4739 XVECTOR (menu_bar_items_vector
)->contents
[end
- 1] = tem2
;
4744 /* Add nil, nil, nil at the end. */
4745 i
= menu_bar_items_index
;
4746 if (i
+ 3 > XVECTOR (menu_bar_items_vector
)->size
)
4749 int newsize
= 2 * i
;
4750 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
4751 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
4752 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
4753 menu_bar_items_vector
= tem
;
4755 /* Add this item. */
4756 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
4757 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
4758 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
4759 menu_bar_items_index
= i
;
4761 Vinhibit_quit
= oquit
;
4763 return menu_bar_items_vector
;
4766 /* Scan one map KEYMAP, accumulating any menu items it defines
4767 in menu_bar_items_vector. */
4770 menu_bar_one_keymap (keymap
)
4773 Lisp_Object tail
, item
, key
, binding
, item_string
, table
;
4775 /* Loop over all keymap entries that have menu strings. */
4776 for (tail
= keymap
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4778 item
= XCONS (tail
)->car
;
4781 key
= XCONS (item
)->car
;
4782 binding
= XCONS (item
)->cdr
;
4783 if (CONSP (binding
))
4785 item_string
= XCONS (binding
)->car
;
4786 if (STRINGP (item_string
))
4787 menu_bar_item (key
, item_string
, Fcdr (binding
));
4789 else if (EQ (binding
, Qundefined
))
4790 menu_bar_item (key
, Qnil
, binding
);
4792 else if (VECTORP (item
))
4794 /* Loop over the char values represented in the vector. */
4795 int len
= XVECTOR (item
)->size
;
4797 for (c
= 0; c
< len
; c
++)
4799 Lisp_Object character
;
4800 XSETFASTINT (character
, c
);
4801 binding
= XVECTOR (item
)->contents
[c
];
4802 if (CONSP (binding
))
4804 item_string
= XCONS (binding
)->car
;
4805 if (STRINGP (item_string
))
4806 menu_bar_item (key
, item_string
, Fcdr (binding
));
4808 else if (EQ (binding
, Qundefined
))
4809 menu_bar_item (key
, Qnil
, binding
);
4815 /* This is used as the handler when calling internal_condition_case_1. */
4818 menu_bar_item_1 (arg
)
4824 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
4825 If there's already an item for KEY, add this DEF to it. */
4828 menu_bar_item (key
, item_string
, def
)
4829 Lisp_Object key
, item_string
, def
;
4832 Lisp_Object enabled
;
4835 if (EQ (def
, Qundefined
))
4837 /* If a map has an explicit `undefined' as definition,
4838 discard any previously made menu bar item. */
4840 for (i
= 0; i
< menu_bar_items_index
; i
+= 3)
4841 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
4843 if (menu_bar_items_index
> i
+ 3)
4844 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3],
4845 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
4846 (menu_bar_items_index
- i
- 3) * sizeof (Lisp_Object
));
4847 menu_bar_items_index
-= 3;
4851 /* If there's no definition for this key yet,
4852 just ignore `undefined'. */
4856 /* See if this entry is enabled. */
4861 /* No property, or nil, means enable.
4862 Otherwise, enable if value is not nil. */
4863 tem
= Fget (def
, Qmenu_enable
);
4865 /* (condition-case nil (eval tem)
4867 enabled
= internal_condition_case_1 (Feval
, tem
, Qerror
,
4871 /* Ignore this item if it's not enabled. */
4875 /* Find any existing item for this KEY. */
4876 for (i
= 0; i
< menu_bar_items_index
; i
+= 3)
4877 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
4880 /* If we did not find this KEY, add it at the end. */
4881 if (i
== menu_bar_items_index
)
4883 /* If vector is too small, get a bigger one. */
4884 if (i
+ 3 > XVECTOR (menu_bar_items_vector
)->size
)
4887 int newsize
= 2 * i
;
4888 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
4889 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
4890 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
4891 menu_bar_items_vector
= tem
;
4893 /* Add this item. */
4894 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = key
;
4895 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = item_string
;
4896 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Fcons (def
, Qnil
);
4897 menu_bar_items_index
= i
;
4899 /* We did find an item for this KEY. Add DEF to its list of maps. */
4903 old
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
4904 XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2] = Fcons (def
, old
);
4908 /* Read a character using menus based on maps in the array MAPS.
4909 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
4910 Return t if we displayed a menu but the user rejected it.
4912 PREV_EVENT is the previous input event, or nil if we are reading
4913 the first event of a key sequence.
4915 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
4916 if we used a mouse menu to read the input, or zero otherwise. If
4917 USED_MOUSE_MENU is null, we don't dereference it.
4919 The prompting is done based on the prompt-string of the map
4920 and the strings associated with various map elements.
4922 This can be done with X menus or with menus put in the minibuf.
4923 These are done in different ways, depending on how the input will be read.
4924 Menus using X are done after auto-saving in read-char, getting the input
4925 event from Fx_popup_menu; menus using the minibuf use read_char recursively
4926 and do auto-saving in the inner call of read_char. */
4929 read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
4932 Lisp_Object prev_event
;
4933 int *used_mouse_menu
;
4936 register Lisp_Object name
;
4937 Lisp_Object rest
, vector
;
4939 if (used_mouse_menu
)
4940 *used_mouse_menu
= 0;
4942 /* Use local over global Menu maps */
4944 if (! menu_prompting
)
4947 /* Optionally disregard all but the global map. */
4948 if (inhibit_local_menu_bar_menus
)
4950 maps
+= (nmaps
- 1);
4954 /* Get the menu name from the first map that has one (a prompt string). */
4955 for (mapno
= 0; mapno
< nmaps
; mapno
++)
4957 name
= map_prompt (maps
[mapno
]);
4962 /* If we don't have any menus, just read a character normally. */
4966 #if (defined (HAVE_X_WINDOWS) && defined (HAVE_X_MENU)) || defined (MSDOS) || defined (HAVE_NTGUI)
4967 /* If we got to this point via a mouse click,
4968 use a real menu for mouse selection. */
4969 if (EVENT_HAS_PARAMETERS (prev_event
)
4970 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
))
4972 /* Display the menu and get the selection. */
4973 Lisp_Object
*realmaps
4974 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
4978 /* Use the maps that are not nil. */
4979 for (mapno
= 0; mapno
< nmaps
; mapno
++)
4980 if (!NILP (maps
[mapno
]))
4981 realmaps
[nmaps1
++] = maps
[mapno
];
4983 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
4988 /* If we got multiple events, unread all but
4990 There is no way to prevent those unread events
4991 from showing up later in last_nonmenu_event.
4992 So turn symbol and integer events into lists,
4993 to indicate that they came from a mouse menu,
4994 so that when present in last_nonmenu_event
4995 they won't confuse things. */
4996 for (tem
= XCONS (value
)->cdr
; !NILP (tem
);
4997 tem
= XCONS (tem
)->cdr
)
4998 if (SYMBOLP (XCONS (tem
)->car
)
4999 || INTEGERP (XCONS (tem
)->car
))
5001 = Fcons (XCONS (tem
)->car
, Qnil
);
5003 /* If we got more than one event, put all but the first
5004 onto this list to be read later.
5005 Return just the first event now. */
5006 Vunread_command_events
5007 = nconc2 (XCONS (value
)->cdr
, Vunread_command_events
);
5008 value
= XCONS (value
)->car
;
5010 else if (NILP (value
))
5012 if (used_mouse_menu
)
5013 *used_mouse_menu
= 1;
5016 #endif /* (HAVE_X_WINDOWS && HAVE_X_MENU) || MSDOS || HAVE_NTGUI */
5021 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
5027 register Lisp_Object name
;
5029 int width
= FRAME_WIDTH (selected_frame
) - 4;
5030 char *menu
= (char *) alloca (width
+ 4);
5033 Lisp_Object rest
, vector
;
5035 if (! menu_prompting
)
5038 /* Get the menu name from the first map that has one (a prompt string). */
5039 for (mapno
= 0; mapno
< nmaps
; mapno
++)
5041 name
= map_prompt (maps
[mapno
]);
5046 /* If we don't have any menus, just read a character normally. */
5050 /* Prompt string always starts with map's prompt, and a space. */
5051 strcpy (menu
, XSTRING (name
)->data
);
5052 nlength
= XSTRING (name
)->size
;
5053 menu
[nlength
++] = ':';
5054 menu
[nlength
++] = ' ';
5057 /* Start prompting at start of first map. */
5061 /* Present the documented bindings, a line at a time. */
5068 Lisp_Object orig_defn_macro
;
5070 /* Loop over elements of map. */
5075 /* If reached end of map, start at beginning of next map. */
5079 /* At end of last map, wrap around to first map if just starting,
5080 or end this line if already have something on it. */
5084 if (notfirst
|| nobindings
) break;
5089 /* Look at the next element of the map. */
5091 elt
= XVECTOR (vector
)->contents
[idx
];
5093 elt
= Fcar_safe (rest
);
5095 if (idx
< 0 && VECTORP (elt
))
5097 /* If we found a dense table in the keymap,
5098 advanced past it, but start scanning its contents. */
5099 rest
= Fcdr_safe (rest
);
5105 /* An ordinary element. */
5110 s
= Fcar_safe (Fcdr_safe (elt
)); /* alist */
5111 event
= Fcar_safe (elt
);
5115 s
= Fcar_safe (elt
); /* vector */
5116 XSETINT (event
, idx
);
5119 /* Ignore the element if it has no prompt string. */
5120 if (STRINGP (s
) && INTEGERP (event
))
5122 /* 1 if the char to type matches the string. */
5124 Lisp_Object upcased_event
, downcased_event
;
5127 upcased_event
= Fupcase (event
);
5128 downcased_event
= Fdowncase (event
);
5129 char_matches
= (XINT (upcased_event
) == XSTRING (s
)->data
[0]
5130 || XINT (downcased_event
) == XSTRING (s
)->data
[0]);
5132 desc
= Fsingle_key_description (event
);
5134 /* If we have room for the prompt string, add it to this line.
5135 If this is the first on the line, always add it. */
5136 if ((XSTRING (s
)->size
+ i
+ 2
5137 + (char_matches
? 0 : XSTRING (desc
)->size
+ 3))
5143 /* Punctuate between strings. */
5146 strcpy (menu
+ i
, ", ");
5152 /* If the char to type doesn't match the string's
5153 first char, explicitly show what char to type. */
5156 /* Add as much of string as fits. */
5157 thiswidth
= XSTRING (desc
)->size
;
5158 if (thiswidth
+ i
> width
)
5159 thiswidth
= width
- i
;
5160 bcopy (XSTRING (desc
)->data
, menu
+ i
, thiswidth
);
5162 strcpy (menu
+ i
, " = ");
5166 /* Add as much of string as fits. */
5167 thiswidth
= XSTRING (s
)->size
;
5168 if (thiswidth
+ i
> width
)
5169 thiswidth
= width
- i
;
5170 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
5176 /* If this element does not fit, end the line now,
5177 and save the element for the next line. */
5178 strcpy (menu
+ i
, "...");
5183 /* Move past this element. */
5184 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
5185 /* Handle reaching end of dense table. */
5190 rest
= Fcdr_safe (rest
);
5194 /* Prompt with that and read response. */
5197 /* Make believe its not a keyboard macro in case the help char
5198 is pressed. Help characters are not recorded because menu prompting
5199 is not used on replay.
5201 orig_defn_macro
= current_kboard
->defining_kbd_macro
;
5202 current_kboard
->defining_kbd_macro
= Qnil
;
5204 obj
= read_char (commandflag
, 0, 0, Qnil
, 0);
5205 while (BUFFERP (obj
));
5206 current_kboard
->defining_kbd_macro
= orig_defn_macro
;
5208 if (!INTEGERP (obj
))
5213 if (! EQ (obj
, menu_prompt_more_char
)
5214 && (!INTEGERP (menu_prompt_more_char
)
5215 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
5217 if (!NILP (current_kboard
->defining_kbd_macro
))
5218 store_kbd_macro_char (obj
);
5221 /* Help char - go round again */
5225 /* Reading key sequences. */
5227 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
5228 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
5229 keymap, or nil otherwise. Return the index of the first keymap in
5230 which KEY has any binding, or NMAPS if no map has a binding.
5232 If KEY is a meta ASCII character, treat it like meta-prefix-char
5233 followed by the corresponding non-meta character. Keymaps in
5234 CURRENT with non-prefix bindings for meta-prefix-char become nil in
5237 If KEY has no bindings in any of the CURRENT maps, NEXT is left
5240 NEXT may be the same array as CURRENT. */
5243 follow_key (key
, nmaps
, current
, defs
, next
)
5245 Lisp_Object
*current
, *defs
, *next
;
5248 int i
, first_binding
;
5251 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
5252 followed by the corresponding non-meta character.
5253 Put the results into DEFS, since we are going to alter that anyway.
5254 Do not alter CURRENT or NEXT. */
5255 if (INTEGERP (key
) && (XINT (key
) & CHAR_META
))
5257 for (i
= 0; i
< nmaps
; i
++)
5258 if (! NILP (current
[i
]))
5261 def
= get_keyelt (access_keymap (current
[i
],
5262 meta_prefix_char
, 1, 0));
5264 /* Note that since we pass the resulting bindings through
5265 get_keymap_1, non-prefix bindings for meta-prefix-char
5267 defs
[i
] = get_keymap_1 (def
, 0, 1);
5273 XSETINT (key
, XFASTINT (key
) & ~CHAR_META
);
5276 first_binding
= nmaps
;
5277 for (i
= nmaps
- 1; i
>= 0; i
--)
5279 if (! NILP (current
[i
]))
5287 defs
[i
] = get_keyelt (access_keymap (map
, key
, 1, 0));
5288 if (! NILP (defs
[i
]))
5295 /* Given the set of bindings we've found, produce the next set of maps. */
5296 if (first_binding
< nmaps
)
5297 for (i
= 0; i
< nmaps
; i
++)
5298 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0, 1);
5300 return first_binding
;
5303 /* Read a sequence of keys that ends with a non prefix character,
5304 storing it in KEYBUF, a buffer of size BUFSIZE.
5306 Return the length of the key sequence stored.
5307 Return -1 if the user rejected a command menu.
5309 Echo starting immediately unless `prompt' is 0.
5311 Where a key sequence ends depends on the currently active keymaps.
5312 These include any minor mode keymaps active in the current buffer,
5313 the current buffer's local map, and the global map.
5315 If a key sequence has no other bindings, we check Vfunction_key_map
5316 to see if some trailing subsequence might be the beginning of a
5317 function key's sequence. If so, we try to read the whole function
5318 key, and substitute its symbolic name into the key sequence.
5320 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
5321 `double-' events into similar click events, if that would make them
5322 bound. We try to turn `triple-' events first into `double-' events,
5325 If we get a mouse click in a mode line, vertical divider, or other
5326 non-text area, we treat the click as if it were prefixed by the
5327 symbol denoting that area - `mode-line', `vertical-line', or
5330 If the sequence starts with a mouse click, we read the key sequence
5331 with respect to the buffer clicked on, not the current buffer.
5333 If the user switches frames in the midst of a key sequence, we put
5334 off the switch-frame event until later; the next call to
5335 read_char will return it. */
5338 read_key_sequence (keybuf
, bufsize
, prompt
, dont_downcase_last
,
5339 can_return_switch_frame
)
5340 Lisp_Object
*keybuf
;
5343 int dont_downcase_last
;
5344 int can_return_switch_frame
;
5346 int count
= specpdl_ptr
- specpdl
;
5348 /* How many keys there are in the current key sequence. */
5351 /* The length of the echo buffer when we started reading, and
5352 the length of this_command_keys when we started reading. */
5356 /* The number of keymaps we're scanning right now, and the number of
5357 keymaps we have allocated space for. */
5359 int nmaps_allocated
= 0;
5361 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
5362 the current keymaps. */
5365 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
5366 in the current keymaps, or nil where it is not a prefix. */
5367 Lisp_Object
*submaps
;
5369 /* The local map to start out with at start of key sequence. */
5370 Lisp_Object orig_local_map
;
5372 /* 1 if we have already considered switching to the local-map property
5373 of the place where a mouse click occurred. */
5374 int localized_local_map
= 0;
5376 /* The index in defs[] of the first keymap that has a binding for
5377 this key sequence. In other words, the lowest i such that
5378 defs[i] is non-nil. */
5381 /* If t < mock_input, then KEYBUF[t] should be read as the next
5384 We use this to recover after recognizing a function key. Once we
5385 realize that a suffix of the current key sequence is actually a
5386 function key's escape sequence, we replace the suffix with the
5387 function key's binding from Vfunction_key_map. Now keybuf
5388 contains a new and different key sequence, so the echo area,
5389 this_command_keys, and the submaps and defs arrays are wrong. In
5390 this situation, we set mock_input to t, set t to 0, and jump to
5391 restart_sequence; the loop will read keys from keybuf up until
5392 mock_input, thus rebuilding the state; and then it will resume
5393 reading characters from the keyboard. */
5396 /* If the sequence is unbound in submaps[], then
5397 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
5398 and fkey_map is its binding.
5400 These might be > t, indicating that all function key scanning
5401 should hold off until t reaches them. We do this when we've just
5402 recognized a function key, to avoid searching for the function
5403 key's again in Vfunction_key_map. */
5404 int fkey_start
= 0, fkey_end
= 0;
5405 Lisp_Object fkey_map
;
5407 /* Likewise, for key_translation_map. */
5408 int keytran_start
= 0, keytran_end
= 0;
5409 Lisp_Object keytran_map
;
5411 /* If we receive a ``switch-frame'' event in the middle of a key sequence,
5412 we put it off for later. While we're reading, we keep the event here. */
5413 Lisp_Object delayed_switch_frame
;
5415 /* See the comment below... */
5416 #if defined (GOBBLE_FIRST_EVENT)
5417 Lisp_Object first_event
;
5420 Lisp_Object original_uppercase
;
5421 int original_uppercase_position
= -1;
5423 /* Gets around Microsoft compiler limitations. */
5426 struct buffer
*starting_buffer
;
5428 /* Nonzero if we seem to have got the beginning of a binding
5429 in function_key_map. */
5430 int function_key_possible
= 0;
5431 int key_translation_possible
= 0;
5433 /* Save the status of key translation before each step,
5434 so that we can restore this after downcasing. */
5435 Lisp_Object prev_fkey_map
;
5436 Lisp_Object prev_fkey_start
;
5437 Lisp_Object prev_fkey_end
;
5439 Lisp_Object prev_keytran_map
;
5440 Lisp_Object prev_keytran_start
;
5441 Lisp_Object prev_keytran_end
;
5445 last_nonmenu_event
= Qnil
;
5447 delayed_switch_frame
= Qnil
;
5448 fkey_map
= Vfunction_key_map
;
5449 keytran_map
= Vkey_translation_map
;
5451 /* If there is no function-key-map, turn off function key scanning. */
5452 if (NILP (Fkeymapp (Vfunction_key_map
)))
5453 fkey_start
= fkey_end
= bufsize
+ 1;
5455 /* If there is no key-translation-map, turn off scanning. */
5456 if (NILP (Fkeymapp (Vkey_translation_map
)))
5457 keytran_start
= keytran_end
= bufsize
+ 1;
5462 echo_prompt (XSTRING (prompt
)->data
);
5463 else if (cursor_in_echo_area
&& echo_keystrokes
)
5464 /* This doesn't put in a dash if the echo buffer is empty, so
5465 you don't always see a dash hanging out in the minibuffer. */
5469 /* Record the initial state of the echo area and this_command_keys;
5470 we will need to restore them if we replay a key sequence. */
5472 echo_start
= echo_length ();
5473 keys_start
= this_command_key_count
;
5475 #if defined (GOBBLE_FIRST_EVENT)
5476 /* This doesn't quite work, because some of the things that read_char
5477 does cannot safely be bypassed. It seems too risky to try to make
5480 /* Read the first char of the sequence specially, before setting
5481 up any keymaps, in case a filter runs and switches buffers on us. */
5482 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
5484 #endif /* GOBBLE_FIRST_EVENT */
5486 orig_local_map
= get_local_map (PT
, current_buffer
);
5488 /* We jump here when the key sequence has been thoroughly changed, and
5489 we need to rescan it starting from the beginning. When we jump here,
5490 keybuf[0..mock_input] holds the sequence we should reread. */
5493 starting_buffer
= current_buffer
;
5494 function_key_possible
= 0;
5495 key_translation_possible
= 0;
5497 /* Build our list of keymaps.
5498 If we recognize a function key and replace its escape sequence in
5499 keybuf with its symbol, or if the sequence starts with a mouse
5500 click and we need to switch buffers, we jump back here to rebuild
5501 the initial keymaps from the current buffer. */
5505 if (!NILP (current_kboard
->Voverriding_terminal_local_map
)
5506 || !NILP (Voverriding_local_map
))
5508 if (3 > nmaps_allocated
)
5510 submaps
= (Lisp_Object
*) alloca (3 * sizeof (submaps
[0]));
5511 defs
= (Lisp_Object
*) alloca (3 * sizeof (defs
[0]));
5512 nmaps_allocated
= 3;
5515 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
5516 submaps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
5517 if (!NILP (Voverriding_local_map
))
5518 submaps
[nmaps
++] = Voverriding_local_map
;
5522 nmaps
= current_minor_maps (0, &maps
);
5523 if (nmaps
+ 2 > nmaps_allocated
)
5525 submaps
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (submaps
[0]));
5526 defs
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (defs
[0]));
5527 nmaps_allocated
= nmaps
+ 2;
5529 bcopy (maps
, submaps
, nmaps
* sizeof (submaps
[0]));
5530 #ifdef USE_TEXT_PROPERTIES
5531 submaps
[nmaps
++] = orig_local_map
;
5533 submaps
[nmaps
++] = current_buffer
->keymap
;
5536 submaps
[nmaps
++] = current_global_map
;
5539 /* Find an accurate initial value for first_binding. */
5540 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
5541 if (! NILP (submaps
[first_binding
]))
5544 /* Start from the beginning in keybuf. */
5547 /* These are no-ops the first time through, but if we restart, they
5548 revert the echo area and this_command_keys to their original state. */
5549 this_command_key_count
= keys_start
;
5550 if (INTERACTIVE
&& t
< mock_input
)
5551 echo_truncate (echo_start
);
5553 /* If the best binding for the current key sequence is a keymap, or
5554 we may be looking at a function key's escape sequence, keep on
5556 while ((first_binding
< nmaps
&& ! NILP (submaps
[first_binding
]))
5557 || (first_binding
>= nmaps
5559 /* mock input is never part of a function key's sequence. */
5560 && mock_input
<= fkey_start
)
5561 || (first_binding
>= nmaps
5562 && keytran_start
< t
&& key_translation_possible
)
5563 /* Don't return in the middle of a possible function key sequence,
5564 if the only bindings we found were via case conversion.
5565 Thus, if ESC O a has a function-key-map translation
5566 and ESC o has a binding, don't return after ESC O,
5567 so that we can translate ESC O plus the next character. */
5571 int used_mouse_menu
= 0;
5573 /* Where the last real key started. If we need to throw away a
5574 key that has expanded into more than one element of keybuf
5575 (say, a mouse click on the mode line which is being treated
5576 as [mode-line (mouse-...)], then we backtrack to this point
5578 int last_real_key_start
;
5580 /* These variables are analogous to echo_start and keys_start;
5581 while those allow us to restart the entire key sequence,
5582 echo_local_start and keys_local_start allow us to throw away
5584 int echo_local_start
, keys_local_start
, local_first_binding
;
5587 error ("Key sequence too long");
5590 echo_local_start
= echo_length ();
5591 keys_local_start
= this_command_key_count
;
5592 local_first_binding
= first_binding
;
5595 /* These are no-ops, unless we throw away a keystroke below and
5596 jumped back up to replay_key; in that case, these restore the
5597 variables to their original state, allowing us to replay the
5599 if (INTERACTIVE
&& t
< mock_input
)
5600 echo_truncate (echo_local_start
);
5601 this_command_key_count
= keys_local_start
;
5602 first_binding
= local_first_binding
;
5604 /* By default, assume each event is "real". */
5605 last_real_key_start
= t
;
5607 /* Does mock_input indicate that we are re-reading a key sequence? */
5611 add_command_key (key
);
5612 if (echo_keystrokes
)
5616 /* If not, we should actually read a character. */
5619 struct buffer
*buf
= current_buffer
;
5623 KBOARD
*interrupted_kboard
= current_kboard
;
5624 struct frame
*interrupted_frame
= selected_frame
;
5625 if (setjmp (wrong_kboard_jmpbuf
))
5627 if (!NILP (delayed_switch_frame
))
5629 interrupted_kboard
->kbd_queue
5630 = Fcons (delayed_switch_frame
,
5631 interrupted_kboard
->kbd_queue
);
5632 delayed_switch_frame
= Qnil
;
5635 interrupted_kboard
->kbd_queue
5636 = Fcons (keybuf
[--t
], interrupted_kboard
->kbd_queue
);
5638 /* If the side queue is non-empty, ensure it begins with a
5639 switch-frame, so we'll replay it in the right context. */
5640 if (CONSP (interrupted_kboard
->kbd_queue
)
5641 && (key
= XCONS (interrupted_kboard
->kbd_queue
)->car
,
5642 !(EVENT_HAS_PARAMETERS (key
)
5643 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)),
5647 XSETFRAME (frame
, interrupted_frame
);
5648 interrupted_kboard
->kbd_queue
5649 = Fcons (make_lispy_switch_frame (frame
),
5650 interrupted_kboard
->kbd_queue
);
5653 orig_local_map
= get_local_map (PT
, current_buffer
);
5654 goto replay_sequence
;
5657 key
= read_char (NILP (prompt
), nmaps
, submaps
, last_nonmenu_event
,
5661 /* read_char returns t when it shows a menu and the user rejects it.
5666 /* read_char returns -1 at the end of a macro.
5667 Emacs 18 handles this by returning immediately with a
5668 zero, so that's what we'll do. */
5669 if (INTEGERP (key
) && XINT (key
) == -1)
5672 /* The Microsoft C compiler can't handle the goto that
5678 /* If the current buffer has been changed from under us, the
5679 keymap may have changed, so replay the sequence. */
5683 orig_local_map
= get_local_map (PT
, current_buffer
);
5684 goto replay_sequence
;
5687 /* If we have a quit that was typed in another frame, and
5688 quit_throw_to_read_char switched buffers,
5689 replay to get the right keymap. */
5690 if (XINT (key
) == quit_char
&& current_buffer
!= starting_buffer
)
5695 orig_local_map
= get_local_map (PT
, current_buffer
);
5696 goto replay_sequence
;
5702 /* Clicks in non-text areas get prefixed by the symbol
5703 in their CHAR-ADDRESS field. For example, a click on
5704 the mode line is prefixed by the symbol `mode-line'.
5706 Furthermore, key sequences beginning with mouse clicks
5707 are read using the keymaps of the buffer clicked on, not
5708 the current buffer. So we may have to switch the buffer
5711 When we turn one event into two events, we must make sure
5712 that neither of the two looks like the original--so that,
5713 if we replay the events, they won't be expanded again.
5714 If not for this, such reexpansion could happen either here
5715 or when user programs play with this-command-keys. */
5716 if (EVENT_HAS_PARAMETERS (key
))
5720 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
5721 if (EQ (kind
, Qmouse_click
))
5723 Lisp_Object window
, posn
;
5725 window
= POSN_WINDOW (EVENT_START (key
));
5726 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
5729 /* We're looking at the second event of a
5730 sequence which we expanded before. Set
5731 last_real_key_start appropriately. */
5733 last_real_key_start
= t
- 1;
5736 /* Key sequences beginning with mouse clicks are
5737 read using the keymaps in the buffer clicked on,
5738 not the current buffer. If we're at the
5739 beginning of a key sequence, switch buffers. */
5740 if (last_real_key_start
== 0
5742 && BUFFERP (XWINDOW (window
)->buffer
)
5743 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
5748 /* Arrange to go back to the original buffer once we're
5749 done reading the key sequence. Note that we can't
5750 use save_excursion_{save,restore} here, because they
5751 save point as well as the current buffer; we don't
5752 want to save point, because redisplay may change it,
5753 to accommodate a Fset_window_start or something. We
5754 don't want to do this at the top of the function,
5755 because we may get input from a subprocess which
5756 wants to change the selected window and stuff (say,
5758 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
5760 set_buffer_internal (XBUFFER (XWINDOW (window
)->buffer
));
5761 orig_local_map
= get_local_map (PT
, current_buffer
);
5762 goto replay_sequence
;
5764 /* For a mouse click, get the local text-property keymap
5765 of the place clicked on, rather than point. */
5766 if (last_real_key_start
== 0 && CONSP (XCONS (key
)->cdr
)
5767 && ! localized_local_map
)
5769 Lisp_Object map_here
, start
, pos
;
5771 localized_local_map
= 1;
5772 start
= EVENT_START (key
);
5773 if (CONSP (start
) && CONSP (XCONS (start
)->cdr
))
5775 pos
= POSN_BUFFER_POSN (start
);
5777 && XINT (pos
) >= BEG
&& XINT (pos
) <= Z
)
5779 map_here
= get_local_map (XINT (pos
), current_buffer
);
5780 if (!EQ (map_here
, orig_local_map
))
5782 orig_local_map
= map_here
;
5786 goto replay_sequence
;
5792 /* Expand mode-line and scroll-bar events into two events:
5793 use posn as a fake prefix key. */
5796 if (t
+ 1 >= bufsize
)
5797 error ("Key sequence too long");
5802 /* Zap the position in key, so we know that we've
5803 expanded it, and don't try to do so again. */
5804 POSN_BUFFER_POSN (EVENT_START (key
))
5805 = Fcons (posn
, Qnil
);
5809 else if (EQ (kind
, Qswitch_frame
))
5811 /* If we're at the beginning of a key sequence, and the caller
5812 says it's okay, go ahead and return this event. If we're
5813 in the midst of a key sequence, delay it until the end. */
5814 if (t
> 0 || !can_return_switch_frame
)
5816 delayed_switch_frame
= key
;
5820 else if (CONSP (XCONS (key
)->cdr
)
5821 && CONSP (EVENT_START (key
))
5822 && CONSP (XCONS (EVENT_START (key
))->cdr
))
5826 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
5827 /* Handle menu-bar events:
5828 insert the dummy prefix event `menu-bar'. */
5829 if (EQ (posn
, Qmenu_bar
))
5831 if (t
+ 1 >= bufsize
)
5832 error ("Key sequence too long");
5836 /* Zap the position in key, so we know that we've
5837 expanded it, and don't try to do so again. */
5838 POSN_BUFFER_POSN (EVENT_START (key
))
5839 = Fcons (posn
, Qnil
);
5842 goto replay_sequence
;
5844 else if (CONSP (posn
))
5846 /* We're looking at the second event of a
5847 sequence which we expanded before. Set
5848 last_real_key_start appropriately. */
5849 if (last_real_key_start
== t
&& t
> 0)
5850 last_real_key_start
= t
- 1;
5855 /* We have finally decided that KEY is something we might want
5857 first_binding
= (follow_key (key
,
5858 nmaps
- first_binding
,
5859 submaps
+ first_binding
,
5860 defs
+ first_binding
,
5861 submaps
+ first_binding
)
5864 /* If KEY wasn't bound, we'll try some fallbacks. */
5865 if (first_binding
>= nmaps
)
5869 head
= EVENT_HEAD (key
);
5870 if (help_char_p (head
) && t
> 0)
5872 read_key_sequence_cmd
= Vprefix_help_command
;
5874 last_nonmenu_event
= key
;
5875 /* The Microsoft C compiler can't handle the goto that
5883 Lisp_Object breakdown
;
5886 breakdown
= parse_modifiers (head
);
5887 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
5888 /* Attempt to reduce an unbound mouse event to a simpler
5889 event that is bound:
5890 Drags reduce to clicks.
5891 Double-clicks reduce to clicks.
5892 Triple-clicks reduce to double-clicks, then to clicks.
5893 Down-clicks are eliminated.
5894 Double-downs reduce to downs, then are eliminated.
5895 Triple-downs reduce to double-downs, then to downs,
5896 then are eliminated. */
5897 if (modifiers
& (down_modifier
| drag_modifier
5898 | double_modifier
| triple_modifier
))
5900 while (modifiers
& (down_modifier
| drag_modifier
5901 | double_modifier
| triple_modifier
))
5903 Lisp_Object new_head
, new_click
;
5904 if (modifiers
& triple_modifier
)
5905 modifiers
^= (double_modifier
| triple_modifier
);
5906 else if (modifiers
& double_modifier
)
5907 modifiers
&= ~double_modifier
;
5908 else if (modifiers
& drag_modifier
)
5909 modifiers
&= ~drag_modifier
;
5912 /* Dispose of this `down' event by simply jumping
5913 back to replay_key, to get another event.
5915 Note that if this event came from mock input,
5916 then just jumping back to replay_key will just
5917 hand it to us again. So we have to wipe out any
5920 We could delete keybuf[t] and shift everything
5921 after that to the left by one spot, but we'd also
5922 have to fix up any variable that points into
5923 keybuf, and shifting isn't really necessary
5926 Adding prefixes for non-textual mouse clicks
5927 creates two characters of mock input, and both
5928 must be thrown away. If we're only looking at
5929 the prefix now, we can just jump back to
5930 replay_key. On the other hand, if we've already
5931 processed the prefix, and now the actual click
5932 itself is giving us trouble, then we've lost the
5933 state of the keymaps we want to backtrack to, and
5934 we need to replay the whole sequence to rebuild
5937 Beyond that, only function key expansion could
5938 create more than two keys, but that should never
5939 generate mouse events, so it's okay to zero
5940 mock_input in that case too.
5942 Isn't this just the most wonderful code ever? */
5943 if (t
== last_real_key_start
)
5950 mock_input
= last_real_key_start
;
5951 goto replay_sequence
;
5956 = apply_modifiers (modifiers
, XCONS (breakdown
)->car
);
5958 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
5960 /* Look for a binding for this new key. follow_key
5961 promises that it didn't munge submaps the
5962 last time we called it, since key was unbound. */
5964 = (follow_key (new_click
,
5965 nmaps
- local_first_binding
,
5966 submaps
+ local_first_binding
,
5967 defs
+ local_first_binding
,
5968 submaps
+ local_first_binding
)
5969 + local_first_binding
);
5971 /* If that click is bound, go for it. */
5972 if (first_binding
< nmaps
)
5977 /* Otherwise, we'll leave key set to the drag event. */
5984 /* Normally, last_nonmenu_event gets the previous key we read.
5985 But when a mouse popup menu is being used,
5986 we don't update last_nonmenu_event; it continues to hold the mouse
5987 event that preceded the first level of menu. */
5988 if (!used_mouse_menu
)
5989 last_nonmenu_event
= key
;
5991 prev_fkey_map
= fkey_map
;
5992 prev_fkey_start
= fkey_start
;
5993 prev_fkey_end
= fkey_end
;
5995 prev_keytran_map
= keytran_map
;
5996 prev_keytran_start
= keytran_start
;
5997 prev_keytran_end
= keytran_end
;
5999 /* If the sequence is unbound, see if we can hang a function key
6000 off the end of it. We only want to scan real keyboard input
6001 for function key sequences, so if mock_input says that we're
6002 re-reading old events, don't examine it. */
6003 if (first_binding
>= nmaps
6006 Lisp_Object fkey_next
;
6008 /* Continue scan from fkey_end until we find a bound suffix.
6009 If we fail, increment fkey_start
6010 and start fkey_end from there. */
6011 while (fkey_end
< t
)
6015 key
= keybuf
[fkey_end
++];
6016 /* Look up meta-characters by prefixing them
6017 with meta_prefix_char. I hate this. */
6018 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
6023 (access_keymap (fkey_map
, meta_prefix_char
, 1, 0)),
6025 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
6028 fkey_next
= fkey_map
;
6031 = get_keyelt (access_keymap (fkey_next
, key
, 1, 0));
6033 #if 0 /* I didn't turn this on, because it might cause trouble
6034 for the mapping of return into C-m and tab into C-i. */
6035 /* Optionally don't map function keys into other things.
6036 This enables the user to redefine kp- keys easily. */
6037 if (SYMBOLP (key
) && !NILP (Vinhibit_function_key_mapping
))
6041 /* If the function key map gives a function, not an
6042 array, then call the function with no args and use
6043 its value instead. */
6044 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
6047 struct gcpro gcpro1
, gcpro2
, gcpro3
;
6051 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
6052 fkey_next
= call1 (fkey_next
, prompt
);
6054 /* If the function returned something invalid,
6055 barf--don't ignore it.
6056 (To ignore it safely, we would need to gcpro a bunch of
6057 other variables.) */
6058 if (! (VECTORP (fkey_next
) || STRINGP (fkey_next
)))
6059 error ("Function in function-key-map returns invalid key sequence");
6062 function_key_possible
= ! NILP (fkey_next
);
6064 /* If keybuf[fkey_start..fkey_end] is bound in the
6065 function key map and it's a suffix of the current
6066 sequence (i.e. fkey_end == t), replace it with
6067 the binding and restart with fkey_start at the end. */
6068 if ((VECTORP (fkey_next
) || STRINGP (fkey_next
))
6071 int len
= XFASTINT (Flength (fkey_next
));
6073 t
= fkey_start
+ len
;
6075 error ("Key sequence too long");
6077 if (VECTORP (fkey_next
))
6078 bcopy (XVECTOR (fkey_next
)->contents
,
6079 keybuf
+ fkey_start
,
6080 (t
- fkey_start
) * sizeof (keybuf
[0]));
6081 else if (STRINGP (fkey_next
))
6085 for (i
= 0; i
< len
; i
++)
6086 XSETFASTINT (keybuf
[fkey_start
+ i
],
6087 XSTRING (fkey_next
)->data
[i
]);
6091 fkey_start
= fkey_end
= t
;
6092 fkey_map
= Vfunction_key_map
;
6094 /* Do pass the results through key-translation-map. */
6095 keytran_start
= keytran_end
= 0;
6096 keytran_map
= Vkey_translation_map
;
6098 goto replay_sequence
;
6101 fkey_map
= get_keymap_1 (fkey_next
, 0, 1);
6103 /* If we no longer have a bound suffix, try a new positions for
6105 if (NILP (fkey_map
))
6107 fkey_end
= ++fkey_start
;
6108 fkey_map
= Vfunction_key_map
;
6109 function_key_possible
= 0;
6114 /* Look for this sequence in key-translation-map. */
6116 Lisp_Object keytran_next
;
6118 /* Scan from keytran_end until we find a bound suffix. */
6119 while (keytran_end
< t
)
6123 key
= keybuf
[keytran_end
++];
6124 /* Look up meta-characters by prefixing them
6125 with meta_prefix_char. I hate this. */
6126 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
6131 (access_keymap (keytran_map
, meta_prefix_char
, 1, 0)),
6133 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
6136 keytran_next
= keytran_map
;
6139 = get_keyelt (access_keymap (keytran_next
, key
, 1, 0));
6141 /* If the key translation map gives a function, not an
6142 array, then call the function with no args and use
6143 its value instead. */
6144 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
6145 && keytran_end
== t
)
6147 struct gcpro gcpro1
, gcpro2
, gcpro3
;
6151 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
6152 keytran_next
= call1 (keytran_next
, prompt
);
6154 /* If the function returned something invalid,
6155 barf--don't ignore it.
6156 (To ignore it safely, we would need to gcpro a bunch of
6157 other variables.) */
6158 if (! (VECTORP (keytran_next
) || STRINGP (keytran_next
)))
6159 error ("Function in key-translation-map returns invalid key sequence");
6162 key_translation_possible
= ! NILP (keytran_next
);
6164 /* If keybuf[keytran_start..keytran_end] is bound in the
6165 key translation map and it's a suffix of the current
6166 sequence (i.e. keytran_end == t), replace it with
6167 the binding and restart with keytran_start at the end. */
6168 if ((VECTORP (keytran_next
) || STRINGP (keytran_next
))
6169 && keytran_end
== t
)
6171 int len
= XFASTINT (Flength (keytran_next
));
6173 t
= keytran_start
+ len
;
6175 error ("Key sequence too long");
6177 if (VECTORP (keytran_next
))
6178 bcopy (XVECTOR (keytran_next
)->contents
,
6179 keybuf
+ keytran_start
,
6180 (t
- keytran_start
) * sizeof (keybuf
[0]));
6181 else if (STRINGP (keytran_next
))
6185 for (i
= 0; i
< len
; i
++)
6186 XSETFASTINT (keybuf
[keytran_start
+ i
],
6187 XSTRING (keytran_next
)->data
[i
]);
6191 keytran_start
= keytran_end
= t
;
6192 keytran_map
= Vkey_translation_map
;
6194 /* Don't pass the results of key-translation-map
6195 through function-key-map. */
6196 fkey_start
= fkey_end
= t
;
6197 fkey_map
= Vkey_translation_map
;
6199 goto replay_sequence
;
6202 keytran_map
= get_keymap_1 (keytran_next
, 0, 1);
6204 /* If we no longer have a bound suffix, try a new positions for
6206 if (NILP (keytran_map
))
6208 keytran_end
= ++keytran_start
;
6209 keytran_map
= Vkey_translation_map
;
6210 key_translation_possible
= 0;
6215 /* If KEY is not defined in any of the keymaps,
6216 and cannot be part of a function key or translation,
6217 and is an upper case letter
6218 use the corresponding lower-case letter instead. */
6219 if (first_binding
== nmaps
&& ! function_key_possible
6220 && ! key_translation_possible
6222 && ((((XINT (key
) & 0x3ffff)
6223 < XSTRING (current_buffer
->downcase_table
)->size
)
6224 && UPPERCASEP (XINT (key
) & 0x3ffff))
6225 || (XINT (key
) & shift_modifier
)))
6227 Lisp_Object new_key
;
6229 original_uppercase
= key
;
6230 original_uppercase_position
= t
- 1;
6232 if (XINT (new_key
) & shift_modifier
)
6233 XSETINT (new_key
, XINT (key
) & ~shift_modifier
);
6235 XSETINT (new_key
, (DOWNCASE (XINT (key
) & 0x3ffff)
6236 | (XINT (key
) & ~0x3ffff)));
6238 /* We have to do this unconditionally, regardless of whether
6239 the lower-case char is defined in the keymaps, because they
6240 might get translated through function-key-map. */
6241 keybuf
[t
- 1] = new_key
;
6244 fkey_map
= prev_fkey_map
;
6245 fkey_start
= prev_fkey_start
;
6246 fkey_end
= prev_fkey_end
;
6248 keytran_map
= prev_keytran_map
;
6249 keytran_start
= prev_keytran_start
;
6250 keytran_end
= prev_keytran_end
;
6252 goto replay_sequence
;
6254 /* If KEY is not defined in any of the keymaps,
6255 and cannot be part of a function key or translation,
6256 and is a shifted function key,
6257 use the corresponding unshifted function key instead. */
6258 if (first_binding
== nmaps
&& ! function_key_possible
6259 && ! key_translation_possible
6262 Lisp_Object breakdown
;
6265 breakdown
= parse_modifiers (key
);
6266 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
6267 if (modifiers
& shift_modifier
)
6269 Lisp_Object new_key
;
6271 original_uppercase
= key
;
6272 original_uppercase_position
= t
- 1;
6274 modifiers
&= ~shift_modifier
;
6275 new_key
= apply_modifiers (modifiers
,
6276 XCONS (breakdown
)->car
);
6278 keybuf
[t
- 1] = new_key
;
6281 fkey_map
= prev_fkey_map
;
6282 fkey_start
= prev_fkey_start
;
6283 fkey_end
= prev_fkey_end
;
6285 keytran_map
= prev_keytran_map
;
6286 keytran_start
= prev_keytran_start
;
6287 keytran_end
= prev_keytran_end
;
6289 goto replay_sequence
;
6295 read_key_sequence_cmd
= (first_binding
< nmaps
6296 ? defs
[first_binding
]
6299 unread_switch_frame
= delayed_switch_frame
;
6300 unbind_to (count
, Qnil
);
6302 /* Don't downcase the last character if the caller says don't.
6303 Don't downcase it if the result is undefined, either. */
6304 if ((dont_downcase_last
|| first_binding
>= nmaps
)
6305 && t
- 1 == original_uppercase_position
)
6306 keybuf
[t
- 1] = original_uppercase
;
6308 /* Occasionally we fabricate events, perhaps by expanding something
6309 according to function-key-map, or by adding a prefix symbol to a
6310 mouse click in the scroll bar or modeline. In this cases, return
6311 the entire generated key sequence, even if we hit an unbound
6312 prefix or a definition before the end. This means that you will
6313 be able to push back the event properly, and also means that
6314 read-key-sequence will always return a logical unit.
6317 for (; t
< mock_input
; t
++)
6319 if (echo_keystrokes
)
6320 echo_char (keybuf
[t
]);
6321 add_command_key (keybuf
[t
]);
6327 #if 0 /* This doc string is too long for some compilers.
6328 This commented-out definition serves for DOC. */
6329 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
6330 "Read a sequence of keystrokes and return as a string or vector.\n\
6331 The sequence is sufficient to specify a non-prefix command in the\n\
6332 current local and global maps.\n\
6334 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
6335 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
6336 as a continuation of the previous key.\n\
6338 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not\n\
6339 convert the last event to lower case. (Normally any upper case event\n\
6340 is converted to lower case if the original event is undefined and the lower\n\
6341 case equivalent is defined.) A non-nil value is appropriate for reading\n\
6342 a key sequence to be defined.\n\
6344 A C-g typed while in this function is treated like any other character,\n\
6345 and `quit-flag' is not set.\n\
6347 If the key sequence starts with a mouse click, then the sequence is read\n\
6348 using the keymaps of the buffer of the window clicked in, not the buffer\n\
6349 of the selected window as normal.\n\
6351 `read-key-sequence' drops unbound button-down events, since you normally\n\
6352 only care about the click or drag events which follow them. If a drag\n\
6353 or multi-click event is unbound, but the corresponding click event would\n\
6354 be bound, `read-key-sequence' turns the event into a click event at the\n\
6355 drag's starting position. This means that you don't have to distinguish\n\
6356 between click and drag, double, or triple events unless you want to.\n\
6358 `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\
6359 lines separating windows, and scroll bars with imaginary keys\n\
6360 `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\
6362 Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this\n\
6363 function will process a switch-frame event if the user switches frames\n\
6364 before typing anything. If the user switches frames in the middle of a\n\
6365 key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME\n\
6366 is nil, then the event will be put off until after the current key sequence.\n\
6368 `read-key-sequence' checks `function-key-map' for function key\n\
6369 sequences, where they wouldn't conflict with ordinary bindings. See\n\
6370 `function-key-map' for more details.")
6371 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
)
6374 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
6376 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
)
6377 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
6378 Lisp_Object can_return_switch_frame
;
6380 Lisp_Object keybuf
[30];
6382 struct gcpro gcpro1
, gcpro2
;
6385 CHECK_STRING (prompt
, 0);
6388 bzero (keybuf
, sizeof keybuf
);
6390 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
6392 if (NILP (continue_echo
))
6393 this_command_key_count
= 0;
6395 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
6396 prompt
, ! NILP (dont_downcase_last
),
6397 ! NILP (can_return_switch_frame
));
6405 return make_event_array (i
, keybuf
);
6408 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 3, 0,
6409 "Execute CMD as an editor command.\n\
6410 CMD must be a symbol that satisfies the `commandp' predicate.\n\
6411 Optional second arg RECORD-FLAG non-nil\n\
6412 means unconditionally put this command in `command-history'.\n\
6413 Otherwise, that is done only if an arg is read using the minibuffer.\n\
6414 The argument KEYS specifies the value to use instead of (this-command-keys)\n\
6415 when reading the arguments; if it is nil, (this_command_key_count) is used.")
6417 Lisp_Object cmd
, record
, keys
;
6419 register Lisp_Object final
;
6420 register Lisp_Object tem
;
6421 Lisp_Object prefixarg
;
6422 struct backtrace backtrace
;
6423 extern int debug_on_next_call
;
6425 prefixarg
= current_kboard
->Vprefix_arg
;
6426 current_kboard
->Vprefix_arg
= Qnil
;
6427 Vcurrent_prefix_arg
= prefixarg
;
6428 debug_on_next_call
= 0;
6432 tem
= Fget (cmd
, Qdisabled
);
6433 if (!NILP (tem
) && !NILP (Vrun_hooks
))
6435 tem
= Fsymbol_value (Qdisabled_command_hook
);
6437 return call1 (Vrun_hooks
, Qdisabled_command_hook
);
6443 final
= Findirect_function (cmd
);
6445 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
6446 do_autoload (final
, cmd
);
6451 if (STRINGP (final
) || VECTORP (final
))
6453 /* If requested, place the macro in the command history. For
6454 other sorts of commands, call-interactively takes care of
6458 = Fcons (Fcons (Qexecute_kbd_macro
,
6459 Fcons (final
, Fcons (prefixarg
, Qnil
))),
6462 return Fexecute_kbd_macro (final
, prefixarg
);
6464 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
6466 backtrace
.next
= backtrace_list
;
6467 backtrace_list
= &backtrace
;
6468 backtrace
.function
= &Qcall_interactively
;
6469 backtrace
.args
= &cmd
;
6470 backtrace
.nargs
= 1;
6471 backtrace
.evalargs
= 0;
6473 tem
= Fcall_interactively (cmd
, record
, keys
);
6475 backtrace_list
= backtrace
.next
;
6481 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
6483 "Read function name, then read its arguments and call it.")
6485 Lisp_Object prefixarg
;
6487 Lisp_Object function
;
6489 Lisp_Object saved_keys
;
6490 struct gcpro gcpro1
;
6492 saved_keys
= Fvector (this_command_key_count
,
6493 XVECTOR (this_command_keys
)->contents
);
6495 GCPRO1 (saved_keys
);
6497 if (EQ (prefixarg
, Qminus
))
6499 else if (CONSP (prefixarg
) && XINT (XCONS (prefixarg
)->car
) == 4)
6500 strcpy (buf
, "C-u ");
6501 else if (CONSP (prefixarg
) && INTEGERP (XCONS (prefixarg
)->car
))
6503 if (sizeof (int) == sizeof (EMACS_INT
))
6504 sprintf (buf
, "%d ", XINT (XCONS (prefixarg
)->car
));
6505 else if (sizeof (long) == sizeof (EMACS_INT
))
6506 sprintf (buf
, "%ld ", XINT (XCONS (prefixarg
)->car
));
6510 else if (INTEGERP (prefixarg
))
6512 if (sizeof (int) == sizeof (EMACS_INT
))
6513 sprintf (buf
, "%d ", XINT (prefixarg
));
6514 else if (sizeof (long) == sizeof (EMACS_INT
))
6515 sprintf (buf
, "%ld ", XINT (prefixarg
));
6520 /* This isn't strictly correct if execute-extended-command
6521 is bound to anything else. Perhaps it should use
6522 this_command_keys? */
6523 strcat (buf
, "M-x ");
6525 /* Prompt with buf, and then read a string, completing from and
6526 restricting to the set of all defined commands. Don't provide
6527 any initial input. Save the command read on the extended-command
6529 function
= Fcompleting_read (build_string (buf
),
6530 Vobarray
, Qcommandp
,
6531 Qt
, Qnil
, Qextended_command_history
);
6533 /* Set this_command_keys to the concatenation of saved_keys and
6534 function, followed by a RET. */
6536 struct Lisp_String
*str
;
6541 this_command_key_count
= 0;
6543 keys
= XVECTOR (saved_keys
)->contents
;
6544 for (i
= 0; i
< XVECTOR (saved_keys
)->size
; i
++)
6545 add_command_key (keys
[i
]);
6547 str
= XSTRING (function
);
6548 for (i
= 0; i
< str
->size
; i
++)
6550 XSETFASTINT (tem
, str
->data
[i
]);
6551 add_command_key (tem
);
6554 XSETFASTINT (tem
, '\015');
6555 add_command_key (tem
);
6560 function
= Fintern (function
, Qnil
);
6561 current_kboard
->Vprefix_arg
= prefixarg
;
6562 this_command
= function
;
6564 /* If enabled, show which key runs this command. */
6565 if (!NILP (Vsuggest_key_bindings
)
6566 && SYMBOLP (function
))
6568 Lisp_Object
*maps
, bindings
;
6572 nmaps
= current_active_maps (&maps
);
6574 for (i
= 0; i
< nmaps
&& NILP (bindings
); i
++)
6575 bindings
= Fwhere_is_internal (function
, maps
[i
], Qt
, Qnil
);
6579 if (!NILP (bindings
))
6581 message ("You can run the command `%s' by typing %s",
6582 XSYMBOL (function
)->name
->data
,
6583 XSTRING (Fkey_description (bindings
))->data
);
6584 Fsit_for ((NUMBERP (Vsuggest_key_bindings
)
6585 ? Vsuggest_key_bindings
: make_number (2)),
6590 return Fcommand_execute (function
, Qt
, Qnil
);
6593 /* Find the set of keymaps now active.
6594 Store into *MAPS_P a vector holding the various maps
6595 and return the number of them. The vector was malloc'd
6596 and the caller should free it. */
6599 current_active_maps (maps_p
)
6600 Lisp_Object
**maps_p
;
6602 Lisp_Object
*tmaps
, *maps
;
6605 /* Should overriding-terminal-local-map and overriding-local-map apply? */
6606 if (!NILP (Voverriding_local_map_menu_flag
))
6608 /* Yes, use them (if non-nil) as well as the global map. */
6609 maps
= (Lisp_Object
*) xmalloc (3 * sizeof (maps
[0]));
6611 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
6612 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
6613 if (!NILP (Voverriding_local_map
))
6614 maps
[nmaps
++] = Voverriding_local_map
;
6618 /* No, so use major and minor mode keymaps. */
6619 nmaps
= current_minor_maps (NULL
, &tmaps
);
6620 maps
= (Lisp_Object
*) xmalloc ((nmaps
+ 2) * sizeof (maps
[0]));
6621 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
6622 #ifdef USE_TEXT_PROPERTIES
6623 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
6625 maps
[nmaps
++] = current_buffer
->keymap
;
6628 maps
[nmaps
++] = current_global_map
;
6635 detect_input_pending ()
6638 get_input_pending (&input_pending
);
6640 return input_pending
;
6643 /* This is called in some cases before a possible quit.
6644 It cases the next call to detect_input_pending to recompute input_pending.
6645 So calling this function unnecessarily can't do any harm. */
6646 clear_input_pending ()
6651 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
6652 "T if command input is currently available with no waiting.\n\
6653 Actually, the value is nil only if we can be sure that no input is available.")
6656 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1)
6659 return detect_input_pending () ? Qt
: Qnil
;
6662 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
6663 "Return vector of last 100 events, not counting those from keyboard macros.")
6666 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
6669 if (total_keys
< NUM_RECENT_KEYS
)
6670 return Fvector (total_keys
, keys
);
6673 val
= Fvector (NUM_RECENT_KEYS
, keys
);
6674 bcopy (keys
+ recent_keys_index
,
6675 XVECTOR (val
)->contents
,
6676 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
6678 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
6679 recent_keys_index
* sizeof (Lisp_Object
));
6684 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
6685 "Return the key sequence that invoked this command.\n\
6686 The value is a string or a vector.")
6689 return make_event_array (this_command_key_count
,
6690 XVECTOR (this_command_keys
)->contents
);
6693 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths
,
6694 Sreset_this_command_lengths
, 0, 0, 0,
6695 "Used for complicated reasons in `universal-argument-other-key'.\n\
6697 `universal-argument-other-key' rereads the event just typed.\n\
6698 It then gets translated through `function-key-map'.\n\
6699 The translated event gets included in the echo area and in\n\
6700 the value of `this-command-keys' in addition to the raw original event.\n\
6701 That is not right.\n\
6703 Calling this function directs the translated event to replace\n\
6704 the original event, so that only one version of the event actually\n\
6705 appears in the echo area and in the value of `this-command-keys.'.")
6708 before_command_restore_flag
= 1;
6709 before_command_key_count_1
= before_command_key_count
;
6710 before_command_echo_length_1
= before_command_echo_length
;
6713 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
6714 "Return the current depth in recursive edits.")
6718 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
6722 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
6723 "FOpen dribble file: ",
6724 "Start writing all keyboard characters to a dribble file called FILE.\n\
6725 If FILE is nil, close any open dribble file.")
6739 file
= Fexpand_file_name (file
, Qnil
);
6740 dribble
= fopen (XSTRING (file
)->data
, "w");
6745 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
6746 "Discard the contents of the terminal input buffer.\n\
6747 Also cancel any kbd macro being defined.")
6750 current_kboard
->defining_kbd_macro
= Qnil
;
6751 update_mode_lines
++;
6753 Vunread_command_events
= Qnil
;
6754 unread_command_char
= -1;
6756 discard_tty_input ();
6758 /* Without the cast, GCC complains that this assignment loses the
6759 volatile qualifier of kbd_store_ptr. Is there anything wrong
6761 kbd_fetch_ptr
= (struct input_event
*) kbd_store_ptr
;
6762 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
6768 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
6769 "Stop Emacs and return to superior process. You can resume later.\n\
6770 If `cannot-suspend' is non-nil, or if the system doesn't support job\n\
6771 control, run a subshell instead.\n\n\
6772 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
6773 to be read as terminal input by Emacs's parent, after suspension.\n\
6775 Before suspending, run the normal hook `suspend-hook'.\n\
6776 After resumption run the normal hook `suspend-resume-hook'.\n\
6778 Some operating systems cannot stop the Emacs process and resume it later.\n\
6779 On such systems, Emacs starts a subshell instead of suspending.")
6781 Lisp_Object stuffstring
;
6784 int count
= specpdl_ptr
- specpdl
;
6785 int old_height
, old_width
;
6787 struct gcpro gcpro1
, gcpro2
;
6788 extern init_sys_modes ();
6790 if (!NILP (stuffstring
))
6791 CHECK_STRING (stuffstring
, 0);
6793 /* Run the functions in suspend-hook. */
6794 if (!NILP (Vrun_hooks
))
6795 call1 (Vrun_hooks
, intern ("suspend-hook"));
6797 GCPRO1 (stuffstring
);
6798 get_frame_size (&old_width
, &old_height
);
6800 /* sys_suspend can get an error if it tries to fork a subshell
6801 and the system resources aren't available for that. */
6802 record_unwind_protect (init_sys_modes
, 0);
6803 stuff_buffered_input (stuffstring
);
6808 unbind_to (count
, Qnil
);
6810 /* Check if terminal/window size has changed.
6811 Note that this is not useful when we are running directly
6812 with a window system; but suspend should be disabled in that case. */
6813 get_frame_size (&width
, &height
);
6814 if (width
!= old_width
|| height
!= old_height
)
6815 change_frame_size (selected_frame
, height
, width
, 0, 0);
6817 /* Run suspend-resume-hook. */
6818 if (!NILP (Vrun_hooks
))
6819 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
6825 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
6826 Then in any case stuff anything Emacs has read ahead and not used. */
6828 stuff_buffered_input (stuffstring
)
6829 Lisp_Object stuffstring
;
6831 /* stuff_char works only in BSD, versions 4.2 and up. */
6834 register unsigned char *p
;
6836 if (STRINGP (stuffstring
))
6840 p
= XSTRING (stuffstring
)->data
;
6841 count
= XSTRING (stuffstring
)->size
;
6846 /* Anything we have read ahead, put back for the shell to read. */
6847 /* ?? What should this do when we have multiple keyboards??
6848 Should we ignore anything that was typed in at the "wrong" kboard? */
6849 for (; kbd_fetch_ptr
!= kbd_store_ptr
; kbd_fetch_ptr
++)
6851 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
6852 kbd_fetch_ptr
= kbd_buffer
;
6853 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
6854 stuff_char (kbd_fetch_ptr
->code
);
6855 kbd_fetch_ptr
->kind
= no_event
;
6856 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_fetch_ptr
6862 #endif /* BSD and not BSD4_1 */
6865 set_waiting_for_input (time_to_clear
)
6866 EMACS_TIME
*time_to_clear
;
6868 input_available_clear_time
= time_to_clear
;
6870 /* Tell interrupt_signal to throw back to read_char, */
6871 waiting_for_input
= 1;
6873 /* If interrupt_signal was called before and buffered a C-g,
6874 make it run again now, to avoid timing error. */
6875 if (!NILP (Vquit_flag
))
6876 quit_throw_to_read_char ();
6879 clear_waiting_for_input ()
6881 /* Tell interrupt_signal not to throw back to read_char, */
6882 waiting_for_input
= 0;
6883 input_available_clear_time
= 0;
6886 /* This routine is called at interrupt level in response to C-G.
6887 If interrupt_input, this is the handler for SIGINT.
6888 Otherwise, it is called from kbd_buffer_store_event,
6889 in handling SIGIO or SIGTINT.
6891 If `waiting_for_input' is non zero, then unless `echoing' is nonzero,
6892 immediately throw back to read_char.
6894 Otherwise it sets the Lisp variable quit-flag not-nil.
6895 This causes eval to throw, when it gets a chance.
6896 If quit-flag is already non-nil, it stops the job right away. */
6899 interrupt_signal (signalnum
) /* If we don't have an argument, */
6900 int signalnum
; /* some compilers complain in signal calls. */
6903 /* Must preserve main program's value of errno. */
6904 int old_errno
= errno
;
6907 if (!read_socket_hook
&& NILP (Vwindow_system
))
6909 /* USG systems forget handlers when they are used;
6910 must reestablish each time */
6911 signal (SIGINT
, interrupt_signal
);
6912 signal (SIGQUIT
, interrupt_signal
);
6918 if (!NILP (Vquit_flag
) && FRAME_TERMCAP_P (selected_frame
))
6923 #ifdef SIGTSTP /* Support possible in later USG versions */
6925 * On systems which can suspend the current process and return to the original
6926 * shell, this command causes the user to end up back at the shell.
6927 * The "Auto-save" and "Abort" questions are not asked until
6928 * the user elects to return to emacs, at which point he can save the current
6929 * job and either dump core or continue.
6934 if (sys_suspend () == -1)
6936 printf ("Not running as a subprocess;\n");
6937 printf ("you can continue or abort.\n");
6940 /* Perhaps should really fork an inferior shell?
6941 But that would not provide any way to get back
6942 to the original shell, ever. */
6943 printf ("No support for stopping a process on this operating system;\n");
6944 printf ("you can continue or abort.\n");
6945 #endif /* not VMS */
6946 #endif /* not SIGTSTP */
6948 /* We must remain inside the screen area when the internal terminal
6949 is used. Note that [Enter] is not echoed by dos. */
6952 /* It doesn't work to autosave while GC is in progress;
6953 the code used for auto-saving doesn't cope with the mark bit. */
6954 if (!gc_in_progress
)
6956 printf ("Auto-save? (y or n) ");
6958 if (((c
= getchar ()) & ~040) == 'Y')
6960 Fdo_auto_save (Qt
, Qnil
);
6962 printf ("\r\nAuto-save done");
6963 #else /* not MSDOS */
6964 printf ("Auto-save done\n");
6965 #endif /* not MSDOS */
6967 while (c
!= '\n') c
= getchar ();
6971 /* During GC, it must be safe to reenable quitting again. */
6972 Vinhibit_quit
= Qnil
;
6975 #endif /* not MSDOS */
6976 printf ("Garbage collection in progress; cannot auto-save now\r\n");
6977 printf ("but will instead do a real quit after garbage collection ends\r\n");
6982 printf ("\r\nAbort? (y or n) ");
6983 #else /* not MSDOS */
6985 printf ("Abort (and enter debugger)? (y or n) ");
6987 printf ("Abort (and dump core)? (y or n) ");
6988 #endif /* not VMS */
6989 #endif /* not MSDOS */
6991 if (((c
= getchar ()) & ~040) == 'Y')
6993 while (c
!= '\n') c
= getchar ();
6995 printf ("\r\nContinuing...\r\n");
6996 #else /* not MSDOS */
6997 printf ("Continuing...\n");
6998 #endif /* not MSDOS */
7004 /* If executing a function that wants to be interrupted out of
7005 and the user has not deferred quitting by binding `inhibit-quit'
7006 then quit right away. */
7007 if (immediate_quit
&& NILP (Vinhibit_quit
))
7011 Fsignal (Qquit
, Qnil
);
7014 /* Else request quit when it's safe */
7018 if (waiting_for_input
&& !echoing
)
7019 quit_throw_to_read_char ();
7024 /* Handle a C-g by making read_char return C-g. */
7026 quit_throw_to_read_char ()
7028 quit_error_check ();
7030 /* Prevent another signal from doing this before we finish. */
7031 clear_waiting_for_input ();
7034 Vunread_command_events
= Qnil
;
7035 unread_command_char
= -1;
7037 #if 0 /* Currently, sit_for is called from read_char without turning
7038 off polling. And that can call set_waiting_for_input.
7039 It seems to be harmless. */
7040 #ifdef POLL_FOR_INPUT
7041 /* May be > 1 if in recursive minibuffer. */
7042 if (poll_suppress_count
== 0)
7047 if (FRAMEP (internal_last_event_frame
)
7048 && XFRAME (internal_last_event_frame
) != selected_frame
)
7049 do_switch_frame (make_lispy_switch_frame (internal_last_event_frame
),
7053 _longjmp (getcjmp
, 1);
7056 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
7057 "Set mode of reading keyboard input.\n\
7058 First arg INTERRUPT non-nil means use input interrupts;\n\
7059 nil means use CBREAK mode.\n\
7060 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
7061 (no effect except in CBREAK mode).\n\
7062 Third arg META t means accept 8-bit input (for a Meta key).\n\
7063 META nil means ignore the top bit, on the assumption it is parity.\n\
7064 Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\
7065 Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\
7066 See also `current-input-mode'.")
7067 (interrupt
, flow
, meta
, quit
)
7068 Lisp_Object interrupt
, flow
, meta
, quit
;
7071 && (!INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400))
7072 error ("set-input-mode: QUIT must be an ASCII character");
7074 #ifdef POLL_FOR_INPUT
7079 /* this causes startup screen to be restored and messes with the mouse */
7084 /* Note SIGIO has been undef'd if FIONREAD is missing. */
7085 if (read_socket_hook
)
7087 /* When using X, don't give the user a real choice,
7088 because we haven't implemented the mechanisms to support it. */
7089 #ifdef NO_SOCK_SIGIO
7090 interrupt_input
= 0;
7091 #else /* not NO_SOCK_SIGIO */
7092 interrupt_input
= 1;
7093 #endif /* NO_SOCK_SIGIO */
7096 interrupt_input
= !NILP (interrupt
);
7097 #else /* not SIGIO */
7098 interrupt_input
= 0;
7099 #endif /* not SIGIO */
7101 /* Our VMS input only works by interrupts, as of now. */
7103 interrupt_input
= 1;
7106 flow_control
= !NILP (flow
);
7109 else if (EQ (meta
, Qt
))
7114 /* Don't let this value be out of range. */
7115 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
7121 #ifdef POLL_FOR_INPUT
7122 poll_suppress_count
= 1;
7128 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
7129 "Return information about the way Emacs currently reads keyboard input.\n\
7130 The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
7131 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\
7132 nil, Emacs is using CBREAK mode.\n\
7133 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\
7134 terminal; this does not apply if Emacs uses interrupt-driven input.\n\
7135 META is t if accepting 8-bit input with 8th bit as Meta flag.\n\
7136 META nil means ignoring the top bit, on the assumption it is parity.\n\
7137 META is neither t nor nil if accepting 8-bit input and using\n\
7138 all 8 bits as the character code.\n\
7139 QUIT is the character Emacs currently uses to quit.\n\
7140 The elements of this list correspond to the arguments of\n\
7146 val
[0] = interrupt_input
? Qt
: Qnil
;
7147 val
[1] = flow_control
? Qt
: Qnil
;
7148 val
[2] = meta_key
== 2 ? make_number (0) : meta_key
== 1 ? Qt
: Qnil
;
7149 XSETFASTINT (val
[3], quit_char
);
7151 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
7156 * Set up a new kboard object with reasonable initial values.
7162 kb
->Voverriding_terminal_local_map
= Qnil
;
7163 kb
->Vlast_command
= Qnil
;
7164 kb
->Vprefix_arg
= Qnil
;
7165 kb
->kbd_queue
= Qnil
;
7166 kb
->kbd_queue_has_data
= 0;
7167 kb
->immediate_echo
= 0;
7168 kb
->echoptr
= kb
->echobuf
;
7169 kb
->echo_after_prompt
= -1;
7170 kb
->kbd_macro_buffer
= 0;
7171 kb
->kbd_macro_bufsize
= 0;
7172 kb
->defining_kbd_macro
= Qnil
;
7173 kb
->Vlast_kbd_macro
= Qnil
;
7174 kb
->reference_count
= 0;
7175 kb
->Vsystem_key_alist
= Qnil
;
7176 kb
->system_key_syms
= Qnil
;
7177 kb
->Vdefault_minibuffer_frame
= Qnil
;
7181 * Destroy the contents of a kboard object, but not the object itself.
7182 * We use this just before deleteing it, or if we're going to initialize
7189 if (kb
->kbd_macro_buffer
)
7190 xfree (kb
->kbd_macro_buffer
);
7199 for (kbp
= &all_kboards
; *kbp
!= kb
; kbp
= &(*kbp
)->next_kboard
)
7202 *kbp
= kb
->next_kboard
;
7210 /* This is correct before outermost invocation of the editor loop */
7211 command_loop_level
= -1;
7213 quit_char
= Ctl ('g');
7214 Vunread_command_events
= Qnil
;
7215 unread_command_char
= -1;
7217 recent_keys_index
= 0;
7218 kbd_fetch_ptr
= kbd_buffer
;
7219 kbd_store_ptr
= kbd_buffer
;
7220 kbd_buffer_frame_or_window
7221 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
7223 do_mouse_tracking
= Qnil
;
7228 /* This means that command_loop_1 won't try to select anything the first
7230 internal_last_event_frame
= Qnil
;
7231 Vlast_event_frame
= internal_last_event_frame
;
7235 current_kboard
= initial_kboard
;
7237 wipe_kboard (current_kboard
);
7238 init_kboard (current_kboard
);
7241 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
7243 kbd_buffer_frame_or_window
7244 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
7245 if (!noninteractive
&& !read_socket_hook
&& NILP (Vwindow_system
))
7247 signal (SIGINT
, interrupt_signal
);
7248 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
7249 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
7250 SIGQUIT and we can't tell which one it will give us. */
7251 signal (SIGQUIT
, interrupt_signal
);
7252 #endif /* HAVE_TERMIO */
7254 /* Note SIGIO has been undef'd if FIONREAD is missing. */
7256 if (!noninteractive
)
7257 signal (SIGIO
, input_available_signal
);
7260 /* Use interrupt input by default, if it works and noninterrupt input
7261 has deficiencies. */
7263 #ifdef INTERRUPT_INPUT
7264 interrupt_input
= 1;
7266 interrupt_input
= 0;
7269 /* Our VMS input only works by interrupts, as of now. */
7271 interrupt_input
= 1;
7277 if (keyboard_init_hook
)
7278 (*keyboard_init_hook
) ();
7280 #ifdef POLL_FOR_INPUT
7281 poll_suppress_count
= 1;
7286 /* This type's only use is in syms_of_keyboard, to initialize the
7287 event header symbols and put properties on them. */
7294 struct event_head head_table
[] = {
7295 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
7296 &Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
,
7297 &Qswitch_frame
, "switch-frame", &Qswitch_frame
,
7298 &Qdelete_frame
, "delete-frame", &Qdelete_frame
,
7299 &Qiconify_frame
, "iconify-frame", &Qiconify_frame
,
7300 &Qmake_frame_visible
, "make-frame-visible", &Qmake_frame_visible
,
7305 Qdisabled_command_hook
= intern ("disabled-command-hook");
7306 staticpro (&Qdisabled_command_hook
);
7308 Qself_insert_command
= intern ("self-insert-command");
7309 staticpro (&Qself_insert_command
);
7311 Qforward_char
= intern ("forward-char");
7312 staticpro (&Qforward_char
);
7314 Qbackward_char
= intern ("backward-char");
7315 staticpro (&Qbackward_char
);
7317 Qdisabled
= intern ("disabled");
7318 staticpro (&Qdisabled
);
7320 Qundefined
= intern ("undefined");
7321 staticpro (&Qundefined
);
7323 Qpre_command_hook
= intern ("pre-command-hook");
7324 staticpro (&Qpre_command_hook
);
7326 Qpost_command_hook
= intern ("post-command-hook");
7327 staticpro (&Qpost_command_hook
);
7329 Qpost_command_idle_hook
= intern ("post-command-idle-hook");
7330 staticpro (&Qpost_command_idle_hook
);
7332 Qdeferred_action_function
= intern ("deferred-action-function");
7333 staticpro (&Qdeferred_action_function
);
7335 Qcommand_hook_internal
= intern ("command-hook-internal");
7336 staticpro (&Qcommand_hook_internal
);
7338 Qfunction_key
= intern ("function-key");
7339 staticpro (&Qfunction_key
);
7340 Qmouse_click
= intern ("mouse-click");
7341 staticpro (&Qmouse_click
);
7343 Qmenu_enable
= intern ("menu-enable");
7344 staticpro (&Qmenu_enable
);
7346 Qmode_line
= intern ("mode-line");
7347 staticpro (&Qmode_line
);
7348 Qvertical_line
= intern ("vertical-line");
7349 staticpro (&Qvertical_line
);
7350 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
7351 staticpro (&Qvertical_scroll_bar
);
7352 Qmenu_bar
= intern ("menu-bar");
7353 staticpro (&Qmenu_bar
);
7355 Qabove_handle
= intern ("above-handle");
7356 staticpro (&Qabove_handle
);
7357 Qhandle
= intern ("handle");
7358 staticpro (&Qhandle
);
7359 Qbelow_handle
= intern ("below-handle");
7360 staticpro (&Qbelow_handle
);
7362 Qevent_kind
= intern ("event-kind");
7363 staticpro (&Qevent_kind
);
7364 Qevent_symbol_elements
= intern ("event-symbol-elements");
7365 staticpro (&Qevent_symbol_elements
);
7366 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
7367 staticpro (&Qevent_symbol_element_mask
);
7368 Qmodifier_cache
= intern ("modifier-cache");
7369 staticpro (&Qmodifier_cache
);
7371 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
7372 staticpro (&Qrecompute_lucid_menubar
);
7373 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
7374 staticpro (&Qactivate_menubar_hook
);
7376 Qpolling_period
= intern ("polling-period");
7377 staticpro (&Qpolling_period
);
7380 struct event_head
*p
;
7382 for (p
= head_table
;
7383 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
7386 *p
->var
= intern (p
->name
);
7388 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
7389 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
7393 button_down_location
= Fmake_vector (make_number (NUM_MOUSE_BUTTONS
), Qnil
);
7394 staticpro (&button_down_location
);
7398 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
7400 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
7401 for (i
= 0; i
< len
; i
++)
7402 if (modifier_names
[i
])
7403 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
7404 staticpro (&modifier_symbols
);
7407 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
7408 staticpro (&recent_keys
);
7410 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
7411 staticpro (&this_command_keys
);
7413 Qextended_command_history
= intern ("extended-command-history");
7414 Fset (Qextended_command_history
, Qnil
);
7415 staticpro (&Qextended_command_history
);
7417 kbd_buffer_frame_or_window
7418 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
7419 staticpro (&kbd_buffer_frame_or_window
);
7421 accent_key_syms
= Qnil
;
7422 staticpro (&accent_key_syms
);
7424 func_key_syms
= Qnil
;
7425 staticpro (&func_key_syms
);
7428 staticpro (&mouse_syms
);
7430 unread_switch_frame
= Qnil
;
7431 staticpro (&unread_switch_frame
);
7433 defsubr (&Sevent_convert_list
);
7434 defsubr (&Sread_key_sequence
);
7435 defsubr (&Srecursive_edit
);
7437 defsubr (&Strack_mouse
);
7439 defsubr (&Sinput_pending_p
);
7440 defsubr (&Scommand_execute
);
7441 defsubr (&Srecent_keys
);
7442 defsubr (&Sthis_command_keys
);
7443 defsubr (&Sreset_this_command_lengths
);
7444 defsubr (&Ssuspend_emacs
);
7445 defsubr (&Sabort_recursive_edit
);
7446 defsubr (&Sexit_recursive_edit
);
7447 defsubr (&Srecursion_depth
);
7448 defsubr (&Stop_level
);
7449 defsubr (&Sdiscard_input
);
7450 defsubr (&Sopen_dribble_file
);
7451 defsubr (&Sset_input_mode
);
7452 defsubr (&Scurrent_input_mode
);
7453 defsubr (&Sexecute_extended_command
);
7455 DEFVAR_LISP ("last-command-char", &last_command_char
,
7456 "Last input event that was part of a command.");
7458 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char
,
7459 "Last input event that was part of a command.");
7461 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
7462 "Last input event in a command, except for mouse menu events.\n\
7463 Mouse menus give back keys that don't look like mouse events;\n\
7464 this variable holds the actual mouse event that led to the menu,\n\
7465 so that you can determine whether the command was run by mouse or not.");
7467 DEFVAR_LISP ("last-input-char", &last_input_char
,
7468 "Last input event.");
7470 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char
,
7471 "Last input event.");
7473 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
7474 "List of objects to be read as next command input events.");
7476 DEFVAR_INT ("unread-command-char", &unread_command_char
,
7477 "If not -1, an object to be read as next command input event.");
7479 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
7480 "Meta-prefix character code. Meta-foo as command input\n\
7481 turns into this character followed by foo.");
7482 XSETINT (meta_prefix_char
, 033);
7484 DEFVAR_KBOARD ("last-command", Vlast_command
,
7485 "The last command executed. Normally a symbol with a function definition,\n\
7486 but can be whatever was found in the keymap, or whatever the variable\n\
7487 `this-command' was set to by that command.\n\
7489 The value `mode-exit' is special; it means that the previous command\n\
7490 read an event that told it to exit, and it did so and unread that event.\n\
7491 In other words, the present command is the event that made the previous\n\
7494 The value `kill-region' is special; it means that the previous command\n\
7495 was a kill command.");
7497 DEFVAR_LISP ("this-command", &this_command
,
7498 "The command now being executed.\n\
7499 The command can set this variable; whatever is put here\n\
7500 will be in `last-command' during the following command.");
7501 this_command
= Qnil
;
7503 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
7504 "*Number of keyboard input characters between auto-saves.\n\
7505 Zero means disable autosaving due to number of characters typed.");
7506 auto_save_interval
= 300;
7508 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
7509 "*Number of seconds idle time before auto-save.\n\
7510 Zero or nil means disable auto-saving due to idleness.\n\
7511 After auto-saving due to this many seconds of idle time,\n\
7512 Emacs also does a garbage collection if that seems to be warranted.");
7513 XSETFASTINT (Vauto_save_timeout
, 30);
7515 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes
,
7516 "*Nonzero means echo unfinished commands after this many seconds of pause.");
7517 echo_keystrokes
= 1;
7519 DEFVAR_INT ("polling-period", &polling_period
,
7520 "*Interval between polling for input during Lisp execution.\n\
7521 The reason for polling is to make C-g work to stop a running program.\n\
7522 Polling is needed only when using X windows and SIGIO does not work.\n\
7523 Polling is automatically disabled in all other cases.");
7526 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
7527 "*Maximum time between mouse clicks to make a double-click.\n\
7528 Measured in milliseconds. nil means disable double-click recognition;\n\
7529 t means double-clicks have no time limit and are detected\n\
7530 by position only.");
7531 Vdouble_click_time
= make_number (500);
7533 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
7534 "*Non-nil means inhibit local map menu bar menus.");
7535 inhibit_local_menu_bar_menus
= 0;
7537 DEFVAR_INT ("num-input-keys", &num_input_keys
,
7538 "Number of complete keys read from the keyboard so far.");
7541 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
7542 "The frame in which the most recently read event occurred.\n\
7543 If the last event came from a keyboard macro, this is set to `macro'.");
7544 Vlast_event_frame
= Qnil
;
7546 DEFVAR_LISP ("help-char", &Vhelp_char
,
7547 "Character to recognize as meaning Help.\n\
7548 When it is read, do `(eval help-form)', and display result if it's a string.\n\
7549 If the value of `help-form' is nil, this char can be read normally.");
7550 XSETINT (Vhelp_char
, Ctl ('H'));
7552 DEFVAR_LISP ("help-event-list", &Vhelp_event_list
,
7553 "List of input events to recognize as meaning Help.\n\
7554 These work just like the value of `help-char' (see that).");
7555 Vhelp_event_list
= Qnil
;
7557 DEFVAR_LISP ("help-form", &Vhelp_form
,
7558 "Form to execute when character `help-char' is read.\n\
7559 If the form returns a string, that string is displayed.\n\
7560 If `help-form' is nil, the help char is not recognized.");
7563 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
7564 "Command to run when `help-char' character follows a prefix key.\n\
7565 This command is used only when there is no actual binding\n\
7566 for that character after that prefix key.");
7567 Vprefix_help_command
= Qnil
;
7569 DEFVAR_LISP ("top-level", &Vtop_level
,
7570 "Form to evaluate when Emacs starts up.\n\
7571 Useful to set before you dump a modified Emacs.");
7574 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
7575 "Translate table for keyboard input, or nil.\n\
7576 Each character is looked up in this string and the contents used instead.\n\
7577 The value may be a string, a vector, or a char-table.\n\
7578 If it is a string or vector of length N,\n\
7579 character codes N and up are untranslated.\n\
7580 In a vector or a char-table, an element which is nil means \"no translation\".");
7581 Vkeyboard_translate_table
= Qnil
;
7583 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
7584 "Non-nil means to always spawn a subshell instead of suspending,\n\
7585 even if the operating system has support for stopping a process.");
7588 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
7589 "Non-nil means prompt with menus when appropriate.\n\
7590 This is done when reading from a keymap that has a prompt string,\n\
7591 for elements that have prompt strings.\n\
7592 The menu is displayed on the screen\n\
7593 if X menus were enabled at configuration\n\
7594 time and the previous event was a mouse click prefix key.\n\
7595 Otherwise, menu prompting uses the echo area.");
7598 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
7599 "Character to see next line of menu prompt.\n\
7600 Type this character while in a menu prompt to rotate around the lines of it.");
7601 XSETINT (menu_prompt_more_char
, ' ');
7603 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
7604 "A mask of additional modifier keys to use with every keyboard character.\n\
7605 Emacs applies the modifiers of the character stored here to each keyboard\n\
7606 character it reads. For example, after evaluating the expression\n\
7607 (setq extra-keyboard-modifiers ?\\C-x)\n\
7608 all input characters will have the control modifier applied to them.\n\
7610 Note that the character ?\\C-@, equivalent to the integer zero, does\n\
7611 not count as a control character; rather, it counts as a character\n\
7612 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\
7613 cancels any modification.");
7614 extra_keyboard_modifiers
= 0;
7616 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
7617 "If an editing command sets this to t, deactivate the mark afterward.\n\
7618 The command loop sets this to nil before each command,\n\
7619 and tests the value when the command returns.\n\
7620 Buffer modification stores t in this variable.");
7621 Vdeactivate_mark
= Qnil
;
7623 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
7624 "Temporary storage of pre-command-hook or post-command-hook.");
7625 Vcommand_hook_internal
= Qnil
;
7627 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
7628 "Normal hook run before each command is executed.\n\
7629 Errors running the hook are caught and ignored.");
7630 Vpre_command_hook
= Qnil
;
7632 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
7633 "Normal hook run after each command is executed.\n\
7634 Errors running the hook are caught and ignored.");
7635 Vpost_command_hook
= Qnil
;
7637 DEFVAR_LISP ("post-command-idle-hook", &Vpost_command_idle_hook
,
7638 "Normal hook run after each command is executed, if idle.\n\
7639 Errors running the hook are caught and ignored.");
7640 Vpost_command_idle_hook
= Qnil
;
7642 DEFVAR_INT ("post-command-idle-delay", &post_command_idle_delay
,
7643 "Delay time before running `post-command-idle-delay'.\n\
7644 This is measured in microseconds.");
7645 post_command_idle_delay
= 100000;
7647 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
7648 "t means menu bar, specified Lucid style, needs to be recomputed.");
7649 Vlucid_menu_bar_dirty_flag
= Qnil
;
7651 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
7652 "List of menu bar items to move to the end of the menu bar.\n\
7653 The elements of the list are event types that may have menu bar bindings.");
7654 Vmenu_bar_final_items
= Qnil
;
7656 DEFVAR_KBOARD ("overriding-terminal-local-map",
7657 Voverriding_terminal_local_map
,
7658 "Keymap that overrides all other local keymaps.\n\
7659 If this variable is non-nil, it is used as a keymap instead of the\n\
7660 buffer's local map, and the minor mode keymaps and text property keymaps.");
7662 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
7663 "Keymap that overrides all other local keymaps.\n\
7664 If this variable is non-nil, it is used as a keymap instead of the\n\
7665 buffer's local map, and the minor mode keymaps and text property keymaps.");
7666 Voverriding_local_map
= Qnil
;
7668 DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag
,
7669 "Non-nil means `overriding-local-map' applies to the menu bar.\n\
7670 Otherwise, the menu bar continues to reflect the buffer's local map\n\
7671 and the minor mode maps regardless of `overriding-local-map'.");
7672 Voverriding_local_map_menu_flag
= Qnil
;
7674 DEFVAR_LISP ("special-event-map", &Vspecial_event_map
,
7675 "Keymap defining bindings for special events to execute at low level.");
7676 Vspecial_event_map
= Fcons (intern ("keymap"), Qnil
);
7678 DEFVAR_LISP ("track-mouse", &do_mouse_tracking
,
7679 "*Non-nil means generate motion events for mouse motion.");
7681 DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist
,
7682 "Alist of system-specific X windows key symbols.\n\
7683 Each element should have the form (N . SYMBOL) where N is the\n\
7684 numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\
7685 and SYMBOL is its name.");
7687 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
7688 "List of deferred actions to be performed at a later time.\n\
7689 The precise format isn't relevant here; we just check whether it is nil.");
7690 Vdeferred_action_list
= Qnil
;
7692 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
7693 "Function to call to handle deferred actions, after each command.\n\
7694 This function is called with no arguments after each command\n\
7695 whenever `deferred-action-list' is non-nil.");
7696 Vdeferred_action_function
= Qnil
;
7698 DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings
,
7699 "Non-nil means show the equivalent key-binding when M-x command has one.\n\
7700 The value can be a length of time to show the message for.\n\
7701 If the value is non-nil and not a number, we wait 2 seconds.");
7702 Vsuggest_key_bindings
= Qt
;
7704 DEFVAR_LISP ("column-number-mode", &Vcolumn_number_mode
,
7705 "Non-nil enables display of the current column number in the mode line.");
7706 Vcolumn_number_mode
= Qnil
;
7711 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
7712 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
7713 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
7714 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
7715 initial_define_key (meta_map
, 'x', "execute-extended-command");
7717 initial_define_lispy_key (Vspecial_event_map
, "delete-frame",
7718 "handle-delete-frame");
7719 initial_define_lispy_key (Vspecial_event_map
, "iconify-frame",
7721 initial_define_lispy_key (Vspecial_event_map
, "make-frame-visible",