1 /* Keyboard and mouse input; editor command loop.
2 Copyright (C) 1985,86,87,88,89,93,94,95 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* Allow config.h to undefine symbols found here. */
28 #include "termhooks.h"
35 #include "dispextern.h"
37 #include "intervals.h"
38 #include "blockinput.h"
47 #include <sys/ioctl.h>
49 #endif /* not MSDOS */
51 #include "syssignal.h"
54 /* This is to get the definitions of the XK_ symbols. */
59 /* Include systime.h after xterm.h to avoid double inclusion of time.h. */
64 /* Variables for blockinput.h: */
66 /* Non-zero if interrupt input is blocked right now. */
67 int interrupt_input_blocked
;
69 /* Nonzero means an input interrupt has arrived
70 during the current critical section. */
71 int interrupt_input_pending
;
74 /* File descriptor to use for input. */
78 /* Make all keyboard buffers much bigger when using X windows. */
79 #define KBD_BUFFER_SIZE 4096
80 #else /* No X-windows, character input */
81 #define KBD_BUFFER_SIZE 256
82 #endif /* No X-windows */
84 /* Following definition copied from eval.c */
88 struct backtrace
*next
;
89 Lisp_Object
*function
;
90 Lisp_Object
*args
; /* Points to vector of args. */
91 int nargs
; /* length of vector. If nargs is UNEVALLED,
92 args points to slot holding list of
98 KBOARD
*initial_kboard
;
99 KBOARD
*current_kboard
;
103 KBOARD the_only_kboard
;
106 /* Non-nil disable property on a command means
107 do not execute it; call disabled-command-hook's value instead. */
108 Lisp_Object Qdisabled
, Qdisabled_command_hook
;
110 #define NUM_RECENT_KEYS (100)
111 int recent_keys_index
; /* Index for storing next element into recent_keys */
112 int total_keys
; /* Total number of elements stored into recent_keys */
113 Lisp_Object recent_keys
; /* A vector, holding the last 100 keystrokes */
115 /* Vector holding the key sequence that invoked the current command.
116 It is reused for each command, and it may be longer than the current
117 sequence; this_command_key_count indicates how many elements
118 actually mean something.
119 It's easier to staticpro a single Lisp_Object than an array. */
120 Lisp_Object this_command_keys
;
121 int this_command_key_count
;
123 /* Record values of this_command_key_count and echo_length ()
124 before this command was read. */
125 static int before_command_key_count
;
126 static int before_command_echo_length
;
127 /* Values of before_command_key_count and before_command_echo_length
128 saved by reset-this-command-lengths. */
129 static int before_command_key_count_1
;
130 static int before_command_echo_length_1
;
131 /* Flag set by reset-this-command-lengths,
132 saying to reset the lengths when add_command_key is called. */
133 static int before_command_restore_flag
;
135 extern int minbuf_level
;
137 extern struct backtrace
*backtrace_list
;
139 /* Nonzero means do menu prompting. */
140 static int menu_prompting
;
142 /* Character to see next line of menu prompt. */
143 static Lisp_Object menu_prompt_more_char
;
145 /* For longjmp to where kbd input is being done. */
146 static jmp_buf getcjmp
;
148 /* True while doing kbd input. */
149 int waiting_for_input
;
151 /* True while displaying for echoing. Delays C-g throwing. */
154 /* Nonzero means disregard local maps for the menu bar. */
155 static int inhibit_local_menu_bar_menus
;
157 /* Nonzero means C-g should cause immediate error-signal. */
160 /* Character to recognize as the help char. */
161 Lisp_Object Vhelp_char
;
163 /* List of other event types to recognize as meaning "help". */
164 Lisp_Object Vhelp_event_list
;
166 /* Form to execute when help char is typed. */
167 Lisp_Object Vhelp_form
;
169 /* Command to run when the help character follows a prefix key. */
170 Lisp_Object Vprefix_help_command
;
172 /* List of items that should move to the end of the menu bar. */
173 Lisp_Object Vmenu_bar_final_items
;
175 /* Character that causes a quit. Normally C-g.
177 If we are running on an ordinary terminal, this must be an ordinary
178 ASCII char, since we want to make it our interrupt character.
180 If we are not running on an ordinary terminal, it still needs to be
181 an ordinary ASCII char. This character needs to be recognized in
182 the input interrupt handler. At this point, the keystroke is
183 represented as a struct input_event, while the desired quit
184 character is specified as a lispy event. The mapping from struct
185 input_events to lispy events cannot run in an interrupt handler,
186 and the reverse mapping is difficult for anything but ASCII
189 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
193 extern Lisp_Object current_global_map
;
194 extern int minibuf_level
;
196 /* If non-nil, this is a map that overrides all other local maps. */
197 Lisp_Object Voverriding_local_map
;
199 /* If non-nil, Voverriding_local_map applies to the menu bar. */
200 Lisp_Object Voverriding_local_map_menu_flag
;
202 /* Keymap that defines special misc events that should
203 be processed immediately at a low level. */
204 Lisp_Object Vspecial_event_map
;
206 /* Current depth in recursive edits. */
207 int command_loop_level
;
209 /* Total number of times command_loop has read a key sequence. */
212 /* Last input character read as a command. */
213 Lisp_Object last_command_char
;
215 /* Last input character read as a command, not counting menus
216 reached by the mouse. */
217 Lisp_Object last_nonmenu_event
;
219 /* Last input character read for any purpose. */
220 Lisp_Object last_input_char
;
222 /* If not Qnil, a list of objects to be read as subsequent command input. */
223 Lisp_Object Vunread_command_events
;
225 /* If not -1, an event to be read as subsequent command input. */
226 int unread_command_char
;
228 /* If not Qnil, this is a switch-frame event which we decided to put
229 off until the end of a key sequence. This should be read as the
230 next command input, after any unread_command_events.
232 read_key_sequence uses this to delay switch-frame events until the
233 end of the key sequence; Fread_char uses it to put off switch-frame
234 events until a non-ASCII event is acceptable as input. */
235 Lisp_Object unread_switch_frame
;
237 /* A mask of extra modifier bits to put into every keyboard char. */
238 int extra_keyboard_modifiers
;
240 /* Char to use as prefix when a meta character is typed in.
241 This is bound on entry to minibuffer in case ESC is changed there. */
243 Lisp_Object meta_prefix_char
;
245 /* Last size recorded for a current buffer which is not a minibuffer. */
246 static int last_non_minibuf_size
;
248 /* Number of idle seconds before an auto-save and garbage collection. */
249 static Lisp_Object Vauto_save_timeout
;
251 /* Total number of times read_char has returned. */
254 /* Total number of times read_char has returned, outside of macros. */
255 int num_nonmacro_input_chars
;
257 /* Auto-save automatically when this many characters have been typed
258 since the last time. */
260 static int auto_save_interval
;
262 /* Value of num_nonmacro_input_chars as of last auto save. */
266 /* The command being executed by the command loop.
267 Commands may set this, and the value set will be copied into
268 current_kboard->Vlast_command instead of the actual command. */
269 Lisp_Object this_command
;
271 /* The value of point when the last command was executed. */
272 int last_point_position
;
274 /* The buffer that was current when the last command was started. */
275 Lisp_Object last_point_position_buffer
;
278 /* The frame in which the last input event occurred, or Qmacro if the
279 last event came from a macro. We use this to determine when to
280 generate switch-frame events. This may be cleared by functions
281 like Fselect_frame, to make sure that a switch-frame event is
282 generated by the next character. */
283 Lisp_Object internal_last_event_frame
;
286 /* A user-visible version of the above, intended to allow users to
287 figure out where the last event came from, if the event doesn't
288 carry that information itself (i.e. if it was a character). */
289 Lisp_Object Vlast_event_frame
;
291 /* The timestamp of the last input event we received from the X server.
292 X Windows wants this for selection ownership. */
293 unsigned long last_event_timestamp
;
295 Lisp_Object Qself_insert_command
;
296 Lisp_Object Qforward_char
;
297 Lisp_Object Qbackward_char
;
298 Lisp_Object Qundefined
;
300 /* read_key_sequence stores here the command definition of the
301 key sequence that it reads. */
302 Lisp_Object read_key_sequence_cmd
;
304 /* Form to evaluate (if non-nil) when Emacs is started. */
305 Lisp_Object Vtop_level
;
307 /* User-supplied string to translate input characters through. */
308 Lisp_Object Vkeyboard_translate_table
;
310 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
311 extern Lisp_Object Vfunction_key_map
;
313 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
314 Lisp_Object Vkey_translation_map
;
316 /* Non-nil means deactivate the mark at end of this command. */
317 Lisp_Object Vdeactivate_mark
;
319 /* Menu bar specified in Lucid Emacs fashion. */
321 Lisp_Object Vlucid_menu_bar_dirty_flag
;
322 Lisp_Object Qrecompute_lucid_menubar
, Qactivate_menubar_hook
;
324 /* Hooks to run before and after each command. */
325 Lisp_Object Qpre_command_hook
, Qpost_command_hook
;
326 Lisp_Object Vpre_command_hook
, Vpost_command_hook
;
327 Lisp_Object Qcommand_hook_internal
, Vcommand_hook_internal
;
329 /* List of deferred actions to be performed at a later time.
330 The precise format isn't relevant here; we just check whether it is nil. */
331 Lisp_Object Vdeferred_action_list
;
333 /* Function to call to handle deferred actions, when there are any. */
334 Lisp_Object Vdeferred_action_function
;
335 Lisp_Object Qdeferred_action_function
;
337 /* File in which we write all commands we read. */
340 /* Nonzero if input is available. */
343 /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
344 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
348 extern char *pending_malloc_warning
;
350 /* Circular buffer for pre-read keyboard input. */
351 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
353 /* Vector to GCPRO the frames and windows mentioned in kbd_buffer.
355 The interrupt-level event handlers will never enqueue an event on a
356 frame which is not in Vframe_list, and once an event is dequeued,
357 internal_last_event_frame or the event itself points to the frame.
360 But while the event is sitting in the queue, it's completely
361 unprotected. Suppose the user types one command which will run for
362 a while and then delete a frame, and then types another event at
363 the frame that will be deleted, before the command gets around to
364 it. Suppose there are no references to this frame elsewhere in
365 Emacs, and a GC occurs before the second event is dequeued. Now we
366 have an event referring to a freed frame, which will crash Emacs
369 Similar things happen when an event on a scroll bar is enqueued; the
370 window may be deleted while the event is in the queue.
372 So, we use this vector to protect the frame_or_window field in the
373 event queue. That way, they'll be dequeued as dead frames or
374 windows, but still valid lisp objects.
376 If kbd_buffer[i].kind != no_event, then
377 (XVECTOR (kbd_buffer_frame_or_window)->contents[i]
378 == kbd_buffer[i].frame_or_window. */
379 static Lisp_Object kbd_buffer_frame_or_window
;
381 /* Pointer to next available character in kbd_buffer.
382 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
383 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the
384 next available char is in kbd_buffer[0]. */
385 static struct input_event
*kbd_fetch_ptr
;
387 /* Pointer to next place to store character in kbd_buffer. This
388 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
389 character should go in kbd_buffer[0]. */
390 static volatile struct input_event
*kbd_store_ptr
;
392 /* The above pair of variables forms a "queue empty" flag. When we
393 enqueue a non-hook event, we increment kbd_store_ptr. When we
394 dequeue a non-hook event, we increment kbd_fetch_ptr. We say that
395 there is input available iff the two pointers are not equal.
397 Why not just have a flag set and cleared by the enqueuing and
398 dequeuing functions? Such a flag could be screwed up by interrupts
399 at inopportune times. */
401 /* If this flag is non-nil, we check mouse_moved to see when the
402 mouse moves, and motion events will appear in the input stream.
403 Otherwise, mouse motion is ignored. */
404 static Lisp_Object do_mouse_tracking
;
406 /* Symbols to head events. */
407 Lisp_Object Qmouse_movement
;
408 Lisp_Object Qscroll_bar_movement
;
409 Lisp_Object Qswitch_frame
;
410 Lisp_Object Qdelete_frame
;
411 Lisp_Object Qiconify_frame
;
412 Lisp_Object Qmake_frame_visible
;
414 /* Symbols to denote kinds of events. */
415 Lisp_Object Qfunction_key
;
416 Lisp_Object Qmouse_click
;
417 /* Lisp_Object Qmouse_movement; - also an event header */
419 /* Properties of event headers. */
420 Lisp_Object Qevent_kind
;
421 Lisp_Object Qevent_symbol_elements
;
423 Lisp_Object Qmenu_enable
;
425 /* An event header symbol HEAD may have a property named
426 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
427 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
428 mask of modifiers applied to it. If present, this is used to help
429 speed up parse_modifiers. */
430 Lisp_Object Qevent_symbol_element_mask
;
432 /* An unmodified event header BASE may have a property named
433 Qmodifier_cache, which is an alist mapping modifier masks onto
434 modified versions of BASE. If present, this helps speed up
436 Lisp_Object Qmodifier_cache
;
438 /* Symbols to use for parts of windows. */
439 Lisp_Object Qmode_line
;
440 Lisp_Object Qvertical_line
;
441 Lisp_Object Qvertical_scroll_bar
;
442 Lisp_Object Qmenu_bar
;
444 extern Lisp_Object Qmenu_enable
;
446 Lisp_Object
recursive_edit_unwind (), command_loop ();
447 Lisp_Object
Fthis_command_keys ();
448 Lisp_Object Qextended_command_history
;
450 extern char *x_get_keysym_name ();
452 Lisp_Object Qpolling_period
;
454 extern Lisp_Object Vprint_level
, Vprint_length
;
456 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
458 EMACS_TIME
*input_available_clear_time
;
460 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
461 Default is 1 if INTERRUPT_INPUT is defined. */
464 /* Nonzero while interrupts are temporarily deferred during redisplay. */
465 int interrupts_deferred
;
467 /* nonzero means use ^S/^Q for flow control. */
470 /* Allow m- file to inhibit use of FIONREAD. */
471 #ifdef BROKEN_FIONREAD
475 /* We are unable to use interrupts if FIONREAD is not available,
476 so flush SIGIO so we won't try. */
483 /* If we support X Windows, turn on the code to poll periodically
484 to detect C-g. It isn't actually used when doing interrupt input. */
485 #ifdef HAVE_X_WINDOWS
486 #define POLL_FOR_INPUT
489 /* Global variable declarations. */
491 /* Function for init_keyboard to call with no args (if nonzero). */
492 void (*keyboard_init_hook
) ();
494 static int read_avail_input ();
495 static void get_input_pending ();
496 static int readable_events ();
497 static Lisp_Object
read_char_x_menu_prompt ();
498 static Lisp_Object
read_char_minibuf_menu_prompt ();
499 static Lisp_Object
make_lispy_event ();
501 static Lisp_Object
make_lispy_movement ();
503 static Lisp_Object
modify_event_symbol ();
504 static Lisp_Object
make_lispy_switch_frame ();
505 static int parse_solitary_modifier ();
507 /* > 0 if we are to echo keystrokes. */
508 static int echo_keystrokes
;
510 /* Nonzero means don't try to suspend even if the operating system seems
512 static int cannot_suspend
;
514 #define min(a,b) ((a)<(b)?(a):(b))
515 #define max(a,b) ((a)>(b)?(a):(b))
517 /* Install the string STR as the beginning of the string of echoing,
518 so that it serves as a prompt for the next character.
519 Also start echoing. */
524 int len
= strlen (str
);
526 if (len
> ECHOBUFSIZE
- 4)
527 len
= ECHOBUFSIZE
- 4;
528 bcopy (str
, current_kboard
->echobuf
, len
);
529 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
530 *current_kboard
->echoptr
= '\0';
532 current_kboard
->echo_after_prompt
= len
;
537 /* Add C to the echo string, if echoing is going on.
538 C can be a character, which is printed prettily ("M-C-x" and all that
539 jazz), or a symbol, whose name is printed. */
544 extern char *push_key_description ();
546 if (current_kboard
->immediate_echo
)
548 char *ptr
= current_kboard
->echoptr
;
550 if (ptr
!= current_kboard
->echobuf
)
553 /* If someone has passed us a composite event, use its head symbol. */
558 if (ptr
- current_kboard
->echobuf
> ECHOBUFSIZE
- 6)
561 ptr
= push_key_description (XINT (c
), ptr
);
563 else if (SYMBOLP (c
))
565 struct Lisp_String
*name
= XSYMBOL (c
)->name
;
566 if ((ptr
- current_kboard
->echobuf
) + name
->size
+ 4 > ECHOBUFSIZE
)
568 bcopy (name
->data
, ptr
, name
->size
);
572 if (current_kboard
->echoptr
== current_kboard
->echobuf
575 strcpy (ptr
, " (Type ? for further options)");
580 current_kboard
->echoptr
= ptr
;
586 /* Temporarily add a dash to the end of the echo string if it's not
587 empty, so that it serves as a mini-prompt for the very next character. */
591 if (!current_kboard
->immediate_echo
592 && current_kboard
->echoptr
== current_kboard
->echobuf
)
594 /* Do nothing if we just printed a prompt. */
595 if (current_kboard
->echo_after_prompt
596 == current_kboard
->echoptr
- current_kboard
->echobuf
)
598 /* Do nothing if not echoing at all. */
599 if (current_kboard
->echoptr
== 0)
602 /* Put a dash at the end of the buffer temporarily,
603 but make it go away when the next character is added. */
604 current_kboard
->echoptr
[0] = '-';
605 current_kboard
->echoptr
[1] = 0;
610 /* Display the current echo string, and begin echoing if not already
615 if (!current_kboard
->immediate_echo
)
618 current_kboard
->immediate_echo
= 1;
620 for (i
= 0; i
< this_command_key_count
; i
++)
623 c
= XVECTOR (this_command_keys
)->contents
[i
];
624 if (! (EVENT_HAS_PARAMETERS (c
)
625 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
632 message1_nolog (current_kboard
->echobuf
);
635 if (waiting_for_input
&& !NILP (Vquit_flag
))
636 quit_throw_to_read_char ();
639 /* Turn off echoing, for the start of a new command. */
643 current_kboard
->immediate_echo
= 0;
644 current_kboard
->echoptr
= current_kboard
->echobuf
;
645 current_kboard
->echo_after_prompt
= -1;
648 /* Return the length of the current echo string. */
653 return current_kboard
->echoptr
- current_kboard
->echobuf
;
656 /* Truncate the current echo message to its first LEN chars.
657 This and echo_char get used by read_key_sequence when the user
658 switches frames while entering a key sequence. */
664 current_kboard
->echobuf
[len
] = '\0';
665 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
666 truncate_echo_area (len
);
670 /* Functions for manipulating this_command_keys. */
672 add_command_key (key
)
675 int size
= XVECTOR (this_command_keys
)->size
;
677 /* If reset-this-command-length was called recently, obey it now.
678 See the doc string of that function for an explanation of why. */
679 if (before_command_restore_flag
)
681 this_command_key_count
= before_command_key_count_1
;
682 echo_truncate (before_command_echo_length_1
);
683 before_command_restore_flag
= 0;
686 if (this_command_key_count
>= size
)
688 Lisp_Object new_keys
;
690 new_keys
= Fmake_vector (make_number (size
* 2), Qnil
);
691 bcopy (XVECTOR (this_command_keys
)->contents
,
692 XVECTOR (new_keys
)->contents
,
693 size
* sizeof (Lisp_Object
));
695 this_command_keys
= new_keys
;
698 XVECTOR (this_command_keys
)->contents
[this_command_key_count
++] = key
;
704 int count
= specpdl_ptr
- specpdl
;
707 if (command_loop_level
> 0)
709 specbind (Qstandard_output
, Qt
);
710 specbind (Qstandard_input
, Qt
);
713 val
= command_loop ();
715 Fsignal (Qquit
, Qnil
);
717 return unbind_to (count
, Qnil
);
720 /* When an auto-save happens, record the "time", and don't do again soon. */
724 last_auto_save
= num_nonmacro_input_chars
;
727 /* Make an auto save happen as soon as possible at command level. */
729 force_auto_save_soon ()
731 last_auto_save
= - auto_save_interval
- 1;
733 record_asynch_buffer_change ();
736 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
737 "Invoke the editor command loop recursively.\n\
738 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
739 that tells this function to return.\n\
740 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
741 This function is called by the editor initialization to begin editing.")
744 int count
= specpdl_ptr
- specpdl
;
747 command_loop_level
++;
748 update_mode_lines
= 1;
750 record_unwind_protect (recursive_edit_unwind
,
752 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
756 return unbind_to (count
, Qnil
);
760 recursive_edit_unwind (buffer
)
764 Fset_buffer (buffer
);
766 command_loop_level
--;
767 update_mode_lines
= 1;
775 #if 0 /* Theory: if there's anything in Vunread_command_events,
776 it will right away be read by read_key_sequence,
777 and then if we do switch KBOARDS, it will go into the side
778 queue then. So we don't need to do anything special here -- rms. */
779 if (CONSP (Vunread_command_events
))
781 current_kboard
->kbd_queue
782 = nconc2 (Vunread_command_events
, current_kboard
->kbd_queue
);
783 current_kboard
->kbd_queue_has_data
= 1;
785 Vunread_command_events
= Qnil
;
791 /* Switch to the single-kboard state, making current_kboard
792 the only KBOARD from which further input is accepted. */
795 single_kboard_state ()
802 /* Maintain a stack of kboards, so other parts of Emacs
803 can switch temporarily to the kboard of a given frame
804 and then revert to the previous status. */
809 struct kboard_stack
*next
;
812 static struct kboard_stack
*kboard_stack
;
815 push_frame_kboard (f
)
819 struct kboard_stack
*p
820 = (struct kboard_stack
*) xmalloc (sizeof (struct kboard_stack
));
822 p
->next
= kboard_stack
;
823 p
->kboard
= current_kboard
;
826 current_kboard
= FRAME_KBOARD (f
);
834 struct kboard_stack
*p
= kboard_stack
;
835 current_kboard
= p
->kboard
;
836 kboard_stack
= p
->next
;
841 /* Handle errors that are not handled at inner levels
842 by printing an error message and returning to the editor command loop. */
848 Lisp_Object old_level
, old_length
;
850 Vstandard_output
= Qt
;
851 Vstandard_input
= Qt
;
852 Vexecuting_macro
= Qnil
;
853 current_kboard
->Vprefix_arg
= Qnil
;
856 /* Avoid unquittable loop if data contains a circular list. */
857 old_level
= Vprint_level
;
858 old_length
= Vprint_length
;
859 XSETFASTINT(Vprint_level
, 10);
860 XSETFASTINT(Vprint_length
, 10);
861 cmd_error_internal (data
, NULL
);
862 Vprint_level
= old_level
;
863 Vprint_length
= old_length
;
867 Vinhibit_quit
= Qnil
;
872 return make_number (0);
875 cmd_error_internal (data
, context
)
879 Lisp_Object errmsg
, tail
, errname
, file_error
;
886 echo_area_glyphs
= 0;
888 /* If the window system or terminal frame hasn't been initialized
889 yet, or we're not interactive, it's best to dump this message out
890 to stderr and exit. */
891 if (! FRAME_MESSAGE_BUF (selected_frame
)
893 stream
= Qexternal_debugging_output
;
902 write_string_1 (context
, -1, stream
);
904 errname
= Fcar (data
);
906 if (EQ (errname
, Qerror
))
909 if (!CONSP (data
)) data
= Qnil
;
910 errmsg
= Fcar (data
);
915 errmsg
= Fget (errname
, Qerror_message
);
916 file_error
= Fmemq (Qfile_error
,
917 Fget (errname
, Qerror_conditions
));
920 /* Print an error message including the data items.
921 This is done by printing it into a scratch buffer
922 and then making a copy of the text in the buffer. */
924 if (!CONSP (data
)) data
= Qnil
;
928 /* For file-error, make error message by concatenating
929 all the data items. They are all strings. */
930 if (!NILP (file_error
) && !NILP (tail
))
931 errmsg
= XCONS (tail
)->car
, tail
= XCONS (tail
)->cdr
;
933 if (STRINGP (errmsg
))
934 Fprinc (errmsg
, stream
);
936 write_string_1 ("peculiar error", -1, stream
);
938 for (i
= 0; CONSP (tail
); tail
= Fcdr (tail
), i
++)
940 write_string_1 (i
? ", " : ": ", 2, stream
);
941 if (!NILP (file_error
))
942 Fprinc (Fcar (tail
), stream
);
944 Fprin1 (Fcar (tail
), stream
);
948 /* If the window system or terminal frame hasn't been initialized
949 yet, or we're in -batch mode, this error should cause Emacs to exit. */
950 if (! FRAME_MESSAGE_BUF (selected_frame
)
954 Fkill_emacs (make_number (-1));
958 Lisp_Object
command_loop_1 ();
959 Lisp_Object
command_loop_2 ();
960 Lisp_Object
top_level_1 ();
962 /* Entry to editor-command-loop.
963 This level has the catches for exiting/returning to editor command loop.
964 It returns nil to exit recursive edit, t to abort it. */
969 if (command_loop_level
> 0 || minibuf_level
> 0)
971 return internal_catch (Qexit
, command_loop_2
, Qnil
);
976 internal_catch (Qtop_level
, top_level_1
, Qnil
);
977 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
979 /* End of file in -batch run causes exit here. */
985 /* Here we catch errors in execution of commands within the
986 editing loop, and reenter the editing loop.
987 When there is an error, cmd_error runs and returns a non-nil
988 value to us. A value of nil means that cmd_loop_1 itself
989 returned due to end of file (or end of kbd macro). */
994 register Lisp_Object val
;
997 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
1006 return Feval (Vtop_level
);
1012 /* On entry to the outer level, run the startup file */
1013 if (!NILP (Vtop_level
))
1014 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
1015 else if (!NILP (Vpurify_flag
))
1016 message ("Bare impure Emacs (standard Lisp code not loaded)");
1018 message ("Bare Emacs (standard Lisp code not loaded)");
1022 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
1023 "Exit all recursive editing levels.")
1026 Fthrow (Qtop_level
, Qnil
);
1029 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
1030 "Exit from the innermost recursive edit or minibuffer.")
1033 if (command_loop_level
> 0 || minibuf_level
> 0)
1034 Fthrow (Qexit
, Qnil
);
1036 error ("No recursive edit is in progress");
1039 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
1040 "Abort the command that requested this recursive edit or minibuffer input.")
1043 if (command_loop_level
> 0 || minibuf_level
> 0)
1046 error ("No recursive edit is in progress");
1049 /* This is the actual command reading loop,
1050 sans error-handling encapsulation. */
1052 Lisp_Object
Fcommand_execute ();
1053 static int read_key_sequence ();
1054 static void safe_run_hooks ();
1059 Lisp_Object cmd
, tem
;
1062 Lisp_Object keybuf
[30];
1067 struct buffer
*prev_buffer
;
1069 int was_locked
= single_kboard
;
1072 current_kboard
->Vprefix_arg
= Qnil
;
1073 Vdeactivate_mark
= Qnil
;
1074 waiting_for_input
= 0;
1079 this_command_key_count
= 0;
1081 /* Make sure this hook runs after commands that get errors and
1082 throw to top level. */
1083 /* Note that the value cell will never directly contain nil
1084 if the symbol is a local variable. */
1085 if (!NILP (XSYMBOL (Qpost_command_hook
)->value
) && !NILP (Vrun_hooks
))
1086 safe_run_hooks (Qpost_command_hook
);
1088 if (!NILP (Vdeferred_action_list
))
1089 call0 (Vdeferred_action_function
);
1091 /* Do this after running Vpost_command_hook, for consistency. */
1092 current_kboard
->Vlast_command
= this_command
;
1096 /* Make sure the current window's buffer is selected. */
1097 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1098 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1100 /* Display any malloc warning that just came out. Use while because
1101 displaying one warning can cause another. */
1103 while (pending_malloc_warning
)
1104 display_malloc_warning ();
1108 Vdeactivate_mark
= Qnil
;
1110 /* If minibuffer on and echo area in use,
1111 wait 2 sec and redraw minibuffer. */
1113 if (minibuf_level
&& echo_area_glyphs
1114 && EQ (minibuf_window
, echo_area_window
))
1116 /* Bind inhibit-quit to t so that C-g gets read in
1117 rather than quitting back to the minibuffer. */
1118 int count
= specpdl_ptr
- specpdl
;
1119 specbind (Qinhibit_quit
, Qt
);
1120 Fsit_for (make_number (2), Qnil
, Qnil
);
1121 unbind_to (count
, Qnil
);
1123 echo_area_glyphs
= 0;
1125 if (!NILP (Vquit_flag
))
1128 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1133 alloca (0); /* Cause a garbage collection now */
1134 /* Since we can free the most stuff here. */
1135 #endif /* C_ALLOCA */
1139 /* Select the frame that the last event came from. Usually,
1140 switch-frame events will take care of this, but if some lisp
1141 code swallows a switch-frame event, we'll fix things up here.
1142 Is this a good idea? */
1143 if (FRAMEP (internal_last_event_frame
)
1144 && XFRAME (internal_last_event_frame
) != selected_frame
)
1145 Fselect_frame (internal_last_event_frame
, Qnil
);
1148 /* If it has changed current-menubar from previous value,
1149 really recompute the menubar from the value. */
1150 if (! NILP (Vlucid_menu_bar_dirty_flag
)
1151 && !NILP (Ffboundp (Qrecompute_lucid_menubar
)))
1152 call0 (Qrecompute_lucid_menubar
);
1154 before_command_key_count
= this_command_key_count
;
1155 before_command_echo_length
= echo_length ();
1157 /* Read next key sequence; i gets its length. */
1158 i
= read_key_sequence (keybuf
, sizeof keybuf
/ sizeof keybuf
[0],
1163 /* Now we have read a key sequence of length I,
1164 or else I is 0 and we found end of file. */
1166 if (i
== 0) /* End of file -- happens only in */
1167 return Qnil
; /* a kbd macro, at the end. */
1168 /* -1 means read_key_sequence got a menu that was rejected.
1169 Just loop around and read another command. */
1173 this_command_key_count
= 0;
1177 last_command_char
= keybuf
[i
- 1];
1179 /* If the previous command tried to force a specific window-start,
1180 forget about that, in case this command moves point far away
1181 from that position. But also throw away beg_unchanged and
1182 end_unchanged information in that case, so that redisplay will
1183 update the whole window properly. */
1184 if (!NILP (XWINDOW (selected_window
)->force_start
))
1186 XWINDOW (selected_window
)->force_start
= Qnil
;
1187 beg_unchanged
= end_unchanged
= 0;
1190 cmd
= read_key_sequence_cmd
;
1191 if (!NILP (Vexecuting_macro
))
1193 if (!NILP (Vquit_flag
))
1195 Vexecuting_macro
= Qt
;
1196 QUIT
; /* Make some noise. */
1197 /* Will return since macro now empty. */
1201 /* Do redisplay processing after this command except in special
1202 cases identified below that set no_redisplay to 1.
1203 (actually, there's currently no way to prevent the redisplay,
1204 and no_redisplay is ignored.
1205 Perhaps someday we will really implement it.) */
1208 prev_buffer
= current_buffer
;
1209 prev_modiff
= MODIFF
;
1210 last_point_position
= PT
;
1211 XSETBUFFER (last_point_position_buffer
, prev_buffer
);
1213 /* Execute the command. */
1216 /* Note that the value cell will never directly contain nil
1217 if the symbol is a local variable. */
1218 if (!NILP (XSYMBOL (Qpre_command_hook
)->value
) && !NILP (Vrun_hooks
))
1219 safe_run_hooks (Qpre_command_hook
);
1221 if (NILP (this_command
))
1223 /* nil means key is undefined. */
1225 current_kboard
->defining_kbd_macro
= Qnil
;
1226 update_mode_lines
= 1;
1227 current_kboard
->Vprefix_arg
= Qnil
;
1231 if (NILP (current_kboard
->Vprefix_arg
) && ! no_direct
)
1233 /* Recognize some common commands in common situations and
1234 do them directly. */
1235 if (EQ (this_command
, Qforward_char
) && PT
< ZV
)
1237 struct Lisp_Vector
*dp
1238 = window_display_table (XWINDOW (selected_window
));
1239 lose
= FETCH_CHAR (PT
);
1242 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1243 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1244 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1245 && (lose
>= 0x20 && lose
< 0x7f)))
1246 : (lose
>= 0x20 && lose
< 0x7f))
1247 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1249 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1251 && !windows_or_buffers_changed
1252 && EQ (current_buffer
->selective_display
, Qnil
)
1253 && !detect_input_pending ()
1254 && NILP (Vexecuting_macro
))
1255 no_redisplay
= direct_output_forward_char (1);
1258 else if (EQ (this_command
, Qbackward_char
) && PT
> BEGV
)
1260 struct Lisp_Vector
*dp
1261 = window_display_table (XWINDOW (selected_window
));
1263 lose
= FETCH_CHAR (PT
);
1265 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1266 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1267 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1268 && (lose
>= 0x20 && lose
< 0x7f)))
1269 : (lose
>= 0x20 && lose
< 0x7f))
1270 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1272 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1274 && !windows_or_buffers_changed
1275 && EQ (current_buffer
->selective_display
, Qnil
)
1276 && !detect_input_pending ()
1277 && NILP (Vexecuting_macro
))
1278 no_redisplay
= direct_output_forward_char (-1);
1281 else if (EQ (this_command
, Qself_insert_command
)
1282 /* Try this optimization only on ascii keystrokes. */
1283 && INTEGERP (last_command_char
))
1285 unsigned char c
= XINT (last_command_char
);
1288 if (NILP (Vexecuting_macro
)
1289 && !EQ (minibuf_window
, selected_window
))
1291 if (!nonundocount
|| nonundocount
>= 20)
1298 lose
= ((XFASTINT (XWINDOW (selected_window
)->last_modified
)
1300 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1302 || MODIFF
<= SAVE_MODIFF
1303 || windows_or_buffers_changed
1304 || !EQ (current_buffer
->selective_display
, Qnil
)
1305 || detect_input_pending ()
1306 || !NILP (Vexecuting_macro
));
1307 value
= internal_self_insert (c
, 0);
1314 && (PT
== ZV
|| FETCH_CHAR (PT
) == '\n'))
1316 struct Lisp_Vector
*dp
1317 = window_display_table (XWINDOW (selected_window
));
1324 obj
= DISP_CHAR_VECTOR (dp
, lose
);
1327 /* Do it only for char codes
1328 that by default display as themselves. */
1329 if (lose
>= 0x20 && lose
<= 0x7e)
1330 no_redisplay
= direct_output_for_insert (lose
);
1332 else if (VECTORP (obj
)
1333 && XVECTOR (obj
)->size
== 1
1334 && (obj
= XVECTOR (obj
)->contents
[0],
1336 /* Insist face not specified in glyph. */
1337 && (XINT (obj
) & ((-1) << 8)) == 0)
1339 = direct_output_for_insert (XINT (obj
));
1343 if (lose
>= 0x20 && lose
<= 0x7e)
1344 no_redisplay
= direct_output_for_insert (lose
);
1351 /* Here for a command that isn't executed directly */
1354 if (NILP (current_kboard
->Vprefix_arg
))
1356 Fcommand_execute (this_command
, Qnil
);
1361 /* Note that the value cell will never directly contain nil
1362 if the symbol is a local variable. */
1363 if (!NILP (XSYMBOL (Qpost_command_hook
)->value
) && !NILP (Vrun_hooks
))
1364 safe_run_hooks (Qpost_command_hook
);
1366 if (!NILP (Vdeferred_action_list
))
1367 safe_run_hooks (Qdeferred_action_function
);
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 if (this_command_key_count
== 0)
1664 if (unread_command_char
!= -1)
1666 XSETINT (c
, unread_command_char
);
1667 unread_command_char
= -1;
1669 if (this_command_key_count
== 0)
1675 /* If there is no function key translated before
1676 reset-this-command-lengths takes effect, forget about it. */
1677 before_command_restore_flag
= 0;
1679 if (!NILP (Vexecuting_macro
))
1682 /* We set this to Qmacro; since that's not a frame, nobody will
1683 try to switch frames on us, and the selected window will
1686 Since this event came from a macro, it would be misleading to
1687 leave internal_last_event_frame set to wherever the last
1688 real event came from. Normally, a switch-frame event selects
1689 internal_last_event_frame after each command is read, but
1690 events read from a macro should never cause a new frame to be
1692 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
1695 /* Exit the macro if we are at the end.
1696 Also, some things replace the macro with t
1697 to force an early exit. */
1698 if (EQ (Vexecuting_macro
, Qt
)
1699 || executing_macro_index
>= XFASTINT (Flength (Vexecuting_macro
)))
1705 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
1706 if (STRINGP (Vexecuting_macro
)
1707 && (XINT (c
) & 0x80))
1708 XSETFASTINT (c
, CHAR_META
| (XINT (c
) & ~0x80));
1710 executing_macro_index
++;
1715 if (!NILP (unread_switch_frame
))
1717 c
= unread_switch_frame
;
1718 unread_switch_frame
= Qnil
;
1720 /* This event should make it into this_command_keys, and get echoed
1721 again, so we go to reread_first, rather than reread. */
1725 if (commandflag
>= 0 && !input_pending
&& !detect_input_pending ())
1728 /* Message turns off echoing unless more keystrokes turn it on again. */
1729 if (echo_area_glyphs
&& *echo_area_glyphs
1730 && echo_area_glyphs
!= current_kboard
->echobuf
)
1733 /* If already echoing, continue. */
1736 /* Try reading a character via menu prompting in the minibuf.
1737 Try this before the sit-for, because the sit-for
1738 would do the wrong thing if we are supposed to do
1739 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
1740 after a mouse event so don't try a minibuf menu. */
1742 if (nmaps
> 0 && INTERACTIVE
1743 && !NILP (prev_event
) && ! EVENT_HAS_PARAMETERS (prev_event
)
1744 /* Don't bring up a menu if we already have another event. */
1745 && NILP (Vunread_command_events
)
1746 && unread_command_char
< 0
1747 && !detect_input_pending ())
1749 c
= read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
);
1752 key_already_recorded
= 1;
1757 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet.
1758 We will do that below, temporarily for short sections of code,
1759 when appropriate. local_getcjmp must be in effect
1760 around any call to sit_for or kbd_buffer_get_event;
1761 it *must not* be in effect when we call redisplay. */
1763 if (_setjmp (local_getcjmp
))
1765 XSETINT (c
, quit_char
);
1767 XSETFRAME (internal_last_event_frame
, selected_frame
);
1768 Vlast_event_frame
= internal_last_event_frame
;
1770 /* If we report the quit char as an event,
1771 don't do so more than once. */
1772 if (!NILP (Vinhibit_quit
))
1777 KBOARD
*kb
= FRAME_KBOARD (selected_frame
);
1778 if (kb
!= current_kboard
)
1780 Lisp_Object
*tailp
= &kb
->kbd_queue
;
1781 /* We shouldn't get here if we were in single-kboard mode! */
1784 while (CONSP (*tailp
))
1785 tailp
= &XCONS (*tailp
)->cdr
;
1788 *tailp
= Fcons (c
, Qnil
);
1789 kb
->kbd_queue_has_data
= 1;
1790 current_kboard
= kb
;
1791 longjmp (wrong_kboard_jmpbuf
, 1);
1798 /* If in middle of key sequence and minibuffer not active,
1799 start echoing if enough time elapses. */
1801 if (minibuf_level
== 0 && !current_kboard
->immediate_echo
1802 && this_command_key_count
> 0
1804 && echo_keystrokes
> 0
1805 && (echo_area_glyphs
== 0 || *echo_area_glyphs
== 0))
1809 /* After a mouse event, start echoing right away.
1810 This is because we are probably about to display a menu,
1811 and we don't want to delay before doing so. */
1812 if (EVENT_HAS_PARAMETERS (prev_event
))
1816 save_getcjmp (save_jump
);
1817 restore_getcjmp (local_getcjmp
);
1818 tem0
= sit_for (echo_keystrokes
, 0, 1, 1);
1819 restore_getcjmp (save_jump
);
1825 /* Maybe auto save due to number of keystrokes. */
1827 if (commandflag
!= 0
1828 && auto_save_interval
> 0
1829 && num_nonmacro_input_chars
- last_auto_save
> max (auto_save_interval
, 20)
1830 && !detect_input_pending ())
1832 Fdo_auto_save (Qnil
, Qnil
);
1833 /* Hooks can actually change some buffers in auto save. */
1837 /* Try reading using an X menu.
1838 This is never confused with reading using the minibuf
1839 because the recursive call of read_char in read_char_minibuf_menu_prompt
1840 does not pass on any keymaps. */
1842 if (nmaps
> 0 && INTERACTIVE
1843 && !NILP (prev_event
)
1844 && EVENT_HAS_PARAMETERS (prev_event
)
1845 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
)
1846 /* Don't bring up a menu if we already have another event. */
1847 && NILP (Vunread_command_events
)
1848 && unread_command_char
< 0)
1849 c
= read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
1851 /* Maybe autosave and/or garbage collect due to idleness. */
1853 if (INTERACTIVE
&& NILP (c
))
1855 int delay_level
, buffer_size
;
1857 /* Slow down auto saves logarithmically in size of current buffer,
1858 and garbage collect while we're at it. */
1859 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
1860 last_non_minibuf_size
= Z
- BEG
;
1861 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
1863 while (buffer_size
> 64)
1864 delay_level
++, buffer_size
-= buffer_size
>> 2;
1865 if (delay_level
< 4) delay_level
= 4;
1866 /* delay_level is 4 for files under around 50k, 7 at 100k,
1867 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
1869 /* Auto save if enough time goes by without input. */
1870 if (commandflag
!= 0
1871 && num_nonmacro_input_chars
> last_auto_save
1872 && INTEGERP (Vauto_save_timeout
)
1873 && XINT (Vauto_save_timeout
) > 0)
1876 int delay
= delay_level
* XFASTINT (Vauto_save_timeout
) / 4;
1878 save_getcjmp (save_jump
);
1879 restore_getcjmp (local_getcjmp
);
1880 tem0
= sit_for (delay
, 0, 1, 1);
1881 restore_getcjmp (save_jump
);
1885 Fdo_auto_save (Qnil
, Qnil
);
1887 /* If we have auto-saved and there is still no input
1888 available, garbage collect if there has been enough
1889 consing going on to make it worthwhile. */
1890 if (!detect_input_pending ()
1891 && consing_since_gc
> gc_cons_threshold
/ 2)
1892 Fgarbage_collect ();
1899 /* Read something from current KBOARD's side queue, if possible. */
1903 if (current_kboard
->kbd_queue_has_data
)
1905 if (!CONSP (current_kboard
->kbd_queue
))
1907 c
= XCONS (current_kboard
->kbd_queue
)->car
;
1908 current_kboard
->kbd_queue
1909 = XCONS (current_kboard
->kbd_queue
)->cdr
;
1910 if (NILP (current_kboard
->kbd_queue
))
1911 current_kboard
->kbd_queue_has_data
= 0;
1912 input_pending
= readable_events ();
1914 if (EVENT_HAS_PARAMETERS (c
)
1915 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qswitch_frame
))
1916 internal_last_event_frame
= XCONS (XCONS (c
)->cdr
)->car
;
1917 Vlast_event_frame
= internal_last_event_frame
;
1923 /* If current_kboard's side queue is empty check the other kboards.
1924 If one of them has data that we have not yet seen here,
1925 switch to it and process the data waiting for it.
1927 Note: if the events queued up for another kboard
1928 have already been seen here, and therefore are not a complete command,
1929 the kbd_queue_has_data field is 0, so we skip that kboard here.
1930 That's to avoid an infinite loop switching between kboards here. */
1931 if (NILP (c
) && !single_kboard
)
1934 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
1935 if (kb
->kbd_queue_has_data
)
1937 current_kboard
= kb
;
1938 longjmp (wrong_kboard_jmpbuf
, 1);
1947 /* Finally, we read from the main queue,
1948 and if that gives us something we can't use yet, we put it on the
1949 appropriate side queue and try again. */
1955 /* Actually read a character, waiting if necessary. */
1956 save_getcjmp (save_jump
);
1957 restore_getcjmp (local_getcjmp
);
1958 c
= kbd_buffer_get_event (&kb
, used_mouse_menu
);
1959 restore_getcjmp (save_jump
);
1962 if (! NILP (c
) && (kb
!= current_kboard
))
1964 Lisp_Object
*tailp
= &kb
->kbd_queue
;
1965 while (CONSP (*tailp
))
1966 tailp
= &XCONS (*tailp
)->cdr
;
1969 *tailp
= Fcons (c
, Qnil
);
1970 kb
->kbd_queue_has_data
= 1;
1974 current_kboard
= kb
;
1975 longjmp (wrong_kboard_jmpbuf
, 1);
1980 /* Terminate Emacs in batch mode if at eof. */
1981 if (noninteractive
&& INTEGERP (c
) && XINT (c
) < 0)
1982 Fkill_emacs (make_number (1));
1986 /* Add in any extra modifiers, where appropriate. */
1987 if ((extra_keyboard_modifiers
& CHAR_CTL
)
1988 || ((extra_keyboard_modifiers
& 0177) < ' '
1989 && (extra_keyboard_modifiers
& 0177) != 0))
1990 XSETINT (c
, make_ctrl_char (XINT (c
)));
1992 /* Transfer any other modifier bits directly from
1993 extra_keyboard_modifiers to c. Ignore the actual character code
1994 in the low 16 bits of extra_keyboard_modifiers. */
1995 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
2004 if (commandflag
>= 0
2005 && !input_pending
&& !detect_input_pending ())
2013 /* Buffer switch events are only for internal wakeups
2014 so don't show them to the user. */
2018 if (key_already_recorded
)
2021 /* Process special events within read_char
2022 and loop around to read another event. */
2025 tem
= get_keyelt (access_keymap (get_keymap_1 (Vspecial_event_map
, 0, 0),
2031 last_input_char
= c
;
2032 Fcommand_execute (tem
, Qnil
);
2036 /* Wipe the echo area. */
2037 echo_area_glyphs
= 0;
2039 /* Handle things that only apply to characters. */
2042 /* If kbd_buffer_get_event gave us an EOF, return that. */
2046 if (STRINGP (Vkeyboard_translate_table
)
2047 && XSTRING (Vkeyboard_translate_table
)->size
> XFASTINT (c
))
2048 XSETINT (c
, XSTRING (Vkeyboard_translate_table
)->data
[XFASTINT (c
)]);
2051 /* If this event is a mouse click in the menu bar,
2052 return just menu-bar for now. Modify the mouse click event
2053 so we won't do this twice, then queue it up. */
2054 if (EVENT_HAS_PARAMETERS (c
)
2055 && CONSP (XCONS (c
)->cdr
)
2056 && CONSP (EVENT_START (c
))
2057 && CONSP (XCONS (EVENT_START (c
))->cdr
))
2061 posn
= POSN_BUFFER_POSN (EVENT_START (c
));
2062 /* Handle menu-bar events:
2063 insert the dummy prefix event `menu-bar'. */
2064 if (EQ (posn
, Qmenu_bar
))
2066 /* Change menu-bar to (menu-bar) as the event "position". */
2067 POSN_BUFFER_POSN (EVENT_START (c
)) = Fcons (posn
, Qnil
);
2070 Vunread_command_events
= Fcons (c
, Vunread_command_events
);
2076 if (! NILP (also_record
))
2077 record_char (also_record
);
2081 before_command_key_count
= this_command_key_count
;
2082 before_command_echo_length
= echo_length ();
2084 /* Don't echo mouse motion events. */
2086 && ! (EVENT_HAS_PARAMETERS (c
)
2087 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
2090 if (! NILP (also_record
))
2091 echo_char (also_record
);
2094 /* Record this character as part of the current key. */
2095 add_command_key (c
);
2096 if (! NILP (also_record
))
2097 add_command_key (also_record
);
2099 /* Re-reading in the middle of a command */
2101 last_input_char
= c
;
2104 /* Process the help character specially if enabled */
2105 if (!NILP (Vhelp_form
) && help_char_p (c
))
2108 count
= specpdl_ptr
- specpdl
;
2110 record_unwind_protect (Fset_window_configuration
,
2111 Fcurrent_window_configuration (Qnil
));
2113 tem0
= Feval (Vhelp_form
);
2115 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
2119 c
= read_char (0, 0, 0, Qnil
, 0);
2120 while (BUFFERP (c
));
2121 /* Remove the help from the frame */
2122 unbind_to (count
, Qnil
);
2125 if (EQ (c
, make_number (040)))
2129 c
= read_char (0, 0, 0, Qnil
, 0);
2130 while (BUFFERP (c
));
2137 /* Return 1 if should recognize C as "the help character". */
2145 if (EQ (c
, Vhelp_char
))
2147 for (tail
= Vhelp_event_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
2148 if (EQ (c
, XCONS (tail
)->car
))
2153 /* Record the input event C in various ways. */
2160 XVECTOR (recent_keys
)->contents
[recent_keys_index
] = c
;
2161 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
2162 recent_keys_index
= 0;
2164 /* Write c to the dribble file. If c is a lispy event, write
2165 the event's symbol to the dribble file, in <brackets>. Bleaugh.
2166 If you, dear reader, have a better idea, you've got the source. :-) */
2171 if (XUINT (c
) < 0x100)
2172 putc (XINT (c
), dribble
);
2174 fprintf (dribble
, " 0x%x", (int) XUINT (c
));
2178 Lisp_Object dribblee
;
2180 /* If it's a structured event, take the event header. */
2181 dribblee
= EVENT_HEAD (c
);
2183 if (SYMBOLP (dribblee
))
2185 putc ('<', dribble
);
2186 fwrite (XSYMBOL (dribblee
)->name
->data
, sizeof (char),
2187 XSYMBOL (dribblee
)->name
->size
,
2189 putc ('>', dribble
);
2196 store_kbd_macro_char (c
);
2198 num_nonmacro_input_chars
++;
2205 struct buffer
*old
= current_buffer
;
2206 Fprinc (object
, Qnil
);
2207 set_buffer_internal (XBUFFER (Vstandard_output
));
2208 call0 (intern ("help-mode"));
2209 set_buffer_internal (old
);
2213 /* Copy out or in the info on where C-g should throw to.
2214 This is used when running Lisp code from within get_char,
2215 in case get_char is called recursively.
2216 See read_process_output. */
2221 bcopy (getcjmp
, temp
, sizeof getcjmp
);
2224 restore_getcjmp (temp
)
2227 bcopy (temp
, getcjmp
, sizeof getcjmp
);
2232 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
2233 of this function. */
2236 tracking_off (old_value
)
2237 Lisp_Object old_value
;
2239 do_mouse_tracking
= old_value
;
2240 if (NILP (old_value
))
2242 /* Redisplay may have been preempted because there was input
2243 available, and it assumes it will be called again after the
2244 input has been processed. If the only input available was
2245 the sort that we have just disabled, then we need to call
2247 if (!readable_events ())
2249 redisplay_preserve_echo_area ();
2250 get_input_pending (&input_pending
);
2255 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
2256 "Evaluate BODY with mouse movement events enabled.\n\
2257 Within a `track-mouse' form, mouse motion generates input events that\n\
2258 you can read with `read-event'.\n\
2259 Normally, mouse motion is ignored.")
2263 int count
= specpdl_ptr
- specpdl
;
2266 record_unwind_protect (tracking_off
, do_mouse_tracking
);
2268 do_mouse_tracking
= Qt
;
2270 val
= Fprogn (args
);
2271 return unbind_to (count
, val
);
2274 /* If mouse has moved on some frame, return one of those frames.
2275 Return 0 otherwise. */
2280 Lisp_Object tail
, frame
;
2282 FOR_EACH_FRAME (tail
, frame
)
2284 if (XFRAME (frame
)->mouse_moved
)
2285 return XFRAME (frame
);
2291 #endif /* HAVE_MOUSE */
2293 /* Low level keyboard/mouse input.
2294 kbd_buffer_store_event places events in kbd_buffer, and
2295 kbd_buffer_get_event retrieves them.
2296 mouse_moved indicates when the mouse has moved again, and
2297 *mouse_position_hook provides the mouse position. */
2299 /* Return true iff there are any events in the queue that read-char
2300 would return. If this returns false, a read-char would block. */
2304 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2307 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2312 if (current_kboard
->kbd_queue_has_data
)
2318 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2319 if (kb
->kbd_queue_has_data
)
2325 /* Set this for debugging, to have a way to get out */
2330 event_to_kboard (event
)
2331 struct input_event
*event
;
2334 frame
= event
->frame_or_window
;
2336 frame
= XCONS (frame
)->car
;
2337 else if (WINDOWP (frame
))
2338 frame
= WINDOW_FRAME (XWINDOW (frame
));
2340 /* There are still some events that don't set this field.
2341 For now, just ignore the problem.
2342 Also ignore dead frames here. */
2343 if (!FRAMEP (frame
) || !FRAME_LIVE_P (XFRAME (frame
)))
2346 return FRAME_KBOARD (XFRAME (frame
));
2350 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
2353 kbd_buffer_store_event (event
)
2354 register struct input_event
*event
;
2356 if (event
->kind
== no_event
)
2359 if (event
->kind
== ascii_keystroke
)
2361 register int c
= event
->code
& 0377;
2363 if (event
->modifiers
& ctrl_modifier
)
2364 c
= make_ctrl_char (c
);
2366 c
|= (event
->modifiers
2367 & (meta_modifier
| alt_modifier
2368 | hyper_modifier
| super_modifier
));
2372 extern SIGTYPE
interrupt_signal ();
2375 struct input_event
*sp
;
2378 && (kb
= FRAME_KBOARD (XFRAME (event
->frame_or_window
)),
2379 kb
!= current_kboard
))
2382 = Fcons (make_lispy_switch_frame (event
->frame_or_window
),
2383 Fcons (make_number (c
), Qnil
));
2384 kb
->kbd_queue_has_data
= 1;
2385 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
2387 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
2390 if (event_to_kboard (sp
) == kb
)
2392 sp
->kind
= no_event
;
2393 sp
->frame_or_window
= Qnil
;
2401 /* If this results in a quit_char being returned to Emacs as
2402 input, set Vlast_event_frame properly. If this doesn't
2403 get returned to Emacs as an event, the next event read
2404 will set Vlast_event_frame again, so this is safe to do. */
2408 focus
= FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
2410 focus
= event
->frame_or_window
;
2411 internal_last_event_frame
= focus
;
2412 Vlast_event_frame
= focus
;
2416 last_event_timestamp
= event
->timestamp
;
2417 interrupt_signal ();
2421 if (c
&& c
== stop_character
)
2428 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
2429 kbd_store_ptr
= kbd_buffer
;
2431 /* Don't let the very last slot in the buffer become full,
2432 since that would make the two pointers equal,
2433 and that is indistinguishable from an empty buffer.
2434 Discard the event if it would fill the last slot. */
2435 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
2437 volatile struct input_event
*sp
= kbd_store_ptr
;
2438 sp
->kind
= event
->kind
;
2439 if (event
->kind
== selection_request_event
)
2441 /* We must not use the ordinary copying code for this case,
2442 since `part' is an enum and copying it might not copy enough
2444 bcopy (event
, (char *) sp
, sizeof (*event
));
2448 sp
->code
= event
->code
;
2449 sp
->part
= event
->part
;
2450 sp
->frame_or_window
= event
->frame_or_window
;
2451 sp
->modifiers
= event
->modifiers
;
2454 sp
->timestamp
= event
->timestamp
;
2456 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_store_ptr
2458 = event
->frame_or_window
);
2464 /* Read one event from the event buffer, waiting if necessary.
2465 The value is a Lisp object representing the event.
2466 The value is nil for an event that should be ignored,
2467 or that was handled here.
2468 We always read and discard one event. */
2471 kbd_buffer_get_event (kbp
, used_mouse_menu
)
2473 int *used_mouse_menu
;
2482 *kbp
= current_kboard
;
2486 /* Wait until there is input available. */
2489 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2492 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2496 /* If the quit flag is set, then read_char will return
2497 quit_char, so that counts as "available input." */
2498 if (!NILP (Vquit_flag
))
2499 quit_throw_to_read_char ();
2501 /* One way or another, wait until input is available; then, if
2502 interrupt handlers have not read it, read it now. */
2505 wait_for_kbd_input ();
2507 /* Note SIGIO has been undef'd if FIONREAD is missing. */
2511 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2514 if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2518 Lisp_Object minus_one
;
2520 XSETINT (minus_one
, -1);
2521 wait_reading_process_input (0, 0, minus_one
, 1);
2523 if (!interrupt_input
&& kbd_fetch_ptr
== kbd_store_ptr
)
2524 /* Pass 1 for EXPECT since we just waited to have input. */
2525 read_avail_input (1);
2527 #endif /* not VMS */
2530 /* At this point, we know that there is a readable event available
2531 somewhere. If the event queue is empty, then there must be a
2532 mouse movement enabled and available. */
2533 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2535 struct input_event
*event
;
2537 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2541 last_event_timestamp
= event
->timestamp
;
2544 *kbp
= event_to_kboard (event
);
2546 *kbp
= current_kboard
; /* Better than returning null ptr? */
2548 *kbp
= &the_only_kboard
;
2553 /* These two kinds of events get special handling
2554 and don't actually appear to the command loop.
2555 We return nil for them. */
2556 if (event
->kind
== selection_request_event
)
2559 struct input_event copy
;
2561 /* Remove it from the buffer before processing it,
2562 since otherwise swallow_events will see it
2563 and process it again. */
2565 kbd_fetch_ptr
= event
+ 1;
2566 x_handle_selection_request (©
);
2568 /* We're getting selection request events, but we don't have
2574 else if (event
->kind
== selection_clear_event
)
2577 kbd_fetch_ptr
= event
+ 1;
2578 x_handle_selection_clear (event
);
2580 /* We're getting selection request events, but we don't have
2586 else if (event
->kind
== delete_window_event
)
2588 /* Make an event (delete-frame (FRAME)). */
2589 obj
= Fcons (event
->frame_or_window
, Qnil
);
2590 obj
= Fcons (Qdelete_frame
, Fcons (obj
, Qnil
));
2591 kbd_fetch_ptr
= event
+ 1;
2593 else if (event
->kind
== iconify_event
)
2595 /* Make an event (iconify-frame (FRAME)). */
2596 obj
= Fcons (event
->frame_or_window
, Qnil
);
2597 obj
= Fcons (Qiconify_frame
, Fcons (obj
, Qnil
));
2598 kbd_fetch_ptr
= event
+ 1;
2600 else if (event
->kind
== deiconify_event
)
2602 /* Make an event (make-frame-visible (FRAME)). */
2603 obj
= Fcons (event
->frame_or_window
, Qnil
);
2604 obj
= Fcons (Qmake_frame_visible
, Fcons (obj
, Qnil
));
2605 kbd_fetch_ptr
= event
+ 1;
2608 else if (event
->kind
== buffer_switch_event
)
2610 /* The value doesn't matter here; only the type is tested. */
2611 XSETBUFFER (obj
, current_buffer
);
2612 kbd_fetch_ptr
= event
+ 1;
2614 #ifdef USE_X_TOOLKIT
2615 else if (event
->kind
== menu_bar_activate_event
)
2617 kbd_fetch_ptr
= event
+ 1;
2618 x_activate_menubar (XFRAME (event
->frame_or_window
));
2621 /* Just discard these, by returning nil.
2622 With MULTI_KBOARD, these events are used as placeholders
2623 when we need to randomly delete events from the queue.
2624 (They shouldn't otherwise be found in the buffer,
2625 but on some machines it appears they do show up
2626 even without MULTI_KBOARD.) */
2627 else if (event
->kind
== no_event
)
2628 kbd_fetch_ptr
= event
+ 1;
2630 /* If this event is on a different frame, return a switch-frame this
2631 time, and leave the event in the queue for next time. */
2638 frame
= event
->frame_or_window
;
2640 frame
= XCONS (frame
)->car
;
2641 else if (WINDOWP (frame
))
2642 frame
= WINDOW_FRAME (XWINDOW (frame
));
2644 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
2648 if (! EQ (frame
, internal_last_event_frame
)
2649 && XFRAME (frame
) != selected_frame
)
2650 obj
= make_lispy_switch_frame (frame
);
2651 internal_last_event_frame
= frame
;
2652 #endif /* MULTI_FRAME */
2654 /* If we didn't decide to make a switch-frame event, go ahead
2655 and build a real event from the queue entry. */
2659 obj
= make_lispy_event (event
);
2660 #ifdef USE_X_TOOLKIT
2661 /* If this was a menu selection, then set the flag to inhibit
2662 writing to last_nonmenu_event. Don't do this if the event
2663 we're returning is (menu-bar), though; that indicates the
2664 beginning of the menu sequence, and we might as well leave
2665 that as the `event with parameters' for this selection. */
2666 if (event
->kind
== menu_bar_event
2667 && !(CONSP (obj
) && EQ (XCONS (obj
)->car
, Qmenu_bar
))
2669 *used_mouse_menu
= 1;
2672 /* Wipe out this event, to catch bugs. */
2673 event
->kind
= no_event
;
2674 XVECTOR (kbd_buffer_frame_or_window
)->contents
[event
- kbd_buffer
] = Qnil
;
2676 kbd_fetch_ptr
= event
+ 1;
2681 /* Try generating a mouse motion event. */
2682 else if (!NILP (do_mouse_tracking
) && some_mouse_moved ())
2684 FRAME_PTR f
= some_mouse_moved ();
2685 Lisp_Object bar_window
;
2686 enum scroll_bar_part part
;
2690 *kbp
= current_kboard
;
2691 /* Note that this uses F to determine which display to look at.
2692 If there is no valid info, it does not store anything
2693 so x remains nil. */
2695 (*mouse_position_hook
) (&f
, 0, &bar_window
, &part
, &x
, &y
, &time
);
2700 /* Decide if we should generate a switch-frame event. Don't
2701 generate switch-frame events for motion outside of all Emacs
2707 frame
= FRAME_FOCUS_FRAME (f
);
2709 XSETFRAME (frame
, f
);
2711 if (! EQ (frame
, internal_last_event_frame
)
2712 && XFRAME (frame
) != selected_frame
)
2713 obj
= make_lispy_switch_frame (frame
);
2714 internal_last_event_frame
= frame
;
2718 /* If we didn't decide to make a switch-frame event, go ahead and
2719 return a mouse-motion event. */
2720 if (!NILP (x
) && NILP (obj
))
2721 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
2723 #endif /* HAVE_MOUSE */
2725 /* We were promised by the above while loop that there was
2726 something for us to read! */
2729 input_pending
= readable_events ();
2732 Vlast_event_frame
= internal_last_event_frame
;
2738 /* Process any events that are not user-visible,
2739 then return, without reading any user-visible events. */
2744 while (kbd_fetch_ptr
!= kbd_store_ptr
)
2746 struct input_event
*event
;
2748 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2752 last_event_timestamp
= event
->timestamp
;
2754 /* These two kinds of events get special handling
2755 and don't actually appear to the command loop. */
2756 if (event
->kind
== selection_request_event
)
2759 struct input_event copy
;
2761 kbd_fetch_ptr
= event
+ 1;
2762 x_handle_selection_request (©
);
2764 /* We're getting selection request events, but we don't have
2770 else if (event
->kind
== selection_clear_event
)
2773 x_handle_selection_clear (event
);
2774 kbd_fetch_ptr
= event
+ 1;
2776 /* We're getting selection request events, but we don't have
2785 get_input_pending (&input_pending
);
2788 /* Caches for modify_event_symbol. */
2789 static Lisp_Object accent_key_syms
;
2790 static Lisp_Object func_key_syms
;
2791 static Lisp_Object mouse_syms
;
2793 /* This is a list of keysym codes for special "accent" characters.
2794 It parallels lispy_accent_keys. */
2796 static int lispy_accent_codes
[] =
2798 #ifdef XK_dead_circumflex
2803 #ifdef XK_dead_grave
2808 #ifdef XK_dead_tilde
2813 #ifdef XK_dead_diaeresis
2818 #ifdef XK_dead_macron
2823 #ifdef XK_dead_degree
2828 #ifdef XK_dead_acute
2833 #ifdef XK_dead_cedilla
2838 #ifdef XK_dead_breve
2843 #ifdef XK_dead_ogonek
2848 #ifdef XK_dead_caron
2853 #ifdef XK_dead_doubleacute
2854 XK_dead_doubleacute
,
2858 #ifdef XK_dead_abovedot
2865 /* This is a list of Lisp names for special "accent" characters.
2866 It parallels lispy_accent_codes. */
2868 static char *lispy_accent_keys
[] =
2885 /* You'll notice that this table is arranged to be conveniently
2886 indexed by X Windows keysym values. */
2887 static char *lispy_function_keys
[] =
2889 /* X Keysym value */
2891 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00 */
2899 0, 0, 0, /* 0xff10 */
2901 0, 0, 0, 0, 0, 0, 0,
2904 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff20...2f */
2905 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff30...3f */
2906 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
2908 "home", /* 0xff50 */ /* IsCursorKey */
2919 "select", /* 0xff60 */ /* IsMiscFunctionKey */
2930 "break", /* 0xff6b */
2932 0, 0, 0, 0, 0, 0, 0, 0, "backtab", 0,
2934 0, 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff7f */
2935 "kp-space", /* 0xff80 */ /* IsKeypadKey */
2936 0, 0, 0, 0, 0, 0, 0, 0,
2937 "kp-tab", /* 0xff89 */
2939 "kp-enter", /* 0xff8d */
2941 "kp-f1", /* 0xff91 */
2945 "kp-home", /* 0xff95 */
2950 "kp-prior", /* kp-page-up */
2951 "kp-next", /* kp-page-down */
2957 0, 0, 0, 0, 0, 0, 0, 0, 0,
2958 "kp-multiply", /* 0xffaa */
2963 "kp-divide", /* 0xffaf */
2964 "kp-0", /* 0xffb0 */
2965 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
2968 "kp-equal", /* 0xffbd */
2969 "f1", /* 0xffbe */ /* IsFunctionKey */
2971 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
2972 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
2973 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
2974 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
2975 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
2976 0, 0, 0, 0, 0, 0, 0, 0,
2977 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
2978 0, 0, 0, 0, 0, 0, 0, "delete"
2981 static char *lispy_mouse_names
[] =
2983 "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5"
2986 /* Scroll bar parts. */
2987 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
2989 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
2990 Lisp_Object
*scroll_bar_parts
[] = {
2991 &Qabove_handle
, &Qhandle
, &Qbelow_handle
2995 /* A vector, indexed by button number, giving the down-going location
2996 of currently depressed buttons, both scroll bar and non-scroll bar.
2998 The elements have the form
2999 (BUTTON-NUMBER MODIFIER-MASK . REST)
3000 where REST is the cdr of a position as it would be reported in the event.
3002 The make_lispy_event function stores positions here to tell the
3003 difference between click and drag events, and to store the starting
3004 location to be included in drag events. */
3006 static Lisp_Object button_down_location
;
3008 /* Information about the most recent up-going button event: Which
3009 button, what location, and what time. */
3011 static int last_mouse_button
;
3012 static int last_mouse_x
;
3013 static int last_mouse_y
;
3014 static unsigned long button_down_time
;
3016 /* The maximum time between clicks to make a double-click,
3017 or Qnil to disable double-click detection,
3018 or Qt for no time limit. */
3019 Lisp_Object Vdouble_click_time
;
3021 /* The number of clicks in this multiple-click. */
3023 int double_click_count
;
3025 /* Given a struct input_event, build the lisp event which represents
3026 it. If EVENT is 0, build a mouse movement event from the mouse
3027 movement buffer, which should have a movement event in it.
3029 Note that events must be passed to this function in the order they
3030 are received; this function stores the location of button presses
3031 in order to build drag events when the button is released. */
3034 make_lispy_event (event
)
3035 struct input_event
*event
;
3039 switch (SWITCH_ENUM_CAST (event
->kind
))
3041 /* A simple keystroke. */
3042 case ascii_keystroke
:
3044 Lisp_Object lispy_c
;
3045 int c
= event
->code
& 0377;
3046 /* Turn ASCII characters into control characters
3048 if (event
->modifiers
& ctrl_modifier
)
3049 c
= make_ctrl_char (c
);
3051 /* Add in the other modifier bits. We took care of ctrl_modifier
3052 just above, and the shift key was taken care of by the X code,
3053 and applied to control characters by make_ctrl_char. */
3054 c
|= (event
->modifiers
3055 & (meta_modifier
| alt_modifier
3056 | hyper_modifier
| super_modifier
));
3057 button_down_time
= 0;
3058 XSETFASTINT (lispy_c
, c
);
3062 /* A function key. The symbol may need to have modifier prefixes
3064 case non_ascii_keystroke
:
3065 button_down_time
= 0;
3067 for (i
= 0; i
< sizeof (lispy_accent_codes
) / sizeof (int); i
++)
3068 if (event
->code
== lispy_accent_codes
[i
])
3069 return modify_event_symbol (i
,
3071 Qfunction_key
, Qnil
,
3072 lispy_accent_keys
, &accent_key_syms
,
3073 (sizeof (lispy_accent_keys
)
3074 / sizeof (lispy_accent_keys
[0])));
3076 /* Handle system-specific keysyms. */
3077 if (event
->code
& (1 << 28))
3079 /* We need to use an alist rather than a vector as the cache
3080 since we can't make a vector long enuf. */
3081 if (NILP (current_kboard
->system_key_syms
))
3082 current_kboard
->system_key_syms
= Fcons (Qnil
, Qnil
);
3083 return modify_event_symbol (event
->code
,
3086 current_kboard
->Vsystem_key_alist
,
3087 0, ¤t_kboard
->system_key_syms
,
3091 return modify_event_symbol (event
->code
- 0xff00,
3093 Qfunction_key
, Qnil
,
3094 lispy_function_keys
, &func_key_syms
,
3095 (sizeof (lispy_function_keys
)
3096 / sizeof (lispy_function_keys
[0])));
3100 /* A mouse click. Figure out where it is, decide whether it's
3101 a press, click or drag, and build the appropriate structure. */
3103 case scroll_bar_click
:
3105 int button
= event
->code
;
3107 Lisp_Object position
;
3108 Lisp_Object
*start_pos_ptr
;
3109 Lisp_Object start_pos
;
3111 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
3114 /* Build the position as appropriate for this mouse click. */
3115 if (event
->kind
== mouse_click
)
3118 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
3123 /* Ignore mouse events that were made on frame that
3124 have been deleted. */
3125 if (! FRAME_LIVE_P (f
))
3128 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
3129 &column
, &row
, NULL
, 1);
3131 #ifndef USE_X_TOOLKIT
3132 /* In the non-toolkit version, clicks on the menu bar
3133 are ordinary button events in the event buffer.
3134 Distinguish them, and invoke the menu.
3136 (In the toolkit version, the toolkit handles the menu bar
3137 and Emacs doesn't know about it until after the user
3138 makes a selection.) */
3139 if (row
>= 0 && row
< FRAME_MENU_BAR_LINES (f
))
3141 Lisp_Object items
, item
;
3145 /* Activate the menu bar on the down event. If the
3146 up event comes in before the menu code can deal with it,
3148 if (! (event
->modifiers
& down_modifier
))
3152 items
= FRAME_MENU_BAR_ITEMS (f
);
3153 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 3)
3155 Lisp_Object pos
, string
;
3156 string
= XVECTOR (items
)->contents
[i
+ 1];
3157 pos
= XVECTOR (items
)->contents
[i
+ 2];
3160 if (column
>= XINT (pos
)
3161 && column
< XINT (pos
) + XSTRING (string
)->size
)
3163 item
= XVECTOR (items
)->contents
[i
];
3169 = Fcons (event
->frame_or_window
,
3171 Fcons (Fcons (event
->x
, event
->y
),
3172 Fcons (make_number (event
->timestamp
),
3175 return Fcons (item
, Fcons (position
, Qnil
));
3177 #endif /* not USE_X_TOOLKIT */
3179 window
= window_from_coordinates (f
, column
, row
, &part
);
3181 if (!WINDOWP (window
))
3183 window
= event
->frame_or_window
;
3188 int pixcolumn
, pixrow
;
3189 column
-= XINT (XWINDOW (window
)->left
);
3190 row
-= XINT (XWINDOW (window
)->top
);
3191 glyph_to_pixel_coords (f
, column
, row
, &pixcolumn
, &pixrow
);
3192 XSETINT (event
->x
, pixcolumn
);
3193 XSETINT (event
->y
, pixrow
);
3198 posn
= Qvertical_line
;
3201 buffer_posn_from_coords (XWINDOW (window
),
3208 Fcons (Fcons (event
->x
, event
->y
),
3209 Fcons (make_number (event
->timestamp
),
3215 Lisp_Object portion_whole
;
3218 window
= event
->frame_or_window
;
3219 portion_whole
= Fcons (event
->x
, event
->y
);
3220 part
= *scroll_bar_parts
[(int) event
->part
];
3224 Fcons (Qvertical_scroll_bar
,
3225 Fcons (portion_whole
,
3226 Fcons (make_number (event
->timestamp
),
3227 Fcons (part
, Qnil
)))));
3230 start_pos_ptr
= &XVECTOR (button_down_location
)->contents
[button
];
3232 start_pos
= *start_pos_ptr
;
3233 *start_pos_ptr
= Qnil
;
3235 is_double
= (button
== last_mouse_button
3236 && XINT (event
->x
) == last_mouse_x
3237 && XINT (event
->y
) == last_mouse_y
3238 && button_down_time
!= 0
3239 && (EQ (Vdouble_click_time
, Qt
)
3240 || (INTEGERP (Vdouble_click_time
)
3241 && ((int)(event
->timestamp
- button_down_time
)
3242 < XINT (Vdouble_click_time
)))));
3243 last_mouse_button
= button
;
3244 last_mouse_x
= XINT (event
->x
);
3245 last_mouse_y
= XINT (event
->y
);
3247 /* If this is a button press, squirrel away the location, so
3248 we can decide later whether it was a click or a drag. */
3249 if (event
->modifiers
& down_modifier
)
3253 double_click_count
++;
3254 event
->modifiers
|= ((double_click_count
> 2)
3259 double_click_count
= 1;
3260 button_down_time
= event
->timestamp
;
3261 *start_pos_ptr
= Fcopy_alist (position
);
3264 /* Now we're releasing a button - check the co-ordinates to
3265 see if this was a click or a drag. */
3266 else if (event
->modifiers
& up_modifier
)
3268 /* If we did not see a down before this up,
3269 ignore the up. Probably this happened because
3270 the down event chose a menu item.
3271 It would be an annoyance to treat the release
3272 of the button that chose the menu item
3273 as a separate event. */
3275 if (!CONSP (start_pos
))
3278 event
->modifiers
&= ~up_modifier
;
3279 #if 0 /* Formerly we treated an up with no down as a click event. */
3280 if (!CONSP (start_pos
))
3281 event
->modifiers
|= click_modifier
;
3285 /* The third element of every position should be the (x,y)
3289 down
= Fnth (make_number (2), start_pos
);
3290 if (EQ (event
->x
, XCONS (down
)->car
)
3291 && EQ (event
->y
, XCONS (down
)->cdr
))
3293 event
->modifiers
|= click_modifier
;
3297 button_down_time
= 0;
3298 event
->modifiers
|= drag_modifier
;
3300 /* Don't check is_double; treat this as multiple
3301 if the down-event was multiple. */
3302 if (double_click_count
> 1)
3303 event
->modifiers
|= ((double_click_count
> 2)
3309 /* Every mouse event should either have the down_modifier or
3310 the up_modifier set. */
3314 /* Get the symbol we should use for the mouse click. */
3317 head
= modify_event_symbol (button
,
3320 lispy_mouse_names
, &mouse_syms
,
3321 (sizeof (lispy_mouse_names
)
3322 / sizeof (lispy_mouse_names
[0])));
3323 if (event
->modifiers
& drag_modifier
)
3328 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
3331 Fcons (make_number (double_click_count
),
3339 #endif /* HAVE_MOUSE */
3341 #ifdef USE_X_TOOLKIT
3342 case menu_bar_event
:
3343 /* The event value is in the cdr of the frame_or_window slot. */
3344 if (!CONSP (event
->frame_or_window
))
3346 return XCONS (event
->frame_or_window
)->cdr
;
3349 /* The 'kind' field of the event is something we don't recognize. */
3358 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
3360 Lisp_Object bar_window
;
3361 enum scroll_bar_part part
;
3366 /* Is it a scroll bar movement? */
3367 if (frame
&& ! NILP (bar_window
))
3369 Lisp_Object part_sym
;
3371 part_sym
= *scroll_bar_parts
[(int) part
];
3372 return Fcons (Qscroll_bar_movement
,
3373 (Fcons (Fcons (bar_window
,
3374 Fcons (Qvertical_scroll_bar
,
3375 Fcons (Fcons (x
, y
),
3376 Fcons (make_number (time
),
3382 /* Or is it an ordinary mouse movement? */
3384 #endif /* MULTI_FRAME */
3397 /* It's in a frame; which window on that frame? */
3398 pixel_to_glyph_coords (frame
, XINT (x
), XINT (y
), &column
, &row
,
3400 window
= window_from_coordinates (frame
, column
, row
, &area
);
3405 if (WINDOWP (window
))
3407 int pixcolumn
, pixrow
;
3408 column
-= XINT (XWINDOW (window
)->left
);
3409 row
-= XINT (XWINDOW (window
)->top
);
3410 glyph_to_pixel_coords (frame
, column
, row
, &pixcolumn
, &pixrow
);
3411 XSETINT (x
, pixcolumn
);
3412 XSETINT (y
, pixrow
);
3417 posn
= Qvertical_line
;
3420 buffer_posn_from_coords (XWINDOW (window
), column
, row
));
3423 else if (frame
!= 0)
3425 XSETFRAME (window
, frame
);
3437 return Fcons (Qmouse_movement
,
3438 Fcons (Fcons (window
,
3440 Fcons (Fcons (x
, y
),
3441 Fcons (make_number (time
),
3447 #endif /* HAVE_MOUSE */
3449 /* Construct a switch frame event. */
3451 make_lispy_switch_frame (frame
)
3454 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
3457 /* Manipulating modifiers. */
3459 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
3461 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
3462 SYMBOL's name of the end of the modifiers; the string from this
3463 position is the unmodified symbol name.
3465 This doesn't use any caches. */
3468 parse_modifiers_uncached (symbol
, modifier_end
)
3472 struct Lisp_String
*name
;
3476 CHECK_SYMBOL (symbol
, 1);
3479 name
= XSYMBOL (symbol
)->name
;
3481 for (i
= 0; i
+2 <= name
->size
; )
3483 int this_mod_end
= 0;
3486 /* See if the name continues with a modifier word.
3487 Check that the word appears, but don't check what follows it.
3488 Set this_mod and this_mod_end to record what we find. */
3490 switch (name
->data
[i
])
3492 #define SINGLE_LETTER_MOD(BIT) \
3493 (this_mod_end = i + 1, this_mod = BIT)
3496 SINGLE_LETTER_MOD (alt_modifier
);
3500 SINGLE_LETTER_MOD (ctrl_modifier
);
3504 SINGLE_LETTER_MOD (hyper_modifier
);
3508 SINGLE_LETTER_MOD (meta_modifier
);
3512 SINGLE_LETTER_MOD (shift_modifier
);
3516 SINGLE_LETTER_MOD (super_modifier
);
3519 #undef SINGLE_LETTER_MOD
3522 /* If we found no modifier, stop looking for them. */
3523 if (this_mod_end
== 0)
3526 /* Check there is a dash after the modifier, so that it
3527 really is a modifier. */
3528 if (this_mod_end
>= name
->size
|| name
->data
[this_mod_end
] != '-')
3531 /* This modifier is real; look for another. */
3532 modifiers
|= this_mod
;
3533 i
= this_mod_end
+ 1;
3536 /* Should we include the `click' modifier? */
3537 if (! (modifiers
& (down_modifier
| drag_modifier
3538 | double_modifier
| triple_modifier
))
3539 && i
+ 7 == name
->size
3540 && strncmp (name
->data
+ i
, "mouse-", 6) == 0
3541 && ('0' <= name
->data
[i
+ 6] && name
->data
[i
+ 6] <= '9'))
3542 modifiers
|= click_modifier
;
3550 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
3551 prepended to the string BASE[0..BASE_LEN-1].
3552 This doesn't use any caches. */
3554 apply_modifiers_uncached (modifiers
, base
, base_len
)
3559 /* Since BASE could contain nulls, we can't use intern here; we have
3560 to use Fintern, which expects a genuine Lisp_String, and keeps a
3563 (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
3569 /* Only the event queue may use the `up' modifier; it should always
3570 be turned into a click or drag event before presented to lisp code. */
3571 if (modifiers
& up_modifier
)
3574 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
3575 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
3576 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
3577 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
3578 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
3579 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
3580 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
3581 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
3582 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
3583 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
3584 /* The click modifier is denoted by the absence of other modifiers. */
3588 mod_len
= p
- new_mods
;
3592 Lisp_Object new_name
;
3594 new_name
= make_uninit_string (mod_len
+ base_len
);
3595 bcopy (new_mods
, XSTRING (new_name
)->data
, mod_len
);
3596 bcopy (base
, XSTRING (new_name
)->data
+ mod_len
, base_len
);
3598 return Fintern (new_name
, Qnil
);
3603 static char *modifier_names
[] =
3605 "up", "down", "drag", "click", "double", "triple", 0, 0,
3606 0, 0, 0, 0, 0, 0, 0, 0,
3607 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
3609 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
3611 static Lisp_Object modifier_symbols
;
3613 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
3615 lispy_modifier_list (modifiers
)
3618 Lisp_Object modifier_list
;
3621 modifier_list
= Qnil
;
3622 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
3623 if (modifiers
& (1<<i
))
3624 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
3627 return modifier_list
;
3631 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
3632 where UNMODIFIED is the unmodified form of SYMBOL,
3633 MASK is the set of modifiers present in SYMBOL's name.
3634 This is similar to parse_modifiers_uncached, but uses the cache in
3635 SYMBOL's Qevent_symbol_element_mask property, and maintains the
3636 Qevent_symbol_elements property. */
3639 parse_modifiers (symbol
)
3642 Lisp_Object elements
;
3644 elements
= Fget (symbol
, Qevent_symbol_element_mask
);
3645 if (CONSP (elements
))
3650 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
3651 Lisp_Object unmodified
;
3654 unmodified
= Fintern (make_string (XSYMBOL (symbol
)->name
->data
+ end
,
3655 XSYMBOL (symbol
)->name
->size
- end
),
3658 if (modifiers
& ~(((EMACS_INT
)1 << VALBITS
) - 1))
3660 XSETFASTINT (mask
, modifiers
);
3661 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
3663 /* Cache the parsing results on SYMBOL. */
3664 Fput (symbol
, Qevent_symbol_element_mask
,
3666 Fput (symbol
, Qevent_symbol_elements
,
3667 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
3669 /* Since we know that SYMBOL is modifiers applied to unmodified,
3670 it would be nice to put that in unmodified's cache.
3671 But we can't, since we're not sure that parse_modifiers is
3678 /* Apply the modifiers MODIFIERS to the symbol BASE.
3679 BASE must be unmodified.
3681 This is like apply_modifiers_uncached, but uses BASE's
3682 Qmodifier_cache property, if present. It also builds
3683 Qevent_symbol_elements properties, since it has that info anyway.
3685 apply_modifiers copies the value of BASE's Qevent_kind property to
3686 the modified symbol. */
3688 apply_modifiers (modifiers
, base
)
3692 Lisp_Object cache
, index
, entry
, new_symbol
;
3694 /* Mask out upper bits. We don't know where this value's been. */
3695 modifiers
&= ((EMACS_INT
)1 << VALBITS
) - 1;
3697 /* The click modifier never figures into cache indices. */
3698 cache
= Fget (base
, Qmodifier_cache
);
3699 XSETFASTINT (index
, (modifiers
& ~click_modifier
));
3700 entry
= assq_no_quit (index
, cache
);
3703 new_symbol
= XCONS (entry
)->cdr
;
3706 /* We have to create the symbol ourselves. */
3707 new_symbol
= apply_modifiers_uncached (modifiers
,
3708 XSYMBOL (base
)->name
->data
,
3709 XSYMBOL (base
)->name
->size
);
3711 /* Add the new symbol to the base's cache. */
3712 entry
= Fcons (index
, new_symbol
);
3713 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
3715 /* We have the parsing info now for free, so add it to the caches. */
3716 XSETFASTINT (index
, modifiers
);
3717 Fput (new_symbol
, Qevent_symbol_element_mask
,
3718 Fcons (base
, Fcons (index
, Qnil
)));
3719 Fput (new_symbol
, Qevent_symbol_elements
,
3720 Fcons (base
, lispy_modifier_list (modifiers
)));
3723 /* Make sure this symbol is of the same kind as BASE.
3725 You'd think we could just set this once and for all when we
3726 intern the symbol above, but reorder_modifiers may call us when
3727 BASE's property isn't set right; we can't assume that just
3728 because it has a Qmodifier_cache property it must have its
3729 Qevent_kind set right as well. */
3730 if (NILP (Fget (new_symbol
, Qevent_kind
)))
3734 kind
= Fget (base
, Qevent_kind
);
3736 Fput (new_symbol
, Qevent_kind
, kind
);
3743 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
3744 return a symbol with the modifiers placed in the canonical order.
3745 Canonical order is alphabetical, except for down and drag, which
3746 always come last. The 'click' modifier is never written out.
3748 Fdefine_key calls this to make sure that (for example) C-M-foo
3749 and M-C-foo end up being equivalent in the keymap. */
3752 reorder_modifiers (symbol
)
3755 /* It's hopefully okay to write the code this way, since everything
3756 will soon be in caches, and no consing will be done at all. */
3759 parsed
= parse_modifiers (symbol
);
3760 return apply_modifiers ((int) XINT (XCONS (XCONS (parsed
)->cdr
)->car
),
3761 XCONS (parsed
)->car
);
3765 /* For handling events, we often want to produce a symbol whose name
3766 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
3767 to some base, like the name of a function key or mouse button.
3768 modify_event_symbol produces symbols of this sort.
3770 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
3771 is the name of the i'th symbol. TABLE_SIZE is the number of elements
3774 Alternatively, NAME_ALIST is an alist mapping codes into symbol names.
3775 NAME_ALIST is used if it is non-nil; otherwise NAME_TABLE is used.
3777 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
3778 persist between calls to modify_event_symbol that it can use to
3779 store a cache of the symbols it's generated for this NAME_TABLE
3780 before. The object stored there may be a vector or an alist.
3782 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
3784 MODIFIERS is a set of modifier bits (as given in struct input_events)
3785 whose prefixes should be applied to the symbol name.
3787 SYMBOL_KIND is the value to be placed in the event_kind property of
3788 the returned symbol.
3790 The symbols we create are supposed to have an
3791 `event-symbol-elements' property, which lists the modifiers present
3792 in the symbol's name. */
3795 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_alist
,
3796 name_table
, symbol_table
, table_size
)
3799 Lisp_Object symbol_kind
;
3800 Lisp_Object name_alist
;
3802 Lisp_Object
*symbol_table
;
3803 unsigned int table_size
;
3806 Lisp_Object symbol_int
;
3808 /* Get rid of the "vendor-specific" bit here. */
3809 XSETINT (symbol_int
, symbol_num
& 0xffffff);
3811 /* Is this a request for a valid symbol? */
3812 if (symbol_num
< 0 || symbol_num
>= table_size
)
3815 if (CONSP (*symbol_table
))
3816 value
= Fcdr (assq_no_quit (symbol_int
, *symbol_table
));
3818 /* If *symbol_table doesn't seem to be initialized properly, fix that.
3819 *symbol_table should be a lisp vector TABLE_SIZE elements long,
3820 where the Nth element is the symbol for NAME_TABLE[N], or nil if
3821 we've never used that symbol before. */
3824 if (! VECTORP (*symbol_table
)
3825 || XVECTOR (*symbol_table
)->size
!= table_size
)
3829 XSETFASTINT (size
, table_size
);
3830 *symbol_table
= Fmake_vector (size
, Qnil
);
3833 value
= XVECTOR (*symbol_table
)->contents
[symbol_num
];
3836 /* Have we already used this symbol before? */
3839 /* No; let's create it. */
3840 if (!NILP (name_alist
))
3841 value
= Fcdr_safe (Fassq (symbol_int
, name_alist
));
3842 else if (name_table
[symbol_num
])
3843 value
= intern (name_table
[symbol_num
]);
3845 #ifdef HAVE_X_WINDOWS
3848 char *name
= x_get_keysym_name (symbol_num
);
3850 value
= intern (name
);
3857 sprintf (buf
, "key-%d", symbol_num
);
3858 value
= intern (buf
);
3861 if (CONSP (*symbol_table
))
3862 *symbol_table
= Fcons (value
, *symbol_table
);
3864 XVECTOR (*symbol_table
)->contents
[symbol_num
] = value
;
3866 /* Fill in the cache entries for this symbol; this also
3867 builds the Qevent_symbol_elements property, which the user
3869 apply_modifiers (modifiers
& click_modifier
, value
);
3870 Fput (value
, Qevent_kind
, symbol_kind
);
3873 /* Apply modifiers to that symbol. */
3874 return apply_modifiers (modifiers
, value
);
3877 /* Convert a list that represents an event type,
3878 such as (ctrl meta backspace), into the usual representation of that
3879 event type as a number or a symbol. */
3881 DEFUN ("event-convert-list", Fevent_convert_list
, Sevent_convert_list
, 1, 1, 0,
3882 "Convert the event description LIST to an event type.\n\
3883 LIST should contain one base event type (a character or symbol)\n\
3884 and zero or more modifier names (control, meta, hyper, super, shift, alt,\n\
3885 drag, down, double or triple).\n\
3886 The return value is an event type (a character or symbol) which\n\
3887 has the same base event type and all the specified modifiers.")
3897 while (CONSP (rest
))
3902 elt
= XCONS (rest
)->car
;
3904 /* Given a symbol, see if it is a modifier name. */
3906 this = parse_solitary_modifier (elt
);
3910 else if (!NILP (base
))
3911 error ("Two bases given in one event");
3915 rest
= XCONS (rest
)->cdr
;
3918 /* Let the symbol A refer to the character A. */
3919 if (SYMBOLP (base
) && XSYMBOL (base
)->name
->size
== 1)
3920 XSETINT (base
, XSYMBOL (base
)->name
->data
[0]);
3922 if (INTEGERP (base
))
3924 /* Turn (shift a) into A. */
3925 if ((modifiers
& shift_modifier
) != 0
3926 && (XINT (base
) >= 'a' && XINT (base
) <= 'z'))
3928 XSETINT (base
, XINT (base
) - ('a' - 'A'));
3929 modifiers
&= ~shift_modifier
;
3932 /* Turn (control a) into C-a. */
3933 if (modifiers
& ctrl_modifier
)
3934 return make_number ((modifiers
& ~ctrl_modifier
)
3935 | make_ctrl_char (XINT (base
)));
3937 return make_number (modifiers
| XINT (base
));
3939 else if (SYMBOLP (base
))
3940 return apply_modifiers (modifiers
, base
);
3942 error ("Invalid base event");
3945 /* Try to recognize SYMBOL as a modifier name.
3946 Return the modifier flag bit, or 0 if not recognized. */
3949 parse_solitary_modifier (symbol
)
3952 struct Lisp_String
*name
= XSYMBOL (symbol
)->name
;
3954 switch (name
->data
[0])
3956 #define SINGLE_LETTER_MOD(BIT) \
3957 if (name->size == 1) \
3960 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
3961 if (LEN == name->size \
3962 && ! strncmp (name->data, NAME, LEN)) \
3966 SINGLE_LETTER_MOD (alt_modifier
);
3970 MULTI_LETTER_MOD (alt_modifier
, "alt", 3);
3974 SINGLE_LETTER_MOD (ctrl_modifier
);
3978 MULTI_LETTER_MOD (ctrl_modifier
, "ctrl", 4);
3979 MULTI_LETTER_MOD (ctrl_modifier
, "control", 7);
3983 SINGLE_LETTER_MOD (hyper_modifier
);
3987 MULTI_LETTER_MOD (hyper_modifier
, "hyper", 5);
3991 SINGLE_LETTER_MOD (meta_modifier
);
3995 MULTI_LETTER_MOD (meta_modifier
, "meta", 4);
3999 SINGLE_LETTER_MOD (shift_modifier
);
4003 MULTI_LETTER_MOD (shift_modifier
, "shift", 5);
4004 MULTI_LETTER_MOD (super_modifier
, "super", 5);
4005 SINGLE_LETTER_MOD (super_modifier
);
4009 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
4010 MULTI_LETTER_MOD (down_modifier
, "down", 4);
4011 MULTI_LETTER_MOD (double_modifier
, "double", 6);
4015 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
4018 #undef SINGLE_LETTER_MOD
4019 #undef MULTI_LETTER_MOD
4025 /* Return 1 if EVENT is a list whose elements are all integers or symbols.
4026 Such a list is not valid as an event,
4027 but it can be a Lucid-style event type list. */
4030 lucid_event_type_list_p (object
)
4035 if (! CONSP (object
))
4038 for (tail
= object
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4041 elt
= XCONS (tail
)->car
;
4042 if (! (INTEGERP (elt
) || SYMBOLP (elt
)))
4049 /* Store into *addr a value nonzero if terminal input chars are available.
4050 Serves the purpose of ioctl (0, FIONREAD, addr)
4051 but works even if FIONREAD does not exist.
4052 (In fact, this may actually read some input.) */
4055 get_input_pending (addr
)
4058 /* First of all, have we already counted some input? */
4059 *addr
= !NILP (Vquit_flag
) || readable_events ();
4061 /* If input is being read as it arrives, and we have none, there is none. */
4062 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
4065 /* Try to read some input and see how much we get. */
4067 *addr
= !NILP (Vquit_flag
) || readable_events ();
4070 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
4073 gobble_input (expected
)
4078 if (interrupt_input
)
4081 mask
= sigblockx (SIGIO
);
4082 read_avail_input (expected
);
4086 #ifdef POLL_FOR_INPUT
4087 if (read_socket_hook
&& !interrupt_input
&& poll_suppress_count
== 0)
4090 mask
= sigblockx (SIGALRM
);
4091 read_avail_input (expected
);
4097 read_avail_input (expected
);
4101 /* Put a buffer_switch_event in the buffer
4102 so that read_key_sequence will notice the new current buffer. */
4104 record_asynch_buffer_change ()
4106 struct input_event event
;
4109 event
.kind
= buffer_switch_event
;
4110 event
.frame_or_window
= Qnil
;
4113 /* We don't need a buffer-switch event unless Emacs is waiting for input.
4114 The purpose of the event is to make read_key_sequence look up the
4115 keymaps again. If we aren't in read_key_sequence, we don't need one,
4116 and the event could cause trouble by messing up (input-pending-p). */
4117 tem
= Fwaiting_for_user_input_p ();
4121 /* We never need these events if we have no asynchronous subprocesses. */
4125 /* Make sure no interrupt happens while storing the event. */
4127 if (interrupt_input
)
4130 mask
= sigblockx (SIGIO
);
4131 kbd_buffer_store_event (&event
);
4138 kbd_buffer_store_event (&event
);
4145 /* Read any terminal input already buffered up by the system
4146 into the kbd_buffer, but do not wait.
4148 EXPECTED should be nonzero if the caller knows there is some input.
4150 Except on VMS, all input is read by this function.
4151 If interrupt_input is nonzero, this function MUST be called
4152 only when SIGIO is blocked.
4154 Returns the number of keyboard chars read, or -1 meaning
4155 this is a bad time to try to read input. */
4158 read_avail_input (expected
)
4161 struct input_event buf
[KBD_BUFFER_SIZE
];
4165 if (read_socket_hook
)
4166 /* No need for FIONREAD or fcntl; just say don't wait. */
4167 nread
= (*read_socket_hook
) (input_fd
, buf
, KBD_BUFFER_SIZE
,
4168 expected
, expected
);
4171 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
4172 the kbd_buffer can really hold. That may prevent loss
4173 of characters on some systems when input is stuffed at us. */
4174 unsigned char cbuf
[KBD_BUFFER_SIZE
- 1];
4177 /* Determine how many characters we should *try* to read. */
4180 #else /* not WINDOWSNT */
4182 n_to_read
= dos_keysns ();
4185 #else /* not MSDOS */
4187 /* Find out how much input is available. */
4188 if (ioctl (input_fd
, FIONREAD
, &n_to_read
) < 0)
4189 /* Formerly simply reported no input, but that sometimes led to
4190 a failure of Emacs to terminate.
4191 SIGHUP seems appropriate if we can't reach the terminal. */
4192 /* ??? Is it really right to send the signal just to this process
4193 rather than to the whole process group?
4194 Perhaps on systems with FIONREAD Emacs is alone in its group. */
4195 kill (getpid (), SIGHUP
);
4198 if (n_to_read
> sizeof cbuf
)
4199 n_to_read
= sizeof cbuf
;
4200 #else /* no FIONREAD */
4201 #if defined(USG) || defined(DGUX)
4202 /* Read some input if available, but don't wait. */
4203 n_to_read
= sizeof cbuf
;
4204 fcntl (input_fd
, F_SETFL
, O_NDELAY
);
4209 #endif /* not MSDOS */
4210 #endif /* not WINDOWSNT */
4212 /* Now read; for one reason or another, this will not block.
4213 NREAD is set to the number of chars read. */
4217 cbuf
[0] = dos_keyread();
4220 nread
= read (input_fd
, cbuf
, n_to_read
);
4222 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
4223 /* The kernel sometimes fails to deliver SIGHUP for ptys.
4224 This looks incorrect, but it isn't, because _BSD causes
4225 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
4226 and that causes a value other than 0 when there is no input. */
4232 /* We used to retry the read if it was interrupted.
4233 But this does the wrong thing when O_NDELAY causes
4234 an EAGAIN error. Does anybody know of a situation
4235 where a retry is actually needed? */
4237 nread
< 0 && (errno
== EAGAIN
4251 #if defined (USG) || defined (DGUX)
4252 fcntl (input_fd
, F_SETFL
, 0);
4253 #endif /* USG or DGUX */
4254 #endif /* no FIONREAD */
4255 for (i
= 0; i
< nread
; i
++)
4257 buf
[i
].kind
= ascii_keystroke
;
4258 buf
[i
].modifiers
= 0;
4259 if (meta_key
== 1 && (cbuf
[i
] & 0x80))
4260 buf
[i
].modifiers
= meta_modifier
;
4264 buf
[i
].code
= cbuf
[i
];
4266 XSETFRAME (buf
[i
].frame_or_window
, selected_frame
);
4268 buf
[i
].frame_or_window
= Qnil
;
4273 /* Scan the chars for C-g and store them in kbd_buffer. */
4274 for (i
= 0; i
< nread
; i
++)
4276 kbd_buffer_store_event (&buf
[i
]);
4277 /* Don't look at input that follows a C-g too closely.
4278 This reduces lossage due to autorepeat on C-g. */
4279 if (buf
[i
].kind
== ascii_keystroke
4280 && buf
[i
].code
== quit_char
)
4286 #endif /* not VMS */
4288 #ifdef SIGIO /* for entire page */
4289 /* Note SIGIO has been undef'd if FIONREAD is missing. */
4292 input_available_signal (signo
)
4295 /* Must preserve main program's value of errno. */
4296 int old_errno
= errno
;
4298 extern int select_alarmed
;
4302 /* USG systems forget handlers when they are used;
4303 must reestablish each time */
4304 signal (signo
, input_available_signal
);
4311 if (input_available_clear_time
)
4312 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
4317 nread
= read_avail_input (1);
4318 /* -1 means it's not ok to read the input now.
4319 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
4320 0 means there was no keyboard input available. */
4325 select_alarmed
= 1; /* Force the select emulator back to life */
4336 /* Send ourselves a SIGIO.
4338 This function exists so that the UNBLOCK_INPUT macro in
4339 blockinput.h can have some way to take care of input we put off
4340 dealing with, without assuming that every file which uses
4341 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
4343 reinvoke_input_signal ()
4352 /* Return the prompt-string of a sparse keymap.
4353 This is the first element which is a string.
4354 Return nil if there is none. */
4362 register Lisp_Object tem
;
4371 static void menu_bar_item ();
4372 static void menu_bar_one_keymap ();
4374 /* These variables hold the vector under construction within
4375 menu_bar_items and its subroutines, and the current index
4376 for storing into that vector. */
4377 static Lisp_Object menu_bar_items_vector
;
4378 static int menu_bar_items_index
;
4380 /* Return a vector of menu items for a menu bar, appropriate
4381 to the current buffer. Each item has three elements in the vector:
4384 OLD is an old vector we can optionally reuse, or nil. */
4387 menu_bar_items (old
)
4390 /* The number of keymaps we're scanning right now, and the number of
4391 keymaps we have allocated space for. */
4394 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
4395 in the current keymaps, or nil where it is not a prefix. */
4398 Lisp_Object def
, tem
, tail
;
4407 struct gcpro gcpro1
;
4409 /* In order to build the menus, we need to call the keymap
4410 accessors. They all call QUIT. But this function is called
4411 during redisplay, during which a quit is fatal. So inhibit
4412 quitting while building the menus.
4413 We do this instead of specbind because (1) errors will clear it anyway
4414 and (2) this avoids risk of specpdl overflow. */
4415 oquit
= Vinhibit_quit
;
4419 menu_bar_items_vector
= old
;
4421 menu_bar_items_vector
= Fmake_vector (make_number (24), Qnil
);
4422 menu_bar_items_index
= 0;
4424 GCPRO1 (menu_bar_items_vector
);
4426 /* Build our list of keymaps.
4427 If we recognize a function key and replace its escape sequence in
4428 keybuf with its symbol, or if the sequence starts with a mouse
4429 click and we need to switch buffers, we jump back here to rebuild
4430 the initial keymaps from the current buffer. */
4434 /* Should overriding-terminal-local-map and overriding-local-map apply? */
4435 if (!NILP (Voverriding_local_map_menu_flag
))
4437 /* Yes, use them (if non-nil) as well as the global map. */
4438 maps
= (Lisp_Object
*) alloca (3 * sizeof (maps
[0]));
4440 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
4441 maps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
4442 if (!NILP (Voverriding_local_map
))
4443 maps
[nmaps
++] = Voverriding_local_map
;
4447 /* No, so use major and minor mode keymaps. */
4448 nmaps
= current_minor_maps (NULL
, &tmaps
);
4449 maps
= (Lisp_Object
*) alloca ((nmaps
+ 2) * sizeof (maps
[0]));
4450 bcopy (tmaps
, maps
, nmaps
* sizeof (maps
[0]));
4451 #ifdef USE_TEXT_PROPERTIES
4452 maps
[nmaps
++] = get_local_map (PT
, current_buffer
);
4454 maps
[nmaps
++] = current_buffer
->keymap
;
4457 maps
[nmaps
++] = current_global_map
;
4460 /* Look up in each map the dummy prefix key `menu-bar'. */
4464 for (mapno
= nmaps
- 1; mapno
>= 0; mapno
--)
4466 if (! NILP (maps
[mapno
]))
4467 def
= get_keyelt (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0));
4471 tem
= Fkeymapp (def
);
4473 menu_bar_one_keymap (def
);
4476 /* Move to the end those items that should be at the end. */
4478 for (tail
= Vmenu_bar_final_items
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4481 int end
= menu_bar_items_index
;
4483 for (i
= 0; i
< end
; i
+= 3)
4484 if (EQ (XCONS (tail
)->car
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
4486 Lisp_Object tem0
, tem1
, tem2
;
4487 /* Move the item at index I to the end,
4488 shifting all the others forward. */
4489 tem0
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 0];
4490 tem1
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 1];
4491 tem2
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
4493 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3],
4494 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
4495 (end
- i
- 3) * sizeof (Lisp_Object
));
4496 XVECTOR (menu_bar_items_vector
)->contents
[end
- 3] = tem0
;
4497 XVECTOR (menu_bar_items_vector
)->contents
[end
- 2] = tem1
;
4498 XVECTOR (menu_bar_items_vector
)->contents
[end
- 1] = tem2
;
4503 /* Add nil, nil, nil at the end. */
4504 i
= menu_bar_items_index
;
4505 if (i
+ 3 > XVECTOR (menu_bar_items_vector
)->size
)
4508 int newsize
= 2 * i
;
4509 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
4510 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
4511 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
4512 menu_bar_items_vector
= tem
;
4514 /* Add this item. */
4515 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
4516 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
4517 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
4518 menu_bar_items_index
= i
;
4520 Vinhibit_quit
= oquit
;
4522 return menu_bar_items_vector
;
4525 /* Scan one map KEYMAP, accumulating any menu items it defines
4526 in menu_bar_items_vector. */
4529 menu_bar_one_keymap (keymap
)
4532 Lisp_Object tail
, item
, key
, binding
, item_string
, table
;
4534 /* Loop over all keymap entries that have menu strings. */
4535 for (tail
= keymap
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4537 item
= XCONS (tail
)->car
;
4540 key
= XCONS (item
)->car
;
4541 binding
= XCONS (item
)->cdr
;
4542 if (CONSP (binding
))
4544 item_string
= XCONS (binding
)->car
;
4545 if (STRINGP (item_string
))
4546 menu_bar_item (key
, item_string
, Fcdr (binding
));
4548 else if (EQ (binding
, Qundefined
))
4549 menu_bar_item (key
, Qnil
, binding
);
4551 else if (VECTORP (item
))
4553 /* Loop over the char values represented in the vector. */
4554 int len
= XVECTOR (item
)->size
;
4556 for (c
= 0; c
< len
; c
++)
4558 Lisp_Object character
;
4559 XSETFASTINT (character
, c
);
4560 binding
= XVECTOR (item
)->contents
[c
];
4561 if (CONSP (binding
))
4563 item_string
= XCONS (binding
)->car
;
4564 if (STRINGP (item_string
))
4565 menu_bar_item (key
, item_string
, Fcdr (binding
));
4567 else if (EQ (binding
, Qundefined
))
4568 menu_bar_item (key
, Qnil
, binding
);
4574 /* This is used as the handler when calling internal_condition_case_1. */
4577 menu_bar_item_1 (arg
)
4583 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
4584 If there's already an item for KEY, add this DEF to it. */
4587 menu_bar_item (key
, item_string
, def
)
4588 Lisp_Object key
, item_string
, def
;
4591 Lisp_Object enabled
;
4594 if (EQ (def
, Qundefined
))
4596 /* If a map has an explicit `undefined' as definition,
4597 discard any previously made menu bar item. */
4599 for (i
= 0; i
< menu_bar_items_index
; i
+= 3)
4600 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
4602 if (menu_bar_items_index
> i
+ 3)
4603 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3],
4604 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
4605 (menu_bar_items_index
- i
- 3) * sizeof (Lisp_Object
));
4606 menu_bar_items_index
-= 3;
4610 /* If there's no definition for this key yet,
4611 just ignore `undefined'. */
4615 /* See if this entry is enabled. */
4620 /* No property, or nil, means enable.
4621 Otherwise, enable if value is not nil. */
4622 tem
= Fget (def
, Qmenu_enable
);
4624 /* (condition-case nil (eval tem)
4626 enabled
= internal_condition_case_1 (Feval
, tem
, Qerror
,
4630 /* Ignore this item if it's not enabled. */
4634 /* Find any existing item for this KEY. */
4635 for (i
= 0; i
< menu_bar_items_index
; i
+= 3)
4636 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
4639 /* If we did not find this KEY, add it at the end. */
4640 if (i
== menu_bar_items_index
)
4642 /* If vector is too small, get a bigger one. */
4643 if (i
+ 3 > XVECTOR (menu_bar_items_vector
)->size
)
4646 int newsize
= 2 * i
;
4647 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
4648 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
4649 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
4650 menu_bar_items_vector
= tem
;
4652 /* Add this item. */
4653 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = key
;
4654 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = item_string
;
4655 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Fcons (def
, Qnil
);
4656 menu_bar_items_index
= i
;
4658 /* We did find an item for this KEY. Add DEF to its list of maps. */
4662 old
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
4663 XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2] = Fcons (def
, old
);
4667 /* Read a character using menus based on maps in the array MAPS.
4668 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
4669 Return t if we displayed a menu but the user rejected it.
4671 PREV_EVENT is the previous input event, or nil if we are reading
4672 the first event of a key sequence.
4674 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
4675 if we used a mouse menu to read the input, or zero otherwise. If
4676 USED_MOUSE_MENU is null, we don't dereference it.
4678 The prompting is done based on the prompt-string of the map
4679 and the strings associated with various map elements.
4681 This can be done with X menus or with menus put in the minibuf.
4682 These are done in different ways, depending on how the input will be read.
4683 Menus using X are done after auto-saving in read-char, getting the input
4684 event from Fx_popup_menu; menus using the minibuf use read_char recursively
4685 and do auto-saving in the inner call of read_char. */
4688 read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
4691 Lisp_Object prev_event
;
4692 int *used_mouse_menu
;
4695 register Lisp_Object name
;
4696 Lisp_Object rest
, vector
;
4698 if (used_mouse_menu
)
4699 *used_mouse_menu
= 0;
4701 /* Use local over global Menu maps */
4703 if (! menu_prompting
)
4706 /* Optionally disregard all but the global map. */
4707 if (inhibit_local_menu_bar_menus
)
4709 maps
+= (nmaps
- 1);
4713 /* Get the menu name from the first map that has one (a prompt string). */
4714 for (mapno
= 0; mapno
< nmaps
; mapno
++)
4716 name
= map_prompt (maps
[mapno
]);
4721 /* If we don't have any menus, just read a character normally. */
4725 #if (defined (HAVE_X_WINDOWS) && defined (HAVE_X_MENU)) || defined (MSDOS)
4726 /* If we got to this point via a mouse click,
4727 use a real menu for mouse selection. */
4728 if (EVENT_HAS_PARAMETERS (prev_event
)
4729 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
))
4731 /* Display the menu and get the selection. */
4732 Lisp_Object
*realmaps
4733 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
4737 /* Use the maps that are not nil. */
4738 for (mapno
= 0; mapno
< nmaps
; mapno
++)
4739 if (!NILP (maps
[mapno
]))
4740 realmaps
[nmaps1
++] = maps
[mapno
];
4742 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
4745 /* If we got more than one event, put all but the first
4746 onto this list to be read later.
4747 Return just the first event now. */
4748 Vunread_command_events
4749 = nconc2 (XCONS (value
)->cdr
, Vunread_command_events
);
4750 value
= XCONS (value
)->car
;
4752 else if (NILP (value
))
4754 if (used_mouse_menu
)
4755 *used_mouse_menu
= 1;
4758 #endif /* (HAVE_X_WINDOWS && HAVE_X_MENU) || MSDOS */
4763 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
4769 register Lisp_Object name
;
4771 int width
= FRAME_WIDTH (selected_frame
) - 4;
4772 char *menu
= (char *) alloca (width
+ 4);
4775 Lisp_Object rest
, vector
;
4777 if (! menu_prompting
)
4780 /* Get the menu name from the first map that has one (a prompt string). */
4781 for (mapno
= 0; mapno
< nmaps
; mapno
++)
4783 name
= map_prompt (maps
[mapno
]);
4788 /* If we don't have any menus, just read a character normally. */
4792 /* Prompt string always starts with map's prompt, and a space. */
4793 strcpy (menu
, XSTRING (name
)->data
);
4794 nlength
= XSTRING (name
)->size
;
4795 menu
[nlength
++] = ':';
4796 menu
[nlength
++] = ' ';
4799 /* Start prompting at start of first map. */
4803 /* Present the documented bindings, a line at a time. */
4810 Lisp_Object orig_defn_macro
;
4812 /* Loop over elements of map. */
4817 /* If reached end of map, start at beginning of next map. */
4821 /* At end of last map, wrap around to first map if just starting,
4822 or end this line if already have something on it. */
4826 if (notfirst
|| nobindings
) break;
4831 /* Look at the next element of the map. */
4833 elt
= XVECTOR (vector
)->contents
[idx
];
4835 elt
= Fcar_safe (rest
);
4837 if (idx
< 0 && VECTORP (elt
))
4839 /* If we found a dense table in the keymap,
4840 advanced past it, but start scanning its contents. */
4841 rest
= Fcdr_safe (rest
);
4847 /* An ordinary element. */
4852 s
= Fcar_safe (Fcdr_safe (elt
)); /* alist */
4853 event
= Fcar_safe (elt
);
4857 s
= Fcar_safe (elt
); /* vector */
4858 XSETINT (event
, idx
);
4861 /* Ignore the element if it has no prompt string. */
4862 if (STRINGP (s
) && INTEGERP (event
))
4864 /* 1 if the char to type matches the string. */
4866 Lisp_Object upcased_event
, downcased_event
;
4869 upcased_event
= Fupcase (event
);
4870 downcased_event
= Fdowncase (event
);
4871 char_matches
= (XINT (upcased_event
) == XSTRING (s
)->data
[0]
4872 || XINT (downcased_event
) == XSTRING (s
)->data
[0]);
4874 desc
= Fsingle_key_description (event
);
4876 /* If we have room for the prompt string, add it to this line.
4877 If this is the first on the line, always add it. */
4878 if ((XSTRING (s
)->size
+ i
+ 2
4879 + (char_matches
? 0 : XSTRING (desc
)->size
+ 3))
4885 /* Punctuate between strings. */
4888 strcpy (menu
+ i
, ", ");
4894 /* If the char to type doesn't match the string's
4895 first char, explicitly show what char to type. */
4898 /* Add as much of string as fits. */
4899 thiswidth
= XSTRING (desc
)->size
;
4900 if (thiswidth
+ i
> width
)
4901 thiswidth
= width
- i
;
4902 bcopy (XSTRING (desc
)->data
, menu
+ i
, thiswidth
);
4904 strcpy (menu
+ i
, " = ");
4908 /* Add as much of string as fits. */
4909 thiswidth
= XSTRING (s
)->size
;
4910 if (thiswidth
+ i
> width
)
4911 thiswidth
= width
- i
;
4912 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
4918 /* If this element does not fit, end the line now,
4919 and save the element for the next line. */
4920 strcpy (menu
+ i
, "...");
4925 /* Move past this element. */
4926 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
4927 /* Handle reaching end of dense table. */
4932 rest
= Fcdr_safe (rest
);
4936 /* Prompt with that and read response. */
4939 /* Make believe its not a keyboard macro in case the help char
4940 is pressed. Help characters are not recorded because menu prompting
4941 is not used on replay.
4943 orig_defn_macro
= current_kboard
->defining_kbd_macro
;
4944 current_kboard
->defining_kbd_macro
= Qnil
;
4946 obj
= read_char (commandflag
, 0, 0, Qnil
, 0);
4947 while (BUFFERP (obj
));
4948 current_kboard
->defining_kbd_macro
= orig_defn_macro
;
4950 if (!INTEGERP (obj
))
4955 if (! EQ (obj
, menu_prompt_more_char
)
4956 && (!INTEGERP (menu_prompt_more_char
)
4957 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
4959 if (!NILP (current_kboard
->defining_kbd_macro
))
4960 store_kbd_macro_char (obj
);
4963 /* Help char - go round again */
4967 /* Reading key sequences. */
4969 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
4970 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
4971 keymap, or nil otherwise. Return the index of the first keymap in
4972 which KEY has any binding, or NMAPS if no map has a binding.
4974 If KEY is a meta ASCII character, treat it like meta-prefix-char
4975 followed by the corresponding non-meta character. Keymaps in
4976 CURRENT with non-prefix bindings for meta-prefix-char become nil in
4979 If KEY has no bindings in any of the CURRENT maps, NEXT is left
4982 NEXT may == CURRENT. */
4985 follow_key (key
, nmaps
, current
, defs
, next
)
4987 Lisp_Object
*current
, *defs
, *next
;
4990 int i
, first_binding
;
4992 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
4993 followed by the corresponding non-meta character. */
4994 if (INTEGERP (key
) && (XINT (key
) & CHAR_META
))
4996 for (i
= 0; i
< nmaps
; i
++)
4997 if (! NILP (current
[i
]))
5000 get_keyelt (access_keymap (current
[i
], meta_prefix_char
, 1, 0));
5002 /* Note that since we pass the resulting bindings through
5003 get_keymap_1, non-prefix bindings for meta-prefix-char
5005 next
[i
] = get_keymap_1 (next
[i
], 0, 1);
5011 XSETINT (key
, XFASTINT (key
) & ~CHAR_META
);
5014 first_binding
= nmaps
;
5015 for (i
= nmaps
- 1; i
>= 0; i
--)
5017 if (! NILP (current
[i
]))
5019 defs
[i
] = get_keyelt (access_keymap (current
[i
], key
, 1, 0));
5020 if (! NILP (defs
[i
]))
5027 /* Given the set of bindings we've found, produce the next set of maps. */
5028 if (first_binding
< nmaps
)
5029 for (i
= 0; i
< nmaps
; i
++)
5030 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0, 1);
5032 return first_binding
;
5035 /* Read a sequence of keys that ends with a non prefix character,
5036 storing it in KEYBUF, a buffer of size BUFSIZE.
5038 Return the length of the key sequence stored.
5039 Return -1 if the user rejected a command menu.
5041 Echo starting immediately unless `prompt' is 0.
5043 Where a key sequence ends depends on the currently active keymaps.
5044 These include any minor mode keymaps active in the current buffer,
5045 the current buffer's local map, and the global map.
5047 If a key sequence has no other bindings, we check Vfunction_key_map
5048 to see if some trailing subsequence might be the beginning of a
5049 function key's sequence. If so, we try to read the whole function
5050 key, and substitute its symbolic name into the key sequence.
5052 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
5053 `double-' events into similar click events, if that would make them
5054 bound. We try to turn `triple-' events first into `double-' events,
5057 If we get a mouse click in a mode line, vertical divider, or other
5058 non-text area, we treat the click as if it were prefixed by the
5059 symbol denoting that area - `mode-line', `vertical-line', or
5062 If the sequence starts with a mouse click, we read the key sequence
5063 with respect to the buffer clicked on, not the current buffer.
5065 If the user switches frames in the midst of a key sequence, we put
5066 off the switch-frame event until later; the next call to
5067 read_char will return it. */
5070 read_key_sequence (keybuf
, bufsize
, prompt
, dont_downcase_last
,
5071 can_return_switch_frame
)
5072 Lisp_Object
*keybuf
;
5075 int dont_downcase_last
;
5076 int can_return_switch_frame
;
5078 int count
= specpdl_ptr
- specpdl
;
5080 /* How many keys there are in the current key sequence. */
5083 /* The length of the echo buffer when we started reading, and
5084 the length of this_command_keys when we started reading. */
5088 /* The number of keymaps we're scanning right now, and the number of
5089 keymaps we have allocated space for. */
5091 int nmaps_allocated
= 0;
5093 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
5094 the current keymaps. */
5097 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
5098 in the current keymaps, or nil where it is not a prefix. */
5099 Lisp_Object
*submaps
;
5101 /* The local map to start out with at start of key sequence. */
5102 Lisp_Object orig_local_map
;
5104 /* 1 if we have already considered switching to the local-map property
5105 of the place where a mouse click occurred. */
5106 int localized_local_map
= 0;
5108 /* The index in defs[] of the first keymap that has a binding for
5109 this key sequence. In other words, the lowest i such that
5110 defs[i] is non-nil. */
5113 /* If t < mock_input, then KEYBUF[t] should be read as the next
5116 We use this to recover after recognizing a function key. Once we
5117 realize that a suffix of the current key sequence is actually a
5118 function key's escape sequence, we replace the suffix with the
5119 function key's binding from Vfunction_key_map. Now keybuf
5120 contains a new and different key sequence, so the echo area,
5121 this_command_keys, and the submaps and defs arrays are wrong. In
5122 this situation, we set mock_input to t, set t to 0, and jump to
5123 restart_sequence; the loop will read keys from keybuf up until
5124 mock_input, thus rebuilding the state; and then it will resume
5125 reading characters from the keyboard. */
5128 /* If the sequence is unbound in submaps[], then
5129 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
5130 and fkey_map is its binding.
5132 These might be > t, indicating that all function key scanning
5133 should hold off until t reaches them. We do this when we've just
5134 recognized a function key, to avoid searching for the function
5135 key's again in Vfunction_key_map. */
5136 int fkey_start
= 0, fkey_end
= 0;
5137 Lisp_Object fkey_map
;
5139 /* Likewise, for key_translation_map. */
5140 int keytran_start
= 0, keytran_end
= 0;
5141 Lisp_Object keytran_map
;
5143 /* If we receive a ``switch-frame'' event in the middle of a key sequence,
5144 we put it off for later. While we're reading, we keep the event here. */
5145 Lisp_Object delayed_switch_frame
;
5147 /* See the comment below... */
5148 #if defined (GOBBLE_FIRST_EVENT)
5149 Lisp_Object first_event
;
5152 Lisp_Object original_uppercase
;
5153 int original_uppercase_position
= -1;
5155 /* Gets around Microsoft compiler limitations. */
5158 struct buffer
*starting_buffer
;
5160 /* Nonzero if we seem to have got the beginning of a binding
5161 in function_key_map. */
5162 int function_key_possible
= 0;
5163 int key_translation_possible
= 0;
5167 last_nonmenu_event
= Qnil
;
5169 delayed_switch_frame
= Qnil
;
5170 fkey_map
= Vfunction_key_map
;
5171 keytran_map
= Vkey_translation_map
;
5173 /* If there is no function-key-map, turn off function key scanning. */
5174 if (NILP (Fkeymapp (Vfunction_key_map
)))
5175 fkey_start
= fkey_end
= bufsize
+ 1;
5177 /* If there is no key-translation-map, turn off scanning. */
5178 if (NILP (Fkeymapp (Vkey_translation_map
)))
5179 keytran_start
= keytran_end
= bufsize
+ 1;
5184 echo_prompt (XSTRING (prompt
)->data
);
5185 else if (cursor_in_echo_area
&& echo_keystrokes
)
5186 /* This doesn't put in a dash if the echo buffer is empty, so
5187 you don't always see a dash hanging out in the minibuffer. */
5191 /* Record the initial state of the echo area and this_command_keys;
5192 we will need to restore them if we replay a key sequence. */
5194 echo_start
= echo_length ();
5195 keys_start
= this_command_key_count
;
5197 #if defined (GOBBLE_FIRST_EVENT)
5198 /* This doesn't quite work, because some of the things that read_char
5199 does cannot safely be bypassed. It seems too risky to try to make
5202 /* Read the first char of the sequence specially, before setting
5203 up any keymaps, in case a filter runs and switches buffers on us. */
5204 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
5206 #endif /* GOBBLE_FIRST_EVENT */
5208 orig_local_map
= get_local_map (PT
, current_buffer
);
5210 /* We jump here when the key sequence has been thoroughly changed, and
5211 we need to rescan it starting from the beginning. When we jump here,
5212 keybuf[0..mock_input] holds the sequence we should reread. */
5215 starting_buffer
= current_buffer
;
5216 function_key_possible
= 0;
5217 key_translation_possible
= 0;
5219 /* Build our list of keymaps.
5220 If we recognize a function key and replace its escape sequence in
5221 keybuf with its symbol, or if the sequence starts with a mouse
5222 click and we need to switch buffers, we jump back here to rebuild
5223 the initial keymaps from the current buffer. */
5227 if (!NILP (current_kboard
->Voverriding_terminal_local_map
)
5228 || !NILP (Voverriding_local_map
))
5230 if (3 > nmaps_allocated
)
5232 submaps
= (Lisp_Object
*) alloca (3 * sizeof (submaps
[0]));
5233 defs
= (Lisp_Object
*) alloca (3 * sizeof (defs
[0]));
5234 nmaps_allocated
= 3;
5237 if (!NILP (current_kboard
->Voverriding_terminal_local_map
))
5238 submaps
[nmaps
++] = current_kboard
->Voverriding_terminal_local_map
;
5239 if (!NILP (Voverriding_local_map
))
5240 submaps
[nmaps
++] = Voverriding_local_map
;
5244 nmaps
= current_minor_maps (0, &maps
);
5245 if (nmaps
+ 2 > nmaps_allocated
)
5247 submaps
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (submaps
[0]));
5248 defs
= (Lisp_Object
*) alloca ((nmaps
+2) * sizeof (defs
[0]));
5249 nmaps_allocated
= nmaps
+ 2;
5251 bcopy (maps
, submaps
, nmaps
* sizeof (submaps
[0]));
5252 #ifdef USE_TEXT_PROPERTIES
5253 submaps
[nmaps
++] = orig_local_map
;
5255 submaps
[nmaps
++] = current_buffer
->keymap
;
5258 submaps
[nmaps
++] = current_global_map
;
5261 /* Find an accurate initial value for first_binding. */
5262 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
5263 if (! NILP (submaps
[first_binding
]))
5266 /* Start from the beginning in keybuf. */
5269 /* These are no-ops the first time through, but if we restart, they
5270 revert the echo area and this_command_keys to their original state. */
5271 this_command_key_count
= keys_start
;
5272 if (INTERACTIVE
&& t
< mock_input
)
5273 echo_truncate (echo_start
);
5275 /* If the best binding for the current key sequence is a keymap, or
5276 we may be looking at a function key's escape sequence, keep on
5278 while ((first_binding
< nmaps
&& ! NILP (submaps
[first_binding
]))
5279 || (first_binding
>= nmaps
5281 /* mock input is never part of a function key's sequence. */
5282 && mock_input
<= fkey_start
)
5283 || (first_binding
>= nmaps
5284 && keytran_start
< t
&& key_translation_possible
)
5285 /* Don't return in the middle of a possible function key sequence,
5286 if the only bindings we found were via case conversion.
5287 Thus, if ESC O a has a function-key-map translation
5288 and ESC o has a binding, don't return after ESC O,
5289 so that we can translate ESC O plus the next character. */
5293 int used_mouse_menu
= 0;
5295 /* Where the last real key started. If we need to throw away a
5296 key that has expanded into more than one element of keybuf
5297 (say, a mouse click on the mode line which is being treated
5298 as [mode-line (mouse-...)], then we backtrack to this point
5300 int last_real_key_start
;
5302 /* These variables are analogous to echo_start and keys_start;
5303 while those allow us to restart the entire key sequence,
5304 echo_local_start and keys_local_start allow us to throw away
5306 int echo_local_start
, keys_local_start
, local_first_binding
;
5309 error ("key sequence too long");
5312 echo_local_start
= echo_length ();
5313 keys_local_start
= this_command_key_count
;
5314 local_first_binding
= first_binding
;
5317 /* These are no-ops, unless we throw away a keystroke below and
5318 jumped back up to replay_key; in that case, these restore the
5319 variables to their original state, allowing us to replay the
5321 if (INTERACTIVE
&& t
< mock_input
)
5322 echo_truncate (echo_local_start
);
5323 this_command_key_count
= keys_local_start
;
5324 first_binding
= local_first_binding
;
5326 /* By default, assume each event is "real". */
5327 last_real_key_start
= t
;
5329 /* Does mock_input indicate that we are re-reading a key sequence? */
5333 add_command_key (key
);
5334 if (echo_keystrokes
)
5338 /* If not, we should actually read a character. */
5341 struct buffer
*buf
= current_buffer
;
5345 KBOARD
*interrupted_kboard
= current_kboard
;
5346 struct frame
*interrupted_frame
= selected_frame
;
5347 if (setjmp (wrong_kboard_jmpbuf
))
5349 if (!NILP (delayed_switch_frame
))
5351 interrupted_kboard
->kbd_queue
5352 = Fcons (delayed_switch_frame
,
5353 interrupted_kboard
->kbd_queue
);
5354 delayed_switch_frame
= Qnil
;
5357 interrupted_kboard
->kbd_queue
5358 = Fcons (keybuf
[--t
], interrupted_kboard
->kbd_queue
);
5360 /* If the side queue is non-empty, ensure it begins with a
5361 switch-frame, so we'll replay it in the right context. */
5362 if (CONSP (interrupted_kboard
->kbd_queue
)
5363 && (key
= XCONS (interrupted_kboard
->kbd_queue
)->car
,
5364 !(EVENT_HAS_PARAMETERS (key
)
5365 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)),
5369 XSETFRAME (frame
, interrupted_frame
);
5370 interrupted_kboard
->kbd_queue
5371 = Fcons (make_lispy_switch_frame (frame
),
5372 interrupted_kboard
->kbd_queue
);
5375 orig_local_map
= get_local_map (PT
, current_buffer
);
5376 goto replay_sequence
;
5379 key
= read_char (NILP (prompt
), nmaps
, submaps
, last_nonmenu_event
,
5383 /* read_char returns t when it shows a menu and the user rejects it.
5388 /* read_char returns -1 at the end of a macro.
5389 Emacs 18 handles this by returning immediately with a
5390 zero, so that's what we'll do. */
5391 if (INTEGERP (key
) && XINT (key
) == -1)
5394 /* The Microsoft C compiler can't handle the goto that
5400 /* If the current buffer has been changed from under us, the
5401 keymap may have changed, so replay the sequence. */
5405 orig_local_map
= get_local_map (PT
, current_buffer
);
5406 goto replay_sequence
;
5409 /* If we have a quit that was typed in another frame, and
5410 quit_throw_to_read_char switched buffers,
5411 replay to get the right keymap. */
5412 if (XINT (key
) == quit_char
&& current_buffer
!= starting_buffer
)
5417 orig_local_map
= get_local_map (PT
, current_buffer
);
5418 goto replay_sequence
;
5424 /* Clicks in non-text areas get prefixed by the symbol
5425 in their CHAR-ADDRESS field. For example, a click on
5426 the mode line is prefixed by the symbol `mode-line'.
5428 Furthermore, key sequences beginning with mouse clicks
5429 are read using the keymaps of the buffer clicked on, not
5430 the current buffer. So we may have to switch the buffer
5433 When we turn one event into two events, we must make sure
5434 that neither of the two looks like the original--so that,
5435 if we replay the events, they won't be expanded again.
5436 If not for this, such reexpansion could happen either here
5437 or when user programs play with this-command-keys. */
5438 if (EVENT_HAS_PARAMETERS (key
))
5442 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
5443 if (EQ (kind
, Qmouse_click
))
5445 Lisp_Object window
, posn
;
5447 window
= POSN_WINDOW (EVENT_START (key
));
5448 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
5451 /* We're looking at the second event of a
5452 sequence which we expanded before. Set
5453 last_real_key_start appropriately. */
5455 last_real_key_start
= t
- 1;
5458 /* Key sequences beginning with mouse clicks are
5459 read using the keymaps in the buffer clicked on,
5460 not the current buffer. If we're at the
5461 beginning of a key sequence, switch buffers. */
5462 if (last_real_key_start
== 0
5464 && BUFFERP (XWINDOW (window
)->buffer
)
5465 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
5470 /* Arrange to go back to the original buffer once we're
5471 done reading the key sequence. Note that we can't
5472 use save_excursion_{save,restore} here, because they
5473 save point as well as the current buffer; we don't
5474 want to save point, because redisplay may change it,
5475 to accommodate a Fset_window_start or something. We
5476 don't want to do this at the top of the function,
5477 because we may get input from a subprocess which
5478 wants to change the selected window and stuff (say,
5480 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
5482 set_buffer_internal (XBUFFER (XWINDOW (window
)->buffer
));
5483 orig_local_map
= get_local_map (PT
, current_buffer
);
5484 goto replay_sequence
;
5486 /* For a mouse click, get the local text-property keymap
5487 of the place clicked on, rather than point. */
5488 if (last_real_key_start
== 0 && CONSP (XCONS (key
)->cdr
)
5489 && ! localized_local_map
)
5491 Lisp_Object map_here
, start
, pos
;
5493 localized_local_map
= 1;
5494 start
= EVENT_START (key
);
5495 if (CONSP (start
) && CONSP (XCONS (start
)->cdr
))
5497 pos
= POSN_BUFFER_POSN (start
);
5500 map_here
= get_local_map (XINT (pos
), current_buffer
);
5501 if (!EQ (map_here
, orig_local_map
))
5503 orig_local_map
= map_here
;
5507 goto replay_sequence
;
5513 /* Expand mode-line and scroll-bar events into two events:
5514 use posn as a fake prefix key. */
5517 if (t
+ 1 >= bufsize
)
5518 error ("key sequence too long");
5523 /* Zap the position in key, so we know that we've
5524 expanded it, and don't try to do so again. */
5525 POSN_BUFFER_POSN (EVENT_START (key
))
5526 = Fcons (posn
, Qnil
);
5530 else if (EQ (kind
, Qswitch_frame
))
5532 /* If we're at the beginning of a key sequence, and the caller
5533 says it's okay, go ahead and return this event. If we're
5534 in the midst of a key sequence, delay it until the end. */
5535 if (t
> 0 || !can_return_switch_frame
)
5537 delayed_switch_frame
= key
;
5541 else if (CONSP (XCONS (key
)->cdr
)
5542 && CONSP (EVENT_START (key
))
5543 && CONSP (XCONS (EVENT_START (key
))->cdr
))
5547 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
5548 /* Handle menu-bar events:
5549 insert the dummy prefix event `menu-bar'. */
5550 if (EQ (posn
, Qmenu_bar
))
5552 if (t
+ 1 >= bufsize
)
5553 error ("key sequence too long");
5557 /* Zap the position in key, so we know that we've
5558 expanded it, and don't try to do so again. */
5559 POSN_BUFFER_POSN (EVENT_START (key
))
5560 = Fcons (posn
, Qnil
);
5563 goto replay_sequence
;
5565 else if (CONSP (posn
))
5567 /* We're looking at the second event of a
5568 sequence which we expanded before. Set
5569 last_real_key_start appropriately. */
5570 if (last_real_key_start
== t
&& t
> 0)
5571 last_real_key_start
= t
- 1;
5576 /* We have finally decided that KEY is something we might want
5578 first_binding
= (follow_key (key
,
5579 nmaps
- first_binding
,
5580 submaps
+ first_binding
,
5581 defs
+ first_binding
,
5582 submaps
+ first_binding
)
5585 /* If KEY wasn't bound, we'll try some fallbacks. */
5586 if (first_binding
>= nmaps
)
5590 head
= EVENT_HEAD (key
);
5591 if (help_char_p (head
) && t
> 0)
5593 read_key_sequence_cmd
= Vprefix_help_command
;
5595 last_nonmenu_event
= key
;
5596 /* The Microsoft C compiler can't handle the goto that
5604 Lisp_Object breakdown
;
5607 breakdown
= parse_modifiers (head
);
5608 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
5609 /* Attempt to reduce an unbound mouse event to a simpler
5610 event that is bound:
5611 Drags reduce to clicks.
5612 Double-clicks reduce to clicks.
5613 Triple-clicks reduce to double-clicks, then to clicks.
5614 Down-clicks are eliminated.
5615 Double-downs reduce to downs, then are eliminated.
5616 Triple-downs reduce to double-downs, then to downs,
5617 then are eliminated. */
5618 if (modifiers
& (down_modifier
| drag_modifier
5619 | double_modifier
| triple_modifier
))
5621 while (modifiers
& (down_modifier
| drag_modifier
5622 | double_modifier
| triple_modifier
))
5624 Lisp_Object new_head
, new_click
;
5625 if (modifiers
& triple_modifier
)
5626 modifiers
^= (double_modifier
| triple_modifier
);
5627 else if (modifiers
& double_modifier
)
5628 modifiers
&= ~double_modifier
;
5629 else if (modifiers
& drag_modifier
)
5630 modifiers
&= ~drag_modifier
;
5633 /* Dispose of this `down' event by simply jumping
5634 back to replay_key, to get another event.
5636 Note that if this event came from mock input,
5637 then just jumping back to replay_key will just
5638 hand it to us again. So we have to wipe out any
5641 We could delete keybuf[t] and shift everything
5642 after that to the left by one spot, but we'd also
5643 have to fix up any variable that points into
5644 keybuf, and shifting isn't really necessary
5647 Adding prefixes for non-textual mouse clicks
5648 creates two characters of mock input, and both
5649 must be thrown away. If we're only looking at
5650 the prefix now, we can just jump back to
5651 replay_key. On the other hand, if we've already
5652 processed the prefix, and now the actual click
5653 itself is giving us trouble, then we've lost the
5654 state of the keymaps we want to backtrack to, and
5655 we need to replay the whole sequence to rebuild
5658 Beyond that, only function key expansion could
5659 create more than two keys, but that should never
5660 generate mouse events, so it's okay to zero
5661 mock_input in that case too.
5663 Isn't this just the most wonderful code ever? */
5664 if (t
== last_real_key_start
)
5671 mock_input
= last_real_key_start
;
5672 goto replay_sequence
;
5677 = apply_modifiers (modifiers
, XCONS (breakdown
)->car
);
5679 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
5681 /* Look for a binding for this new key. follow_key
5682 promises that it didn't munge submaps the
5683 last time we called it, since key was unbound. */
5685 = (follow_key (new_click
,
5686 nmaps
- local_first_binding
,
5687 submaps
+ local_first_binding
,
5688 defs
+ local_first_binding
,
5689 submaps
+ local_first_binding
)
5690 + local_first_binding
);
5692 /* If that click is bound, go for it. */
5693 if (first_binding
< nmaps
)
5698 /* Otherwise, we'll leave key set to the drag event. */
5705 /* Normally, last_nonmenu_event gets the previous key we read.
5706 But when a mouse popup menu is being used,
5707 we don't update last_nonmenu_event; it continues to hold the mouse
5708 event that preceded the first level of menu. */
5709 if (!used_mouse_menu
)
5710 last_nonmenu_event
= key
;
5712 /* If the sequence is unbound, see if we can hang a function key
5713 off the end of it. We only want to scan real keyboard input
5714 for function key sequences, so if mock_input says that we're
5715 re-reading old events, don't examine it. */
5716 if (first_binding
>= nmaps
5719 Lisp_Object fkey_next
;
5721 /* Continue scan from fkey_end until we find a bound suffix.
5722 If we fail, increment fkey_start
5723 and start fkey_end from there. */
5724 while (fkey_end
< t
)
5728 key
= keybuf
[fkey_end
++];
5729 /* Look up meta-characters by prefixing them
5730 with meta_prefix_char. I hate this. */
5731 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
5736 (access_keymap (fkey_map
, meta_prefix_char
, 1, 0)),
5738 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
5741 fkey_next
= fkey_map
;
5744 = get_keyelt (access_keymap (fkey_next
, key
, 1, 0));
5746 #if 0 /* I didn't turn this on, because it might cause trouble
5747 for the mapping of return into C-m and tab into C-i. */
5748 /* Optionally don't map function keys into other things.
5749 This enables the user to redefine kp- keys easily. */
5750 if (SYMBOLP (key
) && !NILP (Vinhibit_function_key_mapping
))
5754 /* If the function key map gives a function, not an
5755 array, then call the function with no args and use
5756 its value instead. */
5757 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
5760 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5764 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
5765 fkey_next
= call1 (fkey_next
, prompt
);
5767 /* If the function returned something invalid,
5768 barf--don't ignore it.
5769 (To ignore it safely, we would need to gcpro a bunch of
5770 other variables.) */
5771 if (! (VECTORP (fkey_next
) || STRINGP (fkey_next
)))
5772 error ("Function in function-key-map returns invalid key sequence");
5775 function_key_possible
= ! NILP (fkey_next
);
5777 /* If keybuf[fkey_start..fkey_end] is bound in the
5778 function key map and it's a suffix of the current
5779 sequence (i.e. fkey_end == t), replace it with
5780 the binding and restart with fkey_start at the end. */
5781 if ((VECTORP (fkey_next
) || STRINGP (fkey_next
))
5784 int len
= XFASTINT (Flength (fkey_next
));
5786 t
= fkey_start
+ len
;
5788 error ("key sequence too long");
5790 if (VECTORP (fkey_next
))
5791 bcopy (XVECTOR (fkey_next
)->contents
,
5792 keybuf
+ fkey_start
,
5793 (t
- fkey_start
) * sizeof (keybuf
[0]));
5794 else if (STRINGP (fkey_next
))
5798 for (i
= 0; i
< len
; i
++)
5799 XSETFASTINT (keybuf
[fkey_start
+ i
],
5800 XSTRING (fkey_next
)->data
[i
]);
5804 fkey_start
= fkey_end
= t
;
5805 fkey_map
= Vfunction_key_map
;
5807 /* Do pass the results through key-translation-map. */
5808 keytran_start
= keytran_end
= 0;
5809 keytran_map
= Vkey_translation_map
;
5811 goto replay_sequence
;
5814 fkey_map
= get_keymap_1 (fkey_next
, 0, 1);
5816 /* If we no longer have a bound suffix, try a new positions for
5818 if (NILP (fkey_map
))
5820 fkey_end
= ++fkey_start
;
5821 fkey_map
= Vfunction_key_map
;
5822 function_key_possible
= 0;
5827 /* Look for this sequence in key-translation-map. */
5829 Lisp_Object keytran_next
;
5831 /* Scan from keytran_end until we find a bound suffix. */
5832 while (keytran_end
< t
)
5836 key
= keybuf
[keytran_end
++];
5837 /* Look up meta-characters by prefixing them
5838 with meta_prefix_char. I hate this. */
5839 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
5844 (access_keymap (keytran_map
, meta_prefix_char
, 1, 0)),
5846 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
5849 keytran_next
= keytran_map
;
5852 = get_keyelt (access_keymap (keytran_next
, key
, 1, 0));
5854 /* If the key translation map gives a function, not an
5855 array, then call the function with no args and use
5856 its value instead. */
5857 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
5858 && keytran_end
== t
)
5860 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5864 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
5865 keytran_next
= call1 (keytran_next
, prompt
);
5867 /* If the function returned something invalid,
5868 barf--don't ignore it.
5869 (To ignore it safely, we would need to gcpro a bunch of
5870 other variables.) */
5871 if (! (VECTORP (keytran_next
) || STRINGP (keytran_next
)))
5872 error ("Function in key-translation-map returns invalid key sequence");
5875 key_translation_possible
= ! NILP (keytran_next
);
5877 /* If keybuf[keytran_start..keytran_end] is bound in the
5878 key translation map and it's a suffix of the current
5879 sequence (i.e. keytran_end == t), replace it with
5880 the binding and restart with keytran_start at the end. */
5881 if ((VECTORP (keytran_next
) || STRINGP (keytran_next
))
5882 && keytran_end
== t
)
5884 int len
= XFASTINT (Flength (keytran_next
));
5886 t
= keytran_start
+ len
;
5888 error ("key sequence too long");
5890 if (VECTORP (keytran_next
))
5891 bcopy (XVECTOR (keytran_next
)->contents
,
5892 keybuf
+ keytran_start
,
5893 (t
- keytran_start
) * sizeof (keybuf
[0]));
5894 else if (STRINGP (keytran_next
))
5898 for (i
= 0; i
< len
; i
++)
5899 XSETFASTINT (keybuf
[keytran_start
+ i
],
5900 XSTRING (keytran_next
)->data
[i
]);
5904 keytran_start
= keytran_end
= t
;
5905 keytran_map
= Vkey_translation_map
;
5907 /* Don't pass the results of key-translation-map
5908 through function-key-map. */
5909 fkey_start
= fkey_end
= t
;
5910 fkey_map
= Vkey_translation_map
;
5912 goto replay_sequence
;
5915 keytran_map
= get_keymap_1 (keytran_next
, 0, 1);
5917 /* If we no longer have a bound suffix, try a new positions for
5919 if (NILP (keytran_map
))
5921 keytran_end
= ++keytran_start
;
5922 keytran_map
= Vkey_translation_map
;
5923 key_translation_possible
= 0;
5928 /* If KEY is not defined in any of the keymaps,
5929 and cannot be part of a function key or translation,
5930 and is an upper case letter
5931 use the corresponding lower-case letter instead. */
5932 if (first_binding
== nmaps
&& ! function_key_possible
5933 && ! key_translation_possible
5935 && ((((XINT (key
) & 0x3ffff)
5936 < XSTRING (current_buffer
->downcase_table
)->size
)
5937 && UPPERCASEP (XINT (key
) & 0x3ffff))
5938 || (XINT (key
) & shift_modifier
)))
5940 original_uppercase
= key
;
5941 original_uppercase_position
= t
- 1;
5943 if (XINT (key
) & shift_modifier
)
5944 XSETINT (key
, XINT (key
) & ~shift_modifier
);
5946 XSETINT (key
, (DOWNCASE (XINT (key
) & 0x3ffff)
5947 | (XINT (key
) & ~0x3ffff)));
5949 keybuf
[t
- 1] = key
;
5951 goto replay_sequence
;
5953 /* If KEY is not defined in any of the keymaps,
5954 and cannot be part of a function key or translation,
5955 and is a shifted function key,
5956 use the corresponding unshifted function key instead. */
5957 if (first_binding
== nmaps
&& ! function_key_possible
5958 && ! key_translation_possible
5961 Lisp_Object breakdown
;
5964 original_uppercase
= key
;
5965 original_uppercase_position
= t
- 1;
5967 breakdown
= parse_modifiers (key
);
5968 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
5969 if (modifiers
& shift_modifier
)
5971 modifiers
&= ~shift_modifier
;
5972 key
= apply_modifiers (modifiers
,
5973 XCONS (breakdown
)->car
);
5975 keybuf
[t
- 1] = key
;
5977 goto replay_sequence
;
5983 read_key_sequence_cmd
= (first_binding
< nmaps
5984 ? defs
[first_binding
]
5987 unread_switch_frame
= delayed_switch_frame
;
5988 unbind_to (count
, Qnil
);
5990 if (dont_downcase_last
&& t
- 1 == original_uppercase_position
)
5991 keybuf
[t
- 1] = original_uppercase
;
5993 /* Occasionally we fabricate events, perhaps by expanding something
5994 according to function-key-map, or by adding a prefix symbol to a
5995 mouse click in the scroll bar or modeline. In this cases, return
5996 the entire generated key sequence, even if we hit an unbound
5997 prefix or a definition before the end. This means that you will
5998 be able to push back the event properly, and also means that
5999 read-key-sequence will always return a logical unit.
6002 for (; t
< mock_input
; t
++)
6004 if (echo_keystrokes
)
6005 echo_char (keybuf
[t
]);
6006 add_command_key (keybuf
[t
]);
6012 #if 0 /* This doc string is too long for some compilers.
6013 This commented-out definition serves for DOC. */
6014 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
6015 "Read a sequence of keystrokes and return as a string or vector.\n\
6016 The sequence is sufficient to specify a non-prefix command in the\n\
6017 current local and global maps.\n\
6019 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
6020 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
6021 as a continuation of the previous key.\n\
6023 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not\n\
6024 convert the last event to lower case. (Normally any upper case event\n\
6025 is converted to lower case if the original event is undefined and the lower\n\
6026 case equivalent is defined.) A non-nil value is appropriate for reading\n\
6027 a key sequence to be defined.\n\
6029 A C-g typed while in this function is treated like any other character,\n\
6030 and `quit-flag' is not set.\n\
6032 If the key sequence starts with a mouse click, then the sequence is read\n\
6033 using the keymaps of the buffer of the window clicked in, not the buffer\n\
6034 of the selected window as normal.\n\
6036 `read-key-sequence' drops unbound button-down events, since you normally\n\
6037 only care about the click or drag events which follow them. If a drag\n\
6038 or multi-click event is unbound, but the corresponding click event would\n\
6039 be bound, `read-key-sequence' turns the event into a click event at the\n\
6040 drag's starting position. This means that you don't have to distinguish\n\
6041 between click and drag, double, or triple events unless you want to.\n\
6043 `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\
6044 lines separating windows, and scroll bars with imaginary keys\n\
6045 `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\
6047 Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this\n\
6048 function will process a switch-frame event if the user switches frames\n\
6049 before typing anything. If the user switches frames in the middle of a\n\
6050 key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME\n\
6051 is nil, then the event will be put off until after the current key sequence.\n\
6053 `read-key-sequence' checks `function-key-map' for function key\n\
6054 sequences, where they wouldn't conflict with ordinary bindings. See\n\
6055 `function-key-map' for more details.")
6056 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
)
6059 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
6061 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
)
6062 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
6063 Lisp_Object can_return_switch_frame
;
6065 Lisp_Object keybuf
[30];
6067 struct gcpro gcpro1
, gcpro2
;
6070 CHECK_STRING (prompt
, 0);
6073 bzero (keybuf
, sizeof keybuf
);
6075 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
6077 if (NILP (continue_echo
))
6078 this_command_key_count
= 0;
6080 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
6081 prompt
, ! NILP (dont_downcase_last
),
6082 ! NILP (can_return_switch_frame
));
6090 return make_event_array (i
, keybuf
);
6093 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 2, 0,
6094 "Execute CMD as an editor command.\n\
6095 CMD must be a symbol that satisfies the `commandp' predicate.\n\
6096 Optional second arg RECORD-FLAG non-nil\n\
6097 means unconditionally put this command in `command-history'.\n\
6098 Otherwise, that is done only if an arg is read using the minibuffer.")
6100 Lisp_Object cmd
, record
;
6102 register Lisp_Object final
;
6103 register Lisp_Object tem
;
6104 Lisp_Object prefixarg
;
6105 struct backtrace backtrace
;
6106 extern int debug_on_next_call
;
6108 prefixarg
= current_kboard
->Vprefix_arg
;
6109 current_kboard
->Vprefix_arg
= Qnil
;
6110 Vcurrent_prefix_arg
= prefixarg
;
6111 debug_on_next_call
= 0;
6115 tem
= Fget (cmd
, Qdisabled
);
6116 if (!NILP (tem
) && !NILP (Vrun_hooks
))
6117 return call1 (Vrun_hooks
, Qdisabled_command_hook
);
6122 final
= Findirect_function (cmd
);
6124 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
6125 do_autoload (final
, cmd
);
6130 if (STRINGP (final
) || VECTORP (final
))
6132 /* If requested, place the macro in the command history. For
6133 other sorts of commands, call-interactively takes care of
6137 = Fcons (Fcons (Qexecute_kbd_macro
,
6138 Fcons (final
, Fcons (prefixarg
, Qnil
))),
6141 return Fexecute_kbd_macro (final
, prefixarg
);
6143 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
6145 backtrace
.next
= backtrace_list
;
6146 backtrace_list
= &backtrace
;
6147 backtrace
.function
= &Qcall_interactively
;
6148 backtrace
.args
= &cmd
;
6149 backtrace
.nargs
= 1;
6150 backtrace
.evalargs
= 0;
6152 tem
= Fcall_interactively (cmd
, record
);
6154 backtrace_list
= backtrace
.next
;
6160 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
6162 "Read function name, then read its arguments and call it.")
6164 Lisp_Object prefixarg
;
6166 Lisp_Object function
;
6168 Lisp_Object saved_keys
;
6169 struct gcpro gcpro1
;
6171 saved_keys
= Fvector (this_command_key_count
,
6172 XVECTOR (this_command_keys
)->contents
);
6174 GCPRO1 (saved_keys
);
6176 if (EQ (prefixarg
, Qminus
))
6178 else if (CONSP (prefixarg
) && XINT (XCONS (prefixarg
)->car
) == 4)
6179 strcpy (buf
, "C-u ");
6180 else if (CONSP (prefixarg
) && INTEGERP (XCONS (prefixarg
)->car
))
6182 if (sizeof (int) == sizeof (EMACS_INT
))
6183 sprintf (buf
, "%d ", XINT (XCONS (prefixarg
)->car
));
6184 else if (sizeof (long) == sizeof (EMACS_INT
))
6185 sprintf (buf
, "%ld ", XINT (XCONS (prefixarg
)->car
));
6189 else if (INTEGERP (prefixarg
))
6191 if (sizeof (int) == sizeof (EMACS_INT
))
6192 sprintf (buf
, "%d ", XINT (prefixarg
));
6193 else if (sizeof (long) == sizeof (EMACS_INT
))
6194 sprintf (buf
, "%ld ", XINT (prefixarg
));
6199 /* This isn't strictly correct if execute-extended-command
6200 is bound to anything else. Perhaps it should use
6201 this_command_keys? */
6202 strcat (buf
, "M-x ");
6204 /* Prompt with buf, and then read a string, completing from and
6205 restricting to the set of all defined commands. Don't provide
6206 any initial input. Save the command read on the extended-command
6208 function
= Fcompleting_read (build_string (buf
),
6209 Vobarray
, Qcommandp
,
6210 Qt
, Qnil
, Qextended_command_history
);
6212 /* Set this_command_keys to the concatenation of saved_keys and
6213 function, followed by a RET. */
6215 struct Lisp_String
*str
;
6220 this_command_key_count
= 0;
6222 keys
= XVECTOR (saved_keys
)->contents
;
6223 for (i
= 0; i
< XVECTOR (saved_keys
)->size
; i
++)
6224 add_command_key (keys
[i
]);
6226 str
= XSTRING (function
);
6227 for (i
= 0; i
< str
->size
; i
++)
6229 XSETFASTINT (tem
, str
->data
[i
]);
6230 add_command_key (tem
);
6233 XSETFASTINT (tem
, '\015');
6234 add_command_key (tem
);
6239 function
= Fintern (function
, Qnil
);
6240 current_kboard
->Vprefix_arg
= prefixarg
;
6241 this_command
= function
;
6243 return Fcommand_execute (function
, Qt
);
6247 detect_input_pending ()
6250 get_input_pending (&input_pending
);
6252 return input_pending
;
6255 /* This is called in some cases before a possible quit.
6256 It cases the next call to detect_input_pending to recompute input_pending.
6257 So calling this function unnecessarily can't do any harm. */
6258 clear_input_pending ()
6263 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
6264 "T if command input is currently available with no waiting.\n\
6265 Actually, the value is nil only if we can be sure that no input is available.")
6268 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1)
6271 return detect_input_pending () ? Qt
: Qnil
;
6274 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
6275 "Return vector of last 100 events, not counting those from keyboard macros.")
6278 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
6281 if (total_keys
< NUM_RECENT_KEYS
)
6282 return Fvector (total_keys
, keys
);
6285 val
= Fvector (NUM_RECENT_KEYS
, keys
);
6286 bcopy (keys
+ recent_keys_index
,
6287 XVECTOR (val
)->contents
,
6288 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
6290 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
6291 recent_keys_index
* sizeof (Lisp_Object
));
6296 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
6297 "Return the key sequence that invoked this command.\n\
6298 The value is a string or a vector.")
6301 return make_event_array (this_command_key_count
,
6302 XVECTOR (this_command_keys
)->contents
);
6305 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths
,
6306 Sreset_this_command_lengths
, 0, 0, 0,
6307 "Used for complicated reasons in `universal-argument-other-key'.\n\
6309 `universal-argument-other-key' rereads the event just typed.\n\
6310 It then gets translated through `function-key-map'.\n\
6311 The translated event gets included in the echo area and in\n\
6312 the value of `this-command-keys' in addition to the raw original event.\n\
6313 That is not right.\n\
6315 Calling this function directs the translated event to replace\n\
6316 the original event, so that only one version of the event actually\n\
6317 appears in the echo area and in the value of `this-command-keys.'.")
6320 before_command_restore_flag
= 1;
6321 before_command_key_count_1
= before_command_key_count
;
6322 before_command_echo_length_1
= before_command_echo_length
;
6325 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
6326 "Return the current depth in recursive edits.")
6330 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
6334 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
6335 "FOpen dribble file: ",
6336 "Start writing all keyboard characters to a dribble file called FILE.\n\
6337 If FILE is nil, close any open dribble file.")
6351 file
= Fexpand_file_name (file
, Qnil
);
6352 dribble
= fopen (XSTRING (file
)->data
, "w");
6357 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
6358 "Discard the contents of the terminal input buffer.\n\
6359 Also cancel any kbd macro being defined.")
6362 current_kboard
->defining_kbd_macro
= Qnil
;
6363 update_mode_lines
++;
6365 Vunread_command_events
= Qnil
;
6366 unread_command_char
= -1;
6368 discard_tty_input ();
6370 /* Without the cast, GCC complains that this assignment loses the
6371 volatile qualifier of kbd_store_ptr. Is there anything wrong
6373 kbd_fetch_ptr
= (struct input_event
*) kbd_store_ptr
;
6374 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
6380 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
6381 "Stop Emacs and return to superior process. You can resume later.\n\
6382 If `cannot-suspend' is non-nil, or if the system doesn't support job\n\
6383 control, run a subshell instead.\n\n\
6384 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
6385 to be read as terminal input by Emacs's parent, after suspension.\n\
6387 Before suspending, run the normal hook `suspend-hook'.\n\
6388 After resumption run the normal hook `suspend-resume-hook'.\n\
6390 Some operating systems cannot stop the Emacs process and resume it later.\n\
6391 On such systems, Emacs starts a subshell instead of suspending.")
6393 Lisp_Object stuffstring
;
6396 int count
= specpdl_ptr
- specpdl
;
6397 int old_height
, old_width
;
6399 struct gcpro gcpro1
, gcpro2
;
6400 extern init_sys_modes ();
6402 if (!NILP (stuffstring
))
6403 CHECK_STRING (stuffstring
, 0);
6405 /* Run the functions in suspend-hook. */
6406 if (!NILP (Vrun_hooks
))
6407 call1 (Vrun_hooks
, intern ("suspend-hook"));
6409 GCPRO1 (stuffstring
);
6410 get_frame_size (&old_width
, &old_height
);
6412 /* sys_suspend can get an error if it tries to fork a subshell
6413 and the system resources aren't available for that. */
6414 record_unwind_protect (init_sys_modes
, 0);
6415 stuff_buffered_input (stuffstring
);
6420 unbind_to (count
, Qnil
);
6422 /* Check if terminal/window size has changed.
6423 Note that this is not useful when we are running directly
6424 with a window system; but suspend should be disabled in that case. */
6425 get_frame_size (&width
, &height
);
6426 if (width
!= old_width
|| height
!= old_height
)
6427 change_frame_size (selected_frame
, height
, width
, 0, 0);
6429 /* Run suspend-resume-hook. */
6430 if (!NILP (Vrun_hooks
))
6431 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
6437 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
6438 Then in any case stuff anything Emacs has read ahead and not used. */
6440 stuff_buffered_input (stuffstring
)
6441 Lisp_Object stuffstring
;
6443 /* stuff_char works only in BSD, versions 4.2 and up. */
6446 register unsigned char *p
;
6448 if (STRINGP (stuffstring
))
6452 p
= XSTRING (stuffstring
)->data
;
6453 count
= XSTRING (stuffstring
)->size
;
6458 /* Anything we have read ahead, put back for the shell to read. */
6459 /* ?? What should this do when we have multiple keyboards??
6460 Should we ignore anything that was typed in at the "wrong" kboard? */
6461 for (; kbd_fetch_ptr
!= kbd_store_ptr
; kbd_fetch_ptr
++)
6463 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
6464 kbd_fetch_ptr
= kbd_buffer
;
6465 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
6466 stuff_char (kbd_fetch_ptr
->code
);
6467 kbd_fetch_ptr
->kind
= no_event
;
6468 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_fetch_ptr
6474 #endif /* BSD and not BSD4_1 */
6477 set_waiting_for_input (time_to_clear
)
6478 EMACS_TIME
*time_to_clear
;
6480 input_available_clear_time
= time_to_clear
;
6482 /* Tell interrupt_signal to throw back to read_char, */
6483 waiting_for_input
= 1;
6485 /* If interrupt_signal was called before and buffered a C-g,
6486 make it run again now, to avoid timing error. */
6487 if (!NILP (Vquit_flag
))
6488 quit_throw_to_read_char ();
6491 clear_waiting_for_input ()
6493 /* Tell interrupt_signal not to throw back to read_char, */
6494 waiting_for_input
= 0;
6495 input_available_clear_time
= 0;
6498 /* This routine is called at interrupt level in response to C-G.
6499 If interrupt_input, this is the handler for SIGINT.
6500 Otherwise, it is called from kbd_buffer_store_event,
6501 in handling SIGIO or SIGTINT.
6503 If `waiting_for_input' is non zero, then unless `echoing' is nonzero,
6504 immediately throw back to read_char.
6506 Otherwise it sets the Lisp variable quit-flag not-nil.
6507 This causes eval to throw, when it gets a chance.
6508 If quit-flag is already non-nil, it stops the job right away. */
6511 interrupt_signal (signalnum
) /* If we don't have an argument, */
6512 int signalnum
; /* some compilers complain in signal calls. */
6515 /* Must preserve main program's value of errno. */
6516 int old_errno
= errno
;
6519 if (!read_socket_hook
&& NILP (Vwindow_system
))
6521 /* USG systems forget handlers when they are used;
6522 must reestablish each time */
6523 signal (SIGINT
, interrupt_signal
);
6524 signal (SIGQUIT
, interrupt_signal
);
6530 if (!NILP (Vquit_flag
) && FRAME_TERMCAP_P (selected_frame
))
6535 #ifdef SIGTSTP /* Support possible in later USG versions */
6537 * On systems which can suspend the current process and return to the original
6538 * shell, this command causes the user to end up back at the shell.
6539 * The "Auto-save" and "Abort" questions are not asked until
6540 * the user elects to return to emacs, at which point he can save the current
6541 * job and either dump core or continue.
6546 if (sys_suspend () == -1)
6548 printf ("Not running as a subprocess;\n");
6549 printf ("you can continue or abort.\n");
6552 /* Perhaps should really fork an inferior shell?
6553 But that would not provide any way to get back
6554 to the original shell, ever. */
6555 printf ("No support for stopping a process on this operating system;\n");
6556 printf ("you can continue or abort.\n");
6557 #endif /* not VMS */
6558 #endif /* not SIGTSTP */
6560 /* We must remain inside the screen area when the internal terminal
6561 is used. Note that [Enter] is not echoed by dos. */
6564 printf ("Auto-save? (y or n) ");
6566 if (((c
= getchar ()) & ~040) == 'Y')
6568 Fdo_auto_save (Qt
, Qnil
);
6570 printf ("\r\nAuto-save done");
6571 #else /* not MSDOS */
6572 printf ("Auto-save done\n");
6573 #endif /* not MSDOS */
6575 while (c
!= '\n') c
= getchar ();
6577 printf ("\r\nAbort? (y or n) ");
6578 #else /* not MSDOS */
6580 printf ("Abort (and enter debugger)? (y or n) ");
6582 printf ("Abort (and dump core)? (y or n) ");
6583 #endif /* not VMS */
6584 #endif /* not MSDOS */
6586 if (((c
= getchar ()) & ~040) == 'Y')
6588 while (c
!= '\n') c
= getchar ();
6590 printf ("\r\nContinuing...\r\n");
6591 #else /* not MSDOS */
6592 printf ("Continuing...\n");
6593 #endif /* not MSDOS */
6599 /* If executing a function that wants to be interrupted out of
6600 and the user has not deferred quitting by binding `inhibit-quit'
6601 then quit right away. */
6602 if (immediate_quit
&& NILP (Vinhibit_quit
))
6606 Fsignal (Qquit
, Qnil
);
6609 /* Else request quit when it's safe */
6613 if (waiting_for_input
&& !echoing
)
6614 quit_throw_to_read_char ();
6619 /* Handle a C-g by making read_char return C-g. */
6621 quit_throw_to_read_char ()
6623 quit_error_check ();
6625 /* Prevent another signal from doing this before we finish. */
6626 clear_waiting_for_input ();
6629 Vunread_command_events
= Qnil
;
6630 unread_command_char
= -1;
6632 #if 0 /* Currently, sit_for is called from read_char without turning
6633 off polling. And that can call set_waiting_for_input.
6634 It seems to be harmless. */
6635 #ifdef POLL_FOR_INPUT
6636 /* May be > 1 if in recursive minibuffer. */
6637 if (poll_suppress_count
== 0)
6642 if (FRAMEP (internal_last_event_frame
)
6643 && XFRAME (internal_last_event_frame
) != selected_frame
)
6644 do_switch_frame (make_lispy_switch_frame (internal_last_event_frame
),
6648 _longjmp (getcjmp
, 1);
6651 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
6652 "Set mode of reading keyboard input.\n\
6653 First arg INTERRUPT non-nil means use input interrupts;\n\
6654 nil means use CBREAK mode.\n\
6655 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
6656 (no effect except in CBREAK mode).\n\
6657 Third arg META t means accept 8-bit input (for a Meta key).\n\
6658 META nil means ignore the top bit, on the assumption it is parity.\n\
6659 Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\
6660 Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\
6661 See also `current-input-mode'.")
6662 (interrupt
, flow
, meta
, quit
)
6663 Lisp_Object interrupt
, flow
, meta
, quit
;
6666 && (!INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400))
6667 error ("set-input-mode: QUIT must be an ASCII character");
6669 #ifdef POLL_FOR_INPUT
6675 /* Note SIGIO has been undef'd if FIONREAD is missing. */
6676 if (read_socket_hook
)
6678 /* When using X, don't give the user a real choice,
6679 because we haven't implemented the mechanisms to support it. */
6680 #ifdef NO_SOCK_SIGIO
6681 interrupt_input
= 0;
6682 #else /* not NO_SOCK_SIGIO */
6683 interrupt_input
= 1;
6684 #endif /* NO_SOCK_SIGIO */
6687 interrupt_input
= !NILP (interrupt
);
6688 #else /* not SIGIO */
6689 interrupt_input
= 0;
6690 #endif /* not SIGIO */
6692 /* Our VMS input only works by interrupts, as of now. */
6694 interrupt_input
= 1;
6697 flow_control
= !NILP (flow
);
6700 else if (EQ (meta
, Qt
))
6705 /* Don't let this value be out of range. */
6706 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
6710 #ifdef POLL_FOR_INPUT
6711 poll_suppress_count
= 1;
6717 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
6718 "Return information about the way Emacs currently reads keyboard input.\n\
6719 The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
6720 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\
6721 nil, Emacs is using CBREAK mode.\n\
6722 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\
6723 terminal; this does not apply if Emacs uses interrupt-driven input.\n\
6724 META is t if accepting 8-bit input with 8th bit as Meta flag.\n\
6725 META nil means ignoring the top bit, on the assumption it is parity.\n\
6726 META is neither t nor nil if accepting 8-bit input and using\n\
6727 all 8 bits as the character code.\n\
6728 QUIT is the character Emacs currently uses to quit.\n\
6729 The elements of this list correspond to the arguments of\n\
6735 val
[0] = interrupt_input
? Qt
: Qnil
;
6736 val
[1] = flow_control
? Qt
: Qnil
;
6737 val
[2] = meta_key
== 2 ? make_number (0) : meta_key
== 1 ? Qt
: Qnil
;
6738 XSETFASTINT (val
[3], quit_char
);
6740 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
6745 * Set up a new kboard object with reasonable initial values.
6751 kb
->Voverriding_terminal_local_map
= Qnil
;
6752 kb
->Vlast_command
= Qnil
;
6753 kb
->Vprefix_arg
= Qnil
;
6754 kb
->kbd_queue
= Qnil
;
6755 kb
->kbd_queue_has_data
= 0;
6756 kb
->immediate_echo
= 0;
6757 kb
->echoptr
= kb
->echobuf
;
6758 kb
->echo_after_prompt
= -1;
6759 kb
->kbd_macro_buffer
= 0;
6760 kb
->kbd_macro_bufsize
= 0;
6761 kb
->defining_kbd_macro
= Qnil
;
6762 kb
->Vlast_kbd_macro
= Qnil
;
6763 kb
->reference_count
= 0;
6764 kb
->Vsystem_key_alist
= Qnil
;
6765 kb
->system_key_syms
= Qnil
;
6766 kb
->Vdefault_minibuffer_frame
= Qnil
;
6770 * Destroy the contents of a kboard object, but not the object itself.
6771 * We use this just before deleteing it, or if we're going to initialize
6778 if (kb
->kbd_macro_buffer
)
6779 xfree (kb
->kbd_macro_buffer
);
6788 for (kbp
= &all_kboards
; *kbp
!= kb
; kbp
= &(*kbp
)->next_kboard
)
6791 *kbp
= kb
->next_kboard
;
6799 /* This is correct before outermost invocation of the editor loop */
6800 command_loop_level
= -1;
6802 quit_char
= Ctl ('g');
6803 Vunread_command_events
= Qnil
;
6804 unread_command_char
= -1;
6806 recent_keys_index
= 0;
6807 kbd_fetch_ptr
= kbd_buffer
;
6808 kbd_store_ptr
= kbd_buffer
;
6809 kbd_buffer_frame_or_window
6810 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
6812 do_mouse_tracking
= Qnil
;
6817 /* This means that command_loop_1 won't try to select anything the first
6819 internal_last_event_frame
= Qnil
;
6820 Vlast_event_frame
= internal_last_event_frame
;
6824 current_kboard
= initial_kboard
;
6826 wipe_kboard (current_kboard
);
6827 init_kboard (current_kboard
);
6830 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
6832 kbd_buffer_frame_or_window
6833 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
6834 if (!noninteractive
&& !read_socket_hook
&& NILP (Vwindow_system
))
6836 signal (SIGINT
, interrupt_signal
);
6837 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
6838 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
6839 SIGQUIT and we can't tell which one it will give us. */
6840 signal (SIGQUIT
, interrupt_signal
);
6841 #endif /* HAVE_TERMIO */
6843 /* Note SIGIO has been undef'd if FIONREAD is missing. */
6845 if (!noninteractive
)
6846 signal (SIGIO
, input_available_signal
);
6849 /* Use interrupt input by default, if it works and noninterrupt input
6850 has deficiencies. */
6852 #ifdef INTERRUPT_INPUT
6853 interrupt_input
= 1;
6855 interrupt_input
= 0;
6858 /* Our VMS input only works by interrupts, as of now. */
6860 interrupt_input
= 1;
6866 if (keyboard_init_hook
)
6867 (*keyboard_init_hook
) ();
6869 #ifdef POLL_FOR_INPUT
6870 poll_suppress_count
= 1;
6875 /* This type's only use is in syms_of_keyboard, to initialize the
6876 event header symbols and put properties on them. */
6883 struct event_head head_table
[] = {
6884 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
6885 &Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
,
6886 &Qswitch_frame
, "switch-frame", &Qswitch_frame
,
6887 &Qdelete_frame
, "delete-frame", &Qdelete_frame
,
6888 &Qiconify_frame
, "iconify-frame", &Qiconify_frame
,
6889 &Qmake_frame_visible
, "make-frame-visible", &Qmake_frame_visible
,
6894 Qdisabled_command_hook
= intern ("disabled-command-hook");
6895 staticpro (&Qdisabled_command_hook
);
6897 Qself_insert_command
= intern ("self-insert-command");
6898 staticpro (&Qself_insert_command
);
6900 Qforward_char
= intern ("forward-char");
6901 staticpro (&Qforward_char
);
6903 Qbackward_char
= intern ("backward-char");
6904 staticpro (&Qbackward_char
);
6906 Qdisabled
= intern ("disabled");
6907 staticpro (&Qdisabled
);
6909 Qundefined
= intern ("undefined");
6910 staticpro (&Qundefined
);
6912 Qpre_command_hook
= intern ("pre-command-hook");
6913 staticpro (&Qpre_command_hook
);
6915 Qpost_command_hook
= intern ("post-command-hook");
6916 staticpro (&Qpost_command_hook
);
6918 Qdeferred_action_function
= intern ("deferred-action-function");
6919 staticpro (&Qdeferred_action_function
);
6921 Qcommand_hook_internal
= intern ("command-hook-internal");
6922 staticpro (&Qcommand_hook_internal
);
6924 Qfunction_key
= intern ("function-key");
6925 staticpro (&Qfunction_key
);
6926 Qmouse_click
= intern ("mouse-click");
6927 staticpro (&Qmouse_click
);
6929 Qmenu_enable
= intern ("menu-enable");
6930 staticpro (&Qmenu_enable
);
6932 Qmode_line
= intern ("mode-line");
6933 staticpro (&Qmode_line
);
6934 Qvertical_line
= intern ("vertical-line");
6935 staticpro (&Qvertical_line
);
6936 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
6937 staticpro (&Qvertical_scroll_bar
);
6938 Qmenu_bar
= intern ("menu-bar");
6939 staticpro (&Qmenu_bar
);
6941 Qabove_handle
= intern ("above-handle");
6942 staticpro (&Qabove_handle
);
6943 Qhandle
= intern ("handle");
6944 staticpro (&Qhandle
);
6945 Qbelow_handle
= intern ("below-handle");
6946 staticpro (&Qbelow_handle
);
6948 Qevent_kind
= intern ("event-kind");
6949 staticpro (&Qevent_kind
);
6950 Qevent_symbol_elements
= intern ("event-symbol-elements");
6951 staticpro (&Qevent_symbol_elements
);
6952 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
6953 staticpro (&Qevent_symbol_element_mask
);
6954 Qmodifier_cache
= intern ("modifier-cache");
6955 staticpro (&Qmodifier_cache
);
6957 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
6958 staticpro (&Qrecompute_lucid_menubar
);
6959 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
6960 staticpro (&Qactivate_menubar_hook
);
6962 Qpolling_period
= intern ("polling-period");
6963 staticpro (&Qpolling_period
);
6966 struct event_head
*p
;
6968 for (p
= head_table
;
6969 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
6972 *p
->var
= intern (p
->name
);
6974 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
6975 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
6979 button_down_location
= Fmake_vector (make_number (NUM_MOUSE_BUTTONS
), Qnil
);
6980 staticpro (&button_down_location
);
6984 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
6986 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
6987 for (i
= 0; i
< len
; i
++)
6988 if (modifier_names
[i
])
6989 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
6990 staticpro (&modifier_symbols
);
6993 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
6994 staticpro (&recent_keys
);
6996 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
6997 staticpro (&this_command_keys
);
6999 Qextended_command_history
= intern ("extended-command-history");
7000 Fset (Qextended_command_history
, Qnil
);
7001 staticpro (&Qextended_command_history
);
7003 kbd_buffer_frame_or_window
7004 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
7005 staticpro (&kbd_buffer_frame_or_window
);
7007 accent_key_syms
= Qnil
;
7008 staticpro (&accent_key_syms
);
7010 func_key_syms
= Qnil
;
7011 staticpro (&func_key_syms
);
7014 staticpro (&mouse_syms
);
7016 unread_switch_frame
= Qnil
;
7017 staticpro (&unread_switch_frame
);
7019 defsubr (&Sevent_convert_list
);
7020 defsubr (&Sread_key_sequence
);
7021 defsubr (&Srecursive_edit
);
7023 defsubr (&Strack_mouse
);
7025 defsubr (&Sinput_pending_p
);
7026 defsubr (&Scommand_execute
);
7027 defsubr (&Srecent_keys
);
7028 defsubr (&Sthis_command_keys
);
7029 defsubr (&Sreset_this_command_lengths
);
7030 defsubr (&Ssuspend_emacs
);
7031 defsubr (&Sabort_recursive_edit
);
7032 defsubr (&Sexit_recursive_edit
);
7033 defsubr (&Srecursion_depth
);
7034 defsubr (&Stop_level
);
7035 defsubr (&Sdiscard_input
);
7036 defsubr (&Sopen_dribble_file
);
7037 defsubr (&Sset_input_mode
);
7038 defsubr (&Scurrent_input_mode
);
7039 defsubr (&Sexecute_extended_command
);
7041 DEFVAR_LISP ("last-command-char", &last_command_char
,
7042 "Last input event that was part of a command.");
7044 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char
,
7045 "Last input event that was part of a command.");
7047 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
7048 "Last input event in a command, except for mouse menu events.\n\
7049 Mouse menus give back keys that don't look like mouse events;\n\
7050 this variable holds the actual mouse event that led to the menu,\n\
7051 so that you can determine whether the command was run by mouse or not.");
7053 DEFVAR_LISP ("last-input-char", &last_input_char
,
7054 "Last input event.");
7056 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char
,
7057 "Last input event.");
7059 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
7060 "List of objects to be read as next command input events.");
7062 DEFVAR_INT ("unread-command-char", &unread_command_char
,
7063 "If not -1, an object to be read as next command input event.");
7065 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
7066 "Meta-prefix character code. Meta-foo as command input\n\
7067 turns into this character followed by foo.");
7068 XSETINT (meta_prefix_char
, 033);
7070 DEFVAR_KBOARD ("last-command", Vlast_command
,
7071 "The last command executed. Normally a symbol with a function definition,\n\
7072 but can be whatever was found in the keymap, or whatever the variable\n\
7073 `this-command' was set to by that command.\n\
7075 The value `mode-exit' is special; it means that the previous command\n\
7076 read an event that told it to exit, and it did so and unread that event.\n\
7077 In other words, the present command is the event that made the previous\n\
7080 The value `kill-region' is special; it means that the previous command\n\
7081 was a kill command.");
7083 DEFVAR_LISP ("this-command", &this_command
,
7084 "The command now being executed.\n\
7085 The command can set this variable; whatever is put here\n\
7086 will be in `last-command' during the following command.");
7087 this_command
= Qnil
;
7089 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
7090 "*Number of keyboard input characters between auto-saves.\n\
7091 Zero means disable autosaving due to number of characters typed.");
7092 auto_save_interval
= 300;
7094 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
7095 "*Number of seconds idle time before auto-save.\n\
7096 Zero or nil means disable auto-saving due to idleness.\n\
7097 After auto-saving due to this many seconds of idle time,\n\
7098 Emacs also does a garbage collection if that seems to be warranted.");
7099 XSETFASTINT (Vauto_save_timeout
, 30);
7101 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes
,
7102 "*Nonzero means echo unfinished commands after this many seconds of pause.");
7103 echo_keystrokes
= 1;
7105 DEFVAR_INT ("polling-period", &polling_period
,
7106 "*Interval between polling for input during Lisp execution.\n\
7107 The reason for polling is to make C-g work to stop a running program.\n\
7108 Polling is needed only when using X windows and SIGIO does not work.\n\
7109 Polling is automatically disabled in all other cases.");
7112 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
7113 "*Maximum time between mouse clicks to make a double-click.\n\
7114 Measured in milliseconds. nil means disable double-click recognition;\n\
7115 t means double-clicks have no time limit and are detected\n\
7116 by position only.");
7117 Vdouble_click_time
= make_number (500);
7119 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
7120 "*Non-nil means inhibit local map menu bar menus.");
7121 inhibit_local_menu_bar_menus
= 0;
7123 DEFVAR_INT ("num-input-keys", &num_input_keys
,
7124 "Number of complete keys read from the keyboard so far.");
7127 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
7128 "The frame in which the most recently read event occurred.\n\
7129 If the last event came from a keyboard macro, this is set to `macro'.");
7130 Vlast_event_frame
= Qnil
;
7132 DEFVAR_LISP ("help-char", &Vhelp_char
,
7133 "Character to recognize as meaning Help.\n\
7134 When it is read, do `(eval help-form)', and display result if it's a string.\n\
7135 If the value of `help-form' is nil, this char can be read normally.");
7136 XSETINT (Vhelp_char
, Ctl ('H'));
7138 DEFVAR_LISP ("help-event-list", &Vhelp_event_list
,
7139 "List of input events to recognize as meaning Help.\n\
7140 These work just like the value of `help-char' (see that).");
7141 Vhelp_event_list
= Qnil
;
7143 DEFVAR_LISP ("help-form", &Vhelp_form
,
7144 "Form to execute when character `help-char' is read.\n\
7145 If the form returns a string, that string is displayed.\n\
7146 If `help-form' is nil, the help char is not recognized.");
7149 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
7150 "Command to run when `help-char' character follows a prefix key.\n\
7151 This command is used only when there is no actual binding\n\
7152 for that character after that prefix key.");
7153 Vprefix_help_command
= Qnil
;
7155 DEFVAR_LISP ("top-level", &Vtop_level
,
7156 "Form to evaluate when Emacs starts up.\n\
7157 Useful to set before you dump a modified Emacs.");
7160 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
7161 "String used as translate table for keyboard input, or nil.\n\
7162 Each character is looked up in this string and the contents used instead.\n\
7163 If string is of length N, character codes N and up are untranslated.");
7164 Vkeyboard_translate_table
= Qnil
;
7166 DEFVAR_LISP ("key-translation-map", &Vkey_translation_map
,
7167 "Keymap of key translations that can override keymaps.\n\
7168 This keymap works like `function-key-map', but comes after that,\n\
7169 and applies even for keys that have ordinary bindings.");
7170 Vkey_translation_map
= Qnil
;
7172 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
7173 "Non-nil means to always spawn a subshell instead of suspending,\n\
7174 even if the operating system has support for stopping a process.");
7177 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
7178 "Non-nil means prompt with menus when appropriate.\n\
7179 This is done when reading from a keymap that has a prompt string,\n\
7180 for elements that have prompt strings.\n\
7181 The menu is displayed on the screen\n\
7182 if X menus were enabled at configuration\n\
7183 time and the previous event was a mouse click prefix key.\n\
7184 Otherwise, menu prompting uses the echo area.");
7187 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
7188 "Character to see next line of menu prompt.\n\
7189 Type this character while in a menu prompt to rotate around the lines of it.");
7190 XSETINT (menu_prompt_more_char
, ' ');
7192 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
7193 "A mask of additional modifier keys to use with every keyboard character.\n\
7194 Emacs applies the modifiers of the character stored here to each keyboard\n\
7195 character it reads. For example, after evaluating the expression\n\
7196 (setq extra-keyboard-modifiers ?\\C-x)\n\
7197 all input characters will have the control modifier applied to them.\n\
7199 Note that the character ?\\C-@, equivalent to the integer zero, does\n\
7200 not count as a control character; rather, it counts as a character\n\
7201 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\
7202 cancels any modification.");
7203 extra_keyboard_modifiers
= 0;
7205 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
7206 "If an editing command sets this to t, deactivate the mark afterward.\n\
7207 The command loop sets this to nil before each command,\n\
7208 and tests the value when the command returns.\n\
7209 Buffer modification stores t in this variable.");
7210 Vdeactivate_mark
= Qnil
;
7212 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
7213 "Temporary storage of pre-command-hook or post-command-hook.");
7214 Vcommand_hook_internal
= Qnil
;
7216 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
7217 "Normal hook run before each command is executed.\n\
7218 While the hook is run, its value is temporarily set to nil\n\
7219 to avoid an unbreakable infinite loop if a hook function gets an error.\n\
7220 As a result, a hook function cannot straightforwardly alter the value of\n\
7221 `pre-command-hook'. See the Emacs Lisp manual for a way of\n\
7222 implementing hook functions that alter the set of hook functions.");
7223 Vpre_command_hook
= Qnil
;
7225 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
7226 "Normal hook run after each command is executed.\n\
7227 While the hook is run, its value is temporarily set to nil\n\
7228 to avoid an unbreakable infinite loop if a hook function gets an error.\n\
7229 As a result, a hook function cannot straightforwardly alter the value of\n\
7230 `post-command-hook'. See the Emacs Lisp manual for a way of\n\
7231 implementing hook functions that alter the set of hook functions.");
7232 Vpost_command_hook
= Qnil
;
7234 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
7235 "t means menu bar, specified Lucid style, needs to be recomputed.");
7236 Vlucid_menu_bar_dirty_flag
= Qnil
;
7238 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
7239 "List of menu bar items to move to the end of the menu bar.\n\
7240 The elements of the list are event types that may have menu bar bindings.");
7241 Vmenu_bar_final_items
= Qnil
;
7243 DEFVAR_KBOARD ("overriding-terminal-local-map",
7244 Voverriding_terminal_local_map
,
7245 "Keymap that overrides all other local keymaps.\n\
7246 If this variable is non-nil, it is used as a keymap instead of the\n\
7247 buffer's local map, and the minor mode keymaps and text property keymaps.");
7249 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
7250 "Keymap that overrides all other local keymaps.\n\
7251 If this variable is non-nil, it is used as a keymap instead of the\n\
7252 buffer's local map, and the minor mode keymaps and text property keymaps.");
7253 Voverriding_local_map
= Qnil
;
7255 DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag
,
7256 "Non-nil means `overriding-local-map' applies to the menu bar.\n\
7257 Otherwise, the menu bar continues to reflect the buffer's local map\n\
7258 and the minor mode maps regardless of `overriding-local-map'.");
7259 Voverriding_local_map_menu_flag
= Qnil
;
7261 DEFVAR_LISP ("special-event-map", &Vspecial_event_map
,
7262 "Keymap defining bindings for special events to execute at low level.");
7263 Vspecial_event_map
= Fcons (intern ("keymap"), Qnil
);
7265 DEFVAR_LISP ("track-mouse", &do_mouse_tracking
,
7266 "*Non-nil means generate motion events for mouse motion.");
7268 DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist
,
7269 "Alist of system-specific X windows key symbols.\n\
7270 Each element should have the form (N . SYMBOL) where N is the\n\
7271 numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\
7272 and SYMBOL is its name.");
7274 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
7275 "List of deferred actions to be performed at a later time.\n\
7276 The precise format isn't relevant here; we just check whether it is nil.");
7277 Vdeferred_action_list
= Qnil
;
7279 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
7280 "Function to call to handle deferred actions, after each command.\n\
7281 This function is called with no arguments after each command\n\
7282 whenever `deferred-action-list' is non-nil.");
7283 Vdeferred_action_function
= Qnil
;
7288 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
7289 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
7290 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
7291 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
7292 initial_define_key (meta_map
, 'x', "execute-extended-command");
7294 initial_define_lispy_key (Vspecial_event_map
, "delete-frame",
7295 "handle-delete-frame");
7296 initial_define_lispy_key (Vspecial_event_map
, "iconify-frame",
7298 initial_define_lispy_key (Vspecial_event_map
, "make-frame-visible",