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
)
907 echo_area_glyphs
= 0;
909 /* If the window system or terminal frame hasn't been initialized
910 yet, or we're not interactive, it's best to dump this message out
911 to stderr and exit. */
912 if (! FRAME_MESSAGE_BUF (selected_frame
)
914 stream
= Qexternal_debugging_output
;
923 write_string_1 (context
, -1, stream
);
925 print_error_message (data
, stream
);
927 /* If the window system or terminal frame hasn't been initialized
928 yet, or we're in -batch mode, this error should cause Emacs to exit. */
929 if (! FRAME_MESSAGE_BUF (selected_frame
)
933 Fkill_emacs (make_number (-1));
937 Lisp_Object
command_loop_1 ();
938 Lisp_Object
command_loop_2 ();
939 Lisp_Object
top_level_1 ();
941 /* Entry to editor-command-loop.
942 This level has the catches for exiting/returning to editor command loop.
943 It returns nil to exit recursive edit, t to abort it. */
948 if (command_loop_level
> 0 || minibuf_level
> 0)
950 return internal_catch (Qexit
, command_loop_2
, Qnil
);
955 internal_catch (Qtop_level
, top_level_1
, Qnil
);
956 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
958 /* End of file in -batch run causes exit here. */
964 /* Here we catch errors in execution of commands within the
965 editing loop, and reenter the editing loop.
966 When there is an error, cmd_error runs and returns a non-nil
967 value to us. A value of nil means that cmd_loop_1 itself
968 returned due to end of file (or end of kbd macro). */
973 register Lisp_Object val
;
976 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
985 return Feval (Vtop_level
);
991 /* On entry to the outer level, run the startup file */
992 if (!NILP (Vtop_level
))
993 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
994 else if (!NILP (Vpurify_flag
))
995 message ("Bare impure Emacs (standard Lisp code not loaded)");
997 message ("Bare Emacs (standard Lisp code not loaded)");
1001 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
1002 "Exit all recursive editing levels.")
1005 Fthrow (Qtop_level
, Qnil
);
1008 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
1009 "Exit from the innermost recursive edit or minibuffer.")
1012 if (command_loop_level
> 0 || minibuf_level
> 0)
1013 Fthrow (Qexit
, Qnil
);
1015 error ("No recursive edit is in progress");
1018 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
1019 "Abort the command that requested this recursive edit or minibuffer input.")
1022 if (command_loop_level
> 0 || minibuf_level
> 0)
1025 error ("No recursive edit is in progress");
1028 /* This is the actual command reading loop,
1029 sans error-handling encapsulation. */
1031 Lisp_Object
Fcommand_execute ();
1032 static int read_key_sequence ();
1033 void safe_run_hooks ();
1038 Lisp_Object cmd
, tem
;
1041 Lisp_Object keybuf
[30];
1046 struct buffer
*prev_buffer
;
1048 int was_locked
= single_kboard
;
1051 current_kboard
->Vprefix_arg
= Qnil
;
1052 Vdeactivate_mark
= Qnil
;
1053 waiting_for_input
= 0;
1058 this_command_key_count
= 0;
1060 /* Make sure this hook runs after commands that get errors and
1061 throw to top level. */
1062 /* Note that the value cell will never directly contain nil
1063 if the symbol is a local variable. */
1064 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1065 safe_run_hooks (Qpost_command_hook
);
1067 if (!NILP (Vdeferred_action_list
))
1068 call0 (Vdeferred_action_function
);
1070 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1072 if (NILP (Vunread_command_events
)
1073 && NILP (Vexecuting_macro
)
1074 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1)))
1075 safe_run_hooks (Qpost_command_idle_hook
);
1078 /* Do this after running Vpost_command_hook, for consistency. */
1079 current_kboard
->Vlast_command
= this_command
;
1083 /* Make sure the current window's buffer is selected. */
1084 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1085 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1087 /* Display any malloc warning that just came out. Use while because
1088 displaying one warning can cause another. */
1090 while (pending_malloc_warning
)
1091 display_malloc_warning ();
1095 Vdeactivate_mark
= Qnil
;
1097 /* If minibuffer on and echo area in use,
1098 wait 2 sec and redraw minibuffer. */
1100 if (minibuf_level
&& echo_area_glyphs
1101 && EQ (minibuf_window
, echo_area_window
))
1103 /* Bind inhibit-quit to t so that C-g gets read in
1104 rather than quitting back to the minibuffer. */
1105 int count
= specpdl_ptr
- specpdl
;
1106 specbind (Qinhibit_quit
, Qt
);
1107 Fsit_for (make_number (2), Qnil
, Qnil
);
1108 unbind_to (count
, Qnil
);
1110 echo_area_glyphs
= 0;
1112 if (!NILP (Vquit_flag
))
1115 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1120 alloca (0); /* Cause a garbage collection now */
1121 /* Since we can free the most stuff here. */
1122 #endif /* C_ALLOCA */
1126 /* Select the frame that the last event came from. Usually,
1127 switch-frame events will take care of this, but if some lisp
1128 code swallows a switch-frame event, we'll fix things up here.
1129 Is this a good idea? */
1130 if (FRAMEP (internal_last_event_frame
)
1131 && XFRAME (internal_last_event_frame
) != selected_frame
)
1132 Fselect_frame (internal_last_event_frame
, Qnil
);
1135 /* If it has changed current-menubar from previous value,
1136 really recompute the menubar from the value. */
1137 if (! NILP (Vlucid_menu_bar_dirty_flag
)
1138 && !NILP (Ffboundp (Qrecompute_lucid_menubar
)))
1139 call0 (Qrecompute_lucid_menubar
);
1141 before_command_key_count
= this_command_key_count
;
1142 before_command_echo_length
= echo_length ();
1144 this_command
= Qnil
;
1146 /* Read next key sequence; i gets its length. */
1147 i
= read_key_sequence (keybuf
, sizeof keybuf
/ sizeof keybuf
[0],
1152 /* Now we have read a key sequence of length I,
1153 or else I is 0 and we found end of file. */
1155 if (i
== 0) /* End of file -- happens only in */
1156 return Qnil
; /* a kbd macro, at the end. */
1157 /* -1 means read_key_sequence got a menu that was rejected.
1158 Just loop around and read another command. */
1162 this_command_key_count
= 0;
1166 last_command_char
= keybuf
[i
- 1];
1168 /* If the previous command tried to force a specific window-start,
1169 forget about that, in case this command moves point far away
1170 from that position. But also throw away beg_unchanged and
1171 end_unchanged information in that case, so that redisplay will
1172 update the whole window properly. */
1173 if (!NILP (XWINDOW (selected_window
)->force_start
))
1175 XWINDOW (selected_window
)->force_start
= Qnil
;
1176 beg_unchanged
= end_unchanged
= 0;
1179 cmd
= read_key_sequence_cmd
;
1180 if (!NILP (Vexecuting_macro
))
1182 if (!NILP (Vquit_flag
))
1184 Vexecuting_macro
= Qt
;
1185 QUIT
; /* Make some noise. */
1186 /* Will return since macro now empty. */
1190 /* Do redisplay processing after this command except in special
1191 cases identified below that set no_redisplay to 1.
1192 (actually, there's currently no way to prevent the redisplay,
1193 and no_redisplay is ignored.
1194 Perhaps someday we will really implement it.) */
1197 prev_buffer
= current_buffer
;
1198 prev_modiff
= MODIFF
;
1199 last_point_position
= PT
;
1200 XSETBUFFER (last_point_position_buffer
, prev_buffer
);
1202 /* Execute the command. */
1205 /* Note that the value cell will never directly contain nil
1206 if the symbol is a local variable. */
1207 if (!NILP (Vpre_command_hook
) && !NILP (Vrun_hooks
))
1208 safe_run_hooks (Qpre_command_hook
);
1210 if (NILP (this_command
))
1212 /* nil means key is undefined. */
1214 current_kboard
->defining_kbd_macro
= Qnil
;
1215 update_mode_lines
= 1;
1216 current_kboard
->Vprefix_arg
= Qnil
;
1220 if (NILP (current_kboard
->Vprefix_arg
) && ! no_direct
)
1222 /* Recognize some common commands in common situations and
1223 do them directly. */
1224 if (EQ (this_command
, Qforward_char
) && PT
< ZV
)
1226 struct Lisp_Char_Table
*dp
1227 = window_display_table (XWINDOW (selected_window
));
1228 lose
= FETCH_CHAR (PT
);
1231 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1232 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1233 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1234 && (lose
>= 0x20 && lose
< 0x7f)))
1235 : (lose
>= 0x20 && lose
< 0x7f))
1236 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1238 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1240 && !windows_or_buffers_changed
1241 && EQ (current_buffer
->selective_display
, Qnil
)
1242 && !detect_input_pending ()
1243 && NILP (Vcolumn_number_mode
)
1244 && NILP (Vexecuting_macro
))
1245 no_redisplay
= direct_output_forward_char (1);
1248 else if (EQ (this_command
, Qbackward_char
) && PT
> BEGV
)
1250 struct Lisp_Char_Table
*dp
1251 = window_display_table (XWINDOW (selected_window
));
1253 lose
= FETCH_CHAR (PT
);
1255 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1256 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1257 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1258 && (lose
>= 0x20 && lose
< 0x7f)))
1259 : (lose
>= 0x20 && lose
< 0x7f))
1260 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1262 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1264 && !windows_or_buffers_changed
1265 && EQ (current_buffer
->selective_display
, Qnil
)
1266 && !detect_input_pending ()
1267 && NILP (Vcolumn_number_mode
)
1268 && NILP (Vexecuting_macro
))
1269 no_redisplay
= direct_output_forward_char (-1);
1272 else if (EQ (this_command
, Qself_insert_command
)
1273 /* Try this optimization only on ascii keystrokes. */
1274 && INTEGERP (last_command_char
))
1276 unsigned char c
= XINT (last_command_char
);
1279 if (NILP (Vexecuting_macro
)
1280 && !EQ (minibuf_window
, selected_window
))
1282 if (!nonundocount
|| nonundocount
>= 20)
1289 lose
= ((XFASTINT (XWINDOW (selected_window
)->last_modified
)
1291 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1293 || MODIFF
<= SAVE_MODIFF
1294 || windows_or_buffers_changed
1295 || !EQ (current_buffer
->selective_display
, Qnil
)
1296 || detect_input_pending ()
1297 || !NILP (Vcolumn_number_mode
)
1298 || !NILP (Vexecuting_macro
));
1299 value
= internal_self_insert (c
, 0);
1306 && (PT
== ZV
|| FETCH_CHAR (PT
) == '\n'))
1308 struct Lisp_Char_Table
*dp
1309 = window_display_table (XWINDOW (selected_window
));
1316 obj
= DISP_CHAR_VECTOR (dp
, lose
);
1319 /* Do it only for char codes
1320 that by default display as themselves. */
1321 if (lose
>= 0x20 && lose
<= 0x7e)
1322 no_redisplay
= direct_output_for_insert (lose
);
1324 else if (VECTORP (obj
)
1325 && XVECTOR (obj
)->size
== 1
1326 && (obj
= XVECTOR (obj
)->contents
[0],
1328 /* Insist face not specified in glyph. */
1329 && (XINT (obj
) & ((-1) << 8)) == 0)
1331 = direct_output_for_insert (XINT (obj
));
1335 if (lose
>= 0x20 && lose
<= 0x7e)
1336 no_redisplay
= direct_output_for_insert (lose
);
1343 /* Here for a command that isn't executed directly */
1346 if (NILP (current_kboard
->Vprefix_arg
))
1348 Fcommand_execute (this_command
, Qnil
, Qnil
);
1353 /* Note that the value cell will never directly contain nil
1354 if the symbol is a local variable. */
1355 if (!NILP (Vpost_command_hook
) && !NILP (Vrun_hooks
))
1356 safe_run_hooks (Qpost_command_hook
);
1358 if (!NILP (Vdeferred_action_list
))
1359 safe_run_hooks (Qdeferred_action_function
);
1361 if (!NILP (Vpost_command_idle_hook
) && !NILP (Vrun_hooks
))
1363 if (NILP (Vunread_command_events
)
1364 && NILP (Vexecuting_macro
)
1365 && !NILP (sit_for (0, post_command_idle_delay
, 0, 1)))
1366 safe_run_hooks (Qpost_command_idle_hook
);
1369 /* If there is a prefix argument,
1370 1) We don't want Vlast_command to be ``universal-argument''
1371 (that would be dumb), so don't set Vlast_command,
1372 2) we want to leave echoing on so that the prefix will be
1373 echoed as part of this key sequence, so don't call
1375 3) we want to leave this_command_key_count non-zero, so that
1376 read_char will realize that it is re-reading a character, and
1377 not echo it a second time.
1379 If the command didn't actually create a prefix arg,
1380 but is merely a frame event that is transparent to prefix args,
1381 then the above doesn't apply. */
1382 if (NILP (current_kboard
->Vprefix_arg
) || CONSP (last_command_char
))
1384 current_kboard
->Vlast_command
= this_command
;
1386 this_command_key_count
= 0;
1389 if (!NILP (current_buffer
->mark_active
) && !NILP (Vrun_hooks
))
1391 if (!NILP (Vdeactivate_mark
) && !NILP (Vtransient_mark_mode
))
1393 current_buffer
->mark_active
= Qnil
;
1394 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
1396 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
1397 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
1401 /* Install chars successfully executed in kbd macro. */
1403 if (!NILP (current_kboard
->defining_kbd_macro
)
1404 && NILP (current_kboard
->Vprefix_arg
))
1405 finalize_kbd_macro_chars ();
1409 any_kboard_state ();
1414 /* Subroutine for safe_run_hooks: run the hook HOOK. */
1417 safe_run_hooks_1 (hook
)
1420 return call1 (Vrun_hooks
, Vinhibit_quit
);
1423 /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */
1426 safe_run_hooks_error (data
)
1429 Fset (Vinhibit_quit
, Qnil
);
1432 /* If we get an error while running the hook, cause the hook variable
1433 to be nil. Also inhibit quits, so that C-g won't cause the hook
1434 to mysteriously evaporate. */
1437 safe_run_hooks (hook
)
1441 int count
= specpdl_ptr
- specpdl
;
1442 specbind (Qinhibit_quit
, hook
);
1444 internal_condition_case (safe_run_hooks_1
, Qerror
, safe_run_hooks_error
);
1446 unbind_to (count
, Qnil
);
1449 /* Number of seconds between polling for input. */
1452 /* Nonzero means polling for input is temporarily suppressed. */
1453 int poll_suppress_count
;
1455 /* Nonzero if polling_for_input is actually being used. */
1456 int polling_for_input
;
1458 #ifdef POLL_FOR_INPUT
1460 /* Handle an alarm once each second and read pending input
1461 so as to handle a C-g if it comces in. */
1464 input_poll_signal (signalnum
) /* If we don't have an argument, */
1465 int signalnum
; /* some compilers complain in signal calls. */
1467 if (interrupt_input_blocked
== 0
1468 && !waiting_for_input
)
1469 read_avail_input (0);
1470 signal (SIGALRM
, input_poll_signal
);
1471 alarm (polling_period
);
1476 /* Begin signals to poll for input, if they are appropriate.
1477 This function is called unconditionally from various places. */
1481 #ifdef POLL_FOR_INPUT
1482 if (read_socket_hook
&& !interrupt_input
)
1484 poll_suppress_count
--;
1485 if (poll_suppress_count
== 0)
1487 signal (SIGALRM
, input_poll_signal
);
1488 polling_for_input
= 1;
1489 alarm (polling_period
);
1495 /* Nonzero if we are using polling to handle input asynchronously. */
1498 input_polling_used ()
1500 #ifdef POLL_FOR_INPUT
1501 return read_socket_hook
&& !interrupt_input
;
1507 /* Turn off polling. */
1511 #ifdef POLL_FOR_INPUT
1512 if (read_socket_hook
&& !interrupt_input
)
1514 if (poll_suppress_count
== 0)
1516 polling_for_input
= 0;
1519 poll_suppress_count
++;
1524 /* Set the value of poll_suppress_count to COUNT
1525 and start or stop polling accordingly. */
1528 set_poll_suppress_count (count
)
1531 #ifdef POLL_FOR_INPUT
1532 if (count
== 0 && poll_suppress_count
!= 0)
1534 poll_suppress_count
= 1;
1537 else if (count
!= 0 && poll_suppress_count
== 0)
1541 poll_suppress_count
= count
;
1545 /* Bind polling_period to a value at least N.
1546 But don't decrease it. */
1548 bind_polling_period (n
)
1551 #ifdef POLL_FOR_INPUT
1552 int new = polling_period
;
1558 specbind (Qpolling_period
, make_number (new));
1559 /* Start a new alarm with the new period. */
1564 /* Apply the control modifier to CHARACTER. */
1570 /* Save the upper bits here. */
1571 int upper
= c
& ~0177;
1575 /* Everything in the columns containing the upper-case letters
1576 denotes a control character. */
1577 if (c
>= 0100 && c
< 0140)
1581 /* Set the shift modifier for a control char
1582 made from a shifted letter. But only for letters! */
1583 if (oc
>= 'A' && oc
<= 'Z')
1584 c
|= shift_modifier
;
1587 /* The lower-case letters denote control characters too. */
1588 else if (c
>= 'a' && c
<= 'z')
1591 /* Include the bits for control and shift
1592 only if the basic ASCII code can't indicate them. */
1596 /* Replace the high bits. */
1597 c
|= (upper
& ~ctrl_modifier
);
1604 /* Input of single characters from keyboard */
1606 Lisp_Object
print_help ();
1607 static Lisp_Object
kbd_buffer_get_event ();
1608 static void record_char ();
1611 static jmp_buf wrong_kboard_jmpbuf
;
1614 /* read a character from the keyboard; call the redisplay if needed */
1615 /* commandflag 0 means do not do auto-saving, but do do redisplay.
1616 -1 means do not do redisplay, but do do autosaving.
1619 /* The arguments MAPS and NMAPS are for menu prompting.
1620 MAPS is an array of keymaps; NMAPS is the length of MAPS.
1622 PREV_EVENT is the previous input event, or nil if we are reading
1623 the first event of a key sequence.
1625 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
1626 if we used a mouse menu to read the input, or zero otherwise. If
1627 USED_MOUSE_MENU is null, we don't dereference it.
1629 Value is t if we showed a menu and the user rejected it. */
1632 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
)
1636 Lisp_Object prev_event
;
1637 int *used_mouse_menu
;
1639 register Lisp_Object c
;
1641 jmp_buf local_getcjmp
;
1643 int key_already_recorded
= 0;
1644 Lisp_Object tem
, save
;
1645 Lisp_Object also_record
;
1648 before_command_key_count
= this_command_key_count
;
1649 before_command_echo_length
= echo_length ();
1653 if (CONSP (Vunread_command_events
))
1655 c
= XCONS (Vunread_command_events
)->car
;
1656 Vunread_command_events
= XCONS (Vunread_command_events
)->cdr
;
1658 /* Undo what read_char_x_menu_prompt did when it unread
1659 additional keys returned by Fx_popup_menu. */
1661 && (SYMBOLP (XCONS (c
)->car
) || INTEGERP (XCONS (c
)->car
))
1662 && NILP (XCONS (c
)->cdr
))
1665 if (this_command_key_count
== 0)
1671 if (unread_command_char
!= -1)
1673 XSETINT (c
, unread_command_char
);
1674 unread_command_char
= -1;
1676 if (this_command_key_count
== 0)
1682 /* If there is no function key translated before
1683 reset-this-command-lengths takes effect, forget about it. */
1684 before_command_restore_flag
= 0;
1686 if (!NILP (Vexecuting_macro
))
1689 /* We set this to Qmacro; since that's not a frame, nobody will
1690 try to switch frames on us, and the selected window will
1693 Since this event came from a macro, it would be misleading to
1694 leave internal_last_event_frame set to wherever the last
1695 real event came from. Normally, a switch-frame event selects
1696 internal_last_event_frame after each command is read, but
1697 events read from a macro should never cause a new frame to be
1699 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
1702 /* Exit the macro if we are at the end.
1703 Also, some things replace the macro with t
1704 to force an early exit. */
1705 if (EQ (Vexecuting_macro
, Qt
)
1706 || executing_macro_index
>= XFASTINT (Flength (Vexecuting_macro
)))
1712 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
1713 if (STRINGP (Vexecuting_macro
)
1714 && (XINT (c
) & 0x80))
1715 XSETFASTINT (c
, CHAR_META
| (XINT (c
) & ~0x80));
1717 executing_macro_index
++;
1722 if (!NILP (unread_switch_frame
))
1724 c
= unread_switch_frame
;
1725 unread_switch_frame
= Qnil
;
1727 /* This event should make it into this_command_keys, and get echoed
1728 again, so we go to reread_first, rather than reread. */
1732 if (commandflag
>= 0 && !input_pending
&& !detect_input_pending ())
1735 /* Message turns off echoing unless more keystrokes turn it on again. */
1736 if (echo_area_glyphs
&& *echo_area_glyphs
1737 && echo_area_glyphs
!= current_kboard
->echobuf
1738 && ok_to_echo_at_next_pause
!= echo_area_glyphs
)
1741 /* If already echoing, continue. */
1744 /* Try reading a character via menu prompting in the minibuf.
1745 Try this before the sit-for, because the sit-for
1746 would do the wrong thing if we are supposed to do
1747 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
1748 after a mouse event so don't try a minibuf menu. */
1750 if (nmaps
> 0 && INTERACTIVE
1751 && !NILP (prev_event
) && ! EVENT_HAS_PARAMETERS (prev_event
)
1752 /* Don't bring up a menu if we already have another event. */
1753 && NILP (Vunread_command_events
)
1754 && unread_command_char
< 0
1755 && !detect_input_pending ())
1757 c
= read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
);
1760 key_already_recorded
= 1;
1765 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet.
1766 We will do that below, temporarily for short sections of code,
1767 when appropriate. local_getcjmp must be in effect
1768 around any call to sit_for or kbd_buffer_get_event;
1769 it *must not* be in effect when we call redisplay. */
1771 if (_setjmp (local_getcjmp
))
1773 XSETINT (c
, quit_char
);
1775 XSETFRAME (internal_last_event_frame
, selected_frame
);
1776 Vlast_event_frame
= internal_last_event_frame
;
1778 /* If we report the quit char as an event,
1779 don't do so more than once. */
1780 if (!NILP (Vinhibit_quit
))
1785 KBOARD
*kb
= FRAME_KBOARD (selected_frame
);
1786 if (kb
!= current_kboard
)
1788 Lisp_Object
*tailp
= &kb
->kbd_queue
;
1789 /* We shouldn't get here if we were in single-kboard mode! */
1792 while (CONSP (*tailp
))
1793 tailp
= &XCONS (*tailp
)->cdr
;
1796 *tailp
= Fcons (c
, Qnil
);
1797 kb
->kbd_queue_has_data
= 1;
1798 current_kboard
= kb
;
1799 longjmp (wrong_kboard_jmpbuf
, 1);
1806 /* If in middle of key sequence and minibuffer not active,
1807 start echoing if enough time elapses. */
1809 if (minibuf_level
== 0 && !current_kboard
->immediate_echo
1810 && this_command_key_count
> 0
1812 && echo_keystrokes
> 0
1813 && (echo_area_glyphs
== 0 || *echo_area_glyphs
== 0
1814 || ok_to_echo_at_next_pause
== echo_area_glyphs
))
1818 /* After a mouse event, start echoing right away.
1819 This is because we are probably about to display a menu,
1820 and we don't want to delay before doing so. */
1821 if (EVENT_HAS_PARAMETERS (prev_event
))
1825 save_getcjmp (save_jump
);
1826 restore_getcjmp (local_getcjmp
);
1827 tem0
= sit_for (echo_keystrokes
, 0, 1, 1);
1828 restore_getcjmp (save_jump
);
1834 /* Maybe auto save due to number of keystrokes. */
1836 if (commandflag
!= 0
1837 && auto_save_interval
> 0
1838 && num_nonmacro_input_chars
- last_auto_save
> max (auto_save_interval
, 20)
1839 && !detect_input_pending ())
1841 Fdo_auto_save (Qnil
, Qnil
);
1842 /* Hooks can actually change some buffers in auto save. */
1846 /* Try reading using an X menu.
1847 This is never confused with reading using the minibuf
1848 because the recursive call of read_char in read_char_minibuf_menu_prompt
1849 does not pass on any keymaps. */
1851 if (nmaps
> 0 && INTERACTIVE
1852 && !NILP (prev_event
)
1853 && EVENT_HAS_PARAMETERS (prev_event
)
1854 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
)
1855 /* Don't bring up a menu if we already have another event. */
1856 && NILP (Vunread_command_events
)
1857 && unread_command_char
< 0)
1858 c
= read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
1860 /* Maybe autosave and/or garbage collect due to idleness. */
1862 if (INTERACTIVE
&& NILP (c
))
1864 int delay_level
, buffer_size
;
1866 /* Slow down auto saves logarithmically in size of current buffer,
1867 and garbage collect while we're at it. */
1868 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
1869 last_non_minibuf_size
= Z
- BEG
;
1870 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
1872 while (buffer_size
> 64)
1873 delay_level
++, buffer_size
-= buffer_size
>> 2;
1874 if (delay_level
< 4) delay_level
= 4;
1875 /* delay_level is 4 for files under around 50k, 7 at 100k,
1876 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
1878 /* Auto save if enough time goes by without input. */
1879 if (commandflag
!= 0
1880 && num_nonmacro_input_chars
> last_auto_save
1881 && INTEGERP (Vauto_save_timeout
)
1882 && XINT (Vauto_save_timeout
) > 0)
1885 int delay
= delay_level
* XFASTINT (Vauto_save_timeout
) / 4;
1887 save_getcjmp (save_jump
);
1888 restore_getcjmp (local_getcjmp
);
1889 tem0
= sit_for (delay
, 0, 1, 1);
1890 restore_getcjmp (save_jump
);
1894 Fdo_auto_save (Qnil
, Qnil
);
1896 /* If we have auto-saved and there is still no input
1897 available, garbage collect if there has been enough
1898 consing going on to make it worthwhile. */
1899 if (!detect_input_pending ()
1900 && consing_since_gc
> gc_cons_threshold
/ 2)
1901 Fgarbage_collect ();
1908 /* Read something from current KBOARD's side queue, if possible. */
1912 if (current_kboard
->kbd_queue_has_data
)
1914 if (!CONSP (current_kboard
->kbd_queue
))
1916 c
= XCONS (current_kboard
->kbd_queue
)->car
;
1917 current_kboard
->kbd_queue
1918 = XCONS (current_kboard
->kbd_queue
)->cdr
;
1919 if (NILP (current_kboard
->kbd_queue
))
1920 current_kboard
->kbd_queue_has_data
= 0;
1921 input_pending
= readable_events ();
1923 if (EVENT_HAS_PARAMETERS (c
)
1924 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qswitch_frame
))
1925 internal_last_event_frame
= XCONS (XCONS (c
)->cdr
)->car
;
1926 Vlast_event_frame
= internal_last_event_frame
;
1932 /* If current_kboard's side queue is empty check the other kboards.
1933 If one of them has data that we have not yet seen here,
1934 switch to it and process the data waiting for it.
1936 Note: if the events queued up for another kboard
1937 have already been seen here, and therefore are not a complete command,
1938 the kbd_queue_has_data field is 0, so we skip that kboard here.
1939 That's to avoid an infinite loop switching between kboards here. */
1940 if (NILP (c
) && !single_kboard
)
1943 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
1944 if (kb
->kbd_queue_has_data
)
1946 current_kboard
= kb
;
1947 longjmp (wrong_kboard_jmpbuf
, 1);
1956 /* Finally, we read from the main queue,
1957 and if that gives us something we can't use yet, we put it on the
1958 appropriate side queue and try again. */
1964 /* Actually read a character, waiting if necessary. */
1965 save_getcjmp (save_jump
);
1966 restore_getcjmp (local_getcjmp
);
1967 c
= kbd_buffer_get_event (&kb
, used_mouse_menu
);
1968 restore_getcjmp (save_jump
);
1971 if (! NILP (c
) && (kb
!= current_kboard
))
1973 Lisp_Object
*tailp
= &kb
->kbd_queue
;
1974 while (CONSP (*tailp
))
1975 tailp
= &XCONS (*tailp
)->cdr
;
1978 *tailp
= Fcons (c
, Qnil
);
1979 kb
->kbd_queue_has_data
= 1;
1983 current_kboard
= kb
;
1984 longjmp (wrong_kboard_jmpbuf
, 1);
1989 /* Terminate Emacs in batch mode if at eof. */
1990 if (noninteractive
&& INTEGERP (c
) && XINT (c
) < 0)
1991 Fkill_emacs (make_number (1));
1995 /* Add in any extra modifiers, where appropriate. */
1996 if ((extra_keyboard_modifiers
& CHAR_CTL
)
1997 || ((extra_keyboard_modifiers
& 0177) < ' '
1998 && (extra_keyboard_modifiers
& 0177) != 0))
1999 XSETINT (c
, make_ctrl_char (XINT (c
)));
2001 /* Transfer any other modifier bits directly from
2002 extra_keyboard_modifiers to c. Ignore the actual character code
2003 in the low 16 bits of extra_keyboard_modifiers. */
2004 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
2013 if (commandflag
>= 0
2014 && !input_pending
&& !detect_input_pending ())
2022 /* Buffer switch events are only for internal wakeups
2023 so don't show them to the user. */
2027 if (key_already_recorded
)
2030 /* Process special events within read_char
2031 and loop around to read another event. */
2034 tem
= get_keyelt (access_keymap (get_keymap_1 (Vspecial_event_map
, 0, 0),
2040 last_input_char
= c
;
2041 Fcommand_execute (tem
, Qnil
, Fvector (1, &last_input_char
));
2045 /* Wipe the echo area. */
2046 echo_area_glyphs
= 0;
2048 /* Handle things that only apply to characters. */
2051 /* If kbd_buffer_get_event gave us an EOF, return that. */
2055 if (STRINGP (Vkeyboard_translate_table
)
2056 && XSTRING (Vkeyboard_translate_table
)->size
> XFASTINT (c
))
2057 XSETINT (c
, XSTRING (Vkeyboard_translate_table
)->data
[XFASTINT (c
)]);
2058 else if ((VECTORP (Vkeyboard_translate_table
)
2059 && XVECTOR (Vkeyboard_translate_table
)->size
> XFASTINT (c
))
2060 || CHAR_TABLE_P (Vkeyboard_translate_table
))
2063 d
= Faref (Vkeyboard_translate_table
, c
);
2064 /* nil in keyboard-translate-table means no translation. */
2070 /* If this event is a mouse click in the menu bar,
2071 return just menu-bar for now. Modify the mouse click event
2072 so we won't do this twice, then queue it up. */
2073 if (EVENT_HAS_PARAMETERS (c
)
2074 && CONSP (XCONS (c
)->cdr
)
2075 && CONSP (EVENT_START (c
))
2076 && CONSP (XCONS (EVENT_START (c
))->cdr
))
2080 posn
= POSN_BUFFER_POSN (EVENT_START (c
));
2081 /* Handle menu-bar events:
2082 insert the dummy prefix event `menu-bar'. */
2083 if (EQ (posn
, Qmenu_bar
))
2085 /* Change menu-bar to (menu-bar) as the event "position". */
2086 POSN_BUFFER_POSN (EVENT_START (c
)) = Fcons (posn
, Qnil
);
2089 Vunread_command_events
= Fcons (c
, Vunread_command_events
);
2095 if (! NILP (also_record
))
2096 record_char (also_record
);
2100 before_command_key_count
= this_command_key_count
;
2101 before_command_echo_length
= echo_length ();
2103 /* Don't echo mouse motion events. */
2105 && ! (EVENT_HAS_PARAMETERS (c
)
2106 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
2109 if (! NILP (also_record
))
2110 echo_char (also_record
);
2111 /* Once we reread a character, echoing can happen
2112 the next time we pause to read a new one. */
2113 ok_to_echo_at_next_pause
= echo_area_glyphs
;
2116 /* Record this character as part of the current key. */
2117 add_command_key (c
);
2118 if (! NILP (also_record
))
2119 add_command_key (also_record
);
2121 /* Re-reading in the middle of a command */
2123 last_input_char
= c
;
2126 /* Process the help character specially if enabled */
2127 if (!NILP (Vhelp_form
) && help_char_p (c
))
2130 count
= specpdl_ptr
- specpdl
;
2132 record_unwind_protect (Fset_window_configuration
,
2133 Fcurrent_window_configuration (Qnil
));
2135 tem0
= Feval (Vhelp_form
);
2137 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
2141 c
= read_char (0, 0, 0, Qnil
, 0);
2142 while (BUFFERP (c
));
2143 /* Remove the help from the frame */
2144 unbind_to (count
, Qnil
);
2147 if (EQ (c
, make_number (040)))
2151 c
= read_char (0, 0, 0, Qnil
, 0);
2152 while (BUFFERP (c
));
2159 /* Return 1 if should recognize C as "the help character". */
2167 if (EQ (c
, Vhelp_char
))
2169 for (tail
= Vhelp_event_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
2170 if (EQ (c
, XCONS (tail
)->car
))
2175 /* Record the input event C in various ways. */
2182 XVECTOR (recent_keys
)->contents
[recent_keys_index
] = c
;
2183 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
2184 recent_keys_index
= 0;
2186 /* Write c to the dribble file. If c is a lispy event, write
2187 the event's symbol to the dribble file, in <brackets>. Bleaugh.
2188 If you, dear reader, have a better idea, you've got the source. :-) */
2193 if (XUINT (c
) < 0x100)
2194 putc (XINT (c
), dribble
);
2196 fprintf (dribble
, " 0x%x", (int) XUINT (c
));
2200 Lisp_Object dribblee
;
2202 /* If it's a structured event, take the event header. */
2203 dribblee
= EVENT_HEAD (c
);
2205 if (SYMBOLP (dribblee
))
2207 putc ('<', dribble
);
2208 fwrite (XSYMBOL (dribblee
)->name
->data
, sizeof (char),
2209 XSYMBOL (dribblee
)->name
->size
,
2211 putc ('>', dribble
);
2218 store_kbd_macro_char (c
);
2220 num_nonmacro_input_chars
++;
2227 struct buffer
*old
= current_buffer
;
2228 Fprinc (object
, Qnil
);
2229 set_buffer_internal (XBUFFER (Vstandard_output
));
2230 call0 (intern ("help-mode"));
2231 set_buffer_internal (old
);
2235 /* Copy out or in the info on where C-g should throw to.
2236 This is used when running Lisp code from within get_char,
2237 in case get_char is called recursively.
2238 See read_process_output. */
2243 bcopy (getcjmp
, temp
, sizeof getcjmp
);
2246 restore_getcjmp (temp
)
2249 bcopy (temp
, getcjmp
, sizeof getcjmp
);
2254 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
2255 of this function. */
2258 tracking_off (old_value
)
2259 Lisp_Object old_value
;
2261 do_mouse_tracking
= old_value
;
2262 if (NILP (old_value
))
2264 /* Redisplay may have been preempted because there was input
2265 available, and it assumes it will be called again after the
2266 input has been processed. If the only input available was
2267 the sort that we have just disabled, then we need to call
2269 if (!readable_events ())
2271 redisplay_preserve_echo_area ();
2272 get_input_pending (&input_pending
);
2277 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
2278 "Evaluate BODY with mouse movement events enabled.\n\
2279 Within a `track-mouse' form, mouse motion generates input events that\n\
2280 you can read with `read-event'.\n\
2281 Normally, mouse motion is ignored.")
2285 int count
= specpdl_ptr
- specpdl
;
2288 record_unwind_protect (tracking_off
, do_mouse_tracking
);
2290 do_mouse_tracking
= Qt
;
2292 val
= Fprogn (args
);
2293 return unbind_to (count
, val
);
2296 /* If mouse has moved on some frame, return one of those frames.
2297 Return 0 otherwise. */
2302 Lisp_Object tail
, frame
;
2304 FOR_EACH_FRAME (tail
, frame
)
2306 if (XFRAME (frame
)->mouse_moved
)
2307 return XFRAME (frame
);
2313 #endif /* HAVE_MOUSE */
2315 /* Low level keyboard/mouse input.
2316 kbd_buffer_store_event places events in kbd_buffer, and
2317 kbd_buffer_get_event retrieves them. */
2319 /* Return true iff there are any events in the queue that read-char
2320 would return. If this returns false, a read-char would block. */
2324 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2327 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2332 if (current_kboard
->kbd_queue_has_data
)
2338 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2339 if (kb
->kbd_queue_has_data
)
2345 /* Set this for debugging, to have a way to get out */
2350 event_to_kboard (event
)
2351 struct input_event
*event
;
2354 frame
= event
->frame_or_window
;
2356 frame
= XCONS (frame
)->car
;
2357 else if (WINDOWP (frame
))
2358 frame
= WINDOW_FRAME (XWINDOW (frame
));
2360 /* There are still some events that don't set this field.
2361 For now, just ignore the problem.
2362 Also ignore dead frames here. */
2363 if (!FRAMEP (frame
) || !FRAME_LIVE_P (XFRAME (frame
)))
2366 return FRAME_KBOARD (XFRAME (frame
));
2370 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
2373 kbd_buffer_store_event (event
)
2374 register struct input_event
*event
;
2376 if (event
->kind
== no_event
)
2379 if (event
->kind
== ascii_keystroke
)
2381 register int c
= event
->code
& 0377;
2383 if (event
->modifiers
& ctrl_modifier
)
2384 c
= make_ctrl_char (c
);
2386 c
|= (event
->modifiers
2387 & (meta_modifier
| alt_modifier
2388 | hyper_modifier
| super_modifier
));
2392 extern SIGTYPE
interrupt_signal ();
2395 struct input_event
*sp
;
2398 && (kb
= FRAME_KBOARD (XFRAME (event
->frame_or_window
)),
2399 kb
!= current_kboard
))
2402 = Fcons (make_lispy_switch_frame (event
->frame_or_window
),
2403 Fcons (make_number (c
), Qnil
));
2404 kb
->kbd_queue_has_data
= 1;
2405 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
2407 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
2410 if (event_to_kboard (sp
) == kb
)
2412 sp
->kind
= no_event
;
2413 sp
->frame_or_window
= Qnil
;
2421 /* If this results in a quit_char being returned to Emacs as
2422 input, set Vlast_event_frame properly. If this doesn't
2423 get returned to Emacs as an event, the next event read
2424 will set Vlast_event_frame again, so this is safe to do. */
2428 focus
= FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
2430 focus
= event
->frame_or_window
;
2431 internal_last_event_frame
= focus
;
2432 Vlast_event_frame
= focus
;
2436 last_event_timestamp
= event
->timestamp
;
2437 interrupt_signal ();
2441 if (c
&& c
== stop_character
)
2447 /* Don't insert two buffer_switch_event's in a row.
2448 Just ignore the second one. */
2449 else if (event
->kind
== buffer_switch_event
2450 && kbd_fetch_ptr
!= kbd_store_ptr
2451 && kbd_store_ptr
->kind
== buffer_switch_event
)
2454 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
2455 kbd_store_ptr
= kbd_buffer
;
2457 /* Don't let the very last slot in the buffer become full,
2458 since that would make the two pointers equal,
2459 and that is indistinguishable from an empty buffer.
2460 Discard the event if it would fill the last slot. */
2461 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
2463 volatile struct input_event
*sp
= kbd_store_ptr
;
2464 sp
->kind
= event
->kind
;
2465 if (event
->kind
== selection_request_event
)
2467 /* We must not use the ordinary copying code for this case,
2468 since `part' is an enum and copying it might not copy enough
2470 bcopy (event
, (char *) sp
, sizeof (*event
));
2474 sp
->code
= event
->code
;
2475 sp
->part
= event
->part
;
2476 sp
->frame_or_window
= event
->frame_or_window
;
2477 sp
->modifiers
= event
->modifiers
;
2480 sp
->timestamp
= event
->timestamp
;
2482 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_store_ptr
2484 = event
->frame_or_window
);
2490 /* Read one event from the event buffer, waiting if necessary.
2491 The value is a Lisp object representing the event.
2492 The value is nil for an event that should be ignored,
2493 or that was handled here.
2494 We always read and discard one event. */
2497 kbd_buffer_get_event (kbp
, used_mouse_menu
)
2499 int *used_mouse_menu
;
2508 *kbp
= current_kboard
;
2512 /* Wait until there is input available. */
2515 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2518 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2522 /* If the quit flag is set, then read_char will return
2523 quit_char, so that counts as "available input." */
2524 if (!NILP (Vquit_flag
))
2525 quit_throw_to_read_char ();
2527 /* One way or another, wait until input is available; then, if
2528 interrupt handlers have not read it, read it now. */
2531 wait_for_kbd_input ();
2533 /* Note SIGIO has been undef'd if FIONREAD is missing. */
2537 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2540 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2544 Lisp_Object minus_one
;
2546 XSETINT (minus_one
, -1);
2547 wait_reading_process_input (0, 0, minus_one
, 1);
2549 if (!interrupt_input
&& kbd_fetch_ptr
== kbd_store_ptr
)
2550 /* Pass 1 for EXPECT since we just waited to have input. */
2551 read_avail_input (1);
2553 #endif /* not VMS */
2556 /* At this point, we know that there is a readable event available
2557 somewhere. If the event queue is empty, then there must be a
2558 mouse movement enabled and available. */
2559 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2561 struct input_event
*event
;
2563 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2567 last_event_timestamp
= event
->timestamp
;
2570 *kbp
= event_to_kboard (event
);
2572 *kbp
= current_kboard
; /* Better than returning null ptr? */
2574 *kbp
= &the_only_kboard
;
2579 /* These two kinds of events get special handling
2580 and don't actually appear to the command loop.
2581 We return nil for them. */
2582 if (event
->kind
== selection_request_event
)
2585 struct input_event copy
;
2587 /* Remove it from the buffer before processing it,
2588 since otherwise swallow_events will see it
2589 and process it again. */
2591 kbd_fetch_ptr
= event
+ 1;
2592 input_pending
= readable_events ();
2593 x_handle_selection_request (©
);
2595 /* We're getting selection request events, but we don't have
2601 else if (event
->kind
== selection_clear_event
)
2604 struct input_event copy
;
2606 /* Remove it from the buffer before processing it. */
2608 kbd_fetch_ptr
= event
+ 1;
2609 input_pending
= readable_events ();
2610 x_handle_selection_clear (©
);
2612 /* We're getting selection request events, but we don't have
2617 #if defined (HAVE_X11) || defined (HAVE_NTGUI)
2618 else if (event
->kind
== delete_window_event
)
2620 /* Make an event (delete-frame (FRAME)). */
2621 obj
= Fcons (event
->frame_or_window
, Qnil
);
2622 obj
= Fcons (Qdelete_frame
, Fcons (obj
, Qnil
));
2623 kbd_fetch_ptr
= event
+ 1;
2625 else if (event
->kind
== iconify_event
)
2627 /* Make an event (iconify-frame (FRAME)). */
2628 obj
= Fcons (event
->frame_or_window
, Qnil
);
2629 obj
= Fcons (Qiconify_frame
, Fcons (obj
, Qnil
));
2630 kbd_fetch_ptr
= event
+ 1;
2632 else if (event
->kind
== deiconify_event
)
2634 /* Make an event (make-frame-visible (FRAME)). */
2635 obj
= Fcons (event
->frame_or_window
, Qnil
);
2636 obj
= Fcons (Qmake_frame_visible
, Fcons (obj
, Qnil
));
2637 kbd_fetch_ptr
= event
+ 1;
2640 else if (event
->kind
== buffer_switch_event
)
2642 /* The value doesn't matter here; only the type is tested. */
2643 XSETBUFFER (obj
, current_buffer
);
2644 kbd_fetch_ptr
= event
+ 1;
2646 #ifdef USE_X_TOOLKIT
2647 else if (event
->kind
== menu_bar_activate_event
)
2649 kbd_fetch_ptr
= event
+ 1;
2650 input_pending
= readable_events ();
2651 x_activate_menubar (XFRAME (event
->frame_or_window
));
2654 /* Just discard these, by returning nil.
2655 With MULTI_KBOARD, these events are used as placeholders
2656 when we need to randomly delete events from the queue.
2657 (They shouldn't otherwise be found in the buffer,
2658 but on some machines it appears they do show up
2659 even without MULTI_KBOARD.) */
2660 else if (event
->kind
== no_event
)
2661 kbd_fetch_ptr
= event
+ 1;
2663 /* If this event is on a different frame, return a switch-frame this
2664 time, and leave the event in the queue for next time. */
2671 frame
= event
->frame_or_window
;
2673 frame
= XCONS (frame
)->car
;
2674 else if (WINDOWP (frame
))
2675 frame
= WINDOW_FRAME (XWINDOW (frame
));
2677 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
2681 if (! EQ (frame
, internal_last_event_frame
)
2682 && XFRAME (frame
) != selected_frame
)
2683 obj
= make_lispy_switch_frame (frame
);
2684 internal_last_event_frame
= frame
;
2685 #endif /* MULTI_FRAME */
2687 /* If we didn't decide to make a switch-frame event, go ahead
2688 and build a real event from the queue entry. */
2692 obj
= make_lispy_event (event
);
2693 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
2694 /* If this was a menu selection, then set the flag to inhibit
2695 writing to last_nonmenu_event. Don't do this if the event
2696 we're returning is (menu-bar), though; that indicates the
2697 beginning of the menu sequence, and we might as well leave
2698 that as the `event with parameters' for this selection. */
2699 if (event
->kind
== menu_bar_event
2700 && !(CONSP (obj
) && EQ (XCONS (obj
)->car
, Qmenu_bar
))
2702 *used_mouse_menu
= 1;
2705 /* Wipe out this event, to catch bugs. */
2706 event
->kind
= no_event
;
2707 XVECTOR (kbd_buffer_frame_or_window
)->contents
[event
- kbd_buffer
] = Qnil
;
2709 kbd_fetch_ptr
= event
+ 1;
2714 /* Try generating a mouse motion event. */
2715 else if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2717 FRAME_PTR f
= some_mouse_moved ();
2718 Lisp_Object bar_window
;
2719 enum scroll_bar_part part
;
2723 *kbp
= current_kboard
;
2724 /* Note that this uses F to determine which display to look at.
2725 If there is no valid info, it does not store anything
2726 so x remains nil. */
2728 (*mouse_position_hook
) (&f
, 0, &bar_window
, &part
, &x
, &y
, &time
);
2733 /* Decide if we should generate a switch-frame event. Don't
2734 generate switch-frame events for motion outside of all Emacs
2740 frame
= FRAME_FOCUS_FRAME (f
);
2742 XSETFRAME (frame
, f
);
2744 if (! EQ (frame
, internal_last_event_frame
)
2745 && XFRAME (frame
) != selected_frame
)
2746 obj
= make_lispy_switch_frame (frame
);
2747 internal_last_event_frame
= frame
;
2751 /* If we didn't decide to make a switch-frame event, go ahead and
2752 return a mouse-motion event. */
2753 if (!NILP (x
) && NILP (obj
))
2754 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
2756 #endif /* HAVE_MOUSE */
2758 /* We were promised by the above while loop that there was
2759 something for us to read! */
2762 input_pending
= readable_events ();
2765 Vlast_event_frame
= internal_last_event_frame
;
2771 /* Process any events that are not user-visible,
2772 then return, without reading any user-visible events. */
2777 while (kbd_fetch_ptr
!= kbd_store_ptr
)
2779 struct input_event
*event
;
2781 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2785 last_event_timestamp
= event
->timestamp
;
2787 /* These two kinds of events get special handling
2788 and don't actually appear to the command loop. */
2789 if (event
->kind
== selection_request_event
)
2792 struct input_event copy
;
2794 /* Remove it from the buffer before processing it,
2795 since otherwise swallow_events called recursively could see it
2796 and process it again. */
2798 kbd_fetch_ptr
= event
+ 1;
2799 input_pending
= readable_events ();
2800 x_handle_selection_request (©
);
2802 /* We're getting selection request events, but we don't have
2808 else if (event
->kind
== selection_clear_event
)
2811 struct input_event copy
;
2813 /* Remove it from the buffer before processing it, */
2816 kbd_fetch_ptr
= event
+ 1;
2817 input_pending
= readable_events ();
2818 x_handle_selection_clear (©
);
2820 /* We're getting selection request events, but we don't have
2829 get_input_pending (&input_pending
);
2832 /* Caches for modify_event_symbol. */
2833 static Lisp_Object accent_key_syms
;
2834 static Lisp_Object func_key_syms
;
2835 static Lisp_Object mouse_syms
;
2837 /* This is a list of keysym codes for special "accent" characters.
2838 It parallels lispy_accent_keys. */
2840 static int lispy_accent_codes
[] =
2842 #ifdef XK_dead_circumflex
2847 #ifdef XK_dead_grave
2852 #ifdef XK_dead_tilde
2857 #ifdef XK_dead_diaeresis
2862 #ifdef XK_dead_macron
2867 #ifdef XK_dead_degree
2872 #ifdef XK_dead_acute
2877 #ifdef XK_dead_cedilla
2882 #ifdef XK_dead_breve
2887 #ifdef XK_dead_ogonek
2892 #ifdef XK_dead_caron
2897 #ifdef XK_dead_doubleacute
2898 XK_dead_doubleacute
,
2902 #ifdef XK_dead_abovedot
2909 /* This is a list of Lisp names for special "accent" characters.
2910 It parallels lispy_accent_codes. */
2912 static char *lispy_accent_keys
[] =
2930 #define FUNCTION_KEY_OFFSET 0x0
2932 char *lispy_function_keys
[] =
2936 0, /* VK_LBUTTON 0x01 */
2937 0, /* VK_RBUTTON 0x02 */
2938 "cancel", /* VK_CANCEL 0x03 */
2939 0, /* VK_MBUTTON 0x04 */
2941 0, 0, 0, /* 0x05 .. 0x07 */
2943 "backspace", /* VK_BACK 0x08 */
2944 "tab", /* VK_TAB 0x09 */
2946 0, 0, /* 0x0A .. 0x0B */
2948 "clear", /* VK_CLEAR 0x0C */
2949 "return", /* VK_RETURN 0x0D */
2951 0, 0, /* 0x0E .. 0x0F */
2953 "shift", /* VK_SHIFT 0x10 */
2954 "control", /* VK_CONTROL 0x11 */
2955 "menu", /* VK_MENU 0x12 */
2956 "pause", /* VK_PAUSE 0x13 */
2957 "capital", /* VK_CAPITAL 0x14 */
2959 0, 0, 0, 0, 0, 0, /* 0x15 .. 0x1A */
2961 0, /* VK_ESCAPE 0x1B */
2963 0, 0, 0, 0, /* 0x1C .. 0x1F */
2965 0, /* VK_SPACE 0x20 */
2966 "prior", /* VK_PRIOR 0x21 */
2967 "next", /* VK_NEXT 0x22 */
2968 "end", /* VK_END 0x23 */
2969 "home", /* VK_HOME 0x24 */
2970 "left", /* VK_LEFT 0x25 */
2971 "up", /* VK_UP 0x26 */
2972 "right", /* VK_RIGHT 0x27 */
2973 "down", /* VK_DOWN 0x28 */
2974 "select", /* VK_SELECT 0x29 */
2975 "print", /* VK_PRINT 0x2A */
2976 "execute", /* VK_EXECUTE 0x2B */
2977 "snapshot", /* VK_SNAPSHOT 0x2C */
2978 "insert", /* VK_INSERT 0x2D */
2979 "delete", /* VK_DELETE 0x2E */
2980 "help", /* VK_HELP 0x2F */
2982 /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
2984 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2986 0, 0, 0, 0, 0, 0, 0, /* 0x3A .. 0x40 */
2988 /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
2990 0, 0, 0, 0, 0, 0, 0, 0, 0,
2991 0, 0, 0, 0, 0, 0, 0, 0, 0,
2992 0, 0, 0, 0, 0, 0, 0, 0,
2994 0, /* VK_LWIN 0x5B */
2995 0, /* VK_RWIN 0x5C */
2996 0, /* VK_APPS 0x5D */
2998 0, 0, /* 0x5E .. 0x5F */
3000 "kp-0", /* VK_NUMPAD0 0x60 */
3001 "kp-1", /* VK_NUMPAD1 0x61 */
3002 "kp-2", /* VK_NUMPAD2 0x62 */
3003 "kp-3", /* VK_NUMPAD3 0x63 */
3004 "kp-4", /* VK_NUMPAD4 0x64 */
3005 "kp-5", /* VK_NUMPAD5 0x65 */
3006 "kp-6", /* VK_NUMPAD6 0x66 */
3007 "kp-7", /* VK_NUMPAD7 0x67 */
3008 "kp-8", /* VK_NUMPAD8 0x68 */
3009 "kp-9", /* VK_NUMPAD9 0x69 */
3010 "kp-multiply", /* VK_MULTIPLY 0x6A */
3011 "kp-add", /* VK_ADD 0x6B */
3012 "kp-separator", /* VK_SEPARATOR 0x6C */
3013 "kp-subtract", /* VK_SUBTRACT 0x6D */
3014 "kp-decimal", /* VK_DECIMAL 0x6E */
3015 "kp-divide", /* VK_DIVIDE 0x6F */
3016 "f1", /* VK_F1 0x70 */
3017 "f2", /* VK_F2 0x71 */
3018 "f3", /* VK_F3 0x72 */
3019 "f4", /* VK_F4 0x73 */
3020 "f5", /* VK_F5 0x74 */
3021 "f6", /* VK_F6 0x75 */
3022 "f7", /* VK_F7 0x76 */
3023 "f8", /* VK_F8 0x77 */
3024 "f9", /* VK_F9 0x78 */
3025 "f10", /* VK_F10 0x79 */
3026 "f11", /* VK_F11 0x7A */
3027 "f12", /* VK_F12 0x7B */
3028 "f13", /* VK_F13 0x7C */
3029 "f14", /* VK_F14 0x7D */
3030 "f15", /* VK_F15 0x7E */
3031 "f16", /* VK_F16 0x7F */
3032 "f17", /* VK_F17 0x80 */
3033 "f18", /* VK_F18 0x81 */
3034 "f19", /* VK_F19 0x82 */
3035 "f20", /* VK_F20 0x83 */
3036 "f21", /* VK_F21 0x84 */
3037 "f22", /* VK_F22 0x85 */
3038 "f23", /* VK_F23 0x86 */
3039 "f24", /* VK_F24 0x87 */
3041 0, 0, 0, 0, /* 0x88 .. 0x8B */
3042 0, 0, 0, 0, /* 0x8C .. 0x8F */
3044 "kp-numlock", /* VK_NUMLOCK 0x90 */
3045 "scroll", /* VK_SCROLL 0x91 */
3047 0, 0, 0, 0, 0, /* 0x92 .. 0x96 */
3048 0, 0, 0, 0, 0, /* 0x97 .. 0x9B */
3049 0, 0, 0, 0, /* 0x9C .. 0x9F */
3052 * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
3053 * Used only as parameters to GetAsyncKeyState() and GetKeyState().
3054 * No other API or message will distinguish left and right keys this way.
3058 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3059 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3060 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3061 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3062 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3068 "attn", /* VK_ATTN 0xF6 */
3069 "crsel", /* VK_CRSEL 0xF7 */
3070 "exsel", /* VK_EXSEL 0xF8 */
3071 "ereof", /* VK_EREOF 0xF9 */
3072 "play", /* VK_PLAY 0xFA */
3073 "zoom", /* VK_ZOOM 0xFB */
3074 "noname", /* VK_NONAME 0xFC */
3075 "pa1", /* VK_PA1 0xFD */
3076 "oem_clear", /* VK_OEM_CLEAR 0xFE */
3081 #define FUNCTION_KEY_OFFSET 0xff00
3083 /* You'll notice that this table is arranged to be conveniently
3084 indexed by X Windows keysym values. */
3085 static char *lispy_function_keys
[] =
3087 /* X Keysym value */
3089 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00 */
3097 0, 0, 0, /* 0xff10 */
3099 0, 0, 0, 0, 0, 0, 0,
3102 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff20...2f */
3103 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff30...3f */
3104 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
3106 "home", /* 0xff50 */ /* IsCursorKey */
3117 "select", /* 0xff60 */ /* IsMiscFunctionKey */
3128 "break", /* 0xff6b */
3130 0, 0, 0, 0, 0, 0, 0, 0, "backtab", 0,
3132 0, 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff7f */
3133 "kp-space", /* 0xff80 */ /* IsKeypadKey */
3134 0, 0, 0, 0, 0, 0, 0, 0,
3135 "kp-tab", /* 0xff89 */
3137 "kp-enter", /* 0xff8d */
3139 "kp-f1", /* 0xff91 */
3143 "kp-home", /* 0xff95 */
3148 "kp-prior", /* kp-page-up */
3149 "kp-next", /* kp-page-down */
3155 0, 0, 0, 0, 0, 0, 0, 0, 0,
3156 "kp-multiply", /* 0xffaa */
3161 "kp-divide", /* 0xffaf */
3162 "kp-0", /* 0xffb0 */
3163 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
3166 "kp-equal", /* 0xffbd */
3167 "f1", /* 0xffbe */ /* IsFunctionKey */
3169 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
3170 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
3171 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
3172 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
3173 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
3174 0, 0, 0, 0, 0, 0, 0, 0,
3175 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
3176 0, 0, 0, 0, 0, 0, 0, "delete"
3179 #endif /* HAVE_NTGUI */
3181 static char *lispy_mouse_names
[] =
3183 "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5"
3186 /* Scroll bar parts. */
3187 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
3189 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
3190 Lisp_Object
*scroll_bar_parts
[] = {
3191 &Qabove_handle
, &Qhandle
, &Qbelow_handle
3195 /* A vector, indexed by button number, giving the down-going location
3196 of currently depressed buttons, both scroll bar and non-scroll bar.
3198 The elements have the form
3199 (BUTTON-NUMBER MODIFIER-MASK . REST)
3200 where REST is the cdr of a position as it would be reported in the event.
3202 The make_lispy_event function stores positions here to tell the
3203 difference between click and drag events, and to store the starting
3204 location to be included in drag events. */
3206 static Lisp_Object button_down_location
;
3208 /* Information about the most recent up-going button event: Which
3209 button, what location, and what time. */
3211 static int last_mouse_button
;
3212 static int last_mouse_x
;
3213 static int last_mouse_y
;
3214 static unsigned long button_down_time
;
3216 /* The maximum time between clicks to make a double-click,
3217 or Qnil to disable double-click detection,
3218 or Qt for no time limit. */
3219 Lisp_Object Vdouble_click_time
;
3221 /* The number of clicks in this multiple-click. */
3223 int double_click_count
;
3225 /* Given a struct input_event, build the lisp event which represents
3226 it. If EVENT is 0, build a mouse movement event from the mouse
3227 movement buffer, which should have a movement event in it.
3229 Note that events must be passed to this function in the order they
3230 are received; this function stores the location of button presses
3231 in order to build drag events when the button is released. */
3234 make_lispy_event (event
)
3235 struct input_event
*event
;
3239 switch (SWITCH_ENUM_CAST (event
->kind
))
3241 /* A simple keystroke. */
3242 case ascii_keystroke
:
3244 Lisp_Object lispy_c
;
3245 int c
= event
->code
& 0377;
3246 /* Turn ASCII characters into control characters
3248 if (event
->modifiers
& ctrl_modifier
)
3249 c
= make_ctrl_char (c
);
3251 /* Add in the other modifier bits. We took care of ctrl_modifier
3252 just above, and the shift key was taken care of by the X code,
3253 and applied to control characters by make_ctrl_char. */
3254 c
|= (event
->modifiers
3255 & (meta_modifier
| alt_modifier
3256 | hyper_modifier
| super_modifier
));
3257 button_down_time
= 0;
3258 XSETFASTINT (lispy_c
, c
);
3262 /* A function key. The symbol may need to have modifier prefixes
3264 case non_ascii_keystroke
:
3265 button_down_time
= 0;
3267 for (i
= 0; i
< sizeof (lispy_accent_codes
) / sizeof (int); i
++)
3268 if (event
->code
== lispy_accent_codes
[i
])
3269 return modify_event_symbol (i
,
3271 Qfunction_key
, Qnil
,
3272 lispy_accent_keys
, &accent_key_syms
,
3273 (sizeof (lispy_accent_keys
)
3274 / sizeof (lispy_accent_keys
[0])));
3276 /* Handle system-specific keysyms. */
3277 if (event
->code
& (1 << 28))
3279 /* We need to use an alist rather than a vector as the cache
3280 since we can't make a vector long enuf. */
3281 if (NILP (current_kboard
->system_key_syms
))
3282 current_kboard
->system_key_syms
= Fcons (Qnil
, Qnil
);
3283 return modify_event_symbol (event
->code
,
3286 current_kboard
->Vsystem_key_alist
,
3287 0, ¤t_kboard
->system_key_syms
,
3291 return modify_event_symbol (event
->code
- FUNCTION_KEY_OFFSET
,
3293 Qfunction_key
, Qnil
,
3294 lispy_function_keys
, &func_key_syms
,
3295 (sizeof (lispy_function_keys
)
3296 / sizeof (lispy_function_keys
[0])));
3300 /* A mouse click. Figure out where it is, decide whether it's
3301 a press, click or drag, and build the appropriate structure. */
3303 case scroll_bar_click
:
3305 int button
= event
->code
;
3307 Lisp_Object position
;
3308 Lisp_Object
*start_pos_ptr
;
3309 Lisp_Object start_pos
;
3311 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
3314 /* Build the position as appropriate for this mouse click. */
3315 if (event
->kind
== mouse_click
)
3318 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
3323 /* Ignore mouse events that were made on frame that
3324 have been deleted. */
3325 if (! FRAME_LIVE_P (f
))
3328 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
3329 &column
, &row
, NULL
, 1);
3331 #ifndef USE_X_TOOLKIT
3332 /* In the non-toolkit version, clicks on the menu bar
3333 are ordinary button events in the event buffer.
3334 Distinguish them, and invoke the menu.
3336 (In the toolkit version, the toolkit handles the menu bar
3337 and Emacs doesn't know about it until after the user
3338 makes a selection.) */
3339 if (row
>= 0 && row
< FRAME_MENU_BAR_LINES (f
)
3340 && (event
->modifiers
& down_modifier
))
3342 Lisp_Object items
, item
;
3347 /* Activate the menu bar on the down event. If the
3348 up event comes in before the menu code can deal with it,
3350 if (! (event
->modifiers
& down_modifier
))
3355 items
= FRAME_MENU_BAR_ITEMS (f
);
3356 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 3)
3358 Lisp_Object pos
, string
;
3359 string
= XVECTOR (items
)->contents
[i
+ 1];
3360 pos
= XVECTOR (items
)->contents
[i
+ 2];
3363 if (column
>= XINT (pos
)
3364 && column
< XINT (pos
) + XSTRING (string
)->size
)
3366 item
= XVECTOR (items
)->contents
[i
];
3372 = Fcons (event
->frame_or_window
,
3374 Fcons (Fcons (event
->x
, event
->y
),
3375 Fcons (make_number (event
->timestamp
),
3378 return Fcons (item
, Fcons (position
, Qnil
));
3380 #endif /* not USE_X_TOOLKIT */
3382 window
= window_from_coordinates (f
, column
, row
, &part
);
3384 if (!WINDOWP (window
))
3386 window
= event
->frame_or_window
;
3391 int pixcolumn
, pixrow
;
3392 column
-= XINT (XWINDOW (window
)->left
);
3393 row
-= XINT (XWINDOW (window
)->top
);
3394 glyph_to_pixel_coords (f
, column
, row
, &pixcolumn
, &pixrow
);
3395 XSETINT (event
->x
, pixcolumn
);
3396 XSETINT (event
->y
, pixrow
);
3401 posn
= Qvertical_line
;
3404 buffer_posn_from_coords (XWINDOW (window
),
3411 Fcons (Fcons (event
->x
, event
->y
),
3412 Fcons (make_number (event
->timestamp
),
3418 Lisp_Object portion_whole
;
3421 window
= event
->frame_or_window
;
3422 portion_whole
= Fcons (event
->x
, event
->y
);
3423 part
= *scroll_bar_parts
[(int) event
->part
];
3427 Fcons (Qvertical_scroll_bar
,
3428 Fcons (portion_whole
,
3429 Fcons (make_number (event
->timestamp
),
3430 Fcons (part
, Qnil
)))));
3433 start_pos_ptr
= &XVECTOR (button_down_location
)->contents
[button
];
3435 start_pos
= *start_pos_ptr
;
3436 *start_pos_ptr
= Qnil
;
3438 is_double
= (button
== last_mouse_button
3439 && XINT (event
->x
) == last_mouse_x
3440 && XINT (event
->y
) == last_mouse_y
3441 && button_down_time
!= 0
3442 && (EQ (Vdouble_click_time
, Qt
)
3443 || (INTEGERP (Vdouble_click_time
)
3444 && ((int)(event
->timestamp
- button_down_time
)
3445 < XINT (Vdouble_click_time
)))));
3446 last_mouse_button
= button
;
3447 last_mouse_x
= XINT (event
->x
);
3448 last_mouse_y
= XINT (event
->y
);
3450 /* If this is a button press, squirrel away the location, so
3451 we can decide later whether it was a click or a drag. */
3452 if (event
->modifiers
& down_modifier
)
3456 double_click_count
++;
3457 event
->modifiers
|= ((double_click_count
> 2)
3462 double_click_count
= 1;
3463 button_down_time
= event
->timestamp
;
3464 *start_pos_ptr
= Fcopy_alist (position
);
3467 /* Now we're releasing a button - check the co-ordinates to
3468 see if this was a click or a drag. */
3469 else if (event
->modifiers
& up_modifier
)
3471 /* If we did not see a down before this up,
3472 ignore the up. Probably this happened because
3473 the down event chose a menu item.
3474 It would be an annoyance to treat the release
3475 of the button that chose the menu item
3476 as a separate event. */
3478 if (!CONSP (start_pos
))
3481 event
->modifiers
&= ~up_modifier
;
3482 #if 0 /* Formerly we treated an up with no down as a click event. */
3483 if (!CONSP (start_pos
))
3484 event
->modifiers
|= click_modifier
;
3488 /* The third element of every position should be the (x,y)
3492 down
= Fnth (make_number (2), start_pos
);
3493 if (EQ (event
->x
, XCONS (down
)->car
)
3494 && EQ (event
->y
, XCONS (down
)->cdr
))
3496 event
->modifiers
|= click_modifier
;
3500 button_down_time
= 0;
3501 event
->modifiers
|= drag_modifier
;
3503 /* Don't check is_double; treat this as multiple
3504 if the down-event was multiple. */
3505 if (double_click_count
> 1)
3506 event
->modifiers
|= ((double_click_count
> 2)
3512 /* Every mouse event should either have the down_modifier or
3513 the up_modifier set. */
3517 /* Get the symbol we should use for the mouse click. */
3520 head
= modify_event_symbol (button
,
3523 lispy_mouse_names
, &mouse_syms
,
3524 (sizeof (lispy_mouse_names
)
3525 / sizeof (lispy_mouse_names
[0])));
3526 if (event
->modifiers
& drag_modifier
)
3531 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
3534 Fcons (make_number (double_click_count
),
3542 #endif /* HAVE_MOUSE */
3544 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
3545 case menu_bar_event
:
3546 /* The event value is in the cdr of the frame_or_window slot. */
3547 if (!CONSP (event
->frame_or_window
))
3549 return XCONS (event
->frame_or_window
)->cdr
;
3552 /* The 'kind' field of the event is something we don't recognize. */
3561 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
3563 Lisp_Object bar_window
;
3564 enum scroll_bar_part part
;
3569 /* Is it a scroll bar movement? */
3570 if (frame
&& ! NILP (bar_window
))
3572 Lisp_Object part_sym
;
3574 part_sym
= *scroll_bar_parts
[(int) part
];
3575 return Fcons (Qscroll_bar_movement
,
3576 (Fcons (Fcons (bar_window
,
3577 Fcons (Qvertical_scroll_bar
,
3578 Fcons (Fcons (x
, y
),
3579 Fcons (make_number (time
),
3585 /* Or is it an ordinary mouse movement? */
3587 #endif /* MULTI_FRAME */
3600 /* It's in a frame; which window on that frame? */
3601 pixel_to_glyph_coords (frame
, XINT (x
), XINT (y
), &column
, &row
,
3603 window
= window_from_coordinates (frame
, column
, row
, &area
);
3608 if (WINDOWP (window
))
3610 int pixcolumn
, pixrow
;
3611 column
-= XINT (XWINDOW (window
)->left
);
3612 row
-= XINT (XWINDOW (window
)->top
);
3613 glyph_to_pixel_coords (frame
, column
, row
, &pixcolumn
, &pixrow
);
3614 XSETINT (x
, pixcolumn
);
3615 XSETINT (y
, pixrow
);
3620 posn
= Qvertical_line
;
3623 buffer_posn_from_coords (XWINDOW (window
), column
, row
));
3626 else if (frame
!= 0)
3628 XSETFRAME (window
, frame
);
3640 return Fcons (Qmouse_movement
,
3641 Fcons (Fcons (window
,
3643 Fcons (Fcons (x
, y
),
3644 Fcons (make_number (time
),
3650 #endif /* HAVE_MOUSE */
3652 /* Construct a switch frame event. */
3654 make_lispy_switch_frame (frame
)
3657 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
3660 /* Manipulating modifiers. */
3662 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
3664 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
3665 SYMBOL's name of the end of the modifiers; the string from this
3666 position is the unmodified symbol name.
3668 This doesn't use any caches. */
3671 parse_modifiers_uncached (symbol
, modifier_end
)
3675 struct Lisp_String
*name
;
3679 CHECK_SYMBOL (symbol
, 1);
3682 name
= XSYMBOL (symbol
)->name
;
3684 for (i
= 0; i
+2 <= name
->size
; )
3686 int this_mod_end
= 0;
3689 /* See if the name continues with a modifier word.
3690 Check that the word appears, but don't check what follows it.
3691 Set this_mod and this_mod_end to record what we find. */
3693 switch (name
->data
[i
])
3695 #define SINGLE_LETTER_MOD(BIT) \
3696 (this_mod_end = i + 1, this_mod = BIT)
3699 SINGLE_LETTER_MOD (alt_modifier
);
3703 SINGLE_LETTER_MOD (ctrl_modifier
);
3707 SINGLE_LETTER_MOD (hyper_modifier
);
3711 SINGLE_LETTER_MOD (meta_modifier
);
3715 SINGLE_LETTER_MOD (shift_modifier
);
3719 SINGLE_LETTER_MOD (super_modifier
);
3722 #undef SINGLE_LETTER_MOD
3725 /* If we found no modifier, stop looking for them. */
3726 if (this_mod_end
== 0)
3729 /* Check there is a dash after the modifier, so that it
3730 really is a modifier. */
3731 if (this_mod_end
>= name
->size
|| name
->data
[this_mod_end
] != '-')
3734 /* This modifier is real; look for another. */
3735 modifiers
|= this_mod
;
3736 i
= this_mod_end
+ 1;
3739 /* Should we include the `click' modifier? */
3740 if (! (modifiers
& (down_modifier
| drag_modifier
3741 | double_modifier
| triple_modifier
))
3742 && i
+ 7 == name
->size
3743 && strncmp (name
->data
+ i
, "mouse-", 6) == 0
3744 && ('0' <= name
->data
[i
+ 6] && name
->data
[i
+ 6] <= '9'))
3745 modifiers
|= click_modifier
;
3753 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
3754 prepended to the string BASE[0..BASE_LEN-1].
3755 This doesn't use any caches. */
3757 apply_modifiers_uncached (modifiers
, base
, base_len
)
3762 /* Since BASE could contain nulls, we can't use intern here; we have
3763 to use Fintern, which expects a genuine Lisp_String, and keeps a
3766 (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
3772 /* Only the event queue may use the `up' modifier; it should always
3773 be turned into a click or drag event before presented to lisp code. */
3774 if (modifiers
& up_modifier
)
3777 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
3778 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
3779 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
3780 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
3781 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
3782 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
3783 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
3784 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
3785 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
3786 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
3787 /* The click modifier is denoted by the absence of other modifiers. */
3791 mod_len
= p
- new_mods
;
3795 Lisp_Object new_name
;
3797 new_name
= make_uninit_string (mod_len
+ base_len
);
3798 bcopy (new_mods
, XSTRING (new_name
)->data
, mod_len
);
3799 bcopy (base
, XSTRING (new_name
)->data
+ mod_len
, base_len
);
3801 return Fintern (new_name
, Qnil
);
3806 static char *modifier_names
[] =
3808 "up", "down", "drag", "click", "double", "triple", 0, 0,
3809 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3810 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
3812 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
3814 static Lisp_Object modifier_symbols
;
3816 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
3818 lispy_modifier_list (modifiers
)
3821 Lisp_Object modifier_list
;
3824 modifier_list
= Qnil
;
3825 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
3826 if (modifiers
& (1<<i
))
3827 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
3830 return modifier_list
;
3834 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
3835 where UNMODIFIED is the unmodified form of SYMBOL,
3836 MASK is the set of modifiers present in SYMBOL's name.
3837 This is similar to parse_modifiers_uncached, but uses the cache in
3838 SYMBOL's Qevent_symbol_element_mask property, and maintains the
3839 Qevent_symbol_elements property. */
3842 parse_modifiers (symbol
)
3845 Lisp_Object elements
;
3847 elements
= Fget (symbol
, Qevent_symbol_element_mask
);
3848 if (CONSP (elements
))
3853 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
3854 Lisp_Object unmodified
;
3857 unmodified
= Fintern (make_string (XSYMBOL (symbol
)->name
->data
+ end
,
3858 XSYMBOL (symbol
)->name
->size
- end
),
3861 if (modifiers
& ~(((EMACS_INT
)1 << VALBITS
) - 1))
3863 XSETFASTINT (mask
, modifiers
);
3864 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
3866 /* Cache the parsing results on SYMBOL. */
3867 Fput (symbol
, Qevent_symbol_element_mask
,
3869 Fput (symbol
, Qevent_symbol_elements
,
3870 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
3872 /* Since we know that SYMBOL is modifiers applied to unmodified,
3873 it would be nice to put that in unmodified's cache.
3874 But we can't, since we're not sure that parse_modifiers is
3881 /* Apply the modifiers MODIFIERS to the symbol BASE.
3882 BASE must be unmodified.
3884 This is like apply_modifiers_uncached, but uses BASE's
3885 Qmodifier_cache property, if present. It also builds
3886 Qevent_symbol_elements properties, since it has that info anyway.
3888 apply_modifiers copies the value of BASE's Qevent_kind property to
3889 the modified symbol. */
3891 apply_modifiers (modifiers
, base
)
3895 Lisp_Object cache
, index
, entry
, new_symbol
;
3897 /* Mask out upper bits. We don't know where this value's been. */
3898 modifiers
&= ((EMACS_INT
)1 << VALBITS
) - 1;
3900 /* The click modifier never figures into cache indices. */
3901 cache
= Fget (base
, Qmodifier_cache
);
3902 XSETFASTINT (index
, (modifiers
& ~click_modifier
));
3903 entry
= assq_no_quit (index
, cache
);
3906 new_symbol
= XCONS (entry
)->cdr
;
3909 /* We have to create the symbol ourselves. */
3910 new_symbol
= apply_modifiers_uncached (modifiers
,
3911 XSYMBOL (base
)->name
->data
,
3912 XSYMBOL (base
)->name
->size
);
3914 /* Add the new symbol to the base's cache. */
3915 entry
= Fcons (index
, new_symbol
);
3916 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
3918 /* We have the parsing info now for free, so add it to the caches. */
3919 XSETFASTINT (index
, modifiers
);
3920 Fput (new_symbol
, Qevent_symbol_element_mask
,
3921 Fcons (base
, Fcons (index
, Qnil
)));
3922 Fput (new_symbol
, Qevent_symbol_elements
,
3923 Fcons (base
, lispy_modifier_list (modifiers
)));
3926 /* Make sure this symbol is of the same kind as BASE.
3928 You'd think we could just set this once and for all when we
3929 intern the symbol above, but reorder_modifiers may call us when
3930 BASE's property isn't set right; we can't assume that just
3931 because it has a Qmodifier_cache property it must have its
3932 Qevent_kind set right as well. */
3933 if (NILP (Fget (new_symbol
, Qevent_kind
)))
3937 kind
= Fget (base
, Qevent_kind
);
3939 Fput (new_symbol
, Qevent_kind
, kind
);
3946 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
3947 return a symbol with the modifiers placed in the canonical order.
3948 Canonical order is alphabetical, except for down and drag, which
3949 always come last. The 'click' modifier is never written out.
3951 Fdefine_key calls this to make sure that (for example) C-M-foo
3952 and M-C-foo end up being equivalent in the keymap. */
3955 reorder_modifiers (symbol
)
3958 /* It's hopefully okay to write the code this way, since everything
3959 will soon be in caches, and no consing will be done at all. */
3962 parsed
= parse_modifiers (symbol
);
3963 return apply_modifiers ((int) XINT (XCONS (XCONS (parsed
)->cdr
)->car
),
3964 XCONS (parsed
)->car
);
3968 /* For handling events, we often want to produce a symbol whose name
3969 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
3970 to some base, like the name of a function key or mouse button.
3971 modify_event_symbol produces symbols of this sort.
3973 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
3974 is the name of the i'th symbol. TABLE_SIZE is the number of elements
3977 Alternatively, NAME_ALIST is an alist mapping codes into symbol names.
3978 NAME_ALIST is used if it is non-nil; otherwise NAME_TABLE is used.
3980 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
3981 persist between calls to modify_event_symbol that it can use to
3982 store a cache of the symbols it's generated for this NAME_TABLE
3983 before. The object stored there may be a vector or an alist.
3985 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
3987 MODIFIERS is a set of modifier bits (as given in struct input_events)
3988 whose prefixes should be applied to the symbol name.
3990 SYMBOL_KIND is the value to be placed in the event_kind property of
3991 the returned symbol.
3993 The symbols we create are supposed to have an
3994 `event-symbol-elements' property, which lists the modifiers present
3995 in the symbol's name. */
3998 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_alist
,
3999 name_table
, symbol_table
, table_size
)
4002 Lisp_Object symbol_kind
;
4003 Lisp_Object name_alist
;
4005 Lisp_Object
*symbol_table
;
4006 unsigned int table_size
;
4009 Lisp_Object symbol_int
;
4011 /* Get rid of the "vendor-specific" bit here. */
4012 XSETINT (symbol_int
, symbol_num
& 0xffffff);
4014 /* Is this a request for a valid symbol? */
4015 if (symbol_num
< 0 || symbol_num
>= table_size
)
4018 if (CONSP (*symbol_table
))
4019 value
= Fcdr (assq_no_quit (symbol_int
, *symbol_table
));
4021 /* If *symbol_table doesn't seem to be initialized properly, fix that.
4022 *symbol_table should be a lisp vector TABLE_SIZE elements long,
4023 where the Nth element is the symbol for NAME_TABLE[N], or nil if
4024 we've never used that symbol before. */
4027 if (! VECTORP (*symbol_table
)
4028 || XVECTOR (*symbol_table
)->size
!= table_size
)
4032 XSETFASTINT (size
, table_size
);
4033 *symbol_table
= Fmake_vector (size
, Qnil
);
4036 value
= XVECTOR (*symbol_table
)->contents
[symbol_num
];
4039 /* Have we already used this symbol before? */
4042 /* No; let's create it. */
4043 if (!NILP (name_alist
))
4044 value
= Fcdr_safe (Fassq (symbol_int
, name_alist
));
4045 else if (name_table
[symbol_num
])
4046 value
= intern (name_table
[symbol_num
]);
4048 #ifdef HAVE_WINDOW_SYSTEM
4051 char *name
= x_get_keysym_name (symbol_num
);
4053 value
= intern (name
);
4060 sprintf (buf
, "key-%d", symbol_num
);
4061 value
= intern (buf
);
4064 if (CONSP (*symbol_table
))
4065 *symbol_table
= Fcons (value
, *symbol_table
);
4067 XVECTOR (*symbol_table
)->contents
[symbol_num
] = value
;
4069 /* Fill in the cache entries for this symbol; this also
4070 builds the Qevent_symbol_elements property, which the user
4072 apply_modifiers (modifiers
& click_modifier
, value
);
4073 Fput (value
, Qevent_kind
, symbol_kind
);
4076 /* Apply modifiers to that symbol. */
4077 return apply_modifiers (modifiers
, value
);
4080 /* Convert a list that represents an event type,
4081 such as (ctrl meta backspace), into the usual representation of that
4082 event type as a number or a symbol. */
4084 DEFUN ("event-convert-list", Fevent_convert_list
, Sevent_convert_list
, 1, 1, 0,
4085 "Convert the event description LIST to an event type.\n\
4086 LIST should contain one base event type (a character or symbol)\n\
4087 and zero or more modifier names (control, meta, hyper, super, shift, alt,\n\
4088 drag, down, double or triple).\n\
4089 The return value is an event type (a character or symbol) which\n\
4090 has the same base event type and all the specified modifiers.")
4100 while (CONSP (rest
))
4105 elt
= XCONS (rest
)->car
;
4107 /* Given a symbol, see if it is a modifier name. */
4109 this = parse_solitary_modifier (elt
);
4113 else if (!NILP (base
))
4114 error ("Two bases given in one event");
4118 rest
= XCONS (rest
)->cdr
;
4121 /* Let the symbol A refer to the character A. */
4122 if (SYMBOLP (base
) && XSYMBOL (base
)->name
->size
== 1)
4123 XSETINT (base
, XSYMBOL (base
)->name
->data
[0]);
4125 if (INTEGERP (base
))
4127 /* Turn (shift a) into A. */
4128 if ((modifiers
& shift_modifier
) != 0
4129 && (XINT (base
) >= 'a' && XINT (base
) <= 'z'))
4131 XSETINT (base
, XINT (base
) - ('a' - 'A'));
4132 modifiers
&= ~shift_modifier
;
4135 /* Turn (control a) into C-a. */
4136 if (modifiers
& ctrl_modifier
)
4137 return make_number ((modifiers
& ~ctrl_modifier
)
4138 | make_ctrl_char (XINT (base
)));
4140 return make_number (modifiers
| XINT (base
));
4142 else if (SYMBOLP (base
))
4143 return apply_modifiers (modifiers
, base
);
4145 error ("Invalid base event");
4148 /* Try to recognize SYMBOL as a modifier name.
4149 Return the modifier flag bit, or 0 if not recognized. */
4152 parse_solitary_modifier (symbol
)
4155 struct Lisp_String
*name
= XSYMBOL (symbol
)->name
;
4157 switch (name
->data
[0])
4159 #define SINGLE_LETTER_MOD(BIT) \
4160 if (name->size == 1) \
4163 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
4164 if (LEN == name->size \
4165 && ! strncmp (name->data, NAME, LEN)) \
4169 SINGLE_LETTER_MOD (alt_modifier
);
4173 MULTI_LETTER_MOD (alt_modifier
, "alt", 3);
4177 SINGLE_LETTER_MOD (ctrl_modifier
);
4181 MULTI_LETTER_MOD (ctrl_modifier
, "ctrl", 4);
4182 MULTI_LETTER_MOD (ctrl_modifier
, "control", 7);
4186 SINGLE_LETTER_MOD (hyper_modifier
);
4190 MULTI_LETTER_MOD (hyper_modifier
, "hyper", 5);
4194 SINGLE_LETTER_MOD (meta_modifier
);
4198 MULTI_LETTER_MOD (meta_modifier
, "meta", 4);
4202 SINGLE_LETTER_MOD (shift_modifier
);
4206 MULTI_LETTER_MOD (shift_modifier
, "shift", 5);
4207 MULTI_LETTER_MOD (super_modifier
, "super", 5);
4208 SINGLE_LETTER_MOD (super_modifier
);
4212 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
4213 MULTI_LETTER_MOD (down_modifier
, "down", 4);
4214 MULTI_LETTER_MOD (double_modifier
, "double", 6);
4218 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
4221 #undef SINGLE_LETTER_MOD
4222 #undef MULTI_LETTER_MOD
4228 /* Return 1 if EVENT is a list whose elements are all integers or symbols.
4229 Such a list is not valid as an event,
4230 but it can be a Lucid-style event type list. */
4233 lucid_event_type_list_p (object
)
4238 if (! CONSP (object
))
4241 for (tail
= object
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4244 elt
= XCONS (tail
)->car
;
4245 if (! (INTEGERP (elt
) || SYMBOLP (elt
)))
4252 /* Store into *addr a value nonzero if terminal input chars are available.
4253 Serves the purpose of ioctl (0, FIONREAD, addr)
4254 but works even if FIONREAD does not exist.
4255 (In fact, this may actually read some input.) */
4258 get_input_pending (addr
)
4261 /* First of all, have we already counted some input? */
4262 *addr
= !NILP (Vquit_flag
) || readable_events ();
4264 /* If input is being read as it arrives, and we have none, there is none. */
4265 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
4268 /* Try to read some input and see how much we get. */
4270 *addr
= !NILP (Vquit_flag
) || readable_events ();
4273 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
4276 gobble_input (expected
)
4281 if (interrupt_input
)
4284 mask
= sigblockx (SIGIO
);
4285 read_avail_input (expected
);
4289 #ifdef POLL_FOR_INPUT
4290 if (read_socket_hook
&& !interrupt_input
&& poll_suppress_count
== 0)
4293 mask
= sigblockx (SIGALRM
);
4294 read_avail_input (expected
);
4300 read_avail_input (expected
);
4304 /* Put a buffer_switch_event in the buffer
4305 so that read_key_sequence will notice the new current buffer. */
4307 record_asynch_buffer_change ()
4309 struct input_event event
;
4312 event
.kind
= buffer_switch_event
;
4313 event
.frame_or_window
= Qnil
;
4316 /* We don't need a buffer-switch event unless Emacs is waiting for input.
4317 The purpose of the event is to make read_key_sequence look up the
4318 keymaps again. If we aren't in read_key_sequence, we don't need one,
4319 and the event could cause trouble by messing up (input-pending-p). */
4320 tem
= Fwaiting_for_user_input_p ();
4324 /* We never need these events if we have no asynchronous subprocesses. */
4328 /* Make sure no interrupt happens while storing the event. */
4330 if (interrupt_input
)
4333 mask
= sigblockx (SIGIO
);
4334 kbd_buffer_store_event (&event
);
4341 kbd_buffer_store_event (&event
);
4348 /* Read any terminal input already buffered up by the system
4349 into the kbd_buffer, but do not wait.
4351 EXPECTED should be nonzero if the caller knows there is some input.
4353 Except on VMS, all input is read by this function.
4354 If interrupt_input is nonzero, this function MUST be called
4355 only when SIGIO is blocked.
4357 Returns the number of keyboard chars read, or -1 meaning
4358 this is a bad time to try to read input. */
4361 read_avail_input (expected
)
4364 struct input_event buf
[KBD_BUFFER_SIZE
];
4368 if (read_socket_hook
)
4369 /* No need for FIONREAD or fcntl; just say don't wait. */
4370 nread
= (*read_socket_hook
) (input_fd
, buf
, KBD_BUFFER_SIZE
,
4371 expected
, expected
);
4374 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
4375 the kbd_buffer can really hold. That may prevent loss
4376 of characters on some systems when input is stuffed at us. */
4377 unsigned char cbuf
[KBD_BUFFER_SIZE
- 1];
4380 /* Determine how many characters we should *try* to read. */
4383 #else /* not WINDOWSNT */
4385 n_to_read
= dos_keysns ();
4388 #else /* not MSDOS */
4390 /* Find out how much input is available. */
4391 if (ioctl (input_fd
, FIONREAD
, &n_to_read
) < 0)
4392 /* Formerly simply reported no input, but that sometimes led to
4393 a failure of Emacs to terminate.
4394 SIGHUP seems appropriate if we can't reach the terminal. */
4395 /* ??? Is it really right to send the signal just to this process
4396 rather than to the whole process group?
4397 Perhaps on systems with FIONREAD Emacs is alone in its group. */
4398 kill (getpid (), SIGHUP
);
4401 if (n_to_read
> sizeof cbuf
)
4402 n_to_read
= sizeof cbuf
;
4403 #else /* no FIONREAD */
4404 #if defined (USG) || defined (DGUX)
4405 /* Read some input if available, but don't wait. */
4406 n_to_read
= sizeof cbuf
;
4407 fcntl (input_fd
, F_SETFL
, O_NDELAY
);
4412 #endif /* not MSDOS */
4413 #endif /* not WINDOWSNT */
4415 /* Now read; for one reason or another, this will not block.
4416 NREAD is set to the number of chars read. */
4420 cbuf
[0] = dos_keyread ();
4423 nread
= read (input_fd
, cbuf
, n_to_read
);
4425 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
4426 /* The kernel sometimes fails to deliver SIGHUP for ptys.
4427 This looks incorrect, but it isn't, because _BSD causes
4428 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
4429 and that causes a value other than 0 when there is no input. */
4435 /* We used to retry the read if it was interrupted.
4436 But this does the wrong thing when O_NDELAY causes
4437 an EAGAIN error. Does anybody know of a situation
4438 where a retry is actually needed? */
4440 nread
< 0 && (errno
== EAGAIN
4454 #if defined (USG) || defined (DGUX)
4455 fcntl (input_fd
, F_SETFL
, 0);
4456 #endif /* USG or DGUX */
4457 #endif /* no FIONREAD */
4458 for (i
= 0; i
< nread
; i
++)
4460 buf
[i
].kind
= ascii_keystroke
;
4461 buf
[i
].modifiers
= 0;
4462 if (meta_key
== 1 && (cbuf
[i
] & 0x80))
4463 buf
[i
].modifiers
= meta_modifier
;
4467 buf
[i
].code
= cbuf
[i
];
4469 XSETFRAME (buf
[i
].frame_or_window
, selected_frame
);
4471 buf
[i
].frame_or_window
= Qnil
;
4476 /* Scan the chars for C-g and store them in kbd_buffer. */
4477 for (i
= 0; i
< nread
; i
++)
4479 kbd_buffer_store_event (&buf
[i
]);
4480 /* Don't look at input that follows a C-g too closely.
4481 This reduces lossage due to autorepeat on C-g. */
4482 if (buf
[i
].kind
== ascii_keystroke
4483 && buf
[i
].code
== quit_char
)
4489 #endif /* not VMS */
4491 #ifdef SIGIO /* for entire page */
4492 /* Note SIGIO has been undef'd if FIONREAD is missing. */
4495 input_available_signal (signo
)
4498 /* Must preserve main program's value of errno. */
4499 int old_errno
= errno
;
4501 extern int select_alarmed
;
4505 /* USG systems forget handlers when they are used;
4506 must reestablish each time */
4507 signal (signo
, input_available_signal
);
4514 if (input_available_clear_time
)
4515 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
4520 nread
= read_avail_input (1);
4521 /* -1 means it's not ok to read the input now.
4522 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
4523 0 means there was no keyboard input available. */
4528 select_alarmed
= 1; /* Force the select emulator back to life */
4539 /* Send ourselves a SIGIO.
4541 This function exists so that the UNBLOCK_INPUT macro in
4542 blockinput.h can have some way to take care of input we put off
4543 dealing with, without assuming that every file which uses
4544 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
4546 reinvoke_input_signal ()
4555 /* Return the prompt-string of a sparse keymap.
4556 This is the first element which is a string.
4557 Return nil if there is none. */
4565 register Lisp_Object tem
;
4574 static void menu_bar_item ();
4575 static void menu_bar_one_keymap ();
4577 /* These variables hold the vector under construction within
4578 menu_bar_items and its subroutines, and the current index
4579 for storing into that vector. */
4580 static Lisp_Object menu_bar_items_vector
;
4581 static int menu_bar_items_index
;
4583 /* Return a vector of menu items for a menu bar, appropriate
4584 to the current buffer. Each item has three elements in the vector:
4587 OLD is an old vector we can optionally reuse, or nil. */
4590 menu_bar_items (old
)
4593 /* The number of keymaps we're scanning right now, and the number of
4594 keymaps we have allocated space for. */
4597 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
4598 in the current keymaps, or nil where it is not a prefix. */
4601 Lisp_Object def
, tem
, tail
;
4610 struct gcpro gcpro1
;
4612 /* In order to build the menus, we need to call the keymap
4613 accessors. They all call QUIT. But this function is called
4614 during redisplay, during which a quit is fatal. So inhibit
4615 quitting while building the menus.
4616 We do this instead of specbind because (1) errors will clear it anyway
4617 and (2) this avoids risk of specpdl overflow. */
4618 oquit
= Vinhibit_quit
;
4622 menu_bar_items_vector
= old
;
4624 menu_bar_items_vector
= Fmake_vector (make_number (24), Qnil
);
4625 menu_bar_items_index
= 0;
4627 GCPRO1 (menu_bar_items_vector
);
4629 /* Build our list of keymaps.
4630 If we recognize a function key and replace its escape sequence in
4631 keybuf with its symbol, or if the sequence starts with a mouse
4632 click and we need to switch buffers, we jump back here to rebuild
4633 the initial keymaps from the current buffer. */
4637 /* Should overriding-terminal-local-map and overriding-local-map apply? */
4638 if (!NILP (Voverriding_local_map_menu_flag
))
4640 /* Yes, use them (if non-nil) as well as the global map. */
4641 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
4643 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
4644 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
4645 if (!NILP (Voverriding_local_map
))
4646 maps
[nmaps
++] = Voverriding_local_map
;
4650 /* No, so use major and minor mode keymaps. */
4651 nmaps
= current_minor_maps (NULL
, &tmaps
);
4652 maps
= (Lisp_Object
*) alloca ((nmaps
+ 2) * sizeof (maps
[0]));
4653 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
4654 #ifdef USE_TEXT_PROPERTIES
4655 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
4657 maps
[nmaps
++] = current_buffer
->keymap
;
4660 maps
[nmaps
++] = current_global_map
;
4663 /* Look up in each map the dummy prefix key `menu-bar'. */
4667 for (mapno
= nmaps
- 1; mapno
>= 0; mapno
--)
4669 if (! NILP (maps
[mapno
]))
4670 def
= get_keyelt (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0));
4674 tem
= Fkeymapp (def
);
4676 menu_bar_one_keymap (def
);
4679 /* Move to the end those items that should be at the end. */
4681 for (tail
= Vmenu_bar_final_items
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4684 int end
= menu_bar_items_index
;
4686 for (i
= 0; i
< end
; i
+= 3)
4687 if (EQ (XCONS (tail
)->car
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
4689 Lisp_Object tem0
, tem1
, tem2
;
4690 /* Move the item at index I to the end,
4691 shifting all the others forward. */
4692 tem0
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 0];
4693 tem1
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 1];
4694 tem2
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
4696 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3],
4697 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
4698 (end
- i
- 3) * sizeof (Lisp_Object
));
4699 XVECTOR (menu_bar_items_vector
)->contents
[end
- 3] = tem0
;
4700 XVECTOR (menu_bar_items_vector
)->contents
[end
- 2] = tem1
;
4701 XVECTOR (menu_bar_items_vector
)->contents
[end
- 1] = tem2
;
4706 /* Add nil, nil, nil at the end. */
4707 i
= menu_bar_items_index
;
4708 if (i
+ 3 > XVECTOR (menu_bar_items_vector
)->size
)
4711 int newsize
= 2 * i
;
4712 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
4713 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
4714 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
4715 menu_bar_items_vector
= tem
;
4717 /* Add this item. */
4718 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
4719 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
4720 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
4721 menu_bar_items_index
= i
;
4723 Vinhibit_quit
= oquit
;
4725 return menu_bar_items_vector
;
4728 /* Scan one map KEYMAP, accumulating any menu items it defines
4729 in menu_bar_items_vector. */
4732 menu_bar_one_keymap (keymap
)
4735 Lisp_Object tail
, item
, key
, binding
, item_string
, table
;
4737 /* Loop over all keymap entries that have menu strings. */
4738 for (tail
= keymap
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4740 item
= XCONS (tail
)->car
;
4743 key
= XCONS (item
)->car
;
4744 binding
= XCONS (item
)->cdr
;
4745 if (CONSP (binding
))
4747 item_string
= XCONS (binding
)->car
;
4748 if (STRINGP (item_string
))
4749 menu_bar_item (key
, item_string
, Fcdr (binding
));
4751 else if (EQ (binding
, Qundefined
))
4752 menu_bar_item (key
, Qnil
, binding
);
4754 else if (VECTORP (item
))
4756 /* Loop over the char values represented in the vector. */
4757 int len
= XVECTOR (item
)->size
;
4759 for (c
= 0; c
< len
; c
++)
4761 Lisp_Object character
;
4762 XSETFASTINT (character
, c
);
4763 binding
= XVECTOR (item
)->contents
[c
];
4764 if (CONSP (binding
))
4766 item_string
= XCONS (binding
)->car
;
4767 if (STRINGP (item_string
))
4768 menu_bar_item (key
, item_string
, Fcdr (binding
));
4770 else if (EQ (binding
, Qundefined
))
4771 menu_bar_item (key
, Qnil
, binding
);
4777 /* This is used as the handler when calling internal_condition_case_1. */
4780 menu_bar_item_1 (arg
)
4786 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
4787 If there's already an item for KEY, add this DEF to it. */
4790 menu_bar_item (key
, item_string
, def
)
4791 Lisp_Object key
, item_string
, def
;
4794 Lisp_Object enabled
;
4797 if (EQ (def
, Qundefined
))
4799 /* If a map has an explicit `undefined' as definition,
4800 discard any previously made menu bar item. */
4802 for (i
= 0; i
< menu_bar_items_index
; i
+= 3)
4803 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
4805 if (menu_bar_items_index
> i
+ 3)
4806 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3],
4807 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
4808 (menu_bar_items_index
- i
- 3) * sizeof (Lisp_Object
));
4809 menu_bar_items_index
-= 3;
4813 /* If there's no definition for this key yet,
4814 just ignore `undefined'. */
4818 /* See if this entry is enabled. */
4823 /* No property, or nil, means enable.
4824 Otherwise, enable if value is not nil. */
4825 tem
= Fget (def
, Qmenu_enable
);
4827 /* (condition-case nil (eval tem)
4829 enabled
= internal_condition_case_1 (Feval
, tem
, Qerror
,
4833 /* Ignore this item if it's not enabled. */
4837 /* Find any existing item for this KEY. */
4838 for (i
= 0; i
< menu_bar_items_index
; i
+= 3)
4839 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
4842 /* If we did not find this KEY, add it at the end. */
4843 if (i
== menu_bar_items_index
)
4845 /* If vector is too small, get a bigger one. */
4846 if (i
+ 3 > XVECTOR (menu_bar_items_vector
)->size
)
4849 int newsize
= 2 * i
;
4850 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
4851 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
4852 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
4853 menu_bar_items_vector
= tem
;
4855 /* Add this item. */
4856 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = key
;
4857 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = item_string
;
4858 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Fcons (def
, Qnil
);
4859 menu_bar_items_index
= i
;
4861 /* We did find an item for this KEY. Add DEF to its list of maps. */
4865 old
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
4866 XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2] = Fcons (def
, old
);
4870 /* Read a character using menus based on maps in the array MAPS.
4871 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
4872 Return t if we displayed a menu but the user rejected it.
4874 PREV_EVENT is the previous input event, or nil if we are reading
4875 the first event of a key sequence.
4877 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
4878 if we used a mouse menu to read the input, or zero otherwise. If
4879 USED_MOUSE_MENU is null, we don't dereference it.
4881 The prompting is done based on the prompt-string of the map
4882 and the strings associated with various map elements.
4884 This can be done with X menus or with menus put in the minibuf.
4885 These are done in different ways, depending on how the input will be read.
4886 Menus using X are done after auto-saving in read-char, getting the input
4887 event from Fx_popup_menu; menus using the minibuf use read_char recursively
4888 and do auto-saving in the inner call of read_char. */
4891 read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
4894 Lisp_Object prev_event
;
4895 int *used_mouse_menu
;
4898 register Lisp_Object name
;
4899 Lisp_Object rest
, vector
;
4901 if (used_mouse_menu
)
4902 *used_mouse_menu
= 0;
4904 /* Use local over global Menu maps */
4906 if (! menu_prompting
)
4909 /* Optionally disregard all but the global map. */
4910 if (inhibit_local_menu_bar_menus
)
4912 maps
+= (nmaps
- 1);
4916 /* Get the menu name from the first map that has one (a prompt string). */
4917 for (mapno
= 0; mapno
< nmaps
; mapno
++)
4919 name
= map_prompt (maps
[mapno
]);
4924 /* If we don't have any menus, just read a character normally. */
4929 /* If we got to this point via a mouse click,
4930 use a real menu for mouse selection. */
4931 if (EVENT_HAS_PARAMETERS (prev_event
)
4932 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
))
4934 /* Display the menu and get the selection. */
4935 Lisp_Object
*realmaps
4936 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
4940 /* Use the maps that are not nil. */
4941 for (mapno
= 0; mapno
< nmaps
; mapno
++)
4942 if (!NILP (maps
[mapno
]))
4943 realmaps
[nmaps1
++] = maps
[mapno
];
4945 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
4950 /* If we got multiple events, unread all but
4952 There is no way to prevent those unread events
4953 from showing up later in last_nonmenu_event.
4954 So turn symbol and integer events into lists,
4955 to indicate that they came from a mouse menu,
4956 so that when present in last_nonmenu_event
4957 they won't confuse things. */
4958 for (tem
= XCONS (value
)->cdr
; !NILP (tem
);
4959 tem
= XCONS (tem
)->cdr
)
4960 if (SYMBOLP (XCONS (tem
)->car
)
4961 || INTEGERP (XCONS (tem
)->car
))
4963 = Fcons (XCONS (tem
)->car
, Qnil
);
4965 /* If we got more than one event, put all but the first
4966 onto this list to be read later.
4967 Return just the first event now. */
4968 Vunread_command_events
4969 = nconc2 (XCONS (value
)->cdr
, Vunread_command_events
);
4970 value
= XCONS (value
)->car
;
4972 else if (NILP (value
))
4974 if (used_mouse_menu
)
4975 *used_mouse_menu
= 1;
4978 #endif /* HAVE_MENUS */
4983 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
4989 register Lisp_Object name
;
4991 int width
= FRAME_WIDTH (selected_frame
) - 4;
4992 char *menu
= (char *) alloca (width
+ 4);
4995 Lisp_Object rest
, vector
;
4997 if (! menu_prompting
)
5000 /* Get the menu name from the first map that has one (a prompt string). */
5001 for (mapno
= 0; mapno
< nmaps
; mapno
++)
5003 name
= map_prompt (maps
[mapno
]);
5008 /* If we don't have any menus, just read a character normally. */
5012 /* Prompt string always starts with map's prompt, and a space. */
5013 strcpy (menu
, XSTRING (name
)->data
);
5014 nlength
= XSTRING (name
)->size
;
5015 menu
[nlength
++] = ':';
5016 menu
[nlength
++] = ' ';
5019 /* Start prompting at start of first map. */
5023 /* Present the documented bindings, a line at a time. */
5030 Lisp_Object orig_defn_macro
;
5032 /* Loop over elements of map. */
5037 /* If reached end of map, start at beginning of next map. */
5041 /* At end of last map, wrap around to first map if just starting,
5042 or end this line if already have something on it. */
5046 if (notfirst
|| nobindings
) break;
5051 /* Look at the next element of the map. */
5053 elt
= XVECTOR (vector
)->contents
[idx
];
5055 elt
= Fcar_safe (rest
);
5057 if (idx
< 0 && VECTORP (elt
))
5059 /* If we found a dense table in the keymap,
5060 advanced past it, but start scanning its contents. */
5061 rest
= Fcdr_safe (rest
);
5067 /* An ordinary element. */
5072 s
= Fcar_safe (Fcdr_safe (elt
)); /* alist */
5073 event
= Fcar_safe (elt
);
5077 s
= Fcar_safe (elt
); /* vector */
5078 XSETINT (event
, idx
);
5081 /* Ignore the element if it has no prompt string. */
5082 if (STRINGP (s
) && INTEGERP (event
))
5084 /* 1 if the char to type matches the string. */
5086 Lisp_Object upcased_event
, downcased_event
;
5089 upcased_event
= Fupcase (event
);
5090 downcased_event
= Fdowncase (event
);
5091 char_matches
= (XINT (upcased_event
) == XSTRING (s
)->data
[0]
5092 || XINT (downcased_event
) == XSTRING (s
)->data
[0]);
5094 desc
= Fsingle_key_description (event
);
5096 /* If we have room for the prompt string, add it to this line.
5097 If this is the first on the line, always add it. */
5098 if ((XSTRING (s
)->size
+ i
+ 2
5099 + (char_matches
? 0 : XSTRING (desc
)->size
+ 3))
5105 /* Punctuate between strings. */
5108 strcpy (menu
+ i
, ", ");
5114 /* If the char to type doesn't match the string's
5115 first char, explicitly show what char to type. */
5118 /* Add as much of string as fits. */
5119 thiswidth
= XSTRING (desc
)->size
;
5120 if (thiswidth
+ i
> width
)
5121 thiswidth
= width
- i
;
5122 bcopy (XSTRING (desc
)->data
, menu
+ i
, thiswidth
);
5124 strcpy (menu
+ i
, " = ");
5128 /* Add as much of string as fits. */
5129 thiswidth
= XSTRING (s
)->size
;
5130 if (thiswidth
+ i
> width
)
5131 thiswidth
= width
- i
;
5132 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
5138 /* If this element does not fit, end the line now,
5139 and save the element for the next line. */
5140 strcpy (menu
+ i
, "...");
5145 /* Move past this element. */
5146 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
5147 /* Handle reaching end of dense table. */
5152 rest
= Fcdr_safe (rest
);
5156 /* Prompt with that and read response. */
5159 /* Make believe its not a keyboard macro in case the help char
5160 is pressed. Help characters are not recorded because menu prompting
5161 is not used on replay.
5163 orig_defn_macro
= current_kboard
->defining_kbd_macro
;
5164 current_kboard
->defining_kbd_macro
= Qnil
;
5166 obj
= read_char (commandflag
, 0, 0, Qnil
, 0);
5167 while (BUFFERP (obj
));
5168 current_kboard
->defining_kbd_macro
= orig_defn_macro
;
5170 if (!INTEGERP (obj
))
5175 if (! EQ (obj
, menu_prompt_more_char
)
5176 && (!INTEGERP (menu_prompt_more_char
)
5177 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
5179 if (!NILP (current_kboard
->defining_kbd_macro
))
5180 store_kbd_macro_char (obj
);
5183 /* Help char - go round again */
5187 /* Reading key sequences. */
5189 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
5190 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
5191 keymap, or nil otherwise. Return the index of the first keymap in
5192 which KEY has any binding, or NMAPS if no map has a binding.
5194 If KEY is a meta ASCII character, treat it like meta-prefix-char
5195 followed by the corresponding non-meta character. Keymaps in
5196 CURRENT with non-prefix bindings for meta-prefix-char become nil in
5199 If KEY has no bindings in any of the CURRENT maps, NEXT is left
5202 NEXT may be the same array as CURRENT. */
5205 follow_key (key
, nmaps
, current
, defs
, next
)
5207 Lisp_Object
*current
, *defs
, *next
;
5210 int i
, first_binding
;
5213 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
5214 followed by the corresponding non-meta character.
5215 Put the results into DEFS, since we are going to alter that anyway.
5216 Do not alter CURRENT or NEXT. */
5217 if (INTEGERP (key
) && (XINT (key
) & CHAR_META
))
5219 for (i
= 0; i
< nmaps
; i
++)
5220 if (! NILP (current
[i
]))
5223 def
= get_keyelt (access_keymap (current
[i
],
5224 meta_prefix_char
, 1, 0));
5226 /* Note that since we pass the resulting bindings through
5227 get_keymap_1, non-prefix bindings for meta-prefix-char
5229 defs
[i
] = get_keymap_1 (def
, 0, 1);
5235 XSETINT (key
, XFASTINT (key
) & ~CHAR_META
);
5238 first_binding
= nmaps
;
5239 for (i
= nmaps
- 1; i
>= 0; i
--)
5241 if (! NILP (current
[i
]))
5249 defs
[i
] = get_keyelt (access_keymap (map
, key
, 1, 0));
5250 if (! NILP (defs
[i
]))
5257 /* Given the set of bindings we've found, produce the next set of maps. */
5258 if (first_binding
< nmaps
)
5259 for (i
= 0; i
< nmaps
; i
++)
5260 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0, 1);
5262 return first_binding
;
5265 /* Read a sequence of keys that ends with a non prefix character,
5266 storing it in KEYBUF, a buffer of size BUFSIZE.
5268 Return the length of the key sequence stored.
5269 Return -1 if the user rejected a command menu.
5271 Echo starting immediately unless `prompt' is 0.
5273 Where a key sequence ends depends on the currently active keymaps.
5274 These include any minor mode keymaps active in the current buffer,
5275 the current buffer's local map, and the global map.
5277 If a key sequence has no other bindings, we check Vfunction_key_map
5278 to see if some trailing subsequence might be the beginning of a
5279 function key's sequence. If so, we try to read the whole function
5280 key, and substitute its symbolic name into the key sequence.
5282 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
5283 `double-' events into similar click events, if that would make them
5284 bound. We try to turn `triple-' events first into `double-' events,
5287 If we get a mouse click in a mode line, vertical divider, or other
5288 non-text area, we treat the click as if it were prefixed by the
5289 symbol denoting that area - `mode-line', `vertical-line', or
5292 If the sequence starts with a mouse click, we read the key sequence
5293 with respect to the buffer clicked on, not the current buffer.
5295 If the user switches frames in the midst of a key sequence, we put
5296 off the switch-frame event until later; the next call to
5297 read_char will return it. */
5300 read_key_sequence (keybuf
, bufsize
, prompt
, dont_downcase_last
,
5301 can_return_switch_frame
)
5302 Lisp_Object
*keybuf
;
5305 int dont_downcase_last
;
5306 int can_return_switch_frame
;
5308 int count
= specpdl_ptr
- specpdl
;
5310 /* How many keys there are in the current key sequence. */
5313 /* The length of the echo buffer when we started reading, and
5314 the length of this_command_keys when we started reading. */
5318 /* The number of keymaps we're scanning right now, and the number of
5319 keymaps we have allocated space for. */
5321 int nmaps_allocated
= 0;
5323 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
5324 the current keymaps. */
5327 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
5328 in the current keymaps, or nil where it is not a prefix. */
5329 Lisp_Object
*submaps
;
5331 /* The local map to start out with at start of key sequence. */
5332 Lisp_Object orig_local_map
;
5334 /* 1 if we have already considered switching to the local-map property
5335 of the place where a mouse click occurred. */
5336 int localized_local_map
= 0;
5338 /* The index in defs[] of the first keymap that has a binding for
5339 this key sequence. In other words, the lowest i such that
5340 defs[i] is non-nil. */
5343 /* If t < mock_input, then KEYBUF[t] should be read as the next
5346 We use this to recover after recognizing a function key. Once we
5347 realize that a suffix of the current key sequence is actually a
5348 function key's escape sequence, we replace the suffix with the
5349 function key's binding from Vfunction_key_map. Now keybuf
5350 contains a new and different key sequence, so the echo area,
5351 this_command_keys, and the submaps and defs arrays are wrong. In
5352 this situation, we set mock_input to t, set t to 0, and jump to
5353 restart_sequence; the loop will read keys from keybuf up until
5354 mock_input, thus rebuilding the state; and then it will resume
5355 reading characters from the keyboard. */
5358 /* If the sequence is unbound in submaps[], then
5359 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
5360 and fkey_map is its binding.
5362 These might be > t, indicating that all function key scanning
5363 should hold off until t reaches them. We do this when we've just
5364 recognized a function key, to avoid searching for the function
5365 key's again in Vfunction_key_map. */
5366 int fkey_start
= 0, fkey_end
= 0;
5367 Lisp_Object fkey_map
;
5369 /* Likewise, for key_translation_map. */
5370 int keytran_start
= 0, keytran_end
= 0;
5371 Lisp_Object keytran_map
;
5373 /* If we receive a ``switch-frame'' event in the middle of a key sequence,
5374 we put it off for later. While we're reading, we keep the event here. */
5375 Lisp_Object delayed_switch_frame
;
5377 /* See the comment below... */
5378 #if defined (GOBBLE_FIRST_EVENT)
5379 Lisp_Object first_event
;
5382 Lisp_Object original_uppercase
;
5383 int original_uppercase_position
= -1;
5385 /* Gets around Microsoft compiler limitations. */
5388 struct buffer
*starting_buffer
;
5390 /* Nonzero if we seem to have got the beginning of a binding
5391 in function_key_map. */
5392 int function_key_possible
= 0;
5393 int key_translation_possible
= 0;
5395 /* Save the status of key translation before each step,
5396 so that we can restore this after downcasing. */
5397 Lisp_Object prev_fkey_map
;
5398 Lisp_Object prev_fkey_start
;
5399 Lisp_Object prev_fkey_end
;
5401 Lisp_Object prev_keytran_map
;
5402 Lisp_Object prev_keytran_start
;
5403 Lisp_Object prev_keytran_end
;
5407 last_nonmenu_event
= Qnil
;
5409 delayed_switch_frame
= Qnil
;
5410 fkey_map
= Vfunction_key_map
;
5411 keytran_map
= Vkey_translation_map
;
5413 /* If there is no function-key-map, turn off function key scanning. */
5414 if (NILP (Fkeymapp (Vfunction_key_map
)))
5415 fkey_start
= fkey_end
= bufsize
+ 1;
5417 /* If there is no key-translation-map, turn off scanning. */
5418 if (NILP (Fkeymapp (Vkey_translation_map
)))
5419 keytran_start
= keytran_end
= bufsize
+ 1;
5424 echo_prompt (XSTRING (prompt
)->data
);
5425 else if (cursor_in_echo_area
&& echo_keystrokes
)
5426 /* This doesn't put in a dash if the echo buffer is empty, so
5427 you don't always see a dash hanging out in the minibuffer. */
5431 /* Record the initial state of the echo area and this_command_keys;
5432 we will need to restore them if we replay a key sequence. */
5434 echo_start
= echo_length ();
5435 keys_start
= this_command_key_count
;
5437 #if defined (GOBBLE_FIRST_EVENT)
5438 /* This doesn't quite work, because some of the things that read_char
5439 does cannot safely be bypassed. It seems too risky to try to make
5442 /* Read the first char of the sequence specially, before setting
5443 up any keymaps, in case a filter runs and switches buffers on us. */
5444 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
5446 #endif /* GOBBLE_FIRST_EVENT */
5448 orig_local_map
= get_local_map (PT
, current_buffer
);
5450 /* We jump here when the key sequence has been thoroughly changed, and
5451 we need to rescan it starting from the beginning. When we jump here,
5452 keybuf[0..mock_input] holds the sequence we should reread. */
5455 starting_buffer
= current_buffer
;
5456 function_key_possible
= 0;
5457 key_translation_possible
= 0;
5459 /* Build our list of keymaps.
5460 If we recognize a function key and replace its escape sequence in
5461 keybuf with its symbol, or if the sequence starts with a mouse
5462 click and we need to switch buffers, we jump back here to rebuild
5463 the initial keymaps from the current buffer. */
5467 if (!NILP (current_kboard
->Voverriding_terminal_local_map
)
5468 || !NILP (Voverriding_local_map
))
5470 if (3 > nmaps_allocated
)
5472 submaps
= (Lisp_Object
*) alloca (3 * sizeof (submaps
[0]));
5473 defs
= (Lisp_Object
*) alloca (3 * sizeof (defs
[0]));
5474 nmaps_allocated
= 3;
5477 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
5478 submaps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
5479 if (!NILP (Voverriding_local_map
))
5480 submaps
[nmaps
++] = Voverriding_local_map
;
5484 nmaps
= current_minor_maps (0, &maps
);
5485 if (nmaps
+ 2 > nmaps_allocated
)
5487 submaps
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (submaps
[0]));
5488 defs
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (defs
[0]));
5489 nmaps_allocated
= nmaps
+ 2;
5491 bcopy (maps
, submaps
, nmaps
* sizeof (submaps
[0]));
5492 #ifdef USE_TEXT_PROPERTIES
5493 submaps
[nmaps
++] = orig_local_map
;
5495 submaps
[nmaps
++] = current_buffer
->keymap
;
5498 submaps
[nmaps
++] = current_global_map
;
5501 /* Find an accurate initial value for first_binding. */
5502 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
5503 if (! NILP (submaps
[first_binding
]))
5506 /* Start from the beginning in keybuf. */
5509 /* These are no-ops the first time through, but if we restart, they
5510 revert the echo area and this_command_keys to their original state. */
5511 this_command_key_count
= keys_start
;
5512 if (INTERACTIVE
&& t
< mock_input
)
5513 echo_truncate (echo_start
);
5515 /* If the best binding for the current key sequence is a keymap, or
5516 we may be looking at a function key's escape sequence, keep on
5518 while ((first_binding
< nmaps
&& ! NILP (submaps
[first_binding
]))
5519 || (first_binding
>= nmaps
5521 /* mock input is never part of a function key's sequence. */
5522 && mock_input
<= fkey_start
)
5523 || (first_binding
>= nmaps
5524 && keytran_start
< t
&& key_translation_possible
)
5525 /* Don't return in the middle of a possible function key sequence,
5526 if the only bindings we found were via case conversion.
5527 Thus, if ESC O a has a function-key-map translation
5528 and ESC o has a binding, don't return after ESC O,
5529 so that we can translate ESC O plus the next character. */
5533 int used_mouse_menu
= 0;
5535 /* Where the last real key started. If we need to throw away a
5536 key that has expanded into more than one element of keybuf
5537 (say, a mouse click on the mode line which is being treated
5538 as [mode-line (mouse-...)], then we backtrack to this point
5540 int last_real_key_start
;
5542 /* These variables are analogous to echo_start and keys_start;
5543 while those allow us to restart the entire key sequence,
5544 echo_local_start and keys_local_start allow us to throw away
5546 int echo_local_start
, keys_local_start
, local_first_binding
;
5549 error ("Key sequence too long");
5552 echo_local_start
= echo_length ();
5553 keys_local_start
= this_command_key_count
;
5554 local_first_binding
= first_binding
;
5557 /* These are no-ops, unless we throw away a keystroke below and
5558 jumped back up to replay_key; in that case, these restore the
5559 variables to their original state, allowing us to replay the
5561 if (INTERACTIVE
&& t
< mock_input
)
5562 echo_truncate (echo_local_start
);
5563 this_command_key_count
= keys_local_start
;
5564 first_binding
= local_first_binding
;
5566 /* By default, assume each event is "real". */
5567 last_real_key_start
= t
;
5569 /* Does mock_input indicate that we are re-reading a key sequence? */
5573 add_command_key (key
);
5574 if (echo_keystrokes
)
5578 /* If not, we should actually read a character. */
5581 struct buffer
*buf
= current_buffer
;
5585 KBOARD
*interrupted_kboard
= current_kboard
;
5586 struct frame
*interrupted_frame
= selected_frame
;
5587 if (setjmp (wrong_kboard_jmpbuf
))
5589 if (!NILP (delayed_switch_frame
))
5591 interrupted_kboard
->kbd_queue
5592 = Fcons (delayed_switch_frame
,
5593 interrupted_kboard
->kbd_queue
);
5594 delayed_switch_frame
= Qnil
;
5597 interrupted_kboard
->kbd_queue
5598 = Fcons (keybuf
[--t
], interrupted_kboard
->kbd_queue
);
5600 /* If the side queue is non-empty, ensure it begins with a
5601 switch-frame, so we'll replay it in the right context. */
5602 if (CONSP (interrupted_kboard
->kbd_queue
)
5603 && (key
= XCONS (interrupted_kboard
->kbd_queue
)->car
,
5604 !(EVENT_HAS_PARAMETERS (key
)
5605 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)),
5609 XSETFRAME (frame
, interrupted_frame
);
5610 interrupted_kboard
->kbd_queue
5611 = Fcons (make_lispy_switch_frame (frame
),
5612 interrupted_kboard
->kbd_queue
);
5615 orig_local_map
= get_local_map (PT
, current_buffer
);
5616 goto replay_sequence
;
5619 key
= read_char (NILP (prompt
), nmaps
, submaps
, last_nonmenu_event
,
5623 /* read_char returns t when it shows a menu and the user rejects it.
5628 /* read_char returns -1 at the end of a macro.
5629 Emacs 18 handles this by returning immediately with a
5630 zero, so that's what we'll do. */
5631 if (INTEGERP (key
) && XINT (key
) == -1)
5634 /* The Microsoft C compiler can't handle the goto that
5640 /* If the current buffer has been changed from under us, the
5641 keymap may have changed, so replay the sequence. */
5645 orig_local_map
= get_local_map (PT
, current_buffer
);
5646 goto replay_sequence
;
5649 /* If we have a quit that was typed in another frame, and
5650 quit_throw_to_read_char switched buffers,
5651 replay to get the right keymap. */
5652 if (XINT (key
) == quit_char
&& current_buffer
!= starting_buffer
)
5657 orig_local_map
= get_local_map (PT
, current_buffer
);
5658 goto replay_sequence
;
5664 /* Clicks in non-text areas get prefixed by the symbol
5665 in their CHAR-ADDRESS field. For example, a click on
5666 the mode line is prefixed by the symbol `mode-line'.
5668 Furthermore, key sequences beginning with mouse clicks
5669 are read using the keymaps of the buffer clicked on, not
5670 the current buffer. So we may have to switch the buffer
5673 When we turn one event into two events, we must make sure
5674 that neither of the two looks like the original--so that,
5675 if we replay the events, they won't be expanded again.
5676 If not for this, such reexpansion could happen either here
5677 or when user programs play with this-command-keys. */
5678 if (EVENT_HAS_PARAMETERS (key
))
5682 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
5683 if (EQ (kind
, Qmouse_click
))
5685 Lisp_Object window
, posn
;
5687 window
= POSN_WINDOW (EVENT_START (key
));
5688 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
5691 /* We're looking at the second event of a
5692 sequence which we expanded before. Set
5693 last_real_key_start appropriately. */
5695 last_real_key_start
= t
- 1;
5698 /* Key sequences beginning with mouse clicks are
5699 read using the keymaps in the buffer clicked on,
5700 not the current buffer. If we're at the
5701 beginning of a key sequence, switch buffers. */
5702 if (last_real_key_start
== 0
5704 && BUFFERP (XWINDOW (window
)->buffer
)
5705 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
5710 /* Arrange to go back to the original buffer once we're
5711 done reading the key sequence. Note that we can't
5712 use save_excursion_{save,restore} here, because they
5713 save point as well as the current buffer; we don't
5714 want to save point, because redisplay may change it,
5715 to accommodate a Fset_window_start or something. We
5716 don't want to do this at the top of the function,
5717 because we may get input from a subprocess which
5718 wants to change the selected window and stuff (say,
5720 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
5722 set_buffer_internal (XBUFFER (XWINDOW (window
)->buffer
));
5723 orig_local_map
= get_local_map (PT
, current_buffer
);
5724 goto replay_sequence
;
5726 /* For a mouse click, get the local text-property keymap
5727 of the place clicked on, rather than point. */
5728 if (last_real_key_start
== 0 && CONSP (XCONS (key
)->cdr
)
5729 && ! localized_local_map
)
5731 Lisp_Object map_here
, start
, pos
;
5733 localized_local_map
= 1;
5734 start
= EVENT_START (key
);
5735 if (CONSP (start
) && CONSP (XCONS (start
)->cdr
))
5737 pos
= POSN_BUFFER_POSN (start
);
5739 && XINT (pos
) >= BEG
&& XINT (pos
) <= Z
)
5741 map_here
= get_local_map (XINT (pos
), current_buffer
);
5742 if (!EQ (map_here
, orig_local_map
))
5744 orig_local_map
= map_here
;
5748 goto replay_sequence
;
5754 /* Expand mode-line and scroll-bar events into two events:
5755 use posn as a fake prefix key. */
5758 if (t
+ 1 >= bufsize
)
5759 error ("Key sequence too long");
5764 /* Zap the position in key, so we know that we've
5765 expanded it, and don't try to do so again. */
5766 POSN_BUFFER_POSN (EVENT_START (key
))
5767 = Fcons (posn
, Qnil
);
5771 else if (EQ (kind
, Qswitch_frame
))
5773 /* If we're at the beginning of a key sequence, and the caller
5774 says it's okay, go ahead and return this event. If we're
5775 in the midst of a key sequence, delay it until the end. */
5776 if (t
> 0 || !can_return_switch_frame
)
5778 delayed_switch_frame
= key
;
5782 else if (CONSP (XCONS (key
)->cdr
)
5783 && CONSP (EVENT_START (key
))
5784 && CONSP (XCONS (EVENT_START (key
))->cdr
))
5788 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
5789 /* Handle menu-bar events:
5790 insert the dummy prefix event `menu-bar'. */
5791 if (EQ (posn
, Qmenu_bar
))
5793 if (t
+ 1 >= bufsize
)
5794 error ("Key sequence too long");
5798 /* Zap the position in key, so we know that we've
5799 expanded it, and don't try to do so again. */
5800 POSN_BUFFER_POSN (EVENT_START (key
))
5801 = Fcons (posn
, Qnil
);
5804 goto replay_sequence
;
5806 else if (CONSP (posn
))
5808 /* We're looking at the second event of a
5809 sequence which we expanded before. Set
5810 last_real_key_start appropriately. */
5811 if (last_real_key_start
== t
&& t
> 0)
5812 last_real_key_start
= t
- 1;
5817 /* We have finally decided that KEY is something we might want
5819 first_binding
= (follow_key (key
,
5820 nmaps
- first_binding
,
5821 submaps
+ first_binding
,
5822 defs
+ first_binding
,
5823 submaps
+ first_binding
)
5826 /* If KEY wasn't bound, we'll try some fallbacks. */
5827 if (first_binding
>= nmaps
)
5831 head
= EVENT_HEAD (key
);
5832 if (help_char_p (head
) && t
> 0)
5834 read_key_sequence_cmd
= Vprefix_help_command
;
5836 last_nonmenu_event
= key
;
5837 /* The Microsoft C compiler can't handle the goto that
5845 Lisp_Object breakdown
;
5848 breakdown
= parse_modifiers (head
);
5849 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
5850 /* Attempt to reduce an unbound mouse event to a simpler
5851 event that is bound:
5852 Drags reduce to clicks.
5853 Double-clicks reduce to clicks.
5854 Triple-clicks reduce to double-clicks, then to clicks.
5855 Down-clicks are eliminated.
5856 Double-downs reduce to downs, then are eliminated.
5857 Triple-downs reduce to double-downs, then to downs,
5858 then are eliminated. */
5859 if (modifiers
& (down_modifier
| drag_modifier
5860 | double_modifier
| triple_modifier
))
5862 while (modifiers
& (down_modifier
| drag_modifier
5863 | double_modifier
| triple_modifier
))
5865 Lisp_Object new_head
, new_click
;
5866 if (modifiers
& triple_modifier
)
5867 modifiers
^= (double_modifier
| triple_modifier
);
5868 else if (modifiers
& double_modifier
)
5869 modifiers
&= ~double_modifier
;
5870 else if (modifiers
& drag_modifier
)
5871 modifiers
&= ~drag_modifier
;
5874 /* Dispose of this `down' event by simply jumping
5875 back to replay_key, to get another event.
5877 Note that if this event came from mock input,
5878 then just jumping back to replay_key will just
5879 hand it to us again. So we have to wipe out any
5882 We could delete keybuf[t] and shift everything
5883 after that to the left by one spot, but we'd also
5884 have to fix up any variable that points into
5885 keybuf, and shifting isn't really necessary
5888 Adding prefixes for non-textual mouse clicks
5889 creates two characters of mock input, and both
5890 must be thrown away. If we're only looking at
5891 the prefix now, we can just jump back to
5892 replay_key. On the other hand, if we've already
5893 processed the prefix, and now the actual click
5894 itself is giving us trouble, then we've lost the
5895 state of the keymaps we want to backtrack to, and
5896 we need to replay the whole sequence to rebuild
5899 Beyond that, only function key expansion could
5900 create more than two keys, but that should never
5901 generate mouse events, so it's okay to zero
5902 mock_input in that case too.
5904 Isn't this just the most wonderful code ever? */
5905 if (t
== last_real_key_start
)
5912 mock_input
= last_real_key_start
;
5913 goto replay_sequence
;
5918 = apply_modifiers (modifiers
, XCONS (breakdown
)->car
);
5920 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
5922 /* Look for a binding for this new key. follow_key
5923 promises that it didn't munge submaps the
5924 last time we called it, since key was unbound. */
5926 = (follow_key (new_click
,
5927 nmaps
- local_first_binding
,
5928 submaps
+ local_first_binding
,
5929 defs
+ local_first_binding
,
5930 submaps
+ local_first_binding
)
5931 + local_first_binding
);
5933 /* If that click is bound, go for it. */
5934 if (first_binding
< nmaps
)
5939 /* Otherwise, we'll leave key set to the drag event. */
5946 /* Normally, last_nonmenu_event gets the previous key we read.
5947 But when a mouse popup menu is being used,
5948 we don't update last_nonmenu_event; it continues to hold the mouse
5949 event that preceded the first level of menu. */
5950 if (!used_mouse_menu
)
5951 last_nonmenu_event
= key
;
5953 prev_fkey_map
= fkey_map
;
5954 prev_fkey_start
= fkey_start
;
5955 prev_fkey_end
= fkey_end
;
5957 prev_keytran_map
= keytran_map
;
5958 prev_keytran_start
= keytran_start
;
5959 prev_keytran_end
= keytran_end
;
5961 /* If the sequence is unbound, see if we can hang a function key
5962 off the end of it. We only want to scan real keyboard input
5963 for function key sequences, so if mock_input says that we're
5964 re-reading old events, don't examine it. */
5965 if (first_binding
>= nmaps
5968 Lisp_Object fkey_next
;
5970 /* Continue scan from fkey_end until we find a bound suffix.
5971 If we fail, increment fkey_start
5972 and start fkey_end from there. */
5973 while (fkey_end
< t
)
5977 key
= keybuf
[fkey_end
++];
5978 /* Look up meta-characters by prefixing them
5979 with meta_prefix_char. I hate this. */
5980 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
5985 (access_keymap (fkey_map
, meta_prefix_char
, 1, 0)),
5987 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
5990 fkey_next
= fkey_map
;
5993 = get_keyelt (access_keymap (fkey_next
, key
, 1, 0));
5995 #if 0 /* I didn't turn this on, because it might cause trouble
5996 for the mapping of return into C-m and tab into C-i. */
5997 /* Optionally don't map function keys into other things.
5998 This enables the user to redefine kp- keys easily. */
5999 if (SYMBOLP (key
) && !NILP (Vinhibit_function_key_mapping
))
6003 /* If the function key map gives a function, not an
6004 array, then call the function with no args and use
6005 its value instead. */
6006 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
6009 struct gcpro gcpro1
, gcpro2
, gcpro3
;
6013 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
6014 fkey_next
= call1 (fkey_next
, prompt
);
6016 /* If the function returned something invalid,
6017 barf--don't ignore it.
6018 (To ignore it safely, we would need to gcpro a bunch of
6019 other variables.) */
6020 if (! (VECTORP (fkey_next
) || STRINGP (fkey_next
)))
6021 error ("Function in function-key-map returns invalid key sequence");
6024 function_key_possible
= ! NILP (fkey_next
);
6026 /* If keybuf[fkey_start..fkey_end] is bound in the
6027 function key map and it's a suffix of the current
6028 sequence (i.e. fkey_end == t), replace it with
6029 the binding and restart with fkey_start at the end. */
6030 if ((VECTORP (fkey_next
) || STRINGP (fkey_next
))
6033 int len
= XFASTINT (Flength (fkey_next
));
6035 t
= fkey_start
+ len
;
6037 error ("Key sequence too long");
6039 if (VECTORP (fkey_next
))
6040 bcopy (XVECTOR (fkey_next
)->contents
,
6041 keybuf
+ fkey_start
,
6042 (t
- fkey_start
) * sizeof (keybuf
[0]));
6043 else if (STRINGP (fkey_next
))
6047 for (i
= 0; i
< len
; i
++)
6048 XSETFASTINT (keybuf
[fkey_start
+ i
],
6049 XSTRING (fkey_next
)->data
[i
]);
6053 fkey_start
= fkey_end
= t
;
6054 fkey_map
= Vfunction_key_map
;
6056 /* Do pass the results through key-translation-map. */
6057 keytran_start
= keytran_end
= 0;
6058 keytran_map
= Vkey_translation_map
;
6060 goto replay_sequence
;
6063 fkey_map
= get_keymap_1 (fkey_next
, 0, 1);
6065 /* If we no longer have a bound suffix, try a new positions for
6067 if (NILP (fkey_map
))
6069 fkey_end
= ++fkey_start
;
6070 fkey_map
= Vfunction_key_map
;
6071 function_key_possible
= 0;
6076 /* Look for this sequence in key-translation-map. */
6078 Lisp_Object keytran_next
;
6080 /* Scan from keytran_end until we find a bound suffix. */
6081 while (keytran_end
< t
)
6085 key
= keybuf
[keytran_end
++];
6086 /* Look up meta-characters by prefixing them
6087 with meta_prefix_char. I hate this. */
6088 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
6093 (access_keymap (keytran_map
, meta_prefix_char
, 1, 0)),
6095 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
6098 keytran_next
= keytran_map
;
6101 = get_keyelt (access_keymap (keytran_next
, key
, 1, 0));
6103 /* If the key translation map gives a function, not an
6104 array, then call the function with no args and use
6105 its value instead. */
6106 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
6107 && keytran_end
== t
)
6109 struct gcpro gcpro1
, gcpro2
, gcpro3
;
6113 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
6114 keytran_next
= call1 (keytran_next
, prompt
);
6116 /* If the function returned something invalid,
6117 barf--don't ignore it.
6118 (To ignore it safely, we would need to gcpro a bunch of
6119 other variables.) */
6120 if (! (VECTORP (keytran_next
) || STRINGP (keytran_next
)))
6121 error ("Function in key-translation-map returns invalid key sequence");
6124 key_translation_possible
= ! NILP (keytran_next
);
6126 /* If keybuf[keytran_start..keytran_end] is bound in the
6127 key translation map and it's a suffix of the current
6128 sequence (i.e. keytran_end == t), replace it with
6129 the binding and restart with keytran_start at the end. */
6130 if ((VECTORP (keytran_next
) || STRINGP (keytran_next
))
6131 && keytran_end
== t
)
6133 int len
= XFASTINT (Flength (keytran_next
));
6135 t
= keytran_start
+ len
;
6137 error ("Key sequence too long");
6139 if (VECTORP (keytran_next
))
6140 bcopy (XVECTOR (keytran_next
)->contents
,
6141 keybuf
+ keytran_start
,
6142 (t
- keytran_start
) * sizeof (keybuf
[0]));
6143 else if (STRINGP (keytran_next
))
6147 for (i
= 0; i
< len
; i
++)
6148 XSETFASTINT (keybuf
[keytran_start
+ i
],
6149 XSTRING (keytran_next
)->data
[i
]);
6153 keytran_start
= keytran_end
= t
;
6154 keytran_map
= Vkey_translation_map
;
6156 /* Don't pass the results of key-translation-map
6157 through function-key-map. */
6158 fkey_start
= fkey_end
= t
;
6159 fkey_map
= Vkey_translation_map
;
6161 goto replay_sequence
;
6164 keytran_map
= get_keymap_1 (keytran_next
, 0, 1);
6166 /* If we no longer have a bound suffix, try a new positions for
6168 if (NILP (keytran_map
))
6170 keytran_end
= ++keytran_start
;
6171 keytran_map
= Vkey_translation_map
;
6172 key_translation_possible
= 0;
6177 /* If KEY is not defined in any of the keymaps,
6178 and cannot be part of a function key or translation,
6179 and is an upper case letter
6180 use the corresponding lower-case letter instead. */
6181 if (first_binding
== nmaps
&& ! function_key_possible
6182 && ! key_translation_possible
6184 && ((((XINT (key
) & 0x3ffff)
6185 < XSTRING (current_buffer
->downcase_table
)->size
)
6186 && UPPERCASEP (XINT (key
) & 0x3ffff))
6187 || (XINT (key
) & shift_modifier
)))
6189 Lisp_Object new_key
;
6191 original_uppercase
= key
;
6192 original_uppercase_position
= t
- 1;
6194 if (XINT (new_key
) & shift_modifier
)
6195 XSETINT (new_key
, XINT (key
) & ~shift_modifier
);
6197 XSETINT (new_key
, (DOWNCASE (XINT (key
) & 0x3ffff)
6198 | (XINT (key
) & ~0x3ffff)));
6200 /* We have to do this unconditionally, regardless of whether
6201 the lower-case char is defined in the keymaps, because they
6202 might get translated through function-key-map. */
6203 keybuf
[t
- 1] = new_key
;
6206 fkey_map
= prev_fkey_map
;
6207 fkey_start
= prev_fkey_start
;
6208 fkey_end
= prev_fkey_end
;
6210 keytran_map
= prev_keytran_map
;
6211 keytran_start
= prev_keytran_start
;
6212 keytran_end
= prev_keytran_end
;
6214 goto replay_sequence
;
6216 /* If KEY is not defined in any of the keymaps,
6217 and cannot be part of a function key or translation,
6218 and is a shifted function key,
6219 use the corresponding unshifted function key instead. */
6220 if (first_binding
== nmaps
&& ! function_key_possible
6221 && ! key_translation_possible
6224 Lisp_Object breakdown
;
6227 breakdown
= parse_modifiers (key
);
6228 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
6229 if (modifiers
& shift_modifier
)
6231 Lisp_Object new_key
;
6233 original_uppercase
= key
;
6234 original_uppercase_position
= t
- 1;
6236 modifiers
&= ~shift_modifier
;
6237 new_key
= apply_modifiers (modifiers
,
6238 XCONS (breakdown
)->car
);
6240 keybuf
[t
- 1] = new_key
;
6243 fkey_map
= prev_fkey_map
;
6244 fkey_start
= prev_fkey_start
;
6245 fkey_end
= prev_fkey_end
;
6247 keytran_map
= prev_keytran_map
;
6248 keytran_start
= prev_keytran_start
;
6249 keytran_end
= prev_keytran_end
;
6251 goto replay_sequence
;
6257 read_key_sequence_cmd
= (first_binding
< nmaps
6258 ? defs
[first_binding
]
6261 unread_switch_frame
= delayed_switch_frame
;
6262 unbind_to (count
, Qnil
);
6264 /* Don't downcase the last character if the caller says don't.
6265 Don't downcase it if the result is undefined, either. */
6266 if ((dont_downcase_last
|| first_binding
>= nmaps
)
6267 && t
- 1 == original_uppercase_position
)
6268 keybuf
[t
- 1] = original_uppercase
;
6270 /* Occasionally we fabricate events, perhaps by expanding something
6271 according to function-key-map, or by adding a prefix symbol to a
6272 mouse click in the scroll bar or modeline. In this cases, return
6273 the entire generated key sequence, even if we hit an unbound
6274 prefix or a definition before the end. This means that you will
6275 be able to push back the event properly, and also means that
6276 read-key-sequence will always return a logical unit.
6279 for (; t
< mock_input
; t
++)
6281 if (echo_keystrokes
)
6282 echo_char (keybuf
[t
]);
6283 add_command_key (keybuf
[t
]);
6289 #if 0 /* This doc string is too long for some compilers.
6290 This commented-out definition serves for DOC. */
6291 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
6292 "Read a sequence of keystrokes and return as a string or vector.\n\
6293 The sequence is sufficient to specify a non-prefix command in the\n\
6294 current local and global maps.\n\
6296 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
6297 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
6298 as a continuation of the previous key.\n\
6300 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not\n\
6301 convert the last event to lower case. (Normally any upper case event\n\
6302 is converted to lower case if the original event is undefined and the lower\n\
6303 case equivalent is defined.) A non-nil value is appropriate for reading\n\
6304 a key sequence to be defined.\n\
6306 A C-g typed while in this function is treated like any other character,\n\
6307 and `quit-flag' is not set.\n\
6309 If the key sequence starts with a mouse click, then the sequence is read\n\
6310 using the keymaps of the buffer of the window clicked in, not the buffer\n\
6311 of the selected window as normal.\n\
6313 `read-key-sequence' drops unbound button-down events, since you normally\n\
6314 only care about the click or drag events which follow them. If a drag\n\
6315 or multi-click event is unbound, but the corresponding click event would\n\
6316 be bound, `read-key-sequence' turns the event into a click event at the\n\
6317 drag's starting position. This means that you don't have to distinguish\n\
6318 between click and drag, double, or triple events unless you want to.\n\
6320 `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\
6321 lines separating windows, and scroll bars with imaginary keys\n\
6322 `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\
6324 Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this\n\
6325 function will process a switch-frame event if the user switches frames\n\
6326 before typing anything. If the user switches frames in the middle of a\n\
6327 key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME\n\
6328 is nil, then the event will be put off until after the current key sequence.\n\
6330 `read-key-sequence' checks `function-key-map' for function key\n\
6331 sequences, where they wouldn't conflict with ordinary bindings. See\n\
6332 `function-key-map' for more details.")
6333 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
)
6336 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
6338 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
)
6339 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
6340 Lisp_Object can_return_switch_frame
;
6342 Lisp_Object keybuf
[30];
6344 struct gcpro gcpro1
, gcpro2
;
6347 CHECK_STRING (prompt
, 0);
6350 bzero (keybuf
, sizeof keybuf
);
6352 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
6354 if (NILP (continue_echo
))
6355 this_command_key_count
= 0;
6357 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
6358 prompt
, ! NILP (dont_downcase_last
),
6359 ! NILP (can_return_switch_frame
));
6367 return make_event_array (i
, keybuf
);
6370 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 3, 0,
6371 "Execute CMD as an editor command.\n\
6372 CMD must be a symbol that satisfies the `commandp' predicate.\n\
6373 Optional second arg RECORD-FLAG non-nil\n\
6374 means unconditionally put this command in `command-history'.\n\
6375 Otherwise, that is done only if an arg is read using the minibuffer.\n\
6376 The argument KEYS specifies the value to use instead of (this-command-keys)\n\
6377 when reading the arguments; if it is nil, (this_command_key_count) is used.")
6379 Lisp_Object cmd
, record
, keys
;
6381 register Lisp_Object final
;
6382 register Lisp_Object tem
;
6383 Lisp_Object prefixarg
;
6384 struct backtrace backtrace
;
6385 extern int debug_on_next_call
;
6387 prefixarg
= current_kboard
->Vprefix_arg
;
6388 current_kboard
->Vprefix_arg
= Qnil
;
6389 Vcurrent_prefix_arg
= prefixarg
;
6390 debug_on_next_call
= 0;
6394 tem
= Fget (cmd
, Qdisabled
);
6395 if (!NILP (tem
) && !NILP (Vrun_hooks
))
6397 tem
= Fsymbol_value (Qdisabled_command_hook
);
6399 return call1 (Vrun_hooks
, Qdisabled_command_hook
);
6405 final
= Findirect_function (cmd
);
6407 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
6408 do_autoload (final
, cmd
);
6413 if (STRINGP (final
) || VECTORP (final
))
6415 /* If requested, place the macro in the command history. For
6416 other sorts of commands, call-interactively takes care of
6420 = Fcons (Fcons (Qexecute_kbd_macro
,
6421 Fcons (final
, Fcons (prefixarg
, Qnil
))),
6424 return Fexecute_kbd_macro (final
, prefixarg
);
6426 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
6428 backtrace
.next
= backtrace_list
;
6429 backtrace_list
= &backtrace
;
6430 backtrace
.function
= &Qcall_interactively
;
6431 backtrace
.args
= &cmd
;
6432 backtrace
.nargs
= 1;
6433 backtrace
.evalargs
= 0;
6435 tem
= Fcall_interactively (cmd
, record
, keys
);
6437 backtrace_list
= backtrace
.next
;
6443 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
6445 "Read function name, then read its arguments and call it.")
6447 Lisp_Object prefixarg
;
6449 Lisp_Object function
;
6451 Lisp_Object saved_keys
;
6452 struct gcpro gcpro1
;
6454 saved_keys
= Fvector (this_command_key_count
,
6455 XVECTOR (this_command_keys
)->contents
);
6457 GCPRO1 (saved_keys
);
6459 if (EQ (prefixarg
, Qminus
))
6461 else if (CONSP (prefixarg
) && XINT (XCONS (prefixarg
)->car
) == 4)
6462 strcpy (buf
, "C-u ");
6463 else if (CONSP (prefixarg
) && INTEGERP (XCONS (prefixarg
)->car
))
6465 if (sizeof (int) == sizeof (EMACS_INT
))
6466 sprintf (buf
, "%d ", XINT (XCONS (prefixarg
)->car
));
6467 else if (sizeof (long) == sizeof (EMACS_INT
))
6468 sprintf (buf
, "%ld ", XINT (XCONS (prefixarg
)->car
));
6472 else if (INTEGERP (prefixarg
))
6474 if (sizeof (int) == sizeof (EMACS_INT
))
6475 sprintf (buf
, "%d ", XINT (prefixarg
));
6476 else if (sizeof (long) == sizeof (EMACS_INT
))
6477 sprintf (buf
, "%ld ", XINT (prefixarg
));
6482 /* This isn't strictly correct if execute-extended-command
6483 is bound to anything else. Perhaps it should use
6484 this_command_keys? */
6485 strcat (buf
, "M-x ");
6487 /* Prompt with buf, and then read a string, completing from and
6488 restricting to the set of all defined commands. Don't provide
6489 any initial input. Save the command read on the extended-command
6491 function
= Fcompleting_read (build_string (buf
),
6492 Vobarray
, Qcommandp
,
6493 Qt
, Qnil
, Qextended_command_history
);
6495 if (STRINGP (function
) && XSTRING (function
)->size
== 0)
6496 error ("No command name given");
6498 /* Set this_command_keys to the concatenation of saved_keys and
6499 function, followed by a RET. */
6501 struct Lisp_String
*str
;
6506 this_command_key_count
= 0;
6508 keys
= XVECTOR (saved_keys
)->contents
;
6509 for (i
= 0; i
< XVECTOR (saved_keys
)->size
; i
++)
6510 add_command_key (keys
[i
]);
6512 str
= XSTRING (function
);
6513 for (i
= 0; i
< str
->size
; i
++)
6515 XSETFASTINT (tem
, str
->data
[i
]);
6516 add_command_key (tem
);
6519 XSETFASTINT (tem
, '\015');
6520 add_command_key (tem
);
6525 function
= Fintern (function
, Qnil
);
6526 current_kboard
->Vprefix_arg
= prefixarg
;
6527 this_command
= function
;
6529 /* If enabled, show which key runs this command. */
6530 if (!NILP (Vsuggest_key_bindings
)
6531 && SYMBOLP (function
))
6533 Lisp_Object bindings
;
6535 bindings
= Fwhere_is_internal (function
, Voverriding_local_map
,
6538 if (!NILP (bindings
))
6540 message ("You can run the command `%s' by typing %s",
6541 XSYMBOL (function
)->name
->data
,
6542 XSTRING (Fkey_description (bindings
))->data
);
6543 Fsit_for ((NUMBERP (Vsuggest_key_bindings
)
6544 ? Vsuggest_key_bindings
: make_number (2)),
6549 return Fcommand_execute (function
, Qt
, Qnil
);
6552 /* Find the set of keymaps now active.
6553 Store into *MAPS_P a vector holding the various maps
6554 and return the number of them. The vector was malloc'd
6555 and the caller should free it. */
6558 current_active_maps (maps_p
)
6559 Lisp_Object
**maps_p
;
6561 Lisp_Object
*tmaps
, *maps
;
6564 /* Should overriding-terminal-local-map and overriding-local-map apply? */
6565 if (!NILP (Voverriding_local_map_menu_flag
))
6567 /* Yes, use them (if non-nil) as well as the global map. */
6568 maps
= (Lisp_Object
*) xmalloc (3 * sizeof (maps
[0]));
6570 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
6571 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
6572 if (!NILP (Voverriding_local_map
))
6573 maps
[nmaps
++] = Voverriding_local_map
;
6577 /* No, so use major and minor mode keymaps. */
6578 nmaps
= current_minor_maps (NULL
, &tmaps
);
6579 maps
= (Lisp_Object
*) xmalloc ((nmaps
+ 2) * sizeof (maps
[0]));
6580 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
6581 #ifdef USE_TEXT_PROPERTIES
6582 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
6584 maps
[nmaps
++] = current_buffer
->keymap
;
6587 maps
[nmaps
++] = current_global_map
;
6594 detect_input_pending ()
6597 get_input_pending (&input_pending
);
6599 return input_pending
;
6602 /* This is called in some cases before a possible quit.
6603 It cases the next call to detect_input_pending to recompute input_pending.
6604 So calling this function unnecessarily can't do any harm. */
6605 clear_input_pending ()
6610 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
6611 "T if command input is currently available with no waiting.\n\
6612 Actually, the value is nil only if we can be sure that no input is available.")
6615 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1)
6618 return detect_input_pending () ? Qt
: Qnil
;
6621 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
6622 "Return vector of last 100 events, not counting those from keyboard macros.")
6625 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
6628 if (total_keys
< NUM_RECENT_KEYS
)
6629 return Fvector (total_keys
, keys
);
6632 val
= Fvector (NUM_RECENT_KEYS
, keys
);
6633 bcopy (keys
+ recent_keys_index
,
6634 XVECTOR (val
)->contents
,
6635 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
6637 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
6638 recent_keys_index
* sizeof (Lisp_Object
));
6643 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
6644 "Return the key sequence that invoked this command.\n\
6645 The value is a string or a vector.")
6648 return make_event_array (this_command_key_count
,
6649 XVECTOR (this_command_keys
)->contents
);
6652 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths
,
6653 Sreset_this_command_lengths
, 0, 0, 0,
6654 "Used for complicated reasons in `universal-argument-other-key'.\n\
6656 `universal-argument-other-key' rereads the event just typed.\n\
6657 It then gets translated through `function-key-map'.\n\
6658 The translated event gets included in the echo area and in\n\
6659 the value of `this-command-keys' in addition to the raw original event.\n\
6660 That is not right.\n\
6662 Calling this function directs the translated event to replace\n\
6663 the original event, so that only one version of the event actually\n\
6664 appears in the echo area and in the value of `this-command-keys.'.")
6667 before_command_restore_flag
= 1;
6668 before_command_key_count_1
= before_command_key_count
;
6669 before_command_echo_length_1
= before_command_echo_length
;
6672 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
6673 "Return the current depth in recursive edits.")
6677 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
6681 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
6682 "FOpen dribble file: ",
6683 "Start writing all keyboard characters to a dribble file called FILE.\n\
6684 If FILE is nil, close any open dribble file.")
6698 file
= Fexpand_file_name (file
, Qnil
);
6699 dribble
= fopen (XSTRING (file
)->data
, "w");
6704 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
6705 "Discard the contents of the terminal input buffer.\n\
6706 Also cancel any kbd macro being defined.")
6709 current_kboard
->defining_kbd_macro
= Qnil
;
6710 update_mode_lines
++;
6712 Vunread_command_events
= Qnil
;
6713 unread_command_char
= -1;
6715 discard_tty_input ();
6717 /* Without the cast, GCC complains that this assignment loses the
6718 volatile qualifier of kbd_store_ptr. Is there anything wrong
6720 kbd_fetch_ptr
= (struct input_event
*) kbd_store_ptr
;
6721 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
6727 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
6728 "Stop Emacs and return to superior process. You can resume later.\n\
6729 If `cannot-suspend' is non-nil, or if the system doesn't support job\n\
6730 control, run a subshell instead.\n\n\
6731 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
6732 to be read as terminal input by Emacs's parent, after suspension.\n\
6734 Before suspending, run the normal hook `suspend-hook'.\n\
6735 After resumption run the normal hook `suspend-resume-hook'.\n\
6737 Some operating systems cannot stop the Emacs process and resume it later.\n\
6738 On such systems, Emacs starts a subshell instead of suspending.")
6740 Lisp_Object stuffstring
;
6743 int count
= specpdl_ptr
- specpdl
;
6744 int old_height
, old_width
;
6746 struct gcpro gcpro1
, gcpro2
;
6747 extern init_sys_modes ();
6749 if (!NILP (stuffstring
))
6750 CHECK_STRING (stuffstring
, 0);
6752 /* Run the functions in suspend-hook. */
6753 if (!NILP (Vrun_hooks
))
6754 call1 (Vrun_hooks
, intern ("suspend-hook"));
6756 GCPRO1 (stuffstring
);
6757 get_frame_size (&old_width
, &old_height
);
6759 /* sys_suspend can get an error if it tries to fork a subshell
6760 and the system resources aren't available for that. */
6761 record_unwind_protect (init_sys_modes
, 0);
6762 stuff_buffered_input (stuffstring
);
6767 unbind_to (count
, Qnil
);
6769 /* Check if terminal/window size has changed.
6770 Note that this is not useful when we are running directly
6771 with a window system; but suspend should be disabled in that case. */
6772 get_frame_size (&width
, &height
);
6773 if (width
!= old_width
|| height
!= old_height
)
6774 change_frame_size (selected_frame
, height
, width
, 0, 0);
6776 /* Run suspend-resume-hook. */
6777 if (!NILP (Vrun_hooks
))
6778 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
6784 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
6785 Then in any case stuff anything Emacs has read ahead and not used. */
6787 stuff_buffered_input (stuffstring
)
6788 Lisp_Object stuffstring
;
6790 /* stuff_char works only in BSD, versions 4.2 and up. */
6793 register unsigned char *p
;
6795 if (STRINGP (stuffstring
))
6799 p
= XSTRING (stuffstring
)->data
;
6800 count
= XSTRING (stuffstring
)->size
;
6805 /* Anything we have read ahead, put back for the shell to read. */
6806 /* ?? What should this do when we have multiple keyboards??
6807 Should we ignore anything that was typed in at the "wrong" kboard? */
6808 for (; kbd_fetch_ptr
!= kbd_store_ptr
; kbd_fetch_ptr
++)
6810 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
6811 kbd_fetch_ptr
= kbd_buffer
;
6812 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
6813 stuff_char (kbd_fetch_ptr
->code
);
6814 kbd_fetch_ptr
->kind
= no_event
;
6815 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_fetch_ptr
6821 #endif /* BSD and not BSD4_1 */
6824 set_waiting_for_input (time_to_clear
)
6825 EMACS_TIME
*time_to_clear
;
6827 input_available_clear_time
= time_to_clear
;
6829 /* Tell interrupt_signal to throw back to read_char, */
6830 waiting_for_input
= 1;
6832 /* If interrupt_signal was called before and buffered a C-g,
6833 make it run again now, to avoid timing error. */
6834 if (!NILP (Vquit_flag
))
6835 quit_throw_to_read_char ();
6838 clear_waiting_for_input ()
6840 /* Tell interrupt_signal not to throw back to read_char, */
6841 waiting_for_input
= 0;
6842 input_available_clear_time
= 0;
6845 /* This routine is called at interrupt level in response to C-G.
6846 If interrupt_input, this is the handler for SIGINT.
6847 Otherwise, it is called from kbd_buffer_store_event,
6848 in handling SIGIO or SIGTINT.
6850 If `waiting_for_input' is non zero, then unless `echoing' is nonzero,
6851 immediately throw back to read_char.
6853 Otherwise it sets the Lisp variable quit-flag not-nil.
6854 This causes eval to throw, when it gets a chance.
6855 If quit-flag is already non-nil, it stops the job right away. */
6858 interrupt_signal (signalnum
) /* If we don't have an argument, */
6859 int signalnum
; /* some compilers complain in signal calls. */
6862 /* Must preserve main program's value of errno. */
6863 int old_errno
= errno
;
6866 if (!read_socket_hook
&& NILP (Vwindow_system
))
6868 /* USG systems forget handlers when they are used;
6869 must reestablish each time */
6870 signal (SIGINT
, interrupt_signal
);
6871 signal (SIGQUIT
, interrupt_signal
);
6877 if (!NILP (Vquit_flag
) && FRAME_TERMCAP_P (selected_frame
))
6882 #ifdef SIGTSTP /* Support possible in later USG versions */
6884 * On systems which can suspend the current process and return to the original
6885 * shell, this command causes the user to end up back at the shell.
6886 * The "Auto-save" and "Abort" questions are not asked until
6887 * the user elects to return to emacs, at which point he can save the current
6888 * job and either dump core or continue.
6893 if (sys_suspend () == -1)
6895 printf ("Not running as a subprocess;\n");
6896 printf ("you can continue or abort.\n");
6899 /* Perhaps should really fork an inferior shell?
6900 But that would not provide any way to get back
6901 to the original shell, ever. */
6902 printf ("No support for stopping a process on this operating system;\n");
6903 printf ("you can continue or abort.\n");
6904 #endif /* not VMS */
6905 #endif /* not SIGTSTP */
6907 /* We must remain inside the screen area when the internal terminal
6908 is used. Note that [Enter] is not echoed by dos. */
6911 /* It doesn't work to autosave while GC is in progress;
6912 the code used for auto-saving doesn't cope with the mark bit. */
6913 if (!gc_in_progress
)
6915 printf ("Auto-save? (y or n) ");
6917 if (((c
= getchar ()) & ~040) == 'Y')
6919 Fdo_auto_save (Qt
, Qnil
);
6921 printf ("\r\nAuto-save done");
6922 #else /* not MSDOS */
6923 printf ("Auto-save done\n");
6924 #endif /* not MSDOS */
6926 while (c
!= '\n') c
= getchar ();
6930 /* During GC, it must be safe to reenable quitting again. */
6931 Vinhibit_quit
= Qnil
;
6934 #endif /* not MSDOS */
6935 printf ("Garbage collection in progress; cannot auto-save now\r\n");
6936 printf ("but will instead do a real quit after garbage collection ends\r\n");
6941 printf ("\r\nAbort? (y or n) ");
6942 #else /* not MSDOS */
6944 printf ("Abort (and enter debugger)? (y or n) ");
6946 printf ("Abort (and dump core)? (y or n) ");
6947 #endif /* not VMS */
6948 #endif /* not MSDOS */
6950 if (((c
= getchar ()) & ~040) == 'Y')
6952 while (c
!= '\n') c
= getchar ();
6954 printf ("\r\nContinuing...\r\n");
6955 #else /* not MSDOS */
6956 printf ("Continuing...\n");
6957 #endif /* not MSDOS */
6963 /* If executing a function that wants to be interrupted out of
6964 and the user has not deferred quitting by binding `inhibit-quit'
6965 then quit right away. */
6966 if (immediate_quit
&& NILP (Vinhibit_quit
))
6970 Fsignal (Qquit
, Qnil
);
6973 /* Else request quit when it's safe */
6977 if (waiting_for_input
&& !echoing
)
6978 quit_throw_to_read_char ();
6983 /* Handle a C-g by making read_char return C-g. */
6985 quit_throw_to_read_char ()
6987 quit_error_check ();
6989 /* Prevent another signal from doing this before we finish. */
6990 clear_waiting_for_input ();
6993 Vunread_command_events
= Qnil
;
6994 unread_command_char
= -1;
6996 #if 0 /* Currently, sit_for is called from read_char without turning
6997 off polling. And that can call set_waiting_for_input.
6998 It seems to be harmless. */
6999 #ifdef POLL_FOR_INPUT
7000 /* May be > 1 if in recursive minibuffer. */
7001 if (poll_suppress_count
== 0)
7006 if (FRAMEP (internal_last_event_frame
)
7007 && XFRAME (internal_last_event_frame
) != selected_frame
)
7008 do_switch_frame (make_lispy_switch_frame (internal_last_event_frame
),
7012 _longjmp (getcjmp
, 1);
7015 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
7016 "Set mode of reading keyboard input.\n\
7017 First arg INTERRUPT non-nil means use input interrupts;\n\
7018 nil means use CBREAK mode.\n\
7019 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
7020 (no effect except in CBREAK mode).\n\
7021 Third arg META t means accept 8-bit input (for a Meta key).\n\
7022 META nil means ignore the top bit, on the assumption it is parity.\n\
7023 Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\
7024 Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\
7025 See also `current-input-mode'.")
7026 (interrupt
, flow
, meta
, quit
)
7027 Lisp_Object interrupt
, flow
, meta
, quit
;
7030 && (!INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400))
7031 error ("set-input-mode: QUIT must be an ASCII character");
7033 #ifdef POLL_FOR_INPUT
7038 /* this causes startup screen to be restored and messes with the mouse */
7043 /* Note SIGIO has been undef'd if FIONREAD is missing. */
7044 if (read_socket_hook
)
7046 /* When using X, don't give the user a real choice,
7047 because we haven't implemented the mechanisms to support it. */
7048 #ifdef NO_SOCK_SIGIO
7049 interrupt_input
= 0;
7050 #else /* not NO_SOCK_SIGIO */
7051 interrupt_input
= 1;
7052 #endif /* NO_SOCK_SIGIO */
7055 interrupt_input
= !NILP (interrupt
);
7056 #else /* not SIGIO */
7057 interrupt_input
= 0;
7058 #endif /* not SIGIO */
7060 /* Our VMS input only works by interrupts, as of now. */
7062 interrupt_input
= 1;
7065 flow_control
= !NILP (flow
);
7068 else if (EQ (meta
, Qt
))
7073 /* Don't let this value be out of range. */
7074 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
7080 #ifdef POLL_FOR_INPUT
7081 poll_suppress_count
= 1;
7087 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
7088 "Return information about the way Emacs currently reads keyboard input.\n\
7089 The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
7090 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\
7091 nil, Emacs is using CBREAK mode.\n\
7092 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\
7093 terminal; this does not apply if Emacs uses interrupt-driven input.\n\
7094 META is t if accepting 8-bit input with 8th bit as Meta flag.\n\
7095 META nil means ignoring the top bit, on the assumption it is parity.\n\
7096 META is neither t nor nil if accepting 8-bit input and using\n\
7097 all 8 bits as the character code.\n\
7098 QUIT is the character Emacs currently uses to quit.\n\
7099 The elements of this list correspond to the arguments of\n\
7105 val
[0] = interrupt_input
? Qt
: Qnil
;
7106 val
[1] = flow_control
? Qt
: Qnil
;
7107 val
[2] = meta_key
== 2 ? make_number (0) : meta_key
== 1 ? Qt
: Qnil
;
7108 XSETFASTINT (val
[3], quit_char
);
7110 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
7115 * Set up a new kboard object with reasonable initial values.
7121 kb
->Voverriding_terminal_local_map
= Qnil
;
7122 kb
->Vlast_command
= Qnil
;
7123 kb
->Vprefix_arg
= Qnil
;
7124 kb
->kbd_queue
= Qnil
;
7125 kb
->kbd_queue_has_data
= 0;
7126 kb
->immediate_echo
= 0;
7127 kb
->echoptr
= kb
->echobuf
;
7128 kb
->echo_after_prompt
= -1;
7129 kb
->kbd_macro_buffer
= 0;
7130 kb
->kbd_macro_bufsize
= 0;
7131 kb
->defining_kbd_macro
= Qnil
;
7132 kb
->Vlast_kbd_macro
= Qnil
;
7133 kb
->reference_count
= 0;
7134 kb
->Vsystem_key_alist
= Qnil
;
7135 kb
->system_key_syms
= Qnil
;
7136 kb
->Vdefault_minibuffer_frame
= Qnil
;
7140 * Destroy the contents of a kboard object, but not the object itself.
7141 * We use this just before deleting it, or if we're going to initialize
7148 if (kb
->kbd_macro_buffer
)
7149 xfree (kb
->kbd_macro_buffer
);
7158 for (kbp
= &all_kboards
; *kbp
!= kb
; kbp
= &(*kbp
)->next_kboard
)
7161 *kbp
= kb
->next_kboard
;
7169 /* This is correct before outermost invocation of the editor loop */
7170 command_loop_level
= -1;
7172 quit_char
= Ctl ('g');
7173 Vunread_command_events
= Qnil
;
7174 unread_command_char
= -1;
7176 recent_keys_index
= 0;
7177 kbd_fetch_ptr
= kbd_buffer
;
7178 kbd_store_ptr
= kbd_buffer
;
7179 kbd_buffer_frame_or_window
7180 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
7182 do_mouse_tracking
= Qnil
;
7187 /* This means that command_loop_1 won't try to select anything the first
7189 internal_last_event_frame
= Qnil
;
7190 Vlast_event_frame
= internal_last_event_frame
;
7194 current_kboard
= initial_kboard
;
7196 wipe_kboard (current_kboard
);
7197 init_kboard (current_kboard
);
7200 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
7202 kbd_buffer_frame_or_window
7203 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
7204 if (!noninteractive
&& !read_socket_hook
&& NILP (Vwindow_system
))
7206 signal (SIGINT
, interrupt_signal
);
7207 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
7208 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
7209 SIGQUIT and we can't tell which one it will give us. */
7210 signal (SIGQUIT
, interrupt_signal
);
7211 #endif /* HAVE_TERMIO */
7213 /* Note SIGIO has been undef'd if FIONREAD is missing. */
7215 if (!noninteractive
)
7216 signal (SIGIO
, input_available_signal
);
7219 /* Use interrupt input by default, if it works and noninterrupt input
7220 has deficiencies. */
7222 #ifdef INTERRUPT_INPUT
7223 interrupt_input
= 1;
7225 interrupt_input
= 0;
7228 /* Our VMS input only works by interrupts, as of now. */
7230 interrupt_input
= 1;
7236 if (keyboard_init_hook
)
7237 (*keyboard_init_hook
) ();
7239 #ifdef POLL_FOR_INPUT
7240 poll_suppress_count
= 1;
7245 /* This type's only use is in syms_of_keyboard, to initialize the
7246 event header symbols and put properties on them. */
7253 struct event_head head_table
[] = {
7254 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
7255 &Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
,
7256 &Qswitch_frame
, "switch-frame", &Qswitch_frame
,
7257 &Qdelete_frame
, "delete-frame", &Qdelete_frame
,
7258 &Qiconify_frame
, "iconify-frame", &Qiconify_frame
,
7259 &Qmake_frame_visible
, "make-frame-visible", &Qmake_frame_visible
,
7264 Qdisabled_command_hook
= intern ("disabled-command-hook");
7265 staticpro (&Qdisabled_command_hook
);
7267 Qself_insert_command
= intern ("self-insert-command");
7268 staticpro (&Qself_insert_command
);
7270 Qforward_char
= intern ("forward-char");
7271 staticpro (&Qforward_char
);
7273 Qbackward_char
= intern ("backward-char");
7274 staticpro (&Qbackward_char
);
7276 Qdisabled
= intern ("disabled");
7277 staticpro (&Qdisabled
);
7279 Qundefined
= intern ("undefined");
7280 staticpro (&Qundefined
);
7282 Qpre_command_hook
= intern ("pre-command-hook");
7283 staticpro (&Qpre_command_hook
);
7285 Qpost_command_hook
= intern ("post-command-hook");
7286 staticpro (&Qpost_command_hook
);
7288 Qpost_command_idle_hook
= intern ("post-command-idle-hook");
7289 staticpro (&Qpost_command_idle_hook
);
7291 Qdeferred_action_function
= intern ("deferred-action-function");
7292 staticpro (&Qdeferred_action_function
);
7294 Qcommand_hook_internal
= intern ("command-hook-internal");
7295 staticpro (&Qcommand_hook_internal
);
7297 Qfunction_key
= intern ("function-key");
7298 staticpro (&Qfunction_key
);
7299 Qmouse_click
= intern ("mouse-click");
7300 staticpro (&Qmouse_click
);
7302 Qmenu_enable
= intern ("menu-enable");
7303 staticpro (&Qmenu_enable
);
7305 Qmode_line
= intern ("mode-line");
7306 staticpro (&Qmode_line
);
7307 Qvertical_line
= intern ("vertical-line");
7308 staticpro (&Qvertical_line
);
7309 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
7310 staticpro (&Qvertical_scroll_bar
);
7311 Qmenu_bar
= intern ("menu-bar");
7312 staticpro (&Qmenu_bar
);
7314 Qabove_handle
= intern ("above-handle");
7315 staticpro (&Qabove_handle
);
7316 Qhandle
= intern ("handle");
7317 staticpro (&Qhandle
);
7318 Qbelow_handle
= intern ("below-handle");
7319 staticpro (&Qbelow_handle
);
7321 Qevent_kind
= intern ("event-kind");
7322 staticpro (&Qevent_kind
);
7323 Qevent_symbol_elements
= intern ("event-symbol-elements");
7324 staticpro (&Qevent_symbol_elements
);
7325 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
7326 staticpro (&Qevent_symbol_element_mask
);
7327 Qmodifier_cache
= intern ("modifier-cache");
7328 staticpro (&Qmodifier_cache
);
7330 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
7331 staticpro (&Qrecompute_lucid_menubar
);
7332 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
7333 staticpro (&Qactivate_menubar_hook
);
7335 Qpolling_period
= intern ("polling-period");
7336 staticpro (&Qpolling_period
);
7339 struct event_head
*p
;
7341 for (p
= head_table
;
7342 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
7345 *p
->var
= intern (p
->name
);
7347 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
7348 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
7352 button_down_location
= Fmake_vector (make_number (NUM_MOUSE_BUTTONS
), Qnil
);
7353 staticpro (&button_down_location
);
7357 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
7359 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
7360 for (i
= 0; i
< len
; i
++)
7361 if (modifier_names
[i
])
7362 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
7363 staticpro (&modifier_symbols
);
7366 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
7367 staticpro (&recent_keys
);
7369 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
7370 staticpro (&this_command_keys
);
7372 Qextended_command_history
= intern ("extended-command-history");
7373 Fset (Qextended_command_history
, Qnil
);
7374 staticpro (&Qextended_command_history
);
7376 kbd_buffer_frame_or_window
7377 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
7378 staticpro (&kbd_buffer_frame_or_window
);
7380 accent_key_syms
= Qnil
;
7381 staticpro (&accent_key_syms
);
7383 func_key_syms
= Qnil
;
7384 staticpro (&func_key_syms
);
7387 staticpro (&mouse_syms
);
7389 unread_switch_frame
= Qnil
;
7390 staticpro (&unread_switch_frame
);
7392 defsubr (&Sevent_convert_list
);
7393 defsubr (&Sread_key_sequence
);
7394 defsubr (&Srecursive_edit
);
7396 defsubr (&Strack_mouse
);
7398 defsubr (&Sinput_pending_p
);
7399 defsubr (&Scommand_execute
);
7400 defsubr (&Srecent_keys
);
7401 defsubr (&Sthis_command_keys
);
7402 defsubr (&Sreset_this_command_lengths
);
7403 defsubr (&Ssuspend_emacs
);
7404 defsubr (&Sabort_recursive_edit
);
7405 defsubr (&Sexit_recursive_edit
);
7406 defsubr (&Srecursion_depth
);
7407 defsubr (&Stop_level
);
7408 defsubr (&Sdiscard_input
);
7409 defsubr (&Sopen_dribble_file
);
7410 defsubr (&Sset_input_mode
);
7411 defsubr (&Scurrent_input_mode
);
7412 defsubr (&Sexecute_extended_command
);
7414 DEFVAR_LISP ("last-command-char", &last_command_char
,
7415 "Last input event that was part of a command.");
7417 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char
,
7418 "Last input event that was part of a command.");
7420 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
7421 "Last input event in a command, except for mouse menu events.\n\
7422 Mouse menus give back keys that don't look like mouse events;\n\
7423 this variable holds the actual mouse event that led to the menu,\n\
7424 so that you can determine whether the command was run by mouse or not.");
7426 DEFVAR_LISP ("last-input-char", &last_input_char
,
7427 "Last input event.");
7429 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char
,
7430 "Last input event.");
7432 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
7433 "List of objects to be read as next command input events.");
7435 DEFVAR_INT ("unread-command-char", &unread_command_char
,
7436 "If not -1, an object to be read as next command input event.");
7438 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
7439 "Meta-prefix character code. Meta-foo as command input\n\
7440 turns into this character followed by foo.");
7441 XSETINT (meta_prefix_char
, 033);
7443 DEFVAR_KBOARD ("last-command", Vlast_command
,
7444 "The last command executed. Normally a symbol with a function definition,\n\
7445 but can be whatever was found in the keymap, or whatever the variable\n\
7446 `this-command' was set to by that command.\n\
7448 The value `mode-exit' is special; it means that the previous command\n\
7449 read an event that told it to exit, and it did so and unread that event.\n\
7450 In other words, the present command is the event that made the previous\n\
7453 The value `kill-region' is special; it means that the previous command\n\
7454 was a kill command.");
7456 DEFVAR_LISP ("this-command", &this_command
,
7457 "The command now being executed.\n\
7458 The command can set this variable; whatever is put here\n\
7459 will be in `last-command' during the following command.");
7460 this_command
= Qnil
;
7462 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
7463 "*Number of keyboard input characters between auto-saves.\n\
7464 Zero means disable autosaving due to number of characters typed.");
7465 auto_save_interval
= 300;
7467 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
7468 "*Number of seconds idle time before auto-save.\n\
7469 Zero or nil means disable auto-saving due to idleness.\n\
7470 After auto-saving due to this many seconds of idle time,\n\
7471 Emacs also does a garbage collection if that seems to be warranted.");
7472 XSETFASTINT (Vauto_save_timeout
, 30);
7474 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes
,
7475 "*Nonzero means echo unfinished commands after this many seconds of pause.");
7476 echo_keystrokes
= 1;
7478 DEFVAR_INT ("polling-period", &polling_period
,
7479 "*Interval between polling for input during Lisp execution.\n\
7480 The reason for polling is to make C-g work to stop a running program.\n\
7481 Polling is needed only when using X windows and SIGIO does not work.\n\
7482 Polling is automatically disabled in all other cases.");
7485 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
7486 "*Maximum time between mouse clicks to make a double-click.\n\
7487 Measured in milliseconds. nil means disable double-click recognition;\n\
7488 t means double-clicks have no time limit and are detected\n\
7489 by position only.");
7490 Vdouble_click_time
= make_number (500);
7492 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
7493 "*Non-nil means inhibit local map menu bar menus.");
7494 inhibit_local_menu_bar_menus
= 0;
7496 DEFVAR_INT ("num-input-keys", &num_input_keys
,
7497 "Number of complete keys read from the keyboard so far.");
7500 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
7501 "The frame in which the most recently read event occurred.\n\
7502 If the last event came from a keyboard macro, this is set to `macro'.");
7503 Vlast_event_frame
= Qnil
;
7505 DEFVAR_LISP ("help-char", &Vhelp_char
,
7506 "Character to recognize as meaning Help.\n\
7507 When it is read, do `(eval help-form)', and display result if it's a string.\n\
7508 If the value of `help-form' is nil, this char can be read normally.");
7509 XSETINT (Vhelp_char
, Ctl ('H'));
7511 DEFVAR_LISP ("help-event-list", &Vhelp_event_list
,
7512 "List of input events to recognize as meaning Help.\n\
7513 These work just like the value of `help-char' (see that).");
7514 Vhelp_event_list
= Qnil
;
7516 DEFVAR_LISP ("help-form", &Vhelp_form
,
7517 "Form to execute when character `help-char' is read.\n\
7518 If the form returns a string, that string is displayed.\n\
7519 If `help-form' is nil, the help char is not recognized.");
7522 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
7523 "Command to run when `help-char' character follows a prefix key.\n\
7524 This command is used only when there is no actual binding\n\
7525 for that character after that prefix key.");
7526 Vprefix_help_command
= Qnil
;
7528 DEFVAR_LISP ("top-level", &Vtop_level
,
7529 "Form to evaluate when Emacs starts up.\n\
7530 Useful to set before you dump a modified Emacs.");
7533 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
7534 "Translate table for keyboard input, or nil.\n\
7535 Each character is looked up in this string and the contents used instead.\n\
7536 The value may be a string, a vector, or a char-table.\n\
7537 If it is a string or vector of length N,\n\
7538 character codes N and up are untranslated.\n\
7539 In a vector or a char-table, an element which is nil means \"no translation\".");
7540 Vkeyboard_translate_table
= Qnil
;
7542 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
7543 "Non-nil means to always spawn a subshell instead of suspending,\n\
7544 even if the operating system has support for stopping a process.");
7547 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
7548 "Non-nil means prompt with menus when appropriate.\n\
7549 This is done when reading from a keymap that has a prompt string,\n\
7550 for elements that have prompt strings.\n\
7551 The menu is displayed on the screen\n\
7552 if X menus were enabled at configuration\n\
7553 time and the previous event was a mouse click prefix key.\n\
7554 Otherwise, menu prompting uses the echo area.");
7557 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
7558 "Character to see next line of menu prompt.\n\
7559 Type this character while in a menu prompt to rotate around the lines of it.");
7560 XSETINT (menu_prompt_more_char
, ' ');
7562 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
7563 "A mask of additional modifier keys to use with every keyboard character.\n\
7564 Emacs applies the modifiers of the character stored here to each keyboard\n\
7565 character it reads. For example, after evaluating the expression\n\
7566 (setq extra-keyboard-modifiers ?\\C-x)\n\
7567 all input characters will have the control modifier applied to them.\n\
7569 Note that the character ?\\C-@, equivalent to the integer zero, does\n\
7570 not count as a control character; rather, it counts as a character\n\
7571 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\
7572 cancels any modification.");
7573 extra_keyboard_modifiers
= 0;
7575 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
7576 "If an editing command sets this to t, deactivate the mark afterward.\n\
7577 The command loop sets this to nil before each command,\n\
7578 and tests the value when the command returns.\n\
7579 Buffer modification stores t in this variable.");
7580 Vdeactivate_mark
= Qnil
;
7582 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
7583 "Temporary storage of pre-command-hook or post-command-hook.");
7584 Vcommand_hook_internal
= Qnil
;
7586 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
7587 "Normal hook run before each command is executed.\n\
7588 Errors running the hook are caught and ignored.");
7589 Vpre_command_hook
= Qnil
;
7591 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
7592 "Normal hook run after each command is executed.\n\
7593 Errors running the hook are caught and ignored.");
7594 Vpost_command_hook
= Qnil
;
7596 DEFVAR_LISP ("post-command-idle-hook", &Vpost_command_idle_hook
,
7597 "Normal hook run after each command is executed, if idle.\n\
7598 Errors running the hook are caught and ignored.");
7599 Vpost_command_idle_hook
= Qnil
;
7601 DEFVAR_INT ("post-command-idle-delay", &post_command_idle_delay
,
7602 "Delay time before running `post-command-idle-delay'.\n\
7603 This is measured in microseconds.");
7604 post_command_idle_delay
= 100000;
7606 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
7607 "t means menu bar, specified Lucid style, needs to be recomputed.");
7608 Vlucid_menu_bar_dirty_flag
= Qnil
;
7610 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
7611 "List of menu bar items to move to the end of the menu bar.\n\
7612 The elements of the list are event types that may have menu bar bindings.");
7613 Vmenu_bar_final_items
= Qnil
;
7615 DEFVAR_KBOARD ("overriding-terminal-local-map",
7616 Voverriding_terminal_local_map
,
7617 "Keymap that overrides all other local keymaps.\n\
7618 If this variable is non-nil, it is used as a keymap instead of the\n\
7619 buffer's local map, and the minor mode keymaps and text property keymaps.");
7621 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
7622 "Keymap that overrides all other local keymaps.\n\
7623 If this variable is non-nil, it is used as a keymap instead of the\n\
7624 buffer's local map, and the minor mode keymaps and text property keymaps.");
7625 Voverriding_local_map
= Qnil
;
7627 DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag
,
7628 "Non-nil means `overriding-local-map' applies to the menu bar.\n\
7629 Otherwise, the menu bar continues to reflect the buffer's local map\n\
7630 and the minor mode maps regardless of `overriding-local-map'.");
7631 Voverriding_local_map_menu_flag
= Qnil
;
7633 DEFVAR_LISP ("special-event-map", &Vspecial_event_map
,
7634 "Keymap defining bindings for special events to execute at low level.");
7635 Vspecial_event_map
= Fcons (intern ("keymap"), Qnil
);
7637 DEFVAR_LISP ("track-mouse", &do_mouse_tracking
,
7638 "*Non-nil means generate motion events for mouse motion.");
7640 DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist
,
7641 "Alist of system-specific X windows key symbols.\n\
7642 Each element should have the form (N . SYMBOL) where N is the\n\
7643 numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\
7644 and SYMBOL is its name.");
7646 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
7647 "List of deferred actions to be performed at a later time.\n\
7648 The precise format isn't relevant here; we just check whether it is nil.");
7649 Vdeferred_action_list
= Qnil
;
7651 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
7652 "Function to call to handle deferred actions, after each command.\n\
7653 This function is called with no arguments after each command\n\
7654 whenever `deferred-action-list' is non-nil.");
7655 Vdeferred_action_function
= Qnil
;
7657 DEFVAR_LISP ("suggest-key-bindings", &Vsuggest_key_bindings
,
7658 "Non-nil means show the equivalent key-binding when M-x command has one.\n\
7659 The value can be a length of time to show the message for.\n\
7660 If the value is non-nil and not a number, we wait 2 seconds.");
7661 Vsuggest_key_bindings
= Qt
;
7663 DEFVAR_LISP ("column-number-mode", &Vcolumn_number_mode
,
7664 "Non-nil enables display of the current column number in the mode line.");
7665 Vcolumn_number_mode
= Qnil
;
7670 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
7671 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
7672 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
7673 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
7674 initial_define_key (meta_map
, 'x', "execute-extended-command");
7676 initial_define_lispy_key (Vspecial_event_map
, "delete-frame",
7677 "handle-delete-frame");
7678 initial_define_lispy_key (Vspecial_event_map
, "iconify-frame",
7680 initial_define_lispy_key (Vspecial_event_map
, "make-frame-visible",