1 /* Keyboard and mouse input; editor command loop.
2 Copyright (C) 1985,86,87,88,89,93,94,95 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* Allow config.h to undefine symbols found here. */
28 #include "termhooks.h"
35 #include "dispextern.h"
37 #include "intervals.h"
38 #include "blockinput.h"
47 #include <sys/ioctl.h>
49 #endif /* not MSDOS */
51 #include "syssignal.h"
54 /* This is to get the definitions of the XK_ symbols. */
59 /* Include systime.h after xterm.h to avoid double inclusion of time.h. */
64 /* Variables for blockinput.h: */
66 /* Non-zero if interrupt input is blocked right now. */
67 int interrupt_input_blocked
;
69 /* Nonzero means an input interrupt has arrived
70 during the current critical section. */
71 int interrupt_input_pending
;
74 /* File descriptor to use for input. */
78 /* Make all keyboard buffers much bigger when using X windows. */
79 #define KBD_BUFFER_SIZE 4096
80 #else /* No X-windows, character input */
81 #define KBD_BUFFER_SIZE 256
82 #endif /* No X-windows */
84 /* Following definition copied from eval.c */
88 struct backtrace
*next
;
89 Lisp_Object
*function
;
90 Lisp_Object
*args
; /* Points to vector of args. */
91 int nargs
; /* length of vector. If nargs is UNEVALLED,
92 args points to slot holding list of
98 KBOARD
*initial_kboard
;
99 KBOARD
*current_kboard
;
103 KBOARD the_only_kboard
;
106 /* Non-nil disable property on a command means
107 do not execute it; call disabled-command-hook's value instead. */
108 Lisp_Object Qdisabled
, Qdisabled_command_hook
;
110 #define NUM_RECENT_KEYS (100)
111 int recent_keys_index
; /* Index for storing next element into recent_keys */
112 int total_keys
; /* Total number of elements stored into recent_keys */
113 Lisp_Object recent_keys
; /* A vector, holding the last 100 keystrokes */
115 /* Vector holding the key sequence that invoked the current command.
116 It is reused for each command, and it may be longer than the current
117 sequence; this_command_key_count indicates how many elements
118 actually mean something.
119 It's easier to staticpro a single Lisp_Object than an array. */
120 Lisp_Object this_command_keys
;
121 int this_command_key_count
;
123 extern int minbuf_level
;
125 extern struct backtrace
*backtrace_list
;
127 /* Nonzero means do menu prompting. */
128 static int menu_prompting
;
130 /* Character to see next line of menu prompt. */
131 static Lisp_Object menu_prompt_more_char
;
133 /* For longjmp to where kbd input is being done. */
134 static jmp_buf getcjmp
;
136 /* True while doing kbd input. */
137 int waiting_for_input
;
139 /* True while displaying for echoing. Delays C-g throwing. */
142 /* Nonzero means disregard local maps for the menu bar. */
143 static int inhibit_local_menu_bar_menus
;
145 /* Nonzero means C-g should cause immediate error-signal. */
148 /* Character to recognize as the help char. */
149 Lisp_Object Vhelp_char
;
151 /* Form to execute when help char is typed. */
152 Lisp_Object Vhelp_form
;
154 /* Command to run when the help character follows a prefix key. */
155 Lisp_Object Vprefix_help_command
;
157 /* List of items that should move to the end of the menu bar. */
158 Lisp_Object Vmenu_bar_final_items
;
160 /* Character that causes a quit. Normally C-g.
162 If we are running on an ordinary terminal, this must be an ordinary
163 ASCII char, since we want to make it our interrupt character.
165 If we are not running on an ordinary terminal, it still needs to be
166 an ordinary ASCII char. This character needs to be recognized in
167 the input interrupt handler. At this point, the keystroke is
168 represented as a struct input_event, while the desired quit
169 character is specified as a lispy event. The mapping from struct
170 input_events to lispy events cannot run in an interrupt handler,
171 and the reverse mapping is difficult for anything but ASCII
174 FOR THESE ELABORATE AND UNSATISFYING REASONS, quit_char must be an
178 extern Lisp_Object current_global_map
;
179 extern int minibuf_level
;
181 /* If non-nil, this is a map that overrides all other local maps. */
182 Lisp_Object Voverriding_local_map
;
184 /* If non-nil, Voverriding_local_map applies to the menu bar. */
185 Lisp_Object Voverriding_local_map_menu_flag
;
187 /* Current depth in recursive edits. */
188 int command_loop_level
;
190 /* Total number of times command_loop has read a key sequence. */
193 /* Last input character read as a command. */
194 Lisp_Object last_command_char
;
196 /* Last input character read as a command, not counting menus
197 reached by the mouse. */
198 Lisp_Object last_nonmenu_event
;
200 /* Last input character read for any purpose. */
201 Lisp_Object last_input_char
;
203 /* If not Qnil, a list of objects to be read as subsequent command input. */
204 Lisp_Object Vunread_command_events
;
206 /* If not -1, an event to be read as subsequent command input. */
207 int unread_command_char
;
209 /* If not Qnil, this is a switch-frame event which we decided to put
210 off until the end of a key sequence. This should be read as the
211 next command input, after any unread_command_events.
213 read_key_sequence uses this to delay switch-frame events until the
214 end of the key sequence; Fread_char uses it to put off switch-frame
215 events until a non-ASCII event is acceptable as input. */
216 Lisp_Object unread_switch_frame
;
218 /* A mask of extra modifier bits to put into every keyboard char. */
219 int extra_keyboard_modifiers
;
221 /* Char to use as prefix when a meta character is typed in.
222 This is bound on entry to minibuffer in case ESC is changed there. */
224 Lisp_Object meta_prefix_char
;
226 /* Last size recorded for a current buffer which is not a minibuffer. */
227 static int last_non_minibuf_size
;
229 /* Number of idle seconds before an auto-save and garbage collection. */
230 static Lisp_Object Vauto_save_timeout
;
232 /* Total number of times read_char has returned. */
235 /* Total number of times read_char has returned, outside of macros. */
236 int num_nonmacro_input_chars
;
238 /* Auto-save automatically when this many characters have been typed
239 since the last time. */
241 static int auto_save_interval
;
243 /* Value of num_nonmacro_input_chars as of last auto save. */
247 /* Last command executed by the editor command loop, not counting
248 commands that set the prefix argument. */
250 Lisp_Object last_command
;
252 /* The command being executed by the command loop.
253 Commands may set this, and the value set will be copied into last_command
254 instead of the actual command. */
255 Lisp_Object this_command
;
257 /* The value of point when the last command was executed. */
258 int last_point_position
;
260 /* The buffer that was current when the last command was started. */
261 Lisp_Object last_point_position_buffer
;
264 /* The frame in which the last input event occurred, or Qmacro if the
265 last event came from a macro. We use this to determine when to
266 generate switch-frame events. This may be cleared by functions
267 like Fselect_frame, to make sure that a switch-frame event is
268 generated by the next character. */
269 Lisp_Object internal_last_event_frame
;
272 /* A user-visible version of the above, intended to allow users to
273 figure out where the last event came from, if the event doesn't
274 carry that information itself (i.e. if it was a character). */
275 Lisp_Object Vlast_event_frame
;
277 /* The timestamp of the last input event we received from the X server.
278 X Windows wants this for selection ownership. */
279 unsigned long last_event_timestamp
;
281 Lisp_Object Qself_insert_command
;
282 Lisp_Object Qforward_char
;
283 Lisp_Object Qbackward_char
;
284 Lisp_Object Qundefined
;
286 /* read_key_sequence stores here the command definition of the
287 key sequence that it reads. */
288 Lisp_Object read_key_sequence_cmd
;
290 /* Form to evaluate (if non-nil) when Emacs is started. */
291 Lisp_Object Vtop_level
;
293 /* User-supplied string to translate input characters through. */
294 Lisp_Object Vkeyboard_translate_table
;
296 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
297 extern Lisp_Object Vfunction_key_map
;
299 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
300 Lisp_Object Vkey_translation_map
;
302 /* Non-nil means deactivate the mark at end of this command. */
303 Lisp_Object Vdeactivate_mark
;
305 /* Menu bar specified in Lucid Emacs fashion. */
307 Lisp_Object Vlucid_menu_bar_dirty_flag
;
308 Lisp_Object Qrecompute_lucid_menubar
, Qactivate_menubar_hook
;
310 /* Hooks to run before and after each command. */
311 Lisp_Object Qpre_command_hook
, Qpost_command_hook
;
312 Lisp_Object Vpre_command_hook
, Vpost_command_hook
;
313 Lisp_Object Qcommand_hook_internal
, Vcommand_hook_internal
;
315 /* List of deferred actions to be performed at a later time.
316 The precise format isn't relevant here; we just check whether it is nil. */
317 Lisp_Object Vdeferred_action_list
;
319 /* Function to call to handle deferred actions, when there are any. */
320 Lisp_Object Vdeferred_action_function
;
321 Lisp_Object Qdeferred_action_function
;
323 /* File in which we write all commands we read. */
326 /* Nonzero if input is available. */
329 /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
330 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
334 extern char *pending_malloc_warning
;
336 /* Circular buffer for pre-read keyboard input. */
337 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
339 /* Vector to GCPRO the frames and windows mentioned in kbd_buffer.
341 The interrupt-level event handlers will never enqueue an event on a
342 frame which is not in Vframe_list, and once an event is dequeued,
343 internal_last_event_frame or the event itself points to the frame.
346 But while the event is sitting in the queue, it's completely
347 unprotected. Suppose the user types one command which will run for
348 a while and then delete a frame, and then types another event at
349 the frame that will be deleted, before the command gets around to
350 it. Suppose there are no references to this frame elsewhere in
351 Emacs, and a GC occurs before the second event is dequeued. Now we
352 have an event referring to a freed frame, which will crash Emacs
355 Similar things happen when an event on a scroll bar is enqueued; the
356 window may be deleted while the event is in the queue.
358 So, we use this vector to protect the frame_or_window field in the
359 event queue. That way, they'll be dequeued as dead frames or
360 windows, but still valid lisp objects.
362 If kbd_buffer[i].kind != no_event, then
363 (XVECTOR (kbd_buffer_frame_or_window)->contents[i]
364 == kbd_buffer[i].frame_or_window. */
365 static Lisp_Object kbd_buffer_frame_or_window
;
367 /* Pointer to next available character in kbd_buffer.
368 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
369 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the
370 next available char is in kbd_buffer[0]. */
371 static struct input_event
*kbd_fetch_ptr
;
373 /* Pointer to next place to store character in kbd_buffer. This
374 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
375 character should go in kbd_buffer[0]. */
376 static volatile struct input_event
*kbd_store_ptr
;
378 /* The above pair of variables forms a "queue empty" flag. When we
379 enqueue a non-hook event, we increment kbd_store_ptr. When we
380 dequeue a non-hook event, we increment kbd_fetch_ptr. We say that
381 there is input available iff the two pointers are not equal.
383 Why not just have a flag set and cleared by the enqueuing and
384 dequeuing functions? Such a flag could be screwed up by interrupts
385 at inopportune times. */
387 /* If this flag is a frame, we check mouse_moved to see when the
388 mouse moves, and motion events will appear in the input stream.
389 Otherwise, mouse motion is ignored. */
390 static Lisp_Object do_mouse_tracking
;
393 /* The window system handling code should set this if the mouse has
394 moved since the last call to the mouse_position_hook. Calling that
395 hook should clear this. Code assumes that if this is set, it can
396 call mouse_position_hook to get the promised position, so don't set
397 it unless you're prepared to substantiate the claim! */
399 #endif /* HAVE_MOUSE */
401 /* Symbols to head events. */
402 Lisp_Object Qmouse_movement
;
403 Lisp_Object Qscroll_bar_movement
;
404 Lisp_Object Qswitch_frame
;
405 Lisp_Object Qdelete_frame
;
406 Lisp_Object Qiconify_frame
;
407 Lisp_Object Qmake_frame_visible
;
409 /* Symbols to denote kinds of events. */
410 Lisp_Object Qfunction_key
;
411 Lisp_Object Qmouse_click
;
412 /* Lisp_Object Qmouse_movement; - also an event header */
414 /* Properties of event headers. */
415 Lisp_Object Qevent_kind
;
416 Lisp_Object Qevent_symbol_elements
;
418 Lisp_Object Qmenu_enable
;
420 /* An event header symbol HEAD may have a property named
421 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
422 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
423 mask of modifiers applied to it. If present, this is used to help
424 speed up parse_modifiers. */
425 Lisp_Object Qevent_symbol_element_mask
;
427 /* An unmodified event header BASE may have a property named
428 Qmodifier_cache, which is an alist mapping modifier masks onto
429 modified versions of BASE. If present, this helps speed up
431 Lisp_Object Qmodifier_cache
;
433 /* Symbols to use for parts of windows. */
434 Lisp_Object Qmode_line
;
435 Lisp_Object Qvertical_line
;
436 Lisp_Object Qvertical_scroll_bar
;
437 Lisp_Object Qmenu_bar
;
439 extern Lisp_Object Qmenu_enable
;
441 Lisp_Object
recursive_edit_unwind (), command_loop ();
442 Lisp_Object
Fthis_command_keys ();
443 Lisp_Object Qextended_command_history
;
445 Lisp_Object Qpolling_period
;
447 extern Lisp_Object Vprint_level
, Vprint_length
;
449 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
451 EMACS_TIME
*input_available_clear_time
;
453 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
454 Default is 1 if INTERRUPT_INPUT is defined. */
457 /* Nonzero while interrupts are temporarily deferred during redisplay. */
458 int interrupts_deferred
;
460 /* nonzero means use ^S/^Q for flow control. */
463 /* Allow m- file to inhibit use of FIONREAD. */
464 #ifdef BROKEN_FIONREAD
468 /* We are unable to use interrupts if FIONREAD is not available,
469 so flush SIGIO so we won't try. */
476 /* If we support X Windows, turn on the code to poll periodically
477 to detect C-g. It isn't actually used when doing interrupt input. */
478 #ifdef HAVE_X_WINDOWS
479 #define POLL_FOR_INPUT
482 /* Global variable declarations. */
484 /* Function for init_keyboard to call with no args (if nonzero). */
485 void (*keyboard_init_hook
) ();
487 static int read_avail_input ();
488 static void get_input_pending ();
489 static int readable_events ();
490 static Lisp_Object
read_char_x_menu_prompt ();
491 static Lisp_Object
read_char_minibuf_menu_prompt ();
492 static Lisp_Object
make_lispy_event ();
494 static Lisp_Object
make_lispy_movement ();
496 static Lisp_Object
modify_event_symbol ();
497 static Lisp_Object
make_lispy_switch_frame ();
498 static int parse_solitary_modifier ();
500 /* > 0 if we are to echo keystrokes. */
501 static int echo_keystrokes
;
503 /* Nonzero means don't try to suspend even if the operating system seems
505 static int cannot_suspend
;
507 #define min(a,b) ((a)<(b)?(a):(b))
508 #define max(a,b) ((a)>(b)?(a):(b))
510 /* Install the string STR as the beginning of the string of echoing,
511 so that it serves as a prompt for the next character.
512 Also start echoing. */
517 int len
= strlen (str
);
519 if (len
> ECHOBUFSIZE
- 4)
520 len
= ECHOBUFSIZE
- 4;
521 bcopy (str
, current_kboard
->echobuf
, len
);
522 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
523 *current_kboard
->echoptr
= '\0';
525 current_kboard
->echo_after_prompt
= len
;
530 /* Add C to the echo string, if echoing is going on.
531 C can be a character, which is printed prettily ("M-C-x" and all that
532 jazz), or a symbol, whose name is printed. */
537 extern char *push_key_description ();
539 if (current_kboard
->immediate_echo
)
541 char *ptr
= current_kboard
->echoptr
;
543 if (ptr
!= current_kboard
->echobuf
)
546 /* If someone has passed us a composite event, use its head symbol. */
551 if (ptr
- current_kboard
->echobuf
> ECHOBUFSIZE
- 6)
554 ptr
= push_key_description (XINT (c
), ptr
);
556 else if (SYMBOLP (c
))
558 struct Lisp_String
*name
= XSYMBOL (c
)->name
;
559 if ((ptr
- current_kboard
->echobuf
) + name
->size
+ 4 > ECHOBUFSIZE
)
561 bcopy (name
->data
, ptr
, name
->size
);
565 if (current_kboard
->echoptr
== current_kboard
->echobuf
566 && EQ (c
, Vhelp_char
))
568 strcpy (ptr
, " (Type ? for further options)");
573 current_kboard
->echoptr
= ptr
;
579 /* Temporarily add a dash to the end of the echo string if it's not
580 empty, so that it serves as a mini-prompt for the very next character. */
584 if (!current_kboard
->immediate_echo
585 && current_kboard
->echoptr
== current_kboard
->echobuf
)
587 /* Do nothing if we just printed a prompt. */
588 if (current_kboard
->echo_after_prompt
589 == current_kboard
->echoptr
- current_kboard
->echobuf
)
591 /* Do nothing if not echoing at all. */
592 if (current_kboard
->echoptr
== 0)
595 /* Put a dash at the end of the buffer temporarily,
596 but make it go away when the next character is added. */
597 current_kboard
->echoptr
[0] = '-';
598 current_kboard
->echoptr
[1] = 0;
603 /* Display the current echo string, and begin echoing if not already
608 if (!current_kboard
->immediate_echo
)
611 current_kboard
->immediate_echo
= 1;
613 for (i
= 0; i
< this_command_key_count
; i
++)
616 c
= XVECTOR (this_command_keys
)->contents
[i
];
617 if (! (EVENT_HAS_PARAMETERS (c
)
618 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
625 message1_nolog (current_kboard
->echobuf
);
628 if (waiting_for_input
&& !NILP (Vquit_flag
))
629 quit_throw_to_read_char ();
632 /* Turn off echoing, for the start of a new command. */
636 current_kboard
->immediate_echo
= 0;
637 current_kboard
->echoptr
= current_kboard
->echobuf
;
638 current_kboard
->echo_after_prompt
= -1;
641 /* Return the length of the current echo string. */
646 return current_kboard
->echoptr
- current_kboard
->echobuf
;
649 /* Truncate the current echo message to its first LEN chars.
650 This and echo_char get used by read_key_sequence when the user
651 switches frames while entering a key sequence. */
657 current_kboard
->echobuf
[len
] = '\0';
658 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
659 truncate_echo_area (len
);
663 /* Functions for manipulating this_command_keys. */
665 add_command_key (key
)
668 int size
= XVECTOR (this_command_keys
)->size
;
670 if (this_command_key_count
>= size
)
672 Lisp_Object new_keys
;
674 new_keys
= Fmake_vector (make_number (size
* 2), Qnil
);
675 bcopy (XVECTOR (this_command_keys
)->contents
,
676 XVECTOR (new_keys
)->contents
,
677 size
* sizeof (Lisp_Object
));
679 this_command_keys
= new_keys
;
682 XVECTOR (this_command_keys
)->contents
[this_command_key_count
++] = key
;
688 int count
= specpdl_ptr
- specpdl
;
691 if (command_loop_level
> 0)
693 specbind (Qstandard_output
, Qt
);
694 specbind (Qstandard_input
, Qt
);
697 val
= command_loop ();
699 Fsignal (Qquit
, Qnil
);
701 return unbind_to (count
, Qnil
);
704 /* When an auto-save happens, record the "time", and don't do again soon. */
708 last_auto_save
= num_nonmacro_input_chars
;
711 /* Make an auto save happen as soon as possible at command level. */
713 force_auto_save_soon ()
715 last_auto_save
= - auto_save_interval
- 1;
717 record_asynch_buffer_change ();
720 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
721 "Invoke the editor command loop recursively.\n\
722 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
723 that tells this function to return.\n\
724 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
725 This function is called by the editor initialization to begin editing.")
728 int count
= specpdl_ptr
- specpdl
;
731 command_loop_level
++;
732 update_mode_lines
= 1;
734 record_unwind_protect (recursive_edit_unwind
,
736 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
740 return unbind_to (count
, Qnil
);
744 recursive_edit_unwind (buffer
)
748 Fset_buffer (buffer
);
750 command_loop_level
--;
751 update_mode_lines
= 1;
759 #if 0 /* Theory: if there's anything in Vunread_command_events,
760 it will right away be read by read_key_sequence,
761 and then if we do switch KBOARDS, it will go into the side
762 queue then. So we don't need to do anything special here -- rms. */
763 if (CONSP (Vunread_command_events
))
765 current_kboard
->kbd_queue
766 = nconc2 (Vunread_command_events
, current_kboard
->kbd_queue
);
767 current_kboard
->kbd_queue_has_data
= 1;
769 Vunread_command_events
= Qnil
;
775 /* Switch to the single-kboard state, making current_kboard
776 the only KBOARD from which further input is accepted. */
779 single_kboard_state ()
786 /* Maintain a stack of kboards, so other parts of Emacs
787 can switch temporarily to the kboard of a given frame
788 and then revert to the previous status. */
793 struct kboard_stack
*next
;
796 static struct kboard_stack
*kboard_stack
;
799 push_frame_kboard (f
)
803 struct kboard_stack
*p
804 = (struct kboard_stack
*) xmalloc (sizeof (struct kboard_stack
));
806 p
->next
= kboard_stack
;
807 p
->kboard
= current_kboard
;
810 current_kboard
= FRAME_KBOARD (f
);
818 struct kboard_stack
*p
= kboard_stack
;
819 current_kboard
= p
->kboard
;
820 kboard_stack
= p
->next
;
825 /* Handle errors that are not handled at inner levels
826 by printing an error message and returning to the editor command loop. */
832 Lisp_Object old_level
, old_length
;
834 Vstandard_output
= Qt
;
835 Vstandard_input
= Qt
;
836 Vexecuting_macro
= Qnil
;
837 current_kboard
->Vprefix_arg
= Qnil
;
840 /* Avoid unquittable loop if data contains a circular list. */
841 old_level
= Vprint_level
;
842 old_length
= Vprint_length
;
843 XSETFASTINT(Vprint_level
, 10);
844 XSETFASTINT(Vprint_length
, 10);
845 cmd_error_internal (data
, NULL
);
846 Vprint_level
= old_level
;
847 Vprint_length
= old_length
;
851 Vinhibit_quit
= Qnil
;
856 return make_number (0);
859 cmd_error_internal (data
, context
)
863 Lisp_Object errmsg
, tail
, errname
, file_error
;
870 echo_area_glyphs
= 0;
872 /* If the window system or terminal frame hasn't been initialized
873 yet, or we're not interactive, it's best to dump this message out
874 to stderr and exit. */
875 if (! FRAME_MESSAGE_BUF (selected_frame
)
877 stream
= Qexternal_debugging_output
;
886 write_string_1 (context
, -1, stream
);
888 errname
= Fcar (data
);
890 if (EQ (errname
, Qerror
))
893 if (!CONSP (data
)) data
= Qnil
;
894 errmsg
= Fcar (data
);
899 errmsg
= Fget (errname
, Qerror_message
);
900 file_error
= Fmemq (Qfile_error
,
901 Fget (errname
, Qerror_conditions
));
904 /* Print an error message including the data items.
905 This is done by printing it into a scratch buffer
906 and then making a copy of the text in the buffer. */
908 if (!CONSP (data
)) data
= Qnil
;
912 /* For file-error, make error message by concatenating
913 all the data items. They are all strings. */
914 if (!NILP (file_error
) && !NILP (tail
))
915 errmsg
= XCONS (tail
)->car
, tail
= XCONS (tail
)->cdr
;
917 if (STRINGP (errmsg
))
918 Fprinc (errmsg
, stream
);
920 write_string_1 ("peculiar error", -1, stream
);
922 for (i
= 0; CONSP (tail
); tail
= Fcdr (tail
), i
++)
924 write_string_1 (i
? ", " : ": ", 2, stream
);
925 if (!NILP (file_error
))
926 Fprinc (Fcar (tail
), stream
);
928 Fprin1 (Fcar (tail
), stream
);
932 /* If the window system or terminal frame hasn't been initialized
933 yet, or we're in -batch mode, this error should cause Emacs to exit. */
934 if (! FRAME_MESSAGE_BUF (selected_frame
)
938 Fkill_emacs (make_number (-1));
942 Lisp_Object
command_loop_1 ();
943 Lisp_Object
command_loop_2 ();
944 Lisp_Object
top_level_1 ();
946 /* Entry to editor-command-loop.
947 This level has the catches for exiting/returning to editor command loop.
948 It returns nil to exit recursive edit, t to abort it. */
953 if (command_loop_level
> 0 || minibuf_level
> 0)
955 return internal_catch (Qexit
, command_loop_2
, Qnil
);
960 internal_catch (Qtop_level
, top_level_1
, Qnil
);
961 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
963 /* End of file in -batch run causes exit here. */
969 /* Here we catch errors in execution of commands within the
970 editing loop, and reenter the editing loop.
971 When there is an error, cmd_error runs and returns a non-nil
972 value to us. A value of nil means that cmd_loop_1 itself
973 returned due to end of file (or end of kbd macro). */
978 register Lisp_Object val
;
981 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
990 return Feval (Vtop_level
);
996 /* On entry to the outer level, run the startup file */
997 if (!NILP (Vtop_level
))
998 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
999 else if (!NILP (Vpurify_flag
))
1000 message ("Bare impure Emacs (standard Lisp code not loaded)");
1002 message ("Bare Emacs (standard Lisp code not loaded)");
1006 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
1007 "Exit all recursive editing levels.")
1010 Fthrow (Qtop_level
, Qnil
);
1013 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
1014 "Exit from the innermost recursive edit or minibuffer.")
1017 if (command_loop_level
> 0 || minibuf_level
> 0)
1018 Fthrow (Qexit
, Qnil
);
1020 error ("No recursive edit is in progress");
1023 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
1024 "Abort the command that requested this recursive edit or minibuffer input.")
1027 if (command_loop_level
> 0 || minibuf_level
> 0)
1030 error ("No recursive edit is in progress");
1033 /* This is the actual command reading loop,
1034 sans error-handling encapsulation. */
1036 Lisp_Object
Fcommand_execute ();
1037 static int read_key_sequence ();
1038 static void safe_run_hooks ();
1043 Lisp_Object cmd
, tem
;
1046 Lisp_Object keybuf
[30];
1051 struct buffer
*prev_buffer
;
1053 int was_locked
= single_kboard
;
1056 Vdeactivate_mark
= Qnil
;
1057 waiting_for_input
= 0;
1062 this_command_key_count
= 0;
1064 /* Make sure this hook runs after commands that get errors and
1065 throw to top level. */
1066 /* Note that the value cell will never directly contain nil
1067 if the symbol is a local variable. */
1068 if (!NILP (XSYMBOL (Qpost_command_hook
)->value
) && !NILP (Vrun_hooks
))
1069 safe_run_hooks (Qpost_command_hook
);
1071 if (!NILP (Vdeferred_action_list
))
1072 call0 (Vdeferred_action_function
);
1074 /* Do this after running Vpost_command_hook, for consistency. */
1075 last_command
= this_command
;
1079 /* Make sure the current window's buffer is selected. */
1080 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1081 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1083 /* Display any malloc warning that just came out. Use while because
1084 displaying one warning can cause another. */
1086 while (pending_malloc_warning
)
1087 display_malloc_warning ();
1091 Vdeactivate_mark
= Qnil
;
1093 /* If minibuffer on and echo area in use,
1094 wait 2 sec and redraw minibuffer. */
1096 if (minibuf_level
&& echo_area_glyphs
)
1098 /* Bind inhibit-quit to t so that C-g gets read in
1099 rather than quitting back to the minibuffer. */
1100 int count
= specpdl_ptr
- specpdl
;
1101 specbind (Qinhibit_quit
, Qt
);
1102 Fsit_for (make_number (2), Qnil
, Qnil
);
1103 unbind_to (count
, Qnil
);
1105 echo_area_glyphs
= 0;
1107 if (!NILP (Vquit_flag
))
1110 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1115 alloca (0); /* Cause a garbage collection now */
1116 /* Since we can free the most stuff here. */
1117 #endif /* C_ALLOCA */
1121 /* Select the frame that the last event came from. Usually,
1122 switch-frame events will take care of this, but if some lisp
1123 code swallows a switch-frame event, we'll fix things up here.
1124 Is this a good idea? */
1125 if (FRAMEP (internal_last_event_frame
)
1126 && XFRAME (internal_last_event_frame
) != selected_frame
)
1127 Fselect_frame (internal_last_event_frame
, Qnil
);
1130 /* If it has changed current-menubar from previous value,
1131 really recompute the menubar from the value. */
1132 if (! NILP (Vlucid_menu_bar_dirty_flag
)
1133 && !NILP (Ffboundp (Qrecompute_lucid_menubar
)))
1134 call0 (Qrecompute_lucid_menubar
);
1136 /* Read next key sequence; i gets its length. */
1137 i
= read_key_sequence (keybuf
, sizeof keybuf
/ sizeof keybuf
[0],
1142 /* Now we have read a key sequence of length I,
1143 or else I is 0 and we found end of file. */
1145 if (i
== 0) /* End of file -- happens only in */
1146 return Qnil
; /* a kbd macro, at the end. */
1147 /* -1 means read_key_sequence got a menu that was rejected.
1148 Just loop around and read another command. */
1152 this_command_key_count
= 0;
1156 last_command_char
= keybuf
[i
- 1];
1158 /* If the previous command tried to force a specific window-start,
1159 forget about that, in case this command moves point far away
1160 from that position. But also throw away beg_unchanged and
1161 end_unchanged information in that case, so that redisplay will
1162 update the whole window properly. */
1163 if (!NILP (XWINDOW (selected_window
)->force_start
))
1165 XWINDOW (selected_window
)->force_start
= Qnil
;
1166 beg_unchanged
= end_unchanged
= 0;
1169 cmd
= read_key_sequence_cmd
;
1170 if (!NILP (Vexecuting_macro
))
1172 if (!NILP (Vquit_flag
))
1174 Vexecuting_macro
= Qt
;
1175 QUIT
; /* Make some noise. */
1176 /* Will return since macro now empty. */
1180 /* Do redisplay processing after this command except in special
1181 cases identified below that set no_redisplay to 1.
1182 (actually, there's currently no way to prevent the redisplay,
1183 and no_redisplay is ignored.
1184 Perhaps someday we will really implement it.) */
1187 prev_buffer
= current_buffer
;
1188 prev_modiff
= MODIFF
;
1189 last_point_position
= PT
;
1190 XSETBUFFER (last_point_position_buffer
, prev_buffer
);
1192 /* Execute the command. */
1195 /* Note that the value cell will never directly contain nil
1196 if the symbol is a local variable. */
1197 if (!NILP (XSYMBOL (Qpre_command_hook
)->value
) && !NILP (Vrun_hooks
))
1198 safe_run_hooks (Qpre_command_hook
);
1200 if (NILP (this_command
))
1202 /* nil means key is undefined. */
1204 current_kboard
->defining_kbd_macro
= Qnil
;
1205 update_mode_lines
= 1;
1206 current_kboard
->Vprefix_arg
= Qnil
;
1210 if (NILP (current_kboard
->Vprefix_arg
) && ! no_direct
)
1212 /* Recognize some common commands in common situations and
1213 do them directly. */
1214 if (EQ (this_command
, Qforward_char
) && PT
< ZV
)
1216 struct Lisp_Vector
*dp
1217 = window_display_table (XWINDOW (selected_window
));
1218 lose
= FETCH_CHAR (PT
);
1221 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1222 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1223 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1224 && (lose
>= 0x20 && lose
< 0x7f)))
1225 : (lose
>= 0x20 && lose
< 0x7f))
1226 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1228 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1230 && !windows_or_buffers_changed
1231 && EQ (current_buffer
->selective_display
, Qnil
)
1232 && !detect_input_pending ()
1233 && NILP (Vexecuting_macro
))
1234 no_redisplay
= direct_output_forward_char (1);
1237 else if (EQ (this_command
, Qbackward_char
) && PT
> BEGV
)
1239 struct Lisp_Vector
*dp
1240 = window_display_table (XWINDOW (selected_window
));
1242 lose
= FETCH_CHAR (PT
);
1244 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1245 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1246 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1247 && (lose
>= 0x20 && lose
< 0x7f)))
1248 : (lose
>= 0x20 && lose
< 0x7f))
1249 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1251 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1253 && !windows_or_buffers_changed
1254 && EQ (current_buffer
->selective_display
, Qnil
)
1255 && !detect_input_pending ()
1256 && NILP (Vexecuting_macro
))
1257 no_redisplay
= direct_output_forward_char (-1);
1260 else if (EQ (this_command
, Qself_insert_command
)
1261 /* Try this optimization only on ascii keystrokes. */
1262 && INTEGERP (last_command_char
))
1264 unsigned char c
= XINT (last_command_char
);
1267 if (NILP (Vexecuting_macro
)
1268 && !EQ (minibuf_window
, selected_window
))
1270 if (!nonundocount
|| nonundocount
>= 20)
1277 lose
= ((XFASTINT (XWINDOW (selected_window
)->last_modified
)
1279 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1281 || MODIFF
<= SAVE_MODIFF
1282 || windows_or_buffers_changed
1283 || !EQ (current_buffer
->selective_display
, Qnil
)
1284 || detect_input_pending ()
1285 || !NILP (Vexecuting_macro
));
1286 value
= internal_self_insert (c
, 0);
1293 && (PT
== ZV
|| FETCH_CHAR (PT
) == '\n'))
1295 struct Lisp_Vector
*dp
1296 = window_display_table (XWINDOW (selected_window
));
1303 obj
= DISP_CHAR_VECTOR (dp
, lose
);
1306 /* Do it only for char codes
1307 that by default display as themselves. */
1308 if (lose
>= 0x20 && lose
<= 0x7e)
1309 no_redisplay
= direct_output_for_insert (lose
);
1311 else if (VECTORP (obj
)
1312 && XVECTOR (obj
)->size
== 1
1313 && (obj
= XVECTOR (obj
)->contents
[0],
1315 /* Insist face not specified in glyph. */
1316 && (XINT (obj
) & ((-1) << 8)) == 0)
1318 = direct_output_for_insert (XINT (obj
));
1322 if (lose
>= 0x20 && lose
<= 0x7e)
1323 no_redisplay
= direct_output_for_insert (lose
);
1330 /* Here for a command that isn't executed directly */
1333 if (NILP (current_kboard
->Vprefix_arg
))
1335 Fcommand_execute (this_command
, Qnil
);
1340 /* Note that the value cell will never directly contain nil
1341 if the symbol is a local variable. */
1342 if (!NILP (XSYMBOL (Qpost_command_hook
)->value
) && !NILP (Vrun_hooks
))
1343 safe_run_hooks (Qpost_command_hook
);
1345 if (!NILP (Vdeferred_action_list
))
1346 safe_run_hooks (Qdeferred_action_function
);
1348 /* If there is a prefix argument,
1349 1) We don't want last_command to be ``universal-argument''
1350 (that would be dumb), so don't set last_command,
1351 2) we want to leave echoing on so that the prefix will be
1352 echoed as part of this key sequence, so don't call
1354 3) we want to leave this_command_key_count non-zero, so that
1355 read_char will realize that it is re-reading a character, and
1356 not echo it a second time. */
1357 if (NILP (current_kboard
->Vprefix_arg
))
1359 last_command
= this_command
;
1361 this_command_key_count
= 0;
1364 if (!NILP (current_buffer
->mark_active
) && !NILP (Vrun_hooks
))
1366 if (!NILP (Vdeactivate_mark
) && !NILP (Vtransient_mark_mode
))
1368 current_buffer
->mark_active
= Qnil
;
1369 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
1371 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
1372 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
1376 /* Install chars successfully executed in kbd macro. */
1378 if (!NILP (current_kboard
->defining_kbd_macro
)
1379 && NILP (current_kboard
->Vprefix_arg
))
1380 finalize_kbd_macro_chars ();
1384 any_kboard_state ();
1389 /* Subroutine for safe_run_hooks: run the hook HOOK. */
1392 safe_run_hooks_1 (hook
)
1395 return call1 (Vrun_hooks
, Vinhibit_quit
);
1398 /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */
1401 safe_run_hooks_error (data
)
1404 Fset (Vinhibit_quit
, Qnil
);
1407 /* If we get an error while running the hook, cause the hook variable
1408 to be nil. Also inhibit quits, so that C-g won't cause the hook
1409 to mysteriously evaporate. */
1412 safe_run_hooks (hook
)
1416 int count
= specpdl_ptr
- specpdl
;
1417 specbind (Qinhibit_quit
, hook
);
1419 internal_condition_case (safe_run_hooks_1
, Qerror
, safe_run_hooks_error
);
1421 unbind_to (count
, Qnil
);
1424 /* Number of seconds between polling for input. */
1427 /* Nonzero means polling for input is temporarily suppressed. */
1428 int poll_suppress_count
;
1430 /* Nonzero if polling_for_input is actually being used. */
1431 int polling_for_input
;
1433 #ifdef POLL_FOR_INPUT
1435 /* Handle an alarm once each second and read pending input
1436 so as to handle a C-g if it comces in. */
1439 input_poll_signal (signalnum
) /* If we don't have an argument, */
1440 int signalnum
; /* some compilers complain in signal calls. */
1442 if (interrupt_input_blocked
== 0
1443 && !waiting_for_input
)
1444 read_avail_input (0);
1445 signal (SIGALRM
, input_poll_signal
);
1446 alarm (polling_period
);
1451 /* Begin signals to poll for input, if they are appropriate.
1452 This function is called unconditionally from various places. */
1456 #ifdef POLL_FOR_INPUT
1457 if (read_socket_hook
&& !interrupt_input
)
1459 poll_suppress_count
--;
1460 if (poll_suppress_count
== 0)
1462 signal (SIGALRM
, input_poll_signal
);
1463 polling_for_input
= 1;
1464 alarm (polling_period
);
1470 /* Nonzero if we are using polling to handle input asynchronously. */
1473 input_polling_used ()
1475 #ifdef POLL_FOR_INPUT
1476 return read_socket_hook
&& !interrupt_input
;
1482 /* Turn off polling. */
1486 #ifdef POLL_FOR_INPUT
1487 if (read_socket_hook
&& !interrupt_input
)
1489 if (poll_suppress_count
== 0)
1491 polling_for_input
= 0;
1494 poll_suppress_count
++;
1499 /* Set the value of poll_suppress_count to COUNT
1500 and start or stop polling accordingly. */
1503 set_poll_suppress_count (count
)
1506 #ifdef POLL_FOR_INPUT
1507 if (count
== 0 && poll_suppress_count
!= 0)
1509 poll_suppress_count
= 1;
1512 else if (count
!= 0 && poll_suppress_count
== 0)
1516 poll_suppress_count
= count
;
1520 /* Bind polling_period to a value at least N.
1521 But don't decrease it. */
1523 bind_polling_period (n
)
1526 #ifdef POLL_FOR_INPUT
1527 int new = polling_period
;
1533 specbind (Qpolling_period
, make_number (new));
1534 /* Start a new alarm with the new period. */
1539 /* Apply the control modifier to CHARACTER. */
1545 /* Save the upper bits here. */
1546 int upper
= c
& ~0177;
1550 /* Everything in the columns containing the upper-case letters
1551 denotes a control character. */
1552 if (c
>= 0100 && c
< 0140)
1556 /* Set the shift modifier for a control char
1557 made from a shifted letter. But only for letters! */
1558 if (oc
>= 'A' && oc
<= 'Z')
1559 c
|= shift_modifier
;
1562 /* The lower-case letters denote control characters too. */
1563 else if (c
>= 'a' && c
<= 'z')
1566 /* Include the bits for control and shift
1567 only if the basic ASCII code can't indicate them. */
1571 /* Replace the high bits. */
1572 c
|= (upper
& ~ctrl_modifier
);
1579 /* Input of single characters from keyboard */
1581 Lisp_Object
print_help ();
1582 static Lisp_Object
kbd_buffer_get_event ();
1583 static void record_char ();
1586 static jmp_buf wrong_kboard_jmpbuf
;
1589 /* read a character from the keyboard; call the redisplay if needed */
1590 /* commandflag 0 means do not do auto-saving, but do do redisplay.
1591 -1 means do not do redisplay, but do do autosaving.
1594 /* The arguments MAPS and NMAPS are for menu prompting.
1595 MAPS is an array of keymaps; NMAPS is the length of MAPS.
1597 PREV_EVENT is the previous input event, or nil if we are reading
1598 the first event of a key sequence.
1600 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
1601 if we used a mouse menu to read the input, or zero otherwise. If
1602 USED_MOUSE_MENU is null, we don't dereference it.
1604 Value is t if we showed a menu and the user rejected it. */
1607 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
)
1611 Lisp_Object prev_event
;
1612 int *used_mouse_menu
;
1614 register Lisp_Object c
;
1616 jmp_buf local_getcjmp
;
1618 int key_already_recorded
= 0;
1619 Lisp_Object also_record
;
1622 if (CONSP (Vunread_command_events
))
1624 c
= XCONS (Vunread_command_events
)->car
;
1625 Vunread_command_events
= XCONS (Vunread_command_events
)->cdr
;
1627 if (this_command_key_count
== 0)
1633 if (unread_command_char
!= -1)
1635 XSETINT (c
, unread_command_char
);
1636 unread_command_char
= -1;
1638 if (this_command_key_count
== 0)
1644 if (!NILP (Vexecuting_macro
))
1647 /* We set this to Qmacro; since that's not a frame, nobody will
1648 try to switch frames on us, and the selected window will
1651 Since this event came from a macro, it would be misleading to
1652 leave internal_last_event_frame set to wherever the last
1653 real event came from. Normally, a switch-frame event selects
1654 internal_last_event_frame after each command is read, but
1655 events read from a macro should never cause a new frame to be
1657 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
1660 /* Exit the macro if we are at the end.
1661 Also, some things replace the macro with t
1662 to force an early exit. */
1663 if (EQ (Vexecuting_macro
, Qt
)
1664 || executing_macro_index
>= XFASTINT (Flength (Vexecuting_macro
)))
1670 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
1671 if (STRINGP (Vexecuting_macro
)
1672 && (XINT (c
) & 0x80))
1673 XSETFASTINT (c
, CHAR_META
| (XINT (c
) & ~0x80));
1675 executing_macro_index
++;
1680 if (!NILP (unread_switch_frame
))
1682 c
= unread_switch_frame
;
1683 unread_switch_frame
= Qnil
;
1685 /* This event should make it into this_command_keys, and get echoed
1686 again, so we go to reread_first, rather than reread. */
1690 if (commandflag
>= 0 && !input_pending
&& !detect_input_pending ())
1693 /* Message turns off echoing unless more keystrokes turn it on again. */
1694 if (echo_area_glyphs
&& *echo_area_glyphs
1695 && echo_area_glyphs
!= current_kboard
->echobuf
)
1698 /* If already echoing, continue. */
1701 /* Try reading a character via menu prompting in the minibuf.
1702 Try this before the sit-for, because the sit-for
1703 would do the wrong thing if we are supposed to do
1704 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
1705 after a mouse event so don't try a minibuf menu. */
1707 if (nmaps
> 0 && INTERACTIVE
1708 && !NILP (prev_event
) && ! EVENT_HAS_PARAMETERS (prev_event
)
1709 /* Don't bring up a menu if we already have another event. */
1710 && NILP (Vunread_command_events
)
1711 && unread_command_char
< 0
1712 && !detect_input_pending ())
1714 c
= read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
);
1717 key_already_recorded
= 1;
1722 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet.
1723 We will do that below, temporarily for short sections of code,
1724 when appropriate. local_getcjmp must be in effect
1725 around any call to sit_for or kbd_buffer_get_event;
1726 it *must not* be in effect when we call redisplay. */
1728 if (_setjmp (local_getcjmp
))
1730 XSETINT (c
, quit_char
);
1732 XSETFRAME (internal_last_event_frame
, selected_frame
);
1733 Vlast_event_frame
= internal_last_event_frame
;
1735 /* If we report the quit char as an event,
1736 don't do so more than once. */
1737 if (!NILP (Vinhibit_quit
))
1742 KBOARD
*kb
= FRAME_KBOARD (selected_frame
);
1743 if (kb
!= current_kboard
)
1745 Lisp_Object
*tailp
= &kb
->kbd_queue
;
1746 /* We shouldn't get here if we were in single-kboard mode! */
1749 while (CONSP (*tailp
))
1750 tailp
= &XCONS (*tailp
)->cdr
;
1753 *tailp
= Fcons (c
, Qnil
);
1754 kb
->kbd_queue_has_data
= 1;
1755 current_kboard
= kb
;
1756 longjmp (wrong_kboard_jmpbuf
, 1);
1763 /* If in middle of key sequence and minibuffer not active,
1764 start echoing if enough time elapses. */
1766 if (minibuf_level
== 0 && !current_kboard
->immediate_echo
1767 && this_command_key_count
> 0
1769 && echo_keystrokes
> 0
1770 && (echo_area_glyphs
== 0 || *echo_area_glyphs
== 0))
1774 /* After a mouse event, start echoing right away.
1775 This is because we are probably about to display a menu,
1776 and we don't want to delay before doing so. */
1777 if (EVENT_HAS_PARAMETERS (prev_event
))
1781 save_getcjmp (save_jump
);
1782 restore_getcjmp (local_getcjmp
);
1783 tem0
= sit_for (echo_keystrokes
, 0, 1, 1);
1784 restore_getcjmp (save_jump
);
1790 /* Maybe auto save due to number of keystrokes. */
1792 if (commandflag
!= 0
1793 && auto_save_interval
> 0
1794 && num_nonmacro_input_chars
- last_auto_save
> max (auto_save_interval
, 20)
1795 && !detect_input_pending ())
1797 Fdo_auto_save (Qnil
, Qnil
);
1798 /* Hooks can actually change some buffers in auto save. */
1802 /* Try reading using an X menu.
1803 This is never confused with reading using the minibuf
1804 because the recursive call of read_char in read_char_minibuf_menu_prompt
1805 does not pass on any keymaps. */
1807 if (nmaps
> 0 && INTERACTIVE
1808 && !NILP (prev_event
)
1809 && EVENT_HAS_PARAMETERS (prev_event
)
1810 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
)
1811 /* Don't bring up a menu if we already have another event. */
1812 && NILP (Vunread_command_events
)
1813 && unread_command_char
< 0)
1814 c
= read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
1816 /* Maybe autosave and/or garbage collect due to idleness. */
1818 if (INTERACTIVE
&& NILP (c
))
1820 int delay_level
, buffer_size
;
1822 /* Slow down auto saves logarithmically in size of current buffer,
1823 and garbage collect while we're at it. */
1824 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
1825 last_non_minibuf_size
= Z
- BEG
;
1826 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
1828 while (buffer_size
> 64)
1829 delay_level
++, buffer_size
-= buffer_size
>> 2;
1830 if (delay_level
< 4) delay_level
= 4;
1831 /* delay_level is 4 for files under around 50k, 7 at 100k,
1832 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
1834 /* Auto save if enough time goes by without input. */
1835 if (commandflag
!= 0
1836 && num_nonmacro_input_chars
> last_auto_save
1837 && INTEGERP (Vauto_save_timeout
)
1838 && XINT (Vauto_save_timeout
) > 0)
1841 int delay
= delay_level
* XFASTINT (Vauto_save_timeout
) / 4;
1843 save_getcjmp (save_jump
);
1844 restore_getcjmp (local_getcjmp
);
1845 tem0
= sit_for (delay
, 0, 1, 1);
1846 restore_getcjmp (save_jump
);
1850 Fdo_auto_save (Qnil
, Qnil
);
1852 /* If we have auto-saved and there is still no input
1853 available, garbage collect if there has been enough
1854 consing going on to make it worthwhile. */
1855 if (!detect_input_pending ()
1856 && consing_since_gc
> gc_cons_threshold
/ 2)
1857 Fgarbage_collect ();
1864 /* Read something from current KBOARD's side queue, if possible. */
1868 if (current_kboard
->kbd_queue_has_data
)
1870 if (!CONSP (current_kboard
->kbd_queue
))
1872 c
= XCONS (current_kboard
->kbd_queue
)->car
;
1873 current_kboard
->kbd_queue
1874 = XCONS (current_kboard
->kbd_queue
)->cdr
;
1875 if (NILP (current_kboard
->kbd_queue
))
1876 current_kboard
->kbd_queue_has_data
= 0;
1877 input_pending
= readable_events ();
1879 if (EVENT_HAS_PARAMETERS (c
)
1880 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qswitch_frame
))
1881 internal_last_event_frame
= XCONS (XCONS (c
)->cdr
)->car
;
1882 Vlast_event_frame
= internal_last_event_frame
;
1888 /* If current_kboard's side queue is empty check the other kboards.
1889 If one of them has data that we have not yet seen here,
1890 switch to it and process the data waiting for it.
1892 Note: if the events queued up for another kboard
1893 have already been seen here, and therefore are not a complete command,
1894 the kbd_queue_has_data field is 0, so we skip that kboard here.
1895 That's to avoid an infinite loop switching between kboards here. */
1896 if (NILP (c
) && !single_kboard
)
1899 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
1900 if (kb
->kbd_queue_has_data
)
1902 current_kboard
= kb
;
1903 longjmp (wrong_kboard_jmpbuf
, 1);
1912 /* Finally, we read from the main queue,
1913 and if that gives us something we can't use yet, we put it on the
1914 appropriate side queue and try again. */
1920 /* Actually read a character, waiting if necessary. */
1921 save_getcjmp (save_jump
);
1922 restore_getcjmp (local_getcjmp
);
1923 c
= kbd_buffer_get_event (&kb
, used_mouse_menu
);
1924 restore_getcjmp (save_jump
);
1927 if (! NILP (c
) && (kb
!= current_kboard
))
1929 Lisp_Object
*tailp
= &kb
->kbd_queue
;
1930 while (CONSP (*tailp
))
1931 tailp
= &XCONS (*tailp
)->cdr
;
1934 *tailp
= Fcons (c
, Qnil
);
1935 kb
->kbd_queue_has_data
= 1;
1939 current_kboard
= kb
;
1940 longjmp (wrong_kboard_jmpbuf
, 1);
1945 /* Terminate Emacs in batch mode if at eof. */
1946 if (noninteractive
&& INTEGERP (c
) && XINT (c
) < 0)
1947 Fkill_emacs (make_number (1));
1951 /* Add in any extra modifiers, where appropriate. */
1952 if ((extra_keyboard_modifiers
& CHAR_CTL
)
1953 || ((extra_keyboard_modifiers
& 0177) < ' '
1954 && (extra_keyboard_modifiers
& 0177) != 0))
1955 XSETINT (c
, make_ctrl_char (XINT (c
)));
1957 /* Transfer any other modifier bits directly from
1958 extra_keyboard_modifiers to c. Ignore the actual character code
1959 in the low 16 bits of extra_keyboard_modifiers. */
1960 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
1969 if (commandflag
>= 0
1970 && !input_pending
&& !detect_input_pending ())
1978 /* Buffer switch events are only for internal wakeups
1979 so don't show them to the user. */
1983 if (key_already_recorded
)
1986 /* Wipe the echo area. */
1987 echo_area_glyphs
= 0;
1989 /* Handle things that only apply to characters. */
1992 /* If kbd_buffer_get_event gave us an EOF, return that. */
1996 if (STRINGP (Vkeyboard_translate_table
)
1997 && XSTRING (Vkeyboard_translate_table
)->size
> XFASTINT (c
))
1998 XSETINT (c
, XSTRING (Vkeyboard_translate_table
)->data
[XFASTINT (c
)]);
2001 /* If this event is a mouse click in the menu bar,
2002 return just menu-bar for now. Modify the mouse click event
2003 so we won't do this twice, then queue it up. */
2004 if (EVENT_HAS_PARAMETERS (c
)
2005 && CONSP (XCONS (c
)->cdr
)
2006 && CONSP (EVENT_START (c
))
2007 && CONSP (XCONS (EVENT_START (c
))->cdr
))
2011 posn
= POSN_BUFFER_POSN (EVENT_START (c
));
2012 /* Handle menu-bar events:
2013 insert the dummy prefix event `menu-bar'. */
2014 if (EQ (posn
, Qmenu_bar
))
2016 /* Change menu-bar to (menu-bar) as the event "position". */
2017 POSN_BUFFER_POSN (EVENT_START (c
)) = Fcons (posn
, Qnil
);
2020 Vunread_command_events
= Fcons (c
, Vunread_command_events
);
2026 if (! NILP (also_record
))
2027 record_char (also_record
);
2032 /* Don't echo mouse motion events. */
2034 && ! (EVENT_HAS_PARAMETERS (c
)
2035 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
2038 if (! NILP (also_record
))
2039 echo_char (also_record
);
2042 /* Record this character as part of the current key. */
2043 add_command_key (c
);
2044 if (! NILP (also_record
))
2045 add_command_key (also_record
);
2047 /* Re-reading in the middle of a command */
2049 last_input_char
= c
;
2052 /* Process the help character specially if enabled */
2053 if (EQ (c
, Vhelp_char
) && !NILP (Vhelp_form
))
2056 count
= specpdl_ptr
- specpdl
;
2058 record_unwind_protect (Fset_window_configuration
,
2059 Fcurrent_window_configuration (Qnil
));
2061 tem0
= Feval (Vhelp_form
);
2063 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
2067 c
= read_char (0, 0, 0, Qnil
, 0);
2068 while (BUFFERP (c
));
2069 /* Remove the help from the frame */
2070 unbind_to (count
, Qnil
);
2073 if (EQ (c
, make_number (040)))
2077 c
= read_char (0, 0, 0, Qnil
, 0);
2078 while (BUFFERP (c
));
2085 /* Record the input event C in various ways. */
2092 XVECTOR (recent_keys
)->contents
[recent_keys_index
] = c
;
2093 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
2094 recent_keys_index
= 0;
2096 /* Write c to the dribble file. If c is a lispy event, write
2097 the event's symbol to the dribble file, in <brackets>. Bleaugh.
2098 If you, dear reader, have a better idea, you've got the source. :-) */
2103 if (XUINT (c
) < 0x100)
2104 putc (XINT (c
), dribble
);
2106 fprintf (dribble
, " 0x%x", (int) XUINT (c
));
2110 Lisp_Object dribblee
;
2112 /* If it's a structured event, take the event header. */
2113 dribblee
= EVENT_HEAD (c
);
2115 if (SYMBOLP (dribblee
))
2117 putc ('<', dribble
);
2118 fwrite (XSYMBOL (dribblee
)->name
->data
, sizeof (char),
2119 XSYMBOL (dribblee
)->name
->size
,
2121 putc ('>', dribble
);
2128 store_kbd_macro_char (c
);
2130 num_nonmacro_input_chars
++;
2137 struct buffer
*old
= current_buffer
;
2138 Fprinc (object
, Qnil
);
2139 set_buffer_internal (XBUFFER (Vstandard_output
));
2140 call0 (intern ("help-mode"));
2141 set_buffer_internal (old
);
2145 /* Copy out or in the info on where C-g should throw to.
2146 This is used when running Lisp code from within get_char,
2147 in case get_char is called recursively.
2148 See read_process_output. */
2153 bcopy (getcjmp
, temp
, sizeof getcjmp
);
2156 restore_getcjmp (temp
)
2159 bcopy (temp
, getcjmp
, sizeof getcjmp
);
2164 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
2165 of this function. */
2168 tracking_off (old_value
)
2169 Lisp_Object old_value
;
2171 do_mouse_tracking
= old_value
;
2172 if (NILP (old_value
))
2174 /* Redisplay may have been preempted because there was input
2175 available, and it assumes it will be called again after the
2176 input has been processed. If the only input available was
2177 the sort that we have just disabled, then we need to call
2179 if (!readable_events ())
2181 redisplay_preserve_echo_area ();
2182 get_input_pending (&input_pending
);
2187 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
2188 "Evaluate BODY with mouse movement events enabled.\n\
2189 Within a `track-mouse' form, mouse motion generates input events that\n\
2190 you can read with `read-event'.\n\
2191 Normally, mouse motion is ignored.")
2195 int count
= specpdl_ptr
- specpdl
;
2198 record_unwind_protect (tracking_off
, do_mouse_tracking
);
2200 XSETFRAME (do_mouse_tracking
, selected_frame
);
2202 val
= Fprogn (args
);
2203 return unbind_to (count
, val
);
2206 #endif /* HAVE_MOUSE */
2208 /* Low level keyboard/mouse input.
2209 kbd_buffer_store_event places events in kbd_buffer, and
2210 kbd_buffer_get_event retrieves them.
2211 mouse_moved indicates when the mouse has moved again, and
2212 *mouse_position_hook provides the mouse position. */
2214 /* Return true iff there are any events in the queue that read-char
2215 would return. If this returns false, a read-char would block. */
2219 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2222 if (FRAMEP (do_mouse_tracking
) && mouse_moved
)
2227 if (current_kboard
->kbd_queue_has_data
)
2233 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2234 if (kb
->kbd_queue_has_data
)
2240 /* Set this for debugging, to have a way to get out */
2245 event_to_kboard (event
)
2246 struct input_event
*event
;
2249 frame
= event
->frame_or_window
;
2251 frame
= XCONS (frame
)->car
;
2252 else if (WINDOWP (frame
))
2253 frame
= WINDOW_FRAME (XWINDOW (frame
));
2255 /* There are still some events that don't set this field.
2256 For now, just ignore the problem.
2257 Also ignore dead frames here. */
2258 if (!FRAMEP (frame
) || !FRAME_LIVE_P (XFRAME (frame
)))
2261 return FRAME_KBOARD (XFRAME (frame
));
2265 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
2268 kbd_buffer_store_event (event
)
2269 register struct input_event
*event
;
2271 if (event
->kind
== no_event
)
2274 if (event
->kind
== ascii_keystroke
)
2276 register int c
= event
->code
& 0377;
2278 if (event
->modifiers
& ctrl_modifier
)
2279 c
= make_ctrl_char (c
);
2281 c
|= (event
->modifiers
2282 & (meta_modifier
| alt_modifier
2283 | hyper_modifier
| super_modifier
));
2287 extern SIGTYPE
interrupt_signal ();
2290 struct input_event
*sp
;
2293 && (kb
= FRAME_KBOARD (XFRAME (event
->frame_or_window
)),
2294 kb
!= current_kboard
))
2297 = Fcons (make_lispy_switch_frame (event
->frame_or_window
),
2298 Fcons (make_number (c
), Qnil
));
2299 kb
->kbd_queue_has_data
= 1;
2300 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
2302 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
2305 if (event_to_kboard (sp
) == kb
)
2307 sp
->kind
= no_event
;
2308 sp
->frame_or_window
= Qnil
;
2316 /* If this results in a quit_char being returned to Emacs as
2317 input, set Vlast_event_frame properly. If this doesn't
2318 get returned to Emacs as an event, the next event read
2319 will set Vlast_event_frame again, so this is safe to do. */
2323 focus
= FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
2325 focus
= event
->frame_or_window
;
2326 internal_last_event_frame
= focus
;
2327 Vlast_event_frame
= focus
;
2331 last_event_timestamp
= event
->timestamp
;
2332 interrupt_signal ();
2336 if (c
&& c
== stop_character
)
2343 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
2344 kbd_store_ptr
= kbd_buffer
;
2346 /* Don't let the very last slot in the buffer become full,
2347 since that would make the two pointers equal,
2348 and that is indistinguishable from an empty buffer.
2349 Discard the event if it would fill the last slot. */
2350 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
2352 volatile struct input_event
*sp
= kbd_store_ptr
;
2353 sp
->kind
= event
->kind
;
2354 if (event
->kind
== selection_request_event
)
2356 /* We must not use the ordinary copying code for this case,
2357 since `part' is an enum and copying it might not copy enough
2359 bcopy (event
, (char *) sp
, sizeof (*event
));
2363 sp
->code
= event
->code
;
2364 sp
->part
= event
->part
;
2365 sp
->frame_or_window
= event
->frame_or_window
;
2366 sp
->modifiers
= event
->modifiers
;
2369 sp
->timestamp
= event
->timestamp
;
2371 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_store_ptr
2373 = event
->frame_or_window
);
2379 /* Read one event from the event buffer, waiting if necessary.
2380 The value is a Lisp object representing the event.
2381 The value is nil for an event that should be ignored,
2382 or that was handled here.
2383 We always read and discard one event. */
2386 kbd_buffer_get_event (kbp
, used_mouse_menu
)
2388 int *used_mouse_menu
;
2397 *kbp
= current_kboard
;
2401 /* Wait until there is input available. */
2404 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2407 if (FRAMEP (do_mouse_tracking
) && mouse_moved
)
2411 /* If the quit flag is set, then read_char will return
2412 quit_char, so that counts as "available input." */
2413 if (!NILP (Vquit_flag
))
2414 quit_throw_to_read_char ();
2416 /* One way or another, wait until input is available; then, if
2417 interrupt handlers have not read it, read it now. */
2420 wait_for_kbd_input ();
2422 /* Note SIGIO has been undef'd if FIONREAD is missing. */
2426 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2429 if (FRAMEP (do_mouse_tracking
) && mouse_moved
)
2433 Lisp_Object minus_one
;
2435 XSETINT (minus_one
, -1);
2436 wait_reading_process_input (0, 0, minus_one
, 1);
2438 if (!interrupt_input
&& kbd_fetch_ptr
== kbd_store_ptr
)
2439 /* Pass 1 for EXPECT since we just waited to have input. */
2440 read_avail_input (1);
2442 #endif /* not VMS */
2445 /* At this point, we know that there is a readable event available
2446 somewhere. If the event queue is empty, then there must be a
2447 mouse movement enabled and available. */
2448 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2450 struct input_event
*event
;
2452 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2456 last_event_timestamp
= event
->timestamp
;
2459 *kbp
= event_to_kboard (event
);
2461 *kbp
= current_kboard
; /* Better than returning null ptr? */
2463 *kbp
= &the_only_kboard
;
2468 /* These two kinds of events get special handling
2469 and don't actually appear to the command loop.
2470 We return nil for them. */
2471 if (event
->kind
== selection_request_event
)
2474 struct input_event copy
;
2476 /* Remove it from the buffer before processing it,
2477 since otherwise swallow_events will see it
2478 and process it again. */
2480 kbd_fetch_ptr
= event
+ 1;
2481 x_handle_selection_request (©
);
2483 /* We're getting selection request events, but we don't have
2489 else if (event
->kind
== selection_clear_event
)
2492 x_handle_selection_clear (event
);
2493 kbd_fetch_ptr
= event
+ 1;
2495 /* We're getting selection request events, but we don't have
2501 else if (event
->kind
== delete_window_event
)
2503 /* Make an event (delete-frame (FRAME)). */
2504 obj
= Fcons (event
->frame_or_window
, Qnil
);
2505 obj
= Fcons (Qdelete_frame
, Fcons (obj
, Qnil
));
2506 kbd_fetch_ptr
= event
+ 1;
2508 else if (event
->kind
== iconify_event
)
2510 /* Make an event (iconify-frame (FRAME)). */
2511 obj
= Fcons (event
->frame_or_window
, Qnil
);
2512 obj
= Fcons (Qiconify_frame
, Fcons (obj
, Qnil
));
2513 kbd_fetch_ptr
= event
+ 1;
2515 else if (event
->kind
== deiconify_event
)
2517 /* Make an event (make-frame-visible (FRAME)). */
2518 obj
= Fcons (event
->frame_or_window
, Qnil
);
2519 obj
= Fcons (Qmake_frame_visible
, Fcons (obj
, Qnil
));
2520 kbd_fetch_ptr
= event
+ 1;
2523 else if (event
->kind
== buffer_switch_event
)
2525 /* The value doesn't matter here; only the type is tested. */
2526 XSETBUFFER (obj
, current_buffer
);
2527 kbd_fetch_ptr
= event
+ 1;
2529 /* Just discard these, by returning nil.
2530 With MULTI_KBOARD, these events are used as placeholders
2531 when we need to randomly delete events from the queue.
2532 (They shouldn't otherwise be found in the buffer,
2533 but on some machines it appears they do show up
2534 even without MULTI_KBOARD.) */
2535 else if (event
->kind
== no_event
)
2536 kbd_fetch_ptr
= event
+ 1;
2538 /* If this event is on a different frame, return a switch-frame this
2539 time, and leave the event in the queue for next time. */
2546 frame
= event
->frame_or_window
;
2548 frame
= XCONS (frame
)->car
;
2549 else if (WINDOWP (frame
))
2550 frame
= WINDOW_FRAME (XWINDOW (frame
));
2552 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
2556 if (! EQ (frame
, internal_last_event_frame
)
2557 && XFRAME (frame
) != selected_frame
)
2558 obj
= make_lispy_switch_frame (frame
);
2559 internal_last_event_frame
= frame
;
2560 #endif /* MULTI_FRAME */
2562 /* If we didn't decide to make a switch-frame event, go ahead
2563 and build a real event from the queue entry. */
2567 obj
= make_lispy_event (event
);
2568 #ifdef USE_X_TOOLKIT
2569 /* If this was a menu selection, then set the flag to inhibit
2570 writing to last_nonmenu_event. Don't do this if the event
2571 we're returning is (menu-bar), though; that indicates the
2572 beginning of the menu sequence, and we might as well leave
2573 that as the `event with parameters' for this selection. */
2574 if (event
->kind
== menu_bar_event
2575 && !(CONSP (obj
) && EQ (XCONS (obj
)->car
, Qmenu_bar
))
2577 *used_mouse_menu
= 1;
2580 /* Wipe out this event, to catch bugs. */
2581 event
->kind
= no_event
;
2582 XVECTOR (kbd_buffer_frame_or_window
)->contents
[event
- kbd_buffer
] = Qnil
;
2584 kbd_fetch_ptr
= event
+ 1;
2589 /* Try generating a mouse motion event. */
2590 else if (FRAMEP (do_mouse_tracking
) && mouse_moved
)
2592 FRAME_PTR f
= XFRAME (do_mouse_tracking
);
2593 Lisp_Object bar_window
;
2594 enum scroll_bar_part part
;
2598 *kbp
= current_kboard
;
2599 /* Note that this uses F to determine which display to look at.
2600 If there is no valid info, it does not store anything
2601 so x remains nil. */
2603 (*mouse_position_hook
) (&f
, 0, &bar_window
, &part
, &x
, &y
, &time
);
2608 /* Decide if we should generate a switch-frame event. Don't
2609 generate switch-frame events for motion outside of all Emacs
2615 frame
= FRAME_FOCUS_FRAME (f
);
2617 XSETFRAME (frame
, f
);
2619 if (! EQ (frame
, internal_last_event_frame
)
2620 && XFRAME (frame
) != selected_frame
)
2621 obj
= make_lispy_switch_frame (frame
);
2622 internal_last_event_frame
= frame
;
2626 /* If we didn't decide to make a switch-frame event, go ahead and
2627 return a mouse-motion event. */
2628 if (!NILP (x
) && NILP (obj
))
2629 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
2631 #endif /* HAVE_MOUSE */
2633 /* We were promised by the above while loop that there was
2634 something for us to read! */
2637 input_pending
= readable_events ();
2640 Vlast_event_frame
= internal_last_event_frame
;
2646 /* Process any events that are not user-visible,
2647 then return, without reading any user-visible events. */
2652 while (kbd_fetch_ptr
!= kbd_store_ptr
)
2654 struct input_event
*event
;
2656 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2660 last_event_timestamp
= event
->timestamp
;
2662 /* These two kinds of events get special handling
2663 and don't actually appear to the command loop. */
2664 if (event
->kind
== selection_request_event
)
2667 struct input_event copy
;
2669 kbd_fetch_ptr
= event
+ 1;
2670 x_handle_selection_request (©
);
2672 /* We're getting selection request events, but we don't have
2678 else if (event
->kind
== selection_clear_event
)
2681 x_handle_selection_clear (event
);
2682 kbd_fetch_ptr
= event
+ 1;
2684 /* We're getting selection request events, but we don't have
2693 get_input_pending (&input_pending
);
2696 /* Caches for modify_event_symbol. */
2697 static Lisp_Object accent_key_syms
;
2698 static Lisp_Object system_key_syms
;
2699 static Lisp_Object func_key_syms
;
2700 static Lisp_Object mouse_syms
;
2702 /* This is a list of keysym codes for special "accent" characters.
2703 It parallels lispy_accent_keys. */
2705 static int lispy_accent_codes
[] =
2707 #ifdef XK_dead_circumflex
2712 #ifdef XK_dead_grave
2717 #ifdef XK_dead_tilde
2722 #ifdef XK_dead_diaeresis
2727 #ifdef XK_dead_macron
2732 #ifdef XK_dead_degree
2737 #ifdef XK_dead_acute
2742 #ifdef XK_dead_cedilla
2747 #ifdef XK_dead_breve
2752 #ifdef XK_dead_ogonek
2757 #ifdef XK_dead_caron
2762 #ifdef XK_dead_doubleacute
2763 XK_dead_doubleacute
,
2767 #ifdef XK_dead_abovedot
2774 /* This is a list of Lisp names for special "accent" characters.
2775 It parallels lispy_accent_codes. */
2777 static char *lispy_accent_keys
[] =
2794 /* You'll notice that this table is arranged to be conveniently
2795 indexed by X Windows keysym values. */
2796 static char *lispy_function_keys
[] =
2798 /* X Keysym value */
2800 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00 */
2808 0, 0, 0, /* 0xff10 */
2810 0, 0, 0, 0, 0, 0, 0,
2813 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff20...2f */
2814 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff30...3f */
2815 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
2817 "home", /* 0xff50 */ /* IsCursorKey */
2828 "select", /* 0xff60 */ /* IsMiscFunctionKey */
2839 "break", /* 0xff6b */
2841 0, 0, 0, 0, 0, 0, 0, 0, "backtab", 0,
2843 0, 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff7f */
2844 "kp-space", /* 0xff80 */ /* IsKeypadKey */
2845 0, 0, 0, 0, 0, 0, 0, 0,
2846 "kp-tab", /* 0xff89 */
2848 "kp-enter", /* 0xff8d */
2850 "kp-f1", /* 0xff91 */
2854 "kp-home", /* 0xff95 */
2859 "kp-prior", /* kp-page-up */
2860 "kp-next", /* kp-page-down */
2866 0, 0, 0, 0, 0, 0, 0, 0, 0,
2867 "kp-multiply", /* 0xffaa */
2872 "kp-divide", /* 0xffaf */
2873 "kp-0", /* 0xffb0 */
2874 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
2877 "kp-equal", /* 0xffbd */
2878 "f1", /* 0xffbe */ /* IsFunctionKey */
2880 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
2881 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
2882 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
2883 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
2884 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
2885 0, 0, 0, 0, 0, 0, 0, 0,
2886 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
2887 0, 0, 0, 0, 0, 0, 0, "delete"
2890 static char *lispy_mouse_names
[] =
2892 "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5"
2895 /* Scroll bar parts. */
2896 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
2898 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
2899 Lisp_Object
*scroll_bar_parts
[] = {
2900 &Qabove_handle
, &Qhandle
, &Qbelow_handle
2904 /* A vector, indexed by button number, giving the down-going location
2905 of currently depressed buttons, both scroll bar and non-scroll bar.
2907 The elements have the form
2908 (BUTTON-NUMBER MODIFIER-MASK . REST)
2909 where REST is the cdr of a position as it would be reported in the event.
2911 The make_lispy_event function stores positions here to tell the
2912 difference between click and drag events, and to store the starting
2913 location to be included in drag events. */
2915 static Lisp_Object button_down_location
;
2917 /* Information about the most recent up-going button event: Which
2918 button, what location, and what time. */
2920 static int last_mouse_button
;
2921 static int last_mouse_x
;
2922 static int last_mouse_y
;
2923 static unsigned long button_down_time
;
2925 /* The maximum time between clicks to make a double-click,
2926 or Qnil to disable double-click detection,
2927 or Qt for no time limit. */
2928 Lisp_Object Vdouble_click_time
;
2930 /* The number of clicks in this multiple-click. */
2932 int double_click_count
;
2934 /* Given a struct input_event, build the lisp event which represents
2935 it. If EVENT is 0, build a mouse movement event from the mouse
2936 movement buffer, which should have a movement event in it.
2938 Note that events must be passed to this function in the order they
2939 are received; this function stores the location of button presses
2940 in order to build drag events when the button is released. */
2943 make_lispy_event (event
)
2944 struct input_event
*event
;
2948 switch (SWITCH_ENUM_CAST (event
->kind
))
2950 /* A simple keystroke. */
2951 case ascii_keystroke
:
2953 Lisp_Object lispy_c
;
2954 int c
= event
->code
& 0377;
2955 /* Turn ASCII characters into control characters
2957 if (event
->modifiers
& ctrl_modifier
)
2958 c
= make_ctrl_char (c
);
2960 /* Add in the other modifier bits. We took care of ctrl_modifier
2961 just above, and the shift key was taken care of by the X code,
2962 and applied to control characters by make_ctrl_char. */
2963 c
|= (event
->modifiers
2964 & (meta_modifier
| alt_modifier
2965 | hyper_modifier
| super_modifier
));
2966 button_down_time
= 0;
2967 XSETFASTINT (lispy_c
, c
);
2971 /* A function key. The symbol may need to have modifier prefixes
2973 case non_ascii_keystroke
:
2974 button_down_time
= 0;
2976 for (i
= 0; i
< sizeof (lispy_accent_codes
) / sizeof (int); i
++)
2977 if (event
->code
== lispy_accent_codes
[i
])
2978 return modify_event_symbol (i
,
2980 Qfunction_key
, Qnil
,
2981 lispy_accent_keys
, &accent_key_syms
,
2982 (sizeof (lispy_accent_keys
)
2983 / sizeof (lispy_accent_keys
[0])));
2985 /* Handle system-specific keysyms. */
2986 if (event
->code
& (1 << 28))
2988 /* We need to use an alist rather than a vector as the cache
2989 since we can't make a vector long enuf. */
2990 if (NILP (system_key_syms
))
2991 system_key_syms
= Fcons (Qnil
, Qnil
);
2992 return modify_event_symbol (event
->code
& 0xffffff,
2995 current_kboard
->Vsystem_key_alist
,
2996 0, &system_key_syms
, 0xffffff);
2999 return modify_event_symbol (event
->code
- 0xff00,
3001 Qfunction_key
, Qnil
,
3002 lispy_function_keys
, &func_key_syms
,
3003 (sizeof (lispy_function_keys
)
3004 / sizeof (lispy_function_keys
[0])));
3008 /* A mouse click. Figure out where it is, decide whether it's
3009 a press, click or drag, and build the appropriate structure. */
3011 case scroll_bar_click
:
3013 int button
= event
->code
;
3015 Lisp_Object position
;
3016 Lisp_Object
*start_pos_ptr
;
3017 Lisp_Object start_pos
;
3019 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
3022 /* Build the position as appropriate for this mouse click. */
3023 if (event
->kind
== mouse_click
)
3026 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
3031 /* Ignore mouse events that were made on frame that
3032 have been deleted. */
3033 if (! FRAME_LIVE_P (f
))
3036 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
3037 &column
, &row
, NULL
, 1);
3039 #ifndef USE_X_TOOLKIT
3040 /* In the non-toolkit version, clicks on the menu bar
3041 are ordinary button events in the event buffer.
3042 Distinguish them, and invoke the menu.
3044 (In the toolkit version, the toolkit handles the menu bar
3045 and Emacs doesn't know about it until after the user
3046 makes a selection.) */
3047 if (row
>= 0 && row
< FRAME_MENU_BAR_LINES (f
))
3049 Lisp_Object items
, item
;
3053 /* Activate the menu bar on the down event. If the
3054 up event comes in before the menu code can deal with it,
3056 if (! (event
->modifiers
& down_modifier
))
3060 items
= FRAME_MENU_BAR_ITEMS (f
);
3061 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 3)
3063 Lisp_Object pos
, string
;
3064 string
= XVECTOR (items
)->contents
[i
+ 1];
3065 pos
= XVECTOR (items
)->contents
[i
+ 2];
3068 if (column
>= XINT (pos
)
3069 && column
< XINT (pos
) + XSTRING (string
)->size
)
3071 item
= XVECTOR (items
)->contents
[i
];
3077 = Fcons (event
->frame_or_window
,
3079 Fcons (Fcons (event
->x
, event
->y
),
3080 Fcons (make_number (event
->timestamp
),
3083 return Fcons (item
, Fcons (position
, Qnil
));
3085 #endif /* not USE_X_TOOLKIT */
3087 window
= window_from_coordinates (f
, column
, row
, &part
);
3089 if (!WINDOWP (window
))
3091 window
= event
->frame_or_window
;
3096 int pixcolumn
, pixrow
;
3097 column
-= XINT (XWINDOW (window
)->left
);
3098 row
-= XINT (XWINDOW (window
)->top
);
3099 glyph_to_pixel_coords (f
, column
, row
, &pixcolumn
, &pixrow
);
3100 XSETINT (event
->x
, pixcolumn
);
3101 XSETINT (event
->y
, pixrow
);
3106 posn
= Qvertical_line
;
3109 buffer_posn_from_coords (XWINDOW (window
),
3116 Fcons (Fcons (event
->x
, event
->y
),
3117 Fcons (make_number (event
->timestamp
),
3123 Lisp_Object portion_whole
;
3126 window
= event
->frame_or_window
;
3127 portion_whole
= Fcons (event
->x
, event
->y
);
3128 part
= *scroll_bar_parts
[(int) event
->part
];
3132 Fcons (Qvertical_scroll_bar
,
3133 Fcons (portion_whole
,
3134 Fcons (make_number (event
->timestamp
),
3135 Fcons (part
, Qnil
)))));
3138 start_pos_ptr
= &XVECTOR (button_down_location
)->contents
[button
];
3140 start_pos
= *start_pos_ptr
;
3141 *start_pos_ptr
= Qnil
;
3143 is_double
= (button
== last_mouse_button
3144 && XINT (event
->x
) == last_mouse_x
3145 && XINT (event
->y
) == last_mouse_y
3146 && button_down_time
!= 0
3147 && (EQ (Vdouble_click_time
, Qt
)
3148 || (INTEGERP (Vdouble_click_time
)
3149 && ((int)(event
->timestamp
- button_down_time
)
3150 < XINT (Vdouble_click_time
)))));
3151 last_mouse_button
= button
;
3152 last_mouse_x
= XINT (event
->x
);
3153 last_mouse_y
= XINT (event
->y
);
3155 /* If this is a button press, squirrel away the location, so
3156 we can decide later whether it was a click or a drag. */
3157 if (event
->modifiers
& down_modifier
)
3161 double_click_count
++;
3162 event
->modifiers
|= ((double_click_count
> 2)
3167 double_click_count
= 1;
3168 button_down_time
= event
->timestamp
;
3169 *start_pos_ptr
= Fcopy_alist (position
);
3172 /* Now we're releasing a button - check the co-ordinates to
3173 see if this was a click or a drag. */
3174 else if (event
->modifiers
& up_modifier
)
3176 /* If we did not see a down before this up,
3177 ignore the up. Probably this happened because
3178 the down event chose a menu item.
3179 It would be an annoyance to treat the release
3180 of the button that chose the menu item
3181 as a separate event. */
3183 if (!CONSP (start_pos
))
3186 event
->modifiers
&= ~up_modifier
;
3187 #if 0 /* Formerly we treated an up with no down as a click event. */
3188 if (!CONSP (start_pos
))
3189 event
->modifiers
|= click_modifier
;
3193 /* The third element of every position should be the (x,y)
3197 down
= Fnth (make_number (2), start_pos
);
3198 if (EQ (event
->x
, XCONS (down
)->car
)
3199 && EQ (event
->y
, XCONS (down
)->cdr
))
3201 event
->modifiers
|= click_modifier
;
3205 button_down_time
= 0;
3206 event
->modifiers
|= drag_modifier
;
3208 /* Don't check is_double; treat this as multiple
3209 if the down-event was multiple. */
3210 if (double_click_count
> 1)
3211 event
->modifiers
|= ((double_click_count
> 2)
3217 /* Every mouse event should either have the down_modifier or
3218 the up_modifier set. */
3222 /* Get the symbol we should use for the mouse click. */
3225 head
= modify_event_symbol (button
,
3228 lispy_mouse_names
, &mouse_syms
,
3229 (sizeof (lispy_mouse_names
)
3230 / sizeof (lispy_mouse_names
[0])));
3231 if (event
->modifiers
& drag_modifier
)
3236 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
3239 Fcons (make_number (double_click_count
),
3247 #endif /* HAVE_MOUSE */
3249 #ifdef USE_X_TOOLKIT
3250 case menu_bar_event
:
3251 /* The event value is in the cdr of the frame_or_window slot. */
3252 if (!CONSP (event
->frame_or_window
))
3254 return XCONS (event
->frame_or_window
)->cdr
;
3257 /* The 'kind' field of the event is something we don't recognize. */
3266 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
3268 Lisp_Object bar_window
;
3269 enum scroll_bar_part part
;
3274 /* Is it a scroll bar movement? */
3275 if (frame
&& ! NILP (bar_window
))
3277 Lisp_Object part_sym
;
3279 part_sym
= *scroll_bar_parts
[(int) part
];
3280 return Fcons (Qscroll_bar_movement
,
3281 (Fcons (Fcons (bar_window
,
3282 Fcons (Qvertical_scroll_bar
,
3283 Fcons (Fcons (x
, y
),
3284 Fcons (make_number (time
),
3290 /* Or is it an ordinary mouse movement? */
3292 #endif /* MULTI_FRAME */
3305 /* It's in a frame; which window on that frame? */
3306 pixel_to_glyph_coords (frame
, XINT (x
), XINT (y
), &column
, &row
,
3308 window
= window_from_coordinates (frame
, column
, row
, &area
);
3313 if (WINDOWP (window
))
3315 int pixcolumn
, pixrow
;
3316 column
-= XINT (XWINDOW (window
)->left
);
3317 row
-= XINT (XWINDOW (window
)->top
);
3318 glyph_to_pixel_coords (frame
, column
, row
, &pixcolumn
, &pixrow
);
3319 XSETINT (x
, pixcolumn
);
3320 XSETINT (y
, pixrow
);
3325 posn
= Qvertical_line
;
3328 buffer_posn_from_coords (XWINDOW (window
), column
, row
));
3331 else if (frame
!= 0)
3333 XSETFRAME (window
, frame
);
3345 return Fcons (Qmouse_movement
,
3346 Fcons (Fcons (window
,
3348 Fcons (Fcons (x
, y
),
3349 Fcons (make_number (time
),
3355 #endif /* HAVE_MOUSE */
3357 /* Construct a switch frame event. */
3359 make_lispy_switch_frame (frame
)
3362 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
3365 /* Manipulating modifiers. */
3367 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
3369 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
3370 SYMBOL's name of the end of the modifiers; the string from this
3371 position is the unmodified symbol name.
3373 This doesn't use any caches. */
3376 parse_modifiers_uncached (symbol
, modifier_end
)
3380 struct Lisp_String
*name
;
3384 CHECK_SYMBOL (symbol
, 1);
3387 name
= XSYMBOL (symbol
)->name
;
3389 for (i
= 0; i
+2 <= name
->size
; )
3391 int this_mod_end
= 0;
3394 /* See if the name continues with a modifier word.
3395 Check that the word appears, but don't check what follows it.
3396 Set this_mod and this_mod_end to record what we find. */
3398 switch (name
->data
[i
])
3400 #define SINGLE_LETTER_MOD(BIT) \
3401 (this_mod_end = i + 1, this_mod = BIT)
3404 SINGLE_LETTER_MOD (alt_modifier
);
3408 SINGLE_LETTER_MOD (ctrl_modifier
);
3412 SINGLE_LETTER_MOD (hyper_modifier
);
3416 SINGLE_LETTER_MOD (meta_modifier
);
3420 SINGLE_LETTER_MOD (shift_modifier
);
3424 SINGLE_LETTER_MOD (super_modifier
);
3427 #undef SINGLE_LETTER_MOD
3430 /* If we found no modifier, stop looking for them. */
3431 if (this_mod_end
== 0)
3434 /* Check there is a dash after the modifier, so that it
3435 really is a modifier. */
3436 if (this_mod_end
>= name
->size
|| name
->data
[this_mod_end
] != '-')
3439 /* This modifier is real; look for another. */
3440 modifiers
|= this_mod
;
3441 i
= this_mod_end
+ 1;
3444 /* Should we include the `click' modifier? */
3445 if (! (modifiers
& (down_modifier
| drag_modifier
3446 | double_modifier
| triple_modifier
))
3447 && i
+ 7 == name
->size
3448 && strncmp (name
->data
+ i
, "mouse-", 6) == 0
3449 && ('0' <= name
->data
[i
+ 6] && name
->data
[i
+ 6] <= '9'))
3450 modifiers
|= click_modifier
;
3458 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
3459 prepended to the string BASE[0..BASE_LEN-1].
3460 This doesn't use any caches. */
3462 apply_modifiers_uncached (modifiers
, base
, base_len
)
3467 /* Since BASE could contain nulls, we can't use intern here; we have
3468 to use Fintern, which expects a genuine Lisp_String, and keeps a
3471 (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
3477 /* Only the event queue may use the `up' modifier; it should always
3478 be turned into a click or drag event before presented to lisp code. */
3479 if (modifiers
& up_modifier
)
3482 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
3483 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
3484 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
3485 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
3486 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
3487 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
3488 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
3489 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
3490 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
3491 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
3492 /* The click modifier is denoted by the absence of other modifiers. */
3496 mod_len
= p
- new_mods
;
3500 Lisp_Object new_name
;
3502 new_name
= make_uninit_string (mod_len
+ base_len
);
3503 bcopy (new_mods
, XSTRING (new_name
)->data
, mod_len
);
3504 bcopy (base
, XSTRING (new_name
)->data
+ mod_len
, base_len
);
3506 return Fintern (new_name
, Qnil
);
3511 static char *modifier_names
[] =
3513 "up", "down", "drag", "click", "double", "triple", 0, 0,
3514 0, 0, 0, 0, 0, 0, 0, 0,
3515 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
3517 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
3519 static Lisp_Object modifier_symbols
;
3521 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
3523 lispy_modifier_list (modifiers
)
3526 Lisp_Object modifier_list
;
3529 modifier_list
= Qnil
;
3530 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
3531 if (modifiers
& (1<<i
))
3532 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
3535 return modifier_list
;
3539 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
3540 where UNMODIFIED is the unmodified form of SYMBOL,
3541 MASK is the set of modifiers present in SYMBOL's name.
3542 This is similar to parse_modifiers_uncached, but uses the cache in
3543 SYMBOL's Qevent_symbol_element_mask property, and maintains the
3544 Qevent_symbol_elements property. */
3547 parse_modifiers (symbol
)
3550 Lisp_Object elements
;
3552 elements
= Fget (symbol
, Qevent_symbol_element_mask
);
3553 if (CONSP (elements
))
3558 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
3559 Lisp_Object unmodified
;
3562 unmodified
= Fintern (make_string (XSYMBOL (symbol
)->name
->data
+ end
,
3563 XSYMBOL (symbol
)->name
->size
- end
),
3566 if (modifiers
& ~(((EMACS_INT
)1 << VALBITS
) - 1))
3568 XSETFASTINT (mask
, modifiers
);
3569 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
3571 /* Cache the parsing results on SYMBOL. */
3572 Fput (symbol
, Qevent_symbol_element_mask
,
3574 Fput (symbol
, Qevent_symbol_elements
,
3575 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
3577 /* Since we know that SYMBOL is modifiers applied to unmodified,
3578 it would be nice to put that in unmodified's cache.
3579 But we can't, since we're not sure that parse_modifiers is
3586 /* Apply the modifiers MODIFIERS to the symbol BASE.
3587 BASE must be unmodified.
3589 This is like apply_modifiers_uncached, but uses BASE's
3590 Qmodifier_cache property, if present. It also builds
3591 Qevent_symbol_elements properties, since it has that info anyway.
3593 apply_modifiers copies the value of BASE's Qevent_kind property to
3594 the modified symbol. */
3596 apply_modifiers (modifiers
, base
)
3600 Lisp_Object cache
, index
, entry
, new_symbol
;
3602 /* Mask out upper bits. We don't know where this value's been. */
3603 modifiers
&= ((EMACS_INT
)1 << VALBITS
) - 1;
3605 /* The click modifier never figures into cache indices. */
3606 cache
= Fget (base
, Qmodifier_cache
);
3607 XSETFASTINT (index
, (modifiers
& ~click_modifier
));
3608 entry
= assq_no_quit (index
, cache
);
3611 new_symbol
= XCONS (entry
)->cdr
;
3614 /* We have to create the symbol ourselves. */
3615 new_symbol
= apply_modifiers_uncached (modifiers
,
3616 XSYMBOL (base
)->name
->data
,
3617 XSYMBOL (base
)->name
->size
);
3619 /* Add the new symbol to the base's cache. */
3620 entry
= Fcons (index
, new_symbol
);
3621 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
3623 /* We have the parsing info now for free, so add it to the caches. */
3624 XSETFASTINT (index
, modifiers
);
3625 Fput (new_symbol
, Qevent_symbol_element_mask
,
3626 Fcons (base
, Fcons (index
, Qnil
)));
3627 Fput (new_symbol
, Qevent_symbol_elements
,
3628 Fcons (base
, lispy_modifier_list (modifiers
)));
3631 /* Make sure this symbol is of the same kind as BASE.
3633 You'd think we could just set this once and for all when we
3634 intern the symbol above, but reorder_modifiers may call us when
3635 BASE's property isn't set right; we can't assume that just
3636 because it has a Qmodifier_cache property it must have its
3637 Qevent_kind set right as well. */
3638 if (NILP (Fget (new_symbol
, Qevent_kind
)))
3642 kind
= Fget (base
, Qevent_kind
);
3644 Fput (new_symbol
, Qevent_kind
, kind
);
3651 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
3652 return a symbol with the modifiers placed in the canonical order.
3653 Canonical order is alphabetical, except for down and drag, which
3654 always come last. The 'click' modifier is never written out.
3656 Fdefine_key calls this to make sure that (for example) C-M-foo
3657 and M-C-foo end up being equivalent in the keymap. */
3660 reorder_modifiers (symbol
)
3663 /* It's hopefully okay to write the code this way, since everything
3664 will soon be in caches, and no consing will be done at all. */
3667 parsed
= parse_modifiers (symbol
);
3668 return apply_modifiers ((int) XINT (XCONS (XCONS (parsed
)->cdr
)->car
),
3669 XCONS (parsed
)->car
);
3673 /* For handling events, we often want to produce a symbol whose name
3674 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
3675 to some base, like the name of a function key or mouse button.
3676 modify_event_symbol produces symbols of this sort.
3678 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
3679 is the name of the i'th symbol. TABLE_SIZE is the number of elements
3682 Alternatively, NAME_ALIST is an alist mapping codes into symbol names.
3683 NAME_ALIST is used if it is non-nil; otherwise NAME_TABLE is used.
3685 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
3686 persist between calls to modify_event_symbol that it can use to
3687 store a cache of the symbols it's generated for this NAME_TABLE
3688 before. The object stored there may be a vector or an alist.
3690 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
3692 MODIFIERS is a set of modifier bits (as given in struct input_events)
3693 whose prefixes should be applied to the symbol name.
3695 SYMBOL_KIND is the value to be placed in the event_kind property of
3696 the returned symbol.
3698 The symbols we create are supposed to have an
3699 `event-symbol-elements' property, which lists the modifiers present
3700 in the symbol's name. */
3703 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_alist
,
3704 name_table
, symbol_table
, table_size
)
3707 Lisp_Object symbol_kind
;
3708 Lisp_Object name_alist
;
3710 Lisp_Object
*symbol_table
;
3714 Lisp_Object symbol_int
;
3716 XSETINT (symbol_int
, symbol_num
);
3718 /* Is this a request for a valid symbol? */
3719 if (symbol_num
< 0 || symbol_num
>= table_size
)
3722 if (CONSP (*symbol_table
))
3723 value
= Fcdr (assq_no_quit (symbol_int
, *symbol_table
));
3725 /* If *symbol_table doesn't seem to be initialized properly, fix that.
3726 *symbol_table should be a lisp vector TABLE_SIZE elements long,
3727 where the Nth element is the symbol for NAME_TABLE[N], or nil if
3728 we've never used that symbol before. */
3731 if (! VECTORP (*symbol_table
)
3732 || XVECTOR (*symbol_table
)->size
!= table_size
)
3736 XSETFASTINT (size
, table_size
);
3737 *symbol_table
= Fmake_vector (size
, Qnil
);
3740 value
= XVECTOR (*symbol_table
)->contents
[symbol_num
];
3743 /* Have we already used this symbol before? */
3746 /* No; let's create it. */
3747 if (!NILP (name_alist
))
3748 value
= Fcdr_safe (Fassq (symbol_int
, name_alist
));
3749 else if (name_table
[symbol_num
])
3750 value
= intern (name_table
[symbol_num
]);
3755 sprintf (buf
, "key-%d", symbol_num
);
3756 value
= intern (buf
);
3759 if (CONSP (*symbol_table
))
3760 *symbol_table
= Fcons (value
, *symbol_table
);
3762 XVECTOR (*symbol_table
)->contents
[symbol_num
] = value
;
3764 /* Fill in the cache entries for this symbol; this also
3765 builds the Qevent_symbol_elements property, which the user
3767 apply_modifiers (modifiers
& click_modifier
, value
);
3768 Fput (value
, Qevent_kind
, symbol_kind
);
3771 /* Apply modifiers to that symbol. */
3772 return apply_modifiers (modifiers
, value
);
3775 /* Convert a list that represents an event type,
3776 such as (ctrl meta backspace), into the usual representation of that
3777 event type as a number or a symbol. */
3780 convert_event_type_list (event
)
3789 while (CONSP (rest
))
3794 elt
= XCONS (rest
)->car
;
3796 /* Given a symbol, see if it is a modifier name. */
3798 this = parse_solitary_modifier (elt
);
3802 else if (!NILP (base
))
3803 error ("Two bases given in one event");
3807 rest
= XCONS (rest
)->cdr
;
3810 /* Let the symbol A refer to the character A. */
3811 if (SYMBOLP (base
) && XSYMBOL (base
)->name
->size
== 1)
3812 XSETINT (base
, XSYMBOL (base
)->name
->data
[0]);
3814 if (INTEGERP (base
))
3816 /* Turn (shift a) into A. */
3817 if ((modifiers
& shift_modifier
) != 0
3818 && (XINT (base
) >= 'a' && XINT (base
) <= 'z'))
3820 XSETINT (base
, XINT (base
) - ('a' - 'A'));
3821 modifiers
&= ~shift_modifier
;
3824 /* Turn (control a) into C-a. */
3825 if (modifiers
& ctrl_modifier
)
3826 return make_number ((modifiers
& ~ctrl_modifier
)
3827 | make_ctrl_char (XINT (base
)));
3829 return make_number (modifiers
| XINT (base
));
3831 else if (SYMBOLP (base
))
3832 return apply_modifiers (modifiers
, base
);
3834 error ("Invalid base event");
3837 /* Try to recognize SYMBOL as a modifier name.
3838 Return the modifier flag bit, or 0 if not recognized. */
3841 parse_solitary_modifier (symbol
)
3844 struct Lisp_String
*name
= XSYMBOL (symbol
)->name
;
3846 switch (name
->data
[0])
3848 #define SINGLE_LETTER_MOD(BIT) \
3849 if (name->size == 1) \
3852 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
3853 if (LEN == name->size \
3854 && ! strncmp (name->data, NAME, LEN)) \
3858 SINGLE_LETTER_MOD (alt_modifier
);
3862 MULTI_LETTER_MOD (alt_modifier
, "alt", 3);
3866 SINGLE_LETTER_MOD (ctrl_modifier
);
3870 MULTI_LETTER_MOD (ctrl_modifier
, "ctrl", 4);
3871 MULTI_LETTER_MOD (ctrl_modifier
, "control", 7);
3875 SINGLE_LETTER_MOD (hyper_modifier
);
3879 MULTI_LETTER_MOD (hyper_modifier
, "hyper", 5);
3883 SINGLE_LETTER_MOD (meta_modifier
);
3887 MULTI_LETTER_MOD (meta_modifier
, "meta", 4);
3891 SINGLE_LETTER_MOD (shift_modifier
);
3895 MULTI_LETTER_MOD (shift_modifier
, "shift", 5);
3896 MULTI_LETTER_MOD (super_modifier
, "super", 5);
3897 SINGLE_LETTER_MOD (super_modifier
);
3901 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
3902 MULTI_LETTER_MOD (down_modifier
, "down", 4);
3903 MULTI_LETTER_MOD (double_modifier
, "double", 6);
3907 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
3910 #undef SINGLE_LETTER_MOD
3911 #undef MULTI_LETTER_MOD
3917 /* Return 1 if EVENT is a list whose elements are all integers or symbols.
3918 Such a list is not valid as an event,
3919 but it can be a Lucid-style event type list. */
3922 lucid_event_type_list_p (object
)
3927 if (! CONSP (object
))
3930 for (tail
= object
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
3933 elt
= XCONS (tail
)->car
;
3934 if (! (INTEGERP (elt
) || SYMBOLP (elt
)))
3941 /* Store into *addr a value nonzero if terminal input chars are available.
3942 Serves the purpose of ioctl (0, FIONREAD, addr)
3943 but works even if FIONREAD does not exist.
3944 (In fact, this may actually read some input.) */
3947 get_input_pending (addr
)
3950 /* First of all, have we already counted some input? */
3951 *addr
= !NILP (Vquit_flag
) || readable_events ();
3953 /* If input is being read as it arrives, and we have none, there is none. */
3954 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
3957 /* Try to read some input and see how much we get. */
3959 *addr
= !NILP (Vquit_flag
) || readable_events ();
3962 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
3965 gobble_input (expected
)
3970 if (interrupt_input
)
3973 mask
= sigblockx (SIGIO
);
3974 read_avail_input (expected
);
3978 #ifdef POLL_FOR_INPUT
3979 if (read_socket_hook
&& !interrupt_input
&& poll_suppress_count
== 0)
3982 mask
= sigblockx (SIGALRM
);
3983 read_avail_input (expected
);
3989 read_avail_input (expected
);
3993 /* Put a buffer_switch_event in the buffer
3994 so that read_key_sequence will notice the new current buffer. */
3996 record_asynch_buffer_change ()
3998 struct input_event event
;
4001 event
.kind
= buffer_switch_event
;
4002 event
.frame_or_window
= Qnil
;
4005 /* We don't need a buffer-switch event unless Emacs is waiting for input.
4006 The purpose of the event is to make read_key_sequence look up the
4007 keymaps again. If we aren't in read_key_sequence, we don't need one,
4008 and the event could cause trouble by messing up (input-pending-p). */
4009 tem
= Fwaiting_for_user_input_p ();
4013 /* We never need these events if we have no asynchronous subprocesses. */
4017 /* Make sure no interrupt happens while storing the event. */
4019 if (interrupt_input
)
4022 mask
= sigblockx (SIGIO
);
4023 kbd_buffer_store_event (&event
);
4030 kbd_buffer_store_event (&event
);
4037 /* Read any terminal input already buffered up by the system
4038 into the kbd_buffer, but do not wait.
4040 EXPECTED should be nonzero if the caller knows there is some input.
4042 Except on VMS, all input is read by this function.
4043 If interrupt_input is nonzero, this function MUST be called
4044 only when SIGIO is blocked.
4046 Returns the number of keyboard chars read, or -1 meaning
4047 this is a bad time to try to read input. */
4050 read_avail_input (expected
)
4053 struct input_event buf
[KBD_BUFFER_SIZE
];
4057 if (read_socket_hook
)
4058 /* No need for FIONREAD or fcntl; just say don't wait. */
4059 nread
= (*read_socket_hook
) (input_fd
, buf
, KBD_BUFFER_SIZE
,
4060 expected
, expected
);
4063 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
4064 the kbd_buffer can really hold. That may prevent loss
4065 of characters on some systems when input is stuffed at us. */
4066 unsigned char cbuf
[KBD_BUFFER_SIZE
- 1];
4069 /* Determine how many characters we should *try* to read. */
4072 #else /* not WINDOWSNT */
4074 n_to_read
= dos_keysns ();
4077 #else /* not MSDOS */
4079 /* Find out how much input is available. */
4080 if (ioctl (input_fd
, FIONREAD
, &n_to_read
) < 0)
4081 /* Formerly simply reported no input, but that sometimes led to
4082 a failure of Emacs to terminate.
4083 SIGHUP seems appropriate if we can't reach the terminal. */
4084 /* ??? Is it really right to send the signal just to this process
4085 rather than to the whole process group?
4086 Perhaps on systems with FIONREAD Emacs is alone in its group. */
4087 kill (getpid (), SIGHUP
);
4090 if (n_to_read
> sizeof cbuf
)
4091 n_to_read
= sizeof cbuf
;
4092 #else /* no FIONREAD */
4093 #if defined(USG) || defined(DGUX)
4094 /* Read some input if available, but don't wait. */
4095 n_to_read
= sizeof cbuf
;
4096 fcntl (input_fd
, F_SETFL
, O_NDELAY
);
4101 #endif /* not MSDOS */
4102 #endif /* not WINDOWSNT */
4104 /* Now read; for one reason or another, this will not block.
4105 NREAD is set to the number of chars read. */
4109 cbuf
[0] = dos_keyread();
4112 nread
= read (input_fd
, cbuf
, n_to_read
);
4114 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
4115 /* The kernel sometimes fails to deliver SIGHUP for ptys.
4116 This looks incorrect, but it isn't, because _BSD causes
4117 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
4118 and that causes a value other than 0 when there is no input. */
4124 /* We used to retry the read if it was interrupted.
4125 But this does the wrong thing when O_NDELAY causes
4126 an EAGAIN error. Does anybody know of a situation
4127 where a retry is actually needed? */
4129 nread
< 0 && (errno
== EAGAIN
4143 #if defined (USG) || defined (DGUX)
4144 fcntl (input_fd
, F_SETFL
, 0);
4145 #endif /* USG or DGUX */
4146 #endif /* no FIONREAD */
4147 for (i
= 0; i
< nread
; i
++)
4149 buf
[i
].kind
= ascii_keystroke
;
4150 buf
[i
].modifiers
= 0;
4151 if (meta_key
== 1 && (cbuf
[i
] & 0x80))
4152 buf
[i
].modifiers
= meta_modifier
;
4156 buf
[i
].code
= cbuf
[i
];
4158 XSETFRAME (buf
[i
].frame_or_window
, selected_frame
);
4160 buf
[i
].frame_or_window
= Qnil
;
4165 /* Scan the chars for C-g and store them in kbd_buffer. */
4166 for (i
= 0; i
< nread
; i
++)
4168 kbd_buffer_store_event (&buf
[i
]);
4169 /* Don't look at input that follows a C-g too closely.
4170 This reduces lossage due to autorepeat on C-g. */
4171 if (buf
[i
].kind
== ascii_keystroke
4172 && buf
[i
].code
== quit_char
)
4178 #endif /* not VMS */
4180 #ifdef SIGIO /* for entire page */
4181 /* Note SIGIO has been undef'd if FIONREAD is missing. */
4184 input_available_signal (signo
)
4187 /* Must preserve main program's value of errno. */
4188 int old_errno
= errno
;
4190 extern int select_alarmed
;
4194 /* USG systems forget handlers when they are used;
4195 must reestablish each time */
4196 signal (signo
, input_available_signal
);
4203 if (input_available_clear_time
)
4204 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
4209 nread
= read_avail_input (1);
4210 /* -1 means it's not ok to read the input now.
4211 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
4212 0 means there was no keyboard input available. */
4217 select_alarmed
= 1; /* Force the select emulator back to life */
4228 /* Send ourselves a SIGIO.
4230 This function exists so that the UNBLOCK_INPUT macro in
4231 blockinput.h can have some way to take care of input we put off
4232 dealing with, without assuming that every file which uses
4233 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
4235 reinvoke_input_signal ()
4244 /* Return the prompt-string of a sparse keymap.
4245 This is the first element which is a string.
4246 Return nil if there is none. */
4254 register Lisp_Object tem
;
4263 static void menu_bar_item ();
4264 static void menu_bar_one_keymap ();
4266 /* These variables hold the vector under construction within
4267 menu_bar_items and its subroutines, and the current index
4268 for storing into that vector. */
4269 static Lisp_Object menu_bar_items_vector
;
4270 static int menu_bar_items_index
;
4272 /* Return a vector of menu items for a menu bar, appropriate
4273 to the current buffer. Each item has three elements in the vector:
4276 OLD is an old vector we can optionally reuse, or nil. */
4279 menu_bar_items (old
)
4282 /* The number of keymaps we're scanning right now, and the number of
4283 keymaps we have allocated space for. */
4286 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
4287 in the current keymaps, or nil where it is not a prefix. */
4290 Lisp_Object def
, tem
, tail
;
4299 struct gcpro gcpro1
;
4301 /* In order to build the menus, we need to call the keymap
4302 accessors. They all call QUIT. But this function is called
4303 during redisplay, during which a quit is fatal. So inhibit
4304 quitting while building the menus.
4305 We do this instead of specbind because (1) errors will clear it anyway
4306 and (2) this avoids risk of specpdl overflow. */
4307 oquit
= Vinhibit_quit
;
4311 menu_bar_items_vector
= old
;
4313 menu_bar_items_vector
= Fmake_vector (make_number (24), Qnil
);
4314 menu_bar_items_index
= 0;
4316 GCPRO1 (menu_bar_items_vector
);
4318 /* Build our list of keymaps.
4319 If we recognize a function key and replace its escape sequence in
4320 keybuf with its symbol, or if the sequence starts with a mouse
4321 click and we need to switch buffers, we jump back here to rebuild
4322 the initial keymaps from the current buffer. */
4326 /* Should overriding-local-map apply, here? */
4327 if (!NILP (Voverriding_local_map_menu_flag
))
4329 if (NILP (Voverriding_local_map
))
4331 /* Yes, and it is nil. Use just global map. */
4333 maps
= (Lisp_Object
*) alloca (nmaps
* sizeof (maps
[0]));
4337 /* Yes, and it is non-nil. Use it and the global map. */
4339 maps
= (Lisp_Object
*) alloca (nmaps
* sizeof (maps
[0]));
4340 maps
[0] = Voverriding_local_map
;
4345 /* No, so use major and minor mode keymaps. */
4346 nmaps
= current_minor_maps (NULL
, &tmaps
) + 2;
4347 maps
= (Lisp_Object
*) alloca (nmaps
* sizeof (maps
[0]));
4348 bcopy (tmaps
, maps
, (nmaps
- 2) * sizeof (maps
[0]));
4349 #ifdef USE_TEXT_PROPERTIES
4350 maps
[nmaps
-2] = get_local_map (PT
, current_buffer
);
4352 maps
[nmaps
-2] = current_buffer
->keymap
;
4355 maps
[nmaps
-1] = current_global_map
;
4358 /* Look up in each map the dummy prefix key `menu-bar'. */
4362 for (mapno
= nmaps
- 1; mapno
>= 0; mapno
--)
4364 if (! NILP (maps
[mapno
]))
4365 def
= get_keyelt (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0));
4369 tem
= Fkeymapp (def
);
4371 menu_bar_one_keymap (def
);
4374 /* Move to the end those items that should be at the end. */
4376 for (tail
= Vmenu_bar_final_items
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4379 int end
= menu_bar_items_index
;
4381 for (i
= 0; i
< end
; i
+= 3)
4382 if (EQ (XCONS (tail
)->car
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
4384 Lisp_Object tem0
, tem1
, tem2
;
4385 /* Move the item at index I to the end,
4386 shifting all the others forward. */
4387 tem0
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 0];
4388 tem1
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 1];
4389 tem2
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
4391 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3],
4392 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
4393 (end
- i
- 3) * sizeof (Lisp_Object
));
4394 XVECTOR (menu_bar_items_vector
)->contents
[end
- 3] = tem0
;
4395 XVECTOR (menu_bar_items_vector
)->contents
[end
- 2] = tem1
;
4396 XVECTOR (menu_bar_items_vector
)->contents
[end
- 1] = tem2
;
4401 /* Add nil, nil, nil at the end. */
4402 i
= menu_bar_items_index
;
4403 if (i
+ 3 > XVECTOR (menu_bar_items_vector
)->size
)
4406 int newsize
= 2 * i
;
4407 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
4408 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
4409 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
4410 menu_bar_items_vector
= tem
;
4412 /* Add this item. */
4413 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
4414 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
4415 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
4416 menu_bar_items_index
= i
;
4418 Vinhibit_quit
= oquit
;
4420 return menu_bar_items_vector
;
4423 /* Scan one map KEYMAP, accumulating any menu items it defines
4424 in menu_bar_items_vector. */
4427 menu_bar_one_keymap (keymap
)
4430 Lisp_Object tail
, item
, key
, binding
, item_string
, table
;
4432 /* Loop over all keymap entries that have menu strings. */
4433 for (tail
= keymap
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4435 item
= XCONS (tail
)->car
;
4438 key
= XCONS (item
)->car
;
4439 binding
= XCONS (item
)->cdr
;
4440 if (CONSP (binding
))
4442 item_string
= XCONS (binding
)->car
;
4443 if (STRINGP (item_string
))
4444 menu_bar_item (key
, item_string
, Fcdr (binding
));
4446 else if (EQ (binding
, Qundefined
))
4447 menu_bar_item (key
, Qnil
, binding
);
4449 else if (VECTORP (item
))
4451 /* Loop over the char values represented in the vector. */
4452 int len
= XVECTOR (item
)->size
;
4454 for (c
= 0; c
< len
; c
++)
4456 Lisp_Object character
;
4457 XSETFASTINT (character
, c
);
4458 binding
= XVECTOR (item
)->contents
[c
];
4459 if (CONSP (binding
))
4461 item_string
= XCONS (binding
)->car
;
4462 if (STRINGP (item_string
))
4463 menu_bar_item (key
, item_string
, Fcdr (binding
));
4465 else if (EQ (binding
, Qundefined
))
4466 menu_bar_item (key
, Qnil
, binding
);
4472 /* This is used as the handler when calling internal_condition_case_1. */
4475 menu_bar_item_1 (arg
)
4481 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
4482 If there's already an item for KEY, add this DEF to it. */
4485 menu_bar_item (key
, item_string
, def
)
4486 Lisp_Object key
, item_string
, def
;
4489 Lisp_Object enabled
;
4492 if (EQ (def
, Qundefined
))
4494 /* If a map has an explicit `undefined' as definition,
4495 discard any previously made menu bar item. */
4497 for (i
= 0; i
< menu_bar_items_index
; i
+= 3)
4498 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
4500 if (menu_bar_items_index
> i
+ 3)
4501 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3],
4502 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
4503 (menu_bar_items_index
- i
- 3) * sizeof (Lisp_Object
));
4504 menu_bar_items_index
-= 3;
4508 /* If there's no definition for this key yet,
4509 just ignore `undefined'. */
4513 /* See if this entry is enabled. */
4518 /* No property, or nil, means enable.
4519 Otherwise, enable if value is not nil. */
4520 tem
= Fget (def
, Qmenu_enable
);
4522 /* (condition-case nil (eval tem)
4524 enabled
= internal_condition_case_1 (Feval
, tem
, Qerror
,
4528 /* Ignore this item if it's not enabled. */
4532 /* Find any existing item for this KEY. */
4533 for (i
= 0; i
< menu_bar_items_index
; i
+= 3)
4534 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
4537 /* If we did not find this KEY, add it at the end. */
4538 if (i
== menu_bar_items_index
)
4540 /* If vector is too small, get a bigger one. */
4541 if (i
+ 3 > XVECTOR (menu_bar_items_vector
)->size
)
4544 int newsize
= 2 * i
;
4545 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
4546 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
4547 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
4548 menu_bar_items_vector
= tem
;
4550 /* Add this item. */
4551 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = key
;
4552 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = item_string
;
4553 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Fcons (def
, Qnil
);
4554 menu_bar_items_index
= i
;
4556 /* We did find an item for this KEY. Add DEF to its list of maps. */
4560 old
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
4561 XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2] = Fcons (def
, old
);
4565 /* Read a character using menus based on maps in the array MAPS.
4566 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
4567 Return t if we displayed a menu but the user rejected it.
4569 PREV_EVENT is the previous input event, or nil if we are reading
4570 the first event of a key sequence.
4572 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
4573 if we used a mouse menu to read the input, or zero otherwise. If
4574 USED_MOUSE_MENU is null, we don't dereference it.
4576 The prompting is done based on the prompt-string of the map
4577 and the strings associated with various map elements.
4579 This can be done with X menus or with menus put in the minibuf.
4580 These are done in different ways, depending on how the input will be read.
4581 Menus using X are done after auto-saving in read-char, getting the input
4582 event from Fx_popup_menu; menus using the minibuf use read_char recursively
4583 and do auto-saving in the inner call of read_char. */
4586 read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
4589 Lisp_Object prev_event
;
4590 int *used_mouse_menu
;
4593 register Lisp_Object name
;
4594 Lisp_Object rest
, vector
;
4596 if (used_mouse_menu
)
4597 *used_mouse_menu
= 0;
4599 /* Use local over global Menu maps */
4601 if (! menu_prompting
)
4604 /* Optionally disregard all but the global map. */
4605 if (inhibit_local_menu_bar_menus
)
4607 maps
+= (nmaps
- 1);
4611 /* Get the menu name from the first map that has one (a prompt string). */
4612 for (mapno
= 0; mapno
< nmaps
; mapno
++)
4614 name
= map_prompt (maps
[mapno
]);
4619 /* If we don't have any menus, just read a character normally. */
4623 #if (defined (HAVE_X_WINDOWS) && defined (HAVE_X_MENU)) || defined (MSDOS)
4624 /* If we got to this point via a mouse click,
4625 use a real menu for mouse selection. */
4626 if (EVENT_HAS_PARAMETERS (prev_event
)
4627 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
))
4629 /* Display the menu and get the selection. */
4630 Lisp_Object
*realmaps
4631 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
4635 /* Use the maps that are not nil. */
4636 for (mapno
= 0; mapno
< nmaps
; mapno
++)
4637 if (!NILP (maps
[mapno
]))
4638 realmaps
[nmaps1
++] = maps
[mapno
];
4640 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
4643 /* If we got more than one event, put all but the first
4644 onto this list to be read later.
4645 Return just the first event now. */
4646 Vunread_command_events
4647 = nconc2 (XCONS (value
)->cdr
, Vunread_command_events
);
4648 value
= XCONS (value
)->car
;
4650 else if (NILP (value
))
4652 if (used_mouse_menu
)
4653 *used_mouse_menu
= 1;
4656 #endif /* (HAVE_X_WINDOWS && HAVE_X_MENU) || MSDOS */
4661 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
4667 register Lisp_Object name
;
4669 int width
= FRAME_WIDTH (selected_frame
) - 4;
4670 char *menu
= (char *) alloca (width
+ 4);
4673 Lisp_Object rest
, vector
;
4675 if (! menu_prompting
)
4678 /* Get the menu name from the first map that has one (a prompt string). */
4679 for (mapno
= 0; mapno
< nmaps
; mapno
++)
4681 name
= map_prompt (maps
[mapno
]);
4686 /* If we don't have any menus, just read a character normally. */
4690 /* Prompt string always starts with map's prompt, and a space. */
4691 strcpy (menu
, XSTRING (name
)->data
);
4692 nlength
= XSTRING (name
)->size
;
4693 menu
[nlength
++] = ':';
4694 menu
[nlength
++] = ' ';
4697 /* Start prompting at start of first map. */
4701 /* Present the documented bindings, a line at a time. */
4708 Lisp_Object orig_defn_macro
;
4710 /* Loop over elements of map. */
4715 /* If reached end of map, start at beginning of next map. */
4719 /* At end of last map, wrap around to first map if just starting,
4720 or end this line if already have something on it. */
4724 if (notfirst
|| nobindings
) break;
4729 /* Look at the next element of the map. */
4731 elt
= XVECTOR (vector
)->contents
[idx
];
4733 elt
= Fcar_safe (rest
);
4735 if (idx
< 0 && VECTORP (elt
))
4737 /* If we found a dense table in the keymap,
4738 advanced past it, but start scanning its contents. */
4739 rest
= Fcdr_safe (rest
);
4745 /* An ordinary element. */
4747 s
= Fcar_safe (Fcdr_safe (elt
)); /* alist */
4749 s
= Fcar_safe(elt
); /* vector */
4751 /* Ignore the element if it has no prompt string. */
4753 /* If we have room for the prompt string, add it to this line.
4754 If this is the first on the line, always add it. */
4755 else if (XSTRING (s
)->size
+ i
+ 2 < width
4760 /* Punctuate between strings. */
4763 strcpy (menu
+ i
, ", ");
4769 /* Add as much of string as fits. */
4770 thiswidth
= XSTRING (s
)->size
;
4771 if (thiswidth
+ i
> width
)
4772 thiswidth
= width
- i
;
4773 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
4779 /* If this element does not fit, end the line now,
4780 and save the element for the next line. */
4781 strcpy (menu
+ i
, "...");
4785 /* Move past this element. */
4786 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
4787 /* Handle reaching end of dense table. */
4792 rest
= Fcdr_safe (rest
);
4796 /* Prompt with that and read response. */
4799 /* Make believe its not a keyboard macro in case the help char
4800 is pressed. Help characters are not recorded because menu prompting
4801 is not used on replay.
4803 orig_defn_macro
= current_kboard
->defining_kbd_macro
;
4804 current_kboard
->defining_kbd_macro
= Qnil
;
4806 obj
= read_char (commandflag
, 0, 0, Qnil
, 0);
4807 while (BUFFERP (obj
));
4808 current_kboard
->defining_kbd_macro
= orig_defn_macro
;
4810 if (!INTEGERP (obj
))
4815 if (! EQ (obj
, menu_prompt_more_char
)
4816 && (!INTEGERP (menu_prompt_more_char
)
4817 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
4819 if (!NILP (current_kboard
->defining_kbd_macro
))
4820 store_kbd_macro_char (obj
);
4823 /* Help char - go round again */
4827 /* Reading key sequences. */
4829 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
4830 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
4831 keymap, or nil otherwise. Return the index of the first keymap in
4832 which KEY has any binding, or NMAPS if no map has a binding.
4834 If KEY is a meta ASCII character, treat it like meta-prefix-char
4835 followed by the corresponding non-meta character. Keymaps in
4836 CURRENT with non-prefix bindings for meta-prefix-char become nil in
4839 If KEY has no bindings in any of the CURRENT maps, NEXT is left
4842 NEXT may == CURRENT. */
4845 follow_key (key
, nmaps
, current
, defs
, next
)
4847 Lisp_Object
*current
, *defs
, *next
;
4850 int i
, first_binding
;
4852 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
4853 followed by the corresponding non-meta character. */
4854 if (INTEGERP (key
) && (XINT (key
) & CHAR_META
))
4856 for (i
= 0; i
< nmaps
; i
++)
4857 if (! NILP (current
[i
]))
4860 get_keyelt (access_keymap (current
[i
], meta_prefix_char
, 1, 0));
4862 /* Note that since we pass the resulting bindings through
4863 get_keymap_1, non-prefix bindings for meta-prefix-char
4865 next
[i
] = get_keymap_1 (next
[i
], 0, 1);
4871 XSETINT (key
, XFASTINT (key
) & ~CHAR_META
);
4874 first_binding
= nmaps
;
4875 for (i
= nmaps
- 1; i
>= 0; i
--)
4877 if (! NILP (current
[i
]))
4879 defs
[i
] = get_keyelt (access_keymap (current
[i
], key
, 1, 0));
4880 if (! NILP (defs
[i
]))
4887 /* Given the set of bindings we've found, produce the next set of maps. */
4888 if (first_binding
< nmaps
)
4889 for (i
= 0; i
< nmaps
; i
++)
4890 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0, 1);
4892 return first_binding
;
4895 /* Read a sequence of keys that ends with a non prefix character,
4896 storing it in KEYBUF, a buffer of size BUFSIZE.
4898 Return the length of the key sequence stored.
4899 Return -1 if the user rejected a command menu.
4901 Echo starting immediately unless `prompt' is 0.
4903 Where a key sequence ends depends on the currently active keymaps.
4904 These include any minor mode keymaps active in the current buffer,
4905 the current buffer's local map, and the global map.
4907 If a key sequence has no other bindings, we check Vfunction_key_map
4908 to see if some trailing subsequence might be the beginning of a
4909 function key's sequence. If so, we try to read the whole function
4910 key, and substitute its symbolic name into the key sequence.
4912 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
4913 `double-' events into similar click events, if that would make them
4914 bound. We try to turn `triple-' events first into `double-' events,
4917 If we get a mouse click in a mode line, vertical divider, or other
4918 non-text area, we treat the click as if it were prefixed by the
4919 symbol denoting that area - `mode-line', `vertical-line', or
4922 If the sequence starts with a mouse click, we read the key sequence
4923 with respect to the buffer clicked on, not the current buffer.
4925 If the user switches frames in the midst of a key sequence, we put
4926 off the switch-frame event until later; the next call to
4927 read_char will return it. */
4930 read_key_sequence (keybuf
, bufsize
, prompt
, dont_downcase_last
,
4931 can_return_switch_frame
)
4932 Lisp_Object
*keybuf
;
4935 int dont_downcase_last
;
4936 int can_return_switch_frame
;
4938 int count
= specpdl_ptr
- specpdl
;
4940 /* How many keys there are in the current key sequence. */
4943 /* The length of the echo buffer when we started reading, and
4944 the length of this_command_keys when we started reading. */
4948 /* The number of keymaps we're scanning right now, and the number of
4949 keymaps we have allocated space for. */
4951 int nmaps_allocated
= 0;
4953 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
4954 the current keymaps. */
4957 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
4958 in the current keymaps, or nil where it is not a prefix. */
4959 Lisp_Object
*submaps
;
4961 /* The local map to start out with at start of key sequence. */
4962 Lisp_Object orig_local_map
;
4964 /* 1 if we have already considered switching to the local-map property
4965 of the place where a mouse click occurred. */
4966 int localized_local_map
= 0;
4968 /* The index in defs[] of the first keymap that has a binding for
4969 this key sequence. In other words, the lowest i such that
4970 defs[i] is non-nil. */
4973 /* If t < mock_input, then KEYBUF[t] should be read as the next
4976 We use this to recover after recognizing a function key. Once we
4977 realize that a suffix of the current key sequence is actually a
4978 function key's escape sequence, we replace the suffix with the
4979 function key's binding from Vfunction_key_map. Now keybuf
4980 contains a new and different key sequence, so the echo area,
4981 this_command_keys, and the submaps and defs arrays are wrong. In
4982 this situation, we set mock_input to t, set t to 0, and jump to
4983 restart_sequence; the loop will read keys from keybuf up until
4984 mock_input, thus rebuilding the state; and then it will resume
4985 reading characters from the keyboard. */
4988 /* If the sequence is unbound in submaps[], then
4989 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
4990 and fkey_map is its binding.
4992 These might be > t, indicating that all function key scanning
4993 should hold off until t reaches them. We do this when we've just
4994 recognized a function key, to avoid searching for the function
4995 key's again in Vfunction_key_map. */
4996 int fkey_start
= 0, fkey_end
= 0;
4997 Lisp_Object fkey_map
;
4999 /* Likewise, for key_translation_map. */
5000 int keytran_start
= 0, keytran_end
= 0;
5001 Lisp_Object keytran_map
;
5003 /* If we receive a ``switch-frame'' event in the middle of a key sequence,
5004 we put it off for later. While we're reading, we keep the event here. */
5005 Lisp_Object delayed_switch_frame
;
5007 /* See the comment below... */
5008 #if defined (GOBBLE_FIRST_EVENT)
5009 Lisp_Object first_event
;
5012 Lisp_Object original_uppercase
;
5013 int original_uppercase_position
= -1;
5015 /* Gets around Microsoft compiler limitations. */
5018 struct buffer
*starting_buffer
;
5020 /* Nonzero if we seem to have got the beginning of a binding
5021 in function_key_map. */
5022 int function_key_possible
= 0;
5023 int key_translation_possible
= 0;
5027 last_nonmenu_event
= Qnil
;
5029 delayed_switch_frame
= Qnil
;
5030 fkey_map
= Vfunction_key_map
;
5031 keytran_map
= Vkey_translation_map
;
5033 /* If there is no function-key-map, turn off function key scanning. */
5034 if (NILP (Fkeymapp (Vfunction_key_map
)))
5035 fkey_start
= fkey_end
= bufsize
+ 1;
5037 /* If there is no key-translation-map, turn off scanning. */
5038 if (NILP (Fkeymapp (Vkey_translation_map
)))
5039 keytran_start
= keytran_end
= bufsize
+ 1;
5044 echo_prompt (XSTRING (prompt
)->data
);
5045 else if (cursor_in_echo_area
&& echo_keystrokes
)
5046 /* This doesn't put in a dash if the echo buffer is empty, so
5047 you don't always see a dash hanging out in the minibuffer. */
5051 /* Record the initial state of the echo area and this_command_keys;
5052 we will need to restore them if we replay a key sequence. */
5054 echo_start
= echo_length ();
5055 keys_start
= this_command_key_count
;
5057 #if defined (GOBBLE_FIRST_EVENT)
5058 /* This doesn't quite work, because some of the things that read_char
5059 does cannot safely be bypassed. It seems too risky to try to make
5062 /* Read the first char of the sequence specially, before setting
5063 up any keymaps, in case a filter runs and switches buffers on us. */
5064 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
5066 #endif /* GOBBLE_FIRST_EVENT */
5068 orig_local_map
= get_local_map (PT
, current_buffer
);
5070 /* We jump here when the key sequence has been thoroughly changed, and
5071 we need to rescan it starting from the beginning. When we jump here,
5072 keybuf[0..mock_input] holds the sequence we should reread. */
5075 starting_buffer
= current_buffer
;
5076 function_key_possible
= 0;
5077 key_translation_possible
= 0;
5079 /* Build our list of keymaps.
5080 If we recognize a function key and replace its escape sequence in
5081 keybuf with its symbol, or if the sequence starts with a mouse
5082 click and we need to switch buffers, we jump back here to rebuild
5083 the initial keymaps from the current buffer. */
5087 if (!NILP (Voverriding_local_map
))
5090 if (nmaps
> nmaps_allocated
)
5092 submaps
= (Lisp_Object
*) alloca (nmaps
* sizeof (submaps
[0]));
5093 defs
= (Lisp_Object
*) alloca (nmaps
* sizeof (defs
[0]));
5094 nmaps_allocated
= nmaps
;
5096 submaps
[0] = Voverriding_local_map
;
5100 nmaps
= current_minor_maps (0, &maps
) + 2;
5101 if (nmaps
> nmaps_allocated
)
5103 submaps
= (Lisp_Object
*) alloca (nmaps
* sizeof (submaps
[0]));
5104 defs
= (Lisp_Object
*) alloca (nmaps
* sizeof (defs
[0]));
5105 nmaps_allocated
= nmaps
;
5107 bcopy (maps
, submaps
, (nmaps
- 2) * sizeof (submaps
[0]));
5108 #ifdef USE_TEXT_PROPERTIES
5109 submaps
[nmaps
-2] = orig_local_map
;
5111 submaps
[nmaps
-2] = current_buffer
->keymap
;
5114 submaps
[nmaps
-1] = current_global_map
;
5117 /* Find an accurate initial value for first_binding. */
5118 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
5119 if (! NILP (submaps
[first_binding
]))
5122 /* Start from the beginning in keybuf. */
5125 /* These are no-ops the first time through, but if we restart, they
5126 revert the echo area and this_command_keys to their original state. */
5127 this_command_key_count
= keys_start
;
5128 if (INTERACTIVE
&& t
< mock_input
)
5129 echo_truncate (echo_start
);
5131 /* If the best binding for the current key sequence is a keymap, or
5132 we may be looking at a function key's escape sequence, keep on
5134 while ((first_binding
< nmaps
&& ! NILP (submaps
[first_binding
]))
5135 || (first_binding
>= nmaps
5137 /* mock input is never part of a function key's sequence. */
5138 && mock_input
<= fkey_start
)
5139 || (first_binding
>= nmaps
5140 && keytran_start
< t
&& key_translation_possible
)
5141 /* Don't return in the middle of a possible function key sequence,
5142 if the only bindings we found were via case conversion.
5143 Thus, if ESC O a has a function-key-map translation
5144 and ESC o has a binding, don't return after ESC O,
5145 so that we can translate ESC O plus the next character. */
5149 int used_mouse_menu
= 0;
5151 /* Where the last real key started. If we need to throw away a
5152 key that has expanded into more than one element of keybuf
5153 (say, a mouse click on the mode line which is being treated
5154 as [mode-line (mouse-...)], then we backtrack to this point
5156 int last_real_key_start
;
5158 /* These variables are analogous to echo_start and keys_start;
5159 while those allow us to restart the entire key sequence,
5160 echo_local_start and keys_local_start allow us to throw away
5162 int echo_local_start
, keys_local_start
, local_first_binding
;
5165 error ("key sequence too long");
5168 echo_local_start
= echo_length ();
5169 keys_local_start
= this_command_key_count
;
5170 local_first_binding
= first_binding
;
5173 /* These are no-ops, unless we throw away a keystroke below and
5174 jumped back up to replay_key; in that case, these restore the
5175 variables to their original state, allowing us to replay the
5177 if (INTERACTIVE
&& t
< mock_input
)
5178 echo_truncate (echo_local_start
);
5179 this_command_key_count
= keys_local_start
;
5180 first_binding
= local_first_binding
;
5182 /* By default, assume each event is "real". */
5183 last_real_key_start
= t
;
5185 /* Does mock_input indicate that we are re-reading a key sequence? */
5189 add_command_key (key
);
5190 if (echo_keystrokes
)
5194 /* If not, we should actually read a character. */
5197 struct buffer
*buf
= current_buffer
;
5201 KBOARD
*interrupted_kboard
= current_kboard
;
5202 struct frame
*interrupted_frame
= selected_frame
;
5203 if (setjmp (wrong_kboard_jmpbuf
))
5205 if (!NILP (delayed_switch_frame
))
5207 interrupted_kboard
->kbd_queue
5208 = Fcons (delayed_switch_frame
,
5209 interrupted_kboard
->kbd_queue
);
5210 delayed_switch_frame
= Qnil
;
5213 interrupted_kboard
->kbd_queue
5214 = Fcons (keybuf
[--t
], interrupted_kboard
->kbd_queue
);
5216 /* If the side queue is non-empty, ensure it begins with a
5217 switch-frame, so we'll replay it in the right context. */
5218 if (CONSP (interrupted_kboard
->kbd_queue
)
5219 && (key
= XCONS (interrupted_kboard
->kbd_queue
)->car
,
5220 !(EVENT_HAS_PARAMETERS (key
)
5221 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)),
5225 XSETFRAME (frame
, interrupted_frame
);
5226 interrupted_kboard
->kbd_queue
5227 = Fcons (make_lispy_switch_frame (frame
),
5228 interrupted_kboard
->kbd_queue
);
5231 orig_local_map
= get_local_map (PT
, current_buffer
);
5232 goto replay_sequence
;
5235 key
= read_char (NILP (prompt
), nmaps
, submaps
, last_nonmenu_event
,
5239 /* read_char returns t when it shows a menu and the user rejects it.
5244 /* read_char returns -1 at the end of a macro.
5245 Emacs 18 handles this by returning immediately with a
5246 zero, so that's what we'll do. */
5247 if (INTEGERP (key
) && XINT (key
) == -1)
5250 /* The Microsoft C compiler can't handle the goto that
5256 /* If the current buffer has been changed from under us, the
5257 keymap may have changed, so replay the sequence. */
5261 orig_local_map
= get_local_map (PT
, current_buffer
);
5262 goto replay_sequence
;
5265 /* If we have a quit that was typed in another frame, and
5266 quit_throw_to_read_char switched buffers,
5267 replay to get the right keymap. */
5268 if (XINT (key
) == quit_char
&& current_buffer
!= starting_buffer
)
5273 orig_local_map
= get_local_map (PT
, current_buffer
);
5274 goto replay_sequence
;
5280 /* Clicks in non-text areas get prefixed by the symbol
5281 in their CHAR-ADDRESS field. For example, a click on
5282 the mode line is prefixed by the symbol `mode-line'.
5284 Furthermore, key sequences beginning with mouse clicks
5285 are read using the keymaps of the buffer clicked on, not
5286 the current buffer. So we may have to switch the buffer
5289 When we turn one event into two events, we must make sure
5290 that neither of the two looks like the original--so that,
5291 if we replay the events, they won't be expanded again.
5292 If not for this, such reexpansion could happen either here
5293 or when user programs play with this-command-keys. */
5294 if (EVENT_HAS_PARAMETERS (key
))
5298 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
5299 if (EQ (kind
, Qmouse_click
))
5301 Lisp_Object window
, posn
;
5303 window
= POSN_WINDOW (EVENT_START (key
));
5304 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
5307 /* We're looking at the second event of a
5308 sequence which we expanded before. Set
5309 last_real_key_start appropriately. */
5311 last_real_key_start
= t
- 1;
5314 /* Key sequences beginning with mouse clicks are
5315 read using the keymaps in the buffer clicked on,
5316 not the current buffer. If we're at the
5317 beginning of a key sequence, switch buffers. */
5318 if (last_real_key_start
== 0
5320 && BUFFERP (XWINDOW (window
)->buffer
)
5321 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
5326 /* Arrange to go back to the original buffer once we're
5327 done reading the key sequence. Note that we can't
5328 use save_excursion_{save,restore} here, because they
5329 save point as well as the current buffer; we don't
5330 want to save point, because redisplay may change it,
5331 to accommodate a Fset_window_start or something. We
5332 don't want to do this at the top of the function,
5333 because we may get input from a subprocess which
5334 wants to change the selected window and stuff (say,
5336 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
5338 set_buffer_internal (XBUFFER (XWINDOW (window
)->buffer
));
5339 orig_local_map
= get_local_map (PT
, current_buffer
);
5340 goto replay_sequence
;
5342 /* For a mouse click, get the local text-property keymap
5343 of the place clicked on, rather than point. */
5344 if (last_real_key_start
== 0 && CONSP (XCONS (key
)->cdr
)
5345 && ! localized_local_map
)
5347 Lisp_Object map_here
, start
, pos
;
5349 localized_local_map
= 1;
5350 start
= EVENT_START (key
);
5351 if (CONSP (start
) && CONSP (XCONS (start
)->cdr
))
5353 pos
= POSN_BUFFER_POSN (start
);
5356 map_here
= get_local_map (XINT (pos
), current_buffer
);
5357 if (!EQ (map_here
, orig_local_map
))
5359 orig_local_map
= map_here
;
5363 goto replay_sequence
;
5369 /* Expand mode-line and scroll-bar events into two events:
5370 use posn as a fake prefix key. */
5373 if (t
+ 1 >= bufsize
)
5374 error ("key sequence too long");
5379 /* Zap the position in key, so we know that we've
5380 expanded it, and don't try to do so again. */
5381 POSN_BUFFER_POSN (EVENT_START (key
))
5382 = Fcons (posn
, Qnil
);
5386 else if (EQ (kind
, Qswitch_frame
))
5388 /* If we're at the beginning of a key sequence, and the caller
5389 says it's okay, go ahead and return this event. If we're
5390 in the midst of a key sequence, delay it until the end. */
5391 if (t
> 0 || !can_return_switch_frame
)
5393 delayed_switch_frame
= key
;
5397 else if (CONSP (XCONS (key
)->cdr
)
5398 && CONSP (EVENT_START (key
))
5399 && CONSP (XCONS (EVENT_START (key
))->cdr
))
5403 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
5404 /* Handle menu-bar events:
5405 insert the dummy prefix event `menu-bar'. */
5406 if (EQ (posn
, Qmenu_bar
))
5408 if (t
+ 1 >= bufsize
)
5409 error ("key sequence too long");
5410 /* Run the Lucid hook. */
5411 if (!NILP (Vrun_hooks
))
5412 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
5413 /* If it has changed current-menubar from previous value,
5414 really recompute the menubar from the value. */
5415 if (! NILP (Vlucid_menu_bar_dirty_flag
))
5416 call0 (Qrecompute_lucid_menubar
);
5420 /* Zap the position in key, so we know that we've
5421 expanded it, and don't try to do so again. */
5422 POSN_BUFFER_POSN (EVENT_START (key
))
5423 = Fcons (posn
, Qnil
);
5426 goto replay_sequence
;
5428 else if (CONSP (posn
))
5430 /* We're looking at the second event of a
5431 sequence which we expanded before. Set
5432 last_real_key_start appropriately. */
5433 if (last_real_key_start
== t
&& t
> 0)
5434 last_real_key_start
= t
- 1;
5439 /* We have finally decided that KEY is something we might want
5441 first_binding
= (follow_key (key
,
5442 nmaps
- first_binding
,
5443 submaps
+ first_binding
,
5444 defs
+ first_binding
,
5445 submaps
+ first_binding
)
5448 /* If KEY wasn't bound, we'll try some fallbacks. */
5449 if (first_binding
>= nmaps
)
5453 head
= EVENT_HEAD (key
);
5454 if (EQ (head
, Vhelp_char
))
5456 read_key_sequence_cmd
= Vprefix_help_command
;
5458 last_nonmenu_event
= key
;
5459 /* The Microsoft C compiler can't handle the goto that
5467 Lisp_Object breakdown
;
5470 breakdown
= parse_modifiers (head
);
5471 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
5472 /* Attempt to reduce an unbound mouse event to a simpler
5473 event that is bound:
5474 Drags reduce to clicks.
5475 Double-clicks reduce to clicks.
5476 Triple-clicks reduce to double-clicks, then to clicks.
5477 Down-clicks are eliminated.
5478 Double-downs reduce to downs, then are eliminated.
5479 Triple-downs reduce to double-downs, then to downs,
5480 then are eliminated. */
5481 if (modifiers
& (down_modifier
| drag_modifier
5482 | double_modifier
| triple_modifier
))
5484 while (modifiers
& (down_modifier
| drag_modifier
5485 | double_modifier
| triple_modifier
))
5487 Lisp_Object new_head
, new_click
;
5488 if (modifiers
& triple_modifier
)
5489 modifiers
^= (double_modifier
| triple_modifier
);
5490 else if (modifiers
& double_modifier
)
5491 modifiers
&= ~double_modifier
;
5492 else if (modifiers
& drag_modifier
)
5493 modifiers
&= ~drag_modifier
;
5496 /* Dispose of this `down' event by simply jumping
5497 back to replay_key, to get another event.
5499 Note that if this event came from mock input,
5500 then just jumping back to replay_key will just
5501 hand it to us again. So we have to wipe out any
5504 We could delete keybuf[t] and shift everything
5505 after that to the left by one spot, but we'd also
5506 have to fix up any variable that points into
5507 keybuf, and shifting isn't really necessary
5510 Adding prefixes for non-textual mouse clicks
5511 creates two characters of mock input, and both
5512 must be thrown away. If we're only looking at
5513 the prefix now, we can just jump back to
5514 replay_key. On the other hand, if we've already
5515 processed the prefix, and now the actual click
5516 itself is giving us trouble, then we've lost the
5517 state of the keymaps we want to backtrack to, and
5518 we need to replay the whole sequence to rebuild
5521 Beyond that, only function key expansion could
5522 create more than two keys, but that should never
5523 generate mouse events, so it's okay to zero
5524 mock_input in that case too.
5526 Isn't this just the most wonderful code ever? */
5527 if (t
== last_real_key_start
)
5534 mock_input
= last_real_key_start
;
5535 goto replay_sequence
;
5540 = apply_modifiers (modifiers
, XCONS (breakdown
)->car
);
5542 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
5544 /* Look for a binding for this new key. follow_key
5545 promises that it didn't munge submaps the
5546 last time we called it, since key was unbound. */
5548 = (follow_key (new_click
,
5549 nmaps
- local_first_binding
,
5550 submaps
+ local_first_binding
,
5551 defs
+ local_first_binding
,
5552 submaps
+ local_first_binding
)
5553 + local_first_binding
);
5555 /* If that click is bound, go for it. */
5556 if (first_binding
< nmaps
)
5561 /* Otherwise, we'll leave key set to the drag event. */
5568 /* Normally, last_nonmenu_event gets the previous key we read.
5569 But when a mouse popup menu is being used,
5570 we don't update last_nonmenu_event; it continues to hold the mouse
5571 event that preceded the first level of menu. */
5572 if (!used_mouse_menu
)
5573 last_nonmenu_event
= key
;
5575 /* If the sequence is unbound, see if we can hang a function key
5576 off the end of it. We only want to scan real keyboard input
5577 for function key sequences, so if mock_input says that we're
5578 re-reading old events, don't examine it. */
5579 if (first_binding
>= nmaps
5582 Lisp_Object fkey_next
;
5584 /* Continue scan from fkey_end until we find a bound suffix.
5585 If we fail, increment fkey_start
5586 and start fkey_end from there. */
5587 while (fkey_end
< t
)
5591 key
= keybuf
[fkey_end
++];
5592 /* Look up meta-characters by prefixing them
5593 with meta_prefix_char. I hate this. */
5594 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
5599 (access_keymap (fkey_map
, meta_prefix_char
, 1, 0)),
5601 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
5604 fkey_next
= fkey_map
;
5607 = get_keyelt (access_keymap (fkey_next
, key
, 1, 0));
5609 #if 0 /* I didn't turn this on, because it might cause trouble
5610 for the mapping of return into C-m and tab into C-i. */
5611 /* Optionally don't map function keys into other things.
5612 This enables the user to redefine kp- keys easily. */
5613 if (SYMBOLP (key
) && !NILP (Vinhibit_function_key_mapping
))
5617 /* If the function key map gives a function, not an
5618 array, then call the function with no args and use
5619 its value instead. */
5620 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
5623 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5627 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
5628 fkey_next
= call1 (fkey_next
, prompt
);
5630 /* If the function returned something invalid,
5631 barf--don't ignore it.
5632 (To ignore it safely, we would need to gcpro a bunch of
5633 other variables.) */
5634 if (! (VECTORP (fkey_next
) || STRINGP (fkey_next
)))
5635 error ("Function in function-key-map returns invalid key sequence");
5638 function_key_possible
= ! NILP (fkey_next
);
5640 /* If keybuf[fkey_start..fkey_end] is bound in the
5641 function key map and it's a suffix of the current
5642 sequence (i.e. fkey_end == t), replace it with
5643 the binding and restart with fkey_start at the end. */
5644 if ((VECTORP (fkey_next
) || STRINGP (fkey_next
))
5647 int len
= XFASTINT (Flength (fkey_next
));
5649 t
= fkey_start
+ len
;
5651 error ("key sequence too long");
5653 if (VECTORP (fkey_next
))
5654 bcopy (XVECTOR (fkey_next
)->contents
,
5655 keybuf
+ fkey_start
,
5656 (t
- fkey_start
) * sizeof (keybuf
[0]));
5657 else if (STRINGP (fkey_next
))
5661 for (i
= 0; i
< len
; i
++)
5662 XSETFASTINT (keybuf
[fkey_start
+ i
],
5663 XSTRING (fkey_next
)->data
[i
]);
5667 fkey_start
= fkey_end
= t
;
5668 fkey_map
= Vfunction_key_map
;
5670 /* Do pass the results through key-translation-map. */
5671 keytran_start
= keytran_end
= 0;
5672 keytran_map
= Vkey_translation_map
;
5674 goto replay_sequence
;
5677 fkey_map
= get_keymap_1 (fkey_next
, 0, 1);
5679 /* If we no longer have a bound suffix, try a new positions for
5681 if (NILP (fkey_map
))
5683 fkey_end
= ++fkey_start
;
5684 fkey_map
= Vfunction_key_map
;
5685 function_key_possible
= 0;
5690 /* Look for this sequence in key-translation-map. */
5692 Lisp_Object keytran_next
;
5694 /* Scan from keytran_end until we find a bound suffix. */
5695 while (keytran_end
< t
)
5699 key
= keybuf
[keytran_end
++];
5700 /* Look up meta-characters by prefixing them
5701 with meta_prefix_char. I hate this. */
5702 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
5707 (access_keymap (keytran_map
, meta_prefix_char
, 1, 0)),
5709 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
5712 keytran_next
= keytran_map
;
5715 = get_keyelt (access_keymap (keytran_next
, key
, 1, 0));
5717 /* If the key translation map gives a function, not an
5718 array, then call the function with no args and use
5719 its value instead. */
5720 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
5721 && keytran_end
== t
)
5723 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5727 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
5728 keytran_next
= call1 (keytran_next
, prompt
);
5730 /* If the function returned something invalid,
5731 barf--don't ignore it.
5732 (To ignore it safely, we would need to gcpro a bunch of
5733 other variables.) */
5734 if (! (VECTORP (keytran_next
) || STRINGP (keytran_next
)))
5735 error ("Function in key-translation-map returns invalid key sequence");
5738 key_translation_possible
= ! NILP (keytran_next
);
5740 /* If keybuf[keytran_start..keytran_end] is bound in the
5741 key translation map and it's a suffix of the current
5742 sequence (i.e. keytran_end == t), replace it with
5743 the binding and restart with keytran_start at the end. */
5744 if ((VECTORP (keytran_next
) || STRINGP (keytran_next
))
5745 && keytran_end
== t
)
5747 int len
= XFASTINT (Flength (keytran_next
));
5749 t
= keytran_start
+ len
;
5751 error ("key sequence too long");
5753 if (VECTORP (keytran_next
))
5754 bcopy (XVECTOR (keytran_next
)->contents
,
5755 keybuf
+ keytran_start
,
5756 (t
- keytran_start
) * sizeof (keybuf
[0]));
5757 else if (STRINGP (keytran_next
))
5761 for (i
= 0; i
< len
; i
++)
5762 XSETFASTINT (keybuf
[keytran_start
+ i
],
5763 XSTRING (keytran_next
)->data
[i
]);
5767 keytran_start
= keytran_end
= t
;
5768 keytran_map
= Vkey_translation_map
;
5770 /* Don't pass the results of key-translation-map
5771 through function-key-map. */
5772 fkey_start
= fkey_end
= t
;
5773 fkey_map
= Vkey_translation_map
;
5775 goto replay_sequence
;
5778 keytran_map
= get_keymap_1 (keytran_next
, 0, 1);
5780 /* If we no longer have a bound suffix, try a new positions for
5782 if (NILP (keytran_map
))
5784 keytran_end
= ++keytran_start
;
5785 keytran_map
= Vkey_translation_map
;
5786 key_translation_possible
= 0;
5791 /* If KEY is not defined in any of the keymaps,
5792 and cannot be part of a function key or translation,
5793 and is an upper case letter
5794 use the corresponding lower-case letter instead. */
5795 if (first_binding
== nmaps
&& ! function_key_possible
5796 && ! key_translation_possible
5798 && ((((XINT (key
) & 0x3ffff)
5799 < XSTRING (current_buffer
->downcase_table
)->size
)
5800 && UPPERCASEP (XINT (key
) & 0x3ffff))
5801 || (XINT (key
) & shift_modifier
)))
5803 original_uppercase
= key
;
5804 original_uppercase_position
= t
- 1;
5806 if (XINT (key
) & shift_modifier
)
5807 XSETINT (key
, XINT (key
) & ~shift_modifier
);
5809 XSETINT (key
, (DOWNCASE (XINT (key
) & 0x3ffff)
5810 | (XINT (key
) & ~0x3ffff)));
5812 keybuf
[t
- 1] = key
;
5814 goto replay_sequence
;
5816 /* If KEY is not defined in any of the keymaps,
5817 and cannot be part of a function key or translation,
5818 and is a shifted function key,
5819 use the corresponding unshifted function key instead. */
5820 if (first_binding
== nmaps
&& ! function_key_possible
5821 && ! key_translation_possible
5824 Lisp_Object breakdown
;
5827 original_uppercase
= key
;
5828 original_uppercase_position
= t
- 1;
5830 breakdown
= parse_modifiers (key
);
5831 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
5832 if (modifiers
& shift_modifier
)
5834 modifiers
&= ~shift_modifier
;
5835 key
= apply_modifiers (modifiers
,
5836 XCONS (breakdown
)->car
);
5838 keybuf
[t
- 1] = key
;
5840 goto replay_sequence
;
5846 read_key_sequence_cmd
= (first_binding
< nmaps
5847 ? defs
[first_binding
]
5850 unread_switch_frame
= delayed_switch_frame
;
5851 unbind_to (count
, Qnil
);
5853 if (dont_downcase_last
&& t
- 1 == original_uppercase_position
)
5854 keybuf
[t
- 1] = original_uppercase
;
5856 /* Occasionally we fabricate events, perhaps by expanding something
5857 according to function-key-map, or by adding a prefix symbol to a
5858 mouse click in the scroll bar or modeline. In this cases, return
5859 the entire generated key sequence, even if we hit an unbound
5860 prefix or a definition before the end. This means that you will
5861 be able to push back the event properly, and also means that
5862 read-key-sequence will always return a logical unit.
5865 for (; t
< mock_input
; t
++)
5867 if (echo_keystrokes
)
5868 echo_char (keybuf
[t
]);
5869 add_command_key (keybuf
[t
]);
5875 #if 0 /* This doc string is too long for some compilers.
5876 This commented-out definition serves for DOC. */
5877 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
5878 "Read a sequence of keystrokes and return as a string or vector.\n\
5879 The sequence is sufficient to specify a non-prefix command in the\n\
5880 current local and global maps.\n\
5882 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
5883 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
5884 as a continuation of the previous key.\n\
5886 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not\n\
5887 convert the last event to lower case. (Normally any upper case event\n\
5888 is converted to lower case if the original event is undefined and the lower\n\
5889 case equivalent is defined.) A non-nil value is appropriate for reading\n\
5890 a key sequence to be defined.\n\
5892 A C-g typed while in this function is treated like any other character,\n\
5893 and `quit-flag' is not set.\n\
5895 If the key sequence starts with a mouse click, then the sequence is read\n\
5896 using the keymaps of the buffer of the window clicked in, not the buffer\n\
5897 of the selected window as normal.\n\
5899 `read-key-sequence' drops unbound button-down events, since you normally\n\
5900 only care about the click or drag events which follow them. If a drag\n\
5901 or multi-click event is unbound, but the corresponding click event would\n\
5902 be bound, `read-key-sequence' turns the event into a click event at the\n\
5903 drag's starting position. This means that you don't have to distinguish\n\
5904 between click and drag, double, or triple events unless you want to.\n\
5906 `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\
5907 lines separating windows, and scroll bars with imaginary keys\n\
5908 `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\
5910 Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this\n\
5911 function will process a switch-frame event if the user switches frames\n\
5912 before typing anything. If the user switches frames in the middle of a\n\
5913 key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME\n\
5914 is nil, then the event will be put off until after the current key sequence.\n\
5916 `read-key-sequence' checks `function-key-map' for function key\n\
5917 sequences, where they wouldn't conflict with ordinary bindings. See\n\
5918 `function-key-map' for more details.")
5919 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
)
5922 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
5924 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
)
5925 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
5926 Lisp_Object can_return_switch_frame
;
5928 Lisp_Object keybuf
[30];
5930 struct gcpro gcpro1
, gcpro2
;
5933 CHECK_STRING (prompt
, 0);
5936 bzero (keybuf
, sizeof keybuf
);
5938 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
5940 if (NILP (continue_echo
))
5941 this_command_key_count
= 0;
5943 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
5944 prompt
, ! NILP (dont_downcase_last
),
5945 ! NILP (can_return_switch_frame
));
5953 return make_event_array (i
, keybuf
);
5956 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 2, 0,
5957 "Execute CMD as an editor command.\n\
5958 CMD must be a symbol that satisfies the `commandp' predicate.\n\
5959 Optional second arg RECORD-FLAG non-nil\n\
5960 means unconditionally put this command in `command-history'.\n\
5961 Otherwise, that is done only if an arg is read using the minibuffer.")
5963 Lisp_Object cmd
, record
;
5965 register Lisp_Object final
;
5966 register Lisp_Object tem
;
5967 Lisp_Object prefixarg
;
5968 struct backtrace backtrace
;
5969 extern int debug_on_next_call
;
5971 prefixarg
= current_kboard
->Vprefix_arg
;
5972 current_kboard
->Vprefix_arg
= Qnil
;
5973 Vcurrent_prefix_arg
= prefixarg
;
5974 debug_on_next_call
= 0;
5978 tem
= Fget (cmd
, Qdisabled
);
5979 if (!NILP (tem
) && !NILP (Vrun_hooks
))
5980 return call1 (Vrun_hooks
, Qdisabled_command_hook
);
5985 final
= Findirect_function (cmd
);
5987 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
5988 do_autoload (final
, cmd
);
5993 if (STRINGP (final
) || VECTORP (final
))
5995 /* If requested, place the macro in the command history. For
5996 other sorts of commands, call-interactively takes care of
6000 = Fcons (Fcons (Qexecute_kbd_macro
,
6001 Fcons (final
, Fcons (prefixarg
, Qnil
))),
6004 return Fexecute_kbd_macro (final
, prefixarg
);
6006 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
6008 backtrace
.next
= backtrace_list
;
6009 backtrace_list
= &backtrace
;
6010 backtrace
.function
= &Qcall_interactively
;
6011 backtrace
.args
= &cmd
;
6012 backtrace
.nargs
= 1;
6013 backtrace
.evalargs
= 0;
6015 tem
= Fcall_interactively (cmd
, record
);
6017 backtrace_list
= backtrace
.next
;
6023 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
6025 "Read function name, then read its arguments and call it.")
6027 Lisp_Object prefixarg
;
6029 Lisp_Object function
;
6031 Lisp_Object saved_keys
;
6032 struct gcpro gcpro1
;
6034 saved_keys
= Fvector (this_command_key_count
,
6035 XVECTOR (this_command_keys
)->contents
);
6037 GCPRO1 (saved_keys
);
6039 if (EQ (prefixarg
, Qminus
))
6041 else if (CONSP (prefixarg
) && XINT (XCONS (prefixarg
)->car
) == 4)
6042 strcpy (buf
, "C-u ");
6043 else if (CONSP (prefixarg
) && INTEGERP (XCONS (prefixarg
)->car
))
6045 if (sizeof (int) == sizeof (EMACS_INT
))
6046 sprintf (buf
, "%d ", XINT (XCONS (prefixarg
)->car
));
6047 else if (sizeof (long) == sizeof (EMACS_INT
))
6048 sprintf (buf
, "%ld ", XINT (XCONS (prefixarg
)->car
));
6052 else if (INTEGERP (prefixarg
))
6054 if (sizeof (int) == sizeof (EMACS_INT
))
6055 sprintf (buf
, "%d ", XINT (prefixarg
));
6056 else if (sizeof (long) == sizeof (EMACS_INT
))
6057 sprintf (buf
, "%ld ", XINT (prefixarg
));
6062 /* This isn't strictly correct if execute-extended-command
6063 is bound to anything else. Perhaps it should use
6064 this_command_keys? */
6065 strcat (buf
, "M-x ");
6067 /* Prompt with buf, and then read a string, completing from and
6068 restricting to the set of all defined commands. Don't provide
6069 any initial input. Save the command read on the extended-command
6071 function
= Fcompleting_read (build_string (buf
),
6072 Vobarray
, Qcommandp
,
6073 Qt
, Qnil
, Qextended_command_history
);
6075 /* Set this_command_keys to the concatenation of saved_keys and
6076 function, followed by a RET. */
6078 struct Lisp_String
*str
;
6083 this_command_key_count
= 0;
6085 keys
= XVECTOR (saved_keys
)->contents
;
6086 for (i
= 0; i
< XVECTOR (saved_keys
)->size
; i
++)
6087 add_command_key (keys
[i
]);
6089 str
= XSTRING (function
);
6090 for (i
= 0; i
< str
->size
; i
++)
6092 XSETFASTINT (tem
, str
->data
[i
]);
6093 add_command_key (tem
);
6096 XSETFASTINT (tem
, '\015');
6097 add_command_key (tem
);
6102 function
= Fintern (function
, Qnil
);
6103 current_kboard
->Vprefix_arg
= prefixarg
;
6104 this_command
= function
;
6106 return Fcommand_execute (function
, Qt
);
6110 detect_input_pending ()
6113 get_input_pending (&input_pending
);
6115 return input_pending
;
6118 /* This is called in some cases before a possible quit.
6119 It cases the next call to detect_input_pending to recompute input_pending.
6120 So calling this function unnecessarily can't do any harm. */
6121 clear_input_pending ()
6126 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
6127 "T if command input is currently available with no waiting.\n\
6128 Actually, the value is nil only if we can be sure that no input is available.")
6131 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1)
6134 return detect_input_pending () ? Qt
: Qnil
;
6137 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
6138 "Return vector of last 100 events, not counting those from keyboard macros.")
6141 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
6144 if (total_keys
< NUM_RECENT_KEYS
)
6145 return Fvector (total_keys
, keys
);
6148 val
= Fvector (NUM_RECENT_KEYS
, keys
);
6149 bcopy (keys
+ recent_keys_index
,
6150 XVECTOR (val
)->contents
,
6151 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
6153 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
6154 recent_keys_index
* sizeof (Lisp_Object
));
6159 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
6160 "Return the key sequence that invoked this command.\n\
6161 The value is a string or a vector.")
6164 return make_event_array (this_command_key_count
,
6165 XVECTOR (this_command_keys
)->contents
);
6168 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
6169 "Return the current depth in recursive edits.")
6173 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
6177 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
6178 "FOpen dribble file: ",
6179 "Start writing all keyboard characters to a dribble file called FILE.\n\
6180 If FILE is nil, close any open dribble file.")
6194 file
= Fexpand_file_name (file
, Qnil
);
6195 dribble
= fopen (XSTRING (file
)->data
, "w");
6200 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
6201 "Discard the contents of the terminal input buffer.\n\
6202 Also cancel any kbd macro being defined.")
6205 current_kboard
->defining_kbd_macro
= Qnil
;
6206 update_mode_lines
++;
6208 Vunread_command_events
= Qnil
;
6209 unread_command_char
= -1;
6211 discard_tty_input ();
6213 /* Without the cast, GCC complains that this assignment loses the
6214 volatile qualifier of kbd_store_ptr. Is there anything wrong
6216 kbd_fetch_ptr
= (struct input_event
*) kbd_store_ptr
;
6217 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
6223 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
6224 "Stop Emacs and return to superior process. You can resume later.\n\
6225 If `cannot-suspend' is non-nil, or if the system doesn't support job\n\
6226 control, run a subshell instead.\n\n\
6227 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
6228 to be read as terminal input by Emacs's parent, after suspension.\n\
6230 Before suspending, run the normal hook `suspend-hook'.\n\
6231 After resumption run the normal hook `suspend-resume-hook'.\n\
6233 Some operating systems cannot stop the Emacs process and resume it later.\n\
6234 On such systems, Emacs starts a subshell instead of suspending.")
6236 Lisp_Object stuffstring
;
6239 int count
= specpdl_ptr
- specpdl
;
6240 int old_height
, old_width
;
6242 struct gcpro gcpro1
, gcpro2
;
6243 extern init_sys_modes ();
6245 if (!NILP (stuffstring
))
6246 CHECK_STRING (stuffstring
, 0);
6248 /* Run the functions in suspend-hook. */
6249 if (!NILP (Vrun_hooks
))
6250 call1 (Vrun_hooks
, intern ("suspend-hook"));
6252 GCPRO1 (stuffstring
);
6253 get_frame_size (&old_width
, &old_height
);
6255 /* sys_suspend can get an error if it tries to fork a subshell
6256 and the system resources aren't available for that. */
6257 record_unwind_protect (init_sys_modes
, 0);
6258 stuff_buffered_input (stuffstring
);
6263 unbind_to (count
, Qnil
);
6265 /* Check if terminal/window size has changed.
6266 Note that this is not useful when we are running directly
6267 with a window system; but suspend should be disabled in that case. */
6268 get_frame_size (&width
, &height
);
6269 if (width
!= old_width
|| height
!= old_height
)
6270 change_frame_size (selected_frame
, height
, width
, 0, 0);
6272 /* Run suspend-resume-hook. */
6273 if (!NILP (Vrun_hooks
))
6274 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
6280 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
6281 Then in any case stuff anything Emacs has read ahead and not used. */
6283 stuff_buffered_input (stuffstring
)
6284 Lisp_Object stuffstring
;
6286 /* stuff_char works only in BSD, versions 4.2 and up. */
6289 register unsigned char *p
;
6291 if (STRINGP (stuffstring
))
6295 p
= XSTRING (stuffstring
)->data
;
6296 count
= XSTRING (stuffstring
)->size
;
6301 /* Anything we have read ahead, put back for the shell to read. */
6302 /* ?? What should this do when we have multiple keyboards??
6303 Should we ignore anything that was typed in at the "wrong" kboard? */
6304 for (; kbd_fetch_ptr
!= kbd_store_ptr
; kbd_fetch_ptr
++)
6306 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
6307 kbd_fetch_ptr
= kbd_buffer
;
6308 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
6309 stuff_char (kbd_fetch_ptr
->code
);
6310 kbd_fetch_ptr
->kind
= no_event
;
6311 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_fetch_ptr
6317 #endif /* BSD and not BSD4_1 */
6320 set_waiting_for_input (time_to_clear
)
6321 EMACS_TIME
*time_to_clear
;
6323 input_available_clear_time
= time_to_clear
;
6325 /* Tell interrupt_signal to throw back to read_char, */
6326 waiting_for_input
= 1;
6328 /* If interrupt_signal was called before and buffered a C-g,
6329 make it run again now, to avoid timing error. */
6330 if (!NILP (Vquit_flag
))
6331 quit_throw_to_read_char ();
6334 clear_waiting_for_input ()
6336 /* Tell interrupt_signal not to throw back to read_char, */
6337 waiting_for_input
= 0;
6338 input_available_clear_time
= 0;
6341 /* This routine is called at interrupt level in response to C-G.
6342 If interrupt_input, this is the handler for SIGINT.
6343 Otherwise, it is called from kbd_buffer_store_event,
6344 in handling SIGIO or SIGTINT.
6346 If `waiting_for_input' is non zero, then unless `echoing' is nonzero,
6347 immediately throw back to read_char.
6349 Otherwise it sets the Lisp variable quit-flag not-nil.
6350 This causes eval to throw, when it gets a chance.
6351 If quit-flag is already non-nil, it stops the job right away. */
6354 interrupt_signal (signalnum
) /* If we don't have an argument, */
6355 int signalnum
; /* some compilers complain in signal calls. */
6358 /* Must preserve main program's value of errno. */
6359 int old_errno
= errno
;
6362 if (!read_socket_hook
&& NILP (Vwindow_system
))
6364 /* USG systems forget handlers when they are used;
6365 must reestablish each time */
6366 signal (SIGINT
, interrupt_signal
);
6367 signal (SIGQUIT
, interrupt_signal
);
6373 if (!NILP (Vquit_flag
) && FRAME_TERMCAP_P (selected_frame
))
6378 #ifdef SIGTSTP /* Support possible in later USG versions */
6380 * On systems which can suspend the current process and return to the original
6381 * shell, this command causes the user to end up back at the shell.
6382 * The "Auto-save" and "Abort" questions are not asked until
6383 * the user elects to return to emacs, at which point he can save the current
6384 * job and either dump core or continue.
6389 if (sys_suspend () == -1)
6391 printf ("Not running as a subprocess;\n");
6392 printf ("you can continue or abort.\n");
6395 /* Perhaps should really fork an inferior shell?
6396 But that would not provide any way to get back
6397 to the original shell, ever. */
6398 printf ("No support for stopping a process on this operating system;\n");
6399 printf ("you can continue or abort.\n");
6400 #endif /* not VMS */
6401 #endif /* not SIGTSTP */
6403 /* We must remain inside the screen area when the internal terminal
6404 is used. Note that [Enter] is not echoed by dos. */
6407 printf ("Auto-save? (y or n) ");
6409 if (((c
= getchar ()) & ~040) == 'Y')
6411 Fdo_auto_save (Qt
, Qnil
);
6413 printf ("\r\nAuto-save done");
6414 #else /* not MSDOS */
6415 printf ("Auto-save done\n");
6416 #endif /* not MSDOS */
6418 while (c
!= '\n') c
= getchar ();
6420 printf ("\r\nAbort? (y or n) ");
6421 #else /* not MSDOS */
6423 printf ("Abort (and enter debugger)? (y or n) ");
6425 printf ("Abort (and dump core)? (y or n) ");
6426 #endif /* not VMS */
6427 #endif /* not MSDOS */
6429 if (((c
= getchar ()) & ~040) == 'Y')
6431 while (c
!= '\n') c
= getchar ();
6433 printf ("\r\nContinuing...\r\n");
6434 #else /* not MSDOS */
6435 printf ("Continuing...\n");
6436 #endif /* not MSDOS */
6442 /* If executing a function that wants to be interrupted out of
6443 and the user has not deferred quitting by binding `inhibit-quit'
6444 then quit right away. */
6445 if (immediate_quit
&& NILP (Vinhibit_quit
))
6449 Fsignal (Qquit
, Qnil
);
6452 /* Else request quit when it's safe */
6456 if (waiting_for_input
&& !echoing
)
6457 quit_throw_to_read_char ();
6462 /* Handle a C-g by making read_char return C-g. */
6464 quit_throw_to_read_char ()
6466 quit_error_check ();
6468 /* Prevent another signal from doing this before we finish. */
6469 clear_waiting_for_input ();
6472 Vunread_command_events
= Qnil
;
6473 unread_command_char
= -1;
6475 #ifdef POLL_FOR_INPUT
6476 /* May be > 1 if in recursive minibuffer. */
6477 if (poll_suppress_count
== 0)
6481 if (FRAMEP (internal_last_event_frame
)
6482 && XFRAME (internal_last_event_frame
) != selected_frame
)
6483 Fhandle_switch_frame (make_lispy_switch_frame (internal_last_event_frame
));
6486 _longjmp (getcjmp
, 1);
6489 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
6490 "Set mode of reading keyboard input.\n\
6491 First arg INTERRUPT non-nil means use input interrupts;\n\
6492 nil means use CBREAK mode.\n\
6493 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
6494 (no effect except in CBREAK mode).\n\
6495 Third arg META t means accept 8-bit input (for a Meta key).\n\
6496 META nil means ignore the top bit, on the assumption it is parity.\n\
6497 Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\
6498 Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\
6499 See also `current-input-mode'.")
6500 (interrupt
, flow
, meta
, quit
)
6501 Lisp_Object interrupt
, flow
, meta
, quit
;
6504 && (!INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400))
6505 error ("set-input-mode: QUIT must be an ASCII character");
6507 #ifdef POLL_FOR_INPUT
6513 /* Note SIGIO has been undef'd if FIONREAD is missing. */
6514 if (read_socket_hook
)
6516 /* When using X, don't give the user a real choice,
6517 because we haven't implemented the mechanisms to support it. */
6518 #ifdef NO_SOCK_SIGIO
6519 interrupt_input
= 0;
6520 #else /* not NO_SOCK_SIGIO */
6521 interrupt_input
= 1;
6522 #endif /* NO_SOCK_SIGIO */
6525 interrupt_input
= !NILP (interrupt
);
6526 #else /* not SIGIO */
6527 interrupt_input
= 0;
6528 #endif /* not SIGIO */
6530 /* Our VMS input only works by interrupts, as of now. */
6532 interrupt_input
= 1;
6535 flow_control
= !NILP (flow
);
6538 else if (EQ (meta
, Qt
))
6543 /* Don't let this value be out of range. */
6544 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
6548 #ifdef POLL_FOR_INPUT
6549 poll_suppress_count
= 1;
6555 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
6556 "Return information about the way Emacs currently reads keyboard input.\n\
6557 The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
6558 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\
6559 nil, Emacs is using CBREAK mode.\n\
6560 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\
6561 terminal; this does not apply if Emacs uses interrupt-driven input.\n\
6562 META is t if accepting 8-bit input with 8th bit as Meta flag.\n\
6563 META nil means ignoring the top bit, on the assumption it is parity.\n\
6564 META is neither t nor nil if accepting 8-bit input and using\n\
6565 all 8 bits as the character code.\n\
6566 QUIT is the character Emacs currently uses to quit.\n\
6567 The elements of this list correspond to the arguments of\n\
6573 val
[0] = interrupt_input
? Qt
: Qnil
;
6574 val
[1] = flow_control
? Qt
: Qnil
;
6575 val
[2] = meta_key
== 2 ? make_number (0) : meta_key
== 1 ? Qt
: Qnil
;
6576 XSETFASTINT (val
[3], quit_char
);
6578 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
6583 * Set up a new kboard object with reasonable initial values.
6589 kb
->Vprefix_arg
= Qnil
;
6590 kb
->kbd_queue
= Qnil
;
6591 kb
->kbd_queue_has_data
= 0;
6592 kb
->immediate_echo
= 0;
6593 kb
->echoptr
= kb
->echobuf
;
6594 kb
->echo_after_prompt
= -1;
6595 kb
->kbd_macro_buffer
= 0;
6596 kb
->kbd_macro_bufsize
= 0;
6597 kb
->defining_kbd_macro
= Qnil
;
6598 kb
->Vlast_kbd_macro
= Qnil
;
6599 kb
->reference_count
= 0;
6600 kb
->Vsystem_key_alist
= Qnil
;
6601 kb
->Vdefault_minibuffer_frame
= Qnil
;
6605 * Destroy the contents of a kboard object, but not the object itself.
6606 * We use this just before deleteing it, or if we're going to initialize
6613 if (kb
->kbd_macro_buffer
)
6614 xfree (kb
->kbd_macro_buffer
);
6623 for (kbp
= &all_kboards
; *kbp
!= kb
; kbp
= &(*kbp
)->next_kboard
)
6626 *kbp
= kb
->next_kboard
;
6634 /* This is correct before outermost invocation of the editor loop */
6635 command_loop_level
= -1;
6637 quit_char
= Ctl ('g');
6638 Vunread_command_events
= Qnil
;
6639 unread_command_char
= -1;
6641 recent_keys_index
= 0;
6642 kbd_fetch_ptr
= kbd_buffer
;
6643 kbd_store_ptr
= kbd_buffer
;
6644 kbd_buffer_frame_or_window
6645 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
6647 do_mouse_tracking
= Qnil
;
6652 /* This means that command_loop_1 won't try to select anything the first
6654 internal_last_event_frame
= Qnil
;
6655 Vlast_event_frame
= internal_last_event_frame
;
6659 current_kboard
= initial_kboard
;
6661 wipe_kboard (current_kboard
);
6662 init_kboard (current_kboard
);
6665 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
6667 kbd_buffer_frame_or_window
6668 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
6669 if (!noninteractive
&& !read_socket_hook
&& NILP (Vwindow_system
))
6671 signal (SIGINT
, interrupt_signal
);
6672 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
6673 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
6674 SIGQUIT and we can't tell which one it will give us. */
6675 signal (SIGQUIT
, interrupt_signal
);
6676 #endif /* HAVE_TERMIO */
6678 /* Note SIGIO has been undef'd if FIONREAD is missing. */
6680 if (!noninteractive
)
6681 signal (SIGIO
, input_available_signal
);
6684 /* Use interrupt input by default, if it works and noninterrupt input
6685 has deficiencies. */
6687 #ifdef INTERRUPT_INPUT
6688 interrupt_input
= 1;
6690 interrupt_input
= 0;
6693 /* Our VMS input only works by interrupts, as of now. */
6695 interrupt_input
= 1;
6701 if (keyboard_init_hook
)
6702 (*keyboard_init_hook
) ();
6704 #ifdef POLL_FOR_INPUT
6705 poll_suppress_count
= 1;
6710 /* This type's only use is in syms_of_keyboard, to initialize the
6711 event header symbols and put properties on them. */
6718 struct event_head head_table
[] = {
6719 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
6720 &Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
,
6721 &Qswitch_frame
, "switch-frame", &Qswitch_frame
,
6722 &Qdelete_frame
, "delete-frame", &Qdelete_frame
,
6723 &Qiconify_frame
, "iconify-frame", &Qiconify_frame
,
6724 &Qmake_frame_visible
, "make-frame-visible", &Qmake_frame_visible
,
6729 Qdisabled_command_hook
= intern ("disabled-command-hook");
6730 staticpro (&Qdisabled_command_hook
);
6732 Qself_insert_command
= intern ("self-insert-command");
6733 staticpro (&Qself_insert_command
);
6735 Qforward_char
= intern ("forward-char");
6736 staticpro (&Qforward_char
);
6738 Qbackward_char
= intern ("backward-char");
6739 staticpro (&Qbackward_char
);
6741 Qdisabled
= intern ("disabled");
6742 staticpro (&Qdisabled
);
6744 Qundefined
= intern ("undefined");
6745 staticpro (&Qundefined
);
6747 Qpre_command_hook
= intern ("pre-command-hook");
6748 staticpro (&Qpre_command_hook
);
6750 Qpost_command_hook
= intern ("post-command-hook");
6751 staticpro (&Qpost_command_hook
);
6753 Qdeferred_action_function
= intern ("deferred-action-function");
6754 staticpro (&Qdeferred_action_function
);
6756 Qcommand_hook_internal
= intern ("command-hook-internal");
6757 staticpro (&Qcommand_hook_internal
);
6759 Qfunction_key
= intern ("function-key");
6760 staticpro (&Qfunction_key
);
6761 Qmouse_click
= intern ("mouse-click");
6762 staticpro (&Qmouse_click
);
6764 Qmenu_enable
= intern ("menu-enable");
6765 staticpro (&Qmenu_enable
);
6767 Qmode_line
= intern ("mode-line");
6768 staticpro (&Qmode_line
);
6769 Qvertical_line
= intern ("vertical-line");
6770 staticpro (&Qvertical_line
);
6771 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
6772 staticpro (&Qvertical_scroll_bar
);
6773 Qmenu_bar
= intern ("menu-bar");
6774 staticpro (&Qmenu_bar
);
6776 Qabove_handle
= intern ("above-handle");
6777 staticpro (&Qabove_handle
);
6778 Qhandle
= intern ("handle");
6779 staticpro (&Qhandle
);
6780 Qbelow_handle
= intern ("below-handle");
6781 staticpro (&Qbelow_handle
);
6783 Qevent_kind
= intern ("event-kind");
6784 staticpro (&Qevent_kind
);
6785 Qevent_symbol_elements
= intern ("event-symbol-elements");
6786 staticpro (&Qevent_symbol_elements
);
6787 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
6788 staticpro (&Qevent_symbol_element_mask
);
6789 Qmodifier_cache
= intern ("modifier-cache");
6790 staticpro (&Qmodifier_cache
);
6792 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
6793 staticpro (&Qrecompute_lucid_menubar
);
6794 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
6795 staticpro (&Qactivate_menubar_hook
);
6797 Qpolling_period
= intern ("polling-period");
6798 staticpro (&Qpolling_period
);
6801 struct event_head
*p
;
6803 for (p
= head_table
;
6804 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
6807 *p
->var
= intern (p
->name
);
6809 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
6810 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
6814 button_down_location
= Fmake_vector (make_number (NUM_MOUSE_BUTTONS
), Qnil
);
6815 staticpro (&button_down_location
);
6819 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
6821 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
6822 for (i
= 0; i
< len
; i
++)
6823 if (modifier_names
[i
])
6824 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
6825 staticpro (&modifier_symbols
);
6828 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
6829 staticpro (&recent_keys
);
6831 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
6832 staticpro (&this_command_keys
);
6834 Qextended_command_history
= intern ("extended-command-history");
6835 Fset (Qextended_command_history
, Qnil
);
6836 staticpro (&Qextended_command_history
);
6838 kbd_buffer_frame_or_window
6839 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
6840 staticpro (&kbd_buffer_frame_or_window
);
6842 accent_key_syms
= Qnil
;
6843 staticpro (&accent_key_syms
);
6845 func_key_syms
= Qnil
;
6846 staticpro (&func_key_syms
);
6848 system_key_syms
= Qnil
;
6849 staticpro (&system_key_syms
);
6852 staticpro (&mouse_syms
);
6854 unread_switch_frame
= Qnil
;
6855 staticpro (&unread_switch_frame
);
6857 defsubr (&Sread_key_sequence
);
6858 defsubr (&Srecursive_edit
);
6860 defsubr (&Strack_mouse
);
6862 defsubr (&Sinput_pending_p
);
6863 defsubr (&Scommand_execute
);
6864 defsubr (&Srecent_keys
);
6865 defsubr (&Sthis_command_keys
);
6866 defsubr (&Ssuspend_emacs
);
6867 defsubr (&Sabort_recursive_edit
);
6868 defsubr (&Sexit_recursive_edit
);
6869 defsubr (&Srecursion_depth
);
6870 defsubr (&Stop_level
);
6871 defsubr (&Sdiscard_input
);
6872 defsubr (&Sopen_dribble_file
);
6873 defsubr (&Sset_input_mode
);
6874 defsubr (&Scurrent_input_mode
);
6875 defsubr (&Sexecute_extended_command
);
6877 DEFVAR_LISP ("last-command-char", &last_command_char
,
6878 "Last input event that was part of a command.");
6880 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char
,
6881 "Last input event that was part of a command.");
6883 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
6884 "Last input event in a command, except for mouse menu events.\n\
6885 Mouse menus give back keys that don't look like mouse events;\n\
6886 this variable holds the actual mouse event that led to the menu,\n\
6887 so that you can determine whether the command was run by mouse or not.");
6889 DEFVAR_LISP ("last-input-char", &last_input_char
,
6890 "Last input event.");
6892 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char
,
6893 "Last input event.");
6895 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
6896 "List of objects to be read as next command input events.");
6898 DEFVAR_INT ("unread-command-char", &unread_command_char
,
6899 "If not -1, an object to be read as next command input event.");
6901 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
6902 "Meta-prefix character code. Meta-foo as command input\n\
6903 turns into this character followed by foo.");
6904 XSETINT (meta_prefix_char
, 033);
6906 DEFVAR_LISP ("last-command", &last_command
,
6907 "The last command executed. Normally a symbol with a function definition,\n\
6908 but can be whatever was found in the keymap, or whatever the variable\n\
6909 `this-command' was set to by that command.\n\
6911 The value `mode-exit' is special; it means that the previous command\n\
6912 read an event that told it to exit, and it did so and unread that event.\n\
6913 In other words, the present command is the event that made the previous\n\
6916 The value `kill-region' is special; it means that the previous command\n\
6917 was a kill command.");
6918 last_command
= Qnil
;
6920 DEFVAR_LISP ("this-command", &this_command
,
6921 "The command now being executed.\n\
6922 The command can set this variable; whatever is put here\n\
6923 will be in `last-command' during the following command.");
6924 this_command
= Qnil
;
6926 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
6927 "*Number of keyboard input characters between auto-saves.\n\
6928 Zero means disable autosaving due to number of characters typed.");
6929 auto_save_interval
= 300;
6931 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
6932 "*Number of seconds idle time before auto-save.\n\
6933 Zero or nil means disable auto-saving due to idleness.\n\
6934 After auto-saving due to this many seconds of idle time,\n\
6935 Emacs also does a garbage collection if that seems to be warranted.");
6936 XSETFASTINT (Vauto_save_timeout
, 30);
6938 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes
,
6939 "*Nonzero means echo unfinished commands after this many seconds of pause.");
6940 echo_keystrokes
= 1;
6942 DEFVAR_INT ("polling-period", &polling_period
,
6943 "*Interval between polling for input during Lisp execution.\n\
6944 The reason for polling is to make C-g work to stop a running program.\n\
6945 Polling is needed only when using X windows and SIGIO does not work.\n\
6946 Polling is automatically disabled in all other cases.");
6949 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
6950 "*Maximum time between mouse clicks to make a double-click.\n\
6951 Measured in milliseconds. nil means disable double-click recognition;\n\
6952 t means double-clicks have no time limit and are detected\n\
6953 by position only.");
6954 Vdouble_click_time
= make_number (500);
6956 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
6957 "*Non-nil means inhibit local map menu bar menus.");
6958 inhibit_local_menu_bar_menus
= 0;
6960 DEFVAR_INT ("num-input-keys", &num_input_keys
,
6961 "Number of complete keys read from the keyboard so far.");
6964 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
6965 "The frame in which the most recently read event occurred.\n\
6966 If the last event came from a keyboard macro, this is set to `macro'.");
6967 Vlast_event_frame
= Qnil
;
6969 DEFVAR_LISP ("help-char", &Vhelp_char
,
6970 "Character to recognize as meaning Help.\n\
6971 When it is read, do `(eval help-form)', and display result if it's a string.\n\
6972 If the value of `help-form' is nil, this char can be read normally.");
6973 XSETINT (Vhelp_char
, Ctl ('H'));
6975 DEFVAR_LISP ("help-form", &Vhelp_form
,
6976 "Form to execute when character `help-char' is read.\n\
6977 If the form returns a string, that string is displayed.\n\
6978 If `help-form' is nil, the help char is not recognized.");
6981 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
6982 "Command to run when `help-char' character follows a prefix key.\n\
6983 This command is used only when there is no actual binding\n\
6984 for that character after that prefix key.");
6985 Vprefix_help_command
= Qnil
;
6987 DEFVAR_LISP ("top-level", &Vtop_level
,
6988 "Form to evaluate when Emacs starts up.\n\
6989 Useful to set before you dump a modified Emacs.");
6992 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
6993 "String used as translate table for keyboard input, or nil.\n\
6994 Each character is looked up in this string and the contents used instead.\n\
6995 If string is of length N, character codes N and up are untranslated.");
6996 Vkeyboard_translate_table
= Qnil
;
6998 DEFVAR_LISP ("key-translation-map", &Vkey_translation_map
,
6999 "Keymap of key translations that can override keymaps.\n\
7000 This keymap works like `function-key-map', but comes after that,\n\
7001 and applies even for keys that have ordinary bindings.");
7002 Vkey_translation_map
= Qnil
;
7004 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
7005 "Non-nil means to always spawn a subshell instead of suspending,\n\
7006 even if the operating system has support for stopping a process.");
7009 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
7010 "Non-nil means prompt with menus when appropriate.\n\
7011 This is done when reading from a keymap that has a prompt string,\n\
7012 for elements that have prompt strings.\n\
7013 The menu is displayed on the screen\n\
7014 if X menus were enabled at configuration\n\
7015 time and the previous event was a mouse click prefix key.\n\
7016 Otherwise, menu prompting uses the echo area.");
7019 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
7020 "Character to see next line of menu prompt.\n\
7021 Type this character while in a menu prompt to rotate around the lines of it.");
7022 XSETINT (menu_prompt_more_char
, ' ');
7024 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
7025 "A mask of additional modifier keys to use with every keyboard character.\n\
7026 Emacs applies the modifiers of the character stored here to each keyboard\n\
7027 character it reads. For example, after evaluating the expression\n\
7028 (setq extra-keyboard-modifiers ?\\C-x)\n\
7029 all input characters will have the control modifier applied to them.\n\
7031 Note that the character ?\\C-@, equivalent to the integer zero, does\n\
7032 not count as a control character; rather, it counts as a character\n\
7033 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\
7034 cancels any modification.");
7035 extra_keyboard_modifiers
= 0;
7037 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
7038 "If an editing command sets this to t, deactivate the mark afterward.\n\
7039 The command loop sets this to nil before each command,\n\
7040 and tests the value when the command returns.\n\
7041 Buffer modification stores t in this variable.");
7042 Vdeactivate_mark
= Qnil
;
7044 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
7045 "Temporary storage of pre-command-hook or post-command-hook.");
7046 Vcommand_hook_internal
= Qnil
;
7048 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
7049 "Normal hook run before each command is executed.\n\
7050 While the hook is run, its value is temporarily set to nil\n\
7051 to avoid an unbreakable infinite loop if a hook function gets an error.\n\
7052 As a result, a hook function cannot straightforwardly alter the value of\n\
7053 `pre-command-hook'. See the Emacs Lisp manual for a way of\n\
7054 implementing hook functions that alter the set of hook functions.");
7055 Vpre_command_hook
= Qnil
;
7057 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
7058 "Normal hook run after each command is executed.\n\
7059 While the hook is run, its value is temporarily set to nil\n\
7060 to avoid an unbreakable infinite loop if a hook function gets an error.\n\
7061 As a result, a hook function cannot straightforwardly alter the value of\n\
7062 `post-command-hook'. See the Emacs Lisp manual for a way of\n\
7063 implementing hook functions that alter the set of hook functions.");
7064 Vpost_command_hook
= Qnil
;
7066 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
7067 "t means menu bar, specified Lucid style, needs to be recomputed.");
7068 Vlucid_menu_bar_dirty_flag
= Qnil
;
7070 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
7071 "List of menu bar items to move to the end of the menu bar.\n\
7072 The elements of the list are event types that may have menu bar bindings.");
7073 Vmenu_bar_final_items
= Qnil
;
7075 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
7076 "Keymap that overrides all other local keymaps.\n\
7077 If this variable is non-nil, it is used as a keymap instead of the\n\
7078 buffer's local map, and the minor mode keymaps and text property keymaps.");
7079 Voverriding_local_map
= Qnil
;
7081 DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag
,
7082 "Non-nil means `overriding-local-map' applies to the menu bar.\n\
7083 Otherwise, the menu bar continues to reflect the buffer's local map\n\
7084 and the minor mode maps regardless of `overriding-local-map'.");
7085 Voverriding_local_map_menu_flag
= Qnil
;
7087 DEFVAR_LISP ("track-mouse", &do_mouse_tracking
,
7088 "*Non-nil means generate motion events for mouse motion.");
7090 DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist
,
7091 "Alist of system-specific X windows key symbols.\n\
7092 Each element should have the form (N . SYMBOL) where N is the\n\
7093 numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\
7094 and SYMBOL is its name.");
7096 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
7097 "List of deferred actions to be performed at a later time.\n\
7098 The precise format isn't relevant here; we just check whether it is nil.");
7099 Vdeferred_action_list
= Qnil
;
7101 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
7102 "Function to call to handle deferred actions, after each command.\n\
7103 This function is called with no arguments after each command\n\
7104 whenever `deferred-action-list' is non-nil.");
7105 Vdeferred_action_function
= Qnil
;
7110 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
7111 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
7112 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
7113 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
7114 initial_define_key (meta_map
, 'x', "execute-extended-command");