1 /* Keyboard and mouse input; editor command loop.
2 Copyright (C) 1985,86,87,88,89,93,94,95 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* Allow config.h to undefine symbols found here. */
28 #include "termhooks.h"
35 #include "dispextern.h"
37 #include "intervals.h"
38 #include "blockinput.h"
47 #include <sys/ioctl.h>
49 #endif /* not MSDOS */
51 #include "syssignal.h"
54 /* This is to get the definitions of the XK_ symbols. */
59 /* Include systime.h after xterm.h to avoid double inclusion of time.h. */
64 /* Variables for blockinput.h: */
66 /* Non-zero if interrupt input is blocked right now. */
67 int interrupt_input_blocked
;
69 /* Nonzero means an input interrupt has arrived
70 during the current critical section. */
71 int interrupt_input_pending
;
74 /* File descriptor to use for input. */
78 /* Make all keyboard buffers much bigger when using X windows. */
79 #define KBD_BUFFER_SIZE 4096
80 #else /* No X-windows, character input */
81 #define KBD_BUFFER_SIZE 256
82 #endif /* No X-windows */
84 /* Following definition copied from eval.c */
88 struct backtrace
*next
;
89 Lisp_Object
*function
;
90 Lisp_Object
*args
; /* Points to vector of args. */
91 int nargs
; /* length of vector. If nargs is UNEVALLED,
92 args points to slot holding list of
98 KBOARD
*initial_kboard
;
99 KBOARD
*current_kboard
;
103 KBOARD the_only_kboard
;
106 /* Non-nil disable property on a command means
107 do not execute it; call disabled-command-hook's value instead. */
108 Lisp_Object Qdisabled
, Qdisabled_command_hook
;
110 #define NUM_RECENT_KEYS (100)
111 int recent_keys_index
; /* Index for storing next element into recent_keys */
112 int total_keys
; /* Total number of elements stored into recent_keys */
113 Lisp_Object recent_keys
; /* A vector, holding the last 100 keystrokes */
115 /* Vector holding the key sequence that invoked the current command.
116 It is reused for each command, and it may be longer than the current
117 sequence; this_command_key_count indicates how many elements
118 actually mean something.
119 It's easier to staticpro a single Lisp_Object than an array. */
120 Lisp_Object this_command_keys
;
121 int this_command_key_count
;
123 extern int minbuf_level
;
125 extern struct backtrace
*backtrace_list
;
127 /* Nonzero means do menu prompting. */
128 static int menu_prompting
;
130 /* Character to see next line of menu prompt. */
131 static Lisp_Object menu_prompt_more_char
;
133 /* For longjmp to where kbd input is being done. */
134 static jmp_buf getcjmp
;
136 /* True while doing kbd input. */
137 int waiting_for_input
;
139 /* True while displaying for echoing. Delays C-g throwing. */
142 /* Nonzero means disregard local maps for the menu bar. */
143 static int inhibit_local_menu_bar_menus
;
145 /* Nonzero means C-g should cause immediate error-signal. */
148 /* Character to recognize as the help char. */
149 Lisp_Object Vhelp_char
;
151 /* List of other event types to recognize as meaning "help". */
152 Lisp_Object Vhelp_event_list
;
154 /* Form to execute when help char is typed. */
155 Lisp_Object Vhelp_form
;
157 /* Command to run when the help character follows a prefix key. */
158 Lisp_Object Vprefix_help_command
;
160 /* List of items that should move to the end of the menu bar. */
161 Lisp_Object Vmenu_bar_final_items
;
163 /* Character that causes a quit. Normally C-g.
165 If we are running on an ordinary terminal, this must be an ordinary
166 ASCII char, since we want to make it our interrupt character.
168 If we are not running on an ordinary terminal, it still needs to be
169 an ordinary ASCII char. This character needs to be recognized in
170 the input interrupt handler. At this point, the keystroke is
171 represented as a struct input_event, while the desired quit
172 character is specified as a lispy event. The mapping from struct
173 input_events to lispy events cannot run in an interrupt handler,
174 and the reverse mapping is difficult for anything but ASCII
177 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
181 extern Lisp_Object current_global_map
;
182 extern int minibuf_level
;
184 /* If non-nil, this is a map that overrides all other local maps. */
185 Lisp_Object Voverriding_local_map
;
187 /* If non-nil, Voverriding_local_map applies to the menu bar. */
188 Lisp_Object Voverriding_local_map_menu_flag
;
190 /* Current depth in recursive edits. */
191 int command_loop_level
;
193 /* Total number of times command_loop has read a key sequence. */
196 /* Last input character read as a command. */
197 Lisp_Object last_command_char
;
199 /* Last input character read as a command, not counting menus
200 reached by the mouse. */
201 Lisp_Object last_nonmenu_event
;
203 /* Last input character read for any purpose. */
204 Lisp_Object last_input_char
;
206 /* If not Qnil, a list of objects to be read as subsequent command input. */
207 Lisp_Object Vunread_command_events
;
209 /* If not -1, an event to be read as subsequent command input. */
210 int unread_command_char
;
212 /* If not Qnil, this is a switch-frame event which we decided to put
213 off until the end of a key sequence. This should be read as the
214 next command input, after any unread_command_events.
216 read_key_sequence uses this to delay switch-frame events until the
217 end of the key sequence; Fread_char uses it to put off switch-frame
218 events until a non-ASCII event is acceptable as input. */
219 Lisp_Object unread_switch_frame
;
221 /* A mask of extra modifier bits to put into every keyboard char. */
222 int extra_keyboard_modifiers
;
224 /* Char to use as prefix when a meta character is typed in.
225 This is bound on entry to minibuffer in case ESC is changed there. */
227 Lisp_Object meta_prefix_char
;
229 /* Last size recorded for a current buffer which is not a minibuffer. */
230 static int last_non_minibuf_size
;
232 /* Number of idle seconds before an auto-save and garbage collection. */
233 static Lisp_Object Vauto_save_timeout
;
235 /* Total number of times read_char has returned. */
238 /* Total number of times read_char has returned, outside of macros. */
239 int num_nonmacro_input_chars
;
241 /* Auto-save automatically when this many characters have been typed
242 since the last time. */
244 static int auto_save_interval
;
246 /* Value of num_nonmacro_input_chars as of last auto save. */
250 /* Last command executed by the editor command loop, not counting
251 commands that set the prefix argument. */
253 Lisp_Object last_command
;
255 /* The command being executed by the command loop.
256 Commands may set this, and the value set will be copied into last_command
257 instead of the actual command. */
258 Lisp_Object this_command
;
260 /* The value of point when the last command was executed. */
261 int last_point_position
;
263 /* The buffer that was current when the last command was started. */
264 Lisp_Object last_point_position_buffer
;
267 /* The frame in which the last input event occurred, or Qmacro if the
268 last event came from a macro. We use this to determine when to
269 generate switch-frame events. This may be cleared by functions
270 like Fselect_frame, to make sure that a switch-frame event is
271 generated by the next character. */
272 Lisp_Object internal_last_event_frame
;
275 /* A user-visible version of the above, intended to allow users to
276 figure out where the last event came from, if the event doesn't
277 carry that information itself (i.e. if it was a character). */
278 Lisp_Object Vlast_event_frame
;
280 /* The timestamp of the last input event we received from the X server.
281 X Windows wants this for selection ownership. */
282 unsigned long last_event_timestamp
;
284 Lisp_Object Qself_insert_command
;
285 Lisp_Object Qforward_char
;
286 Lisp_Object Qbackward_char
;
287 Lisp_Object Qundefined
;
289 /* read_key_sequence stores here the command definition of the
290 key sequence that it reads. */
291 Lisp_Object read_key_sequence_cmd
;
293 /* Form to evaluate (if non-nil) when Emacs is started. */
294 Lisp_Object Vtop_level
;
296 /* User-supplied string to translate input characters through. */
297 Lisp_Object Vkeyboard_translate_table
;
299 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
300 extern Lisp_Object Vfunction_key_map
;
302 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
303 Lisp_Object Vkey_translation_map
;
305 /* Non-nil means deactivate the mark at end of this command. */
306 Lisp_Object Vdeactivate_mark
;
308 /* Menu bar specified in Lucid Emacs fashion. */
310 Lisp_Object Vlucid_menu_bar_dirty_flag
;
311 Lisp_Object Qrecompute_lucid_menubar
, Qactivate_menubar_hook
;
313 /* Hooks to run before and after each command. */
314 Lisp_Object Qpre_command_hook
, Qpost_command_hook
;
315 Lisp_Object Vpre_command_hook
, Vpost_command_hook
;
316 Lisp_Object Qcommand_hook_internal
, Vcommand_hook_internal
;
318 /* List of deferred actions to be performed at a later time.
319 The precise format isn't relevant here; we just check whether it is nil. */
320 Lisp_Object Vdeferred_action_list
;
322 /* Function to call to handle deferred actions, when there are any. */
323 Lisp_Object Vdeferred_action_function
;
324 Lisp_Object Qdeferred_action_function
;
326 /* File in which we write all commands we read. */
329 /* Nonzero if input is available. */
332 /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
333 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
337 extern char *pending_malloc_warning
;
339 /* Circular buffer for pre-read keyboard input. */
340 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
342 /* Vector to GCPRO the frames and windows mentioned in kbd_buffer.
344 The interrupt-level event handlers will never enqueue an event on a
345 frame which is not in Vframe_list, and once an event is dequeued,
346 internal_last_event_frame or the event itself points to the frame.
349 But while the event is sitting in the queue, it's completely
350 unprotected. Suppose the user types one command which will run for
351 a while and then delete a frame, and then types another event at
352 the frame that will be deleted, before the command gets around to
353 it. Suppose there are no references to this frame elsewhere in
354 Emacs, and a GC occurs before the second event is dequeued. Now we
355 have an event referring to a freed frame, which will crash Emacs
358 Similar things happen when an event on a scroll bar is enqueued; the
359 window may be deleted while the event is in the queue.
361 So, we use this vector to protect the frame_or_window field in the
362 event queue. That way, they'll be dequeued as dead frames or
363 windows, but still valid lisp objects.
365 If kbd_buffer[i].kind != no_event, then
366 (XVECTOR (kbd_buffer_frame_or_window)->contents[i]
367 == kbd_buffer[i].frame_or_window. */
368 static Lisp_Object kbd_buffer_frame_or_window
;
370 /* Pointer to next available character in kbd_buffer.
371 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
372 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the
373 next available char is in kbd_buffer[0]. */
374 static struct input_event
*kbd_fetch_ptr
;
376 /* Pointer to next place to store character in kbd_buffer. This
377 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
378 character should go in kbd_buffer[0]. */
379 static volatile struct input_event
*kbd_store_ptr
;
381 /* The above pair of variables forms a "queue empty" flag. When we
382 enqueue a non-hook event, we increment kbd_store_ptr. When we
383 dequeue a non-hook event, we increment kbd_fetch_ptr. We say that
384 there is input available iff the two pointers are not equal.
386 Why not just have a flag set and cleared by the enqueuing and
387 dequeuing functions? Such a flag could be screwed up by interrupts
388 at inopportune times. */
390 /* If this flag is a frame, we check mouse_moved to see when the
391 mouse moves, and motion events will appear in the input stream.
392 Otherwise, mouse motion is ignored. */
393 static Lisp_Object do_mouse_tracking
;
396 /* The window system handling code should set this if the mouse has
397 moved since the last call to the mouse_position_hook. Calling that
398 hook should clear this. Code assumes that if this is set, it can
399 call mouse_position_hook to get the promised position, so don't set
400 it unless you're prepared to substantiate the claim! */
402 #endif /* HAVE_MOUSE */
404 /* Symbols to head events. */
405 Lisp_Object Qmouse_movement
;
406 Lisp_Object Qscroll_bar_movement
;
407 Lisp_Object Qswitch_frame
;
408 Lisp_Object Qdelete_frame
;
409 Lisp_Object Qiconify_frame
;
410 Lisp_Object Qmake_frame_visible
;
412 /* Symbols to denote kinds of events. */
413 Lisp_Object Qfunction_key
;
414 Lisp_Object Qmouse_click
;
415 /* Lisp_Object Qmouse_movement; - also an event header */
417 /* Properties of event headers. */
418 Lisp_Object Qevent_kind
;
419 Lisp_Object Qevent_symbol_elements
;
421 Lisp_Object Qmenu_enable
;
423 /* An event header symbol HEAD may have a property named
424 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
425 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
426 mask of modifiers applied to it. If present, this is used to help
427 speed up parse_modifiers. */
428 Lisp_Object Qevent_symbol_element_mask
;
430 /* An unmodified event header BASE may have a property named
431 Qmodifier_cache, which is an alist mapping modifier masks onto
432 modified versions of BASE. If present, this helps speed up
434 Lisp_Object Qmodifier_cache
;
436 /* Symbols to use for parts of windows. */
437 Lisp_Object Qmode_line
;
438 Lisp_Object Qvertical_line
;
439 Lisp_Object Qvertical_scroll_bar
;
440 Lisp_Object Qmenu_bar
;
442 extern Lisp_Object Qmenu_enable
;
444 Lisp_Object
recursive_edit_unwind (), command_loop ();
445 Lisp_Object
Fthis_command_keys ();
446 Lisp_Object Qextended_command_history
;
448 Lisp_Object Qpolling_period
;
450 extern Lisp_Object Vprint_level
, Vprint_length
;
452 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
454 EMACS_TIME
*input_available_clear_time
;
456 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
457 Default is 1 if INTERRUPT_INPUT is defined. */
460 /* Nonzero while interrupts are temporarily deferred during redisplay. */
461 int interrupts_deferred
;
463 /* nonzero means use ^S/^Q for flow control. */
466 /* Allow m- file to inhibit use of FIONREAD. */
467 #ifdef BROKEN_FIONREAD
471 /* We are unable to use interrupts if FIONREAD is not available,
472 so flush SIGIO so we won't try. */
479 /* If we support X Windows, turn on the code to poll periodically
480 to detect C-g. It isn't actually used when doing interrupt input. */
481 #ifdef HAVE_X_WINDOWS
482 #define POLL_FOR_INPUT
485 /* Global variable declarations. */
487 /* Function for init_keyboard to call with no args (if nonzero). */
488 void (*keyboard_init_hook
) ();
490 static int read_avail_input ();
491 static void get_input_pending ();
492 static int readable_events ();
493 static Lisp_Object
read_char_x_menu_prompt ();
494 static Lisp_Object
read_char_minibuf_menu_prompt ();
495 static Lisp_Object
make_lispy_event ();
497 static Lisp_Object
make_lispy_movement ();
499 static Lisp_Object
modify_event_symbol ();
500 static Lisp_Object
make_lispy_switch_frame ();
501 static int parse_solitary_modifier ();
503 /* > 0 if we are to echo keystrokes. */
504 static int echo_keystrokes
;
506 /* Nonzero means don't try to suspend even if the operating system seems
508 static int cannot_suspend
;
510 #define min(a,b) ((a)<(b)?(a):(b))
511 #define max(a,b) ((a)>(b)?(a):(b))
513 /* Install the string STR as the beginning of the string of echoing,
514 so that it serves as a prompt for the next character.
515 Also start echoing. */
520 int len
= strlen (str
);
522 if (len
> ECHOBUFSIZE
- 4)
523 len
= ECHOBUFSIZE
- 4;
524 bcopy (str
, current_kboard
->echobuf
, len
);
525 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
526 *current_kboard
->echoptr
= '\0';
528 current_kboard
->echo_after_prompt
= len
;
533 /* Add C to the echo string, if echoing is going on.
534 C can be a character, which is printed prettily ("M-C-x" and all that
535 jazz), or a symbol, whose name is printed. */
540 extern char *push_key_description ();
542 if (current_kboard
->immediate_echo
)
544 char *ptr
= current_kboard
->echoptr
;
546 if (ptr
!= current_kboard
->echobuf
)
549 /* If someone has passed us a composite event, use its head symbol. */
554 if (ptr
- current_kboard
->echobuf
> ECHOBUFSIZE
- 6)
557 ptr
= push_key_description (XINT (c
), ptr
);
559 else if (SYMBOLP (c
))
561 struct Lisp_String
*name
= XSYMBOL (c
)->name
;
562 if ((ptr
- current_kboard
->echobuf
) + name
->size
+ 4 > ECHOBUFSIZE
)
564 bcopy (name
->data
, ptr
, name
->size
);
568 if (current_kboard
->echoptr
== current_kboard
->echobuf
571 strcpy (ptr
, " (Type ? for further options)");
576 current_kboard
->echoptr
= ptr
;
582 /* Temporarily add a dash to the end of the echo string if it's not
583 empty, so that it serves as a mini-prompt for the very next character. */
587 if (!current_kboard
->immediate_echo
588 && current_kboard
->echoptr
== current_kboard
->echobuf
)
590 /* Do nothing if we just printed a prompt. */
591 if (current_kboard
->echo_after_prompt
592 == current_kboard
->echoptr
- current_kboard
->echobuf
)
594 /* Do nothing if not echoing at all. */
595 if (current_kboard
->echoptr
== 0)
598 /* Put a dash at the end of the buffer temporarily,
599 but make it go away when the next character is added. */
600 current_kboard
->echoptr
[0] = '-';
601 current_kboard
->echoptr
[1] = 0;
606 /* Display the current echo string, and begin echoing if not already
611 if (!current_kboard
->immediate_echo
)
614 current_kboard
->immediate_echo
= 1;
616 for (i
= 0; i
< this_command_key_count
; i
++)
619 c
= XVECTOR (this_command_keys
)->contents
[i
];
620 if (! (EVENT_HAS_PARAMETERS (c
)
621 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
628 message1_nolog (current_kboard
->echobuf
);
631 if (waiting_for_input
&& !NILP (Vquit_flag
))
632 quit_throw_to_read_char ();
635 /* Turn off echoing, for the start of a new command. */
639 current_kboard
->immediate_echo
= 0;
640 current_kboard
->echoptr
= current_kboard
->echobuf
;
641 current_kboard
->echo_after_prompt
= -1;
644 /* Return the length of the current echo string. */
649 return current_kboard
->echoptr
- current_kboard
->echobuf
;
652 /* Truncate the current echo message to its first LEN chars.
653 This and echo_char get used by read_key_sequence when the user
654 switches frames while entering a key sequence. */
660 current_kboard
->echobuf
[len
] = '\0';
661 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
662 truncate_echo_area (len
);
666 /* Functions for manipulating this_command_keys. */
668 add_command_key (key
)
671 int size
= XVECTOR (this_command_keys
)->size
;
673 if (this_command_key_count
>= size
)
675 Lisp_Object new_keys
;
677 new_keys
= Fmake_vector (make_number (size
* 2), Qnil
);
678 bcopy (XVECTOR (this_command_keys
)->contents
,
679 XVECTOR (new_keys
)->contents
,
680 size
* sizeof (Lisp_Object
));
682 this_command_keys
= new_keys
;
685 XVECTOR (this_command_keys
)->contents
[this_command_key_count
++] = key
;
691 int count
= specpdl_ptr
- specpdl
;
694 if (command_loop_level
> 0)
696 specbind (Qstandard_output
, Qt
);
697 specbind (Qstandard_input
, Qt
);
700 val
= command_loop ();
702 Fsignal (Qquit
, Qnil
);
704 return unbind_to (count
, Qnil
);
707 /* When an auto-save happens, record the "time", and don't do again soon. */
711 last_auto_save
= num_nonmacro_input_chars
;
714 /* Make an auto save happen as soon as possible at command level. */
716 force_auto_save_soon ()
718 last_auto_save
= - auto_save_interval
- 1;
720 record_asynch_buffer_change ();
723 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
724 "Invoke the editor command loop recursively.\n\
725 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
726 that tells this function to return.\n\
727 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
728 This function is called by the editor initialization to begin editing.")
731 int count
= specpdl_ptr
- specpdl
;
734 command_loop_level
++;
735 update_mode_lines
= 1;
737 record_unwind_protect (recursive_edit_unwind
,
739 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
743 return unbind_to (count
, Qnil
);
747 recursive_edit_unwind (buffer
)
751 Fset_buffer (buffer
);
753 command_loop_level
--;
754 update_mode_lines
= 1;
762 #if 0 /* Theory: if there's anything in Vunread_command_events,
763 it will right away be read by read_key_sequence,
764 and then if we do switch KBOARDS, it will go into the side
765 queue then. So we don't need to do anything special here -- rms. */
766 if (CONSP (Vunread_command_events
))
768 current_kboard
->kbd_queue
769 = nconc2 (Vunread_command_events
, current_kboard
->kbd_queue
);
770 current_kboard
->kbd_queue_has_data
= 1;
772 Vunread_command_events
= Qnil
;
778 /* Switch to the single-kboard state, making current_kboard
779 the only KBOARD from which further input is accepted. */
782 single_kboard_state ()
789 /* Maintain a stack of kboards, so other parts of Emacs
790 can switch temporarily to the kboard of a given frame
791 and then revert to the previous status. */
796 struct kboard_stack
*next
;
799 static struct kboard_stack
*kboard_stack
;
802 push_frame_kboard (f
)
806 struct kboard_stack
*p
807 = (struct kboard_stack
*) xmalloc (sizeof (struct kboard_stack
));
809 p
->next
= kboard_stack
;
810 p
->kboard
= current_kboard
;
813 current_kboard
= FRAME_KBOARD (f
);
821 struct kboard_stack
*p
= kboard_stack
;
822 current_kboard
= p
->kboard
;
823 kboard_stack
= p
->next
;
828 /* Handle errors that are not handled at inner levels
829 by printing an error message and returning to the editor command loop. */
835 Lisp_Object old_level
, old_length
;
837 Vstandard_output
= Qt
;
838 Vstandard_input
= Qt
;
839 Vexecuting_macro
= Qnil
;
840 current_kboard
->Vprefix_arg
= Qnil
;
843 /* Avoid unquittable loop if data contains a circular list. */
844 old_level
= Vprint_level
;
845 old_length
= Vprint_length
;
846 XSETFASTINT(Vprint_level
, 10);
847 XSETFASTINT(Vprint_length
, 10);
848 cmd_error_internal (data
, NULL
);
849 Vprint_level
= old_level
;
850 Vprint_length
= old_length
;
854 Vinhibit_quit
= Qnil
;
859 return make_number (0);
862 cmd_error_internal (data
, context
)
866 Lisp_Object errmsg
, tail
, errname
, file_error
;
873 echo_area_glyphs
= 0;
875 /* If the window system or terminal frame hasn't been initialized
876 yet, or we're not interactive, it's best to dump this message out
877 to stderr and exit. */
878 if (! FRAME_MESSAGE_BUF (selected_frame
)
880 stream
= Qexternal_debugging_output
;
889 write_string_1 (context
, -1, stream
);
891 errname
= Fcar (data
);
893 if (EQ (errname
, Qerror
))
896 if (!CONSP (data
)) data
= Qnil
;
897 errmsg
= Fcar (data
);
902 errmsg
= Fget (errname
, Qerror_message
);
903 file_error
= Fmemq (Qfile_error
,
904 Fget (errname
, Qerror_conditions
));
907 /* Print an error message including the data items.
908 This is done by printing it into a scratch buffer
909 and then making a copy of the text in the buffer. */
911 if (!CONSP (data
)) data
= Qnil
;
915 /* For file-error, make error message by concatenating
916 all the data items. They are all strings. */
917 if (!NILP (file_error
) && !NILP (tail
))
918 errmsg
= XCONS (tail
)->car
, tail
= XCONS (tail
)->cdr
;
920 if (STRINGP (errmsg
))
921 Fprinc (errmsg
, stream
);
923 write_string_1 ("peculiar error", -1, stream
);
925 for (i
= 0; CONSP (tail
); tail
= Fcdr (tail
), i
++)
927 write_string_1 (i
? ", " : ": ", 2, stream
);
928 if (!NILP (file_error
))
929 Fprinc (Fcar (tail
), stream
);
931 Fprin1 (Fcar (tail
), stream
);
935 /* If the window system or terminal frame hasn't been initialized
936 yet, or we're in -batch mode, this error should cause Emacs to exit. */
937 if (! FRAME_MESSAGE_BUF (selected_frame
)
941 Fkill_emacs (make_number (-1));
945 Lisp_Object
command_loop_1 ();
946 Lisp_Object
command_loop_2 ();
947 Lisp_Object
top_level_1 ();
949 /* Entry to editor-command-loop.
950 This level has the catches for exiting/returning to editor command loop.
951 It returns nil to exit recursive edit, t to abort it. */
956 if (command_loop_level
> 0 || minibuf_level
> 0)
958 return internal_catch (Qexit
, command_loop_2
, Qnil
);
963 internal_catch (Qtop_level
, top_level_1
, Qnil
);
964 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
966 /* End of file in -batch run causes exit here. */
972 /* Here we catch errors in execution of commands within the
973 editing loop, and reenter the editing loop.
974 When there is an error, cmd_error runs and returns a non-nil
975 value to us. A value of nil means that cmd_loop_1 itself
976 returned due to end of file (or end of kbd macro). */
981 register Lisp_Object val
;
984 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
993 return Feval (Vtop_level
);
999 /* On entry to the outer level, run the startup file */
1000 if (!NILP (Vtop_level
))
1001 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
1002 else if (!NILP (Vpurify_flag
))
1003 message ("Bare impure Emacs (standard Lisp code not loaded)");
1005 message ("Bare Emacs (standard Lisp code not loaded)");
1009 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
1010 "Exit all recursive editing levels.")
1013 Fthrow (Qtop_level
, Qnil
);
1016 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
1017 "Exit from the innermost recursive edit or minibuffer.")
1020 if (command_loop_level
> 0 || minibuf_level
> 0)
1021 Fthrow (Qexit
, Qnil
);
1023 error ("No recursive edit is in progress");
1026 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
1027 "Abort the command that requested this recursive edit or minibuffer input.")
1030 if (command_loop_level
> 0 || minibuf_level
> 0)
1033 error ("No recursive edit is in progress");
1036 /* This is the actual command reading loop,
1037 sans error-handling encapsulation. */
1039 Lisp_Object
Fcommand_execute ();
1040 static int read_key_sequence ();
1041 static void safe_run_hooks ();
1046 Lisp_Object cmd
, tem
;
1049 Lisp_Object keybuf
[30];
1054 struct buffer
*prev_buffer
;
1056 int was_locked
= single_kboard
;
1059 Vdeactivate_mark
= Qnil
;
1060 waiting_for_input
= 0;
1065 this_command_key_count
= 0;
1067 /* Make sure this hook runs after commands that get errors and
1068 throw to top level. */
1069 /* Note that the value cell will never directly contain nil
1070 if the symbol is a local variable. */
1071 if (!NILP (XSYMBOL (Qpost_command_hook
)->value
) && !NILP (Vrun_hooks
))
1072 safe_run_hooks (Qpost_command_hook
);
1074 if (!NILP (Vdeferred_action_list
))
1075 call0 (Vdeferred_action_function
);
1077 /* Do this after running Vpost_command_hook, for consistency. */
1078 last_command
= this_command
;
1082 /* Make sure the current window's buffer is selected. */
1083 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1084 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1086 /* Display any malloc warning that just came out. Use while because
1087 displaying one warning can cause another. */
1089 while (pending_malloc_warning
)
1090 display_malloc_warning ();
1094 Vdeactivate_mark
= Qnil
;
1096 /* If minibuffer on and echo area in use,
1097 wait 2 sec and redraw minibuffer. */
1099 if (minibuf_level
&& echo_area_glyphs
)
1101 /* Bind inhibit-quit to t so that C-g gets read in
1102 rather than quitting back to the minibuffer. */
1103 int count
= specpdl_ptr
- specpdl
;
1104 specbind (Qinhibit_quit
, Qt
);
1105 Fsit_for (make_number (2), Qnil
, Qnil
);
1106 unbind_to (count
, Qnil
);
1108 echo_area_glyphs
= 0;
1110 if (!NILP (Vquit_flag
))
1113 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1118 alloca (0); /* Cause a garbage collection now */
1119 /* Since we can free the most stuff here. */
1120 #endif /* C_ALLOCA */
1124 /* Select the frame that the last event came from. Usually,
1125 switch-frame events will take care of this, but if some lisp
1126 code swallows a switch-frame event, we'll fix things up here.
1127 Is this a good idea? */
1128 if (FRAMEP (internal_last_event_frame
)
1129 && XFRAME (internal_last_event_frame
) != selected_frame
)
1130 Fselect_frame (internal_last_event_frame
, Qnil
);
1133 /* If it has changed current-menubar from previous value,
1134 really recompute the menubar from the value. */
1135 if (! NILP (Vlucid_menu_bar_dirty_flag
)
1136 && !NILP (Ffboundp (Qrecompute_lucid_menubar
)))
1137 call0 (Qrecompute_lucid_menubar
);
1139 /* Read next key sequence; i gets its length. */
1140 i
= read_key_sequence (keybuf
, sizeof keybuf
/ sizeof keybuf
[0],
1145 /* Now we have read a key sequence of length I,
1146 or else I is 0 and we found end of file. */
1148 if (i
== 0) /* End of file -- happens only in */
1149 return Qnil
; /* a kbd macro, at the end. */
1150 /* -1 means read_key_sequence got a menu that was rejected.
1151 Just loop around and read another command. */
1155 this_command_key_count
= 0;
1159 last_command_char
= keybuf
[i
- 1];
1161 /* If the previous command tried to force a specific window-start,
1162 forget about that, in case this command moves point far away
1163 from that position. But also throw away beg_unchanged and
1164 end_unchanged information in that case, so that redisplay will
1165 update the whole window properly. */
1166 if (!NILP (XWINDOW (selected_window
)->force_start
))
1168 XWINDOW (selected_window
)->force_start
= Qnil
;
1169 beg_unchanged
= end_unchanged
= 0;
1172 cmd
= read_key_sequence_cmd
;
1173 if (!NILP (Vexecuting_macro
))
1175 if (!NILP (Vquit_flag
))
1177 Vexecuting_macro
= Qt
;
1178 QUIT
; /* Make some noise. */
1179 /* Will return since macro now empty. */
1183 /* Do redisplay processing after this command except in special
1184 cases identified below that set no_redisplay to 1.
1185 (actually, there's currently no way to prevent the redisplay,
1186 and no_redisplay is ignored.
1187 Perhaps someday we will really implement it.) */
1190 prev_buffer
= current_buffer
;
1191 prev_modiff
= MODIFF
;
1192 last_point_position
= PT
;
1193 XSETBUFFER (last_point_position_buffer
, prev_buffer
);
1195 /* Execute the command. */
1198 /* Note that the value cell will never directly contain nil
1199 if the symbol is a local variable. */
1200 if (!NILP (XSYMBOL (Qpre_command_hook
)->value
) && !NILP (Vrun_hooks
))
1201 safe_run_hooks (Qpre_command_hook
);
1203 if (NILP (this_command
))
1205 /* nil means key is undefined. */
1207 current_kboard
->defining_kbd_macro
= Qnil
;
1208 update_mode_lines
= 1;
1209 current_kboard
->Vprefix_arg
= Qnil
;
1213 if (NILP (current_kboard
->Vprefix_arg
) && ! no_direct
)
1215 /* Recognize some common commands in common situations and
1216 do them directly. */
1217 if (EQ (this_command
, Qforward_char
) && PT
< ZV
)
1219 struct Lisp_Vector
*dp
1220 = window_display_table (XWINDOW (selected_window
));
1221 lose
= FETCH_CHAR (PT
);
1224 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1225 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1226 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1227 && (lose
>= 0x20 && lose
< 0x7f)))
1228 : (lose
>= 0x20 && lose
< 0x7f))
1229 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1231 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1233 && !windows_or_buffers_changed
1234 && EQ (current_buffer
->selective_display
, Qnil
)
1235 && !detect_input_pending ()
1236 && NILP (Vexecuting_macro
))
1237 no_redisplay
= direct_output_forward_char (1);
1240 else if (EQ (this_command
, Qbackward_char
) && PT
> BEGV
)
1242 struct Lisp_Vector
*dp
1243 = window_display_table (XWINDOW (selected_window
));
1245 lose
= FETCH_CHAR (PT
);
1247 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1248 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1249 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1250 && (lose
>= 0x20 && lose
< 0x7f)))
1251 : (lose
>= 0x20 && lose
< 0x7f))
1252 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1254 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1256 && !windows_or_buffers_changed
1257 && EQ (current_buffer
->selective_display
, Qnil
)
1258 && !detect_input_pending ()
1259 && NILP (Vexecuting_macro
))
1260 no_redisplay
= direct_output_forward_char (-1);
1263 else if (EQ (this_command
, Qself_insert_command
)
1264 /* Try this optimization only on ascii keystrokes. */
1265 && INTEGERP (last_command_char
))
1267 unsigned char c
= XINT (last_command_char
);
1270 if (NILP (Vexecuting_macro
)
1271 && !EQ (minibuf_window
, selected_window
))
1273 if (!nonundocount
|| nonundocount
>= 20)
1280 lose
= ((XFASTINT (XWINDOW (selected_window
)->last_modified
)
1282 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1284 || MODIFF
<= SAVE_MODIFF
1285 || windows_or_buffers_changed
1286 || !EQ (current_buffer
->selective_display
, Qnil
)
1287 || detect_input_pending ()
1288 || !NILP (Vexecuting_macro
));
1289 value
= internal_self_insert (c
, 0);
1296 && (PT
== ZV
|| FETCH_CHAR (PT
) == '\n'))
1298 struct Lisp_Vector
*dp
1299 = window_display_table (XWINDOW (selected_window
));
1306 obj
= DISP_CHAR_VECTOR (dp
, lose
);
1309 /* Do it only for char codes
1310 that by default display as themselves. */
1311 if (lose
>= 0x20 && lose
<= 0x7e)
1312 no_redisplay
= direct_output_for_insert (lose
);
1314 else if (VECTORP (obj
)
1315 && XVECTOR (obj
)->size
== 1
1316 && (obj
= XVECTOR (obj
)->contents
[0],
1318 /* Insist face not specified in glyph. */
1319 && (XINT (obj
) & ((-1) << 8)) == 0)
1321 = direct_output_for_insert (XINT (obj
));
1325 if (lose
>= 0x20 && lose
<= 0x7e)
1326 no_redisplay
= direct_output_for_insert (lose
);
1333 /* Here for a command that isn't executed directly */
1336 if (NILP (current_kboard
->Vprefix_arg
))
1338 Fcommand_execute (this_command
, Qnil
);
1343 /* Note that the value cell will never directly contain nil
1344 if the symbol is a local variable. */
1345 if (!NILP (XSYMBOL (Qpost_command_hook
)->value
) && !NILP (Vrun_hooks
))
1346 safe_run_hooks (Qpost_command_hook
);
1348 if (!NILP (Vdeferred_action_list
))
1349 safe_run_hooks (Qdeferred_action_function
);
1351 /* If there is a prefix argument,
1352 1) We don't want last_command to be ``universal-argument''
1353 (that would be dumb), so don't set last_command,
1354 2) we want to leave echoing on so that the prefix will be
1355 echoed as part of this key sequence, so don't call
1357 3) we want to leave this_command_key_count non-zero, so that
1358 read_char will realize that it is re-reading a character, and
1359 not echo it a second time. */
1360 if (NILP (current_kboard
->Vprefix_arg
))
1362 last_command
= this_command
;
1364 this_command_key_count
= 0;
1367 if (!NILP (current_buffer
->mark_active
) && !NILP (Vrun_hooks
))
1369 if (!NILP (Vdeactivate_mark
) && !NILP (Vtransient_mark_mode
))
1371 current_buffer
->mark_active
= Qnil
;
1372 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
1374 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
1375 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
1379 /* Install chars successfully executed in kbd macro. */
1381 if (!NILP (current_kboard
->defining_kbd_macro
)
1382 && NILP (current_kboard
->Vprefix_arg
))
1383 finalize_kbd_macro_chars ();
1387 any_kboard_state ();
1392 /* Subroutine for safe_run_hooks: run the hook HOOK. */
1395 safe_run_hooks_1 (hook
)
1398 return call1 (Vrun_hooks
, Vinhibit_quit
);
1401 /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */
1404 safe_run_hooks_error (data
)
1407 Fset (Vinhibit_quit
, Qnil
);
1410 /* If we get an error while running the hook, cause the hook variable
1411 to be nil. Also inhibit quits, so that C-g won't cause the hook
1412 to mysteriously evaporate. */
1415 safe_run_hooks (hook
)
1419 int count
= specpdl_ptr
- specpdl
;
1420 specbind (Qinhibit_quit
, hook
);
1422 internal_condition_case (safe_run_hooks_1
, Qerror
, safe_run_hooks_error
);
1424 unbind_to (count
, Qnil
);
1427 /* Number of seconds between polling for input. */
1430 /* Nonzero means polling for input is temporarily suppressed. */
1431 int poll_suppress_count
;
1433 /* Nonzero if polling_for_input is actually being used. */
1434 int polling_for_input
;
1436 #ifdef POLL_FOR_INPUT
1438 /* Handle an alarm once each second and read pending input
1439 so as to handle a C-g if it comces in. */
1442 input_poll_signal (signalnum
) /* If we don't have an argument, */
1443 int signalnum
; /* some compilers complain in signal calls. */
1445 if (interrupt_input_blocked
== 0
1446 && !waiting_for_input
)
1447 read_avail_input (0);
1448 signal (SIGALRM
, input_poll_signal
);
1449 alarm (polling_period
);
1454 /* Begin signals to poll for input, if they are appropriate.
1455 This function is called unconditionally from various places. */
1459 #ifdef POLL_FOR_INPUT
1460 if (read_socket_hook
&& !interrupt_input
)
1462 poll_suppress_count
--;
1463 if (poll_suppress_count
== 0)
1465 signal (SIGALRM
, input_poll_signal
);
1466 polling_for_input
= 1;
1467 alarm (polling_period
);
1473 /* Nonzero if we are using polling to handle input asynchronously. */
1476 input_polling_used ()
1478 #ifdef POLL_FOR_INPUT
1479 return read_socket_hook
&& !interrupt_input
;
1485 /* Turn off polling. */
1489 #ifdef POLL_FOR_INPUT
1490 if (read_socket_hook
&& !interrupt_input
)
1492 if (poll_suppress_count
== 0)
1494 polling_for_input
= 0;
1497 poll_suppress_count
++;
1502 /* Set the value of poll_suppress_count to COUNT
1503 and start or stop polling accordingly. */
1506 set_poll_suppress_count (count
)
1509 #ifdef POLL_FOR_INPUT
1510 if (count
== 0 && poll_suppress_count
!= 0)
1512 poll_suppress_count
= 1;
1515 else if (count
!= 0 && poll_suppress_count
== 0)
1519 poll_suppress_count
= count
;
1523 /* Bind polling_period to a value at least N.
1524 But don't decrease it. */
1526 bind_polling_period (n
)
1529 #ifdef POLL_FOR_INPUT
1530 int new = polling_period
;
1536 specbind (Qpolling_period
, make_number (new));
1537 /* Start a new alarm with the new period. */
1542 /* Apply the control modifier to CHARACTER. */
1548 /* Save the upper bits here. */
1549 int upper
= c
& ~0177;
1553 /* Everything in the columns containing the upper-case letters
1554 denotes a control character. */
1555 if (c
>= 0100 && c
< 0140)
1559 /* Set the shift modifier for a control char
1560 made from a shifted letter. But only for letters! */
1561 if (oc
>= 'A' && oc
<= 'Z')
1562 c
|= shift_modifier
;
1565 /* The lower-case letters denote control characters too. */
1566 else if (c
>= 'a' && c
<= 'z')
1569 /* Include the bits for control and shift
1570 only if the basic ASCII code can't indicate them. */
1574 /* Replace the high bits. */
1575 c
|= (upper
& ~ctrl_modifier
);
1582 /* Input of single characters from keyboard */
1584 Lisp_Object
print_help ();
1585 static Lisp_Object
kbd_buffer_get_event ();
1586 static void record_char ();
1589 static jmp_buf wrong_kboard_jmpbuf
;
1592 /* read a character from the keyboard; call the redisplay if needed */
1593 /* commandflag 0 means do not do auto-saving, but do do redisplay.
1594 -1 means do not do redisplay, but do do autosaving.
1597 /* The arguments MAPS and NMAPS are for menu prompting.
1598 MAPS is an array of keymaps; NMAPS is the length of MAPS.
1600 PREV_EVENT is the previous input event, or nil if we are reading
1601 the first event of a key sequence.
1603 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
1604 if we used a mouse menu to read the input, or zero otherwise. If
1605 USED_MOUSE_MENU is null, we don't dereference it.
1607 Value is t if we showed a menu and the user rejected it. */
1610 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
)
1614 Lisp_Object prev_event
;
1615 int *used_mouse_menu
;
1617 register Lisp_Object c
;
1619 jmp_buf local_getcjmp
;
1621 int key_already_recorded
= 0;
1622 Lisp_Object also_record
;
1625 if (CONSP (Vunread_command_events
))
1627 c
= XCONS (Vunread_command_events
)->car
;
1628 Vunread_command_events
= XCONS (Vunread_command_events
)->cdr
;
1630 if (this_command_key_count
== 0)
1636 if (unread_command_char
!= -1)
1638 XSETINT (c
, unread_command_char
);
1639 unread_command_char
= -1;
1641 if (this_command_key_count
== 0)
1647 if (!NILP (Vexecuting_macro
))
1650 /* We set this to Qmacro; since that's not a frame, nobody will
1651 try to switch frames on us, and the selected window will
1654 Since this event came from a macro, it would be misleading to
1655 leave internal_last_event_frame set to wherever the last
1656 real event came from. Normally, a switch-frame event selects
1657 internal_last_event_frame after each command is read, but
1658 events read from a macro should never cause a new frame to be
1660 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
1663 /* Exit the macro if we are at the end.
1664 Also, some things replace the macro with t
1665 to force an early exit. */
1666 if (EQ (Vexecuting_macro
, Qt
)
1667 || executing_macro_index
>= XFASTINT (Flength (Vexecuting_macro
)))
1673 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
1674 if (STRINGP (Vexecuting_macro
)
1675 && (XINT (c
) & 0x80))
1676 XSETFASTINT (c
, CHAR_META
| (XINT (c
) & ~0x80));
1678 executing_macro_index
++;
1683 if (!NILP (unread_switch_frame
))
1685 c
= unread_switch_frame
;
1686 unread_switch_frame
= Qnil
;
1688 /* This event should make it into this_command_keys, and get echoed
1689 again, so we go to reread_first, rather than reread. */
1693 if (commandflag
>= 0 && !input_pending
&& !detect_input_pending ())
1696 /* Message turns off echoing unless more keystrokes turn it on again. */
1697 if (echo_area_glyphs
&& *echo_area_glyphs
1698 && echo_area_glyphs
!= current_kboard
->echobuf
)
1701 /* If already echoing, continue. */
1704 /* Try reading a character via menu prompting in the minibuf.
1705 Try this before the sit-for, because the sit-for
1706 would do the wrong thing if we are supposed to do
1707 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
1708 after a mouse event so don't try a minibuf menu. */
1710 if (nmaps
> 0 && INTERACTIVE
1711 && !NILP (prev_event
) && ! EVENT_HAS_PARAMETERS (prev_event
)
1712 /* Don't bring up a menu if we already have another event. */
1713 && NILP (Vunread_command_events
)
1714 && unread_command_char
< 0
1715 && !detect_input_pending ())
1717 c
= read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
);
1720 key_already_recorded
= 1;
1725 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet.
1726 We will do that below, temporarily for short sections of code,
1727 when appropriate. local_getcjmp must be in effect
1728 around any call to sit_for or kbd_buffer_get_event;
1729 it *must not* be in effect when we call redisplay. */
1731 if (_setjmp (local_getcjmp
))
1733 XSETINT (c
, quit_char
);
1735 XSETFRAME (internal_last_event_frame
, selected_frame
);
1736 Vlast_event_frame
= internal_last_event_frame
;
1738 /* If we report the quit char as an event,
1739 don't do so more than once. */
1740 if (!NILP (Vinhibit_quit
))
1745 KBOARD
*kb
= FRAME_KBOARD (selected_frame
);
1746 if (kb
!= current_kboard
)
1748 Lisp_Object
*tailp
= &kb
->kbd_queue
;
1749 /* We shouldn't get here if we were in single-kboard mode! */
1752 while (CONSP (*tailp
))
1753 tailp
= &XCONS (*tailp
)->cdr
;
1756 *tailp
= Fcons (c
, Qnil
);
1757 kb
->kbd_queue_has_data
= 1;
1758 current_kboard
= kb
;
1759 longjmp (wrong_kboard_jmpbuf
, 1);
1766 /* If in middle of key sequence and minibuffer not active,
1767 start echoing if enough time elapses. */
1769 if (minibuf_level
== 0 && !current_kboard
->immediate_echo
1770 && this_command_key_count
> 0
1772 && echo_keystrokes
> 0
1773 && (echo_area_glyphs
== 0 || *echo_area_glyphs
== 0))
1777 /* After a mouse event, start echoing right away.
1778 This is because we are probably about to display a menu,
1779 and we don't want to delay before doing so. */
1780 if (EVENT_HAS_PARAMETERS (prev_event
))
1784 save_getcjmp (save_jump
);
1785 restore_getcjmp (local_getcjmp
);
1786 tem0
= sit_for (echo_keystrokes
, 0, 1, 1);
1787 restore_getcjmp (save_jump
);
1793 /* Maybe auto save due to number of keystrokes. */
1795 if (commandflag
!= 0
1796 && auto_save_interval
> 0
1797 && num_nonmacro_input_chars
- last_auto_save
> max (auto_save_interval
, 20)
1798 && !detect_input_pending ())
1800 Fdo_auto_save (Qnil
, Qnil
);
1801 /* Hooks can actually change some buffers in auto save. */
1805 /* Try reading using an X menu.
1806 This is never confused with reading using the minibuf
1807 because the recursive call of read_char in read_char_minibuf_menu_prompt
1808 does not pass on any keymaps. */
1810 if (nmaps
> 0 && INTERACTIVE
1811 && !NILP (prev_event
)
1812 && EVENT_HAS_PARAMETERS (prev_event
)
1813 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
)
1814 /* Don't bring up a menu if we already have another event. */
1815 && NILP (Vunread_command_events
)
1816 && unread_command_char
< 0)
1817 c
= read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
1819 /* Maybe autosave and/or garbage collect due to idleness. */
1821 if (INTERACTIVE
&& NILP (c
))
1823 int delay_level
, buffer_size
;
1825 /* Slow down auto saves logarithmically in size of current buffer,
1826 and garbage collect while we're at it. */
1827 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
1828 last_non_minibuf_size
= Z
- BEG
;
1829 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
1831 while (buffer_size
> 64)
1832 delay_level
++, buffer_size
-= buffer_size
>> 2;
1833 if (delay_level
< 4) delay_level
= 4;
1834 /* delay_level is 4 for files under around 50k, 7 at 100k,
1835 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
1837 /* Auto save if enough time goes by without input. */
1838 if (commandflag
!= 0
1839 && num_nonmacro_input_chars
> last_auto_save
1840 && INTEGERP (Vauto_save_timeout
)
1841 && XINT (Vauto_save_timeout
) > 0)
1844 int delay
= delay_level
* XFASTINT (Vauto_save_timeout
) / 4;
1846 save_getcjmp (save_jump
);
1847 restore_getcjmp (local_getcjmp
);
1848 tem0
= sit_for (delay
, 0, 1, 1);
1849 restore_getcjmp (save_jump
);
1853 Fdo_auto_save (Qnil
, Qnil
);
1855 /* If we have auto-saved and there is still no input
1856 available, garbage collect if there has been enough
1857 consing going on to make it worthwhile. */
1858 if (!detect_input_pending ()
1859 && consing_since_gc
> gc_cons_threshold
/ 2)
1860 Fgarbage_collect ();
1867 /* Read something from current KBOARD's side queue, if possible. */
1871 if (current_kboard
->kbd_queue_has_data
)
1873 if (!CONSP (current_kboard
->kbd_queue
))
1875 c
= XCONS (current_kboard
->kbd_queue
)->car
;
1876 current_kboard
->kbd_queue
1877 = XCONS (current_kboard
->kbd_queue
)->cdr
;
1878 if (NILP (current_kboard
->kbd_queue
))
1879 current_kboard
->kbd_queue_has_data
= 0;
1880 input_pending
= readable_events ();
1882 if (EVENT_HAS_PARAMETERS (c
)
1883 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qswitch_frame
))
1884 internal_last_event_frame
= XCONS (XCONS (c
)->cdr
)->car
;
1885 Vlast_event_frame
= internal_last_event_frame
;
1891 /* If current_kboard's side queue is empty check the other kboards.
1892 If one of them has data that we have not yet seen here,
1893 switch to it and process the data waiting for it.
1895 Note: if the events queued up for another kboard
1896 have already been seen here, and therefore are not a complete command,
1897 the kbd_queue_has_data field is 0, so we skip that kboard here.
1898 That's to avoid an infinite loop switching between kboards here. */
1899 if (NILP (c
) && !single_kboard
)
1902 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
1903 if (kb
->kbd_queue_has_data
)
1905 current_kboard
= kb
;
1906 longjmp (wrong_kboard_jmpbuf
, 1);
1915 /* Finally, we read from the main queue,
1916 and if that gives us something we can't use yet, we put it on the
1917 appropriate side queue and try again. */
1923 /* Actually read a character, waiting if necessary. */
1924 save_getcjmp (save_jump
);
1925 restore_getcjmp (local_getcjmp
);
1926 c
= kbd_buffer_get_event (&kb
, used_mouse_menu
);
1927 restore_getcjmp (save_jump
);
1930 if (! NILP (c
) && (kb
!= current_kboard
))
1932 Lisp_Object
*tailp
= &kb
->kbd_queue
;
1933 while (CONSP (*tailp
))
1934 tailp
= &XCONS (*tailp
)->cdr
;
1937 *tailp
= Fcons (c
, Qnil
);
1938 kb
->kbd_queue_has_data
= 1;
1942 current_kboard
= kb
;
1943 longjmp (wrong_kboard_jmpbuf
, 1);
1948 /* Terminate Emacs in batch mode if at eof. */
1949 if (noninteractive
&& INTEGERP (c
) && XINT (c
) < 0)
1950 Fkill_emacs (make_number (1));
1954 /* Add in any extra modifiers, where appropriate. */
1955 if ((extra_keyboard_modifiers
& CHAR_CTL
)
1956 || ((extra_keyboard_modifiers
& 0177) < ' '
1957 && (extra_keyboard_modifiers
& 0177) != 0))
1958 XSETINT (c
, make_ctrl_char (XINT (c
)));
1960 /* Transfer any other modifier bits directly from
1961 extra_keyboard_modifiers to c. Ignore the actual character code
1962 in the low 16 bits of extra_keyboard_modifiers. */
1963 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
1972 if (commandflag
>= 0
1973 && !input_pending
&& !detect_input_pending ())
1981 /* Buffer switch events are only for internal wakeups
1982 so don't show them to the user. */
1986 if (key_already_recorded
)
1989 /* Wipe the echo area. */
1990 echo_area_glyphs
= 0;
1992 /* Handle things that only apply to characters. */
1995 /* If kbd_buffer_get_event gave us an EOF, return that. */
1999 if (STRINGP (Vkeyboard_translate_table
)
2000 && XSTRING (Vkeyboard_translate_table
)->size
> XFASTINT (c
))
2001 XSETINT (c
, XSTRING (Vkeyboard_translate_table
)->data
[XFASTINT (c
)]);
2004 /* If this event is a mouse click in the menu bar,
2005 return just menu-bar for now. Modify the mouse click event
2006 so we won't do this twice, then queue it up. */
2007 if (EVENT_HAS_PARAMETERS (c
)
2008 && CONSP (XCONS (c
)->cdr
)
2009 && CONSP (EVENT_START (c
))
2010 && CONSP (XCONS (EVENT_START (c
))->cdr
))
2014 posn
= POSN_BUFFER_POSN (EVENT_START (c
));
2015 /* Handle menu-bar events:
2016 insert the dummy prefix event `menu-bar'. */
2017 if (EQ (posn
, Qmenu_bar
))
2019 /* Change menu-bar to (menu-bar) as the event "position". */
2020 POSN_BUFFER_POSN (EVENT_START (c
)) = Fcons (posn
, Qnil
);
2023 Vunread_command_events
= Fcons (c
, Vunread_command_events
);
2029 if (! NILP (also_record
))
2030 record_char (also_record
);
2035 /* Don't echo mouse motion events. */
2037 && ! (EVENT_HAS_PARAMETERS (c
)
2038 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
2041 if (! NILP (also_record
))
2042 echo_char (also_record
);
2045 /* Record this character as part of the current key. */
2046 add_command_key (c
);
2047 if (! NILP (also_record
))
2048 add_command_key (also_record
);
2050 /* Re-reading in the middle of a command */
2052 last_input_char
= c
;
2055 /* Process the help character specially if enabled */
2056 if (!NILP (Vhelp_form
) && help_char_p (c
))
2059 count
= specpdl_ptr
- specpdl
;
2061 record_unwind_protect (Fset_window_configuration
,
2062 Fcurrent_window_configuration (Qnil
));
2064 tem0
= Feval (Vhelp_form
);
2066 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
2070 c
= read_char (0, 0, 0, Qnil
, 0);
2071 while (BUFFERP (c
));
2072 /* Remove the help from the frame */
2073 unbind_to (count
, Qnil
);
2076 if (EQ (c
, make_number (040)))
2080 c
= read_char (0, 0, 0, Qnil
, 0);
2081 while (BUFFERP (c
));
2088 /* Return 1 if should recognize C as "the help character". */
2096 if (EQ (c
, Vhelp_char
))
2098 for (tail
= Vhelp_event_list
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
2099 if (EQ (c
, XCONS (tail
)->car
))
2104 /* Record the input event C in various ways. */
2111 XVECTOR (recent_keys
)->contents
[recent_keys_index
] = c
;
2112 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
2113 recent_keys_index
= 0;
2115 /* Write c to the dribble file. If c is a lispy event, write
2116 the event's symbol to the dribble file, in <brackets>. Bleaugh.
2117 If you, dear reader, have a better idea, you've got the source. :-) */
2122 if (XUINT (c
) < 0x100)
2123 putc (XINT (c
), dribble
);
2125 fprintf (dribble
, " 0x%x", (int) XUINT (c
));
2129 Lisp_Object dribblee
;
2131 /* If it's a structured event, take the event header. */
2132 dribblee
= EVENT_HEAD (c
);
2134 if (SYMBOLP (dribblee
))
2136 putc ('<', dribble
);
2137 fwrite (XSYMBOL (dribblee
)->name
->data
, sizeof (char),
2138 XSYMBOL (dribblee
)->name
->size
,
2140 putc ('>', dribble
);
2147 store_kbd_macro_char (c
);
2149 num_nonmacro_input_chars
++;
2156 struct buffer
*old
= current_buffer
;
2157 Fprinc (object
, Qnil
);
2158 set_buffer_internal (XBUFFER (Vstandard_output
));
2159 call0 (intern ("help-mode"));
2160 set_buffer_internal (old
);
2164 /* Copy out or in the info on where C-g should throw to.
2165 This is used when running Lisp code from within get_char,
2166 in case get_char is called recursively.
2167 See read_process_output. */
2172 bcopy (getcjmp
, temp
, sizeof getcjmp
);
2175 restore_getcjmp (temp
)
2178 bcopy (temp
, getcjmp
, sizeof getcjmp
);
2183 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
2184 of this function. */
2187 tracking_off (old_value
)
2188 Lisp_Object old_value
;
2190 do_mouse_tracking
= old_value
;
2191 if (NILP (old_value
))
2193 /* Redisplay may have been preempted because there was input
2194 available, and it assumes it will be called again after the
2195 input has been processed. If the only input available was
2196 the sort that we have just disabled, then we need to call
2198 if (!readable_events ())
2200 redisplay_preserve_echo_area ();
2201 get_input_pending (&input_pending
);
2206 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
2207 "Evaluate BODY with mouse movement events enabled.\n\
2208 Within a `track-mouse' form, mouse motion generates input events that\n\
2209 you can read with `read-event'.\n\
2210 Normally, mouse motion is ignored.")
2214 int count
= specpdl_ptr
- specpdl
;
2217 record_unwind_protect (tracking_off
, do_mouse_tracking
);
2219 XSETFRAME (do_mouse_tracking
, selected_frame
);
2221 val
= Fprogn (args
);
2222 return unbind_to (count
, val
);
2225 #endif /* HAVE_MOUSE */
2227 /* Low level keyboard/mouse input.
2228 kbd_buffer_store_event places events in kbd_buffer, and
2229 kbd_buffer_get_event retrieves them.
2230 mouse_moved indicates when the mouse has moved again, and
2231 *mouse_position_hook provides the mouse position. */
2233 /* Return true iff there are any events in the queue that read-char
2234 would return. If this returns false, a read-char would block. */
2238 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2241 if (FRAMEP (do_mouse_tracking
) && mouse_moved
)
2246 if (current_kboard
->kbd_queue_has_data
)
2252 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2253 if (kb
->kbd_queue_has_data
)
2259 /* Set this for debugging, to have a way to get out */
2264 event_to_kboard (event
)
2265 struct input_event
*event
;
2268 frame
= event
->frame_or_window
;
2270 frame
= XCONS (frame
)->car
;
2271 else if (WINDOWP (frame
))
2272 frame
= WINDOW_FRAME (XWINDOW (frame
));
2274 /* There are still some events that don't set this field.
2275 For now, just ignore the problem.
2276 Also ignore dead frames here. */
2277 if (!FRAMEP (frame
) || !FRAME_LIVE_P (XFRAME (frame
)))
2280 return FRAME_KBOARD (XFRAME (frame
));
2284 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
2287 kbd_buffer_store_event (event
)
2288 register struct input_event
*event
;
2290 if (event
->kind
== no_event
)
2293 if (event
->kind
== ascii_keystroke
)
2295 register int c
= event
->code
& 0377;
2297 if (event
->modifiers
& ctrl_modifier
)
2298 c
= make_ctrl_char (c
);
2300 c
|= (event
->modifiers
2301 & (meta_modifier
| alt_modifier
2302 | hyper_modifier
| super_modifier
));
2306 extern SIGTYPE
interrupt_signal ();
2309 struct input_event
*sp
;
2312 && (kb
= FRAME_KBOARD (XFRAME (event
->frame_or_window
)),
2313 kb
!= current_kboard
))
2316 = Fcons (make_lispy_switch_frame (event
->frame_or_window
),
2317 Fcons (make_number (c
), Qnil
));
2318 kb
->kbd_queue_has_data
= 1;
2319 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
2321 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
2324 if (event_to_kboard (sp
) == kb
)
2326 sp
->kind
= no_event
;
2327 sp
->frame_or_window
= Qnil
;
2335 /* If this results in a quit_char being returned to Emacs as
2336 input, set Vlast_event_frame properly. If this doesn't
2337 get returned to Emacs as an event, the next event read
2338 will set Vlast_event_frame again, so this is safe to do. */
2342 focus
= FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
2344 focus
= event
->frame_or_window
;
2345 internal_last_event_frame
= focus
;
2346 Vlast_event_frame
= focus
;
2350 last_event_timestamp
= event
->timestamp
;
2351 interrupt_signal ();
2355 if (c
&& c
== stop_character
)
2362 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
2363 kbd_store_ptr
= kbd_buffer
;
2365 /* Don't let the very last slot in the buffer become full,
2366 since that would make the two pointers equal,
2367 and that is indistinguishable from an empty buffer.
2368 Discard the event if it would fill the last slot. */
2369 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
2371 volatile struct input_event
*sp
= kbd_store_ptr
;
2372 sp
->kind
= event
->kind
;
2373 if (event
->kind
== selection_request_event
)
2375 /* We must not use the ordinary copying code for this case,
2376 since `part' is an enum and copying it might not copy enough
2378 bcopy (event
, (char *) sp
, sizeof (*event
));
2382 sp
->code
= event
->code
;
2383 sp
->part
= event
->part
;
2384 sp
->frame_or_window
= event
->frame_or_window
;
2385 sp
->modifiers
= event
->modifiers
;
2388 sp
->timestamp
= event
->timestamp
;
2390 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_store_ptr
2392 = event
->frame_or_window
);
2398 /* Read one event from the event buffer, waiting if necessary.
2399 The value is a Lisp object representing the event.
2400 The value is nil for an event that should be ignored,
2401 or that was handled here.
2402 We always read and discard one event. */
2405 kbd_buffer_get_event (kbp
, used_mouse_menu
)
2407 int *used_mouse_menu
;
2416 *kbp
= current_kboard
;
2420 /* Wait until there is input available. */
2423 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2426 if (FRAMEP (do_mouse_tracking
) && mouse_moved
)
2430 /* If the quit flag is set, then read_char will return
2431 quit_char, so that counts as "available input." */
2432 if (!NILP (Vquit_flag
))
2433 quit_throw_to_read_char ();
2435 /* One way or another, wait until input is available; then, if
2436 interrupt handlers have not read it, read it now. */
2439 wait_for_kbd_input ();
2441 /* Note SIGIO has been undef'd if FIONREAD is missing. */
2445 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2448 if (FRAMEP (do_mouse_tracking
) && mouse_moved
)
2452 Lisp_Object minus_one
;
2454 XSETINT (minus_one
, -1);
2455 wait_reading_process_input (0, 0, minus_one
, 1);
2457 if (!interrupt_input
&& kbd_fetch_ptr
== kbd_store_ptr
)
2458 /* Pass 1 for EXPECT since we just waited to have input. */
2459 read_avail_input (1);
2461 #endif /* not VMS */
2464 /* At this point, we know that there is a readable event available
2465 somewhere. If the event queue is empty, then there must be a
2466 mouse movement enabled and available. */
2467 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2469 struct input_event
*event
;
2471 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2475 last_event_timestamp
= event
->timestamp
;
2478 *kbp
= event_to_kboard (event
);
2480 *kbp
= current_kboard
; /* Better than returning null ptr? */
2482 *kbp
= &the_only_kboard
;
2487 /* These two kinds of events get special handling
2488 and don't actually appear to the command loop.
2489 We return nil for them. */
2490 if (event
->kind
== selection_request_event
)
2493 struct input_event copy
;
2495 /* Remove it from the buffer before processing it,
2496 since otherwise swallow_events will see it
2497 and process it again. */
2499 kbd_fetch_ptr
= event
+ 1;
2500 x_handle_selection_request (©
);
2502 /* We're getting selection request events, but we don't have
2508 else if (event
->kind
== selection_clear_event
)
2511 x_handle_selection_clear (event
);
2512 kbd_fetch_ptr
= event
+ 1;
2514 /* We're getting selection request events, but we don't have
2520 else if (event
->kind
== delete_window_event
)
2522 /* Make an event (delete-frame (FRAME)). */
2523 obj
= Fcons (event
->frame_or_window
, Qnil
);
2524 obj
= Fcons (Qdelete_frame
, Fcons (obj
, Qnil
));
2525 kbd_fetch_ptr
= event
+ 1;
2527 else if (event
->kind
== iconify_event
)
2529 /* Make an event (iconify-frame (FRAME)). */
2530 obj
= Fcons (event
->frame_or_window
, Qnil
);
2531 obj
= Fcons (Qiconify_frame
, Fcons (obj
, Qnil
));
2532 kbd_fetch_ptr
= event
+ 1;
2534 else if (event
->kind
== deiconify_event
)
2536 /* Make an event (make-frame-visible (FRAME)). */
2537 obj
= Fcons (event
->frame_or_window
, Qnil
);
2538 obj
= Fcons (Qmake_frame_visible
, Fcons (obj
, Qnil
));
2539 kbd_fetch_ptr
= event
+ 1;
2542 else if (event
->kind
== buffer_switch_event
)
2544 /* The value doesn't matter here; only the type is tested. */
2545 XSETBUFFER (obj
, current_buffer
);
2546 kbd_fetch_ptr
= event
+ 1;
2548 /* Just discard these, by returning nil.
2549 With MULTI_KBOARD, these events are used as placeholders
2550 when we need to randomly delete events from the queue.
2551 (They shouldn't otherwise be found in the buffer,
2552 but on some machines it appears they do show up
2553 even without MULTI_KBOARD.) */
2554 else if (event
->kind
== no_event
)
2555 kbd_fetch_ptr
= event
+ 1;
2557 /* If this event is on a different frame, return a switch-frame this
2558 time, and leave the event in the queue for next time. */
2565 frame
= event
->frame_or_window
;
2567 frame
= XCONS (frame
)->car
;
2568 else if (WINDOWP (frame
))
2569 frame
= WINDOW_FRAME (XWINDOW (frame
));
2571 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
2575 if (! EQ (frame
, internal_last_event_frame
)
2576 && XFRAME (frame
) != selected_frame
)
2577 obj
= make_lispy_switch_frame (frame
);
2578 internal_last_event_frame
= frame
;
2579 #endif /* MULTI_FRAME */
2581 /* If we didn't decide to make a switch-frame event, go ahead
2582 and build a real event from the queue entry. */
2586 obj
= make_lispy_event (event
);
2587 #ifdef USE_X_TOOLKIT
2588 /* If this was a menu selection, then set the flag to inhibit
2589 writing to last_nonmenu_event. Don't do this if the event
2590 we're returning is (menu-bar), though; that indicates the
2591 beginning of the menu sequence, and we might as well leave
2592 that as the `event with parameters' for this selection. */
2593 if (event
->kind
== menu_bar_event
2594 && !(CONSP (obj
) && EQ (XCONS (obj
)->car
, Qmenu_bar
))
2596 *used_mouse_menu
= 1;
2599 /* Wipe out this event, to catch bugs. */
2600 event
->kind
= no_event
;
2601 XVECTOR (kbd_buffer_frame_or_window
)->contents
[event
- kbd_buffer
] = Qnil
;
2603 kbd_fetch_ptr
= event
+ 1;
2608 /* Try generating a mouse motion event. */
2609 else if (FRAMEP (do_mouse_tracking
) && mouse_moved
)
2611 FRAME_PTR f
= XFRAME (do_mouse_tracking
);
2612 Lisp_Object bar_window
;
2613 enum scroll_bar_part part
;
2617 *kbp
= current_kboard
;
2618 /* Note that this uses F to determine which display to look at.
2619 If there is no valid info, it does not store anything
2620 so x remains nil. */
2622 (*mouse_position_hook
) (&f
, 0, &bar_window
, &part
, &x
, &y
, &time
);
2627 /* Decide if we should generate a switch-frame event. Don't
2628 generate switch-frame events for motion outside of all Emacs
2634 frame
= FRAME_FOCUS_FRAME (f
);
2636 XSETFRAME (frame
, f
);
2638 if (! EQ (frame
, internal_last_event_frame
)
2639 && XFRAME (frame
) != selected_frame
)
2640 obj
= make_lispy_switch_frame (frame
);
2641 internal_last_event_frame
= frame
;
2645 /* If we didn't decide to make a switch-frame event, go ahead and
2646 return a mouse-motion event. */
2647 if (!NILP (x
) && NILP (obj
))
2648 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
2650 #endif /* HAVE_MOUSE */
2652 /* We were promised by the above while loop that there was
2653 something for us to read! */
2656 input_pending
= readable_events ();
2659 Vlast_event_frame
= internal_last_event_frame
;
2665 /* Process any events that are not user-visible,
2666 then return, without reading any user-visible events. */
2671 while (kbd_fetch_ptr
!= kbd_store_ptr
)
2673 struct input_event
*event
;
2675 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2679 last_event_timestamp
= event
->timestamp
;
2681 /* These two kinds of events get special handling
2682 and don't actually appear to the command loop. */
2683 if (event
->kind
== selection_request_event
)
2686 struct input_event copy
;
2688 kbd_fetch_ptr
= event
+ 1;
2689 x_handle_selection_request (©
);
2691 /* We're getting selection request events, but we don't have
2697 else if (event
->kind
== selection_clear_event
)
2700 x_handle_selection_clear (event
);
2701 kbd_fetch_ptr
= event
+ 1;
2703 /* We're getting selection request events, but we don't have
2712 get_input_pending (&input_pending
);
2715 /* Caches for modify_event_symbol. */
2716 static Lisp_Object accent_key_syms
;
2717 static Lisp_Object system_key_syms
;
2718 static Lisp_Object func_key_syms
;
2719 static Lisp_Object mouse_syms
;
2721 /* This is a list of keysym codes for special "accent" characters.
2722 It parallels lispy_accent_keys. */
2724 static int lispy_accent_codes
[] =
2726 #ifdef XK_dead_circumflex
2731 #ifdef XK_dead_grave
2736 #ifdef XK_dead_tilde
2741 #ifdef XK_dead_diaeresis
2746 #ifdef XK_dead_macron
2751 #ifdef XK_dead_degree
2756 #ifdef XK_dead_acute
2761 #ifdef XK_dead_cedilla
2766 #ifdef XK_dead_breve
2771 #ifdef XK_dead_ogonek
2776 #ifdef XK_dead_caron
2781 #ifdef XK_dead_doubleacute
2782 XK_dead_doubleacute
,
2786 #ifdef XK_dead_abovedot
2793 /* This is a list of Lisp names for special "accent" characters.
2794 It parallels lispy_accent_codes. */
2796 static char *lispy_accent_keys
[] =
2813 /* You'll notice that this table is arranged to be conveniently
2814 indexed by X Windows keysym values. */
2815 static char *lispy_function_keys
[] =
2817 /* X Keysym value */
2819 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00 */
2827 0, 0, 0, /* 0xff10 */
2829 0, 0, 0, 0, 0, 0, 0,
2832 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff20...2f */
2833 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff30...3f */
2834 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
2836 "home", /* 0xff50 */ /* IsCursorKey */
2847 "select", /* 0xff60 */ /* IsMiscFunctionKey */
2858 "break", /* 0xff6b */
2860 0, 0, 0, 0, 0, 0, 0, 0, "backtab", 0,
2862 0, 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff7f */
2863 "kp-space", /* 0xff80 */ /* IsKeypadKey */
2864 0, 0, 0, 0, 0, 0, 0, 0,
2865 "kp-tab", /* 0xff89 */
2867 "kp-enter", /* 0xff8d */
2869 "kp-f1", /* 0xff91 */
2873 "kp-home", /* 0xff95 */
2878 "kp-prior", /* kp-page-up */
2879 "kp-next", /* kp-page-down */
2885 0, 0, 0, 0, 0, 0, 0, 0, 0,
2886 "kp-multiply", /* 0xffaa */
2891 "kp-divide", /* 0xffaf */
2892 "kp-0", /* 0xffb0 */
2893 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
2896 "kp-equal", /* 0xffbd */
2897 "f1", /* 0xffbe */ /* IsFunctionKey */
2899 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
2900 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
2901 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
2902 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
2903 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
2904 0, 0, 0, 0, 0, 0, 0, 0,
2905 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
2906 0, 0, 0, 0, 0, 0, 0, "delete"
2909 static char *lispy_mouse_names
[] =
2911 "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5"
2914 /* Scroll bar parts. */
2915 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
2917 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
2918 Lisp_Object
*scroll_bar_parts
[] = {
2919 &Qabove_handle
, &Qhandle
, &Qbelow_handle
2923 /* A vector, indexed by button number, giving the down-going location
2924 of currently depressed buttons, both scroll bar and non-scroll bar.
2926 The elements have the form
2927 (BUTTON-NUMBER MODIFIER-MASK . REST)
2928 where REST is the cdr of a position as it would be reported in the event.
2930 The make_lispy_event function stores positions here to tell the
2931 difference between click and drag events, and to store the starting
2932 location to be included in drag events. */
2934 static Lisp_Object button_down_location
;
2936 /* Information about the most recent up-going button event: Which
2937 button, what location, and what time. */
2939 static int last_mouse_button
;
2940 static int last_mouse_x
;
2941 static int last_mouse_y
;
2942 static unsigned long button_down_time
;
2944 /* The maximum time between clicks to make a double-click,
2945 or Qnil to disable double-click detection,
2946 or Qt for no time limit. */
2947 Lisp_Object Vdouble_click_time
;
2949 /* The number of clicks in this multiple-click. */
2951 int double_click_count
;
2953 /* Given a struct input_event, build the lisp event which represents
2954 it. If EVENT is 0, build a mouse movement event from the mouse
2955 movement buffer, which should have a movement event in it.
2957 Note that events must be passed to this function in the order they
2958 are received; this function stores the location of button presses
2959 in order to build drag events when the button is released. */
2962 make_lispy_event (event
)
2963 struct input_event
*event
;
2967 switch (SWITCH_ENUM_CAST (event
->kind
))
2969 /* A simple keystroke. */
2970 case ascii_keystroke
:
2972 Lisp_Object lispy_c
;
2973 int c
= event
->code
& 0377;
2974 /* Turn ASCII characters into control characters
2976 if (event
->modifiers
& ctrl_modifier
)
2977 c
= make_ctrl_char (c
);
2979 /* Add in the other modifier bits. We took care of ctrl_modifier
2980 just above, and the shift key was taken care of by the X code,
2981 and applied to control characters by make_ctrl_char. */
2982 c
|= (event
->modifiers
2983 & (meta_modifier
| alt_modifier
2984 | hyper_modifier
| super_modifier
));
2985 button_down_time
= 0;
2986 XSETFASTINT (lispy_c
, c
);
2990 /* A function key. The symbol may need to have modifier prefixes
2992 case non_ascii_keystroke
:
2993 button_down_time
= 0;
2995 for (i
= 0; i
< sizeof (lispy_accent_codes
) / sizeof (int); i
++)
2996 if (event
->code
== lispy_accent_codes
[i
])
2997 return modify_event_symbol (i
,
2999 Qfunction_key
, Qnil
,
3000 lispy_accent_keys
, &accent_key_syms
,
3001 (sizeof (lispy_accent_keys
)
3002 / sizeof (lispy_accent_keys
[0])));
3004 /* Handle system-specific keysyms. */
3005 if (event
->code
& (1 << 28))
3007 /* We need to use an alist rather than a vector as the cache
3008 since we can't make a vector long enuf. */
3009 if (NILP (system_key_syms
))
3010 system_key_syms
= Fcons (Qnil
, Qnil
);
3011 return modify_event_symbol (event
->code
& 0xffffff,
3014 current_kboard
->Vsystem_key_alist
,
3015 0, &system_key_syms
, 0xffffff);
3018 return modify_event_symbol (event
->code
- 0xff00,
3020 Qfunction_key
, Qnil
,
3021 lispy_function_keys
, &func_key_syms
,
3022 (sizeof (lispy_function_keys
)
3023 / sizeof (lispy_function_keys
[0])));
3027 /* A mouse click. Figure out where it is, decide whether it's
3028 a press, click or drag, and build the appropriate structure. */
3030 case scroll_bar_click
:
3032 int button
= event
->code
;
3034 Lisp_Object position
;
3035 Lisp_Object
*start_pos_ptr
;
3036 Lisp_Object start_pos
;
3038 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
3041 /* Build the position as appropriate for this mouse click. */
3042 if (event
->kind
== mouse_click
)
3045 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
3050 /* Ignore mouse events that were made on frame that
3051 have been deleted. */
3052 if (! FRAME_LIVE_P (f
))
3055 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
3056 &column
, &row
, NULL
, 1);
3058 #ifndef USE_X_TOOLKIT
3059 /* In the non-toolkit version, clicks on the menu bar
3060 are ordinary button events in the event buffer.
3061 Distinguish them, and invoke the menu.
3063 (In the toolkit version, the toolkit handles the menu bar
3064 and Emacs doesn't know about it until after the user
3065 makes a selection.) */
3066 if (row
>= 0 && row
< FRAME_MENU_BAR_LINES (f
))
3068 Lisp_Object items
, item
;
3072 /* Activate the menu bar on the down event. If the
3073 up event comes in before the menu code can deal with it,
3075 if (! (event
->modifiers
& down_modifier
))
3079 items
= FRAME_MENU_BAR_ITEMS (f
);
3080 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 3)
3082 Lisp_Object pos
, string
;
3083 string
= XVECTOR (items
)->contents
[i
+ 1];
3084 pos
= XVECTOR (items
)->contents
[i
+ 2];
3087 if (column
>= XINT (pos
)
3088 && column
< XINT (pos
) + XSTRING (string
)->size
)
3090 item
= XVECTOR (items
)->contents
[i
];
3096 = Fcons (event
->frame_or_window
,
3098 Fcons (Fcons (event
->x
, event
->y
),
3099 Fcons (make_number (event
->timestamp
),
3102 return Fcons (item
, Fcons (position
, Qnil
));
3104 #endif /* not USE_X_TOOLKIT */
3106 window
= window_from_coordinates (f
, column
, row
, &part
);
3108 if (!WINDOWP (window
))
3110 window
= event
->frame_or_window
;
3115 int pixcolumn
, pixrow
;
3116 column
-= XINT (XWINDOW (window
)->left
);
3117 row
-= XINT (XWINDOW (window
)->top
);
3118 glyph_to_pixel_coords (f
, column
, row
, &pixcolumn
, &pixrow
);
3119 XSETINT (event
->x
, pixcolumn
);
3120 XSETINT (event
->y
, pixrow
);
3125 posn
= Qvertical_line
;
3128 buffer_posn_from_coords (XWINDOW (window
),
3135 Fcons (Fcons (event
->x
, event
->y
),
3136 Fcons (make_number (event
->timestamp
),
3142 Lisp_Object portion_whole
;
3145 window
= event
->frame_or_window
;
3146 portion_whole
= Fcons (event
->x
, event
->y
);
3147 part
= *scroll_bar_parts
[(int) event
->part
];
3151 Fcons (Qvertical_scroll_bar
,
3152 Fcons (portion_whole
,
3153 Fcons (make_number (event
->timestamp
),
3154 Fcons (part
, Qnil
)))));
3157 start_pos_ptr
= &XVECTOR (button_down_location
)->contents
[button
];
3159 start_pos
= *start_pos_ptr
;
3160 *start_pos_ptr
= Qnil
;
3162 is_double
= (button
== last_mouse_button
3163 && XINT (event
->x
) == last_mouse_x
3164 && XINT (event
->y
) == last_mouse_y
3165 && button_down_time
!= 0
3166 && (EQ (Vdouble_click_time
, Qt
)
3167 || (INTEGERP (Vdouble_click_time
)
3168 && ((int)(event
->timestamp
- button_down_time
)
3169 < XINT (Vdouble_click_time
)))));
3170 last_mouse_button
= button
;
3171 last_mouse_x
= XINT (event
->x
);
3172 last_mouse_y
= XINT (event
->y
);
3174 /* If this is a button press, squirrel away the location, so
3175 we can decide later whether it was a click or a drag. */
3176 if (event
->modifiers
& down_modifier
)
3180 double_click_count
++;
3181 event
->modifiers
|= ((double_click_count
> 2)
3186 double_click_count
= 1;
3187 button_down_time
= event
->timestamp
;
3188 *start_pos_ptr
= Fcopy_alist (position
);
3191 /* Now we're releasing a button - check the co-ordinates to
3192 see if this was a click or a drag. */
3193 else if (event
->modifiers
& up_modifier
)
3195 /* If we did not see a down before this up,
3196 ignore the up. Probably this happened because
3197 the down event chose a menu item.
3198 It would be an annoyance to treat the release
3199 of the button that chose the menu item
3200 as a separate event. */
3202 if (!CONSP (start_pos
))
3205 event
->modifiers
&= ~up_modifier
;
3206 #if 0 /* Formerly we treated an up with no down as a click event. */
3207 if (!CONSP (start_pos
))
3208 event
->modifiers
|= click_modifier
;
3212 /* The third element of every position should be the (x,y)
3216 down
= Fnth (make_number (2), start_pos
);
3217 if (EQ (event
->x
, XCONS (down
)->car
)
3218 && EQ (event
->y
, XCONS (down
)->cdr
))
3220 event
->modifiers
|= click_modifier
;
3224 button_down_time
= 0;
3225 event
->modifiers
|= drag_modifier
;
3227 /* Don't check is_double; treat this as multiple
3228 if the down-event was multiple. */
3229 if (double_click_count
> 1)
3230 event
->modifiers
|= ((double_click_count
> 2)
3236 /* Every mouse event should either have the down_modifier or
3237 the up_modifier set. */
3241 /* Get the symbol we should use for the mouse click. */
3244 head
= modify_event_symbol (button
,
3247 lispy_mouse_names
, &mouse_syms
,
3248 (sizeof (lispy_mouse_names
)
3249 / sizeof (lispy_mouse_names
[0])));
3250 if (event
->modifiers
& drag_modifier
)
3255 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
3258 Fcons (make_number (double_click_count
),
3266 #endif /* HAVE_MOUSE */
3268 #ifdef USE_X_TOOLKIT
3269 case menu_bar_event
:
3270 /* The event value is in the cdr of the frame_or_window slot. */
3271 if (!CONSP (event
->frame_or_window
))
3273 return XCONS (event
->frame_or_window
)->cdr
;
3276 /* The 'kind' field of the event is something we don't recognize. */
3285 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
3287 Lisp_Object bar_window
;
3288 enum scroll_bar_part part
;
3293 /* Is it a scroll bar movement? */
3294 if (frame
&& ! NILP (bar_window
))
3296 Lisp_Object part_sym
;
3298 part_sym
= *scroll_bar_parts
[(int) part
];
3299 return Fcons (Qscroll_bar_movement
,
3300 (Fcons (Fcons (bar_window
,
3301 Fcons (Qvertical_scroll_bar
,
3302 Fcons (Fcons (x
, y
),
3303 Fcons (make_number (time
),
3309 /* Or is it an ordinary mouse movement? */
3311 #endif /* MULTI_FRAME */
3324 /* It's in a frame; which window on that frame? */
3325 pixel_to_glyph_coords (frame
, XINT (x
), XINT (y
), &column
, &row
,
3327 window
= window_from_coordinates (frame
, column
, row
, &area
);
3332 if (WINDOWP (window
))
3334 int pixcolumn
, pixrow
;
3335 column
-= XINT (XWINDOW (window
)->left
);
3336 row
-= XINT (XWINDOW (window
)->top
);
3337 glyph_to_pixel_coords (frame
, column
, row
, &pixcolumn
, &pixrow
);
3338 XSETINT (x
, pixcolumn
);
3339 XSETINT (y
, pixrow
);
3344 posn
= Qvertical_line
;
3347 buffer_posn_from_coords (XWINDOW (window
), column
, row
));
3350 else if (frame
!= 0)
3352 XSETFRAME (window
, frame
);
3364 return Fcons (Qmouse_movement
,
3365 Fcons (Fcons (window
,
3367 Fcons (Fcons (x
, y
),
3368 Fcons (make_number (time
),
3374 #endif /* HAVE_MOUSE */
3376 /* Construct a switch frame event. */
3378 make_lispy_switch_frame (frame
)
3381 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
3384 /* Manipulating modifiers. */
3386 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
3388 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
3389 SYMBOL's name of the end of the modifiers; the string from this
3390 position is the unmodified symbol name.
3392 This doesn't use any caches. */
3395 parse_modifiers_uncached (symbol
, modifier_end
)
3399 struct Lisp_String
*name
;
3403 CHECK_SYMBOL (symbol
, 1);
3406 name
= XSYMBOL (symbol
)->name
;
3408 for (i
= 0; i
+2 <= name
->size
; )
3410 int this_mod_end
= 0;
3413 /* See if the name continues with a modifier word.
3414 Check that the word appears, but don't check what follows it.
3415 Set this_mod and this_mod_end to record what we find. */
3417 switch (name
->data
[i
])
3419 #define SINGLE_LETTER_MOD(BIT) \
3420 (this_mod_end = i + 1, this_mod = BIT)
3423 SINGLE_LETTER_MOD (alt_modifier
);
3427 SINGLE_LETTER_MOD (ctrl_modifier
);
3431 SINGLE_LETTER_MOD (hyper_modifier
);
3435 SINGLE_LETTER_MOD (meta_modifier
);
3439 SINGLE_LETTER_MOD (shift_modifier
);
3443 SINGLE_LETTER_MOD (super_modifier
);
3446 #undef SINGLE_LETTER_MOD
3449 /* If we found no modifier, stop looking for them. */
3450 if (this_mod_end
== 0)
3453 /* Check there is a dash after the modifier, so that it
3454 really is a modifier. */
3455 if (this_mod_end
>= name
->size
|| name
->data
[this_mod_end
] != '-')
3458 /* This modifier is real; look for another. */
3459 modifiers
|= this_mod
;
3460 i
= this_mod_end
+ 1;
3463 /* Should we include the `click' modifier? */
3464 if (! (modifiers
& (down_modifier
| drag_modifier
3465 | double_modifier
| triple_modifier
))
3466 && i
+ 7 == name
->size
3467 && strncmp (name
->data
+ i
, "mouse-", 6) == 0
3468 && ('0' <= name
->data
[i
+ 6] && name
->data
[i
+ 6] <= '9'))
3469 modifiers
|= click_modifier
;
3477 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
3478 prepended to the string BASE[0..BASE_LEN-1].
3479 This doesn't use any caches. */
3481 apply_modifiers_uncached (modifiers
, base
, base_len
)
3486 /* Since BASE could contain nulls, we can't use intern here; we have
3487 to use Fintern, which expects a genuine Lisp_String, and keeps a
3490 (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
3496 /* Only the event queue may use the `up' modifier; it should always
3497 be turned into a click or drag event before presented to lisp code. */
3498 if (modifiers
& up_modifier
)
3501 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
3502 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
3503 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
3504 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
3505 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
3506 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
3507 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
3508 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
3509 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
3510 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
3511 /* The click modifier is denoted by the absence of other modifiers. */
3515 mod_len
= p
- new_mods
;
3519 Lisp_Object new_name
;
3521 new_name
= make_uninit_string (mod_len
+ base_len
);
3522 bcopy (new_mods
, XSTRING (new_name
)->data
, mod_len
);
3523 bcopy (base
, XSTRING (new_name
)->data
+ mod_len
, base_len
);
3525 return Fintern (new_name
, Qnil
);
3530 static char *modifier_names
[] =
3532 "up", "down", "drag", "click", "double", "triple", 0, 0,
3533 0, 0, 0, 0, 0, 0, 0, 0,
3534 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
3536 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
3538 static Lisp_Object modifier_symbols
;
3540 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
3542 lispy_modifier_list (modifiers
)
3545 Lisp_Object modifier_list
;
3548 modifier_list
= Qnil
;
3549 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
3550 if (modifiers
& (1<<i
))
3551 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
3554 return modifier_list
;
3558 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
3559 where UNMODIFIED is the unmodified form of SYMBOL,
3560 MASK is the set of modifiers present in SYMBOL's name.
3561 This is similar to parse_modifiers_uncached, but uses the cache in
3562 SYMBOL's Qevent_symbol_element_mask property, and maintains the
3563 Qevent_symbol_elements property. */
3566 parse_modifiers (symbol
)
3569 Lisp_Object elements
;
3571 elements
= Fget (symbol
, Qevent_symbol_element_mask
);
3572 if (CONSP (elements
))
3577 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
3578 Lisp_Object unmodified
;
3581 unmodified
= Fintern (make_string (XSYMBOL (symbol
)->name
->data
+ end
,
3582 XSYMBOL (symbol
)->name
->size
- end
),
3585 if (modifiers
& ~(((EMACS_INT
)1 << VALBITS
) - 1))
3587 XSETFASTINT (mask
, modifiers
);
3588 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
3590 /* Cache the parsing results on SYMBOL. */
3591 Fput (symbol
, Qevent_symbol_element_mask
,
3593 Fput (symbol
, Qevent_symbol_elements
,
3594 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
3596 /* Since we know that SYMBOL is modifiers applied to unmodified,
3597 it would be nice to put that in unmodified's cache.
3598 But we can't, since we're not sure that parse_modifiers is
3605 /* Apply the modifiers MODIFIERS to the symbol BASE.
3606 BASE must be unmodified.
3608 This is like apply_modifiers_uncached, but uses BASE's
3609 Qmodifier_cache property, if present. It also builds
3610 Qevent_symbol_elements properties, since it has that info anyway.
3612 apply_modifiers copies the value of BASE's Qevent_kind property to
3613 the modified symbol. */
3615 apply_modifiers (modifiers
, base
)
3619 Lisp_Object cache
, index
, entry
, new_symbol
;
3621 /* Mask out upper bits. We don't know where this value's been. */
3622 modifiers
&= ((EMACS_INT
)1 << VALBITS
) - 1;
3624 /* The click modifier never figures into cache indices. */
3625 cache
= Fget (base
, Qmodifier_cache
);
3626 XSETFASTINT (index
, (modifiers
& ~click_modifier
));
3627 entry
= assq_no_quit (index
, cache
);
3630 new_symbol
= XCONS (entry
)->cdr
;
3633 /* We have to create the symbol ourselves. */
3634 new_symbol
= apply_modifiers_uncached (modifiers
,
3635 XSYMBOL (base
)->name
->data
,
3636 XSYMBOL (base
)->name
->size
);
3638 /* Add the new symbol to the base's cache. */
3639 entry
= Fcons (index
, new_symbol
);
3640 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
3642 /* We have the parsing info now for free, so add it to the caches. */
3643 XSETFASTINT (index
, modifiers
);
3644 Fput (new_symbol
, Qevent_symbol_element_mask
,
3645 Fcons (base
, Fcons (index
, Qnil
)));
3646 Fput (new_symbol
, Qevent_symbol_elements
,
3647 Fcons (base
, lispy_modifier_list (modifiers
)));
3650 /* Make sure this symbol is of the same kind as BASE.
3652 You'd think we could just set this once and for all when we
3653 intern the symbol above, but reorder_modifiers may call us when
3654 BASE's property isn't set right; we can't assume that just
3655 because it has a Qmodifier_cache property it must have its
3656 Qevent_kind set right as well. */
3657 if (NILP (Fget (new_symbol
, Qevent_kind
)))
3661 kind
= Fget (base
, Qevent_kind
);
3663 Fput (new_symbol
, Qevent_kind
, kind
);
3670 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
3671 return a symbol with the modifiers placed in the canonical order.
3672 Canonical order is alphabetical, except for down and drag, which
3673 always come last. The 'click' modifier is never written out.
3675 Fdefine_key calls this to make sure that (for example) C-M-foo
3676 and M-C-foo end up being equivalent in the keymap. */
3679 reorder_modifiers (symbol
)
3682 /* It's hopefully okay to write the code this way, since everything
3683 will soon be in caches, and no consing will be done at all. */
3686 parsed
= parse_modifiers (symbol
);
3687 return apply_modifiers ((int) XINT (XCONS (XCONS (parsed
)->cdr
)->car
),
3688 XCONS (parsed
)->car
);
3692 /* For handling events, we often want to produce a symbol whose name
3693 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
3694 to some base, like the name of a function key or mouse button.
3695 modify_event_symbol produces symbols of this sort.
3697 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
3698 is the name of the i'th symbol. TABLE_SIZE is the number of elements
3701 Alternatively, NAME_ALIST is an alist mapping codes into symbol names.
3702 NAME_ALIST is used if it is non-nil; otherwise NAME_TABLE is used.
3704 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
3705 persist between calls to modify_event_symbol that it can use to
3706 store a cache of the symbols it's generated for this NAME_TABLE
3707 before. The object stored there may be a vector or an alist.
3709 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
3711 MODIFIERS is a set of modifier bits (as given in struct input_events)
3712 whose prefixes should be applied to the symbol name.
3714 SYMBOL_KIND is the value to be placed in the event_kind property of
3715 the returned symbol.
3717 The symbols we create are supposed to have an
3718 `event-symbol-elements' property, which lists the modifiers present
3719 in the symbol's name. */
3722 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_alist
,
3723 name_table
, symbol_table
, table_size
)
3726 Lisp_Object symbol_kind
;
3727 Lisp_Object name_alist
;
3729 Lisp_Object
*symbol_table
;
3733 Lisp_Object symbol_int
;
3735 XSETINT (symbol_int
, symbol_num
);
3737 /* Is this a request for a valid symbol? */
3738 if (symbol_num
< 0 || symbol_num
>= table_size
)
3741 if (CONSP (*symbol_table
))
3742 value
= Fcdr (assq_no_quit (symbol_int
, *symbol_table
));
3744 /* If *symbol_table doesn't seem to be initialized properly, fix that.
3745 *symbol_table should be a lisp vector TABLE_SIZE elements long,
3746 where the Nth element is the symbol for NAME_TABLE[N], or nil if
3747 we've never used that symbol before. */
3750 if (! VECTORP (*symbol_table
)
3751 || XVECTOR (*symbol_table
)->size
!= table_size
)
3755 XSETFASTINT (size
, table_size
);
3756 *symbol_table
= Fmake_vector (size
, Qnil
);
3759 value
= XVECTOR (*symbol_table
)->contents
[symbol_num
];
3762 /* Have we already used this symbol before? */
3765 /* No; let's create it. */
3766 if (!NILP (name_alist
))
3767 value
= Fcdr_safe (Fassq (symbol_int
, name_alist
));
3768 else if (name_table
[symbol_num
])
3769 value
= intern (name_table
[symbol_num
]);
3774 sprintf (buf
, "key-%d", symbol_num
);
3775 value
= intern (buf
);
3778 if (CONSP (*symbol_table
))
3779 *symbol_table
= Fcons (value
, *symbol_table
);
3781 XVECTOR (*symbol_table
)->contents
[symbol_num
] = value
;
3783 /* Fill in the cache entries for this symbol; this also
3784 builds the Qevent_symbol_elements property, which the user
3786 apply_modifiers (modifiers
& click_modifier
, value
);
3787 Fput (value
, Qevent_kind
, symbol_kind
);
3790 /* Apply modifiers to that symbol. */
3791 return apply_modifiers (modifiers
, value
);
3794 /* Convert a list that represents an event type,
3795 such as (ctrl meta backspace), into the usual representation of that
3796 event type as a number or a symbol. */
3798 DEFUN ("event-convert-list", Fevent_convert_list
, Sevent_convert_list
, 1, 1, 0,
3799 "Convert the event description LIST to an event type.\n\
3800 LIST should contain one base event type (a character or symbol)\n\
3801 and zero or more modifier names (control, meta, hyper, super, shift, alt,\n\
3802 drag, down, double or triple).\n\
3803 The return value is an event type (a character or symbol) which\n\
3804 has the same base event type and all the specified modifiers.")
3814 while (CONSP (rest
))
3819 elt
= XCONS (rest
)->car
;
3821 /* Given a symbol, see if it is a modifier name. */
3823 this = parse_solitary_modifier (elt
);
3827 else if (!NILP (base
))
3828 error ("Two bases given in one event");
3832 rest
= XCONS (rest
)->cdr
;
3835 /* Let the symbol A refer to the character A. */
3836 if (SYMBOLP (base
) && XSYMBOL (base
)->name
->size
== 1)
3837 XSETINT (base
, XSYMBOL (base
)->name
->data
[0]);
3839 if (INTEGERP (base
))
3841 /* Turn (shift a) into A. */
3842 if ((modifiers
& shift_modifier
) != 0
3843 && (XINT (base
) >= 'a' && XINT (base
) <= 'z'))
3845 XSETINT (base
, XINT (base
) - ('a' - 'A'));
3846 modifiers
&= ~shift_modifier
;
3849 /* Turn (control a) into C-a. */
3850 if (modifiers
& ctrl_modifier
)
3851 return make_number ((modifiers
& ~ctrl_modifier
)
3852 | make_ctrl_char (XINT (base
)));
3854 return make_number (modifiers
| XINT (base
));
3856 else if (SYMBOLP (base
))
3857 return apply_modifiers (modifiers
, base
);
3859 error ("Invalid base event");
3862 /* Try to recognize SYMBOL as a modifier name.
3863 Return the modifier flag bit, or 0 if not recognized. */
3866 parse_solitary_modifier (symbol
)
3869 struct Lisp_String
*name
= XSYMBOL (symbol
)->name
;
3871 switch (name
->data
[0])
3873 #define SINGLE_LETTER_MOD(BIT) \
3874 if (name->size == 1) \
3877 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
3878 if (LEN == name->size \
3879 && ! strncmp (name->data, NAME, LEN)) \
3883 SINGLE_LETTER_MOD (alt_modifier
);
3887 MULTI_LETTER_MOD (alt_modifier
, "alt", 3);
3891 SINGLE_LETTER_MOD (ctrl_modifier
);
3895 MULTI_LETTER_MOD (ctrl_modifier
, "ctrl", 4);
3896 MULTI_LETTER_MOD (ctrl_modifier
, "control", 7);
3900 SINGLE_LETTER_MOD (hyper_modifier
);
3904 MULTI_LETTER_MOD (hyper_modifier
, "hyper", 5);
3908 SINGLE_LETTER_MOD (meta_modifier
);
3912 MULTI_LETTER_MOD (meta_modifier
, "meta", 4);
3916 SINGLE_LETTER_MOD (shift_modifier
);
3920 MULTI_LETTER_MOD (shift_modifier
, "shift", 5);
3921 MULTI_LETTER_MOD (super_modifier
, "super", 5);
3922 SINGLE_LETTER_MOD (super_modifier
);
3926 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
3927 MULTI_LETTER_MOD (down_modifier
, "down", 4);
3928 MULTI_LETTER_MOD (double_modifier
, "double", 6);
3932 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
3935 #undef SINGLE_LETTER_MOD
3936 #undef MULTI_LETTER_MOD
3942 /* Return 1 if EVENT is a list whose elements are all integers or symbols.
3943 Such a list is not valid as an event,
3944 but it can be a Lucid-style event type list. */
3947 lucid_event_type_list_p (object
)
3952 if (! CONSP (object
))
3955 for (tail
= object
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
3958 elt
= XCONS (tail
)->car
;
3959 if (! (INTEGERP (elt
) || SYMBOLP (elt
)))
3966 /* Store into *addr a value nonzero if terminal input chars are available.
3967 Serves the purpose of ioctl (0, FIONREAD, addr)
3968 but works even if FIONREAD does not exist.
3969 (In fact, this may actually read some input.) */
3972 get_input_pending (addr
)
3975 /* First of all, have we already counted some input? */
3976 *addr
= !NILP (Vquit_flag
) || readable_events ();
3978 /* If input is being read as it arrives, and we have none, there is none. */
3979 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
3982 /* Try to read some input and see how much we get. */
3984 *addr
= !NILP (Vquit_flag
) || readable_events ();
3987 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
3990 gobble_input (expected
)
3995 if (interrupt_input
)
3998 mask
= sigblockx (SIGIO
);
3999 read_avail_input (expected
);
4003 #ifdef POLL_FOR_INPUT
4004 if (read_socket_hook
&& !interrupt_input
&& poll_suppress_count
== 0)
4007 mask
= sigblockx (SIGALRM
);
4008 read_avail_input (expected
);
4014 read_avail_input (expected
);
4018 /* Put a buffer_switch_event in the buffer
4019 so that read_key_sequence will notice the new current buffer. */
4021 record_asynch_buffer_change ()
4023 struct input_event event
;
4026 event
.kind
= buffer_switch_event
;
4027 event
.frame_or_window
= Qnil
;
4030 /* We don't need a buffer-switch event unless Emacs is waiting for input.
4031 The purpose of the event is to make read_key_sequence look up the
4032 keymaps again. If we aren't in read_key_sequence, we don't need one,
4033 and the event could cause trouble by messing up (input-pending-p). */
4034 tem
= Fwaiting_for_user_input_p ();
4038 /* We never need these events if we have no asynchronous subprocesses. */
4042 /* Make sure no interrupt happens while storing the event. */
4044 if (interrupt_input
)
4047 mask
= sigblockx (SIGIO
);
4048 kbd_buffer_store_event (&event
);
4055 kbd_buffer_store_event (&event
);
4062 /* Read any terminal input already buffered up by the system
4063 into the kbd_buffer, but do not wait.
4065 EXPECTED should be nonzero if the caller knows there is some input.
4067 Except on VMS, all input is read by this function.
4068 If interrupt_input is nonzero, this function MUST be called
4069 only when SIGIO is blocked.
4071 Returns the number of keyboard chars read, or -1 meaning
4072 this is a bad time to try to read input. */
4075 read_avail_input (expected
)
4078 struct input_event buf
[KBD_BUFFER_SIZE
];
4082 if (read_socket_hook
)
4083 /* No need for FIONREAD or fcntl; just say don't wait. */
4084 nread
= (*read_socket_hook
) (input_fd
, buf
, KBD_BUFFER_SIZE
,
4085 expected
, expected
);
4088 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
4089 the kbd_buffer can really hold. That may prevent loss
4090 of characters on some systems when input is stuffed at us. */
4091 unsigned char cbuf
[KBD_BUFFER_SIZE
- 1];
4094 /* Determine how many characters we should *try* to read. */
4097 #else /* not WINDOWSNT */
4099 n_to_read
= dos_keysns ();
4102 #else /* not MSDOS */
4104 /* Find out how much input is available. */
4105 if (ioctl (input_fd
, FIONREAD
, &n_to_read
) < 0)
4106 /* Formerly simply reported no input, but that sometimes led to
4107 a failure of Emacs to terminate.
4108 SIGHUP seems appropriate if we can't reach the terminal. */
4109 /* ??? Is it really right to send the signal just to this process
4110 rather than to the whole process group?
4111 Perhaps on systems with FIONREAD Emacs is alone in its group. */
4112 kill (getpid (), SIGHUP
);
4115 if (n_to_read
> sizeof cbuf
)
4116 n_to_read
= sizeof cbuf
;
4117 #else /* no FIONREAD */
4118 #if defined(USG) || defined(DGUX)
4119 /* Read some input if available, but don't wait. */
4120 n_to_read
= sizeof cbuf
;
4121 fcntl (input_fd
, F_SETFL
, O_NDELAY
);
4126 #endif /* not MSDOS */
4127 #endif /* not WINDOWSNT */
4129 /* Now read; for one reason or another, this will not block.
4130 NREAD is set to the number of chars read. */
4134 cbuf
[0] = dos_keyread();
4137 nread
= read (input_fd
, cbuf
, n_to_read
);
4139 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
4140 /* The kernel sometimes fails to deliver SIGHUP for ptys.
4141 This looks incorrect, but it isn't, because _BSD causes
4142 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
4143 and that causes a value other than 0 when there is no input. */
4149 /* We used to retry the read if it was interrupted.
4150 But this does the wrong thing when O_NDELAY causes
4151 an EAGAIN error. Does anybody know of a situation
4152 where a retry is actually needed? */
4154 nread
< 0 && (errno
== EAGAIN
4168 #if defined (USG) || defined (DGUX)
4169 fcntl (input_fd
, F_SETFL
, 0);
4170 #endif /* USG or DGUX */
4171 #endif /* no FIONREAD */
4172 for (i
= 0; i
< nread
; i
++)
4174 buf
[i
].kind
= ascii_keystroke
;
4175 buf
[i
].modifiers
= 0;
4176 if (meta_key
== 1 && (cbuf
[i
] & 0x80))
4177 buf
[i
].modifiers
= meta_modifier
;
4181 buf
[i
].code
= cbuf
[i
];
4183 XSETFRAME (buf
[i
].frame_or_window
, selected_frame
);
4185 buf
[i
].frame_or_window
= Qnil
;
4190 /* Scan the chars for C-g and store them in kbd_buffer. */
4191 for (i
= 0; i
< nread
; i
++)
4193 kbd_buffer_store_event (&buf
[i
]);
4194 /* Don't look at input that follows a C-g too closely.
4195 This reduces lossage due to autorepeat on C-g. */
4196 if (buf
[i
].kind
== ascii_keystroke
4197 && buf
[i
].code
== quit_char
)
4203 #endif /* not VMS */
4205 #ifdef SIGIO /* for entire page */
4206 /* Note SIGIO has been undef'd if FIONREAD is missing. */
4209 input_available_signal (signo
)
4212 /* Must preserve main program's value of errno. */
4213 int old_errno
= errno
;
4215 extern int select_alarmed
;
4219 /* USG systems forget handlers when they are used;
4220 must reestablish each time */
4221 signal (signo
, input_available_signal
);
4228 if (input_available_clear_time
)
4229 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
4234 nread
= read_avail_input (1);
4235 /* -1 means it's not ok to read the input now.
4236 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
4237 0 means there was no keyboard input available. */
4242 select_alarmed
= 1; /* Force the select emulator back to life */
4253 /* Send ourselves a SIGIO.
4255 This function exists so that the UNBLOCK_INPUT macro in
4256 blockinput.h can have some way to take care of input we put off
4257 dealing with, without assuming that every file which uses
4258 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
4260 reinvoke_input_signal ()
4269 /* Return the prompt-string of a sparse keymap.
4270 This is the first element which is a string.
4271 Return nil if there is none. */
4279 register Lisp_Object tem
;
4288 static void menu_bar_item ();
4289 static void menu_bar_one_keymap ();
4291 /* These variables hold the vector under construction within
4292 menu_bar_items and its subroutines, and the current index
4293 for storing into that vector. */
4294 static Lisp_Object menu_bar_items_vector
;
4295 static int menu_bar_items_index
;
4297 /* Return a vector of menu items for a menu bar, appropriate
4298 to the current buffer. Each item has three elements in the vector:
4301 OLD is an old vector we can optionally reuse, or nil. */
4304 menu_bar_items (old
)
4307 /* The number of keymaps we're scanning right now, and the number of
4308 keymaps we have allocated space for. */
4311 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
4312 in the current keymaps, or nil where it is not a prefix. */
4315 Lisp_Object def
, tem
, tail
;
4324 struct gcpro gcpro1
;
4326 /* In order to build the menus, we need to call the keymap
4327 accessors. They all call QUIT. But this function is called
4328 during redisplay, during which a quit is fatal. So inhibit
4329 quitting while building the menus.
4330 We do this instead of specbind because (1) errors will clear it anyway
4331 and (2) this avoids risk of specpdl overflow. */
4332 oquit
= Vinhibit_quit
;
4336 menu_bar_items_vector
= old
;
4338 menu_bar_items_vector
= Fmake_vector (make_number (24), Qnil
);
4339 menu_bar_items_index
= 0;
4341 GCPRO1 (menu_bar_items_vector
);
4343 /* Build our list of keymaps.
4344 If we recognize a function key and replace its escape sequence in
4345 keybuf with its symbol, or if the sequence starts with a mouse
4346 click and we need to switch buffers, we jump back here to rebuild
4347 the initial keymaps from the current buffer. */
4351 /* Should overriding-local-map apply, here? */
4352 if (!NILP (Voverriding_local_map_menu_flag
))
4354 if (NILP (Voverriding_local_map
))
4356 /* Yes, and it is nil. Use just global map. */
4358 maps
= (Lisp_Object
*) alloca (nmaps
* sizeof (maps
[0]));
4362 /* Yes, and it is non-nil. Use it and the global map. */
4364 maps
= (Lisp_Object
*) alloca (nmaps
* sizeof (maps
[0]));
4365 maps
[0] = Voverriding_local_map
;
4370 /* No, so use major and minor mode keymaps. */
4371 nmaps
= current_minor_maps (NULL
, &tmaps
) + 2;
4372 maps
= (Lisp_Object
*) alloca (nmaps
* sizeof (maps
[0]));
4373 bcopy (tmaps
, maps
, (nmaps
- 2) * sizeof (maps
[0]));
4374 #ifdef USE_TEXT_PROPERTIES
4375 maps
[nmaps
-2] = get_local_map (PT
, current_buffer
);
4377 maps
[nmaps
-2] = current_buffer
->keymap
;
4380 maps
[nmaps
-1] = current_global_map
;
4383 /* Look up in each map the dummy prefix key `menu-bar'. */
4387 for (mapno
= nmaps
- 1; mapno
>= 0; mapno
--)
4389 if (! NILP (maps
[mapno
]))
4390 def
= get_keyelt (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0));
4394 tem
= Fkeymapp (def
);
4396 menu_bar_one_keymap (def
);
4399 /* Move to the end those items that should be at the end. */
4401 for (tail
= Vmenu_bar_final_items
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4404 int end
= menu_bar_items_index
;
4406 for (i
= 0; i
< end
; i
+= 3)
4407 if (EQ (XCONS (tail
)->car
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
4409 Lisp_Object tem0
, tem1
, tem2
;
4410 /* Move the item at index I to the end,
4411 shifting all the others forward. */
4412 tem0
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 0];
4413 tem1
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 1];
4414 tem2
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
4416 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3],
4417 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
4418 (end
- i
- 3) * sizeof (Lisp_Object
));
4419 XVECTOR (menu_bar_items_vector
)->contents
[end
- 3] = tem0
;
4420 XVECTOR (menu_bar_items_vector
)->contents
[end
- 2] = tem1
;
4421 XVECTOR (menu_bar_items_vector
)->contents
[end
- 1] = tem2
;
4426 /* Add nil, nil, nil at the end. */
4427 i
= menu_bar_items_index
;
4428 if (i
+ 3 > XVECTOR (menu_bar_items_vector
)->size
)
4431 int newsize
= 2 * i
;
4432 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
4433 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
4434 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
4435 menu_bar_items_vector
= tem
;
4437 /* Add this item. */
4438 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
4439 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
4440 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
4441 menu_bar_items_index
= i
;
4443 Vinhibit_quit
= oquit
;
4445 return menu_bar_items_vector
;
4448 /* Scan one map KEYMAP, accumulating any menu items it defines
4449 in menu_bar_items_vector. */
4452 menu_bar_one_keymap (keymap
)
4455 Lisp_Object tail
, item
, key
, binding
, item_string
, table
;
4457 /* Loop over all keymap entries that have menu strings. */
4458 for (tail
= keymap
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4460 item
= XCONS (tail
)->car
;
4463 key
= XCONS (item
)->car
;
4464 binding
= XCONS (item
)->cdr
;
4465 if (CONSP (binding
))
4467 item_string
= XCONS (binding
)->car
;
4468 if (STRINGP (item_string
))
4469 menu_bar_item (key
, item_string
, Fcdr (binding
));
4471 else if (EQ (binding
, Qundefined
))
4472 menu_bar_item (key
, Qnil
, binding
);
4474 else if (VECTORP (item
))
4476 /* Loop over the char values represented in the vector. */
4477 int len
= XVECTOR (item
)->size
;
4479 for (c
= 0; c
< len
; c
++)
4481 Lisp_Object character
;
4482 XSETFASTINT (character
, c
);
4483 binding
= XVECTOR (item
)->contents
[c
];
4484 if (CONSP (binding
))
4486 item_string
= XCONS (binding
)->car
;
4487 if (STRINGP (item_string
))
4488 menu_bar_item (key
, item_string
, Fcdr (binding
));
4490 else if (EQ (binding
, Qundefined
))
4491 menu_bar_item (key
, Qnil
, binding
);
4497 /* This is used as the handler when calling internal_condition_case_1. */
4500 menu_bar_item_1 (arg
)
4506 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
4507 If there's already an item for KEY, add this DEF to it. */
4510 menu_bar_item (key
, item_string
, def
)
4511 Lisp_Object key
, item_string
, def
;
4514 Lisp_Object enabled
;
4517 if (EQ (def
, Qundefined
))
4519 /* If a map has an explicit `undefined' as definition,
4520 discard any previously made menu bar item. */
4522 for (i
= 0; i
< menu_bar_items_index
; i
+= 3)
4523 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
4525 if (menu_bar_items_index
> i
+ 3)
4526 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3],
4527 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
4528 (menu_bar_items_index
- i
- 3) * sizeof (Lisp_Object
));
4529 menu_bar_items_index
-= 3;
4533 /* If there's no definition for this key yet,
4534 just ignore `undefined'. */
4538 /* See if this entry is enabled. */
4543 /* No property, or nil, means enable.
4544 Otherwise, enable if value is not nil. */
4545 tem
= Fget (def
, Qmenu_enable
);
4547 /* (condition-case nil (eval tem)
4549 enabled
= internal_condition_case_1 (Feval
, tem
, Qerror
,
4553 /* Ignore this item if it's not enabled. */
4557 /* Find any existing item for this KEY. */
4558 for (i
= 0; i
< menu_bar_items_index
; i
+= 3)
4559 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
4562 /* If we did not find this KEY, add it at the end. */
4563 if (i
== menu_bar_items_index
)
4565 /* If vector is too small, get a bigger one. */
4566 if (i
+ 3 > XVECTOR (menu_bar_items_vector
)->size
)
4569 int newsize
= 2 * i
;
4570 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
4571 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
4572 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
4573 menu_bar_items_vector
= tem
;
4575 /* Add this item. */
4576 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = key
;
4577 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = item_string
;
4578 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Fcons (def
, Qnil
);
4579 menu_bar_items_index
= i
;
4581 /* We did find an item for this KEY. Add DEF to its list of maps. */
4585 old
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
4586 XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2] = Fcons (def
, old
);
4590 /* Read a character using menus based on maps in the array MAPS.
4591 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
4592 Return t if we displayed a menu but the user rejected it.
4594 PREV_EVENT is the previous input event, or nil if we are reading
4595 the first event of a key sequence.
4597 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
4598 if we used a mouse menu to read the input, or zero otherwise. If
4599 USED_MOUSE_MENU is null, we don't dereference it.
4601 The prompting is done based on the prompt-string of the map
4602 and the strings associated with various map elements.
4604 This can be done with X menus or with menus put in the minibuf.
4605 These are done in different ways, depending on how the input will be read.
4606 Menus using X are done after auto-saving in read-char, getting the input
4607 event from Fx_popup_menu; menus using the minibuf use read_char recursively
4608 and do auto-saving in the inner call of read_char. */
4611 read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
4614 Lisp_Object prev_event
;
4615 int *used_mouse_menu
;
4618 register Lisp_Object name
;
4619 Lisp_Object rest
, vector
;
4621 if (used_mouse_menu
)
4622 *used_mouse_menu
= 0;
4624 /* Use local over global Menu maps */
4626 if (! menu_prompting
)
4629 /* Optionally disregard all but the global map. */
4630 if (inhibit_local_menu_bar_menus
)
4632 maps
+= (nmaps
- 1);
4636 /* Get the menu name from the first map that has one (a prompt string). */
4637 for (mapno
= 0; mapno
< nmaps
; mapno
++)
4639 name
= map_prompt (maps
[mapno
]);
4644 /* If we don't have any menus, just read a character normally. */
4648 #if (defined (HAVE_X_WINDOWS) && defined (HAVE_X_MENU)) || defined (MSDOS)
4649 /* If we got to this point via a mouse click,
4650 use a real menu for mouse selection. */
4651 if (EVENT_HAS_PARAMETERS (prev_event
)
4652 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
))
4654 /* Display the menu and get the selection. */
4655 Lisp_Object
*realmaps
4656 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
4660 /* Use the maps that are not nil. */
4661 for (mapno
= 0; mapno
< nmaps
; mapno
++)
4662 if (!NILP (maps
[mapno
]))
4663 realmaps
[nmaps1
++] = maps
[mapno
];
4665 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
4668 /* If we got more than one event, put all but the first
4669 onto this list to be read later.
4670 Return just the first event now. */
4671 Vunread_command_events
4672 = nconc2 (XCONS (value
)->cdr
, Vunread_command_events
);
4673 value
= XCONS (value
)->car
;
4675 else if (NILP (value
))
4677 if (used_mouse_menu
)
4678 *used_mouse_menu
= 1;
4681 #endif /* (HAVE_X_WINDOWS && HAVE_X_MENU) || MSDOS */
4686 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
4692 register Lisp_Object name
;
4694 int width
= FRAME_WIDTH (selected_frame
) - 4;
4695 char *menu
= (char *) alloca (width
+ 4);
4698 Lisp_Object rest
, vector
;
4700 if (! menu_prompting
)
4703 /* Get the menu name from the first map that has one (a prompt string). */
4704 for (mapno
= 0; mapno
< nmaps
; mapno
++)
4706 name
= map_prompt (maps
[mapno
]);
4711 /* If we don't have any menus, just read a character normally. */
4715 /* Prompt string always starts with map's prompt, and a space. */
4716 strcpy (menu
, XSTRING (name
)->data
);
4717 nlength
= XSTRING (name
)->size
;
4718 menu
[nlength
++] = ':';
4719 menu
[nlength
++] = ' ';
4722 /* Start prompting at start of first map. */
4726 /* Present the documented bindings, a line at a time. */
4733 Lisp_Object orig_defn_macro
;
4735 /* Loop over elements of map. */
4740 /* If reached end of map, start at beginning of next map. */
4744 /* At end of last map, wrap around to first map if just starting,
4745 or end this line if already have something on it. */
4749 if (notfirst
|| nobindings
) break;
4754 /* Look at the next element of the map. */
4756 elt
= XVECTOR (vector
)->contents
[idx
];
4758 elt
= Fcar_safe (rest
);
4760 if (idx
< 0 && VECTORP (elt
))
4762 /* If we found a dense table in the keymap,
4763 advanced past it, but start scanning its contents. */
4764 rest
= Fcdr_safe (rest
);
4770 /* An ordinary element. */
4772 s
= Fcar_safe (Fcdr_safe (elt
)); /* alist */
4774 s
= Fcar_safe(elt
); /* vector */
4776 /* Ignore the element if it has no prompt string. */
4778 /* If we have room for the prompt string, add it to this line.
4779 If this is the first on the line, always add it. */
4780 else if (XSTRING (s
)->size
+ i
+ 2 < width
4785 /* Punctuate between strings. */
4788 strcpy (menu
+ i
, ", ");
4794 /* Add as much of string as fits. */
4795 thiswidth
= XSTRING (s
)->size
;
4796 if (thiswidth
+ i
> width
)
4797 thiswidth
= width
- i
;
4798 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
4804 /* If this element does not fit, end the line now,
4805 and save the element for the next line. */
4806 strcpy (menu
+ i
, "...");
4810 /* Move past this element. */
4811 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
4812 /* Handle reaching end of dense table. */
4817 rest
= Fcdr_safe (rest
);
4821 /* Prompt with that and read response. */
4824 /* Make believe its not a keyboard macro in case the help char
4825 is pressed. Help characters are not recorded because menu prompting
4826 is not used on replay.
4828 orig_defn_macro
= current_kboard
->defining_kbd_macro
;
4829 current_kboard
->defining_kbd_macro
= Qnil
;
4831 obj
= read_char (commandflag
, 0, 0, Qnil
, 0);
4832 while (BUFFERP (obj
));
4833 current_kboard
->defining_kbd_macro
= orig_defn_macro
;
4835 if (!INTEGERP (obj
))
4840 if (! EQ (obj
, menu_prompt_more_char
)
4841 && (!INTEGERP (menu_prompt_more_char
)
4842 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
4844 if (!NILP (current_kboard
->defining_kbd_macro
))
4845 store_kbd_macro_char (obj
);
4848 /* Help char - go round again */
4852 /* Reading key sequences. */
4854 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
4855 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
4856 keymap, or nil otherwise. Return the index of the first keymap in
4857 which KEY has any binding, or NMAPS if no map has a binding.
4859 If KEY is a meta ASCII character, treat it like meta-prefix-char
4860 followed by the corresponding non-meta character. Keymaps in
4861 CURRENT with non-prefix bindings for meta-prefix-char become nil in
4864 If KEY has no bindings in any of the CURRENT maps, NEXT is left
4867 NEXT may == CURRENT. */
4870 follow_key (key
, nmaps
, current
, defs
, next
)
4872 Lisp_Object
*current
, *defs
, *next
;
4875 int i
, first_binding
;
4877 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
4878 followed by the corresponding non-meta character. */
4879 if (INTEGERP (key
) && (XINT (key
) & CHAR_META
))
4881 for (i
= 0; i
< nmaps
; i
++)
4882 if (! NILP (current
[i
]))
4885 get_keyelt (access_keymap (current
[i
], meta_prefix_char
, 1, 0));
4887 /* Note that since we pass the resulting bindings through
4888 get_keymap_1, non-prefix bindings for meta-prefix-char
4890 next
[i
] = get_keymap_1 (next
[i
], 0, 1);
4896 XSETINT (key
, XFASTINT (key
) & ~CHAR_META
);
4899 first_binding
= nmaps
;
4900 for (i
= nmaps
- 1; i
>= 0; i
--)
4902 if (! NILP (current
[i
]))
4904 defs
[i
] = get_keyelt (access_keymap (current
[i
], key
, 1, 0));
4905 if (! NILP (defs
[i
]))
4912 /* Given the set of bindings we've found, produce the next set of maps. */
4913 if (first_binding
< nmaps
)
4914 for (i
= 0; i
< nmaps
; i
++)
4915 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0, 1);
4917 return first_binding
;
4920 /* Read a sequence of keys that ends with a non prefix character,
4921 storing it in KEYBUF, a buffer of size BUFSIZE.
4923 Return the length of the key sequence stored.
4924 Return -1 if the user rejected a command menu.
4926 Echo starting immediately unless `prompt' is 0.
4928 Where a key sequence ends depends on the currently active keymaps.
4929 These include any minor mode keymaps active in the current buffer,
4930 the current buffer's local map, and the global map.
4932 If a key sequence has no other bindings, we check Vfunction_key_map
4933 to see if some trailing subsequence might be the beginning of a
4934 function key's sequence. If so, we try to read the whole function
4935 key, and substitute its symbolic name into the key sequence.
4937 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
4938 `double-' events into similar click events, if that would make them
4939 bound. We try to turn `triple-' events first into `double-' events,
4942 If we get a mouse click in a mode line, vertical divider, or other
4943 non-text area, we treat the click as if it were prefixed by the
4944 symbol denoting that area - `mode-line', `vertical-line', or
4947 If the sequence starts with a mouse click, we read the key sequence
4948 with respect to the buffer clicked on, not the current buffer.
4950 If the user switches frames in the midst of a key sequence, we put
4951 off the switch-frame event until later; the next call to
4952 read_char will return it. */
4955 read_key_sequence (keybuf
, bufsize
, prompt
, dont_downcase_last
,
4956 can_return_switch_frame
)
4957 Lisp_Object
*keybuf
;
4960 int dont_downcase_last
;
4961 int can_return_switch_frame
;
4963 int count
= specpdl_ptr
- specpdl
;
4965 /* How many keys there are in the current key sequence. */
4968 /* The length of the echo buffer when we started reading, and
4969 the length of this_command_keys when we started reading. */
4973 /* The number of keymaps we're scanning right now, and the number of
4974 keymaps we have allocated space for. */
4976 int nmaps_allocated
= 0;
4978 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
4979 the current keymaps. */
4982 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
4983 in the current keymaps, or nil where it is not a prefix. */
4984 Lisp_Object
*submaps
;
4986 /* The local map to start out with at start of key sequence. */
4987 Lisp_Object orig_local_map
;
4989 /* 1 if we have already considered switching to the local-map property
4990 of the place where a mouse click occurred. */
4991 int localized_local_map
= 0;
4993 /* The index in defs[] of the first keymap that has a binding for
4994 this key sequence. In other words, the lowest i such that
4995 defs[i] is non-nil. */
4998 /* If t < mock_input, then KEYBUF[t] should be read as the next
5001 We use this to recover after recognizing a function key. Once we
5002 realize that a suffix of the current key sequence is actually a
5003 function key's escape sequence, we replace the suffix with the
5004 function key's binding from Vfunction_key_map. Now keybuf
5005 contains a new and different key sequence, so the echo area,
5006 this_command_keys, and the submaps and defs arrays are wrong. In
5007 this situation, we set mock_input to t, set t to 0, and jump to
5008 restart_sequence; the loop will read keys from keybuf up until
5009 mock_input, thus rebuilding the state; and then it will resume
5010 reading characters from the keyboard. */
5013 /* If the sequence is unbound in submaps[], then
5014 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
5015 and fkey_map is its binding.
5017 These might be > t, indicating that all function key scanning
5018 should hold off until t reaches them. We do this when we've just
5019 recognized a function key, to avoid searching for the function
5020 key's again in Vfunction_key_map. */
5021 int fkey_start
= 0, fkey_end
= 0;
5022 Lisp_Object fkey_map
;
5024 /* Likewise, for key_translation_map. */
5025 int keytran_start
= 0, keytran_end
= 0;
5026 Lisp_Object keytran_map
;
5028 /* If we receive a ``switch-frame'' event in the middle of a key sequence,
5029 we put it off for later. While we're reading, we keep the event here. */
5030 Lisp_Object delayed_switch_frame
;
5032 /* See the comment below... */
5033 #if defined (GOBBLE_FIRST_EVENT)
5034 Lisp_Object first_event
;
5037 Lisp_Object original_uppercase
;
5038 int original_uppercase_position
= -1;
5040 /* Gets around Microsoft compiler limitations. */
5043 struct buffer
*starting_buffer
;
5045 /* Nonzero if we seem to have got the beginning of a binding
5046 in function_key_map. */
5047 int function_key_possible
= 0;
5048 int key_translation_possible
= 0;
5052 last_nonmenu_event
= Qnil
;
5054 delayed_switch_frame
= Qnil
;
5055 fkey_map
= Vfunction_key_map
;
5056 keytran_map
= Vkey_translation_map
;
5058 /* If there is no function-key-map, turn off function key scanning. */
5059 if (NILP (Fkeymapp (Vfunction_key_map
)))
5060 fkey_start
= fkey_end
= bufsize
+ 1;
5062 /* If there is no key-translation-map, turn off scanning. */
5063 if (NILP (Fkeymapp (Vkey_translation_map
)))
5064 keytran_start
= keytran_end
= bufsize
+ 1;
5069 echo_prompt (XSTRING (prompt
)->data
);
5070 else if (cursor_in_echo_area
&& echo_keystrokes
)
5071 /* This doesn't put in a dash if the echo buffer is empty, so
5072 you don't always see a dash hanging out in the minibuffer. */
5076 /* Record the initial state of the echo area and this_command_keys;
5077 we will need to restore them if we replay a key sequence. */
5079 echo_start
= echo_length ();
5080 keys_start
= this_command_key_count
;
5082 #if defined (GOBBLE_FIRST_EVENT)
5083 /* This doesn't quite work, because some of the things that read_char
5084 does cannot safely be bypassed. It seems too risky to try to make
5087 /* Read the first char of the sequence specially, before setting
5088 up any keymaps, in case a filter runs and switches buffers on us. */
5089 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
5091 #endif /* GOBBLE_FIRST_EVENT */
5093 orig_local_map
= get_local_map (PT
, current_buffer
);
5095 /* We jump here when the key sequence has been thoroughly changed, and
5096 we need to rescan it starting from the beginning. When we jump here,
5097 keybuf[0..mock_input] holds the sequence we should reread. */
5100 starting_buffer
= current_buffer
;
5101 function_key_possible
= 0;
5102 key_translation_possible
= 0;
5104 /* Build our list of keymaps.
5105 If we recognize a function key and replace its escape sequence in
5106 keybuf with its symbol, or if the sequence starts with a mouse
5107 click and we need to switch buffers, we jump back here to rebuild
5108 the initial keymaps from the current buffer. */
5112 if (!NILP (Voverriding_local_map
))
5115 if (nmaps
> nmaps_allocated
)
5117 submaps
= (Lisp_Object
*) alloca (nmaps
* sizeof (submaps
[0]));
5118 defs
= (Lisp_Object
*) alloca (nmaps
* sizeof (defs
[0]));
5119 nmaps_allocated
= nmaps
;
5121 submaps
[0] = Voverriding_local_map
;
5125 nmaps
= current_minor_maps (0, &maps
) + 2;
5126 if (nmaps
> nmaps_allocated
)
5128 submaps
= (Lisp_Object
*) alloca (nmaps
* sizeof (submaps
[0]));
5129 defs
= (Lisp_Object
*) alloca (nmaps
* sizeof (defs
[0]));
5130 nmaps_allocated
= nmaps
;
5132 bcopy (maps
, submaps
, (nmaps
- 2) * sizeof (submaps
[0]));
5133 #ifdef USE_TEXT_PROPERTIES
5134 submaps
[nmaps
-2] = orig_local_map
;
5136 submaps
[nmaps
-2] = current_buffer
->keymap
;
5139 submaps
[nmaps
-1] = current_global_map
;
5142 /* Find an accurate initial value for first_binding. */
5143 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
5144 if (! NILP (submaps
[first_binding
]))
5147 /* Start from the beginning in keybuf. */
5150 /* These are no-ops the first time through, but if we restart, they
5151 revert the echo area and this_command_keys to their original state. */
5152 this_command_key_count
= keys_start
;
5153 if (INTERACTIVE
&& t
< mock_input
)
5154 echo_truncate (echo_start
);
5156 /* If the best binding for the current key sequence is a keymap, or
5157 we may be looking at a function key's escape sequence, keep on
5159 while ((first_binding
< nmaps
&& ! NILP (submaps
[first_binding
]))
5160 || (first_binding
>= nmaps
5162 /* mock input is never part of a function key's sequence. */
5163 && mock_input
<= fkey_start
)
5164 || (first_binding
>= nmaps
5165 && keytran_start
< t
&& key_translation_possible
)
5166 /* Don't return in the middle of a possible function key sequence,
5167 if the only bindings we found were via case conversion.
5168 Thus, if ESC O a has a function-key-map translation
5169 and ESC o has a binding, don't return after ESC O,
5170 so that we can translate ESC O plus the next character. */
5174 int used_mouse_menu
= 0;
5176 /* Where the last real key started. If we need to throw away a
5177 key that has expanded into more than one element of keybuf
5178 (say, a mouse click on the mode line which is being treated
5179 as [mode-line (mouse-...)], then we backtrack to this point
5181 int last_real_key_start
;
5183 /* These variables are analogous to echo_start and keys_start;
5184 while those allow us to restart the entire key sequence,
5185 echo_local_start and keys_local_start allow us to throw away
5187 int echo_local_start
, keys_local_start
, local_first_binding
;
5190 error ("key sequence too long");
5193 echo_local_start
= echo_length ();
5194 keys_local_start
= this_command_key_count
;
5195 local_first_binding
= first_binding
;
5198 /* These are no-ops, unless we throw away a keystroke below and
5199 jumped back up to replay_key; in that case, these restore the
5200 variables to their original state, allowing us to replay the
5202 if (INTERACTIVE
&& t
< mock_input
)
5203 echo_truncate (echo_local_start
);
5204 this_command_key_count
= keys_local_start
;
5205 first_binding
= local_first_binding
;
5207 /* By default, assume each event is "real". */
5208 last_real_key_start
= t
;
5210 /* Does mock_input indicate that we are re-reading a key sequence? */
5214 add_command_key (key
);
5215 if (echo_keystrokes
)
5219 /* If not, we should actually read a character. */
5222 struct buffer
*buf
= current_buffer
;
5226 KBOARD
*interrupted_kboard
= current_kboard
;
5227 struct frame
*interrupted_frame
= selected_frame
;
5228 if (setjmp (wrong_kboard_jmpbuf
))
5230 if (!NILP (delayed_switch_frame
))
5232 interrupted_kboard
->kbd_queue
5233 = Fcons (delayed_switch_frame
,
5234 interrupted_kboard
->kbd_queue
);
5235 delayed_switch_frame
= Qnil
;
5238 interrupted_kboard
->kbd_queue
5239 = Fcons (keybuf
[--t
], interrupted_kboard
->kbd_queue
);
5241 /* If the side queue is non-empty, ensure it begins with a
5242 switch-frame, so we'll replay it in the right context. */
5243 if (CONSP (interrupted_kboard
->kbd_queue
)
5244 && (key
= XCONS (interrupted_kboard
->kbd_queue
)->car
,
5245 !(EVENT_HAS_PARAMETERS (key
)
5246 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)),
5250 XSETFRAME (frame
, interrupted_frame
);
5251 interrupted_kboard
->kbd_queue
5252 = Fcons (make_lispy_switch_frame (frame
),
5253 interrupted_kboard
->kbd_queue
);
5256 orig_local_map
= get_local_map (PT
, current_buffer
);
5257 goto replay_sequence
;
5260 key
= read_char (NILP (prompt
), nmaps
, submaps
, last_nonmenu_event
,
5264 /* read_char returns t when it shows a menu and the user rejects it.
5269 /* read_char returns -1 at the end of a macro.
5270 Emacs 18 handles this by returning immediately with a
5271 zero, so that's what we'll do. */
5272 if (INTEGERP (key
) && XINT (key
) == -1)
5275 /* The Microsoft C compiler can't handle the goto that
5281 /* If the current buffer has been changed from under us, the
5282 keymap may have changed, so replay the sequence. */
5286 orig_local_map
= get_local_map (PT
, current_buffer
);
5287 goto replay_sequence
;
5290 /* If we have a quit that was typed in another frame, and
5291 quit_throw_to_read_char switched buffers,
5292 replay to get the right keymap. */
5293 if (XINT (key
) == quit_char
&& current_buffer
!= starting_buffer
)
5298 orig_local_map
= get_local_map (PT
, current_buffer
);
5299 goto replay_sequence
;
5305 /* Clicks in non-text areas get prefixed by the symbol
5306 in their CHAR-ADDRESS field. For example, a click on
5307 the mode line is prefixed by the symbol `mode-line'.
5309 Furthermore, key sequences beginning with mouse clicks
5310 are read using the keymaps of the buffer clicked on, not
5311 the current buffer. So we may have to switch the buffer
5314 When we turn one event into two events, we must make sure
5315 that neither of the two looks like the original--so that,
5316 if we replay the events, they won't be expanded again.
5317 If not for this, such reexpansion could happen either here
5318 or when user programs play with this-command-keys. */
5319 if (EVENT_HAS_PARAMETERS (key
))
5323 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
5324 if (EQ (kind
, Qmouse_click
))
5326 Lisp_Object window
, posn
;
5328 window
= POSN_WINDOW (EVENT_START (key
));
5329 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
5332 /* We're looking at the second event of a
5333 sequence which we expanded before. Set
5334 last_real_key_start appropriately. */
5336 last_real_key_start
= t
- 1;
5339 /* Key sequences beginning with mouse clicks are
5340 read using the keymaps in the buffer clicked on,
5341 not the current buffer. If we're at the
5342 beginning of a key sequence, switch buffers. */
5343 if (last_real_key_start
== 0
5345 && BUFFERP (XWINDOW (window
)->buffer
)
5346 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
5351 /* Arrange to go back to the original buffer once we're
5352 done reading the key sequence. Note that we can't
5353 use save_excursion_{save,restore} here, because they
5354 save point as well as the current buffer; we don't
5355 want to save point, because redisplay may change it,
5356 to accommodate a Fset_window_start or something. We
5357 don't want to do this at the top of the function,
5358 because we may get input from a subprocess which
5359 wants to change the selected window and stuff (say,
5361 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
5363 set_buffer_internal (XBUFFER (XWINDOW (window
)->buffer
));
5364 orig_local_map
= get_local_map (PT
, current_buffer
);
5365 goto replay_sequence
;
5367 /* For a mouse click, get the local text-property keymap
5368 of the place clicked on, rather than point. */
5369 if (last_real_key_start
== 0 && CONSP (XCONS (key
)->cdr
)
5370 && ! localized_local_map
)
5372 Lisp_Object map_here
, start
, pos
;
5374 localized_local_map
= 1;
5375 start
= EVENT_START (key
);
5376 if (CONSP (start
) && CONSP (XCONS (start
)->cdr
))
5378 pos
= POSN_BUFFER_POSN (start
);
5381 map_here
= get_local_map (XINT (pos
), current_buffer
);
5382 if (!EQ (map_here
, orig_local_map
))
5384 orig_local_map
= map_here
;
5388 goto replay_sequence
;
5394 /* Expand mode-line and scroll-bar events into two events:
5395 use posn as a fake prefix key. */
5398 if (t
+ 1 >= bufsize
)
5399 error ("key sequence too long");
5404 /* Zap the position in key, so we know that we've
5405 expanded it, and don't try to do so again. */
5406 POSN_BUFFER_POSN (EVENT_START (key
))
5407 = Fcons (posn
, Qnil
);
5411 else if (EQ (kind
, Qswitch_frame
))
5413 /* If we're at the beginning of a key sequence, and the caller
5414 says it's okay, go ahead and return this event. If we're
5415 in the midst of a key sequence, delay it until the end. */
5416 if (t
> 0 || !can_return_switch_frame
)
5418 delayed_switch_frame
= key
;
5422 else if (CONSP (XCONS (key
)->cdr
)
5423 && CONSP (EVENT_START (key
))
5424 && CONSP (XCONS (EVENT_START (key
))->cdr
))
5428 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
5429 /* Handle menu-bar events:
5430 insert the dummy prefix event `menu-bar'. */
5431 if (EQ (posn
, Qmenu_bar
))
5433 if (t
+ 1 >= bufsize
)
5434 error ("key sequence too long");
5438 /* Zap the position in key, so we know that we've
5439 expanded it, and don't try to do so again. */
5440 POSN_BUFFER_POSN (EVENT_START (key
))
5441 = Fcons (posn
, Qnil
);
5444 goto replay_sequence
;
5446 else if (CONSP (posn
))
5448 /* We're looking at the second event of a
5449 sequence which we expanded before. Set
5450 last_real_key_start appropriately. */
5451 if (last_real_key_start
== t
&& t
> 0)
5452 last_real_key_start
= t
- 1;
5457 /* We have finally decided that KEY is something we might want
5459 first_binding
= (follow_key (key
,
5460 nmaps
- first_binding
,
5461 submaps
+ first_binding
,
5462 defs
+ first_binding
,
5463 submaps
+ first_binding
)
5466 /* If KEY wasn't bound, we'll try some fallbacks. */
5467 if (first_binding
>= nmaps
)
5471 head
= EVENT_HEAD (key
);
5472 if (help_char_p (head
))
5474 read_key_sequence_cmd
= Vprefix_help_command
;
5476 last_nonmenu_event
= key
;
5477 /* The Microsoft C compiler can't handle the goto that
5485 Lisp_Object breakdown
;
5488 breakdown
= parse_modifiers (head
);
5489 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
5490 /* Attempt to reduce an unbound mouse event to a simpler
5491 event that is bound:
5492 Drags reduce to clicks.
5493 Double-clicks reduce to clicks.
5494 Triple-clicks reduce to double-clicks, then to clicks.
5495 Down-clicks are eliminated.
5496 Double-downs reduce to downs, then are eliminated.
5497 Triple-downs reduce to double-downs, then to downs,
5498 then are eliminated. */
5499 if (modifiers
& (down_modifier
| drag_modifier
5500 | double_modifier
| triple_modifier
))
5502 while (modifiers
& (down_modifier
| drag_modifier
5503 | double_modifier
| triple_modifier
))
5505 Lisp_Object new_head
, new_click
;
5506 if (modifiers
& triple_modifier
)
5507 modifiers
^= (double_modifier
| triple_modifier
);
5508 else if (modifiers
& double_modifier
)
5509 modifiers
&= ~double_modifier
;
5510 else if (modifiers
& drag_modifier
)
5511 modifiers
&= ~drag_modifier
;
5514 /* Dispose of this `down' event by simply jumping
5515 back to replay_key, to get another event.
5517 Note that if this event came from mock input,
5518 then just jumping back to replay_key will just
5519 hand it to us again. So we have to wipe out any
5522 We could delete keybuf[t] and shift everything
5523 after that to the left by one spot, but we'd also
5524 have to fix up any variable that points into
5525 keybuf, and shifting isn't really necessary
5528 Adding prefixes for non-textual mouse clicks
5529 creates two characters of mock input, and both
5530 must be thrown away. If we're only looking at
5531 the prefix now, we can just jump back to
5532 replay_key. On the other hand, if we've already
5533 processed the prefix, and now the actual click
5534 itself is giving us trouble, then we've lost the
5535 state of the keymaps we want to backtrack to, and
5536 we need to replay the whole sequence to rebuild
5539 Beyond that, only function key expansion could
5540 create more than two keys, but that should never
5541 generate mouse events, so it's okay to zero
5542 mock_input in that case too.
5544 Isn't this just the most wonderful code ever? */
5545 if (t
== last_real_key_start
)
5552 mock_input
= last_real_key_start
;
5553 goto replay_sequence
;
5558 = apply_modifiers (modifiers
, XCONS (breakdown
)->car
);
5560 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
5562 /* Look for a binding for this new key. follow_key
5563 promises that it didn't munge submaps the
5564 last time we called it, since key was unbound. */
5566 = (follow_key (new_click
,
5567 nmaps
- local_first_binding
,
5568 submaps
+ local_first_binding
,
5569 defs
+ local_first_binding
,
5570 submaps
+ local_first_binding
)
5571 + local_first_binding
);
5573 /* If that click is bound, go for it. */
5574 if (first_binding
< nmaps
)
5579 /* Otherwise, we'll leave key set to the drag event. */
5586 /* Normally, last_nonmenu_event gets the previous key we read.
5587 But when a mouse popup menu is being used,
5588 we don't update last_nonmenu_event; it continues to hold the mouse
5589 event that preceded the first level of menu. */
5590 if (!used_mouse_menu
)
5591 last_nonmenu_event
= key
;
5593 /* If the sequence is unbound, see if we can hang a function key
5594 off the end of it. We only want to scan real keyboard input
5595 for function key sequences, so if mock_input says that we're
5596 re-reading old events, don't examine it. */
5597 if (first_binding
>= nmaps
5600 Lisp_Object fkey_next
;
5602 /* Continue scan from fkey_end until we find a bound suffix.
5603 If we fail, increment fkey_start
5604 and start fkey_end from there. */
5605 while (fkey_end
< t
)
5609 key
= keybuf
[fkey_end
++];
5610 /* Look up meta-characters by prefixing them
5611 with meta_prefix_char. I hate this. */
5612 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
5617 (access_keymap (fkey_map
, meta_prefix_char
, 1, 0)),
5619 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
5622 fkey_next
= fkey_map
;
5625 = get_keyelt (access_keymap (fkey_next
, key
, 1, 0));
5627 #if 0 /* I didn't turn this on, because it might cause trouble
5628 for the mapping of return into C-m and tab into C-i. */
5629 /* Optionally don't map function keys into other things.
5630 This enables the user to redefine kp- keys easily. */
5631 if (SYMBOLP (key
) && !NILP (Vinhibit_function_key_mapping
))
5635 /* If the function key map gives a function, not an
5636 array, then call the function with no args and use
5637 its value instead. */
5638 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
5641 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5645 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
5646 fkey_next
= call1 (fkey_next
, prompt
);
5648 /* If the function returned something invalid,
5649 barf--don't ignore it.
5650 (To ignore it safely, we would need to gcpro a bunch of
5651 other variables.) */
5652 if (! (VECTORP (fkey_next
) || STRINGP (fkey_next
)))
5653 error ("Function in function-key-map returns invalid key sequence");
5656 function_key_possible
= ! NILP (fkey_next
);
5658 /* If keybuf[fkey_start..fkey_end] is bound in the
5659 function key map and it's a suffix of the current
5660 sequence (i.e. fkey_end == t), replace it with
5661 the binding and restart with fkey_start at the end. */
5662 if ((VECTORP (fkey_next
) || STRINGP (fkey_next
))
5665 int len
= XFASTINT (Flength (fkey_next
));
5667 t
= fkey_start
+ len
;
5669 error ("key sequence too long");
5671 if (VECTORP (fkey_next
))
5672 bcopy (XVECTOR (fkey_next
)->contents
,
5673 keybuf
+ fkey_start
,
5674 (t
- fkey_start
) * sizeof (keybuf
[0]));
5675 else if (STRINGP (fkey_next
))
5679 for (i
= 0; i
< len
; i
++)
5680 XSETFASTINT (keybuf
[fkey_start
+ i
],
5681 XSTRING (fkey_next
)->data
[i
]);
5685 fkey_start
= fkey_end
= t
;
5686 fkey_map
= Vfunction_key_map
;
5688 /* Do pass the results through key-translation-map. */
5689 keytran_start
= keytran_end
= 0;
5690 keytran_map
= Vkey_translation_map
;
5692 goto replay_sequence
;
5695 fkey_map
= get_keymap_1 (fkey_next
, 0, 1);
5697 /* If we no longer have a bound suffix, try a new positions for
5699 if (NILP (fkey_map
))
5701 fkey_end
= ++fkey_start
;
5702 fkey_map
= Vfunction_key_map
;
5703 function_key_possible
= 0;
5708 /* Look for this sequence in key-translation-map. */
5710 Lisp_Object keytran_next
;
5712 /* Scan from keytran_end until we find a bound suffix. */
5713 while (keytran_end
< t
)
5717 key
= keybuf
[keytran_end
++];
5718 /* Look up meta-characters by prefixing them
5719 with meta_prefix_char. I hate this. */
5720 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
5725 (access_keymap (keytran_map
, meta_prefix_char
, 1, 0)),
5727 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
5730 keytran_next
= keytran_map
;
5733 = get_keyelt (access_keymap (keytran_next
, key
, 1, 0));
5735 /* If the key translation map gives a function, not an
5736 array, then call the function with no args and use
5737 its value instead. */
5738 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
5739 && keytran_end
== t
)
5741 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5745 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
5746 keytran_next
= call1 (keytran_next
, prompt
);
5748 /* If the function returned something invalid,
5749 barf--don't ignore it.
5750 (To ignore it safely, we would need to gcpro a bunch of
5751 other variables.) */
5752 if (! (VECTORP (keytran_next
) || STRINGP (keytran_next
)))
5753 error ("Function in key-translation-map returns invalid key sequence");
5756 key_translation_possible
= ! NILP (keytran_next
);
5758 /* If keybuf[keytran_start..keytran_end] is bound in the
5759 key translation map and it's a suffix of the current
5760 sequence (i.e. keytran_end == t), replace it with
5761 the binding and restart with keytran_start at the end. */
5762 if ((VECTORP (keytran_next
) || STRINGP (keytran_next
))
5763 && keytran_end
== t
)
5765 int len
= XFASTINT (Flength (keytran_next
));
5767 t
= keytran_start
+ len
;
5769 error ("key sequence too long");
5771 if (VECTORP (keytran_next
))
5772 bcopy (XVECTOR (keytran_next
)->contents
,
5773 keybuf
+ keytran_start
,
5774 (t
- keytran_start
) * sizeof (keybuf
[0]));
5775 else if (STRINGP (keytran_next
))
5779 for (i
= 0; i
< len
; i
++)
5780 XSETFASTINT (keybuf
[keytran_start
+ i
],
5781 XSTRING (keytran_next
)->data
[i
]);
5785 keytran_start
= keytran_end
= t
;
5786 keytran_map
= Vkey_translation_map
;
5788 /* Don't pass the results of key-translation-map
5789 through function-key-map. */
5790 fkey_start
= fkey_end
= t
;
5791 fkey_map
= Vkey_translation_map
;
5793 goto replay_sequence
;
5796 keytran_map
= get_keymap_1 (keytran_next
, 0, 1);
5798 /* If we no longer have a bound suffix, try a new positions for
5800 if (NILP (keytran_map
))
5802 keytran_end
= ++keytran_start
;
5803 keytran_map
= Vkey_translation_map
;
5804 key_translation_possible
= 0;
5809 /* If KEY is not defined in any of the keymaps,
5810 and cannot be part of a function key or translation,
5811 and is an upper case letter
5812 use the corresponding lower-case letter instead. */
5813 if (first_binding
== nmaps
&& ! function_key_possible
5814 && ! key_translation_possible
5816 && ((((XINT (key
) & 0x3ffff)
5817 < XSTRING (current_buffer
->downcase_table
)->size
)
5818 && UPPERCASEP (XINT (key
) & 0x3ffff))
5819 || (XINT (key
) & shift_modifier
)))
5821 original_uppercase
= key
;
5822 original_uppercase_position
= t
- 1;
5824 if (XINT (key
) & shift_modifier
)
5825 XSETINT (key
, XINT (key
) & ~shift_modifier
);
5827 XSETINT (key
, (DOWNCASE (XINT (key
) & 0x3ffff)
5828 | (XINT (key
) & ~0x3ffff)));
5830 keybuf
[t
- 1] = key
;
5832 goto replay_sequence
;
5834 /* If KEY is not defined in any of the keymaps,
5835 and cannot be part of a function key or translation,
5836 and is a shifted function key,
5837 use the corresponding unshifted function key instead. */
5838 if (first_binding
== nmaps
&& ! function_key_possible
5839 && ! key_translation_possible
5842 Lisp_Object breakdown
;
5845 original_uppercase
= key
;
5846 original_uppercase_position
= t
- 1;
5848 breakdown
= parse_modifiers (key
);
5849 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
5850 if (modifiers
& shift_modifier
)
5852 modifiers
&= ~shift_modifier
;
5853 key
= apply_modifiers (modifiers
,
5854 XCONS (breakdown
)->car
);
5856 keybuf
[t
- 1] = key
;
5858 goto replay_sequence
;
5864 read_key_sequence_cmd
= (first_binding
< nmaps
5865 ? defs
[first_binding
]
5868 unread_switch_frame
= delayed_switch_frame
;
5869 unbind_to (count
, Qnil
);
5871 if (dont_downcase_last
&& t
- 1 == original_uppercase_position
)
5872 keybuf
[t
- 1] = original_uppercase
;
5874 /* Occasionally we fabricate events, perhaps by expanding something
5875 according to function-key-map, or by adding a prefix symbol to a
5876 mouse click in the scroll bar or modeline. In this cases, return
5877 the entire generated key sequence, even if we hit an unbound
5878 prefix or a definition before the end. This means that you will
5879 be able to push back the event properly, and also means that
5880 read-key-sequence will always return a logical unit.
5883 for (; t
< mock_input
; t
++)
5885 if (echo_keystrokes
)
5886 echo_char (keybuf
[t
]);
5887 add_command_key (keybuf
[t
]);
5893 #if 0 /* This doc string is too long for some compilers.
5894 This commented-out definition serves for DOC. */
5895 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
5896 "Read a sequence of keystrokes and return as a string or vector.\n\
5897 The sequence is sufficient to specify a non-prefix command in the\n\
5898 current local and global maps.\n\
5900 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
5901 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
5902 as a continuation of the previous key.\n\
5904 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not\n\
5905 convert the last event to lower case. (Normally any upper case event\n\
5906 is converted to lower case if the original event is undefined and the lower\n\
5907 case equivalent is defined.) A non-nil value is appropriate for reading\n\
5908 a key sequence to be defined.\n\
5910 A C-g typed while in this function is treated like any other character,\n\
5911 and `quit-flag' is not set.\n\
5913 If the key sequence starts with a mouse click, then the sequence is read\n\
5914 using the keymaps of the buffer of the window clicked in, not the buffer\n\
5915 of the selected window as normal.\n\
5917 `read-key-sequence' drops unbound button-down events, since you normally\n\
5918 only care about the click or drag events which follow them. If a drag\n\
5919 or multi-click event is unbound, but the corresponding click event would\n\
5920 be bound, `read-key-sequence' turns the event into a click event at the\n\
5921 drag's starting position. This means that you don't have to distinguish\n\
5922 between click and drag, double, or triple events unless you want to.\n\
5924 `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\
5925 lines separating windows, and scroll bars with imaginary keys\n\
5926 `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\
5928 Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this\n\
5929 function will process a switch-frame event if the user switches frames\n\
5930 before typing anything. If the user switches frames in the middle of a\n\
5931 key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME\n\
5932 is nil, then the event will be put off until after the current key sequence.\n\
5934 `read-key-sequence' checks `function-key-map' for function key\n\
5935 sequences, where they wouldn't conflict with ordinary bindings. See\n\
5936 `function-key-map' for more details.")
5937 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
)
5940 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
5942 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
)
5943 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
5944 Lisp_Object can_return_switch_frame
;
5946 Lisp_Object keybuf
[30];
5948 struct gcpro gcpro1
, gcpro2
;
5951 CHECK_STRING (prompt
, 0);
5954 bzero (keybuf
, sizeof keybuf
);
5956 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
5958 if (NILP (continue_echo
))
5959 this_command_key_count
= 0;
5961 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
5962 prompt
, ! NILP (dont_downcase_last
),
5963 ! NILP (can_return_switch_frame
));
5971 return make_event_array (i
, keybuf
);
5974 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 2, 0,
5975 "Execute CMD as an editor command.\n\
5976 CMD must be a symbol that satisfies the `commandp' predicate.\n\
5977 Optional second arg RECORD-FLAG non-nil\n\
5978 means unconditionally put this command in `command-history'.\n\
5979 Otherwise, that is done only if an arg is read using the minibuffer.")
5981 Lisp_Object cmd
, record
;
5983 register Lisp_Object final
;
5984 register Lisp_Object tem
;
5985 Lisp_Object prefixarg
;
5986 struct backtrace backtrace
;
5987 extern int debug_on_next_call
;
5989 prefixarg
= current_kboard
->Vprefix_arg
;
5990 current_kboard
->Vprefix_arg
= Qnil
;
5991 Vcurrent_prefix_arg
= prefixarg
;
5992 debug_on_next_call
= 0;
5996 tem
= Fget (cmd
, Qdisabled
);
5997 if (!NILP (tem
) && !NILP (Vrun_hooks
))
5998 return call1 (Vrun_hooks
, Qdisabled_command_hook
);
6003 final
= Findirect_function (cmd
);
6005 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
6006 do_autoload (final
, cmd
);
6011 if (STRINGP (final
) || VECTORP (final
))
6013 /* If requested, place the macro in the command history. For
6014 other sorts of commands, call-interactively takes care of
6018 = Fcons (Fcons (Qexecute_kbd_macro
,
6019 Fcons (final
, Fcons (prefixarg
, Qnil
))),
6022 return Fexecute_kbd_macro (final
, prefixarg
);
6024 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
6026 backtrace
.next
= backtrace_list
;
6027 backtrace_list
= &backtrace
;
6028 backtrace
.function
= &Qcall_interactively
;
6029 backtrace
.args
= &cmd
;
6030 backtrace
.nargs
= 1;
6031 backtrace
.evalargs
= 0;
6033 tem
= Fcall_interactively (cmd
, record
);
6035 backtrace_list
= backtrace
.next
;
6041 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
6043 "Read function name, then read its arguments and call it.")
6045 Lisp_Object prefixarg
;
6047 Lisp_Object function
;
6049 Lisp_Object saved_keys
;
6050 struct gcpro gcpro1
;
6052 saved_keys
= Fvector (this_command_key_count
,
6053 XVECTOR (this_command_keys
)->contents
);
6055 GCPRO1 (saved_keys
);
6057 if (EQ (prefixarg
, Qminus
))
6059 else if (CONSP (prefixarg
) && XINT (XCONS (prefixarg
)->car
) == 4)
6060 strcpy (buf
, "C-u ");
6061 else if (CONSP (prefixarg
) && INTEGERP (XCONS (prefixarg
)->car
))
6063 if (sizeof (int) == sizeof (EMACS_INT
))
6064 sprintf (buf
, "%d ", XINT (XCONS (prefixarg
)->car
));
6065 else if (sizeof (long) == sizeof (EMACS_INT
))
6066 sprintf (buf
, "%ld ", XINT (XCONS (prefixarg
)->car
));
6070 else if (INTEGERP (prefixarg
))
6072 if (sizeof (int) == sizeof (EMACS_INT
))
6073 sprintf (buf
, "%d ", XINT (prefixarg
));
6074 else if (sizeof (long) == sizeof (EMACS_INT
))
6075 sprintf (buf
, "%ld ", XINT (prefixarg
));
6080 /* This isn't strictly correct if execute-extended-command
6081 is bound to anything else. Perhaps it should use
6082 this_command_keys? */
6083 strcat (buf
, "M-x ");
6085 /* Prompt with buf, and then read a string, completing from and
6086 restricting to the set of all defined commands. Don't provide
6087 any initial input. Save the command read on the extended-command
6089 function
= Fcompleting_read (build_string (buf
),
6090 Vobarray
, Qcommandp
,
6091 Qt
, Qnil
, Qextended_command_history
);
6093 /* Set this_command_keys to the concatenation of saved_keys and
6094 function, followed by a RET. */
6096 struct Lisp_String
*str
;
6101 this_command_key_count
= 0;
6103 keys
= XVECTOR (saved_keys
)->contents
;
6104 for (i
= 0; i
< XVECTOR (saved_keys
)->size
; i
++)
6105 add_command_key (keys
[i
]);
6107 str
= XSTRING (function
);
6108 for (i
= 0; i
< str
->size
; i
++)
6110 XSETFASTINT (tem
, str
->data
[i
]);
6111 add_command_key (tem
);
6114 XSETFASTINT (tem
, '\015');
6115 add_command_key (tem
);
6120 function
= Fintern (function
, Qnil
);
6121 current_kboard
->Vprefix_arg
= prefixarg
;
6122 this_command
= function
;
6124 return Fcommand_execute (function
, Qt
);
6128 detect_input_pending ()
6131 get_input_pending (&input_pending
);
6133 return input_pending
;
6136 /* This is called in some cases before a possible quit.
6137 It cases the next call to detect_input_pending to recompute input_pending.
6138 So calling this function unnecessarily can't do any harm. */
6139 clear_input_pending ()
6144 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
6145 "T if command input is currently available with no waiting.\n\
6146 Actually, the value is nil only if we can be sure that no input is available.")
6149 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1)
6152 return detect_input_pending () ? Qt
: Qnil
;
6155 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
6156 "Return vector of last 100 events, not counting those from keyboard macros.")
6159 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
6162 if (total_keys
< NUM_RECENT_KEYS
)
6163 return Fvector (total_keys
, keys
);
6166 val
= Fvector (NUM_RECENT_KEYS
, keys
);
6167 bcopy (keys
+ recent_keys_index
,
6168 XVECTOR (val
)->contents
,
6169 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
6171 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
6172 recent_keys_index
* sizeof (Lisp_Object
));
6177 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
6178 "Return the key sequence that invoked this command.\n\
6179 The value is a string or a vector.")
6182 return make_event_array (this_command_key_count
,
6183 XVECTOR (this_command_keys
)->contents
);
6186 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
6187 "Return the current depth in recursive edits.")
6191 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
6195 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
6196 "FOpen dribble file: ",
6197 "Start writing all keyboard characters to a dribble file called FILE.\n\
6198 If FILE is nil, close any open dribble file.")
6212 file
= Fexpand_file_name (file
, Qnil
);
6213 dribble
= fopen (XSTRING (file
)->data
, "w");
6218 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
6219 "Discard the contents of the terminal input buffer.\n\
6220 Also cancel any kbd macro being defined.")
6223 current_kboard
->defining_kbd_macro
= Qnil
;
6224 update_mode_lines
++;
6226 Vunread_command_events
= Qnil
;
6227 unread_command_char
= -1;
6229 discard_tty_input ();
6231 /* Without the cast, GCC complains that this assignment loses the
6232 volatile qualifier of kbd_store_ptr. Is there anything wrong
6234 kbd_fetch_ptr
= (struct input_event
*) kbd_store_ptr
;
6235 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
6241 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
6242 "Stop Emacs and return to superior process. You can resume later.\n\
6243 If `cannot-suspend' is non-nil, or if the system doesn't support job\n\
6244 control, run a subshell instead.\n\n\
6245 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
6246 to be read as terminal input by Emacs's parent, after suspension.\n\
6248 Before suspending, run the normal hook `suspend-hook'.\n\
6249 After resumption run the normal hook `suspend-resume-hook'.\n\
6251 Some operating systems cannot stop the Emacs process and resume it later.\n\
6252 On such systems, Emacs starts a subshell instead of suspending.")
6254 Lisp_Object stuffstring
;
6257 int count
= specpdl_ptr
- specpdl
;
6258 int old_height
, old_width
;
6260 struct gcpro gcpro1
, gcpro2
;
6261 extern init_sys_modes ();
6263 if (!NILP (stuffstring
))
6264 CHECK_STRING (stuffstring
, 0);
6266 /* Run the functions in suspend-hook. */
6267 if (!NILP (Vrun_hooks
))
6268 call1 (Vrun_hooks
, intern ("suspend-hook"));
6270 GCPRO1 (stuffstring
);
6271 get_frame_size (&old_width
, &old_height
);
6273 /* sys_suspend can get an error if it tries to fork a subshell
6274 and the system resources aren't available for that. */
6275 record_unwind_protect (init_sys_modes
, 0);
6276 stuff_buffered_input (stuffstring
);
6281 unbind_to (count
, Qnil
);
6283 /* Check if terminal/window size has changed.
6284 Note that this is not useful when we are running directly
6285 with a window system; but suspend should be disabled in that case. */
6286 get_frame_size (&width
, &height
);
6287 if (width
!= old_width
|| height
!= old_height
)
6288 change_frame_size (selected_frame
, height
, width
, 0, 0);
6290 /* Run suspend-resume-hook. */
6291 if (!NILP (Vrun_hooks
))
6292 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
6298 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
6299 Then in any case stuff anything Emacs has read ahead and not used. */
6301 stuff_buffered_input (stuffstring
)
6302 Lisp_Object stuffstring
;
6304 /* stuff_char works only in BSD, versions 4.2 and up. */
6307 register unsigned char *p
;
6309 if (STRINGP (stuffstring
))
6313 p
= XSTRING (stuffstring
)->data
;
6314 count
= XSTRING (stuffstring
)->size
;
6319 /* Anything we have read ahead, put back for the shell to read. */
6320 /* ?? What should this do when we have multiple keyboards??
6321 Should we ignore anything that was typed in at the "wrong" kboard? */
6322 for (; kbd_fetch_ptr
!= kbd_store_ptr
; kbd_fetch_ptr
++)
6324 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
6325 kbd_fetch_ptr
= kbd_buffer
;
6326 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
6327 stuff_char (kbd_fetch_ptr
->code
);
6328 kbd_fetch_ptr
->kind
= no_event
;
6329 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_fetch_ptr
6335 #endif /* BSD and not BSD4_1 */
6338 set_waiting_for_input (time_to_clear
)
6339 EMACS_TIME
*time_to_clear
;
6341 input_available_clear_time
= time_to_clear
;
6343 /* Tell interrupt_signal to throw back to read_char, */
6344 waiting_for_input
= 1;
6346 /* If interrupt_signal was called before and buffered a C-g,
6347 make it run again now, to avoid timing error. */
6348 if (!NILP (Vquit_flag
))
6349 quit_throw_to_read_char ();
6352 clear_waiting_for_input ()
6354 /* Tell interrupt_signal not to throw back to read_char, */
6355 waiting_for_input
= 0;
6356 input_available_clear_time
= 0;
6359 /* This routine is called at interrupt level in response to C-G.
6360 If interrupt_input, this is the handler for SIGINT.
6361 Otherwise, it is called from kbd_buffer_store_event,
6362 in handling SIGIO or SIGTINT.
6364 If `waiting_for_input' is non zero, then unless `echoing' is nonzero,
6365 immediately throw back to read_char.
6367 Otherwise it sets the Lisp variable quit-flag not-nil.
6368 This causes eval to throw, when it gets a chance.
6369 If quit-flag is already non-nil, it stops the job right away. */
6372 interrupt_signal (signalnum
) /* If we don't have an argument, */
6373 int signalnum
; /* some compilers complain in signal calls. */
6376 /* Must preserve main program's value of errno. */
6377 int old_errno
= errno
;
6380 if (!read_socket_hook
&& NILP (Vwindow_system
))
6382 /* USG systems forget handlers when they are used;
6383 must reestablish each time */
6384 signal (SIGINT
, interrupt_signal
);
6385 signal (SIGQUIT
, interrupt_signal
);
6391 if (!NILP (Vquit_flag
) && FRAME_TERMCAP_P (selected_frame
))
6396 #ifdef SIGTSTP /* Support possible in later USG versions */
6398 * On systems which can suspend the current process and return to the original
6399 * shell, this command causes the user to end up back at the shell.
6400 * The "Auto-save" and "Abort" questions are not asked until
6401 * the user elects to return to emacs, at which point he can save the current
6402 * job and either dump core or continue.
6407 if (sys_suspend () == -1)
6409 printf ("Not running as a subprocess;\n");
6410 printf ("you can continue or abort.\n");
6413 /* Perhaps should really fork an inferior shell?
6414 But that would not provide any way to get back
6415 to the original shell, ever. */
6416 printf ("No support for stopping a process on this operating system;\n");
6417 printf ("you can continue or abort.\n");
6418 #endif /* not VMS */
6419 #endif /* not SIGTSTP */
6421 /* We must remain inside the screen area when the internal terminal
6422 is used. Note that [Enter] is not echoed by dos. */
6425 printf ("Auto-save? (y or n) ");
6427 if (((c
= getchar ()) & ~040) == 'Y')
6429 Fdo_auto_save (Qt
, Qnil
);
6431 printf ("\r\nAuto-save done");
6432 #else /* not MSDOS */
6433 printf ("Auto-save done\n");
6434 #endif /* not MSDOS */
6436 while (c
!= '\n') c
= getchar ();
6438 printf ("\r\nAbort? (y or n) ");
6439 #else /* not MSDOS */
6441 printf ("Abort (and enter debugger)? (y or n) ");
6443 printf ("Abort (and dump core)? (y or n) ");
6444 #endif /* not VMS */
6445 #endif /* not MSDOS */
6447 if (((c
= getchar ()) & ~040) == 'Y')
6449 while (c
!= '\n') c
= getchar ();
6451 printf ("\r\nContinuing...\r\n");
6452 #else /* not MSDOS */
6453 printf ("Continuing...\n");
6454 #endif /* not MSDOS */
6460 /* If executing a function that wants to be interrupted out of
6461 and the user has not deferred quitting by binding `inhibit-quit'
6462 then quit right away. */
6463 if (immediate_quit
&& NILP (Vinhibit_quit
))
6467 Fsignal (Qquit
, Qnil
);
6470 /* Else request quit when it's safe */
6474 if (waiting_for_input
&& !echoing
)
6475 quit_throw_to_read_char ();
6480 /* Handle a C-g by making read_char return C-g. */
6482 quit_throw_to_read_char ()
6484 quit_error_check ();
6486 /* Prevent another signal from doing this before we finish. */
6487 clear_waiting_for_input ();
6490 Vunread_command_events
= Qnil
;
6491 unread_command_char
= -1;
6493 #ifdef POLL_FOR_INPUT
6494 /* May be > 1 if in recursive minibuffer. */
6495 if (poll_suppress_count
== 0)
6499 if (FRAMEP (internal_last_event_frame
)
6500 && XFRAME (internal_last_event_frame
) != selected_frame
)
6501 Fhandle_switch_frame (make_lispy_switch_frame (internal_last_event_frame
));
6504 _longjmp (getcjmp
, 1);
6507 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
6508 "Set mode of reading keyboard input.\n\
6509 First arg INTERRUPT non-nil means use input interrupts;\n\
6510 nil means use CBREAK mode.\n\
6511 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
6512 (no effect except in CBREAK mode).\n\
6513 Third arg META t means accept 8-bit input (for a Meta key).\n\
6514 META nil means ignore the top bit, on the assumption it is parity.\n\
6515 Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\
6516 Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\
6517 See also `current-input-mode'.")
6518 (interrupt
, flow
, meta
, quit
)
6519 Lisp_Object interrupt
, flow
, meta
, quit
;
6522 && (!INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400))
6523 error ("set-input-mode: QUIT must be an ASCII character");
6525 #ifdef POLL_FOR_INPUT
6531 /* Note SIGIO has been undef'd if FIONREAD is missing. */
6532 if (read_socket_hook
)
6534 /* When using X, don't give the user a real choice,
6535 because we haven't implemented the mechanisms to support it. */
6536 #ifdef NO_SOCK_SIGIO
6537 interrupt_input
= 0;
6538 #else /* not NO_SOCK_SIGIO */
6539 interrupt_input
= 1;
6540 #endif /* NO_SOCK_SIGIO */
6543 interrupt_input
= !NILP (interrupt
);
6544 #else /* not SIGIO */
6545 interrupt_input
= 0;
6546 #endif /* not SIGIO */
6548 /* Our VMS input only works by interrupts, as of now. */
6550 interrupt_input
= 1;
6553 flow_control
= !NILP (flow
);
6556 else if (EQ (meta
, Qt
))
6561 /* Don't let this value be out of range. */
6562 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
6566 #ifdef POLL_FOR_INPUT
6567 poll_suppress_count
= 1;
6573 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
6574 "Return information about the way Emacs currently reads keyboard input.\n\
6575 The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
6576 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\
6577 nil, Emacs is using CBREAK mode.\n\
6578 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\
6579 terminal; this does not apply if Emacs uses interrupt-driven input.\n\
6580 META is t if accepting 8-bit input with 8th bit as Meta flag.\n\
6581 META nil means ignoring the top bit, on the assumption it is parity.\n\
6582 META is neither t nor nil if accepting 8-bit input and using\n\
6583 all 8 bits as the character code.\n\
6584 QUIT is the character Emacs currently uses to quit.\n\
6585 The elements of this list correspond to the arguments of\n\
6591 val
[0] = interrupt_input
? Qt
: Qnil
;
6592 val
[1] = flow_control
? Qt
: Qnil
;
6593 val
[2] = meta_key
== 2 ? make_number (0) : meta_key
== 1 ? Qt
: Qnil
;
6594 XSETFASTINT (val
[3], quit_char
);
6596 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
6601 * Set up a new kboard object with reasonable initial values.
6607 kb
->Vprefix_arg
= Qnil
;
6608 kb
->kbd_queue
= Qnil
;
6609 kb
->kbd_queue_has_data
= 0;
6610 kb
->immediate_echo
= 0;
6611 kb
->echoptr
= kb
->echobuf
;
6612 kb
->echo_after_prompt
= -1;
6613 kb
->kbd_macro_buffer
= 0;
6614 kb
->kbd_macro_bufsize
= 0;
6615 kb
->defining_kbd_macro
= Qnil
;
6616 kb
->Vlast_kbd_macro
= Qnil
;
6617 kb
->reference_count
= 0;
6618 kb
->Vsystem_key_alist
= Qnil
;
6619 kb
->Vdefault_minibuffer_frame
= Qnil
;
6623 * Destroy the contents of a kboard object, but not the object itself.
6624 * We use this just before deleteing it, or if we're going to initialize
6631 if (kb
->kbd_macro_buffer
)
6632 xfree (kb
->kbd_macro_buffer
);
6641 for (kbp
= &all_kboards
; *kbp
!= kb
; kbp
= &(*kbp
)->next_kboard
)
6644 *kbp
= kb
->next_kboard
;
6652 /* This is correct before outermost invocation of the editor loop */
6653 command_loop_level
= -1;
6655 quit_char
= Ctl ('g');
6656 Vunread_command_events
= Qnil
;
6657 unread_command_char
= -1;
6659 recent_keys_index
= 0;
6660 kbd_fetch_ptr
= kbd_buffer
;
6661 kbd_store_ptr
= kbd_buffer
;
6662 kbd_buffer_frame_or_window
6663 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
6665 do_mouse_tracking
= Qnil
;
6670 /* This means that command_loop_1 won't try to select anything the first
6672 internal_last_event_frame
= Qnil
;
6673 Vlast_event_frame
= internal_last_event_frame
;
6677 current_kboard
= initial_kboard
;
6679 wipe_kboard (current_kboard
);
6680 init_kboard (current_kboard
);
6683 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
6685 kbd_buffer_frame_or_window
6686 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
6687 if (!noninteractive
&& !read_socket_hook
&& NILP (Vwindow_system
))
6689 signal (SIGINT
, interrupt_signal
);
6690 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
6691 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
6692 SIGQUIT and we can't tell which one it will give us. */
6693 signal (SIGQUIT
, interrupt_signal
);
6694 #endif /* HAVE_TERMIO */
6696 /* Note SIGIO has been undef'd if FIONREAD is missing. */
6698 if (!noninteractive
)
6699 signal (SIGIO
, input_available_signal
);
6702 /* Use interrupt input by default, if it works and noninterrupt input
6703 has deficiencies. */
6705 #ifdef INTERRUPT_INPUT
6706 interrupt_input
= 1;
6708 interrupt_input
= 0;
6711 /* Our VMS input only works by interrupts, as of now. */
6713 interrupt_input
= 1;
6719 if (keyboard_init_hook
)
6720 (*keyboard_init_hook
) ();
6722 #ifdef POLL_FOR_INPUT
6723 poll_suppress_count
= 1;
6728 /* This type's only use is in syms_of_keyboard, to initialize the
6729 event header symbols and put properties on them. */
6736 struct event_head head_table
[] = {
6737 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
6738 &Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
,
6739 &Qswitch_frame
, "switch-frame", &Qswitch_frame
,
6740 &Qdelete_frame
, "delete-frame", &Qdelete_frame
,
6741 &Qiconify_frame
, "iconify-frame", &Qiconify_frame
,
6742 &Qmake_frame_visible
, "make-frame-visible", &Qmake_frame_visible
,
6747 Qdisabled_command_hook
= intern ("disabled-command-hook");
6748 staticpro (&Qdisabled_command_hook
);
6750 Qself_insert_command
= intern ("self-insert-command");
6751 staticpro (&Qself_insert_command
);
6753 Qforward_char
= intern ("forward-char");
6754 staticpro (&Qforward_char
);
6756 Qbackward_char
= intern ("backward-char");
6757 staticpro (&Qbackward_char
);
6759 Qdisabled
= intern ("disabled");
6760 staticpro (&Qdisabled
);
6762 Qundefined
= intern ("undefined");
6763 staticpro (&Qundefined
);
6765 Qpre_command_hook
= intern ("pre-command-hook");
6766 staticpro (&Qpre_command_hook
);
6768 Qpost_command_hook
= intern ("post-command-hook");
6769 staticpro (&Qpost_command_hook
);
6771 Qdeferred_action_function
= intern ("deferred-action-function");
6772 staticpro (&Qdeferred_action_function
);
6774 Qcommand_hook_internal
= intern ("command-hook-internal");
6775 staticpro (&Qcommand_hook_internal
);
6777 Qfunction_key
= intern ("function-key");
6778 staticpro (&Qfunction_key
);
6779 Qmouse_click
= intern ("mouse-click");
6780 staticpro (&Qmouse_click
);
6782 Qmenu_enable
= intern ("menu-enable");
6783 staticpro (&Qmenu_enable
);
6785 Qmode_line
= intern ("mode-line");
6786 staticpro (&Qmode_line
);
6787 Qvertical_line
= intern ("vertical-line");
6788 staticpro (&Qvertical_line
);
6789 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
6790 staticpro (&Qvertical_scroll_bar
);
6791 Qmenu_bar
= intern ("menu-bar");
6792 staticpro (&Qmenu_bar
);
6794 Qabove_handle
= intern ("above-handle");
6795 staticpro (&Qabove_handle
);
6796 Qhandle
= intern ("handle");
6797 staticpro (&Qhandle
);
6798 Qbelow_handle
= intern ("below-handle");
6799 staticpro (&Qbelow_handle
);
6801 Qevent_kind
= intern ("event-kind");
6802 staticpro (&Qevent_kind
);
6803 Qevent_symbol_elements
= intern ("event-symbol-elements");
6804 staticpro (&Qevent_symbol_elements
);
6805 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
6806 staticpro (&Qevent_symbol_element_mask
);
6807 Qmodifier_cache
= intern ("modifier-cache");
6808 staticpro (&Qmodifier_cache
);
6810 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
6811 staticpro (&Qrecompute_lucid_menubar
);
6812 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
6813 staticpro (&Qactivate_menubar_hook
);
6815 Qpolling_period
= intern ("polling-period");
6816 staticpro (&Qpolling_period
);
6819 struct event_head
*p
;
6821 for (p
= head_table
;
6822 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
6825 *p
->var
= intern (p
->name
);
6827 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
6828 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
6832 button_down_location
= Fmake_vector (make_number (NUM_MOUSE_BUTTONS
), Qnil
);
6833 staticpro (&button_down_location
);
6837 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
6839 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
6840 for (i
= 0; i
< len
; i
++)
6841 if (modifier_names
[i
])
6842 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
6843 staticpro (&modifier_symbols
);
6846 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
6847 staticpro (&recent_keys
);
6849 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
6850 staticpro (&this_command_keys
);
6852 Qextended_command_history
= intern ("extended-command-history");
6853 Fset (Qextended_command_history
, Qnil
);
6854 staticpro (&Qextended_command_history
);
6856 kbd_buffer_frame_or_window
6857 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
6858 staticpro (&kbd_buffer_frame_or_window
);
6860 accent_key_syms
= Qnil
;
6861 staticpro (&accent_key_syms
);
6863 func_key_syms
= Qnil
;
6864 staticpro (&func_key_syms
);
6866 system_key_syms
= Qnil
;
6867 staticpro (&system_key_syms
);
6870 staticpro (&mouse_syms
);
6872 unread_switch_frame
= Qnil
;
6873 staticpro (&unread_switch_frame
);
6875 defsubr (&Sevent_convert_list
);
6876 defsubr (&Sread_key_sequence
);
6877 defsubr (&Srecursive_edit
);
6879 defsubr (&Strack_mouse
);
6881 defsubr (&Sinput_pending_p
);
6882 defsubr (&Scommand_execute
);
6883 defsubr (&Srecent_keys
);
6884 defsubr (&Sthis_command_keys
);
6885 defsubr (&Ssuspend_emacs
);
6886 defsubr (&Sabort_recursive_edit
);
6887 defsubr (&Sexit_recursive_edit
);
6888 defsubr (&Srecursion_depth
);
6889 defsubr (&Stop_level
);
6890 defsubr (&Sdiscard_input
);
6891 defsubr (&Sopen_dribble_file
);
6892 defsubr (&Sset_input_mode
);
6893 defsubr (&Scurrent_input_mode
);
6894 defsubr (&Sexecute_extended_command
);
6896 DEFVAR_LISP ("last-command-char", &last_command_char
,
6897 "Last input event that was part of a command.");
6899 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char
,
6900 "Last input event that was part of a command.");
6902 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
6903 "Last input event in a command, except for mouse menu events.\n\
6904 Mouse menus give back keys that don't look like mouse events;\n\
6905 this variable holds the actual mouse event that led to the menu,\n\
6906 so that you can determine whether the command was run by mouse or not.");
6908 DEFVAR_LISP ("last-input-char", &last_input_char
,
6909 "Last input event.");
6911 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char
,
6912 "Last input event.");
6914 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
6915 "List of objects to be read as next command input events.");
6917 DEFVAR_INT ("unread-command-char", &unread_command_char
,
6918 "If not -1, an object to be read as next command input event.");
6920 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
6921 "Meta-prefix character code. Meta-foo as command input\n\
6922 turns into this character followed by foo.");
6923 XSETINT (meta_prefix_char
, 033);
6925 DEFVAR_LISP ("last-command", &last_command
,
6926 "The last command executed. Normally a symbol with a function definition,\n\
6927 but can be whatever was found in the keymap, or whatever the variable\n\
6928 `this-command' was set to by that command.\n\
6930 The value `mode-exit' is special; it means that the previous command\n\
6931 read an event that told it to exit, and it did so and unread that event.\n\
6932 In other words, the present command is the event that made the previous\n\
6935 The value `kill-region' is special; it means that the previous command\n\
6936 was a kill command.");
6937 last_command
= Qnil
;
6939 DEFVAR_LISP ("this-command", &this_command
,
6940 "The command now being executed.\n\
6941 The command can set this variable; whatever is put here\n\
6942 will be in `last-command' during the following command.");
6943 this_command
= Qnil
;
6945 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
6946 "*Number of keyboard input characters between auto-saves.\n\
6947 Zero means disable autosaving due to number of characters typed.");
6948 auto_save_interval
= 300;
6950 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
6951 "*Number of seconds idle time before auto-save.\n\
6952 Zero or nil means disable auto-saving due to idleness.\n\
6953 After auto-saving due to this many seconds of idle time,\n\
6954 Emacs also does a garbage collection if that seems to be warranted.");
6955 XSETFASTINT (Vauto_save_timeout
, 30);
6957 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes
,
6958 "*Nonzero means echo unfinished commands after this many seconds of pause.");
6959 echo_keystrokes
= 1;
6961 DEFVAR_INT ("polling-period", &polling_period
,
6962 "*Interval between polling for input during Lisp execution.\n\
6963 The reason for polling is to make C-g work to stop a running program.\n\
6964 Polling is needed only when using X windows and SIGIO does not work.\n\
6965 Polling is automatically disabled in all other cases.");
6968 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
6969 "*Maximum time between mouse clicks to make a double-click.\n\
6970 Measured in milliseconds. nil means disable double-click recognition;\n\
6971 t means double-clicks have no time limit and are detected\n\
6972 by position only.");
6973 Vdouble_click_time
= make_number (500);
6975 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
6976 "*Non-nil means inhibit local map menu bar menus.");
6977 inhibit_local_menu_bar_menus
= 0;
6979 DEFVAR_INT ("num-input-keys", &num_input_keys
,
6980 "Number of complete keys read from the keyboard so far.");
6983 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
6984 "The frame in which the most recently read event occurred.\n\
6985 If the last event came from a keyboard macro, this is set to `macro'.");
6986 Vlast_event_frame
= Qnil
;
6988 DEFVAR_LISP ("help-char", &Vhelp_char
,
6989 "Character to recognize as meaning Help.\n\
6990 When it is read, do `(eval help-form)', and display result if it's a string.\n\
6991 If the value of `help-form' is nil, this char can be read normally.");
6992 XSETINT (Vhelp_char
, Ctl ('H'));
6994 DEFVAR_LISP ("help-event-list", &Vhelp_event_list
,
6995 "List of input events to recognize as meaning Help.\n\
6996 These work just like the value of `help-char' (see that).");
6997 Vhelp_event_list
= Qnil
;
6999 DEFVAR_LISP ("help-form", &Vhelp_form
,
7000 "Form to execute when character `help-char' is read.\n\
7001 If the form returns a string, that string is displayed.\n\
7002 If `help-form' is nil, the help char is not recognized.");
7005 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
7006 "Command to run when `help-char' character follows a prefix key.\n\
7007 This command is used only when there is no actual binding\n\
7008 for that character after that prefix key.");
7009 Vprefix_help_command
= Qnil
;
7011 DEFVAR_LISP ("top-level", &Vtop_level
,
7012 "Form to evaluate when Emacs starts up.\n\
7013 Useful to set before you dump a modified Emacs.");
7016 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
7017 "String used as translate table for keyboard input, or nil.\n\
7018 Each character is looked up in this string and the contents used instead.\n\
7019 If string is of length N, character codes N and up are untranslated.");
7020 Vkeyboard_translate_table
= Qnil
;
7022 DEFVAR_LISP ("key-translation-map", &Vkey_translation_map
,
7023 "Keymap of key translations that can override keymaps.\n\
7024 This keymap works like `function-key-map', but comes after that,\n\
7025 and applies even for keys that have ordinary bindings.");
7026 Vkey_translation_map
= Qnil
;
7028 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
7029 "Non-nil means to always spawn a subshell instead of suspending,\n\
7030 even if the operating system has support for stopping a process.");
7033 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
7034 "Non-nil means prompt with menus when appropriate.\n\
7035 This is done when reading from a keymap that has a prompt string,\n\
7036 for elements that have prompt strings.\n\
7037 The menu is displayed on the screen\n\
7038 if X menus were enabled at configuration\n\
7039 time and the previous event was a mouse click prefix key.\n\
7040 Otherwise, menu prompting uses the echo area.");
7043 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
7044 "Character to see next line of menu prompt.\n\
7045 Type this character while in a menu prompt to rotate around the lines of it.");
7046 XSETINT (menu_prompt_more_char
, ' ');
7048 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
7049 "A mask of additional modifier keys to use with every keyboard character.\n\
7050 Emacs applies the modifiers of the character stored here to each keyboard\n\
7051 character it reads. For example, after evaluating the expression\n\
7052 (setq extra-keyboard-modifiers ?\\C-x)\n\
7053 all input characters will have the control modifier applied to them.\n\
7055 Note that the character ?\\C-@, equivalent to the integer zero, does\n\
7056 not count as a control character; rather, it counts as a character\n\
7057 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\
7058 cancels any modification.");
7059 extra_keyboard_modifiers
= 0;
7061 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
7062 "If an editing command sets this to t, deactivate the mark afterward.\n\
7063 The command loop sets this to nil before each command,\n\
7064 and tests the value when the command returns.\n\
7065 Buffer modification stores t in this variable.");
7066 Vdeactivate_mark
= Qnil
;
7068 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
7069 "Temporary storage of pre-command-hook or post-command-hook.");
7070 Vcommand_hook_internal
= Qnil
;
7072 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
7073 "Normal hook run before each command is executed.\n\
7074 While the hook is run, its value is temporarily set to nil\n\
7075 to avoid an unbreakable infinite loop if a hook function gets an error.\n\
7076 As a result, a hook function cannot straightforwardly alter the value of\n\
7077 `pre-command-hook'. See the Emacs Lisp manual for a way of\n\
7078 implementing hook functions that alter the set of hook functions.");
7079 Vpre_command_hook
= Qnil
;
7081 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
7082 "Normal hook run after each command is executed.\n\
7083 While the hook is run, its value is temporarily set to nil\n\
7084 to avoid an unbreakable infinite loop if a hook function gets an error.\n\
7085 As a result, a hook function cannot straightforwardly alter the value of\n\
7086 `post-command-hook'. See the Emacs Lisp manual for a way of\n\
7087 implementing hook functions that alter the set of hook functions.");
7088 Vpost_command_hook
= Qnil
;
7090 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
7091 "t means menu bar, specified Lucid style, needs to be recomputed.");
7092 Vlucid_menu_bar_dirty_flag
= Qnil
;
7094 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
7095 "List of menu bar items to move to the end of the menu bar.\n\
7096 The elements of the list are event types that may have menu bar bindings.");
7097 Vmenu_bar_final_items
= Qnil
;
7099 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
7100 "Keymap that overrides all other local keymaps.\n\
7101 If this variable is non-nil, it is used as a keymap instead of the\n\
7102 buffer's local map, and the minor mode keymaps and text property keymaps.");
7103 Voverriding_local_map
= Qnil
;
7105 DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag
,
7106 "Non-nil means `overriding-local-map' applies to the menu bar.\n\
7107 Otherwise, the menu bar continues to reflect the buffer's local map\n\
7108 and the minor mode maps regardless of `overriding-local-map'.");
7109 Voverriding_local_map_menu_flag
= Qnil
;
7111 DEFVAR_LISP ("track-mouse", &do_mouse_tracking
,
7112 "*Non-nil means generate motion events for mouse motion.");
7114 DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist
,
7115 "Alist of system-specific X windows key symbols.\n\
7116 Each element should have the form (N . SYMBOL) where N is the\n\
7117 numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\
7118 and SYMBOL is its name.");
7120 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
7121 "List of deferred actions to be performed at a later time.\n\
7122 The precise format isn't relevant here; we just check whether it is nil.");
7123 Vdeferred_action_list
= Qnil
;
7125 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
7126 "Function to call to handle deferred actions, after each command.\n\
7127 This function is called with no arguments after each command\n\
7128 whenever `deferred-action-list' is non-nil.");
7129 Vdeferred_action_function
= Qnil
;
7134 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
7135 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
7136 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
7137 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
7138 initial_define_key (meta_map
, 'x', "execute-extended-command");