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
;
285 Lisp_Object Qdigit_argument
, Qnegative_argument
;
287 /* read_key_sequence stores here the command definition of the
288 key sequence that it reads. */
289 Lisp_Object read_key_sequence_cmd
;
291 /* Form to evaluate (if non-nil) when Emacs is started. */
292 Lisp_Object Vtop_level
;
294 /* User-supplied string to translate input characters through. */
295 Lisp_Object Vkeyboard_translate_table
;
297 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
298 extern Lisp_Object Vfunction_key_map
;
300 /* Keymap mapping ASCII function key sequences onto their preferred forms. */
301 Lisp_Object Vkey_translation_map
;
303 /* Non-nil means deactivate the mark at end of this command. */
304 Lisp_Object Vdeactivate_mark
;
306 /* Menu bar specified in Lucid Emacs fashion. */
308 Lisp_Object Vlucid_menu_bar_dirty_flag
;
309 Lisp_Object Qrecompute_lucid_menubar
, Qactivate_menubar_hook
;
311 /* Hooks to run before and after each command. */
312 Lisp_Object Qpre_command_hook
, Qpost_command_hook
;
313 Lisp_Object Vpre_command_hook
, Vpost_command_hook
;
314 Lisp_Object Qcommand_hook_internal
, Vcommand_hook_internal
;
316 /* List of deferred actions to be performed at a later time.
317 The precise format isn't relevant here; we just check whether it is nil. */
318 Lisp_Object Vdeferred_action_list
;
320 /* Function to call to handle deferred actions, when there are any. */
321 Lisp_Object Vdeferred_action_function
;
322 Lisp_Object Qdeferred_action_function
;
324 /* File in which we write all commands we read. */
327 /* Nonzero if input is available. */
330 /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
331 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
335 extern char *pending_malloc_warning
;
337 /* Circular buffer for pre-read keyboard input. */
338 static struct input_event kbd_buffer
[KBD_BUFFER_SIZE
];
340 /* Vector to GCPRO the frames and windows mentioned in kbd_buffer.
342 The interrupt-level event handlers will never enqueue an event on a
343 frame which is not in Vframe_list, and once an event is dequeued,
344 internal_last_event_frame or the event itself points to the frame.
347 But while the event is sitting in the queue, it's completely
348 unprotected. Suppose the user types one command which will run for
349 a while and then delete a frame, and then types another event at
350 the frame that will be deleted, before the command gets around to
351 it. Suppose there are no references to this frame elsewhere in
352 Emacs, and a GC occurs before the second event is dequeued. Now we
353 have an event referring to a freed frame, which will crash Emacs
356 Similar things happen when an event on a scroll bar is enqueued; the
357 window may be deleted while the event is in the queue.
359 So, we use this vector to protect the frame_or_window field in the
360 event queue. That way, they'll be dequeued as dead frames or
361 windows, but still valid lisp objects.
363 If kbd_buffer[i].kind != no_event, then
364 (XVECTOR (kbd_buffer_frame_or_window)->contents[i]
365 == kbd_buffer[i].frame_or_window. */
366 static Lisp_Object kbd_buffer_frame_or_window
;
368 /* Pointer to next available character in kbd_buffer.
369 If kbd_fetch_ptr == kbd_store_ptr, the buffer is empty.
370 This may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the the
371 next available char is in kbd_buffer[0]. */
372 static struct input_event
*kbd_fetch_ptr
;
374 /* Pointer to next place to store character in kbd_buffer. This
375 may be kbd_buffer + KBD_BUFFER_SIZE, meaning that the next
376 character should go in kbd_buffer[0]. */
377 static volatile struct input_event
*kbd_store_ptr
;
379 /* The above pair of variables forms a "queue empty" flag. When we
380 enqueue a non-hook event, we increment kbd_store_ptr. When we
381 dequeue a non-hook event, we increment kbd_fetch_ptr. We say that
382 there is input available iff the two pointers are not equal.
384 Why not just have a flag set and cleared by the enqueuing and
385 dequeuing functions? Such a flag could be screwed up by interrupts
386 at inopportune times. */
389 /* If this flag is a frame, we check mouse_moved to see when the
390 mouse moves, and motion events will appear in the input stream.
391 Otherwise, mouse motion is ignored. */
392 static Lisp_Object do_mouse_tracking
;
394 /* The window system handling code should set this if the mouse has
395 moved since the last call to the mouse_position_hook. Calling that
396 hook should clear this. Code assumes that if this is set, it can
397 call mouse_position_hook to get the promised position, so don't set
398 it unless you're prepared to substantiate the claim! */
400 #endif /* HAVE_MOUSE */
402 /* Symbols to head events. */
403 Lisp_Object Qmouse_movement
;
404 Lisp_Object Qscroll_bar_movement
;
405 Lisp_Object Qswitch_frame
;
406 Lisp_Object Qdelete_frame
;
407 Lisp_Object Qiconify_frame
;
408 Lisp_Object Qmake_frame_visible
;
410 /* Symbols to denote kinds of events. */
411 Lisp_Object Qfunction_key
;
412 Lisp_Object Qmouse_click
;
413 /* Lisp_Object Qmouse_movement; - also an event header */
415 /* Properties of event headers. */
416 Lisp_Object Qevent_kind
;
417 Lisp_Object Qevent_symbol_elements
;
419 Lisp_Object Qmenu_enable
;
421 /* An event header symbol HEAD may have a property named
422 Qevent_symbol_element_mask, which is of the form (BASE MODIFIERS);
423 BASE is the base, unmodified version of HEAD, and MODIFIERS is the
424 mask of modifiers applied to it. If present, this is used to help
425 speed up parse_modifiers. */
426 Lisp_Object Qevent_symbol_element_mask
;
428 /* An unmodified event header BASE may have a property named
429 Qmodifier_cache, which is an alist mapping modifier masks onto
430 modified versions of BASE. If present, this helps speed up
432 Lisp_Object Qmodifier_cache
;
434 /* Symbols to use for parts of windows. */
435 Lisp_Object Qmode_line
;
436 Lisp_Object Qvertical_line
;
437 Lisp_Object Qvertical_scroll_bar
;
438 Lisp_Object Qmenu_bar
;
440 extern Lisp_Object Qmenu_enable
;
442 Lisp_Object
recursive_edit_unwind (), command_loop ();
443 Lisp_Object
Fthis_command_keys ();
444 Lisp_Object Qextended_command_history
;
446 Lisp_Object Qpolling_period
;
448 extern Lisp_Object Vprint_level
, Vprint_length
;
450 /* Address (if not 0) of EMACS_TIME to zero out if a SIGIO interrupt
452 EMACS_TIME
*input_available_clear_time
;
454 /* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
455 Default is 1 if INTERRUPT_INPUT is defined. */
458 /* Nonzero while interrupts are temporarily deferred during redisplay. */
459 int interrupts_deferred
;
461 /* nonzero means use ^S/^Q for flow control. */
464 /* Allow m- file to inhibit use of FIONREAD. */
465 #ifdef BROKEN_FIONREAD
469 /* We are unable to use interrupts if FIONREAD is not available,
470 so flush SIGIO so we won't try. */
477 /* If we support X Windows, turn on the code to poll periodically
478 to detect C-g. It isn't actually used when doing interrupt input. */
479 #ifdef HAVE_X_WINDOWS
480 #define POLL_FOR_INPUT
483 /* Global variable declarations. */
485 /* Function for init_keyboard to call with no args (if nonzero). */
486 void (*keyboard_init_hook
) ();
488 static int read_avail_input ();
489 static void get_input_pending ();
490 static int readable_events ();
491 static Lisp_Object
read_char_x_menu_prompt ();
492 static Lisp_Object
read_char_minibuf_menu_prompt ();
493 static Lisp_Object
make_lispy_event ();
495 static Lisp_Object
make_lispy_movement ();
497 static Lisp_Object
modify_event_symbol ();
498 static Lisp_Object
make_lispy_switch_frame ();
499 static int parse_solitary_modifier ();
501 /* > 0 if we are to echo keystrokes. */
502 static int echo_keystrokes
;
504 /* Nonzero means don't try to suspend even if the operating system seems
506 static int cannot_suspend
;
508 #define min(a,b) ((a)<(b)?(a):(b))
509 #define max(a,b) ((a)>(b)?(a):(b))
511 /* Install the string STR as the beginning of the string of echoing,
512 so that it serves as a prompt for the next character.
513 Also start echoing. */
518 int len
= strlen (str
);
520 if (len
> ECHOBUFSIZE
- 4)
521 len
= ECHOBUFSIZE
- 4;
522 bcopy (str
, current_kboard
->echobuf
, len
);
523 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
524 *current_kboard
->echoptr
= '\0';
526 current_kboard
->echo_after_prompt
= len
;
531 /* Add C to the echo string, if echoing is going on.
532 C can be a character, which is printed prettily ("M-C-x" and all that
533 jazz), or a symbol, whose name is printed. */
538 extern char *push_key_description ();
540 if (current_kboard
->immediate_echo
)
542 char *ptr
= current_kboard
->echoptr
;
544 if (ptr
!= current_kboard
->echobuf
)
547 /* If someone has passed us a composite event, use its head symbol. */
552 if (ptr
- current_kboard
->echobuf
> ECHOBUFSIZE
- 6)
555 ptr
= push_key_description (XINT (c
), ptr
);
557 else if (SYMBOLP (c
))
559 struct Lisp_String
*name
= XSYMBOL (c
)->name
;
560 if ((ptr
- current_kboard
->echobuf
) + name
->size
+ 4 > ECHOBUFSIZE
)
562 bcopy (name
->data
, ptr
, name
->size
);
566 if (current_kboard
->echoptr
== current_kboard
->echobuf
567 && EQ (c
, Vhelp_char
))
569 strcpy (ptr
, " (Type ? for further options)");
574 current_kboard
->echoptr
= ptr
;
580 /* Temporarily add a dash to the end of the echo string if it's not
581 empty, so that it serves as a mini-prompt for the very next character. */
585 if (!current_kboard
->immediate_echo
586 && current_kboard
->echoptr
== current_kboard
->echobuf
)
588 /* Do nothing if we just printed a prompt. */
589 if (current_kboard
->echo_after_prompt
590 == current_kboard
->echoptr
- current_kboard
->echobuf
)
592 /* Do nothing if not echoing at all. */
593 if (current_kboard
->echoptr
== 0)
596 /* Put a dash at the end of the buffer temporarily,
597 but make it go away when the next character is added. */
598 current_kboard
->echoptr
[0] = '-';
599 current_kboard
->echoptr
[1] = 0;
604 /* Display the current echo string, and begin echoing if not already
609 if (!current_kboard
->immediate_echo
)
612 current_kboard
->immediate_echo
= 1;
614 for (i
= 0; i
< this_command_key_count
; i
++)
617 c
= XVECTOR (this_command_keys
)->contents
[i
];
618 if (! (EVENT_HAS_PARAMETERS (c
)
619 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
626 message1_nolog (current_kboard
->echobuf
);
629 if (waiting_for_input
&& !NILP (Vquit_flag
))
630 quit_throw_to_read_char ();
633 /* Turn off echoing, for the start of a new command. */
637 current_kboard
->immediate_echo
= 0;
638 current_kboard
->echoptr
= current_kboard
->echobuf
;
639 current_kboard
->echo_after_prompt
= -1;
642 /* Return the length of the current echo string. */
647 return current_kboard
->echoptr
- current_kboard
->echobuf
;
650 /* Truncate the current echo message to its first LEN chars.
651 This and echo_char get used by read_key_sequence when the user
652 switches frames while entering a key sequence. */
658 current_kboard
->echobuf
[len
] = '\0';
659 current_kboard
->echoptr
= current_kboard
->echobuf
+ len
;
660 truncate_echo_area (len
);
664 /* Functions for manipulating this_command_keys. */
666 add_command_key (key
)
669 int size
= XVECTOR (this_command_keys
)->size
;
671 if (this_command_key_count
>= size
)
673 Lisp_Object new_keys
;
675 new_keys
= Fmake_vector (make_number (size
* 2), Qnil
);
676 bcopy (XVECTOR (this_command_keys
)->contents
,
677 XVECTOR (new_keys
)->contents
,
678 size
* sizeof (Lisp_Object
));
680 this_command_keys
= new_keys
;
683 XVECTOR (this_command_keys
)->contents
[this_command_key_count
++] = key
;
689 int count
= specpdl_ptr
- specpdl
;
692 if (command_loop_level
> 0)
694 specbind (Qstandard_output
, Qt
);
695 specbind (Qstandard_input
, Qt
);
698 val
= command_loop ();
700 Fsignal (Qquit
, Qnil
);
702 return unbind_to (count
, Qnil
);
705 /* When an auto-save happens, record the "time", and don't do again soon. */
709 last_auto_save
= num_nonmacro_input_chars
;
712 /* Make an auto save happen as soon as possible at command level. */
714 force_auto_save_soon ()
716 last_auto_save
= - auto_save_interval
- 1;
718 record_asynch_buffer_change ();
721 DEFUN ("recursive-edit", Frecursive_edit
, Srecursive_edit
, 0, 0, "",
722 "Invoke the editor command loop recursively.\n\
723 To get out of the recursive edit, a command can do `(throw 'exit nil)';\n\
724 that tells this function to return.\n\
725 Alternately, `(throw 'exit t)' makes this function signal an error.\n\
726 This function is called by the editor initialization to begin editing.")
729 int count
= specpdl_ptr
- specpdl
;
732 command_loop_level
++;
733 update_mode_lines
= 1;
735 record_unwind_protect (recursive_edit_unwind
,
737 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
741 return unbind_to (count
, Qnil
);
745 recursive_edit_unwind (buffer
)
749 Fset_buffer (buffer
);
751 command_loop_level
--;
752 update_mode_lines
= 1;
760 #if 0 /* Theory: if there's anything in Vunread_command_events,
761 it will right away be read by read_key_sequence,
762 and then if we do switch KBOARDS, it will go into the side
763 queue then. So we don't need to do anything special here -- rms. */
764 if (CONSP (Vunread_command_events
))
766 current_kboard
->kbd_queue
767 = nconc2 (Vunread_command_events
, current_kboard
->kbd_queue
);
768 current_kboard
->kbd_queue_has_data
= 1;
770 Vunread_command_events
= Qnil
;
776 /* Switch to the single-kboard state, making current_kboard
777 the only KBOARD from which further input is accepted. */
780 single_kboard_state ()
787 /* Maintain a stack of kboards, so other parts of Emacs
788 can switch temporarily to the kboard of a given frame
789 and then revert to the previous status. */
794 struct kboard_stack
*next
;
797 static struct kboard_stack
*kboard_stack
;
800 push_frame_kboard (f
)
804 struct kboard_stack
*p
805 = (struct kboard_stack
*) xmalloc (sizeof (struct kboard_stack
));
807 p
->next
= kboard_stack
;
808 p
->kboard
= current_kboard
;
811 current_kboard
= FRAME_KBOARD (f
);
819 struct kboard_stack
*p
= kboard_stack
;
820 current_kboard
= p
->kboard
;
821 kboard_stack
= p
->next
;
826 /* Handle errors that are not handled at inner levels
827 by printing an error message and returning to the editor command loop. */
833 Lisp_Object old_level
, old_length
;
835 Vstandard_output
= Qt
;
836 Vstandard_input
= Qt
;
837 Vexecuting_macro
= Qnil
;
841 /* Avoid unquittable loop if data contains a circular list. */
842 old_level
= Vprint_level
;
843 old_length
= Vprint_length
;
844 XSETFASTINT(Vprint_level
, 10);
845 XSETFASTINT(Vprint_length
, 10);
846 cmd_error_internal (data
, 0);
847 Vprint_level
= old_level
;
848 Vprint_length
= old_length
;
852 Vinhibit_quit
= Qnil
;
857 return make_number (0);
860 cmd_error_internal (data
, context
)
864 Lisp_Object errmsg
, tail
, errname
, file_error
;
871 echo_area_glyphs
= 0;
873 /* If the window system or terminal frame hasn't been initialized
874 yet, or we're not interactive, it's best to dump this message out
875 to stderr and exit. */
876 if (! FRAME_MESSAGE_BUF (selected_frame
)
878 stream
= Qexternal_debugging_output
;
887 write_string_1 (context
, -1, stream
);
889 errname
= Fcar (data
);
891 if (EQ (errname
, Qerror
))
894 if (!CONSP (data
)) data
= Qnil
;
895 errmsg
= Fcar (data
);
900 errmsg
= Fget (errname
, Qerror_message
);
901 file_error
= Fmemq (Qfile_error
,
902 Fget (errname
, Qerror_conditions
));
905 /* Print an error message including the data items.
906 This is done by printing it into a scratch buffer
907 and then making a copy of the text in the buffer. */
909 if (!CONSP (data
)) data
= Qnil
;
913 /* For file-error, make error message by concatenating
914 all the data items. They are all strings. */
915 if (!NILP (file_error
) && !NILP (tail
))
916 errmsg
= XCONS (tail
)->car
, tail
= XCONS (tail
)->cdr
;
918 if (STRINGP (errmsg
))
919 Fprinc (errmsg
, stream
);
921 write_string_1 ("peculiar error", -1, stream
);
923 for (i
= 0; CONSP (tail
); tail
= Fcdr (tail
), i
++)
925 write_string_1 (i
? ", " : ": ", 2, stream
);
926 if (!NILP (file_error
))
927 Fprinc (Fcar (tail
), stream
);
929 Fprin1 (Fcar (tail
), stream
);
933 /* If the window system or terminal frame hasn't been initialized
934 yet, or we're in -batch mode, this error should cause Emacs to exit. */
935 if (! FRAME_MESSAGE_BUF (selected_frame
)
939 Fkill_emacs (make_number (-1));
943 Lisp_Object
command_loop_1 ();
944 Lisp_Object
command_loop_2 ();
945 Lisp_Object
top_level_1 ();
947 /* Entry to editor-command-loop.
948 This level has the catches for exiting/returning to editor command loop.
949 It returns nil to exit recursive edit, t to abort it. */
954 if (command_loop_level
> 0 || minibuf_level
> 0)
956 return internal_catch (Qexit
, command_loop_2
, Qnil
);
961 internal_catch (Qtop_level
, top_level_1
, Qnil
);
962 internal_catch (Qtop_level
, command_loop_2
, Qnil
);
964 /* End of file in -batch run causes exit here. */
970 /* Here we catch errors in execution of commands within the
971 editing loop, and reenter the editing loop.
972 When there is an error, cmd_error runs and returns a non-nil
973 value to us. A value of nil means that cmd_loop_1 itself
974 returned due to end of file (or end of kbd macro). */
979 register Lisp_Object val
;
982 val
= internal_condition_case (command_loop_1
, Qerror
, cmd_error
);
991 return Feval (Vtop_level
);
997 /* On entry to the outer level, run the startup file */
998 if (!NILP (Vtop_level
))
999 internal_condition_case (top_level_2
, Qerror
, cmd_error
);
1000 else if (!NILP (Vpurify_flag
))
1001 message ("Bare impure Emacs (standard Lisp code not loaded)");
1003 message ("Bare Emacs (standard Lisp code not loaded)");
1007 DEFUN ("top-level", Ftop_level
, Stop_level
, 0, 0, "",
1008 "Exit all recursive editing levels.")
1011 Fthrow (Qtop_level
, Qnil
);
1014 DEFUN ("exit-recursive-edit", Fexit_recursive_edit
, Sexit_recursive_edit
, 0, 0, "",
1015 "Exit from the innermost recursive edit or minibuffer.")
1018 if (command_loop_level
> 0 || minibuf_level
> 0)
1019 Fthrow (Qexit
, Qnil
);
1021 error ("No recursive edit is in progress");
1024 DEFUN ("abort-recursive-edit", Fabort_recursive_edit
, Sabort_recursive_edit
, 0, 0, "",
1025 "Abort the command that requested this recursive edit or minibuffer input.")
1028 if (command_loop_level
> 0 || minibuf_level
> 0)
1031 error ("No recursive edit is in progress");
1034 /* This is the actual command reading loop,
1035 sans error-handling encapsulation. */
1037 Lisp_Object
Fcommand_execute ();
1038 static int read_key_sequence ();
1039 static void safe_run_hooks ();
1044 Lisp_Object cmd
, tem
;
1047 Lisp_Object keybuf
[30];
1052 struct buffer
*prev_buffer
;
1054 int was_locked
= single_kboard
;
1057 Vdeactivate_mark
= Qnil
;
1058 waiting_for_input
= 0;
1063 this_command_key_count
= 0;
1065 /* Make sure this hook runs after commands that get errors and
1066 throw to top level. */
1067 /* Note that the value cell will never directly contain nil
1068 if the symbol is a local variable. */
1069 if (!NILP (XSYMBOL (Qpost_command_hook
)->value
) && !NILP (Vrun_hooks
))
1070 safe_run_hooks (Qpost_command_hook
);
1072 if (!NILP (Vdeferred_action_list
))
1073 call0 (Vdeferred_action_function
);
1075 /* Do this after running Vpost_command_hook, for consistency. */
1076 last_command
= this_command
;
1080 /* Make sure the current window's buffer is selected. */
1081 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
1082 set_buffer_internal (XBUFFER (XWINDOW (selected_window
)->buffer
));
1084 /* Display any malloc warning that just came out. Use while because
1085 displaying one warning can cause another. */
1087 while (pending_malloc_warning
)
1088 display_malloc_warning ();
1092 Vdeactivate_mark
= Qnil
;
1094 /* If minibuffer on and echo area in use,
1095 wait 2 sec and redraw minibuffer. */
1097 if (minibuf_level
&& echo_area_glyphs
)
1099 /* Bind inhibit-quit to t so that C-g gets read in
1100 rather than quitting back to the minibuffer. */
1101 int count
= specpdl_ptr
- specpdl
;
1102 specbind (Qinhibit_quit
, Qt
);
1103 Fsit_for (make_number (2), Qnil
, Qnil
);
1104 unbind_to (count
, Qnil
);
1106 echo_area_glyphs
= 0;
1108 if (!NILP (Vquit_flag
))
1111 Vunread_command_events
= Fcons (make_number (quit_char
), Qnil
);
1116 alloca (0); /* Cause a garbage collection now */
1117 /* Since we can free the most stuff here. */
1118 #endif /* C_ALLOCA */
1122 /* Select the frame that the last event came from. Usually,
1123 switch-frame events will take care of this, but if some lisp
1124 code swallows a switch-frame event, we'll fix things up here.
1125 Is this a good idea? */
1126 if (FRAMEP (internal_last_event_frame
)
1127 && XFRAME (internal_last_event_frame
) != selected_frame
)
1128 Fselect_frame (internal_last_event_frame
, Qnil
);
1131 /* If it has changed current-menubar from previous value,
1132 really recompute the menubar from the value. */
1133 if (! NILP (Vlucid_menu_bar_dirty_flag
)
1134 && !NILP (Ffboundp (Qrecompute_lucid_menubar
)))
1135 call0 (Qrecompute_lucid_menubar
);
1137 /* Read next key sequence; i gets its length. */
1138 i
= read_key_sequence (keybuf
, sizeof keybuf
/ sizeof keybuf
[0],
1143 /* Now we have read a key sequence of length I,
1144 or else I is 0 and we found end of file. */
1146 if (i
== 0) /* End of file -- happens only in */
1147 return Qnil
; /* a kbd macro, at the end. */
1148 /* -1 means read_key_sequence got a menu that was rejected.
1149 Just loop around and read another command. */
1153 this_command_key_count
= 0;
1157 last_command_char
= keybuf
[i
- 1];
1159 /* If the previous command tried to force a specific window-start,
1160 forget about that, in case this command moves point far away
1161 from that position. But also throw away beg_unchanged and
1162 end_unchanged information in that case, so that redisplay will
1163 update the whole window properly. */
1164 if (!NILP (XWINDOW (selected_window
)->force_start
))
1166 XWINDOW (selected_window
)->force_start
= Qnil
;
1167 beg_unchanged
= end_unchanged
= 0;
1170 cmd
= read_key_sequence_cmd
;
1171 if (!NILP (Vexecuting_macro
))
1173 if (!NILP (Vquit_flag
))
1175 Vexecuting_macro
= Qt
;
1176 QUIT
; /* Make some noise. */
1177 /* Will return since macro now empty. */
1181 /* Do redisplay processing after this command except in special
1182 cases identified below that set no_redisplay to 1.
1183 (actually, there's currently no way to prevent the redisplay,
1184 and no_redisplay is ignored.
1185 Perhaps someday we will really implement it.) */
1188 prev_buffer
= current_buffer
;
1189 prev_modiff
= MODIFF
;
1190 last_point_position
= PT
;
1191 XSETBUFFER (last_point_position_buffer
, prev_buffer
);
1193 /* If we're building a prefix argument, override minus and digits. */
1194 if (current_kboard
->prefix_partial
&& i
== 1 && NATNUMP (keybuf
[0]))
1196 if (XFASTINT (keybuf
[0]) == '-'
1197 && NILP (current_kboard
->prefix_value
))
1198 cmd
= Qnegative_argument
;
1199 else if (XFASTINT (keybuf
[0]) >= '0' && XFASTINT (keybuf
[0]) <= '9')
1200 cmd
= Qdigit_argument
;
1203 /* Execute the command. */
1206 /* Note that the value cell will never directly contain nil
1207 if the symbol is a local variable. */
1208 if (!NILP (XSYMBOL (Qpre_command_hook
)->value
) && !NILP (Vrun_hooks
))
1209 safe_run_hooks (Qpre_command_hook
);
1211 if (NILP (this_command
))
1213 /* nil means key is undefined. */
1215 current_kboard
->defining_kbd_macro
= Qnil
;
1216 update_mode_lines
= 1;
1217 clear_prefix_arg ();
1221 current_prefix_partial
= current_kboard
->prefix_partial
;
1222 if (current_kboard
->prefix_partial
)
1223 finalize_prefix_arg ();
1225 if (NILP (Vprefix_arg
) && ! no_direct
)
1227 /* Recognize some common commands in common situations and
1228 do them directly. */
1229 if (EQ (this_command
, Qforward_char
) && PT
< ZV
)
1231 struct Lisp_Vector
*dp
1232 = window_display_table (XWINDOW (selected_window
));
1233 lose
= FETCH_CHAR (PT
);
1236 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1237 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1238 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1239 && (lose
>= 0x20 && lose
< 0x7f)))
1240 : (lose
>= 0x20 && lose
< 0x7f))
1241 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1243 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1245 && !windows_or_buffers_changed
1246 && EQ (current_buffer
->selective_display
, Qnil
)
1247 && !detect_input_pending ()
1248 && NILP (Vexecuting_macro
))
1249 no_redisplay
= direct_output_forward_char (1);
1252 else if (EQ (this_command
, Qbackward_char
) && PT
> BEGV
)
1254 struct Lisp_Vector
*dp
1255 = window_display_table (XWINDOW (selected_window
));
1257 lose
= FETCH_CHAR (PT
);
1259 ? (VECTORP (DISP_CHAR_VECTOR (dp
, lose
))
1260 ? XVECTOR (DISP_CHAR_VECTOR (dp
, lose
))->size
== 1
1261 : (NILP (DISP_CHAR_VECTOR (dp
, lose
))
1262 && (lose
>= 0x20 && lose
< 0x7f)))
1263 : (lose
>= 0x20 && lose
< 0x7f))
1264 && (XFASTINT (XWINDOW (selected_window
)->last_modified
)
1266 && (XFASTINT (XWINDOW (selected_window
)->last_point
)
1268 && !windows_or_buffers_changed
1269 && EQ (current_buffer
->selective_display
, Qnil
)
1270 && !detect_input_pending ()
1271 && NILP (Vexecuting_macro
))
1272 no_redisplay
= direct_output_forward_char (-1);
1275 else if (EQ (this_command
, Qself_insert_command
)
1276 /* Try this optimization only on ascii keystrokes. */
1277 && INTEGERP (last_command_char
))
1279 unsigned char c
= XINT (last_command_char
);
1282 if (NILP (Vexecuting_macro
)
1283 && !EQ (minibuf_window
, selected_window
))
1285 if (!nonundocount
|| nonundocount
>= 20)
1292 lose
= ((XFASTINT (XWINDOW (selected_window
)->last_modified
)
1294 || (XFASTINT (XWINDOW (selected_window
)->last_point
)
1296 || MODIFF
<= SAVE_MODIFF
1297 || windows_or_buffers_changed
1298 || !EQ (current_buffer
->selective_display
, Qnil
)
1299 || detect_input_pending ()
1300 || !NILP (Vexecuting_macro
));
1301 value
= internal_self_insert (c
, 0);
1308 && (PT
== ZV
|| FETCH_CHAR (PT
) == '\n'))
1310 struct Lisp_Vector
*dp
1311 = window_display_table (XWINDOW (selected_window
));
1318 obj
= DISP_CHAR_VECTOR (dp
, lose
);
1321 /* Do it only for char codes
1322 that by default display as themselves. */
1323 if (lose
>= 0x20 && lose
<= 0x7e)
1324 no_redisplay
= direct_output_for_insert (lose
);
1326 else if (VECTORP (obj
)
1327 && XVECTOR (obj
)->size
== 1
1328 && (obj
= XVECTOR (obj
)->contents
[0],
1330 /* Insist face not specified in glyph. */
1331 && (XINT (obj
) & ((-1) << 8)) == 0)
1333 = direct_output_for_insert (XINT (obj
));
1337 if (lose
>= 0x20 && lose
<= 0x7e)
1338 no_redisplay
= direct_output_for_insert (lose
);
1345 /* Here for a command that isn't executed directly */
1348 if (NILP (Vprefix_arg
))
1350 Fcommand_execute (this_command
, Qnil
);
1355 /* Note that the value cell will never directly contain nil
1356 if the symbol is a local variable. */
1357 if (!NILP (XSYMBOL (Qpost_command_hook
)->value
) && !NILP (Vrun_hooks
))
1358 safe_run_hooks (Qpost_command_hook
);
1360 if (!NILP (Vdeferred_action_list
))
1361 safe_run_hooks (Qdeferred_action_function
);
1363 /* If there is a prefix argument,
1364 1) We don't want last_command to be ``universal-argument''
1365 (that would be dumb), so don't set last_command,
1366 2) we want to leave echoing on so that the prefix will be
1367 echoed as part of this key sequence, so don't call
1369 3) we want to leave this_command_key_count non-zero, so that
1370 read_char will realize that it is re-reading a character, and
1371 not echo it a second time. */
1372 if (NILP (Vprefix_arg
) && !current_kboard
->prefix_partial
)
1374 last_command
= this_command
;
1376 this_command_key_count
= 0;
1379 if (!NILP (current_buffer
->mark_active
) && !NILP (Vrun_hooks
))
1381 if (!NILP (Vdeactivate_mark
) && !NILP (Vtransient_mark_mode
))
1383 current_buffer
->mark_active
= Qnil
;
1384 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
1386 else if (current_buffer
!= prev_buffer
|| MODIFF
!= prev_modiff
)
1387 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
1391 /* Install chars successfully executed in kbd macro. */
1393 if (!NILP (current_kboard
->defining_kbd_macro
) && NILP (Vprefix_arg
)
1394 && !current_kboard
->prefix_partial
)
1395 finalize_kbd_macro_chars ();
1399 any_kboard_state ();
1404 /* Subroutine for safe_run_hooks: run the hook HOOK. */
1407 safe_run_hooks_1 (hook
)
1410 return call1 (Vrun_hooks
, Vinhibit_quit
);
1413 /* Subroutine for safe_run_hooks: handle an error by clearing out the hook. */
1416 safe_run_hooks_error (data
)
1419 Fset (Vinhibit_quit
, Qnil
);
1422 /* If we get an error while running the hook, cause the hook variable
1423 to be nil. Also inhibit quits, so that C-g won't cause the hook
1424 to mysteriously evaporate. */
1427 safe_run_hooks (hook
)
1431 int count
= specpdl_ptr
- specpdl
;
1432 specbind (Qinhibit_quit
, hook
);
1434 internal_condition_case (safe_run_hooks_1
, Qerror
, safe_run_hooks_error
);
1436 unbind_to (count
, Qnil
);
1439 /* Number of seconds between polling for input. */
1442 /* Nonzero means polling for input is temporarily suppressed. */
1443 int poll_suppress_count
;
1445 /* Nonzero if polling_for_input is actually being used. */
1446 int polling_for_input
;
1448 #ifdef POLL_FOR_INPUT
1450 /* Handle an alarm once each second and read pending input
1451 so as to handle a C-g if it comces in. */
1454 input_poll_signal (signalnum
) /* If we don't have an argument, */
1455 int signalnum
; /* some compilers complain in signal calls. */
1457 if (interrupt_input_blocked
== 0
1458 && !waiting_for_input
)
1459 read_avail_input (0);
1460 signal (SIGALRM
, input_poll_signal
);
1461 alarm (polling_period
);
1466 /* Begin signals to poll for input, if they are appropriate.
1467 This function is called unconditionally from various places. */
1471 #ifdef POLL_FOR_INPUT
1472 if (read_socket_hook
&& !interrupt_input
)
1474 poll_suppress_count
--;
1475 if (poll_suppress_count
== 0)
1477 signal (SIGALRM
, input_poll_signal
);
1478 polling_for_input
= 1;
1479 alarm (polling_period
);
1485 /* Nonzero if we are using polling to handle input asynchronously. */
1488 input_polling_used ()
1490 #ifdef POLL_FOR_INPUT
1491 return read_socket_hook
&& !interrupt_input
;
1497 /* Turn off polling. */
1501 #ifdef POLL_FOR_INPUT
1502 if (read_socket_hook
&& !interrupt_input
)
1504 if (poll_suppress_count
== 0)
1506 polling_for_input
= 0;
1509 poll_suppress_count
++;
1514 /* Set the value of poll_suppress_count to COUNT
1515 and start or stop polling accordingly. */
1518 set_poll_suppress_count (count
)
1521 #ifdef POLL_FOR_INPUT
1522 if (count
== 0 && poll_suppress_count
!= 0)
1524 poll_suppress_count
= 1;
1527 else if (count
!= 0 && poll_suppress_count
== 0)
1531 poll_suppress_count
= count
;
1535 /* Bind polling_period to a value at least N.
1536 But don't decrease it. */
1538 bind_polling_period (n
)
1541 #ifdef POLL_FOR_INPUT
1542 int new = polling_period
;
1548 specbind (Qpolling_period
, make_number (new));
1549 /* Start a new alarm with the new period. */
1554 /* Apply the control modifier to CHARACTER. */
1560 /* Save the upper bits here. */
1561 int upper
= c
& ~0177;
1565 /* Everything in the columns containing the upper-case letters
1566 denotes a control character. */
1567 if (c
>= 0100 && c
< 0140)
1571 /* Set the shift modifier for a control char
1572 made from a shifted letter. But only for letters! */
1573 if (oc
>= 'A' && oc
<= 'Z')
1574 c
|= shift_modifier
;
1577 /* The lower-case letters denote control characters too. */
1578 else if (c
>= 'a' && c
<= 'z')
1581 /* Include the bits for control and shift
1582 only if the basic ASCII code can't indicate them. */
1586 /* Replace the high bits. */
1587 c
|= (upper
& ~ctrl_modifier
);
1594 /* Input of single characters from keyboard */
1596 Lisp_Object
print_help ();
1597 static Lisp_Object
kbd_buffer_get_event ();
1598 static void record_char ();
1601 static jmp_buf wrong_kboard_jmpbuf
;
1604 /* read a character from the keyboard; call the redisplay if needed */
1605 /* commandflag 0 means do not do auto-saving, but do do redisplay.
1606 -1 means do not do redisplay, but do do autosaving.
1609 /* The arguments MAPS and NMAPS are for menu prompting.
1610 MAPS is an array of keymaps; NMAPS is the length of MAPS.
1612 PREV_EVENT is the previous input event, or nil if we are reading
1613 the first event of a key sequence.
1615 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
1616 if we used a mouse menu to read the input, or zero otherwise. If
1617 USED_MOUSE_MENU is null, we don't dereference it.
1619 Value is t if we showed a menu and the user rejected it. */
1622 read_char (commandflag
, nmaps
, maps
, prev_event
, used_mouse_menu
)
1626 Lisp_Object prev_event
;
1627 int *used_mouse_menu
;
1629 register Lisp_Object c
;
1631 jmp_buf local_getcjmp
;
1633 int key_already_recorded
= 0;
1634 Lisp_Object also_record
;
1637 if (CONSP (Vunread_command_events
))
1639 c
= XCONS (Vunread_command_events
)->car
;
1640 Vunread_command_events
= XCONS (Vunread_command_events
)->cdr
;
1642 if (this_command_key_count
== 0)
1648 if (unread_command_char
!= -1)
1650 XSETINT (c
, unread_command_char
);
1651 unread_command_char
= -1;
1653 if (this_command_key_count
== 0)
1659 if (!NILP (Vexecuting_macro
))
1662 /* We set this to Qmacro; since that's not a frame, nobody will
1663 try to switch frames on us, and the selected window will
1666 Since this event came from a macro, it would be misleading to
1667 leave internal_last_event_frame set to wherever the last
1668 real event came from. Normally, a switch-frame event selects
1669 internal_last_event_frame after each command is read, but
1670 events read from a macro should never cause a new frame to be
1672 Vlast_event_frame
= internal_last_event_frame
= Qmacro
;
1675 /* Exit the macro if we are at the end.
1676 Also, some things replace the macro with t
1677 to force an early exit. */
1678 if (EQ (Vexecuting_macro
, Qt
)
1679 || executing_macro_index
>= XFASTINT (Flength (Vexecuting_macro
)))
1685 c
= Faref (Vexecuting_macro
, make_number (executing_macro_index
));
1686 if (STRINGP (Vexecuting_macro
)
1687 && (XINT (c
) & 0x80))
1688 XSETFASTINT (c
, CHAR_META
| (XINT (c
) & ~0x80));
1690 executing_macro_index
++;
1695 if (!NILP (unread_switch_frame
))
1697 c
= unread_switch_frame
;
1698 unread_switch_frame
= Qnil
;
1700 /* This event should make it into this_command_keys, and get echoed
1701 again, so we go to reread_first, rather than reread. */
1705 if (commandflag
>= 0 && !input_pending
&& !detect_input_pending ())
1708 /* Message turns off echoing unless more keystrokes turn it on again. */
1709 if (echo_area_glyphs
&& *echo_area_glyphs
1710 && echo_area_glyphs
!= current_kboard
->echobuf
)
1713 /* If already echoing, continue. */
1716 /* Try reading a character via menu prompting in the minibuf.
1717 Try this before the sit-for, because the sit-for
1718 would do the wrong thing if we are supposed to do
1719 menu prompting. If EVENT_HAS_PARAMETERS then we are reading
1720 after a mouse event so don't try a minibuf menu. */
1722 if (nmaps
> 0 && INTERACTIVE
1723 && !NILP (prev_event
) && ! EVENT_HAS_PARAMETERS (prev_event
)
1724 /* Don't bring up a menu if we already have another event. */
1725 && NILP (Vunread_command_events
)
1726 && unread_command_char
< 0
1727 && !detect_input_pending ())
1729 c
= read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
);
1732 key_already_recorded
= 1;
1737 /* Make a longjmp point for quits to use, but don't alter getcjmp just yet.
1738 We will do that below, temporarily for short sections of code,
1739 when appropriate. local_getcjmp must be in effect
1740 around any call to sit_for or kbd_buffer_get_event;
1741 it *must not* be in effect when we call redisplay. */
1743 if (_setjmp (local_getcjmp
))
1745 XSETINT (c
, quit_char
);
1747 XSETFRAME (internal_last_event_frame
, selected_frame
);
1748 Vlast_event_frame
= internal_last_event_frame
;
1750 /* If we report the quit char as an event,
1751 don't do so more than once. */
1752 if (!NILP (Vinhibit_quit
))
1757 KBOARD
*kb
= FRAME_KBOARD (selected_frame
);
1758 if (kb
!= current_kboard
)
1760 Lisp_Object
*tailp
= &kb
->kbd_queue
;
1761 /* We shouldn't get here if we were in single-kboard mode! */
1764 while (CONSP (*tailp
))
1765 tailp
= &XCONS (*tailp
)->cdr
;
1768 *tailp
= Fcons (c
, Qnil
);
1769 kb
->kbd_queue_has_data
= 1;
1770 current_kboard
= kb
;
1771 longjmp (wrong_kboard_jmpbuf
, 1);
1778 /* If in middle of key sequence and minibuffer not active,
1779 start echoing if enough time elapses. */
1781 if (minibuf_level
== 0 && !current_kboard
->immediate_echo
1782 && this_command_key_count
> 0
1784 && echo_keystrokes
> 0
1785 && (echo_area_glyphs
== 0 || *echo_area_glyphs
== 0))
1789 /* After a mouse event, start echoing right away.
1790 This is because we are probably about to display a menu,
1791 and we don't want to delay before doing so. */
1792 if (EVENT_HAS_PARAMETERS (prev_event
))
1796 save_getcjmp (save_jump
);
1797 restore_getcjmp (local_getcjmp
);
1798 tem0
= sit_for (echo_keystrokes
, 0, 1, 1);
1799 restore_getcjmp (save_jump
);
1805 /* Maybe auto save due to number of keystrokes. */
1807 if (commandflag
!= 0
1808 && auto_save_interval
> 0
1809 && num_nonmacro_input_chars
- last_auto_save
> max (auto_save_interval
, 20)
1810 && !detect_input_pending ())
1812 Fdo_auto_save (Qnil
, Qnil
);
1813 /* Hooks can actually change some buffers in auto save. */
1817 /* Try reading using an X menu.
1818 This is never confused with reading using the minibuf
1819 because the recursive call of read_char in read_char_minibuf_menu_prompt
1820 does not pass on any keymaps. */
1822 if (nmaps
> 0 && INTERACTIVE
1823 && !NILP (prev_event
)
1824 && EVENT_HAS_PARAMETERS (prev_event
)
1825 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
)
1826 /* Don't bring up a menu if we already have another event. */
1827 && NILP (Vunread_command_events
)
1828 && unread_command_char
< 0)
1829 c
= read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
);
1831 /* Maybe autosave and/or garbage collect due to idleness. */
1833 if (INTERACTIVE
&& NILP (c
))
1835 int delay_level
, buffer_size
;
1837 /* Slow down auto saves logarithmically in size of current buffer,
1838 and garbage collect while we're at it. */
1839 if (! MINI_WINDOW_P (XWINDOW (selected_window
)))
1840 last_non_minibuf_size
= Z
- BEG
;
1841 buffer_size
= (last_non_minibuf_size
>> 8) + 1;
1843 while (buffer_size
> 64)
1844 delay_level
++, buffer_size
-= buffer_size
>> 2;
1845 if (delay_level
< 4) delay_level
= 4;
1846 /* delay_level is 4 for files under around 50k, 7 at 100k,
1847 9 at 200k, 11 at 300k, and 12 at 500k. It is 15 at 1 meg. */
1849 /* Auto save if enough time goes by without input. */
1850 if (commandflag
!= 0
1851 && num_nonmacro_input_chars
> last_auto_save
1852 && INTEGERP (Vauto_save_timeout
)
1853 && XINT (Vauto_save_timeout
) > 0)
1856 int delay
= delay_level
* XFASTINT (Vauto_save_timeout
) / 4;
1858 save_getcjmp (save_jump
);
1859 restore_getcjmp (local_getcjmp
);
1860 tem0
= sit_for (delay
, 0, 1, 1);
1861 restore_getcjmp (save_jump
);
1865 Fdo_auto_save (Qnil
, Qnil
);
1867 /* If we have auto-saved and there is still no input
1868 available, garbage collect if there has been enough
1869 consing going on to make it worthwhile. */
1870 if (!detect_input_pending ()
1871 && consing_since_gc
> gc_cons_threshold
/ 2)
1872 Fgarbage_collect ();
1879 /* Read something from current KBOARD's side queue, if possible. */
1883 if (current_kboard
->kbd_queue_has_data
)
1885 if (!CONSP (current_kboard
->kbd_queue
))
1887 c
= XCONS (current_kboard
->kbd_queue
)->car
;
1888 current_kboard
->kbd_queue
1889 = XCONS (current_kboard
->kbd_queue
)->cdr
;
1890 if (NILP (current_kboard
->kbd_queue
))
1891 current_kboard
->kbd_queue_has_data
= 0;
1892 input_pending
= readable_events ();
1894 if (EVENT_HAS_PARAMETERS (c
)
1895 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qswitch_frame
))
1896 internal_last_event_frame
= XCONS (XCONS (c
)->cdr
)->car
;
1897 Vlast_event_frame
= internal_last_event_frame
;
1903 /* If current_kboard's side queue is empty check the other kboards.
1904 If one of them has data that we have not yet seen here,
1905 switch to it and process the data waiting for it.
1907 Note: if the events queued up for another kboard
1908 have already been seen here, and therefore are not a complete command,
1909 the kbd_queue_has_data field is 0, so we skip that kboard here.
1910 That's to avoid an infinite loop switching between kboards here. */
1911 if (NILP (c
) && !single_kboard
)
1914 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
1915 if (kb
->kbd_queue_has_data
)
1917 current_kboard
= kb
;
1918 longjmp (wrong_kboard_jmpbuf
, 1);
1927 /* Finally, we read from the main queue,
1928 and if that gives us something we can't use yet, we put it on the
1929 appropriate side queue and try again. */
1935 /* Actually read a character, waiting if necessary. */
1936 save_getcjmp (save_jump
);
1937 restore_getcjmp (local_getcjmp
);
1938 c
= kbd_buffer_get_event (&kb
, used_mouse_menu
);
1939 restore_getcjmp (save_jump
);
1942 if (! NILP (c
) && (kb
!= current_kboard
))
1944 Lisp_Object
*tailp
= &kb
->kbd_queue
;
1945 while (CONSP (*tailp
))
1946 tailp
= &XCONS (*tailp
)->cdr
;
1949 *tailp
= Fcons (c
, Qnil
);
1950 kb
->kbd_queue_has_data
= 1;
1953 current_kboard
= kb
;
1954 longjmp (wrong_kboard_jmpbuf
, 1);
1959 /* Terminate Emacs in batch mode if at eof. */
1960 if (noninteractive
&& INTEGERP (c
) && XINT (c
) < 0)
1961 Fkill_emacs (make_number (1));
1965 /* Add in any extra modifiers, where appropriate. */
1966 if ((extra_keyboard_modifiers
& CHAR_CTL
)
1967 || ((extra_keyboard_modifiers
& 0177) < ' '
1968 && (extra_keyboard_modifiers
& 0177) != 0))
1969 XSETINT (c
, make_ctrl_char (XINT (c
)));
1971 /* Transfer any other modifier bits directly from
1972 extra_keyboard_modifiers to c. Ignore the actual character code
1973 in the low 16 bits of extra_keyboard_modifiers. */
1974 XSETINT (c
, XINT (c
) | (extra_keyboard_modifiers
& ~0xff7f & ~CHAR_CTL
));
1983 if (commandflag
>= 0
1984 && !input_pending
&& !detect_input_pending ())
1992 /* Buffer switch events are only for internal wakeups
1993 so don't show them to the user. */
1997 if (key_already_recorded
)
2000 /* Wipe the echo area. */
2001 echo_area_glyphs
= 0;
2003 /* Handle things that only apply to characters. */
2006 /* If kbd_buffer_get_event gave us an EOF, return that. */
2010 if (STRINGP (Vkeyboard_translate_table
)
2011 && XSTRING (Vkeyboard_translate_table
)->size
> XFASTINT (c
))
2012 XSETINT (c
, XSTRING (Vkeyboard_translate_table
)->data
[XFASTINT (c
)]);
2015 /* If this event is a mouse click in the menu bar,
2016 return just menu-bar for now. Modify the mouse click event
2017 so we won't do this twice, then queue it up. */
2018 if (EVENT_HAS_PARAMETERS (c
)
2019 && CONSP (XCONS (c
)->cdr
)
2020 && CONSP (EVENT_START (c
))
2021 && CONSP (XCONS (EVENT_START (c
))->cdr
))
2025 posn
= POSN_BUFFER_POSN (EVENT_START (c
));
2026 /* Handle menu-bar events:
2027 insert the dummy prefix event `menu-bar'. */
2028 if (EQ (posn
, Qmenu_bar
))
2030 /* Change menu-bar to (menu-bar) as the event "position". */
2031 POSN_BUFFER_POSN (EVENT_START (c
)) = Fcons (posn
, Qnil
);
2034 Vunread_command_events
= Fcons (c
, Vunread_command_events
);
2040 if (! NILP (also_record
))
2041 record_char (also_record
);
2046 /* Don't echo mouse motion events. */
2048 && ! (EVENT_HAS_PARAMETERS (c
)
2049 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (c
)), Qmouse_movement
)))
2052 if (! NILP (also_record
))
2053 echo_char (also_record
);
2056 /* Record this character as part of the current key. */
2057 add_command_key (c
);
2058 if (! NILP (also_record
))
2059 add_command_key (also_record
);
2061 /* Re-reading in the middle of a command */
2063 last_input_char
= c
;
2066 /* Process the help character specially if enabled */
2067 if (EQ (c
, Vhelp_char
) && !NILP (Vhelp_form
))
2070 count
= specpdl_ptr
- specpdl
;
2072 record_unwind_protect (Fset_window_configuration
,
2073 Fcurrent_window_configuration (Qnil
));
2075 tem0
= Feval (Vhelp_form
);
2077 internal_with_output_to_temp_buffer ("*Help*", print_help
, tem0
);
2081 c
= read_char (0, 0, 0, Qnil
, 0);
2082 while (BUFFERP (c
));
2083 /* Remove the help from the frame */
2084 unbind_to (count
, Qnil
);
2087 if (EQ (c
, make_number (040)))
2091 c
= read_char (0, 0, 0, Qnil
, 0);
2092 while (BUFFERP (c
));
2099 /* Record the input event C in various ways. */
2106 XVECTOR (recent_keys
)->contents
[recent_keys_index
] = c
;
2107 if (++recent_keys_index
>= NUM_RECENT_KEYS
)
2108 recent_keys_index
= 0;
2110 /* Write c to the dribble file. If c is a lispy event, write
2111 the event's symbol to the dribble file, in <brackets>. Bleaugh.
2112 If you, dear reader, have a better idea, you've got the source. :-) */
2117 if (XUINT (c
) < 0x100)
2118 putc (XINT (c
), dribble
);
2120 fprintf (dribble
, " 0x%x", XUINT (c
));
2124 Lisp_Object dribblee
;
2126 /* If it's a structured event, take the event header. */
2127 dribblee
= EVENT_HEAD (c
);
2129 if (SYMBOLP (dribblee
))
2131 putc ('<', dribble
);
2132 fwrite (XSYMBOL (dribblee
)->name
->data
, sizeof (char),
2133 XSYMBOL (dribblee
)->name
->size
,
2135 putc ('>', dribble
);
2142 store_kbd_macro_char (c
);
2144 num_nonmacro_input_chars
++;
2151 struct buffer
*old
= current_buffer
;
2152 Fprinc (object
, Qnil
);
2153 set_buffer_internal (XBUFFER (Vstandard_output
));
2154 call0 (intern ("help-mode"));
2155 set_buffer_internal (old
);
2159 /* Copy out or in the info on where C-g should throw to.
2160 This is used when running Lisp code from within get_char,
2161 in case get_char is called recursively.
2162 See read_process_output. */
2167 bcopy (getcjmp
, temp
, sizeof getcjmp
);
2170 restore_getcjmp (temp
)
2173 bcopy (temp
, getcjmp
, sizeof getcjmp
);
2178 /* Restore mouse tracking enablement. See Ftrack_mouse for the only use
2179 of this function. */
2182 tracking_off (old_value
)
2183 Lisp_Object old_value
;
2185 do_mouse_tracking
= old_value
;
2186 if (NILP (old_value
))
2188 /* Redisplay may have been preempted because there was input
2189 available, and it assumes it will be called again after the
2190 input has been processed. If the only input available was
2191 the sort that we have just disabled, then we need to call
2193 if (!readable_events ())
2195 redisplay_preserve_echo_area ();
2196 get_input_pending (&input_pending
);
2201 DEFUN ("track-mouse", Ftrack_mouse
, Strack_mouse
, 0, UNEVALLED
, 0,
2202 "Evaluate BODY with mouse movement events enabled.\n\
2203 Within a `track-mouse' form, mouse motion generates input events that\n\
2204 you can read with `read-event'.\n\
2205 Normally, mouse motion is ignored.")
2209 int count
= specpdl_ptr
- specpdl
;
2212 record_unwind_protect (tracking_off
, do_mouse_tracking
);
2214 XSETFRAME (do_mouse_tracking
, selected_frame
);
2216 val
= Fprogn (args
);
2217 return unbind_to (count
, val
);
2220 #endif /* HAVE_MOUSE */
2222 /* Low level keyboard/mouse input.
2223 kbd_buffer_store_event places events in kbd_buffer, and
2224 kbd_buffer_get_event retrieves them.
2225 mouse_moved indicates when the mouse has moved again, and
2226 *mouse_position_hook provides the mouse position. */
2228 /* Return true iff there are any events in the queue that read-char
2229 would return. If this returns false, a read-char would block. */
2233 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2236 if (FRAMEP (do_mouse_tracking
) && mouse_moved
)
2241 if (current_kboard
->kbd_queue_has_data
)
2247 for (kb
= all_kboards
; kb
; kb
= kb
->next_kboard
)
2248 if (kb
->kbd_queue_has_data
)
2254 /* Set this for debugging, to have a way to get out */
2259 event_to_kboard (event
)
2260 struct input_event
*event
;
2263 frame
= event
->frame_or_window
;
2265 frame
= XCONS (frame
)->car
;
2266 else if (WINDOWP (frame
))
2267 frame
= WINDOW_FRAME (XWINDOW (frame
));
2269 /* There are still some events that don't set this field.
2270 For now, just ignore the problem.
2271 Also ignore dead frames here. */
2272 if (!FRAMEP (frame
) || !FRAME_LIVE_P (XFRAME (frame
)))
2275 return FRAME_KBOARD (XFRAME (frame
));
2279 /* Store an event obtained at interrupt level into kbd_buffer, fifo */
2282 kbd_buffer_store_event (event
)
2283 register struct input_event
*event
;
2285 if (event
->kind
== no_event
)
2288 if (event
->kind
== ascii_keystroke
)
2290 register int c
= event
->code
& 0377;
2292 if (event
->modifiers
& ctrl_modifier
)
2293 c
= make_ctrl_char (c
);
2295 c
|= (event
->modifiers
2296 & (meta_modifier
| alt_modifier
2297 | hyper_modifier
| super_modifier
));
2301 extern SIGTYPE
interrupt_signal ();
2304 struct input_event
*sp
;
2307 && (kb
= FRAME_KBOARD (XFRAME (event
->frame_or_window
)),
2308 kb
!= current_kboard
))
2311 = Fcons (make_lispy_switch_frame (event
->frame_or_window
),
2312 Fcons (make_number (c
), Qnil
));
2313 kb
->kbd_queue_has_data
= 1;
2314 for (sp
= kbd_fetch_ptr
; sp
!= kbd_store_ptr
; sp
++)
2316 if (sp
== kbd_buffer
+ KBD_BUFFER_SIZE
)
2319 if (event_to_kboard (sp
) == kb
)
2321 sp
->kind
= no_event
;
2322 sp
->frame_or_window
= Qnil
;
2330 /* If this results in a quit_char being returned to Emacs as
2331 input, set Vlast_event_frame properly. If this doesn't
2332 get returned to Emacs as an event, the next event read
2333 will set Vlast_event_frame again, so this is safe to do. */
2337 focus
= FRAME_FOCUS_FRAME (XFRAME (event
->frame_or_window
));
2339 focus
= event
->frame_or_window
;
2340 internal_last_event_frame
= focus
;
2341 Vlast_event_frame
= focus
;
2345 last_event_timestamp
= event
->timestamp
;
2346 interrupt_signal ();
2350 if (c
&& c
== stop_character
)
2357 if (kbd_store_ptr
- kbd_buffer
== KBD_BUFFER_SIZE
)
2358 kbd_store_ptr
= kbd_buffer
;
2360 /* Don't let the very last slot in the buffer become full,
2361 since that would make the two pointers equal,
2362 and that is indistinguishable from an empty buffer.
2363 Discard the event if it would fill the last slot. */
2364 if (kbd_fetch_ptr
- 1 != kbd_store_ptr
)
2366 volatile struct input_event
*sp
= kbd_store_ptr
;
2367 sp
->kind
= event
->kind
;
2368 if (event
->kind
== selection_request_event
)
2370 /* We must not use the ordinary copying code for this case,
2371 since `part' is an enum and copying it might not copy enough
2373 bcopy (event
, (char *) sp
, sizeof (*event
));
2377 sp
->code
= event
->code
;
2378 sp
->part
= event
->part
;
2379 sp
->frame_or_window
= event
->frame_or_window
;
2380 sp
->modifiers
= event
->modifiers
;
2383 sp
->timestamp
= event
->timestamp
;
2385 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_store_ptr
2387 = event
->frame_or_window
);
2393 /* Read one event from the event buffer, waiting if necessary.
2394 The value is a Lisp object representing the event.
2395 The value is nil for an event that should be ignored,
2396 or that was handled here.
2397 We always read and discard one event. */
2400 kbd_buffer_get_event (kbp
, used_mouse_menu
)
2402 int *used_mouse_menu
;
2411 *kbp
= current_kboard
;
2415 /* Wait until there is input available. */
2418 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2421 if (FRAMEP (do_mouse_tracking
) && mouse_moved
)
2425 /* If the quit flag is set, then read_char will return
2426 quit_char, so that counts as "available input." */
2427 if (!NILP (Vquit_flag
))
2428 quit_throw_to_read_char ();
2430 /* One way or another, wait until input is available; then, if
2431 interrupt handlers have not read it, read it now. */
2434 wait_for_kbd_input ();
2436 /* Note SIGIO has been undef'd if FIONREAD is missing. */
2440 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2443 if (FRAMEP (do_mouse_tracking
) && mouse_moved
)
2447 Lisp_Object minus_one
;
2449 XSETINT (minus_one
, -1);
2450 wait_reading_process_input (0, 0, minus_one
, 1);
2452 if (!interrupt_input
&& kbd_fetch_ptr
== kbd_store_ptr
)
2453 /* Pass 1 for EXPECT since we just waited to have input. */
2454 read_avail_input (1);
2456 #endif /* not VMS */
2459 /* At this point, we know that there is a readable event available
2460 somewhere. If the event queue is empty, then there must be a
2461 mouse movement enabled and available. */
2462 if (kbd_fetch_ptr
!= kbd_store_ptr
)
2464 struct input_event
*event
;
2466 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2470 last_event_timestamp
= event
->timestamp
;
2473 *kbp
= event_to_kboard (event
);
2475 *kbp
= current_kboard
; /* Better than returning null ptr? */
2477 *kbp
= &the_only_kboard
;
2482 /* These two kinds of events get special handling
2483 and don't actually appear to the command loop.
2484 We return nil for them. */
2485 if (event
->kind
== selection_request_event
)
2488 struct input_event copy
;
2490 /* Remove it from the buffer before processing it,
2491 since otherwise swallow_events will see it
2492 and process it again. */
2494 kbd_fetch_ptr
= event
+ 1;
2495 x_handle_selection_request (©
);
2497 /* We're getting selection request events, but we don't have
2503 else if (event
->kind
== selection_clear_event
)
2506 x_handle_selection_clear (event
);
2507 kbd_fetch_ptr
= event
+ 1;
2509 /* We're getting selection request events, but we don't have
2515 else if (event
->kind
== delete_window_event
)
2517 /* Make an event (delete-frame (FRAME)). */
2518 obj
= Fcons (event
->frame_or_window
, Qnil
);
2519 obj
= Fcons (Qdelete_frame
, Fcons (obj
, Qnil
));
2520 kbd_fetch_ptr
= event
+ 1;
2522 else if (event
->kind
== iconify_event
)
2524 /* Make an event (iconify-frame (FRAME)). */
2525 obj
= Fcons (event
->frame_or_window
, Qnil
);
2526 obj
= Fcons (Qiconify_frame
, Fcons (obj
, Qnil
));
2527 kbd_fetch_ptr
= event
+ 1;
2529 else if (event
->kind
== deiconify_event
)
2531 /* Make an event (make-frame-visible (FRAME)). */
2532 obj
= Fcons (event
->frame_or_window
, Qnil
);
2533 obj
= Fcons (Qmake_frame_visible
, Fcons (obj
, Qnil
));
2534 kbd_fetch_ptr
= event
+ 1;
2537 else if (event
->kind
== buffer_switch_event
)
2539 /* The value doesn't matter here; only the type is tested. */
2540 XSETBUFFER (obj
, current_buffer
);
2541 kbd_fetch_ptr
= event
+ 1;
2543 /* Just discard these, by returning nil.
2544 With MULTI_KBOARD, these events are used as placeholders
2545 when we need to randomly delete events from the queue.
2546 (They shouldn't otherwise be found in the buffer,
2547 but on some machines it appears they do show up
2548 even without MULTI_KBOARD.) */
2549 else if (event
->kind
== no_event
)
2550 kbd_fetch_ptr
= event
+ 1;
2552 /* If this event is on a different frame, return a switch-frame this
2553 time, and leave the event in the queue for next time. */
2560 frame
= event
->frame_or_window
;
2562 frame
= XCONS (frame
)->car
;
2563 else if (WINDOWP (frame
))
2564 frame
= WINDOW_FRAME (XWINDOW (frame
));
2566 focus
= FRAME_FOCUS_FRAME (XFRAME (frame
));
2570 if (! EQ (frame
, internal_last_event_frame
)
2571 && XFRAME (frame
) != selected_frame
)
2572 obj
= make_lispy_switch_frame (frame
);
2573 internal_last_event_frame
= frame
;
2574 #endif /* MULTI_FRAME */
2576 /* If we didn't decide to make a switch-frame event, go ahead
2577 and build a real event from the queue entry. */
2581 obj
= make_lispy_event (event
);
2582 #ifdef USE_X_TOOLKIT
2583 /* If this was a menu selection, then set the flag to inhibit
2584 writing to last_nonmenu_event. Don't do this if the event
2585 we're returning is (menu-bar), though; that indicates the
2586 beginning of the menu sequence, and we might as well leave
2587 that as the `event with parameters' for this selection. */
2588 if (event
->kind
== menu_bar_event
2589 && !(CONSP (obj
) && EQ (XCONS (obj
)->car
, Qmenu_bar
))
2591 *used_mouse_menu
= 1;
2594 /* Wipe out this event, to catch bugs. */
2595 event
->kind
= no_event
;
2596 XVECTOR (kbd_buffer_frame_or_window
)->contents
[event
- kbd_buffer
] = Qnil
;
2598 kbd_fetch_ptr
= event
+ 1;
2603 /* Try generating a mouse motion event. */
2604 else if (FRAMEP (do_mouse_tracking
) && mouse_moved
)
2606 FRAME_PTR f
= XFRAME (do_mouse_tracking
);
2607 Lisp_Object bar_window
;
2608 enum scroll_bar_part part
;
2612 *kbp
= current_kboard
;
2613 /* Note that this uses F to determine which display to look at.
2614 If there is no valid info, it does not store anything
2615 so x remains nil. */
2617 (*mouse_position_hook
) (&f
, 0, &bar_window
, &part
, &x
, &y
, &time
);
2622 /* Decide if we should generate a switch-frame event. Don't
2623 generate switch-frame events for motion outside of all Emacs
2629 frame
= FRAME_FOCUS_FRAME (f
);
2631 XSETFRAME (frame
, f
);
2633 if (! EQ (frame
, internal_last_event_frame
)
2634 && XFRAME (frame
) != selected_frame
)
2635 obj
= make_lispy_switch_frame (frame
);
2636 internal_last_event_frame
= frame
;
2640 /* If we didn't decide to make a switch-frame event, go ahead and
2641 return a mouse-motion event. */
2642 if (!NILP (x
) && NILP (obj
))
2643 obj
= make_lispy_movement (f
, bar_window
, part
, x
, y
, time
);
2645 #endif /* HAVE_MOUSE */
2647 /* We were promised by the above while loop that there was
2648 something for us to read! */
2651 input_pending
= readable_events ();
2654 Vlast_event_frame
= internal_last_event_frame
;
2660 /* Process any events that are not user-visible,
2661 then return, without reading any user-visible events. */
2666 while (kbd_fetch_ptr
!= kbd_store_ptr
)
2668 struct input_event
*event
;
2670 event
= ((kbd_fetch_ptr
< kbd_buffer
+ KBD_BUFFER_SIZE
)
2674 last_event_timestamp
= event
->timestamp
;
2676 /* These two kinds of events get special handling
2677 and don't actually appear to the command loop. */
2678 if (event
->kind
== selection_request_event
)
2681 struct input_event copy
;
2683 kbd_fetch_ptr
= event
+ 1;
2684 x_handle_selection_request (©
);
2686 /* We're getting selection request events, but we don't have
2692 else if (event
->kind
== selection_clear_event
)
2695 x_handle_selection_clear (event
);
2696 kbd_fetch_ptr
= event
+ 1;
2698 /* We're getting selection request events, but we don't have
2707 get_input_pending (&input_pending
);
2710 /* Caches for modify_event_symbol. */
2711 static Lisp_Object accent_key_syms
;
2712 static Lisp_Object system_key_syms
;
2713 static Lisp_Object func_key_syms
;
2714 static Lisp_Object mouse_syms
;
2716 /* This is a list of keysym codes for special "accent" characters.
2717 It parallels lispy_accent_keys. */
2719 static int lispy_accent_codes
[] =
2721 #ifdef XK_dead_circumflex
2726 #ifdef XK_dead_grave
2731 #ifdef XK_dead_tilde
2736 #ifdef XK_dead_diaeresis
2741 #ifdef XK_dead_macron
2746 #ifdef XK_dead_degree
2751 #ifdef XK_dead_acute
2756 #ifdef XK_dead_cedilla
2761 #ifdef XK_dead_breve
2766 #ifdef XK_dead_ogonek
2771 #ifdef XK_dead_caron
2776 #ifdef XK_dead_doubleacute
2777 XK_dead_doubleacute
,
2781 #ifdef XK_dead_abovedot
2788 /* This is a list of Lisp names for special "accent" characters.
2789 It parallels lispy_accent_codes. */
2791 static char *lispy_accent_keys
[] =
2808 /* You'll notice that this table is arranged to be conveniently
2809 indexed by X Windows keysym values. */
2810 static char *lispy_function_keys
[] =
2812 /* X Keysym value */
2814 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00 */
2822 0, 0, 0, /* 0xff10 */
2824 0, 0, 0, 0, 0, 0, 0,
2827 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff20...2f */
2828 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff30...3f */
2829 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff40...4f */
2831 "home", /* 0xff50 */ /* IsCursorKey */
2842 "select", /* 0xff60 */ /* IsMiscFunctionKey */
2853 "break", /* 0xff6b */
2855 0, 0, 0, 0, 0, 0, 0, 0, "backtab", 0,
2857 0, 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff7f */
2858 "kp-space", /* 0xff80 */ /* IsKeypadKey */
2859 0, 0, 0, 0, 0, 0, 0, 0,
2860 "kp-tab", /* 0xff89 */
2862 "kp-enter", /* 0xff8d */
2864 "kp-f1", /* 0xff91 */
2868 "kp-home", /* 0xff95 */
2873 "kp-prior", /* kp-page-up */
2874 "kp-next", /* kp-page-down */
2880 0, 0, 0, 0, 0, 0, 0, 0, 0,
2881 "kp-multiply", /* 0xffaa */
2886 "kp-divide", /* 0xffaf */
2887 "kp-0", /* 0xffb0 */
2888 "kp-1", "kp-2", "kp-3", "kp-4", "kp-5", "kp-6", "kp-7", "kp-8", "kp-9",
2891 "kp-equal", /* 0xffbd */
2892 "f1", /* 0xffbe */ /* IsFunctionKey */
2894 "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", /* 0xffc0 */
2895 "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18",
2896 "f19", "f20", "f21", "f22", "f23", "f24", "f25", "f26", /* 0xffd0 */
2897 "f27", "f28", "f29", "f30", "f31", "f32", "f33", "f34",
2898 "f35", 0, 0, 0, 0, 0, 0, 0, /* 0xffe0 */
2899 0, 0, 0, 0, 0, 0, 0, 0,
2900 0, 0, 0, 0, 0, 0, 0, 0, /* 0xfff0 */
2901 0, 0, 0, 0, 0, 0, 0, "delete"
2904 static char *lispy_mouse_names
[] =
2906 "mouse-1", "mouse-2", "mouse-3", "mouse-4", "mouse-5"
2909 /* Scroll bar parts. */
2910 Lisp_Object Qabove_handle
, Qhandle
, Qbelow_handle
;
2912 /* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */
2913 Lisp_Object
*scroll_bar_parts
[] = {
2914 &Qabove_handle
, &Qhandle
, &Qbelow_handle
2918 /* A vector, indexed by button number, giving the down-going location
2919 of currently depressed buttons, both scroll bar and non-scroll bar.
2921 The elements have the form
2922 (BUTTON-NUMBER MODIFIER-MASK . REST)
2923 where REST is the cdr of a position as it would be reported in the event.
2925 The make_lispy_event function stores positions here to tell the
2926 difference between click and drag events, and to store the starting
2927 location to be included in drag events. */
2929 static Lisp_Object button_down_location
;
2931 /* Information about the most recent up-going button event: Which
2932 button, what location, and what time. */
2934 static int last_mouse_button
;
2935 static int last_mouse_x
;
2936 static int last_mouse_y
;
2937 static unsigned long button_down_time
;
2939 /* The maximum time between clicks to make a double-click,
2940 or Qnil to disable double-click detection,
2941 or Qt for no time limit. */
2942 Lisp_Object Vdouble_click_time
;
2944 /* The number of clicks in this multiple-click. */
2946 int double_click_count
;
2948 /* Given a struct input_event, build the lisp event which represents
2949 it. If EVENT is 0, build a mouse movement event from the mouse
2950 movement buffer, which should have a movement event in it.
2952 Note that events must be passed to this function in the order they
2953 are received; this function stores the location of button presses
2954 in order to build drag events when the button is released. */
2957 make_lispy_event (event
)
2958 struct input_event
*event
;
2962 switch (SWITCH_ENUM_CAST (event
->kind
))
2964 /* A simple keystroke. */
2965 case ascii_keystroke
:
2967 Lisp_Object lispy_c
;
2968 int c
= event
->code
& 0377;
2969 /* Turn ASCII characters into control characters
2971 if (event
->modifiers
& ctrl_modifier
)
2972 c
= make_ctrl_char (c
);
2974 /* Add in the other modifier bits. We took care of ctrl_modifier
2975 just above, and the shift key was taken care of by the X code,
2976 and applied to control characters by make_ctrl_char. */
2977 c
|= (event
->modifiers
2978 & (meta_modifier
| alt_modifier
2979 | hyper_modifier
| super_modifier
));
2980 button_down_time
= 0;
2981 XSETFASTINT (lispy_c
, c
);
2985 /* A function key. The symbol may need to have modifier prefixes
2987 case non_ascii_keystroke
:
2988 button_down_time
= 0;
2990 for (i
= 0; i
< sizeof (lispy_accent_codes
) / sizeof (int); i
++)
2991 if (event
->code
== lispy_accent_codes
[i
])
2992 return modify_event_symbol (i
,
2994 Qfunction_key
, Qnil
,
2995 lispy_accent_keys
, &accent_key_syms
,
2996 (sizeof (lispy_accent_keys
)
2997 / sizeof (lispy_accent_keys
[0])));
2999 /* Handle system-specific keysyms. */
3000 if (event
->code
& (1 << 28))
3002 /* We need to use an alist rather than a vector as the cache
3003 since we can't make a vector long enuf. */
3004 if (NILP (system_key_syms
))
3005 system_key_syms
= Fcons (Qnil
, Qnil
);
3006 return modify_event_symbol (event
->code
& 0xffffff,
3009 current_kboard
->Vsystem_key_alist
,
3010 0, &system_key_syms
, 0xffffff);
3013 return modify_event_symbol (event
->code
- 0xff00,
3015 Qfunction_key
, Qnil
,
3016 lispy_function_keys
, &func_key_syms
,
3017 (sizeof (lispy_function_keys
)
3018 / sizeof (lispy_function_keys
[0])));
3022 /* A mouse click. Figure out where it is, decide whether it's
3023 a press, click or drag, and build the appropriate structure. */
3025 case scroll_bar_click
:
3027 int button
= event
->code
;
3029 Lisp_Object position
;
3030 Lisp_Object
*start_pos_ptr
;
3031 Lisp_Object start_pos
;
3033 if (button
< 0 || button
>= NUM_MOUSE_BUTTONS
)
3036 /* Build the position as appropriate for this mouse click. */
3037 if (event
->kind
== mouse_click
)
3040 FRAME_PTR f
= XFRAME (event
->frame_or_window
);
3045 /* Ignore mouse events that were made on frame that
3046 have been deleted. */
3047 if (! FRAME_LIVE_P (f
))
3050 pixel_to_glyph_coords (f
, XINT (event
->x
), XINT (event
->y
),
3051 &column
, &row
, 0, 1);
3053 #ifndef USE_X_TOOLKIT
3054 /* In the non-toolkit version, clicks on the menu bar
3055 are ordinary button events in the event buffer.
3056 Distinguish them, and invoke the menu.
3058 (In the toolkit version, the toolkit handles the menu bar
3059 and Emacs doesn't know about it until after the user
3060 makes a selection.) */
3061 if (row
>= 0 && row
< FRAME_MENU_BAR_LINES (f
))
3063 Lisp_Object items
, item
;
3067 /* Activate the menu bar on the down event. If the
3068 up event comes in before the menu code can deal with it,
3070 if (! (event
->modifiers
& down_modifier
))
3074 items
= FRAME_MENU_BAR_ITEMS (f
);
3075 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 3)
3077 Lisp_Object pos
, string
;
3078 string
= XVECTOR (items
)->contents
[i
+ 1];
3079 pos
= XVECTOR (items
)->contents
[i
+ 2];
3082 if (column
>= XINT (pos
)
3083 && column
< XINT (pos
) + XSTRING (string
)->size
)
3085 item
= XVECTOR (items
)->contents
[i
];
3091 = Fcons (event
->frame_or_window
,
3093 Fcons (Fcons (event
->x
, event
->y
),
3094 Fcons (make_number (event
->timestamp
),
3097 return Fcons (item
, Fcons (position
, Qnil
));
3099 #endif /* not USE_X_TOOLKIT */
3101 window
= window_from_coordinates (f
, column
, row
, &part
);
3103 if (!WINDOWP (window
))
3105 window
= event
->frame_or_window
;
3110 int pixcolumn
, pixrow
;
3111 column
-= XINT (XWINDOW (window
)->left
);
3112 row
-= XINT (XWINDOW (window
)->top
);
3113 glyph_to_pixel_coords (f
, column
, row
, &pixcolumn
, &pixrow
);
3114 XSETINT (event
->x
, pixcolumn
);
3115 XSETINT (event
->y
, pixrow
);
3120 posn
= Qvertical_line
;
3123 buffer_posn_from_coords (XWINDOW (window
),
3130 Fcons (Fcons (event
->x
, event
->y
),
3131 Fcons (make_number (event
->timestamp
),
3137 Lisp_Object portion_whole
;
3140 window
= event
->frame_or_window
;
3141 portion_whole
= Fcons (event
->x
, event
->y
);
3142 part
= *scroll_bar_parts
[(int) event
->part
];
3146 Fcons (Qvertical_scroll_bar
,
3147 Fcons (portion_whole
,
3148 Fcons (make_number (event
->timestamp
),
3149 Fcons (part
, Qnil
)))));
3152 start_pos_ptr
= &XVECTOR (button_down_location
)->contents
[button
];
3154 start_pos
= *start_pos_ptr
;
3155 *start_pos_ptr
= Qnil
;
3157 is_double
= (button
== last_mouse_button
3158 && XINT (event
->x
) == last_mouse_x
3159 && XINT (event
->y
) == last_mouse_y
3160 && button_down_time
!= 0
3161 && (EQ (Vdouble_click_time
, Qt
)
3162 || (INTEGERP (Vdouble_click_time
)
3163 && ((int)(event
->timestamp
- button_down_time
)
3164 < XINT (Vdouble_click_time
)))));
3165 last_mouse_button
= button
;
3166 last_mouse_x
= XINT (event
->x
);
3167 last_mouse_y
= XINT (event
->y
);
3169 /* If this is a button press, squirrel away the location, so
3170 we can decide later whether it was a click or a drag. */
3171 if (event
->modifiers
& down_modifier
)
3175 double_click_count
++;
3176 event
->modifiers
|= ((double_click_count
> 2)
3181 double_click_count
= 1;
3182 button_down_time
= event
->timestamp
;
3183 *start_pos_ptr
= Fcopy_alist (position
);
3186 /* Now we're releasing a button - check the co-ordinates to
3187 see if this was a click or a drag. */
3188 else if (event
->modifiers
& up_modifier
)
3190 /* If we did not see a down before this up,
3191 ignore the up. Probably this happened because
3192 the down event chose a menu item.
3193 It would be an annoyance to treat the release
3194 of the button that chose the menu item
3195 as a separate event. */
3197 if (!CONSP (start_pos
))
3200 event
->modifiers
&= ~up_modifier
;
3201 #if 0 /* Formerly we treated an up with no down as a click event. */
3202 if (!CONSP (start_pos
))
3203 event
->modifiers
|= click_modifier
;
3207 /* The third element of every position should be the (x,y)
3211 down
= Fnth (make_number (2), start_pos
);
3212 if (EQ (event
->x
, XCONS (down
)->car
)
3213 && EQ (event
->y
, XCONS (down
)->cdr
))
3215 event
->modifiers
|= click_modifier
;
3219 button_down_time
= 0;
3220 event
->modifiers
|= drag_modifier
;
3222 /* Don't check is_double; treat this as multiple
3223 if the down-event was multiple. */
3224 if (double_click_count
> 1)
3225 event
->modifiers
|= ((double_click_count
> 2)
3231 /* Every mouse event should either have the down_modifier or
3232 the up_modifier set. */
3236 /* Get the symbol we should use for the mouse click. */
3239 head
= modify_event_symbol (button
,
3242 lispy_mouse_names
, &mouse_syms
,
3243 (sizeof (lispy_mouse_names
)
3244 / sizeof (lispy_mouse_names
[0])));
3245 if (event
->modifiers
& drag_modifier
)
3250 else if (event
->modifiers
& (double_modifier
| triple_modifier
))
3253 Fcons (make_number (double_click_count
),
3261 #endif /* HAVE_MOUSE */
3263 #ifdef USE_X_TOOLKIT
3264 case menu_bar_event
:
3265 /* The event value is in the cdr of the frame_or_window slot. */
3266 if (!CONSP (event
->frame_or_window
))
3268 return XCONS (event
->frame_or_window
)->cdr
;
3271 /* The 'kind' field of the event is something we don't recognize. */
3280 make_lispy_movement (frame
, bar_window
, part
, x
, y
, time
)
3282 Lisp_Object bar_window
;
3283 enum scroll_bar_part part
;
3288 /* Is it a scroll bar movement? */
3289 if (frame
&& ! NILP (bar_window
))
3291 Lisp_Object part_sym
;
3293 part_sym
= *scroll_bar_parts
[(int) part
];
3294 return Fcons (Qscroll_bar_movement
,
3295 (Fcons (Fcons (bar_window
,
3296 Fcons (Qvertical_scroll_bar
,
3297 Fcons (Fcons (x
, y
),
3298 Fcons (make_number (time
),
3304 /* Or is it an ordinary mouse movement? */
3306 #endif /* MULTI_FRAME */
3319 /* It's in a frame; which window on that frame? */
3320 pixel_to_glyph_coords (frame
, XINT (x
), XINT (y
), &column
, &row
, 0, 1);
3321 window
= window_from_coordinates (frame
, column
, row
, &area
);
3326 if (WINDOWP (window
))
3328 int pixcolumn
, pixrow
;
3329 column
-= XINT (XWINDOW (window
)->left
);
3330 row
-= XINT (XWINDOW (window
)->top
);
3331 glyph_to_pixel_coords (frame
, column
, row
, &pixcolumn
, &pixrow
);
3332 XSETINT (x
, pixcolumn
);
3333 XSETINT (y
, pixrow
);
3338 posn
= Qvertical_line
;
3341 buffer_posn_from_coords (XWINDOW (window
), column
, row
));
3344 else if (frame
!= 0)
3346 XSETFRAME (window
, frame
);
3358 return Fcons (Qmouse_movement
,
3359 Fcons (Fcons (window
,
3361 Fcons (Fcons (x
, y
),
3362 Fcons (make_number (time
),
3368 #endif /* HAVE_MOUSE */
3370 /* Construct a switch frame event. */
3372 make_lispy_switch_frame (frame
)
3375 return Fcons (Qswitch_frame
, Fcons (frame
, Qnil
));
3378 /* Manipulating modifiers. */
3380 /* Parse the name of SYMBOL, and return the set of modifiers it contains.
3382 If MODIFIER_END is non-zero, set *MODIFIER_END to the position in
3383 SYMBOL's name of the end of the modifiers; the string from this
3384 position is the unmodified symbol name.
3386 This doesn't use any caches. */
3389 parse_modifiers_uncached (symbol
, modifier_end
)
3393 struct Lisp_String
*name
;
3397 CHECK_SYMBOL (symbol
, 1);
3400 name
= XSYMBOL (symbol
)->name
;
3402 for (i
= 0; i
+2 <= name
->size
; )
3404 int this_mod_end
= 0;
3407 /* See if the name continues with a modifier word.
3408 Check that the word appears, but don't check what follows it.
3409 Set this_mod and this_mod_end to record what we find. */
3411 switch (name
->data
[i
])
3413 #define SINGLE_LETTER_MOD(BIT) \
3414 (this_mod_end = i + 1, this_mod = BIT)
3417 SINGLE_LETTER_MOD (alt_modifier
);
3421 SINGLE_LETTER_MOD (ctrl_modifier
);
3425 SINGLE_LETTER_MOD (hyper_modifier
);
3429 SINGLE_LETTER_MOD (meta_modifier
);
3433 SINGLE_LETTER_MOD (shift_modifier
);
3437 SINGLE_LETTER_MOD (super_modifier
);
3440 #undef SINGLE_LETTER_MOD
3443 /* If we found no modifier, stop looking for them. */
3444 if (this_mod_end
== 0)
3447 /* Check there is a dash after the modifier, so that it
3448 really is a modifier. */
3449 if (this_mod_end
>= name
->size
|| name
->data
[this_mod_end
] != '-')
3452 /* This modifier is real; look for another. */
3453 modifiers
|= this_mod
;
3454 i
= this_mod_end
+ 1;
3457 /* Should we include the `click' modifier? */
3458 if (! (modifiers
& (down_modifier
| drag_modifier
3459 | double_modifier
| triple_modifier
))
3460 && i
+ 7 == name
->size
3461 && strncmp (name
->data
+ i
, "mouse-", 6) == 0
3462 && ('0' <= name
->data
[i
+ 6] && name
->data
[i
+ 6] <= '9'))
3463 modifiers
|= click_modifier
;
3471 /* Return a symbol whose name is the modifier prefixes for MODIFIERS
3472 prepended to the string BASE[0..BASE_LEN-1].
3473 This doesn't use any caches. */
3475 apply_modifiers_uncached (modifiers
, base
, base_len
)
3480 /* Since BASE could contain nulls, we can't use intern here; we have
3481 to use Fintern, which expects a genuine Lisp_String, and keeps a
3484 (char *) alloca (sizeof ("A-C-H-M-S-s-down-drag-double-triple-"));
3490 /* Only the event queue may use the `up' modifier; it should always
3491 be turned into a click or drag event before presented to lisp code. */
3492 if (modifiers
& up_modifier
)
3495 if (modifiers
& alt_modifier
) { *p
++ = 'A'; *p
++ = '-'; }
3496 if (modifiers
& ctrl_modifier
) { *p
++ = 'C'; *p
++ = '-'; }
3497 if (modifiers
& hyper_modifier
) { *p
++ = 'H'; *p
++ = '-'; }
3498 if (modifiers
& meta_modifier
) { *p
++ = 'M'; *p
++ = '-'; }
3499 if (modifiers
& shift_modifier
) { *p
++ = 'S'; *p
++ = '-'; }
3500 if (modifiers
& super_modifier
) { *p
++ = 's'; *p
++ = '-'; }
3501 if (modifiers
& double_modifier
) { strcpy (p
, "double-"); p
+= 7; }
3502 if (modifiers
& triple_modifier
) { strcpy (p
, "triple-"); p
+= 7; }
3503 if (modifiers
& down_modifier
) { strcpy (p
, "down-"); p
+= 5; }
3504 if (modifiers
& drag_modifier
) { strcpy (p
, "drag-"); p
+= 5; }
3505 /* The click modifier is denoted by the absence of other modifiers. */
3509 mod_len
= p
- new_mods
;
3513 Lisp_Object new_name
;
3515 new_name
= make_uninit_string (mod_len
+ base_len
);
3516 bcopy (new_mods
, XSTRING (new_name
)->data
, mod_len
);
3517 bcopy (base
, XSTRING (new_name
)->data
+ mod_len
, base_len
);
3519 return Fintern (new_name
, Qnil
);
3524 static char *modifier_names
[] =
3526 "up", "down", "drag", "click", "double", "triple", 0, 0,
3527 0, 0, 0, 0, 0, 0, 0, 0,
3528 0, 0, "alt", "super", "hyper", "shift", "control", "meta"
3530 #define NUM_MOD_NAMES (sizeof (modifier_names) / sizeof (modifier_names[0]))
3532 static Lisp_Object modifier_symbols
;
3534 /* Return the list of modifier symbols corresponding to the mask MODIFIERS. */
3536 lispy_modifier_list (modifiers
)
3539 Lisp_Object modifier_list
;
3542 modifier_list
= Qnil
;
3543 for (i
= 0; (1<<i
) <= modifiers
&& i
< NUM_MOD_NAMES
; i
++)
3544 if (modifiers
& (1<<i
))
3545 modifier_list
= Fcons (XVECTOR (modifier_symbols
)->contents
[i
],
3548 return modifier_list
;
3552 /* Parse the modifiers on SYMBOL, and return a list like (UNMODIFIED MASK),
3553 where UNMODIFIED is the unmodified form of SYMBOL,
3554 MASK is the set of modifiers present in SYMBOL's name.
3555 This is similar to parse_modifiers_uncached, but uses the cache in
3556 SYMBOL's Qevent_symbol_element_mask property, and maintains the
3557 Qevent_symbol_elements property. */
3560 parse_modifiers (symbol
)
3563 Lisp_Object elements
;
3565 elements
= Fget (symbol
, Qevent_symbol_element_mask
);
3566 if (CONSP (elements
))
3571 int modifiers
= parse_modifiers_uncached (symbol
, &end
);
3572 Lisp_Object unmodified
;
3575 unmodified
= Fintern (make_string (XSYMBOL (symbol
)->name
->data
+ end
,
3576 XSYMBOL (symbol
)->name
->size
- end
),
3579 if (modifiers
& ~(((EMACS_INT
)1 << VALBITS
) - 1))
3581 XSETFASTINT (mask
, modifiers
);
3582 elements
= Fcons (unmodified
, Fcons (mask
, Qnil
));
3584 /* Cache the parsing results on SYMBOL. */
3585 Fput (symbol
, Qevent_symbol_element_mask
,
3587 Fput (symbol
, Qevent_symbol_elements
,
3588 Fcons (unmodified
, lispy_modifier_list (modifiers
)));
3590 /* Since we know that SYMBOL is modifiers applied to unmodified,
3591 it would be nice to put that in unmodified's cache.
3592 But we can't, since we're not sure that parse_modifiers is
3599 /* Apply the modifiers MODIFIERS to the symbol BASE.
3600 BASE must be unmodified.
3602 This is like apply_modifiers_uncached, but uses BASE's
3603 Qmodifier_cache property, if present. It also builds
3604 Qevent_symbol_elements properties, since it has that info anyway.
3606 apply_modifiers copies the value of BASE's Qevent_kind property to
3607 the modified symbol. */
3609 apply_modifiers (modifiers
, base
)
3613 Lisp_Object cache
, index
, entry
, new_symbol
;
3615 /* Mask out upper bits. We don't know where this value's been. */
3616 modifiers
&= ((EMACS_INT
)1 << VALBITS
) - 1;
3618 /* The click modifier never figures into cache indices. */
3619 cache
= Fget (base
, Qmodifier_cache
);
3620 XSETFASTINT (index
, (modifiers
& ~click_modifier
));
3621 entry
= assq_no_quit (index
, cache
);
3624 new_symbol
= XCONS (entry
)->cdr
;
3627 /* We have to create the symbol ourselves. */
3628 new_symbol
= apply_modifiers_uncached (modifiers
,
3629 XSYMBOL (base
)->name
->data
,
3630 XSYMBOL (base
)->name
->size
);
3632 /* Add the new symbol to the base's cache. */
3633 entry
= Fcons (index
, new_symbol
);
3634 Fput (base
, Qmodifier_cache
, Fcons (entry
, cache
));
3636 /* We have the parsing info now for free, so add it to the caches. */
3637 XSETFASTINT (index
, modifiers
);
3638 Fput (new_symbol
, Qevent_symbol_element_mask
,
3639 Fcons (base
, Fcons (index
, Qnil
)));
3640 Fput (new_symbol
, Qevent_symbol_elements
,
3641 Fcons (base
, lispy_modifier_list (modifiers
)));
3644 /* Make sure this symbol is of the same kind as BASE.
3646 You'd think we could just set this once and for all when we
3647 intern the symbol above, but reorder_modifiers may call us when
3648 BASE's property isn't set right; we can't assume that just
3649 because it has a Qmodifier_cache property it must have its
3650 Qevent_kind set right as well. */
3651 if (NILP (Fget (new_symbol
, Qevent_kind
)))
3655 kind
= Fget (base
, Qevent_kind
);
3657 Fput (new_symbol
, Qevent_kind
, kind
);
3664 /* Given a symbol whose name begins with modifiers ("C-", "M-", etc),
3665 return a symbol with the modifiers placed in the canonical order.
3666 Canonical order is alphabetical, except for down and drag, which
3667 always come last. The 'click' modifier is never written out.
3669 Fdefine_key calls this to make sure that (for example) C-M-foo
3670 and M-C-foo end up being equivalent in the keymap. */
3673 reorder_modifiers (symbol
)
3676 /* It's hopefully okay to write the code this way, since everything
3677 will soon be in caches, and no consing will be done at all. */
3680 parsed
= parse_modifiers (symbol
);
3681 return apply_modifiers ((int) XINT (XCONS (XCONS (parsed
)->cdr
)->car
),
3682 XCONS (parsed
)->car
);
3686 /* For handling events, we often want to produce a symbol whose name
3687 is a series of modifier key prefixes ("M-", "C-", etcetera) attached
3688 to some base, like the name of a function key or mouse button.
3689 modify_event_symbol produces symbols of this sort.
3691 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
3692 is the name of the i'th symbol. TABLE_SIZE is the number of elements
3695 Alternatively, NAME_ALIST is an alist mapping codes into symbol names.
3696 NAME_ALIST is used if it is non-nil; otherwise NAME_TABLE is used.
3698 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
3699 persist between calls to modify_event_symbol that it can use to
3700 store a cache of the symbols it's generated for this NAME_TABLE
3701 before. The object stored there may be a vector or an alist.
3703 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
3705 MODIFIERS is a set of modifier bits (as given in struct input_events)
3706 whose prefixes should be applied to the symbol name.
3708 SYMBOL_KIND is the value to be placed in the event_kind property of
3709 the returned symbol.
3711 The symbols we create are supposed to have an
3712 `event-symbol-elements' property, which lists the modifiers present
3713 in the symbol's name. */
3716 modify_event_symbol (symbol_num
, modifiers
, symbol_kind
, name_alist
,
3717 name_table
, symbol_table
, table_size
)
3720 Lisp_Object symbol_kind
;
3721 Lisp_Object name_alist
;
3723 Lisp_Object
*symbol_table
;
3727 Lisp_Object symbol_int
;
3729 XSETINT (symbol_int
, symbol_num
);
3731 /* Is this a request for a valid symbol? */
3732 if (symbol_num
< 0 || symbol_num
>= table_size
)
3735 if (CONSP (*symbol_table
))
3736 value
= Fcdr (assq_no_quit (symbol_int
, *symbol_table
));
3738 /* If *symbol_table doesn't seem to be initialized properly, fix that.
3739 *symbol_table should be a lisp vector TABLE_SIZE elements long,
3740 where the Nth element is the symbol for NAME_TABLE[N], or nil if
3741 we've never used that symbol before. */
3744 if (! VECTORP (*symbol_table
)
3745 || XVECTOR (*symbol_table
)->size
!= table_size
)
3749 XSETFASTINT (size
, table_size
);
3750 *symbol_table
= Fmake_vector (size
, Qnil
);
3753 value
= XVECTOR (*symbol_table
)->contents
[symbol_num
];
3756 /* Have we already used this symbol before? */
3759 /* No; let's create it. */
3760 if (!NILP (name_alist
))
3761 value
= Fcdr_safe (Fassq (symbol_int
, name_alist
));
3762 else if (name_table
[symbol_num
])
3763 value
= intern (name_table
[symbol_num
]);
3768 sprintf (buf
, "key-%d", symbol_num
);
3769 value
= intern (buf
);
3772 if (CONSP (*symbol_table
))
3773 *symbol_table
= Fcons (value
, *symbol_table
);
3775 XVECTOR (*symbol_table
)->contents
[symbol_num
] = value
;
3777 /* Fill in the cache entries for this symbol; this also
3778 builds the Qevent_symbol_elements property, which the user
3780 apply_modifiers (modifiers
& click_modifier
, value
);
3781 Fput (value
, Qevent_kind
, symbol_kind
);
3784 /* Apply modifiers to that symbol. */
3785 return apply_modifiers (modifiers
, value
);
3788 /* Convert a list that represents an event type,
3789 such as (ctrl meta backspace), into the usual representation of that
3790 event type as a number or a symbol. */
3793 convert_event_type_list (event
)
3802 while (CONSP (rest
))
3807 elt
= XCONS (rest
)->car
;
3809 /* Given a symbol, see if it is a modifier name. */
3811 this = parse_solitary_modifier (elt
);
3815 else if (!NILP (base
))
3816 error ("Two bases given in one event");
3820 rest
= XCONS (rest
)->cdr
;
3823 /* Let the symbol A refer to the character A. */
3824 if (SYMBOLP (base
) && XSYMBOL (base
)->name
->size
== 1)
3825 XSETINT (base
, XSYMBOL (base
)->name
->data
[0]);
3827 if (INTEGERP (base
))
3829 /* Turn (shift a) into A. */
3830 if ((modifiers
& shift_modifier
) != 0
3831 && (XINT (base
) >= 'a' && XINT (base
) <= 'z'))
3833 XSETINT (base
, XINT (base
) - ('a' - 'A'));
3834 modifiers
&= ~shift_modifier
;
3837 /* Turn (control a) into C-a. */
3838 if (modifiers
& ctrl_modifier
)
3839 return make_number ((modifiers
& ~ctrl_modifier
)
3840 | make_ctrl_char (XINT (base
)));
3842 return make_number (modifiers
| XINT (base
));
3844 else if (SYMBOLP (base
))
3845 return apply_modifiers (modifiers
, base
);
3847 error ("Invalid base event");
3850 /* Try to recognize SYMBOL as a modifier name.
3851 Return the modifier flag bit, or 0 if not recognized. */
3854 parse_solitary_modifier (symbol
)
3857 struct Lisp_String
*name
= XSYMBOL (symbol
)->name
;
3859 switch (name
->data
[0])
3861 #define SINGLE_LETTER_MOD(BIT) \
3862 if (name->size == 1) \
3865 #define MULTI_LETTER_MOD(BIT, NAME, LEN) \
3866 if (LEN == name->size \
3867 && ! strncmp (name->data, NAME, LEN)) \
3871 SINGLE_LETTER_MOD (alt_modifier
);
3875 MULTI_LETTER_MOD (alt_modifier
, "alt", 3);
3879 SINGLE_LETTER_MOD (ctrl_modifier
);
3883 MULTI_LETTER_MOD (ctrl_modifier
, "ctrl", 4);
3884 MULTI_LETTER_MOD (ctrl_modifier
, "control", 7);
3888 SINGLE_LETTER_MOD (hyper_modifier
);
3892 MULTI_LETTER_MOD (hyper_modifier
, "hyper", 5);
3896 SINGLE_LETTER_MOD (meta_modifier
);
3900 MULTI_LETTER_MOD (meta_modifier
, "meta", 4);
3904 SINGLE_LETTER_MOD (shift_modifier
);
3908 MULTI_LETTER_MOD (shift_modifier
, "shift", 5);
3909 MULTI_LETTER_MOD (super_modifier
, "super", 5);
3910 SINGLE_LETTER_MOD (super_modifier
);
3914 MULTI_LETTER_MOD (drag_modifier
, "drag", 4);
3915 MULTI_LETTER_MOD (down_modifier
, "down", 4);
3916 MULTI_LETTER_MOD (double_modifier
, "double", 6);
3920 MULTI_LETTER_MOD (triple_modifier
, "triple", 6);
3923 #undef SINGLE_LETTER_MOD
3924 #undef MULTI_LETTER_MOD
3930 /* Return 1 if EVENT is a list whose elements are all integers or symbols.
3931 Such a list is not valid as an event,
3932 but it can be a Lucid-style event type list. */
3935 lucid_event_type_list_p (object
)
3940 if (! CONSP (object
))
3943 for (tail
= object
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
3946 elt
= XCONS (tail
)->car
;
3947 if (! (INTEGERP (elt
) || SYMBOLP (elt
)))
3954 /* Store into *addr a value nonzero if terminal input chars are available.
3955 Serves the purpose of ioctl (0, FIONREAD, addr)
3956 but works even if FIONREAD does not exist.
3957 (In fact, this may actually read some input.) */
3960 get_input_pending (addr
)
3963 /* First of all, have we already counted some input? */
3964 *addr
= !NILP (Vquit_flag
) || readable_events ();
3966 /* If input is being read as it arrives, and we have none, there is none. */
3967 if (*addr
> 0 || (interrupt_input
&& ! interrupts_deferred
))
3970 /* Try to read some input and see how much we get. */
3972 *addr
= !NILP (Vquit_flag
) || readable_events ();
3975 /* Interface to read_avail_input, blocking SIGIO or SIGALRM if necessary. */
3978 gobble_input (expected
)
3983 if (interrupt_input
)
3986 mask
= sigblockx (SIGIO
);
3987 read_avail_input (expected
);
3991 #ifdef POLL_FOR_INPUT
3992 if (read_socket_hook
&& !interrupt_input
&& poll_suppress_count
== 0)
3995 mask
= sigblockx (SIGALRM
);
3996 read_avail_input (expected
);
4002 read_avail_input (expected
);
4006 /* Put a buffer_switch_event in the buffer
4007 so that read_key_sequence will notice the new current buffer. */
4009 record_asynch_buffer_change ()
4011 struct input_event event
;
4014 event
.kind
= buffer_switch_event
;
4015 event
.frame_or_window
= Qnil
;
4018 /* We don't need a buffer-switch event unless Emacs is waiting for input.
4019 The purpose of the event is to make read_key_sequence look up the
4020 keymaps again. If we aren't in read_key_sequence, we don't need one,
4021 and the event could cause trouble by messing up (input-pending-p). */
4022 tem
= Fwaiting_for_user_input_p ();
4026 /* We never need these events if we have no asynchronous subprocesses. */
4030 /* Make sure no interrupt happens while storing the event. */
4032 if (interrupt_input
)
4035 mask
= sigblockx (SIGIO
);
4036 kbd_buffer_store_event (&event
);
4043 kbd_buffer_store_event (&event
);
4050 /* Read any terminal input already buffered up by the system
4051 into the kbd_buffer, but do not wait.
4053 EXPECTED should be nonzero if the caller knows there is some input.
4055 Except on VMS, all input is read by this function.
4056 If interrupt_input is nonzero, this function MUST be called
4057 only when SIGIO is blocked.
4059 Returns the number of keyboard chars read, or -1 meaning
4060 this is a bad time to try to read input. */
4063 read_avail_input (expected
)
4066 struct input_event buf
[KBD_BUFFER_SIZE
];
4070 if (read_socket_hook
)
4071 /* No need for FIONREAD or fcntl; just say don't wait. */
4072 nread
= (*read_socket_hook
) (input_fd
, buf
, KBD_BUFFER_SIZE
,
4073 expected
, expected
);
4076 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
4077 the kbd_buffer can really hold. That may prevent loss
4078 of characters on some systems when input is stuffed at us. */
4079 unsigned char cbuf
[KBD_BUFFER_SIZE
- 1];
4082 /* Determine how many characters we should *try* to read. */
4085 #else /* not WINDOWSNT */
4087 n_to_read
= dos_keysns ();
4090 #else /* not MSDOS */
4092 /* Find out how much input is available. */
4093 if (ioctl (input_fd
, FIONREAD
, &n_to_read
) < 0)
4094 /* Formerly simply reported no input, but that sometimes led to
4095 a failure of Emacs to terminate.
4096 SIGHUP seems appropriate if we can't reach the terminal. */
4097 /* ??? Is it really right to send the signal just to this process
4098 rather than to the whole process group?
4099 Perhaps on systems with FIONREAD Emacs is alone in its group. */
4100 kill (getpid (), SIGHUP
);
4103 if (n_to_read
> sizeof cbuf
)
4104 n_to_read
= sizeof cbuf
;
4105 #else /* no FIONREAD */
4106 #if defined(USG) || defined(DGUX)
4107 /* Read some input if available, but don't wait. */
4108 n_to_read
= sizeof cbuf
;
4109 fcntl (input_fd
, F_SETFL
, O_NDELAY
);
4114 #endif /* not MSDOS */
4115 #endif /* not WINDOWSNT */
4117 /* Now read; for one reason or another, this will not block.
4118 NREAD is set to the number of chars read. */
4122 cbuf
[0] = dos_keyread();
4125 nread
= read (input_fd
, cbuf
, n_to_read
);
4127 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
4128 /* The kernel sometimes fails to deliver SIGHUP for ptys.
4129 This looks incorrect, but it isn't, because _BSD causes
4130 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
4131 and that causes a value other than 0 when there is no input. */
4137 /* We used to retry the read if it was interrupted.
4138 But this does the wrong thing when O_NDELAY causes
4139 an EAGAIN error. Does anybody know of a situation
4140 where a retry is actually needed? */
4142 nread
< 0 && (errno
== EAGAIN
4156 #if defined (USG) || defined (DGUX)
4157 fcntl (input_fd
, F_SETFL
, 0);
4158 #endif /* USG or DGUX */
4159 #endif /* no FIONREAD */
4160 for (i
= 0; i
< nread
; i
++)
4162 buf
[i
].kind
= ascii_keystroke
;
4163 buf
[i
].modifiers
= 0;
4164 if (meta_key
== 1 && (cbuf
[i
] & 0x80))
4165 buf
[i
].modifiers
= meta_modifier
;
4169 buf
[i
].code
= cbuf
[i
];
4171 XSETFRAME (buf
[i
].frame_or_window
, selected_frame
);
4173 buf
[i
].frame_or_window
= Qnil
;
4178 /* Scan the chars for C-g and store them in kbd_buffer. */
4179 for (i
= 0; i
< nread
; i
++)
4181 kbd_buffer_store_event (&buf
[i
]);
4182 /* Don't look at input that follows a C-g too closely.
4183 This reduces lossage due to autorepeat on C-g. */
4184 if (buf
[i
].kind
== ascii_keystroke
4185 && buf
[i
].code
== quit_char
)
4191 #endif /* not VMS */
4193 #ifdef SIGIO /* for entire page */
4194 /* Note SIGIO has been undef'd if FIONREAD is missing. */
4197 input_available_signal (signo
)
4200 /* Must preserve main program's value of errno. */
4201 int old_errno
= errno
;
4203 extern int select_alarmed
;
4207 /* USG systems forget handlers when they are used;
4208 must reestablish each time */
4209 signal (signo
, input_available_signal
);
4216 if (input_available_clear_time
)
4217 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
4222 nread
= read_avail_input (1);
4223 /* -1 means it's not ok to read the input now.
4224 UNBLOCK_INPUT will read it later; now, avoid infinite loop.
4225 0 means there was no keyboard input available. */
4230 select_alarmed
= 1; /* Force the select emulator back to life */
4241 /* Send ourselves a SIGIO.
4243 This function exists so that the UNBLOCK_INPUT macro in
4244 blockinput.h can have some way to take care of input we put off
4245 dealing with, without assuming that every file which uses
4246 UNBLOCK_INPUT also has #included the files necessary to get SIGIO. */
4248 reinvoke_input_signal ()
4257 /* Return the prompt-string of a sparse keymap.
4258 This is the first element which is a string.
4259 Return nil if there is none. */
4267 register Lisp_Object tem
;
4276 static void menu_bar_item ();
4277 static void menu_bar_one_keymap ();
4279 /* These variables hold the vector under construction within
4280 menu_bar_items and its subroutines, and the current index
4281 for storing into that vector. */
4282 static Lisp_Object menu_bar_items_vector
;
4283 static int menu_bar_items_index
;
4285 /* Return a vector of menu items for a menu bar, appropriate
4286 to the current buffer. Each item has three elements in the vector:
4289 OLD is an old vector we can optionally reuse, or nil. */
4292 menu_bar_items (old
)
4295 /* The number of keymaps we're scanning right now, and the number of
4296 keymaps we have allocated space for. */
4299 /* maps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
4300 in the current keymaps, or nil where it is not a prefix. */
4303 Lisp_Object def
, tem
, tail
;
4312 struct gcpro gcpro1
;
4314 /* In order to build the menus, we need to call the keymap
4315 accessors. They all call QUIT. But this function is called
4316 during redisplay, during which a quit is fatal. So inhibit
4317 quitting while building the menus.
4318 We do this instead of specbind because (1) errors will clear it anyway
4319 and (2) this avoids risk of specpdl overflow. */
4320 oquit
= Vinhibit_quit
;
4324 menu_bar_items_vector
= old
;
4326 menu_bar_items_vector
= Fmake_vector (make_number (24), Qnil
);
4327 menu_bar_items_index
= 0;
4329 GCPRO1 (menu_bar_items_vector
);
4331 /* Build our list of keymaps.
4332 If we recognize a function key and replace its escape sequence in
4333 keybuf with its symbol, or if the sequence starts with a mouse
4334 click and we need to switch buffers, we jump back here to rebuild
4335 the initial keymaps from the current buffer. */
4339 /* Should overriding-local-map apply, here? */
4340 if (!NILP (Voverriding_local_map_menu_flag
))
4342 if (NILP (Voverriding_local_map
))
4344 /* Yes, and it is nil. Use just global map. */
4346 maps
= (Lisp_Object
*) alloca (nmaps
* sizeof (maps
[0]));
4350 /* Yes, and it is non-nil. Use it and the global map. */
4352 maps
= (Lisp_Object
*) alloca (nmaps
* sizeof (maps
[0]));
4353 maps
[0] = Voverriding_local_map
;
4358 /* No, so use major and minor mode keymaps. */
4359 nmaps
= current_minor_maps (0, &tmaps
) + 2;
4360 maps
= (Lisp_Object
*) alloca (nmaps
* sizeof (maps
[0]));
4361 bcopy (tmaps
, maps
, (nmaps
- 2) * sizeof (maps
[0]));
4362 #ifdef USE_TEXT_PROPERTIES
4363 maps
[nmaps
-2] = get_local_map (PT
, current_buffer
);
4365 maps
[nmaps
-2] = current_buffer
->keymap
;
4368 maps
[nmaps
-1] = current_global_map
;
4371 /* Look up in each map the dummy prefix key `menu-bar'. */
4375 for (mapno
= nmaps
- 1; mapno
>= 0; mapno
--)
4377 if (! NILP (maps
[mapno
]))
4378 def
= get_keyelt (access_keymap (maps
[mapno
], Qmenu_bar
, 1, 0));
4382 tem
= Fkeymapp (def
);
4384 menu_bar_one_keymap (def
);
4387 /* Move to the end those items that should be at the end. */
4389 for (tail
= Vmenu_bar_final_items
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4392 int end
= menu_bar_items_index
;
4394 for (i
= 0; i
< end
; i
+= 3)
4395 if (EQ (XCONS (tail
)->car
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
4397 Lisp_Object tem0
, tem1
, tem2
;
4398 /* Move the item at index I to the end,
4399 shifting all the others forward. */
4400 tem0
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 0];
4401 tem1
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 1];
4402 tem2
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
4404 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3],
4405 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
4406 (end
- i
- 3) * sizeof (Lisp_Object
));
4407 XVECTOR (menu_bar_items_vector
)->contents
[end
- 3] = tem0
;
4408 XVECTOR (menu_bar_items_vector
)->contents
[end
- 2] = tem1
;
4409 XVECTOR (menu_bar_items_vector
)->contents
[end
- 1] = tem2
;
4414 /* Add nil, nil, nil at the end. */
4415 i
= menu_bar_items_index
;
4416 if (i
+ 3 > XVECTOR (menu_bar_items_vector
)->size
)
4419 int newsize
= 2 * i
;
4420 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
4421 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
4422 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
4423 menu_bar_items_vector
= tem
;
4425 /* Add this item. */
4426 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
4427 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
4428 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Qnil
;
4429 menu_bar_items_index
= i
;
4431 Vinhibit_quit
= oquit
;
4433 return menu_bar_items_vector
;
4436 /* Scan one map KEYMAP, accumulating any menu items it defines
4437 in menu_bar_items_vector. */
4440 menu_bar_one_keymap (keymap
)
4443 Lisp_Object tail
, item
, key
, binding
, item_string
, table
;
4445 /* Loop over all keymap entries that have menu strings. */
4446 for (tail
= keymap
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
4448 item
= XCONS (tail
)->car
;
4451 key
= XCONS (item
)->car
;
4452 binding
= XCONS (item
)->cdr
;
4453 if (CONSP (binding
))
4455 item_string
= XCONS (binding
)->car
;
4456 if (STRINGP (item_string
))
4457 menu_bar_item (key
, item_string
, Fcdr (binding
));
4459 else if (EQ (binding
, Qundefined
))
4460 menu_bar_item (key
, Qnil
, binding
);
4462 else if (VECTORP (item
))
4464 /* Loop over the char values represented in the vector. */
4465 int len
= XVECTOR (item
)->size
;
4467 for (c
= 0; c
< len
; c
++)
4469 Lisp_Object character
;
4470 XSETFASTINT (character
, c
);
4471 binding
= XVECTOR (item
)->contents
[c
];
4472 if (CONSP (binding
))
4474 item_string
= XCONS (binding
)->car
;
4475 if (STRINGP (item_string
))
4476 menu_bar_item (key
, item_string
, Fcdr (binding
));
4478 else if (EQ (binding
, Qundefined
))
4479 menu_bar_item (key
, Qnil
, binding
);
4485 /* This is used as the handler when calling internal_condition_case_1. */
4488 menu_bar_item_1 (arg
)
4494 /* Add one item to menu_bar_items_vector, for KEY, ITEM_STRING and DEF.
4495 If there's already an item for KEY, add this DEF to it. */
4498 menu_bar_item (key
, item_string
, def
)
4499 Lisp_Object key
, item_string
, def
;
4502 Lisp_Object enabled
;
4505 if (EQ (def
, Qundefined
))
4507 /* If a map has an explicit `undefined' as definition,
4508 discard any previously made menu bar item. */
4510 for (i
= 0; i
< menu_bar_items_index
; i
+= 3)
4511 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
4513 if (menu_bar_items_index
> i
+ 3)
4514 bcopy (&XVECTOR (menu_bar_items_vector
)->contents
[i
+ 3],
4515 &XVECTOR (menu_bar_items_vector
)->contents
[i
],
4516 (menu_bar_items_index
- i
- 3) * sizeof (Lisp_Object
));
4517 menu_bar_items_index
-= 3;
4521 /* If there's no definition for this key yet,
4522 just ignore `undefined'. */
4526 /* See if this entry is enabled. */
4531 /* No property, or nil, means enable.
4532 Otherwise, enable if value is not nil. */
4533 tem
= Fget (def
, Qmenu_enable
);
4535 /* (condition-case nil (eval tem)
4537 enabled
= internal_condition_case_1 (Feval
, tem
, Qerror
,
4541 /* Ignore this item if it's not enabled. */
4545 /* Find any existing item for this KEY. */
4546 for (i
= 0; i
< menu_bar_items_index
; i
+= 3)
4547 if (EQ (key
, XVECTOR (menu_bar_items_vector
)->contents
[i
]))
4550 /* If we did not find this KEY, add it at the end. */
4551 if (i
== menu_bar_items_index
)
4553 /* If vector is too small, get a bigger one. */
4554 if (i
+ 3 > XVECTOR (menu_bar_items_vector
)->size
)
4557 int newsize
= 2 * i
;
4558 tem
= Fmake_vector (make_number (2 * i
), Qnil
);
4559 bcopy (XVECTOR (menu_bar_items_vector
)->contents
,
4560 XVECTOR (tem
)->contents
, i
* sizeof (Lisp_Object
));
4561 menu_bar_items_vector
= tem
;
4563 /* Add this item. */
4564 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = key
;
4565 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = item_string
;
4566 XVECTOR (menu_bar_items_vector
)->contents
[i
++] = Fcons (def
, Qnil
);
4567 menu_bar_items_index
= i
;
4569 /* We did find an item for this KEY. Add DEF to its list of maps. */
4573 old
= XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2];
4574 XVECTOR (menu_bar_items_vector
)->contents
[i
+ 2] = Fcons (def
, old
);
4578 /* Read a character using menus based on maps in the array MAPS.
4579 NMAPS is the length of MAPS. Return nil if there are no menus in the maps.
4580 Return t if we displayed a menu but the user rejected it.
4582 PREV_EVENT is the previous input event, or nil if we are reading
4583 the first event of a key sequence.
4585 If USED_MOUSE_MENU is non-null, then we set *USED_MOUSE_MENU to 1
4586 if we used a mouse menu to read the input, or zero otherwise. If
4587 USED_MOUSE_MENU is null, we don't dereference it.
4589 The prompting is done based on the prompt-string of the map
4590 and the strings associated with various map elements.
4592 This can be done with X menus or with menus put in the minibuf.
4593 These are done in different ways, depending on how the input will be read.
4594 Menus using X are done after auto-saving in read-char, getting the input
4595 event from Fx_popup_menu; menus using the minibuf use read_char recursively
4596 and do auto-saving in the inner call of read_char. */
4599 read_char_x_menu_prompt (nmaps
, maps
, prev_event
, used_mouse_menu
)
4602 Lisp_Object prev_event
;
4603 int *used_mouse_menu
;
4606 register Lisp_Object name
;
4607 Lisp_Object rest
, vector
;
4609 if (used_mouse_menu
)
4610 *used_mouse_menu
= 0;
4612 /* Use local over global Menu maps */
4614 if (! menu_prompting
)
4617 /* Optionally disregard all but the global map. */
4618 if (inhibit_local_menu_bar_menus
)
4620 maps
+= (nmaps
- 1);
4624 /* Get the menu name from the first map that has one (a prompt string). */
4625 for (mapno
= 0; mapno
< nmaps
; mapno
++)
4627 name
= map_prompt (maps
[mapno
]);
4632 /* If we don't have any menus, just read a character normally. */
4636 #if (defined (HAVE_X_WINDOWS) && defined (HAVE_X_MENU)) || defined (MSDOS)
4637 /* If we got to this point via a mouse click,
4638 use a real menu for mouse selection. */
4639 if (EVENT_HAS_PARAMETERS (prev_event
)
4640 && !EQ (XCONS (prev_event
)->car
, Qmenu_bar
))
4642 /* Display the menu and get the selection. */
4643 Lisp_Object
*realmaps
4644 = (Lisp_Object
*) alloca (nmaps
* sizeof (Lisp_Object
));
4648 /* Use the maps that are not nil. */
4649 for (mapno
= 0; mapno
< nmaps
; mapno
++)
4650 if (!NILP (maps
[mapno
]))
4651 realmaps
[nmaps1
++] = maps
[mapno
];
4653 value
= Fx_popup_menu (prev_event
, Flist (nmaps1
, realmaps
));
4656 /* If we got more than one event, put all but the first
4657 onto this list to be read later.
4658 Return just the first event now. */
4659 Vunread_command_events
4660 = nconc2 (XCONS (value
)->cdr
, Vunread_command_events
);
4661 value
= XCONS (value
)->car
;
4663 else if (NILP (value
))
4665 if (used_mouse_menu
)
4666 *used_mouse_menu
= 1;
4669 #endif /* (HAVE_X_WINDOWS && HAVE_X_MENU) || MSDOS */
4674 read_char_minibuf_menu_prompt (commandflag
, nmaps
, maps
)
4680 register Lisp_Object name
;
4682 int width
= FRAME_WIDTH (selected_frame
) - 4;
4683 char *menu
= (char *) alloca (width
+ 4);
4686 Lisp_Object rest
, vector
;
4688 if (! menu_prompting
)
4691 /* Get the menu name from the first map that has one (a prompt string). */
4692 for (mapno
= 0; mapno
< nmaps
; mapno
++)
4694 name
= map_prompt (maps
[mapno
]);
4699 /* If we don't have any menus, just read a character normally. */
4703 /* Prompt string always starts with map's prompt, and a space. */
4704 strcpy (menu
, XSTRING (name
)->data
);
4705 nlength
= XSTRING (name
)->size
;
4706 menu
[nlength
++] = ':';
4707 menu
[nlength
++] = ' ';
4710 /* Start prompting at start of first map. */
4714 /* Present the documented bindings, a line at a time. */
4721 Lisp_Object orig_defn_macro
;
4723 /* Loop over elements of map. */
4728 /* If reached end of map, start at beginning of next map. */
4732 /* At end of last map, wrap around to first map if just starting,
4733 or end this line if already have something on it. */
4737 if (notfirst
|| nobindings
) break;
4742 /* Look at the next element of the map. */
4744 elt
= XVECTOR (vector
)->contents
[idx
];
4746 elt
= Fcar_safe (rest
);
4748 if (idx
< 0 && VECTORP (elt
))
4750 /* If we found a dense table in the keymap,
4751 advanced past it, but start scanning its contents. */
4752 rest
= Fcdr_safe (rest
);
4758 /* An ordinary element. */
4760 s
= Fcar_safe (Fcdr_safe (elt
)); /* alist */
4762 s
= Fcar_safe(elt
); /* vector */
4764 /* Ignore the element if it has no prompt string. */
4766 /* If we have room for the prompt string, add it to this line.
4767 If this is the first on the line, always add it. */
4768 else if (XSTRING (s
)->size
+ i
+ 2 < width
4773 /* Punctuate between strings. */
4776 strcpy (menu
+ i
, ", ");
4782 /* Add as much of string as fits. */
4783 thiswidth
= XSTRING (s
)->size
;
4784 if (thiswidth
+ i
> width
)
4785 thiswidth
= width
- i
;
4786 bcopy (XSTRING (s
)->data
, menu
+ i
, thiswidth
);
4792 /* If this element does not fit, end the line now,
4793 and save the element for the next line. */
4794 strcpy (menu
+ i
, "...");
4798 /* Move past this element. */
4799 if (idx
>= 0 && idx
+ 1 >= XVECTOR (vector
)->size
)
4800 /* Handle reaching end of dense table. */
4805 rest
= Fcdr_safe (rest
);
4809 /* Prompt with that and read response. */
4812 /* Make believe its not a keyboard macro in case the help char
4813 is pressed. Help characters are not recorded because menu prompting
4814 is not used on replay.
4816 orig_defn_macro
= current_kboard
->defining_kbd_macro
;
4817 current_kboard
->defining_kbd_macro
= Qnil
;
4819 obj
= read_char (commandflag
, 0, 0, Qnil
, 0);
4820 while (BUFFERP (obj
));
4821 current_kboard
->defining_kbd_macro
= orig_defn_macro
;
4823 if (!INTEGERP (obj
))
4828 if (! EQ (obj
, menu_prompt_more_char
)
4829 && (!INTEGERP (menu_prompt_more_char
)
4830 || ! EQ (obj
, make_number (Ctl (XINT (menu_prompt_more_char
))))))
4832 if (!NILP (current_kboard
->defining_kbd_macro
))
4833 store_kbd_macro_char (obj
);
4836 /* Help char - go round again */
4840 /* Reading key sequences. */
4842 /* Follow KEY in the maps in CURRENT[0..NMAPS-1], placing its bindings
4843 in DEFS[0..NMAPS-1]. Set NEXT[i] to DEFS[i] if DEFS[i] is a
4844 keymap, or nil otherwise. Return the index of the first keymap in
4845 which KEY has any binding, or NMAPS if no map has a binding.
4847 If KEY is a meta ASCII character, treat it like meta-prefix-char
4848 followed by the corresponding non-meta character. Keymaps in
4849 CURRENT with non-prefix bindings for meta-prefix-char become nil in
4852 If KEY has no bindings in any of the CURRENT maps, NEXT is left
4855 NEXT may == CURRENT. */
4858 follow_key (key
, nmaps
, current
, defs
, next
)
4860 Lisp_Object
*current
, *defs
, *next
;
4863 int i
, first_binding
;
4865 /* If KEY is a meta ASCII character, treat it like meta-prefix-char
4866 followed by the corresponding non-meta character. */
4867 if (INTEGERP (key
) && (XINT (key
) & CHAR_META
))
4869 for (i
= 0; i
< nmaps
; i
++)
4870 if (! NILP (current
[i
]))
4873 get_keyelt (access_keymap (current
[i
], meta_prefix_char
, 1, 0));
4875 /* Note that since we pass the resulting bindings through
4876 get_keymap_1, non-prefix bindings for meta-prefix-char
4878 next
[i
] = get_keymap_1 (next
[i
], 0, 1);
4884 XSETINT (key
, XFASTINT (key
) & ~CHAR_META
);
4887 first_binding
= nmaps
;
4888 for (i
= nmaps
- 1; i
>= 0; i
--)
4890 if (! NILP (current
[i
]))
4892 defs
[i
] = get_keyelt (access_keymap (current
[i
], key
, 1, 0));
4893 if (! NILP (defs
[i
]))
4900 /* Given the set of bindings we've found, produce the next set of maps. */
4901 if (first_binding
< nmaps
)
4902 for (i
= 0; i
< nmaps
; i
++)
4903 next
[i
] = NILP (defs
[i
]) ? Qnil
: get_keymap_1 (defs
[i
], 0, 1);
4905 return first_binding
;
4908 /* Read a sequence of keys that ends with a non prefix character,
4909 storing it in KEYBUF, a buffer of size BUFSIZE.
4911 Return the length of the key sequence stored.
4912 Return -1 if the user rejected a command menu.
4914 Echo starting immediately unless `prompt' is 0.
4916 Where a key sequence ends depends on the currently active keymaps.
4917 These include any minor mode keymaps active in the current buffer,
4918 the current buffer's local map, and the global map.
4920 If a key sequence has no other bindings, we check Vfunction_key_map
4921 to see if some trailing subsequence might be the beginning of a
4922 function key's sequence. If so, we try to read the whole function
4923 key, and substitute its symbolic name into the key sequence.
4925 We ignore unbound `down-' mouse clicks. We turn unbound `drag-' and
4926 `double-' events into similar click events, if that would make them
4927 bound. We try to turn `triple-' events first into `double-' events,
4930 If we get a mouse click in a mode line, vertical divider, or other
4931 non-text area, we treat the click as if it were prefixed by the
4932 symbol denoting that area - `mode-line', `vertical-line', or
4935 If the sequence starts with a mouse click, we read the key sequence
4936 with respect to the buffer clicked on, not the current buffer.
4938 If the user switches frames in the midst of a key sequence, we put
4939 off the switch-frame event until later; the next call to
4940 read_char will return it. */
4943 read_key_sequence (keybuf
, bufsize
, prompt
, dont_downcase_last
,
4944 can_return_switch_frame
)
4945 Lisp_Object
*keybuf
;
4948 int dont_downcase_last
;
4949 int can_return_switch_frame
;
4951 int count
= specpdl_ptr
- specpdl
;
4953 /* How many keys there are in the current key sequence. */
4956 /* The length of the echo buffer when we started reading, and
4957 the length of this_command_keys when we started reading. */
4961 /* The number of keymaps we're scanning right now, and the number of
4962 keymaps we have allocated space for. */
4964 int nmaps_allocated
= 0;
4966 /* defs[0..nmaps-1] are the definitions of KEYBUF[0..t-1] in
4967 the current keymaps. */
4970 /* submaps[0..nmaps-1] are the prefix definitions of KEYBUF[0..t-1]
4971 in the current keymaps, or nil where it is not a prefix. */
4972 Lisp_Object
*submaps
;
4974 /* The local map to start out with at start of key sequence. */
4975 Lisp_Object orig_local_map
;
4977 /* 1 if we have already considered switching to the local-map property
4978 of the place where a mouse click occurred. */
4979 int localized_local_map
= 0;
4981 /* The index in defs[] of the first keymap that has a binding for
4982 this key sequence. In other words, the lowest i such that
4983 defs[i] is non-nil. */
4986 /* If t < mock_input, then KEYBUF[t] should be read as the next
4989 We use this to recover after recognizing a function key. Once we
4990 realize that a suffix of the current key sequence is actually a
4991 function key's escape sequence, we replace the suffix with the
4992 function key's binding from Vfunction_key_map. Now keybuf
4993 contains a new and different key sequence, so the echo area,
4994 this_command_keys, and the submaps and defs arrays are wrong. In
4995 this situation, we set mock_input to t, set t to 0, and jump to
4996 restart_sequence; the loop will read keys from keybuf up until
4997 mock_input, thus rebuilding the state; and then it will resume
4998 reading characters from the keyboard. */
5001 /* If the sequence is unbound in submaps[], then
5002 keybuf[fkey_start..fkey_end-1] is a prefix in Vfunction_key_map,
5003 and fkey_map is its binding.
5005 These might be > t, indicating that all function key scanning
5006 should hold off until t reaches them. We do this when we've just
5007 recognized a function key, to avoid searching for the function
5008 key's again in Vfunction_key_map. */
5009 int fkey_start
= 0, fkey_end
= 0;
5010 Lisp_Object fkey_map
;
5012 /* Likewise, for key_translation_map. */
5013 int keytran_start
= 0, keytran_end
= 0;
5014 Lisp_Object keytran_map
;
5016 /* If we receive a ``switch-frame'' event in the middle of a key sequence,
5017 we put it off for later. While we're reading, we keep the event here. */
5018 Lisp_Object delayed_switch_frame
;
5020 /* See the comment below... */
5021 #if defined (GOBBLE_FIRST_EVENT)
5022 Lisp_Object first_event
;
5025 Lisp_Object original_uppercase
;
5026 int original_uppercase_position
= -1;
5028 /* Gets around Microsoft compiler limitations. */
5031 struct buffer
*starting_buffer
;
5033 /* Nonzero if we seem to have got the beginning of a binding
5034 in function_key_map. */
5035 int function_key_possible
= 0;
5036 int key_translation_possible
= 0;
5040 last_nonmenu_event
= Qnil
;
5042 delayed_switch_frame
= Qnil
;
5043 fkey_map
= Vfunction_key_map
;
5044 keytran_map
= Vkey_translation_map
;
5046 /* If there is no function-key-map, turn off function key scanning. */
5047 if (NILP (Fkeymapp (Vfunction_key_map
)))
5048 fkey_start
= fkey_end
= bufsize
+ 1;
5050 /* If there is no key-translation-map, turn off scanning. */
5051 if (NILP (Fkeymapp (Vkey_translation_map
)))
5052 keytran_start
= keytran_end
= bufsize
+ 1;
5057 echo_prompt (XSTRING (prompt
)->data
);
5058 else if (cursor_in_echo_area
&& echo_keystrokes
)
5059 /* This doesn't put in a dash if the echo buffer is empty, so
5060 you don't always see a dash hanging out in the minibuffer. */
5064 /* Record the initial state of the echo area and this_command_keys;
5065 we will need to restore them if we replay a key sequence. */
5067 echo_start
= echo_length ();
5068 keys_start
= this_command_key_count
;
5070 #if defined (GOBBLE_FIRST_EVENT)
5071 /* This doesn't quite work, because some of the things that read_char
5072 does cannot safely be bypassed. It seems too risky to try to make
5075 /* Read the first char of the sequence specially, before setting
5076 up any keymaps, in case a filter runs and switches buffers on us. */
5077 first_event
= read_char (NILP (prompt
), 0, submaps
, last_nonmenu_event
,
5079 #endif /* GOBBLE_FIRST_EVENT */
5081 orig_local_map
= get_local_map (PT
, current_buffer
);
5083 /* We jump here when the key sequence has been thoroughly changed, and
5084 we need to rescan it starting from the beginning. When we jump here,
5085 keybuf[0..mock_input] holds the sequence we should reread. */
5088 starting_buffer
= current_buffer
;
5089 function_key_possible
= 0;
5090 key_translation_possible
= 0;
5092 /* Build our list of keymaps.
5093 If we recognize a function key and replace its escape sequence in
5094 keybuf with its symbol, or if the sequence starts with a mouse
5095 click and we need to switch buffers, we jump back here to rebuild
5096 the initial keymaps from the current buffer. */
5100 if (!NILP (Voverriding_local_map
))
5103 if (nmaps
> nmaps_allocated
)
5105 submaps
= (Lisp_Object
*) alloca (nmaps
* sizeof (submaps
[0]));
5106 defs
= (Lisp_Object
*) alloca (nmaps
* sizeof (defs
[0]));
5107 nmaps_allocated
= nmaps
;
5109 submaps
[0] = Voverriding_local_map
;
5113 nmaps
= current_minor_maps (0, &maps
) + 2;
5114 if (nmaps
> nmaps_allocated
)
5116 submaps
= (Lisp_Object
*) alloca (nmaps
* sizeof (submaps
[0]));
5117 defs
= (Lisp_Object
*) alloca (nmaps
* sizeof (defs
[0]));
5118 nmaps_allocated
= nmaps
;
5120 bcopy (maps
, submaps
, (nmaps
- 2) * sizeof (submaps
[0]));
5121 #ifdef USE_TEXT_PROPERTIES
5122 submaps
[nmaps
-2] = orig_local_map
;
5124 submaps
[nmaps
-2] = current_buffer
->keymap
;
5127 submaps
[nmaps
-1] = current_global_map
;
5130 /* Find an accurate initial value for first_binding. */
5131 for (first_binding
= 0; first_binding
< nmaps
; first_binding
++)
5132 if (! NILP (submaps
[first_binding
]))
5135 /* Start from the beginning in keybuf. */
5138 /* These are no-ops the first time through, but if we restart, they
5139 revert the echo area and this_command_keys to their original state. */
5140 this_command_key_count
= keys_start
;
5141 if (INTERACTIVE
&& t
< mock_input
)
5142 echo_truncate (echo_start
);
5144 /* If the best binding for the current key sequence is a keymap, or
5145 we may be looking at a function key's escape sequence, keep on
5147 while ((first_binding
< nmaps
&& ! NILP (submaps
[first_binding
]))
5148 || (first_binding
>= nmaps
5150 /* mock input is never part of a function key's sequence. */
5151 && mock_input
<= fkey_start
)
5152 || (first_binding
>= nmaps
5153 && keytran_start
< t
&& key_translation_possible
)
5154 /* Don't return in the middle of a possible function key sequence,
5155 if the only bindings we found were via case conversion.
5156 Thus, if ESC O a has a function-key-map translation
5157 and ESC o has a binding, don't return after ESC O,
5158 so that we can translate ESC O plus the next character. */
5162 int used_mouse_menu
= 0;
5164 /* Where the last real key started. If we need to throw away a
5165 key that has expanded into more than one element of keybuf
5166 (say, a mouse click on the mode line which is being treated
5167 as [mode-line (mouse-...)], then we backtrack to this point
5169 int last_real_key_start
;
5171 /* These variables are analogous to echo_start and keys_start;
5172 while those allow us to restart the entire key sequence,
5173 echo_local_start and keys_local_start allow us to throw away
5175 int echo_local_start
, keys_local_start
, local_first_binding
;
5178 error ("key sequence too long");
5181 echo_local_start
= echo_length ();
5182 keys_local_start
= this_command_key_count
;
5183 local_first_binding
= first_binding
;
5186 /* These are no-ops, unless we throw away a keystroke below and
5187 jumped back up to replay_key; in that case, these restore the
5188 variables to their original state, allowing us to replay the
5190 if (INTERACTIVE
&& t
< mock_input
)
5191 echo_truncate (echo_local_start
);
5192 this_command_key_count
= keys_local_start
;
5193 first_binding
= local_first_binding
;
5195 /* By default, assume each event is "real". */
5196 last_real_key_start
= t
;
5198 /* Does mock_input indicate that we are re-reading a key sequence? */
5202 add_command_key (key
);
5203 if (echo_keystrokes
)
5207 /* If not, we should actually read a character. */
5210 struct buffer
*buf
= current_buffer
;
5214 KBOARD
*interrupted_kboard
= current_kboard
;
5215 struct frame
*interrupted_frame
= selected_frame
;
5216 if (setjmp (wrong_kboard_jmpbuf
))
5218 if (!NILP (delayed_switch_frame
))
5220 interrupted_kboard
->kbd_queue
5221 = Fcons (delayed_switch_frame
,
5222 interrupted_kboard
->kbd_queue
);
5223 delayed_switch_frame
= Qnil
;
5226 interrupted_kboard
->kbd_queue
5227 = Fcons (keybuf
[--t
], interrupted_kboard
->kbd_queue
);
5229 /* If the side queue is non-empty, ensure it begins with a
5230 switch-frame, so we'll replay it in the right context. */
5231 if (CONSP (interrupted_kboard
->kbd_queue
)
5232 && (key
= XCONS (interrupted_kboard
->kbd_queue
)->car
,
5233 !(EVENT_HAS_PARAMETERS (key
)
5234 && EQ (EVENT_HEAD_KIND (EVENT_HEAD (key
)),
5238 XSETFRAME (frame
, interrupted_frame
);
5239 interrupted_kboard
->kbd_queue
5240 = Fcons (make_lispy_switch_frame (frame
),
5241 interrupted_kboard
->kbd_queue
);
5244 orig_local_map
= get_local_map (PT
, current_buffer
);
5245 goto replay_sequence
;
5248 key
= read_char (NILP (prompt
), nmaps
, submaps
, last_nonmenu_event
,
5252 /* read_char returns t when it shows a menu and the user rejects it.
5257 /* read_char returns -1 at the end of a macro.
5258 Emacs 18 handles this by returning immediately with a
5259 zero, so that's what we'll do. */
5260 if (INTEGERP (key
) && XINT (key
) == -1)
5263 /* The Microsoft C compiler can't handle the goto that
5269 /* If the current buffer has been changed from under us, the
5270 keymap may have changed, so replay the sequence. */
5274 orig_local_map
= get_local_map (PT
, current_buffer
);
5275 goto replay_sequence
;
5278 /* If we have a quit that was typed in another frame, and
5279 quit_throw_to_read_char switched buffers,
5280 replay to get the right keymap. */
5281 if (XINT (key
) == quit_char
&& current_buffer
!= starting_buffer
)
5286 orig_local_map
= get_local_map (PT
, current_buffer
);
5287 goto replay_sequence
;
5293 /* Clicks in non-text areas get prefixed by the symbol
5294 in their CHAR-ADDRESS field. For example, a click on
5295 the mode line is prefixed by the symbol `mode-line'.
5297 Furthermore, key sequences beginning with mouse clicks
5298 are read using the keymaps of the buffer clicked on, not
5299 the current buffer. So we may have to switch the buffer
5302 When we turn one event into two events, we must make sure
5303 that neither of the two looks like the original--so that,
5304 if we replay the events, they won't be expanded again.
5305 If not for this, such reexpansion could happen either here
5306 or when user programs play with this-command-keys. */
5307 if (EVENT_HAS_PARAMETERS (key
))
5311 kind
= EVENT_HEAD_KIND (EVENT_HEAD (key
));
5312 if (EQ (kind
, Qmouse_click
))
5314 Lisp_Object window
, posn
;
5316 window
= POSN_WINDOW (EVENT_START (key
));
5317 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
5320 /* We're looking at the second event of a
5321 sequence which we expanded before. Set
5322 last_real_key_start appropriately. */
5324 last_real_key_start
= t
- 1;
5327 /* Key sequences beginning with mouse clicks are
5328 read using the keymaps in the buffer clicked on,
5329 not the current buffer. If we're at the
5330 beginning of a key sequence, switch buffers. */
5331 if (last_real_key_start
== 0
5333 && BUFFERP (XWINDOW (window
)->buffer
)
5334 && XBUFFER (XWINDOW (window
)->buffer
) != current_buffer
)
5339 /* Arrange to go back to the original buffer once we're
5340 done reading the key sequence. Note that we can't
5341 use save_excursion_{save,restore} here, because they
5342 save point as well as the current buffer; we don't
5343 want to save point, because redisplay may change it,
5344 to accommodate a Fset_window_start or something. We
5345 don't want to do this at the top of the function,
5346 because we may get input from a subprocess which
5347 wants to change the selected window and stuff (say,
5349 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
5351 set_buffer_internal (XBUFFER (XWINDOW (window
)->buffer
));
5352 orig_local_map
= get_local_map (PT
, current_buffer
);
5353 goto replay_sequence
;
5355 /* For a mouse click, get the local text-property keymap
5356 of the place clicked on, rather than point. */
5357 if (last_real_key_start
== 0 && CONSP (XCONS (key
)->cdr
)
5358 && ! localized_local_map
)
5360 Lisp_Object map_here
, start
, pos
;
5362 localized_local_map
= 1;
5363 start
= EVENT_START (key
);
5364 if (CONSP (start
) && CONSP (XCONS (start
)->cdr
))
5366 pos
= POSN_BUFFER_POSN (start
);
5369 map_here
= get_local_map (XINT (pos
), current_buffer
);
5370 if (!EQ (map_here
, orig_local_map
))
5372 orig_local_map
= map_here
;
5376 goto replay_sequence
;
5382 /* Expand mode-line and scroll-bar events into two events:
5383 use posn as a fake prefix key. */
5386 if (t
+ 1 >= bufsize
)
5387 error ("key sequence too long");
5392 /* Zap the position in key, so we know that we've
5393 expanded it, and don't try to do so again. */
5394 POSN_BUFFER_POSN (EVENT_START (key
))
5395 = Fcons (posn
, Qnil
);
5399 else if (EQ (kind
, Qswitch_frame
))
5401 /* If we're at the beginning of a key sequence, and the caller
5402 says it's okay, go ahead and return this event. If we're
5403 in the midst of a key sequence, delay it until the end. */
5404 if (t
> 0 || !can_return_switch_frame
)
5406 delayed_switch_frame
= key
;
5410 else if (CONSP (XCONS (key
)->cdr
)
5411 && CONSP (EVENT_START (key
))
5412 && CONSP (XCONS (EVENT_START (key
))->cdr
))
5416 posn
= POSN_BUFFER_POSN (EVENT_START (key
));
5417 /* Handle menu-bar events:
5418 insert the dummy prefix event `menu-bar'. */
5419 if (EQ (posn
, Qmenu_bar
))
5421 if (t
+ 1 >= bufsize
)
5422 error ("key sequence too long");
5423 /* Run the Lucid hook. */
5424 if (!NILP (Vrun_hooks
))
5425 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
5426 /* If it has changed current-menubar from previous value,
5427 really recompute the menubar from the value. */
5428 if (! NILP (Vlucid_menu_bar_dirty_flag
))
5429 call0 (Qrecompute_lucid_menubar
);
5433 /* Zap the position in key, so we know that we've
5434 expanded it, and don't try to do so again. */
5435 POSN_BUFFER_POSN (EVENT_START (key
))
5436 = Fcons (posn
, Qnil
);
5439 goto replay_sequence
;
5441 else if (CONSP (posn
))
5443 /* We're looking at the second event of a
5444 sequence which we expanded before. Set
5445 last_real_key_start appropriately. */
5446 if (last_real_key_start
== t
&& t
> 0)
5447 last_real_key_start
= t
- 1;
5452 /* We have finally decided that KEY is something we might want
5454 first_binding
= (follow_key (key
,
5455 nmaps
- first_binding
,
5456 submaps
+ first_binding
,
5457 defs
+ first_binding
,
5458 submaps
+ first_binding
)
5461 /* If KEY wasn't bound, we'll try some fallbacks. */
5462 if (first_binding
>= nmaps
)
5466 head
= EVENT_HEAD (key
);
5467 if (EQ (head
, Vhelp_char
))
5469 read_key_sequence_cmd
= Vprefix_help_command
;
5471 last_nonmenu_event
= key
;
5472 /* The Microsoft C compiler can't handle the goto that
5480 Lisp_Object breakdown
;
5483 breakdown
= parse_modifiers (head
);
5484 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
5485 /* Attempt to reduce an unbound mouse event to a simpler
5486 event that is bound:
5487 Drags reduce to clicks.
5488 Double-clicks reduce to clicks.
5489 Triple-clicks reduce to double-clicks, then to clicks.
5490 Down-clicks are eliminated.
5491 Double-downs reduce to downs, then are eliminated.
5492 Triple-downs reduce to double-downs, then to downs,
5493 then are eliminated. */
5494 if (modifiers
& (down_modifier
| drag_modifier
5495 | double_modifier
| triple_modifier
))
5497 while (modifiers
& (down_modifier
| drag_modifier
5498 | double_modifier
| triple_modifier
))
5500 Lisp_Object new_head
, new_click
;
5501 if (modifiers
& triple_modifier
)
5502 modifiers
^= (double_modifier
| triple_modifier
);
5503 else if (modifiers
& double_modifier
)
5504 modifiers
&= ~double_modifier
;
5505 else if (modifiers
& drag_modifier
)
5506 modifiers
&= ~drag_modifier
;
5509 /* Dispose of this `down' event by simply jumping
5510 back to replay_key, to get another event.
5512 Note that if this event came from mock input,
5513 then just jumping back to replay_key will just
5514 hand it to us again. So we have to wipe out any
5517 We could delete keybuf[t] and shift everything
5518 after that to the left by one spot, but we'd also
5519 have to fix up any variable that points into
5520 keybuf, and shifting isn't really necessary
5523 Adding prefixes for non-textual mouse clicks
5524 creates two characters of mock input, and both
5525 must be thrown away. If we're only looking at
5526 the prefix now, we can just jump back to
5527 replay_key. On the other hand, if we've already
5528 processed the prefix, and now the actual click
5529 itself is giving us trouble, then we've lost the
5530 state of the keymaps we want to backtrack to, and
5531 we need to replay the whole sequence to rebuild
5534 Beyond that, only function key expansion could
5535 create more than two keys, but that should never
5536 generate mouse events, so it's okay to zero
5537 mock_input in that case too.
5539 Isn't this just the most wonderful code ever? */
5540 if (t
== last_real_key_start
)
5547 mock_input
= last_real_key_start
;
5548 goto replay_sequence
;
5553 = apply_modifiers (modifiers
, XCONS (breakdown
)->car
);
5555 = Fcons (new_head
, Fcons (EVENT_START (key
), Qnil
));
5557 /* Look for a binding for this new key. follow_key
5558 promises that it didn't munge submaps the
5559 last time we called it, since key was unbound. */
5561 = (follow_key (new_click
,
5562 nmaps
- local_first_binding
,
5563 submaps
+ local_first_binding
,
5564 defs
+ local_first_binding
,
5565 submaps
+ local_first_binding
)
5566 + local_first_binding
);
5568 /* If that click is bound, go for it. */
5569 if (first_binding
< nmaps
)
5574 /* Otherwise, we'll leave key set to the drag event. */
5581 /* Normally, last_nonmenu_event gets the previous key we read.
5582 But when a mouse popup menu is being used,
5583 we don't update last_nonmenu_event; it continues to hold the mouse
5584 event that preceded the first level of menu. */
5585 if (!used_mouse_menu
)
5586 last_nonmenu_event
= key
;
5588 /* If the sequence is unbound, see if we can hang a function key
5589 off the end of it. We only want to scan real keyboard input
5590 for function key sequences, so if mock_input says that we're
5591 re-reading old events, don't examine it. */
5592 if (first_binding
>= nmaps
5595 Lisp_Object fkey_next
;
5597 /* Continue scan from fkey_end until we find a bound suffix.
5598 If we fail, increment fkey_start
5599 and start fkey_end from there. */
5600 while (fkey_end
< t
)
5604 key
= keybuf
[fkey_end
++];
5605 /* Look up meta-characters by prefixing them
5606 with meta_prefix_char. I hate this. */
5607 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
5612 (access_keymap (fkey_map
, meta_prefix_char
, 1, 0)),
5614 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
5617 fkey_next
= fkey_map
;
5620 = get_keyelt (access_keymap (fkey_next
, key
, 1, 0));
5622 #if 0 /* I didn't turn this on, because it might cause trouble
5623 for the mapping of return into C-m and tab into C-i. */
5624 /* Optionally don't map function keys into other things.
5625 This enables the user to redefine kp- keys easily. */
5626 if (SYMBOLP (key
) && !NILP (Vinhibit_function_key_mapping
))
5630 /* If the function key map gives a function, not an
5631 array, then call the function with no args and use
5632 its value instead. */
5633 if (SYMBOLP (fkey_next
) && ! NILP (Ffboundp (fkey_next
))
5636 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5640 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
5641 fkey_next
= call1 (fkey_next
, prompt
);
5643 /* If the function returned something invalid,
5644 barf--don't ignore it.
5645 (To ignore it safely, we would need to gcpro a bunch of
5646 other variables.) */
5647 if (! (VECTORP (fkey_next
) || STRINGP (fkey_next
)))
5648 error ("Function in function-key-map returns invalid key sequence");
5651 function_key_possible
= ! NILP (fkey_next
);
5653 /* If keybuf[fkey_start..fkey_end] is bound in the
5654 function key map and it's a suffix of the current
5655 sequence (i.e. fkey_end == t), replace it with
5656 the binding and restart with fkey_start at the end. */
5657 if ((VECTORP (fkey_next
) || STRINGP (fkey_next
))
5660 int len
= XFASTINT (Flength (fkey_next
));
5662 t
= fkey_start
+ len
;
5664 error ("key sequence too long");
5666 if (VECTORP (fkey_next
))
5667 bcopy (XVECTOR (fkey_next
)->contents
,
5668 keybuf
+ fkey_start
,
5669 (t
- fkey_start
) * sizeof (keybuf
[0]));
5670 else if (STRINGP (fkey_next
))
5674 for (i
= 0; i
< len
; i
++)
5675 XSETFASTINT (keybuf
[fkey_start
+ i
],
5676 XSTRING (fkey_next
)->data
[i
]);
5680 fkey_start
= fkey_end
= t
;
5681 fkey_map
= Vfunction_key_map
;
5683 /* Do pass the results through key-translation-map. */
5684 keytran_start
= keytran_end
= 0;
5685 keytran_map
= Vkey_translation_map
;
5687 goto replay_sequence
;
5690 fkey_map
= get_keymap_1 (fkey_next
, 0, 1);
5692 /* If we no longer have a bound suffix, try a new positions for
5694 if (NILP (fkey_map
))
5696 fkey_end
= ++fkey_start
;
5697 fkey_map
= Vfunction_key_map
;
5698 function_key_possible
= 0;
5703 /* Look for this sequence in key-translation-map. */
5705 Lisp_Object keytran_next
;
5707 /* Scan from keytran_end until we find a bound suffix. */
5708 while (keytran_end
< t
)
5712 key
= keybuf
[keytran_end
++];
5713 /* Look up meta-characters by prefixing them
5714 with meta_prefix_char. I hate this. */
5715 if (INTEGERP (key
) && XINT (key
) & meta_modifier
)
5720 (access_keymap (keytran_map
, meta_prefix_char
, 1, 0)),
5722 XSETFASTINT (key
, XFASTINT (key
) & ~meta_modifier
);
5725 keytran_next
= keytran_map
;
5728 = get_keyelt (access_keymap (keytran_next
, key
, 1, 0));
5730 /* If the key translation map gives a function, not an
5731 array, then call the function with no args and use
5732 its value instead. */
5733 if (SYMBOLP (keytran_next
) && ! NILP (Ffboundp (keytran_next
))
5734 && keytran_end
== t
)
5736 struct gcpro gcpro1
, gcpro2
, gcpro3
;
5740 GCPRO3 (fkey_map
, keytran_map
, delayed_switch_frame
);
5741 keytran_next
= call1 (keytran_next
, prompt
);
5743 /* If the function returned something invalid,
5744 barf--don't ignore it.
5745 (To ignore it safely, we would need to gcpro a bunch of
5746 other variables.) */
5747 if (! (VECTORP (keytran_next
) || STRINGP (keytran_next
)))
5748 error ("Function in key-translation-map returns invalid key sequence");
5751 key_translation_possible
= ! NILP (keytran_next
);
5753 /* If keybuf[keytran_start..keytran_end] is bound in the
5754 key translation map and it's a suffix of the current
5755 sequence (i.e. keytran_end == t), replace it with
5756 the binding and restart with keytran_start at the end. */
5757 if ((VECTORP (keytran_next
) || STRINGP (keytran_next
))
5758 && keytran_end
== t
)
5760 int len
= XFASTINT (Flength (keytran_next
));
5762 t
= keytran_start
+ len
;
5764 error ("key sequence too long");
5766 if (VECTORP (keytran_next
))
5767 bcopy (XVECTOR (keytran_next
)->contents
,
5768 keybuf
+ keytran_start
,
5769 (t
- keytran_start
) * sizeof (keybuf
[0]));
5770 else if (STRINGP (keytran_next
))
5774 for (i
= 0; i
< len
; i
++)
5775 XSETFASTINT (keybuf
[keytran_start
+ i
],
5776 XSTRING (keytran_next
)->data
[i
]);
5780 keytran_start
= keytran_end
= t
;
5781 keytran_map
= Vkey_translation_map
;
5783 /* Don't pass the results of key-translation-map
5784 through function-key-map. */
5785 fkey_start
= fkey_end
= t
;
5786 fkey_map
= Vkey_translation_map
;
5788 goto replay_sequence
;
5791 keytran_map
= get_keymap_1 (keytran_next
, 0, 1);
5793 /* If we no longer have a bound suffix, try a new positions for
5795 if (NILP (keytran_map
))
5797 keytran_end
= ++keytran_start
;
5798 keytran_map
= Vkey_translation_map
;
5799 key_translation_possible
= 0;
5804 /* If KEY is not defined in any of the keymaps,
5805 and cannot be part of a function key or translation,
5806 and is an upper case letter
5807 use the corresponding lower-case letter instead. */
5808 if (first_binding
== nmaps
&& ! function_key_possible
5809 && ! key_translation_possible
5811 && ((((XINT (key
) & 0x3ffff)
5812 < XSTRING (current_buffer
->downcase_table
)->size
)
5813 && UPPERCASEP (XINT (key
) & 0x3ffff))
5814 || (XINT (key
) & shift_modifier
)))
5816 original_uppercase
= key
;
5817 original_uppercase_position
= t
- 1;
5819 if (XINT (key
) & shift_modifier
)
5820 XSETINT (key
, XINT (key
) & ~shift_modifier
);
5822 XSETINT (key
, (DOWNCASE (XINT (key
) & 0x3ffff)
5823 | (XINT (key
) & ~0x3ffff)));
5825 keybuf
[t
- 1] = key
;
5827 goto replay_sequence
;
5829 /* If KEY is not defined in any of the keymaps,
5830 and cannot be part of a function key or translation,
5831 and is a shifted function key,
5832 use the corresponding unshifted function key instead. */
5833 if (first_binding
== nmaps
&& ! function_key_possible
5834 && ! key_translation_possible
5837 Lisp_Object breakdown
;
5840 original_uppercase
= key
;
5841 original_uppercase_position
= t
- 1;
5843 breakdown
= parse_modifiers (key
);
5844 modifiers
= XINT (XCONS (XCONS (breakdown
)->cdr
)->car
);
5845 if (modifiers
& shift_modifier
)
5847 modifiers
&= ~shift_modifier
;
5848 key
= apply_modifiers (modifiers
,
5849 XCONS (breakdown
)->car
);
5851 keybuf
[t
- 1] = key
;
5853 goto replay_sequence
;
5859 read_key_sequence_cmd
= (first_binding
< nmaps
5860 ? defs
[first_binding
]
5863 unread_switch_frame
= delayed_switch_frame
;
5864 unbind_to (count
, Qnil
);
5866 if (dont_downcase_last
&& t
- 1 == original_uppercase_position
)
5867 keybuf
[t
- 1] = original_uppercase
;
5869 /* Occasionally we fabricate events, perhaps by expanding something
5870 according to function-key-map, or by adding a prefix symbol to a
5871 mouse click in the scroll bar or modeline. In this cases, return
5872 the entire generated key sequence, even if we hit an unbound
5873 prefix or a definition before the end. This means that you will
5874 be able to push back the event properly, and also means that
5875 read-key-sequence will always return a logical unit.
5878 for (; t
< mock_input
; t
++)
5880 if (echo_keystrokes
)
5881 echo_char (keybuf
[t
]);
5882 add_command_key (keybuf
[t
]);
5888 #if 0 /* This doc string is too long for some compilers.
5889 This commented-out definition serves for DOC. */
5890 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
5891 "Read a sequence of keystrokes and return as a string or vector.\n\
5892 The sequence is sufficient to specify a non-prefix command in the\n\
5893 current local and global maps.\n\
5895 First arg PROMPT is a prompt string. If nil, do not prompt specially.\n\
5896 Second (optional) arg CONTINUE-ECHO, if non-nil, means this key echos\n\
5897 as a continuation of the previous key.\n\
5899 The third (optional) arg DONT-DOWNCASE-LAST, if non-nil, means do not\n\
5900 convert the last event to lower case. (Normally any upper case event\n\
5901 is converted to lower case if the original event is undefined and the lower\n\
5902 case equivalent is defined.) A non-nil value is appropriate for reading\n\
5903 a key sequence to be defined.\n\
5905 A C-g typed while in this function is treated like any other character,\n\
5906 and `quit-flag' is not set.\n\
5908 If the key sequence starts with a mouse click, then the sequence is read\n\
5909 using the keymaps of the buffer of the window clicked in, not the buffer\n\
5910 of the selected window as normal.\n\
5912 `read-key-sequence' drops unbound button-down events, since you normally\n\
5913 only care about the click or drag events which follow them. If a drag\n\
5914 or multi-click event is unbound, but the corresponding click event would\n\
5915 be bound, `read-key-sequence' turns the event into a click event at the\n\
5916 drag's starting position. This means that you don't have to distinguish\n\
5917 between click and drag, double, or triple events unless you want to.\n\
5919 `read-key-sequence' prefixes mouse events on mode lines, the vertical\n\
5920 lines separating windows, and scroll bars with imaginary keys\n\
5921 `mode-line', `vertical-line', and `vertical-scroll-bar'.\n\
5923 Optional fourth argument CAN-RETURN-SWITCH-FRAME non-nil means that this\n\
5924 function will process a switch-frame event if the user switches frames\n\
5925 before typing anything. If the user switches frames in the middle of a\n\
5926 key sequence, or at the start of the sequence but CAN-RETURN-SWITCH-FRAME\n\
5927 is nil, then the event will be put off until after the current key sequence.\n\
5929 `read-key-sequence' checks `function-key-map' for function key\n\
5930 sequences, where they wouldn't conflict with ordinary bindings. See\n\
5931 `function-key-map' for more details.")
5932 (prompt
, continue_echo
)
5935 DEFUN ("read-key-sequence", Fread_key_sequence
, Sread_key_sequence
, 1, 4, 0,
5937 (prompt
, continue_echo
, dont_downcase_last
, can_return_switch_frame
)
5938 Lisp_Object prompt
, continue_echo
, dont_downcase_last
;
5939 Lisp_Object can_return_switch_frame
;
5941 Lisp_Object keybuf
[30];
5943 struct gcpro gcpro1
, gcpro2
;
5946 CHECK_STRING (prompt
, 0);
5949 bzero (keybuf
, sizeof keybuf
);
5951 gcpro1
.nvars
= (sizeof keybuf
/sizeof (keybuf
[0]));
5953 if (NILP (continue_echo
))
5954 this_command_key_count
= 0;
5956 i
= read_key_sequence (keybuf
, (sizeof keybuf
/sizeof (keybuf
[0])),
5957 prompt
, ! NILP (dont_downcase_last
),
5958 ! NILP (can_return_switch_frame
));
5966 return make_event_array (i
, keybuf
);
5969 DEFUN ("command-execute", Fcommand_execute
, Scommand_execute
, 1, 2, 0,
5970 "Execute CMD as an editor command.\n\
5971 CMD must be a symbol that satisfies the `commandp' predicate.\n\
5972 Optional second arg RECORD-FLAG non-nil\n\
5973 means unconditionally put this command in `command-history'.\n\
5974 Otherwise, that is done only if an arg is read using the minibuffer.")
5976 Lisp_Object cmd
, record
;
5978 register Lisp_Object final
;
5979 register Lisp_Object tem
;
5980 Lisp_Object prefixarg
;
5981 struct backtrace backtrace
;
5982 extern int debug_on_next_call
;
5984 prefixarg
= Vprefix_arg
;
5985 clear_prefix_arg ();
5986 Vcurrent_prefix_arg
= prefixarg
;
5987 debug_on_next_call
= 0;
5991 tem
= Fget (cmd
, Qdisabled
);
5992 if (!NILP (tem
) && !NILP (Vrun_hooks
))
5993 return call1 (Vrun_hooks
, Qdisabled_command_hook
);
5998 final
= Findirect_function (cmd
);
6000 if (CONSP (final
) && (tem
= Fcar (final
), EQ (tem
, Qautoload
)))
6001 do_autoload (final
, cmd
);
6006 if (STRINGP (final
) || VECTORP (final
))
6008 /* If requested, place the macro in the command history. For
6009 other sorts of commands, call-interactively takes care of
6013 = Fcons (Fcons (Qexecute_kbd_macro
,
6014 Fcons (final
, Fcons (prefixarg
, Qnil
))),
6017 return Fexecute_kbd_macro (final
, prefixarg
);
6019 if (CONSP (final
) || SUBRP (final
) || COMPILEDP (final
))
6021 backtrace
.next
= backtrace_list
;
6022 backtrace_list
= &backtrace
;
6023 backtrace
.function
= &Qcall_interactively
;
6024 backtrace
.args
= &cmd
;
6025 backtrace
.nargs
= 1;
6026 backtrace
.evalargs
= 0;
6028 tem
= Fcall_interactively (cmd
, record
);
6030 backtrace_list
= backtrace
.next
;
6036 DEFUN ("execute-extended-command", Fexecute_extended_command
, Sexecute_extended_command
,
6038 "Read function name, then read its arguments and call it.")
6040 Lisp_Object prefixarg
;
6042 Lisp_Object function
;
6044 Lisp_Object saved_keys
;
6045 struct gcpro gcpro1
;
6047 saved_keys
= Fvector (this_command_key_count
,
6048 XVECTOR (this_command_keys
)->contents
);
6050 GCPRO1 (saved_keys
);
6052 if (EQ (prefixarg
, Qminus
))
6054 else if (CONSP (prefixarg
) && XINT (XCONS (prefixarg
)->car
) == 4)
6055 strcpy (buf
, "C-u ");
6056 else if (CONSP (prefixarg
) && INTEGERP (XCONS (prefixarg
)->car
))
6057 sprintf (buf
, "%d ", XINT (XCONS (prefixarg
)->car
));
6058 else if (INTEGERP (prefixarg
))
6059 sprintf (buf
, "%d ", XINT (prefixarg
));
6061 /* This isn't strictly correct if execute-extended-command
6062 is bound to anything else. Perhaps it should use
6063 this_command_keys? */
6064 strcat (buf
, "M-x ");
6066 /* Prompt with buf, and then read a string, completing from and
6067 restricting to the set of all defined commands. Don't provide
6068 any initial input. Save the command read on the extended-command
6070 function
= Fcompleting_read (build_string (buf
),
6071 Vobarray
, Qcommandp
,
6072 Qt
, Qnil
, Qextended_command_history
);
6074 /* Set this_command_keys to the concatenation of saved_keys and
6075 function, followed by a RET. */
6077 struct Lisp_String
*str
;
6082 this_command_key_count
= 0;
6084 keys
= XVECTOR (saved_keys
)->contents
;
6085 for (i
= 0; i
< XVECTOR (saved_keys
)->size
; i
++)
6086 add_command_key (keys
[i
]);
6088 str
= XSTRING (function
);
6089 for (i
= 0; i
< str
->size
; i
++)
6091 XSETFASTINT (tem
, str
->data
[i
]);
6092 add_command_key (tem
);
6095 XSETFASTINT (tem
, '\015');
6096 add_command_key (tem
);
6101 function
= Fintern (function
, Qnil
);
6102 Vprefix_arg
= prefixarg
;
6103 this_command
= function
;
6105 return Fcommand_execute (function
, Qt
);
6109 detect_input_pending ()
6112 get_input_pending (&input_pending
);
6114 return input_pending
;
6117 /* This is called in some cases before a possible quit.
6118 It cases the next call to detect_input_pending to recompute input_pending.
6119 So calling this function unnecessarily can't do any harm. */
6120 clear_input_pending ()
6125 DEFUN ("input-pending-p", Finput_pending_p
, Sinput_pending_p
, 0, 0, 0,
6126 "T if command input is currently available with no waiting.\n\
6127 Actually, the value is nil only if we can be sure that no input is available.")
6130 if (!NILP (Vunread_command_events
) || unread_command_char
!= -1)
6133 return detect_input_pending () ? Qt
: Qnil
;
6136 DEFUN ("recent-keys", Frecent_keys
, Srecent_keys
, 0, 0, 0,
6137 "Return vector of last 100 events, not counting those from keyboard macros.")
6140 Lisp_Object
*keys
= XVECTOR (recent_keys
)->contents
;
6143 if (total_keys
< NUM_RECENT_KEYS
)
6144 return Fvector (total_keys
, keys
);
6147 val
= Fvector (NUM_RECENT_KEYS
, keys
);
6148 bcopy (keys
+ recent_keys_index
,
6149 XVECTOR (val
)->contents
,
6150 (NUM_RECENT_KEYS
- recent_keys_index
) * sizeof (Lisp_Object
));
6152 XVECTOR (val
)->contents
+ NUM_RECENT_KEYS
- recent_keys_index
,
6153 recent_keys_index
* sizeof (Lisp_Object
));
6158 DEFUN ("this-command-keys", Fthis_command_keys
, Sthis_command_keys
, 0, 0, 0,
6159 "Return the key sequence that invoked this command.\n\
6160 The value is a string or a vector.")
6163 return make_event_array (this_command_key_count
,
6164 XVECTOR (this_command_keys
)->contents
);
6167 DEFUN ("recursion-depth", Frecursion_depth
, Srecursion_depth
, 0, 0, 0,
6168 "Return the current depth in recursive edits.")
6172 XSETFASTINT (temp
, command_loop_level
+ minibuf_level
);
6176 DEFUN ("open-dribble-file", Fopen_dribble_file
, Sopen_dribble_file
, 1, 1,
6177 "FOpen dribble file: ",
6178 "Start writing all keyboard characters to a dribble file called FILE.\n\
6179 If FILE is nil, close any open dribble file.")
6193 file
= Fexpand_file_name (file
, Qnil
);
6194 dribble
= fopen (XSTRING (file
)->data
, "w");
6199 DEFUN ("discard-input", Fdiscard_input
, Sdiscard_input
, 0, 0, 0,
6200 "Discard the contents of the terminal input buffer.\n\
6201 Also cancel any kbd macro being defined.")
6204 current_kboard
->defining_kbd_macro
= Qnil
;
6205 update_mode_lines
++;
6207 Vunread_command_events
= Qnil
;
6208 unread_command_char
= -1;
6210 discard_tty_input ();
6212 /* Without the cast, GCC complains that this assignment loses the
6213 volatile qualifier of kbd_store_ptr. Is there anything wrong
6215 kbd_fetch_ptr
= (struct input_event
*) kbd_store_ptr
;
6216 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
6222 DEFUN ("suspend-emacs", Fsuspend_emacs
, Ssuspend_emacs
, 0, 1, "",
6223 "Stop Emacs and return to superior process. You can resume later.\n\
6224 If `cannot-suspend' is non-nil, or if the system doesn't support job\n\
6225 control, run a subshell instead.\n\n\
6226 If optional arg STUFFSTRING is non-nil, its characters are stuffed\n\
6227 to be read as terminal input by Emacs's parent, after suspension.\n\
6229 Before suspending, run the normal hook `suspend-hook'.\n\
6230 After resumption run the normal hook `suspend-resume-hook'.\n\
6232 Some operating systems cannot stop the Emacs process and resume it later.\n\
6233 On such systems, Emacs starts a subshell instead of suspending.")
6235 Lisp_Object stuffstring
;
6238 int count
= specpdl_ptr
- specpdl
;
6239 int old_height
, old_width
;
6241 struct gcpro gcpro1
, gcpro2
;
6242 extern init_sys_modes ();
6244 if (!NILP (stuffstring
))
6245 CHECK_STRING (stuffstring
, 0);
6247 /* Run the functions in suspend-hook. */
6248 if (!NILP (Vrun_hooks
))
6249 call1 (Vrun_hooks
, intern ("suspend-hook"));
6251 GCPRO1 (stuffstring
);
6252 get_frame_size (&old_width
, &old_height
);
6254 /* sys_suspend can get an error if it tries to fork a subshell
6255 and the system resources aren't available for that. */
6256 record_unwind_protect (init_sys_modes
, 0);
6257 stuff_buffered_input (stuffstring
);
6262 unbind_to (count
, Qnil
);
6264 /* Check if terminal/window size has changed.
6265 Note that this is not useful when we are running directly
6266 with a window system; but suspend should be disabled in that case. */
6267 get_frame_size (&width
, &height
);
6268 if (width
!= old_width
|| height
!= old_height
)
6269 change_frame_size (selected_frame
, height
, width
, 0, 0);
6271 /* Run suspend-resume-hook. */
6272 if (!NILP (Vrun_hooks
))
6273 call1 (Vrun_hooks
, intern ("suspend-resume-hook"));
6279 /* If STUFFSTRING is a string, stuff its contents as pending terminal input.
6280 Then in any case stuff anything Emacs has read ahead and not used. */
6282 stuff_buffered_input (stuffstring
)
6283 Lisp_Object stuffstring
;
6285 /* stuff_char works only in BSD, versions 4.2 and up. */
6288 register unsigned char *p
;
6290 if (STRINGP (stuffstring
))
6294 p
= XSTRING (stuffstring
)->data
;
6295 count
= XSTRING (stuffstring
)->size
;
6300 /* Anything we have read ahead, put back for the shell to read. */
6301 /* ?? What should this do when we have multiple keyboards??
6302 Should we ignore anything that was typed in at the "wrong" kboard? */
6303 for (; kbd_fetch_ptr
!= kbd_store_ptr
; kbd_fetch_ptr
++)
6305 if (kbd_fetch_ptr
== kbd_buffer
+ KBD_BUFFER_SIZE
)
6306 kbd_fetch_ptr
= kbd_buffer
;
6307 if (kbd_fetch_ptr
->kind
== ascii_keystroke
)
6308 stuff_char (kbd_fetch_ptr
->code
);
6309 kbd_fetch_ptr
->kind
= no_event
;
6310 (XVECTOR (kbd_buffer_frame_or_window
)->contents
[kbd_fetch_ptr
6316 #endif /* BSD and not BSD4_1 */
6319 set_waiting_for_input (time_to_clear
)
6320 EMACS_TIME
*time_to_clear
;
6322 input_available_clear_time
= time_to_clear
;
6324 /* Tell interrupt_signal to throw back to read_char, */
6325 waiting_for_input
= 1;
6327 /* If interrupt_signal was called before and buffered a C-g,
6328 make it run again now, to avoid timing error. */
6329 if (!NILP (Vquit_flag
))
6330 quit_throw_to_read_char ();
6333 clear_waiting_for_input ()
6335 /* Tell interrupt_signal not to throw back to read_char, */
6336 waiting_for_input
= 0;
6337 input_available_clear_time
= 0;
6340 /* This routine is called at interrupt level in response to C-G.
6341 If interrupt_input, this is the handler for SIGINT.
6342 Otherwise, it is called from kbd_buffer_store_event,
6343 in handling SIGIO or SIGTINT.
6345 If `waiting_for_input' is non zero, then unless `echoing' is nonzero,
6346 immediately throw back to read_char.
6348 Otherwise it sets the Lisp variable quit-flag not-nil.
6349 This causes eval to throw, when it gets a chance.
6350 If quit-flag is already non-nil, it stops the job right away. */
6353 interrupt_signal (signalnum
) /* If we don't have an argument, */
6354 int signalnum
; /* some compilers complain in signal calls. */
6357 /* Must preserve main program's value of errno. */
6358 int old_errno
= errno
;
6361 if (!read_socket_hook
&& NILP (Vwindow_system
))
6363 /* USG systems forget handlers when they are used;
6364 must reestablish each time */
6365 signal (SIGINT
, interrupt_signal
);
6366 signal (SIGQUIT
, interrupt_signal
);
6372 if (!NILP (Vquit_flag
) && FRAME_TERMCAP_P (selected_frame
))
6377 #ifdef SIGTSTP /* Support possible in later USG versions */
6379 * On systems which can suspend the current process and return to the original
6380 * shell, this command causes the user to end up back at the shell.
6381 * The "Auto-save" and "Abort" questions are not asked until
6382 * the user elects to return to emacs, at which point he can save the current
6383 * job and either dump core or continue.
6388 if (sys_suspend () == -1)
6390 printf ("Not running as a subprocess;\n");
6391 printf ("you can continue or abort.\n");
6394 /* Perhaps should really fork an inferior shell?
6395 But that would not provide any way to get back
6396 to the original shell, ever. */
6397 printf ("No support for stopping a process on this operating system;\n");
6398 printf ("you can continue or abort.\n");
6399 #endif /* not VMS */
6400 #endif /* not SIGTSTP */
6402 /* We must remain inside the screen area when the internal terminal
6403 is used. Note that [Enter] is not echoed by dos. */
6406 printf ("Auto-save? (y or n) ");
6408 if (((c
= getchar ()) & ~040) == 'Y')
6410 Fdo_auto_save (Qt
, Qnil
);
6412 printf ("\r\nAuto-save done");
6413 #else /* not MSDOS */
6414 printf ("Auto-save done\n");
6415 #endif /* not MSDOS */
6417 while (c
!= '\n') c
= getchar ();
6419 printf ("\r\nAbort? (y or n) ");
6420 #else /* not MSDOS */
6422 printf ("Abort (and enter debugger)? (y or n) ");
6424 printf ("Abort (and dump core)? (y or n) ");
6425 #endif /* not VMS */
6426 #endif /* not MSDOS */
6428 if (((c
= getchar ()) & ~040) == 'Y')
6430 while (c
!= '\n') c
= getchar ();
6432 printf ("\r\nContinuing...\r\n");
6433 #else /* not MSDOS */
6434 printf ("Continuing...\n");
6435 #endif /* not MSDOS */
6441 /* If executing a function that wants to be interrupted out of
6442 and the user has not deferred quitting by binding `inhibit-quit'
6443 then quit right away. */
6444 if (immediate_quit
&& NILP (Vinhibit_quit
))
6448 Fsignal (Qquit
, Qnil
);
6451 /* Else request quit when it's safe */
6455 if (waiting_for_input
&& !echoing
)
6456 quit_throw_to_read_char ();
6461 /* Handle a C-g by making read_char return C-g. */
6463 quit_throw_to_read_char ()
6465 quit_error_check ();
6467 /* Prevent another signal from doing this before we finish. */
6468 clear_waiting_for_input ();
6471 Vunread_command_events
= Qnil
;
6472 unread_command_char
= -1;
6474 #ifdef POLL_FOR_INPUT
6475 /* May be > 1 if in recursive minibuffer. */
6476 if (poll_suppress_count
== 0)
6480 if (FRAMEP (internal_last_event_frame
)
6481 && XFRAME (internal_last_event_frame
) != selected_frame
)
6482 Fhandle_switch_frame (make_lispy_switch_frame (internal_last_event_frame
));
6485 _longjmp (getcjmp
, 1);
6488 DEFUN ("set-input-mode", Fset_input_mode
, Sset_input_mode
, 3, 4, 0,
6489 "Set mode of reading keyboard input.\n\
6490 First arg INTERRUPT non-nil means use input interrupts;\n\
6491 nil means use CBREAK mode.\n\
6492 Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal\n\
6493 (no effect except in CBREAK mode).\n\
6494 Third arg META t means accept 8-bit input (for a Meta key).\n\
6495 META nil means ignore the top bit, on the assumption it is parity.\n\
6496 Otherwise, accept 8-bit input and don't use the top bit for Meta.\n\
6497 Optional fourth arg QUIT if non-nil specifies character to use for quitting.\n\
6498 See also `current-input-mode'.")
6499 (interrupt
, flow
, meta
, quit
)
6500 Lisp_Object interrupt
, flow
, meta
, quit
;
6503 && (!INTEGERP (quit
) || XINT (quit
) < 0 || XINT (quit
) > 0400))
6504 error ("set-input-mode: QUIT must be an ASCII character");
6506 #ifdef POLL_FOR_INPUT
6512 /* Note SIGIO has been undef'd if FIONREAD is missing. */
6513 #ifdef NO_SOCK_SIGIO
6514 if (read_socket_hook
)
6515 interrupt_input
= 0; /* No interrupts if reading from a socket. */
6517 #endif /* NO_SOCK_SIGIO */
6518 interrupt_input
= !NILP (interrupt
);
6519 #else /* not SIGIO */
6520 interrupt_input
= 0;
6521 #endif /* not SIGIO */
6522 /* Our VMS input only works by interrupts, as of now. */
6524 interrupt_input
= 1;
6526 flow_control
= !NILP (flow
);
6529 else if (EQ (meta
, Qt
))
6534 /* Don't let this value be out of range. */
6535 quit_char
= XINT (quit
) & (meta_key
? 0377 : 0177);
6539 #ifdef POLL_FOR_INPUT
6540 poll_suppress_count
= 1;
6546 DEFUN ("current-input-mode", Fcurrent_input_mode
, Scurrent_input_mode
, 0, 0, 0,
6547 "Return information about the way Emacs currently reads keyboard input.\n\
6548 The value is a list of the form (INTERRUPT FLOW META QUIT), where\n\
6549 INTERRUPT is non-nil if Emacs is using interrupt-driven input; if\n\
6550 nil, Emacs is using CBREAK mode.\n\
6551 FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the\n\
6552 terminal; this does not apply if Emacs uses interrupt-driven input.\n\
6553 META is t if accepting 8-bit input with 8th bit as Meta flag.\n\
6554 META nil means ignoring the top bit, on the assumption it is parity.\n\
6555 META is neither t nor nil if accepting 8-bit input and using\n\
6556 all 8 bits as the character code.\n\
6557 QUIT is the character Emacs currently uses to quit.\n\
6558 The elements of this list correspond to the arguments of\n\
6564 val
[0] = interrupt_input
? Qt
: Qnil
;
6565 val
[1] = flow_control
? Qt
: Qnil
;
6566 val
[2] = meta_key
== 2 ? make_number (0) : meta_key
== 1 ? Qt
: Qnil
;
6567 XSETFASTINT (val
[3], quit_char
);
6569 return Flist (sizeof (val
) / sizeof (val
[0]), val
);
6574 * Set up a new kboard object with reasonable initial values.
6580 kb
->prefix_factor
= Qnil
;
6581 kb
->prefix_value
= Qnil
;
6582 kb
->prefix_sign
= 1;
6583 kb
->prefix_partial
= 0;
6584 kb
->kbd_queue
= Qnil
;
6585 kb
->kbd_queue_has_data
= 0;
6586 kb
->immediate_echo
= 0;
6587 kb
->echoptr
= kb
->echobuf
;
6588 kb
->echo_after_prompt
= -1;
6589 kb
->kbd_macro_buffer
= 0;
6590 kb
->kbd_macro_bufsize
= 0;
6591 kb
->defining_kbd_macro
= Qnil
;
6592 kb
->Vlast_kbd_macro
= Qnil
;
6593 kb
->reference_count
= 0;
6594 kb
->Vsystem_key_alist
= Qnil
;
6598 * Destroy the contents of a kboard object, but not the object itself.
6599 * We use this just before deleteing it, or if we're going to initialize
6606 if (kb
->kbd_macro_buffer
)
6607 xfree (kb
->kbd_macro_buffer
);
6616 for (kbp
= &all_kboards
; *kbp
!= kb
; kbp
= &(*kbp
)->next_kboard
)
6619 *kbp
= kb
->next_kboard
;
6627 /* This is correct before outermost invocation of the editor loop */
6628 command_loop_level
= -1;
6630 quit_char
= Ctl ('g');
6631 Vunread_command_events
= Qnil
;
6632 unread_command_char
= -1;
6634 recent_keys_index
= 0;
6635 kbd_fetch_ptr
= kbd_buffer
;
6636 kbd_store_ptr
= kbd_buffer
;
6637 kbd_buffer_frame_or_window
6638 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
6640 do_mouse_tracking
= Qnil
;
6645 /* This means that command_loop_1 won't try to select anything the first
6647 internal_last_event_frame
= Qnil
;
6648 Vlast_event_frame
= internal_last_event_frame
;
6652 current_kboard
= initial_kboard
;
6654 wipe_kboard (current_kboard
);
6655 init_kboard (current_kboard
);
6658 Ffillarray (kbd_buffer_frame_or_window
, Qnil
);
6660 kbd_buffer_frame_or_window
6661 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
6662 if (!noninteractive
&& !read_socket_hook
&& NILP (Vwindow_system
))
6664 signal (SIGINT
, interrupt_signal
);
6665 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
6666 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
6667 SIGQUIT and we can't tell which one it will give us. */
6668 signal (SIGQUIT
, interrupt_signal
);
6669 #endif /* HAVE_TERMIO */
6671 /* Note SIGIO has been undef'd if FIONREAD is missing. */
6673 if (!noninteractive
)
6674 signal (SIGIO
, input_available_signal
);
6677 /* Use interrupt input by default, if it works and noninterrupt input
6678 has deficiencies. */
6680 #ifdef INTERRUPT_INPUT
6681 interrupt_input
= 1;
6683 interrupt_input
= 0;
6686 /* Our VMS input only works by interrupts, as of now. */
6688 interrupt_input
= 1;
6694 if (keyboard_init_hook
)
6695 (*keyboard_init_hook
) ();
6697 #ifdef POLL_FOR_INPUT
6698 poll_suppress_count
= 1;
6703 /* This type's only use is in syms_of_keyboard, to initialize the
6704 event header symbols and put properties on them. */
6711 struct event_head head_table
[] = {
6712 &Qmouse_movement
, "mouse-movement", &Qmouse_movement
,
6713 &Qscroll_bar_movement
, "scroll-bar-movement", &Qmouse_movement
,
6714 &Qswitch_frame
, "switch-frame", &Qswitch_frame
,
6715 &Qdelete_frame
, "delete-frame", &Qdelete_frame
,
6716 &Qiconify_frame
, "iconify-frame", &Qiconify_frame
,
6717 &Qmake_frame_visible
, "make-frame-visible", &Qmake_frame_visible
,
6722 Qdisabled_command_hook
= intern ("disabled-command-hook");
6723 staticpro (&Qdisabled_command_hook
);
6725 Qself_insert_command
= intern ("self-insert-command");
6726 staticpro (&Qself_insert_command
);
6728 Qforward_char
= intern ("forward-char");
6729 staticpro (&Qforward_char
);
6731 Qbackward_char
= intern ("backward-char");
6732 staticpro (&Qbackward_char
);
6734 Qdisabled
= intern ("disabled");
6735 staticpro (&Qdisabled
);
6737 Qundefined
= intern ("undefined");
6738 staticpro (&Qundefined
);
6740 Qdigit_argument
= intern ("digit-argument");
6741 staticpro (&Qdigit_argument
);
6743 Qnegative_argument
= intern ("negative-argument");
6744 staticpro (&Qnegative_argument
);
6746 Qpre_command_hook
= intern ("pre-command-hook");
6747 staticpro (&Qpre_command_hook
);
6749 Qpost_command_hook
= intern ("post-command-hook");
6750 staticpro (&Qpost_command_hook
);
6752 Qdeferred_action_function
= intern ("deferred-action-function");
6753 staticpro (&Qdeferred_action_function
);
6755 Qcommand_hook_internal
= intern ("command-hook-internal");
6756 staticpro (&Qcommand_hook_internal
);
6758 Qfunction_key
= intern ("function-key");
6759 staticpro (&Qfunction_key
);
6760 Qmouse_click
= intern ("mouse-click");
6761 staticpro (&Qmouse_click
);
6763 Qmenu_enable
= intern ("menu-enable");
6764 staticpro (&Qmenu_enable
);
6766 Qmode_line
= intern ("mode-line");
6767 staticpro (&Qmode_line
);
6768 Qvertical_line
= intern ("vertical-line");
6769 staticpro (&Qvertical_line
);
6770 Qvertical_scroll_bar
= intern ("vertical-scroll-bar");
6771 staticpro (&Qvertical_scroll_bar
);
6772 Qmenu_bar
= intern ("menu-bar");
6773 staticpro (&Qmenu_bar
);
6775 Qabove_handle
= intern ("above-handle");
6776 staticpro (&Qabove_handle
);
6777 Qhandle
= intern ("handle");
6778 staticpro (&Qhandle
);
6779 Qbelow_handle
= intern ("below-handle");
6780 staticpro (&Qbelow_handle
);
6782 Qevent_kind
= intern ("event-kind");
6783 staticpro (&Qevent_kind
);
6784 Qevent_symbol_elements
= intern ("event-symbol-elements");
6785 staticpro (&Qevent_symbol_elements
);
6786 Qevent_symbol_element_mask
= intern ("event-symbol-element-mask");
6787 staticpro (&Qevent_symbol_element_mask
);
6788 Qmodifier_cache
= intern ("modifier-cache");
6789 staticpro (&Qmodifier_cache
);
6791 Qrecompute_lucid_menubar
= intern ("recompute-lucid-menubar");
6792 staticpro (&Qrecompute_lucid_menubar
);
6793 Qactivate_menubar_hook
= intern ("activate-menubar-hook");
6794 staticpro (&Qactivate_menubar_hook
);
6796 Qpolling_period
= intern ("polling-period");
6797 staticpro (&Qpolling_period
);
6800 struct event_head
*p
;
6802 for (p
= head_table
;
6803 p
< head_table
+ (sizeof (head_table
) / sizeof (head_table
[0]));
6806 *p
->var
= intern (p
->name
);
6808 Fput (*p
->var
, Qevent_kind
, *p
->kind
);
6809 Fput (*p
->var
, Qevent_symbol_elements
, Fcons (*p
->var
, Qnil
));
6813 button_down_location
= Fmake_vector (make_number (NUM_MOUSE_BUTTONS
), Qnil
);
6814 staticpro (&button_down_location
);
6818 int len
= sizeof (modifier_names
) / sizeof (modifier_names
[0]);
6820 modifier_symbols
= Fmake_vector (make_number (len
), Qnil
);
6821 for (i
= 0; i
< len
; i
++)
6822 if (modifier_names
[i
])
6823 XVECTOR (modifier_symbols
)->contents
[i
] = intern (modifier_names
[i
]);
6824 staticpro (&modifier_symbols
);
6827 recent_keys
= Fmake_vector (make_number (NUM_RECENT_KEYS
), Qnil
);
6828 staticpro (&recent_keys
);
6830 this_command_keys
= Fmake_vector (make_number (40), Qnil
);
6831 staticpro (&this_command_keys
);
6833 Qextended_command_history
= intern ("extended-command-history");
6834 Fset (Qextended_command_history
, Qnil
);
6835 staticpro (&Qextended_command_history
);
6837 kbd_buffer_frame_or_window
6838 = Fmake_vector (make_number (KBD_BUFFER_SIZE
), Qnil
);
6839 staticpro (&kbd_buffer_frame_or_window
);
6841 accent_key_syms
= Qnil
;
6842 staticpro (&accent_key_syms
);
6844 func_key_syms
= Qnil
;
6845 staticpro (&func_key_syms
);
6847 system_key_syms
= Qnil
;
6848 staticpro (&system_key_syms
);
6851 staticpro (&mouse_syms
);
6853 unread_switch_frame
= Qnil
;
6854 staticpro (&unread_switch_frame
);
6856 defsubr (&Sread_key_sequence
);
6857 defsubr (&Srecursive_edit
);
6859 defsubr (&Strack_mouse
);
6861 defsubr (&Sinput_pending_p
);
6862 defsubr (&Scommand_execute
);
6863 defsubr (&Srecent_keys
);
6864 defsubr (&Sthis_command_keys
);
6865 defsubr (&Ssuspend_emacs
);
6866 defsubr (&Sabort_recursive_edit
);
6867 defsubr (&Sexit_recursive_edit
);
6868 defsubr (&Srecursion_depth
);
6869 defsubr (&Stop_level
);
6870 defsubr (&Sdiscard_input
);
6871 defsubr (&Sopen_dribble_file
);
6872 defsubr (&Sset_input_mode
);
6873 defsubr (&Scurrent_input_mode
);
6874 defsubr (&Sexecute_extended_command
);
6876 DEFVAR_LISP ("last-command-char", &last_command_char
,
6877 "Last input event that was part of a command.");
6879 DEFVAR_LISP_NOPRO ("last-command-event", &last_command_char
,
6880 "Last input event that was part of a command.");
6882 DEFVAR_LISP ("last-nonmenu-event", &last_nonmenu_event
,
6883 "Last input event in a command, except for mouse menu events.\n\
6884 Mouse menus give back keys that don't look like mouse events;\n\
6885 this variable holds the actual mouse event that led to the menu,\n\
6886 so that you can determine whether the command was run by mouse or not.");
6888 DEFVAR_LISP ("last-input-char", &last_input_char
,
6889 "Last input event.");
6891 DEFVAR_LISP_NOPRO ("last-input-event", &last_input_char
,
6892 "Last input event.");
6894 DEFVAR_LISP ("unread-command-events", &Vunread_command_events
,
6895 "List of objects to be read as next command input events.");
6897 DEFVAR_INT ("unread-command-char", &unread_command_char
,
6898 "If not -1, an object to be read as next command input event.");
6900 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char
,
6901 "Meta-prefix character code. Meta-foo as command input\n\
6902 turns into this character followed by foo.");
6903 XSETINT (meta_prefix_char
, 033);
6905 DEFVAR_LISP ("last-command", &last_command
,
6906 "The last command executed. Normally a symbol with a function definition,\n\
6907 but can be whatever was found in the keymap, or whatever the variable\n\
6908 `this-command' was set to by that command.\n\
6910 The value `mode-exit' is special; it means that the previous command\n\
6911 read an event that told it to exit, and it did so and unread that event.\n\
6912 In other words, the present command is the event that made the previous\n\
6915 The value `kill-region' is special; it means that the previous command\n\
6916 was a kill command.");
6917 last_command
= Qnil
;
6919 DEFVAR_LISP ("this-command", &this_command
,
6920 "The command now being executed.\n\
6921 The command can set this variable; whatever is put here\n\
6922 will be in `last-command' during the following command.");
6923 this_command
= Qnil
;
6925 DEFVAR_INT ("auto-save-interval", &auto_save_interval
,
6926 "*Number of keyboard input characters between auto-saves.\n\
6927 Zero means disable autosaving due to number of characters typed.");
6928 auto_save_interval
= 300;
6930 DEFVAR_LISP ("auto-save-timeout", &Vauto_save_timeout
,
6931 "*Number of seconds idle time before auto-save.\n\
6932 Zero or nil means disable auto-saving due to idleness.\n\
6933 After auto-saving due to this many seconds of idle time,\n\
6934 Emacs also does a garbage collection if that seems to be warranted.");
6935 XSETFASTINT (Vauto_save_timeout
, 30);
6937 DEFVAR_INT ("echo-keystrokes", &echo_keystrokes
,
6938 "*Nonzero means echo unfinished commands after this many seconds of pause.");
6939 echo_keystrokes
= 1;
6941 DEFVAR_INT ("polling-period", &polling_period
,
6942 "*Interval between polling for input during Lisp execution.\n\
6943 The reason for polling is to make C-g work to stop a running program.\n\
6944 Polling is needed only when using X windows and SIGIO does not work.\n\
6945 Polling is automatically disabled in all other cases.");
6948 DEFVAR_LISP ("double-click-time", &Vdouble_click_time
,
6949 "*Maximum time between mouse clicks to make a double-click.\n\
6950 Measured in milliseconds. nil means disable double-click recognition;\n\
6951 t means double-clicks have no time limit and are detected\n\
6952 by position only.");
6953 Vdouble_click_time
= make_number (500);
6955 DEFVAR_BOOL ("inhibit-local-menu-bar-menus", &inhibit_local_menu_bar_menus
,
6956 "*Non-nil means inhibit local map menu bar menus.");
6957 inhibit_local_menu_bar_menus
= 0;
6959 DEFVAR_INT ("num-input-keys", &num_input_keys
,
6960 "Number of complete keys read from the keyboard so far.");
6963 DEFVAR_LISP ("last-event-frame", &Vlast_event_frame
,
6964 "The frame in which the most recently read event occurred.\n\
6965 If the last event came from a keyboard macro, this is set to `macro'.");
6966 Vlast_event_frame
= Qnil
;
6968 DEFVAR_LISP ("help-char", &Vhelp_char
,
6969 "Character to recognize as meaning Help.\n\
6970 When it is read, do `(eval help-form)', and display result if it's a string.\n\
6971 If the value of `help-form' is nil, this char can be read normally.");
6972 XSETINT (Vhelp_char
, Ctl ('H'));
6974 DEFVAR_LISP ("help-form", &Vhelp_form
,
6975 "Form to execute when character `help-char' is read.\n\
6976 If the form returns a string, that string is displayed.\n\
6977 If `help-form' is nil, the help char is not recognized.");
6980 DEFVAR_LISP ("prefix-help-command", &Vprefix_help_command
,
6981 "Command to run when `help-char' character follows a prefix key.\n\
6982 This command is used only when there is no actual binding\n\
6983 for that character after that prefix key.");
6984 Vprefix_help_command
= Qnil
;
6986 DEFVAR_LISP ("top-level", &Vtop_level
,
6987 "Form to evaluate when Emacs starts up.\n\
6988 Useful to set before you dump a modified Emacs.");
6991 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table
,
6992 "String used as translate table for keyboard input, or nil.\n\
6993 Each character is looked up in this string and the contents used instead.\n\
6994 If string is of length N, character codes N and up are untranslated.");
6995 Vkeyboard_translate_table
= Qnil
;
6997 DEFVAR_LISP ("key-translation-map", &Vkey_translation_map
,
6998 "Keymap of key translations that can override keymaps.\n\
6999 This keymap works like `function-key-map', but comes after that,\n\
7000 and applies even for keys that have ordinary bindings.");
7001 Vkey_translation_map
= Qnil
;
7003 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend
,
7004 "Non-nil means to always spawn a subshell instead of suspending,\n\
7005 even if the operating system has support for stopping a process.");
7008 DEFVAR_BOOL ("menu-prompting", &menu_prompting
,
7009 "Non-nil means prompt with menus when appropriate.\n\
7010 This is done when reading from a keymap that has a prompt string,\n\
7011 for elements that have prompt strings.\n\
7012 The menu is displayed on the screen\n\
7013 if X menus were enabled at configuration\n\
7014 time and the previous event was a mouse click prefix key.\n\
7015 Otherwise, menu prompting uses the echo area.");
7018 DEFVAR_LISP ("menu-prompt-more-char", &menu_prompt_more_char
,
7019 "Character to see next line of menu prompt.\n\
7020 Type this character while in a menu prompt to rotate around the lines of it.");
7021 XSETINT (menu_prompt_more_char
, ' ');
7023 DEFVAR_INT ("extra-keyboard-modifiers", &extra_keyboard_modifiers
,
7024 "A mask of additional modifier keys to use with every keyboard character.\n\
7025 Emacs applies the modifiers of the character stored here to each keyboard\n\
7026 character it reads. For example, after evaluating the expression\n\
7027 (setq extra-keyboard-modifiers ?\\C-x)\n\
7028 all input characters will have the control modifier applied to them.\n\
7030 Note that the character ?\\C-@, equivalent to the integer zero, does\n\
7031 not count as a control character; rather, it counts as a character\n\
7032 with no modifiers; thus, setting `extra-keyboard-modifiers' to zero\n\
7033 cancels any modification.");
7034 extra_keyboard_modifiers
= 0;
7036 DEFVAR_LISP ("deactivate-mark", &Vdeactivate_mark
,
7037 "If an editing command sets this to t, deactivate the mark afterward.\n\
7038 The command loop sets this to nil before each command,\n\
7039 and tests the value when the command returns.\n\
7040 Buffer modification stores t in this variable.");
7041 Vdeactivate_mark
= Qnil
;
7043 DEFVAR_LISP ("command-hook-internal", &Vcommand_hook_internal
,
7044 "Temporary storage of pre-command-hook or post-command-hook.");
7045 Vcommand_hook_internal
= Qnil
;
7047 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook
,
7048 "Normal hook run before each command is executed.\n\
7049 While the hook is run, its value is temporarily set to nil\n\
7050 to avoid an unbreakable infinite loop if a hook function gets an error.\n\
7051 As a result, a hook function cannot straightforwardly alter the value of\n\
7052 `pre-command-hook'. See the Emacs Lisp manual for a way of\n\
7053 implementing hook functions that alter the set of hook functions.");
7054 Vpre_command_hook
= Qnil
;
7056 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook
,
7057 "Normal hook run after each command is executed.\n\
7058 While the hook is run, its value is temporarily set to nil\n\
7059 to avoid an unbreakable infinite loop if a hook function gets an error.\n\
7060 As a result, a hook function cannot straightforwardly alter the value of\n\
7061 `post-command-hook'. See the Emacs Lisp manual for a way of\n\
7062 implementing hook functions that alter the set of hook functions.");
7063 Vpost_command_hook
= Qnil
;
7065 DEFVAR_LISP ("lucid-menu-bar-dirty-flag", &Vlucid_menu_bar_dirty_flag
,
7066 "t means menu bar, specified Lucid style, needs to be recomputed.");
7067 Vlucid_menu_bar_dirty_flag
= Qnil
;
7069 DEFVAR_LISP ("menu-bar-final-items", &Vmenu_bar_final_items
,
7070 "List of menu bar items to move to the end of the menu bar.\n\
7071 The elements of the list are event types that may have menu bar bindings.");
7072 Vmenu_bar_final_items
= Qnil
;
7074 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map
,
7075 "Keymap that overrides all other local keymaps.\n\
7076 If this variable is non-nil, it is used as a keymap instead of the\n\
7077 buffer's local map, and the minor mode keymaps and text property keymaps.");
7078 Voverriding_local_map
= Qnil
;
7080 DEFVAR_LISP ("overriding-local-map-menu-flag", &Voverriding_local_map_menu_flag
,
7081 "Non-nil means `overriding-local-map' applies to the menu bar.\n\
7082 Otherwise, the menu bar continues to reflect the buffer's local map\n\
7083 and the minor mode maps regardless of `overriding-local-map'.");
7084 Voverriding_local_map_menu_flag
= Qnil
;
7087 DEFVAR_LISP ("track-mouse", &do_mouse_tracking
,
7088 "*Non-nil means generate motion events for mouse motion.");
7091 DEFVAR_KBOARD ("system-key-alist", Vsystem_key_alist
,
7092 "Alist of system-specific X windows key symbols.\n\
7093 Each element should have the form (N . SYMBOL) where N is the\n\
7094 numeric keysym code (sans the \"system-specific\" bit 1<<28)\n\
7095 and SYMBOL is its name.");
7097 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list
,
7098 "List of deferred actions to be performed at a later time.\n\
7099 The precise format isn't relevant here; we just check whether it is nil.");
7100 Vdeferred_action_list
= Qnil
;
7102 DEFVAR_LISP ("deferred-action-function", &Vdeferred_action_function
,
7103 "Function to call to handle deferred actions, after each command.\n\
7104 This function is called with no arguments after each command\n\
7105 whenever `deferred-action-list' is non-nil.");
7106 Vdeferred_action_function
= Qnil
;
7111 initial_define_key (global_map
, Ctl ('Z'), "suspend-emacs");
7112 initial_define_key (control_x_map
, Ctl ('Z'), "suspend-emacs");
7113 initial_define_key (meta_map
, Ctl ('C'), "exit-recursive-edit");
7114 initial_define_key (global_map
, Ctl (']'), "abort-recursive-edit");
7115 initial_define_key (meta_map
, 'x', "execute-extended-command");